blob: 51c0ed78b577d8988c8da6e6482eaf4244385d3f [file] [log] [blame]
Niels Möller802506c2018-05-31 10:44:51 +02001/*
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 Gerey988cc082018-10-23 12:03:01 +020014#include <stddef.h>
15#include <stdint.h>
Jonas Olssona4d87372019-07-05 19:08:33 +020016
Niels Möllera46bd4b2018-06-08 14:03:44 +020017#include <string>
Niels Möller802506c2018-05-31 10:44:51 +020018
Danil Chapovalov9f4859e2020-10-16 17:45:41 +020019#include "absl/strings/string_view.h"
Yves Gerey988cc082018-10-23 12:03:01 +020020#include "api/video/video_bitrate_allocation.h"
Niels Möller22b70ff2018-11-20 11:06:58 +010021#include "api/video/video_codec_type.h"
Niels Möller79d566b2022-04-29 11:03:13 +020022#include "api/video_codecs/scalability_mode.h"
Niels Möller5b69aa62020-08-14 15:32:14 +020023#include "api/video_codecs/spatial_layer.h"
Mirko Bonadei276827c2018-10-16 14:13:50 +020024#include "rtc_base/system/rtc_export.h"
Niels Möller802506c2018-05-31 10:44:51 +020025
Niels Möllera46bd4b2018-06-08 14:03:44 +020026namespace webrtc {
27
28// The VideoCodec class represents an old defacto-apis, which we're migrating
Niels Möller802506c2018-05-31 10:44:51 +020029// away from slowly.
30
Niels Möllera46bd4b2018-06-08 14:03:44 +020031// Video codec
Niels Möllere3cf3d02018-06-13 11:52:16 +020032enum class VideoCodecComplexity {
Erik Språnge4589cb2022-04-06 16:44:30 +020033 kComplexityLow = -1,
Niels Möllera46bd4b2018-06-08 14:03:44 +020034 kComplexityNormal = 0,
35 kComplexityHigh = 1,
36 kComplexityHigher = 2,
37 kComplexityMax = 3
38};
39
40// VP8 specific
41struct VideoCodecVP8 {
42 bool operator==(const VideoCodecVP8& other) const;
43 bool operator!=(const VideoCodecVP8& other) const {
44 return !(*this == other);
45 }
46 VideoCodecComplexity complexity;
47 unsigned char numberOfTemporalLayers;
48 bool denoisingOn;
49 bool automaticResizeOn;
50 bool frameDroppingOn;
51 int keyFrameInterval;
52};
53
Sergey Silkincf267052019-04-09 11:40:09 +020054enum 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öllera46bd4b2018-06-08 14:03:44 +020058};
59
60// VP9 specific.
61struct VideoCodecVP9 {
62 bool operator==(const VideoCodecVP9& other) const;
63 bool operator!=(const VideoCodecVP9& other) const {
64 return !(*this == other);
65 }
66 VideoCodecComplexity complexity;
67 unsigned char numberOfTemporalLayers;
68 bool denoisingOn;
69 bool frameDroppingOn;
70 int keyFrameInterval;
71 bool adaptiveQpMode;
72 bool automaticResizeOn;
73 unsigned char numberOfSpatialLayers;
74 bool flexibleMode;
75 InterLayerPredMode interLayerPred;
76};
77
78// H264 specific.
79struct VideoCodecH264 {
80 bool operator==(const VideoCodecH264& other) const;
81 bool operator!=(const VideoCodecH264& other) const {
82 return !(*this == other);
83 }
84 bool frameDroppingOn;
85 int keyFrameInterval;
Johnny Lee1a1c52b2019-02-08 14:25:40 -050086 uint8_t numberOfTemporalLayers;
Niels Möllera46bd4b2018-06-08 14:03:44 +020087};
88
89// Translates from name of codec to codec type and vice versa.
Mirko Bonadeiac194142018-10-22 17:08:37 +020090RTC_EXPORT const char* CodecTypeToPayloadString(VideoCodecType type);
91RTC_EXPORT VideoCodecType PayloadStringToCodecType(const std::string& name);
Niels Möllera46bd4b2018-06-08 14:03:44 +020092
93union VideoCodecUnion {
94 VideoCodecVP8 VP8;
95 VideoCodecVP9 VP9;
96 VideoCodecH264 H264;
97};
98
Niels Möllere3cf3d02018-06-13 11:52:16 +020099enum class VideoCodecMode { kRealtimeVideo, kScreensharing };
Niels Möllera46bd4b2018-06-08 14:03:44 +0200100
101// Common video codec properties
Mirko Bonadei276827c2018-10-16 14:13:50 +0200102class RTC_EXPORT VideoCodec {
Niels Möllera46bd4b2018-06-08 14:03:44 +0200103 public:
104 VideoCodec();
105
Danil Chapovalov9f4859e2020-10-16 17:45:41 +0200106 // Scalability mode as described in
107 // https://www.w3.org/TR/webrtc-svc/#scalabilitymodes*
Niels Möller79d566b2022-04-29 11:03:13 +0200108 absl::optional<ScalabilityMode> GetScalabilityMode() const {
109 return scalability_mode_;
Danil Chapovalov9f4859e2020-10-16 17:45:41 +0200110 }
Niels Möller79d566b2022-04-29 11:03:13 +0200111 void SetScalabilityMode(ScalabilityMode scalability_mode) {
112 scalability_mode_ = scalability_mode;
113 }
114 void UnsetScalabilityMode() { scalability_mode_ = absl::nullopt; }
Danil Chapovalov9f4859e2020-10-16 17:45:41 +0200115
“Michael3147e292022-02-19 16:48:50 -0600116 VideoCodecComplexity GetVideoEncoderComplexity() const;
117 void SetVideoEncoderComplexity(VideoCodecComplexity complexity_setting);
118
Niels Möller807328f2022-05-12 16:16:39 +0200119 bool GetFrameDropEnabled() const;
120 void SetFrameDropEnabled(bool enabled);
121
Niels Möllera46bd4b2018-06-08 14:03:44 +0200122 // Public variables. TODO(hta): Make them private with accessors.
123 VideoCodecType codecType;
Niels Möllera46bd4b2018-06-08 14:03:44 +0200124
125 // TODO(nisse): Change to int, for consistency.
126 uint16_t width;
127 uint16_t height;
128
Jonas Olssona4d87372019-07-05 19:08:33 +0200129 unsigned int startBitrate; // kilobits/sec.
130 unsigned int maxBitrate; // kilobits/sec.
131 unsigned int minBitrate; // kilobits/sec.
Niels Möllera46bd4b2018-06-08 14:03:44 +0200132
133 uint32_t maxFramerate;
134
135 // This enables/disables encoding and sending when there aren't multiple
136 // simulcast streams,by allocating 0 bitrate if inactive.
137 bool active;
138
139 unsigned int qpMax;
140 unsigned char numberOfSimulcastStreams;
Niels Möller5b69aa62020-08-14 15:32:14 +0200141 SpatialLayer simulcastStream[kMaxSimulcastStreams];
Niels Möllera46bd4b2018-06-08 14:03:44 +0200142 SpatialLayer spatialLayers[kMaxSpatialLayers];
143
144 VideoCodecMode mode;
145 bool expect_encode_from_texture;
146
147 // Timing frames configuration. There is delay of delay_ms between two
148 // consequent timing frames, excluding outliers. Frame is always made a
149 // timing frame if it's at least outlier_ratio in percent of "ideal" average
150 // frame given bitrate and framerate, i.e. if it's bigger than
151 // |outlier_ratio / 100.0 * bitrate_bps / fps| in bits. This way, timing
152 // frames will not be sent too often usually. Yet large frames will always
153 // have timing information for debug purposes because they are more likely to
154 // cause extra delays.
155 struct TimingFrameTriggerThresholds {
156 int64_t delay_ms;
157 uint16_t outlier_ratio_percent;
158 } timing_frame_thresholds;
159
Florent Castellid3511012020-08-04 11:40:23 +0200160 // Legacy Google conference mode flag for simulcast screenshare
161 bool legacy_conference_mode;
162
Niels Möllera46bd4b2018-06-08 14:03:44 +0200163 bool operator==(const VideoCodec& other) const = delete;
164 bool operator!=(const VideoCodec& other) const = delete;
165
166 // Accessors for codec specific information.
167 // There is a const version of each that returns a reference,
168 // and a non-const version that returns a pointer, in order
169 // to allow modification of the parameters.
170 VideoCodecVP8* VP8();
171 const VideoCodecVP8& VP8() const;
172 VideoCodecVP9* VP9();
173 const VideoCodecVP9& VP9() const;
174 VideoCodecH264* H264();
175 const VideoCodecH264& H264() const;
176
177 private:
178 // TODO(hta): Consider replacing the union with a pointer type.
179 // This will allow removing the VideoCodec* types from this file.
180 VideoCodecUnion codec_specific_;
Niels Möller79d566b2022-04-29 11:03:13 +0200181 absl::optional<ScalabilityMode> scalability_mode_;
“Michael3147e292022-02-19 16:48:50 -0600182 // 'complexity_' indicates the CPU capability of the client. It's used to
183 // determine encoder CPU complexity (e.g., cpu_used for VP8, VP9. and AV1).
184 absl::optional<VideoCodecComplexity> complexity_;
Niels Möller807328f2022-05-12 16:16:39 +0200185 // TODO(bugs.webrtc.org/6883): When unset, GetEnableFrameDrop checks the
186 // codec-specific settings.
187 absl::optional<bool> frame_drop_enabled_;
Niels Möllera46bd4b2018-06-08 14:03:44 +0200188};
189
190} // namespace webrtc
Niels Möller802506c2018-05-31 10:44:51 +0200191#endif // API_VIDEO_CODECS_VIDEO_CODEC_H_