| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
| 5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
| 6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
| 7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
| 8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
| 9 */ | 9 */ |
| 10 | 10 |
| 11 #include <string.h> | 11 #include <string.h> |
| 12 | 12 |
| 13 #include <map> | 13 #include <map> |
| 14 #include <vector> | 14 #include <vector> |
| 15 | 15 |
| 16 #include "webrtc/audio/audio_receive_stream.h" | 16 #include "webrtc/audio/audio_receive_stream.h" |
| 17 #include "webrtc/audio/audio_send_stream.h" | 17 #include "webrtc/audio/audio_send_stream.h" |
| 18 #include "webrtc/base/checks.h" | 18 #include "webrtc/base/checks.h" |
| 19 #include "webrtc/base/scoped_ptr.h" | 19 #include "webrtc/base/scoped_ptr.h" |
| 20 #include "webrtc/base/thread_annotations.h" | 20 #include "webrtc/base/thread_annotations.h" |
| 21 #include "webrtc/base/thread_checker.h" |
| 21 #include "webrtc/call.h" | 22 #include "webrtc/call.h" |
| 22 #include "webrtc/call/rtc_event_log.h" | 23 #include "webrtc/call/rtc_event_log.h" |
| 23 #include "webrtc/common.h" | 24 #include "webrtc/common.h" |
| 24 #include "webrtc/config.h" | 25 #include "webrtc/config.h" |
| 25 #include "webrtc/modules/rtp_rtcp/interface/rtp_header_parser.h" | 26 #include "webrtc/modules/rtp_rtcp/interface/rtp_header_parser.h" |
| 26 #include "webrtc/modules/rtp_rtcp/source/byte_io.h" | 27 #include "webrtc/modules/rtp_rtcp/source/byte_io.h" |
| 27 #include "webrtc/modules/utility/interface/process_thread.h" | 28 #include "webrtc/modules/utility/interface/process_thread.h" |
| 28 #include "webrtc/system_wrappers/interface/cpu_info.h" | 29 #include "webrtc/system_wrappers/interface/cpu_info.h" |
| 29 #include "webrtc/system_wrappers/interface/critical_section_wrapper.h" | 30 #include "webrtc/system_wrappers/interface/critical_section_wrapper.h" |
| 30 #include "webrtc/system_wrappers/interface/logging.h" | 31 #include "webrtc/system_wrappers/interface/logging.h" |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 89 const PacketTime& packet_time); | 90 const PacketTime& packet_time); |
| 90 | 91 |
| 91 void ConfigureSync(const std::string& sync_group) | 92 void ConfigureSync(const std::string& sync_group) |
| 92 EXCLUSIVE_LOCKS_REQUIRED(receive_crit_); | 93 EXCLUSIVE_LOCKS_REQUIRED(receive_crit_); |
| 93 | 94 |
| 94 const int num_cpu_cores_; | 95 const int num_cpu_cores_; |
| 95 const rtc::scoped_ptr<ProcessThread> module_process_thread_; | 96 const rtc::scoped_ptr<ProcessThread> module_process_thread_; |
| 96 const rtc::scoped_ptr<ChannelGroup> channel_group_; | 97 const rtc::scoped_ptr<ChannelGroup> channel_group_; |
| 97 volatile int next_channel_id_; | 98 volatile int next_channel_id_; |
| 98 Call::Config config_; | 99 Call::Config config_; |
| 100 rtc::ThreadChecker configuration_thread_checker_; |
| 99 | 101 |
| 100 // Needs to be held while write-locking |receive_crit_| or |send_crit_|. This | 102 // Needs to be held while write-locking |receive_crit_| or |send_crit_|. This |
| 101 // ensures that we have a consistent network state signalled to all senders | 103 // ensures that we have a consistent network state signalled to all senders |
| 102 // and receivers. | 104 // and receivers. |
| 103 rtc::CriticalSection network_enabled_crit_; | 105 rtc::CriticalSection network_enabled_crit_; |
| 104 bool network_enabled_ GUARDED_BY(network_enabled_crit_); | 106 bool network_enabled_ GUARDED_BY(network_enabled_crit_); |
| 105 | 107 |
| 106 rtc::scoped_ptr<RWLockWrapper> receive_crit_; | 108 rtc::scoped_ptr<RWLockWrapper> receive_crit_; |
| 107 // Audio and Video receive streams are owned by the client that creates them. | 109 // Audio and Video receive streams are owned by the client that creates them. |
| 108 std::map<uint32_t, AudioReceiveStream*> audio_receive_ssrcs_ | 110 std::map<uint32_t, AudioReceiveStream*> audio_receive_ssrcs_ |
| (...skipping 28 matching lines...) Expand all Loading... |
| 137 Call::Call(const Call::Config& config) | 139 Call::Call(const Call::Config& config) |
| 138 : num_cpu_cores_(CpuInfo::DetectNumberOfCores()), | 140 : num_cpu_cores_(CpuInfo::DetectNumberOfCores()), |
| 139 module_process_thread_(ProcessThread::Create("ModuleProcessThread")), | 141 module_process_thread_(ProcessThread::Create("ModuleProcessThread")), |
| 140 channel_group_(new ChannelGroup(module_process_thread_.get())), | 142 channel_group_(new ChannelGroup(module_process_thread_.get())), |
| 141 next_channel_id_(0), | 143 next_channel_id_(0), |
| 142 config_(config), | 144 config_(config), |
| 143 network_enabled_(true), | 145 network_enabled_(true), |
| 144 receive_crit_(RWLockWrapper::CreateRWLock()), | 146 receive_crit_(RWLockWrapper::CreateRWLock()), |
| 145 send_crit_(RWLockWrapper::CreateRWLock()), | 147 send_crit_(RWLockWrapper::CreateRWLock()), |
| 146 event_log_(nullptr) { | 148 event_log_(nullptr) { |
| 149 RTC_DCHECK(configuration_thread_checker_.CalledOnValidThread()); |
| 147 RTC_DCHECK_GE(config.bitrate_config.min_bitrate_bps, 0); | 150 RTC_DCHECK_GE(config.bitrate_config.min_bitrate_bps, 0); |
| 148 RTC_DCHECK_GE(config.bitrate_config.start_bitrate_bps, | 151 RTC_DCHECK_GE(config.bitrate_config.start_bitrate_bps, |
| 149 config.bitrate_config.min_bitrate_bps); | 152 config.bitrate_config.min_bitrate_bps); |
| 150 if (config.bitrate_config.max_bitrate_bps != -1) { | 153 if (config.bitrate_config.max_bitrate_bps != -1) { |
| 151 RTC_DCHECK_GE(config.bitrate_config.max_bitrate_bps, | 154 RTC_DCHECK_GE(config.bitrate_config.max_bitrate_bps, |
| 152 config.bitrate_config.start_bitrate_bps); | 155 config.bitrate_config.start_bitrate_bps); |
| 153 } | 156 } |
| 154 if (config.voice_engine) { | 157 if (config.voice_engine) { |
| 155 VoECodec* voe_codec = VoECodec::GetInterface(config.voice_engine); | 158 VoECodec* voe_codec = VoECodec::GetInterface(config.voice_engine); |
| 156 if (voe_codec) { | 159 if (voe_codec) { |
| 157 event_log_ = voe_codec->GetEventLog(); | 160 event_log_ = voe_codec->GetEventLog(); |
| 158 voe_codec->Release(); | 161 voe_codec->Release(); |
| 159 } | 162 } |
| 160 } | 163 } |
| 161 | 164 |
| 162 Trace::CreateTrace(); | 165 Trace::CreateTrace(); |
| 163 module_process_thread_->Start(); | 166 module_process_thread_->Start(); |
| 164 | 167 |
| 165 channel_group_->SetBweBitrates(config_.bitrate_config.min_bitrate_bps, | 168 channel_group_->SetBweBitrates(config_.bitrate_config.min_bitrate_bps, |
| 166 config_.bitrate_config.start_bitrate_bps, | 169 config_.bitrate_config.start_bitrate_bps, |
| 167 config_.bitrate_config.max_bitrate_bps); | 170 config_.bitrate_config.max_bitrate_bps); |
| 168 } | 171 } |
| 169 | 172 |
| 170 Call::~Call() { | 173 Call::~Call() { |
| 174 RTC_DCHECK(configuration_thread_checker_.CalledOnValidThread()); |
| 171 RTC_CHECK(audio_send_ssrcs_.empty()); | 175 RTC_CHECK(audio_send_ssrcs_.empty()); |
| 172 RTC_CHECK(video_send_ssrcs_.empty()); | 176 RTC_CHECK(video_send_ssrcs_.empty()); |
| 173 RTC_CHECK(video_send_streams_.empty()); | 177 RTC_CHECK(video_send_streams_.empty()); |
| 174 RTC_CHECK(audio_receive_ssrcs_.empty()); | 178 RTC_CHECK(audio_receive_ssrcs_.empty()); |
| 175 RTC_CHECK(video_receive_ssrcs_.empty()); | 179 RTC_CHECK(video_receive_ssrcs_.empty()); |
| 176 RTC_CHECK(video_receive_streams_.empty()); | 180 RTC_CHECK(video_receive_streams_.empty()); |
| 177 | 181 |
| 178 module_process_thread_->Stop(); | 182 module_process_thread_->Stop(); |
| 179 Trace::ReturnTrace(); | 183 Trace::ReturnTrace(); |
| 180 } | 184 } |
| 181 | 185 |
| 182 PacketReceiver* Call::Receiver() { return this; } | 186 PacketReceiver* Call::Receiver() { |
| 187 // TODO(solenberg): Some test cases in EndToEndTest use this from a different |
| 188 // thread. Re-enable once that is fixed. |
| 189 // RTC_DCHECK(configuration_thread_checker_.CalledOnValidThread()); |
| 190 return this; |
| 191 } |
| 183 | 192 |
| 184 webrtc::AudioSendStream* Call::CreateAudioSendStream( | 193 webrtc::AudioSendStream* Call::CreateAudioSendStream( |
| 185 const webrtc::AudioSendStream::Config& config) { | 194 const webrtc::AudioSendStream::Config& config) { |
| 186 TRACE_EVENT0("webrtc", "Call::CreateAudioSendStream"); | 195 TRACE_EVENT0("webrtc", "Call::CreateAudioSendStream"); |
| 196 RTC_DCHECK(configuration_thread_checker_.CalledOnValidThread()); |
| 187 AudioSendStream* send_stream = new AudioSendStream(config); | 197 AudioSendStream* send_stream = new AudioSendStream(config); |
| 188 { | 198 { |
| 189 rtc::CritScope lock(&network_enabled_crit_); | 199 rtc::CritScope lock(&network_enabled_crit_); |
| 190 WriteLockScoped write_lock(*send_crit_); | 200 WriteLockScoped write_lock(*send_crit_); |
| 191 RTC_DCHECK(audio_send_ssrcs_.find(config.rtp.ssrc) == | 201 RTC_DCHECK(audio_send_ssrcs_.find(config.rtp.ssrc) == |
| 192 audio_send_ssrcs_.end()); | 202 audio_send_ssrcs_.end()); |
| 193 audio_send_ssrcs_[config.rtp.ssrc] = send_stream; | 203 audio_send_ssrcs_[config.rtp.ssrc] = send_stream; |
| 194 | 204 |
| 195 if (!network_enabled_) | 205 if (!network_enabled_) |
| 196 send_stream->SignalNetworkState(kNetworkDown); | 206 send_stream->SignalNetworkState(kNetworkDown); |
| 197 } | 207 } |
| 198 return send_stream; | 208 return send_stream; |
| 199 } | 209 } |
| 200 | 210 |
| 201 void Call::DestroyAudioSendStream(webrtc::AudioSendStream* send_stream) { | 211 void Call::DestroyAudioSendStream(webrtc::AudioSendStream* send_stream) { |
| 202 TRACE_EVENT0("webrtc", "Call::DestroyAudioSendStream"); | 212 TRACE_EVENT0("webrtc", "Call::DestroyAudioSendStream"); |
| 213 RTC_DCHECK(configuration_thread_checker_.CalledOnValidThread()); |
| 203 RTC_DCHECK(send_stream != nullptr); | 214 RTC_DCHECK(send_stream != nullptr); |
| 204 | 215 |
| 205 send_stream->Stop(); | 216 send_stream->Stop(); |
| 206 | 217 |
| 207 webrtc::internal::AudioSendStream* audio_send_stream = | 218 webrtc::internal::AudioSendStream* audio_send_stream = |
| 208 static_cast<webrtc::internal::AudioSendStream*>(send_stream); | 219 static_cast<webrtc::internal::AudioSendStream*>(send_stream); |
| 209 { | 220 { |
| 210 WriteLockScoped write_lock(*send_crit_); | 221 WriteLockScoped write_lock(*send_crit_); |
| 211 size_t num_deleted = audio_send_ssrcs_.erase( | 222 size_t num_deleted = audio_send_ssrcs_.erase( |
| 212 audio_send_stream->config().rtp.ssrc); | 223 audio_send_stream->config().rtp.ssrc); |
| 213 RTC_DCHECK(num_deleted == 1); | 224 RTC_DCHECK(num_deleted == 1); |
| 214 } | 225 } |
| 215 delete audio_send_stream; | 226 delete audio_send_stream; |
| 216 } | 227 } |
| 217 | 228 |
| 218 webrtc::AudioReceiveStream* Call::CreateAudioReceiveStream( | 229 webrtc::AudioReceiveStream* Call::CreateAudioReceiveStream( |
| 219 const webrtc::AudioReceiveStream::Config& config) { | 230 const webrtc::AudioReceiveStream::Config& config) { |
| 220 TRACE_EVENT0("webrtc", "Call::CreateAudioReceiveStream"); | 231 TRACE_EVENT0("webrtc", "Call::CreateAudioReceiveStream"); |
| 232 RTC_DCHECK(configuration_thread_checker_.CalledOnValidThread()); |
| 221 AudioReceiveStream* receive_stream = new AudioReceiveStream( | 233 AudioReceiveStream* receive_stream = new AudioReceiveStream( |
| 222 channel_group_->GetRemoteBitrateEstimator(false), config); | 234 channel_group_->GetRemoteBitrateEstimator(false), config); |
| 223 { | 235 { |
| 224 WriteLockScoped write_lock(*receive_crit_); | 236 WriteLockScoped write_lock(*receive_crit_); |
| 225 RTC_DCHECK(audio_receive_ssrcs_.find(config.rtp.remote_ssrc) == | 237 RTC_DCHECK(audio_receive_ssrcs_.find(config.rtp.remote_ssrc) == |
| 226 audio_receive_ssrcs_.end()); | 238 audio_receive_ssrcs_.end()); |
| 227 audio_receive_ssrcs_[config.rtp.remote_ssrc] = receive_stream; | 239 audio_receive_ssrcs_[config.rtp.remote_ssrc] = receive_stream; |
| 228 ConfigureSync(config.sync_group); | 240 ConfigureSync(config.sync_group); |
| 229 } | 241 } |
| 230 return receive_stream; | 242 return receive_stream; |
| 231 } | 243 } |
| 232 | 244 |
| 233 void Call::DestroyAudioReceiveStream( | 245 void Call::DestroyAudioReceiveStream( |
| 234 webrtc::AudioReceiveStream* receive_stream) { | 246 webrtc::AudioReceiveStream* receive_stream) { |
| 235 TRACE_EVENT0("webrtc", "Call::DestroyAudioReceiveStream"); | 247 TRACE_EVENT0("webrtc", "Call::DestroyAudioReceiveStream"); |
| 248 RTC_DCHECK(configuration_thread_checker_.CalledOnValidThread()); |
| 236 RTC_DCHECK(receive_stream != nullptr); | 249 RTC_DCHECK(receive_stream != nullptr); |
| 237 webrtc::internal::AudioReceiveStream* audio_receive_stream = | 250 webrtc::internal::AudioReceiveStream* audio_receive_stream = |
| 238 static_cast<webrtc::internal::AudioReceiveStream*>(receive_stream); | 251 static_cast<webrtc::internal::AudioReceiveStream*>(receive_stream); |
| 239 { | 252 { |
| 240 WriteLockScoped write_lock(*receive_crit_); | 253 WriteLockScoped write_lock(*receive_crit_); |
| 241 size_t num_deleted = audio_receive_ssrcs_.erase( | 254 size_t num_deleted = audio_receive_ssrcs_.erase( |
| 242 audio_receive_stream->config().rtp.remote_ssrc); | 255 audio_receive_stream->config().rtp.remote_ssrc); |
| 243 RTC_DCHECK(num_deleted == 1); | 256 RTC_DCHECK(num_deleted == 1); |
| 244 const std::string& sync_group = audio_receive_stream->config().sync_group; | 257 const std::string& sync_group = audio_receive_stream->config().sync_group; |
| 245 const auto it = sync_stream_mapping_.find(sync_group); | 258 const auto it = sync_stream_mapping_.find(sync_group); |
| 246 if (it != sync_stream_mapping_.end() && | 259 if (it != sync_stream_mapping_.end() && |
| 247 it->second == audio_receive_stream) { | 260 it->second == audio_receive_stream) { |
| 248 sync_stream_mapping_.erase(it); | 261 sync_stream_mapping_.erase(it); |
| 249 ConfigureSync(sync_group); | 262 ConfigureSync(sync_group); |
| 250 } | 263 } |
| 251 } | 264 } |
| 252 delete audio_receive_stream; | 265 delete audio_receive_stream; |
| 253 } | 266 } |
| 254 | 267 |
| 255 webrtc::VideoSendStream* Call::CreateVideoSendStream( | 268 webrtc::VideoSendStream* Call::CreateVideoSendStream( |
| 256 const webrtc::VideoSendStream::Config& config, | 269 const webrtc::VideoSendStream::Config& config, |
| 257 const VideoEncoderConfig& encoder_config) { | 270 const VideoEncoderConfig& encoder_config) { |
| 258 TRACE_EVENT0("webrtc", "Call::CreateVideoSendStream"); | 271 TRACE_EVENT0("webrtc", "Call::CreateVideoSendStream"); |
| 272 RTC_DCHECK(configuration_thread_checker_.CalledOnValidThread()); |
| 259 | 273 |
| 260 // TODO(mflodman): Base the start bitrate on a current bandwidth estimate, if | 274 // TODO(mflodman): Base the start bitrate on a current bandwidth estimate, if |
| 261 // the call has already started. | 275 // the call has already started. |
| 262 VideoSendStream* send_stream = new VideoSendStream(num_cpu_cores_, | 276 VideoSendStream* send_stream = new VideoSendStream(num_cpu_cores_, |
| 263 module_process_thread_.get(), channel_group_.get(), | 277 module_process_thread_.get(), channel_group_.get(), |
| 264 rtc::AtomicOps::Increment(&next_channel_id_), config, encoder_config, | 278 rtc::AtomicOps::Increment(&next_channel_id_), config, encoder_config, |
| 265 suspended_video_send_ssrcs_); | 279 suspended_video_send_ssrcs_); |
| 266 | 280 |
| 267 // This needs to be taken before send_crit_ as both locks need to be held | 281 // This needs to be taken before send_crit_ as both locks need to be held |
| 268 // while changing network state. | 282 // while changing network state. |
| 269 rtc::CritScope lock(&network_enabled_crit_); | 283 rtc::CritScope lock(&network_enabled_crit_); |
| 270 WriteLockScoped write_lock(*send_crit_); | 284 WriteLockScoped write_lock(*send_crit_); |
| 271 for (uint32_t ssrc : config.rtp.ssrcs) { | 285 for (uint32_t ssrc : config.rtp.ssrcs) { |
| 272 RTC_DCHECK(video_send_ssrcs_.find(ssrc) == video_send_ssrcs_.end()); | 286 RTC_DCHECK(video_send_ssrcs_.find(ssrc) == video_send_ssrcs_.end()); |
| 273 video_send_ssrcs_[ssrc] = send_stream; | 287 video_send_ssrcs_[ssrc] = send_stream; |
| 274 } | 288 } |
| 275 video_send_streams_.insert(send_stream); | 289 video_send_streams_.insert(send_stream); |
| 276 | 290 |
| 277 if (event_log_) | 291 if (event_log_) |
| 278 event_log_->LogVideoSendStreamConfig(config); | 292 event_log_->LogVideoSendStreamConfig(config); |
| 279 | 293 |
| 280 if (!network_enabled_) | 294 if (!network_enabled_) |
| 281 send_stream->SignalNetworkState(kNetworkDown); | 295 send_stream->SignalNetworkState(kNetworkDown); |
| 282 return send_stream; | 296 return send_stream; |
| 283 } | 297 } |
| 284 | 298 |
| 285 void Call::DestroyVideoSendStream(webrtc::VideoSendStream* send_stream) { | 299 void Call::DestroyVideoSendStream(webrtc::VideoSendStream* send_stream) { |
| 286 TRACE_EVENT0("webrtc", "Call::DestroyVideoSendStream"); | 300 TRACE_EVENT0("webrtc", "Call::DestroyVideoSendStream"); |
| 287 RTC_DCHECK(send_stream != nullptr); | 301 RTC_DCHECK(send_stream != nullptr); |
| 302 RTC_DCHECK(configuration_thread_checker_.CalledOnValidThread()); |
| 288 | 303 |
| 289 send_stream->Stop(); | 304 send_stream->Stop(); |
| 290 | 305 |
| 291 VideoSendStream* send_stream_impl = nullptr; | 306 VideoSendStream* send_stream_impl = nullptr; |
| 292 { | 307 { |
| 293 WriteLockScoped write_lock(*send_crit_); | 308 WriteLockScoped write_lock(*send_crit_); |
| 294 auto it = video_send_ssrcs_.begin(); | 309 auto it = video_send_ssrcs_.begin(); |
| 295 while (it != video_send_ssrcs_.end()) { | 310 while (it != video_send_ssrcs_.end()) { |
| 296 if (it->second == static_cast<VideoSendStream*>(send_stream)) { | 311 if (it->second == static_cast<VideoSendStream*>(send_stream)) { |
| 297 send_stream_impl = it->second; | 312 send_stream_impl = it->second; |
| (...skipping 13 matching lines...) Expand all Loading... |
| 311 ++it) { | 326 ++it) { |
| 312 suspended_video_send_ssrcs_[it->first] = it->second; | 327 suspended_video_send_ssrcs_[it->first] = it->second; |
| 313 } | 328 } |
| 314 | 329 |
| 315 delete send_stream_impl; | 330 delete send_stream_impl; |
| 316 } | 331 } |
| 317 | 332 |
| 318 webrtc::VideoReceiveStream* Call::CreateVideoReceiveStream( | 333 webrtc::VideoReceiveStream* Call::CreateVideoReceiveStream( |
| 319 const webrtc::VideoReceiveStream::Config& config) { | 334 const webrtc::VideoReceiveStream::Config& config) { |
| 320 TRACE_EVENT0("webrtc", "Call::CreateVideoReceiveStream"); | 335 TRACE_EVENT0("webrtc", "Call::CreateVideoReceiveStream"); |
| 336 RTC_DCHECK(configuration_thread_checker_.CalledOnValidThread()); |
| 321 VideoReceiveStream* receive_stream = new VideoReceiveStream( | 337 VideoReceiveStream* receive_stream = new VideoReceiveStream( |
| 322 num_cpu_cores_, channel_group_.get(), | 338 num_cpu_cores_, channel_group_.get(), |
| 323 rtc::AtomicOps::Increment(&next_channel_id_), config, | 339 rtc::AtomicOps::Increment(&next_channel_id_), config, |
| 324 config_.voice_engine, module_process_thread_.get()); | 340 config_.voice_engine, module_process_thread_.get()); |
| 325 | 341 |
| 326 // This needs to be taken before receive_crit_ as both locks need to be held | 342 // This needs to be taken before receive_crit_ as both locks need to be held |
| 327 // while changing network state. | 343 // while changing network state. |
| 328 rtc::CritScope lock(&network_enabled_crit_); | 344 rtc::CritScope lock(&network_enabled_crit_); |
| 329 WriteLockScoped write_lock(*receive_crit_); | 345 WriteLockScoped write_lock(*receive_crit_); |
| 330 RTC_DCHECK(video_receive_ssrcs_.find(config.rtp.remote_ssrc) == | 346 RTC_DCHECK(video_receive_ssrcs_.find(config.rtp.remote_ssrc) == |
| (...skipping 13 matching lines...) Expand all Loading... |
| 344 | 360 |
| 345 if (event_log_) | 361 if (event_log_) |
| 346 event_log_->LogVideoReceiveStreamConfig(config); | 362 event_log_->LogVideoReceiveStreamConfig(config); |
| 347 | 363 |
| 348 return receive_stream; | 364 return receive_stream; |
| 349 } | 365 } |
| 350 | 366 |
| 351 void Call::DestroyVideoReceiveStream( | 367 void Call::DestroyVideoReceiveStream( |
| 352 webrtc::VideoReceiveStream* receive_stream) { | 368 webrtc::VideoReceiveStream* receive_stream) { |
| 353 TRACE_EVENT0("webrtc", "Call::DestroyVideoReceiveStream"); | 369 TRACE_EVENT0("webrtc", "Call::DestroyVideoReceiveStream"); |
| 370 RTC_DCHECK(configuration_thread_checker_.CalledOnValidThread()); |
| 354 RTC_DCHECK(receive_stream != nullptr); | 371 RTC_DCHECK(receive_stream != nullptr); |
| 355 VideoReceiveStream* receive_stream_impl = nullptr; | 372 VideoReceiveStream* receive_stream_impl = nullptr; |
| 356 { | 373 { |
| 357 WriteLockScoped write_lock(*receive_crit_); | 374 WriteLockScoped write_lock(*receive_crit_); |
| 358 // Remove all ssrcs pointing to a receive stream. As RTX retransmits on a | 375 // Remove all ssrcs pointing to a receive stream. As RTX retransmits on a |
| 359 // separate SSRC there can be either one or two. | 376 // separate SSRC there can be either one or two. |
| 360 auto it = video_receive_ssrcs_.begin(); | 377 auto it = video_receive_ssrcs_.begin(); |
| 361 while (it != video_receive_ssrcs_.end()) { | 378 while (it != video_receive_ssrcs_.end()) { |
| 362 if (it->second == static_cast<VideoReceiveStream*>(receive_stream)) { | 379 if (it->second == static_cast<VideoReceiveStream*>(receive_stream)) { |
| 363 if (receive_stream_impl != nullptr) | 380 if (receive_stream_impl != nullptr) |
| 364 RTC_DCHECK(receive_stream_impl == it->second); | 381 RTC_DCHECK(receive_stream_impl == it->second); |
| 365 receive_stream_impl = it->second; | 382 receive_stream_impl = it->second; |
| 366 video_receive_ssrcs_.erase(it++); | 383 video_receive_ssrcs_.erase(it++); |
| 367 } else { | 384 } else { |
| 368 ++it; | 385 ++it; |
| 369 } | 386 } |
| 370 } | 387 } |
| 371 video_receive_streams_.erase(receive_stream_impl); | 388 video_receive_streams_.erase(receive_stream_impl); |
| 372 RTC_CHECK(receive_stream_impl != nullptr); | 389 RTC_CHECK(receive_stream_impl != nullptr); |
| 373 ConfigureSync(receive_stream_impl->config().sync_group); | 390 ConfigureSync(receive_stream_impl->config().sync_group); |
| 374 } | 391 } |
| 375 delete receive_stream_impl; | 392 delete receive_stream_impl; |
| 376 } | 393 } |
| 377 | 394 |
| 378 Call::Stats Call::GetStats() const { | 395 Call::Stats Call::GetStats() const { |
| 396 // TODO(solenberg): Some test cases in EndToEndTest use this from a different |
| 397 // thread. Re-enable once that is fixed. |
| 398 // RTC_DCHECK(configuration_thread_checker_.CalledOnValidThread()); |
| 379 Stats stats; | 399 Stats stats; |
| 380 // Fetch available send/receive bitrates. | 400 // Fetch available send/receive bitrates. |
| 381 uint32_t send_bandwidth = 0; | 401 uint32_t send_bandwidth = 0; |
| 382 channel_group_->GetBitrateController()->AvailableBandwidth(&send_bandwidth); | 402 channel_group_->GetBitrateController()->AvailableBandwidth(&send_bandwidth); |
| 383 std::vector<unsigned int> ssrcs; | 403 std::vector<unsigned int> ssrcs; |
| 384 uint32_t recv_bandwidth = 0; | 404 uint32_t recv_bandwidth = 0; |
| 385 channel_group_->GetRemoteBitrateEstimator(false)->LatestEstimate( | 405 channel_group_->GetRemoteBitrateEstimator(false)->LatestEstimate( |
| 386 &ssrcs, &recv_bandwidth); | 406 &ssrcs, &recv_bandwidth); |
| 387 stats.send_bandwidth_bps = send_bandwidth; | 407 stats.send_bandwidth_bps = send_bandwidth; |
| 388 stats.recv_bandwidth_bps = recv_bandwidth; | 408 stats.recv_bandwidth_bps = recv_bandwidth; |
| 389 stats.pacer_delay_ms = channel_group_->GetPacerQueuingDelayMs(); | 409 stats.pacer_delay_ms = channel_group_->GetPacerQueuingDelayMs(); |
| 390 { | 410 { |
| 391 ReadLockScoped read_lock(*send_crit_); | 411 ReadLockScoped read_lock(*send_crit_); |
| 392 // TODO(solenberg): Add audio send streams. | 412 // TODO(solenberg): Add audio send streams. |
| 393 for (const auto& kv : video_send_ssrcs_) { | 413 for (const auto& kv : video_send_ssrcs_) { |
| 394 int rtt_ms = kv.second->GetRtt(); | 414 int rtt_ms = kv.second->GetRtt(); |
| 395 if (rtt_ms > 0) | 415 if (rtt_ms > 0) |
| 396 stats.rtt_ms = rtt_ms; | 416 stats.rtt_ms = rtt_ms; |
| 397 } | 417 } |
| 398 } | 418 } |
| 399 return stats; | 419 return stats; |
| 400 } | 420 } |
| 401 | 421 |
| 402 void Call::SetBitrateConfig( | 422 void Call::SetBitrateConfig( |
| 403 const webrtc::Call::Config::BitrateConfig& bitrate_config) { | 423 const webrtc::Call::Config::BitrateConfig& bitrate_config) { |
| 404 TRACE_EVENT0("webrtc", "Call::SetBitrateConfig"); | 424 TRACE_EVENT0("webrtc", "Call::SetBitrateConfig"); |
| 425 RTC_DCHECK(configuration_thread_checker_.CalledOnValidThread()); |
| 405 RTC_DCHECK_GE(bitrate_config.min_bitrate_bps, 0); | 426 RTC_DCHECK_GE(bitrate_config.min_bitrate_bps, 0); |
| 406 if (bitrate_config.max_bitrate_bps != -1) | 427 if (bitrate_config.max_bitrate_bps != -1) |
| 407 RTC_DCHECK_GT(bitrate_config.max_bitrate_bps, 0); | 428 RTC_DCHECK_GT(bitrate_config.max_bitrate_bps, 0); |
| 408 if (config_.bitrate_config.min_bitrate_bps == | 429 if (config_.bitrate_config.min_bitrate_bps == |
| 409 bitrate_config.min_bitrate_bps && | 430 bitrate_config.min_bitrate_bps && |
| 410 (bitrate_config.start_bitrate_bps <= 0 || | 431 (bitrate_config.start_bitrate_bps <= 0 || |
| 411 config_.bitrate_config.start_bitrate_bps == | 432 config_.bitrate_config.start_bitrate_bps == |
| 412 bitrate_config.start_bitrate_bps) && | 433 bitrate_config.start_bitrate_bps) && |
| 413 config_.bitrate_config.max_bitrate_bps == | 434 config_.bitrate_config.max_bitrate_bps == |
| 414 bitrate_config.max_bitrate_bps) { | 435 bitrate_config.max_bitrate_bps) { |
| 415 // Nothing new to set, early abort to avoid encoder reconfigurations. | 436 // Nothing new to set, early abort to avoid encoder reconfigurations. |
| 416 return; | 437 return; |
| 417 } | 438 } |
| 418 config_.bitrate_config = bitrate_config; | 439 config_.bitrate_config = bitrate_config; |
| 419 channel_group_->SetBweBitrates(bitrate_config.min_bitrate_bps, | 440 channel_group_->SetBweBitrates(bitrate_config.min_bitrate_bps, |
| 420 bitrate_config.start_bitrate_bps, | 441 bitrate_config.start_bitrate_bps, |
| 421 bitrate_config.max_bitrate_bps); | 442 bitrate_config.max_bitrate_bps); |
| 422 } | 443 } |
| 423 | 444 |
| 424 void Call::SignalNetworkState(NetworkState state) { | 445 void Call::SignalNetworkState(NetworkState state) { |
| 446 RTC_DCHECK(configuration_thread_checker_.CalledOnValidThread()); |
| 425 // Take crit for entire function, it needs to be held while updating streams | 447 // Take crit for entire function, it needs to be held while updating streams |
| 426 // to guarantee a consistent state across streams. | 448 // to guarantee a consistent state across streams. |
| 427 rtc::CritScope lock(&network_enabled_crit_); | 449 rtc::CritScope lock(&network_enabled_crit_); |
| 428 network_enabled_ = state == kNetworkUp; | 450 network_enabled_ = state == kNetworkUp; |
| 429 channel_group_->SignalNetworkState(state); | 451 channel_group_->SignalNetworkState(state); |
| 430 { | 452 { |
| 431 ReadLockScoped write_lock(*send_crit_); | 453 ReadLockScoped write_lock(*send_crit_); |
| 432 for (auto& kv : audio_send_ssrcs_) { | 454 for (auto& kv : audio_send_ssrcs_) { |
| 433 kv.second->SignalNetworkState(state); | 455 kv.second->SignalNetworkState(state); |
| 434 } | 456 } |
| 435 for (auto& kv : video_send_ssrcs_) { | 457 for (auto& kv : video_send_ssrcs_) { |
| 436 kv.second->SignalNetworkState(state); | 458 kv.second->SignalNetworkState(state); |
| 437 } | 459 } |
| 438 } | 460 } |
| 439 { | 461 { |
| 440 ReadLockScoped write_lock(*receive_crit_); | 462 ReadLockScoped write_lock(*receive_crit_); |
| 441 for (auto& kv : video_receive_ssrcs_) { | 463 for (auto& kv : video_receive_ssrcs_) { |
| 442 kv.second->SignalNetworkState(state); | 464 kv.second->SignalNetworkState(state); |
| 443 } | 465 } |
| 444 } | 466 } |
| 445 } | 467 } |
| 446 | 468 |
| 447 void Call::OnSentPacket(const rtc::SentPacket& sent_packet) { | 469 void Call::OnSentPacket(const rtc::SentPacket& sent_packet) { |
| 470 RTC_DCHECK(configuration_thread_checker_.CalledOnValidThread()); |
| 448 channel_group_->OnSentPacket(sent_packet); | 471 channel_group_->OnSentPacket(sent_packet); |
| 449 } | 472 } |
| 450 | 473 |
| 451 void Call::ConfigureSync(const std::string& sync_group) { | 474 void Call::ConfigureSync(const std::string& sync_group) { |
| 452 // Set sync only if there was no previous one. | 475 // Set sync only if there was no previous one. |
| 453 if (config_.voice_engine == nullptr || sync_group.empty()) | 476 if (config_.voice_engine == nullptr || sync_group.empty()) |
| 454 return; | 477 return; |
| 455 | 478 |
| 456 AudioReceiveStream* sync_audio_stream = nullptr; | 479 AudioReceiveStream* sync_audio_stream = nullptr; |
| 457 // Find existing audio stream. | 480 // Find existing audio stream. |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 561 } | 584 } |
| 562 } | 585 } |
| 563 return DELIVERY_UNKNOWN_SSRC; | 586 return DELIVERY_UNKNOWN_SSRC; |
| 564 } | 587 } |
| 565 | 588 |
| 566 PacketReceiver::DeliveryStatus Call::DeliverPacket( | 589 PacketReceiver::DeliveryStatus Call::DeliverPacket( |
| 567 MediaType media_type, | 590 MediaType media_type, |
| 568 const uint8_t* packet, | 591 const uint8_t* packet, |
| 569 size_t length, | 592 size_t length, |
| 570 const PacketTime& packet_time) { | 593 const PacketTime& packet_time) { |
| 594 // TODO(solenberg): Tests call this function on a network thread, libjingle |
| 595 // calls on the worker thread. We should move towards always using a network |
| 596 // thread. Then this check can be enabled. |
| 597 // RTC_DCHECK(!configuration_thread_checker_.CalledOnValidThread()); |
| 571 if (RtpHeaderParser::IsRtcp(packet, length)) | 598 if (RtpHeaderParser::IsRtcp(packet, length)) |
| 572 return DeliverRtcp(media_type, packet, length); | 599 return DeliverRtcp(media_type, packet, length); |
| 573 | 600 |
| 574 return DeliverRtp(media_type, packet, length, packet_time); | 601 return DeliverRtp(media_type, packet, length, packet_time); |
| 575 } | 602 } |
| 576 | 603 |
| 577 } // namespace internal | 604 } // namespace internal |
| 578 } // namespace webrtc | 605 } // namespace webrtc |
| OLD | NEW |