Refine Nal length related structure
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 | } |
| @@ -2772,7 +2779,6 @@ static inline int32_t AddPrefixNal (sWelsEncCtx* pCtx, · 1269 unmodified lines | ||
| 2772 | 2779 | iPayloadSize = pNalLen[*pNalIdxInLayer]; |
| 2773 | 2780 | |
| 2774 | 2781 | pCtx->iPosBsBuffer += iPayloadSize; |
| 2775 | − pLayerBsInfo->iNalLengthInByte[*pNalIdxInLayer] = iPayloadSize; | |
| 2776 | 2782 | |
| 2777 | 2783 | (*pNalIdxInLayer) ++; |
| 2778 | 2784 | } else { // No Prefix NAL Unit RBSP syntax here, but need add NAL Unit Header extension |
| @@ -2789,7 +2795,6 @@ static inline int32_t AddPrefixNal (sWelsEncCtx* pCtx, · 10 unmodified lines | ||
| 2789 | 2795 | iPayloadSize = pNalLen[*pNalIdxInLayer]; |
| 2790 | 2796 | |
| 2791 | 2797 | pCtx->iPosBsBuffer += iPayloadSize; |
| 2792 | − pLayerBsInfo->iNalLengthInByte[*pNalIdxInLayer] = iPayloadSize; | |
| 2793 | 2798 | |
| 2794 | 2799 | (*pNalIdxInLayer) ++; |
| 2795 | 2800 | } |
| @@ -2855,13 +2860,13 @@ int32_t ForceCodingIDR (sWelsEncCtx* pCtx) { · 59 unmodified lines | ||
| 2855 | 2860 | int32_t WelsEncoderEncodeParameterSets (sWelsEncCtx* pCtx, void* pDst) { |
| 2856 | 2861 | SFrameBSInfo* pFbi = (SFrameBSInfo*)pDst; |
| 2857 | 2862 | SLayerBSInfo* pLayerBsInfo = &pFbi->sLayerInfo[0]; |
| 2858 | − int32_t iNalLen[128] = {0}; | |
| 2859 | 2863 | int32_t iCountNal = 0; |
| 2860 | 2864 | |
| 2861 | 2865 | pLayerBsInfo->pBsBuf = pCtx->pFrameBs; |
| 2866 | + pLayerBsInfo->pNalLengthInByte = pCtx->pOut->pNalLen; | |
| 2862 | 2867 | InitBits (&pCtx->pOut->sBsWrite, pCtx->pOut->pBsBuffer, pCtx->pOut->uiSize); |
| 2863 | 2868 | |
| 2864 | − int32_t iReturn = WelsWriteParameterSets (pCtx, &iNalLen[0], &iCountNal); | |
| 2869 | + int32_t iReturn = WelsWriteParameterSets (pCtx, &pLayerBsInfo->pNalLengthInByte[0], &iCountNal); | |
| 2865 | 2870 | WELS_VERIFY_RETURN_IFNEQ (iReturn, ENC_RETURN_SUCCESS) |
| 2866 | 2871 | |
| 2867 | 2872 | pLayerBsInfo->uiPriorityId = 0; |
| @@ -2870,9 +2875,6 @@ int32_t WelsEncoderEncodeParameterSets (sWelsEncCtx* pCtx, void* pDst) { · 2 unmodified lines | ||
| 2870 | 2875 | pLayerBsInfo->uiQualityId = 0; |
| 2871 | 2876 | pLayerBsInfo->uiLayerType = NON_VIDEO_CODING_LAYER; |
| 2872 | 2877 | pLayerBsInfo->iNalCount = iCountNal; |
| 2873 | − for (int32_t iNalIndex = 0; iNalIndex < iCountNal; ++ iNalIndex) { | |
| 2874 | − pLayerBsInfo->iNalLengthInByte[iNalIndex] = iNalLen[iNalIndex]; | |
| 2875 | − } | |
| 2876 | 2878 | |
| 2877 | 2879 | pCtx->eLastNalPriority = NRI_PRI_HIGHEST; |
| 2878 | 2880 | pFbi->iLayerNum = 1; |
| @@ -2904,7 +2906,6 @@ int32_t WelsEncoderEncodeExt (sWelsEncCtx* pCtx, SFrameBSInfo* pFbi, const SSour · 25 unmodified lines | ||
| 2904 | 2906 | int32_t iSpatialNum = 0; // available count number of spatial layers due to frame size changed in this given frame |
| 2905 | 2907 | int32_t iSpatialIdx = 0; // iIndex of spatial layers due to frame size changed in this given frame |
| 2906 | 2908 | int32_t iFrameSize = 0; |
| 2907 | − int32_t iNalLen[128] = {0}; | |
| 2908 | 2909 | int32_t iNalIdxInLayer = 0; |
| 2909 | 2910 | int32_t iCountNal = 0; |
| 2910 | 2911 | EVideoFrameType eFrameType = videoFrameTypeInvalid; |
| @@ -2948,13 +2949,14 @@ int32_t WelsEncoderEncodeExt (sWelsEncCtx* pCtx, SFrameBSInfo* pFbi, const SSour · 37 unmodified lines | ||
| 2948 | 2949 | pCtx->uiTemporalId = iCurTid; |
| 2949 | 2950 | |
| 2950 | 2951 | pLayerBsInfo->pBsBuf = pCtx->pFrameBs ; |
| 2952 | + pLayerBsInfo->pNalLengthInByte = pCtx->pOut->pNalLen; | |
| 2951 | 2953 | |
| 2952 | 2954 | if (eFrameType == videoFrameTypeIDR) { |
| 2953 | 2955 | ++ pCtx->sPSOVector.uiIdrPicId; |
| 2954 | 2956 | //if ( pSvcParam->bEnableSSEI ) |
| 2955 | 2957 | |
| 2956 | 2958 | // write parameter sets bitstream here |
| 2957 | − pCtx->iEncoderError = WelsWriteParameterSets (pCtx, &iNalLen[0], &iCountNal); | |
| 2959 | + pCtx->iEncoderError = WelsWriteParameterSets (pCtx, &pLayerBsInfo->pNalLengthInByte[0], &iCountNal); | |
| 2958 | 2960 | WELS_VERIFY_RETURN_IFNEQ (pCtx->iEncoderError, ENC_RETURN_SUCCESS) |
| 2959 | 2961 | |
| 2960 | 2962 | pLayerBsInfo->uiPriorityId = 0; |
| @@ -2963,12 +2965,10 @@ int32_t WelsEncoderEncodeExt (sWelsEncCtx* pCtx, SFrameBSInfo* pFbi, const SSour · 2 unmodified lines | ||
| 2963 | 2965 | pLayerBsInfo->uiQualityId = 0; |
| 2964 | 2966 | pLayerBsInfo->uiLayerType = NON_VIDEO_CODING_LAYER; |
| 2965 | 2967 | pLayerBsInfo->iNalCount = iCountNal; |
| 2966 | − for (int32_t iNalIndex = 0; iNalIndex < iCountNal; ++ iNalIndex) { | |
| 2967 | − pLayerBsInfo->iNalLengthInByte[iNalIndex] = iNalLen[iNalIndex]; | |
| 2968 | − } | |
| 2969 | 2968 | |
| 2970 | 2969 | ++ pLayerBsInfo; |
| 2971 | 2970 | pLayerBsInfo->pBsBuf = pCtx->pFrameBs + pCtx->iPosBsBuffer; |
| 2971 | + pLayerBsInfo->pNalLengthInByte = (pLayerBsInfo - 1)->pNalLengthInByte + iCountNal; | |
| 2972 | 2972 | ++ iLayerNum; |
| 2973 | 2973 | } |
| 2974 | 2974 | |
| @@ -3089,7 +3089,7 @@ int32_t WelsEncoderEncodeExt (sWelsEncCtx* pCtx, SFrameBSInfo* pFbi, const SSour · 114 unmodified lines | ||
| 3089 | 3089 | int32_t iPayloadSize = 0; |
| 3090 | 3090 | |
| 3091 | 3091 | if (pCtx->bNeedPrefixNalFlag) { |
| 3092 | − pCtx->iEncoderError = AddPrefixNal (pCtx, pLayerBsInfo, &iNalLen[0], &iNalIdxInLayer, eNalType, eNalRefIdc, | |
| 3092 | + pCtx->iEncoderError = AddPrefixNal (pCtx, pLayerBsInfo, &pLayerBsInfo->pNalLengthInByte[0], &iNalIdxInLayer, eNalType, eNalRefIdc, | |
| 3093 | 3093 | iPayloadSize); |
| 3094 | 3094 | WELS_VERIFY_RETURN_IFNEQ (pCtx->iEncoderError, ENC_RETURN_SUCCESS) |
| 3095 | 3095 | iLayerSize += iPayloadSize; |
| @@ -3106,9 +3106,9 @@ int32_t WelsEncoderEncodeExt (sWelsEncCtx* pCtx, SFrameBSInfo* pFbi, const SSour · 10 unmodified lines | ||
| 3106 | 3106 | &pCtx->pCurDqLayer->sLayerInfo.sNalHeaderExt, |
| 3107 | 3107 | pCtx->iFrameBsSize - pCtx->iPosBsBuffer, |
| 3108 | 3108 | pCtx->pFrameBs + pCtx->iPosBsBuffer, |
| 3109 | − &iNalLen[iNalIdxInLayer]); | |
| 3109 | + &pLayerBsInfo->pNalLengthInByte[iNalIdxInLayer]); | |
| 3110 | 3110 | WELS_VERIFY_RETURN_IFNEQ (pCtx->iEncoderError, ENC_RETURN_SUCCESS) |
| 3111 | − iSliceSize = iNalLen[iNalIdxInLayer]; | |
| 3111 | + iSliceSize = pLayerBsInfo->pNalLengthInByte[iNalIdxInLayer]; | |
| 3112 | 3112 | |
| 3113 | 3113 | iLayerSize += iSliceSize; |
| 3114 | 3114 | pCtx->iPosBsBuffer += iSliceSize; |
| @@ -3117,7 +3117,6 @@ int32_t WelsEncoderEncodeExt (sWelsEncCtx* pCtx, SFrameBSInfo* pFbi, const SSour · 2 unmodified lines | ||
| 3117 | 3117 | pLayerBsInfo->uiTemporalId = iCurTid; |
| 3118 | 3118 | pLayerBsInfo->uiQualityId = 0; |
| 3119 | 3119 | pLayerBsInfo->uiPriorityId = 0; |
| 3120 | − pLayerBsInfo->iNalLengthInByte[iNalIdxInLayer] = iSliceSize; | |
| 3121 | 3120 | pLayerBsInfo->iNalCount = ++ iNalIdxInLayer; |
| 3122 | 3121 | } |
| 3123 | 3122 | // for dynamic slicing single threading.. |
| @@ -3260,7 +3259,7 @@ int32_t WelsEncoderEncodeExt (sWelsEncCtx* pCtx, SFrameBSInfo* pFbi, const SSour · 136 unmodified lines | ||
| 3260 | 3259 | int32_t iSliceSize = 0; |
| 3261 | 3260 | int32_t iPayloadSize = 0; |
| 3262 | 3261 | if (bNeedPrefix) { |
| 3263 | − pCtx->iEncoderError = AddPrefixNal (pCtx, pLayerBsInfo, &iNalLen[0], &iNalIdxInLayer, eNalType, eNalRefIdc, | |
| 3262 | + pCtx->iEncoderError = AddPrefixNal (pCtx, pLayerBsInfo, &pLayerBsInfo->pNalLengthInByte[0], &iNalIdxInLayer, eNalType, eNalRefIdc, | |
| 3264 | 3263 | iPayloadSize); |
| 3265 | 3264 | WELS_VERIFY_RETURN_IFNEQ (pCtx->iEncoderError, ENC_RETURN_SUCCESS) |
| 3266 | 3265 | iLayerSize += iPayloadSize; |
| @@ -3275,13 +3274,12 @@ int32_t WelsEncoderEncodeExt (sWelsEncCtx* pCtx, SFrameBSInfo* pFbi, const SSour · 8 unmodified lines | ||
| 3275 | 3274 | pCtx->iEncoderError = WelsEncodeNal (&pCtx->pOut->sNalList[pCtx->pOut->iNalIndex - 1], |
| 3276 | 3275 | &pCtx->pCurDqLayer->sLayerInfo.sNalHeaderExt, |
| 3277 | 3276 | pCtx->iFrameBsSize - pCtx->iPosBsBuffer, |
| 3278 | − pCtx->pFrameBs + pCtx->iPosBsBuffer, &iNalLen[iNalIdxInLayer]); | |
| 3277 | + pCtx->pFrameBs + pCtx->iPosBsBuffer, &pLayerBsInfo->pNalLengthInByte[iNalIdxInLayer]); | |
| 3279 | 3278 | WELS_VERIFY_RETURN_IFNEQ (pCtx->iEncoderError, ENC_RETURN_SUCCESS) |
| 3280 | − iSliceSize = iNalLen[iNalIdxInLayer]; | |
| 3279 | + iSliceSize = pLayerBsInfo->pNalLengthInByte[iNalIdxInLayer]; | |
| 3281 | 3280 | |
| 3282 | 3281 | pCtx->iPosBsBuffer += iSliceSize; |
| 3283 | 3282 | iLayerSize += iSliceSize; |
| 3284 | − pLayerBsInfo->iNalLengthInByte[iNalIdxInLayer] = iSliceSize; | |
| 3285 | 3283 | |
| 3286 | 3284 | #if defined(SLICE_INFO_OUTPUT) |
| 3287 | 3285 | fprintf (stderr, |
| @@ -3413,10 +3411,12 @@ int32_t WelsEncoderEncodeExt (sWelsEncCtx* pCtx, SFrameBSInfo* pFbi, const SSour · 125 unmodified lines | ||
| 3413 | 3411 | } |
| 3414 | 3412 | #endif//STAT_OUTPUT |
| 3415 | 3413 | |
| 3414 | + iCountNal = pLayerBsInfo->iNalCount; | |
| 3416 | 3415 | ++ iLayerNum; |
| 3417 | 3416 | ++ pLayerBsInfo; |
| 3418 | 3417 | |
| 3419 | 3418 | pLayerBsInfo->pBsBuf = pCtx->pFrameBs + pCtx->iPosBsBuffer; |
| 3419 | + pLayerBsInfo->pNalLengthInByte = (pLayerBsInfo - 1)->pNalLengthInByte + iCountNal; | |
| 3420 | 3420 | |
| 3421 | 3421 | if (pSvcParam->iPaddingFlag && pCtx->pWelsSvcRc[pCtx->uiDependencyId].iPaddingSize > 0) { |
| 3422 | 3422 | int32_t iPaddingNalSize = 0; |
| @@ -3440,9 +3440,10 @@ int32_t WelsEncoderEncodeExt (sWelsEncCtx* pCtx, SFrameBSInfo* pFbi, const SSour · 17 unmodified lines | ||
| 3440 | 3440 | pLayerBsInfo->uiQualityId = 0; |
| 3441 | 3441 | pLayerBsInfo->uiLayerType = NON_VIDEO_CODING_LAYER; |
| 3442 | 3442 | pLayerBsInfo->iNalCount = 1; |
| 3443 | − pLayerBsInfo->iNalLengthInByte[0] = iPaddingNalSize; | |
| 3443 | + pLayerBsInfo->pNalLengthInByte[0] = iPaddingNalSize; | |
| 3444 | 3444 | ++ pLayerBsInfo; |
| 3445 | 3445 | pLayerBsInfo->pBsBuf = pCtx->pFrameBs + pCtx->iPosBsBuffer; |
| 3446 | + pLayerBsInfo->pNalLengthInByte = (pLayerBsInfo - 1)->pNalLengthInByte + 1; | |
| 3446 | 3447 | ++ iLayerNum; |
| 3447 | 3448 | } |
| 3448 | 3449 | |
| @@ -3696,7 +3697,6 @@ int32_t WelsCodeOnePicPartition (sWelsEncCtx* pCtx, · 247 unmodified lines | ||
| 3696 | 3697 | |
| 3697 | 3698 | SDqLayer* pCurLayer = pCtx->pCurDqLayer; |
| 3698 | 3699 | SSliceCtx* pSliceCtx = pCurLayer->pSliceEncCtx; |
| 3699 | − int32_t iNalLen[MAX_NAL_UNITS_IN_LAYER] = {0}; | |
| 3700 | 3700 | int32_t iNalIdxInLayer = *pNalIdxInLayer; |
| 3701 | 3701 | int32_t iSliceIdx = iStartSliceIdx; |
| 3702 | 3702 | const int32_t kiSliceStep = pCtx->iActiveThreadsNum; |
| @@ -3727,7 +3727,7 @@ int32_t WelsCodeOnePicPartition (sWelsEncCtx* pCtx, · 24 unmodified lines | ||
| 3727 | 3727 | } |
| 3728 | 3728 | |
| 3729 | 3729 | if (kbNeedPrefix) { |
| 3730 | − iReturn = AddPrefixNal (pCtx, pLayerBsInfo, &iNalLen[0], &iNalIdxInLayer, keNalType, keNalRefIdc, iPayloadSize); | |
| 3730 | + iReturn = AddPrefixNal (pCtx, pLayerBsInfo, &pLayerBsInfo->pNalLengthInByte[0], &iNalIdxInLayer, keNalType, keNalRefIdc, iPayloadSize); | |
| 3731 | 3731 | WELS_VERIFY_RETURN_IFNEQ (iReturn, ENC_RETURN_SUCCESS) |
| 3732 | 3732 | iPartitionBsSize += iPayloadSize; |
| 3733 | 3733 | } |
| @@ -3741,13 +3741,12 @@ int32_t WelsCodeOnePicPartition (sWelsEncCtx* pCtx, · 7 unmodified lines | ||
| 3741 | 3741 | &pCtx->pCurDqLayer->sLayerInfo.sNalHeaderExt, |
| 3742 | 3742 | pCtx->iFrameBsSize - pCtx->iPosBsBuffer, |
| 3743 | 3743 | pCtx->pFrameBs + pCtx->iPosBsBuffer, |
| 3744 | − &iNalLen[iNalIdxInLayer]); | |
| 3744 | + &pLayerBsInfo->pNalLengthInByte[iNalIdxInLayer]); | |
| 3745 | 3745 | WELS_VERIFY_RETURN_IFNEQ (iReturn, ENC_RETURN_SUCCESS) |
| 3746 | − iSliceSize = iNalLen[iNalIdxInLayer]; | |
| 3746 | + iSliceSize = pLayerBsInfo->pNalLengthInByte[iNalIdxInLayer]; | |
| 3747 | 3747 | |
| 3748 | 3748 | pCtx->iPosBsBuffer += iSliceSize; |
| 3749 | 3749 | iPartitionBsSize += iSliceSize; |
| 3750 | − pLayerBsInfo->iNalLengthInByte[iNalIdxInLayer] = iSliceSize; | |
| 3751 | 3750 | |
| 3752 | 3751 | #if defined(SLICE_INFO_OUTPUT) |
| 3753 | 3752 | fprintf (stderr, |