History

Merge pull request #842 from ganyangbbl/refine_nal2

Refine Nal length related structure

ruil2 committed 12 years ago

Commit 69f2d762 parents e15742b c08c0f88 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 }
@@ -2772,7 +2779,6 @@ static inline int32_t AddPrefixNal (sWelsEncCtx* pCtx, · 1269 unmodified lines
27722779 iPayloadSize = pNalLen[*pNalIdxInLayer];
27732780
27742781 pCtx->iPosBsBuffer += iPayloadSize;
2775− pLayerBsInfo->iNalLengthInByte[*pNalIdxInLayer] = iPayloadSize;
27762782
27772783 (*pNalIdxInLayer) ++;
27782784 } 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
27892795 iPayloadSize = pNalLen[*pNalIdxInLayer];
27902796
27912797 pCtx->iPosBsBuffer += iPayloadSize;
2792− pLayerBsInfo->iNalLengthInByte[*pNalIdxInLayer] = iPayloadSize;
27932798
27942799 (*pNalIdxInLayer) ++;
27952800 }
@@ -2855,13 +2860,13 @@ int32_t ForceCodingIDR (sWelsEncCtx* pCtx) { · 59 unmodified lines
28552860 int32_t WelsEncoderEncodeParameterSets (sWelsEncCtx* pCtx, void* pDst) {
28562861 SFrameBSInfo* pFbi = (SFrameBSInfo*)pDst;
28572862 SLayerBSInfo* pLayerBsInfo = &pFbi->sLayerInfo[0];
2858− int32_t iNalLen[128] = {0};
28592863 int32_t iCountNal = 0;
28602864
28612865 pLayerBsInfo->pBsBuf = pCtx->pFrameBs;
2866+ pLayerBsInfo->pNalLengthInByte = pCtx->pOut->pNalLen;
28622867 InitBits (&pCtx->pOut->sBsWrite, pCtx->pOut->pBsBuffer, pCtx->pOut->uiSize);
28632868
2864− int32_t iReturn = WelsWriteParameterSets (pCtx, &iNalLen[0], &iCountNal);
2869+ int32_t iReturn = WelsWriteParameterSets (pCtx, &pLayerBsInfo->pNalLengthInByte[0], &iCountNal);
28652870 WELS_VERIFY_RETURN_IFNEQ (iReturn, ENC_RETURN_SUCCESS)
28662871
28672872 pLayerBsInfo->uiPriorityId = 0;
@@ -2870,9 +2875,6 @@ int32_t WelsEncoderEncodeParameterSets (sWelsEncCtx* pCtx, void* pDst) { · 2 unmodified lines
28702875 pLayerBsInfo->uiQualityId = 0;
28712876 pLayerBsInfo->uiLayerType = NON_VIDEO_CODING_LAYER;
28722877 pLayerBsInfo->iNalCount = iCountNal;
2873− for (int32_t iNalIndex = 0; iNalIndex < iCountNal; ++ iNalIndex) {
2874− pLayerBsInfo->iNalLengthInByte[iNalIndex] = iNalLen[iNalIndex];
2875− }
28762878
28772879 pCtx->eLastNalPriority = NRI_PRI_HIGHEST;
28782880 pFbi->iLayerNum = 1;
@@ -2904,7 +2906,6 @@ int32_t WelsEncoderEncodeExt (sWelsEncCtx* pCtx, SFrameBSInfo* pFbi, const SSour · 25 unmodified lines
29042906 int32_t iSpatialNum = 0; // available count number of spatial layers due to frame size changed in this given frame
29052907 int32_t iSpatialIdx = 0; // iIndex of spatial layers due to frame size changed in this given frame
29062908 int32_t iFrameSize = 0;
2907− int32_t iNalLen[128] = {0};
29082909 int32_t iNalIdxInLayer = 0;
29092910 int32_t iCountNal = 0;
29102911 EVideoFrameType eFrameType = videoFrameTypeInvalid;
@@ -2948,13 +2949,14 @@ int32_t WelsEncoderEncodeExt (sWelsEncCtx* pCtx, SFrameBSInfo* pFbi, const SSour · 37 unmodified lines
29482949 pCtx->uiTemporalId = iCurTid;
29492950
29502951 pLayerBsInfo->pBsBuf = pCtx->pFrameBs ;
2952+ pLayerBsInfo->pNalLengthInByte = pCtx->pOut->pNalLen;
29512953
29522954 if (eFrameType == videoFrameTypeIDR) {
29532955 ++ pCtx->sPSOVector.uiIdrPicId;
29542956 //if ( pSvcParam->bEnableSSEI )
29552957
29562958 // write parameter sets bitstream here
2957− pCtx->iEncoderError = WelsWriteParameterSets (pCtx, &iNalLen[0], &iCountNal);
2959+ pCtx->iEncoderError = WelsWriteParameterSets (pCtx, &pLayerBsInfo->pNalLengthInByte[0], &iCountNal);
29582960 WELS_VERIFY_RETURN_IFNEQ (pCtx->iEncoderError, ENC_RETURN_SUCCESS)
29592961
29602962 pLayerBsInfo->uiPriorityId = 0;
@@ -2963,12 +2965,10 @@ int32_t WelsEncoderEncodeExt (sWelsEncCtx* pCtx, SFrameBSInfo* pFbi, const SSour · 2 unmodified lines
29632965 pLayerBsInfo->uiQualityId = 0;
29642966 pLayerBsInfo->uiLayerType = NON_VIDEO_CODING_LAYER;
29652967 pLayerBsInfo->iNalCount = iCountNal;
2966− for (int32_t iNalIndex = 0; iNalIndex < iCountNal; ++ iNalIndex) {
2967− pLayerBsInfo->iNalLengthInByte[iNalIndex] = iNalLen[iNalIndex];
2968− }
29692968
29702969 ++ pLayerBsInfo;
29712970 pLayerBsInfo->pBsBuf = pCtx->pFrameBs + pCtx->iPosBsBuffer;
2971+ pLayerBsInfo->pNalLengthInByte = (pLayerBsInfo - 1)->pNalLengthInByte + iCountNal;
29722972 ++ iLayerNum;
29732973 }
29742974
@@ -3089,7 +3089,7 @@ int32_t WelsEncoderEncodeExt (sWelsEncCtx* pCtx, SFrameBSInfo* pFbi, const SSour · 114 unmodified lines
30893089 int32_t iPayloadSize = 0;
30903090
30913091 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,
30933093 iPayloadSize);
30943094 WELS_VERIFY_RETURN_IFNEQ (pCtx->iEncoderError, ENC_RETURN_SUCCESS)
30953095 iLayerSize += iPayloadSize;
@@ -3106,9 +3106,9 @@ int32_t WelsEncoderEncodeExt (sWelsEncCtx* pCtx, SFrameBSInfo* pFbi, const SSour · 10 unmodified lines
31063106 &pCtx->pCurDqLayer->sLayerInfo.sNalHeaderExt,
31073107 pCtx->iFrameBsSize - pCtx->iPosBsBuffer,
31083108 pCtx->pFrameBs + pCtx->iPosBsBuffer,
3109− &iNalLen[iNalIdxInLayer]);
3109+ &pLayerBsInfo->pNalLengthInByte[iNalIdxInLayer]);
31103110 WELS_VERIFY_RETURN_IFNEQ (pCtx->iEncoderError, ENC_RETURN_SUCCESS)
3111− iSliceSize = iNalLen[iNalIdxInLayer];
3111+ iSliceSize = pLayerBsInfo->pNalLengthInByte[iNalIdxInLayer];
31123112
31133113 iLayerSize += iSliceSize;
31143114 pCtx->iPosBsBuffer += iSliceSize;
@@ -3117,7 +3117,6 @@ int32_t WelsEncoderEncodeExt (sWelsEncCtx* pCtx, SFrameBSInfo* pFbi, const SSour · 2 unmodified lines
31173117 pLayerBsInfo->uiTemporalId = iCurTid;
31183118 pLayerBsInfo->uiQualityId = 0;
31193119 pLayerBsInfo->uiPriorityId = 0;
3120− pLayerBsInfo->iNalLengthInByte[iNalIdxInLayer] = iSliceSize;
31213120 pLayerBsInfo->iNalCount = ++ iNalIdxInLayer;
31223121 }
31233122 // for dynamic slicing single threading..
@@ -3260,7 +3259,7 @@ int32_t WelsEncoderEncodeExt (sWelsEncCtx* pCtx, SFrameBSInfo* pFbi, const SSour · 136 unmodified lines
32603259 int32_t iSliceSize = 0;
32613260 int32_t iPayloadSize = 0;
32623261 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,
32643263 iPayloadSize);
32653264 WELS_VERIFY_RETURN_IFNEQ (pCtx->iEncoderError, ENC_RETURN_SUCCESS)
32663265 iLayerSize += iPayloadSize;
@@ -3275,13 +3274,12 @@ int32_t WelsEncoderEncodeExt (sWelsEncCtx* pCtx, SFrameBSInfo* pFbi, const SSour · 8 unmodified lines
32753274 pCtx->iEncoderError = WelsEncodeNal (&pCtx->pOut->sNalList[pCtx->pOut->iNalIndex - 1],
32763275 &pCtx->pCurDqLayer->sLayerInfo.sNalHeaderExt,
32773276 pCtx->iFrameBsSize - pCtx->iPosBsBuffer,
3278− pCtx->pFrameBs + pCtx->iPosBsBuffer, &iNalLen[iNalIdxInLayer]);
3277+ pCtx->pFrameBs + pCtx->iPosBsBuffer, &pLayerBsInfo->pNalLengthInByte[iNalIdxInLayer]);
32793278 WELS_VERIFY_RETURN_IFNEQ (pCtx->iEncoderError, ENC_RETURN_SUCCESS)
3280− iSliceSize = iNalLen[iNalIdxInLayer];
3279+ iSliceSize = pLayerBsInfo->pNalLengthInByte[iNalIdxInLayer];
32813280
32823281 pCtx->iPosBsBuffer += iSliceSize;
32833282 iLayerSize += iSliceSize;
3284− pLayerBsInfo->iNalLengthInByte[iNalIdxInLayer] = iSliceSize;
32853283
32863284 #if defined(SLICE_INFO_OUTPUT)
32873285 fprintf (stderr,
@@ -3413,10 +3411,12 @@ int32_t WelsEncoderEncodeExt (sWelsEncCtx* pCtx, SFrameBSInfo* pFbi, const SSour · 125 unmodified lines
34133411 }
34143412 #endif//STAT_OUTPUT
34153413
3414+ iCountNal = pLayerBsInfo->iNalCount;
34163415 ++ iLayerNum;
34173416 ++ pLayerBsInfo;
34183417
34193418 pLayerBsInfo->pBsBuf = pCtx->pFrameBs + pCtx->iPosBsBuffer;
3419+ pLayerBsInfo->pNalLengthInByte = (pLayerBsInfo - 1)->pNalLengthInByte + iCountNal;
34203420
34213421 if (pSvcParam->iPaddingFlag && pCtx->pWelsSvcRc[pCtx->uiDependencyId].iPaddingSize > 0) {
34223422 int32_t iPaddingNalSize = 0;
@@ -3440,9 +3440,10 @@ int32_t WelsEncoderEncodeExt (sWelsEncCtx* pCtx, SFrameBSInfo* pFbi, const SSour · 17 unmodified lines
34403440 pLayerBsInfo->uiQualityId = 0;
34413441 pLayerBsInfo->uiLayerType = NON_VIDEO_CODING_LAYER;
34423442 pLayerBsInfo->iNalCount = 1;
3443− pLayerBsInfo->iNalLengthInByte[0] = iPaddingNalSize;
3443+ pLayerBsInfo->pNalLengthInByte[0] = iPaddingNalSize;
34443444 ++ pLayerBsInfo;
34453445 pLayerBsInfo->pBsBuf = pCtx->pFrameBs + pCtx->iPosBsBuffer;
3446+ pLayerBsInfo->pNalLengthInByte = (pLayerBsInfo - 1)->pNalLengthInByte + 1;
34463447 ++ iLayerNum;
34473448 }
34483449
@@ -3696,7 +3697,6 @@ int32_t WelsCodeOnePicPartition (sWelsEncCtx* pCtx, · 247 unmodified lines
36963697
36973698 SDqLayer* pCurLayer = pCtx->pCurDqLayer;
36983699 SSliceCtx* pSliceCtx = pCurLayer->pSliceEncCtx;
3699− int32_t iNalLen[MAX_NAL_UNITS_IN_LAYER] = {0};
37003700 int32_t iNalIdxInLayer = *pNalIdxInLayer;
37013701 int32_t iSliceIdx = iStartSliceIdx;
37023702 const int32_t kiSliceStep = pCtx->iActiveThreadsNum;
@@ -3727,7 +3727,7 @@ int32_t WelsCodeOnePicPartition (sWelsEncCtx* pCtx, · 24 unmodified lines
37273727 }
37283728
37293729 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);
37313731 WELS_VERIFY_RETURN_IFNEQ (iReturn, ENC_RETURN_SUCCESS)
37323732 iPartitionBsSize += iPayloadSize;
37333733 }
@@ -3741,13 +3741,12 @@ int32_t WelsCodeOnePicPartition (sWelsEncCtx* pCtx, · 7 unmodified lines
37413741 &pCtx->pCurDqLayer->sLayerInfo.sNalHeaderExt,
37423742 pCtx->iFrameBsSize - pCtx->iPosBsBuffer,
37433743 pCtx->pFrameBs + pCtx->iPosBsBuffer,
3744− &iNalLen[iNalIdxInLayer]);
3744+ &pLayerBsInfo->pNalLengthInByte[iNalIdxInLayer]);
37453745 WELS_VERIFY_RETURN_IFNEQ (iReturn, ENC_RETURN_SUCCESS)
3746− iSliceSize = iNalLen[iNalIdxInLayer];
3746+ iSliceSize = pLayerBsInfo->pNalLengthInByte[iNalIdxInLayer];
37473747
37483748 pCtx->iPosBsBuffer += iSliceSize;
37493749 iPartitionBsSize += iSliceSize;
3750− pLayerBsInfo->iNalLengthInByte[iNalIdxInLayer] = iSliceSize;
37513750
37523751 #if defined(SLICE_INFO_OUTPUT)
37533752 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