2013-07-10 00:45:36 +00:00
|
|
|
/*
|
2016-02-12 00:05:01 -08:00
|
|
|
* Copyright 2004 The WebRTC project authors. All Rights Reserved.
|
2013-07-10 00:45:36 +00:00
|
|
|
*
|
2016-02-12 00:05:01 -08:00
|
|
|
* Use of this source code is governed by a BSD-style license
|
|
|
|
|
* that can be found in the LICENSE file in the root of the source
|
|
|
|
|
* tree. An additional intellectual property rights grant can be found
|
|
|
|
|
* in the file PATENTS. All contributing project authors may
|
|
|
|
|
* be found in the AUTHORS file in the root of the source tree.
|
2013-07-10 00:45:36 +00:00
|
|
|
*/
|
|
|
|
|
|
2016-02-12 06:47:59 +01:00
|
|
|
#include "webrtc/pc/channelmanager.h"
|
2013-07-10 00:45:36 +00:00
|
|
|
|
|
|
|
|
#include <algorithm>
|
|
|
|
|
|
2016-02-10 10:53:12 +01:00
|
|
|
#include "webrtc/media/base/device.h"
|
|
|
|
|
#include "webrtc/media/base/rtpdataengine.h"
|
2016-02-12 06:47:59 +01:00
|
|
|
#include "webrtc/pc/srtpfilter.h"
|
2017-07-06 19:44:34 +02:00
|
|
|
#include "webrtc/rtc_base/bind.h"
|
|
|
|
|
#include "webrtc/rtc_base/checks.h"
|
|
|
|
|
#include "webrtc/rtc_base/logging.h"
|
|
|
|
|
#include "webrtc/rtc_base/stringencode.h"
|
|
|
|
|
#include "webrtc/rtc_base/stringutils.h"
|
|
|
|
|
#include "webrtc/rtc_base/trace_event.h"
|
2013-07-10 00:45:36 +00:00
|
|
|
|
|
|
|
|
namespace cricket {
|
|
|
|
|
|
|
|
|
|
|
2014-07-29 17:36:52 +00:00
|
|
|
using rtc::Bind;
|
2013-07-10 00:45:36 +00:00
|
|
|
|
2017-02-10 20:13:37 -08:00
|
|
|
ChannelManager::ChannelManager(std::unique_ptr<MediaEngineInterface> me,
|
|
|
|
|
std::unique_ptr<DataEngineInterface> dme,
|
2016-05-11 19:55:27 +02:00
|
|
|
rtc::Thread* thread) {
|
2017-02-10 20:13:37 -08:00
|
|
|
Construct(std::move(me), std::move(dme), thread, thread);
|
2013-07-10 00:45:36 +00:00
|
|
|
}
|
|
|
|
|
|
2017-02-10 20:13:37 -08:00
|
|
|
ChannelManager::ChannelManager(std::unique_ptr<MediaEngineInterface> me,
|
2016-05-11 19:55:27 +02:00
|
|
|
rtc::Thread* worker_thread,
|
|
|
|
|
rtc::Thread* network_thread) {
|
2017-02-10 20:13:37 -08:00
|
|
|
Construct(std::move(me),
|
|
|
|
|
std::unique_ptr<DataEngineInterface>(new RtpDataEngine()),
|
|
|
|
|
worker_thread, network_thread);
|
2013-07-10 00:45:36 +00:00
|
|
|
}
|
|
|
|
|
|
2017-02-10 20:13:37 -08:00
|
|
|
void ChannelManager::Construct(std::unique_ptr<MediaEngineInterface> me,
|
|
|
|
|
std::unique_ptr<DataEngineInterface> dme,
|
2016-05-11 19:55:27 +02:00
|
|
|
rtc::Thread* worker_thread,
|
|
|
|
|
rtc::Thread* network_thread) {
|
2017-02-10 20:13:37 -08:00
|
|
|
media_engine_ = std::move(me);
|
|
|
|
|
data_media_engine_ = std::move(dme);
|
2013-07-10 00:45:36 +00:00
|
|
|
initialized_ = false;
|
2014-07-29 17:36:52 +00:00
|
|
|
main_thread_ = rtc::Thread::Current();
|
2013-07-10 00:45:36 +00:00
|
|
|
worker_thread_ = worker_thread;
|
2016-05-11 19:55:27 +02:00
|
|
|
network_thread_ = network_thread;
|
2013-07-10 00:45:36 +00:00
|
|
|
capturing_ = false;
|
|
|
|
|
enable_rtx_ = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ChannelManager::~ChannelManager() {
|
2013-08-05 20:36:57 +00:00
|
|
|
if (initialized_) {
|
2013-07-10 00:45:36 +00:00
|
|
|
Terminate();
|
2013-08-05 20:36:57 +00:00
|
|
|
// If srtp is initialized (done by the Channel) then we must call
|
|
|
|
|
// srtp_shutdown to free all crypto kernel lists. But we need to make sure
|
|
|
|
|
// shutdown always called at the end, after channels are destroyed.
|
|
|
|
|
// ChannelManager d'tor is always called last, it's safe place to call
|
|
|
|
|
// shutdown.
|
|
|
|
|
ShutdownSrtp();
|
|
|
|
|
}
|
2016-03-07 17:34:13 -08:00
|
|
|
// The media engine needs to be deleted on the worker thread for thread safe
|
|
|
|
|
// destruction,
|
2016-06-10 14:17:27 -07:00
|
|
|
worker_thread_->Invoke<void>(
|
|
|
|
|
RTC_FROM_HERE, Bind(&ChannelManager::DestructorDeletes_w, this));
|
2013-07-10 00:45:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool ChannelManager::SetVideoRtxEnabled(bool enable) {
|
|
|
|
|
// To be safe, this call is only allowed before initialization. Apps like
|
|
|
|
|
// Flute only have a singleton ChannelManager and we don't want this flag to
|
|
|
|
|
// be toggled between calls or when there's concurrent calls. We expect apps
|
|
|
|
|
// to enable this at startup and retain that setting for the lifetime of the
|
|
|
|
|
// app.
|
|
|
|
|
if (!initialized_) {
|
|
|
|
|
enable_rtx_ = enable;
|
|
|
|
|
return true;
|
|
|
|
|
} else {
|
|
|
|
|
LOG(LS_WARNING) << "Cannot toggle rtx after initialization!";
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-06-14 07:12:39 -07:00
|
|
|
void ChannelManager::GetSupportedAudioSendCodecs(
|
2013-07-10 00:45:36 +00:00
|
|
|
std::vector<AudioCodec>* codecs) const {
|
2017-06-15 12:52:32 -07:00
|
|
|
if (!media_engine_) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2016-06-14 07:12:39 -07:00
|
|
|
*codecs = media_engine_->audio_send_codecs();
|
|
|
|
|
}
|
2013-07-10 00:45:36 +00:00
|
|
|
|
2016-06-14 07:12:39 -07:00
|
|
|
void ChannelManager::GetSupportedAudioReceiveCodecs(
|
|
|
|
|
std::vector<AudioCodec>* codecs) const {
|
2017-06-15 12:52:32 -07:00
|
|
|
if (!media_engine_) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2016-06-14 07:12:39 -07:00
|
|
|
*codecs = media_engine_->audio_recv_codecs();
|
2013-07-10 00:45:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ChannelManager::GetSupportedAudioRtpHeaderExtensions(
|
|
|
|
|
RtpHeaderExtensions* ext) const {
|
2017-06-15 12:52:32 -07:00
|
|
|
if (!media_engine_) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2015-12-07 10:45:43 +01:00
|
|
|
*ext = media_engine_->GetAudioCapabilities().header_extensions;
|
2013-07-10 00:45:36 +00:00
|
|
|
}
|
|
|
|
|
|
2016-11-10 03:36:53 -08:00
|
|
|
void ChannelManager::GetSupportedVideoCodecs(
|
|
|
|
|
std::vector<VideoCodec>* codecs) const {
|
2017-06-15 12:52:32 -07:00
|
|
|
if (!media_engine_) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2016-11-10 03:36:53 -08:00
|
|
|
codecs->clear();
|
|
|
|
|
|
2016-11-28 06:02:22 -08:00
|
|
|
std::vector<VideoCodec> video_codecs = media_engine_->video_codecs();
|
|
|
|
|
for (const auto& video_codec : video_codecs) {
|
|
|
|
|
if (!enable_rtx_ &&
|
|
|
|
|
_stricmp(kRtxCodecName, video_codec.name.c_str()) == 0) {
|
2016-11-10 03:36:53 -08:00
|
|
|
continue;
|
|
|
|
|
}
|
2016-11-28 06:02:22 -08:00
|
|
|
codecs->push_back(video_codec);
|
2013-07-10 00:45:36 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ChannelManager::GetSupportedVideoRtpHeaderExtensions(
|
|
|
|
|
RtpHeaderExtensions* ext) const {
|
2017-06-15 12:52:32 -07:00
|
|
|
if (!media_engine_) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2015-12-07 10:45:43 +01:00
|
|
|
*ext = media_engine_->GetVideoCapabilities().header_extensions;
|
2013-07-10 00:45:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ChannelManager::GetSupportedDataCodecs(
|
|
|
|
|
std::vector<DataCodec>* codecs) const {
|
2017-06-15 12:52:32 -07:00
|
|
|
if (!data_media_engine_) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2013-07-10 00:45:36 +00:00
|
|
|
*codecs = data_media_engine_->data_codecs();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool ChannelManager::Init() {
|
2017-01-12 05:15:36 -08:00
|
|
|
RTC_DCHECK(!initialized_);
|
2013-07-10 00:45:36 +00:00
|
|
|
if (initialized_) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2016-05-11 19:55:27 +02:00
|
|
|
RTC_DCHECK(network_thread_);
|
|
|
|
|
RTC_DCHECK(worker_thread_);
|
|
|
|
|
if (!network_thread_->IsCurrent()) {
|
|
|
|
|
// Do not allow invoking calls to other threads on the network thread.
|
|
|
|
|
network_thread_->Invoke<bool>(
|
2016-06-10 14:17:27 -07:00
|
|
|
RTC_FROM_HERE,
|
2016-05-11 19:55:27 +02:00
|
|
|
rtc::Bind(&rtc::Thread::SetAllowBlockingCalls, network_thread_, false));
|
2015-02-11 08:38:35 +00:00
|
|
|
}
|
2014-09-29 22:45:55 +00:00
|
|
|
|
2016-05-11 19:55:27 +02:00
|
|
|
initialized_ = worker_thread_->Invoke<bool>(
|
2016-06-10 14:17:27 -07:00
|
|
|
RTC_FROM_HERE, Bind(&ChannelManager::InitMediaEngine_w, this));
|
2017-01-12 05:15:36 -08:00
|
|
|
RTC_DCHECK(initialized_);
|
2013-07-10 00:45:36 +00:00
|
|
|
return initialized_;
|
|
|
|
|
}
|
|
|
|
|
|
2015-02-11 08:38:35 +00:00
|
|
|
bool ChannelManager::InitMediaEngine_w() {
|
2017-01-12 05:15:36 -08:00
|
|
|
RTC_DCHECK(worker_thread_ == rtc::Thread::Current());
|
2017-06-15 12:52:32 -07:00
|
|
|
if (media_engine_) {
|
|
|
|
|
return media_engine_->Init();
|
|
|
|
|
}
|
|
|
|
|
return true;
|
2015-02-11 08:38:35 +00:00
|
|
|
}
|
|
|
|
|
|
2013-07-10 00:45:36 +00:00
|
|
|
void ChannelManager::Terminate() {
|
2017-01-12 05:15:36 -08:00
|
|
|
RTC_DCHECK(initialized_);
|
2013-07-10 00:45:36 +00:00
|
|
|
if (!initialized_) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2016-06-10 14:17:27 -07:00
|
|
|
worker_thread_->Invoke<void>(RTC_FROM_HERE,
|
|
|
|
|
Bind(&ChannelManager::Terminate_w, this));
|
2013-07-10 00:45:36 +00:00
|
|
|
initialized_ = false;
|
|
|
|
|
}
|
|
|
|
|
|
2015-02-25 10:09:05 +00:00
|
|
|
void ChannelManager::DestructorDeletes_w() {
|
2017-01-12 05:15:36 -08:00
|
|
|
RTC_DCHECK(worker_thread_ == rtc::Thread::Current());
|
2015-02-11 08:38:35 +00:00
|
|
|
media_engine_.reset(NULL);
|
|
|
|
|
}
|
|
|
|
|
|
2013-07-10 00:45:36 +00:00
|
|
|
void ChannelManager::Terminate_w() {
|
2017-01-12 05:15:36 -08:00
|
|
|
RTC_DCHECK(worker_thread_ == rtc::Thread::Current());
|
2013-07-10 00:45:36 +00:00
|
|
|
// Need to destroy the voice/video channels
|
|
|
|
|
while (!video_channels_.empty()) {
|
|
|
|
|
DestroyVideoChannel_w(video_channels_.back());
|
|
|
|
|
}
|
|
|
|
|
while (!voice_channels_.empty()) {
|
2015-09-15 12:26:33 +02:00
|
|
|
DestroyVoiceChannel_w(voice_channels_.back());
|
2013-07-10 00:45:36 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
VoiceChannel* ChannelManager::CreateVoiceChannel(
|
2017-05-05 02:23:02 -07:00
|
|
|
webrtc::Call* call,
|
|
|
|
|
const cricket::MediaConfig& media_config,
|
2017-01-19 16:54:25 -08:00
|
|
|
DtlsTransportInternal* rtp_transport,
|
|
|
|
|
DtlsTransportInternal* rtcp_transport,
|
2017-01-12 19:37:48 -08:00
|
|
|
rtc::Thread* signaling_thread,
|
2015-05-29 15:05:44 +02:00
|
|
|
const std::string& content_name,
|
2016-12-13 11:29:11 -08:00
|
|
|
bool srtp_required,
|
2015-05-29 15:05:44 +02:00
|
|
|
const AudioOptions& options) {
|
2013-07-10 00:45:36 +00:00
|
|
|
return worker_thread_->Invoke<VoiceChannel*>(
|
2017-01-12 19:37:48 -08:00
|
|
|
RTC_FROM_HERE,
|
2017-05-05 02:23:02 -07:00
|
|
|
Bind(&ChannelManager::CreateVoiceChannel_w, this, call, media_config,
|
2017-02-25 18:15:09 -08:00
|
|
|
rtp_transport, rtcp_transport, rtp_transport, rtcp_transport,
|
|
|
|
|
signaling_thread, content_name, srtp_required, options));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
VoiceChannel* ChannelManager::CreateVoiceChannel(
|
2017-05-05 02:23:02 -07:00
|
|
|
webrtc::Call* call,
|
|
|
|
|
const cricket::MediaConfig& media_config,
|
2017-02-25 18:15:09 -08:00
|
|
|
rtc::PacketTransportInternal* rtp_transport,
|
|
|
|
|
rtc::PacketTransportInternal* rtcp_transport,
|
|
|
|
|
rtc::Thread* signaling_thread,
|
|
|
|
|
const std::string& content_name,
|
|
|
|
|
bool srtp_required,
|
|
|
|
|
const AudioOptions& options) {
|
|
|
|
|
return worker_thread_->Invoke<VoiceChannel*>(
|
|
|
|
|
RTC_FROM_HERE,
|
2017-05-05 02:23:02 -07:00
|
|
|
Bind(&ChannelManager::CreateVoiceChannel_w, this, call, media_config,
|
2017-02-25 18:15:09 -08:00
|
|
|
nullptr, nullptr, rtp_transport, rtcp_transport, signaling_thread,
|
|
|
|
|
content_name, srtp_required, options));
|
2013-07-10 00:45:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
VoiceChannel* ChannelManager::CreateVoiceChannel_w(
|
2017-05-05 02:23:02 -07:00
|
|
|
webrtc::Call* call,
|
|
|
|
|
const cricket::MediaConfig& media_config,
|
2017-02-25 18:15:09 -08:00
|
|
|
DtlsTransportInternal* rtp_dtls_transport,
|
|
|
|
|
DtlsTransportInternal* rtcp_dtls_transport,
|
|
|
|
|
rtc::PacketTransportInternal* rtp_packet_transport,
|
|
|
|
|
rtc::PacketTransportInternal* rtcp_packet_transport,
|
2017-01-12 19:37:48 -08:00
|
|
|
rtc::Thread* signaling_thread,
|
2015-05-29 15:05:44 +02:00
|
|
|
const std::string& content_name,
|
2016-12-13 11:29:11 -08:00
|
|
|
bool srtp_required,
|
2015-05-29 15:05:44 +02:00
|
|
|
const AudioOptions& options) {
|
2017-01-12 05:15:36 -08:00
|
|
|
RTC_DCHECK(initialized_);
|
|
|
|
|
RTC_DCHECK(worker_thread_ == rtc::Thread::Current());
|
2017-05-05 02:23:02 -07:00
|
|
|
RTC_DCHECK(nullptr != call);
|
2017-06-15 12:52:32 -07:00
|
|
|
if (!media_engine_) {
|
|
|
|
|
return nullptr;
|
|
|
|
|
}
|
2017-01-12 19:37:48 -08:00
|
|
|
|
2016-02-12 02:27:06 -08:00
|
|
|
VoiceMediaChannel* media_channel = media_engine_->CreateChannel(
|
2017-05-05 02:23:02 -07:00
|
|
|
call, media_config, options);
|
2015-05-29 15:05:44 +02:00
|
|
|
if (!media_channel)
|
|
|
|
|
return nullptr;
|
2013-07-10 00:45:36 +00:00
|
|
|
|
2017-02-25 18:15:09 -08:00
|
|
|
VoiceChannel* voice_channel =
|
|
|
|
|
new VoiceChannel(worker_thread_, network_thread_, signaling_thread,
|
|
|
|
|
media_engine_.get(), media_channel, content_name,
|
|
|
|
|
rtcp_packet_transport == nullptr, srtp_required);
|
2017-01-12 19:37:48 -08:00
|
|
|
|
2017-02-25 18:15:09 -08:00
|
|
|
if (!voice_channel->Init_w(rtp_dtls_transport, rtcp_dtls_transport,
|
|
|
|
|
rtp_packet_transport, rtcp_packet_transport)) {
|
2013-07-10 00:45:36 +00:00
|
|
|
delete voice_channel;
|
2015-05-29 15:05:44 +02:00
|
|
|
return nullptr;
|
2013-07-10 00:45:36 +00:00
|
|
|
}
|
|
|
|
|
voice_channels_.push_back(voice_channel);
|
|
|
|
|
return voice_channel;
|
|
|
|
|
}
|
|
|
|
|
|
2015-09-15 12:26:33 +02:00
|
|
|
void ChannelManager::DestroyVoiceChannel(VoiceChannel* voice_channel) {
|
2015-12-08 22:15:17 +01:00
|
|
|
TRACE_EVENT0("webrtc", "ChannelManager::DestroyVoiceChannel");
|
2013-07-10 00:45:36 +00:00
|
|
|
if (voice_channel) {
|
|
|
|
|
worker_thread_->Invoke<void>(
|
2016-06-10 14:17:27 -07:00
|
|
|
RTC_FROM_HERE,
|
2015-09-15 12:26:33 +02:00
|
|
|
Bind(&ChannelManager::DestroyVoiceChannel_w, this, voice_channel));
|
2013-07-10 00:45:36 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-09-15 12:26:33 +02:00
|
|
|
void ChannelManager::DestroyVoiceChannel_w(VoiceChannel* voice_channel) {
|
2015-12-08 22:15:17 +01:00
|
|
|
TRACE_EVENT0("webrtc", "ChannelManager::DestroyVoiceChannel_w");
|
2013-07-10 00:45:36 +00:00
|
|
|
// Destroy voice channel.
|
2017-01-12 05:15:36 -08:00
|
|
|
RTC_DCHECK(initialized_);
|
|
|
|
|
RTC_DCHECK(worker_thread_ == rtc::Thread::Current());
|
2013-07-10 00:45:36 +00:00
|
|
|
VoiceChannels::iterator it = std::find(voice_channels_.begin(),
|
|
|
|
|
voice_channels_.end(), voice_channel);
|
2017-01-12 05:15:36 -08:00
|
|
|
RTC_DCHECK(it != voice_channels_.end());
|
2013-07-10 00:45:36 +00:00
|
|
|
if (it == voice_channels_.end())
|
|
|
|
|
return;
|
|
|
|
|
voice_channels_.erase(it);
|
|
|
|
|
delete voice_channel;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
VideoChannel* ChannelManager::CreateVideoChannel(
|
2017-05-05 02:23:02 -07:00
|
|
|
webrtc::Call* call,
|
|
|
|
|
const cricket::MediaConfig& media_config,
|
2017-01-19 16:54:25 -08:00
|
|
|
DtlsTransportInternal* rtp_transport,
|
|
|
|
|
DtlsTransportInternal* rtcp_transport,
|
2017-01-12 19:37:48 -08:00
|
|
|
rtc::Thread* signaling_thread,
|
2014-10-14 20:29:28 +00:00
|
|
|
const std::string& content_name,
|
2016-12-13 11:29:11 -08:00
|
|
|
bool srtp_required,
|
2015-09-15 12:26:33 +02:00
|
|
|
const VideoOptions& options) {
|
2014-10-14 20:29:28 +00:00
|
|
|
return worker_thread_->Invoke<VideoChannel*>(
|
2017-01-12 19:37:48 -08:00
|
|
|
RTC_FROM_HERE,
|
2017-05-05 02:23:02 -07:00
|
|
|
Bind(&ChannelManager::CreateVideoChannel_w, this, call, media_config,
|
2017-02-25 18:15:09 -08:00
|
|
|
rtp_transport, rtcp_transport, rtp_transport, rtcp_transport,
|
|
|
|
|
signaling_thread, content_name, srtp_required, options));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
VideoChannel* ChannelManager::CreateVideoChannel(
|
2017-05-05 02:23:02 -07:00
|
|
|
webrtc::Call* call,
|
|
|
|
|
const cricket::MediaConfig& media_config,
|
2017-02-25 18:15:09 -08:00
|
|
|
rtc::PacketTransportInternal* rtp_transport,
|
|
|
|
|
rtc::PacketTransportInternal* rtcp_transport,
|
|
|
|
|
rtc::Thread* signaling_thread,
|
|
|
|
|
const std::string& content_name,
|
|
|
|
|
bool srtp_required,
|
|
|
|
|
const VideoOptions& options) {
|
|
|
|
|
return worker_thread_->Invoke<VideoChannel*>(
|
|
|
|
|
RTC_FROM_HERE,
|
2017-05-05 02:23:02 -07:00
|
|
|
Bind(&ChannelManager::CreateVideoChannel_w, this, call, media_config,
|
2017-02-25 18:15:09 -08:00
|
|
|
nullptr, nullptr, rtp_transport, rtcp_transport, signaling_thread,
|
|
|
|
|
content_name, srtp_required, options));
|
2013-07-10 00:45:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
VideoChannel* ChannelManager::CreateVideoChannel_w(
|
2017-05-05 02:23:02 -07:00
|
|
|
webrtc::Call* call,
|
|
|
|
|
const cricket::MediaConfig& media_config,
|
2017-02-25 18:15:09 -08:00
|
|
|
DtlsTransportInternal* rtp_dtls_transport,
|
|
|
|
|
DtlsTransportInternal* rtcp_dtls_transport,
|
|
|
|
|
rtc::PacketTransportInternal* rtp_packet_transport,
|
|
|
|
|
rtc::PacketTransportInternal* rtcp_packet_transport,
|
2017-01-12 19:37:48 -08:00
|
|
|
rtc::Thread* signaling_thread,
|
2014-10-14 20:29:28 +00:00
|
|
|
const std::string& content_name,
|
2016-12-13 11:29:11 -08:00
|
|
|
bool srtp_required,
|
2015-09-15 12:26:33 +02:00
|
|
|
const VideoOptions& options) {
|
2017-01-12 05:15:36 -08:00
|
|
|
RTC_DCHECK(initialized_);
|
|
|
|
|
RTC_DCHECK(worker_thread_ == rtc::Thread::Current());
|
2017-05-05 02:23:02 -07:00
|
|
|
RTC_DCHECK(nullptr != call);
|
2016-02-12 02:27:06 -08:00
|
|
|
VideoMediaChannel* media_channel = media_engine_->CreateVideoChannel(
|
2017-05-05 02:23:02 -07:00
|
|
|
call, media_config, options);
|
2015-09-23 11:50:27 -07:00
|
|
|
if (media_channel == NULL) {
|
2013-07-10 00:45:36 +00:00
|
|
|
return NULL;
|
2015-09-23 11:50:27 -07:00
|
|
|
}
|
2013-07-10 00:45:36 +00:00
|
|
|
|
2017-01-12 21:59:29 -08:00
|
|
|
VideoChannel* video_channel = new VideoChannel(
|
|
|
|
|
worker_thread_, network_thread_, signaling_thread, media_channel,
|
2017-02-25 18:15:09 -08:00
|
|
|
content_name, rtcp_packet_transport == nullptr, srtp_required);
|
|
|
|
|
if (!video_channel->Init_w(rtp_dtls_transport, rtcp_dtls_transport,
|
|
|
|
|
rtp_packet_transport, rtcp_packet_transport)) {
|
2013-07-10 00:45:36 +00:00
|
|
|
delete video_channel;
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
video_channels_.push_back(video_channel);
|
|
|
|
|
return video_channel;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ChannelManager::DestroyVideoChannel(VideoChannel* video_channel) {
|
2015-12-08 22:15:17 +01:00
|
|
|
TRACE_EVENT0("webrtc", "ChannelManager::DestroyVideoChannel");
|
2013-07-10 00:45:36 +00:00
|
|
|
if (video_channel) {
|
|
|
|
|
worker_thread_->Invoke<void>(
|
2016-06-10 14:17:27 -07:00
|
|
|
RTC_FROM_HERE,
|
2013-07-10 00:45:36 +00:00
|
|
|
Bind(&ChannelManager::DestroyVideoChannel_w, this, video_channel));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ChannelManager::DestroyVideoChannel_w(VideoChannel* video_channel) {
|
2015-12-08 22:15:17 +01:00
|
|
|
TRACE_EVENT0("webrtc", "ChannelManager::DestroyVideoChannel_w");
|
2013-07-10 00:45:36 +00:00
|
|
|
// Destroy video channel.
|
2017-01-12 05:15:36 -08:00
|
|
|
RTC_DCHECK(initialized_);
|
|
|
|
|
RTC_DCHECK(worker_thread_ == rtc::Thread::Current());
|
2013-07-10 00:45:36 +00:00
|
|
|
VideoChannels::iterator it = std::find(video_channels_.begin(),
|
|
|
|
|
video_channels_.end(), video_channel);
|
2017-01-12 05:15:36 -08:00
|
|
|
RTC_DCHECK(it != video_channels_.end());
|
2013-07-10 00:45:36 +00:00
|
|
|
if (it == video_channels_.end())
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
video_channels_.erase(it);
|
|
|
|
|
delete video_channel;
|
|
|
|
|
}
|
|
|
|
|
|
2017-01-09 14:53:41 -08:00
|
|
|
RtpDataChannel* ChannelManager::CreateRtpDataChannel(
|
2017-05-05 02:23:02 -07:00
|
|
|
const cricket::MediaConfig& media_config,
|
2017-01-19 16:54:25 -08:00
|
|
|
DtlsTransportInternal* rtp_transport,
|
|
|
|
|
DtlsTransportInternal* rtcp_transport,
|
2017-01-12 19:37:48 -08:00
|
|
|
rtc::Thread* signaling_thread,
|
2016-12-06 10:45:42 -08:00
|
|
|
const std::string& content_name,
|
2017-01-09 14:53:41 -08:00
|
|
|
bool srtp_required) {
|
|
|
|
|
return worker_thread_->Invoke<RtpDataChannel*>(
|
2017-02-10 23:44:49 -08:00
|
|
|
RTC_FROM_HERE, Bind(&ChannelManager::CreateRtpDataChannel_w, this,
|
2017-05-05 02:23:02 -07:00
|
|
|
media_config, rtp_transport, rtcp_transport,
|
2017-02-10 23:44:49 -08:00
|
|
|
signaling_thread, content_name, srtp_required));
|
2013-07-10 00:45:36 +00:00
|
|
|
}
|
|
|
|
|
|
2017-01-09 14:53:41 -08:00
|
|
|
RtpDataChannel* ChannelManager::CreateRtpDataChannel_w(
|
2017-05-05 02:23:02 -07:00
|
|
|
const cricket::MediaConfig& media_config,
|
2017-01-19 16:54:25 -08:00
|
|
|
DtlsTransportInternal* rtp_transport,
|
|
|
|
|
DtlsTransportInternal* rtcp_transport,
|
2017-01-12 19:37:48 -08:00
|
|
|
rtc::Thread* signaling_thread,
|
2015-09-23 11:50:27 -07:00
|
|
|
const std::string& content_name,
|
2017-01-09 14:53:41 -08:00
|
|
|
bool srtp_required) {
|
2013-07-10 00:45:36 +00:00
|
|
|
// This is ok to alloc from a thread other than the worker thread.
|
2017-01-12 05:15:36 -08:00
|
|
|
RTC_DCHECK(initialized_);
|
2017-05-05 02:23:02 -07:00
|
|
|
DataMediaChannel* media_channel
|
|
|
|
|
= data_media_engine_->CreateChannel(media_config);
|
2013-07-10 00:45:36 +00:00
|
|
|
if (!media_channel) {
|
2017-01-09 14:53:41 -08:00
|
|
|
LOG(LS_WARNING) << "Failed to create RTP data channel.";
|
|
|
|
|
return nullptr;
|
2013-07-10 00:45:36 +00:00
|
|
|
}
|
|
|
|
|
|
2017-01-12 21:59:29 -08:00
|
|
|
RtpDataChannel* data_channel = new RtpDataChannel(
|
|
|
|
|
worker_thread_, network_thread_, signaling_thread, media_channel,
|
2017-02-10 23:44:49 -08:00
|
|
|
content_name, rtcp_transport == nullptr, srtp_required);
|
2017-01-24 21:51:21 -08:00
|
|
|
if (!data_channel->Init_w(rtp_transport, rtcp_transport, rtp_transport,
|
|
|
|
|
rtcp_transport)) {
|
2013-07-10 00:45:36 +00:00
|
|
|
LOG(LS_WARNING) << "Failed to init data channel.";
|
|
|
|
|
delete data_channel;
|
2017-01-09 14:53:41 -08:00
|
|
|
return nullptr;
|
2013-07-10 00:45:36 +00:00
|
|
|
}
|
|
|
|
|
data_channels_.push_back(data_channel);
|
|
|
|
|
return data_channel;
|
|
|
|
|
}
|
|
|
|
|
|
2017-01-09 14:53:41 -08:00
|
|
|
void ChannelManager::DestroyRtpDataChannel(RtpDataChannel* data_channel) {
|
|
|
|
|
TRACE_EVENT0("webrtc", "ChannelManager::DestroyRtpDataChannel");
|
2013-07-10 00:45:36 +00:00
|
|
|
if (data_channel) {
|
|
|
|
|
worker_thread_->Invoke<void>(
|
2016-06-10 14:17:27 -07:00
|
|
|
RTC_FROM_HERE,
|
2017-01-09 14:53:41 -08:00
|
|
|
Bind(&ChannelManager::DestroyRtpDataChannel_w, this, data_channel));
|
2013-07-10 00:45:36 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-01-09 14:53:41 -08:00
|
|
|
void ChannelManager::DestroyRtpDataChannel_w(RtpDataChannel* data_channel) {
|
|
|
|
|
TRACE_EVENT0("webrtc", "ChannelManager::DestroyRtpDataChannel_w");
|
2013-07-10 00:45:36 +00:00
|
|
|
// Destroy data channel.
|
2017-01-12 05:15:36 -08:00
|
|
|
RTC_DCHECK(initialized_);
|
2017-01-09 14:53:41 -08:00
|
|
|
RtpDataChannels::iterator it =
|
|
|
|
|
std::find(data_channels_.begin(), data_channels_.end(), data_channel);
|
2017-01-12 05:15:36 -08:00
|
|
|
RTC_DCHECK(it != data_channels_.end());
|
2013-07-10 00:45:36 +00:00
|
|
|
if (it == data_channels_.end())
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
data_channels_.erase(it);
|
|
|
|
|
delete data_channel;
|
|
|
|
|
}
|
|
|
|
|
|
2016-01-15 03:06:36 -08:00
|
|
|
bool ChannelManager::StartAecDump(rtc::PlatformFile file,
|
|
|
|
|
int64_t max_size_bytes) {
|
2016-06-10 14:17:27 -07:00
|
|
|
return worker_thread_->Invoke<bool>(
|
|
|
|
|
RTC_FROM_HERE, Bind(&MediaEngineInterface::StartAecDump,
|
|
|
|
|
media_engine_.get(), file, max_size_bytes));
|
2013-12-13 00:21:03 +00:00
|
|
|
}
|
|
|
|
|
|
2015-10-22 03:25:41 -07:00
|
|
|
void ChannelManager::StopAecDump() {
|
|
|
|
|
worker_thread_->Invoke<void>(
|
2016-06-10 14:17:27 -07:00
|
|
|
RTC_FROM_HERE,
|
2015-10-22 03:25:41 -07:00
|
|
|
Bind(&MediaEngineInterface::StopAecDump, media_engine_.get()));
|
|
|
|
|
}
|
|
|
|
|
|
2013-07-10 00:45:36 +00:00
|
|
|
} // namespace cricket
|