| 1 |
/* |
| 2 |
* Copyright (c) 2021, 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 media_ddi_encode_av1.cpp |
| 24 |
//! \brief Defines class for DDI media av1 encode. |
| 25 |
//! |
| 26 |
|
| 27 |
#include "media_libva.h" |
| 28 |
#include "media_libva_util.h" |
| 29 |
#include "media_libva_encoder.h" |
| 30 |
#include "media_ddi_factory.h" |
| 31 |
#include "media_ddi_encode_base.h" |
| 32 |
#include "media_ddi_encode_av1.h" |
| 33 |
#include "media_ddi_encode_const.h" |
| 34 |
#include "codec_def_encode_av1.h" |
| 35 |
#include "mos_solo_generic.h" |
| 36 |
#include "media_ddi_encode_const.h" |
| 37 |
|
| 38 |
enum |
| 39 |
{ |
| 40 |
ENCODE_MODE_NULL = 0, |
| 41 |
ENCODE_MODE_AVC, |
| 42 |
ENCODE_MODE_MPEG2, |
| 43 |
ENCODE_MODE_VP8, |
| 44 |
ENCODE_MODE_JPEG, |
| 45 |
ENCODE_MODE_HEVC, |
| 46 |
ENCODE_MODE_VP9, |
| 47 |
ENCODE_MODE_AV1, |
| 48 |
NUM_ENCODE_MODES |
| 49 |
}; |
| 50 |
|
| 51 |
extern template class MediaDdiFactoryNoArg<DdiEncodeBase>; |
| 52 |
|
| 53 |
static bool isEncodeAV1Registered = |
| 54 |
MediaDdiFactoryNoArg<DdiEncodeBase>::RegisterCodec<DdiEncodeAV1>(ENCODE_ID_AV1); |
| 55 |
|
| 56 |
DdiEncodeAV1::~DdiEncodeAV1() |
| 57 |
{ |
| 58 |
if (m_encodeCtx == nullptr) |
| 59 |
{ |
| 60 |
return; |
| 61 |
} |
| 62 |
|
| 63 |
MOS_FreeMemory(m_encodeCtx->pSeqParams); |
| 64 |
m_encodeCtx->pSeqParams = nullptr; |
| 65 |
|
| 66 |
MOS_FreeMemory(m_encodeCtx->pPicParams); |
| 67 |
m_encodeCtx->pPicParams = nullptr; |
| 68 |
|
| 69 |
MOS_FreeMemory(m_encodeCtx->pSliceParams); |
| 70 |
m_encodeCtx->pSliceParams = nullptr; |
| 71 |
|
| 72 |
MOS_FreeMemory(m_encodeCtx->pEncodeStatusReport); |
| 73 |
m_encodeCtx->pEncodeStatusReport = nullptr; |
| 74 |
|
| 75 |
MOS_FreeMemory(m_encodeCtx->pSliceHeaderData); |
| 76 |
m_encodeCtx->pSliceHeaderData = nullptr; |
| 77 |
|
| 78 |
if (m_encodeCtx->pbsBuffer) |
| 79 |
{ |
| 80 |
MOS_FreeMemory(m_encodeCtx->pbsBuffer->pBase); |
| 81 |
m_encodeCtx->pbsBuffer->pBase = nullptr; |
| 82 |
} |
| 83 |
MOS_FreeMemory(m_encodeCtx->pbsBuffer); |
| 84 |
m_encodeCtx->pbsBuffer = nullptr; |
| 85 |
|
| 86 |
if (m_encodeCtx->ppNALUnitParams && m_encodeCtx->ppNALUnitParams[0]) |
| 87 |
{ |
| 88 |
// Allocate one contiguous memory for the NALUnitParams buffers |
| 89 |
// only need to free one time |
| 90 |
MOS_FreeMemory(m_encodeCtx->ppNALUnitParams[0]); |
| 91 |
m_encodeCtx->ppNALUnitParams[0] = nullptr; |
| 92 |
} |
| 93 |
|
| 94 |
MOS_FreeMemory(m_encodeCtx->ppNALUnitParams); |
| 95 |
m_encodeCtx->ppNALUnitParams = nullptr; |
| 96 |
} |
| 97 |
|
| 98 |
VAStatus DdiEncodeAV1::ContextInitialize( |
| 99 |
CodechalSetting *codecHalSettings) |
| 100 |
{ |
| 101 |
DDI_CHK_NULL(m_encodeCtx, "nullptr m_encodeCtx.", VA_STATUS_ERROR_INVALID_CONTEXT); |
| 102 |
DDI_CHK_NULL(m_encodeCtx->pCpDdiInterface, "nullptr m_encodeCtx->pCpDdiInterface.", VA_STATUS_ERROR_INVALID_CONTEXT); |
| 103 |
DDI_CHK_NULL(codecHalSettings, "nullptr codecHalSettings.", VA_STATUS_ERROR_INVALID_CONTEXT); |
| 104 |
|
| 105 |
codecHalSettings->codecFunction = m_encodeCtx->codecFunction; |
| 106 |
codecHalSettings->width = m_encodeCtx->dworiFrameWidth; |
| 107 |
codecHalSettings->height = m_encodeCtx->dworiFrameHeight; |
| 108 |
codecHalSettings->mode = m_encodeCtx->wModeType; |
| 109 |
codecHalSettings->standard = CODECHAL_AV1; |
| 110 |
codecHalSettings->chromaFormat = AVP_CHROMA_FORMAT_YUV420; |
| 111 |
codecHalSettings->lumaChromaDepth = CODECHAL_LUMA_CHROMA_DEPTH_10_BITS; |
| 112 |
|
| 113 |
VAStatus eStatus = VA_STATUS_SUCCESS; |
| 114 |
|
| 115 |
// Allocate sequence params |
| 116 |
m_encodeCtx->pSeqParams = (void *)MOS_AllocAndZeroMemory(sizeof(CODEC_AV1_ENCODE_SEQUENCE_PARAMS)); |
| 117 |
DDI_CHK_NULL(m_encodeCtx->pSeqParams, "nullptr m_encodeCtx->pSeqParams.", VA_STATUS_ERROR_ALLOCATION_FAILED); |
| 118 |
|
| 119 |
// Allocate picture params |
| 120 |
m_encodeCtx->pPicParams = (void *)MOS_AllocAndZeroMemory(sizeof(CODEC_AV1_ENCODE_PICTURE_PARAMS)); |
| 121 |
DDI_CHK_NULL(m_encodeCtx->pPicParams, "nullptr m_encodeCtx->pPicParams.", VA_STATUS_ERROR_ALLOCATION_FAILED); |
| 122 |
|
| 123 |
// Allocate slice params |
| 124 |
m_encodeCtx->pSliceParams = (void *)MOS_AllocAndZeroMemory(TILE_GROUP_NUM_INCREMENT * sizeof(CODEC_AV1_ENCODE_TILE_GROUP_PARAMS)); |
| 125 |
DDI_CHK_NULL(m_encodeCtx->pSliceParams, "nullptr m_encodeCtx->pSliceParams.", VA_STATUS_ERROR_ALLOCATION_FAILED); |
| 126 |
allocatedTileNum = TILE_GROUP_NUM_INCREMENT; |
| 127 |
|
| 128 |
// Allocate encode status report |
| 129 |
m_encodeCtx->pEncodeStatusReport = (void *)MOS_AllocAndZeroMemory(CODECHAL_ENCODE_STATUS_NUM*sizeof(EncodeStatusReport)); |
| 130 |
DDI_CHK_NULL(m_encodeCtx->pEncodeStatusReport, "nullptr m_encodeCtx->pEncodeStatusReport.", VA_STATUS_ERROR_ALLOCATION_FAILED); |
| 131 |
|
| 132 |
//Allocate Slice Header Data |
| 133 |
m_encodeCtx->pSliceHeaderData = (CODEC_ENCODER_SLCDATA *)MOS_AllocAndZeroMemory(ENCODE_VDENC_AV1_MAX_TILE_GROUP_NUM * sizeof(CODEC_ENCODER_SLCDATA)); |
| 134 |
DDI_CHK_NULL(m_encodeCtx->pSliceHeaderData, "nullptr m_encodeCtx->pSliceHeaderData.", VA_STATUS_ERROR_ALLOCATION_FAILED); |
| 135 |
|
| 136 |
// Create the bit stream buffer to hold the packed headers from application |
| 137 |
m_encodeCtx->pbsBuffer = (PBSBuffer)MOS_AllocAndZeroMemory(sizeof(BSBuffer)); |
| 138 |
DDI_CHK_NULL(m_encodeCtx->pbsBuffer, "nullptr m_encodeCtx->pbsBuffer.", VA_STATUS_ERROR_ALLOCATION_FAILED); |
| 139 |
|
| 140 |
m_encodeCtx->pbsBuffer->BufferSize = CODECHAL_AV1_FRAME_HEADER_SIZE; |
| 141 |
m_encodeCtx->pbsBuffer->pBase = (uint8_t *)MOS_AllocAndZeroMemory(m_encodeCtx->pbsBuffer->BufferSize); |
| 142 |
DDI_CHK_NULL(m_encodeCtx->pbsBuffer, "nullptr m_encodeCtx->pbsBuffer.", VA_STATUS_ERROR_ALLOCATION_FAILED); |
| 143 |
m_encodeCtx->pbsBuffer->pCurrent = m_encodeCtx->pbsBuffer->pBase; |
| 144 |
|
| 145 |
// Allocate NAL unit params |
| 146 |
m_encodeCtx->ppNALUnitParams = (PCODECHAL_NAL_UNIT_PARAMS *)MOS_AllocAndZeroMemory(sizeof(PCODECHAL_NAL_UNIT_PARAMS)*MAX_NUM_OBU_TYPES); |
| 147 |
DDI_CHK_NULL(m_encodeCtx->ppNALUnitParams, "nullptr m_encodeCtx->ppNALUnitParams", VA_STATUS_ERROR_ALLOCATION_FAILED); |
| 148 |
|
| 149 |
PCODECHAL_NAL_UNIT_PARAMS nalUnitParams = (CODECHAL_NAL_UNIT_PARAMS *)MOS_AllocAndZeroMemory(sizeof(CODECHAL_NAL_UNIT_PARAMS)*MAX_NUM_OBU_TYPES); |
| 150 |
DDI_CHK_NULL(nalUnitParams, "nullptr nalUnitParams.", VA_STATUS_ERROR_ALLOCATION_FAILED); |
| 151 |
|
| 152 |
for (uint32_t i = 0; i < MAX_NUM_OBU_TYPES; i++) |
| 153 |
{ |
| 154 |
m_encodeCtx->ppNALUnitParams[i] = &(nalUnitParams[i]); |
| 155 |
} |
| 156 |
|
| 157 |
m_cpuFormat = true; |
| 158 |
|
| 159 |
if (Mos_Solo_Extension(m_encodeCtx->pCodecHal->GetOsInterface()->pOsContext)) |
| 160 |
{ |
| 161 |
DDI_CHK_NULL(m_encodeCtx->pCodecHal, "nullptr m_encodeCtx->pCodecHal", VA_STATUS_ERROR_INVALID_CONTEXT); |
| 162 |
DDI_CHK_NULL(m_encodeCtx->pCodecHal, "nullptr m_encodeCtx->pCodecHal->GetOsInterface()", VA_STATUS_ERROR_INVALID_CONTEXT); |
| 163 |
DDI_CHK_NULL(m_encodeCtx->pCodecHal, "nullptr (m_encodeCtx->pCodecHal->GetOsInterface()->pOsContext", VA_STATUS_ERROR_INVALID_CONTEXT); |
| 164 |
DDI_CHK_NULL(m_encodeCtx->pMediaCtx, "nullptr pMediaCtx", VA_STATUS_ERROR_INVALID_CONTEXT); |
| 165 |
Mos_Solo_CreateExtension(ENCODE_MODE_AV1, m_encodeCtx->pMediaCtx->platform.eProductFamily, m_encodeCtx->pCodecHal->GetOsInterface()->pOsContext); |
| 166 |
} |
| 167 |
|
| 168 |
|
| 169 |
return eStatus; |
| 170 |
} |
| 171 |
|
| 172 |
VAStatus DdiEncodeAV1::RenderPicture( |
| 173 |
VADriverContextP ctx, |
| 174 |
VAContextID context, |
| 175 |
VABufferID *buffers, |
| 176 |
int32_t numBuffers) |
| 177 |
{ |
| 178 |
VAStatus vaStatus = VA_STATUS_SUCCESS; |
| 179 |
|
| 180 |
DDI_FUNCTION_ENTER(); |
| 181 |
|
| 182 |
DDI_CHK_NULL(ctx, "nullptr ctx", VA_STATUS_ERROR_INVALID_CONTEXT); |
| 183 |
|
| 184 |
DDI_MEDIA_CONTEXT *mediaCtx = DdiMedia_GetMediaContext(ctx); |
| 185 |
DDI_CHK_NULL(mediaCtx, "nullptr mediaCtx", VA_STATUS_ERROR_INVALID_CONTEXT); |
| 186 |
|
| 187 |
DDI_CHK_NULL(m_encodeCtx, "nullptr m_encodeCtx", VA_STATUS_ERROR_INVALID_CONTEXT); |
| 188 |
DDI_CHK_NULL(buffers, "nullptr buffers", VA_STATUS_ERROR_INVALID_BUFFER); |
| 189 |
for (int32_t i = 0; i < numBuffers; i++) |
| 190 |
{ |
| 191 |
DDI_MEDIA_BUFFER *buf = DdiMedia_GetBufferFromVABufferID(mediaCtx, buffers[i]); |
| 192 |
DDI_CHK_NULL(buf, "Invalid buffer.", VA_STATUS_ERROR_INVALID_BUFFER); |
| 193 |
if (buf->uiType == VAEncMacroblockDisableSkipMapBufferType) |
| 194 |
{ |
| 195 |
DdiMedia_MediaBufferToMosResource(buf, &(m_encodeCtx->resPerMBSkipMapBuffer)); |
| 196 |
m_encodeCtx->bMbDisableSkipMapEnabled = true; |
| 197 |
continue; |
| 198 |
} |
| 199 |
uint32_t dataSize = buf->iSize; |
| 200 |
//can use internal function instead of DdiMedia_MapBuffer here? |
| 201 |
void *data = nullptr; |
| 202 |
DdiMedia_MapBuffer(ctx, buffers[i], &data); |
| 203 |
|
| 204 |
DDI_CHK_NULL(data, "nullptr data.", VA_STATUS_ERROR_INVALID_BUFFER); |
| 205 |
|
| 206 |
switch (buf->uiType) |
| 207 |
{ |
| 208 |
case VAEncSequenceParameterBufferType: |
| 209 |
{ |
| 210 |
DDI_CHK_STATUS(ParseSeqParams(data), VA_STATUS_ERROR_INVALID_BUFFER); |
| 211 |
m_encodeCtx->bNewSeq = true; |
| 212 |
break; |
| 213 |
} |
| 214 |
case VAEncPictureParameterBufferType: |
| 215 |
{ |
| 216 |
DDI_CHK_STATUS(ParsePicParams(mediaCtx, data), VA_STATUS_ERROR_INVALID_BUFFER); |
| 217 |
DDI_CHK_STATUS( |
| 218 |
AddToStatusReportQueue((void *)m_encodeCtx->resBitstreamBuffer.bo), |
| 219 |
VA_STATUS_ERROR_INVALID_BUFFER); |
| 220 |
break; |
| 221 |
} |
| 222 |
case VAEncSliceParameterBufferType: |
| 223 |
{ |
| 224 |
uint32_t numTiles = buf->uiNumElements; |
| 225 |
DDI_CHK_STATUS(ParseTileGroupParams(data, numTiles), VA_STATUS_ERROR_INVALID_BUFFER); |
| 226 |
break; |
| 227 |
} |
| 228 |
case VAEncPackedHeaderParameterBufferType: |
| 229 |
{ |
| 230 |
DDI_CHK_STATUS(ParsePackedHeaderParams(data), VA_STATUS_ERROR_INVALID_BUFFER); |
| 231 |
break; |
| 232 |
} |
| 233 |
case VAEncPackedHeaderDataBufferType: |
| 234 |
{ |
| 235 |
DDI_CHK_STATUS(ParsePackedHeaderData(data), VA_STATUS_ERROR_INVALID_BUFFER); |
| 236 |
break; |
| 237 |
} |
| 238 |
case VAEncMiscParameterBufferType: |
| 239 |
{ |
| 240 |
DDI_CHK_STATUS(ParseMiscParams(data), VA_STATUS_ERROR_INVALID_BUFFER); |
| 241 |
break; |
| 242 |
} |
| 243 |
case VAEncMacroblockMapBufferType: |
| 244 |
{ |
| 245 |
DDI_CHK_STATUS(ParseSegMapParams(data), VA_STATUS_ERROR_INVALID_BUFFER); |
| 246 |
break; |
| 247 |
} |
| 248 |
default: |
| 249 |
{ |
| 250 |
DDI_ASSERTMESSAGE("not supported buffer type."); |
| 251 |
break; |
| 252 |
} |
| 253 |
} |
| 254 |
DdiMedia_UnmapBuffer(ctx, buffers[i]); |
| 255 |
} |
| 256 |
|
| 257 |
DDI_FUNCTION_EXIT(vaStatus); |
| 258 |
return vaStatus; |
| 259 |
} |
| 260 |
|
| 261 |
VAStatus DdiEncodeAV1::EncodeInCodecHal(uint32_t numSlices) |
| 262 |
{ |
| 263 |
DDI_CHK_NULL(m_encodeCtx, "nullptr m_encodeCtx", VA_STATUS_ERROR_INVALID_CONTEXT); |
| 264 |
DDI_CHK_NULL(m_encodeCtx->pCodecHal, "nullptr m_encodeCtx->pCodecHal", VA_STATUS_ERROR_INVALID_CONTEXT); |
| 265 |
|
| 266 |
PCODEC_AV1_ENCODE_SEQUENCE_PARAMS av1SeqParams = (PCODEC_AV1_ENCODE_SEQUENCE_PARAMS)((uint8_t *)m_encodeCtx->pSeqParams); |
| 267 |
DDI_CHK_NULL(av1SeqParams, "nullptr av1SeqParams", VA_STATUS_ERROR_INVALID_PARAMETER); |
| 268 |
|
| 269 |
DDI_CODEC_RENDER_TARGET_TABLE *rtTbl = &(m_encodeCtx->RTtbl); |
| 270 |
|
| 271 |
EncoderParamsAV1 encodeParams; |
| 272 |
MOS_ZeroMemory(&encodeParams, sizeof(encodeParams)); |
| 273 |
encodeParams.ExecCodecFunction = m_encodeCtx->codecFunction; |
| 274 |
|
| 275 |
/* check whether the target bit rate is initialized for BRC */ |
| 276 |
if ((VA_RC_CBR == m_encodeCtx->uiRCMethod) || |
| 277 |
(VA_RC_VBR == m_encodeCtx->uiRCMethod)) |
| 278 |
{ |
| 279 |
if (av1SeqParams->TargetBitRate[0] == 0) |
| 280 |
{ |
| 281 |
DDI_ASSERTMESSAGE("DDI: No RateControl param for BRC\n!"); |
| 282 |
return VA_STATUS_ERROR_INVALID_PARAMETER; |
| 283 |
} |
| 284 |
} |
| 285 |
|
| 286 |
// Raw Surface |
| 287 |
MOS_SURFACE rawSurface; |
| 288 |
MOS_ZeroMemory(&rawSurface, sizeof(rawSurface)); |
| 289 |
rawSurface.dwOffset = 0; |
| 290 |
|
| 291 |
DdiMedia_MediaSurfaceToMosResource(rtTbl->pCurrentRT, &(rawSurface.OsResource)); |
| 292 |
|
| 293 |
// Recon Surface |
| 294 |
MOS_SURFACE reconSurface; |
| 295 |
MOS_ZeroMemory(&reconSurface, sizeof(reconSurface)); |
| 296 |
reconSurface.dwOffset = 0; |
| 297 |
|
| 298 |
DdiMedia_MediaSurfaceToMosResource(rtTbl->pCurrentReconTarget, &(reconSurface.OsResource)); |
| 299 |
|
| 300 |
// Clear registered recon/ref surface flags |
| 301 |
DDI_CHK_RET(ClearRefList(&m_encodeCtx->RTtbl, true), "ClearRefList failed!"); |
| 302 |
|
| 303 |
// Bitsream surface |
| 304 |
MOS_RESOURCE bitstreamSurface; |
| 305 |
MOS_ZeroMemory(&bitstreamSurface, sizeof(bitstreamSurface)); |
| 306 |
bitstreamSurface = m_encodeCtx->resBitstreamBuffer; |
| 307 |
bitstreamSurface.Format = Format_Buffer; |
| 308 |
|
| 309 |
encodeParams.psRawSurface = &rawSurface; |
| 310 |
encodeParams.psReconSurface = &reconSurface; |
| 311 |
encodeParams.presBitstreamBuffer = &bitstreamSurface; |
| 312 |
|
| 313 |
// Segmentation map won't be sent for each frame, so need to reset params before each frame. |
| 314 |
encodeParams.pSegmentMap = nullptr; |
| 315 |
encodeParams.bSegmentMapProvided = false; |
| 316 |
|
| 317 |
if (m_isSegParamsChanged) |
| 318 |
{ |
| 319 |
encodeParams.pSegmentMap = m_encodeCtx->pSegmentMap; |
| 320 |
encodeParams.segmentMapDataSize = m_encodeCtx->segmentMapDataSize; |
| 321 |
encodeParams.bSegmentMapProvided = true; |
| 322 |
m_isSegParamsChanged = false; |
| 323 |
} |
| 324 |
|
| 325 |
if (m_encodeCtx->bNewSeq) |
| 326 |
{ |
| 327 |
av1SeqParams->TargetUsage = m_encodeCtx->targetUsage; |
| 328 |
} |
| 329 |
|
| 330 |
encodeParams.pSeqParams = m_encodeCtx->pSeqParams; |
| 331 |
encodeParams.pPicParams = m_encodeCtx->pPicParams; |
| 332 |
encodeParams.pSliceParams = m_encodeCtx->pSliceParams; |
| 333 |
encodeParams.ppNALUnitParams = m_encodeCtx->ppNALUnitParams; |
| 334 |
encodeParams.uiNumNalUnits = m_encodeCtx->indexNALUnit; |
| 335 |
|
| 336 |
// Sequence data |
| 337 |
encodeParams.bNewSeq = m_encodeCtx->bNewSeq; |
| 338 |
if (av1SeqParams->SeqFlags.fields.ResetBRC) |
| 339 |
{ |
| 340 |
/* When the BRC needs to be reset, it indicates that the new Seq is issued. */ |
| 341 |
encodeParams.bNewSeq = true; |
| 342 |
} |
| 343 |
|
| 344 |
// Tile level data |
| 345 |
encodeParams.dwNumSlices = numSlices; |
| 346 |
|
| 347 |
for (uint32_t i = 0; i < (av1SeqParams->NumTemporalLayersMinus1 + 1); i++) |
| 348 |
{ |
| 349 |
if (savedFrameRate[i] == 0) |
| 350 |
{ |
| 351 |
/* use the default framerate if FrameRate is not passed */ |
| 352 |
av1SeqParams->FrameRate[i].Numerator = 30; |
| 353 |
av1SeqParams->FrameRate[i].Denominator = 1; |
| 354 |
} |
| 355 |
} |
| 356 |
|
| 357 |
encodeParams.pSlcHeaderData = (void *)m_encodeCtx->pSliceHeaderData; |
| 358 |
encodeParams.pBSBuffer = m_encodeCtx->pbsBuffer; |
| 359 |
|
| 360 |
MOS_STATUS status = m_encodeCtx->pCodecHal->Execute(&encodeParams); |
| 361 |
if (MOS_STATUS_SUCCESS != status) |
| 362 |
{ |
| 363 |
DDI_ASSERTMESSAGE("DDI:Failed in Codechal!"); |
| 364 |
return VA_STATUS_ERROR_ENCODING_ERROR; |
| 365 |
} |
| 366 |
|
| 367 |
return VA_STATUS_SUCCESS; |
| 368 |
} |
| 369 |
|
| 370 |
// Reset the parameters before each frame |
| 371 |
VAStatus DdiEncodeAV1::ResetAtFrameLevel() |
| 372 |
{ |
| 373 |
DDI_CHK_NULL(m_encodeCtx, "nullptr m_encodeCtx", VA_STATUS_ERROR_INVALID_PARAMETER); |
| 374 |
|
| 375 |
PCODEC_AV1_ENCODE_SEQUENCE_PARAMS av1SeqParams = (PCODEC_AV1_ENCODE_SEQUENCE_PARAMS)((uint8_t *)m_encodeCtx->pSeqParams); |
| 376 |
DDI_CHK_NULL(av1SeqParams, "nullptr av1SeqParams", VA_STATUS_ERROR_INVALID_PARAMETER); |
| 377 |
av1SeqParams->SeqFlags.fields.ResetBRC = 0; |
| 378 |
|
| 379 |
m_encodeCtx->dwNumSlices = 0; |
| 380 |
m_encodeCtx->bNewSeq = false; |
| 381 |
|
| 382 |
// reset bsbuffer every frame |
| 383 |
PBSBuffer pBSBuffer = m_encodeCtx->pbsBuffer; |
| 384 |
DDI_CHK_NULL(pBSBuffer, "nullptr bsBuffer.", VA_STATUS_ERROR_INVALID_PARAMETER); |
| 385 |
|
| 386 |
*(pBSBuffer->pBase) = 0; //init first byte to 0 |
| 387 |
pBSBuffer->pCurrent = pBSBuffer->pBase; |
| 388 |
pBSBuffer->SliceOffset = 0; |
| 389 |
pBSBuffer->BitOffset = 0; |
| 390 |
pBSBuffer->BitSize = 0; |
| 391 |
|
| 392 |
// clear the packed header information |
| 393 |
if (nullptr != m_encodeCtx->ppNALUnitParams) |
| 394 |
{ |
| 395 |
MOS_ZeroMemory(m_encodeCtx->ppNALUnitParams[0], sizeof(CODECHAL_NAL_UNIT_PARAMS)*(m_encodeCtx->indexNALUnit)); |
| 396 |
} |
| 397 |
m_encodeCtx->indexNALUnit = 0; |
| 398 |
|
| 399 |
return VA_STATUS_SUCCESS; |
| 400 |
} |
| 401 |
|
| 402 |
VAStatus DdiEncodeAV1::ParseSeqParams(void *ptr) |
| 403 |
{ |
| 404 |
DDI_CHK_NULL(m_encodeCtx, "nullptr m_encodeCtx", VA_STATUS_ERROR_INVALID_PARAMETER); |
| 405 |
DDI_CHK_NULL(ptr, "nullptr ptr", VA_STATUS_ERROR_INVALID_PARAMETER); |
| 406 |
|
| 407 |
VAEncSequenceParameterBufferAV1 *seqParams = (VAEncSequenceParameterBufferAV1 *)ptr; |
| 408 |
|
| 409 |
PCODEC_AV1_ENCODE_SEQUENCE_PARAMS av1SeqParams = (PCODEC_AV1_ENCODE_SEQUENCE_PARAMS)(m_encodeCtx->pSeqParams); |
| 410 |
DDI_CHK_NULL(av1SeqParams, "nullptr av1SeqParams", VA_STATUS_ERROR_INVALID_PARAMETER); |
| 411 |
|
| 412 |
av1SeqParams->seq_profile = seqParams->seq_profile; |
| 413 |
av1SeqParams->seq_level_idx = seqParams->seq_level_idx; |
| 414 |
av1SeqParams->GopPicSize = seqParams->intra_period; |
| 415 |
av1SeqParams->GopRefDist = seqParams->ip_period; |
| 416 |
|
| 417 |
switch ((uint32_t)m_encodeCtx->uiRCMethod) |
| 418 |
{ |
| 419 |
case VA_RC_TCBRC: |
| 420 |
case VA_RC_VBR: |
| 421 |
av1SeqParams->RateControlMethod = (uint8_t)RATECONTROL_VBR; |
| 422 |
break; |
| 423 |
case VA_RC_CQP: |
| 424 |
av1SeqParams->RateControlMethod = (uint8_t)RATECONTROL_CQP; |
| 425 |
break; |
| 426 |
case VA_RC_ICQ: |
| 427 |
av1SeqParams->RateControlMethod = (uint8_t)RATECONTROL_CQL; |
| 428 |
break; |
| 429 |
default: |
| 430 |
av1SeqParams->RateControlMethod = (uint8_t)RATECONTROL_CBR; |
| 431 |
} |
| 432 |
|
| 433 |
/* the bits_per_second is only used when the target bit_rate is not initialized */ |
| 434 |
if (av1SeqParams->TargetBitRate[0] == 0) |
| 435 |
{ |
| 436 |
av1SeqParams->TargetBitRate[0] = MOS_ROUNDUP_DIVIDE(seqParams->bits_per_second, CODECHAL_ENCODE_BRC_KBPS); |
| 437 |
} |
| 438 |
av1SeqParams->MaxBitRate = MOS_ROUNDUP_DIVIDE(seqParams->bits_per_second, CODECHAL_ENCODE_BRC_KBPS); |
| 439 |
av1SeqParams->MinBitRate = MOS_ROUNDUP_DIVIDE(seqParams->bits_per_second, CODECHAL_ENCODE_BRC_KBPS); |
| 440 |
|
| 441 |
//set default same as application, can be overwritten by misc params |
| 442 |
av1SeqParams->InitVBVBufferFullnessInBit = seqParams->bits_per_second; |
| 443 |
av1SeqParams->VBVBufferSizeInBit = seqParams->bits_per_second << 1; |
| 444 |
|
| 445 |
av1SeqParams->CodingToolFlags.fields.enable_order_hint = seqParams->seq_fields.bits.enable_order_hint; |
| 446 |
av1SeqParams->CodingToolFlags.fields.enable_cdef = seqParams->seq_fields.bits.enable_cdef; |
| 447 |
av1SeqParams->CodingToolFlags.fields.enable_warped_motion = seqParams->seq_fields.bits.enable_warped_motion; |
| 448 |
av1SeqParams->CodingToolFlags.fields.enable_restoration = seqParams->seq_fields.bits.enable_restoration; |
| 449 |
|
| 450 |
av1SeqParams->order_hint_bits_minus_1 = seqParams->order_hint_bits_minus_1; |
| 451 |
#if VA_CHECK_VERSION(1, 16, 0) |
| 452 |
av1SeqParams->SeqFlags.fields.HierarchicalFlag = seqParams->hierarchical_flag; |
| 453 |
#else |
| 454 |
av1SeqParams->SeqFlags.fields.HierarchicalFlag = seqParams->reserved8b; |
| 455 |
#endif |
| 456 |
av1SeqParams->SeqFlags.fields.DisplayFormatSwizzle = NeedDisplayFormatSwizzle(m_encodeCtx->RTtbl.pCurrentRT); |
| 457 |
|
| 458 |
return VA_STATUS_SUCCESS; |
| 459 |
} |
| 460 |
|
| 461 |
VAStatus DdiEncodeAV1::ParsePicParams(DDI_MEDIA_CONTEXT *mediaCtx, void *ptr) |
| 462 |
{ |
| 463 |
DDI_CHK_NULL(mediaCtx, "nullptr mediaCtx", VA_STATUS_ERROR_INVALID_PARAMETER); |
| 464 |
DDI_CHK_NULL(ptr, "nullptr ptr", VA_STATUS_ERROR_INVALID_PARAMETER); |
| 465 |
DDI_CHK_NULL(m_encodeCtx, "nullptr m_encodeCtx", VA_STATUS_ERROR_INVALID_PARAMETER); |
| 466 |
|
| 467 |
VAEncPictureParameterBufferAV1 *picParams = (VAEncPictureParameterBufferAV1 *)ptr; |
| 468 |
|
| 469 |
PCODEC_AV1_ENCODE_PICTURE_PARAMS av1PicParams = (PCODEC_AV1_ENCODE_PICTURE_PARAMS)(m_encodeCtx->pPicParams); |
| 470 |
DDI_CHK_NULL(av1PicParams, "nullptr av1PicParams", VA_STATUS_ERROR_INVALID_PARAMETER); |
| 471 |
MOS_ZeroMemory(av1PicParams, sizeof(CODEC_AV1_ENCODE_PICTURE_PARAMS)); |
| 472 |
|
| 473 |
av1PicParams->frame_width_minus1 = picParams->frame_width_minus_1; |
| 474 |
av1PicParams->frame_height_minus1 = picParams->frame_height_minus_1; |
| 475 |
av1PicParams->NumTileGroupsMinus1 = picParams->num_tile_groups_minus1; |
| 476 |
av1PicParams->PicFlags.fields.EnableFrameOBU = picParams->picture_flags.bits.enable_frame_obu; |
| 477 |
|
| 478 |
av1PicParams->LoopRestorationFlags.fields.yframe_restoration_type = picParams->loop_restoration_flags.bits.yframe_restoration_type; |
| 479 |
av1PicParams->LoopRestorationFlags.fields.cbframe_restoration_type = picParams->loop_restoration_flags.bits.cbframe_restoration_type; |
| 480 |
av1PicParams->LoopRestorationFlags.fields.crframe_restoration_type = picParams->loop_restoration_flags.bits.crframe_restoration_type; |
| 481 |
av1PicParams->LoopRestorationFlags.fields.lr_unit_shift = picParams->loop_restoration_flags.bits.lr_unit_shift; |
| 482 |
av1PicParams->LoopRestorationFlags.fields.lr_uv_shift = picParams->loop_restoration_flags.bits.lr_uv_shift; |
| 483 |
|
| 484 |
if (picParams->num_tile_groups_minus1 > 0 && picParams->picture_flags.bits.enable_frame_obu) |
| 485 |
{ |
| 486 |
return VA_STATUS_ERROR_INVALID_PARAMETER; |
| 487 |
} |
| 488 |
|
| 489 |
DDI_CODEC_RENDER_TARGET_TABLE *rtTbl = &(m_encodeCtx->RTtbl); |
| 490 |
|
| 491 |
DDI_MEDIA_SURFACE *recon = DdiMedia_GetSurfaceFromVASurfaceID(mediaCtx, picParams->reconstructed_frame); |
| 492 |
|
| 493 |
DDI_CHK_RET(RegisterRTSurfaces(rtTbl, recon), "RegisterRTSurfaces failed"); |
| 494 |
|
| 495 |
SetupCodecPicture( |
| 496 |
mediaCtx, |
| 497 |
rtTbl, |
| 498 |
&av1PicParams->CurrReconstructedPic, |
| 499 |
picParams->reconstructed_frame, |
| 500 |
false); |
| 501 |
|
| 502 |
rtTbl->pCurrentReconTarget = recon; |
| 503 |
DDI_CHK_NULL(rtTbl->pCurrentReconTarget, "NULL rtTbl->pCurrentReconTarget", VA_STATUS_ERROR_INVALID_PARAMETER); |
| 504 |
|
| 505 |
// curr origin pic |
| 506 |
av1PicParams->CurrOriginalPic.FrameIdx = (uint8_t)GetRenderTargetID(rtTbl, rtTbl->pCurrentReconTarget); |
| 507 |
av1PicParams->CurrOriginalPic.PicFlags = av1PicParams->CurrReconstructedPic.PicFlags; |
| 508 |
av1PicParams->CurrOriginalPic.PicEntry = av1PicParams->CurrReconstructedPic.PicEntry; |
| 509 |
|
| 510 |
// RefFrame List |
| 511 |
for (uint32_t i = 0; i < 8; i++) |
| 512 |
{ |
| 513 |
if (picParams->reference_frames[i] != VA_INVALID_SURFACE) |
| 514 |
{ |
| 515 |
UpdateRegisteredRTSurfaceFlag(rtTbl, DdiMedia_GetSurfaceFromVASurfaceID(mediaCtx, picParams->reference_frames[i])); |
| 516 |
} |
| 517 |
SetupCodecPicture( |
| 518 |
mediaCtx, |
| 519 |
rtTbl, |
| 520 |
&av1PicParams->RefFrameList[i], |
| 521 |
picParams->reference_frames[i], |
| 522 |
true); |
| 523 |
} |
| 524 |
|
| 525 |
// bitstream buffer |
| 526 |
DDI_MEDIA_BUFFER *buf = DdiMedia_GetBufferFromVABufferID(mediaCtx, picParams->coded_buf); |
| 527 |
DDI_CHK_NULL(buf, "nullptr buf", VA_STATUS_ERROR_INVALID_PARAMETER); |
| 528 |
RemoveFromStatusReportQueue(buf); |
| 529 |
DdiMedia_MediaBufferToMosResource(buf, &(m_encodeCtx->resBitstreamBuffer)); |
| 530 |
|
| 531 |
//reference frame index |
| 532 |
DDI_CHK_RET( |
| 533 |
MOS_SecureMemcpy(av1PicParams->ref_frame_idx, |
| 534 |
sizeof(av1PicParams->ref_frame_idx), |
| 535 |
picParams->ref_frame_idx, |
| 536 |
sizeof(picParams->ref_frame_idx)), |
| 537 |
"DDI: PicParams parsing failed!"); |
| 538 |
|
| 539 |
if ((picParams->picture_flags.bits.frame_type == intraOnlyFrame || picParams->picture_flags.bits.frame_type == keyFrame) && |
| 540 |
picParams->primary_ref_frame != av1PrimaryRefNone) |
| 541 |
{ |
| 542 |
return VA_STATUS_ERROR_INVALID_PARAMETER; |
| 543 |
} |
| 544 |
|
| 545 |
av1PicParams->primary_ref_frame = picParams->primary_ref_frame; |
| 546 |
av1PicParams->order_hint = picParams->order_hint; |
| 547 |
|
| 548 |
av1PicParams->ref_frame_ctrl_l0.RefFrameCtrl.value = picParams->ref_frame_ctrl_l0.value; |
| 549 |
av1PicParams->ref_frame_ctrl_l1.RefFrameCtrl.value = picParams->ref_frame_ctrl_l1.value; |
| 550 |
|
| 551 |
if (picParams->picture_flags.bits.frame_type == sFrame && picParams->picture_flags.bits.error_resilient_mode != 1) |
| 552 |
{ |
| 553 |
return VA_STATUS_ERROR_INVALID_PARAMETER; |
| 554 |
} |
| 555 |
|
| 556 |
// picture flags |
| 557 |
av1PicParams->PicFlags.fields.frame_type = picParams->picture_flags.bits.frame_type; |
| 558 |
av1PicParams->PicFlags.fields.error_resilient_mode = picParams->picture_flags.bits.error_resilient_mode; |
| 559 |
av1PicParams->PicFlags.fields.disable_cdf_update = picParams->picture_flags.bits.disable_cdf_update; |
| 560 |
av1PicParams->PicFlags.fields.allow_high_precision_mv = picParams->picture_flags.bits.allow_high_precision_mv; |
| 561 |
av1PicParams->PicFlags.fields.use_ref_frame_mvs = picParams->picture_flags.bits.use_ref_frame_mvs; |
| 562 |
av1PicParams->PicFlags.fields.disable_frame_end_update_cdf = picParams->picture_flags.bits.disable_frame_end_update_cdf; |
| 563 |
av1PicParams->PicFlags.fields.reduced_tx_set_used = picParams->picture_flags.bits.reduced_tx_set; |
| 564 |
av1PicParams->PicFlags.fields.EnableFrameOBU = picParams->picture_flags.bits.enable_frame_obu; |
| 565 |
av1PicParams->PicFlags.fields.LongTermReference = picParams->picture_flags.bits.long_term_reference; |
| 566 |
av1PicParams->PicFlags.fields.DisableFrameRecon = picParams->picture_flags.bits.disable_frame_recon; |
| 567 |
av1PicParams->PicFlags.fields.PaletteModeEnable = picParams->picture_flags.bits.palette_mode_enable; |
| 568 |
av1PicParams->PicFlags.fields.SegIdBlockSize = picParams->seg_id_block_size; |
| 569 |
|
| 570 |
#if VA_CHECK_VERSION(1, 16, 0) |
| 571 |
av1PicParams->HierarchLevelPlus1 = picParams->hierarchical_level_plus1; |
| 572 |
#else |
| 573 |
av1PicParams->HierarchLevelPlus1 = picParams->reserved8bits0; |
| 574 |
#endif |
| 575 |
|
| 576 |
DDI_CHK_RET( |
| 577 |
MOS_SecureMemcpy(av1PicParams->filter_level, |
| 578 |
sizeof(av1PicParams->filter_level), |
| 579 |
picParams->filter_level, |
| 580 |
sizeof(picParams->filter_level)), |
| 581 |
"DDI: PicParams parsing failed!"); |
| 582 |
|
| 583 |
av1PicParams->filter_level_u = picParams->filter_level_u; |
| 584 |
av1PicParams->filter_level_v = picParams->filter_level_v; |
| 585 |
|
| 586 |
av1PicParams->cLoopFilterInfoFlags.value = picParams->loop_filter_flags.value; |
| 587 |
av1PicParams->interp_filter = picParams->interpolation_filter; |
| 588 |
|
| 589 |
DDI_CHK_RET( |
| 590 |
MOS_SecureMemcpy(av1PicParams->ref_deltas, |
| 591 |
sizeof(av1PicParams->ref_deltas), |
| 592 |
picParams->ref_deltas, |
| 593 |
sizeof(picParams->ref_deltas)), |
| 594 |
"DDI: PicParams parsing failed!"); |
| 595 |
|
| 596 |
DDI_CHK_RET( |
| 597 |
MOS_SecureMemcpy(av1PicParams->mode_deltas, |
| 598 |
sizeof(av1PicParams->mode_deltas), |
| 599 |
picParams->mode_deltas, |
| 600 |
sizeof(picParams->mode_deltas)), |
| 601 |
"DDI: PicParams parsing failed!"); |
| 602 |
|
| 603 |
if (abs(picParams->y_dc_delta_q) > 15) |
| 604 |
{ |
| 605 |
return VA_STATUS_ERROR_INVALID_PARAMETER; |
| 606 |
} |
| 607 |
|
| 608 |
av1PicParams->base_qindex = picParams->base_qindex; |
| 609 |
av1PicParams->y_dc_delta_q = picParams->y_dc_delta_q; |
| 610 |
av1PicParams->u_dc_delta_q = picParams->u_dc_delta_q; |
| 611 |
av1PicParams->u_ac_delta_q = picParams->u_ac_delta_q; |
| 612 |
av1PicParams->v_dc_delta_q = picParams->v_dc_delta_q; |
| 613 |
av1PicParams->v_ac_delta_q = picParams->v_ac_delta_q; |
| 614 |
av1PicParams->MinBaseQIndex = picParams->min_base_qindex; |
| 615 |
av1PicParams->MaxBaseQIndex = picParams->max_base_qindex; |
| 616 |
|
| 617 |
// Quatization Matrix is not supportted |
| 618 |
if (picParams->qmatrix_flags.bits.using_qmatrix != 0) |
| 619 |
{ |
| 620 |
DDI_ASSERTMESSAGE("Invalid Parameter for Parsing AV1 Picture parameter"); |
| 621 |
return VA_STATUS_ERROR_INVALID_PARAMETER; |
| 622 |
} |
| 623 |
|
| 624 |
av1PicParams->wQMatrixFlags.value = picParams->qmatrix_flags.value; |
| 625 |
|
| 626 |
av1PicParams->dwModeControlFlags.value = picParams->mode_control_flags.value; |
| 627 |
|
| 628 |
//segment params |
| 629 |
av1PicParams->stAV1Segments.SegmentFlags.fields.segmentation_enabled = picParams->segments.seg_flags.bits.segmentation_enabled; |
| 630 |
av1PicParams->stAV1Segments.SegmentFlags.fields.SegmentNumber = picParams->segments.segment_number; |
| 631 |
av1PicParams->stAV1Segments.SegmentFlags.fields.update_map = picParams->segments.seg_flags.bits.segmentation_update_map; |
| 632 |
av1PicParams->stAV1Segments.SegmentFlags.fields.temporal_update = picParams->segments.seg_flags.bits.segmentation_temporal_update; |
| 633 |
|
| 634 |
DDI_CHK_RET( |
| 635 |
MOS_SecureMemcpy(av1PicParams->stAV1Segments.feature_data, |
| 636 |
sizeof(av1PicParams->stAV1Segments.feature_data), |
| 637 |
picParams->segments.feature_data, |
| 638 |
sizeof(picParams->segments.feature_data)), |
| 639 |
"DDI: PicParams parsing failed!"); |
| 640 |
|
| 641 |
DDI_CHK_RET( |
| 642 |
MOS_SecureMemcpy(av1PicParams->stAV1Segments.feature_mask, |
| 643 |
sizeof(av1PicParams->stAV1Segments.feature_mask), |
| 644 |
picParams->segments.feature_mask, |
| 645 |
sizeof(picParams->segments.feature_mask)), |
| 646 |
"DDI: PicParams parsing failed!"); |
| 647 |
|
| 648 |
av1PicParams->tile_cols = picParams->tile_cols; |
| 649 |
|
| 650 |
DDI_CHK_RET( |
| 651 |
MOS_SecureMemcpy(av1PicParams->width_in_sbs_minus_1, |
| 652 |
sizeof(av1PicParams->width_in_sbs_minus_1), |
| 653 |
picParams->width_in_sbs_minus_1, |
| 654 |
sizeof(picParams->width_in_sbs_minus_1)), |
| 655 |
"DDI: PicParams parsing failed!"); |
| 656 |
|
| 657 |
av1PicParams->tile_rows = picParams->tile_rows; |
| 658 |
|
| 659 |
DDI_CHK_RET( |
| 660 |
MOS_SecureMemcpy(av1PicParams->height_in_sbs_minus_1, |
| 661 |
sizeof(av1PicParams->height_in_sbs_minus_1), |
| 662 |
picParams->height_in_sbs_minus_1, |
| 663 |
sizeof(picParams->height_in_sbs_minus_1)), |
| 664 |
"DDI: PicParams parsing failed!"); |
| 665 |
|
| 666 |
DDI_CHK_RET(CheckCDEF(picParams, mediaCtx->platform.eProductFamily), "invalid CDEF Paramter"); |
| 667 |
|
| 668 |
DDI_CHK_RET(CheckTile(picParams), "invalid Tile Paramter"); |
| 669 |
|
| 670 |
av1PicParams->context_update_tile_id = picParams->context_update_tile_id; |
| 671 |
av1PicParams->temporal_id = picParams->temporal_id; |
| 672 |
|
| 673 |
av1PicParams->cdef_damping_minus_3 = picParams->cdef_damping_minus_3; |
| 674 |
av1PicParams->cdef_bits = picParams->cdef_bits; |
| 675 |
|
| 676 |
DDI_CHK_RET( |
| 677 |
MOS_SecureMemcpy(av1PicParams->cdef_y_strengths, |
| 678 |
sizeof(av1PicParams->cdef_y_strengths), |
| 679 |
picParams->cdef_y_strengths, |
| 680 |
sizeof(picParams->cdef_y_strengths)), |
| 681 |
"DDI: PicParams parsing failed!"); |
| 682 |
|
| 683 |
DDI_CHK_RET( |
| 684 |
MOS_SecureMemcpy(av1PicParams->cdef_uv_strengths, |
| 685 |
sizeof(av1PicParams->cdef_uv_strengths), |
| 686 |
picParams->cdef_uv_strengths, |
| 687 |
sizeof(picParams->cdef_uv_strengths)), |
| 688 |
"DDI: PicParams parsing failed!"); |
| 689 |
|
| 690 |
for(uint32_t i = 0; i < 7; i++) |
| 691 |
{ |
| 692 |
av1PicParams->wm[i].wmtype = picParams->wm[i].wmtype; |
| 693 |
av1PicParams->wm[i].invalid = picParams->wm[i].invalid; |
| 694 |
|
| 695 |
DDI_CHK_RET( |
| 696 |
MOS_SecureMemcpy(av1PicParams->wm[i].wmmat, |
| 697 |
sizeof(av1PicParams->wm[i].wmmat), |
| 698 |
picParams->wm[i].wmmat, |
| 699 |
sizeof(picParams->wm[i].wmmat)), |
| 700 |
"DDI: PicParams parsing failed!"); |
| 701 |
} |
| 702 |
|
| 703 |
av1PicParams->QIndexBitOffset = picParams->bit_offset_qindex; |
| 704 |
av1PicParams->SegmentationBitOffset = picParams->bit_offset_segmentation; |
| 705 |
av1PicParams->LoopFilterParamsBitOffset = picParams->bit_offset_loopfilter_params; |
| 706 |
av1PicParams->CDEFParamsBitOffset = picParams->bit_offset_cdef_params; |
| 707 |
av1PicParams->CDEFParamsSizeInBits = picParams->size_in_bits_cdef_params; |
| 708 |
av1PicParams->FrameHdrOBUSizeByteOffset = picParams->byte_offset_frame_hdr_obu_size; |
| 709 |
av1PicParams->FrameHdrOBUSizeInBits = picParams->size_in_bits_frame_hdr_obu; |
| 710 |
|
| 711 |
av1PicParams->TileGroupOBUHdrInfo.value = picParams->tile_group_obu_hdr_info.value; |
| 712 |
|
| 713 |
av1PicParams->NumSkipFrames = picParams->number_skip_frames; |
| 714 |
av1PicParams->FrameSizeReducedInBytes = 0 - picParams->skip_frames_reduced_size; |
| 715 |
|
| 716 |
return VA_STATUS_SUCCESS; |
| 717 |
} |
| 718 |
|
| 719 |
VAStatus DdiEncodeAV1::ParseTileGroupParams(void *ptr, uint32_t numTileGroupParams) |
| 720 |
{ |
| 721 |
DDI_CHK_NULL(m_encodeCtx, "nullptr m_encodeCtx", VA_STATUS_ERROR_INVALID_PARAMETER); |
| 722 |
DDI_CHK_NULL(ptr, "nullptr ptr", VA_STATUS_ERROR_INVALID_PARAMETER); |
| 723 |
|
| 724 |
VAEncTileGroupBufferAV1 *vaEncTileGroupParams = (VAEncTileGroupBufferAV1 *)ptr; |
| 725 |
|
| 726 |
PCODEC_AV1_ENCODE_TILE_GROUP_PARAMS av1TileGroupParams = (PCODEC_AV1_ENCODE_TILE_GROUP_PARAMS)m_encodeCtx->pSliceParams; |
| 727 |
DDI_CHK_NULL(av1TileGroupParams, "nullptr av1TileGroup", VA_STATUS_ERROR_INVALID_PARAMETER); |
| 728 |
|
| 729 |
if (m_encodeCtx->dwNumSlices + numTileGroupParams > allocatedTileNum) |
| 730 |
{ |
| 731 |
av1TileGroupParams = (PCODEC_AV1_ENCODE_TILE_GROUP_PARAMS)MOS_ReallocMemory(av1TileGroupParams, |
| 732 |
(m_encodeCtx->dwNumSlices + numTileGroupParams + TILE_GROUP_NUM_INCREMENT)*sizeof(CODEC_AV1_ENCODE_TILE_GROUP_PARAMS)); |
| 733 |
DDI_CHK_NULL(av1TileGroupParams, "nullptr av1TileGroupParams", VA_STATUS_ERROR_INVALID_PARAMETER); |
| 734 |
|
| 735 |
allocatedTileNum = m_encodeCtx->dwNumSlices + numTileGroupParams + TILE_GROUP_NUM_INCREMENT; |
| 736 |
m_encodeCtx->pSliceParams = (void *)av1TileGroupParams; |
| 737 |
} |
| 738 |
|
| 739 |
av1TileGroupParams += m_encodeCtx->dwNumSlices; |
| 740 |
MOS_ZeroMemory(av1TileGroupParams, (numTileGroupParams*sizeof(CODEC_AV1_ENCODE_TILE_GROUP_PARAMS))); |
| 741 |
|
| 742 |
for (uint32_t i = 0; i < numTileGroupParams; i++) |
| 743 |
{ |
| 744 |
av1TileGroupParams->TileGroupStart = vaEncTileGroupParams->tg_start; |
| 745 |
av1TileGroupParams->TileGroupEnd = vaEncTileGroupParams->tg_end; |
| 746 |
av1TileGroupParams++; |
| 747 |
vaEncTileGroupParams++; |
| 748 |
} |
| 749 |
|
| 750 |
m_encodeCtx->dwNumSlices += numTileGroupParams; |
| 751 |
|
| 752 |
return VA_STATUS_SUCCESS; |
| 753 |
} |
| 754 |
|
| 755 |
VAStatus DdiEncodeAV1::ParsePackedHeaderParams(void *ptr) |
| 756 |
{ |
| 757 |
DDI_CHK_NULL(m_encodeCtx, "nullptr m_encodeCtx", VA_STATUS_ERROR_INVALID_PARAMETER); |
| 758 |
DDI_CHK_NULL(ptr, "nullptr ptr", VA_STATUS_ERROR_INVALID_PARAMETER); |
| 759 |
|
| 760 |
VAEncPackedHeaderParameterBuffer *encPackedHeaderParamBuf = (VAEncPackedHeaderParameterBuffer *)ptr; |
| 761 |
|
| 762 |
m_encodeCtx->ppNALUnitParams[m_encodeCtx->indexNALUnit]->bInsertEmulationBytes = (encPackedHeaderParamBuf->has_emulation_bytes) ? false : true; |
| 763 |
m_encodeCtx->ppNALUnitParams[m_encodeCtx->indexNALUnit]->uiSkipEmulationCheckCount = 3; |
| 764 |
m_encodeCtx->ppNALUnitParams[m_encodeCtx->indexNALUnit]->uiSize = (encPackedHeaderParamBuf->bit_length + 7) / 8; |
| 765 |
m_encodeCtx->ppNALUnitParams[m_encodeCtx->indexNALUnit]->uiOffset = 0; // will be overwritten later. |
| 766 |
|
| 767 |
return VA_STATUS_SUCCESS; |
| 768 |
} |
| 769 |
|
| 770 |
VAStatus DdiEncodeAV1::ParsePackedHeaderData(void *ptr) |
| 771 |
{ |
| 772 |
DDI_CHK_NULL(m_encodeCtx, "nullptr m_encodeCtx", VA_STATUS_ERROR_INVALID_PARAMETER); |
| 773 |
DDI_CHK_NULL(ptr, "nullptr ptr", VA_STATUS_ERROR_INVALID_PARAMETER); |
| 774 |
|
| 775 |
BSBuffer *bsBuffer = m_encodeCtx->pbsBuffer; |
| 776 |
DDI_CHK_NULL(bsBuffer, "nullptr ptr", VA_STATUS_ERROR_INVALID_PARAMETER); |
| 777 |
|
| 778 |
if (m_encodeCtx->indexNALUnit == 0) |
| 779 |
{ |
| 780 |
bsBuffer->pCurrent = bsBuffer->pBase; |
| 781 |
bsBuffer->SliceOffset = 0; |
| 782 |
bsBuffer->BitOffset = 0; |
| 783 |
bsBuffer->BitSize = 0; |
| 784 |
} |
| 785 |
|
| 786 |
uint32_t hdrDataSize = m_encodeCtx->ppNALUnitParams[m_encodeCtx->indexNALUnit]->uiSize; |
| 787 |
|
| 788 |
DDI_CHK_RET( |
| 789 |
MOS_SecureMemcpy(bsBuffer->pCurrent, bsBuffer->BufferSize - bsBuffer->SliceOffset, (uint8_t *)ptr, hdrDataSize), |
| 790 |
"DDI:packed header size is too large to be supported!"); |
| 791 |
|
| 792 |
m_encodeCtx->ppNALUnitParams[m_encodeCtx->indexNALUnit]->uiOffset = bsBuffer->pCurrent - bsBuffer->pBase; |
| 793 |
m_encodeCtx->indexNALUnit++; |
| 794 |
|
| 795 |
bsBuffer->pCurrent += hdrDataSize; |
| 796 |
bsBuffer->SliceOffset += hdrDataSize; |
| 797 |
|
| 798 |
return VA_STATUS_SUCCESS; |
| 799 |
} |
| 800 |
|
| 801 |
VAStatus DdiEncodeAV1::ParseMiscParams(void *ptr) |
| 802 |
{ |
| 803 |
DDI_CHK_NULL(m_encodeCtx, "nullptr m_enocdeCtx", VA_STATUS_ERROR_INVALID_PARAMETER); |
| 804 |
DDI_CHK_NULL(ptr, "nullptr ptr", VA_STATUS_ERROR_INVALID_PARAMETER); |
| 805 |
|
| 806 |
VAEncMiscParameterBuffer *miscParamBuf = (VAEncMiscParameterBuffer *)ptr; |
| 807 |
DDI_CHK_NULL(miscParamBuf->data, "nullptr miscParamBuf->data", VA_STATUS_ERROR_INVALID_PARAMETER); |
| 808 |
|
| 809 |
VAStatus vaStatus = VA_STATUS_SUCCESS; |
| 810 |
switch ((int32_t)(miscParamBuf->type)) |
| 811 |
{ |
| 812 |
case VAEncMiscParameterTypeHRD: |
| 813 |
{ |
| 814 |
vaStatus = ParseMiscParamVBV((void *)miscParamBuf->data); |
| 815 |
break; |
| 816 |
} |
| 817 |
case VAEncMiscParameterTypeFrameRate: |
| 818 |
{ |
| 819 |
vaStatus = ParseMiscParamFR((void *)miscParamBuf->data); |
| 820 |
break; |
| 821 |
} |
| 822 |
case VAEncMiscParameterTypeRateControl: |
| 823 |
{ |
| 824 |
vaStatus = ParseMiscParamRC((void *)miscParamBuf->data); |
| 825 |
break; |
| 826 |
} |
| 827 |
case VAEncMiscParameterTypeEncQuality: |
| 828 |
{ |
| 829 |
vaStatus = ParseMiscParamEncQuality((void *)miscParamBuf->data); |
| 830 |
break; |
| 831 |
} |
| 832 |
case VAEncMiscParameterTypeTemporalLayerStructure: |
| 833 |
{ |
| 834 |
vaStatus = ParseMiscParamTemporalLayerParams((void *)miscParamBuf->data); |
| 835 |
break; |
| 836 |
} |
| 837 |
case VAEncMiscParameterTypeQualityLevel: |
| 838 |
{ |
| 839 |
vaStatus = ParseMiscParamQualityLevel((void *)miscParamBuf->data); |
| 840 |
break; |
| 841 |
} |
| 842 |
case VAEncMiscParameterTypeMaxFrameSize: |
| 843 |
{ |
| 844 |
vaStatus = ParseMiscParamMaxFrameSize((void *)miscParamBuf->data); |
| 845 |
break; |
| 846 |
} |
| 847 |
default: |
| 848 |
{ |
| 849 |
DDI_ASSERTMESSAGE("DDI: unsupported misc parameter type."); |
| 850 |
return VA_STATUS_ERROR_INVALID_PARAMETER; |
| 851 |
} |
| 852 |
} |
| 853 |
|
| 854 |
return vaStatus; |
| 855 |
} |
| 856 |
|
| 857 |
VAStatus DdiEncodeAV1::ParseSegMapParams(void *ptr) |
| 858 |
{ |
| 859 |
DDI_CHK_NULL(m_encodeCtx, "nullptr m_enocdeCtx", VA_STATUS_ERROR_INVALID_PARAMETER); |
| 860 |
DDI_CHK_NULL(ptr, "nullptr data", VA_STATUS_ERROR_INVALID_PARAMETER); |
| 861 |
|
| 862 |
VAEncSegMapBufferAV1 *vaEncSegMapBuf = (VAEncSegMapBufferAV1 *)ptr; |
| 863 |
m_isSegParamsChanged = true; |
| 864 |
|
| 865 |
m_encodeCtx->segmentMapDataSize = vaEncSegMapBuf->segmentMapDataSize; |
| 866 |
m_encodeCtx->pSegmentMap = vaEncSegMapBuf->pSegmentMap; |
| 867 |
|
| 868 |
return VA_STATUS_SUCCESS; |
| 869 |
} |
| 870 |
|
| 871 |
VAStatus DdiEncodeAV1::ParseMiscParamVBV(void *data) |
| 872 |
{ |
| 873 |
DDI_CHK_NULL(data, "nullptr data", VA_STATUS_ERROR_INVALID_PARAMETER); |
| 874 |
|
| 875 |
VAEncMiscParameterHRD *vaEncMiscParamHRD = (VAEncMiscParameterHRD *)data; |
| 876 |
|
| 877 |
PCODEC_AV1_ENCODE_SEQUENCE_PARAMS seqParams = (PCODEC_AV1_ENCODE_SEQUENCE_PARAMS)m_encodeCtx->pSeqParams; |
| 878 |
DDI_CHK_NULL(seqParams, "nullptr seqParams", VA_STATUS_ERROR_INVALID_PARAMETER); |
| 879 |
|
| 880 |
seqParams->VBVBufferSizeInBit = vaEncMiscParamHRD->buffer_size; |
| 881 |
seqParams->InitVBVBufferFullnessInBit = vaEncMiscParamHRD->initial_buffer_fullness; |
| 882 |
|
| 883 |
return VA_STATUS_SUCCESS; |
| 884 |
} |
| 885 |
|
| 886 |
VAStatus DdiEncodeAV1::ParseMiscParamFR(void *data) |
| 887 |
{ |
| 888 |
DDI_CHK_NULL(data, "nullptr data", VA_STATUS_ERROR_INVALID_PARAMETER); |
| 889 |
|
| 890 |
VAEncMiscParameterFrameRate *vaFrameRate = (VAEncMiscParameterFrameRate *)data; |
| 891 |
|
| 892 |
PCODEC_AV1_ENCODE_SEQUENCE_PARAMS seqParams = (PCODEC_AV1_ENCODE_SEQUENCE_PARAMS)m_encodeCtx->pSeqParams; |
| 893 |
DDI_CHK_NULL(seqParams, "nullptr seqParams", VA_STATUS_ERROR_INVALID_PARAMETER); |
| 894 |
|
| 895 |
if (vaFrameRate->framerate_flags.bits.temporal_id > seqParams->NumTemporalLayersMinus1) |
| 896 |
{ |
| 897 |
return VA_STATUS_ERROR_INVALID_PARAMETER; |
| 898 |
} |
| 899 |
|
| 900 |
uint32_t temporalId = vaFrameRate->framerate_flags.bits.temporal_id; |
| 901 |
|
| 902 |
if (vaFrameRate->framerate != savedFrameRate[temporalId]) |
| 903 |
{ |
| 904 |
savedFrameRate[temporalId] = vaFrameRate->framerate; |
| 905 |
//seqParams->SeqFlags.fields.ResetBRC |= 0x1; |
| 906 |
|
| 907 |
uint32_t frameRate = vaFrameRate->framerate; |
| 908 |
seqParams->FrameRate[temporalId].Numerator = frameRate &(0xFFFF); |
| 909 |
seqParams->FrameRate[temporalId].Denominator = (frameRate >> 16) &(0xFFFF); |
| 910 |
|
| 911 |
if (seqParams->FrameRate[temporalId].Denominator == 0) |
| 912 |
{ |
| 913 |
return VA_STATUS_ERROR_INVALID_PARAMETER; |
| 914 |
} |
| 915 |
} |
| 916 |
|
| 917 |
return VA_STATUS_SUCCESS; |
| 918 |
} |
| 919 |
|
| 920 |
// Parse rate control related information from app. |
| 921 |
VAStatus DdiEncodeAV1::ParseMiscParamRC(void *data) |
| 922 |
{ |
| 923 |
DDI_CHK_NULL(data, "nullptr data", VA_STATUS_ERROR_INVALID_PARAMETER); |
| 924 |
|
| 925 |
VAEncMiscParameterRateControl *vaEncMiscParamRC = (VAEncMiscParameterRateControl *)data; |
| 926 |
|
| 927 |
PCODEC_AV1_ENCODE_SEQUENCE_PARAMS seqParams = (PCODEC_AV1_ENCODE_SEQUENCE_PARAMS)m_encodeCtx->pSeqParams; |
| 928 |
DDI_CHK_NULL(seqParams, "nullptr seqParams", VA_STATUS_ERROR_INVALID_PARAMETER); |
| 929 |
|
| 930 |
PCODEC_AV1_ENCODE_PICTURE_PARAMS picParams = (PCODEC_AV1_ENCODE_PICTURE_PARAMS)(m_encodeCtx->pPicParams); |
| 931 |
DDI_CHK_NULL(picParams, "nullptr picParams", VA_STATUS_ERROR_INVALID_PARAMETER); |
| 932 |
|
| 933 |
uint32_t temporalId = vaEncMiscParamRC->rc_flags.bits.temporal_id; |
| 934 |
DDI_CHK_LESS(temporalId, (seqParams->NumTemporalLayersMinus1 + 1), |
| 935 |
"invalid temporal id", VA_STATUS_ERROR_INVALID_PARAMETER); |
| 936 |
|
| 937 |
uint32_t bitRate = MOS_ROUNDUP_DIVIDE(vaEncMiscParamRC->bits_per_second, CODECHAL_ENCODE_BRC_KBPS); |
| 938 |
seqParams->MaxBitRate = MOS_MAX(seqParams->MaxBitRate, bitRate); |
| 939 |
seqParams->SeqFlags.fields.ResetBRC = vaEncMiscParamRC->rc_flags.bits.reset; |
| 940 |
seqParams->FrameSizeTolerance = static_cast<ENCODE_FRAMESIZE_TOLERANCE>(vaEncMiscParamRC->rc_flags.bits.frame_tolerance_mode); |
| 941 |
#if VA_CHECK_VERSION(1, 10, 0) |
| 942 |
picParams->TargetFrameSize = vaEncMiscParamRC->target_frame_size; |
| 943 |
#endif |
| 944 |
|
| 945 |
if (VA_RC_CBR == m_encodeCtx->uiRCMethod) |
| 946 |
{ |
| 947 |
if(vaEncMiscParamRC->target_percentage != 0) |
| 948 |
seqParams->TargetBitRate[temporalId] = bitRate * vaEncMiscParamRC->target_percentage / 100; |
| 949 |
else |
| 950 |
seqParams->TargetBitRate[temporalId] = bitRate; // Default 100 percent |
| 951 |
seqParams->MaxBitRate = seqParams->TargetBitRate[temporalId]; |
| 952 |
seqParams->MinBitRate = seqParams->TargetBitRate[temporalId]; |
| 953 |
seqParams->RateControlMethod = RATECONTROL_CBR; |
| 954 |
if (savedTargetBit[temporalId] != bitRate) |
| 955 |
{ |
| 956 |
if (savedTargetBit[temporalId] != 0) |
| 957 |
{ |
| 958 |
seqParams->SeqFlags.fields.ResetBRC |= 0x01; |
| 959 |
} |
| 960 |
savedTargetBit[temporalId] = bitRate; |
| 961 |
} |
| 962 |
} |
| 963 |
else if (VA_RC_VBR == m_encodeCtx->uiRCMethod) |
| 964 |
{ |
| 965 |
if(vaEncMiscParamRC->target_percentage != 0) |
| 966 |
seqParams->TargetBitRate[temporalId] = bitRate * vaEncMiscParamRC->target_percentage / 100; |
| 967 |
else |
| 968 |
seqParams->TargetBitRate[temporalId] = bitRate; |
| 969 |
seqParams->MaxBitRate = bitRate; |
| 970 |
seqParams->MinBitRate = 0; |
| 971 |
seqParams->RateControlMethod = RATECONTROL_VBR; |
| 972 |
|
| 973 |
if ((savedTargetBit[temporalId] != seqParams->TargetBitRate[temporalId]) || |
| 974 |
(savedMaxBitRate[temporalId] != bitRate)) |
| 975 |
{ |
| 976 |
if ((savedTargetBit[temporalId] != 0) && (savedMaxBitRate[temporalId] != 0)) |
| 977 |
{ |
| 978 |
seqParams->SeqFlags.fields.ResetBRC |= 0x01; |
| 979 |
} |
| 980 |
savedTargetBit[temporalId] = seqParams->TargetBitRate[temporalId]; |
| 981 |
savedMaxBitRate[temporalId] = bitRate; |
| 982 |
} |
| 983 |
} |
| 984 |
else if (VA_RC_ICQ == m_encodeCtx->uiRCMethod) |
| 985 |
{ |
| 986 |
seqParams->RateControlMethod = RATECONTROL_CQL; |
| 987 |
seqParams->ICQQualityFactor = vaEncMiscParamRC->quality_factor; |
| 988 |
if (savedQualityFactor != seqParams->ICQQualityFactor) |
| 989 |
{ |
| 990 |
if (savedQualityFactor != 0) |
| 991 |
{ |
| 992 |
seqParams->SeqFlags.fields.ResetBRC |= 0x01; |
| 993 |
} |
| 994 |
savedQualityFactor = seqParams->ICQQualityFactor; |
| 995 |
} |
| 996 |
} |
| 997 |
|
| 998 |
/* the reset flag in RC will be considered. */ |
| 999 |
seqParams->SeqFlags.fields.ResetBRC |= vaEncMiscParamRC->rc_flags.bits.reset; |
| 1000 |
|
| 1001 |
return VA_STATUS_SUCCESS; |
| 1002 |
} |
| 1003 |
|
| 1004 |
VAStatus DdiEncodeAV1::ParseMiscParamEncQuality(void *data) |
| 1005 |
{ |
| 1006 |
DDI_CHK_NULL(data, "nullptr data", VA_STATUS_ERROR_INVALID_PARAMETER); |
| 1007 |
|
| 1008 |
VAEncMiscParameterEncQuality *vaEncMiscParamEncQuality = (VAEncMiscParameterEncQuality *)data; |
| 1009 |
|
| 1010 |
PCODEC_AV1_ENCODE_SEQUENCE_PARAMS seqParams = (PCODEC_AV1_ENCODE_SEQUENCE_PARAMS)m_encodeCtx->pSeqParams; |
| 1011 |
DDI_CHK_NULL(seqParams, "nullptr seqParams", VA_STATUS_ERROR_INVALID_PARAMETER); |
| 1012 |
|
| 1013 |
seqParams->SeqFlags.fields.UseRawReconRef = vaEncMiscParamEncQuality->useRawPicForRef; |
| 1014 |
|
| 1015 |
return VA_STATUS_SUCCESS; |
| 1016 |
} |
| 1017 |
|
| 1018 |
VAStatus DdiEncodeAV1::ParseMiscParamTemporalLayerParams(void* data) |
| 1019 |
{ |
| 1020 |
DDI_CHK_NULL(data, "nullptr data", VA_STATUS_ERROR_INVALID_PARAMETER); |
| 1021 |
|
| 1022 |
VAEncMiscParameterTemporalLayerStructure *vaEncTempLayerStruct = (VAEncMiscParameterTemporalLayerStructure *)data; |
| 1023 |
DDI_CHK_LESS(vaEncTempLayerStruct->number_of_layers, (ENCODE_AV1_MAX_NUM_TEMPORAL_LAYERS+1), |
| 1024 |
"invalid number of temporal layers", VA_STATUS_ERROR_INVALID_PARAMETER); |
| 1025 |
|
| 1026 |
PCODEC_AV1_ENCODE_SEQUENCE_PARAMS seqParams = (PCODEC_AV1_ENCODE_SEQUENCE_PARAMS)m_encodeCtx->pSeqParams; |
| 1027 |
DDI_CHK_NULL(seqParams, "nullptr seqParams", VA_STATUS_ERROR_INVALID_PARAMETER); |
| 1028 |
|
| 1029 |
if (vaEncTempLayerStruct->number_of_layers > 0) |
| 1030 |
{ |
| 1031 |
seqParams->NumTemporalLayersMinus1 = vaEncTempLayerStruct->number_of_layers - 1; |
| 1032 |
} |
| 1033 |
else |
| 1034 |
{ |
| 1035 |
seqParams->NumTemporalLayersMinus1 = 0; |
| 1036 |
} |
| 1037 |
|
| 1038 |
return VA_STATUS_SUCCESS; |
| 1039 |
} |
| 1040 |
|
| 1041 |
VAStatus DdiEncodeAV1::ParseMiscParamQualityLevel(void *data) |
| 1042 |
{ |
| 1043 |
DDI_CHK_NULL(data, "nullptr data", VA_STATUS_ERROR_INVALID_PARAMETER); |
| 1044 |
DDI_CHK_NULL(m_encodeCtx, "nullptr m_enocdeCtx", VA_STATUS_ERROR_INVALID_PARAMETER); |
| 1045 |
|
| 1046 |
VAEncMiscParameterBufferQualityLevel *vaEncMiscParamQualityLevel = (VAEncMiscParameterBufferQualityLevel *)data; |
| 1047 |
m_encodeCtx->targetUsage = (uint8_t)vaEncMiscParamQualityLevel->quality_level; |
| 1048 |
|
| 1049 |
return VA_STATUS_SUCCESS; |
| 1050 |
} |
| 1051 |
|
| 1052 |
VAStatus DdiEncodeAV1::ParseMiscParamMaxFrameSize(void *data) |
| 1053 |
{ |
| 1054 |
DDI_CHK_NULL(data, "nullptr data", VA_STATUS_ERROR_INVALID_PARAMETER); |
| 1055 |
|
| 1056 |
VAEncMiscParameterBufferMaxFrameSize *vaEncMiscParamMaxFrameSize = (VAEncMiscParameterBufferMaxFrameSize *)data; |
| 1057 |
|
| 1058 |
PCODEC_AV1_ENCODE_SEQUENCE_PARAMS seqParams = (PCODEC_AV1_ENCODE_SEQUENCE_PARAMS)m_encodeCtx->pSeqParams; |
| 1059 |
DDI_CHK_NULL(seqParams, "nullptr seqParams", VA_STATUS_ERROR_INVALID_PARAMETER); |
| 1060 |
|
| 1061 |
seqParams->UserMaxIFrameSize = vaEncMiscParamMaxFrameSize->max_frame_size >> 3; // convert to bytes. |
| 1062 |
seqParams->UserMaxPBFrameSize = vaEncMiscParamMaxFrameSize->max_frame_size >> 3; |
| 1063 |
|
| 1064 |
return VA_STATUS_SUCCESS; |
| 1065 |
} |
| 1066 |
|
| 1067 |
VAStatus DdiEncodeAV1::CheckCDEF(const VAEncPictureParameterBufferAV1 *picParams, PRODUCT_FAMILY platform) |
| 1068 |
{ |
| 1069 |
DDI_CHK_NULL(picParams, "nullptr picParams", VA_STATUS_ERROR_INVALID_PARAMETER); |
| 1070 |
|
| 1071 |
if (picParams->cdef_damping_minus_3 > av1MaxCDEFDampingMinus3) |
| 1072 |
{ |
| 1073 |
DDI_ASSERTMESSAGE("The CDEF damping exceeds the max value."); |
| 1074 |
return VA_STATUS_ERROR_INVALID_PARAMETER; |
| 1075 |
} |
| 1076 |
|
| 1077 |
if (picParams->cdef_bits > av1MaxCDEFBits) |
| 1078 |
{ |
| 1079 |
DDI_ASSERTMESSAGE("The CDEF bits exceed the max value."); |
| 1080 |
return VA_STATUS_ERROR_INVALID_PARAMETER; |
| 1081 |
} |
| 1082 |
|
| 1083 |
for (uint32_t i = 0; i < av1MaxCDEFEntries; i++) |
| 1084 |
{ |
| 1085 |
if (picParams->cdef_y_strengths[i] > av1MaxCDEFStrengths) |
| 1086 |
{ |
| 1087 |
DDI_ASSERTMESSAGE("The CDEF strengths exceed the max value."); |
| 1088 |
return VA_STATUS_ERROR_INVALID_PARAMETER; |
| 1089 |
} |
| 1090 |
|
| 1091 |
if (picParams->cdef_uv_strengths[i] > av1MaxCDEFStrengths) |
| 1092 |
{ |
| 1093 |
DDI_ASSERTMESSAGE("The CDEF strengths exceed the max value."); |
| 1094 |
return VA_STATUS_ERROR_INVALID_PARAMETER; |
| 1095 |
} |
| 1096 |
|
| 1097 |
if (picParams->cdef_uv_strengths[i] != picParams->cdef_y_strengths[i] && platform <= IGFX_DG2) |
| 1098 |
{ |
| 1099 |
DDI_ASSERTMESSAGE("Non-uniform CDEF strength of Y/UV are not supported for DG2."); |
| 1100 |
return VA_STATUS_ERROR_INVALID_PARAMETER; |
| 1101 |
} |
| 1102 |
} |
| 1103 |
return VA_STATUS_SUCCESS; |
| 1104 |
} |
| 1105 |
|
| 1106 |
VAStatus DdiEncodeAV1::CheckTile(const VAEncPictureParameterBufferAV1 *picParams) |
| 1107 |
{ |
| 1108 |
int minTileHeightInSB = picParams->height_in_sbs_minus_1[0] + 1; |
| 1109 |
int minTileWidthInSB = picParams->width_in_sbs_minus_1[0] + 1; |
| 1110 |
|
| 1111 |
for(int i = 1;i < picParams->tile_cols;i++) |
| 1112 |
{ |
| 1113 |
minTileWidthInSB = MOS_MIN(minTileWidthInSB, picParams->width_in_sbs_minus_1[i] + 1); |
| 1114 |
} |
| 1115 |
for(int i = 1;i < picParams->tile_rows;i++) |
| 1116 |
{ |
| 1117 |
minTileHeightInSB = MOS_MIN(minTileHeightInSB, picParams->height_in_sbs_minus_1[i] + 1); |
| 1118 |
} |
| 1119 |
|
| 1120 |
if(minTileWidthInSB * minTileHeightInSB < 4 || |
| 1121 |
minTileWidthInSB < 2 || |
| 1122 |
minTileHeightInSB < 2) |
| 1123 |
{ |
| 1124 |
DDI_ASSERTMESSAGE("Unsupported Tile Size"); |
| 1125 |
return VA_STATUS_ERROR_INVALID_PARAMETER; |
| 1126 |
} |
| 1127 |
|
| 1128 |
return VA_STATUS_SUCCESS; |
| 1129 |
} |
| 1130 |
|
| 1131 |
void DdiEncodeAV1::SetupCodecPicture( |
| 1132 |
DDI_MEDIA_CONTEXT *mediaCtx, |
| 1133 |
DDI_CODEC_RENDER_TARGET_TABLE *rtTbl, |
| 1134 |
CODEC_PICTURE *codecHalPic, |
| 1135 |
VASurfaceID surfaceID, |
| 1136 |
bool picReference) |
| 1137 |
{ |
| 1138 |
if (VA_INVALID_SURFACE != surfaceID) |
| 1139 |
{ |
| 1140 |
DDI_MEDIA_SURFACE *surface = DdiMedia_GetSurfaceFromVASurfaceID(mediaCtx, surfaceID); |
| 1141 |
codecHalPic->FrameIdx = GetRenderTargetID(rtTbl, surface); |
| 1142 |
codecHalPic->PicEntry = codecHalPic->FrameIdx; |
| 1143 |
} |
| 1144 |
else |
| 1145 |
{ |
| 1146 |
codecHalPic->FrameIdx = (uint8_t)DDI_CODEC_INVALID_FRAME_INDEX; |
| 1147 |
codecHalPic->PicEntry = 0xFF; |
| 1148 |
} |
| 1149 |
|
| 1150 |
if (picReference) |
| 1151 |
{ |
| 1152 |
if (codecHalPic->FrameIdx == (uint8_t)DDI_CODEC_INVALID_FRAME_INDEX) |
| 1153 |
{ |
| 1154 |
codecHalPic->PicFlags = PICTURE_INVALID; |
| 1155 |
} |
| 1156 |
else |
| 1157 |
{ |
| 1158 |
codecHalPic->PicFlags = PICTURE_SHORT_TERM_REFERENCE; |
| 1159 |
} |
| 1160 |
} |
| 1161 |
else |
| 1162 |
{ |
| 1163 |
codecHalPic->PicFlags = PICTURE_FRAME; |
| 1164 |
} |
| 1165 |
} |
| 1166 |
|
| 1167 |
uint32_t DdiEncodeAV1::getSequenceParameterBufferSize() |
| 1168 |
{ |
| 1169 |
return sizeof(VAEncSequenceParameterBufferAV1); |
| 1170 |
} |
| 1171 |
|
| 1172 |
uint32_t DdiEncodeAV1::getPictureParameterBufferSize() |
| 1173 |
{ |
| 1174 |
return sizeof(VAEncPictureParameterBufferAV1); |
| 1175 |
} |
| 1176 |
|
| 1177 |
uint32_t DdiEncodeAV1::getSliceParameterBufferSize() |
| 1178 |
{ |
| 1179 |
return sizeof(VAEncTileGroupBufferAV1); |
| 1180 |
} |
| 1181 |
|