| 1 |
/* |
| 2 |
* Copyright (c) 2017-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 codechal_encode_avc_base.cpp |
| 24 |
//! \brief Defines base class for AVC encoder. |
| 25 |
//! |
| 26 |
#include "codechal_encode_avc_base.h" |
| 27 |
#include "codechal_vdenc_avc.h" |
| 28 |
#include "codechal_encode_avc.h" |
| 29 |
#include "codechal_mmc_encode_avc.h" |
| 30 |
#include "hal_oca_interface.h" |
| 31 |
|
| 32 |
#define CODECHAL_ENCODE_AVC_CQP_NUM_OF_PASSES 2 |
| 33 |
#define CODECHAL_ENCODE_AVC_ICQ_NUM_OF_PASSES 2 |
| 34 |
#define CODECHAL_ENCODE_AVC_EXTENDED_SAR 255 |
| 35 |
|
| 36 |
const uint8_t CODECHAL_ENCODE_AVC_SFD_CostTable_P_FRAME[CODEC_AVC_NUM_QP] = |
| 37 |
{ |
| 38 |
44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 60, 60, 60, 60, 73, 73, 73, 76, 76, 76, 88, 89, 89, 91, 92, 93, 104, 104, 106, 107, 108, 109, 120, 120, 122, 123, 124, 125, 136, 136, 138, 139, 140, 141, 143, 143}; |
| 39 |
|
| 40 |
const uint8_t CODECHAL_ENCODE_AVC_SFD_CostTable_B_FRAME[CODEC_AVC_NUM_QP] = |
| 41 |
{ |
| 42 |
57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 73, 73, 73, 73, 77, 77, 77, 89, 89, 89, 91, 93, 93, 95, 105, 106, 107, 108, 110, 111, 121, 122, 123, 124, 125, 127, 137, 138, 139, 140, 142, 143, 143, 143, 143, 143}; |
| 43 |
|
| 44 |
uint32_t CodecHalAvcEncode_GetMaxVmvR(uint8_t levelIdc) |
| 45 |
{ |
| 46 |
int maxVmvR = 128 * 4; |
| 47 |
|
| 48 |
// See JVT Spec Annex A Table A-1 Level limits for below mapping |
| 49 |
// maxVmvR is in luma quarter pel unit |
| 50 |
switch (levelIdc) |
| 51 |
{ |
| 52 |
case CODEC_AVC_LEVEL_1: |
| 53 |
case CODEC_AVC_LEVEL_1b: |
| 54 |
maxVmvR = 64 * 4; |
| 55 |
break; |
| 56 |
case CODEC_AVC_LEVEL_11: |
| 57 |
case CODEC_AVC_LEVEL_12: |
| 58 |
case CODEC_AVC_LEVEL_13: |
| 59 |
case CODEC_AVC_LEVEL_2: |
| 60 |
maxVmvR = 128 * 4; |
| 61 |
break; |
| 62 |
case CODEC_AVC_LEVEL_21: |
| 63 |
case CODEC_AVC_LEVEL_22: |
| 64 |
case CODEC_AVC_LEVEL_3: |
| 65 |
maxVmvR = 256 * 4; |
| 66 |
break; |
| 67 |
case CODEC_AVC_LEVEL_31: |
| 68 |
case CODEC_AVC_LEVEL_32: |
| 69 |
case CODEC_AVC_LEVEL_4: |
| 70 |
case CODEC_AVC_LEVEL_41: |
| 71 |
case CODEC_AVC_LEVEL_42: |
| 72 |
case CODEC_AVC_LEVEL_5: |
| 73 |
case CODEC_AVC_LEVEL_51: |
| 74 |
case CODEC_AVC_LEVEL_52: |
| 75 |
maxVmvR = 512 * 4; |
| 76 |
break; |
| 77 |
default: |
| 78 |
CODECHAL_ENCODE_NORMALMESSAGE("Unsupported LevelIDC setting."); |
| 79 |
CODECHAL_ENCODE_ASSERT(false); |
| 80 |
break; |
| 81 |
} |
| 82 |
|
| 83 |
return maxVmvR; |
| 84 |
} |
| 85 |
|
| 86 |
uint32_t CodecHalAvcEncode_GetMaxMvLen(uint8_t levelIdc) |
| 87 |
{ |
| 88 |
int maxMvLen = 127; |
| 89 |
|
| 90 |
// See JVT Spec Annex A Table A-1 Level limits for below mapping |
| 91 |
// MaxVmvR is in luma quarter pel unit |
| 92 |
switch (levelIdc) |
| 93 |
{ |
| 94 |
case CODEC_AVC_LEVEL_1: |
| 95 |
case CODEC_AVC_LEVEL_1b: |
| 96 |
maxMvLen = 63; |
| 97 |
break; |
| 98 |
case CODEC_AVC_LEVEL_11: |
| 99 |
case CODEC_AVC_LEVEL_12: |
| 100 |
case CODEC_AVC_LEVEL_13: |
| 101 |
case CODEC_AVC_LEVEL_2: |
| 102 |
maxMvLen = 127; |
| 103 |
break; |
| 104 |
case CODEC_AVC_LEVEL_21: |
| 105 |
case CODEC_AVC_LEVEL_22: |
| 106 |
case CODEC_AVC_LEVEL_3: |
| 107 |
maxMvLen = 255; |
| 108 |
break; |
| 109 |
case CODEC_AVC_LEVEL_31: |
| 110 |
case CODEC_AVC_LEVEL_32: |
| 111 |
case CODEC_AVC_LEVEL_4: |
| 112 |
case CODEC_AVC_LEVEL_41: |
| 113 |
case CODEC_AVC_LEVEL_42: |
| 114 |
case CODEC_AVC_LEVEL_5: |
| 115 |
case CODEC_AVC_LEVEL_51: |
| 116 |
case CODEC_AVC_LEVEL_52: |
| 117 |
maxMvLen = 511; |
| 118 |
break; |
| 119 |
default: |
| 120 |
CODECHAL_ENCODE_NORMALMESSAGE("Unsupported LevelIDC setting."); |
| 121 |
CODECHAL_ENCODE_ASSERT(false); |
| 122 |
break; |
| 123 |
} |
| 124 |
|
| 125 |
return maxMvLen; |
| 126 |
} |
| 127 |
|
| 128 |
bool CodecHalAvcEncode_GetFieldParity( |
| 129 |
PCODEC_AVC_ENCODE_SLICE_PARAMS slcParams, |
| 130 |
uint32_t list, |
| 131 |
uint32_t index) |
| 132 |
{ |
| 133 |
uint32_t fieldParity = 0; |
| 134 |
|
| 135 |
if (slcParams == nullptr) |
| 136 |
{ |
| 137 |
CODECHAL_ENCODE_ASSERTMESSAGE("Invalid (NULL) Pointer."); |
| 138 |
return false; |
| 139 |
} |
| 140 |
CODECHAL_ENCODE_ASSERT(list == LIST_0 || list == LIST_1); |
| 141 |
CODECHAL_ENCODE_ASSERT(index < CODEC_AVC_MAX_NUM_REF_FRAME * 2); |
| 142 |
|
| 143 |
if (!CodecHal_PictureIsInvalid(slcParams->RefPicList[list][index])) |
| 144 |
{ |
| 145 |
fieldParity = CodecHal_PictureIsBottomField(slcParams->RefPicList[list][index]); |
| 146 |
} |
| 147 |
|
| 148 |
return (fieldParity ? true : false); |
| 149 |
} |
| 150 |
|
| 151 |
MOS_STATUS CodechalEncodeAvcBase::SendSlice( |
| 152 |
PMOS_COMMAND_BUFFER cmdBuffer, |
| 153 |
PMHW_VDBOX_AVC_SLICE_STATE params) |
| 154 |
{ |
| 155 |
PCODEC_AVC_ENCODE_SLICE_PARAMS avcSlcParams; |
| 156 |
MHW_VDBOX_AVC_REF_IDX_PARAMS refIdxParams; |
| 157 |
MHW_VDBOX_AVC_WEIGHTOFFSET_PARAMS weightOffsetParams; |
| 158 |
MHW_BATCH_BUFFER secondLevelBatchBuffer; |
| 159 |
MHW_VDBOX_PAK_INSERT_PARAMS pakInsertObjectParams; |
| 160 |
MHW_VDBOX_VDENC_WALKER_STATE_PARAMS vdencWalkerStateParams; |
| 161 |
PMOS_COMMAND_BUFFER cmdBufferInUse; |
| 162 |
PMHW_BATCH_BUFFER batchBufferInUse; |
| 163 |
uint32_t bitSize, offSet; |
| 164 |
uint32_t maxBytesInPakInsertObjCmd; |
| 165 |
uint32_t nalunitPosiSize, nalunitPosiOffset; |
| 166 |
bool insertZeroByteWA = false; |
| 167 |
|
| 168 |
CODECHAL_ENCODE_FUNCTION_ENTER; |
| 169 |
|
| 170 |
CODECHAL_ENCODE_CHK_NULL_RETURN(cmdBuffer); |
| 171 |
CODECHAL_ENCODE_CHK_NULL_RETURN(params); |
| 172 |
CODECHAL_ENCODE_CHK_NULL_RETURN(params->pAvcPicIdx); |
| 173 |
CODECHAL_ENCODE_CHK_NULL_RETURN(params->presDataBuffer); |
| 174 |
CODECHAL_ENCODE_CHK_NULL_RETURN(params->pEncodeAvcSeqParams); |
| 175 |
CODECHAL_ENCODE_CHK_NULL_RETURN(params->pEncodeAvcPicParams); |
| 176 |
CODECHAL_ENCODE_CHK_NULL_RETURN(params->pEncodeAvcSliceParams); |
| 177 |
CODECHAL_ENCODE_CHK_NULL_RETURN(params->pBsBuffer); |
| 178 |
CODECHAL_ENCODE_CHK_NULL_RETURN(params->ppNalUnitParams); |
| 179 |
|
| 180 |
avcSlcParams = params->pEncodeAvcSliceParams; |
| 181 |
maxBytesInPakInsertObjCmd = ((2 << 11) - 1) * 4; // 12 bits for DwordLength field in PAK_INSERT_OBJ cmd |
| 182 |
nalunitPosiSize = 0; |
| 183 |
nalunitPosiOffset = 0; |
| 184 |
|
| 185 |
// VDENC does not use batch buffer for slice state |
| 186 |
if (params->bSingleTaskPhaseSupported && !params->bVdencInUse) |
| 187 |
{ |
| 188 |
CODECHAL_ENCODE_CHK_NULL_RETURN(params->pBatchBufferForPakSlices); |
| 189 |
batchBufferInUse = params->pBatchBufferForPakSlices; |
| 190 |
cmdBufferInUse = nullptr; |
| 191 |
} |
| 192 |
else |
| 193 |
{ |
| 194 |
batchBufferInUse = nullptr; |
| 195 |
cmdBufferInUse = cmdBuffer; |
| 196 |
} |
| 197 |
|
| 198 |
// Add reference index and weight offset commands |
| 199 |
refIdxParams.CurrPic = params->pEncodeAvcPicParams->CurrReconstructedPic; |
| 200 |
refIdxParams.isEncode = true; |
| 201 |
refIdxParams.bVdencInUse = params->bVdencInUse; |
| 202 |
refIdxParams.pAvcPicIdx = params->pAvcPicIdx; |
| 203 |
refIdxParams.avcRefList = (void **)m_refList; |
| 204 |
refIdxParams.oneOnOneMapping = params->oneOnOneMapping; |
| 205 |
|
| 206 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(MOS_SecureMemcpy( |
| 207 |
&refIdxParams.RefPicList, |
| 208 |
2 * 32 * sizeof(CODEC_PICTURE), |
| 209 |
avcSlcParams->RefPicList, |
| 210 |
2 * 32 * sizeof(CODEC_PICTURE))); |
| 211 |
if (Slice_Type[avcSlcParams->slice_type] == SLICE_P) |
| 212 |
{ |
| 213 |
refIdxParams.uiList = LIST_0; |
| 214 |
refIdxParams.uiNumRefForList[LIST_0] = avcSlcParams->num_ref_idx_l0_active_minus1 + 1; |
| 215 |
|
| 216 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(m_mfxInterface->AddMfxAvcRefIdx(cmdBufferInUse, batchBufferInUse, &refIdxParams)); |
| 217 |
|
| 218 |
if (params->pEncodeAvcPicParams->weighted_pred_flag == EXPLICIT_WEIGHTED_INTER_PRED_MODE) |
| 219 |
{ |
| 220 |
weightOffsetParams.uiList = LIST_0; |
| 221 |
weightOffsetParams.uiLumaLogWeightDenom = avcSlcParams->luma_log2_weight_denom; |
| 222 |
weightOffsetParams.uiChromaLogWeightDenom = avcSlcParams->chroma_log2_weight_denom; |
| 223 |
weightOffsetParams.uiLumaWeightFlag = avcSlcParams->luma_weight_flag[LIST_0]; |
| 224 |
weightOffsetParams.uiChromaWeightFlag = avcSlcParams->chroma_weight_flag[LIST_0]; |
| 225 |
weightOffsetParams.uiNumRefForList = avcSlcParams->num_ref_idx_l0_active_minus1 + 1; |
| 226 |
|
| 227 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(MOS_SecureMemcpy( |
| 228 |
&weightOffsetParams.Weights, |
| 229 |
sizeof(weightOffsetParams.Weights), |
| 230 |
&avcSlcParams->Weights, |
| 231 |
sizeof(avcSlcParams->Weights))); |
| 232 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(m_mfxInterface->AddMfxAvcWeightOffset( |
| 233 |
cmdBufferInUse, |
| 234 |
batchBufferInUse, |
| 235 |
&weightOffsetParams)); |
| 236 |
} |
| 237 |
} |
| 238 |
|
| 239 |
else if (Slice_Type[avcSlcParams->slice_type] == SLICE_B) |
| 240 |
{ |
| 241 |
refIdxParams.uiList = LIST_0; |
| 242 |
refIdxParams.uiNumRefForList[LIST_0] = avcSlcParams->num_ref_idx_l0_active_minus1 + 1; |
| 243 |
|
| 244 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(m_mfxInterface->AddMfxAvcRefIdx(cmdBufferInUse, batchBufferInUse, &refIdxParams)); |
| 245 |
|
| 246 |
refIdxParams.uiList = LIST_1; |
| 247 |
refIdxParams.uiNumRefForList[LIST_1] = avcSlcParams->num_ref_idx_l1_active_minus1 + 1; |
| 248 |
|
| 249 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(m_mfxInterface->AddMfxAvcRefIdx(cmdBufferInUse, batchBufferInUse, &refIdxParams)); |
| 250 |
|
| 251 |
if (params->pEncodeAvcPicParams->weighted_bipred_idc == EXPLICIT_WEIGHTED_INTER_PRED_MODE) |
| 252 |
{ |
| 253 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(MOS_SecureMemcpy( |
| 254 |
&weightOffsetParams.Weights, |
| 255 |
sizeof(weightOffsetParams.Weights), |
| 256 |
&avcSlcParams->Weights, |
| 257 |
sizeof(avcSlcParams->Weights))); |
| 258 |
weightOffsetParams.uiList = LIST_0; |
| 259 |
weightOffsetParams.uiLumaLogWeightDenom = avcSlcParams->luma_log2_weight_denom; |
| 260 |
weightOffsetParams.uiChromaLogWeightDenom = avcSlcParams->chroma_log2_weight_denom; |
| 261 |
weightOffsetParams.uiLumaWeightFlag = avcSlcParams->luma_weight_flag[LIST_0]; |
| 262 |
weightOffsetParams.uiChromaWeightFlag = avcSlcParams->chroma_weight_flag[LIST_0]; |
| 263 |
weightOffsetParams.uiNumRefForList = avcSlcParams->num_ref_idx_l0_active_minus1 + 1; |
| 264 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(m_mfxInterface->AddMfxAvcWeightOffset( |
| 265 |
cmdBufferInUse, |
| 266 |
batchBufferInUse, |
| 267 |
&weightOffsetParams)); |
| 268 |
|
| 269 |
weightOffsetParams.uiList = LIST_1; |
| 270 |
weightOffsetParams.uiLumaLogWeightDenom = avcSlcParams->luma_log2_weight_denom; |
| 271 |
weightOffsetParams.uiChromaLogWeightDenom = avcSlcParams->chroma_log2_weight_denom; |
| 272 |
weightOffsetParams.uiLumaWeightFlag = avcSlcParams->luma_weight_flag[LIST_1]; |
| 273 |
weightOffsetParams.uiChromaWeightFlag = avcSlcParams->chroma_weight_flag[LIST_1]; |
| 274 |
weightOffsetParams.uiNumRefForList = avcSlcParams->num_ref_idx_l1_active_minus1 + 1; |
| 275 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(m_mfxInterface->AddMfxAvcWeightOffset( |
| 276 |
cmdBufferInUse, |
| 277 |
batchBufferInUse, |
| 278 |
&weightOffsetParams)); |
| 279 |
} |
| 280 |
} |
| 281 |
|
| 282 |
// add AVC Slice state commands |
| 283 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(AddMfxAvcSlice(cmdBufferInUse, batchBufferInUse, params)); |
| 284 |
|
| 285 |
//insert AU, SPS, PSP headers before first slice header |
| 286 |
if (params->bInsertBeforeSliceHeaders) |
| 287 |
{ |
| 288 |
uint8_t *dataBase = (uint8_t *)(params->pBsBuffer->pBase); |
| 289 |
uint32_t data = ((*dataBase) << 24) + ((*(dataBase + 1)) << 16) + ((*(dataBase + 2)) << 8) + (*(dataBase + 3)); |
| 290 |
// Only apply the WaSuperSliceHeaderPacking for the cases with 00 00 00 01 start code |
| 291 |
if (data == 0x00000001) |
| 292 |
{ |
| 293 |
insertZeroByteWA = true; |
| 294 |
} |
| 295 |
|
| 296 |
bool isInsert; |
| 297 |
uint32_t i; |
| 298 |
for (i = 0; i < CODECHAL_ENCODE_AVC_MAX_NAL_TYPE; i++) |
| 299 |
{ |
| 300 |
nalunitPosiSize = params->ppNalUnitParams[i]->uiSize; |
| 301 |
nalunitPosiOffset = params->ppNalUnitParams[i]->uiOffset; |
| 302 |
while (nalunitPosiSize > 0) |
| 303 |
{ |
| 304 |
isInsert = params->ppNalUnitParams[i]->bInsertEmulationBytes; |
| 305 |
bitSize = MOS_MIN(maxBytesInPakInsertObjCmd * 8, nalunitPosiSize * 8); |
| 306 |
offSet = nalunitPosiOffset; |
| 307 |
|
| 308 |
MOS_ZeroMemory(&pakInsertObjectParams, sizeof(pakInsertObjectParams)); |
| 309 |
pakInsertObjectParams.bEmulationByteBitsInsert = isInsert; |
| 310 |
pakInsertObjectParams.uiSkipEmulationCheckCount = params->ppNalUnitParams[i]->uiSkipEmulationCheckCount; |
| 311 |
pakInsertObjectParams.pBsBuffer = params->pBsBuffer; |
| 312 |
pakInsertObjectParams.dwBitSize = bitSize; |
| 313 |
pakInsertObjectParams.dwOffset = offSet; |
| 314 |
pakInsertObjectParams.bHeaderLengthExcludeFrmSize = true; // Exclude header length from size calculation for accurate Cabac Zero Word Insertion |
| 315 |
|
| 316 |
if (pakInsertObjectParams.bEmulationByteBitsInsert) |
| 317 |
{ |
| 318 |
CODECHAL_ENCODE_VERBOSEMESSAGE("The emulation prevention bytes are not inserted by the app and are requested to be inserted by HW."); |
| 319 |
} |
| 320 |
|
| 321 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(m_mfxInterface->AddMfxPakInsertObject( |
| 322 |
cmdBufferInUse, batchBufferInUse, &pakInsertObjectParams)); |
| 323 |
|
| 324 |
if (nalunitPosiSize > maxBytesInPakInsertObjCmd) |
| 325 |
{ |
| 326 |
nalunitPosiSize -= maxBytesInPakInsertObjCmd; |
| 327 |
nalunitPosiOffset += maxBytesInPakInsertObjCmd; |
| 328 |
} |
| 329 |
else |
| 330 |
{ |
| 331 |
nalunitPosiSize = 0; |
| 332 |
} |
| 333 |
|
| 334 |
insertZeroByteWA = false; |
| 335 |
} |
| 336 |
} |
| 337 |
} |
| 338 |
|
| 339 |
uint8_t *dataBase = (uint8_t *)(params->pBsBuffer->pBase + params->dwOffset); |
| 340 |
uint32_t data = ((*dataBase) << 24) + ((*(dataBase + 1)) << 16) + ((*(dataBase + 2)) << 8) + (*(dataBase + 3)); |
| 341 |
|
| 342 |
if (data == 0x00000001) |
| 343 |
{ |
| 344 |
insertZeroByteWA = true; |
| 345 |
} |
| 346 |
|
| 347 |
// Insert 0x00 for super slice case when PPS/AUD is not inserted |
| 348 |
if (MEDIA_IS_WA(m_hwInterface->GetWaTable(), WaSuperSliceHeaderPacking) && insertZeroByteWA && params->bVdencInUse && m_hwInterface->m_isVdencSuperSliceEnabled) |
| 349 |
{ |
| 350 |
MOS_ZeroMemory(&pakInsertObjectParams, sizeof(pakInsertObjectParams)); |
| 351 |
pakInsertObjectParams.pBsBuffer = params->pBsBuffer; |
| 352 |
pakInsertObjectParams.dwBitSize = 8; |
| 353 |
pakInsertObjectParams.dwOffset = params->dwOffset; |
| 354 |
|
| 355 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(m_mfxInterface->AddMfxPakInsertObject( |
| 356 |
cmdBufferInUse, batchBufferInUse, &pakInsertObjectParams)); |
| 357 |
} |
| 358 |
|
| 359 |
// Insert slice header |
| 360 |
MOS_ZeroMemory(&pakInsertObjectParams, sizeof(pakInsertObjectParams)); |
| 361 |
pakInsertObjectParams.bLastHeader = true; |
| 362 |
pakInsertObjectParams.bEmulationByteBitsInsert = true; |
| 363 |
|
| 364 |
if (params->bAcceleratorHeaderPackingCaps) |
| 365 |
{ |
| 366 |
// If driver does slice header packing set the skip count to 4 |
| 367 |
pakInsertObjectParams.uiSkipEmulationCheckCount = 4; |
| 368 |
} |
| 369 |
else |
| 370 |
{ |
| 371 |
// App does the slice header packing, set the skip count passed by the app |
| 372 |
pakInsertObjectParams.uiSkipEmulationCheckCount = params->uiSkipEmulationCheckCount; |
| 373 |
} |
| 374 |
pakInsertObjectParams.pBsBuffer = params->pBsBuffer; |
| 375 |
// Slice Header Indicator should be set for VDENC for multi-slice case |
| 376 |
pakInsertObjectParams.bSliceHeaderIndicator = (!params->bVdencInUse) ? false : true; |
| 377 |
|
| 378 |
// Remove one byte of 00 for super slice case when PPS/AUD is not inserted, so that HW could patch slice header correctly |
| 379 |
if (MEDIA_IS_WA(m_hwInterface->GetWaTable(), WaSuperSliceHeaderPacking) && insertZeroByteWA && params->bVdencInUse && m_hwInterface->m_isVdencSuperSliceEnabled) |
| 380 |
{ |
| 381 |
pakInsertObjectParams.dwBitSize = params->dwLength - 8; |
| 382 |
pakInsertObjectParams.dwOffset = params->dwOffset + 1; |
| 383 |
} |
| 384 |
else |
| 385 |
{ |
| 386 |
pakInsertObjectParams.dwBitSize = params->dwLength; |
| 387 |
pakInsertObjectParams.dwOffset = params->dwOffset; |
| 388 |
} |
| 389 |
|
| 390 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(m_mfxInterface->AddMfxPakInsertObject( |
| 391 |
cmdBufferInUse, batchBufferInUse, &pakInsertObjectParams)); |
| 392 |
|
| 393 |
if (params->bVdencInUse) |
| 394 |
{ |
| 395 |
//For CNL VDENC Walker command and WeightsOffsets cmds are sent per Super slice |
| 396 |
if (m_hwInterface->m_isVdencSuperSliceEnabled) |
| 397 |
{ |
| 398 |
weightOffsetParams.pAvcPicParams = params->pEncodeAvcPicParams; |
| 399 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(m_vdencInterface->AddVdencAvcWeightsOffsetsStateCmd(cmdBuffer, &weightOffsetParams)); |
| 400 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(AddVdencSliceStateCmd(cmdBuffer, params)); |
| 401 |
|
| 402 |
vdencWalkerStateParams.Mode = CODECHAL_ENCODE_MODE_AVC; |
| 403 |
vdencWalkerStateParams.slcIdx = params->dwSliceIndex; |
| 404 |
vdencWalkerStateParams.pAvcSeqParams = params->pEncodeAvcSeqParams; |
| 405 |
vdencWalkerStateParams.pAvcPicParams = params->pEncodeAvcPicParams; |
| 406 |
vdencWalkerStateParams.pAvcSlcParams = avcSlcParams; |
| 407 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(m_vdencInterface->AddVdencWalkerStateCmd(cmdBuffer, &vdencWalkerStateParams)); |
| 408 |
} |
| 409 |
} |
| 410 |
else |
| 411 |
{ |
| 412 |
if (params->bSingleTaskPhaseSupported) |
| 413 |
{ |
| 414 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(m_miInterface->AddMiBatchBufferEnd(nullptr, batchBufferInUse)); |
| 415 |
|
| 416 |
// Insert Batch Buffer Start command to send AVC_PAK_OBJ data for MBs in this slice |
| 417 |
MOS_ZeroMemory(&secondLevelBatchBuffer, sizeof(MHW_BATCH_BUFFER)); |
| 418 |
CODECHAL_ENCODE_CHK_NULL_RETURN(batchBufferInUse); |
| 419 |
secondLevelBatchBuffer.OsResource = batchBufferInUse->OsResource; |
| 420 |
secondLevelBatchBuffer.dwOffset = params->dwBatchBufferForPakSlicesStartOffset; |
| 421 |
secondLevelBatchBuffer.bSecondLevel = true; |
| 422 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(m_miInterface->AddMiBatchBufferStartCmd(cmdBuffer, &secondLevelBatchBuffer)); |
| 423 |
} |
| 424 |
|
| 425 |
// Insert Batch Buffer Start command to send AVC_PAK_OBJ data for MBs in this slice |
| 426 |
MOS_ZeroMemory(&secondLevelBatchBuffer, sizeof(MHW_BATCH_BUFFER)); |
| 427 |
secondLevelBatchBuffer.OsResource = *params->presDataBuffer; |
| 428 |
secondLevelBatchBuffer.dwOffset = params->dwDataBufferOffset; |
| 429 |
secondLevelBatchBuffer.bSecondLevel = true; |
| 430 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(m_miInterface->AddMiBatchBufferStartCmd(cmdBuffer, &secondLevelBatchBuffer)); |
| 431 |
} |
| 432 |
|
| 433 |
return MOS_STATUS_SUCCESS; |
| 434 |
} |
| 435 |
static int32_t GetMaxMBPS(uint8_t levelIdc) |
| 436 |
{ |
| 437 |
int maxMBPS = 11880; |
| 438 |
|
| 439 |
// See JVT Spec Annex A Table A-1 Level limits for below mapping |
| 440 |
// maxMBPS is in MB/s |
| 441 |
switch (levelIdc) |
| 442 |
{ |
| 443 |
case CODEC_AVC_LEVEL_1: |
| 444 |
case CODEC_AVC_LEVEL_1b: |
| 445 |
maxMBPS = 1485; |
| 446 |
break; |
| 447 |
case CODEC_AVC_LEVEL_11: |
| 448 |
maxMBPS = 3000; |
| 449 |
break; |
| 450 |
case CODEC_AVC_LEVEL_12: |
| 451 |
maxMBPS = 6000; |
| 452 |
break; |
| 453 |
case CODEC_AVC_LEVEL_13: |
| 454 |
case CODEC_AVC_LEVEL_2: |
| 455 |
maxMBPS = 11880; |
| 456 |
break; |
| 457 |
case CODEC_AVC_LEVEL_21: |
| 458 |
maxMBPS = 19800; |
| 459 |
break; |
| 460 |
case CODEC_AVC_LEVEL_22: |
| 461 |
maxMBPS = 20250; |
| 462 |
break; |
| 463 |
case CODEC_AVC_LEVEL_3: |
| 464 |
maxMBPS = 40500; |
| 465 |
break; |
| 466 |
case CODEC_AVC_LEVEL_31: |
| 467 |
maxMBPS = 108000; |
| 468 |
break; |
| 469 |
case CODEC_AVC_LEVEL_32: |
| 470 |
maxMBPS = 216000; |
| 471 |
break; |
| 472 |
case CODEC_AVC_LEVEL_4: |
| 473 |
case CODEC_AVC_LEVEL_41: |
| 474 |
maxMBPS = 245760; |
| 475 |
break; |
| 476 |
case CODEC_AVC_LEVEL_42: |
| 477 |
maxMBPS = 522240; |
| 478 |
break; |
| 479 |
case CODEC_AVC_LEVEL_5: |
| 480 |
maxMBPS = 589824; |
| 481 |
break; |
| 482 |
case CODEC_AVC_LEVEL_51: |
| 483 |
maxMBPS = 983040; |
| 484 |
break; |
| 485 |
case CODEC_AVC_LEVEL_52: |
| 486 |
maxMBPS = 2073600; |
| 487 |
break; |
| 488 |
default: |
| 489 |
maxMBPS = 0; |
| 490 |
break; |
| 491 |
} |
| 492 |
|
| 493 |
return maxMBPS; |
| 494 |
} |
| 495 |
|
| 496 |
MOS_STATUS CodecHalAvcEncode_GetProfileLevelMaxFrameSize( |
| 497 |
PCODEC_AVC_ENCODE_SEQUENCE_PARAMS seqParams, |
| 498 |
CodechalEncoderState * encoder, |
| 499 |
uint32_t * pdwProfileLevelMaxFrame) |
| 500 |
{ |
| 501 |
double bitsPerMB, tmpf; |
| 502 |
int32_t iMaxMBPS, numMBPerFrame, minCR; |
| 503 |
uint64_t maxBytePerPic, maxBytePerPicNot0; |
| 504 |
uint32_t profileLevelMaxFrame, userMaxFrameSize; |
| 505 |
MOS_STATUS eStatus = MOS_STATUS_SUCCESS; |
| 506 |
double frameRateD = 100; |
| 507 |
|
| 508 |
CODECHAL_ENCODE_CHK_NULL_RETURN(seqParams); |
| 509 |
CODECHAL_ENCODE_CHK_NULL_RETURN(encoder); |
| 510 |
CODECHAL_ENCODE_CHK_NULL_RETURN(pdwProfileLevelMaxFrame); |
| 511 |
|
| 512 |
minCR = 4; |
| 513 |
|
| 514 |
if (seqParams->Level >= CODEC_AVC_LEVEL_31 && seqParams->Level <= CODEC_AVC_LEVEL_4) |
| 515 |
{ |
| 516 |
bitsPerMB = 96; |
| 517 |
} |
| 518 |
else |
| 519 |
{ |
| 520 |
bitsPerMB = 192; |
| 521 |
minCR = 2; |
| 522 |
} |
| 523 |
|
| 524 |
iMaxMBPS = GetMaxMBPS(seqParams->Level); |
| 525 |
if (!iMaxMBPS) |
| 526 |
{ |
| 527 |
CODECHAL_ENCODE_ASSERTMESSAGE("Unsupported LevelIDC setting."); |
| 528 |
return MOS_STATUS_UNKNOWN; |
| 529 |
} |
| 530 |
|
| 531 |
numMBPerFrame = encoder->m_picWidthInMb * encoder->m_frameFieldHeightInMb; |
| 532 |
|
| 533 |
tmpf = (double)numMBPerFrame; |
| 534 |
if (tmpf < iMaxMBPS / 172.) |
| 535 |
{ |
| 536 |
tmpf = iMaxMBPS / 172.; |
| 537 |
} |
| 538 |
|
| 539 |
maxBytePerPic = (uint64_t)(tmpf * bitsPerMB); |
| 540 |
maxBytePerPicNot0 = |
| 541 |
(uint64_t)((((double)iMaxMBPS * frameRateD) / |
| 542 |
(double)seqParams->FramesPer100Sec) * |
| 543 |
bitsPerMB); |
| 544 |
userMaxFrameSize = seqParams->UserMaxFrameSize; |
| 545 |
|
| 546 |
if ((encoder->m_pictureCodingType != I_TYPE) && (seqParams->UserMaxPBFrameSize > 0)) |
| 547 |
{ |
| 548 |
userMaxFrameSize = seqParams->UserMaxPBFrameSize; |
| 549 |
} |
| 550 |
|
| 551 |
if (userMaxFrameSize != 0) |
| 552 |
{ |
| 553 |
profileLevelMaxFrame = (uint32_t)MOS_MIN(userMaxFrameSize, maxBytePerPic); |
| 554 |
profileLevelMaxFrame = (uint32_t)MOS_MIN(maxBytePerPicNot0, profileLevelMaxFrame); |
| 555 |
} |
| 556 |
else |
| 557 |
{ |
| 558 |
profileLevelMaxFrame = (uint32_t)MOS_MIN(maxBytePerPicNot0, maxBytePerPic); |
| 559 |
} |
| 560 |
|
| 561 |
// minCR related changes are added to match hardware behavior |
| 562 |
if (encoder->m_vdencEnabled) |
| 563 |
{ |
| 564 |
*pdwProfileLevelMaxFrame = (uint32_t)MOS_MIN((encoder->m_frameHeight * encoder->m_frameHeight), profileLevelMaxFrame); |
| 565 |
} |
| 566 |
else |
| 567 |
{ |
| 568 |
*pdwProfileLevelMaxFrame = (uint32_t)MOS_MIN(encoder->m_frameHeight * encoder->m_frameWidth * 3 / (2 * minCR), profileLevelMaxFrame); |
| 569 |
} |
| 570 |
|
| 571 |
return eStatus; |
| 572 |
} |
| 573 |
|
| 574 |
static void PutVLCCode(BSBuffer *bsbuffer, uint32_t code) |
| 575 |
{ |
| 576 |
uint8_t leadingZeroBits, bitcount; |
| 577 |
uint32_t code1, bits; |
| 578 |
|
| 579 |
code1 = code + 1; |
| 580 |
bitcount = 0; |
| 581 |
while (code1) |
| 582 |
{ |
| 583 |
code1 >>= 1; |
| 584 |
bitcount++; |
| 585 |
} |
| 586 |
|
| 587 |
if (bitcount == 1) |
| 588 |
{ |
| 589 |
PutBit(bsbuffer, 1); |
| 590 |
} |
| 591 |
else |
| 592 |
{ |
| 593 |
leadingZeroBits = bitcount - 1; |
| 594 |
bits = code + 1 - (1 << leadingZeroBits); |
| 595 |
PutBits(bsbuffer, 1, leadingZeroBits + 1); |
| 596 |
PutBits(bsbuffer, bits, leadingZeroBits); |
| 597 |
} |
| 598 |
} |
| 599 |
|
| 600 |
//! |
| 601 |
//! \brief Pack HRD data |
| 602 |
//! |
| 603 |
//! \param [in] params |
| 604 |
//! Pointer to codechal encode Avc pack picture header parameter |
| 605 |
//! |
| 606 |
//! \return MOS_STATUS |
| 607 |
//! Return MOS_STATUS_SUCCESS if call success, else fail reason |
| 608 |
//! |
| 609 |
MOS_STATUS CodecHal_PackPictureHeader_HrdParams( |
| 610 |
PCODECHAL_ENCODE_AVC_PACK_PIC_HEADER_PARAMS params) |
| 611 |
{ |
| 612 |
PCODECHAL_ENCODE_AVC_VUI_PARAMS vuiParams; |
| 613 |
PBSBuffer bsbuffer; |
| 614 |
int schedSelIdx; |
| 615 |
MOS_STATUS eStatus = MOS_STATUS_SUCCESS; |
| 616 |
|
| 617 |
CODECHAL_ENCODE_CHK_NULL_RETURN(params); |
| 618 |
|
| 619 |
vuiParams = params->pAvcVuiParams; |
| 620 |
bsbuffer = params->pBsBuffer; |
| 621 |
|
| 622 |
PutVLCCode(bsbuffer, vuiParams->cpb_cnt_minus1); |
| 623 |
PutBits(bsbuffer, vuiParams->bit_rate_scale, 4); |
| 624 |
PutBits(bsbuffer, vuiParams->cpb_size_scale, 4); |
| 625 |
|
| 626 |
for (schedSelIdx = 0; schedSelIdx <= vuiParams->cpb_cnt_minus1; schedSelIdx++) |
| 627 |
{ |
| 628 |
PutVLCCode(bsbuffer, vuiParams->bit_rate_value_minus1[schedSelIdx]); |
| 629 |
PutVLCCode(bsbuffer, vuiParams->cpb_size_value_minus1[schedSelIdx]); |
| 630 |
PutBit(bsbuffer, ((vuiParams->cbr_flag >> schedSelIdx) & 1)); |
| 631 |
} |
| 632 |
|
| 633 |
PutBits(bsbuffer, vuiParams->initial_cpb_removal_delay_length_minus1, 5); |
| 634 |
PutBits(bsbuffer, vuiParams->cpb_removal_delay_length_minus1, 5); |
| 635 |
PutBits(bsbuffer, vuiParams->dpb_output_delay_length_minus1, 5); |
| 636 |
PutBits(bsbuffer, vuiParams->time_offset_length, 5); |
| 637 |
|
| 638 |
return eStatus; |
| 639 |
} |
| 640 |
|
| 641 |
static void PackScalingList(BSBuffer *bsbuffer, uint8_t *scalingList, uint8_t sizeOfScalingList) |
| 642 |
{ |
| 643 |
uint8_t lastScale, nextScale, j; |
| 644 |
char delta_scale; |
| 645 |
|
| 646 |
lastScale = nextScale = 8; |
| 647 |
|
| 648 |
for (j = 0; j < sizeOfScalingList; j++) |
| 649 |
{ |
| 650 |
if (nextScale != 0) |
| 651 |
{ |
| 652 |
delta_scale = (char)(scalingList[j] - lastScale); |
| 653 |
|
| 654 |
PutVLCCode(bsbuffer, SIGNED(delta_scale)); |
| 655 |
|
| 656 |
nextScale = scalingList[j]; |
| 657 |
} |
| 658 |
lastScale = (nextScale == 0) ? lastScale : nextScale; |
| 659 |
} |
| 660 |
} |
| 661 |
|
| 662 |
//! |
| 663 |
//! \brief Pack VUI data |
| 664 |
//! |
| 665 |
//! \param [in] params |
| 666 |
//! Pointer to codechal encode Avc pack picture header parameter |
| 667 |
//! |
| 668 |
//! \return MOS_STATUS |
| 669 |
//! Return MOS_STATUS_SUCCESS if call success, else fail reason |
| 670 |
//! |
| 671 |
MOS_STATUS CodecHal_PackPictureHeader_VuiParams( |
| 672 |
PCODECHAL_ENCODE_AVC_PACK_PIC_HEADER_PARAMS params) |
| 673 |
{ |
| 674 |
PCODECHAL_ENCODE_AVC_VUI_PARAMS vuiParams; |
| 675 |
PBSBuffer bsbuffer; |
| 676 |
MOS_STATUS eStatus = MOS_STATUS_SUCCESS; |
| 677 |
|
| 678 |
CODECHAL_ENCODE_CHK_NULL_RETURN(params); |
| 679 |
CODECHAL_ENCODE_CHK_NULL_RETURN(params->pAvcVuiParams); |
| 680 |
|
| 681 |
vuiParams = params->pAvcVuiParams; |
| 682 |
bsbuffer = params->pBsBuffer; |
| 683 |
|
| 684 |
PutBit(bsbuffer, vuiParams->aspect_ratio_info_present_flag); |
| 685 |
if (vuiParams->aspect_ratio_info_present_flag) |
| 686 |
{ |
| 687 |
PutBits(bsbuffer, vuiParams->aspect_ratio_idc, 8); |
| 688 |
if (vuiParams->aspect_ratio_idc == CODECHAL_ENCODE_AVC_EXTENDED_SAR) |
| 689 |
{ |
| 690 |
PutBits(bsbuffer, vuiParams->sar_width, 16); |
| 691 |
PutBits(bsbuffer, vuiParams->sar_height, 16); |
| 692 |
} |
| 693 |
} |
| 694 |
|
| 695 |
PutBit(bsbuffer, vuiParams->overscan_info_present_flag); |
| 696 |
if (vuiParams->overscan_info_present_flag) |
| 697 |
{ |
| 698 |
PutBit(bsbuffer, vuiParams->overscan_appropriate_flag); |
| 699 |
} |
| 700 |
|
| 701 |
PutBit(bsbuffer, vuiParams->video_signal_type_present_flag); |
| 702 |
if (vuiParams->video_signal_type_present_flag) |
| 703 |
{ |
| 704 |
PutBits(bsbuffer, vuiParams->video_format, 3); |
| 705 |
PutBit(bsbuffer, vuiParams->video_full_range_flag); |
| 706 |
PutBit(bsbuffer, vuiParams->colour_description_present_flag); |
| 707 |
if (vuiParams->colour_description_present_flag) |
| 708 |
{ |
| 709 |
PutBits(bsbuffer, vuiParams->colour_primaries, 8); |
| 710 |
PutBits(bsbuffer, vuiParams->transfer_characteristics, 8); |
| 711 |
PutBits(bsbuffer, vuiParams->matrix_coefficients, 8); |
| 712 |
} |
| 713 |
} |
| 714 |
|
| 715 |
PutBit(bsbuffer, vuiParams->chroma_loc_info_present_flag); |
| 716 |
if (vuiParams->chroma_loc_info_present_flag) |
| 717 |
{ |
| 718 |
PutVLCCode(bsbuffer, vuiParams->chroma_sample_loc_type_top_field); |
| 719 |
PutVLCCode(bsbuffer, vuiParams->chroma_sample_loc_type_bottom_field); |
| 720 |
} |
| 721 |
|
| 722 |
PutBit(bsbuffer, vuiParams->timing_info_present_flag); |
| 723 |
if (vuiParams->timing_info_present_flag) |
| 724 |
{ |
| 725 |
PutBits(bsbuffer, vuiParams->num_units_in_tick, 32); |
| 726 |
PutBits(bsbuffer, vuiParams->time_scale, 32); |
| 727 |
PutBit(bsbuffer, vuiParams->fixed_frame_rate_flag); |
| 728 |
} |
| 729 |
|
| 730 |
PutBit(bsbuffer, vuiParams->nal_hrd_parameters_present_flag); |
| 731 |
if (vuiParams->nal_hrd_parameters_present_flag) |
| 732 |
{ |
| 733 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(CodecHal_PackPictureHeader_HrdParams(params)); |
| 734 |
} |
| 735 |
|
| 736 |
PutBit(bsbuffer, vuiParams->vcl_hrd_parameters_present_flag); |
| 737 |
if (vuiParams->vcl_hrd_parameters_present_flag) |
| 738 |
{ |
| 739 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(CodecHal_PackPictureHeader_HrdParams(params)); |
| 740 |
} |
| 741 |
|
| 742 |
if (vuiParams->nal_hrd_parameters_present_flag || vuiParams->vcl_hrd_parameters_present_flag) |
| 743 |
{ |
| 744 |
PutBit(bsbuffer, vuiParams->low_delay_hrd_flag); |
| 745 |
} |
| 746 |
|
| 747 |
PutBit(bsbuffer, vuiParams->pic_struct_present_flag); |
| 748 |
PutBit(bsbuffer, vuiParams->bitstream_restriction_flag); |
| 749 |
if (vuiParams->bitstream_restriction_flag) |
| 750 |
{ |
| 751 |
PutBit(bsbuffer, vuiParams->motion_vectors_over_pic_boundaries_flag); |
| 752 |
PutVLCCode(bsbuffer, vuiParams->max_bytes_per_pic_denom); |
| 753 |
PutVLCCode(bsbuffer, vuiParams->max_bits_per_mb_denom); |
| 754 |
PutVLCCode(bsbuffer, vuiParams->log2_max_mv_length_horizontal); |
| 755 |
PutVLCCode(bsbuffer, vuiParams->log2_max_mv_length_vertical); |
| 756 |
PutVLCCode(bsbuffer, vuiParams->num_reorder_frames); |
| 757 |
PutVLCCode(bsbuffer, vuiParams->max_dec_frame_buffering); |
| 758 |
} |
| 759 |
|
| 760 |
return eStatus; |
| 761 |
} |
| 762 |
|
| 763 |
static void SetNalUnit(uint8_t **bsbuffer, uint8_t refIDC, CODECHAL_ENCODE_AVC_NAL_UNIT_TYPE nalType) |
| 764 |
{ |
| 765 |
uint8_t *byte = *bsbuffer; |
| 766 |
|
| 767 |
// for SPS and PPS NAL units zero_byte should exist |
| 768 |
if (nalType == CODECHAL_ENCODE_AVC_NAL_UT_SPS || nalType == CODECHAL_ENCODE_AVC_NAL_UT_PPS || nalType == CODECHAL_ENCODE_AVC_NAL_UT_AUD) |
| 769 |
{ |
| 770 |
*byte++ = 0; |
| 771 |
} |
| 772 |
|
| 773 |
*byte++ = 0; |
| 774 |
*byte++ = 0; |
| 775 |
*byte++ = 1; |
| 776 |
*byte++ = (uint8_t)((refIDC << 5) | nalType); |
| 777 |
*byte = 0; // Clear the next byte |
| 778 |
*bsbuffer = byte; |
| 779 |
} |
| 780 |
|
| 781 |
static void SetTrailingBits(BSBuffer *bsbuffer) |
| 782 |
{ |
| 783 |
// Write Stop Bit |
| 784 |
PutBits(bsbuffer, 1, 1); |
| 785 |
// Make byte aligned |
| 786 |
while (bsbuffer->BitOffset) |
| 787 |
{ |
| 788 |
PutBit(bsbuffer, 0); |
| 789 |
} |
| 790 |
} |
| 791 |
|
| 792 |
static void CodecHal_PackSliceHeader_SetInitialRefPicList( |
| 793 |
PCODECHAL_ENCODE_AVC_PACK_SLC_HEADER_PARAMS params) |
| 794 |
{ |
| 795 |
PCODEC_AVC_ENCODE_SLICE_PARAMS slcParams; |
| 796 |
PCODEC_REF_LIST * refList; |
| 797 |
CODEC_PIC_REORDER * picOrder, pTempPicOrder[32]; |
| 798 |
CODEC_PICTURE picture; |
| 799 |
uint8_t i, j, botField; |
| 800 |
uint32_t picNum, picOC; |
| 801 |
uint8_t topIdx, botIdx, listSize; |
| 802 |
uint32_t defaultPicNumOrder[32]; |
| 803 |
bool reorder; |
| 804 |
|
| 805 |
CODECHAL_ENCODE_FUNCTION_ENTER; |
| 806 |
|
| 807 |
CODECHAL_ENCODE_CHK_NULL_NO_STATUS_RETURN(params); |
| 808 |
CODECHAL_ENCODE_CHK_NULL_NO_STATUS_RETURN(params->pAvcSliceParams); |
| 809 |
CODECHAL_ENCODE_CHK_NULL_NO_STATUS_RETURN(params->ppRefList); |
| 810 |
|
| 811 |
slcParams = params->pAvcSliceParams; |
| 812 |
refList = params->ppRefList; |
| 813 |
reorder = false; |
| 814 |
topIdx = 0; |
| 815 |
botIdx = 0; |
| 816 |
listSize = 0; |
| 817 |
|
| 818 |
if (params->wPictureCodingType == P_TYPE) |
| 819 |
{ |
| 820 |
CodecHal_PackSliceHeader_GetPicNum(params, 0); // list 0 |
| 821 |
picOrder = &slcParams->PicOrder[0][0]; |
| 822 |
// Save the default pic order. |
| 823 |
for (i = 0; i < (slcParams->num_ref_idx_l0_active_minus1 + 1); i++) |
| 824 |
{ |
| 825 |
defaultPicNumOrder[i] = picOrder[i].PicNum; |
| 826 |
} |
| 827 |
for (i = 1; i < (slcParams->num_ref_idx_l0_active_minus1 + 1); i++) |
| 828 |
{ |
| 829 |
picNum = picOrder[i].PicNum; |
| 830 |
picture = picOrder[i].Picture; |
| 831 |
picOC = picOrder[i].POC; |
| 832 |
j = i; |
| 833 |
while ((j > 0) && (picOrder[j - 1].PicNum < picNum)) |
| 834 |
{ |
| 835 |
picOrder[j].PicNum = picOrder[j - 1].PicNum; |
| 836 |
picOrder[j].Picture = picOrder[j - 1].Picture; |
| 837 |
picOrder[j].POC = picOrder[j - 1].POC; |
| 838 |
j--; |
| 839 |
reorder = true; |
| 840 |
} |
| 841 |
picOrder[j].PicNum = picNum; |
| 842 |
picOrder[j].Picture = picture; |
| 843 |
picOrder[j].POC = picOC; |
| 844 |
} |
| 845 |
|
| 846 |
// Sort picOrder[] based on polarity in field case |
| 847 |
if (CodecHal_PictureIsTopField(params->CurrPic)) |
| 848 |
{ |
| 849 |
while ((topIdx < (slcParams->num_ref_idx_l0_active_minus1 + 1)) || |
| 850 |
(botIdx < (slcParams->num_ref_idx_l0_active_minus1 + 1))) |
| 851 |
{ |
| 852 |
for (; topIdx < (slcParams->num_ref_idx_l0_active_minus1 + 1); topIdx++) |
| 853 |
{ |
| 854 |
if (CodecHal_PictureIsTopField(picOrder[topIdx].Picture)) //TOP_FIELD |
| 855 |
{ |
| 856 |
pTempPicOrder[listSize].PicNum = picOrder[topIdx].PicNum; |
| 857 |
pTempPicOrder[listSize].Picture = picOrder[topIdx].Picture; |
| 858 |
pTempPicOrder[listSize].POC = picOrder[topIdx].POC; |
| 859 |
listSize++; |
| 860 |
topIdx++; |
| 861 |
break; |
| 862 |
} |
| 863 |
} |
| 864 |
for (; botIdx < (slcParams->num_ref_idx_l0_active_minus1 + 1); botIdx++) |
| 865 |
{ |
| 866 |
if (CodecHal_PictureIsBottomField(picOrder[botIdx].Picture)) //BOTTOM_FIELD |
| 867 |
{ |
| 868 |
pTempPicOrder[listSize].PicNum = picOrder[botIdx].PicNum; |
| 869 |
pTempPicOrder[listSize].Picture = picOrder[botIdx].Picture; |
| 870 |
pTempPicOrder[listSize].POC = picOrder[botIdx].POC; |
| 871 |
listSize++; |
| 872 |
botIdx++; |
| 873 |
break; |
| 874 |
} |
| 875 |
} |
| 876 |
} |
| 877 |
} |
| 878 |
if (CodecHal_PictureIsBottomField(params->CurrPic)) |
| 879 |
{ |
| 880 |
while ((topIdx < (slcParams->num_ref_idx_l0_active_minus1 + 1)) || |
| 881 |
(botIdx < (slcParams->num_ref_idx_l0_active_minus1 + 1))) |
| 882 |
{ |
| 883 |
for (; botIdx < (slcParams->num_ref_idx_l0_active_minus1 + 1); botIdx++) |
| 884 |
{ |
| 885 |
if (CodecHal_PictureIsBottomField(picOrder[botIdx].Picture)) //BOTTOM_FIELD |
| 886 |
{ |
| 887 |
pTempPicOrder[listSize].PicNum = picOrder[botIdx].PicNum; |
| 888 |
pTempPicOrder[listSize].Picture = picOrder[botIdx].Picture; |
| 889 |
pTempPicOrder[listSize].POC = picOrder[botIdx].POC; |
| 890 |
listSize++; |
| 891 |
botIdx++; |
| 892 |
break; |
| 893 |
} |
| 894 |
} |
| 895 |
for (; topIdx < (slcParams->num_ref_idx_l0_active_minus1 + 1); topIdx++) |
| 896 |
{ |
| 897 |
if (CodecHal_PictureIsTopField(picOrder[topIdx].Picture)) //TOP_FIELD |
| 898 |
{ |
| 899 |
pTempPicOrder[listSize].PicNum = picOrder[topIdx].PicNum; |
| 900 |
pTempPicOrder[listSize].Picture = picOrder[topIdx].Picture; |
| 901 |
pTempPicOrder[listSize].POC = picOrder[topIdx].POC; |
| 902 |
listSize++; |
| 903 |
topIdx++; |
| 904 |
break; |
| 905 |
} |
| 906 |
} |
| 907 |
} |
| 908 |
} |
| 909 |
|
| 910 |
if (!CodecHal_PictureIsFrame(params->CurrPic)) |
| 911 |
{ |
| 912 |
listSize = MOS_MIN(listSize, 32); |
| 913 |
// Copy temp array back to picOrder[] |
| 914 |
for (i = 0; i < listSize; i++) |
| 915 |
{ |
| 916 |
picOrder[i].PicNum = pTempPicOrder[i].PicNum; |
| 917 |
picOrder[i].Picture = pTempPicOrder[i].Picture; |
| 918 |
picOrder[i].POC = pTempPicOrder[i].POC; |
| 919 |
} |
| 920 |
|
| 921 |
// Check if picOrder[] has been shuffled compared to the original list |
| 922 |
reorder = false; |
| 923 |
for (i = 0; i < (slcParams->num_ref_idx_l0_active_minus1 + 1); i++) |
| 924 |
{ |
| 925 |
if (defaultPicNumOrder[i] != picOrder[i].PicNum) |
| 926 |
{ |
| 927 |
reorder = true; |
| 928 |
break; |
| 929 |
} |
| 930 |
} |
| 931 |
} |
| 932 |
|
| 933 |
if (reorder) |
| 934 |
{ |
| 935 |
slcParams->ref_pic_list_reordering_flag_l0 = 1; |
| 936 |
} |
| 937 |
else |
| 938 |
{ |
| 939 |
slcParams->ref_pic_list_reordering_flag_l0 = 0; |
| 940 |
} |
| 941 |
for (i = 0; i < (slcParams->num_ref_idx_l0_active_minus1 + 1); i++) |
| 942 |
{ |
| 943 |
botField = (CodecHal_PictureIsBottomField(picOrder[i].Picture)) ? 1 : 0; |
| 944 |
refList[picOrder[i].Picture.FrameIdx]->ucInitialIdx[0][botField] = i; |
| 945 |
} |
| 946 |
} |
| 947 |
if (params->wPictureCodingType == B_TYPE) |
| 948 |
{ |
| 949 |
} |
| 950 |
|
| 951 |
return; |
| 952 |
} |
| 953 |
|
| 954 |
static void CodecHal_PackSliceHeader_GetPicNum( |
| 955 |
PCODECHAL_ENCODE_AVC_PACK_SLC_HEADER_PARAMS params, |
| 956 |
uint8_t list) |
| 957 |
{ |
| 958 |
PCODEC_AVC_ENCODE_SLICE_PARAMS slcParams; |
| 959 |
PCODEC_REF_LIST * refList; |
| 960 |
uint32_t frameNum, frameNumWrap, picNum; |
| 961 |
uint8_t i, botField, size; |
| 962 |
CODEC_PICTURE picture; |
| 963 |
|
| 964 |
CODECHAL_ENCODE_FUNCTION_ENTER; |
| 965 |
|
| 966 |
CODECHAL_ENCODE_CHK_NULL_NO_STATUS_RETURN(params); |
| 967 |
CODECHAL_ENCODE_CHK_NULL_NO_STATUS_RETURN(params->pAvcSliceParams); |
| 968 |
CODECHAL_ENCODE_CHK_NULL_NO_STATUS_RETURN(params->ppRefList); |
| 969 |
|
| 970 |
slcParams = params->pAvcSliceParams; |
| 971 |
refList = params->ppRefList; |
| 972 |
|
| 973 |
size = list ? (slcParams->num_ref_idx_l1_active_minus1 + 1) : (slcParams->num_ref_idx_l0_active_minus1 + 1); |
| 974 |
|
| 975 |
for (i = 0; i < size; i++) |
| 976 |
{ |
| 977 |
picture = slcParams->PicOrder[list][i].Picture; |
| 978 |
botField = (CodecHal_PictureIsBottomField(picture)) ? 1 : 0; |
| 979 |
refList[picture.FrameIdx]->ucFinalIdx[list][botField] = i; |
| 980 |
frameNum = refList[picture.FrameIdx]->sFrameNumber; |
| 981 |
if (frameNum > (uint32_t)refList[params->CurrReconPic.FrameIdx]->sFrameNumber) |
| 982 |
{ |
| 983 |
frameNumWrap = frameNum - slcParams->MaxFrameNum; |
| 984 |
} |
| 985 |
else |
| 986 |
{ |
| 987 |
frameNumWrap = frameNum; |
| 988 |
} |
| 989 |
|
| 990 |
if (CodecHal_PictureIsFrame(params->CurrPic)) |
| 991 |
{ |
| 992 |
picNum = frameNumWrap; |
| 993 |
} |
| 994 |
else if ((CodecHal_PictureIsTopField(params->CurrPic) && |
| 995 |
CodecHal_PictureIsTopField(picture)) || |
| 996 |
(CodecHal_PictureIsBottomField(params->CurrPic) && |
| 997 |
CodecHal_PictureIsBottomField(picture))) |
| 998 |
{ |
| 999 |
// Same polarity |
| 1000 |
picNum = (frameNumWrap << 1) + 1; |
| 1001 |
} |
| 1002 |
else |
| 1003 |
{ |
| 1004 |
picNum = frameNumWrap << 1; |
| 1005 |
} |
| 1006 |
slcParams->PicOrder[list][i].PicNum = picNum; |
| 1007 |
slcParams->PicOrder[list][i].POC = |
| 1008 |
refList[picture.FrameIdx]->iFieldOrderCnt[botField]; |
| 1009 |
} |
| 1010 |
|
| 1011 |
return; |
| 1012 |
} |
| 1013 |
|
| 1014 |
static MOS_STATUS CodecHal_PackSliceHeader_SetRefPicListParam( |
| 1015 |
PCODECHAL_ENCODE_AVC_PACK_SLC_HEADER_PARAMS params, |
| 1016 |
uint8_t list) |
| 1017 |
{ |
| 1018 |
PCODEC_AVC_ENCODE_SLICE_PARAMS slcParams; |
| 1019 |
PCODEC_REF_LIST * refList; |
| 1020 |
PCODEC_PIC_REORDER picOrder; |
| 1021 |
uint8_t i, j, idx, picIdx, numReorder, numActiveMinus1, refPolarity; |
| 1022 |
uint32_t picNumPred, currPicNum, picNumNoWrap, maxPicNum; |
| 1023 |
int16_t frameNum; |
| 1024 |
MOS_STATUS eStatus = MOS_STATUS_SUCCESS; |
| 1025 |
|
| 1026 |
CODECHAL_ENCODE_FUNCTION_ENTER; |
| 1027 |
|
| 1028 |
CODECHAL_ENCODE_CHK_NULL_RETURN(params); |
| 1029 |
CODECHAL_ENCODE_CHK_NULL_RETURN(params->pAvcSliceParams); |
| 1030 |
CODECHAL_ENCODE_CHK_NULL_RETURN(params->ppRefList); |
| 1031 |
|
| 1032 |
slcParams = params->pAvcSliceParams; |
| 1033 |
refList = params->ppRefList; |
| 1034 |
frameNum = refList[params->CurrReconPic.FrameIdx]->sFrameNumber; |
| 1035 |
|
| 1036 |
currPicNum = (CodecHal_PictureIsFrame(params->CurrPic)) ? frameNum : 2 * frameNum + 1; |
| 1037 |
picNumPred = currPicNum; |
| 1038 |
maxPicNum = (CodecHal_PictureIsFrame(params->CurrPic)) ? slcParams->MaxFrameNum : (2 * slcParams->MaxFrameNum); |
| 1039 |
|
| 1040 |
numActiveMinus1 = list ? slcParams->num_ref_idx_l1_active_minus1 : slcParams->num_ref_idx_l0_active_minus1; |
| 1041 |
|
| 1042 |
picOrder = &slcParams->PicOrder[list][0]; |
| 1043 |
|
| 1044 |
idx = 0; |
| 1045 |
picIdx = picOrder[idx].Picture.FrameIdx; |
| 1046 |
refPolarity = (CodecHal_PictureIsBottomField(picOrder[idx].Picture)) ? 1 : 0; |
| 1047 |
if (refList[picIdx]->ucFinalIdx[list][refPolarity] == |
| 1048 |
refList[picIdx]->ucInitialIdx[list][refPolarity]) |
| 1049 |
{ |
| 1050 |
// Should never happen, something must be wrong in CodecHal_PackSliceHeader_SetInitialRefPicList() |
| 1051 |
CODECHAL_ENCODE_ASSERT(false); |
| 1052 |
if (list) // L1 |
| 1053 |
{ |
| 1054 |
slcParams->ref_pic_list_reordering_flag_l1 = 0; |
| 1055 |
} |
| 1056 |
else // L0 |
| 1057 |
{ |
| 1058 |
slcParams->ref_pic_list_reordering_flag_l0 = 0; |
| 1059 |
} |
| 1060 |
eStatus = MOS_STATUS_UNKNOWN; |
| 1061 |
return eStatus; |
| 1062 |
} |
| 1063 |
|
| 1064 |
numReorder = refList[picIdx]->ucFinalIdx[list][refPolarity] - refList[picIdx]->ucInitialIdx[list][refPolarity]; |
| 1065 |
if (numReorder > numActiveMinus1) |
| 1066 |
{ |
| 1067 |
numReorder = numActiveMinus1; |
| 1068 |
} |
| 1069 |
slcParams->NumReorder = numReorder; |
| 1070 |
do |
| 1071 |
{ |
| 1072 |
for (i = (idx + 1); i <= numActiveMinus1; i++) |
| 1073 |
{ |
| 1074 |
picIdx = picOrder[i].Picture.FrameIdx; |
| 1075 |
refPolarity = (CodecHal_PictureIsBottomField(picOrder[i].Picture)) ? 1 : 0; |
| 1076 |
if (refList[picIdx]->ucFinalIdx[list][refPolarity] == idx) |
| 1077 |
{ |
| 1078 |
break; |
| 1079 |
} |
| 1080 |
} |
| 1081 |
if (i == (numActiveMinus1 + 1)) |
| 1082 |
{ |
| 1083 |
// Should never happen, something must be wrong |
| 1084 |
CODECHAL_ENCODE_ASSERT(false); |
| 1085 |
if (list) // L1 |
| 1086 |
{ |
| 1087 |
slcParams->ref_pic_list_reordering_flag_l1 = 0; |
| 1088 |
} |
| 1089 |
else // L0 |
| 1090 |
{ |
| 1091 |
slcParams->ref_pic_list_reordering_flag_l0 = 0; |
| 1092 |
} |
| 1093 |
eStatus = MOS_STATUS_UNKNOWN; |
| 1094 |
return eStatus; |
| 1095 |
} |
| 1096 |
|
| 1097 |
if (picOrder[i].PicNum > picNumPred) |
| 1098 |
{ |
| 1099 |
picOrder[idx].ReorderPicNumIDC = 1; |
| 1100 |
} |
| 1101 |
else |
| 1102 |
{ |
| 1103 |
picOrder[idx].ReorderPicNumIDC = 0; |
| 1104 |
} |
| 1105 |
|
| 1106 |
if (picOrder[i].PicNum > currPicNum) |
| 1107 |
{ |
| 1108 |
picNumNoWrap = picOrder[i].PicNum + maxPicNum; |
| 1109 |
} |
| 1110 |
else |
| 1111 |
{ |
| 1112 |
picNumNoWrap = picOrder[i].PicNum; |
| 1113 |
} |
| 1114 |
|
| 1115 |
if (picOrder[idx].ReorderPicNumIDC == 0) |
| 1116 |
{ |
| 1117 |
if (picNumPred > picNumNoWrap) |
| 1118 |
{ |
| 1119 |
picOrder[idx].DiffPicNumMinus1 = picNumPred - picNumNoWrap - 1; |
| 1120 |
} |
| 1121 |
else |
| 1122 |
{ |
| 1123 |
picOrder[idx].DiffPicNumMinus1 = picNumPred + maxPicNum - picNumNoWrap - 1; |
| 1124 |
} |
| 1125 |
} |
| 1126 |
else |
| 1127 |
{ |
| 1128 |
if (picNumNoWrap > picNumPred) |
| 1129 |
{ |
| 1130 |
picOrder[idx].DiffPicNumMinus1 = picNumNoWrap - picNumPred - 1; |
| 1131 |
} |
| 1132 |
else |
| 1133 |
{ |
| 1134 |
picOrder[idx].DiffPicNumMinus1 = picNumNoWrap + maxPicNum - picNumPred - 1; |
| 1135 |
} |
| 1136 |
} |
| 1137 |
picNumPred = picNumNoWrap; |
| 1138 |
|
| 1139 |
for (j = i; j > idx; j--) |
| 1140 |
{ |
| 1141 |
picOrder[j].Picture = picOrder[j - 1].Picture; |
| 1142 |
picOrder[j].PicNum = picOrder[j - 1].PicNum; |
| 1143 |
picOrder[j].POC = picOrder[j - 1].POC; |
| 1144 |
} |
| 1145 |
|
| 1146 |
idx++; |
| 1147 |
} while (--numReorder); |
| 1148 |
picOrder[idx].ReorderPicNumIDC = 3; |
| 1149 |
|
| 1150 |
return eStatus; |
| 1151 |
} |
| 1152 |
|
| 1153 |
static MOS_STATUS CodecHal_PackSliceHeader_PredWeightTable( |
| 1154 |
PCODECHAL_ENCODE_AVC_PACK_SLC_HEADER_PARAMS params) |
| 1155 |
{ |
| 1156 |
PCODEC_AVC_ENCODE_SLICE_PARAMS slcParams; |
| 1157 |
PBSBuffer bsbuffer; |
| 1158 |
int16_t weight, offset, weight2, offset2; |
| 1159 |
uint8_t i, weight_flag, chromaIDC; |
| 1160 |
MOS_STATUS eStatus = MOS_STATUS_SUCCESS; |
| 1161 |
|
| 1162 |
CODECHAL_ENCODE_CHK_NULL_RETURN(params); |
| 1163 |
CODECHAL_ENCODE_CHK_NULL_RETURN(params->pSeqParams); |
| 1164 |
CODECHAL_ENCODE_CHK_NULL_RETURN(params->pAvcSliceParams); |
| 1165 |
CODECHAL_ENCODE_CHK_NULL_RETURN(params->pBsBuffer); |
| 1166 |
|
| 1167 |
bsbuffer = params->pBsBuffer; |
| 1168 |
slcParams = params->pAvcSliceParams; |
| 1169 |
chromaIDC = params->pSeqParams->chroma_format_idc; |
| 1170 |
|
| 1171 |
PutVLCCode(bsbuffer, slcParams->luma_log2_weight_denom); |
| 1172 |
|
| 1173 |
if (chromaIDC) |
| 1174 |
{ |
| 1175 |
PutVLCCode(bsbuffer, slcParams->chroma_log2_weight_denom); |
| 1176 |
} |
| 1177 |
|
| 1178 |
for (i = 0; i <= slcParams->num_ref_idx_l0_active_minus1; i++) |
| 1179 |
{ |
| 1180 |
// Luma |
| 1181 |
weight = slcParams->Weights[0][i][0][0]; |
| 1182 |
offset = slcParams->Weights[0][i][0][1]; |
| 1183 |
weight_flag = (weight != (1 << slcParams->luma_log2_weight_denom)) || (offset != 0); |
| 1184 |
PutBit(bsbuffer, weight_flag); |
| 1185 |
if (weight_flag) |
| 1186 |
{ |
| 1187 |
PutVLCCode(bsbuffer, SIGNED(weight)); |
| 1188 |
PutVLCCode(bsbuffer, SIGNED(offset)); |
| 1189 |
} |
| 1190 |
|
| 1191 |
// Chroma |
| 1192 |
if (chromaIDC) |
| 1193 |
{ |
| 1194 |
weight = slcParams->Weights[0][i][1][0]; |
| 1195 |
offset = slcParams->Weights[0][i][1][1]; |
| 1196 |
weight2 = slcParams->Weights[0][i][2][0]; |
| 1197 |
offset2 = slcParams->Weights[0][i][2][1]; |
| 1198 |
weight_flag = (weight != (1 << slcParams->chroma_log2_weight_denom)) || |
| 1199 |
(weight2 != (1 << slcParams->chroma_log2_weight_denom)) || |
| 1200 |
(offset != 0) || (offset2 != 0); |
| 1201 |
PutBit(bsbuffer, weight_flag); |
| 1202 |
if (weight_flag) |
| 1203 |
{ |
| 1204 |
PutVLCCode(bsbuffer, SIGNED(weight)); |
| 1205 |
PutVLCCode(bsbuffer, SIGNED(offset)); |
| 1206 |
PutVLCCode(bsbuffer, SIGNED(weight2)); |
| 1207 |
PutVLCCode(bsbuffer, SIGNED(offset2)); |
| 1208 |
} |
| 1209 |
} |
| 1210 |
} |
| 1211 |
|
| 1212 |
if (Slice_Type[slcParams->slice_type] == SLICE_B) |
| 1213 |
{ |
| 1214 |
for (i = 0; i <= slcParams->num_ref_idx_l1_active_minus1; i++) |
| 1215 |
{ |
| 1216 |
// Luma |
| 1217 |
weight = slcParams->Weights[1][i][0][0]; |
| 1218 |
offset = slcParams->Weights[1][i][0][1]; |
| 1219 |
weight_flag = (weight != (1 << slcParams->luma_log2_weight_denom)) || (offset != 0); |
| 1220 |
PutBit(bsbuffer, weight_flag); |
| 1221 |
if (weight_flag) |
| 1222 |
{ |
| 1223 |
PutVLCCode(bsbuffer, SIGNED(weight)); |
| 1224 |
PutVLCCode(bsbuffer, SIGNED(offset)); |
| 1225 |
} |
| 1226 |
|
| 1227 |
// Chroma |
| 1228 |
if (chromaIDC) |
| 1229 |
{ |
| 1230 |
weight = slcParams->Weights[1][i][1][0]; |
| 1231 |
offset = slcParams->Weights[1][i][1][1]; |
| 1232 |
weight2 = slcParams->Weights[1][i][2][0]; |
| 1233 |
offset2 = slcParams->Weights[1][i][2][1]; |
| 1234 |
weight_flag = (weight != (1 << slcParams->chroma_log2_weight_denom)) || |
| 1235 |
(weight2 != (1 << slcParams->chroma_log2_weight_denom)) || |
| 1236 |
(offset != 0) || (offset2 != 0); |
| 1237 |
PutBit(bsbuffer, weight_flag); |
| 1238 |
if (weight_flag) |
| 1239 |
{ |
| 1240 |
PutVLCCode(bsbuffer, SIGNED(weight)); |
| 1241 |
PutVLCCode(bsbuffer, SIGNED(offset)); |
| 1242 |
PutVLCCode(bsbuffer, SIGNED(weight2)); |
| 1243 |
PutVLCCode(bsbuffer, SIGNED(offset2)); |
| 1244 |
} |
| 1245 |
} |
| 1246 |
} |
| 1247 |
} |
| 1248 |
|
| 1249 |
return eStatus; |
| 1250 |
} |
| 1251 |
|
| 1252 |
static MOS_STATUS CodecHal_PackSliceHeader_MMCO( |
| 1253 |
PCODECHAL_ENCODE_AVC_PACK_SLC_HEADER_PARAMS params) |
| 1254 |
{ |
| 1255 |
PCODEC_AVC_ENCODE_SLICE_PARAMS slcParams; |
| 1256 |
PBSBuffer bsbuffer; |
| 1257 |
MOS_STATUS eStatus = MOS_STATUS_SUCCESS; |
| 1258 |
|
| 1259 |
CODECHAL_ENCODE_CHK_NULL_RETURN(params); |
| 1260 |
CODECHAL_ENCODE_CHK_NULL_RETURN(params->pAvcSliceParams); |
| 1261 |
CODECHAL_ENCODE_CHK_NULL_RETURN(params->pBsBuffer); |
| 1262 |
|
| 1263 |
bsbuffer = params->pBsBuffer; |
| 1264 |
slcParams = params->pAvcSliceParams; |
| 1265 |
|
| 1266 |
PCODEC_SLICE_MMCO mmco = &slcParams->MMCO[0]; |
| 1267 |
do |
| 1268 |
{ |
| 1269 |
PutVLCCode(bsbuffer, mmco->MmcoIDC); |
| 1270 |
if (mmco->MmcoIDC == 1 || |
| 1271 |
mmco->MmcoIDC == 3) |
| 1272 |
PutVLCCode(bsbuffer, mmco->DiffPicNumMinus1); |
| 1273 |
if (mmco->MmcoIDC == 2) |
| 1274 |
PutVLCCode(bsbuffer, mmco->LongTermPicNum); |
| 1275 |
if (mmco->MmcoIDC == 3 || |
| 1276 |
mmco->MmcoIDC == 6) |
| 1277 |
PutVLCCode(bsbuffer, mmco->LongTermFrameIdx); |
| 1278 |
if (mmco->MmcoIDC == 4) |
| 1279 |
PutVLCCode(bsbuffer, mmco->MaxLongTermFrameIdxPlus1); |
| 1280 |
} while ((mmco++)->MmcoIDC != 0); |
| 1281 |
|
| 1282 |
return eStatus; |
| 1283 |
} |
| 1284 |
|
| 1285 |
//! |
| 1286 |
//! \brief Pack AUD parameters |
| 1287 |
//! |
| 1288 |
//! \param [in] params |
| 1289 |
//! Pointer to codechal encode Avc pack picture header parameter |
| 1290 |
//! |
| 1291 |
//! \return MOS_STATUS |
| 1292 |
//! Return MOS_STATUS_SUCCESS if call success, else fail reason |
| 1293 |
//! |
| 1294 |
MOS_STATUS CodecHal_PackPictureHeader_AUDParams( |
| 1295 |
PCODECHAL_ENCODE_AVC_PACK_PIC_HEADER_PARAMS params) |
| 1296 |
{ |
| 1297 |
uint32_t picType; |
| 1298 |
MOS_STATUS eStatus = MOS_STATUS_SUCCESS; |
| 1299 |
|
| 1300 |
CODECHAL_ENCODE_CHK_NULL_RETURN(params); |
| 1301 |
CODECHAL_ENCODE_CHK_NULL_RETURN(params->pBsBuffer); |
| 1302 |
|
| 1303 |
// refer table 7-5 in H.264 spec on primary_pic_type |
| 1304 |
// Here I,P,B types are included |
| 1305 |
// According BD Spec 9.5.1.1, 0 - I; 1 - P; 2 - B |
| 1306 |
|
| 1307 |
picType = (uint32_t)(params->wPictureCodingType) - 1; |
| 1308 |
PutBits(params->pBsBuffer, picType, 3); |
| 1309 |
|
| 1310 |
return eStatus; |
| 1311 |
} |
| 1312 |
|
| 1313 |
// Refer to H264 picture reordering session |
| 1314 |
static MOS_STATUS CodecHal_PackSliceHeader_RefPicListReordering( |
| 1315 |
PCODECHAL_ENCODE_AVC_PACK_SLC_HEADER_PARAMS params) |
| 1316 |
{ |
| 1317 |
PCODEC_AVC_ENCODE_SLICE_PARAMS slcParams; |
| 1318 |
PBSBuffer bsbuffer; |
| 1319 |
CODEC_PIC_REORDER * picOrder; |
| 1320 |
uint8_t sliceType; |
| 1321 |
MOS_STATUS eStatus = MOS_STATUS_SUCCESS; |
| 1322 |
|
| 1323 |
CODECHAL_ENCODE_CHK_NULL_RETURN(params); |
| 1324 |
CODECHAL_ENCODE_CHK_NULL_RETURN(params->pAvcSliceParams); |
| 1325 |
|
| 1326 |
slcParams = params->pAvcSliceParams; |
| 1327 |
bsbuffer = params->pBsBuffer; |
| 1328 |
sliceType = Slice_Type[slcParams->slice_type]; |
| 1329 |
|
| 1330 |
if (!params->UserFlags.bDisableAcceleratorRefPicListReordering) |
| 1331 |
{ |
| 1332 |
// Generate the initial reference list (PicOrder) |
| 1333 |
CodecHal_PackSliceHeader_SetInitialRefPicList(params); |
| 1334 |
} |
| 1335 |
|
| 1336 |
if (sliceType != SLICE_I && sliceType != SLICE_SI) |
| 1337 |
{ |
| 1338 |
if (slcParams->ref_pic_list_reordering_flag_l0) |
| 1339 |
{ |
| 1340 |
if (!params->UserFlags.bDisableAcceleratorRefPicListReordering) |
| 1341 |
{ |
| 1342 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(CodecHal_PackSliceHeader_SetRefPicListParam(params, 0)); |
| 1343 |
} |
| 1344 |
|
| 1345 |
PutBit(bsbuffer, slcParams->ref_pic_list_reordering_flag_l0); |
| 1346 |
|
| 1347 |
if (slcParams->ref_pic_list_reordering_flag_l0) |
| 1348 |
{ |
| 1349 |
picOrder = &slcParams->PicOrder[0][0]; |
| 1350 |
do |
| 1351 |
{ |
| 1352 |
PutVLCCode(bsbuffer, picOrder->ReorderPicNumIDC); |
| 1353 |
if (picOrder->ReorderPicNumIDC == 0 || |
| 1354 |
picOrder->ReorderPicNumIDC == 1) |
| 1355 |
{ |
| 1356 |
PutVLCCode(bsbuffer, picOrder->DiffPicNumMinus1); |
| 1357 |
} else |
| 1358 |
if (picOrder->ReorderPicNumIDC == 2) |
| 1359 |
{ |
| 1360 |
PutVLCCode(bsbuffer, picOrder->LongTermPicNum); |
| 1361 |
} |
| 1362 |
} while ((picOrder++)->ReorderPicNumIDC != 3); |
| 1363 |
} |
| 1364 |
} |
| 1365 |
else |
| 1366 |
{ |
| 1367 |
PutBit(bsbuffer, slcParams->ref_pic_list_reordering_flag_l0); |
| 1368 |
} |
| 1369 |
} |
| 1370 |
if (sliceType == SLICE_B) |
| 1371 |
{ |
| 1372 |
if (slcParams->ref_pic_list_reordering_flag_l1) |
| 1373 |
{ |
| 1374 |
if (!params->UserFlags.bDisableAcceleratorRefPicListReordering) |
| 1375 |
{ |
| 1376 |
CodecHal_PackSliceHeader_SetRefPicListParam(params, 1); |
| 1377 |
} |
| 1378 |
|
| 1379 |
PutBit(bsbuffer, slcParams->ref_pic_list_reordering_flag_l1); |
| 1380 |
|
| 1381 |
if (slcParams->ref_pic_list_reordering_flag_l1) |
| 1382 |
{ |
| 1383 |
picOrder = &slcParams->PicOrder[1][0]; |
| 1384 |
do |
| 1385 |
{ |
| 1386 |
PutVLCCode(bsbuffer, picOrder->ReorderPicNumIDC); |
| 1387 |
if (picOrder->ReorderPicNumIDC == 0 || |
| 1388 |
picOrder->ReorderPicNumIDC == 1) |
| 1389 |
{ |
| 1390 |
PutVLCCode(bsbuffer, picOrder->DiffPicNumMinus1); |
| 1391 |
} else |
| 1392 |
if (picOrder->ReorderPicNumIDC == 2) |
| 1393 |
{ |
| 1394 |
PutVLCCode(bsbuffer, picOrder->PicNum); |
| 1395 |
} |
| 1396 |
} while ((picOrder++)->ReorderPicNumIDC != 3); |
| 1397 |
} |
| 1398 |
} |
| 1399 |
else |
| 1400 |
{ |
| 1401 |
PutBit(bsbuffer, slcParams->ref_pic_list_reordering_flag_l1); |
| 1402 |
} |
| 1403 |
} |
| 1404 |
|
| 1405 |
return eStatus; |
| 1406 |
} |
| 1407 |
|
| 1408 |
//! |
| 1409 |
//! \brief Pack sequence parameters |
| 1410 |
//! |
| 1411 |
//! \param [in] params |
| 1412 |
//! Pointer to codechal encode Avc pack picture header parameter |
| 1413 |
//! |
| 1414 |
//! \return MOS_STATUS |
| 1415 |
//! Return MOS_STATUS_SUCCESS if call success, else fail reason |
| 1416 |
//! |
| 1417 |
MOS_STATUS CodecHal_PackPictureHeader_SeqParams( |
| 1418 |
PCODECHAL_ENCODE_AVC_PACK_PIC_HEADER_PARAMS params) |
| 1419 |
{ |
| 1420 |
PCODEC_AVC_ENCODE_SEQUENCE_PARAMS seqParams; |
| 1421 |
BSBuffer * bsbuffer; |
| 1422 |
uint8_t i; |
| 1423 |
MOS_STATUS eStatus = MOS_STATUS_SUCCESS; |
| 1424 |
|
| 1425 |
CODECHAL_ENCODE_CHK_NULL_RETURN(params); |
| 1426 |
CODECHAL_ENCODE_CHK_NULL_RETURN(params->pBsBuffer); |
| 1427 |
CODECHAL_ENCODE_CHK_NULL_RETURN(params->pSeqParams); |
| 1428 |
|
| 1429 |
seqParams = params->pSeqParams; |
| 1430 |
bsbuffer = params->pBsBuffer; |
| 1431 |
|
| 1432 |
PutBits(bsbuffer, seqParams->Profile, 8); |
| 1433 |
|
| 1434 |
PutBit(bsbuffer, seqParams->constraint_set0_flag); |
| 1435 |
PutBit(bsbuffer, seqParams->constraint_set1_flag); |
| 1436 |
PutBit(bsbuffer, seqParams->constraint_set2_flag); |
| 1437 |
PutBit(bsbuffer, seqParams->constraint_set3_flag); |
| 1438 |
|
| 1439 |
PutBits(bsbuffer, 0, 4); |
| 1440 |
PutBits(bsbuffer, seqParams->Level, 8); |
| 1441 |
PutVLCCode(bsbuffer, seqParams->seq_parameter_set_id); |
| 1442 |
|
| 1443 |
if (seqParams->Profile == CODEC_AVC_HIGH_PROFILE || |
| 1444 |
seqParams->Profile == CODEC_AVC_HIGH10_PROFILE || |
| 1445 |
seqParams->Profile == CODEC_AVC_HIGH422_PROFILE || |
| 1446 |
seqParams->Profile == CODEC_AVC_HIGH444_PROFILE || |
| 1447 |
seqParams->Profile == CODEC_AVC_CAVLC444_INTRA_PROFILE || |
| 1448 |
seqParams->Profile == CODEC_AVC_SCALABLE_BASE_PROFILE || |
| 1449 |
seqParams->Profile == CODEC_AVC_SCALABLE_HIGH_PROFILE) |
| 1450 |
{ |
| 1451 |
PutVLCCode(bsbuffer, seqParams->chroma_format_idc); |
| 1452 |
if (seqParams->chroma_format_idc == 3) |
| 1453 |
{ |
| 1454 |
PutBit(bsbuffer, seqParams->separate_colour_plane_flag); |
| 1455 |
} |
| 1456 |
PutVLCCode(bsbuffer, seqParams->bit_depth_luma_minus8); |
| 1457 |
PutVLCCode(bsbuffer, seqParams->bit_depth_chroma_minus8); |
| 1458 |
PutBit(bsbuffer, seqParams->qpprime_y_zero_transform_bypass_flag); |
| 1459 |
PutBit(bsbuffer, seqParams->seq_scaling_matrix_present_flag); |
| 1460 |
if (seqParams->seq_scaling_matrix_present_flag) |
| 1461 |
{ |
| 1462 |
//Iterate thro' the scaling lists. Refer to ITU-T H.264 std. section 7.3.2.1 |
| 1463 |
for (i = 0; i < 8; i++) |
| 1464 |
{ |
| 1465 |
// scaling list present flag |
| 1466 |
PutBit(bsbuffer, seqParams->seq_scaling_list_present_flag[i]); |
| 1467 |
if (seqParams->seq_scaling_list_present_flag[i]) |
| 1468 |
{ |
| 1469 |
if (i < 6) |
| 1470 |
{ |
| 1471 |
PackScalingList(bsbuffer, ¶ms->pAvcIQMatrixParams->ScalingList4x4[i][0], 16); |
| 1472 |
} |
| 1473 |
else |
| 1474 |
{ |
| 1475 |
PackScalingList(bsbuffer, ¶ms->pAvcIQMatrixParams->ScalingList8x8[i - 6][0], 64); |
| 1476 |
} |
| 1477 |
} |
| 1478 |
} |
| 1479 |
} |
| 1480 |
} |
| 1481 |
|
| 1482 |
PutVLCCode(bsbuffer, seqParams->log2_max_frame_num_minus4); |
| 1483 |
PutVLCCode(bsbuffer, seqParams->pic_order_cnt_type); |
| 1484 |
if (seqParams->pic_order_cnt_type == 0) |
| 1485 |
{ |
| 1486 |
PutVLCCode(bsbuffer, seqParams->log2_max_pic_order_cnt_lsb_minus4); |
| 1487 |
} |
| 1488 |
else if (seqParams->pic_order_cnt_type == 1) |
| 1489 |
{ |
| 1490 |
PutBit(bsbuffer, seqParams->delta_pic_order_always_zero_flag); |
| 1491 |
PutVLCCode(bsbuffer, SIGNED(seqParams->offset_for_non_ref_pic)); |
| 1492 |
PutVLCCode(bsbuffer, SIGNED(seqParams->offset_for_top_to_bottom_field)); |
| 1493 |
PutVLCCode(bsbuffer, seqParams->num_ref_frames_in_pic_order_cnt_cycle); |
| 1494 |
for (i = 0; i < seqParams->num_ref_frames_in_pic_order_cnt_cycle; i++) |
| 1495 |
{ |
| 1496 |
PutVLCCode(bsbuffer, SIGNED(seqParams->offset_for_ref_frame[i])); |
| 1497 |
} |
| 1498 |
} |
| 1499 |
|
| 1500 |
PutVLCCode(bsbuffer, seqParams->NumRefFrames); |
| 1501 |
PutBit(bsbuffer, seqParams->gaps_in_frame_num_value_allowed_flag); |
| 1502 |
PutVLCCode(bsbuffer, seqParams->pic_width_in_mbs_minus1); |
| 1503 |
PutVLCCode(bsbuffer, seqParams->pic_height_in_map_units_minus1); |
| 1504 |
PutBit(bsbuffer, seqParams->frame_mbs_only_flag); |
| 1505 |
|
| 1506 |
if (!seqParams->frame_mbs_only_flag) |
| 1507 |
{ |
| 1508 |
PutBit(bsbuffer, seqParams->mb_adaptive_frame_field_flag); |
| 1509 |
} |
| 1510 |
|
| 1511 |
PutBit(bsbuffer, seqParams->direct_8x8_inference_flag); |
| 1512 |
|
| 1513 |
if ((!seqParams->frame_cropping_flag) && |
| 1514 |
(params->dwFrameHeight != params->dwOriFrameHeight)) |
| 1515 |
{ |
| 1516 |
seqParams->frame_cropping_flag = 1; |
| 1517 |
seqParams->frame_crop_bottom_offset = |
| 1518 |
(int16_t)((params->dwFrameHeight - params->dwOriFrameHeight) >> |
| 1519 |
(2 - seqParams->frame_mbs_only_flag)); // 4:2:0 |
| 1520 |
} |
| 1521 |
|
| 1522 |
PutBit(bsbuffer, seqParams->frame_cropping_flag); |
| 1523 |
|
| 1524 |
if (seqParams->frame_cropping_flag) |
| 1525 |
{ |
| 1526 |
PutVLCCode(bsbuffer, seqParams->frame_crop_left_offset); |
| 1527 |
PutVLCCode(bsbuffer, seqParams->frame_crop_right_offset); |
| 1528 |
PutVLCCode(bsbuffer, seqParams->frame_crop_top_offset); |
| 1529 |
PutVLCCode(bsbuffer, seqParams->frame_crop_bottom_offset); |
| 1530 |
} |
| 1531 |
|
| 1532 |
PutBit(bsbuffer, seqParams->vui_parameters_present_flag); |
| 1533 |
|
| 1534 |
if (seqParams->vui_parameters_present_flag) |
| 1535 |
{ |
| 1536 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(CodecHal_PackPictureHeader_VuiParams(params)); |
| 1537 |
} |
| 1538 |
|
| 1539 |
*params->pbNewSeqHeader = 1; |
| 1540 |
|
| 1541 |
return eStatus; |
| 1542 |
} |
| 1543 |
|
| 1544 |
//! |
| 1545 |
//! \brief Pack picture parameters |
| 1546 |
//! |
| 1547 |
//! \param [in] params |
| 1548 |
//! Pointer to codechal encode Avc pack picture header parameter |
| 1549 |
//! |
| 1550 |
//! \return MOS_STATUS |
| 1551 |
//! Return MOS_STATUS_SUCCESS if call success, else fail reason |
| 1552 |
//! |
| 1553 |
MOS_STATUS CodecHal_PackPictureHeader_PicParams( |
| 1554 |
PCODECHAL_ENCODE_AVC_PACK_PIC_HEADER_PARAMS params) |
| 1555 |
{ |
| 1556 |
PCODEC_AVC_ENCODE_SEQUENCE_PARAMS seqParams; |
| 1557 |
PCODEC_AVC_ENCODE_PIC_PARAMS picParams; |
| 1558 |
PBSBuffer bsbuffer; |
| 1559 |
MOS_STATUS eStatus = MOS_STATUS_SUCCESS; |
| 1560 |
|
| 1561 |
CODECHAL_ENCODE_CHK_NULL_RETURN(params); |
| 1562 |
CODECHAL_ENCODE_CHK_NULL_RETURN(params->pSeqParams); |
| 1563 |
CODECHAL_ENCODE_CHK_NULL_RETURN(params->pPicParams); |
| 1564 |
CODECHAL_ENCODE_CHK_NULL_RETURN(params->pBsBuffer); |
| 1565 |
|
| 1566 |
seqParams = params->pSeqParams; |
| 1567 |
picParams = params->pPicParams; |
| 1568 |
bsbuffer = params->pBsBuffer; |
| 1569 |
|
| 1570 |
PutVLCCode(bsbuffer, picParams->pic_parameter_set_id); |
| 1571 |
PutVLCCode(bsbuffer, picParams->seq_parameter_set_id); |
| 1572 |
|
| 1573 |
PutBit(bsbuffer, picParams->entropy_coding_mode_flag); |
| 1574 |
PutBit(bsbuffer, picParams->pic_order_present_flag); |
| 1575 |
|
| 1576 |
PutVLCCode(bsbuffer, picParams->num_slice_groups_minus1); |
| 1577 |
|
| 1578 |
PutVLCCode(bsbuffer, picParams->num_ref_idx_l0_active_minus1); |
| 1579 |
PutVLCCode(bsbuffer, picParams->num_ref_idx_l1_active_minus1); |
| 1580 |
|
| 1581 |
PutBit(bsbuffer, picParams->weighted_pred_flag); |
| 1582 |
PutBits(bsbuffer, picParams->weighted_bipred_idc, 2); |
| 1583 |
|
| 1584 |
PutVLCCode(bsbuffer, SIGNED(picParams->pic_init_qp_minus26)); |
| 1585 |
PutVLCCode(bsbuffer, SIGNED(picParams->pic_init_qs_minus26)); |
| 1586 |
PutVLCCode(bsbuffer, SIGNED(picParams->chroma_qp_index_offset)); |
| 1587 |
|
| 1588 |
PutBit(bsbuffer, picParams->deblocking_filter_control_present_flag); |
| 1589 |
PutBit(bsbuffer, picParams->constrained_intra_pred_flag); |
| 1590 |
PutBit(bsbuffer, picParams->redundant_pic_cnt_present_flag); |
| 1591 |
|
| 1592 |
// The syntax elements transform_8x8_mode_flag, pic_scaling_matrix_present_flag, and second_chroma_qp_index_offset |
| 1593 |
// shall not be present for main profile |
| 1594 |
if (seqParams->Profile == CODEC_AVC_MAIN_PROFILE || seqParams->Profile == CODEC_AVC_BASE_PROFILE) |
| 1595 |
{ |
| 1596 |
return eStatus; |
| 1597 |
} |
| 1598 |
|
| 1599 |
PutBit(bsbuffer, picParams->transform_8x8_mode_flag); |
| 1600 |
PutBit(bsbuffer, picParams->pic_scaling_matrix_present_flag); |
| 1601 |
if (picParams->pic_scaling_matrix_present_flag) |
| 1602 |
{ |
| 1603 |
uint8_t i; |
| 1604 |
|
| 1605 |
//Iterate thro' the scaling lists. Refer to ITU-T H.264 std. section 7.3.2.2 |
| 1606 |
for (i = 0; i < 6 + 2 * picParams->transform_8x8_mode_flag; i++) |
| 1607 |
{ |
| 1608 |
//Put scaling list present flag |
| 1609 |
PutBit(bsbuffer, picParams->pic_scaling_list_present_flag[i]); |
| 1610 |
if (picParams->pic_scaling_list_present_flag[i]) |
| 1611 |
{ |
| 1612 |
if (i < 6) |
| 1613 |
{ |
| 1614 |
PackScalingList(bsbuffer, ¶ms->pAvcIQMatrixParams->ScalingList4x4[i][0], 16); |
| 1615 |
} |
| 1616 |
else |
| 1617 |
{ |
| 1618 |
PackScalingList(bsbuffer, ¶ms->pAvcIQMatrixParams->ScalingList8x8[i - 6][0], 64); |
| 1619 |
} |
| 1620 |
} |
| 1621 |
} |
| 1622 |
} |
| 1623 |
|
| 1624 |
PutVLCCode(bsbuffer, SIGNED(picParams->second_chroma_qp_index_offset)); |
| 1625 |
|
| 1626 |
*params->pbNewPPSHeader = 1; |
| 1627 |
|
| 1628 |
return eStatus; |
| 1629 |
} |
| 1630 |
|
| 1631 |
MOS_STATUS CodecHalAvcEncode_PackPictureHeader( |
| 1632 |
PCODECHAL_ENCODE_AVC_PACK_PIC_HEADER_PARAMS params) |
| 1633 |
{ |
| 1634 |
PBSBuffer bsbuffer; |
| 1635 |
uint32_t indexNALUnit; |
| 1636 |
MOS_STATUS eStatus = MOS_STATUS_SUCCESS; |
| 1637 |
|
| 1638 |
CODECHAL_ENCODE_CHK_NULL_RETURN(params); |
| 1639 |
CODECHAL_ENCODE_CHK_NULL_RETURN(params->pBsBuffer); |
| 1640 |
CODECHAL_ENCODE_CHK_NULL_RETURN(params->pSeqParams); |
| 1641 |
CODECHAL_ENCODE_CHK_NULL_RETURN(params->ppNALUnitParams); |
| 1642 |
|
| 1643 |
bsbuffer = params->pBsBuffer; |
| 1644 |
*(bsbuffer->pBase) = 0; // init first byte to 0 |
| 1645 |
bsbuffer->pCurrent = bsbuffer->pBase; |
| 1646 |
bsbuffer->SliceOffset = 0; |
| 1647 |
bsbuffer->BitOffset = 0; |
| 1648 |
bsbuffer->BitSize = 0; |
| 1649 |
|
| 1650 |
MOS_ZeroMemory(params->ppNALUnitParams[0], sizeof(CODECHAL_NAL_UNIT_PARAMS) * CODECHAL_ENCODE_AVC_MAX_NAL_TYPE); |
| 1651 |
indexNALUnit = 0; |
| 1652 |
|
| 1653 |
// AU_Delimiter |
| 1654 |
// nal_ref_idc to be 0 for all nal_unit_type equal to 6, 9, 10, 11 or12 |
| 1655 |
params->ppNALUnitParams[indexNALUnit]->uiOffset = 0; |
| 1656 |
params->ppNALUnitParams[indexNALUnit]->uiNalUnitType = CODECHAL_ENCODE_AVC_NAL_UT_AUD; |
| 1657 |
params->ppNALUnitParams[indexNALUnit]->bInsertEmulationBytes = true; |
| 1658 |
params->ppNALUnitParams[indexNALUnit]->uiSkipEmulationCheckCount = 4; |
| 1659 |
SetNalUnit(&bsbuffer->pCurrent, 0, CODECHAL_ENCODE_AVC_NAL_UT_AUD); |
| 1660 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(CodecHal_PackPictureHeader_AUDParams(params)); |
| 1661 |
SetTrailingBits(bsbuffer); |
| 1662 |
//NAL unit are byte aligned, bsbuffer->BitOffset should be 0 |
| 1663 |
params->ppNALUnitParams[indexNALUnit]->uiSize = |
| 1664 |
(uint32_t)(bsbuffer->pCurrent - |
| 1665 |
bsbuffer->pBase - |
| 1666 |
params->ppNALUnitParams[indexNALUnit]->uiOffset); |
| 1667 |
indexNALUnit++; |
| 1668 |
|
| 1669 |
// If this is a new sequence, write the seq set |
| 1670 |
if (params->bNewSeq && !params->pSeqParams->bNoAcceleratorSPSInsertion) |
| 1671 |
{ |
| 1672 |
// Pack SPS |
| 1673 |
params->ppNALUnitParams[indexNALUnit]->uiOffset = (uint32_t)(bsbuffer->pCurrent - bsbuffer->pBase); |
| 1674 |
params->ppNALUnitParams[indexNALUnit]->uiNalUnitType = CODECHAL_ENCODE_AVC_NAL_UT_SPS; |
| 1675 |
params->ppNALUnitParams[indexNALUnit]->bInsertEmulationBytes = true; |
| 1676 |
params->ppNALUnitParams[indexNALUnit]->uiSkipEmulationCheckCount = 4; |
| 1677 |
SetNalUnit(&bsbuffer->pCurrent, 1, CODECHAL_ENCODE_AVC_NAL_UT_SPS); |
| 1678 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(CodecHal_PackPictureHeader_SeqParams(params)); |
| 1679 |
SetTrailingBits(bsbuffer); |
| 1680 |
params->ppNALUnitParams[indexNALUnit]->uiSize = |
| 1681 |
(uint32_t)(bsbuffer->pCurrent - |
| 1682 |
bsbuffer->pBase - |
| 1683 |
params->ppNALUnitParams[indexNALUnit]->uiOffset); |
| 1684 |
indexNALUnit++; |
| 1685 |
} |
| 1686 |
|
| 1687 |
// Pack PPS |
| 1688 |
params->ppNALUnitParams[indexNALUnit]->uiOffset = (uint32_t)(bsbuffer->pCurrent - bsbuffer->pBase); |
| 1689 |
params->ppNALUnitParams[indexNALUnit]->uiNalUnitType = CODECHAL_ENCODE_AVC_NAL_UT_PPS; |
| 1690 |
params->ppNALUnitParams[indexNALUnit]->bInsertEmulationBytes = true; |
| 1691 |
params->ppNALUnitParams[indexNALUnit]->uiSkipEmulationCheckCount = 4; |
| 1692 |
SetNalUnit(&bsbuffer->pCurrent, 1, CODECHAL_ENCODE_AVC_NAL_UT_PPS); |
| 1693 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(CodecHal_PackPictureHeader_PicParams(params)); |
| 1694 |
SetTrailingBits(bsbuffer); |
| 1695 |
params->ppNALUnitParams[indexNALUnit]->uiSize = |
| 1696 |
(uint32_t)(bsbuffer->pCurrent - |
| 1697 |
bsbuffer->pBase - |
| 1698 |
params->ppNALUnitParams[indexNALUnit]->uiOffset); |
| 1699 |
indexNALUnit++; |
| 1700 |
|
| 1701 |
// Pack SEI |
| 1702 |
if (params->pSeiData->newSEIData) |
| 1703 |
{ |
| 1704 |
params->ppNALUnitParams[indexNALUnit]->uiOffset = (uint32_t)(bsbuffer->pCurrent - bsbuffer->pBase); |
| 1705 |
params->ppNALUnitParams[indexNALUnit]->uiNalUnitType = CODECHAL_ENCODE_AVC_NAL_UT_SEI; |
| 1706 |
params->ppNALUnitParams[indexNALUnit]->bInsertEmulationBytes = false; |
| 1707 |
params->ppNALUnitParams[indexNALUnit]->uiSkipEmulationCheckCount = 4; |
| 1708 |
eStatus = MOS_SecureMemcpy(bsbuffer->pCurrent, |
| 1709 |
params->pSeiData->dwSEIBufSize, |
| 1710 |
params->pSeiData->pSEIBuffer, |
| 1711 |
params->pSeiData->dwSEIBufSize); |
| 1712 |
if (eStatus != MOS_STATUS_SUCCESS) |
| 1713 |
{ |
| 1714 |
CODECHAL_ENCODE_ASSERTMESSAGE("Failed to copy memory."); |
| 1715 |
return eStatus; |
| 1716 |
} |
| 1717 |
bsbuffer->pCurrent += params->pSeiData->dwSEIDataSize; |
| 1718 |
params->pSeiData->newSEIData = false; |
| 1719 |
params->ppNALUnitParams[indexNALUnit]->uiSize = |
| 1720 |
(uint32_t)(bsbuffer->pCurrent - |
| 1721 |
bsbuffer->pBase - |
| 1722 |
params->ppNALUnitParams[indexNALUnit]->uiOffset); |
| 1723 |
indexNALUnit++; |
| 1724 |
} |
| 1725 |
|
| 1726 |
bsbuffer->SliceOffset = (uint32_t)(bsbuffer->pCurrent - bsbuffer->pBase); |
| 1727 |
|
| 1728 |
return eStatus; |
| 1729 |
} |
| 1730 |
|
| 1731 |
uint16_t CodecHalAvcEncode_GetMaxNumSlicesAllowed( |
| 1732 |
CODEC_AVC_PROFILE_IDC profileIdc, |
| 1733 |
CODEC_AVC_LEVEL_IDC levelIdc, |
| 1734 |
uint32_t framesPer100Sec) |
| 1735 |
{ |
| 1736 |
uint16_t maxAllowedNumSlices = 0; |
| 1737 |
|
| 1738 |
if ((profileIdc == CODEC_AVC_MAIN_PROFILE) || |
| 1739 |
(profileIdc == CODEC_AVC_HIGH_PROFILE) || |
| 1740 |
(profileIdc == CODEC_AVC_HIGH10_PROFILE) || |
| 1741 |
(profileIdc == CODEC_AVC_HIGH422_PROFILE) || |
| 1742 |
(profileIdc == CODEC_AVC_HIGH444_PROFILE) || |
| 1743 |
(profileIdc == CODEC_AVC_CAVLC444_INTRA_PROFILE)) |
| 1744 |
{ |
| 1745 |
switch (levelIdc) |
| 1746 |
{ |
| 1747 |
case CODEC_AVC_LEVEL_3: |
| 1748 |
maxAllowedNumSlices = (uint16_t)(40500.0 * 100 / 22.0 / framesPer100Sec); |
| 1749 |
break; |
| 1750 |
case CODEC_AVC_LEVEL_31: |
| 1751 |
maxAllowedNumSlices = (uint16_t)(108000.0 * 100 / 60.0 / framesPer100Sec); |
| 1752 |
break; |
| 1753 |
case CODEC_AVC_LEVEL_32: |
| 1754 |
maxAllowedNumSlices = (uint16_t)(216000.0 * 100 / 60.0 / framesPer100Sec); |
| 1755 |
break; |
| 1756 |
case CODEC_AVC_LEVEL_4: |
| 1757 |
case CODEC_AVC_LEVEL_41: |
| 1758 |
maxAllowedNumSlices = (uint16_t)(245760.0 * 100 / 24.0 / framesPer100Sec); |
| 1759 |
break; |
| 1760 |
case CODEC_AVC_LEVEL_42: |
| 1761 |
maxAllowedNumSlices = (uint16_t)(522240.0 * 100 / 24.0 / framesPer100Sec); |
| 1762 |
break; |
| 1763 |
case CODEC_AVC_LEVEL_5: |
| 1764 |
maxAllowedNumSlices = (uint16_t)(589824.0 * 100 / 24.0 / framesPer100Sec); |
| 1765 |
break; |
| 1766 |
case CODEC_AVC_LEVEL_51: |
| 1767 |
maxAllowedNumSlices = (uint16_t)(983040.0 * 100 / 24.0 / framesPer100Sec); |
| 1768 |
break; |
| 1769 |
case CODEC_AVC_LEVEL_52: |
| 1770 |
maxAllowedNumSlices = (uint16_t)(2073600.0 * 100 / 24.0 / framesPer100Sec); |
| 1771 |
break; |
| 1772 |
default: |
| 1773 |
maxAllowedNumSlices = 0; |
| 1774 |
} |
| 1775 |
} |
| 1776 |
|
| 1777 |
return maxAllowedNumSlices; |
| 1778 |
} |
| 1779 |
|
| 1780 |
//Pack Slice Header |
| 1781 |
MOS_STATUS CodecHalAvcEncode_PackSliceHeader( |
| 1782 |
PCODECHAL_ENCODE_AVC_PACK_SLC_HEADER_PARAMS params) |
| 1783 |
{ |
| 1784 |
PCODEC_AVC_ENCODE_SEQUENCE_PARAMS seqParams; |
| 1785 |
PCODEC_AVC_ENCODE_PIC_PARAMS picParams; |
| 1786 |
PCODEC_AVC_ENCODE_SLICE_PARAMS slcParams; |
| 1787 |
PBSBuffer bsbuffer; |
| 1788 |
uint8_t sliceType; |
| 1789 |
CODECHAL_ENCODE_AVC_NAL_UNIT_TYPE nalType; |
| 1790 |
bool ref; |
| 1791 |
MOS_STATUS eStatus = MOS_STATUS_SUCCESS; |
| 1792 |
|
| 1793 |
CODECHAL_ENCODE_CHK_NULL_RETURN(params); |
| 1794 |
CODECHAL_ENCODE_CHK_NULL_RETURN(params->pSeqParams); |
| 1795 |
CODECHAL_ENCODE_CHK_NULL_RETURN(params->pPicParams); |
| 1796 |
CODECHAL_ENCODE_CHK_NULL_RETURN(params->pAvcSliceParams); |
| 1797 |
CODECHAL_ENCODE_CHK_NULL_RETURN(params->pBsBuffer); |
| 1798 |
|
| 1799 |
slcParams = params->pAvcSliceParams; |
| 1800 |
picParams = params->pPicParams; |
| 1801 |
seqParams = params->pSeqParams; |
| 1802 |
bsbuffer = params->pBsBuffer; |
| 1803 |
sliceType = Slice_Type[slcParams->slice_type]; |
| 1804 |
nalType = params->NalUnitType; |
| 1805 |
ref = params->ppRefList[params->CurrReconPic.FrameIdx]->bUsedAsRef; |
| 1806 |
|
| 1807 |
// Make slice header uint8_t aligned |
| 1808 |
while (bsbuffer->BitOffset) |
| 1809 |
{ |
| 1810 |
PutBit(bsbuffer, 0); |
| 1811 |
} |
| 1812 |
|
| 1813 |
// zero byte shall exist when the byte stream NAL unit syntax structure contains the first |
| 1814 |
// NAL unit of an access unit in decoding order, as specified by subclause 7.4.1.2.3. |
| 1815 |
// VDEnc Slice header packing handled by PAK does not need the 0 byte inserted |
| 1816 |
if (params->UserFlags.bDisableAcceleratorHeaderPacking && (!params->bVdencEnabled)) |
| 1817 |
{ |
| 1818 |
*bsbuffer->pCurrent = 0; |
| 1819 |
bsbuffer->pCurrent++; |
| 1820 |
} |
| 1821 |
|
| 1822 |
SetNalUnit(&bsbuffer->pCurrent, (uint8_t)ref, nalType); |
| 1823 |
|
| 1824 |
// In the VDEnc mode, PAK only gets this command at the beginning of the frame for slice position X=0, Y=0 |
| 1825 |
PutVLCCode(bsbuffer, params->bVdencEnabled ? 0 : slcParams->first_mb_in_slice); |
| 1826 |
PutVLCCode(bsbuffer, slcParams->slice_type); |
| 1827 |
PutVLCCode(bsbuffer, slcParams->pic_parameter_set_id); |
| 1828 |
|
| 1829 |
if (seqParams->separate_colour_plane_flag) |
| 1830 |
{ |
| 1831 |
PutBits(bsbuffer, slcParams->colour_plane_id, 2); |
| 1832 |
} |
| 1833 |
|
| 1834 |
PutBits(bsbuffer, slcParams->frame_num, seqParams->log2_max_frame_num_minus4 + 4); |
| 1835 |
|
| 1836 |
if (!seqParams->frame_mbs_only_flag) |
| 1837 |
{ |
| 1838 |
PutBit(bsbuffer, slcParams->field_pic_flag); |
| 1839 |
if (slcParams->field_pic_flag) |
| 1840 |
{ |
| 1841 |
PutBit(bsbuffer, slcParams->bottom_field_flag); |
| 1842 |
} |
| 1843 |
} |
| 1844 |
|
| 1845 |
if (nalType == CODECHAL_ENCODE_AVC_NAL_UT_IDR_SLICE) |
| 1846 |
{ |
| 1847 |
PutVLCCode(bsbuffer, slcParams->idr_pic_id); |
| 1848 |
} |
| 1849 |
|
| 1850 |
if (seqParams->pic_order_cnt_type == 0) |
| 1851 |
{ |
| 1852 |
PutBits(bsbuffer, slcParams->pic_order_cnt_lsb, seqParams->log2_max_pic_order_cnt_lsb_minus4 + 4); |
| 1853 |
if (picParams->pic_order_present_flag && !slcParams->field_pic_flag) |
| 1854 |
{ |
| 1855 |
PutVLCCode(bsbuffer, SIGNED(slcParams->delta_pic_order_cnt_bottom)); |
| 1856 |
} |
| 1857 |
} |
| 1858 |
|
| 1859 |
if (seqParams->pic_order_cnt_type == 1 && !seqParams->delta_pic_order_always_zero_flag) |
| 1860 |
{ |
| 1861 |
PutVLCCode(bsbuffer, SIGNED(slcParams->delta_pic_order_cnt[0])); |
| 1862 |
if (picParams->pic_order_present_flag && !slcParams->field_pic_flag) |
| 1863 |
{ |
| 1864 |
PutVLCCode(bsbuffer, SIGNED(slcParams->delta_pic_order_cnt[1])); |
| 1865 |
} |
| 1866 |
} |
| 1867 |
|
| 1868 |
if (picParams->redundant_pic_cnt_present_flag) |
| 1869 |
{ |
| 1870 |
PutVLCCode(bsbuffer, slcParams->redundant_pic_cnt); |
| 1871 |
} |
| 1872 |
|
| 1873 |
if (sliceType == SLICE_B) |
| 1874 |
{ |
| 1875 |
PutBit(bsbuffer, slcParams->direct_spatial_mv_pred_flag); |
| 1876 |
} |
| 1877 |
|
| 1878 |
if (sliceType == SLICE_P || sliceType == SLICE_SP || sliceType == SLICE_B) |
| 1879 |
{ |
| 1880 |
PutBit(bsbuffer, slcParams->num_ref_idx_active_override_flag); |
| 1881 |
if (slcParams->num_ref_idx_active_override_flag) |
| 1882 |
{ |
| 1883 |
PutVLCCode(bsbuffer, slcParams->num_ref_idx_l0_active_minus1); |
| 1884 |
if (sliceType == SLICE_B) |
| 1885 |
{ |
| 1886 |
PutVLCCode(bsbuffer, slcParams->num_ref_idx_l1_active_minus1); |
| 1887 |
} |
| 1888 |
} |
| 1889 |
} |
| 1890 |
|
| 1891 |
// ref_pic_list_reordering() |
| 1892 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(CodecHal_PackSliceHeader_RefPicListReordering(params)); |
| 1893 |
|
| 1894 |
if ((picParams->weighted_pred_flag && |
| 1895 |
(sliceType == SLICE_P || sliceType == SLICE_SP)) || |
| 1896 |
(picParams->weighted_bipred_idc == EXPLICIT_WEIGHTED_INTER_PRED_MODE && |
| 1897 |
sliceType == SLICE_B)) |
| 1898 |
{ |
| 1899 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(CodecHal_PackSliceHeader_PredWeightTable(params)); |
| 1900 |
} |
| 1901 |
|
| 1902 |
if (ref) |
| 1903 |
{ |
| 1904 |
// dec_ref_pic_marking() |
| 1905 |
if (nalType == CODECHAL_ENCODE_AVC_NAL_UT_IDR_SLICE) |
| 1906 |
{ |
| 1907 |
PutBit(bsbuffer, slcParams->no_output_of_prior_pics_flag); |
| 1908 |
PutBit(bsbuffer, slcParams->long_term_reference_flag); |
| 1909 |
} |
| 1910 |
else |
| 1911 |
{ |
| 1912 |
PutBit(bsbuffer, slcParams->adaptive_ref_pic_marking_mode_flag); |
| 1913 |
if (slcParams->adaptive_ref_pic_marking_mode_flag) |
| 1914 |
{ |
| 1915 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(CodecHal_PackSliceHeader_MMCO(params)); |
| 1916 |
} |
| 1917 |
} |
| 1918 |
} |
| 1919 |
|
| 1920 |
if (picParams->entropy_coding_mode_flag && sliceType != SLICE_I && sliceType != SLICE_SI) |
| 1921 |
{ |
| 1922 |
PutVLCCode(bsbuffer, slcParams->cabac_init_idc); |
| 1923 |
} |
| 1924 |
|
| 1925 |
PutVLCCode(bsbuffer, SIGNED(slcParams->slice_qp_delta)); |
| 1926 |
|
| 1927 |
if (sliceType == SLICE_SP || sliceType == SLICE_SI) |
| 1928 |
{ |
| 1929 |
if (sliceType == SLICE_SP) |
| 1930 |
{ |
| 1931 |
PutBit(bsbuffer, slcParams->sp_for_switch_flag); |
| 1932 |
} |
| 1933 |
PutVLCCode(bsbuffer, SIGNED(slcParams->slice_qs_delta)); |
| 1934 |
} |
| 1935 |
|
| 1936 |
if (picParams->deblocking_filter_control_present_flag) |
| 1937 |
{ |
| 1938 |
PutVLCCode(bsbuffer, slcParams->disable_deblocking_filter_idc); |
| 1939 |
if (slcParams->disable_deblocking_filter_idc != 1) |
| 1940 |
{ |
| 1941 |
PutVLCCode(bsbuffer, SIGNED(slcParams->slice_alpha_c0_offset_div2)); |
| 1942 |
PutVLCCode(bsbuffer, SIGNED(slcParams->slice_beta_offset_div2)); |
| 1943 |
} |
| 1944 |
} |
| 1945 |
|
| 1946 |
bsbuffer->BitSize = |
| 1947 |
(uint32_t)((bsbuffer->pCurrent - bsbuffer->SliceOffset - bsbuffer->pBase) * 8 + bsbuffer->BitOffset); |
| 1948 |
bsbuffer->SliceOffset = |
| 1949 |
(uint32_t)(bsbuffer->pCurrent - bsbuffer->pBase + (bsbuffer->BitOffset != 0)); |
| 1950 |
|
| 1951 |
return eStatus; |
| 1952 |
} |
| 1953 |
|
| 1954 |
MOS_STATUS CodechalEncodeAvcBase::InitMmcState() |
| 1955 |
{ |
| 1956 |
m_mmcState = MOS_New(CodechalMmcEncodeAvc, m_hwInterface, this); |
| 1957 |
CODECHAL_ENCODE_CHK_NULL_RETURN(m_mmcState); |
| 1958 |
|
| 1959 |
return MOS_STATUS_SUCCESS; |
| 1960 |
} |
| 1961 |
|
| 1962 |
CodechalEncodeAvcBase::CodechalEncodeAvcBase( |
| 1963 |
CodechalHwInterface * hwInterface, |
| 1964 |
CodechalDebugInterface *debugInterface, |
| 1965 |
PCODECHAL_STANDARD_INFO standardInfo) : CodechalEncoderState(hwInterface, debugInterface, standardInfo) |
| 1966 |
{ |
| 1967 |
CODECHAL_ENCODE_FUNCTION_ENTER; |
| 1968 |
|
| 1969 |
MOS_ZeroMemory(m_avcPicParams, CODEC_AVC_MAX_PPS_NUM * sizeof(PCODEC_AVC_ENCODE_PIC_PARAMS)); |
| 1970 |
MOS_ZeroMemory(m_avcSeqParams, CODEC_AVC_MAX_SPS_NUM * sizeof(PCODEC_AVC_ENCODE_SEQUENCE_PARAMS)); |
| 1971 |
MOS_ZeroMemory(&m_userFlags, sizeof(CODEC_AVC_ENCODE_USER_FLAGS)); |
| 1972 |
MOS_ZeroMemory(m_picIdx, CODEC_AVC_MAX_NUM_REF_FRAME * sizeof(CODEC_PIC_ID)); |
| 1973 |
MOS_ZeroMemory(m_refList, CODEC_AVC_NUM_UNCOMPRESSED_SURFACE * sizeof(PCODEC_REF_LIST)); |
| 1974 |
MOS_ZeroMemory(m_avcFrameStoreID, CODEC_AVC_MAX_NUM_REF_FRAME * sizeof(CODEC_AVC_FRAME_STORE_ID)); |
| 1975 |
MOS_ZeroMemory(&m_nalUnitType, sizeof(CODECHAL_ENCODE_AVC_NAL_UNIT_TYPE)); |
| 1976 |
MOS_ZeroMemory(&m_trellisQuantParams, sizeof(CODECHAL_ENCODE_AVC_TQ_PARAMS)); |
| 1977 |
MOS_ZeroMemory(m_distScaleFactorList0, 2 * CODEC_AVC_MAX_NUM_REF_FRAME * sizeof(uint32_t)); |
| 1978 |
MOS_ZeroMemory(m_batchBufferForVdencImgStat, CODECHAL_ENCODE_RECYCLED_BUFFER_NUM * sizeof(MHW_BATCH_BUFFER)); |
| 1979 |
MOS_ZeroMemory(&m_4xMeMvDataBuffer, sizeof(MOS_SURFACE)); |
| 1980 |
MOS_ZeroMemory(&m_16xMeMvDataBuffer, sizeof(MOS_SURFACE)); |
| 1981 |
MOS_ZeroMemory(&m_32xMeMvDataBuffer, sizeof(MOS_SURFACE)); |
| 1982 |
MOS_ZeroMemory(&m_4xMeDistortionBuffer, sizeof(MOS_SURFACE)); |
| 1983 |
MOS_ZeroMemory(&m_intraRowStoreScratchBuffer, sizeof(MOS_RESOURCE)); |
| 1984 |
MOS_ZeroMemory(m_batchBufferForPakSlices, CODECHAL_ENCODE_RECYCLED_BUFFER_NUM * sizeof(MHW_BATCH_BUFFER)); |
| 1985 |
MOS_ZeroMemory(&m_pakSliceSizeStreamoutBuffer, sizeof(MOS_RESOURCE)); |
| 1986 |
|
| 1987 |
m_hwInterface->GetStateHeapSettings()->dwNumSyncTags = CODECHAL_ENCODE_AVC_NUM_SYNC_TAGS; |
| 1988 |
m_hwInterface->GetStateHeapSettings()->dwDshSize = CODECHAL_ENCODE_AVC_INIT_DSH_SIZE; |
| 1989 |
} |
| 1990 |
|
| 1991 |
CodechalEncodeAvcBase::~CodechalEncodeAvcBase() |
| 1992 |
{ |
| 1993 |
CODECHAL_ENCODE_FUNCTION_ENTER; |
| 1994 |
|
| 1995 |
// Release Ref Lists |
| 1996 |
CodecHalFreeDataList(m_refList, CODEC_AVC_NUM_UNCOMPRESSED_SURFACE); |
| 1997 |
|
| 1998 |
for (uint8_t i = 0; i < CODECHAL_ENCODE_RECYCLED_BUFFER_NUM; i++) |
| 1999 |
{ |
| 2000 |
ReleaseBatchBufferForPakSlices(i); |
| 2001 |
} |
| 2002 |
|
| 2003 |
m_osInterface->pfnFreeResource(m_osInterface, &m_intraRowStoreScratchBuffer); |
| 2004 |
|
| 2005 |
if (m_encEnabled) |
| 2006 |
{ |
| 2007 |
if (m_hmeSupported) |
| 2008 |
{ |
| 2009 |
if (m_hmeKernel) |
| 2010 |
{ |
| 2011 |
MOS_Delete(m_hmeKernel); |
| 2012 |
} |
| 2013 |
else |
| 2014 |
{ |
| 2015 |
HmeParams hmeParams; |
| 2016 |
|
| 2017 |
MOS_ZeroMemory(&hmeParams, sizeof(hmeParams)); |
| 2018 |
hmeParams.b4xMeDistortionBufferSupported = true; |
| 2019 |
hmeParams.ps16xMeMvDataBuffer = &m_16xMeMvDataBuffer; |
| 2020 |
hmeParams.ps32xMeMvDataBuffer = &m_32xMeMvDataBuffer; |
| 2021 |
hmeParams.ps4xMeDistortionBuffer = &m_4xMeDistortionBuffer; |
| 2022 |
hmeParams.ps4xMeMvDataBuffer = &m_4xMeMvDataBuffer; |
| 2023 |
DestroyMeResources(&hmeParams); |
| 2024 |
} |
| 2025 |
} |
| 2026 |
} |
| 2027 |
|
| 2028 |
if (m_sliceSizeStreamoutSupported) |
| 2029 |
{ |
| 2030 |
m_osInterface->pfnFreeResource(m_osInterface, &m_pakSliceSizeStreamoutBuffer); |
| 2031 |
} |
| 2032 |
} |
| 2033 |
|
| 2034 |
MOS_STATUS CodechalEncodeAvcBase::Initialize(CodechalSetting *settings) |
| 2035 |
{ |
| 2036 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(InitMmcState()); |
| 2037 |
return CodechalEncoderState::Initialize(settings); |
| 2038 |
} |
| 2039 |
|
| 2040 |
MOS_STATUS CodechalEncodeAvcBase::UserFeatureKeyReport() |
| 2041 |
{ |
| 2042 |
return CodechalEncoderState::UserFeatureKeyReport(); |
| 2043 |
} |
| 2044 |
|
| 2045 |
MOS_STATUS CodechalEncodeAvcBase::Initialize() |
| 2046 |
{ |
| 2047 |
MOS_STATUS eStatus = MOS_STATUS_SUCCESS; |
| 2048 |
|
| 2049 |
m_hwInterface->GetMfxPrimitiveCommandsDataSize( |
| 2050 |
m_mode, |
| 2051 |
&m_pakSliceSize, |
| 2052 |
&m_pakSlicePatchListSize, |
| 2053 |
false); |
| 2054 |
|
| 2055 |
// overwrite, must be zero, no patching into second level batch buffer allowed |
| 2056 |
m_pakSlicePatchListSize = 0; |
| 2057 |
|
| 2058 |
return eStatus; |
| 2059 |
} |
| 2060 |
|
| 2061 |
void CodechalEncodeAvcBase::ScalingListFlat() |
| 2062 |
{ |
| 2063 |
// 4x4 block |
| 2064 |
for (uint8_t idx2 = 0; idx2 < 6; idx2++) |
| 2065 |
{ |
| 2066 |
for (uint8_t idx1 = 0; idx1 < 16; idx1++) |
| 2067 |
{ |
| 2068 |
m_avcIQWeightScaleLists->WeightScale4x4[idx2][idx1] = 16; |
| 2069 |
} |
| 2070 |
} |
| 2071 |
// 8x8 block |
| 2072 |
for (uint8_t idx2 = 0; idx2 < 2; idx2++) |
| 2073 |
{ |
| 2074 |
for (uint8_t idx1 = 0; idx1 < 64; idx1++) |
| 2075 |
{ |
| 2076 |
m_avcIQWeightScaleLists->WeightScale8x8[idx2][idx1] = 16; |
| 2077 |
} |
| 2078 |
} |
| 2079 |
} |
| 2080 |
|
| 2081 |
void CodechalEncodeAvcBase::ScalingListFallbackRuleA() |
| 2082 |
{ |
| 2083 |
for (uint8_t idx1 = 0; idx1 < 16; idx1++) |
| 2084 |
{ |
| 2085 |
for (uint8_t idx2 = 0; idx2 < 3; idx2++) |
| 2086 |
{ |
| 2087 |
m_avcIQWeightScaleLists->WeightScale4x4[idx2][CODEC_AVC_Qmatrix_scan_4x4[idx1]] = |
| 2088 |
CODEC_AVC_Default_4x4_Intra[idx1]; |
| 2089 |
} |
| 2090 |
for (uint8_t idx2 = 3; idx2 < 6; idx2++) |
| 2091 |
{ |
| 2092 |
m_avcIQWeightScaleLists->WeightScale4x4[idx2][CODEC_AVC_Qmatrix_scan_4x4[idx1]] = |
| 2093 |
CODEC_AVC_Default_4x4_Inter[idx1]; |
| 2094 |
} |
| 2095 |
} |
| 2096 |
// 8x8 block |
| 2097 |
for (uint8_t idx1 = 0; idx1 < 64; idx1++) |
| 2098 |
{ |
| 2099 |
m_avcIQWeightScaleLists->WeightScale8x8[0][CODEC_AVC_Qmatrix_scan_8x8[idx1]] = |
| 2100 |
CODEC_AVC_Default_8x8_Intra[idx1]; |
| 2101 |
m_avcIQWeightScaleLists->WeightScale8x8[1][CODEC_AVC_Qmatrix_scan_8x8[idx1]] = |
| 2102 |
CODEC_AVC_Default_8x8_Inter[idx1]; |
| 2103 |
} |
| 2104 |
} |
| 2105 |
|
| 2106 |
void CodechalEncodeAvcBase::GetDistScaleFactor() |
| 2107 |
{ |
| 2108 |
auto picParams = m_avcPicParam; |
| 2109 |
auto refList = &(m_refList[0]); |
| 2110 |
auto picIdx = &(m_picIdx[0]); |
| 2111 |
|
| 2112 |
bool bottom = CodecHal_PictureIsBottomField(picParams->CurrOriginalPic); |
| 2113 |
int pocCurr = picParams->CurrFieldOrderCnt[bottom]; |
| 2114 |
|
| 2115 |
MOS_ZeroMemory(m_distScaleFactorList0, sizeof(uint32_t) * CODEC_AVC_MAX_NUM_REF_FRAME * 2); |
| 2116 |
for (unsigned int index = 0; index <= m_avcSliceParams->num_ref_idx_l0_active_minus1; index++) |
| 2117 |
{ |
| 2118 |
auto picture = m_avcSliceParams->RefPicList[LIST_0][index]; |
| 2119 |
if (!CodecHal_PictureIsInvalid(picture)) |
| 2120 |
{ |
| 2121 |
auto pictureIdx = picIdx[picture.FrameIdx].ucPicIdx; |
| 2122 |
int pocPic0 = CodecHal_PictureIsBottomField(picture) ? refList[pictureIdx]->iFieldOrderCnt[1] : refList[pictureIdx]->iFieldOrderCnt[0]; |
| 2123 |
picture = m_avcSliceParams->RefPicList[LIST_1][0]; |
| 2124 |
pictureIdx = picIdx[picture.FrameIdx].ucPicIdx; |
| 2125 |
int pocPic1 = CodecHal_PictureIsBottomField(picture) ? refList[pictureIdx]->iFieldOrderCnt[1] : refList[pictureIdx]->iFieldOrderCnt[0]; |
| 2126 |
int tb = CodecHal_Clip3(-128, 127, (pocCurr - pocPic0)); |
| 2127 |
int td = CodecHal_Clip3(-128, 127, (pocPic1 - pocPic0)); |
| 2128 |
if (td == 0) |
| 2129 |
{ |
| 2130 |
td = 1; |
| 2131 |
} |
| 2132 |
int tx = (16384 + ABS(td / 2)) / td; |
| 2133 |
|
| 2134 |
m_distScaleFactorList0[index] = CodecHal_Clip3(-1024, 1023, (tb * tx + 32) >> 6); |
| 2135 |
} |
| 2136 |
} |
| 2137 |
} |
| 2138 |
|
| 2139 |
MOS_STATUS CodechalEncodeAvcBase::AllocateBatchBufferForPakSlices( |
| 2140 |
uint32_t numSlices, |
| 2141 |
uint8_t numPakPasses, |
| 2142 |
uint8_t currRecycledBufIdx) |
| 2143 |
{ |
| 2144 |
CODECHAL_ENCODE_FUNCTION_ENTER; |
| 2145 |
MOS_STATUS eStatus = MOS_STATUS_SUCCESS; |
| 2146 |
|
| 2147 |
MOS_ZeroMemory( |
| 2148 |
&m_batchBufferForPakSlices[currRecycledBufIdx], |
| 2149 |
sizeof(MHW_BATCH_BUFFER)); |
| 2150 |
|
| 2151 |
// Get the slice size |
| 2152 |
uint32_t size = (numPakPasses + 1) * numSlices * m_pakSliceSize; |
| 2153 |
|
| 2154 |
m_batchBufferForPakSlices[currRecycledBufIdx].bSecondLevel = true; |
| 2155 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(Mhw_AllocateBb( |
| 2156 |
m_osInterface, |
| 2157 |
&m_batchBufferForPakSlices[currRecycledBufIdx], |
| 2158 |
nullptr, |
| 2159 |
size)); |
| 2160 |
|
| 2161 |
MOS_LOCK_PARAMS lockFlags; |
| 2162 |
MOS_ZeroMemory(&lockFlags, sizeof(MOS_LOCK_PARAMS)); |
| 2163 |
lockFlags.WriteOnly = 1; |
| 2164 |
uint8_t *data = (uint8_t *)m_osInterface->pfnLockResource( |
| 2165 |
m_osInterface, |
| 2166 |
&m_batchBufferForPakSlices[currRecycledBufIdx].OsResource, |
| 2167 |
&lockFlags); |
| 2168 |
|
| 2169 |
CODECHAL_ENCODE_CHK_NULL_RETURN(data); |
| 2170 |
|
| 2171 |
MOS_ZeroMemory(data, size); |
| 2172 |
m_osInterface->pfnUnlockResource( |
| 2173 |
m_osInterface, |
| 2174 |
&m_batchBufferForPakSlices[currRecycledBufIdx].OsResource); |
| 2175 |
|
| 2176 |
return eStatus; |
| 2177 |
} |
| 2178 |
|
| 2179 |
MOS_STATUS CodechalEncodeAvcBase::ReleaseBatchBufferForPakSlices( |
| 2180 |
uint8_t currRecycledBufIdx) |
| 2181 |
{ |
| 2182 |
CODECHAL_ENCODE_FUNCTION_ENTER; |
| 2183 |
MOS_STATUS eStatus = MOS_STATUS_SUCCESS; |
| 2184 |
|
| 2185 |
if (m_batchBufferForPakSlices[currRecycledBufIdx].iSize) |
| 2186 |
{ |
| 2187 |
Mhw_FreeBb(m_osInterface, &m_batchBufferForPakSlices[currRecycledBufIdx], nullptr); |
| 2188 |
} |
| 2189 |
|
| 2190 |
return eStatus; |
| 2191 |
} |
| 2192 |
|
| 2193 |
//==<Functions>======================================================= |
| 2194 |
|
| 2195 |
// Calculate BiWeight for AVC B frame |
| 2196 |
// for AVC, we cannot use the CodecHal_GetBiWeight function since AVC can use B as reference and |
| 2197 |
// also supports PAFF |
| 2198 |
int32_t CodechalEncodeAvcBase::GetBiWeight( |
| 2199 |
uint32_t distScaleFactorRefID0List0, |
| 2200 |
uint16_t weightedBiPredIdc) |
| 2201 |
{ |
| 2202 |
int32_t biWeight = 32; // default value |
| 2203 |
if (weightedBiPredIdc != IMPLICIT_WEIGHTED_INTER_PRED_MODE) |
| 2204 |
{ |
| 2205 |
biWeight = 32; |
| 2206 |
} |
| 2207 |
else |
| 2208 |
{ |
| 2209 |
biWeight = (distScaleFactorRefID0List0 + 2) >> 2; |
| 2210 |
|
| 2211 |
if (biWeight != 16 && biWeight != 21 && |
| 2212 |
biWeight != 32 && biWeight != 43 && biWeight != 48) |
| 2213 |
{ |
| 2214 |
biWeight = 32; // If # of B-pics between two refs is more than 3. VME does not support it. |
| 2215 |
} |
| 2216 |
} |
| 2217 |
|
| 2218 |
return biWeight; |
| 2219 |
} |
| 2220 |
|
| 2221 |
MOS_STATUS CodechalEncodeAvcBase::AllocateEncResources() |
| 2222 |
{ |
| 2223 |
CODECHAL_ENCODE_FUNCTION_ENTER; |
| 2224 |
MOS_STATUS eStatus = MOS_STATUS_SUCCESS; |
| 2225 |
|
| 2226 |
uint32_t fieldNumMBs = m_picWidthInMb * ((m_picHeightInMb + 1) >> 1); |
| 2227 |
|
| 2228 |
// to be used in CodecHalEncode_TrackedBuffer_AllocateMbCodeMvDataResources() later |
| 2229 |
m_mbCodeSize = MOS_ALIGN_CEIL(fieldNumMBs * 16 * 4, CODECHAL_PAGE_SIZE) + fieldNumMBs * 16 * 4; |
| 2230 |
m_mvDataSize = MOS_ALIGN_CEIL(fieldNumMBs * (32 * 4), CODECHAL_PAGE_SIZE) * 2; // top field MV + bottom field MV (both page aligned) |
| 2231 |
|
| 2232 |
// allocate 3 + 2 buffers initially |
| 2233 |
if ((m_codecFunction == CODECHAL_FUNCTION_ENC_PAK) && (!m_vdencEnabled)) |
| 2234 |
{ |
| 2235 |
for (uint8_t j = 0; j < 3; j++) |
| 2236 |
{ |
| 2237 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(m_trackedBuf->AllocateMbCodeResources(j)); |
| 2238 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(m_trackedBuf->AllocateMvDataResources(j)); |
| 2239 |
} |
| 2240 |
|
| 2241 |
for (uint8_t k = 0; k < 2; k++) |
| 2242 |
{ |
| 2243 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(m_trackedBuf->AllocateMbCodeResources(CODEC_NUM_REF_BUFFERS + k)); |
| 2244 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(m_trackedBuf->AllocateMvDataResources(CODEC_NUM_REF_BUFFERS + k)); |
| 2245 |
} |
| 2246 |
} |
| 2247 |
|
| 2248 |
if (m_encEnabled && m_hmeSupported) |
| 2249 |
{ |
| 2250 |
if (m_hmeKernel) |
| 2251 |
{ |
| 2252 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(m_hmeKernel->AllocateResources()); |
| 2253 |
} |
| 2254 |
else |
| 2255 |
{ |
| 2256 |
HmeParams hmeParams; |
| 2257 |
MOS_ZeroMemory(&hmeParams, sizeof(hmeParams)); |
| 2258 |
hmeParams.b4xMeDistortionBufferSupported = true; |
| 2259 |
hmeParams.ps4xMeDistortionBuffer = &m_4xMeDistortionBuffer; |
| 2260 |
hmeParams.ps4xMeMvDataBuffer = &m_4xMeMvDataBuffer; |
| 2261 |
hmeParams.ps16xMeMvDataBuffer = &m_16xMeMvDataBuffer; |
| 2262 |
hmeParams.ps32xMeMvDataBuffer = &m_32xMeMvDataBuffer; |
| 2263 |
|
| 2264 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(AllocateResources4xMe(&hmeParams)); |
| 2265 |
if (m_16xMeSupported) |
| 2266 |
{ |
| 2267 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(AllocateResources16xMe(&hmeParams)); |
| 2268 |
} |
| 2269 |
if (m_32xMeSupported) |
| 2270 |
{ |
| 2271 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(AllocateResources32xMe(&hmeParams)); |
| 2272 |
} |
| 2273 |
} |
| 2274 |
} |
| 2275 |
|
| 2276 |
return eStatus; |
| 2277 |
} |
| 2278 |
|
| 2279 |
MOS_STATUS CodechalEncodeAvcBase::AllocateResources() |
| 2280 |
{ |
| 2281 |
CODECHAL_ENCODE_FUNCTION_ENTER; |
| 2282 |
MOS_STATUS eStatus = MOS_STATUS_SUCCESS; |
| 2283 |
|
| 2284 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(CodechalEncoderState::AllocateResources()); |
| 2285 |
|
| 2286 |
// initiate allocation parameters and lock flags |
| 2287 |
MOS_ALLOC_GFXRES_PARAMS allocParamsForBufferLinear; |
| 2288 |
MOS_ZeroMemory(&allocParamsForBufferLinear, sizeof(MOS_ALLOC_GFXRES_PARAMS)); |
| 2289 |
allocParamsForBufferLinear.Type = MOS_GFXRES_BUFFER; |
| 2290 |
allocParamsForBufferLinear.TileType = MOS_TILE_LINEAR; |
| 2291 |
allocParamsForBufferLinear.Format = Format_Buffer; |
| 2292 |
|
| 2293 |
AllocateEncResources(); |
| 2294 |
|
| 2295 |
// Allocate Ref Lists |
| 2296 |
CodecHalAllocateDataList( |
| 2297 |
m_refList, |
| 2298 |
CODEC_AVC_NUM_UNCOMPRESSED_SURFACE); |
| 2299 |
|
| 2300 |
if (m_pakEnabled && m_mfxInterface->IsIntraRowstoreCacheEnabled() == false) |
| 2301 |
{ |
| 2302 |
// Intra Row Store Scratch buffer |
| 2303 |
// 1 cacheline per MB |
| 2304 |
allocParamsForBufferLinear.dwBytes = m_picWidthInMb * CODECHAL_CACHELINE_SIZE; |
| 2305 |
allocParamsForBufferLinear.pBufName = "Intra Row Store Scratch Buffer"; |
| 2306 |
|
| 2307 |
eStatus = (MOS_STATUS)m_osInterface->pfnAllocateResource( |
| 2308 |
m_osInterface, |
| 2309 |
&allocParamsForBufferLinear, |
| 2310 |
&m_intraRowStoreScratchBuffer); |
| 2311 |
|
| 2312 |
if (eStatus != MOS_STATUS_SUCCESS) |
| 2313 |
{ |
| 2314 |
CODECHAL_ENCODE_ASSERTMESSAGE("Failed to allocate Intra Row Store Scratch Buffer."); |
| 2315 |
return eStatus; |
| 2316 |
} |
| 2317 |
} |
| 2318 |
|
| 2319 |
if (m_sliceSizeStreamoutSupported) |
| 2320 |
{ |
| 2321 |
// PAK Slice Size Streamout Buffer |
| 2322 |
allocParamsForBufferLinear.dwBytes = MOS_ALIGN_CEIL(CODECHAL_ENCODE_SLICESIZE_BUF_SIZE, CODECHAL_PAGE_SIZE); |
| 2323 |
allocParamsForBufferLinear.pBufName = "PAK Slice Size Streamout Buffer"; |
| 2324 |
|
| 2325 |
eStatus = (MOS_STATUS)m_osInterface->pfnAllocateResource( |
| 2326 |
m_osInterface, |
| 2327 |
&allocParamsForBufferLinear, |
| 2328 |
&m_pakSliceSizeStreamoutBuffer); |
| 2329 |
|
| 2330 |
if (eStatus != MOS_STATUS_SUCCESS) |
| 2331 |
{ |
| 2332 |
CODECHAL_ENCODE_ASSERTMESSAGE("%s: Failed to allocate Slice Size Streamout Buffer\n", __FUNCTION__); |
| 2333 |
return eStatus; |
| 2334 |
} |
| 2335 |
} |
| 2336 |
|
| 2337 |
return eStatus; |
| 2338 |
} |
| 2339 |
|
| 2340 |
MOS_STATUS CodechalEncodeAvcBase::SetSequenceStructs() |
| 2341 |
{ |
| 2342 |
CODECHAL_ENCODE_FUNCTION_ENTER; |
| 2343 |
MOS_STATUS eStatus = MOS_STATUS_SUCCESS; |
| 2344 |
|
| 2345 |
auto seqParams = m_avcSeqParam; |
| 2346 |
|
| 2347 |
// seq_scaling_matrix_present_flag and chroma_format_idc |
| 2348 |
// shall not be present for main profile |
| 2349 |
if (seqParams->Profile == CODEC_AVC_MAIN_PROFILE) |
| 2350 |
{ |
| 2351 |
seqParams->seq_scaling_matrix_present_flag = 0; |
| 2352 |
for (uint8_t i = 0; i < 12; i++) |
| 2353 |
{ |
| 2354 |
seqParams->seq_scaling_list_present_flag[i] = 0; |
| 2355 |
} |
| 2356 |
seqParams->chroma_format_idc = 1; |
| 2357 |
} |
| 2358 |
// high profile chroma_format_idc in the range of 0 to 1 inclusive |
| 2359 |
if (seqParams->chroma_format_idc > 1) |
| 2360 |
{ |
| 2361 |
seqParams->chroma_format_idc = 1; |
| 2362 |
} |
| 2363 |
|
| 2364 |
// main & high profile support only 8bpp |
| 2365 |
seqParams->bit_depth_luma_minus8 = 0; |
| 2366 |
seqParams->bit_depth_chroma_minus8 = 0; |
| 2367 |
|
| 2368 |
// setup parameters corresponding to H264 bit stream definition |
| 2369 |
seqParams->pic_height_in_map_units_minus1 = seqParams->frame_mbs_only_flag ? CODECHAL_GET_HEIGHT_IN_MACROBLOCKS(seqParams->FrameHeight) - 1 : (CODECHAL_GET_HEIGHT_IN_MACROBLOCKS(seqParams->FrameHeight) + 1) / 2 - 1; |
| 2370 |
seqParams->pic_width_in_mbs_minus1 = CODECHAL_GET_WIDTH_IN_MACROBLOCKS(seqParams->FrameWidth) - 1; |
| 2371 |
seqParams->constraint_set0_flag = 0; |
| 2372 |
seqParams->constraint_set1_flag = (seqParams->Profile == CODEC_AVC_BASE_PROFILE) ? 1 : 0; |
| 2373 |
seqParams->constraint_set2_flag = 0; |
| 2374 |
seqParams->constraint_set3_flag = 0; |
| 2375 |
seqParams->gaps_in_frame_num_value_allowed_flag = 0; |
| 2376 |
seqParams->qpprime_y_zero_transform_bypass_flag = 0; |
| 2377 |
seqParams->separate_colour_plane_flag = 0; |
| 2378 |
|
| 2379 |
// setup internal parameters |
| 2380 |
m_picWidthInMb = CODECHAL_GET_WIDTH_IN_MACROBLOCKS(seqParams->FrameWidth); |
| 2381 |
m_picHeightInMb = CODECHAL_GET_HEIGHT_IN_MACROBLOCKS(seqParams->FrameHeight); |
| 2382 |
m_frameWidth = m_picWidthInMb * CODECHAL_MACROBLOCK_WIDTH; |
| 2383 |
m_frameHeight = m_picHeightInMb * CODECHAL_MACROBLOCK_HEIGHT; |
| 2384 |
|
| 2385 |
// HME Scaling WxH |
| 2386 |
m_downscaledWidthInMb4x = |
| 2387 |
CODECHAL_GET_WIDTH_IN_MACROBLOCKS(m_frameWidth / SCALE_FACTOR_4x); |
| 2388 |
m_downscaledHeightInMb4x = |
| 2389 |
CODECHAL_GET_HEIGHT_IN_MACROBLOCKS(m_frameHeight / SCALE_FACTOR_4x); |
| 2390 |
m_downscaledWidth4x = |
| 2391 |
m_downscaledWidthInMb4x * CODECHAL_MACROBLOCK_WIDTH; |
| 2392 |
m_downscaledHeight4x = |
| 2393 |
m_downscaledHeightInMb4x * CODECHAL_MACROBLOCK_HEIGHT; |
| 2394 |
|
| 2395 |
// SuperHME Scaling WxH |
| 2396 |
m_downscaledWidthInMb16x = |
| 2397 |
CODECHAL_GET_WIDTH_IN_MACROBLOCKS(m_frameWidth / SCALE_FACTOR_16x); |
| 2398 |
m_downscaledHeightInMb16x = |
| 2399 |
CODECHAL_GET_HEIGHT_IN_MACROBLOCKS(m_frameHeight / SCALE_FACTOR_16x); |
| 2400 |
m_downscaledWidth16x = |
| 2401 |
m_downscaledWidthInMb16x * CODECHAL_MACROBLOCK_WIDTH; |
| 2402 |
m_downscaledHeight16x = |
| 2403 |
m_downscaledHeightInMb16x * CODECHAL_MACROBLOCK_HEIGHT; |
| 2404 |
|
| 2405 |
// UltraHME Scaling WxH |
| 2406 |
m_downscaledWidthInMb32x = |
| 2407 |
CODECHAL_GET_WIDTH_IN_MACROBLOCKS(m_frameWidth / SCALE_FACTOR_32x); |
| 2408 |
m_downscaledHeightInMb32x = |
| 2409 |
CODECHAL_GET_HEIGHT_IN_MACROBLOCKS(m_frameHeight / SCALE_FACTOR_32x); |
| 2410 |
m_downscaledWidth32x = |
| 2411 |
m_downscaledWidthInMb32x * CODECHAL_MACROBLOCK_WIDTH; |
| 2412 |
m_downscaledHeight32x = |
| 2413 |
m_downscaledHeightInMb32x * CODECHAL_MACROBLOCK_HEIGHT; |
| 2414 |
|
| 2415 |
MotionEstimationDisableCheck(); |
| 2416 |
|
| 2417 |
m_kernelMode = |
| 2418 |
CodecHal_TargetUsageToMode_AVC[seqParams->TargetUsage & 0x7]; |
| 2419 |
m_targetUsage = seqParams->TargetUsage & 0x7; |
| 2420 |
|
| 2421 |
if (!seqParams->frame_cropping_flag) |
| 2422 |
{ |
| 2423 |
// do cropping only when the picture dimension is not MB aligned... |
| 2424 |
seqParams->frame_crop_left_offset = 0; |
| 2425 |
seqParams->frame_crop_top_offset = 0; |
| 2426 |
|
| 2427 |
if (m_frameWidth != seqParams->FrameWidth || |
| 2428 |
m_frameHeight != seqParams->FrameHeight) |
| 2429 |
{ |
| 2430 |
seqParams->frame_cropping_flag = 1; |
| 2431 |
seqParams->frame_crop_right_offset = (uint16_t)((m_frameWidth - seqParams->FrameWidth) >> 1); // 4:2:0 |
| 2432 |
seqParams->frame_crop_bottom_offset = (uint16_t)((m_frameHeight - seqParams->FrameHeight) >> (2 - seqParams->frame_mbs_only_flag)); // 4:2:0 |
| 2433 |
} |
| 2434 |
else |
| 2435 |
{ |
| 2436 |
seqParams->frame_cropping_flag = 0; |
| 2437 |
seqParams->frame_crop_right_offset = 0; |
| 2438 |
seqParams->frame_crop_bottom_offset = 0; |
| 2439 |
} |
| 2440 |
} |
| 2441 |
|
| 2442 |
if (m_mfxInterface->IsRowStoreCachingSupported()) |
| 2443 |
{ |
| 2444 |
MHW_VDBOX_ROWSTORE_PARAMS rowstoreParams; |
| 2445 |
MOS_ZeroMemory(&rowstoreParams, sizeof(rowstoreParams)); |
| 2446 |
rowstoreParams.Mode = CODECHAL_ENCODE_MODE_AVC; |
| 2447 |
rowstoreParams.dwPicWidth = m_frameWidth; |
| 2448 |
rowstoreParams.bIsFrame = (seqParams->frame_mbs_only_flag == 1); |
| 2449 |
m_hwInterface->SetRowstoreCachingOffsets(&rowstoreParams); |
| 2450 |
} |
| 2451 |
|
| 2452 |
return eStatus; |
| 2453 |
} |
| 2454 |
|
| 2455 |
MOS_STATUS CodechalEncodeAvcBase::SetPictureStructs() |
| 2456 |
{ |
| 2457 |
CODECHAL_ENCODE_FUNCTION_ENTER; |
| 2458 |
MOS_STATUS eStatus = MOS_STATUS_SUCCESS; |
| 2459 |
|
| 2460 |
auto picParams = m_avcPicParam; |
| 2461 |
auto seqParams = m_avcSeqParam; |
| 2462 |
auto avcRefList = &m_refList[0]; |
| 2463 |
auto avcPicIdx = &m_picIdx[0]; |
| 2464 |
auto slcParams = m_avcSliceParams; |
| 2465 |
|
| 2466 |
if (seqParams->Profile == CODEC_AVC_MAIN_PROFILE || seqParams->Profile == CODEC_AVC_BASE_PROFILE) |
| 2467 |
{ |
| 2468 |
picParams->transform_8x8_mode_flag = 0; |
| 2469 |
picParams->pic_scaling_matrix_present_flag = 0; |
| 2470 |
for (uint8_t i = 0; i < 12; i++) |
| 2471 |
{ |
| 2472 |
picParams->pic_scaling_list_present_flag[i] = 0; |
| 2473 |
} |
| 2474 |
picParams->second_chroma_qp_index_offset = picParams->chroma_qp_index_offset; |
| 2475 |
} |
| 2476 |
if (picParams->QpY < 0) |
| 2477 |
{ |
| 2478 |
picParams->QpY = 25; // Set to default, recommended value used in simulation. |
| 2479 |
} |
| 2480 |
else if (picParams->QpY > CODECHAL_ENCODE_AVC_MAX_SLICE_QP) |
| 2481 |
{ |
| 2482 |
picParams->QpY = CODECHAL_ENCODE_AVC_MAX_SLICE_QP; // Crop to 51 if larger |
| 2483 |
} |
| 2484 |
picParams->pic_init_qp_minus26 = picParams->QpY - 26; |
| 2485 |
|
| 2486 |
if (!seqParams->seq_scaling_matrix_present_flag) |
| 2487 |
{ |
| 2488 |
if (!picParams->pic_scaling_matrix_present_flag) |
| 2489 |
ScalingListFlat(); |
| 2490 |
else if (!picParams->pic_scaling_list_present_flag[0]) |
| 2491 |
ScalingListFallbackRuleA(); |
| 2492 |
} |
| 2493 |
else if (!seqParams->seq_scaling_list_present_flag[0] && |
| 2494 |
!picParams->pic_scaling_list_present_flag[0]) |
| 2495 |
{ // fall-back rule A |
| 2496 |
ScalingListFallbackRuleA(); |
| 2497 |
} |
| 2498 |
|
| 2499 |
picParams->num_slice_groups_minus1 = 0; // do not support flexible MB ordering |
| 2500 |
picParams->deblocking_filter_control_present_flag = 1; // always set to 1 |
| 2501 |
picParams->redundant_pic_cnt_present_flag = 0; |
| 2502 |
picParams->pic_init_qs_minus26 = 0; // not used |
| 2503 |
|
| 2504 |
m_userFlags = picParams->UserFlags; |
| 2505 |
m_nalUnitType = picParams->bIdrPic ? CODECHAL_ENCODE_AVC_NAL_UT_IDR_SLICE : CODECHAL_ENCODE_AVC_NAL_UT_SLICE; |
| 2506 |
m_frameNum = picParams->frame_num; |
| 2507 |
m_lastPicInSeq = picParams->bLastPicInSeq; |
| 2508 |
m_lastPicInStream = picParams->bLastPicInStream; |
| 2509 |
// App handles tail insertion for VDEnc dynamic slice in non-cp case |
| 2510 |
if (m_vdencNoTailInsertion) |
| 2511 |
{ |
| 2512 |
m_lastPicInSeq = m_lastPicInStream = 0; |
| 2513 |
} |
| 2514 |
m_statusReportFeedbackNumber = picParams->StatusReportFeedbackNumber; |
| 2515 |
|
| 2516 |
auto prevPic = m_currOriginalPic; |
| 2517 |
auto prevIdx = prevPic.FrameIdx; |
| 2518 |
auto currPic = picParams->CurrOriginalPic; |
| 2519 |
auto currIdx = currPic.FrameIdx; |
| 2520 |
auto prevRefIdx = m_currReconstructedPic.FrameIdx; |
| 2521 |
auto currRefIdx = picParams->CurrReconstructedPic.FrameIdx; |
| 2522 |
|
| 2523 |
m_prevReconFrameIdx = m_currReconFrameIdx; |
| 2524 |
m_currReconFrameIdx = picParams->CurrReconstructedPic.FrameIdx; |
| 2525 |
|
| 2526 |
avcRefList[currRefIdx]->sRefReconBuffer = m_reconSurface; |
| 2527 |
avcRefList[currRefIdx]->sRefRawBuffer = m_rawSurface; |
| 2528 |
avcRefList[currRefIdx]->sFrameNumber = picParams->frame_num; |
| 2529 |
avcRefList[currRefIdx]->RefPic = currPic; |
| 2530 |
m_currOriginalPic = currPic; |
| 2531 |
m_currReconstructedPic = picParams->CurrReconstructedPic; |
| 2532 |
|
| 2533 |
if (picParams->FieldCodingFlag) |
| 2534 |
{ |
| 2535 |
m_frameFieldHeight = ((m_frameHeight + 1) >> 1); |
| 2536 |
m_frameFieldHeightInMb = ((m_picHeightInMb + 1) >> 1); |
| 2537 |
m_downscaledFrameFieldHeightInMb4x = ((m_downscaledHeightInMb4x + 1) >> 1); |
| 2538 |
m_downscaledFrameFieldHeightInMb16x = ((m_downscaledHeightInMb16x + 1) >> 1); |
| 2539 |
m_downscaledFrameFieldHeightInMb32x = ((m_downscaledHeightInMb32x + 1) >> 1); |
| 2540 |
m_currEncBbSet = MB_ENC_Field_BB; |
| 2541 |
if (CodecHal_PictureIsFrame(prevPic) || prevIdx != currIdx || |
| 2542 |
((prevPic.PicFlags != currPic.PicFlags) && !(slcParams->pic_order_cnt_lsb & 1))) |
| 2543 |
{ |
| 2544 |
m_firstField = 1; |
| 2545 |
// Enable self referencing for both IDR and I pics |
| 2546 |
m_firstFieldIdrPic = (picParams->CodingType == I_TYPE) ? 1 : 0; |
| 2547 |
} |
| 2548 |
else |
| 2549 |
{ |
| 2550 |
m_firstField = 0; |
| 2551 |
} |
| 2552 |
} |
| 2553 |
else |
| 2554 |
{ |
| 2555 |
m_frameFieldHeight = m_frameHeight; |
| 2556 |
m_frameFieldHeightInMb = m_picHeightInMb; |
| 2557 |
m_downscaledFrameFieldHeightInMb4x = m_downscaledHeightInMb4x; |
| 2558 |
m_downscaledFrameFieldHeightInMb16x = m_downscaledHeightInMb16x; |
| 2559 |
m_downscaledFrameFieldHeightInMb32x = m_downscaledHeightInMb32x; |
| 2560 |
m_firstField = 1; |
| 2561 |
m_currEncBbSet = MB_ENC_Frame_BB; |
| 2562 |
} |
| 2563 |
|
| 2564 |
if (picParams->FieldFrameCodingFlag) |
| 2565 |
{ // Mbaff |
| 2566 |
seqParams->mb_adaptive_frame_field_flag = 1; |
| 2567 |
m_mbaffEnabled = 1; |
| 2568 |
} |
| 2569 |
else |
| 2570 |
{ |
| 2571 |
seqParams->mb_adaptive_frame_field_flag = 0; |
| 2572 |
m_mbaffEnabled = 0; |
| 2573 |
} |
| 2574 |
|
| 2575 |
// P/B frames with empty ref lists are internally encoded as I frames, |
| 2576 |
// while picture header packing remains the original value |
| 2577 |
m_pictureCodingType = picParams->CodingType; |
| 2578 |
|
| 2579 |
bool emptyRefFrmList = true; |
| 2580 |
for (uint8_t i = 0; i < CODEC_AVC_MAX_NUM_REF_FRAME; i++) |
| 2581 |
{ |
| 2582 |
if (picParams->RefFrameList[i].PicFlags != PICTURE_INVALID) |
| 2583 |
{ |
| 2584 |
emptyRefFrmList = false; |
| 2585 |
break; |
| 2586 |
} |
| 2587 |
} |
| 2588 |
|
| 2589 |
if (emptyRefFrmList && m_pictureCodingType != I_TYPE) |
| 2590 |
{ |
| 2591 |
m_pictureCodingType = I_TYPE; |
| 2592 |
} |
| 2593 |
|
| 2594 |
avcRefList[currRefIdx]->bUsedAsRef = picParams->RefPicFlag; |
| 2595 |
avcRefList[currRefIdx]->resBitstreamBuffer = m_resBitstreamBuffer; |
| 2596 |
|
| 2597 |
for (uint8_t i = 0; i < 16; i++) |
| 2598 |
{ |
| 2599 |
m_avcFrameStoreID[i].inUse = false; |
| 2600 |
} |
| 2601 |
|
| 2602 |
for (uint8_t i = 0; i < 16; i++) |
| 2603 |
{ |
| 2604 |
avcPicIdx[i].bValid = false; |
| 2605 |
if (picParams->RefFrameList[i].PicFlags != PICTURE_INVALID) |
| 2606 |
{ |
| 2607 |
auto index = picParams->RefFrameList[i].FrameIdx; |
| 2608 |
uint8_t duplicatedIdx = 0; |
| 2609 |
for (uint8_t ii = 0; ii < i; ii++) |
| 2610 |
{ |
| 2611 |
if (avcPicIdx[ii].bValid && index == picParams->RefFrameList[ii].FrameIdx) |
| 2612 |
{ |
| 2613 |
duplicatedIdx = 1; |
| 2614 |
break; |
| 2615 |
} |
| 2616 |
} |
| 2617 |
if (duplicatedIdx) |
| 2618 |
{ |
| 2619 |
continue; |
| 2620 |
} |
| 2621 |
|
| 2622 |
avcRefList[index]->RefPic.PicFlags = |
| 2623 |
CodecHal_CombinePictureFlags(avcRefList[index]->RefPic, picParams->RefFrameList[i]); |
| 2624 |
avcRefList[index]->iFieldOrderCnt[0] = picParams->FieldOrderCntList[i][0]; |
| 2625 |
avcRefList[index]->iFieldOrderCnt[1] = picParams->FieldOrderCntList[i][1]; |
| 2626 |
avcPicIdx[i].bValid = true; |
| 2627 |
avcPicIdx[i].ucPicIdx = index; |
| 2628 |
if (prevPic.PicFlags != PICTURE_INVALID) |
| 2629 |
{ |
| 2630 |
uint8_t ii; |
| 2631 |
for (ii = 0; ii < avcRefList[prevRefIdx]->ucNumRef; ii++) |
| 2632 |
{ |
| 2633 |
if (index == avcRefList[prevRefIdx]->RefList[ii].FrameIdx) |
| 2634 |
{ |
| 2635 |
if (avcRefList[index]->ucFrameId == 0x1f) |
| 2636 |
{ |
| 2637 |
// Should never happen, something must be wrong |
| 2638 |
CODECHAL_ENCODE_ASSERT(false); |
| 2639 |
avcRefList[index]->ucFrameId = 0; |
| 2640 |
} |
| 2641 |
m_avcFrameStoreID[avcRefList[index]->ucFrameId].inUse = true; |
| 2642 |
break; |
| 2643 |
} |
| 2644 |
} |
| 2645 |
if (ii == avcRefList[prevRefIdx]->ucNumRef) |
| 2646 |
{ |
| 2647 |
avcRefList[index]->ucFrameId = 0x1f; |
| 2648 |
} |
| 2649 |
} |
| 2650 |
} |
| 2651 |
} |
| 2652 |
|
| 2653 |
// Save the current RefList |
| 2654 |
uint8_t ii = 0; |
| 2655 |
for (uint8_t i = 0; i < 16; i++) |
| 2656 |
{ |
| 2657 |
if (avcPicIdx[i].bValid) |
| 2658 |
{ |
| 2659 |
avcRefList[currRefIdx]->RefList[ii] = picParams->RefFrameList[i]; |
| 2660 |
ii++; |
| 2661 |
} |
| 2662 |
} |
| 2663 |
avcRefList[currRefIdx]->ucNumRef = ii; |
| 2664 |
m_currRefList = avcRefList[currRefIdx]; |
| 2665 |
|
| 2666 |
if (m_codecFunction == CODECHAL_FUNCTION_ENC) |
| 2667 |
{ |
| 2668 |
CODECHAL_ENCODE_CHK_NULL_RETURN(m_encodeParams.presMbCodeSurface); |
| 2669 |
m_resMbCodeSurface = *(m_encodeParams.presMbCodeSurface); |
| 2670 |
} |
| 2671 |
else if (m_codecFunction == CODECHAL_FUNCTION_ENC_PAK) |
| 2672 |
{ |
| 2673 |
if (m_encodeParams.presMbCodeSurface == nullptr || |
| 2674 |
Mos_ResourceIsNull(m_encodeParams.presMbCodeSurface)) |
| 2675 |
{ |
| 2676 |
// the actual MbCode/MvData surface to be allocated later |
| 2677 |
m_trackedBuf->SetAllocationFlag(true); |
| 2678 |
} |
| 2679 |
else |
| 2680 |
{ |
| 2681 |
m_resMbCodeSurface = *(m_encodeParams.presMbCodeSurface); |
| 2682 |
m_resMvDataSurface = *(m_encodeParams.presMbCodeSurface); |
| 2683 |
} |
| 2684 |
} |
| 2685 |
else if (CodecHalIsFeiEncode(m_codecFunction)) |
| 2686 |
{ |
| 2687 |
CodecEncodeAvcFeiPicParams *feiPicParams; |
| 2688 |
|
| 2689 |
feiPicParams = (CodecEncodeAvcFeiPicParams *)m_encodeParams.pFeiPicParams; |
| 2690 |
CODECHAL_ENCODE_CHK_NULL_RETURN(feiPicParams); |
| 2691 |
|
| 2692 |
// Use app provided buffer if available. For FEI_ENC and FEI_PAK, MBCodeMvEnable needs to be set to true |
| 2693 |
if (feiPicParams->MbCodeMvEnable) |
| 2694 |
{ |
| 2695 |
m_resMbCodeSurface = feiPicParams->resMBCode; |
| 2696 |
m_resMvDataSurface = feiPicParams->resMVData; |
| 2697 |
|
| 2698 |
// Inside the AvcRefList, mbCodesurface and mvdatasurface are stored at frame basis, |
| 2699 |
// For FEI, mbcode and mv data buffer are provided separately for each field picture and we need to store them separately. |
| 2700 |
if (CodecHal_PictureIsTopField(picParams->CurrOriginalPic)) |
| 2701 |
{ |
| 2702 |
avcRefList[currRefIdx]->resRefTopFieldMbCodeBuffer = m_resMbCodeSurface; |
| 2703 |
avcRefList[currRefIdx]->resRefTopFieldMvDataBuffer = m_resMvDataSurface; |
| 2704 |
} |
| 2705 |
else if (CodecHal_PictureIsBottomField(picParams->CurrOriginalPic)) |
| 2706 |
{ |
| 2707 |
avcRefList[currRefIdx]->resRefBotFieldMbCodeBuffer = m_resMbCodeSurface; |
| 2708 |
avcRefList[currRefIdx]->resRefBotFieldMvDataBuffer = m_resMvDataSurface; |
| 2709 |
} |
| 2710 |
|
| 2711 |
avcRefList[currRefIdx]->resRefMbCodeBuffer = m_resMbCodeSurface; |
| 2712 |
avcRefList[currRefIdx]->resRefMvDataBuffer = m_resMvDataSurface; |
| 2713 |
} |
| 2714 |
else |
| 2715 |
{ |
| 2716 |
// the actual MbCode/MvData surface to be allocated later |
| 2717 |
m_trackedBuf->SetAllocationFlag(true); |
| 2718 |
} |
| 2719 |
|
| 2720 |
if (feiPicParams->DistortionEnable) |
| 2721 |
{ |
| 2722 |
m_resDistortionBuffer = feiPicParams->resDistortion; |
| 2723 |
} |
| 2724 |
} |
| 2725 |
|
| 2726 |
SetFrameStoreIds(currRefIdx); |
| 2727 |
|
| 2728 |
avcRefList[currRefIdx]->iFieldOrderCnt[0] = picParams->CurrFieldOrderCnt[0]; |
| 2729 |
avcRefList[currRefIdx]->iFieldOrderCnt[1] = picParams->CurrFieldOrderCnt[1]; |
| 2730 |
m_refList[currRefIdx]->ucAvcPictureCodingType = (CodecHal_PictureIsFrame(picParams->CurrOriginalPic)) ? CODEC_AVC_PIC_CODING_TYPE_FRAME : ((picParams->CurrFieldOrderCnt[0] < picParams->CurrFieldOrderCnt[1]) ? CODEC_AVC_PIC_CODING_TYPE_TFF_FIELD : CODEC_AVC_PIC_CODING_TYPE_BFF_FIELD); |
| 2731 |
|
| 2732 |
m_hmeEnabled = m_hmeSupported && m_pictureCodingType != I_TYPE; |
| 2733 |
m_16xMeEnabled = m_16xMeSupported && m_pictureCodingType != I_TYPE; |
| 2734 |
m_32xMeEnabled = m_32xMeSupported && m_pictureCodingType != I_TYPE; |
| 2735 |
|
| 2736 |
if (m_pictureCodingType == B_TYPE) |
| 2737 |
{ |
| 2738 |
GetDistScaleFactor(); |
| 2739 |
m_biWeight = GetBiWeight( |
| 2740 |
m_distScaleFactorList0[0], |
| 2741 |
m_avcPicParam->weighted_bipred_idc); |
| 2742 |
} |
| 2743 |
|
| 2744 |
m_verticalLineStride = CODECHAL_VLINESTRIDE_FRAME; |
| 2745 |
m_verticalLineStrideOffset = CODECHAL_VLINESTRIDEOFFSET_TOP_FIELD; |
| 2746 |
m_mbcodeBottomFieldOffset = 0; |
| 2747 |
m_mvBottomFieldOffset = 0; |
| 2748 |
m_meDistortionBottomFieldOffset = 0; |
| 2749 |
m_meMvBottomFieldOffset = 0; |
| 2750 |
m_meMv16xBottomFieldOffset = 0; |
| 2751 |
m_meMv32xBottomFieldOffset = 0; |
| 2752 |
m_sliceMapBottomFieldOffset = 0; |
| 2753 |
if (m_hmeKernel) |
| 2754 |
{ |
| 2755 |
m_hmeKernel->Set4xMeMvBottomFieldOffset(0); |
| 2756 |
m_hmeKernel->Set16xMeMvBottomFieldOffset(0); |
| 2757 |
m_hmeKernel->Set32xMeMvBottomFieldOffset(0); |
| 2758 |
m_hmeKernel->SetDistortionBottomFieldOffset(0); |
| 2759 |
} |
| 2760 |
|
| 2761 |
if (CodecHal_PictureIsField(m_currOriginalPic)) |
| 2762 |
{ |
| 2763 |
m_verticalLineStride = CODECHAL_VLINESTRIDE_FIELD; |
| 2764 |
m_frameHeight = m_frameFieldHeightInMb * 2 * 16; |
| 2765 |
m_picHeightInMb = (uint16_t)(m_frameHeight / 16); |
| 2766 |
if (CodecHal_PictureIsBottomField(m_currOriginalPic)) |
| 2767 |
{ |
| 2768 |
m_sliceMapBottomFieldOffset = MOS_ALIGN_CEIL((m_picWidthInMb + 1) * sizeof(uint32_t), 64) * m_frameFieldHeightInMb; |
| 2769 |
m_verticalLineStrideOffset = CODECHAL_VLINESTRIDEOFFSET_BOT_FIELD; |
| 2770 |
|
| 2771 |
if (CodecHalIsFeiEncode(m_codecFunction)) |
| 2772 |
{ |
| 2773 |
CodecEncodeAvcFeiPicParams *feiPicParams; |
| 2774 |
|
| 2775 |
feiPicParams = (CodecEncodeAvcFeiPicParams *)m_encodeParams.pFeiPicParams; |
| 2776 |
CODECHAL_ENCODE_CHK_NULL_RETURN(feiPicParams); |
| 2777 |
|
| 2778 |
// for user provided MbCode and Mv data buffer, set BottomFieldOffset to 0 |
| 2779 |
if (feiPicParams->MbCodeMvEnable) |
| 2780 |
{ |
| 2781 |
m_mbcodeBottomFieldOffset = 0; |
| 2782 |
m_mvBottomFieldOffset = 0; |
| 2783 |
} |
| 2784 |
else |
| 2785 |
{ |
| 2786 |
m_mbcodeBottomFieldOffset = m_frameFieldHeightInMb * m_picWidthInMb * 64; |
| 2787 |
m_mvBottomFieldOffset = |
| 2788 |
MOS_ALIGN_CEIL(m_frameFieldHeightInMb * m_picWidthInMb * (32 * 4), CODECHAL_PAGE_SIZE); |
| 2789 |
} |
| 2790 |
} |
| 2791 |
else |
| 2792 |
{ |
| 2793 |
m_mbcodeBottomFieldOffset = m_frameFieldHeightInMb * m_picWidthInMb * 64; |
| 2794 |
m_mvBottomFieldOffset = |
| 2795 |
MOS_ALIGN_CEIL(m_frameFieldHeightInMb * m_picWidthInMb * (32 * 4), CODECHAL_PAGE_SIZE); |
| 2796 |
} |
| 2797 |
|
| 2798 |
m_meDistortionBottomFieldOffset = |
| 2799 |
MOS_ALIGN_CEIL((m_downscaledWidthInMb4x * 8), 64) * |
| 2800 |
MOS_ALIGN_CEIL((m_downscaledFrameFieldHeightInMb4x * 4 * 10), 8); |
| 2801 |
m_meMvBottomFieldOffset = |
| 2802 |
MOS_ALIGN_CEIL((m_downscaledWidthInMb4x * 32), 64) * |
| 2803 |
(m_downscaledFrameFieldHeightInMb4x * 4 * CODECHAL_ENCODE_ME_DATA_SIZE_MULTIPLIER); |
| 2804 |
if (m_16xMeEnabled) |
| 2805 |
{ |
| 2806 |
m_meMv16xBottomFieldOffset = |
| 2807 |
MOS_ALIGN_CEIL((m_downscaledWidthInMb16x * 32), 64) * |
| 2808 |
(m_downscaledFrameFieldHeightInMb16x * 4 * CODECHAL_ENCODE_ME_DATA_SIZE_MULTIPLIER); |
| 2809 |
if (m_32xMeEnabled) |
| 2810 |
{ |
| 2811 |
m_meMv32xBottomFieldOffset = |
| 2812 |
MOS_ALIGN_CEIL((m_downscaledWidthInMb32x * 32), 64) * |
| 2813 |
(m_downscaledFrameFieldHeightInMb32x * 4 * CODECHAL_ENCODE_ME_DATA_SIZE_MULTIPLIER); |
| 2814 |
} |
| 2815 |
} |
| 2816 |
|
| 2817 |
if (m_hmeKernel) |
| 2818 |
{ |
| 2819 |
m_hmeKernel->SetDistortionBottomFieldOffset( |
| 2820 |
MOS_ALIGN_CEIL((m_downscaledWidthInMb4x * 8), 64) * |
| 2821 |
MOS_ALIGN_CEIL((m_downscaledFrameFieldHeightInMb4x * 4 * 10), 8)); |
| 2822 |
m_hmeKernel->Set4xMeMvBottomFieldOffset( |
| 2823 |
MOS_ALIGN_CEIL((m_downscaledWidthInMb4x * 32), 64) * |
| 2824 |
(m_downscaledFrameFieldHeightInMb4x * 4 * CODECHAL_ENCODE_ME_DATA_SIZE_MULTIPLIER)); |
| 2825 |
if (m_hmeKernel->Is16xMeEnabled()) |
| 2826 |
{ |
| 2827 |
m_hmeKernel->Set16xMeMvBottomFieldOffset( |
| 2828 |
MOS_ALIGN_CEIL((m_downscaledWidthInMb16x * 32), 64) * |
| 2829 |
(m_downscaledFrameFieldHeightInMb16x * 4 * CODECHAL_ENCODE_ME_DATA_SIZE_MULTIPLIER)); |
| 2830 |
if (m_hmeKernel->Is32xMeEnabled()) |
| 2831 |
{ |
| 2832 |
m_hmeKernel->Set32xMeMvBottomFieldOffset( |
| 2833 |
MOS_ALIGN_CEIL((m_downscaledWidthInMb32x * 32), 64) * |
| 2834 |
(m_downscaledFrameFieldHeightInMb32x * 4 * CODECHAL_ENCODE_ME_DATA_SIZE_MULTIPLIER)); |
| 2835 |
} |
| 2836 |
} |
| 2837 |
} |
| 2838 |
} |
| 2839 |
} |
| 2840 |
|
| 2841 |
//save reference surface |
| 2842 |
for (uint8_t i = 0; i < CODEC_AVC_MAX_NUM_REF_FRAME; i++) |
| 2843 |
{ |
| 2844 |
if (picParams->RefFrameListSurface[i].dwSize != 0 && avcRefList[i] != NULL) |
| 2845 |
{ |
| 2846 |
avcRefList[i]->sRefReconBuffer = picParams->RefFrameListSurface[i]; |
| 2847 |
} |
| 2848 |
} |
| 2849 |
return eStatus; |
| 2850 |
} |
| 2851 |
|
| 2852 |
MOS_STATUS CodechalEncodeAvcBase::EncodeMeKernel( |
| 2853 |
EncodeBrcBuffers *brcBuffers, |
| 2854 |
HmeLevel hmeLevel) |
| 2855 |
{ |
| 2856 |
MOS_STATUS eStatus = MOS_STATUS_SUCCESS; |
| 2857 |
|
| 2858 |
CODECHAL_ENCODE_FUNCTION_ENTER; |
| 2859 |
|
| 2860 |
PerfTagSetting perfTag; |
| 2861 |
perfTag.Value = 0; |
| 2862 |
perfTag.Mode = (uint16_t)m_mode & CODECHAL_ENCODE_MODE_BIT_MASK; |
| 2863 |
perfTag.CallType = m_singleTaskPhaseSupported ? CODECHAL_ENCODE_PERFTAG_CALL_SCALING_KERNEL : CODECHAL_ENCODE_PERFTAG_CALL_ME_KERNEL; |
| 2864 |
perfTag.PictureCodingType = m_pictureCodingType; |
| 2865 |
m_osInterface->pfnSetPerfTag(m_osInterface, perfTag.Value); |
| 2866 |
// Each ME kernel buffer counts as a separate perf task |
| 2867 |
m_osInterface->pfnResetPerfBufferID(m_osInterface); |
| 2868 |
|
| 2869 |
CODECHAL_MEDIA_STATE_TYPE encFunctionType = (hmeLevel == HME_LEVEL_32x) ? CODECHAL_MEDIA_STATE_32X_ME : (hmeLevel == HME_LEVEL_16x) ? CODECHAL_MEDIA_STATE_16X_ME : CODECHAL_MEDIA_STATE_4X_ME; |
| 2870 |
|
| 2871 |
bool vdencMeInUse = false; |
| 2872 |
if (m_vdencEnabled && (encFunctionType == CODECHAL_MEDIA_STATE_4X_ME)) |
| 2873 |
{ |
| 2874 |
vdencMeInUse = true; |
| 2875 |
encFunctionType = CODECHAL_MEDIA_STATE_ME_VDENC_STREAMIN; |
| 2876 |
} |
| 2877 |
|
| 2878 |
uint32_t krnStateIdx = vdencMeInUse ? CODECHAL_ENCODE_ME_IDX_VDENC : ((m_pictureCodingType == P_TYPE) ? CODECHAL_ENCODE_ME_IDX_P : CODECHAL_ENCODE_ME_IDX_B); |
| 2879 |
auto kernelState = &m_meKernelStates[krnStateIdx]; |
| 2880 |
|
| 2881 |
// If Single Task Phase is not enabled, use BT count for the kernel state. |
| 2882 |
if (m_firstTaskInPhase || !m_singleTaskPhaseSupported) |
| 2883 |
{ |
| 2884 |
uint32_t maxBtCount = m_singleTaskPhaseSupported ? m_maxBtCount : kernelState->KernelParams.iBTCount; |
| 2885 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(m_stateHeapInterface->pfnRequestSshSpaceForCmdBuf( |
| 2886 |
m_stateHeapInterface, |
| 2887 |
maxBtCount)); |
| 2888 |
m_vmeStatesSize = m_hwInterface->GetKernelLoadCommandSize(maxBtCount); |
| 2889 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(VerifySpaceAvailable()); |
| 2890 |
} |
| 2891 |
|
| 2892 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(m_hwInterface->AssignDshAndSshSpace( |
| 2893 |
m_stateHeapInterface, |
| 2894 |
kernelState, |
| 2895 |
false, |
| 2896 |
0, |
| 2897 |
false, |
| 2898 |
m_storeData)); |
| 2899 |
|
| 2900 |
MHW_INTERFACE_DESCRIPTOR_PARAMS idParams; |
| 2901 |
MOS_ZeroMemory(&idParams, sizeof(idParams)); |
| 2902 |
idParams.pKernelState = kernelState; |
| 2903 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(m_stateHeapInterface->pfnSetInterfaceDescriptor( |
| 2904 |
m_stateHeapInterface, |
| 2905 |
1, |
| 2906 |
&idParams)); |
| 2907 |
|
| 2908 |
// Setup AVC Curbe |
| 2909 |
MeCurbeParams meParams; |
| 2910 |
MOS_ZeroMemory(&meParams, sizeof(meParams)); |
| 2911 |
meParams.hmeLvl = hmeLevel; |
| 2912 |
meParams.pKernelState = kernelState; |
| 2913 |
|
| 2914 |
if (!m_useCommonKernel) |
| 2915 |
{ |
| 2916 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(SetCurbeMe(&meParams)); |
| 2917 |
} |
| 2918 |
|
| 2919 |
CODECHAL_DEBUG_TOOL( |
| 2920 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(m_debugInterface->DumpKernelRegion( |
| 2921 |
encFunctionType, |
| 2922 |
MHW_DSH_TYPE, |
| 2923 |
kernelState)); |
| 2924 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(m_debugInterface->DumpCurbe( |
| 2925 |
encFunctionType, |
| 2926 |
kernelState)); |
| 2927 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(m_debugInterface->DumpKernelRegion( |
| 2928 |
encFunctionType, |
| 2929 |
MHW_ISH_TYPE, |
| 2930 |
kernelState));) |
| 2931 |
|
| 2932 |
MOS_COMMAND_BUFFER cmdBuffer; |
| 2933 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(m_osInterface->pfnGetCommandBuffer(m_osInterface, &cmdBuffer, 0)); |
| 2934 |
|
| 2935 |
SendKernelCmdsParams sendKernelCmdsParams = SendKernelCmdsParams(); |
| 2936 |
sendKernelCmdsParams.EncFunctionType = encFunctionType; |
| 2937 |
sendKernelCmdsParams.pKernelState = kernelState; |
| 2938 |
|
| 2939 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(SendGenericKernelCmds(&cmdBuffer, &sendKernelCmdsParams)); |
| 2940 |
|
| 2941 |
// Add binding table |
| 2942 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(m_stateHeapInterface->pfnSetBindingTable( |
| 2943 |
m_stateHeapInterface, |
| 2944 |
kernelState)); |
| 2945 |
|
| 2946 |
//Add surface states |
| 2947 |
MeSurfaceParams meSurfaceParams; |
| 2948 |
MOS_ZeroMemory(&meSurfaceParams, sizeof(meSurfaceParams)); |
| 2949 |
meSurfaceParams.dwNumRefIdxL0ActiveMinus1 = m_avcSliceParams->num_ref_idx_l0_active_minus1; |
| 2950 |
meSurfaceParams.dwNumRefIdxL1ActiveMinus1 = m_avcSliceParams->num_ref_idx_l1_active_minus1; |
| 2951 |
meSurfaceParams.pL0RefFrameList = &(m_avcSliceParams->RefPicList[LIST_0][0]); |
| 2952 |
meSurfaceParams.pL1RefFrameList = &(m_avcSliceParams->RefPicList[LIST_1][0]); |
| 2953 |
meSurfaceParams.ppRefList = &m_refList[0]; |
| 2954 |
meSurfaceParams.pPicIdx = &m_picIdx[0]; |
| 2955 |
meSurfaceParams.pCurrOriginalPic = &m_currOriginalPic; |
| 2956 |
meSurfaceParams.ps4xMeMvDataBuffer = &m_4xMeMvDataBuffer; |
| 2957 |
meSurfaceParams.dw4xMeMvBottomFieldOffset = (uint32_t)m_meMvBottomFieldOffset; |
| 2958 |
meSurfaceParams.ps16xMeMvDataBuffer = &m_16xMeMvDataBuffer; |
| 2959 |
meSurfaceParams.dw16xMeMvBottomFieldOffset = (uint32_t)m_meMv16xBottomFieldOffset; |
| 2960 |
meSurfaceParams.ps32xMeMvDataBuffer = &m_32xMeMvDataBuffer; |
| 2961 |
meSurfaceParams.dw32xMeMvBottomFieldOffset = (uint32_t)m_meMv32xBottomFieldOffset; |
| 2962 |
meSurfaceParams.dw4xScaledBottomFieldOffset = (uint32_t)m_scaledBottomFieldOffset; |
| 2963 |
meSurfaceParams.dw16xScaledBottomFieldOffset = (uint32_t)m_scaled16xBottomFieldOffset; |
| 2964 |
meSurfaceParams.dw32xScaledBottomFieldOffset = (uint32_t)m_scaled32xBottomFieldOffset; |
| 2965 |
meSurfaceParams.psMeDistortionBuffer = &m_4xMeDistortionBuffer; |
| 2966 |
meSurfaceParams.dwMeDistortionBottomFieldOffset = (uint32_t)m_meDistortionBottomFieldOffset; |
| 2967 |
if (nullptr != brcBuffers) |
| 2968 |
{ |
| 2969 |
meSurfaceParams.psMeBrcDistortionBuffer = &brcBuffers->sMeBrcDistortionBuffer; |
| 2970 |
meSurfaceParams.dwMeBrcDistortionBottomFieldOffset = brcBuffers->dwMeBrcDistortionBottomFieldOffset; |
| 2971 |
} |
| 2972 |
meSurfaceParams.psMeVdencStreamInBuffer = &m_resVdencStreamInBuffer[m_currRecycledBufIdx]; |
| 2973 |
meSurfaceParams.dwDownscaledWidthInMb = (hmeLevel == HME_LEVEL_32x) ? m_downscaledWidthInMb32x : (hmeLevel == HME_LEVEL_16x) ? m_downscaledWidthInMb16x : m_downscaledWidthInMb4x; |
| 2974 |
meSurfaceParams.dwDownscaledHeightInMb = (hmeLevel == HME_LEVEL_32x) ? m_downscaledFrameFieldHeightInMb32x : (hmeLevel == HME_LEVEL_16x) ? m_downscaledFrameFieldHeightInMb16x : m_downscaledFrameFieldHeightInMb4x; |
| 2975 |
meSurfaceParams.dwVerticalLineStride = m_verticalLineStride; |
| 2976 |
meSurfaceParams.dwVerticalLineStrideOffset = m_verticalLineStrideOffset; |
| 2977 |
meSurfaceParams.b32xMeInUse = (hmeLevel == HME_LEVEL_32x) ? true : false; |
| 2978 |
meSurfaceParams.b16xMeInUse = (hmeLevel == HME_LEVEL_16x) ? true : false; |
| 2979 |
meSurfaceParams.b32xMeEnabled = m_32xMeEnabled; |
| 2980 |
meSurfaceParams.b16xMeEnabled = m_16xMeEnabled; |
| 2981 |
meSurfaceParams.bVdencStreamInEnabled = m_vdencEnabled && (m_16xMeSupported || m_staticFrameDetectionInUse); |
| 2982 |
meSurfaceParams.pMeBindingTable = &m_meBindingTable; |
| 2983 |
meSurfaceParams.pKernelState = kernelState; |
| 2984 |
meSurfaceParams.dwVDEncStreamInSurfaceSize = MOS_BYTES_TO_DWORDS(m_picHeightInMb * m_picWidthInMb * 64); |
| 2985 |
|
| 2986 |
if (!m_useCommonKernel) |
| 2987 |
{ |
| 2988 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(SendMeSurfaces(&cmdBuffer, &meSurfaceParams)); |
| 2989 |
} |
| 2990 |
|
| 2991 |
// Dump SSH for ME kernel |
| 2992 |
CODECHAL_DEBUG_TOOL( |
| 2993 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(m_debugInterface->DumpKernelRegion( |
| 2994 |
encFunctionType, |
| 2995 |
MHW_SSH_TYPE, |
| 2996 |
kernelState))); |
| 2997 |
|
| 2998 |
/* zero out the mv data memory and me distortion buffer for the driver ULT |
| 2999 |
kernel only writes out this data used for current frame, in some cases the the data used for |
| 3000 |
previous frames would be left in the buffer (for example, the L1 mv for B frame would still show |
| 3001 |
in the P frame mv data buffer */ |
| 3002 |
|
| 3003 |
/* Zeroing out the buffers has perf impact, so zero it out only when dumps are actually enabled */ |
| 3004 |
|
| 3005 |
CODECHAL_DEBUG_TOOL( |
| 3006 |
CODECHAL_ENCODE_CHK_NULL_RETURN(m_debugInterface); |
| 3007 |
uint8_t * data; |
| 3008 |
uint32_t size; |
| 3009 |
bool driverMeDumpEnabled; |
| 3010 |
|
| 3011 |
driverMeDumpEnabled = m_debugInterface->DumpIsEnabled(CodechalDbgKernel::kernel4xMe) || |
| 3012 |
m_debugInterface->DumpIsEnabled(CodechalDbgKernel::kernel16xMe) || |
| 3013 |
m_debugInterface->DumpIsEnabled(CodechalDbgKernel::kernel32xMe); |
| 3014 |
|
| 3015 |
if (driverMeDumpEnabled) { |
| 3016 |
MOS_LOCK_PARAMS lockFlags; |
| 3017 |
MOS_ZeroMemory(&lockFlags, sizeof(MOS_LOCK_PARAMS)); |
| 3018 |
lockFlags.WriteOnly = 1; |
| 3019 |
|
| 3020 |
switch (hmeLevel) |
| 3021 |
{ |
| 3022 |
case HME_LEVEL_32x: |
| 3023 |
data = (uint8_t *)m_osInterface->pfnLockResource( |
| 3024 |
m_osInterface, |
| 3025 |
&m_32xMeMvDataBuffer.OsResource, |
| 3026 |
&lockFlags); |
| 3027 |
CODECHAL_ENCODE_CHK_NULL_RETURN(data); |
| 3028 |
size = MOS_ALIGN_CEIL((m_downscaledWidthInMb32x * 32), 64) * |
| 3029 |
(m_downscaledHeightInMb32x * 2 * 4 * CODECHAL_ENCODE_ME_DATA_SIZE_MULTIPLIER); |
| 3030 |
MOS_ZeroMemory(data, size); |
| 3031 |
m_osInterface->pfnUnlockResource( |
| 3032 |
m_osInterface, |
| 3033 |
&m_32xMeMvDataBuffer.OsResource); |
| 3034 |
break; |
| 3035 |
case HME_LEVEL_16x: |
| 3036 |
data = (uint8_t *)m_osInterface->pfnLockResource( |
| 3037 |
m_osInterface, |
| 3038 |
&m_16xMeMvDataBuffer.OsResource, |
| 3039 |
&lockFlags); |
| 3040 |
CODECHAL_ENCODE_CHK_NULL_RETURN(data); |
| 3041 |
size = MOS_ALIGN_CEIL((m_downscaledWidthInMb16x * 32), 64) * |
| 3042 |
(m_downscaledHeightInMb16x * 2 * 4 * CODECHAL_ENCODE_ME_DATA_SIZE_MULTIPLIER); |
| 3043 |
MOS_ZeroMemory(data, size); |
| 3044 |
m_osInterface->pfnUnlockResource( |
| 3045 |
m_osInterface, |
| 3046 |
&m_16xMeMvDataBuffer.OsResource); |
| 3047 |
break; |
| 3048 |
case HME_LEVEL_4x: |
| 3049 |
if (!m_vdencEnabled) |
| 3050 |
{ |
| 3051 |
data = (uint8_t *)m_osInterface->pfnLockResource( |
| 3052 |
m_osInterface, |
| 3053 |
&m_4xMeMvDataBuffer.OsResource, |
| 3054 |
&lockFlags); |
| 3055 |
CODECHAL_ENCODE_CHK_NULL_RETURN(data); |
| 3056 |
size = MOS_ALIGN_CEIL((m_downscaledWidthInMb4x * 32), 64) * |
| 3057 |
(m_downscaledHeightInMb4x * 2 * 4 * CODECHAL_ENCODE_ME_DATA_SIZE_MULTIPLIER); |
| 3058 |
MOS_ZeroMemory(data, size); |
| 3059 |
m_osInterface->pfnUnlockResource( |
| 3060 |
m_osInterface, |
| 3061 |
&m_4xMeMvDataBuffer.OsResource); |
| 3062 |
} |
| 3063 |
break; |
| 3064 |
default: |
| 3065 |
return MOS_STATUS_INVALID_PARAMETER; |
| 3066 |
} |
| 3067 |
|
| 3068 |
// zeroing out ME dist buffer |
| 3069 |
if (m_4xMeDistortionBufferSupported) |
| 3070 |
{ |
| 3071 |
data = (uint8_t *)m_osInterface->pfnLockResource( |
| 3072 |
m_osInterface, &m_4xMeDistortionBuffer.OsResource, &lockFlags); |
| 3073 |
CODECHAL_ENCODE_CHK_NULL_RETURN(data); |
| 3074 |
size = m_4xMeDistortionBuffer.dwHeight * m_4xMeDistortionBuffer.dwPitch; |
| 3075 |
MOS_ZeroMemory(data, size); |
| 3076 |
m_osInterface->pfnUnlockResource( |
| 3077 |
m_osInterface, |
| 3078 |
&m_4xMeDistortionBuffer.OsResource); |
| 3079 |
} |
| 3080 |
}); |
| 3081 |
|
| 3082 |
uint32_t scalingFactor = (hmeLevel == HME_LEVEL_32x) ? SCALE_FACTOR_32x : (hmeLevel == HME_LEVEL_16x) ? SCALE_FACTOR_16x : SCALE_FACTOR_4x; |
| 3083 |
|
| 3084 |
uint32_t resolutionX = CODECHAL_GET_WIDTH_IN_MACROBLOCKS(m_frameWidth / scalingFactor); |
| 3085 |
uint32_t resolutionY = CODECHAL_GET_HEIGHT_IN_MACROBLOCKS(m_frameFieldHeight / scalingFactor); |
| 3086 |
|
| 3087 |
CODECHAL_WALKER_CODEC_PARAMS walkerCodecParams; |
| 3088 |
MOS_ZeroMemory(&walkerCodecParams, sizeof(walkerCodecParams)); |
| 3089 |
walkerCodecParams.WalkerMode = m_walkerMode; |
| 3090 |
walkerCodecParams.dwResolutionX = resolutionX; |
| 3091 |
walkerCodecParams.dwResolutionY = resolutionY; |
| 3092 |
walkerCodecParams.bNoDependency = true; |
| 3093 |
walkerCodecParams.bMbaff = m_mbaffEnabled; |
| 3094 |
walkerCodecParams.bGroupIdSelectSupported = m_groupIdSelectSupported; |
| 3095 |
walkerCodecParams.ucGroupId = m_groupId; |
| 3096 |
|
| 3097 |
MHW_WALKER_PARAMS walkerParams; |
| 3098 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(CodecHalInitMediaObjectWalkerParams( |
| 3099 |
m_hwInterface, |
| 3100 |
&walkerParams, |
| 3101 |
&walkerCodecParams)); |
| 3102 |
|
| 3103 |
HalOcaInterface::TraceMessage(cmdBuffer, (MOS_CONTEXT_HANDLE)m_osInterface->pOsContext, __FUNCTION__, sizeof(__FUNCTION__)); |
| 3104 |
HalOcaInterface::OnDispatch(cmdBuffer, *m_osInterface, *m_miInterface, *m_renderEngineInterface->GetMmioRegisters()); |
| 3105 |
|
| 3106 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(m_renderEngineInterface->AddMediaObjectWalkerCmd( |
| 3107 |
&cmdBuffer, |
| 3108 |
&walkerParams)); |
| 3109 |
|
| 3110 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(EndStatusReport(&cmdBuffer, encFunctionType)); |
| 3111 |
|
| 3112 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(m_stateHeapInterface->pfnSubmitBlocks( |
| 3113 |
m_stateHeapInterface, |
| 3114 |
kernelState)); |
| 3115 |
if (!m_singleTaskPhaseSupported || m_lastTaskInPhase) |
| 3116 |
{ |
| 3117 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(m_stateHeapInterface->pfnUpdateGlobalCmdBufId( |
| 3118 |
m_stateHeapInterface)); |
| 3119 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(m_miInterface->AddMiBatchBufferEnd(&cmdBuffer, nullptr)); |
| 3120 |
} |
| 3121 |
|
| 3122 |
CODECHAL_DEBUG_TOOL(CODECHAL_ENCODE_CHK_STATUS_RETURN(m_debugInterface->DumpCmdBuffer( |
| 3123 |
&cmdBuffer, |
| 3124 |
encFunctionType, |
| 3125 |
nullptr))); |
| 3126 |
|
| 3127 |
m_hwInterface->UpdateSSEuForCmdBuffer(&cmdBuffer, m_singleTaskPhaseSupported, m_lastTaskInPhase); |
| 3128 |
|
| 3129 |
m_osInterface->pfnReturnCommandBuffer(m_osInterface, &cmdBuffer, 0); |
| 3130 |
|
| 3131 |
if (!m_singleTaskPhaseSupported || m_lastTaskInPhase) |
| 3132 |
{ |
| 3133 |
HalOcaInterface::On1stLevelBBEnd(cmdBuffer, *m_osInterface); |
| 3134 |
m_osInterface->pfnSubmitCommandBuffer(m_osInterface, &cmdBuffer, m_renderContextUsesNullHw); |
| 3135 |
m_lastTaskInPhase = false; |
| 3136 |
} |
| 3137 |
|
| 3138 |
return eStatus; |
| 3139 |
} |
| 3140 |
|
| 3141 |
MOS_STATUS CodechalEncodeAvcBase::SetSliceStructs() |
| 3142 |
{ |
| 3143 |
MOS_STATUS eStatus = MOS_STATUS_SUCCESS; |
| 3144 |
CODECHAL_ENCODE_FUNCTION_ENTER; |
| 3145 |
|
| 3146 |
auto slcParams = m_avcSliceParams; |
| 3147 |
auto seqParams = m_avcSeqParam; |
| 3148 |
auto picParams = m_avcPicParam; |
| 3149 |
|
| 3150 |
// Save the QP value |
| 3151 |
if (CodecHal_PictureIsBottomField(picParams->CurrOriginalPic)) |
| 3152 |
{ |
| 3153 |
m_refList[m_currReconstructedPic.FrameIdx]->ucQPValue[1] = |
| 3154 |
picParams->pic_init_qp_minus26 + 26 + slcParams->slice_qp_delta; |
| 3155 |
} |
| 3156 |
else |
| 3157 |
{ |
| 3158 |
m_refList[m_currReconstructedPic.FrameIdx]->ucQPValue[0] = |
| 3159 |
picParams->pic_init_qp_minus26 + 26 + slcParams->slice_qp_delta; |
| 3160 |
} |
| 3161 |
|
| 3162 |
uint32_t numMbsInPrevSlice = slcParams->NumMbsForSlice; // Initiailize to num mbs in first slice |
| 3163 |
uint32_t numMbsForFirstSlice; |
| 3164 |
uint32_t numMbs = 0; |
| 3165 |
|
| 3166 |
for (uint32_t sliceCount = 0; sliceCount < m_numSlices; sliceCount++) |
| 3167 |
{ |
| 3168 |
if (m_sliceStructCaps != CODECHAL_SLICE_STRUCT_ARBITRARYMBSLICE) |
| 3169 |
{ |
| 3170 |
if (sliceCount == 0) |
| 3171 |
{ |
| 3172 |
numMbsForFirstSlice = slcParams->NumMbsForSlice; |
| 3173 |
// In current kernel, the same MB number in the slice must be number of MB rows. |
| 3174 |
if (numMbsForFirstSlice % m_picWidthInMb) |
| 3175 |
{ |
| 3176 |
eStatus = MOS_STATUS_INVALID_PARAMETER; |
| 3177 |
return eStatus; |
| 3178 |
} |
| 3179 |
m_sliceHeight = numMbsForFirstSlice / m_picWidthInMb; |
| 3180 |
// Slice height should be in power of 2 |
| 3181 |
if (m_sliceStructCaps == CODECHAL_SLICE_STRUCT_POW2ROWS && (m_sliceHeight & (m_sliceHeight - 1))) |
| 3182 |
{ |
| 3183 |
// app can only pass orig numMBs in picture for single slice, set slice height to the nearest pow2 |
| 3184 |
if (m_numSlices == 1) |
| 3185 |
{ |
| 3186 |
uint16_t sliceHeightPow2 = 1; |
| 3187 |
while (sliceHeightPow2 < m_sliceHeight) |
| 3188 |
{ |
| 3189 |
sliceHeightPow2 <<= 1; |
| 3190 |
} |
| 3191 |
m_sliceHeight = sliceHeightPow2; |
| 3192 |
} |
| 3193 |
else |
| 3194 |
{ |
| 3195 |
eStatus = MOS_STATUS_INVALID_PARAMETER; |
| 3196 |
return eStatus; |
| 3197 |
} |
| 3198 |
} |
| 3199 |
} |
| 3200 |
// VME: In current kernel, all slices should have the same MBs except the last one, the last one should have no more MBs than the previous |
| 3201 |
else if (!m_vdencEnabled || (m_vdencEnabled && m_sliceStructCaps == CODECHAL_SLICE_STRUCT_ROWSLICE)) |
| 3202 |
{ |
| 3203 |
if ((sliceCount < m_numSlices - 1 && numMbsForFirstSlice != slcParams->NumMbsForSlice) || |
| 3204 |
(sliceCount == m_numSlices - 1 && numMbsForFirstSlice < slcParams->NumMbsForSlice)) |
| 3205 |
{ |
| 3206 |
eStatus = MOS_STATUS_INVALID_PARAMETER; |
| 3207 |
return eStatus; |
| 3208 |
} |
| 3209 |
} |
| 3210 |
|
| 3211 |
// Gaps between slices are not allowed |
| 3212 |
if (slcParams->first_mb_in_slice != numMbs) |
| 3213 |
{ |
| 3214 |
eStatus = MOS_STATUS_INVALID_PARAMETER; |
| 3215 |
return eStatus; |
| 3216 |
} |
| 3217 |
numMbs += slcParams->NumMbsForSlice; |
| 3218 |
} |
| 3219 |
else // SLICE_STRUCT_ARBITRARYMBSLICE |
| 3220 |
{ |
| 3221 |
uint8_t ppsIdx = m_avcSliceParams->pic_parameter_set_id; |
| 3222 |
uint8_t refPicListIdx = m_avcSliceParams[ppsIdx].RefPicList[0][0].FrameIdx; |
| 3223 |
uint8_t refFrameListIdx = m_avcPicParam[ppsIdx].RefFrameList[refPicListIdx].FrameIdx; |
| 3224 |
|
| 3225 |
bool dirtyRoiEnabled = (m_pictureCodingType == P_TYPE && m_avcPicParams[ppsIdx]->NumDirtyROI > 0 && m_prevReconFrameIdx == refFrameListIdx); |
| 3226 |
|
| 3227 |
if (m_mfeEnabled && m_numSlices > 1) |
| 3228 |
{ |
| 3229 |
m_arbitraryNumMbsInSlice = 1; |
| 3230 |
if (sliceCount == 0) |
| 3231 |
{ |
| 3232 |
m_sliceHeight = slcParams->NumMbsForSlice / m_picWidthInMb; |
| 3233 |
} |
| 3234 |
} |
| 3235 |
else if ((slcParams->NumMbsForSlice % m_picWidthInMb) || // If slice is partial MB row, |
| 3236 |
((sliceCount < m_numSlices - 1) && (numMbsInPrevSlice != slcParams->NumMbsForSlice)) || // OR not the last slice and num mbs is not same as prev slice |
| 3237 |
((sliceCount == m_numSlices - 1) && ((numMbsInPrevSlice < slcParams->NumMbsForSlice) || // OR it is the last slice and num mbs is not less than prev slice |
| 3238 |
(MEDIA_IS_WA(m_waTable, WaArbitraryNumMbsInSlice) && (m_numSlices > 16) && |
| 3239 |
(!m_vdencEnabled) && (!dirtyRoiEnabled))))) |
| 3240 |
{ |
| 3241 |
m_arbitraryNumMbsInSlice = 1; // then set flag to use sliceMapSurface |
| 3242 |
m_sliceHeight = 1; // Slice height doesn't matter if using slicemap just set to any non-zero value. |
| 3243 |
} |
| 3244 |
else if ((m_numSlices == 1) || (sliceCount == 0)) |
| 3245 |
{ |
| 3246 |
m_sliceHeight = slcParams->NumMbsForSlice / m_picWidthInMb; |
| 3247 |
m_arbitraryNumMbsInSlice = 0; |
| 3248 |
} |
| 3249 |
numMbsInPrevSlice = slcParams->NumMbsForSlice; |
| 3250 |
} |
| 3251 |
|
| 3252 |
if ((picParams->pic_init_qp_minus26 + 26 + slcParams->slice_qp_delta) > CODECHAL_ENCODE_AVC_MAX_SLICE_QP) |
| 3253 |
{ |
| 3254 |
slcParams->slice_qp_delta = CODECHAL_ENCODE_AVC_MAX_SLICE_QP - (picParams->pic_init_qp_minus26 + 26); |
| 3255 |
} |
| 3256 |
slcParams->redundant_pic_cnt = 0; |
| 3257 |
slcParams->sp_for_switch_flag = 0; |
| 3258 |
slcParams->slice_qs_delta = 0; |
| 3259 |
slcParams->redundant_pic_cnt = 0; |
| 3260 |
|
| 3261 |
slcParams->MaxFrameNum = |
| 3262 |
1 << (seqParams[picParams->seq_parameter_set_id].log2_max_frame_num_minus4 + 4); |
| 3263 |
slcParams->frame_num = m_frameNum; |
| 3264 |
slcParams->field_pic_flag = picParams->FieldCodingFlag; |
| 3265 |
slcParams->bottom_field_flag = |
| 3266 |
(CodecHal_PictureIsBottomField(picParams->CurrOriginalPic)) ? 1 : 0; |
| 3267 |
|
| 3268 |
if (m_pictureCodingType != I_TYPE) |
| 3269 |
{ |
| 3270 |
for (uint8_t i = 0; i < (slcParams->num_ref_idx_l0_active_minus1 + 1); i++) |
| 3271 |
{ |
| 3272 |
if (slcParams->RefPicList[0][i].FrameIdx >= CODEC_AVC_MAX_NUM_REF_FRAME) |
| 3273 |
{ |
| 3274 |
CODECHAL_ENCODE_ASSERTMESSAGE("Invalid slice parameters."); |
| 3275 |
return MOS_STATUS_INVALID_PARAMETER; |
| 3276 |
} |
| 3277 |
slcParams->PicOrder[0][i].Picture.FrameIdx = |
| 3278 |
m_picIdx[slcParams->RefPicList[0][i].FrameIdx].ucPicIdx; |
| 3279 |
slcParams->PicOrder[0][i].Picture.PicFlags = |
| 3280 |
slcParams->RefPicList[0][i].PicFlags; |
| 3281 |
} |
| 3282 |
} |
| 3283 |
if (m_pictureCodingType == B_TYPE) |
| 3284 |
{ |
| 3285 |
for (uint8_t i = 0; i < (slcParams->num_ref_idx_l1_active_minus1 + 1); i++) |
| 3286 |
{ |
| 3287 |
if (slcParams->RefPicList[1][i].FrameIdx >= CODEC_AVC_MAX_NUM_REF_FRAME) |
| 3288 |
{ |
| 3289 |
CODECHAL_ENCODE_ASSERTMESSAGE("Invalid slice parameters."); |
| 3290 |
return MOS_STATUS_INVALID_PARAMETER; |
| 3291 |
} |
| 3292 |
slcParams->PicOrder[1][i].Picture.FrameIdx = |
| 3293 |
m_picIdx[slcParams->RefPicList[1][i].FrameIdx].ucPicIdx; |
| 3294 |
slcParams->PicOrder[1][i].Picture.PicFlags = |
| 3295 |
slcParams->RefPicList[1][i].PicFlags; |
| 3296 |
} |
| 3297 |
} |
| 3298 |
slcParams++; |
| 3299 |
} |
| 3300 |
|
| 3301 |
if (eStatus == MOS_STATUS_INVALID_PARAMETER) |
| 3302 |
{ |
| 3303 |
CODECHAL_ENCODE_ASSERTMESSAGE("Invalid slice parameters."); |
| 3304 |
} |
| 3305 |
return eStatus; |
| 3306 |
} |
| 3307 |
|
| 3308 |
void CodechalEncodeAvcBase::SetMfxPipeModeSelectParams( |
| 3309 |
const CODECHAL_ENCODE_AVC_GENERIC_PICTURE_LEVEL_PARAMS &genericParam, |
| 3310 |
MHW_VDBOX_PIPE_MODE_SELECT_PARAMS & param) |
| 3311 |
{ |
| 3312 |
// set MFX_PIPE_MODE_SELECT values |
| 3313 |
param = {}; |
| 3314 |
param.Mode = m_mode; |
| 3315 |
param.bStreamOutEnabled = (m_currPass != m_numPasses); // Disable Stream Out for final pass; its important for multiple passes, because , next pass will take the qp from stream out |
| 3316 |
param.bVdencEnabled = m_vdencEnabled; |
| 3317 |
param.bDeblockerStreamOutEnable = genericParam.bDeblockerStreamOutEnable; |
| 3318 |
param.bStreamOutEnabledExtEnabled = genericParam.bPerMBStreamOutEnable; |
| 3319 |
param.bPostDeblockOutEnable = genericParam.bPostDeblockOutEnable; |
| 3320 |
param.bPreDeblockOutEnable = genericParam.bPreDeblockOutEnable; |
| 3321 |
param.bDynamicSliceEnable = m_avcSeqParam->EnableSliceLevelRateCtrl; |
| 3322 |
param.bVdencStreamInEnable = m_vdencStreamInEnabled; |
| 3323 |
param.bTlbPrefetchEnable = m_tlbPrefetchEnable; |
| 3324 |
param.ChromaType = m_avcSeqParam->chroma_format_idc; |
| 3325 |
param.Format = m_rawSurfaceToPak->Format; |
| 3326 |
} |
| 3327 |
|
| 3328 |
MOS_STATUS CodechalEncodeAvcBase::SetMfxPipeBufAddrStateParams( |
| 3329 |
CODECHAL_ENCODE_AVC_GENERIC_PICTURE_LEVEL_PARAMS genericParam, |
| 3330 |
MHW_VDBOX_PIPE_BUF_ADDR_PARAMS & param) |
| 3331 |
{ |
| 3332 |
MOS_STATUS eStatus = MOS_STATUS_SUCCESS; |
| 3333 |
|
| 3334 |
param.Mode = m_mode; |
| 3335 |
param.psPreDeblockSurface = genericParam.psPreDeblockSurface; |
| 3336 |
param.psPostDeblockSurface = genericParam.psPostDeblockSurface; |
| 3337 |
|
| 3338 |
param.psRawSurface = m_rawSurfaceToPak; |
| 3339 |
param.presStreamOutBuffer = &m_resStreamOutBuffer[m_currRecycledBufIdx]; |
| 3340 |
param.presMfdDeblockingFilterRowStoreScratchBuffer = &m_resDeblockingFilterRowStoreScratchBuffer; |
| 3341 |
param.presMfdIntraRowStoreScratchBuffer = &m_intraRowStoreScratchBuffer; |
| 3342 |
param.bVdencEnabled = m_vdencEnabled; |
| 3343 |
param.presMacroblockIldbStreamOutBuffer1 = genericParam.presMacroblockIldbStreamOutBuffer1; |
| 3344 |
param.presMacroblockIldbStreamOutBuffer2 = genericParam.presMacroblockIldbStreamOutBuffer2; |
| 3345 |
|
| 3346 |
CODECHAL_DEBUG_TOOL( |
| 3347 |
// PAK Input Raw Surface |
| 3348 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(m_debugInterface->DumpYUVSurface( |
| 3349 |
m_rawSurfaceToPak, |
| 3350 |
CodechalDbgAttr::attrEncodeRawInputSurface, |
| 3351 |
"PAK_Input_SrcSurf"));); |
| 3352 |
|
| 3353 |
auto firstValidFrame = &m_reconSurface.OsResource; |
| 3354 |
|
| 3355 |
// Setting invalid entries to nullptr |
| 3356 |
for (uint8_t i = 0; i < CODEC_AVC_MAX_NUM_REF_FRAME; i++) |
| 3357 |
param.presReferences[i] = nullptr; |
| 3358 |
|
| 3359 |
uint8_t firstValidFrameId = CODEC_AVC_MAX_NUM_REF_FRAME; |
| 3360 |
uint8_t numrefL0 = m_avcSliceParams->num_ref_idx_l0_active_minus1 + 1; |
| 3361 |
uint8_t numrefL1 = m_avcSliceParams->num_ref_idx_l1_active_minus1 + 1; |
| 3362 |
|
| 3363 |
for (uint8_t i = 0; i < CODEC_AVC_MAX_NUM_REF_FRAME; i++) |
| 3364 |
{ |
| 3365 |
if (m_picIdx[i].bValid) |
| 3366 |
{ |
| 3367 |
auto picIdx = m_picIdx[i].ucPicIdx; |
| 3368 |
auto frameStoreId = m_refList[picIdx]->ucFrameId; |
| 3369 |
|
| 3370 |
CodecHalGetResourceInfo(m_osInterface, &(m_refList[picIdx]->sRefReconBuffer)); |
| 3371 |
param.presReferences[frameStoreId] = &(m_refList[picIdx]->sRefReconBuffer.OsResource); |
| 3372 |
|
| 3373 |
if (picIdx < firstValidFrameId) |
| 3374 |
{ |
| 3375 |
firstValidFrameId = picIdx; |
| 3376 |
firstValidFrame = param.presReferences[picIdx]; |
| 3377 |
} |
| 3378 |
|
| 3379 |
} |
| 3380 |
} |
| 3381 |
CODECHAL_DEBUG_TOOL( |
| 3382 |
MOS_SURFACE refSurface; |
| 3383 |
for (uint8_t i = 0; i < numrefL0; i++) |
| 3384 |
{ |
| 3385 |
if (m_pictureCodingType != I_TYPE && m_avcSliceParams->RefPicList[0][i].PicFlags != PICTURE_INVALID) |
| 3386 |
{ |
| 3387 |
auto refPic = m_avcSliceParams->RefPicList[0][i]; |
| 3388 |
auto picIdx = m_picIdx[refPic.FrameIdx].ucPicIdx; |
| 3389 |
auto frameStoreId = m_refList[picIdx]->ucFrameId; |
| 3390 |
CODECHAL_ENCODE_CHK_NULL_RETURN(m_debugInterface); |
| 3391 |
|
| 3392 |
MOS_ZeroMemory(&refSurface, sizeof(refSurface)); |
| 3393 |
refSurface.Format = Format_NV12; |
| 3394 |
refSurface.OsResource = *(param.presReferences[frameStoreId]); |
| 3395 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(CodecHalGetResourceInfo( |
| 3396 |
m_osInterface, |
| 3397 |
&refSurface)); |
| 3398 |
m_debugInterface->m_refIndex = frameStoreId; |
| 3399 |
std::string refSurfName = "RefSurfL0[" + std::to_string(static_cast<uint32_t>(i)) + "]"; |
| 3400 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(m_debugInterface->DumpYUVSurface( |
| 3401 |
&refSurface, |
| 3402 |
CodechalDbgAttr::attrReferenceSurfaces, |
| 3403 |
refSurfName.c_str())); |
| 3404 |
} |
| 3405 |
} |
| 3406 |
for (uint8_t i = 0; i < numrefL1; i++) |
| 3407 |
{ |
| 3408 |
if (m_pictureCodingType == B_TYPE && m_avcSliceParams->RefPicList[1][i].PicFlags != PICTURE_INVALID) |
| 3409 |
{ |
| 3410 |
auto refPic = m_avcSliceParams->RefPicList[1][i]; |
| 3411 |
auto picIdx = m_picIdx[refPic.FrameIdx].ucPicIdx; |
| 3412 |
auto frameStoreId = m_refList[picIdx]->ucFrameId; |
| 3413 |
CODECHAL_ENCODE_CHK_NULL_RETURN(m_debugInterface); |
| 3414 |
//MOS_SURFACE refSurface; |
| 3415 |
MOS_ZeroMemory(&refSurface, sizeof(refSurface)); |
| 3416 |
refSurface.Format = Format_NV12; |
| 3417 |
refSurface.OsResource = *(param.presReferences[frameStoreId]); |
| 3418 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(CodecHalGetResourceInfo( |
| 3419 |
m_osInterface, |
| 3420 |
&refSurface)); |
| 3421 |
m_debugInterface->m_refIndex = frameStoreId; |
| 3422 |
std::string refSurfName = "RefSurfL1[" + std::to_string(static_cast<uint32_t>(i)) + "]"; |
| 3423 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(m_debugInterface->DumpYUVSurface( |
| 3424 |
&refSurface, |
| 3425 |
CodechalDbgAttr::attrReferenceSurfaces, |
| 3426 |
refSurfName.c_str())); |
| 3427 |
} |
| 3428 |
} |
| 3429 |
|
| 3430 |
); |
| 3431 |
|
| 3432 |
for (uint8_t i = 0; i < CODEC_AVC_MAX_NUM_REF_FRAME; i++) |
| 3433 |
{ |
| 3434 |
// error concealment for the unset reference addresses |
| 3435 |
if (!param.presReferences[i]) |
| 3436 |
{ |
| 3437 |
param.presReferences[i] = firstValidFrame; |
| 3438 |
} |
| 3439 |
} |
| 3440 |
|
| 3441 |
if (m_sliceSizeStreamoutSupported) |
| 3442 |
{ |
| 3443 |
param.presSliceSizeStreamOutBuffer = &m_pakSliceSizeStreamoutBuffer; |
| 3444 |
} |
| 3445 |
return eStatus; |
| 3446 |
} |
| 3447 |
|
| 3448 |
void CodechalEncodeAvcBase::SetMfxIndObjBaseAddrStateParams(MHW_VDBOX_IND_OBJ_BASE_ADDR_PARAMS ¶m) |
| 3449 |
{ |
| 3450 |
MOS_ZeroMemory(¶m, sizeof(param)); |
| 3451 |
param.Mode = CODECHAL_ENCODE_MODE_AVC; |
| 3452 |
param.presPakBaseObjectBuffer = &m_resBitstreamBuffer; |
| 3453 |
param.dwPakBaseObjectSize = m_bitstreamUpperBound; |
| 3454 |
} |
| 3455 |
|
| 3456 |
void CodechalEncodeAvcBase::SetMfxBspBufBaseAddrStateParams(MHW_VDBOX_BSP_BUF_BASE_ADDR_PARAMS ¶m) |
| 3457 |
{ |
| 3458 |
MOS_ZeroMemory(¶m, sizeof(param)); |
| 3459 |
param.presBsdMpcRowStoreScratchBuffer = &m_resMPCRowStoreScratchBuffer; |
| 3460 |
} |
| 3461 |
|
| 3462 |
void CodechalEncodeAvcBase::SetMfxQmStateParams(MHW_VDBOX_QM_PARAMS &qmParams, MHW_VDBOX_QM_PARAMS &fqmParams) |
| 3463 |
{ |
| 3464 |
MOS_ZeroMemory(&qmParams, sizeof(qmParams)); |
| 3465 |
MOS_ZeroMemory(&fqmParams, sizeof(fqmParams)); |
| 3466 |
|
| 3467 |
qmParams.Standard = CODECHAL_AVC; |
| 3468 |
qmParams.pAvcIqMatrix = (PMHW_VDBOX_AVC_QM_PARAMS)m_avcIQWeightScaleLists; |
| 3469 |
|
| 3470 |
fqmParams.Standard = CODECHAL_AVC; |
| 3471 |
fqmParams.pAvcIqMatrix = (PMHW_VDBOX_AVC_QM_PARAMS)m_avcIQWeightScaleLists; |
| 3472 |
} |
| 3473 |
|
| 3474 |
void CodechalEncodeAvcBase::SetMfxAvcImgStateParams(MHW_VDBOX_AVC_IMG_PARAMS ¶m) |
| 3475 |
{ |
| 3476 |
param = {}; |
| 3477 |
param.currPass = m_currPass; |
| 3478 |
param.pEncodeAvcPicParams = m_avcPicParam; |
| 3479 |
param.pEncodeAvcSeqParams = m_avcSeqParam; |
| 3480 |
param.pEncodeAvcSliceParams = m_avcSliceParams; |
| 3481 |
param.wPicWidthInMb = m_picWidthInMb; |
| 3482 |
param.wPicHeightInMb = m_picHeightInMb; |
| 3483 |
param.ppRefList = &(m_refList[0]); |
| 3484 |
param.pPicIdx = &(m_picIdx[0]); |
| 3485 |
param.dwTqEnabled = m_trellisQuantParams.dwTqEnabled; |
| 3486 |
param.dwTqRounding = m_trellisQuantParams.dwTqRounding; |
| 3487 |
param.ucKernelMode = m_kernelMode; |
| 3488 |
param.wSlcHeightInMb = m_sliceHeight; |
| 3489 |
param.dwMaxVmvR = CodecHalAvcEncode_GetMaxVmvR(m_avcSeqParam->Level); |
| 3490 |
param.bVdencStreamInEnabled = m_vdencStreamInEnabled; |
| 3491 |
param.bSliceSizeStreamOutEnabled = m_sliceSizeStreamoutSupported; |
| 3492 |
param.bCrePrefetchEnable = m_crePrefetchEnable; |
| 3493 |
|
| 3494 |
if (m_currPass && (m_currPass == m_numPasses) && (!m_vdencBrcEnabled)) |
| 3495 |
{ |
| 3496 |
// Enable IPCM pass, excluding VDENC BRC case |
| 3497 |
param.bIPCMPass = true; |
| 3498 |
} |
| 3499 |
} |
| 3500 |
|
| 3501 |
void CodechalEncodeAvcBase::UpdateSSDSliceCount() |
| 3502 |
{ |
| 3503 |
m_setRequestedEUSlices = ((m_frameHeight * m_frameWidth) >= m_ssdResolutionThreshold && |
| 3504 |
m_targetUsage <= m_ssdTargetUsageThreshold) |
| 3505 |
? true |
| 3506 |
: false; |
| 3507 |
|
| 3508 |
m_hwInterface->m_numRequestedEuSlices = (m_setRequestedEUSlices) ? m_sliceShutdownRequestState : m_sliceShutdownDefaultState; |
| 3509 |
} |
| 3510 |
|
| 3511 |
MOS_STATUS CodechalEncodeAvcBase::AddIshSize(uint32_t kuid, uint8_t *kernelBase) |
| 3512 |
{ |
| 3513 |
uint8_t *kernelBinary; |
| 3514 |
uint32_t kernelSize; |
| 3515 |
|
| 3516 |
MOS_STATUS status = CodecHalGetKernelBinaryAndSize(kernelBase, kuid, &kernelBinary, &kernelSize); |
| 3517 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(status); |
| 3518 |
m_hwInterface->GetStateHeapSettings()->dwIshSize += MOS_ALIGN_CEIL(kernelSize, (1 << MHW_KERNEL_OFFSET_SHIFT)); |
| 3519 |
return status; |
| 3520 |
} |
| 3521 |
|
| 3522 |
MOS_STATUS CodechalEncodeAvcBase::StoreNumPasses( |
| 3523 |
EncodeStatusBuffer *encodeStatusBuf, |
| 3524 |
MhwMiInterface * miInterface, |
| 3525 |
PMOS_COMMAND_BUFFER cmdBuffer, |
| 3526 |
uint32_t currPass) |
| 3527 |
{ |
| 3528 |
MHW_MI_STORE_DATA_PARAMS storeDataParams; |
| 3529 |
uint32_t offset; |
| 3530 |
MOS_STATUS eStatus = MOS_STATUS_SUCCESS; |
| 3531 |
|
| 3532 |
CODECHAL_ENCODE_FUNCTION_ENTER; |
| 3533 |
|
| 3534 |
CODECHAL_ENCODE_CHK_NULL_RETURN(encodeStatusBuf); |
| 3535 |
CODECHAL_ENCODE_CHK_NULL_RETURN(miInterface); |
| 3536 |
CODECHAL_ENCODE_CHK_NULL_RETURN(cmdBuffer); |
| 3537 |
|
| 3538 |
offset = |
| 3539 |
(encodeStatusBuf->wCurrIndex * encodeStatusBuf->dwReportSize) + |
| 3540 |
encodeStatusBuf->dwNumPassesOffset + // Num passes offset |
| 3541 |
sizeof(uint32_t) * 2; // pEncodeStatus is offset by 2 DWs in the resource |
| 3542 |
|
| 3543 |
storeDataParams.pOsResource = &encodeStatusBuf->resStatusBuffer; |
| 3544 |
storeDataParams.dwResourceOffset = offset; |
| 3545 |
storeDataParams.dwValue = currPass + 1; |
| 3546 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(miInterface->AddMiStoreDataImmCmd(cmdBuffer, &storeDataParams)); |
| 3547 |
|
| 3548 |
return MOS_STATUS_SUCCESS; |
| 3549 |
} |
| 3550 |
|
| 3551 |
void CodechalEncodeAvcBase::fill_pad_with_value(PMOS_SURFACE psSurface, uint32_t real_height, uint32_t aligned_height) |
| 3552 |
{ |
| 3553 |
CODECHAL_ENCODE_CHK_NULL_NO_STATUS_RETURN(psSurface); |
| 3554 |
|
| 3555 |
// unaligned surfaces only |
| 3556 |
if (aligned_height <= real_height || aligned_height > psSurface->dwHeight) |
| 3557 |
{ |
| 3558 |
return; |
| 3559 |
} |
| 3560 |
|
| 3561 |
if (psSurface->OsResource.TileType == MOS_TILE_INVALID) |
| 3562 |
{ |
| 3563 |
return; |
| 3564 |
} |
| 3565 |
|
| 3566 |
if (psSurface->Format == Format_NV12 || psSurface->Format == Format_P010) |
| 3567 |
{ |
| 3568 |
uint32_t pitch = psSurface->dwPitch; |
| 3569 |
uint32_t UVPlaneOffset = psSurface->UPlaneOffset.iSurfaceOffset; |
| 3570 |
uint32_t YPlaneOffset = psSurface->dwOffset; |
| 3571 |
uint32_t pad_rows = aligned_height - real_height; |
| 3572 |
uint32_t y_plane_size = pitch * real_height; |
| 3573 |
uint32_t uv_plane_size = pitch * real_height / 2; |
| 3574 |
|
| 3575 |
MOS_LOCK_PARAMS lockFlags; |
| 3576 |
MOS_ZeroMemory(&lockFlags, sizeof(MOS_LOCK_PARAMS)); |
| 3577 |
lockFlags.WriteOnly = 1; |
| 3578 |
|
| 3579 |
// padding for the linear format buffer. |
| 3580 |
if (psSurface->OsResource.TileType == MOS_TILE_LINEAR) |
| 3581 |
{ |
| 3582 |
uint8_t *src_data = (uint8_t *)m_osInterface->pfnLockResource(m_osInterface, &(psSurface->OsResource), &lockFlags); |
| 3583 |
CODECHAL_ENCODE_CHK_NULL_NO_STATUS_RETURN(src_data); |
| 3584 |
|
| 3585 |
uint8_t *src_data_y = src_data + YPlaneOffset; |
| 3586 |
uint8_t *src_data_y_end = src_data_y + y_plane_size; |
| 3587 |
for (uint32_t i = 0; i < pad_rows; i++) |
| 3588 |
{ |
| 3589 |
MOS_SecureMemcpy(src_data_y_end + i * pitch, pitch, src_data_y_end - pitch, pitch); |
| 3590 |
} |
| 3591 |
|
| 3592 |
uint8_t *src_data_uv = src_data + UVPlaneOffset; |
| 3593 |
uint8_t *src_data_uv_end = src_data_uv + uv_plane_size; |
| 3594 |
for (uint32_t i = 0; i < pad_rows / 2; i++) |
| 3595 |
{ |
| 3596 |
MOS_SecureMemcpy(src_data_uv_end + i * pitch, pitch, src_data_uv_end - pitch, pitch); |
| 3597 |
} |
| 3598 |
|
| 3599 |
m_osInterface->pfnUnlockResource(m_osInterface, &(psSurface->OsResource)); |
| 3600 |
} |
| 3601 |
else |
| 3602 |
{ |
| 3603 |
// we don't copy out the whole tiled buffer to linear and padding on the tiled buffer directly. |
| 3604 |
lockFlags.TiledAsTiled = 1; |
| 3605 |
|
| 3606 |
uint8_t *src_data = (uint8_t *)m_osInterface->pfnLockResource(m_osInterface, &(psSurface->OsResource), &lockFlags); |
| 3607 |
CODECHAL_ENCODE_CHK_NULL_NO_STATUS_RETURN(src_data); |
| 3608 |
|
| 3609 |
uint8_t *padding_data = (uint8_t *)MOS_AllocMemory(pitch * pad_rows); |
| 3610 |
CODECHAL_ENCODE_CHK_NULL_NO_STATUS_RETURN(padding_data); |
| 3611 |
|
| 3612 |
// Copy last Y row data to linear padding data. |
| 3613 |
GMM_RES_COPY_BLT gmmResCopyBlt = {0}; |
| 3614 |
gmmResCopyBlt.Gpu.pData = src_data; |
| 3615 |
gmmResCopyBlt.Gpu.OffsetX = 0; |
| 3616 |
gmmResCopyBlt.Gpu.OffsetY = (YPlaneOffset + y_plane_size - pitch) / pitch; |
| 3617 |
gmmResCopyBlt.Sys.pData = padding_data; |
| 3618 |
gmmResCopyBlt.Sys.RowPitch = pitch; |
| 3619 |
gmmResCopyBlt.Sys.BufferSize = pitch * pad_rows; |
| 3620 |
gmmResCopyBlt.Sys.SlicePitch = pitch; |
| 3621 |
gmmResCopyBlt.Blt.Slices = 1; |
| 3622 |
gmmResCopyBlt.Blt.Upload = false; |
| 3623 |
gmmResCopyBlt.Blt.Width = psSurface->dwWidth; |
| 3624 |
gmmResCopyBlt.Blt.Height = 1; |
| 3625 |
psSurface->OsResource.pGmmResInfo->CpuBlt(&gmmResCopyBlt); |
| 3626 |
// Fill the remain padding lines with last Y row data. |
| 3627 |
for (uint32_t i = 1; i < pad_rows; i++) |
| 3628 |
{ |
| 3629 |
MOS_SecureMemcpy(padding_data + i * pitch, pitch, padding_data, pitch); |
| 3630 |
} |
| 3631 |
// Filling the padding for Y. |
| 3632 |
gmmResCopyBlt.Gpu.pData = src_data; |
| 3633 |
gmmResCopyBlt.Gpu.OffsetX = 0; |
| 3634 |
gmmResCopyBlt.Gpu.OffsetY = (YPlaneOffset + y_plane_size) / pitch; |
| 3635 |
gmmResCopyBlt.Sys.pData = padding_data; |
| 3636 |
gmmResCopyBlt.Sys.RowPitch = pitch; |
| 3637 |
gmmResCopyBlt.Sys.BufferSize = pitch * pad_rows; |
| 3638 |
gmmResCopyBlt.Sys.SlicePitch = pitch; |
| 3639 |
gmmResCopyBlt.Blt.Slices = 1; |
| 3640 |
gmmResCopyBlt.Blt.Upload = true; |
| 3641 |
gmmResCopyBlt.Blt.Width = psSurface->dwWidth; |
| 3642 |
gmmResCopyBlt.Blt.Height = pad_rows; |
| 3643 |
psSurface->OsResource.pGmmResInfo->CpuBlt(&gmmResCopyBlt); |
| 3644 |
|
| 3645 |
// Copy last UV row data to linear padding data. |
| 3646 |
gmmResCopyBlt.Gpu.pData = src_data; |
| 3647 |
gmmResCopyBlt.Gpu.OffsetX = 0; |
| 3648 |
gmmResCopyBlt.Gpu.OffsetY = (UVPlaneOffset + uv_plane_size - pitch) / pitch; |
| 3649 |
gmmResCopyBlt.Sys.pData = padding_data; |
| 3650 |
gmmResCopyBlt.Sys.RowPitch = pitch; |
| 3651 |
gmmResCopyBlt.Sys.BufferSize = pitch * pad_rows / 2; |
| 3652 |
gmmResCopyBlt.Sys.SlicePitch = pitch; |
| 3653 |
gmmResCopyBlt.Blt.Slices = 1; |
| 3654 |
gmmResCopyBlt.Blt.Upload = false; |
| 3655 |
gmmResCopyBlt.Blt.Width = psSurface->dwWidth; |
| 3656 |
gmmResCopyBlt.Blt.Height = 1; |
| 3657 |
psSurface->OsResource.pGmmResInfo->CpuBlt(&gmmResCopyBlt); |
| 3658 |
// Fill the remain padding lines with last UV row data. |
| 3659 |
for (uint32_t i = 1; i < pad_rows / 2; i++) |
| 3660 |
{ |
| 3661 |
MOS_SecureMemcpy(padding_data + i * pitch, pitch, padding_data, pitch); |
| 3662 |
} |
| 3663 |
// Filling the padding for UV. |
| 3664 |
gmmResCopyBlt.Gpu.pData = src_data; |
| 3665 |
gmmResCopyBlt.Gpu.OffsetX = 0; |
| 3666 |
gmmResCopyBlt.Gpu.OffsetY = (UVPlaneOffset + uv_plane_size) / pitch; |
| 3667 |
gmmResCopyBlt.Sys.pData = padding_data; |
| 3668 |
gmmResCopyBlt.Sys.RowPitch = pitch; |
| 3669 |
gmmResCopyBlt.Sys.BufferSize = pitch * pad_rows / 2; |
| 3670 |
gmmResCopyBlt.Sys.SlicePitch = pitch; |
| 3671 |
gmmResCopyBlt.Blt.Slices = 1; |
| 3672 |
gmmResCopyBlt.Blt.Upload = true; |
| 3673 |
gmmResCopyBlt.Blt.Width = psSurface->dwWidth; |
| 3674 |
gmmResCopyBlt.Blt.Height = pad_rows / 2; |
| 3675 |
psSurface->OsResource.pGmmResInfo->CpuBlt(&gmmResCopyBlt); |
| 3676 |
|
| 3677 |
MOS_FreeMemory(padding_data); |
| 3678 |
padding_data = nullptr; |
| 3679 |
m_osInterface->pfnUnlockResource(m_osInterface, &(psSurface->OsResource)); |
| 3680 |
} |
| 3681 |
} |
| 3682 |
} |
| 3683 |
|
| 3684 |
#if USE_CODECHAL_DEBUG_TOOL |
| 3685 |
static MOS_STATUS DumpEncodePicReorder( |
| 3686 |
std::ostringstream &oss, |
| 3687 |
uint32_t x, |
| 3688 |
uint32_t y, |
| 3689 |
CODEC_PIC_REORDER * picReorder) |
| 3690 |
{ |
| 3691 |
uint8_t botField; |
| 3692 |
|
| 3693 |
CODECHAL_DEBUG_CHK_NULL(picReorder); |
| 3694 |
|
| 3695 |
botField = CodecHal_PictureIsBottomField(picReorder->Picture) ? 1 : 0; |
| 3696 |
|
| 3697 |
oss << "# PicOrder[" << std::dec << +x << "][" << std::dec << +y << "] =" << std::endl; |
| 3698 |
oss << "# \tPicNum = " << std::dec << +picReorder->PicNum << std::endl; |
| 3699 |
oss << "# \tPOC = " << std::dec << +picReorder->POC << std::endl; |
| 3700 |
oss << "# \tReorderPicNumIDC = " << std::dec << +picReorder->ReorderPicNumIDC << std::endl; |
| 3701 |
oss << "# \tDiffPicNumMinus1 = " << std::dec << +picReorder->DiffPicNumMinus1 << std::endl; |
| 3702 |
oss << "# \tFrameIdx = " << std::dec << +picReorder->Picture.FrameIdx << std::endl; |
| 3703 |
oss << "# \tBotField = " << std::dec << +botField << std::endl; |
| 3704 |
|
| 3705 |
return MOS_STATUS_SUCCESS; |
| 3706 |
} |
| 3707 |
|
| 3708 |
MOS_STATUS CodechalEncodeAvcBase::DumpSeqParams( |
| 3709 |
PCODEC_AVC_ENCODE_SEQUENCE_PARAMS seqParams, |
| 3710 |
PCODEC_AVC_IQ_MATRIX_PARAMS matrixParams) |
| 3711 |
{ |
| 3712 |
CODECHAL_DEBUG_FUNCTION_ENTER; |
| 3713 |
|
| 3714 |
if (!m_debugInterface->DumpIsEnabled(CodechalDbgAttr::attrSeqParams)) |
| 3715 |
{ |
| 3716 |
return MOS_STATUS_SUCCESS; |
| 3717 |
} |
| 3718 |
|
| 3719 |
CODECHAL_DEBUG_CHK_NULL(seqParams); |
| 3720 |
|
| 3721 |
std::ostringstream oss; |
| 3722 |
oss.setf(std::ios::showbase | std::ios::uppercase); |
| 3723 |
|
| 3724 |
oss << "# DDI Parameters:" << std::endl; |
| 3725 |
oss << "FrameWidth = " << +seqParams->FrameWidth << std::endl; |
| 3726 |
oss << "FrameHeight = " << +seqParams->FrameHeight << std::endl; |
| 3727 |
oss << "Profile = " << +seqParams->Profile << std::endl; |
| 3728 |
oss << "Level = " << +seqParams->Level << std::endl; |
| 3729 |
oss << "GopPicSize = " << +seqParams->GopPicSize << std::endl; |
| 3730 |
oss << "GopRefDist = " << +seqParams->GopRefDist << std::endl; |
| 3731 |
oss << "GopOptFlag = " << +seqParams->GopOptFlag << std::endl; |
| 3732 |
oss << "TargetUsage = " << +seqParams->TargetUsage << std::endl; |
| 3733 |
oss << "RateControlMethod = " << +seqParams->RateControlMethod << std::endl; |
| 3734 |
oss << "TargetBitRate = " << +seqParams->TargetBitRate << std::endl; |
| 3735 |
oss << "MaxBitRate = " << +seqParams->MaxBitRate << std::endl; |
| 3736 |
oss << "MinBitRate = " << +seqParams->MinBitRate << std::endl; |
| 3737 |
oss << "FramesPer100Sec = " << +seqParams->FramesPer100Sec << std::endl; |
| 3738 |
oss << "InitVBVBufferFullnessInBit = " << +seqParams->InitVBVBufferFullnessInBit << std::endl; |
| 3739 |
oss << "VBVBufferSizeInBit = " << +seqParams->VBVBufferSizeInBit << std::endl; |
| 3740 |
oss << "NumRefFrames = " << +seqParams->NumRefFrames / 2 << std::endl; // this prints the value passed from DDI |
| 3741 |
oss << "# NumRefFrames (Actual Value in CodecHal is twice the value passed from DDI) = " |
| 3742 |
<< +seqParams->NumRefFrames << std::endl; // this prints the actual value in CodecHal seq param structure |
| 3743 |
oss << "seq_parameter_set_id = " << +seqParams->seq_parameter_set_id << std::endl; |
| 3744 |
oss << "chroma_format_idc = " << +seqParams->chroma_format_idc << std::endl; |
| 3745 |
oss << "bit_depth_luma_minus8 = " << +seqParams->bit_depth_luma_minus8 << std::endl; |
| 3746 |
oss << "bit_depth_chroma_minus8 = " << +seqParams->bit_depth_chroma_minus8 << std::endl; |
| 3747 |
oss << "log2_max_frame_num_minus4 = " << +seqParams->log2_max_frame_num_minus4 << std::endl; |
| 3748 |
oss << "pic_order_cnt_type = " << +seqParams->pic_order_cnt_type << std::endl; |
| 3749 |
oss << "log2_max_pic_order_cnt_lsb_minus4 = " << +seqParams->log2_max_pic_order_cnt_lsb_minus4 << std::endl; |
| 3750 |
oss << "num_ref_frames_in_pic_order_cnt_cycle = " << +seqParams->num_ref_frames_in_pic_order_cnt_cycle << std::endl; |
| 3751 |
oss << "offset_for_non_ref_pic = " << +seqParams->offset_for_non_ref_pic << std::endl; |
| 3752 |
oss << "offset_for_top_to_bottom_field = " << +seqParams->offset_for_top_to_bottom_field << std::endl; |
| 3753 |
|
| 3754 |
// Conditionally printed (only when pic_order_cnt_type = 1). Contains 256 elements. |
| 3755 |
if (seqParams->pic_order_cnt_type == 1) |
| 3756 |
{ |
| 3757 |
for (uint16_t i = 0; i < 256; ++i) |
| 3758 |
{ |
| 3759 |
oss << "offset_for_ref_frame[" << +i << "] = " << +seqParams->offset_for_ref_frame[i] << std::endl; |
| 3760 |
} |
| 3761 |
} |
| 3762 |
|
| 3763 |
oss << "frame_crop_left_offset = " << +seqParams->frame_crop_left_offset << std::endl; |
| 3764 |
oss << "frame_crop_right_offset = " << +seqParams->frame_crop_right_offset << std::endl; |
| 3765 |
oss << "frame_crop_top_offset = " << +seqParams->frame_crop_top_offset << std::endl; |
| 3766 |
oss << "frame_crop_bottom_offset = " << +seqParams->frame_crop_bottom_offset << std::endl; |
| 3767 |
oss << "seq_scaling_matrix_present_flag = " << +seqParams->seq_scaling_matrix_present_flag << std::endl; |
| 3768 |
oss << "seq_scaling_list_present_flag = " << +seqParams->seq_scaling_list_present_flag[0] << std::endl; |
| 3769 |
|
| 3770 |
// seq_scaling_list_present_flag with 12 elements (only 1 element acknowledged in DDI doc) |
| 3771 |
oss << "# seq_scaling_list_present_flag[1-11]:"; |
| 3772 |
for (uint8_t i = 1; i < 12; i++) |
| 3773 |
oss << +seqParams->seq_scaling_list_present_flag[i] << " "; |
| 3774 |
oss << std::endl; |
| 3775 |
|
| 3776 |
oss << "delta_pic_order_always_zero_flag = " << +seqParams->delta_pic_order_always_zero_flag << std::endl; |
| 3777 |
oss << "frame_mbs_only_flag = " << +seqParams->frame_mbs_only_flag << std::endl; |
| 3778 |
oss << "direct_8x8_inference_flag = " << +seqParams->direct_8x8_inference_flag << std::endl; |
| 3779 |
oss << "vui_parameters_present_flag = " << +seqParams->vui_parameters_present_flag << std::endl; |
| 3780 |
oss << "frame_cropping_flag = " << +seqParams->frame_cropping_flag << std::endl; |
| 3781 |
oss << "EnableSliceLevelRateCtrl = " << +seqParams->EnableSliceLevelRateCtrl << std::endl; |
| 3782 |
oss << "ICQQualityFactor = " << +seqParams->ICQQualityFactor << std::endl; |
| 3783 |
oss << "InputColorSpace = " << +seqParams->InputColorSpace << std::endl; |
| 3784 |
|
| 3785 |
// begining of union/struct |
| 3786 |
oss << "# bResetBRC = " << +seqParams->bResetBRC << std::endl; |
| 3787 |
oss << "# bNoAcceleratorSPSInsertion = " << +seqParams->bNoAcceleratorSPSInsertion << std::endl; |
| 3788 |
oss << "# GlobalSearch = " << +seqParams->GlobalSearch << std::endl; |
| 3789 |
oss << "# LocalSearch = " << +seqParams->LocalSearch << std::endl; |
| 3790 |
oss << "# EarlySkip = " << +seqParams->EarlySkip << std::endl; |
| 3791 |
oss << "# Trellis = " << +seqParams->Trellis << std::endl; |
| 3792 |
oss << "# MBBRC = " << +seqParams->MBBRC << std::endl; |
| 3793 |
oss << "# bTemporalScalability = " << +seqParams->bTemporalScalability << std::endl; |
| 3794 |
oss << "# ROIValueInDeltaQP = " << +seqParams->ROIValueInDeltaQP << std::endl; |
| 3795 |
oss << "# bAutoMaxPBFrameSizeForSceneChange = " << +seqParams->bAutoMaxPBFrameSizeForSceneChange << std::endl; |
| 3796 |
oss << "sFlags = " << +seqParams->sFlags << std::endl; |
| 3797 |
|
| 3798 |
// end of union/struct |
| 3799 |
oss << "UserMaxIFrameSize = " << +seqParams->UserMaxFrameSize << std::endl; |
| 3800 |
oss << "UserMaxPBFrameSize = " << +seqParams->UserMaxPBFrameSize << std::endl; |
| 3801 |
|
| 3802 |
// Parameters not defined in DDI (Any non-DDI parameters printed should be preceeded by #) |
| 3803 |
oss << "# Non-DDI Parameters:" << std::endl; |
| 3804 |
oss << "# constraint_set0_flag = " << std::hex << +seqParams->constraint_set0_flag << std::endl; |
| 3805 |
oss << "# constraint_set1_flag = " << std::hex << +seqParams->constraint_set1_flag << std::endl; |
| 3806 |
oss << "# constraint_set2_flag = " << std::hex << +seqParams->constraint_set2_flag << std::endl; |
| 3807 |
oss << "# constraint_set3_flag = " << std::hex << +seqParams->constraint_set3_flag << std::endl; |
| 3808 |
|
| 3809 |
oss << "# separate_colour_plane_flag = " << std::hex << +seqParams->separate_colour_plane_flag << std::endl; |
| 3810 |
oss << "# qpprime_y_zero_transform_bypass_flag = " << std::hex << +seqParams->qpprime_y_zero_transform_bypass_flag << std::endl; |
| 3811 |
oss << "# gaps_in_frame_num_value_allowed_flag = " << std::hex << +seqParams->gaps_in_frame_num_value_allowed_flag << std::endl; |
| 3812 |
oss << "# pic_width_in_mbs_minus1 = " << std::hex << +seqParams->pic_width_in_mbs_minus1 << std::endl; |
| 3813 |
oss << "# pic_height_in_map_units_minus1 = " << std::hex << +seqParams->pic_height_in_map_units_minus1 << std::endl; |
| 3814 |
oss << "# mb_adaptive_frame_field_flag = " << std::hex << +seqParams->mb_adaptive_frame_field_flag << std::endl; |
| 3815 |
|
| 3816 |
// Dump ScalingList4x4 (6 x 16) |
| 3817 |
for (uint8_t i = 0; i < 16; ++i) |
| 3818 |
{ |
| 3819 |
oss << "# ScalingList4x4[" << std::dec << +i * 6 << "-" << (+i * 6) + 5 << "][" << +i << "]"; |
| 3820 |
for (uint8_t j = 0; j < 6; j++) |
| 3821 |
oss << std::hex << +matrixParams->ScalingList4x4[j][i] << " "; |
| 3822 |
oss << std::endl; |
| 3823 |
} |
| 3824 |
|
| 3825 |
// ScalingList8x8 (2 x 64) |
| 3826 |
for (uint8_t i = 0; i < 64; ++i) |
| 3827 |
{ |
| 3828 |
oss << "# ScalingList8x8[0 / 1][ " << std::dec << +i << "] = "; |
| 3829 |
oss << +matrixParams->ScalingList8x8[0][i] << " / " << +matrixParams->ScalingList8x8[1][i]; |
| 3830 |
oss << std::endl; |
| 3831 |
} |
| 3832 |
|
| 3833 |
const char *fileName = m_debugInterface->CreateFileName( |
| 3834 |
"_DDIEnc", |
| 3835 |
CodechalDbgBufferType::bufSeqParams, |
| 3836 |
CodechalDbgExtType::txt); |
| 3837 |
|
| 3838 |
std::ofstream ofs(fileName, std::ios::out); |
| 3839 |
ofs << oss.str(); |
| 3840 |
ofs.close(); |
| 3841 |
|
| 3842 |
if (m_debugInterface->DumpIsEnabled(CodechalDbgAttr::attrDriverUltDump)) |
| 3843 |
{ |
| 3844 |
if (!m_debugInterface->m_ddiFileName.empty()) |
| 3845 |
{ |
| 3846 |
std::ofstream ofs(m_debugInterface->m_ddiFileName, std::ios::app); |
| 3847 |
ofs << "SeqParamFile" |
| 3848 |
<< " = \"" << m_debugInterface->m_fileName << "\"" << std::endl; |
| 3849 |
ofs.close(); |
| 3850 |
} |
| 3851 |
} |
| 3852 |
|
| 3853 |
return MOS_STATUS_SUCCESS; |
| 3854 |
} |
| 3855 |
|
| 3856 |
MOS_STATUS CodechalEncodeAvcBase::DumpPicParams( |
| 3857 |
PCODEC_AVC_ENCODE_PIC_PARAMS picParams, |
| 3858 |
PCODEC_AVC_IQ_MATRIX_PARAMS matrixParams) |
| 3859 |
{ |
| 3860 |
CODECHAL_DEBUG_FUNCTION_ENTER; |
| 3861 |
|
| 3862 |
if (!m_debugInterface->DumpIsEnabled(CodechalDbgAttr::attrPicParams)) |
| 3863 |
{ |
| 3864 |
return MOS_STATUS_SUCCESS; |
| 3865 |
} |
| 3866 |
|
| 3867 |
CODECHAL_DEBUG_CHK_NULL(picParams); |
| 3868 |
|
| 3869 |
std::ostringstream oss; |
| 3870 |
oss.setf(std::ios::showbase | std::ios::uppercase); |
| 3871 |
|
| 3872 |
oss << "# DDI Parameters:" << std::endl; |
| 3873 |
oss << "TargetFrameSize = " << +picParams->TargetFrameSize << std::endl; |
| 3874 |
oss << "CurrOriginalPic = " << +picParams->CurrOriginalPic.PicEntry << std::endl; |
| 3875 |
oss << "CurrReconstructedPic = " << +picParams->CurrReconstructedPic.PicEntry << std::endl; |
| 3876 |
oss << "CodingType = " << +picParams->CodingType << std::endl; |
| 3877 |
oss << "FieldCodingFlag = " << +picParams->FieldCodingFlag << std::endl; |
| 3878 |
oss << "FieldFrameCodingFlag = " << +picParams->FieldFrameCodingFlag << std::endl; |
| 3879 |
oss << "NumSlice = " << +picParams->NumSlice << std::endl; |
| 3880 |
oss << "QpY = " << +picParams->QpY << std::endl; |
| 3881 |
|
| 3882 |
for (uint8_t i = 0; i < 16; ++i) |
| 3883 |
{ |
| 3884 |
oss << "RefFrameList[" << +i << "] = " << +picParams->RefFrameList[i].PicEntry << std::endl; |
| 3885 |
} |
| 3886 |
|
| 3887 |
oss << "UsedForReferenceFlags = " << +picParams->UsedForReferenceFlags << std::endl; |
| 3888 |
oss << "CurrFieldOrderCnt[0] = " << +picParams->CurrFieldOrderCnt[0] << std::endl; |
| 3889 |
oss << "CurrFieldOrderCnt[1] = " << +picParams->CurrFieldOrderCnt[1] << std::endl; |
| 3890 |
|
| 3891 |
for (uint8_t i = 0; i < 16; ++i) |
| 3892 |
{ |
| 3893 |
for (uint8_t j = 0; j < 2; ++j) |
| 3894 |
{ |
| 3895 |
oss << "FieldOrderCntList[" << +i << "]" |
| 3896 |
<< "[" << +j << "] = " << +picParams->FieldOrderCntList[i][j] << std::endl; |
| 3897 |
} |
| 3898 |
} |
| 3899 |
|
| 3900 |
oss << "frame_num = " << +picParams->frame_num << std::endl; |
| 3901 |
oss << "bLastPicInSeq = " << +picParams->bLastPicInSeq << std::endl; |
| 3902 |
oss << "bLastPicInStream = " << +picParams->bLastPicInStream << std::endl; |
| 3903 |
|
| 3904 |
// User Flags parameters |
| 3905 |
oss << "# bUseRawPicForRef = " << +picParams->UserFlags.bUseRawPicForRef << std::endl; |
| 3906 |
oss << "# bDisableAcceleratorHeaderPacking = " << +picParams->UserFlags.bDisableAcceleratorHeaderPacking << std::endl; |
| 3907 |
oss << "# bDisableSubMBPartition = " << +picParams->UserFlags.bDisableSubMBPartition << std::endl; |
| 3908 |
oss << "# bEmulationByteInsertion = " << +picParams->UserFlags.bEmulationByteInsertion << std::endl; |
| 3909 |
oss << "# bEnableRollingIntraRefresh = " << +picParams->UserFlags.bEnableRollingIntraRefresh << std::endl; |
| 3910 |
oss << "ForceRepartitionCheck = " << +picParams->UserFlags.ForceRepartitionCheck << std::endl; |
| 3911 |
oss << "UserFlags = " << +picParams->UserFlags.Value << std::endl; |
| 3912 |
oss << "StatusReportFeedbackNumber = " << +picParams->StatusReportFeedbackNumber << std::endl; |
| 3913 |
oss << "bIdrPic = " << +picParams->bIdrPic << std::endl; |
| 3914 |
oss << "pic_parameter_set_id = " << +picParams->pic_parameter_set_id << std::endl; |
| 3915 |
oss << "seq_parameter_set_id = " << +picParams->seq_parameter_set_id << std::endl; |
| 3916 |
oss << "num_ref_idx_l0_active_minus1 = " << +picParams->num_ref_idx_l0_active_minus1 << std::endl; |
| 3917 |
oss << "num_ref_idx_l1_active_minus1 = " << +picParams->num_ref_idx_l1_active_minus1 << std::endl; |
| 3918 |
oss << "chroma_qp_index_offset = " << +picParams->chroma_qp_index_offset << std::endl; |
| 3919 |
oss << "second_chroma_qp_index_offset = " << +picParams->second_chroma_qp_index_offset << std::endl; |
| 3920 |
oss << "entropy_coding_mode_flag = " << +picParams->entropy_coding_mode_flag << std::endl; |
| 3921 |
oss << "pic_order_present_flag = " << +picParams->pic_order_present_flag << std::endl; |
| 3922 |
oss << "weighted_pred_flag = " << +picParams->weighted_pred_flag << std::endl; |
| 3923 |
oss << "weighted_bipred_idc = " << +picParams->weighted_bipred_idc << std::endl; |
| 3924 |
oss << "constrained_intra_pred_flag = " << +picParams->constrained_intra_pred_flag << std::endl; |
| 3925 |
oss << "transform_8x8_mode_flag = " << +picParams->transform_8x8_mode_flag << std::endl; |
| 3926 |
oss << "pic_scaling_matrix_present_flag = " << +picParams->pic_scaling_matrix_present_flag << std::endl; |
| 3927 |
oss << "pic_scaling_list_present_flag = " << +picParams->pic_scaling_list_present_flag[0] << std::endl; |
| 3928 |
|
| 3929 |
// pic_scaling_list_present_flag buffer contains 12 elements (only 1 acknowledged DDI document) |
| 3930 |
oss << "# pic_scaling_list_present_flag[1-11]:"; |
| 3931 |
oss << +picParams->pic_scaling_list_present_flag[1] << " "; |
| 3932 |
oss << +picParams->pic_scaling_list_present_flag[2] << " "; |
| 3933 |
oss << +picParams->pic_scaling_list_present_flag[3] << " "; |
| 3934 |
oss << +picParams->pic_scaling_list_present_flag[4] << " "; |
| 3935 |
oss << +picParams->pic_scaling_list_present_flag[5] << " "; |
| 3936 |
oss << +picParams->pic_scaling_list_present_flag[6] << " "; |
| 3937 |
oss << +picParams->pic_scaling_list_present_flag[7] << " "; |
| 3938 |
oss << +picParams->pic_scaling_list_present_flag[8] << " "; |
| 3939 |
oss << +picParams->pic_scaling_list_present_flag[9] << " "; |
| 3940 |
oss << +picParams->pic_scaling_list_present_flag[10] << " "; |
| 3941 |
oss << +picParams->pic_scaling_list_present_flag[11] << std::endl; |
| 3942 |
|
| 3943 |
oss << "RefPicFlag = " << +picParams->RefPicFlag << std::endl; |
| 3944 |
oss << "BRCPrecision = " << +picParams->BRCPrecision << std::endl; |
| 3945 |
oss << "bDisplayFormatSwizzle = " << +picParams->bDisplayFormatSwizzle << std::endl; |
| 3946 |
oss << "IntraInsertionLocation = " << +picParams->IntraRefreshMBNum << std::endl; |
| 3947 |
oss << "IntraInsertionSize = " << +picParams->IntraRefreshUnitinMB << std::endl; |
| 3948 |
oss << "QpDeltaForInsertedIntra = " << +picParams->IntraRefreshQPDelta << std::endl; |
| 3949 |
oss << "SliceSizeInBytes = " << +picParams->SliceSizeInBytes << std::endl; |
| 3950 |
oss << "bDisableRollingIntraRefreshOverlap = " << +picParams->bDisableRollingIntraRefreshOverlap << std::endl; |
| 3951 |
oss << "NumROI = " << +picParams->NumROI << std::endl; |
| 3952 |
oss << "MinDeltaQp = " << +picParams->MinDeltaQp << std::endl; |
| 3953 |
oss << "MaxDeltaQp = " << +picParams->MaxDeltaQp << std::endl; |
| 3954 |
|
| 3955 |
// Dump ROI coordinates and PriorityLevelOrDQp |
| 3956 |
for (uint16_t i = 0; i < picParams->NumROI; ++i) |
| 3957 |
{ |
| 3958 |
oss << "ROI[" << +i << "] = ["; |
| 3959 |
oss << +picParams->ROI[i].Top << ","; |
| 3960 |
oss << +picParams->ROI[i].Bottom << ","; |
| 3961 |
oss << +picParams->ROI[i].Left << ","; |
| 3962 |
oss << +picParams->ROI[i].Right << "], "; |
| 3963 |
oss << "PriorityLevelOrDQp = " << +picParams->ROI[i].PriorityLevelOrDQp << std::endl; |
| 3964 |
} |
| 3965 |
|
| 3966 |
oss << "NumDirtyROI = " << +picParams->NumDirtyROI << std::endl; |
| 3967 |
|
| 3968 |
// Dump Dirty ROI coordinates and PriorityLevelOrDQp |
| 3969 |
for (uint16_t i = 0; i < picParams->NumDirtyROI; ++i) |
| 3970 |
{ |
| 3971 |
oss << "DirtyROI[" << +i << "] = ["; |
| 3972 |
oss << +picParams->DirtyROI[i].Top << ","; |
| 3973 |
oss << +picParams->DirtyROI[i].Bottom << ","; |
| 3974 |
oss << +picParams->DirtyROI[i].Left << ","; |
| 3975 |
oss << +picParams->DirtyROI[i].Right << "], "; |
| 3976 |
oss << "PriorityLevelOrDQp = " << +picParams->DirtyROI[i].PriorityLevelOrDQp << std::endl; |
| 3977 |
} |
| 3978 |
|
| 3979 |
oss << "SkipFrameFlag = " << +picParams->SkipFrameFlag << std::endl; |
| 3980 |
oss << "NumSkipFrames = " << +picParams->NumSkipFrames << std::endl; |
| 3981 |
oss << "SizeSkipFrames = " << +picParams->SizeSkipFrames << std::endl; |
| 3982 |
|
| 3983 |
// Dump Min/Max QP params |
| 3984 |
oss << "BRCMinQp = " << +picParams->ucMinimumQP << std::endl; |
| 3985 |
oss << "BRCMaxQp = " << +picParams->ucMaximumQP << std::endl; |
| 3986 |
|
| 3987 |
// Dump SFD threshold |
| 3988 |
oss << "dwZMvThreshold = " << +picParams->dwZMvThreshold << std::endl; |
| 3989 |
|
| 3990 |
// Dump HME offset |
| 3991 |
oss << "bEnableHMEOffset = " << +picParams->bEnableHMEOffset << std::endl; |
| 3992 |
|
| 3993 |
for (uint8_t i = 0; i < 16; ++i) |
| 3994 |
{ |
| 3995 |
for (uint8_t j = 0; j < 2; ++j) |
| 3996 |
{ |
| 3997 |
for (uint8_t k = 0; k < 2; ++k) |
| 3998 |
{ |
| 3999 |
oss << "HMEOffset[" << +i << "][" << +j << "][" << +k << "] = " << +picParams->HMEOffset[i][j][k] << std::endl; |
| 4000 |
} |
| 4001 |
} |
| 4002 |
} |
| 4003 |
|
| 4004 |
oss << "bDisableFrameSkip = " << +picParams->bDisableFrameSkip << std::endl; |
| 4005 |
oss << "bEnableSync = " << +picParams->bEnableSync << std::endl; |
| 4006 |
oss << "bRepeatFrame = " << +picParams->bRepeatFrame << std::endl; |
| 4007 |
oss << "bEnableQpAdjustment = " << +picParams->bEnableQpAdjustment << std::endl; |
| 4008 |
|
| 4009 |
oss << "NumDeltaQpForNonRectROI = " << +picParams->NumDeltaQpForNonRectROI << std::endl; |
| 4010 |
for (uint16_t i = 0; i < picParams->NumDeltaQpForNonRectROI; ++i) |
| 4011 |
{ |
| 4012 |
oss << "NonRectROIDeltaQpList[" << +i << "] = " << +picParams->NonRectROIDeltaQpList[i] << std::endl; |
| 4013 |
} |
| 4014 |
|
| 4015 |
oss << "SyncMarkerX = " << +picParams->SyncMarkerX << std::endl; |
| 4016 |
oss << "SyncMarkerY = " << +picParams->SyncMarkerY << std::endl; |
| 4017 |
oss << "SyncMarkerSize = " << +picParams->SyncMarkerSize << std::endl; |
| 4018 |
oss << "HierarchLevelPlus1 = " << +picParams->HierarchLevelPlus1 << std::endl; |
| 4019 |
oss << "QpModulationStrength = " << +picParams->QpModulationStrength << std::endl; |
| 4020 |
|
| 4021 |
// Parameters not defined in DDI (Any non-DDI parameters printed should be preceeded by #) |
| 4022 |
oss << "# Non-DDI Parameters:" << std::endl; |
| 4023 |
oss << "# num_slice_groups_minus1 = " << +picParams->num_slice_groups_minus1 << std::endl; |
| 4024 |
oss << "# pic_init_qp_minus26 = " << +picParams->pic_init_qp_minus26 << std::endl; |
| 4025 |
oss << "# pic_init_qs_minus26 = " << +picParams->pic_init_qs_minus26 << std::endl; |
| 4026 |
oss << "# deblocking_filter_control_present_flag = " << +picParams->deblocking_filter_control_present_flag << std::endl; |
| 4027 |
oss << "# redundant_pic_cnt_present_flag = " << +picParams->redundant_pic_cnt_present_flag << std::endl; |
| 4028 |
oss << "# EnableRollingIntraRefresh = " << +picParams->EnableRollingIntraRefresh << std::endl; |
| 4029 |
oss << "# IntraRefreshMBx = " << +picParams->IntraRefreshMBx << std::endl; |
| 4030 |
oss << "# IntraRefreshMBy = " << +picParams->IntraRefreshMBy << std::endl; |
| 4031 |
oss << "# IntraRefreshUnitinMB = " << +picParams->IntraRefreshUnitinMB << std::endl; |
| 4032 |
oss << "# IntraRefreshQPDelta = " << +picParams->IntraRefreshQPDelta << std::endl; |
| 4033 |
|
| 4034 |
// Dump ScalingList4x4 (6 x 16) |
| 4035 |
for (uint8_t i = 0; i < 16; ++i) |
| 4036 |
{ |
| 4037 |
oss << "# ScalingList4x4[" << +i << "] = "; |
| 4038 |
oss << +matrixParams->ScalingList4x4[0][i] << " "; |
| 4039 |
oss << +matrixParams->ScalingList4x4[1][i] << " "; |
| 4040 |
oss << +matrixParams->ScalingList4x4[2][i] << " "; |
| 4041 |
oss << +matrixParams->ScalingList4x4[3][i] << " "; |
| 4042 |
oss << +matrixParams->ScalingList4x4[4][i] << " "; |
| 4043 |
oss << +matrixParams->ScalingList4x4[5][i] << std::endl; |
| 4044 |
} |
| 4045 |
|
| 4046 |
// ScalingList8x8 (2 x 64) |
| 4047 |
for (uint8_t i = 0; i < 64; ++i) |
| 4048 |
{ |
| 4049 |
oss << "# ScalingList8x8[0/1][" << +i << "] = " << +matrixParams->ScalingList8x8[0][i] << " / " << +matrixParams->ScalingList8x8[1][i] << std::endl; |
| 4050 |
} |
| 4051 |
|
| 4052 |
const char *fileName = m_debugInterface->CreateFileName( |
| 4053 |
"_DDIEnc", |
| 4054 |
CodechalDbgBufferType::bufPicParams, |
| 4055 |
CodechalDbgExtType::txt); |
| 4056 |
|
| 4057 |
std::ofstream ofs(fileName, std::ios::out); |
| 4058 |
ofs << oss.str(); |
| 4059 |
ofs.close(); |
| 4060 |
|
| 4061 |
if (m_debugInterface->DumpIsEnabled(CodechalDbgAttr::attrDriverUltDump)) |
| 4062 |
{ |
| 4063 |
if (!m_debugInterface->m_ddiFileName.empty()) |
| 4064 |
{ |
| 4065 |
std::ofstream ofs(m_debugInterface->m_ddiFileName, std::ios::app); |
| 4066 |
ofs << "PicNum" |
| 4067 |
<< " = \"" << m_debugInterface->m_bufferDumpFrameNum << "\"" << std::endl; |
| 4068 |
ofs << "PicParamFile" |
| 4069 |
<< " = \"" << m_debugInterface->m_fileName << "\"" << std::endl; |
| 4070 |
ofs.close(); |
| 4071 |
} |
| 4072 |
} |
| 4073 |
|
| 4074 |
return MOS_STATUS_SUCCESS; |
| 4075 |
} |
| 4076 |
|
| 4077 |
|
| 4078 |
MOS_STATUS CodechalEncodeAvcBase::DumpFeiPicParams( |
| 4079 |
CodecEncodeAvcFeiPicParams *feiPicParams) |
| 4080 |
{ |
| 4081 |
CODECHAL_DEBUG_FUNCTION_ENTER; |
| 4082 |
|
| 4083 |
if (!m_debugInterface->DumpIsEnabled(CodechalDbgAttr::attrFeiPicParams)) |
| 4084 |
{ |
| 4085 |
return MOS_STATUS_SUCCESS; |
| 4086 |
} |
| 4087 |
|
| 4088 |
CODECHAL_DEBUG_CHK_NULL(feiPicParams); |
| 4089 |
|
| 4090 |
std::ostringstream oss; |
| 4091 |
oss.setf(std::ios::showbase | std::ios::uppercase); |
| 4092 |
|
| 4093 |
oss << "# DDI Parameters:" << std::endl; |
| 4094 |
oss << "SearchPath = " << +feiPicParams->SearchPath << std::endl; |
| 4095 |
oss << "LenSP = " << +feiPicParams->LenSP << std::endl; |
| 4096 |
oss << "SubMBPartMask = " << +feiPicParams->SubMBPartMask << std::endl; |
| 4097 |
oss << "IntraPartMask = " << +feiPicParams->IntraPartMask << std::endl; |
| 4098 |
oss << "MultiPredL0 = " << +feiPicParams->MultiPredL0 << std::endl; |
| 4099 |
oss << "MultiPredL1 = " << +feiPicParams->MultiPredL1 << std::endl; |
| 4100 |
oss << "SubPelMode = " << +feiPicParams->SubPelMode << std::endl; |
| 4101 |
oss << "InterSAD = " << +feiPicParams->InterSAD << std::endl; |
| 4102 |
oss << "IntraSAD = " << +feiPicParams->IntraSAD << std::endl; |
| 4103 |
oss << "NumMVPredictors = " << +feiPicParams->NumMVPredictorsL0 << std::endl; |
| 4104 |
oss << "NumMVPredictorsL1 = " << +feiPicParams->NumMVPredictorsL1 << std::endl; |
| 4105 |
oss << "DistortionType = " << +feiPicParams->DistortionType << std::endl; |
| 4106 |
oss << "DistortionEnable = " << +feiPicParams->DistortionEnable << std::endl; |
| 4107 |
oss << "RepartitionCheckEnable = " << +feiPicParams->RepartitionCheckEnable << std::endl; |
| 4108 |
oss << "AdaptiveSearch = " << +feiPicParams->AdaptiveSearch << std::endl; |
| 4109 |
oss << "MVPredictorEnable = " << +feiPicParams->MVPredictorEnable << std::endl; |
| 4110 |
oss << "bMBQp = " << +feiPicParams->bMBQp << std::endl; |
| 4111 |
oss << "bPerMBInput = " << +feiPicParams->bPerMBInput << std::endl; |
| 4112 |
oss << "bMBSizeCtrl = " << +feiPicParams->bMBSizeCtrl << std::endl; |
| 4113 |
oss << "RefWidth = " << +feiPicParams->RefWidth << std::endl; |
| 4114 |
oss << "RefHeight = " << +feiPicParams->RefHeight << std::endl; |
| 4115 |
oss << "SearchWindow = " << +feiPicParams->SearchWindow << std::endl; |
| 4116 |
|
| 4117 |
const char *fileName = m_debugInterface->CreateFileName( |
| 4118 |
"_DDIEnc", |
| 4119 |
CodechalDbgBufferType::bufFeiPicParams, |
| 4120 |
CodechalDbgExtType::txt); |
| 4121 |
|
| 4122 |
std::ofstream ofs(fileName, std::ios::out); |
| 4123 |
ofs << oss.str(); |
| 4124 |
ofs.close(); |
| 4125 |
|
| 4126 |
if (m_debugInterface->DumpIsEnabled(CodechalDbgAttr::attrDriverUltDump)) |
| 4127 |
{ |
| 4128 |
if (!m_debugInterface->m_ddiFileName.empty()) |
| 4129 |
{ |
| 4130 |
std::ofstream ofs(m_debugInterface->m_ddiFileName, std::ios::app); |
| 4131 |
ofs << "PicNum" |
| 4132 |
<< " = \"" << m_debugInterface->m_bufferDumpFrameNum << "\"" << std::endl; |
| 4133 |
ofs << "FeiPicParamFile" |
| 4134 |
<< " = \"" << m_debugInterface->m_fileName << "\"" << std::endl; |
| 4135 |
ofs.close(); |
| 4136 |
} |
| 4137 |
} |
| 4138 |
|
| 4139 |
return MOS_STATUS_SUCCESS; |
| 4140 |
} |
| 4141 |
|
| 4142 |
MOS_STATUS CodechalEncodeAvcBase::DumpSliceParams( |
| 4143 |
PCODEC_AVC_ENCODE_SLICE_PARAMS sliceParams, |
| 4144 |
PCODEC_AVC_ENCODE_PIC_PARAMS picParams) |
| 4145 |
{ |
| 4146 |
CODECHAL_DEBUG_FUNCTION_ENTER; |
| 4147 |
|
| 4148 |
if (!m_debugInterface->DumpIsEnabled(CodechalDbgAttr::attrSlcParams)) |
| 4149 |
{ |
| 4150 |
return MOS_STATUS_SUCCESS; |
| 4151 |
} |
| 4152 |
|
| 4153 |
CODECHAL_DEBUG_CHK_NULL(sliceParams); |
| 4154 |
|
| 4155 |
m_debugInterface->m_sliceId = sliceParams->slice_id; // set here for constructing debug file name |
| 4156 |
|
| 4157 |
std::ostringstream oss; |
| 4158 |
oss.setf(std::ios::showbase | std::ios::uppercase); |
| 4159 |
|
| 4160 |
oss << "# DDI Parameters:" << std::endl; |
| 4161 |
oss << "NumMbsForSlice = " << +sliceParams->NumMbsForSlice << std::endl; |
| 4162 |
|
| 4163 |
// RefPicList (2 x 32) |
| 4164 |
for (uint8_t i = 0; i < 2; ++i) |
| 4165 |
{ |
| 4166 |
for (uint8_t j = 0; j < 32; ++j) |
| 4167 |
{ |
| 4168 |
oss << "RefPicList[" << +i << "][" << +j << "] = " << +sliceParams->RefPicList[i][j].PicEntry << std::endl; |
| 4169 |
} |
| 4170 |
} |
| 4171 |
|
| 4172 |
// Conditionally printed (only when picture parameters weighted_pred_flag or weighted_bipred_idc are set). |
| 4173 |
// Weights contains 192 elements (2 x 32 x 3 x 2). |
| 4174 |
if (picParams->weighted_pred_flag || picParams->weighted_bipred_idc) |
| 4175 |
{ |
| 4176 |
for (uint8_t i = 0; i < 2; ++i) |
| 4177 |
{ |
| 4178 |
for (uint8_t j = 0; j < 32; ++j) |
| 4179 |
{ |
| 4180 |
for (uint8_t k = 0; k < 3; ++k) |
| 4181 |
{ |
| 4182 |
for (uint8_t l = 0; l < 2; ++l) |
| 4183 |
{ |
| 4184 |
oss << "Weights[" << +i << "][" << +j << "][" << +k << "][" << +l << "]: " << +sliceParams->Weights[i][j][k][l] << std::endl; |
| 4185 |
} |
| 4186 |
} |
| 4187 |
} |
| 4188 |
} |
| 4189 |
} |
| 4190 |
|
| 4191 |
oss << "first_mb_in_slice = " << +sliceParams->first_mb_in_slice << std::endl; |
| 4192 |
oss << "slice_type = " << +sliceParams->slice_type << std::endl; |
| 4193 |
oss << "pic_parameter_set_id = " << +sliceParams->pic_parameter_set_id << std::endl; |
| 4194 |
oss << "direct_spatial_mv_pred_flag = " << +sliceParams->direct_spatial_mv_pred_flag << std::endl; |
| 4195 |
oss << "num_ref_idx_active_override_flag = " << +sliceParams->num_ref_idx_active_override_flag << std::endl; |
| 4196 |
oss << "long_term_reference_flag = " << +sliceParams->long_term_reference_flag << std::endl; |
| 4197 |
oss << "idr_pic_id = " << +sliceParams->idr_pic_id << std::endl; |
| 4198 |
oss << "pic_order_cnt_lsb = " << +sliceParams->pic_order_cnt_lsb << std::endl; |
| 4199 |
oss << "delta_pic_order_cnt_bottom = " << +sliceParams->delta_pic_order_cnt_bottom << std::endl; |
| 4200 |
oss << "delta_pic_order_cnt[0] = " << +sliceParams->delta_pic_order_cnt[0] << std::endl; |
| 4201 |
oss << "delta_pic_order_cnt[1] = " << +sliceParams->delta_pic_order_cnt[1] << std::endl; |
| 4202 |
oss << "num_ref_idx_l0_active_minus1 = " << +sliceParams->num_ref_idx_l0_active_minus1 << std::endl; |
| 4203 |
oss << "num_ref_idx_l1_active_minus1 = " << +sliceParams->num_ref_idx_l1_active_minus1 << std::endl; |
| 4204 |
oss << "luma_log2_weight_denom = " << +sliceParams->luma_log2_weight_denom << std::endl; |
| 4205 |
oss << "chroma_log2_weight_denom = " << +sliceParams->chroma_log2_weight_denom << std::endl; |
| 4206 |
oss << "cabac_init_idc = " << +sliceParams->cabac_init_idc << std::endl; |
| 4207 |
oss << "slice_qp_delta = " << +sliceParams->slice_qp_delta << std::endl; |
| 4208 |
oss << "disable_deblocking_filter_idc = " << +sliceParams->disable_deblocking_filter_idc << std::endl; |
| 4209 |
oss << "slice_alpha_c0_offset_div2 = " << +sliceParams->slice_alpha_c0_offset_div2 << std::endl; |
| 4210 |
oss << "slice_beta_offset_div2 = " << +sliceParams->slice_beta_offset_div2 << std::endl; |
| 4211 |
oss << "slice_id = " << +sliceParams->slice_id << std::endl; |
| 4212 |
oss << "luma_weight_flag[0] = " << +sliceParams->luma_weight_flag[0] << std::endl; |
| 4213 |
oss << "luma_weight_flag[1] = " << +sliceParams->luma_weight_flag[1] << std::endl; |
| 4214 |
oss << "chroma_weight_flag[0] = " << +sliceParams->chroma_weight_flag[0] << std::endl; |
| 4215 |
oss << "chroma_weight_flag[1] = " << +sliceParams->chroma_weight_flag[1] << std::endl; |
| 4216 |
|
| 4217 |
// Parameters not in DDI (Any non-DDI parameters printed should be preceeded by #) |
| 4218 |
oss << "# Non-DDI Parameters:" << std::endl; |
| 4219 |
|
| 4220 |
// PicOrder (2 x 32) - Dump in 32 blocks of 2 chunks per line |
| 4221 |
for (uint16_t i = 0; i < 32; ++i) |
| 4222 |
{ |
| 4223 |
CODECHAL_DEBUG_CHK_STATUS(DumpEncodePicReorder( |
| 4224 |
oss, |
| 4225 |
0, |
| 4226 |
i, |
| 4227 |
&(sliceParams->PicOrder[0][i]))); |
| 4228 |
CODECHAL_DEBUG_CHK_STATUS(DumpEncodePicReorder( |
| 4229 |
oss, |
| 4230 |
1, |
| 4231 |
i, |
| 4232 |
&(sliceParams->PicOrder[1][i]))); |
| 4233 |
} |
| 4234 |
|
| 4235 |
oss << "# colour_plane_id = " << +sliceParams->colour_plane_id << std::endl; |
| 4236 |
oss << "# frame_num = " << +sliceParams->frame_num << std::endl; |
| 4237 |
oss << "# field_pic_flag = " << std::hex << +sliceParams->field_pic_flag << std::endl; |
| 4238 |
oss << "# bottom_field_flag = " << std::hex << +sliceParams->bottom_field_flag << std::endl; |
| 4239 |
oss << "# redundant_pic_cnt = " << std::dec << +sliceParams->redundant_pic_cnt << std::endl; |
| 4240 |
oss << "# sp_for_switch_flag = " << std::hex << +sliceParams->sp_for_switch_flag << std::endl; |
| 4241 |
oss << "# slice_qs_delta = " << std::dec << +sliceParams->slice_qs_delta << std::endl; |
| 4242 |
oss << "# ref_pic_list_reordering_flag_l0 = " << std::hex << +sliceParams->ref_pic_list_reordering_flag_l0 << std::endl; |
| 4243 |
oss << "# ref_pic_list_reordering_flag_l1 = " << std::hex << +sliceParams->ref_pic_list_reordering_flag_l1 << std::endl; |
| 4244 |
oss << "# no_output_of_prior_pics_flag = " << std::hex << +sliceParams->no_output_of_prior_pics_flag << std::endl; |
| 4245 |
oss << "# adaptive_ref_pic_marking_mode_flag = " << std::hex << +sliceParams->adaptive_ref_pic_marking_mode_flag << std::endl; |
| 4246 |
oss << "# MaxFrameNum = " << std::dec << +sliceParams->MaxFrameNum << std::endl; |
| 4247 |
oss << "# NumReorder = " << std::dec << +sliceParams->NumReorder << std::endl; |
| 4248 |
|
| 4249 |
const char *fileName = m_debugInterface->CreateFileName( |
| 4250 |
"_DDIEnc", |
| 4251 |
CodechalDbgBufferType::bufSlcParams, |
| 4252 |
CodechalDbgExtType::txt); |
| 4253 |
|
| 4254 |
std::ofstream ofs(fileName, std::ios::out); |
| 4255 |
ofs << oss.str(); |
| 4256 |
ofs.close(); |
| 4257 |
|
| 4258 |
if (m_debugInterface->DumpIsEnabled(CodechalDbgAttr::attrDriverUltDump)) |
| 4259 |
{ |
| 4260 |
if (!m_debugInterface->m_ddiFileName.empty()) |
| 4261 |
{ |
| 4262 |
std::ofstream ofs(m_debugInterface->m_ddiFileName, std::ios::app); |
| 4263 |
ofs << "SlcParamFile" |
| 4264 |
<< " = \"" << m_debugInterface->m_fileName << "\"" << std::endl; |
| 4265 |
ofs.close(); |
| 4266 |
} |
| 4267 |
} |
| 4268 |
|
| 4269 |
return MOS_STATUS_SUCCESS; |
| 4270 |
} |
| 4271 |
|
| 4272 |
MOS_STATUS CodechalEncodeAvcBase::DumpVuiParams( |
| 4273 |
PCODECHAL_ENCODE_AVC_VUI_PARAMS vuiParams) |
| 4274 |
{ |
| 4275 |
CODECHAL_DEBUG_FUNCTION_ENTER; |
| 4276 |
|
| 4277 |
if (!m_debugInterface->DumpIsEnabled(CodechalDbgAttr::attrVuiParams)) |
| 4278 |
{ |
| 4279 |
return MOS_STATUS_SUCCESS; |
| 4280 |
} |
| 4281 |
|
| 4282 |
CODECHAL_DEBUG_CHK_NULL(vuiParams); |
| 4283 |
|
| 4284 |
std::ostringstream oss; |
| 4285 |
oss.setf(std::ios::showbase | std::ios::uppercase); |
| 4286 |
|
| 4287 |
oss << "# DDI Parameters:" << std::endl; |
| 4288 |
oss << "aspect_ratio_info_present_flag = " << +vuiParams->aspect_ratio_info_present_flag << std::endl; |
| 4289 |
oss << "overscan_info_present_flag = " << +vuiParams->overscan_info_present_flag << std::endl; |
| 4290 |
oss << "overscan_appropriate_flag = " << +vuiParams->overscan_appropriate_flag << std::endl; |
| 4291 |
oss << "video_signal_type_present_flag = " << +vuiParams->video_signal_type_present_flag << std::endl; |
| 4292 |
oss << "video_full_range_flag = " << +vuiParams->video_full_range_flag << std::endl; |
| 4293 |
oss << "colour_description_present_flag = " << +vuiParams->colour_description_present_flag << std::endl; |
| 4294 |
oss << "chroma_loc_info_present_flag = " << +vuiParams->chroma_loc_info_present_flag << std::endl; |
| 4295 |
oss << "timing_info_present_flag = " << +vuiParams->timing_info_present_flag << std::endl; |
| 4296 |
oss << "fixed_frame_rate_flag = " << +vuiParams->fixed_frame_rate_flag << std::endl; |
| 4297 |
oss << "nal_hrd_parameters_present_flag = " << +vuiParams->nal_hrd_parameters_present_flag << std::endl; |
| 4298 |
oss << "vcl_hrd_parameters_present_flag = " << +vuiParams->vcl_hrd_parameters_present_flag << std::endl; |
| 4299 |
oss << "low_delay_hrd_flag = " << +vuiParams->low_delay_hrd_flag << std::endl; |
| 4300 |
oss << "pic_struct_present_flag = " << +vuiParams->pic_struct_present_flag << std::endl; |
| 4301 |
oss << "bitstream_restriction_flag = " << +vuiParams->bitstream_restriction_flag << std::endl; |
| 4302 |
oss << "motion_vectors_over_pic_boundaries_flag = " << +vuiParams->motion_vectors_over_pic_boundaries_flag << std::endl; |
| 4303 |
oss << "sar_width = " << +vuiParams->sar_width << std::endl; |
| 4304 |
oss << "sar_height = " << +vuiParams->sar_height << std::endl; |
| 4305 |
oss << "aspect_ratio_idc = " << +vuiParams->aspect_ratio_idc << std::endl; |
| 4306 |
oss << "video_format = " << +vuiParams->video_format << std::endl; |
| 4307 |
oss << "colour_primaries = " << +vuiParams->colour_primaries << std::endl; |
| 4308 |
oss << "transfer_characteristics = " << +vuiParams->transfer_characteristics << std::endl; |
| 4309 |
oss << "matrix_coefficients = " << +vuiParams->matrix_coefficients << std::endl; |
| 4310 |
oss << "chroma_sample_loc_type_top_field = " << +vuiParams->chroma_sample_loc_type_top_field << std::endl; |
| 4311 |
oss << "chroma_sample_loc_type_bottom_field = " << +vuiParams->chroma_sample_loc_type_bottom_field << std::endl; |
| 4312 |
oss << "max_bytes_per_pic_denom = " << +vuiParams->max_bytes_per_pic_denom << std::endl; |
| 4313 |
oss << "max_bits_per_mb_denom = " << +vuiParams->max_bits_per_mb_denom << std::endl; |
| 4314 |
oss << "log2_max_mv_length_horizontal = " << +vuiParams->log2_max_mv_length_horizontal << std::endl; |
| 4315 |
oss << "log2_max_mv_length_vertical = " << +vuiParams->log2_max_mv_length_vertical << std::endl; |
| 4316 |
oss << "num_reorder_frames = " << +vuiParams->num_reorder_frames << std::endl; |
| 4317 |
oss << "num_units_in_tick = " << +vuiParams->num_units_in_tick << std::endl; |
| 4318 |
oss << "time_scale = " << +vuiParams->time_scale << std::endl; |
| 4319 |
oss << "max_dec_frame_buffering = " << +vuiParams->max_dec_frame_buffering << std::endl; |
| 4320 |
oss << "cpb_cnt_minus1 = " << +vuiParams->cpb_cnt_minus1 << std::endl; |
| 4321 |
oss << "bit_rate_scale = " << +vuiParams->bit_rate_scale << std::endl; |
| 4322 |
oss << "cpb_size_scale = " << +vuiParams->cpb_size_scale << std::endl; |
| 4323 |
|
| 4324 |
// bit_rate_value_minus1 (32 in size) |
| 4325 |
for (uint8_t i = 0; i < 32; ++i) |
| 4326 |
{ |
| 4327 |
oss << "bit_rate_value_minus1[" << +i << "] = " << +vuiParams->bit_rate_value_minus1[i] << std::endl; |
| 4328 |
} |
| 4329 |
|
| 4330 |
// cpb_size_value_minus1 (32 in size) |
| 4331 |
for (uint8_t i = 0; i < 32; ++i) |
| 4332 |
{ |
| 4333 |
oss << "cpb_size_value_minus1[" << +i << "] = " << +vuiParams->cpb_size_value_minus1[i] << std::endl; |
| 4334 |
} |
| 4335 |
|
| 4336 |
oss << "cbr_flag = " << +vuiParams->cbr_flag << std::endl; |
| 4337 |
oss << "initial_cpb_removal_delay_length_minus1 = " << +vuiParams->initial_cpb_removal_delay_length_minus1 << std::endl; |
| 4338 |
oss << "cpb_removal_delay_length_minus1 = " << +vuiParams->cpb_removal_delay_length_minus1 << std::endl; |
| 4339 |
oss << "dpb_output_delay_length_minus1 = " << +vuiParams->dpb_output_delay_length_minus1 << std::endl; |
| 4340 |
oss << "time_offset_length = " << +vuiParams->time_offset_length << std::endl; |
| 4341 |
|
| 4342 |
const char *fileName = m_debugInterface->CreateFileName( |
| 4343 |
"_DDIEnc", |
| 4344 |
CodechalDbgBufferType::bufVuiParams, |
| 4345 |
CodechalDbgExtType::txt); |
| 4346 |
|
| 4347 |
std::ofstream ofs(fileName, std::ios::out); |
| 4348 |
ofs << oss.str(); |
| 4349 |
ofs.close(); |
| 4350 |
|
| 4351 |
if (m_debugInterface->DumpIsEnabled(CodechalDbgAttr::attrDriverUltDump)) |
| 4352 |
{ |
| 4353 |
if (!m_debugInterface->m_ddiFileName.empty()) |
| 4354 |
{ |
| 4355 |
std::ofstream ofs(m_debugInterface->m_ddiFileName, std::ios::app); |
| 4356 |
ofs << "VuiParamFile" |
| 4357 |
<< " = \"" << m_debugInterface->m_fileName << "\"" << std::endl; |
| 4358 |
ofs.close(); |
| 4359 |
} |
| 4360 |
} |
| 4361 |
|
| 4362 |
return MOS_STATUS_SUCCESS; |
| 4363 |
} |
| 4364 |
|
| 4365 |
bool SearchNALHeader( |
| 4366 |
PMHW_VDBOX_AVC_SLICE_STATE sliceState, |
| 4367 |
uint32_t startCode) |
| 4368 |
{ |
| 4369 |
CODECHAL_DEBUG_FUNCTION_ENTER; |
| 4370 |
|
| 4371 |
for (auto i = 0; i < CODECHAL_ENCODE_AVC_MAX_NAL_TYPE; i++) |
| 4372 |
{ |
| 4373 |
if (sliceState->ppNalUnitParams[i]->uiSize > 0) |
| 4374 |
{ |
| 4375 |
uint32_t offset = 0; |
| 4376 |
uint8_t *dataBase = (uint8_t *)(sliceState->pBsBuffer->pBase + sliceState->ppNalUnitParams[i]->uiOffset); |
| 4377 |
|
| 4378 |
while (offset < sliceState->ppNalUnitParams[i]->uiSize) |
| 4379 |
{ |
| 4380 |
uint8_t *dataBuf = dataBase + offset; |
| 4381 |
|
| 4382 |
if (*dataBuf == 0) |
| 4383 |
{ |
| 4384 |
uint32_t data = ((*dataBuf) << 24) + ((*(dataBuf + 1)) << 16) + ((*(dataBuf + 2)) << 8) + (*(dataBuf + 3)); |
| 4385 |
|
| 4386 |
if ((data & 0xFFFFFF00) == 0x00000100) |
| 4387 |
{ |
| 4388 |
if (data == startCode) |
| 4389 |
{ |
| 4390 |
return true; |
| 4391 |
} |
| 4392 |
|
| 4393 |
offset += 4; |
| 4394 |
} |
| 4395 |
else |
| 4396 |
{ |
| 4397 |
offset++; |
| 4398 |
} |
| 4399 |
} |
| 4400 |
else |
| 4401 |
{ |
| 4402 |
offset++; |
| 4403 |
} |
| 4404 |
} |
| 4405 |
} |
| 4406 |
} |
| 4407 |
|
| 4408 |
return false; |
| 4409 |
} |
| 4410 |
|
| 4411 |
MOS_STATUS CodechalEncodeAvcBase::CreateAvcPar() |
| 4412 |
{ |
| 4413 |
CODECHAL_DEBUG_FUNCTION_ENTER; |
| 4414 |
|
| 4415 |
CODECHAL_DEBUG_CHK_NULL(m_debugInterface); |
| 4416 |
|
| 4417 |
if (m_debugInterface->DumpIsEnabled(CodechalDbgAttr::attrDumpEncodePar)) |
| 4418 |
{ |
| 4419 |
CODECHAL_DEBUG_CHK_NULL(m_avcPar = MOS_New(EncodeAvcPar)); |
| 4420 |
MOS_ZeroMemory(m_avcPar, sizeof(EncodeAvcPar)); |
| 4421 |
} |
| 4422 |
|
| 4423 |
return MOS_STATUS_SUCCESS; |
| 4424 |
} |
| 4425 |
|
| 4426 |
MOS_STATUS CodechalEncodeAvcBase::DestroyAvcPar() |
| 4427 |
{ |
| 4428 |
CODECHAL_DEBUG_FUNCTION_ENTER; |
| 4429 |
|
| 4430 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(DumpSeqParFile()); |
| 4431 |
MOS_Delete(m_avcPar); |
| 4432 |
|
| 4433 |
return MOS_STATUS_SUCCESS; |
| 4434 |
} |
| 4435 |
|
| 4436 |
MOS_STATUS CodechalEncodeAvcBase::PopulateConstParam() |
| 4437 |
{ |
| 4438 |
CODECHAL_DEBUG_FUNCTION_ENTER; |
| 4439 |
|
| 4440 |
CODECHAL_DEBUG_CHK_NULL(m_debugInterface); |
| 4441 |
|
| 4442 |
if (!m_debugInterface->DumpIsEnabled(CodechalDbgAttr::attrDumpEncodePar)) |
| 4443 |
{ |
| 4444 |
return MOS_STATUS_SUCCESS; |
| 4445 |
} |
| 4446 |
|
| 4447 |
if (m_encodeParState->m_isConstDumped) |
| 4448 |
{ |
| 4449 |
return MOS_STATUS_SUCCESS; |
| 4450 |
} |
| 4451 |
|
| 4452 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(PopulateTargetUsage()); |
| 4453 |
|
| 4454 |
std::ostringstream oss; |
| 4455 |
oss.setf(std::ios::showbase | std::ios::uppercase); |
| 4456 |
|
| 4457 |
// Constant |
| 4458 |
oss << "EnableStatistics = 0" << std::endl; |
| 4459 |
oss << "KernelDumpEnable = 16" << std::endl; |
| 4460 |
oss << "Kernel = 1" << std::endl; |
| 4461 |
oss << "StartMB = -1" << std::endl; |
| 4462 |
oss << "EndMB = -1" << std::endl; |
| 4463 |
oss << "GOPMode = 0" << std::endl; |
| 4464 |
oss << "BoxFilter = 1" << std::endl; |
| 4465 |
oss << "EnableBpyramid = 0" << std::endl; |
| 4466 |
oss << "EnableIPCM = 1" << std::endl; |
| 4467 |
oss << "EnableMVUnpacked = 1" << std::endl; |
| 4468 |
oss << "EnableNewModeCost = 1" << std::endl; |
| 4469 |
oss << "EnablePAFF = 0" << std::endl; |
| 4470 |
oss << "EnableSkip = 3" << std::endl; |
| 4471 |
oss << "EnableSkipBiasAdjustment = 1" << std::endl; |
| 4472 |
oss << "HierarchicalMEFlag = 3" << std::endl; |
| 4473 |
oss << "NumRefStartB = 1" << std::endl; |
| 4474 |
oss << "PAFFThreshold = 10000" << std::endl; |
| 4475 |
oss << "PicScalingList = 0" << std::endl; |
| 4476 |
oss << "SeqScalingList = 0" << std::endl; |
| 4477 |
oss << "SkipChromaCBPDetection = 1" << std::endl; |
| 4478 |
oss << "IdrInterval = 0" << std::endl; |
| 4479 |
oss << "AddEoSquenceNAL = 1" << std::endl; |
| 4480 |
oss << "AddEoStreamNAL = 1" << std::endl; |
| 4481 |
oss << "CabacZeroWordFlag = 0" << std::endl; |
| 4482 |
oss << "EncodeFrameSizeTolerance = 0" << std::endl; |
| 4483 |
oss << "ForceIntraDC = 0" << std::endl; |
| 4484 |
oss << "HMECoarseShape = 2" << std::endl; |
| 4485 |
oss << "HMESubPelMode = 3" << std::endl; |
| 4486 |
oss << "IntraDirectionBias = 1" << std::endl; |
| 4487 |
oss << "InterSADMeasure = 2" << std::endl; |
| 4488 |
oss << "IntraSADMeasure = 2" << std::endl; |
| 4489 |
oss << "CostingFeature = 3" << std::endl; |
| 4490 |
oss << "CostingType = 1" << std::endl; |
| 4491 |
oss << "ModeCosting = 1" << std::endl; |
| 4492 |
oss << "HighQPMvCostEnable = 1" << std::endl; |
| 4493 |
oss << "HighQPHMECostEnable = 1" << std::endl; |
| 4494 |
oss << "RefIDCostMode = 0" << std::endl; |
| 4495 |
oss << "EnableAdaptiveLambdaOffset = 1" << std::endl; |
| 4496 |
|
| 4497 |
m_encodeParState->m_isConstDumped = true; |
| 4498 |
|
| 4499 |
const char *fileName = m_debugInterface->CreateFileName( |
| 4500 |
"EncodeSequence", |
| 4501 |
"EncodePar", |
| 4502 |
CodechalDbgExtType::par); |
| 4503 |
|
| 4504 |
std::ofstream ofs(fileName, std::ios::app); |
| 4505 |
ofs << oss.str(); |
| 4506 |
ofs.close(); |
| 4507 |
|
| 4508 |
return MOS_STATUS_SUCCESS; |
| 4509 |
} |
| 4510 |
|
| 4511 |
MOS_STATUS CodechalEncodeAvcBase::PopulateTargetUsage() |
| 4512 |
{ |
| 4513 |
CODECHAL_DEBUG_FUNCTION_ENTER; |
| 4514 |
|
| 4515 |
if (m_populateTargetUsage == false) |
| 4516 |
{ |
| 4517 |
return MOS_STATUS_SUCCESS; |
| 4518 |
} |
| 4519 |
|
| 4520 |
const char *fileName = m_debugInterface->CreateFileName( |
| 4521 |
"EncodeSequence", |
| 4522 |
"EncodePar", |
| 4523 |
CodechalDbgExtType::par); |
| 4524 |
|
| 4525 |
std::ifstream ifs(fileName); |
| 4526 |
std::string str((std::istreambuf_iterator<char>(ifs)), std::istreambuf_iterator<char>()); |
| 4527 |
ifs.close(); |
| 4528 |
std::ofstream ofs(fileName, std::ios::trunc); |
| 4529 |
ofs << "TargetUsage = " << static_cast<uint32_t>(m_avcSeqParam->TargetUsage) << std::endl; |
| 4530 |
ofs << str; |
| 4531 |
ofs.close(); |
| 4532 |
|
| 4533 |
return MOS_STATUS_SUCCESS; |
| 4534 |
} |
| 4535 |
|
| 4536 |
MOS_STATUS CodechalEncodeAvcBase::PopulateDdiParam( |
| 4537 |
PCODEC_AVC_ENCODE_SEQUENCE_PARAMS avcSeqParams, |
| 4538 |
PCODEC_AVC_ENCODE_PIC_PARAMS avcPicParams, |
| 4539 |
PCODEC_AVC_ENCODE_SLICE_PARAMS avcSlcParams) |
| 4540 |
{ |
| 4541 |
CODECHAL_DEBUG_FUNCTION_ENTER; |
| 4542 |
|
| 4543 |
CODECHAL_DEBUG_CHK_NULL(m_debugInterface); |
| 4544 |
|
| 4545 |
if (!m_debugInterface->DumpIsEnabled(CodechalDbgAttr::attrDumpEncodePar)) |
| 4546 |
{ |
| 4547 |
return MOS_STATUS_SUCCESS; |
| 4548 |
} |
| 4549 |
|
| 4550 |
if (Slice_Type[avcSlcParams->slice_type] == SLICE_I || Slice_Type[avcSlcParams->slice_type] == SLICE_SI) |
| 4551 |
{ |
| 4552 |
m_avcPar->ProfileIDC = avcSeqParams->Profile; |
| 4553 |
m_avcPar->LevelIDC = avcSeqParams->Level; |
| 4554 |
m_avcPar->DisableVUIHeader = !avcSeqParams->vui_parameters_present_flag; |
| 4555 |
m_avcPar->ChromaFormatIDC = avcSeqParams->chroma_format_idc; |
| 4556 |
m_avcPar->ChromaQpOffset = avcPicParams->chroma_qp_index_offset; |
| 4557 |
m_avcPar->SecondChromaQpOffset = avcPicParams->second_chroma_qp_index_offset; |
| 4558 |
|
| 4559 |
uint8_t pictureCodingType = CodecHal_PictureIsFrame(avcPicParams->CurrOriginalPic) ? 0 : (CodecHal_PictureIsTopField(avcPicParams->CurrOriginalPic) ? 1 : 3); |
| 4560 |
m_avcPar->PictureCodingType = pictureCodingType; |
| 4561 |
|
| 4562 |
uint16_t gopP = (avcSeqParams->GopRefDist) ? ((avcSeqParams->GopPicSize - 1) / avcSeqParams->GopRefDist) : 0; |
| 4563 |
uint16_t gopB = avcSeqParams->GopPicSize - 1 - gopP; |
| 4564 |
m_avcPar->NumP = gopP; |
| 4565 |
m_avcPar->NumB = ((gopP > 0) ? (gopB / gopP) : 0); |
| 4566 |
|
| 4567 |
if ((avcPicParams->NumSlice * m_sliceHeight) >= |
| 4568 |
(uint32_t)(avcSeqParams->pic_height_in_map_units_minus1 + 1 + m_sliceHeight)) |
| 4569 |
{ |
| 4570 |
m_avcPar->NumSlices = avcPicParams->NumSlice - 1; |
| 4571 |
} |
| 4572 |
else |
| 4573 |
{ |
| 4574 |
m_avcPar->NumSlices = avcPicParams->NumSlice; |
| 4575 |
} |
| 4576 |
m_avcPar->SliceHeight = m_sliceHeight; |
| 4577 |
|
| 4578 |
m_avcPar->NumSuperSlices = m_avcPar->NumSlices; |
| 4579 |
if (m_avcPar->NumSuperSlices) |
| 4580 |
{ |
| 4581 |
uint32_t sliceIdx = 0; |
| 4582 |
for (; sliceIdx < m_avcPar->NumSuperSlices - 1; sliceIdx++) |
| 4583 |
{ |
| 4584 |
m_avcPar->SuperSliceHeight[sliceIdx] = m_sliceHeight; |
| 4585 |
} |
| 4586 |
m_avcPar->SuperSliceHeight[sliceIdx] = avcSeqParams->pic_height_in_map_units_minus1 + 1 - sliceIdx * m_sliceHeight; |
| 4587 |
} |
| 4588 |
|
| 4589 |
m_avcPar->ISliceQP = avcPicParams->QpY + avcSlcParams->slice_qp_delta; |
| 4590 |
m_avcPar->FrameRateM = ((avcSeqParams->FramesPer100Sec % 100) == 0) ? (avcSeqParams->FramesPer100Sec / 100) : avcSeqParams->FramesPer100Sec; |
| 4591 |
m_avcPar->FrameRateD = ((avcSeqParams->FramesPer100Sec % 100) == 0) ? 1 : 100; |
| 4592 |
|
| 4593 |
uint8_t brcMethod = 0; |
| 4594 |
uint8_t brcType = 0; |
| 4595 |
|
| 4596 |
if (CodecHalIsRateControlBrc(avcSeqParams->RateControlMethod, CODECHAL_AVC)) |
| 4597 |
{ |
| 4598 |
brcMethod = 2; |
| 4599 |
|
| 4600 |
switch (avcSeqParams->RateControlMethod) |
| 4601 |
{ |
| 4602 |
case RATECONTROL_ICQ: |
| 4603 |
brcMethod = m_vdencEnabled ? 2 : 3; |
| 4604 |
brcType = 16; |
| 4605 |
break; |
| 4606 |
case RATECONTROL_QVBR: |
| 4607 |
brcMethod = m_vdencEnabled ? 2 : 4; |
| 4608 |
brcType = 2; |
| 4609 |
break; |
| 4610 |
case RATECONTROL_CBR: |
| 4611 |
brcType = 1; |
| 4612 |
break; |
| 4613 |
case RATECONTROL_VBR: |
| 4614 |
brcType = 2; |
| 4615 |
break; |
| 4616 |
case RATECONTROL_VCM: |
| 4617 |
brcType = m_vdencEnabled ? 4 : 3; |
| 4618 |
break; |
| 4619 |
default: |
| 4620 |
brcMethod = 0; |
| 4621 |
brcType = 0; |
| 4622 |
break; |
| 4623 |
} |
| 4624 |
|
| 4625 |
if (avcSeqParams->FrameSizeTolerance == EFRAMESIZETOL_EXTREMELY_LOW) |
| 4626 |
{ |
| 4627 |
// low delay mode |
| 4628 |
brcType = 8; |
| 4629 |
} |
| 4630 |
} |
| 4631 |
|
| 4632 |
m_avcPar->BRCMethod = brcMethod; |
| 4633 |
m_avcPar->BRCType = brcType; |
| 4634 |
|
| 4635 |
m_avcPar->DeblockingIDC = avcSlcParams->disable_deblocking_filter_idc; |
| 4636 |
m_avcPar->DeblockingFilterAlpha = avcSlcParams->slice_alpha_c0_offset_div2 << 1; |
| 4637 |
m_avcPar->DeblockingFilterBeta = avcSlcParams->slice_beta_offset_div2 << 1; |
| 4638 |
m_avcPar->EntropyCodingMode = avcPicParams->entropy_coding_mode_flag; |
| 4639 |
m_avcPar->DirectInference = avcSeqParams->direct_8x8_inference_flag; |
| 4640 |
m_avcPar->Transform8x8Mode = avcPicParams->transform_8x8_mode_flag; |
| 4641 |
m_avcPar->CRFQualityFactor = avcSeqParams->ICQQualityFactor; |
| 4642 |
m_avcPar->ConstrainedIntraPred = avcPicParams->constrained_intra_pred_flag; |
| 4643 |
|
| 4644 |
// This is only for header matching although I frame doesn't have references |
| 4645 |
if (avcSlcParams->num_ref_idx_active_override_flag) |
| 4646 |
{ |
| 4647 |
m_avcPar->MaxRefIdxL0 = MOS_MAX(m_avcPar->MaxRefIdxL0, avcSlcParams->num_ref_idx_l0_active_minus1); |
| 4648 |
m_avcPar->MaxRefIdxL1 = MOS_MAX(m_avcPar->MaxRefIdxL1, avcSlcParams->num_ref_idx_l1_active_minus1); |
| 4649 |
} |
| 4650 |
else |
| 4651 |
{ |
| 4652 |
m_avcPar->MaxRefIdxL0 = MOS_MAX(m_avcPar->MaxRefIdxL0, avcPicParams->num_ref_idx_l0_active_minus1); |
| 4653 |
m_avcPar->MaxRefIdxL1 = MOS_MAX(m_avcPar->MaxRefIdxL1, avcPicParams->num_ref_idx_l1_active_minus1); |
| 4654 |
} |
| 4655 |
|
| 4656 |
if (m_vdencEnabled) |
| 4657 |
{ |
| 4658 |
m_avcPar->SliceMode = avcSeqParams->EnableSliceLevelRateCtrl ? 2 : 0; |
| 4659 |
} |
| 4660 |
} |
| 4661 |
else if (Slice_Type[avcSlcParams->slice_type] == SLICE_P || Slice_Type[avcSlcParams->slice_type] == SLICE_SP) |
| 4662 |
{ |
| 4663 |
m_avcPar->PSliceQP = avcPicParams->QpY + avcSlcParams->slice_qp_delta; |
| 4664 |
m_avcPar->CabacInitIDC = avcSlcParams->cabac_init_idc; |
| 4665 |
|
| 4666 |
if (avcSlcParams->num_ref_idx_active_override_flag) |
| 4667 |
{ |
| 4668 |
m_avcPar->MaxRefIdxL0 = MOS_MAX(m_avcPar->MaxRefIdxL0, avcSlcParams->num_ref_idx_l0_active_minus1); |
| 4669 |
m_avcPar->MaxRefIdxL1 = MOS_MAX(m_avcPar->MaxRefIdxL1, avcSlcParams->num_ref_idx_l1_active_minus1); |
| 4670 |
} |
| 4671 |
else |
| 4672 |
{ |
| 4673 |
m_avcPar->MaxRefIdxL0 = MOS_MAX(m_avcPar->MaxRefIdxL0, avcPicParams->num_ref_idx_l0_active_minus1); |
| 4674 |
m_avcPar->MaxRefIdxL1 = MOS_MAX(m_avcPar->MaxRefIdxL1, avcPicParams->num_ref_idx_l1_active_minus1); |
| 4675 |
} |
| 4676 |
|
| 4677 |
if (m_avcPar->NumB == 0) // There's no B frame |
| 4678 |
{ |
| 4679 |
m_avcPar->EnableWeightPredictionDetection = avcPicParams->weighted_pred_flag > 0 ? 1 : 0; |
| 4680 |
} |
| 4681 |
m_avcPar->WeightedPred = avcPicParams->weighted_pred_flag; |
| 4682 |
m_avcPar->UseOrigAsRef = avcPicParams->UserFlags.bUseRawPicForRef; |
| 4683 |
m_avcPar->BiSubMbPartMask = avcPicParams->UserFlags.bDisableSubMBPartition ? (bool)(CODECHAL_ENCODE_AVC_DISABLE_4X4_SUB_MB_PARTITION | CODECHAL_ENCODE_AVC_DISABLE_4X8_SUB_MB_PARTITION | CODECHAL_ENCODE_AVC_DISABLE_8X4_SUB_MB_PARTITION) : 0; |
| 4684 |
|
| 4685 |
if (m_vdencEnabled) |
| 4686 |
{ |
| 4687 |
if (m_targetUsage == 1 || m_targetUsage == 2) |
| 4688 |
{ |
| 4689 |
m_avcPar->StaticFrameZMVPercent = avcPicParams->dwZMvThreshold; |
| 4690 |
} |
| 4691 |
else |
| 4692 |
{ |
| 4693 |
m_avcPar->StaticFrameZMVPercent = 100; |
| 4694 |
} |
| 4695 |
|
| 4696 |
if (avcPicParams->bEnableHMEOffset) |
| 4697 |
{ |
| 4698 |
m_avcPar->hme0XOffset = MOS_CLAMP_MIN_MAX(avcPicParams->HMEOffset[0][0][0], -128, 127); |
| 4699 |
m_avcPar->hme0YOffset = MOS_CLAMP_MIN_MAX(avcPicParams->HMEOffset[0][0][1], -128, 127); |
| 4700 |
m_avcPar->hme1XOffset = MOS_CLAMP_MIN_MAX(avcPicParams->HMEOffset[1][0][0], -128, 127); |
| 4701 |
m_avcPar->hme1YOffset = MOS_CLAMP_MIN_MAX(avcPicParams->HMEOffset[1][0][1], -128, 127); |
| 4702 |
} |
| 4703 |
} |
| 4704 |
} |
| 4705 |
else if (Slice_Type[avcSlcParams->slice_type] == SLICE_B) |
| 4706 |
{ |
| 4707 |
m_avcPar->BSliceQP = avcPicParams->QpY + avcSlcParams->slice_qp_delta; |
| 4708 |
|
| 4709 |
if (avcSlcParams->num_ref_idx_active_override_flag) |
| 4710 |
{ |
| 4711 |
m_avcPar->MaxBRefIdxL0 = MOS_MAX(m_avcPar->MaxBRefIdxL0, avcSlcParams->num_ref_idx_l0_active_minus1); |
| 4712 |
} |
| 4713 |
else |
| 4714 |
{ |
| 4715 |
m_avcPar->MaxBRefIdxL0 = MOS_MAX(m_avcPar->MaxBRefIdxL0, avcPicParams->num_ref_idx_l0_active_minus1); |
| 4716 |
} |
| 4717 |
|
| 4718 |
m_avcPar->EnableWeightPredictionDetection = (avcPicParams->weighted_bipred_idc | avcPicParams->weighted_pred_flag) > 0 ? 1 : 0; |
| 4719 |
m_avcPar->WeightedBiPred = avcPicParams->weighted_bipred_idc; |
| 4720 |
m_avcPar->BiWeight = m_biWeight; |
| 4721 |
} |
| 4722 |
|
| 4723 |
return MOS_STATUS_SUCCESS; |
| 4724 |
} |
| 4725 |
|
| 4726 |
MOS_STATUS CodechalEncodeAvcBase::PopulateSliceStateParam( |
| 4727 |
bool adaptiveRoundingInterEnable, |
| 4728 |
PMHW_VDBOX_AVC_SLICE_STATE sliceState) |
| 4729 |
{ |
| 4730 |
CODECHAL_DEBUG_FUNCTION_ENTER; |
| 4731 |
|
| 4732 |
CODECHAL_DEBUG_CHK_NULL(m_debugInterface); |
| 4733 |
|
| 4734 |
if (!m_debugInterface->DumpIsEnabled(CodechalDbgAttr::attrDumpEncodePar)) |
| 4735 |
{ |
| 4736 |
return MOS_STATUS_SUCCESS; |
| 4737 |
} |
| 4738 |
|
| 4739 |
if (m_pictureCodingType == I_TYPE) |
| 4740 |
{ |
| 4741 |
m_avcPar->RoundingIntraEnabled = true; |
| 4742 |
m_avcPar->RoundingIntra = 5; |
| 4743 |
// Set to 1 first, we don't consider 0 case as we only dump I frame param once |
| 4744 |
m_avcPar->FrmHdrEncodingFrequency = 1; // 1: picture header in every IDR frame |
| 4745 |
|
| 4746 |
// Search SEI NAL |
| 4747 |
m_avcPar->EnableSEI = SearchNALHeader(sliceState, CODECHAL_DEBUG_ENCODE_AVC_NAL_START_CODE_SEI); |
| 4748 |
} |
| 4749 |
else if (m_pictureCodingType == P_TYPE) |
| 4750 |
{ |
| 4751 |
m_avcPar->EnableAdaptiveRounding = adaptiveRoundingInterEnable; |
| 4752 |
m_avcPar->RoundingInterEnabled = sliceState->bRoundingInterEnable; |
| 4753 |
m_avcPar->RoundingInter = sliceState->dwRoundingValue; |
| 4754 |
|
| 4755 |
// Search PPS NAL |
| 4756 |
m_avcPar->FrmHdrEncodingFrequency = |
| 4757 |
SearchNALHeader(sliceState, CODECHAL_DEBUG_ENCODE_AVC_NAL_START_CODE_PPS) ? 2 : m_avcPar->FrmHdrEncodingFrequency; |
| 4758 |
} |
| 4759 |
else if (m_pictureCodingType == B_TYPE) |
| 4760 |
{ |
| 4761 |
m_avcPar->RoundingInterB = sliceState->dwRoundingValue; |
| 4762 |
} |
| 4763 |
|
| 4764 |
return MOS_STATUS_SUCCESS; |
| 4765 |
} |
| 4766 |
|
| 4767 |
MOS_STATUS CodechalEncodeAvcBase::PopulateSfdParam( |
| 4768 |
void *cmd) |
| 4769 |
{ |
| 4770 |
CODECHAL_DEBUG_FUNCTION_ENTER; |
| 4771 |
|
| 4772 |
CODECHAL_DEBUG_CHK_NULL(m_debugInterface); |
| 4773 |
|
| 4774 |
if (!m_debugInterface->DumpIsEnabled(CodechalDbgAttr::attrDumpEncodePar)) |
| 4775 |
{ |
| 4776 |
return MOS_STATUS_SUCCESS; |
| 4777 |
} |
| 4778 |
|
| 4779 |
CODECHAL_ENCODE_AVC_SFD_CURBE_COMMON *curbe = (CODECHAL_ENCODE_AVC_SFD_CURBE_COMMON *)cmd; |
| 4780 |
|
| 4781 |
if (m_pictureCodingType == P_TYPE) |
| 4782 |
{ |
| 4783 |
m_avcPar->EnableIntraCostScalingForStaticFrame = curbe->DW0.EnableIntraCostScalingForStaticFrame; |
| 4784 |
m_avcPar->StaticFrameIntraCostScalingRatioP = 240; |
| 4785 |
m_avcPar->AdaptiveMvStreamIn = curbe->DW0.EnableAdaptiveMvStreamIn; |
| 4786 |
m_avcPar->LargeMvThresh = curbe->DW3.LargeMvThresh; |
| 4787 |
m_avcPar->LargeMvPctThreshold = 1; |
| 4788 |
} |
| 4789 |
|
| 4790 |
return MOS_STATUS_SUCCESS; |
| 4791 |
} |
| 4792 |
#endif |
| 4793 |
|
| 4794 |
MOS_STATUS CodechalEncodeAvcBase::SetFrameStoreIds(uint8_t frameIdx) |
| 4795 |
{ |
| 4796 |
uint8_t invalidFrame = (m_mode == CODECHAL_DECODE_MODE_AVCVLD) ? 0x7f : 0x1f; |
| 4797 |
|
| 4798 |
for (uint8_t i = 0; i < m_refList[frameIdx]->ucNumRef; i++) |
| 4799 |
{ |
| 4800 |
uint8_t index; |
| 4801 |
index = m_refList[frameIdx]->RefList[i].FrameIdx; |
| 4802 |
if (m_refList[index]->ucFrameId == invalidFrame) |
| 4803 |
{ |
| 4804 |
uint8_t j; |
| 4805 |
for (j = 0; j < CODEC_AVC_MAX_NUM_REF_FRAME; j++) |
| 4806 |
{ |
| 4807 |
if (!m_avcFrameStoreID[j].inUse) |
| 4808 |
{ |
| 4809 |
m_refList[index]->ucFrameId = j; |
| 4810 |
m_avcFrameStoreID[j].inUse = true; |
| 4811 |
break; |
| 4812 |
} |
| 4813 |
} |
| 4814 |
if (j == CODEC_AVC_MAX_NUM_REF_FRAME) |
| 4815 |
{ |
| 4816 |
// should never happen, something must be wrong |
| 4817 |
CODECHAL_PUBLIC_ASSERT(false); |
| 4818 |
m_refList[index]->ucFrameId = 0; |
| 4819 |
m_avcFrameStoreID[0].inUse = true; |
| 4820 |
} |
| 4821 |
} |
| 4822 |
} |
| 4823 |
return MOS_STATUS_SUCCESS; |
| 4824 |
} |
| 4825 |
|
| 4826 |
MOS_STATUS CodechalEncodeAvcBase::AddMfxAvcSlice( |
| 4827 |
PMOS_COMMAND_BUFFER cmdBuffer, |
| 4828 |
PMHW_BATCH_BUFFER batchBuffer, |
| 4829 |
PMHW_VDBOX_AVC_SLICE_STATE avcSliceState) |
| 4830 |
{ |
| 4831 |
CODECHAL_ENCODE_FUNCTION_ENTER; |
| 4832 |
|
| 4833 |
CODECHAL_ENCODE_CHK_NULL_RETURN(m_mfxInterface); |
| 4834 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(m_mfxInterface->AddMfxAvcSlice(cmdBuffer, batchBuffer, avcSliceState)); |
| 4835 |
|
| 4836 |
return MOS_STATUS_SUCCESS; |
| 4837 |
} |
| 4838 |
|
| 4839 |
MOS_STATUS CodechalEncodeAvcBase::AddVdencSliceStateCmd( |
| 4840 |
PMOS_COMMAND_BUFFER cmdBuffer, |
| 4841 |
PMHW_VDBOX_AVC_SLICE_STATE params) |
| 4842 |
{ |
| 4843 |
CODECHAL_ENCODE_FUNCTION_ENTER; |
| 4844 |
|
| 4845 |
CODECHAL_ENCODE_CHK_NULL_RETURN(m_vdencInterface); |
| 4846 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(m_vdencInterface->AddVdencSliceStateCmd(cmdBuffer, params)); |
| 4847 |
|
| 4848 |
return MOS_STATUS_SUCCESS; |
| 4849 |
} |
| 4850 |
MOS_STATUS CodechalEncodeAvcBase::GetStatusReport( |
| 4851 |
EncodeStatus* encodeStatus, |
| 4852 |
EncodeStatusReport* encodeStatusReport) |
| 4853 |
{ |
| 4854 |
MOS_STATUS eStatus = MOS_STATUS_SUCCESS; |
| 4855 |
|
| 4856 |
encodeStatusReport->CodecStatus = CODECHAL_STATUS_SUCCESSFUL; |
| 4857 |
encodeStatusReport->bitstreamSize = |
| 4858 |
encodeStatus->dwMFCBitstreamByteCountPerFrame + encodeStatus->dwHeaderBytesInserted; |
| 4859 |
|
| 4860 |
// dwHeaderBytesInserted is for WAAVCSWHeaderInsertion |
| 4861 |
// and is 0 otherwise |
| 4862 |
encodeStatusReport->QpY = encodeStatus->BrcQPReport.DW0.QPPrimeY; |
| 4863 |
encodeStatusReport->SuggestedQpYDelta = |
| 4864 |
encodeStatus->ImageStatusCtrl.CumulativeSliceDeltaQP; |
| 4865 |
encodeStatusReport->NumberPasses = (uint8_t)encodeStatus->dwNumberPasses; |
| 4866 |
ENCODE_VERBOSEMESSAGE("statusReportData->numberPasses: %d\n", encodeStatusReport->NumberPasses); |
| 4867 |
encodeStatusReport->SceneChangeDetected = |
| 4868 |
(encodeStatus->dwSceneChangedFlag & CODECHAL_ENCODE_SCENE_CHANGE_DETECTED_MASK) ? 1 : 0; |
| 4869 |
|
| 4870 |
CODECHAL_ENCODE_CHK_NULL_RETURN(m_skuTable); |
| 4871 |
|
| 4872 |
if (m_picWidthInMb != 0 && m_frameFieldHeightInMb != 0) |
| 4873 |
{ |
| 4874 |
encodeStatusReport->AverageQp = (unsigned char)(((uint32_t)encodeStatus->QpStatusCount.cumulativeQP) / (m_picWidthInMb * m_frameFieldHeightInMb)); |
| 4875 |
} |
| 4876 |
encodeStatusReport->PanicMode = encodeStatus->ImageStatusCtrl.Panic; |
| 4877 |
|
| 4878 |
// If Num slices is greater than spec limit set NumSlicesNonCompliant to 1 and report error |
| 4879 |
PMHW_VDBOX_PAK_NUM_OF_SLICES numSlices = &encodeStatus->NumSlices; |
| 4880 |
if (numSlices->NumberOfSlices > m_maxNumSlicesAllowed) |
| 4881 |
{ |
| 4882 |
encodeStatusReport->NumSlicesNonCompliant = 1; |
| 4883 |
} |
| 4884 |
encodeStatusReport->NumberSlices = numSlices->NumberOfSlices; |
| 4885 |
|
| 4886 |
return eStatus; |
| 4887 |
} |