Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1172)

Side by Side Diff: content/browser/renderer_host/media/video_capture_controller_unittest.cc

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

Powered by Google App Engine
This is Rietveld 408576698