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

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

Issue 1258803003: Revert "Add a frame generator that allows scrolling over a larger still image, for use with new scr… (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Created 5 years, 4 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/frame_generator.h ('k') | webrtc/video/screenshare_loopback.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 "webrtc/base/checks.h" 16 #include "webrtc/base/checks.h"
17 #include "webrtc/common_video/libyuv/include/webrtc_libyuv.h" 17 #include "webrtc/common_video/libyuv/include/webrtc_libyuv.h"
18 #include "webrtc/system_wrappers/interface/clock.h"
19 18
20 namespace webrtc { 19 namespace webrtc {
21 namespace test { 20 namespace test {
22 namespace { 21 namespace {
23 22
24 class ChromaGenerator : public FrameGenerator { 23 class ChromaGenerator : public FrameGenerator {
25 public: 24 public:
26 ChromaGenerator(size_t width, size_t height) 25 ChromaGenerator(size_t width, size_t height)
27 : angle_(0.0), width_(width), height_(height) { 26 : angle_(0.0), width_(width), height_(height) {
28 assert(width > 0); 27 assert(width > 0);
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
120 const std::vector<FILE*> files_; 119 const std::vector<FILE*> files_;
121 const size_t width_; 120 const size_t width_;
122 const size_t height_; 121 const size_t height_;
123 const size_t frame_size_; 122 const size_t frame_size_;
124 const rtc::scoped_ptr<uint8_t[]> frame_buffer_; 123 const rtc::scoped_ptr<uint8_t[]> frame_buffer_;
125 const int frame_display_count_; 124 const int frame_display_count_;
126 int current_display_count_; 125 int current_display_count_;
127 VideoFrame last_read_frame_; 126 VideoFrame last_read_frame_;
128 VideoFrame temp_frame_copy_; 127 VideoFrame temp_frame_copy_;
129 }; 128 };
130
131 class ScrollingImageFrameGenerator : public FrameGenerator {
132 public:
133 ScrollingImageFrameGenerator(Clock* clock,
134 const std::vector<FILE*>& files,
135 size_t source_width,
136 size_t source_height,
137 size_t target_width,
138 size_t target_height,
139 int64_t scroll_time_ms,
140 int64_t pause_time_ms)
141 : clock_(clock),
142 start_time_(clock->TimeInMilliseconds()),
143 scroll_time_(scroll_time_ms),
144 pause_time_(pause_time_ms),
145 num_frames_(files.size()),
146 current_frame_num_(num_frames_ - 1),
147 current_source_frame_(nullptr),
148 file_generator_(files, source_width, source_height, 1) {
149 DCHECK(clock_ != nullptr);
150 DCHECK_GT(num_frames_, 0u);
151 DCHECK_GE(source_height, target_height);
152 DCHECK_GE(source_width, target_width);
153 DCHECK_GE(scroll_time_ms, 0);
154 DCHECK_GE(pause_time_ms, 0);
155 DCHECK_GT(scroll_time_ms + pause_time_ms, 0);
156 current_frame_.CreateEmptyFrame(target_width, target_height, target_width,
157 (target_width + 1) / 2,
158 (target_width + 1) / 2);
159 }
160
161 virtual ~ScrollingImageFrameGenerator() {}
162
163 VideoFrame* NextFrame() override {
164 const int64_t kFrameDisplayTime = scroll_time_ + pause_time_;
165 const int64_t now = clock_->TimeInMilliseconds();
166 int64_t ms_since_start = now - start_time_;
167
168 size_t frame_num = (ms_since_start / kFrameDisplayTime) % num_frames_;
169 UpdateSourceFrame(frame_num);
170
171 double scroll_factor;
172 int64_t time_into_frame = ms_since_start % kFrameDisplayTime;
173 if (time_into_frame < scroll_time_) {
174 scroll_factor = static_cast<double>(time_into_frame) / scroll_time_;
175 } else {
176 scroll_factor = 1.0;
177 }
178 CropSourceToScrolledImage(scroll_factor);
179
180 return &current_frame_;
181 }
182
183 void UpdateSourceFrame(size_t frame_num) {
184 while (current_frame_num_ != frame_num) {
185 current_source_frame_ = file_generator_.NextFrame();
186 current_frame_num_ = (current_frame_num_ + 1) % num_frames_;
187 }
188 DCHECK(current_source_frame_ != nullptr);
189 }
190
191 void CropSourceToScrolledImage(double scroll_factor) {
192 const int kTargetWidth = current_frame_.width();
193 const int kTargetHeight = current_frame_.height();
194 int scroll_margin_x = current_source_frame_->width() - kTargetWidth;
195 int pixels_scrolled_x =
196 static_cast<int>(scroll_margin_x * scroll_factor + 0.5);
197 int scroll_margin_y = current_source_frame_->height() - kTargetHeight;
198 int pixels_scrolled_y =
199 static_cast<int>(scroll_margin_y * scroll_factor + 0.5);
200
201 int offset_y = (current_source_frame_->stride(PlaneType::kYPlane) *
202 pixels_scrolled_y) +
203 pixels_scrolled_x;
204 int offset_u = (current_source_frame_->stride(PlaneType::kUPlane) *
205 (pixels_scrolled_y / 2)) +
206 (pixels_scrolled_x / 2);
207 int offset_v = (current_source_frame_->stride(PlaneType::kVPlane) *
208 (pixels_scrolled_y / 2)) +
209 (pixels_scrolled_x / 2);
210
211 current_frame_.CreateFrame(
212 &current_source_frame_->buffer(PlaneType::kYPlane)[offset_y],
213 &current_source_frame_->buffer(PlaneType::kUPlane)[offset_u],
214 &current_source_frame_->buffer(PlaneType::kVPlane)[offset_v],
215 kTargetWidth, kTargetHeight,
216 current_source_frame_->stride(PlaneType::kYPlane),
217 current_source_frame_->stride(PlaneType::kUPlane),
218 current_source_frame_->stride(PlaneType::kVPlane));
219 }
220
221 Clock* const clock_;
222 const int64_t start_time_;
223 const int64_t scroll_time_;
224 const int64_t pause_time_;
225 const size_t num_frames_;
226 size_t current_frame_num_;
227 VideoFrame* current_source_frame_;
228 VideoFrame current_frame_;
229 YuvFileGenerator file_generator_;
230 };
231
232 } // namespace 129 } // namespace
233 130
234 FrameGenerator* FrameGenerator::CreateChromaGenerator(size_t width, 131 FrameGenerator* FrameGenerator::CreateChromaGenerator(size_t width,
235 size_t height) { 132 size_t height) {
236 return new ChromaGenerator(width, height); 133 return new ChromaGenerator(width, height);
237 } 134 }
238 135
239 FrameGenerator* FrameGenerator::CreateFromYuvFile( 136 FrameGenerator* FrameGenerator::CreateFromYuvFile(
240 std::vector<std::string> filenames, 137 std::vector<std::string> filenames,
241 size_t width, 138 size_t width,
242 size_t height, 139 size_t height,
243 int frame_repeat_count) { 140 int frame_repeat_count) {
244 assert(!filenames.empty()); 141 assert(!filenames.empty());
245 std::vector<FILE*> files; 142 std::vector<FILE*> files;
246 for (const std::string& filename : filenames) { 143 for (const std::string& filename : filenames) {
247 FILE* file = fopen(filename.c_str(), "rb"); 144 FILE* file = fopen(filename.c_str(), "rb");
248 DCHECK(file != nullptr); 145 DCHECK(file != nullptr);
249 files.push_back(file); 146 files.push_back(file);
250 } 147 }
251 148
252 return new YuvFileGenerator(files, width, height, frame_repeat_count); 149 return new YuvFileGenerator(files, width, height, frame_repeat_count);
253 } 150 }
254 151
255 FrameGenerator* FrameGenerator::CreateScrollingInputFromYuvFiles(
256 Clock* clock,
257 std::vector<std::string> filenames,
258 size_t source_width,
259 size_t source_height,
260 size_t target_width,
261 size_t target_height,
262 int64_t scroll_time_ms,
263 int64_t pause_time_ms) {
264 assert(!filenames.empty());
265 std::vector<FILE*> files;
266 for (const std::string& filename : filenames) {
267 FILE* file = fopen(filename.c_str(), "rb");
268 DCHECK(file != nullptr);
269 files.push_back(file);
270 }
271
272 return new ScrollingImageFrameGenerator(
273 clock, files, source_width, source_height, target_width, target_height,
274 scroll_time_ms, pause_time_ms);
275 }
276
277 } // namespace test 152 } // namespace test
278 } // namespace webrtc 153 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/test/frame_generator.h ('k') | webrtc/video/screenshare_loopback.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698