tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

gmp-video-codec.h (9124B)


      1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
      2 /* Copyright (c) 2011, The WebRTC project authors. All rights reserved.
      3 * Copyright (c) 2014, Mozilla
      4 *
      5 * Redistribution and use in source and binary forms, with or without
      6 * modification, are permitted provided that the following conditions are
      7 * met:
      8 *
      9 ** Redistributions of source code must retain the above copyright
     10 *  notice, this list of conditions and the following disclaimer.
     11 *
     12 ** Redistributions in binary form must reproduce the above copyright
     13 *  notice, this list of conditions and the following disclaimer in
     14 *  the documentation and/or other materials provided with the
     15 *  distribution.
     16 *
     17 ** Neither the name of Google nor the names of its contributors may
     18 *  be used to endorse or promote products derived from this software
     19 *  without specific prior written permission.
     20 *
     21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
     22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
     23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
     24 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
     25 * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
     26 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
     27 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
     31 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     32 */
     33 
     34 #ifndef GMP_VIDEO_CODEC_h_
     35 #define GMP_VIDEO_CODEC_h_
     36 
     37 #include <stddef.h>
     38 #include <stdint.h>
     39 
     40 enum { kGMPPayloadNameSize = 32 };
     41 enum { kGMPMaxSimulcastStreams = 4 };
     42 
     43 enum GMPVideoCodecComplexity {
     44  kGMPComplexityNormal = 0,
     45  kGMPComplexityHigh = 1,
     46  kGMPComplexityHigher = 2,
     47  kGMPComplexityMax = 3,
     48  kGMPComplexityInvalid  // Should always be last
     49 };
     50 
     51 enum GMPVP8ResilienceMode {
     52  kResilienceOff,     // The stream produced by the encoder requires a
     53                      // recovery frame (typically a key frame) to be
     54                      // decodable after a packet loss.
     55  kResilientStream,   // A stream produced by the encoder is resilient to
     56                      // packet losses, but packets within a frame subsequent
     57                      // to a loss can't be decoded.
     58  kResilientFrames,   // Same as kResilientStream but with added resilience
     59                      // within a frame.
     60  kResilienceInvalid  // Should always be last.
     61 };
     62 
     63 // VP8 specific
     64 struct GMPVideoCodecVP8 {
     65  bool mPictureLossIndicationOn;
     66  bool mFeedbackModeOn;
     67  GMPVideoCodecComplexity mComplexity;
     68  GMPVP8ResilienceMode mResilience;
     69  uint32_t mNumberOfTemporalLayers;
     70  bool mDenoisingOn;
     71  bool mErrorConcealmentOn;
     72  bool mAutomaticResizeOn;
     73 };
     74 
     75 // H264 specific
     76 
     77 // Needs to match a binary spec for this structure.
     78 // Note: the mSPS at the end of this structure is variable length.
     79 struct GMPVideoCodecH264AVCC {
     80  uint8_t mVersion;  // == 0x01
     81  uint8_t mProfile;  // these 3 are profile_level_id
     82  uint8_t mConstraints;
     83  uint8_t mLevel;
     84  uint8_t mLengthSizeMinusOne;  // lower 2 bits (== GMPBufferType-1). Top 6
     85                                // reserved (1's)
     86 
     87  // SPS/PPS will not generally be present for interactive use unless SDP
     88  // parameter-sets are used.
     89  uint8_t mNumSPS;  // lower 5 bits; top 5 reserved (1's)
     90 
     91  /*** uint8_t   mSPS[];  (Not defined due to compiler warnings and
     92   * warnings-as-errors ...) **/
     93  // Following mNumSPS is a variable number of bytes, which is the SPS and PPS.
     94  // Each SPS == 16 bit size, ("N"), then "N" bytes,
     95  // then uint8_t mNumPPS, then each PPS == 16 bit size ("N"), then "N" bytes.
     96 };
     97 
     98 // Codec specific data for H.264 decoding/encoding.
     99 // Cast the "aCodecSpecific" parameter of GMPVideoDecoder::InitDecode() and
    100 // GMPVideoEncoder::InitEncode() to this structure.
    101 struct GMPVideoCodecH264 {
    102  uint8_t mPacketizationMode;  // 0 or 1
    103  struct GMPVideoCodecH264AVCC
    104      mAVCC;  // holds a variable-sized struct GMPVideoCodecH264AVCC mAVCC;
    105 };
    106 
    107 enum GMPVideoCodecType {
    108  kGMPVideoCodecVP8,
    109 
    110  // Encoded frames are in AVCC format; NAL length field of 4 bytes, followed
    111  // by frame data. May be multiple NALUs per sample. Codec specific extra data
    112  // is the AVCC extra data (in AVCC format).
    113  kGMPVideoCodecH264,
    114  kGMPVideoCodecVP9,
    115  kGMPVideoCodecInvalid  // Should always be last.
    116 };
    117 
    118 // Simulcast is when the same stream is encoded multiple times with different
    119 // settings such as resolution.
    120 struct GMPSimulcastStream {
    121  uint32_t mWidth;
    122  uint32_t mHeight;
    123  uint32_t mNumberOfTemporalLayers;
    124  uint32_t mMaxBitrate;     // kilobits/sec.
    125  uint32_t mTargetBitrate;  // kilobits/sec.
    126  uint32_t mMinBitrate;     // kilobits/sec.
    127  uint32_t mQPMax;          // minimum quality
    128 };
    129 
    130 enum GMPVideoCodecMode {
    131  kGMPRealtimeVideo,
    132  kGMPScreensharing,
    133  kGMPStreamingVideo,
    134  kGMPNonRealtimeVideo,
    135  kGMPCodecModeInvalid  // Should always be last.
    136 };
    137 
    138 enum GMPLogLevel {
    139  kGMPLogDefault,
    140  kGMPLogQuiet,
    141  kGMPLogError,
    142  kGMPLogWarning,
    143  kGMPLogInfo,
    144  kGMPLogDebug,
    145  kGMPLogDetail,
    146  kGMPLogInvalid  // Should always be last.
    147 };
    148 
    149 enum GMPProfile {
    150  kGMPH264ProfileUnknown,
    151  kGMPH264ProfileBaseline,
    152  kGMPH264ProfileMain,
    153  kGMPH264ProfileExtended,
    154  kGMPH264ProfileHigh,
    155  kGMPH264ProfileHigh10,
    156  kGMPH264ProfileHigh422,
    157  kGMPH264ProfileHigh444,
    158  kGMPH264ProfileCavlc444,
    159  kGMPH264ProfileScalableBaseline,
    160  kGMPH264ProfileScalableHigh
    161 };
    162 
    163 enum GMPLevel {
    164  kGMPH264LevelUnknown,
    165  kGMPH264Level1_0,
    166  kGMPH264Level1_B,
    167  kGMPH264Level1_1,
    168  kGMPH264Level1_2,
    169  kGMPH264Level1_3,
    170  kGMPH264Level2_0,
    171  kGMPH264Level2_1,
    172  kGMPH264Level2_2,
    173  kGMPH264Level3_0,
    174  kGMPH264Level3_1,
    175  kGMPH264Level3_2,
    176  kGMPH264Level4_0,
    177  kGMPH264Level4_1,
    178  kGMPH264Level4_2,
    179  kGMPH264Level5_0,
    180  kGMPH264Level5_1,
    181  kGMPH264Level5_2
    182 };
    183 
    184 enum GMPRateControlMode {
    185  kGMPRateControlUnknown,
    186  kGMPRateControlBitrate,
    187  kGMPRateControlQuality,
    188  kGMPRateControlBufferBased,
    189  kGMPRateControlTimestamp,
    190  kGMPRateControlBitratePostskip,
    191  kGMPRateControlOff
    192 };
    193 
    194 enum GMPSliceMode {
    195  kGMPSliceUnknown,
    196  kGMPSliceSingle,
    197  kGMPSliceFixedSlcNum,
    198  kGMPSliceRaster,
    199  kGMPSliceSizeLimited
    200 };
    201 
    202 enum GMPApiVersion {
    203  kGMPVersion32 =
    204      1,  // leveraging that V32 had mCodecType first, and only supported H264
    205  kGMPVersion33 = 33,
    206 
    207  // Adds GMPVideoi420Frame::SetUpdatedTimestamp/UpdatedTimestamp
    208  kGMPVersion34 = 34,
    209 
    210  // Adds new options for encoding
    211  kGMPVersion35 = 35,
    212 
    213  // Adds temporal layer options for encoding
    214  kGMPVersion36 = 36,
    215 };
    216 
    217 struct GMPVideoCodec {
    218  uint32_t mGMPApiVersion;
    219 
    220  GMPVideoCodecType mCodecType;
    221  char mPLName[kGMPPayloadNameSize];  // Must be NULL-terminated!
    222  uint32_t mPLType;
    223 
    224  uint32_t mWidth;
    225  uint32_t mHeight;
    226 
    227  uint32_t mStartBitrate;  // kilobits/sec.
    228  uint32_t mMaxBitrate;    // kilobits/sec.
    229  uint32_t mMinBitrate;    // kilobits/sec.
    230  uint32_t mMaxFramerate;
    231 
    232  bool mFrameDroppingOn;
    233  int32_t mKeyFrameInterval;
    234 
    235  uint32_t mQPMax;
    236  uint32_t mNumberOfSimulcastStreams;
    237  GMPSimulcastStream mSimulcastStream[kGMPMaxSimulcastStreams];
    238 
    239  GMPVideoCodecMode mMode;
    240 
    241  // Since GMP version 34
    242  bool mUseThreadedDecode;
    243  GMPLogLevel mLogLevel;
    244 
    245  // Since GMP version 35
    246  GMPLevel mLevel;
    247  GMPProfile mProfile;
    248  GMPRateControlMode mRateControlMode;
    249  GMPSliceMode mSliceMode;
    250  bool mUseThreadedEncode;
    251 
    252  // Since GMP version 36
    253  int32_t mTemporalLayerNum;
    254 };
    255 
    256 // Either single encoded unit, or multiple units separated by 8/16/24/32
    257 // bit lengths, all with the same timestamp.  Note there is no final 0-length
    258 // entry; one should check the overall end-of-buffer against where the next
    259 // length would be.
    260 enum GMPBufferType {
    261  GMP_BufferSingle = 0,
    262  GMP_BufferLength8,
    263  GMP_BufferLength16,
    264  GMP_BufferLength24,
    265  GMP_BufferLength32,
    266  GMP_BufferInvalid,
    267 };
    268 
    269 struct GMPCodecSpecificInfoGeneric {
    270  uint8_t mSimulcastIdx;
    271 };
    272 
    273 struct GMPCodecSpecificInfoH264 {
    274  uint8_t mSimulcastIdx;
    275 };
    276 
    277 // Note: if any pointers are added to this struct, it must be fitted
    278 // with a copy-constructor. See below.
    279 struct GMPCodecSpecificInfoVP8 {
    280  bool mHasReceivedSLI;
    281  uint8_t mPictureIdSLI;
    282  bool mHasReceivedRPSI;
    283  uint64_t mPictureIdRPSI;
    284  int16_t mPictureId;  // negative value to skip pictureId
    285  bool mNonReference;
    286  uint8_t mSimulcastIdx;
    287  uint8_t mTemporalIdx;
    288  bool mLayerSync;
    289  int32_t mTL0PicIdx;  // negative value to skip tl0PicIdx
    290  int8_t mKeyIdx;      // negative value to skip keyIdx
    291 };
    292 
    293 union GMPCodecSpecificInfoUnion {
    294  GMPCodecSpecificInfoGeneric mGeneric;
    295  GMPCodecSpecificInfoVP8 mVP8;
    296  GMPCodecSpecificInfoH264 mH264;
    297 };
    298 
    299 // Note: if any pointers are added to this struct or its sub-structs, it
    300 // must be fitted with a copy-constructor. This is because it is copied
    301 // in the copy-constructor of VCMEncodedFrame.
    302 struct GMPCodecSpecificInfo {
    303  GMPVideoCodecType mCodecType;
    304  GMPBufferType mBufferType;
    305  GMPCodecSpecificInfoUnion mCodecSpecific;
    306 };
    307 
    308 #endif  // GMP_VIDEO_CODEC_h_