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 std::unique_ptr<ProcessThread> module_process_thread_; | 125 const std::unique_ptr<ProcessThread> module_process_thread_; |
124 const std::unique_ptr<ProcessThread> pacer_thread_; | 126 const std::unique_ptr<ProcessThread> pacer_thread_; |
125 const std::unique_ptr<CallStats> call_stats_; | 127 const std::unique_ptr<CallStats> call_stats_; |
126 const std::unique_ptr<BitrateAllocator> bitrate_allocator_; | 128 const std::unique_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 std::unique_ptr<RWLockWrapper> receive_crit_; | 135 std::unique_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 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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_( | 189 module_process_thread_( |
187 rtc::ScopedToUnique(ProcessThread::Create("ModuleProcessThread"))), | 190 rtc::ScopedToUnique(ProcessThread::Create("ModuleProcessThread"))), |
188 pacer_thread_(rtc::ScopedToUnique(ProcessThread::Create("PacerThread"))), | 191 pacer_thread_(rtc::ScopedToUnique(ProcessThread::Create("PacerThread"))), |
189 call_stats_(new CallStats(clock_)), | 192 call_stats_(new CallStats(clock_)), |
190 bitrate_allocator_(new BitrateAllocator()), | 193 bitrate_allocator_(new BitrateAllocator()), |
191 config_(config), | 194 config_(config), |
192 network_enabled_(true), | 195 audio_network_state_(kNetworkUp), |
| 196 video_network_state_(kNetworkUp), |
193 receive_crit_(RWLockWrapper::CreateRWLock()), | 197 receive_crit_(RWLockWrapper::CreateRWLock()), |
194 send_crit_(RWLockWrapper::CreateRWLock()), | 198 send_crit_(RWLockWrapper::CreateRWLock()), |
195 received_video_bytes_(0), | 199 received_video_bytes_(0), |
196 received_audio_bytes_(0), | 200 received_audio_bytes_(0), |
197 received_rtcp_bytes_(0), | 201 received_rtcp_bytes_(0), |
198 first_rtp_packet_received_ms_(-1), | 202 first_rtp_packet_received_ms_(-1), |
199 last_rtp_packet_received_ms_(-1), | 203 last_rtp_packet_received_ms_(-1), |
200 first_packet_sent_ms_(-1), | 204 first_packet_sent_ms_(-1), |
201 estimated_send_bitrate_sum_kbits_(0), | 205 estimated_send_bitrate_sum_kbits_(0), |
202 pacer_bitrate_sum_kbits_(0), | 206 pacer_bitrate_sum_kbits_(0), |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
310 // RTC_DCHECK(configuration_thread_checker_.CalledOnValidThread()); | 314 // RTC_DCHECK(configuration_thread_checker_.CalledOnValidThread()); |
311 return this; | 315 return this; |
312 } | 316 } |
313 | 317 |
314 webrtc::AudioSendStream* Call::CreateAudioSendStream( | 318 webrtc::AudioSendStream* Call::CreateAudioSendStream( |
315 const webrtc::AudioSendStream::Config& config) { | 319 const webrtc::AudioSendStream::Config& config) { |
316 TRACE_EVENT0("webrtc", "Call::CreateAudioSendStream"); | 320 TRACE_EVENT0("webrtc", "Call::CreateAudioSendStream"); |
317 RTC_DCHECK(configuration_thread_checker_.CalledOnValidThread()); | 321 RTC_DCHECK(configuration_thread_checker_.CalledOnValidThread()); |
318 AudioSendStream* send_stream = new AudioSendStream( | 322 AudioSendStream* send_stream = new AudioSendStream( |
319 config, config_.audio_state, congestion_controller_.get()); | 323 config, config_.audio_state, congestion_controller_.get()); |
320 if (!network_enabled_) | |
321 send_stream->SignalNetworkState(kNetworkDown); | |
322 { | 324 { |
323 WriteLockScoped write_lock(*send_crit_); | 325 WriteLockScoped write_lock(*send_crit_); |
324 RTC_DCHECK(audio_send_ssrcs_.find(config.rtp.ssrc) == | 326 RTC_DCHECK(audio_send_ssrcs_.find(config.rtp.ssrc) == |
325 audio_send_ssrcs_.end()); | 327 audio_send_ssrcs_.end()); |
326 audio_send_ssrcs_[config.rtp.ssrc] = send_stream; | 328 audio_send_ssrcs_[config.rtp.ssrc] = send_stream; |
327 } | 329 } |
| 330 send_stream->SignalNetworkState(audio_network_state_); |
| 331 UpdateAggregateNetworkState(); |
328 return send_stream; | 332 return send_stream; |
329 } | 333 } |
330 | 334 |
331 void Call::DestroyAudioSendStream(webrtc::AudioSendStream* send_stream) { | 335 void Call::DestroyAudioSendStream(webrtc::AudioSendStream* send_stream) { |
332 TRACE_EVENT0("webrtc", "Call::DestroyAudioSendStream"); | 336 TRACE_EVENT0("webrtc", "Call::DestroyAudioSendStream"); |
333 RTC_DCHECK(configuration_thread_checker_.CalledOnValidThread()); | 337 RTC_DCHECK(configuration_thread_checker_.CalledOnValidThread()); |
334 RTC_DCHECK(send_stream != nullptr); | 338 RTC_DCHECK(send_stream != nullptr); |
335 | 339 |
336 send_stream->Stop(); | 340 send_stream->Stop(); |
337 | 341 |
338 webrtc::internal::AudioSendStream* audio_send_stream = | 342 webrtc::internal::AudioSendStream* audio_send_stream = |
339 static_cast<webrtc::internal::AudioSendStream*>(send_stream); | 343 static_cast<webrtc::internal::AudioSendStream*>(send_stream); |
340 { | 344 { |
341 WriteLockScoped write_lock(*send_crit_); | 345 WriteLockScoped write_lock(*send_crit_); |
342 size_t num_deleted = audio_send_ssrcs_.erase( | 346 size_t num_deleted = audio_send_ssrcs_.erase( |
343 audio_send_stream->config().rtp.ssrc); | 347 audio_send_stream->config().rtp.ssrc); |
344 RTC_DCHECK(num_deleted == 1); | 348 RTC_DCHECK(num_deleted == 1); |
345 } | 349 } |
| 350 UpdateAggregateNetworkState(); |
346 delete audio_send_stream; | 351 delete audio_send_stream; |
347 } | 352 } |
348 | 353 |
349 webrtc::AudioReceiveStream* Call::CreateAudioReceiveStream( | 354 webrtc::AudioReceiveStream* Call::CreateAudioReceiveStream( |
350 const webrtc::AudioReceiveStream::Config& config) { | 355 const webrtc::AudioReceiveStream::Config& config) { |
351 TRACE_EVENT0("webrtc", "Call::CreateAudioReceiveStream"); | 356 TRACE_EVENT0("webrtc", "Call::CreateAudioReceiveStream"); |
352 RTC_DCHECK(configuration_thread_checker_.CalledOnValidThread()); | 357 RTC_DCHECK(configuration_thread_checker_.CalledOnValidThread()); |
353 AudioReceiveStream* receive_stream = new AudioReceiveStream( | 358 AudioReceiveStream* receive_stream = new AudioReceiveStream( |
354 congestion_controller_.get(), config, config_.audio_state); | 359 congestion_controller_.get(), config, config_.audio_state); |
355 { | 360 { |
356 WriteLockScoped write_lock(*receive_crit_); | 361 WriteLockScoped write_lock(*receive_crit_); |
357 RTC_DCHECK(audio_receive_ssrcs_.find(config.rtp.remote_ssrc) == | 362 RTC_DCHECK(audio_receive_ssrcs_.find(config.rtp.remote_ssrc) == |
358 audio_receive_ssrcs_.end()); | 363 audio_receive_ssrcs_.end()); |
359 audio_receive_ssrcs_[config.rtp.remote_ssrc] = receive_stream; | 364 audio_receive_ssrcs_[config.rtp.remote_ssrc] = receive_stream; |
360 ConfigureSync(config.sync_group); | 365 ConfigureSync(config.sync_group); |
361 } | 366 } |
| 367 receive_stream->SignalNetworkState(audio_network_state_); |
| 368 UpdateAggregateNetworkState(); |
362 return receive_stream; | 369 return receive_stream; |
363 } | 370 } |
364 | 371 |
365 void Call::DestroyAudioReceiveStream( | 372 void Call::DestroyAudioReceiveStream( |
366 webrtc::AudioReceiveStream* receive_stream) { | 373 webrtc::AudioReceiveStream* receive_stream) { |
367 TRACE_EVENT0("webrtc", "Call::DestroyAudioReceiveStream"); | 374 TRACE_EVENT0("webrtc", "Call::DestroyAudioReceiveStream"); |
368 RTC_DCHECK(configuration_thread_checker_.CalledOnValidThread()); | 375 RTC_DCHECK(configuration_thread_checker_.CalledOnValidThread()); |
369 RTC_DCHECK(receive_stream != nullptr); | 376 RTC_DCHECK(receive_stream != nullptr); |
370 webrtc::internal::AudioReceiveStream* audio_receive_stream = | 377 webrtc::internal::AudioReceiveStream* audio_receive_stream = |
371 static_cast<webrtc::internal::AudioReceiveStream*>(receive_stream); | 378 static_cast<webrtc::internal::AudioReceiveStream*>(receive_stream); |
372 { | 379 { |
373 WriteLockScoped write_lock(*receive_crit_); | 380 WriteLockScoped write_lock(*receive_crit_); |
374 size_t num_deleted = audio_receive_ssrcs_.erase( | 381 size_t num_deleted = audio_receive_ssrcs_.erase( |
375 audio_receive_stream->config().rtp.remote_ssrc); | 382 audio_receive_stream->config().rtp.remote_ssrc); |
376 RTC_DCHECK(num_deleted == 1); | 383 RTC_DCHECK(num_deleted == 1); |
377 const std::string& sync_group = audio_receive_stream->config().sync_group; | 384 const std::string& sync_group = audio_receive_stream->config().sync_group; |
378 const auto it = sync_stream_mapping_.find(sync_group); | 385 const auto it = sync_stream_mapping_.find(sync_group); |
379 if (it != sync_stream_mapping_.end() && | 386 if (it != sync_stream_mapping_.end() && |
380 it->second == audio_receive_stream) { | 387 it->second == audio_receive_stream) { |
381 sync_stream_mapping_.erase(it); | 388 sync_stream_mapping_.erase(it); |
382 ConfigureSync(sync_group); | 389 ConfigureSync(sync_group); |
383 } | 390 } |
384 } | 391 } |
| 392 UpdateAggregateNetworkState(); |
385 delete audio_receive_stream; | 393 delete audio_receive_stream; |
386 } | 394 } |
387 | 395 |
388 webrtc::VideoSendStream* Call::CreateVideoSendStream( | 396 webrtc::VideoSendStream* Call::CreateVideoSendStream( |
389 const webrtc::VideoSendStream::Config& config, | 397 const webrtc::VideoSendStream::Config& config, |
390 const VideoEncoderConfig& encoder_config) { | 398 const VideoEncoderConfig& encoder_config) { |
391 TRACE_EVENT0("webrtc", "Call::CreateVideoSendStream"); | 399 TRACE_EVENT0("webrtc", "Call::CreateVideoSendStream"); |
392 RTC_DCHECK(configuration_thread_checker_.CalledOnValidThread()); | 400 RTC_DCHECK(configuration_thread_checker_.CalledOnValidThread()); |
393 | 401 |
394 // TODO(mflodman): Base the start bitrate on a current bandwidth estimate, if | 402 // TODO(mflodman): Base the start bitrate on a current bandwidth estimate, if |
395 // the call has already started. | 403 // the call has already started. |
396 VideoSendStream* send_stream = new VideoSendStream( | 404 VideoSendStream* send_stream = new VideoSendStream( |
397 num_cpu_cores_, module_process_thread_.get(), call_stats_.get(), | 405 num_cpu_cores_, module_process_thread_.get(), call_stats_.get(), |
398 congestion_controller_.get(), bitrate_allocator_.get(), &remb_, config, | 406 congestion_controller_.get(), bitrate_allocator_.get(), &remb_, config, |
399 encoder_config, suspended_video_send_ssrcs_); | 407 encoder_config, suspended_video_send_ssrcs_); |
400 | 408 { |
401 if (!network_enabled_) | 409 WriteLockScoped write_lock(*send_crit_); |
402 send_stream->SignalNetworkState(kNetworkDown); | 410 for (uint32_t ssrc : config.rtp.ssrcs) { |
403 | 411 RTC_DCHECK(video_send_ssrcs_.find(ssrc) == video_send_ssrcs_.end()); |
404 WriteLockScoped write_lock(*send_crit_); | 412 video_send_ssrcs_[ssrc] = send_stream; |
405 for (uint32_t ssrc : config.rtp.ssrcs) { | 413 } |
406 RTC_DCHECK(video_send_ssrcs_.find(ssrc) == video_send_ssrcs_.end()); | 414 video_send_streams_.insert(send_stream); |
407 video_send_ssrcs_[ssrc] = send_stream; | |
408 } | 415 } |
409 video_send_streams_.insert(send_stream); | 416 send_stream->SignalNetworkState(video_network_state_); |
410 | 417 UpdateAggregateNetworkState(); |
411 if (event_log_) | 418 if (event_log_) |
412 event_log_->LogVideoSendStreamConfig(config); | 419 event_log_->LogVideoSendStreamConfig(config); |
413 | |
414 return send_stream; | 420 return send_stream; |
415 } | 421 } |
416 | 422 |
417 void Call::DestroyVideoSendStream(webrtc::VideoSendStream* send_stream) { | 423 void Call::DestroyVideoSendStream(webrtc::VideoSendStream* send_stream) { |
418 TRACE_EVENT0("webrtc", "Call::DestroyVideoSendStream"); | 424 TRACE_EVENT0("webrtc", "Call::DestroyVideoSendStream"); |
419 RTC_DCHECK(send_stream != nullptr); | 425 RTC_DCHECK(send_stream != nullptr); |
420 RTC_DCHECK(configuration_thread_checker_.CalledOnValidThread()); | 426 RTC_DCHECK(configuration_thread_checker_.CalledOnValidThread()); |
421 | 427 |
422 send_stream->Stop(); | 428 send_stream->Stop(); |
423 | 429 |
(...skipping 14 matching lines...) Expand all Loading... |
438 RTC_CHECK(send_stream_impl != nullptr); | 444 RTC_CHECK(send_stream_impl != nullptr); |
439 | 445 |
440 VideoSendStream::RtpStateMap rtp_state = send_stream_impl->GetRtpStates(); | 446 VideoSendStream::RtpStateMap rtp_state = send_stream_impl->GetRtpStates(); |
441 | 447 |
442 for (VideoSendStream::RtpStateMap::iterator it = rtp_state.begin(); | 448 for (VideoSendStream::RtpStateMap::iterator it = rtp_state.begin(); |
443 it != rtp_state.end(); | 449 it != rtp_state.end(); |
444 ++it) { | 450 ++it) { |
445 suspended_video_send_ssrcs_[it->first] = it->second; | 451 suspended_video_send_ssrcs_[it->first] = it->second; |
446 } | 452 } |
447 | 453 |
| 454 UpdateAggregateNetworkState(); |
448 delete send_stream_impl; | 455 delete send_stream_impl; |
449 } | 456 } |
450 | 457 |
451 webrtc::VideoReceiveStream* Call::CreateVideoReceiveStream( | 458 webrtc::VideoReceiveStream* Call::CreateVideoReceiveStream( |
452 const webrtc::VideoReceiveStream::Config& config) { | 459 const webrtc::VideoReceiveStream::Config& config) { |
453 TRACE_EVENT0("webrtc", "Call::CreateVideoReceiveStream"); | 460 TRACE_EVENT0("webrtc", "Call::CreateVideoReceiveStream"); |
454 RTC_DCHECK(configuration_thread_checker_.CalledOnValidThread()); | 461 RTC_DCHECK(configuration_thread_checker_.CalledOnValidThread()); |
455 VideoReceiveStream* receive_stream = new VideoReceiveStream( | 462 VideoReceiveStream* receive_stream = new VideoReceiveStream( |
456 num_cpu_cores_, congestion_controller_.get(), config, voice_engine(), | 463 num_cpu_cores_, congestion_controller_.get(), config, voice_engine(), |
457 module_process_thread_.get(), call_stats_.get(), &remb_); | 464 module_process_thread_.get(), call_stats_.get(), &remb_); |
| 465 { |
| 466 WriteLockScoped write_lock(*receive_crit_); |
| 467 RTC_DCHECK(video_receive_ssrcs_.find(config.rtp.remote_ssrc) == |
| 468 video_receive_ssrcs_.end()); |
| 469 video_receive_ssrcs_[config.rtp.remote_ssrc] = receive_stream; |
| 470 // TODO(pbos): Configure different RTX payloads per receive payload. |
| 471 VideoReceiveStream::Config::Rtp::RtxMap::const_iterator it = |
| 472 config.rtp.rtx.begin(); |
| 473 if (it != config.rtp.rtx.end()) |
| 474 video_receive_ssrcs_[it->second.ssrc] = receive_stream; |
| 475 video_receive_streams_.insert(receive_stream); |
458 | 476 |
459 WriteLockScoped write_lock(*receive_crit_); | 477 ConfigureSync(config.sync_group); |
460 RTC_DCHECK(video_receive_ssrcs_.find(config.rtp.remote_ssrc) == | 478 } |
461 video_receive_ssrcs_.end()); | 479 receive_stream->SignalNetworkState(video_network_state_); |
462 video_receive_ssrcs_[config.rtp.remote_ssrc] = receive_stream; | 480 UpdateAggregateNetworkState(); |
463 // TODO(pbos): Configure different RTX payloads per receive payload. | |
464 VideoReceiveStream::Config::Rtp::RtxMap::const_iterator it = | |
465 config.rtp.rtx.begin(); | |
466 if (it != config.rtp.rtx.end()) | |
467 video_receive_ssrcs_[it->second.ssrc] = receive_stream; | |
468 video_receive_streams_.insert(receive_stream); | |
469 | |
470 ConfigureSync(config.sync_group); | |
471 | |
472 if (!network_enabled_) | |
473 receive_stream->SignalNetworkState(kNetworkDown); | |
474 | |
475 if (event_log_) | 481 if (event_log_) |
476 event_log_->LogVideoReceiveStreamConfig(config); | 482 event_log_->LogVideoReceiveStreamConfig(config); |
477 | |
478 return receive_stream; | 483 return receive_stream; |
479 } | 484 } |
480 | 485 |
481 void Call::DestroyVideoReceiveStream( | 486 void Call::DestroyVideoReceiveStream( |
482 webrtc::VideoReceiveStream* receive_stream) { | 487 webrtc::VideoReceiveStream* receive_stream) { |
483 TRACE_EVENT0("webrtc", "Call::DestroyVideoReceiveStream"); | 488 TRACE_EVENT0("webrtc", "Call::DestroyVideoReceiveStream"); |
484 RTC_DCHECK(configuration_thread_checker_.CalledOnValidThread()); | 489 RTC_DCHECK(configuration_thread_checker_.CalledOnValidThread()); |
485 RTC_DCHECK(receive_stream != nullptr); | 490 RTC_DCHECK(receive_stream != nullptr); |
486 VideoReceiveStream* receive_stream_impl = nullptr; | 491 VideoReceiveStream* receive_stream_impl = nullptr; |
487 { | 492 { |
488 WriteLockScoped write_lock(*receive_crit_); | 493 WriteLockScoped write_lock(*receive_crit_); |
489 // Remove all ssrcs pointing to a receive stream. As RTX retransmits on a | 494 // Remove all ssrcs pointing to a receive stream. As RTX retransmits on a |
490 // separate SSRC there can be either one or two. | 495 // separate SSRC there can be either one or two. |
491 auto it = video_receive_ssrcs_.begin(); | 496 auto it = video_receive_ssrcs_.begin(); |
492 while (it != video_receive_ssrcs_.end()) { | 497 while (it != video_receive_ssrcs_.end()) { |
493 if (it->second == static_cast<VideoReceiveStream*>(receive_stream)) { | 498 if (it->second == static_cast<VideoReceiveStream*>(receive_stream)) { |
494 if (receive_stream_impl != nullptr) | 499 if (receive_stream_impl != nullptr) |
495 RTC_DCHECK(receive_stream_impl == it->second); | 500 RTC_DCHECK(receive_stream_impl == it->second); |
496 receive_stream_impl = it->second; | 501 receive_stream_impl = it->second; |
497 video_receive_ssrcs_.erase(it++); | 502 video_receive_ssrcs_.erase(it++); |
498 } else { | 503 } else { |
499 ++it; | 504 ++it; |
500 } | 505 } |
501 } | 506 } |
502 video_receive_streams_.erase(receive_stream_impl); | 507 video_receive_streams_.erase(receive_stream_impl); |
503 RTC_CHECK(receive_stream_impl != nullptr); | 508 RTC_CHECK(receive_stream_impl != nullptr); |
504 ConfigureSync(receive_stream_impl->config().sync_group); | 509 ConfigureSync(receive_stream_impl->config().sync_group); |
505 } | 510 } |
| 511 UpdateAggregateNetworkState(); |
506 delete receive_stream_impl; | 512 delete receive_stream_impl; |
507 } | 513 } |
508 | 514 |
509 Call::Stats Call::GetStats() const { | 515 Call::Stats Call::GetStats() const { |
510 // TODO(solenberg): Some test cases in EndToEndTest use this from a different | 516 // TODO(solenberg): Some test cases in EndToEndTest use this from a different |
511 // thread. Re-enable once that is fixed. | 517 // thread. Re-enable once that is fixed. |
512 // RTC_DCHECK(configuration_thread_checker_.CalledOnValidThread()); | 518 // RTC_DCHECK(configuration_thread_checker_.CalledOnValidThread()); |
513 Stats stats; | 519 Stats stats; |
514 // Fetch available send/receive bitrates. | 520 // Fetch available send/receive bitrates. |
515 uint32_t send_bandwidth = 0; | 521 uint32_t send_bandwidth = 0; |
(...skipping 26 matching lines...) Expand all Loading... |
542 bitrate_config.max_bitrate_bps) { | 548 bitrate_config.max_bitrate_bps) { |
543 // Nothing new to set, early abort to avoid encoder reconfigurations. | 549 // Nothing new to set, early abort to avoid encoder reconfigurations. |
544 return; | 550 return; |
545 } | 551 } |
546 config_.bitrate_config = bitrate_config; | 552 config_.bitrate_config = bitrate_config; |
547 congestion_controller_->SetBweBitrates(bitrate_config.min_bitrate_bps, | 553 congestion_controller_->SetBweBitrates(bitrate_config.min_bitrate_bps, |
548 bitrate_config.start_bitrate_bps, | 554 bitrate_config.start_bitrate_bps, |
549 bitrate_config.max_bitrate_bps); | 555 bitrate_config.max_bitrate_bps); |
550 } | 556 } |
551 | 557 |
552 void Call::SignalNetworkState(NetworkState state) { | 558 void Call::SignalChannelNetworkState(MediaType media, NetworkState state) { |
553 RTC_DCHECK(configuration_thread_checker_.CalledOnValidThread()); | 559 RTC_DCHECK(configuration_thread_checker_.CalledOnValidThread()); |
554 network_enabled_ = state == kNetworkUp; | 560 switch (media) { |
555 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 case MediaType::ANY: |
| 568 case MediaType::DATA: |
| 569 RTC_NOTREACHED(); |
| 570 break; |
| 571 } |
| 572 |
| 573 UpdateAggregateNetworkState(); |
556 { | 574 { |
557 ReadLockScoped write_lock(*send_crit_); | 575 ReadLockScoped read_lock(*send_crit_); |
558 for (auto& kv : audio_send_ssrcs_) { | 576 for (auto& kv : audio_send_ssrcs_) { |
559 kv.second->SignalNetworkState(state); | 577 kv.second->SignalNetworkState(audio_network_state_); |
560 } | 578 } |
561 for (auto& kv : video_send_ssrcs_) { | 579 for (auto& kv : video_send_ssrcs_) { |
562 kv.second->SignalNetworkState(state); | 580 kv.second->SignalNetworkState(video_network_state_); |
563 } | 581 } |
564 } | 582 } |
565 { | 583 { |
566 ReadLockScoped write_lock(*receive_crit_); | 584 ReadLockScoped read_lock(*receive_crit_); |
| 585 for (auto& kv : audio_receive_ssrcs_) { |
| 586 kv.second->SignalNetworkState(audio_network_state_); |
| 587 } |
567 for (auto& kv : video_receive_ssrcs_) { | 588 for (auto& kv : video_receive_ssrcs_) { |
568 kv.second->SignalNetworkState(state); | 589 kv.second->SignalNetworkState(video_network_state_); |
569 } | 590 } |
570 } | 591 } |
571 } | 592 } |
572 | 593 |
| 594 void Call::UpdateAggregateNetworkState() { |
| 595 RTC_DCHECK(configuration_thread_checker_.CalledOnValidThread()); |
| 596 |
| 597 bool have_audio = false; |
| 598 bool have_video = false; |
| 599 { |
| 600 ReadLockScoped read_lock(*send_crit_); |
| 601 if (audio_send_ssrcs_.size() > 0) |
| 602 have_audio = true; |
| 603 if (video_send_ssrcs_.size() > 0) |
| 604 have_video = true; |
| 605 } |
| 606 { |
| 607 ReadLockScoped read_lock(*receive_crit_); |
| 608 if (audio_receive_ssrcs_.size() > 0) |
| 609 have_audio = true; |
| 610 if (video_receive_ssrcs_.size() > 0) |
| 611 have_video = true; |
| 612 } |
| 613 |
| 614 NetworkState aggregate_state = kNetworkDown; |
| 615 if ((have_video && video_network_state_ == kNetworkUp) || |
| 616 (have_audio && audio_network_state_ == kNetworkUp)) { |
| 617 aggregate_state = kNetworkUp; |
| 618 } |
| 619 |
| 620 LOG(LS_INFO) << "UpdateAggregateNetworkState: aggregate_state=" |
| 621 << (aggregate_state == kNetworkUp ? "up" : "down"); |
| 622 |
| 623 congestion_controller_->SignalNetworkState(aggregate_state); |
| 624 } |
| 625 |
573 void Call::OnSentPacket(const rtc::SentPacket& sent_packet) { | 626 void Call::OnSentPacket(const rtc::SentPacket& sent_packet) { |
574 if (first_packet_sent_ms_ == -1) | 627 if (first_packet_sent_ms_ == -1) |
575 first_packet_sent_ms_ = clock_->TimeInMilliseconds(); | 628 first_packet_sent_ms_ = clock_->TimeInMilliseconds(); |
576 congestion_controller_->OnSentPacket(sent_packet); | 629 congestion_controller_->OnSentPacket(sent_packet); |
577 } | 630 } |
578 | 631 |
579 void Call::OnNetworkChanged(uint32_t target_bitrate_bps, uint8_t fraction_loss, | 632 void Call::OnNetworkChanged(uint32_t target_bitrate_bps, uint8_t fraction_loss, |
580 int64_t rtt_ms) { | 633 int64_t rtt_ms) { |
581 uint32_t allocated_bitrate_bps = bitrate_allocator_->OnNetworkChanged( | 634 uint32_t allocated_bitrate_bps = bitrate_allocator_->OnNetworkChanged( |
582 target_bitrate_bps, fraction_loss, rtt_ms); | 635 target_bitrate_bps, fraction_loss, rtt_ms); |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
745 // thread. Then this check can be enabled. | 798 // thread. Then this check can be enabled. |
746 // RTC_DCHECK(!configuration_thread_checker_.CalledOnValidThread()); | 799 // RTC_DCHECK(!configuration_thread_checker_.CalledOnValidThread()); |
747 if (RtpHeaderParser::IsRtcp(packet, length)) | 800 if (RtpHeaderParser::IsRtcp(packet, length)) |
748 return DeliverRtcp(media_type, packet, length); | 801 return DeliverRtcp(media_type, packet, length); |
749 | 802 |
750 return DeliverRtp(media_type, packet, length, packet_time); | 803 return DeliverRtp(media_type, packet, length, packet_time); |
751 } | 804 } |
752 | 805 |
753 } // namespace internal | 806 } // namespace internal |
754 } // namespace webrtc | 807 } // namespace webrtc |
OLD | NEW |