blob: 068b09d27a0d2f219d7a3fc3ebd4eaf170e5f451 [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öllerc0a9f352022-05-20 13:38:49 +020023#include "api/video_codecs/simulcast_stream.h"
Niels Möller5b69aa62020-08-14 15:32:14 +020024#include "api/video_codecs/spatial_layer.h"
Mirko Bonadei276827c2018-10-16 14:13:50 +020025#include "rtc_base/system/rtc_export.h"
Niels Möller802506c2018-05-31 10:44:51 +020026
Niels Möllera46bd4b2018-06-08 14:03:44 +020027namespace webrtc {
28
29// The VideoCodec class represents an old defacto-apis, which we're migrating
Niels Möller802506c2018-05-31 10:44:51 +020030// away from slowly.
31
Niels Möllera46bd4b2018-06-08 14:03:44 +020032// Video codec
Niels Möllere3cf3d02018-06-13 11:52:16 +020033enum class VideoCodecComplexity {
Erik Språnge4589cb2022-04-06 16:44:30 +020034 kComplexityLow = -1,
Niels Möllera46bd4b2018-06-08 14:03:44 +020035 kComplexityNormal = 0,
36 kComplexityHigh = 1,
37 kComplexityHigher = 2,
38 kComplexityMax = 3
39};
40
41// VP8 specific
42struct VideoCodecVP8 {
43 bool operator==(const VideoCodecVP8& other) const;
44 bool operator!=(const VideoCodecVP8& other) const {
45 return !(*this == other);
46 }
Niels Möllera46bd4b2018-06-08 14:03:44 +020047 unsigned char numberOfTemporalLayers;
48 bool denoisingOn;
49 bool automaticResizeOn;
Niels Möllera46bd4b2018-06-08 14:03:44 +020050 int keyFrameInterval;
51};
52
Sergey Silkincf267052019-04-09 11:40:09 +020053enum class InterLayerPredMode : int {
54 kOff = 0, // Inter-layer prediction is disabled.
55 kOn = 1, // Inter-layer prediction is enabled.
56 kOnKeyPic = 2 // Inter-layer prediction is enabled but limited to key frames.
Niels Möllera46bd4b2018-06-08 14:03:44 +020057};
58
59// VP9 specific.
60struct VideoCodecVP9 {
61 bool operator==(const VideoCodecVP9& other) const;
62 bool operator!=(const VideoCodecVP9& other) const {
63 return !(*this == other);
64 }
Niels Möllera46bd4b2018-06-08 14:03:44 +020065 unsigned char numberOfTemporalLayers;
66 bool denoisingOn;
Niels Möllera46bd4b2018-06-08 14:03:44 +020067 int keyFrameInterval;
68 bool adaptiveQpMode;
69 bool automaticResizeOn;
70 unsigned char numberOfSpatialLayers;
71 bool flexibleMode;
72 InterLayerPredMode interLayerPred;
73};
74
75// H264 specific.
76struct VideoCodecH264 {
77 bool operator==(const VideoCodecH264& other) const;
78 bool operator!=(const VideoCodecH264& other) const {
79 return !(*this == other);
80 }
Niels Möllera46bd4b2018-06-08 14:03:44 +020081 int keyFrameInterval;
Johnny Lee1a1c52b2019-02-08 14:25:40 -050082 uint8_t numberOfTemporalLayers;
Niels Möllera46bd4b2018-06-08 14:03:44 +020083};
84
85// Translates from name of codec to codec type and vice versa.
Mirko Bonadeiac194142018-10-22 17:08:37 +020086RTC_EXPORT const char* CodecTypeToPayloadString(VideoCodecType type);
87RTC_EXPORT VideoCodecType PayloadStringToCodecType(const std::string& name);
Niels Möllera46bd4b2018-06-08 14:03:44 +020088
89union VideoCodecUnion {
90 VideoCodecVP8 VP8;
91 VideoCodecVP9 VP9;
92 VideoCodecH264 H264;
93};
94
Niels Möllere3cf3d02018-06-13 11:52:16 +020095enum class VideoCodecMode { kRealtimeVideo, kScreensharing };
Niels Möllera46bd4b2018-06-08 14:03:44 +020096
97// Common video codec properties
Mirko Bonadei276827c2018-10-16 14:13:50 +020098class RTC_EXPORT VideoCodec {
Niels Möllera46bd4b2018-06-08 14:03:44 +020099 public:
100 VideoCodec();
101
Danil Chapovalov9f4859e2020-10-16 17:45:41 +0200102 // Scalability mode as described in
103 // https://www.w3.org/TR/webrtc-svc/#scalabilitymodes*
Niels Möller79d566b2022-04-29 11:03:13 +0200104 absl::optional<ScalabilityMode> GetScalabilityMode() const {
105 return scalability_mode_;
Danil Chapovalov9f4859e2020-10-16 17:45:41 +0200106 }
Niels Möller79d566b2022-04-29 11:03:13 +0200107 void SetScalabilityMode(ScalabilityMode scalability_mode) {
108 scalability_mode_ = scalability_mode;
109 }
110 void UnsetScalabilityMode() { scalability_mode_ = absl::nullopt; }
Danil Chapovalov9f4859e2020-10-16 17:45:41 +0200111
“Michael3147e292022-02-19 16:48:50 -0600112 VideoCodecComplexity GetVideoEncoderComplexity() const;
113 void SetVideoEncoderComplexity(VideoCodecComplexity complexity_setting);
114
Niels Möller807328f2022-05-12 16:16:39 +0200115 bool GetFrameDropEnabled() const;
116 void SetFrameDropEnabled(bool enabled);
117
Niels Möllera46bd4b2018-06-08 14:03:44 +0200118 // Public variables. TODO(hta): Make them private with accessors.
119 VideoCodecType codecType;
Niels Möllera46bd4b2018-06-08 14:03:44 +0200120
121 // TODO(nisse): Change to int, for consistency.
122 uint16_t width;
123 uint16_t height;
124
Jonas Olssona4d87372019-07-05 19:08:33 +0200125 unsigned int startBitrate; // kilobits/sec.
126 unsigned int maxBitrate; // kilobits/sec.
127 unsigned int minBitrate; // kilobits/sec.
Niels Möllera46bd4b2018-06-08 14:03:44 +0200128
129 uint32_t maxFramerate;
130
131 // This enables/disables encoding and sending when there aren't multiple
132 // simulcast streams,by allocating 0 bitrate if inactive.
133 bool active;
134
135 unsigned int qpMax;
136 unsigned char numberOfSimulcastStreams;
Niels Möllerc0a9f352022-05-20 13:38:49 +0200137 SimulcastStream simulcastStream[kMaxSimulcastStreams];
Niels Möllera46bd4b2018-06-08 14:03:44 +0200138 SpatialLayer spatialLayers[kMaxSpatialLayers];
139
140 VideoCodecMode mode;
141 bool expect_encode_from_texture;
142
143 // Timing frames configuration. There is delay of delay_ms between two
144 // consequent timing frames, excluding outliers. Frame is always made a
145 // timing frame if it's at least outlier_ratio in percent of "ideal" average
146 // frame given bitrate and framerate, i.e. if it's bigger than
147 // |outlier_ratio / 100.0 * bitrate_bps / fps| in bits. This way, timing
148 // frames will not be sent too often usually. Yet large frames will always
149 // have timing information for debug purposes because they are more likely to
150 // cause extra delays.
151 struct TimingFrameTriggerThresholds {
152 int64_t delay_ms;
153 uint16_t outlier_ratio_percent;
154 } timing_frame_thresholds;
155
Florent Castellid3511012020-08-04 11:40:23 +0200156 // Legacy Google conference mode flag for simulcast screenshare
157 bool legacy_conference_mode;
158
Niels Möllera46bd4b2018-06-08 14:03:44 +0200159 bool operator==(const VideoCodec& other) const = delete;
160 bool operator!=(const VideoCodec& other) const = delete;
161
162 // Accessors for codec specific information.
163 // There is a const version of each that returns a reference,
164 // and a non-const version that returns a pointer, in order
165 // to allow modification of the parameters.
166 VideoCodecVP8* VP8();
167 const VideoCodecVP8& VP8() const;
168 VideoCodecVP9* VP9();
169 const VideoCodecVP9& VP9() const;
170 VideoCodecH264* H264();
171 const VideoCodecH264& H264() const;
172
173 private:
174 // TODO(hta): Consider replacing the union with a pointer type.
175 // This will allow removing the VideoCodec* types from this file.
176 VideoCodecUnion codec_specific_;
Niels Möller79d566b2022-04-29 11:03:13 +0200177 absl::optional<ScalabilityMode> scalability_mode_;
“Michael3147e292022-02-19 16:48:50 -0600178 // 'complexity_' indicates the CPU capability of the client. It's used to
179 // determine encoder CPU complexity (e.g., cpu_used for VP8, VP9. and AV1).
Erik Språng4da317f2022-05-17 13:51:01 +0200180 VideoCodecComplexity complexity_;
Niels Möllerbe2fb412022-05-17 15:39:41 +0200181 bool frame_drop_enabled_ = false;
Niels Möllera46bd4b2018-06-08 14:03:44 +0200182};
183
184} // namespace webrtc
Niels Möller802506c2018-05-31 10:44:51 +0200185#endif // API_VIDEO_CODECS_VIDEO_CODEC_H_