Chromium Code Reviews| 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, NetworkState state) override; | |
| 90 | 91 |
| 91 void OnSentPacket(const rtc::SentPacket& sent_packet) override; | 92 void OnSentPacket(const rtc::SentPacket& sent_packet) override; |
| 92 | 93 |
| 93 // Implements BitrateObserver. | 94 // Implements BitrateObserver. |
| 94 void OnNetworkChanged(uint32_t bitrate_bps, uint8_t fraction_loss, | 95 void OnNetworkChanged(uint32_t bitrate_bps, uint8_t fraction_loss, |
| 95 int64_t rtt_ms) override; | 96 int64_t rtt_ms) override; |
| 96 | 97 |
| 97 private: | 98 private: |
| 98 DeliveryStatus DeliverRtcp(MediaType media_type, const uint8_t* packet, | 99 DeliveryStatus DeliverRtcp(MediaType media_type, const uint8_t* packet, |
| 99 size_t length); | 100 size_t length); |
| 100 DeliveryStatus DeliverRtp(MediaType media_type, | 101 DeliveryStatus DeliverRtp(MediaType media_type, |
| 101 const uint8_t* packet, | 102 const uint8_t* packet, |
| 102 size_t length, | 103 size_t length, |
| 103 const PacketTime& packet_time); | 104 const PacketTime& packet_time); |
| 104 | 105 |
| 105 void ConfigureSync(const std::string& sync_group) | 106 void ConfigureSync(const std::string& sync_group) |
| 106 EXCLUSIVE_LOCKS_REQUIRED(receive_crit_); | 107 EXCLUSIVE_LOCKS_REQUIRED(receive_crit_); |
| 107 | 108 |
| 108 VoiceEngine* voice_engine() { | 109 VoiceEngine* voice_engine() { |
| 109 internal::AudioState* audio_state = | 110 internal::AudioState* audio_state = |
| 110 static_cast<internal::AudioState*>(config_.audio_state.get()); | 111 static_cast<internal::AudioState*>(config_.audio_state.get()); |
| 111 if (audio_state) | 112 if (audio_state) |
| 112 return audio_state->voice_engine(); | 113 return audio_state->voice_engine(); |
| 113 else | 114 else |
| 114 return nullptr; | 115 return nullptr; |
| 115 } | 116 } |
| 116 | 117 |
| 117 void UpdateSendHistograms() EXCLUSIVE_LOCKS_REQUIRED(&bitrate_crit_); | 118 void UpdateSendHistograms() EXCLUSIVE_LOCKS_REQUIRED(&bitrate_crit_); |
| 118 void UpdateReceiveHistograms(); | 119 void UpdateReceiveHistograms(); |
| 120 void UpdateAggregateNetworkState(); | |
| 119 | 121 |
| 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 NetworkState audio_network_state_; |
| 133 NetworkState 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 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 181 namespace internal { | 184 namespace internal { |
| 182 | 185 |
| 183 Call::Call(const Call::Config& config) | 186 Call::Call(const Call::Config& config) |
| 184 : clock_(Clock::GetRealTimeClock()), | 187 : clock_(Clock::GetRealTimeClock()), |
| 185 num_cpu_cores_(CpuInfo::DetectNumberOfCores()), | 188 num_cpu_cores_(CpuInfo::DetectNumberOfCores()), |
| 186 module_process_thread_(ProcessThread::Create("ModuleProcessThread")), | 189 module_process_thread_(ProcessThread::Create("ModuleProcessThread")), |
| 187 pacer_thread_(ProcessThread::Create("PacerThread")), | 190 pacer_thread_(ProcessThread::Create("PacerThread")), |
| 188 call_stats_(new CallStats(clock_)), | 191 call_stats_(new CallStats(clock_)), |
| 189 bitrate_allocator_(new BitrateAllocator()), | 192 bitrate_allocator_(new BitrateAllocator()), |
| 190 config_(config), | 193 config_(config), |
| 191 network_enabled_(true), | 194 audio_network_state_(kNetworkUp), |
| 195 video_network_state_(kNetworkUp), | |
| 192 receive_crit_(RWLockWrapper::CreateRWLock()), | 196 receive_crit_(RWLockWrapper::CreateRWLock()), |
| 193 send_crit_(RWLockWrapper::CreateRWLock()), | 197 send_crit_(RWLockWrapper::CreateRWLock()), |
| 194 received_video_bytes_(0), | 198 received_video_bytes_(0), |
| 195 received_audio_bytes_(0), | 199 received_audio_bytes_(0), |
| 196 received_rtcp_bytes_(0), | 200 received_rtcp_bytes_(0), |
| 197 first_rtp_packet_received_ms_(-1), | 201 first_rtp_packet_received_ms_(-1), |
| 198 last_rtp_packet_received_ms_(-1), | 202 last_rtp_packet_received_ms_(-1), |
| 199 first_packet_sent_ms_(-1), | 203 first_packet_sent_ms_(-1), |
| 200 estimated_send_bitrate_sum_kbits_(0), | 204 estimated_send_bitrate_sum_kbits_(0), |
| 201 pacer_bitrate_sum_kbits_(0), | 205 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()); | 313 // RTC_DCHECK(configuration_thread_checker_.CalledOnValidThread()); |
| 310 return this; | 314 return this; |
| 311 } | 315 } |
| 312 | 316 |
| 313 webrtc::AudioSendStream* Call::CreateAudioSendStream( | 317 webrtc::AudioSendStream* Call::CreateAudioSendStream( |
| 314 const webrtc::AudioSendStream::Config& config) { | 318 const webrtc::AudioSendStream::Config& config) { |
| 315 TRACE_EVENT0("webrtc", "Call::CreateAudioSendStream"); | 319 TRACE_EVENT0("webrtc", "Call::CreateAudioSendStream"); |
| 316 RTC_DCHECK(configuration_thread_checker_.CalledOnValidThread()); | 320 RTC_DCHECK(configuration_thread_checker_.CalledOnValidThread()); |
| 317 AudioSendStream* send_stream = new AudioSendStream( | 321 AudioSendStream* send_stream = new AudioSendStream( |
| 318 config, config_.audio_state, congestion_controller_.get()); | 322 config, config_.audio_state, congestion_controller_.get()); |
| 319 if (!network_enabled_) | |
| 320 send_stream->SignalNetworkState(kNetworkDown); | |
| 321 { | 323 { |
| 322 WriteLockScoped write_lock(*send_crit_); | 324 WriteLockScoped write_lock(*send_crit_); |
| 323 RTC_DCHECK(audio_send_ssrcs_.find(config.rtp.ssrc) == | 325 RTC_DCHECK(audio_send_ssrcs_.find(config.rtp.ssrc) == |
| 324 audio_send_ssrcs_.end()); | 326 audio_send_ssrcs_.end()); |
| 325 audio_send_ssrcs_[config.rtp.ssrc] = send_stream; | 327 audio_send_ssrcs_[config.rtp.ssrc] = send_stream; |
| 326 } | 328 } |
| 329 send_stream->SignalNetworkState(audio_network_state_); | |
| 330 UpdateAggregateNetworkState(); | |
| 327 return send_stream; | 331 return send_stream; |
| 328 } | 332 } |
| 329 | 333 |
| 330 void Call::DestroyAudioSendStream(webrtc::AudioSendStream* send_stream) { | 334 void Call::DestroyAudioSendStream(webrtc::AudioSendStream* send_stream) { |
| 331 TRACE_EVENT0("webrtc", "Call::DestroyAudioSendStream"); | 335 TRACE_EVENT0("webrtc", "Call::DestroyAudioSendStream"); |
| 332 RTC_DCHECK(configuration_thread_checker_.CalledOnValidThread()); | 336 RTC_DCHECK(configuration_thread_checker_.CalledOnValidThread()); |
| 333 RTC_DCHECK(send_stream != nullptr); | 337 RTC_DCHECK(send_stream != nullptr); |
| 334 | 338 |
| 335 send_stream->Stop(); | 339 send_stream->Stop(); |
| 336 | 340 |
| 337 webrtc::internal::AudioSendStream* audio_send_stream = | 341 webrtc::internal::AudioSendStream* audio_send_stream = |
| 338 static_cast<webrtc::internal::AudioSendStream*>(send_stream); | 342 static_cast<webrtc::internal::AudioSendStream*>(send_stream); |
| 339 { | 343 { |
| 340 WriteLockScoped write_lock(*send_crit_); | 344 WriteLockScoped write_lock(*send_crit_); |
| 341 size_t num_deleted = audio_send_ssrcs_.erase( | 345 size_t num_deleted = audio_send_ssrcs_.erase( |
| 342 audio_send_stream->config().rtp.ssrc); | 346 audio_send_stream->config().rtp.ssrc); |
| 343 RTC_DCHECK(num_deleted == 1); | 347 RTC_DCHECK(num_deleted == 1); |
| 344 } | 348 } |
| 349 UpdateAggregateNetworkState(); | |
| 345 delete audio_send_stream; | 350 delete audio_send_stream; |
| 346 } | 351 } |
| 347 | 352 |
| 348 webrtc::AudioReceiveStream* Call::CreateAudioReceiveStream( | 353 webrtc::AudioReceiveStream* Call::CreateAudioReceiveStream( |
| 349 const webrtc::AudioReceiveStream::Config& config) { | 354 const webrtc::AudioReceiveStream::Config& config) { |
| 350 TRACE_EVENT0("webrtc", "Call::CreateAudioReceiveStream"); | 355 TRACE_EVENT0("webrtc", "Call::CreateAudioReceiveStream"); |
| 351 RTC_DCHECK(configuration_thread_checker_.CalledOnValidThread()); | 356 RTC_DCHECK(configuration_thread_checker_.CalledOnValidThread()); |
| 352 AudioReceiveStream* receive_stream = new AudioReceiveStream( | 357 AudioReceiveStream* receive_stream = new AudioReceiveStream( |
| 353 congestion_controller_.get(), config, config_.audio_state); | 358 congestion_controller_.get(), config, config_.audio_state); |
| 354 { | 359 { |
| 355 WriteLockScoped write_lock(*receive_crit_); | 360 WriteLockScoped write_lock(*receive_crit_); |
| 356 RTC_DCHECK(audio_receive_ssrcs_.find(config.rtp.remote_ssrc) == | 361 RTC_DCHECK(audio_receive_ssrcs_.find(config.rtp.remote_ssrc) == |
| 357 audio_receive_ssrcs_.end()); | 362 audio_receive_ssrcs_.end()); |
| 358 audio_receive_ssrcs_[config.rtp.remote_ssrc] = receive_stream; | 363 audio_receive_ssrcs_[config.rtp.remote_ssrc] = receive_stream; |
| 359 ConfigureSync(config.sync_group); | 364 ConfigureSync(config.sync_group); |
| 360 } | 365 } |
| 366 receive_stream->SignalNetworkState(audio_network_state_); | |
| 367 UpdateAggregateNetworkState(); | |
| 361 return receive_stream; | 368 return receive_stream; |
| 362 } | 369 } |
| 363 | 370 |
| 364 void Call::DestroyAudioReceiveStream( | 371 void Call::DestroyAudioReceiveStream( |
| 365 webrtc::AudioReceiveStream* receive_stream) { | 372 webrtc::AudioReceiveStream* receive_stream) { |
| 366 TRACE_EVENT0("webrtc", "Call::DestroyAudioReceiveStream"); | 373 TRACE_EVENT0("webrtc", "Call::DestroyAudioReceiveStream"); |
| 367 RTC_DCHECK(configuration_thread_checker_.CalledOnValidThread()); | 374 RTC_DCHECK(configuration_thread_checker_.CalledOnValidThread()); |
| 368 RTC_DCHECK(receive_stream != nullptr); | 375 RTC_DCHECK(receive_stream != nullptr); |
| 369 webrtc::internal::AudioReceiveStream* audio_receive_stream = | 376 webrtc::internal::AudioReceiveStream* audio_receive_stream = |
| 370 static_cast<webrtc::internal::AudioReceiveStream*>(receive_stream); | 377 static_cast<webrtc::internal::AudioReceiveStream*>(receive_stream); |
| 371 { | 378 { |
| 372 WriteLockScoped write_lock(*receive_crit_); | 379 WriteLockScoped write_lock(*receive_crit_); |
| 373 size_t num_deleted = audio_receive_ssrcs_.erase( | 380 size_t num_deleted = audio_receive_ssrcs_.erase( |
| 374 audio_receive_stream->config().rtp.remote_ssrc); | 381 audio_receive_stream->config().rtp.remote_ssrc); |
| 375 RTC_DCHECK(num_deleted == 1); | 382 RTC_DCHECK(num_deleted == 1); |
| 376 const std::string& sync_group = audio_receive_stream->config().sync_group; | 383 const std::string& sync_group = audio_receive_stream->config().sync_group; |
| 377 const auto it = sync_stream_mapping_.find(sync_group); | 384 const auto it = sync_stream_mapping_.find(sync_group); |
| 378 if (it != sync_stream_mapping_.end() && | 385 if (it != sync_stream_mapping_.end() && |
| 379 it->second == audio_receive_stream) { | 386 it->second == audio_receive_stream) { |
| 380 sync_stream_mapping_.erase(it); | 387 sync_stream_mapping_.erase(it); |
| 381 ConfigureSync(sync_group); | 388 ConfigureSync(sync_group); |
| 382 } | 389 } |
| 383 } | 390 } |
| 391 UpdateAggregateNetworkState(); | |
| 384 delete audio_receive_stream; | 392 delete audio_receive_stream; |
| 385 } | 393 } |
| 386 | 394 |
| 387 webrtc::VideoSendStream* Call::CreateVideoSendStream( | 395 webrtc::VideoSendStream* Call::CreateVideoSendStream( |
| 388 const webrtc::VideoSendStream::Config& config, | 396 const webrtc::VideoSendStream::Config& config, |
| 389 const VideoEncoderConfig& encoder_config) { | 397 const VideoEncoderConfig& encoder_config) { |
| 390 TRACE_EVENT0("webrtc", "Call::CreateVideoSendStream"); | 398 TRACE_EVENT0("webrtc", "Call::CreateVideoSendStream"); |
| 391 RTC_DCHECK(configuration_thread_checker_.CalledOnValidThread()); | 399 RTC_DCHECK(configuration_thread_checker_.CalledOnValidThread()); |
| 392 | 400 |
| 393 // TODO(mflodman): Base the start bitrate on a current bandwidth estimate, if | 401 // TODO(mflodman): Base the start bitrate on a current bandwidth estimate, if |
| 394 // the call has already started. | 402 // the call has already started. |
| 395 VideoSendStream* send_stream = new VideoSendStream( | 403 VideoSendStream* send_stream = new VideoSendStream( |
| 396 num_cpu_cores_, module_process_thread_.get(), call_stats_.get(), | 404 num_cpu_cores_, module_process_thread_.get(), call_stats_.get(), |
| 397 congestion_controller_.get(), &remb_, bitrate_allocator_.get(), config, | 405 congestion_controller_.get(), &remb_, bitrate_allocator_.get(), config, |
| 398 encoder_config, suspended_video_send_ssrcs_); | 406 encoder_config, suspended_video_send_ssrcs_); |
| 399 | 407 { |
| 400 if (!network_enabled_) | 408 WriteLockScoped write_lock(*send_crit_); |
| 401 send_stream->SignalNetworkState(kNetworkDown); | 409 for (uint32_t ssrc : config.rtp.ssrcs) { |
| 402 | 410 RTC_DCHECK(video_send_ssrcs_.find(ssrc) == video_send_ssrcs_.end()); |
| 403 WriteLockScoped write_lock(*send_crit_); | 411 video_send_ssrcs_[ssrc] = send_stream; |
| 404 for (uint32_t ssrc : config.rtp.ssrcs) { | 412 } |
| 405 RTC_DCHECK(video_send_ssrcs_.find(ssrc) == video_send_ssrcs_.end()); | 413 video_send_streams_.insert(send_stream); |
| 406 video_send_ssrcs_[ssrc] = send_stream; | |
| 407 } | 414 } |
| 408 video_send_streams_.insert(send_stream); | 415 send_stream->SignalNetworkState(video_network_state_); |
|
the sun
2016/03/07 20:00:34
nit: make order the same; signal, updateaggregate.
skvlad
2016/03/08 23:55:27
Done.
| |
| 409 | |
| 410 if (event_log_) | 416 if (event_log_) |
| 411 event_log_->LogVideoSendStreamConfig(config); | 417 event_log_->LogVideoSendStreamConfig(config); |
| 412 | 418 UpdateAggregateNetworkState(); |
| 413 return send_stream; | 419 return send_stream; |
| 414 } | 420 } |
| 415 | 421 |
| 416 void Call::DestroyVideoSendStream(webrtc::VideoSendStream* send_stream) { | 422 void Call::DestroyVideoSendStream(webrtc::VideoSendStream* send_stream) { |
| 417 TRACE_EVENT0("webrtc", "Call::DestroyVideoSendStream"); | 423 TRACE_EVENT0("webrtc", "Call::DestroyVideoSendStream"); |
| 418 RTC_DCHECK(send_stream != nullptr); | 424 RTC_DCHECK(send_stream != nullptr); |
| 419 RTC_DCHECK(configuration_thread_checker_.CalledOnValidThread()); | 425 RTC_DCHECK(configuration_thread_checker_.CalledOnValidThread()); |
| 420 | 426 |
| 421 send_stream->Stop(); | 427 send_stream->Stop(); |
| 422 | 428 |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 437 RTC_CHECK(send_stream_impl != nullptr); | 443 RTC_CHECK(send_stream_impl != nullptr); |
| 438 | 444 |
| 439 VideoSendStream::RtpStateMap rtp_state = send_stream_impl->GetRtpStates(); | 445 VideoSendStream::RtpStateMap rtp_state = send_stream_impl->GetRtpStates(); |
| 440 | 446 |
| 441 for (VideoSendStream::RtpStateMap::iterator it = rtp_state.begin(); | 447 for (VideoSendStream::RtpStateMap::iterator it = rtp_state.begin(); |
| 442 it != rtp_state.end(); | 448 it != rtp_state.end(); |
| 443 ++it) { | 449 ++it) { |
| 444 suspended_video_send_ssrcs_[it->first] = it->second; | 450 suspended_video_send_ssrcs_[it->first] = it->second; |
| 445 } | 451 } |
| 446 | 452 |
| 453 UpdateAggregateNetworkState(); | |
| 447 delete send_stream_impl; | 454 delete send_stream_impl; |
| 448 } | 455 } |
| 449 | 456 |
| 450 webrtc::VideoReceiveStream* Call::CreateVideoReceiveStream( | 457 webrtc::VideoReceiveStream* Call::CreateVideoReceiveStream( |
| 451 const webrtc::VideoReceiveStream::Config& config) { | 458 const webrtc::VideoReceiveStream::Config& config) { |
| 452 TRACE_EVENT0("webrtc", "Call::CreateVideoReceiveStream"); | 459 TRACE_EVENT0("webrtc", "Call::CreateVideoReceiveStream"); |
| 453 RTC_DCHECK(configuration_thread_checker_.CalledOnValidThread()); | 460 RTC_DCHECK(configuration_thread_checker_.CalledOnValidThread()); |
| 454 VideoReceiveStream* receive_stream = new VideoReceiveStream( | 461 VideoReceiveStream* receive_stream = new VideoReceiveStream( |
| 455 num_cpu_cores_, congestion_controller_.get(), config, voice_engine(), | 462 num_cpu_cores_, congestion_controller_.get(), config, voice_engine(), |
| 456 module_process_thread_.get(), call_stats_.get(), &remb_); | 463 module_process_thread_.get(), call_stats_.get(), &remb_); |
| 464 { | |
| 465 WriteLockScoped write_lock(*receive_crit_); | |
| 466 RTC_DCHECK(video_receive_ssrcs_.find(config.rtp.remote_ssrc) == | |
| 467 video_receive_ssrcs_.end()); | |
| 468 video_receive_ssrcs_[config.rtp.remote_ssrc] = receive_stream; | |
| 469 // TODO(pbos): Configure different RTX payloads per receive payload. | |
| 470 VideoReceiveStream::Config::Rtp::RtxMap::const_iterator it = | |
| 471 config.rtp.rtx.begin(); | |
| 472 if (it != config.rtp.rtx.end()) | |
| 473 video_receive_ssrcs_[it->second.ssrc] = receive_stream; | |
| 474 video_receive_streams_.insert(receive_stream); | |
| 457 | 475 |
| 458 WriteLockScoped write_lock(*receive_crit_); | 476 ConfigureSync(config.sync_group); |
| 459 RTC_DCHECK(video_receive_ssrcs_.find(config.rtp.remote_ssrc) == | 477 } |
| 460 video_receive_ssrcs_.end()); | 478 receive_stream->SignalNetworkState(video_network_state_); |
| 461 video_receive_ssrcs_[config.rtp.remote_ssrc] = receive_stream; | 479 UpdateAggregateNetworkState(); |
| 462 // TODO(pbos): Configure different RTX payloads per receive payload. | |
| 463 VideoReceiveStream::Config::Rtp::RtxMap::const_iterator it = | |
| 464 config.rtp.rtx.begin(); | |
| 465 if (it != config.rtp.rtx.end()) | |
| 466 video_receive_ssrcs_[it->second.ssrc] = receive_stream; | |
| 467 video_receive_streams_.insert(receive_stream); | |
| 468 | |
| 469 ConfigureSync(config.sync_group); | |
| 470 | |
| 471 if (!network_enabled_) | |
| 472 receive_stream->SignalNetworkState(kNetworkDown); | |
| 473 | |
| 474 if (event_log_) | 480 if (event_log_) |
| 475 event_log_->LogVideoReceiveStreamConfig(config); | 481 event_log_->LogVideoReceiveStreamConfig(config); |
| 476 | |
| 477 return receive_stream; | 482 return receive_stream; |
| 478 } | 483 } |
| 479 | 484 |
| 480 void Call::DestroyVideoReceiveStream( | 485 void Call::DestroyVideoReceiveStream( |
| 481 webrtc::VideoReceiveStream* receive_stream) { | 486 webrtc::VideoReceiveStream* receive_stream) { |
| 482 TRACE_EVENT0("webrtc", "Call::DestroyVideoReceiveStream"); | 487 TRACE_EVENT0("webrtc", "Call::DestroyVideoReceiveStream"); |
| 483 RTC_DCHECK(configuration_thread_checker_.CalledOnValidThread()); | 488 RTC_DCHECK(configuration_thread_checker_.CalledOnValidThread()); |
| 484 RTC_DCHECK(receive_stream != nullptr); | 489 RTC_DCHECK(receive_stream != nullptr); |
| 485 VideoReceiveStream* receive_stream_impl = nullptr; | 490 VideoReceiveStream* receive_stream_impl = nullptr; |
| 486 { | 491 { |
| 487 WriteLockScoped write_lock(*receive_crit_); | 492 WriteLockScoped write_lock(*receive_crit_); |
| 488 // Remove all ssrcs pointing to a receive stream. As RTX retransmits on a | 493 // Remove all ssrcs pointing to a receive stream. As RTX retransmits on a |
| 489 // separate SSRC there can be either one or two. | 494 // separate SSRC there can be either one or two. |
| 490 auto it = video_receive_ssrcs_.begin(); | 495 auto it = video_receive_ssrcs_.begin(); |
| 491 while (it != video_receive_ssrcs_.end()) { | 496 while (it != video_receive_ssrcs_.end()) { |
| 492 if (it->second == static_cast<VideoReceiveStream*>(receive_stream)) { | 497 if (it->second == static_cast<VideoReceiveStream*>(receive_stream)) { |
| 493 if (receive_stream_impl != nullptr) | 498 if (receive_stream_impl != nullptr) |
| 494 RTC_DCHECK(receive_stream_impl == it->second); | 499 RTC_DCHECK(receive_stream_impl == it->second); |
| 495 receive_stream_impl = it->second; | 500 receive_stream_impl = it->second; |
| 496 video_receive_ssrcs_.erase(it++); | 501 video_receive_ssrcs_.erase(it++); |
| 497 } else { | 502 } else { |
| 498 ++it; | 503 ++it; |
| 499 } | 504 } |
| 500 } | 505 } |
| 501 video_receive_streams_.erase(receive_stream_impl); | 506 video_receive_streams_.erase(receive_stream_impl); |
| 502 RTC_CHECK(receive_stream_impl != nullptr); | 507 RTC_CHECK(receive_stream_impl != nullptr); |
| 503 ConfigureSync(receive_stream_impl->config().sync_group); | 508 ConfigureSync(receive_stream_impl->config().sync_group); |
| 504 } | 509 } |
| 510 UpdateAggregateNetworkState(); | |
| 505 delete receive_stream_impl; | 511 delete receive_stream_impl; |
| 506 } | 512 } |
| 507 | 513 |
| 508 Call::Stats Call::GetStats() const { | 514 Call::Stats Call::GetStats() const { |
| 509 // TODO(solenberg): Some test cases in EndToEndTest use this from a different | 515 // TODO(solenberg): Some test cases in EndToEndTest use this from a different |
| 510 // thread. Re-enable once that is fixed. | 516 // thread. Re-enable once that is fixed. |
| 511 // RTC_DCHECK(configuration_thread_checker_.CalledOnValidThread()); | 517 // RTC_DCHECK(configuration_thread_checker_.CalledOnValidThread()); |
| 512 Stats stats; | 518 Stats stats; |
| 513 // Fetch available send/receive bitrates. | 519 // Fetch available send/receive bitrates. |
| 514 uint32_t send_bandwidth = 0; | 520 uint32_t send_bandwidth = 0; |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 541 bitrate_config.max_bitrate_bps) { | 547 bitrate_config.max_bitrate_bps) { |
| 542 // Nothing new to set, early abort to avoid encoder reconfigurations. | 548 // Nothing new to set, early abort to avoid encoder reconfigurations. |
| 543 return; | 549 return; |
| 544 } | 550 } |
| 545 config_.bitrate_config = bitrate_config; | 551 config_.bitrate_config = bitrate_config; |
| 546 congestion_controller_->SetBweBitrates(bitrate_config.min_bitrate_bps, | 552 congestion_controller_->SetBweBitrates(bitrate_config.min_bitrate_bps, |
| 547 bitrate_config.start_bitrate_bps, | 553 bitrate_config.start_bitrate_bps, |
| 548 bitrate_config.max_bitrate_bps); | 554 bitrate_config.max_bitrate_bps); |
| 549 } | 555 } |
| 550 | 556 |
| 551 void Call::SignalNetworkState(NetworkState state) { | 557 void Call::SignalChannelNetworkState(MediaType media, |
| 558 NetworkState state) { | |
| 552 RTC_DCHECK(configuration_thread_checker_.CalledOnValidThread()); | 559 RTC_DCHECK(configuration_thread_checker_.CalledOnValidThread()); |
| 553 network_enabled_ = state == kNetworkUp; | 560 switch (media) { |
| 554 congestion_controller_->SignalNetworkState(state); | 561 case MediaType::AUDIO: |
| 562 audio_network_state_ = state; | |
| 563 break; | |
| 564 case MediaType::VIDEO: | |
| 565 video_network_state_ = state; | |
| 566 break; | |
| 567 default: | |
|
pbos-webrtc
2016/03/08 23:35:40
Remove the default case here and list the ones tha
skvlad
2016/03/08 23:55:28
Done.
the sun
2016/03/09 09:54:38
The default state is a good idea anyway, to make s
| |
| 568 RTC_NOTREACHED(); | |
| 569 break; | |
| 570 } | |
| 571 | |
| 572 UpdateAggregateNetworkState(); | |
| 555 { | 573 { |
| 556 ReadLockScoped write_lock(*send_crit_); | 574 ReadLockScoped read_lock(*send_crit_); |
| 557 for (auto& kv : audio_send_ssrcs_) { | 575 for (auto& kv : audio_send_ssrcs_) { |
| 558 kv.second->SignalNetworkState(state); | 576 kv.second->SignalNetworkState(audio_network_state_); |
| 559 } | 577 } |
| 560 for (auto& kv : video_send_ssrcs_) { | 578 for (auto& kv : video_send_ssrcs_) { |
| 561 kv.second->SignalNetworkState(state); | 579 kv.second->SignalNetworkState(video_network_state_); |
| 562 } | 580 } |
| 563 } | 581 } |
| 564 { | 582 { |
| 565 ReadLockScoped write_lock(*receive_crit_); | 583 ReadLockScoped read_lock(*receive_crit_); |
| 584 for (auto& kv : audio_receive_ssrcs_) { | |
| 585 kv.second->SignalNetworkState(audio_network_state_); | |
| 586 } | |
| 566 for (auto& kv : video_receive_ssrcs_) { | 587 for (auto& kv : video_receive_ssrcs_) { |
| 567 kv.second->SignalNetworkState(state); | 588 kv.second->SignalNetworkState(video_network_state_); |
| 568 } | 589 } |
| 569 } | 590 } |
| 570 } | 591 } |
| 571 | 592 |
| 593 void Call::UpdateAggregateNetworkState() { | |
| 594 RTC_DCHECK(configuration_thread_checker_.CalledOnValidThread()); | |
| 595 | |
| 596 bool haveVideo = false; | |
|
pbos-webrtc
2016/03/08 23:35:40
camel case not style compliant
skvlad
2016/03/08 23:55:28
Done.
| |
| 597 bool haveAudio = false; | |
| 598 { | |
| 599 ReadLockScoped read_lock(*send_crit_); | |
| 600 if (audio_send_ssrcs_.size() > 0) haveAudio = true; | |
|
pbos-webrtc
2016/03/08 23:35:40
if (!audio_send_ssrcs_.empty())
have_audio = tru
skvlad
2016/03/08 23:55:28
Done.
| |
| 601 if (video_send_ssrcs_.size() > 0) haveVideo = true; | |
| 602 } | |
| 603 { | |
| 604 ReadLockScoped read_lock(*receive_crit_); | |
| 605 if (audio_receive_ssrcs_.size() > 0) haveAudio = true; | |
| 606 if (video_receive_ssrcs_.size() > 0) haveVideo = true; | |
| 607 } | |
| 608 | |
| 609 NetworkState aggregateState = kNetworkDown; | |
| 610 if ((haveVideo && video_network_state_ == kNetworkUp) || | |
| 611 (haveAudio && audio_network_state_ == kNetworkUp)) { | |
| 612 aggregateState = kNetworkUp; | |
| 613 } | |
| 614 | |
| 615 LOG(LS_INFO) << "UpdateAggregateNetworkState: aggregateState=" << | |
| 616 (aggregateState == kNetworkUp ? "up" : "down"); | |
| 617 | |
| 618 congestion_controller_ -> SignalNetworkState(aggregateState); | |
|
the sun
2016/03/07 20:00:34
nit: remove spaces around "->"
pbos-webrtc
2016/03/08 23:35:40
run "git cl format"
skvlad
2016/03/08 23:55:27
Done.
skvlad
2016/03/08 23:55:27
Thanks, didn't know of this! very useful.
| |
| 619 } | |
| 620 | |
| 572 void Call::OnSentPacket(const rtc::SentPacket& sent_packet) { | 621 void Call::OnSentPacket(const rtc::SentPacket& sent_packet) { |
| 573 if (first_packet_sent_ms_ == -1) | 622 if (first_packet_sent_ms_ == -1) |
| 574 first_packet_sent_ms_ = clock_->TimeInMilliseconds(); | 623 first_packet_sent_ms_ = clock_->TimeInMilliseconds(); |
| 575 congestion_controller_->OnSentPacket(sent_packet); | 624 congestion_controller_->OnSentPacket(sent_packet); |
| 576 } | 625 } |
| 577 | 626 |
| 578 void Call::OnNetworkChanged(uint32_t target_bitrate_bps, uint8_t fraction_loss, | 627 void Call::OnNetworkChanged(uint32_t target_bitrate_bps, uint8_t fraction_loss, |
| 579 int64_t rtt_ms) { | 628 int64_t rtt_ms) { |
| 580 uint32_t allocated_bitrate_bps = bitrate_allocator_->OnNetworkChanged( | 629 uint32_t allocated_bitrate_bps = bitrate_allocator_->OnNetworkChanged( |
| 581 target_bitrate_bps, fraction_loss, rtt_ms); | 630 target_bitrate_bps, fraction_loss, rtt_ms); |
| (...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 744 // thread. Then this check can be enabled. | 793 // thread. Then this check can be enabled. |
| 745 // RTC_DCHECK(!configuration_thread_checker_.CalledOnValidThread()); | 794 // RTC_DCHECK(!configuration_thread_checker_.CalledOnValidThread()); |
| 746 if (RtpHeaderParser::IsRtcp(packet, length)) | 795 if (RtpHeaderParser::IsRtcp(packet, length)) |
| 747 return DeliverRtcp(media_type, packet, length); | 796 return DeliverRtcp(media_type, packet, length); |
| 748 | 797 |
| 749 return DeliverRtp(media_type, packet, length, packet_time); | 798 return DeliverRtp(media_type, packet, length, packet_time); |
| 750 } | 799 } |
| 751 | 800 |
| 752 } // namespace internal | 801 } // namespace internal |
| 753 } // namespace webrtc | 802 } // namespace webrtc |
| OLD | NEW |