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

Side by Side Diff: webrtc/media/base/videoadapter_unittest.cc

Issue 1982983003: VideoAdapter: Drop frames based on actual fps instead of expected fps (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Add jitter test Created 4 years, 7 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/media/base/videoadapter.cc ('k') | webrtc/media/base/videocapturer.h » ('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) 2010 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2010 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 10
(...skipping 10 matching lines...) Expand all
21 #include "webrtc/media/base/testutils.h" 21 #include "webrtc/media/base/testutils.h"
22 #include "webrtc/media/base/videoadapter.h" 22 #include "webrtc/media/base/videoadapter.h"
23 23
24 namespace cricket { 24 namespace cricket {
25 25
26 class VideoAdapterTest : public testing::Test { 26 class VideoAdapterTest : public testing::Test {
27 public: 27 public:
28 virtual void SetUp() { 28 virtual void SetUp() {
29 capturer_.reset(new FakeVideoCapturer); 29 capturer_.reset(new FakeVideoCapturer);
30 capture_format_ = capturer_->GetSupportedFormats()->at(0); 30 capture_format_ = capturer_->GetSupportedFormats()->at(0);
31 capture_format_.interval = VideoFormat::FpsToInterval(50); 31 capture_format_.interval = VideoFormat::FpsToInterval(30);
32 adapter_.SetExpectedInputFrameInterval(capture_format_.interval);
33 32
34 listener_.reset(new VideoCapturerListener(&adapter_)); 33 listener_.reset(new VideoCapturerListener(&adapter_));
35 capturer_->SignalFrameCaptured.connect( 34 capturer_->SignalFrameCaptured.connect(
36 listener_.get(), &VideoCapturerListener::OnFrameCaptured); 35 listener_.get(), &VideoCapturerListener::OnFrameCaptured);
37 } 36 }
38 37
39 virtual void TearDown() { 38 virtual void TearDown() {
40 // Explicitly disconnect the VideoCapturer before to avoid data races 39 // Explicitly disconnect the VideoCapturer before to avoid data races
41 // (frames delivered to VideoCapturerListener while it's being destructed). 40 // (frames delivered to VideoCapturerListener while it's being destructed).
42 capturer_->SignalFrameCaptured.disconnect_all(); 41 capturer_->SignalFrameCaptured.disconnect_all();
(...skipping 23 matching lines...) Expand all
66 void OnFrameCaptured(VideoCapturer* capturer, 65 void OnFrameCaptured(VideoCapturer* capturer,
67 const CapturedFrame* captured_frame) { 66 const CapturedFrame* captured_frame) {
68 rtc::CritScope lock(&crit_); 67 rtc::CritScope lock(&crit_);
69 const int in_width = captured_frame->width; 68 const int in_width = captured_frame->width;
70 const int in_height = abs(captured_frame->height); 69 const int in_height = abs(captured_frame->height);
71 int cropped_width; 70 int cropped_width;
72 int cropped_height; 71 int cropped_height;
73 int out_width; 72 int out_width;
74 int out_height; 73 int out_height;
75 video_adapter_->AdaptFrameResolution(in_width, in_height, 74 video_adapter_->AdaptFrameResolution(in_width, in_height,
75 captured_frame->time_stamp,
76 &cropped_width, &cropped_height, 76 &cropped_width, &cropped_height,
77 &out_width, &out_height); 77 &out_width, &out_height);
78 if (out_width != 0 && out_height != 0) { 78 if (out_width != 0 && out_height != 0) {
79 cropped_width_ = cropped_width; 79 cropped_width_ = cropped_width;
80 cropped_height_ = cropped_height; 80 cropped_height_ = cropped_height;
81 out_width_ = out_width; 81 out_width_ = out_width;
82 out_height_ = out_height; 82 out_height_ = out_height;
83 last_adapt_was_no_op_ = 83 last_adapt_was_no_op_ =
84 (in_width == cropped_width && in_height == cropped_height && 84 (in_width == cropped_width && in_height == cropped_height &&
85 in_width == out_width && in_height == out_height); 85 in_width == out_width && in_height == out_height);
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
163 // Verify no crash and that frames aren't dropped. 163 // Verify no crash and that frames aren't dropped.
164 VideoCapturerListener::Stats stats = listener_->GetStats(); 164 VideoCapturerListener::Stats stats = listener_->GetStats();
165 EXPECT_GE(stats.captured_frames, 10); 165 EXPECT_GE(stats.captured_frames, 10);
166 EXPECT_EQ(0, stats.dropped_frames); 166 EXPECT_EQ(0, stats.dropped_frames);
167 VerifyAdaptedResolution(stats, capture_format_.width, capture_format_.height, 167 VerifyAdaptedResolution(stats, capture_format_.width, capture_format_.height,
168 capture_format_.width, capture_format_.height); 168 capture_format_.width, capture_format_.height);
169 } 169 }
170 170
171 // Adapt the frame rate to be half of the capture rate at the beginning. Expect 171 // Adapt the frame rate to be half of the capture rate at the beginning. Expect
172 // the number of dropped frames to be half of the number the captured frames. 172 // the number of dropped frames to be half of the number the captured frames.
173 TEST_F(VideoAdapterTest, AdaptFramerate) { 173 TEST_F(VideoAdapterTest, AdaptFramerateToHalf) {
174 VideoFormat request_format = capture_format_; 174 VideoFormat request_format = capture_format_;
175 request_format.interval *= 2; 175 request_format.interval *= 2;
176 adapter_.OnOutputFormatRequest(request_format); 176 adapter_.OnOutputFormatRequest(request_format);
177 EXPECT_EQ(CS_RUNNING, capturer_->Start(capture_format_)); 177 EXPECT_EQ(CS_RUNNING, capturer_->Start(capture_format_));
178
179 // Capture 10 frames and verify that every other frame is dropped. The first
180 // frame should not be dropped.
181 capturer_->CaptureFrame();
182 EXPECT_GE(listener_->GetStats().captured_frames, 1);
183 EXPECT_EQ(0, listener_->GetStats().dropped_frames);
184
185 capturer_->CaptureFrame();
186 EXPECT_GE(listener_->GetStats().captured_frames, 2);
187 EXPECT_EQ(0, listener_->GetStats().dropped_frames);
188
189 capturer_->CaptureFrame();
190 EXPECT_GE(listener_->GetStats().captured_frames, 3);
191 EXPECT_EQ(1, listener_->GetStats().dropped_frames);
192
193 capturer_->CaptureFrame();
194 EXPECT_GE(listener_->GetStats().captured_frames, 4);
195 EXPECT_EQ(1, listener_->GetStats().dropped_frames);
196
197 capturer_->CaptureFrame();
198 EXPECT_GE(listener_->GetStats().captured_frames, 5);
199 EXPECT_EQ(2, listener_->GetStats().dropped_frames);
200
201 capturer_->CaptureFrame();
202 EXPECT_GE(listener_->GetStats().captured_frames, 6);
203 EXPECT_EQ(2, listener_->GetStats().dropped_frames);
204
205 capturer_->CaptureFrame();
206 EXPECT_GE(listener_->GetStats().captured_frames, 7);
207 EXPECT_EQ(3, listener_->GetStats().dropped_frames);
208
209 capturer_->CaptureFrame();
210 EXPECT_GE(listener_->GetStats().captured_frames, 8);
211 EXPECT_EQ(3, listener_->GetStats().dropped_frames);
212
213 capturer_->CaptureFrame();
214 EXPECT_GE(listener_->GetStats().captured_frames, 9);
215 EXPECT_EQ(4, listener_->GetStats().dropped_frames);
216
217 capturer_->CaptureFrame();
218 EXPECT_GE(listener_->GetStats().captured_frames, 10);
219 EXPECT_EQ(4, listener_->GetStats().dropped_frames);
220 }
221
222 // Adapt the frame rate to be two thirds of the capture rate at the beginning.
223 // Expect the number of dropped frames to be one thirds of the number the
224 // captured frames.
225 TEST_F(VideoAdapterTest, AdaptFramerateToTwoThirds) {
226 VideoFormat request_format = capture_format_;
227 request_format.interval = request_format.interval * 3 / 2;
228 adapter_.OnOutputFormatRequest(request_format);
229 EXPECT_EQ(CS_RUNNING, capturer_->Start(capture_format_));
230
231 // Capture 10 frames and verify that every third frame is dropped. The first
232 // frame should not be dropped.
233 capturer_->CaptureFrame();
234 EXPECT_GE(listener_->GetStats().captured_frames, 1);
235 EXPECT_EQ(0, listener_->GetStats().dropped_frames);
236
237 capturer_->CaptureFrame();
238 EXPECT_GE(listener_->GetStats().captured_frames, 2);
239 EXPECT_EQ(0, listener_->GetStats().dropped_frames);
240
241 capturer_->CaptureFrame();
242 EXPECT_GE(listener_->GetStats().captured_frames, 3);
243 EXPECT_EQ(1, listener_->GetStats().dropped_frames);
244
245 capturer_->CaptureFrame();
246 EXPECT_GE(listener_->GetStats().captured_frames, 4);
247 EXPECT_EQ(1, listener_->GetStats().dropped_frames);
248
249 capturer_->CaptureFrame();
250 EXPECT_GE(listener_->GetStats().captured_frames, 5);
251 EXPECT_EQ(1, listener_->GetStats().dropped_frames);
252
253 capturer_->CaptureFrame();
254 EXPECT_GE(listener_->GetStats().captured_frames, 6);
255 EXPECT_EQ(2, listener_->GetStats().dropped_frames);
256
257 capturer_->CaptureFrame();
258 EXPECT_GE(listener_->GetStats().captured_frames, 7);
259 EXPECT_EQ(2, listener_->GetStats().dropped_frames);
260
261 capturer_->CaptureFrame();
262 EXPECT_GE(listener_->GetStats().captured_frames, 8);
263 EXPECT_EQ(2, listener_->GetStats().dropped_frames);
264
265 capturer_->CaptureFrame();
266 EXPECT_GE(listener_->GetStats().captured_frames, 9);
267 EXPECT_EQ(3, listener_->GetStats().dropped_frames);
268
269 capturer_->CaptureFrame();
270 EXPECT_GE(listener_->GetStats().captured_frames, 10);
271 EXPECT_EQ(3, listener_->GetStats().dropped_frames);
272 }
273
274 // Request frame rate twice as high as captured frame rate. Expect no frame
275 // drop.
276 TEST_F(VideoAdapterTest, AdaptFramerateHighLimit) {
277 VideoFormat request_format = capture_format_;
278 request_format.interval /= 2;
279 adapter_.OnOutputFormatRequest(request_format);
280 EXPECT_EQ(CS_RUNNING, capturer_->Start(capture_format_));
178 for (int i = 0; i < 10; ++i) 281 for (int i = 0; i < 10; ++i)
179 capturer_->CaptureFrame(); 282 capturer_->CaptureFrame();
180 283
181 // Verify frame drop and no resolution change. 284 // Verify no frame drop.
182 VideoCapturerListener::Stats stats = listener_->GetStats(); 285 EXPECT_EQ(0, listener_->GetStats().dropped_frames);
183 EXPECT_GE(stats.captured_frames, 10);
184 EXPECT_EQ(stats.captured_frames / 2, stats.dropped_frames);
185 VerifyAdaptedResolution(stats, capture_format_.width, capture_format_.height,
186 capture_format_.width, capture_format_.height);
187 } 286 }
188 287
189 // Adapt the frame rate to be half of the capture rate at the beginning. Expect 288 // After the first timestamp, add a big offset to the timestamps. Expect that
190 // the number of dropped frames to be half of the number the captured frames. 289 // the adapter is conservative and resets to the new offset and does not drop
191 TEST_F(VideoAdapterTest, AdaptFramerateVariable) { 290 // any frame.
192 VideoFormat request_format = capture_format_; 291 TEST_F(VideoAdapterTest, AdaptFramerateTimestampOffset) {
193 request_format.interval = request_format.interval * 3 / 2; 292 const int64_t capture_interval = VideoFormat::FpsToInterval(30);
194 adapter_.OnOutputFormatRequest(request_format); 293 adapter_.OnOutputFormatRequest(
195 EXPECT_EQ(CS_RUNNING, capturer_->Start(capture_format_)); 294 VideoFormat(640, 480, capture_interval, cricket::FOURCC_ANY));
196 for (int i = 0; i < 30; ++i)
197 capturer_->CaptureFrame();
198 295
199 // Verify frame drop and no resolution change. 296 const int64_t first_timestamp = 0;
200 VideoCapturerListener::Stats stats = listener_->GetStats(); 297 adapter_.AdaptFrameResolution(640, 480, first_timestamp,
201 EXPECT_GE(stats.captured_frames, 30); 298 &cropped_width_, &cropped_height_,
202 // Verify 2 / 3 kept (20) and 1 / 3 dropped (10). 299 &out_width_, &out_height_);
203 EXPECT_EQ(stats.captured_frames * 1 / 3, stats.dropped_frames); 300 EXPECT_GT(out_width_, 0);
204 VerifyAdaptedResolution(stats, capture_format_.width, capture_format_.height, 301 EXPECT_GT(out_height_, 0);
205 capture_format_.width, capture_format_.height); 302
303 const int64_t big_offset = -987654321LL * 1000;
304 const int64_t second_timestamp = big_offset;
305 adapter_.AdaptFrameResolution(640, 480, second_timestamp,
306 &cropped_width_, &cropped_height_,
307 &out_width_, &out_height_);
308 EXPECT_GT(out_width_, 0);
309 EXPECT_GT(out_height_, 0);
310
311 const int64_t third_timestamp = big_offset + capture_interval;
312 adapter_.AdaptFrameResolution(640, 480, third_timestamp,
313 &cropped_width_, &cropped_height_,
314 &out_width_, &out_height_);
315 EXPECT_GT(out_width_, 0);
316 EXPECT_GT(out_height_, 0);
317 }
318
319 // Request 30 fps and send 30 fps with jitter. Expect that no frame is dropped.
320 TEST_F(VideoAdapterTest, AdaptFramerateTimestampJitter) {
321 const int64_t capture_interval = VideoFormat::FpsToInterval(30);
322 adapter_.OnOutputFormatRequest(
323 VideoFormat(640, 480, capture_interval, cricket::FOURCC_ANY));
324
325 adapter_.AdaptFrameResolution(640, 480, capture_interval * 0 / 10,
326 &cropped_width_, &cropped_height_,
327 &out_width_, &out_height_);
328 EXPECT_GT(out_width_, 0);
329 EXPECT_GT(out_height_, 0);
330
331 adapter_.AdaptFrameResolution(640, 480, capture_interval * 10 / 10 - 1,
332 &cropped_width_, &cropped_height_,
333 &out_width_, &out_height_);
334 EXPECT_GT(out_width_, 0);
335 EXPECT_GT(out_height_, 0);
336
337 adapter_.AdaptFrameResolution(640, 480, capture_interval * 25 / 10,
338 &cropped_width_, &cropped_height_,
339 &out_width_, &out_height_);
340 EXPECT_GT(out_width_, 0);
341 EXPECT_GT(out_height_, 0);
342
343 adapter_.AdaptFrameResolution(640, 480, capture_interval * 30 / 10,
344 &cropped_width_, &cropped_height_,
345 &out_width_, &out_height_);
346 EXPECT_GT(out_width_, 0);
347 EXPECT_GT(out_height_, 0);
348
349 adapter_.AdaptFrameResolution(640, 480, capture_interval * 35 / 10,
350 &cropped_width_, &cropped_height_,
351 &out_width_, &out_height_);
352 EXPECT_GT(out_width_, 0);
353 EXPECT_GT(out_height_, 0);
354
355 adapter_.AdaptFrameResolution(640, 480, capture_interval * 50 / 10,
356 &cropped_width_, &cropped_height_,
357 &out_width_, &out_height_);
358 EXPECT_GT(out_width_, 0);
359 EXPECT_GT(out_height_, 0);
206 } 360 }
207 361
208 // Adapt the frame rate to be half of the capture rate after capturing no less 362 // Adapt the frame rate to be half of the capture rate after capturing no less
209 // than 10 frames. Expect no frame dropped before adaptation and frame dropped 363 // than 10 frames. Expect no frame dropped before adaptation and frame dropped
210 // after adaptation. 364 // after adaptation.
211 TEST_F(VideoAdapterTest, AdaptFramerateOntheFly) { 365 TEST_F(VideoAdapterTest, AdaptFramerateOntheFly) {
212 VideoFormat request_format = capture_format_; 366 VideoFormat request_format = capture_format_;
213 adapter_.OnOutputFormatRequest(request_format); 367 adapter_.OnOutputFormatRequest(request_format);
214 EXPECT_EQ(CS_RUNNING, capturer_->Start(capture_format_)); 368 EXPECT_EQ(CS_RUNNING, capturer_->Start(capture_format_));
215 for (int i = 0; i < 10; ++i) 369 for (int i = 0; i < 10; ++i)
(...skipping 14 matching lines...) Expand all
230 } 384 }
231 385
232 // Set a very high output pixel resolution. Expect no cropping or resolution 386 // Set a very high output pixel resolution. Expect no cropping or resolution
233 // change. 387 // change.
234 TEST_F(VideoAdapterTest, AdaptFrameResolutionHighLimit) { 388 TEST_F(VideoAdapterTest, AdaptFrameResolutionHighLimit) {
235 VideoFormat output_format = capture_format_; 389 VideoFormat output_format = capture_format_;
236 output_format.width *= 10; 390 output_format.width *= 10;
237 output_format.height *= 10; 391 output_format.height *= 10;
238 adapter_.OnOutputFormatRequest(output_format); 392 adapter_.OnOutputFormatRequest(output_format);
239 adapter_.AdaptFrameResolution(capture_format_.width, capture_format_.height, 393 adapter_.AdaptFrameResolution(capture_format_.width, capture_format_.height,
240 &cropped_width_, &cropped_height_, 394 0, &cropped_width_, &cropped_height_,
241 &out_width_, &out_height_); 395 &out_width_, &out_height_);
242 EXPECT_EQ(capture_format_.width, cropped_width_); 396 EXPECT_EQ(capture_format_.width, cropped_width_);
243 EXPECT_EQ(capture_format_.height, cropped_height_); 397 EXPECT_EQ(capture_format_.height, cropped_height_);
244 EXPECT_EQ(capture_format_.width, out_width_); 398 EXPECT_EQ(capture_format_.width, out_width_);
245 EXPECT_EQ(capture_format_.height, out_height_); 399 EXPECT_EQ(capture_format_.height, out_height_);
246 } 400 }
247 401
248 // Adapt the frame resolution to be the same as capture resolution. Expect no 402 // Adapt the frame resolution to be the same as capture resolution. Expect no
249 // cropping or resolution change. 403 // cropping or resolution change.
250 TEST_F(VideoAdapterTest, AdaptFrameResolutionIdentical) { 404 TEST_F(VideoAdapterTest, AdaptFrameResolutionIdentical) {
251 adapter_.OnOutputFormatRequest(capture_format_); 405 adapter_.OnOutputFormatRequest(capture_format_);
252 adapter_.AdaptFrameResolution(capture_format_.width, capture_format_.height, 406 adapter_.AdaptFrameResolution(capture_format_.width, capture_format_.height,
253 &cropped_width_, &cropped_height_, 407 0, &cropped_width_, &cropped_height_,
254 &out_width_, &out_height_); 408 &out_width_, &out_height_);
255 EXPECT_EQ(capture_format_.width, cropped_width_); 409 EXPECT_EQ(capture_format_.width, cropped_width_);
256 EXPECT_EQ(capture_format_.height, cropped_height_); 410 EXPECT_EQ(capture_format_.height, cropped_height_);
257 EXPECT_EQ(capture_format_.width, out_width_); 411 EXPECT_EQ(capture_format_.width, out_width_);
258 EXPECT_EQ(capture_format_.height, out_height_); 412 EXPECT_EQ(capture_format_.height, out_height_);
259 } 413 }
260 414
261 // Adapt the frame resolution to be a quarter of the capture resolution. Expect 415 // Adapt the frame resolution to be a quarter of the capture resolution. Expect
262 // no cropping, but a resolution change. 416 // no cropping, but a resolution change.
263 TEST_F(VideoAdapterTest, AdaptFrameResolutionQuarter) { 417 TEST_F(VideoAdapterTest, AdaptFrameResolutionQuarter) {
264 VideoFormat request_format = capture_format_; 418 VideoFormat request_format = capture_format_;
265 request_format.width /= 2; 419 request_format.width /= 2;
266 request_format.height /= 2; 420 request_format.height /= 2;
267 adapter_.OnOutputFormatRequest(request_format); 421 adapter_.OnOutputFormatRequest(request_format);
268 adapter_.AdaptFrameResolution(capture_format_.width, capture_format_.height, 422 adapter_.AdaptFrameResolution(capture_format_.width, capture_format_.height,
269 &cropped_width_, &cropped_height_, 423 0, &cropped_width_, &cropped_height_,
270 &out_width_, &out_height_); 424 &out_width_, &out_height_);
271 EXPECT_EQ(capture_format_.width, cropped_width_); 425 EXPECT_EQ(capture_format_.width, cropped_width_);
272 EXPECT_EQ(capture_format_.height, cropped_height_); 426 EXPECT_EQ(capture_format_.height, cropped_height_);
273 EXPECT_EQ(request_format.width, out_width_); 427 EXPECT_EQ(request_format.width, out_width_);
274 EXPECT_EQ(request_format.height, out_height_); 428 EXPECT_EQ(request_format.height, out_height_);
275 } 429 }
276 430
277 // Adapt the pixel resolution to 0. Expect frame drop. 431 // Adapt the pixel resolution to 0. Expect frame drop.
278 TEST_F(VideoAdapterTest, AdaptFrameResolutionDrop) { 432 TEST_F(VideoAdapterTest, AdaptFrameResolutionDrop) {
279 VideoFormat output_format = capture_format_; 433 VideoFormat output_format = capture_format_;
280 output_format.width = 0; 434 output_format.width = 0;
281 output_format.height = 0; 435 output_format.height = 0;
282 adapter_.OnOutputFormatRequest(output_format); 436 adapter_.OnOutputFormatRequest(output_format);
283 adapter_.AdaptFrameResolution(capture_format_.width, capture_format_.height, 437 adapter_.AdaptFrameResolution(capture_format_.width, capture_format_.height,
284 &cropped_width_, &cropped_height_, 438 0, &cropped_width_, &cropped_height_,
285 &out_width_, &out_height_); 439 &out_width_, &out_height_);
286 EXPECT_EQ(0, out_width_); 440 EXPECT_EQ(0, out_width_);
287 EXPECT_EQ(0, out_height_); 441 EXPECT_EQ(0, out_height_);
288 } 442 }
289 443
290 // Adapt the frame resolution to be a quarter of the capture resolution at the 444 // Adapt the frame resolution to be a quarter of the capture resolution at the
291 // beginning. Expect no cropping but a resolution change. 445 // beginning. Expect no cropping but a resolution change.
292 TEST_F(VideoAdapterTest, AdaptResolution) { 446 TEST_F(VideoAdapterTest, AdaptResolution) {
293 VideoFormat request_format = capture_format_; 447 VideoFormat request_format = capture_format_;
294 request_format.width /= 2; 448 request_format.width /= 2;
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
341 for (int i = 0; i < 10; ++i) 495 for (int i = 0; i < 10; ++i)
342 capturer_->CaptureFrame(); 496 capturer_->CaptureFrame();
343 497
344 // Verify all frames are dropped. 498 // Verify all frames are dropped.
345 VideoCapturerListener::Stats stats = listener_->GetStats(); 499 VideoCapturerListener::Stats stats = listener_->GetStats();
346 EXPECT_GE(stats.captured_frames, 10); 500 EXPECT_GE(stats.captured_frames, 10);
347 EXPECT_EQ(stats.captured_frames, stats.dropped_frames); 501 EXPECT_EQ(stats.captured_frames, stats.dropped_frames);
348 } 502 }
349 503
350 TEST_F(VideoAdapterTest, TestOnOutputFormatRequest) { 504 TEST_F(VideoAdapterTest, TestOnOutputFormatRequest) {
351 VideoFormat format(640, 400, VideoFormat::FpsToInterval(30), 0); 505 VideoFormat format(640, 400, 0, 0);
352 adapter_.SetExpectedInputFrameInterval(VideoFormat::FpsToInterval(30)); 506 adapter_.AdaptFrameResolution(640, 400, 0,
353 adapter_.AdaptFrameResolution(640, 400,
354 &cropped_width_, &cropped_height_, 507 &cropped_width_, &cropped_height_,
355 &out_width_, &out_height_); 508 &out_width_, &out_height_);
356 EXPECT_EQ(640, cropped_width_); 509 EXPECT_EQ(640, cropped_width_);
357 EXPECT_EQ(400, cropped_height_); 510 EXPECT_EQ(400, cropped_height_);
358 EXPECT_EQ(640, out_width_); 511 EXPECT_EQ(640, out_width_);
359 EXPECT_EQ(400, out_height_); 512 EXPECT_EQ(400, out_height_);
360 513
361 // Format request 640x400. 514 // Format request 640x400.
362 format.height = 400; 515 format.height = 400;
363 adapter_.OnOutputFormatRequest(format); 516 adapter_.OnOutputFormatRequest(format);
364 adapter_.AdaptFrameResolution(640, 400, 517 adapter_.AdaptFrameResolution(640, 400, 0,
365 &cropped_width_, &cropped_height_, 518 &cropped_width_, &cropped_height_,
366 &out_width_, &out_height_); 519 &out_width_, &out_height_);
367 EXPECT_EQ(640, cropped_width_); 520 EXPECT_EQ(640, cropped_width_);
368 EXPECT_EQ(400, cropped_height_); 521 EXPECT_EQ(400, cropped_height_);
369 EXPECT_EQ(640, out_width_); 522 EXPECT_EQ(640, out_width_);
370 EXPECT_EQ(400, out_height_); 523 EXPECT_EQ(400, out_height_);
371 524
372 // Request 1280x720, higher than input, but aspect 16:9. Expect cropping but 525 // Request 1280x720, higher than input, but aspect 16:9. Expect cropping but
373 // no scaling. 526 // no scaling.
374 format.width = 1280; 527 format.width = 1280;
375 format.height = 720; 528 format.height = 720;
376 adapter_.OnOutputFormatRequest(format); 529 adapter_.OnOutputFormatRequest(format);
377 adapter_.AdaptFrameResolution(640, 400, 530 adapter_.AdaptFrameResolution(640, 400, 0,
378 &cropped_width_, &cropped_height_, 531 &cropped_width_, &cropped_height_,
379 &out_width_, &out_height_); 532 &out_width_, &out_height_);
380 EXPECT_EQ(640, cropped_width_); 533 EXPECT_EQ(640, cropped_width_);
381 EXPECT_EQ(360, cropped_height_); 534 EXPECT_EQ(360, cropped_height_);
382 EXPECT_EQ(640, out_width_); 535 EXPECT_EQ(640, out_width_);
383 EXPECT_EQ(360, out_height_); 536 EXPECT_EQ(360, out_height_);
384 537
385 // Request 0x0. 538 // Request 0x0.
386 format.width = 0; 539 format.width = 0;
387 format.height = 0; 540 format.height = 0;
388 adapter_.OnOutputFormatRequest(format); 541 adapter_.OnOutputFormatRequest(format);
389 adapter_.AdaptFrameResolution(640, 400, 542 adapter_.AdaptFrameResolution(640, 400, 0,
390 &cropped_width_, &cropped_height_, 543 &cropped_width_, &cropped_height_,
391 &out_width_, &out_height_); 544 &out_width_, &out_height_);
392 EXPECT_EQ(0, out_width_); 545 EXPECT_EQ(0, out_width_);
393 EXPECT_EQ(0, out_height_); 546 EXPECT_EQ(0, out_height_);
394 547
395 // Request 320x200. Expect scaling, but no cropping. 548 // Request 320x200. Expect scaling, but no cropping.
396 format.width = 320; 549 format.width = 320;
397 format.height = 200; 550 format.height = 200;
398 adapter_.OnOutputFormatRequest(format); 551 adapter_.OnOutputFormatRequest(format);
399 adapter_.AdaptFrameResolution(640, 400, 552 adapter_.AdaptFrameResolution(640, 400, 0,
400 &cropped_width_, &cropped_height_, 553 &cropped_width_, &cropped_height_,
401 &out_width_, &out_height_); 554 &out_width_, &out_height_);
402 EXPECT_EQ(640, cropped_width_); 555 EXPECT_EQ(640, cropped_width_);
403 EXPECT_EQ(400, cropped_height_); 556 EXPECT_EQ(400, cropped_height_);
404 EXPECT_EQ(320, out_width_); 557 EXPECT_EQ(320, out_width_);
405 EXPECT_EQ(200, out_height_); 558 EXPECT_EQ(200, out_height_);
406 559
407 // Request resolution close to 2/3 scale. Expect adapt down. Scaling to 2/3 560 // Request resolution close to 2/3 scale. Expect adapt down. Scaling to 2/3
408 // is not optimized and not allowed, therefore 1/2 scaling will be used 561 // is not optimized and not allowed, therefore 1/2 scaling will be used
409 // instead. 562 // instead.
410 format.width = 424; 563 format.width = 424;
411 format.height = 265; 564 format.height = 265;
412 adapter_.OnOutputFormatRequest(format); 565 adapter_.OnOutputFormatRequest(format);
413 adapter_.AdaptFrameResolution(640, 400, 566 adapter_.AdaptFrameResolution(640, 400, 0,
414 &cropped_width_, &cropped_height_, 567 &cropped_width_, &cropped_height_,
415 &out_width_, &out_height_); 568 &out_width_, &out_height_);
416 EXPECT_EQ(640, cropped_width_); 569 EXPECT_EQ(640, cropped_width_);
417 EXPECT_EQ(400, cropped_height_); 570 EXPECT_EQ(400, cropped_height_);
418 EXPECT_EQ(320, out_width_); 571 EXPECT_EQ(320, out_width_);
419 EXPECT_EQ(200, out_height_); 572 EXPECT_EQ(200, out_height_);
420 573
421 // Request resolution of 3 / 8. Expect adapt down. 574 // Request resolution of 3 / 8. Expect adapt down.
422 format.width = 640 * 3 / 8; 575 format.width = 640 * 3 / 8;
423 format.height = 400 * 3 / 8; 576 format.height = 400 * 3 / 8;
424 adapter_.OnOutputFormatRequest(format); 577 adapter_.OnOutputFormatRequest(format);
425 adapter_.AdaptFrameResolution(640, 400, 578 adapter_.AdaptFrameResolution(640, 400, 0,
426 &cropped_width_, &cropped_height_, 579 &cropped_width_, &cropped_height_,
427 &out_width_, &out_height_); 580 &out_width_, &out_height_);
428 EXPECT_EQ(640, cropped_width_); 581 EXPECT_EQ(640, cropped_width_);
429 EXPECT_EQ(400, cropped_height_); 582 EXPECT_EQ(400, cropped_height_);
430 EXPECT_EQ(640 * 3 / 8, out_width_); 583 EXPECT_EQ(640 * 3 / 8, out_width_);
431 EXPECT_EQ(400 * 3 / 8, out_height_); 584 EXPECT_EQ(400 * 3 / 8, out_height_);
432 585
433 // Switch back up. Expect adapt. 586 // Switch back up. Expect adapt.
434 format.width = 320; 587 format.width = 320;
435 format.height = 200; 588 format.height = 200;
436 adapter_.OnOutputFormatRequest(format); 589 adapter_.OnOutputFormatRequest(format);
437 adapter_.AdaptFrameResolution(640, 400, 590 adapter_.AdaptFrameResolution(640, 400, 0,
438 &cropped_width_, &cropped_height_, 591 &cropped_width_, &cropped_height_,
439 &out_width_, &out_height_); 592 &out_width_, &out_height_);
440 EXPECT_EQ(640, cropped_width_); 593 EXPECT_EQ(640, cropped_width_);
441 EXPECT_EQ(400, cropped_height_); 594 EXPECT_EQ(400, cropped_height_);
442 EXPECT_EQ(320, out_width_); 595 EXPECT_EQ(320, out_width_);
443 EXPECT_EQ(200, out_height_); 596 EXPECT_EQ(200, out_height_);
444 597
445 // Format request 480x300. 598 // Format request 480x300.
446 format.width = 480; 599 format.width = 480;
447 format.height = 300; 600 format.height = 300;
448 adapter_.OnOutputFormatRequest(format); 601 adapter_.OnOutputFormatRequest(format);
449 adapter_.AdaptFrameResolution(640, 400, 602 adapter_.AdaptFrameResolution(640, 400, 0,
450 &cropped_width_, &cropped_height_, 603 &cropped_width_, &cropped_height_,
451 &out_width_, &out_height_); 604 &out_width_, &out_height_);
452 EXPECT_EQ(640, cropped_width_); 605 EXPECT_EQ(640, cropped_width_);
453 EXPECT_EQ(400, cropped_height_); 606 EXPECT_EQ(400, cropped_height_);
454 EXPECT_EQ(480, out_width_); 607 EXPECT_EQ(480, out_width_);
455 EXPECT_EQ(300, out_height_); 608 EXPECT_EQ(300, out_height_);
456 } 609 }
457 610
458 TEST_F(VideoAdapterTest, TestViewRequestPlusCameraSwitch) { 611 TEST_F(VideoAdapterTest, TestViewRequestPlusCameraSwitch) {
459 // Start at HD. 612 // Start at HD.
460 VideoFormat format(1280, 720, VideoFormat::FpsToInterval(30), 0); 613 VideoFormat format(1280, 720, 0, 0);
461 adapter_.SetExpectedInputFrameInterval(VideoFormat::FpsToInterval(30)); 614 adapter_.AdaptFrameResolution(1280, 720, 0,
462 adapter_.AdaptFrameResolution(1280, 720,
463 &cropped_width_, &cropped_height_, 615 &cropped_width_, &cropped_height_,
464 &out_width_, &out_height_); 616 &out_width_, &out_height_);
465 EXPECT_EQ(1280, cropped_width_); 617 EXPECT_EQ(1280, cropped_width_);
466 EXPECT_EQ(720, cropped_height_); 618 EXPECT_EQ(720, cropped_height_);
467 EXPECT_EQ(1280, out_width_); 619 EXPECT_EQ(1280, out_width_);
468 EXPECT_EQ(720, out_height_); 620 EXPECT_EQ(720, out_height_);
469 621
470 // Format request for VGA. 622 // Format request for VGA.
471 format.width = 640; 623 format.width = 640;
472 format.height = 360; 624 format.height = 360;
473 adapter_.OnOutputFormatRequest(format); 625 adapter_.OnOutputFormatRequest(format);
474 adapter_.AdaptFrameResolution(1280, 720, 626 adapter_.AdaptFrameResolution(1280, 720, 0,
475 &cropped_width_, &cropped_height_, 627 &cropped_width_, &cropped_height_,
476 &out_width_, &out_height_); 628 &out_width_, &out_height_);
477 EXPECT_EQ(1280, cropped_width_); 629 EXPECT_EQ(1280, cropped_width_);
478 EXPECT_EQ(720, cropped_height_); 630 EXPECT_EQ(720, cropped_height_);
479 EXPECT_EQ(640, out_width_); 631 EXPECT_EQ(640, out_width_);
480 EXPECT_EQ(360, out_height_); 632 EXPECT_EQ(360, out_height_);
481 633
482 // Now, the camera reopens at VGA. 634 // Now, the camera reopens at VGA.
483 // Both the frame and the output format should be 640x360. 635 // Both the frame and the output format should be 640x360.
484 adapter_.AdaptFrameResolution(640, 360, 636 adapter_.AdaptFrameResolution(640, 360, 0,
485 &cropped_width_, &cropped_height_, 637 &cropped_width_, &cropped_height_,
486 &out_width_, &out_height_); 638 &out_width_, &out_height_);
487 EXPECT_EQ(640, cropped_width_); 639 EXPECT_EQ(640, cropped_width_);
488 EXPECT_EQ(360, cropped_height_); 640 EXPECT_EQ(360, cropped_height_);
489 EXPECT_EQ(640, out_width_); 641 EXPECT_EQ(640, out_width_);
490 EXPECT_EQ(360, out_height_); 642 EXPECT_EQ(360, out_height_);
491 643
492 // And another view request comes in for 640x360, which should have no 644 // And another view request comes in for 640x360, which should have no
493 // real impact. 645 // real impact.
494 adapter_.OnOutputFormatRequest(format); 646 adapter_.OnOutputFormatRequest(format);
495 adapter_.AdaptFrameResolution(640, 360, 647 adapter_.AdaptFrameResolution(640, 360, 0,
496 &cropped_width_, &cropped_height_, 648 &cropped_width_, &cropped_height_,
497 &out_width_, &out_height_); 649 &out_width_, &out_height_);
498 EXPECT_EQ(640, cropped_width_); 650 EXPECT_EQ(640, cropped_width_);
499 EXPECT_EQ(360, cropped_height_); 651 EXPECT_EQ(360, cropped_height_);
500 EXPECT_EQ(640, out_width_); 652 EXPECT_EQ(640, out_width_);
501 EXPECT_EQ(360, out_height_); 653 EXPECT_EQ(360, out_height_);
502 } 654 }
503 655
504 TEST_F(VideoAdapterTest, TestVGAWidth) { 656 TEST_F(VideoAdapterTest, TestVGAWidth) {
505 // Reqeuested Output format is 640x360. 657 // Reqeuested Output format is 640x360.
506 VideoFormat format(640, 360, VideoFormat::FpsToInterval(30), FOURCC_I420); 658 VideoFormat format(640, 360, 0, FOURCC_I420);
507 adapter_.SetExpectedInputFrameInterval(VideoFormat::FpsToInterval(30));
508 adapter_.OnOutputFormatRequest(format); 659 adapter_.OnOutputFormatRequest(format);
509 660
510 adapter_.AdaptFrameResolution(640, 480, 661 adapter_.AdaptFrameResolution(640, 480, 0,
511 &cropped_width_, &cropped_height_, 662 &cropped_width_, &cropped_height_,
512 &out_width_, &out_height_); 663 &out_width_, &out_height_);
513 // Expect cropping. 664 // Expect cropping.
514 EXPECT_EQ(640, cropped_width_); 665 EXPECT_EQ(640, cropped_width_);
515 EXPECT_EQ(360, cropped_height_); 666 EXPECT_EQ(360, cropped_height_);
516 EXPECT_EQ(640, out_width_); 667 EXPECT_EQ(640, out_width_);
517 EXPECT_EQ(360, out_height_); 668 EXPECT_EQ(360, out_height_);
518 669
519 // But if frames come in at 640x360, we shouldn't adapt them down. 670 // But if frames come in at 640x360, we shouldn't adapt them down.
520 adapter_.AdaptFrameResolution(640, 360, 671 adapter_.AdaptFrameResolution(640, 360, 0,
521 &cropped_width_, &cropped_height_, 672 &cropped_width_, &cropped_height_,
522 &out_width_, &out_height_); 673 &out_width_, &out_height_);
523 EXPECT_EQ(640, cropped_width_); 674 EXPECT_EQ(640, cropped_width_);
524 EXPECT_EQ(360, cropped_height_); 675 EXPECT_EQ(360, cropped_height_);
525 EXPECT_EQ(640, out_width_); 676 EXPECT_EQ(640, out_width_);
526 EXPECT_EQ(360, out_height_); 677 EXPECT_EQ(360, out_height_);
527 678
528 adapter_.AdaptFrameResolution(640, 480, 679 adapter_.AdaptFrameResolution(640, 480, 0,
529 &cropped_width_, &cropped_height_, 680 &cropped_width_, &cropped_height_,
530 &out_width_, &out_height_); 681 &out_width_, &out_height_);
531 EXPECT_EQ(640, cropped_width_); 682 EXPECT_EQ(640, cropped_width_);
532 EXPECT_EQ(360, cropped_height_); 683 EXPECT_EQ(360, cropped_height_);
533 EXPECT_EQ(640, out_width_); 684 EXPECT_EQ(640, out_width_);
534 EXPECT_EQ(360, out_height_); 685 EXPECT_EQ(360, out_height_);
535 } 686 }
536 687
537 TEST_F(VideoAdapterTest, TestOnResolutionRequestInSmallSteps) { 688 TEST_F(VideoAdapterTest, TestOnResolutionRequestInSmallSteps) {
538 adapter_.AdaptFrameResolution(1280, 720, 689 adapter_.AdaptFrameResolution(1280, 720, 0,
539 &cropped_width_, &cropped_height_, 690 &cropped_width_, &cropped_height_,
540 &out_width_, &out_height_); 691 &out_width_, &out_height_);
541 EXPECT_EQ(1280, cropped_width_); 692 EXPECT_EQ(1280, cropped_width_);
542 EXPECT_EQ(720, cropped_height_); 693 EXPECT_EQ(720, cropped_height_);
543 EXPECT_EQ(1280, out_width_); 694 EXPECT_EQ(1280, out_width_);
544 EXPECT_EQ(720, out_height_); 695 EXPECT_EQ(720, out_height_);
545 696
546 // Adapt down one step. 697 // Adapt down one step.
547 adapter_.OnResolutionRequest(rtc::Optional<int>(1280 * 720 - 1), 698 adapter_.OnResolutionRequest(rtc::Optional<int>(1280 * 720 - 1),
548 rtc::Optional<int>()); 699 rtc::Optional<int>());
549 adapter_.AdaptFrameResolution(1280, 720, 700 adapter_.AdaptFrameResolution(1280, 720, 0,
550 &cropped_width_, &cropped_height_, 701 &cropped_width_, &cropped_height_,
551 &out_width_, &out_height_); 702 &out_width_, &out_height_);
552 EXPECT_EQ(1280, cropped_width_); 703 EXPECT_EQ(1280, cropped_width_);
553 EXPECT_EQ(720, cropped_height_); 704 EXPECT_EQ(720, cropped_height_);
554 EXPECT_EQ(960, out_width_); 705 EXPECT_EQ(960, out_width_);
555 EXPECT_EQ(540, out_height_); 706 EXPECT_EQ(540, out_height_);
556 707
557 // Adapt down one step more. 708 // Adapt down one step more.
558 adapter_.OnResolutionRequest(rtc::Optional<int>(960 * 540 - 1), 709 adapter_.OnResolutionRequest(rtc::Optional<int>(960 * 540 - 1),
559 rtc::Optional<int>()); 710 rtc::Optional<int>());
560 adapter_.AdaptFrameResolution(1280, 720, 711 adapter_.AdaptFrameResolution(1280, 720, 0,
561 &cropped_width_, &cropped_height_, 712 &cropped_width_, &cropped_height_,
562 &out_width_, &out_height_); 713 &out_width_, &out_height_);
563 EXPECT_EQ(1280, cropped_width_); 714 EXPECT_EQ(1280, cropped_width_);
564 EXPECT_EQ(720, cropped_height_); 715 EXPECT_EQ(720, cropped_height_);
565 EXPECT_EQ(640, out_width_); 716 EXPECT_EQ(640, out_width_);
566 EXPECT_EQ(360, out_height_); 717 EXPECT_EQ(360, out_height_);
567 718
568 // Adapt down one step more. 719 // Adapt down one step more.
569 adapter_.OnResolutionRequest(rtc::Optional<int>(640 * 360 - 1), 720 adapter_.OnResolutionRequest(rtc::Optional<int>(640 * 360 - 1),
570 rtc::Optional<int>()); 721 rtc::Optional<int>());
571 adapter_.AdaptFrameResolution(1280, 720, 722 adapter_.AdaptFrameResolution(1280, 720, 0,
572 &cropped_width_, &cropped_height_, 723 &cropped_width_, &cropped_height_,
573 &out_width_, &out_height_); 724 &out_width_, &out_height_);
574 EXPECT_EQ(1280, cropped_width_); 725 EXPECT_EQ(1280, cropped_width_);
575 EXPECT_EQ(720, cropped_height_); 726 EXPECT_EQ(720, cropped_height_);
576 EXPECT_EQ(480, out_width_); 727 EXPECT_EQ(480, out_width_);
577 EXPECT_EQ(270, out_height_); 728 EXPECT_EQ(270, out_height_);
578 729
579 // Adapt up one step. 730 // Adapt up one step.
580 adapter_.OnResolutionRequest(rtc::Optional<int>(), 731 adapter_.OnResolutionRequest(rtc::Optional<int>(),
581 rtc::Optional<int>(480 * 270)); 732 rtc::Optional<int>(480 * 270));
582 adapter_.AdaptFrameResolution(1280, 720, 733 adapter_.AdaptFrameResolution(1280, 720, 0,
583 &cropped_width_, &cropped_height_, 734 &cropped_width_, &cropped_height_,
584 &out_width_, &out_height_); 735 &out_width_, &out_height_);
585 EXPECT_EQ(1280, cropped_width_); 736 EXPECT_EQ(1280, cropped_width_);
586 EXPECT_EQ(720, cropped_height_); 737 EXPECT_EQ(720, cropped_height_);
587 EXPECT_EQ(640, out_width_); 738 EXPECT_EQ(640, out_width_);
588 EXPECT_EQ(360, out_height_); 739 EXPECT_EQ(360, out_height_);
589 740
590 // Adapt up one step more. 741 // Adapt up one step more.
591 adapter_.OnResolutionRequest(rtc::Optional<int>(), 742 adapter_.OnResolutionRequest(rtc::Optional<int>(),
592 rtc::Optional<int>(640 * 360)); 743 rtc::Optional<int>(640 * 360));
593 adapter_.AdaptFrameResolution(1280, 720, 744 adapter_.AdaptFrameResolution(1280, 720, 0,
594 &cropped_width_, &cropped_height_, 745 &cropped_width_, &cropped_height_,
595 &out_width_, &out_height_); 746 &out_width_, &out_height_);
596 EXPECT_EQ(1280, cropped_width_); 747 EXPECT_EQ(1280, cropped_width_);
597 EXPECT_EQ(720, cropped_height_); 748 EXPECT_EQ(720, cropped_height_);
598 EXPECT_EQ(960, out_width_); 749 EXPECT_EQ(960, out_width_);
599 EXPECT_EQ(540, out_height_); 750 EXPECT_EQ(540, out_height_);
600 751
601 // Adapt up one step more. 752 // Adapt up one step more.
602 adapter_.OnResolutionRequest(rtc::Optional<int>(), 753 adapter_.OnResolutionRequest(rtc::Optional<int>(),
603 rtc::Optional<int>(960 * 720)); 754 rtc::Optional<int>(960 * 720));
604 adapter_.AdaptFrameResolution(1280, 720, 755 adapter_.AdaptFrameResolution(1280, 720, 0,
605 &cropped_width_, &cropped_height_, 756 &cropped_width_, &cropped_height_,
606 &out_width_, &out_height_); 757 &out_width_, &out_height_);
607 EXPECT_EQ(1280, cropped_width_); 758 EXPECT_EQ(1280, cropped_width_);
608 EXPECT_EQ(720, cropped_height_); 759 EXPECT_EQ(720, cropped_height_);
609 EXPECT_EQ(1280, out_width_); 760 EXPECT_EQ(1280, out_width_);
610 EXPECT_EQ(720, out_height_); 761 EXPECT_EQ(720, out_height_);
611 } 762 }
612 763
613 TEST_F(VideoAdapterTest, TestOnResolutionRequestMaxZero) { 764 TEST_F(VideoAdapterTest, TestOnResolutionRequestMaxZero) {
614 adapter_.AdaptFrameResolution(1280, 720, 765 adapter_.AdaptFrameResolution(1280, 720, 0,
615 &cropped_width_, &cropped_height_, 766 &cropped_width_, &cropped_height_,
616 &out_width_, &out_height_); 767 &out_width_, &out_height_);
617 EXPECT_EQ(1280, cropped_width_); 768 EXPECT_EQ(1280, cropped_width_);
618 EXPECT_EQ(720, cropped_height_); 769 EXPECT_EQ(720, cropped_height_);
619 EXPECT_EQ(1280, out_width_); 770 EXPECT_EQ(1280, out_width_);
620 EXPECT_EQ(720, out_height_); 771 EXPECT_EQ(720, out_height_);
621 772
622 adapter_.OnResolutionRequest(rtc::Optional<int>(0), rtc::Optional<int>()); 773 adapter_.OnResolutionRequest(rtc::Optional<int>(0), rtc::Optional<int>());
623 adapter_.AdaptFrameResolution(1280, 720, 774 adapter_.AdaptFrameResolution(1280, 720, 0,
624 &cropped_width_, &cropped_height_, 775 &cropped_width_, &cropped_height_,
625 &out_width_, &out_height_); 776 &out_width_, &out_height_);
626 EXPECT_EQ(0, out_width_); 777 EXPECT_EQ(0, out_width_);
627 EXPECT_EQ(0, out_height_); 778 EXPECT_EQ(0, out_height_);
628 } 779 }
629 780
630 TEST_F(VideoAdapterTest, TestOnResolutionRequestInLargeSteps) { 781 TEST_F(VideoAdapterTest, TestOnResolutionRequestInLargeSteps) {
631 adapter_.OnResolutionRequest(rtc::Optional<int>(640 * 360 - 1), 782 adapter_.OnResolutionRequest(rtc::Optional<int>(640 * 360 - 1),
632 rtc::Optional<int>()); 783 rtc::Optional<int>());
633 adapter_.AdaptFrameResolution(1280, 720, 784 adapter_.AdaptFrameResolution(1280, 720, 0,
634 &cropped_width_, &cropped_height_, 785 &cropped_width_, &cropped_height_,
635 &out_width_, &out_height_); 786 &out_width_, &out_height_);
636 EXPECT_EQ(1280, cropped_width_); 787 EXPECT_EQ(1280, cropped_width_);
637 EXPECT_EQ(720, cropped_height_); 788 EXPECT_EQ(720, cropped_height_);
638 EXPECT_EQ(480, out_width_); 789 EXPECT_EQ(480, out_width_);
639 EXPECT_EQ(270, out_height_); 790 EXPECT_EQ(270, out_height_);
640 791
641 adapter_.OnResolutionRequest(rtc::Optional<int>(), 792 adapter_.OnResolutionRequest(rtc::Optional<int>(),
642 rtc::Optional<int>(960 * 720)); 793 rtc::Optional<int>(960 * 720));
643 adapter_.AdaptFrameResolution(1280, 720, 794 adapter_.AdaptFrameResolution(1280, 720, 0,
644 &cropped_width_, &cropped_height_, 795 &cropped_width_, &cropped_height_,
645 &out_width_, &out_height_); 796 &out_width_, &out_height_);
646 EXPECT_EQ(1280, cropped_width_); 797 EXPECT_EQ(1280, cropped_width_);
647 EXPECT_EQ(720, cropped_height_); 798 EXPECT_EQ(720, cropped_height_);
648 EXPECT_EQ(1280, out_width_); 799 EXPECT_EQ(1280, out_width_);
649 EXPECT_EQ(720, out_height_); 800 EXPECT_EQ(720, out_height_);
650 } 801 }
651 802
652 TEST_F(VideoAdapterTest, TestOnOutputFormatRequestCapsMaxResolution) { 803 TEST_F(VideoAdapterTest, TestOnOutputFormatRequestCapsMaxResolution) {
653 adapter_.OnResolutionRequest(rtc::Optional<int>(640 * 360 - 1), 804 adapter_.OnResolutionRequest(rtc::Optional<int>(640 * 360 - 1),
654 rtc::Optional<int>()); 805 rtc::Optional<int>());
655 adapter_.AdaptFrameResolution(1280, 720, 806 adapter_.AdaptFrameResolution(1280, 720, 0,
656 &cropped_width_, &cropped_height_, 807 &cropped_width_, &cropped_height_,
657 &out_width_, &out_height_); 808 &out_width_, &out_height_);
658 EXPECT_EQ(1280, cropped_width_); 809 EXPECT_EQ(1280, cropped_width_);
659 EXPECT_EQ(720, cropped_height_); 810 EXPECT_EQ(720, cropped_height_);
660 EXPECT_EQ(480, out_width_); 811 EXPECT_EQ(480, out_width_);
661 EXPECT_EQ(270, out_height_); 812 EXPECT_EQ(270, out_height_);
662 813
663 VideoFormat new_format(640, 360, VideoFormat::FpsToInterval(30), FOURCC_I420); 814 VideoFormat new_format(640, 360, 0, FOURCC_I420);
664 adapter_.SetExpectedInputFrameInterval(VideoFormat::FpsToInterval(30));
665 adapter_.OnOutputFormatRequest(new_format); 815 adapter_.OnOutputFormatRequest(new_format);
666 adapter_.AdaptFrameResolution(1280, 720, 816 adapter_.AdaptFrameResolution(1280, 720, 0,
667 &cropped_width_, &cropped_height_, 817 &cropped_width_, &cropped_height_,
668 &out_width_, &out_height_); 818 &out_width_, &out_height_);
669 EXPECT_EQ(1280, cropped_width_); 819 EXPECT_EQ(1280, cropped_width_);
670 EXPECT_EQ(720, cropped_height_); 820 EXPECT_EQ(720, cropped_height_);
671 EXPECT_EQ(480, out_width_); 821 EXPECT_EQ(480, out_width_);
672 EXPECT_EQ(270, out_height_); 822 EXPECT_EQ(270, out_height_);
673 823
674 adapter_.OnResolutionRequest(rtc::Optional<int>(), 824 adapter_.OnResolutionRequest(rtc::Optional<int>(),
675 rtc::Optional<int>(960 * 720)); 825 rtc::Optional<int>(960 * 720));
676 adapter_.AdaptFrameResolution(1280, 720, 826 adapter_.AdaptFrameResolution(1280, 720, 0,
677 &cropped_width_, &cropped_height_, 827 &cropped_width_, &cropped_height_,
678 &out_width_, &out_height_); 828 &out_width_, &out_height_);
679 EXPECT_EQ(1280, cropped_width_); 829 EXPECT_EQ(1280, cropped_width_);
680 EXPECT_EQ(720, cropped_height_); 830 EXPECT_EQ(720, cropped_height_);
681 EXPECT_EQ(640, out_width_); 831 EXPECT_EQ(640, out_width_);
682 EXPECT_EQ(360, out_height_); 832 EXPECT_EQ(360, out_height_);
683 } 833 }
684 834
685 TEST_F(VideoAdapterTest, TestOnResolutionRequestReset) { 835 TEST_F(VideoAdapterTest, TestOnResolutionRequestReset) {
686 adapter_.AdaptFrameResolution(1280, 720, 836 adapter_.AdaptFrameResolution(1280, 720, 0,
687 &cropped_width_, &cropped_height_, 837 &cropped_width_, &cropped_height_,
688 &out_width_, &out_height_); 838 &out_width_, &out_height_);
689 EXPECT_EQ(1280, cropped_width_); 839 EXPECT_EQ(1280, cropped_width_);
690 EXPECT_EQ(720, cropped_height_); 840 EXPECT_EQ(720, cropped_height_);
691 EXPECT_EQ(1280, out_width_); 841 EXPECT_EQ(1280, out_width_);
692 EXPECT_EQ(720, out_height_); 842 EXPECT_EQ(720, out_height_);
693 843
694 adapter_.OnResolutionRequest(rtc::Optional<int>(640 * 360 - 1), 844 adapter_.OnResolutionRequest(rtc::Optional<int>(640 * 360 - 1),
695 rtc::Optional<int>()); 845 rtc::Optional<int>());
696 adapter_.AdaptFrameResolution(1280, 720, 846 adapter_.AdaptFrameResolution(1280, 720, 0,
697 &cropped_width_, &cropped_height_, 847 &cropped_width_, &cropped_height_,
698 &out_width_, &out_height_); 848 &out_width_, &out_height_);
699 EXPECT_EQ(1280, cropped_width_); 849 EXPECT_EQ(1280, cropped_width_);
700 EXPECT_EQ(720, cropped_height_); 850 EXPECT_EQ(720, cropped_height_);
701 EXPECT_EQ(480, out_width_); 851 EXPECT_EQ(480, out_width_);
702 EXPECT_EQ(270, out_height_); 852 EXPECT_EQ(270, out_height_);
703 853
704 adapter_.OnResolutionRequest(rtc::Optional<int>(), rtc::Optional<int>()); 854 adapter_.OnResolutionRequest(rtc::Optional<int>(), rtc::Optional<int>());
705 adapter_.AdaptFrameResolution(1280, 720, 855 adapter_.AdaptFrameResolution(1280, 720, 0,
706 &cropped_width_, &cropped_height_, 856 &cropped_width_, &cropped_height_,
707 &out_width_, &out_height_); 857 &out_width_, &out_height_);
708 EXPECT_EQ(1280, cropped_width_); 858 EXPECT_EQ(1280, cropped_width_);
709 EXPECT_EQ(720, cropped_height_); 859 EXPECT_EQ(720, cropped_height_);
710 EXPECT_EQ(1280, out_width_); 860 EXPECT_EQ(1280, out_width_);
711 EXPECT_EQ(720, out_height_); 861 EXPECT_EQ(720, out_height_);
712 } 862 }
713 863
714 TEST_F(VideoAdapterTest, TestCroppingWithResolutionRequest) { 864 TEST_F(VideoAdapterTest, TestCroppingWithResolutionRequest) {
715 // Ask for 640x360 (16:9 aspect). 865 // Ask for 640x360 (16:9 aspect).
716 adapter_.SetExpectedInputFrameInterval(VideoFormat::FpsToInterval(30)); 866 adapter_.OnOutputFormatRequest(VideoFormat(640, 360, 0, FOURCC_I420));
717 adapter_.OnOutputFormatRequest(
718 VideoFormat(640, 360, VideoFormat::FpsToInterval(30), FOURCC_I420));
719 // Send 640x480 (4:3 aspect). 867 // Send 640x480 (4:3 aspect).
720 adapter_.AdaptFrameResolution(640, 480, 868 adapter_.AdaptFrameResolution(640, 480, 0,
721 &cropped_width_, &cropped_height_, 869 &cropped_width_, &cropped_height_,
722 &out_width_, &out_height_); 870 &out_width_, &out_height_);
723 // Expect cropping to 16:9 format and no scaling. 871 // Expect cropping to 16:9 format and no scaling.
724 EXPECT_EQ(640, cropped_width_); 872 EXPECT_EQ(640, cropped_width_);
725 EXPECT_EQ(360, cropped_height_); 873 EXPECT_EQ(360, cropped_height_);
726 EXPECT_EQ(640, out_width_); 874 EXPECT_EQ(640, out_width_);
727 EXPECT_EQ(360, out_height_); 875 EXPECT_EQ(360, out_height_);
728 876
729 // Adapt down one step. 877 // Adapt down one step.
730 adapter_.OnResolutionRequest(rtc::Optional<int>(640 * 360 - 1), 878 adapter_.OnResolutionRequest(rtc::Optional<int>(640 * 360 - 1),
731 rtc::Optional<int>()); 879 rtc::Optional<int>());
732 // Expect cropping to 16:9 format and 3/4 scaling. 880 // Expect cropping to 16:9 format and 3/4 scaling.
733 adapter_.AdaptFrameResolution(640, 480, 881 adapter_.AdaptFrameResolution(640, 480, 0,
734 &cropped_width_, &cropped_height_, 882 &cropped_width_, &cropped_height_,
735 &out_width_, &out_height_); 883 &out_width_, &out_height_);
736 EXPECT_EQ(640, cropped_width_); 884 EXPECT_EQ(640, cropped_width_);
737 EXPECT_EQ(360, cropped_height_); 885 EXPECT_EQ(360, cropped_height_);
738 EXPECT_EQ(480, out_width_); 886 EXPECT_EQ(480, out_width_);
739 EXPECT_EQ(270, out_height_); 887 EXPECT_EQ(270, out_height_);
740 888
741 // Adapt down one step more. 889 // Adapt down one step more.
742 adapter_.OnResolutionRequest(rtc::Optional<int>(480 * 270 - 1), 890 adapter_.OnResolutionRequest(rtc::Optional<int>(480 * 270 - 1),
743 rtc::Optional<int>()); 891 rtc::Optional<int>());
744 // Expect cropping to 16:9 format and 1/2 scaling. 892 // Expect cropping to 16:9 format and 1/2 scaling.
745 adapter_.AdaptFrameResolution(640, 480, 893 adapter_.AdaptFrameResolution(640, 480, 0,
746 &cropped_width_, &cropped_height_, 894 &cropped_width_, &cropped_height_,
747 &out_width_, &out_height_); 895 &out_width_, &out_height_);
748 EXPECT_EQ(640, cropped_width_); 896 EXPECT_EQ(640, cropped_width_);
749 EXPECT_EQ(360, cropped_height_); 897 EXPECT_EQ(360, cropped_height_);
750 EXPECT_EQ(320, out_width_); 898 EXPECT_EQ(320, out_width_);
751 EXPECT_EQ(180, out_height_); 899 EXPECT_EQ(180, out_height_);
752 900
753 // Adapt up one step. 901 // Adapt up one step.
754 adapter_.OnResolutionRequest(rtc::Optional<int>(), 902 adapter_.OnResolutionRequest(rtc::Optional<int>(),
755 rtc::Optional<int>(320 * 180)); 903 rtc::Optional<int>(320 * 180));
756 // Expect cropping to 16:9 format and 3/4 scaling. 904 // Expect cropping to 16:9 format and 3/4 scaling.
757 adapter_.AdaptFrameResolution(640, 480, 905 adapter_.AdaptFrameResolution(640, 480, 0,
758 &cropped_width_, &cropped_height_, 906 &cropped_width_, &cropped_height_,
759 &out_width_, &out_height_); 907 &out_width_, &out_height_);
760 EXPECT_EQ(640, cropped_width_); 908 EXPECT_EQ(640, cropped_width_);
761 EXPECT_EQ(360, cropped_height_); 909 EXPECT_EQ(360, cropped_height_);
762 EXPECT_EQ(480, out_width_); 910 EXPECT_EQ(480, out_width_);
763 EXPECT_EQ(270, out_height_); 911 EXPECT_EQ(270, out_height_);
764 912
765 // Adapt up one step more. 913 // Adapt up one step more.
766 adapter_.OnResolutionRequest(rtc::Optional<int>(), 914 adapter_.OnResolutionRequest(rtc::Optional<int>(),
767 rtc::Optional<int>(480 * 270)); 915 rtc::Optional<int>(480 * 270));
768 // Expect cropping to 16:9 format and no scaling. 916 // Expect cropping to 16:9 format and no scaling.
769 adapter_.AdaptFrameResolution(640, 480, 917 adapter_.AdaptFrameResolution(640, 480, 0,
770 &cropped_width_, &cropped_height_, 918 &cropped_width_, &cropped_height_,
771 &out_width_, &out_height_); 919 &out_width_, &out_height_);
772 EXPECT_EQ(640, cropped_width_); 920 EXPECT_EQ(640, cropped_width_);
773 EXPECT_EQ(360, cropped_height_); 921 EXPECT_EQ(360, cropped_height_);
774 EXPECT_EQ(640, out_width_); 922 EXPECT_EQ(640, out_width_);
775 EXPECT_EQ(360, out_height_); 923 EXPECT_EQ(360, out_height_);
776 924
777 // Try to adapt up one step more. 925 // Try to adapt up one step more.
778 adapter_.OnResolutionRequest(rtc::Optional<int>(), 926 adapter_.OnResolutionRequest(rtc::Optional<int>(),
779 rtc::Optional<int>(640 * 360)); 927 rtc::Optional<int>(640 * 360));
780 // Expect cropping to 16:9 format and no scaling. 928 // Expect cropping to 16:9 format and no scaling.
781 adapter_.AdaptFrameResolution(640, 480, 929 adapter_.AdaptFrameResolution(640, 480, 0,
782 &cropped_width_, &cropped_height_, 930 &cropped_width_, &cropped_height_,
783 &out_width_, &out_height_); 931 &out_width_, &out_height_);
784 EXPECT_EQ(640, cropped_width_); 932 EXPECT_EQ(640, cropped_width_);
785 EXPECT_EQ(360, cropped_height_); 933 EXPECT_EQ(360, cropped_height_);
786 EXPECT_EQ(640, out_width_); 934 EXPECT_EQ(640, out_width_);
787 EXPECT_EQ(360, out_height_); 935 EXPECT_EQ(360, out_height_);
788 } 936 }
789 937
790 TEST_F(VideoAdapterTest, TestCroppingOddResolution) { 938 TEST_F(VideoAdapterTest, TestCroppingOddResolution) {
791 // Ask for 640x360 (16:9 aspect), with 3/16 scaling. 939 // Ask for 640x360 (16:9 aspect), with 3/16 scaling.
792 adapter_.SetExpectedInputFrameInterval(VideoFormat::FpsToInterval(30));
793 adapter_.OnOutputFormatRequest( 940 adapter_.OnOutputFormatRequest(
794 VideoFormat(640, 360, VideoFormat::FpsToInterval(30), FOURCC_I420)); 941 VideoFormat(640, 360, 0, FOURCC_I420));
795 adapter_.OnResolutionRequest(rtc::Optional<int>(640 * 360 * 3 / 16 * 3 / 16), 942 adapter_.OnResolutionRequest(rtc::Optional<int>(640 * 360 * 3 / 16 * 3 / 16),
796 rtc::Optional<int>()); 943 rtc::Optional<int>());
797 944
798 // Send 640x480 (4:3 aspect). 945 // Send 640x480 (4:3 aspect).
799 adapter_.AdaptFrameResolution(640, 480, 946 adapter_.AdaptFrameResolution(640, 480, 0,
800 &cropped_width_, &cropped_height_, 947 &cropped_width_, &cropped_height_,
801 &out_width_, &out_height_); 948 &out_width_, &out_height_);
802 949
803 // Instead of getting the exact aspect ratio with cropped resolution 640x360, 950 // Instead of getting the exact aspect ratio with cropped resolution 640x360,
804 // the resolution should be adjusted to get a perfect scale factor instead. 951 // the resolution should be adjusted to get a perfect scale factor instead.
805 EXPECT_EQ(640, cropped_width_); 952 EXPECT_EQ(640, cropped_width_);
806 EXPECT_EQ(368, cropped_height_); 953 EXPECT_EQ(368, cropped_height_);
807 EXPECT_EQ(120, out_width_); 954 EXPECT_EQ(120, out_width_);
808 EXPECT_EQ(69, out_height_); 955 EXPECT_EQ(69, out_height_);
809 } 956 }
810 957
811 } // namespace cricket 958 } // namespace cricket
OLDNEW
« no previous file with comments | « webrtc/media/base/videoadapter.cc ('k') | webrtc/media/base/videocapturer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698