diff --git a/api/neteq/DEPS b/api/neteq/DEPS index d9e023bc0d..14dd963f65 100644 --- a/api/neteq/DEPS +++ b/api/neteq/DEPS @@ -5,4 +5,7 @@ specific_include_rules = { "custom_neteq_factory\.h": [ "+system_wrappers/include/clock.h", ], + "default_neteq_factory\.h": [ + "+system_wrappers/include/clock.h", + ], } diff --git a/api/neteq/custom_neteq_factory.cc b/api/neteq/custom_neteq_factory.cc index c52bd68d8b..eaa8c8ac17 100644 --- a/api/neteq/custom_neteq_factory.cc +++ b/api/neteq/custom_neteq_factory.cc @@ -16,6 +16,10 @@ namespace webrtc { +CustomNetEqFactory::CustomNetEqFactory( + std::unique_ptr controller_factory) + : controller_factory_(std::move(controller_factory)) {} + CustomNetEqFactory::CustomNetEqFactory( rtc::scoped_refptr decoder_factory, std::unique_ptr controller_factory) @@ -31,4 +35,13 @@ std::unique_ptr CustomNetEqFactory::CreateNetEq( *controller_factory_)); } +std::unique_ptr CustomNetEqFactory::CreateNetEq( + const NetEq::Config& config, + const rtc::scoped_refptr& decoder_factory, + Clock* clock) const { + return std::make_unique( + config, NetEqImpl::Dependencies(config, clock, decoder_factory, + *controller_factory_)); +} + } // namespace webrtc diff --git a/api/neteq/custom_neteq_factory.h b/api/neteq/custom_neteq_factory.h index f0c03b7cef..7a0ee21257 100644 --- a/api/neteq/custom_neteq_factory.h +++ b/api/neteq/custom_neteq_factory.h @@ -22,9 +22,13 @@ namespace webrtc { // This factory can be used to generate NetEq instances that make use of a -// custom AudioDecoderFactory and/or NetEqControllerFactory. +// custom AudioDecoderFactory and/or NetEqControllerFactory. Using a custom +// AudioDecoderFactory is deprecated and the functionality will be removed soon. class CustomNetEqFactory : public NetEqFactory { public: + explicit CustomNetEqFactory( + std::unique_ptr controller_factory); + // This constructor is deprecated and will be removed soon. CustomNetEqFactory( rtc::scoped_refptr decoder_factory, std::unique_ptr controller_factory); @@ -35,6 +39,11 @@ class CustomNetEqFactory : public NetEqFactory { std::unique_ptr CreateNetEq(const NetEq::Config& config, Clock* clock) const override; + std::unique_ptr CreateNetEq( + const NetEq::Config& config, + const rtc::scoped_refptr& decoder_factory, + Clock* clock) const override; + private: rtc::scoped_refptr decoder_factory_; std::unique_ptr controller_factory_; diff --git a/api/neteq/neteq_factory.h b/api/neteq/neteq_factory.h index 95ddd4bfe0..c2d40ef934 100644 --- a/api/neteq/neteq_factory.h +++ b/api/neteq/neteq_factory.h @@ -13,6 +13,7 @@ #include +#include "api/audio_codecs/audio_decoder_factory.h" #include "api/neteq/neteq.h" #include "system_wrappers/include/clock.h" @@ -26,6 +27,11 @@ class NetEqFactory { // Creates a new NetEq object, with parameters set in |config|. The |config| // object will only have to be valid for the duration of the call to this // method. + virtual std::unique_ptr CreateNetEq( + const NetEq::Config& config, + const rtc::scoped_refptr& decoder_factory, + Clock* clock) const = 0; + // This method is deprecated and will be removed. virtual std::unique_ptr CreateNetEq(const NetEq::Config& config, Clock* clock) const = 0; }; diff --git a/api/test/neteq_factory_with_codecs.cc b/api/test/neteq_factory_with_codecs.cc index 6a5f678443..3bead93a81 100644 --- a/api/test/neteq_factory_with_codecs.cc +++ b/api/test/neteq_factory_with_codecs.cc @@ -30,6 +30,14 @@ class NetEqFactoryWithCodecs final : public NetEqFactory { config, NetEqImpl::Dependencies(config, clock, decoder_factory_, *controller_factory_)); } + std::unique_ptr CreateNetEq( + const NetEq::Config& config, + const rtc::scoped_refptr& decoder_factory, + Clock* clock) const override { + return std::make_unique( + config, NetEqImpl::Dependencies(config, clock, decoder_factory, + *controller_factory_)); + } private: const rtc::scoped_refptr decoder_factory_ = diff --git a/modules/audio_coding/BUILD.gn b/modules/audio_coding/BUILD.gn index 5f20c5c1d3..deb685f8a6 100644 --- a/modules/audio_coding/BUILD.gn +++ b/modules/audio_coding/BUILD.gn @@ -43,6 +43,7 @@ rtc_library("audio_coding") { deps = [ ":audio_coding_module_typedefs", + ":default_neteq_factory", ":neteq", "..:module_api", "..:module_api_public", @@ -50,8 +51,6 @@ rtc_library("audio_coding") { "../../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_library("neteq") { ] } +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 9783fc8871..9cecb98cec 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 @@ std::unique_ptr CreateNetEq( const NetEq::Config& config, Clock* clock, const rtc::scoped_refptr& 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()); - 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 0000000000..ca19b08480 --- /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 + +#include "modules/audio_coding/neteq/neteq_impl.h" + +namespace webrtc { + +DefaultNetEqFactory::DefaultNetEqFactory() = default; +DefaultNetEqFactory::~DefaultNetEqFactory() = default; + +std::unique_ptr DefaultNetEqFactory::CreateNetEq( + const NetEq::Config& config, + const rtc::scoped_refptr& decoder_factory, + Clock* clock) const { + return std::make_unique( + config, NetEqImpl::Dependencies(config, clock, decoder_factory, + controller_factory_)); +} + +std::unique_ptr 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 0000000000..4c5ee9b73e --- /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 + +#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 CreateNetEq( + const NetEq::Config& config, + const rtc::scoped_refptr& decoder_factory, + Clock* clock) const override; + std::unique_ptr 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_ diff --git a/sdk/android/api/org/webrtc/PeerConnectionFactory.java b/sdk/android/api/org/webrtc/PeerConnectionFactory.java index a2acfdd95e..683ac88364 100644 --- a/sdk/android/api/org/webrtc/PeerConnectionFactory.java +++ b/sdk/android/api/org/webrtc/PeerConnectionFactory.java @@ -167,7 +167,6 @@ public class PeerConnectionFactory { @Nullable private AudioDeviceModule audioDeviceModule; private AudioEncoderFactoryFactory audioEncoderFactoryFactory = new BuiltinAudioEncoderFactoryFactory(); - @Nullable private AudioDecoderFactoryFactory audioDecoderFactoryFactory = new BuiltinAudioDecoderFactoryFactory(); @Nullable private VideoEncoderFactory videoEncoderFactory; @@ -201,7 +200,6 @@ public class PeerConnectionFactory { return this; } - @Deprecated public Builder setAudioDecoderFactoryFactory( AudioDecoderFactoryFactory audioDecoderFactoryFactory) { if (audioDecoderFactoryFactory == null) { @@ -263,7 +261,6 @@ public class PeerConnectionFactory { * NetEqFactoryFactory. */ public Builder setNetEqFactoryFactory(NetEqFactoryFactory neteqFactoryFactory) { - this.audioDecoderFactoryFactory = null; this.neteqFactoryFactory = neteqFactoryFactory; return this; } @@ -274,18 +271,11 @@ public class PeerConnectionFactory { audioDeviceModule = JavaAudioDeviceModule.builder(ContextUtils.getApplicationContext()) .createAudioDeviceModule(); } - if (neteqFactoryFactory == null && audioDecoderFactoryFactory == null) { - throw new IllegalStateException( - "Setting both audioDecoderFactoryFactory and neteqFactoryFactory " - + "to null is not allowed."); - } return nativeCreatePeerConnectionFactory(ContextUtils.getApplicationContext(), options, audioDeviceModule.getNativeAudioDeviceModulePointer(), audioEncoderFactoryFactory.createNativeAudioEncoderFactory(), - audioDecoderFactoryFactory == null - ? 0 - : audioDecoderFactoryFactory.createNativeAudioDecoderFactory(), - videoEncoderFactory, videoDecoderFactory, + audioDecoderFactoryFactory.createNativeAudioDecoderFactory(), videoEncoderFactory, + videoDecoderFactory, audioProcessingFactory == null ? 0 : audioProcessingFactory.createNative(), fecControllerFactoryFactory == null ? 0 : fecControllerFactoryFactory.createNative(), networkControllerFactoryFactory == null