Bug 1162412 - Part 1 - don't treat plain facingMode constraint as required. r=jesup
authorJan-Ivar Bruaroey <jib@mozilla.com>
Thu, 07 May 2015 13:15:35 -0400
changeset 274385 8d1e073342edec8dfa5e1b3060a9dc858568ad22
parent 274384 88c8da455ad8fb61bb8123591f1b06c94a90acad
child 274386 252c81b4f5d5afe1752c7bec14e50e56001737c4
push id863
push userraliiev@mozilla.com
push dateMon, 03 Aug 2015 13:22:43 +0000
treeherdermozilla-release@f6321b14228d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjesup
bugs1162412
milestone40.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1162412 - Part 1 - don't treat plain facingMode constraint as required. r=jesup
dom/media/MediaManager.cpp
--- a/dom/media/MediaManager.cpp
+++ b/dom/media/MediaManager.cpp
@@ -525,50 +525,73 @@ VideoDevice::VideoDevice(MediaEngineVide
  */
 
 // Reminder: add handling for new constraints both here and in GetSources below!
 
 uint32_t
 VideoDevice::GetBestFitnessDistance(
     const nsTArray<const MediaTrackConstraintSet*>& aConstraintSets)
 {
+  // TODO: Minimal kludge to fix plain and ideal facingMode regression, for
+  // smooth landing and uplift. Proper cleanup is forthcoming (1037389).
+  uint64_t distance = 0;
+
   // Interrogate device-inherent properties first.
   for (size_t i = 0; i < aConstraintSets.Length(); i++) {
     auto& c = *aConstraintSets[i];
     if (!c.mFacingMode.IsConstrainDOMStringParameters() ||
+        c.mFacingMode.GetAsConstrainDOMStringParameters().mIdeal.WasPassed() ||
         c.mFacingMode.GetAsConstrainDOMStringParameters().mExact.WasPassed()) {
       nsString deviceFacingMode;
       GetFacingMode(deviceFacingMode);
       if (c.mFacingMode.IsString()) {
         if (c.mFacingMode.GetAsString() != deviceFacingMode) {
-          return UINT32_MAX;
+          if (i == 0) {
+            distance = 1000;
+          }
         }
       } else if (c.mFacingMode.IsStringSequence()) {
         if (!c.mFacingMode.GetAsStringSequence().Contains(deviceFacingMode)) {
-          return UINT32_MAX;
+          if (i == 0) {
+            distance = 1000;
+          }
         }
-      } else {
+      } else if (c.mFacingMode.GetAsConstrainDOMStringParameters().mExact.WasPassed()) {
         auto& exact = c.mFacingMode.GetAsConstrainDOMStringParameters().mExact.Value();
         if (exact.IsString()) {
           if (exact.GetAsString() != deviceFacingMode) {
             return UINT32_MAX;
           }
         } else if (!exact.GetAsStringSequence().Contains(deviceFacingMode)) {
           return UINT32_MAX;
         }
+      } else if (c.mFacingMode.GetAsConstrainDOMStringParameters().mIdeal.WasPassed()) {
+        auto& ideal = c.mFacingMode.GetAsConstrainDOMStringParameters().mIdeal.Value();
+        if (ideal.IsString()) {
+          if (ideal.GetAsString() != deviceFacingMode) {
+            if (i == 0) {
+              distance = 1000;
+            }
+          }
+        } else if (!ideal.GetAsStringSequence().Contains(deviceFacingMode)) {
+          if (i == 0) {
+            distance = 1000;
+          }
+        }
       }
     }
     nsString s;
     GetMediaSource(s);
     if (s != c.mMediaSource) {
       return UINT32_MAX;
     }
   }
   // Forward request to underlying object to interrogate per-mode capabilities.
-  return GetSource()->GetBestFitnessDistance(aConstraintSets);
+  distance += uint64_t(GetSource()->GetBestFitnessDistance(aConstraintSets));
+  return uint32_t(std::min(distance, uint64_t(UINT32_MAX)));
 }
 
 AudioDevice::AudioDevice(MediaEngineAudioSource* aSource)
   : MediaDevice(aSource) {}
 
 uint32_t
 AudioDevice::GetBestFitnessDistance(
     const nsTArray<const MediaTrackConstraintSet*>& aConstraintSets)