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