audio_encoder_factory.h (2658B)
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 #ifndef API_AUDIO_CODECS_AUDIO_ENCODER_FACTORY_H_ 12 #define API_AUDIO_CODECS_AUDIO_ENCODER_FACTORY_H_ 13 14 #include <memory> 15 #include <optional> 16 #include <vector> 17 18 #include "absl/base/nullability.h" 19 #include "api/audio_codecs/audio_codec_pair_id.h" 20 #include "api/audio_codecs/audio_encoder.h" 21 #include "api/audio_codecs/audio_format.h" 22 #include "api/environment/environment.h" 23 #include "api/ref_count.h" 24 25 namespace webrtc { 26 27 // A factory that creates AudioEncoders. 28 class AudioEncoderFactory : public RefCountInterface { 29 public: 30 struct Options { 31 // The encoder will tags its payloads with the specified payload type. 32 // TODO(ossu): Try to avoid audio encoders having to know their payload 33 // type. 34 int payload_type = -1; 35 36 // Links encoders and decoders that talk to the same remote entity: if 37 // a AudioEncoderFactory::Create() and a AudioDecoderFactory::Create() call 38 // receive non-null IDs that compare equal, the factory implementations may 39 // assume that the encoder and decoder form a pair. (The intended use case 40 // for this is to set up communication between the AudioEncoder and 41 // AudioDecoder instances, which is needed for some codecs with built-in 42 // bandwidth adaptation.) 43 // 44 // Note: Implementations need to be robust against combinations other than 45 // one encoder, one decoder getting the same ID; such encoders must still 46 // work. 47 std::optional<AudioCodecPairId> codec_pair_id; 48 }; 49 50 // Returns a prioritized list of audio codecs, to use for signaling etc. 51 virtual std::vector<AudioCodecSpec> GetSupportedEncoders() = 0; 52 53 // Returns information about how this format would be encoded, provided it's 54 // supported. More format and format variations may be supported than those 55 // returned by GetSupportedEncoders(). 56 virtual std::optional<AudioCodecInfo> QueryAudioEncoder( 57 const SdpAudioFormat& format) = 0; 58 59 // Creates an AudioEncoder for the specified format. 60 // Returns null if the format isn't supported. 61 virtual absl_nullable std::unique_ptr<AudioEncoder> Create( 62 const Environment& env, 63 const SdpAudioFormat& format, 64 Options options) = 0; 65 }; 66 67 } // namespace webrtc 68 69 #endif // API_AUDIO_CODECS_AUDIO_ENCODER_FACTORY_H_