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(std::vector<uint32>* called_release_sync_points, |
266 scoped_ptr<gpu::MailboxHolder> mailbox_holder) { | 267 const std::vector<uint32>& release_sync_points) { |
267 *sync_value = mailbox_holder->sync_point; | 268 std::vector<uint32> sync_points(release_sync_points); |
269 called_release_sync_points->swap(sync_points); | |
Ami GONE FROM CHROMIUM
2014/04/11 20:55:17
nit: ditto comment elsewhere personally I find cle
dshwang
2014/04/22 19:16:51
Done.
| |
268 } | 270 } |
269 | 271 |
270 // This test will connect and disconnect several clients while simulating an | 272 // This test will connect and disconnect several clients while simulating an |
271 // active capture device being started and generating frames. It runs on one | 273 // active capture device being started and generating frames. It runs on one |
272 // thread and is intended to behave deterministically. | 274 // thread and is intended to behave deterministically. |
273 TEST_F(VideoCaptureControllerTest, NormalCaptureMultipleClients) { | 275 TEST_F(VideoCaptureControllerTest, NormalCaptureMultipleClients) { |
274 media::VideoCaptureParams session_100; | 276 media::VideoCaptureParams session_100; |
275 session_100.requested_format = media::VideoCaptureFormat( | 277 session_100.requested_format = media::VideoCaptureFormat( |
276 gfx::Size(320, 240), 30, media::PIXEL_FORMAT_I420); | 278 gfx::Size(320, 240), 30, media::PIXEL_FORMAT_I420); |
277 | 279 |
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
474 device_->OnIncomingCapturedVideoFrame( | 476 device_->OnIncomingCapturedVideoFrame( |
475 buffer, | 477 buffer, |
476 media::VideoCaptureFormat(capture_resolution, | 478 media::VideoCaptureFormat(capture_resolution, |
477 device_format.frame_rate, | 479 device_format.frame_rate, |
478 media::PIXEL_FORMAT_I420), | 480 media::PIXEL_FORMAT_I420), |
479 WrapI420Buffer(buffer, capture_resolution), | 481 WrapI420Buffer(buffer, capture_resolution), |
480 base::TimeTicks()); | 482 base::TimeTicks()); |
481 buffer = NULL; | 483 buffer = NULL; |
482 } | 484 } |
483 std::vector<uint32> mailbox_syncpoints(mailbox_buffers); | 485 std::vector<uint32> mailbox_syncpoints(mailbox_buffers); |
484 std::vector<uint32> mailbox_syncpoints_new(mailbox_buffers); | 486 std::vector<std::vector<uint32> > release_syncpoint_vectors(mailbox_buffers); |
485 for (int i = 0; i < mailbox_buffers; ++i) { | 487 for (int i = 0; i < mailbox_buffers; ++i) { |
486 buffer = device_->ReserveOutputBuffer(media::VideoFrame::NATIVE_TEXTURE, | 488 buffer = device_->ReserveOutputBuffer(media::VideoFrame::NATIVE_TEXTURE, |
487 gfx::Size(0, 0)); | 489 gfx::Size(0, 0)); |
488 ASSERT_TRUE(buffer); | 490 ASSERT_TRUE(buffer); |
489 mailbox_syncpoints[i] = i; | 491 mailbox_syncpoints[i] = i; |
490 device_->OnIncomingCapturedVideoFrame( | 492 device_->OnIncomingCapturedVideoFrame( |
491 buffer, | 493 buffer, |
492 media::VideoCaptureFormat(capture_resolution, | 494 media::VideoCaptureFormat(capture_resolution, |
493 device_format.frame_rate, | 495 device_format.frame_rate, |
494 media::PIXEL_FORMAT_TEXTURE), | 496 media::PIXEL_FORMAT_TEXTURE), |
495 WrapMailboxBuffer( | 497 WrapMailboxBuffer( |
496 buffer, | 498 buffer, |
497 make_scoped_ptr(new gpu::MailboxHolder( | 499 make_scoped_ptr(new gpu::MailboxHolder( |
498 gpu::Mailbox(), 0, mailbox_syncpoints[i])), | 500 gpu::Mailbox(), 0, mailbox_syncpoints[i])), |
499 base::Bind(&CacheSyncPoint, &mailbox_syncpoints_new[i]), | 501 base::Bind(&CacheSyncPoint, &release_syncpoint_vectors[i]), |
500 capture_resolution), | 502 capture_resolution), |
501 base::TimeTicks()); | 503 base::TimeTicks()); |
502 buffer = NULL; | 504 buffer = NULL; |
503 } | 505 } |
504 // ReserveOutputBuffers ought to fail now regardless of buffer format, because | 506 // ReserveOutputBuffers ought to fail now regardless of buffer format, because |
505 // the pool is depleted. | 507 // the pool is depleted. |
506 ASSERT_FALSE(device_->ReserveOutputBuffer(media::VideoFrame::I420, | 508 ASSERT_FALSE(device_->ReserveOutputBuffer(media::VideoFrame::I420, |
507 capture_resolution)); | 509 capture_resolution)); |
508 ASSERT_FALSE(device_->ReserveOutputBuffer(media::VideoFrame::NATIVE_TEXTURE, | 510 ASSERT_FALSE(device_->ReserveOutputBuffer(media::VideoFrame::NATIVE_TEXTURE, |
509 gfx::Size(0, 0))); | 511 gfx::Size(0, 0))); |
510 EXPECT_CALL(*client_b_, DoBufferReady(client_b_route_2)).Times(shm_buffers); | 512 EXPECT_CALL(*client_b_, DoBufferReady(client_b_route_2)).Times(shm_buffers); |
511 EXPECT_CALL(*client_b_, DoMailboxBufferReady(client_b_route_2)) | 513 EXPECT_CALL(*client_b_, DoMailboxBufferReady(client_b_route_2)) |
512 .Times(mailbox_buffers); | 514 .Times(mailbox_buffers); |
513 base::RunLoop().RunUntilIdle(); | 515 base::RunLoop().RunUntilIdle(); |
514 for (size_t i = 0; i < mailbox_syncpoints.size(); ++i) { | 516 for (size_t i = 0; i < mailbox_syncpoints.size(); ++i) { |
515 // See: MockVideoCaptureControllerEventHandler::OnMailboxBufferReady() | 517 // See: MockVideoCaptureControllerEventHandler::OnMailboxBufferReady() |
516 ASSERT_EQ(mailbox_syncpoints[i], ~mailbox_syncpoints_new[i]); | 518 ASSERT_EQ(1u, release_syncpoint_vectors[i].size()); |
519 ASSERT_EQ(mailbox_syncpoints[i], ~release_syncpoint_vectors[i][0]); | |
517 } | 520 } |
518 Mock::VerifyAndClearExpectations(client_b_.get()); | 521 Mock::VerifyAndClearExpectations(client_b_.get()); |
519 } | 522 } |
520 | 523 |
521 // Exercises the OnError() codepath of VideoCaptureController, and tests the | 524 // Exercises the OnError() codepath of VideoCaptureController, and tests the |
522 // behavior of various operations after the error state has been signalled. | 525 // behavior of various operations after the error state has been signalled. |
523 TEST_F(VideoCaptureControllerTest, ErrorBeforeDeviceCreation) { | 526 TEST_F(VideoCaptureControllerTest, ErrorBeforeDeviceCreation) { |
524 media::VideoCaptureParams session_100; | 527 media::VideoCaptureParams session_100; |
525 session_100.requested_format = media::VideoCaptureFormat( | 528 session_100.requested_format = media::VideoCaptureFormat( |
526 gfx::Size(320, 240), 30, media::PIXEL_FORMAT_I420); | 529 gfx::Size(320, 240), 30, media::PIXEL_FORMAT_I420); |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
605 | 608 |
606 // Second client connects after the error state. It also should get told of | 609 // Second client connects after the error state. It also should get told of |
607 // the error. | 610 // the error. |
608 EXPECT_CALL(*client_b_, DoError(route_id)).Times(1); | 611 EXPECT_CALL(*client_b_, DoError(route_id)).Times(1); |
609 controller_->AddClient( | 612 controller_->AddClient( |
610 route_id, client_b_.get(), base::kNullProcessHandle, 200, session_200); | 613 route_id, client_b_.get(), base::kNullProcessHandle, 200, session_200); |
611 Mock::VerifyAndClearExpectations(client_b_.get()); | 614 Mock::VerifyAndClearExpectations(client_b_.get()); |
612 } | 615 } |
613 | 616 |
614 } // namespace content | 617 } // namespace content |
OLD | NEW |