OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2013 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 #include <vector> | 12 #include <vector> |
13 | 13 |
14 #include "vpx/vp8cx.h" | 14 #include "vpx/vp8cx.h" |
15 #include "vpx/vpx_encoder.h" | 15 #include "vpx/vpx_encoder.h" |
16 #include "webrtc/modules/video_coding/codecs/vp8/screenshare_layers.h" | 16 #include "webrtc/modules/video_coding/codecs/vp8/screenshare_layers.h" |
17 #include "webrtc/modules/video_coding/include/video_codec_interface.h" | 17 #include "webrtc/modules/video_coding/include/video_codec_interface.h" |
18 #include "webrtc/modules/video_coding/utility/mock/mock_frame_dropper.h" | 18 #include "webrtc/modules/video_coding/utility/mock/mock_frame_dropper.h" |
19 #include "webrtc/system_wrappers/include/clock.h" | 19 #include "webrtc/system_wrappers/include/clock.h" |
20 #include "webrtc/system_wrappers/include/metrics.h" | 20 #include "webrtc/system_wrappers/include/metrics.h" |
21 #include "webrtc/system_wrappers/include/metrics_default.h" | 21 #include "webrtc/system_wrappers/include/metrics_default.h" |
22 #include "webrtc/test/gtest.h" | 22 #include "webrtc/test/gtest.h" |
23 | 23 |
24 using ::testing::_; | 24 using ::testing::_; |
25 using ::testing::ElementsAre; | |
26 using ::testing::NiceMock; | 25 using ::testing::NiceMock; |
27 using ::testing::Return; | 26 using ::testing::Return; |
28 | 27 |
29 namespace webrtc { | 28 namespace webrtc { |
30 | 29 |
31 // 5 frames per second at 90 kHz. | 30 // 5 frames per second at 90 kHz. |
32 const uint32_t kTimestampDelta5Fps = 90000 / 5; | 31 const uint32_t kTimestampDelta5Fps = 90000 / 5; |
33 const int kDefaultQp = 54; | 32 const int kDefaultQp = 54; |
34 const int kDefaultTl0BitrateKbps = 200; | 33 const int kDefaultTl0BitrateKbps = 200; |
35 const int kDefaultTl1BitrateKbps = 2000; | 34 const int kDefaultTl1BitrateKbps = 2000; |
(...skipping 19 matching lines...) Expand all Loading... |
55 layers_->PopulateCodecSpecific(base_sync, vp8_info, timestamp); | 54 layers_->PopulateCodecSpecific(base_sync, vp8_info, timestamp); |
56 ASSERT_NE(-1, frame_size_); | 55 ASSERT_NE(-1, frame_size_); |
57 layers_->FrameEncoded(frame_size_, timestamp, kDefaultQp); | 56 layers_->FrameEncoded(frame_size_, timestamp, kDefaultQp); |
58 } | 57 } |
59 | 58 |
60 void ConfigureBitrates() { | 59 void ConfigureBitrates() { |
61 vpx_codec_enc_cfg_t vpx_cfg; | 60 vpx_codec_enc_cfg_t vpx_cfg; |
62 memset(&vpx_cfg, 0, sizeof(vpx_codec_enc_cfg_t)); | 61 memset(&vpx_cfg, 0, sizeof(vpx_codec_enc_cfg_t)); |
63 vpx_cfg.rc_min_quantizer = min_qp_; | 62 vpx_cfg.rc_min_quantizer = min_qp_; |
64 vpx_cfg.rc_max_quantizer = max_qp_; | 63 vpx_cfg.rc_max_quantizer = max_qp_; |
65 EXPECT_THAT(layers_->OnRatesUpdated(kDefaultTl0BitrateKbps, | 64 EXPECT_TRUE(layers_->ConfigureBitrates( |
66 kDefaultTl1BitrateKbps, kFrameRate), | 65 kDefaultTl0BitrateKbps, kDefaultTl1BitrateKbps, kFrameRate, &vpx_cfg)); |
67 ElementsAre(kDefaultTl0BitrateKbps, | |
68 kDefaultTl1BitrateKbps - kDefaultTl0BitrateKbps)); | |
69 EXPECT_TRUE(layers_->UpdateConfiguration(&vpx_cfg)); | |
70 frame_size_ = ((vpx_cfg.rc_target_bitrate * 1000) / 8) / kFrameRate; | 66 frame_size_ = ((vpx_cfg.rc_target_bitrate * 1000) / 8) / kFrameRate; |
71 } | 67 } |
72 | 68 |
73 void WithQpLimits(int min_qp, int max_qp) { | 69 void WithQpLimits(int min_qp, int max_qp) { |
74 min_qp_ = min_qp; | 70 min_qp_ = min_qp; |
75 max_qp_ = max_qp; | 71 max_qp_ = max_qp; |
76 } | 72 } |
77 | 73 |
78 int RunGracePeriod() { | 74 int RunGracePeriod() { |
79 int flags = 0; | 75 int flags = 0; |
(...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
370 } | 366 } |
371 } | 367 } |
372 } | 368 } |
373 | 369 |
374 EXPECT_EQ(50, tl0_frames + tl1_frames); | 370 EXPECT_EQ(50, tl0_frames + tl1_frames); |
375 EXPECT_EQ(50, dropped_frames); | 371 EXPECT_EQ(50, dropped_frames); |
376 } | 372 } |
377 | 373 |
378 TEST_F(ScreenshareLayerTest, TargetBitrateCappedByTL0) { | 374 TEST_F(ScreenshareLayerTest, TargetBitrateCappedByTL0) { |
379 vpx_codec_enc_cfg_t cfg = GetConfig(); | 375 vpx_codec_enc_cfg_t cfg = GetConfig(); |
380 const int kTl0_kbps = 100; | 376 layers_->ConfigureBitrates(100, 1000, 5, &cfg); |
381 const int kTl1_kbps = 1000; | |
382 layers_->OnRatesUpdated(kTl0_kbps, kTl1_kbps, 5); | |
383 | |
384 EXPECT_THAT(layers_->OnRatesUpdated(kTl0_kbps, kTl1_kbps, 5), | |
385 ElementsAre(kTl0_kbps, kTl1_kbps - kTl0_kbps)); | |
386 EXPECT_TRUE(layers_->UpdateConfiguration(&cfg)); | |
387 | 377 |
388 EXPECT_EQ(static_cast<unsigned int>( | 378 EXPECT_EQ(static_cast<unsigned int>( |
389 ScreenshareLayers::kMaxTL0FpsReduction * kTl0_kbps + 0.5), | 379 ScreenshareLayers::kMaxTL0FpsReduction * 100 + 0.5), |
390 cfg.rc_target_bitrate); | 380 cfg.rc_target_bitrate); |
391 } | 381 } |
392 | 382 |
393 TEST_F(ScreenshareLayerTest, TargetBitrateCappedByTL1) { | 383 TEST_F(ScreenshareLayerTest, TargetBitrateCappedByTL1) { |
394 vpx_codec_enc_cfg_t cfg = GetConfig(); | 384 vpx_codec_enc_cfg_t cfg = GetConfig(); |
395 const int kTl0_kbps = 100; | 385 layers_->ConfigureBitrates(100, 450, 5, &cfg); |
396 const int kTl1_kbps = 450; | |
397 EXPECT_THAT(layers_->OnRatesUpdated(kTl0_kbps, kTl1_kbps, 5), | |
398 ElementsAre(kTl0_kbps, kTl1_kbps - kTl0_kbps)); | |
399 EXPECT_TRUE(layers_->UpdateConfiguration(&cfg)); | |
400 | 386 |
401 EXPECT_EQ(static_cast<unsigned int>( | 387 EXPECT_EQ(static_cast<unsigned int>( |
402 kTl1_kbps / ScreenshareLayers::kAcceptableTargetOvershoot), | 388 450 / ScreenshareLayers::kAcceptableTargetOvershoot), |
403 cfg.rc_target_bitrate); | 389 cfg.rc_target_bitrate); |
404 } | 390 } |
405 | 391 |
406 TEST_F(ScreenshareLayerTest, TargetBitrateBelowTL0) { | 392 TEST_F(ScreenshareLayerTest, TargetBitrateBelowTL0) { |
407 vpx_codec_enc_cfg_t cfg = GetConfig(); | 393 vpx_codec_enc_cfg_t cfg = GetConfig(); |
408 const int kTl0_kbps = 100; | 394 layers_->ConfigureBitrates(100, 100, 5, &cfg); |
409 const int kTl1_kbps = 100; | |
410 EXPECT_THAT(layers_->OnRatesUpdated(kTl0_kbps, kTl1_kbps, 5), | |
411 ElementsAre(kTl0_kbps)); | |
412 EXPECT_TRUE(layers_->UpdateConfiguration(&cfg)); | |
413 | 395 |
414 EXPECT_EQ(static_cast<uint32_t>(kTl1_kbps), cfg.rc_target_bitrate); | 396 EXPECT_EQ(100U, cfg.rc_target_bitrate); |
415 } | 397 } |
416 | 398 |
417 TEST_F(ScreenshareLayerTest, EncoderDrop) { | 399 TEST_F(ScreenshareLayerTest, EncoderDrop) { |
418 ConfigureBitrates(); | 400 ConfigureBitrates(); |
419 CodecSpecificInfoVP8 vp8_info; | 401 CodecSpecificInfoVP8 vp8_info; |
420 vpx_codec_enc_cfg_t cfg = GetConfig(); | 402 vpx_codec_enc_cfg_t cfg = GetConfig(); |
421 | 403 |
422 uint32_t timestamp = RunGracePeriod(); | 404 uint32_t timestamp = RunGracePeriod(); |
423 timestamp = SkipUntilTl(0, timestamp); | 405 timestamp = SkipUntilTl(0, timestamp); |
424 | 406 |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
464 EXPECT_EQ(cfg.rc_max_quantizer, static_cast<unsigned int>(kDefaultQp)); | 446 EXPECT_EQ(cfg.rc_max_quantizer, static_cast<unsigned int>(kDefaultQp)); |
465 layers_->FrameEncoded(frame_size_, timestamp, kDefaultQp); | 447 layers_->FrameEncoded(frame_size_, timestamp, kDefaultQp); |
466 } | 448 } |
467 | 449 |
468 TEST_F(ScreenshareLayerTest, RespectsMaxIntervalBetweenFrames) { | 450 TEST_F(ScreenshareLayerTest, RespectsMaxIntervalBetweenFrames) { |
469 const int kLowBitrateKbps = 50; | 451 const int kLowBitrateKbps = 50; |
470 const int kLargeFrameSizeBytes = 100000; | 452 const int kLargeFrameSizeBytes = 100000; |
471 const uint32_t kStartTimestamp = 1234; | 453 const uint32_t kStartTimestamp = 1234; |
472 | 454 |
473 vpx_codec_enc_cfg_t cfg = GetConfig(); | 455 vpx_codec_enc_cfg_t cfg = GetConfig(); |
474 layers_->OnRatesUpdated(kLowBitrateKbps, kLowBitrateKbps, 5); | 456 layers_->ConfigureBitrates(kLowBitrateKbps, kLowBitrateKbps, 5, &cfg); |
475 layers_->UpdateConfiguration(&cfg); | |
476 | 457 |
477 EXPECT_EQ(ScreenshareLayers::kTl0Flags, | 458 EXPECT_EQ(ScreenshareLayers::kTl0Flags, |
478 layers_->EncodeFlags(kStartTimestamp)); | 459 layers_->EncodeFlags(kStartTimestamp)); |
479 layers_->FrameEncoded(kLargeFrameSizeBytes, kStartTimestamp, kDefaultQp); | 460 layers_->FrameEncoded(kLargeFrameSizeBytes, kStartTimestamp, kDefaultQp); |
480 | 461 |
481 const uint32_t kTwoSecondsLater = | 462 const uint32_t kTwoSecondsLater = |
482 kStartTimestamp + (ScreenshareLayers::kMaxFrameIntervalMs * 90); | 463 kStartTimestamp + (ScreenshareLayers::kMaxFrameIntervalMs * 90); |
483 | 464 |
484 // Sanity check, repayment time should exceed kMaxFrameIntervalMs. | 465 // Sanity check, repayment time should exceed kMaxFrameIntervalMs. |
485 ASSERT_GT(kStartTimestamp + 90 * (kLargeFrameSizeBytes * 8) / kLowBitrateKbps, | 466 ASSERT_GT(kStartTimestamp + 90 * (kLargeFrameSizeBytes * 8) / kLowBitrateKbps, |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
564 metrics::NumEvents("WebRTC.Video.Screenshare.Layer1.Qp", kTl1Qp)); | 545 metrics::NumEvents("WebRTC.Video.Screenshare.Layer1.Qp", kTl1Qp)); |
565 EXPECT_EQ(1, | 546 EXPECT_EQ(1, |
566 metrics::NumEvents("WebRTC.Video.Screenshare.Layer0.TargetBitrate", | 547 metrics::NumEvents("WebRTC.Video.Screenshare.Layer0.TargetBitrate", |
567 kDefaultTl0BitrateKbps)); | 548 kDefaultTl0BitrateKbps)); |
568 EXPECT_EQ(1, | 549 EXPECT_EQ(1, |
569 metrics::NumEvents("WebRTC.Video.Screenshare.Layer1.TargetBitrate", | 550 metrics::NumEvents("WebRTC.Video.Screenshare.Layer1.TargetBitrate", |
570 kDefaultTl1BitrateKbps)); | 551 kDefaultTl1BitrateKbps)); |
571 } | 552 } |
572 | 553 |
573 } // namespace webrtc | 554 } // namespace webrtc |
OLD | NEW |