OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
11 #include <memory> | 11 #include <memory> |
12 | 12 |
13 #include "webrtc/api/video/i420_buffer.h" | 13 #include "webrtc/api/video/i420_buffer.h" |
| 14 #include "webrtc/common_types.h" |
14 #include "webrtc/modules/video_coding/codecs/test/mock/mock_packet_manipulator.h
" | 15 #include "webrtc/modules/video_coding/codecs/test/mock/mock_packet_manipulator.h
" |
15 #include "webrtc/modules/video_coding/codecs/test/videoprocessor.h" | 16 #include "webrtc/modules/video_coding/codecs/test/videoprocessor.h" |
16 #include "webrtc/modules/video_coding/include/mock/mock_video_codec_interface.h" | 17 #include "webrtc/modules/video_coding/include/mock/mock_video_codec_interface.h" |
17 #include "webrtc/modules/video_coding/include/video_coding.h" | 18 #include "webrtc/modules/video_coding/include/video_coding.h" |
18 #include "webrtc/rtc_base/ptr_util.h" | 19 #include "webrtc/rtc_base/ptr_util.h" |
19 #include "webrtc/test/gmock.h" | 20 #include "webrtc/test/gmock.h" |
20 #include "webrtc/test/gtest.h" | 21 #include "webrtc/test/gtest.h" |
21 #include "webrtc/test/testsupport/mock/mock_frame_reader.h" | 22 #include "webrtc/test/testsupport/mock/mock_frame_reader.h" |
22 #include "webrtc/test/testsupport/mock/mock_frame_writer.h" | 23 #include "webrtc/test/testsupport/mock/mock_frame_writer.h" |
23 #include "webrtc/test/testsupport/packet_reader.h" | 24 #include "webrtc/test/testsupport/packet_reader.h" |
24 #include "webrtc/test/testsupport/unittest_utils.h" | 25 #include "webrtc/test/testsupport/unittest_utils.h" |
25 #include "webrtc/test/video_codec_settings.h" | 26 #include "webrtc/test/video_codec_settings.h" |
26 #include "webrtc/typedefs.h" | 27 #include "webrtc/typedefs.h" |
27 | 28 |
28 using ::testing::_; | 29 using ::testing::_; |
29 using ::testing::AtLeast; | 30 using ::testing::AtLeast; |
| 31 using ::testing::ElementsAre; |
| 32 using ::testing::Property; |
30 using ::testing::Return; | 33 using ::testing::Return; |
31 | 34 |
32 namespace webrtc { | 35 namespace webrtc { |
33 namespace test { | 36 namespace test { |
34 | 37 |
35 namespace { | 38 namespace { |
36 | 39 |
37 const int kWidth = 352; | 40 const int kWidth = 352; |
38 const int kHeight = 288; | 41 const int kHeight = 288; |
39 const int kFrameSize = kWidth * kHeight * 3 / 2; // I420. | 42 const int kFrameSize = kWidth * kHeight * 3 / 2; // I420. |
40 const int kFramerate = 30; | |
41 const int kNumFrames = 2; | 43 const int kNumFrames = 2; |
42 | 44 |
43 } // namespace | 45 } // namespace |
44 | 46 |
45 class VideoProcessorTest : public testing::Test { | 47 class VideoProcessorTest : public testing::Test { |
46 protected: | 48 protected: |
47 VideoProcessorTest() { | 49 VideoProcessorTest() { |
48 // Get a codec configuration struct and configure it. | 50 // Get a codec configuration struct and configure it. |
49 webrtc::test::CodecSettings(kVideoCodecVP8, &config_.codec_settings); | 51 webrtc::test::CodecSettings(kVideoCodecVP8, &config_.codec_settings); |
50 config_.codec_settings.width = kWidth; | 52 config_.codec_settings.width = kWidth; |
51 config_.codec_settings.height = kHeight; | 53 config_.codec_settings.height = kHeight; |
52 config_.codec_settings.maxFramerate = kFramerate; | |
53 | 54 |
54 EXPECT_CALL(frame_reader_mock_, NumberOfFrames()) | 55 EXPECT_CALL(frame_reader_mock_, NumberOfFrames()) |
55 .WillRepeatedly(Return(kNumFrames)); | 56 .WillRepeatedly(Return(kNumFrames)); |
56 EXPECT_CALL(frame_reader_mock_, FrameLength()) | 57 EXPECT_CALL(frame_reader_mock_, FrameLength()) |
57 .WillRepeatedly(Return(kFrameSize)); | 58 .WillRepeatedly(Return(kFrameSize)); |
58 video_processor_ = rtc::MakeUnique<VideoProcessor>( | 59 video_processor_ = rtc::MakeUnique<VideoProcessor>( |
59 &encoder_mock_, &decoder_mock_, &frame_reader_mock_, | 60 &encoder_mock_, &decoder_mock_, &frame_reader_mock_, |
60 &frame_writer_mock_, &packet_manipulator_mock_, config_, &stats_, | 61 &frame_writer_mock_, &packet_manipulator_mock_, config_, &stats_, |
61 nullptr /* encoded_frame_writer */, nullptr /* decoded_frame_writer */); | 62 nullptr /* encoded_frame_writer */, nullptr /* decoded_frame_writer */); |
62 } | 63 } |
63 | 64 |
64 void ExpectInit() { | 65 void ExpectInit() { |
65 EXPECT_CALL(encoder_mock_, InitEncode(_, _, _)).Times(1); | 66 EXPECT_CALL(encoder_mock_, InitEncode(_, _, _)).Times(1); |
66 EXPECT_CALL(encoder_mock_, RegisterEncodeCompleteCallback(_)) | 67 EXPECT_CALL(encoder_mock_, RegisterEncodeCompleteCallback(_)).Times(1); |
67 .Times(AtLeast(1)); | |
68 EXPECT_CALL(decoder_mock_, InitDecode(_, _)).Times(1); | 68 EXPECT_CALL(decoder_mock_, InitDecode(_, _)).Times(1); |
69 EXPECT_CALL(decoder_mock_, RegisterDecodeCompleteCallback(_)) | 69 EXPECT_CALL(decoder_mock_, RegisterDecodeCompleteCallback(_)).Times(1); |
70 .Times(AtLeast(1)); | 70 } |
| 71 |
| 72 void ExpectRelease() { |
| 73 EXPECT_CALL(encoder_mock_, Release()).Times(1); |
| 74 EXPECT_CALL(encoder_mock_, RegisterEncodeCompleteCallback(_)).Times(1); |
| 75 EXPECT_CALL(decoder_mock_, Release()).Times(1); |
| 76 EXPECT_CALL(decoder_mock_, RegisterDecodeCompleteCallback(_)).Times(1); |
71 } | 77 } |
72 | 78 |
73 TestConfig config_; | 79 TestConfig config_; |
74 | 80 |
75 MockVideoEncoder encoder_mock_; | 81 MockVideoEncoder encoder_mock_; |
76 MockVideoDecoder decoder_mock_; | 82 MockVideoDecoder decoder_mock_; |
77 MockFrameReader frame_reader_mock_; | 83 MockFrameReader frame_reader_mock_; |
78 MockFrameWriter frame_writer_mock_; | 84 MockFrameWriter frame_writer_mock_; |
79 MockPacketManipulator packet_manipulator_mock_; | 85 MockPacketManipulator packet_manipulator_mock_; |
80 Stats stats_; | 86 Stats stats_; |
81 std::unique_ptr<VideoProcessor> video_processor_; | 87 std::unique_ptr<VideoProcessor> video_processor_; |
82 }; | 88 }; |
83 | 89 |
84 TEST_F(VideoProcessorTest, Init) { | 90 TEST_F(VideoProcessorTest, InitRelease) { |
85 ExpectInit(); | |
86 video_processor_->Init(); | |
87 } | |
88 | |
89 TEST_F(VideoProcessorTest, ProcessFrames) { | |
90 ExpectInit(); | 91 ExpectInit(); |
91 video_processor_->Init(); | 92 video_processor_->Init(); |
92 | 93 |
| 94 ExpectRelease(); |
| 95 video_processor_->Release(); |
| 96 } |
| 97 |
| 98 TEST_F(VideoProcessorTest, ProcessFrames_FixedFramerate) { |
| 99 ExpectInit(); |
| 100 video_processor_->Init(); |
| 101 |
| 102 const int kBitrateKbps = 456; |
| 103 const int kFramerateFps = 31; |
| 104 video_processor_->SetRates(kBitrateKbps, kFramerateFps); |
| 105 |
93 EXPECT_CALL(frame_reader_mock_, ReadFrame()) | 106 EXPECT_CALL(frame_reader_mock_, ReadFrame()) |
94 .WillRepeatedly(Return(I420Buffer::Create(kWidth, kHeight))); | 107 .WillRepeatedly(Return(I420Buffer::Create(kWidth, kHeight))); |
95 EXPECT_CALL(encoder_mock_, Encode(testing::Property(&VideoFrame::timestamp, | 108 EXPECT_CALL( |
96 1 * 90000 / kFramerate), | 109 encoder_mock_, |
| 110 Encode(Property(&VideoFrame::timestamp, 1 * 90000 / kFramerateFps), _, _)) |
| 111 .Times(1); |
| 112 video_processor_->ProcessFrame(0); |
| 113 |
| 114 EXPECT_CALL( |
| 115 encoder_mock_, |
| 116 Encode(Property(&VideoFrame::timestamp, 2 * 90000 / kFramerateFps), _, _)) |
| 117 .Times(1); |
| 118 video_processor_->ProcessFrame(1); |
| 119 |
| 120 ExpectRelease(); |
| 121 video_processor_->Release(); |
| 122 } |
| 123 |
| 124 TEST_F(VideoProcessorTest, ProcessFrames_VariableFramerate) { |
| 125 ExpectInit(); |
| 126 video_processor_->Init(); |
| 127 |
| 128 const int kBitrateKbps = 456; |
| 129 const int kStartFramerateFps = 27; |
| 130 video_processor_->SetRates(kBitrateKbps, kStartFramerateFps); |
| 131 |
| 132 EXPECT_CALL(frame_reader_mock_, ReadFrame()) |
| 133 .WillRepeatedly(Return(I420Buffer::Create(kWidth, kHeight))); |
| 134 EXPECT_CALL(encoder_mock_, Encode(Property(&VideoFrame::timestamp, |
| 135 1 * 90000 / kStartFramerateFps), |
97 _, _)) | 136 _, _)) |
98 .Times(1); | 137 .Times(1); |
99 video_processor_->ProcessFrame(0); | 138 video_processor_->ProcessFrame(0); |
100 | 139 |
101 EXPECT_CALL(encoder_mock_, Encode(testing::Property(&VideoFrame::timestamp, | 140 const int kNewFramerateFps = 13; |
102 2 * 90000 / kFramerate), | 141 video_processor_->SetRates(kBitrateKbps, kNewFramerateFps); |
| 142 |
| 143 EXPECT_CALL(encoder_mock_, Encode(Property(&VideoFrame::timestamp, |
| 144 2 * 90000 / kNewFramerateFps), |
103 _, _)) | 145 _, _)) |
104 .Times(1); | 146 .Times(1); |
105 video_processor_->ProcessFrame(1); | 147 video_processor_->ProcessFrame(1); |
| 148 |
| 149 ExpectRelease(); |
| 150 video_processor_->Release(); |
| 151 } |
| 152 |
| 153 TEST_F(VideoProcessorTest, SetRates) { |
| 154 ExpectInit(); |
| 155 video_processor_->Init(); |
| 156 |
| 157 const int kBitrateKbps = 123; |
| 158 const int kFramerateFps = 17; |
| 159 EXPECT_CALL(encoder_mock_, |
| 160 SetRateAllocation( |
| 161 Property(&BitrateAllocation::get_sum_kbps, kBitrateKbps), |
| 162 kFramerateFps)) |
| 163 .Times(1); |
| 164 video_processor_->SetRates(kBitrateKbps, kFramerateFps); |
| 165 EXPECT_THAT(video_processor_->NumberDroppedFramesPerRateUpdate(), |
| 166 ElementsAre(0)); |
| 167 EXPECT_THAT(video_processor_->NumberSpatialResizesPerRateUpdate(), |
| 168 ElementsAre(0)); |
| 169 |
| 170 const int kNewBitrateKbps = 456; |
| 171 const int kNewFramerateFps = 34; |
| 172 EXPECT_CALL(encoder_mock_, |
| 173 SetRateAllocation( |
| 174 Property(&BitrateAllocation::get_sum_kbps, kNewBitrateKbps), |
| 175 kNewFramerateFps)) |
| 176 .Times(1); |
| 177 video_processor_->SetRates(kNewBitrateKbps, kNewFramerateFps); |
| 178 EXPECT_THAT(video_processor_->NumberDroppedFramesPerRateUpdate(), |
| 179 ElementsAre(0, 0)); |
| 180 EXPECT_THAT(video_processor_->NumberSpatialResizesPerRateUpdate(), |
| 181 ElementsAre(0, 0)); |
| 182 |
| 183 ExpectRelease(); |
| 184 video_processor_->Release(); |
106 } | 185 } |
107 | 186 |
108 } // namespace test | 187 } // namespace test |
109 } // namespace webrtc | 188 } // namespace webrtc |
OLD | NEW |