| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
| 5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
| 6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
| 7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
| 8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
| 9 */ | 9 */ |
| 10 #include "webrtc/test/frame_generator.h" | 10 #include "webrtc/test/frame_generator.h" |
| 11 | 11 |
| 12 #include <math.h> | 12 #include <math.h> |
| 13 #include <stdio.h> | 13 #include <stdio.h> |
| 14 #include <string.h> | 14 #include <string.h> |
| 15 | 15 |
| 16 #include <memory> | 16 #include <memory> |
| 17 | 17 |
| 18 #include "webrtc/base/checks.h" | 18 #include "webrtc/base/checks.h" |
| 19 #include "webrtc/common_video/libyuv/include/webrtc_libyuv.h" | 19 #include "webrtc/common_video/libyuv/include/webrtc_libyuv.h" |
| 20 #include "webrtc/system_wrappers/include/clock.h" | 20 #include "webrtc/system_wrappers/include/clock.h" |
| 21 #include "libyuv/convert.h" | 21 #include "webrtc/test/frame_utils.h" |
| 22 | 22 |
| 23 namespace webrtc { | 23 namespace webrtc { |
| 24 namespace test { | 24 namespace test { |
| 25 namespace { | 25 namespace { |
| 26 | 26 |
| 27 class ChromaGenerator : public FrameGenerator { | 27 class ChromaGenerator : public FrameGenerator { |
| 28 public: | 28 public: |
| 29 ChromaGenerator(size_t width, size_t height) | 29 ChromaGenerator(size_t width, size_t height) |
| 30 : angle_(0.0), width_(width), height_(height) { | 30 : angle_(0.0), width_(width), height_(height) { |
| 31 RTC_CHECK(width_ > 0); | 31 RTC_CHECK(width_ > 0); |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 94 if (current_display_count_ == 0) | 94 if (current_display_count_ == 0) |
| 95 ReadNextFrame(); | 95 ReadNextFrame(); |
| 96 if (++current_display_count_ >= frame_display_count_) | 96 if (++current_display_count_ >= frame_display_count_) |
| 97 current_display_count_ = 0; | 97 current_display_count_ = 0; |
| 98 | 98 |
| 99 temp_frame_.reset( | 99 temp_frame_.reset( |
| 100 new VideoFrame(last_read_buffer_, 0, 0, webrtc::kVideoRotation_0)); | 100 new VideoFrame(last_read_buffer_, 0, 0, webrtc::kVideoRotation_0)); |
| 101 return temp_frame_.get(); | 101 return temp_frame_.get(); |
| 102 } | 102 } |
| 103 | 103 |
| 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. | |
| 106 void ReadNextFrame() { | 104 void ReadNextFrame() { |
| 107 size_t bytes_read = | 105 last_read_buffer_ = |
| 108 fread(frame_buffer_.get(), 1, frame_size_, files_[file_index_]); | 106 test::ReadI420Buffer(static_cast<int>(width_), |
| 109 if (bytes_read < frame_size_) { | 107 static_cast<int>(height_), |
| 108 files_[file_index_]); |
| 109 if (!last_read_buffer_) { |
| 110 // No more frames to read in this file, rewind and move to next file. | 110 // No more frames to read in this file, rewind and move to next file. |
| 111 rewind(files_[file_index_]); | 111 rewind(files_[file_index_]); |
| 112 file_index_ = (file_index_ + 1) % files_.size(); | 112 file_index_ = (file_index_ + 1) % files_.size(); |
| 113 bytes_read = fread(frame_buffer_.get(), 1, frame_size_, | 113 last_read_buffer_ = |
| 114 files_[file_index_]); | 114 test::ReadI420Buffer(static_cast<int>(width_), |
| 115 assert(bytes_read >= frame_size_); | 115 static_cast<int>(height_), |
| 116 files_[file_index_]); |
| 117 RTC_CHECK(last_read_buffer_); |
| 116 } | 118 } |
| 117 | |
| 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( | |
| 122 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_)); | |
| 133 } | 119 } |
| 134 | 120 |
| 135 private: | 121 private: |
| 136 size_t file_index_; | 122 size_t file_index_; |
| 137 const std::vector<FILE*> files_; | 123 const std::vector<FILE*> files_; |
| 138 const size_t width_; | 124 const size_t width_; |
| 139 const size_t height_; | 125 const size_t height_; |
| 140 const size_t frame_size_; | 126 const size_t frame_size_; |
| 141 const std::unique_ptr<uint8_t[]> frame_buffer_; | 127 const std::unique_ptr<uint8_t[]> frame_buffer_; |
| 142 const int frame_display_count_; | 128 const int frame_display_count_; |
| (...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 310 files.push_back(file); | 296 files.push_back(file); |
| 311 } | 297 } |
| 312 | 298 |
| 313 return new ScrollingImageFrameGenerator( | 299 return new ScrollingImageFrameGenerator( |
| 314 clock, files, source_width, source_height, target_width, target_height, | 300 clock, files, source_width, source_height, target_width, target_height, |
| 315 scroll_time_ms, pause_time_ms); | 301 scroll_time_ms, pause_time_ms); |
| 316 } | 302 } |
| 317 | 303 |
| 318 } // namespace test | 304 } // namespace test |
| 319 } // namespace webrtc | 305 } // namespace webrtc |
| OLD | NEW |