From d344eea963c99290589d853c0c5c2b23e0073a42 Mon Sep 17 00:00:00 2001 From: Randell Jesup Date: Tue, 15 Jul 2014 15:49:01 -0400 Subject: [PATCH] Bug 1038879: ensure odd widths/heights in getUserMedia are handled correctly r=rillian --- content/media/webrtc/MediaEngineWebRTCVideo.cpp | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/content/media/webrtc/MediaEngineWebRTCVideo.cpp b/content/media/webrtc/MediaEngineWebRTCVideo.cpp index 353572301e23..b4941d941d99 100644 --- a/content/media/webrtc/MediaEngineWebRTCVideo.cpp +++ b/content/media/webrtc/MediaEngineWebRTCVideo.cpp @@ -79,8 +79,8 @@ MediaEngineWebRTCVideoSource::DeliverFrame( return 0; } - MOZ_ASSERT(mWidth*mHeight*3/2 == size); - if (mWidth*mHeight*3/2 != size) { + if (mWidth*mHeight + 2*(((mWidth+1)/2)*((mHeight+1)/2)) != size) { + MOZ_ASSERT(false, "Wrong size frame in DeliverFrame!"); return 0; } @@ -93,14 +93,15 @@ MediaEngineWebRTCVideoSource::DeliverFrame( const uint8_t lumaBpp = 8; const uint8_t chromaBpp = 4; + // Take lots of care to round up! layers::PlanarYCbCrData data; data.mYChannel = frame; data.mYSize = IntSize(mWidth, mHeight); - data.mYStride = mWidth * lumaBpp/ 8; - data.mCbCrStride = mWidth * chromaBpp / 8; + data.mYStride = (mWidth * lumaBpp + 7)/ 8; + data.mCbCrStride = (mWidth * chromaBpp + 7) / 8; data.mCbChannel = frame + mHeight * data.mYStride; - data.mCrChannel = data.mCbChannel + mHeight * data.mCbCrStride / 2; - data.mCbCrSize = IntSize(mWidth/ 2, mHeight/ 2); + data.mCrChannel = data.mCbChannel + ((mHeight+1)/2) * data.mCbCrStride; + data.mCbCrSize = IntSize((mWidth+1)/ 2, (mHeight+1)/ 2); data.mPicX = 0; data.mPicY = 0; data.mPicSize = IntSize(mWidth, mHeight);