Chromium Code Reviews| 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 // Unit test for VideoCaptureController. | 5 // Unit test for VideoCaptureController. |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
| 11 #include "base/memory/ref_counted.h" | 11 #include "base/memory/ref_counted.h" |
| 12 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
| 13 #include "base/message_loop/message_loop.h" | 13 #include "base/message_loop/message_loop.h" |
| 14 #include "base/run_loop.h" | 14 #include "base/run_loop.h" |
| 15 #include "content/browser/renderer_host/media/media_stream_provider.h" | 15 #include "content/browser/renderer_host/media/media_stream_provider.h" |
| 16 #include "content/browser/renderer_host/media/video_capture_controller.h" | 16 #include "content/browser/renderer_host/media/video_capture_controller.h" |
| 17 #include "content/browser/renderer_host/media/video_capture_controller_event_han dler.h" | 17 #include "content/browser/renderer_host/media/video_capture_controller_event_han dler.h" |
| 18 #include "content/browser/renderer_host/media/video_capture_manager.h" | 18 #include "content/browser/renderer_host/media/video_capture_manager.h" |
| 19 #include "content/common/gpu/client/gl_helper.h" | |
| 19 #include "content/common/media/media_stream_options.h" | 20 #include "content/common/media/media_stream_options.h" |
| 20 #include "content/public/test/test_browser_thread_bundle.h" | 21 #include "content/public/test/test_browser_thread_bundle.h" |
| 21 #include "gpu/command_buffer/common/mailbox_holder.h" | 22 #include "gpu/command_buffer/common/mailbox_holder.h" |
| 22 #include "media/base/video_util.h" | 23 #include "media/base/video_util.h" |
| 23 #include "media/video/capture/video_capture_types.h" | 24 #include "media/video/capture/video_capture_types.h" |
| 24 #include "testing/gmock/include/gmock/gmock.h" | 25 #include "testing/gmock/include/gmock/gmock.h" |
| 25 #include "testing/gtest/include/gtest/gtest.h" | 26 #include "testing/gtest/include/gtest/gtest.h" |
| 26 | 27 |
| 28 #if defined(OS_ANDROID) | |
| 29 #include "content/browser/renderer_host/image_transport_factory_android.h" | |
| 30 #include "content/browser/renderer_host/no_image_transport_factory_android.h" | |
| 31 #else | |
| 32 #include "content/browser/compositor/image_transport_factory.h" | |
| 33 #include "ui/compositor/test/in_process_context_factory.h" | |
| 34 #endif | |
| 35 | |
| 27 using ::testing::InSequence; | 36 using ::testing::InSequence; |
| 28 using ::testing::Mock; | 37 using ::testing::Mock; |
| 29 | 38 |
| 30 namespace content { | 39 namespace content { |
| 31 | 40 |
| 32 class MockVideoCaptureControllerEventHandler | 41 class MockVideoCaptureControllerEventHandler |
| 33 : public VideoCaptureControllerEventHandler { | 42 : public VideoCaptureControllerEventHandler { |
| 34 public: | 43 public: |
| 35 explicit MockVideoCaptureControllerEventHandler( | 44 explicit MockVideoCaptureControllerEventHandler( |
| 36 VideoCaptureController* controller) | 45 VideoCaptureController* controller) |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 63 const media::VideoCaptureFormat& format, | 72 const media::VideoCaptureFormat& format, |
| 64 base::TimeTicks timestamp) OVERRIDE { | 73 base::TimeTicks timestamp) OVERRIDE { |
| 65 DoBufferReady(id); | 74 DoBufferReady(id); |
| 66 base::MessageLoop::current()->PostTask( | 75 base::MessageLoop::current()->PostTask( |
| 67 FROM_HERE, | 76 FROM_HERE, |
| 68 base::Bind(&VideoCaptureController::ReturnBuffer, | 77 base::Bind(&VideoCaptureController::ReturnBuffer, |
| 69 base::Unretained(controller_), | 78 base::Unretained(controller_), |
| 70 id, | 79 id, |
| 71 this, | 80 this, |
| 72 buffer_id, | 81 buffer_id, |
| 73 std::vector<uint32>())); | 82 0)); |
| 74 } | 83 } |
| 75 virtual void OnMailboxBufferReady(const VideoCaptureControllerID& id, | 84 virtual void OnMailboxBufferReady(const VideoCaptureControllerID& id, |
| 76 int buffer_id, | 85 int buffer_id, |
| 77 const gpu::MailboxHolder& mailbox_holder, | 86 const gpu::MailboxHolder& mailbox_holder, |
| 78 const media::VideoCaptureFormat& format, | 87 const media::VideoCaptureFormat& format, |
| 79 base::TimeTicks timestamp) OVERRIDE { | 88 base::TimeTicks timestamp) OVERRIDE { |
| 80 DoMailboxBufferReady(id); | 89 DoMailboxBufferReady(id); |
| 81 // Use a very different syncpoint value when returning a new syncpoint. | |
| 82 std::vector<uint32> release_sync_points; | |
| 83 release_sync_points.push_back(~mailbox_holder.sync_point); | |
| 84 base::MessageLoop::current()->PostTask( | 90 base::MessageLoop::current()->PostTask( |
| 85 FROM_HERE, | 91 FROM_HERE, |
| 86 base::Bind(&VideoCaptureController::ReturnBuffer, | 92 base::Bind(&VideoCaptureController::ReturnBuffer, |
| 87 base::Unretained(controller_), | 93 base::Unretained(controller_), |
| 88 id, | 94 id, |
| 89 this, | 95 this, |
| 90 buffer_id, | 96 buffer_id, |
| 91 release_sync_points)); | 97 mailbox_holder.sync_point)); |
| 92 } | 98 } |
| 93 virtual void OnEnded(const VideoCaptureControllerID& id) OVERRIDE { | 99 virtual void OnEnded(const VideoCaptureControllerID& id) OVERRIDE { |
| 94 DoEnded(id); | 100 DoEnded(id); |
| 95 // OnEnded() must respond by (eventually) unregistering the client. | 101 // OnEnded() must respond by (eventually) unregistering the client. |
| 96 base::MessageLoop::current()->PostTask(FROM_HERE, | 102 base::MessageLoop::current()->PostTask(FROM_HERE, |
| 97 base::Bind(base::IgnoreResult(&VideoCaptureController::RemoveClient), | 103 base::Bind(base::IgnoreResult(&VideoCaptureController::RemoveClient), |
| 98 base::Unretained(controller_), id, this)); | 104 base::Unretained(controller_), id, this)); |
| 99 } | 105 } |
| 100 | 106 |
| 101 VideoCaptureController* controller_; | 107 VideoCaptureController* controller_; |
| (...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 256 ASSERT_EQ(1, controller_->GetClientCount()) | 262 ASSERT_EQ(1, controller_->GetClientCount()) |
| 257 << "Removing non-existant session 200 should be a no-op."; | 263 << "Removing non-existant session 200 should be a no-op."; |
| 258 ASSERT_EQ(400, | 264 ASSERT_EQ(400, |
| 259 controller_->RemoveClient(client_b_route_2, client_b_.get())) | 265 controller_->RemoveClient(client_b_route_2, client_b_.get())) |
| 260 << "Removing client B/2 should return its session_id."; | 266 << "Removing client B/2 should return its session_id."; |
| 261 // Clients in controller: [] | 267 // Clients in controller: [] |
| 262 ASSERT_EQ(0, controller_->GetClientCount()) | 268 ASSERT_EQ(0, controller_->GetClientCount()) |
| 263 << "Client count should return to zero after all clients are gone."; | 269 << "Client count should return to zero after all clients are gone."; |
| 264 } | 270 } |
| 265 | 271 |
| 266 static void CacheSyncPoint(std::vector<uint32>* called_release_sync_points, | 272 static void CacheSyncPoint(uint32* called_release_sync_point, |
| 267 const std::vector<uint32>& release_sync_points) { | 273 uint32 release_sync_point) { |
| 268 DCHECK(called_release_sync_points->empty()); | 274 *called_release_sync_point = release_sync_point; |
| 269 called_release_sync_points->assign(release_sync_points.begin(), | |
| 270 release_sync_points.end()); | |
| 271 } | 275 } |
| 272 | 276 |
| 273 // This test will connect and disconnect several clients while simulating an | 277 // This test will connect and disconnect several clients while simulating an |
| 274 // active capture device being started and generating frames. It runs on one | 278 // active capture device being started and generating frames. It runs on one |
| 275 // thread and is intended to behave deterministically. | 279 // thread and is intended to behave deterministically. |
| 276 TEST_F(VideoCaptureControllerTest, NormalCaptureMultipleClients) { | 280 TEST_F(VideoCaptureControllerTest, NormalCaptureMultipleClients) { |
| 281 // VideoCaptureController::ReturnBuffer() uses ImageTransportFactory. | |
| 282 #if defined(OS_ANDROID) | |
| 283 ImageTransportFactoryAndroid::InitializeForUnitTests( | |
| 284 new NoImageTransportFactoryAndroid); | |
| 285 #else | |
| 286 ImageTransportFactory::InitializeForUnitTests( | |
| 287 scoped_ptr<ui::ContextFactory>(new ui::InProcessContextFactory)); | |
| 288 #endif | |
| 289 | |
| 277 media::VideoCaptureParams session_100; | 290 media::VideoCaptureParams session_100; |
| 278 session_100.requested_format = media::VideoCaptureFormat( | 291 session_100.requested_format = media::VideoCaptureFormat( |
| 279 gfx::Size(320, 240), 30, media::PIXEL_FORMAT_I420); | 292 gfx::Size(320, 240), 30, media::PIXEL_FORMAT_I420); |
| 280 | 293 |
| 281 media::VideoCaptureParams session_200 = session_100; | 294 media::VideoCaptureParams session_200 = session_100; |
| 282 | 295 |
| 283 media::VideoCaptureParams session_300 = session_100; | 296 media::VideoCaptureParams session_300 = session_100; |
| 284 | 297 |
| 285 media::VideoCaptureParams session_1 = session_100; | 298 media::VideoCaptureParams session_1 = session_100; |
| 286 | 299 |
| (...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 477 device_->OnIncomingCapturedVideoFrame( | 490 device_->OnIncomingCapturedVideoFrame( |
| 478 buffer, | 491 buffer, |
| 479 media::VideoCaptureFormat(capture_resolution, | 492 media::VideoCaptureFormat(capture_resolution, |
| 480 device_format.frame_rate, | 493 device_format.frame_rate, |
| 481 media::PIXEL_FORMAT_I420), | 494 media::PIXEL_FORMAT_I420), |
| 482 WrapI420Buffer(buffer, capture_resolution), | 495 WrapI420Buffer(buffer, capture_resolution), |
| 483 base::TimeTicks()); | 496 base::TimeTicks()); |
| 484 buffer = NULL; | 497 buffer = NULL; |
| 485 } | 498 } |
| 486 std::vector<uint32> mailbox_syncpoints(mailbox_buffers); | 499 std::vector<uint32> mailbox_syncpoints(mailbox_buffers); |
| 487 std::vector<std::vector<uint32> > release_syncpoint_vectors(mailbox_buffers); | 500 std::vector<uint32> release_syncpoint_vectors(mailbox_buffers); |
|
no sievers
2014/07/10 18:52:29
nit: |release_syncpoints_|?
| |
| 501 #if defined(OS_ANDROID) | |
| 502 GLHelper* gl_helper = | |
| 503 ImageTransportFactoryAndroid::GetInstance()->GetGLHelper(); | |
| 504 #else | |
| 505 GLHelper* gl_helper = ImageTransportFactory::GetInstance()->GetGLHelper(); | |
| 506 #endif | |
| 488 for (int i = 0; i < mailbox_buffers; ++i) { | 507 for (int i = 0; i < mailbox_buffers; ++i) { |
| 489 buffer = device_->ReserveOutputBuffer(media::VideoFrame::NATIVE_TEXTURE, | 508 buffer = device_->ReserveOutputBuffer(media::VideoFrame::NATIVE_TEXTURE, |
| 490 gfx::Size(0, 0)); | 509 gfx::Size(0, 0)); |
| 491 ASSERT_TRUE(buffer); | 510 ASSERT_TRUE(buffer); |
| 492 mailbox_syncpoints[i] = i; | 511 mailbox_syncpoints[i] = gl_helper->InsertSyncPoint(); |
| 493 device_->OnIncomingCapturedVideoFrame( | 512 device_->OnIncomingCapturedVideoFrame( |
| 494 buffer, | 513 buffer, |
| 495 media::VideoCaptureFormat(capture_resolution, | 514 media::VideoCaptureFormat(capture_resolution, |
| 496 device_format.frame_rate, | 515 device_format.frame_rate, |
| 497 media::PIXEL_FORMAT_TEXTURE), | 516 media::PIXEL_FORMAT_TEXTURE), |
| 498 WrapMailboxBuffer( | 517 WrapMailboxBuffer( |
| 499 buffer, | 518 buffer, |
| 500 make_scoped_ptr(new gpu::MailboxHolder( | 519 make_scoped_ptr(new gpu::MailboxHolder( |
| 501 gpu::Mailbox(), 0, mailbox_syncpoints[i])), | 520 gpu::Mailbox(), 0, mailbox_syncpoints[i])), |
| 502 base::Bind(&CacheSyncPoint, &release_syncpoint_vectors[i]), | 521 base::Bind(&CacheSyncPoint, &release_syncpoint_vectors[i]), |
| 503 capture_resolution), | 522 capture_resolution), |
| 504 base::TimeTicks()); | 523 base::TimeTicks()); |
| 505 buffer = NULL; | 524 buffer = NULL; |
| 506 } | 525 } |
| 507 // ReserveOutputBuffers ought to fail now regardless of buffer format, because | 526 // ReserveOutputBuffers ought to fail now regardless of buffer format, because |
| 508 // the pool is depleted. | 527 // the pool is depleted. |
| 509 ASSERT_FALSE(device_->ReserveOutputBuffer(media::VideoFrame::I420, | 528 ASSERT_FALSE(device_->ReserveOutputBuffer(media::VideoFrame::I420, |
| 510 capture_resolution)); | 529 capture_resolution)); |
| 511 ASSERT_FALSE(device_->ReserveOutputBuffer(media::VideoFrame::NATIVE_TEXTURE, | 530 ASSERT_FALSE(device_->ReserveOutputBuffer(media::VideoFrame::NATIVE_TEXTURE, |
| 512 gfx::Size(0, 0))); | 531 gfx::Size(0, 0))); |
| 513 EXPECT_CALL(*client_b_, DoBufferReady(client_b_route_2)).Times(shm_buffers); | 532 EXPECT_CALL(*client_b_, DoBufferReady(client_b_route_2)).Times(shm_buffers); |
| 514 EXPECT_CALL(*client_b_, DoMailboxBufferReady(client_b_route_2)) | 533 EXPECT_CALL(*client_b_, DoMailboxBufferReady(client_b_route_2)) |
| 515 .Times(mailbox_buffers); | 534 .Times(mailbox_buffers); |
| 516 base::RunLoop().RunUntilIdle(); | 535 base::RunLoop().RunUntilIdle(); |
| 517 for (size_t i = 0; i < mailbox_syncpoints.size(); ++i) { | 536 for (size_t i = 0; i < mailbox_syncpoints.size(); ++i) { |
| 518 // See: MockVideoCaptureControllerEventHandler::OnMailboxBufferReady() | 537 // A new release sync point must be inserted when the video frame is |
| 519 ASSERT_EQ(1u, release_syncpoint_vectors[i].size()); | 538 // returned to the Browser process. |
| 520 ASSERT_EQ(mailbox_syncpoints[i], ~release_syncpoint_vectors[i][0]); | 539 // See: MockVideoCaptureControllerEventHandler::OnMailboxBufferReady() and |
| 540 // VideoCaptureController::ReturnBuffer() | |
| 541 ASSERT_NE(mailbox_syncpoints[i], release_syncpoint_vectors[i]); | |
|
no sievers
2014/07/10 18:52:29
At what point are those equal though? Can we ASSER
dshwang
2014/07/10 19:23:11
Unfortunately, we cannot know what is release_sync
| |
| 521 } | 542 } |
| 522 Mock::VerifyAndClearExpectations(client_b_.get()); | 543 Mock::VerifyAndClearExpectations(client_b_.get()); |
| 523 } | 544 } |
| 524 | 545 |
| 525 // Exercises the OnError() codepath of VideoCaptureController, and tests the | 546 // Exercises the OnError() codepath of VideoCaptureController, and tests the |
| 526 // behavior of various operations after the error state has been signalled. | 547 // behavior of various operations after the error state has been signalled. |
| 527 TEST_F(VideoCaptureControllerTest, ErrorBeforeDeviceCreation) { | 548 TEST_F(VideoCaptureControllerTest, ErrorBeforeDeviceCreation) { |
| 528 media::VideoCaptureParams session_100; | 549 media::VideoCaptureParams session_100; |
| 529 session_100.requested_format = media::VideoCaptureFormat( | 550 session_100.requested_format = media::VideoCaptureFormat( |
| 530 gfx::Size(320, 240), 30, media::PIXEL_FORMAT_I420); | 551 gfx::Size(320, 240), 30, media::PIXEL_FORMAT_I420); |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 609 | 630 |
| 610 // Second client connects after the error state. It also should get told of | 631 // Second client connects after the error state. It also should get told of |
| 611 // the error. | 632 // the error. |
| 612 EXPECT_CALL(*client_b_, DoError(route_id)).Times(1); | 633 EXPECT_CALL(*client_b_, DoError(route_id)).Times(1); |
| 613 controller_->AddClient( | 634 controller_->AddClient( |
| 614 route_id, client_b_.get(), base::kNullProcessHandle, 200, session_200); | 635 route_id, client_b_.get(), base::kNullProcessHandle, 200, session_200); |
| 615 Mock::VerifyAndClearExpectations(client_b_.get()); | 636 Mock::VerifyAndClearExpectations(client_b_.get()); |
| 616 } | 637 } |
| 617 | 638 |
| 618 } // namespace content | 639 } // namespace content |
| OLD | NEW |