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

📄 sliceheaderbase.cpp

📁 jsvm开发代码包括抽样,编码,抽取,解码等一系列功能,可以做工具或研究用
💻 CPP
📖 第 1 页 / 共 5 页
字号:
  //JVT-Q054 Red. Picture }
  
	if( bL1InfoPresent )
  {
    RNOK(   pcReadIf->getFlag( m_bDirectSpatialMvPredFlag,                   "SH: direct_spatial_mv_pred_flag" ) );
  }

	if( bL0InfoPresent )
  {
    RNOK( pcReadIf->getFlag( m_bNumRefIdxActiveOverrideFlag,                 "SH: num_ref_idx_active_override_flag" ) );
    if( m_bNumRefIdxActiveOverrideFlag )
    {
      RNOK( pcReadIf->getUvlc( m_auiNumRefIdxActive[LIST_0],                 "SH: num_ref_idx_l0_active_minus1" ) );
      m_auiNumRefIdxActive[LIST_0]++;
	    if( bL1InfoPresent )
      {
        RNOK( pcReadIf->getUvlc( m_auiNumRefIdxActive[LIST_1],               "SH: num_ref_idx_l1_active_minus1" ) );
        m_auiNumRefIdxActive[LIST_1]++;
      }
    }
  }

	if( bL0InfoPresent )
  {
    RNOK( getRplrBuffer( LIST_0 ).read( pcReadIf, getNumRefIdxActive( LIST_0 ) ) );
  }

	if( bL1InfoPresent )
  {
    RNOK( getRplrBuffer( LIST_1 ).read( pcReadIf, getNumRefIdxActive( LIST_1 ) ) );
  }

  RNOK( m_acPredWeightTable[LIST_0].init( 64 ) );
  RNOK( m_acPredWeightTable[LIST_1].init( 64 ) );

  if( ( getPPS().getWeightedPredFlag ()      && ( m_eSliceType == P_SLICE ) ) ||
      ( getPPS().getWeightedBiPredIdc() == 1 && ( m_eSliceType == B_SLICE ) ) )
  {
    RNOK( pcReadIf->getUvlc( m_uiLumaLog2WeightDenom,                     "PWT: luma_log_weight_denom" ) );
    RNOK( pcReadIf->getUvlc( m_uiChromaLog2WeightDenom,                   "PWT: chroma_log_weight_denom" ) );
    ROTR( m_uiLumaLog2WeightDenom   > 7, Err::m_nInvalidParameter );
    ROTR( m_uiChromaLog2WeightDenom > 7, Err::m_nInvalidParameter );

    RNOK( m_acPredWeightTable[LIST_0].initDefaults( m_uiLumaLog2WeightDenom, m_uiChromaLog2WeightDenom ) );
    RNOK( m_acPredWeightTable[LIST_0].read( pcReadIf, getNumRefIdxActive( LIST_0 ) ) );
    if( m_eSliceType == B_SLICE )
    {
      RNOK( m_acPredWeightTable[LIST_1].initDefaults( m_uiLumaLog2WeightDenom, m_uiChromaLog2WeightDenom ) );
      RNOK( m_acPredWeightTable[LIST_1].read( pcReadIf, getNumRefIdxActive( LIST_1) ) );
    }
  }

  if( getNalRefIdc() )
  {
    if( isIdrNalUnit() )
    {
      RNOK( pcReadIf->getFlag( m_bNoOutputOfPriorPicsFlag,                   "DRPM: no_output_of_prior_pics_flag" ) );
      RNOK( pcReadIf->getFlag( bTmp,                                         "DRPM: long_term_reference_flag" ) );
      ROT ( bTmp );
    }
    else
    {
      RNOK( pcReadIf->getFlag( m_bAdaptiveRefPicBufferingModeFlag,           "DRPM: adaptive_ref_pic_buffering_mode_flag" ) );
      if( m_bAdaptiveRefPicBufferingModeFlag )
      {
        RNOK( getMmcoBuffer().read( pcReadIf ) );
      }
    }
  }

	if( getPPS().getEntropyCodingModeFlag() && bL0InfoPresent )
  {
    RNOK( pcReadIf->getUvlc( m_uiCabacInitIdc,                               "SH: cabac_init_idc" ) );
  }


  RNOK( pcReadIf->getSvlc( m_iSliceQpDelta,                                  "SH: slice_qp_delta" ) );
  
  if( getPPS().getDeblockingFilterParametersPresentFlag() )
  {
       RNOK( getDeblockingFilterParameterScalable().getDeblockingFilterParameter().read( pcReadIf, false ) ); //V032, added enhanced layer indicator "false"

  }

  //--ICU/ETRI FMO Implementation
  UInt uiSliceGroupChangeCycle;
  if( getPPS().getNumSliceGroupsMinus1()> 0  && getPPS().getSliceGroupMapType() >= 3  &&  getPPS().getSliceGroupMapType() <= 5)
  {
	  UInt pictureSizeInMB = getSPS().getFrameHeightInMbs()*getSPS().getFrameWidthInMbs();

	  RNOK(     pcReadIf->getCode( uiSliceGroupChangeCycle, getLog2MaxSliceGroupChangeCycle(pictureSizeInMB), "SH: slice_group_change_cycle" ) );
 
	   
	  setSliceGroupChangeCycle(uiSliceGroupChangeCycle);
  }

  return Err::m_nOK;
}



ErrVal
SliceHeaderBase::DeblockingFilterParameter::write( HeaderSymbolWriteIf* pcWriteIf, bool enhancedLayerFlag ) const //V032, added enhanced layer indicator

{
  //RNOK( pcWriteIf->writeUvlc( getDisableDeblockingFilterIdc(),  "SH: disable_deblocking_filter_idc" ) );

  //======The following code were added for V032=============
  //=======Start adding code for V032
  if (enhancedLayerFlag)  //for enhanced layer
	pcWriteIf->writeUvlc( getDisableDeblockingFilterIdc(),  "SH: disable_deblocking_filter_idc" ) ;
  else  //for base layer
  {
    if (3 == getDisableDeblockingFilterIdc())  //Disable chroma deblocking W.R.T. idc of 0 in base layer
	  pcWriteIf->writeUvlc( 0,  "SH: disable_deblocking_filter_idc" );
    else if (4 == getDisableDeblockingFilterIdc()) //Disable chroma deblocking W.R.T. idc of 2 in base layer
	  pcWriteIf->writeUvlc( 2,  "SH: disable_deblocking_filter_idc" );
	else  //normal values of idc, 0, 1, and 2
	  pcWriteIf->writeUvlc( getDisableDeblockingFilterIdc(),  "SH: disable_deblocking_filter_idc" );
  }
  //=======End adding code for V032=========================

  ROTRS( 1 == getDisableDeblockingFilterIdc(), Err::m_nOK );

  RNOK( pcWriteIf->writeSvlc( getSliceAlphaC0Offset() >> 1,     "SH: slice_alpha_c0_offset_div2" ) );
  RNOK( pcWriteIf->writeSvlc( getSliceBetaOffset() >> 1,        "SH: slice_beta_offset_div2" ) );
  return Err::m_nOK;
}



ErrVal
SliceHeaderBase::DeblockingFilterParameter::read( HeaderSymbolReadIf* pcReadIf, bool enhancedLayerFlag )  //V032, added enhanced layer indicator "false"
{
  RNOK( pcReadIf->getUvlc( m_uiDisableDeblockingFilterIdc,      "SH: disable_deblocking_filter_idc" ) );
  //ROT ( m_uiDisableDeblockingFilterIdc > 2 );
  ROT ( m_uiDisableDeblockingFilterIdc > 4 );      //V032 for extending Idc value to 3 and 4 w.r.t. 0 and 2 respectively
  ROT (!enhancedLayerFlag && (m_uiDisableDeblockingFilterIdc > 2) ); //V032, Idc should not be >2 for base layer

  ROTRS( 1 == getDisableDeblockingFilterIdc(), Err::m_nOK );

  Int iTmp;
  RNOK( pcReadIf->getSvlc( iTmp,                                "SH: slice_alpha_c0_offset_div2" ) );
  ROT( (iTmp < -6) || (iTmp >  6) );
  setSliceAlphaC0Offset( iTmp << 1);

  RNOK( pcReadIf->getSvlc( iTmp,                                "SH: slice_beta_offset_div2" ) );
  ROT( (iTmp < -6) || (iTmp >  6) );
  setSliceBetaOffset( iTmp << 1 );

  return Err::m_nOK;
}


//--ICU/ETRI FMO Implementation
ErrVal 
SliceHeaderBase::FMOInit()
{
		
	if(m_pcFMO == NULL)
		m_pcFMO = new FMO();
	else
	{
    //TMM_INTERLACE 
    FMOUninit(); 
    //--
		m_pcFMO = new FMO();
	}

	const SequenceParameterSet* pcSPS = &(getSPS());
	const PictureParameterSet* pcPPS = &(getPPS());

//TMM_INTERLACE {
  m_pcFMO->sps_.frame_mbs_only_flag            = pcSPS->getFrameMbsOnlyFlag(); 
	m_pcFMO->sps_.mb_adaptive_frame_field_flag   = pcSPS->getMbAdaptiveFrameFieldFlag(); 
  m_pcFMO->sps_.pic_height_in_map_units_minus1 = (pcSPS->getFrameMbsOnlyFlag()?pcSPS->getFrameHeightInMbs(): pcSPS->getFrameHeightInMbs()>>1)  -1;
	m_pcFMO->sps_.pic_width_in_mbs_minus1        =  pcSPS->getFrameWidthInMbs()-1;

  m_pcFMO->pps_.num_slice_groups_minus1 = pcPPS->getNumSliceGroupsMinus1();
	m_pcFMO->pps_.slice_group_map_type    = pcPPS->getSliceGroupMapType();
  m_pcFMO->pps_.num_slice_group_map_units_minus1 = pcPPS->getNumSliceGroupMapUnitsMinus1();	  
	m_pcFMO->pps_.copy_run_length_minus1(pcPPS->getArrayRunLengthMinus1());
	m_pcFMO->pps_.copy_top_left(pcPPS->getArrayTopLeft());
	m_pcFMO->pps_.copy_bottom_right(pcPPS->getArrayBottomRight());
	m_pcFMO->pps_.slice_group_change_direction_flag = pcPPS->getSliceGroupChangeDirection_flag();
	m_pcFMO->pps_.slice_group_change_rate_minus1    = pcPPS->getSliceGroupChangeRateMinus1();
	m_pcFMO->pps_.copy_slice_group_id(pcPPS->getArraySliceGroupId());

	m_pcFMO->img_.field_pic_flag      = getFieldPicFlag();
  m_pcFMO->img_.PicHeightInMapUnits = m_pcFMO->sps_.pic_height_in_map_units_minus1 + 1; 
	m_pcFMO->img_.PicWidthInMbs       = pcSPS->getFrameWidthInMbs();
	m_pcFMO->img_.PicSizeInMbs        = (pcSPS->getFrameHeightInMbs()>> (UChar)getFieldPicFlag())*pcSPS->getFrameWidthInMbs();
	m_pcFMO->img_.slice_group_change_cycle = getSliceGroupChangeCycle();
 //TMM_INTERLACE }

	m_pcFMO->init(&(m_pcFMO->pps_),&(m_pcFMO->sps_));

	m_pcFMO->StartPicture();

	return Err::m_nOK;
}

ErrVal 
SliceHeaderBase::FMOUninit()
{
  if(m_pcFMO)
  {
	  m_pcFMO->finit(); // Bug_fix memory leak
    delete m_pcFMO; m_pcFMO = NULL;
  }
		
	return Err::m_nOK;
}

Int SliceHeaderBase::getNumMbInSlice()
{  
	Int SliceID =m_pcFMO->getSliceGroupId(getFirstMbInSlice());
	return m_pcFMO->getNumMbInSliceGroup(SliceID);
}



//TMM_WP
ErrVal SliceHeaderBase::PredWeight::setPredWeightsAndFlags( const Int iLumaScale, 
                                                            const Int iChromaScale, 
                                                            const Double *pfWeight, 
                                                            Double fDiscardThr )
{
  const Double *pW = pfWeight;
  const Int iLScale = iLumaScale;
  const Int iCScale = iChromaScale;
  const Int iLumW = (Int)pW[0];
  const Int iCbW = (Int)pW[1];
  const Int iCrW = (Int)pW[2];

  RNOK( init( iLumW, iCbW, iCrW ) );

  setLumaWeightFlag  ( (iLumW != iLScale) );
  setChromaWeightFlag( (iCbW != iCScale) || (iCrW != iCScale) );

  return Err::m_nOK;
}

ErrVal SliceHeaderBase::PredWeight::getPredWeights( Double *afWeight)
{    
    afWeight[0] = (Double) getLumaWeight();
    afWeight[1] = (Double) getChromaWeight(0);
    afWeight[2] = (Double) getChromaWeight(1);
    
    return Err::m_nOK;
}

ErrVal SliceHeaderBase::PredWeightTable::setPredWeightsAndFlags( const Int iLumaScale, const Int iChromaScale, const Double(*pafWeight)[3], Double fDiscardThr )
{
  ROT( 0 == size() );

  for( UInt n = 0; n < size(); n++ )
  {
    RNOK( get(n).setPredWeightsAndFlags( iLumaScale, iChromaScale, pafWeight[n], fDiscardThr ) );
  }
  return Err::m_nOK;
}

ErrVal SliceHeaderBase::copyWeightedPred(PredWeightTable& pcPredWeightTable, UInt uiLumaLogWeightDenom,
                                         UInt uiChromaWeightDenom, ListIdx eListIdx, Bool bDecoder)
{
    m_uiLumaLog2WeightDenom = uiLumaLogWeightDenom;
    m_uiChromaLog2WeightDenom = uiChromaWeightDenom;
    Int iLumaScale = 1 << uiLumaLogWeightDenom;
    Int iChromaScale = 1 << uiChromaWeightDenom;
    Double afWeights[3];
    /* Disable this for now since offsets are not supported for SVC. Enabling this will result in mismatch*/ 
    //Double afOffsets[3];

    if(!bDecoder)
    {
        RNOK( getPredWeightTable(eListIdx).uninit() );
        RNOK( getPredWeightTable(eListIdx).init( getNumRefIdxActive( eListIdx) ) );
    }
        
    for( UInt n = 0; n < pcPredWeightTable.size(); n++ )
    {
        RNOK( pcPredWeightTable.get(n).getPredWeights( afWeights) );
        m_acPredWeightTable[eListIdx].get(n).setPredWeightsAndFlags( iLumaScale, iChromaScale, afWeights, false );

        /* Disable this for now since offsets are not supported for SVC. Enabling this will result in mismatch*/ 
//        RNOK( pcPredWeightTable.get(n).getOffsets( afOffsets) );
//        m_acPredWeightTable[eListIdx].get(n).setOffsets(afOffsets);
    }

    return Err::m_nOK;
}

ErrVal SliceHeaderBase::PredWeight::setOffsets( const Double *pfOffsets)
{
  const Double *pW = pfOffsets;

  const Int iLumO = (Int)pW[0];
  const Int iCbO = (Int)pW[1];
  const Int iCrO = (Int)pW[2];

  setLumaWeightFlag  ( (iLumO != 0) );
  setChromaWeightFlag( (iCbO != 0) || (iCrO != 0) );

  RNOK( initOffsets( iLumO, iCbO, iCrO ) );

  return Err::m_nOK;
}

ErrVal SliceHeaderBase::PredWeight::getOffsets( Double *afOffset)
{    
    afOffset[0] = (Double) getLumaOffset();
    afOffset[1] = (Double) getChromaOffset(0);
    afOffset[2] = (Double) getChromaOffset(1);
    
    return Err::m_nOK;
}

ErrVal SliceHeaderBase::PredWeightTable::setOffsets(  const Double(*pafOffsets)[3] )
{
  ROT( 0 == size() );

  for( UInt n = 0; 

⌨️ 快捷键说明

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