Bug 1423582 - use UniquePtr to wrap frame. r?pehrsons draft
authorMunro Mengjue Chiang <mchiang@mozilla.com>
Thu, 01 Feb 2018 11:42:28 +0100
changeset 749990 07c4107dfd78c928282fc2b070de19ea20a303be
parent 749896 17ade9f88b6ed2232be51bc02c6860562c3d31dc
push id97532
push userbmo:apehrson@mozilla.com
push dateThu, 01 Feb 2018 10:44:14 +0000
reviewerspehrsons
bugs1423582
milestone60.0a1
Bug 1423582 - use UniquePtr to wrap frame. r?pehrsons MozReview-Commit-ID: 2T7RC1tBbOA
dom/media/webrtc/MediaEngineRemoteVideoSource.cpp
--- a/dom/media/webrtc/MediaEngineRemoteVideoSource.cpp
+++ b/dom/media/webrtc/MediaEngineRemoteVideoSource.cpp
@@ -472,16 +472,17 @@ MediaEngineRemoteVideoSource::DeliverFra
   // The following snippet will set dst_width to dest_max_width and dst_height to dest_max_height
   int32_t dst_width = std::min(req_ideal_width > 0 ? req_ideal_width : aProps.width(), dest_max_width);
   int32_t dst_height = std::min(req_ideal_height > 0 ? req_ideal_height : aProps.height(), dest_max_height);
 
   int dst_stride_y = dst_width;
   int dst_stride_uv = (dst_width + 1) / 2;
 
   camera::VideoFrameProperties properties;
+  UniquePtr<uint8_t []> frameBuf;
   uint8_t* frame;
   bool needReScale = (dst_width != aProps.width() ||
                       dst_height != aProps.height()) &&
                      dst_width <= aProps.width() &&
                      dst_height <= aProps.height();
 
   if (!needReScale) {
     dst_width = aProps.width();
@@ -511,17 +512,18 @@ MediaEngineRemoteVideoSource::DeliverFra
     rtc::scoped_refptr<webrtc::I420Buffer> scaledBuffer;
     scaledBuffer = webrtc::I420Buffer::Create(dst_width, dst_height, dst_stride_y,
                                               dst_stride_uv, dst_stride_uv);
 
     scaledBuffer->CropAndScaleFrom(*captureFrame.video_frame_buffer().get());
     webrtc::VideoFrame scaledFrame(scaledBuffer, 0, 0, webrtc::kVideoRotation_0);
 
     VideoFrameUtils::InitFrameBufferProperties(scaledFrame, properties);
-    frame = new unsigned char[properties.bufferSize()];
+    frameBuf.reset(new (fallible) uint8_t[properties.bufferSize()]);
+    frame = frameBuf.get();
 
     if (!frame) {
       return 0;
     }
 
     VideoFrameUtils::CopyVideoFrameBuffers(frame,
                                            properties.bufferSize(), scaledFrame);
   }
@@ -548,21 +550,16 @@ MediaEngineRemoteVideoSource::DeliverFra
   data.mPicSize = IntSize(dst_width, dst_height);
   data.mStereoMode = StereoMode::MONO;
 
   if (!image->CopyData(data)) {
     MOZ_ASSERT(false);
     return 0;
   }
 
-  if (needReScale && frame) {
-    delete frame;
-    frame = nullptr;
-  }
-
 #ifdef DEBUG
   static uint32_t frame_num = 0;
   LOGFRAME(("frame %d (%dx%d)->(%dx%d); timeStamp %u, ntpTimeMs %" PRIu64 ", renderTimeMs %" PRIu64,
             frame_num++, aProps.width(), aProps.height(), dst_width, dst_height,
             aProps.timeStamp(), aProps.ntpTimeMs(), aProps.renderTimeMs()));
 #endif
 
   bool sizeChanged = false;