Chromium Code Reviews| Index: webrtc/test/frame_generator.cc |
| diff --git a/webrtc/test/frame_generator.cc b/webrtc/test/frame_generator.cc |
| index ed7e95a12679d2abc36da2e56a4e194206c7d198..0190df76dd8062504f1b067540de240ca6726e48 100644 |
| --- a/webrtc/test/frame_generator.cc |
| +++ b/webrtc/test/frame_generator.cc |
| @@ -25,36 +25,39 @@ namespace { |
| class ChromaGenerator : public FrameGenerator { |
| public: |
| - ChromaGenerator(size_t width, size_t height) |
| - : angle_(0.0), width_(width), height_(height) { |
| + ChromaGenerator(size_t width, size_t height) : angle_(0.0) { |
|
perkj_webrtc
2016/09/13 15:29:22
change size_t to int and skip the static_cast?
nisse-webrtc
2016/09/14 06:59:05
The FrameGenerator interface could use a general c
|
| assert(width > 0); |
| assert(height > 0); |
| + size_t half_width = (width + 1) / 2; |
| + y_size_ = width * height; |
| + uv_size_ = half_width * ((height + 1) / 2); |
| + |
| + // Ensure stride == width. |
| + buffer_ = I420Buffer::Create( |
| + static_cast<int>(width), static_cast<int>(height), |
| + static_cast<int>(width), static_cast<int>(half_width), |
| + static_cast<int>(half_width)); |
| } |
| VideoFrame* NextFrame() override { |
| - frame_.CreateEmptyFrame(static_cast<int>(width_), |
| - static_cast<int>(height_), |
| - static_cast<int>(width_), |
| - static_cast<int>((width_ + 1) / 2), |
| - static_cast<int>((width_ + 1) / 2)); |
| angle_ += 30.0; |
| uint8_t u = fabs(sin(angle_)) * 0xFF; |
| uint8_t v = fabs(cos(angle_)) * 0xFF; |
| - memset(frame_.video_frame_buffer()->MutableDataY(), 0x80, |
| - frame_.allocated_size(kYPlane)); |
| - memset(frame_.video_frame_buffer()->MutableDataU(), u, |
| - frame_.allocated_size(kUPlane)); |
| - memset(frame_.video_frame_buffer()->MutableDataV(), v, |
| - frame_.allocated_size(kVPlane)); |
| - return &frame_; |
| + memset(buffer_->MutableDataY(), 0x80, y_size_); |
| + memset(buffer_->MutableDataU(), u, uv_size_); |
| + memset(buffer_->MutableDataV(), v, uv_size_); |
| + |
| + frame_.reset(new VideoFrame(buffer_, 0, 0, webrtc::kVideoRotation_0)); |
| + return frame_.get(); |
| } |
| private: |
| double angle_; |
| - size_t width_; |
| - size_t height_; |
| - VideoFrame frame_; |
| + size_t y_size_; |
| + size_t uv_size_; |
| + rtc::scoped_refptr<I420Buffer> buffer_; |
| + std::unique_ptr<VideoFrame> frame_; |
| }; |
| class YuvFileGenerator : public FrameGenerator { |
| @@ -89,13 +92,9 @@ class YuvFileGenerator : public FrameGenerator { |
| if (++current_display_count_ >= frame_display_count_) |
| current_display_count_ = 0; |
| - // If this is the last repeatition of this frame, it's OK to use the |
| - // original instance, otherwise use a copy. |
| - if (current_display_count_ == frame_display_count_) |
| - return &last_read_frame_; |
| - |
| - temp_frame_copy_.CopyFrame(last_read_frame_); |
| - return &temp_frame_copy_; |
| + temp_frame_.reset( |
| + new VideoFrame(last_read_buffer_, 0, 0, webrtc::kVideoRotation_0)); |
| + return temp_frame_.get(); |
| } |
| void ReadNextFrame() { |
| @@ -110,14 +109,13 @@ class YuvFileGenerator : public FrameGenerator { |
| assert(bytes_read >= frame_size_); |
| } |
| - last_read_frame_.CreateEmptyFrame( |
| + last_read_buffer_ = I420Buffer::Create( |
| static_cast<int>(width_), static_cast<int>(height_), |
| static_cast<int>(width_), static_cast<int>((width_ + 1) / 2), |
| static_cast<int>((width_ + 1) / 2)); |
| - |
| ConvertToI420(kI420, frame_buffer_.get(), 0, 0, static_cast<int>(width_), |
| static_cast<int>(height_), 0, kVideoRotation_0, |
| - &last_read_frame_); |
| + last_read_buffer_.get()); |
| } |
| private: |
| @@ -129,8 +127,8 @@ class YuvFileGenerator : public FrameGenerator { |
| const std::unique_ptr<uint8_t[]> frame_buffer_; |
| const int frame_display_count_; |
| int current_display_count_; |
| - VideoFrame last_read_frame_; |
| - VideoFrame temp_frame_copy_; |
| + rtc::scoped_refptr<I420Buffer> last_read_buffer_; |
| + std::unique_ptr<VideoFrame> temp_frame_; |
| }; |
| class ScrollingImageFrameGenerator : public FrameGenerator { |