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