Magnus Jedvert | d4b0c05 | 2017-09-14 10:24:54 +0200 | [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_VIDEO_CODECS_VIDEO_ENCODER_FACTORY_H_ |
| 12 | #define API_VIDEO_CODECS_VIDEO_ENCODER_FACTORY_H_ |
Magnus Jedvert | d4b0c05 | 2017-09-14 10:24:54 +0200 | [diff] [blame] | 13 | |
| 14 | #include <memory> |
| 15 | #include <vector> |
| 16 | |
philipel | 9b05803 | 2020-02-10 11:30:00 +0100 | [diff] [blame] | 17 | #include "absl/types/optional.h" |
| 18 | #include "api/units/data_rate.h" |
philipel | 0bb0881 | 2019-07-11 13:23:16 +0200 | [diff] [blame] | 19 | #include "api/video_codecs/sdp_video_format.h" |
| 20 | |
Magnus Jedvert | d4b0c05 | 2017-09-14 10:24:54 +0200 | [diff] [blame] | 21 | namespace webrtc { |
| 22 | |
| 23 | class VideoEncoder; |
Magnus Jedvert | d4b0c05 | 2017-09-14 10:24:54 +0200 | [diff] [blame] | 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 { |
Magnus Jedvert | d4b0c05 | 2017-09-14 10:24:54 +0200 | [diff] [blame] | 31 | // |has_internal_source| is true if encoders created by this factory of the |
| 32 | // given codec will use internal camera sources, meaning that they don't |
| 33 | // require/expect frames to be delivered via webrtc::VideoEncoder::Encode. |
| 34 | // This flag is used as the internal_source parameter to |
| 35 | // webrtc::ViEExternalCodec::RegisterExternalSendCodec. |
Niels Möller | 3592839 | 2020-07-16 12:08:44 +0200 | [diff] [blame] | 36 | bool has_internal_source = false; |
Magnus Jedvert | d4b0c05 | 2017-09-14 10:24:54 +0200 | [diff] [blame] | 37 | }; |
| 38 | |
philipel | 9b05803 | 2020-02-10 11:30:00 +0100 | [diff] [blame] | 39 | // An injectable class that is continuously updated with encoding conditions |
| 40 | // and selects the best encoder given those conditions. |
| 41 | class EncoderSelectorInterface { |
| 42 | public: |
| 43 | virtual ~EncoderSelectorInterface() {} |
| 44 | |
| 45 | // Informs the encoder selector about which encoder that is currently being |
| 46 | // used. |
| 47 | virtual void OnCurrentEncoder(const SdpVideoFormat& format) = 0; |
| 48 | |
Mirta Dvornicic | 4f34d78 | 2020-02-26 13:01:19 +0100 | [diff] [blame] | 49 | // Called every time the available bitrate is updated. Should return a |
philipel | 9b05803 | 2020-02-10 11:30:00 +0100 | [diff] [blame] | 50 | // non-empty if an encoder switch should be performed. |
Mirta Dvornicic | 4f34d78 | 2020-02-26 13:01:19 +0100 | [diff] [blame] | 51 | virtual absl::optional<SdpVideoFormat> OnAvailableBitrate( |
philipel | 9b05803 | 2020-02-10 11:30:00 +0100 | [diff] [blame] | 52 | const DataRate& rate) = 0; |
| 53 | |
| 54 | // Called if the currently used encoder reports itself as broken. Should |
| 55 | // return a non-empty if an encoder switch should be performed. |
| 56 | virtual absl::optional<SdpVideoFormat> OnEncoderBroken() = 0; |
| 57 | }; |
| 58 | |
Magnus Jedvert | d4b0c05 | 2017-09-14 10:24:54 +0200 | [diff] [blame] | 59 | // Returns a list of supported video formats in order of preference, to use |
| 60 | // for signaling etc. |
| 61 | virtual std::vector<SdpVideoFormat> GetSupportedFormats() const = 0; |
| 62 | |
philipel | 0bb0881 | 2019-07-11 13:23:16 +0200 | [diff] [blame] | 63 | // Returns a list of supported video formats in order of preference, that can |
| 64 | // also be tagged with additional information to allow the VideoEncoderFactory |
| 65 | // to separate between different implementations when CreateVideoEncoder is |
| 66 | // called. |
| 67 | virtual std::vector<SdpVideoFormat> GetImplementations() const { |
| 68 | return GetSupportedFormats(); |
| 69 | } |
| 70 | |
Magnus Jedvert | d4b0c05 | 2017-09-14 10:24:54 +0200 | [diff] [blame] | 71 | // Returns information about how this format will be encoded. The specified |
| 72 | // format must be one of the supported formats by this factory. |
Niels Möller | 2b781bf | 2020-07-16 14:19:41 +0200 | [diff] [blame] | 73 | |
| 74 | // TODO(magjed): Try to get rid of this method. Since is_hardware_accelerated |
| 75 | // is unused, only factories producing internal source encoders (in itself a |
| 76 | // deprecated feature) needs to override this method. |
| 77 | virtual CodecInfo QueryVideoEncoder(const SdpVideoFormat& format) const { |
| 78 | return CodecInfo(); |
| 79 | } |
Magnus Jedvert | d4b0c05 | 2017-09-14 10:24:54 +0200 | [diff] [blame] | 80 | |
| 81 | // Creates a VideoEncoder for the specified format. |
| 82 | virtual std::unique_ptr<VideoEncoder> CreateVideoEncoder( |
| 83 | const SdpVideoFormat& format) = 0; |
| 84 | |
philipel | 9b05803 | 2020-02-10 11:30:00 +0100 | [diff] [blame] | 85 | virtual std::unique_ptr<EncoderSelectorInterface> GetEncoderSelector() const { |
| 86 | return nullptr; |
| 87 | } |
| 88 | |
Magnus Jedvert | d4b0c05 | 2017-09-14 10:24:54 +0200 | [diff] [blame] | 89 | virtual ~VideoEncoderFactory() {} |
| 90 | }; |
| 91 | |
| 92 | } // namespace webrtc |
| 93 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 94 | #endif // API_VIDEO_CODECS_VIDEO_ENCODER_FACTORY_H_ |