Showing the changes to codec/encoder/core/src/encoder_ext.cpp (1 of 11 files). Show all
Unified · Split
| @@ -939,6 +939,11 @@ void FreeDqLayer (SDqLayer*& pDq, CMemoryAlign* pMa) { · 938 unmodified lines | |||
| 939 | 939 | ||
| 940 | FreeSliceInLayer (pDq, pMa); | 940 | FreeSliceInLayer (pDq, pMa); |
| 941 | 941 | ||
| 942 | if (pDq->ppSliceInLayer) { | ||
| 943 | pMa->WelsFree (pDq->ppSliceInLayer, "pDq->ppSliceInLayer"); | ||
| 944 | pDq->ppSliceInLayer = NULL; | ||
| 945 | } | ||
| 946 | |||
| 942 | if (pDq->pNumSliceCodedOfPartition) { | 947 | if (pDq->pNumSliceCodedOfPartition) { |
| 943 | pMa->WelsFree (pDq->pNumSliceCodedOfPartition, "pNumSliceCodedOfPartition"); | 948 | pMa->WelsFree (pDq->pNumSliceCodedOfPartition, "pNumSliceCodedOfPartition"); |
| 944 | pDq->pNumSliceCodedOfPartition = NULL; | 949 | pDq->pNumSliceCodedOfPartition = NULL; |
| @@ -1059,17 +1064,18 @@ static inline int32_t InitSliceThreadInfo (sWelsEncCtx** ppCtx, · 114 unmodified lines | |||
| 1059 | pSliceThreadInfo->iEncodedSliceNumInThread[iIdx] = 0; | 1064 | pSliceThreadInfo->iEncodedSliceNumInThread[iIdx] = 0; |
| 1060 | pSliceThreadInfo->pSliceInThread[iIdx] = (SSlice*)pMa->WelsMallocz (sizeof (SSlice) * | 1065 | pSliceThreadInfo->pSliceInThread[iIdx] = (SSlice*)pMa->WelsMallocz (sizeof (SSlice) * |
| 1061 | iMaxSliceNumInThread, "pSliceInThread"); | 1066 | iMaxSliceNumInThread, "pSliceInThread"); |
| 1062 | if (NULL == pSliceThreadInfo->pSliceInThread[iIdx]) | 1067 | if(NULL == pSliceThreadInfo->pSliceInThread[iIdx]) { |
| 1063 | return ENC_RETURN_MEMALLOCERR; | 1068 | return ENC_RETURN_MEMALLOCERR; |
| 1064 | 1069 | } | |
| 1065 | iRet = InitSliceList (ppCtx, | 1070 | iRet = InitSliceList (ppCtx, |
| 1066 | pDqLayer, | 1071 | pDqLayer, |
| 1067 | pSliceThreadInfo->pSliceInThread[iIdx], | 1072 | pSliceThreadInfo->pSliceInThread[iIdx], |
| 1068 | iMaxSliceNumInThread, | 1073 | iMaxSliceNumInThread, |
| 1069 | kiDlayerIndex, | 1074 | kiDlayerIndex, |
| 1070 | pMa); | 1075 | pMa); |
| 1071 | if (ENC_RETURN_SUCCESS != iRet) | 1076 | if (ENC_RETURN_SUCCESS != iRet) { |
| 1072 | return iRet; | 1077 | return iRet; |
| 1078 | } | ||
| 1073 | 1079 | ||
| 1074 | iIdx++; | 1080 | iIdx++; |
| 1075 | } | 1081 | } |
| @@ -1089,34 +1095,43 @@ static inline int32_t InitSliceInLayer (sWelsEncCtx** ppCtx, · 13 unmodified lines | |||
| 1089 | 1095 | ||
| 1090 | //SWelsSvcCodingParam* pParam = (*ppCtx)->pSvcParam; | 1096 | //SWelsSvcCodingParam* pParam = (*ppCtx)->pSvcParam; |
| 1091 | int32_t iRet = 0; | 1097 | int32_t iRet = 0; |
| 1098 | int32_t iSliceIdx = 0; | ||
| 1092 | int32_t iMaxSliceNum = pDqLayer->iMaxSliceNum; | 1099 | int32_t iMaxSliceNum = pDqLayer->iMaxSliceNum; |
| 1093 | 1100 | ||
| 1094 | //if (pParam->iMultipleThreadIdc > 1) { | 1101 | |
| 1095 | // to do, will add later, slice buffer allocated based on thread mode if() else () | 1102 | pDqLayer->ppSliceInLayer = (SSlice**)pMa->WelsMallocz (sizeof (SSlice*) * iMaxSliceNum, "ppSliceInLayer"); |
| 1103 | if(NULL == pDqLayer->ppSliceInLayer) { | ||
| 1104 | return ENC_RETURN_MEMALLOCERR; | ||
| 1105 | } | ||
| 1106 | |||
| 1096 | InitSliceThreadInfo (ppCtx, | 1107 | InitSliceThreadInfo (ppCtx, |
| 1097 | pDqLayer, | 1108 | pDqLayer, |
| 1098 | kiDlayerIndex, | 1109 | kiDlayerIndex, |
| 1099 | pMa); | 1110 | pMa); |
| 1100 | if (ENC_RETURN_SUCCESS != iRet) | 1111 | if (ENC_RETURN_SUCCESS != iRet) { |
| 1101 | return iRet; | 1112 | return iRet; |
| 1102 | 1113 | } | |
| 1103 | //} else { | ||
| 1104 | pDqLayer->sLayerInfo.pSliceInLayer = (SSlice*)pMa->WelsMallocz (sizeof (SSlice) * iMaxSliceNum, "pSliceInLayer"); | 1114 | pDqLayer->sLayerInfo.pSliceInLayer = (SSlice*)pMa->WelsMallocz (sizeof (SSlice) * iMaxSliceNum, "pSliceInLayer"); |
| 1105 | if (NULL == pDqLayer->sLayerInfo.pSliceInLayer) | 1115 | if(NULL == pDqLayer->sLayerInfo.pSliceInLayer) { |
| 1106 | return ENC_RETURN_MEMALLOCERR; | 1116 | return ENC_RETURN_MEMALLOCERR; |
| 1107 | 1117 | } | |
| 1108 | InitSliceList (ppCtx, | 1118 | InitSliceList (ppCtx, |
| 1109 | pDqLayer, | 1119 | pDqLayer, |
| 1110 | pDqLayer->sLayerInfo.pSliceInLayer, | 1120 | pDqLayer->sLayerInfo.pSliceInLayer, |
| 1111 | iMaxSliceNum, | 1121 | iMaxSliceNum, |
| 1112 | kiDlayerIndex, | 1122 | kiDlayerIndex, |
| 1113 | pMa); | 1123 | pMa); |
| 1114 | if (ENC_RETURN_SUCCESS != iRet) | 1124 | if (ENC_RETURN_SUCCESS != iRet) { |
| 1115 | return iRet; | 1125 | return iRet; |
| 1116 | //} | 1126 | } |
| 1127 | |||
| 1128 | for (iSliceIdx = 0; iSliceIdx < iMaxSliceNum; iSliceIdx++) { | ||
| 1129 | pDqLayer->ppSliceInLayer[iSliceIdx] = &pDqLayer->sLayerInfo.pSliceInLayer[iSliceIdx]; | ||
| 1130 | } | ||
| 1117 | 1131 | ||
| 1118 | return ENC_RETURN_SUCCESS; | 1132 | return ENC_RETURN_SUCCESS; |
| 1119 | } | 1133 | } |
| 1134 | |||
| 1120 | /*! | 1135 | /*! |
| 1121 | * \brief initialize ppDqLayerList and slicepEncCtx_list due to count number of layers available | 1136 | * \brief initialize ppDqLayerList and slicepEncCtx_list due to count number of layers available |
| 1122 | * \pParam pCtx sWelsEncCtx* | 1137 | * \pParam pCtx sWelsEncCtx* |
| @@ -2553,7 +2568,7 @@ void WelsInitCurrentQBLayerMltslc (sWelsEncCtx* pCtx) { · 1430 unmodified lines | |||
| 2553 | 2568 | ||
| 2554 | void UpdateSlicepEncCtxWithPartition (SDqLayer* pCurDq, int32_t iPartitionNum) { | 2569 | void UpdateSlicepEncCtxWithPartition (SDqLayer* pCurDq, int32_t iPartitionNum) { |
| 2555 | SSliceCtx* pSliceCtx = &pCurDq->sSliceEncCtx; | 2570 | SSliceCtx* pSliceCtx = &pCurDq->sSliceEncCtx; |
| 2556 | SSlice* pSliceInLayer = pCurDq->sLayerInfo.pSliceInLayer; | 2571 | SSlice** ppSliceInLayer = pCurDq->ppSliceInLayer; |
| 2557 | const int32_t kiMbNumInFrame = pSliceCtx->iMbNumInFrame; | 2572 | const int32_t kiMbNumInFrame = pSliceCtx->iMbNumInFrame; |
| 2558 | int32_t iCountMbNumPerPartition = kiMbNumInFrame; | 2573 | int32_t iCountMbNumPerPartition = kiMbNumInFrame; |
| 2559 | int32_t iAssignableMbLeft = kiMbNumInFrame; | 2574 | int32_t iAssignableMbLeft = kiMbNumInFrame; |
| @@ -2569,18 +2584,18 @@ void UpdateSlicepEncCtxWithPartition (SDqLayer* pCurDq, int32_t iPartitionNum) { · 9 unmodified lines | |||
| 2569 | i = 0; | 2584 | i = 0; |
| 2570 | while (i < iPartitionNum) { | 2585 | while (i < iPartitionNum) { |
| 2571 | if (i + 1 == iPartitionNum) { | 2586 | if (i + 1 == iPartitionNum) { |
| 2572 | pSliceInLayer[i].iCountMbNumInSlice = iAssignableMbLeft; | 2587 | ppSliceInLayer[i]->iCountMbNumInSlice = iAssignableMbLeft; |
| 2573 | } else { | 2588 | } else { |
| 2574 | pSliceInLayer[i].iCountMbNumInSlice = iCountMbNumPerPartition; | 2589 | ppSliceInLayer[i]->iCountMbNumInSlice = iCountMbNumPerPartition; |
| 2575 | } | 2590 | } |
| 2576 | pSliceInLayer[i].sSliceHeaderExt.sSliceHeader.iFirstMbInSlice = iFirstMbIdx; | 2591 | ppSliceInLayer[i]->sSliceHeaderExt.sSliceHeader.iFirstMbInSlice = iFirstMbIdx; |
| 2577 | 2592 | ||
| 2578 | WelsSetMemMultiplebytes_c (pSliceCtx->pOverallMbMap + iFirstMbIdx, i, | 2593 | WelsSetMemMultiplebytes_c (pSliceCtx->pOverallMbMap + iFirstMbIdx, i, |
| 2579 | pSliceInLayer[i].iCountMbNumInSlice, sizeof (uint16_t)); | 2594 | ppSliceInLayer[i]->iCountMbNumInSlice, sizeof (uint16_t)); |
| 2580 | 2595 | ||
| 2581 | // for next partition(or pSlice) | 2596 | // for next partition(or pSlice) |
| 2582 | iFirstMbIdx += pSliceInLayer[i].iCountMbNumInSlice; | 2597 | iFirstMbIdx += ppSliceInLayer[i]->iCountMbNumInSlice; |
| 2583 | iAssignableMbLeft -= pSliceInLayer[i].iCountMbNumInSlice; | 2598 | iAssignableMbLeft -= ppSliceInLayer[i]->iCountMbNumInSlice; |
| 2584 | ++ i; | 2599 | ++ i; |
| 2585 | } | 2600 | } |
| 2586 | } | 2601 | } |
| @@ -2646,8 +2661,8 @@ void WelsInitCurrentLayer (sWelsEncCtx* pCtx, · 59 unmodified lines | |||
| 2646 | SPicture* pEncPic = pCtx->pEncPic; | 2661 | SPicture* pEncPic = pCtx->pEncPic; |
| 2647 | SPicture* pDecPic = pCtx->pDecPic; | 2662 | SPicture* pDecPic = pCtx->pDecPic; |
| 2648 | SDqLayer* pCurDq = pCtx->pCurDqLayer; | 2663 | SDqLayer* pCurDq = pCtx->pCurDqLayer; |
| 2649 | SSlice* pBaseSlice = &pCurDq->sLayerInfo.pSliceInLayer[0]; | 2664 | SSlice* pBaseSlice = pCurDq->ppSliceInLayer[0]; |
| 2650 | SSlice* pSlice = NULL; | 2665 | SSlice* pSlice = NULL; |
| 2651 | const uint8_t kiCurDid = pCtx->uiDependencyId; | 2666 | const uint8_t kiCurDid = pCtx->uiDependencyId; |
| 2652 | const bool kbUseSubsetSpsFlag = (!pParam->bSimulcastAVC) && (kiCurDid > BASE_DEPENDENCY_ID); | 2667 | const bool kbUseSubsetSpsFlag = (!pParam->bSimulcastAVC) && (kiCurDid > BASE_DEPENDENCY_ID); |
| 2653 | SSpatialLayerConfig* fDlp = &pParam->sSpatialLayers[kiCurDid]; | 2668 | SSpatialLayerConfig* fDlp = &pParam->sSpatialLayers[kiCurDid]; |
| @@ -2691,10 +2706,10 @@ void WelsInitCurrentLayer (sWelsEncCtx* pCtx, · 37 unmodified lines | |||
| 2691 | 2706 | ||
| 2692 | pBaseSlice->bSliceHeaderExtFlag = (NAL_UNIT_CODED_SLICE_EXT == pCtx->eNalType); | 2707 | pBaseSlice->bSliceHeaderExtFlag = (NAL_UNIT_CODED_SLICE_EXT == pCtx->eNalType); |
| 2693 | 2708 | ||
| 2694 | pSlice = pBaseSlice; | ||
| 2695 | iIdx = 1; | 2709 | iIdx = 1; |
| 2696 | while (iIdx < iSliceCount) { | 2710 | while (iIdx < iSliceCount) { |
| 2697 | ++ pSlice; | 2711 | pSlice = pCurDq->ppSliceInLayer[iIdx]; |
| 2712 | |||
| 2698 | pSlice->sSliceHeaderExt.sSliceHeader.iPpsId = pBaseSlice->sSliceHeaderExt.sSliceHeader.iPpsId; | 2713 | pSlice->sSliceHeaderExt.sSliceHeader.iPpsId = pBaseSlice->sSliceHeaderExt.sSliceHeader.iPpsId; |
| 2699 | pSlice->sSliceHeaderExt.sSliceHeader.pPps = pBaseSlice->sSliceHeaderExt.sSliceHeader.pPps; | 2714 | pSlice->sSliceHeaderExt.sSliceHeader.pPps = pBaseSlice->sSliceHeaderExt.sSliceHeader.pPps; |
| 2700 | pSlice->sSliceHeaderExt.sSliceHeader.iSpsId = pBaseSlice->sSliceHeaderExt.sSliceHeader.iSpsId; | 2715 | pSlice->sSliceHeaderExt.sSliceHeader.iSpsId = pBaseSlice->sSliceHeaderExt.sSliceHeader.iSpsId; |
| @@ -2928,7 +2943,6 @@ static inline void WelsSwapDqLayers (sWelsEncCtx* pCtx, const int32_t kiNextDqId · 227 unmodified lines | |||
| 2928 | * \brief prefetch reference picture after WelsBuildRefList | 2943 | * \brief prefetch reference picture after WelsBuildRefList |
| 2929 | */ | 2944 | */ |
| 2930 | static inline void PrefetchReferencePicture (sWelsEncCtx* pCtx, const EVideoFrameType keFrameType) { | 2945 | static inline void PrefetchReferencePicture (sWelsEncCtx* pCtx, const EVideoFrameType keFrameType) { |
| 2931 | SSlice* pSliceBase = &pCtx->pCurDqLayer->sLayerInfo.pSliceInLayer[0]; | ||
| 2932 | const int32_t kiSliceCount = GetCurrentSliceNum (pCtx->pCurDqLayer); | 2946 | const int32_t kiSliceCount = GetCurrentSliceNum (pCtx->pCurDqLayer); |
| 2933 | int32_t iIdx = 0; | 2947 | int32_t iIdx = 0; |
| 2934 | uint8_t uiRefIdx = -1; | 2948 | uint8_t uiRefIdx = -1; |
| @@ -2946,8 +2960,7 @@ static inline void PrefetchReferencePicture (sWelsEncCtx* pCtx, const EVideoFram · 11 unmodified lines | |||
| 2946 | 2960 | ||
| 2947 | iIdx = 0; | 2961 | iIdx = 0; |
| 2948 | while (iIdx < kiSliceCount) { | 2962 | while (iIdx < kiSliceCount) { |
| 2949 | pSliceBase->sSliceHeaderExt.sSliceHeader.uiRefIndex = uiRefIdx; | 2963 | pCtx->pCurDqLayer->ppSliceInLayer[iIdx]->sSliceHeaderExt.sSliceHeader.uiRefIndex = uiRefIdx; |
| 2950 | ++ pSliceBase; | ||
| 2951 | ++ iIdx; | 2964 | ++ iIdx; |
| 2952 | } | 2965 | } |
| 2953 | } | 2966 | } |
| @@ -3876,7 +3889,7 @@ int32_t WelsEncoderEncodeExt (sWelsEncCtx* pCtx, SFrameBSInfo* pFbi, const SSour · 922 unmodified lines | |||
| 3876 | int32_t iEndMbIdx = pCtx->pCurDqLayer->sSliceEncCtx.iMbNumInFrame; | 3889 | int32_t iEndMbIdx = pCtx->pCurDqLayer->sSliceEncCtx.iMbNumInFrame; |
| 3877 | for (int32_t iIdx = kiPartitionCnt - 1; iIdx >= 0; --iIdx) { | 3890 | for (int32_t iIdx = kiPartitionCnt - 1; iIdx >= 0; --iIdx) { |
| 3878 | const int32_t iFirstMbIdx = | 3891 | const int32_t iFirstMbIdx = |
| 3879 | pCtx->pCurDqLayer->sLayerInfo.pSliceInLayer[iIdx].sSliceHeaderExt.sSliceHeader.iFirstMbInSlice; | 3892 | pCtx->pCurDqLayer->ppSliceInLayer[iIdx]->sSliceHeaderExt.sSliceHeader.iFirstMbInSlice; |
| 3880 | pCtx->pSliceThreading->pThreadPEncCtx[iIdx].iStartMbIndex = iFirstMbIdx; | 3893 | pCtx->pSliceThreading->pThreadPEncCtx[iIdx].iStartMbIndex = iFirstMbIdx; |
| 3881 | pCtx->pSliceThreading->pThreadPEncCtx[iIdx].iEndMbIndex = iEndMbIdx; | 3894 | pCtx->pSliceThreading->pThreadPEncCtx[iIdx].iEndMbIndex = iEndMbIdx; |
| 3882 | iEndMbIdx = iFirstMbIdx; | 3895 | iEndMbIdx = iFirstMbIdx; |
| @@ -4645,6 +4658,19 @@ int32_t SliceBufferRealloc (sWelsEncCtx* pCtx) { · 762 unmodified lines | |||
| 4645 | pMA->WelsFree (pCurLayer->sLayerInfo.pSliceInLayer, "Slice"); | 4658 | pMA->WelsFree (pCurLayer->sLayerInfo.pSliceInLayer, "Slice"); |
| 4646 | pCurLayer->sLayerInfo.pSliceInLayer = pSlice; | 4659 | pCurLayer->sLayerInfo.pSliceInLayer = pSlice; |
| 4647 | 4660 | ||
| 4661 | // update for ppsliceInlayer | ||
| 4662 | SSlice** ppSlice = (SSlice**)pMA->WelsMallocz (sizeof (SSlice*) * iMaxSliceNum, "ppSlice"); | ||
| 4663 | if (NULL == ppSlice) { | ||
| 4664 | WelsLog (& (pCtx->sLogCtx), WELS_LOG_ERROR, "CWelsH264SVCEncoder::DynSliceRealloc: ppSlice is NULL"); | ||
| 4665 | return ENC_RETURN_MEMALLOCERR; | ||
| 4666 | } | ||
| 4667 | pMA->WelsFree (pCurLayer->ppSliceInLayer, "ppSliceInLayer"); | ||
| 4668 | pCurLayer->ppSliceInLayer = ppSlice; | ||
| 4669 | |||
| 4670 | for(uiSliceIdx = 0; uiSliceIdx < iMaxSliceNum; uiSliceIdx++){ | ||
| 4671 | pCurLayer->ppSliceInLayer[uiSliceIdx] = &pCurLayer->sLayerInfo.pSliceInLayer[uiSliceIdx]; | ||
| 4672 | } | ||
| 4673 | |||
| 4648 | if (pCtx->iMaxSliceCount < iMaxSliceNum) | 4674 | if (pCtx->iMaxSliceCount < iMaxSliceNum) |
| 4649 | pCtx->iMaxSliceCount = iMaxSliceNum; | 4675 | pCtx->iMaxSliceCount = iMaxSliceNum; |
| 4650 | pCurLayer->sSliceEncCtx.iMaxSliceNumConstraint = iMaxSliceNum; | 4676 | pCurLayer->sSliceEncCtx.iMaxSliceNumConstraint = iMaxSliceNum; |
| @@ -4678,8 +4704,7 @@ int32_t WelsCodeOnePicPartition (sWelsEncCtx* pCtx, · 27 unmodified lines | |||
| 4678 | 4704 | ||
| 4679 | SDqLayer* pCurLayer = pCtx->pCurDqLayer; | 4705 | SDqLayer* pCurLayer = pCtx->pCurDqLayer; |
| 4680 | SSliceCtx* pSliceCtx = &pCurLayer->sSliceEncCtx; | 4706 | SSliceCtx* pSliceCtx = &pCurLayer->sSliceEncCtx; |
| 4681 | SSlice* pSliceInLayer = pCurLayer->sLayerInfo.pSliceInLayer; | 4707 | SSlice* pStartSlice = pCurLayer->ppSliceInLayer[iStartSliceIdx]; |
| 4682 | SSlice* pStartSlice = &pSliceInLayer[iStartSliceIdx]; | ||
| 4683 | int32_t iNalIdxInLayer = *pNalIdxInLayer; | 4708 | int32_t iNalIdxInLayer = *pNalIdxInLayer; |
| 4684 | int32_t iSliceIdx = iStartSliceIdx; | 4709 | int32_t iSliceIdx = iStartSliceIdx; |
| 4685 | const int32_t kiSliceStep = pCtx->iActiveThreadsNum; | 4710 | const int32_t kiSliceStep = pCtx->iActiveThreadsNum; |