gopencoder.cpp
来自「JVT-S203 contains the JSVM 6 reference s」· C++ 代码 · 共 1,842 行 · 第 1/5 页
CPP
1,842 行
sum += (1<<m_uiSelect[j][i]);
}
if (temp > 6)
break;
}
if (m_uiSelect[0][0] == 0)
{
printf("\"gop mode\" file is empty\n");
exit(0);
}
fclose(d_gop);
}
}
//}}Adaptive GOP structure
// JVT-S054 (ADD) ->
m_bIroiSliceDivisionFlag = pcLayerParameters->m_bSliceDivisionFlag;
if (m_bIroiSliceDivisionFlag)
{
m_uiNumSliceMinus1 = pcLayerParameters->m_uiNumSliceMinus1;
if (m_puiFirstMbInSlice != NULL)
free(m_puiFirstMbInSlice);
m_puiFirstMbInSlice = (UInt*)malloc((m_uiNumSliceMinus1+1)*sizeof(UInt));
memcpy( m_puiFirstMbInSlice, pcLayerParameters->m_puiFirstMbInSlice, (m_uiNumSliceMinus1+1)*sizeof(UInt) );
if (m_puiLastMbInSlice != NULL)
free(m_puiLastMbInSlice);
m_puiLastMbInSlice = (UInt*)malloc((m_uiNumSliceMinus1+1)*sizeof(UInt));
memcpy( m_puiLastMbInSlice, pcLayerParameters->m_puiLastMbInSlice, (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_uiLayerId+1)
{
m_bEncSIP = pcCodingParameter->getLayerParameters( m_uiLayerId+1).getEncSIP();
m_cInSIPFileName = pcCodingParameter->getLayerParameters( m_uiLayerId+1).getInSIPFileName();
}
//S051}
return Err::m_nOK;
}
__inline UInt downround2powerof2( UInt i ) { UInt r = 1; for( ; (UInt)( 1 << r ) <= i; r++ ); return ( 1 << ( r - 1 ) ); }
ErrVal
MCTFEncoder::initParameterSetsForFGS( const SequenceParameterSet& rcSPS,
const PictureParameterSet& rcPPSLP,
const PictureParameterSet& rcPPSHP )
{
m_pcSPS_FGS = &rcSPS;
m_pcPPSLP_FGS = &rcPPSLP;
m_pcPPSHP_FGS = &rcPPSHP;
return Err::m_nOK;
}
ErrVal
MCTFEncoder::initParameterSets( const SequenceParameterSet& rcSPS,
const PictureParameterSet& rcPPSLP,
const PictureParameterSet& rcPPSHP )
{
//===== set references =====
m_pcSPS = &rcSPS;
m_pcPPSLP = &rcPPSLP;
m_pcPPSHP = &rcPPSHP;
m_pcSPS_FGS = &rcSPS;
m_pcPPSLP_FGS = &rcPPSLP;
m_pcPPSHP_FGS = &rcPPSHP;
//===== get and set relevant parameters =====
UInt uiMaxDPBSize = rcSPS.getMaxDPBSize ();
m_uiFrameWidthInMb = rcSPS.getFrameWidthInMbs ();
m_uiFrameHeightInMb = rcSPS.getFrameHeightInMbs ();
m_uiMbNumber = m_uiFrameWidthInMb * m_uiFrameHeightInMb;
m_uiMaxGOPSize = downround2powerof2( uiMaxDPBSize );
//===== re-allocate dynamic memory =====
RNOK( xDeleteData() );
RNOK( xCreateData( rcSPS ) );
//===== initialize some parameters =====
m_bInitDone = true;
m_bFirstGOPCoded = false;
m_uiFrameCounter = 0;
m_uiFrameNum = 0;
m_uiGOPNumber = 0;
::memset( m_abIsRef, 0x00, sizeof( m_abIsRef ) );
return Err::m_nOK;
}
ErrVal
MCTFEncoder::addParameterSetBits( UInt uiParameterSetBits )
{
m_uiParameterSetBits += uiParameterSetBits;
return Err::m_nOK;
}
ErrVal
MCTFEncoder::xCreateData( const SequenceParameterSet& rcSPS )
{
UInt uiIndex;
//========== CREATE FRAME MEMORIES ==========
ROFS ( ( m_papcFrame = new IntFrame* [ m_uiMaxGOPSize + 1 ] ) );
ROFS ( ( m_papcOrgFrame = new IntFrame* [ m_uiMaxGOPSize + 1 ] ) );
if( m_uiClosedLoopMode == 2 )
{
ROFS ( ( m_papcBQFrame = new IntFrame* [ m_uiMaxGOPSize + 1 ] ) );
}
if( m_uiQualityLevelForPrediction < 3 || m_bUseDiscardableUnit) //JVT-P031
{
ROFS ( ( m_papcCLRecFrame = new IntFrame* [ m_uiMaxGOPSize + 1 ] ) );
}
ROFS ( ( m_papcResidual = new IntFrame* [ m_uiMaxGOPSize + 1 ] ) );
ROFS ( ( m_papcSubband = new IntFrame* [ m_uiMaxGOPSize + 1 ] ) );
//-- JVT-R091
ROFS ( ( m_papcSmoothedFrame = new IntFrame* [ m_uiMaxGOPSize + 1 ] ) );
//--
for( uiIndex = 0; uiIndex <= m_uiMaxGOPSize; uiIndex++ )
{
ROFS ( ( m_papcFrame [ uiIndex ] = new IntFrame( *m_pcYuvFullPelBufferCtrl,
*m_pcYuvHalfPelBufferCtrl ) ) );
ROFS ( ( m_papcOrgFrame [ uiIndex ] = new IntFrame( *m_pcYuvFullPelBufferCtrl,
*m_pcYuvFullPelBufferCtrl ) ) );
if( m_papcBQFrame )
{
ROFS(( m_papcBQFrame [ uiIndex ] = new IntFrame( *m_pcYuvFullPelBufferCtrl,
*m_pcYuvFullPelBufferCtrl ) ) );
}
if( m_papcCLRecFrame )
{
ROFS(( m_papcCLRecFrame [ uiIndex ] = new IntFrame( *m_pcYuvFullPelBufferCtrl,
*m_pcYuvHalfPelBufferCtrl ) ) );
}
//-- JVT-R091
if ( m_papcSmoothedFrame )
{
ROFS(( m_papcSmoothedFrame [ uiIndex ] = new IntFrame( *m_pcYuvFullPelBufferCtrl,
*m_pcYuvHalfPelBufferCtrl ) ) );
}
//--
ROFS ( ( m_papcResidual [ uiIndex ] = new IntFrame( *m_pcYuvFullPelBufferCtrl,
*m_pcYuvHalfPelBufferCtrl ) ) );
ROFS ( ( m_papcSubband [ uiIndex ] = new IntFrame( *m_pcYuvFullPelBufferCtrl,
*m_pcYuvHalfPelBufferCtrl ) ) );
RNOK ( m_papcFrame [ uiIndex ] ->init () );
RNOK ( m_papcOrgFrame [ uiIndex ] ->init () );
if( m_papcBQFrame )
{
RNOK( m_papcBQFrame [ uiIndex ] ->init () );
}
if( m_papcCLRecFrame )
{
RNOK( m_papcCLRecFrame [ uiIndex ] ->init () );
}
//-- JVT-R091
if ( m_papcSmoothedFrame )
{
RNOK( m_papcSmoothedFrame [ uiIndex ] ->init () );
}
//--
RNOK ( m_papcResidual [ uiIndex ] ->init () );
RNOK ( m_papcSubband [ uiIndex ] ->init () );
}
for( uiIndex = 0; uiIndex < NUM_TMP_FRAMES; uiIndex++ )
{
ROFS ( ( m_apcFrameTemp [ uiIndex ] = new IntFrame( *m_pcYuvFullPelBufferCtrl,
*m_pcYuvHalfPelBufferCtrl ) ) );
RNOK ( m_apcFrameTemp [ uiIndex ] ->init () );
}
for( uiIndex = 0; uiIndex < 2; uiIndex++ )
{
for( UInt uiLayerIdx = 0; uiLayerIdx < 4; uiLayerIdx ++ )
{
ROFS ( ( m_aapcFGSRecon[uiIndex][uiLayerIdx] = new IntFrame( *m_pcYuvFullPelBufferCtrl,
*m_pcYuvHalfPelBufferCtrl ) ) );
RNOK ( m_aapcFGSRecon[uiIndex][uiLayerIdx] ->init () );
}
}
ROFS ( ( m_aapcFGSPredFrame = new IntFrame( *m_pcYuvFullPelBufferCtrl,
*m_pcYuvHalfPelBufferCtrl ) ) );
RNOK ( m_aapcFGSPredFrame ->init () );
ROFS ( ( m_pcLowPassBaseReconstruction = new IntFrame( *m_pcYuvFullPelBufferCtrl,
*m_pcYuvHalfPelBufferCtrl ) ) );
RNOK ( m_pcLowPassBaseReconstruction ->init () );
ROFS ( ( m_pcAnchorFrameOriginal = new IntFrame( *m_pcYuvFullPelBufferCtrl,
*m_pcYuvHalfPelBufferCtrl ) ) );
RNOK ( m_pcAnchorFrameOriginal ->init () );
ROFS ( ( m_pcAnchorFrameReconstructed = new IntFrame( *m_pcYuvFullPelBufferCtrl,
*m_pcYuvHalfPelBufferCtrl ) ) );
RNOK ( m_pcAnchorFrameReconstructed ->init () );
ROFS ( ( m_pcBaseLayerFrame = new IntFrame( *m_pcYuvFullPelBufferCtrl,
*m_pcYuvHalfPelBufferCtrl ) ) );
RNOK ( m_pcBaseLayerFrame ->init () );
ROFS ( ( m_pcBaseLayerResidual = new IntFrame( *m_pcYuvFullPelBufferCtrl,
*m_pcYuvHalfPelBufferCtrl ) ) );
RNOK ( m_pcBaseLayerResidual ->init () );
//========== CREATE MACROBLOCK DATA MEMORIES ==========
ROFS ( ( m_pacControlData = new ControlData[ m_uiMaxGOPSize + 1 ] ) );
for( uiIndex = 0; uiIndex <= m_uiMaxGOPSize; uiIndex++ )
{
MbDataCtrl* pcMbDataCtrl = 0;
ROFS ( ( pcMbDataCtrl = new MbDataCtrl () ) );
RNOK ( pcMbDataCtrl ->init ( rcSPS ) );
RNOK ( m_pacControlData[ uiIndex ] . setMbDataCtrl ( pcMbDataCtrl ) );
RNOK ( m_pacControlData[ uiIndex ] .initFGSData ( m_uiFrameWidthInMb * m_uiFrameHeightInMb ) );
Bool bLowPass = ( ( uiIndex % ( 1 << m_uiDecompositionStages ) ) == 0 );
SliceHeader* pcSliceHeader = 0;
ROFS ( ( pcSliceHeader = new SliceHeader ( *m_pcSPS, bLowPass ? *m_pcPPSLP : *m_pcPPSHP ) ) );
RNOK ( m_pacControlData[ uiIndex ] . setSliceHeader ( pcSliceHeader ) );
if( m_uiClosedLoopMode == 2 )
{
RNOK( m_pacControlData[ uiIndex ] .initBQData ( m_uiFrameWidthInMb * m_uiFrameHeightInMb ) );
}
m_pacControlData[ uiIndex ].getMbDataCtrl()->initFgsBQData(m_uiFrameWidthInMb * m_uiFrameHeightInMb);
}
ROFS ( ( m_pcBaseLayerCtrl = new MbDataCtrl() ) );
RNOK ( m_pcBaseLayerCtrl ->init ( rcSPS ) );
//========== CREATE UPDATE WEIGHTS ARRAY and WRITE BUFFER ==========
UInt uiNum4x4Blocks = m_uiFrameWidthInMb * m_uiFrameHeightInMb * 4 * 4;
m_uiWriteBufferSize = 3 * ( uiNum4x4Blocks * 4 * 4 );
ROFS( ( m_pucWriteBuffer = new UChar [ m_uiWriteBufferSize ] ) );
ROT ( m_cDownConvert .init ( m_uiFrameWidthInMb<<4, m_uiFrameHeightInMb<<4 ) );
RNOK( m_pcRQFGSEncoder ->initSPS( rcSPS ) );
//S051{
ROFRS( m_auiFrameBits = new UInt[m_uiTotalFrame], Err::m_nERR );
memset( m_auiFrameBits,0,sizeof(UInt)*m_uiTotalFrame);
if(m_bEncSIP)
{
FILE* file=fopen(m_cInSIPFileName.c_str(),"rt");
if(file==NULL)
{
printf("\nCan't open SIP file %s",m_cInSIPFileName.c_str());
return Err::m_nOK;
}
while(!feof(file))
{
UInt tmp;
fscanf(file,"%d",&tmp);
m_cPOCList.push_back(tmp);
}
fclose(file);
}
//S051}
return Err::m_nOK;
}
ErrVal
MCTFEncoder::xDeleteData()
{
UInt uiIndex;
//========== DELETE FRAME MEMORIES ==========
if( m_papcFrame )
{
for( uiIndex = 0; uiIndex <= m_uiMaxGOPSize; uiIndex++ )
{
if( m_papcFrame[ uiIndex ] )
{
//JVT-R057 LA-RDO{
if(m_bLARDOEnable)
m_papcFrame[uiIndex]->uninitChannelDistortion();
//JVT-R057 LA-RDO}
RNOK( m_papcFrame[ uiIndex ]->uninit() );
delete m_papcFrame[ uiIndex ];
m_papcFrame[ uiIndex ] = 0;
}
}
delete [] m_papcFrame;
m_papcFrame = 0;
}
if( m_papcOrgFrame )
{
for( uiIndex = 0; uiIndex <= m_uiMaxGOPSize; uiIndex++ )
{
if( m_papcOrgFrame[ uiIndex ] )
{
RNOK( m_papcOrgFrame[ uiIndex ]->uninit() );
delete m_papcOrgFrame[ uiIndex ];
m_papcOrgFrame[ uiIndex ] = 0;
}
}
delete [] m_papcOrgFrame;
m_papcOrgFrame = 0;
}
if( m_papcBQFrame )
{
for( uiIndex = 0; uiIndex <= m_uiMaxGOPSize; uiIndex++ )
{
if( m_papcBQFrame[ uiIndex ] )
{
RNOK( m_papcBQFrame[ uiIndex ]->uninit() );
delete m_papcBQFrame[ uiIndex ];
m_papcBQFrame[ uiIndex ] = 0;
}
}
delete [] m_papcBQFrame;
m_papcBQFrame = 0;
}
if( m_papcCLRecFrame )
{
for( uiIndex = 0; uiIndex <= m_uiMaxGOPSize; uiIndex++ )
{
if( m_papcCLRecFrame[ uiIndex ] )
{
RNOK( m_papcCLRecFrame[ uiIndex ]->uninit() );
delete m_papcCLRecFrame[ uiIndex ];
m_papcCLRecFrame[ uiIndex ] = 0;
}
}
delete [] m_papcCLRecFrame;
m_papcCLRecFrame = 0;
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?