Showing the changes to codec/encoder/core/src/encoder_ext.cpp (1 of 8 files). Show all
Unified · Split
| @@ -1303,6 +1303,8 @@ int32_t RequestMemorySvc (sWelsEncCtx** ppCtx) { · 1302 unmodified lines | ||
| 1303 | 1303 | (*ppCtx)->pOut->uiSize = iCountBsLen; |
| 1304 | 1304 | (*ppCtx)->pOut->sNalList = (SWelsNalRaw*)pMa->WelsMalloc (iCountNals * sizeof (SWelsNalRaw), "pOut->sNalList"); |
| 1305 | 1305 | WELS_VERIFY_RETURN_PROC_IF (1, (NULL == (*ppCtx)->pOut->sNalList), FreeMemorySvc (ppCtx)) |
| 1306 | + (*ppCtx)->pOut->pNalLen = (int32_t*)pMa->WelsMallocz(iCountNals * sizeof (int32_t), "pOut->pNalLen"); | |
| 1307 | + WELS_VERIFY_RETURN_PROC_IF (1, (NULL == (*ppCtx)->pOut->pNalLen), FreeMemorySvc(ppCtx)) | |
| 1306 | 1308 | (*ppCtx)->pOut->iCountNals = iCountNals; |
| 1307 | 1309 | (*ppCtx)->pOut->iNalIndex = 0; |
| 1308 | 1310 | |
| @@ -1497,6 +1499,11 @@ void FreeMemorySvc (sWelsEncCtx** ppCtx) { · 188 unmodified lines | ||
| 1497 | 1499 | pMa->WelsFree (pCtx->pOut->sNalList, "pOut->sNalList"); |
| 1498 | 1500 | pCtx->pOut->sNalList = NULL; |
| 1499 | 1501 | } |
| 1502 | + // NALs len | |
| 1503 | + if (NULL != pCtx->pOut->pNalLen) { | |
| 1504 | + pMa->WelsFree (pCtx->pOut->pNalLen, "pOut->pNalLen"); | |
| 1505 | + pCtx->pOut->pNalLen = NULL; | |
| 1506 | + } | |
| 1500 | 1507 | pMa->WelsFree (pCtx->pOut, "SWelsEncoderOutput"); |
| 1501 | 1508 | pCtx->pOut = NULL; |
| 1502 | 1509 | } |
| @@ -2733,7 +2740,6 @@ static inline int32_t AddPrefixNal (sWelsEncCtx* pCtx, · 1230 unmodified lines | ||
| 2733 | 2740 | iPayloadSize = pNalLen[*pNalIdxInLayer]; |
| 2734 | 2741 | |
| 2735 | 2742 | pCtx->iPosBsBuffer += iPayloadSize; |
| 2736 | − pLayerBsInfo->iNalLengthInByte[*pNalIdxInLayer] = iPayloadSize; | |
| 2737 | 2743 | |
| 2738 | 2744 | (*pNalIdxInLayer) ++; |
| 2739 | 2745 | } 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, · 10 unmodified lines | ||
| 2750 | 2756 | iPayloadSize = pNalLen[*pNalIdxInLayer]; |
| 2751 | 2757 | |
| 2752 | 2758 | pCtx->iPosBsBuffer += iPayloadSize; |
| 2753 | − pLayerBsInfo->iNalLengthInByte[*pNalIdxInLayer] = iPayloadSize; | |
| 2754 | 2759 | |
| 2755 | 2760 | (*pNalIdxInLayer) ++; |
| 2756 | 2761 | } |
| @@ -2816,13 +2821,13 @@ int32_t ForceCodingIDR (sWelsEncCtx* pCtx) { · 59 unmodified lines | ||
| 2816 | 2821 | int32_t WelsEncoderEncodeParameterSets (sWelsEncCtx* pCtx, void* pDst) { |
| 2817 | 2822 | SFrameBSInfo* pFbi = (SFrameBSInfo*)pDst; |
| 2818 | 2823 | SLayerBSInfo* pLayerBsInfo = &pFbi->sLayerInfo[0]; |
| 2819 | − int32_t iNalLen[128] = {0}; | |
| 2820 | 2824 | int32_t iCountNal = 0; |
| 2821 | 2825 | |
| 2822 | 2826 | pLayerBsInfo->pBsBuf = pCtx->pFrameBs; |
| 2827 | + pLayerBsInfo->pNalLengthInByte = pCtx->pOut->pNalLen; | |
| 2823 | 2828 | InitBits (&pCtx->pOut->sBsWrite, pCtx->pOut->pBsBuffer, pCtx->pOut->uiSize); |
| 2824 | 2829 | |
| 2825 | − int32_t iReturn = WelsWriteParameterSets (pCtx, &iNalLen[0], &iCountNal); | |
| 2830 | + int32_t iReturn = WelsWriteParameterSets (pCtx, &pLayerBsInfo->pNalLengthInByte[0], &iCountNal); | |
| 2826 | 2831 | WELS_VERIFY_RETURN_IFNEQ (iReturn, ENC_RETURN_SUCCESS) |
| 2827 | 2832 | |
| 2828 | 2833 | pLayerBsInfo->uiPriorityId = 0; |
| @@ -2831,9 +2836,6 @@ int32_t WelsEncoderEncodeParameterSets (sWelsEncCtx* pCtx, void* pDst) { · 2 unmodified lines | ||
| 2831 | 2836 | pLayerBsInfo->uiQualityId = 0; |
| 2832 | 2837 | pLayerBsInfo->uiLayerType = NON_VIDEO_CODING_LAYER; |
| 2833 | 2838 | pLayerBsInfo->iNalCount = iCountNal; |
| 2834 | − for (int32_t iNalIndex = 0; iNalIndex < iCountNal; ++ iNalIndex) { | |
| 2835 | − pLayerBsInfo->iNalLengthInByte[iNalIndex] = iNalLen[iNalIndex]; | |
| 2836 | − } | |
| 2837 | 2839 | |
| 2838 | 2840 | pCtx->eLastNalPriority = NRI_PRI_HIGHEST; |
| 2839 | 2841 | pFbi->iLayerNum = 1; |
| @@ -2865,7 +2867,6 @@ int32_t WelsEncoderEncodeExt (sWelsEncCtx* pCtx, SFrameBSInfo* pFbi, const SSour · 25 unmodified lines | ||
| 2865 | 2867 | int32_t iSpatialNum = 0; // available count number of spatial layers due to frame size changed in this given frame |
| 2866 | 2868 | int32_t iSpatialIdx = 0; // iIndex of spatial layers due to frame size changed in this given frame |
| 2867 | 2869 | int32_t iFrameSize = 0; |
| 2868 | − int32_t iNalLen[128] = {0}; | |
| 2869 | 2870 | int32_t iNalIdxInLayer = 0; |
| 2870 | 2871 | int32_t iCountNal = 0; |
| 2871 | 2872 | EVideoFrameType eFrameType = videoFrameTypeInvalid; |
| @@ -2909,13 +2910,14 @@ int32_t WelsEncoderEncodeExt (sWelsEncCtx* pCtx, SFrameBSInfo* pFbi, const SSour · 37 unmodified lines | ||
| 2909 | 2910 | pCtx->uiTemporalId = iCurTid; |
| 2910 | 2911 | |
| 2911 | 2912 | pLayerBsInfo->pBsBuf = pCtx->pFrameBs ; |
| 2913 | + pLayerBsInfo->pNalLengthInByte = pCtx->pOut->pNalLen; | |
| 2912 | 2914 | |
| 2913 | 2915 | if (eFrameType == videoFrameTypeIDR) { |
| 2914 | 2916 | ++ pCtx->sPSOVector.uiIdrPicId; |
| 2915 | 2917 | //if ( pSvcParam->bEnableSSEI ) |
| 2916 | 2918 | |
| 2917 | 2919 | // write parameter sets bitstream here |
| 2918 | − pCtx->iEncoderError = WelsWriteParameterSets (pCtx, &iNalLen[0], &iCountNal); | |
| 2920 | + pCtx->iEncoderError = WelsWriteParameterSets (pCtx, &pLayerBsInfo->pNalLengthInByte[0], &iCountNal); | |
| 2919 | 2921 | WELS_VERIFY_RETURN_IFNEQ (pCtx->iEncoderError, ENC_RETURN_SUCCESS) |
| 2920 | 2922 | |
| 2921 | 2923 | pLayerBsInfo->uiPriorityId = 0; |
| @@ -2924,12 +2926,10 @@ int32_t WelsEncoderEncodeExt (sWelsEncCtx* pCtx, SFrameBSInfo* pFbi, const SSour · 2 unmodified lines | ||
| 2924 | 2926 | pLayerBsInfo->uiQualityId = 0; |
| 2925 | 2927 | pLayerBsInfo->uiLayerType = NON_VIDEO_CODING_LAYER; |
| 2926 | 2928 | pLayerBsInfo->iNalCount = iCountNal; |
| 2927 | − for (int32_t iNalIndex = 0; iNalIndex < iCountNal; ++ iNalIndex) { | |
| 2928 | − pLayerBsInfo->iNalLengthInByte[iNalIndex] = iNalLen[iNalIndex]; | |
| 2929 | − } | |
| 2930 | 2929 | |
| 2931 | 2930 | ++ pLayerBsInfo; |
| 2932 | 2931 | pLayerBsInfo->pBsBuf = pCtx->pFrameBs + pCtx->iPosBsBuffer; |
| 2932 | + pLayerBsInfo->pNalLengthInByte = (pLayerBsInfo - 1)->pNalLengthInByte + iCountNal; | |
| 2933 | 2933 | ++ iLayerNum; |
| 2934 | 2934 | } |
| 2935 | 2935 | |
| @@ -3050,7 +3050,7 @@ int32_t WelsEncoderEncodeExt (sWelsEncCtx* pCtx, SFrameBSInfo* pFbi, const SSour · 114 unmodified lines | ||
| 3050 | 3050 | int32_t iPayloadSize = 0; |
| 3051 | 3051 | |
| 3052 | 3052 | if (pCtx->bNeedPrefixNalFlag) { |
| 3053 | − pCtx->iEncoderError = AddPrefixNal (pCtx, pLayerBsInfo, &iNalLen[0], &iNalIdxInLayer, eNalType, eNalRefIdc, | |
| 3053 | + pCtx->iEncoderError = AddPrefixNal (pCtx, pLayerBsInfo, &pLayerBsInfo->pNalLengthInByte[0], &iNalIdxInLayer, eNalType, eNalRefIdc, | |
| 3054 | 3054 | iPayloadSize); |
| 3055 | 3055 | WELS_VERIFY_RETURN_IFNEQ (pCtx->iEncoderError, ENC_RETURN_SUCCESS) |
| 3056 | 3056 | iLayerSize += iPayloadSize; |
| @@ -3067,9 +3067,9 @@ int32_t WelsEncoderEncodeExt (sWelsEncCtx* pCtx, SFrameBSInfo* pFbi, const SSour · 10 unmodified lines | ||
| 3067 | 3067 | &pCtx->pCurDqLayer->sLayerInfo.sNalHeaderExt, |
| 3068 | 3068 | pCtx->iFrameBsSize - pCtx->iPosBsBuffer, |
| 3069 | 3069 | pCtx->pFrameBs + pCtx->iPosBsBuffer, |
| 3070 | − &iNalLen[iNalIdxInLayer]); | |
| 3070 | + &pLayerBsInfo->pNalLengthInByte[iNalIdxInLayer]); | |
| 3071 | 3071 | WELS_VERIFY_RETURN_IFNEQ (pCtx->iEncoderError, ENC_RETURN_SUCCESS) |
| 3072 | − iSliceSize = iNalLen[iNalIdxInLayer]; | |
| 3072 | + iSliceSize = pLayerBsInfo->pNalLengthInByte[iNalIdxInLayer]; | |
| 3073 | 3073 | |
| 3074 | 3074 | iLayerSize += iSliceSize; |
| 3075 | 3075 | pCtx->iPosBsBuffer += iSliceSize; |
| @@ -3078,7 +3078,6 @@ int32_t WelsEncoderEncodeExt (sWelsEncCtx* pCtx, SFrameBSInfo* pFbi, const SSour · 2 unmodified lines | ||
| 3078 | 3078 | pLayerBsInfo->uiTemporalId = iCurTid; |
| 3079 | 3079 | pLayerBsInfo->uiQualityId = 0; |
| 3080 | 3080 | pLayerBsInfo->uiPriorityId = 0; |
| 3081 | − pLayerBsInfo->iNalLengthInByte[iNalIdxInLayer] = iSliceSize; | |
| 3082 | 3081 | pLayerBsInfo->iNalCount = ++ iNalIdxInLayer; |
| 3083 | 3082 | } |
| 3084 | 3083 | // for dynamic slicing single threading.. |
| @@ -3221,7 +3220,7 @@ int32_t WelsEncoderEncodeExt (sWelsEncCtx* pCtx, SFrameBSInfo* pFbi, const SSour · 136 unmodified lines | ||
| 3221 | 3220 | int32_t iSliceSize = 0; |
| 3222 | 3221 | int32_t iPayloadSize = 0; |
| 3223 | 3222 | if (bNeedPrefix) { |
| 3224 | − pCtx->iEncoderError = AddPrefixNal (pCtx, pLayerBsInfo, &iNalLen[0], &iNalIdxInLayer, eNalType, eNalRefIdc, | |
| 3223 | + pCtx->iEncoderError = AddPrefixNal (pCtx, pLayerBsInfo, &pLayerBsInfo->pNalLengthInByte[0], &iNalIdxInLayer, eNalType, eNalRefIdc, | |
| 3225 | 3224 | iPayloadSize); |
| 3226 | 3225 | WELS_VERIFY_RETURN_IFNEQ (pCtx->iEncoderError, ENC_RETURN_SUCCESS) |
| 3227 | 3226 | iLayerSize += iPayloadSize; |
| @@ -3236,13 +3235,12 @@ int32_t WelsEncoderEncodeExt (sWelsEncCtx* pCtx, SFrameBSInfo* pFbi, const SSour · 8 unmodified lines | ||
| 3236 | 3235 | pCtx->iEncoderError = WelsEncodeNal (&pCtx->pOut->sNalList[pCtx->pOut->iNalIndex - 1], |
| 3237 | 3236 | &pCtx->pCurDqLayer->sLayerInfo.sNalHeaderExt, |
| 3238 | 3237 | pCtx->iFrameBsSize - pCtx->iPosBsBuffer, |
| 3239 | − pCtx->pFrameBs + pCtx->iPosBsBuffer, &iNalLen[iNalIdxInLayer]); | |
| 3238 | + pCtx->pFrameBs + pCtx->iPosBsBuffer, &pLayerBsInfo->pNalLengthInByte[iNalIdxInLayer]); | |
| 3240 | 3239 | WELS_VERIFY_RETURN_IFNEQ (pCtx->iEncoderError, ENC_RETURN_SUCCESS) |
| 3241 | − iSliceSize = iNalLen[iNalIdxInLayer]; | |
| 3240 | + iSliceSize = pLayerBsInfo->pNalLengthInByte[iNalIdxInLayer]; | |
| 3242 | 3241 | |
| 3243 | 3242 | pCtx->iPosBsBuffer += iSliceSize; |
| 3244 | 3243 | iLayerSize += iSliceSize; |
| 3245 | − pLayerBsInfo->iNalLengthInByte[iNalIdxInLayer] = iSliceSize; | |
| 3246 | 3244 | |
| 3247 | 3245 | #if defined(SLICE_INFO_OUTPUT) |
| 3248 | 3246 | fprintf (stderr, |
| @@ -3374,10 +3372,12 @@ int32_t WelsEncoderEncodeExt (sWelsEncCtx* pCtx, SFrameBSInfo* pFbi, const SSour · 125 unmodified lines | ||
| 3374 | 3372 | } |
| 3375 | 3373 | #endif//STAT_OUTPUT |
| 3376 | 3374 | |
| 3375 | + iCountNal = pLayerBsInfo->iNalCount; | |
| 3377 | 3376 | ++ iLayerNum; |
| 3378 | 3377 | ++ pLayerBsInfo; |
| 3379 | 3378 | |
| 3380 | 3379 | pLayerBsInfo->pBsBuf = pCtx->pFrameBs + pCtx->iPosBsBuffer; |
| 3380 | + pLayerBsInfo->pNalLengthInByte = (pLayerBsInfo - 1)->pNalLengthInByte + iCountNal; | |
| 3381 | 3381 | |
| 3382 | 3382 | if (pSvcParam->iPaddingFlag && pCtx->pWelsSvcRc[pCtx->uiDependencyId].iPaddingSize > 0) { |
| 3383 | 3383 | int32_t iPaddingNalSize = 0; |
| @@ -3401,9 +3401,10 @@ int32_t WelsEncoderEncodeExt (sWelsEncCtx* pCtx, SFrameBSInfo* pFbi, const SSour · 17 unmodified lines | ||
| 3401 | 3401 | pLayerBsInfo->uiQualityId = 0; |
| 3402 | 3402 | pLayerBsInfo->uiLayerType = NON_VIDEO_CODING_LAYER; |
| 3403 | 3403 | pLayerBsInfo->iNalCount = 1; |
| 3404 | − pLayerBsInfo->iNalLengthInByte[0] = iPaddingNalSize; | |
| 3404 | + pLayerBsInfo->pNalLengthInByte[0] = iPaddingNalSize; | |
| 3405 | 3405 | ++ pLayerBsInfo; |
| 3406 | 3406 | pLayerBsInfo->pBsBuf = pCtx->pFrameBs + pCtx->iPosBsBuffer; |
| 3407 | + pLayerBsInfo->pNalLengthInByte = (pLayerBsInfo - 1)->pNalLengthInByte + 1; | |
| 3407 | 3408 | ++ iLayerNum; |
| 3408 | 3409 | } |
| 3409 | 3410 | |
| @@ -3657,7 +3658,6 @@ int32_t WelsCodeOnePicPartition (sWelsEncCtx* pCtx, · 247 unmodified lines | ||
| 3657 | 3658 | |
| 3658 | 3659 | SDqLayer* pCurLayer = pCtx->pCurDqLayer; |
| 3659 | 3660 | SSliceCtx* pSliceCtx = pCurLayer->pSliceEncCtx; |
| 3660 | − int32_t iNalLen[MAX_NAL_UNITS_IN_LAYER] = {0}; | |
| 3661 | 3661 | int32_t iNalIdxInLayer = *pNalIdxInLayer; |
| 3662 | 3662 | int32_t iSliceIdx = iStartSliceIdx; |
| 3663 | 3663 | const int32_t kiSliceStep = pCtx->iActiveThreadsNum; |
| @@ -3688,7 +3688,7 @@ int32_t WelsCodeOnePicPartition (sWelsEncCtx* pCtx, · 24 unmodified lines | ||
| 3688 | 3688 | } |
| 3689 | 3689 | |
| 3690 | 3690 | if (kbNeedPrefix) { |
| 3691 | − iReturn = AddPrefixNal (pCtx, pLayerBsInfo, &iNalLen[0], &iNalIdxInLayer, keNalType, keNalRefIdc, iPayloadSize); | |
| 3691 | + iReturn = AddPrefixNal (pCtx, pLayerBsInfo, &pLayerBsInfo->pNalLengthInByte[0], &iNalIdxInLayer, keNalType, keNalRefIdc, iPayloadSize); | |
| 3692 | 3692 | WELS_VERIFY_RETURN_IFNEQ (iReturn, ENC_RETURN_SUCCESS) |
| 3693 | 3693 | iPartitionBsSize += iPayloadSize; |
| 3694 | 3694 | } |
| @@ -3702,13 +3702,12 @@ int32_t WelsCodeOnePicPartition (sWelsEncCtx* pCtx, · 7 unmodified lines | ||
| 3702 | 3702 | &pCtx->pCurDqLayer->sLayerInfo.sNalHeaderExt, |
| 3703 | 3703 | pCtx->iFrameBsSize - pCtx->iPosBsBuffer, |
| 3704 | 3704 | pCtx->pFrameBs + pCtx->iPosBsBuffer, |
| 3705 | − &iNalLen[iNalIdxInLayer]); | |
| 3705 | + &pLayerBsInfo->pNalLengthInByte[iNalIdxInLayer]); | |
| 3706 | 3706 | WELS_VERIFY_RETURN_IFNEQ (iReturn, ENC_RETURN_SUCCESS) |
| 3707 | − iSliceSize = iNalLen[iNalIdxInLayer]; | |
| 3707 | + iSliceSize = pLayerBsInfo->pNalLengthInByte[iNalIdxInLayer]; | |
| 3708 | 3708 | |
| 3709 | 3709 | pCtx->iPosBsBuffer += iSliceSize; |
| 3710 | 3710 | iPartitionBsSize += iSliceSize; |
| 3711 | − pLayerBsInfo->iNalLengthInByte[iNalIdxInLayer] = iSliceSize; | |
| 3712 | 3711 | |
| 3713 | 3712 | #if defined(SLICE_INFO_OUTPUT) |
| 3714 | 3713 | fprintf (stderr, |