Changeset 310 in SHVCSoftware for trunk/source/Lib/TLibEncoder


Ignore:
Timestamp:
22 Jul 2013, 21:40:00 (12 years ago)
Author:
seregin
Message:

reintegrate SHM-2.1-dev branch

Location:
trunk
Files:
20 edited

Legend:

Unmodified
Added
Removed
  • trunk

  • trunk/source

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

    r191 r310  
    8484    fprintf( g_hTrace, "=========== Decoding Unit Information SEI message ===========\n");
    8585    break;
    86 #if J0149_TONE_MAPPING_SEI
    8786  case SEI::TONE_MAPPING_INFO:
    8887    fprintf( g_hTrace, "=========== Tone Mapping Info SEI message ===========\n");
    8988    break;
    90 #endif
    91 #if L0208_SOP_DESCRIPTION_SEI
     89#if M0043_LAYERS_PRESENT_SEI
     90  case SEI::LAYERS_PRESENT:
     91    fprintf( g_hTrace, "=========== Layers Present SEI message ===========\n");
     92    break;
     93#endif
    9294  case SEI::SOP_DESCRIPTION:
    9395    fprintf( g_hTrace, "=========== SOP Description SEI message ===========\n");
    9496    break;
    95 #endif
    96 #if K0180_SCALABLE_NESTING_SEI
    9797  case SEI::SCALABLE_NESTING:
    9898    fprintf( g_hTrace, "=========== Scalable Nesting SEI message ===========\n");
    9999    break;
    100 #endif
    101100  default:
    102101    fprintf( g_hTrace, "=========== Unknown SEI message ===========\n");
     
    106105#endif
    107106
    108 #if K0180_SCALABLE_NESTING_SEI
    109107void SEIWriter::xWriteSEIpayloadData(TComBitIf& bs, const SEI& sei, TComSPS *sps)
    110 #else
    111 void SEIWriter::xWriteSEIpayloadData(const SEI& sei, TComSPS *sps)
    112 #endif
    113108{
    114109  switch (sei.payloadType())
     
    147142    xWriteSEIGradualDecodingRefreshInfo(*static_cast<const SEIGradualDecodingRefreshInfo*>(&sei));
    148143    break;
    149 #if J0149_TONE_MAPPING_SEI
    150144  case SEI::TONE_MAPPING_INFO:
    151145    xWriteSEIToneMappingInfo(*static_cast<const SEIToneMappingInfo*>(&sei));
    152146    break;
    153 #endif
    154 #if L0208_SOP_DESCRIPTION_SEI
     147#if M0043_LAYERS_PRESENT_SEI
     148  case SEI::LAYERS_PRESENT:
     149    xWriteSEILayersPresent(*static_cast<const SEILayersPresent*>(&sei));
     150    break;
     151#endif
    155152  case SEI::SOP_DESCRIPTION:
    156153    xWriteSEISOPDescription(*static_cast<const SEISOPDescription*>(&sei));
    157154    break;
    158 #endif
    159 #if K0180_SCALABLE_NESTING_SEI
    160155  case SEI::SCALABLE_NESTING:
    161156    xWriteSEIScalableNesting(bs, *static_cast<const SEIScalableNesting*>(&sei), sps);
    162157    break;
    163 #endif
    164158  default:
    165159    assert(!"Unhandled SEI message");
     
    180174
    181175
    182 #if K0180_SCALABLE_NESTING_SEI
    183 
    184176#if ENC_DEC_TRACE
    185177  Bool traceEnable = g_HLSTraceEnable;
     
    191183#endif
    192184
    193 #else
    194 
    195 #if ENC_DEC_TRACE
    196   g_HLSTraceEnable = false;
    197 #endif
    198   xWriteSEIpayloadData(sei, sps);
    199 #if ENC_DEC_TRACE
    200   g_HLSTraceEnable = true;
    201 #endif
    202 
    203 #endif
    204 
    205185  UInt payload_data_num_bits = bs_count.getNumberOfWrittenBits();
    206186  assert(0 == payload_data_num_bits % 8);
     
    209189
    210190#if ENC_DEC_TRACE
    211 #if K0180_SCALABLE_NESTING_SEI
    212191  if (g_HLSTraceEnable)
    213 #endif
    214192  xTraceSEIHeader();
    215193#endif
     
    231209  /* payloadData */
    232210#if ENC_DEC_TRACE
    233 #if K0180_SCALABLE_NESTING_SEI
    234211  if (g_HLSTraceEnable)
    235 #endif
    236212  xTraceSEIMessageType(sei.payloadType());
    237213#endif
    238214
    239 #if K0180_SCALABLE_NESTING_SEI
    240215  xWriteSEIpayloadData(bs, sei, sps);
    241 #else
    242   xWriteSEIpayloadData(sei, sps);
    243 #endif
    244216}
    245217
     
    296268{
    297269  WRITE_CODE(sei.activeVPSId,     4, "active_vps_id");
    298 #if L0047_APS_FLAGS
    299270  WRITE_FLAG(sei.m_fullRandomAccessFlag, "full_random_access_flag");
    300271  WRITE_FLAG(sei.m_noParamSetUpdateFlag, "no_param_set_update_flag");
    301 #endif
    302272  WRITE_UVLC(sei.numSpsIdsMinus1,    "num_sps_ids_minus1");
    303273
     
    330300    WRITE_CODE( sei.m_duSptCpbRemovalDelay, (vui->getHrdParameters()->getDuCpbRemovalDelayLengthMinus1() + 1), "du_spt_cpb_removal_delay");
    331301  }
    332 #if L0044_DU_DPB_OUTPUT_DELAY_HRD
    333302  WRITE_FLAG( sei.m_dpbOutputDuDelayPresentFlag, "dpb_output_du_delay_present_flag");
    334303  if(sei.m_dpbOutputDuDelayPresentFlag)
     
    336305    WRITE_CODE(sei.m_picSptDpbOutputDuDelay, vui->getHrdParameters()->getDpbOutputDelayDuLengthMinus1() + 1, "pic_spt_dpb_output_du_delay");
    337306  }
    338 #endif
    339307  xWriteByteAlign();
    340308}
     
    351319    WRITE_FLAG( sei.m_rapCpbParamsPresentFlag, "rap_cpb_params_present_flag" );
    352320  }
    353 #if L0328_SPLICING
    354321  WRITE_FLAG( sei.m_concatenationFlag, "concatenation_flag");
    355322  WRITE_CODE( sei.m_auCpbRemovalDelayDelta - 1, ( hrd->getCpbRemovalDelayLengthMinus1() + 1 ), "au_cpb_removal_delay_delta_minus1" );
    356 #endif
    357 #if L0044_CPB_DPB_DELAY_OFFSET
    358323  if( sei.m_rapCpbParamsPresentFlag )
    359324  {
     
    361326    WRITE_CODE( sei.m_dpbDelayOffset, hrd->getDpbOutputDelayLengthMinus1()  + 1, "dpb_delay_offset" );
    362327  }
    363 #endif
    364328  for( nalOrVcl = 0; nalOrVcl < 2; nalOrVcl ++ )
    365329  {
     
    387351  TComHRD *hrd = vui->getHrdParameters();
    388352
    389 #if !L0045_CONDITION_SIGNALLING
    390   // This condition was probably OK before the pic_struct, progressive_source_idc, duplicate_flag were added
    391   if( !hrd->getNalHrdParametersPresentFlag() && !hrd->getVclHrdParametersPresentFlag() )
    392     return;
    393 #endif
    394353  if( vui->getFrameFieldInfoPresentFlag() )
    395354  {
    396355    WRITE_CODE( sei.m_picStruct, 4,              "pic_struct" );
    397 #if L0046_RENAME_PROG_SRC_IDC
    398356    WRITE_CODE( sei.m_sourceScanType, 2,         "source_scan_type" );
    399 #else
    400     WRITE_CODE( sei.m_progressiveSourceIdc, 2,   "progressive_source_idc" );
    401 #endif
    402357    WRITE_FLAG( sei.m_duplicateFlag ? 1 : 0,     "duplicate_flag" );
    403358  }
    404359
    405 #if L0045_CONDITION_SIGNALLING
    406360  if( hrd->getCpbDpbDelaysPresentFlag() )
    407361  {
    408 #endif
    409362    WRITE_CODE( sei.m_auCpbRemovalDelay - 1, ( hrd->getCpbRemovalDelayLengthMinus1() + 1 ),                                         "au_cpb_removal_delay_minus1" );
    410363    WRITE_CODE( sei.m_picDpbOutputDelay, ( hrd->getDpbOutputDelayLengthMinus1() + 1 ),                                          "pic_dpb_output_delay" );
    411 #if L0044_DU_DPB_OUTPUT_DELAY_HRD
    412364    if(hrd->getSubPicCpbParamsPresentFlag())
    413365    {
    414366      WRITE_CODE(sei.m_picDpbOutputDuDelay, hrd->getDpbOutputDelayDuLengthMinus1()+1, "pic_dpb_output_du_delay" );
    415367    }
    416 #endif
    417368    if( hrd->getSubPicCpbParamsPresentFlag() && hrd->getSubPicCpbParamsInPicTimingSEIFlag() )
    418369    {
     
    432383      }
    433384    }
    434 #if L0045_CONDITION_SIGNALLING
    435   }
    436 #endif
     385  }
    437386  xWriteByteAlign();
    438387}
     
    471420
    472421    WRITE_CODE( sei.m_arrangementReservedByte, 8,   "frame_packing_arrangement_reserved_byte" );
    473 #if L0045_PERSISTENCE_FLAGS
    474422    WRITE_FLAG( sei.m_arrangementPersistenceFlag,   "frame_packing_arrangement_persistence_flag" );
    475 #else
    476     WRITE_UVLC( sei.m_arrangementRepetetionPeriod,  "frame_packing_arrangement_repetition_period" );
    477 #endif
    478423  }
    479424
     
    483428}
    484429
    485 #if J0149_TONE_MAPPING_SEI
    486430Void SEIWriter::xWriteSEIToneMappingInfo(const SEIToneMappingInfo& sei)
    487431{
     
    555499  xWriteByteAlign();
    556500}
    557 #endif
    558501
    559502Void SEIWriter::xWriteSEIDisplayOrientation(const SEIDisplayOrientation &sei)
     
    565508    WRITE_FLAG( sei.verFlip,                   "ver_flip" );
    566509    WRITE_CODE( sei.anticlockwiseRotation, 16, "anticlockwise_rotation" );
    567 #if L0045_PERSISTENCE_FLAGS
    568510    WRITE_FLAG( sei.persistenceFlag,          "display_orientation_persistence_flag" );
    569 #else
    570     WRITE_UVLC( sei.repetitionPeriod,          "display_orientation_repetition_period" );
    571 #endif
    572 #if !REMOVE_SINGLE_SEI_EXTENSION_FLAGS
    573     WRITE_FLAG( sei.extensionFlag,             "display_orientation_extension_flag" );
    574     assert( !sei.extensionFlag );
    575 #endif
    576511  }
    577512  xWriteByteAlign();
     
    591526}
    592527
    593 #if L0208_SOP_DESCRIPTION_SEI
     528#if M0043_LAYERS_PRESENT_SEI
     529Void SEIWriter::xWriteSEILayersPresent(const SEILayersPresent& sei)
     530{
     531  WRITE_UVLC( sei.m_activeVpsId,           "lp_sei_active_vps_id" );
     532  for (UInt i = 0; i < sei.m_vpsMaxLayers; i++)
     533  {
     534    WRITE_FLAG( sei.m_layerPresentFlag[i], "layer_present_flag"   );
     535  }
     536  xWriteByteAlign();
     537}
     538#endif
     539
    594540Void SEIWriter::xWriteSEISOPDescription(const SEISOPDescription& sei)
    595541{
     
    612558  xWriteByteAlign();
    613559}
    614 #endif
    615 
    616 #if K0180_SCALABLE_NESTING_SEI
     560
    617561Void SEIWriter::xWriteSEIScalableNesting(TComBitIf& bs, const SEIScalableNesting& sei, TComSPS *sps)
    618562{
     
    656600  }
    657601}
    658 #endif
    659602
    660603Void SEIWriter::xWriteByteAlign()
  • trunk/source/Lib/TLibEncoder/SEIwrite.h

    r191 r310  
    5050
    5151protected:
    52 #if K0180_SCALABLE_NESTING_SEI
    5352  Void xWriteSEIpayloadData(TComBitIf& bs, const SEI& sei, TComSPS *sps);
    54 #else
    55   Void xWriteSEIpayloadData(const SEI& sei, TComSPS *sps);
    56 #endif
    5753  Void xWriteSEIuserDataUnregistered(const SEIuserDataUnregistered &sei);
    5854  Void xWriteSEIActiveParameterSets(const SEIActiveParameterSets& sei);
     
    6763  Void xWriteSEITemporalLevel0Index(const SEITemporalLevel0Index &sei);
    6864  Void xWriteSEIGradualDecodingRefreshInfo(const SEIGradualDecodingRefreshInfo &sei);
    69 #if J0149_TONE_MAPPING_SEI
    7065  Void xWriteSEIToneMappingInfo(const SEIToneMappingInfo& sei);
     66#if M0043_LAYERS_PRESENT_SEI
     67  Void xWriteSEILayersPresent(const SEILayersPresent& sei);
    7168#endif
    72 #if L0208_SOP_DESCRIPTION_SEI
    7369  Void xWriteSEISOPDescription(const SEISOPDescription& sei);
    74 #endif
    75 #if K0180_SCALABLE_NESTING_SEI
    7670  Void xWriteSEIScalableNesting(TComBitIf& bs, const SEIScalableNesting& sei, TComSPS *sps);
    77 #endif
    7871  Void xWriteByteAlign();
    7972};
  • trunk/source/Lib/TLibEncoder/TEncCavlc.cpp

    r191 r310  
    3939#include "TEncCavlc.h"
    4040#include "SEIwrite.h"
    41 #include <iostream>
     41
    4242//! \ingroup TLibEncoder
    4343//! \{
     
    163163  WRITE_UVLC( pcPPS->getSPSId(),                             "pps_seq_parameter_set_id" );
    164164  WRITE_FLAG( pcPPS->getDependentSliceSegmentsEnabledFlag()    ? 1 : 0, "dependent_slice_segments_enabled_flag" );
    165 #if L0255_MOVE_PPS_FLAGS
    166165  WRITE_FLAG( pcPPS->getOutputFlagPresentFlag() ? 1 : 0,     "output_flag_present_flag" );
    167166  WRITE_CODE( pcPPS->getNumExtraSliceHeaderBits(), 3,        "num_extra_slice_header_bits");
    168 #endif
    169167  WRITE_FLAG( pcPPS->getSignHideFlag(), "sign_data_hiding_flag" );
    170168  WRITE_FLAG( pcPPS->getCabacInitPresentFlag() ? 1 : 0,   "cabac_init_present_flag" );
     
    186184  WRITE_FLAG( pcPPS->getUseWP() ? 1 : 0,  "weighted_pred_flag" );   // Use of Weighting Prediction (P_SLICE)
    187185  WRITE_FLAG( pcPPS->getWPBiPred() ? 1 : 0, "weighted_bipred_flag" );  // Use of Weighting Bi-Prediction (B_SLICE)
    188 #if !L0255_MOVE_PPS_FLAGS
    189   WRITE_FLAG( pcPPS->getOutputFlagPresentFlag() ? 1 : 0,  "output_flag_present_flag" );
    190 #endif
    191186  WRITE_FLAG( pcPPS->getTransquantBypassEnableFlag() ? 1 : 0, "transquant_bypass_enable_flag" );
    192187  WRITE_FLAG( pcPPS->getTilesEnabledFlag()             ? 1 : 0, "tiles_enabled_flag" );
     
    235230  WRITE_FLAG( pcPPS->getListsModificationPresentFlag(), "lists_modification_present_flag");
    236231  WRITE_UVLC( pcPPS->getLog2ParallelMergeLevelMinus2(), "log2_parallel_merge_level_minus2");
    237 #if !L0255_MOVE_PPS_FLAGS
    238   WRITE_CODE( pcPPS->getNumExtraSliceHeaderBits(), 3, "num_extra_slice_header_bits");
    239 #endif
    240232  WRITE_FLAG( pcPPS->getSliceHeaderExtensionPresentFlag() ? 1 : 0, "slice_segment_header_extension_present_flag");
    241233  WRITE_FLAG( 0, "pps_extension_flag" );
     
    296288    WRITE_UVLC(defaultDisplayWindow.getWindowBottomOffset(),    "def_disp_win_bottom_offset");
    297289  }
    298 #if L0043_TIMING_INFO
    299290  TimingInfo *timingInfo = pcVUI->getTimingInfo();
    300291  WRITE_FLAG(timingInfo->getTimingInfoPresentFlag(),          "vui_timing_info_present_flag");
     
    308299      WRITE_UVLC(timingInfo->getNumTicksPocDiffOneMinus1(),   "vui_num_ticks_poc_diff_one_minus1");
    309300    }
    310 #endif
    311301  WRITE_FLAG(pcVUI->getHrdParametersPresentFlag(),              "hrd_parameters_present_flag");
    312302  if( pcVUI->getHrdParametersPresentFlag() )
     
    314304    codeHrdParameters(pcVUI->getHrdParameters(), 1, pcSPS->getMaxTLayers() - 1 );
    315305  }
    316 #if L0043_TIMING_INFO
    317   }
    318 #endif
    319 #if !L0043_TIMING_INFO
    320   WRITE_FLAG( pcVUI->getPocProportionalToTimingFlag(), "poc_proportional_to_timing_flag" );
    321   if( pcVUI->getPocProportionalToTimingFlag() && pcVUI->getHrdParameters()->getTimingInfoPresentFlag() )
    322   {
    323     WRITE_UVLC( pcVUI->getNumTicksPocDiffOneMinus1(), "num_ticks_poc_diff_one_minus1" );
    324   }
    325 #endif
     306  }
    326307
    327308  WRITE_FLAG(pcVUI->getBitstreamRestrictionFlag(),              "bitstream_restriction_flag");
     
    329310  {
    330311    WRITE_FLAG(pcVUI->getTilesFixedStructureFlag(),             "tiles_fixed_structure_flag");
     312#if M0464_TILE_BOUNDARY_ALIGNED_FLAG
     313    if ( pcSPS->getLayerId() > 0 )
     314    {
     315      WRITE_FLAG( pcVUI->getTileBoundariesAlignedFlag( ) ? 1 : 0 , "tile_boundaries_aligned_flag" );
     316    }
     317#endif
    331318    WRITE_FLAG(pcVUI->getMotionVectorsOverPicBoundariesFlag(),  "motion_vectors_over_pic_boundaries_flag");
    332319    WRITE_FLAG(pcVUI->getRestrictedRefPicListsFlag(),           "restricted_ref_pic_lists_flag");
    333 #if L0043_MSS_IDC
    334320    WRITE_UVLC(pcVUI->getMinSpatialSegmentationIdc(),           "min_spatial_segmentation_idc");
    335 #else
    336     WRITE_CODE(pcVUI->getMinSpatialSegmentationIdc(),        8, "min_spatial_segmentation_idc");
    337 #endif
    338321    WRITE_UVLC(pcVUI->getMaxBytesPerPicDenom(),                 "max_bytes_per_pic_denom");
    339322    WRITE_UVLC(pcVUI->getMaxBitsPerMinCuDenom(),                "max_bits_per_mincu_denom");
     
    347330  if( commonInfPresentFlag )
    348331  {
    349 #if !L0043_TIMING_INFO
    350     WRITE_FLAG( hrd->getTimingInfoPresentFlag() ? 1 : 0,        "timing_info_present_flag" );
    351     if( hrd->getTimingInfoPresentFlag() )
    352     {
    353       WRITE_CODE( hrd->getNumUnitsInTick(), 32,                  "num_units_in_tick" );
    354       WRITE_CODE( hrd->getTimeScale(),      32,                  "time_scale" );
    355     }
    356 #endif
    357332    WRITE_FLAG( hrd->getNalHrdParametersPresentFlag() ? 1 : 0 ,  "nal_hrd_parameters_present_flag" );
    358333    WRITE_FLAG( hrd->getVclHrdParametersPresentFlag() ? 1 : 0 ,  "vcl_hrd_parameters_present_flag" );
     
    365340        WRITE_CODE( hrd->getDuCpbRemovalDelayLengthMinus1(), 5,  "du_cpb_removal_delay_length_minus1" );
    366341        WRITE_FLAG( hrd->getSubPicCpbParamsInPicTimingSEIFlag() ? 1 : 0, "sub_pic_cpb_params_in_pic_timing_sei_flag" );
    367 #if L0044_DU_DPB_OUTPUT_DELAY_HRD
    368342        WRITE_CODE( hrd->getDpbOutputDelayDuLengthMinus1(), 5,   "dpb_output_delay_du_length_minus1"  );
    369 #endif
    370343      }
    371344      WRITE_CODE( hrd->getBitRateScale(), 4,                     "bit_rate_scale" );
     
    396369      WRITE_UVLC( hrd->getPicDurationInTcMinus1( i ),           "elemental_duration_in_tc_minus1");
    397370    }
    398 #if L0372
    399371    else
    400372    {
     
    405377      WRITE_UVLC( hrd->getCpbCntMinus1( i ),                      "cpb_cnt_minus1");
    406378    }
    407 #else
    408     WRITE_FLAG( hrd->getLowDelayHrdFlag( i ) ? 1 : 0,           "low_delay_hrd_flag");
    409     WRITE_UVLC( hrd->getCpbCntMinus1( i ),                      "cpb_cnt_minus1");
    410 #endif
    411379   
    412380    for( nalOrVcl = 0; nalOrVcl < 2; nalOrVcl ++ )
     
    421389          if( hrd->getSubPicCpbParamsPresentFlag() )
    422390          {
    423 #if L0363_DU_BIT_RATE
     391            WRITE_UVLC( hrd->getDuCpbSizeValueMinus1( i, j, nalOrVcl ), "cpb_size_du_value_minus1"); 
    424392            WRITE_UVLC( hrd->getDuBitRateValueMinus1( i, j, nalOrVcl ), "bit_rate_du_value_minus1");
    425 #endif
    426             WRITE_UVLC( hrd->getDuCpbSizeValueMinus1( i, j, nalOrVcl ), "cpb_size_du_value_minus1"); 
    427393          }
    428394          WRITE_FLAG( hrd->getCbrFlag( i, j, nalOrVcl ) ? 1 : 0, "cbr_flag");
     
    439405#endif
    440406  WRITE_CODE( pcSPS->getVPSId (),          4,       "sps_video_parameter_set_id" );
    441   WRITE_CODE( pcSPS->getMaxTLayers() - 1,  3,       "sps_max_sub_layers_minus1" );
    442   WRITE_FLAG( pcSPS->getTemporalIdNestingFlag() ? 1 : 0,                             "sps_temporal_id_nesting_flag" );
     407#if SPS_SUB_LAYER_INFO
     408  if(pcSPS->getLayerId() == 0)
     409  {
     410#endif
     411    WRITE_CODE( pcSPS->getMaxTLayers() - 1,  3,       "sps_max_sub_layers_minus1" );
     412    WRITE_FLAG( pcSPS->getTemporalIdNestingFlag() ? 1 : 0,                             "sps_temporal_id_nesting_flag" );
     413#if SPS_SUB_LAYER_INFO
     414  }
     415#endif
    443416  codePTL(pcSPS->getPTL(), 1, pcSPS->getMaxTLayers() - 1);
    444417  WRITE_UVLC( pcSPS->getSPSId (),                   "sps_seq_parameter_set_id" );
     
    473446  for(UInt i=0; i <= pcSPS->getMaxTLayers()-1; i++)
    474447  {
    475 #if L0323_DPB
    476448    WRITE_UVLC( pcSPS->getMaxDecPicBuffering(i) - 1,       "sps_max_dec_pic_buffering_minus1[i]" );
    477 #else
    478     WRITE_UVLC( pcSPS->getMaxDecPicBuffering(i),           "sps_max_dec_pic_buffering[i]" );
    479 #endif
    480449    WRITE_UVLC( pcSPS->getNumReorderPics(i),               "sps_num_reorder_pics[i]" );
    481     WRITE_UVLC( pcSPS->getMaxLatencyIncrease(i),           "sps_max_latency_increase[i]" );
     450    WRITE_UVLC( pcSPS->getMaxLatencyIncrease(i),           "sps_max_latency_increase_plus1[i]" );
    482451    if (!subLayerOrderingInfoPresentFlag)
    483452    {
     
    541510  WRITE_FLAG( pcSPS->getTMVPFlagsPresent()  ? 1 : 0,           "sps_temporal_mvp_enable_flag" );
    542511#if REF_IDX_MFM
     512#if !M0457_COL_PICTURE_SIGNALING
    543513  if( pcSPS->getLayerId() > 0 )
    544514  {
    545515    WRITE_FLAG( pcSPS->getMFMEnabledFlag() ? 1 : 0,          "sps_enh_mfm_enable_flag" );
    546516  }
     517#endif
    547518#endif
    548519  WRITE_FLAG( pcSPS->getUseStrongIntraSmoothing(),             "sps_strong_intra_smoothing_enable_flag" );
     
    553524      codeVUI(pcSPS->getVuiParameters(), pcSPS);
    554525  }
     526
     527#if SPS_EXTENSION
     528  WRITE_FLAG( 1, "sps_extension_flag" );
     529  if( 1 )   // if( sps_extension_flag )
     530  {
     531    codeSPSExtension( pcSPS );
     532    WRITE_FLAG( 0, "sps_extension2_flag" );
     533  }
     534#else
     535  WRITE_FLAG( 0, "sps_extension_flag" );
     536#endif
     537}
     538#if SPS_EXTENSION
     539Void TEncCavlc::codeSPSExtension( TComSPS* pcSPS )
     540{
     541  // more syntax elements to be written here
    555542#if SCALED_REF_LAYER_OFFSETS
     543#if SCALED_REF_LAYER_OFFSET_FLAG
     544  WRITE_FLAG( pcSPS->getLayerId() > 0, "scaled_ref_layer_offset_present_flag" );
    556545  if( pcSPS->getLayerId() > 0 )
    557   {
    558     Window scaledWindow = pcSPS->getScaledRefLayerWindow();
    559     WRITE_SVLC( scaledWindow.getWindowLeftOffset()   >> 1, "scaled_ref_layer_left_offset" );
    560     WRITE_SVLC( scaledWindow.getWindowTopOffset()    >> 1, "scaled_ref_layer_top_offset" );
    561     WRITE_SVLC( scaledWindow.getWindowRightOffset()  >> 1, "scaled_ref_layer_right_offset" );
    562     WRITE_SVLC( scaledWindow.getWindowBottomOffset() >> 1, "scaled_ref_layer_bottom_offset" );
    563   }
    564 #endif
    565 
    566   WRITE_FLAG( 0, "sps_extension_flag" );
    567 }
    568 
     546#else
     547  if( pcSPS->getLayerId() > 0 )
     548#endif
     549  {
     550    WRITE_UVLC( pcSPS->getNumScaledRefLayerOffsets(),      "num_scaled_ref_layer_offsets" );
     551    for(Int i = 0; i < pcSPS->getNumScaledRefLayerOffsets(); i++)
     552    {
     553      Window scaledWindow = pcSPS->getScaledRefLayerWindow(i);
     554      WRITE_SVLC( scaledWindow.getWindowLeftOffset()   >> 1, "scaled_ref_layer_left_offset" );
     555      WRITE_SVLC( scaledWindow.getWindowTopOffset()    >> 1, "scaled_ref_layer_top_offset" );
     556      WRITE_SVLC( scaledWindow.getWindowRightOffset()  >> 1, "scaled_ref_layer_right_offset" );
     557      WRITE_SVLC( scaledWindow.getWindowBottomOffset() >> 1, "scaled_ref_layer_bottom_offset" );
     558    }
     559  }
     560#endif
     561#if M0463_VUI_EXT_ILP_REF
     562  ////   sps_extension_vui_parameters( )
     563  if( pcSPS->getVuiParameters()->getBitstreamRestrictionFlag() )
     564  { 
     565    WRITE_UVLC( pcSPS->getNumIlpRestrictedRefLayers( ),           "num_ilp_restricted_ref_layers" );
     566    for( Int i = 0; i < pcSPS->getNumIlpRestrictedRefLayers( ); i++ )
     567    { 
     568      WRITE_UVLC( pcSPS->getMinSpatialSegmentOffsetPlus1( i ),    "min_spatial_segment_offset_plus1" );
     569      if( pcSPS->getMinSpatialSegmentOffsetPlus1( i ) > 0 )
     570      { 
     571        WRITE_FLAG( pcSPS->getCtuBasedOffsetEnabledFlag( i ),      "ctu_based_offset_enabled_flag[ i ]");
     572        if( pcSPS->getCtuBasedOffsetEnabledFlag( i ) ) 
     573        {
     574          WRITE_UVLC( pcSPS->getMinHorizontalCtuOffsetPlus1( i ), "min_horizontal_ctu_offset_plus1[ i ]");
     575        }
     576      } 
     577    } 
     578  } 
     579  ////   sps_extension_vui_parameters( ) END
     580#endif
     581}
     582#endif
    569583Void TEncCavlc::codeVPS( TComVPS* pcVPS )
    570584{
     
    581595  WRITE_CODE( 0xffff,                              16,        "vps_reserved_ffff_16bits" );
    582596  codePTL( pcVPS->getPTL(), true, pcVPS->getMaxTLayers() - 1 );
    583 #if SIGNAL_BITRATE_PICRATE_IN_VPS
    584   codeBitratePicRateInfo(pcVPS->getBitratePicrateInfo(), 0, pcVPS->getMaxTLayers() - 1);
    585 #endif 
    586597  const Bool subLayerOrderingInfoPresentFlag = 1;
    587598  WRITE_FLAG(subLayerOrderingInfoPresentFlag,              "vps_sub_layer_ordering_info_present_flag");
    588599  for(UInt i=0; i <= pcVPS->getMaxTLayers()-1; i++)
    589600  {
    590 #if L0323_DPB
    591601    WRITE_UVLC( pcVPS->getMaxDecPicBuffering(i) - 1,       "vps_max_dec_pic_buffering_minus1[i]" );
    592 #else
    593     WRITE_UVLC( pcVPS->getMaxDecPicBuffering(i),           "vps_max_dec_pic_buffering[i]" );
    594 #endif
    595602    WRITE_UVLC( pcVPS->getNumReorderPics(i),               "vps_num_reorder_pics[i]" );
    596     WRITE_UVLC( pcVPS->getMaxLatencyIncrease(i),           "vps_max_latency_increase[i]" );
     603    WRITE_UVLC( pcVPS->getMaxLatencyIncrease(i),           "vps_max_latency_increase_plus1[i]" );
    597604    if (!subLayerOrderingInfoPresentFlag)
    598605    {
     
    635642  pcVPS->deriveLayerIdListVariables();
    636643#endif
    637 #if L0043_TIMING_INFO
    638644  TimingInfo *timingInfo = pcVPS->getTimingInfo();
    639645  WRITE_FLAG(timingInfo->getTimingInfoPresentFlag(),          "vps_timing_info_present_flag");
     
    647653      WRITE_UVLC(timingInfo->getNumTicksPocDiffOneMinus1(),   "vps_num_ticks_poc_diff_one_minus1");
    648654    }
    649 #endif
    650655    pcVPS->setNumHrdParameters( 0 );
    651656    WRITE_UVLC( pcVPS->getNumHrdParameters(),                 "vps_num_hrd_parameters" );
     
    666671      codeHrdParameters(pcVPS->getHrdParameters(i), pcVPS->getCprmsPresentFlag( i ), pcVPS->getMaxTLayers() - 1);
    667672    }
    668 #if L0043_TIMING_INFO
    669   }
    670 #endif
     673  }
    671674#if !VPS_EXTNS
    672675  WRITE_FLAG( 0,                     "vps_extension_flag" );
     
    696699  }
    697700
     701#if VPS_SPLIT_FLAG
     702  for(j = 0; j < vps->getNumScalabilityTypes() - vps->getSplittingFlag(); j++)
     703#else
    698704  for(j = 0; j < vps->getNumScalabilityTypes(); j++)
     705#endif
    699706  {
    700707    WRITE_CODE( vps->getDimensionIdLen(j) - 1, 3,      "dimension_id_len_minus1[j]" );
     
    708715      WRITE_CODE( vps->getLayerIdInNuh(i),     6,      "layer_id_in_nuh[i]" );
    709716    }
     717#if VPS_SPLIT_FLAG
     718    if(!vps->getSplittingFlag())
     719#endif
    710720    for(j = 0; j < vps->getNumScalabilityTypes(); j++)
    711721    {
     
    725735  }
    726736#endif
     737#endif
     738#if JCTVC_M0203_INTERLAYER_PRED_IDC
     739  for( i = 0; i < vps->getMaxLayers() - 1; i++)
     740  {
     741    WRITE_CODE(vps->getMaxSublayerForIlpPlus1(i), 3, "max_sublayer_for_ilp_plus1[i]" );
     742  }
    727743#endif
    728744#if VPS_EXTN_PROFILE_INFO
     
    821837#endif
    822838#endif
     839#if VPS_EXTN_DIRECT_REF_LAYERS && M0457_PREDICTION_INDICATIONS
     840  WRITE_UVLC( vps->getDirectDepTypeLen()-2,                           "direct_dep_type_len_minus2");
     841  for(i = 1; i < vps->getMaxLayers(); i++)
     842  {
     843    for(j = 0; j < i; j++)
     844    {
     845      if (vps->getDirectDependencyFlag(i, j))
     846      {
     847        WRITE_CODE( vps->getDirectDependencyType(i, j), vps->getDirectDepTypeLen(), "direct_dependency_type[i][j]" );
     848      }
     849    }
     850  }
     851#endif
     852#if M0040_ADAPTIVE_RESOLUTION_CHANGE
     853  WRITE_FLAG(vps->getSingleLayerForNonIrapFlag(), "single_layer_for_non_irap_flag" );
     854#endif
    823855}
    824856#endif
     
    868900  if ( !pcSlice->getDependentSliceSegmentFlag() )
    869901  {
    870     for (Int i = 0; i < pcSlice->getPPS()->getNumExtraSliceHeaderBits(); i++)
     902
     903#if SH_DISCARDABLE_FLAG
     904    if (pcSlice->getPPS()->getNumExtraSliceHeaderBits()>0)
     905    {
     906      assert(!!"discardable_flag");
     907      WRITE_FLAG(pcSlice->getDiscardableFlag(), "discardable_flag");
     908    }
     909    for (Int i = 1; i < pcSlice->getPPS()->getNumExtraSliceHeaderBits(); i++)
    871910    {
    872911      assert(!!"slice_reserved_undetermined_flag[]");
    873912      WRITE_FLAG(0, "slice_reserved_undetermined_flag[]");
    874913    }
     914#else
     915    for (Int i = 0; i < pcSlice->getPPS()->getNumExtraSliceHeaderBits(); i++)
     916    {
     917      assert(!!"slice_reserved_undetermined_flag[]");
     918      WRITE_FLAG(0, "slice_reserved_undetermined_flag[]");
     919    }
     920#endif
    875921
    876922    WRITE_UVLC( pcSlice->getSliceType(),       "slice_type" );
     
    893939     
    894940#if FIX1071
    895       // Deal with bitstream restriction stating that:
    896       // If the current picture is a BLA or CRA picture, the value of NumPocTotalCurr shall be equal to 0.
     941      // check for bitstream restriction stating that:
     942      // If the current picture is a BLA or CRA picture, the value of NumPocTotalCurr shall be equal to 0.
    897943      // Ideally this process should not be repeated for each slice in a picture
    898       TComReferencePictureSet altRps;
    899       Bool useAltRps = false;
    900944#if SVC_EXTENSION
    901945      if( pcSlice->getLayerId() == 0 )
    902946#endif
    903       if (pcSlice->getRapPicFlag())
    904       {
    905         for (Int picIdx = 0; !useAltRps && picIdx < rps->getNumberOfPictures(); picIdx++)
    906         {
    907           useAltRps = rps->getUsed(picIdx);
    908         }
    909         if (useAltRps)
    910         {
    911           memcpy(&altRps, rps, sizeof(TComReferencePictureSet));
    912           rps = &altRps;
    913           for (Int picIdx = 0; picIdx < rps->getNumberOfPictures(); picIdx++)
    914           {
    915             rps->setUsed(picIdx, false);
    916           }
    917         }
    918       }
    919 
    920       if(pcSlice->getRPSidx() < 0 || useAltRps)
    921 #else
     947      if (pcSlice->isIRAP())
     948      {
     949        for (Int picIdx = 0; picIdx < rps->getNumberOfPictures(); picIdx++)
     950        {
     951          assert (!rps->getUsed(picIdx));
     952        }
     953      }
     954#endif
     955
    922956      if(pcSlice->getRPSidx() < 0)
    923 #endif
    924957      {
    925958        WRITE_FLAG( 0, "short_term_ref_pic_set_sps_flag");
     
    10131046        }
    10141047      }
    1015 
    10161048      if (pcSlice->getSPS()->getTMVPFlagsPresent())
    10171049      {
     
    10351067          if( !pcSlice->getVPS()->getMaxOneActiveRefLayerFlag())
    10361068          {
    1037             WRITE_CODE(pcSlice->getNumInterLayerRefPics(), numBits,"num_inter_layer_ref_pics_minus1");
     1069            WRITE_CODE(pcSlice->getActiveNumILRRefIdx() - 1, numBits,"num_inter_layer_ref_pics_minus1");
    10381070          }       
    1039           for(Int i = 0; i < pcSlice->getActiveNumILRRefIdx(); i++ )
     1071          for(Int i = 0; i < pcSlice->getActiveNumILRRefIdx(); i++ )
     1072          {
    10401073            WRITE_CODE(pcSlice->getInterLayerPredLayerIdc(i),numBits,"inter_layer_pred_layer_idc[i]");   
     1074          }
    10411075        }
    10421076      }
    10431077    }     
     1078#if M0457_IL_SAMPLE_PRED_ONLY_FLAG
     1079    if( pcSlice->getNumSamplePredRefLayers() > 0 && pcSlice->getActiveNumILRRefIdx() > 0 )
     1080    {
     1081      WRITE_FLAG( pcSlice->getInterLayerSamplePredOnlyFlag(), "inter_layer_sample_pred_only_flag" );
     1082    }
     1083#endif
    10441084#endif
    10451085
     
    11471187    if ( pcSlice->getEnableTMVPFlag() )
    11481188    {
     1189#if REF_IDX_FRAMEWORK && M0457_COL_PICTURE_SIGNALING
     1190      if ( !pcSlice->getIdrPicFlag() && pcSlice->getLayerId() > 0 && pcSlice->getActiveNumILRRefIdx() > 0 && pcSlice->getNumMotionPredRefLayers() > 0 )
     1191      {
     1192        WRITE_FLAG( pcSlice->getAltColIndicationFlag() ? 1 : 0, "alt_collocated_indication_flag" );
     1193        if (pcSlice->getAltColIndicationFlag() && pcSlice->getNumMotionPredRefLayers() > 1)
     1194        {
     1195          WRITE_UVLC(0, "collocated_ref_layer_idx");
     1196        }
     1197      }
     1198      else
     1199      {
     1200#endif
    11491201      if ( pcSlice->getSliceType() == B_SLICE )
    11501202      {
     
    11581210        WRITE_UVLC( pcSlice->getColRefIdx(), "collocated_ref_idx" );
    11591211      }
     1212#if REF_IDX_FRAMEWORK && M0457_COL_PICTURE_SIGNALING
     1213      }
     1214#endif
    11601215    }
    11611216    if ( (pcSlice->getPPS()->getUseWP() && pcSlice->getSliceType()==P_SLICE) || (pcSlice->getPPS()->getWPBiPred() && pcSlice->getSliceType()==B_SLICE) )
     
    12021257    }
    12031258  }
    1204 
    12051259  if(pcSlice->getPPS()->getSliceHeaderExtensionPresentFlag())
    12061260  {
     
    12171271  WRITE_CODE( pcPTL->getGeneralPTL()->getLevelIdc(), 8, "general_level_idc" );
    12181272
    1219 #if L0363_BYTE_ALIGN
    12201273  for (Int i = 0; i < maxNumSubLayersMinus1; i++)
    12211274  {
     
    12351288    }
    12361289  }
    1237 #endif
    12381290 
    12391291  for(Int i = 0; i < maxNumSubLayersMinus1; i++)
    12401292  {
    1241 #if !L0363_BYTE_ALIGN
    1242     if(profilePresentFlag)
    1243     {
    1244       WRITE_FLAG( pcPTL->getSubLayerProfilePresentFlag(i), "sub_layer_profile_present_flag[i]" );
    1245     }
    1246 
    1247     WRITE_FLAG( pcPTL->getSubLayerLevelPresentFlag(i),   "sub_layer_level_present_flag[i]" );
    1248 #endif
    12491293    if( profilePresentFlag && pcPTL->getSubLayerProfilePresentFlag(i) )
    12501294    {
     
    12671311  }
    12681312
    1269 #if L0046_CONSTRAINT_FLAGS
    12701313  WRITE_FLAG(ptl->getProgressiveSourceFlag(),   "general_progressive_source_flag");
    12711314  WRITE_FLAG(ptl->getInterlacedSourceFlag(),    "general_interlaced_source_flag");
     
    12761319  WRITE_CODE(0 , 16, "XXX_reserved_zero_44bits[16..31]");
    12771320  WRITE_CODE(0 , 12, "XXX_reserved_zero_44bits[32..43]");
    1278 #elif L0363_MORE_BITS
    1279   WRITE_CODE(0 , 16, "XXX_reserved_zero_48bits[0..15]");
    1280   WRITE_CODE(0 , 16, "XXX_reserved_zero_48bits[16..31]");
    1281   WRITE_CODE(0 , 16, "XXX_reserved_zero_48bits[32..47]");
    1282 #else
    1283   WRITE_CODE(0 , 16, "XXX_reserved_zero_16bits[]");
    1284 #endif
    1285 }
    1286 #if SIGNAL_BITRATE_PICRATE_IN_VPS
    1287 Void TEncCavlc::codeBitratePicRateInfo(TComBitRatePicRateInfo *info, Int tempLevelLow, Int tempLevelHigh)
    1288 {
    1289   for(Int i = tempLevelLow; i <= tempLevelHigh; i++)
    1290   {
    1291     WRITE_FLAG( info->getBitRateInfoPresentFlag(i),  "bit_rate_info_present_flag[i]" );
    1292     WRITE_FLAG( info->getPicRateInfoPresentFlag(i),  "pic_rate_info_present_flag[i]" );
    1293     if(info->getBitRateInfoPresentFlag(i))
    1294     {
    1295       WRITE_CODE( info->getAvgBitRate(i), 16, "avg_bit_rate[i]" );
    1296       WRITE_CODE( info->getMaxBitRate(i), 16, "max_bit_rate[i]" );
    1297     }
    1298     if(info->getPicRateInfoPresentFlag(i))
    1299     {
    1300       WRITE_CODE( info->getConstantPicRateIdc(i),  2, "constant_pic_rate_idc[i]" );
    1301       WRITE_CODE( info->getAvgPicRate(i),         16, "avg_pic_rate[i]"          );
    1302     }
    1303   }
    1304 }
    1305 #endif 
     1321}
     1322
    13061323/**
    13071324 - write wavefront substreams sizes for the slice header.
     
    13731390  for (UInt idx=0; idx<numEntryPointOffsets; idx++)
    13741391  {
    1375 #if L0116_ENTRY_POINT
    13761392    WRITE_CODE(entryPointOffset[ idx ]-1, offsetLenMinus1+1, "entry_point_offset_minus1");
    1377 #else
    1378     WRITE_CODE(entryPointOffset[ idx ], offsetLenMinus1+1, "entry_point_offset");
    1379 #endif
    13801393  }
    13811394
  • trunk/source/Lib/TLibEncoder/TEncCavlc.h

    r191 r310  
    8989  Void  codeVUI                 ( TComVUI *pcVUI, TComSPS* pcSPS );
    9090  Void  codeSPS                 ( TComSPS* pcSPS );
     91#if SPS_EXTENSION
     92  Void codeSPSExtension         ( TComSPS* pcSPS );
     93#endif
    9194  Void  codePPS                 ( TComPPS* pcPPS );
    9295  Void  codeSliceHeader         ( TComSlice* pcSlice );
    9396  Void  codePTL                 ( TComPTL* pcPTL, Bool profilePresentFlag, Int maxNumSubLayersMinus1);
    9497  Void  codeProfileTier         ( ProfileTierLevel* ptl );
    95 #if SIGNAL_BITRATE_PICRATE_IN_VPS
    96   Void codeBitratePicRateInfo(TComBitRatePicRateInfo *info, Int tempLevelLow, Int tempLevelHigh);
    97 #endif
    9898  Void  codeHrdParameters       ( TComHRD *hrd, Bool commonInfPresentFlag, UInt maxNumSubLayersMinus1 );
    9999  Void  codeTilesWPPEntryPoint( TComSlice* pSlice );
  • trunk/source/Lib/TLibEncoder/TEncCfg.h

    r191 r310  
    116116  Level::Tier   m_levelTier;
    117117  Level::Name   m_level;
    118 #if L0046_CONSTRAINT_FLAGS
    119118  Bool m_progressiveSourceFlag;
    120119  Bool m_interlacedSourceFlag;
    121120  Bool m_nonPackedConstraintFlag;
    122121  Bool m_frameOnlyConstraintFlag;
    123 #endif
    124122
    125123  //====== Coding Structure ========
     
    145143  Int       m_numDirectRefLayers;
    146144  Int       m_refLayerId[MAX_VPS_LAYER_ID_PLUS1];
     145
     146  Int       m_numActiveRefLayers;
     147  Int       m_predLayerId[MAX_VPS_LAYER_ID_PLUS1];
     148#if M0457_PREDICTION_INDICATIONS
     149  Int       m_numSamplePredRefLayers;
     150  Int       m_samplePredRefLayerId[MAX_VPS_LAYER_ID_PLUS1];
     151  Int       m_numMotionPredRefLayers;
     152  Int       m_motionPredRefLayerId[MAX_VPS_LAYER_ID_PLUS1];
     153  Bool      m_samplePredEnabledFlag[MAX_VPS_LAYER_ID_PLUS1];
     154  Bool      m_motionPredEnabledFlag[MAX_VPS_LAYER_ID_PLUS1];
     155#endif
    147156#endif
    148157  //======= Transform =============
     
    158167  Int       m_loopFilterTcOffsetDiv2;
    159168  Bool      m_DeblockingFilterControlPresent;
    160 #if L0386_DB_METRIC
    161169  Bool      m_DeblockingFilterMetric;
    162 #endif
    163170  Bool      m_bUseSAO;
    164171  Int       m_maxNumOffsetsPerPic;
     
    191198  Bool      m_bUseASR;
    192199  Bool      m_bUseHADME;
    193 #if !L0034_COMBINED_LIST_CLEANUP
    194   Bool      m_bUseLComb;
    195 #endif
    196200  Bool      m_useRDOQ;
    197201  Bool      m_useRDOQTS;
    198 #if L0232_RD_PENALTY
    199202  UInt      m_rdPenalty;
    200 #endif
    201203  Bool      m_bUseFastEnc;
    202204  Bool      m_bUseEarlyCU;
     
    204206  Bool      m_bUseCbfFastMode;
    205207  Bool      m_useEarlySkipDetection;
     208#if FAST_INTRA_SHVC
     209  Bool      m_useFastIntraScalable;
     210#endif
    206211  Bool      m_useTransformSkip;
    207212  Bool      m_useTransformSkipFast;
     
    239244  Int       m_pictureTimingSEIEnabled;
    240245  Int       m_recoveryPointSEIEnabled;
    241 #if J0149_TONE_MAPPING_SEI
    242246  Bool      m_toneMappingInfoSEIEnabled;
    243247  Int       m_toneMapId;
     
    265269  Int*      m_codedPivotValue;
    266270  Int*      m_targetPivotValue;
    267 #endif
    268271  Int       m_framePackingSEIEnabled;
    269272  Int       m_framePackingSEIType;
     
    275278  Int       m_gradualDecodingRefreshInfoEnabled;
    276279  Int       m_decodingUnitInfoSEIEnabled;
    277 #if L0208_SOP_DESCRIPTION_SEI
     280#if M0043_LAYERS_PRESENT_SEI
     281  Int       m_layersPresentSEIEnabled;
     282#endif
    278283  Int       m_SOPDescriptionSEIEnabled;
    279 #endif
    280 #if K0180_SCALABLE_NESTING_SEI
    281284  Int       m_scalableNestingSEIEnabled;
    282 #endif
    283285  //====== Weighted Prediction ========
    284286  Bool      m_useWeightedPred;       //< Use of Weighting Prediction (P_SLICE)
     
    293295  Bool      m_RCEnableRateControl;
    294296  Int       m_RCTargetBitrate;
     297#if M0036_RC_IMPROVEMENT
     298  Int       m_RCKeepHierarchicalBit;
     299#else
    295300  Bool      m_RCKeepHierarchicalBit;
     301#endif
    296302  Bool      m_RCLCULevelRC;
    297303  Bool      m_RCUseLCUSeparateModel;
     
    351357  Int      m_elRapSliceBEnabled;
    352358#endif
     359#if M0040_ADAPTIVE_RESOLUTION_CHANGE
     360  Int      m_adaptiveResolutionChange;
     361#endif
    353362
    354363public:
     
    402411  Int       getRefLayerId                   (Int i)                         { return m_refLayerId[i];           }
    403412  Void      setRefLayerId                   (Int i, Int refLayerId)         { m_refLayerId[i] = refLayerId;     }
     413
     414  Int       getNumActiveRefLayers           ()                              { return m_numActiveRefLayers;      }
     415  Void      setNumActiveRefLayers           (Int num)                       { m_numActiveRefLayers = num;       }
     416
     417  Int       getPredLayerId                  (Int i)                         { return m_predLayerId[i];          }
     418  Void      setPredLayerId                  (Int i, Int refLayerId)         { m_predLayerId[i] = refLayerId;    }
     419
     420#if M0457_PREDICTION_INDICATIONS
     421  Int       getNumSamplePredRefLayers       ()                              { return m_numSamplePredRefLayers;  }
     422  Void      setNumSamplePredRefLayers       (Int num)                       { m_numSamplePredRefLayers = num;   }
     423
     424  Int       getSamplePredRefLayerId         (Int i)                         { return m_samplePredRefLayerId[i];       }
     425  Void      setSamplePredRefLayerId         (Int i, Int refLayerId)         { m_samplePredRefLayerId[i] = refLayerId; }
     426
     427  Int       getNumMotionPredRefLayers       ()                              { return m_numMotionPredRefLayers;  }
     428  Void      setNumMotionPredRefLayers       (Int num)                       { m_numMotionPredRefLayers = num;   }
     429
     430  Int       getMotionPredRefLayerId         (Int i)                         { return m_motionPredRefLayerId[i];       }
     431  Void      setMotionPredRefLayerId         (Int i, Int refLayerId)         { m_motionPredRefLayerId[i] = refLayerId; }
     432
     433  Bool      getSamplePredEnabledFlag        (Int i)                         { return m_samplePredEnabledFlag[i];  }
     434  Void      setSamplePredEnabledFlag        (Int i,Bool flag)               { m_samplePredEnabledFlag[i] = flag;  }
     435
     436  Bool      getMotionPredEnabledFlag        (Int i)                         { return m_motionPredEnabledFlag[i];  }
     437  Void      setMotionPredEnabledFlag        (Int i,Bool flag)               { m_motionPredEnabledFlag[i] = flag;  }
     438#endif
    404439#endif
    405440  //======== Transform =============
     
    417452  Void      setLoopFilterTcOffset           ( Int   i )      { m_loopFilterTcOffsetDiv2    = i; }
    418453  Void      setDeblockingFilterControlPresent ( Bool b ) { m_DeblockingFilterControlPresent = b; }
    419 #if L0386_DB_METRIC
    420454  Void      setDeblockingFilterMetric       ( Bool  b )      { m_DeblockingFilterMetric = b; }
    421 #endif
    422455
    423456  //====== Motion search ========
     
    474507  Int       getLoopFilterTcOffset           ()      { return m_loopFilterTcOffsetDiv2; }
    475508  Bool      getDeblockingFilterControlPresent()  { return  m_DeblockingFilterControlPresent; }
    476 #if L0386_DB_METRIC
    477509  Bool      getDeblockingFilterMetric       ()      { return m_DeblockingFilterMetric; }
    478 #endif
    479510
    480511  //==== Motion search ========
     
    494525  Void      setUseASR                       ( Bool  b )     { m_bUseASR     = b; }
    495526  Void      setUseHADME                     ( Bool  b )     { m_bUseHADME   = b; }
    496 #if !L0034_COMBINED_LIST_CLEANUP
    497   Void      setUseLComb                     ( Bool  b )     { m_bUseLComb   = b; }
    498 #endif
    499527  Void      setUseRDOQ                      ( Bool  b )     { m_useRDOQ    = b; }
    500528  Void      setUseRDOQTS                    ( Bool  b )     { m_useRDOQTS  = b; }
    501 #if L0232_RD_PENALTY
    502529  Void      setRDpenalty                 ( UInt  b )     { m_rdPenalty  = b; }
    503 #endif
    504530  Void      setUseFastEnc                   ( Bool  b )     { m_bUseFastEnc = b; }
    505531  Void      setUseEarlyCU                   ( Bool  b )     { m_bUseEarlyCU = b; }
     
    507533  Void      setUseCbfFastMode            ( Bool  b )     { m_bUseCbfFastMode = b; }
    508534  Void      setUseEarlySkipDetection        ( Bool  b )     { m_useEarlySkipDetection = b; }
     535#if FAST_INTRA_SHVC
     536  Void      setUseFastIntraScalable         ( Bool  b )     { m_useFastIntraScalable = b; }
     537#endif
    509538  Void      setUseConstrainedIntraPred      ( Bool  b )     { m_bUseConstrainedIntraPred = b; }
    510539  Void      setPCMInputBitDepthFlag         ( Bool  b )     { m_bPCMInputBitDepthFlag = b; }
     
    518547  Bool      getUseASR                       ()      { return m_bUseASR;     }
    519548  Bool      getUseHADME                     ()      { return m_bUseHADME;   }
    520 #if !L0034_COMBINED_LIST_CLEANUP
    521   Bool      getUseLComb                     ()      { return m_bUseLComb;   }
    522 #endif
    523549  Bool      getUseRDOQ                      ()      { return m_useRDOQ;    }
    524550  Bool      getUseRDOQTS                    ()      { return m_useRDOQTS;  }
    525 #if L0232_RD_PENALTY
    526551  Int      getRDpenalty                  ()      { return m_rdPenalty;  }
    527 #endif
    528552  Bool      getUseFastEnc                   ()      { return m_bUseFastEnc; }
    529553  Bool      getUseEarlyCU                   ()      { return m_bUseEarlyCU; }
     
    531555  Bool      getUseCbfFastMode           ()      { return m_bUseCbfFastMode; }
    532556  Bool      getUseEarlySkipDetection        ()      { return m_useEarlySkipDetection; }
     557#if FAST_INTRA_SHVC
     558  Bool      getUseFastIntraScalable         ()      { return m_useFastIntraScalable; }
     559#endif
    533560  Bool      getUseConstrainedIntraPred      ()      { return m_bUseConstrainedIntraPred; }
    534561  Bool      getPCMInputBitDepthFlag         ()      { return m_bPCMInputBitDepthFlag;   }
     
    617644  Void  setRecoveryPointSEIEnabled(Int b)                { m_recoveryPointSEIEnabled = b; }
    618645  Int   getRecoveryPointSEIEnabled()                     { return m_recoveryPointSEIEnabled; }
    619 #if J0149_TONE_MAPPING_SEI
    620646  Void  setToneMappingInfoSEIEnabled(Bool b)                 {  m_toneMappingInfoSEIEnabled = b;  }
    621647  Bool  getToneMappingInfoSEIEnabled()                       {  return m_toneMappingInfoSEIEnabled;  }
     
    668694  Void  setTMISEIExtendedWhiteLevelLumaCodeValue(Int b)      {  m_extendedWhiteLevelLumaCodeValue =b;  }
    669695  Int   getTMISEIExtendedWhiteLevelLumaCodeValue()           {  return m_extendedWhiteLevelLumaCodeValue;  }
    670 #endif
    671696  Void  setFramePackingArrangementSEIEnabled(Int b)      { m_framePackingSEIEnabled = b; }
    672697  Int   getFramePackingArrangementSEIEnabled()           { return m_framePackingSEIEnabled; }
     
    687712  Void  setDecodingUnitInfoSEIEnabled(Int b)                { m_decodingUnitInfoSEIEnabled = b;    }
    688713  Int   getDecodingUnitInfoSEIEnabled()                     { return m_decodingUnitInfoSEIEnabled; }
    689 #if L0208_SOP_DESCRIPTION_SEI
     714#if M0043_LAYERS_PRESENT_SEI
     715  Void  setLayersPresentSEIEnabled(Int b)                { m_layersPresentSEIEnabled = b; }
     716  Int   getLayersPresentSEIEnabled()                     { return m_layersPresentSEIEnabled; }
     717#endif
    690718  Void  setSOPDescriptionSEIEnabled(Int b)                { m_SOPDescriptionSEIEnabled = b; }
    691719  Int   getSOPDescriptionSEIEnabled()                     { return m_SOPDescriptionSEIEnabled; }
    692 #endif
    693 #if K0180_SCALABLE_NESTING_SEI
    694720  Void  setScalableNestingSEIEnabled(Int b)                { m_scalableNestingSEIEnabled = b; }
    695721  Int   getScalableNestingSEIEnabled()                     { return m_scalableNestingSEIEnabled; }
    696 #endif
    697722  Void      setUseWP               ( Bool b )    { m_useWeightedPred   = b;    }
    698723  Void      setWPBiPred            ( Bool b )    { m_useWeightedBiPred = b;    }
     
    716741  Int       getTargetBitrate       ()              { return m_RCTargetBitrate;       }
    717742  Void      setTargetBitrate       ( Int bitrate ) { m_RCTargetBitrate  = bitrate;   }
     743#if M0036_RC_IMPROVEMENT
     744  Int       getKeepHierBit         ()              { return m_RCKeepHierarchicalBit; }
     745  Void      setKeepHierBit         ( Int i )       { m_RCKeepHierarchicalBit = i;    }
     746#else
    718747  Bool      getKeepHierBit         ()              { return m_RCKeepHierarchicalBit; }
    719748  Void      setKeepHierBit         ( Bool b )      { m_RCKeepHierarchicalBit = b;    }
     749#endif
    720750  Bool      getLCULevelRC          ()              { return m_RCLCULevelRC; }
    721751  Void      setLCULevelRC          ( Bool b )      { m_RCLCULevelRC = b; }
     
    809839  Void      setLog2MaxMvLengthVertical(Int i)             { m_log2MaxMvLengthVertical = i; }
    810840 
    811 #if L0046_CONSTRAINT_FLAGS
    812841  Bool getProgressiveSourceFlag() const { return m_progressiveSourceFlag; }
    813842  Void setProgressiveSourceFlag(Bool b) { m_progressiveSourceFlag = b; }
     
    821850  Bool getFrameOnlyConstraintFlag() const { return m_frameOnlyConstraintFlag; }
    822851  Void setFrameOnlyConstraintFlag(Bool b) { m_frameOnlyConstraintFlag = b; }
    823 #endif
    824852
    825853#if SVC_EXTENSION
     
    835863  Int       getElRapSliceTypeB()              {return m_elRapSliceBEnabled;}
    836864#endif
     865#if M0040_ADAPTIVE_RESOLUTION_CHANGE
     866  Void      setAdaptiveResolutionChange(Int x) { m_adaptiveResolutionChange = x;    }
     867  Int       getAdaptiveResolutionChange()      { return m_adaptiveResolutionChange; }
     868#endif
    837869};
    838870
  • trunk/source/Lib/TLibEncoder/TEncCu.cpp

    r191 r310  
    9595 
    9696  m_bEncodeDQP = false;
    97 #if RATE_CONTROL_LAMBDA_DOMAIN
     97#if RATE_CONTROL_LAMBDA_DOMAIN && !M0036_RC_IMPROVEMENT
    9898  m_LCUPredictionSAD = 0;
    9999  m_addSADDepth      = 0;
     
    244244  m_ppcTempCU[0]->initCU( rpcCU->getPic(), rpcCU->getAddr() );
    245245
    246 #if RATE_CONTROL_LAMBDA_DOMAIN
     246#if RATE_CONTROL_LAMBDA_DOMAIN && !M0036_RC_IMPROVEMENT
    247247  m_addSADDepth      = 0;
    248248  m_LCUPredictionSAD = 0;
     
    455455  {
    456456#if (ENCODER_FAST_MODE)
    457     bool testInter = true;
     457    Bool testInter = true;
    458458    if (rpcBestCU->getLayerId() > 0)
    459459    {
    460       if (rpcBestCU->getSlice()->getBaseColPic()->getSlice(0)->getSliceType() == I_SLICE)
    461       {
    462         testInter = false;
    463       }
    464 
     460        if(pcSlice->getSliceType() == P_SLICE && pcSlice->getNumRefIdx(REF_PIC_LIST_0) == pcSlice->getActiveNumILRRefIdx())
     461            testInter = false;
     462        if(pcSlice->getSliceType() == B_SLICE && pcSlice->getNumRefIdx(REF_PIC_LIST_0) == pcSlice->getActiveNumILRRefIdx() && pcSlice->getNumRefIdx(REF_PIC_LIST_1) == pcSlice->getActiveNumILRRefIdx())
     463            testInter = false;
     464#if M0457_IL_SAMPLE_PRED_ONLY_FLAG
     465        if( pcSlice->getInterLayerSamplePredOnlyFlag() )
     466            testInter = false;
     467#endif
    465468    }
    466469#endif
     
    544547    }
    545548
    546 #if RATE_CONTROL_LAMBDA_DOMAIN
     549#if RATE_CONTROL_LAMBDA_DOMAIN && !M0036_RC_IMPROVEMENT
    547550    if ( uiDepth <= m_addSADDepth )
    548551    {
     
    767770      }
    768771#endif
    769 
    770772#if (ENCODER_FAST_MODE)
    771         if(pcPic->getLayerId() > 0)
    772         {
    773           xCheckRDCostILRUni( rpcBestCU, rpcTempCU);
    774           rpcTempCU->initEstData( uiDepth, iQP );
    775        }
     773      if(pcPic->getLayerId() > 0)
     774      {
     775        for(Int refLayer = 0; refLayer < pcSlice->getActiveNumILRRefIdx(); refLayer++)
     776        { 
     777           xCheckRDCostILRUni( rpcBestCU, rpcTempCU, pcSlice->getInterLayerPredLayerIdc(refLayer));
     778           rpcTempCU->initEstData( uiDepth, iQP );
     779        }
     780      }
    776781#endif
    777782
     
    816821  {
    817822    bBoundary = true;
    818 #if RATE_CONTROL_LAMBDA_DOMAIN
     823#if RATE_CONTROL_LAMBDA_DOMAIN && !M0036_RC_IMPROVEMENT
    819824    m_addSADDepth++;
    820825#endif
     
    12461251}
    12471252
     1253#if RATE_CONTROL_INTRA
     1254Int xCalcHADs8x8_ISlice(Pel *piOrg, Int iStrideOrg)
     1255{
     1256  Int k, i, j, jj;
     1257  Int diff[64], m1[8][8], m2[8][8], m3[8][8], iSumHad = 0;
     1258
     1259  for( k = 0; k < 64; k += 8 )
     1260  {
     1261    diff[k+0] = piOrg[0] ;
     1262    diff[k+1] = piOrg[1] ;
     1263    diff[k+2] = piOrg[2] ;
     1264    diff[k+3] = piOrg[3] ;
     1265    diff[k+4] = piOrg[4] ;
     1266    diff[k+5] = piOrg[5] ;
     1267    diff[k+6] = piOrg[6] ;
     1268    diff[k+7] = piOrg[7] ;
     1269 
     1270    piOrg += iStrideOrg;
     1271  }
     1272 
     1273  //horizontal
     1274  for (j=0; j < 8; j++)
     1275  {
     1276    jj = j << 3;
     1277    m2[j][0] = diff[jj  ] + diff[jj+4];
     1278    m2[j][1] = diff[jj+1] + diff[jj+5];
     1279    m2[j][2] = diff[jj+2] + diff[jj+6];
     1280    m2[j][3] = diff[jj+3] + diff[jj+7];
     1281    m2[j][4] = diff[jj  ] - diff[jj+4];
     1282    m2[j][5] = diff[jj+1] - diff[jj+5];
     1283    m2[j][6] = diff[jj+2] - diff[jj+6];
     1284    m2[j][7] = diff[jj+3] - diff[jj+7];
     1285   
     1286    m1[j][0] = m2[j][0] + m2[j][2];
     1287    m1[j][1] = m2[j][1] + m2[j][3];
     1288    m1[j][2] = m2[j][0] - m2[j][2];
     1289    m1[j][3] = m2[j][1] - m2[j][3];
     1290    m1[j][4] = m2[j][4] + m2[j][6];
     1291    m1[j][5] = m2[j][5] + m2[j][7];
     1292    m1[j][6] = m2[j][4] - m2[j][6];
     1293    m1[j][7] = m2[j][5] - m2[j][7];
     1294   
     1295    m2[j][0] = m1[j][0] + m1[j][1];
     1296    m2[j][1] = m1[j][0] - m1[j][1];
     1297    m2[j][2] = m1[j][2] + m1[j][3];
     1298    m2[j][3] = m1[j][2] - m1[j][3];
     1299    m2[j][4] = m1[j][4] + m1[j][5];
     1300    m2[j][5] = m1[j][4] - m1[j][5];
     1301    m2[j][6] = m1[j][6] + m1[j][7];
     1302    m2[j][7] = m1[j][6] - m1[j][7];
     1303  }
     1304 
     1305  //vertical
     1306  for (i=0; i < 8; i++)
     1307  {
     1308    m3[0][i] = m2[0][i] + m2[4][i];
     1309    m3[1][i] = m2[1][i] + m2[5][i];
     1310    m3[2][i] = m2[2][i] + m2[6][i];
     1311    m3[3][i] = m2[3][i] + m2[7][i];
     1312    m3[4][i] = m2[0][i] - m2[4][i];
     1313    m3[5][i] = m2[1][i] - m2[5][i];
     1314    m3[6][i] = m2[2][i] - m2[6][i];
     1315    m3[7][i] = m2[3][i] - m2[7][i];
     1316   
     1317    m1[0][i] = m3[0][i] + m3[2][i];
     1318    m1[1][i] = m3[1][i] + m3[3][i];
     1319    m1[2][i] = m3[0][i] - m3[2][i];
     1320    m1[3][i] = m3[1][i] - m3[3][i];
     1321    m1[4][i] = m3[4][i] + m3[6][i];
     1322    m1[5][i] = m3[5][i] + m3[7][i];
     1323    m1[6][i] = m3[4][i] - m3[6][i];
     1324    m1[7][i] = m3[5][i] - m3[7][i];
     1325   
     1326    m2[0][i] = m1[0][i] + m1[1][i];
     1327    m2[1][i] = m1[0][i] - m1[1][i];
     1328    m2[2][i] = m1[2][i] + m1[3][i];
     1329    m2[3][i] = m1[2][i] - m1[3][i];
     1330    m2[4][i] = m1[4][i] + m1[5][i];
     1331    m2[5][i] = m1[4][i] - m1[5][i];
     1332    m2[6][i] = m1[6][i] + m1[7][i];
     1333    m2[7][i] = m1[6][i] - m1[7][i];
     1334  }
     1335 
     1336  for (i = 0; i < 8; i++)
     1337  {
     1338    for (j = 0; j < 8; j++)
     1339    {
     1340      iSumHad += abs(m2[i][j]);
     1341    }
     1342  }
     1343  iSumHad -= abs(m2[0][0]);
     1344  iSumHad =(iSumHad+2)>>2;
     1345  return(iSumHad);
     1346}
     1347
     1348Int  TEncCu::updateLCUDataISlice(TComDataCU* pcCU, Int LCUIdx, Int width, Int height)
     1349{
     1350  Int  xBl, yBl;
     1351  const Int iBlkSize = 8;
     1352
     1353  Pel* pOrgInit   = pcCU->getPic()->getPicYuvOrg()->getLumaAddr(pcCU->getAddr(), 0);
     1354  Int  iStrideOrig = pcCU->getPic()->getPicYuvOrg()->getStride();
     1355  Pel  *pOrg;
     1356
     1357  Int iSumHad = 0;
     1358  for ( yBl=0; (yBl+iBlkSize)<=height; yBl+= iBlkSize)
     1359  {
     1360    for ( xBl=0; (xBl+iBlkSize)<=width; xBl+= iBlkSize)
     1361    {
     1362      pOrg = pOrgInit + iStrideOrig*yBl + xBl;
     1363      iSumHad += xCalcHADs8x8_ISlice(pOrg, iStrideOrig);
     1364    }
     1365  }
     1366  return(iSumHad);
     1367}
     1368#endif
     1369
    12481370/** check RD costs for a CU block encoded with merge
    12491371 * \param rpcBestCU
     
    12541376{
    12551377  assert( rpcTempCU->getSlice()->getSliceType() != I_SLICE );
    1256   TComMvField  cMvFieldNeighbours[MRG_MAX_NUM_CANDS << 1]; // double length for mv of both lists
     1378  TComMvField  cMvFieldNeighbours[ 2 * MRG_MAX_NUM_CANDS ]; // double length for mv of both lists
    12571379  UChar uhInterDirNeighbours[MRG_MAX_NUM_CANDS];
    12581380  Int numValidMergeCand = 0;
     
    12681390
    12691391  Int mergeCandBuffer[MRG_MAX_NUM_CANDS];
    1270   for( UInt ui = 0; ui < rpcTempCU->getSlice()->getMaxNumMergeCand(); ++ui )
     1392  for( UInt ui = 0; ui < numValidMergeCand; ++ui )
    12711393  {
    12721394    mergeCandBuffer[ui] = 0;
     
    12941416      {
    12951417#endif
    1296         if(!(uiNoResidual==1 && mergeCandBuffer[uiMergeCand]==1))
    1297         {
    1298 
     1418      if(!(uiNoResidual==1 && mergeCandBuffer[uiMergeCand]==1))
     1419      {
    12991420        if( !(bestIsSkip && uiNoResidual == 0) )
    13001421        {
     
    13081429          rpcTempCU->getCUMvField( REF_PIC_LIST_0 )->setAllMvField( cMvFieldNeighbours[0 + 2*uiMergeCand], SIZE_2Nx2N, 0, 0 ); // interprets depth relative to rpcTempCU level
    13091430          rpcTempCU->getCUMvField( REF_PIC_LIST_1 )->setAllMvField( cMvFieldNeighbours[1 + 2*uiMergeCand], SIZE_2Nx2N, 0, 0 ); // interprets depth relative to rpcTempCU level
    1310 
    1311        // do MC
    1312        m_pcPredSearch->motionCompensation ( rpcTempCU, m_ppcPredYuvTemp[uhDepth] );
    1313        // estimate residual and encode everything
    1314        m_pcPredSearch->encodeResAndCalcRdInterCU( rpcTempCU,
    1315          m_ppcOrigYuv    [uhDepth],
    1316          m_ppcPredYuvTemp[uhDepth],
    1317          m_ppcResiYuvTemp[uhDepth],
    1318          m_ppcResiYuvBest[uhDepth],
    1319          m_ppcRecoYuvTemp[uhDepth],
    1320          (uiNoResidual? true:false));
    1321 
    1322 
    1323        if(uiNoResidual==0)
    1324        {
    1325          if(rpcTempCU->getQtRootCbf(0) == 0)
    1326          {
    1327            mergeCandBuffer[uiMergeCand] = 1;
    1328          }
    1329        }
    1330 
    1331        rpcTempCU->setSkipFlagSubParts( rpcTempCU->getQtRootCbf(0) == 0, 0, uhDepth );
     1431         
     1432          // do MC
     1433          m_pcPredSearch->motionCompensation ( rpcTempCU, m_ppcPredYuvTemp[uhDepth] );
     1434          // estimate residual and encode everything
     1435          m_pcPredSearch->encodeResAndCalcRdInterCU( rpcTempCU,
     1436                                                    m_ppcOrigYuv    [uhDepth],
     1437                                                    m_ppcPredYuvTemp[uhDepth],
     1438                                                    m_ppcResiYuvTemp[uhDepth],
     1439                                                    m_ppcResiYuvBest[uhDepth],
     1440                                                    m_ppcRecoYuvTemp[uhDepth],
     1441                                                    (uiNoResidual? true:false));
     1442         
     1443         
     1444          if ( uiNoResidual == 0 && rpcTempCU->getQtRootCbf(0) == 0 )
     1445          {
     1446            // If no residual when allowing for one, then set mark to not try case where residual is forced to 0
     1447            mergeCandBuffer[uiMergeCand] = 1;
     1448          }
     1449         
     1450          rpcTempCU->setSkipFlagSubParts( rpcTempCU->getQtRootCbf(0) == 0, 0, uhDepth );
    13321451          Int orgQP = rpcTempCU->getQP( 0 );
    13331452          xCheckDQP( rpcTempCU );
    13341453          xCheckBestMode(rpcBestCU, rpcTempCU, uhDepth);
    13351454          rpcTempCU->initEstData( uhDepth, orgQP );
    1336 
    1337 
    1338       if( m_pcEncCfg->getUseFastDecisionForMerge() && !bestIsSkip )
    1339       {
    1340         bestIsSkip = rpcBestCU->getQtRootCbf(0) == 0;
    1341       }
    1342 
    1343     }
    1344     }
     1455         
     1456          if( m_pcEncCfg->getUseFastDecisionForMerge() && !bestIsSkip )
     1457          {
     1458            bestIsSkip = rpcBestCU->getQtRootCbf(0) == 0;
     1459          }
     1460        }
    13451461#if REF_IDX_ME_ZEROMV
    1346    }
    1347 #endif
     1462        }
     1463#endif
     1464      }
    13481465  }
    13491466
     
    14111528#endif
    14121529
    1413 #if RATE_CONTROL_LAMBDA_DOMAIN
     1530#if RATE_CONTROL_LAMBDA_DOMAIN && !M0036_RC_IMPROVEMENT
    14141531  if ( m_pcEncCfg->getUseRateCtrl() && m_pcEncCfg->getLCULevelRC() && ePartSize == SIZE_2Nx2N && uhDepth <= m_addSADDepth )
    14151532  {
     
    17761893  //   rpcTempCU->setLumaIntraDirSubParts( DC_IDX, 0, uiDepth );
    17771894  //   rpcTempCU->setChromIntraDirSubParts( DC_IDX, 0, uiDepth );
    1778   m_ppcPredYuvTemp[uiDepth]->copyFromPicLuma  ( rpcTempCU->getSlice()->getFullPelBaseRec(),  rpcTempCU->getAddr(), rpcTempCU->getZorderIdxInCU(), 0, rpcTempCU->getWidth(0), rpcTempCU->getHeight(0));
    1779   m_ppcPredYuvTemp[uiDepth]->copyFromPicChroma( rpcTempCU->getSlice()->getFullPelBaseRec(),  rpcTempCU->getAddr(), rpcTempCU->getZorderIdxInCU(), 0, (rpcTempCU->getWidth(0)>>1), (rpcTempCU->getHeight(0)>>1), 0);
    1780   m_ppcPredYuvTemp[uiDepth]->copyFromPicChroma( rpcTempCU->getSlice()->getFullPelBaseRec(),  rpcTempCU->getAddr(), rpcTempCU->getZorderIdxInCU(), 0, (rpcTempCU->getWidth(0)>>1), (rpcTempCU->getHeight(0)>>1), 1);
     1895  m_ppcPredYuvTemp[uiDepth]->copyFromPicLuma  ( rpcTempCU->getSlice()->getFullPelBaseRec(rpcTempCU->getLayerId() - 1),  rpcTempCU->getAddr(), rpcTempCU->getZorderIdxInCU(), 0, rpcTempCU->getWidth(0), rpcTempCU->getHeight(0));
     1896  m_ppcPredYuvTemp[uiDepth]->copyFromPicChroma( rpcTempCU->getSlice()->getFullPelBaseRec(rpcTempCU->getLayerId() - 1),  rpcTempCU->getAddr(), rpcTempCU->getZorderIdxInCU(), 0, (rpcTempCU->getWidth(0)>>1), (rpcTempCU->getHeight(0)>>1), 0);
     1897  m_ppcPredYuvTemp[uiDepth]->copyFromPicChroma( rpcTempCU->getSlice()->getFullPelBaseRec(rpcTempCU->getLayerId() - 1),  rpcTempCU->getAddr(), rpcTempCU->getZorderIdxInCU(), 0, (rpcTempCU->getWidth(0)>>1), (rpcTempCU->getHeight(0)>>1), 1);
    17811898  m_pcPredSearch->encodeResAndCalcRdInterCU( rpcTempCU, m_ppcOrigYuv[uiDepth], m_ppcPredYuvTemp[uiDepth], m_ppcResiYuvTemp[uiDepth], m_ppcResiYuvBest[uiDepth], m_ppcRecoYuvTemp[uiDepth], false );
    17821899  rpcTempCU->getTotalCost()  = m_pcRdCost->calcRdCost( rpcTempCU->getTotalBits(), rpcTempCU->getTotalDistortion() );
     
    18121929}
    18131930#endif
    1814 
    18151931#if (ENCODER_FAST_MODE)
    1816 Void TEncCu::xCheckRDCostILRUni(TComDataCU *&rpcBestCU, TComDataCU *&rpcTempCU)
     1932Void TEncCu::xCheckRDCostILRUni(TComDataCU *&rpcBestCU, TComDataCU *&rpcTempCU, UInt refLayerId)
    18171933{
    18181934  UChar uhDepth = rpcTempCU->getDepth( 0 );
    1819 
    18201935  rpcTempCU->setDepthSubParts( uhDepth, 0 );
    1821 
    18221936#if SKIP_FLAG
    18231937  rpcTempCU->setSkipFlagSubParts( false, 0, uhDepth );
    18241938#endif
    1825 
    18261939  rpcTempCU->setPartSizeSubParts  ( SIZE_2Nx2N,  0, uhDepth );  //2Nx2N
    18271940  rpcTempCU->setPredModeSubParts  ( MODE_INTER, 0, uhDepth );
    18281941  rpcTempCU->setCUTransquantBypassSubParts  ( m_pcEncCfg->getCUTransquantBypassFlagValue(), 0, uhDepth );
    1829 
    1830   Bool exitILR = m_pcPredSearch->predInterSearchILRUni( rpcTempCU, m_ppcOrigYuv[uhDepth], m_ppcPredYuvTemp[uhDepth], m_ppcResiYuvTemp[uhDepth], m_ppcRecoYuvTemp[uhDepth] );
    1831 
     1942  Bool exitILR = m_pcPredSearch->predInterSearchILRUni( rpcTempCU, m_ppcOrigYuv[uhDepth], m_ppcPredYuvTemp[uhDepth], m_ppcResiYuvTemp[uhDepth], m_ppcRecoYuvTemp[uhDepth], refLayerId );
    18321943  if(!exitILR)
    18331944  {
    1834     return;
    1835   }
    1836 
     1945     return;
     1946  }
    18371947  m_pcPredSearch->encodeResAndCalcRdInterCU( rpcTempCU, m_ppcOrigYuv[uhDepth], m_ppcPredYuvTemp[uhDepth], m_ppcResiYuvTemp[uhDepth], m_ppcResiYuvBest[uhDepth], m_ppcRecoYuvTemp[uhDepth], false );
    1838 
    18391948  rpcTempCU->getTotalCost()  = m_pcRdCost->calcRdCost( rpcTempCU->getTotalBits(), rpcTempCU->getTotalDistortion() );
    1840 
    18411949  xCheckDQP( rpcTempCU );
    18421950  xCheckBestMode(rpcBestCU, rpcTempCU, uhDepth);
    1843 
    18441951  return;
    18451952}
    18461953#endif
    1847 
    1848 
    18491954//! \}
  • trunk/source/Lib/TLibEncoder/TEncCu.h

    r191 r310  
    106106  Bool                    m_bUseSBACRD;
    107107  TEncRateCtrl*           m_pcRateCtrl;
    108 #if RATE_CONTROL_LAMBDA_DOMAIN
     108#if RATE_CONTROL_LAMBDA_DOMAIN && !M0036_RC_IMPROVEMENT
    109109  UInt                    m_LCUPredictionSAD;
    110110  Int                     m_addSADDepth;
     
    128128 
    129129  Void setBitCounter        ( TComBitCounter* pcBitCounter ) { m_pcBitCounter = pcBitCounter; }
    130 #if RATE_CONTROL_LAMBDA_DOMAIN
     130#if RATE_CONTROL_LAMBDA_DOMAIN && !M0036_RC_IMPROVEMENT
    131131  UInt getLCUPredictionSAD() { return m_LCUPredictionSAD; }
     132#endif
     133#if RATE_CONTROL_INTRA
     134  Int   updateLCUDataISlice ( TComDataCU* pcCU, Int LCUIdx, Int width, Int height );
    132135#endif
    133136#if INTRA_BL
     
    158161#endif
    159162#if ENCODER_FAST_MODE
    160   Void  xCheckRDCostILRUni  ( TComDataCU*& rpcBestCU, TComDataCU*& rpcTempCU );
     163  Void  xCheckRDCostILRUni  ( TComDataCU*& rpcBestCU, TComDataCU*& rpcTempCU, UInt refLayerId);
    161164#endif
    162165  Void  xCheckDQP           ( TComDataCU*  pcCU );
  • trunk/source/Lib/TLibEncoder/TEncGOP.cpp

    r191 r310  
    9494  m_cpbRemovalDelay   = 0;
    9595  m_lastBPSEI         = 0;
    96 #if L0045_NON_NESTED_SEI_RESTRICTIONS
    9796  xResetNonNestedSEIPresentFlags();
    98 #if K0180_SCALABLE_NESTING_SEI
    9997  xResetNestedSEIPresentFlags();
    100 #endif
    101 #endif
    10298#if SVC_UPSAMPLING
    10399  m_pcPredSearch        = NULL;
     
    163159  SEIActiveParameterSets *seiActiveParameterSets = new SEIActiveParameterSets();
    164160  seiActiveParameterSets->activeVPSId = m_pcCfg->getVPS()->getVPSId();
    165 #if L0047_APS_FLAGS
    166161  seiActiveParameterSets->m_fullRandomAccessFlag = false;
    167162  seiActiveParameterSets->m_noParamSetUpdateFlag = false;
    168 #endif
    169163  seiActiveParameterSets->numSpsIdsMinus1 = 0;
    170164  seiActiveParameterSets->activeSeqParamSetId.resize(seiActiveParameterSets->numSpsIdsMinus1 + 1);
     
    172166  return seiActiveParameterSets;
    173167}
     168
     169#if M0043_LAYERS_PRESENT_SEI
     170SEILayersPresent* TEncGOP::xCreateSEILayersPresent ()
     171{
     172  UInt i = 0;
     173  SEILayersPresent *seiLayersPresent = new SEILayersPresent();
     174  seiLayersPresent->m_activeVpsId = m_pcCfg->getVPS()->getVPSId();
     175  seiLayersPresent->m_vpsMaxLayers = m_pcCfg->getVPS()->getMaxLayers();
     176  for ( ; i < seiLayersPresent->m_vpsMaxLayers; i++)
     177  {
     178    seiLayersPresent->m_layerPresentFlag[i] = true;
     179  }
     180  for ( ; i < MAX_LAYERS; i++)
     181  {
     182    seiLayersPresent->m_layerPresentFlag[i] = false;
     183  }
     184  return seiLayersPresent;
     185}
     186#endif
    174187
    175188SEIFramePacking* TEncGOP::xCreateSEIFramePacking()
     
    179192  seiFramePacking->m_arrangementCancelFlag = 0;
    180193  seiFramePacking->m_arrangementType = m_pcCfg->getFramePackingArrangementSEIType();
    181 #if L0444_FPA_TYPE
    182194  assert((seiFramePacking->m_arrangementType > 2) && (seiFramePacking->m_arrangementType < 6) );
    183 #endif
    184195  seiFramePacking->m_quincunxSamplingFlag = m_pcCfg->getFramePackingArrangementSEIQuincunx();
    185196  seiFramePacking->m_contentInterpretationType = m_pcCfg->getFramePackingArrangementSEIInterpretation();
     
    195206  seiFramePacking->m_frame1GridPositionY = 0;
    196207  seiFramePacking->m_arrangementReservedByte = 0;
    197 #if L0045_PERSISTENCE_FLAGS
    198208  seiFramePacking->m_arrangementPersistenceFlag = true;
    199 #else
    200   seiFramePacking->m_arrangementRepetetionPeriod = 1;
    201 #endif
    202209  seiFramePacking->m_upsampledAspectRatio = 0;
    203210  return seiFramePacking;
     
    214221}
    215222
    216 #if J0149_TONE_MAPPING_SEI
    217223SEIToneMappingInfo*  TEncGOP::xCreateSEIToneMappingInfo()
    218224{
     
    225231  assert(seiToneMappingInfo->m_codedDataBitDepth >= 8 && seiToneMappingInfo->m_codedDataBitDepth <= 14);
    226232  seiToneMappingInfo->m_targetBitDepth = m_pcCfg->getTMISEITargetBitDepth();
    227   assert( (seiToneMappingInfo->m_targetBitDepth >= 1 && seiToneMappingInfo->m_targetBitDepth <= 17) || (seiToneMappingInfo->m_targetBitDepth  == 255) );
     233  assert( seiToneMappingInfo->m_targetBitDepth >= 1 && seiToneMappingInfo->m_targetBitDepth <= 17 );
    228234  seiToneMappingInfo->m_modelId = m_pcCfg->getTMISEIModelID();
    229235  assert(seiToneMappingInfo->m_modelId >=0 &&seiToneMappingInfo->m_modelId<=4);
     
    300306  return seiToneMappingInfo;
    301307}
    302 #endif
     308
    303309Void TEncGOP::xCreateLeadingSEIMessages (/*SEIMessages seiMessages,*/ AccessUnit &accessUnit, TComSPS *sps)
    304310{
     
    315321    accessUnit.push_back(new NALUnitEBSP(nalu));
    316322    delete sei;
    317 #if L0045_NON_NESTED_SEI_RESTRICTIONS
    318323    m_activeParameterSetSEIPresentInAU = true;
    319 #endif
    320   }
     324  }
     325
     326#if M0043_LAYERS_PRESENT_SEI
     327  if(m_pcCfg->getLayersPresentSEIEnabled())
     328  {
     329    SEILayersPresent *sei = xCreateSEILayersPresent ();
     330    m_pcEntropyCoder->setBitstream(&nalu.m_Bitstream);
     331    m_seiWriter.writeSEImessage(nalu.m_Bitstream, *sei, sps);
     332    writeRBSPTrailingBits(nalu.m_Bitstream);
     333    accessUnit.push_back(new NALUnitEBSP(nalu));
     334    delete sei;
     335  }
     336#endif
    321337
    322338  if(m_pcCfg->getFramePackingArrangementSEIEnabled())
     
    342358    delete sei;
    343359  }
    344 #if J0149_TONE_MAPPING_SEI
    345360  if(m_pcCfg->getToneMappingInfoSEIEnabled())
    346361  {
     
    354369    delete sei;
    355370  }
    356 #endif
    357371}
    358372
     
    380394  m_iNumPicCoded = 0;
    381395  SEIPictureTiming pictureTimingSEI;
    382 #if L0208_SOP_DESCRIPTION_SEI
    383396  Bool writeSOP = m_pcCfg->getSOPDescriptionSEIEnabled();
    384 #endif
    385 #if K0180_SCALABLE_NESTING_SEI
    386397  // Initialize Scalable Nesting SEI with single layer values
    387398  SEIScalableNesting scalableNestingSEI;
     
    394405  scalableNestingSEI.m_nestingLayerId[0]             = 0;
    395406  scalableNestingSEI.m_callerOwnsSEIs                = true;
    396 #endif
    397 #if L0044_DU_DPB_OUTPUT_DELAY_HRD
    398407  Int picSptDpbOutputDuDelay = 0;
    399 #endif
    400408  UInt *accumBitsDU = NULL;
    401409  UInt *accumNalsDU = NULL;
     
    466474      continue;
    467475    }
     476
     477#if M0040_ADAPTIVE_RESOLUTION_CHANGE
     478    if (m_pcEncTop->getAdaptiveResolutionChange() > 0 && ((m_layerId == 1 && pocCurr < m_pcEncTop->getAdaptiveResolutionChange()) ||
     479                                                          (m_layerId == 0 && pocCurr > m_pcEncTop->getAdaptiveResolutionChange())) )
     480    {
     481      continue;
     482    }
     483#endif
    468484
    469485    if( getNalUnitType(pocCurr, m_iLastIDR) == NAL_UNIT_CODED_SLICE_IDR_W_RADL || getNalUnitType(pocCurr, m_iLastIDR) == NAL_UNIT_CODED_SLICE_IDR_N_LP )
     
    487503    m_pcSliceEncoder->initEncSlice ( pcPic, iPOCLast, pocCurr, iNumPicRcvd, iGOPid, pcSlice, m_pcEncTop->getSPS(), m_pcEncTop->getPPS() );
    488504#endif
     505
     506#if M0040_ADAPTIVE_RESOLUTION_CHANGE
     507    if (m_pcEncTop->getAdaptiveResolutionChange() > 0 && m_layerId == 1 && pocCurr > m_pcEncTop->getAdaptiveResolutionChange())
     508    {
     509      pcSlice->setActiveNumILRRefIdx(0);
     510      pcSlice->setInterLayerPredEnabledFlag(false);
     511#if M0457_COL_PICTURE_SIGNALING
     512      pcSlice->setMFMEnabledFlag(false);
     513      pcSlice->setAltColIndicationFlag(false);
     514#endif
     515    }
     516#endif
     517
     518#if M0457_IL_SAMPLE_PRED_ONLY_FLAG
     519    pcSlice->setNumSamplePredRefLayers( m_pcEncTop->getNumSamplePredRefLayers() );
     520    pcSlice->setInterLayerSamplePredOnlyFlag( 0 );
     521    if( pcSlice->getNumSamplePredRefLayers() > 0 && pcSlice->getActiveNumILRRefIdx() > 0 )
     522    {
     523      if( m_pcEncTop->getIlSampleOnlyPred() > 0 )
     524      {
     525        pcSlice->setInterLayerSamplePredOnlyFlag( true );
     526      }
     527    }
     528#endif
     529
    489530    pcSlice->setLastIDR(m_iLastIDR);
    490531    pcSlice->setSliceIdx(0);
     
    532573    // Set the nal unit type
    533574    pcSlice->setNalUnitType(getNalUnitType(pocCurr, m_iLastIDR));
     575#if SVC_EXTENSION
     576    if (m_layerId > 0)
     577    {
     578      for( Int i = 0; i < pcSlice->getActiveNumILRRefIdx(); i++ )
     579      {
     580        UInt refLayerIdc = pcSlice->getInterLayerPredLayerIdc(i);
     581#if VPS_EXTN_DIRECT_REF_LAYERS
     582        TComList<TComPic*> *cListPic = m_ppcTEncTop[m_layerId]->getRefLayerEnc(refLayerIdc)->getListPic();
     583#else
     584        TComList<TComPic*> *cListPic = m_ppcTEncTop[m_layerId-1]->getListPic();
     585#endif
     586        pcSlice->setBaseColPic( *cListPic, refLayerIdc );
     587
     588#if SIMPLIFIED_MV_POS_SCALING
     589#if SCALED_REF_LAYER_OFFSETS
     590        const Window &scalEL = m_pcEncTop->getScaledRefLayerWindow(refLayerIdc);
     591
     592        Int widthBL   = pcSlice->getBaseColPic(refLayerIdc)->getPicYuvRec()->getWidth();
     593        Int heightBL  = pcSlice->getBaseColPic(refLayerIdc)->getPicYuvRec()->getHeight();
     594
     595        Int widthEL   = pcPic->getPicYuvRec()->getWidth()  - scalEL.getWindowLeftOffset() - scalEL.getWindowRightOffset();
     596        Int heightEL  = pcPic->getPicYuvRec()->getHeight() - scalEL.getWindowTopOffset()  - scalEL.getWindowBottomOffset();
     597#else
     598        const Window &confBL = pcSlice->getBaseColPic(refLayerIdc)->getPicYuvRec()->getConformanceWindow();
     599        const Window &confEL = pcPic->getPicYuvRec()->getConformanceWindow();
     600
     601        Int widthBL   = pcSlice->getBaseColPic(refLayerIdc)->getPicYuvRec()->getWidth () - confBL.getWindowLeftOffset() - confBL.getWindowRightOffset();
     602        Int heightBL  = pcSlice->getBaseColPic(refLayerIdc)->getPicYuvRec()->getHeight() - confBL.getWindowTopOffset() - confBL.getWindowBottomOffset();
     603
     604        Int widthEL   = pcPic->getPicYuvRec()->getWidth() - confEL.getWindowLeftOffset() - confEL.getWindowRightOffset();
     605        Int heightEL  = pcPic->getPicYuvRec()->getHeight() - confEL.getWindowTopOffset() - confEL.getWindowBottomOffset();
     606#endif
     607        g_mvScalingFactor[refLayerIdc][0] = widthEL  == widthBL  ? 4096 : Clip3(-4096, 4095, ((widthEL  << 8) + (widthBL  >> 1)) / widthBL);
     608        g_mvScalingFactor[refLayerIdc][1] = heightEL == heightBL ? 4096 : Clip3(-4096, 4095, ((heightEL << 8) + (heightBL >> 1)) / heightBL);
     609
     610        g_posScalingFactor[refLayerIdc][0] = ((widthBL  << 16) + (widthEL  >> 1)) / widthEL;
     611        g_posScalingFactor[refLayerIdc][1] = ((heightBL << 16) + (heightEL >> 1)) / heightEL;
     612#endif
     613
     614#if SVC_UPSAMPLING
     615        if( pcPic->isSpatialEnhLayer(refLayerIdc))
     616        {
     617#if SCALED_REF_LAYER_OFFSETS
     618          m_pcPredSearch->upsampleBasePic( refLayerIdc, pcPic->getFullPelBaseRec(refLayerIdc), pcSlice->getBaseColPic(refLayerIdc)->getPicYuvRec(), pcPic->getPicYuvRec(), pcSlice->getSPS()->getScaledRefLayerWindow(refLayerIdc) );
     619#else
     620          m_pcPredSearch->upsampleBasePic( refLayerIdc, pcPic->getFullPelBaseRec(refLayerIdc), pcSlice->getBaseColPic(refLayerIdc)->getPicYuvRec(), pcPic->getPicYuvRec() );
     621#endif
     622        }
     623        else
     624        {
     625          pcPic->setFullPelBaseRec( refLayerIdc, pcSlice->getBaseColPic(refLayerIdc)->getPicYuvRec() );
     626        }
     627        pcSlice->setFullPelBaseRec ( refLayerIdc, pcPic->getFullPelBaseRec(refLayerIdc) );
     628#endif
     629      }
     630    }
     631#endif
     632
     633#if REF_IDX_FRAMEWORK
     634    if( m_layerId > 0 && (pocCurr % m_pcCfg->getIntraPeriod() == 0) )
     635    {
    534636#if IDR_ALIGNMENT
    535     if (m_layerId > 0)
    536     {
    537 #if VPS_EXTN_DIRECT_REF_LAYERS_CONTINUE
    538       TComList<TComPic*> *cListPic = m_ppcTEncTop[m_layerId]->getRefLayerEnc(m_layerId)->getListPic();
    539 #else
    540       TComList<TComPic*> *cListPic = m_ppcTEncTop[m_layerId-1]->getListPic();
    541 #endif
    542       pcSlice->setBaseColPic (*cListPic, m_layerId );
    543     }
    544 #endif
    545 #if REF_IDX_FRAMEWORK
    546 
    547     if( m_layerId > 0 && (pocCurr % m_pcCfg->getIntraPeriod() == 0) )
    548     {
    549 #if IDR_ALIGNMENT
    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());
     637      TComList<TComPic*> *cListPic = m_ppcTEncTop[m_layerId]->getRefLayerEnc(0)->getListPic();
     638      TComPic* picLayer0 = pcSlice->getRefPic(*cListPic, pcSlice->getPOC() );
     639      if( picLayer0->getSlice(0)->getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_W_RADL || picLayer0->getSlice(0)->getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_N_LP )
     640      {
     641        pcSlice->setNalUnitType(picLayer0->getSlice(0)->getNalUnitType());
    553642      }
    554643      else
     
    594683    pcSlice->getRPS()->setNumberOfLongtermPictures(0);
    595684
     685#if FIX1071
     686    if ((pcSlice->checkThatAllRefPicsAreAvailable(rcListPic, pcSlice->getRPS(), false) != 0) || (pcSlice->isIRAP()))
     687    {
     688      pcSlice->createExplicitReferencePictureSetFromReference(rcListPic, pcSlice->getRPS(), pcSlice->isIRAP());
     689    }
     690#else
    596691    if(pcSlice->checkThatAllRefPicsAreAvailable(rcListPic, pcSlice->getRPS(), false) != 0)
    597692    {
    598693      pcSlice->createExplicitReferencePictureSetFromReference(rcListPic, pcSlice->getRPS());
    599694    }
     695#endif
    600696    pcSlice->applyReferencePictureSet(rcListPic, pcSlice->getRPS());
    601697
     
    670766#endif
    671767    {
     768#if RESTR_CHK
     769      if (pcSlice->getPOC()>0  && pcSlice->isRADL()&& pcPic->getSlice(0)->isRASL())
     770      {
     771#if JCTVC_M0458_INTERLAYER_RPS_SIG
     772        pcSlice->setActiveNumILRRefIdx(0);
     773        pcSlice->setInterLayerPredEnabledFlag(0);
     774#else
     775        pcSlice->setNumILRRefIdx(0);
     776#endif
     777      }
     778#endif
    672779#if JCTVC_M0458_INTERLAYER_RPS_SIG
    673780      if( pcSlice->getNalUnitType() >= NAL_UNIT_CODED_SLICE_BLA_W_LP && pcSlice->getNalUnitType() <= NAL_UNIT_CODED_SLICE_CRA )
     
    700807#endif     
    701808
    702 #if SVC_EXTENSION     
    703 #if ZERO_NUM_DIRECT_LAYERS
    704     if( m_layerId > 0 && pcSlice->getActiveNumILRRefIdx() )
    705 #else
    706     if(m_layerId > 0)
    707 #endif
    708     {
    709 #if !IDR_ALIGNMENT
    710       TComList<TComPic*> *cListPic = m_ppcTEncTop[m_layerId-1]->getListPic();
    711       pcSlice->setBaseColPic (*cListPic, m_layerId );
    712 #endif
    713 #if SVC_UPSAMPLING
    714       if ( pcPic->isSpatialEnhLayer())
    715       {
    716 #if SCALED_REF_LAYER_OFFSETS
    717         m_pcPredSearch->upsampleBasePic( pcPic->getFullPelBaseRec(), pcSlice->getBaseColPic()->getPicYuvRec(), pcPic->getPicYuvRec(), pcSlice->getSPS()->getScaledRefLayerWindow() );
    718 #else
    719         m_pcPredSearch->upsampleBasePic( pcPic->getFullPelBaseRec(), pcSlice->getBaseColPic()->getPicYuvRec(), pcPic->getPicYuvRec() );
    720 #endif
    721       }
    722       else
    723       {
    724         pcPic->setFullPelBaseRec( pcSlice->getBaseColPic()->getPicYuvRec() );
    725       }
    726       pcSlice->setFullPelBaseRec ( pcPic->getFullPelBaseRec() );
    727 #endif
    728     }
    729 #endif
    730 
    731809#if REF_IDX_FRAMEWORK
     810#if M0457_COL_PICTURE_SIGNALING
     811    if ( pcSlice->getSliceType() == B_SLICE && !(pcSlice->getActiveNumILRRefIdx() > 0 && m_pcEncTop->getNumMotionPredRefLayers() > 0) )
     812#else
    732813    if( pcSlice->getSliceType() == B_SLICE )
     814#endif
    733815    {
    734816      pcSlice->setColFromL0Flag(1-uiColDir);
     
    759841
    760842#if REF_IDX_MFM
     843#if M0457_COL_PICTURE_SIGNALING
     844      if( pcSlice->getMFMEnabledFlag() )
     845#else
    761846      if( pcSlice->getSPS()->getMFMEnabledFlag() )
     847#endif
    762848      {
    763849        pcSlice->setRefPOCListILP(m_pcEncTop->getIlpList(), pcSlice->getBaseColPic());
     850#if M0457_COL_PICTURE_SIGNALING
     851        pcSlice->setMotionPredIlp(getMotionPredIlp(pcSlice));
     852#endif
    764853      }
    765854#endif
     
    768857
    769858#if REF_IDX_MFM
     859#if M0457_COL_PICTURE_SIGNALING
     860      if( pcSlice->getMFMEnabledFlag() && !(pcSlice->getActiveNumILRRefIdx() > 0 && m_pcEncTop->getNumMotionPredRefLayers() > 0) )
     861#else
    770862      if( pcSlice->getSPS()->getMFMEnabledFlag() )
     863#endif
    771864      {
    772865        Bool found         = false;
     
    812905      pcSlice->setSliceType ( P_SLICE );
    813906    }
    814 #if !L0034_COMBINED_LIST_CLEANUP
    815     if (pcSlice->getSliceType() != B_SLICE || !pcSlice->getSPS()->getUseLComb())
    816     {
    817       pcSlice->setNumRefIdx(REF_PIC_LIST_C, 0);
    818       pcSlice->setRefPicListCombinationFlag(false);
    819       pcSlice->setRefPicListModificationFlagLC(false);
    820     }
    821     else
    822     {
    823       pcSlice->setRefPicListCombinationFlag(pcSlice->getSPS()->getUseLComb());
    824       pcSlice->setNumRefIdx(REF_PIC_LIST_C, pcSlice->getNumRefIdx(REF_PIC_LIST_0));
    825     }
    826 #endif
    827 
     907
     908#if M0457_IL_SAMPLE_PRED_ONLY_FLAG
     909    if (pcSlice->getSliceType() == B_SLICE && m_pcEncTop->getIlSampleOnlyPred() == 0)
     910#else
    828911    if (pcSlice->getSliceType() == B_SLICE)
     912#endif
    829913    {
    830914#if !REF_IDX_FRAMEWORK
     
    862946    pcSlice->setRefPOCList();
    863947
    864 #if L0034_COMBINED_LIST_CLEANUP
    865948    pcSlice->setList1IdxToList0Idx();
    866 #else
    867     pcSlice->setNoBackPredFlag( false );
    868     if ( pcSlice->getSliceType() == B_SLICE && !pcSlice->getRefPicListCombinationFlag())
    869     {
    870       if ( pcSlice->getNumRefIdx(RefPicList( 0 ) ) == pcSlice->getNumRefIdx(RefPicList( 1 ) ) )
    871       {
    872         pcSlice->setNoBackPredFlag( true );
    873         Int i;
    874         for ( i=0; i < pcSlice->getNumRefIdx(RefPicList( 1 ) ); i++ )
    875         {
    876           if ( pcSlice->getRefPOC(RefPicList(1), i) != pcSlice->getRefPOC(RefPicList(0), i) )
    877           {
    878             pcSlice->setNoBackPredFlag( false );
    879             break;
    880           }
    881         }
    882       }
    883     }
    884 
    885     if(pcSlice->getNoBackPredFlag())
    886     {
    887       pcSlice->setNumRefIdx(REF_PIC_LIST_C, 0);
    888     }
    889     pcSlice->generateCombinedList();
    890 #endif
    891949
    892950    if (m_pcEncTop->getTMVPModeId() == 2)
     
    906964    {
    907965      pcSlice->getSPS()->setTMVPFlagsPresent(1);
     966#if SVC_EXTENSION
     967      if( pcSlice->getIdrPicFlag() )
     968      {
     969        pcSlice->setEnableTMVPFlag(0);
     970      }
     971      else
     972#endif
    908973      pcSlice->setEnableTMVPFlag(1);
    909974    }
     
    9481013
    9491014#if RATE_CONTROL_LAMBDA_DOMAIN
    950     Int sliceQP              = pcSlice->getSliceQp();
    9511015    Double lambda            = 0.0;
    9521016    Int actualHeadBits       = 0;
     
    9641028      estimatedBits = m_pcRateCtrl->getRCPic()->getTargetBits();
    9651029
     1030      Int sliceQP = m_pcCfg->getInitialQP();
    9661031      if ( ( pcSlice->getPOC() == 0 && m_pcCfg->getInitialQP() > 0 ) || ( frameLevel == 0 && m_pcCfg->getForceIntraQP() ) ) // QP is specified
    9671032      {
    968         sliceQP              = m_pcCfg->getInitialQP();
    9691033        Int    NumberBFrames = ( m_pcCfg->getGOPSize() - 1 );
    9701034        Double dLambda_scale = 1.0 - Clip3( 0.0, 0.5, 0.05*(Double)NumberBFrames );
     
    9771041      else if ( frameLevel == 0 )   // intra case, but use the model
    9781042      {
     1043#if RATE_CONTROL_INTRA
     1044        m_pcSliceEncoder->calCostSliceI(pcPic);
     1045#endif
    9791046        if ( m_pcCfg->getIntraPeriod() != 1 )   // do not refine allocated bits for all intra case
    9801047        {
    9811048          Int bits = m_pcRateCtrl->getRCSeq()->getLeftAverageBits();
     1049#if RATE_CONTROL_INTRA
     1050          bits = m_pcRateCtrl->getRCPic()->getRefineBitsForIntra( bits );
     1051#else
    9821052          bits = m_pcRateCtrl->getRCSeq()->getRefineBitsForIntra( bits );
     1053#endif
    9831054          if ( bits < 200 )
    9841055          {
     
    9891060
    9901061        list<TEncRCPic*> listPreviousPicture = m_pcRateCtrl->getPicList();
     1062#if RATE_CONTROL_INTRA
     1063        m_pcRateCtrl->getRCPic()->getLCUInitTargetBits();
     1064        lambda  = m_pcRateCtrl->getRCPic()->estimatePicLambda( listPreviousPicture, pcSlice->getSliceType());
     1065#else
    9911066        lambda  = m_pcRateCtrl->getRCPic()->estimatePicLambda( listPreviousPicture );
     1067#endif
    9921068        sliceQP = m_pcRateCtrl->getRCPic()->estimatePicQP( lambda, listPreviousPicture );
    9931069      }
     
    9951071      {
    9961072        list<TEncRCPic*> listPreviousPicture = m_pcRateCtrl->getPicList();
     1073#if RATE_CONTROL_INTRA
     1074        lambda  = m_pcRateCtrl->getRCPic()->estimatePicLambda( listPreviousPicture, pcSlice->getSliceType());
     1075#else
    9971076        lambda  = m_pcRateCtrl->getRCPic()->estimatePicLambda( listPreviousPicture );
     1077#endif
    9981078        sliceQP = m_pcRateCtrl->getRCPic()->estimatePicQP( lambda, listPreviousPicture );
    9991079      }
     
    10071087
    10081088    UInt uiNumSlices = 1;
    1009 
    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
    10381089
    10391090    UInt uiInternalAddress = pcPic->getNumPartInCU()-4;
     
    12331284    Bool bLFCrossTileBoundary = pcSlice->getPPS()->getLoopFilterAcrossTilesEnabledFlag();
    12341285    m_pcLoopFilter->setCfg(bLFCrossTileBoundary);
    1235 #if L0386_DB_METRIC
    12361286    if ( m_pcCfg->getDeblockingFilterMetric() )
    12371287    {
    12381288      dblMetric(pcPic, uiNumSlices);
    12391289    }
    1240 #endif
    12411290    m_pcLoopFilter->loopFilterPic( pcPic );
    12421291
     
    13091358        UInt maxCU = m_pcCfg->getSliceArgument() >> ( pcSlice->getSPS()->getMaxCUDepth() << 1);
    13101359        UInt numDU = ( m_pcCfg->getSliceMode() == 1 ) ? ( pcPic->getNumCUsInFrame() / maxCU ) : ( 0 );
    1311         if( pcPic->getNumCUsInFrame() % maxCU != 0 )
     1360        if( pcPic->getNumCUsInFrame() % maxCU != 0 || numDU == 0 )
    13121361        {
    13131362          numDU ++;
     
    13451394    }
    13461395
    1347 #if L0208_SOP_DESCRIPTION_SEI
    13481396    if (writeSOP) // write SOP description SEI (if enabled) at the beginning of GOP
    13491397    {
     
    13831431      writeSOP = false;
    13841432    }
    1385 #endif
    13861433
    13871434    if( ( m_pcCfg->getPictureTimingSEIEnabled() || m_pcCfg->getDecodingUnitInfoSEIEnabled() ) &&
     
    14151462      pictureTimingSEI.m_auCpbRemovalDelay = std::max<Int>(1, m_totalCoded - m_lastBPSEI); // Syntax element signalled as minus, hence the .
    14161463      pictureTimingSEI.m_picDpbOutputDelay = pcSlice->getSPS()->getNumReorderPics(0) + pcSlice->getPOC() - m_totalCoded;
    1417 #if L0044_DU_DPB_OUTPUT_DELAY_HRD
    14181464      Int factor = pcSlice->getSPS()->getVuiParameters()->getHrdParameters()->getTickDivisorMinus2() + 2;
    14191465      pictureTimingSEI.m_picDpbOutputDuDelay = factor * pictureTimingSEI.m_picDpbOutputDelay;
     
    14221468        picSptDpbOutputDuDelay = factor * pictureTimingSEI.m_picDpbOutputDelay;
    14231469      }
    1424 #endif
    14251470    }
    14261471
     
    14421487      sei_buffering_period.m_initialCpbRemovalDelayOffset[0][1]     = uiInitialCpbRemovalDelay;
    14431488
    1444 #if L0043_TIMING_INFO
    14451489      Double dTmp = (Double)pcSlice->getSPS()->getVuiParameters()->getTimingInfo()->getNumUnitsInTick() / (Double)pcSlice->getSPS()->getVuiParameters()->getTimingInfo()->getTimeScale();
    1446 #else
    1447       Double dTmp = (Double)pcSlice->getSPS()->getVuiParameters()->getHrdParameters()->getNumUnitsInTick() / (Double)pcSlice->getSPS()->getVuiParameters()->getHrdParameters()->getTimeScale();
    1448 #endif
    14491490
    14501491      UInt uiTmp = (UInt)( dTmp * 90000.0 );
     
    14571498
    14581499      sei_buffering_period.m_rapCpbParamsPresentFlag              = 0;
    1459 #if L0328_SPLICING
    14601500      //for the concatenation, it can be set to one during splicing.
    14611501      sei_buffering_period.m_concatenationFlag = 0;
    14621502      //since the temporal layer HRD is not ready, we assumed it is fixed
    14631503      sei_buffering_period.m_auCpbRemovalDelayDelta = 1;
    1464 #endif
    1465 #if L0044_CPB_DPB_DELAY_OFFSET
    14661504      sei_buffering_period.m_cpbDelayOffset = 0;
    14671505      sei_buffering_period.m_dpbDelayOffset = 0;
    1468 #endif
    14691506
    14701507      m_seiWriter.writeSEImessage( nalu.m_Bitstream, sei_buffering_period, pcSlice->getSPS());
    14711508      writeRBSPTrailingBits(nalu.m_Bitstream);
    1472 #if L0045_NON_NESTED_SEI_RESTRICTIONS
    14731509      {
    14741510      UInt seiPositionInAu = xGetFirstSeiLocation(accessUnit);
     
    14821518      m_bufferingPeriodSEIPresentInAU = true;
    14831519      }
    1484 #else
    1485       accessUnit.push_back(new NALUnitEBSP(nalu));
    1486 #endif
    1487 
    1488 #if K0180_SCALABLE_NESTING_SEI
     1520
    14891521      if (m_pcCfg->getScalableNestingSEIEnabled())
    14901522      {
     
    14961528        m_seiWriter.writeSEImessage( naluTmp.m_Bitstream, scalableNestingSEI, pcSlice->getSPS());
    14971529        writeRBSPTrailingBits(naluTmp.m_Bitstream);
    1498 #if L0045_NON_NESTED_SEI_RESTRICTIONS
    14991530        UInt seiPositionInAu = xGetFirstSeiLocation(accessUnit);
    15001531        UInt offsetPosition = m_activeParameterSetSEIPresentInAU + m_bufferingPeriodSEIPresentInAU + m_pictureTimingSEIPresentInAU;   // Insert BP SEI after non-nested APS, BP and PT SEIs
     
    15061537        accessUnit.insert(it, new NALUnitEBSP(naluTmp));
    15071538        m_nestedBufferingPeriodSEIPresentInAU = true;
    1508 #else
    1509         accessUnit.push_back(new NALUnitEBSP(naluTmp));
    1510 #endif
    1511       }
    1512 #endif
     1539      }
    15131540
    15141541      m_lastBPSEI = m_totalCoded;
     
    16001627            startCUAddrSliceSegmentIdx++;
    16011628          }
    1602 
     1629#if REF_IDX_FRAMEWORK && M0457_COL_PICTURE_SIGNALING
     1630          pcSlice->setNumMotionPredRefLayers(m_pcEncTop->getNumMotionPredRefLayers());
     1631#endif
    16031632          pcSlice->setRPS(pcPic->getSlice(0)->getRPS());
    16041633          pcSlice->setRPSidx(pcPic->getSlice(0)->getRPSidx());
     
    19722001      if ( m_pcCfg->getUseRateCtrl() )
    19732002      {
     2003#if !M0036_RC_IMPROVEMENT
    19742004        Double effectivePercentage = m_pcRateCtrl->getRCPic()->getEffectivePercentage();
     2005#endif
    19752006        Double avgQP     = m_pcRateCtrl->getRCPic()->calAverageQP();
    19762007        Double avgLambda = m_pcRateCtrl->getRCPic()->calAverageLambda();
     
    19792010          avgLambda = lambda;
    19802011        }
     2012#if M0036_RC_IMPROVEMENT
     2013#if RATE_CONTROL_INTRA
     2014        m_pcRateCtrl->getRCPic()->updateAfterPicture( actualHeadBits, actualTotalBits, avgQP, avgLambda, pcSlice->getSliceType());
     2015#else
     2016        m_pcRateCtrl->getRCPic()->updateAfterPicture( actualHeadBits, actualTotalBits, avgQP, avgLambda );
     2017#endif
     2018#else
    19812019        m_pcRateCtrl->getRCPic()->updateAfterPicture( actualHeadBits, actualTotalBits, avgQP, avgLambda, effectivePercentage );
     2020#endif
    19822021        m_pcRateCtrl->getRCPic()->addToPictureLsit( m_pcRateCtrl->getPicList() );
    19832022
     
    19992038      }
    20002039#endif
     2040
    20012041      if( ( m_pcCfg->getPictureTimingSEIEnabled() || m_pcCfg->getDecodingUnitInfoSEIEnabled() ) &&
    20022042          ( pcSlice->getSPS()->getVuiParametersPresentFlag() ) &&
     
    20332073            for( i = ( numDU - 2 ); i >= 0; i -- )
    20342074            {
    2035 #if L0043_TIMING_INFO
    20362075              ui64Tmp = ( ( ( accumBitsDU[ numDU - 1 ]  - accumBitsDU[ i ] ) * ( vui->getTimingInfo()->getTimeScale() / vui->getTimingInfo()->getNumUnitsInTick() ) * ( hrd->getTickDivisorMinus2() + 2 ) ) / ( m_pcCfg->getTargetBitrate() ) );
    2037 #else
    2038               ui64Tmp = ( ( ( accumBitsDU[ numDU - 1 ]  - accumBitsDU[ i ] ) * ( hrd->getTimeScale() / hrd->getNumUnitsInTick() ) * ( hrd->getTickDivisorMinus2() + 2 ) ) / ( m_pcCfg->getTargetBitrate() ) );
    2039 #endif
    20402076              if( (UInt)ui64Tmp > maxDiff )
    20412077              {
     
    20492085            {
    20502086              flag = 0;
    2051 #if L0043_TIMING_INFO
    20522087              ui64Tmp = ( ( ( accumBitsDU[ numDU - 1 ]  - accumBitsDU[ i ] ) * ( vui->getTimingInfo()->getTimeScale() / vui->getTimingInfo()->getNumUnitsInTick() ) * ( hrd->getTickDivisorMinus2() + 2 ) ) / ( m_pcCfg->getTargetBitrate() ) );
    2053 #else
    2054               ui64Tmp = ( ( ( accumBitsDU[ numDU - 1 ]  - accumBitsDU[ i ] ) * ( hrd->getTimeScale() / hrd->getNumUnitsInTick() ) * ( hrd->getTickDivisorMinus2() + 2 ) ) / ( m_pcCfg->getTargetBitrate() ) );
    2055 #endif
    20562088
    20572089              if( (UInt)ui64Tmp > maxDiff )
     
    20852117          m_seiWriter.writeSEImessage(nalu.m_Bitstream, pictureTimingSEI, pcSlice->getSPS());
    20862118          writeRBSPTrailingBits(nalu.m_Bitstream);
    2087 #if L0045_NON_NESTED_SEI_RESTRICTIONS
    20882119          UInt seiPositionInAu = xGetFirstSeiLocation(accessUnit);
    20892120          UInt offsetPosition = m_activeParameterSetSEIPresentInAU
     
    20962127          accessUnit.insert(it, new NALUnitEBSP(nalu));
    20972128          m_pictureTimingSEIPresentInAU = true;
    2098 #else
    2099           AccessUnit::iterator it = find_if(accessUnit.begin(), accessUnit.end(), mem_fun(&NALUnit::isSlice));
    2100           accessUnit.insert(it, new NALUnitEBSP(nalu));
    2101 #endif
    2102         }
    2103 #if K0180_SCALABLE_NESTING_SEI
     2129        }
    21042130          if ( m_pcCfg->getScalableNestingSEIEnabled() ) // put picture timing SEI into scalable nesting SEI
    21052131          {
     
    21102136            m_seiWriter.writeSEImessage(nalu.m_Bitstream, scalableNestingSEI, pcSlice->getSPS());
    21112137            writeRBSPTrailingBits(nalu.m_Bitstream);
    2112 #if L0045_NON_NESTED_SEI_RESTRICTIONS
    21132138            UInt seiPositionInAu = xGetFirstSeiLocation(accessUnit);
    21142139            UInt offsetPosition = m_activeParameterSetSEIPresentInAU
     
    21212146            accessUnit.insert(it, new NALUnitEBSP(nalu));
    21222147            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
    21272148          }
    2128 #endif
    2129 
    21302149        }
    21312150        if( m_pcCfg->getDecodingUnitInfoSEIEnabled() && hrd->getSubPicCpbParamsPresentFlag() )
     
    21392158            tempSEI.m_decodingUnitIdx = i;
    21402159            tempSEI.m_duSptCpbRemovalDelay = pictureTimingSEI.m_duCpbRemovalDelayMinus1[i] + 1;
    2141 #if L0044_DU_DPB_OUTPUT_DELAY_HRD
    21422160            tempSEI.m_dpbOutputDuDelayPresentFlag = false;
    21432161            tempSEI.m_picSptDpbOutputDuDelay = picSptDpbOutputDuDelay;
    2144 #endif
    21452162
    21462163            AccessUnit::iterator it;
     
    21522169              writeRBSPTrailingBits(nalu.m_Bitstream);
    21532170
    2154 #if L0045_NON_NESTED_SEI_RESTRICTIONS
    21552171              UInt seiPositionInAu = xGetFirstSeiLocation(accessUnit);
    21562172              UInt offsetPosition = m_activeParameterSetSEIPresentInAU
     
    21622178              }
    21632179              accessUnit.insert(it, new NALUnitEBSP(nalu));
    2164 #else
    2165               it = find_if(accessUnit.begin(), accessUnit.end(), mem_fun(&NALUnit::isSlice));
    2166               accessUnit.insert(it, new NALUnitEBSP(nalu));
    2167 #endif
    21682180            }
    21692181            else
     
    21912203        }
    21922204      }
    2193 #if L0045_NON_NESTED_SEI_RESTRICTIONS
    21942205      xResetNonNestedSEIPresentFlags();
    2195 #if K0180_SCALABLE_NESTING_SEI
    21962206      xResetNestedSEIPresentFlags();
    2197 #endif
    2198 #endif
    21992207      pcPic->getPicYuvRec()->copyToPic(pcPicYuvRecOut);
     2208
     2209#if M0040_ADAPTIVE_RESOLUTION_CHANGE
     2210      pcPicYuvRecOut->setReconstructed(true);
     2211#endif
    22002212
    22012213      pcPic->setReconMark   ( true );
     
    23482360  }
    23492361 
    2350   assert (rpcPic->getPOC() == pocCurr);
     2362  assert( rpcPic != NULL );
     2363  assert( rpcPic->getPOC() == pocCurr );
    23512364 
    23522365  return;
     
    26202633    for (Int iRefIndex = 0; iRefIndex < pcSlice->getNumRefIdx(RefPicList(iRefList)); iRefIndex++)
    26212634    {
    2622 #if REF_IDX_FRAMEWORK && VPS_EXTN_DIRECT_REF_LAYERS_CONTINUE
     2635#if REF_IDX_FRAMEWORK && VPS_EXTN_DIRECT_REF_LAYERS
    26232636      if( pcSlice->getRefPic(RefPicList(iRefList), iRefIndex)->isILR(m_layerId) )
    26242637      {
     
    28482861}
    28492862
    2850 #if L0045_NON_NESTED_SEI_RESTRICTIONS
    28512863/** Function for finding the position to insert the first of APS and non-nested BP, PT, DU info SEI messages.
    28522864 * \param accessUnit Access Unit of the current picture
     
    28682880  return seiStartPos;
    28692881}
    2870 #endif
    2871 
    2872 #if L0386_DB_METRIC
     2882
    28732883Void TEncGOP::dblMetric( TComPic* pcPic, UInt uiNumSlices )
    28742884{
     
    28842894  const UInt noCol = (picWidth>>log2maxTB);
    28852895  const UInt noRows = (picHeight>>log2maxTB);
     2896  assert(noCol > 1);
     2897  assert(noRows > 1);
    28862898  UInt64 *colSAD = (UInt64*)malloc(noCol*sizeof(UInt64));
    28872899  UInt64 *rowSAD = (UInt64*)malloc(noRows*sizeof(UInt64));
     
    29923004  free(rowSAD);
    29933005}
    2994 #endif
     3006
     3007#if M0457_COL_PICTURE_SIGNALING
     3008TComPic* TEncGOP::getMotionPredIlp(TComSlice* pcSlice)
     3009{
     3010  TComPic* ilpPic = NULL;
     3011  Int activeMotionPredReflayerIdx = 0;
     3012
     3013  for( Int i = 0; i < pcSlice->getActiveNumILRRefIdx(); i++ )
     3014  {
     3015    UInt refLayerIdc = pcSlice->getInterLayerPredLayerIdc(i);
     3016    if( m_pcEncTop->getMotionPredEnabledFlag( pcSlice->getVPS()->getRefLayerId( m_layerId, refLayerIdc ) ) )
     3017    {
     3018      if (activeMotionPredReflayerIdx == pcSlice->getColRefLayerIdx())
     3019      {
     3020        ilpPic = m_pcEncTop->getIlpList()[refLayerIdc];
     3021        break;
     3022      }
     3023      else
     3024      {
     3025        activeMotionPredReflayerIdx++;
     3026      }
     3027    }
     3028  }
     3029
     3030  assert(ilpPic != NULL);
     3031
     3032  return ilpPic;
     3033}
     3034#endif
     3035
    29953036//! \}
  • trunk/source/Lib/TLibEncoder/TEncGOP.h

    r191 r310  
    127127  UInt                    m_tl0Idx;
    128128  UInt                    m_rapIdx;
    129 #if L0045_NON_NESTED_SEI_RESTRICTIONS
    130129  Bool                    m_activeParameterSetSEIPresentInAU;
    131130  Bool                    m_bufferingPeriodSEIPresentInAU;
    132131  Bool                    m_pictureTimingSEIPresentInAU;
    133 #if K0180_SCALABLE_NESTING_SEI
    134132  Bool                    m_nestedBufferingPeriodSEIPresentInAU;
    135133  Bool                    m_nestedPictureTimingSEIPresentInAU;
    136 #endif
    137 #endif
    138134public:
    139135  TEncGOP();
     
    180176
    181177  SEIActiveParameterSets* xCreateSEIActiveParameterSets (TComSPS *sps);
     178#if M0043_LAYERS_PRESENT_SEI
     179  SEILayersPresent*       xCreateSEILayersPresent ();
     180#endif
    182181  SEIFramePacking*        xCreateSEIFramePacking();
    183182  SEIDisplayOrientation*  xCreateSEIDisplayOrientation();
    184183
    185 #if J0149_TONE_MAPPING_SEI
    186184  SEIToneMappingInfo*     xCreateSEIToneMappingInfo();
    187 #endif
    188185
    189186  Void xCreateLeadingSEIMessages (/*SEIMessages seiMessages,*/ AccessUnit &accessUnit, TComSPS *sps);
    190 #if L0045_NON_NESTED_SEI_RESTRICTIONS
    191187  Int xGetFirstSeiLocation (AccessUnit &accessUnit);
    192188  Void xResetNonNestedSEIPresentFlags()
     
    196192    m_pictureTimingSEIPresentInAU      = false;
    197193  }
    198 #if K0180_SCALABLE_NESTING_SEI
    199194  Void xResetNestedSEIPresentFlags()
    200195  {
     
    202197    m_nestedPictureTimingSEIPresentInAU      = false;
    203198  }
    204 #endif
    205 #endif
    206 #if L0386_DB_METRIC
    207199  Void dblMetric( TComPic* pcPic, UInt uiNumSlices );
     200#if M0457_COL_PICTURE_SIGNALING
     201  TComPic* getMotionPredIlp(TComSlice* pcSlice);
    208202#endif
    209203};// END CLASS DEFINITION TEncGOP
  • trunk/source/Lib/TLibEncoder/TEncRateCtrl.cpp

    r191 r310  
    6767  m_bitsLeft            = 0;
    6868  m_useLCUSeparateModel = false;
     69#if M0036_RC_IMPROVEMENT
     70  m_adaptiveBit         = 0;
     71  m_lastLambda          = 0.0;
     72#endif
    6973}
    7074
     
    7478}
    7579
     80#if M0036_RC_IMPROVEMENT
     81Void TEncRCSeq::create( Int totalFrames, Int targetBitrate, Int frameRate, Int GOPSize, Int picWidth, Int picHeight, Int LCUWidth, Int LCUHeight, Int numberOfLevel, Bool useLCUSeparateModel, Int adaptiveBit )
     82#else
    7683Void TEncRCSeq::create( Int totalFrames, Int targetBitrate, Int frameRate, Int GOPSize, Int picWidth, Int picHeight, Int LCUWidth, Int LCUHeight, Int numberOfLevel, Bool useLCUSeparateModel )
     84#endif
    7785{
    7886  destroy();
     
    101109    m_betaUpdate  = 0.025;
    102110  }
    103   else
     111#if M0036_RC_IMPROVEMENT
     112  else if ( m_seqTargetBpp < 0.2 )
    104113  {
    105114    m_alphaUpdate = 0.1;
    106115    m_betaUpdate  = 0.05;
    107116  }
     117  else if ( m_seqTargetBpp < 0.5 )
     118  {
     119    m_alphaUpdate = 0.2;
     120    m_betaUpdate  = 0.1;
     121  }
     122  else
     123  {
     124    m_alphaUpdate = 0.4;
     125    m_betaUpdate  = 0.2;
     126  }
     127#else
     128  else
     129  {
     130    m_alphaUpdate = 0.1;
     131    m_betaUpdate  = 0.05;
     132  }
     133#endif
    108134  m_averageBits     = (Int)(m_targetBits / totalFrames);
    109135  Int picWidthInBU  = ( m_picWidth  % m_LCUWidth  ) == 0 ? m_picWidth  / m_LCUWidth  : m_picWidth  / m_LCUWidth  + 1;
     
    146172  m_framesLeft = m_totalFrames;
    147173  m_bitsLeft   = m_targetBits;
     174#if M0036_RC_IMPROVEMENT
     175  m_adaptiveBit = adaptiveBit;
     176  m_lastLambda = 0.0;
     177#endif
    148178}
    149179
     
    203233    for ( Int i=0; i<m_numberOfLevel; i++ )
    204234    {
     235#if RATE_CONTROL_INTRA
     236      if (i>0)
     237      {
    205238      m_picPara[i].m_alpha = 3.2003;
    206239      m_picPara[i].m_beta  = -1.367;
    207240    }
     241      else
     242      {
     243        m_picPara[i].m_alpha = ALPHA;   
     244        m_picPara[i].m_beta  = BETA2;
     245      }
     246#else
     247      m_picPara[i].m_alpha = 3.2003;
     248      m_picPara[i].m_beta  = -1.367;
     249#endif
     250    }
    208251  }
    209252  else
     
    228271      for ( Int j=0; j<m_numberOfLCU; j++)
    229272      {
     273#if RATE_CONTROL_INTRA
     274        m_LCUPara[i][j].m_alpha = m_picPara[i].m_alpha;
     275        m_LCUPara[i][j].m_beta  = m_picPara[i].m_beta;
     276#else
    230277        m_LCUPara[i][j].m_alpha = 3.2003;
    231278        m_LCUPara[i][j].m_beta  = -1.367;
     279#endif
    232280      }
    233281    }
     
    251299}
    252300
     301#if !RATE_CONTROL_INTRA
    253302Int TEncRCSeq::getRefineBitsForIntra( Int orgBits )
    254303{
     
    264313  return orgBits * 10;
    265314}
     315#endif
     316
     317#if M0036_RC_IMPROVEMENT
     318Void TEncRCSeq::setAllBitRatio( Double basicLambda, Double* equaCoeffA, Double* equaCoeffB )
     319{
     320  Int* bitsRatio = new Int[m_GOPSize];
     321  for ( Int i=0; i<m_GOPSize; i++ )
     322  {
     323    bitsRatio[i] = (Int)( equaCoeffA[i] * pow( basicLambda, equaCoeffB[i] ) * m_numberOfPixel );
     324  }
     325  initBitsRatio( bitsRatio );
     326  delete[] bitsRatio;
     327}
     328#endif
    266329
    267330//GOP level
     
    286349  Int targetBits = xEstGOPTargetBits( encRCSeq, numPic );
    287350
     351#if M0036_RC_IMPROVEMENT
     352  if ( encRCSeq->getAdaptiveBits() > 0 && encRCSeq->getLastLambda() > 0.1 )
     353  {
     354    Double targetBpp = (Double)targetBits / encRCSeq->getNumPixel();
     355    Double basicLambda = 0.0;
     356    Double* lambdaRatio = new Double[encRCSeq->getGOPSize()];
     357    Double* equaCoeffA = new Double[encRCSeq->getGOPSize()];
     358    Double* equaCoeffB = new Double[encRCSeq->getGOPSize()];
     359
     360    if ( encRCSeq->getAdaptiveBits() == 1 )   // for GOP size =4, low delay case
     361    {
     362      if ( encRCSeq->getLastLambda() < 120.0 )
     363      {
     364        lambdaRatio[1] = 0.725 * log( encRCSeq->getLastLambda() ) + 0.5793;
     365        lambdaRatio[0] = 1.3 * lambdaRatio[1];
     366        lambdaRatio[2] = 1.3 * lambdaRatio[1];
     367        lambdaRatio[3] = 1.0;
     368      }
     369      else
     370      {
     371        lambdaRatio[0] = 5.0;
     372        lambdaRatio[1] = 4.0;
     373        lambdaRatio[2] = 5.0;
     374        lambdaRatio[3] = 1.0;
     375      }
     376    }
     377    else if ( encRCSeq->getAdaptiveBits() == 2 )  // for GOP size = 8, random access case
     378    {
     379      if ( encRCSeq->getLastLambda() < 90.0 )
     380      {
     381        lambdaRatio[0] = 1.0;
     382        lambdaRatio[1] = 0.725 * log( encRCSeq->getLastLambda() ) + 0.7963;
     383        lambdaRatio[2] = 1.3 * lambdaRatio[1];
     384        lambdaRatio[3] = 3.25 * lambdaRatio[1];
     385        lambdaRatio[4] = 3.25 * lambdaRatio[1];
     386        lambdaRatio[5] = 1.3  * lambdaRatio[1];
     387        lambdaRatio[6] = 3.25 * lambdaRatio[1];
     388        lambdaRatio[7] = 3.25 * lambdaRatio[1];
     389      }
     390      else
     391      {
     392        lambdaRatio[0] = 1.0;
     393        lambdaRatio[1] = 4.0;
     394        lambdaRatio[2] = 5.0;
     395        lambdaRatio[3] = 12.3;
     396        lambdaRatio[4] = 12.3;
     397        lambdaRatio[5] = 5.0;
     398        lambdaRatio[6] = 12.3;
     399        lambdaRatio[7] = 12.3;
     400      }
     401    }
     402
     403    xCalEquaCoeff( encRCSeq, lambdaRatio, equaCoeffA, equaCoeffB, encRCSeq->getGOPSize() );
     404    basicLambda = xSolveEqua( targetBpp, equaCoeffA, equaCoeffB, encRCSeq->getGOPSize() );
     405    encRCSeq->setAllBitRatio( basicLambda, equaCoeffA, equaCoeffB );
     406
     407    delete []lambdaRatio;
     408    delete []equaCoeffA;
     409    delete []equaCoeffB;
     410  }
     411#endif
     412
    288413  m_picTargetBitInGOP = new Int[numPic];
    289414  Int i;
     
    297422  {
    298423    currPicRatio = encRCSeq->getBitRatio( i );
     424#if M0036_RC_IMPROVEMENT
     425    m_picTargetBitInGOP[i] = (Int)( ((Double)targetBits) * currPicRatio / totalPicRatio );
     426#else
    299427    m_picTargetBitInGOP[i] = targetBits * currPicRatio / totalPicRatio;
     428#endif
    300429  }
    301430
     
    306435  m_bitsLeft     = m_targetBits;
    307436}
     437
     438#if M0036_RC_IMPROVEMENT
     439Void TEncRCGOP::xCalEquaCoeff( TEncRCSeq* encRCSeq, Double* lambdaRatio, Double* equaCoeffA, Double* equaCoeffB, Int GOPSize )
     440{
     441  for ( Int i=0; i<GOPSize; i++ )
     442  {
     443    Int frameLevel = encRCSeq->getGOPID2Level(i);
     444    Double alpha   = encRCSeq->getPicPara(frameLevel).m_alpha;
     445    Double beta    = encRCSeq->getPicPara(frameLevel).m_beta;
     446    equaCoeffA[i] = pow( 1.0/alpha, 1.0/beta ) * pow( lambdaRatio[i], 1.0/beta );
     447    equaCoeffB[i] = 1.0/beta;
     448  }
     449}
     450
     451Double TEncRCGOP::xSolveEqua( Double targetBpp, Double* equaCoeffA, Double* equaCoeffB, Int GOPSize )
     452{
     453  Double solution = 100.0;
     454  Double minNumber = 0.1;
     455  Double maxNumber = 10000.0;
     456  for ( Int i=0; i<g_RCIterationNum; i++ )
     457  {
     458    Double fx = 0.0;
     459    for ( Int j=0; j<GOPSize; j++ )
     460    {
     461      fx += equaCoeffA[j] * pow( solution, equaCoeffB[j] );
     462    }
     463
     464    if ( fabs( fx - targetBpp ) < 0.000001 )
     465    {
     466      break;
     467    }
     468
     469    if ( fx > targetBpp )
     470    {
     471      minNumber = solution;
     472      solution = ( solution + maxNumber ) / 2.0;
     473    }
     474    else
     475    {
     476      maxNumber = solution;
     477      solution = ( solution + minNumber ) / 2.0;
     478    }
     479  }
     480
     481  solution = Clip3( 0.1, 10000.0, solution );
     482  return solution;
     483}
     484#endif
    308485
    309486Void TEncRCGOP::destroy()
     
    357534
    358535  m_LCUs         = NULL;
     536#if !M0036_RC_IMPROVEMENT
    359537  m_lastPicture  = NULL;
     538#endif
    360539  m_picActualHeaderBits = 0;
     540#if !M0036_RC_IMPROVEMENT
    361541  m_totalMAD            = 0.0;
     542#endif
    362543  m_picActualBits       = 0;
    363544  m_picQP               = 0;
     
    384565  }
    385566
     567#if M0036_RC_IMPROVEMENT
     568  targetBits  = Int( ((Double)GOPbitsLeft) * currPicRatio / totalPicRatio );
     569#else
    386570  targetBits  = Int( GOPbitsLeft * currPicRatio / totalPicRatio );
     571#endif
    387572
    388573  if ( targetBits < 100 )
     
    480665      m_LCUs[LCUIdx].m_lambda     = 0.0;
    481666      m_LCUs[LCUIdx].m_targetBits = 0;
     667#if M0036_RC_IMPROVEMENT
     668      m_LCUs[LCUIdx].m_bitWeight  = 1.0;
     669#else
    482670      m_LCUs[LCUIdx].m_MAD        = 0.0;
     671#endif
    483672      Int currWidth  = ( (i == picWidthInLCU -1) ? picWidth  - LCUWidth *(picWidthInLCU -1) : LCUWidth  );
    484673      Int currHeight = ( (j == picHeightInLCU-1) ? picHeight - LCUHeight*(picHeightInLCU-1) : LCUHeight );
     
    487676  }
    488677  m_picActualHeaderBits = 0;
     678#if !M0036_RC_IMPROVEMENT
    489679  m_totalMAD            = 0.0;
     680#endif
    490681  m_picActualBits       = 0;
    491682  m_picQP               = 0;
    492683  m_picLambda           = 0.0;
    493684
     685#if !M0036_RC_IMPROVEMENT
    494686  m_lastPicture = NULL;
    495687  list<TEncRCPic*>::reverse_iterator it;
     
    502694    }
    503695  }
     696#endif
    504697}
    505698
     
    515708}
    516709
     710
     711#if RATE_CONTROL_INTRA
     712Double TEncRCPic::estimatePicLambda( list<TEncRCPic*>& listPreviousPictures, SliceType eSliceType)
     713#else
    517714Double TEncRCPic::estimatePicLambda( list<TEncRCPic*>& listPreviousPictures )
     715#endif
    518716{
    519717  Double alpha         = m_encRCSeq->getPicPara( m_frameLevel ).m_alpha;
    520718  Double beta          = m_encRCSeq->getPicPara( m_frameLevel ).m_beta;
    521719  Double bpp       = (Double)m_targetBits/(Double)m_numberOfPixel;
     720#if RATE_CONTROL_INTRA
     721  Double estLambda;
     722  if (eSliceType == I_SLICE)
     723  {
     724    estLambda = calculateLambdaIntra(alpha, beta, pow(m_totalCostIntra/(Double)m_numberOfPixel, BETA1), bpp);
     725  }
     726  else
     727  {
     728    estLambda = alpha * pow( bpp, beta );
     729  }
     730#else
    522731  Double estLambda = alpha * pow( bpp, beta );
     732#endif 
     733 
    523734  Double lastLevelLambda = -1.0;
    524735  Double lastPicLambda   = -1.0;
     
    566777
    567778  m_estPicLambda = estLambda;
     779
     780#if M0036_RC_IMPROVEMENT
     781  Double totalWeight = 0.0;
     782  // initial BU bit allocation weight
     783  for ( Int i=0; i<m_numberOfLCU; i++ )
     784  {
     785#if RC_FIX
     786    Double alphaLCU, betaLCU;
     787    if ( m_encRCSeq->getUseLCUSeparateModel() )
     788    {
     789      alphaLCU = m_encRCSeq->getLCUPara( m_frameLevel, i ).m_alpha;
     790      betaLCU  = m_encRCSeq->getLCUPara( m_frameLevel, i ).m_beta;
     791    }
     792    else
     793    {
     794      alphaLCU = m_encRCSeq->getPicPara( m_frameLevel ).m_alpha;
     795      betaLCU  = m_encRCSeq->getPicPara( m_frameLevel ).m_beta;
     796    }
     797#else
     798    Double alphaLCU = m_encRCSeq->getLCUPara( m_frameLevel, i ).m_alpha;
     799    Double betaLCU  = m_encRCSeq->getLCUPara( m_frameLevel, i ).m_beta;
     800#endif
     801
     802    m_LCUs[i].m_bitWeight =  m_LCUs[i].m_numberOfPixel * pow( estLambda/alphaLCU, 1.0/betaLCU );
     803
     804    if ( m_LCUs[i].m_bitWeight < 0.01 )
     805    {
     806      m_LCUs[i].m_bitWeight = 0.01;
     807    }
     808    totalWeight += m_LCUs[i].m_bitWeight;
     809  }
     810  for ( Int i=0; i<m_numberOfLCU; i++ )
     811  {
     812    Double BUTargetBits = m_targetBits * m_LCUs[i].m_bitWeight / totalWeight;
     813    m_LCUs[i].m_bitWeight = BUTargetBits;
     814  }
     815#endif
     816
    568817  return estLambda;
    569818}
     
    607856}
    608857
     858#if RATE_CONTROL_INTRA
     859Double TEncRCPic::getLCUTargetBpp(SliceType eSliceType) 
     860#else
    609861Double TEncRCPic::getLCUTargetBpp()
     862#endif
    610863{
    611864  Int   LCUIdx    = getLCUCoded();
    612865  Double bpp      = -1.0;
    613866  Int avgBits     = 0;
     867#if !M0036_RC_IMPROVEMENT
    614868  Double totalMAD = -1.0;
    615869  Double MAD      = -1.0;
    616 
     870#endif
     871
     872#if RATE_CONTROL_INTRA
     873  if (eSliceType == I_SLICE){
     874    Int noOfLCUsLeft = m_numberOfLCU - LCUIdx + 1;
     875    Int bitrateWindow = min(4,noOfLCUsLeft);
     876    Double MAD      = getLCU(LCUIdx).m_costIntra;
     877
     878    if (m_remainingCostIntra > 0.1 )
     879    {
     880      Double weightedBitsLeft = (m_bitsLeft*bitrateWindow+(m_bitsLeft-getLCU(LCUIdx).m_targetBitsLeft)*noOfLCUsLeft)/(Double)bitrateWindow;
     881      avgBits = Int( MAD*weightedBitsLeft/m_remainingCostIntra );
     882    }
     883    else
     884    {
     885      avgBits = Int( m_bitsLeft / m_LCULeft );
     886    }
     887    m_remainingCostIntra -= MAD;
     888  }
     889  else
     890  {
     891#endif
     892#if M0036_RC_IMPROVEMENT
     893  Double totalWeight = 0;
     894  for ( Int i=LCUIdx; i<m_numberOfLCU; i++ )
     895  {
     896    totalWeight += m_LCUs[i].m_bitWeight;
     897  }
     898  Int realInfluenceLCU = min( g_RCLCUSmoothWindowSize, getLCULeft() );
     899  avgBits = (Int)( m_LCUs[LCUIdx].m_bitWeight - ( totalWeight - m_bitsLeft ) / realInfluenceLCU + 0.5 );
     900#else
    617901  if ( m_lastPicture == NULL )
    618902  {
     
    637921    }
    638922  }
    639 
    640 #if L0033_RC_BUGFIX
     923#endif
     924#if RATE_CONTROL_INTRA
     925  }
     926#endif
     927
    641928  if ( avgBits < 1 )
    642929  {
    643930    avgBits = 1;
    644931  }
    645 #else
    646   if ( avgBits < 5 )
    647   {
    648     avgBits = 5;
    649   }
    650 #endif
    651932
    652933  bpp = ( Double )avgBits/( Double )m_LCUs[ LCUIdx ].m_numberOfPixel;
     
    716997  //for Lambda clip, LCU level clip
    717998  Int clipNeighbourQP = g_RCInvalidQPValue;
    718 #if L0033_RC_BUGFIX
    719999  for ( int i=LCUIdx - 1; i>=0; i-- )
    720 #else
    721   for ( int i=LCUIdx; i>=0; i-- )
    722 #endif
    7231000  {
    7241001    if ( (getLCU(i)).m_QP > g_RCInvalidQPValue )
     
    7731050    beta  *= ( 1.0 - m_encRCSeq->getBetaUpdate() / 2.0 );
    7741051
     1052#if M0036_RC_IMPROVEMENT
     1053    alpha = Clip3( g_RCAlphaMinValue, g_RCAlphaMaxValue, alpha );
     1054    beta  = Clip3( g_RCBetaMinValue,  g_RCBetaMaxValue,  beta  );
     1055#else
    7751056    alpha = Clip3( 0.05, 20.0, alpha );
    7761057    beta  = Clip3( -3.0, -0.1, beta  );
     1058#endif
    7771059
    7781060    TRCParameter rcPara;
     
    7871069  alpha += m_encRCSeq->getAlphaUpdate() * ( log( inputLambda ) - log( calLambda ) ) * alpha;
    7881070  double lnbpp = log( bpp );
     1071#if M0036_RC_IMPROVEMENT
     1072  lnbpp = Clip3( -5.0, -0.1, lnbpp );
     1073#else
    7891074  lnbpp = Clip3( -5.0, 1.0, lnbpp );
     1075#endif
    7901076  beta  += m_encRCSeq->getBetaUpdate() * ( log( inputLambda ) - log( calLambda ) ) * lnbpp;
    7911077
     1078#if M0036_RC_IMPROVEMENT
     1079  alpha = Clip3( g_RCAlphaMinValue, g_RCAlphaMaxValue, alpha );
     1080  beta  = Clip3( g_RCBetaMinValue,  g_RCBetaMaxValue,  beta  );
     1081#else
    7921082  alpha = Clip3( 0.05, 20.0, alpha );
    7931083  beta  = Clip3( -3.0, -0.1, beta  );
     1084#endif
    7941085  TRCParameter rcPara;
    7951086  rcPara.m_alpha = alpha;
     
    7991090}
    8001091
     1092#if !M0036_RC_IMPROVEMENT
    8011093Double TEncRCPic::getEffectivePercentage()
    8021094{
     
    8161108  return effectivePixelPercentage;
    8171109}
     1110#endif
    8181111
    8191112Double TEncRCPic::calAverageQP()
     
    8711164}
    8721165
     1166#if M0036_RC_IMPROVEMENT
     1167#if RATE_CONTROL_INTRA
     1168Void TEncRCPic::updateAfterPicture( Int actualHeaderBits, Int actualTotalBits, Double averageQP, Double averageLambda, SliceType eSliceType)
     1169#else
     1170Void TEncRCPic::updateAfterPicture( Int actualHeaderBits, Int actualTotalBits, Double averageQP, Double averageLambda )
     1171#endif
     1172#else
    8731173Void TEncRCPic::updateAfterPicture( Int actualHeaderBits, Int actualTotalBits, Double averageQP, Double averageLambda, Double effectivePercentage )
     1174#endif
    8741175{
    8751176  m_picActualHeaderBits = actualHeaderBits;
     
    8841185  }
    8851186  m_picLambda           = averageLambda;
     1187#if !M0036_RC_IMPROVEMENT
    8861188  for ( Int i=0; i<m_numberOfLCU; i++ )
    8871189  {
    8881190    m_totalMAD += m_LCUs[i].m_MAD;
    8891191  }
     1192#endif
    8901193
    8911194  Double alpha = m_encRCSeq->getPicPara( m_frameLevel ).m_alpha;
    8921195  Double beta  = m_encRCSeq->getPicPara( m_frameLevel ).m_beta;
    893 
     1196#if RATE_CONTROL_INTRA
     1197  if (eSliceType == I_SLICE)
     1198  {
     1199    updateAlphaBetaIntra(&alpha, &beta);
     1200  }
     1201  else
     1202  {
     1203#endif
    8941204  // update parameters
    8951205  Double picActualBits = ( Double )m_picActualBits;
     
    8981208  Double inputLambda   = m_picLambda;
    8991209
     1210#if M0036_RC_IMPROVEMENT
     1211  if ( inputLambda < 0.01 || calLambda < 0.01 || picActualBpp < 0.0001 )
     1212#else
    9001213  if ( inputLambda < 0.01 || calLambda < 0.01 || picActualBpp < 0.0001 || effectivePercentage < 0.05 )
     1214#endif
    9011215  {
    9021216    alpha *= ( 1.0 - m_encRCSeq->getAlphaUpdate() / 2.0 );
    9031217    beta  *= ( 1.0 - m_encRCSeq->getBetaUpdate() / 2.0 );
    9041218
     1219#if M0036_RC_IMPROVEMENT
     1220    alpha = Clip3( g_RCAlphaMinValue, g_RCAlphaMaxValue, alpha );
     1221    beta  = Clip3( g_RCBetaMinValue,  g_RCBetaMaxValue,  beta  );
     1222#else
    9051223    alpha = Clip3( 0.05, 20.0, alpha );
    9061224    beta  = Clip3( -3.0, -0.1, beta  );
     1225#endif
    9071226    TRCParameter rcPara;
    9081227    rcPara.m_alpha = alpha;
     
    9161235  alpha += m_encRCSeq->getAlphaUpdate() * ( log( inputLambda ) - log( calLambda ) ) * alpha;
    9171236  double lnbpp = log( picActualBpp );
     1237#if M0036_RC_IMPROVEMENT
     1238  lnbpp = Clip3( -5.0, -0.1, lnbpp );
     1239#else
    9181240  lnbpp = Clip3( -5.0, 1.0, lnbpp );
     1241#endif
    9191242  beta  += m_encRCSeq->getBetaUpdate() * ( log( inputLambda ) - log( calLambda ) ) * lnbpp;
    9201243
     1244#if M0036_RC_IMPROVEMENT
     1245  alpha = Clip3( g_RCAlphaMinValue, g_RCAlphaMaxValue, alpha );
     1246  beta  = Clip3( g_RCBetaMinValue,  g_RCBetaMaxValue,  beta  );
     1247#else
    9211248  alpha = Clip3( 0.05, 20.0, alpha );
    9221249  beta  = Clip3( -3.0, -0.1, beta  );
     1250#endif
     1251#if RATE_CONTROL_INTRA
     1252  }
     1253#endif
    9231254
    9241255  TRCParameter rcPara;
     
    9271258
    9281259  m_encRCSeq->setPicPara( m_frameLevel, rcPara );
    929 }
     1260
     1261#if M0036_RC_IMPROVEMENT
     1262  if ( m_frameLevel == 1 )
     1263  {
     1264    Double currLambda = Clip3( 0.1, 10000.0, m_picLambda );
     1265    Double updateLastLambda = g_RCWeightHistoryLambda * m_encRCSeq->getLastLambda() + g_RCWeightCurrentLambda * currLambda;
     1266    m_encRCSeq->setLastLambda( updateLastLambda );
     1267  }
     1268#endif
     1269}
     1270
     1271#if RATE_CONTROL_INTRA
     1272Int TEncRCPic::getRefineBitsForIntra( Int orgBits )
     1273{
     1274  Double alpha=0.25, beta=0.5582;
     1275  Int iIntraBits;
     1276
     1277  if (orgBits*40 < m_numberOfPixel)
     1278  {
     1279    alpha=0.25;
     1280  }
     1281  else
     1282  {
     1283    alpha=0.30;
     1284  }
     1285
     1286  iIntraBits = (Int)(alpha* pow(m_totalCostIntra*4.0/(Double)orgBits, beta)*(Double)orgBits+0.5);
     1287 
     1288  return iIntraBits;
     1289}
     1290
     1291Double TEncRCPic::calculateLambdaIntra(double alpha, double beta, double MADPerPixel, double bitsPerPixel)
     1292{
     1293  return ( (alpha/256.0) * pow( MADPerPixel/bitsPerPixel, beta ) );
     1294}
     1295
     1296Void TEncRCPic::updateAlphaBetaIntra(double *alpha, double *beta)
     1297{
     1298  Double lnbpp = log(pow(m_totalCostIntra / (Double)m_numberOfPixel, BETA1));
     1299  Double diffLambda = (*beta)*(log((Double)m_picActualBits)-log((Double)m_targetBits));
     1300
     1301  diffLambda = Clip3(-0.125, 0.125, 0.25*diffLambda);
     1302  *alpha    =  (*alpha) * exp(diffLambda);
     1303  *beta     =  (*beta) + diffLambda / lnbpp;
     1304}
     1305
     1306
     1307Void TEncRCPic::getLCUInitTargetBits() 
     1308{
     1309  Int iAvgBits     = 0;
     1310
     1311  m_remainingCostIntra = m_totalCostIntra;
     1312  for (Int i=m_numberOfLCU-1; i>=0; i--)
     1313  {
     1314    iAvgBits += Int(m_targetBits * getLCU(i).m_costIntra/m_totalCostIntra);
     1315    getLCU(i).m_targetBitsLeft = iAvgBits;
     1316  }
     1317}
     1318
     1319
     1320Double TEncRCPic::getLCUEstLambdaAndQP(Double bpp, Int clipPicQP, Int *estQP)
     1321{
     1322  Int   LCUIdx = getLCUCoded();
     1323
     1324  Double   alpha = m_encRCSeq->getPicPara( m_frameLevel ).m_alpha;
     1325  Double   beta  = m_encRCSeq->getPicPara( m_frameLevel ).m_beta;
     1326
     1327  Double costPerPixel = getLCU(LCUIdx).m_costIntra/(Double)getLCU(LCUIdx).m_numberOfPixel;
     1328  costPerPixel = pow(costPerPixel, BETA1);
     1329  Double estLambda = calculateLambdaIntra(alpha, beta, costPerPixel, bpp);
     1330
     1331  Int clipNeighbourQP = g_RCInvalidQPValue;
     1332  for (int i=LCUIdx-1; i>=0; i--)
     1333  {
     1334    if ((getLCU(i)).m_QP > g_RCInvalidQPValue)
     1335    {
     1336      clipNeighbourQP = getLCU(i).m_QP;
     1337      break;
     1338    }
     1339  }
     1340
     1341  Int minQP = clipPicQP - 2;
     1342  Int maxQP = clipPicQP + 2;
     1343
     1344  if ( clipNeighbourQP > g_RCInvalidQPValue )
     1345  {
     1346    maxQP = min(clipNeighbourQP + 1, maxQP);
     1347    minQP = max(clipNeighbourQP - 1, minQP);
     1348  }
     1349
     1350  Double maxLambda=exp(((Double)(maxQP+0.49)-13.7122)/4.2005);
     1351  Double minLambda=exp(((Double)(minQP-0.49)-13.7122)/4.2005);
     1352
     1353  estLambda = Clip3(minLambda, maxLambda, estLambda);
     1354
     1355  *estQP = Int( 4.2005 * log(estLambda) + 13.7122 + 0.5 );
     1356  *estQP = Clip3(minQP, maxQP, *estQP);
     1357
     1358  return estLambda;
     1359}
     1360#endif
    9301361
    9311362TEncRateCtrl::TEncRateCtrl()
     
    9611392}
    9621393
     1394#if M0036_RC_IMPROVEMENT
     1395Void TEncRateCtrl::init( Int totalFrames, Int targetBitrate, Int frameRate, Int GOPSize, Int picWidth, Int picHeight, Int LCUWidth, Int LCUHeight, Int keepHierBits, Bool useLCUSeparateModel, GOPEntry  GOPList[MAX_GOP] )
     1396#else
    9631397Void TEncRateCtrl::init( Int totalFrames, Int targetBitrate, Int frameRate, Int GOPSize, Int picWidth, Int picHeight, Int LCUWidth, Int LCUHeight, Bool keepHierBits, Bool useLCUSeparateModel, GOPEntry  GOPList[MAX_GOP] )
     1398#endif
    9641399{
    9651400  destroy();
     
    9761411
    9771412  Int numberOfLevel = 1;
     1413#if M0036_RC_IMPROVEMENT
     1414  Int adaptiveBit = 0;
     1415  if ( keepHierBits > 0 )
     1416#else
    9781417  if ( keepHierBits )
     1418#endif
    9791419  {
    9801420    numberOfLevel = Int( log((Double)GOPSize)/log(2.0) + 0.5 ) + 1;
     
    9981438    }
    9991439  }
     1440
     1441#if M0036_RC_IMPROVEMENT
     1442  if ( keepHierBits > 0 )
     1443#else
    10001444  if ( keepHierBits )
     1445#endif
    10011446  {
    10021447    Double bpp = (Double)( targetBitrate / (Double)( frameRate*picWidth*picHeight ) );
     
    10311476        bitsRatio[3] = 14;
    10321477      }
     1478#if M0036_RC_IMPROVEMENT
     1479      if ( keepHierBits == 2 )
     1480      {
     1481        adaptiveBit = 1;
     1482      }
     1483#endif
    10331484    }
    10341485    else if ( GOPSize == 8 && !isLowdelay )
     
    10781529        bitsRatio[7] = 1;
    10791530      }
     1531#if M0036_RC_IMPROVEMENT
     1532      if ( keepHierBits == 2 )
     1533      {
     1534        adaptiveBit = 2;
     1535      }
     1536#endif
    10801537    }
    10811538    else
    10821539    {
     1540#if M0036_RC_IMPROVEMENT
     1541      printf( "\n hierarchical bit allocation is not support for the specified coding structure currently.\n" );
     1542#else
    10831543      printf( "\n hierarchical bit allocation is not support for the specified coding structure currently." );
     1544#endif
    10841545    }
    10851546  }
     
    10941555    }
    10951556  }
     1557#if M0036_RC_IMPROVEMENT
     1558  if ( keepHierBits > 0 )
     1559#else
    10961560  if ( keepHierBits )
     1561#endif
    10971562  {
    10981563    if ( GOPSize == 4 && isLowdelay )
     
    11291594
    11301595  m_encRCSeq = new TEncRCSeq;
     1596#if M0036_RC_IMPROVEMENT
     1597  m_encRCSeq->create( totalFrames, targetBitrate, frameRate, GOPSize, picWidth, picHeight, LCUWidth, LCUHeight, numberOfLevel, useLCUSeparateModel, adaptiveBit );
     1598#else
    11311599  m_encRCSeq->create( totalFrames, targetBitrate, frameRate, GOPSize, picWidth, picHeight, LCUWidth, LCUHeight, numberOfLevel, useLCUSeparateModel );
     1600#endif
    11321601  m_encRCSeq->initBitsRatio( bitsRatio );
    11331602  m_encRCSeq->initGOPID2Level( GOPID2Level );
  • trunk/source/Lib/TLibEncoder/TEncRateCtrl.h

    r191 r310  
    6565const Double g_RCWeightPicTargetBitInGOP    = 0.9;
    6666const Double g_RCWeightPicRargetBitInBuffer = 1.0 - g_RCWeightPicTargetBitInGOP;
     67#if M0036_RC_IMPROVEMENT
     68const Int g_RCIterationNum = 20;
     69const Double g_RCWeightHistoryLambda = 0.5;
     70const Double g_RCWeightCurrentLambda = 1.0 - g_RCWeightHistoryLambda;
     71const Int g_RCLCUSmoothWindowSize = 4;
     72const Double g_RCAlphaMinValue = 0.05;
     73const Double g_RCAlphaMaxValue = 500.0;
     74const Double g_RCBetaMinValue  = -3.0;
     75const Double g_RCBetaMaxValue  = -0.1;
     76#endif
     77
     78#if RATE_CONTROL_INTRA
     79#define ALPHA     6.7542;
     80#define BETA1     1.2517
     81#define BETA2     1.7860
     82#endif
    6783
    6884struct TRCLCU
     
    7288  Int m_targetBits;
    7389  Double m_lambda;
     90#if M0036_RC_IMPROVEMENT
     91  Double m_bitWeight;
     92#else
    7493  Double m_MAD;
     94#endif
    7595  Int m_numberOfPixel;
     96#if RATE_CONTROL_INTRA
     97  Double m_costIntra;
     98  Int m_targetBitsLeft;
     99#endif
    76100};
    77101
     
    89113
    90114public:
     115#if M0036_RC_IMPROVEMENT
     116  Void create( Int totalFrames, Int targetBitrate, Int frameRate, Int GOPSize, Int picWidth, Int picHeight, Int LCUWidth, Int LCUHeight, Int numberOfLevel, Bool useLCUSeparateModel, Int adaptiveBit );
     117#else
    91118  Void create( Int totalFrames, Int targetBitrate, Int frameRate, Int GOPSize, Int picWidth, Int picHeight, Int LCUWidth, Int LCUHeight, Int numberOfLevel, Bool useLCUSeparateModel );
     119#endif
    92120  Void destroy();
    93121  Void initBitsRatio( Int bitsRatio[] );
     
    96124  Void initLCUPara( TRCParameter** LCUPara = NULL );    // NULL to initial with default value
    97125  Void updateAfterPic ( Int bits );
     126#if !RATE_CONTROL_INTRA
    98127  Int  getRefineBitsForIntra( Int orgBits );
     128#endif
     129#if M0036_RC_IMPROVEMENT
     130  Void setAllBitRatio( Double basicLambda, Double* equaCoeffA, Double* equaCoeffB );
     131#endif
    99132
    100133public:
     
    134167  Double getBetaUpdate()                { return m_betaUpdate; }
    135168
     169#if M0036_RC_IMPROVEMENT
     170  Int    getAdaptiveBits()              { return m_adaptiveBit;  }
     171  Double getLastLambda()                { return m_lastLambda;   }
     172  Void   setLastLambda( Double lamdba ) { m_lastLambda = lamdba; }
     173#endif
     174
    136175private:
    137176  Int m_totalFrames;
     
    160199  Double m_betaUpdate;
    161200  Bool m_useLCUSeparateModel;
     201
     202#if M0036_RC_IMPROVEMENT
     203  Int m_adaptiveBit;
     204  Double m_lastLambda;
     205#endif
    162206};
    163207
     
    175219private:
    176220  Int  xEstGOPTargetBits( TEncRCSeq* encRCSeq, Int GOPSize );
     221#if M0036_RC_IMPROVEMENT
     222  Void   xCalEquaCoeff( TEncRCSeq* encRCSeq, Double* lambdaRatio, Double* equaCoeffA, Double* equaCoeffB, Int GOPSize );
     223  Double xSolveEqua( Double targetBpp, Double* equaCoeffA, Double* equaCoeffB, Int GOPSize );
     224#endif
    177225
    178226public:
     
    203251  Void destroy();
    204252
     253#if !RATE_CONTROL_INTRA
    205254  Double estimatePicLambda( list<TEncRCPic*>& listPreviousPictures );
     255#endif
    206256  Int    estimatePicQP    ( Double lambda, list<TEncRCPic*>& listPreviousPictures );
     257#if RATE_CONTROL_INTRA
     258  Int    getRefineBitsForIntra(Int orgBits);
     259  Double calculateLambdaIntra(double alpha, double beta, double MADPerPixel, double bitsPerPixel);
     260  Double estimatePicLambda( list<TEncRCPic*>& listPreviousPictures, SliceType eSliceType);
     261
     262  Void   updateAlphaBetaIntra(double *alpha, double *beta);
     263
     264  Double getLCUTargetBpp(SliceType eSliceType);
     265  Double getLCUEstLambdaAndQP(Double bpp, Int clipPicQP, Int *estQP);
     266#else
    207267  Double getLCUTargetBpp();
     268#endif
    208269  Double getLCUEstLambda( Double bpp );
    209270  Int    getLCUEstQP( Double lambda, Int clipPicQP );
    210271
    211272  Void updateAfterLCU( Int LCUIdx, Int bits, Int QP, Double lambda, Bool updateLCUParameter = true );
     273#if M0036_RC_IMPROVEMENT
     274#if RATE_CONTROL_INTRA
     275  Void updateAfterPicture( Int actualHeaderBits, Int actualTotalBits, Double averageQP, Double averageLambda, SliceType eSliceType);
     276#else
     277  Void updateAfterPicture( Int actualHeaderBits, Int actualTotalBits, Double averageQP, Double averageLambda );
     278#endif
     279#else
    212280  Void updateAfterPicture( Int actualHeaderBits, Int actualTotalBits, Double averageQP, Double averageLambda, Double effectivePercentage );
     281#endif
    213282
    214283  Void addToPictureLsit( list<TEncRCPic*>& listPreviousPictures );
     284#if !M0036_RC_IMPROVEMENT
    215285  Double getEffectivePercentage();
     286#endif
    216287  Double calAverageQP();
    217288  Double calAverageLambda();
     
    229300  Int  getNumberOfLCU()                                   { return m_numberOfLCU; }
    230301  Int  getTargetBits()                                    { return m_targetBits; }
     302#if !RATE_CONTROL_INTRA
    231303  Void setTargetBits( Int bits )                          { m_targetBits = bits; }
     304#endif
    232305  Int  getEstHeaderBits()                                 { return m_estHeaderBits; }
    233306  Int  getLCULeft()                                       { return m_LCULeft; }
     
    239312  TRCLCU& getLCU( Int LCUIdx )                            { return m_LCUs[LCUIdx]; }
    240313  Int  getPicActualHeaderBits()                           { return m_picActualHeaderBits; }
     314#if !M0036_RC_IMPROVEMENT
    241315  Double getTotalMAD()                                    { return m_totalMAD; }
    242316  Void   setTotalMAD( Double MAD )                        { m_totalMAD = MAD; }
     317#endif
     318#if RATE_CONTROL_INTRA
     319  Void setTargetBits( Int bits )                          { m_targetBits = bits; m_bitsLeft = bits;}
     320  Void setTotalIntraCost(Double cost)                     { m_totalCostIntra = cost; }
     321  Void getLCUInitTargetBits();
     322#endif
     323
    243324  Int  getPicActualBits()                                 { return m_picActualBits; }
    244325  Int  getPicActualQP()                                   { return m_picQP; }
     
    267348  TRCLCU* m_LCUs;
    268349  Int m_picActualHeaderBits;    // only SH and potential APS
     350#if !M0036_RC_IMPROVEMENT
    269351  Double m_totalMAD;
     352#endif
     353#if RATE_CONTROL_INTRA
     354  Double m_totalCostIntra;
     355  Double m_remainingCostIntra;
     356#endif
    270357  Int m_picActualBits;          // the whole picture, including header
    271358  Int m_picQP;                  // in integer form
    272359  Double m_picLambda;
     360#if !M0036_RC_IMPROVEMENT
    273361  TEncRCPic* m_lastPicture;
     362#endif
    274363};
    275364
     
    281370
    282371public:
     372#if M0036_RC_IMPROVEMENT
     373  Void init( Int totalFrames, Int targetBitrate, Int frameRate, Int GOPSize, Int picWidth, Int picHeight, Int LCUWidth, Int LCUHeight, Int keepHierBits, Bool useLCUSeparateModel, GOPEntry GOPList[MAX_GOP] );
     374#else
    283375  Void init( Int totalFrames, Int targetBitrate, Int frameRate, Int GOPSize, Int picWidth, Int picHeight, Int LCUWidth, Int LCUHeight, Bool keepHierBits, Bool useLCUSeparateModel, GOPEntry GOPList[MAX_GOP] );
     376#endif
    284377  Void destroy();
    285378  Void initRCPic( Int frameLevel );
  • trunk/source/Lib/TLibEncoder/TEncSampleAdaptiveOffset.cpp

    r191 r310  
    299299        m_iTypePartBest[iPartIdx] = -1;
    300300        if( m_bUseSBACRD )
     301        {
    301302          m_pcRDGoOnSbacCoder->store( m_pppcRDSbacCoder[pOnePart->PartLevel][CI_TEMP_BEST] );
     303        }
    302304      }
    303305    }
  • trunk/source/Lib/TLibEncoder/TEncSearch.cpp

    r191 r310  
    14101410 
    14111411#if HHI_RQT_INTRA_SPEEDUP
    1412 #if L0232_RD_PENALTY
    14131412  Int maxTuSize = pcCU->getSlice()->getSPS()->getQuadtreeTULog2MaxSize();
    14141413  Int isIntraSlice = (pcCU->getSlice()->getSliceType() == I_SLICE);
     
    14271426  }
    14281427  if( bCheckFirst && noSplitIntraMaxTuSize )
     1428  {
     1429    bCheckSplit = false;
     1430  }
    14291431#else
    1430   if( bCheckFirst && bCheckFull )
    1431 #endif
    1432   {
    1433     bCheckSplit = false;
    1434   }
    1435 #else
    1436 #if L0232_RD_PENALTY
    14371432  Int maxTuSize = pcCU->getSlice()->getSPS()->getQuadtreeTULog2MaxSize();
    14381433  Int isIntraSlice = (pcCU->getSlice()->getSliceType() == I_SLICE);
     
    14421437    bCheckFull    = ( uiLog2TrSize  <= min(maxTuSize,4));
    14431438  }
    1444 #endif
    14451439#endif
    14461440  Double  dSingleCost   = MAX_DOUBLE;
     
    16171611      //----- determine rate and r-d cost -----
    16181612      UInt uiSingleBits = xGetIntraBitsQT( pcCU, uiTrDepth, uiAbsPartIdx, true, !bLumaOnly, false );
    1619 #if L0232_RD_PENALTY
    16201613      if(m_pcEncCfg->getRDpenalty() && (uiLog2TrSize==5) && !isIntraSlice)
    16211614      {
    16221615        uiSingleBits=uiSingleBits*4;
    16231616      }
    1624 #endif
    16251617      dSingleCost       = m_pcRdCost->calcRdCost( uiSingleBits, uiSingleDistY + uiSingleDistC );
    16261618    }
     
    25062498    {
    25072499      assert(numModesForFullRD < numModesAvailable);
     2500#if FAST_INTRA_SHVC
     2501      Int   uiPreds[3] = {-1, -1, -1};
     2502      Int   iMode = -1;
     2503      Bool  skipFastHAD = false;
     2504      Int numCand = pcCU->getIntraDirLumaPredictor( uiPartOffset, uiPreds, &iMode );
     2505
     2506      if ( m_pcEncCfg->getUseFastIntraScalable() )
     2507      {
     2508        if( pcCU->getLayerId() > 0 )
     2509        {
     2510          numModesAvailable = pcCU->reduceSetOfIntraModes(uiPartOffset, uiPreds, iMode );
     2511          if( numModesForFullRD > numModesAvailable ) //fast HAD can be skipped
     2512          {
     2513            skipFastHAD = true;
     2514            numModesForFullRD = numModesAvailable;
     2515            for( Int i=0; i < numModesForFullRD; i++ )
     2516              uiRdModeList[ i ] = g_reducedSetIntraModes[ i ];
     2517          }
     2518        }
     2519      }
     2520#endif
    25082521
    25092522      for( Int i=0; i < numModesForFullRD; i++ )
     
    25162529      {
    25172530        UInt uiMode = modeIdx;
     2531#if FAST_INTRA_SHVC
     2532        if ( m_pcEncCfg->getUseFastIntraScalable() )
     2533        {
     2534          if( skipFastHAD )//indicates that fast HAD can be skipped
     2535            break;
     2536          uiMode = ( iMode==0 ) ? g_reducedSetIntraModes[modeIdx] : uiMode; //(iMode=0) indicates reduced set of modes
     2537        }
     2538#endif
    25182539
    25192540        predIntraLumaAng( pcCU->getPattern(), uiMode, piPred, uiStride, uiWidth, uiHeight, bAboveAvail, bLeftAvail );
     
    25292550   
    25302551#if FAST_UDI_USE_MPM
     2552#if FAST_INTRA_SHVC == 0
    25312553      Int uiPreds[3] = {-1, -1, -1};
    25322554      Int iMode = -1;
    25332555      Int numCand = pcCU->getIntraDirLumaPredictor( uiPartOffset, uiPreds, &iMode );
     2556#endif
    25342557      if( iMode >= 0 )
    25352558      {
     
    30653088  Int iHeight = 0;
    30663089
    3067 #if 0 //REF_IDX_FRAMEWORK  // HM bug fix
    3068   for( UInt uiMergeCand = 0; uiMergeCand < pcCU->getSlice()->getMaxNumMergeCand(); ++uiMergeCand )
    3069   {
    3070     uhInterDirNeighbours[uiMergeCand] = 0;
    3071     cMvFieldNeighbours[0 + 2*uiMergeCand].setMvField(TComMv(), NOT_VALID);
    3072     cMvFieldNeighbours[1 + 2*uiMergeCand].setMvField(TComMv(), NOT_VALID);
    3073   }
    3074 #endif
    30753090  pcCU->getPartIndexAndSize( iPUIdx, uiAbsPartIdx, iWidth, iHeight );
    30763091  UInt uiDepth = pcCU->getDepth( uiAbsPartIdx );
     
    32493264    UInt          uiBitsTempL0[MAX_NUM_REF];
    32503265
    3251 #if L0034_COMBINED_LIST_CLEANUP
    32523266    TComMv        mvValidList1;
    32533267    Int           refIdxValidList1 = 0;
    32543268    UInt          bitsValidList1 = MAX_UINT;
    32553269    UInt          costValidList1 = MAX_UINT;
    3256 #endif
    3257 
    3258 #if (ENCODER_FAST_MODE)
    3259     Bool          testILR;
    3260 #endif
    32613270
    32623271    xGetBlkBits( ePartSize, pcCU->getSlice()->isInterP(), iPartIdx, uiLastMode, uiMbBits);
     
    32813290      RefPicList  eRefPicList = ( iRefList ? REF_PIC_LIST_1 : REF_PIC_LIST_0 );
    32823291     
    3283 #if (ENCODER_FAST_MODE)
    3284       if (pcCU->getSlice()->getNumRefIdx(eRefPicList) > 1)
    3285       {
    3286         testILR = false;
    3287       }
    3288       else
    3289       {
    3290         testILR = true;
    3291       }
    3292 #endif
    3293 
    32943292      for ( Int iRefIdxTemp = 0; iRefIdxTemp < pcCU->getSlice()->getNumRefIdx(eRefPicList); iRefIdxTemp++ )
    32953293      {
    32963294#if (ENCODER_FAST_MODE)
    32973295        TComPic* pcPic    = pcCU->getSlice()->getRefPic( eRefPicList, iRefIdxTemp );
    3298         if( !testILR && pcPic->isILR(pcCU->getLayerId()) && (ePartSize == SIZE_2Nx2N) )
     3296        if( pcPic->isILR(pcCU->getLayerId()) && (ePartSize == SIZE_2Nx2N) )
    32993297        {
    33003298          continue;
     
    33333331        uiBitsTemp += m_auiMVPIdxCost[aaiMvpIdx[iRefList][iRefIdxTemp]][AMVP_MAX_NUM_CANDS];
    33343332#if ZERO_MVD_EST
    3335 #if L0034_COMBINED_LIST_CLEANUP
    33363333        if ( iRefList == 0 || pcCU->getSlice()->getList1IdxToList0Idx( iRefIdxTemp ) < 0 )
    3337 #else
    3338         if ((iRefList != 1 || !pcCU->getSlice()->getNoBackPredFlag()) &&
    3339             (pcCU->getSlice()->getNumRefIdx(REF_PIC_LIST_C) <= 0 || pcCU->getSlice()->getRefIdxOfLC(eRefPicList, iRefIdxTemp)>=0))
    3340 #endif
    33413334        {
    33423335          uiZeroMvdBitsTemp = uiBitsTemp;
     
    33583351       
    33593352#if GPB_SIMPLE_UNI
    3360 #if L0034_COMBINED_LIST_CLEANUP
    33613353        if ( iRefList == 1 )    // list 1
    33623354        {
     
    33833375        }
    33843376#else
    3385         if ( pcCU->getSlice()->getNumRefIdx(REF_PIC_LIST_C) > 0)
    3386         {
    3387           if ( iRefList && ( pcCU->getSlice()->getNoBackPredFlag() || (pcCU->getSlice()->getNumRefIdx(REF_PIC_LIST_C) > 0 && !pcCU->getSlice()->getNoBackPredFlag() && pcCU->getSlice()->getRefIdxOfL0FromRefIdxOfL1(iRefIdxTemp)>=0 ) ) )
    3388             {
    3389               if ( pcCU->getSlice()->getNoBackPredFlag() )
    3390               {
    3391                 cMvTemp[1][iRefIdxTemp] = cMvTemp[0][iRefIdxTemp];
    3392                 uiCostTemp = uiCostTempL0[iRefIdxTemp];
    3393                 /*first subtract the bit-rate part of the cost of the other list*/
    3394                 uiCostTemp -= m_pcRdCost->getCost( uiBitsTempL0[iRefIdxTemp] );
    3395               }
    3396               else
    3397               {
    3398                 cMvTemp[1][iRefIdxTemp] = cMvTemp[0][pcCU->getSlice()->getRefIdxOfL0FromRefIdxOfL1(iRefIdxTemp)];
    3399                 uiCostTemp = uiCostTempL0[pcCU->getSlice()->getRefIdxOfL0FromRefIdxOfL1(iRefIdxTemp)];
    3400                 /*first subtract the bit-rate part of the cost of the other list*/
    3401                 uiCostTemp -= m_pcRdCost->getCost( uiBitsTempL0[pcCU->getSlice()->getRefIdxOfL0FromRefIdxOfL1(iRefIdxTemp)] );
    3402               }
    3403               /*correct the bit-rate part of the current ref*/
    3404               m_pcRdCost->setPredictor  ( cMvPred[iRefList][iRefIdxTemp] );
    3405               uiBitsTemp += m_pcRdCost->getBits( cMvTemp[1][iRefIdxTemp].getHor(), cMvTemp[1][iRefIdxTemp].getVer() );
    3406               /*calculate the correct cost*/
    3407               uiCostTemp += m_pcRdCost->getCost( uiBitsTemp );
    3408             }
    3409             else
    3410             {
    3411               xMotionEstimation ( pcCU, pcOrgYuv, iPartIdx, eRefPicList, &cMvPred[iRefList][iRefIdxTemp], iRefIdxTemp, cMvTemp[iRefList][iRefIdxTemp], uiBitsTemp, uiCostTemp );
    3412             }
    3413         }
    3414         else
    3415         {
    3416           if (iRefList && pcCU->getSlice()->getNoBackPredFlag())
    3417           {
    3418             uiCostTemp = MAX_UINT;
    3419             cMvTemp[1][iRefIdxTemp] = cMvTemp[0][iRefIdxTemp];
    3420           }
    3421           else
    3422           {
    3423             xMotionEstimation ( pcCU, pcOrgYuv, iPartIdx, eRefPicList, &cMvPred[iRefList][iRefIdxTemp], iRefIdxTemp, cMvTemp[iRefList][iRefIdxTemp], uiBitsTemp, uiCostTemp );
    3424           }       
    3425         }
    3426 #endif
    3427 #else
    34283377        xMotionEstimation ( pcCU, pcOrgYuv, iPartIdx, eRefPicList, &cMvPred[iRefList][iRefIdxTemp], iRefIdxTemp, cMvTemp[iRefList][iRefIdxTemp], uiBitsTemp, uiCostTemp );
    34293378#endif
     
    34313380        xCheckBestMVP(pcCU, eRefPicList, cMvTemp[iRefList][iRefIdxTemp], cMvPred[iRefList][iRefIdxTemp], aaiMvpIdx[iRefList][iRefIdxTemp], uiBitsTemp, uiCostTemp);
    34323381
    3433 #if L0034_COMBINED_LIST_CLEANUP
    34343382        if ( iRefList == 0 )
    34353383        {
     
    34563404          refIdxValidList1 = iRefIdxTemp;
    34573405        }
    3458 #else
    3459         if(pcCU->getSlice()->getNumRefIdx(REF_PIC_LIST_C) > 0 && !pcCU->getSlice()->getNoBackPredFlag())
    3460         {
    3461           if(iRefList==REF_PIC_LIST_0)
    3462           {
    3463             uiCostTempL0[iRefIdxTemp] = uiCostTemp;
    3464             uiBitsTempL0[iRefIdxTemp] = uiBitsTemp;
    3465             if(pcCU->getSlice()->getRefIdxOfLC(REF_PIC_LIST_0, iRefIdxTemp)<0)
    3466             {
    3467               uiCostTemp = MAX_UINT;
    3468             }
    3469           }
    3470           else
    3471           {
    3472             if(pcCU->getSlice()->getRefIdxOfLC(REF_PIC_LIST_1, iRefIdxTemp)<0)
    3473             {
    3474               uiCostTemp = MAX_UINT;
    3475             }           
    3476           }
    3477         }
    3478 
    3479 #if ENCODER_BUGFIX
    3480         if ( ( iRefList == 0 && uiCostTemp < uiCost[iRefList] ) ||
    3481             ( iRefList == 1 &&  pcCU->getSlice()->getNoBackPredFlag() && iRefIdxTemp == iRefIdx[0] ) ||
    3482             ( iRefList == 1 && !pcCU->getSlice()->getNoBackPredFlag() && uiCostTemp < uiCost[iRefList] ) )
    3483 #else
    3484         if ( ( iRefList == 0 && uiCostTemp < uiCost[iRefList] ) ||
    3485             ( iRefList == 1 &&  pcCU->getSlice()->getNoBackPredFlag() && iRefIdxTemp == iRefIdx[0] ) ||
    3486             ( iRefList == 1 && (pcCU->getSlice()->getNumRefIdx(REF_PIC_LIST_C) > 0) && (iRefIdxTemp==0 || iRefIdxTemp == iRefIdx[0]) && !pcCU->getSlice()->getNoBackPredFlag() && (iRefIdxTemp == pcCU->getSlice()->getRefIdxOfL0FromRefIdxOfL1(iRefIdxTemp)) ) ||
    3487             ( iRefList == 1 && !pcCU->getSlice()->getNoBackPredFlag() && uiCostTemp < uiCost[iRefList] ) )
    3488 #endif
    3489           {
    3490             uiCost[iRefList] = uiCostTemp;
    3491             uiBits[iRefList] = uiBitsTemp; // storing for bi-prediction
    3492            
    3493             // set motion
    3494             cMv[iRefList]     = cMvTemp[iRefList][iRefIdxTemp];
    3495             iRefIdx[iRefList] = iRefIdxTemp;
    3496             pcCU->getCUMvField(eRefPicList)->setAllMv( cMv[iRefList], ePartSize, uiPartAddr, 0, iPartIdx );
    3497             pcCU->getCUMvField(eRefPicList)->setAllRefIdx( iRefIdx[iRefList], ePartSize, uiPartAddr, 0, iPartIdx );
    3498 
    3499             if(!pcCU->getSlice()->getMvdL1ZeroFlag())
    3500             {
    3501               // storing list 1 prediction signal for iterative bi-directional prediction
    3502               if ( eRefPicList == REF_PIC_LIST_1 )
    3503               {
    3504                 TComYuv*  pcYuvPred = &m_acYuvPred[iRefList];
    3505                 motionCompensation ( pcCU, pcYuvPred, eRefPicList, iPartIdx );
    3506               }
    3507               if ( (pcCU->getSlice()->getNoBackPredFlag() || (pcCU->getSlice()->getNumRefIdx(REF_PIC_LIST_C) > 0 && pcCU->getSlice()->getRefIdxOfL0FromRefIdxOfL1(0)==0 )) && eRefPicList == REF_PIC_LIST_0 )
    3508               {
    3509                 TComYuv*  pcYuvPred = &m_acYuvPred[iRefList];
    3510                 motionCompensation ( pcCU, pcYuvPred, eRefPicList, iPartIdx );
    3511               }
    3512             }
    3513           }
    3514 #endif
    35153406      }
    35163407    }
     
    35803471       
    35813472        Int         iRefList    = iIter % 2;
    3582 #if L0034_COMBINED_LIST_CLEANUP
    35833473        if ( m_pcEncCfg->getUseFastEnc() )
    35843474        {
     
    36033493          motionCompensation ( pcCU, pcYuvPred, RefPicList(1-iRefList), iPartIdx );
    36043494        }
    3605 #else
    3606         if ( m_pcEncCfg->getUseFastEnc() && (pcCU->getSlice()->getNoBackPredFlag() || (pcCU->getSlice()->getNumRefIdx(REF_PIC_LIST_C) > 0 && pcCU->getSlice()->getRefIdxOfL0FromRefIdxOfL1(0)==0 )) )
    3607         {
    3608           iRefList = 1;
    3609         }
    3610 #endif
    36113495        RefPicList  eRefPicList = ( iRefList ? REF_PIC_LIST_1 : REF_PIC_LIST_0 );
    36123496
     
    37693653    UInt uiMEBits = 0;
    37703654    // Set Motion Field_
    3771 #if L0034_COMBINED_LIST_CLEANUP
    37723655    cMv[1] = mvValidList1;
    37733656    iRefIdx[1] = refIdxValidList1;
    37743657    uiBits[1] = bitsValidList1;
    37753658    uiCost[1] = costValidList1;
    3776 #else
    3777     if ( pcCU->getSlice()->getNoBackPredFlag() || (pcCU->getSlice()->getNumRefIdx(REF_PIC_LIST_C) > 0 && pcCU->getSlice()->getRefIdxOfL0FromRefIdxOfL1(0)==0 ) )
    3778     {
    3779       uiCost[1] = MAX_UINT;
    3780     }
    3781 #endif
    37823659#if AMP_MRG
    37833660    if (bTestNormalMC)
     
    62746151
    62756152#if ENCODER_FAST_MODE
    6276 Bool TEncSearch::predInterSearchILRUni( TComDataCU* pcCU, TComYuv* pcOrgYuv, TComYuv*& rpcPredYuv, TComYuv*& rpcResiYuv, TComYuv*& rpcRecoYuv )
     6153Bool TEncSearch::predInterSearchILRUni( TComDataCU* pcCU, TComYuv* pcOrgYuv, TComYuv*& rpcPredYuv, TComYuv*& rpcResiYuv, TComYuv*& rpcRecoYuv, UInt refLayerId )
    62776154{
    6278   rpcPredYuv->clear();
    6279   rpcRecoYuv->clear();
    6280 
    6281   Int           iNumPredDir = pcCU->getSlice()->isInterP() ? 1 : 2;
    6282 
    6283   TComMv        cMv[2];
    6284   TComMv        cMvPred[2][33];
    6285   TComMv        cMvTemp[2][33];
    6286   TComMv        TempMv;
    6287 
    6288   Int           iRefIdx[2]={0,0};
    6289 
    6290   Int           aaiMvpIdx[2][33];
    6291   Int           aaiMvpNum[2][33];
    6292 
    6293   UInt          uiMbBits[3] = {1, 1, 0};
    6294   UInt          uiLastMode = 0;
    6295 
    6296   UInt          uiCost[2]   = { MAX_UINT, MAX_UINT };     //uni, rdCost
    6297   UInt          uiCostTemp;
    6298   UInt          biPDistTemp = MAX_INT;
    6299   UInt          uiBitsTemp;
    6300 
    6301   PartSize      ePartSize = pcCU->getPartitionSize( 0 );  //2Nx2N
    6302   Int           iPartIdx  = 0;                            //one PU in CU
    6303   UInt          uiPartAddr;
    6304   Int           iRoiWidth, iRoiHeight;
    6305 
    6306   xGetBlkBits( ePartSize, pcCU->getSlice()->isInterP(), iPartIdx, uiLastMode, uiMbBits);
    6307   pcCU->getPartIndexAndSize( iPartIdx, uiPartAddr, iRoiWidth, iRoiHeight );
    6308 
    6309   for( Int iRefList = 0; iRefList < iNumPredDir; iRefList++)  //list
    6310   {
    6311     RefPicList  eRefPicList = ( iRefList ? REF_PIC_LIST_1 : REF_PIC_LIST_0 );
    6312 
    6313     Int  iRefIdxTemp = -1;
    6314     Bool foundILR    = false;
    6315     for( Int refIdx = 0; refIdx < pcCU->getSlice()->getNumRefIdx(eRefPicList); refIdx++ )
    6316     {
    6317       if( pcCU->getSlice()->getRefPic(eRefPicList, refIdx)->isILR(pcCU->getLayerId()) )
    6318       {
    6319         iRefIdxTemp = refIdx;
    6320         foundILR    = true;
    6321         break;
    6322       }
    6323     }
    6324 
    6325     if(!foundILR)  //no ILR in eRefPiclist
    6326     {
    6327       continue; 
    6328     }
    6329 
    6330     uiBitsTemp = uiMbBits[iRefList];
    6331     if ( pcCU->getSlice()->getNumRefIdx(eRefPicList) > 1 )
    6332     {
    6333       uiBitsTemp += iRefIdxTemp+1;
    6334       if ( iRefIdxTemp == pcCU->getSlice()->getNumRefIdx(eRefPicList)-1 ) uiBitsTemp--;
    6335     }
    6336 
    6337     xEstimateMvPredAMVP( pcCU, pcOrgYuv, iPartIdx, eRefPicList, iRefIdxTemp, cMvPred[iRefList][iRefIdxTemp], false, &biPDistTemp);
    6338     aaiMvpIdx[iRefList][iRefIdxTemp] = pcCU->getMVPIdx(eRefPicList, uiPartAddr);
    6339     aaiMvpNum[iRefList][iRefIdxTemp] = pcCU->getMVPNum(eRefPicList, uiPartAddr);
    6340 
    6341     uiBitsTemp += m_auiMVPIdxCost[aaiMvpIdx[iRefList][iRefIdxTemp]][AMVP_MAX_NUM_CANDS];
    6342 
    6343     xMotionEstimation ( pcCU, pcOrgYuv, iPartIdx, eRefPicList, &cMvPred[iRefList][iRefIdxTemp], iRefIdxTemp, cMvTemp[iRefList][iRefIdxTemp], uiBitsTemp, uiCostTemp );
    6344     xCheckBestMVP(pcCU, eRefPicList, cMvTemp[iRefList][iRefIdxTemp], cMvPred[iRefList][iRefIdxTemp], aaiMvpIdx[iRefList][iRefIdxTemp], uiBitsTemp, uiCostTemp);
    6345 
    6346     if( uiCostTemp < uiCost[iRefList] )
    6347     {
    6348       uiCost[iRefList] = uiCostTemp;
    6349 
    6350       cMv[iRefList]     = cMvTemp[iRefList][iRefIdxTemp];
    6351       iRefIdx[iRefList] = iRefIdxTemp;
    6352 
    6353       pcCU->getCUMvField(eRefPicList)->setAllMv( cMv[iRefList], ePartSize, uiPartAddr, 0, iPartIdx );
    6354       pcCU->getCUMvField(eRefPicList)->setAllRefIdx( iRefIdx[iRefList], ePartSize, uiPartAddr, 0, iPartIdx );
    6355     }
    6356   }
    6357 
    6358   if( uiCost[0] == MAX_UINT && uiCost[1] == MAX_UINT )  //no ILR in both list0 and list1
    6359   {
    6360     return false;
    6361   }
    6362 
    6363   //  Clear Motion Field
    6364   pcCU->getCUMvField(REF_PIC_LIST_0)->setAllMvField( TComMvField(), ePartSize, uiPartAddr, 0, iPartIdx );
    6365   pcCU->getCUMvField(REF_PIC_LIST_1)->setAllMvField( TComMvField(), ePartSize, uiPartAddr, 0, iPartIdx );
    6366   pcCU->getCUMvField(REF_PIC_LIST_0)->setAllMvd    ( TComMv(),      ePartSize, uiPartAddr, 0, iPartIdx );
    6367   pcCU->getCUMvField(REF_PIC_LIST_1)->setAllMvd    ( TComMv(),      ePartSize, uiPartAddr, 0, iPartIdx );
    6368 
    6369   pcCU->setMVPIdxSubParts( -1, REF_PIC_LIST_0, uiPartAddr, iPartIdx, pcCU->getDepth(uiPartAddr));
    6370   pcCU->setMVPNumSubParts( -1, REF_PIC_LIST_0, uiPartAddr, iPartIdx, pcCU->getDepth(uiPartAddr));
    6371   pcCU->setMVPIdxSubParts( -1, REF_PIC_LIST_1, uiPartAddr, iPartIdx, pcCU->getDepth(uiPartAddr));
    6372   pcCU->setMVPNumSubParts( -1, REF_PIC_LIST_1, uiPartAddr, iPartIdx, pcCU->getDepth(uiPartAddr));
    6373 
    6374   if( uiCost[0] <= uiCost[1] )  //list0 ILR
    6375   {
    6376     pcCU->getCUMvField(REF_PIC_LIST_0)->setAllMv    ( cMv[0], ePartSize, uiPartAddr, 0, iPartIdx );
    6377     pcCU->getCUMvField(REF_PIC_LIST_0)->setAllRefIdx( iRefIdx[0], ePartSize, uiPartAddr, 0, iPartIdx );
    6378 
    6379     TempMv = cMv[0] - cMvPred[0][iRefIdx[0]];
    6380     pcCU->getCUMvField(REF_PIC_LIST_0)->setAllMvd( TempMv, ePartSize, uiPartAddr, 0, iPartIdx );
    6381 
    6382     pcCU->setInterDirSubParts( 1, uiPartAddr, iPartIdx, pcCU->getDepth(0) );
    6383 
    6384     pcCU->setMVPIdxSubParts( aaiMvpIdx[0][iRefIdx[0]], REF_PIC_LIST_0, uiPartAddr, iPartIdx, pcCU->getDepth(uiPartAddr));
    6385     pcCU->setMVPNumSubParts( aaiMvpNum[0][iRefIdx[0]], REF_PIC_LIST_0, uiPartAddr, iPartIdx, pcCU->getDepth(uiPartAddr));
    6386   }
    6387   else if( uiCost[1] < uiCost[0] )  //list1 ILR
    6388   {
    6389     pcCU->getCUMvField(REF_PIC_LIST_1)->setAllMv    ( cMv[1], ePartSize, uiPartAddr, 0, iPartIdx );
    6390     pcCU->getCUMvField(REF_PIC_LIST_1)->setAllRefIdx( iRefIdx[1], ePartSize, uiPartAddr, 0, iPartIdx );
    6391 
    6392     TempMv = cMv[1] - cMvPred[1][iRefIdx[1]];
    6393     pcCU->getCUMvField(REF_PIC_LIST_1)->setAllMvd( TempMv, ePartSize, uiPartAddr, 0, iPartIdx );
    6394 
    6395     pcCU->setInterDirSubParts( 2, uiPartAddr, iPartIdx, pcCU->getDepth(0) );
    6396 
    6397     pcCU->setMVPIdxSubParts( aaiMvpIdx[1][iRefIdx[1]], REF_PIC_LIST_1, uiPartAddr, iPartIdx, pcCU->getDepth(uiPartAddr));
    6398     pcCU->setMVPNumSubParts( aaiMvpNum[1][iRefIdx[1]], REF_PIC_LIST_1, uiPartAddr, iPartIdx, pcCU->getDepth(uiPartAddr));
    6399   }
    6400   else
    6401   {
    6402     assert(0);
    6403   }
    6404 
    6405   pcCU->setMergeFlagSubParts( false, uiPartAddr, iPartIdx, pcCU->getDepth( uiPartAddr ) );
    6406 
    6407   motionCompensation ( pcCU, rpcPredYuv, REF_PIC_LIST_X, iPartIdx );
    6408 
    6409   setWpScalingDistParam( pcCU, -1, REF_PIC_LIST_X );
    6410 
    6411   return true;
     6155    rpcPredYuv->clear();
     6156    rpcRecoYuv->clear();
     6157
     6158    Int           iNumPredDir = pcCU->getSlice()->isInterP() ? 1 : 2;
     6159
     6160    TComMv        cMv[2];
     6161    TComMv        cMvPred[2][33];
     6162    TComMv        cMvTemp[2][33];
     6163    TComMv        TempMv;
     6164
     6165    Int           iRefIdx[2]={0,0};
     6166
     6167    Int           aaiMvpIdx[2][33];
     6168    Int           aaiMvpNum[2][33];
     6169
     6170    UInt          uiMbBits[3] = {1, 1, 0};
     6171    UInt          uiLastMode = 0;
     6172
     6173    UInt          uiCost[2]   = { MAX_UINT, MAX_UINT };     //uni, rdCost
     6174    UInt          uiCostTemp;
     6175    UInt          biPDistTemp = MAX_INT;
     6176    UInt          uiBitsTemp;
     6177
     6178    PartSize      ePartSize = pcCU->getPartitionSize( 0 );  //2Nx2N
     6179    Int           iPartIdx  = 0;                            //one PU in CU
     6180    UInt          uiPartAddr;
     6181    Int           iRoiWidth, iRoiHeight;
     6182    Bool          bILRSearched = false;
     6183
     6184    xGetBlkBits( ePartSize, pcCU->getSlice()->isInterP(), iPartIdx, uiLastMode, uiMbBits);
     6185    pcCU->getPartIndexAndSize( iPartIdx, uiPartAddr, iRoiWidth, iRoiHeight );
     6186
     6187    for( Int iRefList = 0; iRefList < iNumPredDir; iRefList++)  //list
     6188    {
     6189        if(bILRSearched)
     6190           continue;
     6191
     6192        RefPicList  eRefPicList = ( iRefList ? REF_PIC_LIST_1 : REF_PIC_LIST_0 );
     6193
     6194        Int  iRefIdxTemp = -1;
     6195        Bool foundILR    = false;
     6196
     6197        for( Int refIdx = 0; refIdx < pcCU->getSlice()->getNumRefIdx(eRefPicList); refIdx++ )
     6198        {
     6199            if( pcCU->getSlice()->getRefPic(eRefPicList, refIdx)->isILR(pcCU->getLayerId()) && pcCU->getSlice()->getRefPic(eRefPicList, refIdx)->getLayerId() == refLayerId )
     6200            {
     6201                iRefIdxTemp = refIdx;
     6202                foundILR    = true;
     6203                bILRSearched = true;
     6204                break;
     6205            }
     6206        }
     6207
     6208        if(!foundILR)  //no ILR in eRefPiclist
     6209        {
     6210            continue; 
     6211        }
     6212
     6213        uiBitsTemp = uiMbBits[iRefList];
     6214        if ( pcCU->getSlice()->getNumRefIdx(eRefPicList) > 1 )
     6215        {
     6216            uiBitsTemp += iRefIdxTemp+1;
     6217            if ( iRefIdxTemp == pcCU->getSlice()->getNumRefIdx(eRefPicList)-1 ) uiBitsTemp--;
     6218        }
     6219
     6220        xEstimateMvPredAMVP( pcCU, pcOrgYuv, iPartIdx, eRefPicList, iRefIdxTemp, cMvPred[iRefList][iRefIdxTemp], false, &biPDistTemp);
     6221        aaiMvpIdx[iRefList][iRefIdxTemp] = pcCU->getMVPIdx(eRefPicList, uiPartAddr);
     6222        aaiMvpNum[iRefList][iRefIdxTemp] = pcCU->getMVPNum(eRefPicList, uiPartAddr);
     6223
     6224        uiBitsTemp += m_auiMVPIdxCost[aaiMvpIdx[iRefList][iRefIdxTemp]][AMVP_MAX_NUM_CANDS];
     6225
     6226        xMotionEstimation ( pcCU, pcOrgYuv, iPartIdx, eRefPicList, &cMvPred[iRefList][iRefIdxTemp], iRefIdxTemp, cMvTemp[iRefList][iRefIdxTemp], uiBitsTemp, uiCostTemp );
     6227        xCheckBestMVP(pcCU, eRefPicList, cMvTemp[iRefList][iRefIdxTemp], cMvPred[iRefList][iRefIdxTemp], aaiMvpIdx[iRefList][iRefIdxTemp], uiBitsTemp, uiCostTemp);
     6228
     6229        if( uiCostTemp < uiCost[iRefList] )
     6230        {
     6231            uiCost[iRefList] = uiCostTemp;
     6232
     6233            cMv[iRefList]     = cMvTemp[iRefList][iRefIdxTemp];
     6234            iRefIdx[iRefList] = iRefIdxTemp;
     6235
     6236            pcCU->getCUMvField(eRefPicList)->setAllMv( cMv[iRefList], ePartSize, uiPartAddr, 0, iPartIdx );
     6237            pcCU->getCUMvField(eRefPicList)->setAllRefIdx( iRefIdx[iRefList], ePartSize, uiPartAddr, 0, iPartIdx );
     6238        }
     6239    }
     6240
     6241    if( uiCost[0] == MAX_UINT && uiCost[1] == MAX_UINT )  //no ILR in both list0 and list1
     6242    {
     6243        return false;
     6244    }
     6245
     6246    //  Clear Motion Field
     6247    pcCU->getCUMvField(REF_PIC_LIST_0)->setAllMvField( TComMvField(), ePartSize, uiPartAddr, 0, iPartIdx );
     6248    pcCU->getCUMvField(REF_PIC_LIST_1)->setAllMvField( TComMvField(), ePartSize, uiPartAddr, 0, iPartIdx );
     6249    pcCU->getCUMvField(REF_PIC_LIST_0)->setAllMvd    ( TComMv(),      ePartSize, uiPartAddr, 0, iPartIdx );
     6250    pcCU->getCUMvField(REF_PIC_LIST_1)->setAllMvd    ( TComMv(),      ePartSize, uiPartAddr, 0, iPartIdx );
     6251
     6252    pcCU->setMVPIdxSubParts( -1, REF_PIC_LIST_0, uiPartAddr, iPartIdx, pcCU->getDepth(uiPartAddr));
     6253    pcCU->setMVPNumSubParts( -1, REF_PIC_LIST_0, uiPartAddr, iPartIdx, pcCU->getDepth(uiPartAddr));
     6254    pcCU->setMVPIdxSubParts( -1, REF_PIC_LIST_1, uiPartAddr, iPartIdx, pcCU->getDepth(uiPartAddr));
     6255    pcCU->setMVPNumSubParts( -1, REF_PIC_LIST_1, uiPartAddr, iPartIdx, pcCU->getDepth(uiPartAddr));
     6256
     6257    if( uiCost[0] <= uiCost[1] )  //list0 ILR
     6258    {
     6259        pcCU->getCUMvField(REF_PIC_LIST_0)->setAllMv    ( cMv[0], ePartSize, uiPartAddr, 0, iPartIdx );
     6260        pcCU->getCUMvField(REF_PIC_LIST_0)->setAllRefIdx( iRefIdx[0], ePartSize, uiPartAddr, 0, iPartIdx );
     6261
     6262        TempMv = cMv[0] - cMvPred[0][iRefIdx[0]];
     6263        pcCU->getCUMvField(REF_PIC_LIST_0)->setAllMvd( TempMv, ePartSize, uiPartAddr, 0, iPartIdx );
     6264
     6265        pcCU->setInterDirSubParts( 1, uiPartAddr, iPartIdx, pcCU->getDepth(0) );
     6266
     6267        pcCU->setMVPIdxSubParts( aaiMvpIdx[0][iRefIdx[0]], REF_PIC_LIST_0, uiPartAddr, iPartIdx, pcCU->getDepth(uiPartAddr));
     6268        pcCU->setMVPNumSubParts( aaiMvpNum[0][iRefIdx[0]], REF_PIC_LIST_0, uiPartAddr, iPartIdx, pcCU->getDepth(uiPartAddr));
     6269    }
     6270    else if( uiCost[1] < uiCost[0] )  //list1 ILR
     6271    {
     6272        pcCU->getCUMvField(REF_PIC_LIST_1)->setAllMv    ( cMv[1], ePartSize, uiPartAddr, 0, iPartIdx );
     6273        pcCU->getCUMvField(REF_PIC_LIST_1)->setAllRefIdx( iRefIdx[1], ePartSize, uiPartAddr, 0, iPartIdx );
     6274
     6275        TempMv = cMv[1] - cMvPred[1][iRefIdx[1]];
     6276        pcCU->getCUMvField(REF_PIC_LIST_1)->setAllMvd( TempMv, ePartSize, uiPartAddr, 0, iPartIdx );
     6277
     6278        pcCU->setInterDirSubParts( 2, uiPartAddr, iPartIdx, pcCU->getDepth(0) );
     6279
     6280        pcCU->setMVPIdxSubParts( aaiMvpIdx[1][iRefIdx[1]], REF_PIC_LIST_1, uiPartAddr, iPartIdx, pcCU->getDepth(uiPartAddr));
     6281        pcCU->setMVPNumSubParts( aaiMvpNum[1][iRefIdx[1]], REF_PIC_LIST_1, uiPartAddr, iPartIdx, pcCU->getDepth(uiPartAddr));
     6282    }
     6283    else
     6284    {
     6285        assert(0);
     6286    }
     6287
     6288    pcCU->setMergeFlagSubParts( false, uiPartAddr, iPartIdx, pcCU->getDepth( uiPartAddr ) );
     6289
     6290    motionCompensation ( pcCU, rpcPredYuv, REF_PIC_LIST_X, iPartIdx );
     6291    setWpScalingDistParam( pcCU, -1, REF_PIC_LIST_X );
     6292
     6293    return true;
    64126294}
    6413 
    6414 
    64156295#endif
    64166296
  • trunk/source/Lib/TLibEncoder/TEncSearch.h

    r191 r310  
    216216 
    217217#if (ENCODER_FAST_MODE)
    218   Bool predInterSearchILRUni    ( TComDataCU* pcCU,
    219                                   TComYuv*    pcOrgYuv,
    220                                   TComYuv*&   rpcPredYuv,
    221                                   TComYuv*&   rpcResiYuv,
    222                                   TComYuv*&   rpcRecoYuv
    223                                 );
    224 
     218  Bool predInterSearchILRUni    ( TComDataCU* pcCU, TComYuv*    pcOrgYuv, TComYuv*&   rpcPredYuv, TComYuv*&   rpcResiYuv, TComYuv*&   rpcRecoYuv, UInt        refLayerId );
    225219#endif
    226220 
  • trunk/source/Lib/TLibEncoder/TEncSlice.cpp

    r191 r310  
    425425  rpcSlice->setNumRefIdx(REF_PIC_LIST_1,m_pcCfg->getGOPEntry(iGOPid).m_numRefPicsActive);
    426426 
    427 #if L0386_DB_METRIC
    428427  if ( m_pcCfg->getDeblockingFilterMetric() )
    429428  {
     
    433432    rpcSlice->setDeblockingFilterTcOffsetDiv2( 0 );
    434433  } else
    435 #endif
    436434  if (rpcSlice->getPPS()->getDeblockingFilterControlPresentFlag())
    437435  {
     
    491489  {
    492490#if JCTVC_M0458_INTERLAYER_RPS_SIG
    493   // currently only one reference layer is supported in software and no decision logic to select yet.
    494   // hence num of active inter layer references is set to one always
    495491    if( rpcSlice->getNumILRRefIdx() > 0 )
    496492    {
    497       rpcSlice->setActiveNumILRRefIdx(1);
     493      rpcSlice->setActiveNumILRRefIdx( m_ppcTEncTop[layerId]->getNumActiveRefLayers() );
     494      for( Int i = 0; i < rpcSlice->getActiveNumILRRefIdx(); i++ )
     495      {
     496        rpcSlice->setInterLayerPredLayerIdc( m_ppcTEncTop[layerId]->getPredLayerId(i), i );
     497      }
    498498      rpcSlice->setInterLayerPredEnabledFlag(1);
    499499    }
    500500#else
    501501    rpcSlice->setNumILRRefIdx( rpcSlice->getVPS()->getNumDirectRefLayers( layerId ) );
    502 #endif
     502#endif
     503#if M0457_COL_PICTURE_SIGNALING
     504    rpcSlice->setMFMEnabledFlag(m_ppcTEncTop[layerId]->getMFMEnabledFlag());
     505    rpcSlice->setAltColIndicationFlag(rpcSlice->getMFMEnabledFlag());
     506#endif
    503507  }
    504508
     
    513517  // store lambda
    514518  slice->setSliceQp( sliceQP );
    515 #if L0033_RC_BUGFIX
    516519  slice->setSliceQpBase ( sliceQP );
    517 #endif
    518520  m_pcRdCost ->setLambda( lambda );
    519521#if WEIGHTED_CHROMA_DISTORTION
     
    822824/** \param rpcPic   picture class
    823825 */
     826#if RATE_CONTROL_INTRA
     827Void TEncSlice::calCostSliceI(TComPic*& rpcPic)
     828{
     829  UInt    uiCUAddr;
     830  UInt    uiStartCUAddr;
     831  UInt    uiBoundingCUAddr;
     832  Int     iSumHad, shift = g_bitDepthY-8, offset = (shift>0)?(1<<(shift-1)):0;;
     833  Double  iSumHadSlice = 0;
     834
     835  rpcPic->getSlice(getSliceIdx())->setSliceSegmentBits(0);
     836  TComSlice* pcSlice            = rpcPic->getSlice(getSliceIdx());
     837  xDetermineStartAndBoundingCUAddr ( uiStartCUAddr, uiBoundingCUAddr, rpcPic, false );
     838
     839  UInt uiEncCUOrder;
     840  uiCUAddr = rpcPic->getPicSym()->getCUOrderMap( uiStartCUAddr /rpcPic->getNumPartInCU());
     841  for( uiEncCUOrder = uiStartCUAddr/rpcPic->getNumPartInCU();
     842       uiEncCUOrder < (uiBoundingCUAddr+(rpcPic->getNumPartInCU()-1))/rpcPic->getNumPartInCU();
     843       uiCUAddr = rpcPic->getPicSym()->getCUOrderMap(++uiEncCUOrder) )
     844  {
     845    // initialize CU encoder
     846    TComDataCU*& pcCU = rpcPic->getCU( uiCUAddr );
     847    pcCU->initCU( rpcPic, uiCUAddr );
     848
     849    Int height  = min( pcSlice->getSPS()->getMaxCUHeight(),pcSlice->getSPS()->getPicHeightInLumaSamples() - uiCUAddr / rpcPic->getFrameWidthInCU() * pcSlice->getSPS()->getMaxCUHeight() );
     850    Int width   = min( pcSlice->getSPS()->getMaxCUWidth(),pcSlice->getSPS()->getPicWidthInLumaSamples() - uiCUAddr % rpcPic->getFrameWidthInCU() * pcSlice->getSPS()->getMaxCUWidth() );
     851
     852    iSumHad = m_pcCuEncoder->updateLCUDataISlice(pcCU, uiCUAddr, width, height);
     853
     854    (m_pcRateCtrl->getRCPic()->getLCU(uiCUAddr)).m_costIntra=(iSumHad+offset)>>shift;
     855    iSumHadSlice += (m_pcRateCtrl->getRCPic()->getLCU(uiCUAddr)).m_costIntra;
     856
     857  }
     858  m_pcRateCtrl->getRCPic()->setTotalIntraCost(iSumHadSlice);
     859}
     860#endif
     861
    824862Void TEncSlice::compressSlice( TComPic*& rpcPic )
    825863{
     
    943981
    944982#if INTRA_BL
    945   m_pcCuEncoder->setBaseRecPic( rpcPic->getLayerId() > 0 ? rpcPic->getFullPelBaseRec() : NULL);
     983  m_pcCuEncoder->setBaseRecPic( rpcPic->getLayerId() > 0 ? rpcPic->getFullPelBaseRec(rpcPic->getLayerId()-1) : NULL);
    946984#endif
    947985
     
    9931031    TComDataCU*& pcCU = rpcPic->getCU( uiCUAddr );
    9941032    pcCU->initCU( rpcPic, uiCUAddr );
    995 #if SVC_EXTENSION
    996     pcCU->setLayerId(m_pcCfg->getLayerId());
    997 #endif
    9981033
    9991034#if !RATE_CONTROL_LAMBDA_DOMAIN
     
    10881123        Double bpp       = -1.0;
    10891124
     1125#if M0036_RC_IMPROVEMENT
     1126        if ( ( rpcPic->getSlice( 0 )->getSliceType() == I_SLICE && m_pcCfg->getForceIntraQP() ) || !m_pcCfg->getLCULevelRC() )
     1127#else
    10901128        if ( rpcPic->getSlice( 0 )->getSliceType() == I_SLICE || !m_pcCfg->getLCULevelRC() )
     1129#endif
    10911130        {
    10921131          estQP = pcSlice->getSliceQp();
     
    10941133        else
    10951134        {
     1135#if RATE_CONTROL_INTRA
     1136          bpp = m_pcRateCtrl->getRCPic()->getLCUTargetBpp(pcSlice->getSliceType());
     1137          if ( rpcPic->getSlice( 0 )->getSliceType() == I_SLICE)
     1138          {
     1139            estLambda = m_pcRateCtrl->getRCPic()->getLCUEstLambdaAndQP(bpp, pcSlice->getSliceQp(), &estQP);
     1140          }
     1141          else
     1142          {
     1143            estLambda = m_pcRateCtrl->getRCPic()->getLCUEstLambda( bpp );
     1144            estQP     = m_pcRateCtrl->getRCPic()->getLCUEstQP    ( estLambda, pcSlice->getSliceQp() );
     1145          }
     1146#else
    10961147          bpp       = m_pcRateCtrl->getRCPic()->getLCUTargetBpp();
    10971148          estLambda = m_pcRateCtrl->getRCPic()->getLCUEstLambda( bpp );
    10981149          estQP     = m_pcRateCtrl->getRCPic()->getLCUEstQP    ( estLambda, pcSlice->getSliceQp() );
     1150#endif
     1151
    10991152          estQP     = Clip3( -pcSlice->getSPS()->getQpBDOffsetY(), MAX_QP, estQP );
    11001153
    11011154          m_pcRdCost->setLambda(estLambda);
     1155#if M0036_RC_IMPROVEMENT
     1156#if RDOQ_CHROMA_LAMBDA
     1157          // set lambda for RDOQ
     1158          Double weight=m_pcRdCost->getChromaWeight();
     1159          m_pcTrQuant->setLambda( estLambda, estLambda / weight );
     1160#else
     1161          m_pcTrQuant->setLambda( estLambda );
     1162#endif
     1163#endif
    11021164        }
    11031165
    11041166        m_pcRateCtrl->setRCQP( estQP );
    1105 #if L0033_RC_BUGFIX
    11061167        pcCU->getSlice()->setSliceQpBase( estQP );
    1107 #endif
    11081168      }
    11091169#endif
     
    11121172      m_pcCuEncoder->compressCU( pcCU );
    11131173
     1174#if !TICKET_1090_FIX
    11141175#if RATE_CONTROL_LAMBDA_DOMAIN
    11151176      if ( m_pcCfg->getUseRateCtrl() )
    11161177      {
     1178#if !M0036_RC_IMPROVEMENT
    11171179        UInt SAD    = m_pcCuEncoder->getLCUPredictionSAD();
    11181180        Int height  = min( pcSlice->getSPS()->getMaxCUHeight(),pcSlice->getSPS()->getPicHeightInLumaSamples() - uiCUAddr / rpcPic->getFrameWidthInCU() * pcSlice->getSPS()->getMaxCUHeight() );
     
    11211183        MAD = MAD * MAD;
    11221184        ( m_pcRateCtrl->getRCPic()->getLCU(uiCUAddr) ).m_MAD = MAD;
     1185#endif
    11231186
    11241187        Int actualQP        = g_RCInvalidQPValue;
     
    11441207        }
    11451208        m_pcRdCost->setLambda(oldLambda);
    1146 
     1209#if RATE_CONTROL_INTRA
     1210        m_pcRateCtrl->getRCPic()->updateAfterLCU( m_pcRateCtrl->getRCPic()->getLCUCoded(), actualBits, actualQP, actualLambda,
     1211          pcCU->getSlice()->getSliceType() == I_SLICE ? 0 : m_pcCfg->getLCULevelRC() );
     1212#else
    11471213        m_pcRateCtrl->getRCPic()->updateAfterLCU( m_pcRateCtrl->getRCPic()->getLCUCoded(), actualBits, actualQP, actualLambda, m_pcCfg->getLCULevelRC() );
    1148       }
     1214#endif
     1215      }
     1216#endif
    11491217#endif
    11501218     
     
    11801248        }
    11811249      }
     1250
     1251#if TICKET_1090_FIX
     1252#if RATE_CONTROL_LAMBDA_DOMAIN
     1253      if ( m_pcCfg->getUseRateCtrl() )
     1254      {
     1255#if !M0036_RC_IMPROVEMENT
     1256        UInt SAD    = m_pcCuEncoder->getLCUPredictionSAD();
     1257        Int height  = min( pcSlice->getSPS()->getMaxCUHeight(),pcSlice->getSPS()->getPicHeightInLumaSamples() - uiCUAddr / rpcPic->getFrameWidthInCU() * pcSlice->getSPS()->getMaxCUHeight() );
     1258        Int width   = min( pcSlice->getSPS()->getMaxCUWidth(),pcSlice->getSPS()->getPicWidthInLumaSamples() - uiCUAddr % rpcPic->getFrameWidthInCU() * pcSlice->getSPS()->getMaxCUWidth() );
     1259        Double MAD = (Double)SAD / (Double)(height * width);
     1260        MAD = MAD * MAD;
     1261        ( m_pcRateCtrl->getRCPic()->getLCU(uiCUAddr) ).m_MAD = MAD;
     1262#endif
     1263
     1264        Int actualQP        = g_RCInvalidQPValue;
     1265        Double actualLambda = m_pcRdCost->getLambda();
     1266        Int actualBits      = pcCU->getTotalBits();
     1267        Int numberOfEffectivePixels    = 0;
     1268        for ( Int idx = 0; idx < rpcPic->getNumPartInCU(); idx++ )
     1269        {
     1270          if ( pcCU->getPredictionMode( idx ) != MODE_NONE && ( !pcCU->isSkipped( idx ) ) )
     1271          {
     1272            numberOfEffectivePixels = numberOfEffectivePixels + 16;
     1273            break;
     1274          }
     1275        }
     1276
     1277        if ( numberOfEffectivePixels == 0 )
     1278        {
     1279          actualQP = g_RCInvalidQPValue;
     1280        }
     1281        else
     1282        {
     1283          actualQP = pcCU->getQP( 0 );
     1284        }
     1285        m_pcRdCost->setLambda(oldLambda);
     1286
     1287#if RATE_CONTROL_INTRA
     1288        m_pcRateCtrl->getRCPic()->updateAfterLCU( m_pcRateCtrl->getRCPic()->getLCUCoded(), actualBits, actualQP, actualLambda,
     1289          pcCU->getSlice()->getSliceType() == I_SLICE ? 0 : m_pcCfg->getLCULevelRC() );
     1290#else
     1291        m_pcRateCtrl->getRCPic()->updateAfterLCU( m_pcRateCtrl->getRCPic()->getLCUCoded(), actualBits, actualQP, actualLambda, m_pcCfg->getLCULevelRC() );
     1292#endif
     1293      }
     1294#endif
     1295#endif
    11821296    }
    11831297    // other case: encodeCU is not called
  • trunk/source/Lib/TLibEncoder/TEncSlice.h

    r191 r310  
    132132  Void    precompressSlice    ( TComPic*& rpcPic                                );      ///< precompress slice for multi-loop opt.
    133133  Void    compressSlice       ( TComPic*& rpcPic                                );      ///< analysis stage of slice
     134#if RATE_CONTROL_INTRA
     135  Void    calCostSliceI       ( TComPic*& rpcPic );
     136#endif
    134137  Void    encodeSlice         ( TComPic*& rpcPic, TComOutputBitstream* pcSubstreams  );
    135138 
  • trunk/source/Lib/TLibEncoder/TEncTop.cpp

    r191 r310  
    8989  m_bMFMEnabledFlag = false;
    9090#endif
     91#if SCALED_REF_LAYER_OFFSETS
     92  m_numScaledRefLayerOffsets = 0;
     93#endif
    9194}
    9295
     
    310313  /* set the VPS profile information */
    311314  *m_cVPS.getPTL() = *m_cSPS.getPTL();
    312 #if L0043_TIMING_INFO
    313315  m_cVPS.getTimingInfo()->setTimingInfoPresentFlag       ( false );
    314 #endif
    315316  // initialize PPS
    316317  m_cPPS.setSPS(&m_cSPS);
     
    386387  // compress GOP
    387388#if RATE_CONTROL_LAMBDA_DOMAIN
     389#if !RC_SHVC_HARMONIZATION
    388390  if ( m_RCEnableRateControl )
    389391  {
    390392    m_cRateCtrl.initRCGOP( m_iNumPicRcvd );
    391393  }
     394#endif
    392395#endif
    393396
     
    396399
    397400#if RATE_CONTROL_LAMBDA_DOMAIN
     401#if !RC_SHVC_HARMONIZATION
    398402  if ( m_RCEnableRateControl )
    399403  {
    400404    m_cRateCtrl.destroyRCGOP();
    401405  }
     406#endif
    402407#endif
    403408 
     
    503508      if(m_layerId > 0)
    504509      {
    505 #if VPS_EXTN_DIRECT_REF_LAYERS_CONTINUE
    506         TEncTop *pcEncTopBase = (TEncTop *)getRefLayerEnc( m_layerId );
     510        for(UInt i = 0; i < m_cVPS.getNumDirectRefLayers( m_layerId ); i++ )
     511        {
     512          const Window scalEL = getSPS()->getScaledRefLayerWindow(i);
     513          Bool zeroOffsets = ( scalEL.getWindowLeftOffset() == 0 && scalEL.getWindowRightOffset() == 0 && scalEL.getWindowTopOffset() == 0 && scalEL.getWindowBottomOffset() == 0 );
     514
     515#if VPS_EXTN_DIRECT_REF_LAYERS
     516          TEncTop *pcEncTopBase = (TEncTop *)getRefLayerEnc( i );
    507517#else
    508         TEncTop *pcEncTopBase = (TEncTop *)getLayerEnc( m_layerId-1 );
    509 #endif
    510         if(m_iSourceWidth != pcEncTopBase->getSourceWidth() || m_iSourceHeight != pcEncTopBase->getSourceHeight() )
    511         {
    512           pcEPic->setSpatialEnhLayerFlag( true );
     518          TEncTop *pcEncTopBase = (TEncTop *)getLayerEnc( m_layerId-1 );
     519#endif
     520          if(m_iSourceWidth != pcEncTopBase->getSourceWidth() || m_iSourceHeight != pcEncTopBase->getSourceHeight() || !zeroOffsets )
     521          {
     522            pcEPic->setSpatialEnhLayerFlag( i, true );
     523
     524            //only for scalable extension
     525            assert( m_cVPS.getScalabilityMask(1) == true );
     526          }
    513527        }
    514528      }
     
    531545      if(m_layerId > 0)
    532546      {
    533 #if VPS_EXTN_DIRECT_REF_LAYERS_CONTINUE
    534         TEncTop *pcEncTopBase = (TEncTop *)getRefLayerEnc( m_layerId );
     547        for(UInt i = 0; i < m_cVPS.getNumDirectRefLayers( m_layerId ); i++ )
     548        {
     549          const Window scalEL = getSPS()->getScaledRefLayerWindow(i);
     550          Bool zeroOffsets = ( scalEL.getWindowLeftOffset() == 0 && scalEL.getWindowRightOffset() == 0 && scalEL.getWindowTopOffset() == 0 && scalEL.getWindowBottomOffset() == 0 );
     551
     552#if VPS_EXTN_DIRECT_REF_LAYERS
     553          TEncTop *pcEncTopBase = (TEncTop *)getRefLayerEnc( i );
    535554#else
    536         TEncTop *pcEncTopBase = (TEncTop *)getLayerEnc( m_layerId-1 );
    537 #endif
    538         if(m_iSourceWidth != pcEncTopBase->getSourceWidth() || m_iSourceHeight != pcEncTopBase->getSourceHeight() )
    539         {
    540           rpcPic->setSpatialEnhLayerFlag( true );
     555          TEncTop *pcEncTopBase = (TEncTop *)getLayerEnc( m_layerId-1 );
     556#endif
     557          if(m_iSourceWidth != pcEncTopBase->getSourceWidth() || m_iSourceHeight != pcEncTopBase->getSourceHeight() || !zeroOffsets )
     558          {
     559            rpcPic->setSpatialEnhLayerFlag( i, true );
     560
     561            //only for scalable extension
     562            assert( m_cVPS.getScalabilityMask(1) == true );
     563          }
    541564        }
    542565      }
     
    574597#endif
    575598#if REF_IDX_MFM
     599#if !M0457_COL_PICTURE_SIGNALING
    576600  m_cSPS.setMFMEnabledFlag(m_bMFMEnabledFlag);
    577601#endif
     602#endif
    578603#if SCALED_REF_LAYER_OFFSETS
    579   m_cSPS.getScaledRefLayerWindow() = m_scaledRefLayerWindow;
     604  m_cSPS.setNumScaledRefLayerOffsets(m_numScaledRefLayerOffsets);
     605  for(Int i = 0; i < m_cSPS.getNumScaledRefLayerOffsets(); i++)
     606  {
     607    m_cSPS.getScaledRefLayerWindow(i) = m_scaledRefLayerWindow[i];
     608  }
    580609#endif
    581610  ProfileTierLevel& profileTierLevel = *m_cSPS.getPTL()->getGeneralPTL();
     
    584613  profileTierLevel.setProfileIdc(m_profile);
    585614  profileTierLevel.setProfileCompatibilityFlag(m_profile, 1);
    586 #if L0046_CONSTRAINT_FLAGS
    587615  profileTierLevel.setProgressiveSourceFlag(m_progressiveSourceFlag);
    588616  profileTierLevel.setInterlacedSourceFlag(m_interlacedSourceFlag);
    589617  profileTierLevel.setNonPackedConstraintFlag(m_nonPackedConstraintFlag);
    590618  profileTierLevel.setFrameOnlyConstraintFlag(m_frameOnlyConstraintFlag);
    591 #endif
    592619 
    593620  if (m_profile == Profile::MAIN10 && g_bitDepthY == 8 && g_bitDepthC == 8)
     
    639666
    640667  m_cSPS.setMaxTrSize   ( 1 << m_uiQuadtreeTULog2MaxSize );
    641 #if !L0034_COMBINED_LIST_CLEANUP
    642   m_cSPS.setUseLComb    ( m_bUseLComb           );
    643 #endif
    644668 
    645669  Int i;
     
    706730    pcVUI->setFieldSeqFlag(false);
    707731    pcVUI->setHrdParametersPresentFlag(false);
    708 #if L0043_TIMING_INFO
    709732    pcVUI->getTimingInfo()->setPocProportionalToTimingFlag(getPocProportionalToTimingFlag());
    710733    pcVUI->getTimingInfo()->setNumTicksPocDiffOneMinus1   (getNumTicksPocDiffOneMinus1()   );
    711 #else
    712     pcVUI->setPocProportionalToTimingFlag(getPocProportionalToTimingFlag());
    713     pcVUI->setNumTicksPocDiffOneMinus1   (getNumTicksPocDiffOneMinus1()   );
    714 #endif
    715734    pcVUI->setBitstreamRestrictionFlag(getBitstreamRestrictionFlag());
    716735    pcVUI->setTilesFixedStructureFlag(getTilesFixedStructureFlag());
     
    785804  m_cPPS.setOutputFlagPresentFlag( false );
    786805  m_cPPS.setSignHideFlag(getSignHideFlag());
    787 #if L0386_DB_METRIC
    788806  if ( getDeblockingFilterMetric() )
    789807  {
     
    798816  m_cPPS.setDeblockingFilterControlPresentFlag (m_DeblockingFilterControlPresent );
    799817  }
    800 #else
    801   m_cPPS.setDeblockingFilterControlPresentFlag (m_DeblockingFilterControlPresent );
    802 #endif
    803818  m_cPPS.setLog2ParallelMergeLevelMinus2   (m_log2ParallelMergeLevelMinus2 );
    804819  m_cPPS.setCabacInitPresentFlag(CABAC_INIT_PRESENT_FLAG);
     
    824839    }
    825840  }
    826 #if L0323_LIMIT_DEFAULT_LIST_SIZE
    827841  assert(bestPos <= 15);
    828 #endif
    829842  m_cPPS.setNumRefIdxL0DefaultActive(bestPos);
    830843  m_cPPS.setNumRefIdxL1DefaultActive(bestPos);
     
    10731086}
    10741087
    1075 #if L0208_SOP_DESCRIPTION_SEI
    10761088Int TEncTop::getReferencePictureSetIdxForSOP(TComSlice* slice, Int POCCurr, Int GOPid )
    10771089{
     
    11031115  return rpsIdx;
    11041116}
    1105 #endif
    11061117
    11071118Void  TEncTop::xInitPPSforTiles()
     
    11881199
    11891200#if SVC_EXTENSION
    1190 #if VPS_EXTN_DIRECT_REF_LAYERS_CONTINUE
    1191 TEncTop* TEncTop::getRefLayerEnc( UInt layerId )
     1201#if VPS_EXTN_DIRECT_REF_LAYERS
     1202TEncTop* TEncTop::getRefLayerEnc( UInt refLayerIdc )
    11921203{
    11931204  if( m_ppcTEncTop[m_layerId]->getNumDirectRefLayers() <= 0 )
     
    12001211  }
    12011212
    1202   // currently only one reference layer is supported
    1203   assert( m_ppcTEncTop[m_layerId]->getNumDirectRefLayers() == 1 );
    1204 
    1205   return (TEncTop *)getLayerEnc( getVPS()->getRefLayerId( m_layerId, 0 ) );
     1213  return (TEncTop *)getLayerEnc( m_cVPS.getRefLayerId( m_layerId, refLayerIdc ) );
    12061214}
    12071215#endif
     
    12251233    if (m_cIlpPic[0] == NULL)
    12261234    {
    1227       for (Int j=0; j<1/*MAX_NUM_REF*/; j++)
     1235      for (Int j=0; j < MAX_LAYERS /*MAX_NUM_REF*/; j++) // consider to set to NumDirectRefLayers[LayerIdInVps[nuh_layer_id]]
    12281236      {
    12291237        m_cIlpPic[j] = new  TComPic;
     
    12441252Void TEncTop::setILRPic(TComPic *pcPic)
    12451253{
    1246   if(m_cIlpPic[0])
    1247   {
    1248     m_cIlpPic[0]->copyUpsampledPictureYuv(pcPic->getFullPelBaseRec(), m_cIlpPic[0]->getPicYuvRec());
    1249     m_cIlpPic[0]->getSlice(0)->setPOC(pcPic->getPOC());
    1250     m_cIlpPic[0]->setLayerId(pcPic->getSlice(0)->getBaseColPic()->getLayerId()); //set reference layerId
    1251     m_cIlpPic[0]->getPicYuvRec()->setBorderExtension(false);
    1252     m_cIlpPic[0]->getPicYuvRec()->extendPicBorder();
     1254  for( Int i = 0; i < pcPic->getSlice(0)->getActiveNumILRRefIdx(); i++ )
     1255  {
     1256    Int refLayerIdc = pcPic->getSlice(0)->getInterLayerPredLayerIdc(i);
     1257
     1258    if(m_cIlpPic[refLayerIdc])
     1259    {
     1260      m_cIlpPic[refLayerIdc]->copyUpsampledPictureYuv(pcPic->getFullPelBaseRec(refLayerIdc), m_cIlpPic[refLayerIdc]->getPicYuvRec());
     1261      m_cIlpPic[refLayerIdc]->getSlice(0)->setPOC(pcPic->getPOC());
     1262      m_cIlpPic[refLayerIdc]->setLayerId(pcPic->getSlice(0)->getBaseColPic(refLayerIdc)->getLayerId()); //set reference layerId
     1263      m_cIlpPic[refLayerIdc]->getPicYuvRec()->setBorderExtension(false);
     1264      m_cIlpPic[refLayerIdc]->getPicYuvRec()->extendPicBorder();
     1265    }
    12531266  }
    12541267}
  • trunk/source/Lib/TLibEncoder/TEncTop.h

    r191 r310  
    139139  Bool                    m_bMFMEnabledFlag;
    140140#endif
     141#if M0457_IL_SAMPLE_PRED_ONLY_FLAG
     142  Int                     m_ilSampleOnlyPred;
     143#endif
    141144#if SCALED_REF_LAYER_OFFSETS
    142   Window                  m_scaledRefLayerWindow;
     145  UInt                    m_numScaledRefLayerOffsets;
     146  Window                  m_scaledRefLayerWindow[MAX_LAYERS];
    143147#endif
    144148protected:
     
    195199  TComPPS*                getPPS                () { return  &m_cPPS;                 }
    196200  Void selectReferencePictureSet(TComSlice* slice, Int POCCurr, Int GOPid );
    197 #if L0208_SOP_DESCRIPTION_SEI
    198201  Int getReferencePictureSetIdxForSOP(TComSlice* slice, Int POCCurr, Int GOPid );
    199 #endif
    200202  TComScalingList*        getScalingList        () { return  &m_scalingList;         }
    201203#if SVC_EXTENSION
     
    207209#endif
    208210#if SCALED_REF_LAYER_OFFSETS
    209   Window&  getScaledRefLayerWindow()            { return m_scaledRefLayerWindow; }
     211  Void                    setNumScaledRefLayerOffsets(Int x) { m_numScaledRefLayerOffsets = x; }
     212  UInt                    getNumScaledRefLayerOffsets() { return m_numScaledRefLayerOffsets; }
     213  Window&  getScaledRefLayerWindow(Int x)            { return m_scaledRefLayerWindow[x]; }
    210214#endif
    211215
     
    224228  Bool      getMFMEnabledFlag()                   {return m_bMFMEnabledFlag;}   
    225229#endif
     230#if M0457_IL_SAMPLE_PRED_ONLY_FLAG
     231  Void      setIlSampleOnlyPred( Int i )          { m_ilSampleOnlyPred = i;    }
     232  Int       getIlSampleOnlyPred()                 { return m_ilSampleOnlyPred; }
     233#endif
    226234#if AVC_SYNTAX
    227235  Void      setBLSyntaxFile( fstream* pFile ) { m_pBLSyntaxFile = pFile; }
     
    230238  Void      encode( TComPicYuv* pcPicYuvOrg, TComList<TComPicYuv*>& rcListPicYuvRecOut, std::list<AccessUnit>& accessUnitsOut, Int iPicIdInGOP  );
    231239  Void      encodePrep( TComPicYuv* pcPicYuvOrg );
    232 #if VPS_EXTN_DIRECT_REF_LAYERS_CONTINUE
    233   TEncTop*  getRefLayerEnc(UInt layerId);
     240#if VPS_EXTN_DIRECT_REF_LAYERS
     241  TEncTop*  getRefLayerEnc(UInt refLayerIdc);
    234242#endif
    235243#else
Note: See TracChangeset for help on using the changeset viewer.