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