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

📄 createrh264avcdecoder.cpp

📁 jsvm开发代码包括抽样,编码,抽取,解码等一系列功能,可以做工具或研究用
💻 CPP
📖 第 1 页 / 共 3 页
字号:
        uiLayer = 0;
        pcScalableSEIMessage = pcSEIMessage;
        {
          //====set parameters used for further parsing =====
          SEI::ScalableSei* pcSEI    = (SEI::ScalableSei*)pcSEIMessage;
          UInt uiNumScalableLayers  = pcSEI->getNumLayersMinus1() + 1;
          for(UInt uiIndex = 0; uiIndex < uiNumScalableLayers; uiIndex++ )
          {
            if( pcSEI->getDependencyId( uiIndex ) == 0 )
            {
// BUG_FIX liuhui{
              m_uiStdAVCOffset = pcSEI->getTemporalLevel( uiIndex );
              pcSEI->setStdAVCOffset( m_uiStdAVCOffset-1 ); //bugfix replace
              //bugfix delete
// BUG_FIX liuhui}
            }
            else
              break;
          }
        }

          SEI::ScalableSei* pcSEI    = (SEI::ScalableSei*)pcSEIMessage;
          m_uiNum_layers = pcSEI->getNumLayersMinus1() + 1;
          for(int i=0; i< m_uiNum_layers; i++)
        {
          m_ID_ROI[i] = pcSEI->getRoiId(i);
          m_ID_Dependency[i] = pcSEI->getDependencyId(i);
        }
        break;
      }

    case SEI::MOTION_SEI:
      {
        SEI::MotionSEI* pcSEI           = (SEI::MotionSEI*)pcSEIMessage;

        m_silceIDOfSubPicLayer[m_layer_id] = pcSEI->m_slice_group_id[0];
        break;
      }

// JVT-S080 LMI {
    case SEI::SCALABLE_SEI_LAYERS_NOT_PRESENT:
      case SEI::SCALABLE_SEI_DEPENDENCY_CHANGE:
      {
        pcScalableSEIMessage = pcSEIMessage;
        break;
      }
// JVT-S080 LMI }
      case SEI::SUB_PIC_SEI:
      {
        SEI::SubPicSei* pcSEI    = (SEI::SubPicSei*)pcSEIMessage;
        m_layer_id          = pcSEI->getLayerId();
        bApplyToNext  = true;
              break;
      }
      //{{Quality level estimation and modified truncation- JVTO044 and m12007
      //France Telecom R&D-(nathalie.cammas@francetelecom.com)
      case SEI::QUALITYLEVEL_SEI:
      {
      UInt uiNum = 0;
      UInt uiDeltaBytesRateOfLevel = 0;
      UInt uiQualityLevel = 0;
      SEI::QualityLevelSEI* pcSEI           = (SEI::QualityLevelSEI*)pcSEIMessage;
      uiNum = pcSEI->getNumLevel();
      rcPacketDescription.uiNumLevelsQL = uiNum;
      for(UInt ui = 0; ui < uiNum; ui++)
      {
        uiQualityLevel = pcSEI->getQualityLevel(ui);
        uiDeltaBytesRateOfLevel = pcSEI->getDeltaBytesRateOfLevel(ui);
        rcPacketDescription.auiQualityLevelQL[ui] = uiQualityLevel;
        rcPacketDescription.auiDeltaBytesRateOfLevelQL[ui] = uiDeltaBytesRateOfLevel;
      }
      uiLayer = pcSEI->getDependencyId();
      bApplyToNext = true;
      break;
      }
      //}}Quality level estimation and modified truncation- JVTO044 and m12007
      case SEI::NON_REQUIRED_SEI:
      {
        m_pcNonRequiredSEI = (SEI::NonRequiredSei*) pcSEIMessage;
        m_uiNonRequiredSeiFlag = 1;
        break;
      }
// JVT-T073 {
    case SEI::SCALABLE_NESTING_SEI:
      {
        Bool bAllPicturesInAuFlag;
        UInt uiNumPictures;
        UInt *puiDependencyId, *puiQualityLevel;
        SEI::ScalableNestingSei* pcSEI = (SEI::ScalableNestingSei*)pcSEIMessage;
        bAllPicturesInAuFlag = pcSEI->getAllPicturesInAuFlag();
        if( bAllPicturesInAuFlag == 0 )
        {
          uiNumPictures = pcSEI->getNumPictures();
          ROT( uiNumPictures == 0 );
          puiDependencyId = new UInt[uiNumPictures];
          puiQualityLevel = new UInt[uiNumPictures];
          for( UInt uiIndex = 0; uiIndex < uiNumPictures; uiIndex++ )
          {
            puiDependencyId[uiIndex] = pcSEI->getDependencyId(uiIndex);
            puiQualityLevel[uiIndex] = pcSEI->getQualityLevel(uiIndex);
          }
          //make use of dependency_id and quality_level here

          delete puiDependencyId;
          delete puiQualityLevel;
        }
              bApplyToNext = true;
        break;
      }
// JVT-T073 }
      default:
        {
          delete pcSEIMessage;
        }
      }
    }
    m_pcNalUnitParser->closeNalUnit();
  }

  if( eNalUnitType != NAL_UNIT_SEI )
  {
    ULong*  pulData = (ULong*)( pcBinData->data() + 1 );
    UInt    uiSize  =     8 * ( pcBinData->size() - 1 ) - 1;
    RNOK( m_pcBitReadBuffer->initPacket( pulData, uiSize ) );

    uiSize = pcBinData->byteSize();
    BinData cBinData( new UChar[uiSize], uiSize );
    memcpy( cBinData.data(), pcBinData->data(), uiSize );
    BinDataAccessor cBinDataAccessor;
    cBinData.setMemAccessor( cBinDataAccessor );
    m_pcNalUnitParser->setCheckAllNALUs(true); //JVT-P031
    UInt uiNumBytesRemoved; //FIX_FRAG_CAVLC
//bug-fix suffix shenqiu{{
  //RNOK( m_pcNalUnitParser->initNalUnit( &cBinDataAccessor, NULL, uiNumBytesRemoved ) ); //FIX_FRAG_CAVLC
  RNOK( m_pcNalUnitParser->initNalUnit( &cBinDataAccessor, uiNumBytesRemoved ) ); //FIX_FRAG_CAVLC
//bug-fix suffix shenqiu}}
    m_pcNalUnitParser->setCheckAllNALUs(false);//JVT-P031

    // get the SPSid
    if(eNalUnitType == NAL_UNIT_SPS )
    {
      SequenceParameterSet* pcSPS = NULL;
      RNOK( SequenceParameterSet::create  ( pcSPS   ) );
      RNOK( pcSPS->read( m_pcUvlcReader, eNalUnitType ) );
      // Copy simple priority ID mapping from SPS

      uiSPSid = pcSPS->getSeqParameterSetId();
      pcSPS->destroy();
    }
    // get the PPSid and the referenced SPSid
    else if( eNalUnitType == NAL_UNIT_PPS )
    {
      PictureParameterSet* pcPPS = NULL;
      RNOK( PictureParameterSet::create  ( pcPPS   ) );
      RNOK( pcPPS->read( m_pcUvlcReader, eNalUnitType ) );
      uiPPSid = pcPPS->getPicParameterSetId();
      uiSPSid = pcPPS->getSeqParameterSetId();

    // FMO ROI ICU/ETRI
    m_uiNumSliceGroupsMinus1 = pcPPS->getNumSliceGroupsMinus1();

    for(UInt i=0; i<=m_uiNumSliceGroupsMinus1; i++)
    {
     uiaAddrFirstMBofROIs[uiPPSid ][i] = pcPPS->getTopLeft (i);
     uiaAddrLastMBofROIs[uiPPSid ][i]  = pcPPS->getBottomRight (i);
    }

      pcPPS->destroy();
      rcPacketDescription.SPSidRefByPPS[uiPPSid] = uiSPSid;
    }
    // get the PPSid and SPSid referenced by the slice header
    else if(  eNalUnitType == NAL_UNIT_CODED_SLICE              ||
              eNalUnitType == NAL_UNIT_CODED_SLICE_IDR          ||
              eNalUnitType == NAL_UNIT_CODED_SLICE_SCALABLE     ||
              eNalUnitType == NAL_UNIT_CODED_SLICE_IDR_SCALABLE   )
    {
      // fragmented flag means that FGS is used.
      rcPacketDescription.bEnableQLTruncation = bFragmentedFlag;

      if(!(uiLayer == 0 && uiFGSLayer == 0 &&
      (eNalUnitType == NAL_UNIT_CODED_SLICE_SCALABLE||eNalUnitType == NAL_UNIT_CODED_SLICE_IDR_SCALABLE))){

      UInt uiTemp;
      //JVT-P031
    RNOK( m_pcUvlcReader->getUvlc( uiTemp,  "SH: first_mb_in_slice" ) );

  // FMO ROI ICU/ETRI
  rcPacketDescription.uiFirstMb = uiTemp;


    RNOK( m_pcUvlcReader->getUvlc( uiTemp,  "SH: slice_type" ) );
          // Normally the following test is not necessary because FGS slice shall be marked as Fragmented.
    //JVT-T054_FIX{
    rcPacketDescription.bEnableQLTruncation = false;
    //JVT-T054}
    if(uiTemp == F_SLICE)
      rcPacketDescription.bEnableQLTruncation = true;

        RNOK( m_pcUvlcReader->getUvlc( uiPPSid, "SH: pic_parameter_set_id" ) );
        uiSPSid = rcPacketDescription.SPSidRefByPPS[uiPPSid];

    //~JVT-P031
    m_uiCurrPicLayer = (uiLayer << 4) + uiFGSLayer;
    if((m_uiCurrPicLayer < m_uiPrevPicLayer || (m_uiCurrPicLayer == m_uiPrevPicLayer && m_uiCurrPicLayer == 0))&& m_uiNonRequiredSeiFlag != 1) //prefix unit
    {
      m_pcNonRequiredSEI->destroy();
      m_pcNonRequiredSEI = NULL;
    }
    m_uiNonRequiredSeiFlag = 0;
    m_uiPrevPicLayer = m_uiCurrPicLayer;
    }
//BUG_FIX Kai Zhang}
    }
    m_pcNalUnitParser->closeNalUnit();
  }

  rcPacketDescription.NalUnitType   = eNalUnitType;
  rcPacketDescription.SPSid         = uiSPSid;
  rcPacketDescription.PPSid         = uiPPSid;

  rcPacketDescription.Scalable      = bScalable;
  rcPacketDescription.ParameterSet  = bParameterSet;
  rcPacketDescription.Layer         = uiLayer;
  rcPacketDescription.FGSLayer      = uiFGSLayer;
  rcPacketDescription.Level         = uiLevel;
  rcPacketDescription.ApplyToNext   = bApplyToNext;
  rcPacketDescription.uiPId         = uiSimplePriorityId;
  rcPacketDescription.bDiscardable  = bDiscardableFlag;//JVT-P031
  rcPacketDescription.bFragmentedFlag   = bFragmentedFlag;//JVT-P031
  rcPacketDescription.uiFragmentOrder   = uiFragmentOrder;
  rcPacketDescription.bLastFragmentFlag = bLastFragmentFlag;
  rcPacketDescription.NalRefIdc     = eNalRefIdc;
  return Err::m_nOK;
}



ErrVal
H264AVCPacketAnalyzer::create( H264AVCPacketAnalyzer*& rpcH264AVCPacketAnalyzer )
{
  rpcH264AVCPacketAnalyzer = new H264AVCPacketAnalyzer;
  ROT( NULL == rpcH264AVCPacketAnalyzer );
  RNOK( rpcH264AVCPacketAnalyzer->xCreate() )
  return Err::m_nOK;
}



ErrVal
H264AVCPacketAnalyzer::xCreate()
{
  RNOK( BitReadBuffer::create( m_pcBitReadBuffer ) );
  RNOK( UvlcReader   ::create( m_pcUvlcReader    ) );
  RNOK( NalUnitParser::create( m_pcNalUnitParser  ) );

  return Err::m_nOK;
}



ErrVal
H264AVCPacketAnalyzer::destroy()
{
  RNOK( m_pcBitReadBuffer ->destroy() );
  RNOK( m_pcUvlcReader    ->destroy() );
  RNOK( m_pcNalUnitParser ->destroy() );

  delete this;

  return Err::m_nOK;
}



ErrVal
H264AVCPacketAnalyzer::init()
{
  RNOK( m_pcBitReadBuffer ->init() );
  RNOK( m_pcUvlcReader    ->init( m_pcBitReadBuffer ) );
  RNOK( m_pcNalUnitParser ->init( m_pcBitReadBuffer ) );

  ::memset( m_auiDecompositionStages, 0x00, MAX_LAYERS*sizeof(UInt) );

  return Err::m_nOK;
}



ErrVal
H264AVCPacketAnalyzer::uninit()
{
  RNOK( m_pcBitReadBuffer ->uninit() );
  RNOK( m_pcUvlcReader    ->uninit() );

  return Err::m_nOK;
}


// JVT-Q054 Red. Picture {
Bool
CreaterH264AVCDecoder::isRedundantPic()
{
  return m_pcH264AVCDecoder->isRedundantPic();
}


ErrVal
CreaterH264AVCDecoder::checkRedundantPic()
{
  return m_pcH264AVCDecoder->checkRedundantPic();
}


// JVT-Q054 Red. Picture }

#ifdef SHARP_AVC_REWRITE_OUTPUT
bool
CreaterH264AVCDecoder::getAvcRewriteFlag()
{
	return m_pcH264AVCDecoder->xGetAvcRewriteFlag();
}

ErrVal
CreaterH264AVCDecoder::startAvcRewrite(UChar*& avcRewriteBinDataBuffer, BinData*& avcRewriteBinData, ExtBinDataAccessor* avcRewriteBinDataAccessor) {
	return m_pcH264AVCDecoder->xStartAvcRewrite(avcRewriteBinDataBuffer, avcRewriteBinData, avcRewriteBinDataAccessor);
}

ErrVal
CreaterH264AVCDecoder::closeAvcRewrite() {
	return m_pcH264AVCDecoder->xCloseAvcRewriteEncoder();

}
bool
CreaterH264AVCDecoder::writeAvcRewriteParameterSets(int nal_unit_type, UInt index) {

	return m_pcH264AVCDecoder->xWriteAvcRewriteParameterSets((NalUnitType)nal_unit_type, index);
}

#endif

H264AVC_NAMESPACE_END

⌨️ 快捷键说明

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