Bug 1423582 - use UniquePtr to wrap frame. r?pehrsons draft
authorMunro Mengjue Chiang <mchiang@mozilla.com>
Wed, 13 Dec 2017 18:08:27 -0600
changeset 711574 44bd6379f990991a1b34c8dfdb3dd5fd34cd738e
parent 711340 3d2bcdbeffeb12a4c48496b22d2678ab9f454444
child 743818 f677c45a7d6c8a5126b98496eccc62c4ace7a611
push id93079
push userbmo:mchiang@mozilla.com
push dateThu, 14 Dec 2017 00:08:57 +0000
reviewerspehrsons
bugs1423582
milestone59.0a1
Bug 1423582 - use UniquePtr to wrap frame. r?pehrsons MozReview-Commit-ID: 7WdOwfAqD4
dom/media/webrtc/MediaEngineRemoteVideoSource.cpp
--- a/dom/media/webrtc/MediaEngineRemoteVideoSource.cpp
+++ b/dom/media/webrtc/MediaEngineRemoteVideoSource.cpp
@@ -471,16 +471,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 : mWidth, dest_max_width);
     int32_t dst_height = std::min(req_ideal_height > 0 ? req_ideal_height : mHeight, dest_max_height);
 
     int dst_stride_y = dst_width;
     int dst_stride_uv = (dst_width + 1) / 2;
 
     camera::VideoFrameProperties properties;
+    UniquePtr<uint8_t []> frameBuf(nullptr);
     uint8_t* frame;
     bool needReScale = !((dst_width == mWidth && dst_height == mHeight) ||
                          (dst_width > mWidth || dst_height > mHeight));
 
     if (!needReScale) {
       dst_width = mWidth;
       dst_height = mHeight;
       frame = aBuffer;
@@ -505,17 +506,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);
     }
@@ -541,21 +543,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); timeStamp %u, ntpTimeMs %" PRIu64 ", renderTimeMs %" PRIu64,
               frame_num++, mWidth, mHeight,
               aProps.timeStamp(), aProps.ntpTimeMs(), aProps.renderTimeMs()));
 #endif
 
     // implicitly releases last image