Bug 1450954 - Add back code to undo screenshare constraints hack. r=jib, a=jcristau
authorAndreas Pehrson <pehrsons@mozilla.com>
Tue, 10 Apr 2018 13:13:41 +0200
changeset 460833 bf6f0553eaeb4b41e4d9c70744b3818a42c27115
parent 460832 eb825e4db72f892b87e53fec8619d7643a17a990
child 460834 9f8ac6bbbd47a4da7cad5f138a58528d382a5f25
push id9066
push userryanvm@gmail.com
push dateMon, 16 Apr 2018 16:39:10 +0000
treeherdermozilla-beta@9f8ac6bbbd47 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjib, jcristau
bugs1450954
milestone60.0
Bug 1450954 - Add back code to undo screenshare constraints hack. r=jib, a=jcristau MozReview-Commit-ID: 9rDRj7U8vQi
dom/media/webrtc/MediaEngineRemoteVideoSource.cpp
--- a/dom/media/webrtc/MediaEngineRemoteVideoSource.cpp
+++ b/dom/media/webrtc/MediaEngineRemoteVideoSource.cpp
@@ -304,17 +304,32 @@ MediaEngineRemoteVideoSource::Start(cons
     LOG(("StartCapture failed"));
     MutexAutoLock lock(mMutex);
     mState = kStopped;
     return NS_ERROR_FAILURE;
   }
 
   NS_DispatchToMainThread(NS_NewRunnableFunction(
       "MediaEngineRemoteVideoSource::SetLastCapability",
-      [settings = mSettings, cap = mCapability]() mutable {
+      [settings = mSettings, source = mMediaSource, cap = mCapability]() mutable {
+    switch (source) {
+      case dom::MediaSourceEnum::Screen:
+      case dom::MediaSourceEnum::Window:
+      case dom::MediaSourceEnum::Application:
+        // Undo the hack where ideal and max constraints are crammed together
+        // in mCapability for consumption by low-level code. We don't actually
+        // know the real resolution yet, so report min(ideal, max) for now.
+        // TODO: This can be removed in bug 1453269.
+        cap.width = std::min(cap.width >> 16, cap.width & 0xffff);
+        cap.height = std::min(cap.height >> 16, cap.height & 0xffff);
+        break;
+      default:
+        break;
+    }
+
     settings->mWidth.Value() = cap.width;
     settings->mHeight.Value() = cap.height;
     settings->mFrameRate.Value() = cap.maxFPS;
   }));
 
   return NS_OK;
 }
 
@@ -476,16 +491,17 @@ MediaEngineRemoteVideoSource::DeliverFra
 
   int32_t req_max_width;
   int32_t req_max_height;
   int32_t req_ideal_width;
   int32_t req_ideal_height;
   {
     MutexAutoLock lock(mMutex);
     MOZ_ASSERT(mState == kStarted);
+    // TODO: These can be removed in bug 1453269.
     req_max_width = mCapability.width & 0xffff;
     req_max_height = mCapability.height & 0xffff;
     req_ideal_width = (mCapability.width >> 16) & 0xffff;
     req_ideal_height = (mCapability.height >> 16) & 0xffff;
   }
 
   // This is only used in the case of screen sharing, see bug 1453269.
   const int32_t target_width = aProps.width();
@@ -839,16 +855,17 @@ MediaEngineRemoteVideoSource::ChooseCapa
     case MediaSourceEnum::Screen:
     case MediaSourceEnum::Window:
     case MediaSourceEnum::Application: {
       FlattenedConstraints c(aConstraints);
       // The actual resolution to constrain around is not easy to find ahead of
       // time (and may in fact change over time), so as a hack, we push ideal
       // and max constraints down to desktop_capture_impl.cc and finish the
       // algorithm there.
+      // TODO: This can be removed in bug 1453269.
       aCapability.width =
         (c.mWidth.mIdeal.valueOr(0) & 0xffff) << 16 | (c.mWidth.mMax & 0xffff);
       aCapability.height =
         (c.mHeight.mIdeal.valueOr(0) & 0xffff) << 16 | (c.mHeight.mMax & 0xffff);
       aCapability.maxFPS =
         c.mFrameRate.Clamp(c.mFrameRate.mIdeal.valueOr(aPrefs.mFPS));
       return true;
     }