codingparameter.cpp

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

CPP
970
字号
    pcLayer->setNotCodedStages      ( uiLogFactorInOutRate );
    pcLayer->setTemporalResolution  ( uiLogFactorMaxInRate );
    pcLayer->setDecompositionStages ( getDecompositionStages() - uiLogFactorMaxInRate );
    pcLayer->setFrameDelay          ( uiMaxFrameDelay );
    if( ( uiMaxFrameDelay >> ( uiLogFactorMaxInRate + uiLogFactorInOutRate ) ) == 0 || ( getDecompositionStages() - uiLogFactorMaxInRate - uiLogFactorInOutRate ) == 0 )
    {
      pcLayer->setPicCodingType( 1 );
    }
    if( pcLayer->getPicCodingType() == 1 )
    {
      pcLayer->setBiPred8x8Disable( 1 );
    }
    if( uiBaseLayerId != MSYS_UINT_MAX )
    {
      ROTREPORT( pcLayer->getPicCodingType() == 1 && pcBaseLayer->getPicCodingType() != 1, "DisableBSlices must be equal to 0 when it is equal to 0 for the bse layer" );
    }

    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->getFrameWidthInSamples () != pcBaseLayer->getFrameWidthInSamples () || 
                               pcLayer->getFrameHeightInSamples() != pcBaseLayer->getFrameHeightInSamples();
      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( m_uiCGSSNRRefinementFlag && !bResolutionChange && pcLayer->getPicCodingType() != pcBaseLayer->getPicCodingType(),
        "DisableBSlices shall be the same in successive MGS layers" );

      ROTREPORT( m_uiCGSSNRRefinementFlag && !bResolutionChange && pcLayer->getUseLongTerm() != pcBaseLayer->getUseLongTerm(),
        "UseLongTerm shall be the same in successive MGS layers" );

      ROTREPORT( pcLayer->getFrameWidthInSamples ()  < pcBaseLayer->getFrameWidthInSamples (), "Frame width  less than base layer frame width" );
      ROTREPORT( pcLayer->getFrameHeightInSamples()  < pcBaseLayer->getFrameHeightInSamples(), "Frame height less than base layer frame height" );
      UInt uiLogFactorWidth  = getLogFactor( pcBaseLayer->getFrameWidthInSamples (), pcLayer->getFrameWidthInSamples () );
     
      pcLayer->setBaseLayerSpatRes( uiLogFactorWidth );
			
      ResizeParameters& rcRP = pcLayer->getResizeParameters();
      if( rcRP.m_iExtendedSpatialScalability != ESS_NONE )
      {
        Bool  bI    = pcLayer->isInterlaced();
        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->setSliceSkipTLevelStart( pcLayer->getSliceSkip() - 1 );
        if( 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 shall not exceed 15." );

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

  RNOK( xCheckAndSetProfiles() );

  return Err::m_nOK;
}


ErrVal
CodingParameter::xCheckAndSetProfiles()
{
  for( UInt uiLayer = 0; uiLayer < m_uiNumberOfLayers; uiLayer++ )
  {
    RNOK( m_acLayerParameters[uiLayer].setAndCheckProfile( this ) );
  }
  return Err::m_nOK;
}

ErrVal
LayerParameters::setAndCheckProfile( CodingParameter* pcCodingParameter )
{
  ROF( pcCodingParameter );

  Bool  bSVCLayersPresent     = ( pcCodingParameter->getNumberOfLayers() > 1 );
  Bool  bScalBaselineRequired = false;
  Bool  bScalHighRequired     = false;
  for( UInt uiTestLayer = m_uiLayerId + 1; uiTestLayer < pcCodingParameter->getNumberOfLayers(); uiTestLayer++ )
  {
    if( pcCodingParameter->getLayerParameters( uiTestLayer ).getProfileIdc() == SCALABLE_BASELINE_PROFILE )
    {
      bScalBaselineRequired = true;
    }
    if( pcCodingParameter->getLayerParameters( uiTestLayer ).getProfileIdc() == SCALABLE_HIGH_PROFILE )
    {
      bScalHighRequired     = true;
    }
  }

  //===== BASE LAYER =====
  if ( m_uiLayerId == 0 )
  {
    ROTREPORT( m_uiProfileIdc != BASELINE_PROFILE &&
               m_uiProfileIdc != MAIN_PROFILE     &&
               m_uiProfileIdc != EXTENDED_PROFILE &&
               m_uiProfileIdc != HIGH_PROFILE     &&
               m_uiProfileIdc != 0, "Unsupported ProfileIdc in base layer" );
    //----- try to force compatibility when required -----
    Bool  bForceBaseline    = ( m_uiProfileIdc == BASELINE_PROFILE || bScalBaselineRequired );
    Bool  bForceMain        = ( m_uiProfileIdc == MAIN_PROFILE     || bScalBaselineRequired );
    Bool  bForceExtended    = ( m_uiProfileIdc == EXTENDED_PROFILE || bScalBaselineRequired );
    Bool  bForceHigh        = ( m_uiProfileIdc == HIGH_PROFILE     || bSVCLayersPresent     );
    if(   bForceBaseline )  RNOK( xForceBaselineProfile ( pcCodingParameter ) );
    if(   bForceMain     )  RNOK( xForceMainProfile     ( pcCodingParameter ) );
    if(   bForceExtended )  RNOK( xForceExtendedProfile ( pcCodingParameter ) );
    if(   bForceHigh     )  RNOK( xForceHighProfile     ( pcCodingParameter ) );
    //----- check compatibility -----
    Bool  bBaseline         = xIsBaselineProfile          ( pcCodingParameter );
    Bool  bMain             = xIsMainProfile              ( pcCodingParameter );
    Bool  bExtended         = xIsExtendedProfile          ( pcCodingParameter );
    Bool  bHigh             = xIsHighProfile              ( pcCodingParameter );
    Bool  bIntraOnly        = xIsIntraOnly                ( pcCodingParameter );
    ROT(  bForceBaseline  && !bBaseline );
    ROT(  bForceMain      && !bMain     );
    ROT(  bForceExtended  && !bExtended );
    ROT(  bForceHigh      && !bHigh     );
    //----- set parameters -----
    if( m_uiProfileIdc == 0)
    {
      m_uiProfileIdc        = ( bBaseline ? BASELINE_PROFILE : bMain ? MAIN_PROFILE : bExtended ? EXTENDED_PROFILE : bHigh ? HIGH_PROFILE : 0 );
      ROTREPORT( m_uiProfileIdc == 0, "No profile found for given configuration parameters" );
    }
    m_bIntraOnly            = bIntraOnly;
    m_bConstrainedSetFlag0  = bBaseline;
    m_bConstrainedSetFlag1  = bMain;
    m_bConstrainedSetFlag2  = bExtended;
    m_bConstrainedSetFlag3  = ( bHigh && bIntraOnly );
    m_uiNumDependentDId     = 1;
    m_uiLevelIdc            = 0;
    //----- update IDR period -----
    if( bIntraOnly )
    {
      m_iIDRPeriod          = pcCodingParameter->getGOPSize();
    }
    return Err::m_nOK;
  }

  //===== ENHANCEMENT LAYER =====
  ROTREPORT( m_uiProfileIdc != SCALABLE_BASELINE_PROFILE &&
             m_uiProfileIdc != SCALABLE_HIGH_PROFILE     &&
             m_uiProfileIdc != 0, "Unsupported ProfileIdc in enhancement layer" );
  //----- try to force compatibility when required -----
  Bool  bForceScalBase    = ( m_uiProfileIdc == SCALABLE_BASELINE_PROFILE || bScalBaselineRequired );
  Bool  bForceScalHigh    = ( m_uiProfileIdc == SCALABLE_HIGH_PROFILE     || bScalHighRequired     );
  if(   bForceScalBase )  RNOK( xForceScalableBaselineProfile ( pcCodingParameter ) );
  if(   bForceScalHigh )  RNOK( xForceScalableHighProfile     ( pcCodingParameter ) );
  //----- check compatibility -----
  Bool  bScalBase         = xIsScalableBaselineProfile          ( pcCodingParameter );
  Bool  bScalHigh         = xIsScalableHighProfile              ( pcCodingParameter );
  Bool  bIntraOnly        = xIsIntraOnly                        ( pcCodingParameter );
  ROT(  bForceScalBase  && !bScalBase );
  ROT(  bForceScalHigh  && !bScalHigh );
  //----- set parameters -----
  if( m_uiProfileIdc == 0)
  {
    m_uiProfileIdc        = ( bScalBase ? SCALABLE_BASELINE_PROFILE : bScalHigh ? SCALABLE_HIGH_PROFILE : 0 );
    ROTREPORT( m_uiProfileIdc == 0, "No profile found for given configuration parameters" );
  }
  m_bIntraOnly            = bIntraOnly;
  m_bConstrainedSetFlag0  = bScalBase;
  m_bConstrainedSetFlag1  = bScalHigh;
  m_bConstrainedSetFlag2  = false;
  m_bConstrainedSetFlag3  = ( bScalHigh && bIntraOnly );
  m_uiNumDependentDId     = 1;
  m_uiLevelIdc            = 0;
  if( m_uiBaseLayerId != MSYS_UINT_MAX )
  {
    if( pcCodingParameter->getLayerParameters( m_uiBaseLayerId ).m_uiLayerCGSSNR == m_uiLayerCGSSNR )
    {
      m_uiNumDependentDId = 0;
    }
    m_uiNumDependentDId  += pcCodingParameter->getLayerParameters( m_uiBaseLayerId ).m_uiNumDependentDId;
    ROTREPORT( m_uiNumDependentDId > 3, "At most 3 dependent dependency layers are supported in SVC" );
  }
  //----- update picture coding type -----
  if( m_uiBaseLayerId != MSYS_UINT_MAX && m_uiPicCodingType == 0 && pcCodingParameter->getLayerParameters( m_uiBaseLayerId ).getPicCodingType() != 0 )
  {
    m_uiPicCodingType     = 2;
  }
  //----- update IDR period -----
  if( bIntraOnly )
  {
    m_iIDRPeriod          = pcCodingParameter->getGOPSize();
  }
  return Err::m_nOK;
}

ErrVal
LayerParameters::updateWithLevel( CodingParameter* pcCodingParameter, UInt& ruiLevelIdc )
{
  if( m_uiBaseLayerId != MSYS_UINT_MAX )
  {
    UInt uiBaseLevel  = pcCodingParameter->getLayerParameters( m_uiBaseLayerId ).getLevelIdc();
    ROF( uiBaseLevel );
    ruiLevelIdc       = max( ruiLevelIdc, uiBaseLevel );
  }
  switch( m_uiProfileIdc )
  {
  case MAIN_PROFILE:
  case EXTENDED_PROFILE:

⌨️ 快捷键说明

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