OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/renderer_host/media/video_capture_host.h" | 5 #include "content/browser/renderer_host/media/video_capture_host.h" |
6 | 6 |
7 #include <stdint.h> | 7 #include <stdint.h> |
8 | 8 |
9 #include <map> | 9 #include <map> |
10 #include <memory> | 10 #include <memory> |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
60 // Id used to identify the capture session between renderer and | 60 // Id used to identify the capture session between renderer and |
61 // video_capture_host. This is an arbitrary value. | 61 // video_capture_host. This is an arbitrary value. |
62 static const int kDeviceId = 555; | 62 static const int kDeviceId = 555; |
63 | 63 |
64 // Define to enable test where video is dumped to file. | 64 // Define to enable test where video is dumped to file. |
65 // #define DUMP_VIDEO | 65 // #define DUMP_VIDEO |
66 | 66 |
67 // Define to use a real video capture device. | 67 // Define to use a real video capture device. |
68 // #define TEST_REAL_CAPTURE_DEVICE | 68 // #define TEST_REAL_CAPTURE_DEVICE |
69 | 69 |
70 // Simple class used for dumping video to a file. This can be used for | 70 // Simple class used for dumping video to a file. This can be used for verifying |
71 // verifying the output. | 71 // the output. |
72 class DumpVideo { | 72 class DumpVideo { |
73 public: | 73 public: |
74 DumpVideo() {} | 74 DumpVideo() {} |
75 const gfx::Size& coded_size() const { return coded_size_; } | 75 const gfx::Size& coded_size() const { return coded_size_; } |
76 void StartDump(const gfx::Size& coded_size) { | 76 void StartDump(const gfx::Size& coded_size) { |
77 base::FilePath file_name = base::FilePath(base::StringPrintf( | 77 base::FilePath file_name = base::FilePath(base::StringPrintf( |
78 FILE_PATH_LITERAL("dump_w%d_h%d.yuv"), | 78 FILE_PATH_LITERAL("dump_w%d_h%d.yuv"), |
79 coded_size.width(), | 79 coded_size.width(), |
80 coded_size.height())); | 80 coded_size.height())); |
81 file_.reset(base::OpenFile(file_name, "wb")); | 81 file_.reset(base::OpenFile(file_name, "wb")); |
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
284 host_ = new MockVideoCaptureHost(media_stream_manager_.get()); | 284 host_ = new MockVideoCaptureHost(media_stream_manager_.get()); |
285 host_->OnChannelConnected(base::GetCurrentProcId()); | 285 host_->OnChannelConnected(base::GetCurrentProcId()); |
286 | 286 |
287 OpenSession(); | 287 OpenSession(); |
288 } | 288 } |
289 | 289 |
290 void TearDown() override { | 290 void TearDown() override { |
291 // Verifies and removes the expectations on host_ and | 291 // Verifies and removes the expectations on host_ and |
292 // returns true iff successful. | 292 // returns true iff successful. |
293 Mock::VerifyAndClearExpectations(host_.get()); | 293 Mock::VerifyAndClearExpectations(host_.get()); |
294 EXPECT_EQ(0u, host_->entries_.size()); | 294 EXPECT_TRUE(host_->controllers_.empty()); |
295 | 295 |
296 CloseSession(); | 296 CloseSession(); |
297 | 297 |
298 // Simulate closing the IPC sender. | 298 // Simulate closing the IPC sender. |
299 host_->OnChannelClosing(); | 299 host_->OnChannelClosing(); |
300 | 300 |
301 // Release the reference to the mock object. The object will be destructed | 301 // Release the reference to the mock object. The object will be destructed |
302 // on the current message loop. | 302 // on the current message loop. |
303 host_ = NULL; | 303 host_ = NULL; |
304 | 304 |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
395 // Quickly start and then stop capture, without giving much chance for | 395 // Quickly start and then stop capture, without giving much chance for |
396 // asynchronous start operations to complete. | 396 // asynchronous start operations to complete. |
397 InSequence s; | 397 InSequence s; |
398 base::RunLoop run_loop; | 398 base::RunLoop run_loop; |
399 EXPECT_CALL(*host_.get(), | 399 EXPECT_CALL(*host_.get(), |
400 OnStateChanged(kDeviceId, VIDEO_CAPTURE_STATE_STOPPED)); | 400 OnStateChanged(kDeviceId, VIDEO_CAPTURE_STATE_STOPPED)); |
401 media::VideoCaptureParams params; | 401 media::VideoCaptureParams params; |
402 params.requested_format = media::VideoCaptureFormat( | 402 params.requested_format = media::VideoCaptureFormat( |
403 gfx::Size(352, 288), 30, media::PIXEL_FORMAT_I420); | 403 gfx::Size(352, 288), 30, media::PIXEL_FORMAT_I420); |
404 host_->OnStartCapture(kDeviceId, opened_session_id_, params); | 404 host_->OnStartCapture(kDeviceId, opened_session_id_, params); |
405 host_->OnStopCapture(kDeviceId); | 405 host_->StopCapture(kDeviceId); |
406 run_loop.RunUntilIdle(); | 406 run_loop.RunUntilIdle(); |
407 WaitForVideoDeviceThread(); | 407 WaitForVideoDeviceThread(); |
408 } | 408 } |
409 | 409 |
410 #ifdef DUMP_VIDEO | 410 #ifdef DUMP_VIDEO |
411 void CaptureAndDumpVideo(int width, int height, int frame_rate) { | 411 void CaptureAndDumpVideo(int width, int height, int frame_rate) { |
412 InSequence s; | 412 InSequence s; |
413 EXPECT_CALL(*host_.get(), OnNewBufferCreated(kDeviceId, _, _, _)) | 413 EXPECT_CALL(*host_.get(), OnNewBufferCreated(kDeviceId, _, _, _)) |
414 .Times(AnyNumber()).WillRepeatedly(Return()); | 414 .Times(AnyNumber()).WillRepeatedly(Return()); |
415 | 415 |
(...skipping 10 matching lines...) Expand all Loading... |
426 run_loop.Run(); | 426 run_loop.Run(); |
427 } | 427 } |
428 #endif | 428 #endif |
429 | 429 |
430 void StopCapture() { | 430 void StopCapture() { |
431 base::RunLoop run_loop; | 431 base::RunLoop run_loop; |
432 EXPECT_CALL(*host_.get(), | 432 EXPECT_CALL(*host_.get(), |
433 OnStateChanged(kDeviceId, VIDEO_CAPTURE_STATE_STOPPED)) | 433 OnStateChanged(kDeviceId, VIDEO_CAPTURE_STATE_STOPPED)) |
434 .WillOnce(ExitMessageLoop(task_runner_, run_loop.QuitClosure())); | 434 .WillOnce(ExitMessageLoop(task_runner_, run_loop.QuitClosure())); |
435 | 435 |
436 host_->OnStopCapture(kDeviceId); | 436 host_->StopCapture(kDeviceId); |
437 host_->SetReturnReceivedDibs(true); | 437 host_->SetReturnReceivedDibs(true); |
438 host_->ReturnReceivedDibs(kDeviceId); | 438 host_->ReturnReceivedDibs(kDeviceId); |
439 | 439 |
440 run_loop.Run(); | 440 run_loop.Run(); |
441 | 441 |
442 host_->SetReturnReceivedDibs(false); | 442 host_->SetReturnReceivedDibs(false); |
443 // Expect the VideoCaptureDevice has been stopped | 443 // Expect the VideoCaptureDevice has been stopped |
444 EXPECT_EQ(0u, host_->entries_.size()); | 444 EXPECT_TRUE(host_->controllers_.empty()); |
445 } | 445 } |
446 | 446 |
447 void NotifyPacketReady() { | 447 void NotifyPacketReady() { |
448 base::RunLoop run_loop; | 448 base::RunLoop run_loop; |
449 EXPECT_CALL(*host_.get(), OnBufferFilled(kDeviceId)) | 449 EXPECT_CALL(*host_.get(), OnBufferFilled(kDeviceId)) |
450 .Times(AnyNumber()) | 450 .Times(AnyNumber()) |
451 .WillOnce(ExitMessageLoop(task_runner_, run_loop.QuitClosure())) | 451 .WillOnce(ExitMessageLoop(task_runner_, run_loop.QuitClosure())) |
452 .RetiresOnSaturation(); | 452 .RetiresOnSaturation(); |
453 run_loop.Run(); | 453 run_loop.Run(); |
454 } | 454 } |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
537 #ifdef DUMP_VIDEO | 537 #ifdef DUMP_VIDEO |
538 TEST_F(VideoCaptureHostTest, CaptureAndDumpVideoVga) { | 538 TEST_F(VideoCaptureHostTest, CaptureAndDumpVideoVga) { |
539 CaptureAndDumpVideo(640, 480, 30); | 539 CaptureAndDumpVideo(640, 480, 30); |
540 } | 540 } |
541 TEST_F(VideoCaptureHostTest, CaptureAndDump720P) { | 541 TEST_F(VideoCaptureHostTest, CaptureAndDump720P) { |
542 CaptureAndDumpVideo(1280, 720, 30); | 542 CaptureAndDumpVideo(1280, 720, 30); |
543 } | 543 } |
544 #endif | 544 #endif |
545 | 545 |
546 } // namespace content | 546 } // namespace content |
OLD | NEW |