| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2004 The WebRTC project authors. All Rights Reserved. | 2 * Copyright 2004 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 "webrtc/pc/channelmanager.h" | 11 #include "webrtc/pc/channelmanager.h" |
| 12 | 12 |
| 13 #include <algorithm> | 13 #include <algorithm> |
| 14 | 14 |
| 15 #include "webrtc/api/mediacontroller.h" | 15 #include "webrtc/api/mediacontroller.h" |
| 16 #include "webrtc/base/bind.h" | 16 #include "webrtc/base/bind.h" |
| 17 #include "webrtc/base/checks.h" |
| 17 #include "webrtc/base/common.h" | 18 #include "webrtc/base/common.h" |
| 18 #include "webrtc/base/logging.h" | 19 #include "webrtc/base/logging.h" |
| 19 #include "webrtc/base/stringencode.h" | 20 #include "webrtc/base/stringencode.h" |
| 20 #include "webrtc/base/stringutils.h" | 21 #include "webrtc/base/stringutils.h" |
| 21 #include "webrtc/base/trace_event.h" | 22 #include "webrtc/base/trace_event.h" |
| 22 #include "webrtc/media/base/device.h" | 23 #include "webrtc/media/base/device.h" |
| 23 #include "webrtc/media/base/rtpdataengine.h" | 24 #include "webrtc/media/base/rtpdataengine.h" |
| 24 #include "webrtc/pc/srtpfilter.h" | 25 #include "webrtc/pc/srtpfilter.h" |
| 25 | 26 |
| 26 namespace cricket { | 27 namespace cricket { |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 147 RtpHeaderExtensions* ext) const { | 148 RtpHeaderExtensions* ext) const { |
| 148 *ext = media_engine_->GetVideoCapabilities().header_extensions; | 149 *ext = media_engine_->GetVideoCapabilities().header_extensions; |
| 149 } | 150 } |
| 150 | 151 |
| 151 void ChannelManager::GetSupportedDataCodecs( | 152 void ChannelManager::GetSupportedDataCodecs( |
| 152 std::vector<DataCodec>* codecs) const { | 153 std::vector<DataCodec>* codecs) const { |
| 153 *codecs = data_media_engine_->data_codecs(); | 154 *codecs = data_media_engine_->data_codecs(); |
| 154 } | 155 } |
| 155 | 156 |
| 156 bool ChannelManager::Init() { | 157 bool ChannelManager::Init() { |
| 157 ASSERT(!initialized_); | 158 RTC_DCHECK(!initialized_); |
| 158 if (initialized_) { | 159 if (initialized_) { |
| 159 return false; | 160 return false; |
| 160 } | 161 } |
| 161 RTC_DCHECK(network_thread_); | 162 RTC_DCHECK(network_thread_); |
| 162 RTC_DCHECK(worker_thread_); | 163 RTC_DCHECK(worker_thread_); |
| 163 if (!network_thread_->IsCurrent()) { | 164 if (!network_thread_->IsCurrent()) { |
| 164 // Do not allow invoking calls to other threads on the network thread. | 165 // Do not allow invoking calls to other threads on the network thread. |
| 165 network_thread_->Invoke<bool>( | 166 network_thread_->Invoke<bool>( |
| 166 RTC_FROM_HERE, | 167 RTC_FROM_HERE, |
| 167 rtc::Bind(&rtc::Thread::SetAllowBlockingCalls, network_thread_, false)); | 168 rtc::Bind(&rtc::Thread::SetAllowBlockingCalls, network_thread_, false)); |
| 168 } | 169 } |
| 169 | 170 |
| 170 initialized_ = worker_thread_->Invoke<bool>( | 171 initialized_ = worker_thread_->Invoke<bool>( |
| 171 RTC_FROM_HERE, Bind(&ChannelManager::InitMediaEngine_w, this)); | 172 RTC_FROM_HERE, Bind(&ChannelManager::InitMediaEngine_w, this)); |
| 172 ASSERT(initialized_); | 173 RTC_DCHECK(initialized_); |
| 173 return initialized_; | 174 return initialized_; |
| 174 } | 175 } |
| 175 | 176 |
| 176 bool ChannelManager::InitMediaEngine_w() { | 177 bool ChannelManager::InitMediaEngine_w() { |
| 177 ASSERT(worker_thread_ == rtc::Thread::Current()); | 178 RTC_DCHECK(worker_thread_ == rtc::Thread::Current()); |
| 178 return media_engine_->Init(); | 179 return media_engine_->Init(); |
| 179 } | 180 } |
| 180 | 181 |
| 181 void ChannelManager::Terminate() { | 182 void ChannelManager::Terminate() { |
| 182 ASSERT(initialized_); | 183 RTC_DCHECK(initialized_); |
| 183 if (!initialized_) { | 184 if (!initialized_) { |
| 184 return; | 185 return; |
| 185 } | 186 } |
| 186 worker_thread_->Invoke<void>(RTC_FROM_HERE, | 187 worker_thread_->Invoke<void>(RTC_FROM_HERE, |
| 187 Bind(&ChannelManager::Terminate_w, this)); | 188 Bind(&ChannelManager::Terminate_w, this)); |
| 188 initialized_ = false; | 189 initialized_ = false; |
| 189 } | 190 } |
| 190 | 191 |
| 191 void ChannelManager::DestructorDeletes_w() { | 192 void ChannelManager::DestructorDeletes_w() { |
| 192 ASSERT(worker_thread_ == rtc::Thread::Current()); | 193 RTC_DCHECK(worker_thread_ == rtc::Thread::Current()); |
| 193 media_engine_.reset(NULL); | 194 media_engine_.reset(NULL); |
| 194 } | 195 } |
| 195 | 196 |
| 196 void ChannelManager::Terminate_w() { | 197 void ChannelManager::Terminate_w() { |
| 197 ASSERT(worker_thread_ == rtc::Thread::Current()); | 198 RTC_DCHECK(worker_thread_ == rtc::Thread::Current()); |
| 198 // Need to destroy the voice/video channels | 199 // Need to destroy the voice/video channels |
| 199 while (!video_channels_.empty()) { | 200 while (!video_channels_.empty()) { |
| 200 DestroyVideoChannel_w(video_channels_.back()); | 201 DestroyVideoChannel_w(video_channels_.back()); |
| 201 } | 202 } |
| 202 while (!voice_channels_.empty()) { | 203 while (!voice_channels_.empty()) { |
| 203 DestroyVoiceChannel_w(voice_channels_.back()); | 204 DestroyVoiceChannel_w(voice_channels_.back()); |
| 204 } | 205 } |
| 205 } | 206 } |
| 206 | 207 |
| 207 VoiceChannel* ChannelManager::CreateVoiceChannel( | 208 VoiceChannel* ChannelManager::CreateVoiceChannel( |
| (...skipping 11 matching lines...) Expand all Loading... |
| 219 } | 220 } |
| 220 | 221 |
| 221 VoiceChannel* ChannelManager::CreateVoiceChannel_w( | 222 VoiceChannel* ChannelManager::CreateVoiceChannel_w( |
| 222 webrtc::MediaControllerInterface* media_controller, | 223 webrtc::MediaControllerInterface* media_controller, |
| 223 TransportController* transport_controller, | 224 TransportController* transport_controller, |
| 224 const std::string& content_name, | 225 const std::string& content_name, |
| 225 const std::string* bundle_transport_name, | 226 const std::string* bundle_transport_name, |
| 226 bool rtcp, | 227 bool rtcp, |
| 227 bool srtp_required, | 228 bool srtp_required, |
| 228 const AudioOptions& options) { | 229 const AudioOptions& options) { |
| 229 ASSERT(initialized_); | 230 RTC_DCHECK(initialized_); |
| 230 ASSERT(worker_thread_ == rtc::Thread::Current()); | 231 RTC_DCHECK(worker_thread_ == rtc::Thread::Current()); |
| 231 ASSERT(nullptr != media_controller); | 232 RTC_DCHECK(nullptr != media_controller); |
| 232 VoiceMediaChannel* media_channel = media_engine_->CreateChannel( | 233 VoiceMediaChannel* media_channel = media_engine_->CreateChannel( |
| 233 media_controller->call_w(), media_controller->config(), options); | 234 media_controller->call_w(), media_controller->config(), options); |
| 234 if (!media_channel) | 235 if (!media_channel) |
| 235 return nullptr; | 236 return nullptr; |
| 236 | 237 |
| 237 VoiceChannel* voice_channel = new VoiceChannel( | 238 VoiceChannel* voice_channel = new VoiceChannel( |
| 238 worker_thread_, network_thread_, media_engine_.get(), media_channel, | 239 worker_thread_, network_thread_, media_engine_.get(), media_channel, |
| 239 transport_controller, content_name, rtcp, srtp_required); | 240 transport_controller, content_name, rtcp, srtp_required); |
| 240 voice_channel->SetCryptoOptions(crypto_options_); | 241 voice_channel->SetCryptoOptions(crypto_options_); |
| 241 if (!voice_channel->Init_w(bundle_transport_name)) { | 242 if (!voice_channel->Init_w(bundle_transport_name)) { |
| 242 delete voice_channel; | 243 delete voice_channel; |
| 243 return nullptr; | 244 return nullptr; |
| 244 } | 245 } |
| 245 voice_channels_.push_back(voice_channel); | 246 voice_channels_.push_back(voice_channel); |
| 246 return voice_channel; | 247 return voice_channel; |
| 247 } | 248 } |
| 248 | 249 |
| 249 void ChannelManager::DestroyVoiceChannel(VoiceChannel* voice_channel) { | 250 void ChannelManager::DestroyVoiceChannel(VoiceChannel* voice_channel) { |
| 250 TRACE_EVENT0("webrtc", "ChannelManager::DestroyVoiceChannel"); | 251 TRACE_EVENT0("webrtc", "ChannelManager::DestroyVoiceChannel"); |
| 251 if (voice_channel) { | 252 if (voice_channel) { |
| 252 worker_thread_->Invoke<void>( | 253 worker_thread_->Invoke<void>( |
| 253 RTC_FROM_HERE, | 254 RTC_FROM_HERE, |
| 254 Bind(&ChannelManager::DestroyVoiceChannel_w, this, voice_channel)); | 255 Bind(&ChannelManager::DestroyVoiceChannel_w, this, voice_channel)); |
| 255 } | 256 } |
| 256 } | 257 } |
| 257 | 258 |
| 258 void ChannelManager::DestroyVoiceChannel_w(VoiceChannel* voice_channel) { | 259 void ChannelManager::DestroyVoiceChannel_w(VoiceChannel* voice_channel) { |
| 259 TRACE_EVENT0("webrtc", "ChannelManager::DestroyVoiceChannel_w"); | 260 TRACE_EVENT0("webrtc", "ChannelManager::DestroyVoiceChannel_w"); |
| 260 // Destroy voice channel. | 261 // Destroy voice channel. |
| 261 ASSERT(initialized_); | 262 RTC_DCHECK(initialized_); |
| 262 ASSERT(worker_thread_ == rtc::Thread::Current()); | 263 RTC_DCHECK(worker_thread_ == rtc::Thread::Current()); |
| 263 VoiceChannels::iterator it = std::find(voice_channels_.begin(), | 264 VoiceChannels::iterator it = std::find(voice_channels_.begin(), |
| 264 voice_channels_.end(), voice_channel); | 265 voice_channels_.end(), voice_channel); |
| 265 ASSERT(it != voice_channels_.end()); | 266 RTC_DCHECK(it != voice_channels_.end()); |
| 266 if (it == voice_channels_.end()) | 267 if (it == voice_channels_.end()) |
| 267 return; | 268 return; |
| 268 voice_channels_.erase(it); | 269 voice_channels_.erase(it); |
| 269 delete voice_channel; | 270 delete voice_channel; |
| 270 } | 271 } |
| 271 | 272 |
| 272 VideoChannel* ChannelManager::CreateVideoChannel( | 273 VideoChannel* ChannelManager::CreateVideoChannel( |
| 273 webrtc::MediaControllerInterface* media_controller, | 274 webrtc::MediaControllerInterface* media_controller, |
| 274 TransportController* transport_controller, | 275 TransportController* transport_controller, |
| 275 const std::string& content_name, | 276 const std::string& content_name, |
| 276 const std::string* bundle_transport_name, | 277 const std::string* bundle_transport_name, |
| 277 bool rtcp, | 278 bool rtcp, |
| 278 bool srtp_required, | 279 bool srtp_required, |
| 279 const VideoOptions& options) { | 280 const VideoOptions& options) { |
| 280 return worker_thread_->Invoke<VideoChannel*>( | 281 return worker_thread_->Invoke<VideoChannel*>( |
| 281 RTC_FROM_HERE, Bind(&ChannelManager::CreateVideoChannel_w, this, | 282 RTC_FROM_HERE, Bind(&ChannelManager::CreateVideoChannel_w, this, |
| 282 media_controller, transport_controller, content_name, | 283 media_controller, transport_controller, content_name, |
| 283 bundle_transport_name, rtcp, srtp_required, options)); | 284 bundle_transport_name, rtcp, srtp_required, options)); |
| 284 } | 285 } |
| 285 | 286 |
| 286 VideoChannel* ChannelManager::CreateVideoChannel_w( | 287 VideoChannel* ChannelManager::CreateVideoChannel_w( |
| 287 webrtc::MediaControllerInterface* media_controller, | 288 webrtc::MediaControllerInterface* media_controller, |
| 288 TransportController* transport_controller, | 289 TransportController* transport_controller, |
| 289 const std::string& content_name, | 290 const std::string& content_name, |
| 290 const std::string* bundle_transport_name, | 291 const std::string* bundle_transport_name, |
| 291 bool rtcp, | 292 bool rtcp, |
| 292 bool srtp_required, | 293 bool srtp_required, |
| 293 const VideoOptions& options) { | 294 const VideoOptions& options) { |
| 294 ASSERT(initialized_); | 295 RTC_DCHECK(initialized_); |
| 295 ASSERT(worker_thread_ == rtc::Thread::Current()); | 296 RTC_DCHECK(worker_thread_ == rtc::Thread::Current()); |
| 296 ASSERT(nullptr != media_controller); | 297 RTC_DCHECK(nullptr != media_controller); |
| 297 VideoMediaChannel* media_channel = media_engine_->CreateVideoChannel( | 298 VideoMediaChannel* media_channel = media_engine_->CreateVideoChannel( |
| 298 media_controller->call_w(), media_controller->config(), options); | 299 media_controller->call_w(), media_controller->config(), options); |
| 299 if (media_channel == NULL) { | 300 if (media_channel == NULL) { |
| 300 return NULL; | 301 return NULL; |
| 301 } | 302 } |
| 302 | 303 |
| 303 VideoChannel* video_channel = | 304 VideoChannel* video_channel = |
| 304 new VideoChannel(worker_thread_, network_thread_, media_channel, | 305 new VideoChannel(worker_thread_, network_thread_, media_channel, |
| 305 transport_controller, content_name, rtcp, srtp_required); | 306 transport_controller, content_name, rtcp, srtp_required); |
| 306 video_channel->SetCryptoOptions(crypto_options_); | 307 video_channel->SetCryptoOptions(crypto_options_); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 317 if (video_channel) { | 318 if (video_channel) { |
| 318 worker_thread_->Invoke<void>( | 319 worker_thread_->Invoke<void>( |
| 319 RTC_FROM_HERE, | 320 RTC_FROM_HERE, |
| 320 Bind(&ChannelManager::DestroyVideoChannel_w, this, video_channel)); | 321 Bind(&ChannelManager::DestroyVideoChannel_w, this, video_channel)); |
| 321 } | 322 } |
| 322 } | 323 } |
| 323 | 324 |
| 324 void ChannelManager::DestroyVideoChannel_w(VideoChannel* video_channel) { | 325 void ChannelManager::DestroyVideoChannel_w(VideoChannel* video_channel) { |
| 325 TRACE_EVENT0("webrtc", "ChannelManager::DestroyVideoChannel_w"); | 326 TRACE_EVENT0("webrtc", "ChannelManager::DestroyVideoChannel_w"); |
| 326 // Destroy video channel. | 327 // Destroy video channel. |
| 327 ASSERT(initialized_); | 328 RTC_DCHECK(initialized_); |
| 328 ASSERT(worker_thread_ == rtc::Thread::Current()); | 329 RTC_DCHECK(worker_thread_ == rtc::Thread::Current()); |
| 329 VideoChannels::iterator it = std::find(video_channels_.begin(), | 330 VideoChannels::iterator it = std::find(video_channels_.begin(), |
| 330 video_channels_.end(), video_channel); | 331 video_channels_.end(), video_channel); |
| 331 ASSERT(it != video_channels_.end()); | 332 RTC_DCHECK(it != video_channels_.end()); |
| 332 if (it == video_channels_.end()) | 333 if (it == video_channels_.end()) |
| 333 return; | 334 return; |
| 334 | 335 |
| 335 video_channels_.erase(it); | 336 video_channels_.erase(it); |
| 336 delete video_channel; | 337 delete video_channel; |
| 337 } | 338 } |
| 338 | 339 |
| 339 RtpDataChannel* ChannelManager::CreateRtpDataChannel( | 340 RtpDataChannel* ChannelManager::CreateRtpDataChannel( |
| 340 webrtc::MediaControllerInterface* media_controller, | 341 webrtc::MediaControllerInterface* media_controller, |
| 341 TransportController* transport_controller, | 342 TransportController* transport_controller, |
| 342 const std::string& content_name, | 343 const std::string& content_name, |
| 343 const std::string* bundle_transport_name, | 344 const std::string* bundle_transport_name, |
| 344 bool rtcp, | 345 bool rtcp, |
| 345 bool srtp_required) { | 346 bool srtp_required) { |
| 346 return worker_thread_->Invoke<RtpDataChannel*>( | 347 return worker_thread_->Invoke<RtpDataChannel*>( |
| 347 RTC_FROM_HERE, Bind(&ChannelManager::CreateRtpDataChannel_w, this, | 348 RTC_FROM_HERE, Bind(&ChannelManager::CreateRtpDataChannel_w, this, |
| 348 media_controller, transport_controller, content_name, | 349 media_controller, transport_controller, content_name, |
| 349 bundle_transport_name, rtcp, srtp_required)); | 350 bundle_transport_name, rtcp, srtp_required)); |
| 350 } | 351 } |
| 351 | 352 |
| 352 RtpDataChannel* ChannelManager::CreateRtpDataChannel_w( | 353 RtpDataChannel* ChannelManager::CreateRtpDataChannel_w( |
| 353 webrtc::MediaControllerInterface* media_controller, | 354 webrtc::MediaControllerInterface* media_controller, |
| 354 TransportController* transport_controller, | 355 TransportController* transport_controller, |
| 355 const std::string& content_name, | 356 const std::string& content_name, |
| 356 const std::string* bundle_transport_name, | 357 const std::string* bundle_transport_name, |
| 357 bool rtcp, | 358 bool rtcp, |
| 358 bool srtp_required) { | 359 bool srtp_required) { |
| 359 // This is ok to alloc from a thread other than the worker thread. | 360 // This is ok to alloc from a thread other than the worker thread. |
| 360 ASSERT(initialized_); | 361 RTC_DCHECK(initialized_); |
| 361 MediaConfig config; | 362 MediaConfig config; |
| 362 if (media_controller) { | 363 if (media_controller) { |
| 363 config = media_controller->config(); | 364 config = media_controller->config(); |
| 364 } | 365 } |
| 365 DataMediaChannel* media_channel = data_media_engine_->CreateChannel(config); | 366 DataMediaChannel* media_channel = data_media_engine_->CreateChannel(config); |
| 366 if (!media_channel) { | 367 if (!media_channel) { |
| 367 LOG(LS_WARNING) << "Failed to create RTP data channel."; | 368 LOG(LS_WARNING) << "Failed to create RTP data channel."; |
| 368 return nullptr; | 369 return nullptr; |
| 369 } | 370 } |
| 370 | 371 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 386 if (data_channel) { | 387 if (data_channel) { |
| 387 worker_thread_->Invoke<void>( | 388 worker_thread_->Invoke<void>( |
| 388 RTC_FROM_HERE, | 389 RTC_FROM_HERE, |
| 389 Bind(&ChannelManager::DestroyRtpDataChannel_w, this, data_channel)); | 390 Bind(&ChannelManager::DestroyRtpDataChannel_w, this, data_channel)); |
| 390 } | 391 } |
| 391 } | 392 } |
| 392 | 393 |
| 393 void ChannelManager::DestroyRtpDataChannel_w(RtpDataChannel* data_channel) { | 394 void ChannelManager::DestroyRtpDataChannel_w(RtpDataChannel* data_channel) { |
| 394 TRACE_EVENT0("webrtc", "ChannelManager::DestroyRtpDataChannel_w"); | 395 TRACE_EVENT0("webrtc", "ChannelManager::DestroyRtpDataChannel_w"); |
| 395 // Destroy data channel. | 396 // Destroy data channel. |
| 396 ASSERT(initialized_); | 397 RTC_DCHECK(initialized_); |
| 397 RtpDataChannels::iterator it = | 398 RtpDataChannels::iterator it = |
| 398 std::find(data_channels_.begin(), data_channels_.end(), data_channel); | 399 std::find(data_channels_.begin(), data_channels_.end(), data_channel); |
| 399 ASSERT(it != data_channels_.end()); | 400 RTC_DCHECK(it != data_channels_.end()); |
| 400 if (it == data_channels_.end()) | 401 if (it == data_channels_.end()) |
| 401 return; | 402 return; |
| 402 | 403 |
| 403 data_channels_.erase(it); | 404 data_channels_.erase(it); |
| 404 delete data_channel; | 405 delete data_channel; |
| 405 } | 406 } |
| 406 | 407 |
| 407 bool ChannelManager::StartAecDump(rtc::PlatformFile file, | 408 bool ChannelManager::StartAecDump(rtc::PlatformFile file, |
| 408 int64_t max_size_bytes) { | 409 int64_t max_size_bytes) { |
| 409 return worker_thread_->Invoke<bool>( | 410 return worker_thread_->Invoke<bool>( |
| 410 RTC_FROM_HERE, Bind(&MediaEngineInterface::StartAecDump, | 411 RTC_FROM_HERE, Bind(&MediaEngineInterface::StartAecDump, |
| 411 media_engine_.get(), file, max_size_bytes)); | 412 media_engine_.get(), file, max_size_bytes)); |
| 412 } | 413 } |
| 413 | 414 |
| 414 void ChannelManager::StopAecDump() { | 415 void ChannelManager::StopAecDump() { |
| 415 worker_thread_->Invoke<void>( | 416 worker_thread_->Invoke<void>( |
| 416 RTC_FROM_HERE, | 417 RTC_FROM_HERE, |
| 417 Bind(&MediaEngineInterface::StopAecDump, media_engine_.get())); | 418 Bind(&MediaEngineInterface::StopAecDump, media_engine_.get())); |
| 418 } | 419 } |
| 419 | 420 |
| 420 } // namespace cricket | 421 } // namespace cricket |
| OLD | NEW |