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 #include "content/browser/renderer_host/media/video_capture_controller.h" | 5 #include "content/browser/renderer_host/media/video_capture_controller.h" |
6 | 6 |
7 #include <stdint.h> | 7 #include <stdint.h> |
8 #include <string.h> | 8 #include <string.h> |
9 | 9 |
10 #include <memory> | 10 #include <memory> |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
74 mojo::ScopedSharedBufferHandle handle, | 74 mojo::ScopedSharedBufferHandle handle, |
75 int length, | 75 int length, |
76 int buffer_id) override { | 76 int buffer_id) override { |
77 DoBufferCreated(id, buffer_id); | 77 DoBufferCreated(id, buffer_id); |
78 } | 78 } |
79 void OnBufferDestroyed(VideoCaptureControllerID id, int buffer_id) override { | 79 void OnBufferDestroyed(VideoCaptureControllerID id, int buffer_id) override { |
80 DoBufferDestroyed(id, buffer_id); | 80 DoBufferDestroyed(id, buffer_id); |
81 } | 81 } |
82 void OnBufferReady(VideoCaptureControllerID id, | 82 void OnBufferReady(VideoCaptureControllerID id, |
83 int buffer_id, | 83 int buffer_id, |
84 const scoped_refptr<media::VideoFrame>& frame) override { | 84 media::mojom::VideoFrameInfoPtr frame_info) override { |
85 EXPECT_EQ(expected_pixel_format_, frame->format()); | 85 EXPECT_EQ(expected_pixel_format_, frame_info->pixel_format); |
| 86 media::VideoFrameMetadata metadata; |
| 87 metadata.MergeInternalValuesFrom(*frame_info->metadata); |
86 base::TimeTicks reference_time; | 88 base::TimeTicks reference_time; |
87 EXPECT_TRUE(frame->metadata()->GetTimeTicks( | 89 EXPECT_TRUE(metadata.GetTimeTicks(media::VideoFrameMetadata::REFERENCE_TIME, |
88 media::VideoFrameMetadata::REFERENCE_TIME, &reference_time)); | 90 &reference_time)); |
89 DoBufferReady(id, frame->coded_size()); | 91 DoBufferReady(id, frame_info->coded_size); |
90 if (enable_auto_return_buffer_on_buffer_ready_) { | 92 if (enable_auto_return_buffer_on_buffer_ready_) { |
91 base::ThreadTaskRunnerHandle::Get()->PostTask( | 93 base::ThreadTaskRunnerHandle::Get()->PostTask( |
92 FROM_HERE, base::Bind(&VideoCaptureController::ReturnBuffer, | 94 FROM_HERE, base::Bind(&VideoCaptureController::ReturnBuffer, |
93 base::Unretained(controller_), id, this, | 95 base::Unretained(controller_), id, this, |
94 buffer_id, resource_utilization_)); | 96 buffer_id, resource_utilization_)); |
95 } | 97 } |
96 } | 98 } |
97 void OnEnded(VideoCaptureControllerID id) override { | 99 void OnEnded(VideoCaptureControllerID id) override { |
98 DoEnded(id); | 100 DoEnded(id); |
99 // OnEnded() must respond by (eventually) unregistering the client. | 101 // OnEnded() must respond by (eventually) unregistering the client. |
100 base::ThreadTaskRunnerHandle::Get()->PostTask( | 102 base::ThreadTaskRunnerHandle::Get()->PostTask( |
101 FROM_HERE, | 103 FROM_HERE, |
102 base::Bind(base::IgnoreResult(&VideoCaptureController::RemoveClient), | 104 base::Bind(base::IgnoreResult(&VideoCaptureController::RemoveClient), |
103 base::Unretained(controller_), id, this)); | 105 base::Unretained(controller_), id, this)); |
104 } | 106 } |
105 | 107 |
106 VideoCaptureController* controller_; | 108 VideoCaptureController* controller_; |
107 media::VideoPixelFormat expected_pixel_format_ = media::PIXEL_FORMAT_I420; | 109 media::VideoPixelFormat expected_pixel_format_ = media::PIXEL_FORMAT_I420; |
108 double resource_utilization_; | 110 double resource_utilization_; |
109 bool enable_auto_return_buffer_on_buffer_ready_ = true; | 111 bool enable_auto_return_buffer_on_buffer_ready_ = true; |
110 }; | 112 }; |
111 | 113 |
112 class MockConsumerFeedbackObserver | 114 class MockConsumerFeedbackObserver |
113 : public media::VideoFrameConsumerFeedbackObserver { | 115 : public media::VideoFrameConsumerFeedbackObserver { |
114 public: | 116 public: |
115 MOCK_METHOD2(OnUtilizationReport, | 117 MOCK_METHOD2(OnUtilizationReport, |
116 void(int frame_feedback_id, double utilization)); | 118 void(int frame_feedback_id, double utilization)); |
117 }; | 119 }; |
118 | 120 |
119 class MockFrameBufferPool : public media::FrameBufferPool { | |
120 public: | |
121 MOCK_METHOD1(SetBufferHold, void(int buffer_id)); | |
122 MOCK_METHOD1(ReleaseBufferHold, void(int buffer_id)); | |
123 }; | |
124 | |
125 // Test fixture for testing a unit consisting of an instance of | 121 // Test fixture for testing a unit consisting of an instance of |
126 // VideoCaptureController connected to an instance of VideoCaptureDeviceClient, | 122 // VideoCaptureController connected to an instance of VideoCaptureDeviceClient, |
127 // an instance of VideoCaptureBufferPoolImpl, as well as related threading glue | 123 // an instance of VideoCaptureBufferPoolImpl, as well as related threading glue |
128 // that replicates how it is used in production. | 124 // that replicates how it is used in production. |
129 class VideoCaptureControllerTest | 125 class VideoCaptureControllerTest |
130 : public testing::Test, | 126 : public testing::Test, |
131 public testing::WithParamInterface<media::VideoPixelFormat> { | 127 public testing::WithParamInterface<media::VideoPixelFormat> { |
132 public: | 128 public: |
133 VideoCaptureControllerTest() | 129 VideoCaptureControllerTest() |
134 : arbitrary_format_(gfx::Size(320, 240), 30, media::PIXEL_FORMAT_I420), | 130 : arbitrary_format_(gfx::Size(320, 240), 30, media::PIXEL_FORMAT_I420), |
135 arbitrary_route_id_(0x99), | 131 arbitrary_route_id_(0x99), |
136 arbitrary_session_id_(100) {} | 132 arbitrary_session_id_(100) {} |
137 ~VideoCaptureControllerTest() override {} | 133 ~VideoCaptureControllerTest() override {} |
138 | 134 |
139 protected: | 135 protected: |
140 static const int kPoolSize = 3; | 136 static const int kPoolSize = 3; |
141 | 137 |
142 void SetUp() override { | 138 void SetUp() override { |
143 controller_.reset(new VideoCaptureController()); | 139 controller_.reset(new VideoCaptureController()); |
144 InitializeNewDeviceClientAndBufferPoolInstances(); | 140 InitializeNewDeviceClientAndBufferPoolInstances(); |
145 auto frame_receiver_observer = base::MakeUnique<MockFrameBufferPool>(); | |
146 mock_frame_receiver_observer_ = frame_receiver_observer.get(); | |
147 controller_->SetFrameBufferPool(std::move(frame_receiver_observer)); | |
148 auto consumer_feedback_observer = | 141 auto consumer_feedback_observer = |
149 base::MakeUnique<MockConsumerFeedbackObserver>(); | 142 base::MakeUnique<MockConsumerFeedbackObserver>(); |
150 mock_consumer_feedback_observer_ = consumer_feedback_observer.get(); | 143 mock_consumer_feedback_observer_ = consumer_feedback_observer.get(); |
151 controller_->SetConsumerFeedbackObserver( | 144 controller_->SetConsumerFeedbackObserver( |
152 std::move(consumer_feedback_observer)); | 145 std::move(consumer_feedback_observer)); |
153 client_a_.reset( | 146 client_a_.reset( |
154 new MockVideoCaptureControllerEventHandler(controller_.get())); | 147 new MockVideoCaptureControllerEventHandler(controller_.get())); |
155 client_b_.reset( | 148 client_b_.reset( |
156 new MockVideoCaptureControllerEventHandler(controller_.get())); | 149 new MockVideoCaptureControllerEventHandler(controller_.get())); |
157 } | 150 } |
158 | 151 |
159 void TearDown() override { base::RunLoop().RunUntilIdle(); } | 152 void TearDown() override { base::RunLoop().RunUntilIdle(); } |
160 | 153 |
161 void InitializeNewDeviceClientAndBufferPoolInstances() { | 154 void InitializeNewDeviceClientAndBufferPoolInstances() { |
162 buffer_pool_ = new media::VideoCaptureBufferPoolImpl( | 155 buffer_pool_ = new media::VideoCaptureBufferPoolImpl( |
163 base::MakeUnique<media::VideoCaptureBufferTrackerFactoryImpl>(), | 156 base::MakeUnique<media::VideoCaptureBufferTrackerFactoryImpl>(), |
164 kPoolSize); | 157 kPoolSize); |
165 device_client_.reset(new media::VideoCaptureDeviceClient( | 158 device_client_.reset(new media::VideoCaptureDeviceClient( |
166 base::MakeUnique<VideoFrameReceiverOnIOThread>( | 159 base::MakeUnique<VideoFrameReceiverOnIOThread>( |
167 controller_->GetWeakPtrForIOThread()), | 160 controller_->GetWeakPtrForIOThread()), |
168 buffer_pool_, | 161 buffer_pool_, |
169 base::Bind( | 162 base::Bind(&CreateGpuJpegDecoder, |
170 &CreateGpuJpegDecoder, | 163 base::Bind(&media::VideoFrameReceiver::OnFrameReadyInBuffer, |
171 base::Bind(&media::VideoFrameReceiver::OnIncomingCapturedVideoFrame, | 164 controller_->GetWeakPtrForIOThread())))); |
172 controller_->GetWeakPtrForIOThread())))); | |
173 } | 165 } |
174 | 166 |
175 void SendStubFrameToDeviceClient(const media::VideoCaptureFormat format) { | 167 void SendStubFrameToDeviceClient(const media::VideoCaptureFormat format) { |
176 auto stub_frame = media::VideoFrame::CreateZeroInitializedFrame( | 168 auto stub_frame = media::VideoFrame::CreateZeroInitializedFrame( |
177 format.pixel_format, format.frame_size, | 169 format.pixel_format, format.frame_size, |
178 gfx::Rect(format.frame_size.width(), format.frame_size.height()), | 170 gfx::Rect(format.frame_size.width(), format.frame_size.height()), |
179 format.frame_size, base::TimeDelta()); | 171 format.frame_size, base::TimeDelta()); |
180 const int rotation = 0; | 172 const int rotation = 0; |
181 const int frame_feedback_id = 0; | 173 const int frame_feedback_id = 0; |
182 device_client_->OnIncomingCapturedData( | 174 device_client_->OnIncomingCapturedData( |
183 stub_frame->data(0), | 175 stub_frame->data(0), |
184 media::VideoFrame::AllocationSize(stub_frame->format(), | 176 media::VideoFrame::AllocationSize(stub_frame->format(), |
185 stub_frame->coded_size()), | 177 stub_frame->coded_size()), |
186 format, rotation, base::TimeTicks(), base::TimeDelta(), | 178 format, rotation, base::TimeTicks(), base::TimeDelta(), |
187 frame_feedback_id); | 179 frame_feedback_id); |
188 } | 180 } |
189 | 181 |
190 TestBrowserThreadBundle bundle_; | 182 TestBrowserThreadBundle bundle_; |
191 scoped_refptr<media::VideoCaptureBufferPool> buffer_pool_; | 183 scoped_refptr<media::VideoCaptureBufferPool> buffer_pool_; |
192 std::unique_ptr<MockVideoCaptureControllerEventHandler> client_a_; | 184 std::unique_ptr<MockVideoCaptureControllerEventHandler> client_a_; |
193 std::unique_ptr<MockVideoCaptureControllerEventHandler> client_b_; | 185 std::unique_ptr<MockVideoCaptureControllerEventHandler> client_b_; |
194 std::unique_ptr<VideoCaptureController> controller_; | 186 std::unique_ptr<VideoCaptureController> controller_; |
195 std::unique_ptr<media::VideoCaptureDevice::Client> device_client_; | 187 std::unique_ptr<media::VideoCaptureDevice::Client> device_client_; |
196 MockFrameBufferPool* mock_frame_receiver_observer_; | |
197 MockConsumerFeedbackObserver* mock_consumer_feedback_observer_; | 188 MockConsumerFeedbackObserver* mock_consumer_feedback_observer_; |
198 const float arbitrary_frame_rate_ = 10.0f; | 189 const float arbitrary_frame_rate_ = 10.0f; |
199 const base::TimeTicks arbitrary_reference_time_ = base::TimeTicks(); | 190 const base::TimeTicks arbitrary_reference_time_ = base::TimeTicks(); |
200 const base::TimeDelta arbitrary_timestamp_ = base::TimeDelta(); | 191 const base::TimeDelta arbitrary_timestamp_ = base::TimeDelta(); |
201 const media::VideoCaptureFormat arbitrary_format_; | 192 const media::VideoCaptureFormat arbitrary_format_; |
202 const VideoCaptureControllerID arbitrary_route_id_; | 193 const VideoCaptureControllerID arbitrary_route_id_; |
203 const media::VideoCaptureSessionId arbitrary_session_id_; | 194 const media::VideoCaptureSessionId arbitrary_session_id_; |
204 | 195 |
205 private: | 196 private: |
206 DISALLOW_COPY_AND_ASSIGN(VideoCaptureControllerTest); | 197 DISALLOW_COPY_AND_ASSIGN(VideoCaptureControllerTest); |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
320 // Now, simulate an incoming captured buffer from the capture device. As a | 311 // Now, simulate an incoming captured buffer from the capture device. As a |
321 // side effect this will cause the first buffer to be shared with clients. | 312 // side effect this will cause the first buffer to be shared with clients. |
322 uint8_t buffer_no = 1; | 313 uint8_t buffer_no = 1; |
323 const int arbitrary_frame_feedback_id = 101; | 314 const int arbitrary_frame_feedback_id = 101; |
324 ASSERT_EQ(0.0, device_client_->GetBufferPoolUtilization()); | 315 ASSERT_EQ(0.0, device_client_->GetBufferPoolUtilization()); |
325 media::VideoCaptureDevice::Client::Buffer buffer = | 316 media::VideoCaptureDevice::Client::Buffer buffer = |
326 device_client_->ReserveOutputBuffer( | 317 device_client_->ReserveOutputBuffer( |
327 device_format.frame_size, device_format.pixel_format, | 318 device_format.frame_size, device_format.pixel_format, |
328 device_format.pixel_storage, arbitrary_frame_feedback_id); | 319 device_format.pixel_storage, arbitrary_frame_feedback_id); |
329 ASSERT_TRUE(buffer.is_valid()); | 320 ASSERT_TRUE(buffer.is_valid()); |
330 auto buffer_access = buffer.handle_provider()->GetHandleForInProcessAccess(); | 321 auto buffer_access = buffer.handle_provider->GetHandleForInProcessAccess(); |
331 ASSERT_EQ(1.0 / kPoolSize, device_client_->GetBufferPoolUtilization()); | 322 ASSERT_EQ(1.0 / kPoolSize, device_client_->GetBufferPoolUtilization()); |
332 memset(buffer_access->data(), buffer_no++, buffer_access->mapped_size()); | 323 memset(buffer_access->data(), buffer_no++, buffer_access->mapped_size()); |
333 { | 324 { |
334 InSequence s; | 325 InSequence s; |
335 EXPECT_CALL(*client_a_, DoBufferCreated(client_a_route_1, _)).Times(1); | 326 EXPECT_CALL(*client_a_, DoBufferCreated(client_a_route_1, _)); |
336 EXPECT_CALL(*client_a_, | 327 EXPECT_CALL(*client_a_, |
337 DoBufferReady(client_a_route_1, device_format.frame_size)) | 328 DoBufferReady(client_a_route_1, device_format.frame_size)); |
338 .Times(1); | |
339 } | 329 } |
340 { | 330 { |
341 InSequence s; | 331 InSequence s; |
342 EXPECT_CALL(*client_b_, DoBufferCreated(client_b_route_1, _)).Times(1); | 332 EXPECT_CALL(*client_b_, DoBufferCreated(client_b_route_1, _)); |
343 EXPECT_CALL(*client_b_, | 333 EXPECT_CALL(*client_b_, |
344 DoBufferReady(client_b_route_1, device_format.frame_size)) | 334 DoBufferReady(client_b_route_1, device_format.frame_size)); |
345 .Times(1); | |
346 } | 335 } |
347 { | 336 { |
348 InSequence s; | 337 InSequence s; |
349 EXPECT_CALL(*client_a_, DoBufferCreated(client_a_route_2, _)).Times(1); | 338 EXPECT_CALL(*client_a_, DoBufferCreated(client_a_route_2, _)); |
350 EXPECT_CALL(*client_a_, | 339 EXPECT_CALL(*client_a_, |
351 DoBufferReady(client_a_route_2, device_format.frame_size)) | 340 DoBufferReady(client_a_route_2, device_format.frame_size)); |
352 .Times(1); | |
353 } | 341 } |
354 client_a_->resource_utilization_ = 0.5; | 342 client_a_->resource_utilization_ = 0.5; |
355 client_b_->resource_utilization_ = -1.0; | 343 client_b_->resource_utilization_ = -1.0; |
356 { | 344 // Expect VideoCaptureController to call the load observer with a |
357 InSequence s; | 345 // resource utilization of 0.5 (the largest of all reported values). |
358 EXPECT_CALL(*mock_frame_receiver_observer_, SetBufferHold(buffer.id())) | 346 EXPECT_CALL(*mock_consumer_feedback_observer_, |
359 .Times(1); | 347 OnUtilizationReport(arbitrary_frame_feedback_id, 0.5)); |
360 // Expect VideoCaptureController to call the load observer with a | |
361 // resource utilization of 0.5 (the largest of all reported values). | |
362 EXPECT_CALL(*mock_consumer_feedback_observer_, | |
363 OnUtilizationReport(arbitrary_frame_feedback_id, 0.5)) | |
364 .Times(1); | |
365 EXPECT_CALL(*mock_frame_receiver_observer_, ReleaseBufferHold(buffer.id())) | |
366 .Times(1); | |
367 } | |
368 | 348 |
369 device_client_->OnIncomingCapturedBuffer(std::move(buffer), device_format, | 349 device_client_->OnIncomingCapturedBuffer(std::move(buffer), device_format, |
370 arbitrary_reference_time_, | 350 arbitrary_reference_time_, |
371 arbitrary_timestamp_); | 351 arbitrary_timestamp_); |
372 | 352 |
373 base::RunLoop().RunUntilIdle(); | 353 base::RunLoop().RunUntilIdle(); |
374 Mock::VerifyAndClearExpectations(client_a_.get()); | 354 Mock::VerifyAndClearExpectations(client_a_.get()); |
375 Mock::VerifyAndClearExpectations(client_b_.get()); | 355 Mock::VerifyAndClearExpectations(client_b_.get()); |
376 Mock::VerifyAndClearExpectations(mock_consumer_feedback_observer_); | 356 Mock::VerifyAndClearExpectations(mock_consumer_feedback_observer_); |
377 Mock::VerifyAndClearExpectations(mock_frame_receiver_observer_); | |
378 | 357 |
379 // Second buffer which ought to use the same shared memory buffer. In this | 358 // Second buffer which ought to use the same shared memory buffer. In this |
380 // case pretend that the Buffer pointer is held by the device for a long | 359 // case pretend that the Buffer pointer is held by the device for a long |
381 // delay. This shouldn't affect anything. | 360 // delay. This shouldn't affect anything. |
382 const int arbitrary_frame_feedback_id_2 = 102; | 361 const int arbitrary_frame_feedback_id_2 = 102; |
383 media::VideoCaptureDevice::Client::Buffer buffer2 = | 362 media::VideoCaptureDevice::Client::Buffer buffer2 = |
384 device_client_->ReserveOutputBuffer( | 363 device_client_->ReserveOutputBuffer( |
385 device_format.frame_size, device_format.pixel_format, | 364 device_format.frame_size, device_format.pixel_format, |
386 device_format.pixel_storage, arbitrary_frame_feedback_id_2); | 365 device_format.pixel_storage, arbitrary_frame_feedback_id_2); |
387 ASSERT_TRUE(buffer2.is_valid()); | 366 ASSERT_TRUE(buffer2.is_valid()); |
388 auto buffer2_access = | 367 auto buffer2_access = buffer2.handle_provider->GetHandleForInProcessAccess(); |
389 buffer2.handle_provider()->GetHandleForInProcessAccess(); | |
390 memset(buffer2_access->data(), buffer_no++, buffer2_access->mapped_size()); | 368 memset(buffer2_access->data(), buffer_no++, buffer2_access->mapped_size()); |
391 client_a_->resource_utilization_ = 0.5; | 369 client_a_->resource_utilization_ = 0.5; |
392 client_b_->resource_utilization_ = 3.14; | 370 client_b_->resource_utilization_ = 3.14; |
393 // Expect VideoCaptureController to call the load observer with a | 371 // Expect VideoCaptureController to call the load observer with a |
394 // resource utilization of 3.14 (the largest of all reported values). | 372 // resource utilization of 3.14 (the largest of all reported values). |
395 { | 373 EXPECT_CALL(*mock_consumer_feedback_observer_, |
396 InSequence s; | 374 OnUtilizationReport(arbitrary_frame_feedback_id_2, 3.14)); |
397 EXPECT_CALL(*mock_frame_receiver_observer_, SetBufferHold(buffer2.id())) | |
398 .Times(1); | |
399 // Expect VideoCaptureController to call the load observer with a | |
400 // resource utilization of 3.14 (the largest of all reported values). | |
401 EXPECT_CALL(*mock_consumer_feedback_observer_, | |
402 OnUtilizationReport(arbitrary_frame_feedback_id_2, 3.14)) | |
403 .Times(1); | |
404 EXPECT_CALL(*mock_frame_receiver_observer_, ReleaseBufferHold(buffer2.id())) | |
405 .Times(1); | |
406 } | |
407 | 375 |
408 device_client_->OnIncomingCapturedBuffer(std::move(buffer2), device_format, | 376 device_client_->OnIncomingCapturedBuffer(std::move(buffer2), device_format, |
409 arbitrary_reference_time_, | 377 arbitrary_reference_time_, |
410 arbitrary_timestamp_); | 378 arbitrary_timestamp_); |
411 | 379 |
412 // The buffer should be delivered to the clients in any order. | 380 // The buffer should be delivered to the clients in any order. |
413 { | 381 { |
414 InSequence s; | 382 InSequence s; |
415 EXPECT_CALL(*client_a_, DoBufferCreated(client_a_route_1, _)).Times(1); | 383 EXPECT_CALL(*client_a_, DoBufferCreated(client_a_route_1, _)); |
416 EXPECT_CALL(*client_a_, | 384 EXPECT_CALL(*client_a_, |
417 DoBufferReady(client_a_route_1, device_format.frame_size)) | 385 DoBufferReady(client_a_route_1, device_format.frame_size)); |
418 .Times(1); | |
419 } | 386 } |
420 { | 387 { |
421 InSequence s; | 388 InSequence s; |
422 EXPECT_CALL(*client_b_, DoBufferCreated(client_b_route_1, _)).Times(1); | 389 EXPECT_CALL(*client_b_, DoBufferCreated(client_b_route_1, _)); |
423 EXPECT_CALL(*client_b_, | 390 EXPECT_CALL(*client_b_, |
424 DoBufferReady(client_b_route_1, device_format.frame_size)) | 391 DoBufferReady(client_b_route_1, device_format.frame_size)); |
425 .Times(1); | |
426 } | 392 } |
427 { | 393 { |
428 InSequence s; | 394 InSequence s; |
429 EXPECT_CALL(*client_a_, DoBufferCreated(client_a_route_2, _)).Times(1); | 395 EXPECT_CALL(*client_a_, DoBufferCreated(client_a_route_2, _)); |
430 EXPECT_CALL(*client_a_, | 396 EXPECT_CALL(*client_a_, |
431 DoBufferReady(client_a_route_2, device_format.frame_size)) | 397 DoBufferReady(client_a_route_2, device_format.frame_size)); |
432 .Times(1); | |
433 } | 398 } |
434 base::RunLoop().RunUntilIdle(); | 399 base::RunLoop().RunUntilIdle(); |
435 Mock::VerifyAndClearExpectations(client_a_.get()); | 400 Mock::VerifyAndClearExpectations(client_a_.get()); |
436 Mock::VerifyAndClearExpectations(client_b_.get()); | 401 Mock::VerifyAndClearExpectations(client_b_.get()); |
437 Mock::VerifyAndClearExpectations(mock_consumer_feedback_observer_); | 402 Mock::VerifyAndClearExpectations(mock_consumer_feedback_observer_); |
438 Mock::VerifyAndClearExpectations(mock_frame_receiver_observer_); | |
439 | 403 |
440 // Add a fourth client now that some buffers have come through. | 404 // Add a fourth client now that some buffers have come through. |
441 controller_->AddClient(client_b_route_2, client_b_.get(), 1, session_1); | 405 controller_->AddClient(client_b_route_2, client_b_.get(), 1, session_1); |
442 Mock::VerifyAndClearExpectations(client_b_.get()); | 406 Mock::VerifyAndClearExpectations(client_b_.get()); |
443 | 407 |
444 // Third, fourth, and fifth buffers. Pretend they all arrive at the same time. | 408 // Third, fourth, and fifth buffers. Pretend they all arrive at the same time. |
445 for (int i = 0; i < kPoolSize; i++) { | 409 for (int i = 0; i < kPoolSize; i++) { |
446 const int arbitrary_frame_feedback_id = 200 + i; | 410 const int arbitrary_frame_feedback_id = 200 + i; |
447 media::VideoCaptureDevice::Client::Buffer buffer = | 411 media::VideoCaptureDevice::Client::Buffer buffer = |
448 device_client_->ReserveOutputBuffer( | 412 device_client_->ReserveOutputBuffer( |
449 device_format.frame_size, device_format.pixel_format, | 413 device_format.frame_size, device_format.pixel_format, |
450 device_format.pixel_storage, arbitrary_frame_feedback_id); | 414 device_format.pixel_storage, arbitrary_frame_feedback_id); |
451 ASSERT_TRUE(buffer.is_valid()); | 415 ASSERT_TRUE(buffer.is_valid()); |
452 auto buffer_access = | 416 auto buffer_access = buffer.handle_provider->GetHandleForInProcessAccess(); |
453 buffer.handle_provider()->GetHandleForInProcessAccess(); | |
454 memset(buffer_access->data(), buffer_no++, buffer_access->mapped_size()); | 417 memset(buffer_access->data(), buffer_no++, buffer_access->mapped_size()); |
455 device_client_->OnIncomingCapturedBuffer(std::move(buffer), device_format, | 418 device_client_->OnIncomingCapturedBuffer(std::move(buffer), device_format, |
456 arbitrary_reference_time_, | 419 arbitrary_reference_time_, |
457 arbitrary_timestamp_); | 420 arbitrary_timestamp_); |
458 } | 421 } |
459 // ReserveOutputBuffer ought to fail now, because the pool is depleted. | 422 // ReserveOutputBuffer ought to fail now, because the pool is depleted. |
460 ASSERT_FALSE(device_client_ | 423 ASSERT_FALSE(device_client_ |
461 ->ReserveOutputBuffer( | 424 ->ReserveOutputBuffer( |
462 device_format.frame_size, device_format.pixel_format, | 425 device_format.frame_size, device_format.pixel_format, |
463 device_format.pixel_storage, arbitrary_frame_feedback_id) | 426 device_format.pixel_storage, arbitrary_frame_feedback_id) |
(...skipping 30 matching lines...) Expand all Loading... |
494 controller_->RemoveClient(client_a_route_1, client_a_.get()); | 457 controller_->RemoveClient(client_a_route_1, client_a_.get()); |
495 // Kill B1 via session close (posts a task to disconnect). | 458 // Kill B1 via session close (posts a task to disconnect). |
496 EXPECT_CALL(*client_b_, DoEnded(client_b_route_1)).Times(1); | 459 EXPECT_CALL(*client_b_, DoEnded(client_b_route_1)).Times(1); |
497 controller_->StopSession(300); | 460 controller_->StopSession(300); |
498 // Queue up another buffer. | 461 // Queue up another buffer. |
499 media::VideoCaptureDevice::Client::Buffer buffer3 = | 462 media::VideoCaptureDevice::Client::Buffer buffer3 = |
500 device_client_->ReserveOutputBuffer( | 463 device_client_->ReserveOutputBuffer( |
501 device_format.frame_size, device_format.pixel_format, | 464 device_format.frame_size, device_format.pixel_format, |
502 device_format.pixel_storage, arbitrary_frame_feedback_id); | 465 device_format.pixel_storage, arbitrary_frame_feedback_id); |
503 ASSERT_TRUE(buffer3.is_valid()); | 466 ASSERT_TRUE(buffer3.is_valid()); |
504 auto buffer3_access = | 467 auto buffer3_access = buffer3.handle_provider->GetHandleForInProcessAccess(); |
505 buffer3.handle_provider()->GetHandleForInProcessAccess(); | |
506 memset(buffer3_access->data(), buffer_no++, buffer3_access->mapped_size()); | 468 memset(buffer3_access->data(), buffer_no++, buffer3_access->mapped_size()); |
507 device_client_->OnIncomingCapturedBuffer(std::move(buffer3), device_format, | 469 device_client_->OnIncomingCapturedBuffer(std::move(buffer3), device_format, |
508 arbitrary_reference_time_, | 470 arbitrary_reference_time_, |
509 arbitrary_timestamp_); | 471 arbitrary_timestamp_); |
510 | 472 |
511 media::VideoCaptureDevice::Client::Buffer buffer4 = | 473 media::VideoCaptureDevice::Client::Buffer buffer4 = |
512 device_client_->ReserveOutputBuffer( | 474 device_client_->ReserveOutputBuffer( |
513 device_format.frame_size, device_format.pixel_format, | 475 device_format.frame_size, device_format.pixel_format, |
514 device_format.pixel_storage, arbitrary_frame_feedback_id); | 476 device_format.pixel_storage, arbitrary_frame_feedback_id); |
515 { | 477 { |
516 // Kill A2 via session close (posts a task to disconnect, but A2 must not | 478 // Kill A2 via session close (posts a task to disconnect, but A2 must not |
517 // be sent either of these two buffers). | 479 // be sent either of these two buffers). |
518 EXPECT_CALL(*client_a_, DoEnded(client_a_route_2)).Times(1); | 480 EXPECT_CALL(*client_a_, DoEnded(client_a_route_2)).Times(1); |
519 controller_->StopSession(200); | 481 controller_->StopSession(200); |
520 } | 482 } |
521 ASSERT_TRUE(buffer4.is_valid()); | 483 ASSERT_TRUE(buffer4.is_valid()); |
522 auto buffer4_access = | 484 auto buffer4_access = buffer4.handle_provider->GetHandleForInProcessAccess(); |
523 buffer4.handle_provider()->GetHandleForInProcessAccess(); | |
524 memset(buffer4_access->data(), buffer_no++, buffer4_access->mapped_size()); | 485 memset(buffer4_access->data(), buffer_no++, buffer4_access->mapped_size()); |
525 device_client_->OnIncomingCapturedBuffer(std::move(buffer4), device_format, | 486 device_client_->OnIncomingCapturedBuffer(std::move(buffer4), device_format, |
526 arbitrary_reference_time_, | 487 arbitrary_reference_time_, |
527 arbitrary_timestamp_); | 488 arbitrary_timestamp_); |
528 // B2 is the only client left, and is the only one that should | 489 // B2 is the only client left, and is the only one that should |
529 // get the buffer. | 490 // get the buffer. |
530 EXPECT_CALL(*client_b_, | 491 EXPECT_CALL(*client_b_, |
531 DoBufferReady(client_b_route_2, device_format.frame_size)) | 492 DoBufferReady(client_b_route_2, device_format.frame_size)) |
532 .Times(2); | 493 .Times(2); |
533 base::RunLoop().RunUntilIdle(); | 494 base::RunLoop().RunUntilIdle(); |
(...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
834 // buffer is expected to stay alive. | 795 // buffer is expected to stay alive. |
835 EXPECT_CALL(*client_a_, DoBufferDestroyed(_, first_buffer_id)).Times(0); | 796 EXPECT_CALL(*client_a_, DoBufferDestroyed(_, first_buffer_id)).Times(0); |
836 EXPECT_CALL(*client_a_, DoBufferDestroyed(_, second_buffer_id)).Times(0); | 797 EXPECT_CALL(*client_a_, DoBufferDestroyed(_, second_buffer_id)).Times(0); |
837 controller_->ReturnBuffer(arbitrary_route_id_, client_a_.get(), | 798 controller_->ReturnBuffer(arbitrary_route_id_, client_a_.get(), |
838 second_buffer_id, arbitrary_utilization); | 799 second_buffer_id, arbitrary_utilization); |
839 base::RunLoop().RunUntilIdle(); | 800 base::RunLoop().RunUntilIdle(); |
840 Mock::VerifyAndClearExpectations(client_a_.get()); | 801 Mock::VerifyAndClearExpectations(client_a_.get()); |
841 } | 802 } |
842 | 803 |
843 } // namespace content | 804 } // namespace content |
OLD | NEW |