codingparameter.cpp

来自「SVC最新更新代码」· C++ 代码 · 共 970 行 · 第 1/4 页

CPP
970
字号
        pauiSGMap[ iY * uiMapWidth + iX ] = iGroup0;
      }
    }
    //----- set ROI map -----
    UInt uiROIId = MSYS_UINT_MAX;
    for( Int iGroup = 0; iGroup <= (Int)m_uiNumSliceGroupsMinus1; iGroup++ )
    {
      UInt uiNumMb = 0;
      for( UInt uiIdx = 0; uiIdx < uiMapSize; uiIdx++ )
      {
        if( pauiSGMap[uiIdx] == iGroup )
        {
          if( uiNumMb == 0 )
          {
            uiROIId++;
            pauiROIFirstMB[uiROIId] = uiIdx;
          }
          pauiROILastMB   [uiROIId] = uiIdx;
          pauiROIMap      [uiIdx]   = uiROIId;
          if( ++uiNumMb == uiMaxSliceSize )
          {
            uiNumMb = 0;
          }
        }
      }
    }
    UInt  uiNumROI      = uiROIId + 1;
    Bool  bRectangular  = true;
    Bool  bSameSize     = true;
    //----- check ROI map and set sizes -----
    for( uiROIId = 0; uiROIId < uiNumROI; uiROIId++ )
    {
      Int iY0 = pauiROIFirstMB[ uiROIId ] / uiMapWidth;
      Int iX0 = pauiROIFirstMB[ uiROIId ] % uiMapWidth;
      Int iY1 = pauiROILastMB [ uiROIId ] / uiMapWidth;
      Int iX1 = pauiROILastMB [ uiROIId ] % uiMapWidth;
      for( Int iY = 0; iY < (Int)uiMapHeight; iY++ )
      for( Int iX = 0; iX < (Int)uiMapWidth;  iX++ )
      {
        Bool bInside = ( iY >= iY0 && iY <= iY1 && iX >= iX0 && iX <= iX1 );
        Bool bMatch  = ( pauiROIMap[ iY * uiMapWidth + iX ] == uiROIId );
        if( ( bInside && ! bMatch ) || ( !bInside && bMatch ) )
        {
          bRectangular = false;
        }
      }
      pauiROIWidth [uiROIId] = iX1 - iX0 + 1;
      pauiROIHeight[uiROIId] = iY1 - iY0 + 1;
      if( uiROIId > 0 && bSameSize )
      {
        if( pauiROIWidth[uiROIId] != pauiROIWidth[0] || pauiROIHeight[uiROIId] != pauiROIHeight[0] )
        {
          bSameSize = false;
        }
      }
    }
    //----- set ROI parameters -----
    if( bRectangular )
    {
      m_bSliceDivisionFlag  = true;
      m_bGridFlag           = bSameSize;
      m_uiNumSliceMinus1    = uiNumROI - 1;
      // alloc arrays
      if (m_puiGridSliceWidthInMbsMinus1 != NULL)
        free(m_puiGridSliceWidthInMbsMinus1);
      m_puiGridSliceWidthInMbsMinus1 = (UInt*)malloc((m_uiNumSliceMinus1+1)*sizeof(UInt));
      if (m_puiGridSliceHeightInMbsMinus1 != NULL)
        free(m_puiGridSliceHeightInMbsMinus1);
      m_puiGridSliceHeightInMbsMinus1 = (UInt*)malloc((m_uiNumSliceMinus1+1)*sizeof(UInt));
      if (m_puiFirstMbInSlice != NULL)
        free(m_puiFirstMbInSlice);
      m_puiFirstMbInSlice = (UInt*)malloc((m_uiNumSliceMinus1+1)*sizeof(UInt));
      if (m_puiLastMbInSlice != NULL)
        free(m_puiLastMbInSlice);
      m_puiLastMbInSlice = (UInt*)malloc((m_uiNumSliceMinus1+1)*sizeof(UInt));
      if (m_puiSliceId != NULL)
        free(m_puiSliceId);
      m_puiSliceId = (UInt*)malloc(uiMapSize*sizeof(UInt));
      // set data and output some info
      UInt uiMBCount  = 0;
      printf("Layer%2d: %d IROI's with IROI grid flag = %d\n", m_uiLayerId, uiNumROI, m_bGridFlag );
      for( UInt uiSliceNum = 0; uiSliceNum < uiNumROI; uiSliceNum++ )
      {
        printf("\tROI%2d:  W =%3d,  H =%3d,  FirstMb = %d\n", uiSliceNum, pauiROIWidth[uiSliceNum], pauiROIHeight[uiSliceNum], pauiROIFirstMB[uiSliceNum] );
        m_puiGridSliceWidthInMbsMinus1  [uiSliceNum] = pauiROIWidth  [ uiSliceNum ] - 1;
        m_puiGridSliceHeightInMbsMinus1 [uiSliceNum] = pauiROIHeight [ uiSliceNum ] - 1;
        m_puiFirstMbInSlice             [uiSliceNum] = pauiROIFirstMB[ uiSliceNum ];
        m_puiLastMbInSlice              [uiSliceNum] = pauiROILastMB [ uiSliceNum ];
        UInt uiMBAddr   = m_puiFirstMbInSlice[uiSliceNum];
        for( UInt i = 0; i <= m_puiGridSliceHeightInMbsMinus1[uiSliceNum]; i++, uiMBAddr += uiMapWidth )
        {
          for( UInt j = 0; j <= m_puiGridSliceWidthInMbsMinus1[uiSliceNum]; j++, uiMBCount++)
          {
            m_puiSliceId[uiMBAddr+j] = uiSliceNum;
          }
        }
      }
      ROF( uiMBCount == uiMapSize );
      printf("\n\n");
    }
    //----- delete temporary arrays -----
    delete [] pauiSGMap;
    delete [] pauiROIMap;
    delete [] pauiROIFirstMB;
    delete [] pauiROILastMB;
    delete [] pauiROIWidth;
    delete [] pauiROIHeight;
  }

  //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( getEnable8x8Trafo        ()  > 1,              "The value for Enable8x8Transform is not supported" );
    ROTREPORT( getScalingMatricesPresent()  > 1,              "The value for ScalingMatricesPresent is not supported" );
    ROTREPORT( getBiPred8x8Disable      ()  > 1,              "The value for BiPredLT8x8Disable is not supported" );
    ROTREPORT( getMCBlks8x8Disable      ()  > 1,              "The value for MCBlocksLT8x8Disable is 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( getNumberOfLayers() == 0, "Number of layer must be greate than 0" );
  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 );
  }

  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 );
  Double  dMinUnrstrDelay = Double( ( 1 << m_uiDecompositionStages ) - 1 ) / m_dMaximumFrameRate * 1000.0;

  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" );

    if( pcLayer->getUseLongTerm() && m_dMaximumDelay < dMinUnrstrDelay )
    {
      fprintf( stderr, "\nWARNING: The usage of long term pictures for"
                       "\n         a delay of less than %.2lf ms might"
                       "\n         result in non-conforming DPB behaviour"
                       "\n         for temporal sub-streams\n\n", dMinUnrstrDelay );
    }

⌨️ 快捷键说明

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