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