Bug 1348381 - Handle VideoFrame::CreateBlackImage returning nullptr. r=jesup, a=gchang
authorAndreas Pehrson <pehrsons@gmail.com>
Fri, 28 Apr 2017 13:58:22 +0200
changeset 393859 3f63049dfca95ad0082e6400c72a92d71f79fd17
parent 393858 19b457181440eb5b844c2a8b5dfa2e97228d11b1
child 393860 b13c3ced8ccf79c0df78183fd57f4a22272022bf
push id7281
push userryanvm@gmail.com
push dateSat, 06 May 2017 01:11:41 +0000
treeherdermozilla-beta@3d9699ce0b0a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjesup, gchang
bugs1348381
milestone54.0
Bug 1348381 - Handle VideoFrame::CreateBlackImage returning nullptr. r=jesup, a=gchang MozReview-Commit-ID: LWon0cx5hAK
dom/media/VideoSegment.cpp
dom/media/encoder/VP8TrackEncoder.cpp
dom/media/imagecapture/CaptureTask.cpp
--- a/dom/media/VideoSegment.cpp
+++ b/dom/media/VideoSegment.cpp
@@ -45,17 +45,16 @@ VideoFrame::TakeFrom(VideoFrame* aFrame)
 
 /* static */ already_AddRefed<Image>
 VideoFrame::CreateBlackImage(const gfx::IntSize& aSize)
 {
   RefPtr<ImageContainer> container =
     LayerManager::CreateImageContainer(ImageContainer::ASYNCHRONOUS);
   RefPtr<PlanarYCbCrImage> image = container->CreatePlanarYCbCrImage();
   if (!image) {
-    MOZ_ASSERT(false);
     return nullptr;
   }
 
   int len = ((aSize.width * aSize.height) * 3 / 2);
 
   // Generate a black image.
   auto frame = MakeUnique<uint8_t[]>(len);
   int y = aSize.width * aSize.height;
@@ -77,17 +76,16 @@ VideoFrame::CreateBlackImage(const gfx::
   data.mCbCrSize = gfx::IntSize(aSize.width / 2, aSize.height / 2);
   data.mPicX = 0;
   data.mPicY = 0;
   data.mPicSize = gfx::IntSize(aSize.width, aSize.height);
   data.mStereoMode = StereoMode::MONO;
 
   // Copies data, so we can free data.
   if (!image->CopyData(data)) {
-    MOZ_ASSERT(false);
     return nullptr;
   }
 
   return image.forget();
 }
 
 VideoChunk::VideoChunk()
 {}
--- a/dom/media/encoder/VP8TrackEncoder.cpp
+++ b/dom/media/encoder/VP8TrackEncoder.cpp
@@ -286,17 +286,21 @@ static bool isYUV444(const PlanarYCbCrIm
 }
 
 nsresult VP8TrackEncoder::PrepareRawFrame(VideoChunk &aChunk)
 {
   RefPtr<Image> img;
   if (aChunk.mFrame.GetForceBlack() || aChunk.IsNull()) {
     if (!mMuteFrame) {
       mMuteFrame = VideoFrame::CreateBlackImage(gfx::IntSize(mFrameWidth, mFrameHeight));
-      MOZ_ASSERT(mMuteFrame);
+    }
+    if (!mMuteFrame) {
+      VP8LOG(LogLevel::Warning, "Failed to allocate black image of size %dx%d",
+             mFrameWidth, mFrameHeight);
+      return NS_OK;
     }
     img = mMuteFrame;
   } else {
     img = aChunk.mFrame.GetImage();
   }
 
   if (img->GetSize() != IntSize(mFrameWidth, mFrameHeight)) {
     VP8LOG(LogLevel::Error,
--- a/dom/media/imagecapture/CaptureTask.cpp
+++ b/dom/media/imagecapture/CaptureTask.cpp
@@ -123,34 +123,34 @@ CaptureTask::SetCurrentFrames(const Vide
       mTask = nullptr;
       return NS_OK;
     }
 
   protected:
     RefPtr<CaptureTask> mTask;
   };
 
-  VideoSegment::ConstChunkIterator iter(aSegment);
-
-
-
-  while (!iter.IsEnded()) {
+  for (VideoSegment::ConstChunkIterator iter(aSegment);
+       !iter.IsEnded(); iter.Next()) {
     VideoChunk chunk = *iter;
 
     // Extract the first valid video frame.
     VideoFrame frame;
     if (!chunk.IsNull()) {
       RefPtr<layers::Image> image;
       if (chunk.mFrame.GetForceBlack()) {
         // Create a black image.
         image = VideoFrame::CreateBlackImage(chunk.mFrame.GetIntrinsicSize());
       } else {
         image = chunk.mFrame.GetImage();
       }
-      MOZ_ASSERT(image);
+      if (!image) {
+        MOZ_ASSERT(image);
+        continue;
+      }
       mImageGrabbedOrTrackEnd = true;
 
       // Encode image.
       nsresult rv;
       nsAutoString type(NS_LITERAL_STRING("image/jpeg"));
       nsAutoString options;
       rv = dom::ImageEncoder::ExtractDataFromLayersImageAsync(
                                 type,
@@ -158,17 +158,16 @@ CaptureTask::SetCurrentFrames(const Vide
                                 false,
                                 image,
                                 new EncodeComplete(this));
       if (NS_FAILED(rv)) {
         PostTrackEndEvent();
       }
       return;
     }
-    iter.Next();
   }
 }
 
 void
 CaptureTask::PostTrackEndEvent()
 {
   mImageGrabbedOrTrackEnd = true;