Skip to content

Commit

Permalink
Use stable_sort to sort media capture devices according the fitness d…
Browse files Browse the repository at this point in the history
…istance

https://bugs.webkit.org/show_bug.cgi?id=255131
rdar://problem/107735578

Reviewed by Eric Carlson.

Using stable_sort gives more predictive results since the initial order is the one we specify.
Also, it will favor higher priority devices (first in the list) against lower priority devices.

* Source/WebCore/platform/mediastream/RealtimeMediaSourceCenter.cpp:
(WebCore::RealtimeMediaSourceCenter::validateRequestConstraintsAfterEnumeration):

Canonical link: https://commits.webkit.org/262718@main
  • Loading branch information
youennf committed Apr 7, 2023
1 parent 5981ddb commit 3b5080a
Showing 1 changed file with 2 additions and 2 deletions.
Expand Up @@ -332,15 +332,15 @@ void RealtimeMediaSourceCenter::validateRequestConstraintsAfterEnumeration(Valid

Vector<CaptureDevice> audioDevices;
if (!audioDeviceInfo.isEmpty()) {
std::sort(audioDeviceInfo.begin(), audioDeviceInfo.end(), sortBasedOnFitnessScore);
std::stable_sort(audioDeviceInfo.begin(), audioDeviceInfo.end(), sortBasedOnFitnessScore);
audioDevices = WTF::map(audioDeviceInfo, [] (auto& info) {
return info.device;
});
}

Vector<CaptureDevice> videoDevices;
if (!videoDeviceInfo.isEmpty()) {
std::sort(videoDeviceInfo.begin(), videoDeviceInfo.end(), sortBasedOnFitnessScore);
std::stable_sort(videoDeviceInfo.begin(), videoDeviceInfo.end(), sortBasedOnFitnessScore);
videoDevices = WTF::map(videoDeviceInfo, [] (auto& info) {
return info.device;
});
Expand Down

0 comments on commit 3b5080a

Please sign in to comment.