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

Side by Side Diff: webrtc/modules/video_coding/protection_bitrate_calculator_unittest.cc

Issue 1972083002: Move logic for calculating needed bitrate overhead used by NACK and FEC to VideoSender. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Addressed Åsas comments. Created 4 years, 6 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) 2013 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/modules/video_coding/media_optimization.h" 12 #include "webrtc/modules/video_coding/protection_bitrate_calculator.h"
13 #include "webrtc/system_wrappers/include/clock.h" 13 #include "webrtc/system_wrappers/include/clock.h"
14 14
15 namespace webrtc { 15 namespace webrtc {
16 namespace media_optimization {
17 16
18 class TestMediaOptimization : public ::testing::Test { 17 static const int kCodecBitrateBps = 100000;
18
19 class ProtectionBitrateCalculatorTest : public ::testing::Test {
19 protected: 20 protected:
20 enum { 21 enum {
21 kSampleRate = 90000 // RTP timestamps per second. 22 kSampleRate = 90000 // RTP timestamps per second.
22 }; 23 };
23 24
24 // Note: simulated clock starts at 1 seconds, since parts of webrtc use 0 as
25 // a special case (e.g. frame rate in media optimization).
26 TestMediaOptimization()
27 : clock_(1000),
28 media_opt_(&clock_),
29 frame_time_ms_(33),
30 next_timestamp_(0) {}
31
32 // This method mimics what happens in VideoSender::AddVideoFrame.
33 void AddFrameAndAdvanceTime(uint32_t bitrate_bps, bool expect_frame_drop) {
34 bool frame_dropped = media_opt_.DropFrame();
35 EXPECT_EQ(expect_frame_drop, frame_dropped);
36 if (!frame_dropped) {
37 size_t bytes_per_frame = bitrate_bps * frame_time_ms_ / (8 * 1000);
38 EncodedImage encoded_image;
39 encoded_image._length = bytes_per_frame;
40 encoded_image._timeStamp = next_timestamp_;
41 encoded_image._frameType = kVideoFrameKey;
42 ASSERT_EQ(VCM_OK, media_opt_.UpdateWithEncodedData(encoded_image));
43 }
44 next_timestamp_ += frame_time_ms_ * kSampleRate / 1000;
45 clock_.AdvanceTimeMilliseconds(frame_time_ms_);
46 }
47
48 SimulatedClock clock_;
49 MediaOptimization media_opt_;
50 int frame_time_ms_;
51 uint32_t next_timestamp_;
52 };
53
54 TEST_F(TestMediaOptimization, VerifyMuting) {
55 // Enable video suspension with these limits.
56 // Suspend the video when the rate is below 50 kbps and resume when it gets
57 // above 50 + 10 kbps again.
58 const uint32_t kThresholdBps = 50000;
59 const uint32_t kWindowBps = 10000;
60 media_opt_.SuspendBelowMinBitrate(kThresholdBps, kWindowBps);
61
62 // The video should not be suspended from the start.
63 EXPECT_FALSE(media_opt_.IsVideoSuspended());
64
65 uint32_t target_bitrate_kbps = 100;
66 media_opt_.SetTargetRates(target_bitrate_kbps * 1000,
67 0, // Lossrate.
68 100, // RTT in ms.
69 nullptr);
70 media_opt_.EnableFrameDropper(true);
71 for (int time = 0; time < 2000; time += frame_time_ms_) {
72 ASSERT_NO_FATAL_FAILURE(AddFrameAndAdvanceTime(target_bitrate_kbps, false));
73 }
74
75 // Set the target rate below the limit for muting.
76 media_opt_.SetTargetRates(kThresholdBps - 1000,
77 0, // Lossrate.
78 100, // RTT in ms.
79 nullptr);
80 // Expect the muter to engage immediately and stay muted.
81 // Test during 2 seconds.
82 for (int time = 0; time < 2000; time += frame_time_ms_) {
83 EXPECT_TRUE(media_opt_.IsVideoSuspended());
84 ASSERT_NO_FATAL_FAILURE(AddFrameAndAdvanceTime(target_bitrate_kbps, true));
85 }
86
87 // Set the target above the limit for muting, but not above the
88 // limit + window.
89 media_opt_.SetTargetRates(kThresholdBps + 1000,
90 0, // Lossrate.
91 100, // RTT in ms.
92 nullptr);
93 // Expect the muter to stay muted.
94 // Test during 2 seconds.
95 for (int time = 0; time < 2000; time += frame_time_ms_) {
96 EXPECT_TRUE(media_opt_.IsVideoSuspended());
97 ASSERT_NO_FATAL_FAILURE(AddFrameAndAdvanceTime(target_bitrate_kbps, true));
98 }
99
100 // Set the target above limit + window.
101 media_opt_.SetTargetRates(kThresholdBps + kWindowBps + 1000,
102 0, // Lossrate.
103 100, // RTT in ms.
104 nullptr);
105 // Expect the muter to disengage immediately.
106 // Test during 2 seconds.
107 for (int time = 0; time < 2000; time += frame_time_ms_) {
108 EXPECT_FALSE(media_opt_.IsVideoSuspended());
109 ASSERT_NO_FATAL_FAILURE(
110 AddFrameAndAdvanceTime((kThresholdBps + kWindowBps) / 1000, false));
111 }
112 }
113
114 TEST_F(TestMediaOptimization, ProtectsUsingFecBitrateAboveCodecMax) {
115 static const int kCodecBitrateBps = 100000;
116 static const int kMaxBitrateBps = 130000;
117
118 class ProtectionCallback : public VCMProtectionCallback { 25 class ProtectionCallback : public VCMProtectionCallback {
26 public:
119 int ProtectionRequest(const FecProtectionParams* delta_params, 27 int ProtectionRequest(const FecProtectionParams* delta_params,
120 const FecProtectionParams* key_params, 28 const FecProtectionParams* key_params,
121 uint32_t* sent_video_rate_bps, 29 uint32_t* sent_video_rate_bps,
122 uint32_t* sent_nack_rate_bps, 30 uint32_t* sent_nack_rate_bps,
123 uint32_t* sent_fec_rate_bps) override { 31 uint32_t* sent_fec_rate_bps) override {
124 *sent_video_rate_bps = kCodecBitrateBps; 32 *sent_video_rate_bps = kCodecBitrateBps;
125 *sent_nack_rate_bps = 0; 33 *sent_nack_rate_bps = nack_rate_bps_;
126 *sent_fec_rate_bps = fec_rate_bps_; 34 *sent_fec_rate_bps = fec_rate_bps_;
127 return 0; 35 return 0;
128 } 36 }
129 37
130 public: 38 uint32_t fec_rate_bps_ = 0;
131 uint32_t fec_rate_bps_; 39 uint32_t nack_rate_bps_ = 0;
132 } protection_callback; 40 };
133 41
134 media_opt_.SetProtectionMethod(kFec); 42 // Note: simulated clock starts at 1 seconds, since parts of webrtc use 0 as
135 media_opt_.SetEncodingData(kVideoCodecVP8, kCodecBitrateBps, kCodecBitrateBps, 43 // a special case (e.g. frame rate in media optimization).
136 640, 480, 30, 1, 1000); 44 ProtectionBitrateCalculatorTest()
45 : clock_(1000), media_opt_(&clock_, &protection_callback_) {}
137 46
138 // Using 10% of codec bitrate for FEC, should still be able to use all of it. 47 SimulatedClock clock_;
139 protection_callback.fec_rate_bps_ = kCodecBitrateBps / 10; 48 ProtectionCallback protection_callback_;
140 uint32_t target_bitrate = media_opt_.SetTargetRates( 49 ProtectionBitrateCalculator media_opt_;
141 kMaxBitrateBps, 0, 0, &protection_callback); 50 };
142 51
143 EXPECT_EQ(kCodecBitrateBps, static_cast<int>(target_bitrate)); 52 TEST_F(ProtectionBitrateCalculatorTest, ProtectsUsingFecBitrate) {
53 static const uint32_t kMaxBitrateBps = 130000;
54
55 media_opt_.SetProtectionMethod(true /*enable_fec*/, false /* enable_nack */);
56 media_opt_.SetEncodingData(kCodecBitrateBps, 640, 480, 30, 1, 1000);
57
58 // Using 10% of codec bitrate for FEC.
59 protection_callback_.fec_rate_bps_ = kCodecBitrateBps / 10;
60 uint32_t target_bitrate = media_opt_.SetTargetRates(kMaxBitrateBps, 30, 0, 0);
61
62 EXPECT_GT(target_bitrate, 0u);
63 EXPECT_GT(kMaxBitrateBps, target_bitrate);
144 64
145 // Using as much for codec bitrate as fec rate, new target rate should share 65 // Using as much for codec bitrate as fec rate, new target rate should share
146 // both equally, but only be half of max (since that ceiling should be hit). 66 // both equally, but only be half of max (since that ceiling should be hit).
147 protection_callback.fec_rate_bps_ = kCodecBitrateBps; 67 protection_callback_.fec_rate_bps_ = kCodecBitrateBps;
148 target_bitrate = media_opt_.SetTargetRates(kMaxBitrateBps, 128, 100, 68 target_bitrate = media_opt_.SetTargetRates(kMaxBitrateBps, 30, 128, 100);
149 &protection_callback); 69 EXPECT_EQ(kMaxBitrateBps / 2, target_bitrate);
150 EXPECT_EQ(kMaxBitrateBps / 2, static_cast<int>(target_bitrate));
151 } 70 }
152 71
153 } // namespace media_optimization 72 TEST_F(ProtectionBitrateCalculatorTest, ProtectsUsingNackBitrate) {
73 static const uint32_t kMaxBitrateBps = 130000;
74
75 media_opt_.SetProtectionMethod(false /*enable_fec*/, true /* enable_nack */);
76 media_opt_.SetEncodingData(kCodecBitrateBps, 640, 480, 30, 1, 1000);
77
78 uint32_t target_bitrate = media_opt_.SetTargetRates(kMaxBitrateBps, 30, 0, 0);
79
80 EXPECT_EQ(kMaxBitrateBps, target_bitrate);
81
82 // Using as much for codec bitrate as nack rate, new target rate should share
83 // both equally, but only be half of max (since that ceiling should be hit).
84 protection_callback_.nack_rate_bps_ = kMaxBitrateBps;
85 target_bitrate = media_opt_.SetTargetRates(kMaxBitrateBps, 30, 128, 100);
86 EXPECT_EQ(kMaxBitrateBps / 2, target_bitrate);
87 }
88
154 } // namespace webrtc 89 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/modules/video_coding/protection_bitrate_calculator.cc ('k') | webrtc/modules/video_coding/video_coding.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698