blob: 622cce13266c9da7cb4048d7a2f778ddbf91fa2b [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>
Niels Möllera46bd4b2018-06-08 14:03:44 +020016#include <string>
Niels Möller802506c2018-05-31 10:44:51 +020017
Yves Gerey988cc082018-10-23 12:03:01 +020018#include "api/video/video_bitrate_allocation.h"
Niels Möller22b70ff2018-11-20 11:06:58 +010019#include "api/video/video_codec_type.h"
Niels Möller802506c2018-05-31 10:44:51 +020020#include "common_types.h" // NOLINT(build/include)
Mirko Bonadei276827c2018-10-16 14:13:50 +020021#include "rtc_base/system/rtc_export.h"
Niels Möller802506c2018-05-31 10:44:51 +020022
Niels Möllera46bd4b2018-06-08 14:03:44 +020023namespace webrtc {
24
25// The VideoCodec class represents an old defacto-apis, which we're migrating
Niels Möller802506c2018-05-31 10:44:51 +020026// away from slowly.
27
Niels Möllera46bd4b2018-06-08 14:03:44 +020028// Video codec
Niels Möllere3cf3d02018-06-13 11:52:16 +020029enum class VideoCodecComplexity {
Niels Möllera46bd4b2018-06-08 14:03:44 +020030 kComplexityNormal = 0,
31 kComplexityHigh = 1,
32 kComplexityHigher = 2,
33 kComplexityMax = 3
34};
35
36// VP8 specific
37struct 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
Sergey Silkincf267052019-04-09 11:40:09 +020050enum class InterLayerPredMode : int {
51 kOff = 0, // Inter-layer prediction is disabled.
52 kOn = 1, // Inter-layer prediction is enabled.
53 kOnKeyPic = 2 // Inter-layer prediction is enabled but limited to key frames.
Niels Möllera46bd4b2018-06-08 14:03:44 +020054};
55
56// VP9 specific.
57struct VideoCodecVP9 {
58 bool operator==(const VideoCodecVP9& other) const;
59 bool operator!=(const VideoCodecVP9& other) const {
60 return !(*this == other);
61 }
62 VideoCodecComplexity complexity;
63 unsigned char numberOfTemporalLayers;
64 bool denoisingOn;
65 bool frameDroppingOn;
66 int keyFrameInterval;
67 bool adaptiveQpMode;
68 bool automaticResizeOn;
69 unsigned char numberOfSpatialLayers;
70 bool flexibleMode;
71 InterLayerPredMode interLayerPred;
72};
73
74// H264 specific.
75struct VideoCodecH264 {
76 bool operator==(const VideoCodecH264& other) const;
77 bool operator!=(const VideoCodecH264& other) const {
78 return !(*this == other);
79 }
80 bool frameDroppingOn;
81 int keyFrameInterval;
Johnny Lee1a1c52b2019-02-08 14:25:40 -050082 uint8_t numberOfTemporalLayers;
Niels Möllera46bd4b2018-06-08 14:03:44 +020083 // These are NULL/0 if not externally negotiated.
84 const uint8_t* spsData;
85 size_t spsLen;
86 const uint8_t* ppsData;
87 size_t ppsLen;
88 H264::Profile profile;
89};
90
91// Translates from name of codec to codec type and vice versa.
Mirko Bonadeiac194142018-10-22 17:08:37 +020092RTC_EXPORT const char* CodecTypeToPayloadString(VideoCodecType type);
93RTC_EXPORT VideoCodecType PayloadStringToCodecType(const std::string& name);
Niels Möllera46bd4b2018-06-08 14:03:44 +020094
95union VideoCodecUnion {
96 VideoCodecVP8 VP8;
97 VideoCodecVP9 VP9;
98 VideoCodecH264 H264;
99};
100
Niels Möllere3cf3d02018-06-13 11:52:16 +0200101enum class VideoCodecMode { kRealtimeVideo, kScreensharing };
Niels Möllera46bd4b2018-06-08 14:03:44 +0200102
103// Common video codec properties
Mirko Bonadei276827c2018-10-16 14:13:50 +0200104class RTC_EXPORT VideoCodec {
Niels Möllera46bd4b2018-06-08 14:03:44 +0200105 public:
106 VideoCodec();
107
108 // Public variables. TODO(hta): Make them private with accessors.
109 VideoCodecType codecType;
110 unsigned char plType;
111
112 // TODO(nisse): Change to int, for consistency.
113 uint16_t width;
114 uint16_t height;
115
116 unsigned int startBitrate; // kilobits/sec.
117 unsigned int maxBitrate; // kilobits/sec.
118 unsigned int minBitrate; // kilobits/sec.
Niels Möllera46bd4b2018-06-08 14:03:44 +0200119
120 uint32_t maxFramerate;
121
122 // This enables/disables encoding and sending when there aren't multiple
123 // simulcast streams,by allocating 0 bitrate if inactive.
124 bool active;
125
126 unsigned int qpMax;
127 unsigned char numberOfSimulcastStreams;
128 SimulcastStream simulcastStream[kMaxSimulcastStreams];
129 SpatialLayer spatialLayers[kMaxSpatialLayers];
130
131 VideoCodecMode mode;
132 bool expect_encode_from_texture;
133
134 // Timing frames configuration. There is delay of delay_ms between two
135 // consequent timing frames, excluding outliers. Frame is always made a
136 // timing frame if it's at least outlier_ratio in percent of "ideal" average
137 // frame given bitrate and framerate, i.e. if it's bigger than
138 // |outlier_ratio / 100.0 * bitrate_bps / fps| in bits. This way, timing
139 // frames will not be sent too often usually. Yet large frames will always
140 // have timing information for debug purposes because they are more likely to
141 // cause extra delays.
142 struct TimingFrameTriggerThresholds {
143 int64_t delay_ms;
144 uint16_t outlier_ratio_percent;
145 } timing_frame_thresholds;
146
147 bool operator==(const VideoCodec& other) const = delete;
148 bool operator!=(const VideoCodec& other) const = delete;
149
150 // Accessors for codec specific information.
151 // There is a const version of each that returns a reference,
152 // and a non-const version that returns a pointer, in order
153 // to allow modification of the parameters.
154 VideoCodecVP8* VP8();
155 const VideoCodecVP8& VP8() const;
156 VideoCodecVP9* VP9();
157 const VideoCodecVP9& VP9() const;
158 VideoCodecH264* H264();
159 const VideoCodecH264& H264() const;
160
161 private:
162 // TODO(hta): Consider replacing the union with a pointer type.
163 // This will allow removing the VideoCodec* types from this file.
164 VideoCodecUnion codec_specific_;
165};
166
167} // namespace webrtc
Niels Möller802506c2018-05-31 10:44:51 +0200168#endif // API_VIDEO_CODECS_VIDEO_CODEC_H_