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 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
173 const uint8_t* packet, | 173 const uint8_t* packet, |
174 size_t length, | 174 size_t length, |
175 const PacketTime& packet_time) override; | 175 const PacketTime& packet_time) override; |
176 | 176 |
177 // Implements RecoveredPacketReceiver. | 177 // Implements RecoveredPacketReceiver. |
178 bool OnRecoveredPacket(const uint8_t* packet, size_t length) override; | 178 bool OnRecoveredPacket(const uint8_t* packet, size_t length) override; |
179 | 179 |
180 void SetBitrateConfig( | 180 void SetBitrateConfig( |
181 const webrtc::Call::Config::BitrateConfig& bitrate_config) override; | 181 const webrtc::Call::Config::BitrateConfig& bitrate_config) override; |
182 | 182 |
| 183 void SetBitrateConfigMask( |
| 184 const webrtc::Call::Config::BitrateConfigMask& bitrate_config) override; |
| 185 |
| 186 // Updates the cached |masked_bitrate_config_| struct and updates the |
| 187 // congestion controller if the masked config changed. |
| 188 void UpdateMaskedBitrateConfig(); |
| 189 |
183 void SignalChannelNetworkState(MediaType media, NetworkState state) override; | 190 void SignalChannelNetworkState(MediaType media, NetworkState state) override; |
184 | 191 |
185 void OnTransportOverheadChanged(MediaType media, | 192 void OnTransportOverheadChanged(MediaType media, |
186 int transport_overhead_per_packet) override; | 193 int transport_overhead_per_packet) override; |
187 | 194 |
188 void OnNetworkRouteChanged(const std::string& transport_name, | 195 void OnNetworkRouteChanged(const std::string& transport_name, |
189 const rtc::NetworkRoute& network_route) override; | 196 const rtc::NetworkRoute& network_route) override; |
190 | 197 |
191 void OnSentPacket(const rtc::SentPacket& sent_packet) override; | 198 void OnSentPacket(const rtc::SentPacket& sent_packet) override; |
192 | 199 |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
314 VieRemb remb_; | 321 VieRemb remb_; |
315 ReceiveSideCongestionController receive_side_cc_; | 322 ReceiveSideCongestionController receive_side_cc_; |
316 const std::unique_ptr<SendDelayStats> video_send_delay_stats_; | 323 const std::unique_ptr<SendDelayStats> video_send_delay_stats_; |
317 const int64_t start_ms_; | 324 const int64_t start_ms_; |
318 // TODO(perkj): |worker_queue_| is supposed to replace | 325 // TODO(perkj): |worker_queue_| is supposed to replace |
319 // |module_process_thread_|. | 326 // |module_process_thread_|. |
320 // |worker_queue| is defined last to ensure all pending tasks are cancelled | 327 // |worker_queue| is defined last to ensure all pending tasks are cancelled |
321 // and deleted before any other members. | 328 // and deleted before any other members. |
322 rtc::TaskQueue worker_queue_; | 329 rtc::TaskQueue worker_queue_; |
323 | 330 |
| 331 // The mask is kept so it can be re-applied if SetBitrateConfig is called. |
| 332 Config::BitrateConfigMask bitrate_config_mask_; |
| 333 |
| 334 // This is the BitrateConfig given to the congestion controller. We cache it |
| 335 // here to avoid resets in the congestion controller when nothing has actually |
| 336 // changed. |
| 337 Config::BitrateConfig masked_bitrate_config_; |
| 338 |
324 RTC_DISALLOW_COPY_AND_ASSIGN(Call); | 339 RTC_DISALLOW_COPY_AND_ASSIGN(Call); |
325 }; | 340 }; |
326 } // namespace internal | 341 } // namespace internal |
327 | 342 |
328 std::string Call::Stats::ToString(int64_t time_ms) const { | 343 std::string Call::Stats::ToString(int64_t time_ms) const { |
329 std::stringstream ss; | 344 std::stringstream ss; |
330 ss << "Call stats: " << time_ms << ", {"; | 345 ss << "Call stats: " << time_ms << ", {"; |
331 ss << "send_bw_bps: " << send_bandwidth_bps << ", "; | 346 ss << "send_bw_bps: " << send_bandwidth_bps << ", "; |
332 ss << "recv_bw_bps: " << recv_bandwidth_bps << ", "; | 347 ss << "recv_bw_bps: " << recv_bandwidth_bps << ", "; |
333 ss << "max_pad_bps: " << max_padding_bitrate_bps << ", "; | 348 ss << "max_pad_bps: " << max_padding_bitrate_bps << ", "; |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
367 received_rtcp_bytes_per_second_counter_(clock_, nullptr, true), | 382 received_rtcp_bytes_per_second_counter_(clock_, nullptr, true), |
368 min_allocated_send_bitrate_bps_(0), | 383 min_allocated_send_bitrate_bps_(0), |
369 configured_max_padding_bitrate_bps_(0), | 384 configured_max_padding_bitrate_bps_(0), |
370 estimated_send_bitrate_kbps_counter_(clock_, nullptr, true), | 385 estimated_send_bitrate_kbps_counter_(clock_, nullptr, true), |
371 pacer_bitrate_kbps_counter_(clock_, nullptr, true), | 386 pacer_bitrate_kbps_counter_(clock_, nullptr, true), |
372 transport_send_(std::move(transport_send)), | 387 transport_send_(std::move(transport_send)), |
373 remb_(clock_), | 388 remb_(clock_), |
374 receive_side_cc_(clock_, &remb_, transport_send_->packet_router()), | 389 receive_side_cc_(clock_, &remb_, transport_send_->packet_router()), |
375 video_send_delay_stats_(new SendDelayStats(clock_)), | 390 video_send_delay_stats_(new SendDelayStats(clock_)), |
376 start_ms_(clock_->TimeInMilliseconds()), | 391 start_ms_(clock_->TimeInMilliseconds()), |
377 worker_queue_("call_worker_queue") { | 392 worker_queue_("call_worker_queue"), |
| 393 masked_bitrate_config_(config.bitrate_config) { |
378 RTC_DCHECK(configuration_thread_checker_.CalledOnValidThread()); | 394 RTC_DCHECK(configuration_thread_checker_.CalledOnValidThread()); |
379 RTC_DCHECK(config.event_log != nullptr); | 395 RTC_DCHECK(config.event_log != nullptr); |
380 RTC_DCHECK_GE(config.bitrate_config.min_bitrate_bps, 0); | 396 RTC_DCHECK_GE(config.bitrate_config.min_bitrate_bps, 0); |
381 RTC_DCHECK_GT(config.bitrate_config.start_bitrate_bps, | 397 RTC_DCHECK_GT(config.bitrate_config.start_bitrate_bps, |
382 config.bitrate_config.min_bitrate_bps); | 398 config.bitrate_config.min_bitrate_bps); |
383 if (config.bitrate_config.max_bitrate_bps != -1) { | 399 if (config.bitrate_config.max_bitrate_bps != -1) { |
384 RTC_DCHECK_GE(config.bitrate_config.max_bitrate_bps, | 400 RTC_DCHECK_GE(config.bitrate_config.max_bitrate_bps, |
385 config.bitrate_config.start_bitrate_bps); | 401 config.bitrate_config.start_bitrate_bps); |
386 } | 402 } |
387 Trace::CreateTrace(); | 403 Trace::CreateTrace(); |
(...skipping 502 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
890 rtc::CritScope cs(&bitrate_crit_); | 906 rtc::CritScope cs(&bitrate_crit_); |
891 stats.max_padding_bitrate_bps = configured_max_padding_bitrate_bps_; | 907 stats.max_padding_bitrate_bps = configured_max_padding_bitrate_bps_; |
892 } | 908 } |
893 return stats; | 909 return stats; |
894 } | 910 } |
895 | 911 |
896 void Call::SetBitrateConfig( | 912 void Call::SetBitrateConfig( |
897 const webrtc::Call::Config::BitrateConfig& bitrate_config) { | 913 const webrtc::Call::Config::BitrateConfig& bitrate_config) { |
898 TRACE_EVENT0("webrtc", "Call::SetBitrateConfig"); | 914 TRACE_EVENT0("webrtc", "Call::SetBitrateConfig"); |
899 RTC_DCHECK(configuration_thread_checker_.CalledOnValidThread()); | 915 RTC_DCHECK(configuration_thread_checker_.CalledOnValidThread()); |
| 916 |
900 RTC_DCHECK_GE(bitrate_config.min_bitrate_bps, 0); | 917 RTC_DCHECK_GE(bitrate_config.min_bitrate_bps, 0); |
901 if (bitrate_config.max_bitrate_bps != -1) | 918 if (bitrate_config.max_bitrate_bps != -1) |
902 RTC_DCHECK_GT(bitrate_config.max_bitrate_bps, 0); | 919 RTC_DCHECK_GT(bitrate_config.max_bitrate_bps, 0); |
| 920 |
903 if (config_.bitrate_config.min_bitrate_bps == | 921 if (config_.bitrate_config.min_bitrate_bps == |
904 bitrate_config.min_bitrate_bps && | 922 bitrate_config.min_bitrate_bps && |
905 (bitrate_config.start_bitrate_bps <= 0 || | 923 (bitrate_config.start_bitrate_bps <= 0 || |
906 config_.bitrate_config.start_bitrate_bps == | 924 config_.bitrate_config.start_bitrate_bps == |
907 bitrate_config.start_bitrate_bps) && | 925 bitrate_config.start_bitrate_bps) && |
908 config_.bitrate_config.max_bitrate_bps == | 926 config_.bitrate_config.max_bitrate_bps == |
909 bitrate_config.max_bitrate_bps) { | 927 bitrate_config.max_bitrate_bps) { |
910 // Nothing new to set, early abort to avoid encoder reconfigurations. | 928 // Nothing new to set, early abort to avoid encoder reconfigurations. |
911 return; | 929 return; |
912 } | 930 } |
| 931 |
913 config_.bitrate_config.min_bitrate_bps = bitrate_config.min_bitrate_bps; | 932 config_.bitrate_config.min_bitrate_bps = bitrate_config.min_bitrate_bps; |
914 // Start bitrate of -1 means we should keep the old bitrate, which there is | 933 // Start bitrate of -1 means we should keep the old bitrate, which there is |
915 // no point in remembering for the future. | 934 // no point in remembering for the future. |
916 if (bitrate_config.start_bitrate_bps > 0) | 935 if (bitrate_config.start_bitrate_bps > 0) |
917 config_.bitrate_config.start_bitrate_bps = bitrate_config.start_bitrate_bps; | 936 config_.bitrate_config.start_bitrate_bps = bitrate_config.start_bitrate_bps; |
918 config_.bitrate_config.max_bitrate_bps = bitrate_config.max_bitrate_bps; | 937 config_.bitrate_config.max_bitrate_bps = bitrate_config.max_bitrate_bps; |
| 938 |
919 RTC_DCHECK_NE(bitrate_config.start_bitrate_bps, 0); | 939 RTC_DCHECK_NE(bitrate_config.start_bitrate_bps, 0); |
920 transport_send_->send_side_cc()->SetBweBitrates( | 940 |
921 bitrate_config.min_bitrate_bps, bitrate_config.start_bitrate_bps, | 941 UpdateMaskedBitrateConfig(); |
| 942 } |
| 943 |
| 944 void Call::SetBitrateConfigMask( |
| 945 const webrtc::Call::Config::BitrateConfigMask& mask) { |
| 946 TRACE_EVENT0("webrtc", "Call::UpdateBitrateConfig"); |
| 947 RTC_DCHECK(configuration_thread_checker_.CalledOnValidThread()); |
| 948 |
| 949 // TODO(zstein): this validation belongs in PeerConnection::SetBitrate, which |
| 950 // should return an RTCError instead of using DCHECK |
| 951 const bool has_min = static_cast<bool>(mask.min_bitrate_bps); |
| 952 const bool has_start = static_cast<bool>(mask.start_bitrate_bps); |
| 953 const bool has_max = static_cast<bool>(mask.max_bitrate_bps); |
| 954 if (has_min) { |
| 955 RTC_DCHECK_GE(*mask.min_bitrate_bps, 0); |
| 956 } |
| 957 if (has_start) { |
| 958 RTC_DCHECK_GE(*mask.start_bitrate_bps, has_min ? *mask.min_bitrate_bps : 0); |
| 959 } |
| 960 if (has_max) { |
| 961 RTC_DCHECK_GE(*mask.max_bitrate_bps, |
| 962 has_start ? *mask.start_bitrate_bps |
| 963 : (has_min ? *mask.min_bitrate_bps : 0)); |
| 964 } |
| 965 |
| 966 bitrate_config_mask_ = mask; |
| 967 |
| 968 UpdateMaskedBitrateConfig(); |
| 969 } |
| 970 |
| 971 void Call::UpdateMaskedBitrateConfig() { |
| 972 Config::BitrateConfig new_masked; |
| 973 const Config::BitrateConfig& bitrate_config = config_.bitrate_config; |
| 974 |
| 975 new_masked.min_bitrate_bps = bitrate_config_mask_.min_bitrate_bps.value_or( |
| 976 bitrate_config.min_bitrate_bps); |
| 977 new_masked.start_bitrate_bps = |
| 978 bitrate_config_mask_.start_bitrate_bps.value_or( |
| 979 bitrate_config.start_bitrate_bps); |
| 980 new_masked.max_bitrate_bps = bitrate_config_mask_.max_bitrate_bps.value_or( |
922 bitrate_config.max_bitrate_bps); | 981 bitrate_config.max_bitrate_bps); |
| 982 |
| 983 if (new_masked.min_bitrate_bps != masked_bitrate_config_.min_bitrate_bps || |
| 984 new_masked.start_bitrate_bps != |
| 985 masked_bitrate_config_.start_bitrate_bps || |
| 986 new_masked.max_bitrate_bps != masked_bitrate_config_.max_bitrate_bps) { |
| 987 RTC_DCHECK_GT(new_masked.min_bitrate_bps, 0); |
| 988 // TODO(zstein): start_bitrate might be <= 0 if it wasn't set in the mask |
| 989 RTC_DCHECK_GT(new_masked.start_bitrate_bps, new_masked.min_bitrate_bps); |
| 990 RTC_DCHECK(new_masked.max_bitrate_bps == -1 || |
| 991 new_masked.max_bitrate_bps > new_masked.start_bitrate_bps); |
| 992 |
| 993 masked_bitrate_config_ = new_masked; |
| 994 transport_send_->send_side_cc()->SetBweBitrates( |
| 995 masked_bitrate_config_.min_bitrate_bps, |
| 996 masked_bitrate_config_.start_bitrate_bps, |
| 997 masked_bitrate_config_.max_bitrate_bps); |
| 998 } |
923 } | 999 } |
924 | 1000 |
925 void Call::SignalChannelNetworkState(MediaType media, NetworkState state) { | 1001 void Call::SignalChannelNetworkState(MediaType media, NetworkState state) { |
926 RTC_DCHECK(configuration_thread_checker_.CalledOnValidThread()); | 1002 RTC_DCHECK(configuration_thread_checker_.CalledOnValidThread()); |
927 switch (media) { | 1003 switch (media) { |
928 case MediaType::AUDIO: | 1004 case MediaType::AUDIO: |
929 audio_network_state_ = state; | 1005 audio_network_state_ = state; |
930 break; | 1006 break; |
931 case MediaType::VIDEO: | 1007 case MediaType::VIDEO: |
932 video_network_state_ = state; | 1008 video_network_state_ = state; |
(...skipping 392 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1325 (use_send_side_bwe && header.extension.hasTransportSequenceNumber)) { | 1401 (use_send_side_bwe && header.extension.hasTransportSequenceNumber)) { |
1326 receive_side_cc_.OnReceivedPacket( | 1402 receive_side_cc_.OnReceivedPacket( |
1327 packet.arrival_time_ms(), packet.payload_size() + packet.padding_size(), | 1403 packet.arrival_time_ms(), packet.payload_size() + packet.padding_size(), |
1328 header); | 1404 header); |
1329 } | 1405 } |
1330 } | 1406 } |
1331 | 1407 |
1332 } // namespace internal | 1408 } // namespace internal |
1333 | 1409 |
1334 } // namespace webrtc | 1410 } // namespace webrtc |
OLD | NEW |