Introduce media engine factory where TaskQueueFactory dependency can be set.

For new factory function use same style as PeerConnectionFactory does:
insteat of multiple parameters pass struct where some parameters might be not set.


Bug: webrtc:10284
Change-Id: Ic54813e3afa3f873295409d2f7e2347c69f76988
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/131952
Reviewed-by: Niels Moller <nisse@webrtc.org>
Commit-Queue: Danil Chapovalov <danilchap@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#27556}
This commit is contained in:
Danil Chapovalov 2019-04-10 14:10:10 +02:00 committed by Commit Bot
parent 48cce4d9e8
commit 4844c5fd00
6 changed files with 153 additions and 0 deletions

View File

@ -332,6 +332,31 @@ rtc_static_library("rtc_audio_video") {
}
}
# Heavy but optional helper for unittests and webrtc users who prefer to use
# defaults factories or do not worry about extra dependencies and binary size.
rtc_source_set("rtc_media_engine_defaults") {
visibility = [ "*" ]
allow_poison = [
"audio_codecs",
"software_video_codecs",
]
sources = [
"engine/webrtc_media_engine_defaults.cc",
"engine/webrtc_media_engine_defaults.h",
]
deps = [
":rtc_audio_video",
"../api/audio_codecs:builtin_audio_decoder_factory",
"../api/audio_codecs:builtin_audio_encoder_factory",
"../api/task_queue:default_task_queue_factory",
"../api/video:builtin_video_bitrate_allocator_factory",
"../api/video_codecs:builtin_video_decoder_factory",
"../api/video_codecs:builtin_video_encoder_factory",
"../modules/audio_processing:api",
"../rtc_base:checks",
]
}
rtc_static_library("rtc_data") {
defines = []
deps = [
@ -472,6 +497,7 @@ if (rtc_include_tests) {
":rtc_internal_video_codecs",
":rtc_media",
":rtc_media_base",
":rtc_media_engine_defaults",
":rtc_media_tests_utils",
":rtc_simulcast_encoder_adapter",
":rtc_vp9_profile",

View File

@ -29,6 +29,26 @@
namespace cricket {
std::unique_ptr<MediaEngineInterface> CreateMediaEngine(
MediaEngineDependencies dependencies) {
auto audio_engine = absl::make_unique<WebRtcVoiceEngine>(
dependencies.task_queue_factory, std::move(dependencies.adm),
std::move(dependencies.audio_encoder_factory),
std::move(dependencies.audio_decoder_factory),
std::move(dependencies.audio_mixer),
std::move(dependencies.audio_processing));
#ifdef HAVE_WEBRTC_VIDEO
auto video_engine = absl::make_unique<WebRtcVideoEngine>(
std::move(dependencies.video_encoder_factory),
std::move(dependencies.video_decoder_factory),
std::move(dependencies.video_bitrate_allocator_factory));
#else
auto video_engine = absl::make_unique<NullWebRtcVideoEngine>();
#endif
return absl::make_unique<CompositeMediaEngine>(std::move(audio_engine),
std::move(video_engine));
}
std::unique_ptr<MediaEngineInterface> WebRtcMediaEngineFactory::Create(
rtc::scoped_refptr<webrtc::AudioDeviceModule> adm,
rtc::scoped_refptr<webrtc::AudioEncoderFactory> audio_encoder_factory,

View File

@ -15,6 +15,7 @@
#include <string>
#include <vector>
#include "api/task_queue/task_queue_factory.h"
#include "call/call.h"
#include "media/base/media_engine.h"
#include "modules/audio_device/include/audio_device.h"
@ -30,6 +31,30 @@ class VideoBitrateAllocatorFactory;
namespace cricket {
struct MediaEngineDependencies {
MediaEngineDependencies() = default;
MediaEngineDependencies(const MediaEngineDependencies&) = delete;
MediaEngineDependencies(MediaEngineDependencies&&) = default;
MediaEngineDependencies& operator=(const MediaEngineDependencies&) = delete;
MediaEngineDependencies& operator=(MediaEngineDependencies&&) = default;
~MediaEngineDependencies() = default;
webrtc::TaskQueueFactory* task_queue_factory = nullptr;
rtc::scoped_refptr<webrtc::AudioDeviceModule> adm;
rtc::scoped_refptr<webrtc::AudioEncoderFactory> audio_encoder_factory;
rtc::scoped_refptr<webrtc::AudioDecoderFactory> audio_decoder_factory;
rtc::scoped_refptr<webrtc::AudioMixer> audio_mixer;
rtc::scoped_refptr<webrtc::AudioProcessing> audio_processing;
std::unique_ptr<webrtc::VideoEncoderFactory> video_encoder_factory;
std::unique_ptr<webrtc::VideoDecoderFactory> video_decoder_factory;
std::unique_ptr<webrtc::VideoBitrateAllocatorFactory>
video_bitrate_allocator_factory;
};
std::unique_ptr<MediaEngineInterface> CreateMediaEngine(
MediaEngineDependencies dependencies);
class WebRtcMediaEngineFactory {
public:
// These Create methods may be called on any thread, though the engine is

View File

@ -0,0 +1,47 @@
/*
* Copyright (c) 2019 The WebRTC project authors. All Rights Reserved.
*
* 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.
*/
#include "media/engine/webrtc_media_engine_defaults.h"
#include "api/audio_codecs/builtin_audio_decoder_factory.h"
#include "api/audio_codecs/builtin_audio_encoder_factory.h"
#include "api/task_queue/default_task_queue_factory.h"
#include "api/video/builtin_video_bitrate_allocator_factory.h"
#include "api/video_codecs/builtin_video_decoder_factory.h"
#include "api/video_codecs/builtin_video_encoder_factory.h"
#include "modules/audio_processing/include/audio_processing.h"
#include "rtc_base/checks.h"
namespace webrtc {
void SetMediaEngineDefaults(cricket::MediaEngineDependencies* deps) {
RTC_DCHECK(deps);
if (deps->task_queue_factory == nullptr) {
static TaskQueueFactory* const task_queue_factory =
CreateDefaultTaskQueueFactory().release();
deps->task_queue_factory = task_queue_factory;
}
if (deps->audio_encoder_factory == nullptr)
deps->audio_encoder_factory = CreateBuiltinAudioEncoderFactory();
if (deps->audio_decoder_factory == nullptr)
deps->audio_decoder_factory = CreateBuiltinAudioDecoderFactory();
if (deps->audio_processing == nullptr)
deps->audio_processing = AudioProcessingBuilder().Create();
if (deps->video_encoder_factory == nullptr)
deps->video_encoder_factory = CreateBuiltinVideoEncoderFactory();
if (deps->video_decoder_factory == nullptr)
deps->video_decoder_factory = CreateBuiltinVideoDecoderFactory();
if (deps->video_bitrate_allocator_factory == nullptr) {
deps->video_bitrate_allocator_factory =
CreateBuiltinVideoBitrateAllocatorFactory();
}
}
} // namespace webrtc

View File

@ -0,0 +1,23 @@
/*
* Copyright (c) 2019 The WebRTC project authors. All Rights Reserved.
*
* 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.
*/
#ifndef MEDIA_ENGINE_WEBRTC_MEDIA_ENGINE_DEFAULTS_H_
#define MEDIA_ENGINE_WEBRTC_MEDIA_ENGINE_DEFAULTS_H_
#include "media/engine/webrtc_media_engine.h"
namespace webrtc {
// Sets required but null dependencies with default factories.
void SetMediaEngineDefaults(cricket::MediaEngineDependencies* deps);
} // namespace webrtc
#endif // MEDIA_ENGINE_WEBRTC_MEDIA_ENGINE_DEFAULTS_H_

View File

@ -9,6 +9,7 @@
*/
#include <memory>
#include <utility>
#include "api/audio_codecs/builtin_audio_decoder_factory.h"
#include "api/audio_codecs/builtin_audio_encoder_factory.h"
@ -16,6 +17,7 @@
#include "api/video_codecs/builtin_video_decoder_factory.h"
#include "api/video_codecs/builtin_video_encoder_factory.h"
#include "media/engine/webrtc_media_engine.h"
#include "media/engine/webrtc_media_engine_defaults.h"
#include "modules/audio_processing/include/audio_processing.h"
#include "test/field_trial.h"
#include "test/gtest.h"
@ -306,4 +308,14 @@ TEST(WebRtcMediaEngineFactoryTest, CreateWithVideoBitrateFactory) {
EXPECT_TRUE(engine);
}
TEST(WebRtcMediaEngineFactoryTest, Create) {
MediaEngineDependencies deps;
webrtc::SetMediaEngineDefaults(&deps);
std::unique_ptr<MediaEngineInterface> engine =
CreateMediaEngine(std::move(deps));
EXPECT_TRUE(engine);
}
} // namespace cricket