Bug 1423582 - use UniquePtr to wrap frame. r?pehrsons
MozReview-Commit-ID: 7WdOwfAqD4
--- 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