audio_encoder_factory.h 2.5 KB

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