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 RTCError SetBitrateConfigMask( | |
184 const webrtc::Call::Config::BitrateConfigMask& bitrate_config) override; | |
185 | |
183 void SignalChannelNetworkState(MediaType media, NetworkState state) override; | 186 void SignalChannelNetworkState(MediaType media, NetworkState state) override; |
184 | 187 |
185 void OnTransportOverheadChanged(MediaType media, | 188 void OnTransportOverheadChanged(MediaType media, |
186 int transport_overhead_per_packet) override; | 189 int transport_overhead_per_packet) override; |
187 | 190 |
188 void OnNetworkRouteChanged(const std::string& transport_name, | 191 void OnNetworkRouteChanged(const std::string& transport_name, |
189 const rtc::NetworkRoute& network_route) override; | 192 const rtc::NetworkRoute& network_route) override; |
190 | 193 |
191 void OnSentPacket(const rtc::SentPacket& sent_packet) override; | 194 void OnSentPacket(const rtc::SentPacket& sent_packet) override; |
192 | 195 |
(...skipping 25 matching lines...) Expand all Loading... | |
218 rtc::Optional<RtpPacketReceived> ParseRtpPacket(const uint8_t* packet, | 221 rtc::Optional<RtpPacketReceived> ParseRtpPacket(const uint8_t* packet, |
219 size_t length, | 222 size_t length, |
220 const PacketTime& packet_time) | 223 const PacketTime& packet_time) |
221 SHARED_LOCKS_REQUIRED(receive_crit_); | 224 SHARED_LOCKS_REQUIRED(receive_crit_); |
222 | 225 |
223 void UpdateSendHistograms() EXCLUSIVE_LOCKS_REQUIRED(&bitrate_crit_); | 226 void UpdateSendHistograms() EXCLUSIVE_LOCKS_REQUIRED(&bitrate_crit_); |
224 void UpdateReceiveHistograms(); | 227 void UpdateReceiveHistograms(); |
225 void UpdateHistograms(); | 228 void UpdateHistograms(); |
226 void UpdateAggregateNetworkState(); | 229 void UpdateAggregateNetworkState(); |
227 | 230 |
231 // Updates the BitrateConfig cached in |config_| by combining | |
232 // |base_bitrate_config_| and |bitrate_config_mask_| and updates the | |
233 // congestion controller if the combined config changed or if | |
234 // |force_update| is true. | |
235 RTCError UpdateCurrentBitrateConfig(bool force_update); | |
236 | |
237 // UpdateCurrentBitrateConfig, but doesn't verify BitrateConfig invariants. | |
238 void UpdateCurrentBitrateConfigUnchecked(); | |
239 | |
228 Clock* const clock_; | 240 Clock* const clock_; |
229 | 241 |
230 const int num_cpu_cores_; | 242 const int num_cpu_cores_; |
231 const std::unique_ptr<ProcessThread> module_process_thread_; | 243 const std::unique_ptr<ProcessThread> module_process_thread_; |
232 const std::unique_ptr<ProcessThread> pacer_thread_; | 244 const std::unique_ptr<ProcessThread> pacer_thread_; |
233 const std::unique_ptr<CallStats> call_stats_; | 245 const std::unique_ptr<CallStats> call_stats_; |
234 const std::unique_ptr<BitrateAllocator> bitrate_allocator_; | 246 const std::unique_ptr<BitrateAllocator> bitrate_allocator_; |
235 Call::Config config_; | 247 Call::Config config_; |
236 rtc::ThreadChecker configuration_thread_checker_; | 248 rtc::ThreadChecker configuration_thread_checker_; |
237 | 249 |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
314 VieRemb remb_; | 326 VieRemb remb_; |
315 ReceiveSideCongestionController receive_side_cc_; | 327 ReceiveSideCongestionController receive_side_cc_; |
316 const std::unique_ptr<SendDelayStats> video_send_delay_stats_; | 328 const std::unique_ptr<SendDelayStats> video_send_delay_stats_; |
317 const int64_t start_ms_; | 329 const int64_t start_ms_; |
318 // TODO(perkj): |worker_queue_| is supposed to replace | 330 // TODO(perkj): |worker_queue_| is supposed to replace |
319 // |module_process_thread_|. | 331 // |module_process_thread_|. |
320 // |worker_queue| is defined last to ensure all pending tasks are cancelled | 332 // |worker_queue| is defined last to ensure all pending tasks are cancelled |
321 // and deleted before any other members. | 333 // and deleted before any other members. |
322 rtc::TaskQueue worker_queue_; | 334 rtc::TaskQueue worker_queue_; |
323 | 335 |
336 // The config mask set by SetBitrateConfigMask. | |
337 // 0 <= min <= start <= max | |
338 Config::BitrateConfigMask bitrate_config_mask_; | |
339 | |
340 // The config set by SetBitrateConfig. | |
341 // min >= 0, start != 0, max == -1 || max > 0 | |
342 Config::BitrateConfig base_bitrate_config_; | |
343 | |
324 RTC_DISALLOW_COPY_AND_ASSIGN(Call); | 344 RTC_DISALLOW_COPY_AND_ASSIGN(Call); |
325 }; | 345 }; |
326 } // namespace internal | 346 } // namespace internal |
327 | 347 |
328 std::string Call::Stats::ToString(int64_t time_ms) const { | 348 std::string Call::Stats::ToString(int64_t time_ms) const { |
329 std::stringstream ss; | 349 std::stringstream ss; |
330 ss << "Call stats: " << time_ms << ", {"; | 350 ss << "Call stats: " << time_ms << ", {"; |
331 ss << "send_bw_bps: " << send_bandwidth_bps << ", "; | 351 ss << "send_bw_bps: " << send_bandwidth_bps << ", "; |
332 ss << "recv_bw_bps: " << recv_bandwidth_bps << ", "; | 352 ss << "recv_bw_bps: " << recv_bandwidth_bps << ", "; |
333 ss << "max_pad_bps: " << max_padding_bitrate_bps << ", "; | 353 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), | 387 received_rtcp_bytes_per_second_counter_(clock_, nullptr, true), |
368 min_allocated_send_bitrate_bps_(0), | 388 min_allocated_send_bitrate_bps_(0), |
369 configured_max_padding_bitrate_bps_(0), | 389 configured_max_padding_bitrate_bps_(0), |
370 estimated_send_bitrate_kbps_counter_(clock_, nullptr, true), | 390 estimated_send_bitrate_kbps_counter_(clock_, nullptr, true), |
371 pacer_bitrate_kbps_counter_(clock_, nullptr, true), | 391 pacer_bitrate_kbps_counter_(clock_, nullptr, true), |
372 transport_send_(std::move(transport_send)), | 392 transport_send_(std::move(transport_send)), |
373 remb_(clock_), | 393 remb_(clock_), |
374 receive_side_cc_(clock_, &remb_, transport_send_->packet_router()), | 394 receive_side_cc_(clock_, &remb_, transport_send_->packet_router()), |
375 video_send_delay_stats_(new SendDelayStats(clock_)), | 395 video_send_delay_stats_(new SendDelayStats(clock_)), |
376 start_ms_(clock_->TimeInMilliseconds()), | 396 start_ms_(clock_->TimeInMilliseconds()), |
377 worker_queue_("call_worker_queue") { | 397 worker_queue_("call_worker_queue"), |
398 base_bitrate_config_(config.bitrate_config) { | |
378 RTC_DCHECK(configuration_thread_checker_.CalledOnValidThread()); | 399 RTC_DCHECK(configuration_thread_checker_.CalledOnValidThread()); |
379 RTC_DCHECK(config.event_log != nullptr); | 400 RTC_DCHECK(config.event_log != nullptr); |
380 RTC_DCHECK_GE(config.bitrate_config.min_bitrate_bps, 0); | 401 RTC_DCHECK_GE(config.bitrate_config.min_bitrate_bps, 0); |
381 RTC_DCHECK_GT(config.bitrate_config.start_bitrate_bps, | 402 RTC_DCHECK_GT(config.bitrate_config.start_bitrate_bps, |
382 config.bitrate_config.min_bitrate_bps); | 403 config.bitrate_config.min_bitrate_bps); |
383 if (config.bitrate_config.max_bitrate_bps != -1) { | 404 if (config.bitrate_config.max_bitrate_bps != -1) { |
384 RTC_DCHECK_GE(config.bitrate_config.max_bitrate_bps, | 405 RTC_DCHECK_GE(config.bitrate_config.max_bitrate_bps, |
385 config.bitrate_config.start_bitrate_bps); | 406 config.bitrate_config.start_bitrate_bps); |
386 } | 407 } |
387 Trace::CreateTrace(); | 408 Trace::CreateTrace(); |
(...skipping 502 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
890 rtc::CritScope cs(&bitrate_crit_); | 911 rtc::CritScope cs(&bitrate_crit_); |
891 stats.max_padding_bitrate_bps = configured_max_padding_bitrate_bps_; | 912 stats.max_padding_bitrate_bps = configured_max_padding_bitrate_bps_; |
892 } | 913 } |
893 return stats; | 914 return stats; |
894 } | 915 } |
895 | 916 |
896 void Call::SetBitrateConfig( | 917 void Call::SetBitrateConfig( |
897 const webrtc::Call::Config::BitrateConfig& bitrate_config) { | 918 const webrtc::Call::Config::BitrateConfig& bitrate_config) { |
898 TRACE_EVENT0("webrtc", "Call::SetBitrateConfig"); | 919 TRACE_EVENT0("webrtc", "Call::SetBitrateConfig"); |
899 RTC_DCHECK(configuration_thread_checker_.CalledOnValidThread()); | 920 RTC_DCHECK(configuration_thread_checker_.CalledOnValidThread()); |
921 | |
900 RTC_DCHECK_GE(bitrate_config.min_bitrate_bps, 0); | 922 RTC_DCHECK_GE(bitrate_config.min_bitrate_bps, 0); |
901 if (bitrate_config.max_bitrate_bps != -1) | 923 RTC_DCHECK_NE(bitrate_config.start_bitrate_bps, 0); |
924 if (bitrate_config.max_bitrate_bps != -1) { | |
902 RTC_DCHECK_GT(bitrate_config.max_bitrate_bps, 0); | 925 RTC_DCHECK_GT(bitrate_config.max_bitrate_bps, 0); |
903 if (config_.bitrate_config.min_bitrate_bps == | 926 } |
904 bitrate_config.min_bitrate_bps && | 927 |
905 (bitrate_config.start_bitrate_bps <= 0 || | 928 const bool same_min = |
906 config_.bitrate_config.start_bitrate_bps == | 929 base_bitrate_config_.min_bitrate_bps == bitrate_config.min_bitrate_bps; |
907 bitrate_config.start_bitrate_bps) && | 930 const bool same_start = base_bitrate_config_.start_bitrate_bps == |
908 config_.bitrate_config.max_bitrate_bps == | 931 bitrate_config.start_bitrate_bps; |
909 bitrate_config.max_bitrate_bps) { | 932 const bool same_max = |
933 base_bitrate_config_.max_bitrate_bps == bitrate_config.max_bitrate_bps; | |
934 if (same_min && (bitrate_config.start_bitrate_bps <= 0 || same_start) && | |
935 same_max) { | |
Zach Stein
2017/04/20 20:48:01
(bitrate_config.max_bitrate_bps == -1 || same_max)
| |
910 // Nothing new to set, early abort to avoid encoder reconfigurations. | 936 // Nothing new to set, early abort to avoid encoder reconfigurations. |
911 return; | 937 return; |
912 } | 938 } |
913 config_.bitrate_config.min_bitrate_bps = bitrate_config.min_bitrate_bps; | 939 |
940 base_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 | 941 // Start bitrate of -1 means we should keep the old bitrate, which there is |
915 // no point in remembering for the future. | 942 // no point in remembering for the future. |
916 if (bitrate_config.start_bitrate_bps > 0) | 943 if (bitrate_config.start_bitrate_bps > 0) { |
917 config_.bitrate_config.start_bitrate_bps = bitrate_config.start_bitrate_bps; | 944 base_bitrate_config_.start_bitrate_bps = bitrate_config.start_bitrate_bps; |
918 config_.bitrate_config.max_bitrate_bps = bitrate_config.max_bitrate_bps; | 945 } |
919 RTC_DCHECK_NE(bitrate_config.start_bitrate_bps, 0); | 946 base_bitrate_config_.max_bitrate_bps = bitrate_config.max_bitrate_bps; |
947 | |
948 UpdateCurrentBitrateConfigUnchecked(); | |
949 } | |
950 | |
951 RTCError Call::SetBitrateConfigMask( | |
952 const webrtc::Call::Config::BitrateConfigMask& mask) { | |
953 TRACE_EVENT0("webrtc", "Call::SetBitrateConfigMask"); | |
954 RTC_DCHECK(configuration_thread_checker_.CalledOnValidThread()); | |
955 | |
956 bitrate_config_mask_ = mask; | |
957 | |
958 const bool force_update = static_cast<bool>(mask.start_bitrate_bps); | |
959 | |
960 return UpdateCurrentBitrateConfig(force_update); | |
961 } | |
962 | |
963 Call::Config::BitrateConfig ComputeMasked( | |
964 const Call::Config::BitrateConfig& base, | |
965 const Call::Config::BitrateConfigMask& mask) { | |
966 Call::Config::BitrateConfig masked; | |
967 masked.min_bitrate_bps = mask.min_bitrate_bps.value_or(base.min_bitrate_bps); | |
968 masked.start_bitrate_bps = | |
969 mask.start_bitrate_bps.value_or(base.start_bitrate_bps); | |
970 | |
971 const rtc::Optional<int>& mask_max = mask.max_bitrate_bps; | |
972 const int base_max = base.max_bitrate_bps; | |
973 const bool mask_has_max = static_cast<bool>(mask_max); | |
974 const bool base_has_max = base_max != -1; | |
975 if (mask_has_max && base_has_max) { | |
976 masked.max_bitrate_bps = std::min(*mask_max, base_max); | |
977 } else if (mask_has_max) { | |
978 masked.max_bitrate_bps = *mask_max; | |
979 } else if (base_has_max) { | |
980 masked.max_bitrate_bps = base_max; | |
981 } else { | |
982 masked.max_bitrate_bps = -1; | |
983 } | |
984 | |
985 return masked; | |
986 } | |
987 | |
988 void Call::UpdateCurrentBitrateConfigUnchecked() { | |
989 Config::BitrateConfig masked = | |
990 ComputeMasked(base_bitrate_config_, bitrate_config_mask_); | |
991 | |
992 // We only get here if SetBitrateConfig changed something. | |
993 | |
994 config_.bitrate_config = masked; | |
920 transport_send_->send_side_cc()->SetBweBitrates( | 995 transport_send_->send_side_cc()->SetBweBitrates( |
921 bitrate_config.min_bitrate_bps, bitrate_config.start_bitrate_bps, | 996 masked.min_bitrate_bps, masked.start_bitrate_bps, masked.max_bitrate_bps); |
922 bitrate_config.max_bitrate_bps); | 997 } |
998 | |
999 RTCError Call::UpdateCurrentBitrateConfig(bool force_update) { | |
Zach Stein
2017/04/20 20:48:00
Looking in to adding Call tests next.
| |
1000 Config::BitrateConfig masked = | |
1001 ComputeMasked(base_bitrate_config_, bitrate_config_mask_); | |
1002 | |
1003 Config::BitrateConfig& current = config_.bitrate_config; | |
1004 if (!force_update && masked.min_bitrate_bps == current.min_bitrate_bps && | |
1005 masked.start_bitrate_bps == current.start_bitrate_bps && | |
1006 masked.max_bitrate_bps == current.max_bitrate_bps) { | |
1007 return RTCError::OK(); | |
1008 } | |
1009 | |
1010 RTC_DCHECK_GE(masked.min_bitrate_bps, 0); | |
1011 if (masked.start_bitrate_bps > 0 && | |
1012 masked.start_bitrate_bps < masked.min_bitrate_bps) { | |
1013 LOG_AND_RETURN_ERROR( | |
1014 RTCErrorType::INVALID_STATE, | |
1015 "effective start_bitrate_bps < effective min_bitrate_bps"); | |
1016 } | |
1017 if (masked.max_bitrate_bps != -1 && masked.start_bitrate_bps > 0 && | |
1018 masked.max_bitrate_bps < masked.start_bitrate_bps) { | |
1019 LOG_AND_RETURN_ERROR( | |
1020 RTCErrorType::INVALID_STATE, | |
1021 "effective max_bitrate_bps < effective start_bitrate_bps"); | |
1022 } | |
1023 if (masked.max_bitrate_bps != -1 && | |
1024 masked.max_bitrate_bps < masked.min_bitrate_bps) { | |
1025 LOG_AND_RETURN_ERROR( | |
1026 RTCErrorType::INVALID_STATE, | |
1027 "effective max_bitrate_bps < effective min_bitrate_bps"); | |
1028 } | |
1029 | |
1030 current = masked; | |
1031 transport_send_->send_side_cc()->SetBweBitrates(current.min_bitrate_bps, | |
1032 current.start_bitrate_bps, | |
1033 current.max_bitrate_bps); | |
1034 return RTCError::OK(); | |
923 } | 1035 } |
924 | 1036 |
925 void Call::SignalChannelNetworkState(MediaType media, NetworkState state) { | 1037 void Call::SignalChannelNetworkState(MediaType media, NetworkState state) { |
926 RTC_DCHECK(configuration_thread_checker_.CalledOnValidThread()); | 1038 RTC_DCHECK(configuration_thread_checker_.CalledOnValidThread()); |
927 switch (media) { | 1039 switch (media) { |
928 case MediaType::AUDIO: | 1040 case MediaType::AUDIO: |
929 audio_network_state_ = state; | 1041 audio_network_state_ = state; |
930 break; | 1042 break; |
931 case MediaType::VIDEO: | 1043 case MediaType::VIDEO: |
932 video_network_state_ = state; | 1044 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)) { | 1437 (use_send_side_bwe && header.extension.hasTransportSequenceNumber)) { |
1326 receive_side_cc_.OnReceivedPacket( | 1438 receive_side_cc_.OnReceivedPacket( |
1327 packet.arrival_time_ms(), packet.payload_size() + packet.padding_size(), | 1439 packet.arrival_time_ms(), packet.payload_size() + packet.padding_size(), |
1328 header); | 1440 header); |
1329 } | 1441 } |
1330 } | 1442 } |
1331 | 1443 |
1332 } // namespace internal | 1444 } // namespace internal |
1333 | 1445 |
1334 } // namespace webrtc | 1446 } // namespace webrtc |
OLD | NEW |