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

Side by Side Diff: webrtc/modules/video_coding/codecs/test/videoprocessor_unittest.cc

Issue 2997283002: VideoProcessorIntegrationTest: make it runnable on a task queue. (Closed)
Patch Set: Created 3 years, 4 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
« no previous file with comments | « webrtc/modules/video_coding/codecs/test/videoprocessor_integrationtest.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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;
30 using ::testing::Return; 31 using ::testing::Return;
31 32
32 namespace webrtc { 33 namespace webrtc {
33 namespace test { 34 namespace test {
34 35
35 namespace { 36 namespace {
36 37
37 const int kWidth = 352; 38 const int kWidth = 352;
38 const int kHeight = 288; 39 const int kHeight = 288;
39 const int kFrameSize = kWidth * kHeight * 3 / 2; // I420. 40 const int kFrameSize = kWidth * kHeight * 3 / 2; // I420.
40 const int kFramerate = 30;
41 const int kNumFrames = 2; 41 const int kNumFrames = 2;
42 42
43 } // namespace 43 } // namespace
44 44
45 class VideoProcessorTest : public testing::Test { 45 class VideoProcessorTest : public testing::Test {
46 protected: 46 protected:
47 VideoProcessorTest() { 47 VideoProcessorTest() {
48 // Get a codec configuration struct and configure it. 48 // Get a codec configuration struct and configure it.
49 webrtc::test::CodecSettings(kVideoCodecVP8, &config_.codec_settings); 49 webrtc::test::CodecSettings(kVideoCodecVP8, &config_.codec_settings);
50 config_.codec_settings.width = kWidth; 50 config_.codec_settings.width = kWidth;
51 config_.codec_settings.height = kHeight; 51 config_.codec_settings.height = kHeight;
52 config_.codec_settings.maxFramerate = kFramerate; 52 }
53 53
54 void CreateVideoProcessor() {
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(); 91 CreateVideoProcessor();
86 video_processor_->Init();
87 }
88 92
89 TEST_F(VideoProcessorTest, ProcessFrames) {
90 ExpectInit(); 93 ExpectInit();
91 video_processor_->Init(); 94 video_processor_->Init();
92 95
96 ExpectRelease();
97 video_processor_->Release();
98 }
99
100 TEST_F(VideoProcessorTest, ProcessFrames_30fps) {
101 CreateVideoProcessor();
102
103 ExpectInit();
104 video_processor_->Init();
105
106 const int kBitrateKbps = 456;
107 const int kFramerateFps = 30;
108 video_processor_->SetRates(kBitrateKbps, kFramerateFps);
109
93 EXPECT_CALL(frame_reader_mock_, ReadFrame()) 110 EXPECT_CALL(frame_reader_mock_, ReadFrame())
94 .WillRepeatedly(Return(I420Buffer::Create(kWidth, kHeight))); 111 .WillRepeatedly(Return(I420Buffer::Create(kWidth, kHeight)));
95 EXPECT_CALL(encoder_mock_, Encode(testing::Property(&VideoFrame::timestamp, 112 EXPECT_CALL(encoder_mock_,
96 1 * 90000 / kFramerate), 113 Encode(testing::Property(&VideoFrame::timestamp,
97 _, _)) 114 1 * 90000 / kFramerateFps),
115 _, _))
98 .Times(1); 116 .Times(1);
99 video_processor_->ProcessFrame(0); 117 video_processor_->ProcessFrame(0);
100 118
101 EXPECT_CALL(encoder_mock_, Encode(testing::Property(&VideoFrame::timestamp, 119 EXPECT_CALL(encoder_mock_,
102 2 * 90000 / kFramerate), 120 Encode(testing::Property(&VideoFrame::timestamp,
103 _, _)) 121 2 * 90000 / kFramerateFps),
122 _, _))
104 .Times(1); 123 .Times(1);
105 video_processor_->ProcessFrame(1); 124 video_processor_->ProcessFrame(1);
125
126 ExpectRelease();
127 video_processor_->Release();
128 }
129
130 TEST_F(VideoProcessorTest, ProcessFrames_15fps) {
131 CreateVideoProcessor();
132
133 ExpectInit();
134 video_processor_->Init();
135
136 const int kBitrateKbps = 456;
137 const int kFramerateFps = 15;
138 video_processor_->SetRates(kBitrateKbps, kFramerateFps);
139
140 EXPECT_CALL(frame_reader_mock_, ReadFrame())
141 .WillRepeatedly(Return(I420Buffer::Create(kWidth, kHeight)));
142 EXPECT_CALL(encoder_mock_,
143 Encode(testing::Property(&VideoFrame::timestamp,
144 1 * 90000 / kFramerateFps),
145 _, _))
146 .Times(1);
147 video_processor_->ProcessFrame(0);
148
149 EXPECT_CALL(encoder_mock_,
150 Encode(testing::Property(&VideoFrame::timestamp,
151 2 * 90000 / kFramerateFps),
152 _, _))
153 .Times(1);
154 video_processor_->ProcessFrame(1);
155
156 ExpectRelease();
157 video_processor_->Release();
158 }
159
160 TEST_F(VideoProcessorTest, ProcessFrames_VariableFramerate) {
161 CreateVideoProcessor();
162
163 ExpectInit();
164 video_processor_->Init();
165
166 const int kBitrateKbps = 456;
167 const int kStartFramerateFps = 27;
168 video_processor_->SetRates(kBitrateKbps, kStartFramerateFps);
169
170 EXPECT_CALL(frame_reader_mock_, ReadFrame())
171 .WillRepeatedly(Return(I420Buffer::Create(kWidth, kHeight)));
172 EXPECT_CALL(encoder_mock_,
173 Encode(testing::Property(&VideoFrame::timestamp,
174 1 * 90000 / kStartFramerateFps),
175 _, _))
176 .Times(1);
177 video_processor_->ProcessFrame(0);
178
179 const int kNewFramerateFps = 13;
180 video_processor_->SetRates(kBitrateKbps, kNewFramerateFps);
181
182 EXPECT_CALL(encoder_mock_,
183 Encode(testing::Property(&VideoFrame::timestamp,
184 2 * 90000 / kNewFramerateFps),
185 _, _))
186 .Times(1);
187 video_processor_->ProcessFrame(1);
188
189 ExpectRelease();
190 video_processor_->Release();
191 }
192
193 TEST_F(VideoProcessorTest, SetRates) {
194 CreateVideoProcessor();
195 ExpectInit();
196 video_processor_->Init();
197
198 const int kBitrateKbps = 123;
199 const int kFramerateFps = 17;
200 EXPECT_CALL(
201 encoder_mock_,
202 SetRateAllocation(
203 testing::Property(&BitrateAllocation::get_sum_kbps, kBitrateKbps),
204 kFramerateFps))
205 .Times(1);
206 video_processor_->SetRates(kBitrateKbps, kFramerateFps);
207 ASSERT_EQ(1u, video_processor_->NumberDroppedFramesPerRateUpdate().size());
208 EXPECT_EQ(0, video_processor_->NumberDroppedFramesPerRateUpdate()[0]);
209 ASSERT_EQ(1u, video_processor_->NumberSpatialResizesPerRateUpdate().size());
210 EXPECT_EQ(0, video_processor_->NumberSpatialResizesPerRateUpdate()[0]);
211
212 const int kNewBitrateKbps = 456;
213 const int kNewFramerateFps = 34;
214 EXPECT_CALL(
215 encoder_mock_,
216 SetRateAllocation(
217 testing::Property(&BitrateAllocation::get_sum_kbps, kNewBitrateKbps),
218 kNewFramerateFps))
219 .Times(1);
220 video_processor_->SetRates(kNewBitrateKbps, kNewFramerateFps);
221 ASSERT_EQ(2u, video_processor_->NumberDroppedFramesPerRateUpdate().size());
222 EXPECT_EQ(0, video_processor_->NumberDroppedFramesPerRateUpdate()[1]);
223 ASSERT_EQ(2u, video_processor_->NumberSpatialResizesPerRateUpdate().size());
224 EXPECT_EQ(0, video_processor_->NumberSpatialResizesPerRateUpdate()[1]);
106 } 225 }
107 226
108 } // namespace test 227 } // namespace test
109 } // namespace webrtc 228 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/modules/video_coding/codecs/test/videoprocessor_integrationtest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698