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