📄 gopencoder.cpp
字号:
MCTFEncoder::init( CodingParameter* pcCodingParameter,
LayerParameters* pcLayerParameters,
H264AVCEncoder* pcH264AVCEncoder,
SliceEncoder* pcSliceEncoder,
RQFGSEncoder* pcRQFGSEncoder,
LoopFilter* pcLoopFilter,
PocCalculator* pcPocCalculator,
NalUnitEncoder* pcNalUnitEncoder,
YuvBufferCtrl* pcYuvFullPelBufferCtrl,
YuvBufferCtrl* pcYuvHalfPelBufferCtrl,
QuarterPelFilter* pcQuarterPelFilter,
MotionEstimation* pcMotionEstimation
//JVT-U106 Behaviour at slice boundaries{
,ReconstructionBypass* pcReconstructionBypass
//JVT-U106 Behaviour at slice boundaries}
)
{
ROF( pcCodingParameter );
ROF( pcLayerParameters );
ROF( pcH264AVCEncoder );
ROF( pcSliceEncoder );
ROF( pcRQFGSEncoder );
ROF( pcLoopFilter );
ROF( pcPocCalculator );
ROF( pcNalUnitEncoder );
ROF( pcYuvFullPelBufferCtrl );
ROF( pcYuvHalfPelBufferCtrl );
ROF( pcQuarterPelFilter );
ROF( pcMotionEstimation );
//JVT-U106 Behaviour at slice boundaries{
ROF( pcReconstructionBypass );
//JVT-U106 Behaviour at slice boundaries}
//----- references -----
m_pcSPS = 0;
m_pcPPSLP = 0;
m_pcPPSHP = 0;
m_pcSPS_FGS = 0;
m_pcPPSLP_FGS = 0;
m_pcPPSHP_FGS = 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;
m_pcRQFGSEncoder = pcRQFGSEncoder;
//JVT-U106 Behaviour at slice boundaries{
m_pcReconstructionBypass = pcReconstructionBypass;
//JVT-U106 Behaviour at slice boundaries}
//----- fixed control parameters -----
m_dLowPassEnhRef = pcLayerParameters->getLowPassEnhRef();
m_uiLowPassFgsMcFilter = pcCodingParameter->getLowPassFgsMcFilter();
pcLayerParameters->getAdaptiveRefFGSWeights(
m_uiBaseWeightZeroBaseBlock, m_uiBaseWeightZeroBaseCoeff);
m_uiFgsEncStructureFlag = pcLayerParameters->getFgsEncStructureFlag();
m_uiLayerId = pcLayerParameters->getLayerId ();
m_uiBaseLayerId = pcLayerParameters->getBaseLayerId ();
m_uiBaseQualityLevel = pcLayerParameters->getBaseQualityLevel ();
// JVT-Q065 EIDR{
m_iIDRPeriod = pcLayerParameters->getIDRPeriod ();
m_bBLSkipEnable = pcLayerParameters->getBLSkipEnable ();
// JVT-Q065 EIDR}
// JVT-U085 LMI
m_bTlevelNestingFlag = pcCodingParameter->getTlevelNestingFlag();
// JVT-U116 LMI
m_bTl0PicIdxPresentFlag = pcCodingParameter->getTl0PicIdxPresentFlag();
m_bExtendedPriorityId = pcCodingParameter->getExtendedPriorityId();
m_uiQualityLevelForPrediction = 3;
if( pcCodingParameter->getNumberOfLayers() > pcLayerParameters->getLayerId() + 1 )
{
m_uiQualityLevelForPrediction = (pcLayerParameters + 1)->getBaseQualityLevel();
if( m_uiQualityLevelForPrediction > 3)
m_uiQualityLevelForPrediction = 3;
}
m_uiDecompositionStages = pcLayerParameters->getDecompositionStages ();
m_uiTemporalResolution = pcLayerParameters->getTemporalResolution ();
m_uiNotCodedMCTFStages = pcLayerParameters->getNotCodedMCTFStages ();
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_uiClosedLoopMode = pcLayerParameters->getClosedLoop ();
// m_bH264AVCCompatible = pcCodingParameter->getBaseLayerMode () > 0 && m_uiLayerId == 0;
m_bH264AVCCompatible = m_uiLayerId == 0; //bug-fix suffix
m_bInterLayerPrediction = pcLayerParameters->getInterLayerPredictionMode() > 0;
m_bAdaptivePrediction = pcLayerParameters->getInterLayerPredictionMode() > 1;
m_bHaarFiltering = false;
m_bBiPredOnly = false;
m_bForceReOrderingCommands= pcLayerParameters->getForceReorderingCommands () > 0;
m_bWriteSubSequenceSei = pcCodingParameter->getBaseLayerMode () > 1 && m_uiLayerId == 0;
m_bUseSmoothedRef = (pcLayerParameters->getUseSmoothedRef()!=0 ? true: false); //JVT-V058
m_bSameResBL = ( m_uiBaseLayerId != MSYS_UINT_MAX &&
pcCodingParameter->getLayerParameters( m_uiBaseLayerId ).getFrameWidth () == pcLayerParameters->getFrameWidth () &&
pcCodingParameter->getLayerParameters( m_uiBaseLayerId ).getFrameHeight() == pcLayerParameters->getFrameHeight() &&
pcLayerParameters->getResizeParameters()->m_iExtendedSpatialScalability == ESS_NONE );
m_bSameResEL = false;
{
UInt uiLId;
for( uiLId = m_uiLayerId + 1; uiLId < pcCodingParameter->getNumberOfLayers() && ! m_bSameResEL; uiLId++ )
{
LayerParameters& rcEL = pcCodingParameter->getLayerParameters( uiLId );
if( rcEL.getBaseLayerId() == m_uiLayerId )
{
m_bSameResEL = ( pcLayerParameters->getFrameWidth () == rcEL.getFrameWidth () &&
pcLayerParameters->getFrameHeight() == rcEL.getFrameHeight() &&
rcEL.getResizeParameters()->m_iExtendedSpatialScalability == ESS_NONE );
}
}
}
m_bMGS = pcCodingParameter->getCGSSNRRefinement () == 1 && ( m_bSameResBL || m_bSameResEL );
m_uiEncodeKeyPictures = pcCodingParameter->getEncodeKeyPictures ();
m_uiMGSKeyPictureControl = pcCodingParameter->getMGSKeyPictureControl();
m_bHighestMGSLayer = m_bMGS && !m_bSameResEL;
m_uiMGSKeyPictureMotRef = pcCodingParameter->getMGSKeyPictureMotRef();
m_bExplicitQPCascading = pcLayerParameters->getExplicitQPCascading() != 0;
for( UInt uiTTL = 0; uiTTL < MAX_TEMP_LEVELS; uiTTL++ )
{
m_adDeltaQPTLevel[uiTTL] = pcLayerParameters->getDeltaQPTLevel( uiTTL );
}
//JVT-R057 LA-RDO{
if(pcCodingParameter->getLARDOEnable()!=0)
{
static UInt auiPLR[5];
static UInt aauiSize[5][2];
static Double dRatio[5][2];
auiPLR[m_uiLayerId] = pcLayerParameters->getPLR ();
m_bLARDOEnable = pcCodingParameter->getLARDOEnable()==0? false:true;
m_bLARDOEnable = m_bLARDOEnable&&((Int)pcLayerParameters->getNumFGSLayers()==0);
aauiSize[m_uiLayerId][0] =pcLayerParameters->getFrameWidth();
aauiSize[m_uiLayerId][1] =pcLayerParameters->getFrameHeight();
if(m_uiLayerId==0||pcLayerParameters->getBaseLayerId()==MSYS_UINT_MAX)
{
dRatio[m_uiLayerId][0]=1;
dRatio[m_uiLayerId][1]=1;
}
else
{
dRatio[m_uiLayerId][0]=(Double)aauiSize[m_uiLayerId][0]/aauiSize[pcLayerParameters->getBaseLayerId()][0];
dRatio[m_uiLayerId][1]=(Double)aauiSize[m_uiLayerId][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();
for( UInt uiStage = 0; uiStage < MAX_DSTAGES; uiStage++ )
{
m_adBaseQpLambdaMotion[uiStage] = pcLayerParameters->getQpModeDecision( uiStage );
}
m_dBaseQpLambdaMotionLP = pcLayerParameters->getQpModeDecisionLP ();
m_dBaseQPResidual = pcLayerParameters->getBaseQpResidual ();
m_dNumFGSLayers = pcLayerParameters->getNumFGSLayers ();
m_uiFilterIdc = pcCodingParameter->getLoopFilterParams ().getFilterIdc ();
m_iAlphaOffset = pcCodingParameter->getLoopFilterParams ().getAlphaOffset ();
m_iBetaOffset = pcCodingParameter->getLoopFilterParams ().getBetaOffset ();
m_bLoadMotionInfo = pcLayerParameters->getMotionInfoMode () == 1;
m_bSaveMotionInfo = pcLayerParameters->getMotionInfoMode () == 2;
m_pMotionInfoFile = 0;
m_uiFGSMotionMode = pcLayerParameters->getFGSMotionMode();
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;
}
for( ui = 0; ui < MAX_SCALABLE_LAYERS; ui++ )
{
m_auiCurrGOPBits [ui] = 0;
m_adSeqBits [ui] = 0.0;
}
m_uiNewlyCodedBits = 0;
//----- FGS -----
m_uiFGSMode = pcLayerParameters->getFGSMode();
m_pFGSFile = 0;
//FIX_FRAG_CAVLC
m_bUseDiscardableUnit = pcLayerParameters->getUseDiscardable();
if(m_bUseDiscardableUnit)
{
m_pFGSFile = ::fopen( pcLayerParameters->getFGSFilename().c_str(), "rt" );
if (!m_pFGSFile)
fprintf( stderr, "Error: FGS failed '%s' couldn't be Opened\n",pcLayerParameters->getFGSFilename().c_str());
ROF( m_pFGSFile );
}
else
{
//~FIX_FRAG_CAVLC
if( m_uiFGSMode == 1 )
{
m_pFGSFile = ::fopen( pcLayerParameters->getFGSFilename().c_str(), "wt" );
if (!m_pFGSFile)
fprintf( stderr, "Error: FGS failed '%s' couldn't be created\n",pcLayerParameters->getFGSFilename().c_str());
ROF( m_pFGSFile );
}
if( m_uiFGSMode == 2 )
{
m_pFGSFile = ::fopen( pcLayerParameters->getFGSFilename().c_str(), "rt" );
if (!m_pFGSFile)
fprintf( stderr, "Error: FGS failed '%s' couldn't be Opened\n",pcLayerParameters->getFGSFilename().c_str());
ROF( m_pFGSFile );
}
} //FIX_FRAG_CAVLC
m_dFGSBitRateFactor = 0.0;
m_dFGSRoundingOffset = 0.0;
m_iLastFGSError = 0;
m_uiNotYetConsideredBaseLayerBits = 0;
// analyse and set parameters
//JVT-P031
m_bUseDiscardableUnit = pcLayerParameters->getUseDiscardable();
m_dPredFGSCutFactor = 0.0;
m_dPredFGSRoundingOffset = 0.0;
m_iPredLastFGSError = 0;
if(m_bUseDiscardableUnit || m_uiFGSMode == 2)
//JVT-P031
{
Char acLine [1000];
UInt uiNumFrames = 0;
UInt uiBaseBits = 0;
UInt uiSumBaseBits = 0;
UInt uiSumFGSBits [MAX_FGS_LAYERS] = { 0, 0, 0 };
UInt uiFGSBits [MAX_FGS_LAYERS] = { 0, 0, 0 };
UInt uiDummy;
for( ; ; )
{
Int i, c;
for( i = 0; ( c = fgetc(m_pFGSFile), ( c != '\n' && c != EOF ) ); acLine[i++] = c );
acLine[i] = '\0';
if( feof(m_pFGSFile) )
{
break;
}
sscanf( acLine, "%d %d %d %d %d %d %d ",
&uiBaseBits, &uiDummy, &uiFGSBits[0], &uiDummy, &uiFGSBits[1], &uiDummy, &uiFGSBits[2] );
uiNumFrames ++;
uiSumBaseBits += uiBaseBits;
uiSumFGSBits[0] += uiFGSBits[0];
uiSumFGSBits[1] += uiFGSBits[1];
uiSumFGSBits[2] += uiFGSBits[2];
}
ROF( uiNumFrames );
//FIX_FRAG_CAVLC
if(m_uiFGSMode == 2)
{
//~FIX_FRAG_CAVLC
Double dTargetBits = 1000.0 * pcLayerParameters->getFGSRate() * (Double)uiNumFrames / pcLayerParameters->getOutputFrameRate();
UInt uiTargetBits = (UInt)floor( dTargetBits + 0.5 );
UInt uiSumAllBits = uiSumBaseBits + uiSumFGSBits[0] + uiSumFGSBits[1] + uiSumFGSBits[2];
if( uiTargetBits <= uiSumBaseBits )
{
ROF( uiTargetBits );
printf("Warning: Layer %d bitrate overflow (only base layer coded)\n", m_uiLayerId );
m_dFGSCutFactor = 0.0;
m_dFGSBitRateFactor = (Double)uiTargetBits / (Double)uiSumBaseBits; // there is a chance that only coding the base layer is not the right thing for closed-loop
m_dNumFGSLayers = 0.0;
}
else if( uiTargetBits >= uiSumAllBits )
{
printf("Warning: Layer %d bitrate underflow (code as much as possible)\n", m_uiLayerId );
m_dFGSCutFactor = 3.0;
m_dFGSBitRateFactor = (Double)uiTargetBits / (Double)uiSumAllBits; // it is possible that not all layers have been coded during the analysis run (e.g. for closed-loop)
m_dNumFGSLayers = 3.0;
for( UInt uiFGSLayer = 0; uiFGSLayer < MAX_FGS_LAYERS; uiFGSLayer++ )
{
if (uiSumFGSBits[uiFGSLayer] == 0)
{
m_dNumFGSLayers = (Double)uiFGSLayer;
break;
}
}
}
else
{
uiTargetBits -= uiSumBaseBits;
for( UInt uiFGSLayer = 0; uiFGSLayer < MAX_FGS_LAYERS; uiFGSLayer++ )
{
if( uiTargetBits < uiSumFGSBits[uiFGSLayer] )
{
m_dFGSCutFactor = (Double)uiFGSLayer + (Double)uiTargetBits / (Double)uiSumFGSBits[uiFGSLayer];
m_dNumFGSLayers = uiFGSLayer + 1;
break;
}
uiTargetBits -= uiSumFGSBits[uiFGSLayer];
}
m_dFGSBitRateFactor = 0.0;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -