1818#include " webrtc/base/checks.h"
1919#include " webrtc/common_video/libyuv/include/webrtc_libyuv.h"
2020#include " webrtc/system_wrappers/include/clock.h"
21- #include " libyuv/convert.h"
2221
2322namespace webrtc {
2423namespace test {
@@ -27,41 +26,35 @@ namespace {
2726class ChromaGenerator : public FrameGenerator {
2827 public:
2928 ChromaGenerator (size_t width, size_t height)
30- : width_(width), height_(height), angle_(0.0 ) {
31- RTC_CHECK (width_ > 0 );
32- RTC_CHECK (height_ > 0 );
33- half_width_ = (width_ + 1 ) / 2 ;
34- y_size_ = width_ * height_;
35- uv_size_ = half_width_ * ((height_ + 1 ) / 2 );
29+ : angle_(0.0 ), width_(width), height_(height) {
30+ assert (width > 0 );
31+ assert (height > 0 );
3632 }
3733
3834 VideoFrame* NextFrame () override {
35+ frame_.CreateEmptyFrame (static_cast <int >(width_),
36+ static_cast <int >(height_),
37+ static_cast <int >(width_),
38+ static_cast <int >((width_ + 1 ) / 2 ),
39+ static_cast <int >((width_ + 1 ) / 2 ));
3940 angle_ += 30.0 ;
4041 uint8_t u = fabs (sin (angle_)) * 0xFF ;
4142 uint8_t v = fabs (cos (angle_)) * 0xFF ;
4243
43- // Ensure stride == width.
44- rtc::scoped_refptr<I420Buffer> buffer (I420Buffer::Create (
45- static_cast <int >(width_), static_cast <int >(height_),
46- static_cast <int >(width_), static_cast <int >(half_width_),
47- static_cast <int >(half_width_)));
48-
49- memset (buffer->MutableDataY (), 0x80 , y_size_);
50- memset (buffer->MutableDataU (), u, uv_size_);
51- memset (buffer->MutableDataV (), v, uv_size_);
52-
53- frame_.reset (new VideoFrame (buffer, 0 , 0 , webrtc::kVideoRotation_0 ));
54- return frame_.get ();
44+ memset (frame_.video_frame_buffer ()->MutableDataY (), 0x80 ,
45+ frame_.allocated_size (kYPlane ));
46+ memset (frame_.video_frame_buffer ()->MutableDataU (), u,
47+ frame_.allocated_size (kUPlane ));
48+ memset (frame_.video_frame_buffer ()->MutableDataV (), v,
49+ frame_.allocated_size (kVPlane ));
50+ return &frame_;
5551 }
5652
5753 private:
5854 double angle_;
5955 size_t width_;
6056 size_t height_;
61- size_t half_width_;
62- size_t y_size_;
63- size_t uv_size_;
64- std::unique_ptr<VideoFrame> frame_;
57+ VideoFrame frame_;
6558};
6659
6760class YuvFileGenerator : public FrameGenerator {
@@ -96,13 +89,15 @@ class YuvFileGenerator : public FrameGenerator {
9689 if (++current_display_count_ >= frame_display_count_)
9790 current_display_count_ = 0 ;
9891
99- temp_frame_.reset (
100- new VideoFrame (last_read_buffer_, 0 , 0 , webrtc::kVideoRotation_0 ));
101- return temp_frame_.get ();
92+ // If this is the last repeatition of this frame, it's OK to use the
93+ // original instance, otherwise use a copy.
94+ if (current_display_count_ == frame_display_count_)
95+ return &last_read_frame_;
96+
97+ temp_frame_copy_.CopyFrame (last_read_frame_);
98+ return &temp_frame_copy_;
10299 }
103100
104- // TODO(nisse): Have a frame reader in one place. And read directly
105- // into the planes of an I420Buffer, the extra copying below is silly.
106101 void ReadNextFrame () {
107102 size_t bytes_read =
108103 fread (frame_buffer_.get (), 1 , frame_size_, files_[file_index_]);
@@ -115,21 +110,14 @@ class YuvFileGenerator : public FrameGenerator {
115110 assert (bytes_read >= frame_size_);
116111 }
117112
118- size_t half_width = (width_ + 1 ) / 2 ;
119- size_t size_y = width_ * height_;
120- size_t size_uv = half_width * ((height_ + 1 ) / 2 );
121- last_read_buffer_ = I420Buffer::Create (
113+ last_read_frame_.CreateEmptyFrame (
122114 static_cast <int >(width_), static_cast <int >(height_),
123- static_cast <int >(width_), static_cast <int >(half_width),
124- static_cast <int >(half_width));
125- libyuv::I420Copy (
126- frame_buffer_.get (), static_cast <int >(width_),
127- frame_buffer_.get () + size_y, static_cast <int >(half_width),
128- frame_buffer_.get () + size_y + size_uv, static_cast <int >(half_width),
129- last_read_buffer_->MutableDataY (), last_read_buffer_->StrideY (),
130- last_read_buffer_->MutableDataU (), last_read_buffer_->StrideU (),
131- last_read_buffer_->MutableDataV (), last_read_buffer_->StrideV (),
132- static_cast <int >(width_), static_cast <int >(height_));
115+ static_cast <int >(width_), static_cast <int >((width_ + 1 ) / 2 ),
116+ static_cast <int >((width_ + 1 ) / 2 ));
117+
118+ ConvertToI420 (kI420 , frame_buffer_.get (), 0 , 0 , static_cast <int >(width_),
119+ static_cast <int >(height_), 0 , kVideoRotation_0 ,
120+ &last_read_frame_);
133121 }
134122
135123 private:
@@ -141,8 +129,8 @@ class YuvFileGenerator : public FrameGenerator {
141129 const std::unique_ptr<uint8_t []> frame_buffer_;
142130 const int frame_display_count_;
143131 int current_display_count_;
144- rtc::scoped_refptr<I420Buffer> last_read_buffer_ ;
145- std::unique_ptr< VideoFrame> temp_frame_ ;
132+ VideoFrame last_read_frame_ ;
133+ VideoFrame temp_frame_copy_ ;
146134};
147135
148136class ScrollingImageFrameGenerator : public FrameGenerator {
0 commit comments