| 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 std::map<uintptr_t, uint32>())); |
| 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 std::map<uintptr_t, uint32> release_sync_points; |
| 83 release_sync_points.push_back(~mailbox_holder.sync_point); | 83 release_sync_points[0x111] = ~mailbox_holder.sync_point; |
| 84 release_sync_points[0x222] = mailbox_holder.sync_point; |
| 84 base::MessageLoop::current()->PostTask( | 85 base::MessageLoop::current()->PostTask( |
| 85 FROM_HERE, | 86 FROM_HERE, |
| 86 base::Bind(&VideoCaptureController::ReturnBuffer, | 87 base::Bind(&VideoCaptureController::ReturnBuffer, |
| 87 base::Unretained(controller_), | 88 base::Unretained(controller_), |
| 88 id, | 89 id, |
| 89 this, | 90 this, |
| 90 buffer_id, | 91 buffer_id, |
| 91 release_sync_points)); | 92 release_sync_points)); |
| 92 } | 93 } |
| 93 virtual void OnEnded(const VideoCaptureControllerID& id) OVERRIDE { | 94 virtual void OnEnded(const VideoCaptureControllerID& id) OVERRIDE { |
| (...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 256 ASSERT_EQ(1, controller_->GetClientCount()) | 257 ASSERT_EQ(1, controller_->GetClientCount()) |
| 257 << "Removing non-existant session 200 should be a no-op."; | 258 << "Removing non-existant session 200 should be a no-op."; |
| 258 ASSERT_EQ(400, | 259 ASSERT_EQ(400, |
| 259 controller_->RemoveClient(client_b_route_2, client_b_.get())) | 260 controller_->RemoveClient(client_b_route_2, client_b_.get())) |
| 260 << "Removing client B/2 should return its session_id."; | 261 << "Removing client B/2 should return its session_id."; |
| 261 // Clients in controller: [] | 262 // Clients in controller: [] |
| 262 ASSERT_EQ(0, controller_->GetClientCount()) | 263 ASSERT_EQ(0, controller_->GetClientCount()) |
| 263 << "Client count should return to zero after all clients are gone."; | 264 << "Client count should return to zero after all clients are gone."; |
| 264 } | 265 } |
| 265 | 266 |
| 266 static void CacheSyncPoint(std::vector<uint32>* called_release_sync_points, | 267 static void CacheSyncPoint( |
| 267 const std::vector<uint32>& release_sync_points) { | 268 std::map<uintptr_t, uint32>* called_release_sync_points, |
| 269 const std::map<uintptr_t, uint32>& release_sync_points) { |
| 268 DCHECK(called_release_sync_points->empty()); | 270 DCHECK(called_release_sync_points->empty()); |
| 269 called_release_sync_points->assign(release_sync_points.begin(), | 271 for (std::map<uintptr_t, uint32>::const_iterator iter = |
| 270 release_sync_points.end()); | 272 release_sync_points.begin(); |
| 273 iter != release_sync_points.end(); |
| 274 iter++) { |
| 275 EXPECT_TRUE(called_release_sync_points->insert(std::make_pair(iter->first, |
| 276 iter->second)) |
| 277 .second); |
| 278 } |
| 271 } | 279 } |
| 272 | 280 |
| 273 // This test will connect and disconnect several clients while simulating an | 281 // This test will connect and disconnect several clients while simulating an |
| 274 // active capture device being started and generating frames. It runs on one | 282 // active capture device being started and generating frames. It runs on one |
| 275 // thread and is intended to behave deterministically. | 283 // thread and is intended to behave deterministically. |
| 276 TEST_F(VideoCaptureControllerTest, NormalCaptureMultipleClients) { | 284 TEST_F(VideoCaptureControllerTest, NormalCaptureMultipleClients) { |
| 277 media::VideoCaptureParams session_100; | 285 media::VideoCaptureParams session_100; |
| 278 session_100.requested_format = media::VideoCaptureFormat( | 286 session_100.requested_format = media::VideoCaptureFormat( |
| 279 gfx::Size(320, 240), 30, media::PIXEL_FORMAT_I420); | 287 gfx::Size(320, 240), 30, media::PIXEL_FORMAT_I420); |
| 280 | 288 |
| (...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 477 device_->OnIncomingCapturedVideoFrame( | 485 device_->OnIncomingCapturedVideoFrame( |
| 478 buffer, | 486 buffer, |
| 479 media::VideoCaptureFormat(capture_resolution, | 487 media::VideoCaptureFormat(capture_resolution, |
| 480 device_format.frame_rate, | 488 device_format.frame_rate, |
| 481 media::PIXEL_FORMAT_I420), | 489 media::PIXEL_FORMAT_I420), |
| 482 WrapI420Buffer(buffer, capture_resolution), | 490 WrapI420Buffer(buffer, capture_resolution), |
| 483 base::TimeTicks()); | 491 base::TimeTicks()); |
| 484 buffer = NULL; | 492 buffer = NULL; |
| 485 } | 493 } |
| 486 std::vector<uint32> mailbox_syncpoints(mailbox_buffers); | 494 std::vector<uint32> mailbox_syncpoints(mailbox_buffers); |
| 487 std::vector<std::vector<uint32> > release_syncpoint_vectors(mailbox_buffers); | 495 std::vector<std::map<uintptr_t, uint32> > release_syncpoint_vectors( |
| 496 mailbox_buffers); |
| 488 for (int i = 0; i < mailbox_buffers; ++i) { | 497 for (int i = 0; i < mailbox_buffers; ++i) { |
| 489 buffer = device_->ReserveOutputBuffer(media::VideoFrame::NATIVE_TEXTURE, | 498 buffer = device_->ReserveOutputBuffer(media::VideoFrame::NATIVE_TEXTURE, |
| 490 gfx::Size(0, 0)); | 499 gfx::Size(0, 0)); |
| 491 ASSERT_TRUE(buffer); | 500 ASSERT_TRUE(buffer); |
| 492 mailbox_syncpoints[i] = i; | 501 mailbox_syncpoints[i] = i + 1; |
| 493 device_->OnIncomingCapturedVideoFrame( | 502 device_->OnIncomingCapturedVideoFrame( |
| 494 buffer, | 503 buffer, |
| 495 media::VideoCaptureFormat(capture_resolution, | 504 media::VideoCaptureFormat(capture_resolution, |
| 496 device_format.frame_rate, | 505 device_format.frame_rate, |
| 497 media::PIXEL_FORMAT_TEXTURE), | 506 media::PIXEL_FORMAT_TEXTURE), |
| 498 WrapMailboxBuffer( | 507 WrapMailboxBuffer( |
| 499 buffer, | 508 buffer, |
| 500 make_scoped_ptr(new gpu::MailboxHolder( | 509 make_scoped_ptr(new gpu::MailboxHolder( |
| 501 gpu::Mailbox(), 0, mailbox_syncpoints[i])), | 510 gpu::Mailbox(), 0, mailbox_syncpoints[i])), |
| 502 base::Bind(&CacheSyncPoint, &release_syncpoint_vectors[i]), | 511 base::Bind(&CacheSyncPoint, &release_syncpoint_vectors[i]), |
| 503 capture_resolution), | 512 capture_resolution), |
| 504 base::TimeTicks()); | 513 base::TimeTicks()); |
| 505 buffer = NULL; | 514 buffer = NULL; |
| 506 } | 515 } |
| 507 // ReserveOutputBuffers ought to fail now regardless of buffer format, because | 516 // ReserveOutputBuffers ought to fail now regardless of buffer format, because |
| 508 // the pool is depleted. | 517 // the pool is depleted. |
| 509 ASSERT_FALSE(device_->ReserveOutputBuffer(media::VideoFrame::I420, | 518 ASSERT_FALSE(device_->ReserveOutputBuffer(media::VideoFrame::I420, |
| 510 capture_resolution)); | 519 capture_resolution)); |
| 511 ASSERT_FALSE(device_->ReserveOutputBuffer(media::VideoFrame::NATIVE_TEXTURE, | 520 ASSERT_FALSE(device_->ReserveOutputBuffer(media::VideoFrame::NATIVE_TEXTURE, |
| 512 gfx::Size(0, 0))); | 521 gfx::Size(0, 0))); |
| 513 EXPECT_CALL(*client_b_, DoBufferReady(client_b_route_2)).Times(shm_buffers); | 522 EXPECT_CALL(*client_b_, DoBufferReady(client_b_route_2)).Times(shm_buffers); |
| 514 EXPECT_CALL(*client_b_, DoMailboxBufferReady(client_b_route_2)) | 523 EXPECT_CALL(*client_b_, DoMailboxBufferReady(client_b_route_2)) |
| 515 .Times(mailbox_buffers); | 524 .Times(mailbox_buffers); |
| 516 base::RunLoop().RunUntilIdle(); | 525 base::RunLoop().RunUntilIdle(); |
| 517 for (size_t i = 0; i < mailbox_syncpoints.size(); ++i) { | 526 for (size_t i = 0; i < mailbox_syncpoints.size(); ++i) { |
| 518 // See: MockVideoCaptureControllerEventHandler::OnMailboxBufferReady() | 527 // See: MockVideoCaptureControllerEventHandler::OnMailboxBufferReady() |
| 519 ASSERT_EQ(1u, release_syncpoint_vectors[i].size()); | 528 ASSERT_EQ(2u, release_syncpoint_vectors[i].size()); |
| 520 ASSERT_EQ(mailbox_syncpoints[i], ~release_syncpoint_vectors[i][0]); | 529 ASSERT_EQ(mailbox_syncpoints[i], ~release_syncpoint_vectors[i].at(0x111)); |
| 530 ASSERT_EQ(mailbox_syncpoints[i], release_syncpoint_vectors[i].at(0x222)); |
| 521 } | 531 } |
| 522 Mock::VerifyAndClearExpectations(client_b_.get()); | 532 Mock::VerifyAndClearExpectations(client_b_.get()); |
| 523 } | 533 } |
| 524 | 534 |
| 525 // Exercises the OnError() codepath of VideoCaptureController, and tests the | 535 // Exercises the OnError() codepath of VideoCaptureController, and tests the |
| 526 // behavior of various operations after the error state has been signalled. | 536 // behavior of various operations after the error state has been signalled. |
| 527 TEST_F(VideoCaptureControllerTest, ErrorBeforeDeviceCreation) { | 537 TEST_F(VideoCaptureControllerTest, ErrorBeforeDeviceCreation) { |
| 528 media::VideoCaptureParams session_100; | 538 media::VideoCaptureParams session_100; |
| 529 session_100.requested_format = media::VideoCaptureFormat( | 539 session_100.requested_format = media::VideoCaptureFormat( |
| 530 gfx::Size(320, 240), 30, media::PIXEL_FORMAT_I420); | 540 gfx::Size(320, 240), 30, media::PIXEL_FORMAT_I420); |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 609 | 619 |
| 610 // Second client connects after the error state. It also should get told of | 620 // Second client connects after the error state. It also should get told of |
| 611 // the error. | 621 // the error. |
| 612 EXPECT_CALL(*client_b_, DoError(route_id)).Times(1); | 622 EXPECT_CALL(*client_b_, DoError(route_id)).Times(1); |
| 613 controller_->AddClient( | 623 controller_->AddClient( |
| 614 route_id, client_b_.get(), base::kNullProcessHandle, 200, session_200); | 624 route_id, client_b_.get(), base::kNullProcessHandle, 200, session_200); |
| 615 Mock::VerifyAndClearExpectations(client_b_.get()); | 625 Mock::VerifyAndClearExpectations(client_b_.get()); |
| 616 } | 626 } |
| 617 | 627 |
| 618 } // namespace content | 628 } // namespace content |
| OLD | NEW |