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" |
11 #include "base/memory/ref_counted.h" | 11 #include "base/memory/ref_counted.h" |
12 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
13 #include "base/message_loop/message_loop.h" | 13 #include "base/message_loop/message_loop.h" |
14 #include "base/run_loop.h" | 14 #include "base/run_loop.h" |
15 #include "content/browser/compositor/image_transport_factory.h" | |
15 #include "content/browser/renderer_host/media/media_stream_provider.h" | 16 #include "content/browser/renderer_host/media/media_stream_provider.h" |
16 #include "content/browser/renderer_host/media/video_capture_controller.h" | 17 #include "content/browser/renderer_host/media/video_capture_controller.h" |
17 #include "content/browser/renderer_host/media/video_capture_controller_event_han dler.h" | 18 #include "content/browser/renderer_host/media/video_capture_controller_event_han dler.h" |
18 #include "content/browser/renderer_host/media/video_capture_manager.h" | 19 #include "content/browser/renderer_host/media/video_capture_manager.h" |
20 #include "content/common/gpu/client/gl_helper.h" | |
19 #include "content/common/media/media_stream_options.h" | 21 #include "content/common/media/media_stream_options.h" |
20 #include "content/public/test/test_browser_thread_bundle.h" | 22 #include "content/public/test/test_browser_thread_bundle.h" |
21 #include "gpu/command_buffer/common/mailbox_holder.h" | 23 #include "gpu/command_buffer/common/mailbox_holder.h" |
22 #include "media/base/video_util.h" | 24 #include "media/base/video_util.h" |
23 #include "media/video/capture/video_capture_types.h" | 25 #include "media/video/capture/video_capture_types.h" |
24 #include "testing/gmock/include/gmock/gmock.h" | 26 #include "testing/gmock/include/gmock/gmock.h" |
25 #include "testing/gtest/include/gtest/gtest.h" | 27 #include "testing/gtest/include/gtest/gtest.h" |
28 #include "ui/compositor/test/in_process_context_factory.h" | |
26 | 29 |
27 using ::testing::InSequence; | 30 using ::testing::InSequence; |
28 using ::testing::Mock; | 31 using ::testing::Mock; |
29 | 32 |
30 namespace content { | 33 namespace content { |
31 | 34 |
32 class MockVideoCaptureControllerEventHandler | 35 class MockVideoCaptureControllerEventHandler |
33 : public VideoCaptureControllerEventHandler { | 36 : public VideoCaptureControllerEventHandler { |
34 public: | 37 public: |
35 explicit MockVideoCaptureControllerEventHandler( | 38 explicit MockVideoCaptureControllerEventHandler( |
(...skipping 27 matching lines...) Expand all Loading... | |
63 const media::VideoCaptureFormat& format, | 66 const media::VideoCaptureFormat& format, |
64 base::TimeTicks timestamp) OVERRIDE { | 67 base::TimeTicks timestamp) OVERRIDE { |
65 DoBufferReady(id); | 68 DoBufferReady(id); |
66 base::MessageLoop::current()->PostTask( | 69 base::MessageLoop::current()->PostTask( |
67 FROM_HERE, | 70 FROM_HERE, |
68 base::Bind(&VideoCaptureController::ReturnBuffer, | 71 base::Bind(&VideoCaptureController::ReturnBuffer, |
69 base::Unretained(controller_), | 72 base::Unretained(controller_), |
70 id, | 73 id, |
71 this, | 74 this, |
72 buffer_id, | 75 buffer_id, |
73 std::vector<uint32>())); | 76 0)); |
74 } | 77 } |
75 virtual void OnMailboxBufferReady(const VideoCaptureControllerID& id, | 78 virtual void OnMailboxBufferReady(const VideoCaptureControllerID& id, |
76 int buffer_id, | 79 int buffer_id, |
77 const gpu::MailboxHolder& mailbox_holder, | 80 const gpu::MailboxHolder& mailbox_holder, |
78 const media::VideoCaptureFormat& format, | 81 const media::VideoCaptureFormat& format, |
79 base::TimeTicks timestamp) OVERRIDE { | 82 base::TimeTicks timestamp) OVERRIDE { |
80 DoMailboxBufferReady(id); | 83 DoMailboxBufferReady(id); |
81 // Use a very different syncpoint value when returning a new syncpoint. | |
82 std::vector<uint32> release_sync_points; | |
83 release_sync_points.push_back(~mailbox_holder.sync_point); | |
84 base::MessageLoop::current()->PostTask( | 84 base::MessageLoop::current()->PostTask( |
85 FROM_HERE, | 85 FROM_HERE, |
86 base::Bind(&VideoCaptureController::ReturnBuffer, | 86 base::Bind(&VideoCaptureController::ReturnBuffer, |
87 base::Unretained(controller_), | 87 base::Unretained(controller_), |
88 id, | 88 id, |
89 this, | 89 this, |
90 buffer_id, | 90 buffer_id, |
91 release_sync_points)); | 91 mailbox_holder.sync_point)); |
92 } | 92 } |
93 virtual void OnEnded(const VideoCaptureControllerID& id) OVERRIDE { | 93 virtual void OnEnded(const VideoCaptureControllerID& id) OVERRIDE { |
94 DoEnded(id); | 94 DoEnded(id); |
95 // OnEnded() must respond by (eventually) unregistering the client. | 95 // OnEnded() must respond by (eventually) unregistering the client. |
96 base::MessageLoop::current()->PostTask(FROM_HERE, | 96 base::MessageLoop::current()->PostTask(FROM_HERE, |
97 base::Bind(base::IgnoreResult(&VideoCaptureController::RemoveClient), | 97 base::Bind(base::IgnoreResult(&VideoCaptureController::RemoveClient), |
98 base::Unretained(controller_), id, this)); | 98 base::Unretained(controller_), id, this)); |
99 } | 99 } |
100 | 100 |
101 VideoCaptureController* controller_; | 101 VideoCaptureController* controller_; |
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
256 ASSERT_EQ(1, controller_->GetClientCount()) | 256 ASSERT_EQ(1, controller_->GetClientCount()) |
257 << "Removing non-existant session 200 should be a no-op."; | 257 << "Removing non-existant session 200 should be a no-op."; |
258 ASSERT_EQ(400, | 258 ASSERT_EQ(400, |
259 controller_->RemoveClient(client_b_route_2, client_b_.get())) | 259 controller_->RemoveClient(client_b_route_2, client_b_.get())) |
260 << "Removing client B/2 should return its session_id."; | 260 << "Removing client B/2 should return its session_id."; |
261 // Clients in controller: [] | 261 // Clients in controller: [] |
262 ASSERT_EQ(0, controller_->GetClientCount()) | 262 ASSERT_EQ(0, controller_->GetClientCount()) |
263 << "Client count should return to zero after all clients are gone."; | 263 << "Client count should return to zero after all clients are gone."; |
264 } | 264 } |
265 | 265 |
266 static void CacheSyncPoint(std::vector<uint32>* called_release_sync_points, | 266 static void CacheSyncPoint(uint32* called_release_sync_point, |
267 const std::vector<uint32>& release_sync_points) { | 267 uint32 release_sync_point) { |
268 DCHECK(called_release_sync_points->empty()); | 268 *called_release_sync_point = release_sync_point; |
269 called_release_sync_points->assign(release_sync_points.begin(), | |
270 release_sync_points.end()); | |
271 } | 269 } |
272 | 270 |
273 // This test will connect and disconnect several clients while simulating an | 271 // This test will connect and disconnect several clients while simulating an |
274 // active capture device being started and generating frames. It runs on one | 272 // active capture device being started and generating frames. It runs on one |
275 // thread and is intended to behave deterministically. | 273 // thread and is intended to behave deterministically. |
276 TEST_F(VideoCaptureControllerTest, NormalCaptureMultipleClients) { | 274 TEST_F(VideoCaptureControllerTest, NormalCaptureMultipleClients) { |
275 // VideoCaptureController::ReturnBuffer() uses ImageTransportFactory. | |
276 ImageTransportFactory::InitializeForUnitTests( | |
277 scoped_ptr<ui::ContextFactory>(new ui::InProcessContextFactory)); | |
278 | |
277 media::VideoCaptureParams session_100; | 279 media::VideoCaptureParams session_100; |
278 session_100.requested_format = media::VideoCaptureFormat( | 280 session_100.requested_format = media::VideoCaptureFormat( |
279 gfx::Size(320, 240), 30, media::PIXEL_FORMAT_I420); | 281 gfx::Size(320, 240), 30, media::PIXEL_FORMAT_I420); |
280 | 282 |
281 media::VideoCaptureParams session_200 = session_100; | 283 media::VideoCaptureParams session_200 = session_100; |
282 | 284 |
283 media::VideoCaptureParams session_300 = session_100; | 285 media::VideoCaptureParams session_300 = session_100; |
284 | 286 |
285 media::VideoCaptureParams session_1 = session_100; | 287 media::VideoCaptureParams session_1 = session_100; |
286 | 288 |
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
477 device_->OnIncomingCapturedVideoFrame( | 479 device_->OnIncomingCapturedVideoFrame( |
478 buffer, | 480 buffer, |
479 media::VideoCaptureFormat(capture_resolution, | 481 media::VideoCaptureFormat(capture_resolution, |
480 device_format.frame_rate, | 482 device_format.frame_rate, |
481 media::PIXEL_FORMAT_I420), | 483 media::PIXEL_FORMAT_I420), |
482 WrapI420Buffer(buffer, capture_resolution), | 484 WrapI420Buffer(buffer, capture_resolution), |
483 base::TimeTicks()); | 485 base::TimeTicks()); |
484 buffer = NULL; | 486 buffer = NULL; |
485 } | 487 } |
486 std::vector<uint32> mailbox_syncpoints(mailbox_buffers); | 488 std::vector<uint32> mailbox_syncpoints(mailbox_buffers); |
487 std::vector<std::vector<uint32> > release_syncpoint_vectors(mailbox_buffers); | 489 std::vector<uint32> release_syncpoint_vectors(mailbox_buffers); |
490 GLHelper* gl_helper = ImageTransportFactory::GetInstance()->GetGLHelper(); | |
488 for (int i = 0; i < mailbox_buffers; ++i) { | 491 for (int i = 0; i < mailbox_buffers; ++i) { |
489 buffer = device_->ReserveOutputBuffer(media::VideoFrame::NATIVE_TEXTURE, | 492 buffer = device_->ReserveOutputBuffer(media::VideoFrame::NATIVE_TEXTURE, |
490 gfx::Size(0, 0)); | 493 gfx::Size(0, 0)); |
491 ASSERT_TRUE(buffer); | 494 ASSERT_TRUE(buffer); |
492 mailbox_syncpoints[i] = i; | 495 mailbox_syncpoints[i] = gl_helper->InsertSyncPoint(); |
493 device_->OnIncomingCapturedVideoFrame( | 496 device_->OnIncomingCapturedVideoFrame( |
494 buffer, | 497 buffer, |
495 media::VideoCaptureFormat(capture_resolution, | 498 media::VideoCaptureFormat(capture_resolution, |
496 device_format.frame_rate, | 499 device_format.frame_rate, |
497 media::PIXEL_FORMAT_TEXTURE), | 500 media::PIXEL_FORMAT_TEXTURE), |
498 WrapMailboxBuffer( | 501 WrapMailboxBuffer( |
499 buffer, | 502 buffer, |
500 make_scoped_ptr(new gpu::MailboxHolder( | 503 make_scoped_ptr(new gpu::MailboxHolder( |
501 gpu::Mailbox(), 0, mailbox_syncpoints[i])), | 504 gpu::Mailbox(), 0, mailbox_syncpoints[i])), |
502 base::Bind(&CacheSyncPoint, &release_syncpoint_vectors[i]), | 505 base::Bind(&CacheSyncPoint, &release_syncpoint_vectors[i]), |
503 capture_resolution), | 506 capture_resolution), |
504 base::TimeTicks()); | 507 base::TimeTicks()); |
505 buffer = NULL; | 508 buffer = NULL; |
506 } | 509 } |
507 // ReserveOutputBuffers ought to fail now regardless of buffer format, because | 510 // ReserveOutputBuffers ought to fail now regardless of buffer format, because |
508 // the pool is depleted. | 511 // the pool is depleted. |
509 ASSERT_FALSE(device_->ReserveOutputBuffer(media::VideoFrame::I420, | 512 ASSERT_FALSE(device_->ReserveOutputBuffer(media::VideoFrame::I420, |
510 capture_resolution)); | 513 capture_resolution)); |
511 ASSERT_FALSE(device_->ReserveOutputBuffer(media::VideoFrame::NATIVE_TEXTURE, | 514 ASSERT_FALSE(device_->ReserveOutputBuffer(media::VideoFrame::NATIVE_TEXTURE, |
512 gfx::Size(0, 0))); | 515 gfx::Size(0, 0))); |
513 EXPECT_CALL(*client_b_, DoBufferReady(client_b_route_2)).Times(shm_buffers); | 516 EXPECT_CALL(*client_b_, DoBufferReady(client_b_route_2)).Times(shm_buffers); |
514 EXPECT_CALL(*client_b_, DoMailboxBufferReady(client_b_route_2)) | 517 EXPECT_CALL(*client_b_, DoMailboxBufferReady(client_b_route_2)) |
515 .Times(mailbox_buffers); | 518 .Times(mailbox_buffers); |
516 base::RunLoop().RunUntilIdle(); | 519 base::RunLoop().RunUntilIdle(); |
517 for (size_t i = 0; i < mailbox_syncpoints.size(); ++i) { | 520 for (size_t i = 0; i < mailbox_syncpoints.size(); ++i) { |
521 // The release sync point must be created later than the sync point inserted | |
522 // into the mailbox. | |
518 // See: MockVideoCaptureControllerEventHandler::OnMailboxBufferReady() | 523 // See: MockVideoCaptureControllerEventHandler::OnMailboxBufferReady() |
519 ASSERT_EQ(1u, release_syncpoint_vectors[i].size()); | 524 ASSERT_GT(release_syncpoint_vectors[i], mailbox_syncpoints[i]); |
dshwang
2014/06/23 18:33:20
I sorta abuse sync point implementation detail; sy
danakj
2014/06/23 18:34:59
Is _NE not enough to show it's been updated since
dshwang
2014/06/23 18:50:38
yes, it's not enough.
This check's goal is to ensu
dshwang
2014/06/23 18:53:53
Ah, sorry for wrong answer of your question.
_NE e
| |
520 ASSERT_EQ(mailbox_syncpoints[i], ~release_syncpoint_vectors[i][0]); | |
521 } | 525 } |
522 Mock::VerifyAndClearExpectations(client_b_.get()); | 526 Mock::VerifyAndClearExpectations(client_b_.get()); |
523 } | 527 } |
524 | 528 |
525 // Exercises the OnError() codepath of VideoCaptureController, and tests the | 529 // Exercises the OnError() codepath of VideoCaptureController, and tests the |
526 // behavior of various operations after the error state has been signalled. | 530 // behavior of various operations after the error state has been signalled. |
527 TEST_F(VideoCaptureControllerTest, ErrorBeforeDeviceCreation) { | 531 TEST_F(VideoCaptureControllerTest, ErrorBeforeDeviceCreation) { |
528 media::VideoCaptureParams session_100; | 532 media::VideoCaptureParams session_100; |
529 session_100.requested_format = media::VideoCaptureFormat( | 533 session_100.requested_format = media::VideoCaptureFormat( |
530 gfx::Size(320, 240), 30, media::PIXEL_FORMAT_I420); | 534 gfx::Size(320, 240), 30, media::PIXEL_FORMAT_I420); |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
609 | 613 |
610 // Second client connects after the error state. It also should get told of | 614 // Second client connects after the error state. It also should get told of |
611 // the error. | 615 // the error. |
612 EXPECT_CALL(*client_b_, DoError(route_id)).Times(1); | 616 EXPECT_CALL(*client_b_, DoError(route_id)).Times(1); |
613 controller_->AddClient( | 617 controller_->AddClient( |
614 route_id, client_b_.get(), base::kNullProcessHandle, 200, session_200); | 618 route_id, client_b_.get(), base::kNullProcessHandle, 200, session_200); |
615 Mock::VerifyAndClearExpectations(client_b_.get()); | 619 Mock::VerifyAndClearExpectations(client_b_.get()); |
616 } | 620 } |
617 | 621 |
618 } // namespace content | 622 } // namespace content |
OLD | NEW |