gopencoder.cpp
来自「SVC最新更新代码」· C++ 代码 · 共 1,714 行 · 第 1/5 页
CPP
1,714 行
m_pcSPS = 0;
m_pcPPSLP = 0;
m_pcPPSHP = 0;
m_pcYuvFullPelBufferCtrl = pcYuvFullPelBufferCtrl;
m_pcYuvHalfPelBufferCtrl = pcYuvHalfPelBufferCtrl;
m_pcPocCalculator = pcPocCalculator;
m_pcH264AVCEncoder = pcH264AVCEncoder;
m_pcSliceEncoder = pcSliceEncoder;
m_pcNalUnitEncoder = pcNalUnitEncoder;
m_pcLoopFilter = pcLoopFilter;
m_pcQuarterPelFilter = pcQuarterPelFilter;
m_pcMotionEstimation = pcMotionEstimation;
//JVT-U106 Behaviour at slice boundaries{
m_pcReconstructionBypass = pcReconstructionBypass;
//JVT-U106 Behaviour at slice boundaries}
m_pcLayerParameters = pcLayerParameters;
//----- fixed control parameters -----
m_bInterlaced = pcLayerParameters->isInterlaced();
// JVT-V068 {
m_bEnableHrd = pcCodingParameter->getEnableNalHRD() || pcCodingParameter->getEnableVclHRD();
m_apcScheduler = apcScheduler;
// JVT-V068 }
// JVT-W049 {
m_uiNumberLayersCnt = pcCodingParameter->getNumberOfLayers();
// JVT-W049 }
m_uiDependencyId = pcLayerParameters->getDependencyId ();
m_uiBaseLayerId = pcLayerParameters->getBaseLayerId ();
m_uiBaseQualityLevel = pcLayerParameters->getBaseQualityLevel ();
// JVT-Q065 EIDR{
m_iIDRPeriod = pcLayerParameters->getIDRPeriod ();
// JVT-Q065 EIDR}
// JVT-U085 LMI
m_bTlevelNestingFlag = pcCodingParameter->getTlevelNestingFlag();
// JVT-U116 W062 LMI
m_bTl0DepRepIdxEnable = pcCodingParameter->getTl0DepRepIdxSeiEnable();
m_bDiscardable = pcLayerParameters->isDiscardable(); //DS_FIX_FT_09_2007
m_uiQLDiscardable = pcLayerParameters->getQLDiscardable(); //DS_FIX_FT_09_2007
m_uiEssRPChkEnable = pcCodingParameter->getEssRPChkEnable();
m_uiMVThres = pcCodingParameter->getMVThres();
m_uiDecompositionStages = pcLayerParameters->getDecompositionStages ();
m_uiTemporalResolution = pcLayerParameters->getTemporalResolution ();
m_uiNotCodedStages = pcLayerParameters->getNotCodedStages ();
m_uiFrameDelay = pcLayerParameters->getFrameDelay ();
m_uiMaxNumRefFrames = pcCodingParameter->getNumRefFrames ();
m_uiLowPassIntraPeriod = pcCodingParameter->getIntraPeriodLowPass ();
m_uiNumMaxIter = pcCodingParameter->getMotionVectorSearchParams().getNumMaxIter ();
m_uiIterSearchRange = pcCodingParameter->getMotionVectorSearchParams().getIterSearchRange ();
m_iMaxDeltaQp = pcLayerParameters->getMaxAbsDeltaQP ();
m_bH264AVCCompatible = m_uiDependencyId == 0; //bug-fix suffix
m_bInterLayerPrediction = pcLayerParameters->getInterLayerPredictionMode() > 0;
m_bAdaptivePrediction = pcLayerParameters->getInterLayerPredictionMode() > 1;
m_bBiPred8x8Disable = pcLayerParameters->getBiPred8x8Disable() > 0;
m_bMCBlks8x8Disable = pcLayerParameters->getMCBlks8x8Disable() > 0;
m_bBotFieldFirst = pcLayerParameters->getBotFieldFirst() > 0;
m_bUseLongTermPics = pcLayerParameters->getUseLongTerm() > 0;
m_iMaxLongTermFrmIdx = -1;
m_uiNextTL0LongTermIdx = 0;
if( m_bUseLongTermPics )
{
m_iMaxLongTermFrmIdx = m_uiDecompositionStages - m_uiNotCodedStages + ( pcLayerParameters->getPAff() ? 1 : 0 );
}
m_uiPicCodingType = pcLayerParameters->getPicCodingType();
m_bForceReOrderingCommands= pcLayerParameters->getForceReorderingCommands () > 0;
m_bWriteSubSequenceSei = pcCodingParameter->getBaseLayerMode () > 1 && m_uiDependencyId == 0;
m_bSameResBL = ( m_uiBaseLayerId != MSYS_UINT_MAX &&
pcCodingParameter->getLayerParameters( m_uiBaseLayerId ).getFrameWidthInSamples () == pcLayerParameters->getFrameWidthInSamples () &&
pcCodingParameter->getLayerParameters( m_uiBaseLayerId ).getFrameHeightInSamples() == pcLayerParameters->getFrameHeightInSamples() &&
pcLayerParameters->getResizeParameters().m_iExtendedSpatialScalability == ESS_NONE );
m_bSameResEL = false;
{
UInt uiLId;
for( uiLId = m_uiDependencyId + 1; uiLId < pcCodingParameter->getNumberOfLayers() && ! m_bSameResEL; uiLId++ )
{
LayerParameters& rcEL = pcCodingParameter->getLayerParameters( uiLId );
if( rcEL.getBaseLayerId() == m_uiDependencyId )
{
m_bSameResEL = ( pcLayerParameters->getFrameWidthInSamples () == rcEL.getFrameWidthInSamples () &&
pcLayerParameters->getFrameHeightInSamples() == rcEL.getFrameHeightInSamples() &&
rcEL.getResizeParameters().m_iExtendedSpatialScalability == ESS_NONE );
}
}
}
m_bMGS = pcCodingParameter->getCGSSNRRefinement () == 1 && ( m_bSameResBL || m_bSameResEL );
m_uiEncodeKeyPictures = ( pcLayerParameters->isIntraOnly() ? 0 : pcCodingParameter->getEncodeKeyPictures() );
m_uiMGSKeyPictureControl = pcCodingParameter->getMGSKeyPictureControl();
m_bHighestMGSLayer = m_bMGS && !m_bSameResEL;
m_uiLastCodedFrameIdInGOP = MSYS_UINT_MAX;
m_uiLastCodedTemporalId = MSYS_UINT_MAX;
RNOK( xInitCodingOrder( m_uiDecompositionStages, m_uiTemporalResolution, m_uiFrameDelay ) );
for( UInt uiTId = 0; uiTId <= MAX_DSTAGES; uiTId++ )
{
m_acActiveRefListFrameNum[uiTId].clear();
}
m_cActiveRefBasePicListFrameNum.clear();
m_bExplicitQPCascading = pcLayerParameters->getExplicitQPCascading() != 0;
for( UInt uiTTL = 0; uiTTL < MAX_TEMP_LEVELS; uiTTL++ )
{
m_adDeltaQPTLevel[uiTTL] = pcLayerParameters->getDeltaQPTLevel( uiTTL );
}
//JVT-V079 Low-complexity MB mode decision {
if ( m_uiDependencyId==0 )
m_pcSliceEncoder->getMbEncoder()->setLowComplexMbEnable ( m_uiDependencyId, (pcLayerParameters->getLowComplexMbEnable ()==1) );
else
m_pcSliceEncoder->getMbEncoder()->setLowComplexMbEnable ( m_uiDependencyId, false );
//JVT-V079 Low-complexity MB mode decision }
//JVT-R057 LA-RDO{
if(pcCodingParameter->getLARDOEnable()!=0)
{
static UInt auiPLR[5];
static UInt aauiSize[5][2];
static Double dRatio[5][2];
auiPLR[m_uiDependencyId] = pcLayerParameters->getPLR ();
m_bLARDOEnable = pcCodingParameter->getLARDOEnable()==0? false:true;
aauiSize[m_uiDependencyId][0] = pcLayerParameters->getFrameWidthInSamples ();
aauiSize[m_uiDependencyId][1] = pcLayerParameters->getFrameHeightInSamples();
if(m_uiDependencyId==0||pcLayerParameters->getBaseLayerId()==MSYS_UINT_MAX)
{
dRatio[m_uiDependencyId][0]=1;
dRatio[m_uiDependencyId][1]=1;
}
else
{
dRatio[m_uiDependencyId][0]=(Double)aauiSize[m_uiDependencyId][0]/aauiSize[pcLayerParameters->getBaseLayerId()][0];
dRatio[m_uiDependencyId][1]=(Double)aauiSize[m_uiDependencyId][1]/aauiSize[pcLayerParameters->getBaseLayerId()][1];
}
m_pcSliceEncoder->getMbEncoder()->setRatio(dRatio);
m_pcSliceEncoder->getMbEncoder()->setPLR(auiPLR);
pcLayerParameters->setContrainedIntraForLP();
}
//JVT-R057 LA-RDO}
m_uiPreAndSuffixUnitEnable = pcCodingParameter->getPreAndSuffixUnitEnable();//JVT-S036 lsj
m_uiMMCOBaseEnable = pcCodingParameter->getMMCOBaseEnable(); //JVT-S036 lsj
// TMM_ESS
m_pcResizeParameters = &pcLayerParameters->getResizeParameters();
m_pESSFile = 0;
if( m_pcResizeParameters->m_iExtendedSpatialScalability == ESS_PICT )
{
m_pESSFile = fopen( pcLayerParameters->getESSFilename().c_str(), "r" );
if( !m_pESSFile )
{
printf( "failed to open resize parameter file %s\n", pcLayerParameters->getESSFilename().c_str() );
ROT(1);
}
}
for( UInt uiStage = 0; uiStage < MAX_DSTAGES; uiStage++ )
{
m_adBaseQpLambdaMotion[uiStage] = pcLayerParameters->getQpModeDecision( uiStage );
}
m_dBaseQpLambdaMotionLP = pcLayerParameters->getQpModeDecisionLP ();
m_dBaseQPResidual = pcLayerParameters->getBaseQpResidual ();
m_uiFilterIdc = pcCodingParameter->getLoopFilterParams ().getFilterIdc ();
m_iAlphaOffset = pcCodingParameter->getLoopFilterParams ().getAlphaOffset ();
m_iBetaOffset = pcCodingParameter->getLoopFilterParams ().getBetaOffset ();
m_uiInterLayerFilterIdc = pcCodingParameter->getInterLayerLoopFilterParams().getFilterIdc ();
m_iInterLayerAlphaOffset = pcCodingParameter->getInterLayerLoopFilterParams().getAlphaOffset ();
m_iInterLayerBetaOffset = pcCodingParameter->getInterLayerLoopFilterParams().getBetaOffset ();
m_bLoadMotionInfo = pcLayerParameters->getMotionInfoMode () == 1;
m_bSaveMotionInfo = pcLayerParameters->getMotionInfoMode () == 2;
m_pMotionInfoFile = 0;
if( m_bLoadMotionInfo )
{
m_pMotionInfoFile = ::fopen( pcLayerParameters->getMotionInfoFilename().c_str(), "rb" );
if( ! m_pMotionInfoFile )
{
fprintf( stderr, "\nCANNOT OPEN MOTION INFO FILE \"%s\"\n\n", pcLayerParameters->getMotionInfoFilename().c_str() );
return Err::m_nERR;
}
}
else if( m_bSaveMotionInfo )
{
m_pMotionInfoFile = ::fopen( pcLayerParameters->getMotionInfoFilename().c_str(), "wb" );
if( ! m_pMotionInfoFile )
{
fprintf( stderr, "\nCANNOT OPEN MOTION INFO FILE \"%s\"\n\n", pcLayerParameters->getMotionInfoFilename().c_str() );
return Err::m_nERR;
}
}
//----- PSNR and rate -----
m_fOutputFrameRate = pcLayerParameters->getOutputFrameRate();
m_uiParameterSetBits = 0;
UInt ui;
for( ui = 0; ui <= MAX_DSTAGES; ui++ )
{
m_auiNumFramesCoded [ui] = 0;
m_adPSNRSumY [ui] = 0.0;
m_adPSNRSumU [ui] = 0.0;
m_adPSNRSumV [ui] = 0.0;
}
m_uiNewlyCodedBits = 0;
// JVT-S054 (ADD) ->
if( pcLayerParameters->m_bSliceDivisionFlag )
{
if( m_puiFirstMbInSlice != NULL )
free(m_puiFirstMbInSlice);
m_puiFirstMbInSlice = (UInt*)malloc((pcLayerParameters->m_uiNumSliceMinus1+1)*sizeof(UInt));
memcpy( m_puiFirstMbInSlice, pcLayerParameters->m_puiFirstMbInSlice, (pcLayerParameters->m_uiNumSliceMinus1+1)*sizeof(UInt) );
}
// JVT-S054 (ADD) <-
//S051{
m_uiTotalFrame = pcCodingParameter->getTotalFrames();
m_uiAnaSIP = pcLayerParameters->getAnaSIP();
m_cOutSIPFileName = pcLayerParameters->getOutSIPFileName();
if(m_uiAnaSIP==1)
m_bInterLayerPrediction=true;
if(m_uiAnaSIP==2)
m_bInterLayerPrediction=m_bAdaptivePrediction=false;
if(pcCodingParameter->getNumberOfLayers() > m_uiDependencyId+1)
{
m_bEncSIP = pcCodingParameter->getLayerParameters( m_uiDependencyId+1).getEncSIP();
m_cInSIPFileName = pcCodingParameter->getLayerParameters( m_uiDependencyId+1).getInSIPFileName();
}
//S051}
//JVT-U106 Behaviour at slice boundaries{
m_bCIUFlag=pcCodingParameter->getCIUFlag()!=0;
//JVT-U106 Behaviour at slice boundaries}
{
Int iMaxNumMb = pcLayerParameters->getFrameWidthInMbs() * pcLayerParameters->getFrameHeightInMbs();
m_apabBaseModeFlagAllowedArrays[0] = new Bool [iMaxNumMb];
m_apabBaseModeFlagAllowedArrays[1] = new Bool [iMaxNumMb];
ROF( m_apabBaseModeFlagAllowedArrays[0] );
ROF( m_apabBaseModeFlagAllowedArrays[1] );
}
m_uiFramesInCompleteGOPsProcessed = 0;
m_uiMinScalableLayer = 0;
for( UInt uiBaseLayerId = 0; uiBaseLayerId < m_uiDependencyId; uiBaseLayerId++ )
{
m_uiMinScalableLayer += pcCodingParameter->getLayerParameters( uiBaseLayerId ).getDecompositionStages() -
pcCodingParameter->getLayerParameters( uiBaseLayerId ).getNotCodedStages () + 1U;
}
//JVT-X046 {
m_uiSliceMode = pcLayerParameters->getSliceMode();
m_uiSliceArgument = pcLayerParameters->getSliceArgument();
if( m_uiSliceMode == 2 )
{
m_uiSliceArgument = m_uiSliceArgument*8;
}
else if( m_uiSliceMode == 0 || m_uiSliceMode > 2 )
{
m_uiSliceMode = 0;
m_uiSliceArgument = MSYS_UINT_MAX;
}
//JVT-X046 }
return Err::m_nOK;
}
ErrVal
LayerEncoder::xInitCodingOrder( UInt uiDecompositionStages, UInt uiTemporalSubSampling, UInt uiMaxFrameDelay )
{
ROF( uiDecompositionStages + uiTemporalSubSampling <= MAX_DSTAGES );
uiDecompositionStages += uiTemporalSubSampling;
const UInt uiMaxSize = ( 1U << MAX_DSTAGES ) + 1U;
UInt uiMaxGOPSize = ( 1U << uiDecompositionStages );
UInt auiTemporalId [ uiMaxSize ];
UInt auiRequiredFId [ uiMaxSize ];
Bool abIndexAssigned[ uiMaxSize ];
//===== restrict input delay and determine period parameters =====
uiMaxFrameDelay = min( uiMaxFrameDelay, uiMaxGOPSize - 1 );
UInt uiPeriod = 0;
for( uiPeriod = 1; uiMaxFrameDelay >= uiPeriod; uiPeriod <<= 1 );
UInt uiP0Size = uiPeriod - ( uiMaxFrameDelay + 1 );
//===== init arrays =====
for( UInt uiIdx = 0; uiIdx < uiMaxSize; uiIdx++ )
{
m_auiFrameIdToTemporalId[uiIdx] = 0;
auiTemporalId [uiIdx] = 0;
auiRequiredFId [uiIdx] = 0;
abIndexAssigned [uiIdx] = false;
}
//===== set temporal level (for the inside of a virtual GOP) =====
for( UInt uiTemporalId = 1; uiTemporalId <= uiDecompositionStages; uiTemporalId++ )
{
UInt uiOffset = ( 1U << ( uiDecompositionStages - uiTemporalId ) );
for( UInt uiFrameIdInGOP = uiOffset; uiFrameIdInGOP <= uiMaxGOPSize; uiFrameIdInGOP += ( uiOffset << 1 ) )
{
auiTemporalId[ uiFrameIdInGOP ] = uiTemporalId;
}
}
//===== initialize the array required =====
for( UInt uiFrameId = 1; uiFrameId < uiMaxGOPSize; uiFrameId++ )
{
Bool bSet = false;
for( UInt uiNextId = uiFrameId + 1; !bSet; uiNextId++ )
{
if( auiTemporalId[uiNextId] < auiTemporalId[uiFrameId] )
{
auiRequiredFId[uiFrameId] = uiNextId;
bSet = true;
}
}
}
//===== update the array required taking into account the delay =====
for( UInt uiPeriodOffset = 1; uiPeriodOffset <= uiMaxGOPSize; uiPeriodOffset += uiPeriod )
{
for( UInt uiCnt = 0; uiCnt < 2; uiCnt++ )
{
UInt uiMinFrameIdInGOP = uiPeriodOffset + ( uiCnt ? uiP0Size : 0 );
UInt uiMaxFrameIdInGOP = uiPeriodOffset + ( uiCnt ? uiPeriod : uiP0Size );
for( UInt uiFrameId = uiMinFrameIdInGOP; uiFrameId < uiMaxFrameIdInGOP; uiFrameId++ )
{
if( auiRequiredFId[uiFrameId] >= uiMaxFrameIdInGOP )
{
auiRequiredFId[uiFrameId] = 0;
}
}
}
}
//===== determine coding order =====
UInt uiCodingNumber = 0;
for( UInt uiFrameIdInGOP = 0; uiFrameIdInGOP <= uiMaxGOPSize; uiFrameIdInGOP++ )
{
if( ! abIndexAssigned[ uiFrameIdInGOP ] )
{
// get list of required pictures
UInt auiRequiredList[MAX_DSTAGES];
UInt uiRequiredListSize = 0;
for( UInt uiNextRequired = auiRequiredFId[uiFrameIdInGOP]; uiNextRequired && !abIndexAssigned[uiNextRequired]; uiNextRequired = auiRequiredFId[uiNextRequired] )
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?