h264avcdecoder.cpp
来自「JVT-S203 contains the JSVM 6 reference s」· C++ 代码 · 共 1,899 行 · 第 1/5 页
CPP
1,899 行
m_pcSliceHeader = m_pcPrevSliceHeader;
m_pcPrevSliceHeader = pTmp;
for ( UInt i=0; i< m_uiNumLayers; i++)
{
if (m_pauiPocInGOP[i]) delete [] m_pauiPocInGOP[i];
if (m_pauiFrameNumInGOP[i]) delete [] m_pauiFrameNumInGOP[i];
if (m_pauiTempLevelInGOP[i]) delete [] m_pauiTempLevelInGOP[i];
}
m_bLastFrame = true;
delete m_pcSliceHeader;
m_pcSliceHeader = 0;
return Err::m_nOK;
}
//TMM_EC }}
switch ( m_pcNalUnitParser->getNalUnitType() )
{
case NAL_UNIT_CODED_SLICE:
case NAL_UNIT_CODED_SLICE_IDR:
{
UnitAVCFlag = true; //JVT-S036 lsj
//JVT-P031
RNOK( xStartSlice(bPreParseHeader,bLastFragment, bDiscardable, UnitAVCFlag) ); //FRAG_FIX //TMM_EC //JVT-S036 lsj
ruiEndPos = pcBinDataAccessor->size();
bDiscardable = false;
uiHeaderBits = uiBitsLeft - m_pcNalUnitParser->getBitsLeft();
ruiStartPos += (uiHeaderBits+7)>>3;
ruiStartPos = 0; //FRAG_FIX
//~JVT-P031
RNOK( m_pcControlMng ->initSlice0(m_pcSliceHeader) );
m_pcSliceHeader->setKeyPictureFlag (KeyPicFlag);
m_bActive = true;
rbStartDecoding = true; //JVT-P031
bSuffixUnit = true; //JVT-S036 lsj
//TMM_EC {{
if (!m_bNotSupport && !bPreParseHeader)
{
UInt uiMaxGopSize = m_uiMaxGopSize;
UInt uiGopSize;
m_uiNextLayerId = m_pcSliceHeader->getLayerId();
do
{
m_uiNextLayerId = (m_uiNextLayerId + 1) % m_uiNumLayers;
uiGopSize = 1 << m_uiDecompositionStages[m_uiNextLayerId];
if (m_uiFrameIdx[m_uiNextLayerId] % uiMaxGopSize < m_uiGopSize[m_uiNextLayerId])
break;
m_uiFrameIdx[m_uiNextLayerId]++;
}
while( true);
if ( m_pcNalUnitParser->getNalUnitType() != NAL_UNIT_CODED_SLICE_IDR || m_uiNextLayerId == 0)
{
UInt uiMaxFrameNum = 1 << m_pcSliceHeader->getSPS().getLog2MaxFrameNum();
m_uiNextFrameNum = m_pauiFrameNumInGOP[m_uiNextLayerId][m_uiFrameIdx[m_uiNextLayerId] % uiGopSize] % uiMaxFrameNum;
m_uiNextPoc = m_pauiPocInGOP[m_uiNextLayerId][m_uiFrameIdx[m_uiNextLayerId] % uiGopSize];
m_uiNextTempLevel = m_pauiTempLevelInGOP[m_uiNextLayerId][m_uiFrameIdx[m_uiNextLayerId] % uiGopSize];
m_pauiFrameNumInGOP[m_uiNextLayerId][m_uiFrameIdx[m_uiNextLayerId] % uiGopSize] += uiGopSize >> 1;
m_pauiPocInGOP[m_uiNextLayerId][m_uiFrameIdx[m_uiNextLayerId] % uiGopSize] += uiMaxGopSize;
m_uiFrameIdx[m_uiNextLayerId]++;
}
else
{
m_uiNextFrameNum = 0;
m_uiNextPoc = 0;
}
}
//TMM_EC }}
m_pcSliceHeader->setFGSCodingMode( m_bFGSCodingMode );
m_pcSliceHeader->setGroupingSize ( m_uiGroupingSize );
UInt ui;
for( ui = 0; ui < 16; ui++ )
{
m_pcSliceHeader->setPosVect( ui, m_uiPosVect[ui] );
}
}
break;
case NAL_UNIT_SPS:
{
SequenceParameterSet* pcSPS = NULL;
RNOK( SequenceParameterSet::create ( pcSPS ) );
RNOK( pcSPS ->read ( m_pcHeaderSymbolReadIf,
m_pcNalUnitParser->getNalUnitType() ) );
// It is assumed that layer 0 and layer 1 use the first two SPSs, respectively.
if( NULL == m_pcVeryFirstSPS )
{
setVeryFirstSPS( pcSPS );
}
//TMM_EC {{
for ( UInt i=0; i<m_uiNumLayers; i++)
{
UInt uiDecompositionStagesSub = m_uiMaxDecompositionStages - m_uiDecompositionStages[i];
UInt uiGopSize = m_uiGopSize[i];
m_pauiPocInGOP[i] = new UInt[uiGopSize];
m_pauiFrameNumInGOP[i] = new UInt[uiGopSize];
m_pauiTempLevelInGOP[i] = new UInt[uiGopSize];
UInt uiFrameIdx = 0;
UInt uiFrameNum = 1;
for( UInt uiTemporalLevel = 0; uiTemporalLevel <= m_uiDecompositionStages[i]; uiTemporalLevel++ )
{
UInt uiStep = ( 1 << ( m_uiDecompositionStages[i] - uiTemporalLevel ) );
for( UInt uiFrameId = uiStep; uiFrameId <= uiGopSize; uiFrameId += ( uiStep << 1 ) )
{
m_pauiPocInGOP[i][uiFrameIdx] = uiFrameId << uiDecompositionStagesSub;
m_pauiFrameNumInGOP[i][uiFrameIdx] = uiFrameNum;
m_pauiTempLevelInGOP[i][uiFrameIdx] = uiTemporalLevel;
uiFrameIdx++;
if ( uiFrameId % 2 == 0)
uiFrameNum++;
}
}
}
//TMM_EC }}
if ( pcSPS->getProfileIdc()==SCALABLE_PROFILE )
{
//TMM_EC {{
if ( pcSPS->getSeqParameterSetId() == 0)
{
m_bNotSupport = true;
}
//TMM_EC }}
m_bEnhancementLayer = true;
}
m_bNewSPS = true;
RNOK( m_pcParameterSetMng ->store ( pcSPS ) );
// Copy simple priority ID mapping from SPS to NAL unit parser
/* if ( !pcSPS->getNalUnitExtFlag() )
{
for ( UInt uiPriId = 0; uiPriId < pcSPS->getNumSimplePriIdVals(); uiPriId++)
{
UInt uiLayer, uiTempLevel, uiQualLevel;
pcSPS->getSimplePriorityMap( uiPriId, uiTempLevel, uiLayer, uiQualLevel );
m_pcNalUnitParser->setSimplePriorityMap( uiPriId, uiTempLevel, uiLayer, uiQualLevel );
}
}
JVT-S036 lsj */
ruiMbX = pcSPS->getFrameWidthInMbs ();
ruiMbY = pcSPS->getFrameHeightInMbs();
ruiSize = max( ruiSize, ( (ruiMbX << 3 ) + YUV_X_MARGIN ) * ( ( ruiMbY << 3 ) + YUV_Y_MARGIN ) * 6 );
m_pcControlMng->initSPS( *pcSPS, m_uiRecLayerId );
ruiEndPos = pcBinDataAccessor->size(); //JVT-P031
bDiscardable = false;//JVT-P031
rbStartDecoding = true;//JVT-P031
m_bFGSCodingMode = pcSPS->getFGSCodingMode();
m_uiGroupingSize = pcSPS->getGroupingSize ();
UInt ui;
for(ui = 0; ui < 16; ui++)
{
m_uiPosVect[ui] = pcSPS->getPosVect(ui);
}
}
break;
case NAL_UNIT_PPS:
{
PictureParameterSet* pcPPS = NULL;
RNOK( PictureParameterSet::create( pcPPS ) );
RNOK( pcPPS->read( m_pcHeaderSymbolReadIf,
m_pcNalUnitParser->getNalUnitType() ) );
RNOK( m_pcParameterSetMng->store( pcPPS ) );
ruiEndPos = pcBinDataAccessor->size();//JVT-P031
bDiscardable = false;//JVT-P031
rbStartDecoding = true;//JVT-P031
}
break;
case NAL_UNIT_CODED_SLICE_SCALABLE:
case NAL_UNIT_CODED_SLICE_IDR_SCALABLE:
{
//JVT-P031
getDecodedResolution(m_uiDecodedLayer);
if(m_pcNalUnitParser->getLayerId() < m_uiDecodedLayer && m_pcNalUnitParser->getDiscardableFlag())
bDiscardable = true;
else
bDiscardable = false;
RNOK( xStartSlice(bPreParseHeader,bLastFragment, bDiscardable, UnitAVCFlag) ); //FRAG_FIX //TMM_EC //JVT-S036 lsj
if(bDiscardable)
ruiEndPos = 0;
else
ruiEndPos = pcBinDataAccessor->size();
uiHeaderBits = uiBitsLeft - m_pcNalUnitParser->getBitsLeft();
if( (bDiscardable) || !bLastFragment) //FRAG_FIX
ruiStartPos = 0;
else
{
//JVT-S036 lsj start
// if(m_pcNalUnitParser->getExtensionFlag())
//{
// ruiStartPos += (uiHeaderBits+3*8+7)>>3;//(uiHeaderBits+7)>>3; //BUG_FIX_FT_01_2006_2
//3*8 is used to take into account the nal header which has already been read
//uiHeaderBits only contains the remaining bits of the slice header read
//}
// else
// {
ruiStartPos += (uiHeaderBits+3*8+7)>>3;//BUG_FIX_FT_01_2006_2
// }
//JVT-S036 lsj end
}
if(m_pcSliceHeader && (m_pcSliceHeader->getFragmentedFlag() && !bLastFragment ))
{ //FIX_FRAG_CAVLC
if(bPreParseHeader)
{
ruiEndPos -= uiNumBytesRemoved;
}//~FIX_FRAG_CAVLC
ruiEndPos -= 2;
}//FIX_FRAG_CAVLC
if(!bDiscardable)
//~JVT-P031
RNOK( m_pcControlMng ->initSlice0(m_pcSliceHeader) );
if(m_pcSliceHeader) //JVT-P031
m_pcSliceHeader->setKeyPictureFlag (KeyPicFlag);
//JVT-P031
bFragmented = (!m_pcSliceHeader ? false : m_pcSliceHeader->getFragmentedFlag());
if( (bLastFragment) || (!bFragmented) ||
( bFragmented && m_pcSliceHeader->getFragmentOrder()+1 == m_uiNumberOfFragment[m_pcSliceHeader->getLayerId() ]))
rbStartDecoding = true;
//~JVT-P031
//TMM_EC {{
if ( !m_bNotSupport && !bPreParseHeader && m_pcNalUnitParser->getQualityLevel() == 0)
{
UInt uiMaxGopSize = m_uiMaxGopSize;
UInt uiGopSize;
m_uiNextLayerId = m_pcSliceHeader->getLayerId();
do
{
m_uiNextLayerId = (m_uiNextLayerId + 1) % m_uiNumLayers;
uiGopSize = 1 << m_uiDecompositionStages[m_uiNextLayerId];
if (m_uiFrameIdx[m_uiNextLayerId] % uiMaxGopSize < m_uiGopSize[m_uiNextLayerId])
break;
m_uiFrameIdx[m_uiNextLayerId]++;
}
while( true);
if ( m_pcNalUnitParser->getNalUnitType() != NAL_UNIT_CODED_SLICE_IDR || m_uiNextLayerId == 0)
{
UInt uiMaxFrameNum = 1 << m_pcSliceHeader->getSPS().getLog2MaxFrameNum();
m_uiNextFrameNum = m_pauiFrameNumInGOP[m_uiNextLayerId][m_uiFrameIdx[m_uiNextLayerId] % uiGopSize] % uiMaxFrameNum;
m_uiNextPoc = m_pauiPocInGOP[m_uiNextLayerId][m_uiFrameIdx[m_uiNextLayerId] % uiGopSize];
m_uiNextTempLevel = m_pauiTempLevelInGOP[m_uiNextLayerId][m_uiFrameIdx[m_uiNextLayerId] % uiGopSize];
m_pauiFrameNumInGOP[m_uiNextLayerId][m_uiFrameIdx[m_uiNextLayerId] % uiGopSize] += uiGopSize >> 1;
m_pauiPocInGOP[m_uiNextLayerId][m_uiFrameIdx[m_uiNextLayerId] % uiGopSize] += uiMaxGopSize;
m_uiFrameIdx[m_uiNextLayerId]++;
}
else
{
m_uiNextFrameNum = 0;
m_uiNextPoc = 0;
}
}
//TMM_EC }}
if(m_pcSliceHeader)
{
m_pcSliceHeader->setFGSCodingMode( m_bFGSCodingMode );
m_pcSliceHeader->setGroupingSize ( m_uiGroupingSize );
UInt ui;
for(ui = 0; ui < 16; ui++)
{
m_pcSliceHeader->setPosVect( ui, m_uiPosVect[ui] );
}
}
}
break;
case NAL_UNIT_SEI:
{
//===== just for trace file =====
SEI::MessageList cMessageList;
UInt i;
RNOK( SEI::read( m_pcHeaderSymbolReadIf, cMessageList ) );
while( ! cMessageList.empty() )
{
SEI::SEIMessage* pcSEIMessage = cMessageList.popBack();
if(pcSEIMessage->getMessageType() == SEI::NON_REQUIRED_SEI)
{
m_pcNonRequiredSei = (SEI::NonRequiredSei*) pcSEIMessage;
m_uiNonRequiredSeiReadFlag = 1;
}
else
{
if ( pcSEIMessage->getMessageType() == SEI::SCALABLE_SEI)
{
// trick
m_uiNumLayers = ((SEI::ScalableSei*)pcSEIMessage)->getDependencyId( ((SEI::ScalableSei*)pcSEIMessage)->getNumLayersMinus1()) + 1;
for ( uiLayerId=0; uiLayerId<((SEI::ScalableSei*)pcSEIMessage)->getNumLayersMinus1()+1; uiLayerId++)
{
if ( ((SEI::ScalableSei*)pcSEIMessage)->getDependencyId( uiLayerId) != 0)
break;
}
uiLayerId--;
m_uiDecompositionStages[0] = ((SEI::ScalableSei*)pcSEIMessage)->getTemporalLevel( uiLayerId);
m_uiDecompositionStages[m_uiNumLayers-1] = ((SEI::ScalableSei*)pcSEIMessage)->getTemporalLevel( ((SEI::ScalableSei*)pcSEIMessage)->getNumLayersMinus1());
m_uiMaxDecompositionStages = m_uiDecompositionStages[m_uiNumLayers-1];
m_uiMaxGopSize = 1 << m_uiMaxDecompositionStages;
for ( i=0; i< m_uiNumLayers; i++)
m_uiGopSize[i] = 1 << m_uiDecompositionStages[i];
}
delete pcSEIMessage;
}
}
ruiEndPos = (uiBitsLeft+7)/8; //FRAG_FIX
bDiscardable = false;//JVT-P031
rbStartDecoding = true;//JVT-P031
}
break;
case NAL_UNIT_ACCESS_UNIT_DELIMITER:
{
RNOK ( m_pcNalUnitParser->readAUDelimiter());
ruiEndPos = pcBinDataAccessor->size();//JVT-P031
bDiscardable = false;//JVT-P031
rbStartDecoding = true;//JVT-P031
}
break;
case NAL_UNIT_END_OF_SEQUENCE:
{
RNOK ( m_pcNalUnitParser->readEndOfSeqence());
ruiEndPos = pcBinDataAccessor->size();//JVT-P031
bDiscardable = false;//JVT-P031
rbStartDecoding = true;//JVT-P031
}
case NAL_UNIT_END_OF_STREAM:
{
RNOK ( m_pcNalUnitParser->readEndOfStream());
ruiEndPos = pcBinDataAccessor->size();//JVT-P031
bDiscardable = false;//JVT-P031
rbStartDecoding = true;//JVT-P031
}
break;
default:
return Err::m_nERR;
break;
}
m_uiNonRequiredPic = 0; //NonRequired JVT-Q066
//ruiNonRequiredPic = 0;
if(m_pcSliceHeader)
{
m_uiCurrPicLayer = (m_pcSliceHeader->getLayerId() << 4) + m_pcSliceHeader->getQualityLevel();
if(m_uiCurrPicLayer == 0 || m_uiCurrPicLayer <= m_uiPrevPicLayer)
{
if(m_uiNonRequiredSeiReadFlag == 0 && m_pcNonRequiredSei)
{
m_pcNonRequiredSei->destroy();
m_pcNonRequiredSei = NULL;
}
m_uiNonRequiredSeiRead = m_uiNonRequiredSeiReadFlag;
m_uiNonRequiredSeiReadFlag = 0;
}
m_uiPrevPicLayer = m_uiCurrPicLayer;
if(m_uiNonRequiredSeiRead == 1)
{
for(UInt i = 0; i <= m_pcNonRequiredSei->getNumInfoEntriesMinus1(); i++)
{
if(m_pcNonRequiredSei->getEntryDependencyId(i)) // it should be changed to if(DenpendencyId == LayerId of the shown picture)
{
for(UInt j = 0; j <= m_pcNonRequiredSei->getNumNonRequiredPicsMinus1(i); j++)
{
if(m_pcSliceHeader->getLayerId() == m_pcNonRequiredSei->getNonRequiredPicDependencyId(i,j) &&
m_pcSliceHeader->getQualityLevel() == m_pcNonRequiredSei->getNonRequiredPicQulityLevel(i,j)) // it should be add something about FragmentFlag
{
m_uiNonRequiredPic = 1; //NonRequired JVT-Q066
// ruiNonRequiredPic = 1;
ROTRS( m_apcMCTFDecoder[m_pcSliceHeader->getLayerId()]->getWaitForIdr() && !m_pcSliceHeader->isIdrNalUnit(), Err::m_nOK );
m_apcMCTFDecoder[m_pcSliceHeader->getLayerId()]->setWaitForIdr(false);
return Err::m_nOK;
}
}
}
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?