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