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