Showing the changes to codec/encoder/core/src/encoder_ext.cpp (1 of 6 files). Show all
Unified · Split
| @@ -1754,7 +1754,8 @@ int32_t RequestMemorySvc (sWelsEncCtx** ppCtx, SExistingParasetList* pExistingPa · 1753 unmodified lines | |||
| 1754 | return 1; | 1754 | return 1; |
| 1755 | } | 1755 | } |
| 1756 | 1756 | ||
| 1757 | (*ppCtx)->pReferenceStrategy = IWelsReferenceStrategy::CreateReferenceStrategy((*ppCtx), pParam->iUsageType, pParam->bEnableLongTermReference); | 1757 | (*ppCtx)->pReferenceStrategy = IWelsReferenceStrategy::CreateReferenceStrategy ((*ppCtx), pParam->iUsageType, |
| 1758 | pParam->bEnableLongTermReference); | ||
| 1758 | WELS_VERIFY_RETURN_PROC_IF (1, (NULL == (*ppCtx)->pReferenceStrategy), FreeMemorySvc (ppCtx)) | 1759 | WELS_VERIFY_RETURN_PROC_IF (1, (NULL == (*ppCtx)->pReferenceStrategy), FreeMemorySvc (ppCtx)) |
| 1759 | 1760 | ||
| 1760 | (*ppCtx)->pIntra4x4PredModeBlocks = static_cast<int8_t*> | 1761 | (*ppCtx)->pIntra4x4PredModeBlocks = static_cast<int8_t*> |
| @@ -1946,7 +1947,7 @@ void FreeMemorySvc (sWelsEncCtx** ppCtx) { · 185 unmodified lines | |||
| 1946 | ReleaseMtResource (ppCtx); | 1947 | ReleaseMtResource (ppCtx); |
| 1947 | 1948 | ||
| 1948 | if (NULL != pCtx->pReferenceStrategy) { | 1949 | if (NULL != pCtx->pReferenceStrategy) { |
| 1949 | WELS_DELETE_OP(pCtx->pReferenceStrategy); | 1950 | WELS_DELETE_OP (pCtx->pReferenceStrategy); |
| 1950 | } | 1951 | } |
| 1951 | 1952 | ||
| 1952 | // frame bitstream pBuffer | 1953 | // frame bitstream pBuffer |
| @@ -3453,7 +3454,6 @@ EVideoFrameType PrepareEncodeFrame (sWelsEncCtx* pCtx, SLayerBSInfo*& pLayerBsIn · 1500 unmodified lines | |||
| 3453 | int32_t& iLayerNum, int32_t& iFrameSize, long long uiTimeStamp) { | 3454 | int32_t& iLayerNum, int32_t& iFrameSize, long long uiTimeStamp) { |
| 3454 | SWelsSvcCodingParam* pSvcParam = pCtx->pSvcParam; | 3455 | SWelsSvcCodingParam* pSvcParam = pCtx->pSvcParam; |
| 3455 | SSpatialPicIndex* pSpatialIndexMap = &pCtx->sSpatialIndexMap[0]; | 3456 | SSpatialPicIndex* pSpatialIndexMap = &pCtx->sSpatialIndexMap[0]; |
| 3456 | |||
| 3457 | if (!pSvcParam->bSimulcastAVC) { | 3457 | if (!pSvcParam->bSimulcastAVC) { |
| 3458 | pCtx->iSkipFrameFlag = false; | 3458 | pCtx->iSkipFrameFlag = false; |
| 3459 | for (int32_t iDid = 0; iDid < iSpatialNum; iDid++) { | 3459 | for (int32_t iDid = 0; iDid < iSpatialNum; iDid++) { |
| @@ -3461,8 +3461,6 @@ EVideoFrameType PrepareEncodeFrame (sWelsEncCtx* pCtx, SLayerBSInfo*& pLayerBsIn · 1 unmodified line | |||
| 3461 | pCtx->iSkipFrameFlag = 1; | 3461 | pCtx->iSkipFrameFlag = 1; |
| 3462 | } | 3462 | } |
| 3463 | } | 3463 | } |
| 3464 | |||
| 3465 | |||
| 3466 | EVideoFrameType eFrameType = DecideFrameType (pCtx, iSpatialNum, iCurDid); | 3464 | EVideoFrameType eFrameType = DecideFrameType (pCtx, iSpatialNum, iCurDid); |
| 3467 | 3465 | ||
| 3468 | if (eFrameType == videoFrameTypeSkip) { | 3466 | if (eFrameType == videoFrameTypeSkip) { |
| @@ -3502,35 +3500,34 @@ EVideoFrameType PrepareEncodeFrame (sWelsEncCtx* pCtx, SLayerBSInfo*& pLayerBsIn · 33 unmodified lines | |||
| 3502 | pCtx->iContinualSkipFrames = 0; | 3500 | pCtx->iContinualSkipFrames = 0; |
| 3503 | iCurTid = GetTemporalLevel (&pSvcParam->sDependencyLayers[iCurDid], pParamInternal->iCodingIndex, | 3501 | iCurTid = GetTemporalLevel (&pSvcParam->sDependencyLayers[iCurDid], pParamInternal->iCodingIndex, |
| 3504 | pSvcParam->uiGopSize); | 3502 | pSvcParam->uiGopSize); |
| 3505 | //skip this spatial layer | 3503 | pCtx->uiTemporalId = iCurTid; |
| 3506 | if (iCurTid == INVALID_TEMPORAL_ID) { | 3504 | if (eFrameType == videoFrameTypeIDR) { |
| 3507 | pParamInternal->iCodingIndex ++; | 3505 | // write parameter sets bitstream or SEI/SSEI (if any) here |
| 3508 | eFrameType = videoFrameTypeSkip; | 3506 | // TODO: use function pointer instead |
| 3509 | pLayerBsInfo->eFrameType = videoFrameTypeSkip; | 3507 | if (! (SPS_LISTING & pCtx->pSvcParam->eSpsPpsIdStrategy)) { |
| 3510 | } else { | 3508 | if (pSvcParam->bSimulcastAVC) { |
| 3511 | pCtx->uiTemporalId = iCurTid; | 3509 | pCtx->iEncoderError = WriteSavcParaset (pCtx, iCurDid, pLayerBsInfo, iLayerNum, iFrameSize); |
| 3512 | if (eFrameType == videoFrameTypeIDR) { | 3510 | ++ pCtx->uiIdrPicId; |
| 3513 | // write parameter sets bitstream or SEI/SSEI (if any) here | ||
| 3514 | // TODO: use function pointer instead | ||
| 3515 | if (! (SPS_LISTING & pCtx->pSvcParam->eSpsPpsIdStrategy)) { | ||
| 3516 | if (pSvcParam->bSimulcastAVC) { | ||
| 3517 | pCtx->iEncoderError = WriteSavcParaset (pCtx, iCurDid, pLayerBsInfo, iLayerNum, iFrameSize); | ||
| 3518 | ++ pCtx->uiIdrPicId; | ||
| 3519 | } else { | ||
| 3520 | pCtx->iEncoderError = WriteSsvcParaset (pCtx, iSpatialNum, pLayerBsInfo, iLayerNum, iFrameSize); | ||
| 3521 | ++ pCtx->uiIdrPicId; | ||
| 3522 | } | ||
| 3523 | } else { | 3511 | } else { |
| 3524 | pCtx->iEncoderError = WriteSavcParaset_Listing (pCtx, iSpatialNum, pLayerBsInfo, iLayerNum, iFrameSize); | 3512 | pCtx->iEncoderError = WriteSsvcParaset (pCtx, iSpatialNum, pLayerBsInfo, iLayerNum, iFrameSize); |
| 3525 | |||
| 3526 | ++ pCtx->uiIdrPicId; | 3513 | ++ pCtx->uiIdrPicId; |
| 3527 | } | 3514 | } |
| 3515 | } else { | ||
| 3516 | pCtx->iEncoderError = WriteSavcParaset_Listing (pCtx, iSpatialNum, pLayerBsInfo, iLayerNum, iFrameSize); | ||
| 3517 | |||
| 3518 | ++ pCtx->uiIdrPicId; | ||
| 3528 | } | 3519 | } |
| 3529 | } | 3520 | } |
| 3530 | 3521 | if (!pSvcParam->bSimulcastAVC) { | |
| 3522 | for (int32_t i = 0; i < pSvcParam->iSpatialLayerNum; i++) { | ||
| 3523 | SSpatialLayerInternal* pParamInternal = &pSvcParam->sDependencyLayers[i]; | ||
| 3524 | pParamInternal->iCodingIndex ++; | ||
| 3525 | } | ||
| 3526 | } else { | ||
| 3527 | SSpatialLayerInternal* pParamInternal = &pSvcParam->sDependencyLayers[iCurDid]; | ||
| 3528 | pParamInternal->iCodingIndex++; | ||
| 3529 | } | ||
| 3531 | } | 3530 | } |
| 3532 | |||
| 3533 | |||
| 3534 | return eFrameType; | 3531 | return eFrameType; |
| 3535 | } | 3532 | } |
| 3536 | /*! | 3533 | /*! |
| @@ -3608,8 +3605,8 @@ int32_t WelsEncoderEncodeExt (sWelsEncCtx* pCtx, SFrameBSInfo* pFbi, const SSour · 71 unmodified lines | |||
| 3608 | InitBitStream (pCtx); | 3605 | InitBitStream (pCtx); |
| 3609 | pLayerBsInfo->pBsBuf = pCtx->pFrameBs ; | 3606 | pLayerBsInfo->pBsBuf = pCtx->pFrameBs ; |
| 3610 | pLayerBsInfo->pNalLengthInByte = pCtx->pOut->pNalLen; | 3607 | pLayerBsInfo->pNalLengthInByte = pCtx->pOut->pNalLen; |
| 3611 | 3608 | iCurDid = pSpatialIndexMap->iDid; | |
| 3612 | pCtx->pCurDqLayer = pCtx->ppDqLayerList[pSpatialIndexMap->iDid]; | 3609 | pCtx->pCurDqLayer = pCtx->ppDqLayerList[iCurDid]; |
| 3613 | pCtx->pCurDqLayer->pRefLayer = NULL; | 3610 | pCtx->pCurDqLayer->pRefLayer = NULL; |
| 3614 | if (!pSvcParam->bSimulcastAVC) { | 3611 | if (!pSvcParam->bSimulcastAVC) { |
| 3615 | eFrameType = PrepareEncodeFrame (pCtx, pLayerBsInfo, iSpatialNum , iCurDid, iCurTid, iLayerNum, iFrameSize, | 3612 | eFrameType = PrepareEncodeFrame (pCtx, pLayerBsInfo, iSpatialNum , iCurDid, iCurTid, iLayerNum, iFrameSize, |
| @@ -3617,9 +3614,16 @@ int32_t WelsEncoderEncodeExt (sWelsEncCtx* pCtx, SFrameBSInfo* pFbi, const SSour · 1 unmodified line | |||
| 3617 | if (eFrameType == videoFrameTypeSkip) { | 3614 | if (eFrameType == videoFrameTypeSkip) { |
| 3618 | pFbi->eFrameType = videoFrameTypeSkip; | 3615 | pFbi->eFrameType = videoFrameTypeSkip; |
| 3619 | pLayerBsInfo->eFrameType = videoFrameTypeSkip; | 3616 | pLayerBsInfo->eFrameType = videoFrameTypeSkip; |
| 3620 | |||
| 3621 | return ENC_RETURN_SUCCESS; | 3617 | return ENC_RETURN_SUCCESS; |
| 3622 | } | 3618 | } |
| 3619 | } else { | ||
| 3620 | for (int32_t iDidIdx = 0; iDidIdx < pSvcParam->iSpatialLayerNum; iDidIdx++) { | ||
| 3621 | SSpatialLayerInternal* pParamInternal = &pSvcParam->sDependencyLayers[iDidIdx]; | ||
| 3622 | int32_t iTemporalId = GetTemporalLevel (pParamInternal, pParamInternal->iCodingIndex, | ||
| 3623 | pSvcParam->uiGopSize); | ||
| 3624 | if (iTemporalId == INVALID_TEMPORAL_ID) | ||
| 3625 | pParamInternal->iCodingIndex ++; | ||
| 3626 | } | ||
| 3623 | } | 3627 | } |
| 3624 | 3628 | ||
| 3625 | while (iSpatialIdx < iSpatialNum) { | 3629 | while (iSpatialIdx < iSpatialNum) { |
| @@ -3713,7 +3717,7 @@ int32_t WelsEncoderEncodeExt (sWelsEncCtx* pCtx, SFrameBSInfo* pFbi, const SSour · 87 unmodified lines | |||
| 3713 | 3717 | ||
| 3714 | WelsInitCurrentLayer (pCtx, iCurWidth, iCurHeight); | 3718 | WelsInitCurrentLayer (pCtx, iCurWidth, iCurHeight); |
| 3715 | 3719 | ||
| 3716 | pCtx->pReferenceStrategy->MarkPic (); | 3720 | pCtx->pReferenceStrategy->MarkPic(); |
| 3717 | if (!pCtx->pReferenceStrategy->BuildRefList (pParamInternal->iPOC, 0)) { | 3721 | if (!pCtx->pReferenceStrategy->BuildRefList (pParamInternal->iPOC, 0)) { |
| 3718 | WelsLog (pLogCtx, WELS_LOG_WARNING, | 3722 | WelsLog (pLogCtx, WELS_LOG_WARNING, |
| 3719 | "WelsEncoderEncodeExt(), WelsBuildRefList failed for P frames, pCtx->iNumRef0= %d. ForceCodingIDR!", | 3723 | "WelsEncoderEncodeExt(), WelsBuildRefList failed for P frames, pCtx->iNumRef0= %d. ForceCodingIDR!", |
| @@ -3723,7 +3727,7 @@ int32_t WelsEncoderEncodeExt (sWelsEncCtx* pCtx, SFrameBSInfo* pFbi, const SSour · 3 unmodified lines | |||
| 3723 | break; | 3727 | break; |
| 3724 | } | 3728 | } |
| 3725 | if (pCtx->eSliceType != I_SLICE) { | 3729 | if (pCtx->eSliceType != I_SLICE) { |
| 3726 | pCtx->pReferenceStrategy->AfterBuildRefList (); | 3730 | pCtx->pReferenceStrategy->AfterBuildRefList(); |
| 3727 | } | 3731 | } |
| 3728 | #ifdef LONG_TERM_REF_DUMP | 3732 | #ifdef LONG_TERM_REF_DUMP |
| 3729 | DumpRef (pCtx); | 3733 | DumpRef (pCtx); |
| @@ -3981,7 +3985,7 @@ int32_t WelsEncoderEncodeExt (sWelsEncCtx* pCtx, SFrameBSInfo* pFbi, const SSour · 251 unmodified lines | |||
| 3981 | 3985 | ||
| 3982 | // reference picture list update | 3986 | // reference picture list update |
| 3983 | if (eNalRefIdc != NRI_PRI_LOWEST) { | 3987 | if (eNalRefIdc != NRI_PRI_LOWEST) { |
| 3984 | if (!pCtx->pReferenceStrategy->UpdateRefList ()) { | 3988 | if (!pCtx->pReferenceStrategy->UpdateRefList()) { |
| 3985 | WelsLog (pLogCtx, WELS_LOG_WARNING, "WelsEncoderEncodeExt(), WelsUpdateRefList failed. ForceCodingIDR!"); | 3989 | WelsLog (pLogCtx, WELS_LOG_WARNING, "WelsEncoderEncodeExt(), WelsUpdateRefList failed. ForceCodingIDR!"); |
| 3986 | //the above is to set the next frame to be IDR | 3990 | //the above is to set the next frame to be IDR |
| 3987 | pCtx->iEncoderError = ENC_RETURN_CORRECTED; | 3991 | pCtx->iEncoderError = ENC_RETURN_CORRECTED; |
| @@ -4155,7 +4159,7 @@ int32_t WelsEncoderEncodeExt (sWelsEncCtx* pCtx, SFrameBSInfo* pFbi, const SSour · 167 unmodified lines | |||
| 4155 | && (pCtx->pLtr[pCtx->uiDependencyId].iLTRMarkMode == LTR_DIRECT_MARK)) || eFrameType == videoFrameTypeIDR)) { | 4159 | && (pCtx->pLtr[pCtx->uiDependencyId].iLTRMarkMode == LTR_DIRECT_MARK)) || eFrameType == videoFrameTypeIDR)) { |
| 4156 | pCtx->bRefOfCurTidIsLtr[iCurDid][iCurTid] = true; | 4160 | pCtx->bRefOfCurTidIsLtr[iCurDid][iCurTid] = true; |
| 4157 | } | 4161 | } |
| 4158 | ++ pParamInternal->iCodingIndex; | 4162 | // ++ pParamInternal->iCodingIndex; |
| 4159 | }//end of (iSpatialIdx/iSpatialNum) | 4163 | }//end of (iSpatialIdx/iSpatialNum) |
| 4160 | 4164 | ||
| 4161 | if (ENC_RETURN_CORRECTED == pCtx->iEncoderError) { | 4165 | if (ENC_RETURN_CORRECTED == pCtx->iEncoderError) { |