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 "content/browser/renderer_host/media/video_capture_controller.h" | 7 #include "content/browser/renderer_host/media/video_capture_controller.h" |
8 | 8 |
9 #include <stdint.h> | 9 #include <stdint.h> |
10 #include <string.h> | 10 #include <string.h> |
11 | 11 |
12 #include <memory> | 12 #include <memory> |
13 #include <string> | 13 #include <string> |
14 #include <utility> | 14 #include <utility> |
15 | 15 |
16 #include "base/bind.h" | 16 #include "base/bind.h" |
17 #include "base/bind_helpers.h" | 17 #include "base/bind_helpers.h" |
18 #include "base/location.h" | 18 #include "base/location.h" |
19 #include "base/macros.h" | 19 #include "base/macros.h" |
20 #include "base/memory/ref_counted.h" | 20 #include "base/memory/ref_counted.h" |
21 #include "base/run_loop.h" | 21 #include "base/run_loop.h" |
22 #include "base/single_thread_task_runner.h" | 22 #include "base/single_thread_task_runner.h" |
23 #include "base/threading/thread_task_runner_handle.h" | 23 #include "base/threading/thread_task_runner_handle.h" |
24 #include "content/browser/renderer_host/media/media_stream_provider.h" | 24 #include "content/browser/renderer_host/media/media_stream_provider.h" |
25 #include "content/browser/renderer_host/media/video_capture_controller_event_han
dler.h" | 25 #include "content/browser/renderer_host/media/video_capture_controller_event_han
dler.h" |
| 26 #include "content/browser/renderer_host/media/video_capture_gpu_jpeg_decoder.h" |
26 #include "content/browser/renderer_host/media/video_capture_manager.h" | 27 #include "content/browser/renderer_host/media/video_capture_manager.h" |
| 28 #include "content/browser/renderer_host/media/video_frame_receiver_on_io_thread.
h" |
27 #include "content/common/media/media_stream_options.h" | 29 #include "content/common/media/media_stream_options.h" |
28 #include "content/public/test/test_browser_thread_bundle.h" | 30 #include "content/public/test/test_browser_thread_bundle.h" |
29 #include "media/base/video_frame_metadata.h" | 31 #include "media/base/video_frame_metadata.h" |
30 #include "media/base/video_util.h" | 32 #include "media/base/video_util.h" |
| 33 #include "media/capture/video/video_capture_buffer_pool_impl.h" |
| 34 #include "media/capture/video/video_capture_buffer_tracker_factory_impl.h" |
| 35 #include "media/capture/video/video_capture_device_client.h" |
31 #include "media/capture/video_capture_types.h" | 36 #include "media/capture/video_capture_types.h" |
32 #include "testing/gmock/include/gmock/gmock.h" | 37 #include "testing/gmock/include/gmock/gmock.h" |
33 #include "testing/gtest/include/gtest/gtest.h" | 38 #include "testing/gtest/include/gtest/gtest.h" |
34 | 39 |
35 using ::testing::_; | 40 using ::testing::_; |
36 using ::testing::AnyNumber; | 41 using ::testing::AnyNumber; |
37 using ::testing::InSequence; | 42 using ::testing::InSequence; |
38 using ::testing::Mock; | 43 using ::testing::Mock; |
39 using ::testing::SaveArg; | 44 using ::testing::SaveArg; |
40 | 45 |
41 namespace content { | 46 namespace content { |
42 | 47 |
| 48 std::unique_ptr<media::VideoCaptureJpegDecoder> CreateGpuJpegDecoder( |
| 49 const media::VideoCaptureJpegDecoder::DecodeDoneCB& decode_done_cb) { |
| 50 return base::MakeUnique<content::VideoCaptureGpuJpegDecoder>(decode_done_cb); |
| 51 } |
| 52 |
43 class MockVideoCaptureControllerEventHandler | 53 class MockVideoCaptureControllerEventHandler |
44 : public VideoCaptureControllerEventHandler { | 54 : public VideoCaptureControllerEventHandler { |
45 public: | 55 public: |
46 explicit MockVideoCaptureControllerEventHandler( | 56 explicit MockVideoCaptureControllerEventHandler( |
47 VideoCaptureController* controller) | 57 VideoCaptureController* controller) |
48 : controller_(controller), | 58 : controller_(controller), resource_utilization_(-1.0) {} |
49 resource_utilization_(-1.0) {} | |
50 ~MockVideoCaptureControllerEventHandler() override {} | 59 ~MockVideoCaptureControllerEventHandler() override {} |
51 | 60 |
52 // These mock methods are delegated to by our fake implementation of | 61 // These mock methods are delegated to by our fake implementation of |
53 // VideoCaptureControllerEventHandler, to be used in EXPECT_CALL(). | 62 // VideoCaptureControllerEventHandler, to be used in EXPECT_CALL(). |
54 MOCK_METHOD1(DoBufferCreated, void(VideoCaptureControllerID)); | 63 MOCK_METHOD1(DoBufferCreated, void(VideoCaptureControllerID)); |
55 MOCK_METHOD1(DoBufferDestroyed, void(VideoCaptureControllerID)); | 64 MOCK_METHOD1(DoBufferDestroyed, void(VideoCaptureControllerID)); |
56 MOCK_METHOD2(DoBufferReady, void(VideoCaptureControllerID, const gfx::Size&)); | 65 MOCK_METHOD2(DoBufferReady, void(VideoCaptureControllerID, const gfx::Size&)); |
57 MOCK_METHOD1(DoEnded, void(VideoCaptureControllerID)); | 66 MOCK_METHOD1(DoEnded, void(VideoCaptureControllerID)); |
58 MOCK_METHOD1(DoError, void(VideoCaptureControllerID)); | 67 MOCK_METHOD1(DoError, void(VideoCaptureControllerID)); |
59 | 68 |
60 void OnError(VideoCaptureControllerID id) override { | 69 void OnError(VideoCaptureControllerID id) override { DoError(id); } |
61 DoError(id); | |
62 } | |
63 void OnBufferCreated(VideoCaptureControllerID id, | 70 void OnBufferCreated(VideoCaptureControllerID id, |
64 mojo::ScopedSharedBufferHandle handle, | 71 mojo::ScopedSharedBufferHandle handle, |
65 int length, int buffer_id) override { | 72 int length, |
| 73 int buffer_id) override { |
66 DoBufferCreated(id); | 74 DoBufferCreated(id); |
67 } | 75 } |
68 void OnBufferDestroyed(VideoCaptureControllerID id, int buffer_id) override { | 76 void OnBufferDestroyed(VideoCaptureControllerID id, int buffer_id) override { |
69 DoBufferDestroyed(id); | 77 DoBufferDestroyed(id); |
70 } | 78 } |
71 void OnBufferReady(VideoCaptureControllerID id, | 79 void OnBufferReady(VideoCaptureControllerID id, |
72 int buffer_id, | 80 int buffer_id, |
73 const scoped_refptr<media::VideoFrame>& frame) override { | 81 const scoped_refptr<media::VideoFrame>& frame) override { |
74 EXPECT_EQ(expected_pixel_format_, frame->format()); | 82 EXPECT_EQ(expected_pixel_format_, frame->format()); |
75 base::TimeTicks reference_time; | 83 base::TimeTicks reference_time; |
(...skipping 20 matching lines...) Expand all Loading... |
96 double resource_utilization_; | 104 double resource_utilization_; |
97 }; | 105 }; |
98 | 106 |
99 class MockConsumerFeedbackObserver | 107 class MockConsumerFeedbackObserver |
100 : public media::VideoFrameConsumerFeedbackObserver { | 108 : public media::VideoFrameConsumerFeedbackObserver { |
101 public: | 109 public: |
102 MOCK_METHOD2(OnUtilizationReport, | 110 MOCK_METHOD2(OnUtilizationReport, |
103 void(int frame_feedback_id, double utilization)); | 111 void(int frame_feedback_id, double utilization)); |
104 }; | 112 }; |
105 | 113 |
| 114 class MockFrameBufferPool : public media::FrameBufferPool { |
| 115 public: |
| 116 MOCK_METHOD1(SetBufferHold, void(int buffer_id)); |
| 117 MOCK_METHOD1(ReleaseBufferHold, void(int buffer_id)); |
| 118 MOCK_METHOD1(GetHandleForTransit, |
| 119 mojo::ScopedSharedBufferHandle(int buffer_id)); |
| 120 }; |
| 121 |
106 // Test class. | 122 // Test class. |
107 class VideoCaptureControllerTest | 123 class VideoCaptureControllerTest |
108 : public testing::Test, | 124 : public testing::Test, |
109 public testing::WithParamInterface<media::VideoPixelFormat> { | 125 public testing::WithParamInterface<media::VideoPixelFormat> { |
110 public: | 126 public: |
111 VideoCaptureControllerTest() {} | 127 VideoCaptureControllerTest() {} |
112 ~VideoCaptureControllerTest() override {} | 128 ~VideoCaptureControllerTest() override {} |
113 | 129 |
114 protected: | 130 protected: |
115 static const int kPoolSize = 3; | 131 static const int kPoolSize = 3; |
116 | 132 |
117 void SetUp() override { | 133 void SetUp() override { |
118 controller_.reset(new VideoCaptureController(kPoolSize)); | 134 scoped_refptr<media::VideoCaptureBufferPool> buffer_pool( |
119 device_ = controller_->NewDeviceClient(); | 135 new media::VideoCaptureBufferPoolImpl( |
| 136 base::MakeUnique<media::VideoCaptureBufferTrackerFactoryImpl>(), |
| 137 kPoolSize)); |
| 138 controller_.reset(new VideoCaptureController()); |
| 139 device_client_.reset(new media::VideoCaptureDeviceClient( |
| 140 base::MakeUnique<VideoFrameReceiverOnIOThread>( |
| 141 controller_->GetWeakPtrForIOThread()), |
| 142 buffer_pool, |
| 143 base::Bind( |
| 144 &CreateGpuJpegDecoder, |
| 145 base::Bind(&media::VideoFrameReceiver::OnIncomingCapturedVideoFrame, |
| 146 controller_->GetWeakPtrForIOThread())))); |
| 147 auto frame_receiver_observer = base::MakeUnique<MockFrameBufferPool>(); |
| 148 mock_frame_receiver_observer_ = frame_receiver_observer.get(); |
| 149 controller_->SetFrameBufferPool(std::move(frame_receiver_observer)); |
120 auto consumer_feedback_observer = | 150 auto consumer_feedback_observer = |
121 base::MakeUnique<MockConsumerFeedbackObserver>(); | 151 base::MakeUnique<MockConsumerFeedbackObserver>(); |
122 mock_consumer_feedback_observer_ = consumer_feedback_observer.get(); | 152 mock_consumer_feedback_observer_ = consumer_feedback_observer.get(); |
123 controller_->SetConsumerFeedbackObserver( | 153 controller_->SetConsumerFeedbackObserver( |
124 std::move(consumer_feedback_observer)); | 154 std::move(consumer_feedback_observer)); |
125 client_a_.reset(new MockVideoCaptureControllerEventHandler( | 155 client_a_.reset(new MockVideoCaptureControllerEventHandler( |
126 controller_.get())); | 156 controller_.get())); |
127 client_b_.reset(new MockVideoCaptureControllerEventHandler( | 157 client_b_.reset(new MockVideoCaptureControllerEventHandler( |
128 controller_.get())); | 158 controller_.get())); |
129 } | 159 } |
(...skipping 10 matching lines...) Expand all Loading... |
140 media::VideoFrame::AllocationSize(format, dimensions), | 170 media::VideoFrame::AllocationSize(format, dimensions), |
141 base::SharedMemory::NULLHandle(), 0u, base::TimeDelta()); | 171 base::SharedMemory::NULLHandle(), 0u, base::TimeDelta()); |
142 EXPECT_TRUE(video_frame); | 172 EXPECT_TRUE(video_frame); |
143 return video_frame; | 173 return video_frame; |
144 } | 174 } |
145 | 175 |
146 TestBrowserThreadBundle bundle_; | 176 TestBrowserThreadBundle bundle_; |
147 std::unique_ptr<MockVideoCaptureControllerEventHandler> client_a_; | 177 std::unique_ptr<MockVideoCaptureControllerEventHandler> client_a_; |
148 std::unique_ptr<MockVideoCaptureControllerEventHandler> client_b_; | 178 std::unique_ptr<MockVideoCaptureControllerEventHandler> client_b_; |
149 std::unique_ptr<VideoCaptureController> controller_; | 179 std::unique_ptr<VideoCaptureController> controller_; |
150 std::unique_ptr<media::VideoCaptureDevice::Client> device_; | 180 std::unique_ptr<media::VideoCaptureDevice::Client> device_client_; |
| 181 MockFrameBufferPool* mock_frame_receiver_observer_; |
151 MockConsumerFeedbackObserver* mock_consumer_feedback_observer_; | 182 MockConsumerFeedbackObserver* mock_consumer_feedback_observer_; |
152 | 183 |
153 private: | 184 private: |
154 DISALLOW_COPY_AND_ASSIGN(VideoCaptureControllerTest); | 185 DISALLOW_COPY_AND_ASSIGN(VideoCaptureControllerTest); |
155 }; | 186 }; |
156 | 187 |
157 // A simple test of VideoCaptureController's ability to add, remove, and keep | 188 // A simple test of VideoCaptureController's ability to add, remove, and keep |
158 // track of clients. | 189 // track of clients. |
159 TEST_F(VideoCaptureControllerTest, AddAndRemoveClients) { | 190 TEST_F(VideoCaptureControllerTest, AddAndRemoveClients) { |
160 media::VideoCaptureParams session_100; | 191 media::VideoCaptureParams session_100; |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
292 controller_->AddClient(client_a_route_2, | 323 controller_->AddClient(client_a_route_2, |
293 client_a_.get(), | 324 client_a_.get(), |
294 200, | 325 200, |
295 session_200); | 326 session_200); |
296 ASSERT_EQ(3, controller_->GetClientCount()); | 327 ASSERT_EQ(3, controller_->GetClientCount()); |
297 | 328 |
298 // Now, simulate an incoming captured buffer from the capture device. As a | 329 // Now, simulate an incoming captured buffer from the capture device. As a |
299 // side effect this will cause the first buffer to be shared with clients. | 330 // side effect this will cause the first buffer to be shared with clients. |
300 uint8_t buffer_no = 1; | 331 uint8_t buffer_no = 1; |
301 const int arbitrary_frame_feedback_id = 101; | 332 const int arbitrary_frame_feedback_id = 101; |
302 ASSERT_EQ(0.0, device_->GetBufferPoolUtilization()); | 333 ASSERT_EQ(0.0, device_client_->GetBufferPoolUtilization()); |
303 std::unique_ptr<media::VideoCaptureDevice::Client::Buffer> buffer( | 334 std::unique_ptr<media::VideoCaptureDevice::Client::Buffer> buffer( |
304 device_->ReserveOutputBuffer(capture_resolution, format, | 335 device_client_->ReserveOutputBuffer(capture_resolution, format, |
305 media::PIXEL_STORAGE_CPU, | 336 media::PIXEL_STORAGE_CPU, |
306 arbitrary_frame_feedback_id)); | 337 arbitrary_frame_feedback_id)); |
307 ASSERT_TRUE(buffer.get()); | 338 ASSERT_TRUE(buffer.get()); |
308 ASSERT_EQ(1.0 / kPoolSize, device_->GetBufferPoolUtilization()); | 339 ASSERT_EQ(1.0 / kPoolSize, device_client_->GetBufferPoolUtilization()); |
309 memset(buffer->data(), buffer_no++, buffer->mapped_size()); | 340 memset(buffer->data(), buffer_no++, buffer->mapped_size()); |
310 { | 341 { |
311 InSequence s; | 342 InSequence s; |
312 EXPECT_CALL(*client_a_, DoBufferCreated(client_a_route_1)).Times(1); | 343 EXPECT_CALL(*client_a_, DoBufferCreated(client_a_route_1)).Times(1); |
313 EXPECT_CALL(*client_a_, DoBufferReady(client_a_route_1, capture_resolution)) | 344 EXPECT_CALL(*client_a_, DoBufferReady(client_a_route_1, capture_resolution)) |
314 .Times(1); | 345 .Times(1); |
315 } | 346 } |
316 { | 347 { |
317 InSequence s; | 348 InSequence s; |
318 EXPECT_CALL(*client_b_, DoBufferCreated(client_b_route_1)).Times(1); | 349 EXPECT_CALL(*client_b_, DoBufferCreated(client_b_route_1)).Times(1); |
319 EXPECT_CALL(*client_b_, DoBufferReady(client_b_route_1, capture_resolution)) | 350 EXPECT_CALL(*client_b_, DoBufferReady(client_b_route_1, capture_resolution)) |
320 .Times(1); | 351 .Times(1); |
321 } | 352 } |
322 { | 353 { |
323 InSequence s; | 354 InSequence s; |
324 EXPECT_CALL(*client_a_, DoBufferCreated(client_a_route_2)).Times(1); | 355 EXPECT_CALL(*client_a_, DoBufferCreated(client_a_route_2)).Times(1); |
325 EXPECT_CALL(*client_a_, DoBufferReady(client_a_route_2, capture_resolution)) | 356 EXPECT_CALL(*client_a_, DoBufferReady(client_a_route_2, capture_resolution)) |
326 .Times(1); | 357 .Times(1); |
327 } | 358 } |
328 scoped_refptr<media::VideoFrame> video_frame = WrapBuffer( | 359 scoped_refptr<media::VideoFrame> video_frame = WrapBuffer( |
329 capture_resolution, static_cast<uint8_t*>(buffer->data()), format); | 360 capture_resolution, static_cast<uint8_t*>(buffer->data()), format); |
330 ASSERT_TRUE(video_frame); | 361 ASSERT_TRUE(video_frame); |
331 ASSERT_FALSE(video_frame->metadata()->HasKey( | 362 ASSERT_FALSE(video_frame->metadata()->HasKey( |
332 media::VideoFrameMetadata::RESOURCE_UTILIZATION)); | 363 media::VideoFrameMetadata::RESOURCE_UTILIZATION)); |
333 client_a_->resource_utilization_ = 0.5; | 364 client_a_->resource_utilization_ = 0.5; |
334 client_b_->resource_utilization_ = -1.0; | 365 client_b_->resource_utilization_ = -1.0; |
335 | 366 { |
336 // Expect VideoCaptureController to call the load observer with a | 367 InSequence s; |
337 // resource utilization of 0.5 (the largest of all reported values). | 368 EXPECT_CALL(*mock_frame_receiver_observer_, SetBufferHold(buffer->id())) |
338 EXPECT_CALL(*mock_consumer_feedback_observer_, | 369 .Times(1); |
339 OnUtilizationReport(arbitrary_frame_feedback_id, 0.5)) | 370 // Expect VideoCaptureController to call the load observer with a |
340 .Times(1); | 371 // resource utilization of 0.5 (the largest of all reported values). |
| 372 EXPECT_CALL(*mock_consumer_feedback_observer_, |
| 373 OnUtilizationReport(arbitrary_frame_feedback_id, 0.5)) |
| 374 .Times(1); |
| 375 EXPECT_CALL(*mock_frame_receiver_observer_, ReleaseBufferHold(buffer->id())) |
| 376 .Times(1); |
| 377 } |
341 | 378 |
342 video_frame->metadata()->SetTimeTicks( | 379 video_frame->metadata()->SetTimeTicks( |
343 media::VideoFrameMetadata::REFERENCE_TIME, base::TimeTicks()); | 380 media::VideoFrameMetadata::REFERENCE_TIME, base::TimeTicks()); |
344 device_->OnIncomingCapturedVideoFrame(std::move(buffer), video_frame); | 381 device_client_->OnIncomingCapturedVideoFrame(std::move(buffer), video_frame); |
345 | 382 |
346 base::RunLoop().RunUntilIdle(); | 383 base::RunLoop().RunUntilIdle(); |
347 Mock::VerifyAndClearExpectations(client_a_.get()); | 384 Mock::VerifyAndClearExpectations(client_a_.get()); |
348 Mock::VerifyAndClearExpectations(client_b_.get()); | 385 Mock::VerifyAndClearExpectations(client_b_.get()); |
349 Mock::VerifyAndClearExpectations(mock_consumer_feedback_observer_); | 386 Mock::VerifyAndClearExpectations(mock_consumer_feedback_observer_); |
| 387 Mock::VerifyAndClearExpectations(mock_frame_receiver_observer_); |
350 | 388 |
351 // Second buffer which ought to use the same shared memory buffer. In this | 389 // Second buffer which ought to use the same shared memory buffer. In this |
352 // case pretend that the Buffer pointer is held by the device for a long | 390 // case pretend that the Buffer pointer is held by the device for a long |
353 // delay. This shouldn't affect anything. | 391 // delay. This shouldn't affect anything. |
354 const int arbitrary_frame_feedback_id_2 = 102; | 392 const int arbitrary_frame_feedback_id_2 = 102; |
355 std::unique_ptr<media::VideoCaptureDevice::Client::Buffer> buffer2 = | 393 std::unique_ptr<media::VideoCaptureDevice::Client::Buffer> buffer2 = |
356 device_->ReserveOutputBuffer(capture_resolution, format, | 394 device_client_->ReserveOutputBuffer(capture_resolution, format, |
357 media::PIXEL_STORAGE_CPU, | 395 media::PIXEL_STORAGE_CPU, |
358 arbitrary_frame_feedback_id_2); | 396 arbitrary_frame_feedback_id_2); |
359 ASSERT_TRUE(buffer2.get()); | 397 ASSERT_TRUE(buffer2.get()); |
360 memset(buffer2->data(), buffer_no++, buffer2->mapped_size()); | 398 memset(buffer2->data(), buffer_no++, buffer2->mapped_size()); |
361 video_frame = WrapBuffer(capture_resolution, | 399 video_frame = WrapBuffer(capture_resolution, |
362 static_cast<uint8_t*>(buffer2->data()), format); | 400 static_cast<uint8_t*>(buffer2->data()), format); |
363 client_a_->resource_utilization_ = 0.5; | 401 client_a_->resource_utilization_ = 0.5; |
364 client_b_->resource_utilization_ = 3.14; | 402 client_b_->resource_utilization_ = 3.14; |
365 video_frame->metadata()->SetTimeTicks( | 403 video_frame->metadata()->SetTimeTicks( |
366 media::VideoFrameMetadata::REFERENCE_TIME, base::TimeTicks()); | 404 media::VideoFrameMetadata::REFERENCE_TIME, base::TimeTicks()); |
367 // Expect VideoCaptureController to call the load observer with a | 405 // Expect VideoCaptureController to call the load observer with a |
368 // resource utilization of 3.14 (the largest of all reported values). | 406 // resource utilization of 3.14 (the largest of all reported values). |
369 EXPECT_CALL(*mock_consumer_feedback_observer_, | 407 { |
370 OnUtilizationReport(arbitrary_frame_feedback_id_2, 3.14)) | 408 InSequence s; |
371 .Times(1); | 409 EXPECT_CALL(*mock_frame_receiver_observer_, SetBufferHold(buffer2->id())) |
| 410 .Times(1); |
| 411 // Expect VideoCaptureController to call the load observer with a |
| 412 // resource utilization of 3.14 (the largest of all reported values). |
| 413 EXPECT_CALL(*mock_consumer_feedback_observer_, |
| 414 OnUtilizationReport(arbitrary_frame_feedback_id_2, 3.14)) |
| 415 .Times(1); |
| 416 EXPECT_CALL(*mock_frame_receiver_observer_, |
| 417 ReleaseBufferHold(buffer2->id())) |
| 418 .Times(1); |
| 419 } |
372 | 420 |
373 device_->OnIncomingCapturedVideoFrame(std::move(buffer2), video_frame); | 421 device_client_->OnIncomingCapturedVideoFrame(std::move(buffer2), video_frame); |
374 | 422 |
375 // The buffer should be delivered to the clients in any order. | 423 // The buffer should be delivered to the clients in any order. |
376 { | 424 { |
377 InSequence s; | 425 InSequence s; |
378 EXPECT_CALL(*client_a_, DoBufferCreated(client_a_route_1)).Times(1); | 426 EXPECT_CALL(*client_a_, DoBufferCreated(client_a_route_1)).Times(1); |
379 EXPECT_CALL(*client_a_, DoBufferReady(client_a_route_1, capture_resolution)) | 427 EXPECT_CALL(*client_a_, DoBufferReady(client_a_route_1, capture_resolution)) |
380 .Times(1); | 428 .Times(1); |
381 } | 429 } |
382 { | 430 { |
383 InSequence s; | 431 InSequence s; |
384 EXPECT_CALL(*client_b_, DoBufferCreated(client_b_route_1)).Times(1); | 432 EXPECT_CALL(*client_b_, DoBufferCreated(client_b_route_1)).Times(1); |
385 EXPECT_CALL(*client_b_, DoBufferReady(client_b_route_1, capture_resolution)) | 433 EXPECT_CALL(*client_b_, DoBufferReady(client_b_route_1, capture_resolution)) |
386 .Times(1); | 434 .Times(1); |
387 } | 435 } |
388 { | 436 { |
389 InSequence s; | 437 InSequence s; |
390 EXPECT_CALL(*client_a_, DoBufferCreated(client_a_route_2)).Times(1); | 438 EXPECT_CALL(*client_a_, DoBufferCreated(client_a_route_2)).Times(1); |
391 EXPECT_CALL(*client_a_, DoBufferReady(client_a_route_2, capture_resolution)) | 439 EXPECT_CALL(*client_a_, DoBufferReady(client_a_route_2, capture_resolution)) |
392 .Times(1); | 440 .Times(1); |
393 } | 441 } |
394 base::RunLoop().RunUntilIdle(); | 442 base::RunLoop().RunUntilIdle(); |
395 Mock::VerifyAndClearExpectations(client_a_.get()); | 443 Mock::VerifyAndClearExpectations(client_a_.get()); |
396 Mock::VerifyAndClearExpectations(client_b_.get()); | 444 Mock::VerifyAndClearExpectations(client_b_.get()); |
397 Mock::VerifyAndClearExpectations(mock_consumer_feedback_observer_); | 445 Mock::VerifyAndClearExpectations(mock_consumer_feedback_observer_); |
| 446 Mock::VerifyAndClearExpectations(mock_frame_receiver_observer_); |
398 | 447 |
399 // Add a fourth client now that some buffers have come through. | 448 // Add a fourth client now that some buffers have come through. |
400 controller_->AddClient(client_b_route_2, | 449 controller_->AddClient(client_b_route_2, |
401 client_b_.get(), | 450 client_b_.get(), |
402 1, | 451 1, |
403 session_1); | 452 session_1); |
404 Mock::VerifyAndClearExpectations(client_b_.get()); | 453 Mock::VerifyAndClearExpectations(client_b_.get()); |
405 | 454 |
406 // Third, fourth, and fifth buffers. Pretend they all arrive at the same time. | 455 // Third, fourth, and fifth buffers. Pretend they all arrive at the same time. |
407 for (int i = 0; i < kPoolSize; i++) { | 456 for (int i = 0; i < kPoolSize; i++) { |
408 const int arbitrary_frame_feedback_id = 200 + i; | 457 const int arbitrary_frame_feedback_id = 200 + i; |
409 std::unique_ptr<media::VideoCaptureDevice::Client::Buffer> buffer = | 458 std::unique_ptr<media::VideoCaptureDevice::Client::Buffer> buffer = |
410 device_->ReserveOutputBuffer(capture_resolution, format, | 459 device_client_->ReserveOutputBuffer(capture_resolution, format, |
411 media::PIXEL_STORAGE_CPU, | 460 media::PIXEL_STORAGE_CPU, |
412 arbitrary_frame_feedback_id); | 461 arbitrary_frame_feedback_id); |
413 ASSERT_TRUE(buffer.get()); | 462 ASSERT_TRUE(buffer.get()); |
414 memset(buffer->data(), buffer_no++, buffer->mapped_size()); | 463 memset(buffer->data(), buffer_no++, buffer->mapped_size()); |
415 video_frame = WrapBuffer(capture_resolution, | 464 video_frame = WrapBuffer(capture_resolution, |
416 static_cast<uint8_t*>(buffer->data()), format); | 465 static_cast<uint8_t*>(buffer->data()), format); |
417 ASSERT_TRUE(video_frame); | 466 ASSERT_TRUE(video_frame); |
418 video_frame->metadata()->SetTimeTicks( | 467 video_frame->metadata()->SetTimeTicks( |
419 media::VideoFrameMetadata::REFERENCE_TIME, base::TimeTicks()); | 468 media::VideoFrameMetadata::REFERENCE_TIME, base::TimeTicks()); |
420 device_->OnIncomingCapturedVideoFrame(std::move(buffer), video_frame); | 469 device_client_->OnIncomingCapturedVideoFrame(std::move(buffer), |
| 470 video_frame); |
421 } | 471 } |
422 // ReserveOutputBuffer ought to fail now, because the pool is depleted. | 472 // ReserveOutputBuffer ought to fail now, because the pool is depleted. |
423 ASSERT_FALSE(device_ | 473 ASSERT_FALSE(device_client_ |
424 ->ReserveOutputBuffer(capture_resolution, format, | 474 ->ReserveOutputBuffer(capture_resolution, format, |
425 media::PIXEL_STORAGE_CPU, | 475 media::PIXEL_STORAGE_CPU, |
426 arbitrary_frame_feedback_id) | 476 arbitrary_frame_feedback_id) |
427 .get()); | 477 .get()); |
428 | 478 |
429 // The new client needs to be notified of the creation of |kPoolSize| buffers; | 479 // The new client needs to be notified of the creation of |kPoolSize| buffers; |
430 // the old clients only |kPoolSize - 2|. | 480 // the old clients only |kPoolSize - 2|. |
431 EXPECT_CALL(*client_b_, DoBufferCreated(client_b_route_2)).Times(kPoolSize); | 481 EXPECT_CALL(*client_b_, DoBufferCreated(client_b_route_2)).Times(kPoolSize); |
432 EXPECT_CALL(*client_b_, DoBufferReady(client_b_route_2, capture_resolution)) | 482 EXPECT_CALL(*client_b_, DoBufferReady(client_b_route_2, capture_resolution)) |
433 .Times(kPoolSize); | 483 .Times(kPoolSize); |
(...skipping 14 matching lines...) Expand all Loading... |
448 Mock::VerifyAndClearExpectations(client_b_.get()); | 498 Mock::VerifyAndClearExpectations(client_b_.get()); |
449 | 499 |
450 // Now test the interaction of client shutdown and buffer delivery. | 500 // Now test the interaction of client shutdown and buffer delivery. |
451 // Kill A1 via renderer disconnect (synchronous). | 501 // Kill A1 via renderer disconnect (synchronous). |
452 controller_->RemoveClient(client_a_route_1, client_a_.get()); | 502 controller_->RemoveClient(client_a_route_1, client_a_.get()); |
453 // Kill B1 via session close (posts a task to disconnect). | 503 // Kill B1 via session close (posts a task to disconnect). |
454 EXPECT_CALL(*client_b_, DoEnded(client_b_route_1)).Times(1); | 504 EXPECT_CALL(*client_b_, DoEnded(client_b_route_1)).Times(1); |
455 controller_->StopSession(300); | 505 controller_->StopSession(300); |
456 // Queue up another buffer. | 506 // Queue up another buffer. |
457 std::unique_ptr<media::VideoCaptureDevice::Client::Buffer> buffer3 = | 507 std::unique_ptr<media::VideoCaptureDevice::Client::Buffer> buffer3 = |
458 device_->ReserveOutputBuffer(capture_resolution, format, | 508 device_client_->ReserveOutputBuffer(capture_resolution, format, |
459 media::PIXEL_STORAGE_CPU, | 509 media::PIXEL_STORAGE_CPU, |
460 arbitrary_frame_feedback_id); | 510 arbitrary_frame_feedback_id); |
461 ASSERT_TRUE(buffer3.get()); | 511 ASSERT_TRUE(buffer3.get()); |
462 memset(buffer3->data(), buffer_no++, buffer3->mapped_size()); | 512 memset(buffer3->data(), buffer_no++, buffer3->mapped_size()); |
463 video_frame = WrapBuffer(capture_resolution, | 513 video_frame = WrapBuffer(capture_resolution, |
464 static_cast<uint8_t*>(buffer3->data()), format); | 514 static_cast<uint8_t*>(buffer3->data()), format); |
465 ASSERT_TRUE(video_frame); | 515 ASSERT_TRUE(video_frame); |
466 video_frame->metadata()->SetTimeTicks( | 516 video_frame->metadata()->SetTimeTicks( |
467 media::VideoFrameMetadata::REFERENCE_TIME, base::TimeTicks()); | 517 media::VideoFrameMetadata::REFERENCE_TIME, base::TimeTicks()); |
468 device_->OnIncomingCapturedVideoFrame(std::move(buffer3), video_frame); | 518 device_client_->OnIncomingCapturedVideoFrame(std::move(buffer3), video_frame); |
469 | 519 |
470 std::unique_ptr<media::VideoCaptureDevice::Client::Buffer> buffer4 = | 520 std::unique_ptr<media::VideoCaptureDevice::Client::Buffer> buffer4 = |
471 device_->ReserveOutputBuffer(capture_resolution, format, | 521 device_client_->ReserveOutputBuffer(capture_resolution, format, |
472 media::PIXEL_STORAGE_CPU, | 522 media::PIXEL_STORAGE_CPU, |
473 arbitrary_frame_feedback_id); | 523 arbitrary_frame_feedback_id); |
474 { | 524 { |
475 // Kill A2 via session close (posts a task to disconnect, but A2 must not | 525 // Kill A2 via session close (posts a task to disconnect, but A2 must not |
476 // be sent either of these two buffers). | 526 // be sent either of these two buffers). |
477 EXPECT_CALL(*client_a_, DoEnded(client_a_route_2)).Times(1); | 527 EXPECT_CALL(*client_a_, DoEnded(client_a_route_2)).Times(1); |
478 controller_->StopSession(200); | 528 controller_->StopSession(200); |
479 } | 529 } |
480 ASSERT_TRUE(buffer4.get()); | 530 ASSERT_TRUE(buffer4.get()); |
481 memset(buffer4->data(), buffer_no++, buffer4->mapped_size()); | 531 memset(buffer4->data(), buffer_no++, buffer4->mapped_size()); |
482 video_frame = WrapBuffer(capture_resolution, | 532 video_frame = WrapBuffer(capture_resolution, |
483 static_cast<uint8_t*>(buffer4->data()), format); | 533 static_cast<uint8_t*>(buffer4->data()), format); |
484 ASSERT_TRUE(video_frame); | 534 ASSERT_TRUE(video_frame); |
485 video_frame->metadata()->SetTimeTicks( | 535 video_frame->metadata()->SetTimeTicks( |
486 media::VideoFrameMetadata::REFERENCE_TIME, base::TimeTicks()); | 536 media::VideoFrameMetadata::REFERENCE_TIME, base::TimeTicks()); |
487 device_->OnIncomingCapturedVideoFrame(std::move(buffer4), video_frame); | 537 device_client_->OnIncomingCapturedVideoFrame(std::move(buffer4), video_frame); |
488 // B2 is the only client left, and is the only one that should | 538 // B2 is the only client left, and is the only one that should |
489 // get the buffer. | 539 // get the buffer. |
490 EXPECT_CALL(*client_b_, DoBufferReady(client_b_route_2, capture_resolution)) | 540 EXPECT_CALL(*client_b_, DoBufferReady(client_b_route_2, capture_resolution)) |
491 .Times(2); | 541 .Times(2); |
492 base::RunLoop().RunUntilIdle(); | 542 base::RunLoop().RunUntilIdle(); |
493 Mock::VerifyAndClearExpectations(client_a_.get()); | 543 Mock::VerifyAndClearExpectations(client_a_.get()); |
494 Mock::VerifyAndClearExpectations(client_b_.get()); | 544 Mock::VerifyAndClearExpectations(client_b_.get()); |
495 } | 545 } |
496 | 546 |
497 INSTANTIATE_TEST_CASE_P(, | 547 INSTANTIATE_TEST_CASE_P(, |
498 VideoCaptureControllerTest, | 548 VideoCaptureControllerTest, |
499 ::testing::Values(media::PIXEL_FORMAT_I420, | 549 ::testing::Values(media::PIXEL_FORMAT_I420, |
500 media::PIXEL_FORMAT_Y16)); | 550 media::PIXEL_FORMAT_Y16)); |
501 | 551 |
502 // Exercises the OnError() codepath of VideoCaptureController, and tests the | 552 // Exercises the OnError() codepath of VideoCaptureController, and tests the |
503 // behavior of various operations after the error state has been signalled. | 553 // behavior of various operations after the error state has been signalled. |
504 TEST_F(VideoCaptureControllerTest, ErrorBeforeDeviceCreation) { | 554 TEST_F(VideoCaptureControllerTest, ErrorBeforeDeviceCreation) { |
505 media::VideoCaptureParams session_100; | 555 media::VideoCaptureParams session_100; |
506 session_100.requested_format = media::VideoCaptureFormat( | 556 session_100.requested_format = media::VideoCaptureFormat( |
507 gfx::Size(320, 240), 30, media::PIXEL_FORMAT_I420); | 557 gfx::Size(320, 240), 30, media::PIXEL_FORMAT_I420); |
508 | 558 |
509 media::VideoCaptureParams session_200 = session_100; | 559 media::VideoCaptureParams session_200 = session_100; |
510 | 560 |
511 const gfx::Size capture_resolution(320, 240); | 561 const gfx::Size capture_resolution(320, 240); |
512 | 562 |
513 const VideoCaptureControllerID route_id(0x99); | 563 const VideoCaptureControllerID route_id(0x99); |
514 | 564 |
515 // Start with one client. | 565 // Start with one client. |
516 controller_->AddClient(route_id, client_a_.get(), 100, session_100); | 566 controller_->AddClient(route_id, client_a_.get(), 100, session_100); |
517 device_->OnError(FROM_HERE, "Test Error"); | 567 device_client_->OnError(FROM_HERE, "Test Error"); |
518 EXPECT_CALL(*client_a_, DoError(route_id)).Times(1); | 568 EXPECT_CALL(*client_a_, DoError(route_id)).Times(1); |
519 base::RunLoop().RunUntilIdle(); | 569 base::RunLoop().RunUntilIdle(); |
520 Mock::VerifyAndClearExpectations(client_a_.get()); | 570 Mock::VerifyAndClearExpectations(client_a_.get()); |
521 | 571 |
522 // Second client connects after the error state. It also should get told of | 572 // Second client connects after the error state. It also should get told of |
523 // the error. | 573 // the error. |
524 EXPECT_CALL(*client_b_, DoError(route_id)).Times(1); | 574 EXPECT_CALL(*client_b_, DoError(route_id)).Times(1); |
525 controller_->AddClient(route_id, client_b_.get(), 200, session_200); | 575 controller_->AddClient(route_id, client_b_.get(), 200, session_200); |
526 base::RunLoop().RunUntilIdle(); | 576 base::RunLoop().RunUntilIdle(); |
527 Mock::VerifyAndClearExpectations(client_b_.get()); | 577 Mock::VerifyAndClearExpectations(client_b_.get()); |
528 | 578 |
529 const int arbitrary_frame_feedback_id = 101; | 579 const int arbitrary_frame_feedback_id = 101; |
530 std::unique_ptr<media::VideoCaptureDevice::Client::Buffer> buffer( | 580 std::unique_ptr<media::VideoCaptureDevice::Client::Buffer> buffer( |
531 device_->ReserveOutputBuffer(capture_resolution, media::PIXEL_FORMAT_I420, | 581 device_client_->ReserveOutputBuffer( |
532 media::PIXEL_STORAGE_CPU, | 582 capture_resolution, media::PIXEL_FORMAT_I420, |
533 arbitrary_frame_feedback_id)); | 583 media::PIXEL_STORAGE_CPU, arbitrary_frame_feedback_id)); |
534 ASSERT_TRUE(buffer.get()); | 584 ASSERT_TRUE(buffer.get()); |
535 scoped_refptr<media::VideoFrame> video_frame = | 585 scoped_refptr<media::VideoFrame> video_frame = |
536 WrapBuffer(capture_resolution, static_cast<uint8_t*>(buffer->data())); | 586 WrapBuffer(capture_resolution, static_cast<uint8_t*>(buffer->data())); |
537 ASSERT_TRUE(video_frame); | 587 ASSERT_TRUE(video_frame); |
538 video_frame->metadata()->SetTimeTicks( | 588 video_frame->metadata()->SetTimeTicks( |
539 media::VideoFrameMetadata::REFERENCE_TIME, base::TimeTicks()); | 589 media::VideoFrameMetadata::REFERENCE_TIME, base::TimeTicks()); |
540 device_->OnIncomingCapturedVideoFrame(std::move(buffer), video_frame); | 590 device_client_->OnIncomingCapturedVideoFrame(std::move(buffer), video_frame); |
541 | 591 |
542 base::RunLoop().RunUntilIdle(); | 592 base::RunLoop().RunUntilIdle(); |
543 } | 593 } |
544 | 594 |
545 // Exercises the OnError() codepath of VideoCaptureController, and tests the | 595 // Exercises the OnError() codepath of VideoCaptureController, and tests the |
546 // behavior of various operations after the error state has been signalled. | 596 // behavior of various operations after the error state has been signalled. |
547 TEST_F(VideoCaptureControllerTest, ErrorAfterDeviceCreation) { | 597 TEST_F(VideoCaptureControllerTest, ErrorAfterDeviceCreation) { |
548 media::VideoCaptureParams session_100; | 598 media::VideoCaptureParams session_100; |
549 session_100.requested_format = media::VideoCaptureFormat( | 599 session_100.requested_format = media::VideoCaptureFormat( |
550 gfx::Size(320, 240), 30, media::PIXEL_FORMAT_I420); | 600 gfx::Size(320, 240), 30, media::PIXEL_FORMAT_I420); |
551 | 601 |
552 media::VideoCaptureParams session_200 = session_100; | 602 media::VideoCaptureParams session_200 = session_100; |
553 | 603 |
554 const VideoCaptureControllerID route_id(0x99); | 604 const VideoCaptureControllerID route_id(0x99); |
555 | 605 |
556 // Start with one client. | 606 // Start with one client. |
557 controller_->AddClient(route_id, client_a_.get(), 100, session_100); | 607 controller_->AddClient(route_id, client_a_.get(), 100, session_100); |
558 media::VideoCaptureFormat device_format( | 608 media::VideoCaptureFormat device_format( |
559 gfx::Size(10, 10), 25, media::PIXEL_FORMAT_ARGB); | 609 gfx::Size(10, 10), 25, media::PIXEL_FORMAT_ARGB); |
560 | 610 |
561 // Start the device. Then, before the first buffer, signal an error and | 611 // Start the device. Then, before the first buffer, signal an error and |
562 // deliver the buffer. The error should be propagated to clients; the buffer | 612 // deliver the buffer. The error should be propagated to clients; the buffer |
563 // should not be. | 613 // should not be. |
564 base::RunLoop().RunUntilIdle(); | 614 base::RunLoop().RunUntilIdle(); |
565 Mock::VerifyAndClearExpectations(client_a_.get()); | 615 Mock::VerifyAndClearExpectations(client_a_.get()); |
566 | 616 |
567 const gfx::Size dims(320, 240); | 617 const gfx::Size dims(320, 240); |
568 const int arbitrary_frame_feedback_id = 101; | 618 const int arbitrary_frame_feedback_id = 101; |
569 std::unique_ptr<media::VideoCaptureDevice::Client::Buffer> buffer( | 619 std::unique_ptr<media::VideoCaptureDevice::Client::Buffer> buffer( |
570 device_->ReserveOutputBuffer(dims, media::PIXEL_FORMAT_I420, | 620 device_client_->ReserveOutputBuffer(dims, media::PIXEL_FORMAT_I420, |
571 media::PIXEL_STORAGE_CPU, | 621 media::PIXEL_STORAGE_CPU, |
572 arbitrary_frame_feedback_id)); | 622 arbitrary_frame_feedback_id)); |
573 ASSERT_TRUE(buffer.get()); | 623 ASSERT_TRUE(buffer.get()); |
574 | 624 |
575 scoped_refptr<media::VideoFrame> video_frame = | 625 scoped_refptr<media::VideoFrame> video_frame = |
576 WrapBuffer(dims, static_cast<uint8_t*>(buffer->data())); | 626 WrapBuffer(dims, static_cast<uint8_t*>(buffer->data())); |
577 ASSERT_TRUE(video_frame); | 627 ASSERT_TRUE(video_frame); |
578 device_->OnError(FROM_HERE, "Test Error"); | 628 device_client_->OnError(FROM_HERE, "Test Error"); |
579 video_frame->metadata()->SetTimeTicks( | 629 video_frame->metadata()->SetTimeTicks( |
580 media::VideoFrameMetadata::REFERENCE_TIME, base::TimeTicks()); | 630 media::VideoFrameMetadata::REFERENCE_TIME, base::TimeTicks()); |
581 device_->OnIncomingCapturedVideoFrame(std::move(buffer), video_frame); | 631 device_client_->OnIncomingCapturedVideoFrame(std::move(buffer), video_frame); |
582 | 632 |
583 EXPECT_CALL(*client_a_, DoError(route_id)).Times(1); | 633 EXPECT_CALL(*client_a_, DoError(route_id)).Times(1); |
584 base::RunLoop().RunUntilIdle(); | 634 base::RunLoop().RunUntilIdle(); |
585 Mock::VerifyAndClearExpectations(client_a_.get()); | 635 Mock::VerifyAndClearExpectations(client_a_.get()); |
586 | 636 |
587 // Second client connects after the error state. It also should get told of | 637 // Second client connects after the error state. It also should get told of |
588 // the error. | 638 // the error. |
589 EXPECT_CALL(*client_b_, DoError(route_id)).Times(1); | 639 EXPECT_CALL(*client_b_, DoError(route_id)).Times(1); |
590 controller_->AddClient(route_id, client_b_.get(), 200, session_200); | 640 controller_->AddClient(route_id, client_b_.get(), 200, session_200); |
591 Mock::VerifyAndClearExpectations(client_b_.get()); | 641 Mock::VerifyAndClearExpectations(client_b_.get()); |
592 } | 642 } |
593 | 643 |
594 } // namespace content | 644 } // namespace content |
OLD | NEW |