[Encoder] Fixing for large number of slices
Unified · Split
| @@ -42,6 +42,7 @@ · 41 unmodified lines | |||
| 42 | 42 | ||
| 43 | #include <math.h> | 43 | #include <math.h> |
| 44 | #include <assert.h> | 44 | #include <assert.h> |
| 45 | #include <string.h> | ||
| 45 | #include "typedefs.h" | 46 | #include "typedefs.h" |
| 46 | 47 | ||
| 47 | 48 | ||
| @@ -273,8 +274,36 @@ static inline bool WELS_POWER2_IF (uint32_t v) { · 225 unmodified lines | |||
| 273 | #endif | 274 | #endif |
| 274 | 275 | ||
| 275 | inline bool CheckInRangeCloseOpen (const int16_t kiCurrent, const int16_t kiMin, const int16_t kiMax) { | 276 | inline bool CheckInRangeCloseOpen (const int16_t kiCurrent, const int16_t kiMin, const int16_t kiMax) { |
| 276 | return ((kiCurrent >= kiMin) && (kiCurrent < kiMax)); | 277 | return ((kiCurrent >= kiMin) && (kiCurrent < kiMax)); |
| 277 | } | 278 | } |
| 278 | 279 | ||
| 280 | static inline void WelsSetMemUint32_c (uint32_t* pDst, uint32_t iValue, int32_t iSizeOfData) { | ||
| 281 | for (int i = 0; i < iSizeOfData; i++) { | ||
| 282 | pDst[i] = iValue; | ||
| 283 | } | ||
| 284 | } | ||
| 285 | |||
| 286 | static inline void WelsSetMemUint16_c (uint16_t* pDst, uint16_t iValue, int32_t iSizeOfData) { | ||
| 287 | for (int i = 0; i < iSizeOfData; i++) { | ||
| 288 | pDst[i] = iValue; | ||
| 289 | } | ||
| 290 | } | ||
| 291 | |||
| 292 | inline void WelsSetMemMultiplebytes_c (void* pDst, uint32_t iValue, int32_t iSizeOfData, int32_t iDataLengthOfData) { | ||
| 293 | assert (4 == iDataLengthOfData || 2 == iDataLengthOfData || 1 == iDataLengthOfData); | ||
| 294 | |||
| 295 | // TODO: consider add assembly for these functions | ||
| 296 | if (0 != iValue) { | ||
| 297 | if (4 == iDataLengthOfData) { | ||
| 298 | WelsSetMemUint32_c (static_cast<uint32_t*> (pDst), static_cast<uint32_t> (iValue), iSizeOfData); | ||
| 299 | } else if (2 == iDataLengthOfData) { | ||
| 300 | WelsSetMemUint16_c (static_cast<uint16_t*> (pDst), static_cast<uint16_t> (iValue), iSizeOfData); | ||
| 301 | } else { | ||
| 302 | memset (static_cast<uint8_t*> (pDst), static_cast<uint8_t> (iValue), iSizeOfData); | ||
| 303 | } | ||
| 304 | } else { | ||
| 305 | memset (static_cast<uint8_t*> (pDst), 0, iSizeOfData * iDataLengthOfData); | ||
| 306 | } | ||
| 307 | } | ||
| 279 | 308 | ||
| 280 | #endif//WELS_MACRO_UTILIZATIONS_H__ | 309 | #endif//WELS_MACRO_UTILIZATIONS_H__ |
| @@ -68,12 +68,12 @@ SMVUnitXY sP16x16Mv; · 67 unmodified lines | |||
| 68 | 68 | ||
| 69 | uint8_t uiLumaQp; // uiLumaQp: pPps->iInitialQp + sSliceHeader->delta_qp + mb->dquant. | 69 | uint8_t uiLumaQp; // uiLumaQp: pPps->iInitialQp + sSliceHeader->delta_qp + mb->dquant. |
| 70 | uint8_t uiChromaQp; | 70 | uint8_t uiChromaQp; |
| 71 | uint8_t uiSliceIdc; // AVC: pFirstMbInSlice?; SVC: (pFirstMbInSlice << 7) | ((uiDependencyId << 4) | uiQualityId); | 71 | uint16_t uiSliceIdc; // 2^16=65536 > MaxFS(36864) of level 5.1; AVC: pFirstMbInSlice?; SVC: (pFirstMbInSlice << 7) | ((uiDependencyId << 4) | uiQualityId); |
| 72 | uint32_t uiChromPredMode; | 72 | uint32_t uiChromPredMode; |
| 73 | int32_t iLumaDQp; | 73 | int32_t iLumaDQp; |
| 74 | SMVUnitXY sMvd[4]; | 74 | SMVUnitXY sMvd[4]; |
| 75 | int32_t iCbpDc; | 75 | int32_t iCbpDc; |
| 76 | uint8_t reserved_filling_bytes[1]; // filling bytes reserved to make structure aligned with 4 bytes, higher cache hit on less structure size by 2 cache lines( 2 * 64 bytes) once hit | 76 | //uint8_t reserved_filling_bytes[1]; // not deleting this line for further changes of this structure. filling bytes reserved to make structure aligned with 4 bytes, higher cache hit on less structure size by 2 cache lines( 2 * 64 bytes) once hit |
| 77 | } SMB, *PMb; | 77 | } SMB, *PMb; |
| 78 | 78 | ||
| 79 | } | 79 | } |
| @@ -80,7 +80,7 @@ int16_t iMbWidth; /* width of picture size in mb */ · 79 unmodified lines | |||
| 80 | int16_t iMbHeight; /* height of picture size in mb */ | 80 | int16_t iMbHeight; /* height of picture size in mb */ |
| 81 | int16_t iSliceNumInFrame; /* count number of slices in frame; */ | 81 | int16_t iSliceNumInFrame; /* count number of slices in frame; */ |
| 82 | int32_t iMbNumInFrame; /* count number of MBs in frame */ | 82 | int32_t iMbNumInFrame; /* count number of MBs in frame */ |
| 83 | uint8_t* pOverallMbMap; /* overall MB map in frame, store virtual slice idc; */ | 83 | uint16_t* pOverallMbMap; /* overall MB map in frame, store virtual slice idc; */ |
| 84 | int16_t* pFirstMbInSlice; /* first MB address top-left based in every slice respectively; */ | 84 | int16_t* pFirstMbInSlice; /* first MB address top-left based in every slice respectively; */ |
| 85 | int32_t* pCountMbNumInSlice; /* count number of MBs in every slice respectively; */ | 85 | int32_t* pCountMbNumInSlice; /* count number of MBs in every slice respectively; */ |
| 86 | uint32_t uiSliceSizeConstraint;/*in byte*/ | 86 | uint32_t uiSliceSizeConstraint;/*in byte*/ |
| @@ -140,7 +140,7 @@ void UninitSlicePEncCtx (SSliceCtx* pSliceCtx, CMemoryAlign* pMa); · 53 unmodified lines | |||
| 140 | * | 140 | * |
| 141 | * \return uiSliceIdc - successful; (uint8_t)(-1) - failed; | 141 | * \return uiSliceIdc - successful; (uint8_t)(-1) - failed; |
| 142 | */ | 142 | */ |
| 143 | uint8_t WelsMbToSliceIdc (SSliceCtx* pSliceCtx, const int16_t kiMbXY); | 143 | uint16_t WelsMbToSliceIdc (SSliceCtx* pSliceCtx, const int16_t kiMbXY); |
| 144 | 144 | ||
| 145 | /*! | 145 | /*! |
| 146 | * \brief Get first mb in slice/slice_group: uiSliceIdc (apply in Single/multiple slices and FMO) | 146 | * \brief Get first mb in slice/slice_group: uiSliceIdc (apply in Single/multiple slices and FMO) |
| @@ -597,7 +597,7 @@ static void InitMbInfo (sWelsEncCtx* pEnc, SMB* pList, SDqLayer* pLayer, con · 596 unmodified lines | |||
| 597 | bool bLeftTop; | 597 | bool bLeftTop; |
| 598 | bool bRightTop; | 598 | bool bRightTop; |
| 599 | int32_t iLeftXY, iTopXY, iLeftTopXY, iRightTopXY; | 599 | int32_t iLeftXY, iTopXY, iLeftTopXY, iRightTopXY; |
| 600 | uint8_t uiSliceIdc; | 600 | uint16_t uiSliceIdc; |
| 601 | 601 | ||
| 602 | pList[iIdx].iMbX = pEnc->pStrideTab->pMbIndexX[kiDlayerId][iIdx]; | 602 | pList[iIdx].iMbX = pEnc->pStrideTab->pMbIndexX[kiDlayerId][iIdx]; |
| 603 | pList[iIdx].iMbY = pEnc->pStrideTab->pMbIndexY[kiDlayerId][iIdx]; | 603 | pList[iIdx].iMbY = pEnc->pStrideTab->pMbIndexY[kiDlayerId][iIdx]; |
| @@ -2272,7 +2272,7 @@ void DynslcUpdateMbNeighbourInfoListForAllSlices (SSliceCtx* pSliceCtx, SMB* pMb · 1668 unmodified lines | |||
| 2272 | bool bTop; | 2272 | bool bTop; |
| 2273 | bool bLeftTop; | 2273 | bool bLeftTop; |
| 2274 | bool bRightTop; | 2274 | bool bRightTop; |
| 2275 | int32_t uiSliceIdc; | 2275 | uint16_t uiSliceIdc; |
| 2276 | int32_t iLeftXY, iTopXY, iLeftTopXY, iRightTopXY; | 2276 | int32_t iLeftXY, iTopXY, iLeftTopXY, iRightTopXY; |
| 2277 | 2277 | ||
| 2278 | uiSliceIdc = WelsMbToSliceIdc (pSliceCtx, kiMbXY); | 2278 | uiSliceIdc = WelsMbToSliceIdc (pSliceCtx, kiMbXY); |
| @@ -2347,7 +2347,8 @@ void UpdateSlicepEncCtxWithPartition (SSliceCtx* pSliceCtx, int32_t iPartitionNu · 68 unmodified lines | |||
| 2347 | } | 2347 | } |
| 2348 | pSliceCtx->pFirstMbInSlice[i] = iFirstMbIdx; | 2348 | pSliceCtx->pFirstMbInSlice[i] = iFirstMbIdx; |
| 2349 | 2349 | ||
| 2350 | memset (pSliceCtx->pOverallMbMap + iFirstMbIdx, (uint8_t)i, pSliceCtx->pCountMbNumInSlice[i]*sizeof (uint8_t)); | 2350 | WelsSetMemMultiplebytes_c(pSliceCtx->pOverallMbMap + iFirstMbIdx, i, |
| 2351 | pSliceCtx->pCountMbNumInSlice[i], sizeof(uint16_t)); | ||
| 2351 | 2352 | ||
| 2352 | // for next partition(or pSlice) | 2353 | // for next partition(or pSlice) |
| 2353 | iFirstMbIdx += pSliceCtx->pCountMbNumInSlice[i]; | 2354 | iFirstMbIdx += pSliceCtx->pCountMbNumInSlice[i]; |
| @@ -3924,15 +3925,19 @@ int32_t DynSliceRealloc (sWelsEncCtx* pCtx, · 1570 unmodified lines | |||
| 3924 | iMaxSliceNum *= SLICE_NUM_EXPAND_COEF; | 3925 | iMaxSliceNum *= SLICE_NUM_EXPAND_COEF; |
| 3925 | 3926 | ||
| 3926 | SWelsNalRaw* pNalList = (SWelsNalRaw*)pMA->WelsMalloc (iCountNals * sizeof (SWelsNalRaw), "pOut->sNalList"); | 3927 | SWelsNalRaw* pNalList = (SWelsNalRaw*)pMA->WelsMalloc (iCountNals * sizeof (SWelsNalRaw), "pOut->sNalList"); |
| 3927 | if (NULL == pNalList) | 3928 | if (NULL == pNalList) { |
| 3929 | WelsLog (&(pCtx->sLogCtx), WELS_LOG_ERROR, "CWelsH264SVCEncoder::DynSliceRealloc: pNalList is NULL"); | ||
| 3928 | return ENC_RETURN_MEMALLOCERR; | 3930 | return ENC_RETURN_MEMALLOCERR; |
| 3931 | } | ||
| 3929 | memcpy (pNalList, pCtx->pOut->sNalList, sizeof (SWelsNalRaw) * pCtx->pOut->iCountNals); | 3932 | memcpy (pNalList, pCtx->pOut->sNalList, sizeof (SWelsNalRaw) * pCtx->pOut->iCountNals); |
| 3930 | pMA->WelsFree (pCtx->pOut->sNalList, "pOut->sNalList"); | 3933 | pMA->WelsFree (pCtx->pOut->sNalList, "pOut->sNalList"); |
| 3931 | pCtx->pOut->sNalList = pNalList; | 3934 | pCtx->pOut->sNalList = pNalList; |
| 3932 | 3935 | ||
| 3933 | int32_t* pNalLen = (int32_t*)pMA->WelsMalloc (iCountNals * sizeof (int32_t), "pOut->pNalLen"); | 3936 | int32_t* pNalLen = (int32_t*)pMA->WelsMalloc (iCountNals * sizeof (int32_t), "pOut->pNalLen"); |
| 3934 | if (NULL == pNalLen) | 3937 | if (NULL == pNalLen) { |
| 3938 | WelsLog (&(pCtx->sLogCtx), WELS_LOG_ERROR, "CWelsH264SVCEncoder::DynSliceRealloc: pNalLen is NULL"); | ||
| 3935 | return ENC_RETURN_MEMALLOCERR; | 3939 | return ENC_RETURN_MEMALLOCERR; |
| 3940 | } | ||
| 3936 | memcpy (pNalLen, pCtx->pOut->pNalLen, sizeof (int32_t) * pCtx->pOut->iCountNals); | 3941 | memcpy (pNalLen, pCtx->pOut->pNalLen, sizeof (int32_t) * pCtx->pOut->iCountNals); |
| 3937 | pMA->WelsFree (pCtx->pOut->pNalLen, "pOut->pNalLen"); | 3942 | pMA->WelsFree (pCtx->pOut->pNalLen, "pOut->pNalLen"); |
| 3938 | pCtx->pOut->pNalLen = pNalLen; | 3943 | pCtx->pOut->pNalLen = pNalLen; |
| @@ -3948,8 +3953,10 @@ int32_t DynSliceRealloc (sWelsEncCtx* pCtx, · 9 unmodified lines | |||
| 3948 | } | 3953 | } |
| 3949 | 3954 | ||
| 3950 | SSlice* pSlice = (SSlice*)pMA->WelsMallocz (sizeof (SSlice) * iMaxSliceNum, "Slice"); | 3955 | SSlice* pSlice = (SSlice*)pMA->WelsMallocz (sizeof (SSlice) * iMaxSliceNum, "Slice"); |
| 3951 | if (NULL == pSlice) | 3956 | if (NULL == pSlice) { |
| 3957 | WelsLog (&(pCtx->sLogCtx), WELS_LOG_ERROR, "CWelsH264SVCEncoder::DynSliceRealloc: pSlice is NULL"); | ||
| 3952 | return ENC_RETURN_MEMALLOCERR; | 3958 | return ENC_RETURN_MEMALLOCERR; |
| 3959 | } | ||
| 3953 | memcpy (pSlice, pCurLayer->sLayerInfo.pSliceInLayer, sizeof (SSlice) * iMaxSliceNumOld); | 3960 | memcpy (pSlice, pCurLayer->sLayerInfo.pSliceInLayer, sizeof (SSlice) * iMaxSliceNumOld); |
| 3954 | int32_t uiSliceIdx; | 3961 | int32_t uiSliceIdx; |
| 3955 | uiSliceIdx = iMaxSliceNumOld; | 3962 | uiSliceIdx = iMaxSliceNumOld; |
| @@ -3963,8 +3970,11 @@ int32_t DynSliceRealloc (sWelsEncCtx* pCtx, · 7 unmodified lines | |||
| 3963 | pSliceIdx->pSliceBsa = &pCtx->pSliceBs[uiSliceIdx].sBsWrite; | 3970 | pSliceIdx->pSliceBsa = &pCtx->pSliceBs[uiSliceIdx].sBsWrite; |
| 3964 | else | 3971 | else |
| 3965 | pSliceIdx->pSliceBsa = &pCtx->pOut->sBsWrite; | 3972 | pSliceIdx->pSliceBsa = &pCtx->pOut->sBsWrite; |
| 3966 | if (AllocMbCacheAligned (&pSliceIdx->sMbCacheInfo, pMA)) | 3973 | if (AllocMbCacheAligned (&pSliceIdx->sMbCacheInfo, pMA)) { |
| 3974 | WelsLog (&(pCtx->sLogCtx), WELS_LOG_ERROR, "CWelsH264SVCEncoder::DynSliceRealloc: realloc MbCache not successful at slice_idx=%d (max-slice=%d)", | ||
| 3975 | uiSliceIdx, iMaxSliceNum); | ||
| 3967 | return ENC_RETURN_MEMALLOCERR; | 3976 | return ENC_RETURN_MEMALLOCERR; |
| 3977 | } | ||
| 3968 | 3978 | ||
| 3969 | pSliceIdx->bSliceHeaderExtFlag = pBaseSlice->bSliceHeaderExtFlag; | 3979 | pSliceIdx->bSliceHeaderExtFlag = pBaseSlice->bSliceHeaderExtFlag; |
| 3970 | pSHExt->sSliceHeader.iPpsId = pBaseSHExt->sSliceHeader.iPpsId; | 3980 | pSHExt->sSliceHeader.iPpsId = pBaseSHExt->sSliceHeader.iPpsId; |
| @@ -3983,8 +3993,10 @@ int32_t DynSliceRealloc (sWelsEncCtx* pCtx, · 12 unmodified lines | |||
| 3983 | pCurLayer->sLayerInfo.pSliceInLayer = pSlice; | 3993 | pCurLayer->sLayerInfo.pSliceInLayer = pSlice; |
| 3984 | 3994 | ||
| 3985 | int16_t* pFirstMbInSlice = (int16_t*)pMA->WelsMalloc (iMaxSliceNum * sizeof (int16_t), "pSliceSeg->pFirstMbInSlice"); | 3995 | int16_t* pFirstMbInSlice = (int16_t*)pMA->WelsMalloc (iMaxSliceNum * sizeof (int16_t), "pSliceSeg->pFirstMbInSlice"); |
| 3986 | if (NULL == pFirstMbInSlice) | 3996 | if (NULL == pFirstMbInSlice) { |
| 3997 | WelsLog (&(pCtx->sLogCtx), WELS_LOG_ERROR, "CWelsH264SVCEncoder::DynSliceRealloc: pFirstMbInSlice is NULL"); | ||
| 3987 | return ENC_RETURN_MEMALLOCERR; | 3998 | return ENC_RETURN_MEMALLOCERR; |
| 3999 | } | ||
| 3988 | memset (pFirstMbInSlice, 0, sizeof (int16_t) * iMaxSliceNum); | 4000 | memset (pFirstMbInSlice, 0, sizeof (int16_t) * iMaxSliceNum); |
| 3989 | memcpy (pFirstMbInSlice, pCurLayer->pSliceEncCtx->pFirstMbInSlice, sizeof (int16_t) * iMaxSliceNumOld); | 4001 | memcpy (pFirstMbInSlice, pCurLayer->pSliceEncCtx->pFirstMbInSlice, sizeof (int16_t) * iMaxSliceNumOld); |
| 3990 | pMA->WelsFree (pCurLayer->pSliceEncCtx->pFirstMbInSlice, "pSliceSeg->pFirstMbInSlice"); | 4002 | pMA->WelsFree (pCurLayer->pSliceEncCtx->pFirstMbInSlice, "pSliceSeg->pFirstMbInSlice"); |
| @@ -3992,8 +4004,10 @@ int32_t DynSliceRealloc (sWelsEncCtx* pCtx, · 1 unmodified line | |||
| 3992 | 4004 | ||
| 3993 | int32_t* pCountMbNumInSlice = (int32_t*)pMA->WelsMalloc (iMaxSliceNum * sizeof (int32_t), | 4005 | int32_t* pCountMbNumInSlice = (int32_t*)pMA->WelsMalloc (iMaxSliceNum * sizeof (int32_t), |
| 3994 | "pSliceSeg->pCountMbNumInSlice"); | 4006 | "pSliceSeg->pCountMbNumInSlice"); |
| 3995 | if (NULL == pCountMbNumInSlice) | 4007 | if (NULL == pCountMbNumInSlice) { |
| 4008 | WelsLog (&(pCtx->sLogCtx), WELS_LOG_ERROR, "CWelsH264SVCEncoder::DynSliceRealloc: realloc pCountMbNumInSlice not successful"); | ||
| 3996 | return ENC_RETURN_MEMALLOCERR; | 4009 | return ENC_RETURN_MEMALLOCERR; |
| 4010 | } | ||
| 3997 | memcpy (pCountMbNumInSlice, pCurLayer->pSliceEncCtx->pCountMbNumInSlice, sizeof (int32_t) * iMaxSliceNumOld); | 4011 | memcpy (pCountMbNumInSlice, pCurLayer->pSliceEncCtx->pCountMbNumInSlice, sizeof (int32_t) * iMaxSliceNumOld); |
| 3998 | uiSliceIdx = iMaxSliceNumOld; | 4012 | uiSliceIdx = iMaxSliceNumOld; |
| 3999 | while (uiSliceIdx < iMaxSliceNum) { | 4013 | while (uiSliceIdx < iMaxSliceNum) { |
| @@ -4004,8 +4018,10 @@ int32_t DynSliceRealloc (sWelsEncCtx* pCtx, · 4 unmodified lines | |||
| 4004 | pCurLayer->pSliceEncCtx->pCountMbNumInSlice = pCountMbNumInSlice; | 4018 | pCurLayer->pSliceEncCtx->pCountMbNumInSlice = pCountMbNumInSlice; |
| 4005 | 4019 | ||
| 4006 | SRCSlicing* pSlcingOverRc = (SRCSlicing*)pMA->WelsMalloc (iMaxSliceNum * sizeof (SRCSlicing), "SlicingOverRC"); | 4020 | SRCSlicing* pSlcingOverRc = (SRCSlicing*)pMA->WelsMalloc (iMaxSliceNum * sizeof (SRCSlicing), "SlicingOverRC"); |
| 4007 | if (NULL == pSlcingOverRc) | 4021 | if (NULL == pSlcingOverRc) { |
| 4022 | WelsLog (&(pCtx->sLogCtx), WELS_LOG_ERROR, "CWelsH264SVCEncoder::DynSliceRealloc: realloc pSlcingOverRc not successful"); | ||
| 4008 | return ENC_RETURN_MEMALLOCERR; | 4023 | return ENC_RETURN_MEMALLOCERR; |
| 4024 | } | ||
| 4009 | memcpy (pSlcingOverRc, pCtx->pWelsSvcRc->pSlicingOverRc, sizeof (SRCSlicing) * iMaxSliceNumOld); | 4025 | memcpy (pSlcingOverRc, pCtx->pWelsSvcRc->pSlicingOverRc, sizeof (SRCSlicing) * iMaxSliceNumOld); |
| 4010 | uiSliceIdx = iMaxSliceNumOld; | 4026 | uiSliceIdx = iMaxSliceNumOld; |
| 4011 | SRCSlicing* pSORC = &pSlcingOverRc[uiSliceIdx]; | 4027 | SRCSlicing* pSORC = &pSlcingOverRc[uiSliceIdx]; |
| @@ -4069,9 +4085,13 @@ int32_t WelsCodeOnePicPartition (sWelsEncCtx* pCtx, · 57 unmodified lines | |||
| 4069 | 4085 | ||
| 4070 | if (iSliceIdx >= (pSliceCtx->iMaxSliceNumConstraint - kiSliceIdxStep)) { // insufficient memory in pSliceInLayer[] | 4086 | if (iSliceIdx >= (pSliceCtx->iMaxSliceNumConstraint - kiSliceIdxStep)) { // insufficient memory in pSliceInLayer[] |
| 4071 | if (pCtx->iActiveThreadsNum == 1) { | 4087 | if (pCtx->iActiveThreadsNum == 1) { |
| 4072 | if (DynSliceRealloc (pCtx, pFrameBSInfo, pLayerBsInfo)) //only single thread support re-alloc now | 4088 | //only single thread support re-alloc now |
| 4089 | if (DynSliceRealloc (pCtx, pFrameBSInfo, pLayerBsInfo)) { | ||
| 4090 | WelsLog (&(pCtx->sLogCtx), WELS_LOG_ERROR, "CWelsH264SVCEncoder::WelsCodeOnePicPartition: DynSliceRealloc not successful"); | ||
| 4073 | return ENC_RETURN_MEMALLOCERR; | 4091 | return ENC_RETURN_MEMALLOCERR; |
| 4092 | } | ||
| 4074 | } else if (iSliceIdx >= pSliceCtx->iMaxSliceNumConstraint) { | 4093 | } else if (iSliceIdx >= pSliceCtx->iMaxSliceNumConstraint) { |
| 4094 | WelsLog (&(pCtx->sLogCtx), WELS_LOG_ERROR, "CWelsH264SVCEncoder::WelsCodeOnePicPartition: iSliceIdx(%d) over iMaxSliceNumConstraint(%d)", iSliceIdx, pSliceCtx->iMaxSliceNumConstraint); | ||
| 4075 | return ENC_RETURN_MEMALLOCERR; | 4095 | return ENC_RETURN_MEMALLOCERR; |
| 4076 | } | 4096 | } |
| 4077 | } | 4097 | } |
| @@ -73,7 +73,7 @@ namespace WelsEnc { · 72 unmodified lines | |||
| 73 | void UpdateMbListNeighborParallel (SSliceCtx* pSliceCtx, | 73 | void UpdateMbListNeighborParallel (SSliceCtx* pSliceCtx, |
| 74 | SMB* pMbList, | 74 | SMB* pMbList, |
| 75 | const int32_t uiSliceIdc) { | 75 | const int32_t uiSliceIdc) { |
| 76 | const uint8_t* kpMbMap = pSliceCtx->pOverallMbMap; | 76 | const uint16_t* kpMbMap = pSliceCtx->pOverallMbMap; |
| 77 | const int32_t kiMbWidth = pSliceCtx->iMbWidth; | 77 | const int32_t kiMbWidth = pSliceCtx->iMbWidth; |
| 78 | int32_t iIdx = pSliceCtx->pFirstMbInSlice[uiSliceIdc]; | 78 | int32_t iIdx = pSliceCtx->pFirstMbInSlice[uiSliceIdc]; |
| 79 | const int32_t kiEndMbInSlice = iIdx + pSliceCtx->pCountMbNumInSlice[uiSliceIdc] - 1; | 79 | const int32_t kiEndMbInSlice = iIdx + pSliceCtx->pCountMbNumInSlice[uiSliceIdc] - 1; |
| @@ -78,7 +78,8 @@ int32_t AssignMbMapMultipleSlices (SSliceCtx* pSliceSeg, const SSliceConfig* kpM · 77 unmodified lines | |||
| 78 | const int16_t kiFirstMb = uiSliceIdx * kiMbWidth; | 78 | const int16_t kiFirstMb = uiSliceIdx * kiMbWidth; |
| 79 | pSliceSeg->pCountMbNumInSlice[uiSliceIdx] = kiMbWidth; | 79 | pSliceSeg->pCountMbNumInSlice[uiSliceIdx] = kiMbWidth; |
| 80 | pSliceSeg->pFirstMbInSlice[uiSliceIdx] = kiFirstMb; | 80 | pSliceSeg->pFirstMbInSlice[uiSliceIdx] = kiFirstMb; |
| 81 | memset (pSliceSeg->pOverallMbMap + kiFirstMb, (uint8_t)uiSliceIdx, kiMbWidth * sizeof (uint8_t)); | 81 | WelsSetMemMultiplebytes_c(pSliceSeg->pOverallMbMap + kiFirstMb, uiSliceIdx, |
| 82 | kiMbWidth, sizeof(uint16_t)); | ||
| 82 | ++ uiSliceIdx; | 83 | ++ uiSliceIdx; |
| 83 | } | 84 | } |
| 84 | 85 | ||
| @@ -89,7 +90,7 @@ int32_t AssignMbMapMultipleSlices (SSliceCtx* pSliceSeg, const SSliceConfig* kpM · 4 unmodified lines | |||
| 89 | const int32_t* kpSlicesAssignList = (int32_t*) & (kpMso->sSliceArgument.uiSliceMbNum[0]); | 90 | const int32_t* kpSlicesAssignList = (int32_t*) & (kpMso->sSliceArgument.uiSliceMbNum[0]); |
| 90 | const int32_t kiCountNumMbInFrame = pSliceSeg->iMbNumInFrame; | 91 | const int32_t kiCountNumMbInFrame = pSliceSeg->iMbNumInFrame; |
| 91 | const int32_t kiCountSliceNumInFrame = pSliceSeg->iSliceNumInFrame; | 92 | const int32_t kiCountSliceNumInFrame = pSliceSeg->iSliceNumInFrame; |
| 92 | int32_t iSliceIdx = 0; | 93 | uint16_t iSliceIdx = 0; |
| 93 | int16_t iMbIdx = 0; | 94 | int16_t iMbIdx = 0; |
| 94 | 95 | ||
| 95 | do { | 96 | do { |
| @@ -392,7 +393,7 @@ int32_t InitSliceSegment (SSliceCtx* pSliceSeg, · 296 unmodified lines | |||
| 392 | } | 393 | } |
| 393 | 394 | ||
| 394 | if (SM_SINGLE_SLICE == uiSliceMode) { | 395 | if (SM_SINGLE_SLICE == uiSliceMode) { |
| 395 | pSliceSeg->pOverallMbMap = (uint8_t*)pMa->WelsMalloc (kiCountMbNum * sizeof (uint8_t), "pSliceSeg->pOverallMbMap"); | 396 | pSliceSeg->pOverallMbMap = (uint16_t*)pMa->WelsMalloc (kiCountMbNum * sizeof (uint16_t), "pSliceSeg->pOverallMbMap"); |
| 396 | 397 | ||
| 397 | WELS_VERIFY_RETURN_IF (1, NULL == pSliceSeg->pOverallMbMap) | 398 | WELS_VERIFY_RETURN_IF (1, NULL == pSliceSeg->pOverallMbMap) |
| 398 | pSliceSeg->iSliceNumInFrame = 1; | 399 | pSliceSeg->iSliceNumInFrame = 1; |
| @@ -419,11 +420,12 @@ int32_t InitSliceSegment (SSliceCtx* pSliceSeg, · 20 unmodified lines | |||
| 419 | && uiSliceMode != SM_DYN_SLICE && uiSliceMode != SM_AUTO_SLICE) | 420 | && uiSliceMode != SM_DYN_SLICE && uiSliceMode != SM_AUTO_SLICE) |
| 420 | return 1; | 421 | return 1; |
| 421 | 422 | ||
| 422 | pSliceSeg->pOverallMbMap = (uint8_t*)pMa->WelsMalloc (kiCountMbNum * sizeof (uint8_t), "pSliceSeg->pOverallMbMap"); | 423 | pSliceSeg->pOverallMbMap = (uint16_t*)pMa->WelsMalloc (kiCountMbNum * sizeof (uint16_t), "pSliceSeg->pOverallMbMap"); |
| 423 | 424 | ||
| 424 | WELS_VERIFY_RETURN_IF (1, NULL == pSliceSeg->pOverallMbMap) | 425 | WELS_VERIFY_RETURN_IF (1, NULL == pSliceSeg->pOverallMbMap) |
| 425 | 426 | ||
| 426 | memset (pSliceSeg->pOverallMbMap, 0, kiCountMbNum * sizeof (uint8_t)); | 427 | WelsSetMemMultiplebytes_c(pSliceSeg->pOverallMbMap, 0, kiCountMbNum, sizeof(uint16_t)); |
| 428 | |||
| 427 | //SM_DYN_SLICE: init, set pSliceSeg->iSliceNumInFrame = 1; | 429 | //SM_DYN_SLICE: init, set pSliceSeg->iSliceNumInFrame = 1; |
| 428 | pSliceSeg->iSliceNumInFrame = GetInitialSliceNum (kiMbWidth, kiMbHeight, pMso); | 430 | pSliceSeg->iSliceNumInFrame = GetInitialSliceNum (kiMbWidth, kiMbHeight, pMso); |
| 429 | 431 | ||
| @@ -550,10 +552,10 @@ void UninitSlicePEncCtx (SSliceCtx* pSliceCtx, CMemoryAlign* pMa) { · 120 unmodified lines | |||
| 550 | * | 552 | * |
| 551 | * \return uiSliceIdc - successful; -1 - failed; | 553 | * \return uiSliceIdc - successful; -1 - failed; |
| 552 | */ | 554 | */ |
| 553 | uint8_t WelsMbToSliceIdc (SSliceCtx* pSliceCtx, const int16_t kiMbXY) { | 555 | uint16_t WelsMbToSliceIdc (SSliceCtx* pSliceCtx, const int16_t kiMbXY) { |
| 554 | if (NULL != pSliceCtx && kiMbXY < pSliceCtx->iMbNumInFrame && kiMbXY >= 0) | 556 | if (NULL != pSliceCtx && kiMbXY < pSliceCtx->iMbNumInFrame && kiMbXY >= 0) |
| 555 | return pSliceCtx->pOverallMbMap[ kiMbXY ]; | 557 | return pSliceCtx->pOverallMbMap[ kiMbXY ]; |
| 556 | return (uint8_t) (-1); | 558 | return (uint16_t) (-1); |
| 557 | } | 559 | } |
| 558 | 560 | ||
| 559 | /*! | 561 | /*! |
| @@ -688,7 +690,8 @@ int32_t DynamicAdjustSlicePEncCtxAll (SSliceCtx* pSliceCtx, · 128 unmodified lines | |||
| 688 | pSliceCtx->pFirstMbInSlice[iSliceIdx] = iFirstMbIdx; | 690 | pSliceCtx->pFirstMbInSlice[iSliceIdx] = iFirstMbIdx; |
| 689 | pSliceCtx->pCountMbNumInSlice[iSliceIdx] = kiSliceRun; | 691 | pSliceCtx->pCountMbNumInSlice[iSliceIdx] = kiSliceRun; |
| 690 | 692 | ||
| 691 | memset (pSliceCtx->pOverallMbMap + iFirstMbIdx, (uint8_t)iSliceIdx, kiSliceRun * sizeof (uint8_t)); | 693 | WelsSetMemMultiplebytes_c(pSliceCtx->pOverallMbMap + iFirstMbIdx, iSliceIdx, |
| 694 | kiSliceRun, sizeof(uint16_t)); | ||
| 692 | 695 | ||
| 693 | iFirstMbIdx += kiSliceRun; | 696 | iFirstMbIdx += kiSliceRun; |
| 694 | 697 | ||
| @@ -776,7 +776,7 @@ void UpdateMbNeighbourInfoForNextSlice (SSliceCtx* pSliceCtx, · 775 unmodified lines | |||
| 776 | bool bLeftTop; | 776 | bool bLeftTop; |
| 777 | bool bRightTop; | 777 | bool bRightTop; |
| 778 | int32_t iLeftXY, iTopXY, iLeftTopXY, iRightTopXY; | 778 | int32_t iLeftXY, iTopXY, iLeftTopXY, iRightTopXY; |
| 779 | const uint8_t kuiSliceIdc = WelsMbToSliceIdc (pSliceCtx, kiMbXY); | 779 | const uint16_t kuiSliceIdc = WelsMbToSliceIdc (pSliceCtx, kiMbXY); |
| 780 | 780 | ||
| 781 | pMb->uiSliceIdc = kuiSliceIdc; | 781 | pMb->uiSliceIdc = kuiSliceIdc; |
| 782 | iLeftXY = kiMbXY - 1; | 782 | iLeftXY = kiMbXY - 1; |
| @@ -814,9 +814,9 @@ void AddSliceBoundary (sWelsEncCtx* pEncCtx, SSlice* pCurSlice, SSliceCtx* pSlic · 31 unmodified lines | |||
| 814 | int32_t iFirstMbIdxOfNextSlice, const int32_t kiLastMbIdxInPartition) { | 814 | int32_t iFirstMbIdxOfNextSlice, const int32_t kiLastMbIdxInPartition) { |
| 815 | SDqLayer* pCurLayer = pEncCtx->pCurDqLayer; | 815 | SDqLayer* pCurLayer = pEncCtx->pCurDqLayer; |
| 816 | int32_t iCurMbIdx = pCurMb->iMbXY; | 816 | int32_t iCurMbIdx = pCurMb->iMbXY; |
| 817 | int32_t iCurSliceIdc = pSliceCtx->pOverallMbMap[ iCurMbIdx ]; | 817 | uint16_t iCurSliceIdc = pSliceCtx->pOverallMbMap[ iCurMbIdx ]; |
| 818 | const int32_t kiSliceIdxStep = pEncCtx->iActiveThreadsNum; | 818 | const int32_t kiSliceIdxStep = pEncCtx->iActiveThreadsNum; |
| 819 | int32_t iNextSliceIdc = iCurSliceIdc + kiSliceIdxStep; | 819 | uint16_t iNextSliceIdc = iCurSliceIdc + kiSliceIdxStep; |
| 820 | SSlice* pNextSlice = NULL; | 820 | SSlice* pNextSlice = NULL; |
| 821 | 821 | ||
| 822 | SMB* pMbList = pCurLayer->sMbDataP; | 822 | SMB* pMbList = pCurLayer->sMbDataP; |
| @@ -839,9 +839,8 @@ void AddSliceBoundary (sWelsEncCtx* pEncCtx, SSlice* pCurSlice, SSliceCtx* pSlic · 16 unmodified lines | |||
| 839 | sizeof (SSliceHeaderExt)); // confirmed_safe_unsafe_usage | 839 | sizeof (SSliceHeaderExt)); // confirmed_safe_unsafe_usage |
| 840 | 840 | ||
| 841 | pSliceCtx->pFirstMbInSlice[iNextSliceIdc] = iFirstMbIdxOfNextSlice; | 841 | pSliceCtx->pFirstMbInSlice[iNextSliceIdc] = iFirstMbIdxOfNextSlice; |
| 842 | 842 | WelsSetMemMultiplebytes_c (pSliceCtx->pOverallMbMap + iFirstMbIdxOfNextSlice, iNextSliceIdc, | |
| 843 | memset (pSliceCtx->pOverallMbMap + iFirstMbIdxOfNextSlice, (uint8_t)iNextSliceIdc, | 843 | (kiLastMbIdxInPartition - iFirstMbIdxOfNextSlice + 1), sizeof(uint16_t)); |
| 844 | (kiLastMbIdxInPartition - iFirstMbIdxOfNextSlice + 1)*sizeof (uint8_t)); | ||
| 845 | 844 | ||
| 846 | //DYNAMIC_SLICING_ONE_THREAD: update pMbList slice_neighbor_info | 845 | //DYNAMIC_SLICING_ONE_THREAD: update pMbList slice_neighbor_info |
| 847 | UpdateMbNeighbourInfoForNextSlice (pSliceCtx, pMbList, iFirstMbIdxOfNextSlice, kiLastMbIdxInPartition); | 846 | UpdateMbNeighbourInfoForNextSlice (pSliceCtx, pMbList, iFirstMbIdxOfNextSlice, kiLastMbIdxInPartition); |
| @@ -875,6 +874,10 @@ bool DynSlcJudgeSliceBoundaryStepBack (void* pCtx, void* pSlice, SSliceCtx* pSli · 27 unmodified lines | |||
| 875 | && JUMPPACKETSIZE_JUDGE (uiLen, iCurMbIdx, pSliceCtx->uiSliceSizeConstraint)) /*jump_avoiding_pack_exceed*/ | 874 | && JUMPPACKETSIZE_JUDGE (uiLen, iCurMbIdx, pSliceCtx->uiSliceSizeConstraint)) /*jump_avoiding_pack_exceed*/ |
| 876 | && kbCurMbNotLastMbOfCurPartition) { //decide to add new pSlice | 875 | && kbCurMbNotLastMbOfCurPartition) { //decide to add new pSlice |
| 877 | 876 | ||
| 877 | WelsLog (&pEncCtx->sLogCtx, WELS_LOG_DETAIL, | ||
| 878 | "DynSlcJudgeSliceBoundaryStepBack: AddSliceBoundary: iCurMbIdx=%d, uiLen=%d, uiSliceIdx=%d", iCurMbIdx, uiLen, | ||
| 879 | pCurSlice->uiSliceIdx); | ||
| 880 | |||
| 878 | if (pEncCtx->pSvcParam->iMultipleThreadIdc > 1) { | 881 | if (pEncCtx->pSvcParam->iMultipleThreadIdc > 1) { |
| 879 | WelsMutexLock (&pEncCtx->pSliceThreading->mutexSliceNumUpdate); | 882 | WelsMutexLock (&pEncCtx->pSliceThreading->mutexSliceNumUpdate); |
| 880 | //lock the acessing to this variable: pSliceCtx->iSliceNumInFrame | 883 | //lock the acessing to this variable: pSliceCtx->iSliceNumInFrame |
| @@ -718,7 +718,7 @@ int32_t RequestScreenBlockFeatureStorage (CMemoryAlign* pMa, const int32_t kiFra · 717 unmodified lines | |||
| 718 | pScreenBlockFeatureStorage->iIs16x16 = !bIsBlock8x8; | 718 | pScreenBlockFeatureStorage->iIs16x16 = !bIsBlock8x8; |
| 719 | pScreenBlockFeatureStorage->uiFeatureStrategyIndex = kiFeatureStrategyIndex; | 719 | pScreenBlockFeatureStorage->uiFeatureStrategyIndex = kiFeatureStrategyIndex; |
| 720 | pScreenBlockFeatureStorage->iActualListSize = kiListSize; | 720 | pScreenBlockFeatureStorage->iActualListSize = kiListSize; |
| 721 | memset (pScreenBlockFeatureStorage->uiSadCostThreshold, UINT_MAX, BLOCK_SIZE_ALL * sizeof (uint32_t)); | 721 | WelsSetMemMultiplebytes_c (pScreenBlockFeatureStorage->uiSadCostThreshold, UINT_MAX, BLOCK_SIZE_ALL, sizeof(uint32_t)); |
| 722 | pScreenBlockFeatureStorage->bRefBlockFeatureCalculated = false; | 722 | pScreenBlockFeatureStorage->bRefBlockFeatureCalculated = false; |
| 723 | 723 | ||
| 724 | return ENC_RETURN_SUCCESS; | 724 | return ENC_RETURN_SUCCESS; |