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