Bug 1274626 part 2 - make the blank video data creator return a white image; r=jya draft
authorKaku Kuo <tkuo@mozilla.com>
Thu, 28 Jul 2016 16:16:56 +0800
changeset 396017 6696ee41757de6286fc5153e1ba0d79a745449af
parent 396016 f785c04568430116ab60c2b01c334af52c6f8b47
child 396018 05df0526b442cfce765fa73c39ed6f1bc6b01e68
push id24896
push usertkuo@mozilla.com
push dateWed, 03 Aug 2016 07:58:00 +0000
reviewersjya
bugs1274626
milestone51.0a1
Bug 1274626 part 2 - make the blank video data creator return a white image; r=jya MozReview-Commit-ID: By8h71EsXrg
dom/media/platforms/agnostic/BlankDecoderModule.cpp
--- a/dom/media/platforms/agnostic/BlankDecoderModule.cpp
+++ b/dom/media/platforms/agnostic/BlankDecoderModule.cpp
@@ -88,66 +88,70 @@ public:
     mPicture = gfx::IntRect(0, 0, mFrameWidth, mFrameHeight);
   }
 
   already_AddRefed<MediaData>
   Create(const media::TimeUnit& aDTS, const media::TimeUnit& aDuration, int64_t aOffsetInStream)
   {
     // Create a fake YUV buffer in a 420 format. That is, an 8bpp Y plane,
     // with a U and V plane that are half the size of the Y plane, i.e 8 bit,
-    // 2x2 subsampled. Have the data pointers of each frame point to the
-    // first plane, they'll always be zero'd memory anyway.
-    auto frame = MakeUnique<uint8_t[]>(mFrameWidth * mFrameHeight);
-    memset(frame.get(), 0, mFrameWidth * mFrameHeight);
+    // 2x2 subsampled.
+    const int sizeY = mFrameWidth * mFrameHeight;
+    const int sizeCbCr = ((mFrameWidth + 1) / 2) * ((mFrameHeight + 1) / 2);
+    auto frame = MakeUnique<uint8_t[]>(sizeY + sizeCbCr);
     VideoData::YCbCrBuffer buffer;
 
     // Y plane.
     buffer.mPlanes[0].mData = frame.get();
     buffer.mPlanes[0].mStride = mFrameWidth;
     buffer.mPlanes[0].mHeight = mFrameHeight;
     buffer.mPlanes[0].mWidth = mFrameWidth;
     buffer.mPlanes[0].mOffset = 0;
     buffer.mPlanes[0].mSkip = 0;
 
     // Cb plane.
-    buffer.mPlanes[1].mData = frame.get();
+    buffer.mPlanes[1].mData = frame.get() + sizeY;
     buffer.mPlanes[1].mStride = mFrameWidth / 2;
     buffer.mPlanes[1].mHeight = mFrameHeight / 2;
     buffer.mPlanes[1].mWidth = mFrameWidth / 2;
     buffer.mPlanes[1].mOffset = 0;
     buffer.mPlanes[1].mSkip = 0;
 
     // Cr plane.
-    buffer.mPlanes[2].mData = frame.get();
+    buffer.mPlanes[2].mData = frame.get() + sizeY;
     buffer.mPlanes[2].mStride = mFrameWidth / 2;
     buffer.mPlanes[2].mHeight = mFrameHeight / 2;
     buffer.mPlanes[2].mWidth = mFrameWidth / 2;
     buffer.mPlanes[2].mOffset = 0;
     buffer.mPlanes[2].mSkip = 0;
 
+    // Set to color white.
+    memset(buffer.mPlanes[0].mData, 255, sizeY);
+    memset(buffer.mPlanes[1].mData, 128, sizeCbCr);
+
     return VideoData::Create(mInfo,
                              mImageContainer,
                              nullptr,
                              aOffsetInStream,
                              aDTS.ToMicroseconds(),
                              aDuration.ToMicroseconds(),
                              buffer,
                              true,
                              aDTS.ToMicroseconds(),
                              mPicture);
   }
+
 private:
   VideoInfo mInfo;
   gfx::IntRect mPicture;
   uint32_t mFrameWidth;
   uint32_t mFrameHeight;
   RefPtr<layers::ImageContainer> mImageContainer;
 };
 
-
 class BlankAudioDataCreator {
 public:
   BlankAudioDataCreator(uint32_t aChannelCount, uint32_t aSampleRate)
     : mFrameSum(0), mChannelCount(aChannelCount), mSampleRate(aSampleRate)
   {
   }
 
   MediaData* Create(const media::TimeUnit& aDTS,