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

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

Issue 2566983007: [Mojo Video Capture] Replace method OnIncomingCapturedVideoFrame with OnIncomingCapturedBufferExt (Closed)
Patch Set: mcasas comments Created 4 years 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 // 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>
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
153 controller_->SetConsumerFeedbackObserver( 153 controller_->SetConsumerFeedbackObserver(
154 std::move(consumer_feedback_observer)); 154 std::move(consumer_feedback_observer));
155 client_a_.reset(new MockVideoCaptureControllerEventHandler( 155 client_a_.reset(new MockVideoCaptureControllerEventHandler(
156 controller_.get())); 156 controller_.get()));
157 client_b_.reset(new MockVideoCaptureControllerEventHandler( 157 client_b_.reset(new MockVideoCaptureControllerEventHandler(
158 controller_.get())); 158 controller_.get()));
159 } 159 }
160 160
161 void TearDown() override { base::RunLoop().RunUntilIdle(); } 161 void TearDown() override { base::RunLoop().RunUntilIdle(); }
162 162
163 scoped_refptr<media::VideoFrame> WrapBuffer(
164 gfx::Size dimensions,
165 uint8_t* data,
166 media::VideoPixelFormat format = media::PIXEL_FORMAT_I420) {
167 scoped_refptr<media::VideoFrame> video_frame =
168 media::VideoFrame::WrapExternalSharedMemory(
169 format, dimensions, gfx::Rect(dimensions), dimensions, data,
170 media::VideoFrame::AllocationSize(format, dimensions),
171 base::SharedMemory::NULLHandle(), 0u, base::TimeDelta());
172 EXPECT_TRUE(video_frame);
173 return video_frame;
174 }
175
176 TestBrowserThreadBundle bundle_; 163 TestBrowserThreadBundle bundle_;
177 std::unique_ptr<MockVideoCaptureControllerEventHandler> client_a_; 164 std::unique_ptr<MockVideoCaptureControllerEventHandler> client_a_;
178 std::unique_ptr<MockVideoCaptureControllerEventHandler> client_b_; 165 std::unique_ptr<MockVideoCaptureControllerEventHandler> client_b_;
179 std::unique_ptr<VideoCaptureController> controller_; 166 std::unique_ptr<VideoCaptureController> controller_;
180 std::unique_ptr<media::VideoCaptureDevice::Client> device_client_; 167 std::unique_ptr<media::VideoCaptureDevice::Client> device_client_;
181 MockFrameBufferPool* mock_frame_receiver_observer_; 168 MockFrameBufferPool* mock_frame_receiver_observer_;
182 MockConsumerFeedbackObserver* mock_consumer_feedback_observer_; 169 MockConsumerFeedbackObserver* mock_consumer_feedback_observer_;
170 const float arbitrary_frame_rate_ = 10.0f;
171 const base::TimeTicks arbitrary_reference_time_ = base::TimeTicks();
172 const base::TimeDelta arbitrary_timestamp_ = base::TimeDelta();
183 173
184 private: 174 private:
185 DISALLOW_COPY_AND_ASSIGN(VideoCaptureControllerTest); 175 DISALLOW_COPY_AND_ASSIGN(VideoCaptureControllerTest);
186 }; 176 };
187 177
188 // A simple test of VideoCaptureController's ability to add, remove, and keep 178 // A simple test of VideoCaptureController's ability to add, remove, and keep
189 // track of clients. 179 // track of clients.
190 TEST_F(VideoCaptureControllerTest, AddAndRemoveClients) { 180 TEST_F(VideoCaptureControllerTest, AddAndRemoveClients) {
191 media::VideoCaptureParams session_100; 181 media::VideoCaptureParams session_100;
192 session_100.requested_format = media::VideoCaptureFormat( 182 session_100.requested_format = media::VideoCaptureFormat(
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
292 282
293 session_100.requested_format = 283 session_100.requested_format =
294 media::VideoCaptureFormat(gfx::Size(320, 240), 30, format); 284 media::VideoCaptureFormat(gfx::Size(320, 240), 30, format);
295 285
296 media::VideoCaptureParams session_200 = session_100; 286 media::VideoCaptureParams session_200 = session_100;
297 287
298 media::VideoCaptureParams session_300 = session_100; 288 media::VideoCaptureParams session_300 = session_100;
299 289
300 media::VideoCaptureParams session_1 = session_100; 290 media::VideoCaptureParams session_1 = session_100;
301 291
302 const gfx::Size capture_resolution(444, 200); 292 media::VideoCaptureFormat device_format(gfx::Size(444, 200), 25, format);
303
304 // The device format needn't match the VideoCaptureParams (the camera can do
305 // what it wants). Pick something random.
306 media::VideoCaptureFormat device_format(
307 gfx::Size(10, 10), 25, media::PIXEL_FORMAT_RGB24);
308 293
309 const VideoCaptureControllerID client_a_route_1(0xa1a1a1a1); 294 const VideoCaptureControllerID client_a_route_1(0xa1a1a1a1);
310 const VideoCaptureControllerID client_a_route_2(0xa2a2a2a2); 295 const VideoCaptureControllerID client_a_route_2(0xa2a2a2a2);
311 const VideoCaptureControllerID client_b_route_1(0xb1b1b1b1); 296 const VideoCaptureControllerID client_b_route_1(0xb1b1b1b1);
312 const VideoCaptureControllerID client_b_route_2(0xb2b2b2b2); 297 const VideoCaptureControllerID client_b_route_2(0xb2b2b2b2);
313 298
314 // Start with two clients.
315 controller_->AddClient(client_a_route_1, 299 controller_->AddClient(client_a_route_1,
316 client_a_.get(), 300 client_a_.get(),
317 100, 301 100,
318 session_100); 302 session_100);
319 controller_->AddClient(client_b_route_1, 303 controller_->AddClient(client_b_route_1,
320 client_b_.get(), 304 client_b_.get(),
321 300, 305 300,
322 session_300); 306 session_300);
323 controller_->AddClient(client_a_route_2, 307 controller_->AddClient(client_a_route_2,
324 client_a_.get(), 308 client_a_.get(),
325 200, 309 200,
326 session_200); 310 session_200);
327 ASSERT_EQ(3, controller_->GetClientCount()); 311 ASSERT_EQ(3, controller_->GetClientCount());
328 312
329 // Now, simulate an incoming captured buffer from the capture device. As a 313 // 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. 314 // side effect this will cause the first buffer to be shared with clients.
331 uint8_t buffer_no = 1; 315 uint8_t buffer_no = 1;
332 const int arbitrary_frame_feedback_id = 101; 316 const int arbitrary_frame_feedback_id = 101;
333 ASSERT_EQ(0.0, device_client_->GetBufferPoolUtilization()); 317 ASSERT_EQ(0.0, device_client_->GetBufferPoolUtilization());
334 std::unique_ptr<media::VideoCaptureDevice::Client::Buffer> buffer( 318 std::unique_ptr<media::VideoCaptureDevice::Client::Buffer> buffer(
335 device_client_->ReserveOutputBuffer(capture_resolution, format, 319 device_client_->ReserveOutputBuffer(device_format.frame_size,
336 media::PIXEL_STORAGE_CPU, 320 device_format.pixel_format,
321 device_format.pixel_storage,
337 arbitrary_frame_feedback_id)); 322 arbitrary_frame_feedback_id));
338 ASSERT_TRUE(buffer.get()); 323 ASSERT_TRUE(buffer.get());
339 ASSERT_EQ(1.0 / kPoolSize, device_client_->GetBufferPoolUtilization()); 324 ASSERT_EQ(1.0 / kPoolSize, device_client_->GetBufferPoolUtilization());
340 memset(buffer->data(), buffer_no++, buffer->mapped_size()); 325 memset(buffer->data(), buffer_no++, buffer->mapped_size());
341 { 326 {
342 InSequence s; 327 InSequence s;
343 EXPECT_CALL(*client_a_, DoBufferCreated(client_a_route_1)).Times(1); 328 EXPECT_CALL(*client_a_, DoBufferCreated(client_a_route_1)).Times(1);
344 EXPECT_CALL(*client_a_, DoBufferReady(client_a_route_1, capture_resolution)) 329 EXPECT_CALL(*client_a_,
330 DoBufferReady(client_a_route_1, device_format.frame_size))
345 .Times(1); 331 .Times(1);
346 } 332 }
347 { 333 {
348 InSequence s; 334 InSequence s;
349 EXPECT_CALL(*client_b_, DoBufferCreated(client_b_route_1)).Times(1); 335 EXPECT_CALL(*client_b_, DoBufferCreated(client_b_route_1)).Times(1);
350 EXPECT_CALL(*client_b_, DoBufferReady(client_b_route_1, capture_resolution)) 336 EXPECT_CALL(*client_b_,
337 DoBufferReady(client_b_route_1, device_format.frame_size))
351 .Times(1); 338 .Times(1);
352 } 339 }
353 { 340 {
354 InSequence s; 341 InSequence s;
355 EXPECT_CALL(*client_a_, DoBufferCreated(client_a_route_2)).Times(1); 342 EXPECT_CALL(*client_a_, DoBufferCreated(client_a_route_2)).Times(1);
356 EXPECT_CALL(*client_a_, DoBufferReady(client_a_route_2, capture_resolution)) 343 EXPECT_CALL(*client_a_,
344 DoBufferReady(client_a_route_2, device_format.frame_size))
357 .Times(1); 345 .Times(1);
358 } 346 }
359 scoped_refptr<media::VideoFrame> video_frame = WrapBuffer(
360 capture_resolution, static_cast<uint8_t*>(buffer->data()), format);
361 ASSERT_TRUE(video_frame);
362 ASSERT_FALSE(video_frame->metadata()->HasKey(
363 media::VideoFrameMetadata::RESOURCE_UTILIZATION));
364 client_a_->resource_utilization_ = 0.5; 347 client_a_->resource_utilization_ = 0.5;
365 client_b_->resource_utilization_ = -1.0; 348 client_b_->resource_utilization_ = -1.0;
366 { 349 {
367 InSequence s; 350 InSequence s;
368 EXPECT_CALL(*mock_frame_receiver_observer_, SetBufferHold(buffer->id())) 351 EXPECT_CALL(*mock_frame_receiver_observer_, SetBufferHold(buffer->id()))
369 .Times(1); 352 .Times(1);
370 // Expect VideoCaptureController to call the load observer with a 353 // Expect VideoCaptureController to call the load observer with a
371 // resource utilization of 0.5 (the largest of all reported values). 354 // resource utilization of 0.5 (the largest of all reported values).
372 EXPECT_CALL(*mock_consumer_feedback_observer_, 355 EXPECT_CALL(*mock_consumer_feedback_observer_,
373 OnUtilizationReport(arbitrary_frame_feedback_id, 0.5)) 356 OnUtilizationReport(arbitrary_frame_feedback_id, 0.5))
374 .Times(1); 357 .Times(1);
375 EXPECT_CALL(*mock_frame_receiver_observer_, ReleaseBufferHold(buffer->id())) 358 EXPECT_CALL(*mock_frame_receiver_observer_, ReleaseBufferHold(buffer->id()))
376 .Times(1); 359 .Times(1);
377 } 360 }
378 361
379 video_frame->metadata()->SetTimeTicks( 362 device_client_->OnIncomingCapturedBuffer(std::move(buffer),
380 media::VideoFrameMetadata::REFERENCE_TIME, base::TimeTicks()); 363 device_format,
381 device_client_->OnIncomingCapturedVideoFrame(std::move(buffer), video_frame); 364 arbitrary_reference_time_,
365 arbitrary_timestamp_);
382 366
383 base::RunLoop().RunUntilIdle(); 367 base::RunLoop().RunUntilIdle();
384 Mock::VerifyAndClearExpectations(client_a_.get()); 368 Mock::VerifyAndClearExpectations(client_a_.get());
385 Mock::VerifyAndClearExpectations(client_b_.get()); 369 Mock::VerifyAndClearExpectations(client_b_.get());
386 Mock::VerifyAndClearExpectations(mock_consumer_feedback_observer_); 370 Mock::VerifyAndClearExpectations(mock_consumer_feedback_observer_);
387 Mock::VerifyAndClearExpectations(mock_frame_receiver_observer_); 371 Mock::VerifyAndClearExpectations(mock_frame_receiver_observer_);
388 372
389 // Second buffer which ought to use the same shared memory buffer. In this 373 // 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 374 // case pretend that the Buffer pointer is held by the device for a long
391 // delay. This shouldn't affect anything. 375 // delay. This shouldn't affect anything.
392 const int arbitrary_frame_feedback_id_2 = 102; 376 const int arbitrary_frame_feedback_id_2 = 102;
393 std::unique_ptr<media::VideoCaptureDevice::Client::Buffer> buffer2 = 377 std::unique_ptr<media::VideoCaptureDevice::Client::Buffer> buffer2 =
394 device_client_->ReserveOutputBuffer(capture_resolution, format, 378 device_client_->ReserveOutputBuffer(device_format.frame_size,
395 media::PIXEL_STORAGE_CPU, 379 device_format.pixel_format,
380 device_format.pixel_storage,
396 arbitrary_frame_feedback_id_2); 381 arbitrary_frame_feedback_id_2);
397 ASSERT_TRUE(buffer2.get()); 382 ASSERT_TRUE(buffer2.get());
398 memset(buffer2->data(), buffer_no++, buffer2->mapped_size()); 383 memset(buffer2->data(), buffer_no++, buffer2->mapped_size());
399 video_frame = WrapBuffer(capture_resolution,
400 static_cast<uint8_t*>(buffer2->data()), format);
401 client_a_->resource_utilization_ = 0.5; 384 client_a_->resource_utilization_ = 0.5;
402 client_b_->resource_utilization_ = 3.14; 385 client_b_->resource_utilization_ = 3.14;
403 video_frame->metadata()->SetTimeTicks(
404 media::VideoFrameMetadata::REFERENCE_TIME, base::TimeTicks());
405 // Expect VideoCaptureController to call the load observer with a 386 // Expect VideoCaptureController to call the load observer with a
406 // resource utilization of 3.14 (the largest of all reported values). 387 // resource utilization of 3.14 (the largest of all reported values).
407 { 388 {
408 InSequence s; 389 InSequence s;
409 EXPECT_CALL(*mock_frame_receiver_observer_, SetBufferHold(buffer2->id())) 390 EXPECT_CALL(*mock_frame_receiver_observer_, SetBufferHold(buffer2->id()))
410 .Times(1); 391 .Times(1);
411 // Expect VideoCaptureController to call the load observer with a 392 // Expect VideoCaptureController to call the load observer with a
412 // resource utilization of 3.14 (the largest of all reported values). 393 // resource utilization of 3.14 (the largest of all reported values).
413 EXPECT_CALL(*mock_consumer_feedback_observer_, 394 EXPECT_CALL(*mock_consumer_feedback_observer_,
414 OnUtilizationReport(arbitrary_frame_feedback_id_2, 3.14)) 395 OnUtilizationReport(arbitrary_frame_feedback_id_2, 3.14))
415 .Times(1); 396 .Times(1);
416 EXPECT_CALL(*mock_frame_receiver_observer_, 397 EXPECT_CALL(*mock_frame_receiver_observer_,
417 ReleaseBufferHold(buffer2->id())) 398 ReleaseBufferHold(buffer2->id()))
418 .Times(1); 399 .Times(1);
419 } 400 }
420 401
421 device_client_->OnIncomingCapturedVideoFrame(std::move(buffer2), video_frame); 402 device_client_->OnIncomingCapturedBuffer(std::move(buffer2),
403 device_format,
404 arbitrary_reference_time_,
405 arbitrary_timestamp_);
422 406
423 // The buffer should be delivered to the clients in any order. 407 // The buffer should be delivered to the clients in any order.
424 { 408 {
425 InSequence s; 409 InSequence s;
426 EXPECT_CALL(*client_a_, DoBufferCreated(client_a_route_1)).Times(1); 410 EXPECT_CALL(*client_a_, DoBufferCreated(client_a_route_1)).Times(1);
427 EXPECT_CALL(*client_a_, DoBufferReady(client_a_route_1, capture_resolution)) 411 EXPECT_CALL(*client_a_,
412 DoBufferReady(client_a_route_1, device_format.frame_size))
428 .Times(1); 413 .Times(1);
429 } 414 }
430 { 415 {
431 InSequence s; 416 InSequence s;
432 EXPECT_CALL(*client_b_, DoBufferCreated(client_b_route_1)).Times(1); 417 EXPECT_CALL(*client_b_, DoBufferCreated(client_b_route_1)).Times(1);
433 EXPECT_CALL(*client_b_, DoBufferReady(client_b_route_1, capture_resolution)) 418 EXPECT_CALL(*client_b_,
419 DoBufferReady(client_b_route_1, device_format.frame_size))
434 .Times(1); 420 .Times(1);
435 } 421 }
436 { 422 {
437 InSequence s; 423 InSequence s;
438 EXPECT_CALL(*client_a_, DoBufferCreated(client_a_route_2)).Times(1); 424 EXPECT_CALL(*client_a_, DoBufferCreated(client_a_route_2)).Times(1);
439 EXPECT_CALL(*client_a_, DoBufferReady(client_a_route_2, capture_resolution)) 425 EXPECT_CALL(*client_a_,
426 DoBufferReady(client_a_route_2, device_format.frame_size))
440 .Times(1); 427 .Times(1);
441 } 428 }
442 base::RunLoop().RunUntilIdle(); 429 base::RunLoop().RunUntilIdle();
443 Mock::VerifyAndClearExpectations(client_a_.get()); 430 Mock::VerifyAndClearExpectations(client_a_.get());
444 Mock::VerifyAndClearExpectations(client_b_.get()); 431 Mock::VerifyAndClearExpectations(client_b_.get());
445 Mock::VerifyAndClearExpectations(mock_consumer_feedback_observer_); 432 Mock::VerifyAndClearExpectations(mock_consumer_feedback_observer_);
446 Mock::VerifyAndClearExpectations(mock_frame_receiver_observer_); 433 Mock::VerifyAndClearExpectations(mock_frame_receiver_observer_);
447 434
448 // Add a fourth client now that some buffers have come through. 435 // Add a fourth client now that some buffers have come through.
449 controller_->AddClient(client_b_route_2, 436 controller_->AddClient(client_b_route_2,
450 client_b_.get(), 437 client_b_.get(),
451 1, 438 1,
452 session_1); 439 session_1);
453 Mock::VerifyAndClearExpectations(client_b_.get()); 440 Mock::VerifyAndClearExpectations(client_b_.get());
454 441
455 // Third, fourth, and fifth buffers. Pretend they all arrive at the same time. 442 // Third, fourth, and fifth buffers. Pretend they all arrive at the same time.
456 for (int i = 0; i < kPoolSize; i++) { 443 for (int i = 0; i < kPoolSize; i++) {
457 const int arbitrary_frame_feedback_id = 200 + i; 444 const int arbitrary_frame_feedback_id = 200 + i;
458 std::unique_ptr<media::VideoCaptureDevice::Client::Buffer> buffer = 445 std::unique_ptr<media::VideoCaptureDevice::Client::Buffer> buffer =
459 device_client_->ReserveOutputBuffer(capture_resolution, format, 446 device_client_->ReserveOutputBuffer(device_format.frame_size,
460 media::PIXEL_STORAGE_CPU, 447 device_format.pixel_format,
448 device_format.pixel_storage,
461 arbitrary_frame_feedback_id); 449 arbitrary_frame_feedback_id);
462 ASSERT_TRUE(buffer.get()); 450 ASSERT_TRUE(buffer.get());
463 memset(buffer->data(), buffer_no++, buffer->mapped_size()); 451 memset(buffer->data(), buffer_no++, buffer->mapped_size());
464 video_frame = WrapBuffer(capture_resolution, 452 device_client_->OnIncomingCapturedBuffer(std::move(buffer),
465 static_cast<uint8_t*>(buffer->data()), format); 453 device_format,
466 ASSERT_TRUE(video_frame); 454 arbitrary_reference_time_,
467 video_frame->metadata()->SetTimeTicks( 455 arbitrary_timestamp_);
468 media::VideoFrameMetadata::REFERENCE_TIME, base::TimeTicks());
469 device_client_->OnIncomingCapturedVideoFrame(std::move(buffer),
470 video_frame);
471 } 456 }
472 // ReserveOutputBuffer ought to fail now, because the pool is depleted. 457 // ReserveOutputBuffer ought to fail now, because the pool is depleted.
473 ASSERT_FALSE(device_client_ 458 ASSERT_FALSE(device_client_
474 ->ReserveOutputBuffer(capture_resolution, format, 459 ->ReserveOutputBuffer(device_format.frame_size,
475 media::PIXEL_STORAGE_CPU, 460 device_format.pixel_format,
461 device_format.pixel_storage,
476 arbitrary_frame_feedback_id) 462 arbitrary_frame_feedback_id)
477 .get()); 463 .get());
478 464
479 // The new client needs to be notified of the creation of |kPoolSize| buffers; 465 // The new client needs to be notified of the creation of |kPoolSize| buffers;
480 // the old clients only |kPoolSize - 2|. 466 // the old clients only |kPoolSize - 2|.
481 EXPECT_CALL(*client_b_, DoBufferCreated(client_b_route_2)).Times(kPoolSize); 467 EXPECT_CALL(*client_b_, DoBufferCreated(client_b_route_2)).Times(kPoolSize);
482 EXPECT_CALL(*client_b_, DoBufferReady(client_b_route_2, capture_resolution)) 468 EXPECT_CALL(*client_b_,
469 DoBufferReady(client_b_route_2, device_format.frame_size))
483 .Times(kPoolSize); 470 .Times(kPoolSize);
484 EXPECT_CALL(*client_a_, DoBufferCreated(client_a_route_1)) 471 EXPECT_CALL(*client_a_, DoBufferCreated(client_a_route_1))
485 .Times(kPoolSize - 2); 472 .Times(kPoolSize - 2);
486 EXPECT_CALL(*client_a_, DoBufferReady(client_a_route_1, capture_resolution)) 473 EXPECT_CALL(*client_a_,
474 DoBufferReady(client_a_route_1, device_format.frame_size))
487 .Times(kPoolSize); 475 .Times(kPoolSize);
488 EXPECT_CALL(*client_a_, DoBufferCreated(client_a_route_2)) 476 EXPECT_CALL(*client_a_, DoBufferCreated(client_a_route_2))
489 .Times(kPoolSize - 2); 477 .Times(kPoolSize - 2);
490 EXPECT_CALL(*client_a_, DoBufferReady(client_a_route_2, capture_resolution)) 478 EXPECT_CALL(*client_a_,
479 DoBufferReady(client_a_route_2, device_format.frame_size))
491 .Times(kPoolSize); 480 .Times(kPoolSize);
492 EXPECT_CALL(*client_b_, DoBufferCreated(client_b_route_1)) 481 EXPECT_CALL(*client_b_, DoBufferCreated(client_b_route_1))
493 .Times(kPoolSize - 2); 482 .Times(kPoolSize - 2);
494 EXPECT_CALL(*client_b_, DoBufferReady(client_b_route_1, capture_resolution)) 483 EXPECT_CALL(*client_b_,
484 DoBufferReady(client_b_route_1, device_format.frame_size))
495 .Times(kPoolSize); 485 .Times(kPoolSize);
496 base::RunLoop().RunUntilIdle(); 486 base::RunLoop().RunUntilIdle();
497 Mock::VerifyAndClearExpectations(client_a_.get()); 487 Mock::VerifyAndClearExpectations(client_a_.get());
498 Mock::VerifyAndClearExpectations(client_b_.get()); 488 Mock::VerifyAndClearExpectations(client_b_.get());
499 489
500 // Now test the interaction of client shutdown and buffer delivery. 490 // Now test the interaction of client shutdown and buffer delivery.
501 // Kill A1 via renderer disconnect (synchronous). 491 // Kill A1 via renderer disconnect (synchronous).
502 controller_->RemoveClient(client_a_route_1, client_a_.get()); 492 controller_->RemoveClient(client_a_route_1, client_a_.get());
503 // Kill B1 via session close (posts a task to disconnect). 493 // Kill B1 via session close (posts a task to disconnect).
504 EXPECT_CALL(*client_b_, DoEnded(client_b_route_1)).Times(1); 494 EXPECT_CALL(*client_b_, DoEnded(client_b_route_1)).Times(1);
505 controller_->StopSession(300); 495 controller_->StopSession(300);
506 // Queue up another buffer. 496 // Queue up another buffer.
507 std::unique_ptr<media::VideoCaptureDevice::Client::Buffer> buffer3 = 497 std::unique_ptr<media::VideoCaptureDevice::Client::Buffer> buffer3 =
508 device_client_->ReserveOutputBuffer(capture_resolution, format, 498 device_client_->ReserveOutputBuffer(device_format.frame_size,
509 media::PIXEL_STORAGE_CPU, 499 device_format.pixel_format,
500 device_format.pixel_storage,
510 arbitrary_frame_feedback_id); 501 arbitrary_frame_feedback_id);
511 ASSERT_TRUE(buffer3.get()); 502 ASSERT_TRUE(buffer3.get());
512 memset(buffer3->data(), buffer_no++, buffer3->mapped_size()); 503 memset(buffer3->data(), buffer_no++, buffer3->mapped_size());
513 video_frame = WrapBuffer(capture_resolution, 504 device_client_->OnIncomingCapturedBuffer(std::move(buffer3),
514 static_cast<uint8_t*>(buffer3->data()), format); 505 device_format,
515 ASSERT_TRUE(video_frame); 506 arbitrary_reference_time_,
516 video_frame->metadata()->SetTimeTicks( 507 arbitrary_timestamp_);
517 media::VideoFrameMetadata::REFERENCE_TIME, base::TimeTicks());
518 device_client_->OnIncomingCapturedVideoFrame(std::move(buffer3), video_frame);
519 508
520 std::unique_ptr<media::VideoCaptureDevice::Client::Buffer> buffer4 = 509 std::unique_ptr<media::VideoCaptureDevice::Client::Buffer> buffer4 =
521 device_client_->ReserveOutputBuffer(capture_resolution, format, 510 device_client_->ReserveOutputBuffer(device_format.frame_size,
522 media::PIXEL_STORAGE_CPU, 511 device_format.pixel_format,
512 device_format.pixel_storage,
523 arbitrary_frame_feedback_id); 513 arbitrary_frame_feedback_id);
524 { 514 {
525 // Kill A2 via session close (posts a task to disconnect, but A2 must not 515 // Kill A2 via session close (posts a task to disconnect, but A2 must not
526 // be sent either of these two buffers). 516 // be sent either of these two buffers).
527 EXPECT_CALL(*client_a_, DoEnded(client_a_route_2)).Times(1); 517 EXPECT_CALL(*client_a_, DoEnded(client_a_route_2)).Times(1);
528 controller_->StopSession(200); 518 controller_->StopSession(200);
529 } 519 }
530 ASSERT_TRUE(buffer4.get()); 520 ASSERT_TRUE(buffer4.get());
531 memset(buffer4->data(), buffer_no++, buffer4->mapped_size()); 521 memset(buffer4->data(), buffer_no++, buffer4->mapped_size());
532 video_frame = WrapBuffer(capture_resolution, 522 device_client_->OnIncomingCapturedBuffer(std::move(buffer4),
533 static_cast<uint8_t*>(buffer4->data()), format); 523 device_format,
534 ASSERT_TRUE(video_frame); 524 arbitrary_reference_time_,
535 video_frame->metadata()->SetTimeTicks( 525 arbitrary_timestamp_);
536 media::VideoFrameMetadata::REFERENCE_TIME, base::TimeTicks());
537 device_client_->OnIncomingCapturedVideoFrame(std::move(buffer4), video_frame);
538 // B2 is the only client left, and is the only one that should 526 // B2 is the only client left, and is the only one that should
539 // get the buffer. 527 // get the buffer.
540 EXPECT_CALL(*client_b_, DoBufferReady(client_b_route_2, capture_resolution)) 528 EXPECT_CALL(*client_b_,
529 DoBufferReady(client_b_route_2, device_format.frame_size))
541 .Times(2); 530 .Times(2);
542 base::RunLoop().RunUntilIdle(); 531 base::RunLoop().RunUntilIdle();
543 Mock::VerifyAndClearExpectations(client_a_.get()); 532 Mock::VerifyAndClearExpectations(client_a_.get());
544 Mock::VerifyAndClearExpectations(client_b_.get()); 533 Mock::VerifyAndClearExpectations(client_b_.get());
545 } 534 }
546 535
547 INSTANTIATE_TEST_CASE_P(, 536 INSTANTIATE_TEST_CASE_P(,
548 VideoCaptureControllerTest, 537 VideoCaptureControllerTest,
549 ::testing::Values(media::PIXEL_FORMAT_I420, 538 ::testing::Values(media::PIXEL_FORMAT_I420,
550 media::PIXEL_FORMAT_Y16)); 539 media::PIXEL_FORMAT_Y16));
(...skipping 18 matching lines...) Expand all
569 base::RunLoop().RunUntilIdle(); 558 base::RunLoop().RunUntilIdle();
570 Mock::VerifyAndClearExpectations(client_a_.get()); 559 Mock::VerifyAndClearExpectations(client_a_.get());
571 560
572 // Second client connects after the error state. It also should get told of 561 // Second client connects after the error state. It also should get told of
573 // the error. 562 // the error.
574 EXPECT_CALL(*client_b_, DoError(route_id)).Times(1); 563 EXPECT_CALL(*client_b_, DoError(route_id)).Times(1);
575 controller_->AddClient(route_id, client_b_.get(), 200, session_200); 564 controller_->AddClient(route_id, client_b_.get(), 200, session_200);
576 base::RunLoop().RunUntilIdle(); 565 base::RunLoop().RunUntilIdle();
577 Mock::VerifyAndClearExpectations(client_b_.get()); 566 Mock::VerifyAndClearExpectations(client_b_.get());
578 567
579 const int arbitrary_frame_feedback_id = 101; 568 media::VideoCaptureFormat device_format(
569 capture_resolution, arbitrary_frame_rate_, media::PIXEL_FORMAT_I420,
570 media::PIXEL_STORAGE_CPU);
571 const int arbitrary_frame_feedback_id = 101;
580 std::unique_ptr<media::VideoCaptureDevice::Client::Buffer> buffer( 572 std::unique_ptr<media::VideoCaptureDevice::Client::Buffer> buffer(
581 device_client_->ReserveOutputBuffer( 573 device_client_->ReserveOutputBuffer(device_format.frame_size,
582 capture_resolution, media::PIXEL_FORMAT_I420, 574 device_format.pixel_format,
583 media::PIXEL_STORAGE_CPU, arbitrary_frame_feedback_id)); 575 device_format.pixel_storage,
584 ASSERT_TRUE(buffer.get()); 576 arbitrary_frame_feedback_id));
585 scoped_refptr<media::VideoFrame> video_frame = 577 device_client_->OnIncomingCapturedBuffer(std::move(buffer),
586 WrapBuffer(capture_resolution, static_cast<uint8_t*>(buffer->data())); 578 device_format,
587 ASSERT_TRUE(video_frame); 579 arbitrary_reference_time_,
588 video_frame->metadata()->SetTimeTicks( 580 arbitrary_timestamp_);
589 media::VideoFrameMetadata::REFERENCE_TIME, base::TimeTicks());
590 device_client_->OnIncomingCapturedVideoFrame(std::move(buffer), video_frame);
591 581
592 base::RunLoop().RunUntilIdle(); 582 base::RunLoop().RunUntilIdle();
593 } 583 }
594 584
595 // Exercises the OnError() codepath of VideoCaptureController, and tests the 585 // Exercises the OnError() codepath of VideoCaptureController, and tests the
596 // behavior of various operations after the error state has been signalled. 586 // behavior of various operations after the error state has been signalled.
597 TEST_F(VideoCaptureControllerTest, ErrorAfterDeviceCreation) { 587 TEST_F(VideoCaptureControllerTest, ErrorAfterDeviceCreation) {
598 media::VideoCaptureParams session_100; 588 media::VideoCaptureParams session_100;
599 session_100.requested_format = media::VideoCaptureFormat( 589 session_100.requested_format = media::VideoCaptureFormat(
600 gfx::Size(320, 240), 30, media::PIXEL_FORMAT_I420); 590 gfx::Size(320, 240), 30, media::PIXEL_FORMAT_I420);
601 591
602 media::VideoCaptureParams session_200 = session_100; 592 media::VideoCaptureParams session_200 = session_100;
603 593
604 const VideoCaptureControllerID route_id(0x99); 594 const VideoCaptureControllerID route_id(0x99);
605 595
606 // Start with one client. 596 // Start with one client.
607 controller_->AddClient(route_id, client_a_.get(), 100, session_100); 597 controller_->AddClient(route_id, client_a_.get(), 100, session_100);
608 media::VideoCaptureFormat device_format(
609 gfx::Size(10, 10), 25, media::PIXEL_FORMAT_ARGB);
610 598
611 // Start the device. Then, before the first buffer, signal an error and 599 // 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 600 // deliver the buffer. The error should be propagated to clients; the buffer
613 // should not be. 601 // should not be.
614 base::RunLoop().RunUntilIdle(); 602 base::RunLoop().RunUntilIdle();
615 Mock::VerifyAndClearExpectations(client_a_.get()); 603 Mock::VerifyAndClearExpectations(client_a_.get());
616 604
617 const gfx::Size dims(320, 240); 605 media::VideoCaptureFormat device_format(
606 gfx::Size(10, 10), arbitrary_frame_rate_, media::PIXEL_FORMAT_I420);
618 const int arbitrary_frame_feedback_id = 101; 607 const int arbitrary_frame_feedback_id = 101;
619 std::unique_ptr<media::VideoCaptureDevice::Client::Buffer> buffer( 608 std::unique_ptr<media::VideoCaptureDevice::Client::Buffer> buffer(
620 device_client_->ReserveOutputBuffer(dims, media::PIXEL_FORMAT_I420, 609 device_client_->ReserveOutputBuffer(device_format.frame_size,
621 media::PIXEL_STORAGE_CPU, 610 device_format.pixel_format,
611 device_format.pixel_storage,
622 arbitrary_frame_feedback_id)); 612 arbitrary_frame_feedback_id));
623 ASSERT_TRUE(buffer.get()); 613 ASSERT_TRUE(buffer.get());
624 614
625 scoped_refptr<media::VideoFrame> video_frame =
626 WrapBuffer(dims, static_cast<uint8_t*>(buffer->data()));
627 ASSERT_TRUE(video_frame);
628 device_client_->OnError(FROM_HERE, "Test Error"); 615 device_client_->OnError(FROM_HERE, "Test Error");
629 video_frame->metadata()->SetTimeTicks( 616 device_client_->OnIncomingCapturedBuffer(std::move(buffer),
630 media::VideoFrameMetadata::REFERENCE_TIME, base::TimeTicks()); 617 device_format,
631 device_client_->OnIncomingCapturedVideoFrame(std::move(buffer), video_frame); 618 arbitrary_reference_time_,
619 arbitrary_timestamp_);
632 620
633 EXPECT_CALL(*client_a_, DoError(route_id)).Times(1); 621 EXPECT_CALL(*client_a_, DoError(route_id)).Times(1);
634 base::RunLoop().RunUntilIdle(); 622 base::RunLoop().RunUntilIdle();
635 Mock::VerifyAndClearExpectations(client_a_.get()); 623 Mock::VerifyAndClearExpectations(client_a_.get());
636 624
637 // Second client connects after the error state. It also should get told of 625 // Second client connects after the error state. It also should get told of
638 // the error. 626 // the error.
639 EXPECT_CALL(*client_b_, DoError(route_id)).Times(1); 627 EXPECT_CALL(*client_b_, DoError(route_id)).Times(1);
640 controller_->AddClient(route_id, client_b_.get(), 200, session_200); 628 controller_->AddClient(route_id, client_b_.get(), 200, session_200);
641 Mock::VerifyAndClearExpectations(client_b_.get()); 629 Mock::VerifyAndClearExpectations(client_b_.get());
642 } 630 }
643 631
644 } // namespace content 632 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698