/* * ConstructAccessUnit * construct an access unit for given input bitstream, maybe partial NAL Unit, one or more Units are involved to * joint a collective access unit. * parameter\ * buf: bitstream data buffer * bit_len: size in bit length of data * buf_len: size in byte length of data * coded_au: mark an Access Unit decoding finished * return: * 0 - success; otherwise returned error_no defined in error_no.h */ int32_tConstructAccessUnit(PWelsDecoderContext pCtx, uint8_t** ppDst, SBufferInfo* pDstInfo){ int32_t iErr = ERR_NONE; if (GetThreadCount (pCtx) <= 1) { //初始化 iErr = InitConstructAccessUnit (pCtx, pDstInfo); if (ERR_NONE != iErr) { return iErr; } } if (pCtx->pCabacDecEngine == NULL) { pCtx->pCabacDecEngine = (SWelsCabacDecEngine*)pCtx->pMemAlign->WelsMallocz (sizeof (SWelsCabacDecEngine), "pCtx->pCabacDecEngine"); WELS_VERIFY_RETURN_IF (ERR_INFO_OUT_OF_MEMORY, (NULL == pCtx->pCabacDecEngine)) }
typedefstructTagWelsDecoderContext { SLogContext sLogCtx; // Input void* pArgDec; // structured arguments for decoder, reserved here for extension in the future
SDataBuffer sRawData; //内部缓存的比特流 SDataBuffer sSavedData; //for parse only purpose
VIDEO_BITSTREAM_TYPE eVideoType; //indicate the type of video to decide whether or not to do qp_delta error detection. bool bHaveGotMemory; // global memory for decoder context related ever requested?
int32_t iImgWidthInPixel; // width of image in pixel reconstruction picture to be output int32_t iImgHeightInPixel;// height of image in pixel reconstruction picture to be output int32_t iLastImgWidthInPixel; // width of image in last successful pixel reconstruction picture to be output int32_t iLastImgHeightInPixel;// height of image in last successful pixel reconstruction picture to be output bool bFreezeOutput; // indicating current frame freezing. Default: true
// Derived common elements SNalUnitHeader sCurNalHead; EWelsSliceType eSliceType; // Slice type bool bUsedAsRef; //flag as ref int32_t iFrameNum; int32_t iErrorCode; // error code return while decoding in case packets lost SFmo sFmoList[MAX_PPS_COUNT]; // list for FMO storage PFmo pFmo; // current fmo context after parsed slice_header int32_t iActiveFmoNum; // active count number of fmo context in list
/*needed info by decode slice level and mb level*/ int32_t iDecBlockOffsetArray[24]; // address talbe for sub 4x4 block in intra4x4_mb, so no need to caculta the address every time.
// reconstruction picture PPicture pDec; //pointer to current picture being reconstructed
PPicture pTempDec; //pointer to temp decoder picture to be used only for Bi Prediction.
// reference pictures SRefPic sRefPic; SRefPic sTmpRefPic; //used to temporarily save RefPic for next active thread SVlcTable* pVlcTable; // vlc table
SBitStringAux sBs; int32_t iMaxBsBufferSizeInByte; //actual memory size for BS buffer
/* Global memory external */ SWelsDecoderSpsPpsCTX sSpsPpsCtx; bool bHasNewSps;
SPosOffset sFrameCrop;
PSliceHeader pSliceHeader;
PPicBuff pPicBuff; // Initially allocated memory for pictures which are used in decoding. int32_t iPicQueueNumber;
PAccessUnit pAccessUnitList; // current access unit list to be performed //PSps pActiveLayerSps[MAX_LAYER_NUM]; PSps pSps; // used by current AU PPps pPps; // used by current AU // Memory for pAccessUnitList is dynamically held till decoder destruction. PDqLayer pCurDqLayer; // current DQ layer representation, also carry reference base layer if applicable PDqLayer pDqLayersList[LAYER_NUM_EXCHANGEABLE]; // DQ layers list with memory allocated PNalUnit pNalCur; // point to current NAL Nnit uint8_t uiNalRefIdc; // NalRefIdc for easy access; int32_t iPicWidthReq; // picture width have requested the memory int32_t iPicHeightReq; // picture height have requested the memory
uint8_t uiTargetDqId; // maximal DQ ID in current access unit, meaning target layer ID //bool bAvcBasedFlag; // For decoding bitstream: bool bEndOfStreamFlag; // Flag on end of stream requested by external application layer bool bInstantDecFlag; // Flag for no-delay decoding bool bInitialDqLayersMem; // dq layers related memory is available?
bool bOnlyOneLayerInCurAuFlag; //only one layer in current AU: 1
bool bReferenceLostAtT0Flag; int32_t iTotalNumMbRec; //record current number of decoded MB #ifdef LONG_TERM_REF bool bParamSetsLostFlag; //sps or pps do not exist or not correct
bool bCurAuContainLtrMarkSeFlag; //current AU has the LTR marking syntax element, mark the previous frame or self int32_t iFrameNumOfAuMarkedLtr; //if bCurAuContainLtrMarkSeFlag==true, SHOULD set this variable
//feedback whether or not have VCL in current AU, and the temporal ID int32_t iFeedbackVclNalInAu; int32_t iFeedbackTidInAu; int32_t iFeedbackNalRefIdc;
bool bAuReadyFlag; // true: one au is ready for decoding; false: default value
bool bPrintFrameErrorTraceFlag; //true: can print info for upper layer int32_t iIgnoredErrorInfoPacketCount; //store the packet number with error decoding info //trace handle void* pTraceHandle;
PWelsLastDecPicInfo pLastDecPicInfo;
SWelsCabacCtx sWelsCabacContexts[4][WELS_QP_MAX + 1][WELS_CONTEXT_COUNT]; bool bCabacInited; SWelsCabacCtx pCabacCtx[WELS_CONTEXT_COUNT]; PWelsCabacDecEngine pCabacDecEngine; double dDecTime; SDecoderStatistics* pDecoderStatistics; // For real time debugging int32_t iMbEcedNum; int32_t iMbEcedPropNum; int32_t iMbNum; bool bMbRefConcealed; bool bRPLRError; int32_t iECMVs[16][2]; PPicture pECRefPic[16]; unsignedlonglong uiTimeStamp; uint32_t uiDecodingTimeStamp; //represent relative decoding time stamps // To support scaling list HP uint16_t pDequant_coeff_buffer4x4[6][52][16]; uint16_t pDequant_coeff_buffer8x8[6][52][64]; uint16_t (*pDequant_coeff4x4[6])[16];// 4x4 sclaing list value pointer uint16_t (*pDequant_coeff8x8[6])[64];//64 residual coeff ,with 6 kinds of residual type, 52 qp level int iDequantCoeffPpsid;//When a new pps actived, reinitialised the scaling list value bool bDequantCoeff4x4Init; bool bUseScalingList; CMemoryAlign* pMemAlign; void* pThreadCtx; void* pLastThreadCtx; WELS_MUTEX* pCsDecoder; int16_t lastReadyHeightOffset[LIST_A][MAX_REF_PIC_COUNT]; //last ready reference MB offset PPictInfo pPictInfoList; PPictReoderingStatus pPictReoderingStatus; } SWelsDecoderContext, *PWelsDecoderContext;
解码参数
这里只可以指定目标空域,后面可以新增指定目标时域
1 2 3 4 5 6 7 8 9 10 11 12 13 14
/** * @brief SVC Decoding Parameters, reserved here and potential applicable in the future */ typedefstructTagSVCDecodingParam { char* pFileNameRestructed; ///< file name of reconstructed frame used for PSNR calculation based debug
unsignedint uiCpuLoad; ///< CPU load unsignedchar uiTargetDqLayer; ///< setting target dq layer id
ERROR_CON_IDC eEcActiveIdc; ///< whether active error concealment feature in decoder bool bParseOnly; ///< decoder for parse only, no reconstruction. When it is true, SPS/PPS size should not exceed SPS_PPS_BS_SIZE (128). Otherwise, it will return error info
SVideoProperty sVideoProperty; ///< video stream property } SDecodingParam, *PDecodingParam;
structSPicture { /************************************payload data*********************************/ uint8_t* pBuffer[4]; // pointer to the first allocated byte, basical offset of buffer, dimension: uint8_t* pData[4]; // pointer to picture planes respectively int32_t iLinesize[4];// linesize of picture planes respectively used currently int32_t iPlanes; // How many planes are introduced due to color space format? // picture information
/*******************************from other standard syntax****************************/ /*from sps*/ int32_t iWidthInPixel; // picture width in pixel int32_t iHeightInPixel;// picture height in pixel /*from slice header*/ int32_t iFramePoc; // frame POC
/*******************************sef_definition for misc use****************************/ bool bUsedAsRef; //for ref pic management bool bIsLongRef; // long term reference frame flag //for ref pic management int8_t iRefCount;
bool bIsComplete; // indicate whether current picture is complete, not from EC /*******************************for future use****************************/ uint8_t uiTemporalId; uint8_t uiSpatialId; uint8_t uiQualityId;
int32_t iFrameNum; // frame number //for ref pic management int32_t iFrameWrapNum; // frame wrap number //for ref pic management int32_t iLongTermFrameIdx; //id for long term ref pic uint32_t uiLongTermPicNum; //long_term_pic_num
int32_t iSpsId; //against mosaic caused by cross-IDR interval reference. int32_t iPpsId; unsignedlonglong uiTimeStamp; uint32_t uiDecodingTimeStamp; //represent relative decoding time stamps int32_t iPicBuffIdx; EWelsSliceType eSliceType; bool bIsUngroupedMultiSlice; //multi-slice picture with each each slice group contains one slice. bool bNewSeqBegin; int32_t iMbEcedNum; int32_t iMbEcedPropNum; int32_t iMbNum;
bool* pMbCorrectlyDecodedFlag; int8_t (*pNzc)[24]; uint32_t* pMbType; // mb type used for direct mode int16_t (*pMv[LIST_A])[MB_BLOCK4x4_NUM][MV_A]; // used for direct mode int8_t (*pRefIndex[LIST_A])[MB_BLOCK4x4_NUM]; //used for direct mode structSPicture* pRefPic[LIST_A][17]; //ref pictures used for direct mode SWelsDecEvent* pReadyEvent; //MB line ready event
};// "Picture" declaration is comflict with Mac system
typedefstructSPicture* PPicture;
AU结构
1 2 3 4 5 6 7 8 9 10
typedefstructTagAccessUnits { PNalUnit* pNalUnitsList; // list of NAL Units pointer in this AU uint32_t uiAvailUnitsNum; // Number of NAL Units available in each AU list based current bitstream, uint32_t uiActualUnitsNum; // actual number of NAL units belong to current au // While available number exceeds count size below, need realloc extra NAL Units for list space. uint32_t uiCountUnitsNum; // Count size number of malloced NAL Units in each AU list uint32_t uiStartPos; uint32_t uiEndPos; bool bCompletedAuFlag; // Indicate whether it is a completed AU } SAccessUnit, *PAccessUnit;
typedefstructTagDqLayer SDqLayer; typedef SDqLayer* PDqLayer; typedefstructTagLayerInfo { SNalUnitHeaderExt sNalHeaderExt; SSlice sSliceInLayer; // Here Slice identify to Frame on concept PSubsetSps pSubsetSps; // current pSubsetSps used, memory alloc in external PSps pSps; // current sps based avc used, memory alloc in external PPps pPps; // current pps used } SLayerInfo, *PLayerInfo; /* Layer Representation */
structTagDqLayer { SLayerInfo sLayerInfo;
PBitStringAux pBitStringAux; // pointer to SBitStringAux PFmo pFmo; // Current fmo context pointer used /* 从这里开始下面的指针,真实的内存空间位于解码器句柄的sMb结构 */ uint32_t* pMbType; int32_t* pSliceIdc; // using int32_t for slice_idc int16_t (*pMv[LIST_A])[MB_BLOCK4x4_NUM][MV_A]; int16_t (*pMvd[LIST_A])[MB_BLOCK4x4_NUM][MV_A]; int8_t (*pRefIndex[LIST_A])[MB_BLOCK4x4_NUM]; int8_t (*pDirect)[MB_BLOCK4x4_NUM]; bool* pNoSubMbPartSizeLessThan8x8Flag; bool* pTransformSize8x8Flag; int8_t* pLumaQp; int8_t (*pChromaQp)[2]; int8_t* pCbp; uint16_t *pCbfDc; int8_t (*pNzc)[24]; int8_t (*pNzcRs)[24]; int8_t* pResidualPredFlag; int8_t* pInterPredictionDoneFlag; bool* pMbCorrectlyDecodedFlag; bool* pMbRefConcealedFlag; int16_t (*pScaledTCoeff)[MB_COEFF_LIST_SIZE]; int8_t (*pIntraPredMode)[8]; //0~3 top4x4 ; 4~6 left 4x4; 7 intra16x16 int8_t (*pIntra4x4FinalMode)[MB_BLOCK4x4_NUM]; uint8_t *pIntraNxNAvailFlag; int8_t* pChromaPredMode; //uint8_t (*motion_pred_flag[LIST_A])[MB_PARTITION_SIZE]; // 8x8 uint32_t (*pSubMbType)[MB_SUB_PARTITION_SIZE]; int32_t iLumaStride; int32_t iChromaStride; uint8_t* pPred[3]; int32_t iMbX; int32_t iMbY; int32_t iMbXyIndex; int32_t iMbWidth; // MB width of this picture, equal to sSps.iMbWidth int32_t iMbHeight; // MB height of this picture, equal to sSps.iMbHeight; /* 以上内容来自解码器句柄的sMb结构 */
/* Common syntax elements across all slices of a DQLayer */ int32_t iSliceIdcBackup; uint32_t uiSpsId; uint32_t uiPpsId; uint32_t uiDisableInterLayerDeblockingFilterIdc; int32_t iInterLayerSliceAlphaC0Offset; int32_t iInterLayerSliceBetaOffset; //SPosOffset sScaledRefLayer; int32_t iSliceGroupChangeCycle;