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

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

Issue 1826643003: Add frame refresh to VideoCaptureDevice, and buffer pool resurrection. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: REBASE before commit Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // Unit test for VideoCaptureController. 5 // Unit test for VideoCaptureController.
6 6
7 #include "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 313 matching lines...) Expand 10 before | Expand all | Expand 10 after
324 ASSERT_FALSE(video_frame->metadata()->HasKey( 324 ASSERT_FALSE(video_frame->metadata()->HasKey(
325 media::VideoFrameMetadata::RESOURCE_UTILIZATION)); 325 media::VideoFrameMetadata::RESOURCE_UTILIZATION));
326 client_a_->resource_utilization_ = 0.5; 326 client_a_->resource_utilization_ = 0.5;
327 client_b_->resource_utilization_ = -1.0; 327 client_b_->resource_utilization_ = -1.0;
328 device_->OnIncomingCapturedVideoFrame(std::move(buffer), video_frame, 328 device_->OnIncomingCapturedVideoFrame(std::move(buffer), video_frame,
329 base::TimeTicks()); 329 base::TimeTicks());
330 330
331 base::RunLoop().RunUntilIdle(); 331 base::RunLoop().RunUntilIdle();
332 Mock::VerifyAndClearExpectations(client_a_.get()); 332 Mock::VerifyAndClearExpectations(client_a_.get());
333 Mock::VerifyAndClearExpectations(client_b_.get()); 333 Mock::VerifyAndClearExpectations(client_b_.get());
334
334 // Expect VideoCaptureController set the metadata in |video_frame| to hold a 335 // Expect VideoCaptureController set the metadata in |video_frame| to hold a
335 // resource utilization of 0.5 (the largest of all reported values). 336 // resource utilization of 0.5 (the largest of all reported values).
336 double resource_utilization_in_metadata = -1.0; 337 double resource_utilization_in_metadata = -1.0;
337 ASSERT_TRUE(video_frame->metadata()->GetDouble( 338 ASSERT_TRUE(video_frame->metadata()->GetDouble(
338 media::VideoFrameMetadata::RESOURCE_UTILIZATION, 339 media::VideoFrameMetadata::RESOURCE_UTILIZATION,
339 &resource_utilization_in_metadata)); 340 &resource_utilization_in_metadata));
340 ASSERT_EQ(0.5, resource_utilization_in_metadata); 341 ASSERT_EQ(0.5, resource_utilization_in_metadata);
341 342
342 // Second buffer which ought to use the same shared memory buffer. In this 343 // Second buffer which ought to use the same shared memory buffer. In this
343 // case pretend that the Buffer pointer is held by the device for a long 344 // case pretend that the Buffer pointer is held by the device for a long
344 // delay. This shouldn't affect anything. 345 // delay. This shouldn't affect anything.
345 scoped_ptr<media::VideoCaptureDevice::Client::Buffer> buffer2 = 346 scoped_ptr<media::VideoCaptureDevice::Client::Buffer> buffer2 =
346 device_->ReserveOutputBuffer(capture_resolution, 347 device_->ReserveOutputBuffer(capture_resolution,
347 media::PIXEL_FORMAT_I420, 348 media::PIXEL_FORMAT_I420,
348 media::PIXEL_STORAGE_CPU); 349 media::PIXEL_STORAGE_CPU);
349 ASSERT_TRUE(buffer2.get()); 350 ASSERT_TRUE(buffer2.get());
350 memset(buffer2->data(), buffer_no++, buffer2->mapped_size()); 351 memset(buffer2->data(), buffer_no++, buffer2->mapped_size());
351 video_frame = WrapI420Buffer(capture_resolution, 352 video_frame = WrapI420Buffer(capture_resolution,
352 static_cast<uint8_t*>(buffer2->data())); 353 static_cast<uint8_t*>(buffer2->data()));
353 ASSERT_TRUE(video_frame); 354 ASSERT_TRUE(video_frame);
354 ASSERT_FALSE(video_frame->metadata()->HasKey( 355 ASSERT_FALSE(video_frame->metadata()->HasKey(
355 media::VideoFrameMetadata::RESOURCE_UTILIZATION)); 356 media::VideoFrameMetadata::RESOURCE_UTILIZATION));
356 client_a_->resource_utilization_ = 0.5; 357 client_a_->resource_utilization_ = 0.5;
357 client_b_->resource_utilization_ = 3.14; 358 client_b_->resource_utilization_ = 3.14;
358 device_->OnIncomingCapturedVideoFrame(std::move(buffer2), video_frame, 359 device_->OnIncomingCapturedVideoFrame(std::move(buffer2), video_frame,
359 base::TimeTicks()); 360 base::TimeTicks());
360 361
361 // The buffer should be delivered to the clients in any order. 362 // The buffer should be delivered to the clients in any order.
362 EXPECT_CALL(*client_a_, 363 {
363 DoI420BufferReady(client_a_route_1, capture_resolution)) 364 InSequence s;
364 .Times(1); 365 EXPECT_CALL(*client_a_, DoBufferCreated(client_a_route_1)).Times(1);
365 EXPECT_CALL(*client_b_, 366 EXPECT_CALL(*client_a_,
366 DoI420BufferReady(client_b_route_1, capture_resolution)) 367 DoI420BufferReady(client_a_route_1, capture_resolution))
367 .Times(1); 368 .Times(1);
368 EXPECT_CALL(*client_a_, 369 }
369 DoI420BufferReady(client_a_route_2, capture_resolution)) 370 {
370 .Times(1); 371 InSequence s;
372 EXPECT_CALL(*client_b_, DoBufferCreated(client_b_route_1)).Times(1);
373 EXPECT_CALL(*client_b_,
374 DoI420BufferReady(client_b_route_1, capture_resolution))
375 .Times(1);
376 }
377 {
378 InSequence s;
379 EXPECT_CALL(*client_a_, DoBufferCreated(client_a_route_2)).Times(1);
380 EXPECT_CALL(*client_a_,
381 DoI420BufferReady(client_a_route_2, capture_resolution))
382 .Times(1);
383 }
371 base::RunLoop().RunUntilIdle(); 384 base::RunLoop().RunUntilIdle();
372 Mock::VerifyAndClearExpectations(client_a_.get()); 385 Mock::VerifyAndClearExpectations(client_a_.get());
373 Mock::VerifyAndClearExpectations(client_b_.get()); 386 Mock::VerifyAndClearExpectations(client_b_.get());
374 // Expect VideoCaptureController set the metadata in |video_frame| to hold a 387 // Expect VideoCaptureController set the metadata in |video_frame| to hold a
375 // resource utilization of 3.14 (the largest of all reported values). 388 // resource utilization of 3.14 (the largest of all reported values).
376 resource_utilization_in_metadata = -1.0; 389 resource_utilization_in_metadata = -1.0;
377 ASSERT_TRUE(video_frame->metadata()->GetDouble( 390 ASSERT_TRUE(video_frame->metadata()->GetDouble(
378 media::VideoFrameMetadata::RESOURCE_UTILIZATION, 391 media::VideoFrameMetadata::RESOURCE_UTILIZATION,
379 &resource_utilization_in_metadata)); 392 &resource_utilization_in_metadata));
380 ASSERT_EQ(3.14, resource_utilization_in_metadata); 393 ASSERT_EQ(3.14, resource_utilization_in_metadata);
(...skipping 19 matching lines...) Expand all
400 ASSERT_TRUE(video_frame); 413 ASSERT_TRUE(video_frame);
401 device_->OnIncomingCapturedVideoFrame(std::move(buffer), video_frame, 414 device_->OnIncomingCapturedVideoFrame(std::move(buffer), video_frame,
402 base::TimeTicks()); 415 base::TimeTicks());
403 } 416 }
404 // ReserveOutputBuffer ought to fail now, because the pool is depleted. 417 // ReserveOutputBuffer ought to fail now, because the pool is depleted.
405 ASSERT_FALSE( 418 ASSERT_FALSE(
406 device_->ReserveOutputBuffer(capture_resolution, 419 device_->ReserveOutputBuffer(capture_resolution,
407 media::PIXEL_FORMAT_I420, 420 media::PIXEL_FORMAT_I420,
408 media::PIXEL_STORAGE_CPU).get()); 421 media::PIXEL_STORAGE_CPU).get());
409 422
410 // The new client needs to be told of 3 buffers; the old clients only 2. 423 // The new client needs to be notified of the creation of |kPoolSize| buffers;
424 // the old clients only |kPoolSize - 2|.
411 EXPECT_CALL(*client_b_, DoBufferCreated(client_b_route_2)).Times(kPoolSize); 425 EXPECT_CALL(*client_b_, DoBufferCreated(client_b_route_2)).Times(kPoolSize);
412 EXPECT_CALL(*client_b_, 426 EXPECT_CALL(*client_b_,
413 DoI420BufferReady(client_b_route_2, capture_resolution)) 427 DoI420BufferReady(client_b_route_2, capture_resolution))
414 .Times(kPoolSize); 428 .Times(kPoolSize);
415 EXPECT_CALL(*client_a_, DoBufferCreated(client_a_route_1)) 429 EXPECT_CALL(*client_a_, DoBufferCreated(client_a_route_1))
416 .Times(kPoolSize - 1); 430 .Times(kPoolSize - 2);
417 EXPECT_CALL(*client_a_, 431 EXPECT_CALL(*client_a_,
418 DoI420BufferReady(client_a_route_1, capture_resolution)) 432 DoI420BufferReady(client_a_route_1, capture_resolution))
419 .Times(kPoolSize); 433 .Times(kPoolSize);
420 EXPECT_CALL(*client_a_, DoBufferCreated(client_a_route_2)) 434 EXPECT_CALL(*client_a_, DoBufferCreated(client_a_route_2))
421 .Times(kPoolSize - 1); 435 .Times(kPoolSize - 2);
422 EXPECT_CALL(*client_a_, 436 EXPECT_CALL(*client_a_,
423 DoI420BufferReady(client_a_route_2, capture_resolution)) 437 DoI420BufferReady(client_a_route_2, capture_resolution))
424 .Times(kPoolSize); 438 .Times(kPoolSize);
425 EXPECT_CALL(*client_b_, DoBufferCreated(client_b_route_1)) 439 EXPECT_CALL(*client_b_, DoBufferCreated(client_b_route_1))
426 .Times(kPoolSize - 1); 440 .Times(kPoolSize - 2);
427 EXPECT_CALL(*client_b_, 441 EXPECT_CALL(*client_b_,
428 DoI420BufferReady(client_b_route_1, capture_resolution)) 442 DoI420BufferReady(client_b_route_1, capture_resolution))
429 .Times(kPoolSize); 443 .Times(kPoolSize);
430 base::RunLoop().RunUntilIdle(); 444 base::RunLoop().RunUntilIdle();
431 Mock::VerifyAndClearExpectations(client_a_.get()); 445 Mock::VerifyAndClearExpectations(client_a_.get());
432 Mock::VerifyAndClearExpectations(client_b_.get()); 446 Mock::VerifyAndClearExpectations(client_b_.get());
433 447
434 // Now test the interaction of client shutdown and buffer delivery. 448 // Now test the interaction of client shutdown and buffer delivery.
435 // Kill A1 via renderer disconnect (synchronous). 449 // Kill A1 via renderer disconnect (synchronous).
436 controller_->RemoveClient(client_a_route_1, client_a_.get()); 450 controller_->RemoveClient(client_a_route_1, client_a_.get());
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
562 576
563 // Second client connects after the error state. It also should get told of 577 // Second client connects after the error state. It also should get told of
564 // the error. 578 // the error.
565 EXPECT_CALL(*client_b_, DoError(route_id)).Times(1); 579 EXPECT_CALL(*client_b_, DoError(route_id)).Times(1);
566 controller_->AddClient( 580 controller_->AddClient(
567 route_id, client_b_.get(), base::kNullProcessHandle, 200, session_200); 581 route_id, client_b_.get(), base::kNullProcessHandle, 200, session_200);
568 Mock::VerifyAndClearExpectations(client_b_.get()); 582 Mock::VerifyAndClearExpectations(client_b_.get());
569 } 583 }
570 584
571 } // namespace content 585 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698