Bug 1495478 - Move LogConstraints() to class MediaConstraintsHelper and add logging of missing constraints (rollup includes backed-out bug 1494498) r=pehrsons
authorJan-Ivar Bruaroey <jib@mozilla.com>
Tue, 02 Oct 2018 16:13:20 +0000
changeset 439195 fb7f5d71b31ad06c7207f0945cd8fdbee003e237
parent 439194 cefdf4d102faabf8a000caa821d311ca3d289701
child 439196 5780816ec3a9eff36b3d7f1c221c5f58aa6aba47
push id34758
push userdvarga@mozilla.com
push dateTue, 02 Oct 2018 21:45:21 +0000
treeherdermozilla-central@4392b5198fb7 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerspehrsons
bugs1495478, 1494498
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 1495478 - Move LogConstraints() to class MediaConstraintsHelper and add logging of missing constraints (rollup includes backed-out bug 1494498) r=pehrsons Differential Revision: https://phabricator.services.mozilla.com/D7378
dom/media/webrtc/MediaEngineRemoteVideoSource.cpp
dom/media/webrtc/MediaTrackConstraints.cpp
dom/media/webrtc/MediaTrackConstraints.h
--- a/dom/media/webrtc/MediaEngineRemoteVideoSource.cpp
+++ b/dom/media/webrtc/MediaEngineRemoteVideoSource.cpp
@@ -792,46 +792,16 @@ MediaEngineRemoteVideoSource::GetBestFit
   if (!candidateSet.Length()) {
     return UINT32_MAX;
   }
   TrimLessFitCandidates(candidateSet);
   return candidateSet[0].mDistance;
 }
 
 static void
-LogConstraints(const NormalizedConstraintSet& aConstraints)
-{
-  auto& c = aConstraints;
-  if (c.mWidth.mIdeal.isSome()) {
-    LOG(("Constraints: width: { min: %d, max: %d, ideal: %d }",
-         c.mWidth.mMin, c.mWidth.mMax,
-         c.mWidth.mIdeal.valueOr(0)));
-  } else {
-    LOG(("Constraints: width: { min: %d, max: %d }",
-         c.mWidth.mMin, c.mWidth.mMax));
-  }
-  if (c.mHeight.mIdeal.isSome()) {
-    LOG(("             height: { min: %d, max: %d, ideal: %d }",
-         c.mHeight.mMin, c.mHeight.mMax,
-         c.mHeight.mIdeal.valueOr(0)));
-  } else {
-    LOG(("             height: { min: %d, max: %d }",
-         c.mHeight.mMin, c.mHeight.mMax));
-  }
-  if (c.mFrameRate.mIdeal.isSome()) {
-    LOG(("             frameRate: { min: %f, max: %f, ideal: %f }",
-         c.mFrameRate.mMin, c.mFrameRate.mMax,
-         c.mFrameRate.mIdeal.valueOr(0)));
-  } else {
-    LOG(("             frameRate: { min: %f, max: %f }",
-         c.mFrameRate.mMin, c.mFrameRate.mMax));
-  }
-}
-
-static void
 LogCapability(const char* aHeader,
               const webrtc::CaptureCapability &aCapability,
               uint32_t aDistance)
 {
   // RawVideoType and VideoCodecType media/webrtc/trunk/webrtc/common_types.h
   static const char* const types[] = {
     "I420",
     "YV12",
@@ -880,21 +850,21 @@ MediaEngineRemoteVideoSource::ChooseCapa
 {
   LOG((__PRETTY_FUNCTION__));
   AssertIsOnOwningThread();
 
   if (MOZ_LOG_TEST(GetMediaManagerLog(), LogLevel::Debug)) {
     LOG(("ChooseCapability: prefs: %dx%d @%dfps",
          aPrefs.GetWidth(), aPrefs.GetHeight(),
          aPrefs.mFPS));
-    LogConstraints(aConstraints);
+    MediaConstraintsHelper::LogConstraints(aConstraints);
     if (!aConstraints.mAdvanced.empty()) {
       LOG(("Advanced array[%zu]:", aConstraints.mAdvanced.size()));
       for (auto& advanced : aConstraints.mAdvanced) {
-        LogConstraints(advanced);
+        MediaConstraintsHelper::LogConstraints(advanced);
       }
     }
   }
 
   switch (mMediaSource) {
     case MediaSourceEnum::Screen:
     case MediaSourceEnum::Window:
     case MediaSourceEnum::Application: {
--- a/dom/media/webrtc/MediaTrackConstraints.cpp
+++ b/dom/media/webrtc/MediaTrackConstraints.cpp
@@ -9,16 +9,20 @@
 #include <algorithm>
 #include <iterator>
 
 #include "MediaEngineSource.h"
 #include "nsIScriptError.h"
 #include "mozilla/dom/MediaStreamTrackBinding.h"
 #include "mozilla/MediaManager.h"
 
+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
@@ -476,16 +480,17 @@ MediaConstraintsHelper::FitnessDistance(
 
 /* static */ const char*
 MediaConstraintsHelper::SelectSettings(
     const NormalizedConstraints& aConstraints,
     nsTArray<RefPtr<MediaDevice>>& aDevices,
     bool aIsChrome)
 {
   auto& c = aConstraints;
+  LogConstraints(c);
 
   // First apply top-level constraints.
 
   // Stack constraintSets that pass, starting with the required one, because the
   // whole stack must be re-satisfied each time a capability-set is ruled out
   // (this avoids storing state or pushing algorithm into the lower-level code).
   nsTArray<RefPtr<MediaDevice>> unsatisfactory;
   nsTArray<const NormalizedConstraintSet*> aggregateConstraints;
@@ -625,9 +630,74 @@ MediaConstraintsHelper::ConvertOldWithWa
     if (old.IsBoolean()) {
       to.SetAsBoolean() = old.GetAsBoolean();
     } else {
       to.SetAsConstrainBooleanParameters() = old.GetAsConstrainBooleanParameters();
     }
   }
 }
 
+static void
+LogConstraintStringRange(const NormalizedConstraintSet::StringRange& aRange)
+{
+  if (aRange.mExact.size() <= 1 && aRange.mIdeal.size() <= 1) {
+    LOG("  %s: { exact: [%s], ideal: [%s] }",
+        aRange.mName,
+        (aRange.mExact.size()? NS_ConvertUTF16toUTF8(*aRange.mExact.begin()).get() : ""),
+        (aRange.mIdeal.size()? NS_ConvertUTF16toUTF8(*aRange.mIdeal.begin()).get() : ""));
+  } else {
+    LOG("  %s: { exact: [", aRange.mName);
+    for (auto& entry : aRange.mExact) {
+      LOG("      %s,", NS_ConvertUTF16toUTF8(entry).get());
+    }
+    LOG("    ], ideal: [");
+    for (auto& entry : aRange.mIdeal) {
+      LOG("      %s,", NS_ConvertUTF16toUTF8(entry).get());
+    }
+    LOG("    ]}");
+  }
 }
+
+template<typename T>
+static void
+LogConstraintRange(const NormalizedConstraintSet::Range<T>& aRange)
+{
+  if (aRange.mIdeal.isSome()) {
+    LOG("  %s: { min: %d, max: %d, ideal: %d }",
+         aRange.mName, aRange.mMin, aRange.mMax, aRange.mIdeal.valueOr(0));
+  } else {
+    LOG("  %s: { min: %d, max: %d }", aRange.mName, aRange.mMin, aRange.mMax);
+  }
+}
+
+template<>
+void
+LogConstraintRange(const NormalizedConstraintSet::Range<double>& aRange)
+{
+  if (aRange.mIdeal.isSome()) {
+    LOG("  %s: { min: %f, max: %f, ideal: %f }",
+         aRange.mName, aRange.mMin, aRange.mMax, aRange.mIdeal.valueOr(0));
+  } else {
+    LOG("  %s: { min: %f, max: %f }", aRange.mName, aRange.mMin, aRange.mMax);
+  }
+}
+
+/* static */ void
+MediaConstraintsHelper::LogConstraints(const NormalizedConstraintSet& aConstraints)
+{
+  auto& c = aConstraints;
+  LOG("Constraints: {");
+  LOG("%s", [&]() {
+    LogConstraintRange(c.mWidth);
+    LogConstraintRange(c.mHeight);
+    LogConstraintRange(c.mFrameRate);
+    LogConstraintStringRange(c.mMediaSource);
+    LogConstraintStringRange(c.mFacingMode);
+    LogConstraintStringRange(c.mDeviceId);
+    LogConstraintRange(c.mEchoCancellation);
+    LogConstraintRange(c.mAutoGainControl);
+    LogConstraintRange(c.mNoiseSuppression);
+    LogConstraintRange(c.mChannelCount);
+    return "}";
+  }());
+}
+
+}
--- a/dom/media/webrtc/MediaTrackConstraints.h
+++ b/dom/media/webrtc/MediaTrackConstraints.h
@@ -339,13 +339,15 @@ public:
 
   // Warn on and convert use of deprecated constraints to new ones
   static void
   ConvertOldWithWarning(
       const dom::OwningBooleanOrConstrainBooleanParameters& old,
       dom::OwningBooleanOrConstrainBooleanParameters& to,
       const char* aMessageName,
       nsPIDOMWindowInner* aWindow);
+
+  static void LogConstraints(const NormalizedConstraintSet& aConstraints);
 };
 
 } // namespace mozilla
 
 #endif /* MEDIATRACKCONSTRAINTS_H_ */