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