|
|
|
@ -1303,6 +1303,8 @@ int32_t RequestMemorySvc (sWelsEncCtx** ppCtx) {
|
|
|
|
|
(*ppCtx)->pOut->uiSize = iCountBsLen;
|
|
|
|
|
(*ppCtx)->pOut->sNalList = (SWelsNalRaw*)pMa->WelsMalloc (iCountNals * sizeof (SWelsNalRaw), "pOut->sNalList");
|
|
|
|
|
WELS_VERIFY_RETURN_PROC_IF (1, (NULL == (*ppCtx)->pOut->sNalList), FreeMemorySvc (ppCtx))
|
|
|
|
|
(*ppCtx)->pOut->pNalLen = (int32_t*)pMa->WelsMallocz(iCountNals * sizeof (int32_t), "pOut->pNalLen");
|
|
|
|
|
WELS_VERIFY_RETURN_PROC_IF (1, (NULL == (*ppCtx)->pOut->pNalLen), FreeMemorySvc(ppCtx))
|
|
|
|
|
(*ppCtx)->pOut->iCountNals = iCountNals;
|
|
|
|
|
(*ppCtx)->pOut->iNalIndex = 0;
|
|
|
|
|
|
|
|
|
@ -1497,6 +1499,11 @@ void FreeMemorySvc (sWelsEncCtx** ppCtx) {
|
|
|
|
|
pMa->WelsFree (pCtx->pOut->sNalList, "pOut->sNalList");
|
|
|
|
|
pCtx->pOut->sNalList = NULL;
|
|
|
|
|
}
|
|
|
|
|
// NALs len
|
|
|
|
|
if (NULL != pCtx->pOut->pNalLen) {
|
|
|
|
|
pMa->WelsFree (pCtx->pOut->pNalLen, "pOut->pNalLen");
|
|
|
|
|
pCtx->pOut->pNalLen = NULL;
|
|
|
|
|
}
|
|
|
|
|
pMa->WelsFree (pCtx->pOut, "SWelsEncoderOutput");
|
|
|
|
|
pCtx->pOut = NULL;
|
|
|
|
|
}
|
|
|
|
@ -2733,7 +2740,6 @@ static inline int32_t AddPrefixNal (sWelsEncCtx* pCtx,
|
|
|
|
|
iPayloadSize = pNalLen[*pNalIdxInLayer];
|
|
|
|
|
|
|
|
|
|
pCtx->iPosBsBuffer += iPayloadSize;
|
|
|
|
|
pLayerBsInfo->iNalLengthInByte[*pNalIdxInLayer] = iPayloadSize;
|
|
|
|
|
|
|
|
|
|
(*pNalIdxInLayer) ++;
|
|
|
|
|
} else { // No Prefix NAL Unit RBSP syntax here, but need add NAL Unit Header extension
|
|
|
|
@ -2750,7 +2756,6 @@ static inline int32_t AddPrefixNal (sWelsEncCtx* pCtx,
|
|
|
|
|
iPayloadSize = pNalLen[*pNalIdxInLayer];
|
|
|
|
|
|
|
|
|
|
pCtx->iPosBsBuffer += iPayloadSize;
|
|
|
|
|
pLayerBsInfo->iNalLengthInByte[*pNalIdxInLayer] = iPayloadSize;
|
|
|
|
|
|
|
|
|
|
(*pNalIdxInLayer) ++;
|
|
|
|
|
}
|
|
|
|
@ -2816,13 +2821,13 @@ int32_t ForceCodingIDR (sWelsEncCtx* pCtx) {
|
|
|
|
|
int32_t WelsEncoderEncodeParameterSets (sWelsEncCtx* pCtx, void* pDst) {
|
|
|
|
|
SFrameBSInfo* pFbi = (SFrameBSInfo*)pDst;
|
|
|
|
|
SLayerBSInfo* pLayerBsInfo = &pFbi->sLayerInfo[0];
|
|
|
|
|
int32_t iNalLen[128] = {0};
|
|
|
|
|
int32_t iCountNal = 0;
|
|
|
|
|
|
|
|
|
|
pLayerBsInfo->pBsBuf = pCtx->pFrameBs;
|
|
|
|
|
pLayerBsInfo->pNalLengthInByte = pCtx->pOut->pNalLen;
|
|
|
|
|
InitBits (&pCtx->pOut->sBsWrite, pCtx->pOut->pBsBuffer, pCtx->pOut->uiSize);
|
|
|
|
|
|
|
|
|
|
int32_t iReturn = WelsWriteParameterSets (pCtx, &iNalLen[0], &iCountNal);
|
|
|
|
|
int32_t iReturn = WelsWriteParameterSets (pCtx, &pLayerBsInfo->pNalLengthInByte[0], &iCountNal);
|
|
|
|
|
WELS_VERIFY_RETURN_IFNEQ (iReturn, ENC_RETURN_SUCCESS)
|
|
|
|
|
|
|
|
|
|
pLayerBsInfo->uiPriorityId = 0;
|
|
|
|
@ -2831,9 +2836,6 @@ int32_t WelsEncoderEncodeParameterSets (sWelsEncCtx* pCtx, void* pDst) {
|
|
|
|
|
pLayerBsInfo->uiQualityId = 0;
|
|
|
|
|
pLayerBsInfo->uiLayerType = NON_VIDEO_CODING_LAYER;
|
|
|
|
|
pLayerBsInfo->iNalCount = iCountNal;
|
|
|
|
|
for (int32_t iNalIndex = 0; iNalIndex < iCountNal; ++ iNalIndex) {
|
|
|
|
|
pLayerBsInfo->iNalLengthInByte[iNalIndex] = iNalLen[iNalIndex];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pCtx->eLastNalPriority = NRI_PRI_HIGHEST;
|
|
|
|
|
pFbi->iLayerNum = 1;
|
|
|
|
@ -2865,7 +2867,6 @@ int32_t WelsEncoderEncodeExt (sWelsEncCtx* pCtx, SFrameBSInfo* pFbi, const SSour
|
|
|
|
|
int32_t iSpatialNum = 0; // available count number of spatial layers due to frame size changed in this given frame
|
|
|
|
|
int32_t iSpatialIdx = 0; // iIndex of spatial layers due to frame size changed in this given frame
|
|
|
|
|
int32_t iFrameSize = 0;
|
|
|
|
|
int32_t iNalLen[128] = {0};
|
|
|
|
|
int32_t iNalIdxInLayer = 0;
|
|
|
|
|
int32_t iCountNal = 0;
|
|
|
|
|
EVideoFrameType eFrameType = videoFrameTypeInvalid;
|
|
|
|
@ -2909,13 +2910,14 @@ int32_t WelsEncoderEncodeExt (sWelsEncCtx* pCtx, SFrameBSInfo* pFbi, const SSour
|
|
|
|
|
pCtx->uiTemporalId = iCurTid;
|
|
|
|
|
|
|
|
|
|
pLayerBsInfo->pBsBuf = pCtx->pFrameBs ;
|
|
|
|
|
pLayerBsInfo->pNalLengthInByte = pCtx->pOut->pNalLen;
|
|
|
|
|
|
|
|
|
|
if (eFrameType == videoFrameTypeIDR) {
|
|
|
|
|
++ pCtx->sPSOVector.uiIdrPicId;
|
|
|
|
|
//if ( pSvcParam->bEnableSSEI )
|
|
|
|
|
|
|
|
|
|
// write parameter sets bitstream here
|
|
|
|
|
pCtx->iEncoderError = WelsWriteParameterSets (pCtx, &iNalLen[0], &iCountNal);
|
|
|
|
|
pCtx->iEncoderError = WelsWriteParameterSets (pCtx, &pLayerBsInfo->pNalLengthInByte[0], &iCountNal);
|
|
|
|
|
WELS_VERIFY_RETURN_IFNEQ (pCtx->iEncoderError, ENC_RETURN_SUCCESS)
|
|
|
|
|
|
|
|
|
|
pLayerBsInfo->uiPriorityId = 0;
|
|
|
|
@ -2924,12 +2926,10 @@ int32_t WelsEncoderEncodeExt (sWelsEncCtx* pCtx, SFrameBSInfo* pFbi, const SSour
|
|
|
|
|
pLayerBsInfo->uiQualityId = 0;
|
|
|
|
|
pLayerBsInfo->uiLayerType = NON_VIDEO_CODING_LAYER;
|
|
|
|
|
pLayerBsInfo->iNalCount = iCountNal;
|
|
|
|
|
for (int32_t iNalIndex = 0; iNalIndex < iCountNal; ++ iNalIndex) {
|
|
|
|
|
pLayerBsInfo->iNalLengthInByte[iNalIndex] = iNalLen[iNalIndex];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
++ pLayerBsInfo;
|
|
|
|
|
pLayerBsInfo->pBsBuf = pCtx->pFrameBs + pCtx->iPosBsBuffer;
|
|
|
|
|
pLayerBsInfo->pNalLengthInByte = (pLayerBsInfo - 1)->pNalLengthInByte + iCountNal;
|
|
|
|
|
++ iLayerNum;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -3050,7 +3050,7 @@ int32_t WelsEncoderEncodeExt (sWelsEncCtx* pCtx, SFrameBSInfo* pFbi, const SSour
|
|
|
|
|
int32_t iPayloadSize = 0;
|
|
|
|
|
|
|
|
|
|
if (pCtx->bNeedPrefixNalFlag) {
|
|
|
|
|
pCtx->iEncoderError = AddPrefixNal (pCtx, pLayerBsInfo, &iNalLen[0], &iNalIdxInLayer, eNalType, eNalRefIdc,
|
|
|
|
|
pCtx->iEncoderError = AddPrefixNal (pCtx, pLayerBsInfo, &pLayerBsInfo->pNalLengthInByte[0], &iNalIdxInLayer, eNalType, eNalRefIdc,
|
|
|
|
|
iPayloadSize);
|
|
|
|
|
WELS_VERIFY_RETURN_IFNEQ (pCtx->iEncoderError, ENC_RETURN_SUCCESS)
|
|
|
|
|
iLayerSize += iPayloadSize;
|
|
|
|
@ -3067,9 +3067,9 @@ int32_t WelsEncoderEncodeExt (sWelsEncCtx* pCtx, SFrameBSInfo* pFbi, const SSour
|
|
|
|
|
&pCtx->pCurDqLayer->sLayerInfo.sNalHeaderExt,
|
|
|
|
|
pCtx->iFrameBsSize - pCtx->iPosBsBuffer,
|
|
|
|
|
pCtx->pFrameBs + pCtx->iPosBsBuffer,
|
|
|
|
|
&iNalLen[iNalIdxInLayer]);
|
|
|
|
|
&pLayerBsInfo->pNalLengthInByte[iNalIdxInLayer]);
|
|
|
|
|
WELS_VERIFY_RETURN_IFNEQ (pCtx->iEncoderError, ENC_RETURN_SUCCESS)
|
|
|
|
|
iSliceSize = iNalLen[iNalIdxInLayer];
|
|
|
|
|
iSliceSize = pLayerBsInfo->pNalLengthInByte[iNalIdxInLayer];
|
|
|
|
|
|
|
|
|
|
iLayerSize += iSliceSize;
|
|
|
|
|
pCtx->iPosBsBuffer += iSliceSize;
|
|
|
|
@ -3078,7 +3078,6 @@ int32_t WelsEncoderEncodeExt (sWelsEncCtx* pCtx, SFrameBSInfo* pFbi, const SSour
|
|
|
|
|
pLayerBsInfo->uiTemporalId = iCurTid;
|
|
|
|
|
pLayerBsInfo->uiQualityId = 0;
|
|
|
|
|
pLayerBsInfo->uiPriorityId = 0;
|
|
|
|
|
pLayerBsInfo->iNalLengthInByte[iNalIdxInLayer] = iSliceSize;
|
|
|
|
|
pLayerBsInfo->iNalCount = ++ iNalIdxInLayer;
|
|
|
|
|
}
|
|
|
|
|
// for dynamic slicing single threading..
|
|
|
|
@ -3221,7 +3220,7 @@ int32_t WelsEncoderEncodeExt (sWelsEncCtx* pCtx, SFrameBSInfo* pFbi, const SSour
|
|
|
|
|
int32_t iSliceSize = 0;
|
|
|
|
|
int32_t iPayloadSize = 0;
|
|
|
|
|
if (bNeedPrefix) {
|
|
|
|
|
pCtx->iEncoderError = AddPrefixNal (pCtx, pLayerBsInfo, &iNalLen[0], &iNalIdxInLayer, eNalType, eNalRefIdc,
|
|
|
|
|
pCtx->iEncoderError = AddPrefixNal (pCtx, pLayerBsInfo, &pLayerBsInfo->pNalLengthInByte[0], &iNalIdxInLayer, eNalType, eNalRefIdc,
|
|
|
|
|
iPayloadSize);
|
|
|
|
|
WELS_VERIFY_RETURN_IFNEQ (pCtx->iEncoderError, ENC_RETURN_SUCCESS)
|
|
|
|
|
iLayerSize += iPayloadSize;
|
|
|
|
@ -3236,13 +3235,12 @@ int32_t WelsEncoderEncodeExt (sWelsEncCtx* pCtx, SFrameBSInfo* pFbi, const SSour
|
|
|
|
|
pCtx->iEncoderError = WelsEncodeNal (&pCtx->pOut->sNalList[pCtx->pOut->iNalIndex - 1],
|
|
|
|
|
&pCtx->pCurDqLayer->sLayerInfo.sNalHeaderExt,
|
|
|
|
|
pCtx->iFrameBsSize - pCtx->iPosBsBuffer,
|
|
|
|
|
pCtx->pFrameBs + pCtx->iPosBsBuffer, &iNalLen[iNalIdxInLayer]);
|
|
|
|
|
pCtx->pFrameBs + pCtx->iPosBsBuffer, &pLayerBsInfo->pNalLengthInByte[iNalIdxInLayer]);
|
|
|
|
|
WELS_VERIFY_RETURN_IFNEQ (pCtx->iEncoderError, ENC_RETURN_SUCCESS)
|
|
|
|
|
iSliceSize = iNalLen[iNalIdxInLayer];
|
|
|
|
|
iSliceSize = pLayerBsInfo->pNalLengthInByte[iNalIdxInLayer];
|
|
|
|
|
|
|
|
|
|
pCtx->iPosBsBuffer += iSliceSize;
|
|
|
|
|
iLayerSize += iSliceSize;
|
|
|
|
|
pLayerBsInfo->iNalLengthInByte[iNalIdxInLayer] = iSliceSize;
|
|
|
|
|
|
|
|
|
|
#if defined(SLICE_INFO_OUTPUT)
|
|
|
|
|
fprintf (stderr,
|
|
|
|
@ -3374,10 +3372,12 @@ int32_t WelsEncoderEncodeExt (sWelsEncCtx* pCtx, SFrameBSInfo* pFbi, const SSour
|
|
|
|
|
}
|
|
|
|
|
#endif//STAT_OUTPUT
|
|
|
|
|
|
|
|
|
|
iCountNal = pLayerBsInfo->iNalCount;
|
|
|
|
|
++ iLayerNum;
|
|
|
|
|
++ pLayerBsInfo;
|
|
|
|
|
|
|
|
|
|
pLayerBsInfo->pBsBuf = pCtx->pFrameBs + pCtx->iPosBsBuffer;
|
|
|
|
|
pLayerBsInfo->pNalLengthInByte = (pLayerBsInfo - 1)->pNalLengthInByte + iCountNal;
|
|
|
|
|
|
|
|
|
|
if (pSvcParam->iPaddingFlag && pCtx->pWelsSvcRc[pCtx->uiDependencyId].iPaddingSize > 0) {
|
|
|
|
|
int32_t iPaddingNalSize = 0;
|
|
|
|
@ -3401,9 +3401,10 @@ int32_t WelsEncoderEncodeExt (sWelsEncCtx* pCtx, SFrameBSInfo* pFbi, const SSour
|
|
|
|
|
pLayerBsInfo->uiQualityId = 0;
|
|
|
|
|
pLayerBsInfo->uiLayerType = NON_VIDEO_CODING_LAYER;
|
|
|
|
|
pLayerBsInfo->iNalCount = 1;
|
|
|
|
|
pLayerBsInfo->iNalLengthInByte[0] = iPaddingNalSize;
|
|
|
|
|
pLayerBsInfo->pNalLengthInByte[0] = iPaddingNalSize;
|
|
|
|
|
++ pLayerBsInfo;
|
|
|
|
|
pLayerBsInfo->pBsBuf = pCtx->pFrameBs + pCtx->iPosBsBuffer;
|
|
|
|
|
pLayerBsInfo->pNalLengthInByte = (pLayerBsInfo - 1)->pNalLengthInByte + 1;
|
|
|
|
|
++ iLayerNum;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -3657,7 +3658,6 @@ int32_t WelsCodeOnePicPartition (sWelsEncCtx* pCtx,
|
|
|
|
|
|
|
|
|
|
SDqLayer* pCurLayer = pCtx->pCurDqLayer;
|
|
|
|
|
SSliceCtx* pSliceCtx = pCurLayer->pSliceEncCtx;
|
|
|
|
|
int32_t iNalLen[MAX_NAL_UNITS_IN_LAYER] = {0};
|
|
|
|
|
int32_t iNalIdxInLayer = *pNalIdxInLayer;
|
|
|
|
|
int32_t iSliceIdx = iStartSliceIdx;
|
|
|
|
|
const int32_t kiSliceStep = pCtx->iActiveThreadsNum;
|
|
|
|
@ -3688,7 +3688,7 @@ int32_t WelsCodeOnePicPartition (sWelsEncCtx* pCtx,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (kbNeedPrefix) {
|
|
|
|
|
iReturn = AddPrefixNal (pCtx, pLayerBsInfo, &iNalLen[0], &iNalIdxInLayer, keNalType, keNalRefIdc, iPayloadSize);
|
|
|
|
|
iReturn = AddPrefixNal (pCtx, pLayerBsInfo, &pLayerBsInfo->pNalLengthInByte[0], &iNalIdxInLayer, keNalType, keNalRefIdc, iPayloadSize);
|
|
|
|
|
WELS_VERIFY_RETURN_IFNEQ (iReturn, ENC_RETURN_SUCCESS)
|
|
|
|
|
iPartitionBsSize += iPayloadSize;
|
|
|
|
|
}
|
|
|
|
@ -3702,13 +3702,12 @@ int32_t WelsCodeOnePicPartition (sWelsEncCtx* pCtx,
|
|
|
|
|
&pCtx->pCurDqLayer->sLayerInfo.sNalHeaderExt,
|
|
|
|
|
pCtx->iFrameBsSize - pCtx->iPosBsBuffer,
|
|
|
|
|
pCtx->pFrameBs + pCtx->iPosBsBuffer,
|
|
|
|
|
&iNalLen[iNalIdxInLayer]);
|
|
|
|
|
&pLayerBsInfo->pNalLengthInByte[iNalIdxInLayer]);
|
|
|
|
|
WELS_VERIFY_RETURN_IFNEQ (iReturn, ENC_RETURN_SUCCESS)
|
|
|
|
|
iSliceSize = iNalLen[iNalIdxInLayer];
|
|
|
|
|
iSliceSize = pLayerBsInfo->pNalLengthInByte[iNalIdxInLayer];
|
|
|
|
|
|
|
|
|
|
pCtx->iPosBsBuffer += iSliceSize;
|
|
|
|
|
iPartitionBsSize += iSliceSize;
|
|
|
|
|
pLayerBsInfo->iNalLengthInByte[iNalIdxInLayer] = iSliceSize;
|
|
|
|
|
|
|
|
|
|
#if defined(SLICE_INFO_OUTPUT)
|
|
|
|
|
fprintf (stderr,
|
|
|
|
|