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 // These values only get set if there is actually something to change. | |
195 struct BitrateUpdate { | |
196 rtc::Optional<int> min_bitrate_bps; | |
197 rtc::Optional<int> start_bitrate_bps; | |
198 rtc::Optional<int> max_bitrate_bps; | |
199 }; | |
200 | |
201 // Applies update to the BitrateConfig cached in |config_| and updates the | |
202 // congestion controller if update is not empty. | |
203 void UpdateCurrentBitrateConfig(const BitrateUpdate& update); | |
204 | |
191 Clock* const clock_; | 205 Clock* const clock_; |
192 | 206 |
193 const int num_cpu_cores_; | 207 const int num_cpu_cores_; |
194 const std::unique_ptr<ProcessThread> module_process_thread_; | 208 const std::unique_ptr<ProcessThread> module_process_thread_; |
195 const std::unique_ptr<ProcessThread> pacer_thread_; | 209 const std::unique_ptr<ProcessThread> pacer_thread_; |
196 const std::unique_ptr<CallStats> call_stats_; | 210 const std::unique_ptr<CallStats> call_stats_; |
197 const std::unique_ptr<BitrateAllocator> bitrate_allocator_; | 211 const std::unique_ptr<BitrateAllocator> bitrate_allocator_; |
198 Call::Config config_; | 212 Call::Config config_; |
199 rtc::ThreadChecker configuration_thread_checker_; | 213 rtc::ThreadChecker configuration_thread_checker_; |
200 | 214 |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
275 std::unique_ptr<RtpTransportControllerSendInterface> transport_send_; | 289 std::unique_ptr<RtpTransportControllerSendInterface> transport_send_; |
276 ReceiveSideCongestionController receive_side_cc_; | 290 ReceiveSideCongestionController receive_side_cc_; |
277 const std::unique_ptr<SendDelayStats> video_send_delay_stats_; | 291 const std::unique_ptr<SendDelayStats> video_send_delay_stats_; |
278 const int64_t start_ms_; | 292 const int64_t start_ms_; |
279 // TODO(perkj): |worker_queue_| is supposed to replace | 293 // TODO(perkj): |worker_queue_| is supposed to replace |
280 // |module_process_thread_|. | 294 // |module_process_thread_|. |
281 // |worker_queue| is defined last to ensure all pending tasks are cancelled | 295 // |worker_queue| is defined last to ensure all pending tasks are cancelled |
282 // and deleted before any other members. | 296 // and deleted before any other members. |
283 rtc::TaskQueue worker_queue_; | 297 rtc::TaskQueue worker_queue_; |
284 | 298 |
299 // The config mask set by SetBitrateConfigMask. | |
300 // 0 <= min <= start <= max | |
301 Config::BitrateConfigMask bitrate_config_mask_; | |
302 | |
303 // The config set by SetBitrateConfig. | |
304 // min >= 0, start != 0, max == -1 || max > 0 | |
305 Config::BitrateConfig base_bitrate_config_; | |
306 | |
285 RTC_DISALLOW_COPY_AND_ASSIGN(Call); | 307 RTC_DISALLOW_COPY_AND_ASSIGN(Call); |
286 }; | 308 }; |
287 } // namespace internal | 309 } // namespace internal |
288 | 310 |
289 std::string Call::Stats::ToString(int64_t time_ms) const { | 311 std::string Call::Stats::ToString(int64_t time_ms) const { |
290 std::stringstream ss; | 312 std::stringstream ss; |
291 ss << "Call stats: " << time_ms << ", {"; | 313 ss << "Call stats: " << time_ms << ", {"; |
292 ss << "send_bw_bps: " << send_bandwidth_bps << ", "; | 314 ss << "send_bw_bps: " << send_bandwidth_bps << ", "; |
293 ss << "recv_bw_bps: " << recv_bandwidth_bps << ", "; | 315 ss << "recv_bw_bps: " << recv_bandwidth_bps << ", "; |
294 ss << "max_pad_bps: " << max_padding_bitrate_bps << ", "; | 316 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), | 352 received_audio_bytes_per_second_counter_(clock_, nullptr, true), |
331 received_video_bytes_per_second_counter_(clock_, nullptr, true), | 353 received_video_bytes_per_second_counter_(clock_, nullptr, true), |
332 received_rtcp_bytes_per_second_counter_(clock_, nullptr, true), | 354 received_rtcp_bytes_per_second_counter_(clock_, nullptr, true), |
333 min_allocated_send_bitrate_bps_(0), | 355 min_allocated_send_bitrate_bps_(0), |
334 configured_max_padding_bitrate_bps_(0), | 356 configured_max_padding_bitrate_bps_(0), |
335 estimated_send_bitrate_kbps_counter_(clock_, nullptr, true), | 357 estimated_send_bitrate_kbps_counter_(clock_, nullptr, true), |
336 pacer_bitrate_kbps_counter_(clock_, nullptr, true), | 358 pacer_bitrate_kbps_counter_(clock_, nullptr, true), |
337 receive_side_cc_(clock_, transport_send->packet_router()), | 359 receive_side_cc_(clock_, transport_send->packet_router()), |
338 video_send_delay_stats_(new SendDelayStats(clock_)), | 360 video_send_delay_stats_(new SendDelayStats(clock_)), |
339 start_ms_(clock_->TimeInMilliseconds()), | 361 start_ms_(clock_->TimeInMilliseconds()), |
340 worker_queue_("call_worker_queue") { | 362 worker_queue_("call_worker_queue"), |
363 base_bitrate_config_(config.bitrate_config) { | |
341 RTC_DCHECK(configuration_thread_checker_.CalledOnValidThread()); | 364 RTC_DCHECK(configuration_thread_checker_.CalledOnValidThread()); |
342 RTC_DCHECK(config.event_log != nullptr); | 365 RTC_DCHECK(config.event_log != nullptr); |
343 RTC_DCHECK_GE(config.bitrate_config.min_bitrate_bps, 0); | 366 RTC_DCHECK_GE(config.bitrate_config.min_bitrate_bps, 0); |
344 RTC_DCHECK_GE(config.bitrate_config.start_bitrate_bps, | 367 RTC_DCHECK_GE(config.bitrate_config.start_bitrate_bps, |
345 config.bitrate_config.min_bitrate_bps); | 368 config.bitrate_config.min_bitrate_bps); |
346 if (config.bitrate_config.max_bitrate_bps != -1) { | 369 if (config.bitrate_config.max_bitrate_bps != -1) { |
347 RTC_DCHECK_GE(config.bitrate_config.max_bitrate_bps, | 370 RTC_DCHECK_GE(config.bitrate_config.max_bitrate_bps, |
348 config.bitrate_config.start_bitrate_bps); | 371 config.bitrate_config.start_bitrate_bps); |
349 } | 372 } |
350 Trace::CreateTrace(); | 373 Trace::CreateTrace(); |
(...skipping 504 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
855 rtc::CritScope cs(&bitrate_crit_); | 878 rtc::CritScope cs(&bitrate_crit_); |
856 stats.max_padding_bitrate_bps = configured_max_padding_bitrate_bps_; | 879 stats.max_padding_bitrate_bps = configured_max_padding_bitrate_bps_; |
857 } | 880 } |
858 return stats; | 881 return stats; |
859 } | 882 } |
860 | 883 |
861 void Call::SetBitrateConfig( | 884 void Call::SetBitrateConfig( |
862 const webrtc::Call::Config::BitrateConfig& bitrate_config) { | 885 const webrtc::Call::Config::BitrateConfig& bitrate_config) { |
863 TRACE_EVENT0("webrtc", "Call::SetBitrateConfig"); | 886 TRACE_EVENT0("webrtc", "Call::SetBitrateConfig"); |
864 RTC_DCHECK(configuration_thread_checker_.CalledOnValidThread()); | 887 RTC_DCHECK(configuration_thread_checker_.CalledOnValidThread()); |
888 | |
865 RTC_DCHECK_GE(bitrate_config.min_bitrate_bps, 0); | 889 RTC_DCHECK_GE(bitrate_config.min_bitrate_bps, 0); |
866 if (bitrate_config.max_bitrate_bps != -1) | 890 RTC_DCHECK_NE(bitrate_config.start_bitrate_bps, 0); |
891 if (bitrate_config.max_bitrate_bps != -1) { | |
867 RTC_DCHECK_GT(bitrate_config.max_bitrate_bps, 0); | 892 RTC_DCHECK_GT(bitrate_config.max_bitrate_bps, 0); |
868 if (config_.bitrate_config.min_bitrate_bps == | 893 } |
869 bitrate_config.min_bitrate_bps && | 894 |
870 (bitrate_config.start_bitrate_bps <= 0 || | 895 BitrateUpdate update; |
871 config_.bitrate_config.start_bitrate_bps == | 896 |
872 bitrate_config.start_bitrate_bps) && | 897 const int min = bitrate_config.min_bitrate_bps; |
873 config_.bitrate_config.max_bitrate_bps == | 898 if (min != base_bitrate_config_.min_bitrate_bps) { |
874 bitrate_config.max_bitrate_bps) { | 899 base_bitrate_config_.min_bitrate_bps = min; |
875 // Nothing new to set, early abort to avoid encoder reconfigurations. | 900 if (!bitrate_config_mask_.min_bitrate_bps || |
901 min > *bitrate_config_mask_.min_bitrate_bps) { | |
902 update.min_bitrate_bps = rtc::Optional<int>(min); | |
903 LOG(LS_INFO) << "WebRTC.Call.SetBitrateConfig: " | |
904 << "Planning to update min to " << min; | |
905 } | |
906 } | |
907 | |
908 const int start = bitrate_config.start_bitrate_bps; | |
909 if (start != -1 && start != base_bitrate_config_.start_bitrate_bps) { | |
910 base_bitrate_config_.start_bitrate_bps = start; | |
911 update.start_bitrate_bps = rtc::Optional<int>(start); | |
912 LOG(LS_INFO) << "WebRTC.Call.SetBitrateConfig: " | |
913 << "Planning to update start to " << start; | |
914 } | |
915 const int max = bitrate_config.max_bitrate_bps; | |
916 if (max != -1 && max != base_bitrate_config_.max_bitrate_bps) { | |
917 base_bitrate_config_.max_bitrate_bps = max; | |
918 if (!bitrate_config_mask_.max_bitrate_bps || | |
919 max < *bitrate_config_mask_.max_bitrate_bps) { | |
920 update.max_bitrate_bps = rtc::Optional<int>(max); | |
921 LOG(LS_INFO) << "WebRTC.Call.SetBitrateConfig: " | |
922 << "Planning to update max to " << max; | |
923 } | |
924 } | |
925 | |
926 UpdateCurrentBitrateConfig(update); | |
927 } | |
928 | |
929 void Call::SetBitrateConfigMask( | |
930 const webrtc::Call::Config::BitrateConfigMask& mask) { | |
931 TRACE_EVENT0("webrtc", "Call::SetBitrateConfigMask"); | |
932 RTC_DCHECK(configuration_thread_checker_.CalledOnValidThread()); | |
933 | |
934 bitrate_config_mask_ = mask; | |
935 BitrateUpdate update; | |
936 | |
937 if (mask.min_bitrate_bps && | |
938 *mask.min_bitrate_bps > base_bitrate_config_.min_bitrate_bps) { | |
939 update.min_bitrate_bps = mask.min_bitrate_bps; | |
940 } | |
941 update.start_bitrate_bps = mask.start_bitrate_bps; | |
942 if (mask.max_bitrate_bps && | |
943 (base_bitrate_config_.max_bitrate_bps == -1 || | |
944 *mask.max_bitrate_bps < base_bitrate_config_.max_bitrate_bps)) { | |
945 update.max_bitrate_bps = mask.max_bitrate_bps; | |
946 } | |
947 | |
948 UpdateCurrentBitrateConfig(update); | |
949 } | |
950 | |
951 void Call::UpdateCurrentBitrateConfig(const BitrateUpdate& update) { | |
952 if (!update.min_bitrate_bps && !update.start_bitrate_bps && | |
953 !update.max_bitrate_bps) { | |
954 // Nothing to update. | |
955 LOG(LS_INFO) << "WebRTC.Call.UpdateCurrentBitrateConfig: " | |
956 << "nothing to update"; | |
Taylor Brandstetter
2017/05/11 23:14:08
This could be spammy if it happens for every SDP o
Zach Stein
2017/05/23 20:58:53
Done.
| |
876 return; | 957 return; |
877 } | 958 } |
878 config_.bitrate_config.min_bitrate_bps = bitrate_config.min_bitrate_bps; | 959 |
879 // Start bitrate of -1 means we should keep the old bitrate, which there is | 960 Config::BitrateConfig updated; |
880 // no point in remembering for the future. | 961 const Config::BitrateConfig& current = config_.bitrate_config; |
881 if (bitrate_config.start_bitrate_bps > 0) | 962 updated.min_bitrate_bps = |
882 config_.bitrate_config.start_bitrate_bps = bitrate_config.start_bitrate_bps; | 963 update.min_bitrate_bps.value_or(current.min_bitrate_bps); |
883 config_.bitrate_config.max_bitrate_bps = bitrate_config.max_bitrate_bps; | 964 updated.start_bitrate_bps = |
884 RTC_DCHECK_NE(bitrate_config.start_bitrate_bps, 0); | 965 update.start_bitrate_bps.value_or(current.start_bitrate_bps); |
966 updated.max_bitrate_bps = | |
967 update.max_bitrate_bps.value_or(current.max_bitrate_bps); | |
968 | |
969 // TODO(zstein): This clamp logic is different than send_side_cc's (moves min | |
970 // instead of max, allows start to be greather than min) - check that it is a | |
971 // sensible difference. | |
972 | |
973 // Clamp min under max and start under max and above min. | |
974 if (updated.max_bitrate_bps != -1) { | |
975 updated.min_bitrate_bps = | |
976 std::min(updated.min_bitrate_bps, updated.max_bitrate_bps); | |
977 } | |
978 updated.start_bitrate_bps = | |
979 cricket::MinPositive(updated.start_bitrate_bps, updated.max_bitrate_bps); | |
980 updated.start_bitrate_bps = | |
981 std::max(updated.start_bitrate_bps, updated.min_bitrate_bps); | |
982 | |
983 int effective_start = | |
984 update.start_bitrate_bps ? updated.start_bitrate_bps : -1; | |
985 LOG(INFO) << "WebRTC.Call.UpdateCurrentBitrateConfig: " | |
986 << "calling SetBweBitrates with args (" << updated.min_bitrate_bps | |
987 << ", " << effective_start << ", " << updated.max_bitrate_bps | |
988 << ")"; | |
885 transport_send_->send_side_cc()->SetBweBitrates( | 989 transport_send_->send_side_cc()->SetBweBitrates( |
886 bitrate_config.min_bitrate_bps, bitrate_config.start_bitrate_bps, | 990 updated.min_bitrate_bps, effective_start, updated.max_bitrate_bps); |
887 bitrate_config.max_bitrate_bps); | 991 config_.bitrate_config = updated; |
888 } | 992 } |
889 | 993 |
890 void Call::SignalChannelNetworkState(MediaType media, NetworkState state) { | 994 void Call::SignalChannelNetworkState(MediaType media, NetworkState state) { |
891 RTC_DCHECK(configuration_thread_checker_.CalledOnValidThread()); | 995 RTC_DCHECK(configuration_thread_checker_.CalledOnValidThread()); |
892 switch (media) { | 996 switch (media) { |
893 case MediaType::AUDIO: | 997 case MediaType::AUDIO: |
894 audio_network_state_ = state; | 998 audio_network_state_ = state; |
895 break; | 999 break; |
896 case MediaType::VIDEO: | 1000 case MediaType::VIDEO: |
897 video_network_state_ = state; | 1001 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)) { | 1392 (use_send_side_bwe && header.extension.hasTransportSequenceNumber)) { |
1289 receive_side_cc_.OnReceivedPacket( | 1393 receive_side_cc_.OnReceivedPacket( |
1290 packet.arrival_time_ms(), packet.payload_size() + packet.padding_size(), | 1394 packet.arrival_time_ms(), packet.payload_size() + packet.padding_size(), |
1291 header); | 1395 header); |
1292 } | 1396 } |
1293 } | 1397 } |
1294 | 1398 |
1295 } // namespace internal | 1399 } // namespace internal |
1296 | 1400 |
1297 } // namespace webrtc | 1401 } // namespace webrtc |
OLD | NEW |