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 #include <algorithm> // max | 10 #include <algorithm> // max |
(...skipping 1103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1114 | 1114 |
1115 std::unique_ptr<RtpRtcp> rtp_rtcp_; | 1115 std::unique_ptr<RtpRtcp> rtp_rtcp_; |
1116 std::unique_ptr<internal::TransportAdapter> feedback_transport_; | 1116 std::unique_ptr<internal::TransportAdapter> feedback_transport_; |
1117 VideoSendStream* stream_; | 1117 VideoSendStream* stream_; |
1118 bool bitrate_capped_; | 1118 bool bitrate_capped_; |
1119 } test; | 1119 } test; |
1120 | 1120 |
1121 RunBaseTest(&test); | 1121 RunBaseTest(&test); |
1122 } | 1122 } |
1123 | 1123 |
| 1124 class MinTransmitBitrateTest : public test::SendTest, public test::FakeEncoder { |
| 1125 public: |
| 1126 static const uint32_t kMinTransmitBitrateBps = 400000; |
| 1127 static const uint32_t kActualEncodeBitrateBps = 40000; |
| 1128 static const uint32_t kMinFramesToSend = 10; |
| 1129 |
| 1130 explicit MinTransmitBitrateTest(bool test_switch_content_type) |
| 1131 : SendTest(test::CallTest::kDefaultTimeoutMs), |
| 1132 FakeEncoder(Clock::GetRealTimeClock()), |
| 1133 call_(nullptr), |
| 1134 send_stream_(nullptr), |
| 1135 frames_sent_(0), |
| 1136 running_without_padding_(test_switch_content_type) {} |
| 1137 |
| 1138 void OnVideoStreamsCreated( |
| 1139 VideoSendStream* send_stream, |
| 1140 const std::vector<VideoReceiveStream*>& receive_streams) override { |
| 1141 send_stream_ = send_stream; |
| 1142 } |
| 1143 |
| 1144 void ModifyVideoConfigs( |
| 1145 VideoSendStream::Config* send_config, |
| 1146 std::vector<VideoReceiveStream::Config>* receive_configs, |
| 1147 VideoEncoderConfig* encoder_config) override { |
| 1148 send_config->encoder_settings.encoder = this; |
| 1149 RTC_DCHECK_EQ(1u, encoder_config->streams.size()); |
| 1150 encoder_config->streams[0].target_bitrate_bps = kMinTransmitBitrateBps * 2; |
| 1151 encoder_config->streams[0].max_bitrate_bps = kMinTransmitBitrateBps * 4; |
| 1152 if (running_without_padding_) { |
| 1153 encoder_config->min_transmit_bitrate_bps = 0; |
| 1154 encoder_config->content_type = |
| 1155 VideoEncoderConfig::ContentType::kRealtimeVideo; |
| 1156 } else { |
| 1157 encoder_config->min_transmit_bitrate_bps = kMinTransmitBitrateBps; |
| 1158 encoder_config->content_type = VideoEncoderConfig::ContentType::kScreen; |
| 1159 } |
| 1160 encoder_config_ = *encoder_config; |
| 1161 } |
| 1162 |
| 1163 int32_t SetRates(uint32_t new_target_bitrate, uint32_t framerate) override { |
| 1164 // Make sure not to trigger on any default zero bitrates. |
| 1165 if (new_target_bitrate == 0) |
| 1166 return 0; |
| 1167 rtc::CritScope lock(&crit_); |
| 1168 return FakeEncoder::SetRates( |
| 1169 std::min<uint32_t>(new_target_bitrate, kActualEncodeBitrateBps / 1000), |
| 1170 framerate); |
| 1171 } |
| 1172 |
| 1173 int32_t Encode(const VideoFrame& input_image, |
| 1174 const CodecSpecificInfo* codec_specific_info, |
| 1175 const std::vector<FrameType>* frame_types) override { |
| 1176 int32_t res = |
| 1177 FakeEncoder::Encode(input_image, codec_specific_info, frame_types); |
| 1178 CheckDoneState(); |
| 1179 return res; |
| 1180 } |
| 1181 |
| 1182 void OnCallsCreated(Call* sender_call, Call* receiver_call) override { |
| 1183 call_ = sender_call; |
| 1184 } |
| 1185 |
| 1186 void CheckDoneState() { |
| 1187 rtc::CritScope lock(&crit_); |
| 1188 |
| 1189 if (running_without_padding_) |
| 1190 EXPECT_EQ(0, call_->GetStats().min_transmit_bitrate_bps); |
| 1191 |
| 1192 // Wait until at least kMinFramesToSend frames have been encoded, so that |
| 1193 // we have reliable data. |
| 1194 if (++frames_sent_ < kMinFramesToSend) |
| 1195 return; |
| 1196 |
| 1197 if (running_without_padding_) { |
| 1198 // We've sent kMinFramesToSend frames with default configuration, switch |
| 1199 // to enabling screen content and setting min transmit bitrate. |
| 1200 frames_sent_ = 0; |
| 1201 encoder_config_.min_transmit_bitrate_bps = kMinTransmitBitrateBps; |
| 1202 encoder_config_.content_type = VideoEncoderConfig::ContentType::kScreen; |
| 1203 send_stream_->ReconfigureVideoEncoder(encoder_config_); |
| 1204 running_without_padding_ = false; |
| 1205 return; |
| 1206 } |
| 1207 |
| 1208 // Make sure the pacer has been configured with a min transmit bitrate. |
| 1209 if (call_->GetStats().min_transmit_bitrate_bps > 0) |
| 1210 observation_complete_.Set(); |
| 1211 } |
| 1212 |
| 1213 void PerformTest() override { |
| 1214 ASSERT_TRUE(Wait()) << "Timed out waiting for a valid padding bitrate."; |
| 1215 } |
| 1216 |
| 1217 private: |
| 1218 rtc::CriticalSection crit_; |
| 1219 Call* call_; |
| 1220 VideoSendStream* send_stream_; |
| 1221 VideoEncoderConfig encoder_config_; |
| 1222 uint32_t frames_sent_ GUARDED_BY(crit_); |
| 1223 bool running_without_padding_; |
| 1224 }; |
| 1225 |
| 1226 TEST_F(VideoSendStreamTest, RespectsMinTransmitBitrate) { |
| 1227 MinTransmitBitrateTest test(false); |
| 1228 RunBaseTest(&test); |
| 1229 } |
| 1230 |
| 1231 TEST_F(VideoSendStreamTest, RespectsMinTransmitBitrateAfterContentSwitch) { |
| 1232 MinTransmitBitrateTest test(true); |
| 1233 RunBaseTest(&test); |
| 1234 } |
| 1235 |
1124 TEST_F(VideoSendStreamTest, CanReconfigureToUseStartBitrateAbovePreviousMax) { | 1236 TEST_F(VideoSendStreamTest, CanReconfigureToUseStartBitrateAbovePreviousMax) { |
1125 class StartBitrateObserver : public test::FakeEncoder { | 1237 class StartBitrateObserver : public test::FakeEncoder { |
1126 public: | 1238 public: |
1127 StartBitrateObserver() | 1239 StartBitrateObserver() |
1128 : FakeEncoder(Clock::GetRealTimeClock()), | 1240 : FakeEncoder(Clock::GetRealTimeClock()), |
1129 start_bitrate_changed_(false, false), | 1241 start_bitrate_changed_(false, false), |
1130 start_bitrate_kbps_(0) {} | 1242 start_bitrate_kbps_(0) {} |
1131 int32_t InitEncode(const VideoCodec* config, | 1243 int32_t InitEncode(const VideoCodec* config, |
1132 int32_t number_of_cores, | 1244 int32_t number_of_cores, |
1133 size_t max_payload_size) override { | 1245 size_t max_payload_size) override { |
(...skipping 1242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2376 observation_complete_.Set(); | 2488 observation_complete_.Set(); |
2377 } | 2489 } |
2378 } | 2490 } |
2379 } test; | 2491 } test; |
2380 | 2492 |
2381 RunBaseTest(&test); | 2493 RunBaseTest(&test); |
2382 } | 2494 } |
2383 #endif // !defined(RTC_DISABLE_VP9) | 2495 #endif // !defined(RTC_DISABLE_VP9) |
2384 | 2496 |
2385 } // namespace webrtc | 2497 } // namespace webrtc |
OLD | NEW |