blob: 2d805ca593dd95c91b681f65855f31ef0597ba5d [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öller5b69aa62020-08-14 15:32:14 +020022#include "api/video_codecs/spatial_layer.h"
Mirko Bonadei276827c2018-10-16 14:13:50 +020023#include "rtc_base/system/rtc_export.h"
Niels Möller802506c2018-05-31 10:44:51 +020024
Niels Möllera46bd4b2018-06-08 14:03:44 +020025namespace webrtc {
26
27// The VideoCodec class represents an old defacto-apis, which we're migrating
Niels Möller802506c2018-05-31 10:44:51 +020028// away from slowly.
29
Niels Möllera46bd4b2018-06-08 14:03:44 +020030// Video codec
Niels Möllere3cf3d02018-06-13 11:52:16 +020031enum class VideoCodecComplexity {
Erik Språnge4589cb2022-04-06 16:44:30 +020032 kComplexityLow = -1,
Niels Möllera46bd4b2018-06-08 14:03:44 +020033 kComplexityNormal = 0,
34 kComplexityHigh = 1,
35 kComplexityHigher = 2,
36 kComplexityMax = 3
37};
38
39// VP8 specific
40struct VideoCodecVP8 {
41 bool operator==(const VideoCodecVP8& other) const;
42 bool operator!=(const VideoCodecVP8& other) const {
43 return !(*this == other);
44 }
45 VideoCodecComplexity complexity;
46 unsigned char numberOfTemporalLayers;
47 bool denoisingOn;
48 bool automaticResizeOn;
49 bool frameDroppingOn;
50 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 }
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.
78struct 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;
Johnny Lee1a1c52b2019-02-08 14:25:40 -050085 uint8_t numberOfTemporalLayers;
Niels Möllera46bd4b2018-06-08 14:03:44 +020086};
87
88// Translates from name of codec to codec type and vice versa.
Mirko Bonadeiac194142018-10-22 17:08:37 +020089RTC_EXPORT const char* CodecTypeToPayloadString(VideoCodecType type);
90RTC_EXPORT VideoCodecType PayloadStringToCodecType(const std::string& name);
Niels Möllera46bd4b2018-06-08 14:03:44 +020091
92union VideoCodecUnion {
93 VideoCodecVP8 VP8;
94 VideoCodecVP9 VP9;
95 VideoCodecH264 H264;
96};
97
Niels Möllere3cf3d02018-06-13 11:52:16 +020098enum class VideoCodecMode { kRealtimeVideo, kScreensharing };
Niels Möllera46bd4b2018-06-08 14:03:44 +020099
100// Common video codec properties
Mirko Bonadei276827c2018-10-16 14:13:50 +0200101class RTC_EXPORT VideoCodec {
Niels Möllera46bd4b2018-06-08 14:03:44 +0200102 public:
103 VideoCodec();
104
Danil Chapovalov9f4859e2020-10-16 17:45:41 +0200105 // Scalability mode as described in
106 // https://www.w3.org/TR/webrtc-svc/#scalabilitymodes*
107 // or value 'NONE' to indicate no scalability.
108 absl::string_view ScalabilityMode() const { return scalability_mode_; }
109 void SetScalabilityMode(absl::string_view scalability_mode) {
110 scalability_mode_ = std::string(scalability_mode);
111 }
112
“Michael3147e292022-02-19 16:48:50 -0600113 VideoCodecComplexity GetVideoEncoderComplexity() const;
114 void SetVideoEncoderComplexity(VideoCodecComplexity complexity_setting);
115
Niels Möllera46bd4b2018-06-08 14:03:44 +0200116 // Public variables. TODO(hta): Make them private with accessors.
117 VideoCodecType codecType;
Niels Möllera46bd4b2018-06-08 14:03:44 +0200118
119 // TODO(nisse): Change to int, for consistency.
120 uint16_t width;
121 uint16_t height;
122
Jonas Olssona4d87372019-07-05 19:08:33 +0200123 unsigned int startBitrate; // kilobits/sec.
124 unsigned int maxBitrate; // kilobits/sec.
125 unsigned int minBitrate; // kilobits/sec.
Niels Möllera46bd4b2018-06-08 14:03:44 +0200126
127 uint32_t maxFramerate;
128
129 // This enables/disables encoding and sending when there aren't multiple
130 // simulcast streams,by allocating 0 bitrate if inactive.
131 bool active;
132
133 unsigned int qpMax;
134 unsigned char numberOfSimulcastStreams;
Niels Möller5b69aa62020-08-14 15:32:14 +0200135 SpatialLayer simulcastStream[kMaxSimulcastStreams];
Niels Möllera46bd4b2018-06-08 14:03:44 +0200136 SpatialLayer spatialLayers[kMaxSpatialLayers];
137
138 VideoCodecMode mode;
139 bool expect_encode_from_texture;
140
141 // Timing frames configuration. There is delay of delay_ms between two
142 // consequent timing frames, excluding outliers. Frame is always made a
143 // timing frame if it's at least outlier_ratio in percent of "ideal" average
144 // frame given bitrate and framerate, i.e. if it's bigger than
145 // |outlier_ratio / 100.0 * bitrate_bps / fps| in bits. This way, timing
146 // frames will not be sent too often usually. Yet large frames will always
147 // have timing information for debug purposes because they are more likely to
148 // cause extra delays.
149 struct TimingFrameTriggerThresholds {
150 int64_t delay_ms;
151 uint16_t outlier_ratio_percent;
152 } timing_frame_thresholds;
153
Florent Castellid3511012020-08-04 11:40:23 +0200154 // Legacy Google conference mode flag for simulcast screenshare
155 bool legacy_conference_mode;
156
Niels Möllera46bd4b2018-06-08 14:03:44 +0200157 bool operator==(const VideoCodec& other) const = delete;
158 bool operator!=(const VideoCodec& other) const = delete;
159
160 // Accessors for codec specific information.
161 // There is a const version of each that returns a reference,
162 // and a non-const version that returns a pointer, in order
163 // to allow modification of the parameters.
164 VideoCodecVP8* VP8();
165 const VideoCodecVP8& VP8() const;
166 VideoCodecVP9* VP9();
167 const VideoCodecVP9& VP9() const;
168 VideoCodecH264* H264();
169 const VideoCodecH264& H264() const;
170
171 private:
172 // TODO(hta): Consider replacing the union with a pointer type.
173 // This will allow removing the VideoCodec* types from this file.
174 VideoCodecUnion codec_specific_;
Danil Chapovalov9f4859e2020-10-16 17:45:41 +0200175 std::string scalability_mode_;
“Michael3147e292022-02-19 16:48:50 -0600176 // 'complexity_' indicates the CPU capability of the client. It's used to
177 // determine encoder CPU complexity (e.g., cpu_used for VP8, VP9. and AV1).
178 absl::optional<VideoCodecComplexity> complexity_;
Niels Möllera46bd4b2018-06-08 14:03:44 +0200179};
180
181} // namespace webrtc
Niels Möller802506c2018-05-31 10:44:51 +0200182#endif // API_VIDEO_CODECS_VIDEO_CODEC_H_