Showing the changes to codec/encoder/core/src/svc_encode_slice.cpp (1 of 8 files). Show all
Unified · Split
| @@ -94,8 +94,6 @@ void WelsSliceHeaderExtInit (sWelsEncCtx* pEncCtx, SDqLayer* pCurLayer, SSlice* · 93 unmodified lines | ||
| 94 | 94 | |
| 95 | 95 | pCurSliceExt->bStoreRefBasePicFlag = false; |
| 96 | 96 | |
| 97 | − pCurSliceHeader->iFirstMbInSlice = WelsGetFirstMbOfSlice (pCurLayer->ppSliceInLayer, pSlice->uiSliceIdx); | |
| 98 | − | |
| 99 | 97 | pCurSliceHeader->iFrameNum = pParamInternal->iFrameNum; |
| 100 | 98 | pCurSliceHeader->uiIdrPicId = pParamInternal->uiIdrPicId; |
| 101 | 99 | pCurSliceHeader->iPicOrderCntLsb = pEncCtx->pEncPic->iFramePoc; // 0 |
| @@ -814,49 +812,64 @@ void FreeMbCache (SMbCache* pMbCache, CMemoryAlign* pMa) { · 712 unmodified lines | ||
| 814 | 812 | } |
| 815 | 813 | } |
| 816 | 814 | |
| 817 | −//Initialize slice's MB info) | |
| 818 | −int32_t InitSliceMBInfo (SSliceArgument* pSliceArgument, | |
| 819 | − SSlice* pSlice, | |
| 820 | − const int32_t kiMBWidth, | |
| 821 | − const int32_t kiMBHeight) { | |
| 822 | − SSliceHeader* pSliceHeader = &pSlice->sSliceHeaderExt.sSliceHeader; | |
| 815 | +//Initialize slice's boundary info) | |
| 816 | +int32_t InitSliceBoundaryInfo (SDqLayer* pCurLayer, SSliceArgument* pSliceArgument) { | |
| 817 | + | |
| 823 | 818 | const int32_t* kpSlicesAssignList = (int32_t*) & (pSliceArgument->uiSliceMbNum[0]); |
| 819 | + const int32_t kiMBWidth = pCurLayer->iMbWidth; | |
| 820 | + const int32_t kiMBHeight = pCurLayer->iMbHeight; | |
| 824 | 821 | const int32_t kiCountNumMbInFrame = kiMBWidth * kiMBHeight; |
| 825 | − const int32_t kiSliceIdx = pSlice->uiSliceIdx; | |
| 822 | + int32_t iSliceIdx = 0; | |
| 826 | 823 | int32_t iFirstMBInSlice = 0; |
| 827 | 824 | int32_t iMbNumInSlice = 0; |
| 828 | 825 | |
| 829 | − if (SM_SINGLE_SLICE == pSliceArgument->uiSliceMode) { | |
| 830 | − iFirstMBInSlice = 0; | |
| 831 | − iMbNumInSlice = kiCountNumMbInFrame; | |
| 826 | + for( ;iSliceIdx < pCurLayer->iMaxSliceNum; iSliceIdx++ ){ | |
| 827 | + if (SM_SINGLE_SLICE == pSliceArgument->uiSliceMode) { | |
| 828 | + iFirstMBInSlice = 0; | |
| 829 | + iMbNumInSlice = kiCountNumMbInFrame; | |
| 832 | 830 | |
| 833 | − } else if ((SM_RASTER_SLICE == pSliceArgument->uiSliceMode) && (0 == pSliceArgument->uiSliceMbNum[0])) { | |
| 834 | − iFirstMBInSlice = kiSliceIdx * kiMBWidth; | |
| 835 | − iMbNumInSlice = kiMBWidth; | |
| 836 | − } else if (SM_RASTER_SLICE == pSliceArgument->uiSliceMode || | |
| 831 | + } else if ((SM_RASTER_SLICE == pSliceArgument->uiSliceMode) && (0 == pSliceArgument->uiSliceMbNum[0])) { | |
| 832 | + iFirstMBInSlice = iSliceIdx * kiMBWidth; | |
| 833 | + iMbNumInSlice = kiMBWidth; | |
| 834 | + } else if (SM_RASTER_SLICE == pSliceArgument->uiSliceMode || | |
| 837 | 835 | SM_FIXEDSLCNUM_SLICE == pSliceArgument->uiSliceMode) { |
| 838 | − int32_t iMbIdx = 0; | |
| 839 | − for (int i = 0; i < kiSliceIdx; i++) { | |
| 840 | − iMbIdx += kpSlicesAssignList[i]; | |
| 841 | − } | |
| 836 | + int32_t iMbIdx = 0; | |
| 837 | + for (int i = 0; i < iSliceIdx; i++) { | |
| 838 | + iMbIdx += kpSlicesAssignList[i]; | |
| 839 | + } | |
| 842 | 840 | |
| 843 | − if (iMbIdx >= kiCountNumMbInFrame) { | |
| 844 | − return ENC_RETURN_UNEXPECTED; | |
| 841 | + if (iMbIdx >= kiCountNumMbInFrame) { | |
| 842 | + return ENC_RETURN_UNEXPECTED; | |
| 843 | + } | |
| 844 | + | |
| 845 | + iFirstMBInSlice = iMbIdx; | |
| 846 | + iMbNumInSlice = kpSlicesAssignList[iSliceIdx]; | |
| 847 | + | |
| 848 | + } else if (SM_SIZELIMITED_SLICE == pSliceArgument->uiSliceMode) { | |
| 849 | + iFirstMBInSlice = 0; | |
| 850 | + iMbNumInSlice = kiCountNumMbInFrame; | |
| 851 | + | |
| 852 | + } else { // any else uiSliceMode? | |
| 853 | + assert (0); | |
| 845 | 854 | } |
| 846 | 855 | |
| 847 | − iFirstMBInSlice = iMbIdx; | |
| 848 | − iMbNumInSlice = kpSlicesAssignList[kiSliceIdx]; | |
| 856 | + pCurLayer->pCountMbNumInSlice[iSliceIdx] = iMbNumInSlice; | |
| 857 | + pCurLayer->pFirstMbIdxOfSlice[iSliceIdx] = iFirstMBInSlice; | |
| 858 | + } | |
| 859 | + | |
| 860 | + return ENC_RETURN_SUCCESS; | |
| 861 | +} | |
| 849 | 862 | |
| 850 | − } else if (SM_SIZELIMITED_SLICE == pSliceArgument->uiSliceMode) { | |
| 851 | − iFirstMBInSlice = 0; | |
| 852 | − iMbNumInSlice = kiCountNumMbInFrame; | |
| 863 | +int32_t SetSliceBoundaryInfo(SDqLayer* pCurLayer, SSlice* pSlice, const int32_t kiSliceIdx) { | |
| 864 | + if(NULL == pCurLayer || NULL == pSlice || | |
| 865 | + NULL == pCurLayer->pFirstMbIdxOfSlice || | |
| 866 | + NULL == pCurLayer->pCountMbNumInSlice) { | |
| 853 | 867 | |
| 854 | − } else { // any else uiSliceMode? | |
| 855 | − assert (0); | |
| 868 | + return ENC_RETURN_UNEXPECTED; | |
| 856 | 869 | } |
| 857 | 870 | |
| 858 | − pSlice->iCountMbNumInSlice = iMbNumInSlice; | |
| 859 | − pSliceHeader->iFirstMbInSlice = iFirstMBInSlice; | |
| 871 | + pSlice->sSliceHeaderExt.sSliceHeader.iFirstMbInSlice = pCurLayer->pFirstMbIdxOfSlice[kiSliceIdx]; | |
| 872 | + pSlice->iCountMbNumInSlice = pCurLayer->pCountMbNumInSlice[kiSliceIdx]; | |
| 860 | 873 | |
| 861 | 874 | return ENC_RETURN_SUCCESS; |
| 862 | 875 | } |
| @@ -941,9 +954,11 @@ int32_t InitSliceList (sWelsEncCtx* pCtx, · 78 unmodified lines | ||
| 941 | 954 | } |
| 942 | 955 | |
| 943 | 956 | pSlice->uiSliceIdx = iSliceIdx; |
| 957 | + pSlice->iCountMbNumInSlice = 0; | |
| 958 | + pSlice->sSliceHeaderExt.sSliceHeader.iFirstMbInSlice = 0; | |
| 944 | 959 | |
| 945 | 960 | iRet = InitSliceBsBuffer (pSlice, |
| 946 | − & pCtx->pOut->sBsWrite, | |
| 961 | + &pCtx->pOut->sBsWrite, | |
| 947 | 962 | bIndependenceBsBuffer, |
| 948 | 963 | iMaxSliceBufferSize, |
| 949 | 964 | pMa); |
| @@ -951,12 +966,6 @@ int32_t InitSliceList (sWelsEncCtx* pCtx, · 1 unmodified line | ||
| 951 | 966 | return iRet; |
| 952 | 967 | } |
| 953 | 968 | |
| 954 | − iRet = InitSliceMBInfo (pSliceArgument, pSlice, | |
| 955 | − kiMBWidth, kiMBHeight); | |
| 956 | − | |
| 957 | − if (ENC_RETURN_SUCCESS != iRet) { | |
| 958 | − return iRet; | |
| 959 | − } | |
| 960 | 969 | iRet = AllocateSliceMBBuffer (pSlice, pMa); |
| 961 | 970 | |
| 962 | 971 | if (ENC_RETURN_SUCCESS != iRet) { |
| @@ -993,11 +1002,6 @@ int32_t InitOneSliceInThread (sWelsEncCtx* pCtx, · 30 unmodified lines | ||
| 993 | 1002 | pSlice->sSliceBs.iNalIndex = 0; |
| 994 | 1003 | pSlice->sSliceBs.pBsBuffer = pCtx->pSliceThreading->pThreadBsBuffer[kiThreadIdx]; |
| 995 | 1004 | |
| 996 | − // init slice MB info | |
| 997 | − iRet = InitSliceMBInfo (pSliceArgument, pSlice, kiMBWidth, kiMBHeight); | |
| 998 | − if (ENC_RETURN_SUCCESS != iRet) { | |
| 999 | − return iRet; | |
| 1000 | − } | |
| 1001 | 1005 | return ENC_RETURN_SUCCESS; |
| 1002 | 1006 | } |
| 1003 | 1007 | */ |
| @@ -1073,6 +1077,11 @@ int32_t InitSliceInLayer (sWelsEncCtx* pCtx, · 69 unmodified lines | ||
| 1073 | 1077 | return ENC_RETURN_MEMALLOCERR; |
| 1074 | 1078 | } |
| 1075 | 1079 | |
| 1080 | + iRet = InitSliceBoundaryInfo (pDqLayer, &pCtx->pSvcParam->sSpatialLayers[kiDlayerIndex].sSliceArgument); | |
| 1081 | + if (ENC_RETURN_SUCCESS != iRet) { | |
| 1082 | + return iRet; | |
| 1083 | + } | |
| 1084 | + | |
| 1076 | 1085 | InitSliceThreadInfo (pCtx, |
| 1077 | 1086 | pDqLayer, |
| 1078 | 1087 | kiDlayerIndex, |
| @@ -1142,7 +1151,6 @@ int32_t ReallocateSliceList (sWelsEncCtx* pCtx, · 63 unmodified lines | ||
| 1142 | 1151 | const int32_t kiMaxSliceNumOld, |
| 1143 | 1152 | const int32_t kiMaxSliceNumNew) { |
| 1144 | 1153 | CMemoryAlign* pMA = pCtx->pMemAlign; |
| 1145 | − SDqLayer* pCurLayer = pCtx->pCurDqLayer; | |
| 1146 | 1154 | SSlice* pBaseSlice = NULL; |
| 1147 | 1155 | SSlice* pNewSliceList = NULL; |
| 1148 | 1156 | SSlice* pSlice = NULL; |
| @@ -1181,6 +1189,8 @@ int32_t ReallocateSliceList (sWelsEncCtx* pCtx, · 32 unmodified lines | ||
| 1181 | 1189 | } |
| 1182 | 1190 | |
| 1183 | 1191 | pSlice->uiSliceIdx = iSliceIdx; |
| 1192 | + pSlice->iCountMbNumInSlice = 0; | |
| 1193 | + pSlice->sSliceHeaderExt.sSliceHeader.iFirstMbInSlice = 0; | |
| 1184 | 1194 | |
| 1185 | 1195 | iRet = InitSliceBsBuffer (pSlice, |
| 1186 | 1196 | & pCtx->pOut->sBsWrite, |
| @@ -1198,15 +1208,6 @@ int32_t ReallocateSliceList (sWelsEncCtx* pCtx, · 11 unmodified lines | ||
| 1198 | 1208 | return iRet; |
| 1199 | 1209 | } |
| 1200 | 1210 | |
| 1201 | − iRet = InitSliceMBInfo (pSliceArgument, | |
| 1202 | − pSlice, | |
| 1203 | − pCurLayer->iMbWidth, | |
| 1204 | − pCurLayer->iMbHeight); | |
| 1205 | − if (ENC_RETURN_SUCCESS != iRet) { | |
| 1206 | − FreeSliceBuffer(pNewSliceList, kiMaxSliceNumNew, pMA, "ReallocateSliceList()::InitSliceBsBuffer()"); | |
| 1207 | − return iRet; | |
| 1208 | − } | |
| 1209 | − | |
| 1210 | 1211 | InitSliceHeadWithBase (pSlice, pBaseSlice); |
| 1211 | 1212 | InitSliceRefInfoWithBase (pSlice, pBaseSlice, pCtx->iNumRef0); |
| 1212 | 1213 | |
| @@ -1357,6 +1358,7 @@ int32_t ReallocSliceBuffer (sWelsEncCtx* pCtx) { · 144 unmodified lines | ||
| 1357 | 1358 | return ENC_RETURN_SUCCESS; |
| 1358 | 1359 | } |
| 1359 | 1360 | |
| 1361 | + | |
| 1360 | 1362 | /* |
| 1361 | 1363 | int32_t ReOrderSliceInLayer (SDqLayer* pCurLayer, |
| 1362 | 1364 | const int32_t kiThreadNum, |