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 | 21 |
22 namespace webrtc { | 22 namespace webrtc { |
23 namespace test { | 23 namespace test { |
24 namespace { | 24 namespace { |
25 | 25 |
26 class ChromaGenerator : public FrameGenerator { | 26 class ChromaGenerator : public FrameGenerator { |
27 public: | 27 public: |
28 ChromaGenerator(size_t width, size_t height) | 28 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
| |
29 : angle_(0.0), width_(width), height_(height) { | |
30 assert(width > 0); | 29 assert(width > 0); |
31 assert(height > 0); | 30 assert(height > 0); |
31 size_t half_width = (width + 1) / 2; | |
32 y_size_ = width * height; | |
33 uv_size_ = half_width * ((height + 1) / 2); | |
34 | |
35 // Ensure stride == width. | |
36 buffer_ = I420Buffer::Create( | |
37 static_cast<int>(width), static_cast<int>(height), | |
38 static_cast<int>(width), static_cast<int>(half_width), | |
39 static_cast<int>(half_width)); | |
32 } | 40 } |
33 | 41 |
34 VideoFrame* NextFrame() override { | 42 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)); | |
40 angle_ += 30.0; | 43 angle_ += 30.0; |
41 uint8_t u = fabs(sin(angle_)) * 0xFF; | 44 uint8_t u = fabs(sin(angle_)) * 0xFF; |
42 uint8_t v = fabs(cos(angle_)) * 0xFF; | 45 uint8_t v = fabs(cos(angle_)) * 0xFF; |
43 | 46 |
44 memset(frame_.video_frame_buffer()->MutableDataY(), 0x80, | 47 memset(buffer_->MutableDataY(), 0x80, y_size_); |
45 frame_.allocated_size(kYPlane)); | 48 memset(buffer_->MutableDataU(), u, uv_size_); |
46 memset(frame_.video_frame_buffer()->MutableDataU(), u, | 49 memset(buffer_->MutableDataV(), v, uv_size_); |
47 frame_.allocated_size(kUPlane)); | 50 |
48 memset(frame_.video_frame_buffer()->MutableDataV(), v, | 51 frame_.reset(new VideoFrame(buffer_, 0, 0, webrtc::kVideoRotation_0)); |
49 frame_.allocated_size(kVPlane)); | 52 return frame_.get(); |
50 return &frame_; | |
51 } | 53 } |
52 | 54 |
53 private: | 55 private: |
54 double angle_; | 56 double angle_; |
55 size_t width_; | 57 size_t y_size_; |
56 size_t height_; | 58 size_t uv_size_; |
57 VideoFrame frame_; | 59 rtc::scoped_refptr<I420Buffer> buffer_; |
60 std::unique_ptr<VideoFrame> frame_; | |
58 }; | 61 }; |
59 | 62 |
60 class YuvFileGenerator : public FrameGenerator { | 63 class YuvFileGenerator : public FrameGenerator { |
61 public: | 64 public: |
62 YuvFileGenerator(std::vector<FILE*> files, | 65 YuvFileGenerator(std::vector<FILE*> files, |
63 size_t width, | 66 size_t width, |
64 size_t height, | 67 size_t height, |
65 int frame_repeat_count) | 68 int frame_repeat_count) |
66 : file_index_(0), | 69 : file_index_(0), |
67 files_(files), | 70 files_(files), |
(...skipping 14 matching lines...) Expand all Loading... | |
82 for (FILE* file : files_) | 85 for (FILE* file : files_) |
83 fclose(file); | 86 fclose(file); |
84 } | 87 } |
85 | 88 |
86 VideoFrame* NextFrame() override { | 89 VideoFrame* NextFrame() override { |
87 if (current_display_count_ == 0) | 90 if (current_display_count_ == 0) |
88 ReadNextFrame(); | 91 ReadNextFrame(); |
89 if (++current_display_count_ >= frame_display_count_) | 92 if (++current_display_count_ >= frame_display_count_) |
90 current_display_count_ = 0; | 93 current_display_count_ = 0; |
91 | 94 |
92 // If this is the last repeatition of this frame, it's OK to use the | 95 temp_frame_.reset( |
93 // original instance, otherwise use a copy. | 96 new VideoFrame(last_read_buffer_, 0, 0, webrtc::kVideoRotation_0)); |
94 if (current_display_count_ == frame_display_count_) | 97 return temp_frame_.get(); |
95 return &last_read_frame_; | |
96 | |
97 temp_frame_copy_.CopyFrame(last_read_frame_); | |
98 return &temp_frame_copy_; | |
99 } | 98 } |
100 | 99 |
101 void ReadNextFrame() { | 100 void ReadNextFrame() { |
102 size_t bytes_read = | 101 size_t bytes_read = |
103 fread(frame_buffer_.get(), 1, frame_size_, files_[file_index_]); | 102 fread(frame_buffer_.get(), 1, frame_size_, files_[file_index_]); |
104 if (bytes_read < frame_size_) { | 103 if (bytes_read < frame_size_) { |
105 // No more frames to read in this file, rewind and move to next file. | 104 // No more frames to read in this file, rewind and move to next file. |
106 rewind(files_[file_index_]); | 105 rewind(files_[file_index_]); |
107 file_index_ = (file_index_ + 1) % files_.size(); | 106 file_index_ = (file_index_ + 1) % files_.size(); |
108 bytes_read = fread(frame_buffer_.get(), 1, frame_size_, | 107 bytes_read = fread(frame_buffer_.get(), 1, frame_size_, |
109 files_[file_index_]); | 108 files_[file_index_]); |
110 assert(bytes_read >= frame_size_); | 109 assert(bytes_read >= frame_size_); |
111 } | 110 } |
112 | 111 |
113 last_read_frame_.CreateEmptyFrame( | 112 last_read_buffer_ = I420Buffer::Create( |
114 static_cast<int>(width_), static_cast<int>(height_), | 113 static_cast<int>(width_), static_cast<int>(height_), |
115 static_cast<int>(width_), static_cast<int>((width_ + 1) / 2), | 114 static_cast<int>(width_), static_cast<int>((width_ + 1) / 2), |
116 static_cast<int>((width_ + 1) / 2)); | 115 static_cast<int>((width_ + 1) / 2)); |
117 | |
118 ConvertToI420(kI420, frame_buffer_.get(), 0, 0, static_cast<int>(width_), | 116 ConvertToI420(kI420, frame_buffer_.get(), 0, 0, static_cast<int>(width_), |
119 static_cast<int>(height_), 0, kVideoRotation_0, | 117 static_cast<int>(height_), 0, kVideoRotation_0, |
120 &last_read_frame_); | 118 last_read_buffer_.get()); |
121 } | 119 } |
122 | 120 |
123 private: | 121 private: |
124 size_t file_index_; | 122 size_t file_index_; |
125 const std::vector<FILE*> files_; | 123 const std::vector<FILE*> files_; |
126 const size_t width_; | 124 const size_t width_; |
127 const size_t height_; | 125 const size_t height_; |
128 const size_t frame_size_; | 126 const size_t frame_size_; |
129 const std::unique_ptr<uint8_t[]> frame_buffer_; | 127 const std::unique_ptr<uint8_t[]> frame_buffer_; |
130 const int frame_display_count_; | 128 const int frame_display_count_; |
131 int current_display_count_; | 129 int current_display_count_; |
132 VideoFrame last_read_frame_; | 130 rtc::scoped_refptr<I420Buffer> last_read_buffer_; |
133 VideoFrame temp_frame_copy_; | 131 std::unique_ptr<VideoFrame> temp_frame_; |
134 }; | 132 }; |
135 | 133 |
136 class ScrollingImageFrameGenerator : public FrameGenerator { | 134 class ScrollingImageFrameGenerator : public FrameGenerator { |
137 public: | 135 public: |
138 ScrollingImageFrameGenerator(Clock* clock, | 136 ScrollingImageFrameGenerator(Clock* clock, |
139 const std::vector<FILE*>& files, | 137 const std::vector<FILE*>& files, |
140 size_t source_width, | 138 size_t source_width, |
141 size_t source_height, | 139 size_t source_height, |
142 size_t target_width, | 140 size_t target_width, |
143 size_t target_height, | 141 size_t target_height, |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
277 files.push_back(file); | 275 files.push_back(file); |
278 } | 276 } |
279 | 277 |
280 return new ScrollingImageFrameGenerator( | 278 return new ScrollingImageFrameGenerator( |
281 clock, files, source_width, source_height, target_width, target_height, | 279 clock, files, source_width, source_height, target_width, target_height, |
282 scroll_time_ms, pause_time_ms); | 280 scroll_time_ms, pause_time_ms); |
283 } | 281 } |
284 | 282 |
285 } // namespace test | 283 } // namespace test |
286 } // namespace webrtc | 284 } // namespace webrtc |
OLD | NEW |