Changeset 125 in SHVCSoftware for trunk/source/Lib/TLibEncoder/TEncCavlc.cpp


Ignore:
Timestamp:
16 Apr 2013, 06:39:31 (12 years ago)
Author:
seregin
Message:

copy from HM-10.0-dev-SHM

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/source/Lib/TLibEncoder/TEncCavlc.cpp

    r33 r125  
    44 * granted under this license. 
    55 *
    6  * Copyright (c) 2010-2012, ITU/ISO/IEC
     6 * Copyright (c) 2010-2013, ITU/ISO/IEC
    77 * All rights reserved.
    88 *
     
    5555}
    5656
    57 #if !REMOVE_APS
    58 Void  xTraceAPSHeader (TComAPS *pAPS)
    59 {
    60   fprintf( g_hTrace, "=========== Adaptation Parameter Set ===========\n");
    61 }
    62 #endif
    63 
    6457Void  xTraceSliceHeader (TComSlice *pSlice)
    6558{
     
    7972  m_pcBitIf           = NULL;
    8073  m_uiCoeffCost       = 0;
    81 #if !REMOVE_FGS
    82   m_iSliceGranularity = 0;
    83 #endif
    8474}
    8575
     
    9888
    9989
    100 #if !REMOVE_APS
    101 Void  TEncCavlc::codeAPSInitInfo(TComAPS* pcAPS)
    102 {
    103 
    104 #if ENC_DEC_TRACE 
    105   xTraceAPSHeader(pcAPS);
    106 #endif
    107   //APS ID
    108   WRITE_UVLC( pcAPS->getAPSID(), "aps_id" );
    109 }
    110 #endif
    111 
    11290Void TEncCavlc::codeDFFlag(UInt uiCode, const Char *pSymbolName)
    11391{
     
    11997}
    12098
    121 #if J0234_INTER_RPS_SIMPL
    122 Void TEncCavlc::codeShortTermRefPicSet( TComSPS* pcSPS, TComReferencePictureSet* rps, Bool calledFromSliceHeader)
    123 #else
    124 Void TEncCavlc::codeShortTermRefPicSet( TComSPS* pcSPS, TComReferencePictureSet* rps )
    125 #endif
     99Void TEncCavlc::codeShortTermRefPicSet( TComSPS* pcSPS, TComReferencePictureSet* rps, Bool calledFromSliceHeader, Int idx)
    126100{
    127101#if PRINT_RPS_INFO
    128   int lastBits = getNumberOfWrittenBits();
    129 #endif
     102  Int lastBits = getNumberOfWrittenBits();
     103#endif
     104  if (idx > 0)
     105  {
    130106  WRITE_FLAG( rps->getInterRPSPrediction(), "inter_ref_pic_set_prediction_flag" ); // inter_RPS_prediction_flag
    131   if (rps->getInterRPSPrediction())
     107  }
     108  if (rps->getInterRPSPrediction())
    132109  {
    133110    Int deltaRPS = rps->getDeltaRPS();
    134 #if J0234_INTER_RPS_SIMPL
    135111    if(calledFromSliceHeader)
    136112    {
    137113      WRITE_UVLC( rps->getDeltaRIdxMinus1(), "delta_idx_minus1" ); // delta index of the Reference Picture Set used for prediction minus 1
    138114    }
    139 #else
    140     WRITE_UVLC( rps->getDeltaRIdxMinus1(), "delta_idx_minus1" ); // delta index of the Reference Picture Set used for prediction minus 1
    141 #endif
    142115
    143116    WRITE_CODE( (deltaRPS >=0 ? 0: 1), 1, "delta_rps_sign" ); //delta_rps_sign
     
    187160#endif
    188161 
    189   WRITE_UVLC( pcPPS->getPPSId(),                             "pic_parameter_set_id" );
    190   WRITE_UVLC( pcPPS->getSPSId(),                             "seq_parameter_set_id" );
    191 
     162  WRITE_UVLC( pcPPS->getPPSId(),                             "pps_pic_parameter_set_id" );
     163  WRITE_UVLC( pcPPS->getSPSId(),                             "pps_seq_parameter_set_id" );
     164  WRITE_FLAG( pcPPS->getDependentSliceSegmentsEnabledFlag()    ? 1 : 0, "dependent_slice_segments_enabled_flag" );
     165#if L0255_MOVE_PPS_FLAGS
     166  WRITE_FLAG( pcPPS->getOutputFlagPresentFlag() ? 1 : 0,     "output_flag_present_flag" );
     167  WRITE_CODE( pcPPS->getNumExtraSliceHeaderBits(), 3,        "num_extra_slice_header_bits");
     168#endif
    192169  WRITE_FLAG( pcPPS->getSignHideFlag(), "sign_data_hiding_flag" );
    193170  WRITE_FLAG( pcPPS->getCabacInitPresentFlag() ? 1 : 0,   "cabac_init_present_flag" );
     
    195172  WRITE_UVLC( pcPPS->getNumRefIdxL1DefaultActive()-1,     "num_ref_idx_l1_default_active_minus1");
    196173
    197   WRITE_SVLC( pcPPS->getPicInitQPMinus26(),                  "pic_init_qp_minus26");
     174  WRITE_SVLC( pcPPS->getPicInitQPMinus26(),                  "init_qp_minus26");
    198175  WRITE_FLAG( pcPPS->getConstrainedIntraPred() ? 1 : 0,      "constrained_intra_pred_flag" );
    199 #if PPS_TS_FLAG
    200176  WRITE_FLAG( pcPPS->getUseTransformSkip() ? 1 : 0,  "transform_skip_enabled_flag" );
    201 #endif
    202 #if !REMOVE_FGS
    203   WRITE_CODE( pcPPS->getSliceGranularity(), 2,               "slice_granularity");
    204 #endif
    205 #if CU_DQP_ENABLE_FLAG
    206177  WRITE_FLAG( pcPPS->getUseDQP() ? 1 : 0, "cu_qp_delta_enabled_flag" );
    207178  if ( pcPPS->getUseDQP() )
    208179  {
    209 #if REMOVE_FGS
    210180    WRITE_UVLC( pcPPS->getMaxCuDQPDepth(), "diff_cu_qp_delta_depth" );
    211 #else
    212     WRITE_UVLC( pcPPS->getMaxCuDQPDepth() - pcPPS->getSliceGranularity(), "diff_cu_qp_delta_depth" );
    213 #endif
    214   }
    215 #else
    216 #if REMOVE_FGS
    217   WRITE_UVLC( pcPPS->getMaxCuDQPDepth() + pcPPS->getUseDQP(),                   "diff_cu_qp_delta_depth" );
    218 #else
    219   WRITE_UVLC( pcPPS->getMaxCuDQPDepth() - pcPPS->getSliceGranularity() + pcPPS->getUseDQP(),                   "diff_cu_qp_delta_depth" );
    220 #endif
    221 #endif
    222   WRITE_SVLC( pcPPS->getChromaCbQpOffset(),                   "cb_qp_offset" );
    223   WRITE_SVLC( pcPPS->getChromaCrQpOffset(),                   "cr_qp_offset" );
    224 #if CHROMA_QP_EXTENSION
    225   WRITE_FLAG( pcPPS->getSliceChromaQpFlag() ? 1 : 0,          "slicelevel_chroma_qp_flag" );
    226 #endif
     181  }
     182  WRITE_SVLC( pcPPS->getChromaCbQpOffset(),                   "pps_cb_qp_offset" );
     183  WRITE_SVLC( pcPPS->getChromaCrQpOffset(),                   "pps_cr_qp_offset" );
     184  WRITE_FLAG( pcPPS->getSliceChromaQpFlag() ? 1 : 0,          "pps_slice_chroma_qp_offsets_present_flag" );
    227185
    228186  WRITE_FLAG( pcPPS->getUseWP() ? 1 : 0,  "weighted_pred_flag" );   // Use of Weighting Prediction (P_SLICE)
    229187  WRITE_FLAG( pcPPS->getWPBiPred() ? 1 : 0, "weighted_bipred_flag" );  // Use of Weighting Bi-Prediction (B_SLICE)
     188#if !L0255_MOVE_PPS_FLAGS
    230189  WRITE_FLAG( pcPPS->getOutputFlagPresentFlag() ? 1 : 0,  "output_flag_present_flag" );
    231 #if !TILES_WPP_ENTROPYSLICES_FLAGS
    232 #if DEPENDENT_SLICES
    233   WRITE_FLAG( pcPPS->getDependentSliceEnabledFlag() ? 1 : 0, "dependent_slices_enabled_flag" );
    234 #endif
    235190#endif
    236191  WRITE_FLAG( pcPPS->getTransquantBypassEnableFlag() ? 1 : 0, "transquant_bypass_enable_flag" );
    237 
    238 #if TILES_WPP_ENTROPYSLICES_FLAGS
    239 #if DEPENDENT_SLICES
    240   WRITE_FLAG( pcPPS->getDependentSliceEnabledFlag()    ? 1 : 0, "dependent_slice_enabled_flag" );
    241 #endif
    242192  WRITE_FLAG( pcPPS->getTilesEnabledFlag()             ? 1 : 0, "tiles_enabled_flag" );
    243193  WRITE_FLAG( pcPPS->getEntropyCodingSyncEnabledFlag() ? 1 : 0, "entropy_coding_sync_enabled_flag" );
    244   WRITE_FLAG( pcPPS->getEntropySliceEnabledFlag()      ? 1 : 0, "entropy_slice_enabled_flag" );
    245194  if( pcPPS->getTilesEnabledFlag() )
    246 #else
    247   Int tilesOrEntropyCodingSyncIdc = 0;
    248   if ( pcPPS->getNumColumnsMinus1() > 0 || pcPPS->getNumRowsMinus1() > 0)
    249   {
    250     tilesOrEntropyCodingSyncIdc = 1;
    251   }
    252   else if ( pcPPS->getNumSubstreams() > 1 )
    253   {
    254     tilesOrEntropyCodingSyncIdc = 2;
    255   }
    256 #if DEPENDENT_SLICES
    257   else if( pcPPS->getDependentSliceEnabledFlag() )
    258   {
    259     if(pcPPS->getTilesOrEntropyCodingSyncIdc() != 2)
    260     {
    261       tilesOrEntropyCodingSyncIdc = 3;
    262     }
    263     else
    264     {
    265       tilesOrEntropyCodingSyncIdc = 2;
    266     }
    267   }
    268 #endif
    269   pcPPS->setTilesOrEntropyCodingSyncIdc( tilesOrEntropyCodingSyncIdc );
    270   WRITE_CODE(tilesOrEntropyCodingSyncIdc, 2, "tiles_or_entropy_coding_sync_idc");
    271 
    272   if(pcPPS->getTilesOrEntropyCodingSyncIdc()==1)
    273 #endif
    274195  {
    275196    WRITE_UVLC( pcPPS->getNumColumnsMinus1(),                                    "num_tile_columns_minus1" );
     
    292213    }
    293214  }
    294 #if !TILES_WPP_ENTROPYSLICES_FLAGS
    295 #if DEPENDENT_SLICES
    296   else if( pcPPS->getTilesOrEntropyCodingSyncIdc()==3 )
    297   {
    298     WRITE_FLAG( pcPPS->getCabacIndependentFlag()? 1 : 0,            "cabac_independent_flag" );
    299   }
    300 #endif
    301 #endif
    302 #if MOVE_LOOP_FILTER_SLICES_FLAG
    303215  WRITE_FLAG( pcPPS->getLoopFilterAcrossSlicesEnabledFlag()?1 : 0,        "loop_filter_across_slices_enabled_flag");
    304 #endif
    305216  WRITE_FLAG( pcPPS->getDeblockingFilterControlPresentFlag()?1 : 0,       "deblocking_filter_control_present_flag");
    306217  if(pcPPS->getDeblockingFilterControlPresentFlag())
    307218  {
    308219    WRITE_FLAG( pcPPS->getDeblockingFilterOverrideEnabledFlag() ? 1 : 0,  "deblocking_filter_override_enabled_flag" );
    309     WRITE_FLAG( pcPPS->getPicDisableDeblockingFilterFlag(),               "pic_disable_deblocking_filter_flag" );
     220    WRITE_FLAG( pcPPS->getPicDisableDeblockingFilterFlag() ? 1 : 0,       "pps_disable_deblocking_filter_flag" );
    310221    if(!pcPPS->getPicDisableDeblockingFilterFlag())
    311222    {
     
    322233    codeScalingList( m_pcSlice->getScalingList() );
    323234  }
     235  WRITE_FLAG( pcPPS->getListsModificationPresentFlag(), "lists_modification_present_flag");
    324236  WRITE_UVLC( pcPPS->getLog2ParallelMergeLevelMinus2(), "log2_parallel_merge_level_minus2");
    325 #if SLICE_HEADER_EXTENSION
    326   WRITE_FLAG( pcPPS->getSliceHeaderExtensionPresentFlag(), "slice_header_extension_present_flag");
    327 #endif
     237#if !L0255_MOVE_PPS_FLAGS
     238  WRITE_CODE( pcPPS->getNumExtraSliceHeaderBits(), 3, "num_extra_slice_header_bits");
     239#endif
     240  WRITE_FLAG( pcPPS->getSliceHeaderExtensionPresentFlag() ? 1 : 0, "slice_segment_header_extension_present_flag");
    328241  WRITE_FLAG( 0, "pps_extension_flag" );
    329242}
    330243
    331 #if SUPPORT_FOR_VUI
    332244Void TEncCavlc::codeVUI( TComVUI *pcVUI, TComSPS* pcSPS )
    333245{
     
    374286  WRITE_FLAG(pcVUI->getFieldSeqFlag(),                          "field_seq_flag");
    375287  assert(pcVUI->getFieldSeqFlag() == 0);                        // not currently supported
     288  WRITE_FLAG(pcVUI->getFrameFieldInfoPresentFlag(),             "frame_field_info_present_flag");
     289
     290  Window defaultDisplayWindow = pcVUI->getDefaultDisplayWindow();
     291  WRITE_FLAG(defaultDisplayWindow.getWindowEnabledFlag(),       "default_display_window_flag");
     292  if( defaultDisplayWindow.getWindowEnabledFlag() )
     293  {
     294    WRITE_UVLC(defaultDisplayWindow.getWindowLeftOffset(),      "def_disp_win_left_offset");
     295    WRITE_UVLC(defaultDisplayWindow.getWindowRightOffset(),     "def_disp_win_right_offset");
     296    WRITE_UVLC(defaultDisplayWindow.getWindowTopOffset(),       "def_disp_win_top_offset");
     297    WRITE_UVLC(defaultDisplayWindow.getWindowBottomOffset(),    "def_disp_win_bottom_offset");
     298  }
     299#if L0043_TIMING_INFO
     300  TimingInfo *timingInfo = pcVUI->getTimingInfo();
     301  WRITE_FLAG(timingInfo->getTimingInfoPresentFlag(),          "vui_timing_info_present_flag");
     302  if(timingInfo->getTimingInfoPresentFlag())
     303  {
     304    WRITE_CODE(timingInfo->getNumUnitsInTick(), 32,           "vui_num_units_in_tick");
     305    WRITE_CODE(timingInfo->getTimeScale(),      32,           "vui_time_scale");
     306    WRITE_FLAG(timingInfo->getPocProportionalToTimingFlag(),  "vui_poc_proportional_to_timing_flag");
     307    if(timingInfo->getPocProportionalToTimingFlag())
     308    {
     309      WRITE_UVLC(timingInfo->getNumTicksPocDiffOneMinus1(),   "vui_num_ticks_poc_diff_one_minus1");
     310    }
     311#endif
    376312  WRITE_FLAG(pcVUI->getHrdParametersPresentFlag(),              "hrd_parameters_present_flag");
    377 #if !BUFFERING_PERIOD_AND_TIMING_SEI
    378   assert(pcVUI->getHrdParametersPresentFlag() == 0);            // not currently supported
    379 #else
    380313  if( pcVUI->getHrdParametersPresentFlag() )
    381314  {
    382     WRITE_FLAG(pcVUI->getTimingInfoPresentFlag(),               "timing_info_present_flag");
    383     if( pcVUI->getTimingInfoPresentFlag() )
    384     {
    385       WRITE_CODE(pcVUI->getNumUnitsInTick(), 32,                "num_units_in_tick");
    386       WRITE_CODE(pcVUI->getTimeScale(),      32,                "time_scale");
    387     }
    388     WRITE_FLAG(pcVUI->getNalHrdParametersPresentFlag(),         "nal_hrd_parameters_present_flag");
    389     WRITE_FLAG(pcVUI->getVclHrdParametersPresentFlag(),         "vcl_hrd_parameters_present_flag");
    390     if( pcVUI->getNalHrdParametersPresentFlag() || pcVUI->getVclHrdParametersPresentFlag() )
    391     {
    392       WRITE_FLAG(pcVUI->getSubPicCpbParamsPresentFlag(),        "sub_pic_cpb_params_present_flag");
    393       if( pcVUI->getSubPicCpbParamsPresentFlag() )
    394       {
    395         WRITE_CODE(pcVUI->getTickDivisorMinus2(), 8,            "tick_divisor_minus2");
    396         WRITE_CODE(pcVUI->getDuCpbRemovalDelayLengthMinus1(), 5,  "du_cpb_removal_delay_length_minus1");
    397       }
    398       WRITE_CODE(pcVUI->getBitRateScale(), 4,                   "bit_rate_scale");
    399       WRITE_CODE(pcVUI->getCpbSizeScale(), 4,                   "cpb_size_scale");
    400       WRITE_CODE(pcVUI->getInitialCpbRemovalDelayLengthMinus1(), 5, "initial_cpb_removal_delay_length_minus1");
    401       WRITE_CODE(pcVUI->getCpbRemovalDelayLengthMinus1(),        5, "cpb_removal_delay_length_minus1");
    402       WRITE_CODE(pcVUI->getDpbOutputDelayLengthMinus1(),         5, "dpb_output_delay_length_minus1");
    403     }
    404     Int i, j, nalOrVcl;
    405     for( i = 0; i <= pcSPS->getMaxTLayers(); i ++ )
    406     {
    407       WRITE_FLAG(pcVUI->getFixedPicRateFlag(i),                 "fixed_pic_rate_flag");
    408       if( pcVUI->getFixedPicRateFlag( i ) )
    409       {
    410         WRITE_UVLC(pcVUI->getPicDurationInTcMinus1(i),          "pic_duration_in_tc_minus1");
    411       }
    412       WRITE_FLAG(pcVUI->getLowDelayHrdFlag(i),                  "low_delay_hrd_flag");
    413       WRITE_UVLC(pcVUI->getCpbCntMinus1(i),                     "cpb_cnt_minus1");
    414      
    415       for( nalOrVcl = 0; nalOrVcl < 2; nalOrVcl ++ )
    416       {
    417         if( ( ( nalOrVcl == 0 ) && ( pcVUI->getNalHrdParametersPresentFlag() ) ) ||
    418             ( ( nalOrVcl == 1 ) && ( pcVUI->getVclHrdParametersPresentFlag() ) ) )
    419         {
    420           for( j = 0; j < ( pcVUI->getCpbCntMinus1( i ) + 1 ); j ++ )
    421           {
    422             WRITE_UVLC(pcVUI->getBitRateValueMinus1(i, j, nalOrVcl), "bit_size_value_minus1");
    423             WRITE_UVLC(pcVUI->getCpbSizeValueMinus1(i, j, nalOrVcl), "cpb_size_value_minus1");
    424             WRITE_FLAG(pcVUI->getCbrFlag(i, j, nalOrVcl),            "cbr_flag");
    425           }
    426         }
    427       }
    428     }
    429   }
    430 #endif
     315    codeHrdParameters(pcVUI->getHrdParameters(), 1, pcSPS->getMaxTLayers() - 1 );
     316  }
     317#if L0043_TIMING_INFO
     318  }
     319#endif
     320#if !L0043_TIMING_INFO
     321  WRITE_FLAG( pcVUI->getPocProportionalToTimingFlag(), "poc_proportional_to_timing_flag" );
     322  if( pcVUI->getPocProportionalToTimingFlag() && pcVUI->getHrdParameters()->getTimingInfoPresentFlag() )
     323  {
     324    WRITE_UVLC( pcVUI->getNumTicksPocDiffOneMinus1(), "num_ticks_poc_diff_one_minus1" );
     325  }
     326#endif
     327
    431328  WRITE_FLAG(pcVUI->getBitstreamRestrictionFlag(),              "bitstream_restriction_flag");
    432329  if (pcVUI->getBitstreamRestrictionFlag())
     
    434331    WRITE_FLAG(pcVUI->getTilesFixedStructureFlag(),             "tiles_fixed_structure_flag");
    435332    WRITE_FLAG(pcVUI->getMotionVectorsOverPicBoundariesFlag(),  "motion_vectors_over_pic_boundaries_flag");
     333    WRITE_FLAG(pcVUI->getRestrictedRefPicListsFlag(),           "restricted_ref_pic_lists_flag");
     334#if L0043_MSS_IDC
     335    WRITE_UVLC(pcVUI->getMinSpatialSegmentationIdc(),           "min_spatial_segmentation_idc");
     336#else
     337    WRITE_CODE(pcVUI->getMinSpatialSegmentationIdc(),        8, "min_spatial_segmentation_idc");
     338#endif
    436339    WRITE_UVLC(pcVUI->getMaxBytesPerPicDenom(),                 "max_bytes_per_pic_denom");
    437340    WRITE_UVLC(pcVUI->getMaxBitsPerMinCuDenom(),                "max_bits_per_mincu_denom");
     
    439342    WRITE_UVLC(pcVUI->getLog2MaxMvLengthVertical(),             "log2_max_mv_length_vertical");
    440343  }
    441 
    442 }
    443 #endif
     344}
     345
     346Void TEncCavlc::codeHrdParameters( TComHRD *hrd, Bool commonInfPresentFlag, UInt maxNumSubLayersMinus1 )
     347{
     348  if( commonInfPresentFlag )
     349  {
     350#if !L0043_TIMING_INFO
     351    WRITE_FLAG( hrd->getTimingInfoPresentFlag() ? 1 : 0,        "timing_info_present_flag" );
     352    if( hrd->getTimingInfoPresentFlag() )
     353    {
     354      WRITE_CODE( hrd->getNumUnitsInTick(), 32,                  "num_units_in_tick" );
     355      WRITE_CODE( hrd->getTimeScale(),      32,                  "time_scale" );
     356    }
     357#endif
     358    WRITE_FLAG( hrd->getNalHrdParametersPresentFlag() ? 1 : 0 ,  "nal_hrd_parameters_present_flag" );
     359    WRITE_FLAG( hrd->getVclHrdParametersPresentFlag() ? 1 : 0 ,  "vcl_hrd_parameters_present_flag" );
     360    if( hrd->getNalHrdParametersPresentFlag() || hrd->getVclHrdParametersPresentFlag() )
     361    {
     362      WRITE_FLAG( hrd->getSubPicCpbParamsPresentFlag() ? 1 : 0,  "sub_pic_cpb_params_present_flag" );
     363      if( hrd->getSubPicCpbParamsPresentFlag() )
     364      {
     365        WRITE_CODE( hrd->getTickDivisorMinus2(), 8,              "tick_divisor_minus2" );
     366        WRITE_CODE( hrd->getDuCpbRemovalDelayLengthMinus1(), 5,  "du_cpb_removal_delay_length_minus1" );
     367        WRITE_FLAG( hrd->getSubPicCpbParamsInPicTimingSEIFlag() ? 1 : 0, "sub_pic_cpb_params_in_pic_timing_sei_flag" );
     368#if L0044_DU_DPB_OUTPUT_DELAY_HRD
     369        WRITE_CODE( hrd->getDpbOutputDelayDuLengthMinus1(), 5,   "dpb_output_delay_du_length_minus1"  );
     370#endif
     371      }
     372      WRITE_CODE( hrd->getBitRateScale(), 4,                     "bit_rate_scale" );
     373      WRITE_CODE( hrd->getCpbSizeScale(), 4,                     "cpb_size_scale" );
     374      if( hrd->getSubPicCpbParamsPresentFlag() )
     375      {
     376        WRITE_CODE( hrd->getDuCpbSizeScale(), 4,                "du_cpb_size_scale" );
     377      }
     378      WRITE_CODE( hrd->getInitialCpbRemovalDelayLengthMinus1(), 5, "initial_cpb_removal_delay_length_minus1" );
     379      WRITE_CODE( hrd->getCpbRemovalDelayLengthMinus1(),        5, "au_cpb_removal_delay_length_minus1" );
     380      WRITE_CODE( hrd->getDpbOutputDelayLengthMinus1(),         5, "dpb_output_delay_length_minus1" );
     381    }
     382  }
     383  Int i, j, nalOrVcl;
     384  for( i = 0; i <= maxNumSubLayersMinus1; i ++ )
     385  {
     386    WRITE_FLAG( hrd->getFixedPicRateFlag( i ) ? 1 : 0,          "fixed_pic_rate_general_flag");
     387    if( !hrd->getFixedPicRateFlag( i ) )
     388    {
     389      WRITE_FLAG( hrd->getFixedPicRateWithinCvsFlag( i ) ? 1 : 0, "fixed_pic_rate_within_cvs_flag");
     390    }
     391    else
     392    {
     393      hrd->setFixedPicRateWithinCvsFlag( i, true );
     394    }
     395    if( hrd->getFixedPicRateWithinCvsFlag( i ) )
     396    {
     397      WRITE_UVLC( hrd->getPicDurationInTcMinus1( i ),           "elemental_duration_in_tc_minus1");
     398    }
     399#if L0372
     400    else
     401    {
     402      WRITE_FLAG( hrd->getLowDelayHrdFlag( i ) ? 1 : 0,           "low_delay_hrd_flag");
     403    }
     404    if (!hrd->getLowDelayHrdFlag( i ))
     405    {
     406      WRITE_UVLC( hrd->getCpbCntMinus1( i ),                      "cpb_cnt_minus1");
     407    }
     408#else
     409    WRITE_FLAG( hrd->getLowDelayHrdFlag( i ) ? 1 : 0,           "low_delay_hrd_flag");
     410    WRITE_UVLC( hrd->getCpbCntMinus1( i ),                      "cpb_cnt_minus1");
     411#endif
     412   
     413    for( nalOrVcl = 0; nalOrVcl < 2; nalOrVcl ++ )
     414    {
     415      if( ( ( nalOrVcl == 0 ) && ( hrd->getNalHrdParametersPresentFlag() ) ) ||
     416          ( ( nalOrVcl == 1 ) && ( hrd->getVclHrdParametersPresentFlag() ) ) )
     417      {
     418        for( j = 0; j <= ( hrd->getCpbCntMinus1( i ) ); j ++ )
     419        {
     420          WRITE_UVLC( hrd->getBitRateValueMinus1( i, j, nalOrVcl ), "bit_rate_value_minus1");
     421          WRITE_UVLC( hrd->getCpbSizeValueMinus1( i, j, nalOrVcl ), "cpb_size_value_minus1");
     422          if( hrd->getSubPicCpbParamsPresentFlag() )
     423          {
     424#if L0363_DU_BIT_RATE
     425            WRITE_UVLC( hrd->getDuBitRateValueMinus1( i, j, nalOrVcl ), "bit_rate_du_value_minus1");
     426#endif
     427            WRITE_UVLC( hrd->getDuCpbSizeValueMinus1( i, j, nalOrVcl ), "cpb_size_du_value_minus1"); 
     428          }
     429          WRITE_FLAG( hrd->getCbrFlag( i, j, nalOrVcl ) ? 1 : 0, "cbr_flag");
     430        }
     431      }
     432    }
     433  }
     434}
    444435
    445436Void TEncCavlc::codeSPS( TComSPS* pcSPS )
     
    448439  xTraceSPSHeader (pcSPS);
    449440#endif
    450 #if SPS_SYNTAX_CHANGES
    451   WRITE_CODE( pcSPS->getVPSId (),          4,       "video_parameter_set_id" );
     441  WRITE_CODE( pcSPS->getVPSId (),          4,       "sps_video_parameter_set_id" );
    452442  WRITE_CODE( pcSPS->getMaxTLayers() - 1,  3,       "sps_max_sub_layers_minus1" );
    453   WRITE_FLAG( 0,                                    "sps_reserved_zero_bit");
     443  WRITE_FLAG( pcSPS->getTemporalIdNestingFlag() ? 1 : 0,                             "sps_temporal_id_nesting_flag" );
    454444  codePTL(pcSPS->getPTL(), 1, pcSPS->getMaxTLayers() - 1);
    455   WRITE_UVLC( pcSPS->getSPSId (),                   "seq_parameter_set_id" );
     445  WRITE_UVLC( pcSPS->getSPSId (),                   "sps_seq_parameter_set_id" );
    456446  WRITE_UVLC( pcSPS->getChromaFormatIdc (),         "chroma_format_idc" );
    457447  assert(pcSPS->getChromaFormatIdc () == 1);
     
    462452  }
    463453
    464 #else
    465   WRITE_CODE( pcSPS->getProfileSpace (),   3,       "profile_space" );
    466   WRITE_CODE( pcSPS->getProfileIdc (),     5,       "profile_idc" );
    467   WRITE_CODE( pcSPS->getRsvdIndFlags(),   16,       "reserved_indicator_flags" );
    468   WRITE_CODE( pcSPS->getLevelIdc (),       8,       "level_idc" );
    469   WRITE_CODE( pcSPS->getProfileCompat (), 32,       "profile_compatibility" );
    470   WRITE_UVLC( pcSPS->getSPSId (),                   "seq_parameter_set_id" );
    471   WRITE_UVLC( pcSPS->getVPSId (),                   "video_parameter_set_id" );
    472   WRITE_UVLC( pcSPS->getChromaFormatIdc (),         "chroma_format_idc" );
    473   WRITE_CODE( pcSPS->getMaxTLayers() - 1,  3,       "max_temporal_layers_minus1" );
    474 #endif
    475454  WRITE_UVLC( pcSPS->getPicWidthInLumaSamples (),   "pic_width_in_luma_samples" );
    476455  WRITE_UVLC( pcSPS->getPicHeightInLumaSamples(),   "pic_height_in_luma_samples" );
    477   WRITE_FLAG( pcSPS->getPicCroppingFlag(),          "pic_cropping_flag" );
    478   if (pcSPS->getPicCroppingFlag())
    479   {
    480     WRITE_UVLC( pcSPS->getPicCropLeftOffset()   / TComSPS::getCropUnitX(pcSPS->getChromaFormatIdc() ), "pic_crop_left_offset" );
    481     WRITE_UVLC( pcSPS->getPicCropRightOffset()  / TComSPS::getCropUnitX(pcSPS->getChromaFormatIdc() ), "pic_crop_right_offset" );
    482     WRITE_UVLC( pcSPS->getPicCropTopOffset()    / TComSPS::getCropUnitY(pcSPS->getChromaFormatIdc() ), "pic_crop_top_offset" );
    483     WRITE_UVLC( pcSPS->getPicCropBottomOffset() / TComSPS::getCropUnitY(pcSPS->getChromaFormatIdc() ), "pic_crop_bottom_offset" );
    484   }
    485 
    486 #if FULL_NBIT
    487   WRITE_UVLC( pcSPS->getBitDepth() - 8,             "bit_depth_luma_minus8" );
    488 #else
    489   WRITE_UVLC( pcSPS->getBitIncrement(),             "bit_depth_luma_minus8" );
    490 #endif
    491 #if FULL_NBIT
    492   WRITE_UVLC( pcSPS->getBitDepth() - 8,             "bit_depth_chroma_minus8" );
    493 #else
    494   WRITE_UVLC( pcSPS->getBitIncrement(),             "bit_depth_chroma_minus8" );
    495 #endif
    496 
    497   WRITE_FLAG( pcSPS->getUsePCM() ? 1 : 0,                   "pcm_enabled_flag");
    498 
    499   if( pcSPS->getUsePCM() )
    500   {
    501   WRITE_CODE( pcSPS->getPCMBitDepthLuma() - 1, 4,   "pcm_bit_depth_luma_minus1" );
    502   WRITE_CODE( pcSPS->getPCMBitDepthChroma() - 1, 4, "pcm_bit_depth_chroma_minus1" );
    503   }
     456  Window conf = pcSPS->getConformanceWindow();
     457
     458  WRITE_FLAG( conf.getWindowEnabledFlag(),          "conformance_window_flag" );
     459  if (conf.getWindowEnabledFlag())
     460  {
     461    WRITE_UVLC( conf.getWindowLeftOffset()   / TComSPS::getWinUnitX(pcSPS->getChromaFormatIdc() ), "conf_win_left_offset" );
     462    WRITE_UVLC( conf.getWindowRightOffset()  / TComSPS::getWinUnitX(pcSPS->getChromaFormatIdc() ), "conf_win_right_offset" );
     463    WRITE_UVLC( conf.getWindowTopOffset()    / TComSPS::getWinUnitY(pcSPS->getChromaFormatIdc() ), "conf_win_top_offset" );
     464    WRITE_UVLC( conf.getWindowBottomOffset() / TComSPS::getWinUnitY(pcSPS->getChromaFormatIdc() ), "conf_win_bottom_offset" );
     465  }
     466
     467  WRITE_UVLC( pcSPS->getBitDepthY() - 8,             "bit_depth_luma_minus8" );
     468  WRITE_UVLC( pcSPS->getBitDepthC() - 8,             "bit_depth_chroma_minus8" );
    504469
    505470  WRITE_UVLC( pcSPS->getBitsForPOC()-4,                 "log2_max_pic_order_cnt_lsb_minus4" );
     471
     472  const Bool subLayerOrderingInfoPresentFlag = 1;
     473  WRITE_FLAG(subLayerOrderingInfoPresentFlag,       "sps_sub_layer_ordering_info_present_flag");
    506474  for(UInt i=0; i <= pcSPS->getMaxTLayers()-1; i++)
    507475  {
    508     WRITE_UVLC( pcSPS->getMaxDecPicBuffering(i),           "max_dec_pic_buffering[i]" );
    509     WRITE_UVLC( pcSPS->getNumReorderPics(i),               "num_reorder_pics[i]" );
    510     WRITE_UVLC( pcSPS->getMaxLatencyIncrease(i),           "max_latency_increase[i]" );
     476    WRITE_UVLC( pcSPS->getMaxDecPicBuffering(i),           "sps_max_dec_pic_buffering[i]" );
     477    WRITE_UVLC( pcSPS->getNumReorderPics(i),               "sps_num_reorder_pics[i]" );
     478    WRITE_UVLC( pcSPS->getMaxLatencyIncrease(i),           "sps_max_latency_increase[i]" );
     479    if (!subLayerOrderingInfoPresentFlag)
     480    {
     481      break;
     482    }
    511483  }
    512484  assert( pcSPS->getMaxCUWidth() == pcSPS->getMaxCUHeight() );
     
    520492  }
    521493
    522   WRITE_FLAG( pcSPS->getRestrictedRefPicListsFlag(),                                 "restricted_ref_pic_lists_flag" );
    523   if( pcSPS->getRestrictedRefPicListsFlag() )
    524   {
    525     WRITE_FLAG( pcSPS->getListsModificationPresentFlag(),                            "lists_modification_present_flag" );
    526   }
    527494  WRITE_UVLC( log2MinCUSize - 3,                                                     "log2_min_coding_block_size_minus3" );
    528495  WRITE_UVLC( pcSPS->getMaxCUDepth()-g_uiAddCUDepth,                                 "log2_diff_max_min_coding_block_size" );
    529496  WRITE_UVLC( pcSPS->getQuadtreeTULog2MinSize() - 2,                                 "log2_min_transform_block_size_minus2" );
    530497  WRITE_UVLC( pcSPS->getQuadtreeTULog2MaxSize() - pcSPS->getQuadtreeTULog2MinSize(), "log2_diff_max_min_transform_block_size" );
    531   if( pcSPS->getUsePCM() )
    532   {
    533     WRITE_UVLC( pcSPS->getPCMLog2MinSize() - 3,                                      "log2_min_pcm_coding_block_size_minus3" );
    534     WRITE_UVLC( pcSPS->getPCMLog2MaxSize() - pcSPS->getPCMLog2MinSize(),             "log2_diff_max_min_pcm_coding_block_size" );
    535   }
    536498  WRITE_UVLC( pcSPS->getQuadtreeTUMaxDepthInter() - 1,                               "max_transform_hierarchy_depth_inter" );
    537499  WRITE_UVLC( pcSPS->getQuadtreeTUMaxDepthIntra() - 1,                               "max_transform_hierarchy_depth_intra" );
     
    548510    }
    549511  }
    550 #if !REMOVE_LMCHROMA
    551   WRITE_FLAG( pcSPS->getUseLMChroma () ? 1 : 0,                                      "chroma_pred_from_luma_enabled_flag" );
    552 #endif
    553 #if !PPS_TS_FLAG
    554   WRITE_FLAG( pcSPS->getUseTransformSkip () ? 1 : 0,                                 "transform_skip_enabled_flag" );
    555 #endif
    556 #if !MOVE_LOOP_FILTER_SLICES_FLAG
    557   WRITE_FLAG( pcSPS->getLFCrossSliceBoundaryFlag()?1 : 0,                            "seq_loop_filter_across_slices_enabled_flag");
    558 #endif
    559   WRITE_FLAG( pcSPS->getUseAMP(),                                                    "asymmetric_motion_partitions_enabled_flag" );
    560 #if !REMOVE_NSQT
    561   WRITE_FLAG( pcSPS->getUseNSQT(),                                                   "non_square_quadtree_enabled_flag" );
    562 #endif
     512  WRITE_FLAG( pcSPS->getUseAMP() ? 1 : 0,                                            "amp_enabled_flag" );
    563513  WRITE_FLAG( pcSPS->getUseSAO() ? 1 : 0,                                            "sample_adaptive_offset_enabled_flag");
    564 #if !REMOVE_ALF
    565   WRITE_FLAG( pcSPS->getUseALF () ? 1 : 0,                                           "adaptive_loop_filter_enabled_flag");
    566 #endif
     514
     515  WRITE_FLAG( pcSPS->getUsePCM() ? 1 : 0,                                            "pcm_enabled_flag");
    567516  if( pcSPS->getUsePCM() )
    568517  {
    569   WRITE_FLAG( pcSPS->getPCMFilterDisableFlag()?1 : 0,                                "pcm_loop_filter_disable_flag");
     518    WRITE_CODE( pcSPS->getPCMBitDepthLuma() - 1, 4,                                  "pcm_sample_bit_depth_luma_minus1" );
     519    WRITE_CODE( pcSPS->getPCMBitDepthChroma() - 1, 4,                                "pcm_sample_bit_depth_chroma_minus1" );
     520    WRITE_UVLC( pcSPS->getPCMLog2MinSize() - 3,                                      "log2_min_pcm_luma_coding_block_size_minus3" );
     521    WRITE_UVLC( pcSPS->getPCMLog2MaxSize() - pcSPS->getPCMLog2MinSize(),             "log2_diff_max_min_pcm_luma_coding_block_size" );
     522    WRITE_FLAG( pcSPS->getPCMFilterDisableFlag()?1 : 0,                              "pcm_loop_filter_disable_flag");
    570523  }
    571524
    572525  assert( pcSPS->getMaxTLayers() > 0 );         
    573 
    574   WRITE_FLAG( pcSPS->getTemporalIdNestingFlag() ? 1 : 0,                             "temporal_id_nesting_flag" );
    575526
    576527  TComRPSList* rpsList = pcSPS->getRPSList();
     
    581532  {
    582533    rps = rpsList->getReferencePictureSet(i);
    583 #if J0234_INTER_RPS_SIMPL
    584     codeShortTermRefPicSet(pcSPS,rps,false);
    585 #else
    586     codeShortTermRefPicSet(pcSPS,rps);
    587 #endif
    588   }   
     534    codeShortTermRefPicSet(pcSPS,rps,false, i);
     535  }
    589536  WRITE_FLAG( pcSPS->getLongTermRefsPresent() ? 1 : 0,         "long_term_ref_pics_present_flag" );
    590 #if LTRP_IN_SPS
    591537  if (pcSPS->getLongTermRefsPresent())
    592538  {
     
    598544    }
    599545  }
    600 #endif
    601546  WRITE_FLAG( pcSPS->getTMVPFlagsPresent()  ? 1 : 0,           "sps_temporal_mvp_enable_flag" );
    602547#if REF_IDX_MFM
    603548  if( pcSPS->getLayerId() > 0 )
    604549  {
    605     assert(pcSPS->getMFMEnabledFlag());
    606550    WRITE_FLAG( pcSPS->getMFMEnabledFlag() ? 1 : 0,          "sps_enh_mfm_enable_flag" );
    607551  }
    608552#endif
    609 #if SUPPORT_FOR_VUI
     553  WRITE_FLAG( pcSPS->getUseStrongIntraSmoothing(),             "sps_strong_intra_smoothing_enable_flag" );
     554
    610555  WRITE_FLAG( pcSPS->getVuiParametersPresentFlag(),             "vui_parameters_present_flag" );
    611556  if (pcSPS->getVuiParametersPresentFlag())
     
    613558      codeVUI(pcSPS->getVuiParameters(), pcSPS);
    614559  }
    615 #endif
    616 #if !SPS_AMVP_CLEANUP
    617   // AMVP mode for each depth
    618   for (Int i = 0; i < pcSPS->getMaxCUDepth(); i++)
    619   {
    620     xWriteFlag( pcSPS->getAMVPMode(i) ? 1 : 0);
    621   }
    622 #endif
     560
    623561  WRITE_FLAG( 0, "sps_extension_flag" );
    624562}
     
    626564Void TEncCavlc::codeVPS( TComVPS* pcVPS )
    627565{
    628 #if VPS_SYNTAX_CHANGES
    629   WRITE_CODE( pcVPS->getVPSId(),                    4,        "video_parameter_set_id" );
     566  WRITE_CODE( pcVPS->getVPSId(),                    4,        "vps_video_parameter_set_id" );
     567  WRITE_CODE( 3,                                    2,        "vps_reserved_three_2bits" );
     568#if VPS_RENAME
     569  WRITE_CODE( pcVPS->getMaxLayers() - 1,            6,        "vps_max_layers_minus1" );           
     570#else
     571  WRITE_CODE( 0,                                    6,        "vps_reserved_zero_6bits" );
     572#endif
     573  WRITE_CODE( pcVPS->getMaxTLayers() - 1,           3,        "vps_max_sub_layers_minus1" );
    630574  WRITE_FLAG( pcVPS->getTemporalNestingFlag(),                "vps_temporal_id_nesting_flag" );
    631   WRITE_CODE( 0,                                    2,        "vps_reserved_zero_2bits" );
    632   WRITE_CODE( 0,                                    6,        "vps_reserved_zero_6bits" );
    633   WRITE_CODE( pcVPS->getMaxTLayers() - 1,           3,        "vps_max_sub_layers_minus1" );
     575  assert (pcVPS->getMaxTLayers()>1||pcVPS->getTemporalNestingFlag());
     576  WRITE_CODE( 0xffff,                              16,        "vps_reserved_ffff_16bits" );
    634577  codePTL( pcVPS->getPTL(), true, pcVPS->getMaxTLayers() - 1 );
    635   WRITE_CODE( 0,                                   12,        "vps_reserved_zero_12bits" );
    636 #else
    637   WRITE_CODE( pcVPS->getMaxTLayers() - 1,     3,        "vps_max_temporal_layers_minus1" );
    638   WRITE_CODE( pcVPS->getMaxLayers() - 1,      5,        "vps_max_layers_minus1" );
    639   WRITE_UVLC( pcVPS->getVPSId(),                        "video_parameter_set_id" );
    640   WRITE_FLAG( pcVPS->getTemporalNestingFlag(),          "vps_temporal_id_nesting_flag" );
    641 #endif
     578#if SIGNAL_BITRATE_PICRATE_IN_VPS
     579  codeBitratePicRateInfo(pcVPS->getBitratePicrateInfo(), 0, pcVPS->getMaxTLayers() - 1);
     580#endif 
     581  const Bool subLayerOrderingInfoPresentFlag = 1;
     582  WRITE_FLAG(subLayerOrderingInfoPresentFlag,              "vps_sub_layer_ordering_info_present_flag");
    642583  for(UInt i=0; i <= pcVPS->getMaxTLayers()-1; i++)
    643584  {
     
    645586    WRITE_UVLC( pcVPS->getNumReorderPics(i),               "vps_num_reorder_pics[i]" );
    646587    WRITE_UVLC( pcVPS->getMaxLatencyIncrease(i),           "vps_max_latency_increase[i]" );
    647   }
    648 #if VPS_SYNTAX_CHANGES
    649   WRITE_UVLC( 0,                                           "vps_num_hrd_parameters" );
    650   // hrd_parameters
    651 #endif
     588    if (!subLayerOrderingInfoPresentFlag)
     589    {
     590      break;
     591    }
     592  }
     593
     594#if VPS_RENAME
     595  assert( pcVPS->getNumHrdParameters() <= MAX_VPS_LAYER_SETS_PLUS1 );
     596  assert( pcVPS->getMaxLayerId() < MAX_VPS_LAYER_ID_PLUS1 );
     597#if !VPS_EXTN_OP_LAYER_SETS     // num layer sets set in TAppEncTop.cpp
     598  pcVPS->setNumLayerSets(1);
     599#endif
     600  WRITE_CODE( pcVPS->getMaxLayerId(), 6,                       "vps_max_layer_id" );
     601  WRITE_UVLC( pcVPS->getNumLayerSets() - 1,                 "vps_num_layer_sets_minus1" );
     602  for( UInt opsIdx = 1; opsIdx <= ( pcVPS->getNumLayerSets() - 1 ); opsIdx ++ )
     603  {
     604    // Operation point set
     605    for( UInt i = 0; i <= pcVPS->getMaxLayerId(); i ++ )
     606#else
     607  assert( pcVPS->getNumHrdParameters() <= MAX_VPS_NUM_HRD_PARAMETERS );
     608  assert( pcVPS->getMaxNuhReservedZeroLayerId() < MAX_VPS_NUH_RESERVED_ZERO_LAYER_ID_PLUS1 );
     609  WRITE_CODE( pcVPS->getMaxNuhReservedZeroLayerId(), 6,     "vps_max_nuh_reserved_zero_layer_id" );
     610  pcVPS->setMaxOpSets(1);
     611  WRITE_UVLC( pcVPS->getMaxOpSets() - 1,                    "vps_max_op_sets_minus1" );
     612  for( UInt opsIdx = 1; opsIdx <= ( pcVPS->getMaxOpSets() - 1 ); opsIdx ++ )
     613  {
     614    // Operation point set
     615    for( UInt i = 0; i <= pcVPS->getMaxNuhReservedZeroLayerId(); i ++ )
     616#endif
     617    {
     618#if !VPS_EXTN_OP_LAYER_SETS     // layer Id include flag set in TAppEncTop.cpp
     619      // Only applicable for version 1
     620      pcVPS->setLayerIdIncludedFlag( true, opsIdx, i );
     621#endif
     622      WRITE_FLAG( pcVPS->getLayerIdIncludedFlag( opsIdx, i ) ? 1 : 0, "layer_id_included_flag[opsIdx][i]" );
     623    }
     624  }
     625#if L0043_TIMING_INFO
     626  TimingInfo *timingInfo = pcVPS->getTimingInfo();
     627  WRITE_FLAG(timingInfo->getTimingInfoPresentFlag(),          "vps_timing_info_present_flag");
     628  if(timingInfo->getTimingInfoPresentFlag())
     629  {
     630    WRITE_CODE(timingInfo->getNumUnitsInTick(), 32,           "vps_num_units_in_tick");
     631    WRITE_CODE(timingInfo->getTimeScale(),      32,           "vps_time_scale");
     632    WRITE_FLAG(timingInfo->getPocProportionalToTimingFlag(),  "vps_poc_proportional_to_timing_flag");
     633    if(timingInfo->getPocProportionalToTimingFlag())
     634    {
     635      WRITE_UVLC(timingInfo->getNumTicksPocDiffOneMinus1(),   "vps_num_ticks_poc_diff_one_minus1");
     636    }
     637#endif
     638    pcVPS->setNumHrdParameters( 0 );
     639    WRITE_UVLC( pcVPS->getNumHrdParameters(),                 "vps_num_hrd_parameters" );
     640
     641    if( pcVPS->getNumHrdParameters() > 0 )
     642    {
     643      pcVPS->createHrdParamBuffer();
     644    }
     645    for( UInt i = 0; i < pcVPS->getNumHrdParameters(); i ++ )
     646    {
     647      // Only applicable for version 1
     648      pcVPS->setHrdOpSetIdx( 0, i );
     649      WRITE_UVLC( pcVPS->getHrdOpSetIdx( i ),                "hrd_op_set_idx" );
     650      if( i > 0 )
     651      {
     652        WRITE_FLAG( pcVPS->getCprmsPresentFlag( i ) ? 1 : 0, "cprms_present_flag[i]" );
     653      }
     654      codeHrdParameters(pcVPS->getHrdParameters(i), pcVPS->getCprmsPresentFlag( i ), pcVPS->getMaxTLayers() - 1);
     655    }
     656#if L0043_TIMING_INFO
     657  }
     658#endif
     659#if !VPS_EXTNS
    652660  WRITE_FLAG( 0,                     "vps_extension_flag" );
    653  
     661#else
     662  WRITE_FLAG( 1,                     "vps_extension_flag" );
     663  codeVPSExtension(pcVPS);
     664  WRITE_FLAG( 0,                     "vps_extension2_flag" );   // Flag value of 1 reserved
     665#endif 
    654666  //future extensions here..
    655667 
     
    657669}
    658670
     671#if VPS_EXTNS
     672Void TEncCavlc::codeVPSExtension (TComVPS *vps)
     673{
     674  // ... More syntax elements to be written here
     675#if VPS_EXTN_MASK_AND_DIM_INFO
     676  UInt i = 0, j = 0;
     677
     678  WRITE_FLAG( vps->getAvcBaseLayerFlag(),              "avc_base_layer_flag" );
     679  WRITE_FLAG( vps->getSplittingFlag(),                 "splitting_flag" );
     680
     681  for(i = 0; i < MAX_VPS_NUM_SCALABILITY_TYPES; i++)
     682  {
     683    WRITE_FLAG( vps->getScalabilityMask(i),            "scalability_mask[i]" );
     684  }
     685
     686  for(j = 0; j < vps->getNumScalabilityTypes(); j++)
     687  {
     688    WRITE_CODE( vps->getDimensionIdLen(j) - 1, 3,      "dimension_id_len_minus1[j]" );
     689  }
     690
     691  WRITE_FLAG( vps->getNuhLayerIdPresentFlag(),         "vps_nuh_layer_id_present_flag" );
     692  for(i = 1; i < vps->getMaxLayers(); i++)
     693  {
     694    if( vps->getNuhLayerIdPresentFlag() )
     695    {
     696      WRITE_CODE( vps->getLayerIdInNuh(i),     6,      "layer_id_in_nuh[i]" );
     697    }
     698    for(j = 0; j < vps->getNumScalabilityTypes(); j++)
     699    {
     700      UInt bits = vps->getDimensionIdLen(j);
     701      WRITE_CODE( vps->getDimensionId(i, j),   bits,   "dimension_id[i][j]" );
     702    }
     703  }
     704#endif
     705#if VPS_EXTN_PROFILE_INFO
     706  // Profile-tier-level signalling
     707  for(Int idx = 1; idx <= vps->getNumLayerSets() - 1; idx++)
     708  {
     709    WRITE_FLAG( vps->getProfilePresentFlag(idx),       "vps_profile_present_flag[i]" );
     710    if( !vps->getProfilePresentFlag(idx) )
     711    {
     712      WRITE_UVLC( vps->getProfileLayerSetRef(idx) - 1, "vps_profile_layer_set_ref_minus1[i]" );
     713    }
     714    codePTL( vps->getPTLForExtn(idx), vps->getProfilePresentFlag(idx), vps->getMaxTLayers() - 1 );
     715  }
     716#endif
     717#if VPS_EXTN_OP_LAYER_SETS
     718  // Target output layer signalling
     719  WRITE_UVLC( vps->getNumOutputLayerSets(),            "vps_num_output_layer_sets");
     720  for(i = 0; i < vps->getNumOutputLayerSets(); i++)
     721  {
     722    WRITE_UVLC( vps->getOutputLayerSetIdx(i),           "vps_output_layer_set_idx[i]");
     723    Int lsIdx = vps->getOutputLayerSetIdx(i);
     724    for(j = 0; j <= vps->getMaxLayerId(); j++)
     725    {
     726      if(vps->getLayerIdIncludedFlag(lsIdx, j))
     727      {
     728        WRITE_FLAG( vps->getOutputLayerFlag(lsIdx, j), "vps_output_layer_flag[lsIdx][j]");
     729      }
     730    }
     731  }
     732#endif
     733#if VPS_EXTN_DIRECT_REF_LAYERS
     734  for( Int layerCtr = 1; layerCtr <= vps->getMaxLayers() - 1; layerCtr++)
     735  {
     736    for( Int refLayerCtr = 0; refLayerCtr < layerCtr; refLayerCtr++)
     737    {
     738      WRITE_FLAG(vps->getDirectDependencyFlag(layerCtr, refLayerCtr), "direct_dependency_flag[i][j]" );
     739    }
     740  }
     741#endif
     742}
     743#endif
     744
    659745Void TEncCavlc::codeSliceHeader         ( TComSlice* pcSlice )
    660746{
     
    664750
    665751  //calculate number of bits required for slice address
    666   Int maxAddrOuter = pcSlice->getPic()->getNumCUsInFrame();
    667   Int reqBitsOuter = 0;
    668   while(maxAddrOuter>(1<<reqBitsOuter))
    669   {
    670     reqBitsOuter++;
    671   }
    672   Int maxAddrInner = pcSlice->getPic()->getNumPartInCU()>>(2);
    673 #if REMOVE_FGS
    674   maxAddrInner = 1;
    675 #else
    676   maxAddrInner = (1<<(pcSlice->getPPS()->getSliceGranularity()<<1));
    677 #endif
    678   Int reqBitsInner = 0;
    679  
    680   while(maxAddrInner>(1<<reqBitsInner))
    681   {
    682     reqBitsInner++;
    683   }
    684   Int lCUAddress;
    685   Int innerAddress;
     752  Int maxSliceSegmentAddress = pcSlice->getPic()->getNumCUsInFrame();
     753  Int bitsSliceSegmentAddress = 0;
     754  while(maxSliceSegmentAddress>(1<<bitsSliceSegmentAddress))
     755  {
     756    bitsSliceSegmentAddress++;
     757  }
     758  Int ctuAddress;
    686759  if (pcSlice->isNextSlice())
    687760  {
    688761    // Calculate slice address
    689     lCUAddress = (pcSlice->getSliceCurStartCUAddr()/pcSlice->getPic()->getNumPartInCU());
    690 #if REMOVE_FGS
    691     innerAddress = 0;
    692 #else
    693     innerAddress = (pcSlice->getSliceCurStartCUAddr()%(pcSlice->getPic()->getNumPartInCU()))>>((pcSlice->getSPS()->getMaxCUDepth()-pcSlice->getPPS()->getSliceGranularity())<<1);
    694 #endif
     762    ctuAddress = (pcSlice->getSliceCurStartCUAddr()/pcSlice->getPic()->getNumPartInCU());
    695763  }
    696764  else
    697765  {
    698766    // Calculate slice address
    699     lCUAddress = (pcSlice->getDependentSliceCurStartCUAddr()/pcSlice->getPic()->getNumPartInCU());
    700 #if REMOVE_FGS
    701     innerAddress = 0;
    702 #else
    703     innerAddress = (pcSlice->getDependentSliceCurStartCUAddr()%(pcSlice->getPic()->getNumPartInCU()))>>((pcSlice->getSPS()->getMaxCUDepth()-pcSlice->getPPS()->getSliceGranularity())<<1);
    704 #endif
    705    
     767    ctuAddress = (pcSlice->getSliceSegmentCurStartCUAddr()/pcSlice->getPic()->getNumPartInCU());
    706768  }
    707769  //write slice address
    708   Int address = (pcSlice->getPic()->getPicSym()->getCUOrderMap(lCUAddress) << reqBitsInner) + innerAddress;
    709   WRITE_FLAG( address==0, "first_slice_in_pic_flag" );
    710 #if SPLICING_FRIENDLY_PARAMS
     770  Int sliceSegmentAddress = pcSlice->getPic()->getPicSym()->getCUOrderMap(ctuAddress);
     771
     772  WRITE_FLAG( sliceSegmentAddress==0, "first_slice_segment_in_pic_flag" );
    711773  if ( pcSlice->getRapPicFlag() )
    712774  {
    713775    WRITE_FLAG( 0, "no_output_of_prior_pics_flag" );
    714776  }
    715 #endif
    716   WRITE_UVLC( pcSlice->getPPS()->getPPSId(), "pic_parameter_set_id" );
    717   if(address>0)
    718   {
    719     WRITE_CODE( address, reqBitsOuter+reqBitsInner, "slice_address" );
    720   }
    721 
    722 #if SLICEHEADER_SYNTAX_FIX
    723   pcSlice->setDependentSliceFlag(!pcSlice->isNextSlice());
    724   if ( pcSlice->getPPS()->getDependentSliceEnabledFlag() && (address!=0) )
    725   {
    726     WRITE_FLAG( pcSlice->getDependentSliceFlag() ? 1 : 0, "dependent_slice_flag" );
    727   }
    728   if ( !pcSlice->getDependentSliceFlag() )
    729   {
    730 #endif
     777  WRITE_UVLC( pcSlice->getPPS()->getPPSId(), "slice_pic_parameter_set_id" );
     778  pcSlice->setDependentSliceSegmentFlag(!pcSlice->isNextSlice());
     779  if ( pcSlice->getPPS()->getDependentSliceSegmentsEnabledFlag() && (sliceSegmentAddress!=0) )
     780  {
     781    WRITE_FLAG( pcSlice->getDependentSliceSegmentFlag() ? 1 : 0, "dependent_slice_segment_flag" );
     782  }
     783  if(sliceSegmentAddress>0)
     784  {
     785    WRITE_CODE( sliceSegmentAddress, bitsSliceSegmentAddress, "slice_segment_address" );
     786  }
     787  if ( !pcSlice->getDependentSliceSegmentFlag() )
     788  {
     789    for (Int i = 0; i < pcSlice->getPPS()->getNumExtraSliceHeaderBits(); i++)
     790    {
     791      assert(!!"slice_reserved_undetermined_flag[]");
     792      WRITE_FLAG(0, "slice_reserved_undetermined_flag[]");
     793    }
    731794
    732795    WRITE_UVLC( pcSlice->getSliceType(),       "slice_type" );
    733796
    734 #if !SLICEHEADER_SYNTAX_FIX
    735   Bool bDependentSlice = (!pcSlice->isNextSlice());
    736   WRITE_FLAG( bDependentSlice ? 1 : 0, "dependent_slice_flag" );
    737  
    738 #if DEPENDENT_SLICES
    739   if( pcSlice->getPPS()->getDependentSliceEnabledFlag() && bDependentSlice )
    740     return;
    741 #endif
    742 
    743   if (!bDependentSlice)
    744   {
    745 #endif
    746797    if( pcSlice->getPPS()->getOutputFlagPresentFlag() )
    747798    {
     
    754805    //   colour_plane_id                                      u(2)
    755806
    756 #if !SPLICING_FRIENDLY_PARAMS
    757     if(   pcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR
    758 #if SUPPORT_FOR_RAP_N_LP
    759        || pcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_N_LP
    760        || pcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_N_LP
    761 #endif
    762        || pcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLANT
    763        || pcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA
    764 #if !NAL_UNIT_TYPES_J1003_D7
    765        || pcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_CRANT
    766 #endif
    767        || pcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_CRA )
    768     {
    769       WRITE_UVLC( 0, "rap_pic_id" );
    770       WRITE_FLAG( 0, "no_output_of_prior_pics_flag" );
    771     }
    772 #endif
    773 #if SUPPORT_FOR_RAP_N_LP
    774807    if( !pcSlice->getIdrPicFlag() )
    775 #else
    776     if( pcSlice->getNalUnitType() != NAL_UNIT_CODED_SLICE_IDR )
    777 #endif
    778808    {
    779809      Int picOrderCntLSB = (pcSlice->getPOC()-pcSlice->getLastIDR()+(1<<pcSlice->getSPS()->getBitsForPOC()))%(1<<pcSlice->getSPS()->getBitsForPOC());
     
    783813      {
    784814        WRITE_FLAG( 0, "short_term_ref_pic_set_sps_flag");
    785 #if J0234_INTER_RPS_SIMPL
    786         codeShortTermRefPicSet(pcSlice->getSPS(), rps, true);
    787 #else
    788         codeShortTermRefPicSet(pcSlice->getSPS(), rps);
    789 #endif
     815        codeShortTermRefPicSet(pcSlice->getSPS(), rps, true, pcSlice->getSPS()->getRPSList()->getNumberOfReferencePictureSets());
    790816      }
    791817      else
    792818      {
    793819        WRITE_FLAG( 1, "short_term_ref_pic_set_sps_flag");
    794         WRITE_UVLC( pcSlice->getRPSidx(), "short_term_ref_pic_set_idx" );
     820        Int numBits = 0;
     821        while ((1 << numBits) < pcSlice->getSPS()->getRPSList()->getNumberOfReferencePictureSets())
     822        {
     823          numBits++;
     824        }
     825        if (numBits > 0)
     826        {
     827          WRITE_CODE( pcSlice->getRPSidx(), numBits, "short_term_ref_pic_set_idx" );         
     828        }
    795829      }
    796830      if(pcSlice->getSPS()->getLongTermRefsPresent())
    797831      {
    798 #if LTRP_IN_SPS
    799832        Int numLtrpInSH = rps->getNumberOfLongtermPictures();
    800833        Int ltrpInSPS[MAX_NUM_REF_PICS];
     
    816849        numLtrpInSH -= numLtrpInSPS;
    817850
    818         Int bitsForLtrpInSPS = 1;
     851        Int bitsForLtrpInSPS = 0;
    819852        while (pcSlice->getSPS()->getNumLongTermRefPicSPS() > (1 << bitsForLtrpInSPS))
    820853        {
     
    826859        }
    827860        WRITE_UVLC( numLtrpInSH, "num_long_term_pics");
    828 #else
    829         WRITE_UVLC( rps->getNumberOfLongtermPictures(), "num_long_term_pics");
    830 #endif
    831861        // Note that the LSBs of the LT ref. pic. POCs must be sorted before.
    832862        // Not sorted here because LT ref indices will be used in setRefPicList()
     
    835865        for(Int i=rps->getNumberOfPictures()-1 ; i > offset-1; i--)
    836866        {
    837 #if LTRP_IN_SPS
    838867          if (counter < numLtrpInSPS)
    839868          {
    840             WRITE_CODE( ltrpInSPS[counter], bitsForLtrpInSPS, "lt_idx_sps[i]");
     869            if (bitsForLtrpInSPS > 0)
     870            {
     871              WRITE_CODE( ltrpInSPS[counter], bitsForLtrpInSPS, "lt_idx_sps[i]");             
     872            }
    841873          }
    842874          else
     
    845877            WRITE_FLAG( rps->getUsed(i), "used_by_curr_pic_lt_flag");
    846878          }
    847 #else
    848           WRITE_CODE( rps->getPocLSBLT(i), pcSlice->getSPS()->getBitsForPOC(), "poc_lsb_lt");
    849 #endif
    850879          WRITE_FLAG( rps->getDeltaPocMSBPresentFlag(i), "delta_poc_msb_present_flag");
    851880
     
    853882          {
    854883            Bool deltaFlag = false;
    855 #if LTRP_IN_SPS
    856884            //  First LTRP from SPS                 ||  First LTRP from SH                              || curr LSB            != prev LSB
    857885            if( (i == rps->getNumberOfPictures()-1) || (i == rps->getNumberOfPictures()-1-numLtrpInSPS) || (rps->getPocLSBLT(i) != prevLSB) )
    858 #else
    859             //   First LTRP                         ||  curr LSB            != prev LSB
    860             if( (i == rps->getNumberOfPictures()-1) || (rps->getPocLSBLT(i) != prevLSB) )
    861 #endif
    862886            {
    863887              deltaFlag = true;
     
    876900            prevDeltaMSB = rps->getDeltaPocMSBCycleLT(i);
    877901          }
    878 #if !LTRP_IN_SPS
    879           WRITE_FLAG( rps->getUsed(i), "used_by_curr_pic_lt_flag");
    880 #endif
    881         }
    882       }
    883     }
    884 #if REMOVE_ALF
     902        }
     903      }
     904      if (pcSlice->getSPS()->getTMVPFlagsPresent())
     905      {
     906        WRITE_FLAG( pcSlice->getEnableTMVPFlag() ? 1 : 0, "slice_temporal_mvp_enable_flag" );
     907      }
     908    }
    885909    if(pcSlice->getSPS()->getUseSAO())
    886 #else
    887     if(pcSlice->getSPS()->getUseSAO() || pcSlice->getSPS()->getUseALF())
    888 #endif
    889910    {
    890911      if (pcSlice->getSPS()->getUseSAO())
    891912      {
    892913         WRITE_FLAG( pcSlice->getSaoEnabledFlag(), "slice_sao_luma_flag" );
    893 #if !SAO_LUM_CHROMA_ONOFF_FLAGS
    894          if (pcSlice->getSaoEnabledFlag() )
    895 #endif
    896914         {
    897 #if REMOVE_APS
    898915           SAOParam *saoParam = pcSlice->getPic()->getPicSym()->getSaoParam();
    899 #else
    900            SAOParam *saoParam = pcSlice->getAPS()->getSaoParam();
    901 #endif
    902 #if SAO_TYPE_SHARING
    903916          WRITE_FLAG( saoParam->bSaoFlag[1], "slice_sao_chroma_flag" );
    904 #else
    905           WRITE_FLAG( saoParam->bSaoFlag[1], "SAO on/off flag for Cb in slice header" );
    906           WRITE_FLAG( saoParam->bSaoFlag[2], "SAO on/off flag for Cr in slice header" );
    907 #endif
    908917         }
    909918      }
    910 #if !REMOVE_APS
    911       WRITE_UVLC( pcSlice->getAPS()->getAPSID(), "aps_id");
    912 #endif
    913919    }
    914920
    915921    //check if numrefidxes match the defaults. If not, override
     922
    916923    if (!pcSlice->isIntra())
    917924    {
    918       if (pcSlice->getSPS()->getTMVPFlagsPresent())
    919       {
    920         WRITE_FLAG( pcSlice->getEnableTMVPFlag(), "enable_temporal_mvp_flag" );
    921       }
    922925      Bool overrideFlag = (pcSlice->getNumRefIdx( REF_PIC_LIST_0 )!=pcSlice->getPPS()->getNumRefIdxL0DefaultActive()||(pcSlice->isInterB()&&pcSlice->getNumRefIdx( REF_PIC_LIST_1 )!=pcSlice->getPPS()->getNumRefIdxL1DefaultActive()));
    923926      WRITE_FLAG( overrideFlag ? 1 : 0,                               "num_ref_idx_active_override_flag");
     
    940943      pcSlice->setNumRefIdx(REF_PIC_LIST_1, 0);
    941944    }
    942     if( pcSlice->getSPS()->getListsModificationPresentFlag() )
     945
     946    if( pcSlice->getPPS()->getListsModificationPresentFlag() && pcSlice->getNumRpsCurrTempList() > 1)
    943947    {
    944948      TComRefPicListModification* refPicListModification = pcSlice->getRefPicListModification();
     
    986990      }
    987991    }
    988 #if !SLICEHEADER_SYNTAX_FIX
    989   }
    990 #endif
    991992   
    992993    if (pcSlice->isInterB())
     
    10071008    }
    10081009
    1009 #if !SLICEHEADER_SYNTAX_FIX
    1010   // if( !lightweight_slice_flag ) {
    1011   if (!bDependentSlice)
    1012   {
    1013 #else
    10141010    if ( pcSlice->getEnableTMVPFlag() )
    10151011    {
     
    10311027    }
    10321028    assert(pcSlice->getMaxNumMergeCand()<=MRG_MAX_NUM_CANDS);
    1033     WRITE_UVLC(MRG_MAX_NUM_CANDS - pcSlice->getMaxNumMergeCand(), "five_minus_max_num_merge_cand");
    1034 #endif
     1029    if (!pcSlice->isIntra())
     1030    {
     1031      WRITE_UVLC(MRG_MAX_NUM_CANDS - pcSlice->getMaxNumMergeCand(), "five_minus_max_num_merge_cand");
     1032    }
    10351033    Int iCode = pcSlice->getSliceQp() - ( pcSlice->getPPS()->getPicInitQPMinus26() + 26 );
    10361034    WRITE_SVLC( iCode, "slice_qp_delta" );
    1037 #if CHROMA_QP_EXTENSION
    10381035    if (pcSlice->getPPS()->getSliceChromaQpFlag())
    10391036    {
     
    10431040      WRITE_SVLC( iCode, "slice_qp_delta_cr" );
    10441041    }
    1045 #endif
    10461042    if (pcSlice->getPPS()->getDeblockingFilterControlPresentFlag())
    10471043    {
     
    10551051        if(!pcSlice->getDeblockingFilterDisable())
    10561052        {
    1057           WRITE_SVLC (pcSlice->getDeblockingFilterBetaOffsetDiv2(), "beta_offset_div2");
    1058           WRITE_SVLC (pcSlice->getDeblockingFilterTcOffsetDiv2(),   "tc_offset_div2");
    1059         }
    1060       }
    1061     }
    1062 #if !SLICEHEADER_SYNTAX_FIX
    1063     if ( pcSlice->getEnableTMVPFlag() )
    1064     {
    1065       if ( pcSlice->getSliceType() == B_SLICE )
    1066       {
    1067         WRITE_FLAG( pcSlice->getColFromL0Flag(), "collocated_from_l0_flag" );
    1068       }
    1069 
    1070       if ( pcSlice->getSliceType() != I_SLICE &&
    1071          ((pcSlice->getColFromL0Flag()==1 && pcSlice->getNumRefIdx(REF_PIC_LIST_0)>1)||
    1072          (pcSlice->getColFromL0Flag()==0  && pcSlice->getNumRefIdx(REF_PIC_LIST_1)>1)))
    1073       {
    1074         WRITE_UVLC( pcSlice->getColRefIdx(), "collocated_ref_idx" );
    1075       }
    1076     }
    1077     if ( (pcSlice->getPPS()->getUseWP() && pcSlice->getSliceType()==P_SLICE) || (pcSlice->getPPS()->getWPBiPred() && pcSlice->getSliceType()==B_SLICE) )
    1078     {
    1079       xCodePredWeightTable( pcSlice );
    1080     }
    1081   }
    1082     assert(pcSlice->getMaxNumMergeCand()<=MRG_MAX_NUM_CANDS);
    1083     WRITE_UVLC(MRG_MAX_NUM_CANDS - pcSlice->getMaxNumMergeCand(), "five_minus_max_num_merge_cand");
    1084 #endif
    1085 
    1086 #if !REMOVE_ALF
    1087   if (!bDependentSlice)
    1088   {
    1089     if (pcSlice->getSPS()->getUseALF())
    1090     {
    1091       char syntaxString[50];
    1092       for(Int compIdx=0; compIdx< 3; compIdx++)
    1093       {
    1094         sprintf(syntaxString, "alf_slice_filter_flag[%d]", compIdx);
    1095         WRITE_FLAG( pcSlice->getAlfEnabledFlag(compIdx)?1:0, syntaxString );
    1096       }
    1097     }
    1098   }
    1099 #endif
    1100 #if !SLICEHEADER_SYNTAX_FIX
    1101   if(!bDependentSlice)
    1102   {
    1103 #endif
    1104 #if !REMOVE_ALF
    1105     Bool isAlfEnabled = (!pcSlice->getSPS()->getUseALF())?(false):(pcSlice->getAlfEnabledFlag(0)||pcSlice->getAlfEnabledFlag(1)||pcSlice->getAlfEnabledFlag(2));
    1106 #endif
    1107 #if !SAO_LUM_CHROMA_ONOFF_FLAGS
    1108     Bool isSAOEnabled = (!pcSlice->getSPS()->getUseSAO())?(false):(pcSlice->getSaoEnabledFlag());
    1109 #else
     1053          WRITE_SVLC (pcSlice->getDeblockingFilterBetaOffsetDiv2(), "slice_beta_offset_div2");
     1054          WRITE_SVLC (pcSlice->getDeblockingFilterTcOffsetDiv2(),   "slice_tc_offset_div2");
     1055        }
     1056      }
     1057    }
     1058
    11101059    Bool isSAOEnabled = (!pcSlice->getSPS()->getUseSAO())?(false):(pcSlice->getSaoEnabledFlag()||pcSlice->getSaoEnabledFlagChroma());
    1111 #endif
    11121060    Bool isDBFEnabled = (!pcSlice->getDeblockingFilterDisable());
    11131061
    1114 #if REMOVE_ALF
    1115 #if MOVE_LOOP_FILTER_SLICES_FLAG
    11161062    if(pcSlice->getPPS()->getLoopFilterAcrossSlicesEnabledFlag() && ( isSAOEnabled || isDBFEnabled ))
    1117 #else
    1118     if(pcSlice->getSPS()->getLFCrossSliceBoundaryFlag() && ( isSAOEnabled || isDBFEnabled ))
    1119 #endif
    1120 #else
    1121     if(pcSlice->getSPS()->getLFCrossSliceBoundaryFlag() && ( isAlfEnabled || isSAOEnabled || isDBFEnabled ))
    1122 #endif
    11231063    {
    11241064      WRITE_FLAG(pcSlice->getLFCrossSliceBoundaryFlag()?1:0, "slice_loop_filter_across_slices_enabled_flag");
    11251065    }
    11261066  }
    1127 #if SLICE_HEADER_EXTENSION
    11281067  if(pcSlice->getPPS()->getSliceHeaderExtensionPresentFlag())
    11291068  {
    11301069    WRITE_UVLC(0,"slice_header_extension_length");
    11311070  }
    1132 #endif
    1133 }
    1134 
    1135 #if PROFILE_TIER_LEVEL_SYNTAX
     1071}
     1072
    11361073Void TEncCavlc::codePTL( TComPTL* pcPTL, Bool profilePresentFlag, Int maxNumSubLayersMinus1)
    11371074{
     
    11421079  WRITE_CODE( pcPTL->getGeneralPTL()->getLevelIdc(), 8, "general_level_idc" );
    11431080
     1081#if L0363_BYTE_ALIGN
     1082  for (Int i = 0; i < maxNumSubLayersMinus1; i++)
     1083  {
     1084    if(profilePresentFlag)
     1085    {
     1086      WRITE_FLAG( pcPTL->getSubLayerProfilePresentFlag(i), "sub_layer_profile_present_flag[i]" );
     1087    }
     1088   
     1089    WRITE_FLAG( pcPTL->getSubLayerLevelPresentFlag(i),   "sub_layer_level_present_flag[i]" );
     1090  }
     1091 
     1092  if (maxNumSubLayersMinus1 > 0)
     1093  {
     1094    for (Int i = maxNumSubLayersMinus1; i < 8; i++)
     1095    {
     1096      WRITE_CODE(0, 2, "reserved_zero_2bits");
     1097    }
     1098  }
     1099#endif
     1100 
    11441101  for(Int i = 0; i < maxNumSubLayersMinus1; i++)
    11451102  {
    1146     WRITE_FLAG( pcPTL->getSubLayerProfilePresentFlag(i), "sub_layer_profile_present_flag[i]" );
     1103#if !L0363_BYTE_ALIGN
     1104    if(profilePresentFlag)
     1105    {
     1106      WRITE_FLAG( pcPTL->getSubLayerProfilePresentFlag(i), "sub_layer_profile_present_flag[i]" );
     1107    }
     1108
    11471109    WRITE_FLAG( pcPTL->getSubLayerLevelPresentFlag(i),   "sub_layer_level_present_flag[i]" );
     1110#endif
    11481111    if( profilePresentFlag && pcPTL->getSubLayerProfilePresentFlag(i) )
    11491112    {
     
    11651128    WRITE_FLAG( ptl->getProfileCompatibilityFlag(j), "XXX_profile_compatibility_flag[][j]");   
    11661129  }
    1167   WRITE_CODE(0 , 16, "XXX_reserved_zero_16bits[]"); 
    1168 }
    1169 #endif
    1170 
     1130
     1131#if L0046_CONSTRAINT_FLAGS
     1132  WRITE_FLAG(ptl->getProgressiveSourceFlag(),   "general_progressive_source_flag");
     1133  WRITE_FLAG(ptl->getInterlacedSourceFlag(),    "general_interlaced_source_flag");
     1134  WRITE_FLAG(ptl->getNonPackedConstraintFlag(), "general_non_packed_constraint_flag");
     1135  WRITE_FLAG(ptl->getFrameOnlyConstraintFlag(), "general_frame_only_constraint_flag");
     1136 
     1137  WRITE_CODE(0 , 16, "XXX_reserved_zero_44bits[0..15]");
     1138  WRITE_CODE(0 , 16, "XXX_reserved_zero_44bits[16..31]");
     1139  WRITE_CODE(0 , 12, "XXX_reserved_zero_44bits[32..43]");
     1140#elif L0363_MORE_BITS
     1141  WRITE_CODE(0 , 16, "XXX_reserved_zero_48bits[0..15]");
     1142  WRITE_CODE(0 , 16, "XXX_reserved_zero_48bits[16..31]");
     1143  WRITE_CODE(0 , 16, "XXX_reserved_zero_48bits[32..47]");
     1144#else
     1145  WRITE_CODE(0 , 16, "XXX_reserved_zero_16bits[]");
     1146#endif
     1147}
     1148#if SIGNAL_BITRATE_PICRATE_IN_VPS
     1149Void TEncCavlc::codeBitratePicRateInfo(TComBitRatePicRateInfo *info, Int tempLevelLow, Int tempLevelHigh)
     1150{
     1151  for(Int i = tempLevelLow; i <= tempLevelHigh; i++)
     1152  {
     1153    WRITE_FLAG( info->getBitRateInfoPresentFlag(i),  "bit_rate_info_present_flag[i]" );
     1154    WRITE_FLAG( info->getPicRateInfoPresentFlag(i),  "pic_rate_info_present_flag[i]" );
     1155    if(info->getBitRateInfoPresentFlag(i))
     1156    {
     1157      WRITE_CODE( info->getAvgBitRate(i), 16, "avg_bit_rate[i]" );
     1158      WRITE_CODE( info->getMaxBitRate(i), 16, "max_bit_rate[i]" );
     1159    }
     1160    if(info->getPicRateInfoPresentFlag(i))
     1161    {
     1162      WRITE_CODE( info->getConstantPicRateIdc(i),  2, "constant_pic_rate_idc[i]" );
     1163      WRITE_CODE( info->getAvgPicRate(i),         16, "avg_pic_rate[i]"          );
     1164    }
     1165  }
     1166}
     1167#endif 
    11711168/**
    11721169 - write wavefront substreams sizes for the slice header.
     
    11761173Void  TEncCavlc::codeTilesWPPEntryPoint( TComSlice* pSlice )
    11771174{
    1178 #if TILES_WPP_ENTROPYSLICES_FLAGS
    11791175  if (!pSlice->getPPS()->getTilesEnabledFlag() && !pSlice->getPPS()->getEntropyCodingSyncEnabledFlag())
    1180 #else
    1181   Int tilesOrEntropyCodingSyncIdc = pSlice->getPPS()->getTilesOrEntropyCodingSyncIdc();
    1182   if ( tilesOrEntropyCodingSyncIdc == 0 )
    1183 #endif
    11841176  {
    11851177    return;
     
    11881180  Int  numZeroSubstreamsAtStartOfSlice  = 0;
    11891181  UInt *entryPointOffset = NULL;
    1190 #if TILES_WPP_ENTROPYSLICES_FLAGS
    11911182  if ( pSlice->getPPS()->getTilesEnabledFlag() )
    1192 #else
    1193   if (tilesOrEntropyCodingSyncIdc == 1) // tiles
    1194 #endif
    11951183  {
    11961184    numEntryPointOffsets = pSlice->getTileLocationCount();
     
    12131201    }
    12141202  }
    1215 #if TILES_WPP_ENTROPYSLICES_FLAGS
    12161203  else if ( pSlice->getPPS()->getEntropyCodingSyncEnabledFlag() )
    1217 #else
    1218   else if (tilesOrEntropyCodingSyncIdc == 2) // wavefront
    1219 #endif
    12201204  {
    12211205    UInt* pSubstreamSizes               = pSlice->getSubstreamSizes();
    12221206    Int maxNumParts                       = pSlice->getPic()->getNumPartInCU();
    1223 #if DEPENDENT_SLICES
    1224     numZeroSubstreamsAtStartOfSlice       = pSlice->getDependentSliceCurStartCUAddr()/maxNumParts/pSlice->getPic()->getFrameWidthInCU();
    1225     Int  numZeroSubstreamsAtEndOfSlice    = pSlice->getPic()->getFrameHeightInCU()-1 - ((pSlice->getDependentSliceCurEndCUAddr()-1)/maxNumParts/pSlice->getPic()->getFrameWidthInCU());
    1226 #else
    1227     numZeroSubstreamsAtStartOfSlice       = pSlice->getSliceCurStartCUAddr()/maxNumParts/pSlice->getPic()->getFrameWidthInCU();
    1228     Int  numZeroSubstreamsAtEndOfSlice    = pSlice->getPic()->getFrameHeightInCU()-1 - ((pSlice->getSliceCurEndCUAddr()-1)/maxNumParts/pSlice->getPic()->getFrameWidthInCU());
    1229 #endif
     1207    numZeroSubstreamsAtStartOfSlice       = pSlice->getSliceSegmentCurStartCUAddr()/maxNumParts/pSlice->getPic()->getFrameWidthInCU();
     1208    Int  numZeroSubstreamsAtEndOfSlice    = pSlice->getPic()->getFrameHeightInCU()-1 - ((pSlice->getSliceSegmentCurEndCUAddr()-1)/maxNumParts/pSlice->getPic()->getFrameWidthInCU());
    12301209    numEntryPointOffsets                  = pSlice->getPPS()->getNumSubstreams() - numZeroSubstreamsAtStartOfSlice - numZeroSubstreamsAtEndOfSlice - 1;
    12311210    pSlice->setNumEntryPointOffsets(numEntryPointOffsets);
     
    12561235  for (UInt idx=0; idx<numEntryPointOffsets; idx++)
    12571236  {
     1237#if L0116_ENTRY_POINT
     1238    WRITE_CODE(entryPointOffset[ idx ]-1, offsetLenMinus1+1, "entry_point_offset_minus1");
     1239#else
    12581240    WRITE_CODE(entryPointOffset[ idx ], offsetLenMinus1+1, "entry_point_offset");
     1241#endif
    12591242  }
    12601243
     
    12951278}
    12961279
    1297 Void TEncCavlc::codeApsExtensionFlag ()
    1298 {
    1299   WRITE_FLAG(0, "aps_extension_flag");
    1300 }
    1301 
    13021280Void TEncCavlc::codeInterModeFlag( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, UInt uiEncMode )
    13031281{
     
    13151293}
    13161294
    1317 #if INTRA_BL
    1318 Void TEncCavlc::codeIntraBLFlag( TComDataCU* pcCU, UInt uiAbsPartIdx )
    1319 {
    1320   assert(0);
    1321 }
    1322 
    1323 #endif
    13241295Void TEncCavlc::codeSplitFlag   ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
    13251296{
     
    13421313}
    13431314
    1344 #if TU_ZERO_CBF_RDO
    1345 Void TEncCavlc::codeQtCbfZero( TComDataCU* pcCU, UInt uiAbsPartIdx, TextType eType, UInt uiTrDepth )
    1346 {
    1347   assert(0);
    1348 }
    1349 Void TEncCavlc::codeQtRootCbfZero( TComDataCU* pcCU, UInt uiAbsPartIdx )
    1350 {
    1351   assert(0);
    1352 }
    1353 #endif
    1354 
    1355 Void TEncCavlc::codeTransformSkipFlags (TComDataCU* pcCU, UInt uiAbsPartIdx, UInt width, UInt height, UInt uiDepth, TextType eTType )
    1356 {
    1357   assert(0);
    1358 }
    1359 
    1360 /** Code I_PCM information.
     1315Void TEncCavlc::codeQtCbfZero( TComDataCU* pcCU, TextType eType, UInt uiTrDepth )
     1316{
     1317  assert(0);
     1318}
     1319Void TEncCavlc::codeQtRootCbfZero( TComDataCU* pcCU )
     1320{
     1321  assert(0);
     1322}
     1323
     1324Void TEncCavlc::codeTransformSkipFlags (TComDataCU* pcCU, UInt uiAbsPartIdx, UInt width, UInt height, TextType eTType )
     1325{
     1326  assert(0);
     1327}
     1328
     1329/** Code I_PCM information.
    13611330 * \param pcCU pointer to CU
    13621331 * \param uiAbsPartIdx CU index
    1363  * \param numIPCM the number of succesive IPCM blocks with the same size
    1364  * \param firstIPCMFlag
    13651332 * \returns Void
    13661333 */
    1367 Void TEncCavlc::codeIPCMInfo( TComDataCU* pcCU, UInt uiAbsPartIdx, Int numIPCM, Bool firstIPCMFlag)
     1334Void TEncCavlc::codeIPCMInfo( TComDataCU* pcCU, UInt uiAbsPartIdx )
    13681335{
    13691336  assert(0);
     
    14111378  assert(0);
    14121379}
    1413 
    1414 Void TEncCavlc::xGolombEncode(Int coeff, Int k)
    1415 {
    1416   xWriteEpExGolomb((UInt)abs(coeff), k);
    1417   if(coeff != 0)
    1418   {
    1419     Int sign = (coeff > 0)? 1: 0;
    1420     xWriteFlag(sign);
    1421   }
    1422 #if ENC_DEC_TRACE
    1423   fprintf( g_hTrace, "%8lld  ", g_nSymbolCounter++ );
    1424   fprintf( g_hTrace, "%-40s se(v) : %d\n", "alf_filt_coeff", coeff );
    1425 #endif
    1426 
    1427 }
    1428 
    1429 #if !REMOVE_ALF
    1430 Void TEncCavlc::codeAlfParam(ALFParam* alfParam)
    1431 {
    1432   char syntaxString[50];
    1433   sprintf(syntaxString, "alf_aps_filter_flag[%d]", alfParam->componentID);
    1434   WRITE_FLAG(alfParam->alf_flag, syntaxString);
    1435   if(alfParam->alf_flag == 0)
    1436   {
    1437     return;
    1438   }
    1439 
    1440   const Int numCoeff = (Int)ALF_MAX_NUM_COEF;
    1441   switch(alfParam->componentID)
    1442   {
    1443   case ALF_Cb:
    1444   case ALF_Cr:
    1445     {
    1446       for(Int pos=0; pos< numCoeff; pos++)
    1447       {
    1448         WRITE_SVLC(alfParam->coeffmulti[0][pos], "alf_filt_coeff");
    1449       }
    1450     }
    1451     break;
    1452   case ALF_Y:
    1453     {
    1454       Int noFilters = min(alfParam->filters_per_group-1, 2);
    1455       WRITE_UVLC(noFilters, "alf_no_filters_minus1");
    1456       if(noFilters == 1)
    1457       {
    1458         WRITE_UVLC(alfParam->startSecondFilter, "alf_start_second_filter");
    1459       }
    1460       else if (noFilters == 2)
    1461       {
    1462         Int numMergeFlags = 16;
    1463         for (Int i=1; i<numMergeFlags; i++)
    1464         {
    1465           WRITE_FLAG(alfParam->filterPattern[i], "alf_filter_pattern");
    1466         }
    1467       }
    1468       for(Int f=0; f< alfParam->filters_per_group; f++)
    1469       {
    1470         for(Int pos=0; pos< numCoeff; pos++)
    1471         {
    1472           xGolombEncode(alfParam->coeffmulti[f][pos], kTableTabShapes[ALF_CROSS9x7_SQUARE3x3][pos]);
    1473         }
    1474       }
    1475     }
    1476     break;
    1477   default:
    1478     {
    1479       printf("Not a legal component ID\n");
    1480       assert(0);
    1481       exit(-1);
    1482     }
    1483   }
    1484 
    1485 }
    1486 #endif
    14871380
    14881381Void TEncCavlc::estBit( estBitsSbacStruct* pcEstBitsCabac, Int width, Int height, TextType eTType )
     
    15851478  Bool            bDenomCoded  = false;
    15861479  UInt            uiMode = 0;
    1587 #if NUM_WP_LIMIT
    15881480  UInt            uiTotalSignalledWeightFlags = 0;
    1589 #endif
    15901481  if ( (pcSlice->getSliceType()==P_SLICE && pcSlice->getPPS()->getUseWP()) || (pcSlice->getSliceType()==B_SLICE && pcSlice->getPPS()->getWPBiPred()) )
    15911482  {
     
    16151506        }
    16161507        WRITE_FLAG( wp[0].bPresentFlag, "luma_weight_lX_flag" );               // u(1): luma_weight_lX_flag
    1617 #if NUM_WP_LIMIT
    16181508        uiTotalSignalledWeightFlags += wp[0].bPresentFlag;
    16191509      }
     
    16311521      {
    16321522        pcSlice->getWpScaling(eRefPicList, iRefIdx, wp);
    1633 #endif
    16341523        if ( wp[0].bPresentFlag )
    16351524        {
     
    16411530        if ( bChroma )
    16421531        {
    1643 #if !NUM_WP_LIMIT
    1644           WRITE_FLAG( wp[1].bPresentFlag, "chroma_weight_lX_flag" );           // u(1): chroma_weight_lX_flag
    1645 #endif
    16461532          if ( wp[1].bPresentFlag )
    16471533          {
     
    16511537              WRITE_SVLC( iDeltaWeight, "delta_chroma_weight_lX" );            // se(v): delta_chroma_weight_lX
    16521538
    1653               Int shift = ((1<<(g_uiBitDepth+g_uiBitIncrement-1)));
    1654               Int pred = ( shift - ( ( shift*wp[j].iWeight)>>(wp[j].uiLog2WeightDenom) ) );
     1539              Int pred = ( 128 - ( ( 128*wp[j].iWeight)>>(wp[j].uiLog2WeightDenom) ) );
    16551540              Int iDeltaChroma = (wp[j].iOffset - pred);
    16561541              WRITE_SVLC( iDeltaChroma, "delta_chroma_offset_lX" );            // se(v): delta_chroma_offset_lX
     
    16601545      }
    16611546    }
    1662 #if NUM_WP_LIMIT
    16631547    assert(uiTotalSignalledWeightFlags<=24);
    1664 #endif
    16651548  }
    16661549}
     
    17171600{
    17181601  Int coefNum = min(MAX_MATRIX_COEF_NUM,(Int)g_scalingListSize[sizeId]);
    1719 #if REMOVE_ZIGZAG_SCAN
    17201602  UInt* scan  = (sizeId == 0) ? g_auiSigLastScan [ SCAN_DIAG ] [ 1 ] :  g_sigLastScanCG32x32;
    1721 #else
    1722   UInt* scan    = g_auiFrameScanXY [ (sizeId == 0)? 1 : 2];
    1723 #endif
    17241603  Int nextCoef = SCALING_LIST_START_VALUE;
    17251604  Int data;
     
    17461625    }
    17471626}
    1748 #if LTRP_IN_SPS
    17491627Bool TEncCavlc::findMatchingLTRP ( TComSlice* pcSlice, UInt *ltrpsIndex, Int ltrpPOC, Bool usedFlag )
    17501628{
    1751   // bool state = true, state2 = false;
     1629  // Bool state = true, state2 = false;
    17521630  Int lsb = ltrpPOC % (1<<pcSlice->getSPS()->getBitsForPOC());
    17531631  for (Int k = 0; k < pcSlice->getSPS()->getNumLongTermRefPicSPS(); k++)
     
    17611639  return false;
    17621640}
    1763 #endif
    17641641Bool TComScalingList::checkPredMode(UInt sizeId, UInt listId)
    17651642{
     
    17761653  return true;
    17771654}
     1655
     1656#if INTRA_BL
     1657Void TEncCavlc::codeIntraBLFlag( TComDataCU* pcCU, UInt uiAbsPartIdx )
     1658{
     1659  assert(0);
     1660}
     1661
     1662#endif
    17781663//! \}
Note: See TracChangeset for help on using the changeset viewer.