| Index: content/browser/renderer_host/media/video_capture_device_client_unittest.cc
|
| diff --git a/content/browser/renderer_host/media/video_capture_device_client_unittest.cc b/content/browser/renderer_host/media/video_capture_device_client_unittest.cc
|
| index 020854b4f270b0dba399f2d43c8a8f6806fb7bd9..991faa8bbeecce001da18797bf1e03c2a458d74d 100644
|
| --- a/content/browser/renderer_host/media/video_capture_device_client_unittest.cc
|
| +++ b/content/browser/renderer_host/media/video_capture_device_client_unittest.cc
|
| @@ -37,7 +37,8 @@ class MockVideoCaptureController : public VideoCaptureController {
|
| : VideoCaptureController(max_buffers) {}
|
| ~MockVideoCaptureController() override {}
|
|
|
| - MOCK_METHOD1(MockOnIncomingCapturedVideoFrame, void(const gfx::Size&));
|
| + MOCK_METHOD2(MockOnIncomingCapturedVideoFrame,
|
| + void(const gfx::Size& coded_size, int buffer_id));
|
| MOCK_METHOD0(OnError, void());
|
| MOCK_METHOD1(OnLog, void(const std::string& message));
|
| MOCK_METHOD1(OnBufferDestroyed, void(int buffer_id_to_drop));
|
| @@ -45,10 +46,16 @@ class MockVideoCaptureController : public VideoCaptureController {
|
| void OnIncomingCapturedVideoFrame(
|
| std::unique_ptr<media::VideoCaptureDevice::Client::Buffer> buffer,
|
| scoped_refptr<media::VideoFrame> frame) override {
|
| - MockOnIncomingCapturedVideoFrame(frame->coded_size());
|
| + MockOnIncomingCapturedVideoFrame(frame->coded_size(), buffer->id());
|
| }
|
| };
|
|
|
| +class MockConsumerLoadObserver : public media::ConsumerLoadObserver {
|
| + public:
|
| + MOCK_METHOD2(OnConsumerReportingUtilization,
|
| + void(int frame_id, double utilization));
|
| +};
|
| +
|
| // Note that this test does not exercise the class VideoCaptureDeviceClient
|
| // in isolation. The "unit under test" is an instance of
|
| // VideoCaptureDeviceClient with some context that is specific to
|
| @@ -67,7 +74,7 @@ class VideoCaptureDeviceClientTest : public ::testing::Test {
|
| protected:
|
| const content::TestBrowserThreadBundle thread_bundle_;
|
| const std::unique_ptr<MockVideoCaptureController> controller_;
|
| - const std::unique_ptr<media::VideoCaptureDevice::Client> device_client_;
|
| + const std::unique_ptr<media::VideoCaptureDeviceClient> device_client_;
|
|
|
| private:
|
| DISALLOW_COPY_AND_ASSIGN(VideoCaptureDeviceClientTest);
|
| @@ -86,7 +93,7 @@ TEST_F(VideoCaptureDeviceClientTest, Minimal) {
|
| media::PIXEL_STORAGE_CPU);
|
| DCHECK(device_client_.get());
|
| EXPECT_CALL(*controller_, OnLog(_)).Times(1);
|
| - EXPECT_CALL(*controller_, MockOnIncomingCapturedVideoFrame(_)).Times(1);
|
| + EXPECT_CALL(*controller_, MockOnIncomingCapturedVideoFrame(_, _)).Times(1);
|
| device_client_->OnIncomingCapturedData(data, kScratchpadSizeInBytes,
|
| kFrameFormat, 0 /*clockwise rotation*/,
|
| base::TimeTicks(), base::TimeDelta());
|
| @@ -107,7 +114,7 @@ TEST_F(VideoCaptureDeviceClientTest, FailsSilentlyGivenInvalidFrameFormat) {
|
| DCHECK(device_client_.get());
|
| // Expect the the call to fail silently inside the VideoCaptureDeviceClient.
|
| EXPECT_CALL(*controller_, OnLog(_)).Times(1);
|
| - EXPECT_CALL(*controller_, MockOnIncomingCapturedVideoFrame(_)).Times(0);
|
| + EXPECT_CALL(*controller_, MockOnIncomingCapturedVideoFrame(_, _)).Times(0);
|
| device_client_->OnIncomingCapturedData(data, kScratchpadSizeInBytes,
|
| kFrameFormat, 0 /*clockwise rotation*/,
|
| base::TimeTicks(), base::TimeDelta());
|
| @@ -126,7 +133,7 @@ TEST_F(VideoCaptureDeviceClientTest, DropsFrameIfNoBuffer) {
|
| // We expect the second frame to be silently dropped, so these should
|
| // only be called once despite the two frames.
|
| EXPECT_CALL(*controller_, OnLog(_)).Times(1);
|
| - EXPECT_CALL(*controller_, MockOnIncomingCapturedVideoFrame(_)).Times(1);
|
| + EXPECT_CALL(*controller_, MockOnIncomingCapturedVideoFrame(_, _)).Times(1);
|
| // Pass two frames. The second will be dropped.
|
| device_client_->OnIncomingCapturedData(data, kScratchpadSizeInBytes,
|
| kFrameFormat, 0 /*clockwise rotation*/,
|
| @@ -175,7 +182,7 @@ TEST_F(VideoCaptureDeviceClientTest, DataCaptureGoodPixelFormats) {
|
| params.requested_format.pixel_format = format;
|
|
|
| EXPECT_CALL(*controller_, OnLog(_)).Times(1);
|
| - EXPECT_CALL(*controller_, MockOnIncomingCapturedVideoFrame(_)).Times(1);
|
| + EXPECT_CALL(*controller_, MockOnIncomingCapturedVideoFrame(_, _)).Times(1);
|
| device_client_->OnIncomingCapturedData(
|
| data, params.requested_format.ImageAllocationSize(),
|
| params.requested_format, 0 /* clockwise_rotation */, base::TimeTicks(),
|
| @@ -219,7 +226,7 @@ TEST_F(VideoCaptureDeviceClientTest, CheckRotationsAndCrops) {
|
| media::VideoCaptureFormat(size_and_rotation.input_resolution, 30.0f,
|
| media::PIXEL_FORMAT_ARGB);
|
| gfx::Size coded_size;
|
| - EXPECT_CALL(*controller_, MockOnIncomingCapturedVideoFrame(_))
|
| + EXPECT_CALL(*controller_, MockOnIncomingCapturedVideoFrame(_, _))
|
| .Times(1)
|
| .WillOnce(SaveArg<0>(&coded_size));
|
| device_client_->OnIncomingCapturedData(
|
| @@ -236,4 +243,41 @@ TEST_F(VideoCaptureDeviceClientTest, CheckRotationsAndCrops) {
|
| }
|
| }
|
|
|
| +// Tests that consumer load reports arriving at VideoCaptureDeviceClient are
|
| +// correctly forwarded to its ConsumerLoadObserver with the buffer_id being
|
| +// translated to the frame_id.
|
| +TEST_F(VideoCaptureDeviceClientTest, ReportConsumerLoad) {
|
| + const size_t kScratchpadSizeInBytes = 400;
|
| + unsigned char data[kScratchpadSizeInBytes] = {};
|
| + const media::VideoCaptureFormat kFrameFormat(
|
| + gfx::Size(10, 10), 30.0f /*frame_rate*/,
|
| + media::PIXEL_FORMAT_I420,
|
| + media::PIXEL_STORAGE_CPU);
|
| + const int arbitrary_frame_id = 123;
|
| + const double arbitrary_utilization = 0.789;
|
| + DCHECK(device_client_.get());
|
| + MockConsumerLoadObserver load_observer;
|
| + device_client_->SetConsumerLoadObserver(&load_observer);
|
| +
|
| + int buffer_id;
|
| + EXPECT_CALL(*controller_, MockOnIncomingCapturedVideoFrame(_, _))
|
| + .Times(1)
|
| + .WillOnce(SaveArg<1>(&buffer_id));
|
| + EXPECT_CALL(load_observer, OnConsumerReportingUtilization(
|
| + arbitrary_frame_id, arbitrary_utilization))
|
| + .Times(1);
|
| +
|
| + device_client_->OnIncomingCapturedData(data, kScratchpadSizeInBytes,
|
| + kFrameFormat, 0 /*clockwise rotation*/,
|
| + base::TimeTicks(), base::TimeDelta(),
|
| + arbitrary_frame_id);
|
| + base::RunLoop().RunUntilIdle();
|
| +
|
| + device_client_->OnReceiverReportingUtilization(buffer_id,
|
| + arbitrary_utilization);
|
| +
|
| + base::RunLoop().RunUntilIdle();
|
| + Mock::VerifyAndClearExpectations(controller_.get());
|
| +}
|
| +
|
| } // namespace content
|
|
|