Bug 1497351 - Remove dictionary null defaults from MediaTrackConstraintSet; handle absence in NormalizedConstraintSet. r=bzbarsky,pehrsons
authorJan-Ivar Bruaroey <jib@mozilla.com>
Thu, 11 Oct 2018 02:03:17 +0000
changeset 496404 336da65f35ea1237d94c4a8e6d67b8f2bd794496
parent 496403 419218259bc1a6f5f1cd527225f1f200fbf55126
child 496405 838b2692a934fba342f5b288326b224405305f7f
push id9984
push userffxbld-merge
push dateMon, 15 Oct 2018 21:07:35 +0000
treeherdermozilla-beta@183d27ea8570 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbzbarsky, pehrsons
bugs1497351
milestone64.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 1497351 - Remove dictionary null defaults from MediaTrackConstraintSet; handle absence in NormalizedConstraintSet. r=bzbarsky,pehrsons Differential Revision: https://phabricator.services.mozilla.com/D8054
dom/media/webrtc/MediaEngineDefault.cpp
dom/media/webrtc/MediaEngineRemoteVideoSource.cpp
dom/media/webrtc/MediaTrackConstraints.cpp
dom/media/webrtc/MediaTrackConstraints.h
dom/webidl/MediaStreamTrack.webidl
--- a/dom/media/webrtc/MediaEngineDefault.cpp
+++ b/dom/media/webrtc/MediaEngineDefault.cpp
@@ -419,18 +419,19 @@ MediaEngineDefaultAudioSource::Allocate(
                                         AllocationHandle** aOutHandle,
                                         const char** aOutBadConstraint)
 {
   AssertIsOnOwningThread();
 
   MOZ_ASSERT(mState == kReleased);
 
   // Mock failure for automated tests.
-  if (aConstraints.mDeviceId.IsString() &&
-      aConstraints.mDeviceId.GetAsString().EqualsASCII("bad device")) {
+  if (aConstraints.mDeviceId.WasPassed() &&
+      aConstraints.mDeviceId.Value().IsString() &&
+      aConstraints.mDeviceId.Value().GetAsString().EqualsASCII("bad device")) {
     return NS_ERROR_FAILURE;
   }
 
   mFreq = aPrefs.mFreq ? aPrefs.mFreq : 1000;
   *aOutHandle = nullptr;
 
   MutexAutoLock lock(mMutex);
   mState = kAllocated;
--- a/dom/media/webrtc/MediaEngineRemoteVideoSource.cpp
+++ b/dom/media/webrtc/MediaEngineRemoteVideoSource.cpp
@@ -986,19 +986,19 @@ MediaEngineRemoteVideoSource::ChooseCapa
 
   TrimLessFitCandidates(candidateSet);
 
   // Any remaining multiples all have the same distance. A common case of this
   // occurs when no ideal is specified. Lean toward defaults.
   uint32_t sameDistance = candidateSet[0].mDistance;
   {
     MediaTrackConstraintSet prefs;
-    prefs.mWidth.SetAsLong() = aPrefs.GetWidth();
-    prefs.mHeight.SetAsLong() = aPrefs.GetHeight();
-    prefs.mFrameRate.SetAsDouble() = aPrefs.mFPS;
+    prefs.mWidth.Construct().SetAsLong() = aPrefs.GetWidth();
+    prefs.mHeight.Construct().SetAsLong() = aPrefs.GetHeight();
+    prefs.mFrameRate.Construct().SetAsDouble() = aPrefs.mFPS;
     NormalizedConstraintSet normPrefs(prefs, false);
 
     for (auto& candidate : candidateSet) {
       candidate.mDistance =
         GetDistance(candidate.mCapability, normPrefs, aDeviceId, aCalculate);
     }
     TrimLessFitCandidates(candidateSet);
   }
--- a/dom/media/webrtc/MediaTrackConstraints.cpp
+++ b/dom/media/webrtc/MediaTrackConstraints.cpp
@@ -16,17 +16,16 @@
 
 mozilla::LogModule* GetMediaManagerLog();
 #undef LOG
 #define LOG(msg, ...) MOZ_LOG(GetMediaManagerLog(), mozilla::LogLevel::Debug, (msg, ##__VA_ARGS__))
 
 namespace mozilla {
 
 using dom::ConstrainBooleanParameters;
-using dom::OwningLongOrConstrainLongRange;
 
 template<class ValueType>
 template<class ConstrainRange>
 void
 NormalizedConstraintSet::Range<ValueType>::SetFrom(const ConstrainRange& aOther)
 {
   if (aOther.mIdeal.WasPassed()) {
     mIdeal.emplace(aOther.mIdeal.Value());
@@ -86,31 +85,35 @@ NormalizedConstraintSet::Range<bool>::Fi
     *mIdeal = !!(counter / denominator);
     mMergeDenominator = 0;
   }
 }
 
 NormalizedConstraintSet::LongRange::LongRange(
     LongPtrType aMemberPtr,
     const char* aName,
-    const dom::OwningLongOrConstrainLongRange& aOther,
+    const dom::Optional<dom::OwningLongOrConstrainLongRange>& aOther,
     bool advanced,
     nsTArray<MemberPtrType>* aList)
 : Range<int32_t>((MemberPtrType)aMemberPtr, aName,
                  1 + INT32_MIN, INT32_MAX, // +1 avoids Windows compiler bug
                  aList)
 {
-  if (aOther.IsLong()) {
+  if (!aOther.WasPassed()) {
+    return;
+  }
+  auto& other = aOther.Value();
+  if (other.IsLong()) {
     if (advanced) {
-      mMin = mMax = aOther.GetAsLong();
+      mMin = mMax = other.GetAsLong();
     } else {
-      mIdeal.emplace(aOther.GetAsLong());
+      mIdeal.emplace(other.GetAsLong());
     }
   } else {
-    SetFrom(aOther.GetAsConstrainLongRange());
+    SetFrom(other.GetAsConstrainLongRange());
   }
 }
 
 NormalizedConstraintSet::LongLongRange::LongLongRange(
     LongLongPtrType aMemberPtr,
     const char* aName,
     const long long& aOther,
     nsTArray<MemberPtrType>* aList)
@@ -119,87 +122,100 @@ NormalizedConstraintSet::LongLongRange::
                  aList)
 {
   mIdeal.emplace(aOther);
 }
 
 NormalizedConstraintSet::DoubleRange::DoubleRange(
     DoublePtrType aMemberPtr,
     const char* aName,
-    const dom::OwningDoubleOrConstrainDoubleRange& aOther, bool advanced,
+    const dom::Optional<dom::OwningDoubleOrConstrainDoubleRange>& aOther,
+    bool advanced,
     nsTArray<MemberPtrType>* aList)
 : Range<double>((MemberPtrType)aMemberPtr, aName,
                 -std::numeric_limits<double>::infinity(),
                 std::numeric_limits<double>::infinity(), aList)
 {
-  if (aOther.IsDouble()) {
+  if (!aOther.WasPassed()) {
+    return;
+  }
+  auto& other = aOther.Value();
+  if (other.IsDouble()) {
     if (advanced) {
-      mMin = mMax = aOther.GetAsDouble();
+      mMin = mMax = other.GetAsDouble();
     } else {
-      mIdeal.emplace(aOther.GetAsDouble());
+      mIdeal.emplace(other.GetAsDouble());
     }
   } else {
-    SetFrom(aOther.GetAsConstrainDoubleRange());
+    SetFrom(other.GetAsConstrainDoubleRange());
   }
 }
 
 NormalizedConstraintSet::BooleanRange::BooleanRange(
     BooleanPtrType aMemberPtr,
     const char* aName,
-    const dom::OwningBooleanOrConstrainBooleanParameters& aOther,
+    const dom::Optional<dom::OwningBooleanOrConstrainBooleanParameters>& aOther,
     bool advanced,
     nsTArray<MemberPtrType>* aList)
 : Range<bool>((MemberPtrType)aMemberPtr, aName, false, true, aList)
 {
-  if (aOther.IsBoolean()) {
+  if (!aOther.WasPassed()) {
+    return;
+  }
+  auto& other = aOther.Value();
+  if (other.IsBoolean()) {
     if (advanced) {
-      mMin = mMax = aOther.GetAsBoolean();
+      mMin = mMax = other.GetAsBoolean();
     } else {
-      mIdeal.emplace(aOther.GetAsBoolean());
+      mIdeal.emplace(other.GetAsBoolean());
     }
   } else {
-    const dom::ConstrainBooleanParameters& r = aOther.GetAsConstrainBooleanParameters();
+    auto& r = other.GetAsConstrainBooleanParameters();
     if (r.mIdeal.WasPassed()) {
       mIdeal.emplace(r.mIdeal.Value());
     }
     if (r.mExact.WasPassed()) {
       mMin = r.mExact.Value();
       mMax = r.mExact.Value();
     }
   }
 }
 
 NormalizedConstraintSet::StringRange::StringRange(
     StringPtrType aMemberPtr,
     const char* aName,
-    const dom::OwningStringOrStringSequenceOrConstrainDOMStringParameters& aOther,
+    const dom::Optional<dom::OwningStringOrStringSequenceOrConstrainDOMStringParameters>& aOther,
     bool advanced,
     nsTArray<MemberPtrType>* aList)
   : BaseRange((MemberPtrType)aMemberPtr, aName, aList)
 {
-  if (aOther.IsString()) {
+  if (!aOther.WasPassed()) {
+    return;
+  }
+  auto& other = aOther.Value();
+  if (other.IsString()) {
     if (advanced) {
-      mExact.insert(aOther.GetAsString());
+      mExact.insert(other.GetAsString());
     } else {
-      mIdeal.insert(aOther.GetAsString());
+      mIdeal.insert(other.GetAsString());
     }
-  } else if (aOther.IsStringSequence()) {
+  } else if (other.IsStringSequence()) {
     if (advanced) {
       mExact.clear();
-      for (auto& str : aOther.GetAsStringSequence()) {
+      for (auto& str : other.GetAsStringSequence()) {
         mExact.insert(str);
       }
     } else {
       mIdeal.clear();
-      for (auto& str : aOther.GetAsStringSequence()) {
+      for (auto& str : other.GetAsStringSequence()) {
         mIdeal.insert(str);
       }
     }
   } else {
-    SetFrom(aOther.GetAsConstrainDOMStringParameters());
+    SetFrom(other.GetAsConstrainDOMStringParameters());
   }
 }
 
 void
 NormalizedConstraintSet::StringRange::SetFrom(
     const dom::ConstrainDOMStringParameters& aOther)
 {
   if (aOther.mIdeal.WasPassed()) {
--- a/dom/media/webrtc/MediaTrackConstraints.h
+++ b/dom/media/webrtc/MediaTrackConstraints.h
@@ -145,17 +145,18 @@ public:
     uint32_t mMergeDenominator;
   };
 
   struct LongRange : public Range<int32_t>
   {
     typedef LongRange NormalizedConstraintSet::* LongPtrType;
 
     LongRange(LongPtrType aMemberPtr, const char* aName,
-              const dom::OwningLongOrConstrainLongRange& aOther, bool advanced,
+              const dom::Optional<dom::OwningLongOrConstrainLongRange>& aOther,
+              bool advanced,
               nsTArray<MemberPtrType>* aList);
   };
 
   struct LongLongRange : public Range<int64_t>
   {
     typedef LongLongRange NormalizedConstraintSet::* LongLongPtrType;
 
     LongLongRange(LongLongPtrType aMemberPtr, const char* aName,
@@ -164,27 +165,27 @@ public:
   };
 
   struct DoubleRange : public Range<double>
   {
     typedef DoubleRange NormalizedConstraintSet::* DoublePtrType;
 
     DoubleRange(DoublePtrType aMemberPtr,
                 const char* aName,
-                const dom::OwningDoubleOrConstrainDoubleRange& aOther,
+                const dom::Optional<dom::OwningDoubleOrConstrainDoubleRange>& aOther,
                 bool advanced,
                 nsTArray<MemberPtrType>* aList);
   };
 
   struct BooleanRange : public Range<bool>
   {
     typedef BooleanRange NormalizedConstraintSet::* BooleanPtrType;
 
     BooleanRange(BooleanPtrType aMemberPtr, const char* aName,
-                 const dom::OwningBooleanOrConstrainBooleanParameters& aOther,
+                 const dom::Optional<dom::OwningBooleanOrConstrainBooleanParameters>& aOther,
                  bool advanced,
                  nsTArray<MemberPtrType>* aList);
 
     BooleanRange(BooleanPtrType aMemberPtr, const char* aName, const bool& aOther,
                  nsTArray<MemberPtrType>* aList)
       : Range<bool>((MemberPtrType)aMemberPtr, aName, false, true, aList) {
       mIdeal.emplace(aOther);
     }
@@ -193,17 +194,17 @@ public:
   struct StringRange : public BaseRange
   {
     typedef std::set<nsString> ValueType;
     ValueType mExact, mIdeal;
 
     typedef StringRange NormalizedConstraintSet::* StringPtrType;
 
     StringRange(StringPtrType aMemberPtr,  const char* aName,
-        const dom::OwningStringOrStringSequenceOrConstrainDOMStringParameters& aOther,
+        const dom::Optional<dom::OwningStringOrStringSequenceOrConstrainDOMStringParameters>& aOther,
         bool advanced,
         nsTArray<MemberPtrType>* aList);
 
     StringRange(StringPtrType aMemberPtr, const char* aName,
                 const nsString& aOther, nsTArray<MemberPtrType>* aList)
       : BaseRange((MemberPtrType)aMemberPtr, aName, aList) {
       mIdeal.insert(aOther);
     }
--- a/dom/webidl/MediaStreamTrack.webidl
+++ b/dom/webidl/MediaStreamTrack.webidl
@@ -37,45 +37,32 @@ typedef (long or ConstrainLongRange) Con
 typedef (double or ConstrainDoubleRange) ConstrainDouble;
 typedef (boolean or ConstrainBooleanParameters) ConstrainBoolean;
 typedef (DOMString or sequence<DOMString> or ConstrainDOMStringParameters) ConstrainDOMString;
 
 // Note: When adding new constraints, remember to update the SelectSettings()
 // function in MediaManager.cpp to make OverconstrainedError's constraint work!
 
 dictionary MediaTrackConstraintSet {
-    // FIXME: bug 1493860 or bug 1493798: should this "= null" be here?
-    ConstrainLong width = null;
-    // FIXME: bug 1493860 or bug 1493798: should this "= null" be here?
-    ConstrainLong height = null;
-    // FIXME: bug 1493860 or bug 1493798: should this "= null" be here?
-    ConstrainDouble frameRate = null;
-    // FIXME: bug 1493860 or bug 1493798: should this "= null" be here?
-    ConstrainDOMString facingMode = null;
+    ConstrainLong width;
+    ConstrainLong height;
+    ConstrainDouble frameRate;
+    ConstrainDOMString facingMode;
     DOMString mediaSource = "camera";
     long long browserWindow;
     boolean scrollWithPage;
-    // FIXME: bug 1493860 or bug 1493798: should this "= null" be here?
-    ConstrainDOMString deviceId = null;
-    // FIXME: bug 1493860 or bug 1493798: should this "= null" be here?
-    ConstrainLong viewportOffsetX = null;
-    // FIXME: bug 1493860 or bug 1493798: should this "= null" be here?
-    ConstrainLong viewportOffsetY = null;
-    // FIXME: bug 1493860 or bug 1493798: should this "= null" be here?
-    ConstrainLong viewportWidth = null;
-    // FIXME: bug 1493860 or bug 1493798: should this "= null" be here?
-    ConstrainLong viewportHeight = null;
-    // FIXME: bug 1493860 or bug 1493798: should this "= null" be here?
-    ConstrainBoolean echoCancellation = null;
-    // FIXME: bug 1493860 or bug 1493798: should this "= null" be here?
-    ConstrainBoolean noiseSuppression = null;
-    // FIXME: bug 1493860 or bug 1493798: should this "= null" be here?
-    ConstrainBoolean autoGainControl = null;
-    // FIXME: bug 1493860 or bug 1493798: should this "= null" be here?
-    ConstrainLong channelCount = null;
+    ConstrainDOMString deviceId;
+    ConstrainLong viewportOffsetX;
+    ConstrainLong viewportOffsetY;
+    ConstrainLong viewportWidth;
+    ConstrainLong viewportHeight;
+    ConstrainBoolean echoCancellation;
+    ConstrainBoolean noiseSuppression;
+    ConstrainBoolean autoGainControl;
+    ConstrainLong channelCount;
 };
 
 dictionary MediaTrackConstraints : MediaTrackConstraintSet {
     sequence<MediaTrackConstraintSet> advanced;
 };
 
 enum MediaStreamTrackState {
     "live",