History

This refine is to remove slice number limitation in the future. The changes contains: 1. add pNalLen in Structure SWelsEncoderOutput to store each nal length 2. rename iNalLengthInByte[MAX_NAL_UNITS_IN_LAYER] to pNalLengthInByte in Structure SLayerBSInfo, the pointer point to pNalLen, like pBSBuf point to pFrameBS.

ganyang committed 12 years ago

Commit c08c0f81 parent 3c4d1518 files · +34 −34Browse files

Showing the changes to codec/encoder/core/src/encoder_ext.cpp (1 of 8 files). Show all

Unified · Split

codec/encoder/core/src/encoder_ext.cpp+25−26
@@ -1303,6 +1303,8 @@ int32_t RequestMemorySvc (sWelsEncCtx** ppCtx) { · 1302 unmodified lines
13031303 (*ppCtx)->pOut->uiSize = iCountBsLen;
13041304 (*ppCtx)->pOut->sNalList = (SWelsNalRaw*)pMa->WelsMalloc (iCountNals * sizeof (SWelsNalRaw), "pOut->sNalList");
13051305 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))
13061308 (*ppCtx)->pOut->iCountNals = iCountNals;
13071309 (*ppCtx)->pOut->iNalIndex = 0;
13081310
@@ -1497,6 +1499,11 @@ void FreeMemorySvc (sWelsEncCtx** ppCtx) { · 188 unmodified lines
14971499 pMa->WelsFree (pCtx->pOut->sNalList, "pOut->sNalList");
14981500 pCtx->pOut->sNalList = NULL;
14991501 }
1502+ // NALs len
1503+ if (NULL != pCtx->pOut->pNalLen) {
1504+ pMa->WelsFree (pCtx->pOut->pNalLen, "pOut->pNalLen");
1505+ pCtx->pOut->pNalLen = NULL;
1506+ }
15001507 pMa->WelsFree (pCtx->pOut, "SWelsEncoderOutput");
15011508 pCtx->pOut = NULL;
15021509 }
@@ -2733,7 +2740,6 @@ static inline int32_t AddPrefixNal (sWelsEncCtx* pCtx, · 1230 unmodified lines
27332740 iPayloadSize = pNalLen[*pNalIdxInLayer];
27342741
27352742 pCtx->iPosBsBuffer += iPayloadSize;
2736− pLayerBsInfo->iNalLengthInByte[*pNalIdxInLayer] = iPayloadSize;
27372743
27382744 (*pNalIdxInLayer) ++;
27392745 } 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
27502756 iPayloadSize = pNalLen[*pNalIdxInLayer];
27512757
27522758 pCtx->iPosBsBuffer += iPayloadSize;
2753− pLayerBsInfo->iNalLengthInByte[*pNalIdxInLayer] = iPayloadSize;
27542759
27552760 (*pNalIdxInLayer) ++;
27562761 }
@@ -2816,13 +2821,13 @@ int32_t ForceCodingIDR (sWelsEncCtx* pCtx) { · 59 unmodified lines
28162821 int32_t WelsEncoderEncodeParameterSets (sWelsEncCtx* pCtx, void* pDst) {
28172822 SFrameBSInfo* pFbi = (SFrameBSInfo*)pDst;
28182823 SLayerBSInfo* pLayerBsInfo = &pFbi->sLayerInfo[0];
2819− int32_t iNalLen[128] = {0};
28202824 int32_t iCountNal = 0;
28212825
28222826 pLayerBsInfo->pBsBuf = pCtx->pFrameBs;
2827+ pLayerBsInfo->pNalLengthInByte = pCtx->pOut->pNalLen;
28232828 InitBits (&pCtx->pOut->sBsWrite, pCtx->pOut->pBsBuffer, pCtx->pOut->uiSize);
28242829
2825− int32_t iReturn = WelsWriteParameterSets (pCtx, &iNalLen[0], &iCountNal);
2830+ int32_t iReturn = WelsWriteParameterSets (pCtx, &pLayerBsInfo->pNalLengthInByte[0], &iCountNal);
28262831 WELS_VERIFY_RETURN_IFNEQ (iReturn, ENC_RETURN_SUCCESS)
28272832
28282833 pLayerBsInfo->uiPriorityId = 0;
@@ -2831,9 +2836,6 @@ int32_t WelsEncoderEncodeParameterSets (sWelsEncCtx* pCtx, void* pDst) { · 2 unmodified lines
28312836 pLayerBsInfo->uiQualityId = 0;
28322837 pLayerBsInfo->uiLayerType = NON_VIDEO_CODING_LAYER;
28332838 pLayerBsInfo->iNalCount = iCountNal;
2834− for (int32_t iNalIndex = 0; iNalIndex < iCountNal; ++ iNalIndex) {
2835− pLayerBsInfo->iNalLengthInByte[iNalIndex] = iNalLen[iNalIndex];
2836− }
28372839
28382840 pCtx->eLastNalPriority = NRI_PRI_HIGHEST;
28392841 pFbi->iLayerNum = 1;
@@ -2865,7 +2867,6 @@ int32_t WelsEncoderEncodeExt (sWelsEncCtx* pCtx, SFrameBSInfo* pFbi, const SSour · 25 unmodified lines
28652867 int32_t iSpatialNum = 0; // available count number of spatial layers due to frame size changed in this given frame
28662868 int32_t iSpatialIdx = 0; // iIndex of spatial layers due to frame size changed in this given frame
28672869 int32_t iFrameSize = 0;
2868− int32_t iNalLen[128] = {0};
28692870 int32_t iNalIdxInLayer = 0;
28702871 int32_t iCountNal = 0;
28712872 EVideoFrameType eFrameType = videoFrameTypeInvalid;
@@ -2909,13 +2910,14 @@ int32_t WelsEncoderEncodeExt (sWelsEncCtx* pCtx, SFrameBSInfo* pFbi, const SSour · 37 unmodified lines
29092910 pCtx->uiTemporalId = iCurTid;
29102911
29112912 pLayerBsInfo->pBsBuf = pCtx->pFrameBs ;
2913+ pLayerBsInfo->pNalLengthInByte = pCtx->pOut->pNalLen;
29122914
29132915 if (eFrameType == videoFrameTypeIDR) {
29142916 ++ pCtx->sPSOVector.uiIdrPicId;
29152917 //if ( pSvcParam->bEnableSSEI )
29162918
29172919 // write parameter sets bitstream here
2918− pCtx->iEncoderError = WelsWriteParameterSets (pCtx, &iNalLen[0], &iCountNal);
2920+ pCtx->iEncoderError = WelsWriteParameterSets (pCtx, &pLayerBsInfo->pNalLengthInByte[0], &iCountNal);
29192921 WELS_VERIFY_RETURN_IFNEQ (pCtx->iEncoderError, ENC_RETURN_SUCCESS)
29202922
29212923 pLayerBsInfo->uiPriorityId = 0;
@@ -2924,12 +2926,10 @@ int32_t WelsEncoderEncodeExt (sWelsEncCtx* pCtx, SFrameBSInfo* pFbi, const SSour · 2 unmodified lines
29242926 pLayerBsInfo->uiQualityId = 0;
29252927 pLayerBsInfo->uiLayerType = NON_VIDEO_CODING_LAYER;
29262928 pLayerBsInfo->iNalCount = iCountNal;
2927− for (int32_t iNalIndex = 0; iNalIndex < iCountNal; ++ iNalIndex) {
2928− pLayerBsInfo->iNalLengthInByte[iNalIndex] = iNalLen[iNalIndex];
2929− }
29302929
29312930 ++ pLayerBsInfo;
29322931 pLayerBsInfo->pBsBuf = pCtx->pFrameBs + pCtx->iPosBsBuffer;
2932+ pLayerBsInfo->pNalLengthInByte = (pLayerBsInfo - 1)->pNalLengthInByte + iCountNal;
29332933 ++ iLayerNum;
29342934 }
29352935
@@ -3050,7 +3050,7 @@ int32_t WelsEncoderEncodeExt (sWelsEncCtx* pCtx, SFrameBSInfo* pFbi, const SSour · 114 unmodified lines
30503050 int32_t iPayloadSize = 0;
30513051
30523052 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,
30543054 iPayloadSize);
30553055 WELS_VERIFY_RETURN_IFNEQ (pCtx->iEncoderError, ENC_RETURN_SUCCESS)
30563056 iLayerSize += iPayloadSize;
@@ -3067,9 +3067,9 @@ int32_t WelsEncoderEncodeExt (sWelsEncCtx* pCtx, SFrameBSInfo* pFbi, const SSour · 10 unmodified lines
30673067 &pCtx->pCurDqLayer->sLayerInfo.sNalHeaderExt,
30683068 pCtx->iFrameBsSize - pCtx->iPosBsBuffer,
30693069 pCtx->pFrameBs + pCtx->iPosBsBuffer,
3070− &iNalLen[iNalIdxInLayer]);
3070+ &pLayerBsInfo->pNalLengthInByte[iNalIdxInLayer]);
30713071 WELS_VERIFY_RETURN_IFNEQ (pCtx->iEncoderError, ENC_RETURN_SUCCESS)
3072− iSliceSize = iNalLen[iNalIdxInLayer];
3072+ iSliceSize = pLayerBsInfo->pNalLengthInByte[iNalIdxInLayer];
30733073
30743074 iLayerSize += iSliceSize;
30753075 pCtx->iPosBsBuffer += iSliceSize;
@@ -3078,7 +3078,6 @@ int32_t WelsEncoderEncodeExt (sWelsEncCtx* pCtx, SFrameBSInfo* pFbi, const SSour · 2 unmodified lines
30783078 pLayerBsInfo->uiTemporalId = iCurTid;
30793079 pLayerBsInfo->uiQualityId = 0;
30803080 pLayerBsInfo->uiPriorityId = 0;
3081− pLayerBsInfo->iNalLengthInByte[iNalIdxInLayer] = iSliceSize;
30823081 pLayerBsInfo->iNalCount = ++ iNalIdxInLayer;
30833082 }
30843083 // for dynamic slicing single threading..
@@ -3221,7 +3220,7 @@ int32_t WelsEncoderEncodeExt (sWelsEncCtx* pCtx, SFrameBSInfo* pFbi, const SSour · 136 unmodified lines
32213220 int32_t iSliceSize = 0;
32223221 int32_t iPayloadSize = 0;
32233222 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,
32253224 iPayloadSize);
32263225 WELS_VERIFY_RETURN_IFNEQ (pCtx->iEncoderError, ENC_RETURN_SUCCESS)
32273226 iLayerSize += iPayloadSize;
@@ -3236,13 +3235,12 @@ int32_t WelsEncoderEncodeExt (sWelsEncCtx* pCtx, SFrameBSInfo* pFbi, const SSour · 8 unmodified lines
32363235 pCtx->iEncoderError = WelsEncodeNal (&pCtx->pOut->sNalList[pCtx->pOut->iNalIndex - 1],
32373236 &pCtx->pCurDqLayer->sLayerInfo.sNalHeaderExt,
32383237 pCtx->iFrameBsSize - pCtx->iPosBsBuffer,
3239− pCtx->pFrameBs + pCtx->iPosBsBuffer, &iNalLen[iNalIdxInLayer]);
3238+ pCtx->pFrameBs + pCtx->iPosBsBuffer, &pLayerBsInfo->pNalLengthInByte[iNalIdxInLayer]);
32403239 WELS_VERIFY_RETURN_IFNEQ (pCtx->iEncoderError, ENC_RETURN_SUCCESS)
3241− iSliceSize = iNalLen[iNalIdxInLayer];
3240+ iSliceSize = pLayerBsInfo->pNalLengthInByte[iNalIdxInLayer];
32423241
32433242 pCtx->iPosBsBuffer += iSliceSize;
32443243 iLayerSize += iSliceSize;
3245− pLayerBsInfo->iNalLengthInByte[iNalIdxInLayer] = iSliceSize;
32463244
32473245 #if defined(SLICE_INFO_OUTPUT)
32483246 fprintf (stderr,
@@ -3374,10 +3372,12 @@ int32_t WelsEncoderEncodeExt (sWelsEncCtx* pCtx, SFrameBSInfo* pFbi, const SSour · 125 unmodified lines
33743372 }
33753373 #endif//STAT_OUTPUT
33763374
3375+ iCountNal = pLayerBsInfo->iNalCount;
33773376 ++ iLayerNum;
33783377 ++ pLayerBsInfo;
33793378
33803379 pLayerBsInfo->pBsBuf = pCtx->pFrameBs + pCtx->iPosBsBuffer;
3380+ pLayerBsInfo->pNalLengthInByte = (pLayerBsInfo - 1)->pNalLengthInByte + iCountNal;
33813381
33823382 if (pSvcParam->iPaddingFlag && pCtx->pWelsSvcRc[pCtx->uiDependencyId].iPaddingSize > 0) {
33833383 int32_t iPaddingNalSize = 0;
@@ -3401,9 +3401,10 @@ int32_t WelsEncoderEncodeExt (sWelsEncCtx* pCtx, SFrameBSInfo* pFbi, const SSour · 17 unmodified lines
34013401 pLayerBsInfo->uiQualityId = 0;
34023402 pLayerBsInfo->uiLayerType = NON_VIDEO_CODING_LAYER;
34033403 pLayerBsInfo->iNalCount = 1;
3404− pLayerBsInfo->iNalLengthInByte[0] = iPaddingNalSize;
3404+ pLayerBsInfo->pNalLengthInByte[0] = iPaddingNalSize;
34053405 ++ pLayerBsInfo;
34063406 pLayerBsInfo->pBsBuf = pCtx->pFrameBs + pCtx->iPosBsBuffer;
3407+ pLayerBsInfo->pNalLengthInByte = (pLayerBsInfo - 1)->pNalLengthInByte + 1;
34073408 ++ iLayerNum;
34083409 }
34093410
@@ -3657,7 +3658,6 @@ int32_t WelsCodeOnePicPartition (sWelsEncCtx* pCtx, · 247 unmodified lines
36573658
36583659 SDqLayer* pCurLayer = pCtx->pCurDqLayer;
36593660 SSliceCtx* pSliceCtx = pCurLayer->pSliceEncCtx;
3660− int32_t iNalLen[MAX_NAL_UNITS_IN_LAYER] = {0};
36613661 int32_t iNalIdxInLayer = *pNalIdxInLayer;
36623662 int32_t iSliceIdx = iStartSliceIdx;
36633663 const int32_t kiSliceStep = pCtx->iActiveThreadsNum;
@@ -3688,7 +3688,7 @@ int32_t WelsCodeOnePicPartition (sWelsEncCtx* pCtx, · 24 unmodified lines
36883688 }
36893689
36903690 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);
36923692 WELS_VERIFY_RETURN_IFNEQ (iReturn, ENC_RETURN_SUCCESS)
36933693 iPartitionBsSize += iPayloadSize;
36943694 }
@@ -3702,13 +3702,12 @@ int32_t WelsCodeOnePicPartition (sWelsEncCtx* pCtx, · 7 unmodified lines
37023702 &pCtx->pCurDqLayer->sLayerInfo.sNalHeaderExt,
37033703 pCtx->iFrameBsSize - pCtx->iPosBsBuffer,
37043704 pCtx->pFrameBs + pCtx->iPosBsBuffer,
3705− &iNalLen[iNalIdxInLayer]);
3705+ &pLayerBsInfo->pNalLengthInByte[iNalIdxInLayer]);
37063706 WELS_VERIFY_RETURN_IFNEQ (iReturn, ENC_RETURN_SUCCESS)
3707− iSliceSize = iNalLen[iNalIdxInLayer];
3707+ iSliceSize = pLayerBsInfo->pNalLengthInByte[iNalIdxInLayer];
37083708
37093709 pCtx->iPosBsBuffer += iSliceSize;
37103710 iPartitionBsSize += iSliceSize;
3711− pLayerBsInfo->iNalLengthInByte[iNalIdxInLayer] = iSliceSize;
37123711
37133712 #if defined(SLICE_INFO_OUTPUT)
37143713 fprintf (stderr,

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t