History

refactor for slice buffer init/allocate/free

huade committed 10 years ago

Commit a7a5b7b1 parent 33bb96f7 files · +334 −158Browse files

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

Unified · Split

codec/encoder/core/src/svc_encode_slice.cpp+165−8
@@ -89,7 +89,7 @@ void WelsSliceHeaderScalExtInit (SDqLayer* pCurLayer, SSlice* pSlice) { · 88 unmodified lines
89void WelsSliceHeaderExtInit (sWelsEncCtx* pEncCtx, SDqLayer* pCurLayer, SSlice* pSlice) {89void WelsSliceHeaderExtInit (sWelsEncCtx* pEncCtx, SDqLayer* pCurLayer, SSlice* pSlice) {
90 SSliceHeaderExt* pCurSliceExt = &pSlice->sSliceHeaderExt;90 SSliceHeaderExt* pCurSliceExt = &pSlice->sSliceHeaderExt;
91 SSliceHeader* pCurSliceHeader = &pCurSliceExt->sSliceHeader;91 SSliceHeader* pCurSliceHeader = &pCurSliceExt->sSliceHeader;
92 SSpatialLayerInternal *pParamInternal = &pEncCtx->pSvcParam->sDependencyLayers[pEncCtx->uiDependencyId];92 SSpatialLayerInternal* pParamInternal = &pEncCtx->pSvcParam->sDependencyLayers[pEncCtx->uiDependencyId];
93 pCurSliceHeader->eSliceType = pEncCtx->eSliceType;93 pCurSliceHeader->eSliceType = pEncCtx->eSliceType;
94 94
95 pCurSliceExt->bStoreRefBasePicFlag = false;95 pCurSliceExt->bStoreRefBasePicFlag = false;
@@ -138,7 +138,7 @@ void WelsSliceHeaderExtInit (sWelsEncCtx* pEncCtx, SDqLayer* pCurLayer, SSlice* · 42 unmodified lines
138}138}
139 139
140 140
141void UpdateMbNeighbor(SDqLayer* pCurDq, SMB* pMb, const int32_t kiMbWidth, uint16_t uiSliceIdc) {141void UpdateMbNeighbor (SDqLayer* pCurDq, SMB* pMb, const int32_t kiMbWidth, uint16_t uiSliceIdc) {
142 uint32_t uiNeighborAvailFlag = 0;142 uint32_t uiNeighborAvailFlag = 0;
143 const int32_t kiMbXY = pMb->iMbXY;143 const int32_t kiMbXY = pMb->iMbXY;
144 const int32_t kiMbX = pMb->iMbX;144 const int32_t kiMbX = pMb->iMbX;
@@ -298,7 +298,7 @@ void WelsSliceHeaderWrite (sWelsEncCtx* pCtx, SBitStringAux* pBs, SDqLayer* pCur · 153 unmodified lines
298 if (P_SLICE == pSliceHeader->eSliceType) {298 if (P_SLICE == pSliceHeader->eSliceType) {
299 BsWriteOneBit (pBs, pSliceHeader->bNumRefIdxActiveOverrideFlag);299 BsWriteOneBit (pBs, pSliceHeader->bNumRefIdxActiveOverrideFlag);
300 if (pSliceHeader->bNumRefIdxActiveOverrideFlag) {300 if (pSliceHeader->bNumRefIdxActiveOverrideFlag) {
301 BsWriteUE (pBs, WELS_CLIP3(pSliceHeader->uiNumRefIdxL0Active - 1, 0, MAX_REF_PIC_COUNT));301 BsWriteUE (pBs, WELS_CLIP3 (pSliceHeader->uiNumRefIdxL0Active - 1, 0, MAX_REF_PIC_COUNT));
302 }302 }
303 }303 }
304 304
@@ -366,7 +366,7 @@ void WelsSliceHeaderExtWrite (sWelsEncCtx* pCtx, SBitStringAux* pBs, SDqLayer* p · 61 unmodified lines
366 if (P_SLICE == pSliceHeader->eSliceType) {366 if (P_SLICE == pSliceHeader->eSliceType) {
367 BsWriteOneBit (pBs, pSliceHeader->bNumRefIdxActiveOverrideFlag);367 BsWriteOneBit (pBs, pSliceHeader->bNumRefIdxActiveOverrideFlag);
368 if (pSliceHeader->bNumRefIdxActiveOverrideFlag) {368 if (pSliceHeader->bNumRefIdxActiveOverrideFlag) {
369 BsWriteUE (pBs, WELS_CLIP3(pSliceHeader->uiNumRefIdxL0Active - 1, 0, MAX_REF_PIC_COUNT));369 BsWriteUE (pBs, WELS_CLIP3 (pSliceHeader->uiNumRefIdxL0Active - 1, 0, MAX_REF_PIC_COUNT));
370 }370 }
371 }371 }
372 372
@@ -521,7 +521,7 @@ void UpdateQpForOverflow (SMB* pCurMb, uint8_t kuiChromaQpIndexOffset) { · 148 unmodified lines
521//second. lower than highest Dependency Layer, and for every Dependency Layer with one quality layer(single layer)521//second. lower than highest Dependency Layer, and for every Dependency Layer with one quality layer(single layer)
522int32_t WelsISliceMdEnc (sWelsEncCtx* pEncCtx, SSlice* pSlice) { //pMd + encoding522int32_t WelsISliceMdEnc (sWelsEncCtx* pEncCtx, SSlice* pSlice) { //pMd + encoding
523 SDqLayer* pCurLayer = pEncCtx->pCurDqLayer;523 SDqLayer* pCurLayer = pEncCtx->pCurDqLayer;
524 SMbCache* pMbCache = &pSlice->sMbCacheInfo;524 SMbCache* pMbCache = &pSlice->sMbCacheInfo;
525 SSliceHeaderExt* pSliceHdExt = &pSlice->sSliceHeaderExt;525 SSliceHeaderExt* pSliceHdExt = &pSlice->sSliceHeaderExt;
526 SMB* pMbList = pCurLayer->sMbDataP;526 SMB* pMbList = pCurLayer->sMbDataP;
527 SMB* pCurMb = NULL;527 SMB* pCurMb = NULL;
@@ -746,6 +746,163 @@ static const PWelsSliceHeaderWriteFunc g_pWelsWriteSliceHeader[2] = { // 0: for · 218 unmodified lines
746 WelsSliceHeaderExtWrite746 WelsSliceHeaderExtWrite
747};747};
748 748
749//Allocate slice's MB cache buffer
750int32_t AllocMbCacheAligned (SMbCache* pMbCache, CMemoryAlign* pMa) {
751 pMbCache->pCoeffLevel = (int16_t*)pMa->WelsMallocz (MB_COEFF_LIST_SIZE * sizeof (int16_t), "pMbCache->pCoeffLevel");
752 WELS_VERIFY_RETURN_IF (1, (NULL == pMbCache->pCoeffLevel));
753 pMbCache->pMemPredMb = (uint8_t*)pMa->WelsMallocz (2 * 256 * sizeof (uint8_t), "pMbCache->pMemPredMb");
754 WELS_VERIFY_RETURN_IF (1, (NULL == pMbCache->pMemPredMb));
755 pMbCache->pSkipMb = (uint8_t*)pMa->WelsMallocz (384 * sizeof (uint8_t), "pMbCache->pSkipMb");
756 WELS_VERIFY_RETURN_IF (1, (NULL == pMbCache->pSkipMb));
757 pMbCache->pMemPredBlk4 = (uint8_t*)pMa->WelsMallocz (2 * 16 * sizeof (uint8_t), "pMbCache->pMemPredBlk4");
758 WELS_VERIFY_RETURN_IF (1, (NULL == pMbCache->pMemPredBlk4));
759 pMbCache->pBufferInterPredMe = (uint8_t*)pMa->WelsMallocz (4 * 640 * sizeof (uint8_t), "pMbCache->pBufferInterPredMe");
760 WELS_VERIFY_RETURN_IF (1, (NULL == pMbCache->pBufferInterPredMe));
761 pMbCache->pPrevIntra4x4PredModeFlag = (bool*)pMa->WelsMallocz (16 * sizeof (bool),
762 "pMbCache->pPrevIntra4x4PredModeFlag");
763 WELS_VERIFY_RETURN_IF (1, (NULL == pMbCache->pPrevIntra4x4PredModeFlag));
764 pMbCache->pRemIntra4x4PredModeFlag = (int8_t*)pMa->WelsMallocz (16 * sizeof (int8_t),
765 "pMbCache->pRemIntra4x4PredModeFlag");
766 WELS_VERIFY_RETURN_IF (1, (NULL == pMbCache->pRemIntra4x4PredModeFlag));
767 pMbCache->pDct = (SDCTCoeff*)pMa->WelsMallocz (sizeof (SDCTCoeff), "pMbCache->pDct");
768 WELS_VERIFY_RETURN_IF (1, (NULL == pMbCache->pDct));
769
770 return 0;
771}
772
773// Free slice's MB cache buffer
774void FreeMbCache (SMbCache* pMbCache, CMemoryAlign* pMa) {
775 if (NULL != pMbCache->pCoeffLevel) {
776 pMa->WelsFree (pMbCache->pCoeffLevel, "pMbCache->pCoeffLevel");
777 pMbCache->pCoeffLevel = NULL;
778 }
779 if (NULL != pMbCache->pMemPredMb) {
780 pMa->WelsFree (pMbCache->pMemPredMb, "pMbCache->pMemPredMb");
781 pMbCache->pMemPredMb = NULL;
782 }
783 if (NULL != pMbCache->pSkipMb) {
784 pMa->WelsFree (pMbCache->pSkipMb, "pMbCache->pSkipMb");
785 pMbCache->pSkipMb = NULL;
786 }
787 if (NULL != pMbCache->pMemPredBlk4) {
788 pMa->WelsFree (pMbCache->pMemPredBlk4, "pMbCache->pMemPredBlk4");
789 pMbCache->pMemPredBlk4 = NULL;
790 }
791 if (NULL != pMbCache->pBufferInterPredMe) {
792 pMa->WelsFree (pMbCache->pBufferInterPredMe, "pMbCache->pBufferInterPredMe");
793 pMbCache->pBufferInterPredMe = NULL;
794 }
795 if (NULL != pMbCache->pPrevIntra4x4PredModeFlag) {
796 pMa->WelsFree (pMbCache->pPrevIntra4x4PredModeFlag, "pMbCache->pPrevIntra4x4PredModeFlag");
797 pMbCache->pPrevIntra4x4PredModeFlag = NULL;
798 }
799 if (NULL != pMbCache->pRemIntra4x4PredModeFlag) {
800 pMa->WelsFree (pMbCache->pRemIntra4x4PredModeFlag, "pMbCache->pRemIntra4x4PredModeFlag");
801 pMbCache->pRemIntra4x4PredModeFlag = NULL;
802 }
803 if (NULL != pMbCache->pDct) {
804 pMa->WelsFree (pMbCache->pDct, "pMbCache->pDct");
805 pMbCache->pDct = NULL;
806 }
807}
808
809//Initialize slice's MB info)
810int32_t InitSliceMBInfo (SSliceArgument* pSliceArgument,
811 SSlice* pSlice,
812 const int32_t kiMBWidth,
813 const int32_t kiMBHeight,
814 CMemoryAlign* pMa) {
815 SSliceHeader* pSliceHeader = &pSlice->sSliceHeaderExt.sSliceHeader;
816 const int32_t* kpSlicesAssignList = (int32_t*) & (pSliceArgument->uiSliceMbNum[0]);
817 const int32_t kiCountNumMbInFrame = kiMBWidth * kiMBHeight;
818 const int32_t kiSliceIdx = pSlice->uiSliceIdx;
819 int32_t iFirstMBInSlice = 0;
820 int32_t iMbNumInSlice = 0;
821
822 if (SM_SINGLE_SLICE == pSliceArgument->uiSliceMode) {
823 iFirstMBInSlice = 0;
824 iMbNumInSlice = kiCountNumMbInFrame;
825
826 } else if ((SM_RASTER_SLICE == pSliceArgument->uiSliceMode) && (0 == pSliceArgument->uiSliceMbNum[0])) {
827 iFirstMBInSlice = kiSliceIdx * kiMBWidth;
828 iMbNumInSlice = kiMBWidth;
829 } else if (SM_RASTER_SLICE == pSliceArgument->uiSliceMode ||
830 SM_FIXEDSLCNUM_SLICE == pSliceArgument->uiSliceMode) {
831 int32_t iMbIdx = 0;
832 for (int i = 0; i < kiSliceIdx; i++) {
833 iMbIdx += kpSlicesAssignList[i];
834 }
835
836 if (iMbIdx >= kiCountNumMbInFrame)
837 return ENC_RETURN_UNEXPECTED;
838
839 iFirstMBInSlice = iMbIdx;
840 iMbNumInSlice = kpSlicesAssignList[kiSliceIdx];
841
842 } else if (SM_SIZELIMITED_SLICE == pSliceArgument->uiSliceMode) {
843 iFirstMBInSlice = 0;
844 iMbNumInSlice = kiCountNumMbInFrame;
845
846 } else { // any else uiSliceMode?
847 assert (0);
848 }
849
850 pSlice->iCountMbNumInSlice = iMbNumInSlice;
851 pSliceHeader->iFirstMbInSlice = iFirstMBInSlice;
852
853 return ENC_RETURN_SUCCESS;
854}
855
856//Allocate slice's MB info buffer
857int32_t AllocateSliceMBBuffer (SSlice* pSlice, CMemoryAlign* pMa) {
858 if (AllocMbCacheAligned (&pSlice->sMbCacheInfo, pMa)) {
859 return ENC_RETURN_MEMALLOCERR;
860 }
861
862 return ENC_RETURN_SUCCESS;
863}
864
865// Initialize slice bs buffer info
866int32_t InitSliceBsBuffer (SSlice* pSlice,
867 SBitStringAux* pBsWrite,
868 bool bIndependenceBsBuffer,
869 const int32_t iMaxSliceBufferSize,
870 CMemoryAlign* pMa) {
871 pSlice->sSliceBs.uiSize = iMaxSliceBufferSize;
872 pSlice->sSliceBs.uiBsPos = 0;
873
874 if (bIndependenceBsBuffer) {
875 pSlice->pSliceBsa = &pSlice->sSliceBs.sBsWrite;
876 pSlice->sSliceBs.pBs = (uint8_t*)pMa->WelsMalloc (iMaxSliceBufferSize, "SliceBs");
877 if (NULL == pSlice->sSliceBs.pBs) {
878 return ENC_RETURN_MEMALLOCERR;
879 }
880 } else {
881 pSlice->pSliceBsa = pBsWrite;
882 pSlice->sSliceBs.pBs = NULL;
883 }
884 return ENC_RETURN_SUCCESS;
885}
886
887//free slice bs buffer
888void FreeSliceBuffer (SSlice*& pSliceList, const int32_t kiMaxSliceNum, CMemoryAlign* pMa, const char* kpTag) {
889 if (NULL != pSliceList) {
890 int32_t iSliceIdx = 0;
891 while (iSliceIdx < kiMaxSliceNum) {
892 SSlice* pSlice = &pSliceList[iSliceIdx];
893 FreeMbCache (&pSlice->sMbCacheInfo, pMa);
894
895 //slice bs buffer
896 if (NULL != pSlice->sSliceBs.pBs) {
897 pMa->WelsFree (pSlice->sSliceBs.pBs, "sSliceBs.pBs");
898 pSlice->sSliceBs.pBs = NULL;
899 }
900 ++ iSliceIdx;
901 }
902 pMa->WelsFree (pSliceList, kpTag);
903 pSliceList = NULL;
904 }
905}
749 906
750int32_t WelsCodeOneSlice (sWelsEncCtx* pEncCtx, const int32_t kiSliceIdx, const int32_t kiNalType) {907int32_t WelsCodeOneSlice (sWelsEncCtx* pEncCtx, const int32_t kiSliceIdx, const int32_t kiNalType) {
751 SDqLayer* pCurLayer = pEncCtx->pCurDqLayer;908 SDqLayer* pCurLayer = pEncCtx->pCurDqLayer;
@@ -753,8 +910,8 @@ int32_t WelsCodeOneSlice (sWelsEncCtx* pEncCtx, const int32_t kiSliceIdx, const · 1 unmodified line
753 SSlice* pCurSlice = &pCurLayer->sLayerInfo.pSliceInLayer[kiSliceIdx];910 SSlice* pCurSlice = &pCurLayer->sLayerInfo.pSliceInLayer[kiSliceIdx];
754 SBitStringAux* pBs = pCurSlice->pSliceBsa;911 SBitStringAux* pBs = pCurSlice->pSliceBsa;
755 const int32_t kiDynamicSliceFlag = (pEncCtx->pSvcParam->sSpatialLayers[pEncCtx->uiDependencyId].sSliceArgument.uiSliceMode912 const int32_t kiDynamicSliceFlag = (pEncCtx->pSvcParam->sSpatialLayers[pEncCtx->uiDependencyId].sSliceArgument.uiSliceMode
756 ==913 ==
757 SM_SIZELIMITED_SLICE);914 SM_SIZELIMITED_SLICE);
758 915
759 assert (kiSliceIdx == (int) pCurSlice->uiSliceIdx);916 assert (kiSliceIdx == (int) pCurSlice->uiSliceIdx);
760 917
@@ -805,7 +962,7 @@ void UpdateMbNeighbourInfoForNextSlice (SDqLayer* pCurDq, · 44 unmodified lines
805 int32_t iIdx = kiFirstMbIdxOfNextSlice;962 int32_t iIdx = kiFirstMbIdxOfNextSlice;
806 int32_t iNextSliceFirstMbIdxRowStart = ((kiFirstMbIdxOfNextSlice % kiMbWidth) ? 1 : 0);963 int32_t iNextSliceFirstMbIdxRowStart = ((kiFirstMbIdxOfNextSlice % kiMbWidth) ? 1 : 0);
807 int32_t iCountMbUpdate = kiMbWidth +964 int32_t iCountMbUpdate = kiMbWidth +
808 iNextSliceFirstMbIdxRowStart; //need to update MB(iMbXY+1) to MB(iMbXY+1+row) in common case965 iNextSliceFirstMbIdxRowStart; //need to update MB(iMbXY+1) to MB(iMbXY+1+row) in common case
809 const int32_t kiEndMbNeedUpdate = kiFirstMbIdxOfNextSlice + iCountMbUpdate;966 const int32_t kiEndMbNeedUpdate = kiFirstMbIdxOfNextSlice + iCountMbUpdate;
810 SMB* pMb = &pMbList[iIdx];967 SMB* pMb = &pMbList[iIdx];
811 968

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