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

Side by Side Diff: webrtc/modules/video_capture/test/video_capture_unittest.cc

Issue 2278883002: Move MutableDataY{,U,V} methods to I420Buffer only. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Delete unused variable. Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2012 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 402 matching lines...) Expand 10 before | Expand all | Expand 10 after
413 process_module_->Start(); 413 process_module_->Start();
414 process_module_->RegisterModule(capture_module_); 414 process_module_->RegisterModule(capture_module_);
415 415
416 VideoCaptureCapability capability; 416 VideoCaptureCapability capability;
417 capability.width = kTestWidth; 417 capability.width = kTestWidth;
418 capability.height = kTestHeight; 418 capability.height = kTestHeight;
419 capability.rawType = webrtc::kVideoYV12; 419 capability.rawType = webrtc::kVideoYV12;
420 capability.maxFPS = kTestFramerate; 420 capability.maxFPS = kTestFramerate;
421 capture_callback_.SetExpectedCapability(capability); 421 capture_callback_.SetExpectedCapability(capability);
422 422
423 test_frame_.CreateEmptyFrame(kTestWidth, kTestHeight, kTestWidth, 423 rtc::scoped_refptr<webrtc::I420Buffer> buffer = webrtc::I420Buffer::Create(
424 ((kTestWidth + 1) / 2), (kTestWidth + 1) / 2); 424 kTestWidth, kTestHeight,
425 SleepMs(1); // Wait 1ms so that two tests can't have the same timestamp. 425 kTestWidth, ((kTestWidth + 1) / 2), (kTestWidth + 1) / 2);
426 memset(test_frame_.video_frame_buffer()->MutableDataY(), 127, 426
427 kTestWidth * kTestHeight); 427 memset(buffer->MutableDataY(), 127, kTestWidth * kTestHeight);
428 memset(test_frame_.video_frame_buffer()->MutableDataU(), 127, 428 memset(buffer->MutableDataU(), 127,
429 ((kTestWidth + 1) / 2) * ((kTestHeight + 1) / 2)); 429 ((kTestWidth + 1) / 2) * ((kTestHeight + 1) / 2));
430 memset(test_frame_.video_frame_buffer()->MutableDataV(), 127, 430 memset(buffer->MutableDataV(), 127,
431 ((kTestWidth + 1) / 2) * ((kTestHeight + 1) / 2)); 431 ((kTestWidth + 1) / 2) * ((kTestHeight + 1) / 2));
432 test_frame_.reset(
433 new webrtc::VideoFrame(buffer, 0, 0, webrtc::kVideoRotation_0));
434
435 SleepMs(1); // Wait 1ms so that two tests can't have the same timestamp.
432 436
433 capture_module_->RegisterCaptureDataCallback(capture_callback_); 437 capture_module_->RegisterCaptureDataCallback(capture_callback_);
434 capture_module_->RegisterCaptureCallback(capture_feedback_); 438 capture_module_->RegisterCaptureCallback(capture_feedback_);
435 capture_module_->EnableFrameRateCallback(true); 439 capture_module_->EnableFrameRateCallback(true);
436 capture_module_->EnableNoPictureAlarm(true); 440 capture_module_->EnableNoPictureAlarm(true);
437 } 441 }
438 442
439 void TearDown() { 443 void TearDown() {
440 process_module_->Stop(); 444 process_module_->Stop();
441 } 445 }
442 446
443 webrtc::VideoCaptureExternal* capture_input_interface_; 447 webrtc::VideoCaptureExternal* capture_input_interface_;
444 rtc::scoped_refptr<VideoCaptureModule> capture_module_; 448 rtc::scoped_refptr<VideoCaptureModule> capture_module_;
445 std::unique_ptr<webrtc::ProcessThread> process_module_; 449 std::unique_ptr<webrtc::ProcessThread> process_module_;
446 webrtc::VideoFrame test_frame_; 450 std::unique_ptr<webrtc::VideoFrame> test_frame_;
447 TestVideoCaptureCallback capture_callback_; 451 TestVideoCaptureCallback capture_callback_;
448 TestVideoCaptureFeedBack capture_feedback_; 452 TestVideoCaptureFeedBack capture_feedback_;
449 }; 453 };
450 454
451 // Test input of external video frames. 455 // Test input of external video frames.
452 TEST_F(VideoCaptureExternalTest, TestExternalCapture) { 456 TEST_F(VideoCaptureExternalTest, TestExternalCapture) {
453 size_t length = webrtc::CalcBufferSize(webrtc::kI420, 457 size_t length = webrtc::CalcBufferSize(webrtc::kI420,
454 test_frame_.width(), 458 test_frame_->width(),
455 test_frame_.height()); 459 test_frame_->height());
456 std::unique_ptr<uint8_t[]> test_buffer(new uint8_t[length]); 460 std::unique_ptr<uint8_t[]> test_buffer(new uint8_t[length]);
457 webrtc::ExtractBuffer(test_frame_, length, test_buffer.get()); 461 webrtc::ExtractBuffer(*test_frame_, length, test_buffer.get());
458 EXPECT_EQ(0, capture_input_interface_->IncomingFrame(test_buffer.get(), 462 EXPECT_EQ(0, capture_input_interface_->IncomingFrame(test_buffer.get(),
459 length, capture_callback_.capability(), 0)); 463 length, capture_callback_.capability(), 0));
460 EXPECT_TRUE(capture_callback_.CompareLastFrame(test_frame_)); 464 EXPECT_TRUE(capture_callback_.CompareLastFrame(*test_frame_));
461 } 465 }
462 466
463 // Test frame rate and no picture alarm. 467 // Test frame rate and no picture alarm.
464 // Flaky on Win32, see webrtc:3270. 468 // Flaky on Win32, see webrtc:3270.
465 #if defined(WEBRTC_WIN) || defined(WEBRTC_MAC) 469 #if defined(WEBRTC_WIN) || defined(WEBRTC_MAC)
466 #define MAYBE_FrameRate DISABLED_FrameRate 470 #define MAYBE_FrameRate DISABLED_FrameRate
467 #else 471 #else
468 #define MAYBE_FrameRate FrameRate 472 #define MAYBE_FrameRate FrameRate
469 #endif 473 #endif
470 TEST_F(VideoCaptureExternalTest, MAYBE_FrameRate) { 474 TEST_F(VideoCaptureExternalTest, MAYBE_FrameRate) {
471 uint64_t testTime = 3 * rtc::kNumNanosecsPerSec; 475 uint64_t testTime = 3 * rtc::kNumNanosecsPerSec;
472 uint64_t startTime = rtc::TimeNanos(); 476 uint64_t startTime = rtc::TimeNanos();
473 477
474 while ((rtc::TimeNanos() - startTime) < testTime) { 478 while ((rtc::TimeNanos() - startTime) < testTime) {
475 size_t length = webrtc::CalcBufferSize(webrtc::kI420, 479 size_t length = webrtc::CalcBufferSize(webrtc::kI420,
476 test_frame_.width(), 480 test_frame_->width(),
477 test_frame_.height()); 481 test_frame_->height());
478 std::unique_ptr<uint8_t[]> test_buffer(new uint8_t[length]); 482 std::unique_ptr<uint8_t[]> test_buffer(new uint8_t[length]);
479 webrtc::ExtractBuffer(test_frame_, length, test_buffer.get()); 483 webrtc::ExtractBuffer(*test_frame_, length, test_buffer.get());
480 EXPECT_EQ(0, capture_input_interface_->IncomingFrame(test_buffer.get(), 484 EXPECT_EQ(
481 length, capture_callback_.capability(), 0)); 485 0, capture_input_interface_->IncomingFrame(
486 test_buffer.get(), length, capture_callback_.capability(), 0));
482 SleepMs(100); 487 SleepMs(100);
483 } 488 }
484 EXPECT_TRUE(capture_feedback_.frame_rate() >= 8 && 489 EXPECT_TRUE(capture_feedback_.frame_rate() >= 8 &&
485 capture_feedback_.frame_rate() <= 10); 490 capture_feedback_.frame_rate() <= 10);
486 SleepMs(500); 491 SleepMs(500);
487 EXPECT_EQ(webrtc::Raised, capture_feedback_.alarm()); 492 EXPECT_EQ(webrtc::Raised, capture_feedback_.alarm());
488 493
489 startTime = rtc::TimeNanos(); 494 startTime = rtc::TimeNanos();
490 while ((rtc::TimeNanos() - startTime) < testTime) { 495 while ((rtc::TimeNanos() - startTime) < testTime) {
491 size_t length = webrtc::CalcBufferSize(webrtc::kI420, 496 size_t length = webrtc::CalcBufferSize(webrtc::kI420,
492 test_frame_.width(), 497 test_frame_->width(),
493 test_frame_.height()); 498 test_frame_->height());
494 std::unique_ptr<uint8_t[]> test_buffer(new uint8_t[length]); 499 std::unique_ptr<uint8_t[]> test_buffer(new uint8_t[length]);
495 webrtc::ExtractBuffer(test_frame_, length, test_buffer.get()); 500 webrtc::ExtractBuffer(*test_frame_, length, test_buffer.get());
496 EXPECT_EQ(0, capture_input_interface_->IncomingFrame(test_buffer.get(), 501 EXPECT_EQ(0, capture_input_interface_->IncomingFrame(test_buffer.get(),
497 length, capture_callback_.capability(), 0)); 502 length, capture_callback_.capability(), 0));
498 SleepMs(1000 / 30); 503 SleepMs(1000 / 30);
499 } 504 }
500 EXPECT_EQ(webrtc::Cleared, capture_feedback_.alarm()); 505 EXPECT_EQ(webrtc::Cleared, capture_feedback_.alarm());
501 // Frame rate might be less than 33 since we have paused providing 506 // Frame rate might be less than 33 since we have paused providing
502 // frames for a while. 507 // frames for a while.
503 EXPECT_TRUE(capture_feedback_.frame_rate() >= 25 && 508 EXPECT_TRUE(capture_feedback_.frame_rate() >= 25 &&
504 capture_feedback_.frame_rate() <= 33); 509 capture_feedback_.frame_rate() <= 33);
505 } 510 }
506 511
507 TEST_F(VideoCaptureExternalTest, Rotation) { 512 TEST_F(VideoCaptureExternalTest, Rotation) {
508 EXPECT_EQ(0, capture_module_->SetCaptureRotation(webrtc::kVideoRotation_0)); 513 EXPECT_EQ(0, capture_module_->SetCaptureRotation(webrtc::kVideoRotation_0));
509 size_t length = webrtc::CalcBufferSize(webrtc::kI420, 514 size_t length = webrtc::CalcBufferSize(webrtc::kI420,
510 test_frame_.width(), 515 test_frame_->width(),
511 test_frame_.height()); 516 test_frame_->height());
512 std::unique_ptr<uint8_t[]> test_buffer(new uint8_t[length]); 517 std::unique_ptr<uint8_t[]> test_buffer(new uint8_t[length]);
513 webrtc::ExtractBuffer(test_frame_, length, test_buffer.get()); 518 webrtc::ExtractBuffer(*test_frame_, length, test_buffer.get());
514 EXPECT_EQ(0, capture_input_interface_->IncomingFrame(test_buffer.get(), 519 EXPECT_EQ(0, capture_input_interface_->IncomingFrame(test_buffer.get(),
515 length, capture_callback_.capability(), 0)); 520 length, capture_callback_.capability(), 0));
516 EXPECT_EQ(0, capture_module_->SetCaptureRotation(webrtc::kVideoRotation_90)); 521 EXPECT_EQ(0, capture_module_->SetCaptureRotation(webrtc::kVideoRotation_90));
517 capture_callback_.SetExpectedCaptureRotation(webrtc::kVideoRotation_90); 522 capture_callback_.SetExpectedCaptureRotation(webrtc::kVideoRotation_90);
518 EXPECT_EQ(0, capture_input_interface_->IncomingFrame(test_buffer.get(), 523 EXPECT_EQ(0, capture_input_interface_->IncomingFrame(test_buffer.get(),
519 length, capture_callback_.capability(), 0)); 524 length, capture_callback_.capability(), 0));
520 EXPECT_EQ(0, capture_module_->SetCaptureRotation(webrtc::kVideoRotation_180)); 525 EXPECT_EQ(0, capture_module_->SetCaptureRotation(webrtc::kVideoRotation_180));
521 capture_callback_.SetExpectedCaptureRotation(webrtc::kVideoRotation_180); 526 capture_callback_.SetExpectedCaptureRotation(webrtc::kVideoRotation_180);
522 EXPECT_EQ(0, capture_input_interface_->IncomingFrame(test_buffer.get(), 527 EXPECT_EQ(0, capture_input_interface_->IncomingFrame(test_buffer.get(),
523 length, capture_callback_.capability(), 0)); 528 length, capture_callback_.capability(), 0));
524 EXPECT_EQ(0, capture_module_->SetCaptureRotation(webrtc::kVideoRotation_270)); 529 EXPECT_EQ(0, capture_module_->SetCaptureRotation(webrtc::kVideoRotation_270));
525 capture_callback_.SetExpectedCaptureRotation(webrtc::kVideoRotation_270); 530 capture_callback_.SetExpectedCaptureRotation(webrtc::kVideoRotation_270);
526 EXPECT_EQ(0, capture_input_interface_->IncomingFrame(test_buffer.get(), 531 EXPECT_EQ(0, capture_input_interface_->IncomingFrame(test_buffer.get(),
527 length, capture_callback_.capability(), 0)); 532 length, capture_callback_.capability(), 0));
528 } 533 }
OLDNEW
« no previous file with comments | « webrtc/media/engine/webrtcvideoframe.cc ('k') | webrtc/modules/video_capture/video_capture_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698