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

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

Issue 1973873003: Delete AndroidVideoCapturer::FrameFactory. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Address nit. Delete left-over include. Created 4 years, 6 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 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
64 64
65 void OnFrameCaptured(VideoCapturer* capturer, 65 void OnFrameCaptured(VideoCapturer* capturer,
66 const CapturedFrame* captured_frame) { 66 const CapturedFrame* captured_frame) {
67 rtc::CritScope lock(&crit_); 67 rtc::CritScope lock(&crit_);
68 const int in_width = captured_frame->width; 68 const int in_width = captured_frame->width;
69 const int in_height = abs(captured_frame->height); 69 const int in_height = abs(captured_frame->height);
70 int cropped_width; 70 int cropped_width;
71 int cropped_height; 71 int cropped_height;
72 int out_width; 72 int out_width;
73 int out_height; 73 int out_height;
74 video_adapter_->AdaptFrameResolution(in_width, in_height, 74 if (video_adapter_->AdaptFrameResolution(in_width, in_height,
75 captured_frame->time_stamp, 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) {
79 cropped_width_ = cropped_width; 78 cropped_width_ = cropped_width;
80 cropped_height_ = cropped_height; 79 cropped_height_ = cropped_height;
81 out_width_ = out_width; 80 out_width_ = out_width;
82 out_height_ = out_height; 81 out_height_ = out_height;
83 last_adapt_was_no_op_ = 82 last_adapt_was_no_op_ =
84 (in_width == cropped_width && in_height == cropped_height && 83 (in_width == cropped_width && in_height == cropped_height &&
85 in_width == out_width && in_height == out_height); 84 in_width == out_width && in_height == out_height);
86 } else { 85 } else {
87 ++dropped_frames_; 86 ++dropped_frames_;
88 } 87 }
(...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after
383 EXPECT_GT(listener_->GetStats().dropped_frames, 0); 382 EXPECT_GT(listener_->GetStats().dropped_frames, 0);
384 } 383 }
385 384
386 // Set a very high output pixel resolution. Expect no cropping or resolution 385 // Set a very high output pixel resolution. Expect no cropping or resolution
387 // change. 386 // change.
388 TEST_F(VideoAdapterTest, AdaptFrameResolutionHighLimit) { 387 TEST_F(VideoAdapterTest, AdaptFrameResolutionHighLimit) {
389 VideoFormat output_format = capture_format_; 388 VideoFormat output_format = capture_format_;
390 output_format.width *= 10; 389 output_format.width *= 10;
391 output_format.height *= 10; 390 output_format.height *= 10;
392 adapter_.OnOutputFormatRequest(output_format); 391 adapter_.OnOutputFormatRequest(output_format);
393 adapter_.AdaptFrameResolution(capture_format_.width, capture_format_.height, 392 EXPECT_TRUE(adapter_.AdaptFrameResolution(
394 0, &cropped_width_, &cropped_height_, 393 capture_format_.width, capture_format_.height, 0,
395 &out_width_, &out_height_); 394 &cropped_width_, &cropped_height_,
395 &out_width_, &out_height_));
396 EXPECT_EQ(capture_format_.width, cropped_width_); 396 EXPECT_EQ(capture_format_.width, cropped_width_);
397 EXPECT_EQ(capture_format_.height, cropped_height_); 397 EXPECT_EQ(capture_format_.height, cropped_height_);
398 EXPECT_EQ(capture_format_.width, out_width_); 398 EXPECT_EQ(capture_format_.width, out_width_);
399 EXPECT_EQ(capture_format_.height, out_height_); 399 EXPECT_EQ(capture_format_.height, out_height_);
400 } 400 }
401 401
402 // 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
403 // cropping or resolution change. 403 // cropping or resolution change.
404 TEST_F(VideoAdapterTest, AdaptFrameResolutionIdentical) { 404 TEST_F(VideoAdapterTest, AdaptFrameResolutionIdentical) {
405 adapter_.OnOutputFormatRequest(capture_format_); 405 adapter_.OnOutputFormatRequest(capture_format_);
406 adapter_.AdaptFrameResolution(capture_format_.width, capture_format_.height, 406 EXPECT_TRUE(adapter_.AdaptFrameResolution(
407 0, &cropped_width_, &cropped_height_, 407 capture_format_.width, capture_format_.height, 0,
408 &out_width_, &out_height_); 408 &cropped_width_, &cropped_height_,
409 &out_width_, &out_height_));
409 EXPECT_EQ(capture_format_.width, cropped_width_); 410 EXPECT_EQ(capture_format_.width, cropped_width_);
410 EXPECT_EQ(capture_format_.height, cropped_height_); 411 EXPECT_EQ(capture_format_.height, cropped_height_);
411 EXPECT_EQ(capture_format_.width, out_width_); 412 EXPECT_EQ(capture_format_.width, out_width_);
412 EXPECT_EQ(capture_format_.height, out_height_); 413 EXPECT_EQ(capture_format_.height, out_height_);
413 } 414 }
414 415
415 // Adapt the frame resolution to be a quarter of the capture resolution. Expect 416 // Adapt the frame resolution to be a quarter of the capture resolution. Expect
416 // no cropping, but a resolution change. 417 // no cropping, but a resolution change.
417 TEST_F(VideoAdapterTest, AdaptFrameResolutionQuarter) { 418 TEST_F(VideoAdapterTest, AdaptFrameResolutionQuarter) {
418 VideoFormat request_format = capture_format_; 419 VideoFormat request_format = capture_format_;
419 request_format.width /= 2; 420 request_format.width /= 2;
420 request_format.height /= 2; 421 request_format.height /= 2;
421 adapter_.OnOutputFormatRequest(request_format); 422 adapter_.OnOutputFormatRequest(request_format);
422 adapter_.AdaptFrameResolution(capture_format_.width, capture_format_.height, 423 EXPECT_TRUE(adapter_.AdaptFrameResolution(
423 0, &cropped_width_, &cropped_height_, 424 capture_format_.width, capture_format_.height, 0,
424 &out_width_, &out_height_); 425 &cropped_width_, &cropped_height_,
426 &out_width_, &out_height_));
425 EXPECT_EQ(capture_format_.width, cropped_width_); 427 EXPECT_EQ(capture_format_.width, cropped_width_);
426 EXPECT_EQ(capture_format_.height, cropped_height_); 428 EXPECT_EQ(capture_format_.height, cropped_height_);
427 EXPECT_EQ(request_format.width, out_width_); 429 EXPECT_EQ(request_format.width, out_width_);
428 EXPECT_EQ(request_format.height, out_height_); 430 EXPECT_EQ(request_format.height, out_height_);
429 } 431 }
430 432
431 // Adapt the pixel resolution to 0. Expect frame drop. 433 // Adapt the pixel resolution to 0. Expect frame drop.
432 TEST_F(VideoAdapterTest, AdaptFrameResolutionDrop) { 434 TEST_F(VideoAdapterTest, AdaptFrameResolutionDrop) {
433 VideoFormat output_format = capture_format_; 435 VideoFormat output_format = capture_format_;
434 output_format.width = 0; 436 output_format.width = 0;
435 output_format.height = 0; 437 output_format.height = 0;
436 adapter_.OnOutputFormatRequest(output_format); 438 adapter_.OnOutputFormatRequest(output_format);
437 adapter_.AdaptFrameResolution(capture_format_.width, capture_format_.height, 439 EXPECT_FALSE(adapter_.AdaptFrameResolution(
438 0, &cropped_width_, &cropped_height_, 440 capture_format_.width, capture_format_.height, 0,
439 &out_width_, &out_height_); 441 &cropped_width_, &cropped_height_,
440 EXPECT_EQ(0, out_width_); 442 &out_width_, &out_height_));
441 EXPECT_EQ(0, out_height_);
442 } 443 }
443 444
444 // Adapt the frame resolution to be a quarter of the capture resolution at the 445 // Adapt the frame resolution to be a quarter of the capture resolution at the
445 // beginning. Expect no cropping but a resolution change. 446 // beginning. Expect no cropping but a resolution change.
446 TEST_F(VideoAdapterTest, AdaptResolution) { 447 TEST_F(VideoAdapterTest, AdaptResolution) {
447 VideoFormat request_format = capture_format_; 448 VideoFormat request_format = capture_format_;
448 request_format.width /= 2; 449 request_format.width /= 2;
449 request_format.height /= 2; 450 request_format.height /= 2;
450 adapter_.OnOutputFormatRequest(request_format); 451 adapter_.OnOutputFormatRequest(request_format);
451 EXPECT_EQ(CS_RUNNING, capturer_->Start(capture_format_)); 452 EXPECT_EQ(CS_RUNNING, capturer_->Start(capture_format_));
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
496 capturer_->CaptureFrame(); 497 capturer_->CaptureFrame();
497 498
498 // Verify all frames are dropped. 499 // Verify all frames are dropped.
499 VideoCapturerListener::Stats stats = listener_->GetStats(); 500 VideoCapturerListener::Stats stats = listener_->GetStats();
500 EXPECT_GE(stats.captured_frames, 10); 501 EXPECT_GE(stats.captured_frames, 10);
501 EXPECT_EQ(stats.captured_frames, stats.dropped_frames); 502 EXPECT_EQ(stats.captured_frames, stats.dropped_frames);
502 } 503 }
503 504
504 TEST_F(VideoAdapterTest, TestOnOutputFormatRequest) { 505 TEST_F(VideoAdapterTest, TestOnOutputFormatRequest) {
505 VideoFormat format(640, 400, 0, 0); 506 VideoFormat format(640, 400, 0, 0);
506 adapter_.AdaptFrameResolution(640, 400, 0, 507 EXPECT_TRUE(adapter_.AdaptFrameResolution(640, 400, 0,
507 &cropped_width_, &cropped_height_, 508 &cropped_width_, &cropped_height_,
508 &out_width_, &out_height_); 509 &out_width_, &out_height_));
509 EXPECT_EQ(640, cropped_width_); 510 EXPECT_EQ(640, cropped_width_);
510 EXPECT_EQ(400, cropped_height_); 511 EXPECT_EQ(400, cropped_height_);
511 EXPECT_EQ(640, out_width_); 512 EXPECT_EQ(640, out_width_);
512 EXPECT_EQ(400, out_height_); 513 EXPECT_EQ(400, out_height_);
513 514
514 // Format request 640x400. 515 // Format request 640x400.
515 format.height = 400; 516 format.height = 400;
516 adapter_.OnOutputFormatRequest(format); 517 adapter_.OnOutputFormatRequest(format);
517 adapter_.AdaptFrameResolution(640, 400, 0, 518 EXPECT_TRUE(adapter_.AdaptFrameResolution(640, 400, 0,
518 &cropped_width_, &cropped_height_, 519 &cropped_width_, &cropped_height_,
519 &out_width_, &out_height_); 520 &out_width_, &out_height_));
520 EXPECT_EQ(640, cropped_width_); 521 EXPECT_EQ(640, cropped_width_);
521 EXPECT_EQ(400, cropped_height_); 522 EXPECT_EQ(400, cropped_height_);
522 EXPECT_EQ(640, out_width_); 523 EXPECT_EQ(640, out_width_);
523 EXPECT_EQ(400, out_height_); 524 EXPECT_EQ(400, out_height_);
524 525
525 // Request 1280x720, higher than input, but aspect 16:9. Expect cropping but 526 // Request 1280x720, higher than input, but aspect 16:9. Expect cropping but
526 // no scaling. 527 // no scaling.
527 format.width = 1280; 528 format.width = 1280;
528 format.height = 720; 529 format.height = 720;
529 adapter_.OnOutputFormatRequest(format); 530 adapter_.OnOutputFormatRequest(format);
530 adapter_.AdaptFrameResolution(640, 400, 0, 531 EXPECT_TRUE(adapter_.AdaptFrameResolution(640, 400, 0,
531 &cropped_width_, &cropped_height_, 532 &cropped_width_, &cropped_height_,
532 &out_width_, &out_height_); 533 &out_width_, &out_height_));
533 EXPECT_EQ(640, cropped_width_); 534 EXPECT_EQ(640, cropped_width_);
534 EXPECT_EQ(360, cropped_height_); 535 EXPECT_EQ(360, cropped_height_);
535 EXPECT_EQ(640, out_width_); 536 EXPECT_EQ(640, out_width_);
536 EXPECT_EQ(360, out_height_); 537 EXPECT_EQ(360, out_height_);
537 538
538 // Request 0x0. 539 // Request 0x0.
539 format.width = 0; 540 format.width = 0;
540 format.height = 0; 541 format.height = 0;
541 adapter_.OnOutputFormatRequest(format); 542 adapter_.OnOutputFormatRequest(format);
542 adapter_.AdaptFrameResolution(640, 400, 0, 543 EXPECT_FALSE(adapter_.AdaptFrameResolution(640, 400, 0,
543 &cropped_width_, &cropped_height_, 544 &cropped_width_, &cropped_height_,
544 &out_width_, &out_height_); 545 &out_width_, &out_height_));
545 EXPECT_EQ(0, out_width_);
546 EXPECT_EQ(0, out_height_);
547 546
548 // Request 320x200. Expect scaling, but no cropping. 547 // Request 320x200. Expect scaling, but no cropping.
549 format.width = 320; 548 format.width = 320;
550 format.height = 200; 549 format.height = 200;
551 adapter_.OnOutputFormatRequest(format); 550 adapter_.OnOutputFormatRequest(format);
552 adapter_.AdaptFrameResolution(640, 400, 0, 551 EXPECT_TRUE(adapter_.AdaptFrameResolution(640, 400, 0,
553 &cropped_width_, &cropped_height_, 552 &cropped_width_, &cropped_height_,
554 &out_width_, &out_height_); 553 &out_width_, &out_height_));
555 EXPECT_EQ(640, cropped_width_); 554 EXPECT_EQ(640, cropped_width_);
556 EXPECT_EQ(400, cropped_height_); 555 EXPECT_EQ(400, cropped_height_);
557 EXPECT_EQ(320, out_width_); 556 EXPECT_EQ(320, out_width_);
558 EXPECT_EQ(200, out_height_); 557 EXPECT_EQ(200, out_height_);
559 558
560 // Request resolution close to 2/3 scale. Expect adapt down. Scaling to 2/3 559 // Request resolution close to 2/3 scale. Expect adapt down. Scaling to 2/3
561 // is not optimized and not allowed, therefore 1/2 scaling will be used 560 // is not optimized and not allowed, therefore 1/2 scaling will be used
562 // instead. 561 // instead.
563 format.width = 424; 562 format.width = 424;
564 format.height = 265; 563 format.height = 265;
565 adapter_.OnOutputFormatRequest(format); 564 adapter_.OnOutputFormatRequest(format);
566 adapter_.AdaptFrameResolution(640, 400, 0, 565 EXPECT_TRUE(adapter_.AdaptFrameResolution(640, 400, 0,
567 &cropped_width_, &cropped_height_, 566 &cropped_width_, &cropped_height_,
568 &out_width_, &out_height_); 567 &out_width_, &out_height_));
569 EXPECT_EQ(640, cropped_width_); 568 EXPECT_EQ(640, cropped_width_);
570 EXPECT_EQ(400, cropped_height_); 569 EXPECT_EQ(400, cropped_height_);
571 EXPECT_EQ(320, out_width_); 570 EXPECT_EQ(320, out_width_);
572 EXPECT_EQ(200, out_height_); 571 EXPECT_EQ(200, out_height_);
573 572
574 // Request resolution of 3 / 8. Expect adapt down. 573 // Request resolution of 3 / 8. Expect adapt down.
575 format.width = 640 * 3 / 8; 574 format.width = 640 * 3 / 8;
576 format.height = 400 * 3 / 8; 575 format.height = 400 * 3 / 8;
577 adapter_.OnOutputFormatRequest(format); 576 adapter_.OnOutputFormatRequest(format);
578 adapter_.AdaptFrameResolution(640, 400, 0, 577 EXPECT_TRUE(adapter_.AdaptFrameResolution(640, 400, 0,
579 &cropped_width_, &cropped_height_, 578 &cropped_width_, &cropped_height_,
580 &out_width_, &out_height_); 579 &out_width_, &out_height_));
581 EXPECT_EQ(640, cropped_width_); 580 EXPECT_EQ(640, cropped_width_);
582 EXPECT_EQ(400, cropped_height_); 581 EXPECT_EQ(400, cropped_height_);
583 EXPECT_EQ(640 * 3 / 8, out_width_); 582 EXPECT_EQ(640 * 3 / 8, out_width_);
584 EXPECT_EQ(400 * 3 / 8, out_height_); 583 EXPECT_EQ(400 * 3 / 8, out_height_);
585 584
586 // Switch back up. Expect adapt. 585 // Switch back up. Expect adapt.
587 format.width = 320; 586 format.width = 320;
588 format.height = 200; 587 format.height = 200;
589 adapter_.OnOutputFormatRequest(format); 588 adapter_.OnOutputFormatRequest(format);
590 adapter_.AdaptFrameResolution(640, 400, 0, 589 EXPECT_TRUE(adapter_.AdaptFrameResolution(640, 400, 0,
591 &cropped_width_, &cropped_height_, 590 &cropped_width_, &cropped_height_,
592 &out_width_, &out_height_); 591 &out_width_, &out_height_));
593 EXPECT_EQ(640, cropped_width_); 592 EXPECT_EQ(640, cropped_width_);
594 EXPECT_EQ(400, cropped_height_); 593 EXPECT_EQ(400, cropped_height_);
595 EXPECT_EQ(320, out_width_); 594 EXPECT_EQ(320, out_width_);
596 EXPECT_EQ(200, out_height_); 595 EXPECT_EQ(200, out_height_);
597 596
598 // Format request 480x300. 597 // Format request 480x300.
599 format.width = 480; 598 format.width = 480;
600 format.height = 300; 599 format.height = 300;
601 adapter_.OnOutputFormatRequest(format); 600 adapter_.OnOutputFormatRequest(format);
602 adapter_.AdaptFrameResolution(640, 400, 0, 601 EXPECT_TRUE(adapter_.AdaptFrameResolution(640, 400, 0,
603 &cropped_width_, &cropped_height_, 602 &cropped_width_, &cropped_height_,
604 &out_width_, &out_height_); 603 &out_width_, &out_height_));
605 EXPECT_EQ(640, cropped_width_); 604 EXPECT_EQ(640, cropped_width_);
606 EXPECT_EQ(400, cropped_height_); 605 EXPECT_EQ(400, cropped_height_);
607 EXPECT_EQ(480, out_width_); 606 EXPECT_EQ(480, out_width_);
608 EXPECT_EQ(300, out_height_); 607 EXPECT_EQ(300, out_height_);
609 } 608 }
610 609
611 TEST_F(VideoAdapterTest, TestViewRequestPlusCameraSwitch) { 610 TEST_F(VideoAdapterTest, TestViewRequestPlusCameraSwitch) {
612 // Start at HD. 611 // Start at HD.
613 VideoFormat format(1280, 720, 0, 0); 612 VideoFormat format(1280, 720, 0, 0);
614 adapter_.AdaptFrameResolution(1280, 720, 0, 613 EXPECT_TRUE(adapter_.AdaptFrameResolution(1280, 720, 0,
615 &cropped_width_, &cropped_height_, 614 &cropped_width_, &cropped_height_,
616 &out_width_, &out_height_); 615 &out_width_, &out_height_));
617 EXPECT_EQ(1280, cropped_width_); 616 EXPECT_EQ(1280, cropped_width_);
618 EXPECT_EQ(720, cropped_height_); 617 EXPECT_EQ(720, cropped_height_);
619 EXPECT_EQ(1280, out_width_); 618 EXPECT_EQ(1280, out_width_);
620 EXPECT_EQ(720, out_height_); 619 EXPECT_EQ(720, out_height_);
621 620
622 // Format request for VGA. 621 // Format request for VGA.
623 format.width = 640; 622 format.width = 640;
624 format.height = 360; 623 format.height = 360;
625 adapter_.OnOutputFormatRequest(format); 624 adapter_.OnOutputFormatRequest(format);
626 adapter_.AdaptFrameResolution(1280, 720, 0, 625 EXPECT_TRUE(adapter_.AdaptFrameResolution(1280, 720, 0,
627 &cropped_width_, &cropped_height_, 626 &cropped_width_, &cropped_height_,
628 &out_width_, &out_height_); 627 &out_width_, &out_height_));
629 EXPECT_EQ(1280, cropped_width_); 628 EXPECT_EQ(1280, cropped_width_);
630 EXPECT_EQ(720, cropped_height_); 629 EXPECT_EQ(720, cropped_height_);
631 EXPECT_EQ(640, out_width_); 630 EXPECT_EQ(640, out_width_);
632 EXPECT_EQ(360, out_height_); 631 EXPECT_EQ(360, out_height_);
633 632
634 // Now, the camera reopens at VGA. 633 // Now, the camera reopens at VGA.
635 // Both the frame and the output format should be 640x360. 634 // Both the frame and the output format should be 640x360.
636 adapter_.AdaptFrameResolution(640, 360, 0, 635 EXPECT_TRUE(adapter_.AdaptFrameResolution(640, 360, 0,
637 &cropped_width_, &cropped_height_, 636 &cropped_width_, &cropped_height_,
638 &out_width_, &out_height_); 637 &out_width_, &out_height_));
639 EXPECT_EQ(640, cropped_width_); 638 EXPECT_EQ(640, cropped_width_);
640 EXPECT_EQ(360, cropped_height_); 639 EXPECT_EQ(360, cropped_height_);
641 EXPECT_EQ(640, out_width_); 640 EXPECT_EQ(640, out_width_);
642 EXPECT_EQ(360, out_height_); 641 EXPECT_EQ(360, out_height_);
643 642
644 // And another view request comes in for 640x360, which should have no 643 // And another view request comes in for 640x360, which should have no
645 // real impact. 644 // real impact.
646 adapter_.OnOutputFormatRequest(format); 645 adapter_.OnOutputFormatRequest(format);
647 adapter_.AdaptFrameResolution(640, 360, 0, 646 EXPECT_TRUE(adapter_.AdaptFrameResolution(640, 360, 0,
648 &cropped_width_, &cropped_height_, 647 &cropped_width_, &cropped_height_,
649 &out_width_, &out_height_); 648 &out_width_, &out_height_));
650 EXPECT_EQ(640, cropped_width_); 649 EXPECT_EQ(640, cropped_width_);
651 EXPECT_EQ(360, cropped_height_); 650 EXPECT_EQ(360, cropped_height_);
652 EXPECT_EQ(640, out_width_); 651 EXPECT_EQ(640, out_width_);
653 EXPECT_EQ(360, out_height_); 652 EXPECT_EQ(360, out_height_);
654 } 653 }
655 654
656 TEST_F(VideoAdapterTest, TestVGAWidth) { 655 TEST_F(VideoAdapterTest, TestVGAWidth) {
657 // Reqeuested Output format is 640x360. 656 // Reqeuested Output format is 640x360.
658 VideoFormat format(640, 360, 0, FOURCC_I420); 657 VideoFormat format(640, 360, 0, FOURCC_I420);
659 adapter_.OnOutputFormatRequest(format); 658 adapter_.OnOutputFormatRequest(format);
660 659
661 adapter_.AdaptFrameResolution(640, 480, 0, 660 EXPECT_TRUE(adapter_.AdaptFrameResolution(640, 480, 0,
662 &cropped_width_, &cropped_height_, 661 &cropped_width_, &cropped_height_,
663 &out_width_, &out_height_); 662 &out_width_, &out_height_));
664 // Expect cropping. 663 // Expect cropping.
665 EXPECT_EQ(640, cropped_width_); 664 EXPECT_EQ(640, cropped_width_);
666 EXPECT_EQ(360, cropped_height_); 665 EXPECT_EQ(360, cropped_height_);
667 EXPECT_EQ(640, out_width_); 666 EXPECT_EQ(640, out_width_);
668 EXPECT_EQ(360, out_height_); 667 EXPECT_EQ(360, out_height_);
669 668
670 // But if frames come in at 640x360, we shouldn't adapt them down. 669 // But if frames come in at 640x360, we shouldn't adapt them down.
671 adapter_.AdaptFrameResolution(640, 360, 0, 670 EXPECT_TRUE(adapter_.AdaptFrameResolution(640, 360, 0,
672 &cropped_width_, &cropped_height_, 671 &cropped_width_, &cropped_height_,
673 &out_width_, &out_height_); 672 &out_width_, &out_height_));
674 EXPECT_EQ(640, cropped_width_); 673 EXPECT_EQ(640, cropped_width_);
675 EXPECT_EQ(360, cropped_height_); 674 EXPECT_EQ(360, cropped_height_);
676 EXPECT_EQ(640, out_width_); 675 EXPECT_EQ(640, out_width_);
677 EXPECT_EQ(360, out_height_); 676 EXPECT_EQ(360, out_height_);
678 677
679 adapter_.AdaptFrameResolution(640, 480, 0, 678 EXPECT_TRUE(adapter_.AdaptFrameResolution(640, 480, 0,
680 &cropped_width_, &cropped_height_, 679 &cropped_width_, &cropped_height_,
681 &out_width_, &out_height_); 680 &out_width_, &out_height_));
682 EXPECT_EQ(640, cropped_width_); 681 EXPECT_EQ(640, cropped_width_);
683 EXPECT_EQ(360, cropped_height_); 682 EXPECT_EQ(360, cropped_height_);
684 EXPECT_EQ(640, out_width_); 683 EXPECT_EQ(640, out_width_);
685 EXPECT_EQ(360, out_height_); 684 EXPECT_EQ(360, out_height_);
686 } 685 }
687 686
688 TEST_F(VideoAdapterTest, TestOnResolutionRequestInSmallSteps) { 687 TEST_F(VideoAdapterTest, TestOnResolutionRequestInSmallSteps) {
689 adapter_.AdaptFrameResolution(1280, 720, 0, 688 EXPECT_TRUE(adapter_.AdaptFrameResolution(1280, 720, 0,
690 &cropped_width_, &cropped_height_, 689 &cropped_width_, &cropped_height_,
691 &out_width_, &out_height_); 690 &out_width_, &out_height_));
692 EXPECT_EQ(1280, cropped_width_); 691 EXPECT_EQ(1280, cropped_width_);
693 EXPECT_EQ(720, cropped_height_); 692 EXPECT_EQ(720, cropped_height_);
694 EXPECT_EQ(1280, out_width_); 693 EXPECT_EQ(1280, out_width_);
695 EXPECT_EQ(720, out_height_); 694 EXPECT_EQ(720, out_height_);
696 695
697 // Adapt down one step. 696 // Adapt down one step.
698 adapter_.OnResolutionRequest(rtc::Optional<int>(1280 * 720 - 1), 697 adapter_.OnResolutionRequest(rtc::Optional<int>(1280 * 720 - 1),
699 rtc::Optional<int>()); 698 rtc::Optional<int>());
700 adapter_.AdaptFrameResolution(1280, 720, 0, 699 EXPECT_TRUE(adapter_.AdaptFrameResolution(1280, 720, 0,
701 &cropped_width_, &cropped_height_, 700 &cropped_width_, &cropped_height_,
702 &out_width_, &out_height_); 701 &out_width_, &out_height_));
703 EXPECT_EQ(1280, cropped_width_); 702 EXPECT_EQ(1280, cropped_width_);
704 EXPECT_EQ(720, cropped_height_); 703 EXPECT_EQ(720, cropped_height_);
705 EXPECT_EQ(960, out_width_); 704 EXPECT_EQ(960, out_width_);
706 EXPECT_EQ(540, out_height_); 705 EXPECT_EQ(540, out_height_);
707 706
708 // Adapt down one step more. 707 // Adapt down one step more.
709 adapter_.OnResolutionRequest(rtc::Optional<int>(960 * 540 - 1), 708 adapter_.OnResolutionRequest(rtc::Optional<int>(960 * 540 - 1),
710 rtc::Optional<int>()); 709 rtc::Optional<int>());
711 adapter_.AdaptFrameResolution(1280, 720, 0, 710 EXPECT_TRUE(adapter_.AdaptFrameResolution(1280, 720, 0,
712 &cropped_width_, &cropped_height_, 711 &cropped_width_, &cropped_height_,
713 &out_width_, &out_height_); 712 &out_width_, &out_height_));
714 EXPECT_EQ(1280, cropped_width_); 713 EXPECT_EQ(1280, cropped_width_);
715 EXPECT_EQ(720, cropped_height_); 714 EXPECT_EQ(720, cropped_height_);
716 EXPECT_EQ(640, out_width_); 715 EXPECT_EQ(640, out_width_);
717 EXPECT_EQ(360, out_height_); 716 EXPECT_EQ(360, out_height_);
718 717
719 // Adapt down one step more. 718 // Adapt down one step more.
720 adapter_.OnResolutionRequest(rtc::Optional<int>(640 * 360 - 1), 719 adapter_.OnResolutionRequest(rtc::Optional<int>(640 * 360 - 1),
721 rtc::Optional<int>()); 720 rtc::Optional<int>());
722 adapter_.AdaptFrameResolution(1280, 720, 0, 721 EXPECT_TRUE(adapter_.AdaptFrameResolution(1280, 720, 0,
723 &cropped_width_, &cropped_height_, 722 &cropped_width_, &cropped_height_,
724 &out_width_, &out_height_); 723 &out_width_, &out_height_));
725 EXPECT_EQ(1280, cropped_width_); 724 EXPECT_EQ(1280, cropped_width_);
726 EXPECT_EQ(720, cropped_height_); 725 EXPECT_EQ(720, cropped_height_);
727 EXPECT_EQ(480, out_width_); 726 EXPECT_EQ(480, out_width_);
728 EXPECT_EQ(270, out_height_); 727 EXPECT_EQ(270, out_height_);
729 728
730 // Adapt up one step. 729 // Adapt up one step.
731 adapter_.OnResolutionRequest(rtc::Optional<int>(), 730 adapter_.OnResolutionRequest(rtc::Optional<int>(),
732 rtc::Optional<int>(480 * 270)); 731 rtc::Optional<int>(480 * 270));
733 adapter_.AdaptFrameResolution(1280, 720, 0, 732 EXPECT_TRUE(adapter_.AdaptFrameResolution(1280, 720, 0,
734 &cropped_width_, &cropped_height_, 733 &cropped_width_, &cropped_height_,
735 &out_width_, &out_height_); 734 &out_width_, &out_height_));
736 EXPECT_EQ(1280, cropped_width_); 735 EXPECT_EQ(1280, cropped_width_);
737 EXPECT_EQ(720, cropped_height_); 736 EXPECT_EQ(720, cropped_height_);
738 EXPECT_EQ(640, out_width_); 737 EXPECT_EQ(640, out_width_);
739 EXPECT_EQ(360, out_height_); 738 EXPECT_EQ(360, out_height_);
740 739
741 // Adapt up one step more. 740 // Adapt up one step more.
742 adapter_.OnResolutionRequest(rtc::Optional<int>(), 741 adapter_.OnResolutionRequest(rtc::Optional<int>(),
743 rtc::Optional<int>(640 * 360)); 742 rtc::Optional<int>(640 * 360));
744 adapter_.AdaptFrameResolution(1280, 720, 0, 743 EXPECT_TRUE(adapter_.AdaptFrameResolution(1280, 720, 0,
745 &cropped_width_, &cropped_height_, 744 &cropped_width_, &cropped_height_,
746 &out_width_, &out_height_); 745 &out_width_, &out_height_));
747 EXPECT_EQ(1280, cropped_width_); 746 EXPECT_EQ(1280, cropped_width_);
748 EXPECT_EQ(720, cropped_height_); 747 EXPECT_EQ(720, cropped_height_);
749 EXPECT_EQ(960, out_width_); 748 EXPECT_EQ(960, out_width_);
750 EXPECT_EQ(540, out_height_); 749 EXPECT_EQ(540, out_height_);
751 750
752 // Adapt up one step more. 751 // Adapt up one step more.
753 adapter_.OnResolutionRequest(rtc::Optional<int>(), 752 adapter_.OnResolutionRequest(rtc::Optional<int>(),
754 rtc::Optional<int>(960 * 720)); 753 rtc::Optional<int>(960 * 720));
755 adapter_.AdaptFrameResolution(1280, 720, 0, 754 EXPECT_TRUE(adapter_.AdaptFrameResolution(1280, 720, 0,
756 &cropped_width_, &cropped_height_, 755 &cropped_width_, &cropped_height_,
757 &out_width_, &out_height_); 756 &out_width_, &out_height_));
758 EXPECT_EQ(1280, cropped_width_); 757 EXPECT_EQ(1280, cropped_width_);
759 EXPECT_EQ(720, cropped_height_); 758 EXPECT_EQ(720, cropped_height_);
760 EXPECT_EQ(1280, out_width_); 759 EXPECT_EQ(1280, out_width_);
761 EXPECT_EQ(720, out_height_); 760 EXPECT_EQ(720, out_height_);
762 } 761 }
763 762
764 TEST_F(VideoAdapterTest, TestOnResolutionRequestMaxZero) { 763 TEST_F(VideoAdapterTest, TestOnResolutionRequestMaxZero) {
765 adapter_.AdaptFrameResolution(1280, 720, 0, 764 EXPECT_TRUE(adapter_.AdaptFrameResolution(1280, 720, 0,
766 &cropped_width_, &cropped_height_, 765 &cropped_width_, &cropped_height_,
767 &out_width_, &out_height_); 766 &out_width_, &out_height_));
768 EXPECT_EQ(1280, cropped_width_); 767 EXPECT_EQ(1280, cropped_width_);
769 EXPECT_EQ(720, cropped_height_); 768 EXPECT_EQ(720, cropped_height_);
770 EXPECT_EQ(1280, out_width_); 769 EXPECT_EQ(1280, out_width_);
771 EXPECT_EQ(720, out_height_); 770 EXPECT_EQ(720, out_height_);
772 771
773 adapter_.OnResolutionRequest(rtc::Optional<int>(0), rtc::Optional<int>()); 772 adapter_.OnResolutionRequest(rtc::Optional<int>(0), rtc::Optional<int>());
774 adapter_.AdaptFrameResolution(1280, 720, 0, 773 EXPECT_FALSE(adapter_.AdaptFrameResolution(1280, 720, 0,
775 &cropped_width_, &cropped_height_, 774 &cropped_width_, &cropped_height_,
776 &out_width_, &out_height_); 775 &out_width_, &out_height_));
777 EXPECT_EQ(0, out_width_);
778 EXPECT_EQ(0, out_height_);
779 } 776 }
780 777
781 TEST_F(VideoAdapterTest, TestOnResolutionRequestInLargeSteps) { 778 TEST_F(VideoAdapterTest, TestOnResolutionRequestInLargeSteps) {
782 adapter_.OnResolutionRequest(rtc::Optional<int>(640 * 360 - 1), 779 adapter_.OnResolutionRequest(rtc::Optional<int>(640 * 360 - 1),
783 rtc::Optional<int>()); 780 rtc::Optional<int>());
784 adapter_.AdaptFrameResolution(1280, 720, 0, 781 EXPECT_TRUE(adapter_.AdaptFrameResolution(1280, 720, 0,
785 &cropped_width_, &cropped_height_, 782 &cropped_width_, &cropped_height_,
786 &out_width_, &out_height_); 783 &out_width_, &out_height_));
787 EXPECT_EQ(1280, cropped_width_); 784 EXPECT_EQ(1280, cropped_width_);
788 EXPECT_EQ(720, cropped_height_); 785 EXPECT_EQ(720, cropped_height_);
789 EXPECT_EQ(480, out_width_); 786 EXPECT_EQ(480, out_width_);
790 EXPECT_EQ(270, out_height_); 787 EXPECT_EQ(270, out_height_);
791 788
792 adapter_.OnResolutionRequest(rtc::Optional<int>(), 789 adapter_.OnResolutionRequest(rtc::Optional<int>(),
793 rtc::Optional<int>(960 * 720)); 790 rtc::Optional<int>(960 * 720));
794 adapter_.AdaptFrameResolution(1280, 720, 0, 791 EXPECT_TRUE(adapter_.AdaptFrameResolution(1280, 720, 0,
795 &cropped_width_, &cropped_height_, 792 &cropped_width_, &cropped_height_,
796 &out_width_, &out_height_); 793 &out_width_, &out_height_));
797 EXPECT_EQ(1280, cropped_width_); 794 EXPECT_EQ(1280, cropped_width_);
798 EXPECT_EQ(720, cropped_height_); 795 EXPECT_EQ(720, cropped_height_);
799 EXPECT_EQ(1280, out_width_); 796 EXPECT_EQ(1280, out_width_);
800 EXPECT_EQ(720, out_height_); 797 EXPECT_EQ(720, out_height_);
801 } 798 }
802 799
803 TEST_F(VideoAdapterTest, TestOnOutputFormatRequestCapsMaxResolution) { 800 TEST_F(VideoAdapterTest, TestOnOutputFormatRequestCapsMaxResolution) {
804 adapter_.OnResolutionRequest(rtc::Optional<int>(640 * 360 - 1), 801 adapter_.OnResolutionRequest(rtc::Optional<int>(640 * 360 - 1),
805 rtc::Optional<int>()); 802 rtc::Optional<int>());
806 adapter_.AdaptFrameResolution(1280, 720, 0, 803 EXPECT_TRUE(adapter_.AdaptFrameResolution(1280, 720, 0,
807 &cropped_width_, &cropped_height_, 804 &cropped_width_, &cropped_height_,
808 &out_width_, &out_height_); 805 &out_width_, &out_height_));
809 EXPECT_EQ(1280, cropped_width_); 806 EXPECT_EQ(1280, cropped_width_);
810 EXPECT_EQ(720, cropped_height_); 807 EXPECT_EQ(720, cropped_height_);
811 EXPECT_EQ(480, out_width_); 808 EXPECT_EQ(480, out_width_);
812 EXPECT_EQ(270, out_height_); 809 EXPECT_EQ(270, out_height_);
813 810
814 VideoFormat new_format(640, 360, 0, FOURCC_I420); 811 VideoFormat new_format(640, 360, 0, FOURCC_I420);
815 adapter_.OnOutputFormatRequest(new_format); 812 adapter_.OnOutputFormatRequest(new_format);
816 adapter_.AdaptFrameResolution(1280, 720, 0, 813 EXPECT_TRUE(adapter_.AdaptFrameResolution(1280, 720, 0,
817 &cropped_width_, &cropped_height_, 814 &cropped_width_, &cropped_height_,
818 &out_width_, &out_height_); 815 &out_width_, &out_height_));
819 EXPECT_EQ(1280, cropped_width_); 816 EXPECT_EQ(1280, cropped_width_);
820 EXPECT_EQ(720, cropped_height_); 817 EXPECT_EQ(720, cropped_height_);
821 EXPECT_EQ(480, out_width_); 818 EXPECT_EQ(480, out_width_);
822 EXPECT_EQ(270, out_height_); 819 EXPECT_EQ(270, out_height_);
823 820
824 adapter_.OnResolutionRequest(rtc::Optional<int>(), 821 adapter_.OnResolutionRequest(rtc::Optional<int>(),
825 rtc::Optional<int>(960 * 720)); 822 rtc::Optional<int>(960 * 720));
826 adapter_.AdaptFrameResolution(1280, 720, 0, 823 EXPECT_TRUE(adapter_.AdaptFrameResolution(1280, 720, 0,
827 &cropped_width_, &cropped_height_, 824 &cropped_width_, &cropped_height_,
828 &out_width_, &out_height_); 825 &out_width_, &out_height_));
829 EXPECT_EQ(1280, cropped_width_); 826 EXPECT_EQ(1280, cropped_width_);
830 EXPECT_EQ(720, cropped_height_); 827 EXPECT_EQ(720, cropped_height_);
831 EXPECT_EQ(640, out_width_); 828 EXPECT_EQ(640, out_width_);
832 EXPECT_EQ(360, out_height_); 829 EXPECT_EQ(360, out_height_);
833 } 830 }
834 831
835 TEST_F(VideoAdapterTest, TestOnResolutionRequestReset) { 832 TEST_F(VideoAdapterTest, TestOnResolutionRequestReset) {
836 adapter_.AdaptFrameResolution(1280, 720, 0, 833 EXPECT_TRUE(adapter_.AdaptFrameResolution(1280, 720, 0,
837 &cropped_width_, &cropped_height_, 834 &cropped_width_, &cropped_height_,
838 &out_width_, &out_height_); 835 &out_width_, &out_height_));
839 EXPECT_EQ(1280, cropped_width_); 836 EXPECT_EQ(1280, cropped_width_);
840 EXPECT_EQ(720, cropped_height_); 837 EXPECT_EQ(720, cropped_height_);
841 EXPECT_EQ(1280, out_width_); 838 EXPECT_EQ(1280, out_width_);
842 EXPECT_EQ(720, out_height_); 839 EXPECT_EQ(720, out_height_);
843 840
844 adapter_.OnResolutionRequest(rtc::Optional<int>(640 * 360 - 1), 841 adapter_.OnResolutionRequest(rtc::Optional<int>(640 * 360 - 1),
845 rtc::Optional<int>()); 842 rtc::Optional<int>());
846 adapter_.AdaptFrameResolution(1280, 720, 0, 843 EXPECT_TRUE(adapter_.AdaptFrameResolution(1280, 720, 0,
847 &cropped_width_, &cropped_height_, 844 &cropped_width_, &cropped_height_,
848 &out_width_, &out_height_); 845 &out_width_, &out_height_));
849 EXPECT_EQ(1280, cropped_width_); 846 EXPECT_EQ(1280, cropped_width_);
850 EXPECT_EQ(720, cropped_height_); 847 EXPECT_EQ(720, cropped_height_);
851 EXPECT_EQ(480, out_width_); 848 EXPECT_EQ(480, out_width_);
852 EXPECT_EQ(270, out_height_); 849 EXPECT_EQ(270, out_height_);
853 850
854 adapter_.OnResolutionRequest(rtc::Optional<int>(), rtc::Optional<int>()); 851 adapter_.OnResolutionRequest(rtc::Optional<int>(), rtc::Optional<int>());
855 adapter_.AdaptFrameResolution(1280, 720, 0, 852 EXPECT_TRUE(adapter_.AdaptFrameResolution(1280, 720, 0,
856 &cropped_width_, &cropped_height_, 853 &cropped_width_, &cropped_height_,
857 &out_width_, &out_height_); 854 &out_width_, &out_height_));
858 EXPECT_EQ(1280, cropped_width_); 855 EXPECT_EQ(1280, cropped_width_);
859 EXPECT_EQ(720, cropped_height_); 856 EXPECT_EQ(720, cropped_height_);
860 EXPECT_EQ(1280, out_width_); 857 EXPECT_EQ(1280, out_width_);
861 EXPECT_EQ(720, out_height_); 858 EXPECT_EQ(720, out_height_);
862 } 859 }
863 860
864 TEST_F(VideoAdapterTest, TestCroppingWithResolutionRequest) { 861 TEST_F(VideoAdapterTest, TestCroppingWithResolutionRequest) {
865 // Ask for 640x360 (16:9 aspect). 862 // Ask for 640x360 (16:9 aspect).
866 adapter_.OnOutputFormatRequest(VideoFormat(640, 360, 0, FOURCC_I420)); 863 adapter_.OnOutputFormatRequest(VideoFormat(640, 360, 0, FOURCC_I420));
867 // Send 640x480 (4:3 aspect). 864 // Send 640x480 (4:3 aspect).
868 adapter_.AdaptFrameResolution(640, 480, 0, 865 EXPECT_TRUE(adapter_.AdaptFrameResolution(640, 480, 0,
869 &cropped_width_, &cropped_height_, 866 &cropped_width_, &cropped_height_,
870 &out_width_, &out_height_); 867 &out_width_, &out_height_));
871 // Expect cropping to 16:9 format and no scaling. 868 // Expect cropping to 16:9 format and no scaling.
872 EXPECT_EQ(640, cropped_width_); 869 EXPECT_EQ(640, cropped_width_);
873 EXPECT_EQ(360, cropped_height_); 870 EXPECT_EQ(360, cropped_height_);
874 EXPECT_EQ(640, out_width_); 871 EXPECT_EQ(640, out_width_);
875 EXPECT_EQ(360, out_height_); 872 EXPECT_EQ(360, out_height_);
876 873
877 // Adapt down one step. 874 // Adapt down one step.
878 adapter_.OnResolutionRequest(rtc::Optional<int>(640 * 360 - 1), 875 adapter_.OnResolutionRequest(rtc::Optional<int>(640 * 360 - 1),
879 rtc::Optional<int>()); 876 rtc::Optional<int>());
880 // Expect cropping to 16:9 format and 3/4 scaling. 877 // Expect cropping to 16:9 format and 3/4 scaling.
881 adapter_.AdaptFrameResolution(640, 480, 0, 878 EXPECT_TRUE(adapter_.AdaptFrameResolution(640, 480, 0,
882 &cropped_width_, &cropped_height_, 879 &cropped_width_, &cropped_height_,
883 &out_width_, &out_height_); 880 &out_width_, &out_height_));
884 EXPECT_EQ(640, cropped_width_); 881 EXPECT_EQ(640, cropped_width_);
885 EXPECT_EQ(360, cropped_height_); 882 EXPECT_EQ(360, cropped_height_);
886 EXPECT_EQ(480, out_width_); 883 EXPECT_EQ(480, out_width_);
887 EXPECT_EQ(270, out_height_); 884 EXPECT_EQ(270, out_height_);
888 885
889 // Adapt down one step more. 886 // Adapt down one step more.
890 adapter_.OnResolutionRequest(rtc::Optional<int>(480 * 270 - 1), 887 adapter_.OnResolutionRequest(rtc::Optional<int>(480 * 270 - 1),
891 rtc::Optional<int>()); 888 rtc::Optional<int>());
892 // Expect cropping to 16:9 format and 1/2 scaling. 889 // Expect cropping to 16:9 format and 1/2 scaling.
893 adapter_.AdaptFrameResolution(640, 480, 0, 890 EXPECT_TRUE(adapter_.AdaptFrameResolution(640, 480, 0,
894 &cropped_width_, &cropped_height_, 891 &cropped_width_, &cropped_height_,
895 &out_width_, &out_height_); 892 &out_width_, &out_height_));
896 EXPECT_EQ(640, cropped_width_); 893 EXPECT_EQ(640, cropped_width_);
897 EXPECT_EQ(360, cropped_height_); 894 EXPECT_EQ(360, cropped_height_);
898 EXPECT_EQ(320, out_width_); 895 EXPECT_EQ(320, out_width_);
899 EXPECT_EQ(180, out_height_); 896 EXPECT_EQ(180, out_height_);
900 897
901 // Adapt up one step. 898 // Adapt up one step.
902 adapter_.OnResolutionRequest(rtc::Optional<int>(), 899 adapter_.OnResolutionRequest(rtc::Optional<int>(),
903 rtc::Optional<int>(320 * 180)); 900 rtc::Optional<int>(320 * 180));
904 // Expect cropping to 16:9 format and 3/4 scaling. 901 // Expect cropping to 16:9 format and 3/4 scaling.
905 adapter_.AdaptFrameResolution(640, 480, 0, 902 EXPECT_TRUE(adapter_.AdaptFrameResolution(640, 480, 0,
906 &cropped_width_, &cropped_height_, 903 &cropped_width_, &cropped_height_,
907 &out_width_, &out_height_); 904 &out_width_, &out_height_));
908 EXPECT_EQ(640, cropped_width_); 905 EXPECT_EQ(640, cropped_width_);
909 EXPECT_EQ(360, cropped_height_); 906 EXPECT_EQ(360, cropped_height_);
910 EXPECT_EQ(480, out_width_); 907 EXPECT_EQ(480, out_width_);
911 EXPECT_EQ(270, out_height_); 908 EXPECT_EQ(270, out_height_);
912 909
913 // Adapt up one step more. 910 // Adapt up one step more.
914 adapter_.OnResolutionRequest(rtc::Optional<int>(), 911 adapter_.OnResolutionRequest(rtc::Optional<int>(),
915 rtc::Optional<int>(480 * 270)); 912 rtc::Optional<int>(480 * 270));
916 // Expect cropping to 16:9 format and no scaling. 913 // Expect cropping to 16:9 format and no scaling.
917 adapter_.AdaptFrameResolution(640, 480, 0, 914 EXPECT_TRUE(adapter_.AdaptFrameResolution(640, 480, 0,
918 &cropped_width_, &cropped_height_, 915 &cropped_width_, &cropped_height_,
919 &out_width_, &out_height_); 916 &out_width_, &out_height_));
920 EXPECT_EQ(640, cropped_width_); 917 EXPECT_EQ(640, cropped_width_);
921 EXPECT_EQ(360, cropped_height_); 918 EXPECT_EQ(360, cropped_height_);
922 EXPECT_EQ(640, out_width_); 919 EXPECT_EQ(640, out_width_);
923 EXPECT_EQ(360, out_height_); 920 EXPECT_EQ(360, out_height_);
924 921
925 // Try to adapt up one step more. 922 // Try to adapt up one step more.
926 adapter_.OnResolutionRequest(rtc::Optional<int>(), 923 adapter_.OnResolutionRequest(rtc::Optional<int>(),
927 rtc::Optional<int>(640 * 360)); 924 rtc::Optional<int>(640 * 360));
928 // Expect cropping to 16:9 format and no scaling. 925 // Expect cropping to 16:9 format and no scaling.
929 adapter_.AdaptFrameResolution(640, 480, 0, 926 EXPECT_TRUE(adapter_.AdaptFrameResolution(640, 480, 0,
930 &cropped_width_, &cropped_height_, 927 &cropped_width_, &cropped_height_,
931 &out_width_, &out_height_); 928 &out_width_, &out_height_));
932 EXPECT_EQ(640, cropped_width_); 929 EXPECT_EQ(640, cropped_width_);
933 EXPECT_EQ(360, cropped_height_); 930 EXPECT_EQ(360, cropped_height_);
934 EXPECT_EQ(640, out_width_); 931 EXPECT_EQ(640, out_width_);
935 EXPECT_EQ(360, out_height_); 932 EXPECT_EQ(360, out_height_);
936 } 933 }
937 934
938 TEST_F(VideoAdapterTest, TestCroppingOddResolution) { 935 TEST_F(VideoAdapterTest, TestCroppingOddResolution) {
939 // Ask for 640x360 (16:9 aspect), with 3/16 scaling. 936 // Ask for 640x360 (16:9 aspect), with 3/16 scaling.
940 adapter_.OnOutputFormatRequest( 937 adapter_.OnOutputFormatRequest(
941 VideoFormat(640, 360, 0, FOURCC_I420)); 938 VideoFormat(640, 360, 0, FOURCC_I420));
942 adapter_.OnResolutionRequest(rtc::Optional<int>(640 * 360 * 3 / 16 * 3 / 16), 939 adapter_.OnResolutionRequest(rtc::Optional<int>(640 * 360 * 3 / 16 * 3 / 16),
943 rtc::Optional<int>()); 940 rtc::Optional<int>());
944 941
945 // Send 640x480 (4:3 aspect). 942 // Send 640x480 (4:3 aspect).
946 adapter_.AdaptFrameResolution(640, 480, 0, 943 EXPECT_TRUE(adapter_.AdaptFrameResolution(640, 480, 0,
947 &cropped_width_, &cropped_height_, 944 &cropped_width_, &cropped_height_,
948 &out_width_, &out_height_); 945 &out_width_, &out_height_));
949 946
950 // Instead of getting the exact aspect ratio with cropped resolution 640x360, 947 // Instead of getting the exact aspect ratio with cropped resolution 640x360,
951 // the resolution should be adjusted to get a perfect scale factor instead. 948 // the resolution should be adjusted to get a perfect scale factor instead.
952 EXPECT_EQ(640, cropped_width_); 949 EXPECT_EQ(640, cropped_width_);
953 EXPECT_EQ(368, cropped_height_); 950 EXPECT_EQ(368, cropped_height_);
954 EXPECT_EQ(120, out_width_); 951 EXPECT_EQ(120, out_width_);
955 EXPECT_EQ(69, out_height_); 952 EXPECT_EQ(69, out_height_);
956 } 953 }
957 954
958 } // namespace cricket 955 } // 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