| 1 |
/* |
| 2 |
* Copyright (c) 2017, Intel Corporation |
| 3 |
* |
| 4 |
* Permission is hereby granted, free of charge, to any person obtaining a |
| 5 |
* copy of this software and associated documentation files (the "Software"), |
| 6 |
* to deal in the Software without restriction, including without limitation |
| 7 |
* the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 8 |
* and/or sell copies of the Software, and to permit persons to whom the |
| 9 |
* Software is furnished to do so, subject to the following conditions: |
| 10 |
* |
| 11 |
* The above copyright notice and this permission notice shall be included |
| 12 |
* in all copies or substantial portions of the Software. |
| 13 |
* |
| 14 |
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
| 15 |
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 16 |
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 17 |
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR |
| 18 |
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, |
| 19 |
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
| 20 |
* OTHER DEALINGS IN THE SOFTWARE. |
| 21 |
*/ |
| 22 |
//! |
| 23 |
//! \file codec_def_encode_mpeg2.h |
| 24 |
//! \brief Defines encode MPEG2 types and macros shared by CodecHal, MHW, and DDI layer |
| 25 |
//! \details Applies to MPEG2 encode only. Should not contain any DDI specific code. |
| 26 |
//! |
| 27 |
|
| 28 |
#ifndef __CODEC_DEF_ENCODE_MPEG2_H__ |
| 29 |
#define __CODEC_DEF_ENCODE_MPEG2_H__ |
| 30 |
|
| 31 |
#include "codec_def_common_encode.h" |
| 32 |
#include "codec_def_common_mpeg2.h" |
| 33 |
|
| 34 |
#define CODEC_ENCODE_MPEG2_BRC_PIC_HEADER_SURFACE_SIZE 1024 |
| 35 |
#define CODEC_ENCODE_MPEG2_VBV_BUFFER_SIZE_UNITS (16 * 1024) //!< 16 K bits |
| 36 |
#define CODEC_ENCODE_MPEG2_MAX_NAL_TYPE 0x1f |
| 37 |
|
| 38 |
//! |
| 39 |
//! \enum CodecEncodeMpeg2ExtensionStartCode |
| 40 |
//! \brief Codec encode MPEG2 extension start code |
| 41 |
//! |
| 42 |
enum CodecEncodeMpeg2ExtensionStartCode |
| 43 |
{ |
| 44 |
// 0x00 - Reserved |
| 45 |
Mpeg2sequenceExtension = 0x01, |
| 46 |
Mpeg2sequenceDisplayExtension = 0x02, |
| 47 |
Mpeg2quantMatrixExtension = 0x03, |
| 48 |
Mpeg2copyrightExtension = 0x04, |
| 49 |
Mpeg2sequnceScalableExtension = 0x05, |
| 50 |
// 0x06 - Reserved |
| 51 |
Mpeg2pictureDisplayExtension = 0x07, |
| 52 |
Mpeg2pictureCodingExtension = 0x08, |
| 53 |
Mpeg2pictureSpatialScalableExtension = 0x09, |
| 54 |
Mpeg2pictureTemporalScalableExtension = 0x0A |
| 55 |
// 0x0B .. 0x0F - Reserved |
| 56 |
} ; |
| 57 |
|
| 58 |
//! |
| 59 |
//! \struct CodecEncodeMpeg2SequenceParams |
| 60 |
//! \brief MPEG2 Sequence Parameter Set |
| 61 |
//! |
| 62 |
struct CodecEncodeMpeg2SequenceParams |
| 63 |
{ |
| 64 |
uint16_t m_frameWidth; //!< Width of picture in unit of pixels |
| 65 |
uint16_t m_frameHeight; //!< Height of picture in unit pixels |
| 66 |
uint8_t m_profile; //!< Profile |
| 67 |
uint8_t m_level; //!< Level |
| 68 |
uint8_t m_chromaFormat; //!< Color sampling formats |
| 69 |
uint8_t m_targetUsage; //!< Target usage number, indicates trade-offs between quality and speed |
| 70 |
|
| 71 |
// ENC + PAK related parameters |
| 72 |
union |
| 73 |
{ |
| 74 |
uint16_t m_aratioFrate; //!< Aspect ratio and frame rate |
| 75 |
struct |
| 76 |
{ |
| 77 |
uint16_t m_aspectRatio : 4; //!< Aspect ratio |
| 78 |
uint16_t m_frameRateCode : 4; //!< Frame rate Code |
| 79 |
uint16_t m_frameRateExtN : 3; //!< Frame rate extend numerator |
| 80 |
uint16_t m_frameRateExtD : 5; //!< Frame rate extend denominator |
| 81 |
}; |
| 82 |
}; |
| 83 |
|
| 84 |
uint32_t m_bitrate; //!< Bit rate bits per second |
| 85 |
uint32_t m_vbvBufferSize; //!< VBV buffer size in bits |
| 86 |
|
| 87 |
uint8_t m_progressiveSequence : 1; //!< Indicate progressive sequence |
| 88 |
uint8_t m_lowDelay : 1; //!< Indicate low delay |
| 89 |
uint8_t m_resetBRC : 1; //!< Indicate if a BRC reset is desired to set a new bit rate or frame rate |
| 90 |
uint8_t m_noAcceleratorSPSInsertion : 1; //!< Indicates if current SPS is just a BRC parameter update, not a SPS change to be inserted into the bitstream. |
| 91 |
uint8_t m_forcePanicModeControl : 1; // Force to control the panic mode through DDI. |
| 92 |
uint8_t m_panicModeDisable : 1; // Disable the panic mode |
| 93 |
uint8_t m_reserved0 : 2; //!< Reserved |
| 94 |
uint8_t m_rateControlMethod; //!< rate control method, CBR = 1, VBR = 2, AVBR = 4, CQP = 3 |
| 95 |
uint16_t m_reserved1; //!< Reserved |
| 96 |
uint32_t m_maxBitRate; //!< Maximum bit rate, bits/sec |
| 97 |
uint32_t m_minBitRate; //!< Minimum bit rate, bits/sec |
| 98 |
uint32_t m_userMaxFrameSize; //!< Maximum frame size by user |
| 99 |
uint32_t m_initVBVBufferFullnessInBit; //!< Initial VBV buffer fullness size in bits |
| 100 |
uint16_t m_reserved2; //!< Reserved |
| 101 |
uint16_t m_reserved3; //!< Reserved |
| 102 |
} ; |
| 103 |
|
| 104 |
//! |
| 105 |
//! \struct CodecEncodeMpeg2PictureParams |
| 106 |
//! \brief MPEG2 Picture Parameter Set |
| 107 |
//! |
| 108 |
struct CodecEncodeMpeg2PictureParams |
| 109 |
{ |
| 110 |
CODEC_PICTURE m_currOriginalPic; //!< The current uncompressed original frame surface for encoding |
| 111 |
CODEC_PICTURE m_currReconstructedPic; //!< The uncompressed frame surface for the current reconstructed picture. |
| 112 |
uint8_t m_pictureCodingType; //!< Coding Type |
| 113 |
uint8_t m_fieldCodingFlag : 1; //!< Indication of field mode coding when set to 1. |
| 114 |
uint8_t m_fieldFrameCodingFlag : 1; //!< Indication interlaced frame coding |
| 115 |
uint8_t m_reserved0 : 2; //!< Reserved |
| 116 |
uint8_t m_interleavedFieldBFF : 1; //!< Indication of input picture layout has top field and bottom field interleaved together |
| 117 |
//!< with bottom field first when set to 1; otherwise (when set to 0) it is |
| 118 |
//!< interleaved with top field first. |
| 119 |
uint8_t m_progressiveField : 1; //!< Indication of input picture layout has only one field picture (half of a frame) stored progressively |
| 120 |
uint8_t m_reserved1 : 2; //!< Reserved |
| 121 |
|
| 122 |
uint8_t m_numSlice; //!< Number of slices per frame; number of slices per field in field coding |
| 123 |
uint8_t m_picBackwardPrediction; //!< Indicates whether any macroblocks of the current picture might include backward prediction |
| 124 |
uint8_t m_bidirectionalAveragingMode; //!< Indicates the rounding method for combining prediction planes in bidirectional motion compensation |
| 125 |
uint8_t m_pic4MVallowed; //!< Picture 4 MV allowed |
| 126 |
CODEC_PICTURE m_refFrameList[2]; //!< List of reference frame buffers |
| 127 |
bool m_useRawPicForRef; //!< Setting to 1 may improve performance at the cost of image quality |
| 128 |
uint32_t m_statusReportFeedbackNumber; //!< The status report feedback data |
| 129 |
|
| 130 |
uint32_t m_alternateScan : 1; //!< Indicate the Inverse Scan method |
| 131 |
uint32_t m_intraVlcFormat : 1; //!< Intra VLC format |
| 132 |
uint32_t m_qscaleType : 1; //!< Quantizer Scale Type |
| 133 |
uint32_t m_concealmentMotionVectors : 1; //!< Indicates if the concealment motion vectors are coded in intra macroblocks |
| 134 |
uint32_t m_framePredFrameDCT : 1; //!< Frame Prediction Frame DCT |
| 135 |
uint32_t m_disableMismatchControl : 1; //!< Disable mismatch control |
| 136 |
uint32_t m_intraDCprecision : 2; //!< Intra DC Precision |
| 137 |
uint32_t m_fcode00 : 4; //!< Used for forward horizontal motion vector prediction |
| 138 |
uint32_t m_fcode01 : 4; //!< Used for forward vertical motion vector prediction |
| 139 |
uint32_t m_fcode10 : 4; //!< Used for backward horizontal motion vector prediction |
| 140 |
uint32_t m_fcode11 : 4; //!< Used for backward vertical motion vector prediction |
| 141 |
uint32_t m_reserved2 : 8; //!< Reserved |
| 142 |
|
| 143 |
// ENC + PAK related parameters |
| 144 |
bool m_lastPicInStream; //!< Indicate the last picture of the stream |
| 145 |
bool m_newGop; //!< Indicates that a new GOP will start with this picture |
| 146 |
|
| 147 |
uint16_t m_gopPicSize; //!< Number of pictures within the current GOP |
| 148 |
uint8_t m_gopRefDist; //!< Distance between I- or P (or GPB) - key frames |
| 149 |
uint8_t m_gopOptFlag : 2; //!< Indicate the additional flags for the GOP specification |
| 150 |
uint8_t m_reserved3 : 6; //!< Reserved |
| 151 |
|
| 152 |
uint32_t m_timeCode : 25;//!< Time code |
| 153 |
uint32_t m_reserved4 : 7; //!< Reserved |
| 154 |
|
| 155 |
uint16_t m_temporalReference : 10;//!< Temporal reference |
| 156 |
uint16_t m_reserved5 : 6; //!< Reserved |
| 157 |
|
| 158 |
uint16_t m_vbvDelay; |
| 159 |
|
| 160 |
uint32_t m_repeatFirstField : 1; //!< Repeat first field |
| 161 |
uint32_t m_compositeDisplayFlag : 1; //!< Composite display flag |
| 162 |
uint32_t m_vaxis : 1; //!< Vaxis |
| 163 |
uint32_t m_fieldSequence : 3; //!< Field sequence |
| 164 |
uint32_t m_subCarrier : 1; //!< Sub carrier |
| 165 |
uint32_t m_burstAmplitude : 7; //!< Burst Amplitude |
| 166 |
uint32_t m_subCarrierPhase : 8; //!< Sub carrier phase |
| 167 |
uint32_t m_reserved6 : 10;//!< Reserved |
| 168 |
|
| 169 |
// Parameters for Skip Frames |
| 170 |
uint8_t m_skipFrameFlag; //!< Skip frame flag |
| 171 |
uint8_t m_numSkipFrames; //!< only reserved for BRC case |
| 172 |
uint32_t m_sizeSkipFrames; //!< only reserved for BRC case |
| 173 |
}; |
| 174 |
|
| 175 |
//! |
| 176 |
//! \struct CodecEncodeMpeg2SliceParmas |
| 177 |
//! \brief MPEG2 Slice Parameters |
| 178 |
//! |
| 179 |
struct CodecEncodeMpeg2SliceParmas |
| 180 |
{ |
| 181 |
uint16_t m_numMbsForSlice; //!< Number of macroblocks per slice |
| 182 |
uint16_t m_firstMbX; //!< Specifies the horizontal position of the first macroblock of the slice expressed in units of macroblocks |
| 183 |
uint16_t m_firstMbY; //!< Specifies the vertical position of the first macroblock of the slice expressed in units of macroblocks |
| 184 |
uint16_t m_intraSlice; //!< Indicates slices coded as Intra Slice |
| 185 |
uint8_t m_quantiserScaleCode; //!< Quantier scale code |
| 186 |
}; |
| 187 |
|
| 188 |
//! |
| 189 |
//! \struct CodecEncodeMpeg2VuiParams |
| 190 |
//! \brief MPEG2 VUI Parameters |
| 191 |
//! |
| 192 |
struct CodecEncodeMpeg2VuiParams |
| 193 |
{ |
| 194 |
uint32_t m_videoFormat : 3; //!< Indicate the representation of the pictures |
| 195 |
uint32_t m_reserved0 : 4; //!< Reserved |
| 196 |
uint32_t m_colourDescription : 1; //!< Indicate the colour description is presented |
| 197 |
uint32_t m_colourPrimaries : 8; //!< The chromaticity coordinates of the source primaries |
| 198 |
uint32_t m_transferCharacteristics : 8; //!< The opto-electronic transfer characteristic of the source picture |
| 199 |
uint32_t m_matrixCoefficients : 8; //!< The matrix coefficients used in deriving luminance and chrominance signals |
| 200 |
|
| 201 |
uint32_t m_displayHorizontalSize : 14;//!< The horizontal size of the display active region |
| 202 |
uint32_t m_reserved1 : 2; //!< Reserved |
| 203 |
uint32_t m_displayVerticalSize : 14;//!< The vertical size of the display active region |
| 204 |
uint32_t m_reserved2 : 2; //!< Reserved |
| 205 |
}; |
| 206 |
|
| 207 |
//! |
| 208 |
//! \struct CodecEncodeMpeg2QmatixParams |
| 209 |
//! \brief MPEG2 QMATRIX Parameters |
| 210 |
//! |
| 211 |
struct CodecEncodeMpeg2QmatixParams |
| 212 |
{ |
| 213 |
uint8_t m_newQmatrix[4]; //!< 0 - intra Y, 1 - inter Y, 2 - intra chroma, 3 - inter chroma |
| 214 |
uint16_t m_qmatrix[4][64]; //!< Quantiser matrix |
| 215 |
}; |
| 216 |
|
| 217 |
//! |
| 218 |
//! \struct CodecEncodeMpeg2UserDataList |
| 219 |
//! \brief Linked List for MPEG-2 User Data |
| 220 |
//! User data may be provided in several pieces. |
| 221 |
//! So a linked list is implemented to keep track of them. |
| 222 |
//! |
| 223 |
struct CodecEncodeMpeg2UserDataList |
| 224 |
{ |
| 225 |
void *m_userData; |
| 226 |
uint32_t m_userDataSize; |
| 227 |
CodecEncodeMpeg2UserDataList *m_nextItem; |
| 228 |
}; |
| 229 |
|
| 230 |
#endif // __CODEC_DEF_ENCODE_MPEG2_H__ |