ossu | a1a040a | 2017-04-06 10:03:21 -0700 | [diff] [blame] | 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 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 11 | #ifndef API_AUDIO_CODECS_AUDIO_ENCODER_FACTORY_H_ |
| 12 | #define API_AUDIO_CODECS_AUDIO_ENCODER_FACTORY_H_ |
ossu | a1a040a | 2017-04-06 10:03:21 -0700 | [diff] [blame] | 13 | |
| 14 | #include <memory> |
| 15 | #include <vector> |
| 16 | |
Danil Chapovalov | 0bc58cf | 2018-06-21 13:32:56 +0200 | [diff] [blame] | 17 | #include "absl/types/optional.h" |
Karl Wiberg | 9890074 | 2018-03-01 12:03:49 +0100 | [diff] [blame] | 18 | #include "api/audio_codecs/audio_codec_pair_id.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 19 | #include "api/audio_codecs/audio_encoder.h" |
| 20 | #include "api/audio_codecs/audio_format.h" |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame^] | 21 | #include "rtc_base/ref_count.h" |
ossu | a1a040a | 2017-04-06 10:03:21 -0700 | [diff] [blame] | 22 | |
| 23 | namespace webrtc { |
| 24 | |
| 25 | // A factory that creates AudioEncoders. |
ossu | a1a040a | 2017-04-06 10:03:21 -0700 | [diff] [blame] | 26 | class AudioEncoderFactory : public rtc::RefCountInterface { |
| 27 | public: |
| 28 | // Returns a prioritized list of audio codecs, to use for signaling etc. |
| 29 | virtual std::vector<AudioCodecSpec> GetSupportedEncoders() = 0; |
| 30 | |
| 31 | // Returns information about how this format would be encoded, provided it's |
| 32 | // supported. More format and format variations may be supported than those |
| 33 | // returned by GetSupportedEncoders(). |
Danil Chapovalov | 0bc58cf | 2018-06-21 13:32:56 +0200 | [diff] [blame] | 34 | virtual absl::optional<AudioCodecInfo> QueryAudioEncoder( |
ossu | a1a040a | 2017-04-06 10:03:21 -0700 | [diff] [blame] | 35 | const SdpAudioFormat& format) = 0; |
| 36 | |
Karl Wiberg | ad858d1 | 2018-12-10 11:50:55 +0100 | [diff] [blame] | 37 | // Creates an AudioEncoder for the specified format. The encoder will tags its |
| 38 | // payloads with the specified payload type. The `codec_pair_id` argument is |
| 39 | // used to link encoders and decoders that talk to the same remote entity: if |
| 40 | // a AudioEncoderFactory::MakeAudioEncoder() and a |
| 41 | // AudioDecoderFactory::MakeAudioDecoder() call receive non-null IDs that |
| 42 | // compare equal, the factory implementations may assume that the encoder and |
| 43 | // decoder form a pair. (The intended use case for this is to set up |
| 44 | // communication between the AudioEncoder and AudioDecoder instances, which is |
| 45 | // needed for some codecs with built-in bandwidth adaptation.) |
Karl Wiberg | 9890074 | 2018-03-01 12:03:49 +0100 | [diff] [blame] | 46 | // |
| 47 | // Note: Implementations need to be robust against combinations other than |
| 48 | // one encoder, one decoder getting the same ID; such encoders must still |
| 49 | // work. |
| 50 | // |
ossu | a1a040a | 2017-04-06 10:03:21 -0700 | [diff] [blame] | 51 | // TODO(ossu): Try to avoid audio encoders having to know their payload type. |
| 52 | virtual std::unique_ptr<AudioEncoder> MakeAudioEncoder( |
| 53 | int payload_type, |
Karl Wiberg | 9890074 | 2018-03-01 12:03:49 +0100 | [diff] [blame] | 54 | const SdpAudioFormat& format, |
Danil Chapovalov | 0bc58cf | 2018-06-21 13:32:56 +0200 | [diff] [blame] | 55 | absl::optional<AudioCodecPairId> codec_pair_id) = 0; |
ossu | a1a040a | 2017-04-06 10:03:21 -0700 | [diff] [blame] | 56 | }; |
| 57 | |
| 58 | } // namespace webrtc |
| 59 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 60 | #endif // API_AUDIO_CODECS_AUDIO_ENCODER_FACTORY_H_ |