Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(105)

Side by Side Diff: webrtc/test/frame_generator.cc

Issue 2343083002: Revert of Update test code to use I420Buffer when writing pixel data. (Closed)
Patch Set: Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « webrtc/test/fake_texture_frame.h ('k') | webrtc/test/testsupport/metrics/video_metrics.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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"
22 21
23 namespace webrtc { 22 namespace webrtc {
24 namespace test { 23 namespace test {
25 namespace { 24 namespace {
26 25
27 class ChromaGenerator : public FrameGenerator { 26 class ChromaGenerator : public FrameGenerator {
28 public: 27 public:
29 ChromaGenerator(size_t width, size_t height) 28 ChromaGenerator(size_t width, size_t height)
30 : width_(width), height_(height), angle_(0.0) { 29 : angle_(0.0), width_(width), height_(height) {
31 RTC_CHECK(width_ > 0); 30 assert(width > 0);
32 RTC_CHECK(height_ > 0); 31 assert(height > 0);
33 half_width_ = (width_ + 1) / 2;
34 y_size_ = width_ * height_;
35 uv_size_ = half_width_ * ((height_ + 1) / 2);
36 } 32 }
37 33
38 VideoFrame* NextFrame() override { 34 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));
39 angle_ += 30.0; 40 angle_ += 30.0;
40 uint8_t u = fabs(sin(angle_)) * 0xFF; 41 uint8_t u = fabs(sin(angle_)) * 0xFF;
41 uint8_t v = fabs(cos(angle_)) * 0xFF; 42 uint8_t v = fabs(cos(angle_)) * 0xFF;
42 43
43 // Ensure stride == width. 44 memset(frame_.video_frame_buffer()->MutableDataY(), 0x80,
44 rtc::scoped_refptr<I420Buffer> buffer(I420Buffer::Create( 45 frame_.allocated_size(kYPlane));
45 static_cast<int>(width_), static_cast<int>(height_), 46 memset(frame_.video_frame_buffer()->MutableDataU(), u,
46 static_cast<int>(width_), static_cast<int>(half_width_), 47 frame_.allocated_size(kUPlane));
47 static_cast<int>(half_width_))); 48 memset(frame_.video_frame_buffer()->MutableDataV(), v,
48 49 frame_.allocated_size(kVPlane));
49 memset(buffer->MutableDataY(), 0x80, y_size_); 50 return &frame_;
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();
55 } 51 }
56 52
57 private: 53 private:
58 double angle_; 54 double angle_;
59 size_t width_; 55 size_t width_;
60 size_t height_; 56 size_t height_;
61 size_t half_width_; 57 VideoFrame frame_;
62 size_t y_size_;
63 size_t uv_size_;
64 std::unique_ptr<VideoFrame> frame_;
65 }; 58 };
66 59
67 class YuvFileGenerator : public FrameGenerator { 60 class YuvFileGenerator : public FrameGenerator {
68 public: 61 public:
69 YuvFileGenerator(std::vector<FILE*> files, 62 YuvFileGenerator(std::vector<FILE*> files,
70 size_t width, 63 size_t width,
71 size_t height, 64 size_t height,
72 int frame_repeat_count) 65 int frame_repeat_count)
73 : file_index_(0), 66 : file_index_(0),
74 files_(files), 67 files_(files),
(...skipping 14 matching lines...) Expand all
89 for (FILE* file : files_) 82 for (FILE* file : files_)
90 fclose(file); 83 fclose(file);
91 } 84 }
92 85
93 VideoFrame* NextFrame() override { 86 VideoFrame* NextFrame() override {
94 if (current_display_count_ == 0) 87 if (current_display_count_ == 0)
95 ReadNextFrame(); 88 ReadNextFrame();
96 if (++current_display_count_ >= frame_display_count_) 89 if (++current_display_count_ >= frame_display_count_)
97 current_display_count_ = 0; 90 current_display_count_ = 0;
98 91
99 temp_frame_.reset( 92 // If this is the last repeatition of this frame, it's OK to use the
100 new VideoFrame(last_read_buffer_, 0, 0, webrtc::kVideoRotation_0)); 93 // original instance, otherwise use a copy.
101 return temp_frame_.get(); 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_;
102 } 99 }
103 100
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() { 101 void ReadNextFrame() {
107 size_t bytes_read = 102 size_t bytes_read =
108 fread(frame_buffer_.get(), 1, frame_size_, files_[file_index_]); 103 fread(frame_buffer_.get(), 1, frame_size_, files_[file_index_]);
109 if (bytes_read < frame_size_) { 104 if (bytes_read < frame_size_) {
110 // No more frames to read in this file, rewind and move to next file. 105 // No more frames to read in this file, rewind and move to next file.
111 rewind(files_[file_index_]); 106 rewind(files_[file_index_]);
112 file_index_ = (file_index_ + 1) % files_.size(); 107 file_index_ = (file_index_ + 1) % files_.size();
113 bytes_read = fread(frame_buffer_.get(), 1, frame_size_, 108 bytes_read = fread(frame_buffer_.get(), 1, frame_size_,
114 files_[file_index_]); 109 files_[file_index_]);
115 assert(bytes_read >= frame_size_); 110 assert(bytes_read >= frame_size_);
116 } 111 }
117 112
118 size_t half_width = (width_ + 1) / 2; 113 last_read_frame_.CreateEmptyFrame(
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_), 114 static_cast<int>(width_), static_cast<int>(height_),
123 static_cast<int>(width_), static_cast<int>(half_width), 115 static_cast<int>(width_), static_cast<int>((width_ + 1) / 2),
124 static_cast<int>(half_width)); 116 static_cast<int>((width_ + 1) / 2));
125 libyuv::I420Copy( 117
126 frame_buffer_.get(), static_cast<int>(width_), 118 ConvertToI420(kI420, frame_buffer_.get(), 0, 0, static_cast<int>(width_),
127 frame_buffer_.get() + size_y, static_cast<int>(half_width), 119 static_cast<int>(height_), 0, kVideoRotation_0,
128 frame_buffer_.get() + size_y + size_uv, static_cast<int>(half_width), 120 &last_read_frame_);
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 } 121 }
134 122
135 private: 123 private:
136 size_t file_index_; 124 size_t file_index_;
137 const std::vector<FILE*> files_; 125 const std::vector<FILE*> files_;
138 const size_t width_; 126 const size_t width_;
139 const size_t height_; 127 const size_t height_;
140 const size_t frame_size_; 128 const size_t frame_size_;
141 const std::unique_ptr<uint8_t[]> frame_buffer_; 129 const std::unique_ptr<uint8_t[]> frame_buffer_;
142 const int frame_display_count_; 130 const int frame_display_count_;
143 int current_display_count_; 131 int current_display_count_;
144 rtc::scoped_refptr<I420Buffer> last_read_buffer_; 132 VideoFrame last_read_frame_;
145 std::unique_ptr<VideoFrame> temp_frame_; 133 VideoFrame temp_frame_copy_;
146 }; 134 };
147 135
148 class ScrollingImageFrameGenerator : public FrameGenerator { 136 class ScrollingImageFrameGenerator : public FrameGenerator {
149 public: 137 public:
150 ScrollingImageFrameGenerator(Clock* clock, 138 ScrollingImageFrameGenerator(Clock* clock,
151 const std::vector<FILE*>& files, 139 const std::vector<FILE*>& files,
152 size_t source_width, 140 size_t source_width,
153 size_t source_height, 141 size_t source_height,
154 size_t target_width, 142 size_t target_width,
155 size_t target_height, 143 size_t target_height,
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
289 files.push_back(file); 277 files.push_back(file);
290 } 278 }
291 279
292 return new ScrollingImageFrameGenerator( 280 return new ScrollingImageFrameGenerator(
293 clock, files, source_width, source_height, target_width, target_height, 281 clock, files, source_width, source_height, target_width, target_height,
294 scroll_time_ms, pause_time_ms); 282 scroll_time_ms, pause_time_ms);
295 } 283 }
296 284
297 } // namespace test 285 } // namespace test
298 } // namespace webrtc 286 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/test/fake_texture_frame.h ('k') | webrtc/test/testsupport/metrics/video_metrics.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698