opus_audio_decoder_factory.cc (1816B)
1 /* 2 * Copyright (c) 2019 The WebRTC project authors. All Rights Reserved. 3 * 4 * Use of this source code is governed by a BSD-style license 5 * that can be found in the LICENSE file in the root of the source 6 * tree. An additional intellectual property rights grant can be found 7 * in the file PATENTS. All contributing project authors may 8 * be found in the AUTHORS file in the root of the source tree. 9 */ 10 11 #include "api/audio_codecs/opus_audio_decoder_factory.h" 12 13 #include <memory> 14 #include <optional> 15 #include <vector> 16 17 #include "api/audio_codecs/audio_codec_pair_id.h" 18 #include "api/audio_codecs/audio_decoder.h" 19 #include "api/audio_codecs/audio_decoder_factory.h" 20 #include "api/audio_codecs/audio_decoder_factory_template.h" 21 #include "api/audio_codecs/audio_format.h" 22 #include "api/audio_codecs/opus/audio_decoder_multi_channel_opus.h" 23 #include "api/audio_codecs/opus/audio_decoder_opus.h" 24 #include "api/scoped_refptr.h" 25 26 namespace webrtc { 27 28 namespace { 29 30 // Modify an audio decoder to not advertise support for anything. 31 template <typename T> 32 struct NotAdvertised { 33 using Config = typename T::Config; 34 static std::optional<Config> SdpToConfig(const SdpAudioFormat& audio_format) { 35 return T::SdpToConfig(audio_format); 36 } 37 static void AppendSupportedDecoders( 38 std::vector<AudioCodecSpec>* /* specs */) { 39 // Don't advertise support for anything. 40 } 41 static std::unique_ptr<AudioDecoder> MakeAudioDecoder( 42 const Config& config, 43 std::optional<AudioCodecPairId> codec_pair_id = std::nullopt) { 44 return T::MakeAudioDecoder(config, codec_pair_id); 45 } 46 }; 47 48 } // namespace 49 50 scoped_refptr<AudioDecoderFactory> CreateOpusAudioDecoderFactory() { 51 return CreateAudioDecoderFactory< 52 AudioDecoderOpus, NotAdvertised<AudioDecoderMultiChannelOpus>>(); 53 } 54 55 } // namespace webrtc