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

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

Issue 2493893003: Turn off error resilience for vp8 for no temporal layers if nack is enabled. (Closed)
Patch Set: address comments Created 4 years 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/video/vie_encoder.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) 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 <limits> 11 #include <limits>
12 #include <utility> 12 #include <utility>
13 13
14 #include "webrtc/base/logging.h" 14 #include "webrtc/base/logging.h"
15 #include "webrtc/system_wrappers/include/metrics_default.h" 15 #include "webrtc/system_wrappers/include/metrics_default.h"
16 #include "webrtc/test/encoder_settings.h" 16 #include "webrtc/test/encoder_settings.h"
17 #include "webrtc/test/fake_encoder.h" 17 #include "webrtc/test/fake_encoder.h"
18 #include "webrtc/test/frame_generator.h" 18 #include "webrtc/test/frame_generator.h"
19 #include "webrtc/test/gtest.h" 19 #include "webrtc/test/gtest.h"
20 #include "webrtc/video/send_statistics_proxy.h" 20 #include "webrtc/video/send_statistics_proxy.h"
21 #include "webrtc/video/vie_encoder.h" 21 #include "webrtc/video/vie_encoder.h"
22 22
23 namespace webrtc { 23 namespace webrtc {
24 24
25 namespace { 25 namespace {
26 const size_t kMaxPayloadLength = 1440;
27 const int kTargetBitrateBps = 100000;
28
26 class TestBuffer : public webrtc::I420Buffer { 29 class TestBuffer : public webrtc::I420Buffer {
27 public: 30 public:
28 TestBuffer(rtc::Event* event, int width, int height) 31 TestBuffer(rtc::Event* event, int width, int height)
29 : I420Buffer(width, height), event_(event) {} 32 : I420Buffer(width, height), event_(event) {}
30 33
31 private: 34 private:
32 friend class rtc::RefCountedObject<TestBuffer>; 35 friend class rtc::RefCountedObject<TestBuffer>;
33 ~TestBuffer() override { 36 ~TestBuffer() override {
34 if (event_) 37 if (event_)
35 event_->Set(); 38 event_->Set();
(...skipping 24 matching lines...) Expand all
60 void TriggerCpuNormalUsage() { 63 void TriggerCpuNormalUsage() {
61 rtc::Event event(false, false); 64 rtc::Event event(false, false);
62 encoder_queue()->PostTask([this, &event] { 65 encoder_queue()->PostTask([this, &event] {
63 NormalUsage(); 66 NormalUsage();
64 event.Set(); 67 event.Set();
65 }); 68 });
66 event.Wait(rtc::Event::kForever); 69 event.Wait(rtc::Event::kForever);
67 } 70 }
68 }; 71 };
69 72
73 class VideoStreamFactory
74 : public VideoEncoderConfig::VideoStreamFactoryInterface {
75 public:
76 explicit VideoStreamFactory(size_t num_temporal_layers)
77 : num_temporal_layers_(num_temporal_layers) {
78 EXPECT_GT(num_temporal_layers, 0u);
79 }
80
81 private:
82 std::vector<VideoStream> CreateEncoderStreams(
83 int width,
84 int height,
85 const VideoEncoderConfig& encoder_config) override {
86 std::vector<VideoStream> streams =
87 test::CreateVideoStreams(width, height, encoder_config);
88 for (VideoStream& stream : streams) {
89 stream.temporal_layer_thresholds_bps.resize(num_temporal_layers_ - 1);
90 }
91 return streams;
92 }
93 const size_t num_temporal_layers_;
94 };
95
70 } // namespace 96 } // namespace
71 97
72 class ViEEncoderTest : public ::testing::Test { 98 class ViEEncoderTest : public ::testing::Test {
73 public: 99 public:
74 static const int kDefaultTimeoutMs = 30 * 1000; 100 static const int kDefaultTimeoutMs = 30 * 1000;
75 101
76 ViEEncoderTest() 102 ViEEncoderTest()
77 : video_send_config_(VideoSendStream::Config(nullptr)), 103 : video_send_config_(VideoSendStream::Config(nullptr)),
78 codec_width_(320), 104 codec_width_(320),
79 codec_height_(240), 105 codec_height_(240),
80 fake_encoder_(), 106 fake_encoder_(),
81 stats_proxy_(new SendStatisticsProxy( 107 stats_proxy_(new SendStatisticsProxy(
82 Clock::GetRealTimeClock(), 108 Clock::GetRealTimeClock(),
83 video_send_config_, 109 video_send_config_,
84 webrtc::VideoEncoderConfig::ContentType::kRealtimeVideo)), 110 webrtc::VideoEncoderConfig::ContentType::kRealtimeVideo)),
85 sink_(&fake_encoder_) {} 111 sink_(&fake_encoder_) {}
86 112
87 void SetUp() override { 113 void SetUp() override {
88 metrics::Reset(); 114 metrics::Reset();
89 video_send_config_ = VideoSendStream::Config(nullptr); 115 video_send_config_ = VideoSendStream::Config(nullptr);
90 video_send_config_.encoder_settings.encoder = &fake_encoder_; 116 video_send_config_.encoder_settings.encoder = &fake_encoder_;
91 video_send_config_.encoder_settings.payload_name = "FAKE"; 117 video_send_config_.encoder_settings.payload_name = "FAKE";
92 video_send_config_.encoder_settings.payload_type = 125; 118 video_send_config_.encoder_settings.payload_type = 125;
93 119
94 VideoEncoderConfig video_encoder_config; 120 VideoEncoderConfig video_encoder_config;
95 test::FillEncoderConfiguration(1, &video_encoder_config); 121 test::FillEncoderConfiguration(1, &video_encoder_config);
96 video_encoder_config_ = video_encoder_config.Copy(); 122 video_encoder_config_ = video_encoder_config.Copy();
123 ConfigureEncoder(std::move(video_encoder_config), true /* nack_enabled */);
124 }
125
126 void ConfigureEncoder(VideoEncoderConfig video_encoder_config,
127 bool nack_enabled) {
128 if (vie_encoder_)
129 vie_encoder_->Stop();
97 vie_encoder_.reset(new ViEEncoderUnderTest( 130 vie_encoder_.reset(new ViEEncoderUnderTest(
98 stats_proxy_.get(), video_send_config_.encoder_settings)); 131 stats_proxy_.get(), video_send_config_.encoder_settings));
99 vie_encoder_->SetSink(&sink_, false /* rotation_applied */); 132 vie_encoder_->SetSink(&sink_, false /* rotation_applied */);
100 vie_encoder_->SetSource(&video_source_, 133 vie_encoder_->SetSource(&video_source_,
101 VideoSendStream::DegradationPreference::kBalanced); 134 VideoSendStream::DegradationPreference::kBalanced);
102 vie_encoder_->SetStartBitrate(10000); 135 vie_encoder_->SetStartBitrate(10000);
103 vie_encoder_->ConfigureEncoder(std::move(video_encoder_config), 1440); 136 vie_encoder_->ConfigureEncoder(std::move(video_encoder_config),
137 kMaxPayloadLength, nack_enabled);
138 }
139
140 void ResetEncoder(const std::string& payload_name,
141 size_t num_streams,
142 size_t num_temporal_layers,
143 bool nack_enabled) {
144 video_send_config_.encoder_settings.payload_name = payload_name;
145
146 VideoEncoderConfig video_encoder_config;
147 video_encoder_config.number_of_streams = num_streams;
148 video_encoder_config.max_bitrate_bps = 1000000;
149 video_encoder_config.video_stream_factory =
150 new rtc::RefCountedObject<VideoStreamFactory>(num_temporal_layers);
151 ConfigureEncoder(std::move(video_encoder_config), nack_enabled);
104 } 152 }
105 153
106 VideoFrame CreateFrame(int64_t ntp_ts, rtc::Event* destruction_event) const { 154 VideoFrame CreateFrame(int64_t ntp_ts, rtc::Event* destruction_event) const {
107 VideoFrame frame(new rtc::RefCountedObject<TestBuffer>( 155 VideoFrame frame(new rtc::RefCountedObject<TestBuffer>(
108 destruction_event, codec_width_, codec_height_), 156 destruction_event, codec_width_, codec_height_),
109 99, 99, kVideoRotation_0); 157 99, 99, kVideoRotation_0);
110 frame.set_ntp_time_ms(ntp_ts); 158 frame.set_ntp_time_ms(ntp_ts);
111 return frame; 159 return frame;
112 } 160 }
113 161
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
241 int codec_width_; 289 int codec_width_;
242 int codec_height_; 290 int codec_height_;
243 TestEncoder fake_encoder_; 291 TestEncoder fake_encoder_;
244 std::unique_ptr<SendStatisticsProxy> stats_proxy_; 292 std::unique_ptr<SendStatisticsProxy> stats_proxy_;
245 TestSink sink_; 293 TestSink sink_;
246 test::FrameForwarder video_source_; 294 test::FrameForwarder video_source_;
247 std::unique_ptr<ViEEncoderUnderTest> vie_encoder_; 295 std::unique_ptr<ViEEncoderUnderTest> vie_encoder_;
248 }; 296 };
249 297
250 TEST_F(ViEEncoderTest, EncodeOneFrame) { 298 TEST_F(ViEEncoderTest, EncodeOneFrame) {
251 const int kTargetBitrateBps = 100000;
252 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); 299 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0);
253 rtc::Event frame_destroyed_event(false, false); 300 rtc::Event frame_destroyed_event(false, false);
254 video_source_.IncomingCapturedFrame(CreateFrame(1, &frame_destroyed_event)); 301 video_source_.IncomingCapturedFrame(CreateFrame(1, &frame_destroyed_event));
255 sink_.WaitForEncodedFrame(1); 302 sink_.WaitForEncodedFrame(1);
256 EXPECT_TRUE(frame_destroyed_event.Wait(kDefaultTimeoutMs)); 303 EXPECT_TRUE(frame_destroyed_event.Wait(kDefaultTimeoutMs));
257 vie_encoder_->Stop(); 304 vie_encoder_->Stop();
258 } 305 }
259 306
260 TEST_F(ViEEncoderTest, DropsFramesBeforeFirstOnBitrateUpdated) { 307 TEST_F(ViEEncoderTest, DropsFramesBeforeFirstOnBitrateUpdated) {
261 // Dropped since no target bitrate has been set. 308 // Dropped since no target bitrate has been set.
262 rtc::Event frame_destroyed_event(false, false); 309 rtc::Event frame_destroyed_event(false, false);
263 video_source_.IncomingCapturedFrame(CreateFrame(1, &frame_destroyed_event)); 310 video_source_.IncomingCapturedFrame(CreateFrame(1, &frame_destroyed_event));
264 EXPECT_TRUE(frame_destroyed_event.Wait(kDefaultTimeoutMs)); 311 EXPECT_TRUE(frame_destroyed_event.Wait(kDefaultTimeoutMs));
265 312
266 const int kTargetBitrateBps = 100000;
267 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); 313 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0);
268 314
269 video_source_.IncomingCapturedFrame(CreateFrame(2, nullptr)); 315 video_source_.IncomingCapturedFrame(CreateFrame(2, nullptr));
270 sink_.WaitForEncodedFrame(2); 316 sink_.WaitForEncodedFrame(2);
271 vie_encoder_->Stop(); 317 vie_encoder_->Stop();
272 } 318 }
273 319
274 TEST_F(ViEEncoderTest, DropsFramesWhenRateSetToZero) { 320 TEST_F(ViEEncoderTest, DropsFramesWhenRateSetToZero) {
275 const int kTargetBitrateBps = 100000;
276 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); 321 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0);
277 video_source_.IncomingCapturedFrame(CreateFrame(1, nullptr)); 322 video_source_.IncomingCapturedFrame(CreateFrame(1, nullptr));
278 sink_.WaitForEncodedFrame(1); 323 sink_.WaitForEncodedFrame(1);
279 324
280 vie_encoder_->OnBitrateUpdated(0, 0, 0); 325 vie_encoder_->OnBitrateUpdated(0, 0, 0);
281 // Dropped since bitrate is zero. 326 // Dropped since bitrate is zero.
282 video_source_.IncomingCapturedFrame(CreateFrame(2, nullptr)); 327 video_source_.IncomingCapturedFrame(CreateFrame(2, nullptr));
283 328
284 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); 329 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0);
285 video_source_.IncomingCapturedFrame(CreateFrame(3, nullptr)); 330 video_source_.IncomingCapturedFrame(CreateFrame(3, nullptr));
286 sink_.WaitForEncodedFrame(3); 331 sink_.WaitForEncodedFrame(3);
287 vie_encoder_->Stop(); 332 vie_encoder_->Stop();
288 } 333 }
289 334
290 TEST_F(ViEEncoderTest, DropsFramesWithSameOrOldNtpTimestamp) { 335 TEST_F(ViEEncoderTest, DropsFramesWithSameOrOldNtpTimestamp) {
291 const int kTargetBitrateBps = 100000;
292 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); 336 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0);
293 video_source_.IncomingCapturedFrame(CreateFrame(1, nullptr)); 337 video_source_.IncomingCapturedFrame(CreateFrame(1, nullptr));
294 sink_.WaitForEncodedFrame(1); 338 sink_.WaitForEncodedFrame(1);
295 339
296 // This frame will be dropped since it has the same ntp timestamp. 340 // This frame will be dropped since it has the same ntp timestamp.
297 video_source_.IncomingCapturedFrame(CreateFrame(1, nullptr)); 341 video_source_.IncomingCapturedFrame(CreateFrame(1, nullptr));
298 342
299 video_source_.IncomingCapturedFrame(CreateFrame(2, nullptr)); 343 video_source_.IncomingCapturedFrame(CreateFrame(2, nullptr));
300 sink_.WaitForEncodedFrame(2); 344 sink_.WaitForEncodedFrame(2);
301 vie_encoder_->Stop(); 345 vie_encoder_->Stop();
302 } 346 }
303 347
304 TEST_F(ViEEncoderTest, DropsFrameAfterStop) { 348 TEST_F(ViEEncoderTest, DropsFrameAfterStop) {
305 const int kTargetBitrateBps = 100000;
306 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); 349 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0);
307 350
308 video_source_.IncomingCapturedFrame(CreateFrame(1, nullptr)); 351 video_source_.IncomingCapturedFrame(CreateFrame(1, nullptr));
309 sink_.WaitForEncodedFrame(1); 352 sink_.WaitForEncodedFrame(1);
310 353
311 vie_encoder_->Stop(); 354 vie_encoder_->Stop();
312 sink_.SetExpectNoFrames(); 355 sink_.SetExpectNoFrames();
313 rtc::Event frame_destroyed_event(false, false); 356 rtc::Event frame_destroyed_event(false, false);
314 video_source_.IncomingCapturedFrame(CreateFrame(2, &frame_destroyed_event)); 357 video_source_.IncomingCapturedFrame(CreateFrame(2, &frame_destroyed_event));
315 EXPECT_TRUE(frame_destroyed_event.Wait(kDefaultTimeoutMs)); 358 EXPECT_TRUE(frame_destroyed_event.Wait(kDefaultTimeoutMs));
316 } 359 }
317 360
318 TEST_F(ViEEncoderTest, DropsPendingFramesOnSlowEncode) { 361 TEST_F(ViEEncoderTest, DropsPendingFramesOnSlowEncode) {
319 const int kTargetBitrateBps = 100000;
320 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); 362 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0);
321 363
322 fake_encoder_.BlockNextEncode(); 364 fake_encoder_.BlockNextEncode();
323 video_source_.IncomingCapturedFrame(CreateFrame(1, nullptr)); 365 video_source_.IncomingCapturedFrame(CreateFrame(1, nullptr));
324 sink_.WaitForEncodedFrame(1); 366 sink_.WaitForEncodedFrame(1);
325 // Here, the encoder thread will be blocked in the TestEncoder waiting for a 367 // Here, the encoder thread will be blocked in the TestEncoder waiting for a
326 // call to ContinueEncode. 368 // call to ContinueEncode.
327 video_source_.IncomingCapturedFrame(CreateFrame(2, nullptr)); 369 video_source_.IncomingCapturedFrame(CreateFrame(2, nullptr));
328 video_source_.IncomingCapturedFrame(CreateFrame(3, nullptr)); 370 video_source_.IncomingCapturedFrame(CreateFrame(3, nullptr));
329 fake_encoder_.ContinueEncode(); 371 fake_encoder_.ContinueEncode();
330 sink_.WaitForEncodedFrame(3); 372 sink_.WaitForEncodedFrame(3);
331 373
332 vie_encoder_->Stop(); 374 vie_encoder_->Stop();
333 } 375 }
334 376
335 TEST_F(ViEEncoderTest, ConfigureEncoderTriggersOnEncoderConfigurationChanged) { 377 TEST_F(ViEEncoderTest, ConfigureEncoderTriggersOnEncoderConfigurationChanged) {
336 const int kTargetBitrateBps = 100000;
337 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); 378 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0);
338 EXPECT_EQ(0, sink_.number_of_reconfigurations()); 379 EXPECT_EQ(0, sink_.number_of_reconfigurations());
339 380
340 // Capture a frame and wait for it to synchronize with the encoder thread. 381 // Capture a frame and wait for it to synchronize with the encoder thread.
341 video_source_.IncomingCapturedFrame(CreateFrame(1, nullptr)); 382 video_source_.IncomingCapturedFrame(CreateFrame(1, nullptr));
342 sink_.WaitForEncodedFrame(1); 383 sink_.WaitForEncodedFrame(1);
343 // The encoder will have been configured once when the first frame is 384 // The encoder will have been configured once when the first frame is
344 // received. 385 // received.
345 EXPECT_EQ(1, sink_.number_of_reconfigurations()); 386 EXPECT_EQ(1, sink_.number_of_reconfigurations());
346 387
347 VideoEncoderConfig video_encoder_config; 388 VideoEncoderConfig video_encoder_config;
348 test::FillEncoderConfiguration(1, &video_encoder_config); 389 test::FillEncoderConfiguration(1, &video_encoder_config);
349 video_encoder_config.min_transmit_bitrate_bps = 9999; 390 video_encoder_config.min_transmit_bitrate_bps = 9999;
350 vie_encoder_->ConfigureEncoder(std::move(video_encoder_config), 1440); 391 vie_encoder_->ConfigureEncoder(std::move(video_encoder_config),
392 kMaxPayloadLength, true /* nack_enabled */);
351 393
352 // Capture a frame and wait for it to synchronize with the encoder thread. 394 // Capture a frame and wait for it to synchronize with the encoder thread.
353 video_source_.IncomingCapturedFrame(CreateFrame(2, nullptr)); 395 video_source_.IncomingCapturedFrame(CreateFrame(2, nullptr));
354 sink_.WaitForEncodedFrame(2); 396 sink_.WaitForEncodedFrame(2);
355 EXPECT_EQ(2, sink_.number_of_reconfigurations()); 397 EXPECT_EQ(2, sink_.number_of_reconfigurations());
356 EXPECT_EQ(9999, sink_.last_min_transmit_bitrate()); 398 EXPECT_EQ(9999, sink_.last_min_transmit_bitrate());
357 399
358 vie_encoder_->Stop(); 400 vie_encoder_->Stop();
359 } 401 }
360 402
361 TEST_F(ViEEncoderTest, FrameResolutionChangeReconfigureEncoder) { 403 TEST_F(ViEEncoderTest, FrameResolutionChangeReconfigureEncoder) {
362 const int kTargetBitrateBps = 100000;
363 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); 404 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0);
364 405
365 // Capture a frame and wait for it to synchronize with the encoder thread. 406 // Capture a frame and wait for it to synchronize with the encoder thread.
366 video_source_.IncomingCapturedFrame(CreateFrame(1, nullptr)); 407 video_source_.IncomingCapturedFrame(CreateFrame(1, nullptr));
367 sink_.WaitForEncodedFrame(1); 408 sink_.WaitForEncodedFrame(1);
368 // The encoder will have been configured once. 409 // The encoder will have been configured once.
369 EXPECT_EQ(1, sink_.number_of_reconfigurations()); 410 EXPECT_EQ(1, sink_.number_of_reconfigurations());
370 EXPECT_EQ(codec_width_, fake_encoder_.codec_config().width); 411 EXPECT_EQ(codec_width_, fake_encoder_.codec_config().width);
371 EXPECT_EQ(codec_height_, fake_encoder_.codec_config().height); 412 EXPECT_EQ(codec_height_, fake_encoder_.codec_config().height);
372 413
373 codec_width_ *= 2; 414 codec_width_ *= 2;
374 codec_height_ *= 2; 415 codec_height_ *= 2;
375 // Capture a frame with a higher resolution and wait for it to synchronize 416 // Capture a frame with a higher resolution and wait for it to synchronize
376 // with the encoder thread. 417 // with the encoder thread.
377 video_source_.IncomingCapturedFrame(CreateFrame(2, nullptr)); 418 video_source_.IncomingCapturedFrame(CreateFrame(2, nullptr));
378 sink_.WaitForEncodedFrame(2); 419 sink_.WaitForEncodedFrame(2);
379 EXPECT_EQ(codec_width_, fake_encoder_.codec_config().width); 420 EXPECT_EQ(codec_width_, fake_encoder_.codec_config().width);
380 EXPECT_EQ(codec_height_, fake_encoder_.codec_config().height); 421 EXPECT_EQ(codec_height_, fake_encoder_.codec_config().height);
381 EXPECT_EQ(2, sink_.number_of_reconfigurations()); 422 EXPECT_EQ(2, sink_.number_of_reconfigurations());
382 423
383 vie_encoder_->Stop(); 424 vie_encoder_->Stop();
384 } 425 }
385 426
427 TEST_F(ViEEncoderTest, Vp8ResilienceIsOffFor1S1TLWithNackEnabled) {
428 const bool kNackEnabled = true;
429 const size_t kNumStreams = 1;
430 const size_t kNumTl = 1;
431 ResetEncoder("VP8", kNumStreams, kNumTl, kNackEnabled);
432 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0);
433
434 // Capture a frame and wait for it to synchronize with the encoder thread.
435 video_source_.IncomingCapturedFrame(CreateFrame(1, nullptr));
436 sink_.WaitForEncodedFrame(1);
437 // The encoder have been configured once when the first frame is received.
438 EXPECT_EQ(1, sink_.number_of_reconfigurations());
439 EXPECT_EQ(kVideoCodecVP8, fake_encoder_.codec_config().codecType);
440 EXPECT_EQ(kNumStreams, fake_encoder_.codec_config().numberOfSimulcastStreams);
441 EXPECT_EQ(kNumTl, fake_encoder_.codec_config().VP8()->numberOfTemporalLayers);
442 // Resilience is off for no temporal layers with nack on.
443 EXPECT_EQ(kResilienceOff, fake_encoder_.codec_config().VP8()->resilience);
444 vie_encoder_->Stop();
445 }
446
447 TEST_F(ViEEncoderTest, Vp8ResilienceIsOffFor2S1TlWithNackEnabled) {
448 const bool kNackEnabled = true;
449 const size_t kNumStreams = 2;
450 const size_t kNumTl = 1;
451 ResetEncoder("VP8", kNumStreams, kNumTl, kNackEnabled);
452 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0);
453
454 // Capture a frame and wait for it to synchronize with the encoder thread.
455 video_source_.IncomingCapturedFrame(CreateFrame(1, nullptr));
456 sink_.WaitForEncodedFrame(1);
457 // The encoder have been configured once when the first frame is received.
458 EXPECT_EQ(1, sink_.number_of_reconfigurations());
459 EXPECT_EQ(kVideoCodecVP8, fake_encoder_.codec_config().codecType);
460 EXPECT_EQ(kNumStreams, fake_encoder_.codec_config().numberOfSimulcastStreams);
461 EXPECT_EQ(kNumTl, fake_encoder_.codec_config().VP8()->numberOfTemporalLayers);
462 // Resilience is off for no temporal layers and >1 streams with nack on.
463 EXPECT_EQ(kResilienceOff, fake_encoder_.codec_config().VP8()->resilience);
464 vie_encoder_->Stop();
465 }
466
467 TEST_F(ViEEncoderTest, Vp8ResilienceIsOnFor1S1TLWithNackDisabled) {
468 const bool kNackEnabled = false;
469 const size_t kNumStreams = 1;
470 const size_t kNumTl = 1;
471 ResetEncoder("VP8", kNumStreams, kNumTl, kNackEnabled);
472 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0);
473
474 // Capture a frame and wait for it to synchronize with the encoder thread.
475 video_source_.IncomingCapturedFrame(CreateFrame(1, nullptr));
476 sink_.WaitForEncodedFrame(1);
477 // The encoder have been configured once when the first frame is received.
478 EXPECT_EQ(1, sink_.number_of_reconfigurations());
479 EXPECT_EQ(kVideoCodecVP8, fake_encoder_.codec_config().codecType);
480 EXPECT_EQ(kNumStreams, fake_encoder_.codec_config().numberOfSimulcastStreams);
481 EXPECT_EQ(kNumTl, fake_encoder_.codec_config().VP8()->numberOfTemporalLayers);
482 // Resilience is on for no temporal layers with nack off.
483 EXPECT_EQ(kResilientStream, fake_encoder_.codec_config().VP8()->resilience);
484 vie_encoder_->Stop();
485 }
486
487 TEST_F(ViEEncoderTest, Vp8ResilienceIsOnFor1S2TlWithNackEnabled) {
488 const bool kNackEnabled = true;
489 const size_t kNumStreams = 1;
490 const size_t kNumTl = 2;
491 ResetEncoder("VP8", kNumStreams, kNumTl, kNackEnabled);
492 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0);
493
494 // Capture a frame and wait for it to synchronize with the encoder thread.
495 video_source_.IncomingCapturedFrame(CreateFrame(1, nullptr));
496 sink_.WaitForEncodedFrame(1);
497 // The encoder have been configured once when the first frame is received.
498 EXPECT_EQ(1, sink_.number_of_reconfigurations());
499 EXPECT_EQ(kVideoCodecVP8, fake_encoder_.codec_config().codecType);
500 EXPECT_EQ(kNumStreams, fake_encoder_.codec_config().numberOfSimulcastStreams);
501 EXPECT_EQ(kNumTl, fake_encoder_.codec_config().VP8()->numberOfTemporalLayers);
502 // Resilience is on for temporal layers.
503 EXPECT_EQ(kResilientStream, fake_encoder_.codec_config().VP8()->resilience);
504 vie_encoder_->Stop();
505 }
506
386 TEST_F(ViEEncoderTest, SwitchSourceDeregisterEncoderAsSink) { 507 TEST_F(ViEEncoderTest, SwitchSourceDeregisterEncoderAsSink) {
387 EXPECT_TRUE(video_source_.has_sinks()); 508 EXPECT_TRUE(video_source_.has_sinks());
388 test::FrameForwarder new_video_source; 509 test::FrameForwarder new_video_source;
389 vie_encoder_->SetSource(&new_video_source, 510 vie_encoder_->SetSource(&new_video_source,
390 VideoSendStream::DegradationPreference::kBalanced); 511 VideoSendStream::DegradationPreference::kBalanced);
391 EXPECT_FALSE(video_source_.has_sinks()); 512 EXPECT_FALSE(video_source_.has_sinks());
392 EXPECT_TRUE(new_video_source.has_sinks()); 513 EXPECT_TRUE(new_video_source.has_sinks());
393 514
394 vie_encoder_->Stop(); 515 vie_encoder_->Stop();
395 } 516 }
396 517
397 TEST_F(ViEEncoderTest, SinkWantsRotationApplied) { 518 TEST_F(ViEEncoderTest, SinkWantsRotationApplied) {
398 EXPECT_FALSE(video_source_.sink_wants().rotation_applied); 519 EXPECT_FALSE(video_source_.sink_wants().rotation_applied);
399 vie_encoder_->SetSink(&sink_, true /*rotation_applied*/); 520 vie_encoder_->SetSink(&sink_, true /*rotation_applied*/);
400 EXPECT_TRUE(video_source_.sink_wants().rotation_applied); 521 EXPECT_TRUE(video_source_.sink_wants().rotation_applied);
401 vie_encoder_->Stop(); 522 vie_encoder_->Stop();
402 } 523 }
403 524
404 TEST_F(ViEEncoderTest, SinkWantsFromOveruseDetector) { 525 TEST_F(ViEEncoderTest, SinkWantsFromOveruseDetector) {
405 const int kTargetBitrateBps = 100000;
406 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); 526 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0);
407 527
408 EXPECT_FALSE(video_source_.sink_wants().max_pixel_count); 528 EXPECT_FALSE(video_source_.sink_wants().max_pixel_count);
409 EXPECT_FALSE(video_source_.sink_wants().max_pixel_count_step_up); 529 EXPECT_FALSE(video_source_.sink_wants().max_pixel_count_step_up);
410 530
411 int frame_width = 1280; 531 int frame_width = 1280;
412 int frame_height = 720; 532 int frame_height = 720;
413 533
414 // Trigger CPU overuse kMaxCpuDowngrades times. Every time, ViEEncoder should 534 // Trigger CPU overuse kMaxCpuDowngrades times. Every time, ViEEncoder should
415 // request lower resolution. 535 // request lower resolution.
(...skipping 29 matching lines...) Expand all
445 vie_encoder_->TriggerCpuNormalUsage(); 565 vie_encoder_->TriggerCpuNormalUsage();
446 EXPECT_FALSE(video_source_.sink_wants().max_pixel_count); 566 EXPECT_FALSE(video_source_.sink_wants().max_pixel_count);
447 EXPECT_EQ(video_source_.sink_wants().max_pixel_count_step_up.value_or(0), 567 EXPECT_EQ(video_source_.sink_wants().max_pixel_count_step_up.value_or(0),
448 frame_width * frame_height); 568 frame_width * frame_height);
449 569
450 vie_encoder_->Stop(); 570 vie_encoder_->Stop();
451 } 571 }
452 572
453 TEST_F(ViEEncoderTest, 573 TEST_F(ViEEncoderTest,
454 ResolutionSinkWantsResetOnSetSourceWithDisabledResolutionScaling) { 574 ResolutionSinkWantsResetOnSetSourceWithDisabledResolutionScaling) {
455 const int kTargetBitrateBps = 100000;
456 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); 575 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0);
457 576
458 EXPECT_FALSE(video_source_.sink_wants().max_pixel_count); 577 EXPECT_FALSE(video_source_.sink_wants().max_pixel_count);
459 EXPECT_FALSE(video_source_.sink_wants().max_pixel_count_step_up); 578 EXPECT_FALSE(video_source_.sink_wants().max_pixel_count_step_up);
460 579
461 int frame_width = 1280; 580 int frame_width = 1280;
462 int frame_height = 720; 581 int frame_height = 720;
463 582
464 // Trigger CPU overuse. 583 // Trigger CPU overuse.
465 vie_encoder_->TriggerCpuOveruse(); 584 vie_encoder_->TriggerCpuOveruse();
(...skipping 26 matching lines...) Expand all
492 VideoSendStream::DegradationPreference::kBalanced); 611 VideoSendStream::DegradationPreference::kBalanced);
493 EXPECT_LT(new_video_source.sink_wants().max_pixel_count.value_or( 612 EXPECT_LT(new_video_source.sink_wants().max_pixel_count.value_or(
494 std::numeric_limits<int>::max()), 613 std::numeric_limits<int>::max()),
495 frame_width * frame_height); 614 frame_width * frame_height);
496 EXPECT_FALSE(new_video_source.sink_wants().max_pixel_count_step_up); 615 EXPECT_FALSE(new_video_source.sink_wants().max_pixel_count_step_up);
497 616
498 vie_encoder_->Stop(); 617 vie_encoder_->Stop();
499 } 618 }
500 619
501 TEST_F(ViEEncoderTest, StatsTracksAdaptationStats) { 620 TEST_F(ViEEncoderTest, StatsTracksAdaptationStats) {
502 const int kTargetBitrateBps = 100000;
503 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); 621 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0);
504 622
505 int frame_width = 1280; 623 int frame_width = 1280;
506 int frame_height = 720; 624 int frame_height = 720;
507 625
508 video_source_.IncomingCapturedFrame( 626 video_source_.IncomingCapturedFrame(
509 CreateFrame(1, frame_width, frame_height)); 627 CreateFrame(1, frame_width, frame_height));
510 sink_.WaitForEncodedFrame(1); 628 sink_.WaitForEncodedFrame(1);
511 VideoSendStream::Stats stats = stats_proxy_->GetStats(); 629 VideoSendStream::Stats stats = stats_proxy_->GetStats();
512 EXPECT_FALSE(stats.cpu_limited_resolution); 630 EXPECT_FALSE(stats.cpu_limited_resolution);
(...skipping 16 matching lines...) Expand all
529 sink_.WaitForEncodedFrame(3); 647 sink_.WaitForEncodedFrame(3);
530 648
531 stats = stats_proxy_->GetStats(); 649 stats = stats_proxy_->GetStats();
532 EXPECT_FALSE(stats.cpu_limited_resolution); 650 EXPECT_FALSE(stats.cpu_limited_resolution);
533 EXPECT_EQ(2, stats.number_of_cpu_adapt_changes); 651 EXPECT_EQ(2, stats.number_of_cpu_adapt_changes);
534 652
535 vie_encoder_->Stop(); 653 vie_encoder_->Stop();
536 } 654 }
537 655
538 TEST_F(ViEEncoderTest, StatsTracksAdaptationStatsWhenSwitchingSource) { 656 TEST_F(ViEEncoderTest, StatsTracksAdaptationStatsWhenSwitchingSource) {
539 const int kTargetBitrateBps = 100000;
540 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); 657 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0);
541 658
542 // Trigger CPU overuse. 659 // Trigger CPU overuse.
543 vie_encoder_->TriggerCpuOveruse(); 660 vie_encoder_->TriggerCpuOveruse();
544 int frame_width = 1280; 661 int frame_width = 1280;
545 int frame_height = 720; 662 int frame_height = 720;
546 663
547 video_source_.IncomingCapturedFrame( 664 video_source_.IncomingCapturedFrame(
548 CreateFrame(1, frame_width, frame_height)); 665 CreateFrame(1, frame_width, frame_height));
549 sink_.WaitForEncodedFrame(1); 666 sink_.WaitForEncodedFrame(1);
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
591 CreateFrame(5, frame_width, frame_height)); 708 CreateFrame(5, frame_width, frame_height));
592 sink_.WaitForEncodedFrame(5); 709 sink_.WaitForEncodedFrame(5);
593 stats = stats_proxy_->GetStats(); 710 stats = stats_proxy_->GetStats();
594 EXPECT_FALSE(stats.cpu_limited_resolution); 711 EXPECT_FALSE(stats.cpu_limited_resolution);
595 EXPECT_EQ(2, stats.number_of_cpu_adapt_changes); 712 EXPECT_EQ(2, stats.number_of_cpu_adapt_changes);
596 713
597 vie_encoder_->Stop(); 714 vie_encoder_->Stop();
598 } 715 }
599 716
600 TEST_F(ViEEncoderTest, StatsTracksPreferredBitrate) { 717 TEST_F(ViEEncoderTest, StatsTracksPreferredBitrate) {
601 const int kTargetBitrateBps = 100000;
602 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); 718 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0);
603 719
604 video_source_.IncomingCapturedFrame(CreateFrame(1, 1280, 720)); 720 video_source_.IncomingCapturedFrame(CreateFrame(1, 1280, 720));
605 sink_.WaitForEncodedFrame(1); 721 sink_.WaitForEncodedFrame(1);
606 722
607 VideoSendStream::Stats stats = stats_proxy_->GetStats(); 723 VideoSendStream::Stats stats = stats_proxy_->GetStats();
608 EXPECT_EQ(video_encoder_config_.max_bitrate_bps, 724 EXPECT_EQ(video_encoder_config_.max_bitrate_bps,
609 stats.preferred_media_bitrate_bps); 725 stats.preferred_media_bitrate_bps);
610 726
611 vie_encoder_->Stop(); 727 vie_encoder_->Stop();
612 } 728 }
613 729
614 TEST_F(ViEEncoderTest, UMACpuLimitedResolutionInPercent) { 730 TEST_F(ViEEncoderTest, UMACpuLimitedResolutionInPercent) {
615 const int kTargetBitrateBps = 100000;
616 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); 731 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0);
617 732
618 int frame_width = 640; 733 int frame_width = 640;
619 int frame_height = 360; 734 int frame_height = 360;
620 735
621 for (int i = 1; i <= SendStatisticsProxy::kMinRequiredMetricsSamples; ++i) { 736 for (int i = 1; i <= SendStatisticsProxy::kMinRequiredMetricsSamples; ++i) {
622 video_source_.IncomingCapturedFrame( 737 video_source_.IncomingCapturedFrame(
623 CreateFrame(i, frame_width, frame_height)); 738 CreateFrame(i, frame_width, frame_height));
624 sink_.WaitForEncodedFrame(i); 739 sink_.WaitForEncodedFrame(i);
625 } 740 }
(...skipping 10 matching lines...) Expand all
636 vie_encoder_->Stop(); 751 vie_encoder_->Stop();
637 752
638 stats_proxy_.reset(); 753 stats_proxy_.reset();
639 EXPECT_EQ(1, 754 EXPECT_EQ(1,
640 metrics::NumSamples("WebRTC.Video.CpuLimitedResolutionInPercent")); 755 metrics::NumSamples("WebRTC.Video.CpuLimitedResolutionInPercent"));
641 EXPECT_EQ( 756 EXPECT_EQ(
642 1, metrics::NumEvents("WebRTC.Video.CpuLimitedResolutionInPercent", 50)); 757 1, metrics::NumEvents("WebRTC.Video.CpuLimitedResolutionInPercent", 50));
643 } 758 }
644 759
645 } // namespace webrtc 760 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/video/vie_encoder.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698