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. | |
6 | |
7 #include "content/browser/renderer_host/media/video_capture_controller.h" | 5 #include "content/browser/renderer_host/media/video_capture_controller.h" |
8 | 6 |
9 #include <stdint.h> | 7 #include <stdint.h> |
10 #include <string.h> | 8 #include <string.h> |
11 | 9 |
12 #include <memory> | 10 #include <memory> |
13 #include <string> | 11 #include <string> |
14 #include <utility> | 12 #include <utility> |
15 | 13 |
16 #include "base/bind.h" | 14 #include "base/bind.h" |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
51 return base::MakeUnique<content::VideoCaptureGpuJpegDecoder>(decode_done_cb); | 49 return base::MakeUnique<content::VideoCaptureGpuJpegDecoder>(decode_done_cb); |
52 } | 50 } |
53 | 51 |
54 class MockVideoCaptureControllerEventHandler | 52 class MockVideoCaptureControllerEventHandler |
55 : public VideoCaptureControllerEventHandler { | 53 : public VideoCaptureControllerEventHandler { |
56 public: | 54 public: |
57 explicit MockVideoCaptureControllerEventHandler( | 55 explicit MockVideoCaptureControllerEventHandler( |
58 VideoCaptureController* controller) | 56 VideoCaptureController* controller) |
59 : controller_(controller), resource_utilization_(-1.0) {} | 57 : controller_(controller), resource_utilization_(-1.0) {} |
60 ~MockVideoCaptureControllerEventHandler() override {} | 58 ~MockVideoCaptureControllerEventHandler() override {} |
| 59 void set_enable_auto_return_buffer_on_buffer_ready(bool enable) { |
| 60 enable_auto_return_buffer_on_buffer_ready_ = enable; |
| 61 } |
61 | 62 |
62 // These mock methods are delegated to by our fake implementation of | 63 // These mock methods are delegated to by our fake implementation of |
63 // VideoCaptureControllerEventHandler, to be used in EXPECT_CALL(). | 64 // VideoCaptureControllerEventHandler, to be used in EXPECT_CALL(). |
64 MOCK_METHOD1(DoBufferCreated, void(VideoCaptureControllerID)); | 65 MOCK_METHOD2(DoBufferCreated, void(VideoCaptureControllerID, int buffer_id)); |
65 MOCK_METHOD1(DoBufferDestroyed, void(VideoCaptureControllerID)); | 66 MOCK_METHOD2(DoBufferDestroyed, |
| 67 void(VideoCaptureControllerID, int buffer_id)); |
66 MOCK_METHOD2(DoBufferReady, void(VideoCaptureControllerID, const gfx::Size&)); | 68 MOCK_METHOD2(DoBufferReady, void(VideoCaptureControllerID, const gfx::Size&)); |
67 MOCK_METHOD1(DoEnded, void(VideoCaptureControllerID)); | 69 MOCK_METHOD1(DoEnded, void(VideoCaptureControllerID)); |
68 MOCK_METHOD1(DoError, void(VideoCaptureControllerID)); | 70 MOCK_METHOD1(DoError, void(VideoCaptureControllerID)); |
69 | 71 |
70 void OnError(VideoCaptureControllerID id) override { DoError(id); } | 72 void OnError(VideoCaptureControllerID id) override { DoError(id); } |
71 void OnBufferCreated(VideoCaptureControllerID id, | 73 void OnBufferCreated(VideoCaptureControllerID id, |
72 mojo::ScopedSharedBufferHandle handle, | 74 mojo::ScopedSharedBufferHandle handle, |
73 int length, | 75 int length, |
74 int buffer_id) override { | 76 int buffer_id) override { |
75 DoBufferCreated(id); | 77 DoBufferCreated(id, buffer_id); |
76 } | 78 } |
77 void OnBufferDestroyed(VideoCaptureControllerID id, int buffer_id) override { | 79 void OnBufferDestroyed(VideoCaptureControllerID id, int buffer_id) override { |
78 DoBufferDestroyed(id); | 80 DoBufferDestroyed(id, buffer_id); |
79 } | 81 } |
80 void OnBufferReady(VideoCaptureControllerID id, | 82 void OnBufferReady(VideoCaptureControllerID id, |
81 int buffer_id, | 83 int buffer_id, |
82 const scoped_refptr<media::VideoFrame>& frame) override { | 84 const scoped_refptr<media::VideoFrame>& frame) override { |
83 EXPECT_EQ(expected_pixel_format_, frame->format()); | 85 EXPECT_EQ(expected_pixel_format_, frame->format()); |
84 base::TimeTicks reference_time; | 86 base::TimeTicks reference_time; |
85 EXPECT_TRUE(frame->metadata()->GetTimeTicks( | 87 EXPECT_TRUE(frame->metadata()->GetTimeTicks( |
86 media::VideoFrameMetadata::REFERENCE_TIME, &reference_time)); | 88 media::VideoFrameMetadata::REFERENCE_TIME, &reference_time)); |
87 DoBufferReady(id, frame->coded_size()); | 89 DoBufferReady(id, frame->coded_size()); |
88 base::ThreadTaskRunnerHandle::Get()->PostTask( | 90 if (enable_auto_return_buffer_on_buffer_ready_) { |
89 FROM_HERE, base::Bind(&VideoCaptureController::ReturnBuffer, | 91 base::ThreadTaskRunnerHandle::Get()->PostTask( |
90 base::Unretained(controller_), id, this, | 92 FROM_HERE, base::Bind(&VideoCaptureController::ReturnBuffer, |
91 buffer_id, resource_utilization_)); | 93 base::Unretained(controller_), id, this, |
| 94 buffer_id, resource_utilization_)); |
| 95 } |
92 } | 96 } |
93 void OnEnded(VideoCaptureControllerID id) override { | 97 void OnEnded(VideoCaptureControllerID id) override { |
94 DoEnded(id); | 98 DoEnded(id); |
95 // OnEnded() must respond by (eventually) unregistering the client. | 99 // OnEnded() must respond by (eventually) unregistering the client. |
96 base::ThreadTaskRunnerHandle::Get()->PostTask( | 100 base::ThreadTaskRunnerHandle::Get()->PostTask( |
97 FROM_HERE, | 101 FROM_HERE, |
98 base::Bind(base::IgnoreResult(&VideoCaptureController::RemoveClient), | 102 base::Bind(base::IgnoreResult(&VideoCaptureController::RemoveClient), |
99 base::Unretained(controller_), id, this)); | 103 base::Unretained(controller_), id, this)); |
100 } | 104 } |
101 | 105 |
102 VideoCaptureController* controller_; | 106 VideoCaptureController* controller_; |
103 media::VideoPixelFormat expected_pixel_format_ = media::PIXEL_FORMAT_I420; | 107 media::VideoPixelFormat expected_pixel_format_ = media::PIXEL_FORMAT_I420; |
104 double resource_utilization_; | 108 double resource_utilization_; |
| 109 bool enable_auto_return_buffer_on_buffer_ready_ = true; |
105 }; | 110 }; |
106 | 111 |
107 class MockConsumerFeedbackObserver | 112 class MockConsumerFeedbackObserver |
108 : public media::VideoFrameConsumerFeedbackObserver { | 113 : public media::VideoFrameConsumerFeedbackObserver { |
109 public: | 114 public: |
110 MOCK_METHOD2(OnUtilizationReport, | 115 MOCK_METHOD2(OnUtilizationReport, |
111 void(int frame_feedback_id, double utilization)); | 116 void(int frame_feedback_id, double utilization)); |
112 }; | 117 }; |
113 | 118 |
114 class MockFrameBufferPool : public media::FrameBufferPool { | 119 class MockFrameBufferPool : public media::FrameBufferPool { |
115 public: | 120 public: |
116 MOCK_METHOD1(SetBufferHold, void(int buffer_id)); | 121 MOCK_METHOD1(SetBufferHold, void(int buffer_id)); |
117 MOCK_METHOD1(ReleaseBufferHold, void(int buffer_id)); | 122 MOCK_METHOD1(ReleaseBufferHold, void(int buffer_id)); |
118 }; | 123 }; |
119 | 124 |
120 // Test class. | 125 // Test fixture for testing a unit consisting of an instance of |
| 126 // VideoCaptureController connected to an instance of VideoCaptureDeviceClient, |
| 127 // an instance of VideoCaptureBufferPoolImpl, as well as related threading glue |
| 128 // that replicates how it is used in production. |
121 class VideoCaptureControllerTest | 129 class VideoCaptureControllerTest |
122 : public testing::Test, | 130 : public testing::Test, |
123 public testing::WithParamInterface<media::VideoPixelFormat> { | 131 public testing::WithParamInterface<media::VideoPixelFormat> { |
124 public: | 132 public: |
125 VideoCaptureControllerTest() {} | 133 VideoCaptureControllerTest() |
| 134 : arbitrary_format_(gfx::Size(320, 240), 30, media::PIXEL_FORMAT_I420), |
| 135 arbitrary_route_id_(0x99), |
| 136 arbitrary_session_id_(100) {} |
126 ~VideoCaptureControllerTest() override {} | 137 ~VideoCaptureControllerTest() override {} |
127 | 138 |
128 protected: | 139 protected: |
129 static const int kPoolSize = 3; | 140 static const int kPoolSize = 3; |
130 | 141 |
131 void SetUp() override { | 142 void SetUp() override { |
132 scoped_refptr<media::VideoCaptureBufferPool> buffer_pool( | |
133 new media::VideoCaptureBufferPoolImpl( | |
134 base::MakeUnique<media::VideoCaptureBufferTrackerFactoryImpl>(), | |
135 kPoolSize)); | |
136 controller_.reset(new VideoCaptureController()); | 143 controller_.reset(new VideoCaptureController()); |
137 device_client_.reset(new media::VideoCaptureDeviceClient( | 144 InitializeNewDeviceClientAndBufferPoolInstances(); |
138 base::MakeUnique<VideoFrameReceiverOnIOThread>( | |
139 controller_->GetWeakPtrForIOThread()), | |
140 buffer_pool, | |
141 base::Bind( | |
142 &CreateGpuJpegDecoder, | |
143 base::Bind(&media::VideoFrameReceiver::OnIncomingCapturedVideoFrame, | |
144 controller_->GetWeakPtrForIOThread())))); | |
145 auto frame_receiver_observer = base::MakeUnique<MockFrameBufferPool>(); | 145 auto frame_receiver_observer = base::MakeUnique<MockFrameBufferPool>(); |
146 mock_frame_receiver_observer_ = frame_receiver_observer.get(); | 146 mock_frame_receiver_observer_ = frame_receiver_observer.get(); |
147 controller_->SetFrameBufferPool(std::move(frame_receiver_observer)); | 147 controller_->SetFrameBufferPool(std::move(frame_receiver_observer)); |
148 auto consumer_feedback_observer = | 148 auto consumer_feedback_observer = |
149 base::MakeUnique<MockConsumerFeedbackObserver>(); | 149 base::MakeUnique<MockConsumerFeedbackObserver>(); |
150 mock_consumer_feedback_observer_ = consumer_feedback_observer.get(); | 150 mock_consumer_feedback_observer_ = consumer_feedback_observer.get(); |
151 controller_->SetConsumerFeedbackObserver( | 151 controller_->SetConsumerFeedbackObserver( |
152 std::move(consumer_feedback_observer)); | 152 std::move(consumer_feedback_observer)); |
153 client_a_.reset( | 153 client_a_.reset( |
154 new MockVideoCaptureControllerEventHandler(controller_.get())); | 154 new MockVideoCaptureControllerEventHandler(controller_.get())); |
155 client_b_.reset( | 155 client_b_.reset( |
156 new MockVideoCaptureControllerEventHandler(controller_.get())); | 156 new MockVideoCaptureControllerEventHandler(controller_.get())); |
157 } | 157 } |
158 | 158 |
159 void TearDown() override { base::RunLoop().RunUntilIdle(); } | 159 void TearDown() override { base::RunLoop().RunUntilIdle(); } |
160 | 160 |
| 161 void InitializeNewDeviceClientAndBufferPoolInstances() { |
| 162 buffer_pool_ = new media::VideoCaptureBufferPoolImpl( |
| 163 base::MakeUnique<media::VideoCaptureBufferTrackerFactoryImpl>(), |
| 164 kPoolSize); |
| 165 device_client_.reset(new media::VideoCaptureDeviceClient( |
| 166 base::MakeUnique<VideoFrameReceiverOnIOThread>( |
| 167 controller_->GetWeakPtrForIOThread()), |
| 168 buffer_pool_, |
| 169 base::Bind( |
| 170 &CreateGpuJpegDecoder, |
| 171 base::Bind(&media::VideoFrameReceiver::OnIncomingCapturedVideoFrame, |
| 172 controller_->GetWeakPtrForIOThread())))); |
| 173 } |
| 174 |
| 175 void SendStubFrameToDeviceClient(const media::VideoCaptureFormat format) { |
| 176 auto stub_frame = media::VideoFrame::CreateZeroInitializedFrame( |
| 177 format.pixel_format, format.frame_size, |
| 178 gfx::Rect(format.frame_size.width(), format.frame_size.height()), |
| 179 format.frame_size, base::TimeDelta()); |
| 180 const int rotation = 0; |
| 181 const int frame_feedback_id = 0; |
| 182 device_client_->OnIncomingCapturedData( |
| 183 stub_frame->data(0), |
| 184 media::VideoFrame::AllocationSize(stub_frame->format(), |
| 185 stub_frame->coded_size()), |
| 186 format, rotation, base::TimeTicks(), base::TimeDelta(), |
| 187 frame_feedback_id); |
| 188 } |
| 189 |
161 TestBrowserThreadBundle bundle_; | 190 TestBrowserThreadBundle bundle_; |
| 191 scoped_refptr<media::VideoCaptureBufferPool> buffer_pool_; |
162 std::unique_ptr<MockVideoCaptureControllerEventHandler> client_a_; | 192 std::unique_ptr<MockVideoCaptureControllerEventHandler> client_a_; |
163 std::unique_ptr<MockVideoCaptureControllerEventHandler> client_b_; | 193 std::unique_ptr<MockVideoCaptureControllerEventHandler> client_b_; |
164 std::unique_ptr<VideoCaptureController> controller_; | 194 std::unique_ptr<VideoCaptureController> controller_; |
165 std::unique_ptr<media::VideoCaptureDevice::Client> device_client_; | 195 std::unique_ptr<media::VideoCaptureDevice::Client> device_client_; |
166 MockFrameBufferPool* mock_frame_receiver_observer_; | 196 MockFrameBufferPool* mock_frame_receiver_observer_; |
167 MockConsumerFeedbackObserver* mock_consumer_feedback_observer_; | 197 MockConsumerFeedbackObserver* mock_consumer_feedback_observer_; |
168 const float arbitrary_frame_rate_ = 10.0f; | 198 const float arbitrary_frame_rate_ = 10.0f; |
169 const base::TimeTicks arbitrary_reference_time_ = base::TimeTicks(); | 199 const base::TimeTicks arbitrary_reference_time_ = base::TimeTicks(); |
170 const base::TimeDelta arbitrary_timestamp_ = base::TimeDelta(); | 200 const base::TimeDelta arbitrary_timestamp_ = base::TimeDelta(); |
| 201 const media::VideoCaptureFormat arbitrary_format_; |
| 202 const VideoCaptureControllerID arbitrary_route_id_; |
| 203 const media::VideoCaptureSessionId arbitrary_session_id_; |
171 | 204 |
172 private: | 205 private: |
173 DISALLOW_COPY_AND_ASSIGN(VideoCaptureControllerTest); | 206 DISALLOW_COPY_AND_ASSIGN(VideoCaptureControllerTest); |
174 }; | 207 }; |
175 | 208 |
176 // A simple test of VideoCaptureController's ability to add, remove, and keep | 209 // A simple test of VideoCaptureController's ability to add, remove, and keep |
177 // track of clients. | 210 // track of clients. |
178 TEST_F(VideoCaptureControllerTest, AddAndRemoveClients) { | 211 TEST_F(VideoCaptureControllerTest, AddAndRemoveClients) { |
179 media::VideoCaptureParams session_100; | 212 media::VideoCaptureParams session_100; |
180 session_100.requested_format = media::VideoCaptureFormat( | 213 session_100.requested_format = media::VideoCaptureFormat( |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
292 media::VideoCaptureDevice::Client::Buffer buffer = | 325 media::VideoCaptureDevice::Client::Buffer buffer = |
293 device_client_->ReserveOutputBuffer( | 326 device_client_->ReserveOutputBuffer( |
294 device_format.frame_size, device_format.pixel_format, | 327 device_format.frame_size, device_format.pixel_format, |
295 device_format.pixel_storage, arbitrary_frame_feedback_id); | 328 device_format.pixel_storage, arbitrary_frame_feedback_id); |
296 ASSERT_TRUE(buffer.is_valid()); | 329 ASSERT_TRUE(buffer.is_valid()); |
297 auto buffer_access = buffer.handle_provider()->GetHandleForInProcessAccess(); | 330 auto buffer_access = buffer.handle_provider()->GetHandleForInProcessAccess(); |
298 ASSERT_EQ(1.0 / kPoolSize, device_client_->GetBufferPoolUtilization()); | 331 ASSERT_EQ(1.0 / kPoolSize, device_client_->GetBufferPoolUtilization()); |
299 memset(buffer_access->data(), buffer_no++, buffer_access->mapped_size()); | 332 memset(buffer_access->data(), buffer_no++, buffer_access->mapped_size()); |
300 { | 333 { |
301 InSequence s; | 334 InSequence s; |
302 EXPECT_CALL(*client_a_, DoBufferCreated(client_a_route_1)).Times(1); | 335 EXPECT_CALL(*client_a_, DoBufferCreated(client_a_route_1, _)).Times(1); |
303 EXPECT_CALL(*client_a_, | 336 EXPECT_CALL(*client_a_, |
304 DoBufferReady(client_a_route_1, device_format.frame_size)) | 337 DoBufferReady(client_a_route_1, device_format.frame_size)) |
305 .Times(1); | 338 .Times(1); |
306 } | 339 } |
307 { | 340 { |
308 InSequence s; | 341 InSequence s; |
309 EXPECT_CALL(*client_b_, DoBufferCreated(client_b_route_1)).Times(1); | 342 EXPECT_CALL(*client_b_, DoBufferCreated(client_b_route_1, _)).Times(1); |
310 EXPECT_CALL(*client_b_, | 343 EXPECT_CALL(*client_b_, |
311 DoBufferReady(client_b_route_1, device_format.frame_size)) | 344 DoBufferReady(client_b_route_1, device_format.frame_size)) |
312 .Times(1); | 345 .Times(1); |
313 } | 346 } |
314 { | 347 { |
315 InSequence s; | 348 InSequence s; |
316 EXPECT_CALL(*client_a_, DoBufferCreated(client_a_route_2)).Times(1); | 349 EXPECT_CALL(*client_a_, DoBufferCreated(client_a_route_2, _)).Times(1); |
317 EXPECT_CALL(*client_a_, | 350 EXPECT_CALL(*client_a_, |
318 DoBufferReady(client_a_route_2, device_format.frame_size)) | 351 DoBufferReady(client_a_route_2, device_format.frame_size)) |
319 .Times(1); | 352 .Times(1); |
320 } | 353 } |
321 client_a_->resource_utilization_ = 0.5; | 354 client_a_->resource_utilization_ = 0.5; |
322 client_b_->resource_utilization_ = -1.0; | 355 client_b_->resource_utilization_ = -1.0; |
323 { | 356 { |
324 InSequence s; | 357 InSequence s; |
325 EXPECT_CALL(*mock_frame_receiver_observer_, SetBufferHold(buffer.id())) | 358 EXPECT_CALL(*mock_frame_receiver_observer_, SetBufferHold(buffer.id())) |
326 .Times(1); | 359 .Times(1); |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
372 .Times(1); | 405 .Times(1); |
373 } | 406 } |
374 | 407 |
375 device_client_->OnIncomingCapturedBuffer(std::move(buffer2), device_format, | 408 device_client_->OnIncomingCapturedBuffer(std::move(buffer2), device_format, |
376 arbitrary_reference_time_, | 409 arbitrary_reference_time_, |
377 arbitrary_timestamp_); | 410 arbitrary_timestamp_); |
378 | 411 |
379 // The buffer should be delivered to the clients in any order. | 412 // The buffer should be delivered to the clients in any order. |
380 { | 413 { |
381 InSequence s; | 414 InSequence s; |
382 EXPECT_CALL(*client_a_, DoBufferCreated(client_a_route_1)).Times(1); | 415 EXPECT_CALL(*client_a_, DoBufferCreated(client_a_route_1, _)).Times(1); |
383 EXPECT_CALL(*client_a_, | 416 EXPECT_CALL(*client_a_, |
384 DoBufferReady(client_a_route_1, device_format.frame_size)) | 417 DoBufferReady(client_a_route_1, device_format.frame_size)) |
385 .Times(1); | 418 .Times(1); |
386 } | 419 } |
387 { | 420 { |
388 InSequence s; | 421 InSequence s; |
389 EXPECT_CALL(*client_b_, DoBufferCreated(client_b_route_1)).Times(1); | 422 EXPECT_CALL(*client_b_, DoBufferCreated(client_b_route_1, _)).Times(1); |
390 EXPECT_CALL(*client_b_, | 423 EXPECT_CALL(*client_b_, |
391 DoBufferReady(client_b_route_1, device_format.frame_size)) | 424 DoBufferReady(client_b_route_1, device_format.frame_size)) |
392 .Times(1); | 425 .Times(1); |
393 } | 426 } |
394 { | 427 { |
395 InSequence s; | 428 InSequence s; |
396 EXPECT_CALL(*client_a_, DoBufferCreated(client_a_route_2)).Times(1); | 429 EXPECT_CALL(*client_a_, DoBufferCreated(client_a_route_2, _)).Times(1); |
397 EXPECT_CALL(*client_a_, | 430 EXPECT_CALL(*client_a_, |
398 DoBufferReady(client_a_route_2, device_format.frame_size)) | 431 DoBufferReady(client_a_route_2, device_format.frame_size)) |
399 .Times(1); | 432 .Times(1); |
400 } | 433 } |
401 base::RunLoop().RunUntilIdle(); | 434 base::RunLoop().RunUntilIdle(); |
402 Mock::VerifyAndClearExpectations(client_a_.get()); | 435 Mock::VerifyAndClearExpectations(client_a_.get()); |
403 Mock::VerifyAndClearExpectations(client_b_.get()); | 436 Mock::VerifyAndClearExpectations(client_b_.get()); |
404 Mock::VerifyAndClearExpectations(mock_consumer_feedback_observer_); | 437 Mock::VerifyAndClearExpectations(mock_consumer_feedback_observer_); |
405 Mock::VerifyAndClearExpectations(mock_frame_receiver_observer_); | 438 Mock::VerifyAndClearExpectations(mock_frame_receiver_observer_); |
406 | 439 |
(...skipping 18 matching lines...) Expand all Loading... |
425 } | 458 } |
426 // ReserveOutputBuffer ought to fail now, because the pool is depleted. | 459 // ReserveOutputBuffer ought to fail now, because the pool is depleted. |
427 ASSERT_FALSE(device_client_ | 460 ASSERT_FALSE(device_client_ |
428 ->ReserveOutputBuffer( | 461 ->ReserveOutputBuffer( |
429 device_format.frame_size, device_format.pixel_format, | 462 device_format.frame_size, device_format.pixel_format, |
430 device_format.pixel_storage, arbitrary_frame_feedback_id) | 463 device_format.pixel_storage, arbitrary_frame_feedback_id) |
431 .is_valid()); | 464 .is_valid()); |
432 | 465 |
433 // The new client needs to be notified of the creation of |kPoolSize| buffers; | 466 // The new client needs to be notified of the creation of |kPoolSize| buffers; |
434 // the old clients only |kPoolSize - 2|. | 467 // the old clients only |kPoolSize - 2|. |
435 EXPECT_CALL(*client_b_, DoBufferCreated(client_b_route_2)).Times(kPoolSize); | 468 EXPECT_CALL(*client_b_, DoBufferCreated(client_b_route_2, _)) |
| 469 .Times(kPoolSize); |
436 EXPECT_CALL(*client_b_, | 470 EXPECT_CALL(*client_b_, |
437 DoBufferReady(client_b_route_2, device_format.frame_size)) | 471 DoBufferReady(client_b_route_2, device_format.frame_size)) |
438 .Times(kPoolSize); | 472 .Times(kPoolSize); |
439 EXPECT_CALL(*client_a_, DoBufferCreated(client_a_route_1)) | 473 EXPECT_CALL(*client_a_, DoBufferCreated(client_a_route_1, _)) |
440 .Times(kPoolSize - 2); | 474 .Times(kPoolSize - 2); |
441 EXPECT_CALL(*client_a_, | 475 EXPECT_CALL(*client_a_, |
442 DoBufferReady(client_a_route_1, device_format.frame_size)) | 476 DoBufferReady(client_a_route_1, device_format.frame_size)) |
443 .Times(kPoolSize); | 477 .Times(kPoolSize); |
444 EXPECT_CALL(*client_a_, DoBufferCreated(client_a_route_2)) | 478 EXPECT_CALL(*client_a_, DoBufferCreated(client_a_route_2, _)) |
445 .Times(kPoolSize - 2); | 479 .Times(kPoolSize - 2); |
446 EXPECT_CALL(*client_a_, | 480 EXPECT_CALL(*client_a_, |
447 DoBufferReady(client_a_route_2, device_format.frame_size)) | 481 DoBufferReady(client_a_route_2, device_format.frame_size)) |
448 .Times(kPoolSize); | 482 .Times(kPoolSize); |
449 EXPECT_CALL(*client_b_, DoBufferCreated(client_b_route_1)) | 483 EXPECT_CALL(*client_b_, DoBufferCreated(client_b_route_1, _)) |
450 .Times(kPoolSize - 2); | 484 .Times(kPoolSize - 2); |
451 EXPECT_CALL(*client_b_, | 485 EXPECT_CALL(*client_b_, |
452 DoBufferReady(client_b_route_1, device_format.frame_size)) | 486 DoBufferReady(client_b_route_1, device_format.frame_size)) |
453 .Times(kPoolSize); | 487 .Times(kPoolSize); |
454 base::RunLoop().RunUntilIdle(); | 488 base::RunLoop().RunUntilIdle(); |
455 Mock::VerifyAndClearExpectations(client_a_.get()); | 489 Mock::VerifyAndClearExpectations(client_a_.get()); |
456 Mock::VerifyAndClearExpectations(client_b_.get()); | 490 Mock::VerifyAndClearExpectations(client_b_.get()); |
457 | 491 |
458 // Now test the interaction of client shutdown and buffer delivery. | 492 // Now test the interaction of client shutdown and buffer delivery. |
459 // Kill A1 via renderer disconnect (synchronous). | 493 // Kill A1 via renderer disconnect (synchronous). |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
586 base::RunLoop().RunUntilIdle(); | 620 base::RunLoop().RunUntilIdle(); |
587 Mock::VerifyAndClearExpectations(client_a_.get()); | 621 Mock::VerifyAndClearExpectations(client_a_.get()); |
588 | 622 |
589 // Second client connects after the error state. It also should get told of | 623 // Second client connects after the error state. It also should get told of |
590 // the error. | 624 // the error. |
591 EXPECT_CALL(*client_b_, DoError(route_id)).Times(1); | 625 EXPECT_CALL(*client_b_, DoError(route_id)).Times(1); |
592 controller_->AddClient(route_id, client_b_.get(), 200, session_200); | 626 controller_->AddClient(route_id, client_b_.get(), 200, session_200); |
593 Mock::VerifyAndClearExpectations(client_b_.get()); | 627 Mock::VerifyAndClearExpectations(client_b_.get()); |
594 } | 628 } |
595 | 629 |
| 630 TEST_F(VideoCaptureControllerTest, |
| 631 DeviceClientIsReleasedBeforeAnyBufferWasShared) { |
| 632 // Register |client_a_| at |controller_|. |
| 633 media::VideoCaptureParams requested_params; |
| 634 requested_params.requested_format = arbitrary_format_; |
| 635 controller_->AddClient(arbitrary_route_id_, client_a_.get(), |
| 636 arbitrary_session_id_, requested_params); |
| 637 base::RunLoop().RunUntilIdle(); |
| 638 |
| 639 // |device_client_| is released by the device. |
| 640 EXPECT_CALL(*client_a_, DoBufferDestroyed(arbitrary_route_id_, _)).Times(0); |
| 641 device_client_.reset(); |
| 642 base::RunLoop().RunUntilIdle(); |
| 643 Mock::VerifyAndClearExpectations(client_a_.get()); |
| 644 } |
| 645 |
| 646 TEST_F(VideoCaptureControllerTest, |
| 647 DeviceClientIsReleasedAfterFrameHasBeenConsumed) { |
| 648 // Register |client_a_| at |controller_|. |
| 649 media::VideoCaptureParams requested_params; |
| 650 requested_params.requested_format = arbitrary_format_; |
| 651 controller_->AddClient(arbitrary_route_id_, client_a_.get(), |
| 652 arbitrary_session_id_, requested_params); |
| 653 base::RunLoop().RunUntilIdle(); |
| 654 |
| 655 // Device sends a frame to |device_client_| and |client_a_| reports to |
| 656 // |controller_| that it has finished consuming the frame. |
| 657 { |
| 658 InSequence s; |
| 659 EXPECT_CALL(*client_a_, DoBufferCreated(_, _)) |
| 660 .Times(1); |
| 661 EXPECT_CALL(*client_a_, DoBufferReady(_, _)).Times(1); |
| 662 } |
| 663 EXPECT_CALL(*client_a_, DoBufferDestroyed(_, _)).Times(0); |
| 664 SendStubFrameToDeviceClient(arbitrary_format_); |
| 665 base::RunLoop().RunUntilIdle(); |
| 666 Mock::VerifyAndClearExpectations(client_a_.get()); |
| 667 |
| 668 // |device_client_| is released by the device. |
| 669 EXPECT_CALL(*client_a_, DoBufferDestroyed(_, _)).Times(1); |
| 670 device_client_.reset(); |
| 671 base::RunLoop().RunUntilIdle(); |
| 672 Mock::VerifyAndClearExpectations(client_a_.get()); |
| 673 } |
| 674 |
| 675 TEST_F(VideoCaptureControllerTest, |
| 676 DeviceClientIsReleasedWhileFrameIsBeingConsumed) { |
| 677 client_a_->set_enable_auto_return_buffer_on_buffer_ready(false); |
| 678 // Register |client_a_| at |controller_|. |
| 679 media::VideoCaptureParams requested_params; |
| 680 requested_params.requested_format = arbitrary_format_; |
| 681 controller_->AddClient(arbitrary_route_id_, client_a_.get(), |
| 682 arbitrary_session_id_, requested_params); |
| 683 base::RunLoop().RunUntilIdle(); |
| 684 |
| 685 // Device sends a frame to |device_client_|. |
| 686 int buffer_id = 0; |
| 687 { |
| 688 InSequence s; |
| 689 EXPECT_CALL(*client_a_, DoBufferCreated(_, _)) |
| 690 .Times(1) |
| 691 .WillOnce(SaveArg<1>(&buffer_id)); |
| 692 EXPECT_CALL(*client_a_, DoBufferReady(_, _)).Times(1); |
| 693 } |
| 694 SendStubFrameToDeviceClient(arbitrary_format_); |
| 695 base::RunLoop().RunUntilIdle(); |
| 696 Mock::VerifyAndClearExpectations(client_a_.get()); |
| 697 |
| 698 // |device_client_| is released by the device. |
| 699 EXPECT_CALL(*client_a_, DoBufferDestroyed(_, _)).Times(0); |
| 700 device_client_.reset(); |
| 701 base::RunLoop().RunUntilIdle(); |
| 702 Mock::VerifyAndClearExpectations(client_a_.get()); |
| 703 |
| 704 // |client_a_| signals to |controller_| that it has finished consuming the |
| 705 // frame. |
| 706 EXPECT_CALL(*client_a_, DoBufferDestroyed(_, _)).Times(1); |
| 707 const double arbitrary_utilization = 0.0; |
| 708 controller_->ReturnBuffer(arbitrary_route_id_, client_a_.get(), buffer_id, |
| 709 arbitrary_utilization); |
| 710 base::RunLoop().RunUntilIdle(); |
| 711 Mock::VerifyAndClearExpectations(client_a_.get()); |
| 712 } |
| 713 |
| 714 TEST_F(VideoCaptureControllerTest, |
| 715 NewDeviceClientSendsNewBufferWhileRetiredBufferStillBeingConsumed) { |
| 716 client_a_->set_enable_auto_return_buffer_on_buffer_ready(false); |
| 717 // Register |client_a_| at |controller_|. |
| 718 media::VideoCaptureParams requested_params; |
| 719 requested_params.requested_format = arbitrary_format_; |
| 720 controller_->AddClient(arbitrary_route_id_, client_a_.get(), |
| 721 arbitrary_session_id_, requested_params); |
| 722 base::RunLoop().RunUntilIdle(); |
| 723 |
| 724 // Device sends a frame to |device_client_|. |
| 725 int first_buffer_id = 0; |
| 726 { |
| 727 InSequence s; |
| 728 EXPECT_CALL(*client_a_, DoBufferCreated(_, _)) |
| 729 .Times(1) |
| 730 .WillOnce(SaveArg<1>(&first_buffer_id)); |
| 731 EXPECT_CALL(*client_a_, DoBufferReady(_, _)).Times(1); |
| 732 } |
| 733 SendStubFrameToDeviceClient(arbitrary_format_); |
| 734 base::RunLoop().RunUntilIdle(); |
| 735 Mock::VerifyAndClearExpectations(client_a_.get()); |
| 736 |
| 737 // |device_client_| is released by the device. |
| 738 EXPECT_CALL(*client_a_, DoBufferDestroyed(_, _)).Times(0); |
| 739 device_client_.reset(); |
| 740 base::RunLoop().RunUntilIdle(); |
| 741 Mock::VerifyAndClearExpectations(client_a_.get()); |
| 742 |
| 743 // A new |device_client_| is created with a new buffer pool. |
| 744 InitializeNewDeviceClientAndBufferPoolInstances(); |
| 745 |
| 746 // Device sends a frame to the new |device_client_|. |
| 747 int second_buffer_id = 0; |
| 748 { |
| 749 InSequence s; |
| 750 EXPECT_CALL(*client_a_, DoBufferCreated(_, _)) |
| 751 .Times(1) |
| 752 .WillOnce(SaveArg<1>(&second_buffer_id)); |
| 753 EXPECT_CALL(*client_a_, DoBufferReady(_, _)).Times(1); |
| 754 } |
| 755 SendStubFrameToDeviceClient(arbitrary_format_); |
| 756 base::RunLoop().RunUntilIdle(); |
| 757 Mock::VerifyAndClearExpectations(client_a_.get()); |
| 758 |
| 759 EXPECT_NE(first_buffer_id, second_buffer_id); |
| 760 |
| 761 // |client_a_| signals to |controller_| that it has finished consuming the |
| 762 // first frame. |
| 763 EXPECT_CALL(*client_a_, DoBufferDestroyed(_, first_buffer_id)).Times(1); |
| 764 EXPECT_CALL(*client_a_, DoBufferDestroyed(_, second_buffer_id)).Times(0); |
| 765 const double arbitrary_utilization = 0.0; |
| 766 controller_->ReturnBuffer(arbitrary_route_id_, client_a_.get(), |
| 767 first_buffer_id, arbitrary_utilization); |
| 768 base::RunLoop().RunUntilIdle(); |
| 769 Mock::VerifyAndClearExpectations(client_a_.get()); |
| 770 |
| 771 // |client_a_| signals to |controller_| that it has finished consuming the |
| 772 // second frame. Since the new |device_client_| is still alive, the second |
| 773 // buffer is expected to stay alive. |
| 774 EXPECT_CALL(*client_a_, DoBufferDestroyed(_, first_buffer_id)).Times(0); |
| 775 EXPECT_CALL(*client_a_, DoBufferDestroyed(_, second_buffer_id)).Times(0); |
| 776 controller_->ReturnBuffer(arbitrary_route_id_, client_a_.get(), |
| 777 second_buffer_id, arbitrary_utilization); |
| 778 base::RunLoop().RunUntilIdle(); |
| 779 Mock::VerifyAndClearExpectations(client_a_.get()); |
| 780 } |
| 781 |
596 } // namespace content | 782 } // namespace content |
OLD | NEW |