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