xref: /aosp_15_r20/external/webrtc/api/audio_codecs/builtin_audio_encoder_factory.cc (revision d9f758449e529ab9291ac668be2861e7a55c2422)
1 /*
2  *  Copyright (c) 2017 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/builtin_audio_encoder_factory.h"
12 
13 #include <memory>
14 #include <vector>
15 
16 #include "api/audio_codecs/L16/audio_encoder_L16.h"
17 #include "api/audio_codecs/audio_encoder_factory_template.h"
18 #include "api/audio_codecs/g711/audio_encoder_g711.h"
19 #include "api/audio_codecs/g722/audio_encoder_g722.h"
20 #if WEBRTC_USE_BUILTIN_ILBC
21 #include "api/audio_codecs/ilbc/audio_encoder_ilbc.h"  // nogncheck
22 #endif
23 #if WEBRTC_USE_BUILTIN_OPUS
24 #include "api/audio_codecs/opus/audio_encoder_multi_channel_opus.h"
25 #include "api/audio_codecs/opus/audio_encoder_opus.h"  // nogncheck
26 #endif
27 
28 namespace webrtc {
29 
30 namespace {
31 
32 // Modify an audio encoder to not advertise support for anything.
33 template <typename T>
34 struct NotAdvertised {
35   using Config = typename T::Config;
SdpToConfigwebrtc::__anonc8dadd290111::NotAdvertised36   static absl::optional<Config> SdpToConfig(
37       const SdpAudioFormat& audio_format) {
38     return T::SdpToConfig(audio_format);
39   }
AppendSupportedEncoderswebrtc::__anonc8dadd290111::NotAdvertised40   static void AppendSupportedEncoders(std::vector<AudioCodecSpec>* specs) {
41     // Don't advertise support for anything.
42   }
QueryAudioEncoderwebrtc::__anonc8dadd290111::NotAdvertised43   static AudioCodecInfo QueryAudioEncoder(const Config& config) {
44     return T::QueryAudioEncoder(config);
45   }
MakeAudioEncoderwebrtc::__anonc8dadd290111::NotAdvertised46   static std::unique_ptr<AudioEncoder> MakeAudioEncoder(
47       const Config& config,
48       int payload_type,
49       absl::optional<AudioCodecPairId> codec_pair_id = absl::nullopt,
50       const FieldTrialsView* field_trials = nullptr) {
51     return T::MakeAudioEncoder(config, payload_type, codec_pair_id,
52                                field_trials);
53   }
54 };
55 
56 }  // namespace
57 
CreateBuiltinAudioEncoderFactory()58 rtc::scoped_refptr<AudioEncoderFactory> CreateBuiltinAudioEncoderFactory() {
59   return CreateAudioEncoderFactory<
60 
61 #if WEBRTC_USE_BUILTIN_OPUS
62       AudioEncoderOpus, NotAdvertised<AudioEncoderMultiChannelOpus>,
63 #endif
64 
65       AudioEncoderG722,
66 
67 #if WEBRTC_USE_BUILTIN_ILBC
68       AudioEncoderIlbc,
69 #endif
70 
71       AudioEncoderG711, NotAdvertised<AudioEncoderL16>>();
72 }
73 
74 }  // namespace webrtc
75