| 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 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 63 const media::VideoCaptureFormat& format, | 63 const media::VideoCaptureFormat& format, |
| 64 base::TimeTicks timestamp) OVERRIDE { | 64 base::TimeTicks timestamp) OVERRIDE { |
| 65 DoBufferReady(id); | 65 DoBufferReady(id); |
| 66 base::MessageLoop::current()->PostTask( | 66 base::MessageLoop::current()->PostTask( |
| 67 FROM_HERE, | 67 FROM_HERE, |
| 68 base::Bind(&VideoCaptureController::ReturnBuffer, | 68 base::Bind(&VideoCaptureController::ReturnBuffer, |
| 69 base::Unretained(controller_), | 69 base::Unretained(controller_), |
| 70 id, | 70 id, |
| 71 this, | 71 this, |
| 72 buffer_id, | 72 buffer_id, |
| 73 std::vector<uint32>())); | 73 0)); |
| 74 } | 74 } |
| 75 virtual void OnMailboxBufferReady(const VideoCaptureControllerID& id, | 75 virtual void OnMailboxBufferReady(const VideoCaptureControllerID& id, |
| 76 int buffer_id, | 76 int buffer_id, |
| 77 const gpu::MailboxHolder& mailbox_holder, | 77 const gpu::MailboxHolder& mailbox_holder, |
| 78 const media::VideoCaptureFormat& format, | 78 const media::VideoCaptureFormat& format, |
| 79 base::TimeTicks timestamp) OVERRIDE { | 79 base::TimeTicks timestamp) OVERRIDE { |
| 80 DoMailboxBufferReady(id); | 80 DoMailboxBufferReady(id); |
| 81 // Use a very different syncpoint value when returning a new syncpoint. | 81 // Use a very different syncpoint value when returning a new syncpoint. |
| 82 std::vector<uint32> release_sync_points; | 82 uint32 release_sync_point = ~mailbox_holder.sync_point; |
| 83 release_sync_points.push_back(~mailbox_holder.sync_point); | |
| 84 base::MessageLoop::current()->PostTask( | 83 base::MessageLoop::current()->PostTask( |
| 85 FROM_HERE, | 84 FROM_HERE, |
| 86 base::Bind(&VideoCaptureController::ReturnBuffer, | 85 base::Bind(&VideoCaptureController::ReturnBuffer, |
| 87 base::Unretained(controller_), | 86 base::Unretained(controller_), |
| 88 id, | 87 id, |
| 89 this, | 88 this, |
| 90 buffer_id, | 89 buffer_id, |
| 91 release_sync_points)); | 90 release_sync_point)); |
| 92 } | 91 } |
| 93 virtual void OnEnded(const VideoCaptureControllerID& id) OVERRIDE { | 92 virtual void OnEnded(const VideoCaptureControllerID& id) OVERRIDE { |
| 94 DoEnded(id); | 93 DoEnded(id); |
| 95 // OnEnded() must respond by (eventually) unregistering the client. | 94 // OnEnded() must respond by (eventually) unregistering the client. |
| 96 base::MessageLoop::current()->PostTask(FROM_HERE, | 95 base::MessageLoop::current()->PostTask(FROM_HERE, |
| 97 base::Bind(base::IgnoreResult(&VideoCaptureController::RemoveClient), | 96 base::Bind(base::IgnoreResult(&VideoCaptureController::RemoveClient), |
| 98 base::Unretained(controller_), id, this)); | 97 base::Unretained(controller_), id, this)); |
| 99 } | 98 } |
| 100 | 99 |
| 101 VideoCaptureController* controller_; | 100 VideoCaptureController* controller_; |
| (...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 256 ASSERT_EQ(1, controller_->GetClientCount()) | 255 ASSERT_EQ(1, controller_->GetClientCount()) |
| 257 << "Removing non-existant session 200 should be a no-op."; | 256 << "Removing non-existant session 200 should be a no-op."; |
| 258 ASSERT_EQ(400, | 257 ASSERT_EQ(400, |
| 259 controller_->RemoveClient(client_b_route_2, client_b_.get())) | 258 controller_->RemoveClient(client_b_route_2, client_b_.get())) |
| 260 << "Removing client B/2 should return its session_id."; | 259 << "Removing client B/2 should return its session_id."; |
| 261 // Clients in controller: [] | 260 // Clients in controller: [] |
| 262 ASSERT_EQ(0, controller_->GetClientCount()) | 261 ASSERT_EQ(0, controller_->GetClientCount()) |
| 263 << "Client count should return to zero after all clients are gone."; | 262 << "Client count should return to zero after all clients are gone."; |
| 264 } | 263 } |
| 265 | 264 |
| 266 static void CacheSyncPoint(std::vector<uint32>* called_release_sync_points, | 265 static void CacheSyncPoint(uint32* called_release_sync_point, |
| 267 const std::vector<uint32>& release_sync_points) { | 266 uint32 release_sync_point) { |
| 268 DCHECK(called_release_sync_points->empty()); | 267 *called_release_sync_point = release_sync_point; |
| 269 called_release_sync_points->assign(release_sync_points.begin(), | |
| 270 release_sync_points.end()); | |
| 271 } | 268 } |
| 272 | 269 |
| 273 // This test will connect and disconnect several clients while simulating an | 270 // This test will connect and disconnect several clients while simulating an |
| 274 // active capture device being started and generating frames. It runs on one | 271 // active capture device being started and generating frames. It runs on one |
| 275 // thread and is intended to behave deterministically. | 272 // thread and is intended to behave deterministically. |
| 276 TEST_F(VideoCaptureControllerTest, NormalCaptureMultipleClients) { | 273 TEST_F(VideoCaptureControllerTest, NormalCaptureMultipleClients) { |
| 277 media::VideoCaptureParams session_100; | 274 media::VideoCaptureParams session_100; |
| 278 session_100.requested_format = media::VideoCaptureFormat( | 275 session_100.requested_format = media::VideoCaptureFormat( |
| 279 gfx::Size(320, 240), 30, media::PIXEL_FORMAT_I420); | 276 gfx::Size(320, 240), 30, media::PIXEL_FORMAT_I420); |
| 280 | 277 |
| (...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 477 device_->OnIncomingCapturedVideoFrame( | 474 device_->OnIncomingCapturedVideoFrame( |
| 478 buffer, | 475 buffer, |
| 479 media::VideoCaptureFormat(capture_resolution, | 476 media::VideoCaptureFormat(capture_resolution, |
| 480 device_format.frame_rate, | 477 device_format.frame_rate, |
| 481 media::PIXEL_FORMAT_I420), | 478 media::PIXEL_FORMAT_I420), |
| 482 WrapI420Buffer(buffer, capture_resolution), | 479 WrapI420Buffer(buffer, capture_resolution), |
| 483 base::TimeTicks()); | 480 base::TimeTicks()); |
| 484 buffer = NULL; | 481 buffer = NULL; |
| 485 } | 482 } |
| 486 std::vector<uint32> mailbox_syncpoints(mailbox_buffers); | 483 std::vector<uint32> mailbox_syncpoints(mailbox_buffers); |
| 487 std::vector<std::vector<uint32> > release_syncpoint_vectors(mailbox_buffers); | 484 std::vector<uint32> release_syncpoint_vectors(mailbox_buffers); |
| 488 for (int i = 0; i < mailbox_buffers; ++i) { | 485 for (int i = 0; i < mailbox_buffers; ++i) { |
| 489 buffer = device_->ReserveOutputBuffer(media::VideoFrame::NATIVE_TEXTURE, | 486 buffer = device_->ReserveOutputBuffer(media::VideoFrame::NATIVE_TEXTURE, |
| 490 gfx::Size(0, 0)); | 487 gfx::Size(0, 0)); |
| 491 ASSERT_TRUE(buffer); | 488 ASSERT_TRUE(buffer); |
| 492 mailbox_syncpoints[i] = i; | 489 mailbox_syncpoints[i] = i + 1; |
| 493 device_->OnIncomingCapturedVideoFrame( | 490 device_->OnIncomingCapturedVideoFrame( |
| 494 buffer, | 491 buffer, |
| 495 media::VideoCaptureFormat(capture_resolution, | 492 media::VideoCaptureFormat(capture_resolution, |
| 496 device_format.frame_rate, | 493 device_format.frame_rate, |
| 497 media::PIXEL_FORMAT_TEXTURE), | 494 media::PIXEL_FORMAT_TEXTURE), |
| 498 WrapMailboxBuffer( | 495 WrapMailboxBuffer( |
| 499 buffer, | 496 buffer, |
| 500 make_scoped_ptr(new gpu::MailboxHolder( | 497 make_scoped_ptr(new gpu::MailboxHolder( |
| 501 gpu::Mailbox(), 0, mailbox_syncpoints[i])), | 498 gpu::Mailbox(), 0, mailbox_syncpoints[i])), |
| 502 base::Bind(&CacheSyncPoint, &release_syncpoint_vectors[i]), | 499 base::Bind(&CacheSyncPoint, &release_syncpoint_vectors[i]), |
| 503 capture_resolution), | 500 capture_resolution), |
| 504 base::TimeTicks()); | 501 base::TimeTicks()); |
| 505 buffer = NULL; | 502 buffer = NULL; |
| 506 } | 503 } |
| 507 // ReserveOutputBuffers ought to fail now regardless of buffer format, because | 504 // ReserveOutputBuffers ought to fail now regardless of buffer format, because |
| 508 // the pool is depleted. | 505 // the pool is depleted. |
| 509 ASSERT_FALSE(device_->ReserveOutputBuffer(media::VideoFrame::I420, | 506 ASSERT_FALSE(device_->ReserveOutputBuffer(media::VideoFrame::I420, |
| 510 capture_resolution)); | 507 capture_resolution)); |
| 511 ASSERT_FALSE(device_->ReserveOutputBuffer(media::VideoFrame::NATIVE_TEXTURE, | 508 ASSERT_FALSE(device_->ReserveOutputBuffer(media::VideoFrame::NATIVE_TEXTURE, |
| 512 gfx::Size(0, 0))); | 509 gfx::Size(0, 0))); |
| 513 EXPECT_CALL(*client_b_, DoBufferReady(client_b_route_2)).Times(shm_buffers); | 510 EXPECT_CALL(*client_b_, DoBufferReady(client_b_route_2)).Times(shm_buffers); |
| 514 EXPECT_CALL(*client_b_, DoMailboxBufferReady(client_b_route_2)) | 511 EXPECT_CALL(*client_b_, DoMailboxBufferReady(client_b_route_2)) |
| 515 .Times(mailbox_buffers); | 512 .Times(mailbox_buffers); |
| 516 base::RunLoop().RunUntilIdle(); | 513 base::RunLoop().RunUntilIdle(); |
| 517 for (size_t i = 0; i < mailbox_syncpoints.size(); ++i) { | 514 for (size_t i = 0; i < mailbox_syncpoints.size(); ++i) { |
| 518 // See: MockVideoCaptureControllerEventHandler::OnMailboxBufferReady() | 515 // See: MockVideoCaptureControllerEventHandler::OnMailboxBufferReady() |
| 519 ASSERT_EQ(1u, release_syncpoint_vectors[i].size()); | 516 ASSERT_EQ(mailbox_syncpoints[i], ~release_syncpoint_vectors[i]); |
| 520 ASSERT_EQ(mailbox_syncpoints[i], ~release_syncpoint_vectors[i][0]); | |
| 521 } | 517 } |
| 522 Mock::VerifyAndClearExpectations(client_b_.get()); | 518 Mock::VerifyAndClearExpectations(client_b_.get()); |
| 523 } | 519 } |
| 524 | 520 |
| 525 // Exercises the OnError() codepath of VideoCaptureController, and tests the | 521 // Exercises the OnError() codepath of VideoCaptureController, and tests the |
| 526 // behavior of various operations after the error state has been signalled. | 522 // behavior of various operations after the error state has been signalled. |
| 527 TEST_F(VideoCaptureControllerTest, ErrorBeforeDeviceCreation) { | 523 TEST_F(VideoCaptureControllerTest, ErrorBeforeDeviceCreation) { |
| 528 media::VideoCaptureParams session_100; | 524 media::VideoCaptureParams session_100; |
| 529 session_100.requested_format = media::VideoCaptureFormat( | 525 session_100.requested_format = media::VideoCaptureFormat( |
| 530 gfx::Size(320, 240), 30, media::PIXEL_FORMAT_I420); | 526 gfx::Size(320, 240), 30, media::PIXEL_FORMAT_I420); |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 609 | 605 |
| 610 // Second client connects after the error state. It also should get told of | 606 // Second client connects after the error state. It also should get told of |
| 611 // the error. | 607 // the error. |
| 612 EXPECT_CALL(*client_b_, DoError(route_id)).Times(1); | 608 EXPECT_CALL(*client_b_, DoError(route_id)).Times(1); |
| 613 controller_->AddClient( | 609 controller_->AddClient( |
| 614 route_id, client_b_.get(), base::kNullProcessHandle, 200, session_200); | 610 route_id, client_b_.get(), base::kNullProcessHandle, 200, session_200); |
| 615 Mock::VerifyAndClearExpectations(client_b_.get()); | 611 Mock::VerifyAndClearExpectations(client_b_.get()); |
| 616 } | 612 } |
| 617 | 613 |
| 618 } // namespace content | 614 } // namespace content |
| OLD | NEW |