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 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
135 const uint8_t* packet, | 135 const uint8_t* packet, |
136 size_t length, | 136 size_t length, |
137 const PacketTime& packet_time) override; | 137 const PacketTime& packet_time) override; |
138 | 138 |
139 // Implements RecoveredPacketReceiver. | 139 // Implements RecoveredPacketReceiver. |
140 bool OnRecoveredPacket(const uint8_t* packet, size_t length) override; | 140 bool OnRecoveredPacket(const uint8_t* packet, size_t length) override; |
141 | 141 |
142 void SetBitrateConfig( | 142 void SetBitrateConfig( |
143 const webrtc::Call::Config::BitrateConfig& bitrate_config) override; | 143 const webrtc::Call::Config::BitrateConfig& bitrate_config) override; |
144 | 144 |
| 145 void SetBitrateConfigMask( |
| 146 const webrtc::Call::Config::BitrateConfigMask& bitrate_config) override; |
| 147 |
145 void SignalChannelNetworkState(MediaType media, NetworkState state) override; | 148 void SignalChannelNetworkState(MediaType media, NetworkState state) override; |
146 | 149 |
147 void OnTransportOverheadChanged(MediaType media, | 150 void OnTransportOverheadChanged(MediaType media, |
148 int transport_overhead_per_packet) override; | 151 int transport_overhead_per_packet) override; |
149 | 152 |
150 void OnNetworkRouteChanged(const std::string& transport_name, | 153 void OnNetworkRouteChanged(const std::string& transport_name, |
151 const rtc::NetworkRoute& network_route) override; | 154 const rtc::NetworkRoute& network_route) override; |
152 | 155 |
153 void OnSentPacket(const rtc::SentPacket& sent_packet) override; | 156 void OnSentPacket(const rtc::SentPacket& sent_packet) override; |
154 | 157 |
(...skipping 26 matching lines...) Expand all Loading... |
181 size_t length, | 184 size_t length, |
182 const PacketTime& packet_time) | 185 const PacketTime& packet_time) |
183 SHARED_LOCKS_REQUIRED(receive_crit_); | 186 SHARED_LOCKS_REQUIRED(receive_crit_); |
184 | 187 |
185 void UpdateSendHistograms(int64_t first_sent_packet_ms) | 188 void UpdateSendHistograms(int64_t first_sent_packet_ms) |
186 EXCLUSIVE_LOCKS_REQUIRED(&bitrate_crit_); | 189 EXCLUSIVE_LOCKS_REQUIRED(&bitrate_crit_); |
187 void UpdateReceiveHistograms(); | 190 void UpdateReceiveHistograms(); |
188 void UpdateHistograms(); | 191 void UpdateHistograms(); |
189 void UpdateAggregateNetworkState(); | 192 void UpdateAggregateNetworkState(); |
190 | 193 |
| 194 // Applies update to the BitrateConfig cached in |config_|, restarting |
| 195 // bandwidth estimation from |new_start| if set. |
| 196 void UpdateCurrentBitrateConfig(const rtc::Optional<int>& new_start); |
| 197 |
191 Clock* const clock_; | 198 Clock* const clock_; |
192 | 199 |
193 const int num_cpu_cores_; | 200 const int num_cpu_cores_; |
194 const std::unique_ptr<ProcessThread> module_process_thread_; | 201 const std::unique_ptr<ProcessThread> module_process_thread_; |
195 const std::unique_ptr<ProcessThread> pacer_thread_; | 202 const std::unique_ptr<ProcessThread> pacer_thread_; |
196 const std::unique_ptr<CallStats> call_stats_; | 203 const std::unique_ptr<CallStats> call_stats_; |
197 const std::unique_ptr<BitrateAllocator> bitrate_allocator_; | 204 const std::unique_ptr<BitrateAllocator> bitrate_allocator_; |
198 Call::Config config_; | 205 Call::Config config_; |
199 rtc::ThreadChecker configuration_thread_checker_; | 206 rtc::ThreadChecker configuration_thread_checker_; |
200 | 207 |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
275 std::unique_ptr<RtpTransportControllerSendInterface> transport_send_; | 282 std::unique_ptr<RtpTransportControllerSendInterface> transport_send_; |
276 ReceiveSideCongestionController receive_side_cc_; | 283 ReceiveSideCongestionController receive_side_cc_; |
277 const std::unique_ptr<SendDelayStats> video_send_delay_stats_; | 284 const std::unique_ptr<SendDelayStats> video_send_delay_stats_; |
278 const int64_t start_ms_; | 285 const int64_t start_ms_; |
279 // TODO(perkj): |worker_queue_| is supposed to replace | 286 // TODO(perkj): |worker_queue_| is supposed to replace |
280 // |module_process_thread_|. | 287 // |module_process_thread_|. |
281 // |worker_queue| is defined last to ensure all pending tasks are cancelled | 288 // |worker_queue| is defined last to ensure all pending tasks are cancelled |
282 // and deleted before any other members. | 289 // and deleted before any other members. |
283 rtc::TaskQueue worker_queue_; | 290 rtc::TaskQueue worker_queue_; |
284 | 291 |
| 292 // The config mask set by SetBitrateConfigMask. |
| 293 // 0 <= min <= start <= max |
| 294 Config::BitrateConfigMask bitrate_config_mask_; |
| 295 |
| 296 // The config set by SetBitrateConfig. |
| 297 // min >= 0, start != 0, max == -1 || max > 0 |
| 298 Config::BitrateConfig base_bitrate_config_; |
| 299 |
285 RTC_DISALLOW_COPY_AND_ASSIGN(Call); | 300 RTC_DISALLOW_COPY_AND_ASSIGN(Call); |
286 }; | 301 }; |
287 } // namespace internal | 302 } // namespace internal |
288 | 303 |
289 std::string Call::Stats::ToString(int64_t time_ms) const { | 304 std::string Call::Stats::ToString(int64_t time_ms) const { |
290 std::stringstream ss; | 305 std::stringstream ss; |
291 ss << "Call stats: " << time_ms << ", {"; | 306 ss << "Call stats: " << time_ms << ", {"; |
292 ss << "send_bw_bps: " << send_bandwidth_bps << ", "; | 307 ss << "send_bw_bps: " << send_bandwidth_bps << ", "; |
293 ss << "recv_bw_bps: " << recv_bandwidth_bps << ", "; | 308 ss << "recv_bw_bps: " << recv_bandwidth_bps << ", "; |
294 ss << "max_pad_bps: " << max_padding_bitrate_bps << ", "; | 309 ss << "max_pad_bps: " << max_padding_bitrate_bps << ", "; |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
330 received_audio_bytes_per_second_counter_(clock_, nullptr, true), | 345 received_audio_bytes_per_second_counter_(clock_, nullptr, true), |
331 received_video_bytes_per_second_counter_(clock_, nullptr, true), | 346 received_video_bytes_per_second_counter_(clock_, nullptr, true), |
332 received_rtcp_bytes_per_second_counter_(clock_, nullptr, true), | 347 received_rtcp_bytes_per_second_counter_(clock_, nullptr, true), |
333 min_allocated_send_bitrate_bps_(0), | 348 min_allocated_send_bitrate_bps_(0), |
334 configured_max_padding_bitrate_bps_(0), | 349 configured_max_padding_bitrate_bps_(0), |
335 estimated_send_bitrate_kbps_counter_(clock_, nullptr, true), | 350 estimated_send_bitrate_kbps_counter_(clock_, nullptr, true), |
336 pacer_bitrate_kbps_counter_(clock_, nullptr, true), | 351 pacer_bitrate_kbps_counter_(clock_, nullptr, true), |
337 receive_side_cc_(clock_, transport_send->packet_router()), | 352 receive_side_cc_(clock_, transport_send->packet_router()), |
338 video_send_delay_stats_(new SendDelayStats(clock_)), | 353 video_send_delay_stats_(new SendDelayStats(clock_)), |
339 start_ms_(clock_->TimeInMilliseconds()), | 354 start_ms_(clock_->TimeInMilliseconds()), |
340 worker_queue_("call_worker_queue") { | 355 worker_queue_("call_worker_queue"), |
| 356 base_bitrate_config_(config.bitrate_config) { |
341 RTC_DCHECK(configuration_thread_checker_.CalledOnValidThread()); | 357 RTC_DCHECK(configuration_thread_checker_.CalledOnValidThread()); |
342 RTC_DCHECK(config.event_log != nullptr); | 358 RTC_DCHECK(config.event_log != nullptr); |
343 RTC_DCHECK_GE(config.bitrate_config.min_bitrate_bps, 0); | 359 RTC_DCHECK_GE(config.bitrate_config.min_bitrate_bps, 0); |
344 RTC_DCHECK_GE(config.bitrate_config.start_bitrate_bps, | 360 RTC_DCHECK_GE(config.bitrate_config.start_bitrate_bps, |
345 config.bitrate_config.min_bitrate_bps); | 361 config.bitrate_config.min_bitrate_bps); |
346 if (config.bitrate_config.max_bitrate_bps != -1) { | 362 if (config.bitrate_config.max_bitrate_bps != -1) { |
347 RTC_DCHECK_GE(config.bitrate_config.max_bitrate_bps, | 363 RTC_DCHECK_GE(config.bitrate_config.max_bitrate_bps, |
348 config.bitrate_config.start_bitrate_bps); | 364 config.bitrate_config.start_bitrate_bps); |
349 } | 365 } |
350 Trace::CreateTrace(); | 366 Trace::CreateTrace(); |
(...skipping 504 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
855 rtc::CritScope cs(&bitrate_crit_); | 871 rtc::CritScope cs(&bitrate_crit_); |
856 stats.max_padding_bitrate_bps = configured_max_padding_bitrate_bps_; | 872 stats.max_padding_bitrate_bps = configured_max_padding_bitrate_bps_; |
857 } | 873 } |
858 return stats; | 874 return stats; |
859 } | 875 } |
860 | 876 |
861 void Call::SetBitrateConfig( | 877 void Call::SetBitrateConfig( |
862 const webrtc::Call::Config::BitrateConfig& bitrate_config) { | 878 const webrtc::Call::Config::BitrateConfig& bitrate_config) { |
863 TRACE_EVENT0("webrtc", "Call::SetBitrateConfig"); | 879 TRACE_EVENT0("webrtc", "Call::SetBitrateConfig"); |
864 RTC_DCHECK(configuration_thread_checker_.CalledOnValidThread()); | 880 RTC_DCHECK(configuration_thread_checker_.CalledOnValidThread()); |
| 881 |
865 RTC_DCHECK_GE(bitrate_config.min_bitrate_bps, 0); | 882 RTC_DCHECK_GE(bitrate_config.min_bitrate_bps, 0); |
866 if (bitrate_config.max_bitrate_bps != -1) | 883 RTC_DCHECK_NE(bitrate_config.start_bitrate_bps, 0); |
| 884 if (bitrate_config.max_bitrate_bps != -1) { |
867 RTC_DCHECK_GT(bitrate_config.max_bitrate_bps, 0); | 885 RTC_DCHECK_GT(bitrate_config.max_bitrate_bps, 0); |
868 if (config_.bitrate_config.min_bitrate_bps == | 886 } |
869 bitrate_config.min_bitrate_bps && | 887 |
870 (bitrate_config.start_bitrate_bps <= 0 || | 888 rtc::Optional<int> new_start; |
871 config_.bitrate_config.start_bitrate_bps == | 889 // Only update the "start" bitrate if it's set, and different from the old |
872 bitrate_config.start_bitrate_bps) && | 890 // value. In practice, this value comes from the x-google-start-bitrate codec |
873 config_.bitrate_config.max_bitrate_bps == | 891 // parameter in SDP, and setting the same remote description twice shouldn't |
874 bitrate_config.max_bitrate_bps) { | 892 // restart bandwidth estimation. |
875 // Nothing new to set, early abort to avoid encoder reconfigurations. | 893 if (bitrate_config.start_bitrate_bps != -1 && |
| 894 bitrate_config.start_bitrate_bps != |
| 895 base_bitrate_config_.start_bitrate_bps) { |
| 896 new_start.emplace(bitrate_config.start_bitrate_bps); |
| 897 } |
| 898 base_bitrate_config_ = bitrate_config; |
| 899 UpdateCurrentBitrateConfig(new_start); |
| 900 } |
| 901 |
| 902 void Call::SetBitrateConfigMask( |
| 903 const webrtc::Call::Config::BitrateConfigMask& mask) { |
| 904 TRACE_EVENT0("webrtc", "Call::SetBitrateConfigMask"); |
| 905 RTC_DCHECK(configuration_thread_checker_.CalledOnValidThread()); |
| 906 |
| 907 bitrate_config_mask_ = mask; |
| 908 UpdateCurrentBitrateConfig(mask.start_bitrate_bps); |
| 909 } |
| 910 |
| 911 void Call::UpdateCurrentBitrateConfig(const rtc::Optional<int>& new_start) { |
| 912 Config::BitrateConfig updated; |
| 913 updated.min_bitrate_bps = |
| 914 std::max(bitrate_config_mask_.min_bitrate_bps.value_or(0), |
| 915 base_bitrate_config_.min_bitrate_bps); |
| 916 updated.max_bitrate_bps = |
| 917 cricket::MinPositive(bitrate_config_mask_.max_bitrate_bps.value_or(-1), |
| 918 base_bitrate_config_.max_bitrate_bps); |
| 919 // If the combined min ends up greater than the combined max, the max takes |
| 920 // priority. |
| 921 // TODO(zstein): This clamp logic is different than send_side_cc's (moves min |
| 922 // instead of max, allows start to be greather than min) - check that it is a |
| 923 // sensible difference. |
| 924 if (updated.max_bitrate_bps != -1 && |
| 925 updated.min_bitrate_bps > updated.max_bitrate_bps) { |
| 926 updated.min_bitrate_bps = updated.max_bitrate_bps; |
| 927 } |
| 928 |
| 929 // If there's nothing to update (min/max unchanged, no new bandwidth |
| 930 // estimation start value), return early. |
| 931 if (updated.min_bitrate_bps == config_.bitrate_config.min_bitrate_bps && |
| 932 updated.max_bitrate_bps == config_.bitrate_config.max_bitrate_bps && |
| 933 !new_start) { |
876 return; | 934 return; |
877 } | 935 } |
878 config_.bitrate_config.min_bitrate_bps = bitrate_config.min_bitrate_bps; | 936 |
879 // Start bitrate of -1 means we should keep the old bitrate, which there is | 937 if (new_start) { |
880 // no point in remembering for the future. | 938 updated.start_bitrate_bps = cricket::MinPositive( |
881 if (bitrate_config.start_bitrate_bps > 0) | 939 std::max(*new_start, updated.min_bitrate_bps), updated.max_bitrate_bps); |
882 config_.bitrate_config.start_bitrate_bps = bitrate_config.start_bitrate_bps; | 940 } else { |
883 config_.bitrate_config.max_bitrate_bps = bitrate_config.max_bitrate_bps; | 941 updated.start_bitrate_bps = -1; |
884 RTC_DCHECK_NE(bitrate_config.start_bitrate_bps, 0); | 942 } |
885 transport_send_->send_side_cc()->SetBweBitrates( | 943 |
886 bitrate_config.min_bitrate_bps, bitrate_config.start_bitrate_bps, | 944 transport_send_->send_side_cc()->SetBweBitrates(updated.min_bitrate_bps, |
887 bitrate_config.max_bitrate_bps); | 945 updated.start_bitrate_bps, |
| 946 updated.max_bitrate_bps); |
| 947 config_.bitrate_config = updated; |
888 } | 948 } |
889 | 949 |
890 void Call::SignalChannelNetworkState(MediaType media, NetworkState state) { | 950 void Call::SignalChannelNetworkState(MediaType media, NetworkState state) { |
891 RTC_DCHECK(configuration_thread_checker_.CalledOnValidThread()); | 951 RTC_DCHECK(configuration_thread_checker_.CalledOnValidThread()); |
892 switch (media) { | 952 switch (media) { |
893 case MediaType::AUDIO: | 953 case MediaType::AUDIO: |
894 audio_network_state_ = state; | 954 audio_network_state_ = state; |
895 break; | 955 break; |
896 case MediaType::VIDEO: | 956 case MediaType::VIDEO: |
897 video_network_state_ = state; | 957 video_network_state_ = state; |
(...skipping 390 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1288 (use_send_side_bwe && header.extension.hasTransportSequenceNumber)) { | 1348 (use_send_side_bwe && header.extension.hasTransportSequenceNumber)) { |
1289 receive_side_cc_.OnReceivedPacket( | 1349 receive_side_cc_.OnReceivedPacket( |
1290 packet.arrival_time_ms(), packet.payload_size() + packet.padding_size(), | 1350 packet.arrival_time_ms(), packet.payload_size() + packet.padding_size(), |
1291 header); | 1351 header); |
1292 } | 1352 } |
1293 } | 1353 } |
1294 | 1354 |
1295 } // namespace internal | 1355 } // namespace internal |
1296 | 1356 |
1297 } // namespace webrtc | 1357 } // namespace webrtc |
OLD | NEW |