henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1 | /* |
kjellander | 65c7f67 | 2016-02-12 00:05:01 -0800 | [diff] [blame] | 2 | * Copyright 2004 The WebRTC project authors. All Rights Reserved. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3 | * |
kjellander | 65c7f67 | 2016-02-12 00:05:01 -0800 | [diff] [blame] | 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 |
| 6 | * tree. An additional intellectual property rights grant can be found |
| 7 | * in the file PATENTS. All contributing project authors may |
| 8 | * be found in the AUTHORS file in the root of the source tree. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 9 | */ |
| 10 | |
kjellander@webrtc.org | 9b8df25 | 2016-02-12 06:47:59 +0100 | [diff] [blame] | 11 | #include "webrtc/pc/channelmanager.h" |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 12 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 13 | #include <algorithm> |
| 14 | |
Henrik Kjellander | 15583c1 | 2016-02-10 10:53:12 +0100 | [diff] [blame] | 15 | #include "webrtc/api/mediacontroller.h" |
| 16 | #include "webrtc/base/bind.h" |
| 17 | #include "webrtc/base/common.h" |
| 18 | #include "webrtc/base/logging.h" |
Henrik Kjellander | 15583c1 | 2016-02-10 10:53:12 +0100 | [diff] [blame] | 19 | #include "webrtc/base/stringencode.h" |
| 20 | #include "webrtc/base/stringutils.h" |
| 21 | #include "webrtc/base/trace_event.h" |
kjellander | a96e2d7 | 2016-02-04 23:52:28 -0800 | [diff] [blame] | 22 | #include "webrtc/media/base/device.h" |
| 23 | #include "webrtc/media/base/hybriddataengine.h" |
| 24 | #include "webrtc/media/base/rtpdataengine.h" |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 25 | #ifdef HAVE_SCTP |
kjellander | a96e2d7 | 2016-02-04 23:52:28 -0800 | [diff] [blame] | 26 | #include "webrtc/media/sctp/sctpdataengine.h" |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 27 | #endif |
kjellander@webrtc.org | 9b8df25 | 2016-02-12 06:47:59 +0100 | [diff] [blame] | 28 | #include "webrtc/pc/srtpfilter.h" |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 29 | |
| 30 | namespace cricket { |
| 31 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 32 | |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 33 | using rtc::Bind; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 34 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 35 | static DataEngineInterface* ConstructDataEngine() { |
| 36 | #ifdef HAVE_SCTP |
| 37 | return new HybridDataEngine(new RtpDataEngine(), new SctpDataEngine()); |
| 38 | #else |
| 39 | return new RtpDataEngine(); |
| 40 | #endif |
| 41 | } |
| 42 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 43 | ChannelManager::ChannelManager(MediaEngineInterface* me, |
| 44 | DataEngineInterface* dme, |
Danil Chapovalov | 33b01f2 | 2016-05-11 19:55:27 +0200 | [diff] [blame] | 45 | rtc::Thread* thread) { |
| 46 | Construct(me, dme, thread, thread); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 47 | } |
| 48 | |
| 49 | ChannelManager::ChannelManager(MediaEngineInterface* me, |
Danil Chapovalov | 33b01f2 | 2016-05-11 19:55:27 +0200 | [diff] [blame] | 50 | rtc::Thread* worker_thread, |
| 51 | rtc::Thread* network_thread) { |
| 52 | Construct(me, ConstructDataEngine(), worker_thread, network_thread); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 53 | } |
| 54 | |
| 55 | void ChannelManager::Construct(MediaEngineInterface* me, |
| 56 | DataEngineInterface* dme, |
Danil Chapovalov | 33b01f2 | 2016-05-11 19:55:27 +0200 | [diff] [blame] | 57 | rtc::Thread* worker_thread, |
| 58 | rtc::Thread* network_thread) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 59 | media_engine_.reset(me); |
| 60 | data_media_engine_.reset(dme); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 61 | initialized_ = false; |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 62 | main_thread_ = rtc::Thread::Current(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 63 | worker_thread_ = worker_thread; |
Danil Chapovalov | 33b01f2 | 2016-05-11 19:55:27 +0200 | [diff] [blame] | 64 | network_thread_ = network_thread; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 65 | capturing_ = false; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 66 | enable_rtx_ = false; |
jbauch | cb56065 | 2016-08-04 05:20:32 -0700 | [diff] [blame] | 67 | crypto_options_ = rtc::CryptoOptions::NoGcm(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 68 | } |
| 69 | |
| 70 | ChannelManager::~ChannelManager() { |
wu@webrtc.org | 9dba525 | 2013-08-05 20:36:57 +0000 | [diff] [blame] | 71 | if (initialized_) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 72 | Terminate(); |
wu@webrtc.org | 9dba525 | 2013-08-05 20:36:57 +0000 | [diff] [blame] | 73 | // If srtp is initialized (done by the Channel) then we must call |
| 74 | // srtp_shutdown to free all crypto kernel lists. But we need to make sure |
| 75 | // shutdown always called at the end, after channels are destroyed. |
| 76 | // ChannelManager d'tor is always called last, it's safe place to call |
| 77 | // shutdown. |
| 78 | ShutdownSrtp(); |
| 79 | } |
perkj | c11b184 | 2016-03-07 17:34:13 -0800 | [diff] [blame] | 80 | // The media engine needs to be deleted on the worker thread for thread safe |
| 81 | // destruction, |
Taylor Brandstetter | 5d97a9a | 2016-06-10 14:17:27 -0700 | [diff] [blame] | 82 | worker_thread_->Invoke<void>( |
| 83 | RTC_FROM_HERE, Bind(&ChannelManager::DestructorDeletes_w, this)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 84 | } |
| 85 | |
| 86 | bool ChannelManager::SetVideoRtxEnabled(bool enable) { |
| 87 | // To be safe, this call is only allowed before initialization. Apps like |
| 88 | // Flute only have a singleton ChannelManager and we don't want this flag to |
| 89 | // be toggled between calls or when there's concurrent calls. We expect apps |
| 90 | // to enable this at startup and retain that setting for the lifetime of the |
| 91 | // app. |
| 92 | if (!initialized_) { |
| 93 | enable_rtx_ = enable; |
| 94 | return true; |
| 95 | } else { |
| 96 | LOG(LS_WARNING) << "Cannot toggle rtx after initialization!"; |
| 97 | return false; |
| 98 | } |
| 99 | } |
| 100 | |
jbauch | cb56065 | 2016-08-04 05:20:32 -0700 | [diff] [blame] | 101 | bool ChannelManager::SetCryptoOptions( |
| 102 | const rtc::CryptoOptions& crypto_options) { |
| 103 | return worker_thread_->Invoke<bool>(RTC_FROM_HERE, Bind( |
| 104 | &ChannelManager::SetCryptoOptions_w, this, crypto_options)); |
| 105 | } |
| 106 | |
| 107 | bool ChannelManager::SetCryptoOptions_w( |
| 108 | const rtc::CryptoOptions& crypto_options) { |
| 109 | if (!video_channels_.empty() || !voice_channels_.empty() || |
| 110 | !data_channels_.empty()) { |
| 111 | LOG(LS_WARNING) << "Not changing crypto options in existing channels."; |
| 112 | } |
| 113 | crypto_options_ = crypto_options; |
| 114 | #if defined(ENABLE_EXTERNAL_AUTH) |
| 115 | if (crypto_options_.enable_gcm_crypto_suites) { |
| 116 | // TODO(jbauch): Re-enable once https://crbug.com/628400 is resolved. |
| 117 | crypto_options_.enable_gcm_crypto_suites = false; |
| 118 | LOG(LS_WARNING) << "GCM ciphers are not supported with " << |
| 119 | "ENABLE_EXTERNAL_AUTH and will be disabled."; |
| 120 | } |
| 121 | #endif |
| 122 | return true; |
| 123 | } |
| 124 | |
ossu | dedfd28 | 2016-06-14 07:12:39 -0700 | [diff] [blame] | 125 | void ChannelManager::GetSupportedAudioSendCodecs( |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 126 | std::vector<AudioCodec>* codecs) const { |
ossu | dedfd28 | 2016-06-14 07:12:39 -0700 | [diff] [blame] | 127 | *codecs = media_engine_->audio_send_codecs(); |
| 128 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 129 | |
ossu | dedfd28 | 2016-06-14 07:12:39 -0700 | [diff] [blame] | 130 | void ChannelManager::GetSupportedAudioReceiveCodecs( |
| 131 | std::vector<AudioCodec>* codecs) const { |
| 132 | *codecs = media_engine_->audio_recv_codecs(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 133 | } |
| 134 | |
| 135 | void ChannelManager::GetSupportedAudioRtpHeaderExtensions( |
| 136 | RtpHeaderExtensions* ext) const { |
Stefan Holmer | 9d69c3f | 2015-12-07 10:45:43 +0100 | [diff] [blame] | 137 | *ext = media_engine_->GetAudioCapabilities().header_extensions; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 138 | } |
| 139 | |
magjed | 3cf8ece | 2016-11-10 03:36:53 -0800 | [diff] [blame] | 140 | void ChannelManager::GetSupportedVideoCodecs( |
| 141 | std::vector<VideoCodec>* codecs) const { |
| 142 | codecs->clear(); |
| 143 | |
| 144 | std::vector<VideoCodec>::const_iterator it; |
| 145 | for (it = media_engine_->video_codecs().begin(); |
| 146 | it != media_engine_->video_codecs().end(); ++it) { |
| 147 | if (!enable_rtx_ && _stricmp(kRtxCodecName, it->name.c_str()) == 0) { |
| 148 | continue; |
| 149 | } |
| 150 | codecs->push_back(*it); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 151 | } |
| 152 | } |
| 153 | |
| 154 | void ChannelManager::GetSupportedVideoRtpHeaderExtensions( |
| 155 | RtpHeaderExtensions* ext) const { |
Stefan Holmer | 9d69c3f | 2015-12-07 10:45:43 +0100 | [diff] [blame] | 156 | *ext = media_engine_->GetVideoCapabilities().header_extensions; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 157 | } |
| 158 | |
| 159 | void ChannelManager::GetSupportedDataCodecs( |
| 160 | std::vector<DataCodec>* codecs) const { |
| 161 | *codecs = data_media_engine_->data_codecs(); |
| 162 | } |
| 163 | |
| 164 | bool ChannelManager::Init() { |
| 165 | ASSERT(!initialized_); |
| 166 | if (initialized_) { |
| 167 | return false; |
| 168 | } |
Danil Chapovalov | 33b01f2 | 2016-05-11 19:55:27 +0200 | [diff] [blame] | 169 | RTC_DCHECK(network_thread_); |
| 170 | RTC_DCHECK(worker_thread_); |
| 171 | if (!network_thread_->IsCurrent()) { |
| 172 | // Do not allow invoking calls to other threads on the network thread. |
| 173 | network_thread_->Invoke<bool>( |
Taylor Brandstetter | 5d97a9a | 2016-06-10 14:17:27 -0700 | [diff] [blame] | 174 | RTC_FROM_HERE, |
Danil Chapovalov | 33b01f2 | 2016-05-11 19:55:27 +0200 | [diff] [blame] | 175 | rtc::Bind(&rtc::Thread::SetAllowBlockingCalls, network_thread_, false)); |
henrika@webrtc.org | 62f6e75 | 2015-02-11 08:38:35 +0000 | [diff] [blame] | 176 | } |
| 177 | |
Danil Chapovalov | 33b01f2 | 2016-05-11 19:55:27 +0200 | [diff] [blame] | 178 | initialized_ = worker_thread_->Invoke<bool>( |
Taylor Brandstetter | 5d97a9a | 2016-06-10 14:17:27 -0700 | [diff] [blame] | 179 | RTC_FROM_HERE, Bind(&ChannelManager::InitMediaEngine_w, this)); |
henrika@webrtc.org | 62f6e75 | 2015-02-11 08:38:35 +0000 | [diff] [blame] | 180 | ASSERT(initialized_); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 181 | return initialized_; |
| 182 | } |
| 183 | |
henrika@webrtc.org | 62f6e75 | 2015-02-11 08:38:35 +0000 | [diff] [blame] | 184 | bool ChannelManager::InitMediaEngine_w() { |
| 185 | ASSERT(worker_thread_ == rtc::Thread::Current()); |
solenberg | ff97631 | 2016-03-30 23:28:51 -0700 | [diff] [blame] | 186 | return media_engine_->Init(); |
henrika@webrtc.org | 62f6e75 | 2015-02-11 08:38:35 +0000 | [diff] [blame] | 187 | } |
| 188 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 189 | void ChannelManager::Terminate() { |
| 190 | ASSERT(initialized_); |
| 191 | if (!initialized_) { |
| 192 | return; |
| 193 | } |
Taylor Brandstetter | 5d97a9a | 2016-06-10 14:17:27 -0700 | [diff] [blame] | 194 | worker_thread_->Invoke<void>(RTC_FROM_HERE, |
| 195 | Bind(&ChannelManager::Terminate_w, this)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 196 | initialized_ = false; |
| 197 | } |
| 198 | |
hbos@webrtc.org | 4aef5fe | 2015-02-25 10:09:05 +0000 | [diff] [blame] | 199 | void ChannelManager::DestructorDeletes_w() { |
henrika@webrtc.org | 62f6e75 | 2015-02-11 08:38:35 +0000 | [diff] [blame] | 200 | ASSERT(worker_thread_ == rtc::Thread::Current()); |
| 201 | media_engine_.reset(NULL); |
| 202 | } |
| 203 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 204 | void ChannelManager::Terminate_w() { |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 205 | ASSERT(worker_thread_ == rtc::Thread::Current()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 206 | // Need to destroy the voice/video channels |
| 207 | while (!video_channels_.empty()) { |
| 208 | DestroyVideoChannel_w(video_channels_.back()); |
| 209 | } |
| 210 | while (!voice_channels_.empty()) { |
Fredrik Solenberg | 709ed67 | 2015-09-15 12:26:33 +0200 | [diff] [blame] | 211 | DestroyVoiceChannel_w(voice_channels_.back()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 212 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 213 | } |
| 214 | |
| 215 | VoiceChannel* ChannelManager::CreateVoiceChannel( |
Fredrik Solenberg | 709ed67 | 2015-09-15 12:26:33 +0200 | [diff] [blame] | 216 | webrtc::MediaControllerInterface* media_controller, |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 217 | TransportController* transport_controller, |
Jelena Marusic | c28a896 | 2015-05-29 15:05:44 +0200 | [diff] [blame] | 218 | const std::string& content_name, |
skvlad | 6c87a67 | 2016-05-17 17:49:52 -0700 | [diff] [blame] | 219 | const std::string* bundle_transport_name, |
Jelena Marusic | c28a896 | 2015-05-29 15:05:44 +0200 | [diff] [blame] | 220 | bool rtcp, |
| 221 | const AudioOptions& options) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 222 | return worker_thread_->Invoke<VoiceChannel*>( |
Taylor Brandstetter | 5d97a9a | 2016-06-10 14:17:27 -0700 | [diff] [blame] | 223 | RTC_FROM_HERE, Bind(&ChannelManager::CreateVoiceChannel_w, this, |
| 224 | media_controller, transport_controller, content_name, |
| 225 | bundle_transport_name, rtcp, options)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 226 | } |
| 227 | |
| 228 | VoiceChannel* ChannelManager::CreateVoiceChannel_w( |
Fredrik Solenberg | 709ed67 | 2015-09-15 12:26:33 +0200 | [diff] [blame] | 229 | webrtc::MediaControllerInterface* media_controller, |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 230 | TransportController* transport_controller, |
Jelena Marusic | c28a896 | 2015-05-29 15:05:44 +0200 | [diff] [blame] | 231 | const std::string& content_name, |
skvlad | 6c87a67 | 2016-05-17 17:49:52 -0700 | [diff] [blame] | 232 | const std::string* bundle_transport_name, |
Jelena Marusic | c28a896 | 2015-05-29 15:05:44 +0200 | [diff] [blame] | 233 | bool rtcp, |
| 234 | const AudioOptions& options) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 235 | ASSERT(initialized_); |
Fredrik Solenberg | 4b60c73 | 2015-05-07 14:07:48 +0200 | [diff] [blame] | 236 | ASSERT(worker_thread_ == rtc::Thread::Current()); |
Fredrik Solenberg | 709ed67 | 2015-09-15 12:26:33 +0200 | [diff] [blame] | 237 | ASSERT(nullptr != media_controller); |
nisse | 51542be | 2016-02-12 02:27:06 -0800 | [diff] [blame] | 238 | VoiceMediaChannel* media_channel = media_engine_->CreateChannel( |
| 239 | media_controller->call_w(), media_controller->config(), options); |
Jelena Marusic | c28a896 | 2015-05-29 15:05:44 +0200 | [diff] [blame] | 240 | if (!media_channel) |
| 241 | return nullptr; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 242 | |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 243 | VoiceChannel* voice_channel = |
Danil Chapovalov | 33b01f2 | 2016-05-11 19:55:27 +0200 | [diff] [blame] | 244 | new VoiceChannel(worker_thread_, network_thread_, media_engine_.get(), |
| 245 | media_channel, transport_controller, content_name, rtcp); |
jbauch | cb56065 | 2016-08-04 05:20:32 -0700 | [diff] [blame] | 246 | voice_channel->SetCryptoOptions(crypto_options_); |
skvlad | 6c87a67 | 2016-05-17 17:49:52 -0700 | [diff] [blame] | 247 | if (!voice_channel->Init_w(bundle_transport_name)) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 248 | delete voice_channel; |
Jelena Marusic | c28a896 | 2015-05-29 15:05:44 +0200 | [diff] [blame] | 249 | return nullptr; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 250 | } |
| 251 | voice_channels_.push_back(voice_channel); |
| 252 | return voice_channel; |
| 253 | } |
| 254 | |
Fredrik Solenberg | 709ed67 | 2015-09-15 12:26:33 +0200 | [diff] [blame] | 255 | void ChannelManager::DestroyVoiceChannel(VoiceChannel* voice_channel) { |
Peter Boström | 1a9d615 | 2015-12-08 22:15:17 +0100 | [diff] [blame] | 256 | TRACE_EVENT0("webrtc", "ChannelManager::DestroyVoiceChannel"); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 257 | if (voice_channel) { |
| 258 | worker_thread_->Invoke<void>( |
Taylor Brandstetter | 5d97a9a | 2016-06-10 14:17:27 -0700 | [diff] [blame] | 259 | RTC_FROM_HERE, |
Fredrik Solenberg | 709ed67 | 2015-09-15 12:26:33 +0200 | [diff] [blame] | 260 | Bind(&ChannelManager::DestroyVoiceChannel_w, this, voice_channel)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 261 | } |
| 262 | } |
| 263 | |
Fredrik Solenberg | 709ed67 | 2015-09-15 12:26:33 +0200 | [diff] [blame] | 264 | void ChannelManager::DestroyVoiceChannel_w(VoiceChannel* voice_channel) { |
Peter Boström | 1a9d615 | 2015-12-08 22:15:17 +0100 | [diff] [blame] | 265 | TRACE_EVENT0("webrtc", "ChannelManager::DestroyVoiceChannel_w"); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 266 | // Destroy voice channel. |
| 267 | ASSERT(initialized_); |
Fredrik Solenberg | 4b60c73 | 2015-05-07 14:07:48 +0200 | [diff] [blame] | 268 | ASSERT(worker_thread_ == rtc::Thread::Current()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 269 | VoiceChannels::iterator it = std::find(voice_channels_.begin(), |
| 270 | voice_channels_.end(), voice_channel); |
| 271 | ASSERT(it != voice_channels_.end()); |
| 272 | if (it == voice_channels_.end()) |
| 273 | return; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 274 | voice_channels_.erase(it); |
| 275 | delete voice_channel; |
| 276 | } |
| 277 | |
| 278 | VideoChannel* ChannelManager::CreateVideoChannel( |
Fredrik Solenberg | 709ed67 | 2015-09-15 12:26:33 +0200 | [diff] [blame] | 279 | webrtc::MediaControllerInterface* media_controller, |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 280 | TransportController* transport_controller, |
buildbot@webrtc.org | 1ecbe45 | 2014-10-14 20:29:28 +0000 | [diff] [blame] | 281 | const std::string& content_name, |
skvlad | 6c87a67 | 2016-05-17 17:49:52 -0700 | [diff] [blame] | 282 | const std::string* bundle_transport_name, |
buildbot@webrtc.org | 1ecbe45 | 2014-10-14 20:29:28 +0000 | [diff] [blame] | 283 | bool rtcp, |
Fredrik Solenberg | 709ed67 | 2015-09-15 12:26:33 +0200 | [diff] [blame] | 284 | const VideoOptions& options) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 285 | return worker_thread_->Invoke<VideoChannel*>( |
Taylor Brandstetter | 5d97a9a | 2016-06-10 14:17:27 -0700 | [diff] [blame] | 286 | RTC_FROM_HERE, Bind(&ChannelManager::CreateVideoChannel_w, this, |
| 287 | media_controller, transport_controller, content_name, |
| 288 | bundle_transport_name, rtcp, options)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 289 | } |
| 290 | |
| 291 | VideoChannel* ChannelManager::CreateVideoChannel_w( |
Fredrik Solenberg | 709ed67 | 2015-09-15 12:26:33 +0200 | [diff] [blame] | 292 | webrtc::MediaControllerInterface* media_controller, |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 293 | TransportController* transport_controller, |
buildbot@webrtc.org | 1ecbe45 | 2014-10-14 20:29:28 +0000 | [diff] [blame] | 294 | const std::string& content_name, |
skvlad | 6c87a67 | 2016-05-17 17:49:52 -0700 | [diff] [blame] | 295 | const std::string* bundle_transport_name, |
buildbot@webrtc.org | 1ecbe45 | 2014-10-14 20:29:28 +0000 | [diff] [blame] | 296 | bool rtcp, |
Fredrik Solenberg | 709ed67 | 2015-09-15 12:26:33 +0200 | [diff] [blame] | 297 | const VideoOptions& options) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 298 | ASSERT(initialized_); |
Fredrik Solenberg | 4b60c73 | 2015-05-07 14:07:48 +0200 | [diff] [blame] | 299 | ASSERT(worker_thread_ == rtc::Thread::Current()); |
Fredrik Solenberg | 709ed67 | 2015-09-15 12:26:33 +0200 | [diff] [blame] | 300 | ASSERT(nullptr != media_controller); |
nisse | 51542be | 2016-02-12 02:27:06 -0800 | [diff] [blame] | 301 | VideoMediaChannel* media_channel = media_engine_->CreateVideoChannel( |
| 302 | media_controller->call_w(), media_controller->config(), options); |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 303 | if (media_channel == NULL) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 304 | return NULL; |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 305 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 306 | |
Danil Chapovalov | 33b01f2 | 2016-05-11 19:55:27 +0200 | [diff] [blame] | 307 | VideoChannel* video_channel = |
| 308 | new VideoChannel(worker_thread_, network_thread_, media_channel, |
| 309 | transport_controller, content_name, rtcp); |
jbauch | cb56065 | 2016-08-04 05:20:32 -0700 | [diff] [blame] | 310 | video_channel->SetCryptoOptions(crypto_options_); |
skvlad | 6c87a67 | 2016-05-17 17:49:52 -0700 | [diff] [blame] | 311 | if (!video_channel->Init_w(bundle_transport_name)) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 312 | delete video_channel; |
| 313 | return NULL; |
| 314 | } |
| 315 | video_channels_.push_back(video_channel); |
| 316 | return video_channel; |
| 317 | } |
| 318 | |
| 319 | void ChannelManager::DestroyVideoChannel(VideoChannel* video_channel) { |
Peter Boström | 1a9d615 | 2015-12-08 22:15:17 +0100 | [diff] [blame] | 320 | TRACE_EVENT0("webrtc", "ChannelManager::DestroyVideoChannel"); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 321 | if (video_channel) { |
| 322 | worker_thread_->Invoke<void>( |
Taylor Brandstetter | 5d97a9a | 2016-06-10 14:17:27 -0700 | [diff] [blame] | 323 | RTC_FROM_HERE, |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 324 | Bind(&ChannelManager::DestroyVideoChannel_w, this, video_channel)); |
| 325 | } |
| 326 | } |
| 327 | |
| 328 | void ChannelManager::DestroyVideoChannel_w(VideoChannel* video_channel) { |
Peter Boström | 1a9d615 | 2015-12-08 22:15:17 +0100 | [diff] [blame] | 329 | TRACE_EVENT0("webrtc", "ChannelManager::DestroyVideoChannel_w"); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 330 | // Destroy video channel. |
| 331 | ASSERT(initialized_); |
Fredrik Solenberg | 4b60c73 | 2015-05-07 14:07:48 +0200 | [diff] [blame] | 332 | ASSERT(worker_thread_ == rtc::Thread::Current()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 333 | VideoChannels::iterator it = std::find(video_channels_.begin(), |
| 334 | video_channels_.end(), video_channel); |
| 335 | ASSERT(it != video_channels_.end()); |
| 336 | if (it == video_channels_.end()) |
| 337 | return; |
| 338 | |
| 339 | video_channels_.erase(it); |
| 340 | delete video_channel; |
| 341 | } |
| 342 | |
| 343 | DataChannel* ChannelManager::CreateDataChannel( |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 344 | TransportController* transport_controller, |
| 345 | const std::string& content_name, |
skvlad | 6c87a67 | 2016-05-17 17:49:52 -0700 | [diff] [blame] | 346 | const std::string* bundle_transport_name, |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 347 | bool rtcp, |
| 348 | DataChannelType channel_type) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 349 | return worker_thread_->Invoke<DataChannel*>( |
Taylor Brandstetter | 5d97a9a | 2016-06-10 14:17:27 -0700 | [diff] [blame] | 350 | RTC_FROM_HERE, |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 351 | Bind(&ChannelManager::CreateDataChannel_w, this, transport_controller, |
skvlad | 6c87a67 | 2016-05-17 17:49:52 -0700 | [diff] [blame] | 352 | content_name, bundle_transport_name, rtcp, channel_type)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 353 | } |
| 354 | |
| 355 | DataChannel* ChannelManager::CreateDataChannel_w( |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 356 | TransportController* transport_controller, |
| 357 | const std::string& content_name, |
skvlad | 6c87a67 | 2016-05-17 17:49:52 -0700 | [diff] [blame] | 358 | const std::string* bundle_transport_name, |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 359 | bool rtcp, |
| 360 | DataChannelType data_channel_type) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 361 | // This is ok to alloc from a thread other than the worker thread. |
| 362 | ASSERT(initialized_); |
| 363 | DataMediaChannel* media_channel = data_media_engine_->CreateChannel( |
| 364 | data_channel_type); |
| 365 | if (!media_channel) { |
| 366 | LOG(LS_WARNING) << "Failed to create data channel of type " |
| 367 | << data_channel_type; |
| 368 | return NULL; |
| 369 | } |
| 370 | |
Danil Chapovalov | 33b01f2 | 2016-05-11 19:55:27 +0200 | [diff] [blame] | 371 | DataChannel* data_channel = |
| 372 | new DataChannel(worker_thread_, network_thread_, media_channel, |
| 373 | transport_controller, content_name, rtcp); |
jbauch | cb56065 | 2016-08-04 05:20:32 -0700 | [diff] [blame] | 374 | data_channel->SetCryptoOptions(crypto_options_); |
skvlad | 6c87a67 | 2016-05-17 17:49:52 -0700 | [diff] [blame] | 375 | if (!data_channel->Init_w(bundle_transport_name)) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 376 | LOG(LS_WARNING) << "Failed to init data channel."; |
| 377 | delete data_channel; |
| 378 | return NULL; |
| 379 | } |
| 380 | data_channels_.push_back(data_channel); |
| 381 | return data_channel; |
| 382 | } |
| 383 | |
| 384 | void ChannelManager::DestroyDataChannel(DataChannel* data_channel) { |
Peter Boström | 1a9d615 | 2015-12-08 22:15:17 +0100 | [diff] [blame] | 385 | TRACE_EVENT0("webrtc", "ChannelManager::DestroyDataChannel"); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 386 | if (data_channel) { |
| 387 | worker_thread_->Invoke<void>( |
Taylor Brandstetter | 5d97a9a | 2016-06-10 14:17:27 -0700 | [diff] [blame] | 388 | RTC_FROM_HERE, |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 389 | Bind(&ChannelManager::DestroyDataChannel_w, this, data_channel)); |
| 390 | } |
| 391 | } |
| 392 | |
| 393 | void ChannelManager::DestroyDataChannel_w(DataChannel* data_channel) { |
Peter Boström | 1a9d615 | 2015-12-08 22:15:17 +0100 | [diff] [blame] | 394 | TRACE_EVENT0("webrtc", "ChannelManager::DestroyDataChannel_w"); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 395 | // Destroy data channel. |
| 396 | ASSERT(initialized_); |
| 397 | DataChannels::iterator it = std::find(data_channels_.begin(), |
| 398 | data_channels_.end(), data_channel); |
| 399 | ASSERT(it != data_channels_.end()); |
| 400 | if (it == data_channels_.end()) |
| 401 | return; |
| 402 | |
| 403 | data_channels_.erase(it); |
| 404 | delete data_channel; |
| 405 | } |
| 406 | |
ivoc | d66b44d | 2016-01-15 03:06:36 -0800 | [diff] [blame] | 407 | bool ChannelManager::StartAecDump(rtc::PlatformFile file, |
| 408 | int64_t max_size_bytes) { |
Taylor Brandstetter | 5d97a9a | 2016-06-10 14:17:27 -0700 | [diff] [blame] | 409 | return worker_thread_->Invoke<bool>( |
| 410 | RTC_FROM_HERE, Bind(&MediaEngineInterface::StartAecDump, |
| 411 | media_engine_.get(), file, max_size_bytes)); |
wu@webrtc.org | a989080 | 2013-12-13 00:21:03 +0000 | [diff] [blame] | 412 | } |
| 413 | |
ivoc | 797ef12 | 2015-10-22 03:25:41 -0700 | [diff] [blame] | 414 | void ChannelManager::StopAecDump() { |
| 415 | worker_thread_->Invoke<void>( |
Taylor Brandstetter | 5d97a9a | 2016-06-10 14:17:27 -0700 | [diff] [blame] | 416 | RTC_FROM_HERE, |
ivoc | 797ef12 | 2015-10-22 03:25:41 -0700 | [diff] [blame] | 417 | Bind(&MediaEngineInterface::StopAecDump, media_engine_.get())); |
| 418 | } |
| 419 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 420 | } // namespace cricket |