OLD | NEW |
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 Loading... |
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 (size_t i = 0; i < streams.size(); ++i) { |
| 89 streams[i].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); |
| 122 ConfigureEncoder(std::move(video_encoder_config), true /* nack_enabled */); |
| 123 } |
| 124 |
| 125 void ConfigureEncoder(VideoEncoderConfig video_encoder_config, |
| 126 bool nack_enabled) { |
| 127 if (vie_encoder_) |
| 128 vie_encoder_->Stop(); |
96 vie_encoder_.reset(new ViEEncoderUnderTest( | 129 vie_encoder_.reset(new ViEEncoderUnderTest( |
97 stats_proxy_.get(), video_send_config_.encoder_settings)); | 130 stats_proxy_.get(), video_send_config_.encoder_settings)); |
98 vie_encoder_->SetSink(&sink_, false /* rotation_applied */); | 131 vie_encoder_->SetSink(&sink_, false /* rotation_applied */); |
99 vie_encoder_->SetSource(&video_source_, | 132 vie_encoder_->SetSource(&video_source_, |
100 VideoSendStream::DegradationPreference::kBalanced); | 133 VideoSendStream::DegradationPreference::kBalanced); |
101 vie_encoder_->SetStartBitrate(10000); | 134 vie_encoder_->SetStartBitrate(10000); |
102 vie_encoder_->ConfigureEncoder(std::move(video_encoder_config), 1440); | 135 vie_encoder_->ConfigureEncoder(std::move(video_encoder_config), |
| 136 kMaxPayloadLength, nack_enabled); |
| 137 } |
| 138 |
| 139 void ResetEncoder(const std::string& payload_name, |
| 140 size_t num_streams, |
| 141 size_t num_temporal_layers, |
| 142 bool nack_enabled) { |
| 143 video_send_config_.encoder_settings.payload_name = payload_name; |
| 144 |
| 145 VideoEncoderConfig video_encoder_config; |
| 146 video_encoder_config.number_of_streams = num_streams; |
| 147 video_encoder_config.max_bitrate_bps = 1000000; |
| 148 video_encoder_config.video_stream_factory = |
| 149 new rtc::RefCountedObject<VideoStreamFactory>(num_temporal_layers); |
| 150 ConfigureEncoder(std::move(video_encoder_config), nack_enabled); |
103 } | 151 } |
104 | 152 |
105 VideoFrame CreateFrame(int64_t ntp_ts, rtc::Event* destruction_event) const { | 153 VideoFrame CreateFrame(int64_t ntp_ts, rtc::Event* destruction_event) const { |
106 VideoFrame frame(new rtc::RefCountedObject<TestBuffer>( | 154 VideoFrame frame(new rtc::RefCountedObject<TestBuffer>( |
107 destruction_event, codec_width_, codec_height_), | 155 destruction_event, codec_width_, codec_height_), |
108 99, 99, kVideoRotation_0); | 156 99, 99, kVideoRotation_0); |
109 frame.set_ntp_time_ms(ntp_ts); | 157 frame.set_ntp_time_ms(ntp_ts); |
110 return frame; | 158 return frame; |
111 } | 159 } |
112 | 160 |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
238 int codec_width_; | 286 int codec_width_; |
239 int codec_height_; | 287 int codec_height_; |
240 TestEncoder fake_encoder_; | 288 TestEncoder fake_encoder_; |
241 std::unique_ptr<SendStatisticsProxy> stats_proxy_; | 289 std::unique_ptr<SendStatisticsProxy> stats_proxy_; |
242 TestSink sink_; | 290 TestSink sink_; |
243 test::FrameForwarder video_source_; | 291 test::FrameForwarder video_source_; |
244 std::unique_ptr<ViEEncoderUnderTest> vie_encoder_; | 292 std::unique_ptr<ViEEncoderUnderTest> vie_encoder_; |
245 }; | 293 }; |
246 | 294 |
247 TEST_F(ViEEncoderTest, EncodeOneFrame) { | 295 TEST_F(ViEEncoderTest, EncodeOneFrame) { |
248 const int kTargetBitrateBps = 100000; | |
249 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); | 296 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); |
250 rtc::Event frame_destroyed_event(false, false); | 297 rtc::Event frame_destroyed_event(false, false); |
251 video_source_.IncomingCapturedFrame(CreateFrame(1, &frame_destroyed_event)); | 298 video_source_.IncomingCapturedFrame(CreateFrame(1, &frame_destroyed_event)); |
252 sink_.WaitForEncodedFrame(1); | 299 sink_.WaitForEncodedFrame(1); |
253 EXPECT_TRUE(frame_destroyed_event.Wait(kDefaultTimeoutMs)); | 300 EXPECT_TRUE(frame_destroyed_event.Wait(kDefaultTimeoutMs)); |
254 vie_encoder_->Stop(); | 301 vie_encoder_->Stop(); |
255 } | 302 } |
256 | 303 |
257 TEST_F(ViEEncoderTest, DropsFramesBeforeFirstOnBitrateUpdated) { | 304 TEST_F(ViEEncoderTest, DropsFramesBeforeFirstOnBitrateUpdated) { |
258 // Dropped since no target bitrate has been set. | 305 // Dropped since no target bitrate has been set. |
259 rtc::Event frame_destroyed_event(false, false); | 306 rtc::Event frame_destroyed_event(false, false); |
260 video_source_.IncomingCapturedFrame(CreateFrame(1, &frame_destroyed_event)); | 307 video_source_.IncomingCapturedFrame(CreateFrame(1, &frame_destroyed_event)); |
261 EXPECT_TRUE(frame_destroyed_event.Wait(kDefaultTimeoutMs)); | 308 EXPECT_TRUE(frame_destroyed_event.Wait(kDefaultTimeoutMs)); |
262 | 309 |
263 const int kTargetBitrateBps = 100000; | |
264 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); | 310 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); |
265 | 311 |
266 video_source_.IncomingCapturedFrame(CreateFrame(2, nullptr)); | 312 video_source_.IncomingCapturedFrame(CreateFrame(2, nullptr)); |
267 sink_.WaitForEncodedFrame(2); | 313 sink_.WaitForEncodedFrame(2); |
268 vie_encoder_->Stop(); | 314 vie_encoder_->Stop(); |
269 } | 315 } |
270 | 316 |
271 TEST_F(ViEEncoderTest, DropsFramesWhenRateSetToZero) { | 317 TEST_F(ViEEncoderTest, DropsFramesWhenRateSetToZero) { |
272 const int kTargetBitrateBps = 100000; | |
273 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); | 318 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); |
274 video_source_.IncomingCapturedFrame(CreateFrame(1, nullptr)); | 319 video_source_.IncomingCapturedFrame(CreateFrame(1, nullptr)); |
275 sink_.WaitForEncodedFrame(1); | 320 sink_.WaitForEncodedFrame(1); |
276 | 321 |
277 vie_encoder_->OnBitrateUpdated(0, 0, 0); | 322 vie_encoder_->OnBitrateUpdated(0, 0, 0); |
278 // Dropped since bitrate is zero. | 323 // Dropped since bitrate is zero. |
279 video_source_.IncomingCapturedFrame(CreateFrame(2, nullptr)); | 324 video_source_.IncomingCapturedFrame(CreateFrame(2, nullptr)); |
280 | 325 |
281 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); | 326 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); |
282 video_source_.IncomingCapturedFrame(CreateFrame(3, nullptr)); | 327 video_source_.IncomingCapturedFrame(CreateFrame(3, nullptr)); |
283 sink_.WaitForEncodedFrame(3); | 328 sink_.WaitForEncodedFrame(3); |
284 vie_encoder_->Stop(); | 329 vie_encoder_->Stop(); |
285 } | 330 } |
286 | 331 |
287 TEST_F(ViEEncoderTest, DropsFramesWithSameOrOldNtpTimestamp) { | 332 TEST_F(ViEEncoderTest, DropsFramesWithSameOrOldNtpTimestamp) { |
288 const int kTargetBitrateBps = 100000; | |
289 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); | 333 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); |
290 video_source_.IncomingCapturedFrame(CreateFrame(1, nullptr)); | 334 video_source_.IncomingCapturedFrame(CreateFrame(1, nullptr)); |
291 sink_.WaitForEncodedFrame(1); | 335 sink_.WaitForEncodedFrame(1); |
292 | 336 |
293 // This frame will be dropped since it has the same ntp timestamp. | 337 // This frame will be dropped since it has the same ntp timestamp. |
294 video_source_.IncomingCapturedFrame(CreateFrame(1, nullptr)); | 338 video_source_.IncomingCapturedFrame(CreateFrame(1, nullptr)); |
295 | 339 |
296 video_source_.IncomingCapturedFrame(CreateFrame(2, nullptr)); | 340 video_source_.IncomingCapturedFrame(CreateFrame(2, nullptr)); |
297 sink_.WaitForEncodedFrame(2); | 341 sink_.WaitForEncodedFrame(2); |
298 vie_encoder_->Stop(); | 342 vie_encoder_->Stop(); |
299 } | 343 } |
300 | 344 |
301 TEST_F(ViEEncoderTest, DropsFrameAfterStop) { | 345 TEST_F(ViEEncoderTest, DropsFrameAfterStop) { |
302 const int kTargetBitrateBps = 100000; | |
303 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); | 346 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); |
304 | 347 |
305 video_source_.IncomingCapturedFrame(CreateFrame(1, nullptr)); | 348 video_source_.IncomingCapturedFrame(CreateFrame(1, nullptr)); |
306 sink_.WaitForEncodedFrame(1); | 349 sink_.WaitForEncodedFrame(1); |
307 | 350 |
308 vie_encoder_->Stop(); | 351 vie_encoder_->Stop(); |
309 sink_.SetExpectNoFrames(); | 352 sink_.SetExpectNoFrames(); |
310 rtc::Event frame_destroyed_event(false, false); | 353 rtc::Event frame_destroyed_event(false, false); |
311 video_source_.IncomingCapturedFrame(CreateFrame(2, &frame_destroyed_event)); | 354 video_source_.IncomingCapturedFrame(CreateFrame(2, &frame_destroyed_event)); |
312 EXPECT_TRUE(frame_destroyed_event.Wait(kDefaultTimeoutMs)); | 355 EXPECT_TRUE(frame_destroyed_event.Wait(kDefaultTimeoutMs)); |
313 } | 356 } |
314 | 357 |
315 TEST_F(ViEEncoderTest, DropsPendingFramesOnSlowEncode) { | 358 TEST_F(ViEEncoderTest, DropsPendingFramesOnSlowEncode) { |
316 const int kTargetBitrateBps = 100000; | |
317 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); | 359 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); |
318 | 360 |
319 fake_encoder_.BlockNextEncode(); | 361 fake_encoder_.BlockNextEncode(); |
320 video_source_.IncomingCapturedFrame(CreateFrame(1, nullptr)); | 362 video_source_.IncomingCapturedFrame(CreateFrame(1, nullptr)); |
321 sink_.WaitForEncodedFrame(1); | 363 sink_.WaitForEncodedFrame(1); |
322 // Here, the encoder thread will be blocked in the TestEncoder waiting for a | 364 // Here, the encoder thread will be blocked in the TestEncoder waiting for a |
323 // call to ContinueEncode. | 365 // call to ContinueEncode. |
324 video_source_.IncomingCapturedFrame(CreateFrame(2, nullptr)); | 366 video_source_.IncomingCapturedFrame(CreateFrame(2, nullptr)); |
325 video_source_.IncomingCapturedFrame(CreateFrame(3, nullptr)); | 367 video_source_.IncomingCapturedFrame(CreateFrame(3, nullptr)); |
326 fake_encoder_.ContinueEncode(); | 368 fake_encoder_.ContinueEncode(); |
327 sink_.WaitForEncodedFrame(3); | 369 sink_.WaitForEncodedFrame(3); |
328 | 370 |
329 vie_encoder_->Stop(); | 371 vie_encoder_->Stop(); |
330 } | 372 } |
331 | 373 |
332 TEST_F(ViEEncoderTest, ConfigureEncoderTriggersOnEncoderConfigurationChanged) { | 374 TEST_F(ViEEncoderTest, ConfigureEncoderTriggersOnEncoderConfigurationChanged) { |
333 const int kTargetBitrateBps = 100000; | |
334 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); | 375 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); |
335 EXPECT_EQ(0, sink_.number_of_reconfigurations()); | 376 EXPECT_EQ(0, sink_.number_of_reconfigurations()); |
336 | 377 |
337 // Capture a frame and wait for it to synchronize with the encoder thread. | 378 // Capture a frame and wait for it to synchronize with the encoder thread. |
338 video_source_.IncomingCapturedFrame(CreateFrame(1, nullptr)); | 379 video_source_.IncomingCapturedFrame(CreateFrame(1, nullptr)); |
339 sink_.WaitForEncodedFrame(1); | 380 sink_.WaitForEncodedFrame(1); |
340 // The encoder will have been configured once when the first frame is | 381 // The encoder will have been configured once when the first frame is |
341 // received. | 382 // received. |
342 EXPECT_EQ(1, sink_.number_of_reconfigurations()); | 383 EXPECT_EQ(1, sink_.number_of_reconfigurations()); |
343 | 384 |
344 VideoEncoderConfig video_encoder_config; | 385 VideoEncoderConfig video_encoder_config; |
345 test::FillEncoderConfiguration(1, &video_encoder_config); | 386 test::FillEncoderConfiguration(1, &video_encoder_config); |
346 video_encoder_config.min_transmit_bitrate_bps = 9999; | 387 video_encoder_config.min_transmit_bitrate_bps = 9999; |
347 vie_encoder_->ConfigureEncoder(std::move(video_encoder_config), 1440); | 388 vie_encoder_->ConfigureEncoder(std::move(video_encoder_config), |
| 389 kMaxPayloadLength, true /* nack_enabled */); |
348 | 390 |
349 // Capture a frame and wait for it to synchronize with the encoder thread. | 391 // Capture a frame and wait for it to synchronize with the encoder thread. |
350 video_source_.IncomingCapturedFrame(CreateFrame(2, nullptr)); | 392 video_source_.IncomingCapturedFrame(CreateFrame(2, nullptr)); |
351 sink_.WaitForEncodedFrame(2); | 393 sink_.WaitForEncodedFrame(2); |
352 EXPECT_EQ(2, sink_.number_of_reconfigurations()); | 394 EXPECT_EQ(2, sink_.number_of_reconfigurations()); |
353 EXPECT_EQ(9999, sink_.last_min_transmit_bitrate()); | 395 EXPECT_EQ(9999, sink_.last_min_transmit_bitrate()); |
354 | 396 |
355 vie_encoder_->Stop(); | 397 vie_encoder_->Stop(); |
356 } | 398 } |
357 | 399 |
358 TEST_F(ViEEncoderTest, FrameResolutionChangeReconfigureEncoder) { | 400 TEST_F(ViEEncoderTest, FrameResolutionChangeReconfigureEncoder) { |
359 const int kTargetBitrateBps = 100000; | |
360 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); | 401 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); |
361 | 402 |
362 // Capture a frame and wait for it to synchronize with the encoder thread. | 403 // Capture a frame and wait for it to synchronize with the encoder thread. |
363 video_source_.IncomingCapturedFrame(CreateFrame(1, nullptr)); | 404 video_source_.IncomingCapturedFrame(CreateFrame(1, nullptr)); |
364 sink_.WaitForEncodedFrame(1); | 405 sink_.WaitForEncodedFrame(1); |
365 // The encoder will have been configured once. | 406 // The encoder will have been configured once. |
366 EXPECT_EQ(1, sink_.number_of_reconfigurations()); | 407 EXPECT_EQ(1, sink_.number_of_reconfigurations()); |
367 EXPECT_EQ(codec_width_, fake_encoder_.codec_config().width); | 408 EXPECT_EQ(codec_width_, fake_encoder_.codec_config().width); |
368 EXPECT_EQ(codec_height_, fake_encoder_.codec_config().height); | 409 EXPECT_EQ(codec_height_, fake_encoder_.codec_config().height); |
369 | 410 |
370 codec_width_ *= 2; | 411 codec_width_ *= 2; |
371 codec_height_ *= 2; | 412 codec_height_ *= 2; |
372 // Capture a frame with a higher resolution and wait for it to synchronize | 413 // Capture a frame with a higher resolution and wait for it to synchronize |
373 // with the encoder thread. | 414 // with the encoder thread. |
374 video_source_.IncomingCapturedFrame(CreateFrame(2, nullptr)); | 415 video_source_.IncomingCapturedFrame(CreateFrame(2, nullptr)); |
375 sink_.WaitForEncodedFrame(2); | 416 sink_.WaitForEncodedFrame(2); |
376 EXPECT_EQ(codec_width_, fake_encoder_.codec_config().width); | 417 EXPECT_EQ(codec_width_, fake_encoder_.codec_config().width); |
377 EXPECT_EQ(codec_height_, fake_encoder_.codec_config().height); | 418 EXPECT_EQ(codec_height_, fake_encoder_.codec_config().height); |
378 EXPECT_EQ(2, sink_.number_of_reconfigurations()); | 419 EXPECT_EQ(2, sink_.number_of_reconfigurations()); |
379 | 420 |
380 vie_encoder_->Stop(); | 421 vie_encoder_->Stop(); |
381 } | 422 } |
382 | 423 |
| 424 TEST_F(ViEEncoderTest, Vp8ResilienceIsOffFor1SL1TLWithNackEnabled) { |
| 425 const bool kNackEnabled = true; |
| 426 const size_t kNumStreams = 1; |
| 427 const size_t kNumTl = 1; |
| 428 ResetEncoder("VP8", kNumStreams, kNumTl, kNackEnabled); |
| 429 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); |
| 430 |
| 431 // Capture a frame and wait for it to synchronize with the encoder thread. |
| 432 video_source_.IncomingCapturedFrame(CreateFrame(1, nullptr)); |
| 433 sink_.WaitForEncodedFrame(1); |
| 434 // The encoder have been configured once when the first frame is received. |
| 435 EXPECT_EQ(1, sink_.number_of_reconfigurations()); |
| 436 EXPECT_EQ(kVideoCodecVP8, fake_encoder_.codec_config().codecType); |
| 437 EXPECT_EQ(kNumStreams, fake_encoder_.codec_config().numberOfSimulcastStreams); |
| 438 EXPECT_EQ(kNumTl, fake_encoder_.codec_config().VP8()->numberOfTemporalLayers); |
| 439 // Resilience is off for single stream and no temporal layers with nack on. |
| 440 EXPECT_FALSE(fake_encoder_.codec_config().VP8()->resilience); |
| 441 vie_encoder_->Stop(); |
| 442 } |
| 443 |
| 444 TEST_F(ViEEncoderTest, Vp8ResilienceIsOnFor1SL1TLWithNackDisabled) { |
| 445 const bool kNackEnabled = false; |
| 446 const size_t kNumStreams = 1; |
| 447 const size_t kNumTl = 1; |
| 448 ResetEncoder("VP8", kNumStreams, kNumTl, kNackEnabled); |
| 449 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); |
| 450 |
| 451 // Capture a frame and wait for it to synchronize with the encoder thread. |
| 452 video_source_.IncomingCapturedFrame(CreateFrame(1, nullptr)); |
| 453 sink_.WaitForEncodedFrame(1); |
| 454 // The encoder have been configured once when the first frame is received. |
| 455 EXPECT_EQ(1, sink_.number_of_reconfigurations()); |
| 456 EXPECT_EQ(kVideoCodecVP8, fake_encoder_.codec_config().codecType); |
| 457 EXPECT_EQ(kNumStreams, fake_encoder_.codec_config().numberOfSimulcastStreams); |
| 458 EXPECT_EQ(kNumTl, fake_encoder_.codec_config().VP8()->numberOfTemporalLayers); |
| 459 // Resilience is on for single stream and no temporal layers with nack off. |
| 460 EXPECT_TRUE(fake_encoder_.codec_config().VP8()->resilience); |
| 461 vie_encoder_->Stop(); |
| 462 } |
| 463 |
| 464 TEST_F(ViEEncoderTest, Vp8ResilienceIsOnFor2SL1TlWithNackEnabled) { |
| 465 const bool kNackEnabled = true; |
| 466 const size_t kNumStreams = 2; |
| 467 const size_t kNumTl = 1; |
| 468 ResetEncoder("VP8", kNumStreams, kNumTl, kNackEnabled); |
| 469 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); |
| 470 |
| 471 // Capture a frame and wait for it to synchronize with the encoder thread. |
| 472 video_source_.IncomingCapturedFrame(CreateFrame(1, nullptr)); |
| 473 sink_.WaitForEncodedFrame(1); |
| 474 // The encoder have been configured once when the first frame is received. |
| 475 EXPECT_EQ(1, sink_.number_of_reconfigurations()); |
| 476 EXPECT_EQ(kVideoCodecVP8, fake_encoder_.codec_config().codecType); |
| 477 EXPECT_EQ(kNumStreams, fake_encoder_.codec_config().numberOfSimulcastStreams); |
| 478 EXPECT_EQ(kNumTl, fake_encoder_.codec_config().VP8()->numberOfTemporalLayers); |
| 479 // Resilience is on if not single stream. |
| 480 EXPECT_TRUE(fake_encoder_.codec_config().VP8()->resilience); |
| 481 vie_encoder_->Stop(); |
| 482 } |
| 483 |
| 484 TEST_F(ViEEncoderTest, Vp8ResilienceIsOnFor1SL2TlWithNackEnabled) { |
| 485 const bool kNackEnabled = true; |
| 486 const size_t kNumStreams = 1; |
| 487 const size_t kNumTl = 2; |
| 488 ResetEncoder("VP8", kNumStreams, kNumTl, kNackEnabled); |
| 489 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); |
| 490 |
| 491 // Capture a frame and wait for it to synchronize with the encoder thread. |
| 492 video_source_.IncomingCapturedFrame(CreateFrame(1, nullptr)); |
| 493 sink_.WaitForEncodedFrame(1); |
| 494 // The encoder have been configured once when the first frame is received. |
| 495 EXPECT_EQ(1, sink_.number_of_reconfigurations()); |
| 496 EXPECT_EQ(kVideoCodecVP8, fake_encoder_.codec_config().codecType); |
| 497 EXPECT_EQ(kNumStreams, fake_encoder_.codec_config().numberOfSimulcastStreams); |
| 498 EXPECT_EQ(kNumTl, fake_encoder_.codec_config().VP8()->numberOfTemporalLayers); |
| 499 // Resilience is on for temporal layers. |
| 500 EXPECT_TRUE(fake_encoder_.codec_config().VP8()->resilience); |
| 501 vie_encoder_->Stop(); |
| 502 } |
| 503 |
383 TEST_F(ViEEncoderTest, SwitchSourceDeregisterEncoderAsSink) { | 504 TEST_F(ViEEncoderTest, SwitchSourceDeregisterEncoderAsSink) { |
384 EXPECT_TRUE(video_source_.has_sinks()); | 505 EXPECT_TRUE(video_source_.has_sinks()); |
385 test::FrameForwarder new_video_source; | 506 test::FrameForwarder new_video_source; |
386 vie_encoder_->SetSource(&new_video_source, | 507 vie_encoder_->SetSource(&new_video_source, |
387 VideoSendStream::DegradationPreference::kBalanced); | 508 VideoSendStream::DegradationPreference::kBalanced); |
388 EXPECT_FALSE(video_source_.has_sinks()); | 509 EXPECT_FALSE(video_source_.has_sinks()); |
389 EXPECT_TRUE(new_video_source.has_sinks()); | 510 EXPECT_TRUE(new_video_source.has_sinks()); |
390 | 511 |
391 vie_encoder_->Stop(); | 512 vie_encoder_->Stop(); |
392 } | 513 } |
393 | 514 |
394 TEST_F(ViEEncoderTest, SinkWantsRotationApplied) { | 515 TEST_F(ViEEncoderTest, SinkWantsRotationApplied) { |
395 EXPECT_FALSE(video_source_.sink_wants().rotation_applied); | 516 EXPECT_FALSE(video_source_.sink_wants().rotation_applied); |
396 vie_encoder_->SetSink(&sink_, true /*rotation_applied*/); | 517 vie_encoder_->SetSink(&sink_, true /*rotation_applied*/); |
397 EXPECT_TRUE(video_source_.sink_wants().rotation_applied); | 518 EXPECT_TRUE(video_source_.sink_wants().rotation_applied); |
398 vie_encoder_->Stop(); | 519 vie_encoder_->Stop(); |
399 } | 520 } |
400 | 521 |
401 TEST_F(ViEEncoderTest, SinkWantsFromOveruseDetector) { | 522 TEST_F(ViEEncoderTest, SinkWantsFromOveruseDetector) { |
402 const int kTargetBitrateBps = 100000; | |
403 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); | 523 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); |
404 | 524 |
405 EXPECT_FALSE(video_source_.sink_wants().max_pixel_count); | 525 EXPECT_FALSE(video_source_.sink_wants().max_pixel_count); |
406 EXPECT_FALSE(video_source_.sink_wants().max_pixel_count_step_up); | 526 EXPECT_FALSE(video_source_.sink_wants().max_pixel_count_step_up); |
407 | 527 |
408 int frame_width = 1280; | 528 int frame_width = 1280; |
409 int frame_height = 720; | 529 int frame_height = 720; |
410 | 530 |
411 // Trigger CPU overuse kMaxCpuDowngrades times. Every time, ViEEncoder should | 531 // Trigger CPU overuse kMaxCpuDowngrades times. Every time, ViEEncoder should |
412 // request lower resolution. | 532 // request lower resolution. |
(...skipping 29 matching lines...) Expand all Loading... |
442 vie_encoder_->TriggerCpuNormalUsage(); | 562 vie_encoder_->TriggerCpuNormalUsage(); |
443 EXPECT_FALSE(video_source_.sink_wants().max_pixel_count); | 563 EXPECT_FALSE(video_source_.sink_wants().max_pixel_count); |
444 EXPECT_EQ(video_source_.sink_wants().max_pixel_count_step_up.value_or(0), | 564 EXPECT_EQ(video_source_.sink_wants().max_pixel_count_step_up.value_or(0), |
445 frame_width * frame_height); | 565 frame_width * frame_height); |
446 | 566 |
447 vie_encoder_->Stop(); | 567 vie_encoder_->Stop(); |
448 } | 568 } |
449 | 569 |
450 TEST_F(ViEEncoderTest, | 570 TEST_F(ViEEncoderTest, |
451 ResolutionSinkWantsResetOnSetSourceWithDisabledResolutionScaling) { | 571 ResolutionSinkWantsResetOnSetSourceWithDisabledResolutionScaling) { |
452 const int kTargetBitrateBps = 100000; | |
453 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); | 572 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); |
454 | 573 |
455 EXPECT_FALSE(video_source_.sink_wants().max_pixel_count); | 574 EXPECT_FALSE(video_source_.sink_wants().max_pixel_count); |
456 EXPECT_FALSE(video_source_.sink_wants().max_pixel_count_step_up); | 575 EXPECT_FALSE(video_source_.sink_wants().max_pixel_count_step_up); |
457 | 576 |
458 int frame_width = 1280; | 577 int frame_width = 1280; |
459 int frame_height = 720; | 578 int frame_height = 720; |
460 | 579 |
461 // Trigger CPU overuse. | 580 // Trigger CPU overuse. |
462 vie_encoder_->TriggerCpuOveruse(); | 581 vie_encoder_->TriggerCpuOveruse(); |
(...skipping 26 matching lines...) Expand all Loading... |
489 VideoSendStream::DegradationPreference::kBalanced); | 608 VideoSendStream::DegradationPreference::kBalanced); |
490 EXPECT_LT(new_video_source.sink_wants().max_pixel_count.value_or( | 609 EXPECT_LT(new_video_source.sink_wants().max_pixel_count.value_or( |
491 std::numeric_limits<int>::max()), | 610 std::numeric_limits<int>::max()), |
492 frame_width * frame_height); | 611 frame_width * frame_height); |
493 EXPECT_FALSE(new_video_source.sink_wants().max_pixel_count_step_up); | 612 EXPECT_FALSE(new_video_source.sink_wants().max_pixel_count_step_up); |
494 | 613 |
495 vie_encoder_->Stop(); | 614 vie_encoder_->Stop(); |
496 } | 615 } |
497 | 616 |
498 TEST_F(ViEEncoderTest, StatsTracksAdaptationStats) { | 617 TEST_F(ViEEncoderTest, StatsTracksAdaptationStats) { |
499 const int kTargetBitrateBps = 100000; | |
500 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); | 618 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); |
501 | 619 |
502 int frame_width = 1280; | 620 int frame_width = 1280; |
503 int frame_height = 720; | 621 int frame_height = 720; |
504 | 622 |
505 video_source_.IncomingCapturedFrame( | 623 video_source_.IncomingCapturedFrame( |
506 CreateFrame(1, frame_width, frame_height)); | 624 CreateFrame(1, frame_width, frame_height)); |
507 sink_.WaitForEncodedFrame(1); | 625 sink_.WaitForEncodedFrame(1); |
508 VideoSendStream::Stats stats = stats_proxy_->GetStats(); | 626 VideoSendStream::Stats stats = stats_proxy_->GetStats(); |
509 EXPECT_FALSE(stats.cpu_limited_resolution); | 627 EXPECT_FALSE(stats.cpu_limited_resolution); |
(...skipping 16 matching lines...) Expand all Loading... |
526 sink_.WaitForEncodedFrame(3); | 644 sink_.WaitForEncodedFrame(3); |
527 | 645 |
528 stats = stats_proxy_->GetStats(); | 646 stats = stats_proxy_->GetStats(); |
529 EXPECT_FALSE(stats.cpu_limited_resolution); | 647 EXPECT_FALSE(stats.cpu_limited_resolution); |
530 EXPECT_EQ(2, stats.number_of_cpu_adapt_changes); | 648 EXPECT_EQ(2, stats.number_of_cpu_adapt_changes); |
531 | 649 |
532 vie_encoder_->Stop(); | 650 vie_encoder_->Stop(); |
533 } | 651 } |
534 | 652 |
535 TEST_F(ViEEncoderTest, StatsTracksAdaptationStatsWhenSwitchingSource) { | 653 TEST_F(ViEEncoderTest, StatsTracksAdaptationStatsWhenSwitchingSource) { |
536 const int kTargetBitrateBps = 100000; | |
537 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); | 654 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); |
538 | 655 |
539 // Trigger CPU overuse. | 656 // Trigger CPU overuse. |
540 vie_encoder_->TriggerCpuOveruse(); | 657 vie_encoder_->TriggerCpuOveruse(); |
541 int frame_width = 1280; | 658 int frame_width = 1280; |
542 int frame_height = 720; | 659 int frame_height = 720; |
543 | 660 |
544 video_source_.IncomingCapturedFrame( | 661 video_source_.IncomingCapturedFrame( |
545 CreateFrame(1, frame_width, frame_height)); | 662 CreateFrame(1, frame_width, frame_height)); |
546 sink_.WaitForEncodedFrame(1); | 663 sink_.WaitForEncodedFrame(1); |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
588 CreateFrame(5, frame_width, frame_height)); | 705 CreateFrame(5, frame_width, frame_height)); |
589 sink_.WaitForEncodedFrame(5); | 706 sink_.WaitForEncodedFrame(5); |
590 stats = stats_proxy_->GetStats(); | 707 stats = stats_proxy_->GetStats(); |
591 EXPECT_FALSE(stats.cpu_limited_resolution); | 708 EXPECT_FALSE(stats.cpu_limited_resolution); |
592 EXPECT_EQ(2, stats.number_of_cpu_adapt_changes); | 709 EXPECT_EQ(2, stats.number_of_cpu_adapt_changes); |
593 | 710 |
594 vie_encoder_->Stop(); | 711 vie_encoder_->Stop(); |
595 } | 712 } |
596 | 713 |
597 TEST_F(ViEEncoderTest, UMACpuLimitedResolutionInPercent) { | 714 TEST_F(ViEEncoderTest, UMACpuLimitedResolutionInPercent) { |
598 const int kTargetBitrateBps = 100000; | |
599 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); | 715 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); |
600 | 716 |
601 int frame_width = 640; | 717 int frame_width = 640; |
602 int frame_height = 360; | 718 int frame_height = 360; |
603 | 719 |
604 for (int i = 1; i <= SendStatisticsProxy::kMinRequiredMetricsSamples; ++i) { | 720 for (int i = 1; i <= SendStatisticsProxy::kMinRequiredMetricsSamples; ++i) { |
605 video_source_.IncomingCapturedFrame( | 721 video_source_.IncomingCapturedFrame( |
606 CreateFrame(i, frame_width, frame_height)); | 722 CreateFrame(i, frame_width, frame_height)); |
607 sink_.WaitForEncodedFrame(i); | 723 sink_.WaitForEncodedFrame(i); |
608 } | 724 } |
(...skipping 10 matching lines...) Expand all Loading... |
619 vie_encoder_->Stop(); | 735 vie_encoder_->Stop(); |
620 | 736 |
621 stats_proxy_.reset(); | 737 stats_proxy_.reset(); |
622 EXPECT_EQ(1, | 738 EXPECT_EQ(1, |
623 metrics::NumSamples("WebRTC.Video.CpuLimitedResolutionInPercent")); | 739 metrics::NumSamples("WebRTC.Video.CpuLimitedResolutionInPercent")); |
624 EXPECT_EQ( | 740 EXPECT_EQ( |
625 1, metrics::NumEvents("WebRTC.Video.CpuLimitedResolutionInPercent", 50)); | 741 1, metrics::NumEvents("WebRTC.Video.CpuLimitedResolutionInPercent", 50)); |
626 } | 742 } |
627 | 743 |
628 } // namespace webrtc | 744 } // namespace webrtc |
OLD | NEW |