Clean up the NetEqFactory API.

This CL decouples NetEqFactory and AudioDecoderFactory.
AudioDecoderFactory is used in more places than just inside of NetEq, so
decoupling these makes sense.

Bug: webrtc:11005
Change-Id: I78dd856e4248e398e69a65816b062ef30555b055
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/161005
Reviewed-by: Karl Wiberg <kwiberg@webrtc.org>
Commit-Queue: Ivo Creusen <ivoc@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#29961}
This commit is contained in:
Ivo Creusen 2019-11-28 14:07:14 +01:00 committed by Commit Bot
parent 2d02c943b2
commit 39cf3c723e
17 changed files with 34 additions and 174 deletions

View File

@ -601,26 +601,6 @@ rtc_library("neteq_simulator_api") {
]
}
rtc_source_set("neteq_factory_with_codecs") {
visibility = [ "*" ]
testonly = true
sources = [
"test/neteq_factory_with_codecs.cc",
"test/neteq_factory_with_codecs.h",
]
deps = [
":scoped_refptr",
"../modules/audio_coding:neteq",
"../system_wrappers:system_wrappers",
"audio_codecs:audio_codecs_api",
"audio_codecs:builtin_audio_decoder_factory",
"neteq:default_neteq_controller_factory",
"neteq:neteq_api",
"neteq:neteq_controller_api",
]
}
rtc_source_set("function_view") {
visibility = [ "*" ]
sources = [

View File

@ -20,21 +20,8 @@ CustomNetEqFactory::CustomNetEqFactory(
std::unique_ptr<NetEqControllerFactory> controller_factory)
: controller_factory_(std::move(controller_factory)) {}
CustomNetEqFactory::CustomNetEqFactory(
rtc::scoped_refptr<AudioDecoderFactory> decoder_factory,
std::unique_ptr<NetEqControllerFactory> controller_factory)
: decoder_factory_(decoder_factory),
controller_factory_(std::move(controller_factory)) {}
CustomNetEqFactory::~CustomNetEqFactory() = default;
std::unique_ptr<NetEq> CustomNetEqFactory::CreateNetEq(
const NetEq::Config& config,
Clock* clock) const {
return std::make_unique<NetEqImpl>(
config, NetEqImpl::Dependencies(config, clock, decoder_factory_,
*controller_factory_));
}
std::unique_ptr<NetEq> CustomNetEqFactory::CreateNetEq(
const NetEq::Config& config,
const rtc::scoped_refptr<AudioDecoderFactory>& decoder_factory,

View File

@ -22,30 +22,21 @@
namespace webrtc {
// This factory can be used to generate NetEq instances that make use of a
// custom AudioDecoderFactory and/or NetEqControllerFactory. Using a custom
// AudioDecoderFactory is deprecated and the functionality will be removed soon.
// custom NetEqControllerFactory.
class CustomNetEqFactory : public NetEqFactory {
public:
explicit CustomNetEqFactory(
std::unique_ptr<NetEqControllerFactory> controller_factory);
// This constructor is deprecated and will be removed soon.
CustomNetEqFactory(
rtc::scoped_refptr<AudioDecoderFactory> decoder_factory,
std::unique_ptr<NetEqControllerFactory> controller_factory);
~CustomNetEqFactory() override;
CustomNetEqFactory(const CustomNetEqFactory&) = delete;
CustomNetEqFactory& operator=(const CustomNetEqFactory&) = delete;
std::unique_ptr<NetEq> CreateNetEq(const NetEq::Config& config,
Clock* clock) const override;
std::unique_ptr<NetEq> CreateNetEq(
const NetEq::Config& config,
const rtc::scoped_refptr<AudioDecoderFactory>& decoder_factory,
Clock* clock) const override;
private:
rtc::scoped_refptr<AudioDecoderFactory> decoder_factory_;
std::unique_ptr<NetEqControllerFactory> controller_factory_;
};

View File

@ -31,9 +31,6 @@ class NetEqFactory {
const NetEq::Config& config,
const rtc::scoped_refptr<AudioDecoderFactory>& decoder_factory,
Clock* clock) const = 0;
// This method is deprecated and will be removed.
virtual std::unique_ptr<NetEq> CreateNetEq(const NetEq::Config& config,
Clock* clock) const = 0;
};
} // namespace webrtc

View File

@ -1,55 +0,0 @@
/*
* 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 "api/test/neteq_factory_with_codecs.h"
#include "api/audio_codecs/audio_decoder_factory.h"
#include "api/audio_codecs/builtin_audio_decoder_factory.h"
#include "api/neteq/default_neteq_controller_factory.h"
#include "api/neteq/neteq_controller_factory.h"
#include "api/neteq/neteq_factory.h"
#include "modules/audio_coding/neteq/decision_logic.h"
#include "modules/audio_coding/neteq/neteq_impl.h"
#include "system_wrappers/include/clock.h"
namespace webrtc {
namespace {
class NetEqFactoryWithCodecs final : public NetEqFactory {
public:
std::unique_ptr<NetEq> CreateNetEq(const NetEq::Config& config,
Clock* clock) const override {
return std::make_unique<NetEqImpl>(
config, NetEqImpl::Dependencies(config, clock, decoder_factory_,
*controller_factory_));
}
std::unique_ptr<NetEq> CreateNetEq(
const NetEq::Config& config,
const rtc::scoped_refptr<AudioDecoderFactory>& decoder_factory,
Clock* clock) const override {
return std::make_unique<NetEqImpl>(
config, NetEqImpl::Dependencies(config, clock, decoder_factory,
*controller_factory_));
}
private:
const rtc::scoped_refptr<AudioDecoderFactory> decoder_factory_ =
CreateBuiltinAudioDecoderFactory();
const std::unique_ptr<NetEqControllerFactory> controller_factory_ =
std::make_unique<DefaultNetEqControllerFactory>();
};
} // namespace
std::unique_ptr<NetEqFactory> CreateNetEqFactoryWithCodecs() {
return std::make_unique<NetEqFactoryWithCodecs>();
}
} // namespace webrtc

View File

@ -1,25 +0,0 @@
/*
* 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 API_TEST_NETEQ_FACTORY_WITH_CODECS_H_
#define API_TEST_NETEQ_FACTORY_WITH_CODECS_H_
#include <memory>
#include "api/neteq/neteq_factory.h"
namespace webrtc {
// This NetEq factory will use WebRTC's built-in AudioDecoders as well as the
// built-in NetEqController logic.
std::unique_ptr<NetEqFactory> CreateNetEqFactoryWithCodecs();
} // namespace webrtc
#endif // API_TEST_NETEQ_FACTORY_WITH_CODECS_H_

View File

@ -1065,6 +1065,7 @@ rtc_library("neteq_tools_minimal") {
]
deps = [
":default_neteq_factory",
":neteq",
"../../api:neteq_simulator_api",
"../../api:rtp_headers",
@ -1239,11 +1240,11 @@ rtc_library("audio_coding_modules_tests_shared") {
deps = [
":audio_coding",
":audio_coding_module_typedefs",
":default_neteq_factory",
":neteq_test_tools",
":neteq_tools_minimal",
":webrtc_opus_wrapper",
"..:module_api",
"../../api:neteq_factory_with_codecs",
"../../api:rtp_headers",
"../../api/audio:audio_frame_api",
"../../api/audio_codecs:builtin_audio_decoder_factory",
@ -1630,10 +1631,10 @@ if (rtc_include_tests) {
]
deps = [
":default_neteq_factory",
":neteq",
":neteq_test_tools",
":pcm16b",
"../../api:neteq_factory_with_codecs",
"../../api/audio:audio_frame_api",
"../../api/audio_codecs:audio_codecs_api",
"../../api/audio_codecs:builtin_audio_decoder_factory",
@ -1655,11 +1656,10 @@ if (rtc_include_tests) {
]
deps = [
":default_neteq_factory",
":neteq",
":neteq_test_tools",
"../../api/audio_codecs:builtin_audio_decoder_factory",
"../../api/neteq:custom_neteq_factory",
"../../api/neteq:default_neteq_controller_factory",
"../../api/neteq:neteq_api",
"../../rtc_base:checks",
"../../system_wrappers",
@ -2072,6 +2072,7 @@ if (rtc_include_tests) {
":audio_coding_opus_common",
":audio_encoder_cng",
":audio_network_adaptor",
":default_neteq_factory",
":g711",
":ilbc",
":isac",
@ -2088,7 +2089,6 @@ if (rtc_include_tests) {
":webrtc_opus",
"..:module_api",
"..:module_api_public",
"../../api:neteq_factory_with_codecs",
"../../api/audio:audio_frame_api",
"../../api/audio_codecs:audio_codecs_api",
"../../api/audio_codecs:builtin_audio_decoder_factory",
@ -2097,7 +2097,6 @@ if (rtc_include_tests) {
"../../api/audio_codecs/opus:audio_decoder_opus",
"../../api/audio_codecs/opus:audio_encoder_multiopus",
"../../api/audio_codecs/opus:audio_encoder_opus",
"../../api/neteq:custom_neteq_factory",
"../../api/neteq:default_neteq_controller_factory",
"../../api/neteq:neteq_api",
"../../api/neteq:neteq_controller_api",

View File

@ -28,12 +28,4 @@ std::unique_ptr<NetEq> DefaultNetEqFactory::CreateNetEq(
controller_factory_));
}
std::unique_ptr<NetEq> DefaultNetEqFactory::CreateNetEq(
const NetEq::Config& /*config*/,
Clock* /*clock*/) const {
RTC_NOTREACHED() << "Calling CreateNetEq without an AudioDecoderFactory on "
"DefaultNetEqFactory is not supported.";
return nullptr;
}
} // namespace webrtc

View File

@ -32,8 +32,6 @@ class DefaultNetEqFactory : public NetEqFactory {
const NetEq::Config& config,
const rtc::scoped_refptr<AudioDecoderFactory>& decoder_factory,
Clock* clock) const override;
std::unique_ptr<NetEq> CreateNetEq(const NetEq::Config& config,
Clock* clock) const override;
private:
const DefaultNetEqControllerFactory controller_factory_;

View File

@ -18,9 +18,9 @@
#include "api/neteq/default_neteq_controller_factory.h"
#include "api/neteq/neteq.h"
#include "api/neteq/neteq_controller.h"
#include "api/test/neteq_factory_with_codecs.h"
#include "modules/audio_coding/neteq/accelerate.h"
#include "modules/audio_coding/neteq/decision_logic.h"
#include "modules/audio_coding/neteq/default_neteq_factory.h"
#include "modules/audio_coding/neteq/expand.h"
#include "modules/audio_coding/neteq/histogram.h"
#include "modules/audio_coding/neteq/mock/mock_decoder_database.h"
@ -252,8 +252,9 @@ class NetEqImplTest : public ::testing::Test {
TEST(NetEq, CreateAndDestroy) {
NetEq::Config config;
SimulatedClock clock(0);
std::unique_ptr<NetEqFactory> neteq_factory = CreateNetEqFactoryWithCodecs();
std::unique_ptr<NetEq> neteq = neteq_factory->CreateNetEq(config, &clock);
auto decoder_factory = CreateBuiltinAudioDecoderFactory();
std::unique_ptr<NetEq> neteq =
DefaultNetEqFactory().CreateNetEq(config, decoder_factory, &clock);
}
TEST_F(NetEqImplTest, RegisterPayloadType) {

View File

@ -13,9 +13,9 @@
#include "absl/memory/memory.h"
#include "api/audio/audio_frame.h"
#include "api/audio_codecs/audio_decoder.h"
#include "api/neteq/custom_neteq_factory.h"
#include "api/neteq/default_neteq_controller_factory.h"
#include "api/audio_codecs/builtin_audio_decoder_factory.h"
#include "api/neteq/neteq.h"
#include "modules/audio_coding/neteq/default_neteq_factory.h"
#include "modules/audio_coding/neteq/tools/rtp_generator.h"
#include "rtc_base/ref_counted_object.h"
#include "system_wrappers/include/clock.h"
@ -31,9 +31,7 @@ std::unique_ptr<NetEq> CreateNetEq(
const NetEq::Config& config,
Clock* clock,
const rtc::scoped_refptr<AudioDecoderFactory>& decoder_factory) {
CustomNetEqFactory neteq_factory(
decoder_factory, std::make_unique<DefaultNetEqControllerFactory>());
return neteq_factory.CreateNetEq(config, clock);
return DefaultNetEqFactory().CreateNetEq(config, decoder_factory, clock);
}
} // namespace

View File

@ -18,8 +18,8 @@
#include "api/audio/audio_frame.h"
#include "api/audio_codecs/builtin_audio_decoder_factory.h"
#include "api/neteq/neteq.h"
#include "api/test/neteq_factory_with_codecs.h"
#include "modules/audio_coding/codecs/pcm16b/pcm16b.h"
#include "modules/audio_coding/neteq/default_neteq_factory.h"
#include "modules/audio_coding/neteq/tools/input_audio_file.h"
#include "modules/audio_coding/neteq/tools/rtp_generator.h"
#include "rtc_base/strings/string_builder.h"
@ -68,10 +68,10 @@ class NetEqStereoTest : public ::testing::TestWithParam<TestParameters> {
last_arrival_time_(0) {
NetEq::Config config;
config.sample_rate_hz = sample_rate_hz_;
std::unique_ptr<NetEqFactory> neteq_factory =
CreateNetEqFactoryWithCodecs();
neteq_mono_ = neteq_factory->CreateNetEq(config, &clock_);
neteq_ = neteq_factory->CreateNetEq(config, &clock_);
DefaultNetEqFactory neteq_factory;
auto decoder_factory = CreateBuiltinAudioDecoderFactory();
neteq_mono_ = neteq_factory.CreateNetEq(config, decoder_factory, &clock_);
neteq_ = neteq_factory.CreateNetEq(config, decoder_factory, &clock_);
input_ = new int16_t[frame_size_samples_];
encoded_ = new uint8_t[2 * frame_size_samples_];
input_multi_channel_ = new int16_t[frame_size_samples_ * num_channels_];

View File

@ -23,7 +23,6 @@
#include "absl/flags/flag.h"
#include "api/audio/audio_frame.h"
#include "api/audio_codecs/builtin_audio_decoder_factory.h"
#include "api/test/neteq_factory_with_codecs.h"
#include "modules/audio_coding/codecs/pcm16b/pcm16b.h"
#include "modules/audio_coding/neteq/test/neteq_decoding_test.h"
#include "modules/audio_coding/neteq/tools/audio_loop.h"

View File

@ -10,8 +10,9 @@
#include "modules/audio_coding/neteq/test/neteq_decoding_test.h"
#include "api/audio_codecs/builtin_audio_decoder_factory.h"
#include "api/rtp_headers.h"
#include "api/test/neteq_factory_with_codecs.h"
#include "modules/audio_coding/neteq/default_neteq_factory.h"
#include "modules/audio_coding/neteq/test/result_sink.h"
#include "rtc_base/strings/string_builder.h"
#include "test/testsupport/file_utils.h"
@ -81,8 +82,8 @@ NetEqDecodingTest::NetEqDecodingTest()
}
void NetEqDecodingTest::SetUp() {
std::unique_ptr<NetEqFactory> neteq_factory = CreateNetEqFactoryWithCodecs();
neteq_ = neteq_factory->CreateNetEq(config_, &clock_);
auto decoder_factory = CreateBuiltinAudioDecoderFactory();
neteq_ = DefaultNetEqFactory().CreateNetEq(config_, decoder_factory, &clock_);
NetEqNetworkStatistics stat;
ASSERT_EQ(0, neteq_->NetworkStatistics(&stat));
algorithmic_delay_ms_ = stat.current_buffer_size_ms;
@ -421,8 +422,9 @@ void NetEqDecodingTestTwoInstances::SetUp() {
}
void NetEqDecodingTestTwoInstances::CreateSecondInstance() {
std::unique_ptr<NetEqFactory> neteq_factory = CreateNetEqFactoryWithCodecs();
neteq2_ = neteq_factory->CreateNetEq(config2_, &clock_);
auto decoder_factory = CreateBuiltinAudioDecoderFactory();
neteq2_ =
DefaultNetEqFactory().CreateNetEq(config2_, decoder_factory, &clock_);
ASSERT_TRUE(neteq2_);
LoadDecoders(neteq2_.get());
}

View File

@ -11,9 +11,10 @@
#include "modules/audio_coding/neteq/tools/neteq_performance_test.h"
#include "api/audio/audio_frame.h"
#include "api/audio_codecs/builtin_audio_decoder_factory.h"
#include "api/neteq/neteq.h"
#include "api/test/neteq_factory_with_codecs.h"
#include "modules/audio_coding/codecs/pcm16b/pcm16b.h"
#include "modules/audio_coding/neteq/default_neteq_factory.h"
#include "modules/audio_coding/neteq/tools/audio_loop.h"
#include "modules/audio_coding/neteq/tools/rtp_generator.h"
#include "rtc_base/checks.h"
@ -40,8 +41,9 @@ int64_t NetEqPerformanceTest::Run(int runtime_ms,
NetEq::Config config;
config.sample_rate_hz = kSampRateHz;
webrtc::Clock* clock = webrtc::Clock::GetRealTimeClock();
std::unique_ptr<NetEqFactory> neteq_factory = CreateNetEqFactoryWithCodecs();
auto neteq = neteq_factory->CreateNetEq(config, clock);
auto audio_decoder_factory = CreateBuiltinAudioDecoderFactory();
auto neteq =
DefaultNetEqFactory().CreateNetEq(config, audio_decoder_factory, clock);
// Register decoder in |neteq|.
if (!neteq->RegisterPayloadType(kPayloadType,
SdpAudioFormat("l16", kSampRateHz, 1)))

View File

@ -15,8 +15,7 @@
#include <cmath>
#include "absl/flags/flag.h"
#include "api/neteq/custom_neteq_factory.h"
#include "api/neteq/default_neteq_controller_factory.h"
#include "modules/audio_coding/neteq/default_neteq_factory.h"
#include "modules/audio_coding/neteq/tools/neteq_quality_test.h"
#include "modules/audio_coding/neteq/tools/output_audio_file.h"
#include "modules/audio_coding/neteq/tools/output_wav_file.h"
@ -95,9 +94,7 @@ std::unique_ptr<NetEq> CreateNetEq(
const NetEq::Config& config,
Clock* clock,
const rtc::scoped_refptr<AudioDecoderFactory>& decoder_factory) {
CustomNetEqFactory neteq_factory(
decoder_factory, std::make_unique<DefaultNetEqControllerFactory>());
return neteq_factory.CreateNetEq(config, clock);
return DefaultNetEqFactory().CreateNetEq(config, decoder_factory, clock);
}
} // namespace

View File

@ -13,8 +13,7 @@
#include <iomanip>
#include <iostream>
#include "api/neteq/custom_neteq_factory.h"
#include "api/neteq/default_neteq_controller_factory.h"
#include "modules/audio_coding/neteq/default_neteq_factory.h"
#include "modules/rtp_rtcp/source/byte_io.h"
#include "system_wrappers/include/clock.h"
@ -43,9 +42,7 @@ std::unique_ptr<NetEq> CreateNetEq(
const NetEq::Config& config,
Clock* clock,
const rtc::scoped_refptr<AudioDecoderFactory>& decoder_factory) {
CustomNetEqFactory neteq_factory(
decoder_factory, std::make_unique<DefaultNetEqControllerFactory>());
return neteq_factory.CreateNetEq(config, clock);
return DefaultNetEqFactory().CreateNetEq(config, decoder_factory, clock);
}
} // namespace