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