From 086c8d5a029d95f72a16eabd8a31e24a4213d5dc Mon Sep 17 00:00:00 2001 From: "braveyao@webrtc.org" Date: Mon, 22 Dec 2014 05:46:42 +0000 Subject: [PATCH] Use a temporary buffer to scale a screencast in OnFrameCaptured BUG=3903 R=sergeyu@chromium.org Review URL: https://webrtc-codereview.appspot.com/23909005 git-svn-id: http://webrtc.googlecode.com/svn/trunk@7973 4adac7df-926f-26a2-2b94-8c16560cd09d --- talk/media/base/videocapturer.cc | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/talk/media/base/videocapturer.cc b/talk/media/base/videocapturer.cc index 300003890..77563840b 100644 --- a/talk/media/base/videocapturer.cc +++ b/talk/media/base/videocapturer.cc @@ -362,6 +362,10 @@ void VideoCapturer::OnFrameCaptured(VideoCapturer*, return; } #if !defined(DISABLE_YUV) + + // Use a temporary buffer to scale + rtc::scoped_ptr scale_buffer; + if (IsScreencast()) { int scaled_width, scaled_height; if (screencast_max_pixels_ > 0) { @@ -388,6 +392,8 @@ void VideoCapturer::OnFrameCaptured(VideoCapturer*, } CapturedFrame* modified_frame = const_cast(captured_frame); + const int modified_frame_size = scaled_width * scaled_height * 4; + scale_buffer.reset(new uint8[modified_frame_size]); // Compute new width such that width * height is less than maximum but // maintains original captured frame aspect ratio. // Round down width to multiple of 4 so odd width won't round up beyond @@ -396,12 +402,13 @@ void VideoCapturer::OnFrameCaptured(VideoCapturer*, libyuv::ARGBScale(reinterpret_cast(captured_frame->data), captured_frame->width * 4, captured_frame->width, captured_frame->height, - reinterpret_cast(modified_frame->data), + scale_buffer.get(), scaled_width * 4, scaled_width, scaled_height, libyuv::kFilterBilinear); modified_frame->width = scaled_width; modified_frame->height = scaled_height; modified_frame->data_size = scaled_width * 4 * scaled_height; + modified_frame->data = scale_buffer.get(); } }