diff --git a/webrtc/common_video/i420_video_frame.cc b/webrtc/common_video/i420_video_frame.cc index a8c5de5d5..a0ade4618 100644 --- a/webrtc/common_video/i420_video_frame.cc +++ b/webrtc/common_video/i420_video_frame.cc @@ -226,4 +226,9 @@ rtc::scoped_refptr I420VideoFrame::video_frame_buffer() return video_frame_buffer_; } +void I420VideoFrame::set_video_frame_buffer( + const rtc::scoped_refptr& buffer) { + video_frame_buffer_ = buffer; +} + } // namespace webrtc diff --git a/webrtc/common_video/libyuv/include/scaler.h b/webrtc/common_video/libyuv/include/scaler.h index ce7462c12..5dff5095a 100644 --- a/webrtc/common_video/libyuv/include/scaler.h +++ b/webrtc/common_video/libyuv/include/scaler.h @@ -15,6 +15,7 @@ #ifndef WEBRTC_COMMON_VIDEO_LIBYUV_INCLUDE_SCALER_H_ #define WEBRTC_COMMON_VIDEO_LIBYUV_INCLUDE_SCALER_H_ +#include "webrtc/common_video/interface/i420_buffer_pool.h" #include "webrtc/common_video/interface/i420_video_frame.h" #include "webrtc/common_video/libyuv/include/webrtc_libyuv.h" #include "webrtc/typedefs.h" @@ -43,8 +44,7 @@ class Scaler { ScaleMethod method); // Scale frame - // Memory is allocated by user. If dst_frame is not of sufficient size, - // the frame will be reallocated to the appropriate size. + // Memory is allocated by this object and recycled using |buffer_pool_|. // Return value: 0 - OK, // -1 - parameter error // -2 - scaler not set @@ -62,6 +62,7 @@ class Scaler { int dst_width_; int dst_height_; bool set_; + I420BufferPool buffer_pool_; }; } // namespace webrtc diff --git a/webrtc/common_video/libyuv/scaler.cc b/webrtc/common_video/libyuv/scaler.cc index e64b28f4d..598c1d018 100644 --- a/webrtc/common_video/libyuv/scaler.cc +++ b/webrtc/common_video/libyuv/scaler.cc @@ -56,10 +56,8 @@ int Scaler::Scale(const I420VideoFrame& src_frame, return -2; // Making sure that destination frame is of sufficient size. - // Aligning stride values based on width. - dst_frame->CreateEmptyFrame(dst_width_, dst_height_, - dst_width_, (dst_width_ + 1) / 2, - (dst_width_ + 1) / 2); + dst_frame->set_video_frame_buffer( + buffer_pool_.CreateBuffer(dst_width_, dst_height_)); // We want to preserve aspect ratio instead of stretching the frame. // Therefore, we need to crop the source frame. Calculate the largest center diff --git a/webrtc/video_frame.h b/webrtc/video_frame.h index 96c69be98..d2f94fe0b 100644 --- a/webrtc/video_frame.h +++ b/webrtc/video_frame.h @@ -162,6 +162,10 @@ class I420VideoFrame { // Return the underlying buffer. rtc::scoped_refptr video_frame_buffer() const; + // Set the underlying buffer. + void set_video_frame_buffer( + const rtc::scoped_refptr& buffer); + private: // An opaque reference counted handle that stores the pixel data. rtc::scoped_refptr video_frame_buffer_; @@ -202,4 +206,3 @@ class EncodedImage { } // namespace webrtc #endif // WEBRTC_VIDEO_FRAME_H_ -