Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(90)

Side by Side Diff: webrtc/call/call.cc

Issue 1993113003: Refactor how padding is calculated. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Self review Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
47 #include "webrtc/voice_engine/include/voe_codec.h" 47 #include "webrtc/voice_engine/include/voe_codec.h"
48 48
49 namespace webrtc { 49 namespace webrtc {
50 50
51 const int Call::Config::kDefaultStartBitrateBps = 300000; 51 const int Call::Config::kDefaultStartBitrateBps = 300000;
52 52
53 namespace internal { 53 namespace internal {
54 54
55 class Call : public webrtc::Call, 55 class Call : public webrtc::Call,
56 public PacketReceiver, 56 public PacketReceiver,
57 public CongestionController::Observer { 57 public CongestionController::Observer,
58 public BitrateAllocator::LimitObserver {
58 public: 59 public:
59 explicit Call(const Call::Config& config); 60 explicit Call(const Call::Config& config);
60 virtual ~Call(); 61 virtual ~Call();
61 62
62 PacketReceiver* Receiver() override; 63 PacketReceiver* Receiver() override;
63 64
64 webrtc::AudioSendStream* CreateAudioSendStream( 65 webrtc::AudioSendStream* CreateAudioSendStream(
65 const webrtc::AudioSendStream::Config& config) override; 66 const webrtc::AudioSendStream::Config& config) override;
66 void DestroyAudioSendStream(webrtc::AudioSendStream* send_stream) override; 67 void DestroyAudioSendStream(webrtc::AudioSendStream* send_stream) override;
67 68
(...skipping 26 matching lines...) Expand all
94 95
95 void OnNetworkRouteChanged(const std::string& transport_name, 96 void OnNetworkRouteChanged(const std::string& transport_name,
96 const rtc::NetworkRoute& network_route) override; 97 const rtc::NetworkRoute& network_route) override;
97 98
98 void OnSentPacket(const rtc::SentPacket& sent_packet) override; 99 void OnSentPacket(const rtc::SentPacket& sent_packet) override;
99 100
100 // Implements BitrateObserver. 101 // Implements BitrateObserver.
101 void OnNetworkChanged(uint32_t bitrate_bps, uint8_t fraction_loss, 102 void OnNetworkChanged(uint32_t bitrate_bps, uint8_t fraction_loss,
102 int64_t rtt_ms) override; 103 int64_t rtt_ms) override;
103 104
105 // Implements BitrateAllocator::LimitObserver.
106 void OnAllocationLimitsChanged(uint32_t min_send_bitrate_bps,
107 uint32_t max_padding_bitrate_bps) override;
108
104 private: 109 private:
105 DeliveryStatus DeliverRtcp(MediaType media_type, const uint8_t* packet, 110 DeliveryStatus DeliverRtcp(MediaType media_type, const uint8_t* packet,
106 size_t length); 111 size_t length);
107 DeliveryStatus DeliverRtp(MediaType media_type, 112 DeliveryStatus DeliverRtp(MediaType media_type,
108 const uint8_t* packet, 113 const uint8_t* packet,
109 size_t length, 114 size_t length,
110 const PacketTime& packet_time); 115 const PacketTime& packet_time);
111 void ConfigureSync(const std::string& sync_group) 116 void ConfigureSync(const std::string& sync_group)
112 EXCLUSIVE_LOCKS_REQUIRED(receive_crit_); 117 EXCLUSIVE_LOCKS_REQUIRED(receive_crit_);
113 118
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
166 int64_t received_rtcp_bytes_; 171 int64_t received_rtcp_bytes_;
167 int64_t first_rtp_packet_received_ms_; 172 int64_t first_rtp_packet_received_ms_;
168 int64_t last_rtp_packet_received_ms_; 173 int64_t last_rtp_packet_received_ms_;
169 int64_t first_packet_sent_ms_; 174 int64_t first_packet_sent_ms_;
170 175
171 // TODO(holmer): Remove this lock once BitrateController no longer calls 176 // TODO(holmer): Remove this lock once BitrateController no longer calls
172 // OnNetworkChanged from multiple threads. 177 // OnNetworkChanged from multiple threads.
173 rtc::CriticalSection bitrate_crit_; 178 rtc::CriticalSection bitrate_crit_;
174 int64_t estimated_send_bitrate_sum_kbits_ GUARDED_BY(&bitrate_crit_); 179 int64_t estimated_send_bitrate_sum_kbits_ GUARDED_BY(&bitrate_crit_);
175 int64_t pacer_bitrate_sum_kbits_ GUARDED_BY(&bitrate_crit_); 180 int64_t pacer_bitrate_sum_kbits_ GUARDED_BY(&bitrate_crit_);
181 uint32_t min_allocated_send_bitrate_bps_ GUARDED_BY(&bitrate_crit_);
176 int64_t num_bitrate_updates_ GUARDED_BY(&bitrate_crit_); 182 int64_t num_bitrate_updates_ GUARDED_BY(&bitrate_crit_);
177 183
178 std::map<std::string, rtc::NetworkRoute> network_routes_; 184 std::map<std::string, rtc::NetworkRoute> network_routes_;
179 185
180 VieRemb remb_; 186 VieRemb remb_;
181 const std::unique_ptr<CongestionController> congestion_controller_; 187 const std::unique_ptr<CongestionController> congestion_controller_;
182 const std::unique_ptr<SendDelayStats> video_send_delay_stats_; 188 const std::unique_ptr<SendDelayStats> video_send_delay_stats_;
183 189
184 RTC_DISALLOW_COPY_AND_ASSIGN(Call); 190 RTC_DISALLOW_COPY_AND_ASSIGN(Call);
185 }; 191 };
186 } // namespace internal 192 } // namespace internal
187 193
188 Call* Call::Create(const Call::Config& config) { 194 Call* Call::Create(const Call::Config& config) {
189 return new internal::Call(config); 195 return new internal::Call(config);
190 } 196 }
191 197
192 namespace internal { 198 namespace internal {
193 199
194 Call::Call(const Call::Config& config) 200 Call::Call(const Call::Config& config)
195 : clock_(Clock::GetRealTimeClock()), 201 : clock_(Clock::GetRealTimeClock()),
196 num_cpu_cores_(CpuInfo::DetectNumberOfCores()), 202 num_cpu_cores_(CpuInfo::DetectNumberOfCores()),
197 module_process_thread_(ProcessThread::Create("ModuleProcessThread")), 203 module_process_thread_(ProcessThread::Create("ModuleProcessThread")),
198 pacer_thread_(ProcessThread::Create("PacerThread")), 204 pacer_thread_(ProcessThread::Create("PacerThread")),
199 call_stats_(new CallStats(clock_)), 205 call_stats_(new CallStats(clock_)),
200 bitrate_allocator_(new BitrateAllocator()), 206 bitrate_allocator_(new BitrateAllocator(this)),
201 config_(config), 207 config_(config),
202 audio_network_state_(kNetworkUp), 208 audio_network_state_(kNetworkUp),
203 video_network_state_(kNetworkUp), 209 video_network_state_(kNetworkUp),
204 receive_crit_(RWLockWrapper::CreateRWLock()), 210 receive_crit_(RWLockWrapper::CreateRWLock()),
205 send_crit_(RWLockWrapper::CreateRWLock()), 211 send_crit_(RWLockWrapper::CreateRWLock()),
206 received_video_bytes_(0), 212 received_video_bytes_(0),
207 received_audio_bytes_(0), 213 received_audio_bytes_(0),
208 received_rtcp_bytes_(0), 214 received_rtcp_bytes_(0),
209 first_rtp_packet_received_ms_(-1), 215 first_rtp_packet_received_ms_(-1),
210 last_rtp_packet_received_ms_(-1), 216 last_rtp_packet_received_ms_(-1),
(...skipping 456 matching lines...) Expand 10 before | Expand all | Expand 10 after
667 void Call::OnSentPacket(const rtc::SentPacket& sent_packet) { 673 void Call::OnSentPacket(const rtc::SentPacket& sent_packet) {
668 if (first_packet_sent_ms_ == -1) 674 if (first_packet_sent_ms_ == -1)
669 first_packet_sent_ms_ = clock_->TimeInMilliseconds(); 675 first_packet_sent_ms_ = clock_->TimeInMilliseconds();
670 video_send_delay_stats_->OnSentPacket(sent_packet.packet_id, 676 video_send_delay_stats_->OnSentPacket(sent_packet.packet_id,
671 clock_->TimeInMilliseconds()); 677 clock_->TimeInMilliseconds());
672 congestion_controller_->OnSentPacket(sent_packet); 678 congestion_controller_->OnSentPacket(sent_packet);
673 } 679 }
674 680
675 void Call::OnNetworkChanged(uint32_t target_bitrate_bps, uint8_t fraction_loss, 681 void Call::OnNetworkChanged(uint32_t target_bitrate_bps, uint8_t fraction_loss,
676 int64_t rtt_ms) { 682 int64_t rtt_ms) {
677 uint32_t allocated_bitrate_bps = bitrate_allocator_->OnNetworkChanged( 683 bitrate_allocator_->OnNetworkChanged(target_bitrate_bps, fraction_loss,
678 target_bitrate_bps, fraction_loss, rtt_ms); 684 rtt_ms);
679 685
680 int pad_up_to_bitrate_bps = 0;
681 {
682 ReadLockScoped read_lock(*send_crit_);
683 // No need to update as long as we're not sending.
684 if (video_send_streams_.empty())
685 return;
686
687 for (VideoSendStream* stream : video_send_streams_)
688 pad_up_to_bitrate_bps += stream->GetPaddingNeededBps();
689 }
690 // Allocated bitrate might be higher than bitrate estimate if enforcing min
691 // bitrate, or lower if estimate is higher than the sum of max bitrates, so
692 // set the pacer bitrate to the maximum of the two.
693 uint32_t pacer_bitrate_bps =
694 std::max(target_bitrate_bps, allocated_bitrate_bps);
695 { 686 {
696 rtc::CritScope lock(&bitrate_crit_); 687 rtc::CritScope lock(&bitrate_crit_);
697 // We only update these stats if we have send streams, and assume that 688 // We only update these stats if we have send streams, and assume that
698 // OnNetworkChanged is called roughly with a fixed frequency. 689 // OnNetworkChanged is called roughly with a fixed frequency.
699 estimated_send_bitrate_sum_kbits_ += target_bitrate_bps / 1000; 690 estimated_send_bitrate_sum_kbits_ += target_bitrate_bps / 1000;
691 // Pacer bitrate might be higher than bitrate estimate if enforcing min
692 // bitrate.
693 uint32_t pacer_bitrate_bps =
694 std::max(target_bitrate_bps, min_allocated_send_bitrate_bps_);
700 pacer_bitrate_sum_kbits_ += pacer_bitrate_bps / 1000; 695 pacer_bitrate_sum_kbits_ += pacer_bitrate_bps / 1000;
701 ++num_bitrate_updates_; 696 ++num_bitrate_updates_;
702 } 697 }
703 congestion_controller_->SetAllocatedSendBitrate(allocated_bitrate_bps, 698 }
704 pad_up_to_bitrate_bps); 699
700 void Call::OnAllocationLimitsChanged(uint32_t min_send_bitrate_bps,
701 uint32_t max_padding_bitrate_bps) {
702 congestion_controller_->SetAllocatedSendBitrate(min_send_bitrate_bps,
703 max_padding_bitrate_bps);
704 rtc::CritScope lock(&bitrate_crit_);
705 min_allocated_send_bitrate_bps_ = min_send_bitrate_bps;
705 } 706 }
706 707
707 void Call::ConfigureSync(const std::string& sync_group) { 708 void Call::ConfigureSync(const std::string& sync_group) {
708 // Set sync only if there was no previous one. 709 // Set sync only if there was no previous one.
709 if (voice_engine() == nullptr || sync_group.empty()) 710 if (voice_engine() == nullptr || sync_group.empty())
710 return; 711 return;
711 712
712 AudioReceiveStream* sync_audio_stream = nullptr; 713 AudioReceiveStream* sync_audio_stream = nullptr;
713 // Find existing audio stream. 714 // Find existing audio stream.
714 const auto it = sync_stream_mapping_.find(sync_group); 715 const auto it = sync_stream_mapping_.find(sync_group);
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
848 // thread. Then this check can be enabled. 849 // thread. Then this check can be enabled.
849 // RTC_DCHECK(!configuration_thread_checker_.CalledOnValidThread()); 850 // RTC_DCHECK(!configuration_thread_checker_.CalledOnValidThread());
850 if (RtpHeaderParser::IsRtcp(packet, length)) 851 if (RtpHeaderParser::IsRtcp(packet, length))
851 return DeliverRtcp(media_type, packet, length); 852 return DeliverRtcp(media_type, packet, length);
852 853
853 return DeliverRtp(media_type, packet, length, packet_time); 854 return DeliverRtp(media_type, packet, length, packet_time);
854 } 855 }
855 856
856 } // namespace internal 857 } // namespace internal
857 } // namespace webrtc 858 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698