summaryrefslogtreecommitdiffstats
path: root/dom/media/gmp/gmp-api/gmp-video-codec.h
blob: 1fb4930a8bfd04d35c4173e49cfdb3368a45e3ed (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* Copyright (c) 2011, The WebRTC project authors. All rights reserved.
 * Copyright (c) 2014, Mozilla
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are
 * met:
 *
 ** Redistributions of source code must retain the above copyright
 *  notice, this list of conditions and the following disclaimer.
 *
 ** Redistributions in binary form must reproduce the above copyright
 *  notice, this list of conditions and the following disclaimer in
 *  the documentation and/or other materials provided with the
 *  distribution.
 *
 ** Neither the name of Google nor the names of its contributors may
 *  be used to endorse or promote products derived from this software
 *  without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
 * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

#ifndef GMP_VIDEO_CODEC_h_
#define GMP_VIDEO_CODEC_h_

#include <stdint.h>
#include <stddef.h>

enum { kGMPPayloadNameSize = 32 };
enum { kGMPMaxSimulcastStreams = 4 };

enum GMPVideoCodecComplexity {
  kGMPComplexityNormal = 0,
  kGMPComplexityHigh = 1,
  kGMPComplexityHigher = 2,
  kGMPComplexityMax = 3,
  kGMPComplexityInvalid  // Should always be last
};

enum GMPVP8ResilienceMode {
  kResilienceOff,     // The stream produced by the encoder requires a
                      // recovery frame (typically a key frame) to be
                      // decodable after a packet loss.
  kResilientStream,   // A stream produced by the encoder is resilient to
                      // packet losses, but packets within a frame subsequent
                      // to a loss can't be decoded.
  kResilientFrames,   // Same as kResilientStream but with added resilience
                      // within a frame.
  kResilienceInvalid  // Should always be last.
};

// VP8 specific
struct GMPVideoCodecVP8 {
  bool mPictureLossIndicationOn;
  bool mFeedbackModeOn;
  GMPVideoCodecComplexity mComplexity;
  GMPVP8ResilienceMode mResilience;
  uint32_t mNumberOfTemporalLayers;
  bool mDenoisingOn;
  bool mErrorConcealmentOn;
  bool mAutomaticResizeOn;
};

// H264 specific

// Needs to match a binary spec for this structure.
// Note: the mSPS at the end of this structure is variable length.
struct GMPVideoCodecH264AVCC {
  uint8_t mVersion;  // == 0x01
  uint8_t mProfile;  // these 3 are profile_level_id
  uint8_t mConstraints;
  uint8_t mLevel;
  uint8_t mLengthSizeMinusOne;  // lower 2 bits (== GMPBufferType-1). Top 6
                                // reserved (1's)

  // SPS/PPS will not generally be present for interactive use unless SDP
  // parameter-sets are used.
  uint8_t mNumSPS;  // lower 5 bits; top 5 reserved (1's)

  /*** uint8_t   mSPS[];  (Not defined due to compiler warnings and
   * warnings-as-errors ...) **/
  // Following mNumSPS is a variable number of bytes, which is the SPS and PPS.
  // Each SPS == 16 bit size, ("N"), then "N" bytes,
  // then uint8_t mNumPPS, then each PPS == 16 bit size ("N"), then "N" bytes.
};

// Codec specific data for H.264 decoding/encoding.
// Cast the "aCodecSpecific" parameter of GMPVideoDecoder::InitDecode() and
// GMPVideoEncoder::InitEncode() to this structure.
struct GMPVideoCodecH264 {
  uint8_t mPacketizationMode;  // 0 or 1
  struct GMPVideoCodecH264AVCC
      mAVCC;  // holds a variable-sized struct GMPVideoCodecH264AVCC mAVCC;
};

enum GMPVideoCodecType {
  kGMPVideoCodecVP8,

  // Encoded frames are in AVCC format; NAL length field of 4 bytes, followed
  // by frame data. May be multiple NALUs per sample. Codec specific extra data
  // is the AVCC extra data (in AVCC format).
  kGMPVideoCodecH264,
  kGMPVideoCodecVP9,
  kGMPVideoCodecInvalid  // Should always be last.
};

// Simulcast is when the same stream is encoded multiple times with different
// settings such as resolution.
struct GMPSimulcastStream {
  uint32_t mWidth;
  uint32_t mHeight;
  uint32_t mNumberOfTemporalLayers;
  uint32_t mMaxBitrate;     // kilobits/sec.
  uint32_t mTargetBitrate;  // kilobits/sec.
  uint32_t mMinBitrate;     // kilobits/sec.
  uint32_t mQPMax;          // minimum quality
};

enum GMPVideoCodecMode {
  kGMPRealtimeVideo,
  kGMPScreensharing,
  kGMPStreamingVideo,
  kGMPNonRealtimeVideo,
  kGMPCodecModeInvalid  // Should always be last.
};

enum GMPLogLevel {
  kGMPLogDefault,
  kGMPLogQuiet,
  kGMPLogError,
  kGMPLogWarning,
  kGMPLogInfo,
  kGMPLogDebug,
  kGMPLogDetail,
  kGMPLogInvalid  // Should always be last.
};

enum GMPProfile {
  kGMPH264ProfileUnknown,
  kGMPH264ProfileBaseline,
  kGMPH264ProfileMain,
  kGMPH264ProfileExtended,
  kGMPH264ProfileHigh,
  kGMPH264ProfileHigh10,
  kGMPH264ProfileHigh422,
  kGMPH264ProfileHigh444,
  kGMPH264ProfileCavlc444,
  kGMPH264ProfileScalableBaseline,
  kGMPH264ProfileScalableHigh
};

enum GMPLevel {
  kGMPH264LevelUnknown,
  kGMPH264Level1_0,
  kGMPH264Level1_B,
  kGMPH264Level1_1,
  kGMPH264Level1_2,
  kGMPH264Level1_3,
  kGMPH264Level2_0,
  kGMPH264Level2_1,
  kGMPH264Level2_2,
  kGMPH264Level3_0,
  kGMPH264Level3_1,
  kGMPH264Level3_2,
  kGMPH264Level4_0,
  kGMPH264Level4_1,
  kGMPH264Level4_2,
  kGMPH264Level5_0,
  kGMPH264Level5_1,
  kGMPH264Level5_2
};

enum GMPRateControlMode {
  kGMPRateControlUnknown,
  kGMPRateControlBitrate,
  kGMPRateControlQuality,
  kGMPRateControlBufferBased,
  kGMPRateControlTimestamp,
  kGMPRateControlBitratePostskip,
  kGMPRateControlOff
};

enum GMPSliceMode {
  kGMPSliceUnknown,
  kGMPSliceSingle,
  kGMPSliceFixedSlcNum,
  kGMPSliceRaster,
  kGMPSliceSizeLimited
};

enum GMPApiVersion {
  kGMPVersion32 =
      1,  // leveraging that V32 had mCodecType first, and only supported H264
  kGMPVersion33 = 33,

  // Adds GMPVideoi420Frame::SetUpdatedTimestamp/UpdatedTimestamp
  kGMPVersion34 = 34,

  // Adds new options for encoding
  kGMPVersion35 = 35,
};

struct GMPVideoCodec {
  uint32_t mGMPApiVersion;

  GMPVideoCodecType mCodecType;
  char mPLName[kGMPPayloadNameSize];  // Must be NULL-terminated!
  uint32_t mPLType;

  uint32_t mWidth;
  uint32_t mHeight;

  uint32_t mStartBitrate;  // kilobits/sec.
  uint32_t mMaxBitrate;    // kilobits/sec.
  uint32_t mMinBitrate;    // kilobits/sec.
  uint32_t mMaxFramerate;

  bool mFrameDroppingOn;
  int32_t mKeyFrameInterval;

  uint32_t mQPMax;
  uint32_t mNumberOfSimulcastStreams;
  GMPSimulcastStream mSimulcastStream[kGMPMaxSimulcastStreams];

  GMPVideoCodecMode mMode;

  // Since GMP version 34
  bool mUseThreadedDecode;
  GMPLogLevel mLogLevel;

  // Since GMP version 35
  GMPLevel mLevel;
  GMPProfile mProfile;
  GMPRateControlMode mRateControlMode;
  GMPSliceMode mSliceMode;
  bool mUseThreadedEncode;
};

// Either single encoded unit, or multiple units separated by 8/16/24/32
// bit lengths, all with the same timestamp.  Note there is no final 0-length
// entry; one should check the overall end-of-buffer against where the next
// length would be.
enum GMPBufferType {
  GMP_BufferSingle = 0,
  GMP_BufferLength8,
  GMP_BufferLength16,
  GMP_BufferLength24,
  GMP_BufferLength32,
  GMP_BufferInvalid,
};

struct GMPCodecSpecificInfoGeneric {
  uint8_t mSimulcastIdx;
};

struct GMPCodecSpecificInfoH264 {
  uint8_t mSimulcastIdx;
};

// Note: if any pointers are added to this struct, it must be fitted
// with a copy-constructor. See below.
struct GMPCodecSpecificInfoVP8 {
  bool mHasReceivedSLI;
  uint8_t mPictureIdSLI;
  bool mHasReceivedRPSI;
  uint64_t mPictureIdRPSI;
  int16_t mPictureId;  // negative value to skip pictureId
  bool mNonReference;
  uint8_t mSimulcastIdx;
  uint8_t mTemporalIdx;
  bool mLayerSync;
  int32_t mTL0PicIdx;  // negative value to skip tl0PicIdx
  int8_t mKeyIdx;      // negative value to skip keyIdx
};

union GMPCodecSpecificInfoUnion {
  GMPCodecSpecificInfoGeneric mGeneric;
  GMPCodecSpecificInfoVP8 mVP8;
  GMPCodecSpecificInfoH264 mH264;
};

// Note: if any pointers are added to this struct or its sub-structs, it
// must be fitted with a copy-constructor. This is because it is copied
// in the copy-constructor of VCMEncodedFrame.
struct GMPCodecSpecificInfo {
  GMPVideoCodecType mCodecType;
  GMPBufferType mBufferType;
  GMPCodecSpecificInfoUnion mCodecSpecific;
};

#endif  // GMP_VIDEO_CODEC_h_