Niels Möller | 0a8f435 | 2018-05-18 11:37:23 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2013 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_CONFIG_H_ |
| 12 | #define API_VIDEO_CODECS_VIDEO_ENCODER_CONFIG_H_ |
| 13 | |
Yves Gerey | 988cc08 | 2018-10-23 12:03:01 +0200 | [diff] [blame] | 14 | #include <stddef.h> |
Jonas Olsson | a4d8737 | 2019-07-05 19:08:33 +0200 | [diff] [blame] | 15 | |
Niels Möller | 0a8f435 | 2018-05-18 11:37:23 +0200 | [diff] [blame] | 16 | #include <string> |
| 17 | #include <vector> |
| 18 | |
Danil Chapovalov | 0bc58cf | 2018-06-21 13:32:56 +0200 | [diff] [blame] | 19 | #include "absl/types/optional.h" |
Mirko Bonadei | d970807 | 2019-01-25 20:26:48 +0100 | [diff] [blame] | 20 | #include "api/scoped_refptr.h" |
Niels Möller | 79d566b | 2022-04-29 11:03:13 +0200 | [diff] [blame] | 21 | #include "api/video_codecs/scalability_mode.h" |
Niels Möller | 0a8f435 | 2018-05-18 11:37:23 +0200 | [diff] [blame] | 22 | #include "api/video_codecs/sdp_video_format.h" |
Danil Chapovalov | 0bc58cf | 2018-06-21 13:32:56 +0200 | [diff] [blame] | 23 | #include "api/video_codecs/video_codec.h" |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 24 | #include "rtc_base/ref_count.h" |
Niels Möller | 0a8f435 | 2018-05-18 11:37:23 +0200 | [diff] [blame] | 25 | |
| 26 | namespace webrtc { |
| 27 | |
Artem Titov | 0e61fdd | 2021-07-25 21:50:14 +0200 | [diff] [blame] | 28 | // The `VideoStream` struct describes a simulcast layer, or "stream". |
Niels Möller | 0a8f435 | 2018-05-18 11:37:23 +0200 | [diff] [blame] | 29 | struct VideoStream { |
| 30 | VideoStream(); |
| 31 | ~VideoStream(); |
| 32 | VideoStream(const VideoStream& other); |
| 33 | std::string ToString() const; |
| 34 | |
Rasmus Brandt | 43bfe0b | 2020-01-21 13:54:11 +0100 | [diff] [blame] | 35 | // Width in pixels. |
Danil Chapovalov | 350531e | 2018-06-08 11:04:04 +0000 | [diff] [blame] | 36 | size_t width; |
Rasmus Brandt | 43bfe0b | 2020-01-21 13:54:11 +0100 | [diff] [blame] | 37 | |
| 38 | // Height in pixels. |
Danil Chapovalov | 350531e | 2018-06-08 11:04:04 +0000 | [diff] [blame] | 39 | size_t height; |
Rasmus Brandt | 43bfe0b | 2020-01-21 13:54:11 +0100 | [diff] [blame] | 40 | |
| 41 | // Frame rate in fps. |
Niels Möller | 0a8f435 | 2018-05-18 11:37:23 +0200 | [diff] [blame] | 42 | int max_framerate; |
| 43 | |
Rasmus Brandt | 43bfe0b | 2020-01-21 13:54:11 +0100 | [diff] [blame] | 44 | // Bitrate, in bps, for the stream. |
Niels Möller | 0a8f435 | 2018-05-18 11:37:23 +0200 | [diff] [blame] | 45 | int min_bitrate_bps; |
| 46 | int target_bitrate_bps; |
| 47 | int max_bitrate_bps; |
Rasmus Brandt | 43bfe0b | 2020-01-21 13:54:11 +0100 | [diff] [blame] | 48 | |
Florent Castelli | c1a0bcb | 2019-01-29 14:26:48 +0100 | [diff] [blame] | 49 | // Scaling factor applied to the stream size. |
Artem Titov | 0e61fdd | 2021-07-25 21:50:14 +0200 | [diff] [blame] | 50 | // `width` and `height` values are already scaled down. |
Florent Castelli | c1a0bcb | 2019-01-29 14:26:48 +0100 | [diff] [blame] | 51 | double scale_resolution_down_by; |
Rasmus Brandt | 43bfe0b | 2020-01-21 13:54:11 +0100 | [diff] [blame] | 52 | |
| 53 | // Maximum Quantization Parameter to use when encoding the stream. |
Niels Möller | 0a8f435 | 2018-05-18 11:37:23 +0200 | [diff] [blame] | 54 | int max_qp; |
| 55 | |
Rasmus Brandt | 43bfe0b | 2020-01-21 13:54:11 +0100 | [diff] [blame] | 56 | // Determines the number of temporal layers that the stream should be |
| 57 | // encoded with. This value should be greater than zero. |
| 58 | // TODO(brandtr): This class is used both for configuring the encoder |
| 59 | // (meaning that this field _must_ be set), and for signaling the app-level |
| 60 | // encoder settings (meaning that the field _may_ be set). We should separate |
| 61 | // this and remove this optional instead. |
Danil Chapovalov | 0bc58cf | 2018-06-21 13:32:56 +0200 | [diff] [blame] | 62 | absl::optional<size_t> num_temporal_layers; |
Niels Möller | 0a8f435 | 2018-05-18 11:37:23 +0200 | [diff] [blame] | 63 | |
Rasmus Brandt | 43bfe0b | 2020-01-21 13:54:11 +0100 | [diff] [blame] | 64 | // The priority of this stream, to be used when allocating resources |
| 65 | // between multiple streams. |
Danil Chapovalov | 0bc58cf | 2018-06-21 13:32:56 +0200 | [diff] [blame] | 66 | absl::optional<double> bitrate_priority; |
Niels Möller | 0a8f435 | 2018-05-18 11:37:23 +0200 | [diff] [blame] | 67 | |
Niels Möller | 79d566b | 2022-04-29 11:03:13 +0200 | [diff] [blame] | 68 | absl::optional<ScalabilityMode> scalability_mode; |
philipel | 87e9909 | 2020-11-18 11:52:04 +0100 | [diff] [blame] | 69 | |
Rasmus Brandt | 43bfe0b | 2020-01-21 13:54:11 +0100 | [diff] [blame] | 70 | // If this stream is enabled by the user, or not. |
Niels Möller | 0a8f435 | 2018-05-18 11:37:23 +0200 | [diff] [blame] | 71 | bool active; |
| 72 | }; |
| 73 | |
| 74 | class VideoEncoderConfig { |
| 75 | public: |
| 76 | // These are reference counted to permit copying VideoEncoderConfig and be |
| 77 | // kept alive until all encoder_specific_settings go out of scope. |
| 78 | // TODO(kthelgason): Consider removing the need for copying VideoEncoderConfig |
Danil Chapovalov | 0bc58cf | 2018-06-21 13:32:56 +0200 | [diff] [blame] | 79 | // and use absl::optional for encoder_specific_settings instead. |
Niels Möller | 0a8f435 | 2018-05-18 11:37:23 +0200 | [diff] [blame] | 80 | class EncoderSpecificSettings : public rtc::RefCountInterface { |
| 81 | public: |
| 82 | // TODO(pbos): Remove FillEncoderSpecificSettings as soon as VideoCodec is |
| 83 | // not in use and encoder implementations ask for codec-specific structs |
| 84 | // directly. |
| 85 | void FillEncoderSpecificSettings(VideoCodec* codec_struct) const; |
| 86 | |
| 87 | virtual void FillVideoCodecVp8(VideoCodecVP8* vp8_settings) const; |
| 88 | virtual void FillVideoCodecVp9(VideoCodecVP9* vp9_settings) const; |
Niels Möller | 0a8f435 | 2018-05-18 11:37:23 +0200 | [diff] [blame] | 89 | |
| 90 | private: |
| 91 | ~EncoderSpecificSettings() override {} |
| 92 | friend class VideoEncoderConfig; |
| 93 | }; |
| 94 | |
Niels Möller | 0a8f435 | 2018-05-18 11:37:23 +0200 | [diff] [blame] | 95 | class Vp8EncoderSpecificSettings : public EncoderSpecificSettings { |
| 96 | public: |
| 97 | explicit Vp8EncoderSpecificSettings(const VideoCodecVP8& specifics); |
| 98 | void FillVideoCodecVp8(VideoCodecVP8* vp8_settings) const override; |
| 99 | |
| 100 | private: |
| 101 | VideoCodecVP8 specifics_; |
| 102 | }; |
| 103 | |
| 104 | class Vp9EncoderSpecificSettings : public EncoderSpecificSettings { |
| 105 | public: |
| 106 | explicit Vp9EncoderSpecificSettings(const VideoCodecVP9& specifics); |
| 107 | void FillVideoCodecVp9(VideoCodecVP9* vp9_settings) const override; |
| 108 | |
| 109 | private: |
| 110 | VideoCodecVP9 specifics_; |
| 111 | }; |
| 112 | |
| 113 | enum class ContentType { |
| 114 | kRealtimeVideo, |
| 115 | kScreen, |
| 116 | }; |
| 117 | |
| 118 | class VideoStreamFactoryInterface : public rtc::RefCountInterface { |
| 119 | public: |
| 120 | // An implementation should return a std::vector<VideoStream> with the |
| 121 | // wanted VideoStream settings for the given video resolution. |
| 122 | // The size of the vector may not be larger than |
Artem Titov | cfea218 | 2021-08-10 01:22:31 +0200 | [diff] [blame] | 123 | // `encoder_config.number_of_streams`. |
Niels Möller | 0a8f435 | 2018-05-18 11:37:23 +0200 | [diff] [blame] | 124 | virtual std::vector<VideoStream> CreateEncoderStreams( |
| 125 | int width, |
| 126 | int height, |
| 127 | const VideoEncoderConfig& encoder_config) = 0; |
| 128 | |
| 129 | protected: |
| 130 | ~VideoStreamFactoryInterface() override {} |
| 131 | }; |
| 132 | |
| 133 | VideoEncoderConfig& operator=(VideoEncoderConfig&&) = default; |
| 134 | VideoEncoderConfig& operator=(const VideoEncoderConfig&) = delete; |
| 135 | |
| 136 | // Mostly used by tests. Avoid creating copies if you can. |
| 137 | VideoEncoderConfig Copy() const { return VideoEncoderConfig(*this); } |
| 138 | |
| 139 | VideoEncoderConfig(); |
| 140 | VideoEncoderConfig(VideoEncoderConfig&&); |
| 141 | ~VideoEncoderConfig(); |
| 142 | std::string ToString() const; |
| 143 | |
Niels Möller | 6939f63 | 2022-07-05 08:55:19 +0200 | [diff] [blame] | 144 | // TODO(bugs.webrtc.org/6883): Consolidate on one of these. |
Niels Möller | 0a8f435 | 2018-05-18 11:37:23 +0200 | [diff] [blame] | 145 | VideoCodecType codec_type; |
| 146 | SdpVideoFormat video_format; |
| 147 | |
| 148 | rtc::scoped_refptr<VideoStreamFactoryInterface> video_stream_factory; |
| 149 | std::vector<SpatialLayer> spatial_layers; |
| 150 | ContentType content_type; |
Niels Möller | 807328f | 2022-05-12 16:16:39 +0200 | [diff] [blame] | 151 | bool frame_drop_enabled; |
Niels Möller | 0a8f435 | 2018-05-18 11:37:23 +0200 | [diff] [blame] | 152 | rtc::scoped_refptr<const EncoderSpecificSettings> encoder_specific_settings; |
| 153 | |
| 154 | // Padding will be used up to this bitrate regardless of the bitrate produced |
| 155 | // by the encoder. Padding above what's actually produced by the encoder helps |
| 156 | // maintaining a higher bitrate estimate. Padding will however not be sent |
| 157 | // unless the estimated bandwidth indicates that the link can handle it. |
| 158 | int min_transmit_bitrate_bps; |
| 159 | int max_bitrate_bps; |
| 160 | // The bitrate priority used for all VideoStreams. |
| 161 | double bitrate_priority; |
| 162 | |
| 163 | // The simulcast layer's configurations set by the application for this video |
| 164 | // sender. These are modified by the video_stream_factory before being passed |
| 165 | // down to lower layers for the video encoding. |
Artem Titov | 0e61fdd | 2021-07-25 21:50:14 +0200 | [diff] [blame] | 166 | // `simulcast_layers` is also used for configuring non-simulcast (when there |
Åsa Persson | bdee46d | 2018-06-25 11:28:06 +0200 | [diff] [blame] | 167 | // is a single VideoStream). |
Niels Möller | 0a8f435 | 2018-05-18 11:37:23 +0200 | [diff] [blame] | 168 | std::vector<VideoStream> simulcast_layers; |
| 169 | |
| 170 | // Max number of encoded VideoStreams to produce. |
| 171 | size_t number_of_streams; |
| 172 | |
Florent Castelli | d351101 | 2020-08-04 11:40:23 +0200 | [diff] [blame] | 173 | // Legacy Google conference mode flag for simulcast screenshare |
| 174 | bool legacy_conference_mode; |
| 175 | |
Sergey Silkin | d19e3b9 | 2021-03-16 10:05:30 +0000 | [diff] [blame] | 176 | // Indicates whether quality scaling can be used or not. |
| 177 | bool is_quality_scaling_allowed; |
| 178 | |
Niels Möller | 0a8f435 | 2018-05-18 11:37:23 +0200 | [diff] [blame] | 179 | private: |
| 180 | // Access to the copy constructor is private to force use of the Copy() |
| 181 | // method for those exceptional cases where we do use it. |
| 182 | VideoEncoderConfig(const VideoEncoderConfig&); |
| 183 | }; |
| 184 | |
| 185 | } // namespace webrtc |
| 186 | |
| 187 | #endif // API_VIDEO_CODECS_VIDEO_ENCODER_CONFIG_H_ |