📄 vui.cpp
字号:
m_cBitstreamRestriction ( pcSPS ),
m_uiDefaultIdx ( MSYS_UINT_MAX )
{
m_eProfileIdc = pcSPS->getProfileIdc();
}
VUI::~VUI()
{
}
ErrVal VUI::InitHrd( UInt uiIndex, HRD::HrdParamType eHrdType, UInt uiBitRate, UInt uiCpbSize)
{
HRD& rcHrd = (eHrdType == HRD::NAL_HRD) ? m_acNalHrd[uiIndex] : m_acVclHrd[uiIndex];
if( rcHrd.getHrdParametersPresentFlag())
{
// we provide only one set of parameters. the following code is pretty hard coded
rcHrd.setCpbCnt(1);
UInt uiExponentBR = max(6, gGetNumberOfLSBZeros(uiBitRate));
UInt uiExponentCpb = max(4, gGetNumberOfLSBZeros(uiCpbSize));
rcHrd.setBitRateScale(uiExponentBR-6);
rcHrd.setCpbSizeScale(uiExponentCpb-4);
rcHrd.init(1);
for( UInt CpbCnt=0; CpbCnt<1; CpbCnt++)
{
Int iBitNumLSBZeros = gGetNumberOfLSBZeros(uiBitRate);
Int iCpbNumLSBZeros = gGetNumberOfLSBZeros(uiCpbSize);
// we're doing a bit complicated rounding here to find the nearest value
// probably we should use the exact or bigger bit rate value:
//for values with 6 or more LSBZeros:
if( iBitNumLSBZeros >= 5)
{
rcHrd.getCntBuf(CpbCnt).setBitRateValue((UInt)floor ( ((Double)(uiBitRate) / (1 << uiExponentBR))));
}
else//for values with less than 6 LSBZeros
{
rcHrd.getCntBuf(CpbCnt).setBitRateValue((UInt)floor ( ((Double)(uiBitRate) / (1 << uiExponentBR)) + 0.5));
}
//for values with 4 or more LSBZeros:
if( iCpbNumLSBZeros >= 3)
{
rcHrd.getCntBuf(CpbCnt).setCpbSizeValue((UInt)floor ( ((Double)(uiCpbSize) / (1<< uiExponentCpb)) ));
}
else//for values with less than 4 LSBZeros
{
rcHrd.getCntBuf(CpbCnt).setCpbSizeValue((UInt)floor ( ((Double)(uiCpbSize) / (1<< uiExponentCpb)) + 0.5));
}
//0 VBR 1 CBR
rcHrd.getCntBuf(CpbCnt).setVbrCbrFlag(0);// 1: stuffing needed
}
rcHrd.setInitialCpbRemovalDelayLength(24);
rcHrd.setCpbRemovalDelayLength(24);
rcHrd.setDpbOutputDelayLength(24);
rcHrd.setTimeOffsetLength(0);
}
return Err::m_nOK;
}
ErrVal VUI::init( UInt uiNumTemporalLevels, UInt uiNumFGSLevels )
{
m_uiNumTemporalLevels = uiNumTemporalLevels;
m_uiNumFGSLevels = uiNumFGSLevels;
UInt uiNumLayers = uiNumTemporalLevels * uiNumFGSLevels;
RNOK( m_acLayerInfo.init( uiNumLayers ) );
RNOK( m_acTimingInfo.init( uiNumLayers ) );
RNOK( m_acNalHrd.init( uiNumLayers ) );
RNOK( m_acVclHrd.init( uiNumLayers ) );
RNOK( m_abLowDelayHrdFlag.init( uiNumLayers ) );
RNOK( m_abPicStructPresentFlag.init( uiNumLayers ) );
return Err::m_nOK;
}
ErrVal VUI::LayerInfo::write( HeaderSymbolWriteIf* pcWriteIf ) const
{
RNOK( pcWriteIf->writeCode( m_uiTemporalId, 3, "HRD::temporal_level[i]"));
RNOK( pcWriteIf->writeCode( m_uiDependencyID, 3, "HRD::dependency_id[i]"));
RNOK( pcWriteIf->writeCode( m_uiQualityId, 4, "HRD::quality_level[i]"));
return Err::m_nOK;
}
ErrVal VUI::write( HeaderSymbolWriteIf* pcWriteIf ) const
{
RNOK( pcWriteIf->writeFlag( m_bVuiParametersPresentFlag, "SPS: vui_parameters_present_flag" ) );
if (!m_bVuiParametersPresentFlag) return Err::m_nOK;
RNOK( m_cAspectRatioInfo.write( pcWriteIf ) );
RNOK( pcWriteIf->writeFlag( getOverscanInfoPresentFlag(), "VUI: overscan_info_present_flag"));
if( getOverscanInfoPresentFlag() )
{
RNOK( pcWriteIf->writeFlag( getOverscanAppropriateFlag(), "VUI: overscan_appropriate_flag"));
}
RNOK( m_cVideoSignalType.write( pcWriteIf ) );
RNOK( m_cChromaLocationInfo.write( pcWriteIf ) );
ROT( m_uiDefaultIdx == MSYS_UINT_MAX );
RNOK( m_acTimingInfo.get(m_uiDefaultIdx).write( pcWriteIf ) );
RNOK( m_acNalHrd.get(m_uiDefaultIdx).write( pcWriteIf ) );
RNOK( m_acVclHrd.get(m_uiDefaultIdx).write( pcWriteIf ) );
if( m_acNalHrd.get(m_uiDefaultIdx).getHrdParametersPresentFlag() || m_acVclHrd.get(m_uiDefaultIdx).getHrdParametersPresentFlag() )
{
RNOK( pcWriteIf->writeFlag( m_abLowDelayHrdFlag.get(m_uiDefaultIdx), "VUI: low_delay_hrd_flag"));
}
RNOK( pcWriteIf->writeFlag( m_abPicStructPresentFlag.get(m_uiDefaultIdx), "VUI: pic_struct_present_flag"));
RNOK( m_cBitstreamRestriction.write( pcWriteIf ) );
return Err::m_nOK;
}
ErrVal VUI::writeSVCExtension( HeaderSymbolWriteIf* pcWriteIf ) const
{
ROF( getNumLayers() );
RNOK( pcWriteIf->writeUvlc( getNumLayers() - 1, "SPS: num_layers_nimus1" ) );
for( UInt uiLayer = 0; uiLayer < getNumLayers(); uiLayer++ )
{
RNOK( m_acLayerInfo.get(uiLayer).write( pcWriteIf ) );
RNOK( m_acTimingInfo.get(uiLayer).write( pcWriteIf ) );
RNOK( m_acNalHrd.get(uiLayer).write( pcWriteIf ) );
RNOK( m_acVclHrd.get(uiLayer).write( pcWriteIf ) );
if( m_acNalHrd.get(uiLayer).getHrdParametersPresentFlag() || m_acVclHrd.get(uiLayer).getHrdParametersPresentFlag() )
{
RNOK( pcWriteIf->writeFlag( m_abLowDelayHrdFlag.get(uiLayer), "VUI: low_delay_hrd_flag"));
}
RNOK( pcWriteIf->writeFlag( m_abPicStructPresentFlag.get(uiLayer), "VUI: pic_struct_present_flag"));
}
return Err::m_nOK;
}
ErrVal VUI::LayerInfo::read( HeaderSymbolReadIf* pcReadIf )
{
RNOKS( pcReadIf->getCode( m_uiTemporalId, 3, "VUI: temporal_level"));
RNOKS( pcReadIf->getCode( m_uiDependencyID, 3, "VUI: dependency_id"));
RNOKS( pcReadIf->getCode( m_uiQualityId, 4, "VUI: quality_level"));
return Err::m_nOK;
}
ErrVal VUI::read( HeaderSymbolReadIf *pcReadIf )
{
RNOKS( m_cAspectRatioInfo.read( pcReadIf ) );
RNOKS( pcReadIf->getFlag( m_bOverscanInfoPresentFlag, "VUI: overscan_info_present_flag"));
if( m_bOverscanInfoPresentFlag )
{
RNOKS( pcReadIf->getFlag( m_bOverscanAppropriateFlag, "VUI: overscan_appropriate_flag"));
}
RNOKS( m_cVideoSignalType.read( pcReadIf ) );
RNOKS( m_cChromaLocationInfo.read( pcReadIf ) );
m_acLayerInfo .uninit();
m_acTimingInfo .uninit();
m_acNalHrd .uninit();
m_acVclHrd .uninit();
m_abLowDelayHrdFlag .uninit();
m_abPicStructPresentFlag.uninit();
m_acLayerInfo .init( 1 );
m_acTimingInfo .init( 1 );
m_acNalHrd .init( 1 );
m_acVclHrd .init( 1 );
m_abLowDelayHrdFlag .init( 1 );
m_abPicStructPresentFlag.init( 1 );
// fill in the LayerInfo of AVC compatible layer
m_uiDefaultIdx = 0;
m_acLayerInfo[m_uiDefaultIdx].setDependencyID(0);
m_acLayerInfo[m_uiDefaultIdx].setQualityLevel(0);
m_acLayerInfo[m_uiDefaultIdx].setTemporalId(0);
RNOKS( m_acTimingInfo.get(m_uiDefaultIdx).read( pcReadIf ) );
RNOKS( m_acNalHrd.get(m_uiDefaultIdx).read( pcReadIf ) );
RNOKS( m_acVclHrd.get(m_uiDefaultIdx).read( pcReadIf ) );
if( m_acNalHrd.get(m_uiDefaultIdx).getHrdParametersPresentFlag() || m_acVclHrd.get(m_uiDefaultIdx).getHrdParametersPresentFlag() )
{
RNOKS( pcReadIf->getFlag( m_abLowDelayHrdFlag[m_uiDefaultIdx], "VUI: low_delay_hrd_flag"));
}
RNOKS( pcReadIf->getFlag( m_abPicStructPresentFlag[m_uiDefaultIdx], "VUI: pic_struct_present_flag"));
RNOKS( m_cBitstreamRestriction.read( pcReadIf ) );
return Err::m_nOK;
}
ErrVal VUI::readSVCExtension( HeaderSymbolReadIf *pcReadIf )
{
UInt uiNumLayers = 0;
RNOK( pcReadIf->getUvlc( uiNumLayers, "SPS: num_layers_nimus1" ) );
uiNumLayers++;
UInt uiStartIdx = m_acLayerInfo.size();
m_acLayerInfo .reinit( uiNumLayers );
m_acTimingInfo .reinit( uiNumLayers );
m_acNalHrd .reinit( uiNumLayers );
m_acVclHrd .reinit( uiNumLayers );
m_abLowDelayHrdFlag .reinit( uiNumLayers );
m_abPicStructPresentFlag.reinit( uiNumLayers );
for( UInt uiLayer = uiStartIdx; uiLayer < uiNumLayers + uiStartIdx; uiLayer++ )
{
RNOK( m_acLayerInfo.get(uiLayer).read( pcReadIf ) );
RNOK( m_acTimingInfo.get(uiLayer).read( pcReadIf ) );
RNOK( m_acNalHrd.get(uiLayer).read( pcReadIf ) );
RNOK( m_acVclHrd.get(uiLayer).read( pcReadIf ) );
if( m_acNalHrd.get(uiLayer).getHrdParametersPresentFlag() || m_acVclHrd.get(uiLayer).getHrdParametersPresentFlag() )
{
RNOK( pcReadIf->getFlag( m_abLowDelayHrdFlag.get(uiLayer), "VUI: low_delay_hrd_flag"));
}
RNOK( pcReadIf->getFlag( m_abPicStructPresentFlag.get(uiLayer), "VUI: pic_struct_present_flag"));
}
return Err::m_nOK;
}
// h264 namespace end
H264AVC_NAMESPACE_END
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -