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
|
|
|
*/
|
|
|
|
|
|
2019-01-11 09:11:00 -08:00
|
|
|
#include "pc/channel_manager.h"
|
2013-07-10 00:45:36 +00:00
|
|
|
|
2017-10-30 09:57:42 -07:00
|
|
|
#include <utility>
|
2013-07-10 00:45:36 +00:00
|
|
|
|
2019-01-28 17:25:26 -08:00
|
|
|
#include "absl/algorithm/container.h"
|
Use absl::make_unique and absl::WrapUnique directly
Instead of going through our wrappers in ptr_util.h.
This CL was generated by the following script:
git grep -l ptr_util | xargs perl -pi -e 's,#include "rtc_base/ptr_util.h",#include "absl/memory/memory.h",'
git grep -l MakeUnique | xargs perl -pi -e 's,\b(rtc::)?MakeUnique\b,absl::make_unique,g'
git grep -l WrapUnique | xargs perl -pi -e 's,\b(rtc::)?WrapUnique\b,absl::WrapUnique,g'
git checkout -- rtc_base/ptr_util{.h,_unittest.cc}
git cl format
Followed by manually adding dependencies on
//third_party/abseil-cpp/absl/memory until `gn check` stopped
complaining.
Bug: webrtc:9473
Change-Id: I89ccd363f070479b8c431eb2c3d404a46eaacc1c
Reviewed-on: https://webrtc-review.googlesource.com/86600
Commit-Queue: Karl Wiberg <kwiberg@webrtc.org>
Reviewed-by: Danil Chapovalov <danilchap@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#23850}
2018-07-05 11:40:33 +02:00
|
|
|
#include "absl/memory/memory.h"
|
2018-10-19 15:29:54 +02:00
|
|
|
#include "absl/strings/match.h"
|
2022-02-23 13:44:59 +00:00
|
|
|
#include "api/media_types.h"
|
2021-02-10 14:31:24 +01:00
|
|
|
#include "api/sequence_checker.h"
|
2019-01-11 09:11:00 -08:00
|
|
|
#include "media/base/media_constants.h"
|
2017-09-15 06:47:31 +02:00
|
|
|
#include "rtc_base/checks.h"
|
2018-11-28 16:47:49 +01:00
|
|
|
#include "rtc_base/location.h"
|
2017-09-15 06:47:31 +02:00
|
|
|
#include "rtc_base/trace_event.h"
|
2013-07-10 00:45:36 +00:00
|
|
|
|
|
|
|
|
namespace cricket {
|
|
|
|
|
|
2021-04-01 16:49:42 +02:00
|
|
|
// static
|
|
|
|
|
std::unique_ptr<ChannelManager> ChannelManager::Create(
|
|
|
|
|
std::unique_ptr<MediaEngineInterface> media_engine,
|
|
|
|
|
bool enable_rtx,
|
|
|
|
|
rtc::Thread* worker_thread,
|
|
|
|
|
rtc::Thread* network_thread) {
|
|
|
|
|
RTC_DCHECK(network_thread);
|
|
|
|
|
RTC_DCHECK(worker_thread);
|
|
|
|
|
|
2021-04-16 11:12:14 +00:00
|
|
|
return absl::WrapUnique(new ChannelManager(
|
|
|
|
|
std::move(media_engine), enable_rtx, worker_thread, network_thread));
|
2021-04-01 16:49:42 +02:00
|
|
|
}
|
|
|
|
|
|
2017-11-06 15:40:09 -08:00
|
|
|
ChannelManager::ChannelManager(
|
|
|
|
|
std::unique_ptr<MediaEngineInterface> media_engine,
|
2021-04-01 16:49:42 +02:00
|
|
|
bool enable_rtx,
|
2017-11-06 15:40:09 -08:00
|
|
|
rtc::Thread* worker_thread,
|
|
|
|
|
rtc::Thread* network_thread)
|
|
|
|
|
: media_engine_(std::move(media_engine)),
|
2022-01-24 08:45:26 +01:00
|
|
|
signaling_thread_(rtc::Thread::Current()),
|
2017-11-06 15:40:09 -08:00
|
|
|
worker_thread_(worker_thread),
|
2021-04-01 16:49:42 +02:00
|
|
|
network_thread_(network_thread),
|
|
|
|
|
enable_rtx_(enable_rtx) {
|
2022-01-24 08:45:26 +01:00
|
|
|
RTC_DCHECK_RUN_ON(signaling_thread_);
|
2017-11-06 15:40:09 -08:00
|
|
|
RTC_DCHECK(worker_thread_);
|
|
|
|
|
RTC_DCHECK(network_thread_);
|
2022-01-24 08:45:26 +01:00
|
|
|
|
|
|
|
|
if (media_engine_) {
|
|
|
|
|
// TODO(tommi): Change VoiceEngine to do ctor time initialization so that
|
|
|
|
|
// this isn't necessary.
|
|
|
|
|
worker_thread_->Invoke<void>(RTC_FROM_HERE, [&] { media_engine_->Init(); });
|
|
|
|
|
}
|
2013-07-10 00:45:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ChannelManager::~ChannelManager() {
|
2022-01-24 08:45:26 +01:00
|
|
|
RTC_DCHECK_RUN_ON(signaling_thread_);
|
2022-01-26 10:21:57 +01:00
|
|
|
worker_thread_->Invoke<void>(RTC_FROM_HERE, [&] {
|
|
|
|
|
RTC_DCHECK_RUN_ON(worker_thread_);
|
|
|
|
|
RTC_DCHECK(voice_channels_.empty());
|
|
|
|
|
RTC_DCHECK(video_channels_.empty());
|
2022-01-28 08:53:00 +01:00
|
|
|
// While `media_engine_` is const throughout the ChannelManager's lifetime,
|
|
|
|
|
// it requires destruction to happen on the worker thread. Instead of
|
|
|
|
|
// marking the pointer as non-const, we live with this const_cast<> in the
|
|
|
|
|
// destructor.
|
2022-01-26 10:21:57 +01:00
|
|
|
const_cast<std::unique_ptr<MediaEngineInterface>&>(media_engine_).reset();
|
|
|
|
|
});
|
2013-07-10 00:45:36 +00:00
|
|
|
}
|
|
|
|
|
|
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;
|
|
|
|
|
}
|
2018-11-16 11:29:55 +01:00
|
|
|
*codecs = media_engine_->voice().send_codecs();
|
2016-06-14 07:12:39 -07:00
|
|
|
}
|
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;
|
|
|
|
|
}
|
2018-11-16 11:29:55 +01:00
|
|
|
*codecs = media_engine_->voice().recv_codecs();
|
2013-07-10 00:45:36 +00:00
|
|
|
}
|
|
|
|
|
|
2020-03-29 22:17:00 +02:00
|
|
|
void ChannelManager::GetSupportedVideoSendCodecs(
|
2016-11-10 03:36:53 -08:00
|
|
|
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();
|
|
|
|
|
|
2020-03-29 22:17:00 +02:00
|
|
|
std::vector<VideoCodec> video_codecs = media_engine_->video().send_codecs();
|
|
|
|
|
for (const auto& video_codec : video_codecs) {
|
|
|
|
|
if (!enable_rtx_ &&
|
|
|
|
|
absl::EqualsIgnoreCase(kRtxCodecName, video_codec.name)) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
codecs->push_back(video_codec);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ChannelManager::GetSupportedVideoReceiveCodecs(
|
|
|
|
|
std::vector<VideoCodec>* codecs) const {
|
|
|
|
|
if (!media_engine_) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
codecs->clear();
|
|
|
|
|
|
|
|
|
|
std::vector<VideoCodec> video_codecs = media_engine_->video().recv_codecs();
|
2016-11-28 06:02:22 -08:00
|
|
|
for (const auto& video_codec : video_codecs) {
|
|
|
|
|
if (!enable_rtx_ &&
|
2018-10-19 15:29:54 +02:00
|
|
|
absl::EqualsIgnoreCase(kRtxCodecName, video_codec.name)) {
|
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
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-03-16 13:40:51 +01:00
|
|
|
RtpHeaderExtensions ChannelManager::GetDefaultEnabledAudioRtpHeaderExtensions()
|
|
|
|
|
const {
|
|
|
|
|
if (!media_engine_)
|
|
|
|
|
return {};
|
|
|
|
|
return GetDefaultEnabledRtpHeaderExtensions(media_engine_->voice());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::vector<webrtc::RtpHeaderExtensionCapability>
|
|
|
|
|
ChannelManager::GetSupportedAudioRtpHeaderExtensions() const {
|
|
|
|
|
if (!media_engine_)
|
|
|
|
|
return {};
|
|
|
|
|
return media_engine_->voice().GetRtpHeaderExtensions();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
RtpHeaderExtensions ChannelManager::GetDefaultEnabledVideoRtpHeaderExtensions()
|
|
|
|
|
const {
|
|
|
|
|
if (!media_engine_)
|
|
|
|
|
return {};
|
|
|
|
|
return GetDefaultEnabledRtpHeaderExtensions(media_engine_->video());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::vector<webrtc::RtpHeaderExtensionCapability>
|
|
|
|
|
ChannelManager::GetSupportedVideoRtpHeaderExtensions() const {
|
|
|
|
|
if (!media_engine_)
|
|
|
|
|
return {};
|
|
|
|
|
return media_engine_->video().GetRtpHeaderExtensions();
|
|
|
|
|
}
|
|
|
|
|
|
2017-12-04 13:38:48 -08:00
|
|
|
VoiceChannel* ChannelManager::CreateVoiceChannel(
|
|
|
|
|
webrtc::Call* call,
|
2021-04-01 16:49:42 +02:00
|
|
|
const MediaConfig& media_config,
|
2022-01-24 08:45:26 +01:00
|
|
|
const std::string& mid,
|
2017-12-04 13:38:48 -08:00
|
|
|
bool srtp_required,
|
2018-10-11 15:33:17 -07:00
|
|
|
const webrtc::CryptoOptions& crypto_options,
|
2017-12-04 13:38:48 -08:00
|
|
|
const AudioOptions& options) {
|
2021-04-08 14:39:47 +02:00
|
|
|
RTC_DCHECK(call);
|
|
|
|
|
RTC_DCHECK(media_engine_);
|
2020-09-28 10:39:31 +02:00
|
|
|
// TODO(bugs.webrtc.org/11992): Remove this workaround after updates in
|
|
|
|
|
// PeerConnection and add the expectation that we're already on the right
|
|
|
|
|
// thread.
|
2017-12-04 13:38:48 -08:00
|
|
|
if (!worker_thread_->IsCurrent()) {
|
|
|
|
|
return worker_thread_->Invoke<VoiceChannel*>(RTC_FROM_HERE, [&] {
|
2022-01-24 08:45:26 +01:00
|
|
|
return CreateVoiceChannel(call, media_config, mid, srtp_required,
|
|
|
|
|
crypto_options, options);
|
2017-12-04 13:38:48 -08:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
RTC_DCHECK_RUN_ON(worker_thread_);
|
|
|
|
|
|
2018-11-16 11:29:55 +01:00
|
|
|
VoiceMediaChannel* media_channel = media_engine_->voice().CreateMediaChannel(
|
|
|
|
|
call, media_config, options, crypto_options);
|
2017-12-04 13:38:48 -08:00
|
|
|
if (!media_channel) {
|
|
|
|
|
return nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
2019-09-17 17:06:18 +02:00
|
|
|
auto voice_channel = std::make_unique<VoiceChannel>(
|
2022-01-24 08:45:26 +01:00
|
|
|
worker_thread_, network_thread_, signaling_thread_,
|
|
|
|
|
absl::WrapUnique(media_channel), mid, srtp_required, crypto_options,
|
|
|
|
|
&ssrc_generator_);
|
2017-12-04 13:38:48 -08:00
|
|
|
|
|
|
|
|
VoiceChannel* voice_channel_ptr = voice_channel.get();
|
|
|
|
|
voice_channels_.push_back(std::move(voice_channel));
|
|
|
|
|
return voice_channel_ptr;
|
|
|
|
|
}
|
|
|
|
|
|
2022-01-24 08:45:26 +01:00
|
|
|
void ChannelManager::DestroyVoiceChannel(VoiceChannel* channel) {
|
2015-12-08 22:15:17 +01:00
|
|
|
TRACE_EVENT0("webrtc", "ChannelManager::DestroyVoiceChannel");
|
2021-04-01 16:49:42 +02:00
|
|
|
RTC_DCHECK_RUN_ON(worker_thread_);
|
2021-04-08 14:39:47 +02:00
|
|
|
voice_channels_.erase(absl::c_find_if(
|
2022-01-24 08:45:26 +01:00
|
|
|
voice_channels_, [&](const auto& p) { return p.get() == channel; }));
|
2013-07-10 00:45:36 +00:00
|
|
|
}
|
|
|
|
|
|
2017-12-04 13:38:48 -08:00
|
|
|
VideoChannel* ChannelManager::CreateVideoChannel(
|
|
|
|
|
webrtc::Call* call,
|
2021-04-01 16:49:42 +02:00
|
|
|
const MediaConfig& media_config,
|
2022-01-24 08:45:26 +01:00
|
|
|
const std::string& mid,
|
2017-12-04 13:38:48 -08:00
|
|
|
bool srtp_required,
|
2018-10-11 15:33:17 -07:00
|
|
|
const webrtc::CryptoOptions& crypto_options,
|
2019-04-17 07:38:40 +02:00
|
|
|
const VideoOptions& options,
|
|
|
|
|
webrtc::VideoBitrateAllocatorFactory* video_bitrate_allocator_factory) {
|
2021-04-08 14:39:47 +02:00
|
|
|
RTC_DCHECK(call);
|
|
|
|
|
RTC_DCHECK(media_engine_);
|
2020-09-28 10:39:31 +02:00
|
|
|
// TODO(bugs.webrtc.org/11992): Remove this workaround after updates in
|
|
|
|
|
// PeerConnection and add the expectation that we're already on the right
|
|
|
|
|
// thread.
|
2017-12-04 13:38:48 -08:00
|
|
|
if (!worker_thread_->IsCurrent()) {
|
|
|
|
|
return worker_thread_->Invoke<VideoChannel*>(RTC_FROM_HERE, [&] {
|
2022-01-24 08:45:26 +01:00
|
|
|
return CreateVideoChannel(call, media_config, mid, srtp_required,
|
|
|
|
|
crypto_options, options,
|
2020-06-16 16:39:13 +02:00
|
|
|
video_bitrate_allocator_factory);
|
2017-12-04 13:38:48 -08:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
RTC_DCHECK_RUN_ON(worker_thread_);
|
|
|
|
|
|
2018-11-16 11:29:55 +01:00
|
|
|
VideoMediaChannel* media_channel = media_engine_->video().CreateMediaChannel(
|
2019-04-17 07:38:40 +02:00
|
|
|
call, media_config, options, crypto_options,
|
|
|
|
|
video_bitrate_allocator_factory);
|
2017-12-04 13:38:48 -08:00
|
|
|
if (!media_channel) {
|
|
|
|
|
return nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
2019-09-17 17:06:18 +02:00
|
|
|
auto video_channel = std::make_unique<VideoChannel>(
|
2022-01-24 08:45:26 +01:00
|
|
|
worker_thread_, network_thread_, signaling_thread_,
|
|
|
|
|
absl::WrapUnique(media_channel), mid, srtp_required, crypto_options,
|
|
|
|
|
&ssrc_generator_);
|
2018-10-17 13:15:42 -07:00
|
|
|
|
2017-12-04 13:38:48 -08:00
|
|
|
VideoChannel* video_channel_ptr = video_channel.get();
|
|
|
|
|
video_channels_.push_back(std::move(video_channel));
|
|
|
|
|
return video_channel_ptr;
|
|
|
|
|
}
|
|
|
|
|
|
2022-01-24 08:45:26 +01:00
|
|
|
void ChannelManager::DestroyVideoChannel(VideoChannel* channel) {
|
2015-12-08 22:15:17 +01:00
|
|
|
TRACE_EVENT0("webrtc", "ChannelManager::DestroyVideoChannel");
|
2022-01-24 08:45:26 +01:00
|
|
|
RTC_DCHECK_RUN_ON(worker_thread_);
|
2021-04-08 14:39:47 +02:00
|
|
|
|
2022-01-24 08:45:26 +01:00
|
|
|
video_channels_.erase(absl::c_find_if(
|
|
|
|
|
video_channels_, [&](const auto& p) { return p.get() == channel; }));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ChannelManager::DestroyChannel(ChannelInterface* channel) {
|
|
|
|
|
RTC_DCHECK(channel);
|
|
|
|
|
|
2017-11-06 15:40:09 -08:00
|
|
|
if (!worker_thread_->IsCurrent()) {
|
2022-01-28 08:53:00 +01:00
|
|
|
// TODO(tommi): Do this asynchronously when we have a way to make sure that
|
|
|
|
|
// the call to DestroyChannel runs before ~Call() runs, which today happens
|
|
|
|
|
// inside an Invoke from the signaling thread in PeerConnectin::Close().
|
|
|
|
|
worker_thread_->Invoke<void>(RTC_FROM_HERE,
|
|
|
|
|
[&] { DestroyChannel(channel); });
|
2017-11-06 15:40:09 -08:00
|
|
|
return;
|
2013-07-10 00:45:36 +00:00
|
|
|
}
|
|
|
|
|
|
2022-01-24 08:45:26 +01:00
|
|
|
if (channel->media_type() == MEDIA_TYPE_AUDIO) {
|
|
|
|
|
DestroyVoiceChannel(static_cast<VoiceChannel*>(channel));
|
|
|
|
|
} else {
|
|
|
|
|
RTC_DCHECK_EQ(channel->media_type(), MEDIA_TYPE_VIDEO);
|
|
|
|
|
DestroyVideoChannel(static_cast<VideoChannel*>(channel));
|
|
|
|
|
}
|
2013-07-10 00:45:36 +00:00
|
|
|
}
|
|
|
|
|
|
2019-06-11 14:04:16 +02:00
|
|
|
bool ChannelManager::StartAecDump(webrtc::FileWrapper file,
|
2016-01-15 03:06:36 -08:00
|
|
|
int64_t max_size_bytes) {
|
2021-04-01 19:14:54 +02:00
|
|
|
RTC_DCHECK_RUN_ON(worker_thread_);
|
|
|
|
|
return media_engine_->voice().StartAecDump(std::move(file), max_size_bytes);
|
2013-12-13 00:21:03 +00:00
|
|
|
}
|
|
|
|
|
|
2015-10-22 03:25:41 -07:00
|
|
|
void ChannelManager::StopAecDump() {
|
2021-04-01 19:14:54 +02:00
|
|
|
RTC_DCHECK_RUN_ON(worker_thread_);
|
|
|
|
|
media_engine_->voice().StopAecDump();
|
2015-10-22 03:25:41 -07:00
|
|
|
}
|
|
|
|
|
|
2013-07-10 00:45:36 +00:00
|
|
|
} // namespace cricket
|