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 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
79 | 79 |
80 Stats GetStats() const override; | 80 Stats GetStats() const override; |
81 | 81 |
82 DeliveryStatus DeliverPacket(MediaType media_type, | 82 DeliveryStatus DeliverPacket(MediaType media_type, |
83 const uint8_t* packet, | 83 const uint8_t* packet, |
84 size_t length, | 84 size_t length, |
85 const PacketTime& packet_time) override; | 85 const PacketTime& packet_time) override; |
86 | 86 |
87 void SetBitrateConfig( | 87 void SetBitrateConfig( |
88 const webrtc::Call::Config::BitrateConfig& bitrate_config) override; | 88 const webrtc::Call::Config::BitrateConfig& bitrate_config) override; |
89 void SignalNetworkState(NetworkState state) override; | 89 |
90 void SignalChannelNetworkState(MediaType media, | |
91 ChannelNetworkState state) override; | |
90 | 92 |
91 void OnSentPacket(const rtc::SentPacket& sent_packet) override; | 93 void OnSentPacket(const rtc::SentPacket& sent_packet) override; |
92 | 94 |
93 // Implements BitrateObserver. | 95 // Implements BitrateObserver. |
94 void OnNetworkChanged(uint32_t bitrate_bps, uint8_t fraction_loss, | 96 void OnNetworkChanged(uint32_t bitrate_bps, uint8_t fraction_loss, |
95 int64_t rtt_ms) override; | 97 int64_t rtt_ms) override; |
96 | 98 |
97 private: | 99 private: |
98 DeliveryStatus DeliverRtcp(MediaType media_type, const uint8_t* packet, | 100 DeliveryStatus DeliverRtcp(MediaType media_type, const uint8_t* packet, |
99 size_t length); | 101 size_t length); |
(...skipping 20 matching lines...) Expand all Loading... | |
120 Clock* const clock_; | 122 Clock* const clock_; |
121 | 123 |
122 const int num_cpu_cores_; | 124 const int num_cpu_cores_; |
123 const rtc::scoped_ptr<ProcessThread> module_process_thread_; | 125 const rtc::scoped_ptr<ProcessThread> module_process_thread_; |
124 const rtc::scoped_ptr<ProcessThread> pacer_thread_; | 126 const rtc::scoped_ptr<ProcessThread> pacer_thread_; |
125 const rtc::scoped_ptr<CallStats> call_stats_; | 127 const rtc::scoped_ptr<CallStats> call_stats_; |
126 const rtc::scoped_ptr<BitrateAllocator> bitrate_allocator_; | 128 const rtc::scoped_ptr<BitrateAllocator> bitrate_allocator_; |
127 Call::Config config_; | 129 Call::Config config_; |
128 rtc::ThreadChecker configuration_thread_checker_; | 130 rtc::ThreadChecker configuration_thread_checker_; |
129 | 131 |
130 bool network_enabled_; | 132 ChannelNetworkState audio_network_state_; |
133 ChannelNetworkState video_network_state_; | |
131 | 134 |
132 rtc::scoped_ptr<RWLockWrapper> receive_crit_; | 135 rtc::scoped_ptr<RWLockWrapper> receive_crit_; |
133 // Audio and Video receive streams are owned by the client that creates them. | 136 // Audio and Video receive streams are owned by the client that creates them. |
134 std::map<uint32_t, AudioReceiveStream*> audio_receive_ssrcs_ | 137 std::map<uint32_t, AudioReceiveStream*> audio_receive_ssrcs_ |
135 GUARDED_BY(receive_crit_); | 138 GUARDED_BY(receive_crit_); |
136 std::map<uint32_t, VideoReceiveStream*> video_receive_ssrcs_ | 139 std::map<uint32_t, VideoReceiveStream*> video_receive_ssrcs_ |
137 GUARDED_BY(receive_crit_); | 140 GUARDED_BY(receive_crit_); |
138 std::set<VideoReceiveStream*> video_receive_streams_ | 141 std::set<VideoReceiveStream*> video_receive_streams_ |
139 GUARDED_BY(receive_crit_); | 142 GUARDED_BY(receive_crit_); |
140 std::map<std::string, AudioReceiveStream*> sync_stream_mapping_ | 143 std::map<std::string, AudioReceiveStream*> sync_stream_mapping_ |
(...skipping 30 matching lines...) Expand all Loading... | |
171 const rtc::scoped_ptr<CongestionController> congestion_controller_; | 174 const rtc::scoped_ptr<CongestionController> congestion_controller_; |
172 | 175 |
173 RTC_DISALLOW_COPY_AND_ASSIGN(Call); | 176 RTC_DISALLOW_COPY_AND_ASSIGN(Call); |
174 }; | 177 }; |
175 } // namespace internal | 178 } // namespace internal |
176 | 179 |
177 Call* Call::Create(const Call::Config& config) { | 180 Call* Call::Create(const Call::Config& config) { |
178 return new internal::Call(config); | 181 return new internal::Call(config); |
179 } | 182 } |
180 | 183 |
184 NetworkState ChannelStateToNetworkState(ChannelNetworkState channelState) { | |
185 return (channelState == ChannelNetworkState::CHANNEL_NETWORK_DOWN ? | |
186 kNetworkDown : kNetworkUp); | |
187 } | |
188 | |
189 NetworkState AggregateNetworkState(ChannelNetworkState channelA, | |
190 ChannelNetworkState channelB) { | |
191 NetworkState aggregateState = kNetworkDown; | |
192 if (channelA == ChannelNetworkState::CHANNEL_NOT_PRESENT && | |
193 channelB == ChannelNetworkState::CHANNEL_NOT_PRESENT) { | |
194 // When no channels are configured - such as in tests - | |
195 // the network is assumed to be up | |
196 aggregateState = kNetworkUp; | |
197 } else if (channelA == ChannelNetworkState::CHANNEL_NETWORK_UP || | |
198 channelB == ChannelNetworkState::CHANNEL_NETWORK_UP) { | |
199 // There is at least one channel that reports the network to be up | |
200 aggregateState = kNetworkUp; | |
201 } else { | |
202 // All the channels report that the network is down | |
203 aggregateState = kNetworkDown; | |
204 } | |
205 return aggregateState; | |
206 } | |
207 | |
181 namespace internal { | 208 namespace internal { |
182 | 209 |
183 Call::Call(const Call::Config& config) | 210 Call::Call(const Call::Config& config) |
184 : clock_(Clock::GetRealTimeClock()), | 211 : clock_(Clock::GetRealTimeClock()), |
185 num_cpu_cores_(CpuInfo::DetectNumberOfCores()), | 212 num_cpu_cores_(CpuInfo::DetectNumberOfCores()), |
186 module_process_thread_(ProcessThread::Create("ModuleProcessThread")), | 213 module_process_thread_(ProcessThread::Create("ModuleProcessThread")), |
187 pacer_thread_(ProcessThread::Create("PacerThread")), | 214 pacer_thread_(ProcessThread::Create("PacerThread")), |
188 call_stats_(new CallStats(clock_)), | 215 call_stats_(new CallStats(clock_)), |
189 bitrate_allocator_(new BitrateAllocator()), | 216 bitrate_allocator_(new BitrateAllocator()), |
190 config_(config), | 217 config_(config), |
191 network_enabled_(true), | 218 audio_network_state_(ChannelNetworkState::CHANNEL_NOT_PRESENT), |
219 video_network_state_(ChannelNetworkState::CHANNEL_NOT_PRESENT), | |
192 receive_crit_(RWLockWrapper::CreateRWLock()), | 220 receive_crit_(RWLockWrapper::CreateRWLock()), |
193 send_crit_(RWLockWrapper::CreateRWLock()), | 221 send_crit_(RWLockWrapper::CreateRWLock()), |
194 received_video_bytes_(0), | 222 received_video_bytes_(0), |
195 received_audio_bytes_(0), | 223 received_audio_bytes_(0), |
196 received_rtcp_bytes_(0), | 224 received_rtcp_bytes_(0), |
197 first_rtp_packet_received_ms_(-1), | 225 first_rtp_packet_received_ms_(-1), |
198 last_rtp_packet_received_ms_(-1), | 226 last_rtp_packet_received_ms_(-1), |
199 first_packet_sent_ms_(-1), | 227 first_packet_sent_ms_(-1), |
200 estimated_send_bitrate_sum_kbits_(0), | 228 estimated_send_bitrate_sum_kbits_(0), |
201 pacer_bitrate_sum_kbits_(0), | 229 pacer_bitrate_sum_kbits_(0), |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
309 // RTC_DCHECK(configuration_thread_checker_.CalledOnValidThread()); | 337 // RTC_DCHECK(configuration_thread_checker_.CalledOnValidThread()); |
310 return this; | 338 return this; |
311 } | 339 } |
312 | 340 |
313 webrtc::AudioSendStream* Call::CreateAudioSendStream( | 341 webrtc::AudioSendStream* Call::CreateAudioSendStream( |
314 const webrtc::AudioSendStream::Config& config) { | 342 const webrtc::AudioSendStream::Config& config) { |
315 TRACE_EVENT0("webrtc", "Call::CreateAudioSendStream"); | 343 TRACE_EVENT0("webrtc", "Call::CreateAudioSendStream"); |
316 RTC_DCHECK(configuration_thread_checker_.CalledOnValidThread()); | 344 RTC_DCHECK(configuration_thread_checker_.CalledOnValidThread()); |
317 AudioSendStream* send_stream = new AudioSendStream( | 345 AudioSendStream* send_stream = new AudioSendStream( |
318 config, config_.audio_state, congestion_controller_.get()); | 346 config, config_.audio_state, congestion_controller_.get()); |
319 if (!network_enabled_) | 347 |
320 send_stream->SignalNetworkState(kNetworkDown); | 348 send_stream->SignalNetworkState( |
349 ChannelStateToNetworkState(audio_network_state_)); | |
321 { | 350 { |
322 WriteLockScoped write_lock(*send_crit_); | 351 WriteLockScoped write_lock(*send_crit_); |
323 RTC_DCHECK(audio_send_ssrcs_.find(config.rtp.ssrc) == | 352 RTC_DCHECK(audio_send_ssrcs_.find(config.rtp.ssrc) == |
324 audio_send_ssrcs_.end()); | 353 audio_send_ssrcs_.end()); |
325 audio_send_ssrcs_[config.rtp.ssrc] = send_stream; | 354 audio_send_ssrcs_[config.rtp.ssrc] = send_stream; |
326 } | 355 } |
327 return send_stream; | 356 return send_stream; |
328 } | 357 } |
329 | 358 |
330 void Call::DestroyAudioSendStream(webrtc::AudioSendStream* send_stream) { | 359 void Call::DestroyAudioSendStream(webrtc::AudioSendStream* send_stream) { |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
390 TRACE_EVENT0("webrtc", "Call::CreateVideoSendStream"); | 419 TRACE_EVENT0("webrtc", "Call::CreateVideoSendStream"); |
391 RTC_DCHECK(configuration_thread_checker_.CalledOnValidThread()); | 420 RTC_DCHECK(configuration_thread_checker_.CalledOnValidThread()); |
392 | 421 |
393 // TODO(mflodman): Base the start bitrate on a current bandwidth estimate, if | 422 // TODO(mflodman): Base the start bitrate on a current bandwidth estimate, if |
394 // the call has already started. | 423 // the call has already started. |
395 VideoSendStream* send_stream = new VideoSendStream( | 424 VideoSendStream* send_stream = new VideoSendStream( |
396 num_cpu_cores_, module_process_thread_.get(), call_stats_.get(), | 425 num_cpu_cores_, module_process_thread_.get(), call_stats_.get(), |
397 congestion_controller_.get(), &remb_, bitrate_allocator_.get(), config, | 426 congestion_controller_.get(), &remb_, bitrate_allocator_.get(), config, |
398 encoder_config, suspended_video_send_ssrcs_); | 427 encoder_config, suspended_video_send_ssrcs_); |
399 | 428 |
400 if (!network_enabled_) | 429 send_stream->SignalNetworkState( |
401 send_stream->SignalNetworkState(kNetworkDown); | 430 ChannelStateToNetworkState(video_network_state_)); |
402 | 431 |
403 WriteLockScoped write_lock(*send_crit_); | 432 WriteLockScoped write_lock(*send_crit_); |
404 for (uint32_t ssrc : config.rtp.ssrcs) { | 433 for (uint32_t ssrc : config.rtp.ssrcs) { |
405 RTC_DCHECK(video_send_ssrcs_.find(ssrc) == video_send_ssrcs_.end()); | 434 RTC_DCHECK(video_send_ssrcs_.find(ssrc) == video_send_ssrcs_.end()); |
406 video_send_ssrcs_[ssrc] = send_stream; | 435 video_send_ssrcs_[ssrc] = send_stream; |
407 } | 436 } |
408 video_send_streams_.insert(send_stream); | 437 video_send_streams_.insert(send_stream); |
409 | 438 |
410 if (event_log_) | 439 if (event_log_) |
411 event_log_->LogVideoSendStreamConfig(config); | 440 event_log_->LogVideoSendStreamConfig(config); |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
461 video_receive_ssrcs_[config.rtp.remote_ssrc] = receive_stream; | 490 video_receive_ssrcs_[config.rtp.remote_ssrc] = receive_stream; |
462 // TODO(pbos): Configure different RTX payloads per receive payload. | 491 // TODO(pbos): Configure different RTX payloads per receive payload. |
463 VideoReceiveStream::Config::Rtp::RtxMap::const_iterator it = | 492 VideoReceiveStream::Config::Rtp::RtxMap::const_iterator it = |
464 config.rtp.rtx.begin(); | 493 config.rtp.rtx.begin(); |
465 if (it != config.rtp.rtx.end()) | 494 if (it != config.rtp.rtx.end()) |
466 video_receive_ssrcs_[it->second.ssrc] = receive_stream; | 495 video_receive_ssrcs_[it->second.ssrc] = receive_stream; |
467 video_receive_streams_.insert(receive_stream); | 496 video_receive_streams_.insert(receive_stream); |
468 | 497 |
469 ConfigureSync(config.sync_group); | 498 ConfigureSync(config.sync_group); |
470 | 499 |
471 if (!network_enabled_) | 500 receive_stream->SignalNetworkState( |
the sun
2016/03/04 12:40:48
For the send streams, the network state is signale
| |
472 receive_stream->SignalNetworkState(kNetworkDown); | 501 ChannelStateToNetworkState(video_network_state_)); |
473 | 502 |
474 if (event_log_) | 503 if (event_log_) |
475 event_log_->LogVideoReceiveStreamConfig(config); | 504 event_log_->LogVideoReceiveStreamConfig(config); |
476 | 505 |
477 return receive_stream; | 506 return receive_stream; |
478 } | 507 } |
479 | 508 |
480 void Call::DestroyVideoReceiveStream( | 509 void Call::DestroyVideoReceiveStream( |
481 webrtc::VideoReceiveStream* receive_stream) { | 510 webrtc::VideoReceiveStream* receive_stream) { |
482 TRACE_EVENT0("webrtc", "Call::DestroyVideoReceiveStream"); | 511 TRACE_EVENT0("webrtc", "Call::DestroyVideoReceiveStream"); |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
541 bitrate_config.max_bitrate_bps) { | 570 bitrate_config.max_bitrate_bps) { |
542 // Nothing new to set, early abort to avoid encoder reconfigurations. | 571 // Nothing new to set, early abort to avoid encoder reconfigurations. |
543 return; | 572 return; |
544 } | 573 } |
545 config_.bitrate_config = bitrate_config; | 574 config_.bitrate_config = bitrate_config; |
546 congestion_controller_->SetBweBitrates(bitrate_config.min_bitrate_bps, | 575 congestion_controller_->SetBweBitrates(bitrate_config.min_bitrate_bps, |
547 bitrate_config.start_bitrate_bps, | 576 bitrate_config.start_bitrate_bps, |
548 bitrate_config.max_bitrate_bps); | 577 bitrate_config.max_bitrate_bps); |
549 } | 578 } |
550 | 579 |
551 void Call::SignalNetworkState(NetworkState state) { | 580 void Call::SignalChannelNetworkState(MediaType media, |
581 ChannelNetworkState state) { | |
552 RTC_DCHECK(configuration_thread_checker_.CalledOnValidThread()); | 582 RTC_DCHECK(configuration_thread_checker_.CalledOnValidThread()); |
553 network_enabled_ = state == kNetworkUp; | 583 if (media == MediaType::AUDIO) |
554 congestion_controller_->SignalNetworkState(state); | 584 audio_network_state_ = state; |
585 if (media == MediaType::VIDEO) | |
586 video_network_state_ = state; | |
587 | |
588 NetworkState aggregateState = AggregateNetworkState(audio_network_state_, | |
589 video_network_state_); | |
590 LOG(LS_INFO) << "SignalChannelNetworkState: aggregateState=" << | |
591 (aggregateState == kNetworkUp ? "up" : "down"); | |
592 congestion_controller_->SignalNetworkState(aggregateState); | |
555 { | 593 { |
556 ReadLockScoped write_lock(*send_crit_); | 594 ReadLockScoped write_lock(*send_crit_); |
557 for (auto& kv : audio_send_ssrcs_) { | 595 for (auto& kv : audio_send_ssrcs_) { |
558 kv.second->SignalNetworkState(state); | 596 kv.second->SignalNetworkState( |
597 ChannelStateToNetworkState(audio_network_state_)); | |
559 } | 598 } |
560 for (auto& kv : video_send_ssrcs_) { | 599 for (auto& kv : video_send_ssrcs_) { |
561 kv.second->SignalNetworkState(state); | 600 kv.second->SignalNetworkState( |
601 ChannelStateToNetworkState(video_network_state_)); | |
562 } | 602 } |
563 } | 603 } |
564 { | 604 { |
565 ReadLockScoped write_lock(*receive_crit_); | 605 ReadLockScoped write_lock(*receive_crit_); |
566 for (auto& kv : video_receive_ssrcs_) { | 606 for (auto& kv : video_receive_ssrcs_) { |
567 kv.second->SignalNetworkState(state); | 607 kv.second->SignalNetworkState( |
608 ChannelStateToNetworkState(video_network_state_)); | |
568 } | 609 } |
569 } | 610 } |
570 } | 611 } |
571 | 612 |
572 void Call::OnSentPacket(const rtc::SentPacket& sent_packet) { | 613 void Call::OnSentPacket(const rtc::SentPacket& sent_packet) { |
573 if (first_packet_sent_ms_ == -1) | 614 if (first_packet_sent_ms_ == -1) |
574 first_packet_sent_ms_ = clock_->TimeInMilliseconds(); | 615 first_packet_sent_ms_ = clock_->TimeInMilliseconds(); |
575 congestion_controller_->OnSentPacket(sent_packet); | 616 congestion_controller_->OnSentPacket(sent_packet); |
576 } | 617 } |
577 | 618 |
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
744 // thread. Then this check can be enabled. | 785 // thread. Then this check can be enabled. |
745 // RTC_DCHECK(!configuration_thread_checker_.CalledOnValidThread()); | 786 // RTC_DCHECK(!configuration_thread_checker_.CalledOnValidThread()); |
746 if (RtpHeaderParser::IsRtcp(packet, length)) | 787 if (RtpHeaderParser::IsRtcp(packet, length)) |
747 return DeliverRtcp(media_type, packet, length); | 788 return DeliverRtcp(media_type, packet, length); |
748 | 789 |
749 return DeliverRtp(media_type, packet, length, packet_time); | 790 return DeliverRtp(media_type, packet, length, packet_time); |
750 } | 791 } |
751 | 792 |
752 } // namespace internal | 793 } // namespace internal |
753 } // namespace webrtc | 794 } // namespace webrtc |
OLD | NEW |