Removes templating from CompositeMediaEngine.
Usage of templates makes it harder for tooling to help the user. This can be experienced when trying to investigate compile failures and using editor tools to browse the code. This CL replaces usage of templates with injection of unique pointers to interfaces that implements the behavior that previously was assumed by the templated implementation. Bug: webrtc:9883 Change-Id: Ica17af9646f68a9b063988f9e85d6acc8ca37c10 Reviewed-on: https://webrtc-review.googlesource.com/c/106703 Commit-Queue: Sebastian Jansson <srte@webrtc.org> Reviewed-by: Fredrik Solenberg <solenberg@webrtc.org> Cr-Commit-Position: refs/heads/master@{#25668}
This commit is contained in:
parent
84848f26b5
commit
fa0aa39fba
@ -374,6 +374,7 @@ rtc_static_library("rtc_audio_video") {
|
||||
"../rtc_base:stringutils",
|
||||
"../rtc_base/experiments:normalize_simulcast_size_experiment",
|
||||
"../system_wrappers",
|
||||
"//third_party/abseil-cpp/absl/memory",
|
||||
"//third_party/abseil-cpp/absl/strings",
|
||||
"//third_party/abseil-cpp/absl/types:optional",
|
||||
]
|
||||
|
||||
@ -12,6 +12,7 @@
|
||||
|
||||
#include <utility>
|
||||
|
||||
#include "absl/memory/memory.h"
|
||||
#include "absl/strings/match.h"
|
||||
#include "rtc_base/checks.h"
|
||||
|
||||
@ -552,10 +553,10 @@ bool FakeVideoEngine::SetCapture(bool capture) {
|
||||
}
|
||||
|
||||
FakeMediaEngine::FakeMediaEngine()
|
||||
: CompositeMediaEngine<FakeVoiceEngine, FakeVideoEngine>(std::tuple<>(),
|
||||
std::tuple<>()),
|
||||
voice_(&voice()),
|
||||
video_(&video()) {}
|
||||
: CompositeMediaEngine(absl::make_unique<FakeVoiceEngine>(),
|
||||
absl::make_unique<FakeVideoEngine>()),
|
||||
voice_(static_cast<FakeVoiceEngine*>(&voice())),
|
||||
video_(static_cast<FakeVideoEngine*>(&video())) {}
|
||||
FakeMediaEngine::~FakeMediaEngine() {}
|
||||
void FakeMediaEngine::SetAudioCodecs(const std::vector<AudioCodec>& codecs) {
|
||||
voice_->SetCodecs(codecs);
|
||||
|
||||
@ -554,8 +554,7 @@ class FakeVideoEngine : public VideoEngineInterface {
|
||||
friend class FakeMediaEngine;
|
||||
};
|
||||
|
||||
class FakeMediaEngine
|
||||
: public CompositeMediaEngine<FakeVoiceEngine, FakeVideoEngine> {
|
||||
class FakeMediaEngine : public CompositeMediaEngine {
|
||||
public:
|
||||
FakeMediaEngine();
|
||||
|
||||
|
||||
@ -10,6 +10,8 @@
|
||||
|
||||
#include "media/base/mediaengine.h"
|
||||
|
||||
#include <utility>
|
||||
|
||||
#include "api/video/video_bitrate_allocation.h"
|
||||
#include "rtc_base/stringencode.h"
|
||||
|
||||
@ -104,4 +106,83 @@ webrtc::RTCError ValidateRtpParameters(
|
||||
return webrtc::RTCError::OK();
|
||||
}
|
||||
|
||||
CompositeMediaEngine::CompositeMediaEngine(
|
||||
std::unique_ptr<VoiceEngineInterface> voice_engine,
|
||||
std::unique_ptr<VideoEngineInterface> video_engine)
|
||||
: voice_engine_(std::move(voice_engine)),
|
||||
video_engine_(std::move(video_engine)) {}
|
||||
|
||||
CompositeMediaEngine::~CompositeMediaEngine() = default;
|
||||
|
||||
bool CompositeMediaEngine::Init() {
|
||||
voice().Init();
|
||||
return true;
|
||||
}
|
||||
|
||||
rtc::scoped_refptr<webrtc::AudioState> CompositeMediaEngine::GetAudioState()
|
||||
const {
|
||||
return voice().GetAudioState();
|
||||
}
|
||||
|
||||
VoiceMediaChannel* CompositeMediaEngine::CreateChannel(
|
||||
webrtc::Call* call,
|
||||
const MediaConfig& config,
|
||||
const AudioOptions& options,
|
||||
const webrtc::CryptoOptions& crypto_options) {
|
||||
return voice().CreateMediaChannel(call, config, options, crypto_options);
|
||||
}
|
||||
|
||||
VideoMediaChannel* CompositeMediaEngine::CreateVideoChannel(
|
||||
webrtc::Call* call,
|
||||
const MediaConfig& config,
|
||||
const VideoOptions& options,
|
||||
const webrtc::CryptoOptions& crypto_options) {
|
||||
return video().CreateMediaChannel(call, config, options, crypto_options);
|
||||
}
|
||||
|
||||
const std::vector<AudioCodec>& CompositeMediaEngine::audio_send_codecs() {
|
||||
return voice().send_codecs();
|
||||
}
|
||||
|
||||
const std::vector<AudioCodec>& CompositeMediaEngine::audio_recv_codecs() {
|
||||
return voice().recv_codecs();
|
||||
}
|
||||
|
||||
RtpCapabilities CompositeMediaEngine::GetAudioCapabilities() {
|
||||
return voice().GetCapabilities();
|
||||
}
|
||||
|
||||
std::vector<VideoCodec> CompositeMediaEngine::video_codecs() {
|
||||
return video().codecs();
|
||||
}
|
||||
|
||||
RtpCapabilities CompositeMediaEngine::GetVideoCapabilities() {
|
||||
return video().GetCapabilities();
|
||||
}
|
||||
|
||||
bool CompositeMediaEngine::StartAecDump(rtc::PlatformFile file,
|
||||
int64_t max_size_bytes) {
|
||||
return voice().StartAecDump(file, max_size_bytes);
|
||||
}
|
||||
|
||||
void CompositeMediaEngine::StopAecDump() {
|
||||
voice().StopAecDump();
|
||||
}
|
||||
|
||||
VoiceEngineInterface& CompositeMediaEngine::voice() {
|
||||
return *voice_engine_.get();
|
||||
}
|
||||
|
||||
VideoEngineInterface& CompositeMediaEngine::video() {
|
||||
return *video_engine_.get();
|
||||
}
|
||||
|
||||
const VoiceEngineInterface& CompositeMediaEngine::voice() const {
|
||||
return *voice_engine_.get();
|
||||
}
|
||||
|
||||
const VideoEngineInterface& CompositeMediaEngine::video() const {
|
||||
return *video_engine_.get();
|
||||
}
|
||||
|
||||
}; // namespace cricket
|
||||
|
||||
@ -15,9 +15,8 @@
|
||||
#include <CoreAudio/CoreAudio.h>
|
||||
#endif
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <tuple>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#include "api/audio_codecs/audio_decoder_factory.h"
|
||||
@ -147,68 +146,45 @@ class MediaEngineInterface {
|
||||
|
||||
// CompositeMediaEngine constructs a MediaEngine from separate
|
||||
// voice and video engine classes.
|
||||
template <class VOICE, class VIDEO>
|
||||
class CompositeMediaEngine : public MediaEngineInterface {
|
||||
public:
|
||||
template <class... Args1, class... Args2>
|
||||
CompositeMediaEngine(std::tuple<Args1...> first_args,
|
||||
std::tuple<Args2...> second_args)
|
||||
: engines_(std::piecewise_construct,
|
||||
std::move(first_args),
|
||||
std::move(second_args)) {}
|
||||
CompositeMediaEngine(std::unique_ptr<VoiceEngineInterface> audio_engine,
|
||||
std::unique_ptr<VideoEngineInterface> video_engine);
|
||||
~CompositeMediaEngine() override;
|
||||
bool Init() override;
|
||||
|
||||
virtual ~CompositeMediaEngine() {}
|
||||
virtual bool Init() {
|
||||
voice().Init();
|
||||
return true;
|
||||
}
|
||||
|
||||
virtual rtc::scoped_refptr<webrtc::AudioState> GetAudioState() const {
|
||||
return voice().GetAudioState();
|
||||
}
|
||||
virtual VoiceMediaChannel* CreateChannel(
|
||||
rtc::scoped_refptr<webrtc::AudioState> GetAudioState() const override;
|
||||
VoiceMediaChannel* CreateChannel(
|
||||
webrtc::Call* call,
|
||||
const MediaConfig& config,
|
||||
const AudioOptions& options,
|
||||
const webrtc::CryptoOptions& crypto_options) {
|
||||
return voice().CreateMediaChannel(call, config, options, crypto_options);
|
||||
}
|
||||
virtual VideoMediaChannel* CreateVideoChannel(
|
||||
const webrtc::CryptoOptions& crypto_options) override;
|
||||
|
||||
VideoMediaChannel* CreateVideoChannel(
|
||||
webrtc::Call* call,
|
||||
const MediaConfig& config,
|
||||
const VideoOptions& options,
|
||||
const webrtc::CryptoOptions& crypto_options) {
|
||||
return video().CreateMediaChannel(call, config, options, crypto_options);
|
||||
}
|
||||
const webrtc::CryptoOptions& crypto_options) override;
|
||||
|
||||
virtual const std::vector<AudioCodec>& audio_send_codecs() {
|
||||
return voice().send_codecs();
|
||||
}
|
||||
virtual const std::vector<AudioCodec>& audio_recv_codecs() {
|
||||
return voice().recv_codecs();
|
||||
}
|
||||
virtual RtpCapabilities GetAudioCapabilities() {
|
||||
return voice().GetCapabilities();
|
||||
}
|
||||
virtual std::vector<VideoCodec> video_codecs() { return video().codecs(); }
|
||||
virtual RtpCapabilities GetVideoCapabilities() {
|
||||
return video().GetCapabilities();
|
||||
}
|
||||
const std::vector<AudioCodec>& audio_send_codecs() override;
|
||||
const std::vector<AudioCodec>& audio_recv_codecs() override;
|
||||
RtpCapabilities GetAudioCapabilities() override;
|
||||
|
||||
virtual bool StartAecDump(rtc::PlatformFile file, int64_t max_size_bytes) {
|
||||
return voice().StartAecDump(file, max_size_bytes);
|
||||
}
|
||||
std::vector<VideoCodec> video_codecs() override;
|
||||
RtpCapabilities GetVideoCapabilities() override;
|
||||
|
||||
virtual void StopAecDump() { voice().StopAecDump(); }
|
||||
bool StartAecDump(rtc::PlatformFile file, int64_t max_size_bytes) override;
|
||||
void StopAecDump() override;
|
||||
|
||||
protected:
|
||||
VOICE& voice() { return engines_.first; }
|
||||
VIDEO& video() { return engines_.second; }
|
||||
const VOICE& voice() const { return engines_.first; }
|
||||
const VIDEO& video() const { return engines_.second; }
|
||||
VoiceEngineInterface& voice();
|
||||
VideoEngineInterface& video();
|
||||
const VoiceEngineInterface& voice() const;
|
||||
const VideoEngineInterface& video() const;
|
||||
|
||||
private:
|
||||
std::pair<VOICE, VIDEO> engines_;
|
||||
std::unique_ptr<VoiceEngineInterface> voice_engine_;
|
||||
std::unique_ptr<VideoEngineInterface> video_engine_;
|
||||
};
|
||||
|
||||
enum DataChannelType {
|
||||
|
||||
@ -9,6 +9,7 @@
|
||||
*/
|
||||
|
||||
#include "media/engine/nullwebrtcvideoengine.h"
|
||||
#include "absl/memory/memory.h"
|
||||
#include "media/engine/webrtcvoiceengine.h"
|
||||
#include "modules/audio_device/include/mock_audio_device.h"
|
||||
#include "modules/audio_processing/include/audio_processing.h"
|
||||
@ -18,8 +19,7 @@
|
||||
|
||||
namespace cricket {
|
||||
|
||||
class WebRtcMediaEngineNullVideo
|
||||
: public CompositeMediaEngine<WebRtcVoiceEngine, NullWebRtcVideoEngine> {
|
||||
class WebRtcMediaEngineNullVideo : public CompositeMediaEngine {
|
||||
public:
|
||||
WebRtcMediaEngineNullVideo(
|
||||
webrtc::AudioDeviceModule* adm,
|
||||
@ -27,13 +27,13 @@ class WebRtcMediaEngineNullVideo
|
||||
audio_encoder_factory,
|
||||
const rtc::scoped_refptr<webrtc::AudioDecoderFactory>&
|
||||
audio_decoder_factory)
|
||||
: CompositeMediaEngine<WebRtcVoiceEngine, NullWebRtcVideoEngine>(
|
||||
std::forward_as_tuple(adm,
|
||||
audio_encoder_factory,
|
||||
audio_decoder_factory,
|
||||
nullptr,
|
||||
webrtc::AudioProcessingBuilder().Create()),
|
||||
std::forward_as_tuple()) {}
|
||||
: CompositeMediaEngine(absl::make_unique<WebRtcVoiceEngine>(
|
||||
adm,
|
||||
audio_encoder_factory,
|
||||
audio_decoder_factory,
|
||||
nullptr,
|
||||
webrtc::AudioProcessingBuilder().Create()),
|
||||
absl::make_unique<NullWebRtcVideoEngine>()) {}
|
||||
};
|
||||
|
||||
// Simple test to check if NullWebRtcVideoEngine implements the methods
|
||||
|
||||
@ -11,10 +11,9 @@
|
||||
#include "media/engine/webrtcmediaengine.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <memory>
|
||||
#include <tuple>
|
||||
#include <utility>
|
||||
|
||||
#include "absl/memory/memory.h"
|
||||
#include "api/video/builtin_video_bitrate_allocator_factory.h"
|
||||
#include "api/video_codecs/video_decoder_factory.h"
|
||||
#include "api/video_codecs/video_encoder_factory.h"
|
||||
@ -43,23 +42,20 @@ MediaEngineInterface* CreateWebRtcMediaEngine(
|
||||
video_bitrate_allocator_factory,
|
||||
rtc::scoped_refptr<webrtc::AudioMixer> audio_mixer,
|
||||
rtc::scoped_refptr<webrtc::AudioProcessing> audio_processing) {
|
||||
std::unique_ptr<VideoEngineInterface> video_engine;
|
||||
#ifdef HAVE_WEBRTC_VIDEO
|
||||
typedef WebRtcVideoEngine VideoEngine;
|
||||
std::tuple<std::unique_ptr<WebRtcVideoEncoderFactory>,
|
||||
std::unique_ptr<WebRtcVideoDecoderFactory>,
|
||||
std::unique_ptr<webrtc::VideoBitrateAllocatorFactory>>
|
||||
video_args(
|
||||
(std::unique_ptr<WebRtcVideoEncoderFactory>(video_encoder_factory)),
|
||||
(std::unique_ptr<WebRtcVideoDecoderFactory>(video_decoder_factory)),
|
||||
(std::move(video_bitrate_allocator_factory)));
|
||||
video_engine = absl::make_unique<WebRtcVideoEngine>(
|
||||
std::unique_ptr<WebRtcVideoEncoderFactory>(video_encoder_factory),
|
||||
std::unique_ptr<WebRtcVideoDecoderFactory>(video_decoder_factory),
|
||||
std::move(video_bitrate_allocator_factory));
|
||||
#else
|
||||
typedef NullWebRtcVideoEngine VideoEngine;
|
||||
std::tuple<> video_args;
|
||||
video_engine = absl::make_unique<NullWebRtcVideoEngine>();
|
||||
#endif
|
||||
return new CompositeMediaEngine<WebRtcVoiceEngine, VideoEngine>(
|
||||
std::forward_as_tuple(adm, audio_encoder_factory, audio_decoder_factory,
|
||||
audio_mixer, audio_processing),
|
||||
std::move(video_args));
|
||||
return new CompositeMediaEngine(
|
||||
absl::make_unique<WebRtcVoiceEngine>(adm, audio_encoder_factory,
|
||||
audio_decoder_factory, audio_mixer,
|
||||
audio_processing),
|
||||
std::move(video_engine));
|
||||
}
|
||||
|
||||
} // namespace
|
||||
@ -156,23 +152,17 @@ std::unique_ptr<MediaEngineInterface> WebRtcMediaEngineFactory::Create(
|
||||
rtc::scoped_refptr<webrtc::AudioMixer> audio_mixer,
|
||||
rtc::scoped_refptr<webrtc::AudioProcessing> audio_processing) {
|
||||
#ifdef HAVE_WEBRTC_VIDEO
|
||||
typedef WebRtcVideoEngine VideoEngine;
|
||||
std::tuple<std::unique_ptr<webrtc::VideoEncoderFactory>,
|
||||
std::unique_ptr<webrtc::VideoDecoderFactory>,
|
||||
std::unique_ptr<webrtc::VideoBitrateAllocatorFactory>>
|
||||
video_args(std::move(video_encoder_factory),
|
||||
std::move(video_decoder_factory),
|
||||
std::move(video_bitrate_allocator_factory));
|
||||
auto video_engine = absl::make_unique<WebRtcVideoEngine>(
|
||||
std::move(video_encoder_factory), std::move(video_decoder_factory),
|
||||
std::move(video_bitrate_allocator_factory));
|
||||
#else
|
||||
typedef NullWebRtcVideoEngine VideoEngine;
|
||||
std::tuple<> video_args;
|
||||
auto video_engine = absl::make_unique<NullWebRtcVideoEngine>();
|
||||
#endif
|
||||
return std::unique_ptr<MediaEngineInterface>(
|
||||
new CompositeMediaEngine<WebRtcVoiceEngine, VideoEngine>(
|
||||
std::forward_as_tuple(adm, audio_encoder_factory,
|
||||
audio_decoder_factory, audio_mixer,
|
||||
audio_processing),
|
||||
std::move(video_args)));
|
||||
return std::unique_ptr<MediaEngineInterface>(new CompositeMediaEngine(
|
||||
absl::make_unique<WebRtcVoiceEngine>(adm, audio_encoder_factory,
|
||||
audio_decoder_factory, audio_mixer,
|
||||
audio_processing),
|
||||
std::move(video_engine)));
|
||||
}
|
||||
|
||||
namespace {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user