Bug 1081409: Fix forwarding of captured MediaStreams to PeerConnections r=jib
authorRandell Jesup <rjesup@jesup.org>
Wed, 15 Oct 2014 17:34:26 -0400
changeset 210678 3bfafff4ff073b43c76b6756e97c4ba582065aa7
parent 210677 39c4ff676526ea6e8ef249976151b6cf9b198019
child 210679 b845c0769a85de220afd4a7af3eea2a7c46fec4d
push id1
push userroot
push dateMon, 20 Oct 2014 17:29:22 +0000
reviewersjib
bugs1081409
milestone36.0a1
Bug 1081409: Fix forwarding of captured MediaStreams to PeerConnections r=jib
media/webrtc/signaling/src/mediapipeline/MediaPipeline.cpp
--- a/media/webrtc/signaling/src/mediapipeline/MediaPipeline.cpp
+++ b/media/webrtc/signaling/src/mediapipeline/MediaPipeline.cpp
@@ -1190,40 +1190,47 @@ void MediaPipelineTransmit::PipelineList
     layers::PlanarYCbCrImage* yuv =
     const_cast<layers::PlanarYCbCrImage *>(
           static_cast<const layers::PlanarYCbCrImage *>(img));
     // Big-time assumption here that this is all contiguous data coming
     // from getUserMedia or other sources.
     const layers::PlanarYCbCrData *data = yuv->GetData();
 
     uint8_t *y = data->mYChannel;
-#ifdef DEBUG
     uint8_t *cb = data->mCbChannel;
     uint8_t *cr = data->mCrChannel;
-#endif
     uint32_t width = yuv->GetSize().width;
     uint32_t height = yuv->GetSize().height;
     uint32_t length = yuv->GetDataSize();
+    // NOTE: length may be rounded up or include 'other' data (see
+    // YCbCrImageDataDeserializerBase::ComputeMinBufferSize())
 
     // SendVideoFrame only supports contiguous YCrCb 4:2:0 buffers
     // Verify it's contiguous and in the right order
-    MOZ_ASSERT(cb == (y + YSIZE(width, height)) &&
-               cr == (cb + CRSIZE(width, height)) &&
-               length == I420SIZE(width, height));
-    // XXX Consider making this a non-debug-only check if we ever implement
+    if (cb != (y + YSIZE(width, height)) ||
+        cr != (cb + CRSIZE(width, height))) {
+      MOZ_ASSERT(false, "Incorrect cb/cr pointers in ProcessVideoChunk()!");
+      return;
+    }
+    if (length < I420SIZE(width, height)) {
+      MOZ_ASSERT(false, "Invalid length for ProcessVideoChunk()");
+      return;
+    }
+    // XXX Consider modifying these checks if we ever implement
     // any subclasses of PlanarYCbCrImage that allow disjoint buffers such
-    // that y+3(width*height)/2 might go outside the allocation.
+    // that y+3(width*height)/2 might go outside the allocation or there are
+    // pads between y, cr and cb.
     // GrallocImage can have wider strides, and so in some cases
     // would encode as garbage.  If we need to encode it we'll either want to
     // modify SendVideoFrame or copy/move the data in the buffer.
 
     // OK, pass it on to the conduit
     MOZ_MTLOG(ML_DEBUG, "Sending a video frame");
     // Not much for us to do with an error
-    conduit->SendVideoFrame(y, length, width, height, mozilla::kVideoI420, 0);
+    conduit->SendVideoFrame(y, I420SIZE(width, height), width, height, mozilla::kVideoI420, 0);
   } else if(format == ImageFormat::CAIRO_SURFACE) {
     layers::CairoImage* rgb =
     const_cast<layers::CairoImage *>(
           static_cast<const layers::CairoImage *>(img));
 
     gfx::IntSize size = rgb->GetSize();
     int half_width = (size.width + 1) >> 1;
     int half_height = (size.height + 1) >> 1;