| 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 "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 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 88 FROM_HERE, | 88 FROM_HERE, |
| 89 base::Bind(base::IgnoreResult(&VideoCaptureController::RemoveClient), | 89 base::Bind(base::IgnoreResult(&VideoCaptureController::RemoveClient), |
| 90 base::Unretained(controller_), id, this)); | 90 base::Unretained(controller_), id, this)); |
| 91 } | 91 } |
| 92 | 92 |
| 93 VideoCaptureController* controller_; | 93 VideoCaptureController* controller_; |
| 94 media::VideoPixelFormat expected_pixel_format_ = media::PIXEL_FORMAT_I420; | 94 media::VideoPixelFormat expected_pixel_format_ = media::PIXEL_FORMAT_I420; |
| 95 double resource_utilization_; | 95 double resource_utilization_; |
| 96 }; | 96 }; |
| 97 | 97 |
| 98 class MockFrameReceiverObserver : public media::FrameReceiverObserver { |
| 99 public: |
| 100 MOCK_METHOD2(OnReceiverReportingUtilization, void(int buffer_id, |
| 101 double utilization)); |
| 102 }; |
| 103 |
| 98 // Test class. | 104 // Test class. |
| 99 class VideoCaptureControllerTest | 105 class VideoCaptureControllerTest |
| 100 : public testing::Test, | 106 : public testing::Test, |
| 101 public testing::WithParamInterface<media::VideoPixelFormat> { | 107 public testing::WithParamInterface<media::VideoPixelFormat> { |
| 102 public: | 108 public: |
| 103 VideoCaptureControllerTest() {} | 109 VideoCaptureControllerTest() {} |
| 104 ~VideoCaptureControllerTest() override {} | 110 ~VideoCaptureControllerTest() override {} |
| 105 | 111 |
| 106 protected: | 112 protected: |
| 107 static const int kPoolSize = 3; | 113 static const int kPoolSize = 3; |
| 108 | 114 |
| 109 void SetUp() override { | 115 void SetUp() override { |
| 110 controller_.reset(new VideoCaptureController(kPoolSize)); | 116 controller_.reset(new VideoCaptureController(kPoolSize)); |
| 111 device_ = controller_->NewDeviceClient(); | 117 device_ = controller_->NewDeviceClient(); |
| 118 controller_->SetFrameReceiverObserver(&mock_frame_receiver_observer_); |
| 112 client_a_.reset(new MockVideoCaptureControllerEventHandler( | 119 client_a_.reset(new MockVideoCaptureControllerEventHandler( |
| 113 controller_.get())); | 120 controller_.get())); |
| 114 client_b_.reset(new MockVideoCaptureControllerEventHandler( | 121 client_b_.reset(new MockVideoCaptureControllerEventHandler( |
| 115 controller_.get())); | 122 controller_.get())); |
| 116 } | 123 } |
| 117 | 124 |
| 118 void TearDown() override { base::RunLoop().RunUntilIdle(); } | 125 void TearDown() override { base::RunLoop().RunUntilIdle(); } |
| 119 | 126 |
| 120 scoped_refptr<media::VideoFrame> WrapBuffer( | 127 scoped_refptr<media::VideoFrame> WrapBuffer( |
| 121 gfx::Size dimensions, | 128 gfx::Size dimensions, |
| 122 uint8_t* data, | 129 uint8_t* data, |
| 123 media::VideoPixelFormat format = media::PIXEL_FORMAT_I420) { | 130 media::VideoPixelFormat format = media::PIXEL_FORMAT_I420) { |
| 124 scoped_refptr<media::VideoFrame> video_frame = | 131 scoped_refptr<media::VideoFrame> video_frame = |
| 125 media::VideoFrame::WrapExternalSharedMemory( | 132 media::VideoFrame::WrapExternalSharedMemory( |
| 126 format, dimensions, gfx::Rect(dimensions), dimensions, data, | 133 format, dimensions, gfx::Rect(dimensions), dimensions, data, |
| 127 media::VideoFrame::AllocationSize(format, dimensions), | 134 media::VideoFrame::AllocationSize(format, dimensions), |
| 128 base::SharedMemory::NULLHandle(), 0u, base::TimeDelta()); | 135 base::SharedMemory::NULLHandle(), 0u, base::TimeDelta()); |
| 129 EXPECT_TRUE(video_frame); | 136 EXPECT_TRUE(video_frame); |
| 130 return video_frame; | 137 return video_frame; |
| 131 } | 138 } |
| 132 | 139 |
| 133 TestBrowserThreadBundle bundle_; | 140 TestBrowserThreadBundle bundle_; |
| 134 std::unique_ptr<MockVideoCaptureControllerEventHandler> client_a_; | 141 std::unique_ptr<MockVideoCaptureControllerEventHandler> client_a_; |
| 135 std::unique_ptr<MockVideoCaptureControllerEventHandler> client_b_; | 142 std::unique_ptr<MockVideoCaptureControllerEventHandler> client_b_; |
| 136 std::unique_ptr<VideoCaptureController> controller_; | 143 std::unique_ptr<VideoCaptureController> controller_; |
| 137 std::unique_ptr<media::VideoCaptureDevice::Client> device_; | 144 std::unique_ptr<media::VideoCaptureDevice::Client> device_; |
| 145 MockFrameReceiverObserver mock_frame_receiver_observer_; |
| 146 const int arbitrary_frame_id_ = 0; |
| 138 | 147 |
| 139 private: | 148 private: |
| 140 DISALLOW_COPY_AND_ASSIGN(VideoCaptureControllerTest); | 149 DISALLOW_COPY_AND_ASSIGN(VideoCaptureControllerTest); |
| 141 }; | 150 }; |
| 142 | 151 |
| 143 // A simple test of VideoCaptureController's ability to add, remove, and keep | 152 // A simple test of VideoCaptureController's ability to add, remove, and keep |
| 144 // track of clients. | 153 // track of clients. |
| 145 TEST_F(VideoCaptureControllerTest, AddAndRemoveClients) { | 154 TEST_F(VideoCaptureControllerTest, AddAndRemoveClients) { |
| 146 media::VideoCaptureParams session_100; | 155 media::VideoCaptureParams session_100; |
| 147 session_100.requested_format = media::VideoCaptureFormat( | 156 session_100.requested_format = media::VideoCaptureFormat( |
| (...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 309 EXPECT_CALL(*client_a_, DoBufferReady(client_a_route_2, capture_resolution)) | 318 EXPECT_CALL(*client_a_, DoBufferReady(client_a_route_2, capture_resolution)) |
| 310 .Times(1); | 319 .Times(1); |
| 311 } | 320 } |
| 312 scoped_refptr<media::VideoFrame> video_frame = WrapBuffer( | 321 scoped_refptr<media::VideoFrame> video_frame = WrapBuffer( |
| 313 capture_resolution, static_cast<uint8_t*>(buffer->data()), format); | 322 capture_resolution, static_cast<uint8_t*>(buffer->data()), format); |
| 314 ASSERT_TRUE(video_frame); | 323 ASSERT_TRUE(video_frame); |
| 315 ASSERT_FALSE(video_frame->metadata()->HasKey( | 324 ASSERT_FALSE(video_frame->metadata()->HasKey( |
| 316 media::VideoFrameMetadata::RESOURCE_UTILIZATION)); | 325 media::VideoFrameMetadata::RESOURCE_UTILIZATION)); |
| 317 client_a_->resource_utilization_ = 0.5; | 326 client_a_->resource_utilization_ = 0.5; |
| 318 client_b_->resource_utilization_ = -1.0; | 327 client_b_->resource_utilization_ = -1.0; |
| 328 |
| 329 // Expect VideoCaptureController to call the load observer with a |
| 330 // resource utilization of 0.5 (the largest of all reported values). |
| 331 EXPECT_CALL(mock_frame_receiver_observer_, |
| 332 OnReceiverReportingUtilization(buffer->id(), 0.5)); |
| 333 |
| 319 video_frame->metadata()->SetTimeTicks( | 334 video_frame->metadata()->SetTimeTicks( |
| 320 media::VideoFrameMetadata::REFERENCE_TIME, base::TimeTicks()); | 335 media::VideoFrameMetadata::REFERENCE_TIME, base::TimeTicks()); |
| 321 device_->OnIncomingCapturedVideoFrame(std::move(buffer), video_frame); | 336 device_->OnIncomingCapturedVideoFrame(std::move(buffer), video_frame, |
| 337 arbitrary_frame_id_); |
| 322 | 338 |
| 323 base::RunLoop().RunUntilIdle(); | 339 base::RunLoop().RunUntilIdle(); |
| 324 Mock::VerifyAndClearExpectations(client_a_.get()); | 340 Mock::VerifyAndClearExpectations(client_a_.get()); |
| 325 Mock::VerifyAndClearExpectations(client_b_.get()); | 341 Mock::VerifyAndClearExpectations(client_b_.get()); |
| 326 | 342 Mock::VerifyAndClearExpectations(&mock_frame_receiver_observer_); |
| 327 // Expect VideoCaptureController set the metadata in |video_frame| to hold a | |
| 328 // resource utilization of 0.5 (the largest of all reported values). | |
| 329 double resource_utilization_in_metadata = -1.0; | |
| 330 ASSERT_TRUE(video_frame->metadata()->GetDouble( | |
| 331 media::VideoFrameMetadata::RESOURCE_UTILIZATION, | |
| 332 &resource_utilization_in_metadata)); | |
| 333 ASSERT_EQ(0.5, resource_utilization_in_metadata); | |
| 334 | 343 |
| 335 // Second buffer which ought to use the same shared memory buffer. In this | 344 // Second buffer which ought to use the same shared memory buffer. In this |
| 336 // case pretend that the Buffer pointer is held by the device for a long | 345 // case pretend that the Buffer pointer is held by the device for a long |
| 337 // delay. This shouldn't affect anything. | 346 // delay. This shouldn't affect anything. |
| 338 std::unique_ptr<media::VideoCaptureDevice::Client::Buffer> buffer2 = | 347 std::unique_ptr<media::VideoCaptureDevice::Client::Buffer> buffer2 = |
| 339 device_->ReserveOutputBuffer(capture_resolution, format, | 348 device_->ReserveOutputBuffer(capture_resolution, format, |
| 340 media::PIXEL_STORAGE_CPU); | 349 media::PIXEL_STORAGE_CPU); |
| 341 ASSERT_TRUE(buffer2.get()); | 350 ASSERT_TRUE(buffer2.get()); |
| 342 memset(buffer2->data(), buffer_no++, buffer2->mapped_size()); | 351 memset(buffer2->data(), buffer_no++, buffer2->mapped_size()); |
| 343 video_frame = WrapBuffer(capture_resolution, | 352 video_frame = WrapBuffer(capture_resolution, |
| 344 static_cast<uint8_t*>(buffer2->data()), format); | 353 static_cast<uint8_t*>(buffer2->data()), format); |
| 345 ASSERT_TRUE(video_frame); | |
| 346 ASSERT_FALSE(video_frame->metadata()->HasKey( | |
| 347 media::VideoFrameMetadata::RESOURCE_UTILIZATION)); | |
| 348 client_a_->resource_utilization_ = 0.5; | 354 client_a_->resource_utilization_ = 0.5; |
| 349 client_b_->resource_utilization_ = 3.14; | 355 client_b_->resource_utilization_ = 3.14; |
| 350 video_frame->metadata()->SetTimeTicks( | 356 video_frame->metadata()->SetTimeTicks( |
| 351 media::VideoFrameMetadata::REFERENCE_TIME, base::TimeTicks()); | 357 media::VideoFrameMetadata::REFERENCE_TIME, base::TimeTicks()); |
| 352 device_->OnIncomingCapturedVideoFrame(std::move(buffer2), video_frame); | 358 // Expect VideoCaptureController to call the load observer with a |
| 359 // resource utilization of 3.14 (the largest of all reported values). |
| 360 EXPECT_CALL(mock_frame_receiver_observer_, |
| 361 OnReceiverReportingUtilization(buffer2->id(), 3.14)); |
| 362 |
| 363 device_->OnIncomingCapturedVideoFrame(std::move(buffer2), video_frame, |
| 364 arbitrary_frame_id_); |
| 353 | 365 |
| 354 // The buffer should be delivered to the clients in any order. | 366 // The buffer should be delivered to the clients in any order. |
| 355 { | 367 { |
| 356 InSequence s; | 368 InSequence s; |
| 357 EXPECT_CALL(*client_a_, DoBufferCreated(client_a_route_1)).Times(1); | 369 EXPECT_CALL(*client_a_, DoBufferCreated(client_a_route_1)).Times(1); |
| 358 EXPECT_CALL(*client_a_, DoBufferReady(client_a_route_1, capture_resolution)) | 370 EXPECT_CALL(*client_a_, DoBufferReady(client_a_route_1, capture_resolution)) |
| 359 .Times(1); | 371 .Times(1); |
| 360 } | 372 } |
| 361 { | 373 { |
| 362 InSequence s; | 374 InSequence s; |
| 363 EXPECT_CALL(*client_b_, DoBufferCreated(client_b_route_1)).Times(1); | 375 EXPECT_CALL(*client_b_, DoBufferCreated(client_b_route_1)).Times(1); |
| 364 EXPECT_CALL(*client_b_, DoBufferReady(client_b_route_1, capture_resolution)) | 376 EXPECT_CALL(*client_b_, DoBufferReady(client_b_route_1, capture_resolution)) |
| 365 .Times(1); | 377 .Times(1); |
| 366 } | 378 } |
| 367 { | 379 { |
| 368 InSequence s; | 380 InSequence s; |
| 369 EXPECT_CALL(*client_a_, DoBufferCreated(client_a_route_2)).Times(1); | 381 EXPECT_CALL(*client_a_, DoBufferCreated(client_a_route_2)).Times(1); |
| 370 EXPECT_CALL(*client_a_, DoBufferReady(client_a_route_2, capture_resolution)) | 382 EXPECT_CALL(*client_a_, DoBufferReady(client_a_route_2, capture_resolution)) |
| 371 .Times(1); | 383 .Times(1); |
| 372 } | 384 } |
| 373 base::RunLoop().RunUntilIdle(); | 385 base::RunLoop().RunUntilIdle(); |
| 374 Mock::VerifyAndClearExpectations(client_a_.get()); | 386 Mock::VerifyAndClearExpectations(client_a_.get()); |
| 375 Mock::VerifyAndClearExpectations(client_b_.get()); | 387 Mock::VerifyAndClearExpectations(client_b_.get()); |
| 376 // Expect VideoCaptureController set the metadata in |video_frame| to hold a | 388 Mock::VerifyAndClearExpectations(&mock_frame_receiver_observer_); |
| 377 // resource utilization of 3.14 (the largest of all reported values). | |
| 378 resource_utilization_in_metadata = -1.0; | |
| 379 ASSERT_TRUE(video_frame->metadata()->GetDouble( | |
| 380 media::VideoFrameMetadata::RESOURCE_UTILIZATION, | |
| 381 &resource_utilization_in_metadata)); | |
| 382 ASSERT_EQ(3.14, resource_utilization_in_metadata); | |
| 383 | 389 |
| 384 // Add a fourth client now that some buffers have come through. | 390 // Add a fourth client now that some buffers have come through. |
| 385 controller_->AddClient(client_b_route_2, | 391 controller_->AddClient(client_b_route_2, |
| 386 client_b_.get(), | 392 client_b_.get(), |
| 387 1, | 393 1, |
| 388 session_1); | 394 session_1); |
| 389 Mock::VerifyAndClearExpectations(client_b_.get()); | 395 Mock::VerifyAndClearExpectations(client_b_.get()); |
| 390 | 396 |
| 391 // Third, fourth, and fifth buffers. Pretend they all arrive at the same time. | 397 // Third, fourth, and fifth buffers. Pretend they all arrive at the same time. |
| 392 for (int i = 0; i < kPoolSize; i++) { | 398 for (int i = 0; i < kPoolSize; i++) { |
| 393 std::unique_ptr<media::VideoCaptureDevice::Client::Buffer> buffer = | 399 std::unique_ptr<media::VideoCaptureDevice::Client::Buffer> buffer = |
| 394 device_->ReserveOutputBuffer(capture_resolution, format, | 400 device_->ReserveOutputBuffer(capture_resolution, format, |
| 395 media::PIXEL_STORAGE_CPU); | 401 media::PIXEL_STORAGE_CPU); |
| 396 ASSERT_TRUE(buffer.get()); | 402 ASSERT_TRUE(buffer.get()); |
| 397 memset(buffer->data(), buffer_no++, buffer->mapped_size()); | 403 memset(buffer->data(), buffer_no++, buffer->mapped_size()); |
| 398 video_frame = WrapBuffer(capture_resolution, | 404 video_frame = WrapBuffer(capture_resolution, |
| 399 static_cast<uint8_t*>(buffer->data()), format); | 405 static_cast<uint8_t*>(buffer->data()), format); |
| 400 ASSERT_TRUE(video_frame); | 406 ASSERT_TRUE(video_frame); |
| 401 video_frame->metadata()->SetTimeTicks( | 407 video_frame->metadata()->SetTimeTicks( |
| 402 media::VideoFrameMetadata::REFERENCE_TIME, base::TimeTicks()); | 408 media::VideoFrameMetadata::REFERENCE_TIME, base::TimeTicks()); |
| 403 device_->OnIncomingCapturedVideoFrame(std::move(buffer), video_frame); | 409 device_->OnIncomingCapturedVideoFrame(std::move(buffer), video_frame, |
| 410 arbitrary_frame_id_); |
| 404 } | 411 } |
| 405 // ReserveOutputBuffer ought to fail now, because the pool is depleted. | 412 // ReserveOutputBuffer ought to fail now, because the pool is depleted. |
| 406 ASSERT_FALSE(device_ | 413 ASSERT_FALSE(device_ |
| 407 ->ReserveOutputBuffer(capture_resolution, format, | 414 ->ReserveOutputBuffer(capture_resolution, format, |
| 408 media::PIXEL_STORAGE_CPU) | 415 media::PIXEL_STORAGE_CPU) |
| 409 .get()); | 416 .get()); |
| 410 | 417 |
| 411 // The new client needs to be notified of the creation of |kPoolSize| buffers; | 418 // The new client needs to be notified of the creation of |kPoolSize| buffers; |
| 412 // the old clients only |kPoolSize - 2|. | 419 // the old clients only |kPoolSize - 2|. |
| 413 EXPECT_CALL(*client_b_, DoBufferCreated(client_b_route_2)).Times(kPoolSize); | 420 EXPECT_CALL(*client_b_, DoBufferCreated(client_b_route_2)).Times(kPoolSize); |
| (...skipping 25 matching lines...) Expand all Loading... |
| 439 std::unique_ptr<media::VideoCaptureDevice::Client::Buffer> buffer3 = | 446 std::unique_ptr<media::VideoCaptureDevice::Client::Buffer> buffer3 = |
| 440 device_->ReserveOutputBuffer(capture_resolution, format, | 447 device_->ReserveOutputBuffer(capture_resolution, format, |
| 441 media::PIXEL_STORAGE_CPU); | 448 media::PIXEL_STORAGE_CPU); |
| 442 ASSERT_TRUE(buffer3.get()); | 449 ASSERT_TRUE(buffer3.get()); |
| 443 memset(buffer3->data(), buffer_no++, buffer3->mapped_size()); | 450 memset(buffer3->data(), buffer_no++, buffer3->mapped_size()); |
| 444 video_frame = WrapBuffer(capture_resolution, | 451 video_frame = WrapBuffer(capture_resolution, |
| 445 static_cast<uint8_t*>(buffer3->data()), format); | 452 static_cast<uint8_t*>(buffer3->data()), format); |
| 446 ASSERT_TRUE(video_frame); | 453 ASSERT_TRUE(video_frame); |
| 447 video_frame->metadata()->SetTimeTicks( | 454 video_frame->metadata()->SetTimeTicks( |
| 448 media::VideoFrameMetadata::REFERENCE_TIME, base::TimeTicks()); | 455 media::VideoFrameMetadata::REFERENCE_TIME, base::TimeTicks()); |
| 449 device_->OnIncomingCapturedVideoFrame(std::move(buffer3), video_frame); | 456 device_->OnIncomingCapturedVideoFrame(std::move(buffer3), video_frame, |
| 457 arbitrary_frame_id_); |
| 450 | 458 |
| 451 std::unique_ptr<media::VideoCaptureDevice::Client::Buffer> buffer4 = | 459 std::unique_ptr<media::VideoCaptureDevice::Client::Buffer> buffer4 = |
| 452 device_->ReserveOutputBuffer(capture_resolution, format, | 460 device_->ReserveOutputBuffer(capture_resolution, format, |
| 453 media::PIXEL_STORAGE_CPU); | 461 media::PIXEL_STORAGE_CPU); |
| 454 { | 462 { |
| 455 // Kill A2 via session close (posts a task to disconnect, but A2 must not | 463 // Kill A2 via session close (posts a task to disconnect, but A2 must not |
| 456 // be sent either of these two buffers). | 464 // be sent either of these two buffers). |
| 457 EXPECT_CALL(*client_a_, DoEnded(client_a_route_2)).Times(1); | 465 EXPECT_CALL(*client_a_, DoEnded(client_a_route_2)).Times(1); |
| 458 controller_->StopSession(200); | 466 controller_->StopSession(200); |
| 459 } | 467 } |
| 460 ASSERT_TRUE(buffer4.get()); | 468 ASSERT_TRUE(buffer4.get()); |
| 461 memset(buffer4->data(), buffer_no++, buffer4->mapped_size()); | 469 memset(buffer4->data(), buffer_no++, buffer4->mapped_size()); |
| 462 video_frame = WrapBuffer(capture_resolution, | 470 video_frame = WrapBuffer(capture_resolution, |
| 463 static_cast<uint8_t*>(buffer4->data()), format); | 471 static_cast<uint8_t*>(buffer4->data()), format); |
| 464 ASSERT_TRUE(video_frame); | 472 ASSERT_TRUE(video_frame); |
| 465 video_frame->metadata()->SetTimeTicks( | 473 video_frame->metadata()->SetTimeTicks( |
| 466 media::VideoFrameMetadata::REFERENCE_TIME, base::TimeTicks()); | 474 media::VideoFrameMetadata::REFERENCE_TIME, base::TimeTicks()); |
| 467 device_->OnIncomingCapturedVideoFrame(std::move(buffer4), video_frame); | 475 device_->OnIncomingCapturedVideoFrame(std::move(buffer4), video_frame, |
| 476 arbitrary_frame_id_); |
| 468 // B2 is the only client left, and is the only one that should | 477 // B2 is the only client left, and is the only one that should |
| 469 // get the buffer. | 478 // get the buffer. |
| 470 EXPECT_CALL(*client_b_, DoBufferReady(client_b_route_2, capture_resolution)) | 479 EXPECT_CALL(*client_b_, DoBufferReady(client_b_route_2, capture_resolution)) |
| 471 .Times(2); | 480 .Times(2); |
| 472 base::RunLoop().RunUntilIdle(); | 481 base::RunLoop().RunUntilIdle(); |
| 473 Mock::VerifyAndClearExpectations(client_a_.get()); | 482 Mock::VerifyAndClearExpectations(client_a_.get()); |
| 474 Mock::VerifyAndClearExpectations(client_b_.get()); | 483 Mock::VerifyAndClearExpectations(client_b_.get()); |
| 475 } | 484 } |
| 476 | 485 |
| 477 INSTANTIATE_TEST_CASE_P(, | 486 INSTANTIATE_TEST_CASE_P(, |
| (...skipping 30 matching lines...) Expand all Loading... |
| 508 | 517 |
| 509 std::unique_ptr<media::VideoCaptureDevice::Client::Buffer> buffer( | 518 std::unique_ptr<media::VideoCaptureDevice::Client::Buffer> buffer( |
| 510 device_->ReserveOutputBuffer(capture_resolution, media::PIXEL_FORMAT_I420, | 519 device_->ReserveOutputBuffer(capture_resolution, media::PIXEL_FORMAT_I420, |
| 511 media::PIXEL_STORAGE_CPU)); | 520 media::PIXEL_STORAGE_CPU)); |
| 512 ASSERT_TRUE(buffer.get()); | 521 ASSERT_TRUE(buffer.get()); |
| 513 scoped_refptr<media::VideoFrame> video_frame = | 522 scoped_refptr<media::VideoFrame> video_frame = |
| 514 WrapBuffer(capture_resolution, static_cast<uint8_t*>(buffer->data())); | 523 WrapBuffer(capture_resolution, static_cast<uint8_t*>(buffer->data())); |
| 515 ASSERT_TRUE(video_frame); | 524 ASSERT_TRUE(video_frame); |
| 516 video_frame->metadata()->SetTimeTicks( | 525 video_frame->metadata()->SetTimeTicks( |
| 517 media::VideoFrameMetadata::REFERENCE_TIME, base::TimeTicks()); | 526 media::VideoFrameMetadata::REFERENCE_TIME, base::TimeTicks()); |
| 518 device_->OnIncomingCapturedVideoFrame(std::move(buffer), video_frame); | 527 device_->OnIncomingCapturedVideoFrame(std::move(buffer), video_frame, |
| 528 arbitrary_frame_id_); |
| 519 | 529 |
| 520 base::RunLoop().RunUntilIdle(); | 530 base::RunLoop().RunUntilIdle(); |
| 521 } | 531 } |
| 522 | 532 |
| 523 // Exercises the OnError() codepath of VideoCaptureController, and tests the | 533 // Exercises the OnError() codepath of VideoCaptureController, and tests the |
| 524 // behavior of various operations after the error state has been signalled. | 534 // behavior of various operations after the error state has been signalled. |
| 525 TEST_F(VideoCaptureControllerTest, ErrorAfterDeviceCreation) { | 535 TEST_F(VideoCaptureControllerTest, ErrorAfterDeviceCreation) { |
| 526 media::VideoCaptureParams session_100; | 536 media::VideoCaptureParams session_100; |
| 527 session_100.requested_format = media::VideoCaptureFormat( | 537 session_100.requested_format = media::VideoCaptureFormat( |
| 528 gfx::Size(320, 240), 30, media::PIXEL_FORMAT_I420); | 538 gfx::Size(320, 240), 30, media::PIXEL_FORMAT_I420); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 547 device_->ReserveOutputBuffer(dims, media::PIXEL_FORMAT_I420, | 557 device_->ReserveOutputBuffer(dims, media::PIXEL_FORMAT_I420, |
| 548 media::PIXEL_STORAGE_CPU)); | 558 media::PIXEL_STORAGE_CPU)); |
| 549 ASSERT_TRUE(buffer.get()); | 559 ASSERT_TRUE(buffer.get()); |
| 550 | 560 |
| 551 scoped_refptr<media::VideoFrame> video_frame = | 561 scoped_refptr<media::VideoFrame> video_frame = |
| 552 WrapBuffer(dims, static_cast<uint8_t*>(buffer->data())); | 562 WrapBuffer(dims, static_cast<uint8_t*>(buffer->data())); |
| 553 ASSERT_TRUE(video_frame); | 563 ASSERT_TRUE(video_frame); |
| 554 device_->OnError(FROM_HERE, "Test Error"); | 564 device_->OnError(FROM_HERE, "Test Error"); |
| 555 video_frame->metadata()->SetTimeTicks( | 565 video_frame->metadata()->SetTimeTicks( |
| 556 media::VideoFrameMetadata::REFERENCE_TIME, base::TimeTicks()); | 566 media::VideoFrameMetadata::REFERENCE_TIME, base::TimeTicks()); |
| 557 device_->OnIncomingCapturedVideoFrame(std::move(buffer), video_frame); | 567 device_->OnIncomingCapturedVideoFrame(std::move(buffer), video_frame, |
| 568 arbitrary_frame_id_); |
| 558 | 569 |
| 559 EXPECT_CALL(*client_a_, DoError(route_id)).Times(1); | 570 EXPECT_CALL(*client_a_, DoError(route_id)).Times(1); |
| 560 base::RunLoop().RunUntilIdle(); | 571 base::RunLoop().RunUntilIdle(); |
| 561 Mock::VerifyAndClearExpectations(client_a_.get()); | 572 Mock::VerifyAndClearExpectations(client_a_.get()); |
| 562 | 573 |
| 563 // Second client connects after the error state. It also should get told of | 574 // Second client connects after the error state. It also should get told of |
| 564 // the error. | 575 // the error. |
| 565 EXPECT_CALL(*client_b_, DoError(route_id)).Times(1); | 576 EXPECT_CALL(*client_b_, DoError(route_id)).Times(1); |
| 566 controller_->AddClient(route_id, client_b_.get(), 200, session_200); | 577 controller_->AddClient(route_id, client_b_.get(), 200, session_200); |
| 567 Mock::VerifyAndClearExpectations(client_b_.get()); | 578 Mock::VerifyAndClearExpectations(client_b_.get()); |
| 568 } | 579 } |
| 569 | 580 |
| 570 } // namespace content | 581 } // namespace content |
| OLD | NEW |