OLD | NEW |
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 Loading... |
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 rtc::scoped_refptr<webrtc::I420Buffer> buffer = webrtc::I420Buffer::Create( | 423 test_frame_.CreateEmptyFrame(kTestWidth, kTestHeight, kTestWidth, |
424 kTestWidth, kTestHeight, | 424 ((kTestWidth + 1) / 2), (kTestWidth + 1) / 2); |
425 kTestWidth, ((kTestWidth + 1) / 2), (kTestWidth + 1) / 2); | 425 SleepMs(1); // Wait 1ms so that two tests can't have the same timestamp. |
426 | 426 memset(test_frame_.video_frame_buffer()->MutableDataY(), 127, |
427 memset(buffer->MutableDataY(), 127, kTestWidth * kTestHeight); | 427 kTestWidth * kTestHeight); |
428 memset(buffer->MutableDataU(), 127, | 428 memset(test_frame_.video_frame_buffer()->MutableDataU(), 127, |
429 ((kTestWidth + 1) / 2) * ((kTestHeight + 1) / 2)); | 429 ((kTestWidth + 1) / 2) * ((kTestHeight + 1) / 2)); |
430 memset(buffer->MutableDataV(), 127, | 430 memset(test_frame_.video_frame_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. | |
436 | 432 |
437 capture_module_->RegisterCaptureDataCallback(capture_callback_); | 433 capture_module_->RegisterCaptureDataCallback(capture_callback_); |
438 capture_module_->RegisterCaptureCallback(capture_feedback_); | 434 capture_module_->RegisterCaptureCallback(capture_feedback_); |
439 capture_module_->EnableFrameRateCallback(true); | 435 capture_module_->EnableFrameRateCallback(true); |
440 capture_module_->EnableNoPictureAlarm(true); | 436 capture_module_->EnableNoPictureAlarm(true); |
441 } | 437 } |
442 | 438 |
443 void TearDown() { | 439 void TearDown() { |
444 process_module_->Stop(); | 440 process_module_->Stop(); |
445 } | 441 } |
446 | 442 |
447 webrtc::VideoCaptureExternal* capture_input_interface_; | 443 webrtc::VideoCaptureExternal* capture_input_interface_; |
448 rtc::scoped_refptr<VideoCaptureModule> capture_module_; | 444 rtc::scoped_refptr<VideoCaptureModule> capture_module_; |
449 std::unique_ptr<webrtc::ProcessThread> process_module_; | 445 std::unique_ptr<webrtc::ProcessThread> process_module_; |
450 std::unique_ptr<webrtc::VideoFrame> test_frame_; | 446 webrtc::VideoFrame test_frame_; |
451 TestVideoCaptureCallback capture_callback_; | 447 TestVideoCaptureCallback capture_callback_; |
452 TestVideoCaptureFeedBack capture_feedback_; | 448 TestVideoCaptureFeedBack capture_feedback_; |
453 }; | 449 }; |
454 | 450 |
455 // Test input of external video frames. | 451 // Test input of external video frames. |
456 TEST_F(VideoCaptureExternalTest, TestExternalCapture) { | 452 TEST_F(VideoCaptureExternalTest, TestExternalCapture) { |
457 size_t length = webrtc::CalcBufferSize(webrtc::kI420, | 453 size_t length = webrtc::CalcBufferSize(webrtc::kI420, |
458 test_frame_->width(), | 454 test_frame_.width(), |
459 test_frame_->height()); | 455 test_frame_.height()); |
460 std::unique_ptr<uint8_t[]> test_buffer(new uint8_t[length]); | 456 std::unique_ptr<uint8_t[]> test_buffer(new uint8_t[length]); |
461 webrtc::ExtractBuffer(*test_frame_, length, test_buffer.get()); | 457 webrtc::ExtractBuffer(test_frame_, length, test_buffer.get()); |
462 EXPECT_EQ(0, capture_input_interface_->IncomingFrame(test_buffer.get(), | 458 EXPECT_EQ(0, capture_input_interface_->IncomingFrame(test_buffer.get(), |
463 length, capture_callback_.capability(), 0)); | 459 length, capture_callback_.capability(), 0)); |
464 EXPECT_TRUE(capture_callback_.CompareLastFrame(*test_frame_)); | 460 EXPECT_TRUE(capture_callback_.CompareLastFrame(test_frame_)); |
465 } | 461 } |
466 | 462 |
467 // Test frame rate and no picture alarm. | 463 // Test frame rate and no picture alarm. |
468 // Flaky on Win32, see webrtc:3270. | 464 // Flaky on Win32, see webrtc:3270. |
469 #if defined(WEBRTC_WIN) || defined(WEBRTC_MAC) | 465 #if defined(WEBRTC_WIN) || defined(WEBRTC_MAC) |
470 #define MAYBE_FrameRate DISABLED_FrameRate | 466 #define MAYBE_FrameRate DISABLED_FrameRate |
471 #else | 467 #else |
472 #define MAYBE_FrameRate FrameRate | 468 #define MAYBE_FrameRate FrameRate |
473 #endif | 469 #endif |
474 TEST_F(VideoCaptureExternalTest, MAYBE_FrameRate) { | 470 TEST_F(VideoCaptureExternalTest, MAYBE_FrameRate) { |
475 uint64_t testTime = 3 * rtc::kNumNanosecsPerSec; | 471 uint64_t testTime = 3 * rtc::kNumNanosecsPerSec; |
476 uint64_t startTime = rtc::TimeNanos(); | 472 uint64_t startTime = rtc::TimeNanos(); |
477 | 473 |
478 while ((rtc::TimeNanos() - startTime) < testTime) { | 474 while ((rtc::TimeNanos() - startTime) < testTime) { |
479 size_t length = webrtc::CalcBufferSize(webrtc::kI420, | 475 size_t length = webrtc::CalcBufferSize(webrtc::kI420, |
480 test_frame_->width(), | 476 test_frame_.width(), |
481 test_frame_->height()); | 477 test_frame_.height()); |
482 std::unique_ptr<uint8_t[]> test_buffer(new uint8_t[length]); | 478 std::unique_ptr<uint8_t[]> test_buffer(new uint8_t[length]); |
483 webrtc::ExtractBuffer(*test_frame_, length, test_buffer.get()); | 479 webrtc::ExtractBuffer(test_frame_, length, test_buffer.get()); |
484 EXPECT_EQ( | 480 EXPECT_EQ(0, capture_input_interface_->IncomingFrame(test_buffer.get(), |
485 0, capture_input_interface_->IncomingFrame( | 481 length, capture_callback_.capability(), 0)); |
486 test_buffer.get(), length, capture_callback_.capability(), 0)); | |
487 SleepMs(100); | 482 SleepMs(100); |
488 } | 483 } |
489 EXPECT_TRUE(capture_feedback_.frame_rate() >= 8 && | 484 EXPECT_TRUE(capture_feedback_.frame_rate() >= 8 && |
490 capture_feedback_.frame_rate() <= 10); | 485 capture_feedback_.frame_rate() <= 10); |
491 SleepMs(500); | 486 SleepMs(500); |
492 EXPECT_EQ(webrtc::Raised, capture_feedback_.alarm()); | 487 EXPECT_EQ(webrtc::Raised, capture_feedback_.alarm()); |
493 | 488 |
494 startTime = rtc::TimeNanos(); | 489 startTime = rtc::TimeNanos(); |
495 while ((rtc::TimeNanos() - startTime) < testTime) { | 490 while ((rtc::TimeNanos() - startTime) < testTime) { |
496 size_t length = webrtc::CalcBufferSize(webrtc::kI420, | 491 size_t length = webrtc::CalcBufferSize(webrtc::kI420, |
497 test_frame_->width(), | 492 test_frame_.width(), |
498 test_frame_->height()); | 493 test_frame_.height()); |
499 std::unique_ptr<uint8_t[]> test_buffer(new uint8_t[length]); | 494 std::unique_ptr<uint8_t[]> test_buffer(new uint8_t[length]); |
500 webrtc::ExtractBuffer(*test_frame_, length, test_buffer.get()); | 495 webrtc::ExtractBuffer(test_frame_, length, test_buffer.get()); |
501 EXPECT_EQ(0, capture_input_interface_->IncomingFrame(test_buffer.get(), | 496 EXPECT_EQ(0, capture_input_interface_->IncomingFrame(test_buffer.get(), |
502 length, capture_callback_.capability(), 0)); | 497 length, capture_callback_.capability(), 0)); |
503 SleepMs(1000 / 30); | 498 SleepMs(1000 / 30); |
504 } | 499 } |
505 EXPECT_EQ(webrtc::Cleared, capture_feedback_.alarm()); | 500 EXPECT_EQ(webrtc::Cleared, capture_feedback_.alarm()); |
506 // Frame rate might be less than 33 since we have paused providing | 501 // Frame rate might be less than 33 since we have paused providing |
507 // frames for a while. | 502 // frames for a while. |
508 EXPECT_TRUE(capture_feedback_.frame_rate() >= 25 && | 503 EXPECT_TRUE(capture_feedback_.frame_rate() >= 25 && |
509 capture_feedback_.frame_rate() <= 33); | 504 capture_feedback_.frame_rate() <= 33); |
510 } | 505 } |
511 | 506 |
512 TEST_F(VideoCaptureExternalTest, Rotation) { | 507 TEST_F(VideoCaptureExternalTest, Rotation) { |
513 EXPECT_EQ(0, capture_module_->SetCaptureRotation(webrtc::kVideoRotation_0)); | 508 EXPECT_EQ(0, capture_module_->SetCaptureRotation(webrtc::kVideoRotation_0)); |
514 size_t length = webrtc::CalcBufferSize(webrtc::kI420, | 509 size_t length = webrtc::CalcBufferSize(webrtc::kI420, |
515 test_frame_->width(), | 510 test_frame_.width(), |
516 test_frame_->height()); | 511 test_frame_.height()); |
517 std::unique_ptr<uint8_t[]> test_buffer(new uint8_t[length]); | 512 std::unique_ptr<uint8_t[]> test_buffer(new uint8_t[length]); |
518 webrtc::ExtractBuffer(*test_frame_, length, test_buffer.get()); | 513 webrtc::ExtractBuffer(test_frame_, length, test_buffer.get()); |
519 EXPECT_EQ(0, capture_input_interface_->IncomingFrame(test_buffer.get(), | 514 EXPECT_EQ(0, capture_input_interface_->IncomingFrame(test_buffer.get(), |
520 length, capture_callback_.capability(), 0)); | 515 length, capture_callback_.capability(), 0)); |
521 EXPECT_EQ(0, capture_module_->SetCaptureRotation(webrtc::kVideoRotation_90)); | 516 EXPECT_EQ(0, capture_module_->SetCaptureRotation(webrtc::kVideoRotation_90)); |
522 capture_callback_.SetExpectedCaptureRotation(webrtc::kVideoRotation_90); | 517 capture_callback_.SetExpectedCaptureRotation(webrtc::kVideoRotation_90); |
523 EXPECT_EQ(0, capture_input_interface_->IncomingFrame(test_buffer.get(), | 518 EXPECT_EQ(0, capture_input_interface_->IncomingFrame(test_buffer.get(), |
524 length, capture_callback_.capability(), 0)); | 519 length, capture_callback_.capability(), 0)); |
525 EXPECT_EQ(0, capture_module_->SetCaptureRotation(webrtc::kVideoRotation_180)); | 520 EXPECT_EQ(0, capture_module_->SetCaptureRotation(webrtc::kVideoRotation_180)); |
526 capture_callback_.SetExpectedCaptureRotation(webrtc::kVideoRotation_180); | 521 capture_callback_.SetExpectedCaptureRotation(webrtc::kVideoRotation_180); |
527 EXPECT_EQ(0, capture_input_interface_->IncomingFrame(test_buffer.get(), | 522 EXPECT_EQ(0, capture_input_interface_->IncomingFrame(test_buffer.get(), |
528 length, capture_callback_.capability(), 0)); | 523 length, capture_callback_.capability(), 0)); |
529 EXPECT_EQ(0, capture_module_->SetCaptureRotation(webrtc::kVideoRotation_270)); | 524 EXPECT_EQ(0, capture_module_->SetCaptureRotation(webrtc::kVideoRotation_270)); |
530 capture_callback_.SetExpectedCaptureRotation(webrtc::kVideoRotation_270); | 525 capture_callback_.SetExpectedCaptureRotation(webrtc::kVideoRotation_270); |
531 EXPECT_EQ(0, capture_input_interface_->IncomingFrame(test_buffer.get(), | 526 EXPECT_EQ(0, capture_input_interface_->IncomingFrame(test_buffer.get(), |
532 length, capture_callback_.capability(), 0)); | 527 length, capture_callback_.capability(), 0)); |
533 } | 528 } |
OLD | NEW |