Changeset 189 in SHVCSoftware for trunk/source/Lib/TLibEncoder/TEncGOP.cpp


Ignore:
Timestamp:
13 May 2013, 16:58:44 (12 years ago)
Author:
seregin
Message:

merge with SHM-2.0-dev branch

Location:
trunk/source
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/source

  • trunk/source/Lib/TLibEncoder/TEncGOP.cpp

    r125 r189  
    9696#if L0045_NON_NESTED_SEI_RESTRICTIONS
    9797  xResetNonNestedSEIPresentFlags();
     98#if K0180_SCALABLE_NESTING_SEI
     99  xResetNestedSEIPresentFlags();
     100#endif
    98101#endif
    99102#if SVC_UPSAMPLING
     
    134137  m_pcSliceEncoder       = pcTEncTop->getSliceEncoder();
    135138  m_pcListPic            = pcTEncTop->getListPic(); 
     139 
    136140  m_pcEntropyCoder       = pcTEncTop->getEntropyCoder();
    137141  m_pcCavlcCoder         = pcTEncTop->getCavlcCoder();
     
    210214}
    211215
     216#if J0149_TONE_MAPPING_SEI
     217SEIToneMappingInfo*  TEncGOP::xCreateSEIToneMappingInfo()
     218{
     219  SEIToneMappingInfo *seiToneMappingInfo = new SEIToneMappingInfo();
     220  seiToneMappingInfo->m_toneMapId = m_pcCfg->getTMISEIToneMapId();
     221  seiToneMappingInfo->m_toneMapCancelFlag = m_pcCfg->getTMISEIToneMapCancelFlag();
     222  seiToneMappingInfo->m_toneMapPersistenceFlag = m_pcCfg->getTMISEIToneMapPersistenceFlag();
     223
     224  seiToneMappingInfo->m_codedDataBitDepth = m_pcCfg->getTMISEICodedDataBitDepth();
     225  assert(seiToneMappingInfo->m_codedDataBitDepth >= 8 && seiToneMappingInfo->m_codedDataBitDepth <= 14);
     226  seiToneMappingInfo->m_targetBitDepth = m_pcCfg->getTMISEITargetBitDepth();
     227  assert( (seiToneMappingInfo->m_targetBitDepth >= 1 && seiToneMappingInfo->m_targetBitDepth <= 17) || (seiToneMappingInfo->m_targetBitDepth  == 255) );
     228  seiToneMappingInfo->m_modelId = m_pcCfg->getTMISEIModelID();
     229  assert(seiToneMappingInfo->m_modelId >=0 &&seiToneMappingInfo->m_modelId<=4);
     230
     231  switch( seiToneMappingInfo->m_modelId)
     232  {
     233  case 0:
     234    {
     235      seiToneMappingInfo->m_minValue = m_pcCfg->getTMISEIMinValue();
     236      seiToneMappingInfo->m_maxValue = m_pcCfg->getTMISEIMaxValue();
     237      break;
     238    }
     239  case 1:
     240    {
     241      seiToneMappingInfo->m_sigmoidMidpoint = m_pcCfg->getTMISEISigmoidMidpoint();
     242      seiToneMappingInfo->m_sigmoidWidth = m_pcCfg->getTMISEISigmoidWidth();
     243      break;
     244    }
     245  case 2:
     246    {
     247      UInt num = 1u<<(seiToneMappingInfo->m_targetBitDepth);
     248      seiToneMappingInfo->m_startOfCodedInterval.resize(num);
     249      Int* ptmp = m_pcCfg->getTMISEIStartOfCodedInterva();
     250      if(ptmp)
     251      {
     252        for(int i=0; i<num;i++)
     253        {
     254          seiToneMappingInfo->m_startOfCodedInterval[i] = ptmp[i];
     255        }
     256      }
     257      break;
     258    }
     259  case 3:
     260    {
     261      seiToneMappingInfo->m_numPivots = m_pcCfg->getTMISEINumPivots();
     262      seiToneMappingInfo->m_codedPivotValue.resize(seiToneMappingInfo->m_numPivots);
     263      seiToneMappingInfo->m_targetPivotValue.resize(seiToneMappingInfo->m_numPivots);
     264      Int* ptmpcoded = m_pcCfg->getTMISEICodedPivotValue();
     265      Int* ptmptarget = m_pcCfg->getTMISEITargetPivotValue();
     266      if(ptmpcoded&&ptmptarget)
     267      {
     268        for(int i=0; i<(seiToneMappingInfo->m_numPivots);i++)
     269        {
     270          seiToneMappingInfo->m_codedPivotValue[i]=ptmpcoded[i];
     271          seiToneMappingInfo->m_targetPivotValue[i]=ptmptarget[i];
     272         }
     273       }
     274       break;
     275     }
     276  case 4:
     277     {
     278       seiToneMappingInfo->m_cameraIsoSpeedIdc = m_pcCfg->getTMISEICameraIsoSpeedIdc();
     279       seiToneMappingInfo->m_cameraIsoSpeedValue = m_pcCfg->getTMISEICameraIsoSpeedValue();
     280       assert( seiToneMappingInfo->m_cameraIsoSpeedValue !=0 );
     281       seiToneMappingInfo->m_exposureCompensationValueSignFlag = m_pcCfg->getTMISEIExposureCompensationValueSignFlag();
     282       seiToneMappingInfo->m_exposureCompensationValueNumerator = m_pcCfg->getTMISEIExposureCompensationValueNumerator();
     283       seiToneMappingInfo->m_exposureCompensationValueDenomIdc = m_pcCfg->getTMISEIExposureCompensationValueDenomIdc();
     284       seiToneMappingInfo->m_refScreenLuminanceWhite = m_pcCfg->getTMISEIRefScreenLuminanceWhite();
     285       seiToneMappingInfo->m_extendedRangeWhiteLevel = m_pcCfg->getTMISEIExtendedRangeWhiteLevel();
     286       assert( seiToneMappingInfo->m_extendedRangeWhiteLevel >= 100 );
     287       seiToneMappingInfo->m_nominalBlackLevelLumaCodeValue = m_pcCfg->getTMISEINominalBlackLevelLumaCodeValue();
     288       seiToneMappingInfo->m_nominalWhiteLevelLumaCodeValue = m_pcCfg->getTMISEINominalWhiteLevelLumaCodeValue();
     289       assert( seiToneMappingInfo->m_nominalWhiteLevelLumaCodeValue > seiToneMappingInfo->m_nominalBlackLevelLumaCodeValue );
     290       seiToneMappingInfo->m_extendedWhiteLevelLumaCodeValue = m_pcCfg->getTMISEIExtendedWhiteLevelLumaCodeValue();
     291       assert( seiToneMappingInfo->m_extendedWhiteLevelLumaCodeValue >= seiToneMappingInfo->m_nominalWhiteLevelLumaCodeValue );
     292       break;
     293    }
     294  default:
     295    {
     296      assert(!"Undefined SEIToneMapModelId");
     297      break;
     298    }
     299  }
     300  return seiToneMappingInfo;
     301}
     302#endif
    212303Void TEncGOP::xCreateLeadingSEIMessages (/*SEIMessages seiMessages,*/ AccessUnit &accessUnit, TComSPS *sps)
    213304{
    214   OutputNALUnit nalu(NAL_UNIT_SEI);
     305  OutputNALUnit nalu(NAL_UNIT_PREFIX_SEI);
    215306
    216307  if(m_pcCfg->getActiveParameterSetsSEIEnabled())
     
    233324    SEIFramePacking *sei = xCreateSEIFramePacking ();
    234325
    235     nalu = NALUnit(NAL_UNIT_SEI);
     326    nalu = NALUnit(NAL_UNIT_PREFIX_SEI);
    236327    m_pcEntropyCoder->setBitstream(&nalu.m_Bitstream);
    237328    m_seiWriter.writeSEImessage(nalu.m_Bitstream, *sei, sps);
     
    244335    SEIDisplayOrientation *sei = xCreateSEIDisplayOrientation();
    245336
    246     nalu = NALUnit(NAL_UNIT_SEI);
     337    nalu = NALUnit(NAL_UNIT_PREFIX_SEI);
    247338    m_pcEntropyCoder->setBitstream(&nalu.m_Bitstream);
    248339    m_seiWriter.writeSEImessage(nalu.m_Bitstream, *sei, sps);
     
    251342    delete sei;
    252343  }
     344#if J0149_TONE_MAPPING_SEI
     345  if(m_pcCfg->getToneMappingInfoSEIEnabled())
     346  {
     347    SEIToneMappingInfo *sei = xCreateSEIToneMappingInfo ();
     348     
     349    nalu = NALUnit(NAL_UNIT_PREFIX_SEI);
     350    m_pcEntropyCoder->setBitstream(&nalu.m_Bitstream);
     351    m_seiWriter.writeSEImessage(nalu.m_Bitstream, *sei, sps);
     352    writeRBSPTrailingBits(nalu.m_Bitstream);
     353    accessUnit.push_back(new NALUnitEBSP(nalu));
     354    delete sei;
     355  }
     356#endif
    253357}
    254358
     
    276380  m_iNumPicCoded = 0;
    277381  SEIPictureTiming pictureTimingSEI;
     382#if L0208_SOP_DESCRIPTION_SEI
     383  Bool writeSOP = m_pcCfg->getSOPDescriptionSEIEnabled();
     384#endif
     385#if K0180_SCALABLE_NESTING_SEI
     386  // Initialize Scalable Nesting SEI with single layer values
     387  SEIScalableNesting scalableNestingSEI;
     388  scalableNestingSEI.m_bitStreamSubsetFlag           = 1;      // If the nested SEI messages are picture buffereing SEI mesages, picure timing SEI messages or sub-picture timing SEI messages, bitstream_subset_flag shall be equal to 1
     389  scalableNestingSEI.m_nestingOpFlag                 = 0;
     390  scalableNestingSEI.m_nestingNumOpsMinus1           = 0;      //nesting_num_ops_minus1
     391  scalableNestingSEI.m_allLayersFlag                 = 0;
     392  scalableNestingSEI.m_nestingNoOpMaxTemporalIdPlus1 = 6 + 1;  //nesting_no_op_max_temporal_id_plus1
     393  scalableNestingSEI.m_nestingNumLayersMinus1        = 1 - 1;  //nesting_num_layers_minus1
     394  scalableNestingSEI.m_nestingLayerId[0]             = 0;
     395  scalableNestingSEI.m_callerOwnsSEIs                = true;
     396#endif
    278397#if L0044_DU_DPB_OUTPUT_DELAY_HRD
    279398  Int picSptDpbOutputDuDelay = 0;
     
    348467    }
    349468
    350     if( getNalUnitType(pocCurr) == NAL_UNIT_CODED_SLICE_IDR || getNalUnitType(pocCurr) == NAL_UNIT_CODED_SLICE_IDR_N_LP )
     469    if( getNalUnitType(pocCurr, m_iLastIDR) == NAL_UNIT_CODED_SLICE_IDR_W_RADL || getNalUnitType(pocCurr, m_iLastIDR) == NAL_UNIT_CODED_SLICE_IDR_N_LP )
    351470    {
    352471      m_iLastIDR = pocCurr;
     
    364483#if SVC_EXTENSION
    365484    pcPic->setLayerId( m_layerId );
    366 #endif
    367 
     485    m_pcSliceEncoder->initEncSlice ( pcPic, iPOCLast, pocCurr, iNumPicRcvd, iGOPid, pcSlice, m_pcEncTop->getSPS(), m_pcEncTop->getPPS(), m_pcEncTop->getVPS() );
     486#else
    368487    m_pcSliceEncoder->initEncSlice ( pcPic, iPOCLast, pocCurr, iNumPicRcvd, iGOPid, pcSlice, m_pcEncTop->getSPS(), m_pcEncTop->getPPS() );
     488#endif
    369489    pcSlice->setLastIDR(m_iLastIDR);
    370490    pcSlice->setSliceIdx(0);
     
    411531    }
    412532    // Set the nal unit type
    413     pcSlice->setNalUnitType(getNalUnitType(pocCurr));
     533    pcSlice->setNalUnitType(getNalUnitType(pocCurr, m_iLastIDR));
    414534#if IDR_ALIGNMENT
    415535    if (m_layerId > 0)
    416536    {
     537#if VPS_EXTN_DIRECT_REF_LAYERS_CONTINUE
     538      TComList<TComPic*> *cListPic = m_ppcTEncTop[m_layerId]->getRefLayerEnc(m_layerId)->getListPic();
     539#else
    417540      TComList<TComPic*> *cListPic = m_ppcTEncTop[m_layerId-1]->getListPic();
     541#endif
    418542      pcSlice->setBaseColPic (*cListPic, m_layerId );
    419543    }
     
    424548    {
    425549#if IDR_ALIGNMENT
    426       if( pcSlice->getBaseColPic()->getSlice(0)->getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR )
    427       {
    428         pcSlice->setNalUnitType(NAL_UNIT_CODED_SLICE_IDR);
     550      if( pcSlice->getBaseColPic()->getSlice(0)->getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_W_RADL || pcSlice->getBaseColPic()->getSlice(0)->getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_N_LP )
     551      {
     552        pcSlice->setNalUnitType(pcSlice->getBaseColPic()->getSlice(0)->getNalUnitType());
    429553      }
    430554      else
     
    432556      pcSlice->setNalUnitType(NAL_UNIT_CODED_SLICE_CRA);
    433557    }
     558#if ZERO_NUM_DIRECT_LAYERS
     559    if( m_layerId > 0 && pcSlice->getActiveNumILRRefIdx() == 0 && pcSlice->getNalUnitType() >= NAL_UNIT_CODED_SLICE_BLA_W_LP && pcSlice->getNalUnitType() <= NAL_UNIT_CODED_SLICE_CRA )
     560    {
     561      pcSlice->setSliceType(I_SLICE);
     562    }
     563    else
     564#endif
    434565    if( m_layerId > 0 && !m_pcEncTop->getElRapSliceTypeB() )
    435566    {
    436       if( (pcSlice->getNalUnitType() >= NAL_UNIT_CODED_SLICE_BLA) &&
     567      if( (pcSlice->getNalUnitType() >= NAL_UNIT_CODED_SLICE_BLA_W_LP) &&
    437568          (pcSlice->getNalUnitType() <= NAL_UNIT_CODED_SLICE_CRA) &&
    438569           pcSlice->getSliceType() == B_SLICE )
     
    442573    }
    443574#endif
    444     if(pcSlice->getNalUnitType()==NAL_UNIT_CODED_SLICE_TRAIL_R)
    445     {
    446       if(pcSlice->getTemporalLayerNonReferenceFlag())
     575    if(pcSlice->getTemporalLayerNonReferenceFlag())
     576    {
     577      if(pcSlice->getNalUnitType()==NAL_UNIT_CODED_SLICE_TRAIL_R)
    447578      {
    448579        pcSlice->setNalUnitType(NAL_UNIT_CODED_SLICE_TRAIL_N);
     580    }
     581      if(pcSlice->getNalUnitType()==NAL_UNIT_CODED_SLICE_RADL_R)
     582      {
     583        pcSlice->setNalUnitType(NAL_UNIT_CODED_SLICE_RADL_N);
     584      }
     585      if(pcSlice->getNalUnitType()==NAL_UNIT_CODED_SLICE_RASL_R)
     586      {
     587        pcSlice->setNalUnitType(NAL_UNIT_CODED_SLICE_RASL_N);
    449588      }
    450589    }
     
    471610        else
    472611        {
    473           pcSlice->setNalUnitType(NAL_UNIT_CODED_SLICE_TLA);
     612          pcSlice->setNalUnitType(NAL_UNIT_CODED_SLICE_TLA_R);
    474613        }
    475614      }
     
    524663    pcSlice->setNumRefIdx(REF_PIC_LIST_1,min(m_pcCfg->getGOPEntry(iGOPid).m_numRefPicsActive,pcSlice->getRPS()->getNumberOfPictures()));
    525664
    526 #if REF_LIST_BUGFIX
     665#if REF_IDX_FRAMEWORK
     666#if ZERO_NUM_DIRECT_LAYERS
     667    if( m_layerId > 0 && pcSlice->getActiveNumILRRefIdx() )
     668#else
    527669    if(m_layerId > 0)
    528     {
    529       if( pcSlice->getNalUnitType() >= NAL_UNIT_CODED_SLICE_BLA && pcSlice->getNalUnitType() <= NAL_UNIT_CODED_SLICE_CRA )
     670#endif
     671    {
     672#if JCTVC_M0458_INTERLAYER_RPS_SIG
     673      if( pcSlice->getNalUnitType() >= NAL_UNIT_CODED_SLICE_BLA_W_LP && pcSlice->getNalUnitType() <= NAL_UNIT_CODED_SLICE_CRA )
     674      {
     675        pcSlice->setNumRefIdx(REF_PIC_LIST_0, pcSlice->getActiveNumILRRefIdx());
     676        pcSlice->setNumRefIdx(REF_PIC_LIST_1, pcSlice->getActiveNumILRRefIdx());
     677      }
     678      else
     679      {
     680        pcSlice->setNumRefIdx(REF_PIC_LIST_0, pcSlice->getNumRefIdx(REF_PIC_LIST_0)+pcSlice->getActiveNumILRRefIdx());
     681        pcSlice->setNumRefIdx(REF_PIC_LIST_1, pcSlice->getNumRefIdx(REF_PIC_LIST_1)+pcSlice->getActiveNumILRRefIdx());
     682      }
     683#else
     684      if( pcSlice->getNalUnitType() >= NAL_UNIT_CODED_SLICE_BLA_W_LP && pcSlice->getNalUnitType() <= NAL_UNIT_CODED_SLICE_CRA )
    530685      {
    531686        pcSlice->setNumRefIdx(REF_PIC_LIST_0, pcSlice->getNumILRRefIdx());
     
    537692        pcSlice->setNumRefIdx(REF_PIC_LIST_1, pcSlice->getNumRefIdx(REF_PIC_LIST_1)+pcSlice->getNumILRRefIdx());
    538693      }
     694#endif
    539695    }
    540696#endif
     
    545701
    546702#if SVC_EXTENSION     
     703#if ZERO_NUM_DIRECT_LAYERS
     704    if( m_layerId > 0 && pcSlice->getActiveNumILRRefIdx() )
     705#else
    547706    if(m_layerId > 0)
     707#endif
    548708    {
    549709#if !IDR_ALIGNMENT
     
    553713#if SVC_UPSAMPLING
    554714      if ( pcPic->isSpatialEnhLayer())
    555       {   
     715      {
     716#if SCALED_REF_LAYER_OFFSETS
     717        m_pcPredSearch->upsampleBasePic( pcPic->getFullPelBaseRec(), pcSlice->getBaseColPic()->getPicYuvRec(), pcPic->getPicYuvRec(), pcSlice->getSPS()->getScaledRefLayerWindow() );
     718#else
    556719        m_pcPredSearch->upsampleBasePic( pcPic->getFullPelBaseRec(), pcSlice->getBaseColPic()->getPicYuvRec(), pcPic->getPicYuvRec() );
     720#endif
    557721      }
    558722      else
     
    573737
    574738    //  Set reference list
    575 #if REF_LIST_BUGFIX
     739#if REF_IDX_FRAMEWORK
     740#if ZERO_NUM_DIRECT_LAYERS
     741    if(m_layerId ==  0 || ( m_layerId > 0 && pcSlice->getActiveNumILRRefIdx() == 0 ) )
     742#else
    576743    if(m_layerId ==  0)
     744#endif
    577745    {
    578746      pcSlice->setRefPicList( rcListPic);
     
    582750#endif
    583751#if REF_IDX_FRAMEWORK
     752#if ZERO_NUM_DIRECT_LAYERS
     753    if( m_layerId > 0 && pcSlice->getActiveNumILRRefIdx() )
     754#else
    584755    if(m_layerId > 0)
     756#endif
    585757    {
    586758      m_pcEncTop->setILRPic(pcPic);
     
    592764      }
    593765#endif
    594 #if REF_LIST_BUGFIX
    595766      pcSlice->setRefPicListModificationSvc();
    596       pcSlice->setRefPicListSvc( rcListPic, m_pcEncTop->getIlpList() );
    597 #else
    598       pcSlice->addRefPicList ( m_pcEncTop->getIlpList(), 1);
    599 #endif
     767      pcSlice->setRefPicList( rcListPic, false, m_pcEncTop->getIlpList());
    600768
    601769#if REF_IDX_MFM
     
    607775        for(Int colIdx = 0; colIdx < pcSlice->getNumRefIdx( RefPicList(1 - ColFromL0Flag) ); colIdx++)
    608776        {
    609           if( pcSlice->getRefPic( RefPicList(1 - ColFromL0Flag), colIdx)->isILR() )
     777          if( pcSlice->getRefPic( RefPicList(1 - ColFromL0Flag), colIdx)->isILR(m_layerId) )
    610778          {
    611779            ColRefIdx = colIdx;
     
    620788          for(Int colIdx = 0; colIdx < pcSlice->getNumRefIdx( RefPicList(1 - ColFromL0Flag) ); colIdx++)
    621789          {
    622             if( pcSlice->getRefPic( RefPicList(1 - ColFromL0Flag), colIdx)->isILR() )
     790            if( pcSlice->getRefPic( RefPicList(1 - ColFromL0Flag), colIdx)->isILR(m_layerId) )
    623791            {
    624792              ColRefIdx = colIdx;
     
    644812      pcSlice->setSliceType ( P_SLICE );
    645813    }
    646 
     814#if !L0034_COMBINED_LIST_CLEANUP
    647815    if (pcSlice->getSliceType() != B_SLICE || !pcSlice->getSPS()->getUseLComb())
    648816    {
     
    656824      pcSlice->setNumRefIdx(REF_PIC_LIST_C, pcSlice->getNumRefIdx(REF_PIC_LIST_0));
    657825    }
     826#endif
    658827
    659828    if (pcSlice->getSliceType() == B_SLICE)
     
    683852      pcSlice->setCheckLDC(bLowDelay); 
    684853    }
     854    else
     855    {
     856      pcSlice->setCheckLDC(true); 
     857    }
    685858
    686859    uiColDir = 1-uiColDir;
     
    689862    pcSlice->setRefPOCList();
    690863
     864#if L0034_COMBINED_LIST_CLEANUP
     865    pcSlice->setList1IdxToList0Idx();
     866#else
    691867    pcSlice->setNoBackPredFlag( false );
    692868    if ( pcSlice->getSliceType() == B_SLICE && !pcSlice->getRefPicListCombinationFlag())
     
    712888    }
    713889    pcSlice->generateCombinedList();
     890#endif
    714891
    715892    if (m_pcEncTop->getTMVPModeId() == 2)
     
    8311008    UInt uiNumSlices = 1;
    8321009
     1010#if SIMPLIFIED_MV_POS_SCALING
     1011    if (m_layerId > 0)
     1012    {
     1013#if SCALED_REF_LAYER_OFFSETS
     1014      const Window &scalEL = m_pcEncTop->getScaledRefLayerWindow();
     1015
     1016      Int widthBL   = pcSlice->getBaseColPic()->getPicYuvRec()->getWidth();
     1017      Int heightBL  = pcSlice->getBaseColPic()->getPicYuvRec()->getHeight();
     1018
     1019      Int widthEL   = pcPic->getPicYuvRec()->getWidth()  - scalEL.getWindowLeftOffset() - scalEL.getWindowRightOffset();
     1020      Int heightEL  = pcPic->getPicYuvRec()->getHeight() - scalEL.getWindowTopOffset()  - scalEL.getWindowBottomOffset();
     1021#else
     1022      const Window &confBL = pcSlice->getBaseColPic()->getPicYuvRec()->getConformanceWindow();
     1023      const Window &confEL = pcPic->getPicYuvRec()->getConformanceWindow();
     1024
     1025      Int widthBL   = pcSlice->getBaseColPic()->getPicYuvRec()->getWidth () - confBL.getWindowLeftOffset() - confBL.getWindowRightOffset();
     1026      Int heightBL  = pcSlice->getBaseColPic()->getPicYuvRec()->getHeight() - confBL.getWindowTopOffset() - confBL.getWindowBottomOffset();
     1027
     1028      Int widthEL   = pcPic->getPicYuvRec()->getWidth() - confEL.getWindowLeftOffset() - confEL.getWindowRightOffset();
     1029      Int heightEL  = pcPic->getPicYuvRec()->getHeight() - confEL.getWindowTopOffset() - confEL.getWindowBottomOffset();
     1030#endif
     1031      g_mvScalingFactor[m_layerId][0] = Clip3(-4096, 4095, ((widthEL  << 8) + (widthBL  >> 1)) / widthBL);
     1032      g_mvScalingFactor[m_layerId][1] = Clip3(-4096, 4095, ((heightEL << 8) + (heightBL >> 1)) / heightBL);
     1033
     1034      g_posScalingFactor[m_layerId][0] = ((widthBL  << 16) + (widthEL  >> 1)) / widthEL;
     1035      g_posScalingFactor[m_layerId][1] = ((heightBL << 16) + (heightEL >> 1)) / heightEL;
     1036    }
     1037#endif
     1038
    8331039    UInt uiInternalAddress = pcPic->getNumPartInCU()-4;
    8341040    UInt uiExternalAddress = pcPic->getPicSym()->getNumberOfCUsInFrame()-1;
     
    9491155    startCUAddrSliceSegmentIdx++;
    9501156#if AVC_BASE
    951     if( m_layerId == 0 )
     1157    if( m_layerId == 0 && m_pcEncTop->getVPS()->getAvcBaseLayerFlag() )
    9521158    {
    9531159      pcPic->getPicYuvOrg()->copyToPic( pcPic->getPicYuvRec() );
     
    10271233    Bool bLFCrossTileBoundary = pcSlice->getPPS()->getLoopFilterAcrossTilesEnabledFlag();
    10281234    m_pcLoopFilter->setCfg(bLFCrossTileBoundary);
     1235#if L0386_DB_METRIC
     1236    if ( m_pcCfg->getDeblockingFilterMetric() )
     1237    {
     1238      dblMetric(pcPic, uiNumSlices);
     1239    }
     1240#endif
    10291241    m_pcLoopFilter->loopFilterPic( pcPic );
    10301242
     
    10591271      OutputNALUnit nalu(NAL_UNIT_VPS, 0, m_layerId);
    10601272#if AVC_BASE
    1061       if( m_layerId == 1 )
     1273      if( ( m_layerId == 1 && m_pcEncTop->getVPS()->getAvcBaseLayerFlag() ) || ( m_layerId == 0 && !m_pcEncTop->getVPS()->getAvcBaseLayerFlag() ) )
    10621274#else
    10631275      if( m_layerId == 0 )
     
    11331345    }
    11341346
     1347#if L0208_SOP_DESCRIPTION_SEI
     1348    if (writeSOP) // write SOP description SEI (if enabled) at the beginning of GOP
     1349    {
     1350      Int SOPcurrPOC = pocCurr;
     1351
     1352      OutputNALUnit nalu(NAL_UNIT_PREFIX_SEI);
     1353      m_pcEntropyCoder->setEntropyCoder(m_pcCavlcCoder, pcSlice);
     1354      m_pcEntropyCoder->setBitstream(&nalu.m_Bitstream);
     1355
     1356      SEISOPDescription SOPDescriptionSEI;
     1357      SOPDescriptionSEI.m_sopSeqParameterSetId = pcSlice->getSPS()->getSPSId();
     1358
     1359      UInt i = 0;
     1360      UInt prevEntryId = iGOPid;
     1361      for (j = iGOPid; j < m_iGopSize; j++)
     1362      {
     1363        Int deltaPOC = m_pcCfg->getGOPEntry(j).m_POC - m_pcCfg->getGOPEntry(prevEntryId).m_POC;
     1364        if ((SOPcurrPOC + deltaPOC) < m_pcCfg->getFramesToBeEncoded())
     1365        {
     1366          SOPcurrPOC += deltaPOC;
     1367          SOPDescriptionSEI.m_sopDescVclNaluType[i] = getNalUnitType(SOPcurrPOC, m_iLastIDR);
     1368          SOPDescriptionSEI.m_sopDescTemporalId[i] = m_pcCfg->getGOPEntry(j).m_temporalId;
     1369          SOPDescriptionSEI.m_sopDescStRpsIdx[i] = m_pcEncTop->getReferencePictureSetIdxForSOP(pcSlice, SOPcurrPOC, j);
     1370          SOPDescriptionSEI.m_sopDescPocDelta[i] = deltaPOC;
     1371
     1372          prevEntryId = j;
     1373          i++;
     1374        }
     1375      }
     1376
     1377      SOPDescriptionSEI.m_numPicsInSopMinus1 = i - 1;
     1378
     1379      m_seiWriter.writeSEImessage( nalu.m_Bitstream, SOPDescriptionSEI, pcSlice->getSPS());
     1380      writeRBSPTrailingBits(nalu.m_Bitstream);
     1381      accessUnit.push_back(new NALUnitEBSP(nalu));
     1382
     1383      writeSOP = false;
     1384    }
     1385#endif
     1386
    11351387    if( ( m_pcCfg->getPictureTimingSEIEnabled() || m_pcCfg->getDecodingUnitInfoSEIEnabled() ) &&
    11361388        ( pcSlice->getSPS()->getVuiParametersPresentFlag() ) &&
     
    11781430       || ( pcSlice->getSPS()->getVuiParameters()->getHrdParameters()->getVclHrdParametersPresentFlag() ) ) )
    11791431    {
    1180       OutputNALUnit nalu(NAL_UNIT_SEI);
     1432      OutputNALUnit nalu(NAL_UNIT_PREFIX_SEI);
    11811433      m_pcEntropyCoder->setEntropyCoder(m_pcCavlcCoder, pcSlice);
    11821434      m_pcEntropyCoder->setBitstream(&nalu.m_Bitstream);
     
    12191471      writeRBSPTrailingBits(nalu.m_Bitstream);
    12201472#if L0045_NON_NESTED_SEI_RESTRICTIONS
     1473      {
    12211474      UInt seiPositionInAu = xGetFirstSeiLocation(accessUnit);
    12221475      UInt offsetPosition = m_activeParameterSetSEIPresentInAU;   // Insert BP SEI after APS SEI
     
    12281481      accessUnit.insert(it, new NALUnitEBSP(nalu));
    12291482      m_bufferingPeriodSEIPresentInAU = true;
     1483      }
    12301484#else
    12311485      accessUnit.push_back(new NALUnitEBSP(nalu));
     1486#endif
     1487
     1488#if K0180_SCALABLE_NESTING_SEI
     1489      if (m_pcCfg->getScalableNestingSEIEnabled())
     1490      {
     1491        OutputNALUnit naluTmp(NAL_UNIT_PREFIX_SEI);
     1492        m_pcEntropyCoder->setEntropyCoder(m_pcCavlcCoder, pcSlice);
     1493        m_pcEntropyCoder->setBitstream(&naluTmp.m_Bitstream);
     1494        scalableNestingSEI.m_nestedSEIs.clear();
     1495        scalableNestingSEI.m_nestedSEIs.push_back(&sei_buffering_period);
     1496        m_seiWriter.writeSEImessage( naluTmp.m_Bitstream, scalableNestingSEI, pcSlice->getSPS());
     1497        writeRBSPTrailingBits(naluTmp.m_Bitstream);
     1498#if L0045_NON_NESTED_SEI_RESTRICTIONS
     1499        UInt seiPositionInAu = xGetFirstSeiLocation(accessUnit);
     1500        UInt offsetPosition = m_activeParameterSetSEIPresentInAU + m_bufferingPeriodSEIPresentInAU + m_pictureTimingSEIPresentInAU;   // Insert BP SEI after non-nested APS, BP and PT SEIs
     1501        AccessUnit::iterator it;
     1502        for(j = 0, it = accessUnit.begin(); j < seiPositionInAu + offsetPosition; j++)
     1503        {
     1504          it++;
     1505        }
     1506        accessUnit.insert(it, new NALUnitEBSP(naluTmp));
     1507        m_nestedBufferingPeriodSEIPresentInAU = true;
     1508#else
     1509        accessUnit.push_back(new NALUnitEBSP(naluTmp));
     1510#endif
     1511      }
    12321512#endif
    12331513
     
    12411521      {
    12421522        // Gradual decoding refresh SEI
    1243         OutputNALUnit nalu(NAL_UNIT_SEI);
     1523        OutputNALUnit nalu(NAL_UNIT_PREFIX_SEI);
    12441524        m_pcEntropyCoder->setEntropyCoder(m_pcCavlcCoder, pcSlice);
    12451525        m_pcEntropyCoder->setBitstream(&nalu.m_Bitstream);
     
    12531533      }
    12541534    // Recovery point SEI
    1255       OutputNALUnit nalu(NAL_UNIT_SEI);
     1535      OutputNALUnit nalu(NAL_UNIT_PREFIX_SEI);
    12561536      m_pcEntropyCoder->setEntropyCoder(m_pcCavlcCoder, pcSlice);
    12571537      m_pcEntropyCoder->setBitstream(&nalu.m_Bitstream);
     
    14441724
    14451725          pcSlice->setTileOffstForMultES( uiOneBitstreamPerSliceLength );
    1446           if (!sliceSegment)
    1447           {
    14481726            pcSlice->setTileLocationCount ( 0 );
    1449             m_pcSliceEncoder->encodeSlice(pcPic, pcBitstreamRedirect, pcSubstreamsOut); // redirect is only used for CAVLC tile position info.
    1450           }
    1451           else
    1452           {
    1453             m_pcSliceEncoder->encodeSlice(pcPic, &nalu.m_Bitstream, pcSubstreamsOut); // nalu.m_Bitstream is only used for CAVLC tile position info.
    1454           }
     1727          m_pcSliceEncoder->encodeSlice(pcPic, pcSubstreamsOut);
    14551728
    14561729          {
     
    14841757              if (ui+1 < pcSlice->getPPS()->getNumSubstreams())
    14851758              {
    1486                 puiSubstreamSizes[ui] = pcSubstreamsOut[ui].getNumberOfWrittenBits();
     1759                puiSubstreamSizes[ui] = pcSubstreamsOut[ui].getNumberOfWrittenBits() + (pcSubstreamsOut[ui].countStartCodeEmulations()<<3);
    14871760              }
    14881761            }
     
    15161789          // If current NALU is the last NALU of slice and a NALU was buffered, then (a) Write current NALU (b) Update an write buffered NALU at approproate location in NALU list.
    15171790          Bool bNALUAlignedWrittenToList    = false; // used to ensure current NALU is not written more than once to the NALU list.
    1518           xWriteTileLocationToSliceHeader(nalu, pcBitstreamRedirect, pcSlice);
     1791          xAttachSliceDataToNalUnit(nalu, pcBitstreamRedirect);
    15191792          accessUnit.push_back(new NALUnitEBSP(nalu));
    15201793#if RATE_CONTROL_LAMBDA_DOMAIN
     
    15441817            {
    15451818              UInt numRBSPBytes_nal = UInt((*it)->m_nalUnitData.str().size());
    1546               if ((*it)->m_nalUnitType != NAL_UNIT_SEI && (*it)->m_nalUnitType != NAL_UNIT_SEI_SUFFIX)
     1819              if ((*it)->m_nalUnitType != NAL_UNIT_PREFIX_SEI && (*it)->m_nalUnitType != NAL_UNIT_SUFFIX_SEI)
    15471820              {
    15481821                numRBSPBytes += numRBSPBytes_nal;
     
    16401913        }
    16411914#if SVC_EXTENSION
    1642         OutputNALUnit nalu(NAL_UNIT_SEI_SUFFIX, pcSlice->getTLayer(), m_layerId);
    1643 #else
    1644         OutputNALUnit nalu(NAL_UNIT_SEI_SUFFIX, pcSlice->getTLayer());
     1915        OutputNALUnit nalu(NAL_UNIT_SUFFIX_SEI, pcSlice->getTLayer(), m_layerId);
     1916#else
     1917        OutputNALUnit nalu(NAL_UNIT_SUFFIX_SEI, pcSlice->getTLayer());
    16451918#endif
    16461919
     
    16671940        sei_temporal_level0_index.rapIdx = m_rapIdx;
    16681941
    1669         OutputNALUnit nalu(NAL_UNIT_SEI);
     1942        OutputNALUnit nalu(NAL_UNIT_PREFIX_SEI);
    16701943
    16711944        /* write the SEI messages */
     
    18072080        if( m_pcCfg->getPictureTimingSEIEnabled() )
    18082081        {
    1809           OutputNALUnit nalu(NAL_UNIT_SEI, pcSlice->getTLayer());
     2082          {
     2083            OutputNALUnit nalu(NAL_UNIT_PREFIX_SEI, pcSlice->getTLayer());
    18102084          m_pcEntropyCoder->setEntropyCoder(m_pcCavlcCoder, pcSlice);
    18112085          m_seiWriter.writeSEImessage(nalu.m_Bitstream, pictureTimingSEI, pcSlice->getSPS());
     
    18272101#endif
    18282102        }
     2103#if K0180_SCALABLE_NESTING_SEI
     2104          if ( m_pcCfg->getScalableNestingSEIEnabled() ) // put picture timing SEI into scalable nesting SEI
     2105          {
     2106            OutputNALUnit nalu(NAL_UNIT_PREFIX_SEI, pcSlice->getTLayer());
     2107            m_pcEntropyCoder->setEntropyCoder(m_pcCavlcCoder, pcSlice);
     2108            scalableNestingSEI.m_nestedSEIs.clear();
     2109            scalableNestingSEI.m_nestedSEIs.push_back(&pictureTimingSEI);
     2110            m_seiWriter.writeSEImessage(nalu.m_Bitstream, scalableNestingSEI, pcSlice->getSPS());
     2111            writeRBSPTrailingBits(nalu.m_Bitstream);
     2112#if L0045_NON_NESTED_SEI_RESTRICTIONS
     2113            UInt seiPositionInAu = xGetFirstSeiLocation(accessUnit);
     2114            UInt offsetPosition = m_activeParameterSetSEIPresentInAU
     2115              + m_bufferingPeriodSEIPresentInAU + m_pictureTimingSEIPresentInAU + m_nestedBufferingPeriodSEIPresentInAU;    // Insert PT SEI after APS and BP SEI
     2116            AccessUnit::iterator it;
     2117            for(j = 0, it = accessUnit.begin(); j < seiPositionInAu + offsetPosition; j++)
     2118            {
     2119              it++;
     2120            }
     2121            accessUnit.insert(it, new NALUnitEBSP(nalu));
     2122            m_nestedPictureTimingSEIPresentInAU = true;
     2123#else
     2124            AccessUnit::iterator it = find_if(accessUnit.begin(), accessUnit.end(), mem_fun(&NALUnit::isSlice));
     2125            accessUnit.insert(it, new NALUnitEBSP(nalu));
     2126#endif
     2127          }
     2128#endif
     2129
     2130        }
    18292131        if( m_pcCfg->getDecodingUnitInfoSEIEnabled() && hrd->getSubPicCpbParamsPresentFlag() )
    18302132        {             
     
    18322134          for( Int i = 0; i < ( pictureTimingSEI.m_numDecodingUnitsMinus1 + 1 ); i ++ )
    18332135          {
    1834             OutputNALUnit nalu(NAL_UNIT_SEI, pcSlice->getTLayer());
     2136            OutputNALUnit nalu(NAL_UNIT_PREFIX_SEI, pcSlice->getTLayer());
    18352137
    18362138            SEIDecodingUnitInfo tempSEI;
     
    18802182                  break;
    18812183                }
    1882                 if ((*it)->m_nalUnitType != NAL_UNIT_SEI && (*it)->m_nalUnitType != NAL_UNIT_SEI_SUFFIX)
     2184                if ((*it)->m_nalUnitType != NAL_UNIT_PREFIX_SEI && (*it)->m_nalUnitType != NAL_UNIT_SUFFIX_SEI)
    18832185                {
    18842186                  ctr++;
     
    18912193#if L0045_NON_NESTED_SEI_RESTRICTIONS
    18922194      xResetNonNestedSEIPresentFlags();
     2195#if K0180_SCALABLE_NESTING_SEI
     2196      xResetNestedSEIPresentFlags();
     2197#endif
    18932198#endif
    18942199      pcPic->getPicYuvRec()->copyToPic(pcPicYuvRecOut);
     
    21132418    case NAL_UNIT_CODED_SLICE_TRAIL_R: return "TRAIL_R";
    21142419    case NAL_UNIT_CODED_SLICE_TRAIL_N: return "TRAIL_N";
    2115     case NAL_UNIT_CODED_SLICE_TLA: return "TLA";
     2420    case NAL_UNIT_CODED_SLICE_TLA_R:      return "TLA_R";
    21162421    case NAL_UNIT_CODED_SLICE_TSA_N: return "TSA_N";
    21172422    case NAL_UNIT_CODED_SLICE_STSA_R: return "STSA_R";
    21182423    case NAL_UNIT_CODED_SLICE_STSA_N: return "STSA_N";
    2119     case NAL_UNIT_CODED_SLICE_BLA: return "BLA";
    2120     case NAL_UNIT_CODED_SLICE_BLANT: return "BLANT";
     2424    case NAL_UNIT_CODED_SLICE_BLA_W_LP:   return "BLA_W_LP";
     2425    case NAL_UNIT_CODED_SLICE_BLA_W_RADL: return "BLA_W_RADL";
    21212426    case NAL_UNIT_CODED_SLICE_BLA_N_LP: return "BLA_N_LP";
    2122     case NAL_UNIT_CODED_SLICE_IDR: return "IDR";
     2427    case NAL_UNIT_CODED_SLICE_IDR_W_RADL: return "IDR_W_RADL";
    21232428    case NAL_UNIT_CODED_SLICE_IDR_N_LP: return "IDR_N_LP";
    21242429    case NAL_UNIT_CODED_SLICE_CRA: return "CRA";
    2125     case NAL_UNIT_CODED_SLICE_DLP: return "DLP";
    2126     case NAL_UNIT_CODED_SLICE_TFD: return "TFD";
     2430    case NAL_UNIT_CODED_SLICE_RADL_R:     return "RADL_R";
     2431    case NAL_UNIT_CODED_SLICE_RASL_R:     return "RASL_R";
    21272432    case NAL_UNIT_VPS: return "VPS";
    21282433    case NAL_UNIT_SPS: return "SPS";
     
    21322437    case NAL_UNIT_EOB: return "EOB";
    21332438    case NAL_UNIT_FILLER_DATA: return "FILLER";
    2134     case NAL_UNIT_SEI: return "SEI";
     2439    case NAL_UNIT_PREFIX_SEI:             return "SEI";
     2440    case NAL_UNIT_SUFFIX_SEI:             return "SEI";
    21352441    default: return "UNK";
    21362442  }
     
    22232529    printf("*** %6s numBytesInNALunit: %u\n", nalUnitTypeToString((*it)->m_nalUnitType), numRBSPBytes_nal);
    22242530#endif
    2225     if ((*it)->m_nalUnitType != NAL_UNIT_SEI && (*it)->m_nalUnitType != NAL_UNIT_SEI_SUFFIX)
     2531    if ((*it)->m_nalUnitType != NAL_UNIT_PREFIX_SEI && (*it)->m_nalUnitType != NAL_UNIT_SUFFIX_SEI)
    22262532    {
    22272533      numRBSPBytes += numRBSPBytes_nal;
     
    23142620    for (Int iRefIndex = 0; iRefIndex < pcSlice->getNumRefIdx(RefPicList(iRefList)); iRefIndex++)
    23152621    {
     2622#if REF_IDX_FRAMEWORK && VPS_EXTN_DIRECT_REF_LAYERS_CONTINUE
     2623      if( pcSlice->getRefPic(RefPicList(iRefList), iRefIndex)->isILR(m_layerId) )
     2624      {
     2625        printf( "%d(%d) ", pcSlice->getRefPOC(RefPicList(iRefList), iRefIndex)-pcSlice->getLastIDR(), pcSlice->getRefPic(RefPicList(iRefList), iRefIndex)->getLayerId() );
     2626      }
     2627      else
     2628#endif
    23162629      printf ("%d ", pcSlice->getRefPOC(RefPicList(iRefList), iRefIndex)-pcSlice->getLastIDR());
    23172630    }
     
    23252638 * This function checks the configuration and returns the appropriate nal_unit_type for the picture.
    23262639 */
    2327 NalUnitType TEncGOP::getNalUnitType(Int pocCurr)
     2640NalUnitType TEncGOP::getNalUnitType(Int pocCurr, Int lastIDR)
    23282641{
    23292642  if (pocCurr == 0)
    23302643  {
    2331     return NAL_UNIT_CODED_SLICE_IDR;
     2644    return NAL_UNIT_CODED_SLICE_IDR_W_RADL;
    23322645  }
    23332646  if (pocCurr % m_pcCfg->getIntraPeriod() == 0)
     
    23392652    else if (m_pcCfg->getDecodingRefreshType() == 2)
    23402653    {
    2341       return NAL_UNIT_CODED_SLICE_IDR;
     2654      return NAL_UNIT_CODED_SLICE_IDR_W_RADL;
    23422655    }
    23432656  }
     
    23512664      // controlling the reference pictures used for encoding that leading picture. Such a leading
    23522665      // picture need not be marked as a TFD picture.
    2353       return NAL_UNIT_CODED_SLICE_TFD;
     2666      return NAL_UNIT_CODED_SLICE_RASL_R;
     2667    }
     2668  }
     2669  if (lastIDR>0)
     2670  {
     2671    if (pocCurr < lastIDR)
     2672    {
     2673      return NAL_UNIT_CODED_SLICE_RADL_R;
    23542674    }
    23552675  }
     
    24022722}
    24032723
    2404 /** Determine the difference between consecutive tile sizes (in bytes) and writes it to  bistream rNalu [slice header]
    2405  * \param rpcBitstreamRedirect contains the bitstream to be concatenated to rNalu. rpcBitstreamRedirect contains slice payload. rpcSlice contains tile location information.
    2406  * \returns Updates rNalu to contain concatenated bitstream. rpcBitstreamRedirect is cleared at the end of this function call.
     2724/** Attaches the input bitstream to the stream in the output NAL unit
     2725    Updates rNalu to contain concatenated bitstream. rpcBitstreamRedirect is cleared at the end of this function call.
     2726 *  \param codedSliceData contains the coded slice data (bitstream) to be concatenated to rNalu
     2727 *  \param rNalu          target NAL unit
    24072728 */
    2408 Void TEncGOP::xWriteTileLocationToSliceHeader (OutputNALUnit& rNalu, TComOutputBitstream*& rpcBitstreamRedirect, TComSlice*& rpcSlice)
     2729Void TEncGOP::xAttachSliceDataToNalUnit (OutputNALUnit& rNalu, TComOutputBitstream*& codedSliceData)
    24092730{
    24102731  // Byte-align
     
    24122733
    24132734  // Perform bitstream concatenation
    2414   if (rpcBitstreamRedirect->getNumberOfWrittenBits() > 0)
    2415   {
    2416     UInt uiBitCount  = rpcBitstreamRedirect->getNumberOfWrittenBits();
    2417     if (rpcBitstreamRedirect->getByteStreamLength()>0)
    2418     {
    2419       UChar *pucStart  =  reinterpret_cast<UChar*>(rpcBitstreamRedirect->getByteStream());
    2420       UInt uiWriteByteCount = 0;
    2421       while (uiWriteByteCount < (uiBitCount >> 3) )
    2422       {
    2423         UInt uiBits = (*pucStart);
    2424         rNalu.m_Bitstream.write(uiBits, 8);
    2425         pucStart++;
    2426         uiWriteByteCount++;
    2427       }
    2428     }
    2429     UInt uiBitsHeld = (uiBitCount & 0x07);
    2430     for (UInt uiIdx=0; uiIdx < uiBitsHeld; uiIdx++)
    2431     {
    2432       rNalu.m_Bitstream.write((rpcBitstreamRedirect->getHeldBits() & (1 << (7-uiIdx))) >> (7-uiIdx), 1);
    2433     }         
     2735  if (codedSliceData->getNumberOfWrittenBits() > 0)
     2736    {
     2737    rNalu.m_Bitstream.addSubstream(codedSliceData);
    24342738  }
    24352739
    24362740  m_pcEntropyCoder->setBitstream(&rNalu.m_Bitstream);
    24372741
    2438   delete rpcBitstreamRedirect;
    2439   rpcBitstreamRedirect = new TComOutputBitstream;
     2742  codedSliceData->clear();
    24402743}
    24412744
     
    25622865     }               
    25632866  }
    2564   assert(it != accessUnit.end());
     2867//  assert(it != accessUnit.end());  // Triggers with some legit configurations
    25652868  return seiStartPos;
    25662869}
    25672870#endif
     2871
     2872#if L0386_DB_METRIC
     2873Void TEncGOP::dblMetric( TComPic* pcPic, UInt uiNumSlices )
     2874{
     2875  TComPicYuv* pcPicYuvRec = pcPic->getPicYuvRec();
     2876  Pel* Rec    = pcPicYuvRec->getLumaAddr( 0 );
     2877  Pel* tempRec = Rec;
     2878  Int  stride = pcPicYuvRec->getStride();
     2879  UInt log2maxTB = pcPic->getSlice(0)->getSPS()->getQuadtreeTULog2MaxSize();
     2880  UInt maxTBsize = (1<<log2maxTB);
     2881  const UInt minBlockArtSize = 8;
     2882  const UInt picWidth = pcPicYuvRec->getWidth();
     2883  const UInt picHeight = pcPicYuvRec->getHeight();
     2884  const UInt noCol = (picWidth>>log2maxTB);
     2885  const UInt noRows = (picHeight>>log2maxTB);
     2886  UInt64 *colSAD = (UInt64*)malloc(noCol*sizeof(UInt64));
     2887  UInt64 *rowSAD = (UInt64*)malloc(noRows*sizeof(UInt64));
     2888  UInt colIdx = 0;
     2889  UInt rowIdx = 0;
     2890  Pel p0, p1, p2, q0, q1, q2;
     2891 
     2892  Int qp = pcPic->getSlice(0)->getSliceQp();
     2893  Int bitdepthScale = 1 << (g_bitDepthY-8);
     2894  Int beta = TComLoopFilter::getBeta( qp ) * bitdepthScale;
     2895  const Int thr2 = (beta>>2);
     2896  const Int thr1 = 2*bitdepthScale;
     2897  UInt a = 0;
     2898 
     2899  memset(colSAD, 0, noCol*sizeof(UInt64));
     2900  memset(rowSAD, 0, noRows*sizeof(UInt64));
     2901 
     2902  if (maxTBsize > minBlockArtSize)
     2903  {
     2904    // Analyze vertical artifact edges
     2905    for(Int c = maxTBsize; c < picWidth; c += maxTBsize)
     2906    {
     2907      for(Int r = 0; r < picHeight; r++)
     2908      {
     2909        p2 = Rec[c-3];
     2910        p1 = Rec[c-2];
     2911        p0 = Rec[c-1];
     2912        q0 = Rec[c];
     2913        q1 = Rec[c+1];
     2914        q2 = Rec[c+2];
     2915        a = ((abs(p2-(p1<<1)+p0)+abs(q0-(q1<<1)+q2))<<1);
     2916        if ( thr1 < a && a < thr2)
     2917        {
     2918          colSAD[colIdx] += abs(p0 - q0);
     2919        }
     2920        Rec += stride;
     2921      }
     2922      colIdx++;
     2923      Rec = tempRec;
     2924    }
     2925   
     2926    // Analyze horizontal artifact edges
     2927    for(Int r = maxTBsize; r < picHeight; r += maxTBsize)
     2928    {
     2929      for(Int c = 0; c < picWidth; c++)
     2930      {
     2931        p2 = Rec[c + (r-3)*stride];
     2932        p1 = Rec[c + (r-2)*stride];
     2933        p0 = Rec[c + (r-1)*stride];
     2934        q0 = Rec[c + r*stride];
     2935        q1 = Rec[c + (r+1)*stride];
     2936        q2 = Rec[c + (r+2)*stride];
     2937        a = ((abs(p2-(p1<<1)+p0)+abs(q0-(q1<<1)+q2))<<1);
     2938        if (thr1 < a && a < thr2)
     2939        {
     2940          rowSAD[rowIdx] += abs(p0 - q0);
     2941        }
     2942      }
     2943      rowIdx++;
     2944    }
     2945  }
     2946 
     2947  UInt64 colSADsum = 0;
     2948  UInt64 rowSADsum = 0;
     2949  for(Int c = 0; c < noCol-1; c++)
     2950  {
     2951    colSADsum += colSAD[c];
     2952  }
     2953  for(Int r = 0; r < noRows-1; r++)
     2954  {
     2955    rowSADsum += rowSAD[r];
     2956  }
     2957 
     2958  colSADsum <<= 10;
     2959  rowSADsum <<= 10;
     2960  colSADsum /= (noCol-1);
     2961  colSADsum /= picHeight;
     2962  rowSADsum /= (noRows-1);
     2963  rowSADsum /= picWidth;
     2964 
     2965  UInt64 avgSAD = ((colSADsum + rowSADsum)>>1);
     2966  avgSAD >>= (g_bitDepthY-8);
     2967 
     2968  if ( avgSAD > 2048 )
     2969  {
     2970    avgSAD >>= 9;
     2971    Int offset = Clip3(2,6,(Int)avgSAD);
     2972    for (Int i=0; i<uiNumSlices; i++)
     2973    {
     2974      pcPic->getSlice(i)->setDeblockingFilterOverrideFlag(true);
     2975      pcPic->getSlice(i)->setDeblockingFilterDisable(false);
     2976      pcPic->getSlice(i)->setDeblockingFilterBetaOffsetDiv2( offset );
     2977      pcPic->getSlice(i)->setDeblockingFilterTcOffsetDiv2( offset );
     2978    }
     2979  }
     2980  else
     2981  {
     2982    for (Int i=0; i<uiNumSlices; i++)
     2983    {
     2984      pcPic->getSlice(i)->setDeblockingFilterOverrideFlag(false);
     2985      pcPic->getSlice(i)->setDeblockingFilterDisable(        pcPic->getSlice(i)->getPPS()->getPicDisableDeblockingFilterFlag() );
     2986      pcPic->getSlice(i)->setDeblockingFilterBetaOffsetDiv2( pcPic->getSlice(i)->getPPS()->getDeblockingFilterBetaOffsetDiv2() );
     2987      pcPic->getSlice(i)->setDeblockingFilterTcOffsetDiv2(   pcPic->getSlice(i)->getPPS()->getDeblockingFilterTcOffsetDiv2()   );
     2988    }
     2989  }
     2990 
     2991  free(colSAD);
     2992  free(rowSAD);
     2993}
     2994#endif
    25682995//! \}
Note: See TracChangeset for help on using the changeset viewer.