| 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" |
| (...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 325 200, | 325 200, |
| 326 session_200); | 326 session_200); |
| 327 ASSERT_EQ(3, controller_->GetClientCount()); | 327 ASSERT_EQ(3, controller_->GetClientCount()); |
| 328 | 328 |
| 329 // Now, simulate an incoming captured buffer from the capture device. As a | 329 // Now, simulate an incoming captured buffer from the capture device. As a |
| 330 // side effect this will cause the first buffer to be shared with clients. | 330 // side effect this will cause the first buffer to be shared with clients. |
| 331 uint8 buffer_no = 1; | 331 uint8 buffer_no = 1; |
| 332 scoped_refptr<media::VideoCaptureDevice::Client::Buffer> buffer; | 332 scoped_refptr<media::VideoCaptureDevice::Client::Buffer> buffer; |
| 333 buffer = | 333 buffer = |
| 334 device_->ReserveOutputBuffer(media::VideoFrame::I420, capture_resolution); | 334 device_->ReserveOutputBuffer(media::VideoFrame::I420, capture_resolution); |
| 335 ASSERT_TRUE(buffer); | 335 ASSERT_TRUE(buffer.get()); |
| 336 memset(buffer->data(), buffer_no++, buffer->size()); | 336 memset(buffer->data(), buffer_no++, buffer->size()); |
| 337 { | 337 { |
| 338 InSequence s; | 338 InSequence s; |
| 339 EXPECT_CALL(*client_a_, DoBufferCreated(client_a_route_1)).Times(1); | 339 EXPECT_CALL(*client_a_, DoBufferCreated(client_a_route_1)).Times(1); |
| 340 EXPECT_CALL(*client_a_, DoBufferReady(client_a_route_1)).Times(1); | 340 EXPECT_CALL(*client_a_, DoBufferReady(client_a_route_1)).Times(1); |
| 341 } | 341 } |
| 342 { | 342 { |
| 343 InSequence s; | 343 InSequence s; |
| 344 EXPECT_CALL(*client_b_, DoBufferCreated(client_b_route_1)).Times(1); | 344 EXPECT_CALL(*client_b_, DoBufferCreated(client_b_route_1)).Times(1); |
| 345 EXPECT_CALL(*client_b_, DoBufferReady(client_b_route_1)).Times(1); | 345 EXPECT_CALL(*client_b_, DoBufferReady(client_b_route_1)).Times(1); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 360 | 360 |
| 361 base::RunLoop().RunUntilIdle(); | 361 base::RunLoop().RunUntilIdle(); |
| 362 Mock::VerifyAndClearExpectations(client_a_.get()); | 362 Mock::VerifyAndClearExpectations(client_a_.get()); |
| 363 Mock::VerifyAndClearExpectations(client_b_.get()); | 363 Mock::VerifyAndClearExpectations(client_b_.get()); |
| 364 | 364 |
| 365 // Second buffer which ought to use the same shared memory buffer. In this | 365 // Second buffer which ought to use the same shared memory buffer. In this |
| 366 // case pretend that the Buffer pointer is held by the device for a long | 366 // case pretend that the Buffer pointer is held by the device for a long |
| 367 // delay. This shouldn't affect anything. | 367 // delay. This shouldn't affect anything. |
| 368 buffer = | 368 buffer = |
| 369 device_->ReserveOutputBuffer(media::VideoFrame::I420, capture_resolution); | 369 device_->ReserveOutputBuffer(media::VideoFrame::I420, capture_resolution); |
| 370 ASSERT_TRUE(buffer); | 370 ASSERT_TRUE(buffer.get()); |
| 371 memset(buffer->data(), buffer_no++, buffer->size()); | 371 memset(buffer->data(), buffer_no++, buffer->size()); |
| 372 device_->OnIncomingCapturedVideoFrame( | 372 device_->OnIncomingCapturedVideoFrame( |
| 373 buffer, | 373 buffer, |
| 374 media::VideoCaptureFormat(capture_resolution, | 374 media::VideoCaptureFormat(capture_resolution, |
| 375 device_format.frame_rate, | 375 device_format.frame_rate, |
| 376 media::PIXEL_FORMAT_I420), | 376 media::PIXEL_FORMAT_I420), |
| 377 WrapI420Buffer(buffer, capture_resolution), | 377 WrapI420Buffer(buffer, capture_resolution), |
| 378 base::TimeTicks()); | 378 base::TimeTicks()); |
| 379 buffer = NULL; | 379 buffer = NULL; |
| 380 | 380 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 391 client_b_.get(), | 391 client_b_.get(), |
| 392 base::kNullProcessHandle, | 392 base::kNullProcessHandle, |
| 393 1, | 393 1, |
| 394 session_1); | 394 session_1); |
| 395 Mock::VerifyAndClearExpectations(client_b_.get()); | 395 Mock::VerifyAndClearExpectations(client_b_.get()); |
| 396 | 396 |
| 397 // Third, fourth, and fifth buffers. Pretend they all arrive at the same time. | 397 // Third, fourth, and fifth buffers. Pretend they all arrive at the same time. |
| 398 for (int i = 0; i < kPoolSize; i++) { | 398 for (int i = 0; i < kPoolSize; i++) { |
| 399 buffer = device_->ReserveOutputBuffer(media::VideoFrame::I420, | 399 buffer = device_->ReserveOutputBuffer(media::VideoFrame::I420, |
| 400 capture_resolution); | 400 capture_resolution); |
| 401 ASSERT_TRUE(buffer); | 401 ASSERT_TRUE(buffer.get()); |
| 402 memset(buffer->data(), buffer_no++, buffer->size()); | 402 memset(buffer->data(), buffer_no++, buffer->size()); |
| 403 device_->OnIncomingCapturedVideoFrame( | 403 device_->OnIncomingCapturedVideoFrame( |
| 404 buffer, | 404 buffer, |
| 405 media::VideoCaptureFormat(capture_resolution, | 405 media::VideoCaptureFormat(capture_resolution, |
| 406 device_format.frame_rate, | 406 device_format.frame_rate, |
| 407 media::PIXEL_FORMAT_I420), | 407 media::PIXEL_FORMAT_I420), |
| 408 WrapI420Buffer(buffer, capture_resolution), | 408 WrapI420Buffer(buffer, capture_resolution), |
| 409 base::TimeTicks()); | 409 base::TimeTicks()); |
| 410 buffer = NULL; | 410 buffer = NULL; |
| 411 } | 411 } |
| (...skipping 19 matching lines...) Expand all Loading... |
| 431 | 431 |
| 432 // Now test the interaction of client shutdown and buffer delivery. | 432 // Now test the interaction of client shutdown and buffer delivery. |
| 433 // Kill A1 via renderer disconnect (synchronous). | 433 // Kill A1 via renderer disconnect (synchronous). |
| 434 controller_->RemoveClient(client_a_route_1, client_a_.get()); | 434 controller_->RemoveClient(client_a_route_1, client_a_.get()); |
| 435 // Kill B1 via session close (posts a task to disconnect). | 435 // Kill B1 via session close (posts a task to disconnect). |
| 436 EXPECT_CALL(*client_b_, DoEnded(client_b_route_1)).Times(1); | 436 EXPECT_CALL(*client_b_, DoEnded(client_b_route_1)).Times(1); |
| 437 controller_->StopSession(300); | 437 controller_->StopSession(300); |
| 438 // Queue up another buffer. | 438 // Queue up another buffer. |
| 439 buffer = | 439 buffer = |
| 440 device_->ReserveOutputBuffer(media::VideoFrame::I420, capture_resolution); | 440 device_->ReserveOutputBuffer(media::VideoFrame::I420, capture_resolution); |
| 441 ASSERT_TRUE(buffer); | 441 ASSERT_TRUE(buffer.get()); |
| 442 memset(buffer->data(), buffer_no++, buffer->size()); | 442 memset(buffer->data(), buffer_no++, buffer->size()); |
| 443 device_->OnIncomingCapturedVideoFrame( | 443 device_->OnIncomingCapturedVideoFrame( |
| 444 buffer, | 444 buffer, |
| 445 media::VideoCaptureFormat(capture_resolution, | 445 media::VideoCaptureFormat(capture_resolution, |
| 446 device_format.frame_rate, | 446 device_format.frame_rate, |
| 447 media::PIXEL_FORMAT_I420), | 447 media::PIXEL_FORMAT_I420), |
| 448 WrapI420Buffer(buffer, capture_resolution), | 448 WrapI420Buffer(buffer, capture_resolution), |
| 449 base::TimeTicks()); | 449 base::TimeTicks()); |
| 450 buffer = NULL; | 450 buffer = NULL; |
| 451 buffer = | 451 buffer = |
| 452 device_->ReserveOutputBuffer(media::VideoFrame::I420, capture_resolution); | 452 device_->ReserveOutputBuffer(media::VideoFrame::I420, capture_resolution); |
| 453 { | 453 { |
| 454 // Kill A2 via session close (posts a task to disconnect, but A2 must not | 454 // Kill A2 via session close (posts a task to disconnect, but A2 must not |
| 455 // be sent either of these two buffers). | 455 // be sent either of these two buffers). |
| 456 EXPECT_CALL(*client_a_, DoEnded(client_a_route_2)).Times(1); | 456 EXPECT_CALL(*client_a_, DoEnded(client_a_route_2)).Times(1); |
| 457 controller_->StopSession(200); | 457 controller_->StopSession(200); |
| 458 } | 458 } |
| 459 ASSERT_TRUE(buffer); | 459 ASSERT_TRUE(buffer.get()); |
| 460 memset(buffer->data(), buffer_no++, buffer->size()); | 460 memset(buffer->data(), buffer_no++, buffer->size()); |
| 461 device_->OnIncomingCapturedVideoFrame( | 461 device_->OnIncomingCapturedVideoFrame( |
| 462 buffer, | 462 buffer, |
| 463 media::VideoCaptureFormat(capture_resolution, | 463 media::VideoCaptureFormat(capture_resolution, |
| 464 device_format.frame_rate, | 464 device_format.frame_rate, |
| 465 media::PIXEL_FORMAT_I420), | 465 media::PIXEL_FORMAT_I420), |
| 466 WrapI420Buffer(buffer, capture_resolution), | 466 WrapI420Buffer(buffer, capture_resolution), |
| 467 base::TimeTicks()); | 467 base::TimeTicks()); |
| 468 buffer = NULL; | 468 buffer = NULL; |
| 469 // B2 is the only client left, and is the only one that should | 469 // B2 is the only client left, and is the only one that should |
| 470 // get the buffer. | 470 // get the buffer. |
| 471 EXPECT_CALL(*client_b_, DoBufferReady(client_b_route_2)).Times(2); | 471 EXPECT_CALL(*client_b_, DoBufferReady(client_b_route_2)).Times(2); |
| 472 base::RunLoop().RunUntilIdle(); | 472 base::RunLoop().RunUntilIdle(); |
| 473 Mock::VerifyAndClearExpectations(client_a_.get()); | 473 Mock::VerifyAndClearExpectations(client_a_.get()); |
| 474 Mock::VerifyAndClearExpectations(client_b_.get()); | 474 Mock::VerifyAndClearExpectations(client_b_.get()); |
| 475 | 475 |
| 476 // Allocate all buffers from the buffer pool, half as SHM buffer and half as | 476 // Allocate all buffers from the buffer pool, half as SHM buffer and half as |
| 477 // mailbox buffers. Make sure of different counts though. | 477 // mailbox buffers. Make sure of different counts though. |
| 478 int shm_buffers = kPoolSize / 2; | 478 int shm_buffers = kPoolSize / 2; |
| 479 int mailbox_buffers = kPoolSize - shm_buffers; | 479 int mailbox_buffers = kPoolSize - shm_buffers; |
| 480 if (shm_buffers == mailbox_buffers) { | 480 if (shm_buffers == mailbox_buffers) { |
| 481 shm_buffers--; | 481 shm_buffers--; |
| 482 mailbox_buffers++; | 482 mailbox_buffers++; |
| 483 } | 483 } |
| 484 | 484 |
| 485 for (int i = 0; i < shm_buffers; ++i) { | 485 for (int i = 0; i < shm_buffers; ++i) { |
| 486 buffer = device_->ReserveOutputBuffer(media::VideoFrame::I420, | 486 buffer = device_->ReserveOutputBuffer(media::VideoFrame::I420, |
| 487 capture_resolution); | 487 capture_resolution); |
| 488 ASSERT_TRUE(buffer); | 488 ASSERT_TRUE(buffer.get()); |
| 489 device_->OnIncomingCapturedVideoFrame( | 489 device_->OnIncomingCapturedVideoFrame( |
| 490 buffer, | 490 buffer, |
| 491 media::VideoCaptureFormat(capture_resolution, | 491 media::VideoCaptureFormat(capture_resolution, |
| 492 device_format.frame_rate, | 492 device_format.frame_rate, |
| 493 media::PIXEL_FORMAT_I420), | 493 media::PIXEL_FORMAT_I420), |
| 494 WrapI420Buffer(buffer, capture_resolution), | 494 WrapI420Buffer(buffer, capture_resolution), |
| 495 base::TimeTicks()); | 495 base::TimeTicks()); |
| 496 buffer = NULL; | 496 buffer = NULL; |
| 497 } | 497 } |
| 498 std::vector<uint32> mailbox_syncpoints(mailbox_buffers); | 498 std::vector<uint32> mailbox_syncpoints(mailbox_buffers); |
| 499 std::vector<uint32> release_syncpoints(mailbox_buffers); | 499 std::vector<uint32> release_syncpoints(mailbox_buffers); |
| 500 #if defined(OS_ANDROID) | 500 #if defined(OS_ANDROID) |
| 501 GLHelper* gl_helper = | 501 GLHelper* gl_helper = |
| 502 ImageTransportFactoryAndroid::GetInstance()->GetGLHelper(); | 502 ImageTransportFactoryAndroid::GetInstance()->GetGLHelper(); |
| 503 #else | 503 #else |
| 504 GLHelper* gl_helper = ImageTransportFactory::GetInstance()->GetGLHelper(); | 504 GLHelper* gl_helper = ImageTransportFactory::GetInstance()->GetGLHelper(); |
| 505 #endif | 505 #endif |
| 506 for (int i = 0; i < mailbox_buffers; ++i) { | 506 for (int i = 0; i < mailbox_buffers; ++i) { |
| 507 buffer = device_->ReserveOutputBuffer(media::VideoFrame::NATIVE_TEXTURE, | 507 buffer = device_->ReserveOutputBuffer(media::VideoFrame::NATIVE_TEXTURE, |
| 508 gfx::Size(0, 0)); | 508 gfx::Size(0, 0)); |
| 509 ASSERT_TRUE(buffer); | 509 ASSERT_TRUE(buffer.get()); |
| 510 mailbox_syncpoints[i] = gl_helper->InsertSyncPoint(); | 510 mailbox_syncpoints[i] = gl_helper->InsertSyncPoint(); |
| 511 device_->OnIncomingCapturedVideoFrame( | 511 device_->OnIncomingCapturedVideoFrame( |
| 512 buffer, | 512 buffer, |
| 513 media::VideoCaptureFormat(capture_resolution, | 513 media::VideoCaptureFormat(capture_resolution, |
| 514 device_format.frame_rate, | 514 device_format.frame_rate, |
| 515 media::PIXEL_FORMAT_TEXTURE), | 515 media::PIXEL_FORMAT_TEXTURE), |
| 516 WrapMailboxBuffer(buffer, | 516 WrapMailboxBuffer(buffer, |
| 517 make_scoped_ptr(new gpu::MailboxHolder( | 517 make_scoped_ptr(new gpu::MailboxHolder( |
| 518 gpu::Mailbox(), 0, mailbox_syncpoints[i])), | 518 gpu::Mailbox(), 0, mailbox_syncpoints[i])), |
| 519 base::Bind(&CacheSyncPoint, &release_syncpoints[i]), | 519 base::Bind(&CacheSyncPoint, &release_syncpoints[i]), |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 571 // Second client connects after the error state. It also should get told of | 571 // Second client connects after the error state. It also should get told of |
| 572 // the error. | 572 // the error. |
| 573 EXPECT_CALL(*client_b_, DoError(route_id)).Times(1); | 573 EXPECT_CALL(*client_b_, DoError(route_id)).Times(1); |
| 574 controller_->AddClient( | 574 controller_->AddClient( |
| 575 route_id, client_b_.get(), base::kNullProcessHandle, 200, session_200); | 575 route_id, client_b_.get(), base::kNullProcessHandle, 200, session_200); |
| 576 base::RunLoop().RunUntilIdle(); | 576 base::RunLoop().RunUntilIdle(); |
| 577 Mock::VerifyAndClearExpectations(client_b_.get()); | 577 Mock::VerifyAndClearExpectations(client_b_.get()); |
| 578 | 578 |
| 579 scoped_refptr<media::VideoCaptureDevice::Client::Buffer> buffer = | 579 scoped_refptr<media::VideoCaptureDevice::Client::Buffer> buffer = |
| 580 device_->ReserveOutputBuffer(media::VideoFrame::I420, capture_resolution); | 580 device_->ReserveOutputBuffer(media::VideoFrame::I420, capture_resolution); |
| 581 ASSERT_TRUE(buffer); | 581 ASSERT_TRUE(buffer.get()); |
| 582 | 582 |
| 583 device_->OnIncomingCapturedVideoFrame( | 583 device_->OnIncomingCapturedVideoFrame( |
| 584 buffer, | 584 buffer, |
| 585 media::VideoCaptureFormat( | 585 media::VideoCaptureFormat( |
| 586 capture_resolution, 30, media::PIXEL_FORMAT_I420), | 586 capture_resolution, 30, media::PIXEL_FORMAT_I420), |
| 587 WrapI420Buffer(buffer, capture_resolution), | 587 WrapI420Buffer(buffer, capture_resolution), |
| 588 base::TimeTicks()); | 588 base::TimeTicks()); |
| 589 buffer = NULL; | 589 buffer = NULL; |
| 590 | 590 |
| 591 base::RunLoop().RunUntilIdle(); | 591 base::RunLoop().RunUntilIdle(); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 610 | 610 |
| 611 // Start the device. Then, before the first buffer, signal an error and | 611 // Start the device. Then, before the first buffer, signal an error and |
| 612 // deliver the buffer. The error should be propagated to clients; the buffer | 612 // deliver the buffer. The error should be propagated to clients; the buffer |
| 613 // should not be. | 613 // should not be. |
| 614 base::RunLoop().RunUntilIdle(); | 614 base::RunLoop().RunUntilIdle(); |
| 615 Mock::VerifyAndClearExpectations(client_a_.get()); | 615 Mock::VerifyAndClearExpectations(client_a_.get()); |
| 616 | 616 |
| 617 const gfx::Size dims(320, 240); | 617 const gfx::Size dims(320, 240); |
| 618 scoped_refptr<media::VideoCaptureDevice::Client::Buffer> buffer = | 618 scoped_refptr<media::VideoCaptureDevice::Client::Buffer> buffer = |
| 619 device_->ReserveOutputBuffer(media::VideoFrame::I420, dims); | 619 device_->ReserveOutputBuffer(media::VideoFrame::I420, dims); |
| 620 ASSERT_TRUE(buffer); | 620 ASSERT_TRUE(buffer.get()); |
| 621 | 621 |
| 622 device_->OnError("Test error"); | 622 device_->OnError("Test error"); |
| 623 device_->OnIncomingCapturedVideoFrame( | 623 device_->OnIncomingCapturedVideoFrame( |
| 624 buffer, | 624 buffer, |
| 625 media::VideoCaptureFormat( | 625 media::VideoCaptureFormat( |
| 626 dims, device_format.frame_rate, media::PIXEL_FORMAT_I420), | 626 dims, device_format.frame_rate, media::PIXEL_FORMAT_I420), |
| 627 WrapI420Buffer(buffer, dims), | 627 WrapI420Buffer(buffer, dims), |
| 628 base::TimeTicks()); | 628 base::TimeTicks()); |
| 629 buffer = NULL; | 629 buffer = NULL; |
| 630 | 630 |
| 631 EXPECT_CALL(*client_a_, DoError(route_id)).Times(1); | 631 EXPECT_CALL(*client_a_, DoError(route_id)).Times(1); |
| 632 base::RunLoop().RunUntilIdle(); | 632 base::RunLoop().RunUntilIdle(); |
| 633 Mock::VerifyAndClearExpectations(client_a_.get()); | 633 Mock::VerifyAndClearExpectations(client_a_.get()); |
| 634 | 634 |
| 635 // Second client connects after the error state. It also should get told of | 635 // Second client connects after the error state. It also should get told of |
| 636 // the error. | 636 // the error. |
| 637 EXPECT_CALL(*client_b_, DoError(route_id)).Times(1); | 637 EXPECT_CALL(*client_b_, DoError(route_id)).Times(1); |
| 638 controller_->AddClient( | 638 controller_->AddClient( |
| 639 route_id, client_b_.get(), base::kNullProcessHandle, 200, session_200); | 639 route_id, client_b_.get(), base::kNullProcessHandle, 200, session_200); |
| 640 Mock::VerifyAndClearExpectations(client_b_.get()); | 640 Mock::VerifyAndClearExpectations(client_b_.get()); |
| 641 } | 641 } |
| 642 | 642 |
| 643 } // namespace content | 643 } // namespace content |
| OLD | NEW |