Ignore:
Timestamp:
28 Apr 2013, 08:49:16 (12 years ago)
Author:
seregin
Message:

update to HM10.1

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/SHM-2.0-dev/source/Lib/TLibEncoder/TEncGOP.cpp

    r125 r133  
    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;
     
    411530    }
    412531    // Set the nal unit type
    413     pcSlice->setNalUnitType(getNalUnitType(pocCurr));
     532    pcSlice->setNalUnitType(getNalUnitType(pocCurr, m_iLastIDR));
    414533#if IDR_ALIGNMENT
    415534    if (m_layerId > 0)
     
    424543    {
    425544#if IDR_ALIGNMENT
    426       if( pcSlice->getBaseColPic()->getSlice(0)->getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR )
    427       {
    428         pcSlice->setNalUnitType(NAL_UNIT_CODED_SLICE_IDR);
     545      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 )
     546      {
     547        pcSlice->setNalUnitType(pcSlice->getBaseColPic()->getSlice(0)->getNalUnitType());
    429548      }
    430549      else
     
    434553    if( m_layerId > 0 && !m_pcEncTop->getElRapSliceTypeB() )
    435554    {
    436       if( (pcSlice->getNalUnitType() >= NAL_UNIT_CODED_SLICE_BLA) &&
     555      if( (pcSlice->getNalUnitType() >= NAL_UNIT_CODED_SLICE_BLA_W_LP) &&
    437556          (pcSlice->getNalUnitType() <= NAL_UNIT_CODED_SLICE_CRA) &&
    438557           pcSlice->getSliceType() == B_SLICE )
     
    442561    }
    443562#endif
    444     if(pcSlice->getNalUnitType()==NAL_UNIT_CODED_SLICE_TRAIL_R)
    445     {
    446       if(pcSlice->getTemporalLayerNonReferenceFlag())
     563    if(pcSlice->getTemporalLayerNonReferenceFlag())
     564    {
     565      if(pcSlice->getNalUnitType()==NAL_UNIT_CODED_SLICE_TRAIL_R)
    447566      {
    448567        pcSlice->setNalUnitType(NAL_UNIT_CODED_SLICE_TRAIL_N);
     568    }
     569      if(pcSlice->getNalUnitType()==NAL_UNIT_CODED_SLICE_RADL_R)
     570      {
     571        pcSlice->setNalUnitType(NAL_UNIT_CODED_SLICE_RADL_N);
     572      }
     573      if(pcSlice->getNalUnitType()==NAL_UNIT_CODED_SLICE_RASL_R)
     574      {
     575        pcSlice->setNalUnitType(NAL_UNIT_CODED_SLICE_RASL_N);
    449576      }
    450577    }
     
    471598        else
    472599        {
    473           pcSlice->setNalUnitType(NAL_UNIT_CODED_SLICE_TLA);
     600          pcSlice->setNalUnitType(NAL_UNIT_CODED_SLICE_TLA_R);
    474601        }
    475602      }
     
    527654    if(m_layerId > 0)
    528655    {
    529       if( pcSlice->getNalUnitType() >= NAL_UNIT_CODED_SLICE_BLA && pcSlice->getNalUnitType() <= NAL_UNIT_CODED_SLICE_CRA )
     656      if( pcSlice->getNalUnitType() >= NAL_UNIT_CODED_SLICE_BLA_W_LP && pcSlice->getNalUnitType() <= NAL_UNIT_CODED_SLICE_CRA )
    530657      {
    531658        pcSlice->setNumRefIdx(REF_PIC_LIST_0, pcSlice->getNumILRRefIdx());
     
    644771      pcSlice->setSliceType ( P_SLICE );
    645772    }
    646 
     773#if !L0034_COMBINED_LIST_CLEANUP
    647774    if (pcSlice->getSliceType() != B_SLICE || !pcSlice->getSPS()->getUseLComb())
    648775    {
     
    656783      pcSlice->setNumRefIdx(REF_PIC_LIST_C, pcSlice->getNumRefIdx(REF_PIC_LIST_0));
    657784    }
     785#endif
    658786
    659787    if (pcSlice->getSliceType() == B_SLICE)
     
    683811      pcSlice->setCheckLDC(bLowDelay); 
    684812    }
     813    else
     814    {
     815      pcSlice->setCheckLDC(true); 
     816    }
    685817
    686818    uiColDir = 1-uiColDir;
     
    689821    pcSlice->setRefPOCList();
    690822
     823#if L0034_COMBINED_LIST_CLEANUP
     824    pcSlice->setList1IdxToList0Idx();
     825#else
    691826    pcSlice->setNoBackPredFlag( false );
    692827    if ( pcSlice->getSliceType() == B_SLICE && !pcSlice->getRefPicListCombinationFlag())
     
    712847    }
    713848    pcSlice->generateCombinedList();
     849#endif
    714850
    715851    if (m_pcEncTop->getTMVPModeId() == 2)
     
    10271163    Bool bLFCrossTileBoundary = pcSlice->getPPS()->getLoopFilterAcrossTilesEnabledFlag();
    10281164    m_pcLoopFilter->setCfg(bLFCrossTileBoundary);
     1165#if L0386_DB_METRIC
     1166    if ( m_pcCfg->getDeblockingFilterMetric() )
     1167    {
     1168      dblMetric(pcPic, uiNumSlices);
     1169    }
     1170#endif
    10291171    m_pcLoopFilter->loopFilterPic( pcPic );
    10301172
     
    11331275    }
    11341276
     1277#if L0208_SOP_DESCRIPTION_SEI
     1278    if (writeSOP) // write SOP description SEI (if enabled) at the beginning of GOP
     1279    {
     1280      Int SOPcurrPOC = pocCurr;
     1281
     1282      OutputNALUnit nalu(NAL_UNIT_PREFIX_SEI);
     1283      m_pcEntropyCoder->setEntropyCoder(m_pcCavlcCoder, pcSlice);
     1284      m_pcEntropyCoder->setBitstream(&nalu.m_Bitstream);
     1285
     1286      SEISOPDescription SOPDescriptionSEI;
     1287      SOPDescriptionSEI.m_sopSeqParameterSetId = pcSlice->getSPS()->getSPSId();
     1288
     1289      UInt i = 0;
     1290      UInt prevEntryId = iGOPid;
     1291      for (j = iGOPid; j < m_iGopSize; j++)
     1292      {
     1293        Int deltaPOC = m_pcCfg->getGOPEntry(j).m_POC - m_pcCfg->getGOPEntry(prevEntryId).m_POC;
     1294        if ((SOPcurrPOC + deltaPOC) < m_pcCfg->getFramesToBeEncoded())
     1295        {
     1296          SOPcurrPOC += deltaPOC;
     1297          SOPDescriptionSEI.m_sopDescVclNaluType[i] = getNalUnitType(SOPcurrPOC, m_iLastIDR);
     1298          SOPDescriptionSEI.m_sopDescTemporalId[i] = m_pcCfg->getGOPEntry(j).m_temporalId;
     1299          SOPDescriptionSEI.m_sopDescStRpsIdx[i] = m_pcEncTop->getReferencePictureSetIdxForSOP(pcSlice, SOPcurrPOC, j);
     1300          SOPDescriptionSEI.m_sopDescPocDelta[i] = deltaPOC;
     1301
     1302          prevEntryId = j;
     1303          i++;
     1304        }
     1305      }
     1306
     1307      SOPDescriptionSEI.m_numPicsInSopMinus1 = i - 1;
     1308
     1309      m_seiWriter.writeSEImessage( nalu.m_Bitstream, SOPDescriptionSEI, pcSlice->getSPS());
     1310      writeRBSPTrailingBits(nalu.m_Bitstream);
     1311      accessUnit.push_back(new NALUnitEBSP(nalu));
     1312
     1313      writeSOP = false;
     1314    }
     1315#endif
     1316
    11351317    if( ( m_pcCfg->getPictureTimingSEIEnabled() || m_pcCfg->getDecodingUnitInfoSEIEnabled() ) &&
    11361318        ( pcSlice->getSPS()->getVuiParametersPresentFlag() ) &&
     
    11781360       || ( pcSlice->getSPS()->getVuiParameters()->getHrdParameters()->getVclHrdParametersPresentFlag() ) ) )
    11791361    {
    1180       OutputNALUnit nalu(NAL_UNIT_SEI);
     1362      OutputNALUnit nalu(NAL_UNIT_PREFIX_SEI);
    11811363      m_pcEntropyCoder->setEntropyCoder(m_pcCavlcCoder, pcSlice);
    11821364      m_pcEntropyCoder->setBitstream(&nalu.m_Bitstream);
     
    12191401      writeRBSPTrailingBits(nalu.m_Bitstream);
    12201402#if L0045_NON_NESTED_SEI_RESTRICTIONS
     1403      {
    12211404      UInt seiPositionInAu = xGetFirstSeiLocation(accessUnit);
    12221405      UInt offsetPosition = m_activeParameterSetSEIPresentInAU;   // Insert BP SEI after APS SEI
     
    12281411      accessUnit.insert(it, new NALUnitEBSP(nalu));
    12291412      m_bufferingPeriodSEIPresentInAU = true;
     1413      }
    12301414#else
    12311415      accessUnit.push_back(new NALUnitEBSP(nalu));
    12321416#endif
    12331417
     1418#if K0180_SCALABLE_NESTING_SEI
     1419      if (m_pcCfg->getScalableNestingSEIEnabled())
     1420      {
     1421        OutputNALUnit naluTmp(NAL_UNIT_PREFIX_SEI);
     1422        m_pcEntropyCoder->setEntropyCoder(m_pcCavlcCoder, pcSlice);
     1423        m_pcEntropyCoder->setBitstream(&naluTmp.m_Bitstream);
     1424        scalableNestingSEI.m_nestedSEIs.clear();
     1425        scalableNestingSEI.m_nestedSEIs.push_back(&sei_buffering_period);
     1426        m_seiWriter.writeSEImessage( naluTmp.m_Bitstream, scalableNestingSEI, pcSlice->getSPS());
     1427        writeRBSPTrailingBits(naluTmp.m_Bitstream);
     1428#if L0045_NON_NESTED_SEI_RESTRICTIONS
     1429        UInt seiPositionInAu = xGetFirstSeiLocation(accessUnit);
     1430        UInt offsetPosition = m_activeParameterSetSEIPresentInAU + m_bufferingPeriodSEIPresentInAU + m_pictureTimingSEIPresentInAU;   // Insert BP SEI after non-nested APS, BP and PT SEIs
     1431        AccessUnit::iterator it;
     1432        for(j = 0, it = accessUnit.begin(); j < seiPositionInAu + offsetPosition; j++)
     1433        {
     1434          it++;
     1435        }
     1436        accessUnit.insert(it, new NALUnitEBSP(naluTmp));
     1437        m_nestedBufferingPeriodSEIPresentInAU = true;
     1438#else
     1439        accessUnit.push_back(new NALUnitEBSP(naluTmp));
     1440#endif
     1441      }
     1442#endif
     1443
    12341444      m_lastBPSEI = m_totalCoded;
    12351445      m_cpbRemovalDelay = 0;
     
    12411451      {
    12421452        // Gradual decoding refresh SEI
    1243         OutputNALUnit nalu(NAL_UNIT_SEI);
     1453        OutputNALUnit nalu(NAL_UNIT_PREFIX_SEI);
    12441454        m_pcEntropyCoder->setEntropyCoder(m_pcCavlcCoder, pcSlice);
    12451455        m_pcEntropyCoder->setBitstream(&nalu.m_Bitstream);
     
    12531463      }
    12541464    // Recovery point SEI
    1255       OutputNALUnit nalu(NAL_UNIT_SEI);
     1465      OutputNALUnit nalu(NAL_UNIT_PREFIX_SEI);
    12561466      m_pcEntropyCoder->setEntropyCoder(m_pcCavlcCoder, pcSlice);
    12571467      m_pcEntropyCoder->setBitstream(&nalu.m_Bitstream);
     
    14441654
    14451655          pcSlice->setTileOffstForMultES( uiOneBitstreamPerSliceLength );
    1446           if (!sliceSegment)
    1447           {
    14481656            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           }
     1657          m_pcSliceEncoder->encodeSlice(pcPic, pcSubstreamsOut);
    14551658
    14561659          {
     
    14841687              if (ui+1 < pcSlice->getPPS()->getNumSubstreams())
    14851688              {
    1486                 puiSubstreamSizes[ui] = pcSubstreamsOut[ui].getNumberOfWrittenBits();
     1689                puiSubstreamSizes[ui] = pcSubstreamsOut[ui].getNumberOfWrittenBits() + (pcSubstreamsOut[ui].countStartCodeEmulations()<<3);
    14871690              }
    14881691            }
     
    15161719          // 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.
    15171720          Bool bNALUAlignedWrittenToList    = false; // used to ensure current NALU is not written more than once to the NALU list.
    1518           xWriteTileLocationToSliceHeader(nalu, pcBitstreamRedirect, pcSlice);
     1721          xAttachSliceDataToNalUnit(nalu, pcBitstreamRedirect);
    15191722          accessUnit.push_back(new NALUnitEBSP(nalu));
    15201723#if RATE_CONTROL_LAMBDA_DOMAIN
     
    15441747            {
    15451748              UInt numRBSPBytes_nal = UInt((*it)->m_nalUnitData.str().size());
    1546               if ((*it)->m_nalUnitType != NAL_UNIT_SEI && (*it)->m_nalUnitType != NAL_UNIT_SEI_SUFFIX)
     1749              if ((*it)->m_nalUnitType != NAL_UNIT_PREFIX_SEI && (*it)->m_nalUnitType != NAL_UNIT_SUFFIX_SEI)
    15471750              {
    15481751                numRBSPBytes += numRBSPBytes_nal;
     
    16401843        }
    16411844#if SVC_EXTENSION
    1642         OutputNALUnit nalu(NAL_UNIT_SEI_SUFFIX, pcSlice->getTLayer(), m_layerId);
     1845        OutputNALUnit nalu(NAL_UNIT_SUFFIX_SEI, pcSlice->getTLayer(), m_layerId);
    16431846#else
    1644         OutputNALUnit nalu(NAL_UNIT_SEI_SUFFIX, pcSlice->getTLayer());
     1847        OutputNALUnit nalu(NAL_UNIT_SUFFIX_SEI, pcSlice->getTLayer());
    16451848#endif
    16461849
     
    16671870        sei_temporal_level0_index.rapIdx = m_rapIdx;
    16681871
    1669         OutputNALUnit nalu(NAL_UNIT_SEI);
     1872        OutputNALUnit nalu(NAL_UNIT_PREFIX_SEI);
    16701873
    16711874        /* write the SEI messages */
     
    18072010        if( m_pcCfg->getPictureTimingSEIEnabled() )
    18082011        {
    1809           OutputNALUnit nalu(NAL_UNIT_SEI, pcSlice->getTLayer());
     2012          {
     2013            OutputNALUnit nalu(NAL_UNIT_PREFIX_SEI, pcSlice->getTLayer());
    18102014          m_pcEntropyCoder->setEntropyCoder(m_pcCavlcCoder, pcSlice);
    18112015          m_seiWriter.writeSEImessage(nalu.m_Bitstream, pictureTimingSEI, pcSlice->getSPS());
     
    18272031#endif
    18282032        }
     2033#if K0180_SCALABLE_NESTING_SEI
     2034          if ( m_pcCfg->getScalableNestingSEIEnabled() ) // put picture timing SEI into scalable nesting SEI
     2035          {
     2036            OutputNALUnit nalu(NAL_UNIT_PREFIX_SEI, pcSlice->getTLayer());
     2037            m_pcEntropyCoder->setEntropyCoder(m_pcCavlcCoder, pcSlice);
     2038            scalableNestingSEI.m_nestedSEIs.clear();
     2039            scalableNestingSEI.m_nestedSEIs.push_back(&pictureTimingSEI);
     2040            m_seiWriter.writeSEImessage(nalu.m_Bitstream, scalableNestingSEI, pcSlice->getSPS());
     2041            writeRBSPTrailingBits(nalu.m_Bitstream);
     2042#if L0045_NON_NESTED_SEI_RESTRICTIONS
     2043            UInt seiPositionInAu = xGetFirstSeiLocation(accessUnit);
     2044            UInt offsetPosition = m_activeParameterSetSEIPresentInAU
     2045              + m_bufferingPeriodSEIPresentInAU + m_pictureTimingSEIPresentInAU + m_nestedBufferingPeriodSEIPresentInAU;    // Insert PT SEI after APS and BP SEI
     2046            AccessUnit::iterator it;
     2047            for(j = 0, it = accessUnit.begin(); j < seiPositionInAu + offsetPosition; j++)
     2048            {
     2049              it++;
     2050            }
     2051            accessUnit.insert(it, new NALUnitEBSP(nalu));
     2052            m_nestedPictureTimingSEIPresentInAU = true;
     2053#else
     2054            AccessUnit::iterator it = find_if(accessUnit.begin(), accessUnit.end(), mem_fun(&NALUnit::isSlice));
     2055            accessUnit.insert(it, new NALUnitEBSP(nalu));
     2056#endif
     2057          }
     2058#endif
     2059
     2060        }
    18292061        if( m_pcCfg->getDecodingUnitInfoSEIEnabled() && hrd->getSubPicCpbParamsPresentFlag() )
    18302062        {             
     
    18322064          for( Int i = 0; i < ( pictureTimingSEI.m_numDecodingUnitsMinus1 + 1 ); i ++ )
    18332065          {
    1834             OutputNALUnit nalu(NAL_UNIT_SEI, pcSlice->getTLayer());
     2066            OutputNALUnit nalu(NAL_UNIT_PREFIX_SEI, pcSlice->getTLayer());
    18352067
    18362068            SEIDecodingUnitInfo tempSEI;
     
    18802112                  break;
    18812113                }
    1882                 if ((*it)->m_nalUnitType != NAL_UNIT_SEI && (*it)->m_nalUnitType != NAL_UNIT_SEI_SUFFIX)
     2114                if ((*it)->m_nalUnitType != NAL_UNIT_PREFIX_SEI && (*it)->m_nalUnitType != NAL_UNIT_SUFFIX_SEI)
    18832115                {
    18842116                  ctr++;
     
    18912123#if L0045_NON_NESTED_SEI_RESTRICTIONS
    18922124      xResetNonNestedSEIPresentFlags();
     2125#if K0180_SCALABLE_NESTING_SEI
     2126      xResetNestedSEIPresentFlags();
     2127#endif
    18932128#endif
    18942129      pcPic->getPicYuvRec()->copyToPic(pcPicYuvRecOut);
     
    21132348    case NAL_UNIT_CODED_SLICE_TRAIL_R: return "TRAIL_R";
    21142349    case NAL_UNIT_CODED_SLICE_TRAIL_N: return "TRAIL_N";
    2115     case NAL_UNIT_CODED_SLICE_TLA: return "TLA";
     2350    case NAL_UNIT_CODED_SLICE_TLA_R:      return "TLA_R";
    21162351    case NAL_UNIT_CODED_SLICE_TSA_N: return "TSA_N";
    21172352    case NAL_UNIT_CODED_SLICE_STSA_R: return "STSA_R";
    21182353    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";
     2354    case NAL_UNIT_CODED_SLICE_BLA_W_LP:   return "BLA_W_LP";
     2355    case NAL_UNIT_CODED_SLICE_BLA_W_RADL: return "BLA_W_RADL";
    21212356    case NAL_UNIT_CODED_SLICE_BLA_N_LP: return "BLA_N_LP";
    2122     case NAL_UNIT_CODED_SLICE_IDR: return "IDR";
     2357    case NAL_UNIT_CODED_SLICE_IDR_W_RADL: return "IDR_W_RADL";
    21232358    case NAL_UNIT_CODED_SLICE_IDR_N_LP: return "IDR_N_LP";
    21242359    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";
     2360    case NAL_UNIT_CODED_SLICE_RADL_R:     return "RADL_R";
     2361    case NAL_UNIT_CODED_SLICE_RASL_R:     return "RASL_R";
    21272362    case NAL_UNIT_VPS: return "VPS";
    21282363    case NAL_UNIT_SPS: return "SPS";
     
    21322367    case NAL_UNIT_EOB: return "EOB";
    21332368    case NAL_UNIT_FILLER_DATA: return "FILLER";
    2134     case NAL_UNIT_SEI: return "SEI";
     2369    case NAL_UNIT_PREFIX_SEI:             return "SEI";
     2370    case NAL_UNIT_SUFFIX_SEI:             return "SEI";
    21352371    default: return "UNK";
    21362372  }
     
    22232459    printf("*** %6s numBytesInNALunit: %u\n", nalUnitTypeToString((*it)->m_nalUnitType), numRBSPBytes_nal);
    22242460#endif
    2225     if ((*it)->m_nalUnitType != NAL_UNIT_SEI && (*it)->m_nalUnitType != NAL_UNIT_SEI_SUFFIX)
     2461    if ((*it)->m_nalUnitType != NAL_UNIT_PREFIX_SEI && (*it)->m_nalUnitType != NAL_UNIT_SUFFIX_SEI)
    22262462    {
    22272463      numRBSPBytes += numRBSPBytes_nal;
     
    23252561 * This function checks the configuration and returns the appropriate nal_unit_type for the picture.
    23262562 */
    2327 NalUnitType TEncGOP::getNalUnitType(Int pocCurr)
     2563NalUnitType TEncGOP::getNalUnitType(Int pocCurr, Int lastIDR)
    23282564{
    23292565  if (pocCurr == 0)
    23302566  {
    2331     return NAL_UNIT_CODED_SLICE_IDR;
     2567    return NAL_UNIT_CODED_SLICE_IDR_W_RADL;
    23322568  }
    23332569  if (pocCurr % m_pcCfg->getIntraPeriod() == 0)
     
    23392575    else if (m_pcCfg->getDecodingRefreshType() == 2)
    23402576    {
    2341       return NAL_UNIT_CODED_SLICE_IDR;
     2577      return NAL_UNIT_CODED_SLICE_IDR_W_RADL;
    23422578    }
    23432579  }
     
    23512587      // controlling the reference pictures used for encoding that leading picture. Such a leading
    23522588      // picture need not be marked as a TFD picture.
    2353       return NAL_UNIT_CODED_SLICE_TFD;
     2589      return NAL_UNIT_CODED_SLICE_RASL_R;
     2590    }
     2591  }
     2592  if (lastIDR>0)
     2593  {
     2594    if (pocCurr < lastIDR)
     2595    {
     2596      return NAL_UNIT_CODED_SLICE_RADL_R;
    23542597    }
    23552598  }
     
    24022645}
    24032646
    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.
     2647/** Attaches the input bitstream to the stream in the output NAL unit
     2648    Updates rNalu to contain concatenated bitstream. rpcBitstreamRedirect is cleared at the end of this function call.
     2649 *  \param codedSliceData contains the coded slice data (bitstream) to be concatenated to rNalu
     2650 *  \param rNalu          target NAL unit
    24072651 */
    2408 Void TEncGOP::xWriteTileLocationToSliceHeader (OutputNALUnit& rNalu, TComOutputBitstream*& rpcBitstreamRedirect, TComSlice*& rpcSlice)
     2652Void TEncGOP::xAttachSliceDataToNalUnit (OutputNALUnit& rNalu, TComOutputBitstream*& codedSliceData)
    24092653{
    24102654  // Byte-align
     
    24122656
    24132657  // 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     }         
     2658  if (codedSliceData->getNumberOfWrittenBits() > 0)
     2659    {
     2660    rNalu.m_Bitstream.addSubstream(codedSliceData);
    24342661  }
    24352662
    24362663  m_pcEntropyCoder->setBitstream(&rNalu.m_Bitstream);
    24372664
    2438   delete rpcBitstreamRedirect;
    2439   rpcBitstreamRedirect = new TComOutputBitstream;
     2665  codedSliceData->clear();
    24402666}
    24412667
     
    25622788     }               
    25632789  }
    2564   assert(it != accessUnit.end());
     2790//  assert(it != accessUnit.end());  // Triggers with some legit configurations
    25652791  return seiStartPos;
    25662792}
    25672793#endif
     2794
     2795#if L0386_DB_METRIC
     2796Void TEncGOP::dblMetric( TComPic* pcPic, UInt uiNumSlices )
     2797{
     2798  TComPicYuv* pcPicYuvRec = pcPic->getPicYuvRec();
     2799  Pel* Rec    = pcPicYuvRec->getLumaAddr( 0 );
     2800  Pel* tempRec = Rec;
     2801  Int  stride = pcPicYuvRec->getStride();
     2802  UInt log2maxTB = pcPic->getSlice(0)->getSPS()->getQuadtreeTULog2MaxSize();
     2803  UInt maxTBsize = (1<<log2maxTB);
     2804  const UInt minBlockArtSize = 8;
     2805  const UInt picWidth = pcPicYuvRec->getWidth();
     2806  const UInt picHeight = pcPicYuvRec->getHeight();
     2807  const UInt noCol = (picWidth>>log2maxTB);
     2808  const UInt noRows = (picHeight>>log2maxTB);
     2809  UInt64 *colSAD = (UInt64*)malloc(noCol*sizeof(UInt64));
     2810  UInt64 *rowSAD = (UInt64*)malloc(noRows*sizeof(UInt64));
     2811  UInt colIdx = 0;
     2812  UInt rowIdx = 0;
     2813  Pel p0, p1, p2, q0, q1, q2;
     2814 
     2815  Int qp = pcPic->getSlice(0)->getSliceQp();
     2816  Int bitdepthScale = 1 << (g_bitDepthY-8);
     2817  Int beta = TComLoopFilter::getBeta( qp ) * bitdepthScale;
     2818  const Int thr2 = (beta>>2);
     2819  const Int thr1 = 2*bitdepthScale;
     2820  UInt a = 0;
     2821 
     2822  memset(colSAD, 0, noCol*sizeof(UInt64));
     2823  memset(rowSAD, 0, noRows*sizeof(UInt64));
     2824 
     2825  if (maxTBsize > minBlockArtSize)
     2826  {
     2827    // Analyze vertical artifact edges
     2828    for(Int c = maxTBsize; c < picWidth; c += maxTBsize)
     2829    {
     2830      for(Int r = 0; r < picHeight; r++)
     2831      {
     2832        p2 = Rec[c-3];
     2833        p1 = Rec[c-2];
     2834        p0 = Rec[c-1];
     2835        q0 = Rec[c];
     2836        q1 = Rec[c+1];
     2837        q2 = Rec[c+2];
     2838        a = ((abs(p2-(p1<<1)+p0)+abs(q0-(q1<<1)+q2))<<1);
     2839        if ( thr1 < a && a < thr2)
     2840        {
     2841          colSAD[colIdx] += abs(p0 - q0);
     2842        }
     2843        Rec += stride;
     2844      }
     2845      colIdx++;
     2846      Rec = tempRec;
     2847    }
     2848   
     2849    // Analyze horizontal artifact edges
     2850    for(Int r = maxTBsize; r < picHeight; r += maxTBsize)
     2851    {
     2852      for(Int c = 0; c < picWidth; c++)
     2853      {
     2854        p2 = Rec[c + (r-3)*stride];
     2855        p1 = Rec[c + (r-2)*stride];
     2856        p0 = Rec[c + (r-1)*stride];
     2857        q0 = Rec[c + r*stride];
     2858        q1 = Rec[c + (r+1)*stride];
     2859        q2 = Rec[c + (r+2)*stride];
     2860        a = ((abs(p2-(p1<<1)+p0)+abs(q0-(q1<<1)+q2))<<1);
     2861        if (thr1 < a && a < thr2)
     2862        {
     2863          rowSAD[rowIdx] += abs(p0 - q0);
     2864        }
     2865      }
     2866      rowIdx++;
     2867    }
     2868  }
     2869 
     2870  UInt64 colSADsum = 0;
     2871  UInt64 rowSADsum = 0;
     2872  for(Int c = 0; c < noCol-1; c++)
     2873  {
     2874    colSADsum += colSAD[c];
     2875  }
     2876  for(Int r = 0; r < noRows-1; r++)
     2877  {
     2878    rowSADsum += rowSAD[r];
     2879  }
     2880 
     2881  colSADsum <<= 10;
     2882  rowSADsum <<= 10;
     2883  colSADsum /= (noCol-1);
     2884  colSADsum /= picHeight;
     2885  rowSADsum /= (noRows-1);
     2886  rowSADsum /= picWidth;
     2887 
     2888  UInt64 avgSAD = ((colSADsum + rowSADsum)>>1);
     2889  avgSAD >>= (g_bitDepthY-8);
     2890 
     2891  if ( avgSAD > 2048 )
     2892  {
     2893    avgSAD >>= 9;
     2894    Int offset = Clip3(2,6,(Int)avgSAD);
     2895    for (Int i=0; i<uiNumSlices; i++)
     2896    {
     2897      pcPic->getSlice(i)->setDeblockingFilterOverrideFlag(true);
     2898      pcPic->getSlice(i)->setDeblockingFilterDisable(false);
     2899      pcPic->getSlice(i)->setDeblockingFilterBetaOffsetDiv2( offset );
     2900      pcPic->getSlice(i)->setDeblockingFilterTcOffsetDiv2( offset );
     2901    }
     2902  }
     2903  else
     2904  {
     2905    for (Int i=0; i<uiNumSlices; i++)
     2906    {
     2907      pcPic->getSlice(i)->setDeblockingFilterOverrideFlag(false);
     2908      pcPic->getSlice(i)->setDeblockingFilterDisable(        pcPic->getSlice(i)->getPPS()->getPicDisableDeblockingFilterFlag() );
     2909      pcPic->getSlice(i)->setDeblockingFilterBetaOffsetDiv2( pcPic->getSlice(i)->getPPS()->getDeblockingFilterBetaOffsetDiv2() );
     2910      pcPic->getSlice(i)->setDeblockingFilterTcOffsetDiv2(   pcPic->getSlice(i)->getPPS()->getDeblockingFilterTcOffsetDiv2()   );
     2911    }
     2912  }
     2913 
     2914  free(colSAD);
     2915  free(rowSAD);
     2916}
     2917#endif
    25682918//! \}
Note: See TracChangeset for help on using the changeset viewer.