| 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 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 48 #include "webrtc/voice_engine/include/voe_codec.h" | 48 #include "webrtc/voice_engine/include/voe_codec.h" |
| 49 | 49 |
| 50 namespace webrtc { | 50 namespace webrtc { |
| 51 | 51 |
| 52 const int Call::Config::kDefaultStartBitrateBps = 300000; | 52 const int Call::Config::kDefaultStartBitrateBps = 300000; |
| 53 | 53 |
| 54 namespace internal { | 54 namespace internal { |
| 55 | 55 |
| 56 class Call : public webrtc::Call, | 56 class Call : public webrtc::Call, |
| 57 public PacketReceiver, | 57 public PacketReceiver, |
| 58 public CongestionController::Observer { | 58 public CongestionController::Observer, |
| 59 public BitrateAllocator::LimitObserver { |
| 59 public: | 60 public: |
| 60 explicit Call(const Call::Config& config); | 61 explicit Call(const Call::Config& config); |
| 61 virtual ~Call(); | 62 virtual ~Call(); |
| 62 | 63 |
| 63 PacketReceiver* Receiver() override; | 64 PacketReceiver* Receiver() override; |
| 64 | 65 |
| 65 webrtc::AudioSendStream* CreateAudioSendStream( | 66 webrtc::AudioSendStream* CreateAudioSendStream( |
| 66 const webrtc::AudioSendStream::Config& config) override; | 67 const webrtc::AudioSendStream::Config& config) override; |
| 67 void DestroyAudioSendStream(webrtc::AudioSendStream* send_stream) override; | 68 void DestroyAudioSendStream(webrtc::AudioSendStream* send_stream) override; |
| 68 | 69 |
| (...skipping 26 matching lines...) Expand all Loading... |
| 95 | 96 |
| 96 void OnNetworkRouteChanged(const std::string& transport_name, | 97 void OnNetworkRouteChanged(const std::string& transport_name, |
| 97 const rtc::NetworkRoute& network_route) override; | 98 const rtc::NetworkRoute& network_route) override; |
| 98 | 99 |
| 99 void OnSentPacket(const rtc::SentPacket& sent_packet) override; | 100 void OnSentPacket(const rtc::SentPacket& sent_packet) override; |
| 100 | 101 |
| 101 // Implements BitrateObserver. | 102 // Implements BitrateObserver. |
| 102 void OnNetworkChanged(uint32_t bitrate_bps, uint8_t fraction_loss, | 103 void OnNetworkChanged(uint32_t bitrate_bps, uint8_t fraction_loss, |
| 103 int64_t rtt_ms) override; | 104 int64_t rtt_ms) override; |
| 104 | 105 |
| 106 // Implements BitrateAllocator::LimitObserver. |
| 107 void OnAllocationLimitsChanged(uint32_t min_send_bitrate_bps, |
| 108 uint32_t max_padding_bitrate_bps) override; |
| 109 |
| 105 private: | 110 private: |
| 106 DeliveryStatus DeliverRtcp(MediaType media_type, const uint8_t* packet, | 111 DeliveryStatus DeliverRtcp(MediaType media_type, const uint8_t* packet, |
| 107 size_t length); | 112 size_t length); |
| 108 DeliveryStatus DeliverRtp(MediaType media_type, | 113 DeliveryStatus DeliverRtp(MediaType media_type, |
| 109 const uint8_t* packet, | 114 const uint8_t* packet, |
| 110 size_t length, | 115 size_t length, |
| 111 const PacketTime& packet_time); | 116 const PacketTime& packet_time); |
| 112 void ConfigureSync(const std::string& sync_group) | 117 void ConfigureSync(const std::string& sync_group) |
| 113 EXCLUSIVE_LOCKS_REQUIRED(receive_crit_); | 118 EXCLUSIVE_LOCKS_REQUIRED(receive_crit_); |
| 114 | 119 |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 167 int64_t received_rtcp_bytes_; | 172 int64_t received_rtcp_bytes_; |
| 168 int64_t first_rtp_packet_received_ms_; | 173 int64_t first_rtp_packet_received_ms_; |
| 169 int64_t last_rtp_packet_received_ms_; | 174 int64_t last_rtp_packet_received_ms_; |
| 170 int64_t first_packet_sent_ms_; | 175 int64_t first_packet_sent_ms_; |
| 171 | 176 |
| 172 // TODO(holmer): Remove this lock once BitrateController no longer calls | 177 // TODO(holmer): Remove this lock once BitrateController no longer calls |
| 173 // OnNetworkChanged from multiple threads. | 178 // OnNetworkChanged from multiple threads. |
| 174 rtc::CriticalSection bitrate_crit_; | 179 rtc::CriticalSection bitrate_crit_; |
| 175 int64_t estimated_send_bitrate_sum_kbits_ GUARDED_BY(&bitrate_crit_); | 180 int64_t estimated_send_bitrate_sum_kbits_ GUARDED_BY(&bitrate_crit_); |
| 176 int64_t pacer_bitrate_sum_kbits_ GUARDED_BY(&bitrate_crit_); | 181 int64_t pacer_bitrate_sum_kbits_ GUARDED_BY(&bitrate_crit_); |
| 182 uint32_t min_allocated_send_bitrate_bps_ GUARDED_BY(&bitrate_crit_); |
| 177 int64_t num_bitrate_updates_ GUARDED_BY(&bitrate_crit_); | 183 int64_t num_bitrate_updates_ GUARDED_BY(&bitrate_crit_); |
| 178 | 184 |
| 179 std::map<std::string, rtc::NetworkRoute> network_routes_; | 185 std::map<std::string, rtc::NetworkRoute> network_routes_; |
| 180 | 186 |
| 181 VieRemb remb_; | 187 VieRemb remb_; |
| 182 const std::unique_ptr<CongestionController> congestion_controller_; | 188 const std::unique_ptr<CongestionController> congestion_controller_; |
| 183 const std::unique_ptr<SendDelayStats> video_send_delay_stats_; | 189 const std::unique_ptr<SendDelayStats> video_send_delay_stats_; |
| 184 | 190 |
| 185 RTC_DISALLOW_COPY_AND_ASSIGN(Call); | 191 RTC_DISALLOW_COPY_AND_ASSIGN(Call); |
| 186 }; | 192 }; |
| 187 } // namespace internal | 193 } // namespace internal |
| 188 | 194 |
| 189 Call* Call::Create(const Call::Config& config) { | 195 Call* Call::Create(const Call::Config& config) { |
| 190 return new internal::Call(config); | 196 return new internal::Call(config); |
| 191 } | 197 } |
| 192 | 198 |
| 193 namespace internal { | 199 namespace internal { |
| 194 | 200 |
| 195 Call::Call(const Call::Config& config) | 201 Call::Call(const Call::Config& config) |
| 196 : clock_(Clock::GetRealTimeClock()), | 202 : clock_(Clock::GetRealTimeClock()), |
| 197 num_cpu_cores_(CpuInfo::DetectNumberOfCores()), | 203 num_cpu_cores_(CpuInfo::DetectNumberOfCores()), |
| 198 module_process_thread_(ProcessThread::Create("ModuleProcessThread")), | 204 module_process_thread_(ProcessThread::Create("ModuleProcessThread")), |
| 199 pacer_thread_(ProcessThread::Create("PacerThread")), | 205 pacer_thread_(ProcessThread::Create("PacerThread")), |
| 200 call_stats_(new CallStats(clock_)), | 206 call_stats_(new CallStats(clock_)), |
| 201 bitrate_allocator_(new BitrateAllocator()), | 207 bitrate_allocator_(new BitrateAllocator(this)), |
| 202 config_(config), | 208 config_(config), |
| 203 audio_network_state_(kNetworkUp), | 209 audio_network_state_(kNetworkUp), |
| 204 video_network_state_(kNetworkUp), | 210 video_network_state_(kNetworkUp), |
| 205 receive_crit_(RWLockWrapper::CreateRWLock()), | 211 receive_crit_(RWLockWrapper::CreateRWLock()), |
| 206 send_crit_(RWLockWrapper::CreateRWLock()), | 212 send_crit_(RWLockWrapper::CreateRWLock()), |
| 207 received_video_bytes_(0), | 213 received_video_bytes_(0), |
| 208 received_audio_bytes_(0), | 214 received_audio_bytes_(0), |
| 209 received_rtcp_bytes_(0), | 215 received_rtcp_bytes_(0), |
| 210 first_rtp_packet_received_ms_(-1), | 216 first_rtp_packet_received_ms_(-1), |
| 211 last_rtp_packet_received_ms_(-1), | 217 last_rtp_packet_received_ms_(-1), |
| 212 first_packet_sent_ms_(-1), | 218 first_packet_sent_ms_(-1), |
| 213 estimated_send_bitrate_sum_kbits_(0), | 219 estimated_send_bitrate_sum_kbits_(0), |
| 214 pacer_bitrate_sum_kbits_(0), | 220 pacer_bitrate_sum_kbits_(0), |
| 221 min_allocated_send_bitrate_bps_(0), |
| 215 num_bitrate_updates_(0), | 222 num_bitrate_updates_(0), |
| 216 remb_(clock_), | 223 remb_(clock_), |
| 217 congestion_controller_(new CongestionController(clock_, this, &remb_)), | 224 congestion_controller_(new CongestionController(clock_, this, &remb_)), |
| 218 video_send_delay_stats_(new SendDelayStats(clock_)) { | 225 video_send_delay_stats_(new SendDelayStats(clock_)) { |
| 219 RTC_DCHECK(configuration_thread_checker_.CalledOnValidThread()); | 226 RTC_DCHECK(configuration_thread_checker_.CalledOnValidThread()); |
| 220 RTC_DCHECK_GE(config.bitrate_config.min_bitrate_bps, 0); | 227 RTC_DCHECK_GE(config.bitrate_config.min_bitrate_bps, 0); |
| 221 RTC_DCHECK_GE(config.bitrate_config.start_bitrate_bps, | 228 RTC_DCHECK_GE(config.bitrate_config.start_bitrate_bps, |
| 222 config.bitrate_config.min_bitrate_bps); | 229 config.bitrate_config.min_bitrate_bps); |
| 223 if (config.bitrate_config.max_bitrate_bps != -1) { | 230 if (config.bitrate_config.max_bitrate_bps != -1) { |
| 224 RTC_DCHECK_GE(config.bitrate_config.max_bitrate_bps, | 231 RTC_DCHECK_GE(config.bitrate_config.max_bitrate_bps, |
| (...skipping 445 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 670 void Call::OnSentPacket(const rtc::SentPacket& sent_packet) { | 677 void Call::OnSentPacket(const rtc::SentPacket& sent_packet) { |
| 671 if (first_packet_sent_ms_ == -1) | 678 if (first_packet_sent_ms_ == -1) |
| 672 first_packet_sent_ms_ = clock_->TimeInMilliseconds(); | 679 first_packet_sent_ms_ = clock_->TimeInMilliseconds(); |
| 673 video_send_delay_stats_->OnSentPacket(sent_packet.packet_id, | 680 video_send_delay_stats_->OnSentPacket(sent_packet.packet_id, |
| 674 clock_->TimeInMilliseconds()); | 681 clock_->TimeInMilliseconds()); |
| 675 congestion_controller_->OnSentPacket(sent_packet); | 682 congestion_controller_->OnSentPacket(sent_packet); |
| 676 } | 683 } |
| 677 | 684 |
| 678 void Call::OnNetworkChanged(uint32_t target_bitrate_bps, uint8_t fraction_loss, | 685 void Call::OnNetworkChanged(uint32_t target_bitrate_bps, uint8_t fraction_loss, |
| 679 int64_t rtt_ms) { | 686 int64_t rtt_ms) { |
| 680 uint32_t allocated_bitrate_bps = bitrate_allocator_->OnNetworkChanged( | 687 bitrate_allocator_->OnNetworkChanged(target_bitrate_bps, fraction_loss, |
| 681 target_bitrate_bps, fraction_loss, rtt_ms); | 688 rtt_ms); |
| 682 | 689 |
| 683 int pad_up_to_bitrate_bps = 0; | |
| 684 { | |
| 685 ReadLockScoped read_lock(*send_crit_); | |
| 686 // No need to update as long as we're not sending. | |
| 687 if (video_send_streams_.empty()) | |
| 688 return; | |
| 689 | |
| 690 for (VideoSendStream* stream : video_send_streams_) | |
| 691 pad_up_to_bitrate_bps += stream->GetPaddingNeededBps(); | |
| 692 } | |
| 693 // Allocated bitrate might be higher than bitrate estimate if enforcing min | |
| 694 // bitrate, or lower if estimate is higher than the sum of max bitrates, so | |
| 695 // set the pacer bitrate to the maximum of the two. | |
| 696 uint32_t pacer_bitrate_bps = | |
| 697 std::max(target_bitrate_bps, allocated_bitrate_bps); | |
| 698 { | 690 { |
| 699 rtc::CritScope lock(&bitrate_crit_); | 691 rtc::CritScope lock(&bitrate_crit_); |
| 700 // We only update these stats if we have send streams, and assume that | 692 // We only update these stats if we have send streams, and assume that |
| 701 // OnNetworkChanged is called roughly with a fixed frequency. | 693 // OnNetworkChanged is called roughly with a fixed frequency. |
| 702 estimated_send_bitrate_sum_kbits_ += target_bitrate_bps / 1000; | 694 estimated_send_bitrate_sum_kbits_ += target_bitrate_bps / 1000; |
| 695 // Pacer bitrate might be higher than bitrate estimate if enforcing min |
| 696 // bitrate. |
| 697 uint32_t pacer_bitrate_bps = |
| 698 std::max(target_bitrate_bps, min_allocated_send_bitrate_bps_); |
| 703 pacer_bitrate_sum_kbits_ += pacer_bitrate_bps / 1000; | 699 pacer_bitrate_sum_kbits_ += pacer_bitrate_bps / 1000; |
| 704 ++num_bitrate_updates_; | 700 ++num_bitrate_updates_; |
| 705 } | 701 } |
| 702 } |
| 706 | 703 |
| 707 // Make sure to not ask for more padding than the current BWE allows for. | 704 void Call::OnAllocationLimitsChanged(uint32_t min_send_bitrate_bps, |
| 708 pad_up_to_bitrate_bps = std::min(static_cast<uint32_t>(pad_up_to_bitrate_bps), | 705 uint32_t max_padding_bitrate_bps) { |
| 709 target_bitrate_bps); | 706 congestion_controller_->SetAllocatedSendBitrateLimits( |
| 710 congestion_controller_->SetAllocatedSendBitrate(allocated_bitrate_bps, | 707 min_send_bitrate_bps, max_padding_bitrate_bps); |
| 711 pad_up_to_bitrate_bps); | 708 rtc::CritScope lock(&bitrate_crit_); |
| 709 min_allocated_send_bitrate_bps_ = min_send_bitrate_bps; |
| 712 } | 710 } |
| 713 | 711 |
| 714 void Call::ConfigureSync(const std::string& sync_group) { | 712 void Call::ConfigureSync(const std::string& sync_group) { |
| 715 // Set sync only if there was no previous one. | 713 // Set sync only if there was no previous one. |
| 716 if (voice_engine() == nullptr || sync_group.empty()) | 714 if (voice_engine() == nullptr || sync_group.empty()) |
| 717 return; | 715 return; |
| 718 | 716 |
| 719 AudioReceiveStream* sync_audio_stream = nullptr; | 717 AudioReceiveStream* sync_audio_stream = nullptr; |
| 720 // Find existing audio stream. | 718 // Find existing audio stream. |
| 721 const auto it = sync_stream_mapping_.find(sync_group); | 719 const auto it = sync_stream_mapping_.find(sync_group); |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 855 // thread. Then this check can be enabled. | 853 // thread. Then this check can be enabled. |
| 856 // RTC_DCHECK(!configuration_thread_checker_.CalledOnValidThread()); | 854 // RTC_DCHECK(!configuration_thread_checker_.CalledOnValidThread()); |
| 857 if (RtpHeaderParser::IsRtcp(packet, length)) | 855 if (RtpHeaderParser::IsRtcp(packet, length)) |
| 858 return DeliverRtcp(media_type, packet, length); | 856 return DeliverRtcp(media_type, packet, length); |
| 859 | 857 |
| 860 return DeliverRtp(media_type, packet, length, packet_time); | 858 return DeliverRtp(media_type, packet, length, packet_time); |
| 861 } | 859 } |
| 862 | 860 |
| 863 } // namespace internal | 861 } // namespace internal |
| 864 } // namespace webrtc | 862 } // namespace webrtc |
| OLD | NEW |