Add a CreateNetEq method that takes an AudioDecoderFactory
The NetEqFactory is currently expected to wrap the AudioDecoderFactory,
but this turns out not to be a good idea. Instead, it makes more sense
to pass the AudioDecoderFactory through the CreateNetEq method.
Bug: webrtc:11005
Change-Id: I8027ff6593f40c92072e7e88157631dcf329a984
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/160644
Commit-Queue: Ivo Creusen <ivoc@webrtc.org>
Reviewed-by: Karl Wiberg <kwiberg@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#29918}
diff --git a/modules/audio_coding/BUILD.gn b/modules/audio_coding/BUILD.gn
index 5f20c5c..deb685f 100644
--- a/modules/audio_coding/BUILD.gn
+++ b/modules/audio_coding/BUILD.gn
@@ -43,6 +43,7 @@
deps = [
":audio_coding_module_typedefs",
+ ":default_neteq_factory",
":neteq",
"..:module_api",
"..:module_api_public",
@@ -50,8 +51,6 @@
"../../api:function_view",
"../../api/audio:audio_frame_api",
"../../api/audio_codecs:audio_codecs_api",
- "../../api/neteq:custom_neteq_factory",
- "../../api/neteq:default_neteq_controller_factory",
"../../api/neteq:neteq_api",
"../../common_audio",
"../../common_audio:common_audio_c",
@@ -1028,6 +1027,22 @@
]
}
+rtc_source_set("default_neteq_factory") {
+ visibility += webrtc_default_visibility
+ sources = [
+ "neteq/default_neteq_factory.cc",
+ "neteq/default_neteq_factory.h",
+ ]
+ deps = [
+ ":neteq",
+ "../../api:scoped_refptr",
+ "../../api/audio_codecs:audio_codecs_api",
+ "../../api/neteq:default_neteq_controller_factory",
+ "../../api/neteq:neteq_api",
+ "../../system_wrappers:system_wrappers",
+ ]
+}
+
# Although providing only test support, this target must be outside of the
# rtc_include_tests conditional. The reason is that it supports fuzzer tests
# that ultimately are built and run as a part of the Chromium ecosystem, which
diff --git a/modules/audio_coding/acm2/acm_receiver.cc b/modules/audio_coding/acm2/acm_receiver.cc
index 9783fc8..9cecb98 100644
--- a/modules/audio_coding/acm2/acm_receiver.cc
+++ b/modules/audio_coding/acm2/acm_receiver.cc
@@ -19,11 +19,10 @@
#include "absl/strings/match.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/neteq/neteq.h"
#include "modules/audio_coding/acm2/acm_resampler.h"
#include "modules/audio_coding/acm2/call_statistics.h"
+#include "modules/audio_coding/neteq/default_neteq_factory.h"
#include "rtc_base/checks.h"
#include "rtc_base/logging.h"
#include "rtc_base/numerics/safe_conversions.h"
@@ -41,16 +40,10 @@
const NetEq::Config& config,
Clock* clock,
const rtc::scoped_refptr<AudioDecoderFactory>& decoder_factory) {
- RTC_CHECK((neteq_factory == nullptr) || (decoder_factory.get() == nullptr))
- << "Either a NetEqFactory or a AudioDecoderFactory should be injected, "
- "supplying both is not supported. Please wrap the AudioDecoderFactory "
- "inside the NetEqFactory when using both.";
if (neteq_factory) {
- return neteq_factory->CreateNetEq(config, clock);
+ return neteq_factory->CreateNetEq(config, decoder_factory, clock);
}
- CustomNetEqFactory custom_factory(
- decoder_factory, std::make_unique<DefaultNetEqControllerFactory>());
- return custom_factory.CreateNetEq(config, clock);
+ return DefaultNetEqFactory().CreateNetEq(config, decoder_factory, clock);
}
} // namespace
diff --git a/modules/audio_coding/neteq/default_neteq_factory.cc b/modules/audio_coding/neteq/default_neteq_factory.cc
new file mode 100644
index 0000000..ca19b08
--- /dev/null
+++ b/modules/audio_coding/neteq/default_neteq_factory.cc
@@ -0,0 +1,39 @@
+/*
+ * 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 "modules/audio_coding/neteq/default_neteq_factory.h"
+
+#include <utility>
+
+#include "modules/audio_coding/neteq/neteq_impl.h"
+
+namespace webrtc {
+
+DefaultNetEqFactory::DefaultNetEqFactory() = default;
+DefaultNetEqFactory::~DefaultNetEqFactory() = default;
+
+std::unique_ptr<NetEq> DefaultNetEqFactory::CreateNetEq(
+ const NetEq::Config& config,
+ const rtc::scoped_refptr<AudioDecoderFactory>& decoder_factory,
+ Clock* clock) const {
+ return std::make_unique<NetEqImpl>(
+ config, NetEqImpl::Dependencies(config, clock, decoder_factory,
+ 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
diff --git a/modules/audio_coding/neteq/default_neteq_factory.h b/modules/audio_coding/neteq/default_neteq_factory.h
new file mode 100644
index 0000000..4c5ee9b
--- /dev/null
+++ b/modules/audio_coding/neteq/default_neteq_factory.h
@@ -0,0 +1,43 @@
+/*
+ * 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 MODULES_AUDIO_CODING_NETEQ_DEFAULT_NETEQ_FACTORY_H_
+#define MODULES_AUDIO_CODING_NETEQ_DEFAULT_NETEQ_FACTORY_H_
+
+#include <memory>
+
+#include "api/audio_codecs/audio_decoder_factory.h"
+#include "api/neteq/default_neteq_controller_factory.h"
+#include "api/neteq/neteq_factory.h"
+#include "api/scoped_refptr.h"
+#include "system_wrappers/include/clock.h"
+
+namespace webrtc {
+
+class DefaultNetEqFactory : public NetEqFactory {
+ public:
+ DefaultNetEqFactory();
+ ~DefaultNetEqFactory() override;
+ DefaultNetEqFactory(const DefaultNetEqFactory&) = delete;
+ DefaultNetEqFactory& operator=(const DefaultNetEqFactory&) = delete;
+
+ std::unique_ptr<NetEq> CreateNetEq(
+ 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_;
+};
+
+} // namespace webrtc
+#endif // MODULES_AUDIO_CODING_NETEQ_DEFAULT_NETEQ_FACTORY_H_