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