Bug 1348381 - Handle VideoFrame::CreateBlackImage returning nullptr. r=jesup
authorAndreas Pehrson <pehrsons@gmail.com>
Fri, 28 Apr 2017 13:58:22 +0200
changeset 355965 e1a305a0f6378696b91b0938fef4ec68bd04d05e
parent 355964 47debe9bbc713f3a87bffa13ec12d694356c7f9b
child 355966 151963610e799364d0e12af286f6201e5947d625
push id41861
push userpehrsons@gmail.com
push dateTue, 02 May 2017 08:27:31 +0000
treeherderautoland@e1a305a0f637 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjesup
bugs1348381
milestone55.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1348381 - Handle VideoFrame::CreateBlackImage returning nullptr. r=jesup 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
@@ -342,17 +342,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::Info,
--- 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;