Niels Möller | 802506c | 2018-05-31 08:44:51 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2018 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_CODEC_H_ |
| 12 | #define API_VIDEO_CODECS_VIDEO_CODEC_H_ |
| 13 | |
Yves Gerey | 988cc08 | 2018-10-23 10:03:01 | [diff] [blame] | 14 | #include <stddef.h> |
| 15 | #include <stdint.h> |
Jonas Olsson | a4d8737 | 2019-07-05 17:08:33 | [diff] [blame] | 16 | |
Niels Möller | a46bd4b | 2018-06-08 12:03:44 | [diff] [blame] | 17 | #include <string> |
Niels Möller | 802506c | 2018-05-31 08:44:51 | [diff] [blame] | 18 | |
Danil Chapovalov | 9f4859e | 2020-10-16 15:45:41 | [diff] [blame] | 19 | #include "absl/strings/string_view.h" |
Yves Gerey | 988cc08 | 2018-10-23 10:03:01 | [diff] [blame] | 20 | #include "api/video/video_bitrate_allocation.h" |
Niels Möller | 22b70ff | 2018-11-20 10:06:58 | [diff] [blame] | 21 | #include "api/video/video_codec_type.h" |
Niels Möller | 79d566b | 2022-04-29 09:03:13 | [diff] [blame] | 22 | #include "api/video_codecs/scalability_mode.h" |
Niels Möller | c0a9f35 | 2022-05-20 11:38:49 | [diff] [blame] | 23 | #include "api/video_codecs/simulcast_stream.h" |
Niels Möller | 5b69aa6 | 2020-08-14 13:32:14 | [diff] [blame] | 24 | #include "api/video_codecs/spatial_layer.h" |
Mirko Bonadei | 276827c | 2018-10-16 12:13:50 | [diff] [blame] | 25 | #include "rtc_base/system/rtc_export.h" |
Niels Möller | 802506c | 2018-05-31 08:44:51 | [diff] [blame] | 26 | |
Niels Möller | a46bd4b | 2018-06-08 12:03:44 | [diff] [blame] | 27 | namespace webrtc { |
| 28 | |
| 29 | // The VideoCodec class represents an old defacto-apis, which we're migrating |
Niels Möller | 802506c | 2018-05-31 08:44:51 | [diff] [blame] | 30 | // away from slowly. |
| 31 | |
Niels Möller | a46bd4b | 2018-06-08 12:03:44 | [diff] [blame] | 32 | // Video codec |
Niels Möller | e3cf3d0 | 2018-06-13 09:52:16 | [diff] [blame] | 33 | enum class VideoCodecComplexity { |
Erik Språng | e4589cb | 2022-04-06 14:44:30 | [diff] [blame] | 34 | kComplexityLow = -1, |
Niels Möller | a46bd4b | 2018-06-08 12:03:44 | [diff] [blame] | 35 | kComplexityNormal = 0, |
| 36 | kComplexityHigh = 1, |
| 37 | kComplexityHigher = 2, |
| 38 | kComplexityMax = 3 |
| 39 | }; |
| 40 | |
| 41 | // VP8 specific |
| 42 | struct VideoCodecVP8 { |
| 43 | bool operator==(const VideoCodecVP8& other) const; |
| 44 | bool operator!=(const VideoCodecVP8& other) const { |
| 45 | return !(*this == other); |
| 46 | } |
Niels Möller | 7992457 | 2022-07-05 12:22:27 | [diff] [blame] | 47 | // Temporary utility method for transition deleting numberOfTemporalLayers |
| 48 | // setting (replaced by ScalabilityMode). |
| 49 | void SetNumberOfTemporalLayers(unsigned char n) { |
| 50 | numberOfTemporalLayers = n; |
| 51 | } |
Niels Möller | a46bd4b | 2018-06-08 12:03:44 | [diff] [blame] | 52 | unsigned char numberOfTemporalLayers; |
| 53 | bool denoisingOn; |
| 54 | bool automaticResizeOn; |
Niels Möller | a46bd4b | 2018-06-08 12:03:44 | [diff] [blame] | 55 | int keyFrameInterval; |
| 56 | }; |
| 57 | |
Sergey Silkin | cf26705 | 2019-04-09 09:40:09 | [diff] [blame] | 58 | enum class InterLayerPredMode : int { |
| 59 | kOff = 0, // Inter-layer prediction is disabled. |
| 60 | kOn = 1, // Inter-layer prediction is enabled. |
| 61 | kOnKeyPic = 2 // Inter-layer prediction is enabled but limited to key frames. |
Niels Möller | a46bd4b | 2018-06-08 12:03:44 | [diff] [blame] | 62 | }; |
| 63 | |
| 64 | // VP9 specific. |
| 65 | struct VideoCodecVP9 { |
| 66 | bool operator==(const VideoCodecVP9& other) const; |
| 67 | bool operator!=(const VideoCodecVP9& other) const { |
| 68 | return !(*this == other); |
| 69 | } |
Niels Möller | 7992457 | 2022-07-05 12:22:27 | [diff] [blame] | 70 | // Temporary utility method for transition deleting numberOfTemporalLayers |
| 71 | // setting (replaced by ScalabilityMode). |
| 72 | void SetNumberOfTemporalLayers(unsigned char n) { |
| 73 | numberOfTemporalLayers = n; |
| 74 | } |
Niels Möller | a46bd4b | 2018-06-08 12:03:44 | [diff] [blame] | 75 | unsigned char numberOfTemporalLayers; |
| 76 | bool denoisingOn; |
Niels Möller | a46bd4b | 2018-06-08 12:03:44 | [diff] [blame] | 77 | int keyFrameInterval; |
| 78 | bool adaptiveQpMode; |
| 79 | bool automaticResizeOn; |
| 80 | unsigned char numberOfSpatialLayers; |
| 81 | bool flexibleMode; |
| 82 | InterLayerPredMode interLayerPred; |
| 83 | }; |
| 84 | |
| 85 | // H264 specific. |
| 86 | struct VideoCodecH264 { |
| 87 | bool operator==(const VideoCodecH264& other) const; |
| 88 | bool operator!=(const VideoCodecH264& other) const { |
| 89 | return !(*this == other); |
| 90 | } |
Niels Möller | 7992457 | 2022-07-05 12:22:27 | [diff] [blame] | 91 | // Temporary utility method for transition deleting numberOfTemporalLayers |
| 92 | // setting (replaced by ScalabilityMode). |
| 93 | void SetNumberOfTemporalLayers(unsigned char n) { |
| 94 | numberOfTemporalLayers = n; |
| 95 | } |
Niels Möller | a46bd4b | 2018-06-08 12:03:44 | [diff] [blame] | 96 | int keyFrameInterval; |
Johnny Lee | 1a1c52b | 2019-02-08 19:25:40 | [diff] [blame] | 97 | uint8_t numberOfTemporalLayers; |
Niels Möller | a46bd4b | 2018-06-08 12:03:44 | [diff] [blame] | 98 | }; |
| 99 | |
| 100 | // Translates from name of codec to codec type and vice versa. |
Mirko Bonadei | ac19414 | 2018-10-22 15:08:37 | [diff] [blame] | 101 | RTC_EXPORT const char* CodecTypeToPayloadString(VideoCodecType type); |
| 102 | RTC_EXPORT VideoCodecType PayloadStringToCodecType(const std::string& name); |
Niels Möller | a46bd4b | 2018-06-08 12:03:44 | [diff] [blame] | 103 | |
| 104 | union VideoCodecUnion { |
| 105 | VideoCodecVP8 VP8; |
| 106 | VideoCodecVP9 VP9; |
| 107 | VideoCodecH264 H264; |
| 108 | }; |
| 109 | |
Niels Möller | e3cf3d0 | 2018-06-13 09:52:16 | [diff] [blame] | 110 | enum class VideoCodecMode { kRealtimeVideo, kScreensharing }; |
Niels Möller | a46bd4b | 2018-06-08 12:03:44 | [diff] [blame] | 111 | |
| 112 | // Common video codec properties |
Mirko Bonadei | 276827c | 2018-10-16 12:13:50 | [diff] [blame] | 113 | class RTC_EXPORT VideoCodec { |
Niels Möller | a46bd4b | 2018-06-08 12:03:44 | [diff] [blame] | 114 | public: |
| 115 | VideoCodec(); |
| 116 | |
Danil Chapovalov | 9f4859e | 2020-10-16 15:45:41 | [diff] [blame] | 117 | // Scalability mode as described in |
| 118 | // https://www.w3.org/TR/webrtc-svc/#scalabilitymodes* |
Niels Möller | 79d566b | 2022-04-29 09:03:13 | [diff] [blame] | 119 | absl::optional<ScalabilityMode> GetScalabilityMode() const { |
| 120 | return scalability_mode_; |
Danil Chapovalov | 9f4859e | 2020-10-16 15:45:41 | [diff] [blame] | 121 | } |
Niels Möller | 79d566b | 2022-04-29 09:03:13 | [diff] [blame] | 122 | void SetScalabilityMode(ScalabilityMode scalability_mode) { |
| 123 | scalability_mode_ = scalability_mode; |
| 124 | } |
| 125 | void UnsetScalabilityMode() { scalability_mode_ = absl::nullopt; } |
Danil Chapovalov | 9f4859e | 2020-10-16 15:45:41 | [diff] [blame] | 126 | |
“Michael | 3147e29 | 2022-02-19 22:48:50 | [diff] [blame] | 127 | VideoCodecComplexity GetVideoEncoderComplexity() const; |
| 128 | void SetVideoEncoderComplexity(VideoCodecComplexity complexity_setting); |
| 129 | |
Niels Möller | 807328f | 2022-05-12 14:16:39 | [diff] [blame] | 130 | bool GetFrameDropEnabled() const; |
| 131 | void SetFrameDropEnabled(bool enabled); |
| 132 | |
Niels Möller | a46bd4b | 2018-06-08 12:03:44 | [diff] [blame] | 133 | // Public variables. TODO(hta): Make them private with accessors. |
| 134 | VideoCodecType codecType; |
Niels Möller | a46bd4b | 2018-06-08 12:03:44 | [diff] [blame] | 135 | |
| 136 | // TODO(nisse): Change to int, for consistency. |
| 137 | uint16_t width; |
| 138 | uint16_t height; |
| 139 | |
Jonas Olsson | a4d8737 | 2019-07-05 17:08:33 | [diff] [blame] | 140 | unsigned int startBitrate; // kilobits/sec. |
| 141 | unsigned int maxBitrate; // kilobits/sec. |
| 142 | unsigned int minBitrate; // kilobits/sec. |
Niels Möller | a46bd4b | 2018-06-08 12:03:44 | [diff] [blame] | 143 | |
| 144 | uint32_t maxFramerate; |
| 145 | |
| 146 | // This enables/disables encoding and sending when there aren't multiple |
| 147 | // simulcast streams,by allocating 0 bitrate if inactive. |
| 148 | bool active; |
| 149 | |
| 150 | unsigned int qpMax; |
Henrik Boström | 2fec644 | 2023-06-15 10:49:26 | [diff] [blame^] | 151 | // The actual number of simulcast streams. This is <= 1 in singlecast (it can |
| 152 | // be 0 in old code paths), but it is also 1 in the {active,inactive,inactive} |
| 153 | // "single RTP simulcast" use case and the legacy kSVC use case. In all other |
| 154 | // cases this is the same as the number of encodings (which may include |
| 155 | // inactive encodings). In other words: |
| 156 | // - `numberOfSimulcastStreams <= 1` in singlecast and singlecast-like setups |
| 157 | // including legacy kSVC (encodings interpreted as spatial layers) or |
| 158 | // standard kSVC (1 active encoding). |
| 159 | // - `numberOfSimulcastStreams > 1` in simulcast of 2+ active encodings. |
Niels Möller | a46bd4b | 2018-06-08 12:03:44 | [diff] [blame] | 160 | unsigned char numberOfSimulcastStreams; |
Niels Möller | c0a9f35 | 2022-05-20 11:38:49 | [diff] [blame] | 161 | SimulcastStream simulcastStream[kMaxSimulcastStreams]; |
Niels Möller | a46bd4b | 2018-06-08 12:03:44 | [diff] [blame] | 162 | SpatialLayer spatialLayers[kMaxSpatialLayers]; |
| 163 | |
| 164 | VideoCodecMode mode; |
| 165 | bool expect_encode_from_texture; |
| 166 | |
| 167 | // Timing frames configuration. There is delay of delay_ms between two |
| 168 | // consequent timing frames, excluding outliers. Frame is always made a |
| 169 | // timing frame if it's at least outlier_ratio in percent of "ideal" average |
| 170 | // frame given bitrate and framerate, i.e. if it's bigger than |
| 171 | // |outlier_ratio / 100.0 * bitrate_bps / fps| in bits. This way, timing |
| 172 | // frames will not be sent too often usually. Yet large frames will always |
| 173 | // have timing information for debug purposes because they are more likely to |
| 174 | // cause extra delays. |
| 175 | struct TimingFrameTriggerThresholds { |
| 176 | int64_t delay_ms; |
| 177 | uint16_t outlier_ratio_percent; |
| 178 | } timing_frame_thresholds; |
| 179 | |
Florent Castelli | d351101 | 2020-08-04 09:40:23 | [diff] [blame] | 180 | // Legacy Google conference mode flag for simulcast screenshare |
| 181 | bool legacy_conference_mode; |
| 182 | |
Niels Möller | a46bd4b | 2018-06-08 12:03:44 | [diff] [blame] | 183 | bool operator==(const VideoCodec& other) const = delete; |
| 184 | bool operator!=(const VideoCodec& other) const = delete; |
| 185 | |
| 186 | // Accessors for codec specific information. |
| 187 | // There is a const version of each that returns a reference, |
| 188 | // and a non-const version that returns a pointer, in order |
| 189 | // to allow modification of the parameters. |
| 190 | VideoCodecVP8* VP8(); |
| 191 | const VideoCodecVP8& VP8() const; |
| 192 | VideoCodecVP9* VP9(); |
| 193 | const VideoCodecVP9& VP9() const; |
| 194 | VideoCodecH264* H264(); |
| 195 | const VideoCodecH264& H264() const; |
| 196 | |
| 197 | private: |
| 198 | // TODO(hta): Consider replacing the union with a pointer type. |
| 199 | // This will allow removing the VideoCodec* types from this file. |
| 200 | VideoCodecUnion codec_specific_; |
Niels Möller | 79d566b | 2022-04-29 09:03:13 | [diff] [blame] | 201 | absl::optional<ScalabilityMode> scalability_mode_; |
“Michael | 3147e29 | 2022-02-19 22:48:50 | [diff] [blame] | 202 | // 'complexity_' indicates the CPU capability of the client. It's used to |
| 203 | // determine encoder CPU complexity (e.g., cpu_used for VP8, VP9. and AV1). |
Erik Språng | 4da317f | 2022-05-17 11:51:01 | [diff] [blame] | 204 | VideoCodecComplexity complexity_; |
Niels Möller | be2fb41 | 2022-05-17 13:39:41 | [diff] [blame] | 205 | bool frame_drop_enabled_ = false; |
Niels Möller | a46bd4b | 2018-06-08 12:03:44 | [diff] [blame] | 206 | }; |
| 207 | |
| 208 | } // namespace webrtc |
Niels Möller | 802506c | 2018-05-31 08:44:51 | [diff] [blame] | 209 | #endif // API_VIDEO_CODECS_VIDEO_CODEC_H_ |