henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 1 | /* |
kjellander | 65c7f67 | 2016-02-12 08:05:01 | [diff] [blame] | 2 | * Copyright 2004 The WebRTC project authors. All Rights Reserved. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 3 | * |
kjellander | 65c7f67 | 2016-02-12 08:05:01 | [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 | [diff] [blame] | 9 | */ |
| 10 | |
Steve Anton | 10542f2 | 2019-01-11 17:11:00 | [diff] [blame] | 11 | #include "pc/channel_manager.h" |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 12 | |
Steve Anton | 36b29d1 | 2017-10-30 16:57:42 | [diff] [blame] | 13 | #include <utility> |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 14 | |
Steve Anton | 64b626b | 2019-01-29 01:25:26 | [diff] [blame] | 15 | #include "absl/algorithm/container.h" |
Karl Wiberg | 918f50c | 2018-07-05 09:40:33 | [diff] [blame] | 16 | #include "absl/memory/memory.h" |
Niels Möller | 3c7d599 | 2018-10-19 13:29:54 | [diff] [blame] | 17 | #include "absl/strings/match.h" |
Steve Anton | 10542f2 | 2019-01-11 17:11:00 | [diff] [blame] | 18 | #include "media/base/media_constants.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 04:47:31 | [diff] [blame] | 19 | #include "rtc_base/checks.h" |
Yves Gerey | 3e70781 | 2018-11-28 15:47:49 | [diff] [blame] | 20 | #include "rtc_base/location.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 04:47:31 | [diff] [blame] | 21 | #include "rtc_base/logging.h" |
Yves Gerey | 3e70781 | 2018-11-28 15:47:49 | [diff] [blame] | 22 | #include "rtc_base/thread_checker.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 04:47:31 | [diff] [blame] | 23 | #include "rtc_base/trace_event.h" |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 24 | |
| 25 | namespace cricket { |
| 26 | |
Steve Anton | c9e1560 | 2017-11-06 23:40:09 | [diff] [blame] | 27 | ChannelManager::ChannelManager( |
| 28 | std::unique_ptr<MediaEngineInterface> media_engine, |
| 29 | std::unique_ptr<DataEngineInterface> data_engine, |
| 30 | rtc::Thread* worker_thread, |
| 31 | rtc::Thread* network_thread) |
| 32 | : media_engine_(std::move(media_engine)), |
| 33 | data_engine_(std::move(data_engine)), |
| 34 | main_thread_(rtc::Thread::Current()), |
| 35 | worker_thread_(worker_thread), |
| 36 | network_thread_(network_thread) { |
| 37 | RTC_DCHECK(data_engine_); |
| 38 | RTC_DCHECK(worker_thread_); |
| 39 | RTC_DCHECK(network_thread_); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 40 | } |
| 41 | |
| 42 | ChannelManager::~ChannelManager() { |
wu@webrtc.org | 9dba525 | 2013-08-05 20:36:57 | [diff] [blame] | 43 | if (initialized_) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 44 | Terminate(); |
wu@webrtc.org | 9dba525 | 2013-08-05 20:36:57 | [diff] [blame] | 45 | } |
perkj | c11b184 | 2016-03-08 01:34:13 | [diff] [blame] | 46 | // The media engine needs to be deleted on the worker thread for thread safe |
| 47 | // destruction, |
Steve Anton | c9e1560 | 2017-11-06 23:40:09 | [diff] [blame] | 48 | worker_thread_->Invoke<void>(RTC_FROM_HERE, [&] { media_engine_.reset(); }); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 49 | } |
| 50 | |
| 51 | bool ChannelManager::SetVideoRtxEnabled(bool enable) { |
| 52 | // To be safe, this call is only allowed before initialization. Apps like |
| 53 | // Flute only have a singleton ChannelManager and we don't want this flag to |
| 54 | // be toggled between calls or when there's concurrent calls. We expect apps |
| 55 | // to enable this at startup and retain that setting for the lifetime of the |
| 56 | // app. |
| 57 | if (!initialized_) { |
| 58 | enable_rtx_ = enable; |
| 59 | return true; |
| 60 | } else { |
Mirko Bonadei | 675513b | 2017-11-09 10:09:25 | [diff] [blame] | 61 | RTC_LOG(LS_WARNING) << "Cannot toggle rtx after initialization!"; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 62 | return false; |
| 63 | } |
| 64 | } |
| 65 | |
ossu | dedfd28 | 2016-06-14 14:12:39 | [diff] [blame] | 66 | void ChannelManager::GetSupportedAudioSendCodecs( |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 67 | std::vector<AudioCodec>* codecs) const { |
zhihuang | 38ede13 | 2017-06-15 19:52:32 | [diff] [blame] | 68 | if (!media_engine_) { |
| 69 | return; |
| 70 | } |
Sebastian Jansson | 6eb8a16 | 2018-11-16 10:29:55 | [diff] [blame] | 71 | *codecs = media_engine_->voice().send_codecs(); |
ossu | dedfd28 | 2016-06-14 14:12:39 | [diff] [blame] | 72 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 73 | |
ossu | dedfd28 | 2016-06-14 14:12:39 | [diff] [blame] | 74 | void ChannelManager::GetSupportedAudioReceiveCodecs( |
| 75 | std::vector<AudioCodec>* codecs) const { |
zhihuang | 38ede13 | 2017-06-15 19:52:32 | [diff] [blame] | 76 | if (!media_engine_) { |
| 77 | return; |
| 78 | } |
Sebastian Jansson | 6eb8a16 | 2018-11-16 10:29:55 | [diff] [blame] | 79 | *codecs = media_engine_->voice().recv_codecs(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 80 | } |
| 81 | |
| 82 | void ChannelManager::GetSupportedAudioRtpHeaderExtensions( |
| 83 | RtpHeaderExtensions* ext) const { |
zhihuang | 38ede13 | 2017-06-15 19:52:32 | [diff] [blame] | 84 | if (!media_engine_) { |
| 85 | return; |
| 86 | } |
Sebastian Jansson | 6eb8a16 | 2018-11-16 10:29:55 | [diff] [blame] | 87 | *ext = media_engine_->voice().GetCapabilities().header_extensions; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 88 | } |
| 89 | |
magjed | 3cf8ece | 2016-11-10 11:36:53 | [diff] [blame] | 90 | void ChannelManager::GetSupportedVideoCodecs( |
| 91 | std::vector<VideoCodec>* codecs) const { |
zhihuang | 38ede13 | 2017-06-15 19:52:32 | [diff] [blame] | 92 | if (!media_engine_) { |
| 93 | return; |
| 94 | } |
magjed | 3cf8ece | 2016-11-10 11:36:53 | [diff] [blame] | 95 | codecs->clear(); |
| 96 | |
Sebastian Jansson | 6eb8a16 | 2018-11-16 10:29:55 | [diff] [blame] | 97 | std::vector<VideoCodec> video_codecs = media_engine_->video().codecs(); |
brandtr | ffc6118 | 2016-11-28 14:02:22 | [diff] [blame] | 98 | for (const auto& video_codec : video_codecs) { |
| 99 | if (!enable_rtx_ && |
Niels Möller | 3c7d599 | 2018-10-19 13:29:54 | [diff] [blame] | 100 | absl::EqualsIgnoreCase(kRtxCodecName, video_codec.name)) { |
magjed | 3cf8ece | 2016-11-10 11:36:53 | [diff] [blame] | 101 | continue; |
| 102 | } |
brandtr | ffc6118 | 2016-11-28 14:02:22 | [diff] [blame] | 103 | codecs->push_back(video_codec); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 104 | } |
| 105 | } |
| 106 | |
| 107 | void ChannelManager::GetSupportedVideoRtpHeaderExtensions( |
| 108 | RtpHeaderExtensions* ext) const { |
zhihuang | 38ede13 | 2017-06-15 19:52:32 | [diff] [blame] | 109 | if (!media_engine_) { |
| 110 | return; |
| 111 | } |
Sebastian Jansson | 6eb8a16 | 2018-11-16 10:29:55 | [diff] [blame] | 112 | *ext = media_engine_->video().GetCapabilities().header_extensions; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 113 | } |
| 114 | |
| 115 | void ChannelManager::GetSupportedDataCodecs( |
| 116 | std::vector<DataCodec>* codecs) const { |
Steve Anton | c9e1560 | 2017-11-06 23:40:09 | [diff] [blame] | 117 | *codecs = data_engine_->data_codecs(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 118 | } |
| 119 | |
| 120 | bool ChannelManager::Init() { |
nisse | ede5da4 | 2017-01-12 13:15:36 | [diff] [blame] | 121 | RTC_DCHECK(!initialized_); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 122 | if (initialized_) { |
| 123 | return false; |
| 124 | } |
Danil Chapovalov | 33b01f2 | 2016-05-11 17:55:27 | [diff] [blame] | 125 | RTC_DCHECK(network_thread_); |
| 126 | RTC_DCHECK(worker_thread_); |
| 127 | if (!network_thread_->IsCurrent()) { |
| 128 | // Do not allow invoking calls to other threads on the network thread. |
Steve Anton | c9e1560 | 2017-11-06 23:40:09 | [diff] [blame] | 129 | network_thread_->Invoke<void>( |
Karl Wiberg | 3256225 | 2019-02-21 12:38:30 | [diff] [blame] | 130 | RTC_FROM_HERE, [&] { network_thread_->DisallowBlockingCalls(); }); |
henrika@webrtc.org | 62f6e75 | 2015-02-11 08:38:35 | [diff] [blame] | 131 | } |
| 132 | |
zhihuang | 38ede13 | 2017-06-15 19:52:32 | [diff] [blame] | 133 | if (media_engine_) { |
Steve Anton | c9e1560 | 2017-11-06 23:40:09 | [diff] [blame] | 134 | initialized_ = worker_thread_->Invoke<bool>( |
| 135 | RTC_FROM_HERE, [&] { return media_engine_->Init(); }); |
| 136 | RTC_DCHECK(initialized_); |
| 137 | } else { |
| 138 | initialized_ = true; |
zhihuang | 38ede13 | 2017-06-15 19:52:32 | [diff] [blame] | 139 | } |
Steve Anton | c9e1560 | 2017-11-06 23:40:09 | [diff] [blame] | 140 | return initialized_; |
henrika@webrtc.org | 62f6e75 | 2015-02-11 08:38:35 | [diff] [blame] | 141 | } |
| 142 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 143 | void ChannelManager::Terminate() { |
nisse | ede5da4 | 2017-01-12 13:15:36 | [diff] [blame] | 144 | RTC_DCHECK(initialized_); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 145 | if (!initialized_) { |
| 146 | return; |
| 147 | } |
Steve Anton | c9e1560 | 2017-11-06 23:40:09 | [diff] [blame] | 148 | // Need to destroy the channels on the worker thread. |
| 149 | worker_thread_->Invoke<void>(RTC_FROM_HERE, [&] { |
| 150 | video_channels_.clear(); |
| 151 | voice_channels_.clear(); |
| 152 | data_channels_.clear(); |
| 153 | }); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 154 | initialized_ = false; |
| 155 | } |
| 156 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 157 | VoiceChannel* ChannelManager::CreateVoiceChannel( |
nisse | eaabdf6 | 2017-05-05 09:23:02 | [diff] [blame] | 158 | webrtc::Call* call, |
| 159 | const cricket::MediaConfig& media_config, |
Zhi Huang | 2dfc42d | 2017-12-04 21:38:48 | [diff] [blame] | 160 | webrtc::RtpTransportInternal* rtp_transport, |
Anton Sukhanov | 4f08faa | 2019-05-21 18:12:57 | [diff] [blame] | 161 | const webrtc::MediaTransportConfig& media_transport_config, |
Zhi Huang | 2dfc42d | 2017-12-04 21:38:48 | [diff] [blame] | 162 | rtc::Thread* signaling_thread, |
| 163 | const std::string& content_name, |
| 164 | bool srtp_required, |
Benjamin Wright | a54daf1 | 2018-10-11 22:33:17 | [diff] [blame] | 165 | const webrtc::CryptoOptions& crypto_options, |
Amit Hilbuch | bcd39d4 | 2019-01-26 01:13:56 | [diff] [blame] | 166 | rtc::UniqueRandomIdGenerator* ssrc_generator, |
Zhi Huang | 2dfc42d | 2017-12-04 21:38:48 | [diff] [blame] | 167 | const AudioOptions& options) { |
| 168 | if (!worker_thread_->IsCurrent()) { |
| 169 | return worker_thread_->Invoke<VoiceChannel*>(RTC_FROM_HERE, [&] { |
Anton Sukhanov | 4f08faa | 2019-05-21 18:12:57 | [diff] [blame] | 170 | return CreateVoiceChannel(call, media_config, rtp_transport, |
| 171 | media_transport_config, signaling_thread, |
| 172 | content_name, srtp_required, crypto_options, |
| 173 | ssrc_generator, options); |
Zhi Huang | 2dfc42d | 2017-12-04 21:38:48 | [diff] [blame] | 174 | }); |
| 175 | } |
| 176 | |
| 177 | RTC_DCHECK_RUN_ON(worker_thread_); |
| 178 | RTC_DCHECK(initialized_); |
| 179 | RTC_DCHECK(call); |
| 180 | if (!media_engine_) { |
| 181 | return nullptr; |
| 182 | } |
| 183 | |
Sebastian Jansson | 6eb8a16 | 2018-11-16 10:29:55 | [diff] [blame] | 184 | VoiceMediaChannel* media_channel = media_engine_->voice().CreateMediaChannel( |
| 185 | call, media_config, options, crypto_options); |
Zhi Huang | 2dfc42d | 2017-12-04 21:38:48 | [diff] [blame] | 186 | if (!media_channel) { |
| 187 | return nullptr; |
| 188 | } |
| 189 | |
Karl Wiberg | 918f50c | 2018-07-05 09:40:33 | [diff] [blame] | 190 | auto voice_channel = absl::make_unique<VoiceChannel>( |
Amit Hilbuch | bcd39d4 | 2019-01-26 01:13:56 | [diff] [blame] | 191 | worker_thread_, network_thread_, signaling_thread, |
Karl Wiberg | 918f50c | 2018-07-05 09:40:33 | [diff] [blame] | 192 | absl::WrapUnique(media_channel), content_name, srtp_required, |
Amit Hilbuch | bcd39d4 | 2019-01-26 01:13:56 | [diff] [blame] | 193 | crypto_options, ssrc_generator); |
Zhi Huang | 2dfc42d | 2017-12-04 21:38:48 | [diff] [blame] | 194 | |
Anton Sukhanov | 4f08faa | 2019-05-21 18:12:57 | [diff] [blame] | 195 | voice_channel->Init_w(rtp_transport, media_transport_config); |
Zhi Huang | 2dfc42d | 2017-12-04 21:38:48 | [diff] [blame] | 196 | |
| 197 | VoiceChannel* voice_channel_ptr = voice_channel.get(); |
| 198 | voice_channels_.push_back(std::move(voice_channel)); |
| 199 | return voice_channel_ptr; |
| 200 | } |
| 201 | |
Fredrik Solenberg | 709ed67 | 2015-09-15 10:26:33 | [diff] [blame] | 202 | void ChannelManager::DestroyVoiceChannel(VoiceChannel* voice_channel) { |
Peter Boström | 1a9d615 | 2015-12-08 21:15:17 | [diff] [blame] | 203 | TRACE_EVENT0("webrtc", "ChannelManager::DestroyVoiceChannel"); |
Steve Anton | c9e1560 | 2017-11-06 23:40:09 | [diff] [blame] | 204 | if (!voice_channel) { |
| 205 | return; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 206 | } |
Steve Anton | c9e1560 | 2017-11-06 23:40:09 | [diff] [blame] | 207 | if (!worker_thread_->IsCurrent()) { |
| 208 | worker_thread_->Invoke<void>(RTC_FROM_HERE, |
| 209 | [&] { DestroyVoiceChannel(voice_channel); }); |
| 210 | return; |
| 211 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 212 | |
nisse | ede5da4 | 2017-01-12 13:15:36 | [diff] [blame] | 213 | RTC_DCHECK(initialized_); |
Steve Anton | 774115c | 2017-08-30 17:48:46 | [diff] [blame] | 214 | |
Steve Anton | 64b626b | 2019-01-29 01:25:26 | [diff] [blame] | 215 | auto it = absl::c_find_if(voice_channels_, |
| 216 | [&](const std::unique_ptr<VoiceChannel>& p) { |
| 217 | return p.get() == voice_channel; |
| 218 | }); |
nisse | ede5da4 | 2017-01-12 13:15:36 | [diff] [blame] | 219 | RTC_DCHECK(it != voice_channels_.end()); |
Steve Anton | c9e1560 | 2017-11-06 23:40:09 | [diff] [blame] | 220 | if (it == voice_channels_.end()) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 221 | return; |
Steve Anton | c9e1560 | 2017-11-06 23:40:09 | [diff] [blame] | 222 | } |
| 223 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 224 | voice_channels_.erase(it); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 225 | } |
| 226 | |
| 227 | VideoChannel* ChannelManager::CreateVideoChannel( |
nisse | eaabdf6 | 2017-05-05 09:23:02 | [diff] [blame] | 228 | webrtc::Call* call, |
| 229 | const cricket::MediaConfig& media_config, |
Zhi Huang | 2dfc42d | 2017-12-04 21:38:48 | [diff] [blame] | 230 | webrtc::RtpTransportInternal* rtp_transport, |
Anton Sukhanov | 4f08faa | 2019-05-21 18:12:57 | [diff] [blame] | 231 | const webrtc::MediaTransportConfig& media_transport_config, |
Zhi Huang | 2dfc42d | 2017-12-04 21:38:48 | [diff] [blame] | 232 | rtc::Thread* signaling_thread, |
| 233 | const std::string& content_name, |
| 234 | bool srtp_required, |
Benjamin Wright | a54daf1 | 2018-10-11 22:33:17 | [diff] [blame] | 235 | const webrtc::CryptoOptions& crypto_options, |
Amit Hilbuch | bcd39d4 | 2019-01-26 01:13:56 | [diff] [blame] | 236 | rtc::UniqueRandomIdGenerator* ssrc_generator, |
Jonas Oreland | a3aa9bd | 2019-04-17 05:38:40 | [diff] [blame] | 237 | const VideoOptions& options, |
| 238 | webrtc::VideoBitrateAllocatorFactory* video_bitrate_allocator_factory) { |
Zhi Huang | 2dfc42d | 2017-12-04 21:38:48 | [diff] [blame] | 239 | if (!worker_thread_->IsCurrent()) { |
| 240 | return worker_thread_->Invoke<VideoChannel*>(RTC_FROM_HERE, [&] { |
Anton Sukhanov | 4f08faa | 2019-05-21 18:12:57 | [diff] [blame] | 241 | return CreateVideoChannel( |
| 242 | call, media_config, rtp_transport, media_transport_config, |
| 243 | signaling_thread, content_name, srtp_required, crypto_options, |
| 244 | ssrc_generator, options, video_bitrate_allocator_factory); |
Zhi Huang | 2dfc42d | 2017-12-04 21:38:48 | [diff] [blame] | 245 | }); |
| 246 | } |
| 247 | |
| 248 | RTC_DCHECK_RUN_ON(worker_thread_); |
| 249 | RTC_DCHECK(initialized_); |
| 250 | RTC_DCHECK(call); |
| 251 | if (!media_engine_) { |
| 252 | return nullptr; |
| 253 | } |
| 254 | |
Sebastian Jansson | 6eb8a16 | 2018-11-16 10:29:55 | [diff] [blame] | 255 | VideoMediaChannel* media_channel = media_engine_->video().CreateMediaChannel( |
Jonas Oreland | a3aa9bd | 2019-04-17 05:38:40 | [diff] [blame] | 256 | call, media_config, options, crypto_options, |
| 257 | video_bitrate_allocator_factory); |
Zhi Huang | 2dfc42d | 2017-12-04 21:38:48 | [diff] [blame] | 258 | if (!media_channel) { |
| 259 | return nullptr; |
| 260 | } |
| 261 | |
Karl Wiberg | 918f50c | 2018-07-05 09:40:33 | [diff] [blame] | 262 | auto video_channel = absl::make_unique<VideoChannel>( |
Zhi Huang | 2dfc42d | 2017-12-04 21:38:48 | [diff] [blame] | 263 | worker_thread_, network_thread_, signaling_thread, |
Karl Wiberg | 918f50c | 2018-07-05 09:40:33 | [diff] [blame] | 264 | absl::WrapUnique(media_channel), content_name, srtp_required, |
Amit Hilbuch | bcd39d4 | 2019-01-26 01:13:56 | [diff] [blame] | 265 | crypto_options, ssrc_generator); |
Anton Sukhanov | 98a462c | 2018-10-17 20:15:42 | [diff] [blame] | 266 | |
Anton Sukhanov | 4f08faa | 2019-05-21 18:12:57 | [diff] [blame] | 267 | video_channel->Init_w(rtp_transport, media_transport_config); |
Zhi Huang | 2dfc42d | 2017-12-04 21:38:48 | [diff] [blame] | 268 | |
| 269 | VideoChannel* video_channel_ptr = video_channel.get(); |
| 270 | video_channels_.push_back(std::move(video_channel)); |
| 271 | return video_channel_ptr; |
| 272 | } |
| 273 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 274 | void ChannelManager::DestroyVideoChannel(VideoChannel* video_channel) { |
Peter Boström | 1a9d615 | 2015-12-08 21:15:17 | [diff] [blame] | 275 | TRACE_EVENT0("webrtc", "ChannelManager::DestroyVideoChannel"); |
Steve Anton | c9e1560 | 2017-11-06 23:40:09 | [diff] [blame] | 276 | if (!video_channel) { |
| 277 | return; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 278 | } |
Steve Anton | c9e1560 | 2017-11-06 23:40:09 | [diff] [blame] | 279 | if (!worker_thread_->IsCurrent()) { |
| 280 | worker_thread_->Invoke<void>(RTC_FROM_HERE, |
| 281 | [&] { DestroyVideoChannel(video_channel); }); |
| 282 | return; |
| 283 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 284 | |
nisse | ede5da4 | 2017-01-12 13:15:36 | [diff] [blame] | 285 | RTC_DCHECK(initialized_); |
Steve Anton | 774115c | 2017-08-30 17:48:46 | [diff] [blame] | 286 | |
Steve Anton | 64b626b | 2019-01-29 01:25:26 | [diff] [blame] | 287 | auto it = absl::c_find_if(video_channels_, |
| 288 | [&](const std::unique_ptr<VideoChannel>& p) { |
| 289 | return p.get() == video_channel; |
| 290 | }); |
nisse | ede5da4 | 2017-01-12 13:15:36 | [diff] [blame] | 291 | RTC_DCHECK(it != video_channels_.end()); |
Steve Anton | c9e1560 | 2017-11-06 23:40:09 | [diff] [blame] | 292 | if (it == video_channels_.end()) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 293 | return; |
Steve Anton | c9e1560 | 2017-11-06 23:40:09 | [diff] [blame] | 294 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 295 | |
| 296 | video_channels_.erase(it); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 297 | } |
| 298 | |
deadbeef | 953c2ce | 2017-01-09 22:53:41 | [diff] [blame] | 299 | RtpDataChannel* ChannelManager::CreateRtpDataChannel( |
nisse | eaabdf6 | 2017-05-05 09:23:02 | [diff] [blame] | 300 | const cricket::MediaConfig& media_config, |
Zhi Huang | 2dfc42d | 2017-12-04 21:38:48 | [diff] [blame] | 301 | webrtc::RtpTransportInternal* rtp_transport, |
| 302 | rtc::Thread* signaling_thread, |
| 303 | const std::string& content_name, |
Zhi Huang | e830e68 | 2018-03-30 17:48:35 | [diff] [blame] | 304 | bool srtp_required, |
Amit Hilbuch | bcd39d4 | 2019-01-26 01:13:56 | [diff] [blame] | 305 | const webrtc::CryptoOptions& crypto_options, |
| 306 | rtc::UniqueRandomIdGenerator* ssrc_generator) { |
Zhi Huang | 2dfc42d | 2017-12-04 21:38:48 | [diff] [blame] | 307 | if (!worker_thread_->IsCurrent()) { |
| 308 | return worker_thread_->Invoke<RtpDataChannel*>(RTC_FROM_HERE, [&] { |
| 309 | return CreateRtpDataChannel(media_config, rtp_transport, signaling_thread, |
Amit Hilbuch | bcd39d4 | 2019-01-26 01:13:56 | [diff] [blame] | 310 | content_name, srtp_required, crypto_options, |
| 311 | ssrc_generator); |
Zhi Huang | 2dfc42d | 2017-12-04 21:38:48 | [diff] [blame] | 312 | }); |
| 313 | } |
| 314 | |
| 315 | // This is ok to alloc from a thread other than the worker thread. |
| 316 | RTC_DCHECK(initialized_); |
| 317 | DataMediaChannel* media_channel = data_engine_->CreateChannel(media_config); |
| 318 | if (!media_channel) { |
| 319 | RTC_LOG(LS_WARNING) << "Failed to create RTP data channel."; |
| 320 | return nullptr; |
| 321 | } |
| 322 | |
Karl Wiberg | 918f50c | 2018-07-05 09:40:33 | [diff] [blame] | 323 | auto data_channel = absl::make_unique<RtpDataChannel>( |
Zhi Huang | 2dfc42d | 2017-12-04 21:38:48 | [diff] [blame] | 324 | worker_thread_, network_thread_, signaling_thread, |
Karl Wiberg | 918f50c | 2018-07-05 09:40:33 | [diff] [blame] | 325 | absl::WrapUnique(media_channel), content_name, srtp_required, |
Amit Hilbuch | bcd39d4 | 2019-01-26 01:13:56 | [diff] [blame] | 326 | crypto_options, ssrc_generator); |
Anton Sukhanov | 4f08faa | 2019-05-21 18:12:57 | [diff] [blame] | 327 | |
| 328 | // Media Transports are not supported with Rtp Data Channel. |
| 329 | data_channel->Init_w(rtp_transport, webrtc::MediaTransportConfig()); |
Zhi Huang | 2dfc42d | 2017-12-04 21:38:48 | [diff] [blame] | 330 | |
| 331 | RtpDataChannel* data_channel_ptr = data_channel.get(); |
| 332 | data_channels_.push_back(std::move(data_channel)); |
| 333 | return data_channel_ptr; |
| 334 | } |
| 335 | |
deadbeef | 953c2ce | 2017-01-09 22:53:41 | [diff] [blame] | 336 | void ChannelManager::DestroyRtpDataChannel(RtpDataChannel* data_channel) { |
| 337 | TRACE_EVENT0("webrtc", "ChannelManager::DestroyRtpDataChannel"); |
Steve Anton | c9e1560 | 2017-11-06 23:40:09 | [diff] [blame] | 338 | if (!data_channel) { |
| 339 | return; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 340 | } |
Steve Anton | c9e1560 | 2017-11-06 23:40:09 | [diff] [blame] | 341 | if (!worker_thread_->IsCurrent()) { |
| 342 | worker_thread_->Invoke<void>( |
| 343 | RTC_FROM_HERE, [&] { return DestroyRtpDataChannel(data_channel); }); |
| 344 | return; |
| 345 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 346 | |
nisse | ede5da4 | 2017-01-12 13:15:36 | [diff] [blame] | 347 | RTC_DCHECK(initialized_); |
Steve Anton | 774115c | 2017-08-30 17:48:46 | [diff] [blame] | 348 | |
Steve Anton | 64b626b | 2019-01-29 01:25:26 | [diff] [blame] | 349 | auto it = absl::c_find_if(data_channels_, |
| 350 | [&](const std::unique_ptr<RtpDataChannel>& p) { |
| 351 | return p.get() == data_channel; |
| 352 | }); |
nisse | ede5da4 | 2017-01-12 13:15:36 | [diff] [blame] | 353 | RTC_DCHECK(it != data_channels_.end()); |
Steve Anton | c9e1560 | 2017-11-06 23:40:09 | [diff] [blame] | 354 | if (it == data_channels_.end()) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 355 | return; |
Steve Anton | c9e1560 | 2017-11-06 23:40:09 | [diff] [blame] | 356 | } |
Zhi Huang | 95e7dbb | 2018-03-29 00:08:03 | [diff] [blame] | 357 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 358 | data_channels_.erase(it); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 359 | } |
| 360 | |
ivoc | d66b44d | 2016-01-15 11:06:36 | [diff] [blame] | 361 | bool ChannelManager::StartAecDump(rtc::PlatformFile file, |
| 362 | int64_t max_size_bytes) { |
Steve Anton | c9e1560 | 2017-11-06 23:40:09 | [diff] [blame] | 363 | return worker_thread_->Invoke<bool>(RTC_FROM_HERE, [&] { |
Sebastian Jansson | 6eb8a16 | 2018-11-16 10:29:55 | [diff] [blame] | 364 | return media_engine_->voice().StartAecDump(file, max_size_bytes); |
Steve Anton | c9e1560 | 2017-11-06 23:40:09 | [diff] [blame] | 365 | }); |
wu@webrtc.org | a989080 | 2013-12-13 00:21:03 | [diff] [blame] | 366 | } |
| 367 | |
ivoc | 797ef12 | 2015-10-22 10:25:41 | [diff] [blame] | 368 | void ChannelManager::StopAecDump() { |
Steve Anton | c9e1560 | 2017-11-06 23:40:09 | [diff] [blame] | 369 | worker_thread_->Invoke<void>(RTC_FROM_HERE, |
Sebastian Jansson | 6eb8a16 | 2018-11-16 10:29:55 | [diff] [blame] | 370 | [&] { media_engine_->voice().StopAecDump(); }); |
ivoc | 797ef12 | 2015-10-22 10:25:41 | [diff] [blame] | 371 | } |
| 372 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 373 | } // namespace cricket |