| 1 |
/* |
| 2 |
* Copyright (c) 2022, 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 ddi_libva_encoder_specific.h |
| 24 |
//! \brief libva(and its extension) encoder head file |
| 25 |
//! |
| 26 |
|
| 27 |
#ifndef __DDI_LIBVA_ENCODER_SPECIFIC_H__ |
| 28 |
#define __DDI_LIBVA_ENCODER_SPECIFIC_H__ |
| 29 |
|
| 30 |
#include "media_libva.h" |
| 31 |
#include "ddi_cp_interface_next.h" |
| 32 |
#include "media_libva_cp_interface.h" |
| 33 |
#include <vector> |
| 34 |
namespace encode |
| 35 |
{ |
| 36 |
// change to 0x1000 for memory optimization, double check when implement slice header packing in app |
| 37 |
#define PACKED_HEADER_SIZE_PER_ROW 0x1000 |
| 38 |
|
| 39 |
#define DDI_ENCODE_MAX_STATUS_REPORT_BUFFER CODECHAL_ENCODE_STATUS_NUM |
| 40 |
|
| 41 |
typedef enum _DDI_ENCODE_FEI_ENC_BUFFER_TYPE |
| 42 |
{ |
| 43 |
FEI_ENC_BUFFER_TYPE_MVDATA = 0, |
| 44 |
FEI_ENC_BUFFER_TYPE_MBCODE = 1, |
| 45 |
FEI_ENC_BUFFER_TYPE_DISTORTION = 2, |
| 46 |
FEI_ENC_BUFFER_TYPE_MAX = 3 |
| 47 |
} DDI_ENCODE_FEI_ENC_BUFFER_TYPE; |
| 48 |
|
| 49 |
typedef enum _DDI_ENCODE_PRE_ENC_BUFFER_TYPE |
| 50 |
{ |
| 51 |
PRE_ENC_BUFFER_TYPE_MVDATA = 0, |
| 52 |
PRE_ENC_BUFFER_TYPE_STATS = 1, |
| 53 |
PRE_ENC_BUFFER_TYPE_STATS_BOT = 2, |
| 54 |
PRE_ENC_BUFFER_TYPE_MAX = 3 |
| 55 |
} DDI_ENCODE_PRE_ENC_BUFFER_TYPE; |
| 56 |
|
| 57 |
typedef struct _DDI_ENCODE_STATUS_REPORT_INFO |
| 58 |
{ |
| 59 |
void *pCodedBuf; //encoded buffer address |
| 60 |
uint32_t uiSize; //encoded frame size |
| 61 |
uint32_t uiStatus; // Encode frame status |
| 62 |
uint32_t uiInputCtr[4]; // Counter for HDCP2 session |
| 63 |
} DDI_ENCODE_STATUS_REPORT_INFO; |
| 64 |
|
| 65 |
// ENC output buffer checking for FEI_ENC case only |
| 66 |
typedef struct _DDI_ENCODE_STATUS_REPORT_ENC_INFO |
| 67 |
{ |
| 68 |
void *pEncBuf[3]; // ENC buffers address for Mvdata, MbCode and Distortion |
| 69 |
uint32_t uiBuffers; // rendered ENC buffers |
| 70 |
uint32_t uiStatus; // ENC frame status |
| 71 |
} DDI_ENCODE_STATUS_REPORT_ENC_INFO; |
| 72 |
|
| 73 |
// PREENC output buffer checking |
| 74 |
typedef struct _DDI_ENCODE_STATUS_REPORT_PREENC_INFO |
| 75 |
{ |
| 76 |
void *pPreEncBuf[3]; // PREENC buffers address for Mvdata and Statistics, Statistics of Bottom Field |
| 77 |
uint32_t uiBuffers; // rendered ENC buffers |
| 78 |
uint32_t uiStatus; // PREENC frame status |
| 79 |
} DDI_ENCODE_STATUS_REPORT_PREENC_INFO; |
| 80 |
|
| 81 |
typedef struct _DDI_ENCODE_STATUS_REPORT_INFO_BUF |
| 82 |
{ |
| 83 |
DDI_ENCODE_STATUS_REPORT_INFO infos[DDI_ENCODE_MAX_STATUS_REPORT_BUFFER]; |
| 84 |
DDI_ENCODE_STATUS_REPORT_ENC_INFO encInfos[DDI_ENCODE_MAX_STATUS_REPORT_BUFFER]; |
| 85 |
DDI_ENCODE_STATUS_REPORT_PREENC_INFO preencInfos[DDI_ENCODE_MAX_STATUS_REPORT_BUFFER]; |
| 86 |
uint32_t ulHeadPosition; |
| 87 |
uint32_t ulUpdatePosition; |
| 88 |
} DDI_ENCODE_STATUS_REPORT_INFO_BUF; |
| 89 |
|
| 90 |
class DdiEncodeBase; |
| 91 |
|
| 92 |
typedef struct _DDI_ENCODE_CONTEXT |
| 93 |
{ |
| 94 |
DdiEncodeBase *m_encode; |
| 95 |
Codechal *pCodecHal; |
| 96 |
CODECHAL_MODE wModeType; |
| 97 |
CODECHAL_FUNCTION codecFunction; |
| 98 |
VAProfile vaProfile; |
| 99 |
VAEntrypoint vaEntrypoint; |
| 100 |
void *pSeqParams; |
| 101 |
void *pVuiParams; |
| 102 |
void *pPicParams; |
| 103 |
void *pSliceParams; |
| 104 |
void *pEncodeStatusReport; |
| 105 |
void *pQmatrixParams; |
| 106 |
void *pFeiPicParams; |
| 107 |
void *pVpxSegParams; |
| 108 |
bool bMbDisableSkipMapEnabled; |
| 109 |
MOS_RESOURCE resPerMBSkipMapBuffer; |
| 110 |
void *pPreEncParams; |
| 111 |
DDI_ENCODE_STATUS_REPORT_INFO_BUF statusReportBuf; |
| 112 |
MOS_RESOURCE resBitstreamBuffer; |
| 113 |
MOS_RESOURCE resMbCodeBuffer; |
| 114 |
MOS_RESOURCE resProbCoeffBuffer; |
| 115 |
MOS_SURFACE sCoeffSurface; |
| 116 |
MOS_RESOURCE resMBQpBuffer; |
| 117 |
//CP related |
| 118 |
DdiCpInterface *pCpDdiInterface; |
| 119 |
DdiCpInterfaceNext *pCpDdiInterfaceNext; |
| 120 |
|
| 121 |
uint32_t indexNALUnit; |
| 122 |
uint8_t PicParamId; |
| 123 |
MOS_SURFACE segMapBuffer; |
| 124 |
uint32_t segmentMapDataSize; |
| 125 |
uint8_t *pSegmentMap; |
| 126 |
uint16_t wPicWidthInMB; // Picture Width in MB width count |
| 127 |
uint16_t wPicHeightInMB; // Picture Height in MB height count |
| 128 |
uint16_t wOriPicWidthInMB; |
| 129 |
uint16_t wOriPicHeightInMB; |
| 130 |
uint16_t wContextPicWidthInMB; |
| 131 |
uint16_t wContextPicHeightInMB; |
| 132 |
uint32_t dworiFrameWidth; // Original Frame width in luma samples |
| 133 |
uint32_t dworiFrameHeight; // Original Frame height in luma samples |
| 134 |
uint32_t dwFrameWidth; // Frame width in luma samples |
| 135 |
uint32_t dwFrameHeight; // Frame height in luma samples |
| 136 |
PBSBuffer pbsBuffer; |
| 137 |
uint32_t dwNumSlices; |
| 138 |
bool bNewSeq; |
| 139 |
bool bPicQuant; |
| 140 |
bool bNewQmatrixData; |
| 141 |
bool bNewVuiData; |
| 142 |
uint32_t uFrameRate; |
| 143 |
|
| 144 |
PCODECHAL_NAL_UNIT_PARAMS *ppNALUnitParams; |
| 145 |
PCODEC_ENCODER_SLCDATA pSliceHeaderData; |
| 146 |
uint32_t uiSliceHeaderCnt; |
| 147 |
// For square region based rolling I |
| 148 |
uint32_t uiIntraRefreshFrameCnt; |
| 149 |
uint32_t uiIntraRefreshMBx; |
| 150 |
uint32_t uiIntraRefreshMBy; |
| 151 |
|
| 152 |
// whether packed slice headers are passed from application; |
| 153 |
bool bHavePackedSliceHdr; |
| 154 |
|
| 155 |
// whether the latest packed header type is for slice header |
| 156 |
bool bLastPackedHdrIsSlice; |
| 157 |
|
| 158 |
// SEI stream passed by app |
| 159 |
CodechalEncodeSeiData *pSEIFromApp; |
| 160 |
uint32_t uiRCMethod; |
| 161 |
|
| 162 |
uint32_t uiTargetBitRate; |
| 163 |
uint32_t uiMaxBitRate; |
| 164 |
|
| 165 |
EncoderParams EncodeParams; |
| 166 |
|
| 167 |
//VDENC Enable flag |
| 168 |
bool bVdencActive; |
| 169 |
//VDENC Dynamic slice enabling |
| 170 |
bool EnableSliceLevelRateCtrl; |
| 171 |
//Per-MB Qp control |
| 172 |
bool bMBQpEnable; |
| 173 |
|
| 174 |
DDI_CODEC_RENDER_TARGET_TABLE RTtbl; |
| 175 |
DDI_CODEC_COM_BUFFER_MGR BufMgr; |
| 176 |
PDDI_MEDIA_CONTEXT pMediaCtx; |
| 177 |
|
| 178 |
uint8_t targetUsage; |
| 179 |
|
| 180 |
} DDI_ENCODE_CONTEXT, *PDDI_ENCODE_CONTEXT; |
| 181 |
|
| 182 |
static __inline PDDI_ENCODE_CONTEXT GetEncContextFromPVOID (void *encCtx) |
| 183 |
{ |
| 184 |
return (PDDI_ENCODE_CONTEXT)encCtx; |
| 185 |
} |
| 186 |
|
| 187 |
} // namespace encode |
| 188 |
#endif // __DDI_LIBVA_ENCODER_SPECiFIC_H__ |