OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "content/browser/media/capture/desktop_capture_device.h" | 5 #include "content/browser/media/capture/desktop_capture_device.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 #include <string.h> | 9 #include <string.h> |
10 #include <algorithm> | 10 #include <algorithm> |
(...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
285 #else | 285 #else |
286 #define MAYBE_Capture Capture | 286 #define MAYBE_Capture Capture |
287 #endif | 287 #endif |
288 TEST_F(DesktopCaptureDeviceTest, MAYBE_Capture) { | 288 TEST_F(DesktopCaptureDeviceTest, MAYBE_Capture) { |
289 std::unique_ptr<webrtc::DesktopCapturer> capturer( | 289 std::unique_ptr<webrtc::DesktopCapturer> capturer( |
290 webrtc::ScreenCapturer::Create( | 290 webrtc::ScreenCapturer::Create( |
291 webrtc::DesktopCaptureOptions::CreateDefault())); | 291 webrtc::DesktopCaptureOptions::CreateDefault())); |
292 CreateScreenCaptureDevice(std::move(capturer)); | 292 CreateScreenCaptureDevice(std::move(capturer)); |
293 | 293 |
294 media::VideoCaptureFormat format; | 294 media::VideoCaptureFormat format; |
295 base::WaitableEvent done_event(false, false); | 295 base::WaitableEvent done_event( |
| 296 base::WaitableEvent::ResetPolicy::AUTOMATIC, |
| 297 base::WaitableEvent::InitialState::NOT_SIGNALED); |
296 int frame_size; | 298 int frame_size; |
297 | 299 |
298 std::unique_ptr<MockDeviceClient> client(new MockDeviceClient()); | 300 std::unique_ptr<MockDeviceClient> client(new MockDeviceClient()); |
299 EXPECT_CALL(*client, OnError(_, _)).Times(0); | 301 EXPECT_CALL(*client, OnError(_, _)).Times(0); |
300 EXPECT_CALL(*client, OnIncomingCapturedData(_, _, _, _, _, _)) | 302 EXPECT_CALL(*client, OnIncomingCapturedData(_, _, _, _, _, _)) |
301 .WillRepeatedly( | 303 .WillRepeatedly( |
302 DoAll(SaveArg<1>(&frame_size), SaveArg<2>(&format), | 304 DoAll(SaveArg<1>(&frame_size), SaveArg<2>(&format), |
303 InvokeWithoutArgs(&done_event, &base::WaitableEvent::Signal))); | 305 InvokeWithoutArgs(&done_event, &base::WaitableEvent::Signal))); |
304 | 306 |
305 media::VideoCaptureParams capture_params; | 307 media::VideoCaptureParams capture_params; |
(...skipping 15 matching lines...) Expand all Loading... |
321 // Test that screen capturer behaves correctly if the source frame size changes | 323 // Test that screen capturer behaves correctly if the source frame size changes |
322 // but the caller cannot cope with variable resolution output. | 324 // but the caller cannot cope with variable resolution output. |
323 TEST_F(DesktopCaptureDeviceTest, ScreenResolutionChangeConstantResolution) { | 325 TEST_F(DesktopCaptureDeviceTest, ScreenResolutionChangeConstantResolution) { |
324 FakeScreenCapturer* mock_capturer = new FakeScreenCapturer(); | 326 FakeScreenCapturer* mock_capturer = new FakeScreenCapturer(); |
325 | 327 |
326 CreateScreenCaptureDevice( | 328 CreateScreenCaptureDevice( |
327 std::unique_ptr<webrtc::DesktopCapturer>(mock_capturer)); | 329 std::unique_ptr<webrtc::DesktopCapturer>(mock_capturer)); |
328 | 330 |
329 FormatChecker format_checker(gfx::Size(kTestFrameWidth1, kTestFrameHeight1), | 331 FormatChecker format_checker(gfx::Size(kTestFrameWidth1, kTestFrameHeight1), |
330 gfx::Size(kTestFrameWidth1, kTestFrameHeight1)); | 332 gfx::Size(kTestFrameWidth1, kTestFrameHeight1)); |
331 base::WaitableEvent done_event(false, false); | 333 base::WaitableEvent done_event( |
| 334 base::WaitableEvent::ResetPolicy::AUTOMATIC, |
| 335 base::WaitableEvent::InitialState::NOT_SIGNALED); |
332 | 336 |
333 std::unique_ptr<MockDeviceClient> client(new MockDeviceClient()); | 337 std::unique_ptr<MockDeviceClient> client(new MockDeviceClient()); |
334 EXPECT_CALL(*client, OnError(_, _)).Times(0); | 338 EXPECT_CALL(*client, OnError(_, _)).Times(0); |
335 EXPECT_CALL(*client, OnIncomingCapturedData(_, _, _, _, _, _)) | 339 EXPECT_CALL(*client, OnIncomingCapturedData(_, _, _, _, _, _)) |
336 .WillRepeatedly( | 340 .WillRepeatedly( |
337 DoAll(WithArg<2>(Invoke(&format_checker, | 341 DoAll(WithArg<2>(Invoke(&format_checker, |
338 &FormatChecker::ExpectAcceptableSize)), | 342 &FormatChecker::ExpectAcceptableSize)), |
339 InvokeWithoutArgs(&done_event, &base::WaitableEvent::Signal))); | 343 InvokeWithoutArgs(&done_event, &base::WaitableEvent::Signal))); |
340 | 344 |
341 media::VideoCaptureParams capture_params; | 345 media::VideoCaptureParams capture_params; |
(...skipping 21 matching lines...) Expand all Loading... |
363 // Test that screen capturer behaves correctly if the source frame size changes, | 367 // Test that screen capturer behaves correctly if the source frame size changes, |
364 // where the video frames sent the the client vary in resolution but maintain | 368 // where the video frames sent the the client vary in resolution but maintain |
365 // the same aspect ratio. | 369 // the same aspect ratio. |
366 TEST_F(DesktopCaptureDeviceTest, ScreenResolutionChangeFixedAspectRatio) { | 370 TEST_F(DesktopCaptureDeviceTest, ScreenResolutionChangeFixedAspectRatio) { |
367 FakeScreenCapturer* mock_capturer = new FakeScreenCapturer(); | 371 FakeScreenCapturer* mock_capturer = new FakeScreenCapturer(); |
368 | 372 |
369 CreateScreenCaptureDevice( | 373 CreateScreenCaptureDevice( |
370 std::unique_ptr<webrtc::DesktopCapturer>(mock_capturer)); | 374 std::unique_ptr<webrtc::DesktopCapturer>(mock_capturer)); |
371 | 375 |
372 FormatChecker format_checker(gfx::Size(888, 500), gfx::Size(532, 300)); | 376 FormatChecker format_checker(gfx::Size(888, 500), gfx::Size(532, 300)); |
373 base::WaitableEvent done_event(false, false); | 377 base::WaitableEvent done_event( |
| 378 base::WaitableEvent::ResetPolicy::AUTOMATIC, |
| 379 base::WaitableEvent::InitialState::NOT_SIGNALED); |
374 | 380 |
375 std::unique_ptr<MockDeviceClient> client(new MockDeviceClient()); | 381 std::unique_ptr<MockDeviceClient> client(new MockDeviceClient()); |
376 EXPECT_CALL(*client, OnError(_,_)).Times(0); | 382 EXPECT_CALL(*client, OnError(_,_)).Times(0); |
377 EXPECT_CALL(*client, OnIncomingCapturedData(_, _, _, _, _, _)) | 383 EXPECT_CALL(*client, OnIncomingCapturedData(_, _, _, _, _, _)) |
378 .WillRepeatedly( | 384 .WillRepeatedly( |
379 DoAll(WithArg<2>(Invoke(&format_checker, | 385 DoAll(WithArg<2>(Invoke(&format_checker, |
380 &FormatChecker::ExpectAcceptableSize)), | 386 &FormatChecker::ExpectAcceptableSize)), |
381 InvokeWithoutArgs(&done_event, &base::WaitableEvent::Signal))); | 387 InvokeWithoutArgs(&done_event, &base::WaitableEvent::Signal))); |
382 | 388 |
383 media::VideoCaptureParams capture_params; | 389 media::VideoCaptureParams capture_params; |
(...skipping 25 matching lines...) Expand all Loading... |
409 // Test that screen capturer behaves correctly if the source frame size changes | 415 // Test that screen capturer behaves correctly if the source frame size changes |
410 // and the caller can cope with variable resolution output. | 416 // and the caller can cope with variable resolution output. |
411 TEST_F(DesktopCaptureDeviceTest, ScreenResolutionChangeVariableResolution) { | 417 TEST_F(DesktopCaptureDeviceTest, ScreenResolutionChangeVariableResolution) { |
412 FakeScreenCapturer* mock_capturer = new FakeScreenCapturer(); | 418 FakeScreenCapturer* mock_capturer = new FakeScreenCapturer(); |
413 | 419 |
414 CreateScreenCaptureDevice( | 420 CreateScreenCaptureDevice( |
415 std::unique_ptr<webrtc::DesktopCapturer>(mock_capturer)); | 421 std::unique_ptr<webrtc::DesktopCapturer>(mock_capturer)); |
416 | 422 |
417 FormatChecker format_checker(gfx::Size(kTestFrameWidth1, kTestFrameHeight1), | 423 FormatChecker format_checker(gfx::Size(kTestFrameWidth1, kTestFrameHeight1), |
418 gfx::Size(kTestFrameWidth2, kTestFrameHeight2)); | 424 gfx::Size(kTestFrameWidth2, kTestFrameHeight2)); |
419 base::WaitableEvent done_event(false, false); | 425 base::WaitableEvent done_event( |
| 426 base::WaitableEvent::ResetPolicy::AUTOMATIC, |
| 427 base::WaitableEvent::InitialState::NOT_SIGNALED); |
420 | 428 |
421 std::unique_ptr<MockDeviceClient> client(new MockDeviceClient()); | 429 std::unique_ptr<MockDeviceClient> client(new MockDeviceClient()); |
422 EXPECT_CALL(*client, OnError(_,_)).Times(0); | 430 EXPECT_CALL(*client, OnError(_,_)).Times(0); |
423 EXPECT_CALL(*client, OnIncomingCapturedData(_, _, _, _, _, _)) | 431 EXPECT_CALL(*client, OnIncomingCapturedData(_, _, _, _, _, _)) |
424 .WillRepeatedly( | 432 .WillRepeatedly( |
425 DoAll(WithArg<2>(Invoke(&format_checker, | 433 DoAll(WithArg<2>(Invoke(&format_checker, |
426 &FormatChecker::ExpectAcceptableSize)), | 434 &FormatChecker::ExpectAcceptableSize)), |
427 InvokeWithoutArgs(&done_event, &base::WaitableEvent::Signal))); | 435 InvokeWithoutArgs(&done_event, &base::WaitableEvent::Signal))); |
428 | 436 |
429 media::VideoCaptureParams capture_params; | 437 media::VideoCaptureParams capture_params; |
(...skipping 23 matching lines...) Expand all Loading... |
453 } | 461 } |
454 | 462 |
455 // This test verifies that an unpacked frame is converted to a packed frame. | 463 // This test verifies that an unpacked frame is converted to a packed frame. |
456 TEST_F(DesktopCaptureDeviceTest, UnpackedFrame) { | 464 TEST_F(DesktopCaptureDeviceTest, UnpackedFrame) { |
457 FakeScreenCapturer* mock_capturer = new FakeScreenCapturer(); | 465 FakeScreenCapturer* mock_capturer = new FakeScreenCapturer(); |
458 mock_capturer->set_generate_cropped_frames(true); | 466 mock_capturer->set_generate_cropped_frames(true); |
459 CreateScreenCaptureDevice( | 467 CreateScreenCaptureDevice( |
460 std::unique_ptr<webrtc::DesktopCapturer>(mock_capturer)); | 468 std::unique_ptr<webrtc::DesktopCapturer>(mock_capturer)); |
461 | 469 |
462 media::VideoCaptureFormat format; | 470 media::VideoCaptureFormat format; |
463 base::WaitableEvent done_event(false, false); | 471 base::WaitableEvent done_event( |
| 472 base::WaitableEvent::ResetPolicy::AUTOMATIC, |
| 473 base::WaitableEvent::InitialState::NOT_SIGNALED); |
464 | 474 |
465 int frame_size = 0; | 475 int frame_size = 0; |
466 output_frame_.reset(new webrtc::BasicDesktopFrame( | 476 output_frame_.reset(new webrtc::BasicDesktopFrame( |
467 webrtc::DesktopSize(kTestFrameWidth1, kTestFrameHeight1))); | 477 webrtc::DesktopSize(kTestFrameWidth1, kTestFrameHeight1))); |
468 | 478 |
469 std::unique_ptr<MockDeviceClient> client(new MockDeviceClient()); | 479 std::unique_ptr<MockDeviceClient> client(new MockDeviceClient()); |
470 EXPECT_CALL(*client, OnError(_,_)).Times(0); | 480 EXPECT_CALL(*client, OnError(_,_)).Times(0); |
471 EXPECT_CALL(*client, OnIncomingCapturedData(_, _, _, _, _, _)) | 481 EXPECT_CALL(*client, OnIncomingCapturedData(_, _, _, _, _, _)) |
472 .WillRepeatedly( | 482 .WillRepeatedly( |
473 DoAll(Invoke(this, &DesktopCaptureDeviceTest::CopyFrame), | 483 DoAll(Invoke(this, &DesktopCaptureDeviceTest::CopyFrame), |
(...skipping 24 matching lines...) Expand all Loading... |
498 } | 508 } |
499 | 509 |
500 // The test verifies that a bottom-to-top frame is converted to top-to-bottom. | 510 // The test verifies that a bottom-to-top frame is converted to top-to-bottom. |
501 TEST_F(DesktopCaptureDeviceTest, InvertedFrame) { | 511 TEST_F(DesktopCaptureDeviceTest, InvertedFrame) { |
502 FakeScreenCapturer* mock_capturer = new FakeScreenCapturer(); | 512 FakeScreenCapturer* mock_capturer = new FakeScreenCapturer(); |
503 mock_capturer->set_generate_inverted_frames(true); | 513 mock_capturer->set_generate_inverted_frames(true); |
504 CreateScreenCaptureDevice( | 514 CreateScreenCaptureDevice( |
505 std::unique_ptr<webrtc::DesktopCapturer>(mock_capturer)); | 515 std::unique_ptr<webrtc::DesktopCapturer>(mock_capturer)); |
506 | 516 |
507 media::VideoCaptureFormat format; | 517 media::VideoCaptureFormat format; |
508 base::WaitableEvent done_event(false, false); | 518 base::WaitableEvent done_event( |
| 519 base::WaitableEvent::ResetPolicy::AUTOMATIC, |
| 520 base::WaitableEvent::InitialState::NOT_SIGNALED); |
509 | 521 |
510 int frame_size = 0; | 522 int frame_size = 0; |
511 output_frame_.reset(new webrtc::BasicDesktopFrame( | 523 output_frame_.reset(new webrtc::BasicDesktopFrame( |
512 webrtc::DesktopSize(kTestFrameWidth1, kTestFrameHeight1))); | 524 webrtc::DesktopSize(kTestFrameWidth1, kTestFrameHeight1))); |
513 | 525 |
514 std::unique_ptr<MockDeviceClient> client(new MockDeviceClient()); | 526 std::unique_ptr<MockDeviceClient> client(new MockDeviceClient()); |
515 EXPECT_CALL(*client, OnError(_,_)).Times(0); | 527 EXPECT_CALL(*client, OnError(_,_)).Times(0); |
516 EXPECT_CALL(*client, OnIncomingCapturedData(_, _, _, _, _, _)) | 528 EXPECT_CALL(*client, OnIncomingCapturedData(_, _, _, _, _, _)) |
517 .WillRepeatedly( | 529 .WillRepeatedly( |
518 DoAll(Invoke(this, &DesktopCaptureDeviceTest::CopyFrame), | 530 DoAll(Invoke(this, &DesktopCaptureDeviceTest::CopyFrame), |
(...skipping 21 matching lines...) Expand all Loading... |
540 frame_size); | 552 frame_size); |
541 for (int i = 0; i < output_frame_->size().height(); ++i) { | 553 for (int i = 0; i < output_frame_->size().height(); ++i) { |
542 EXPECT_EQ(0, | 554 EXPECT_EQ(0, |
543 memcmp(inverted_frame->data() + i * inverted_frame->stride(), | 555 memcmp(inverted_frame->data() + i * inverted_frame->stride(), |
544 output_frame_->data() + i * output_frame_->stride(), | 556 output_frame_->data() + i * output_frame_->stride(), |
545 output_frame_->stride())); | 557 output_frame_->stride())); |
546 } | 558 } |
547 } | 559 } |
548 | 560 |
549 } // namespace content | 561 } // namespace content |
OLD | NEW |