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

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

Issue 1064703002: VideoCaptureBufferPool: Refactor to allow support of non-ShMem backed buffers (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: miu@s nits Created 5 years, 8 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 // Unit test for VideoCaptureController. 5 // Unit test for VideoCaptureController.
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/bind_helpers.h" 10 #include "base/bind_helpers.h"
(...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after
319 client_a_.get(), 319 client_a_.get(),
320 base::kNullProcessHandle, 320 base::kNullProcessHandle,
321 200, 321 200,
322 session_200); 322 session_200);
323 ASSERT_EQ(3, controller_->GetClientCount()); 323 ASSERT_EQ(3, controller_->GetClientCount());
324 324
325 // Now, simulate an incoming captured buffer from the capture device. As a 325 // Now, simulate an incoming captured buffer from the capture device. As a
326 // side effect this will cause the first buffer to be shared with clients. 326 // side effect this will cause the first buffer to be shared with clients.
327 uint8 buffer_no = 1; 327 uint8 buffer_no = 1;
328 scoped_refptr<media::VideoCaptureDevice::Client::Buffer> buffer; 328 scoped_refptr<media::VideoCaptureDevice::Client::Buffer> buffer;
329 buffer = 329 buffer = device_->ReserveOutputBuffer(media::PIXEL_FORMAT_I420,
330 device_->ReserveOutputBuffer(media::VideoFrame::I420, capture_resolution); 330 capture_resolution);
331 ASSERT_TRUE(buffer.get()); 331 ASSERT_TRUE(buffer.get());
332 memset(buffer->data(), buffer_no++, buffer->size()); 332 memset(buffer->data(), buffer_no++, buffer->size());
333 { 333 {
334 InSequence s; 334 InSequence s;
335 EXPECT_CALL(*client_a_, DoBufferCreated(client_a_route_1)).Times(1); 335 EXPECT_CALL(*client_a_, DoBufferCreated(client_a_route_1)).Times(1);
336 EXPECT_CALL(*client_a_, DoBufferReady(client_a_route_1,_)).Times(1); 336 EXPECT_CALL(*client_a_, DoBufferReady(client_a_route_1,_)).Times(1);
337 } 337 }
338 { 338 {
339 InSequence s; 339 InSequence s;
340 EXPECT_CALL(*client_b_, DoBufferCreated(client_b_route_1)).Times(1); 340 EXPECT_CALL(*client_b_, DoBufferCreated(client_b_route_1)).Times(1);
(...skipping 10 matching lines...) Expand all
351 base::TimeTicks()); 351 base::TimeTicks());
352 buffer = NULL; 352 buffer = NULL;
353 353
354 base::RunLoop().RunUntilIdle(); 354 base::RunLoop().RunUntilIdle();
355 Mock::VerifyAndClearExpectations(client_a_.get()); 355 Mock::VerifyAndClearExpectations(client_a_.get());
356 Mock::VerifyAndClearExpectations(client_b_.get()); 356 Mock::VerifyAndClearExpectations(client_b_.get());
357 357
358 // 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
359 // 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
360 // delay. This shouldn't affect anything. 360 // delay. This shouldn't affect anything.
361 buffer = 361 buffer = device_->ReserveOutputBuffer(media::PIXEL_FORMAT_I420,
362 device_->ReserveOutputBuffer(media::VideoFrame::I420, capture_resolution); 362 capture_resolution);
363 ASSERT_TRUE(buffer.get()); 363 ASSERT_TRUE(buffer.get());
364 memset(buffer->data(), buffer_no++, buffer->size()); 364 memset(buffer->data(), buffer_no++, buffer->size());
365 device_->OnIncomingCapturedVideoFrame( 365 device_->OnIncomingCapturedVideoFrame(
366 buffer, 366 buffer,
367 WrapI420Buffer(buffer, capture_resolution), 367 WrapI420Buffer(buffer, capture_resolution),
368 base::TimeTicks()); 368 base::TimeTicks());
369 buffer = NULL; 369 buffer = NULL;
370 370
371 // The buffer should be delivered to the clients in any order. 371 // The buffer should be delivered to the clients in any order.
372 EXPECT_CALL(*client_a_, DoBufferReady(client_a_route_1,_)).Times(1); 372 EXPECT_CALL(*client_a_, DoBufferReady(client_a_route_1,_)).Times(1);
373 EXPECT_CALL(*client_b_, DoBufferReady(client_b_route_1,_)).Times(1); 373 EXPECT_CALL(*client_b_, DoBufferReady(client_b_route_1,_)).Times(1);
374 EXPECT_CALL(*client_a_, DoBufferReady(client_a_route_2,_)).Times(1); 374 EXPECT_CALL(*client_a_, DoBufferReady(client_a_route_2,_)).Times(1);
375 base::RunLoop().RunUntilIdle(); 375 base::RunLoop().RunUntilIdle();
376 Mock::VerifyAndClearExpectations(client_a_.get()); 376 Mock::VerifyAndClearExpectations(client_a_.get());
377 Mock::VerifyAndClearExpectations(client_b_.get()); 377 Mock::VerifyAndClearExpectations(client_b_.get());
378 378
379 // Add a fourth client now that some buffers have come through. 379 // Add a fourth client now that some buffers have come through.
380 controller_->AddClient(client_b_route_2, 380 controller_->AddClient(client_b_route_2,
381 client_b_.get(), 381 client_b_.get(),
382 base::kNullProcessHandle, 382 base::kNullProcessHandle,
383 1, 383 1,
384 session_1); 384 session_1);
385 Mock::VerifyAndClearExpectations(client_b_.get()); 385 Mock::VerifyAndClearExpectations(client_b_.get());
386 386
387 // Third, fourth, and fifth buffers. Pretend they all arrive at the same time. 387 // Third, fourth, and fifth buffers. Pretend they all arrive at the same time.
388 for (int i = 0; i < kPoolSize; i++) { 388 for (int i = 0; i < kPoolSize; i++) {
389 buffer = device_->ReserveOutputBuffer(media::VideoFrame::I420, 389 buffer = device_->ReserveOutputBuffer(media::PIXEL_FORMAT_I420,
390 capture_resolution); 390 capture_resolution);
391 ASSERT_TRUE(buffer.get()); 391 ASSERT_TRUE(buffer.get());
392 memset(buffer->data(), buffer_no++, buffer->size()); 392 memset(buffer->data(), buffer_no++, buffer->size());
393 device_->OnIncomingCapturedVideoFrame( 393 device_->OnIncomingCapturedVideoFrame(
394 buffer, 394 buffer,
395 WrapI420Buffer(buffer, capture_resolution), 395 WrapI420Buffer(buffer, capture_resolution),
396 base::TimeTicks()); 396 base::TimeTicks());
397 buffer = NULL; 397 buffer = NULL;
398 } 398 }
399 // ReserveOutputBuffer ought to fail now, because the pool is depleted. 399 // ReserveOutputBuffer ought to fail now, because the pool is depleted.
400 ASSERT_FALSE(device_->ReserveOutputBuffer(media::VideoFrame::I420, 400 ASSERT_FALSE(device_->ReserveOutputBuffer(media::PIXEL_FORMAT_I420,
401 capture_resolution).get()); 401 capture_resolution).get());
402 402
403 // The new client needs to be told of 3 buffers; the old clients only 2. 403 // The new client needs to be told of 3 buffers; the old clients only 2.
404 EXPECT_CALL(*client_b_, DoBufferCreated(client_b_route_2)).Times(kPoolSize); 404 EXPECT_CALL(*client_b_, DoBufferCreated(client_b_route_2)).Times(kPoolSize);
405 EXPECT_CALL(*client_b_, DoBufferReady(client_b_route_2,_)).Times(kPoolSize); 405 EXPECT_CALL(*client_b_, DoBufferReady(client_b_route_2,_)).Times(kPoolSize);
406 EXPECT_CALL(*client_a_, DoBufferCreated(client_a_route_1)) 406 EXPECT_CALL(*client_a_, DoBufferCreated(client_a_route_1))
407 .Times(kPoolSize - 1); 407 .Times(kPoolSize - 1);
408 EXPECT_CALL(*client_a_, DoBufferReady(client_a_route_1,_)).Times(kPoolSize); 408 EXPECT_CALL(*client_a_, DoBufferReady(client_a_route_1,_)).Times(kPoolSize);
409 EXPECT_CALL(*client_a_, DoBufferCreated(client_a_route_2)) 409 EXPECT_CALL(*client_a_, DoBufferCreated(client_a_route_2))
410 .Times(kPoolSize - 1); 410 .Times(kPoolSize - 1);
411 EXPECT_CALL(*client_a_, DoBufferReady(client_a_route_2,_)).Times(kPoolSize); 411 EXPECT_CALL(*client_a_, DoBufferReady(client_a_route_2,_)).Times(kPoolSize);
412 EXPECT_CALL(*client_b_, DoBufferCreated(client_b_route_1)) 412 EXPECT_CALL(*client_b_, DoBufferCreated(client_b_route_1))
413 .Times(kPoolSize - 1); 413 .Times(kPoolSize - 1);
414 EXPECT_CALL(*client_b_, DoBufferReady(client_b_route_1,_)).Times(kPoolSize); 414 EXPECT_CALL(*client_b_, DoBufferReady(client_b_route_1,_)).Times(kPoolSize);
415 base::RunLoop().RunUntilIdle(); 415 base::RunLoop().RunUntilIdle();
416 Mock::VerifyAndClearExpectations(client_a_.get()); 416 Mock::VerifyAndClearExpectations(client_a_.get());
417 Mock::VerifyAndClearExpectations(client_b_.get()); 417 Mock::VerifyAndClearExpectations(client_b_.get());
418 418
419 // Now test the interaction of client shutdown and buffer delivery. 419 // Now test the interaction of client shutdown and buffer delivery.
420 // Kill A1 via renderer disconnect (synchronous). 420 // Kill A1 via renderer disconnect (synchronous).
421 controller_->RemoveClient(client_a_route_1, client_a_.get()); 421 controller_->RemoveClient(client_a_route_1, client_a_.get());
422 // Kill B1 via session close (posts a task to disconnect). 422 // Kill B1 via session close (posts a task to disconnect).
423 EXPECT_CALL(*client_b_, DoEnded(client_b_route_1)).Times(1); 423 EXPECT_CALL(*client_b_, DoEnded(client_b_route_1)).Times(1);
424 controller_->StopSession(300); 424 controller_->StopSession(300);
425 // Queue up another buffer. 425 // Queue up another buffer.
426 buffer = 426 buffer = device_->ReserveOutputBuffer(media::PIXEL_FORMAT_I420,
427 device_->ReserveOutputBuffer(media::VideoFrame::I420, capture_resolution); 427 capture_resolution);
428 ASSERT_TRUE(buffer.get()); 428 ASSERT_TRUE(buffer.get());
429 memset(buffer->data(), buffer_no++, buffer->size()); 429 memset(buffer->data(), buffer_no++, buffer->size());
430 device_->OnIncomingCapturedVideoFrame( 430 device_->OnIncomingCapturedVideoFrame(
431 buffer, 431 buffer,
432 WrapI420Buffer(buffer, capture_resolution), 432 WrapI420Buffer(buffer, capture_resolution),
433 base::TimeTicks()); 433 base::TimeTicks());
434 buffer = NULL; 434 buffer = NULL;
435 buffer = 435 buffer = device_->ReserveOutputBuffer(media::PIXEL_FORMAT_I420,
436 device_->ReserveOutputBuffer(media::VideoFrame::I420, capture_resolution); 436 capture_resolution);
437 { 437 {
438 // Kill A2 via session close (posts a task to disconnect, but A2 must not 438 // Kill A2 via session close (posts a task to disconnect, but A2 must not
439 // be sent either of these two buffers). 439 // be sent either of these two buffers).
440 EXPECT_CALL(*client_a_, DoEnded(client_a_route_2)).Times(1); 440 EXPECT_CALL(*client_a_, DoEnded(client_a_route_2)).Times(1);
441 controller_->StopSession(200); 441 controller_->StopSession(200);
442 } 442 }
443 ASSERT_TRUE(buffer.get()); 443 ASSERT_TRUE(buffer.get());
444 memset(buffer->data(), buffer_no++, buffer->size()); 444 memset(buffer->data(), buffer_no++, buffer->size());
445 device_->OnIncomingCapturedVideoFrame( 445 device_->OnIncomingCapturedVideoFrame(
446 buffer, 446 buffer,
(...skipping 15 matching lines...) Expand all
462 int mailbox_buffers = kPoolSize / 2; 462 int mailbox_buffers = kPoolSize / 2;
463 GLHelper* gl_helper = ImageTransportFactory::GetInstance()->GetGLHelper(); 463 GLHelper* gl_helper = ImageTransportFactory::GetInstance()->GetGLHelper();
464 #endif 464 #endif
465 int shm_buffers = kPoolSize - mailbox_buffers; 465 int shm_buffers = kPoolSize - mailbox_buffers;
466 if (shm_buffers == mailbox_buffers) { 466 if (shm_buffers == mailbox_buffers) {
467 shm_buffers--; 467 shm_buffers--;
468 mailbox_buffers++; 468 mailbox_buffers++;
469 } 469 }
470 470
471 for (int i = 0; i < shm_buffers; ++i) { 471 for (int i = 0; i < shm_buffers; ++i) {
472 buffer = device_->ReserveOutputBuffer(media::VideoFrame::I420, 472 buffer = device_->ReserveOutputBuffer(media::PIXEL_FORMAT_I420,
473 capture_resolution); 473 capture_resolution);
474 ASSERT_TRUE(buffer.get()); 474 ASSERT_TRUE(buffer.get());
475 device_->OnIncomingCapturedVideoFrame( 475 device_->OnIncomingCapturedVideoFrame(
476 buffer, 476 buffer,
477 WrapI420Buffer(buffer, capture_resolution), 477 WrapI420Buffer(buffer, capture_resolution),
478 base::TimeTicks()); 478 base::TimeTicks());
479 buffer = NULL; 479 buffer = NULL;
480 } 480 }
481 std::vector<uint32> mailbox_syncpoints(mailbox_buffers); 481 std::vector<uint32> mailbox_syncpoints(mailbox_buffers);
482 std::vector<uint32> release_syncpoints(mailbox_buffers); 482 std::vector<uint32> release_syncpoints(mailbox_buffers);
483 for (int i = 0; i < mailbox_buffers; ++i) { 483 for (int i = 0; i < mailbox_buffers; ++i) {
484 buffer = device_->ReserveOutputBuffer(media::VideoFrame::NATIVE_TEXTURE, 484 buffer = device_->ReserveOutputBuffer(media::PIXEL_FORMAT_TEXTURE,
485 gfx::Size(0, 0)); 485 capture_resolution);
486 ASSERT_TRUE(buffer.get()); 486 ASSERT_TRUE(buffer.get());
487 #if !defined(OS_ANDROID) 487 #if !defined(OS_ANDROID)
488 mailbox_syncpoints[i] = gl_helper->InsertSyncPoint(); 488 mailbox_syncpoints[i] = gl_helper->InsertSyncPoint();
489 #endif 489 #endif
490 device_->OnIncomingCapturedVideoFrame( 490 device_->OnIncomingCapturedVideoFrame(
491 buffer, 491 buffer,
492 WrapMailboxBuffer(make_scoped_ptr(new gpu::MailboxHolder( 492 WrapMailboxBuffer(make_scoped_ptr(new gpu::MailboxHolder(
493 gpu::Mailbox(), 0, mailbox_syncpoints[i])), 493 gpu::Mailbox(), 0, mailbox_syncpoints[i])),
494 base::Bind(&CacheSyncPoint, &release_syncpoints[i]), 494 base::Bind(&CacheSyncPoint, &release_syncpoints[i]),
495 capture_resolution), 495 capture_resolution),
496 base::TimeTicks()); 496 base::TimeTicks());
497 buffer = NULL; 497 buffer = NULL;
498 } 498 }
499 // ReserveOutputBuffers ought to fail now regardless of buffer format, because 499 // ReserveOutputBuffers ought to fail now regardless of buffer format, because
500 // the pool is depleted. 500 // the pool is depleted.
501 ASSERT_FALSE(device_->ReserveOutputBuffer(media::VideoFrame::I420, 501 ASSERT_FALSE(device_->ReserveOutputBuffer(media::PIXEL_FORMAT_I420,
502 capture_resolution).get()); 502 capture_resolution).get());
503 ASSERT_FALSE(device_->ReserveOutputBuffer(media::VideoFrame::NATIVE_TEXTURE, 503 ASSERT_FALSE(device_->ReserveOutputBuffer(media::PIXEL_FORMAT_TEXTURE,
504 gfx::Size(0, 0)).get()); 504 capture_resolution).get());
505 EXPECT_CALL(*client_b_, DoBufferReady(client_b_route_2,_)).Times(shm_buffers); 505 EXPECT_CALL(*client_b_, DoBufferReady(client_b_route_2,_)).Times(shm_buffers);
506 EXPECT_CALL(*client_b_, DoMailboxBufferReady(client_b_route_2)) 506 EXPECT_CALL(*client_b_, DoMailboxBufferReady(client_b_route_2))
507 .Times(mailbox_buffers); 507 .Times(mailbox_buffers);
508 base::RunLoop().RunUntilIdle(); 508 base::RunLoop().RunUntilIdle();
509 for (size_t i = 0; i < mailbox_syncpoints.size(); ++i) { 509 for (size_t i = 0; i < mailbox_syncpoints.size(); ++i) {
510 // A new release sync point must be inserted when the video frame is 510 // A new release sync point must be inserted when the video frame is
511 // returned to the Browser process. 511 // returned to the Browser process.
512 // See: MockVideoCaptureControllerEventHandler::OnMailboxBufferReady() and 512 // See: MockVideoCaptureControllerEventHandler::OnMailboxBufferReady() and
513 // VideoCaptureController::ReturnBuffer() 513 // VideoCaptureController::ReturnBuffer()
514 ASSERT_NE(mailbox_syncpoints[i], release_syncpoints[i]); 514 ASSERT_NE(mailbox_syncpoints[i], release_syncpoints[i]);
(...skipping 28 matching lines...) Expand all
543 543
544 // Second client connects after the error state. It also should get told of 544 // Second client connects after the error state. It also should get told of
545 // the error. 545 // the error.
546 EXPECT_CALL(*client_b_, DoError(route_id)).Times(1); 546 EXPECT_CALL(*client_b_, DoError(route_id)).Times(1);
547 controller_->AddClient( 547 controller_->AddClient(
548 route_id, client_b_.get(), base::kNullProcessHandle, 200, session_200); 548 route_id, client_b_.get(), base::kNullProcessHandle, 200, session_200);
549 base::RunLoop().RunUntilIdle(); 549 base::RunLoop().RunUntilIdle();
550 Mock::VerifyAndClearExpectations(client_b_.get()); 550 Mock::VerifyAndClearExpectations(client_b_.get());
551 551
552 scoped_refptr<media::VideoCaptureDevice::Client::Buffer> buffer = 552 scoped_refptr<media::VideoCaptureDevice::Client::Buffer> buffer =
553 device_->ReserveOutputBuffer(media::VideoFrame::I420, capture_resolution); 553 device_->ReserveOutputBuffer(media::PIXEL_FORMAT_I420,
554 capture_resolution);
554 ASSERT_TRUE(buffer.get()); 555 ASSERT_TRUE(buffer.get());
555 556
556 device_->OnIncomingCapturedVideoFrame( 557 device_->OnIncomingCapturedVideoFrame(
557 buffer, 558 buffer,
558 WrapI420Buffer(buffer, capture_resolution), 559 WrapI420Buffer(buffer, capture_resolution),
559 base::TimeTicks()); 560 base::TimeTicks());
560 buffer = NULL; 561 buffer = NULL;
561 562
562 base::RunLoop().RunUntilIdle(); 563 base::RunLoop().RunUntilIdle();
563 } 564 }
(...skipping 16 matching lines...) Expand all
580 gfx::Size(10, 10), 25, media::PIXEL_FORMAT_ARGB); 581 gfx::Size(10, 10), 25, media::PIXEL_FORMAT_ARGB);
581 582
582 // Start the device. Then, before the first buffer, signal an error and 583 // Start the device. Then, before the first buffer, signal an error and
583 // deliver the buffer. The error should be propagated to clients; the buffer 584 // deliver the buffer. The error should be propagated to clients; the buffer
584 // should not be. 585 // should not be.
585 base::RunLoop().RunUntilIdle(); 586 base::RunLoop().RunUntilIdle();
586 Mock::VerifyAndClearExpectations(client_a_.get()); 587 Mock::VerifyAndClearExpectations(client_a_.get());
587 588
588 const gfx::Size dims(320, 240); 589 const gfx::Size dims(320, 240);
589 scoped_refptr<media::VideoCaptureDevice::Client::Buffer> buffer = 590 scoped_refptr<media::VideoCaptureDevice::Client::Buffer> buffer =
590 device_->ReserveOutputBuffer(media::VideoFrame::I420, dims); 591 device_->ReserveOutputBuffer(media::PIXEL_FORMAT_I420, dims);
591 ASSERT_TRUE(buffer.get()); 592 ASSERT_TRUE(buffer.get());
592 593
593 device_->OnError("Test error"); 594 device_->OnError("Test error");
594 device_->OnIncomingCapturedVideoFrame( 595 device_->OnIncomingCapturedVideoFrame(
595 buffer, 596 buffer,
596 WrapI420Buffer(buffer, dims), 597 WrapI420Buffer(buffer, dims),
597 base::TimeTicks()); 598 base::TimeTicks());
598 buffer = NULL; 599 buffer = NULL;
599 600
600 EXPECT_CALL(*client_a_, DoError(route_id)).Times(1); 601 EXPECT_CALL(*client_a_, DoError(route_id)).Times(1);
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
703 EXPECT_EQ(coded_size.width(), size_and_rotation.output_resolution.width()); 704 EXPECT_EQ(coded_size.width(), size_and_rotation.output_resolution.width());
704 EXPECT_EQ(coded_size.height(), 705 EXPECT_EQ(coded_size.height(),
705 size_and_rotation.output_resolution.height()); 706 size_and_rotation.output_resolution.height());
706 707
707 EXPECT_EQ(kSessionId, controller_->RemoveClient(route_id, client_a_.get())); 708 EXPECT_EQ(kSessionId, controller_->RemoveClient(route_id, client_a_.get()));
708 Mock::VerifyAndClearExpectations(client_a_.get()); 709 Mock::VerifyAndClearExpectations(client_a_.get());
709 } 710 }
710 } 711 }
711 712
712 } // namespace content 713 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698