From ce807810be2b1c597c2d403fd74b05cefd752872 Mon Sep 17 00:00:00 2001 From: Danil Chapovalov Date: Wed, 14 Aug 2024 12:59:26 +0200 Subject: [PATCH] Change AudioDecoderFactory api to provide Environment to construct AudioDecoders MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Bug: webrtc:356878416 Change-Id: Id910bef48138b1b659938b1c1a6d23b5634967f5 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/359540 Reviewed-by: Jakob Ivarsson‎ Commit-Queue: Danil Chapovalov Cr-Commit-Position: refs/heads/main@{#42781} --- api/audio_codecs/audio_decoder_factory.h | 29 ++++++++++++++----- api/audio_codecs/audio_encoder_factory.h | 12 ++++---- .../audio_coding/neteq/decoder_database.cc | 2 +- 3 files changed, 29 insertions(+), 14 deletions(-) diff --git a/api/audio_codecs/audio_decoder_factory.h b/api/audio_codecs/audio_decoder_factory.h index 19b921a97f..a5649cc202 100644 --- a/api/audio_codecs/audio_decoder_factory.h +++ b/api/audio_codecs/audio_decoder_factory.h @@ -14,11 +14,14 @@ #include #include +#include "absl/base/nullability.h" #include "absl/types/optional.h" #include "api/audio_codecs/audio_codec_pair_id.h" #include "api/audio_codecs/audio_decoder.h" #include "api/audio_codecs/audio_format.h" +#include "api/environment/environment.h" #include "api/ref_count.h" +#include "rtc_base/checks.h" namespace webrtc { @@ -31,12 +34,12 @@ class AudioDecoderFactory : public RefCountInterface { // Create a new decoder instance. The `codec_pair_id` argument is used to link // encoders and decoders that talk to the same remote entity: if a - // AudioEncoderFactory::MakeAudioEncoder() and a - // AudioDecoderFactory::MakeAudioDecoder() call receive non-null IDs that - // compare equal, the factory implementations may assume that the encoder and - // decoder form a pair. (The intended use case for this is to set up - // communication between the AudioEncoder and AudioDecoder instances, which is - // needed for some codecs with built-in bandwidth adaptation.) + // AudioEncoderFactory::Create() and a AudioDecoderFactory::Create() call + // receive non-null IDs that compare equal, the factory implementations may + // assume that the encoder and decoder form a pair. (The intended use case for + // this is to set up communication between the AudioEncoder and AudioDecoder + // instances, which is needed for some codecs with built-in bandwidth + // adaptation.) // // Returns null if the format isn't supported. // @@ -45,7 +48,19 @@ class AudioDecoderFactory : public RefCountInterface { // work. virtual std::unique_ptr MakeAudioDecoder( const SdpAudioFormat& format, - absl::optional codec_pair_id) = 0; + absl::optional codec_pair_id) { + RTC_DCHECK_NOTREACHED(); + return nullptr; + } + + // TODO: bugs.webrtc.org/356878416 - Make pure virtual when implemented by + // derived classes instead of the MakeAudioDecoder. + virtual absl::Nullable> Create( + const Environment& env, + const SdpAudioFormat& format, + absl::optional codec_pair_id) { + return MakeAudioDecoder(format, codec_pair_id); + } }; } // namespace webrtc diff --git a/api/audio_codecs/audio_encoder_factory.h b/api/audio_codecs/audio_encoder_factory.h index 066a15ee0e..8fe09f96ae 100644 --- a/api/audio_codecs/audio_encoder_factory.h +++ b/api/audio_codecs/audio_encoder_factory.h @@ -34,12 +34,12 @@ class AudioEncoderFactory : public RefCountInterface { int payload_type = -1; // Links encoders and decoders that talk to the same remote entity: if - // a AudioEncoderFactory::Create() and a - // AudioDecoderFactory::MakeAudioDecoder() call receive non-null IDs that - // compare equal, the factory implementations may assume that the encoder - // and decoder form a pair. (The intended use case for this is to set up - // communication between the AudioEncoder and AudioDecoder instances, which - // is needed for some codecs with built-in bandwidth adaptation.) + // a AudioEncoderFactory::Create() and a AudioDecoderFactory::Create() call + // receive non-null IDs that compare equal, the factory implementations may + // assume that the encoder and decoder form a pair. (The intended use case + // for this is to set up communication between the AudioEncoder and + // AudioDecoder instances, which is needed for some codecs with built-in + // bandwidth adaptation.) // // Note: Implementations need to be robust against combinations other than // one encoder, one decoder getting the same ID; such encoders must still diff --git a/modules/audio_coding/neteq/decoder_database.cc b/modules/audio_coding/neteq/decoder_database.cc index c765ec53d1..28a985df14 100644 --- a/modules/audio_coding/neteq/decoder_database.cc +++ b/modules/audio_coding/neteq/decoder_database.cc @@ -63,7 +63,7 @@ AudioDecoder* DecoderDatabase::DecoderInfo::GetDecoder() const { // TODO(ossu): Keep a check here for now, since a number of tests create // DecoderInfos without factories. RTC_DCHECK(factory_); - decoder_ = factory_->MakeAudioDecoder(audio_format_, codec_pair_id_); + decoder_ = factory_->Create(env_, audio_format_, codec_pair_id_); } RTC_DCHECK(decoder_) << "Failed to create: " << rtc::ToString(audio_format_); return decoder_.get();