Bug 1449832 - restore screen share scaling code to prevent cropping r=pehrsons
authorNico Grunbaum <na-g@nostrum.com>
Thu, 12 Apr 2018 14:26:14 -0700
changeset 413426 af50acbd6c2884dbbb26b3c8053475318fd57697
parent 413425 86f9b0d937eaa65bb3ac26528c593361701b818f
child 413427 e96685584bf7d3c1d7a4c1861716da89fd650c51
push id33847
push userncsoregi@mozilla.com
push dateSun, 15 Apr 2018 09:17:31 +0000
treeherdermozilla-central@e96685584bf7 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerspehrsons
bugs1449832
milestone61.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 1449832 - restore screen share scaling code to prevent cropping r=pehrsons MozReview-Commit-ID: KctPLbF4PSa
dom/media/webrtc/MediaEngineRemoteVideoSource.cpp
--- a/dom/media/webrtc/MediaEngineRemoteVideoSource.cpp
+++ b/dom/media/webrtc/MediaEngineRemoteVideoSource.cpp
@@ -511,31 +511,62 @@ MediaEngineRemoteVideoSource::DeliverFra
     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();
+  const int32_t target_height = aProps.height();
+
   if (aProps.rotation() == 90 || aProps.rotation() == 270) {
     // This frame is rotated, so what was negotiated as width is now height,
     // and vice versa.
     std::swap(req_max_width, req_max_height);
     std::swap(req_ideal_width, req_ideal_height);
   }
 
   int32_t dst_max_width = std::min(req_max_width, aProps.width());
   int32_t dst_max_height = std::min(req_max_height, aProps.height());
   // This logic works for both camera and screen sharing case.
   // for camera case, req_ideal_width and req_ideal_height is 0.
   // The following snippet will set dst_width to dst_max_width and dst_height to dst_max_height
   int32_t dst_width = std::min(req_ideal_width > 0 ? req_ideal_width : aProps.width(), dst_max_width);
   int32_t dst_height = std::min(req_ideal_height > 0 ? req_ideal_height : aProps.height(), dst_max_height);
 
+  // Apply scaling for screen sharing, see bug 1453269.
+  switch (mMediaSource) {
+    case MediaSourceEnum::Screen:
+    case MediaSourceEnum::Window:
+    case MediaSourceEnum::Application: {
+      // scale to average of portrait and landscape
+      float scale_width = (float)dst_width / (float)aProps.width();
+      float scale_height = (float)dst_height / (float)aProps.height();
+      float scale = (scale_width + scale_height) / 2;
+      dst_width = (int)(scale * target_width);
+      dst_height = (int)(scale * target_height);
+
+      // if scaled rectangle exceeds max rectangle, scale to minimum of portrait and landscape
+      if (dst_width > dst_max_width || dst_height > dst_max_height) {
+        scale_width = (float)dst_max_width / (float)dst_width;
+        scale_height = (float)dst_max_height / (float)dst_height;
+        scale = std::min(scale_width, scale_height);
+        dst_width = (int32_t)(scale * dst_width);
+        dst_height = (int32_t)(scale * dst_height);
+      }
+      break;
+    }
+    default: {
+      break;
+    }
+  }
+
   rtc::Callback0<void> callback_unused;
   rtc::scoped_refptr<webrtc::VideoFrameBuffer> buffer =
     new rtc::RefCountedObject<webrtc::WrappedI420Buffer>(
       aProps.width(),
       aProps.height(),
       aBuffer,
       aProps.yStride(),
       aBuffer + aProps.yAllocatedSize(),