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 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 102 | 102 |
| 103 private: | 103 private: |
| 104 DeliveryStatus DeliverRtcp(MediaType media_type, const uint8_t* packet, | 104 DeliveryStatus DeliverRtcp(MediaType media_type, const uint8_t* packet, |
| 105 size_t length); | 105 size_t length); |
| 106 DeliveryStatus DeliverRtp(MediaType media_type, const uint8_t* packet, | 106 DeliveryStatus DeliverRtp(MediaType media_type, const uint8_t* packet, |
| 107 size_t length); | 107 size_t length); |
| 108 | 108 |
| 109 void SetBitrateControllerConfig( | 109 void SetBitrateControllerConfig( |
| 110 const webrtc::Call::Config::BitrateConfig& bitrate_config); | 110 const webrtc::Call::Config::BitrateConfig& bitrate_config); |
| 111 | 111 |
| 112 void AddAudioReceiveStreamSync(AudioReceiveStream* stream) | |
| 113 EXCLUSIVE_LOCKS_REQUIRED(receive_crit_); | |
| 114 void RemoveAudioReceiveStreamSync(AudioReceiveStream* stream) | |
| 115 EXCLUSIVE_LOCKS_REQUIRED(receive_crit_); | |
| 116 | |
| 117 void AddVideoReceiveStreamSync(VideoReceiveStream* stream) | |
| 118 EXCLUSIVE_LOCKS_REQUIRED(receive_crit_); | |
| 119 void RemoveVideoReceiveStreamSync(VideoReceiveStream* stream) | |
| 120 EXCLUSIVE_LOCKS_REQUIRED(receive_crit_); | |
| 121 | |
| 112 const int num_cpu_cores_; | 122 const int num_cpu_cores_; |
| 113 const rtc::scoped_ptr<ProcessThread> module_process_thread_; | 123 const rtc::scoped_ptr<ProcessThread> module_process_thread_; |
| 114 const rtc::scoped_ptr<ChannelGroup> channel_group_; | 124 const rtc::scoped_ptr<ChannelGroup> channel_group_; |
| 115 const int base_channel_id_; | 125 const int base_channel_id_; |
| 116 volatile int next_channel_id_; | 126 volatile int next_channel_id_; |
| 117 Call::Config config_; | 127 Call::Config config_; |
| 118 | 128 |
| 119 // Needs to be held while write-locking |receive_crit_| or |send_crit_|. This | 129 // Needs to be held while write-locking |receive_crit_| or |send_crit_|. This |
| 120 // ensures that we have a consistent network state signalled to all senders | 130 // ensures that we have a consistent network state signalled to all senders |
| 121 // and receivers. | 131 // and receivers. |
| 122 rtc::CriticalSection network_enabled_crit_; | 132 rtc::CriticalSection network_enabled_crit_; |
| 123 bool network_enabled_ GUARDED_BY(network_enabled_crit_); | 133 bool network_enabled_ GUARDED_BY(network_enabled_crit_); |
| 124 TransportAdapter transport_adapter_; | 134 TransportAdapter transport_adapter_; |
| 125 | 135 |
| 126 rtc::scoped_ptr<RWLockWrapper> receive_crit_; | 136 rtc::scoped_ptr<RWLockWrapper> receive_crit_; |
| 127 std::map<uint32_t, AudioReceiveStream*> audio_receive_ssrcs_ | 137 std::map<uint32_t, AudioReceiveStream*> audio_receive_ssrcs_ |
| 128 GUARDED_BY(receive_crit_); | 138 GUARDED_BY(receive_crit_); |
| 129 std::map<uint32_t, VideoReceiveStream*> video_receive_ssrcs_ | 139 std::map<uint32_t, VideoReceiveStream*> video_receive_ssrcs_ |
| 130 GUARDED_BY(receive_crit_); | 140 GUARDED_BY(receive_crit_); |
| 131 std::set<VideoReceiveStream*> video_receive_streams_ | 141 std::set<VideoReceiveStream*> video_receive_streams_ |
| 132 GUARDED_BY(receive_crit_); | 142 GUARDED_BY(receive_crit_); |
| 143 std::map<std::string, AudioReceiveStream*> sync_stream_mapping_ | |
| 144 GUARDED_BY(receive_crit_); | |
| 133 | 145 |
| 134 rtc::scoped_ptr<RWLockWrapper> send_crit_; | 146 rtc::scoped_ptr<RWLockWrapper> send_crit_; |
| 135 std::map<uint32_t, VideoSendStream*> video_send_ssrcs_ GUARDED_BY(send_crit_); | 147 std::map<uint32_t, VideoSendStream*> video_send_ssrcs_ GUARDED_BY(send_crit_); |
| 136 std::set<VideoSendStream*> video_send_streams_ GUARDED_BY(send_crit_); | 148 std::set<VideoSendStream*> video_send_streams_ GUARDED_BY(send_crit_); |
| 137 | 149 |
| 138 rtc::scoped_ptr<CpuOveruseObserverProxy> overuse_observer_proxy_; | 150 rtc::scoped_ptr<CpuOveruseObserverProxy> overuse_observer_proxy_; |
| 139 | 151 |
| 140 VideoSendStream::RtpStateMap suspended_video_send_ssrcs_; | 152 VideoSendStream::RtpStateMap suspended_video_send_ssrcs_; |
| 141 | 153 |
| 142 DISALLOW_COPY_AND_ASSIGN(Call); | 154 DISALLOW_COPY_AND_ASSIGN(Call); |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 212 const webrtc::AudioReceiveStream::Config& config) { | 224 const webrtc::AudioReceiveStream::Config& config) { |
| 213 TRACE_EVENT0("webrtc", "Call::CreateAudioReceiveStream"); | 225 TRACE_EVENT0("webrtc", "Call::CreateAudioReceiveStream"); |
| 214 LOG(LS_INFO) << "CreateAudioReceiveStream: " << config.ToString(); | 226 LOG(LS_INFO) << "CreateAudioReceiveStream: " << config.ToString(); |
| 215 AudioReceiveStream* receive_stream = new AudioReceiveStream( | 227 AudioReceiveStream* receive_stream = new AudioReceiveStream( |
| 216 channel_group_->GetRemoteBitrateEstimator(), config); | 228 channel_group_->GetRemoteBitrateEstimator(), config); |
| 217 { | 229 { |
| 218 WriteLockScoped write_lock(*receive_crit_); | 230 WriteLockScoped write_lock(*receive_crit_); |
| 219 DCHECK(audio_receive_ssrcs_.find(config.rtp.remote_ssrc) == | 231 DCHECK(audio_receive_ssrcs_.find(config.rtp.remote_ssrc) == |
| 220 audio_receive_ssrcs_.end()); | 232 audio_receive_ssrcs_.end()); |
| 221 audio_receive_ssrcs_[config.rtp.remote_ssrc] = receive_stream; | 233 audio_receive_ssrcs_[config.rtp.remote_ssrc] = receive_stream; |
| 234 AddAudioReceiveStreamSync(receive_stream); | |
| 222 } | 235 } |
| 223 return receive_stream; | 236 return receive_stream; |
| 224 } | 237 } |
| 225 | 238 |
| 226 void Call::DestroyAudioReceiveStream( | 239 void Call::DestroyAudioReceiveStream( |
| 227 webrtc::AudioReceiveStream* receive_stream) { | 240 webrtc::AudioReceiveStream* receive_stream) { |
| 228 TRACE_EVENT0("webrtc", "Call::DestroyAudioReceiveStream"); | 241 TRACE_EVENT0("webrtc", "Call::DestroyAudioReceiveStream"); |
| 229 DCHECK(receive_stream != nullptr); | 242 DCHECK(receive_stream != nullptr); |
| 230 AudioReceiveStream* audio_receive_stream = | 243 AudioReceiveStream* audio_receive_stream = |
| 231 static_cast<AudioReceiveStream*>(receive_stream); | 244 static_cast<AudioReceiveStream*>(receive_stream); |
| 232 { | 245 { |
| 233 WriteLockScoped write_lock(*receive_crit_); | 246 WriteLockScoped write_lock(*receive_crit_); |
| 234 size_t num_deleted = audio_receive_ssrcs_.erase( | 247 size_t num_deleted = audio_receive_ssrcs_.erase( |
| 235 audio_receive_stream->config().rtp.remote_ssrc); | 248 audio_receive_stream->config().rtp.remote_ssrc); |
| 236 DCHECK(num_deleted == 1); | 249 DCHECK(num_deleted == 1); |
| 250 RemoveAudioReceiveStreamSync(audio_receive_stream); | |
| 237 } | 251 } |
| 238 delete audio_receive_stream; | 252 delete audio_receive_stream; |
| 239 } | 253 } |
| 240 | 254 |
| 241 webrtc::VideoSendStream* Call::CreateVideoSendStream( | 255 webrtc::VideoSendStream* Call::CreateVideoSendStream( |
| 242 const webrtc::VideoSendStream::Config& config, | 256 const webrtc::VideoSendStream::Config& config, |
| 243 const VideoEncoderConfig& encoder_config) { | 257 const VideoEncoderConfig& encoder_config) { |
| 244 TRACE_EVENT0("webrtc", "Call::CreateVideoSendStream"); | 258 TRACE_EVENT0("webrtc", "Call::CreateVideoSendStream"); |
| 245 LOG(LS_INFO) << "CreateVideoSendStream: " << config.ToString(); | 259 LOG(LS_INFO) << "CreateVideoSendStream: " << config.ToString(); |
| 246 DCHECK(!config.rtp.ssrcs.empty()); | 260 DCHECK(!config.rtp.ssrcs.empty()); |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 317 DCHECK(video_receive_ssrcs_.find(config.rtp.remote_ssrc) == | 331 DCHECK(video_receive_ssrcs_.find(config.rtp.remote_ssrc) == |
| 318 video_receive_ssrcs_.end()); | 332 video_receive_ssrcs_.end()); |
| 319 video_receive_ssrcs_[config.rtp.remote_ssrc] = receive_stream; | 333 video_receive_ssrcs_[config.rtp.remote_ssrc] = receive_stream; |
| 320 // TODO(pbos): Configure different RTX payloads per receive payload. | 334 // TODO(pbos): Configure different RTX payloads per receive payload. |
| 321 VideoReceiveStream::Config::Rtp::RtxMap::const_iterator it = | 335 VideoReceiveStream::Config::Rtp::RtxMap::const_iterator it = |
| 322 config.rtp.rtx.begin(); | 336 config.rtp.rtx.begin(); |
| 323 if (it != config.rtp.rtx.end()) | 337 if (it != config.rtp.rtx.end()) |
| 324 video_receive_ssrcs_[it->second.ssrc] = receive_stream; | 338 video_receive_ssrcs_[it->second.ssrc] = receive_stream; |
| 325 video_receive_streams_.insert(receive_stream); | 339 video_receive_streams_.insert(receive_stream); |
| 326 | 340 |
| 341 AddVideoReceiveStreamSync(receive_stream); | |
| 342 | |
| 327 if (!network_enabled_) | 343 if (!network_enabled_) |
| 328 receive_stream->SignalNetworkState(kNetworkDown); | 344 receive_stream->SignalNetworkState(kNetworkDown); |
| 345 | |
| 329 return receive_stream; | 346 return receive_stream; |
| 330 } | 347 } |
| 331 | 348 |
| 332 void Call::DestroyVideoReceiveStream( | 349 void Call::DestroyVideoReceiveStream( |
| 333 webrtc::VideoReceiveStream* receive_stream) { | 350 webrtc::VideoReceiveStream* receive_stream) { |
| 334 TRACE_EVENT0("webrtc", "Call::DestroyVideoReceiveStream"); | 351 TRACE_EVENT0("webrtc", "Call::DestroyVideoReceiveStream"); |
| 335 DCHECK(receive_stream != nullptr); | 352 DCHECK(receive_stream != nullptr); |
| 336 | |
| 337 VideoReceiveStream* receive_stream_impl = nullptr; | 353 VideoReceiveStream* receive_stream_impl = nullptr; |
| 338 { | 354 { |
| 339 WriteLockScoped write_lock(*receive_crit_); | 355 WriteLockScoped write_lock(*receive_crit_); |
| 340 // Remove all ssrcs pointing to a receive stream. As RTX retransmits on a | 356 // Remove all ssrcs pointing to a receive stream. As RTX retransmits on a |
| 341 // separate SSRC there can be either one or two. | 357 // separate SSRC there can be either one or two. |
| 342 auto it = video_receive_ssrcs_.begin(); | 358 auto it = video_receive_ssrcs_.begin(); |
| 343 while (it != video_receive_ssrcs_.end()) { | 359 while (it != video_receive_ssrcs_.end()) { |
| 344 if (it->second == static_cast<VideoReceiveStream*>(receive_stream)) { | 360 if (it->second == static_cast<VideoReceiveStream*>(receive_stream)) { |
| 345 if (receive_stream_impl != nullptr) | 361 if (receive_stream_impl != nullptr) |
| 346 DCHECK(receive_stream_impl == it->second); | 362 DCHECK(receive_stream_impl == it->second); |
| 347 receive_stream_impl = it->second; | 363 receive_stream_impl = it->second; |
| 348 video_receive_ssrcs_.erase(it++); | 364 video_receive_ssrcs_.erase(it++); |
| 349 } else { | 365 } else { |
| 350 ++it; | 366 ++it; |
| 351 } | 367 } |
| 352 } | 368 } |
| 353 video_receive_streams_.erase(receive_stream_impl); | 369 video_receive_streams_.erase(receive_stream_impl); |
| 370 CHECK(receive_stream_impl != nullptr); | |
| 371 RemoveVideoReceiveStreamSync(receive_stream_impl); | |
| 354 } | 372 } |
| 355 CHECK(receive_stream_impl != nullptr); | |
| 356 delete receive_stream_impl; | 373 delete receive_stream_impl; |
| 357 } | 374 } |
| 358 | 375 |
| 359 Call::Stats Call::GetStats() const { | 376 Call::Stats Call::GetStats() const { |
| 360 Stats stats; | 377 Stats stats; |
| 361 // Fetch available send/receive bitrates. | 378 // Fetch available send/receive bitrates. |
| 362 uint32_t send_bandwidth = 0; | 379 uint32_t send_bandwidth = 0; |
| 363 channel_group_->GetBitrateController()->AvailableBandwidth(&send_bandwidth); | 380 channel_group_->GetBitrateController()->AvailableBandwidth(&send_bandwidth); |
| 364 std::vector<unsigned int> ssrcs; | 381 std::vector<unsigned int> ssrcs; |
| 365 uint32_t recv_bandwidth = 0; | 382 uint32_t recv_bandwidth = 0; |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 421 } | 438 } |
| 422 } | 439 } |
| 423 { | 440 { |
| 424 ReadLockScoped write_lock(*receive_crit_); | 441 ReadLockScoped write_lock(*receive_crit_); |
| 425 for (auto& kv : video_receive_ssrcs_) { | 442 for (auto& kv : video_receive_ssrcs_) { |
| 426 kv.second->SignalNetworkState(state); | 443 kv.second->SignalNetworkState(state); |
| 427 } | 444 } |
| 428 } | 445 } |
| 429 } | 446 } |
| 430 | 447 |
| 448 void Call::AddAudioReceiveStreamSync(AudioReceiveStream* stream) { | |
|
the sun
2015/06/11 15:38:48
I'd like you to spend a few minutes to see if this
pbos-webrtc
2015/06/12 15:53:14
Done.
| |
| 449 // Set sync only if there was no previous one. | |
| 450 if (stream->config().sync_group.empty() || | |
| 451 sync_stream_mapping_[stream->config().sync_group] != nullptr) { | |
| 452 return; | |
| 453 } | |
| 454 | |
| 455 sync_stream_mapping_[stream->config().sync_group] = stream; | |
| 456 for (VideoReceiveStream* video_stream : video_receive_streams_) { | |
| 457 video_stream->SetSyncChannel(config_.voice_engine, | |
| 458 stream->config().voe_channel_id); | |
| 459 } | |
| 460 } | |
| 461 | |
| 462 void Call::RemoveAudioReceiveStreamSync(AudioReceiveStream* stream) { | |
| 463 // Try to replace sync only if this stream was previously used. | |
| 464 if (stream->config().sync_group.empty() || | |
| 465 sync_stream_mapping_[stream->config().sync_group] != stream) { | |
| 466 return; | |
| 467 } | |
| 468 sync_stream_mapping_[stream->config().sync_group] = nullptr; | |
| 469 int voe_channel_id = -1; | |
| 470 for (auto& kv : audio_receive_ssrcs_) { | |
| 471 if (kv.second->config().sync_group == stream->config().sync_group) { | |
| 472 sync_stream_mapping_[stream->config().sync_group] = kv.second; | |
| 473 voe_channel_id = kv.second->config().voe_channel_id; | |
| 474 break; | |
| 475 } | |
| 476 } | |
| 477 | |
| 478 for (VideoReceiveStream* video_stream : video_receive_streams_) | |
| 479 video_stream->SetSyncChannel(config_.voice_engine, voe_channel_id); | |
| 480 } | |
| 481 | |
| 482 void Call::AddVideoReceiveStreamSync(VideoReceiveStream* stream) { | |
| 483 // Configure sync only if there's an audio stream to sync to. | |
| 484 if (stream->config().sync_group.empty() || | |
| 485 sync_stream_mapping_[stream->config().sync_group] == nullptr) { | |
| 486 return; | |
| 487 } | |
| 488 stream->SetSyncChannel(config_.voice_engine, | |
| 489 sync_stream_mapping_[stream->config().sync_group] | |
| 490 ->config() | |
| 491 .voe_channel_id); | |
| 492 } | |
| 493 | |
| 494 void Call::RemoveVideoReceiveStreamSync(VideoReceiveStream* stream) { | |
| 495 stream->SetSyncChannel(nullptr, -1); | |
| 496 } | |
| 497 | |
| 431 PacketReceiver::DeliveryStatus Call::DeliverRtcp(MediaType media_type, | 498 PacketReceiver::DeliveryStatus Call::DeliverRtcp(MediaType media_type, |
| 432 const uint8_t* packet, | 499 const uint8_t* packet, |
| 433 size_t length) { | 500 size_t length) { |
| 434 // TODO(pbos): Figure out what channel needs it actually. | 501 // TODO(pbos): Figure out what channel needs it actually. |
| 435 // Do NOT broadcast! Also make sure it's a valid packet. | 502 // Do NOT broadcast! Also make sure it's a valid packet. |
| 436 // Return DELIVERY_UNKNOWN_SSRC if it can be determined that | 503 // Return DELIVERY_UNKNOWN_SSRC if it can be determined that |
| 437 // there's no receiver of the packet. | 504 // there's no receiver of the packet. |
| 438 bool rtcp_delivered = false; | 505 bool rtcp_delivered = false; |
| 439 if (media_type == MediaType::ANY || media_type == MediaType::VIDEO) { | 506 if (media_type == MediaType::ANY || media_type == MediaType::VIDEO) { |
| 440 ReadLockScoped read_lock(*receive_crit_); | 507 ReadLockScoped read_lock(*receive_crit_); |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 484 const uint8_t* packet, | 551 const uint8_t* packet, |
| 485 size_t length) { | 552 size_t length) { |
| 486 if (RtpHeaderParser::IsRtcp(packet, length)) | 553 if (RtpHeaderParser::IsRtcp(packet, length)) |
| 487 return DeliverRtcp(media_type, packet, length); | 554 return DeliverRtcp(media_type, packet, length); |
| 488 | 555 |
| 489 return DeliverRtp(media_type, packet, length); | 556 return DeliverRtp(media_type, packet, length); |
| 490 } | 557 } |
| 491 | 558 |
| 492 } // namespace internal | 559 } // namespace internal |
| 493 } // namespace webrtc | 560 } // namespace webrtc |
| OLD | NEW |