| 1 |
/* |
| 2 |
* Copyright (c) 2018-2025, 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_decoder.h |
| 24 |
//! \brief Defines the decode interface for CodecHal. |
| 25 |
//! \details The decode interface is further sub-divided by standard, this file is for the base interface which is shared by all decode standards. |
| 26 |
//! |
| 27 |
|
| 28 |
#ifndef __CODEC_DEF_DECODE_H__ |
| 29 |
#define __CODEC_DEF_DECODE_H__ |
| 30 |
|
| 31 |
#include "mos_os.h" |
| 32 |
#include "codec_def_decode_jpeg.h" |
| 33 |
|
| 34 |
#define HISTOGRAM_BINCOUNT 256 |
| 35 |
|
| 36 |
struct CencDecodeShareBuf; |
| 37 |
|
| 38 |
//! |
| 39 |
//! \struct FilmGrainProcParams |
| 40 |
//! \brief Define the film grain processing parameters |
| 41 |
//! |
| 42 |
struct FilmGrainProcParams |
| 43 |
{ |
| 44 |
PMOS_SURFACE m_inputSurface; |
| 45 |
PMOS_SURFACE m_outputSurface; |
| 46 |
}; |
| 47 |
|
| 48 |
//! |
| 49 |
//! \struct CodecRectangle |
| 50 |
//! \brief Parameters to describe a surface region |
| 51 |
//! |
| 52 |
struct CodecRectangle |
| 53 |
{ |
| 54 |
uint32_t m_x; |
| 55 |
uint32_t m_y; |
| 56 |
uint32_t m_width; |
| 57 |
uint32_t m_height; |
| 58 |
}; |
| 59 |
|
| 60 |
//! |
| 61 |
//! \struct DecodeProcessingParams |
| 62 |
//! \brief Parameters needed for the processing of the decode render target. |
| 63 |
//! |
| 64 |
struct DecodeProcessingParams |
| 65 |
{ |
| 66 |
// Input |
| 67 |
PMOS_SURFACE m_inputSurface; |
| 68 |
CodecRectangle m_inputSurfaceRegion; |
| 69 |
uint32_t m_inputColorStandard; |
| 70 |
uint32_t m_inputColorRange; |
| 71 |
uint32_t m_chromaSitingType; |
| 72 |
|
| 73 |
// Output |
| 74 |
PMOS_SURFACE m_outputSurface; |
| 75 |
CodecRectangle m_outputSurfaceRegion; |
| 76 |
uint32_t m_outputColorStandard; |
| 77 |
|
| 78 |
PMOS_SURFACE m_histogramSurface; |
| 79 |
PMOS_SURFACE m_histogramSurfaceU; |
| 80 |
PMOS_SURFACE m_histogramSurfaceV; |
| 81 |
|
| 82 |
// Processing state |
| 83 |
uint32_t m_rotationState; |
| 84 |
uint32_t m_blendState; |
| 85 |
uint32_t m_mirrorState; |
| 86 |
bool m_isSourceSurfAllocated; |
| 87 |
bool m_isReferenceOnlyPattern; |
| 88 |
|
| 89 |
CODECHAL_SCALING_MODE m_scalingMode; |
| 90 |
}; |
| 91 |
|
| 92 |
//! |
| 93 |
//! \struct CodechalDecodeParams |
| 94 |
//! \brief Parameters passed in via Execute() to perform decoding. |
| 95 |
//! |
| 96 |
struct CodechalDecodeParams |
| 97 |
{ |
| 98 |
//! \brief Decode render target |
| 99 |
PMOS_SURFACE m_destSurface = nullptr; |
| 100 |
//! \brief Reference frame surface |
| 101 |
PMOS_SURFACE m_refFrameSurface = nullptr; |
| 102 |
//! \brief [VC1] Deblocked output of OLP |
| 103 |
PMOS_SURFACE m_deblockSurface = nullptr; |
| 104 |
//! \brief Resource containing the bitstream (VLD mode) or residual difference (IT mode) data |
| 105 |
PMOS_RESOURCE m_dataBuffer = nullptr; |
| 106 |
//! \brief [VC1] Resource containing the bitplane data |
| 107 |
PMOS_RESOURCE m_bitplaneBuffer = nullptr; |
| 108 |
//! \brief [VP8 & VP9] resource containing coefficient probability data |
| 109 |
PMOS_RESOURCE m_coefProbBuffer = nullptr; |
| 110 |
//! \brief [VP8 & VP9] resource containing the last reference surface which was not registered. |
| 111 |
PMOS_RESOURCE m_presNoneRegLastRefFrame = nullptr; |
| 112 |
//! \brief [VP8 & VP9] resource containing the golden reference surface which was not registered. |
| 113 |
PMOS_RESOURCE m_presNoneRegGoldenRefFrame = nullptr; |
| 114 |
//! \brief [VP8 & VP9] resource containing the alt reference surface which was not registered. |
| 115 |
PMOS_RESOURCE m_presNoneRegAltRefFrame = nullptr; |
| 116 |
//! \brief [VC1 IT] Deblock data |
| 117 |
//! For advanced profile P frames, this data should be formated as an array of 6 bytes for each MB: |
| 118 |
//! Byte0: ILDBControlDataforY0 |
| 119 |
//! Byte1: ILDBControlDataforY1 |
| 120 |
//! Byte2: ILDBControlDataforY2 |
| 121 |
//! Byte3: ILDBControlDataforY3 |
| 122 |
//! Byte4: ILDBControlDataforCb |
| 123 |
//! Byte5: ILDBControlDataforCr |
| 124 |
uint8_t *m_deblockData = nullptr; |
| 125 |
|
| 126 |
//! \brief [Codecs (HEVC & VP9)] Bitstream buffer data |
| 127 |
uint8_t *m_bitStreamBufData = nullptr; |
| 128 |
//! \brief Size of the data contained in m_dataBuffer |
| 129 |
uint32_t m_dataSize = 0; |
| 130 |
//! \brief Offset of the data contained in presDataBuffer |
| 131 |
uint32_t m_dataOffset = 0; |
| 132 |
//! \brief [VLD mode] Number of slices to be decoded |
| 133 |
uint32_t m_numSlices = 0; |
| 134 |
//! \brief [IT mode] Number of MBs to be decoded |
| 135 |
uint32_t m_numMacroblocks = 0; |
| 136 |
//! \brief [VC1] size of the data contained in m_bitplaneBuffer |
| 137 |
uint32_t m_vc1BitplaneSize = 0; |
| 138 |
//! \brief [VP8 & VP9] Size of the data contained in m_coefProbBuffer |
| 139 |
uint32_t m_coefProbSize = 0; |
| 140 |
//! \brief [VC1 IT] Size of the data contained in m_deblockData |
| 141 |
uint32_t m_deblockDataSize = 0; |
| 142 |
//! \brief Number of reference frame surface |
| 143 |
uint32_t m_refSurfaceNum = 0; |
| 144 |
|
| 145 |
//! \brief Indicates whether or not stream out information should be returned to the DDI |
| 146 |
bool m_streamOutEnabled = false; |
| 147 |
//! \brief Resource to contain the stream out output from HW |
| 148 |
PMOS_RESOURCE m_externalStreamOutBuffer = nullptr; |
| 149 |
|
| 150 |
//! \brief [CENC Decode] Status reporting number associated with the current frame. |
| 151 |
uint16_t m_cencDecodeStatusReportNum = 0; |
| 152 |
CencDecodeShareBuf *m_cencBuf = nullptr; |
| 153 |
|
| 154 |
//! \brief Picture level parameters to be used for decoding |
| 155 |
void *m_picParams = nullptr; |
| 156 |
//! \brief Additional picture level parameters to be used for decoding. |
| 157 |
//! In certain cases additional parameters are needed to supplement m_picParams (MVC, etc). |
| 158 |
void *m_extPicParams = nullptr; |
| 159 |
//! \brief Picture Level parameters for HEVC advanced feature |
| 160 |
void *m_advPicParams = nullptr; |
| 161 |
//! \brief [VLD mode] Slice level parameters to be used for decoding |
| 162 |
void *m_sliceParams = nullptr; |
| 163 |
//!< [VLD LF mode] Intel long format |
| 164 |
void *m_subsetParams = nullptr; |
| 165 |
//! \brief Additional slice level parameters to be used for decoding. |
| 166 |
//! In certain cases additional parameters are needed to supplement m_sliceParams (MVC, etc). |
| 167 |
void *m_extSliceParams = nullptr; |
| 168 |
//! \brief Inverse quant matrix data |
| 169 |
void *m_iqMatrixBuffer = nullptr; |
| 170 |
//! \brief [IT mode] MB level parameters to be used for decoding |
| 171 |
void *m_macroblockParams = nullptr; |
| 172 |
//!\brief size of data contained in m_iqMatrixBuffer |
| 173 |
uint32_t m_iqMatrixSize = 0; |
| 174 |
//! \brief reference parameters to be used for decoding |
| 175 |
void *m_refParams = nullptr; |
| 176 |
//! \brief tile info parameters to be used for decoding |
| 177 |
void *m_tileParams = nullptr; |
| 178 |
|
| 179 |
//! \brief Reference count used for downsampling, If non-zero enables downsampling of the render target. |
| 180 |
uint32_t m_refFrameCnt = 0; |
| 181 |
#ifdef _DECODE_PROCESSING_SUPPORTED |
| 182 |
//! \brief Parameters used for processing the decode render target, if invalid, decode render target processing will not be used. |
| 183 |
void *m_procParams = nullptr; |
| 184 |
#endif |
| 185 |
|
| 186 |
//! \brief Parameters used for film grain process |
| 187 |
FilmGrainProcParams m_filmGrainProcParams; |
| 188 |
|
| 189 |
//! \brief [Predication] Resource for predication |
| 190 |
PMOS_RESOURCE m_presPredication = nullptr; |
| 191 |
//! \brief [Predication] Offset for Predication resource |
| 192 |
uint64_t m_predicationResOffset = 0; |
| 193 |
//! \brief [Predication] Predication mode |
| 194 |
bool m_predicationNotEqualZero = false; |
| 195 |
|
| 196 |
//! \brief [Predication] Indicates whether or not Predication is enabled |
| 197 |
bool m_predicationEnabled = false; |
| 198 |
//! \brief [Predication] Temp buffer for Predication |
| 199 |
PMOS_RESOURCE *m_tempPredicationBuffer = nullptr; |
| 200 |
|
| 201 |
//! \brief [JPEG] Huffman table data |
| 202 |
void *m_huffmanTable = nullptr; |
| 203 |
//! \brief [JPEG] Describes the layout of the decode render target |
| 204 |
CodecDecodeJpegImageLayout m_outputSurfLayout = {{0}}; |
| 205 |
// JPEG incomplete bitstream flag |
| 206 |
bool m_scanIncomplete = false; |
| 207 |
|
| 208 |
//! \brief [AVC] Indicates whethe or not PicId remapping is in use |
| 209 |
bool m_picIdRemappingInUse = false; |
| 210 |
|
| 211 |
// MPEG2 Specific Parameters |
| 212 |
//! \brief [MPEG2] MPEG2 I slice concealment mode |
| 213 |
uint32_t m_mpeg2ISliceConcealmentMode = 0; |
| 214 |
//! \brief [MPEG2] MPEG2 P/B slice concealment mode |
| 215 |
uint32_t m_mpeg2PBSliceConcealmentMode = 0; |
| 216 |
//! \brief [MPEG2] MPEG2 P/B Slice Predicted BiDir Motion Type Override |
| 217 |
uint32_t m_mpeg2PBSlicePredBiDirMVTypeOverride = 0; |
| 218 |
//! \brief [MPEG2] MPEG2 P/B Slice Predicted Motion Vector Override |
| 219 |
uint32_t m_mpeg2PBSlicePredMVOverride = 0; |
| 220 |
|
| 221 |
//! \brief [VP8] Indicates whether or not the driver is expected to parse parameters from the frame header |
| 222 |
bool m_bitstreamLockingInUse = false; |
| 223 |
//! \brief [VP8] Indicates whether or not the bitstream buffer may be directly locked to perform header parsing. |
| 224 |
bool m_bitstreamLockable = false; |
| 225 |
|
| 226 |
//! \brief [SetMarker] Indicates whether or not SetMarker is enabled |
| 227 |
bool m_setMarkerEnabled = false; |
| 228 |
//! \brief [SetMarker] Resource for SetMarker |
| 229 |
PMOS_RESOURCE m_presSetMarker = nullptr; |
| 230 |
//! \brief [SetMarker] Number Timestamp for SetMarker |
| 231 |
uint32_t setMarkerNumTs = 0; |
| 232 |
//! \brief [CENC Decode] Indicates if it's a full frame |
| 233 |
bool m_bFullFrameData = false; |
| 234 |
//! \brief MSDK event handling |
| 235 |
HANDLE m_gpuAppTaskEvent; |
| 236 |
//! \brief execution call index in multiple execution call mode |
| 237 |
uint32_t m_executeCallIndex = 0; |
| 238 |
//! \brief [Decode Histogram] Input buffer to hold decode histogram |
| 239 |
MOS_SURFACE m_histogramSurface = {}; |
| 240 |
MOS_SURFACE m_histogramSurfaceU = {}; |
| 241 |
MOS_SURFACE m_histogramSurfaceV = {}; |
| 242 |
}; |
| 243 |
|
| 244 |
typedef enum _CODECHAL_DUMMY_REFERENCE_STATUS |
| 245 |
{ |
| 246 |
CODECHAL_DUMMY_REFERENCE_INVALID, |
| 247 |
CODECHAL_DUMMY_REFERENCE_DPB, |
| 248 |
CODECHAL_DUMMY_REFERENCE_DEST_SURFACE, |
| 249 |
CODECHAL_DUMMY_REFERENCE_ALLOCATED |
| 250 |
} CODECHAL_DUMMY_REFERENCE_STATUS; |
| 251 |
|
| 252 |
//! |
| 253 |
//! \class CodechalDecodeRestoreData |
| 254 |
//! \brief This class restore the data when destory, used as temporal storage and restore automatically. |
| 255 |
//! |
| 256 |
template <typename T> |
| 257 |
class CodechalDecodeRestoreData |
| 258 |
{ |
| 259 |
public: |
| 260 |
//! |
| 261 |
//! \brief Constructor |
| 262 |
//! |
| 263 |
CodechalDecodeRestoreData(T *mem): |
| 264 |
m_mem(mem) |
| 265 |
{ |
| 266 |
if (m_mem != nullptr) |
| 267 |
{ |
| 268 |
m_restoreValue = *mem; |
| 269 |
} |
| 270 |
} |
| 271 |
//! |
| 272 |
//! \brief Constructor |
| 273 |
//! |
| 274 |
CodechalDecodeRestoreData(T *mem, T restoreValue): |
| 275 |
m_mem(mem) |
| 276 |
{ |
| 277 |
if (m_mem != nullptr) |
| 278 |
{ |
| 279 |
m_restoreValue = restoreValue; |
| 280 |
} |
| 281 |
} |
| 282 |
|
| 283 |
//! |
| 284 |
//! \brief Destructor |
| 285 |
//! |
| 286 |
~CodechalDecodeRestoreData() |
| 287 |
{ |
| 288 |
if (m_mem != nullptr) |
| 289 |
{ |
| 290 |
*m_mem = m_restoreValue; |
| 291 |
} |
| 292 |
} |
| 293 |
|
| 294 |
private: |
| 295 |
T * m_mem = nullptr; //!< Point to the memory need to be restored when this class destroy |
| 296 |
T m_restoreValue = {}; //!< The value to be restored to memory when this class destroy |
| 297 |
}; |
| 298 |
#endif // __CODEC_DEF_DECODE_H__ |