Modernize and cleanup ChannelManager
Bug: None Change-Id: Ifd07c10dc1d3655e0138900c9a9897810cec3d54 Reviewed-on: https://webrtc-review.googlesource.com/18080 Reviewed-by: Karl Wiberg <kwiberg@webrtc.org> Reviewed-by: Peter Thatcher <pthatcher@webrtc.org> Commit-Queue: Steve Anton <steveanton@webrtc.org> Cr-Commit-Position: refs/heads/master@{#20593}
This commit is contained in:
@ -22,6 +22,7 @@
|
||||
#include "api/videosourceproxy.h"
|
||||
#include "logging/rtc_event_log/rtc_event_log.h"
|
||||
#include "media/base/mediaconstants.h"
|
||||
#include "media/base/rtpdataengine.h"
|
||||
#include "modules/audio_processing/include/audio_processing.h"
|
||||
#include "ortc/ortcrtpreceiveradapter.h"
|
||||
#include "ortc/ortcrtpsenderadapter.h"
|
||||
@ -40,6 +41,7 @@
|
||||
#include "rtc_base/checks.h"
|
||||
#include "rtc_base/helpers.h"
|
||||
#include "rtc_base/logging.h"
|
||||
#include "rtc_base/ptr_util.h"
|
||||
|
||||
namespace {
|
||||
|
||||
@ -528,7 +530,8 @@ RTCError OrtcFactory::Initialize(
|
||||
}
|
||||
|
||||
channel_manager_.reset(new cricket::ChannelManager(
|
||||
std::move(media_engine), worker_thread_.get(), network_thread_));
|
||||
std::move(media_engine), rtc::MakeUnique<cricket::RtpDataEngine>(),
|
||||
worker_thread_.get(), network_thread_));
|
||||
channel_manager_->SetVideoRtxEnabled(true);
|
||||
if (!channel_manager_->Init()) {
|
||||
LOG_AND_RETURN_ERROR(RTCErrorType::INTERNAL_ERROR,
|
||||
|
||||
@ -13,47 +13,28 @@
|
||||
#include <algorithm>
|
||||
#include <utility>
|
||||
|
||||
#include "media/base/device.h"
|
||||
#include "media/base/rtpdataengine.h"
|
||||
#include "pc/srtpfilter.h"
|
||||
#include "rtc_base/bind.h"
|
||||
#include "rtc_base/checks.h"
|
||||
#include "rtc_base/logging.h"
|
||||
#include "rtc_base/stringencode.h"
|
||||
#include "rtc_base/ptr_util.h"
|
||||
#include "rtc_base/stringutils.h"
|
||||
#include "rtc_base/trace_event.h"
|
||||
|
||||
namespace cricket {
|
||||
|
||||
|
||||
using rtc::Bind;
|
||||
|
||||
ChannelManager::ChannelManager(std::unique_ptr<MediaEngineInterface> me,
|
||||
std::unique_ptr<DataEngineInterface> dme,
|
||||
rtc::Thread* thread) {
|
||||
Construct(std::move(me), std::move(dme), thread, thread);
|
||||
}
|
||||
|
||||
ChannelManager::ChannelManager(std::unique_ptr<MediaEngineInterface> me,
|
||||
rtc::Thread* worker_thread,
|
||||
rtc::Thread* network_thread) {
|
||||
Construct(std::move(me),
|
||||
std::unique_ptr<DataEngineInterface>(new RtpDataEngine()),
|
||||
worker_thread, network_thread);
|
||||
}
|
||||
|
||||
void ChannelManager::Construct(std::unique_ptr<MediaEngineInterface> me,
|
||||
std::unique_ptr<DataEngineInterface> dme,
|
||||
rtc::Thread* worker_thread,
|
||||
rtc::Thread* network_thread) {
|
||||
media_engine_ = std::move(me);
|
||||
data_media_engine_ = std::move(dme);
|
||||
initialized_ = false;
|
||||
main_thread_ = rtc::Thread::Current();
|
||||
worker_thread_ = worker_thread;
|
||||
network_thread_ = network_thread;
|
||||
capturing_ = false;
|
||||
enable_rtx_ = false;
|
||||
ChannelManager::ChannelManager(
|
||||
std::unique_ptr<MediaEngineInterface> media_engine,
|
||||
std::unique_ptr<DataEngineInterface> data_engine,
|
||||
rtc::Thread* worker_thread,
|
||||
rtc::Thread* network_thread)
|
||||
: media_engine_(std::move(media_engine)),
|
||||
data_engine_(std::move(data_engine)),
|
||||
main_thread_(rtc::Thread::Current()),
|
||||
worker_thread_(worker_thread),
|
||||
network_thread_(network_thread) {
|
||||
RTC_DCHECK(data_engine_);
|
||||
RTC_DCHECK(worker_thread_);
|
||||
RTC_DCHECK(network_thread_);
|
||||
}
|
||||
|
||||
ChannelManager::~ChannelManager() {
|
||||
@ -62,8 +43,7 @@ ChannelManager::~ChannelManager() {
|
||||
}
|
||||
// The media engine needs to be deleted on the worker thread for thread safe
|
||||
// destruction,
|
||||
worker_thread_->Invoke<void>(
|
||||
RTC_FROM_HERE, Bind(&ChannelManager::DestructorDeletes_w, this));
|
||||
worker_thread_->Invoke<void>(RTC_FROM_HERE, [&] { media_engine_.reset(); });
|
||||
}
|
||||
|
||||
bool ChannelManager::SetVideoRtxEnabled(bool enable) {
|
||||
@ -132,10 +112,7 @@ void ChannelManager::GetSupportedVideoRtpHeaderExtensions(
|
||||
|
||||
void ChannelManager::GetSupportedDataCodecs(
|
||||
std::vector<DataCodec>* codecs) const {
|
||||
if (!data_media_engine_) {
|
||||
return;
|
||||
}
|
||||
*codecs = data_media_engine_->data_codecs();
|
||||
*codecs = data_engine_->data_codecs();
|
||||
}
|
||||
|
||||
bool ChannelManager::Init() {
|
||||
@ -147,23 +124,18 @@ bool ChannelManager::Init() {
|
||||
RTC_DCHECK(worker_thread_);
|
||||
if (!network_thread_->IsCurrent()) {
|
||||
// Do not allow invoking calls to other threads on the network thread.
|
||||
network_thread_->Invoke<bool>(
|
||||
RTC_FROM_HERE,
|
||||
rtc::Bind(&rtc::Thread::SetAllowBlockingCalls, network_thread_, false));
|
||||
network_thread_->Invoke<void>(
|
||||
RTC_FROM_HERE, [&] { network_thread_->SetAllowBlockingCalls(false); });
|
||||
}
|
||||
|
||||
initialized_ = worker_thread_->Invoke<bool>(
|
||||
RTC_FROM_HERE, Bind(&ChannelManager::InitMediaEngine_w, this));
|
||||
RTC_DCHECK(initialized_);
|
||||
return initialized_;
|
||||
}
|
||||
|
||||
bool ChannelManager::InitMediaEngine_w() {
|
||||
RTC_DCHECK(worker_thread_ == rtc::Thread::Current());
|
||||
if (media_engine_) {
|
||||
return media_engine_->Init();
|
||||
initialized_ = worker_thread_->Invoke<bool>(
|
||||
RTC_FROM_HERE, [&] { return media_engine_->Init(); });
|
||||
RTC_DCHECK(initialized_);
|
||||
} else {
|
||||
initialized_ = true;
|
||||
}
|
||||
return true;
|
||||
return initialized_;
|
||||
}
|
||||
|
||||
void ChannelManager::Terminate() {
|
||||
@ -171,23 +143,15 @@ void ChannelManager::Terminate() {
|
||||
if (!initialized_) {
|
||||
return;
|
||||
}
|
||||
worker_thread_->Invoke<void>(RTC_FROM_HERE,
|
||||
Bind(&ChannelManager::Terminate_w, this));
|
||||
// Need to destroy the channels on the worker thread.
|
||||
worker_thread_->Invoke<void>(RTC_FROM_HERE, [&] {
|
||||
video_channels_.clear();
|
||||
voice_channels_.clear();
|
||||
data_channels_.clear();
|
||||
});
|
||||
initialized_ = false;
|
||||
}
|
||||
|
||||
void ChannelManager::DestructorDeletes_w() {
|
||||
RTC_DCHECK(worker_thread_ == rtc::Thread::Current());
|
||||
media_engine_.reset(nullptr);
|
||||
}
|
||||
|
||||
void ChannelManager::Terminate_w() {
|
||||
RTC_DCHECK(worker_thread_ == rtc::Thread::Current());
|
||||
// Need to destroy the voice/video channels
|
||||
video_channels_.clear();
|
||||
voice_channels_.clear();
|
||||
}
|
||||
|
||||
VoiceChannel* ChannelManager::CreateVoiceChannel(
|
||||
webrtc::Call* call,
|
||||
const cricket::MediaConfig& media_config,
|
||||
@ -197,11 +161,11 @@ VoiceChannel* ChannelManager::CreateVoiceChannel(
|
||||
const std::string& content_name,
|
||||
bool srtp_required,
|
||||
const AudioOptions& options) {
|
||||
return worker_thread_->Invoke<VoiceChannel*>(
|
||||
RTC_FROM_HERE,
|
||||
Bind(&ChannelManager::CreateVoiceChannel_w, this, call, media_config,
|
||||
rtp_transport, rtcp_transport, rtp_transport, rtcp_transport,
|
||||
signaling_thread, content_name, srtp_required, options));
|
||||
return worker_thread_->Invoke<VoiceChannel*>(RTC_FROM_HERE, [&] {
|
||||
return CreateVoiceChannel_w(
|
||||
call, media_config, rtp_transport, rtcp_transport, rtp_transport,
|
||||
rtcp_transport, signaling_thread, content_name, srtp_required, options);
|
||||
});
|
||||
}
|
||||
|
||||
VoiceChannel* ChannelManager::CreateVoiceChannel(
|
||||
@ -213,11 +177,11 @@ VoiceChannel* ChannelManager::CreateVoiceChannel(
|
||||
const std::string& content_name,
|
||||
bool srtp_required,
|
||||
const AudioOptions& options) {
|
||||
return worker_thread_->Invoke<VoiceChannel*>(
|
||||
RTC_FROM_HERE,
|
||||
Bind(&ChannelManager::CreateVoiceChannel_w, this, call, media_config,
|
||||
nullptr, nullptr, rtp_transport, rtcp_transport, signaling_thread,
|
||||
content_name, srtp_required, options));
|
||||
return worker_thread_->Invoke<VoiceChannel*>(RTC_FROM_HERE, [&] {
|
||||
return CreateVoiceChannel_w(call, media_config, nullptr, nullptr,
|
||||
rtp_transport, rtcp_transport, signaling_thread,
|
||||
content_name, srtp_required, options);
|
||||
});
|
||||
}
|
||||
|
||||
VoiceChannel* ChannelManager::CreateVoiceChannel_w(
|
||||
@ -231,9 +195,9 @@ VoiceChannel* ChannelManager::CreateVoiceChannel_w(
|
||||
const std::string& content_name,
|
||||
bool srtp_required,
|
||||
const AudioOptions& options) {
|
||||
RTC_DCHECK_RUN_ON(worker_thread_);
|
||||
RTC_DCHECK(initialized_);
|
||||
RTC_DCHECK(worker_thread_ == rtc::Thread::Current());
|
||||
RTC_DCHECK(nullptr != call);
|
||||
RTC_DCHECK(call);
|
||||
if (!media_engine_) {
|
||||
return nullptr;
|
||||
}
|
||||
@ -244,15 +208,15 @@ VoiceChannel* ChannelManager::CreateVoiceChannel_w(
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
std::unique_ptr<VoiceChannel> voice_channel(
|
||||
new VoiceChannel(worker_thread_, network_thread_, signaling_thread,
|
||||
media_engine_.get(), media_channel, content_name,
|
||||
rtcp_packet_transport == nullptr, srtp_required));
|
||||
|
||||
auto voice_channel = rtc::MakeUnique<VoiceChannel>(
|
||||
worker_thread_, network_thread_, signaling_thread, media_engine_.get(),
|
||||
media_channel, content_name, rtcp_packet_transport == nullptr,
|
||||
srtp_required);
|
||||
if (!voice_channel->Init_w(rtp_dtls_transport, rtcp_dtls_transport,
|
||||
rtp_packet_transport, rtcp_packet_transport)) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
VoiceChannel* voice_channel_ptr = voice_channel.get();
|
||||
voice_channels_.push_back(std::move(voice_channel));
|
||||
return voice_channel_ptr;
|
||||
@ -260,25 +224,26 @@ VoiceChannel* ChannelManager::CreateVoiceChannel_w(
|
||||
|
||||
void ChannelManager::DestroyVoiceChannel(VoiceChannel* voice_channel) {
|
||||
TRACE_EVENT0("webrtc", "ChannelManager::DestroyVoiceChannel");
|
||||
if (voice_channel) {
|
||||
worker_thread_->Invoke<void>(
|
||||
RTC_FROM_HERE,
|
||||
Bind(&ChannelManager::DestroyVoiceChannel_w, this, voice_channel));
|
||||
if (!voice_channel) {
|
||||
return;
|
||||
}
|
||||
if (!worker_thread_->IsCurrent()) {
|
||||
worker_thread_->Invoke<void>(RTC_FROM_HERE,
|
||||
[&] { DestroyVoiceChannel(voice_channel); });
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
void ChannelManager::DestroyVoiceChannel_w(VoiceChannel* voice_channel) {
|
||||
TRACE_EVENT0("webrtc", "ChannelManager::DestroyVoiceChannel_w");
|
||||
RTC_DCHECK(initialized_);
|
||||
RTC_DCHECK(worker_thread_ == rtc::Thread::Current());
|
||||
|
||||
auto it = std::find_if(voice_channels_.begin(), voice_channels_.end(),
|
||||
[&](const std::unique_ptr<VoiceChannel>& p) {
|
||||
return p.get() == voice_channel;
|
||||
});
|
||||
RTC_DCHECK(it != voice_channels_.end());
|
||||
if (it == voice_channels_.end())
|
||||
if (it == voice_channels_.end()) {
|
||||
return;
|
||||
}
|
||||
|
||||
voice_channels_.erase(it);
|
||||
}
|
||||
|
||||
@ -291,11 +256,11 @@ VideoChannel* ChannelManager::CreateVideoChannel(
|
||||
const std::string& content_name,
|
||||
bool srtp_required,
|
||||
const VideoOptions& options) {
|
||||
return worker_thread_->Invoke<VideoChannel*>(
|
||||
RTC_FROM_HERE,
|
||||
Bind(&ChannelManager::CreateVideoChannel_w, this, call, media_config,
|
||||
rtp_transport, rtcp_transport, rtp_transport, rtcp_transport,
|
||||
signaling_thread, content_name, srtp_required, options));
|
||||
return worker_thread_->Invoke<VideoChannel*>(RTC_FROM_HERE, [&] {
|
||||
return CreateVideoChannel_w(
|
||||
call, media_config, rtp_transport, rtcp_transport, rtp_transport,
|
||||
rtcp_transport, signaling_thread, content_name, srtp_required, options);
|
||||
});
|
||||
}
|
||||
|
||||
VideoChannel* ChannelManager::CreateVideoChannel(
|
||||
@ -307,11 +272,11 @@ VideoChannel* ChannelManager::CreateVideoChannel(
|
||||
const std::string& content_name,
|
||||
bool srtp_required,
|
||||
const VideoOptions& options) {
|
||||
return worker_thread_->Invoke<VideoChannel*>(
|
||||
RTC_FROM_HERE,
|
||||
Bind(&ChannelManager::CreateVideoChannel_w, this, call, media_config,
|
||||
nullptr, nullptr, rtp_transport, rtcp_transport, signaling_thread,
|
||||
content_name, srtp_required, options));
|
||||
return worker_thread_->Invoke<VideoChannel*>(RTC_FROM_HERE, [&] {
|
||||
return CreateVideoChannel_w(call, media_config, nullptr, nullptr,
|
||||
rtp_transport, rtcp_transport, signaling_thread,
|
||||
content_name, srtp_required, options);
|
||||
});
|
||||
}
|
||||
|
||||
VideoChannel* ChannelManager::CreateVideoChannel_w(
|
||||
@ -325,22 +290,25 @@ VideoChannel* ChannelManager::CreateVideoChannel_w(
|
||||
const std::string& content_name,
|
||||
bool srtp_required,
|
||||
const VideoOptions& options) {
|
||||
RTC_DCHECK_RUN_ON(worker_thread_);
|
||||
RTC_DCHECK(initialized_);
|
||||
RTC_DCHECK(worker_thread_ == rtc::Thread::Current());
|
||||
RTC_DCHECK(nullptr != call);
|
||||
RTC_DCHECK(call);
|
||||
RTC_DCHECK(media_engine_);
|
||||
|
||||
VideoMediaChannel* media_channel = media_engine_->CreateVideoChannel(
|
||||
call, media_config, options);
|
||||
if (!media_channel) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
std::unique_ptr<VideoChannel> video_channel(new VideoChannel(
|
||||
auto video_channel = rtc::MakeUnique<VideoChannel>(
|
||||
worker_thread_, network_thread_, signaling_thread, media_channel,
|
||||
content_name, rtcp_packet_transport == nullptr, srtp_required));
|
||||
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)) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
VideoChannel* video_channel_ptr = video_channel.get();
|
||||
video_channels_.push_back(std::move(video_channel));
|
||||
return video_channel_ptr;
|
||||
@ -348,25 +316,25 @@ VideoChannel* ChannelManager::CreateVideoChannel_w(
|
||||
|
||||
void ChannelManager::DestroyVideoChannel(VideoChannel* video_channel) {
|
||||
TRACE_EVENT0("webrtc", "ChannelManager::DestroyVideoChannel");
|
||||
if (video_channel) {
|
||||
worker_thread_->Invoke<void>(
|
||||
RTC_FROM_HERE,
|
||||
Bind(&ChannelManager::DestroyVideoChannel_w, this, video_channel));
|
||||
if (!video_channel) {
|
||||
return;
|
||||
}
|
||||
if (!worker_thread_->IsCurrent()) {
|
||||
worker_thread_->Invoke<void>(RTC_FROM_HERE,
|
||||
[&] { DestroyVideoChannel(video_channel); });
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
void ChannelManager::DestroyVideoChannel_w(VideoChannel* video_channel) {
|
||||
TRACE_EVENT0("webrtc", "ChannelManager::DestroyVideoChannel_w");
|
||||
RTC_DCHECK(initialized_);
|
||||
RTC_DCHECK(worker_thread_ == rtc::Thread::Current());
|
||||
|
||||
auto it = std::find_if(video_channels_.begin(), video_channels_.end(),
|
||||
[&](const std::unique_ptr<VideoChannel>& p) {
|
||||
return p.get() == video_channel;
|
||||
});
|
||||
RTC_DCHECK(it != video_channels_.end());
|
||||
if (it == video_channels_.end())
|
||||
if (it == video_channels_.end()) {
|
||||
return;
|
||||
}
|
||||
|
||||
video_channels_.erase(it);
|
||||
}
|
||||
@ -378,36 +346,31 @@ RtpDataChannel* ChannelManager::CreateRtpDataChannel(
|
||||
rtc::Thread* signaling_thread,
|
||||
const std::string& content_name,
|
||||
bool srtp_required) {
|
||||
return worker_thread_->Invoke<RtpDataChannel*>(
|
||||
RTC_FROM_HERE, Bind(&ChannelManager::CreateRtpDataChannel_w, this,
|
||||
media_config, rtp_transport, rtcp_transport,
|
||||
signaling_thread, content_name, srtp_required));
|
||||
}
|
||||
if (!worker_thread_->IsCurrent()) {
|
||||
return worker_thread_->Invoke<RtpDataChannel*>(RTC_FROM_HERE, [&] {
|
||||
return CreateRtpDataChannel(media_config, rtp_transport, rtcp_transport,
|
||||
signaling_thread, content_name,
|
||||
srtp_required);
|
||||
});
|
||||
}
|
||||
|
||||
RtpDataChannel* ChannelManager::CreateRtpDataChannel_w(
|
||||
const cricket::MediaConfig& media_config,
|
||||
DtlsTransportInternal* rtp_transport,
|
||||
DtlsTransportInternal* rtcp_transport,
|
||||
rtc::Thread* signaling_thread,
|
||||
const std::string& content_name,
|
||||
bool srtp_required) {
|
||||
// This is ok to alloc from a thread other than the worker thread.
|
||||
RTC_DCHECK(initialized_);
|
||||
DataMediaChannel* media_channel
|
||||
= data_media_engine_->CreateChannel(media_config);
|
||||
DataMediaChannel* media_channel = data_engine_->CreateChannel(media_config);
|
||||
if (!media_channel) {
|
||||
LOG(LS_WARNING) << "Failed to create RTP data channel.";
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
std::unique_ptr<RtpDataChannel> data_channel(new RtpDataChannel(
|
||||
auto data_channel = rtc::MakeUnique<RtpDataChannel>(
|
||||
worker_thread_, network_thread_, signaling_thread, media_channel,
|
||||
content_name, rtcp_transport == nullptr, srtp_required));
|
||||
content_name, rtcp_transport == nullptr, srtp_required);
|
||||
if (!data_channel->Init_w(rtp_transport, rtcp_transport, rtp_transport,
|
||||
rtcp_transport)) {
|
||||
LOG(LS_WARNING) << "Failed to init data channel.";
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
RtpDataChannel* data_channel_ptr = data_channel.get();
|
||||
data_channels_.push_back(std::move(data_channel));
|
||||
return data_channel_ptr;
|
||||
@ -415,15 +378,15 @@ RtpDataChannel* ChannelManager::CreateRtpDataChannel_w(
|
||||
|
||||
void ChannelManager::DestroyRtpDataChannel(RtpDataChannel* data_channel) {
|
||||
TRACE_EVENT0("webrtc", "ChannelManager::DestroyRtpDataChannel");
|
||||
if (data_channel) {
|
||||
worker_thread_->Invoke<void>(
|
||||
RTC_FROM_HERE,
|
||||
Bind(&ChannelManager::DestroyRtpDataChannel_w, this, data_channel));
|
||||
if (!data_channel) {
|
||||
return;
|
||||
}
|
||||
if (!worker_thread_->IsCurrent()) {
|
||||
worker_thread_->Invoke<void>(
|
||||
RTC_FROM_HERE, [&] { return DestroyRtpDataChannel(data_channel); });
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
void ChannelManager::DestroyRtpDataChannel_w(RtpDataChannel* data_channel) {
|
||||
TRACE_EVENT0("webrtc", "ChannelManager::DestroyRtpDataChannel_w");
|
||||
RTC_DCHECK(initialized_);
|
||||
|
||||
auto it = std::find_if(data_channels_.begin(), data_channels_.end(),
|
||||
@ -431,23 +394,23 @@ void ChannelManager::DestroyRtpDataChannel_w(RtpDataChannel* data_channel) {
|
||||
return p.get() == data_channel;
|
||||
});
|
||||
RTC_DCHECK(it != data_channels_.end());
|
||||
if (it == data_channels_.end())
|
||||
if (it == data_channels_.end()) {
|
||||
return;
|
||||
}
|
||||
|
||||
data_channels_.erase(it);
|
||||
}
|
||||
|
||||
bool ChannelManager::StartAecDump(rtc::PlatformFile file,
|
||||
int64_t max_size_bytes) {
|
||||
return worker_thread_->Invoke<bool>(
|
||||
RTC_FROM_HERE, Bind(&MediaEngineInterface::StartAecDump,
|
||||
media_engine_.get(), file, max_size_bytes));
|
||||
return worker_thread_->Invoke<bool>(RTC_FROM_HERE, [&] {
|
||||
return media_engine_->StartAecDump(file, max_size_bytes);
|
||||
});
|
||||
}
|
||||
|
||||
void ChannelManager::StopAecDump() {
|
||||
worker_thread_->Invoke<void>(
|
||||
RTC_FROM_HERE,
|
||||
Bind(&MediaEngineInterface::StopAecDump, media_engine_.get()));
|
||||
worker_thread_->Invoke<void>(RTC_FROM_HERE,
|
||||
[&] { media_engine_->StopAecDump(); });
|
||||
}
|
||||
|
||||
} // namespace cricket
|
||||
|
||||
@ -16,13 +16,11 @@
|
||||
#include <vector>
|
||||
|
||||
#include "media/base/mediaengine.h"
|
||||
#include "pc/voicechannel.h"
|
||||
#include "pc/channel.h"
|
||||
#include "rtc_base/thread.h"
|
||||
|
||||
namespace cricket {
|
||||
|
||||
class VoiceChannel;
|
||||
|
||||
// ChannelManager allows the MediaEngine to run on a separate thread, and takes
|
||||
// care of marshalling calls between threads. It also creates and keeps track of
|
||||
// voice and video channels; by doing so, it can temporarily pause all the
|
||||
@ -31,17 +29,13 @@ class VoiceChannel;
|
||||
// voice or just video channels.
|
||||
// ChannelManager also allows the application to discover what devices it has
|
||||
// using device manager.
|
||||
class ChannelManager {
|
||||
class ChannelManager final {
|
||||
public:
|
||||
// For testing purposes. Allows the media engine and data media
|
||||
// engine and dev manager to be mocks.
|
||||
ChannelManager(std::unique_ptr<MediaEngineInterface> me,
|
||||
std::unique_ptr<DataEngineInterface> dme,
|
||||
rtc::Thread* worker_and_network);
|
||||
// Same as above, but gives an easier default DataEngine.
|
||||
ChannelManager(std::unique_ptr<MediaEngineInterface> me,
|
||||
rtc::Thread* worker,
|
||||
rtc::Thread* network);
|
||||
// Construct a ChannelManager with the specified media engine and data engine.
|
||||
ChannelManager(std::unique_ptr<MediaEngineInterface> media_engine,
|
||||
std::unique_ptr<DataEngineInterface> data_engine,
|
||||
rtc::Thread* worker_thread,
|
||||
rtc::Thread* network_thread);
|
||||
~ChannelManager();
|
||||
|
||||
// Accessors for the worker thread, allowing it to be set after construction,
|
||||
@ -144,7 +138,8 @@ class ChannelManager {
|
||||
|
||||
// Indicates whether any channels exist.
|
||||
bool has_channels() const {
|
||||
return (!voice_channels_.empty() || !video_channels_.empty());
|
||||
return (!voice_channels_.empty() || !video_channels_.empty() ||
|
||||
!data_channels_.empty());
|
||||
}
|
||||
|
||||
// RTX will be enabled/disabled in engines that support it. The supporting
|
||||
@ -165,13 +160,6 @@ class ChannelManager {
|
||||
void StopAecDump();
|
||||
|
||||
private:
|
||||
void Construct(std::unique_ptr<MediaEngineInterface> me,
|
||||
std::unique_ptr<DataEngineInterface> dme,
|
||||
rtc::Thread* worker_thread,
|
||||
rtc::Thread* network_thread);
|
||||
bool InitMediaEngine_w();
|
||||
void DestructorDeletes_w();
|
||||
void Terminate_w();
|
||||
VoiceChannel* CreateVoiceChannel_w(
|
||||
webrtc::Call* call,
|
||||
const cricket::MediaConfig& media_config,
|
||||
@ -183,7 +171,6 @@ class ChannelManager {
|
||||
const std::string& content_name,
|
||||
bool srtp_required,
|
||||
const AudioOptions& options);
|
||||
void DestroyVoiceChannel_w(VoiceChannel* voice_channel);
|
||||
VideoChannel* CreateVideoChannel_w(
|
||||
webrtc::Call* call,
|
||||
const cricket::MediaConfig& media_config,
|
||||
@ -195,29 +182,21 @@ class ChannelManager {
|
||||
const std::string& content_name,
|
||||
bool srtp_required,
|
||||
const VideoOptions& options);
|
||||
void DestroyVideoChannel_w(VideoChannel* video_channel);
|
||||
RtpDataChannel* CreateRtpDataChannel_w(
|
||||
const cricket::MediaConfig& media_config,
|
||||
DtlsTransportInternal* rtp_transport,
|
||||
DtlsTransportInternal* rtcp_transport,
|
||||
rtc::Thread* signaling_thread,
|
||||
const std::string& content_name,
|
||||
bool srtp_required);
|
||||
void DestroyRtpDataChannel_w(RtpDataChannel* data_channel);
|
||||
|
||||
std::unique_ptr<MediaEngineInterface> media_engine_;
|
||||
std::unique_ptr<DataEngineInterface> data_media_engine_;
|
||||
bool initialized_;
|
||||
std::unique_ptr<MediaEngineInterface> media_engine_; // Nullable.
|
||||
std::unique_ptr<DataEngineInterface> data_engine_; // Non-null.
|
||||
bool initialized_ = false;
|
||||
rtc::Thread* main_thread_;
|
||||
rtc::Thread* worker_thread_;
|
||||
rtc::Thread* network_thread_;
|
||||
|
||||
// Vector contents are non-null.
|
||||
std::vector<std::unique_ptr<VoiceChannel>> voice_channels_;
|
||||
std::vector<std::unique_ptr<VideoChannel>> video_channels_;
|
||||
std::vector<std::unique_ptr<RtpDataChannel>> data_channels_;
|
||||
|
||||
bool enable_rtx_;
|
||||
bool capturing_;
|
||||
bool enable_rtx_ = false;
|
||||
bool capturing_ = false;
|
||||
};
|
||||
|
||||
} // namespace cricket
|
||||
|
||||
@ -45,6 +45,7 @@ class ChannelManagerTest : public testing::Test {
|
||||
cm_(new cricket::ChannelManager(
|
||||
std::unique_ptr<MediaEngineInterface>(fme_),
|
||||
std::unique_ptr<DataEngineInterface>(fdme_),
|
||||
rtc::Thread::Current(),
|
||||
rtc::Thread::Current())),
|
||||
fake_call_(webrtc::Call::Config(&event_log_)),
|
||||
transport_controller_(
|
||||
|
||||
@ -20,6 +20,7 @@
|
||||
#include "api/turncustomizer.h"
|
||||
#include "api/videosourceproxy.h"
|
||||
#include "logging/rtc_event_log/rtc_event_log.h"
|
||||
#include "media/base/rtpdataengine.h"
|
||||
#include "media/sctp/sctptransport.h"
|
||||
#include "rtc_base/bind.h"
|
||||
#include "rtc_base/checks.h"
|
||||
@ -139,8 +140,9 @@ bool PeerConnectionFactory::Initialize() {
|
||||
return false;
|
||||
}
|
||||
|
||||
channel_manager_.reset(new cricket::ChannelManager(
|
||||
std::move(media_engine_), worker_thread_, network_thread_));
|
||||
channel_manager_ = rtc::MakeUnique<cricket::ChannelManager>(
|
||||
std::move(media_engine_), rtc::MakeUnique<cricket::RtpDataEngine>(),
|
||||
worker_thread_, network_thread_);
|
||||
|
||||
channel_manager_->SetVideoRtxEnabled(true);
|
||||
if (!channel_manager_->Init()) {
|
||||
|
||||
@ -13,6 +13,7 @@
|
||||
#include <utility>
|
||||
|
||||
#include "media/base/fakemediaengine.h"
|
||||
#include "media/base/rtpdataengine.h"
|
||||
#include "media/engine/fakewebrtccall.h"
|
||||
#include "pc/audiotrack.h"
|
||||
#include "pc/channelmanager.h"
|
||||
@ -56,10 +57,10 @@ class RtpSenderReceiverTest : public testing::Test,
|
||||
: // Create fake media engine/etc. so we can create channels to use to
|
||||
// test RtpSenders/RtpReceivers.
|
||||
media_engine_(new cricket::FakeMediaEngine()),
|
||||
channel_manager_(
|
||||
std::unique_ptr<cricket::MediaEngineInterface>(media_engine_),
|
||||
rtc::Thread::Current(),
|
||||
rtc::Thread::Current()),
|
||||
channel_manager_(rtc::WrapUnique(media_engine_),
|
||||
rtc::MakeUnique<cricket::RtpDataEngine>(),
|
||||
rtc::Thread::Current(),
|
||||
rtc::Thread::Current()),
|
||||
fake_call_(Call::Config(&event_log_)),
|
||||
local_stream_(MediaStream::Create(kStreamLabel1)) {
|
||||
// Create channels to be used by the RtpSenders and RtpReceivers.
|
||||
|
||||
Reference in New Issue
Block a user