Index: content/browser/renderer_host/media/video_capture_controller_unittest.cc |
diff --git a/content/browser/renderer_host/media/video_capture_controller_unittest.cc b/content/browser/renderer_host/media/video_capture_controller_unittest.cc |
index 21c5fbe693104a4a72b7e0d9c97b6a8caa308175..6f05cb092bf2f3d6aa6eefea79c6bca6fa057e24 100644 |
--- a/content/browser/renderer_host/media/video_capture_controller_unittest.cc |
+++ b/content/browser/renderer_host/media/video_capture_controller_unittest.cc |
@@ -95,6 +95,12 @@ class MockVideoCaptureControllerEventHandler |
double resource_utilization_; |
}; |
+class MockFrameReceiverObserver : public media::FrameReceiverObserver { |
+ public: |
+ MOCK_METHOD2(OnReceiverReportingUtilization, void(int buffer_id, |
+ double utilization)); |
+}; |
+ |
// Test class. |
class VideoCaptureControllerTest |
: public testing::Test, |
@@ -109,6 +115,7 @@ class VideoCaptureControllerTest |
void SetUp() override { |
controller_.reset(new VideoCaptureController(kPoolSize)); |
device_ = controller_->NewDeviceClient(); |
+ controller_->SetFrameReceiverObserver(&mock_frame_receiver_observer_); |
client_a_.reset(new MockVideoCaptureControllerEventHandler( |
controller_.get())); |
client_b_.reset(new MockVideoCaptureControllerEventHandler( |
@@ -135,6 +142,8 @@ class VideoCaptureControllerTest |
std::unique_ptr<MockVideoCaptureControllerEventHandler> client_b_; |
std::unique_ptr<VideoCaptureController> controller_; |
std::unique_ptr<media::VideoCaptureDevice::Client> device_; |
+ MockFrameReceiverObserver mock_frame_receiver_observer_; |
+ const int arbitrary_frame_id_ = 0; |
private: |
DISALLOW_COPY_AND_ASSIGN(VideoCaptureControllerTest); |
@@ -316,21 +325,21 @@ TEST_P(VideoCaptureControllerTest, NormalCaptureMultipleClients) { |
media::VideoFrameMetadata::RESOURCE_UTILIZATION)); |
client_a_->resource_utilization_ = 0.5; |
client_b_->resource_utilization_ = -1.0; |
+ |
+ // Expect VideoCaptureController to call the load observer with a |
+ // resource utilization of 0.5 (the largest of all reported values). |
+ EXPECT_CALL(mock_frame_receiver_observer_, |
+ OnReceiverReportingUtilization(buffer->id(), 0.5)); |
+ |
video_frame->metadata()->SetTimeTicks( |
media::VideoFrameMetadata::REFERENCE_TIME, base::TimeTicks()); |
- device_->OnIncomingCapturedVideoFrame(std::move(buffer), video_frame); |
+ device_->OnIncomingCapturedVideoFrame(std::move(buffer), video_frame, |
+ arbitrary_frame_id_); |
base::RunLoop().RunUntilIdle(); |
Mock::VerifyAndClearExpectations(client_a_.get()); |
Mock::VerifyAndClearExpectations(client_b_.get()); |
- |
- // Expect VideoCaptureController set the metadata in |video_frame| to hold a |
- // resource utilization of 0.5 (the largest of all reported values). |
- double resource_utilization_in_metadata = -1.0; |
- ASSERT_TRUE(video_frame->metadata()->GetDouble( |
- media::VideoFrameMetadata::RESOURCE_UTILIZATION, |
- &resource_utilization_in_metadata)); |
- ASSERT_EQ(0.5, resource_utilization_in_metadata); |
+ Mock::VerifyAndClearExpectations(&mock_frame_receiver_observer_); |
// Second buffer which ought to use the same shared memory buffer. In this |
// case pretend that the Buffer pointer is held by the device for a long |
@@ -342,14 +351,17 @@ TEST_P(VideoCaptureControllerTest, NormalCaptureMultipleClients) { |
memset(buffer2->data(), buffer_no++, buffer2->mapped_size()); |
video_frame = WrapBuffer(capture_resolution, |
static_cast<uint8_t*>(buffer2->data()), format); |
- ASSERT_TRUE(video_frame); |
- ASSERT_FALSE(video_frame->metadata()->HasKey( |
- media::VideoFrameMetadata::RESOURCE_UTILIZATION)); |
client_a_->resource_utilization_ = 0.5; |
client_b_->resource_utilization_ = 3.14; |
video_frame->metadata()->SetTimeTicks( |
media::VideoFrameMetadata::REFERENCE_TIME, base::TimeTicks()); |
- device_->OnIncomingCapturedVideoFrame(std::move(buffer2), video_frame); |
+ // Expect VideoCaptureController to call the load observer with a |
+ // resource utilization of 3.14 (the largest of all reported values). |
+ EXPECT_CALL(mock_frame_receiver_observer_, |
+ OnReceiverReportingUtilization(buffer2->id(), 3.14)); |
+ |
+ device_->OnIncomingCapturedVideoFrame(std::move(buffer2), video_frame, |
+ arbitrary_frame_id_); |
// The buffer should be delivered to the clients in any order. |
{ |
@@ -373,13 +385,7 @@ TEST_P(VideoCaptureControllerTest, NormalCaptureMultipleClients) { |
base::RunLoop().RunUntilIdle(); |
Mock::VerifyAndClearExpectations(client_a_.get()); |
Mock::VerifyAndClearExpectations(client_b_.get()); |
- // Expect VideoCaptureController set the metadata in |video_frame| to hold a |
- // resource utilization of 3.14 (the largest of all reported values). |
- resource_utilization_in_metadata = -1.0; |
- ASSERT_TRUE(video_frame->metadata()->GetDouble( |
- media::VideoFrameMetadata::RESOURCE_UTILIZATION, |
- &resource_utilization_in_metadata)); |
- ASSERT_EQ(3.14, resource_utilization_in_metadata); |
+ Mock::VerifyAndClearExpectations(&mock_frame_receiver_observer_); |
// Add a fourth client now that some buffers have come through. |
controller_->AddClient(client_b_route_2, |
@@ -400,7 +406,8 @@ TEST_P(VideoCaptureControllerTest, NormalCaptureMultipleClients) { |
ASSERT_TRUE(video_frame); |
video_frame->metadata()->SetTimeTicks( |
media::VideoFrameMetadata::REFERENCE_TIME, base::TimeTicks()); |
- device_->OnIncomingCapturedVideoFrame(std::move(buffer), video_frame); |
+ device_->OnIncomingCapturedVideoFrame(std::move(buffer), video_frame, |
+ arbitrary_frame_id_); |
} |
// ReserveOutputBuffer ought to fail now, because the pool is depleted. |
ASSERT_FALSE(device_ |
@@ -446,7 +453,8 @@ TEST_P(VideoCaptureControllerTest, NormalCaptureMultipleClients) { |
ASSERT_TRUE(video_frame); |
video_frame->metadata()->SetTimeTicks( |
media::VideoFrameMetadata::REFERENCE_TIME, base::TimeTicks()); |
- device_->OnIncomingCapturedVideoFrame(std::move(buffer3), video_frame); |
+ device_->OnIncomingCapturedVideoFrame(std::move(buffer3), video_frame, |
+ arbitrary_frame_id_); |
std::unique_ptr<media::VideoCaptureDevice::Client::Buffer> buffer4 = |
device_->ReserveOutputBuffer(capture_resolution, format, |
@@ -464,7 +472,8 @@ TEST_P(VideoCaptureControllerTest, NormalCaptureMultipleClients) { |
ASSERT_TRUE(video_frame); |
video_frame->metadata()->SetTimeTicks( |
media::VideoFrameMetadata::REFERENCE_TIME, base::TimeTicks()); |
- device_->OnIncomingCapturedVideoFrame(std::move(buffer4), video_frame); |
+ device_->OnIncomingCapturedVideoFrame(std::move(buffer4), video_frame, |
+ arbitrary_frame_id_); |
// B2 is the only client left, and is the only one that should |
// get the buffer. |
EXPECT_CALL(*client_b_, DoBufferReady(client_b_route_2, capture_resolution)) |
@@ -515,7 +524,8 @@ TEST_F(VideoCaptureControllerTest, ErrorBeforeDeviceCreation) { |
ASSERT_TRUE(video_frame); |
video_frame->metadata()->SetTimeTicks( |
media::VideoFrameMetadata::REFERENCE_TIME, base::TimeTicks()); |
- device_->OnIncomingCapturedVideoFrame(std::move(buffer), video_frame); |
+ device_->OnIncomingCapturedVideoFrame(std::move(buffer), video_frame, |
+ arbitrary_frame_id_); |
base::RunLoop().RunUntilIdle(); |
} |
@@ -554,7 +564,8 @@ TEST_F(VideoCaptureControllerTest, ErrorAfterDeviceCreation) { |
device_->OnError(FROM_HERE, "Test Error"); |
video_frame->metadata()->SetTimeTicks( |
media::VideoFrameMetadata::REFERENCE_TIME, base::TimeTicks()); |
- device_->OnIncomingCapturedVideoFrame(std::move(buffer), video_frame); |
+ device_->OnIncomingCapturedVideoFrame(std::move(buffer), video_frame, |
+ arbitrary_frame_id_); |
EXPECT_CALL(*client_a_, DoError(route_id)).Times(1); |
base::RunLoop().RunUntilIdle(); |