video_encoder_factory.h 3.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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_VIDEO_CODECS_VIDEO_ENCODER_FACTORY_H_
  11. #define API_VIDEO_CODECS_VIDEO_ENCODER_FACTORY_H_
  12. #include <memory>
  13. #include <vector>
  14. #include "absl/types/optional.h"
  15. #include "api/units/data_rate.h"
  16. #include "api/video_codecs/sdp_video_format.h"
  17. namespace webrtc {
  18. class VideoEncoder;
  19. // A factory that creates VideoEncoders.
  20. // NOTE: This class is still under development and may change without notice.
  21. class VideoEncoderFactory {
  22. public:
  23. // TODO(magjed): Try to get rid of this struct.
  24. struct CodecInfo {
  25. // |has_internal_source| is true if encoders created by this factory of the
  26. // given codec will use internal camera sources, meaning that they don't
  27. // require/expect frames to be delivered via webrtc::VideoEncoder::Encode.
  28. // This flag is used as the internal_source parameter to
  29. // webrtc::ViEExternalCodec::RegisterExternalSendCodec.
  30. bool has_internal_source = false;
  31. };
  32. // An injectable class that is continuously updated with encoding conditions
  33. // and selects the best encoder given those conditions.
  34. class EncoderSelectorInterface {
  35. public:
  36. virtual ~EncoderSelectorInterface() {}
  37. // Informs the encoder selector about which encoder that is currently being
  38. // used.
  39. virtual void OnCurrentEncoder(const SdpVideoFormat& format) = 0;
  40. // Called every time the available bitrate is updated. Should return a
  41. // non-empty if an encoder switch should be performed.
  42. virtual absl::optional<SdpVideoFormat> OnAvailableBitrate(
  43. const DataRate& rate) = 0;
  44. // Called if the currently used encoder reports itself as broken. Should
  45. // return a non-empty if an encoder switch should be performed.
  46. virtual absl::optional<SdpVideoFormat> OnEncoderBroken() = 0;
  47. };
  48. // Returns a list of supported video formats in order of preference, to use
  49. // for signaling etc.
  50. virtual std::vector<SdpVideoFormat> GetSupportedFormats() const = 0;
  51. // Returns a list of supported video formats in order of preference, that can
  52. // also be tagged with additional information to allow the VideoEncoderFactory
  53. // to separate between different implementations when CreateVideoEncoder is
  54. // called.
  55. virtual std::vector<SdpVideoFormat> GetImplementations() const {
  56. return GetSupportedFormats();
  57. }
  58. // Returns information about how this format will be encoded. The specified
  59. // format must be one of the supported formats by this factory.
  60. // TODO(magjed): Try to get rid of this method. Since is_hardware_accelerated
  61. // is unused, only factories producing internal source encoders (in itself a
  62. // deprecated feature) needs to override this method.
  63. virtual CodecInfo QueryVideoEncoder(const SdpVideoFormat& format) const {
  64. return CodecInfo();
  65. }
  66. // Creates a VideoEncoder for the specified format.
  67. virtual std::unique_ptr<VideoEncoder> CreateVideoEncoder(
  68. const SdpVideoFormat& format) = 0;
  69. virtual std::unique_ptr<EncoderSelectorInterface> GetEncoderSelector() const {
  70. return nullptr;
  71. }
  72. virtual ~VideoEncoderFactory() {}
  73. };
  74. } // namespace webrtc
  75. #endif // API_VIDEO_CODECS_VIDEO_ENCODER_FACTORY_H_