| 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 MaxPaddingSetTest : public test::SendTest { | 
|  | 1125  public: | 
|  | 1126   static const uint32_t kMinTransmitBitrateBps = 400000; | 
|  | 1127   static const uint32_t kActualEncodeBitrateBps = 40000; | 
|  | 1128   static const uint32_t kMinPacketsToSend = 50; | 
|  | 1129 | 
|  | 1130   explicit MaxPaddingSetTest(bool test_switch_content_type) | 
|  | 1131       : SendTest(test::CallTest::kDefaultTimeoutMs), | 
|  | 1132         call_(nullptr), | 
|  | 1133         send_stream_(nullptr), | 
|  | 1134         packets_sent_(0), | 
|  | 1135         running_without_padding_(test_switch_content_type) {} | 
|  | 1136 | 
|  | 1137   void OnVideoStreamsCreated( | 
|  | 1138       VideoSendStream* send_stream, | 
|  | 1139       const std::vector<VideoReceiveStream*>& receive_streams) override { | 
|  | 1140     send_stream_ = send_stream; | 
|  | 1141   } | 
|  | 1142 | 
|  | 1143   void ModifyVideoConfigs( | 
|  | 1144       VideoSendStream::Config* send_config, | 
|  | 1145       std::vector<VideoReceiveStream::Config>* receive_configs, | 
|  | 1146       VideoEncoderConfig* encoder_config) override { | 
|  | 1147     RTC_DCHECK_EQ(1u, encoder_config->streams.size()); | 
|  | 1148     if (running_without_padding_) { | 
|  | 1149       encoder_config->min_transmit_bitrate_bps = 0; | 
|  | 1150       encoder_config->content_type = | 
|  | 1151           VideoEncoderConfig::ContentType::kRealtimeVideo; | 
|  | 1152     } else { | 
|  | 1153       encoder_config->min_transmit_bitrate_bps = kMinTransmitBitrateBps; | 
|  | 1154       encoder_config->content_type = VideoEncoderConfig::ContentType::kScreen; | 
|  | 1155     } | 
|  | 1156     encoder_config_ = *encoder_config; | 
|  | 1157   } | 
|  | 1158 | 
|  | 1159   void OnCallsCreated(Call* sender_call, Call* receiver_call) override { | 
|  | 1160     call_ = sender_call; | 
|  | 1161   } | 
|  | 1162 | 
|  | 1163   Action OnSendRtp(const uint8_t* packet, size_t length) override { | 
|  | 1164     rtc::CritScope lock(&crit_); | 
|  | 1165 | 
|  | 1166     if (running_without_padding_) | 
|  | 1167       EXPECT_EQ(0, call_->GetStats().max_padding_bitrate_bps); | 
|  | 1168 | 
|  | 1169     // Wait until at least kMinPacketsToSend frames have been encoded, so that | 
|  | 1170     // we have reliable data. | 
|  | 1171     if (++packets_sent_ < kMinPacketsToSend) | 
|  | 1172       return SEND_PACKET; | 
|  | 1173 | 
|  | 1174     if (running_without_padding_) { | 
|  | 1175       // We've sent kMinPacketsToSend packets with default configuration, switch | 
|  | 1176       // to enabling screen content and setting min transmit bitrate. | 
|  | 1177       packets_sent_ = 0; | 
|  | 1178       encoder_config_.min_transmit_bitrate_bps = kMinTransmitBitrateBps; | 
|  | 1179       encoder_config_.content_type = VideoEncoderConfig::ContentType::kScreen; | 
|  | 1180       send_stream_->ReconfigureVideoEncoder(encoder_config_); | 
|  | 1181       running_without_padding_ = false; | 
|  | 1182       return SEND_PACKET; | 
|  | 1183     } | 
|  | 1184 | 
|  | 1185     // Make sure the pacer has been configured with a min transmit bitrate. | 
|  | 1186     if (call_->GetStats().max_padding_bitrate_bps > 0) | 
|  | 1187       observation_complete_.Set(); | 
|  | 1188 | 
|  | 1189     return SEND_PACKET; | 
|  | 1190   } | 
|  | 1191 | 
|  | 1192   void PerformTest() override { | 
|  | 1193     ASSERT_TRUE(Wait()) << "Timed out waiting for a valid padding bitrate."; | 
|  | 1194   } | 
|  | 1195 | 
|  | 1196  private: | 
|  | 1197   rtc::CriticalSection crit_; | 
|  | 1198   Call* call_; | 
|  | 1199   VideoSendStream* send_stream_; | 
|  | 1200   VideoEncoderConfig encoder_config_; | 
|  | 1201   uint32_t packets_sent_ GUARDED_BY(crit_); | 
|  | 1202   bool running_without_padding_; | 
|  | 1203 }; | 
|  | 1204 | 
|  | 1205 TEST_F(VideoSendStreamTest, RespectsMinTransmitBitrate) { | 
|  | 1206   MaxPaddingSetTest test(false); | 
|  | 1207   RunBaseTest(&test); | 
|  | 1208 } | 
|  | 1209 | 
|  | 1210 TEST_F(VideoSendStreamTest, RespectsMinTransmitBitrateAfterContentSwitch) { | 
|  | 1211   MaxPaddingSetTest test(true); | 
|  | 1212   RunBaseTest(&test); | 
|  | 1213 } | 
|  | 1214 | 
| 1124 TEST_F(VideoSendStreamTest, CanReconfigureToUseStartBitrateAbovePreviousMax) { | 1215 TEST_F(VideoSendStreamTest, CanReconfigureToUseStartBitrateAbovePreviousMax) { | 
| 1125   class StartBitrateObserver : public test::FakeEncoder { | 1216   class StartBitrateObserver : public test::FakeEncoder { | 
| 1126    public: | 1217    public: | 
| 1127     StartBitrateObserver() | 1218     StartBitrateObserver() | 
| 1128         : FakeEncoder(Clock::GetRealTimeClock()), | 1219         : FakeEncoder(Clock::GetRealTimeClock()), | 
| 1129           start_bitrate_changed_(false, false), | 1220           start_bitrate_changed_(false, false), | 
| 1130           start_bitrate_kbps_(0) {} | 1221           start_bitrate_kbps_(0) {} | 
| 1131     int32_t InitEncode(const VideoCodec* config, | 1222     int32_t InitEncode(const VideoCodec* config, | 
| 1132                        int32_t number_of_cores, | 1223                        int32_t number_of_cores, | 
| 1133                        size_t max_payload_size) override { | 1224                        size_t max_payload_size) override { | 
| (...skipping 1242 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 2376         observation_complete_.Set(); | 2467         observation_complete_.Set(); | 
| 2377       } | 2468       } | 
| 2378     } | 2469     } | 
| 2379   } test; | 2470   } test; | 
| 2380 | 2471 | 
| 2381   RunBaseTest(&test); | 2472   RunBaseTest(&test); | 
| 2382 } | 2473 } | 
| 2383 #endif  // !defined(RTC_DISABLE_VP9) | 2474 #endif  // !defined(RTC_DISABLE_VP9) | 
| 2384 | 2475 | 
| 2385 }  // namespace webrtc | 2476 }  // namespace webrtc | 
| OLD | NEW | 
|---|