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