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

📄 codingparameter.cpp

📁 JVT-Z203_jsvm.rar
💻 CPP
📖 第 1 页 / 共 2 页
字号:
      m_puiFirstMbInSlice[uiSliceId] = m_puiFirstMbInSlice[uiSliceId-uiNumSlicePerHeight] + m_uiRunLengthMinus1[i-1] + 1;
      m_puiLastMbInSlice[uiSliceId] = m_puiFirstMbInSlice[uiSliceId] + m_puiGridSliceHeightInMbsMinus1[uiSliceId]*uiFrameWidthInMbs + m_puiGridSliceWidthInMbsMinus1[uiSliceId];
      uiSliceId += uiNumSlicePerHeight;
    }
    uiSliceId = 0;
    for (i=0; i<=m_uiNumSliceGroupsMinus1; i++)
    {
      uiSliceId++;
      for (j=1; j<uiNumSlicePerHeight; j++, uiSliceId++)
      {
        m_puiGridSliceWidthInMbsMinus1[uiSliceId] = m_puiGridSliceWidthInMbsMinus1[uiSliceId-1];
        m_puiGridSliceHeightInMbsMinus1[uiSliceId] = m_uiSliceArgument-1;
        if ( j == (uiNumSlicePerHeight-1) )
          m_puiGridSliceHeightInMbsMinus1[uiSliceId] = (m_uiFrameHeight>>4) - (j*m_uiSliceArgument) - 1;

        m_puiFirstMbInSlice[uiSliceId] = m_puiFirstMbInSlice[uiSliceId-1] + m_uiSliceArgument*uiFrameWidthInMbs;
        m_puiLastMbInSlice[uiSliceId] = m_puiFirstMbInSlice[uiSliceId] + m_puiGridSliceHeightInMbsMinus1[uiSliceId]*uiFrameWidthInMbs + m_puiGridSliceWidthInMbsMinus1[uiSliceId];
      }
    }
    // Debug
    if (uiSliceId != (m_uiNumSliceMinus1+1))
    {
      printf("IROI error\n");
      m_bSliceDivisionFlag = false;
      return Err::m_nOK;
    }

    uiMBCount = 0;
    for (uiSliceId = 0; uiSliceId <= m_uiNumSliceMinus1; uiSliceId++)
    {
      uiMBAddr = m_puiFirstMbInSlice[uiSliceId];
      for (i = 0; i <= m_puiGridSliceHeightInMbsMinus1[uiSliceId]; i++, uiMBAddr+=uiFrameWidthInMbs)
      {
        for (j = 0; j <= m_puiGridSliceWidthInMbsMinus1[uiSliceId]; j++, uiMBCount++)
        {
          m_puiSliceId[uiMBAddr+j] = uiSliceId;
        }
      }
    }
    // Debug
    if (uiMBCount != uiFrameSizeInMbs)
    {
      printf("IROI error\n");
      m_bSliceDivisionFlag = false;
      return Err::m_nOK;
    }


    // Display slice division info.
    //printf("IROI: Slice Division Type %d, Num Slice %d\n", m_uiSliceDivisionType, m_uiNumSliceMinus1+1);//SEI changes update
		printf("IROI: Iroi Grid Flag %d, Num Slice %d\n", m_bGridFlag, m_uiNumSliceMinus1+1);//SEI changes update
    //for (i=0; i<=m_uiNumSliceMinus1; i++)
    //{
    //  printf("(%d, %d, %d, %d, %d)\n", i, m_puiGridSliceWidthInMbsMinus1[i], m_puiGridSliceHeightInMbsMinus1[i], m_puiFirstMbInSlice[i], m_puiLastMbInSlice[i]);
    //}
  }
  // JVT-S054 (ADD) <-

  //S051{
  ROTREPORT( getAnaSIP	()>0 && getEncSIP(),			"Unsupported SIP mode\n"); 
  //S051}

  return Err::m_nOK;
}


UInt CodingParameter::getLogFactor( Double r0, Double r1 )
{
  Double dLog2Factor  = log10( r1 / r0 ) / log10( 2.0 );
  Double dRound       = floor( dLog2Factor + 0.5 );
  Double dEpsilon     = 0.0001;

  if( dLog2Factor-dEpsilon < dRound && dRound < dLog2Factor+dEpsilon )
  {
    return (UInt)(dRound);
  }
  return MSYS_UINT_MAX;
}



ErrVal CodingParameter::check()
{
  ROTS( m_cLoopFilterParams           .check() );
  ROTS( m_cInterLayerLoopFilterParams .check() );
  ROTS( m_cMotionVectorSearchParams   .check() );

  if( getAVCmode() )
  {
    Bool bStringNotOk = SequenceStructure::checkString( getSequenceFormatString() ); 

    //===== coder is operated in MVC mode =====
    ROTREPORT( getFrameWidth        () <= 0 ||
               getFrameWidth        ()  % 16,             "Frame Width  must be greater than 0 and a multiple of 16" );
    ROTREPORT( getFrameHeight       () <= 0 ||
               getFrameHeight       ()  % 16,             "Frame Height must be greater than 0 and a multiple of 16" );
    ROTREPORT( getMaximumFrameRate  () <= 0.0,            "Frame rate not supported" );
    ROTREPORT( getTotalFrames       () == 0,              "Total Number Of Frames must be greater than 0" );
    ROTREPORT( getSymbolMode        ()  > 1,              "Symbol mode not supported" );
    ROTREPORT( get8x8Mode           ()  > 2,              "FRExt mode not supported" );
    ROTREPORT( getDPBSize           () == 0,              "DPBSize must be greater than 0" );
    ROTREPORT( getNumDPBRefFrames   () == 0 ||
               getNumDPBRefFrames   ()  > getDPBSize(),   "NumRefFrames must be greater than 0 and must not be greater than DPB size" );
    ROTREPORT( getLog2MaxFrameNum   ()  < 4 ||
               getLog2MaxFrameNum   ()  > 16,             "Log2MaxFrameNum must be in the range of [4..16]" );
    ROTREPORT( getLog2MaxPocLsb     ()  < 4 ||
               getLog2MaxPocLsb     ()  > 15,             "Log2MaxFrameNum must be in the range of [4..15]" );
    ROTREPORT( bStringNotOk,                              "Unvalid SequenceFormatString" );
    ROTREPORT( getMaxRefIdxActiveBL0() <= 0 ||
               getMaxRefIdxActiveBL0()  > 15,             "Unvalid value for MaxRefIdxActiveBL0" );
    ROTREPORT( getMaxRefIdxActiveBL1() <= 0 ||
               getMaxRefIdxActiveBL1()  > 15,             "Unvalid value for MaxRefIdxActiveBL1" );
    ROTREPORT( getMaxRefIdxActiveP  () <= 0 ||
               getMaxRefIdxActiveP  ()  > 15,             "Unvalid value for MaxRefIdxActiveP" );

    return Err::m_nOK;
  }

  ROTREPORT( getMaximumFrameRate() <= 0.0,              "Maximum frame rate not supported" );
  ROTREPORT( getMaximumDelay    ()  < 0.0,              "Maximum delay must be greater than or equal to 0" );
  ROTREPORT( getTotalFrames     () == 0,                "Total Number Of Frames must be greater than 0" );

  ROTREPORT( getGOPSize         ()  < 1  ||
             getGOPSize         ()  > 64,               "GOP Size not supported" );
  UInt uiDecStages = getLogFactor( 1.0, getGOPSize() );
  ROTREPORT( uiDecStages == MSYS_UINT_MAX,              "GOP Size must be a power of 2" );
  setDecompositionStages( uiDecStages );

  ROTREPORT( getIntraPeriod     ()  <
             getGOPSize         (),                     "Intra period must be greater or equal to GOP size" );
  if( getIntraPeriod() == MSYS_UINT_MAX )
  {
    setIntraPeriodLowPass( MSYS_UINT_MAX );
  }
  else
  {
    UInt uiIntraPeriod = getIntraPeriod() / getGOPSize() - 1;
    ROTREPORT( getIntraPeriod() % getGOPSize(),         "Intra period must be a power of 2 of GOP size (or -1)" );
    setIntraPeriodLowPass( uiIntraPeriod );
  }

	//JVT-X046 {
  ROTREPORT(   m_uiSliceMode < 0 || m_uiSliceMode > 2 || 
	  (m_uiSliceMode==1)&&(m_uiSliceArgument <= 0) || (m_uiSliceMode==2)&&(m_uiSliceArgument <= 0)
	  , "Unvalid value for SliceMode or SliceArgument" );
  //JVT-X046 }
  ROTREPORT( getNumRefFrames    ()  < 1  ||
             getNumRefFrames    ()  > 15,               "Number of reference frames not supported" );
  ROTREPORT( getBaseLayerMode   ()  > 2,                "Base layer mode not supported" );
  ROTREPORT( getNumberOfLayers  ()  > MAX_LAYERS,       "Number of layers not supported" );

  if( m_uiCIUFlag )
  {
    UInt uiILFIdc = m_cInterLayerLoopFilterParams.getFilterIdc();
    ROTREPORT( uiILFIdc != 1 && uiILFIdc != 2 && uiILFIdc != 5, "Inter-layer deblocking filter idc not supported for constrained intra upsampling" );
  }

  ROTREPORT( m_uiEncodeKeyPictures    > 2,          "Key picture mode not supported" );
  ROTREPORT( m_uiMGSKeyPictureControl > 2,          "Unsupported value for MGSControl" );
  ROTREPORT( m_uiMGSKeyPictureControl &&
            !m_uiCGSSNRRefinementFlag,              "MGSControl can only be specified in connection with CGSSNRRefinementFlag=1" );

  Double  dMaxFrameDelay  = max( 0, m_dMaximumFrameRate * m_dMaximumDelay / 1000.0 );
  UInt    uiMaxFrameDelay = (UInt)floor( dMaxFrameDelay );

  for( UInt uiLayer = 0; uiLayer < getNumberOfLayers(); uiLayer++ )
  {
    LayerParameters*  pcLayer               = &m_acLayerParameters[uiLayer];

	  RNOK( pcLayer->check() );

    UInt              uiBaseLayerId         = uiLayer && pcLayer->getBaseLayerId() != MSYS_UINT_MAX ? pcLayer->getBaseLayerId() : MSYS_UINT_MAX;
    LayerParameters*  pcBaseLayer           = uiBaseLayerId != MSYS_UINT_MAX ? &m_acLayerParameters[uiBaseLayerId] : 0;
    UInt              uiLogFactorInOutRate  = getLogFactor( pcLayer->getOutputFrameRate (), pcLayer->getInputFrameRate() );
    UInt              uiLogFactorMaxInRate  = getLogFactor( pcLayer->getInputFrameRate  (), getMaximumFrameRate       () );

    // heiko.schwarz@hhi.fhg.de: add some additional check for input/output frame rates
    ROTREPORT( pcLayer->getInputFrameRate() < pcLayer->getOutputFrameRate(),  "Input frame rate must not be less than output frame rate" );
    ROTREPORT( pcLayer->getInputFrameRate() > getMaximumFrameRate(),          "Input frame rate must not be greater than maximum frame rate" );
    ROTREPORT( getDecompositionStages() < uiLogFactorMaxInRate + uiLogFactorInOutRate, "Number of decomposition stages is too small for the specified output rate" );

    ROTREPORT( uiLogFactorInOutRate == MSYS_UINT_MAX,   "Input frame rate must be a power of 2 of output frame rate" );
    ROTREPORT( uiLogFactorMaxInRate == MSYS_UINT_MAX,   "Maximum frame rate must be a power of 2 of input frame rate" );

    pcLayer->setNotCodedStages      ( uiLogFactorInOutRate );
    pcLayer->setTemporalResolution  ( uiLogFactorMaxInRate );
    pcLayer->setDecompositionStages ( getDecompositionStages() - uiLogFactorMaxInRate );
    pcLayer->setFrameDelay          ( uiMaxFrameDelay  /  ( 1 << uiLogFactorMaxInRate ) );

    Bool bMGSVectorUsed = pcLayer->getMGSVect( 0 ) != 16;
    if( bMGSVectorUsed )
    {
      ROTREPORT( !getCGSSNRRefinement(), "MGS vectors are only supported in MGS." );
      ROTREPORT( !pcBaseLayer,           "MGS vectors are not allowed in the base layer." );
    }

    ROTREPORT( ! pcBaseLayer && pcLayer->getSliceSkip(), "Slice skip only supported in enhancement layers" );

    if( pcBaseLayer )
    {
      Bool bResolutionChange = pcLayer->getFrameWidth () != pcBaseLayer->getFrameWidth() || 
                               pcLayer->getFrameHeight() != pcBaseLayer->getFrameHeight();
      ROTREPORT( bResolutionChange && pcLayer->getMGSVect(0) != 16, "Base layer and current layer must have the same resolution when MGS vectors are used in the current layer." );
      ROTREPORT( pcLayer->getInputFrameRate() < pcBaseLayer->getInputFrameRate(), "Input frame rate less than base layer output frame rate" );
      UInt uiLogFactorRate = getLogFactor( pcBaseLayer->getInputFrameRate(), pcLayer->getInputFrameRate() );
      ROTREPORT( uiLogFactorRate == MSYS_UINT_MAX, "Input Frame rate must be a power of 2 from layer to layer" );
      pcLayer->setBaseLayerTempRes( uiLogFactorRate );

      ROTREPORT( pcLayer->getFrameWidth ()  < pcBaseLayer->getFrameWidth (), "Frame width  less than base layer frame width" );
      ROTREPORT( pcLayer->getFrameHeight()  < pcBaseLayer->getFrameHeight(), "Frame height less than base layer frame height" );
      UInt uiLogFactorWidth  = getLogFactor( pcBaseLayer->getFrameWidth (), pcLayer->getFrameWidth () );
     
      pcLayer->setBaseLayerSpatRes( uiLogFactorWidth );
			
      ResizeParameters& rcRP = pcLayer->getResizeParameters();
      if( rcRP.m_iExtendedSpatialScalability != ESS_NONE )
      {
        Bool  bI    = ( pcLayer->getMbAff() || pcLayer->getPAff() );
        Int   iV    = ( bI ? 4 : 2 );
        Int   iL    = rcRP.m_iLeftFrmOffset;
        Int   iT    = rcRP.m_iTopFrmOffset;
        Int   iR    = rcRP.m_iFrameWidth  - rcRP.m_iScaledRefFrmWidth  - iL;
        Int   iB    = rcRP.m_iFrameHeight - rcRP.m_iScaledRefFrmHeight - iT;
        Bool  bHor  = ( iL %  2 != 0 || iR %  2 != 0 );
        Bool  bVer  = ( iT % iV != 0 || iB % iV != 0 );
        ROTREPORT( bHor,        "Cropping window must be horizonzally aligned on a 2 pixel grid" );
        ROTREPORT( bVer && !bI, "Cropping window must be vertically aligned on a 2 pixel grid" );
        ROTREPORT( bVer &&  bI, "Cropping window must be vertically aligned on a 4 pixel grid for interlaced configurations" );
      }

      pcBaseLayer->setContrainedIntraForLP();

      if( pcLayer->getSliceSkip() && pcLayer->getSliceSkipTLevelStart() == 0 )
      {
        pcLayer->setContrainedIntraForLP();
      }

      if( pcLayer->getTCoeffLevelPredictionFlag() )
      {
        Bool bSpatial = pcLayer->getResizeParameters().getSpatialResolutionChangeFlag();
        ROTREPORT( bSpatial,              "AVCRewriteFlag cannot be equal to 1 for a spatial enhancement layer" );
        ROTREPORT( m_uiEncodeKeyPictures, "Key pictures are not supported in connection with AVCRewriteFlag" );
      }
    }
    if( pcLayer->getTCoeffLevelPredictionFlag() )
    {
      pcLayer->setContrainedIntraForLP();
      pcLayer->setInterLayerPredictionMode( pcLayer->getInterLayerPredictionMode() > 0 ? 2 : 0 );
    }

    ROTREPORT( pcLayer->getBaseQualityLevel() > 15, "Base quality level may not exceed 15." );

    if( uiLayer == 0 && pcLayer->getBaseQualityLevel() != 0 )
    {
      pcLayer->setBaseQualityLevel(0);
    }
  }

  return Err::m_nOK;
}



H264AVC_NAMESPACE_END

⌨️ 快捷键说明

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