Showing the changes to codec/encoder/core/src/encoder_ext.cpp (1 of 6 files). Show all
Unified · Split
| @@ -58,7 +58,8 @@ namespace WelsSVCEnc { · 57 unmodified lines | |||
| 58 | 58 | ||
| 59 | 59 | ||
| 60 | int32_t WelsCodeOnePicPartition (sWelsEncCtx* pCtx, | 60 | int32_t WelsCodeOnePicPartition (sWelsEncCtx* pCtx, |
| 61 | SLayerBSInfo* pLbi, | 61 | SFrameBSInfo* pFrameBsInfo, |
| 62 | SLayerBSInfo* pLayerBsInfo, | ||
| 62 | int32_t* pNalIdxInLayer, | 63 | int32_t* pNalIdxInLayer, |
| 63 | int32_t* pLayerSize, | 64 | int32_t* pLayerSize, |
| 64 | int32_t iFirstMbInPartition, // first mb inclusive in partition | 65 | int32_t iFirstMbInPartition, // first mb inclusive in partition |
| @@ -1588,6 +1589,11 @@ void FreeMemorySvc (sWelsEncCtx** ppCtx) { · 1523 unmodified lines | |||
| 1588 | if (NULL != pDq->sLayerInfo.pSliceInLayer) { | 1589 | if (NULL != pDq->sLayerInfo.pSliceInLayer) { |
| 1589 | int32_t iSliceIdx = 0; | 1590 | int32_t iSliceIdx = 0; |
| 1590 | int32_t iSliceNum = GetInitialSliceNum (pDq->iMbWidth, pDq->iMbHeight, &pDlp->sSliceCfg); | 1591 | int32_t iSliceNum = GetInitialSliceNum (pDq->iMbWidth, pDq->iMbHeight, &pDlp->sSliceCfg); |
| 1592 | if (pDlp->sSliceCfg.uiSliceMode == SM_DYN_SLICE && pCtx->iActiveThreadsNum == 1) { | ||
| 1593 | if (iSliceNum < pDq->pSliceEncCtx->iMaxSliceNumConstraint) { | ||
| 1594 | iSliceNum = pDq->pSliceEncCtx->iMaxSliceNumConstraint; | ||
| 1595 | } | ||
| 1596 | } | ||
| 1591 | if (iSliceNum < 1) | 1597 | if (iSliceNum < 1) |
| 1592 | iSliceNum = 1; | 1598 | iSliceNum = 1; |
| 1593 | while (iSliceIdx < iSliceNum) { | 1599 | while (iSliceIdx < iSliceNum) { |
| @@ -3117,7 +3123,7 @@ int32_t WelsEncoderEncodeExt (sWelsEncCtx* pCtx, SFrameBSInfo* pFbi, const SSour · 1523 unmodified lines | |||
| 3117 | // for dynamic slicing single threading.. | 3123 | // for dynamic slicing single threading.. |
| 3118 | else if ((SM_DYN_SLICE == pParam->sSliceCfg.uiSliceMode) && (pSvcParam->iMultipleThreadIdc <= 1)) { | 3124 | else if ((SM_DYN_SLICE == pParam->sSliceCfg.uiSliceMode) && (pSvcParam->iMultipleThreadIdc <= 1)) { |
| 3119 | const int32_t kiLastMbInFrame = pCtx->pCurDqLayer->pSliceEncCtx->iMbNumInFrame; | 3125 | const int32_t kiLastMbInFrame = pCtx->pCurDqLayer->pSliceEncCtx->iMbNumInFrame; |
| 3120 | pCtx->iEncoderError = WelsCodeOnePicPartition (pCtx, pLayerBsInfo, &iNalIdxInLayer, &iLayerSize, 0, kiLastMbInFrame, 0); | 3126 | pCtx->iEncoderError = WelsCodeOnePicPartition (pCtx, pFbi, pLayerBsInfo, &iNalIdxInLayer, &iLayerSize, 0, kiLastMbInFrame, 0); |
| 3121 | WELS_VERIFY_RETURN_IFNEQ (pCtx->iEncoderError, ENC_RETURN_SUCCESS) | 3127 | WELS_VERIFY_RETURN_IFNEQ (pCtx->iEncoderError, ENC_RETURN_SUCCESS) |
| 3122 | } else { | 3128 | } else { |
| 3123 | //other multi-slice uiSliceMode | 3129 | //other multi-slice uiSliceMode |
| @@ -3680,8 +3686,112 @@ int32_t WelsEncoderParamAdjust (sWelsEncCtx** ppCtx, SWelsSvcCodingParam* pNewPa · 556 unmodified lines | |||
| 3680 | return 0; | 3686 | return 0; |
| 3681 | } | 3687 | } |
| 3682 | 3688 | ||
| 3689 | int32_t DynSliceRealloc(sWelsEncCtx* pCtx, | ||
| 3690 | SFrameBSInfo* pFrameBsInfo, | ||
| 3691 | SLayerBSInfo* pLayerBsInfo) { | ||
| 3692 | CMemoryAlign* pMA = pCtx->pMemAlign; | ||
| 3693 | SDqLayer* pCurLayer = pCtx->pCurDqLayer; | ||
| 3694 | |||
| 3695 | int32_t iCountNals = pCtx->pOut->iCountNals; | ||
| 3696 | int32_t iMaxSliceNumOld = pCurLayer->pSliceEncCtx->iMaxSliceNumConstraint; | ||
| 3697 | int32_t iMaxSliceNum = iMaxSliceNumOld; | ||
| 3698 | iCountNals += iMaxSliceNum * (pCtx->pSvcParam->iSpatialLayerNum + pCtx->bNeedPrefixNalFlag); | ||
| 3699 | iMaxSliceNum *= SLICE_NUM_EXPAND_COEF; | ||
| 3700 | |||
| 3701 | SWelsNalRaw* pNalList = (SWelsNalRaw*)pMA->WelsMalloc(iCountNals * sizeof(SWelsNalRaw), "pOut->sNalList"); | ||
| 3702 | if (NULL == pNalList) | ||
| 3703 | return ENC_RETURN_MEMALLOCERR; | ||
| 3704 | memcpy(pNalList, pCtx->pOut->sNalList, sizeof(SWelsNalRaw) * pCtx->pOut->iCountNals); | ||
| 3705 | pMA->WelsFree(pCtx->pOut->sNalList, "pOut->sNalList"); | ||
| 3706 | pCtx->pOut->sNalList = pNalList; | ||
| 3707 | |||
| 3708 | int32_t* pNalLen = (int32_t*)pMA->WelsMalloc(iCountNals * sizeof(int32_t), "pOut->pNalLen"); | ||
| 3709 | if (NULL == pNalLen) | ||
| 3710 | return ENC_RETURN_MEMALLOCERR; | ||
| 3711 | memcpy(pNalLen, pCtx->pOut->pNalLen, sizeof(int32_t) * pCtx->pOut->iCountNals); | ||
| 3712 | pMA->WelsFree(pCtx->pOut->pNalLen, "pOut->pNalLen"); | ||
| 3713 | pCtx->pOut->pNalLen = pNalLen; | ||
| 3714 | |||
| 3715 | pCtx->pOut->iCountNals = iCountNals; | ||
| 3716 | SLayerBSInfo *pLBI1, *pLBI2; | ||
| 3717 | pLBI1 = &pFrameBsInfo->sLayerInfo[0]; | ||
| 3718 | pLBI1->pNalLengthInByte = pCtx->pOut->pNalLen; | ||
| 3719 | while (pLBI1 != pLayerBsInfo) { | ||
| 3720 | pLBI2 = pLBI1; | ||
| 3721 | ++ pLBI1; | ||
| 3722 | pLBI1->pNalLengthInByte = pLBI2->pNalLengthInByte + pLBI2->iNalCount; | ||
| 3723 | } | ||
| 3724 | |||
| 3725 | SSlice *pSlice = (SSlice*)pMA->WelsMallocz( sizeof(SSlice) * iMaxSliceNum, "Slice"); | ||
| 3726 | if (NULL == pSlice) | ||
| 3727 | return ENC_RETURN_MEMALLOCERR; | ||
| 3728 | memcpy(pSlice, pCurLayer->sLayerInfo.pSliceInLayer, sizeof(SSlice) * iMaxSliceNumOld); | ||
| 3729 | uint32_t uiSliceIdx; | ||
| 3730 | uiSliceIdx = iMaxSliceNumOld; | ||
| 3731 | SSlice *pBaseSlice = &pCurLayer->sLayerInfo.pSliceInLayer[0]; | ||
| 3732 | SSliceHeaderExt *pBaseSHExt = &pBaseSlice->sSliceHeaderExt; | ||
| 3733 | SSlice *pSliceIdx = &pSlice[uiSliceIdx]; | ||
| 3734 | while (uiSliceIdx < iMaxSliceNum) { | ||
| 3735 | SSliceHeaderExt *pSHExt = &pSliceIdx->sSliceHeaderExt; | ||
| 3736 | pSliceIdx->uiSliceIdx = uiSliceIdx; | ||
| 3737 | if (pCtx->pSvcParam->iMultipleThreadIdc > 1) | ||
| 3738 | pSliceIdx->pSliceBsa = &pCtx->pSliceBs[uiSliceIdx].sBsWrite; | ||
| 3739 | else | ||
| 3740 | pSliceIdx->pSliceBsa = &pCtx->pOut->sBsWrite; | ||
| 3741 | if (AllocMbCacheAligned(&pSliceIdx->sMbCacheInfo, pMA)) | ||
| 3742 | return ENC_RETURN_MEMALLOCERR; | ||
| 3683 | 3743 | ||
| 3744 | pSliceIdx->bSliceHeaderExtFlag = pBaseSlice->bSliceHeaderExtFlag; | ||
| 3745 | pSHExt->sSliceHeader.iPpsId = pBaseSHExt->sSliceHeader.iPpsId; | ||
| 3746 | pSHExt->sSliceHeader.pPps = pBaseSHExt->sSliceHeader.pPps; | ||
| 3747 | pSHExt->sSliceHeader.iSpsId = pBaseSHExt->sSliceHeader.iSpsId; | ||
| 3748 | pSHExt->sSliceHeader.pSps = pBaseSHExt->sSliceHeader.pSps; | ||
| 3749 | pSHExt->sSliceHeader.uiRefCount = pCtx->iNumRef0; | ||
| 3750 | memcpy(&pSHExt->sSliceHeader.sRefMarking, &pBaseSHExt->sSliceHeader.sRefMarking, sizeof(SRefPicMarking)); | ||
| 3751 | memcpy(&pSHExt->sSliceHeader.sRefReordering, &pBaseSHExt->sSliceHeader.sRefReordering, sizeof(SRefPicListReorderSyntax)); | ||
| 3752 | |||
| 3753 | pSliceIdx++; | ||
| 3754 | uiSliceIdx++; | ||
| 3755 | } | ||
| 3756 | pMA->WelsFree(pCurLayer->sLayerInfo.pSliceInLayer, "Slice"); | ||
| 3757 | pCurLayer->sLayerInfo.pSliceInLayer = pSlice; | ||
| 3758 | |||
| 3759 | SRCSlicing *pSlcingOverRc = (SRCSlicing *)pMA->WelsMalloc(iMaxSliceNum * sizeof(SRCSlicing), "SlicingOverRC"); | ||
| 3760 | if (NULL == pSlcingOverRc) | ||
| 3761 | return ENC_RETURN_MEMALLOCERR; | ||
| 3762 | memcpy(pSlcingOverRc, pCtx->pWelsSvcRc->pSlicingOverRc, sizeof(SRCSlicing) * iMaxSliceNumOld); | ||
| 3763 | uiSliceIdx = iMaxSliceNumOld; | ||
| 3764 | SRCSlicing *pSORC = &pSlcingOverRc[uiSliceIdx]; | ||
| 3765 | while (uiSliceIdx < iMaxSliceNum) { | ||
| 3766 | pSORC->iComplexityIndexSlice = 0; | ||
| 3767 | pSORC->iCalculatedQpSlice = pCtx->iGlobalQp; | ||
| 3768 | pSORC ++; | ||
| 3769 | uiSliceIdx ++; | ||
| 3770 | } | ||
| 3771 | pMA->WelsFree(pCtx->pWelsSvcRc->pSlicingOverRc, "SlicingOverRC"); | ||
| 3772 | pCtx->pWelsSvcRc->pSlicingOverRc = pSlcingOverRc; | ||
| 3773 | |||
| 3774 | int16_t *pFirstMbInSlice = (int16_t *)pMA->WelsMalloc(iMaxSliceNum * sizeof(int16_t), "pSliceSeg->pFirstMbInSlice"); | ||
| 3775 | if (NULL == pFirstMbInSlice) | ||
| 3776 | return ENC_RETURN_MEMALLOCERR; | ||
| 3777 | memcpy(pFirstMbInSlice, pCurLayer->pSliceEncCtx->pFirstMbInSlice, sizeof(int16_t) * iMaxSliceNumOld); | ||
| 3778 | pMA->WelsFree(pCurLayer->pSliceEncCtx->pFirstMbInSlice, "pSliceSeg->pFirstMbInSlice"); | ||
| 3779 | pCurLayer->pSliceEncCtx->pFirstMbInSlice = pFirstMbInSlice; | ||
| 3780 | |||
| 3781 | int32_t *pCountMbNumInSlice = (int32_t *)pMA->WelsMalloc(iMaxSliceNum * sizeof(int32_t), "pSliceSeg->pCountMbNumInSlice"); | ||
| 3782 | if (NULL == pCountMbNumInSlice) | ||
| 3783 | return ENC_RETURN_MEMALLOCERR; | ||
| 3784 | memcpy(pCountMbNumInSlice, pCurLayer->pSliceEncCtx->pCountMbNumInSlice, sizeof(int32_t) * iMaxSliceNumOld); | ||
| 3785 | pMA->WelsFree(pCurLayer->pSliceEncCtx->pCountMbNumInSlice, "pSliceSeg->pCountMbNumInSlice"); | ||
| 3786 | pCurLayer->pSliceEncCtx->pCountMbNumInSlice = pCountMbNumInSlice; | ||
| 3787 | |||
| 3788 | if (pCtx->iMaxSliceCount < iMaxSliceNum) | ||
| 3789 | pCtx->iMaxSliceCount = iMaxSliceNum; | ||
| 3790 | pCurLayer->pSliceEncCtx->iMaxSliceNumConstraint = iMaxSliceNum; | ||
| 3791 | return ENC_RETURN_SUCCESS; | ||
| 3792 | } | ||
| 3684 | int32_t WelsCodeOnePicPartition (sWelsEncCtx* pCtx, | 3793 | int32_t WelsCodeOnePicPartition (sWelsEncCtx* pCtx, |
| 3794 | SFrameBSInfo* pFrameBSInfo, | ||
| 3685 | SLayerBSInfo* pLayerBsInfo, | 3795 | SLayerBSInfo* pLayerBsInfo, |
| 3686 | int32_t* pNalIdxInLayer, | 3796 | int32_t* pNalIdxInLayer, |
| 3687 | int32_t* pLayerSize, | 3797 | int32_t* pLayerSize, |
| @@ -3701,6 +3811,7 @@ int32_t WelsCodeOnePicPartition (sWelsEncCtx* pCtx, · 13 unmodified lines | |||
| 3701 | const EWelsNalUnitType keNalType = pCtx->eNalType; | 3811 | const EWelsNalUnitType keNalType = pCtx->eNalType; |
| 3702 | const EWelsNalRefIdc keNalRefIdc = pCtx->eNalPriority; | 3812 | const EWelsNalRefIdc keNalRefIdc = pCtx->eNalPriority; |
| 3703 | const bool kbNeedPrefix = pCtx->bNeedPrefixNalFlag; | 3813 | const bool kbNeedPrefix = pCtx->bNeedPrefixNalFlag; |
| 3814 | const int32_t kiSliceIdxStep = pCtx->iActiveThreadsNum; | ||
| 3704 | int32_t iReturn = ENC_RETURN_SUCCESS; | 3815 | int32_t iReturn = ENC_RETURN_SUCCESS; |
| 3705 | 3816 | ||
| 3706 | //init | 3817 | //init |
| @@ -3715,10 +3826,13 @@ int32_t WelsCodeOnePicPartition (sWelsEncCtx* pCtx, · 8 unmodified lines | |||
| 3715 | int32_t iSliceSize = 0; | 3826 | int32_t iSliceSize = 0; |
| 3716 | int32_t iPayloadSize = 0; | 3827 | int32_t iPayloadSize = 0; |
| 3717 | 3828 | ||
| 3718 | if (iSliceIdx >= pSliceCtx->iMaxSliceNumConstraint) { // insufficient memory in pSliceInLayer[] | 3829 | if (iSliceIdx >= (pSliceCtx->iMaxSliceNumConstraint - kiSliceIdxStep)) { // insufficient memory in pSliceInLayer[] |
| 3719 | // TODO: need exception handler for not large enough of MAX_SLICES_NUM related memory usage | 3830 | if (pCtx->iActiveThreadsNum == 1) |
| 3720 | // No idea about its solution due MAX_SLICES_NUM is fixed lenght in relevent pData structure | 3831 | if (DynSliceRealloc(pCtx, pFrameBSInfo, pLayerBsInfo)) //only single thread support re-alloc now |
| 3721 | return ENC_RETURN_MEMALLOCERR; | 3832 | return ENC_RETURN_MEMALLOCERR; |
| 3833 | else if (iSliceIdx >= pSliceCtx->iMaxSliceNumConstraint) { | ||
| 3834 | return ENC_RETURN_MEMALLOCERR; | ||
| 3835 | } | ||
| 3722 | } | 3836 | } |
| 3723 | 3837 | ||
| 3724 | if (kbNeedPrefix) { | 3838 | if (kbNeedPrefix) { |