Chromium Code Reviews| Index: webrtc/modules/video_coding/codecs/test/videoprocessor_unittest.cc |
| diff --git a/webrtc/modules/video_coding/codecs/test/videoprocessor_unittest.cc b/webrtc/modules/video_coding/codecs/test/videoprocessor_unittest.cc |
| index 825c076a5033bd68f10b62dba70ee3e5ae1de8e5..211ac38c27aa9fb370bcd6873524d4bca2634b8a 100644 |
| --- a/webrtc/modules/video_coding/codecs/test/videoprocessor_unittest.cc |
| +++ b/webrtc/modules/video_coding/codecs/test/videoprocessor_unittest.cc |
| @@ -11,6 +11,7 @@ |
| #include <memory> |
| #include "webrtc/api/video/i420_buffer.h" |
| +#include "webrtc/common_types.h" |
| #include "webrtc/modules/video_coding/codecs/test/mock/mock_packet_manipulator.h" |
| #include "webrtc/modules/video_coding/codecs/test/videoprocessor.h" |
| #include "webrtc/modules/video_coding/include/mock/mock_video_codec_interface.h" |
| @@ -37,7 +38,6 @@ namespace { |
| const int kWidth = 352; |
| const int kHeight = 288; |
| const int kFrameSize = kWidth * kHeight * 3 / 2; // I420. |
| -const int kFramerate = 30; |
| const int kNumFrames = 2; |
| } // namespace |
| @@ -49,7 +49,6 @@ class VideoProcessorTest : public testing::Test { |
| webrtc::test::CodecSettings(kVideoCodecVP8, &config_.codec_settings); |
| config_.codec_settings.width = kWidth; |
| config_.codec_settings.height = kHeight; |
| - config_.codec_settings.maxFramerate = kFramerate; |
| EXPECT_CALL(frame_reader_mock_, NumberOfFrames()) |
| .WillRepeatedly(Return(kNumFrames)); |
| @@ -63,11 +62,16 @@ class VideoProcessorTest : public testing::Test { |
| void ExpectInit() { |
| EXPECT_CALL(encoder_mock_, InitEncode(_, _, _)).Times(1); |
| - EXPECT_CALL(encoder_mock_, RegisterEncodeCompleteCallback(_)) |
| - .Times(AtLeast(1)); |
| + EXPECT_CALL(encoder_mock_, RegisterEncodeCompleteCallback(_)).Times(1); |
| EXPECT_CALL(decoder_mock_, InitDecode(_, _)).Times(1); |
| - EXPECT_CALL(decoder_mock_, RegisterDecodeCompleteCallback(_)) |
| - .Times(AtLeast(1)); |
| + EXPECT_CALL(decoder_mock_, RegisterDecodeCompleteCallback(_)).Times(1); |
| + } |
| + |
| + void ExpectRelease() { |
| + EXPECT_CALL(encoder_mock_, Release()).Times(1); |
| + EXPECT_CALL(encoder_mock_, RegisterEncodeCompleteCallback(_)).Times(1); |
| + EXPECT_CALL(decoder_mock_, Release()).Times(1); |
| + EXPECT_CALL(decoder_mock_, RegisterDecodeCompleteCallback(_)).Times(1); |
| } |
| TestConfig config_; |
| @@ -81,28 +85,107 @@ class VideoProcessorTest : public testing::Test { |
| std::unique_ptr<VideoProcessor> video_processor_; |
| }; |
| -TEST_F(VideoProcessorTest, Init) { |
| +TEST_F(VideoProcessorTest, InitRelease) { |
| ExpectInit(); |
| video_processor_->Init(); |
| + |
| + ExpectRelease(); |
| + video_processor_->Release(); |
| } |
| -TEST_F(VideoProcessorTest, ProcessFrames) { |
| +TEST_F(VideoProcessorTest, ProcessFrames_FixedFramerate) { |
| ExpectInit(); |
| video_processor_->Init(); |
| + const int kBitrateKbps = 456; |
| + const int kFramerateFps = 31; |
| + video_processor_->SetRates(kBitrateKbps, kFramerateFps); |
| + |
| EXPECT_CALL(frame_reader_mock_, ReadFrame()) |
| .WillRepeatedly(Return(I420Buffer::Create(kWidth, kHeight))); |
| - EXPECT_CALL(encoder_mock_, Encode(testing::Property(&VideoFrame::timestamp, |
| - 1 * 90000 / kFramerate), |
| - _, _)) |
| + EXPECT_CALL(encoder_mock_, |
| + Encode(testing::Property(&VideoFrame::timestamp, |
| + 1 * 90000 / kFramerateFps), |
| + _, _)) |
| .Times(1); |
| video_processor_->ProcessFrame(0); |
| - EXPECT_CALL(encoder_mock_, Encode(testing::Property(&VideoFrame::timestamp, |
| - 2 * 90000 / kFramerate), |
| - _, _)) |
| + EXPECT_CALL(encoder_mock_, |
| + Encode(testing::Property(&VideoFrame::timestamp, |
| + 2 * 90000 / kFramerateFps), |
| + _, _)) |
| .Times(1); |
| video_processor_->ProcessFrame(1); |
| + |
| + ExpectRelease(); |
| + video_processor_->Release(); |
| +} |
| + |
| +TEST_F(VideoProcessorTest, ProcessFrames_VariableFramerate) { |
| + ExpectInit(); |
| + video_processor_->Init(); |
| + |
| + const int kBitrateKbps = 456; |
| + const int kStartFramerateFps = 27; |
| + video_processor_->SetRates(kBitrateKbps, kStartFramerateFps); |
| + |
| + EXPECT_CALL(frame_reader_mock_, ReadFrame()) |
| + .WillRepeatedly(Return(I420Buffer::Create(kWidth, kHeight))); |
| + EXPECT_CALL(encoder_mock_, |
| + Encode(testing::Property(&VideoFrame::timestamp, |
| + 1 * 90000 / kStartFramerateFps), |
| + _, _)) |
| + .Times(1); |
| + video_processor_->ProcessFrame(0); |
| + |
| + const int kNewFramerateFps = 13; |
| + video_processor_->SetRates(kBitrateKbps, kNewFramerateFps); |
| + |
| + EXPECT_CALL(encoder_mock_, |
| + Encode(testing::Property(&VideoFrame::timestamp, |
| + 2 * 90000 / kNewFramerateFps), |
| + _, _)) |
| + .Times(1); |
| + video_processor_->ProcessFrame(1); |
| + |
| + ExpectRelease(); |
| + video_processor_->Release(); |
| +} |
| + |
| +TEST_F(VideoProcessorTest, SetRates) { |
| + ExpectInit(); |
| + video_processor_->Init(); |
| + |
| + const int kBitrateKbps = 123; |
| + const int kFramerateFps = 17; |
| + EXPECT_CALL( |
| + encoder_mock_, |
| + SetRateAllocation( |
| + testing::Property(&BitrateAllocation::get_sum_kbps, kBitrateKbps), |
| + kFramerateFps)) |
| + .Times(1); |
| + video_processor_->SetRates(kBitrateKbps, kFramerateFps); |
| + ASSERT_EQ(1u, video_processor_->NumberDroppedFramesPerRateUpdate().size()); |
| + EXPECT_EQ(0, video_processor_->NumberDroppedFramesPerRateUpdate()[0]); |
|
åsapersson
2017/08/29 13:42:33
maybe EXPECT_THAT(video_processor_->NumberDroppedF
brandtr
2017/08/30 11:44:26
Done.
|
| + ASSERT_EQ(1u, video_processor_->NumberSpatialResizesPerRateUpdate().size()); |
| + EXPECT_EQ(0, video_processor_->NumberSpatialResizesPerRateUpdate()[0]); |
| + |
| + const int kNewBitrateKbps = 456; |
| + const int kNewFramerateFps = 34; |
| + EXPECT_CALL( |
| + encoder_mock_, |
| + SetRateAllocation( |
| + testing::Property(&BitrateAllocation::get_sum_kbps, kNewBitrateKbps), |
| + kNewFramerateFps)) |
| + .Times(1); |
| + video_processor_->SetRates(kNewBitrateKbps, kNewFramerateFps); |
| + ASSERT_EQ(2u, video_processor_->NumberDroppedFramesPerRateUpdate().size()); |
| + EXPECT_EQ(0, video_processor_->NumberDroppedFramesPerRateUpdate()[1]); |
| + ASSERT_EQ(2u, video_processor_->NumberSpatialResizesPerRateUpdate().size()); |
| + EXPECT_EQ(0, video_processor_->NumberSpatialResizesPerRateUpdate()[1]); |
| + |
| + ExpectRelease(); |
| + video_processor_->Release(); |
| } |
| } // namespace test |