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 |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
58 // above 50 + 10 kbps again. | 58 // above 50 + 10 kbps again. |
59 const uint32_t kThresholdBps = 50000; | 59 const uint32_t kThresholdBps = 50000; |
60 const uint32_t kWindowBps = 10000; | 60 const uint32_t kWindowBps = 10000; |
61 media_opt_.SuspendBelowMinBitrate(kThresholdBps, kWindowBps); | 61 media_opt_.SuspendBelowMinBitrate(kThresholdBps, kWindowBps); |
62 | 62 |
63 // The video should not be suspended from the start. | 63 // The video should not be suspended from the start. |
64 EXPECT_FALSE(media_opt_.IsVideoSuspended()); | 64 EXPECT_FALSE(media_opt_.IsVideoSuspended()); |
65 | 65 |
66 uint32_t target_bitrate_kbps = 100; | 66 uint32_t target_bitrate_kbps = 100; |
67 media_opt_.SetTargetRates(target_bitrate_kbps * 1000, | 67 media_opt_.SetTargetRates(target_bitrate_kbps * 1000, |
68 0, // Lossrate. | 68 0, // Lossrate. |
69 100, | 69 100, // RTT in ms. |
70 NULL, | 70 nullptr, nullptr); |
71 NULL); // RTT in ms. | |
72 media_opt_.EnableFrameDropper(true); | 71 media_opt_.EnableFrameDropper(true); |
73 for (int time = 0; time < 2000; time += frame_time_ms_) { | 72 for (int time = 0; time < 2000; time += frame_time_ms_) { |
74 ASSERT_NO_FATAL_FAILURE(AddFrameAndAdvanceTime(target_bitrate_kbps, false)); | 73 ASSERT_NO_FATAL_FAILURE(AddFrameAndAdvanceTime(target_bitrate_kbps, false)); |
75 } | 74 } |
76 | 75 |
77 // Set the target rate below the limit for muting. | 76 // Set the target rate below the limit for muting. |
78 media_opt_.SetTargetRates(kThresholdBps - 1000, | 77 media_opt_.SetTargetRates(kThresholdBps - 1000, |
79 0, // Lossrate. | 78 0, // Lossrate. |
80 100, | 79 100, // RTT in ms. |
81 NULL, | 80 nullptr, nullptr); |
82 NULL); // RTT in ms. | |
83 // Expect the muter to engage immediately and stay muted. | 81 // Expect the muter to engage immediately and stay muted. |
84 // Test during 2 seconds. | 82 // Test during 2 seconds. |
85 for (int time = 0; time < 2000; time += frame_time_ms_) { | 83 for (int time = 0; time < 2000; time += frame_time_ms_) { |
86 EXPECT_TRUE(media_opt_.IsVideoSuspended()); | 84 EXPECT_TRUE(media_opt_.IsVideoSuspended()); |
87 ASSERT_NO_FATAL_FAILURE(AddFrameAndAdvanceTime(target_bitrate_kbps, true)); | 85 ASSERT_NO_FATAL_FAILURE(AddFrameAndAdvanceTime(target_bitrate_kbps, true)); |
88 } | 86 } |
89 | 87 |
90 // Set the target above the limit for muting, but not above the | 88 // Set the target above the limit for muting, but not above the |
91 // limit + window. | 89 // limit + window. |
92 media_opt_.SetTargetRates(kThresholdBps + 1000, | 90 media_opt_.SetTargetRates(kThresholdBps + 1000, |
93 0, // Lossrate. | 91 0, // Lossrate. |
94 100, | 92 100, // RTT in ms. |
95 NULL, | 93 nullptr, nullptr); |
96 NULL); // RTT in ms. | 94 // Expect the muter to stay muted. |
97 // Expect the muter to stay muted. | |
98 // Test during 2 seconds. | 95 // Test during 2 seconds. |
99 for (int time = 0; time < 2000; time += frame_time_ms_) { | 96 for (int time = 0; time < 2000; time += frame_time_ms_) { |
100 EXPECT_TRUE(media_opt_.IsVideoSuspended()); | 97 EXPECT_TRUE(media_opt_.IsVideoSuspended()); |
101 ASSERT_NO_FATAL_FAILURE(AddFrameAndAdvanceTime(target_bitrate_kbps, true)); | 98 ASSERT_NO_FATAL_FAILURE(AddFrameAndAdvanceTime(target_bitrate_kbps, true)); |
102 } | 99 } |
103 | 100 |
104 // Set the target above limit + window. | 101 // Set the target above limit + window. |
105 media_opt_.SetTargetRates(kThresholdBps + kWindowBps + 1000, | 102 media_opt_.SetTargetRates(kThresholdBps + kWindowBps + 1000, |
106 0, // Lossrate. | 103 0, // Lossrate. |
107 100, | 104 100, // RTT in ms. |
108 NULL, | 105 nullptr, nullptr); |
109 NULL); // RTT in ms. | |
110 // Expect the muter to disengage immediately. | 106 // Expect the muter to disengage immediately. |
111 // Test during 2 seconds. | 107 // Test during 2 seconds. |
112 for (int time = 0; time < 2000; time += frame_time_ms_) { | 108 for (int time = 0; time < 2000; time += frame_time_ms_) { |
113 EXPECT_FALSE(media_opt_.IsVideoSuspended()); | 109 EXPECT_FALSE(media_opt_.IsVideoSuspended()); |
114 ASSERT_NO_FATAL_FAILURE( | 110 ASSERT_NO_FATAL_FAILURE( |
115 AddFrameAndAdvanceTime((kThresholdBps + kWindowBps) / 1000, false)); | 111 AddFrameAndAdvanceTime((kThresholdBps + kWindowBps) / 1000, false)); |
116 } | 112 } |
117 } | 113 } |
118 | 114 |
| 115 TEST_F(TestMediaOptimization, ProtectsUsingFecBitrateAboveCodecMax) { |
| 116 static const int kCodecBitrateBps = 100000; |
| 117 static const int kMaxBitrateBps = 130000; |
| 118 |
| 119 class ProtectionCallback : public VCMProtectionCallback { |
| 120 int ProtectionRequest(const FecProtectionParams* delta_params, |
| 121 const FecProtectionParams* key_params, |
| 122 uint32_t* sent_video_rate_bps, |
| 123 uint32_t* sent_nack_rate_bps, |
| 124 uint32_t* sent_fec_rate_bps) override { |
| 125 *sent_video_rate_bps = kCodecBitrateBps; |
| 126 *sent_nack_rate_bps = 0; |
| 127 *sent_fec_rate_bps = fec_rate_bps_; |
| 128 return 0; |
| 129 } |
| 130 |
| 131 public: |
| 132 uint32_t fec_rate_bps_; |
| 133 } protection_callback; |
| 134 |
| 135 media_opt_.SetProtectionMethod(kFec); |
| 136 media_opt_.SetEncodingData(kVideoCodecVP8, kCodecBitrateBps, kCodecBitrateBps, |
| 137 640, 480, 30, 1, 1000); |
| 138 |
| 139 // Using 10% of codec bitrate for FEC, should still be able to use all of it. |
| 140 protection_callback.fec_rate_bps_ = kCodecBitrateBps / 10; |
| 141 uint32_t target_bitrate = media_opt_.SetTargetRates( |
| 142 kMaxBitrateBps, 0, 0, &protection_callback, nullptr); |
| 143 |
| 144 EXPECT_EQ(kCodecBitrateBps, static_cast<int>(target_bitrate)); |
| 145 |
| 146 // Using as much for codec bitrate as fec rate, new target rate should share |
| 147 // both equally, but only be half of max (since that ceiling should be hit). |
| 148 protection_callback.fec_rate_bps_ = kCodecBitrateBps; |
| 149 target_bitrate = media_opt_.SetTargetRates(kMaxBitrateBps, 128, 100, |
| 150 &protection_callback, nullptr); |
| 151 EXPECT_EQ(kMaxBitrateBps / 2, static_cast<int>(target_bitrate)); |
| 152 } |
| 153 |
119 } // namespace media_optimization | 154 } // namespace media_optimization |
120 } // namespace webrtc | 155 } // namespace webrtc |
OLD | NEW |