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 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
68 base::TimeTicks reference_time, | 68 base::TimeTicks reference_time, |
69 base::TimeDelta timestamp, | 69 base::TimeDelta timestamp, |
70 int frame_feedback_id)); | 70 int frame_feedback_id)); |
71 MOCK_METHOD0(DoReserveOutputBuffer, void(void)); | 71 MOCK_METHOD0(DoReserveOutputBuffer, void(void)); |
72 MOCK_METHOD0(DoOnIncomingCapturedBuffer, void(void)); | 72 MOCK_METHOD0(DoOnIncomingCapturedBuffer, void(void)); |
73 MOCK_METHOD0(DoOnIncomingCapturedVideoFrame, void(void)); | 73 MOCK_METHOD0(DoOnIncomingCapturedVideoFrame, void(void)); |
74 MOCK_METHOD0(DoResurrectLastOutputBuffer, void(void)); | 74 MOCK_METHOD0(DoResurrectLastOutputBuffer, void(void)); |
75 MOCK_METHOD2(OnError, | 75 MOCK_METHOD2(OnError, |
76 void(const tracked_objects::Location& from_here, | 76 void(const tracked_objects::Location& from_here, |
77 const std::string& reason)); | 77 const std::string& reason)); |
| 78 MOCK_METHOD0(OnStarted, void(void)); |
78 | 79 |
79 // Trampoline methods to workaround GMOCK problems with std::unique_ptr<>. | 80 // Trampoline methods to workaround GMOCK problems with std::unique_ptr<>. |
80 Buffer ReserveOutputBuffer(const gfx::Size& dimensions, | 81 Buffer ReserveOutputBuffer(const gfx::Size& dimensions, |
81 media::VideoPixelFormat format, | 82 media::VideoPixelFormat format, |
82 media::VideoPixelStorage storage, | 83 media::VideoPixelStorage storage, |
83 int frame_feedback_id) override { | 84 int frame_feedback_id) override { |
84 EXPECT_TRUE(format == media::PIXEL_FORMAT_I420 && | 85 EXPECT_TRUE(format == media::PIXEL_FORMAT_I420 && |
85 storage == media::PIXEL_STORAGE_CPU); | 86 storage == media::PIXEL_STORAGE_CPU); |
86 DoReserveOutputBuffer(); | 87 DoReserveOutputBuffer(); |
87 return Buffer(); | 88 return Buffer(); |
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
296 CreateScreenCaptureDevice(std::move(capturer)); | 297 CreateScreenCaptureDevice(std::move(capturer)); |
297 | 298 |
298 media::VideoCaptureFormat format; | 299 media::VideoCaptureFormat format; |
299 base::WaitableEvent done_event( | 300 base::WaitableEvent done_event( |
300 base::WaitableEvent::ResetPolicy::AUTOMATIC, | 301 base::WaitableEvent::ResetPolicy::AUTOMATIC, |
301 base::WaitableEvent::InitialState::NOT_SIGNALED); | 302 base::WaitableEvent::InitialState::NOT_SIGNALED); |
302 int frame_size; | 303 int frame_size; |
303 | 304 |
304 std::unique_ptr<MockDeviceClient> client(new MockDeviceClient()); | 305 std::unique_ptr<MockDeviceClient> client(new MockDeviceClient()); |
305 EXPECT_CALL(*client, OnError(_, _)).Times(0); | 306 EXPECT_CALL(*client, OnError(_, _)).Times(0); |
| 307 EXPECT_CALL(*client, OnStarted()); |
306 EXPECT_CALL(*client, OnIncomingCapturedData(_, _, _, _, _, _, _)) | 308 EXPECT_CALL(*client, OnIncomingCapturedData(_, _, _, _, _, _, _)) |
307 .WillRepeatedly( | 309 .WillRepeatedly( |
308 DoAll(SaveArg<1>(&frame_size), SaveArg<2>(&format), | 310 DoAll(SaveArg<1>(&frame_size), SaveArg<2>(&format), |
309 InvokeWithoutArgs(&done_event, &base::WaitableEvent::Signal))); | 311 InvokeWithoutArgs(&done_event, &base::WaitableEvent::Signal))); |
310 | 312 |
311 media::VideoCaptureParams capture_params; | 313 media::VideoCaptureParams capture_params; |
312 capture_params.requested_format.frame_size.SetSize(640, 480); | 314 capture_params.requested_format.frame_size.SetSize(640, 480); |
313 capture_params.requested_format.frame_rate = kFrameRate; | 315 capture_params.requested_format.frame_rate = kFrameRate; |
314 capture_params.requested_format.pixel_format = media::PIXEL_FORMAT_I420; | 316 capture_params.requested_format.pixel_format = media::PIXEL_FORMAT_I420; |
315 capture_device_->AllocateAndStart(capture_params, std::move(client)); | 317 capture_device_->AllocateAndStart(capture_params, std::move(client)); |
(...skipping 17 matching lines...) Expand all Loading... |
333 std::unique_ptr<webrtc::DesktopCapturer>(mock_capturer)); | 335 std::unique_ptr<webrtc::DesktopCapturer>(mock_capturer)); |
334 | 336 |
335 FormatChecker format_checker(gfx::Size(kTestFrameWidth1, kTestFrameHeight1), | 337 FormatChecker format_checker(gfx::Size(kTestFrameWidth1, kTestFrameHeight1), |
336 gfx::Size(kTestFrameWidth1, kTestFrameHeight1)); | 338 gfx::Size(kTestFrameWidth1, kTestFrameHeight1)); |
337 base::WaitableEvent done_event( | 339 base::WaitableEvent done_event( |
338 base::WaitableEvent::ResetPolicy::AUTOMATIC, | 340 base::WaitableEvent::ResetPolicy::AUTOMATIC, |
339 base::WaitableEvent::InitialState::NOT_SIGNALED); | 341 base::WaitableEvent::InitialState::NOT_SIGNALED); |
340 | 342 |
341 std::unique_ptr<MockDeviceClient> client(new MockDeviceClient()); | 343 std::unique_ptr<MockDeviceClient> client(new MockDeviceClient()); |
342 EXPECT_CALL(*client, OnError(_, _)).Times(0); | 344 EXPECT_CALL(*client, OnError(_, _)).Times(0); |
| 345 EXPECT_CALL(*client, OnStarted()); |
343 EXPECT_CALL(*client, OnIncomingCapturedData(_, _, _, _, _, _, _)) | 346 EXPECT_CALL(*client, OnIncomingCapturedData(_, _, _, _, _, _, _)) |
344 .WillRepeatedly( | 347 .WillRepeatedly( |
345 DoAll(WithArg<2>(Invoke(&format_checker, | 348 DoAll(WithArg<2>(Invoke(&format_checker, |
346 &FormatChecker::ExpectAcceptableSize)), | 349 &FormatChecker::ExpectAcceptableSize)), |
347 InvokeWithoutArgs(&done_event, &base::WaitableEvent::Signal))); | 350 InvokeWithoutArgs(&done_event, &base::WaitableEvent::Signal))); |
348 | 351 |
349 media::VideoCaptureParams capture_params; | 352 media::VideoCaptureParams capture_params; |
350 capture_params.requested_format.frame_size.SetSize(kTestFrameWidth1, | 353 capture_params.requested_format.frame_size.SetSize(kTestFrameWidth1, |
351 kTestFrameHeight1); | 354 kTestFrameHeight1); |
352 capture_params.requested_format.frame_rate = kFrameRate; | 355 capture_params.requested_format.frame_rate = kFrameRate; |
(...skipping 24 matching lines...) Expand all Loading... |
377 CreateScreenCaptureDevice( | 380 CreateScreenCaptureDevice( |
378 std::unique_ptr<webrtc::DesktopCapturer>(mock_capturer)); | 381 std::unique_ptr<webrtc::DesktopCapturer>(mock_capturer)); |
379 | 382 |
380 FormatChecker format_checker(gfx::Size(888, 500), gfx::Size(532, 300)); | 383 FormatChecker format_checker(gfx::Size(888, 500), gfx::Size(532, 300)); |
381 base::WaitableEvent done_event( | 384 base::WaitableEvent done_event( |
382 base::WaitableEvent::ResetPolicy::AUTOMATIC, | 385 base::WaitableEvent::ResetPolicy::AUTOMATIC, |
383 base::WaitableEvent::InitialState::NOT_SIGNALED); | 386 base::WaitableEvent::InitialState::NOT_SIGNALED); |
384 | 387 |
385 std::unique_ptr<MockDeviceClient> client(new MockDeviceClient()); | 388 std::unique_ptr<MockDeviceClient> client(new MockDeviceClient()); |
386 EXPECT_CALL(*client, OnError(_,_)).Times(0); | 389 EXPECT_CALL(*client, OnError(_,_)).Times(0); |
| 390 EXPECT_CALL(*client, OnStarted()); |
387 EXPECT_CALL(*client, OnIncomingCapturedData(_, _, _, _, _, _, _)) | 391 EXPECT_CALL(*client, OnIncomingCapturedData(_, _, _, _, _, _, _)) |
388 .WillRepeatedly( | 392 .WillRepeatedly( |
389 DoAll(WithArg<2>(Invoke(&format_checker, | 393 DoAll(WithArg<2>(Invoke(&format_checker, |
390 &FormatChecker::ExpectAcceptableSize)), | 394 &FormatChecker::ExpectAcceptableSize)), |
391 InvokeWithoutArgs(&done_event, &base::WaitableEvent::Signal))); | 395 InvokeWithoutArgs(&done_event, &base::WaitableEvent::Signal))); |
392 | 396 |
393 media::VideoCaptureParams capture_params; | 397 media::VideoCaptureParams capture_params; |
394 const gfx::Size high_def_16_by_9(1920, 1080); | 398 const gfx::Size high_def_16_by_9(1920, 1080); |
395 ASSERT_GE(high_def_16_by_9.width(), | 399 ASSERT_GE(high_def_16_by_9.width(), |
396 std::max(kTestFrameWidth1, kTestFrameWidth2)); | 400 std::max(kTestFrameWidth1, kTestFrameWidth2)); |
(...skipping 28 matching lines...) Expand all Loading... |
425 std::unique_ptr<webrtc::DesktopCapturer>(mock_capturer)); | 429 std::unique_ptr<webrtc::DesktopCapturer>(mock_capturer)); |
426 | 430 |
427 FormatChecker format_checker(gfx::Size(kTestFrameWidth1, kTestFrameHeight1), | 431 FormatChecker format_checker(gfx::Size(kTestFrameWidth1, kTestFrameHeight1), |
428 gfx::Size(kTestFrameWidth2, kTestFrameHeight2)); | 432 gfx::Size(kTestFrameWidth2, kTestFrameHeight2)); |
429 base::WaitableEvent done_event( | 433 base::WaitableEvent done_event( |
430 base::WaitableEvent::ResetPolicy::AUTOMATIC, | 434 base::WaitableEvent::ResetPolicy::AUTOMATIC, |
431 base::WaitableEvent::InitialState::NOT_SIGNALED); | 435 base::WaitableEvent::InitialState::NOT_SIGNALED); |
432 | 436 |
433 std::unique_ptr<MockDeviceClient> client(new MockDeviceClient()); | 437 std::unique_ptr<MockDeviceClient> client(new MockDeviceClient()); |
434 EXPECT_CALL(*client, OnError(_,_)).Times(0); | 438 EXPECT_CALL(*client, OnError(_,_)).Times(0); |
| 439 EXPECT_CALL(*client, OnStarted()); |
435 EXPECT_CALL(*client, OnIncomingCapturedData(_, _, _, _, _, _, _)) | 440 EXPECT_CALL(*client, OnIncomingCapturedData(_, _, _, _, _, _, _)) |
436 .WillRepeatedly( | 441 .WillRepeatedly( |
437 DoAll(WithArg<2>(Invoke(&format_checker, | 442 DoAll(WithArg<2>(Invoke(&format_checker, |
438 &FormatChecker::ExpectAcceptableSize)), | 443 &FormatChecker::ExpectAcceptableSize)), |
439 InvokeWithoutArgs(&done_event, &base::WaitableEvent::Signal))); | 444 InvokeWithoutArgs(&done_event, &base::WaitableEvent::Signal))); |
440 | 445 |
441 media::VideoCaptureParams capture_params; | 446 media::VideoCaptureParams capture_params; |
442 const gfx::Size high_def_16_by_9(1920, 1080); | 447 const gfx::Size high_def_16_by_9(1920, 1080); |
443 ASSERT_GE(high_def_16_by_9.width(), | 448 ASSERT_GE(high_def_16_by_9.width(), |
444 std::max(kTestFrameWidth1, kTestFrameWidth2)); | 449 std::max(kTestFrameWidth1, kTestFrameWidth2)); |
(...skipping 30 matching lines...) Expand all Loading... |
475 base::WaitableEvent done_event( | 480 base::WaitableEvent done_event( |
476 base::WaitableEvent::ResetPolicy::AUTOMATIC, | 481 base::WaitableEvent::ResetPolicy::AUTOMATIC, |
477 base::WaitableEvent::InitialState::NOT_SIGNALED); | 482 base::WaitableEvent::InitialState::NOT_SIGNALED); |
478 | 483 |
479 int frame_size = 0; | 484 int frame_size = 0; |
480 output_frame_.reset(new webrtc::BasicDesktopFrame( | 485 output_frame_.reset(new webrtc::BasicDesktopFrame( |
481 webrtc::DesktopSize(kTestFrameWidth1, kTestFrameHeight1))); | 486 webrtc::DesktopSize(kTestFrameWidth1, kTestFrameHeight1))); |
482 | 487 |
483 std::unique_ptr<MockDeviceClient> client(new MockDeviceClient()); | 488 std::unique_ptr<MockDeviceClient> client(new MockDeviceClient()); |
484 EXPECT_CALL(*client, OnError(_,_)).Times(0); | 489 EXPECT_CALL(*client, OnError(_,_)).Times(0); |
| 490 EXPECT_CALL(*client, OnStarted()); |
485 EXPECT_CALL(*client, OnIncomingCapturedData(_, _, _, _, _, _, _)) | 491 EXPECT_CALL(*client, OnIncomingCapturedData(_, _, _, _, _, _, _)) |
486 .WillRepeatedly( | 492 .WillRepeatedly( |
487 DoAll(Invoke(this, &DesktopCaptureDeviceTest::CopyFrame), | 493 DoAll(Invoke(this, &DesktopCaptureDeviceTest::CopyFrame), |
488 SaveArg<1>(&frame_size), | 494 SaveArg<1>(&frame_size), |
489 InvokeWithoutArgs(&done_event, &base::WaitableEvent::Signal))); | 495 InvokeWithoutArgs(&done_event, &base::WaitableEvent::Signal))); |
490 | 496 |
491 media::VideoCaptureParams capture_params; | 497 media::VideoCaptureParams capture_params; |
492 capture_params.requested_format.frame_size.SetSize(kTestFrameWidth1, | 498 capture_params.requested_format.frame_size.SetSize(kTestFrameWidth1, |
493 kTestFrameHeight1); | 499 kTestFrameHeight1); |
494 capture_params.requested_format.frame_rate = kFrameRate; | 500 capture_params.requested_format.frame_rate = kFrameRate; |
(...skipping 27 matching lines...) Expand all Loading... |
522 base::WaitableEvent done_event( | 528 base::WaitableEvent done_event( |
523 base::WaitableEvent::ResetPolicy::AUTOMATIC, | 529 base::WaitableEvent::ResetPolicy::AUTOMATIC, |
524 base::WaitableEvent::InitialState::NOT_SIGNALED); | 530 base::WaitableEvent::InitialState::NOT_SIGNALED); |
525 | 531 |
526 int frame_size = 0; | 532 int frame_size = 0; |
527 output_frame_.reset(new webrtc::BasicDesktopFrame( | 533 output_frame_.reset(new webrtc::BasicDesktopFrame( |
528 webrtc::DesktopSize(kTestFrameWidth1, kTestFrameHeight1))); | 534 webrtc::DesktopSize(kTestFrameWidth1, kTestFrameHeight1))); |
529 | 535 |
530 std::unique_ptr<MockDeviceClient> client(new MockDeviceClient()); | 536 std::unique_ptr<MockDeviceClient> client(new MockDeviceClient()); |
531 EXPECT_CALL(*client, OnError(_,_)).Times(0); | 537 EXPECT_CALL(*client, OnError(_,_)).Times(0); |
| 538 EXPECT_CALL(*client, OnStarted()); |
532 EXPECT_CALL(*client, OnIncomingCapturedData(_, _, _, _, _, _, _)) | 539 EXPECT_CALL(*client, OnIncomingCapturedData(_, _, _, _, _, _, _)) |
533 .WillRepeatedly( | 540 .WillRepeatedly( |
534 DoAll(Invoke(this, &DesktopCaptureDeviceTest::CopyFrame), | 541 DoAll(Invoke(this, &DesktopCaptureDeviceTest::CopyFrame), |
535 SaveArg<1>(&frame_size), | 542 SaveArg<1>(&frame_size), |
536 InvokeWithoutArgs(&done_event, &base::WaitableEvent::Signal))); | 543 InvokeWithoutArgs(&done_event, &base::WaitableEvent::Signal))); |
537 | 544 |
538 media::VideoCaptureParams capture_params; | 545 media::VideoCaptureParams capture_params; |
539 capture_params.requested_format.frame_size.SetSize(kTestFrameWidth1, | 546 capture_params.requested_format.frame_size.SetSize(kTestFrameWidth1, |
540 kTestFrameHeight1); | 547 kTestFrameHeight1); |
541 capture_params.requested_format.frame_rate = kFrameRate; | 548 capture_params.requested_format.frame_rate = kFrameRate; |
(...skipping 14 matching lines...) Expand all Loading... |
556 frame_size); | 563 frame_size); |
557 for (int i = 0; i < output_frame_->size().height(); ++i) { | 564 for (int i = 0; i < output_frame_->size().height(); ++i) { |
558 EXPECT_EQ(0, | 565 EXPECT_EQ(0, |
559 memcmp(inverted_frame->data() + i * inverted_frame->stride(), | 566 memcmp(inverted_frame->data() + i * inverted_frame->stride(), |
560 output_frame_->data() + i * output_frame_->stride(), | 567 output_frame_->data() + i * output_frame_->stride(), |
561 output_frame_->stride())); | 568 output_frame_->stride())); |
562 } | 569 } |
563 } | 570 } |
564 | 571 |
565 } // namespace content | 572 } // namespace content |
OLD | NEW |