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