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

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

Issue 1434403004: Add UMA for send bwe and pacer bitrate. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Add locks to handle OnNetworkChanged from multiple threads. Created 5 years, 1 month 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
« no previous file with comments | « no previous file | webrtc/video/end_to_end_tests.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
107 107
108 VoiceEngine* voice_engine() { 108 VoiceEngine* voice_engine() {
109 internal::AudioState* audio_state = 109 internal::AudioState* audio_state =
110 static_cast<internal::AudioState*>(config_.audio_state.get()); 110 static_cast<internal::AudioState*>(config_.audio_state.get());
111 if (audio_state) 111 if (audio_state)
112 return audio_state->voice_engine(); 112 return audio_state->voice_engine();
113 else 113 else
114 return nullptr; 114 return nullptr;
115 } 115 }
116 116
117 void UpdateHistograms(); 117 void UpdateSendHistograms();
118 void UpdateReceiveHistograms();
118 119
119 const Clock* const clock_; 120 const Clock* const clock_;
120 121
121 const int num_cpu_cores_; 122 const int num_cpu_cores_;
122 const rtc::scoped_ptr<ProcessThread> module_process_thread_; 123 const rtc::scoped_ptr<ProcessThread> module_process_thread_;
123 const rtc::scoped_ptr<CallStats> call_stats_; 124 const rtc::scoped_ptr<CallStats> call_stats_;
124 const rtc::scoped_ptr<BitrateAllocator> bitrate_allocator_; 125 const rtc::scoped_ptr<BitrateAllocator> bitrate_allocator_;
125 Call::Config config_; 126 Call::Config config_;
126 rtc::ThreadChecker configuration_thread_checker_; 127 rtc::ThreadChecker configuration_thread_checker_;
127 128
(...skipping 13 matching lines...) Expand all
141 rtc::scoped_ptr<RWLockWrapper> send_crit_; 142 rtc::scoped_ptr<RWLockWrapper> send_crit_;
142 // Audio and Video send streams are owned by the client that creates them. 143 // Audio and Video send streams are owned by the client that creates them.
143 std::map<uint32_t, AudioSendStream*> audio_send_ssrcs_ GUARDED_BY(send_crit_); 144 std::map<uint32_t, AudioSendStream*> audio_send_ssrcs_ GUARDED_BY(send_crit_);
144 std::map<uint32_t, VideoSendStream*> video_send_ssrcs_ GUARDED_BY(send_crit_); 145 std::map<uint32_t, VideoSendStream*> video_send_ssrcs_ GUARDED_BY(send_crit_);
145 std::set<VideoSendStream*> video_send_streams_ GUARDED_BY(send_crit_); 146 std::set<VideoSendStream*> video_send_streams_ GUARDED_BY(send_crit_);
146 147
147 VideoSendStream::RtpStateMap suspended_video_send_ssrcs_; 148 VideoSendStream::RtpStateMap suspended_video_send_ssrcs_;
148 149
149 RtcEventLog* event_log_ = nullptr; 150 RtcEventLog* event_log_ = nullptr;
150 151
151 // The RateTrackers are only accessed (exclusively) from DeliverRtp or 152 // The following members are only accessed (exclusively) from one thread and
152 // DeliverRtcp, and from the destructor, and therefore doesn't need any 153 // from the destructor, and therefore doesn't need any explicit
153 // explicit synchronization. 154 // synchronization.
154 rtc::RateTracker received_video_bytes_per_sec_; 155 rtc::RateTracker received_video_bytes_per_sec_;
155 rtc::RateTracker received_audio_bytes_per_sec_; 156 rtc::RateTracker received_audio_bytes_per_sec_;
156 rtc::RateTracker received_rtcp_bytes_per_sec_; 157 rtc::RateTracker received_rtcp_bytes_per_sec_;
158 int64_t first_packet_sent_ms_;
157 int64_t first_rtp_packet_received_ms_; 159 int64_t first_rtp_packet_received_ms_;
158 160
161 // TODO(holmer): Remove this lock once BitrateController no longer calls
162 // OnNetworkChanged from multiple threads.
163 rtc::CriticalSection bitrate_crit_;
164 rtc::RateTracker estimated_send_bitrate_kbps_ GUARDED_BY(&bitrate_crit_);
165 rtc::RateTracker pacer_bitrate_kbps_ GUARDED_BY(&bitrate_crit_);
166 uint32_t target_bitrate_bps_ GUARDED_BY(&bitrate_crit_);
167 uint32_t pacer_bitrate_bps_ GUARDED_BY(&bitrate_crit_);
168 int64_t last_bitrate_update_ms_ GUARDED_BY(&bitrate_crit_);
169
159 const rtc::scoped_ptr<CongestionController> congestion_controller_; 170 const rtc::scoped_ptr<CongestionController> congestion_controller_;
160 171
161 RTC_DISALLOW_COPY_AND_ASSIGN(Call); 172 RTC_DISALLOW_COPY_AND_ASSIGN(Call);
162 }; 173 };
163 } // namespace internal 174 } // namespace internal
164 175
165 Call* Call::Create(const Call::Config& config) { 176 Call* Call::Create(const Call::Config& config) {
166 return new internal::Call(config); 177 return new internal::Call(config);
167 } 178 }
168 179
169 namespace internal { 180 namespace internal {
170 181
171 Call::Call(const Call::Config& config) 182 Call::Call(const Call::Config& config)
172 : clock_(Clock::GetRealTimeClock()), 183 : clock_(Clock::GetRealTimeClock()),
173 num_cpu_cores_(CpuInfo::DetectNumberOfCores()), 184 num_cpu_cores_(CpuInfo::DetectNumberOfCores()),
174 module_process_thread_(ProcessThread::Create("ModuleProcessThread")), 185 module_process_thread_(ProcessThread::Create("ModuleProcessThread")),
175 call_stats_(new CallStats()), 186 call_stats_(new CallStats()),
176 bitrate_allocator_(new BitrateAllocator()), 187 bitrate_allocator_(new BitrateAllocator()),
177 config_(config), 188 config_(config),
178 network_enabled_(true), 189 network_enabled_(true),
179 receive_crit_(RWLockWrapper::CreateRWLock()), 190 receive_crit_(RWLockWrapper::CreateRWLock()),
180 send_crit_(RWLockWrapper::CreateRWLock()), 191 send_crit_(RWLockWrapper::CreateRWLock()),
181 received_video_bytes_per_sec_(1000, 1), 192 received_video_bytes_per_sec_(1000, 1),
182 received_audio_bytes_per_sec_(1000, 1), 193 received_audio_bytes_per_sec_(1000, 1),
183 received_rtcp_bytes_per_sec_(1000, 1), 194 received_rtcp_bytes_per_sec_(1000, 1),
195 first_packet_sent_ms_(-1),
184 first_rtp_packet_received_ms_(-1), 196 first_rtp_packet_received_ms_(-1),
185 congestion_controller_(new CongestionController( 197 estimated_send_bitrate_kbps_(1000, 1),
186 module_process_thread_.get(), call_stats_.get(), this)) { 198 pacer_bitrate_kbps_(1000, 1),
199 target_bitrate_bps_(0),
200 pacer_bitrate_bps_(0),
201 last_bitrate_update_ms_(-1),
202 congestion_controller_(
203 new CongestionController(module_process_thread_.get(),
204 call_stats_.get(),
205 this)) {
187 RTC_DCHECK(configuration_thread_checker_.CalledOnValidThread()); 206 RTC_DCHECK(configuration_thread_checker_.CalledOnValidThread());
188 RTC_DCHECK_GE(config.bitrate_config.min_bitrate_bps, 0); 207 RTC_DCHECK_GE(config.bitrate_config.min_bitrate_bps, 0);
189 RTC_DCHECK_GE(config.bitrate_config.start_bitrate_bps, 208 RTC_DCHECK_GE(config.bitrate_config.start_bitrate_bps,
190 config.bitrate_config.min_bitrate_bps); 209 config.bitrate_config.min_bitrate_bps);
191 if (config.bitrate_config.max_bitrate_bps != -1) { 210 if (config.bitrate_config.max_bitrate_bps != -1) {
192 RTC_DCHECK_GE(config.bitrate_config.max_bitrate_bps, 211 RTC_DCHECK_GE(config.bitrate_config.max_bitrate_bps,
193 config.bitrate_config.start_bitrate_bps); 212 config.bitrate_config.start_bitrate_bps);
194 } 213 }
195 if (config.audio_state.get()) { 214 if (config.audio_state.get()) {
196 ScopedVoEInterface<VoECodec> voe_codec(voice_engine()); 215 ScopedVoEInterface<VoECodec> voe_codec(voice_engine());
197 event_log_ = voe_codec->GetEventLog(); 216 event_log_ = voe_codec->GetEventLog();
198 } 217 }
199 218
200 Trace::CreateTrace(); 219 Trace::CreateTrace();
201 module_process_thread_->Start(); 220 module_process_thread_->Start();
202 module_process_thread_->RegisterModule(call_stats_.get()); 221 module_process_thread_->RegisterModule(call_stats_.get());
203 222
204 congestion_controller_->SetBweBitrates( 223 congestion_controller_->SetBweBitrates(
205 config_.bitrate_config.min_bitrate_bps, 224 config_.bitrate_config.min_bitrate_bps,
206 config_.bitrate_config.start_bitrate_bps, 225 config_.bitrate_config.start_bitrate_bps,
207 config_.bitrate_config.max_bitrate_bps); 226 config_.bitrate_config.max_bitrate_bps);
208 227
209 congestion_controller_->GetBitrateController()->SetEventLog(event_log_); 228 congestion_controller_->GetBitrateController()->SetEventLog(event_log_);
210 } 229 }
211 230
212 Call::~Call() { 231 Call::~Call() {
213 RTC_DCHECK(configuration_thread_checker_.CalledOnValidThread()); 232 RTC_DCHECK(configuration_thread_checker_.CalledOnValidThread());
214 UpdateHistograms(); 233 UpdateSendHistograms();
234 UpdateReceiveHistograms();
215 RTC_CHECK(audio_send_ssrcs_.empty()); 235 RTC_CHECK(audio_send_ssrcs_.empty());
216 RTC_CHECK(video_send_ssrcs_.empty()); 236 RTC_CHECK(video_send_ssrcs_.empty());
217 RTC_CHECK(video_send_streams_.empty()); 237 RTC_CHECK(video_send_streams_.empty());
218 RTC_CHECK(audio_receive_ssrcs_.empty()); 238 RTC_CHECK(audio_receive_ssrcs_.empty());
219 RTC_CHECK(video_receive_ssrcs_.empty()); 239 RTC_CHECK(video_receive_ssrcs_.empty());
220 RTC_CHECK(video_receive_streams_.empty()); 240 RTC_CHECK(video_receive_streams_.empty());
221 241
222 module_process_thread_->DeRegisterModule(call_stats_.get()); 242 module_process_thread_->DeRegisterModule(call_stats_.get());
223 module_process_thread_->Stop(); 243 module_process_thread_->Stop();
224 Trace::ReturnTrace(); 244 Trace::ReturnTrace();
225 } 245 }
226 246
227 void Call::UpdateHistograms() { 247 void Call::UpdateSendHistograms() {
248 if (first_packet_sent_ms_ == -1)
249 return;
250 int64_t elapsed_sec =
251 (clock_->TimeInMilliseconds() - first_packet_sent_ms_) / 1000;
252 if (elapsed_sec < metrics::kMinRunTimeInSeconds)
253 return;
254 rtc::CritScope lock(&bitrate_crit_);
255 int send_bitrate_kbps = estimated_send_bitrate_kbps_.ComputeTotalRate();
256 int pacer_bitrate_kbps = pacer_bitrate_kbps_.ComputeTotalRate();
257 if (send_bitrate_kbps > 0) {
258 RTC_HISTOGRAM_COUNTS_100000("WebRTC.Call.EstimatedSendBitrateInKbps",
259 send_bitrate_kbps);
260 }
261 if (pacer_bitrate_kbps > 0) {
262 RTC_HISTOGRAM_COUNTS_100000("WebRTC.Call.PacerBitrateInKbps",
263 pacer_bitrate_kbps);
264 }
265 }
266
267 void Call::UpdateReceiveHistograms() {
228 if (first_rtp_packet_received_ms_ == -1) 268 if (first_rtp_packet_received_ms_ == -1)
229 return; 269 return;
230 int64_t elapsed_sec = 270 int64_t elapsed_sec =
231 (clock_->TimeInMilliseconds() - first_rtp_packet_received_ms_) / 1000; 271 (clock_->TimeInMilliseconds() - first_rtp_packet_received_ms_) / 1000;
232 if (elapsed_sec < metrics::kMinRunTimeInSeconds) 272 if (elapsed_sec < metrics::kMinRunTimeInSeconds)
233 return; 273 return;
234 int audio_bitrate_kbps = 274 int audio_bitrate_kbps =
235 received_audio_bytes_per_sec_.ComputeTotalRate() * 8 / 1000; 275 received_audio_bytes_per_sec_.ComputeTotalRate() * 8 / 1000;
236 int video_bitrate_kbps = 276 int video_bitrate_kbps =
237 received_video_bytes_per_sec_.ComputeTotalRate() * 8 / 1000; 277 received_video_bytes_per_sec_.ComputeTotalRate() * 8 / 1000;
(...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after
522 } 562 }
523 { 563 {
524 ReadLockScoped write_lock(*receive_crit_); 564 ReadLockScoped write_lock(*receive_crit_);
525 for (auto& kv : video_receive_ssrcs_) { 565 for (auto& kv : video_receive_ssrcs_) {
526 kv.second->SignalNetworkState(state); 566 kv.second->SignalNetworkState(state);
527 } 567 }
528 } 568 }
529 } 569 }
530 570
531 void Call::OnSentPacket(const rtc::SentPacket& sent_packet) { 571 void Call::OnSentPacket(const rtc::SentPacket& sent_packet) {
572 if (first_packet_sent_ms_ == -1)
573 first_packet_sent_ms_ = clock_->TimeInMilliseconds();
532 congestion_controller_->OnSentPacket(sent_packet); 574 congestion_controller_->OnSentPacket(sent_packet);
533 } 575 }
534 576
535 void Call::OnNetworkChanged(uint32_t target_bitrate_bps, uint8_t fraction_loss, 577 void Call::OnNetworkChanged(uint32_t target_bitrate_bps, uint8_t fraction_loss,
536 int64_t rtt_ms) { 578 int64_t rtt_ms) {
579 int64_t now_ms = clock_->TimeInMilliseconds();
580 int64_t time_since_last_update_ms = 0;
581 {
582 rtc::CritScope lock(&bitrate_crit_);
583 if (last_bitrate_update_ms_ >= 0)
584 time_since_last_update_ms = now_ms - last_bitrate_update_ms_;
585 estimated_send_bitrate_kbps_.AddSamples(
586 time_since_last_update_ms * (target_bitrate_bps_ / 1000) / 1000);
587 pacer_bitrate_kbps_.AddSamples(time_since_last_update_ms *
588 (pacer_bitrate_bps_ / 1000) / 1000);
589 target_bitrate_bps_ = target_bitrate_bps;
590 last_bitrate_update_ms_ = now_ms;
591 }
537 uint32_t allocated_bitrate_bps = bitrate_allocator_->OnNetworkChanged( 592 uint32_t allocated_bitrate_bps = bitrate_allocator_->OnNetworkChanged(
538 target_bitrate_bps, fraction_loss, rtt_ms); 593 target_bitrate_bps, fraction_loss, rtt_ms);
539 594
540 int pad_up_to_bitrate_bps = 0; 595 int pad_up_to_bitrate_bps = 0;
541 { 596 {
542 ReadLockScoped read_lock(*send_crit_); 597 ReadLockScoped read_lock(*send_crit_);
543 // No need to update as long as we're not sending. 598 // No need to update as long as we're not sending.
544 if (video_send_streams_.empty()) 599 if (video_send_streams_.empty())
545 return; 600 return;
546 601
547 for (VideoSendStream* stream : video_send_streams_) 602 for (VideoSendStream* stream : video_send_streams_)
548 pad_up_to_bitrate_bps += stream->GetPaddingNeededBps(); 603 pad_up_to_bitrate_bps += stream->GetPaddingNeededBps();
549 } 604 }
550 // Allocated bitrate might be higher than bitrate estimate if enforcing min 605 // Allocated bitrate might be higher than bitrate estimate if enforcing min
551 // bitrate, or lower if estimate is higher than the sum of max bitrates, so 606 // bitrate, or lower if estimate is higher than the sum of max bitrates, so
552 // set the pacer bitrate to the maximum of the two. 607 // set the pacer bitrate to the maximum of the two.
553 uint32_t pacer_bitrate_bps = 608 uint32_t pacer_bitrate_bps =
554 std::max(target_bitrate_bps, allocated_bitrate_bps); 609 std::max(target_bitrate_bps, allocated_bitrate_bps);
610 {
611 rtc::CritScope lock(&bitrate_crit_);
612 pacer_bitrate_bps_ = pacer_bitrate_bps;
613 }
555 congestion_controller_->UpdatePacerBitrate( 614 congestion_controller_->UpdatePacerBitrate(
556 target_bitrate_bps / 1000, 615 target_bitrate_bps / 1000,
557 PacedSender::kDefaultPaceMultiplier * pacer_bitrate_bps / 1000, 616 PacedSender::kDefaultPaceMultiplier * pacer_bitrate_bps / 1000,
558 pad_up_to_bitrate_bps / 1000); 617 pad_up_to_bitrate_bps / 1000);
559 } 618 }
560 619
561 void Call::ConfigureSync(const std::string& sync_group) { 620 void Call::ConfigureSync(const std::string& sync_group) {
562 // Set sync only if there was no previous one. 621 // Set sync only if there was no previous one.
563 if (voice_engine() == nullptr || sync_group.empty()) 622 if (voice_engine() == nullptr || sync_group.empty())
564 return; 623 return;
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
688 // thread. Then this check can be enabled. 747 // thread. Then this check can be enabled.
689 // RTC_DCHECK(!configuration_thread_checker_.CalledOnValidThread()); 748 // RTC_DCHECK(!configuration_thread_checker_.CalledOnValidThread());
690 if (RtpHeaderParser::IsRtcp(packet, length)) 749 if (RtpHeaderParser::IsRtcp(packet, length))
691 return DeliverRtcp(media_type, packet, length); 750 return DeliverRtcp(media_type, packet, length);
692 751
693 return DeliverRtp(media_type, packet, length, packet_time); 752 return DeliverRtp(media_type, packet, length, packet_time);
694 } 753 }
695 754
696 } // namespace internal 755 } // namespace internal
697 } // namespace webrtc 756 } // namespace webrtc
OLDNEW
« no previous file with comments | « no previous file | webrtc/video/end_to_end_tests.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698