⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 extractor.cpp

📁 jsvm开发代码包括抽样,编码,抽取,解码等一系列功能,可以做工具或研究用
💻 CPP
📖 第 1 页 / 共 5 页
字号:
			RNOK( CheckSuffixNalUnit( &cPacketDescription, bNextSuffix ) );
//prefix unit{{
			if((cPacketDescription.NalUnitType == 1 || cPacketDescription.NalUnitType == 5) && !bNextSuffix)
			{
				cPacketDescription.Level = uiLevel;
				cPacketDescription.bDiscardable = bDiscardable_prefix;
			}
			bDiscardable_prefix = cPacketDescription.bDiscardable;
//prefix unit}}	
      uiLayer     = cPacketDescription.Layer;
      uiLevel     = cPacketDescription.Level;
      uiFGSLayer  = cPacketDescription.FGSLayer;
    }
    bApplyToNext  = cPacketDescription.ApplyToNext;
    bNewPicture   = ( ! cPacketDescription.ParameterSet && ! cPacketDescription.ApplyToNext && !bFirstPacket );

    if((cPacketDescription.NalUnitType == 20 || cPacketDescription.NalUnitType == 21 ) && cPacketDescription.Layer == 0 && cPacketDescription.FGSLayer == 0 && getBaseLayerAVCCompatible())
    {
      bNewPicture = false;
    }
//prefix unit{{
	if( cPacketDescription.NalUnitType == 14 )
		bNewPicture = false;
//prefix unit}}

    //==== update stream description =====
    //{{Quality level estimation and modified truncation- JVTO044 and m12007
    //France Telecom R&D-(nathalie.cammas@francetelecom.com)
    //count number of picture per layer in input stream
    if (bNewPicture && uiFGSLayer == 0 && cPacketDescription.NalUnitType != NAL_UNIT_SEI)
    {
      auiNumImage[uiLayer] ++;
      if( cPacketDescription.NalUnitType == NAL_UNIT_CODED_SLICE ||
          cPacketDescription.NalUnitType == NAL_UNIT_CODED_SLICE_IDR )
        setBaseLayerAVCCompatible(true);
    }

    if(cPacketDescription.uiNumLevelsQL != 0)
    {
        //QL SEI packet
        bApplyToNext = false;
    }


    RNOK( m_pcReadBitstream->releasePacket( pcBinData ) );
    pcBinData = NULL;
  }

  //----- reset input file -----
  RNOKS( static_cast<ReadBitstreamFile*>(m_pcReadBitstream)->uninit() );
  RNOKS( static_cast<ReadBitstreamFile*>(m_pcReadBitstream)->init  ( m_pcExtractorParameter->getInFile() ) );

  //{{Quality level estimation and modified truncation- JVTO044 and m12007
  //France Telecom R&D-(nathalie.cammas@francetelecom.com)
  //save number of frames per layer
  for(uiLayer = 0; uiLayer < MAX_LAYERS; uiLayer++)
  {
    m_auiNbImages[uiLayer] = auiNumImage[uiLayer];
  }

  return Err::m_nOK;
}

Void Extractor::AllocateAndInitializeDatas()
{
    UInt uiLayer, uiFGSLayer, uiPoint, uiFrame;
    for(uiLayer=0; uiLayer<MAX_LAYERS; uiLayer++)
    {
        m_aaadMaxRate[uiLayer] = new Double[m_auiNbImages[uiLayer]];
        m_aaiLevelForFrame[uiLayer] = new Int[m_auiNbImages[uiLayer]];
        m_aadTargetByteForFrame[uiLayer] = new Double[m_auiNbImages[uiLayer]];
        m_aaiNumLevels[uiLayer] = new Int[m_auiNbImages[uiLayer]];
        for(uiFGSLayer = 0; uiFGSLayer <= MAX_FGS_LAYERS; uiFGSLayer++)
        {
            m_aaadTargetBytesFGS[uiLayer][uiFGSLayer] = new Double[m_auiNbImages[uiLayer]];
            m_aaadBytesForFrameFGS[uiLayer][uiFGSLayer] = new Double[m_auiNbImages[uiLayer]];
        }
        for(uiPoint = 0; uiPoint < MAX_NUM_RD_LEVELS; uiPoint++)
        {
            m_aaauiBytesForQualityLevel[uiLayer][uiPoint] = new UInt[m_auiNbImages[uiLayer]];
            m_aaadQualityLevel[uiLayer][uiPoint] = new Double[m_auiNbImages[uiLayer]];
        }
    }

    for(uiLayer=0; uiLayer<MAX_LAYERS; uiLayer++)
    {
        for(uiFrame=0; uiFrame<m_auiNbImages[uiLayer]; uiFrame++)
        {
            m_aaadMaxRate[uiLayer][uiFrame] = 0;
            m_aaiLevelForFrame[uiLayer][uiFrame] = -1;
            m_aadTargetByteForFrame[uiLayer][uiFrame] = 0;
            m_aaiNumLevels[uiLayer][uiFrame] = 0;
            for(uiFGSLayer = 0; uiFGSLayer <= MAX_FGS_LAYERS; uiFGSLayer++)
            {
                m_aaadTargetBytesFGS[uiLayer][uiFGSLayer][uiFrame] = 0;
                m_aaadBytesForFrameFGS[uiLayer][uiFGSLayer][uiFrame] = 0;
            }
            for(uiPoint = 0; uiPoint < MAX_NUM_RD_LEVELS; uiPoint++)
            {
                m_aaauiBytesForQualityLevel[uiLayer][uiPoint][uiFrame] = 0;
                m_aaadQualityLevel[uiLayer][uiPoint][uiFrame] = 0;
            }
        }
    }
}

ErrVal
Extractor::xAnalyse()
{
  UInt                    uiLayer       = 0;
  UInt                    uiLevel       = 0;
  UInt                    uiFGSLayer    = 0;
  Bool                    bNewPicture   = false;
  Bool                    bApplyToNext  = false;
  Bool                    bEOS          = false;
  BinData*                pcBinData     = 0;
	Bool                    bFirstPacket  = true;
  h264::SEI::SEIMessage*  pcScalableSei = 0;
  h264::PacketDescription cPacketDescription;
//prefix unit{{
	Bool bDiscardable_prefix;
//prefix unit}}
  //{{Quality level estimation and modified truncation- JVTO044 and m12007
  //France Telecom R&D-(nathalie.cammas@francetelecom.com)

  //Quality levels information
  UInt uiNumFrame;

  UInt uiMaxLayer = 0;
  UInt uiMaxTempLevel = 0;
  h264::SEI::ScalableSei*  pcTmpScalableSei = 0;

  //Common information to dead substreams and quality levels
  //arrays initialization
  static UInt auiNumImage[MAX_LAYERS] =
  {
    0,0,0,0,0,0,0,0
  };
  //}}Quality level estimation and modified truncation- JVTO044 and m12007

// JVT-T073 {
  Bool bNextSuffix = false;
// JVT-T073 }


  UInt uiPId = 0;

  // HS: packet trace
  Int64                   i64StartPos   = 0;
  Int64                   i64EndPos     = 0;
  Int                     iLastTempLevel= 0;
  m_uiMaxSize                           = 0;

  //========== initialize (scalable SEI message shall be the first packet of the stream) ===========
  {
    RNOK( m_pcH264AVCPacketAnalyzer->init() );
    //--- get first packet ---
    RNOK( m_pcReadBitstream->extractPacket( pcBinData, bEOS ) );

    if( bEOS )
    {
      RNOK( m_pcReadBitstream->releasePacket( pcBinData ) );
      return Err::m_nERR;
    }

    //--- analyse packet ---
    RNOK( m_pcH264AVCPacketAnalyzer ->process( pcBinData, cPacketDescription, pcScalableSei ) );
    if( !pcScalableSei )
    {
      printf("No scalability SEI messages found!\nExtractor exit.\n\n ");
      exit( 0 );
    }
    bFirstPacket = false;

    // HS: packet trace
    if( ! cPacketDescription.ApplyToNext )
    {
      i64EndPos     = static_cast<ReadBitstreamFile*>(m_pcReadBitstream)->getFilePos();
      UInt  uiStart = (UInt)( i64StartPos & 0xFFFFFFFF  );
      UInt  uiSize  = (UInt)( i64EndPos   - i64StartPos );
      i64StartPos   = i64EndPos;
      if( m_pcTraceFile )
      {
        ::fprintf( m_pcTraceFile, "Start-Pos.  Length  LId  TId  QId   Packet-Type  Discardable  Truncatable""\n" );
        ::fprintf( m_pcTraceFile, "==========  ======  ===  ===  ===  ============  ===========  ===========""\n" );
        ::fprintf( m_pcTraceFile, "0x%08x"   "%8d"   "%5d""%5d""%5d""  %s"        "         %s""         %s" "\n",
          uiStart,
          uiSize,
          cPacketDescription.Layer,
          cPacketDescription.Level,
          cPacketDescription.FGSLayer,
          "StreamHeader",
          " No", " No" );
      }
      m_uiMaxSize = max( m_uiMaxSize, uiSize );
    }

    //--- initialize stream description ----
    RNOK( m_cScalableStreamDescription.init( (h264::SEI::ScalableSei*)pcScalableSei ) );

    m_cScalableStreamDescription.setBaseLayerMode( getBaseLayerAVCCompatible() );
    pcTmpScalableSei    = (h264::SEI::ScalableSei* ) pcScalableSei;
    m_uiScalableNumLayersMinus1 = pcTmpScalableSei->getNumLayersMinus1();
    uiMaxLayer          = pcTmpScalableSei->getDependencyId( m_uiScalableNumLayersMinus1);
    uiMaxTempLevel      = pcTmpScalableSei->getTemporalLevel(m_uiScalableNumLayersMinus1);

    if(pcBinData)
    {
      RNOK( m_pcReadBitstream->releasePacket( pcBinData ) );
      pcBinData = NULL;
    }
  }

  while( ! bEOS )
  {
    //===== get packet =====
    RNOK( m_pcReadBitstream->extractPacket( pcBinData, bEOS ) );
    if( bEOS )
    {
      RNOK( m_pcReadBitstream->releasePacket( pcBinData ) );
      pcBinData = NULL;
      continue;
    }

    //===== get packet description =====
    RNOK( m_pcH264AVCPacketAnalyzer->process( pcBinData, cPacketDescription, pcScalableSei ) );

		RNOK( CheckSuffixNalUnit( &cPacketDescription, bNextSuffix ) );

    // *LMH (ADD) ->
		if ( m_pcExtractorParameter->getROIFlag() )
		{
				//-- ROI Extraction ICU/ETRI
				const MyList<ExtractorParameter::Point>&          rcExtList   = m_pcExtractorParameter->getExtractionList();
				ROT( rcExtList.size() != 1 );
				MyList<ExtractorParameter::Point>::const_iterator cIter       = rcExtList.begin ();
				MyList<ExtractorParameter::Point>::const_iterator cEnd        = rcExtList.end   ();
				const ExtractorParameter::Point&                  rcExtPoint  = *cIter;

				if (false == CurNalKeepingNeed(cPacketDescription, rcExtPoint))
				{
					if(pcBinData)
					{
						RNOK( m_pcReadBitstream->releasePacket( pcBinData ) );
						pcBinData = NULL;
					}
					continue;
				}
		}
		// *LMH (ADD) <-
    // JVT-S080 LMI {
    delete pcScalableSei;
    pcScalableSei = NULL;
    // JVT-S080 LMI }
    // HS: packet trace
    if( ! cPacketDescription.ApplyToNext )
    {
      if( iLastTempLevel )
      {
        cPacketDescription.Level  = iLastTempLevel;
        iLastTempLevel            = 0;
      }
      i64EndPos     = static_cast<ReadBitstreamFile*>(m_pcReadBitstream)->getFilePos();
      UInt  uiStart = (UInt)( i64StartPos & 0xFFFFFFFF  );
      UInt  uiSize  = (UInt)( i64EndPos   - i64StartPos );
      i64StartPos   = i64EndPos;
      if( m_pcTraceFile )
      {
        ::fprintf( m_pcTraceFile, "0x%08x"   "%8d"   "%5d""%5d""%5d""  %s"        "         %s""         %s" "\n",
          uiStart,
          uiSize,
          cPacketDescription.Layer,
          cPacketDescription.Level,
          cPacketDescription.FGSLayer,
          cPacketDescription.ParameterSet ? "ParameterSet" : "   SliceData",
          cPacketDescription.ParameterSet || ( cPacketDescription.Level == 0 && cPacketDescription.FGSLayer == 0 )  ? " No" : "Yes",
          cPacketDescription.FGSLayer ? "Yes" : " No" );
      }
      m_uiMaxSize = max( m_uiMaxSize, uiSize );
    }
    else
    {
      iLastTempLevel = cPacketDescription.Level;
    }

    //===== set packet length =====
    while( pcBinData->data()[ pcBinData->size() - 1 ] == 0x00 )
    {
      RNOK( pcBinData->decreaseEndPos( 1 ) ); // remove zero at end
    }

    //==== get parameters =====
    UInt  uiPacketSize  = 4 + pcBinData->size();
    if( ! bApplyToNext )
    {
			RNOK( CheckSuffixNalUnit( &cPacketDescription, bNextSuffix ) );
//prefix unit{{
			if((cPacketDescription.NalUnitType == 1 || cPacketDescription.NalUnitType == 5) && !bNextSuffix)
			{
				cPacketDescription.Level = uiLevel;
				cPacketDescription.bDiscardable = bDiscardable_prefix;
			}
			bDiscardable_prefix = cPacketDescription.bDiscardable;
//prefix unit}}	
      uiLayer     = cPacketDescription.Layer;
      uiLevel     = cPacketDescription.Level;
      uiFGSLayer  = cPacketDescription.FGSLayer;
    }
//JVT-T054{
    if(uiFGSLayer > 0)
      m_bEnableQLTruncation[uiLayer][uiFGSLayer-1] = cPacketDescription.bEnableQLTruncation;
//JVT-T054}
    bApplyToNext  = cPacketDescription.ApplyToNext;
    bNewPicture   = ( ! cPacketDescription.ParameterSet && ! cPacketDescription.ApplyToNext && !bFirstPacket );
    if((cPacketDescription.NalUnitType == 20 || cPacketDescription.NalUnitType == 21 ) && cPacketDescription.Layer == 0 && cPacketDescription.FGSLayer == 0 && getBaseLayerAVCCompatible())
    {
      bNewPicture = false;
    }
//prefix unit{{
	if( cPacketDescription.NalUnitType == 14 )
		bNewPicture = false;
//prefix unit}}
    uiPId = cPacketDescription.uiPId;
    //S051{
    if(!m_bUseSIP)
    //S051}
    //JVT-P031
    if(cPacketDescription.bDiscardable)
    {
      m_bInInputStreamDS = true;
    }
    //~JVT-P031

    //==== update stream description =====
    //{{Quality level estimation and modified truncation- JVTO044 and m12007
    //France Telecom R&D-(nathalie.cammas@francetelecom.com)
    //count number of picture per layer in input stream
    if (bNewPicture && uiFGSLayer == 0 && cPacketDescription.NalUnitType != NAL_UNIT_SEI)
    {
      auiNumImage[uiLayer] ++;
    }
     if(cPacketDescription.ParameterSet || cPacketDescription.NalUnitType == NAL_UNIT_SEI 
			   || cPacketDescription.NalUnitType == NAL_UNIT_PREFIX ) //prefix unit
		 {
      //NonRequired JVT-Q066 (06-04-08){{
      if(m_pcH264AVCPacketAnalyzer->getNonRequiredSeiFlag() == 1 )
      {
        uiLayer = uiMaxLayer;
      }
      //NonRequired JVT-Q066 (06-04-08)}}
      uiNumFrame = auiNumImage[uiLayer];
    }
    else
      uiNumFrame = auiNumImage[uiLayer]-1;

    if(cPacketDescription.uiNumLevelsQL != 0)
    {
      //QL SEI packet
      bApplyToNext = false;
    }

    if(m_pcExtractorParameter->getExtractUsingQL() == true)
    {
      m_bInInputStreamQL = true;

      //Saving of Quality Level SEI information
      if(cPacketDescription.uiNumLevelsQL != 0)
      {
        m_bQualityLevelInSEI = true;
        m_aaiNumLevels[uiLayer][uiNumFrame] = cPacketDescription.uiNumLevelsQL;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -