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 |
11 #include <string.h> | 11 #include <string.h> |
12 | |
13 #include <algorithm> | 12 #include <algorithm> |
14 #include <map> | 13 #include <map> |
15 #include <memory> | 14 #include <memory> |
16 #include <vector> | 15 #include <vector> |
17 | 16 |
18 #include "webrtc/audio/audio_receive_stream.h" | 17 #include "webrtc/audio/audio_receive_stream.h" |
19 #include "webrtc/audio/audio_send_stream.h" | 18 #include "webrtc/audio/audio_send_stream.h" |
20 #include "webrtc/audio/audio_state.h" | 19 #include "webrtc/audio/audio_state.h" |
21 #include "webrtc/audio/scoped_voe_interface.h" | 20 #include "webrtc/audio/scoped_voe_interface.h" |
22 #include "webrtc/base/checks.h" | 21 #include "webrtc/base/checks.h" |
23 #include "webrtc/base/constructormagic.h" | 22 #include "webrtc/base/constructormagic.h" |
24 #include "webrtc/base/logging.h" | 23 #include "webrtc/base/logging.h" |
24 #include "webrtc/base/task_queue.h" | |
25 #include "webrtc/base/thread_annotations.h" | 25 #include "webrtc/base/thread_annotations.h" |
26 #include "webrtc/base/thread_checker.h" | 26 #include "webrtc/base/thread_checker.h" |
27 #include "webrtc/base/trace_event.h" | 27 #include "webrtc/base/trace_event.h" |
28 #include "webrtc/call.h" | 28 #include "webrtc/call.h" |
29 #include "webrtc/call/bitrate_allocator.h" | 29 #include "webrtc/call/bitrate_allocator.h" |
30 #include "webrtc/call/rtc_event_log.h" | 30 #include "webrtc/call/rtc_event_log.h" |
31 #include "webrtc/config.h" | 31 #include "webrtc/config.h" |
32 #include "webrtc/modules/bitrate_controller/include/bitrate_controller.h" | 32 #include "webrtc/modules/bitrate_controller/include/bitrate_controller.h" |
33 #include "webrtc/modules/congestion_controller/include/congestion_controller.h" | 33 #include "webrtc/modules/congestion_controller/include/congestion_controller.h" |
34 #include "webrtc/modules/pacing/paced_sender.h" | 34 #include "webrtc/modules/pacing/paced_sender.h" |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
126 return nullptr; | 126 return nullptr; |
127 } | 127 } |
128 | 128 |
129 void UpdateSendHistograms() EXCLUSIVE_LOCKS_REQUIRED(&bitrate_crit_); | 129 void UpdateSendHistograms() EXCLUSIVE_LOCKS_REQUIRED(&bitrate_crit_); |
130 void UpdateReceiveHistograms(); | 130 void UpdateReceiveHistograms(); |
131 void UpdateAggregateNetworkState(); | 131 void UpdateAggregateNetworkState(); |
132 | 132 |
133 Clock* const clock_; | 133 Clock* const clock_; |
134 | 134 |
135 const int num_cpu_cores_; | 135 const int num_cpu_cores_; |
136 // TODO(perkj): |worker_queu_| is supposed to replace |module_process_thread_| | |
137 // in the long run. | |
138 rtc::TaskQueue worker_queu_; | |
tommi
2016/06/17 07:59:01
worker_queue_
perkj_webrtc
2016/06/27 14:34:34
Done.
| |
136 const std::unique_ptr<ProcessThread> module_process_thread_; | 139 const std::unique_ptr<ProcessThread> module_process_thread_; |
137 const std::unique_ptr<ProcessThread> pacer_thread_; | 140 const std::unique_ptr<ProcessThread> pacer_thread_; |
138 const std::unique_ptr<CallStats> call_stats_; | 141 const std::unique_ptr<CallStats> call_stats_; |
139 const std::unique_ptr<BitrateAllocator> bitrate_allocator_; | 142 const std::unique_ptr<BitrateAllocator> bitrate_allocator_; |
140 Call::Config config_; | 143 Call::Config config_; |
141 rtc::ThreadChecker configuration_thread_checker_; | 144 rtc::ThreadChecker configuration_thread_checker_; |
142 | 145 |
143 NetworkState audio_network_state_; | 146 NetworkState audio_network_state_; |
144 NetworkState video_network_state_; | 147 NetworkState video_network_state_; |
145 | 148 |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
194 | 197 |
195 Call* Call::Create(const Call::Config& config) { | 198 Call* Call::Create(const Call::Config& config) { |
196 return new internal::Call(config); | 199 return new internal::Call(config); |
197 } | 200 } |
198 | 201 |
199 namespace internal { | 202 namespace internal { |
200 | 203 |
201 Call::Call(const Call::Config& config) | 204 Call::Call(const Call::Config& config) |
202 : clock_(Clock::GetRealTimeClock()), | 205 : clock_(Clock::GetRealTimeClock()), |
203 num_cpu_cores_(CpuInfo::DetectNumberOfCores()), | 206 num_cpu_cores_(CpuInfo::DetectNumberOfCores()), |
207 worker_queu_("worker_queue"), | |
204 module_process_thread_(ProcessThread::Create("ModuleProcessThread")), | 208 module_process_thread_(ProcessThread::Create("ModuleProcessThread")), |
205 pacer_thread_(ProcessThread::Create("PacerThread")), | 209 pacer_thread_(ProcessThread::Create("PacerThread")), |
206 call_stats_(new CallStats(clock_)), | 210 call_stats_(new CallStats(clock_)), |
207 bitrate_allocator_(new BitrateAllocator(this)), | 211 bitrate_allocator_(new BitrateAllocator(this)), |
208 config_(config), | 212 config_(config), |
209 audio_network_state_(kNetworkUp), | 213 audio_network_state_(kNetworkUp), |
210 video_network_state_(kNetworkUp), | 214 video_network_state_(kNetworkUp), |
211 receive_crit_(RWLockWrapper::CreateRWLock()), | 215 receive_crit_(RWLockWrapper::CreateRWLock()), |
212 send_crit_(RWLockWrapper::CreateRWLock()), | 216 send_crit_(RWLockWrapper::CreateRWLock()), |
213 received_video_bytes_(0), | 217 received_video_bytes_(0), |
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
412 webrtc::VideoSendStream* Call::CreateVideoSendStream( | 416 webrtc::VideoSendStream* Call::CreateVideoSendStream( |
413 const webrtc::VideoSendStream::Config& config, | 417 const webrtc::VideoSendStream::Config& config, |
414 const VideoEncoderConfig& encoder_config) { | 418 const VideoEncoderConfig& encoder_config) { |
415 TRACE_EVENT0("webrtc", "Call::CreateVideoSendStream"); | 419 TRACE_EVENT0("webrtc", "Call::CreateVideoSendStream"); |
416 RTC_DCHECK(configuration_thread_checker_.CalledOnValidThread()); | 420 RTC_DCHECK(configuration_thread_checker_.CalledOnValidThread()); |
417 | 421 |
418 video_send_delay_stats_->AddSsrcs(config); | 422 video_send_delay_stats_->AddSsrcs(config); |
419 // TODO(mflodman): Base the start bitrate on a current bandwidth estimate, if | 423 // TODO(mflodman): Base the start bitrate on a current bandwidth estimate, if |
420 // the call has already started. | 424 // the call has already started. |
421 VideoSendStream* send_stream = new VideoSendStream( | 425 VideoSendStream* send_stream = new VideoSendStream( |
422 num_cpu_cores_, module_process_thread_.get(), call_stats_.get(), | 426 num_cpu_cores_, module_process_thread_.get(), &worker_queu_, |
423 congestion_controller_.get(), bitrate_allocator_.get(), | 427 call_stats_.get(), congestion_controller_.get(), bitrate_allocator_.get(), |
424 video_send_delay_stats_.get(), &remb_, event_log_, config, encoder_config, | 428 video_send_delay_stats_.get(), &remb_, event_log_, config, encoder_config, |
425 suspended_video_send_ssrcs_); | 429 suspended_video_send_ssrcs_); |
426 { | 430 { |
427 WriteLockScoped write_lock(*send_crit_); | 431 WriteLockScoped write_lock(*send_crit_); |
428 for (uint32_t ssrc : config.rtp.ssrcs) { | 432 for (uint32_t ssrc : config.rtp.ssrcs) { |
429 RTC_DCHECK(video_send_ssrcs_.find(ssrc) == video_send_ssrcs_.end()); | 433 RTC_DCHECK(video_send_ssrcs_.find(ssrc) == video_send_ssrcs_.end()); |
430 video_send_ssrcs_[ssrc] = send_stream; | 434 video_send_ssrcs_[ssrc] = send_stream; |
431 } | 435 } |
432 video_send_streams_.insert(send_stream); | 436 video_send_streams_.insert(send_stream); |
433 } | 437 } |
(...skipping 20 matching lines...) Expand all Loading... | |
454 send_stream_impl = it->second; | 458 send_stream_impl = it->second; |
455 video_send_ssrcs_.erase(it++); | 459 video_send_ssrcs_.erase(it++); |
456 } else { | 460 } else { |
457 ++it; | 461 ++it; |
458 } | 462 } |
459 } | 463 } |
460 video_send_streams_.erase(send_stream_impl); | 464 video_send_streams_.erase(send_stream_impl); |
461 } | 465 } |
462 RTC_CHECK(send_stream_impl != nullptr); | 466 RTC_CHECK(send_stream_impl != nullptr); |
463 | 467 |
464 VideoSendStream::RtpStateMap rtp_state = send_stream_impl->GetRtpStates(); | 468 VideoSendStream::RtpStateMap rtp_state = |
469 send_stream_impl->StopPermanentlyAndGetRtpStates(); | |
465 | 470 |
466 for (VideoSendStream::RtpStateMap::iterator it = rtp_state.begin(); | 471 for (VideoSendStream::RtpStateMap::iterator it = rtp_state.begin(); |
467 it != rtp_state.end(); | 472 it != rtp_state.end(); ++it) { |
468 ++it) { | |
469 suspended_video_send_ssrcs_[it->first] = it->second; | 473 suspended_video_send_ssrcs_[it->first] = it->second; |
470 } | 474 } |
471 | 475 |
472 UpdateAggregateNetworkState(); | 476 UpdateAggregateNetworkState(); |
473 delete send_stream_impl; | 477 delete send_stream_impl; |
474 } | 478 } |
475 | 479 |
476 webrtc::VideoReceiveStream* Call::CreateVideoReceiveStream( | 480 webrtc::VideoReceiveStream* Call::CreateVideoReceiveStream( |
477 webrtc::VideoReceiveStream::Config configuration) { | 481 webrtc::VideoReceiveStream::Config configuration) { |
478 TRACE_EVENT0("webrtc", "Call::CreateVideoReceiveStream"); | 482 TRACE_EVENT0("webrtc", "Call::CreateVideoReceiveStream"); |
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
677 void Call::OnSentPacket(const rtc::SentPacket& sent_packet) { | 681 void Call::OnSentPacket(const rtc::SentPacket& sent_packet) { |
678 if (first_packet_sent_ms_ == -1) | 682 if (first_packet_sent_ms_ == -1) |
679 first_packet_sent_ms_ = clock_->TimeInMilliseconds(); | 683 first_packet_sent_ms_ = clock_->TimeInMilliseconds(); |
680 video_send_delay_stats_->OnSentPacket(sent_packet.packet_id, | 684 video_send_delay_stats_->OnSentPacket(sent_packet.packet_id, |
681 clock_->TimeInMilliseconds()); | 685 clock_->TimeInMilliseconds()); |
682 congestion_controller_->OnSentPacket(sent_packet); | 686 congestion_controller_->OnSentPacket(sent_packet); |
683 } | 687 } |
684 | 688 |
685 void Call::OnNetworkChanged(uint32_t target_bitrate_bps, uint8_t fraction_loss, | 689 void Call::OnNetworkChanged(uint32_t target_bitrate_bps, uint8_t fraction_loss, |
686 int64_t rtt_ms) { | 690 int64_t rtt_ms) { |
691 // TODO(perkj): Consider making sure CongestionController operates on | |
692 // |worker_queu_|. | |
693 if (!worker_queu_.IsCurrent()) { | |
694 worker_queu_.PostTask([this, target_bitrate_bps, fraction_loss, rtt_ms] { | |
695 OnNetworkChanged(target_bitrate_bps, fraction_loss, rtt_ms); | |
696 }); | |
697 return; | |
698 } | |
699 RTC_DCHECK_RUN_ON(&worker_queu_); | |
687 bitrate_allocator_->OnNetworkChanged(target_bitrate_bps, fraction_loss, | 700 bitrate_allocator_->OnNetworkChanged(target_bitrate_bps, fraction_loss, |
688 rtt_ms); | 701 rtt_ms); |
689 | 702 |
690 { | 703 { |
691 rtc::CritScope lock(&bitrate_crit_); | 704 rtc::CritScope lock(&bitrate_crit_); |
692 // We only update these stats if we have send streams, and assume that | 705 // We only update these stats if we have send streams, and assume that |
693 // OnNetworkChanged is called roughly with a fixed frequency. | 706 // OnNetworkChanged is called roughly with a fixed frequency. |
694 estimated_send_bitrate_sum_kbits_ += target_bitrate_bps / 1000; | 707 estimated_send_bitrate_sum_kbits_ += target_bitrate_bps / 1000; |
695 // Pacer bitrate might be higher than bitrate estimate if enforcing min | 708 // Pacer bitrate might be higher than bitrate estimate if enforcing min |
696 // bitrate. | 709 // bitrate. |
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
853 // thread. Then this check can be enabled. | 866 // thread. Then this check can be enabled. |
854 // RTC_DCHECK(!configuration_thread_checker_.CalledOnValidThread()); | 867 // RTC_DCHECK(!configuration_thread_checker_.CalledOnValidThread()); |
855 if (RtpHeaderParser::IsRtcp(packet, length)) | 868 if (RtpHeaderParser::IsRtcp(packet, length)) |
856 return DeliverRtcp(media_type, packet, length); | 869 return DeliverRtcp(media_type, packet, length); |
857 | 870 |
858 return DeliverRtp(media_type, packet, length, packet_time); | 871 return DeliverRtp(media_type, packet, length, packet_time); |
859 } | 872 } |
860 | 873 |
861 } // namespace internal | 874 } // namespace internal |
862 } // namespace webrtc | 875 } // namespace webrtc |
OLD | NEW |