Bug 1441145 - Signal the capture-to-render rotation from parent to child. r?jib draft
authorAndreas Pehrson <pehrsons@mozilla.com>
Tue, 27 Feb 2018 11:29:59 +0100
changeset 761165 e31fd1d347e1e4ca49c9bfdff2b0f8cadc414be3
parent 760269 d6abea1cce397126b86f778c623a243819f2dd12
child 761166 b4f452e157d9d49f96d0854482c6e8a34daccfe5
push id100897
push userbmo:apehrson@mozilla.com
push dateWed, 28 Feb 2018 19:55:57 +0000
reviewersjib
bugs1441145
milestone60.0a1
Bug 1441145 - Signal the capture-to-render rotation from parent to child. r?jib MozReview-Commit-ID: 7JkJOedq9wm
dom/media/systemservices/CamerasParent.cpp
dom/media/systemservices/PCameras.ipdl
--- a/dom/media/systemservices/CamerasParent.cpp
+++ b/dom/media/systemservices/CamerasParent.cpp
@@ -158,16 +158,36 @@ public:
     , mProperties(aProperties){};
 
   NS_IMETHOD Run() override {
     if (mParent->IsShuttingDown()) {
       // Communication channel is being torn down
       mResult = 0;
       return NS_OK;
     }
+    // Figure out if this frame had already applied rotation. If so, we pass this
+    // information to the child so it can scale to the proper dimensions.
+    MOZ_DIAGNOSTIC_ASSERT(sAllRequestedCapabilities.count(mStreamId) == 1);
+    const webrtc::VideoCaptureCapability& cap =
+      sAllRequestedCapabilities[mStreamId];
+    MOZ_ASSERT(mProperties.rotation() == 0, "Rotation is always applied");
+    MOZ_ASSERT(mProperties.width() == cap.width ||
+               mProperties.width() == cap.height, "Width must match cap");
+    MOZ_ASSERT(mProperties.height() == cap.width ||
+               mProperties.height() == cap.height, "Height must match cap");
+    if (mProperties.width() == cap.height && mProperties.height() == cap.width) {
+      // The capability is for the sensor, and the device's rotation was such
+      // that this frame had to be rotated. We signal this to the child so
+      // it can rescale to the proper dimensions.
+      //
+      // It doesn't matter if we pass 90 or 270 as the frame has already been
+      // rotated and we just want to get the target width and height right.
+      mProperties.rotation() = 90;
+    }
+
     if (!mParent->DeliverFrameOverIPC(mCapEngine, mStreamId, Move(mBuffer),
                                       mAlternateBuffer.get(), mProperties)) {
       mResult = -1;
     } else {
       mResult = 0;
     }
     return NS_OK;
   }
--- a/dom/media/systemservices/PCameras.ipdl
+++ b/dom/media/systemservices/PCameras.ipdl
@@ -32,17 +32,18 @@ struct VideoFrameProperties
 {
   // Size of image data within the ShMem,
   // the ShMem is at least this large
   size_t bufferSize;
   // From webrtc::VideoFrame
   uint32_t timeStamp;
   int64_t ntpTimeMs;
   int64_t renderTimeMs;
-  // See webrtc/**/rotation.h
+  // Rotation of the frame in degrees compared to the requested capability.
+  // Note that the buffer is already upright.
   int rotation;
   int yAllocatedSize;
   int uAllocatedSize;
   int vAllocatedSize;
   // From webrtc::VideoFrameBuffer
   int width;
   int height;
   int yStride;