| 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 "base/thread_task_runner_handle.h" | |
| 16 #include "content/browser/renderer_host/media/media_stream_provider.h" | 15 #include "content/browser/renderer_host/media/media_stream_provider.h" |
| 17 #include "content/browser/renderer_host/media/video_capture_controller.h" | 16 #include "content/browser/renderer_host/media/video_capture_controller.h" |
| 18 #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" |
| 19 #include "content/browser/renderer_host/media/video_capture_manager.h" | 18 #include "content/browser/renderer_host/media/video_capture_manager.h" |
| 20 #include "content/common/gpu/client/gl_helper.h" | 19 #include "content/common/gpu/client/gl_helper.h" |
| 21 #include "content/common/media/media_stream_options.h" | 20 #include "content/common/media/media_stream_options.h" |
| 22 #include "content/public/test/test_browser_thread_bundle.h" | 21 #include "content/public/test/test_browser_thread_bundle.h" |
| 23 #include "gpu/command_buffer/common/mailbox_holder.h" | 22 #include "gpu/command_buffer/common/mailbox_holder.h" |
| 24 #include "media/base/video_capture_types.h" | 23 #include "media/base/video_capture_types.h" |
| 25 #include "media/base/video_util.h" | 24 #include "media/base/video_util.h" |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 116 public: | 115 public: |
| 117 VideoCaptureControllerTest() {} | 116 VideoCaptureControllerTest() {} |
| 118 ~VideoCaptureControllerTest() override {} | 117 ~VideoCaptureControllerTest() override {} |
| 119 | 118 |
| 120 protected: | 119 protected: |
| 121 static const int kPoolSize = 3; | 120 static const int kPoolSize = 3; |
| 122 | 121 |
| 123 void SetUp() override { | 122 void SetUp() override { |
| 124 controller_.reset(new VideoCaptureController(kPoolSize)); | 123 controller_.reset(new VideoCaptureController(kPoolSize)); |
| 125 device_ = controller_->NewDeviceClient( | 124 device_ = controller_->NewDeviceClient( |
| 126 base::ThreadTaskRunnerHandle::Get()); | 125 base::MessageLoopProxy::current(), |
| 126 controller_->GetVideoCaptureFormat()); |
| 127 client_a_.reset(new MockVideoCaptureControllerEventHandler( | 127 client_a_.reset(new MockVideoCaptureControllerEventHandler( |
| 128 controller_.get())); | 128 controller_.get())); |
| 129 client_b_.reset(new MockVideoCaptureControllerEventHandler( | 129 client_b_.reset(new MockVideoCaptureControllerEventHandler( |
| 130 controller_.get())); | 130 controller_.get())); |
| 131 } | 131 } |
| 132 | 132 |
| 133 void TearDown() override { base::RunLoop().RunUntilIdle(); } | 133 void TearDown() override { base::RunLoop().RunUntilIdle(); } |
| 134 | 134 |
| 135 scoped_refptr<media::VideoFrame> WrapI420Buffer(gfx::Size dimensions, | 135 scoped_refptr<media::VideoFrame> WrapI420Buffer( |
| 136 uint8* data) { | 136 const scoped_refptr<media::VideoCaptureDevice::Client::Buffer>& buffer, |
| 137 gfx::Size dimensions) { |
| 137 return media::VideoFrame::WrapExternalPackedMemory( | 138 return media::VideoFrame::WrapExternalPackedMemory( |
| 138 media::VideoFrame::I420, | 139 media::VideoFrame::I420, |
| 139 dimensions, | 140 dimensions, |
| 140 gfx::Rect(dimensions), | 141 gfx::Rect(dimensions), |
| 141 dimensions, | 142 dimensions, |
| 142 data, | 143 reinterpret_cast<uint8*>(buffer->data()), |
| 143 media::VideoFrame::AllocationSize(media::VideoFrame::I420, dimensions), | 144 media::VideoFrame::AllocationSize(media::VideoFrame::I420, dimensions), |
| 144 base::SharedMemory::NULLHandle(), | 145 base::SharedMemory::NULLHandle(), |
| 145 0, | 146 0, |
| 146 base::TimeDelta(), | 147 base::TimeDelta(), |
| 147 base::Closure()); | 148 base::Closure()); |
| 148 } | 149 } |
| 149 | 150 |
| 150 scoped_refptr<media::VideoFrame> WrapMailboxBuffer( | 151 scoped_refptr<media::VideoFrame> WrapMailboxBuffer( |
| 151 scoped_ptr<gpu::MailboxHolder> holder, | 152 scoped_ptr<gpu::MailboxHolder> holder, |
| 152 const media::VideoFrame::ReleaseMailboxCB& release_cb, | 153 const media::VideoFrame::ReleaseMailboxCB& release_cb, |
| (...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 317 controller_->AddClient(client_a_route_2, | 318 controller_->AddClient(client_a_route_2, |
| 318 client_a_.get(), | 319 client_a_.get(), |
| 319 base::kNullProcessHandle, | 320 base::kNullProcessHandle, |
| 320 200, | 321 200, |
| 321 session_200); | 322 session_200); |
| 322 ASSERT_EQ(3, controller_->GetClientCount()); | 323 ASSERT_EQ(3, controller_->GetClientCount()); |
| 323 | 324 |
| 324 // Now, simulate an incoming captured buffer from the capture device. As a | 325 // Now, simulate an incoming captured buffer from the capture device. As a |
| 325 // side effect this will cause the first buffer to be shared with clients. | 326 // side effect this will cause the first buffer to be shared with clients. |
| 326 uint8 buffer_no = 1; | 327 uint8 buffer_no = 1; |
| 327 scoped_ptr<media::VideoCaptureDevice::Client::Buffer> buffer( | 328 scoped_refptr<media::VideoCaptureDevice::Client::Buffer> buffer; |
| 328 device_->ReserveOutputBuffer(media::PIXEL_FORMAT_I420, | 329 buffer = device_->ReserveOutputBuffer(media::PIXEL_FORMAT_I420, |
| 329 capture_resolution)); | 330 capture_resolution); |
| 330 ASSERT_TRUE(buffer.get()); | 331 ASSERT_TRUE(buffer.get()); |
| 331 memset(buffer->data(), buffer_no++, buffer->size()); | 332 memset(buffer->data(), buffer_no++, buffer->size()); |
| 332 { | 333 { |
| 333 InSequence s; | 334 InSequence s; |
| 334 EXPECT_CALL(*client_a_, DoBufferCreated(client_a_route_1)).Times(1); | 335 EXPECT_CALL(*client_a_, DoBufferCreated(client_a_route_1)).Times(1); |
| 335 EXPECT_CALL(*client_a_, DoBufferReady(client_a_route_1,_)).Times(1); | 336 EXPECT_CALL(*client_a_, DoBufferReady(client_a_route_1,_)).Times(1); |
| 336 } | 337 } |
| 337 { | 338 { |
| 338 InSequence s; | 339 InSequence s; |
| 339 EXPECT_CALL(*client_b_, DoBufferCreated(client_b_route_1)).Times(1); | 340 EXPECT_CALL(*client_b_, DoBufferCreated(client_b_route_1)).Times(1); |
| 340 EXPECT_CALL(*client_b_, DoBufferReady(client_b_route_1,_)).Times(1); | 341 EXPECT_CALL(*client_b_, DoBufferReady(client_b_route_1,_)).Times(1); |
| 341 } | 342 } |
| 342 { | 343 { |
| 343 InSequence s; | 344 InSequence s; |
| 344 EXPECT_CALL(*client_a_, DoBufferCreated(client_a_route_2)).Times(1); | 345 EXPECT_CALL(*client_a_, DoBufferCreated(client_a_route_2)).Times(1); |
| 345 EXPECT_CALL(*client_a_, DoBufferReady(client_a_route_2,_)).Times(1); | 346 EXPECT_CALL(*client_a_, DoBufferReady(client_a_route_2,_)).Times(1); |
| 346 } | 347 } |
| 347 scoped_refptr<media::VideoFrame> video_frame = | 348 device_->OnIncomingCapturedVideoFrame( |
| 348 WrapI420Buffer(capture_resolution, static_cast<uint8*>(buffer->data())); | 349 buffer, |
| 349 device_->OnIncomingCapturedVideoFrame(buffer.Pass(), video_frame, | 350 WrapI420Buffer(buffer, capture_resolution), |
| 350 base::TimeTicks()); | 351 base::TimeTicks()); |
| 352 buffer = NULL; |
| 351 | 353 |
| 352 base::RunLoop().RunUntilIdle(); | 354 base::RunLoop().RunUntilIdle(); |
| 353 Mock::VerifyAndClearExpectations(client_a_.get()); | 355 Mock::VerifyAndClearExpectations(client_a_.get()); |
| 354 Mock::VerifyAndClearExpectations(client_b_.get()); | 356 Mock::VerifyAndClearExpectations(client_b_.get()); |
| 355 | 357 |
| 356 // Second buffer which ought to use the same shared memory buffer. In this | 358 // Second buffer which ought to use the same shared memory buffer. In this |
| 357 // case pretend that the Buffer pointer is held by the device for a long | 359 // case pretend that the Buffer pointer is held by the device for a long |
| 358 // delay. This shouldn't affect anything. | 360 // delay. This shouldn't affect anything. |
| 359 scoped_ptr<media::VideoCaptureDevice::Client::Buffer> buffer2 = | 361 buffer = device_->ReserveOutputBuffer(media::PIXEL_FORMAT_I420, |
| 360 device_->ReserveOutputBuffer(media::PIXEL_FORMAT_I420, | 362 capture_resolution); |
| 361 capture_resolution); | 363 ASSERT_TRUE(buffer.get()); |
| 362 ASSERT_TRUE(buffer2.get()); | 364 memset(buffer->data(), buffer_no++, buffer->size()); |
| 363 memset(buffer2->data(), buffer_no++, buffer2->size()); | 365 device_->OnIncomingCapturedVideoFrame( |
| 364 video_frame = | 366 buffer, |
| 365 WrapI420Buffer(capture_resolution, static_cast<uint8*>(buffer2->data())); | 367 WrapI420Buffer(buffer, capture_resolution), |
| 366 device_->OnIncomingCapturedVideoFrame(buffer2.Pass(), video_frame, | 368 base::TimeTicks()); |
| 367 base::TimeTicks()); | 369 buffer = NULL; |
| 368 | 370 |
| 369 // The buffer should be delivered to the clients in any order. | 371 // The buffer should be delivered to the clients in any order. |
| 370 EXPECT_CALL(*client_a_, DoBufferReady(client_a_route_1,_)).Times(1); | 372 EXPECT_CALL(*client_a_, DoBufferReady(client_a_route_1,_)).Times(1); |
| 371 EXPECT_CALL(*client_b_, DoBufferReady(client_b_route_1,_)).Times(1); | 373 EXPECT_CALL(*client_b_, DoBufferReady(client_b_route_1,_)).Times(1); |
| 372 EXPECT_CALL(*client_a_, DoBufferReady(client_a_route_2,_)).Times(1); | 374 EXPECT_CALL(*client_a_, DoBufferReady(client_a_route_2,_)).Times(1); |
| 373 base::RunLoop().RunUntilIdle(); | 375 base::RunLoop().RunUntilIdle(); |
| 374 Mock::VerifyAndClearExpectations(client_a_.get()); | 376 Mock::VerifyAndClearExpectations(client_a_.get()); |
| 375 Mock::VerifyAndClearExpectations(client_b_.get()); | 377 Mock::VerifyAndClearExpectations(client_b_.get()); |
| 376 | 378 |
| 377 // Add a fourth client now that some buffers have come through. | 379 // Add a fourth client now that some buffers have come through. |
| 378 controller_->AddClient(client_b_route_2, | 380 controller_->AddClient(client_b_route_2, |
| 379 client_b_.get(), | 381 client_b_.get(), |
| 380 base::kNullProcessHandle, | 382 base::kNullProcessHandle, |
| 381 1, | 383 1, |
| 382 session_1); | 384 session_1); |
| 383 Mock::VerifyAndClearExpectations(client_b_.get()); | 385 Mock::VerifyAndClearExpectations(client_b_.get()); |
| 384 | 386 |
| 385 // Third, fourth, and fifth buffers. Pretend they all arrive at the same time. | 387 // Third, fourth, and fifth buffers. Pretend they all arrive at the same time. |
| 386 for (int i = 0; i < kPoolSize; i++) { | 388 for (int i = 0; i < kPoolSize; i++) { |
| 387 scoped_ptr<media::VideoCaptureDevice::Client::Buffer> buffer = | 389 buffer = device_->ReserveOutputBuffer(media::PIXEL_FORMAT_I420, |
| 388 device_->ReserveOutputBuffer(media::PIXEL_FORMAT_I420, | 390 capture_resolution); |
| 389 capture_resolution); | |
| 390 ASSERT_TRUE(buffer.get()); | 391 ASSERT_TRUE(buffer.get()); |
| 391 memset(buffer->data(), buffer_no++, buffer->size()); | 392 memset(buffer->data(), buffer_no++, buffer->size()); |
| 392 video_frame = | 393 device_->OnIncomingCapturedVideoFrame( |
| 393 WrapI420Buffer(capture_resolution, static_cast<uint8*>(buffer->data())); | 394 buffer, |
| 394 device_->OnIncomingCapturedVideoFrame(buffer.Pass(), video_frame, | 395 WrapI420Buffer(buffer, capture_resolution), |
| 395 base::TimeTicks()); | 396 base::TimeTicks()); |
| 397 buffer = NULL; |
| 396 } | 398 } |
| 397 // ReserveOutputBuffer ought to fail now, because the pool is depleted. | 399 // ReserveOutputBuffer ought to fail now, because the pool is depleted. |
| 398 ASSERT_FALSE(device_->ReserveOutputBuffer(media::PIXEL_FORMAT_I420, | 400 ASSERT_FALSE(device_->ReserveOutputBuffer(media::PIXEL_FORMAT_I420, |
| 399 capture_resolution).get()); | 401 capture_resolution).get()); |
| 400 | 402 |
| 401 // The new client needs to be told of 3 buffers; the old clients only 2. | 403 // The new client needs to be told of 3 buffers; the old clients only 2. |
| 402 EXPECT_CALL(*client_b_, DoBufferCreated(client_b_route_2)).Times(kPoolSize); | 404 EXPECT_CALL(*client_b_, DoBufferCreated(client_b_route_2)).Times(kPoolSize); |
| 403 EXPECT_CALL(*client_b_, DoBufferReady(client_b_route_2,_)).Times(kPoolSize); | 405 EXPECT_CALL(*client_b_, DoBufferReady(client_b_route_2,_)).Times(kPoolSize); |
| 404 EXPECT_CALL(*client_a_, DoBufferCreated(client_a_route_1)) | 406 EXPECT_CALL(*client_a_, DoBufferCreated(client_a_route_1)) |
| 405 .Times(kPoolSize - 1); | 407 .Times(kPoolSize - 1); |
| 406 EXPECT_CALL(*client_a_, DoBufferReady(client_a_route_1,_)).Times(kPoolSize); | 408 EXPECT_CALL(*client_a_, DoBufferReady(client_a_route_1,_)).Times(kPoolSize); |
| 407 EXPECT_CALL(*client_a_, DoBufferCreated(client_a_route_2)) | 409 EXPECT_CALL(*client_a_, DoBufferCreated(client_a_route_2)) |
| 408 .Times(kPoolSize - 1); | 410 .Times(kPoolSize - 1); |
| 409 EXPECT_CALL(*client_a_, DoBufferReady(client_a_route_2,_)).Times(kPoolSize); | 411 EXPECT_CALL(*client_a_, DoBufferReady(client_a_route_2,_)).Times(kPoolSize); |
| 410 EXPECT_CALL(*client_b_, DoBufferCreated(client_b_route_1)) | 412 EXPECT_CALL(*client_b_, DoBufferCreated(client_b_route_1)) |
| 411 .Times(kPoolSize - 1); | 413 .Times(kPoolSize - 1); |
| 412 EXPECT_CALL(*client_b_, DoBufferReady(client_b_route_1,_)).Times(kPoolSize); | 414 EXPECT_CALL(*client_b_, DoBufferReady(client_b_route_1,_)).Times(kPoolSize); |
| 413 base::RunLoop().RunUntilIdle(); | 415 base::RunLoop().RunUntilIdle(); |
| 414 Mock::VerifyAndClearExpectations(client_a_.get()); | 416 Mock::VerifyAndClearExpectations(client_a_.get()); |
| 415 Mock::VerifyAndClearExpectations(client_b_.get()); | 417 Mock::VerifyAndClearExpectations(client_b_.get()); |
| 416 | 418 |
| 417 // Now test the interaction of client shutdown and buffer delivery. | 419 // Now test the interaction of client shutdown and buffer delivery. |
| 418 // Kill A1 via renderer disconnect (synchronous). | 420 // Kill A1 via renderer disconnect (synchronous). |
| 419 controller_->RemoveClient(client_a_route_1, client_a_.get()); | 421 controller_->RemoveClient(client_a_route_1, client_a_.get()); |
| 420 // Kill B1 via session close (posts a task to disconnect). | 422 // Kill B1 via session close (posts a task to disconnect). |
| 421 EXPECT_CALL(*client_b_, DoEnded(client_b_route_1)).Times(1); | 423 EXPECT_CALL(*client_b_, DoEnded(client_b_route_1)).Times(1); |
| 422 controller_->StopSession(300); | 424 controller_->StopSession(300); |
| 423 // Queue up another buffer. | 425 // Queue up another buffer. |
| 424 scoped_ptr<media::VideoCaptureDevice::Client::Buffer> buffer3 = | 426 buffer = device_->ReserveOutputBuffer(media::PIXEL_FORMAT_I420, |
| 425 device_->ReserveOutputBuffer(media::PIXEL_FORMAT_I420, | 427 capture_resolution); |
| 426 capture_resolution); | 428 ASSERT_TRUE(buffer.get()); |
| 427 ASSERT_TRUE(buffer3.get()); | 429 memset(buffer->data(), buffer_no++, buffer->size()); |
| 428 memset(buffer3->data(), buffer_no++, buffer3->size()); | 430 device_->OnIncomingCapturedVideoFrame( |
| 429 video_frame = | 431 buffer, |
| 430 WrapI420Buffer(capture_resolution, static_cast<uint8*>(buffer3->data())); | 432 WrapI420Buffer(buffer, capture_resolution), |
| 431 device_->OnIncomingCapturedVideoFrame(buffer3.Pass(), video_frame, | 433 base::TimeTicks()); |
| 432 base::TimeTicks()); | 434 buffer = NULL; |
| 433 | 435 buffer = device_->ReserveOutputBuffer(media::PIXEL_FORMAT_I420, |
| 434 scoped_ptr<media::VideoCaptureDevice::Client::Buffer> buffer4 = | 436 capture_resolution); |
| 435 device_->ReserveOutputBuffer(media::PIXEL_FORMAT_I420, | |
| 436 capture_resolution); | |
| 437 { | 437 { |
| 438 // Kill A2 via session close (posts a task to disconnect, but A2 must not | 438 // Kill A2 via session close (posts a task to disconnect, but A2 must not |
| 439 // be sent either of these two buffers). | 439 // be sent either of these two buffers). |
| 440 EXPECT_CALL(*client_a_, DoEnded(client_a_route_2)).Times(1); | 440 EXPECT_CALL(*client_a_, DoEnded(client_a_route_2)).Times(1); |
| 441 controller_->StopSession(200); | 441 controller_->StopSession(200); |
| 442 } | 442 } |
| 443 ASSERT_TRUE(buffer4.get()); | 443 ASSERT_TRUE(buffer.get()); |
| 444 memset(buffer4->data(), buffer_no++, buffer4->size()); | 444 memset(buffer->data(), buffer_no++, buffer->size()); |
| 445 video_frame = | 445 device_->OnIncomingCapturedVideoFrame( |
| 446 WrapI420Buffer(capture_resolution, static_cast<uint8*>(buffer4->data())); | 446 buffer, |
| 447 device_->OnIncomingCapturedVideoFrame(buffer4.Pass(), video_frame, | 447 WrapI420Buffer(buffer, capture_resolution), |
| 448 base::TimeTicks()); | 448 base::TimeTicks()); |
| 449 buffer = NULL; |
| 449 // B2 is the only client left, and is the only one that should | 450 // B2 is the only client left, and is the only one that should |
| 450 // get the buffer. | 451 // get the buffer. |
| 451 EXPECT_CALL(*client_b_, DoBufferReady(client_b_route_2,_)).Times(2); | 452 EXPECT_CALL(*client_b_, DoBufferReady(client_b_route_2,_)).Times(2); |
| 452 base::RunLoop().RunUntilIdle(); | 453 base::RunLoop().RunUntilIdle(); |
| 453 Mock::VerifyAndClearExpectations(client_a_.get()); | 454 Mock::VerifyAndClearExpectations(client_a_.get()); |
| 454 Mock::VerifyAndClearExpectations(client_b_.get()); | 455 Mock::VerifyAndClearExpectations(client_b_.get()); |
| 455 | 456 |
| 456 // Allocate all buffers from the buffer pool, half as SHM buffer and half as | 457 // Allocate all buffers from the buffer pool, half as SHM buffer and half as |
| 457 // mailbox buffers. Make sure of different counts though. | 458 // mailbox buffers. Make sure of different counts though. |
| 458 #if defined(OS_ANDROID) | 459 #if defined(OS_ANDROID) |
| 459 int mailbox_buffers = 0; | 460 int mailbox_buffers = 0; |
| 460 #else | 461 #else |
| 461 int mailbox_buffers = kPoolSize / 2; | 462 int mailbox_buffers = kPoolSize / 2; |
| 462 GLHelper* gl_helper = ImageTransportFactory::GetInstance()->GetGLHelper(); | 463 GLHelper* gl_helper = ImageTransportFactory::GetInstance()->GetGLHelper(); |
| 463 #endif | 464 #endif |
| 464 int shm_buffers = kPoolSize - mailbox_buffers; | 465 int shm_buffers = kPoolSize - mailbox_buffers; |
| 465 if (shm_buffers == mailbox_buffers) { | 466 if (shm_buffers == mailbox_buffers) { |
| 466 shm_buffers--; | 467 shm_buffers--; |
| 467 mailbox_buffers++; | 468 mailbox_buffers++; |
| 468 } | 469 } |
| 469 | 470 |
| 470 for (int i = 0; i < shm_buffers; ++i) { | 471 for (int i = 0; i < shm_buffers; ++i) { |
| 471 scoped_ptr<media::VideoCaptureDevice::Client::Buffer> buffer = | 472 buffer = device_->ReserveOutputBuffer(media::PIXEL_FORMAT_I420, |
| 472 device_->ReserveOutputBuffer(media::PIXEL_FORMAT_I420, | 473 capture_resolution); |
| 473 capture_resolution); | |
| 474 ASSERT_TRUE(buffer.get()); | 474 ASSERT_TRUE(buffer.get()); |
| 475 video_frame = | 475 device_->OnIncomingCapturedVideoFrame( |
| 476 WrapI420Buffer(capture_resolution, static_cast<uint8*>(buffer->data())); | 476 buffer, |
| 477 device_->OnIncomingCapturedVideoFrame(buffer.Pass(), video_frame, | 477 WrapI420Buffer(buffer, capture_resolution), |
| 478 base::TimeTicks()); | 478 base::TimeTicks()); |
| 479 buffer = NULL; |
| 479 } | 480 } |
| 480 std::vector<uint32> mailbox_syncpoints(mailbox_buffers); | 481 std::vector<uint32> mailbox_syncpoints(mailbox_buffers); |
| 481 std::vector<uint32> release_syncpoints(mailbox_buffers); | 482 std::vector<uint32> release_syncpoints(mailbox_buffers); |
| 482 for (int i = 0; i < mailbox_buffers; ++i) { | 483 for (int i = 0; i < mailbox_buffers; ++i) { |
| 483 scoped_ptr<media::VideoCaptureDevice::Client::Buffer> buffer = | 484 buffer = device_->ReserveOutputBuffer(media::PIXEL_FORMAT_TEXTURE, |
| 484 device_->ReserveOutputBuffer(media::PIXEL_FORMAT_TEXTURE, | 485 capture_resolution); |
| 485 capture_resolution); | |
| 486 ASSERT_TRUE(buffer.get()); | 486 ASSERT_TRUE(buffer.get()); |
| 487 #if !defined(OS_ANDROID) | 487 #if !defined(OS_ANDROID) |
| 488 mailbox_syncpoints[i] = gl_helper->InsertSyncPoint(); | 488 mailbox_syncpoints[i] = gl_helper->InsertSyncPoint(); |
| 489 #endif | 489 #endif |
| 490 device_->OnIncomingCapturedVideoFrame( | 490 device_->OnIncomingCapturedVideoFrame( |
| 491 buffer.Pass(), | 491 buffer, |
| 492 WrapMailboxBuffer(make_scoped_ptr(new gpu::MailboxHolder( | 492 WrapMailboxBuffer(make_scoped_ptr(new gpu::MailboxHolder( |
| 493 gpu::Mailbox(), 0, mailbox_syncpoints[i])), | 493 gpu::Mailbox(), 0, mailbox_syncpoints[i])), |
| 494 base::Bind(&CacheSyncPoint, &release_syncpoints[i]), | 494 base::Bind(&CacheSyncPoint, &release_syncpoints[i]), |
| 495 capture_resolution), | 495 capture_resolution), |
| 496 base::TimeTicks()); | 496 base::TimeTicks()); |
| 497 buffer = NULL; |
| 497 } | 498 } |
| 498 // ReserveOutputBuffers ought to fail now regardless of buffer format, because | 499 // ReserveOutputBuffers ought to fail now regardless of buffer format, because |
| 499 // the pool is depleted. | 500 // the pool is depleted. |
| 500 ASSERT_FALSE(device_->ReserveOutputBuffer(media::PIXEL_FORMAT_I420, | 501 ASSERT_FALSE(device_->ReserveOutputBuffer(media::PIXEL_FORMAT_I420, |
| 501 capture_resolution).get()); | 502 capture_resolution).get()); |
| 502 ASSERT_FALSE(device_->ReserveOutputBuffer(media::PIXEL_FORMAT_TEXTURE, | 503 ASSERT_FALSE(device_->ReserveOutputBuffer(media::PIXEL_FORMAT_TEXTURE, |
| 503 capture_resolution).get()); | 504 capture_resolution).get()); |
| 504 EXPECT_CALL(*client_b_, DoBufferReady(client_b_route_2,_)).Times(shm_buffers); | 505 EXPECT_CALL(*client_b_, DoBufferReady(client_b_route_2,_)).Times(shm_buffers); |
| 505 EXPECT_CALL(*client_b_, DoMailboxBufferReady(client_b_route_2)) | 506 EXPECT_CALL(*client_b_, DoMailboxBufferReady(client_b_route_2)) |
| 506 .Times(mailbox_buffers); | 507 .Times(mailbox_buffers); |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 541 Mock::VerifyAndClearExpectations(client_a_.get()); | 542 Mock::VerifyAndClearExpectations(client_a_.get()); |
| 542 | 543 |
| 543 // Second client connects after the error state. It also should get told of | 544 // Second client connects after the error state. It also should get told of |
| 544 // the error. | 545 // the error. |
| 545 EXPECT_CALL(*client_b_, DoError(route_id)).Times(1); | 546 EXPECT_CALL(*client_b_, DoError(route_id)).Times(1); |
| 546 controller_->AddClient( | 547 controller_->AddClient( |
| 547 route_id, client_b_.get(), base::kNullProcessHandle, 200, session_200); | 548 route_id, client_b_.get(), base::kNullProcessHandle, 200, session_200); |
| 548 base::RunLoop().RunUntilIdle(); | 549 base::RunLoop().RunUntilIdle(); |
| 549 Mock::VerifyAndClearExpectations(client_b_.get()); | 550 Mock::VerifyAndClearExpectations(client_b_.get()); |
| 550 | 551 |
| 551 scoped_ptr<media::VideoCaptureDevice::Client::Buffer> buffer( | 552 scoped_refptr<media::VideoCaptureDevice::Client::Buffer> buffer = |
| 552 device_->ReserveOutputBuffer(media::PIXEL_FORMAT_I420, | 553 device_->ReserveOutputBuffer(media::PIXEL_FORMAT_I420, |
| 553 capture_resolution)); | 554 capture_resolution); |
| 554 ASSERT_TRUE(buffer.get()); | 555 ASSERT_TRUE(buffer.get()); |
| 555 scoped_refptr<media::VideoFrame> video_frame = | 556 |
| 556 WrapI420Buffer(capture_resolution, static_cast<uint8*>(buffer->data())); | 557 device_->OnIncomingCapturedVideoFrame( |
| 557 device_->OnIncomingCapturedVideoFrame(buffer.Pass(), video_frame, | 558 buffer, |
| 558 base::TimeTicks()); | 559 WrapI420Buffer(buffer, capture_resolution), |
| 560 base::TimeTicks()); |
| 561 buffer = NULL; |
| 559 | 562 |
| 560 base::RunLoop().RunUntilIdle(); | 563 base::RunLoop().RunUntilIdle(); |
| 561 } | 564 } |
| 562 | 565 |
| 563 // Exercises the OnError() codepath of VideoCaptureController, and tests the | 566 // Exercises the OnError() codepath of VideoCaptureController, and tests the |
| 564 // behavior of various operations after the error state has been signalled. | 567 // behavior of various operations after the error state has been signalled. |
| 565 TEST_F(VideoCaptureControllerTest, ErrorAfterDeviceCreation) { | 568 TEST_F(VideoCaptureControllerTest, ErrorAfterDeviceCreation) { |
| 566 media::VideoCaptureParams session_100; | 569 media::VideoCaptureParams session_100; |
| 567 session_100.requested_format = media::VideoCaptureFormat( | 570 session_100.requested_format = media::VideoCaptureFormat( |
| 568 gfx::Size(320, 240), 30, media::PIXEL_FORMAT_I420); | 571 gfx::Size(320, 240), 30, media::PIXEL_FORMAT_I420); |
| 569 | 572 |
| 570 media::VideoCaptureParams session_200 = session_100; | 573 media::VideoCaptureParams session_200 = session_100; |
| 571 | 574 |
| 572 const VideoCaptureControllerID route_id(0x99); | 575 const VideoCaptureControllerID route_id(0x99); |
| 573 | 576 |
| 574 // Start with one client. | 577 // Start with one client. |
| 575 controller_->AddClient( | 578 controller_->AddClient( |
| 576 route_id, client_a_.get(), base::kNullProcessHandle, 100, session_100); | 579 route_id, client_a_.get(), base::kNullProcessHandle, 100, session_100); |
| 577 media::VideoCaptureFormat device_format( | 580 media::VideoCaptureFormat device_format( |
| 578 gfx::Size(10, 10), 25, media::PIXEL_FORMAT_ARGB); | 581 gfx::Size(10, 10), 25, media::PIXEL_FORMAT_ARGB); |
| 579 | 582 |
| 580 // Start the device. Then, before the first buffer, signal an error and | 583 // Start the device. Then, before the first buffer, signal an error and |
| 581 // deliver the buffer. The error should be propagated to clients; the buffer | 584 // deliver the buffer. The error should be propagated to clients; the buffer |
| 582 // should not be. | 585 // should not be. |
| 583 base::RunLoop().RunUntilIdle(); | 586 base::RunLoop().RunUntilIdle(); |
| 584 Mock::VerifyAndClearExpectations(client_a_.get()); | 587 Mock::VerifyAndClearExpectations(client_a_.get()); |
| 585 | 588 |
| 586 const gfx::Size dims(320, 240); | 589 const gfx::Size dims(320, 240); |
| 587 scoped_ptr<media::VideoCaptureDevice::Client::Buffer> buffer( | 590 scoped_refptr<media::VideoCaptureDevice::Client::Buffer> buffer = |
| 588 device_->ReserveOutputBuffer(media::PIXEL_FORMAT_I420, dims)); | 591 device_->ReserveOutputBuffer(media::PIXEL_FORMAT_I420, dims); |
| 589 ASSERT_TRUE(buffer.get()); | 592 ASSERT_TRUE(buffer.get()); |
| 590 | 593 |
| 591 scoped_refptr<media::VideoFrame> video_frame = | 594 device_->OnError("Test error"); |
| 592 WrapI420Buffer(dims, static_cast<uint8*>(buffer->data())); | 595 device_->OnIncomingCapturedVideoFrame( |
| 593 device_->OnError("Test Error"); | 596 buffer, |
| 594 device_->OnIncomingCapturedVideoFrame(buffer.Pass(), video_frame, | 597 WrapI420Buffer(buffer, dims), |
| 595 base::TimeTicks()); | 598 base::TimeTicks()); |
| 599 buffer = NULL; |
| 596 | 600 |
| 597 EXPECT_CALL(*client_a_, DoError(route_id)).Times(1); | 601 EXPECT_CALL(*client_a_, DoError(route_id)).Times(1); |
| 598 base::RunLoop().RunUntilIdle(); | 602 base::RunLoop().RunUntilIdle(); |
| 599 Mock::VerifyAndClearExpectations(client_a_.get()); | 603 Mock::VerifyAndClearExpectations(client_a_.get()); |
| 600 | 604 |
| 601 // Second client connects after the error state. It also should get told of | 605 // Second client connects after the error state. It also should get told of |
| 602 // the error. | 606 // the error. |
| 603 EXPECT_CALL(*client_b_, DoError(route_id)).Times(1); | 607 EXPECT_CALL(*client_b_, DoError(route_id)).Times(1); |
| 604 controller_->AddClient( | 608 controller_->AddClient( |
| 605 route_id, client_b_.get(), base::kNullProcessHandle, 200, session_200); | 609 route_id, client_b_.get(), base::kNullProcessHandle, 200, session_200); |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 702 EXPECT_EQ(coded_size.width(), size_and_rotation.output_resolution.width()); | 706 EXPECT_EQ(coded_size.width(), size_and_rotation.output_resolution.width()); |
| 703 EXPECT_EQ(coded_size.height(), | 707 EXPECT_EQ(coded_size.height(), |
| 704 size_and_rotation.output_resolution.height()); | 708 size_and_rotation.output_resolution.height()); |
| 705 | 709 |
| 706 EXPECT_EQ(kSessionId, controller_->RemoveClient(route_id, client_a_.get())); | 710 EXPECT_EQ(kSessionId, controller_->RemoveClient(route_id, client_a_.get())); |
| 707 Mock::VerifyAndClearExpectations(client_a_.get()); | 711 Mock::VerifyAndClearExpectations(client_a_.get()); |
| 708 } | 712 } |
| 709 } | 713 } |
| 710 | 714 |
| 711 } // namespace content | 715 } // namespace content |
| OLD | NEW |