blob: cdfed68bb6bbd7f98b70c2f13a5bec3da48f4e57 [file] [log] [blame]
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001/*
kjellander65c7f672016-02-12 00:05:01 -08002 * Copyright 2004 The WebRTC project authors. All Rights Reserved.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003 *
kjellander65c7f672016-02-12 00:05:01 -08004 * 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.org28e20752013-07-10 00:45:36 +00009 */
10
kjellander@webrtc.org9b8df252016-02-12 06:47:59 +010011#include "webrtc/pc/channelmanager.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000012
henrike@webrtc.org28e20752013-07-10 00:45:36 +000013#include <algorithm>
14
Henrik Kjellander15583c12016-02-10 10:53:12 +010015#include "webrtc/api/mediacontroller.h"
16#include "webrtc/base/bind.h"
17#include "webrtc/base/common.h"
18#include "webrtc/base/logging.h"
Henrik Kjellander15583c12016-02-10 10:53:12 +010019#include "webrtc/base/stringencode.h"
20#include "webrtc/base/stringutils.h"
21#include "webrtc/base/trace_event.h"
kjellandera96e2d72016-02-04 23:52:28 -080022#include "webrtc/media/base/device.h"
kjellandera96e2d72016-02-04 23:52:28 -080023#include "webrtc/media/base/rtpdataengine.h"
kjellander@webrtc.org9b8df252016-02-12 06:47:59 +010024#include "webrtc/pc/srtpfilter.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000025
26namespace cricket {
27
henrike@webrtc.org28e20752013-07-10 00:45:36 +000028
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000029using rtc::Bind;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000030
henrike@webrtc.org28e20752013-07-10 00:45:36 +000031static DataEngineInterface* ConstructDataEngine() {
henrike@webrtc.org28e20752013-07-10 00:45:36 +000032 return new RtpDataEngine();
henrike@webrtc.org28e20752013-07-10 00:45:36 +000033}
34
henrike@webrtc.org28e20752013-07-10 00:45:36 +000035ChannelManager::ChannelManager(MediaEngineInterface* me,
36 DataEngineInterface* dme,
Danil Chapovalov33b01f22016-05-11 19:55:27 +020037 rtc::Thread* thread) {
38 Construct(me, dme, thread, thread);
henrike@webrtc.org28e20752013-07-10 00:45:36 +000039}
40
41ChannelManager::ChannelManager(MediaEngineInterface* me,
Danil Chapovalov33b01f22016-05-11 19:55:27 +020042 rtc::Thread* worker_thread,
43 rtc::Thread* network_thread) {
44 Construct(me, ConstructDataEngine(), worker_thread, network_thread);
henrike@webrtc.org28e20752013-07-10 00:45:36 +000045}
46
47void ChannelManager::Construct(MediaEngineInterface* me,
48 DataEngineInterface* dme,
Danil Chapovalov33b01f22016-05-11 19:55:27 +020049 rtc::Thread* worker_thread,
50 rtc::Thread* network_thread) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +000051 media_engine_.reset(me);
52 data_media_engine_.reset(dme);
henrike@webrtc.org28e20752013-07-10 00:45:36 +000053 initialized_ = false;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000054 main_thread_ = rtc::Thread::Current();
henrike@webrtc.org28e20752013-07-10 00:45:36 +000055 worker_thread_ = worker_thread;
Danil Chapovalov33b01f22016-05-11 19:55:27 +020056 network_thread_ = network_thread;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000057 capturing_ = false;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000058 enable_rtx_ = false;
jbauchcb560652016-08-04 05:20:32 -070059 crypto_options_ = rtc::CryptoOptions::NoGcm();
henrike@webrtc.org28e20752013-07-10 00:45:36 +000060}
61
62ChannelManager::~ChannelManager() {
wu@webrtc.org9dba5252013-08-05 20:36:57 +000063 if (initialized_) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +000064 Terminate();
wu@webrtc.org9dba5252013-08-05 20:36:57 +000065 // 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 }
perkjc11b1842016-03-07 17:34:13 -080072 // The media engine needs to be deleted on the worker thread for thread safe
73 // destruction,
Taylor Brandstetter5d97a9a2016-06-10 14:17:27 -070074 worker_thread_->Invoke<void>(
75 RTC_FROM_HERE, Bind(&ChannelManager::DestructorDeletes_w, this));
henrike@webrtc.org28e20752013-07-10 00:45:36 +000076}
77
78bool 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
jbauchcb560652016-08-04 05:20:32 -070093bool 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
99bool 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
ossudedfd282016-06-14 07:12:39 -0700117void ChannelManager::GetSupportedAudioSendCodecs(
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000118 std::vector<AudioCodec>* codecs) const {
ossudedfd282016-06-14 07:12:39 -0700119 *codecs = media_engine_->audio_send_codecs();
120}
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000121
ossudedfd282016-06-14 07:12:39 -0700122void ChannelManager::GetSupportedAudioReceiveCodecs(
123 std::vector<AudioCodec>* codecs) const {
124 *codecs = media_engine_->audio_recv_codecs();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000125}
126
127void ChannelManager::GetSupportedAudioRtpHeaderExtensions(
128 RtpHeaderExtensions* ext) const {
Stefan Holmer9d69c3f2015-12-07 10:45:43 +0100129 *ext = media_engine_->GetAudioCapabilities().header_extensions;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000130}
131
magjed3cf8ece2016-11-10 03:36:53 -0800132void ChannelManager::GetSupportedVideoCodecs(
133 std::vector<VideoCodec>* codecs) const {
134 codecs->clear();
135
brandtrffc61182016-11-28 06:02:22 -0800136 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) {
magjed3cf8ece2016-11-10 03:36:53 -0800140 continue;
141 }
brandtrffc61182016-11-28 06:02:22 -0800142 codecs->push_back(video_codec);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000143 }
144}
145
146void ChannelManager::GetSupportedVideoRtpHeaderExtensions(
147 RtpHeaderExtensions* ext) const {
Stefan Holmer9d69c3f2015-12-07 10:45:43 +0100148 *ext = media_engine_->GetVideoCapabilities().header_extensions;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000149}
150
151void ChannelManager::GetSupportedDataCodecs(
152 std::vector<DataCodec>* codecs) const {
153 *codecs = data_media_engine_->data_codecs();
154}
155
156bool ChannelManager::Init() {
157 ASSERT(!initialized_);
158 if (initialized_) {
159 return false;
160 }
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200161 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 Brandstetter5d97a9a2016-06-10 14:17:27 -0700166 RTC_FROM_HERE,
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200167 rtc::Bind(&rtc::Thread::SetAllowBlockingCalls, network_thread_, false));
henrika@webrtc.org62f6e752015-02-11 08:38:35 +0000168 }
169
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200170 initialized_ = worker_thread_->Invoke<bool>(
Taylor Brandstetter5d97a9a2016-06-10 14:17:27 -0700171 RTC_FROM_HERE, Bind(&ChannelManager::InitMediaEngine_w, this));
henrika@webrtc.org62f6e752015-02-11 08:38:35 +0000172 ASSERT(initialized_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000173 return initialized_;
174}
175
henrika@webrtc.org62f6e752015-02-11 08:38:35 +0000176bool ChannelManager::InitMediaEngine_w() {
177 ASSERT(worker_thread_ == rtc::Thread::Current());
solenbergff976312016-03-30 23:28:51 -0700178 return media_engine_->Init();
henrika@webrtc.org62f6e752015-02-11 08:38:35 +0000179}
180
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000181void ChannelManager::Terminate() {
182 ASSERT(initialized_);
183 if (!initialized_) {
184 return;
185 }
Taylor Brandstetter5d97a9a2016-06-10 14:17:27 -0700186 worker_thread_->Invoke<void>(RTC_FROM_HERE,
187 Bind(&ChannelManager::Terminate_w, this));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000188 initialized_ = false;
189}
190
hbos@webrtc.org4aef5fe2015-02-25 10:09:05 +0000191void ChannelManager::DestructorDeletes_w() {
henrika@webrtc.org62f6e752015-02-11 08:38:35 +0000192 ASSERT(worker_thread_ == rtc::Thread::Current());
193 media_engine_.reset(NULL);
194}
195
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000196void ChannelManager::Terminate_w() {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000197 ASSERT(worker_thread_ == rtc::Thread::Current());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000198 // 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 Solenberg709ed672015-09-15 12:26:33 +0200203 DestroyVoiceChannel_w(voice_channels_.back());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000204 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000205}
206
207VoiceChannel* ChannelManager::CreateVoiceChannel(
Fredrik Solenberg709ed672015-09-15 12:26:33 +0200208 webrtc::MediaControllerInterface* media_controller,
deadbeefcbecd352015-09-23 11:50:27 -0700209 TransportController* transport_controller,
Jelena Marusicc28a8962015-05-29 15:05:44 +0200210 const std::string& content_name,
skvlad6c87a672016-05-17 17:49:52 -0700211 const std::string* bundle_transport_name,
Jelena Marusicc28a8962015-05-29 15:05:44 +0200212 bool rtcp,
deadbeef7af91dd2016-12-13 11:29:11 -0800213 bool srtp_required,
Jelena Marusicc28a8962015-05-29 15:05:44 +0200214 const AudioOptions& options) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000215 return worker_thread_->Invoke<VoiceChannel*>(
Taylor Brandstetter5d97a9a2016-06-10 14:17:27 -0700216 RTC_FROM_HERE, Bind(&ChannelManager::CreateVoiceChannel_w, this,
217 media_controller, transport_controller, content_name,
deadbeef7af91dd2016-12-13 11:29:11 -0800218 bundle_transport_name, rtcp, srtp_required, options));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000219}
220
221VoiceChannel* ChannelManager::CreateVoiceChannel_w(
Fredrik Solenberg709ed672015-09-15 12:26:33 +0200222 webrtc::MediaControllerInterface* media_controller,
deadbeefcbecd352015-09-23 11:50:27 -0700223 TransportController* transport_controller,
Jelena Marusicc28a8962015-05-29 15:05:44 +0200224 const std::string& content_name,
skvlad6c87a672016-05-17 17:49:52 -0700225 const std::string* bundle_transport_name,
Jelena Marusicc28a8962015-05-29 15:05:44 +0200226 bool rtcp,
deadbeef7af91dd2016-12-13 11:29:11 -0800227 bool srtp_required,
Jelena Marusicc28a8962015-05-29 15:05:44 +0200228 const AudioOptions& options) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000229 ASSERT(initialized_);
Fredrik Solenberg4b60c732015-05-07 14:07:48 +0200230 ASSERT(worker_thread_ == rtc::Thread::Current());
Fredrik Solenberg709ed672015-09-15 12:26:33 +0200231 ASSERT(nullptr != media_controller);
nisse51542be2016-02-12 02:27:06 -0800232 VoiceMediaChannel* media_channel = media_engine_->CreateChannel(
233 media_controller->call_w(), media_controller->config(), options);
Jelena Marusicc28a8962015-05-29 15:05:44 +0200234 if (!media_channel)
235 return nullptr;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000236
deadbeef7af91dd2016-12-13 11:29:11 -0800237 VoiceChannel* voice_channel = new VoiceChannel(
238 worker_thread_, network_thread_, media_engine_.get(), media_channel,
239 transport_controller, content_name, rtcp, srtp_required);
jbauchcb560652016-08-04 05:20:32 -0700240 voice_channel->SetCryptoOptions(crypto_options_);
skvlad6c87a672016-05-17 17:49:52 -0700241 if (!voice_channel->Init_w(bundle_transport_name)) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000242 delete voice_channel;
Jelena Marusicc28a8962015-05-29 15:05:44 +0200243 return nullptr;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000244 }
245 voice_channels_.push_back(voice_channel);
246 return voice_channel;
247}
248
Fredrik Solenberg709ed672015-09-15 12:26:33 +0200249void ChannelManager::DestroyVoiceChannel(VoiceChannel* voice_channel) {
Peter Boström1a9d6152015-12-08 22:15:17 +0100250 TRACE_EVENT0("webrtc", "ChannelManager::DestroyVoiceChannel");
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000251 if (voice_channel) {
252 worker_thread_->Invoke<void>(
Taylor Brandstetter5d97a9a2016-06-10 14:17:27 -0700253 RTC_FROM_HERE,
Fredrik Solenberg709ed672015-09-15 12:26:33 +0200254 Bind(&ChannelManager::DestroyVoiceChannel_w, this, voice_channel));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000255 }
256}
257
Fredrik Solenberg709ed672015-09-15 12:26:33 +0200258void ChannelManager::DestroyVoiceChannel_w(VoiceChannel* voice_channel) {
Peter Boström1a9d6152015-12-08 22:15:17 +0100259 TRACE_EVENT0("webrtc", "ChannelManager::DestroyVoiceChannel_w");
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000260 // Destroy voice channel.
261 ASSERT(initialized_);
Fredrik Solenberg4b60c732015-05-07 14:07:48 +0200262 ASSERT(worker_thread_ == rtc::Thread::Current());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000263 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.org28e20752013-07-10 00:45:36 +0000268 voice_channels_.erase(it);
269 delete voice_channel;
270}
271
272VideoChannel* ChannelManager::CreateVideoChannel(
Fredrik Solenberg709ed672015-09-15 12:26:33 +0200273 webrtc::MediaControllerInterface* media_controller,
deadbeefcbecd352015-09-23 11:50:27 -0700274 TransportController* transport_controller,
buildbot@webrtc.org1ecbe452014-10-14 20:29:28 +0000275 const std::string& content_name,
skvlad6c87a672016-05-17 17:49:52 -0700276 const std::string* bundle_transport_name,
buildbot@webrtc.org1ecbe452014-10-14 20:29:28 +0000277 bool rtcp,
deadbeef7af91dd2016-12-13 11:29:11 -0800278 bool srtp_required,
Fredrik Solenberg709ed672015-09-15 12:26:33 +0200279 const VideoOptions& options) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000280 return worker_thread_->Invoke<VideoChannel*>(
Taylor Brandstetter5d97a9a2016-06-10 14:17:27 -0700281 RTC_FROM_HERE, Bind(&ChannelManager::CreateVideoChannel_w, this,
282 media_controller, transport_controller, content_name,
deadbeef7af91dd2016-12-13 11:29:11 -0800283 bundle_transport_name, rtcp, srtp_required, options));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000284}
285
286VideoChannel* ChannelManager::CreateVideoChannel_w(
Fredrik Solenberg709ed672015-09-15 12:26:33 +0200287 webrtc::MediaControllerInterface* media_controller,
deadbeefcbecd352015-09-23 11:50:27 -0700288 TransportController* transport_controller,
buildbot@webrtc.org1ecbe452014-10-14 20:29:28 +0000289 const std::string& content_name,
skvlad6c87a672016-05-17 17:49:52 -0700290 const std::string* bundle_transport_name,
buildbot@webrtc.org1ecbe452014-10-14 20:29:28 +0000291 bool rtcp,
deadbeef7af91dd2016-12-13 11:29:11 -0800292 bool srtp_required,
Fredrik Solenberg709ed672015-09-15 12:26:33 +0200293 const VideoOptions& options) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000294 ASSERT(initialized_);
Fredrik Solenberg4b60c732015-05-07 14:07:48 +0200295 ASSERT(worker_thread_ == rtc::Thread::Current());
Fredrik Solenberg709ed672015-09-15 12:26:33 +0200296 ASSERT(nullptr != media_controller);
nisse51542be2016-02-12 02:27:06 -0800297 VideoMediaChannel* media_channel = media_engine_->CreateVideoChannel(
298 media_controller->call_w(), media_controller->config(), options);
deadbeefcbecd352015-09-23 11:50:27 -0700299 if (media_channel == NULL) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000300 return NULL;
deadbeefcbecd352015-09-23 11:50:27 -0700301 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000302
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200303 VideoChannel* video_channel =
304 new VideoChannel(worker_thread_, network_thread_, media_channel,
deadbeef7af91dd2016-12-13 11:29:11 -0800305 transport_controller, content_name, rtcp, srtp_required);
jbauchcb560652016-08-04 05:20:32 -0700306 video_channel->SetCryptoOptions(crypto_options_);
skvlad6c87a672016-05-17 17:49:52 -0700307 if (!video_channel->Init_w(bundle_transport_name)) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000308 delete video_channel;
309 return NULL;
310 }
311 video_channels_.push_back(video_channel);
312 return video_channel;
313}
314
315void ChannelManager::DestroyVideoChannel(VideoChannel* video_channel) {
Peter Boström1a9d6152015-12-08 22:15:17 +0100316 TRACE_EVENT0("webrtc", "ChannelManager::DestroyVideoChannel");
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000317 if (video_channel) {
318 worker_thread_->Invoke<void>(
Taylor Brandstetter5d97a9a2016-06-10 14:17:27 -0700319 RTC_FROM_HERE,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000320 Bind(&ChannelManager::DestroyVideoChannel_w, this, video_channel));
321 }
322}
323
324void ChannelManager::DestroyVideoChannel_w(VideoChannel* video_channel) {
Peter Boström1a9d6152015-12-08 22:15:17 +0100325 TRACE_EVENT0("webrtc", "ChannelManager::DestroyVideoChannel_w");
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000326 // Destroy video channel.
327 ASSERT(initialized_);
Fredrik Solenberg4b60c732015-05-07 14:07:48 +0200328 ASSERT(worker_thread_ == rtc::Thread::Current());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000329 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
deadbeef953c2ce2017-01-09 14:53:41 -0800339RtpDataChannel* ChannelManager::CreateRtpDataChannel(
zhihuangebbe4f22016-12-06 10:45:42 -0800340 webrtc::MediaControllerInterface* media_controller,
deadbeef7af91dd2016-12-13 11:29:11 -0800341 TransportController* transport_controller,
zhihuangebbe4f22016-12-06 10:45:42 -0800342 const std::string& content_name,
343 const std::string* bundle_transport_name,
344 bool rtcp,
deadbeef953c2ce2017-01-09 14:53:41 -0800345 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.org28e20752013-07-10 00:45:36 +0000350}
351
deadbeef953c2ce2017-01-09 14:53:41 -0800352RtpDataChannel* ChannelManager::CreateRtpDataChannel_w(
deadbeef7af91dd2016-12-13 11:29:11 -0800353 webrtc::MediaControllerInterface* media_controller,
deadbeefcbecd352015-09-23 11:50:27 -0700354 TransportController* transport_controller,
355 const std::string& content_name,
skvlad6c87a672016-05-17 17:49:52 -0700356 const std::string* bundle_transport_name,
deadbeefcbecd352015-09-23 11:50:27 -0700357 bool rtcp,
deadbeef953c2ce2017-01-09 14:53:41 -0800358 bool srtp_required) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000359 // This is ok to alloc from a thread other than the worker thread.
360 ASSERT(initialized_);
zhihuangebbe4f22016-12-06 10:45:42 -0800361 MediaConfig config;
362 if (media_controller) {
363 config = media_controller->config();
364 }
deadbeef953c2ce2017-01-09 14:53:41 -0800365 DataMediaChannel* media_channel = data_media_engine_->CreateChannel(config);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000366 if (!media_channel) {
deadbeef953c2ce2017-01-09 14:53:41 -0800367 LOG(LS_WARNING) << "Failed to create RTP data channel.";
368 return nullptr;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000369 }
370
deadbeef953c2ce2017-01-09 14:53:41 -0800371 RtpDataChannel* data_channel = new RtpDataChannel(
372 worker_thread_, network_thread_, media_channel, transport_controller,
373 content_name, rtcp, srtp_required);
jbauchcb560652016-08-04 05:20:32 -0700374 data_channel->SetCryptoOptions(crypto_options_);
skvlad6c87a672016-05-17 17:49:52 -0700375 if (!data_channel->Init_w(bundle_transport_name)) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000376 LOG(LS_WARNING) << "Failed to init data channel.";
377 delete data_channel;
deadbeef953c2ce2017-01-09 14:53:41 -0800378 return nullptr;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000379 }
380 data_channels_.push_back(data_channel);
381 return data_channel;
382}
383
deadbeef953c2ce2017-01-09 14:53:41 -0800384void ChannelManager::DestroyRtpDataChannel(RtpDataChannel* data_channel) {
385 TRACE_EVENT0("webrtc", "ChannelManager::DestroyRtpDataChannel");
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000386 if (data_channel) {
387 worker_thread_->Invoke<void>(
Taylor Brandstetter5d97a9a2016-06-10 14:17:27 -0700388 RTC_FROM_HERE,
deadbeef953c2ce2017-01-09 14:53:41 -0800389 Bind(&ChannelManager::DestroyRtpDataChannel_w, this, data_channel));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000390 }
391}
392
deadbeef953c2ce2017-01-09 14:53:41 -0800393void ChannelManager::DestroyRtpDataChannel_w(RtpDataChannel* data_channel) {
394 TRACE_EVENT0("webrtc", "ChannelManager::DestroyRtpDataChannel_w");
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000395 // Destroy data channel.
396 ASSERT(initialized_);
deadbeef953c2ce2017-01-09 14:53:41 -0800397 RtpDataChannels::iterator it =
398 std::find(data_channels_.begin(), data_channels_.end(), data_channel);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000399 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
ivocd66b44d2016-01-15 03:06:36 -0800407bool ChannelManager::StartAecDump(rtc::PlatformFile file,
408 int64_t max_size_bytes) {
Taylor Brandstetter5d97a9a2016-06-10 14:17:27 -0700409 return worker_thread_->Invoke<bool>(
410 RTC_FROM_HERE, Bind(&MediaEngineInterface::StartAecDump,
411 media_engine_.get(), file, max_size_bytes));
wu@webrtc.orga9890802013-12-13 00:21:03 +0000412}
413
ivoc797ef122015-10-22 03:25:41 -0700414void ChannelManager::StopAecDump() {
415 worker_thread_->Invoke<void>(
Taylor Brandstetter5d97a9a2016-06-10 14:17:27 -0700416 RTC_FROM_HERE,
ivoc797ef122015-10-22 03:25:41 -0700417 Bind(&MediaEngineInterface::StopAecDump, media_engine_.get()));
418}
419
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000420} // namespace cricket