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

Side by Side Diff: webrtc/video/vie_encoder_unittest.cc

Issue 2257413002: Replace interface VideoCapturerInput with VideoSinkInterface. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Fix EXPECT_GT order. Created 4 years, 3 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
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2016 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 "testing/gtest/include/gtest/gtest.h" 11 #include "testing/gtest/include/gtest/gtest.h"
12 #include "webrtc/base/logging.h" 12 #include "webrtc/base/logging.h"
13 #include "webrtc/test/encoder_settings.h" 13 #include "webrtc/test/encoder_settings.h"
14 #include "webrtc/test/fake_encoder.h" 14 #include "webrtc/test/fake_encoder.h"
15 #include "webrtc/test/frame_generator.h"
15 #include "webrtc/video/send_statistics_proxy.h" 16 #include "webrtc/video/send_statistics_proxy.h"
16 #include "webrtc/video/vie_encoder.h" 17 #include "webrtc/video/vie_encoder.h"
17 18
18 namespace webrtc { 19 namespace webrtc {
19 20
20 class ViEEncoderTest : public ::testing::Test { 21 class ViEEncoderTest : public ::testing::Test {
21 public: 22 public:
22 static const int kDefaultTimeoutMs = 30 * 1000; 23 static const int kDefaultTimeoutMs = 30 * 1000;
23 24
24 ViEEncoderTest() 25 ViEEncoderTest()
(...skipping 10 matching lines...) Expand all
35 video_send_config_.encoder_settings.payload_name = "FAKE"; 36 video_send_config_.encoder_settings.payload_name = "FAKE";
36 video_send_config_.encoder_settings.payload_type = 125; 37 video_send_config_.encoder_settings.payload_type = 125;
37 38
38 video_encoder_config_.streams = test::CreateVideoStreams(1); 39 video_encoder_config_.streams = test::CreateVideoStreams(1);
39 40
40 vie_encoder_.reset(new ViEEncoder( 41 vie_encoder_.reset(new ViEEncoder(
41 1 /* number_of_cores */, &stats_proxy_, 42 1 /* number_of_cores */, &stats_proxy_,
42 video_send_config_.encoder_settings, nullptr /* pre_encode_callback */, 43 video_send_config_.encoder_settings, nullptr /* pre_encode_callback */,
43 nullptr /* overuse_callback */, nullptr /* encoder_timing */)); 44 nullptr /* overuse_callback */, nullptr /* encoder_timing */));
44 vie_encoder_->SetSink(&sink_); 45 vie_encoder_->SetSink(&sink_);
46 vie_encoder_->SetSource(&forwarder_);
45 vie_encoder_->SetStartBitrate(10000); 47 vie_encoder_->SetStartBitrate(10000);
46 vie_encoder_->ConfigureEncoder(video_encoder_config_, 1440); 48 vie_encoder_->ConfigureEncoder(video_encoder_config_, 1440);
47 } 49 }
48 50
49 VideoFrame CreateFrame(int64_t ntp_ts, rtc::Event* destruction_event) const { 51 VideoFrame CreateFrame(int64_t ntp_ts, rtc::Event* destruction_event) const {
50 class TestBuffer : public webrtc::I420Buffer { 52 class TestBuffer : public webrtc::I420Buffer {
51 public: 53 public:
52 TestBuffer(rtc::Event* event, int width, int height) 54 TestBuffer(rtc::Event* event, int width, int height)
53 : I420Buffer(width, height), event_(event) {} 55 : I420Buffer(width, height), event_(event) {}
54 56
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
157 rtc::Event encoded_frame_event_; 159 rtc::Event encoded_frame_event_;
158 uint32_t timestamp_ = 0; 160 uint32_t timestamp_ = 0;
159 bool expect_frames_ = true; 161 bool expect_frames_ = true;
160 }; 162 };
161 163
162 VideoSendStream::Config video_send_config_; 164 VideoSendStream::Config video_send_config_;
163 VideoEncoderConfig video_encoder_config_; 165 VideoEncoderConfig video_encoder_config_;
164 TestEncoder fake_encoder_; 166 TestEncoder fake_encoder_;
165 SendStatisticsProxy stats_proxy_; 167 SendStatisticsProxy stats_proxy_;
166 TestSink sink_; 168 TestSink sink_;
169 test::FrameForwarder forwarder_;
167 std::unique_ptr<ViEEncoder> vie_encoder_; 170 std::unique_ptr<ViEEncoder> vie_encoder_;
168 }; 171 };
169 172
170 TEST_F(ViEEncoderTest, EncodeOneFrame) { 173 TEST_F(ViEEncoderTest, EncodeOneFrame) {
171 const int kTargetBitrateBps = 100000; 174 const int kTargetBitrateBps = 100000;
172 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); 175 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0);
173 rtc::Event frame_destroyed_event(false, false); 176 rtc::Event frame_destroyed_event(false, false);
174 vie_encoder_->IncomingCapturedFrame(CreateFrame(1, &frame_destroyed_event)); 177 forwarder_.IncomingCapturedFrame(CreateFrame(1, &frame_destroyed_event));
175 sink_.WaitForEncodedFrame(1); 178 sink_.WaitForEncodedFrame(1);
176 frame_destroyed_event.Wait(kDefaultTimeoutMs); 179 frame_destroyed_event.Wait(kDefaultTimeoutMs);
177 vie_encoder_->Stop(); 180 vie_encoder_->Stop();
178 } 181 }
179 182
180 TEST_F(ViEEncoderTest, DropsFramesBeforeFirstOnBitrateUpdated) { 183 TEST_F(ViEEncoderTest, DropsFramesBeforeFirstOnBitrateUpdated) {
181 // Dropped since no target bitrate has been set. 184 // Dropped since no target bitrate has been set.
182 rtc::Event frame_destroyed_event(false, false); 185 rtc::Event frame_destroyed_event(false, false);
183 vie_encoder_->IncomingCapturedFrame(CreateFrame(1, &frame_destroyed_event)); 186 forwarder_.IncomingCapturedFrame(CreateFrame(1, &frame_destroyed_event));
184 frame_destroyed_event.Wait(kDefaultTimeoutMs); 187 frame_destroyed_event.Wait(kDefaultTimeoutMs);
185 188
186 const int kTargetBitrateBps = 100000; 189 const int kTargetBitrateBps = 100000;
187 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); 190 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0);
188 191
189 vie_encoder_->IncomingCapturedFrame(CreateFrame(2, nullptr)); 192 forwarder_.IncomingCapturedFrame(CreateFrame(2, nullptr));
190 sink_.WaitForEncodedFrame(2); 193 sink_.WaitForEncodedFrame(2);
191 vie_encoder_->Stop(); 194 vie_encoder_->Stop();
192 } 195 }
193 196
194 TEST_F(ViEEncoderTest, DropsFramesWhenRateSetToZero) { 197 TEST_F(ViEEncoderTest, DropsFramesWhenRateSetToZero) {
195 const int kTargetBitrateBps = 100000; 198 const int kTargetBitrateBps = 100000;
196 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); 199 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0);
197 vie_encoder_->IncomingCapturedFrame(CreateFrame(1, nullptr)); 200 forwarder_.IncomingCapturedFrame(CreateFrame(1, nullptr));
198 sink_.WaitForEncodedFrame(1); 201 sink_.WaitForEncodedFrame(1);
199 202
200 vie_encoder_->OnBitrateUpdated(0, 0, 0); 203 vie_encoder_->OnBitrateUpdated(0, 0, 0);
201 // Dropped since bitrate is zero. 204 // Dropped since bitrate is zero.
202 vie_encoder_->IncomingCapturedFrame(CreateFrame(2, nullptr)); 205 forwarder_.IncomingCapturedFrame(CreateFrame(1, nullptr));
206 forwarder_.IncomingCapturedFrame(CreateFrame(2, nullptr));
stefan-webrtc 2016/09/06 12:24:38 The test is changed here. Can you comment on why?
perkj_webrtc 2016/09/07 15:10:37 oops. Thanks- its a mistake.
203 207
204 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); 208 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0);
205 vie_encoder_->IncomingCapturedFrame(CreateFrame(3, nullptr)); 209 forwarder_.IncomingCapturedFrame(CreateFrame(3, nullptr));
206 sink_.WaitForEncodedFrame(3); 210 sink_.WaitForEncodedFrame(3);
207 vie_encoder_->Stop(); 211 vie_encoder_->Stop();
208 } 212 }
209 213
210 TEST_F(ViEEncoderTest, DropsFramesWithSameOrOldNtpTimestamp) { 214 TEST_F(ViEEncoderTest, DropsFramesWithSameOrOldNtpTimestamp) {
211 const int kTargetBitrateBps = 100000; 215 const int kTargetBitrateBps = 100000;
212 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); 216 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0);
213 vie_encoder_->IncomingCapturedFrame(CreateFrame(1, nullptr)); 217 forwarder_.IncomingCapturedFrame(CreateFrame(1, nullptr));
214 sink_.WaitForEncodedFrame(1); 218 sink_.WaitForEncodedFrame(1);
215 219
216 // This frame will be dropped since it has the same ntp timestamp. 220 // This frame will be dropped since it has the same ntp timestamp.
217 vie_encoder_->IncomingCapturedFrame(CreateFrame(1, nullptr)); 221 forwarder_.IncomingCapturedFrame(CreateFrame(1, nullptr));
218 222
219 vie_encoder_->IncomingCapturedFrame(CreateFrame(2, nullptr)); 223 forwarder_.IncomingCapturedFrame(CreateFrame(2, nullptr));
220 sink_.WaitForEncodedFrame(2); 224 sink_.WaitForEncodedFrame(2);
221 vie_encoder_->Stop(); 225 vie_encoder_->Stop();
222 } 226 }
223 227
224 TEST_F(ViEEncoderTest, DropsFrameAfterStop) { 228 TEST_F(ViEEncoderTest, DropsFrameAfterStop) {
225 const int kTargetBitrateBps = 100000; 229 const int kTargetBitrateBps = 100000;
226 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); 230 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0);
227 231
228 vie_encoder_->IncomingCapturedFrame(CreateFrame(1, nullptr)); 232 forwarder_.IncomingCapturedFrame(CreateFrame(1, nullptr));
229 sink_.WaitForEncodedFrame(1); 233 sink_.WaitForEncodedFrame(1);
230 234
231 vie_encoder_->Stop(); 235 vie_encoder_->Stop();
232 sink_.SetExpectNoFrames(); 236 sink_.SetExpectNoFrames();
233 rtc::Event frame_destroyed_event(false, false); 237 rtc::Event frame_destroyed_event(false, false);
234 vie_encoder_->IncomingCapturedFrame(CreateFrame(2, &frame_destroyed_event)); 238 forwarder_.IncomingCapturedFrame(CreateFrame(2, nullptr));
perkj_webrtc 2016/09/07 15:10:37 I also noticed this mistake that passed the unitte
235 frame_destroyed_event.Wait(kDefaultTimeoutMs); 239 frame_destroyed_event.Wait(kDefaultTimeoutMs);
236 } 240 }
237 241
238 TEST_F(ViEEncoderTest, DropsPendingFramesOnSlowEncode) { 242 TEST_F(ViEEncoderTest, DropsPendingFramesOnSlowEncode) {
239 const int kTargetBitrateBps = 100000; 243 const int kTargetBitrateBps = 100000;
240 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); 244 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0);
241 245
242 fake_encoder_.BlockNextEncode(); 246 fake_encoder_.BlockNextEncode();
243 vie_encoder_->IncomingCapturedFrame(CreateFrame(1, nullptr)); 247 forwarder_.IncomingCapturedFrame(CreateFrame(1, nullptr));
244 sink_.WaitForEncodedFrame(1); 248 sink_.WaitForEncodedFrame(1);
245 // Here, the encoder thread will be blocked in the TestEncoder waiting for a 249 // Here, the encoder thread will be blocked in the TestEncoder waiting for a
246 // call to ContinueEncode. 250 // call to ContinueEncode.
247 vie_encoder_->IncomingCapturedFrame(CreateFrame(2, nullptr)); 251 forwarder_.IncomingCapturedFrame(CreateFrame(2, nullptr));
248 vie_encoder_->IncomingCapturedFrame(CreateFrame(3, nullptr)); 252 forwarder_.IncomingCapturedFrame(CreateFrame(3, nullptr));
249 fake_encoder_.ContinueEncode(); 253 fake_encoder_.ContinueEncode();
250 sink_.WaitForEncodedFrame(3); 254 sink_.WaitForEncodedFrame(3);
251 255
252 vie_encoder_->Stop(); 256 vie_encoder_->Stop();
253 } 257 }
254 258
255 } // namespace webrtc 259 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698