OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // Unit test for VideoCaptureController. | 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 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
56 } | 56 } |
57 virtual void OnBufferCreated(const VideoCaptureControllerID& id, | 57 virtual void OnBufferCreated(const VideoCaptureControllerID& id, |
58 base::SharedMemoryHandle handle, | 58 base::SharedMemoryHandle handle, |
59 int length, int buffer_id) override { | 59 int length, int buffer_id) override { |
60 DoBufferCreated(id); | 60 DoBufferCreated(id); |
61 } | 61 } |
62 virtual void OnBufferDestroyed(const VideoCaptureControllerID& id, | 62 virtual void OnBufferDestroyed(const VideoCaptureControllerID& id, |
63 int buffer_id) override { | 63 int buffer_id) override { |
64 DoBufferDestroyed(id); | 64 DoBufferDestroyed(id); |
65 } | 65 } |
66 virtual void OnBufferReady(const VideoCaptureControllerID& id, | 66 virtual void OnBufferReady( |
67 int buffer_id, | 67 const VideoCaptureControllerID& id, |
68 const media::VideoCaptureFormat& format, | 68 int buffer_id, |
69 const gfx::Rect& visible_rect, | 69 const gfx::Size& coded_size, |
70 base::TimeTicks timestamp) override { | 70 const gfx::Rect& visible_rect, |
| 71 base::TimeTicks timestamp, |
| 72 scoped_ptr<base::DictionaryValue> metadata) override { |
71 DoBufferReady(id); | 73 DoBufferReady(id); |
72 base::MessageLoop::current()->PostTask( | 74 base::MessageLoop::current()->PostTask( |
73 FROM_HERE, | 75 FROM_HERE, |
74 base::Bind(&VideoCaptureController::ReturnBuffer, | 76 base::Bind(&VideoCaptureController::ReturnBuffer, |
75 base::Unretained(controller_), | 77 base::Unretained(controller_), |
76 id, | 78 id, |
77 this, | 79 this, |
78 buffer_id, | 80 buffer_id, |
79 0)); | 81 0)); |
80 } | 82 } |
81 virtual void OnMailboxBufferReady(const VideoCaptureControllerID& id, | 83 virtual void OnMailboxBufferReady( |
82 int buffer_id, | 84 const VideoCaptureControllerID& id, |
83 const gpu::MailboxHolder& mailbox_holder, | 85 int buffer_id, |
84 const media::VideoCaptureFormat& format, | 86 const gpu::MailboxHolder& mailbox_holder, |
85 base::TimeTicks timestamp) override { | 87 const gfx::Size& packed_frame_size, |
| 88 base::TimeTicks timestamp, |
| 89 scoped_ptr<base::DictionaryValue> metadata) override { |
86 DoMailboxBufferReady(id); | 90 DoMailboxBufferReady(id); |
87 base::MessageLoop::current()->PostTask( | 91 base::MessageLoop::current()->PostTask( |
88 FROM_HERE, | 92 FROM_HERE, |
89 base::Bind(&VideoCaptureController::ReturnBuffer, | 93 base::Bind(&VideoCaptureController::ReturnBuffer, |
90 base::Unretained(controller_), | 94 base::Unretained(controller_), |
91 id, | 95 id, |
92 this, | 96 this, |
93 buffer_id, | 97 buffer_id, |
94 mailbox_holder.sync_point)); | 98 mailbox_holder.sync_point)); |
95 } | 99 } |
(...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
332 EXPECT_CALL(*client_b_, DoBufferCreated(client_b_route_1)).Times(1); | 336 EXPECT_CALL(*client_b_, DoBufferCreated(client_b_route_1)).Times(1); |
333 EXPECT_CALL(*client_b_, DoBufferReady(client_b_route_1)).Times(1); | 337 EXPECT_CALL(*client_b_, DoBufferReady(client_b_route_1)).Times(1); |
334 } | 338 } |
335 { | 339 { |
336 InSequence s; | 340 InSequence s; |
337 EXPECT_CALL(*client_a_, DoBufferCreated(client_a_route_2)).Times(1); | 341 EXPECT_CALL(*client_a_, DoBufferCreated(client_a_route_2)).Times(1); |
338 EXPECT_CALL(*client_a_, DoBufferReady(client_a_route_2)).Times(1); | 342 EXPECT_CALL(*client_a_, DoBufferReady(client_a_route_2)).Times(1); |
339 } | 343 } |
340 device_->OnIncomingCapturedVideoFrame( | 344 device_->OnIncomingCapturedVideoFrame( |
341 buffer, | 345 buffer, |
342 media::VideoCaptureFormat(capture_resolution, | |
343 device_format.frame_rate, | |
344 media::PIXEL_FORMAT_I420), | |
345 WrapI420Buffer(buffer, capture_resolution), | 346 WrapI420Buffer(buffer, capture_resolution), |
346 base::TimeTicks()); | 347 base::TimeTicks()); |
347 buffer = NULL; | 348 buffer = NULL; |
348 | 349 |
349 base::RunLoop().RunUntilIdle(); | 350 base::RunLoop().RunUntilIdle(); |
350 Mock::VerifyAndClearExpectations(client_a_.get()); | 351 Mock::VerifyAndClearExpectations(client_a_.get()); |
351 Mock::VerifyAndClearExpectations(client_b_.get()); | 352 Mock::VerifyAndClearExpectations(client_b_.get()); |
352 | 353 |
353 // Second buffer which ought to use the same shared memory buffer. In this | 354 // Second buffer which ought to use the same shared memory buffer. In this |
354 // case pretend that the Buffer pointer is held by the device for a long | 355 // case pretend that the Buffer pointer is held by the device for a long |
355 // delay. This shouldn't affect anything. | 356 // delay. This shouldn't affect anything. |
356 buffer = | 357 buffer = |
357 device_->ReserveOutputBuffer(media::VideoFrame::I420, capture_resolution); | 358 device_->ReserveOutputBuffer(media::VideoFrame::I420, capture_resolution); |
358 ASSERT_TRUE(buffer.get()); | 359 ASSERT_TRUE(buffer.get()); |
359 memset(buffer->data(), buffer_no++, buffer->size()); | 360 memset(buffer->data(), buffer_no++, buffer->size()); |
360 device_->OnIncomingCapturedVideoFrame( | 361 device_->OnIncomingCapturedVideoFrame( |
361 buffer, | 362 buffer, |
362 media::VideoCaptureFormat(capture_resolution, | |
363 device_format.frame_rate, | |
364 media::PIXEL_FORMAT_I420), | |
365 WrapI420Buffer(buffer, capture_resolution), | 363 WrapI420Buffer(buffer, capture_resolution), |
366 base::TimeTicks()); | 364 base::TimeTicks()); |
367 buffer = NULL; | 365 buffer = NULL; |
368 | 366 |
369 // The buffer should be delivered to the clients in any order. | 367 // The buffer should be delivered to the clients in any order. |
370 EXPECT_CALL(*client_a_, DoBufferReady(client_a_route_1)).Times(1); | 368 EXPECT_CALL(*client_a_, DoBufferReady(client_a_route_1)).Times(1); |
371 EXPECT_CALL(*client_b_, DoBufferReady(client_b_route_1)).Times(1); | 369 EXPECT_CALL(*client_b_, DoBufferReady(client_b_route_1)).Times(1); |
372 EXPECT_CALL(*client_a_, DoBufferReady(client_a_route_2)).Times(1); | 370 EXPECT_CALL(*client_a_, DoBufferReady(client_a_route_2)).Times(1); |
373 base::RunLoop().RunUntilIdle(); | 371 base::RunLoop().RunUntilIdle(); |
374 Mock::VerifyAndClearExpectations(client_a_.get()); | 372 Mock::VerifyAndClearExpectations(client_a_.get()); |
375 Mock::VerifyAndClearExpectations(client_b_.get()); | 373 Mock::VerifyAndClearExpectations(client_b_.get()); |
376 | 374 |
377 // Add a fourth client now that some buffers have come through. | 375 // Add a fourth client now that some buffers have come through. |
378 controller_->AddClient(client_b_route_2, | 376 controller_->AddClient(client_b_route_2, |
379 client_b_.get(), | 377 client_b_.get(), |
380 base::kNullProcessHandle, | 378 base::kNullProcessHandle, |
381 1, | 379 1, |
382 session_1); | 380 session_1); |
383 Mock::VerifyAndClearExpectations(client_b_.get()); | 381 Mock::VerifyAndClearExpectations(client_b_.get()); |
384 | 382 |
385 // Third, fourth, and fifth buffers. Pretend they all arrive at the same time. | 383 // Third, fourth, and fifth buffers. Pretend they all arrive at the same time. |
386 for (int i = 0; i < kPoolSize; i++) { | 384 for (int i = 0; i < kPoolSize; i++) { |
387 buffer = device_->ReserveOutputBuffer(media::VideoFrame::I420, | 385 buffer = device_->ReserveOutputBuffer(media::VideoFrame::I420, |
388 capture_resolution); | 386 capture_resolution); |
389 ASSERT_TRUE(buffer.get()); | 387 ASSERT_TRUE(buffer.get()); |
390 memset(buffer->data(), buffer_no++, buffer->size()); | 388 memset(buffer->data(), buffer_no++, buffer->size()); |
391 device_->OnIncomingCapturedVideoFrame( | 389 device_->OnIncomingCapturedVideoFrame( |
392 buffer, | 390 buffer, |
393 media::VideoCaptureFormat(capture_resolution, | |
394 device_format.frame_rate, | |
395 media::PIXEL_FORMAT_I420), | |
396 WrapI420Buffer(buffer, capture_resolution), | 391 WrapI420Buffer(buffer, capture_resolution), |
397 base::TimeTicks()); | 392 base::TimeTicks()); |
398 buffer = NULL; | 393 buffer = NULL; |
399 } | 394 } |
400 // ReserveOutputBuffer ought to fail now, because the pool is depleted. | 395 // ReserveOutputBuffer ought to fail now, because the pool is depleted. |
401 ASSERT_FALSE(device_->ReserveOutputBuffer(media::VideoFrame::I420, | 396 ASSERT_FALSE(device_->ReserveOutputBuffer(media::VideoFrame::I420, |
402 capture_resolution).get()); | 397 capture_resolution).get()); |
403 | 398 |
404 // The new client needs to be told of 3 buffers; the old clients only 2. | 399 // The new client needs to be told of 3 buffers; the old clients only 2. |
405 EXPECT_CALL(*client_b_, DoBufferCreated(client_b_route_2)).Times(kPoolSize); | 400 EXPECT_CALL(*client_b_, DoBufferCreated(client_b_route_2)).Times(kPoolSize); |
(...skipping 17 matching lines...) Expand all Loading... |
423 // Kill B1 via session close (posts a task to disconnect). | 418 // Kill B1 via session close (posts a task to disconnect). |
424 EXPECT_CALL(*client_b_, DoEnded(client_b_route_1)).Times(1); | 419 EXPECT_CALL(*client_b_, DoEnded(client_b_route_1)).Times(1); |
425 controller_->StopSession(300); | 420 controller_->StopSession(300); |
426 // Queue up another buffer. | 421 // Queue up another buffer. |
427 buffer = | 422 buffer = |
428 device_->ReserveOutputBuffer(media::VideoFrame::I420, capture_resolution); | 423 device_->ReserveOutputBuffer(media::VideoFrame::I420, capture_resolution); |
429 ASSERT_TRUE(buffer.get()); | 424 ASSERT_TRUE(buffer.get()); |
430 memset(buffer->data(), buffer_no++, buffer->size()); | 425 memset(buffer->data(), buffer_no++, buffer->size()); |
431 device_->OnIncomingCapturedVideoFrame( | 426 device_->OnIncomingCapturedVideoFrame( |
432 buffer, | 427 buffer, |
433 media::VideoCaptureFormat(capture_resolution, | |
434 device_format.frame_rate, | |
435 media::PIXEL_FORMAT_I420), | |
436 WrapI420Buffer(buffer, capture_resolution), | 428 WrapI420Buffer(buffer, capture_resolution), |
437 base::TimeTicks()); | 429 base::TimeTicks()); |
438 buffer = NULL; | 430 buffer = NULL; |
439 buffer = | 431 buffer = |
440 device_->ReserveOutputBuffer(media::VideoFrame::I420, capture_resolution); | 432 device_->ReserveOutputBuffer(media::VideoFrame::I420, capture_resolution); |
441 { | 433 { |
442 // Kill A2 via session close (posts a task to disconnect, but A2 must not | 434 // Kill A2 via session close (posts a task to disconnect, but A2 must not |
443 // be sent either of these two buffers). | 435 // be sent either of these two buffers). |
444 EXPECT_CALL(*client_a_, DoEnded(client_a_route_2)).Times(1); | 436 EXPECT_CALL(*client_a_, DoEnded(client_a_route_2)).Times(1); |
445 controller_->StopSession(200); | 437 controller_->StopSession(200); |
446 } | 438 } |
447 ASSERT_TRUE(buffer.get()); | 439 ASSERT_TRUE(buffer.get()); |
448 memset(buffer->data(), buffer_no++, buffer->size()); | 440 memset(buffer->data(), buffer_no++, buffer->size()); |
449 device_->OnIncomingCapturedVideoFrame( | 441 device_->OnIncomingCapturedVideoFrame( |
450 buffer, | 442 buffer, |
451 media::VideoCaptureFormat(capture_resolution, | |
452 device_format.frame_rate, | |
453 media::PIXEL_FORMAT_I420), | |
454 WrapI420Buffer(buffer, capture_resolution), | 443 WrapI420Buffer(buffer, capture_resolution), |
455 base::TimeTicks()); | 444 base::TimeTicks()); |
456 buffer = NULL; | 445 buffer = NULL; |
457 // B2 is the only client left, and is the only one that should | 446 // B2 is the only client left, and is the only one that should |
458 // get the buffer. | 447 // get the buffer. |
459 EXPECT_CALL(*client_b_, DoBufferReady(client_b_route_2)).Times(2); | 448 EXPECT_CALL(*client_b_, DoBufferReady(client_b_route_2)).Times(2); |
460 base::RunLoop().RunUntilIdle(); | 449 base::RunLoop().RunUntilIdle(); |
461 Mock::VerifyAndClearExpectations(client_a_.get()); | 450 Mock::VerifyAndClearExpectations(client_a_.get()); |
462 Mock::VerifyAndClearExpectations(client_b_.get()); | 451 Mock::VerifyAndClearExpectations(client_b_.get()); |
463 | 452 |
(...skipping 10 matching lines...) Expand all Loading... |
474 shm_buffers--; | 463 shm_buffers--; |
475 mailbox_buffers++; | 464 mailbox_buffers++; |
476 } | 465 } |
477 | 466 |
478 for (int i = 0; i < shm_buffers; ++i) { | 467 for (int i = 0; i < shm_buffers; ++i) { |
479 buffer = device_->ReserveOutputBuffer(media::VideoFrame::I420, | 468 buffer = device_->ReserveOutputBuffer(media::VideoFrame::I420, |
480 capture_resolution); | 469 capture_resolution); |
481 ASSERT_TRUE(buffer.get()); | 470 ASSERT_TRUE(buffer.get()); |
482 device_->OnIncomingCapturedVideoFrame( | 471 device_->OnIncomingCapturedVideoFrame( |
483 buffer, | 472 buffer, |
484 media::VideoCaptureFormat(capture_resolution, | |
485 device_format.frame_rate, | |
486 media::PIXEL_FORMAT_I420), | |
487 WrapI420Buffer(buffer, capture_resolution), | 473 WrapI420Buffer(buffer, capture_resolution), |
488 base::TimeTicks()); | 474 base::TimeTicks()); |
489 buffer = NULL; | 475 buffer = NULL; |
490 } | 476 } |
491 std::vector<uint32> mailbox_syncpoints(mailbox_buffers); | 477 std::vector<uint32> mailbox_syncpoints(mailbox_buffers); |
492 std::vector<uint32> release_syncpoints(mailbox_buffers); | 478 std::vector<uint32> release_syncpoints(mailbox_buffers); |
493 for (int i = 0; i < mailbox_buffers; ++i) { | 479 for (int i = 0; i < mailbox_buffers; ++i) { |
494 buffer = device_->ReserveOutputBuffer(media::VideoFrame::NATIVE_TEXTURE, | 480 buffer = device_->ReserveOutputBuffer(media::VideoFrame::NATIVE_TEXTURE, |
495 gfx::Size(0, 0)); | 481 gfx::Size(0, 0)); |
496 ASSERT_TRUE(buffer.get()); | 482 ASSERT_TRUE(buffer.get()); |
497 #if !defined(OS_ANDROID) | 483 #if !defined(OS_ANDROID) |
498 mailbox_syncpoints[i] = gl_helper->InsertSyncPoint(); | 484 mailbox_syncpoints[i] = gl_helper->InsertSyncPoint(); |
499 #endif | 485 #endif |
500 device_->OnIncomingCapturedVideoFrame( | 486 device_->OnIncomingCapturedVideoFrame( |
501 buffer, | 487 buffer, |
502 media::VideoCaptureFormat(capture_resolution, | |
503 device_format.frame_rate, | |
504 media::PIXEL_FORMAT_TEXTURE), | |
505 WrapMailboxBuffer(make_scoped_ptr(new gpu::MailboxHolder( | 488 WrapMailboxBuffer(make_scoped_ptr(new gpu::MailboxHolder( |
506 gpu::Mailbox(), 0, mailbox_syncpoints[i])), | 489 gpu::Mailbox(), 0, mailbox_syncpoints[i])), |
507 base::Bind(&CacheSyncPoint, &release_syncpoints[i]), | 490 base::Bind(&CacheSyncPoint, &release_syncpoints[i]), |
508 capture_resolution), | 491 capture_resolution), |
509 base::TimeTicks()); | 492 base::TimeTicks()); |
510 buffer = NULL; | 493 buffer = NULL; |
511 } | 494 } |
512 // ReserveOutputBuffers ought to fail now regardless of buffer format, because | 495 // ReserveOutputBuffers ought to fail now regardless of buffer format, because |
513 // the pool is depleted. | 496 // the pool is depleted. |
514 ASSERT_FALSE(device_->ReserveOutputBuffer(media::VideoFrame::I420, | 497 ASSERT_FALSE(device_->ReserveOutputBuffer(media::VideoFrame::I420, |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
561 route_id, client_b_.get(), base::kNullProcessHandle, 200, session_200); | 544 route_id, client_b_.get(), base::kNullProcessHandle, 200, session_200); |
562 base::RunLoop().RunUntilIdle(); | 545 base::RunLoop().RunUntilIdle(); |
563 Mock::VerifyAndClearExpectations(client_b_.get()); | 546 Mock::VerifyAndClearExpectations(client_b_.get()); |
564 | 547 |
565 scoped_refptr<media::VideoCaptureDevice::Client::Buffer> buffer = | 548 scoped_refptr<media::VideoCaptureDevice::Client::Buffer> buffer = |
566 device_->ReserveOutputBuffer(media::VideoFrame::I420, capture_resolution); | 549 device_->ReserveOutputBuffer(media::VideoFrame::I420, capture_resolution); |
567 ASSERT_TRUE(buffer.get()); | 550 ASSERT_TRUE(buffer.get()); |
568 | 551 |
569 device_->OnIncomingCapturedVideoFrame( | 552 device_->OnIncomingCapturedVideoFrame( |
570 buffer, | 553 buffer, |
571 media::VideoCaptureFormat( | |
572 capture_resolution, 30, media::PIXEL_FORMAT_I420), | |
573 WrapI420Buffer(buffer, capture_resolution), | 554 WrapI420Buffer(buffer, capture_resolution), |
574 base::TimeTicks()); | 555 base::TimeTicks()); |
575 buffer = NULL; | 556 buffer = NULL; |
576 | 557 |
577 base::RunLoop().RunUntilIdle(); | 558 base::RunLoop().RunUntilIdle(); |
578 } | 559 } |
579 | 560 |
580 // Exercises the OnError() codepath of VideoCaptureController, and tests the | 561 // Exercises the OnError() codepath of VideoCaptureController, and tests the |
581 // behavior of various operations after the error state has been signalled. | 562 // behavior of various operations after the error state has been signalled. |
582 TEST_F(VideoCaptureControllerTest, ErrorAfterDeviceCreation) { | 563 TEST_F(VideoCaptureControllerTest, ErrorAfterDeviceCreation) { |
(...skipping 18 matching lines...) Expand all Loading... |
601 Mock::VerifyAndClearExpectations(client_a_.get()); | 582 Mock::VerifyAndClearExpectations(client_a_.get()); |
602 | 583 |
603 const gfx::Size dims(320, 240); | 584 const gfx::Size dims(320, 240); |
604 scoped_refptr<media::VideoCaptureDevice::Client::Buffer> buffer = | 585 scoped_refptr<media::VideoCaptureDevice::Client::Buffer> buffer = |
605 device_->ReserveOutputBuffer(media::VideoFrame::I420, dims); | 586 device_->ReserveOutputBuffer(media::VideoFrame::I420, dims); |
606 ASSERT_TRUE(buffer.get()); | 587 ASSERT_TRUE(buffer.get()); |
607 | 588 |
608 device_->OnError("Test error"); | 589 device_->OnError("Test error"); |
609 device_->OnIncomingCapturedVideoFrame( | 590 device_->OnIncomingCapturedVideoFrame( |
610 buffer, | 591 buffer, |
611 media::VideoCaptureFormat( | |
612 dims, device_format.frame_rate, media::PIXEL_FORMAT_I420), | |
613 WrapI420Buffer(buffer, dims), | 592 WrapI420Buffer(buffer, dims), |
614 base::TimeTicks()); | 593 base::TimeTicks()); |
615 buffer = NULL; | 594 buffer = NULL; |
616 | 595 |
617 EXPECT_CALL(*client_a_, DoError(route_id)).Times(1); | 596 EXPECT_CALL(*client_a_, DoError(route_id)).Times(1); |
618 base::RunLoop().RunUntilIdle(); | 597 base::RunLoop().RunUntilIdle(); |
619 Mock::VerifyAndClearExpectations(client_a_.get()); | 598 Mock::VerifyAndClearExpectations(client_a_.get()); |
620 | 599 |
621 // Second client connects after the error state. It also should get told of | 600 // Second client connects after the error state. It also should get told of |
622 // the error. | 601 // the error. |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
659 params.requested_format.ImageAllocationSize(), | 638 params.requested_format.ImageAllocationSize(), |
660 params.requested_format, | 639 params.requested_format, |
661 0 /* rotation */, | 640 0 /* rotation */, |
662 base::TimeTicks()); | 641 base::TimeTicks()); |
663 EXPECT_EQ(100, controller_->RemoveClient(route, client_a_.get())); | 642 EXPECT_EQ(100, controller_->RemoveClient(route, client_a_.get())); |
664 Mock::VerifyAndClearExpectations(client_a_.get()); | 643 Mock::VerifyAndClearExpectations(client_a_.get()); |
665 } | 644 } |
666 } | 645 } |
667 | 646 |
668 } // namespace content | 647 } // namespace content |
OLD | NEW |