| 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 15 matching lines...) Expand all Loading... |
| 26 #include "content/browser/renderer_host/media/video_capture_manager.h" | 26 #include "content/browser/renderer_host/media/video_capture_manager.h" |
| 27 #include "content/common/media/media_stream_options.h" | 27 #include "content/common/media/media_stream_options.h" |
| 28 #include "content/public/test/test_browser_thread_bundle.h" | 28 #include "content/public/test/test_browser_thread_bundle.h" |
| 29 #include "media/base/video_frame_metadata.h" | 29 #include "media/base/video_frame_metadata.h" |
| 30 #include "media/base/video_util.h" | 30 #include "media/base/video_util.h" |
| 31 #include "media/capture/video_capture_types.h" | 31 #include "media/capture/video_capture_types.h" |
| 32 #include "testing/gmock/include/gmock/gmock.h" | 32 #include "testing/gmock/include/gmock/gmock.h" |
| 33 #include "testing/gtest/include/gtest/gtest.h" | 33 #include "testing/gtest/include/gtest/gtest.h" |
| 34 | 34 |
| 35 using ::testing::_; | 35 using ::testing::_; |
| 36 using ::testing::AnyNumber; |
| 36 using ::testing::InSequence; | 37 using ::testing::InSequence; |
| 37 using ::testing::Mock; | 38 using ::testing::Mock; |
| 38 using ::testing::SaveArg; | 39 using ::testing::SaveArg; |
| 39 | 40 |
| 40 namespace content { | 41 namespace content { |
| 41 | 42 |
| 42 class MockVideoCaptureControllerEventHandler | 43 class MockVideoCaptureControllerEventHandler |
| 43 : public VideoCaptureControllerEventHandler { | 44 : public VideoCaptureControllerEventHandler { |
| 44 public: | 45 public: |
| 45 explicit MockVideoCaptureControllerEventHandler( | 46 explicit MockVideoCaptureControllerEventHandler( |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 88 FROM_HERE, | 89 FROM_HERE, |
| 89 base::Bind(base::IgnoreResult(&VideoCaptureController::RemoveClient), | 90 base::Bind(base::IgnoreResult(&VideoCaptureController::RemoveClient), |
| 90 base::Unretained(controller_), id, this)); | 91 base::Unretained(controller_), id, this)); |
| 91 } | 92 } |
| 92 | 93 |
| 93 VideoCaptureController* controller_; | 94 VideoCaptureController* controller_; |
| 94 media::VideoPixelFormat expected_pixel_format_ = media::PIXEL_FORMAT_I420; | 95 media::VideoPixelFormat expected_pixel_format_ = media::PIXEL_FORMAT_I420; |
| 95 double resource_utilization_; | 96 double resource_utilization_; |
| 96 }; | 97 }; |
| 97 | 98 |
| 99 class MockConsumerFeedbackObserver |
| 100 : public media::VideoFrameConsumerFeedbackObserver { |
| 101 public: |
| 102 MOCK_METHOD2(OnUtilizationReport, |
| 103 void(int frame_feedback_id, double utilization)); |
| 104 }; |
| 105 |
| 98 // Test class. | 106 // Test class. |
| 99 class VideoCaptureControllerTest | 107 class VideoCaptureControllerTest |
| 100 : public testing::Test, | 108 : public testing::Test, |
| 101 public testing::WithParamInterface<media::VideoPixelFormat> { | 109 public testing::WithParamInterface<media::VideoPixelFormat> { |
| 102 public: | 110 public: |
| 103 VideoCaptureControllerTest() {} | 111 VideoCaptureControllerTest() {} |
| 104 ~VideoCaptureControllerTest() override {} | 112 ~VideoCaptureControllerTest() override {} |
| 105 | 113 |
| 106 protected: | 114 protected: |
| 107 static const int kPoolSize = 3; | 115 static const int kPoolSize = 3; |
| 108 | 116 |
| 109 void SetUp() override { | 117 void SetUp() override { |
| 110 controller_.reset(new VideoCaptureController(kPoolSize)); | 118 controller_.reset(new VideoCaptureController(kPoolSize)); |
| 111 device_ = controller_->NewDeviceClient(); | 119 device_ = controller_->NewDeviceClient(); |
| 120 auto consumer_feedback_observer = |
| 121 base::MakeUnique<MockConsumerFeedbackObserver>(); |
| 122 mock_consumer_feedback_observer_ = consumer_feedback_observer.get(); |
| 123 controller_->SetConsumerFeedbackObserver( |
| 124 std::move(consumer_feedback_observer)); |
| 112 client_a_.reset(new MockVideoCaptureControllerEventHandler( | 125 client_a_.reset(new MockVideoCaptureControllerEventHandler( |
| 113 controller_.get())); | 126 controller_.get())); |
| 114 client_b_.reset(new MockVideoCaptureControllerEventHandler( | 127 client_b_.reset(new MockVideoCaptureControllerEventHandler( |
| 115 controller_.get())); | 128 controller_.get())); |
| 116 } | 129 } |
| 117 | 130 |
| 118 void TearDown() override { base::RunLoop().RunUntilIdle(); } | 131 void TearDown() override { base::RunLoop().RunUntilIdle(); } |
| 119 | 132 |
| 120 scoped_refptr<media::VideoFrame> WrapBuffer( | 133 scoped_refptr<media::VideoFrame> WrapBuffer( |
| 121 gfx::Size dimensions, | 134 gfx::Size dimensions, |
| 122 uint8_t* data, | 135 uint8_t* data, |
| 123 media::VideoPixelFormat format = media::PIXEL_FORMAT_I420) { | 136 media::VideoPixelFormat format = media::PIXEL_FORMAT_I420) { |
| 124 scoped_refptr<media::VideoFrame> video_frame = | 137 scoped_refptr<media::VideoFrame> video_frame = |
| 125 media::VideoFrame::WrapExternalSharedMemory( | 138 media::VideoFrame::WrapExternalSharedMemory( |
| 126 format, dimensions, gfx::Rect(dimensions), dimensions, data, | 139 format, dimensions, gfx::Rect(dimensions), dimensions, data, |
| 127 media::VideoFrame::AllocationSize(format, dimensions), | 140 media::VideoFrame::AllocationSize(format, dimensions), |
| 128 base::SharedMemory::NULLHandle(), 0u, base::TimeDelta()); | 141 base::SharedMemory::NULLHandle(), 0u, base::TimeDelta()); |
| 129 EXPECT_TRUE(video_frame); | 142 EXPECT_TRUE(video_frame); |
| 130 return video_frame; | 143 return video_frame; |
| 131 } | 144 } |
| 132 | 145 |
| 133 TestBrowserThreadBundle bundle_; | 146 TestBrowserThreadBundle bundle_; |
| 134 std::unique_ptr<MockVideoCaptureControllerEventHandler> client_a_; | 147 std::unique_ptr<MockVideoCaptureControllerEventHandler> client_a_; |
| 135 std::unique_ptr<MockVideoCaptureControllerEventHandler> client_b_; | 148 std::unique_ptr<MockVideoCaptureControllerEventHandler> client_b_; |
| 136 std::unique_ptr<VideoCaptureController> controller_; | 149 std::unique_ptr<VideoCaptureController> controller_; |
| 137 std::unique_ptr<media::VideoCaptureDevice::Client> device_; | 150 std::unique_ptr<media::VideoCaptureDevice::Client> device_; |
| 151 MockConsumerFeedbackObserver* mock_consumer_feedback_observer_; |
| 138 | 152 |
| 139 private: | 153 private: |
| 140 DISALLOW_COPY_AND_ASSIGN(VideoCaptureControllerTest); | 154 DISALLOW_COPY_AND_ASSIGN(VideoCaptureControllerTest); |
| 141 }; | 155 }; |
| 142 | 156 |
| 143 // A simple test of VideoCaptureController's ability to add, remove, and keep | 157 // A simple test of VideoCaptureController's ability to add, remove, and keep |
| 144 // track of clients. | 158 // track of clients. |
| 145 TEST_F(VideoCaptureControllerTest, AddAndRemoveClients) { | 159 TEST_F(VideoCaptureControllerTest, AddAndRemoveClients) { |
| 146 media::VideoCaptureParams session_100; | 160 media::VideoCaptureParams session_100; |
| 147 session_100.requested_format = media::VideoCaptureFormat( | 161 session_100.requested_format = media::VideoCaptureFormat( |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 277 session_300); | 291 session_300); |
| 278 controller_->AddClient(client_a_route_2, | 292 controller_->AddClient(client_a_route_2, |
| 279 client_a_.get(), | 293 client_a_.get(), |
| 280 200, | 294 200, |
| 281 session_200); | 295 session_200); |
| 282 ASSERT_EQ(3, controller_->GetClientCount()); | 296 ASSERT_EQ(3, controller_->GetClientCount()); |
| 283 | 297 |
| 284 // Now, simulate an incoming captured buffer from the capture device. As a | 298 // Now, simulate an incoming captured buffer from the capture device. As a |
| 285 // side effect this will cause the first buffer to be shared with clients. | 299 // side effect this will cause the first buffer to be shared with clients. |
| 286 uint8_t buffer_no = 1; | 300 uint8_t buffer_no = 1; |
| 301 const int arbitrary_frame_feedback_id = 101; |
| 287 ASSERT_EQ(0.0, device_->GetBufferPoolUtilization()); | 302 ASSERT_EQ(0.0, device_->GetBufferPoolUtilization()); |
| 288 std::unique_ptr<media::VideoCaptureDevice::Client::Buffer> buffer( | 303 std::unique_ptr<media::VideoCaptureDevice::Client::Buffer> buffer( |
| 289 device_->ReserveOutputBuffer(capture_resolution, format, | 304 device_->ReserveOutputBuffer(capture_resolution, format, |
| 290 media::PIXEL_STORAGE_CPU)); | 305 media::PIXEL_STORAGE_CPU, |
| 306 arbitrary_frame_feedback_id)); |
| 291 ASSERT_TRUE(buffer.get()); | 307 ASSERT_TRUE(buffer.get()); |
| 292 ASSERT_EQ(1.0 / kPoolSize, device_->GetBufferPoolUtilization()); | 308 ASSERT_EQ(1.0 / kPoolSize, device_->GetBufferPoolUtilization()); |
| 293 memset(buffer->data(), buffer_no++, buffer->mapped_size()); | 309 memset(buffer->data(), buffer_no++, buffer->mapped_size()); |
| 294 { | 310 { |
| 295 InSequence s; | 311 InSequence s; |
| 296 EXPECT_CALL(*client_a_, DoBufferCreated(client_a_route_1)).Times(1); | 312 EXPECT_CALL(*client_a_, DoBufferCreated(client_a_route_1)).Times(1); |
| 297 EXPECT_CALL(*client_a_, DoBufferReady(client_a_route_1, capture_resolution)) | 313 EXPECT_CALL(*client_a_, DoBufferReady(client_a_route_1, capture_resolution)) |
| 298 .Times(1); | 314 .Times(1); |
| 299 } | 315 } |
| 300 { | 316 { |
| 301 InSequence s; | 317 InSequence s; |
| 302 EXPECT_CALL(*client_b_, DoBufferCreated(client_b_route_1)).Times(1); | 318 EXPECT_CALL(*client_b_, DoBufferCreated(client_b_route_1)).Times(1); |
| 303 EXPECT_CALL(*client_b_, DoBufferReady(client_b_route_1, capture_resolution)) | 319 EXPECT_CALL(*client_b_, DoBufferReady(client_b_route_1, capture_resolution)) |
| 304 .Times(1); | 320 .Times(1); |
| 305 } | 321 } |
| 306 { | 322 { |
| 307 InSequence s; | 323 InSequence s; |
| 308 EXPECT_CALL(*client_a_, DoBufferCreated(client_a_route_2)).Times(1); | 324 EXPECT_CALL(*client_a_, DoBufferCreated(client_a_route_2)).Times(1); |
| 309 EXPECT_CALL(*client_a_, DoBufferReady(client_a_route_2, capture_resolution)) | 325 EXPECT_CALL(*client_a_, DoBufferReady(client_a_route_2, capture_resolution)) |
| 310 .Times(1); | 326 .Times(1); |
| 311 } | 327 } |
| 312 scoped_refptr<media::VideoFrame> video_frame = WrapBuffer( | 328 scoped_refptr<media::VideoFrame> video_frame = WrapBuffer( |
| 313 capture_resolution, static_cast<uint8_t*>(buffer->data()), format); | 329 capture_resolution, static_cast<uint8_t*>(buffer->data()), format); |
| 314 ASSERT_TRUE(video_frame); | 330 ASSERT_TRUE(video_frame); |
| 315 ASSERT_FALSE(video_frame->metadata()->HasKey( | 331 ASSERT_FALSE(video_frame->metadata()->HasKey( |
| 316 media::VideoFrameMetadata::RESOURCE_UTILIZATION)); | 332 media::VideoFrameMetadata::RESOURCE_UTILIZATION)); |
| 317 client_a_->resource_utilization_ = 0.5; | 333 client_a_->resource_utilization_ = 0.5; |
| 318 client_b_->resource_utilization_ = -1.0; | 334 client_b_->resource_utilization_ = -1.0; |
| 335 |
| 336 // Expect VideoCaptureController to call the load observer with a |
| 337 // resource utilization of 0.5 (the largest of all reported values). |
| 338 EXPECT_CALL(*mock_consumer_feedback_observer_, |
| 339 OnUtilizationReport(arbitrary_frame_feedback_id, 0.5)) |
| 340 .Times(1); |
| 341 |
| 319 video_frame->metadata()->SetTimeTicks( | 342 video_frame->metadata()->SetTimeTicks( |
| 320 media::VideoFrameMetadata::REFERENCE_TIME, base::TimeTicks()); | 343 media::VideoFrameMetadata::REFERENCE_TIME, base::TimeTicks()); |
| 321 device_->OnIncomingCapturedVideoFrame(std::move(buffer), video_frame); | 344 device_->OnIncomingCapturedVideoFrame(std::move(buffer), video_frame); |
| 322 | 345 |
| 323 base::RunLoop().RunUntilIdle(); | 346 base::RunLoop().RunUntilIdle(); |
| 324 Mock::VerifyAndClearExpectations(client_a_.get()); | 347 Mock::VerifyAndClearExpectations(client_a_.get()); |
| 325 Mock::VerifyAndClearExpectations(client_b_.get()); | 348 Mock::VerifyAndClearExpectations(client_b_.get()); |
| 326 | 349 Mock::VerifyAndClearExpectations(mock_consumer_feedback_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 | 350 |
| 335 // Second buffer which ought to use the same shared memory buffer. In this | 351 // 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 | 352 // case pretend that the Buffer pointer is held by the device for a long |
| 337 // delay. This shouldn't affect anything. | 353 // delay. This shouldn't affect anything. |
| 354 const int arbitrary_frame_feedback_id_2 = 102; |
| 338 std::unique_ptr<media::VideoCaptureDevice::Client::Buffer> buffer2 = | 355 std::unique_ptr<media::VideoCaptureDevice::Client::Buffer> buffer2 = |
| 339 device_->ReserveOutputBuffer(capture_resolution, format, | 356 device_->ReserveOutputBuffer(capture_resolution, format, |
| 340 media::PIXEL_STORAGE_CPU); | 357 media::PIXEL_STORAGE_CPU, |
| 358 arbitrary_frame_feedback_id_2); |
| 341 ASSERT_TRUE(buffer2.get()); | 359 ASSERT_TRUE(buffer2.get()); |
| 342 memset(buffer2->data(), buffer_no++, buffer2->mapped_size()); | 360 memset(buffer2->data(), buffer_no++, buffer2->mapped_size()); |
| 343 video_frame = WrapBuffer(capture_resolution, | 361 video_frame = WrapBuffer(capture_resolution, |
| 344 static_cast<uint8_t*>(buffer2->data()), format); | 362 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; | 363 client_a_->resource_utilization_ = 0.5; |
| 349 client_b_->resource_utilization_ = 3.14; | 364 client_b_->resource_utilization_ = 3.14; |
| 350 video_frame->metadata()->SetTimeTicks( | 365 video_frame->metadata()->SetTimeTicks( |
| 351 media::VideoFrameMetadata::REFERENCE_TIME, base::TimeTicks()); | 366 media::VideoFrameMetadata::REFERENCE_TIME, base::TimeTicks()); |
| 367 // Expect VideoCaptureController to call the load observer with a |
| 368 // resource utilization of 3.14 (the largest of all reported values). |
| 369 EXPECT_CALL(*mock_consumer_feedback_observer_, |
| 370 OnUtilizationReport(arbitrary_frame_feedback_id_2, 3.14)) |
| 371 .Times(1); |
| 372 |
| 352 device_->OnIncomingCapturedVideoFrame(std::move(buffer2), video_frame); | 373 device_->OnIncomingCapturedVideoFrame(std::move(buffer2), video_frame); |
| 353 | 374 |
| 354 // The buffer should be delivered to the clients in any order. | 375 // The buffer should be delivered to the clients in any order. |
| 355 { | 376 { |
| 356 InSequence s; | 377 InSequence s; |
| 357 EXPECT_CALL(*client_a_, DoBufferCreated(client_a_route_1)).Times(1); | 378 EXPECT_CALL(*client_a_, DoBufferCreated(client_a_route_1)).Times(1); |
| 358 EXPECT_CALL(*client_a_, DoBufferReady(client_a_route_1, capture_resolution)) | 379 EXPECT_CALL(*client_a_, DoBufferReady(client_a_route_1, capture_resolution)) |
| 359 .Times(1); | 380 .Times(1); |
| 360 } | 381 } |
| 361 { | 382 { |
| 362 InSequence s; | 383 InSequence s; |
| 363 EXPECT_CALL(*client_b_, DoBufferCreated(client_b_route_1)).Times(1); | 384 EXPECT_CALL(*client_b_, DoBufferCreated(client_b_route_1)).Times(1); |
| 364 EXPECT_CALL(*client_b_, DoBufferReady(client_b_route_1, capture_resolution)) | 385 EXPECT_CALL(*client_b_, DoBufferReady(client_b_route_1, capture_resolution)) |
| 365 .Times(1); | 386 .Times(1); |
| 366 } | 387 } |
| 367 { | 388 { |
| 368 InSequence s; | 389 InSequence s; |
| 369 EXPECT_CALL(*client_a_, DoBufferCreated(client_a_route_2)).Times(1); | 390 EXPECT_CALL(*client_a_, DoBufferCreated(client_a_route_2)).Times(1); |
| 370 EXPECT_CALL(*client_a_, DoBufferReady(client_a_route_2, capture_resolution)) | 391 EXPECT_CALL(*client_a_, DoBufferReady(client_a_route_2, capture_resolution)) |
| 371 .Times(1); | 392 .Times(1); |
| 372 } | 393 } |
| 373 base::RunLoop().RunUntilIdle(); | 394 base::RunLoop().RunUntilIdle(); |
| 374 Mock::VerifyAndClearExpectations(client_a_.get()); | 395 Mock::VerifyAndClearExpectations(client_a_.get()); |
| 375 Mock::VerifyAndClearExpectations(client_b_.get()); | 396 Mock::VerifyAndClearExpectations(client_b_.get()); |
| 376 // Expect VideoCaptureController set the metadata in |video_frame| to hold a | 397 Mock::VerifyAndClearExpectations(mock_consumer_feedback_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 | 398 |
| 384 // Add a fourth client now that some buffers have come through. | 399 // Add a fourth client now that some buffers have come through. |
| 385 controller_->AddClient(client_b_route_2, | 400 controller_->AddClient(client_b_route_2, |
| 386 client_b_.get(), | 401 client_b_.get(), |
| 387 1, | 402 1, |
| 388 session_1); | 403 session_1); |
| 389 Mock::VerifyAndClearExpectations(client_b_.get()); | 404 Mock::VerifyAndClearExpectations(client_b_.get()); |
| 390 | 405 |
| 391 // Third, fourth, and fifth buffers. Pretend they all arrive at the same time. | 406 // Third, fourth, and fifth buffers. Pretend they all arrive at the same time. |
| 392 for (int i = 0; i < kPoolSize; i++) { | 407 for (int i = 0; i < kPoolSize; i++) { |
| 408 const int arbitrary_frame_feedback_id = 200 + i; |
| 393 std::unique_ptr<media::VideoCaptureDevice::Client::Buffer> buffer = | 409 std::unique_ptr<media::VideoCaptureDevice::Client::Buffer> buffer = |
| 394 device_->ReserveOutputBuffer(capture_resolution, format, | 410 device_->ReserveOutputBuffer(capture_resolution, format, |
| 395 media::PIXEL_STORAGE_CPU); | 411 media::PIXEL_STORAGE_CPU, |
| 412 arbitrary_frame_feedback_id); |
| 396 ASSERT_TRUE(buffer.get()); | 413 ASSERT_TRUE(buffer.get()); |
| 397 memset(buffer->data(), buffer_no++, buffer->mapped_size()); | 414 memset(buffer->data(), buffer_no++, buffer->mapped_size()); |
| 398 video_frame = WrapBuffer(capture_resolution, | 415 video_frame = WrapBuffer(capture_resolution, |
| 399 static_cast<uint8_t*>(buffer->data()), format); | 416 static_cast<uint8_t*>(buffer->data()), format); |
| 400 ASSERT_TRUE(video_frame); | 417 ASSERT_TRUE(video_frame); |
| 401 video_frame->metadata()->SetTimeTicks( | 418 video_frame->metadata()->SetTimeTicks( |
| 402 media::VideoFrameMetadata::REFERENCE_TIME, base::TimeTicks()); | 419 media::VideoFrameMetadata::REFERENCE_TIME, base::TimeTicks()); |
| 403 device_->OnIncomingCapturedVideoFrame(std::move(buffer), video_frame); | 420 device_->OnIncomingCapturedVideoFrame(std::move(buffer), video_frame); |
| 404 } | 421 } |
| 405 // ReserveOutputBuffer ought to fail now, because the pool is depleted. | 422 // ReserveOutputBuffer ought to fail now, because the pool is depleted. |
| 406 ASSERT_FALSE(device_ | 423 ASSERT_FALSE(device_ |
| 407 ->ReserveOutputBuffer(capture_resolution, format, | 424 ->ReserveOutputBuffer(capture_resolution, format, |
| 408 media::PIXEL_STORAGE_CPU) | 425 media::PIXEL_STORAGE_CPU, |
| 426 arbitrary_frame_feedback_id) |
| 409 .get()); | 427 .get()); |
| 410 | 428 |
| 411 // The new client needs to be notified of the creation of |kPoolSize| buffers; | 429 // The new client needs to be notified of the creation of |kPoolSize| buffers; |
| 412 // the old clients only |kPoolSize - 2|. | 430 // the old clients only |kPoolSize - 2|. |
| 413 EXPECT_CALL(*client_b_, DoBufferCreated(client_b_route_2)).Times(kPoolSize); | 431 EXPECT_CALL(*client_b_, DoBufferCreated(client_b_route_2)).Times(kPoolSize); |
| 414 EXPECT_CALL(*client_b_, DoBufferReady(client_b_route_2, capture_resolution)) | 432 EXPECT_CALL(*client_b_, DoBufferReady(client_b_route_2, capture_resolution)) |
| 415 .Times(kPoolSize); | 433 .Times(kPoolSize); |
| 416 EXPECT_CALL(*client_a_, DoBufferCreated(client_a_route_1)) | 434 EXPECT_CALL(*client_a_, DoBufferCreated(client_a_route_1)) |
| 417 .Times(kPoolSize - 2); | 435 .Times(kPoolSize - 2); |
| 418 EXPECT_CALL(*client_a_, DoBufferReady(client_a_route_1, capture_resolution)) | 436 EXPECT_CALL(*client_a_, DoBufferReady(client_a_route_1, capture_resolution)) |
| (...skipping 12 matching lines...) Expand all Loading... |
| 431 | 449 |
| 432 // Now test the interaction of client shutdown and buffer delivery. | 450 // Now test the interaction of client shutdown and buffer delivery. |
| 433 // Kill A1 via renderer disconnect (synchronous). | 451 // Kill A1 via renderer disconnect (synchronous). |
| 434 controller_->RemoveClient(client_a_route_1, client_a_.get()); | 452 controller_->RemoveClient(client_a_route_1, client_a_.get()); |
| 435 // Kill B1 via session close (posts a task to disconnect). | 453 // Kill B1 via session close (posts a task to disconnect). |
| 436 EXPECT_CALL(*client_b_, DoEnded(client_b_route_1)).Times(1); | 454 EXPECT_CALL(*client_b_, DoEnded(client_b_route_1)).Times(1); |
| 437 controller_->StopSession(300); | 455 controller_->StopSession(300); |
| 438 // Queue up another buffer. | 456 // Queue up another buffer. |
| 439 std::unique_ptr<media::VideoCaptureDevice::Client::Buffer> buffer3 = | 457 std::unique_ptr<media::VideoCaptureDevice::Client::Buffer> buffer3 = |
| 440 device_->ReserveOutputBuffer(capture_resolution, format, | 458 device_->ReserveOutputBuffer(capture_resolution, format, |
| 441 media::PIXEL_STORAGE_CPU); | 459 media::PIXEL_STORAGE_CPU, |
| 460 arbitrary_frame_feedback_id); |
| 442 ASSERT_TRUE(buffer3.get()); | 461 ASSERT_TRUE(buffer3.get()); |
| 443 memset(buffer3->data(), buffer_no++, buffer3->mapped_size()); | 462 memset(buffer3->data(), buffer_no++, buffer3->mapped_size()); |
| 444 video_frame = WrapBuffer(capture_resolution, | 463 video_frame = WrapBuffer(capture_resolution, |
| 445 static_cast<uint8_t*>(buffer3->data()), format); | 464 static_cast<uint8_t*>(buffer3->data()), format); |
| 446 ASSERT_TRUE(video_frame); | 465 ASSERT_TRUE(video_frame); |
| 447 video_frame->metadata()->SetTimeTicks( | 466 video_frame->metadata()->SetTimeTicks( |
| 448 media::VideoFrameMetadata::REFERENCE_TIME, base::TimeTicks()); | 467 media::VideoFrameMetadata::REFERENCE_TIME, base::TimeTicks()); |
| 449 device_->OnIncomingCapturedVideoFrame(std::move(buffer3), video_frame); | 468 device_->OnIncomingCapturedVideoFrame(std::move(buffer3), video_frame); |
| 450 | 469 |
| 451 std::unique_ptr<media::VideoCaptureDevice::Client::Buffer> buffer4 = | 470 std::unique_ptr<media::VideoCaptureDevice::Client::Buffer> buffer4 = |
| 452 device_->ReserveOutputBuffer(capture_resolution, format, | 471 device_->ReserveOutputBuffer(capture_resolution, format, |
| 453 media::PIXEL_STORAGE_CPU); | 472 media::PIXEL_STORAGE_CPU, |
| 473 arbitrary_frame_feedback_id); |
| 454 { | 474 { |
| 455 // Kill A2 via session close (posts a task to disconnect, but A2 must not | 475 // Kill A2 via session close (posts a task to disconnect, but A2 must not |
| 456 // be sent either of these two buffers). | 476 // be sent either of these two buffers). |
| 457 EXPECT_CALL(*client_a_, DoEnded(client_a_route_2)).Times(1); | 477 EXPECT_CALL(*client_a_, DoEnded(client_a_route_2)).Times(1); |
| 458 controller_->StopSession(200); | 478 controller_->StopSession(200); |
| 459 } | 479 } |
| 460 ASSERT_TRUE(buffer4.get()); | 480 ASSERT_TRUE(buffer4.get()); |
| 461 memset(buffer4->data(), buffer_no++, buffer4->mapped_size()); | 481 memset(buffer4->data(), buffer_no++, buffer4->mapped_size()); |
| 462 video_frame = WrapBuffer(capture_resolution, | 482 video_frame = WrapBuffer(capture_resolution, |
| 463 static_cast<uint8_t*>(buffer4->data()), format); | 483 static_cast<uint8_t*>(buffer4->data()), format); |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 499 base::RunLoop().RunUntilIdle(); | 519 base::RunLoop().RunUntilIdle(); |
| 500 Mock::VerifyAndClearExpectations(client_a_.get()); | 520 Mock::VerifyAndClearExpectations(client_a_.get()); |
| 501 | 521 |
| 502 // Second client connects after the error state. It also should get told of | 522 // Second client connects after the error state. It also should get told of |
| 503 // the error. | 523 // the error. |
| 504 EXPECT_CALL(*client_b_, DoError(route_id)).Times(1); | 524 EXPECT_CALL(*client_b_, DoError(route_id)).Times(1); |
| 505 controller_->AddClient(route_id, client_b_.get(), 200, session_200); | 525 controller_->AddClient(route_id, client_b_.get(), 200, session_200); |
| 506 base::RunLoop().RunUntilIdle(); | 526 base::RunLoop().RunUntilIdle(); |
| 507 Mock::VerifyAndClearExpectations(client_b_.get()); | 527 Mock::VerifyAndClearExpectations(client_b_.get()); |
| 508 | 528 |
| 529 const int arbitrary_frame_feedback_id = 101; |
| 509 std::unique_ptr<media::VideoCaptureDevice::Client::Buffer> buffer( | 530 std::unique_ptr<media::VideoCaptureDevice::Client::Buffer> buffer( |
| 510 device_->ReserveOutputBuffer(capture_resolution, media::PIXEL_FORMAT_I420, | 531 device_->ReserveOutputBuffer(capture_resolution, media::PIXEL_FORMAT_I420, |
| 511 media::PIXEL_STORAGE_CPU)); | 532 media::PIXEL_STORAGE_CPU, |
| 533 arbitrary_frame_feedback_id)); |
| 512 ASSERT_TRUE(buffer.get()); | 534 ASSERT_TRUE(buffer.get()); |
| 513 scoped_refptr<media::VideoFrame> video_frame = | 535 scoped_refptr<media::VideoFrame> video_frame = |
| 514 WrapBuffer(capture_resolution, static_cast<uint8_t*>(buffer->data())); | 536 WrapBuffer(capture_resolution, static_cast<uint8_t*>(buffer->data())); |
| 515 ASSERT_TRUE(video_frame); | 537 ASSERT_TRUE(video_frame); |
| 516 video_frame->metadata()->SetTimeTicks( | 538 video_frame->metadata()->SetTimeTicks( |
| 517 media::VideoFrameMetadata::REFERENCE_TIME, base::TimeTicks()); | 539 media::VideoFrameMetadata::REFERENCE_TIME, base::TimeTicks()); |
| 518 device_->OnIncomingCapturedVideoFrame(std::move(buffer), video_frame); | 540 device_->OnIncomingCapturedVideoFrame(std::move(buffer), video_frame); |
| 519 | 541 |
| 520 base::RunLoop().RunUntilIdle(); | 542 base::RunLoop().RunUntilIdle(); |
| 521 } | 543 } |
| (...skipping 14 matching lines...) Expand all Loading... |
| 536 media::VideoCaptureFormat device_format( | 558 media::VideoCaptureFormat device_format( |
| 537 gfx::Size(10, 10), 25, media::PIXEL_FORMAT_ARGB); | 559 gfx::Size(10, 10), 25, media::PIXEL_FORMAT_ARGB); |
| 538 | 560 |
| 539 // Start the device. Then, before the first buffer, signal an error and | 561 // Start the device. Then, before the first buffer, signal an error and |
| 540 // deliver the buffer. The error should be propagated to clients; the buffer | 562 // deliver the buffer. The error should be propagated to clients; the buffer |
| 541 // should not be. | 563 // should not be. |
| 542 base::RunLoop().RunUntilIdle(); | 564 base::RunLoop().RunUntilIdle(); |
| 543 Mock::VerifyAndClearExpectations(client_a_.get()); | 565 Mock::VerifyAndClearExpectations(client_a_.get()); |
| 544 | 566 |
| 545 const gfx::Size dims(320, 240); | 567 const gfx::Size dims(320, 240); |
| 568 const int arbitrary_frame_feedback_id = 101; |
| 546 std::unique_ptr<media::VideoCaptureDevice::Client::Buffer> buffer( | 569 std::unique_ptr<media::VideoCaptureDevice::Client::Buffer> buffer( |
| 547 device_->ReserveOutputBuffer(dims, media::PIXEL_FORMAT_I420, | 570 device_->ReserveOutputBuffer(dims, media::PIXEL_FORMAT_I420, |
| 548 media::PIXEL_STORAGE_CPU)); | 571 media::PIXEL_STORAGE_CPU, |
| 572 arbitrary_frame_feedback_id)); |
| 549 ASSERT_TRUE(buffer.get()); | 573 ASSERT_TRUE(buffer.get()); |
| 550 | 574 |
| 551 scoped_refptr<media::VideoFrame> video_frame = | 575 scoped_refptr<media::VideoFrame> video_frame = |
| 552 WrapBuffer(dims, static_cast<uint8_t*>(buffer->data())); | 576 WrapBuffer(dims, static_cast<uint8_t*>(buffer->data())); |
| 553 ASSERT_TRUE(video_frame); | 577 ASSERT_TRUE(video_frame); |
| 554 device_->OnError(FROM_HERE, "Test Error"); | 578 device_->OnError(FROM_HERE, "Test Error"); |
| 555 video_frame->metadata()->SetTimeTicks( | 579 video_frame->metadata()->SetTimeTicks( |
| 556 media::VideoFrameMetadata::REFERENCE_TIME, base::TimeTicks()); | 580 media::VideoFrameMetadata::REFERENCE_TIME, base::TimeTicks()); |
| 557 device_->OnIncomingCapturedVideoFrame(std::move(buffer), video_frame); | 581 device_->OnIncomingCapturedVideoFrame(std::move(buffer), video_frame); |
| 558 | 582 |
| 559 EXPECT_CALL(*client_a_, DoError(route_id)).Times(1); | 583 EXPECT_CALL(*client_a_, DoError(route_id)).Times(1); |
| 560 base::RunLoop().RunUntilIdle(); | 584 base::RunLoop().RunUntilIdle(); |
| 561 Mock::VerifyAndClearExpectations(client_a_.get()); | 585 Mock::VerifyAndClearExpectations(client_a_.get()); |
| 562 | 586 |
| 563 // Second client connects after the error state. It also should get told of | 587 // Second client connects after the error state. It also should get told of |
| 564 // the error. | 588 // the error. |
| 565 EXPECT_CALL(*client_b_, DoError(route_id)).Times(1); | 589 EXPECT_CALL(*client_b_, DoError(route_id)).Times(1); |
| 566 controller_->AddClient(route_id, client_b_.get(), 200, session_200); | 590 controller_->AddClient(route_id, client_b_.get(), 200, session_200); |
| 567 Mock::VerifyAndClearExpectations(client_b_.get()); | 591 Mock::VerifyAndClearExpectations(client_b_.get()); |
| 568 } | 592 } |
| 569 | 593 |
| 570 } // namespace content | 594 } // namespace content |
| OLD | NEW |