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