[313] | 1 | /* The copyright in this software is being made available under the BSD |
---|
| 2 | * License, included below. This software may be subject to other third party |
---|
| 3 | * and contributor rights, including patent rights, and no such rights are |
---|
| 4 | * granted under this license. |
---|
| 5 | * |
---|
| 6 | * Copyright (c) 2010-2013, ITU/ISO/IEC |
---|
| 7 | * All rights reserved. |
---|
| 8 | * |
---|
| 9 | * Redistribution and use in source and binary forms, with or without |
---|
| 10 | * modification, are permitted provided that the following conditions are met: |
---|
| 11 | * |
---|
| 12 | * * Redistributions of source code must retain the above copyright notice, |
---|
| 13 | * this list of conditions and the following disclaimer. |
---|
| 14 | * * Redistributions in binary form must reproduce the above copyright notice, |
---|
| 15 | * this list of conditions and the following disclaimer in the documentation |
---|
| 16 | * and/or other materials provided with the distribution. |
---|
| 17 | * * Neither the name of the ITU/ISO/IEC nor the names of its contributors may |
---|
| 18 | * be used to endorse or promote products derived from this software without |
---|
| 19 | * specific prior written permission. |
---|
| 20 | * |
---|
| 21 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
---|
| 22 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
---|
| 23 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
---|
| 24 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS |
---|
| 25 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
---|
| 26 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
---|
| 27 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
---|
| 28 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
---|
| 29 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
---|
| 30 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF |
---|
| 31 | * THE POSSIBILITY OF SUCH DAMAGE. |
---|
| 32 | */ |
---|
| 33 | |
---|
| 34 | /** \file TEncCavlc.cpp |
---|
| 35 | \brief CAVLC encoder class |
---|
| 36 | */ |
---|
| 37 | |
---|
| 38 | #include "../TLibCommon/CommonDef.h" |
---|
| 39 | #include "TEncCavlc.h" |
---|
| 40 | #include "SEIwrite.h" |
---|
| 41 | |
---|
| 42 | //! \ingroup TLibEncoder |
---|
| 43 | //! \{ |
---|
| 44 | |
---|
| 45 | #if ENC_DEC_TRACE |
---|
| 46 | |
---|
| 47 | Void xTraceSPSHeader (TComSPS *pSPS) |
---|
| 48 | { |
---|
| 49 | fprintf( g_hTrace, "=========== Sequence Parameter Set ID: %d ===========\n", pSPS->getSPSId() ); |
---|
| 50 | } |
---|
| 51 | |
---|
| 52 | Void xTracePPSHeader (TComPPS *pPPS) |
---|
| 53 | { |
---|
| 54 | fprintf( g_hTrace, "=========== Picture Parameter Set ID: %d ===========\n", pPPS->getPPSId() ); |
---|
| 55 | } |
---|
| 56 | |
---|
| 57 | Void xTraceSliceHeader (TComSlice *pSlice) |
---|
| 58 | { |
---|
| 59 | fprintf( g_hTrace, "=========== Slice ===========\n"); |
---|
| 60 | } |
---|
| 61 | |
---|
| 62 | #endif |
---|
| 63 | |
---|
| 64 | |
---|
| 65 | |
---|
| 66 | // ==================================================================================================================== |
---|
| 67 | // Constructor / destructor / create / destroy |
---|
| 68 | // ==================================================================================================================== |
---|
| 69 | |
---|
| 70 | TEncCavlc::TEncCavlc() |
---|
| 71 | { |
---|
| 72 | m_pcBitIf = NULL; |
---|
| 73 | m_uiCoeffCost = 0; |
---|
| 74 | } |
---|
| 75 | |
---|
| 76 | TEncCavlc::~TEncCavlc() |
---|
| 77 | { |
---|
| 78 | } |
---|
| 79 | |
---|
| 80 | |
---|
| 81 | // ==================================================================================================================== |
---|
| 82 | // Public member functions |
---|
| 83 | // ==================================================================================================================== |
---|
| 84 | |
---|
| 85 | Void TEncCavlc::resetEntropy() |
---|
| 86 | { |
---|
| 87 | } |
---|
| 88 | |
---|
| 89 | |
---|
| 90 | Void TEncCavlc::codeDFFlag(UInt uiCode, const Char *pSymbolName) |
---|
| 91 | { |
---|
| 92 | WRITE_FLAG(uiCode, pSymbolName); |
---|
| 93 | } |
---|
| 94 | Void TEncCavlc::codeDFSvlc(Int iCode, const Char *pSymbolName) |
---|
| 95 | { |
---|
| 96 | WRITE_SVLC(iCode, pSymbolName); |
---|
| 97 | } |
---|
| 98 | |
---|
| 99 | Void TEncCavlc::codeShortTermRefPicSet( TComSPS* pcSPS, TComReferencePictureSet* rps, Bool calledFromSliceHeader, Int idx) |
---|
| 100 | { |
---|
| 101 | #if PRINT_RPS_INFO |
---|
| 102 | Int lastBits = getNumberOfWrittenBits(); |
---|
| 103 | #endif |
---|
| 104 | if (idx > 0) |
---|
| 105 | { |
---|
| 106 | WRITE_FLAG( rps->getInterRPSPrediction(), "inter_ref_pic_set_prediction_flag" ); // inter_RPS_prediction_flag |
---|
| 107 | } |
---|
| 108 | if (rps->getInterRPSPrediction()) |
---|
| 109 | { |
---|
| 110 | Int deltaRPS = rps->getDeltaRPS(); |
---|
| 111 | if(calledFromSliceHeader) |
---|
| 112 | { |
---|
| 113 | WRITE_UVLC( rps->getDeltaRIdxMinus1(), "delta_idx_minus1" ); // delta index of the Reference Picture Set used for prediction minus 1 |
---|
| 114 | } |
---|
| 115 | |
---|
| 116 | WRITE_CODE( (deltaRPS >=0 ? 0: 1), 1, "delta_rps_sign" ); //delta_rps_sign |
---|
| 117 | WRITE_UVLC( abs(deltaRPS) - 1, "abs_delta_rps_minus1"); // absolute delta RPS minus 1 |
---|
| 118 | |
---|
| 119 | for(Int j=0; j < rps->getNumRefIdc(); j++) |
---|
| 120 | { |
---|
| 121 | Int refIdc = rps->getRefIdc(j); |
---|
| 122 | WRITE_CODE( (refIdc==1? 1: 0), 1, "used_by_curr_pic_flag" ); //first bit is "1" if Idc is 1 |
---|
| 123 | if (refIdc != 1) |
---|
| 124 | { |
---|
| 125 | WRITE_CODE( refIdc>>1, 1, "use_delta_flag" ); //second bit is "1" if Idc is 2, "0" otherwise. |
---|
| 126 | } |
---|
| 127 | } |
---|
| 128 | } |
---|
| 129 | else |
---|
| 130 | { |
---|
| 131 | WRITE_UVLC( rps->getNumberOfNegativePictures(), "num_negative_pics" ); |
---|
| 132 | WRITE_UVLC( rps->getNumberOfPositivePictures(), "num_positive_pics" ); |
---|
| 133 | Int prev = 0; |
---|
| 134 | for(Int j=0 ; j < rps->getNumberOfNegativePictures(); j++) |
---|
| 135 | { |
---|
| 136 | WRITE_UVLC( prev-rps->getDeltaPOC(j)-1, "delta_poc_s0_minus1" ); |
---|
| 137 | prev = rps->getDeltaPOC(j); |
---|
| 138 | WRITE_FLAG( rps->getUsed(j), "used_by_curr_pic_s0_flag"); |
---|
| 139 | } |
---|
| 140 | prev = 0; |
---|
| 141 | for(Int j=rps->getNumberOfNegativePictures(); j < rps->getNumberOfNegativePictures()+rps->getNumberOfPositivePictures(); j++) |
---|
| 142 | { |
---|
| 143 | WRITE_UVLC( rps->getDeltaPOC(j)-prev-1, "delta_poc_s1_minus1" ); |
---|
| 144 | prev = rps->getDeltaPOC(j); |
---|
| 145 | WRITE_FLAG( rps->getUsed(j), "used_by_curr_pic_s1_flag" ); |
---|
| 146 | } |
---|
| 147 | } |
---|
| 148 | |
---|
| 149 | #if PRINT_RPS_INFO |
---|
| 150 | printf("irps=%d (%2d bits) ", rps->getInterRPSPrediction(), getNumberOfWrittenBits() - lastBits); |
---|
| 151 | rps->printDeltaPOC(); |
---|
| 152 | #endif |
---|
| 153 | } |
---|
| 154 | |
---|
| 155 | |
---|
| 156 | Void TEncCavlc::codePPS( TComPPS* pcPPS ) |
---|
| 157 | { |
---|
| 158 | #if ENC_DEC_TRACE |
---|
| 159 | xTracePPSHeader (pcPPS); |
---|
| 160 | #endif |
---|
| 161 | |
---|
| 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 | WRITE_FLAG( pcPPS->getOutputFlagPresentFlag() ? 1 : 0, "output_flag_present_flag" ); |
---|
| 166 | WRITE_CODE( pcPPS->getNumExtraSliceHeaderBits(), 3, "num_extra_slice_header_bits"); |
---|
| 167 | WRITE_FLAG( pcPPS->getSignHideFlag(), "sign_data_hiding_flag" ); |
---|
| 168 | WRITE_FLAG( pcPPS->getCabacInitPresentFlag() ? 1 : 0, "cabac_init_present_flag" ); |
---|
| 169 | WRITE_UVLC( pcPPS->getNumRefIdxL0DefaultActive()-1, "num_ref_idx_l0_default_active_minus1"); |
---|
| 170 | WRITE_UVLC( pcPPS->getNumRefIdxL1DefaultActive()-1, "num_ref_idx_l1_default_active_minus1"); |
---|
| 171 | |
---|
| 172 | WRITE_SVLC( pcPPS->getPicInitQPMinus26(), "init_qp_minus26"); |
---|
| 173 | WRITE_FLAG( pcPPS->getConstrainedIntraPred() ? 1 : 0, "constrained_intra_pred_flag" ); |
---|
| 174 | WRITE_FLAG( pcPPS->getUseTransformSkip() ? 1 : 0, "transform_skip_enabled_flag" ); |
---|
| 175 | WRITE_FLAG( pcPPS->getUseDQP() ? 1 : 0, "cu_qp_delta_enabled_flag" ); |
---|
| 176 | if ( pcPPS->getUseDQP() ) |
---|
| 177 | { |
---|
| 178 | WRITE_UVLC( pcPPS->getMaxCuDQPDepth(), "diff_cu_qp_delta_depth" ); |
---|
| 179 | } |
---|
| 180 | WRITE_SVLC( pcPPS->getChromaCbQpOffset(), "pps_cb_qp_offset" ); |
---|
| 181 | WRITE_SVLC( pcPPS->getChromaCrQpOffset(), "pps_cr_qp_offset" ); |
---|
| 182 | WRITE_FLAG( pcPPS->getSliceChromaQpFlag() ? 1 : 0, "pps_slice_chroma_qp_offsets_present_flag" ); |
---|
| 183 | |
---|
| 184 | WRITE_FLAG( pcPPS->getUseWP() ? 1 : 0, "weighted_pred_flag" ); // Use of Weighting Prediction (P_SLICE) |
---|
| 185 | WRITE_FLAG( pcPPS->getWPBiPred() ? 1 : 0, "weighted_bipred_flag" ); // Use of Weighting Bi-Prediction (B_SLICE) |
---|
| 186 | WRITE_FLAG( pcPPS->getTransquantBypassEnableFlag() ? 1 : 0, "transquant_bypass_enable_flag" ); |
---|
| 187 | WRITE_FLAG( pcPPS->getTilesEnabledFlag() ? 1 : 0, "tiles_enabled_flag" ); |
---|
| 188 | WRITE_FLAG( pcPPS->getEntropyCodingSyncEnabledFlag() ? 1 : 0, "entropy_coding_sync_enabled_flag" ); |
---|
| 189 | if( pcPPS->getTilesEnabledFlag() ) |
---|
| 190 | { |
---|
| 191 | WRITE_UVLC( pcPPS->getNumColumnsMinus1(), "num_tile_columns_minus1" ); |
---|
| 192 | WRITE_UVLC( pcPPS->getNumRowsMinus1(), "num_tile_rows_minus1" ); |
---|
| 193 | WRITE_FLAG( pcPPS->getUniformSpacingFlag(), "uniform_spacing_flag" ); |
---|
| 194 | if( pcPPS->getUniformSpacingFlag() == 0 ) |
---|
| 195 | { |
---|
| 196 | for(UInt i=0; i<pcPPS->getNumColumnsMinus1(); i++) |
---|
| 197 | { |
---|
| 198 | WRITE_UVLC( pcPPS->getColumnWidth(i)-1, "column_width_minus1" ); |
---|
| 199 | } |
---|
| 200 | for(UInt i=0; i<pcPPS->getNumRowsMinus1(); i++) |
---|
| 201 | { |
---|
| 202 | WRITE_UVLC( pcPPS->getRowHeight(i)-1, "row_height_minus1" ); |
---|
| 203 | } |
---|
| 204 | } |
---|
| 205 | if(pcPPS->getNumColumnsMinus1() !=0 || pcPPS->getNumRowsMinus1() !=0) |
---|
| 206 | { |
---|
| 207 | WRITE_FLAG( pcPPS->getLoopFilterAcrossTilesEnabledFlag()?1 : 0, "loop_filter_across_tiles_enabled_flag"); |
---|
| 208 | } |
---|
| 209 | } |
---|
| 210 | WRITE_FLAG( pcPPS->getLoopFilterAcrossSlicesEnabledFlag()?1 : 0, "loop_filter_across_slices_enabled_flag"); |
---|
| 211 | WRITE_FLAG( pcPPS->getDeblockingFilterControlPresentFlag()?1 : 0, "deblocking_filter_control_present_flag"); |
---|
| 212 | if(pcPPS->getDeblockingFilterControlPresentFlag()) |
---|
| 213 | { |
---|
| 214 | WRITE_FLAG( pcPPS->getDeblockingFilterOverrideEnabledFlag() ? 1 : 0, "deblocking_filter_override_enabled_flag" ); |
---|
| 215 | WRITE_FLAG( pcPPS->getPicDisableDeblockingFilterFlag() ? 1 : 0, "pps_disable_deblocking_filter_flag" ); |
---|
| 216 | if(!pcPPS->getPicDisableDeblockingFilterFlag()) |
---|
| 217 | { |
---|
| 218 | WRITE_SVLC( pcPPS->getDeblockingFilterBetaOffsetDiv2(), "pps_beta_offset_div2" ); |
---|
| 219 | WRITE_SVLC( pcPPS->getDeblockingFilterTcOffsetDiv2(), "pps_tc_offset_div2" ); |
---|
| 220 | } |
---|
| 221 | } |
---|
[528] | 222 | |
---|
| 223 | #if SCALINGLIST_INFERRING |
---|
| 224 | if( pcPPS->getLayerId() > 0 ) |
---|
| 225 | { |
---|
| 226 | WRITE_FLAG( pcPPS->getInferScalingListFlag() ? 1 : 0, "pps_infer_scaling_list_flag" ); |
---|
| 227 | } |
---|
| 228 | |
---|
| 229 | if( pcPPS->getInferScalingListFlag() ) |
---|
| 230 | { |
---|
| 231 | // The value of pps_scaling_list_ref_layer_id shall be in the range of 0 to 62, inclusive |
---|
| 232 | assert( pcPPS->getScalingListRefLayerId() <= 62 ); |
---|
| 233 | |
---|
| 234 | WRITE_UVLC( pcPPS->getScalingListRefLayerId(), "pps_scaling_list_ref_layer_id" ); |
---|
| 235 | } |
---|
| 236 | else |
---|
| 237 | { |
---|
| 238 | #endif |
---|
| 239 | |
---|
[313] | 240 | WRITE_FLAG( pcPPS->getScalingListPresentFlag() ? 1 : 0, "pps_scaling_list_data_present_flag" ); |
---|
| 241 | if( pcPPS->getScalingListPresentFlag() ) |
---|
| 242 | { |
---|
| 243 | codeScalingList( m_pcSlice->getScalingList() ); |
---|
[528] | 244 | } |
---|
[442] | 245 | |
---|
[528] | 246 | #if SCALINGLIST_INFERRING |
---|
[313] | 247 | } |
---|
[528] | 248 | #endif |
---|
| 249 | |
---|
[313] | 250 | WRITE_FLAG( pcPPS->getListsModificationPresentFlag(), "lists_modification_present_flag"); |
---|
| 251 | WRITE_UVLC( pcPPS->getLog2ParallelMergeLevelMinus2(), "log2_parallel_merge_level_minus2"); |
---|
| 252 | WRITE_FLAG( pcPPS->getSliceHeaderExtensionPresentFlag() ? 1 : 0, "slice_segment_header_extension_present_flag"); |
---|
| 253 | WRITE_FLAG( 0, "pps_extension_flag" ); |
---|
| 254 | } |
---|
| 255 | |
---|
| 256 | Void TEncCavlc::codeVUI( TComVUI *pcVUI, TComSPS* pcSPS ) |
---|
| 257 | { |
---|
| 258 | #if ENC_DEC_TRACE |
---|
| 259 | fprintf( g_hTrace, "----------- vui_parameters -----------\n"); |
---|
| 260 | #endif |
---|
| 261 | WRITE_FLAG(pcVUI->getAspectRatioInfoPresentFlag(), "aspect_ratio_info_present_flag"); |
---|
| 262 | if (pcVUI->getAspectRatioInfoPresentFlag()) |
---|
| 263 | { |
---|
| 264 | WRITE_CODE(pcVUI->getAspectRatioIdc(), 8, "aspect_ratio_idc" ); |
---|
| 265 | if (pcVUI->getAspectRatioIdc() == 255) |
---|
| 266 | { |
---|
| 267 | WRITE_CODE(pcVUI->getSarWidth(), 16, "sar_width"); |
---|
| 268 | WRITE_CODE(pcVUI->getSarHeight(), 16, "sar_height"); |
---|
| 269 | } |
---|
| 270 | } |
---|
| 271 | WRITE_FLAG(pcVUI->getOverscanInfoPresentFlag(), "overscan_info_present_flag"); |
---|
| 272 | if (pcVUI->getOverscanInfoPresentFlag()) |
---|
| 273 | { |
---|
| 274 | WRITE_FLAG(pcVUI->getOverscanAppropriateFlag(), "overscan_appropriate_flag"); |
---|
| 275 | } |
---|
| 276 | WRITE_FLAG(pcVUI->getVideoSignalTypePresentFlag(), "video_signal_type_present_flag"); |
---|
| 277 | if (pcVUI->getVideoSignalTypePresentFlag()) |
---|
| 278 | { |
---|
| 279 | WRITE_CODE(pcVUI->getVideoFormat(), 3, "video_format"); |
---|
| 280 | WRITE_FLAG(pcVUI->getVideoFullRangeFlag(), "video_full_range_flag"); |
---|
| 281 | WRITE_FLAG(pcVUI->getColourDescriptionPresentFlag(), "colour_description_present_flag"); |
---|
| 282 | if (pcVUI->getColourDescriptionPresentFlag()) |
---|
| 283 | { |
---|
| 284 | WRITE_CODE(pcVUI->getColourPrimaries(), 8, "colour_primaries"); |
---|
| 285 | WRITE_CODE(pcVUI->getTransferCharacteristics(), 8, "transfer_characteristics"); |
---|
| 286 | WRITE_CODE(pcVUI->getMatrixCoefficients(), 8, "matrix_coefficients"); |
---|
| 287 | } |
---|
| 288 | } |
---|
| 289 | |
---|
| 290 | WRITE_FLAG(pcVUI->getChromaLocInfoPresentFlag(), "chroma_loc_info_present_flag"); |
---|
| 291 | if (pcVUI->getChromaLocInfoPresentFlag()) |
---|
| 292 | { |
---|
| 293 | WRITE_UVLC(pcVUI->getChromaSampleLocTypeTopField(), "chroma_sample_loc_type_top_field"); |
---|
| 294 | WRITE_UVLC(pcVUI->getChromaSampleLocTypeBottomField(), "chroma_sample_loc_type_bottom_field"); |
---|
| 295 | } |
---|
| 296 | |
---|
| 297 | WRITE_FLAG(pcVUI->getNeutralChromaIndicationFlag(), "neutral_chroma_indication_flag"); |
---|
| 298 | WRITE_FLAG(pcVUI->getFieldSeqFlag(), "field_seq_flag"); |
---|
| 299 | WRITE_FLAG(pcVUI->getFrameFieldInfoPresentFlag(), "frame_field_info_present_flag"); |
---|
| 300 | |
---|
| 301 | Window defaultDisplayWindow = pcVUI->getDefaultDisplayWindow(); |
---|
| 302 | WRITE_FLAG(defaultDisplayWindow.getWindowEnabledFlag(), "default_display_window_flag"); |
---|
| 303 | if( defaultDisplayWindow.getWindowEnabledFlag() ) |
---|
| 304 | { |
---|
| 305 | WRITE_UVLC(defaultDisplayWindow.getWindowLeftOffset(), "def_disp_win_left_offset"); |
---|
| 306 | WRITE_UVLC(defaultDisplayWindow.getWindowRightOffset(), "def_disp_win_right_offset"); |
---|
| 307 | WRITE_UVLC(defaultDisplayWindow.getWindowTopOffset(), "def_disp_win_top_offset"); |
---|
| 308 | WRITE_UVLC(defaultDisplayWindow.getWindowBottomOffset(), "def_disp_win_bottom_offset"); |
---|
| 309 | } |
---|
| 310 | TimingInfo *timingInfo = pcVUI->getTimingInfo(); |
---|
| 311 | WRITE_FLAG(timingInfo->getTimingInfoPresentFlag(), "vui_timing_info_present_flag"); |
---|
| 312 | if(timingInfo->getTimingInfoPresentFlag()) |
---|
| 313 | { |
---|
| 314 | WRITE_CODE(timingInfo->getNumUnitsInTick(), 32, "vui_num_units_in_tick"); |
---|
| 315 | WRITE_CODE(timingInfo->getTimeScale(), 32, "vui_time_scale"); |
---|
| 316 | WRITE_FLAG(timingInfo->getPocProportionalToTimingFlag(), "vui_poc_proportional_to_timing_flag"); |
---|
| 317 | if(timingInfo->getPocProportionalToTimingFlag()) |
---|
| 318 | { |
---|
| 319 | WRITE_UVLC(timingInfo->getNumTicksPocDiffOneMinus1(), "vui_num_ticks_poc_diff_one_minus1"); |
---|
| 320 | } |
---|
| 321 | WRITE_FLAG(pcVUI->getHrdParametersPresentFlag(), "hrd_parameters_present_flag"); |
---|
| 322 | if( pcVUI->getHrdParametersPresentFlag() ) |
---|
| 323 | { |
---|
| 324 | codeHrdParameters(pcVUI->getHrdParameters(), 1, pcSPS->getMaxTLayers() - 1 ); |
---|
| 325 | } |
---|
| 326 | } |
---|
| 327 | |
---|
| 328 | WRITE_FLAG(pcVUI->getBitstreamRestrictionFlag(), "bitstream_restriction_flag"); |
---|
| 329 | if (pcVUI->getBitstreamRestrictionFlag()) |
---|
| 330 | { |
---|
| 331 | WRITE_FLAG(pcVUI->getTilesFixedStructureFlag(), "tiles_fixed_structure_flag"); |
---|
| 332 | WRITE_FLAG(pcVUI->getMotionVectorsOverPicBoundariesFlag(), "motion_vectors_over_pic_boundaries_flag"); |
---|
| 333 | WRITE_FLAG(pcVUI->getRestrictedRefPicListsFlag(), "restricted_ref_pic_lists_flag"); |
---|
| 334 | WRITE_UVLC(pcVUI->getMinSpatialSegmentationIdc(), "min_spatial_segmentation_idc"); |
---|
| 335 | WRITE_UVLC(pcVUI->getMaxBytesPerPicDenom(), "max_bytes_per_pic_denom"); |
---|
| 336 | WRITE_UVLC(pcVUI->getMaxBitsPerMinCuDenom(), "max_bits_per_mincu_denom"); |
---|
| 337 | WRITE_UVLC(pcVUI->getLog2MaxMvLengthHorizontal(), "log2_max_mv_length_horizontal"); |
---|
| 338 | WRITE_UVLC(pcVUI->getLog2MaxMvLengthVertical(), "log2_max_mv_length_vertical"); |
---|
| 339 | } |
---|
| 340 | } |
---|
| 341 | |
---|
| 342 | Void TEncCavlc::codeHrdParameters( TComHRD *hrd, Bool commonInfPresentFlag, UInt maxNumSubLayersMinus1 ) |
---|
| 343 | { |
---|
| 344 | if( commonInfPresentFlag ) |
---|
| 345 | { |
---|
| 346 | WRITE_FLAG( hrd->getNalHrdParametersPresentFlag() ? 1 : 0 , "nal_hrd_parameters_present_flag" ); |
---|
| 347 | WRITE_FLAG( hrd->getVclHrdParametersPresentFlag() ? 1 : 0 , "vcl_hrd_parameters_present_flag" ); |
---|
| 348 | if( hrd->getNalHrdParametersPresentFlag() || hrd->getVclHrdParametersPresentFlag() ) |
---|
| 349 | { |
---|
| 350 | WRITE_FLAG( hrd->getSubPicCpbParamsPresentFlag() ? 1 : 0, "sub_pic_cpb_params_present_flag" ); |
---|
| 351 | if( hrd->getSubPicCpbParamsPresentFlag() ) |
---|
| 352 | { |
---|
| 353 | WRITE_CODE( hrd->getTickDivisorMinus2(), 8, "tick_divisor_minus2" ); |
---|
| 354 | WRITE_CODE( hrd->getDuCpbRemovalDelayLengthMinus1(), 5, "du_cpb_removal_delay_length_minus1" ); |
---|
| 355 | WRITE_FLAG( hrd->getSubPicCpbParamsInPicTimingSEIFlag() ? 1 : 0, "sub_pic_cpb_params_in_pic_timing_sei_flag" ); |
---|
| 356 | WRITE_CODE( hrd->getDpbOutputDelayDuLengthMinus1(), 5, "dpb_output_delay_du_length_minus1" ); |
---|
| 357 | } |
---|
| 358 | WRITE_CODE( hrd->getBitRateScale(), 4, "bit_rate_scale" ); |
---|
| 359 | WRITE_CODE( hrd->getCpbSizeScale(), 4, "cpb_size_scale" ); |
---|
| 360 | if( hrd->getSubPicCpbParamsPresentFlag() ) |
---|
| 361 | { |
---|
| 362 | WRITE_CODE( hrd->getDuCpbSizeScale(), 4, "du_cpb_size_scale" ); |
---|
| 363 | } |
---|
| 364 | WRITE_CODE( hrd->getInitialCpbRemovalDelayLengthMinus1(), 5, "initial_cpb_removal_delay_length_minus1" ); |
---|
| 365 | WRITE_CODE( hrd->getCpbRemovalDelayLengthMinus1(), 5, "au_cpb_removal_delay_length_minus1" ); |
---|
| 366 | WRITE_CODE( hrd->getDpbOutputDelayLengthMinus1(), 5, "dpb_output_delay_length_minus1" ); |
---|
| 367 | } |
---|
| 368 | } |
---|
| 369 | Int i, j, nalOrVcl; |
---|
| 370 | for( i = 0; i <= maxNumSubLayersMinus1; i ++ ) |
---|
| 371 | { |
---|
| 372 | WRITE_FLAG( hrd->getFixedPicRateFlag( i ) ? 1 : 0, "fixed_pic_rate_general_flag"); |
---|
| 373 | if( !hrd->getFixedPicRateFlag( i ) ) |
---|
| 374 | { |
---|
| 375 | WRITE_FLAG( hrd->getFixedPicRateWithinCvsFlag( i ) ? 1 : 0, "fixed_pic_rate_within_cvs_flag"); |
---|
| 376 | } |
---|
| 377 | else |
---|
| 378 | { |
---|
| 379 | hrd->setFixedPicRateWithinCvsFlag( i, true ); |
---|
| 380 | } |
---|
| 381 | if( hrd->getFixedPicRateWithinCvsFlag( i ) ) |
---|
| 382 | { |
---|
| 383 | WRITE_UVLC( hrd->getPicDurationInTcMinus1( i ), "elemental_duration_in_tc_minus1"); |
---|
| 384 | } |
---|
| 385 | else |
---|
| 386 | { |
---|
| 387 | WRITE_FLAG( hrd->getLowDelayHrdFlag( i ) ? 1 : 0, "low_delay_hrd_flag"); |
---|
| 388 | } |
---|
| 389 | if (!hrd->getLowDelayHrdFlag( i )) |
---|
| 390 | { |
---|
| 391 | WRITE_UVLC( hrd->getCpbCntMinus1( i ), "cpb_cnt_minus1"); |
---|
| 392 | } |
---|
| 393 | |
---|
| 394 | for( nalOrVcl = 0; nalOrVcl < 2; nalOrVcl ++ ) |
---|
| 395 | { |
---|
| 396 | if( ( ( nalOrVcl == 0 ) && ( hrd->getNalHrdParametersPresentFlag() ) ) || |
---|
| 397 | ( ( nalOrVcl == 1 ) && ( hrd->getVclHrdParametersPresentFlag() ) ) ) |
---|
| 398 | { |
---|
| 399 | for( j = 0; j <= ( hrd->getCpbCntMinus1( i ) ); j ++ ) |
---|
| 400 | { |
---|
| 401 | WRITE_UVLC( hrd->getBitRateValueMinus1( i, j, nalOrVcl ), "bit_rate_value_minus1"); |
---|
| 402 | WRITE_UVLC( hrd->getCpbSizeValueMinus1( i, j, nalOrVcl ), "cpb_size_value_minus1"); |
---|
| 403 | if( hrd->getSubPicCpbParamsPresentFlag() ) |
---|
| 404 | { |
---|
| 405 | WRITE_UVLC( hrd->getDuCpbSizeValueMinus1( i, j, nalOrVcl ), "cpb_size_du_value_minus1"); |
---|
| 406 | WRITE_UVLC( hrd->getDuBitRateValueMinus1( i, j, nalOrVcl ), "bit_rate_du_value_minus1"); |
---|
| 407 | } |
---|
| 408 | WRITE_FLAG( hrd->getCbrFlag( i, j, nalOrVcl ) ? 1 : 0, "cbr_flag"); |
---|
| 409 | } |
---|
| 410 | } |
---|
| 411 | } |
---|
| 412 | } |
---|
| 413 | } |
---|
| 414 | |
---|
| 415 | Void TEncCavlc::codeSPS( TComSPS* pcSPS ) |
---|
| 416 | { |
---|
| 417 | #if ENC_DEC_TRACE |
---|
| 418 | xTraceSPSHeader (pcSPS); |
---|
| 419 | #endif |
---|
| 420 | WRITE_CODE( pcSPS->getVPSId (), 4, "sps_video_parameter_set_id" ); |
---|
[494] | 421 | #if SVC_EXTENSION |
---|
[313] | 422 | if(pcSPS->getLayerId() == 0) |
---|
| 423 | { |
---|
| 424 | #endif |
---|
| 425 | WRITE_CODE( pcSPS->getMaxTLayers() - 1, 3, "sps_max_sub_layers_minus1" ); |
---|
| 426 | WRITE_FLAG( pcSPS->getTemporalIdNestingFlag() ? 1 : 0, "sps_temporal_id_nesting_flag" ); |
---|
[494] | 427 | #if SVC_EXTENSION |
---|
[313] | 428 | } |
---|
| 429 | #endif |
---|
[442] | 430 | #ifdef SPS_PTL_FIX |
---|
| 431 | if (pcSPS->getLayerId() == 0) |
---|
| 432 | { |
---|
| 433 | codePTL(pcSPS->getPTL(), 1, pcSPS->getMaxTLayers() - 1); |
---|
| 434 | } |
---|
| 435 | #else |
---|
[313] | 436 | codePTL(pcSPS->getPTL(), 1, pcSPS->getMaxTLayers() - 1); |
---|
[442] | 437 | #endif |
---|
[313] | 438 | WRITE_UVLC( pcSPS->getSPSId (), "sps_seq_parameter_set_id" ); |
---|
[442] | 439 | #if REPN_FORMAT_IN_VPS |
---|
| 440 | if( pcSPS->getLayerId() > 0 ) |
---|
[313] | 441 | { |
---|
[442] | 442 | WRITE_FLAG( pcSPS->getUpdateRepFormatFlag(), "update_rep_format_flag" ); |
---|
[313] | 443 | } |
---|
[506] | 444 | #if O0096_REP_FORMAT_INDEX |
---|
| 445 | if( pcSPS->getLayerId() == 0 ) |
---|
| 446 | #else |
---|
[442] | 447 | if( pcSPS->getLayerId() == 0 || pcSPS->getUpdateRepFormatFlag() ) |
---|
[506] | 448 | #endif |
---|
[442] | 449 | { |
---|
| 450 | #endif |
---|
| 451 | WRITE_UVLC( pcSPS->getChromaFormatIdc (), "chroma_format_idc" ); |
---|
| 452 | assert(pcSPS->getChromaFormatIdc () == 1); |
---|
| 453 | // in the first version chroma_format_idc can only be equal to 1 (4:2:0) |
---|
| 454 | if( pcSPS->getChromaFormatIdc () == 3 ) |
---|
| 455 | { |
---|
| 456 | WRITE_FLAG( 0, "separate_colour_plane_flag"); |
---|
| 457 | } |
---|
[313] | 458 | |
---|
[442] | 459 | WRITE_UVLC( pcSPS->getPicWidthInLumaSamples (), "pic_width_in_luma_samples" ); |
---|
| 460 | WRITE_UVLC( pcSPS->getPicHeightInLumaSamples(), "pic_height_in_luma_samples" ); |
---|
| 461 | #if REPN_FORMAT_IN_VPS |
---|
| 462 | } |
---|
[506] | 463 | #if O0096_REP_FORMAT_INDEX |
---|
| 464 | else if (pcSPS->getUpdateRepFormatFlag()) |
---|
| 465 | { |
---|
| 466 | WRITE_CODE( pcSPS->getUpdateRepFormatIndex(), 8, "update_rep_format_index"); |
---|
| 467 | } |
---|
[442] | 468 | #endif |
---|
[506] | 469 | #endif |
---|
[313] | 470 | Window conf = pcSPS->getConformanceWindow(); |
---|
| 471 | |
---|
| 472 | WRITE_FLAG( conf.getWindowEnabledFlag(), "conformance_window_flag" ); |
---|
| 473 | if (conf.getWindowEnabledFlag()) |
---|
| 474 | { |
---|
| 475 | WRITE_UVLC( conf.getWindowLeftOffset() / TComSPS::getWinUnitX(pcSPS->getChromaFormatIdc() ), "conf_win_left_offset" ); |
---|
| 476 | WRITE_UVLC( conf.getWindowRightOffset() / TComSPS::getWinUnitX(pcSPS->getChromaFormatIdc() ), "conf_win_right_offset" ); |
---|
| 477 | WRITE_UVLC( conf.getWindowTopOffset() / TComSPS::getWinUnitY(pcSPS->getChromaFormatIdc() ), "conf_win_top_offset" ); |
---|
| 478 | WRITE_UVLC( conf.getWindowBottomOffset() / TComSPS::getWinUnitY(pcSPS->getChromaFormatIdc() ), "conf_win_bottom_offset" ); |
---|
| 479 | } |
---|
| 480 | |
---|
[442] | 481 | #if REPN_FORMAT_IN_VPS |
---|
[506] | 482 | #if O0096_REP_FORMAT_INDEX |
---|
| 483 | if( pcSPS->getLayerId() == 0 ) |
---|
| 484 | #else |
---|
[442] | 485 | if( pcSPS->getLayerId() == 0 || pcSPS->getUpdateRepFormatFlag() ) |
---|
[506] | 486 | #endif |
---|
[442] | 487 | { |
---|
| 488 | assert( pcSPS->getBitDepthY() >= 8 ); |
---|
| 489 | assert( pcSPS->getBitDepthC() >= 8 ); |
---|
| 490 | #endif |
---|
| 491 | WRITE_UVLC( pcSPS->getBitDepthY() - 8, "bit_depth_luma_minus8" ); |
---|
| 492 | WRITE_UVLC( pcSPS->getBitDepthC() - 8, "bit_depth_chroma_minus8" ); |
---|
| 493 | #if REPN_FORMAT_IN_VPS |
---|
| 494 | } |
---|
| 495 | #endif |
---|
[313] | 496 | WRITE_UVLC( pcSPS->getBitsForPOC()-4, "log2_max_pic_order_cnt_lsb_minus4" ); |
---|
| 497 | |
---|
| 498 | const Bool subLayerOrderingInfoPresentFlag = 1; |
---|
| 499 | WRITE_FLAG(subLayerOrderingInfoPresentFlag, "sps_sub_layer_ordering_info_present_flag"); |
---|
| 500 | for(UInt i=0; i <= pcSPS->getMaxTLayers()-1; i++) |
---|
| 501 | { |
---|
| 502 | WRITE_UVLC( pcSPS->getMaxDecPicBuffering(i) - 1, "sps_max_dec_pic_buffering_minus1[i]" ); |
---|
| 503 | WRITE_UVLC( pcSPS->getNumReorderPics(i), "sps_num_reorder_pics[i]" ); |
---|
| 504 | WRITE_UVLC( pcSPS->getMaxLatencyIncrease(i), "sps_max_latency_increase_plus1[i]" ); |
---|
| 505 | if (!subLayerOrderingInfoPresentFlag) |
---|
| 506 | { |
---|
| 507 | break; |
---|
| 508 | } |
---|
| 509 | } |
---|
| 510 | assert( pcSPS->getMaxCUWidth() == pcSPS->getMaxCUHeight() ); |
---|
| 511 | |
---|
| 512 | WRITE_UVLC( pcSPS->getLog2MinCodingBlockSize() - 3, "log2_min_coding_block_size_minus3" ); |
---|
| 513 | WRITE_UVLC( pcSPS->getLog2DiffMaxMinCodingBlockSize(), "log2_diff_max_min_coding_block_size" ); |
---|
| 514 | WRITE_UVLC( pcSPS->getQuadtreeTULog2MinSize() - 2, "log2_min_transform_block_size_minus2" ); |
---|
| 515 | WRITE_UVLC( pcSPS->getQuadtreeTULog2MaxSize() - pcSPS->getQuadtreeTULog2MinSize(), "log2_diff_max_min_transform_block_size" ); |
---|
| 516 | WRITE_UVLC( pcSPS->getQuadtreeTUMaxDepthInter() - 1, "max_transform_hierarchy_depth_inter" ); |
---|
| 517 | WRITE_UVLC( pcSPS->getQuadtreeTUMaxDepthIntra() - 1, "max_transform_hierarchy_depth_intra" ); |
---|
| 518 | WRITE_FLAG( pcSPS->getScalingListFlag() ? 1 : 0, "scaling_list_enabled_flag" ); |
---|
| 519 | if(pcSPS->getScalingListFlag()) |
---|
| 520 | { |
---|
[528] | 521 | #if SCALINGLIST_INFERRING |
---|
| 522 | if( pcSPS->getLayerId() > 0 ) |
---|
| 523 | { |
---|
| 524 | WRITE_FLAG( pcSPS->getInferScalingListFlag() ? 1 : 0, "sps_infer_scaling_list_flag" ); |
---|
| 525 | } |
---|
| 526 | |
---|
| 527 | if( pcSPS->getInferScalingListFlag() ) |
---|
| 528 | { |
---|
| 529 | // The value of pps_scaling_list_ref_layer_id shall be in the range of 0 to 62, inclusive |
---|
| 530 | assert( pcSPS->getScalingListRefLayerId() <= 62 ); |
---|
| 531 | |
---|
| 532 | WRITE_UVLC( pcSPS->getScalingListRefLayerId(), "sps_scaling_list_ref_layer_id" ); |
---|
| 533 | } |
---|
| 534 | else |
---|
| 535 | { |
---|
| 536 | #endif |
---|
[313] | 537 | WRITE_FLAG( pcSPS->getScalingListPresentFlag() ? 1 : 0, "sps_scaling_list_data_present_flag" ); |
---|
| 538 | if(pcSPS->getScalingListPresentFlag()) |
---|
| 539 | { |
---|
| 540 | codeScalingList( m_pcSlice->getScalingList() ); |
---|
| 541 | } |
---|
[528] | 542 | #if SCALINGLIST_INFERRING |
---|
| 543 | } |
---|
| 544 | #endif |
---|
[313] | 545 | } |
---|
| 546 | WRITE_FLAG( pcSPS->getUseAMP() ? 1 : 0, "amp_enabled_flag" ); |
---|
| 547 | WRITE_FLAG( pcSPS->getUseSAO() ? 1 : 0, "sample_adaptive_offset_enabled_flag"); |
---|
| 548 | |
---|
| 549 | WRITE_FLAG( pcSPS->getUsePCM() ? 1 : 0, "pcm_enabled_flag"); |
---|
| 550 | if( pcSPS->getUsePCM() ) |
---|
| 551 | { |
---|
| 552 | WRITE_CODE( pcSPS->getPCMBitDepthLuma() - 1, 4, "pcm_sample_bit_depth_luma_minus1" ); |
---|
| 553 | WRITE_CODE( pcSPS->getPCMBitDepthChroma() - 1, 4, "pcm_sample_bit_depth_chroma_minus1" ); |
---|
| 554 | WRITE_UVLC( pcSPS->getPCMLog2MinSize() - 3, "log2_min_pcm_luma_coding_block_size_minus3" ); |
---|
| 555 | WRITE_UVLC( pcSPS->getPCMLog2MaxSize() - pcSPS->getPCMLog2MinSize(), "log2_diff_max_min_pcm_luma_coding_block_size" ); |
---|
| 556 | WRITE_FLAG( pcSPS->getPCMFilterDisableFlag()?1 : 0, "pcm_loop_filter_disable_flag"); |
---|
| 557 | } |
---|
| 558 | |
---|
| 559 | assert( pcSPS->getMaxTLayers() > 0 ); |
---|
| 560 | |
---|
| 561 | TComRPSList* rpsList = pcSPS->getRPSList(); |
---|
| 562 | TComReferencePictureSet* rps; |
---|
[442] | 563 | |
---|
[313] | 564 | WRITE_UVLC(rpsList->getNumberOfReferencePictureSets(), "num_short_term_ref_pic_sets" ); |
---|
| 565 | for(Int i=0; i < rpsList->getNumberOfReferencePictureSets(); i++) |
---|
| 566 | { |
---|
| 567 | rps = rpsList->getReferencePictureSet(i); |
---|
| 568 | codeShortTermRefPicSet(pcSPS,rps,false, i); |
---|
| 569 | } |
---|
| 570 | WRITE_FLAG( pcSPS->getLongTermRefsPresent() ? 1 : 0, "long_term_ref_pics_present_flag" ); |
---|
| 571 | if (pcSPS->getLongTermRefsPresent()) |
---|
| 572 | { |
---|
| 573 | WRITE_UVLC(pcSPS->getNumLongTermRefPicSPS(), "num_long_term_ref_pic_sps" ); |
---|
| 574 | for (UInt k = 0; k < pcSPS->getNumLongTermRefPicSPS(); k++) |
---|
| 575 | { |
---|
| 576 | WRITE_CODE( pcSPS->getLtRefPicPocLsbSps(k), pcSPS->getBitsForPOC(), "lt_ref_pic_poc_lsb_sps"); |
---|
| 577 | WRITE_FLAG( pcSPS->getUsedByCurrPicLtSPSFlag(k), "used_by_curr_pic_lt_sps_flag"); |
---|
| 578 | } |
---|
| 579 | } |
---|
| 580 | WRITE_FLAG( pcSPS->getTMVPFlagsPresent() ? 1 : 0, "sps_temporal_mvp_enable_flag" ); |
---|
| 581 | #if REF_IDX_MFM |
---|
| 582 | #if !M0457_COL_PICTURE_SIGNALING |
---|
| 583 | if( pcSPS->getLayerId() > 0 ) |
---|
| 584 | { |
---|
| 585 | WRITE_FLAG( pcSPS->getMFMEnabledFlag() ? 1 : 0, "sps_enh_mfm_enable_flag" ); |
---|
| 586 | } |
---|
| 587 | #endif |
---|
| 588 | #endif |
---|
| 589 | WRITE_FLAG( pcSPS->getUseStrongIntraSmoothing(), "sps_strong_intra_smoothing_enable_flag" ); |
---|
| 590 | |
---|
| 591 | WRITE_FLAG( pcSPS->getVuiParametersPresentFlag(), "vui_parameters_present_flag" ); |
---|
| 592 | if (pcSPS->getVuiParametersPresentFlag()) |
---|
| 593 | { |
---|
| 594 | codeVUI(pcSPS->getVuiParameters(), pcSPS); |
---|
| 595 | } |
---|
| 596 | |
---|
| 597 | #if SPS_EXTENSION |
---|
| 598 | WRITE_FLAG( 1, "sps_extension_flag" ); |
---|
| 599 | if( 1 ) // if( sps_extension_flag ) |
---|
| 600 | { |
---|
[515] | 601 | #if O0142_CONDITIONAL_SPS_EXTENSION |
---|
| 602 | UInt spsExtensionTypeFlag[8] = { 0, 1, 0, 0, 0, 0, 0, 0 }; |
---|
| 603 | for (UInt i = 0; i < 8; i++) |
---|
| 604 | { |
---|
| 605 | WRITE_FLAG( spsExtensionTypeFlag[i], "sps_extension_type_flag" ); |
---|
| 606 | } |
---|
| 607 | if (spsExtensionTypeFlag[1]) |
---|
| 608 | { |
---|
| 609 | codeSPSExtension( pcSPS ); |
---|
| 610 | } |
---|
| 611 | #else |
---|
[313] | 612 | codeSPSExtension( pcSPS ); |
---|
| 613 | WRITE_FLAG( 0, "sps_extension2_flag" ); |
---|
[515] | 614 | #endif |
---|
[313] | 615 | } |
---|
| 616 | #else |
---|
| 617 | WRITE_FLAG( 0, "sps_extension_flag" ); |
---|
| 618 | #endif |
---|
| 619 | } |
---|
| 620 | #if SPS_EXTENSION |
---|
| 621 | Void TEncCavlc::codeSPSExtension( TComSPS* pcSPS ) |
---|
| 622 | { |
---|
| 623 | // more syntax elements to be written here |
---|
[442] | 624 | |
---|
| 625 | #if VERT_MV_CONSTRAINT |
---|
| 626 | // Vertical MV component restriction is not used in SHVC CTC |
---|
| 627 | WRITE_FLAG( 0, "inter_view_mv_vert_constraint_flag" ); |
---|
| 628 | #endif |
---|
[313] | 629 | if( pcSPS->getLayerId() > 0 ) |
---|
| 630 | { |
---|
| 631 | WRITE_UVLC( pcSPS->getNumScaledRefLayerOffsets(), "num_scaled_ref_layer_offsets" ); |
---|
| 632 | for(Int i = 0; i < pcSPS->getNumScaledRefLayerOffsets(); i++) |
---|
| 633 | { |
---|
| 634 | Window scaledWindow = pcSPS->getScaledRefLayerWindow(i); |
---|
[507] | 635 | #if O0098_SCALED_REF_LAYER_ID |
---|
| 636 | WRITE_CODE( pcSPS->getScaledRefLayerId(i), 6, "scaled_ref_layer_id" ); |
---|
| 637 | #endif |
---|
[313] | 638 | WRITE_SVLC( scaledWindow.getWindowLeftOffset() >> 1, "scaled_ref_layer_left_offset" ); |
---|
| 639 | WRITE_SVLC( scaledWindow.getWindowTopOffset() >> 1, "scaled_ref_layer_top_offset" ); |
---|
| 640 | WRITE_SVLC( scaledWindow.getWindowRightOffset() >> 1, "scaled_ref_layer_right_offset" ); |
---|
| 641 | WRITE_SVLC( scaledWindow.getWindowBottomOffset() >> 1, "scaled_ref_layer_bottom_offset" ); |
---|
| 642 | } |
---|
| 643 | } |
---|
| 644 | #if M0463_VUI_EXT_ILP_REF |
---|
| 645 | //// sps_extension_vui_parameters( ) |
---|
| 646 | if( pcSPS->getVuiParameters()->getBitstreamRestrictionFlag() ) |
---|
| 647 | { |
---|
| 648 | WRITE_UVLC( pcSPS->getNumIlpRestrictedRefLayers( ), "num_ilp_restricted_ref_layers" ); |
---|
| 649 | for( Int i = 0; i < pcSPS->getNumIlpRestrictedRefLayers( ); i++ ) |
---|
| 650 | { |
---|
| 651 | WRITE_UVLC( pcSPS->getMinSpatialSegmentOffsetPlus1( i ), "min_spatial_segment_offset_plus1" ); |
---|
| 652 | if( pcSPS->getMinSpatialSegmentOffsetPlus1( i ) > 0 ) |
---|
| 653 | { |
---|
| 654 | WRITE_FLAG( pcSPS->getCtuBasedOffsetEnabledFlag( i ), "ctu_based_offset_enabled_flag[ i ]"); |
---|
| 655 | if( pcSPS->getCtuBasedOffsetEnabledFlag( i ) ) |
---|
| 656 | { |
---|
| 657 | WRITE_UVLC( pcSPS->getMinHorizontalCtuOffsetPlus1( i ), "min_horizontal_ctu_offset_plus1[ i ]"); |
---|
| 658 | } |
---|
| 659 | } |
---|
| 660 | } |
---|
| 661 | } |
---|
| 662 | //// sps_extension_vui_parameters( ) END |
---|
| 663 | #endif |
---|
| 664 | } |
---|
| 665 | #endif |
---|
| 666 | Void TEncCavlc::codeVPS( TComVPS* pcVPS ) |
---|
| 667 | { |
---|
[494] | 668 | #if VPS_EXTN_OFFSET_CALC |
---|
| 669 | UInt numBytesInVps = this->m_pcBitIf->getNumberOfWrittenBits(); |
---|
| 670 | #endif |
---|
[542] | 671 | #if VPS_VUI_OFFSET |
---|
| 672 | m_vpsVuiCounter = this->m_pcBitIf->getNumberOfWrittenBits(); |
---|
| 673 | #endif |
---|
[313] | 674 | WRITE_CODE( pcVPS->getVPSId(), 4, "vps_video_parameter_set_id" ); |
---|
| 675 | WRITE_CODE( 3, 2, "vps_reserved_three_2bits" ); |
---|
| 676 | #if VPS_RENAME |
---|
| 677 | WRITE_CODE( pcVPS->getMaxLayers() - 1, 6, "vps_max_layers_minus1" ); |
---|
| 678 | #else |
---|
| 679 | WRITE_CODE( 0, 6, "vps_reserved_zero_6bits" ); |
---|
| 680 | #endif |
---|
| 681 | WRITE_CODE( pcVPS->getMaxTLayers() - 1, 3, "vps_max_sub_layers_minus1" ); |
---|
| 682 | WRITE_FLAG( pcVPS->getTemporalNestingFlag(), "vps_temporal_id_nesting_flag" ); |
---|
| 683 | assert (pcVPS->getMaxTLayers()>1||pcVPS->getTemporalNestingFlag()); |
---|
[442] | 684 | #if VPS_EXTN_OFFSET |
---|
| 685 | WRITE_CODE( pcVPS->getExtensionOffset(), 16, "vps_extension_offset" ); |
---|
| 686 | #else |
---|
[313] | 687 | WRITE_CODE( 0xffff, 16, "vps_reserved_ffff_16bits" ); |
---|
[442] | 688 | #endif |
---|
[313] | 689 | codePTL( pcVPS->getPTL(), true, pcVPS->getMaxTLayers() - 1 ); |
---|
| 690 | const Bool subLayerOrderingInfoPresentFlag = 1; |
---|
| 691 | WRITE_FLAG(subLayerOrderingInfoPresentFlag, "vps_sub_layer_ordering_info_present_flag"); |
---|
| 692 | for(UInt i=0; i <= pcVPS->getMaxTLayers()-1; i++) |
---|
| 693 | { |
---|
| 694 | WRITE_UVLC( pcVPS->getMaxDecPicBuffering(i) - 1, "vps_max_dec_pic_buffering_minus1[i]" ); |
---|
| 695 | WRITE_UVLC( pcVPS->getNumReorderPics(i), "vps_num_reorder_pics[i]" ); |
---|
| 696 | WRITE_UVLC( pcVPS->getMaxLatencyIncrease(i), "vps_max_latency_increase_plus1[i]" ); |
---|
| 697 | if (!subLayerOrderingInfoPresentFlag) |
---|
| 698 | { |
---|
| 699 | break; |
---|
| 700 | } |
---|
| 701 | } |
---|
| 702 | |
---|
| 703 | #if VPS_RENAME |
---|
| 704 | assert( pcVPS->getNumHrdParameters() <= MAX_VPS_LAYER_SETS_PLUS1 ); |
---|
| 705 | assert( pcVPS->getMaxLayerId() < MAX_VPS_LAYER_ID_PLUS1 ); |
---|
| 706 | #if !VPS_EXTN_OP_LAYER_SETS // num layer sets set in TAppEncTop.cpp |
---|
| 707 | pcVPS->setNumLayerSets(1); |
---|
| 708 | #endif |
---|
| 709 | WRITE_CODE( pcVPS->getMaxLayerId(), 6, "vps_max_layer_id" ); |
---|
| 710 | WRITE_UVLC( pcVPS->getNumLayerSets() - 1, "vps_num_layer_sets_minus1" ); |
---|
| 711 | for( UInt opsIdx = 1; opsIdx <= ( pcVPS->getNumLayerSets() - 1 ); opsIdx ++ ) |
---|
| 712 | { |
---|
| 713 | // Operation point set |
---|
| 714 | for( UInt i = 0; i <= pcVPS->getMaxLayerId(); i ++ ) |
---|
| 715 | #else |
---|
| 716 | assert( pcVPS->getNumHrdParameters() <= MAX_VPS_NUM_HRD_PARAMETERS ); |
---|
| 717 | assert( pcVPS->getMaxNuhReservedZeroLayerId() < MAX_VPS_NUH_RESERVED_ZERO_LAYER_ID_PLUS1 ); |
---|
| 718 | WRITE_CODE( pcVPS->getMaxNuhReservedZeroLayerId(), 6, "vps_max_nuh_reserved_zero_layer_id" ); |
---|
| 719 | pcVPS->setMaxOpSets(1); |
---|
| 720 | WRITE_UVLC( pcVPS->getMaxOpSets() - 1, "vps_max_op_sets_minus1" ); |
---|
| 721 | for( UInt opsIdx = 1; opsIdx <= ( pcVPS->getMaxOpSets() - 1 ); opsIdx ++ ) |
---|
| 722 | { |
---|
| 723 | // Operation point set |
---|
| 724 | for( UInt i = 0; i <= pcVPS->getMaxNuhReservedZeroLayerId(); i ++ ) |
---|
| 725 | #endif |
---|
| 726 | { |
---|
| 727 | #if !VPS_EXTN_OP_LAYER_SETS // layer Id include flag set in TAppEncTop.cpp |
---|
| 728 | // Only applicable for version 1 |
---|
| 729 | pcVPS->setLayerIdIncludedFlag( true, opsIdx, i ); |
---|
| 730 | #endif |
---|
| 731 | WRITE_FLAG( pcVPS->getLayerIdIncludedFlag( opsIdx, i ) ? 1 : 0, "layer_id_included_flag[opsIdx][i]" ); |
---|
| 732 | } |
---|
| 733 | } |
---|
| 734 | #if DERIVE_LAYER_ID_LIST_VARIABLES |
---|
| 735 | pcVPS->deriveLayerIdListVariables(); |
---|
| 736 | #endif |
---|
| 737 | TimingInfo *timingInfo = pcVPS->getTimingInfo(); |
---|
| 738 | WRITE_FLAG(timingInfo->getTimingInfoPresentFlag(), "vps_timing_info_present_flag"); |
---|
| 739 | if(timingInfo->getTimingInfoPresentFlag()) |
---|
| 740 | { |
---|
| 741 | WRITE_CODE(timingInfo->getNumUnitsInTick(), 32, "vps_num_units_in_tick"); |
---|
| 742 | WRITE_CODE(timingInfo->getTimeScale(), 32, "vps_time_scale"); |
---|
| 743 | WRITE_FLAG(timingInfo->getPocProportionalToTimingFlag(), "vps_poc_proportional_to_timing_flag"); |
---|
| 744 | if(timingInfo->getPocProportionalToTimingFlag()) |
---|
| 745 | { |
---|
| 746 | WRITE_UVLC(timingInfo->getNumTicksPocDiffOneMinus1(), "vps_num_ticks_poc_diff_one_minus1"); |
---|
| 747 | } |
---|
| 748 | pcVPS->setNumHrdParameters( 0 ); |
---|
| 749 | WRITE_UVLC( pcVPS->getNumHrdParameters(), "vps_num_hrd_parameters" ); |
---|
| 750 | |
---|
| 751 | if( pcVPS->getNumHrdParameters() > 0 ) |
---|
| 752 | { |
---|
| 753 | pcVPS->createHrdParamBuffer(); |
---|
| 754 | } |
---|
| 755 | for( UInt i = 0; i < pcVPS->getNumHrdParameters(); i ++ ) |
---|
| 756 | { |
---|
| 757 | // Only applicable for version 1 |
---|
| 758 | pcVPS->setHrdOpSetIdx( 0, i ); |
---|
| 759 | WRITE_UVLC( pcVPS->getHrdOpSetIdx( i ), "hrd_op_set_idx" ); |
---|
| 760 | if( i > 0 ) |
---|
| 761 | { |
---|
| 762 | WRITE_FLAG( pcVPS->getCprmsPresentFlag( i ) ? 1 : 0, "cprms_present_flag[i]" ); |
---|
| 763 | } |
---|
| 764 | codeHrdParameters(pcVPS->getHrdParameters(i), pcVPS->getCprmsPresentFlag( i ), pcVPS->getMaxTLayers() - 1); |
---|
| 765 | } |
---|
| 766 | } |
---|
| 767 | #if !VPS_EXTNS |
---|
| 768 | WRITE_FLAG( 0, "vps_extension_flag" ); |
---|
| 769 | #else |
---|
| 770 | WRITE_FLAG( 1, "vps_extension_flag" ); |
---|
[442] | 771 | if(1) // Should be conditioned on the value of vps_extension_flag |
---|
| 772 | { |
---|
| 773 | while ( m_pcBitIf->getNumberOfWrittenBits() % 8 != 0 ) |
---|
| 774 | { |
---|
| 775 | WRITE_FLAG(1, "vps_extension_alignment_bit_equal_to_one"); |
---|
| 776 | } |
---|
[494] | 777 | #if VPS_EXTN_OFFSET_CALC |
---|
| 778 | Int vpsExntOffsetValueInBits = this->m_pcBitIf->getNumberOfWrittenBits() - numBytesInVps + 16; // 2 bytes for NUH |
---|
| 779 | assert( vpsExntOffsetValueInBits % 8 == 0 ); |
---|
| 780 | pcVPS->setExtensionOffset( vpsExntOffsetValueInBits >> 3 ); |
---|
| 781 | #endif |
---|
[442] | 782 | codeVPSExtension(pcVPS); |
---|
| 783 | WRITE_FLAG( 0, "vps_extension2_flag" ); // Flag value of 1 reserved |
---|
| 784 | } |
---|
[313] | 785 | #endif |
---|
| 786 | //future extensions here.. |
---|
| 787 | |
---|
| 788 | return; |
---|
| 789 | } |
---|
| 790 | |
---|
[494] | 791 | #if SVC_EXTENSION |
---|
[313] | 792 | #if VPS_EXTNS |
---|
| 793 | Void TEncCavlc::codeVPSExtension (TComVPS *vps) |
---|
| 794 | { |
---|
| 795 | // ... More syntax elements to be written here |
---|
| 796 | #if VPS_EXTN_MASK_AND_DIM_INFO |
---|
| 797 | UInt i = 0, j = 0; |
---|
| 798 | |
---|
| 799 | WRITE_FLAG( vps->getAvcBaseLayerFlag(), "avc_base_layer_flag" ); |
---|
[544] | 800 | #if O0109_MOVE_VPS_VUI_FLAG |
---|
| 801 | #if !VPS_VUI |
---|
| 802 | WRITE_FLAG( 0, "vps_vui_present_flag" ); |
---|
| 803 | vps->setVpsVuiPresentFlag(false); |
---|
| 804 | #else |
---|
| 805 | WRITE_FLAG( 1, "vps_vui_present_flag" ); |
---|
| 806 | vps->setVpsVuiPresentFlag(true); |
---|
| 807 | #endif |
---|
| 808 | if ( vps->getVpsVuiPresentFlag() ) |
---|
| 809 | { |
---|
[542] | 810 | #if VPS_VUI_OFFSET |
---|
[544] | 811 | WRITE_CODE( vps->getVpsVuiOffset( ), 16, "vps_vui_offset" ); |
---|
| 812 | #endif |
---|
| 813 | WRITE_FLAG( vps->getSplittingFlag(), "splitting_flag" ); |
---|
| 814 | } |
---|
| 815 | #else |
---|
| 816 | #if VPS_VUI_OFFSET |
---|
[542] | 817 | WRITE_CODE( vps->getVpsVuiOffset( ), 16, "vps_vui_offset" ); |
---|
| 818 | #endif |
---|
[313] | 819 | WRITE_FLAG( vps->getSplittingFlag(), "splitting_flag" ); |
---|
[544] | 820 | #endif // O0109_MOVE_VPS_VUI_FLAG |
---|
[313] | 821 | |
---|
| 822 | for(i = 0; i < MAX_VPS_NUM_SCALABILITY_TYPES; i++) |
---|
| 823 | { |
---|
| 824 | WRITE_FLAG( vps->getScalabilityMask(i), "scalability_mask[i]" ); |
---|
| 825 | } |
---|
| 826 | |
---|
| 827 | for(j = 0; j < vps->getNumScalabilityTypes() - vps->getSplittingFlag(); j++) |
---|
| 828 | { |
---|
| 829 | WRITE_CODE( vps->getDimensionIdLen(j) - 1, 3, "dimension_id_len_minus1[j]" ); |
---|
| 830 | } |
---|
| 831 | |
---|
[345] | 832 | #if SPL_FLG_CHK |
---|
| 833 | if(vps->getSplittingFlag()) |
---|
| 834 | { |
---|
| 835 | UInt splDimSum=0; |
---|
| 836 | for(j = 0; j < vps->getNumScalabilityTypes(); j++) |
---|
| 837 | { |
---|
| 838 | splDimSum+=(vps->getDimensionIdLen(j)); |
---|
| 839 | } |
---|
| 840 | assert(splDimSum<=6); |
---|
| 841 | } |
---|
| 842 | #endif |
---|
| 843 | |
---|
[313] | 844 | WRITE_FLAG( vps->getNuhLayerIdPresentFlag(), "vps_nuh_layer_id_present_flag" ); |
---|
| 845 | for(i = 1; i < vps->getMaxLayers(); i++) |
---|
| 846 | { |
---|
| 847 | if( vps->getNuhLayerIdPresentFlag() ) |
---|
| 848 | { |
---|
| 849 | WRITE_CODE( vps->getLayerIdInNuh(i), 6, "layer_id_in_nuh[i]" ); |
---|
| 850 | } |
---|
[494] | 851 | |
---|
| 852 | if( !vps->getSplittingFlag() ) |
---|
| 853 | { |
---|
[313] | 854 | for(j = 0; j < vps->getNumScalabilityTypes(); j++) |
---|
| 855 | { |
---|
| 856 | UInt bits = vps->getDimensionIdLen(j); |
---|
| 857 | WRITE_CODE( vps->getDimensionId(i, j), bits, "dimension_id[i][j]" ); |
---|
| 858 | } |
---|
| 859 | } |
---|
[494] | 860 | } |
---|
[313] | 861 | #endif |
---|
[442] | 862 | #if VIEW_ID_RELATED_SIGNALING |
---|
| 863 | // if ( pcVPS->getNumViews() > 1 ) |
---|
| 864 | // However, this is a bug in the text since, view_id_len_minus1 is needed to parse view_id_val. |
---|
| 865 | { |
---|
[544] | 866 | #if O0109_VIEW_ID_LEN |
---|
| 867 | WRITE_CODE( vps->getViewIdLen( ), 4, "view_id_len" ); |
---|
| 868 | assert ( vps->getNumViews() >= (1<<vps->getViewIdLen()) ); |
---|
| 869 | #else |
---|
[442] | 870 | WRITE_CODE( vps->getViewIdLenMinus1( ), 4, "view_id_len_minus1" ); |
---|
[544] | 871 | #endif |
---|
[442] | 872 | } |
---|
| 873 | |
---|
[544] | 874 | #if O0109_VIEW_ID_LEN |
---|
| 875 | if ( vps->getViewIdLen() > 0 ) |
---|
| 876 | { |
---|
| 877 | #endif |
---|
[442] | 878 | for( i = 0; i < vps->getNumViews(); i++ ) |
---|
| 879 | { |
---|
[544] | 880 | #if O0109_VIEW_ID_LEN |
---|
| 881 | WRITE_CODE( vps->getViewIdVal( i ), vps->getViewIdLen( ), "view_id_val[i]" ); |
---|
| 882 | #else |
---|
[442] | 883 | WRITE_CODE( vps->getViewIdVal( i ), vps->getViewIdLenMinus1( ) + 1, "view_id_val[i]" ); |
---|
[544] | 884 | #endif |
---|
[442] | 885 | } |
---|
[544] | 886 | #if O0109_VIEW_ID_LEN |
---|
| 887 | } |
---|
[442] | 888 | #endif |
---|
[544] | 889 | #endif // VIEW_ID_RELATED_SIGNALING |
---|
| 890 | |
---|
[313] | 891 | #if VPS_EXTN_DIRECT_REF_LAYERS |
---|
| 892 | for( Int layerCtr = 1; layerCtr <= vps->getMaxLayers() - 1; layerCtr++) |
---|
| 893 | { |
---|
| 894 | for( Int refLayerCtr = 0; refLayerCtr < layerCtr; refLayerCtr++) |
---|
| 895 | { |
---|
| 896 | WRITE_FLAG(vps->getDirectDependencyFlag(layerCtr, refLayerCtr), "direct_dependency_flag[i][j]" ); |
---|
| 897 | } |
---|
| 898 | } |
---|
| 899 | #endif |
---|
[514] | 900 | #if VPS_TSLAYERS |
---|
| 901 | WRITE_FLAG( vps->getMaxTSLayersPresentFlag(), "vps_sub_layers_max_minus1_present_flag"); |
---|
| 902 | if (vps->getMaxTSLayersPresentFlag()) |
---|
| 903 | { |
---|
| 904 | for( i = 0; i < vps->getMaxLayers() - 1; i++) |
---|
| 905 | { |
---|
| 906 | WRITE_CODE(vps->getMaxTSLayersMinus1(i), 3, "sub_layers_vps_max_minus1[i]" ); |
---|
| 907 | } |
---|
| 908 | } |
---|
| 909 | #endif |
---|
[313] | 910 | #if JCTVC_M0203_INTERLAYER_PRED_IDC |
---|
[345] | 911 | #if N0120_MAX_TID_REF_PRESENT_FLAG |
---|
[442] | 912 | WRITE_FLAG( vps->getMaxTidRefPresentFlag(), "max_tid_ref_present_flag"); |
---|
| 913 | if (vps->getMaxTidRefPresentFlag()) |
---|
[345] | 914 | { |
---|
| 915 | for( i = 0; i < vps->getMaxLayers() - 1; i++) |
---|
| 916 | { |
---|
[494] | 917 | #if O0225_MAX_TID_FOR_REF_LAYERS |
---|
| 918 | for( j = i+1; j <= vps->getMaxLayers() - 1; j++) |
---|
| 919 | { |
---|
| 920 | if(vps->getDirectDependencyFlag(j, i)) |
---|
| 921 | { |
---|
| 922 | WRITE_CODE(vps->getMaxTidIlRefPicsPlus1(i,j), 3, "max_tid_il_ref_pics_plus1[i][j]" ); |
---|
| 923 | } |
---|
| 924 | } |
---|
| 925 | #else |
---|
[442] | 926 | WRITE_CODE(vps->getMaxTidIlRefPicsPlus1(i), 3, "max_tid_il_ref_pics_plus1[i]" ); |
---|
[494] | 927 | #endif |
---|
[345] | 928 | } |
---|
| 929 | } |
---|
| 930 | #else |
---|
[313] | 931 | for( i = 0; i < vps->getMaxLayers() - 1; i++) |
---|
| 932 | { |
---|
[494] | 933 | #if O0225_MAX_TID_FOR_REF_LAYERS |
---|
| 934 | for( j = i+1; j <= vps->getMaxLayers() - 1; j++) |
---|
| 935 | { |
---|
| 936 | if(vps->getDirectDependencyFlag(j, i)) |
---|
| 937 | { |
---|
| 938 | WRITE_CODE(vps->getMaxTidIlRefPicsPlus1(i,j), 3, "max_tid_il_ref_pics_plus1[i][j]" ); |
---|
| 939 | } |
---|
| 940 | } |
---|
| 941 | #else |
---|
[442] | 942 | WRITE_CODE(vps->getMaxTidIlRefPicsPlus1(i), 3, "max_tid_il_ref_pics_plus1[i]" ); |
---|
[494] | 943 | #endif |
---|
[313] | 944 | } |
---|
| 945 | #endif |
---|
[345] | 946 | #endif |
---|
| 947 | #if ILP_SSH_SIG |
---|
| 948 | WRITE_FLAG( vps->getIlpSshSignalingEnabledFlag(), "all_ref_layers_active_flag" ); |
---|
| 949 | #endif |
---|
[313] | 950 | #if VPS_EXTN_PROFILE_INFO |
---|
| 951 | // Profile-tier-level signalling |
---|
| 952 | WRITE_CODE( vps->getNumLayerSets() - 1 , 10, "vps_number_layer_sets_minus1" ); |
---|
| 953 | WRITE_CODE( vps->getNumProfileTierLevel() - 1, 6, "vps_num_profile_tier_level_minus1"); |
---|
| 954 | for(Int idx = 1; idx <= vps->getNumProfileTierLevel() - 1; idx++) |
---|
| 955 | { |
---|
| 956 | WRITE_FLAG( vps->getProfilePresentFlag(idx), "vps_profile_present_flag[i]" ); |
---|
| 957 | if( !vps->getProfilePresentFlag(idx) ) |
---|
| 958 | { |
---|
| 959 | WRITE_CODE( vps->getProfileLayerSetRef(idx) - 1, 6, "profile_ref_minus1[i]" ); |
---|
| 960 | } |
---|
| 961 | codePTL( vps->getPTLForExtn(idx), vps->getProfilePresentFlag(idx), vps->getMaxTLayers() - 1 ); |
---|
| 962 | } |
---|
| 963 | #endif |
---|
| 964 | |
---|
| 965 | Int numOutputLayerSets = vps->getNumOutputLayerSets() ; |
---|
| 966 | WRITE_FLAG( (numOutputLayerSets > vps->getNumLayerSets()), "more_output_layer_sets_than_default_flag" ); |
---|
| 967 | if(numOutputLayerSets > vps->getNumLayerSets()) |
---|
| 968 | { |
---|
| 969 | WRITE_CODE( numOutputLayerSets - vps->getNumLayerSets(), 10, "num_add_output_layer_sets" ); |
---|
| 970 | } |
---|
| 971 | if( numOutputLayerSets > 1 ) |
---|
| 972 | { |
---|
[544] | 973 | #if O0109_DEFAULT_ONE_OUT_LAYER_IDC |
---|
| 974 | WRITE_CODE( vps->getDefaultOneTargetOutputLayerIdc(), 2, "default_one_target_output_layer_idc" ); |
---|
| 975 | #else |
---|
[313] | 976 | WRITE_FLAG( vps->getDefaultOneTargetOutputLayerFlag(), "default_one_target_output_layer_flag" ); |
---|
[544] | 977 | #endif |
---|
[313] | 978 | } |
---|
| 979 | |
---|
| 980 | for(i = 1; i < numOutputLayerSets; i++) |
---|
| 981 | { |
---|
| 982 | if( i > (vps->getNumLayerSets() - 1) ) |
---|
| 983 | { |
---|
| 984 | Int numBits = 1; |
---|
| 985 | while ((1 << numBits) < (vps->getNumLayerSets() - 1)) |
---|
| 986 | { |
---|
| 987 | numBits++; |
---|
| 988 | } |
---|
| 989 | WRITE_CODE( vps->getOutputLayerSetIdx(i) - 1, numBits, "output_layer_set_idx_minus1"); |
---|
| 990 | Int lsIdx = vps->getOutputLayerSetIdx(i); |
---|
| 991 | for(j = 0; j < vps->getNumLayersInIdList(lsIdx) - 1; j++) |
---|
| 992 | { |
---|
| 993 | WRITE_FLAG( vps->getOutputLayerFlag(i,j), "output_layer_flag[i][j]"); |
---|
| 994 | } |
---|
| 995 | } |
---|
| 996 | Int numBits = 1; |
---|
| 997 | while ((1 << numBits) < (vps->getNumProfileTierLevel())) |
---|
| 998 | { |
---|
| 999 | numBits++; |
---|
| 1000 | } |
---|
| 1001 | WRITE_CODE( vps->getProfileLevelTierIdx(i), numBits, "profile_level_tier_idx[i]" ); |
---|
| 1002 | } |
---|
[442] | 1003 | |
---|
[512] | 1004 | #if O0153_ALT_OUTPUT_LAYER_FLAG |
---|
| 1005 | if( vps->getMaxLayers() > 1 ) |
---|
| 1006 | { |
---|
| 1007 | WRITE_FLAG( vps->getAltOuputLayerFlag(), "alt_output_layer_flag" ); |
---|
| 1008 | } |
---|
| 1009 | #endif |
---|
| 1010 | |
---|
[442] | 1011 | #if REPN_FORMAT_IN_VPS |
---|
| 1012 | WRITE_FLAG( vps->getRepFormatIdxPresentFlag(), "rep_format_idx_present_flag"); |
---|
| 1013 | |
---|
| 1014 | if( vps->getRepFormatIdxPresentFlag() ) |
---|
| 1015 | { |
---|
[506] | 1016 | #if O0096_REP_FORMAT_INDEX |
---|
| 1017 | WRITE_CODE( vps->getVpsNumRepFormats() - 1, 8, "vps_num_rep_formats_minus1" ); |
---|
| 1018 | #else |
---|
[442] | 1019 | WRITE_CODE( vps->getVpsNumRepFormats() - 1, 4, "vps_num_rep_formats_minus1" ); |
---|
[506] | 1020 | #endif |
---|
[442] | 1021 | } |
---|
| 1022 | for(i = 0; i < vps->getVpsNumRepFormats(); i++) |
---|
| 1023 | { |
---|
| 1024 | // Read rep_format_structures |
---|
| 1025 | codeRepFormat( vps->getVpsRepFormat(i) ); |
---|
| 1026 | } |
---|
| 1027 | |
---|
| 1028 | if( vps->getRepFormatIdxPresentFlag() ) |
---|
| 1029 | { |
---|
| 1030 | for(i = 1; i < vps->getMaxLayers(); i++) |
---|
| 1031 | { |
---|
| 1032 | if( vps->getVpsNumRepFormats() > 1 ) |
---|
| 1033 | { |
---|
[506] | 1034 | #if O0096_REP_FORMAT_INDEX |
---|
| 1035 | WRITE_CODE( vps->getVpsRepFormatIdx(i), 8, "vps_rep_format_idx[i]" ); |
---|
| 1036 | #else |
---|
[442] | 1037 | WRITE_CODE( vps->getVpsRepFormatIdx(i), 4, "vps_rep_format_idx[i]" ); |
---|
[506] | 1038 | #endif |
---|
[442] | 1039 | } |
---|
| 1040 | } |
---|
| 1041 | } |
---|
| 1042 | #endif |
---|
| 1043 | |
---|
[313] | 1044 | #if JCTVC_M0458_INTERLAYER_RPS_SIG |
---|
| 1045 | WRITE_FLAG(vps->getMaxOneActiveRefLayerFlag(), "max_one_active_ref_layer_flag"); |
---|
[494] | 1046 | #endif |
---|
| 1047 | #if O0062_POC_LSB_NOT_PRESENT_FLAG |
---|
| 1048 | for(i = 1; i< vps->getMaxLayers(); i++) |
---|
[313] | 1049 | { |
---|
[494] | 1050 | if( vps->getNumDirectRefLayers( vps->getLayerIdInNuh(i) ) == 0 ) |
---|
[313] | 1051 | { |
---|
[494] | 1052 | WRITE_FLAG(vps->getPocLsbNotPresentFlag(i), "poc_lsb_not_present_flag[i]"); |
---|
[313] | 1053 | } |
---|
| 1054 | } |
---|
| 1055 | #endif |
---|
[494] | 1056 | #if O0215_PHASE_ALIGNMENT |
---|
| 1057 | WRITE_FLAG(vps->getPhaseAlignFlag(), "cross_layer_phase_alignment_flag" ); |
---|
[313] | 1058 | #endif |
---|
[494] | 1059 | #if N0147_IRAP_ALIGN_FLAG && !IRAP_ALIGN_FLAG_IN_VPS_VUI |
---|
| 1060 | WRITE_FLAG(vps->getCrossLayerIrapAlignFlag(), "cross_layer_irap_aligned_flag"); |
---|
| 1061 | #endif |
---|
[516] | 1062 | #if VPS_DPB_SIZE_TABLE |
---|
| 1063 | for(i = 1; i < vps->getNumOutputLayerSets(); i++) |
---|
| 1064 | { |
---|
| 1065 | WRITE_FLAG( vps->getSubLayerFlagInfoPresentFlag( i ), "sub_layer_flag_info_present_flag[i]"); |
---|
| 1066 | for(j = 0; j < vps->getMaxTLayers(); j++) |
---|
| 1067 | { |
---|
| 1068 | if( j > 0 && vps->getSubLayerFlagInfoPresentFlag(i) ) |
---|
| 1069 | { |
---|
| 1070 | WRITE_FLAG( vps->getSubLayerDpbInfoPresentFlag( i, j), "sub_layer_dpb_info_present_flag[i]"); |
---|
| 1071 | } |
---|
| 1072 | if( vps->getSubLayerDpbInfoPresentFlag(i, j) ) |
---|
| 1073 | { |
---|
| 1074 | for(Int k = 0; k < vps->getNumSubDpbs(i); k++) |
---|
| 1075 | { |
---|
| 1076 | WRITE_UVLC( vps->getMaxVpsDecPicBufferingMinus1( i, k, j), "max_vps_dec_pic_buffering_minus1[i][k][j]" ); |
---|
| 1077 | } |
---|
| 1078 | WRITE_UVLC( vps->getMaxVpsNumReorderPics( i, j), "max_vps_num_reorder_pics[i][j]" ); |
---|
| 1079 | WRITE_UVLC( vps->getMaxVpsLatencyIncreasePlus1( i, j), "max_vps_latency_increase_plus1[i][j]" ); |
---|
| 1080 | } |
---|
| 1081 | } |
---|
| 1082 | } |
---|
| 1083 | #endif |
---|
[313] | 1084 | #if VPS_EXTN_DIRECT_REF_LAYERS && M0457_PREDICTION_INDICATIONS |
---|
| 1085 | WRITE_UVLC( vps->getDirectDepTypeLen()-2, "direct_dep_type_len_minus2"); |
---|
[506] | 1086 | #if O0096_DEFAULT_DEPENDENCY_TYPE |
---|
| 1087 | WRITE_FLAG(vps->getDefaultDirectDependencyTypeFlag(), "default_direct_dependency_flag"); |
---|
| 1088 | if (vps->getDefaultDirectDependencyTypeFlag()) |
---|
| 1089 | { |
---|
| 1090 | WRITE_CODE( vps->getDefaultDirectDependencyType(), vps->getDirectDepTypeLen(), "default_direct_dependency_type" ); |
---|
| 1091 | } |
---|
| 1092 | else |
---|
| 1093 | { |
---|
| 1094 | for(i = 1; i < vps->getMaxLayers(); i++) |
---|
| 1095 | { |
---|
| 1096 | for(j = 0; j < i; j++) |
---|
| 1097 | { |
---|
| 1098 | if (vps->getDirectDependencyFlag(i, j)) |
---|
| 1099 | { |
---|
| 1100 | WRITE_CODE( vps->getDirectDependencyType(i, j), vps->getDirectDepTypeLen(), "direct_dependency_type[i][j]" ); |
---|
| 1101 | } |
---|
| 1102 | } |
---|
| 1103 | } |
---|
| 1104 | } |
---|
| 1105 | #else |
---|
[313] | 1106 | for(i = 1; i < vps->getMaxLayers(); i++) |
---|
| 1107 | { |
---|
| 1108 | for(j = 0; j < i; j++) |
---|
| 1109 | { |
---|
| 1110 | if (vps->getDirectDependencyFlag(i, j)) |
---|
| 1111 | { |
---|
| 1112 | WRITE_CODE( vps->getDirectDependencyType(i, j), vps->getDirectDepTypeLen(), "direct_dependency_type[i][j]" ); |
---|
| 1113 | } |
---|
| 1114 | } |
---|
| 1115 | } |
---|
[506] | 1116 | #endif |
---|
[313] | 1117 | #endif |
---|
[544] | 1118 | |
---|
| 1119 | #if !O0109_O0199_FLAGS_TO_VUI |
---|
[313] | 1120 | #if M0040_ADAPTIVE_RESOLUTION_CHANGE |
---|
| 1121 | WRITE_FLAG(vps->getSingleLayerForNonIrapFlag(), "single_layer_for_non_irap_flag" ); |
---|
| 1122 | #endif |
---|
[524] | 1123 | #if HIGHER_LAYER_IRAP_SKIP_FLAG |
---|
| 1124 | WRITE_FLAG(vps->getHigherLayerIrapSkipFlag(), "higher_layer_irap_skip_flag" ); |
---|
| 1125 | #endif |
---|
[544] | 1126 | #endif |
---|
[442] | 1127 | |
---|
[544] | 1128 | #if !O0109_MOVE_VPS_VUI_FLAG |
---|
[442] | 1129 | #if !VPS_VUI |
---|
| 1130 | WRITE_FLAG( 0, "vps_vui_present_flag" ); |
---|
| 1131 | #else |
---|
| 1132 | WRITE_FLAG( 1, "vps_vui_present_flag" ); |
---|
| 1133 | if(1) // Should be conditioned on the value of vps_vui_present_flag |
---|
| 1134 | { |
---|
| 1135 | while ( m_pcBitIf->getNumberOfWrittenBits() % 8 != 0 ) |
---|
| 1136 | { |
---|
| 1137 | WRITE_FLAG(1, "vps_vui_alignment_bit_equal_to_one"); |
---|
| 1138 | } |
---|
[542] | 1139 | #if VPS_VUI_OFFSET |
---|
| 1140 | Int vpsVuiOffsetValeInBits = this->m_pcBitIf->getNumberOfWrittenBits() - m_vpsVuiCounter + 16; // 2 bytes for NUH |
---|
| 1141 | assert( vpsVuiOffsetValeInBits % 8 == 0 ); |
---|
| 1142 | vps->setVpsVuiOffset( vpsVuiOffsetValeInBits >> 3 ); |
---|
| 1143 | #endif |
---|
[442] | 1144 | codeVPSVUI(vps); |
---|
| 1145 | } |
---|
| 1146 | #endif |
---|
[544] | 1147 | #else |
---|
| 1148 | if(vps->getVpsVuiPresentFlag()) // Should be conditioned on the value of vps_vui_present_flag |
---|
| 1149 | { |
---|
| 1150 | while ( m_pcBitIf->getNumberOfWrittenBits() % 8 != 0 ) |
---|
| 1151 | { |
---|
| 1152 | WRITE_FLAG(1, "vps_vui_alignment_bit_equal_to_one"); |
---|
| 1153 | } |
---|
| 1154 | #if VPS_VUI_OFFSET |
---|
| 1155 | Int vpsVuiOffsetValeInBits = this->m_pcBitIf->getNumberOfWrittenBits() - m_vpsVuiCounter + 16; // 2 bytes for NUH |
---|
| 1156 | assert( vpsVuiOffsetValeInBits % 8 == 0 ); |
---|
| 1157 | vps->setVpsVuiOffset( vpsVuiOffsetValeInBits >> 3 ); |
---|
| 1158 | #endif |
---|
| 1159 | codeVPSVUI(vps); |
---|
| 1160 | } |
---|
| 1161 | #endif // 0109_MOVE_VPS_FLAG |
---|
[313] | 1162 | } |
---|
| 1163 | #endif |
---|
[442] | 1164 | #if REPN_FORMAT_IN_VPS |
---|
| 1165 | Void TEncCavlc::codeRepFormat ( RepFormat *repFormat ) |
---|
| 1166 | { |
---|
[502] | 1167 | #if REPN_FORMAT_CONTROL_FLAG |
---|
| 1168 | WRITE_FLAG ( repFormat->getChromaAndBitDepthVpsPresentFlag(), "chroma_and_bit_depth_vps_presenet_flag"); |
---|
| 1169 | |
---|
| 1170 | WRITE_CODE ( repFormat->getPicWidthVpsInLumaSamples (), 16, "pic_width_in_luma_samples" ); |
---|
| 1171 | WRITE_CODE ( repFormat->getPicHeightVpsInLumaSamples(), 16, "pic_height_in_luma_samples" ); |
---|
| 1172 | |
---|
| 1173 | if ( repFormat->getChromaAndBitDepthVpsPresentFlag() ) |
---|
| 1174 | { |
---|
| 1175 | WRITE_CODE( repFormat->getChromaFormatVpsIdc(), 2, "chroma_format_idc" ); |
---|
| 1176 | |
---|
| 1177 | if( repFormat->getChromaFormatVpsIdc() == 3 ) |
---|
| 1178 | { |
---|
| 1179 | WRITE_FLAG( repFormat->getSeparateColourPlaneVpsFlag(), "separate_colour_plane_flag"); |
---|
| 1180 | } |
---|
| 1181 | |
---|
| 1182 | assert( repFormat->getBitDepthVpsLuma() >= 8 ); |
---|
| 1183 | assert( repFormat->getBitDepthVpsChroma() >= 8 ); |
---|
| 1184 | WRITE_CODE( repFormat->getBitDepthVpsLuma() - 8, 4, "bit_depth_luma_minus8" ); |
---|
| 1185 | WRITE_CODE( repFormat->getBitDepthVpsChroma() - 8, 4, "bit_depth_chroma_minus8" ); |
---|
| 1186 | } |
---|
| 1187 | #else |
---|
[442] | 1188 | WRITE_CODE( repFormat->getChromaFormatVpsIdc(), 2, "chroma_format_idc" ); |
---|
| 1189 | |
---|
| 1190 | if( repFormat->getChromaFormatVpsIdc() == 3 ) |
---|
| 1191 | { |
---|
| 1192 | WRITE_FLAG( repFormat->getSeparateColourPlaneVpsFlag(), "separate_colour_plane_flag"); |
---|
| 1193 | } |
---|
[313] | 1194 | |
---|
[442] | 1195 | WRITE_CODE ( repFormat->getPicWidthVpsInLumaSamples (), 16, "pic_width_in_luma_samples" ); |
---|
| 1196 | WRITE_CODE ( repFormat->getPicHeightVpsInLumaSamples(), 16, "pic_height_in_luma_samples" ); |
---|
| 1197 | |
---|
| 1198 | assert( repFormat->getBitDepthVpsLuma() >= 8 ); |
---|
| 1199 | assert( repFormat->getBitDepthVpsChroma() >= 8 ); |
---|
| 1200 | WRITE_CODE( repFormat->getBitDepthVpsLuma() - 8, 4, "bit_depth_luma_minus8" ); |
---|
[502] | 1201 | WRITE_CODE( repFormat->getBitDepthVpsChroma() - 8, 4, "bit_depth_chroma_minus8" ); |
---|
| 1202 | #endif |
---|
[442] | 1203 | |
---|
| 1204 | } |
---|
| 1205 | #endif |
---|
| 1206 | #if VPS_VUI |
---|
| 1207 | Void TEncCavlc::codeVPSVUI (TComVPS *vps) |
---|
| 1208 | { |
---|
| 1209 | Int i,j; |
---|
[530] | 1210 | #if O0223_PICTURE_TYPES_ALIGN_FLAG |
---|
| 1211 | WRITE_FLAG(vps->getCrossLayerPictureTypeAlignFlag(), "cross_layer_pic_type_aligned_flag"); |
---|
| 1212 | if (!vps->getCrossLayerPictureTypeAlignFlag()) |
---|
| 1213 | { |
---|
| 1214 | #endif |
---|
[494] | 1215 | #if IRAP_ALIGN_FLAG_IN_VPS_VUI |
---|
[530] | 1216 | WRITE_FLAG(vps->getCrossLayerIrapAlignFlag(), "cross_layer_irap_aligned_flag"); |
---|
[494] | 1217 | #endif |
---|
[530] | 1218 | #if O0223_PICTURE_TYPES_ALIGN_FLAG |
---|
| 1219 | } |
---|
| 1220 | #endif |
---|
[442] | 1221 | #if VPS_VUI_BITRATE_PICRATE |
---|
| 1222 | WRITE_FLAG( vps->getBitRatePresentVpsFlag(), "bit_rate_present_vps_flag" ); |
---|
| 1223 | WRITE_FLAG( vps->getPicRatePresentVpsFlag(), "pic_rate_present_vps_flag" ); |
---|
| 1224 | |
---|
| 1225 | if( vps->getBitRatePresentVpsFlag() || vps->getPicRatePresentVpsFlag() ) |
---|
| 1226 | { |
---|
| 1227 | for( i = 0; i < vps->getNumLayerSets(); i++ ) |
---|
| 1228 | { |
---|
| 1229 | for( j = 0; j < vps->getMaxTLayers(); j++ ) |
---|
| 1230 | { |
---|
| 1231 | if( vps->getBitRatePresentVpsFlag() ) |
---|
| 1232 | { |
---|
| 1233 | WRITE_FLAG( vps->getBitRatePresentFlag( i, j), "bit_rate_present_vps_flag[i][j]" ); |
---|
| 1234 | } |
---|
| 1235 | if( vps->getPicRatePresentVpsFlag() ) |
---|
| 1236 | { |
---|
| 1237 | WRITE_FLAG( vps->getPicRatePresentFlag( i, j), "pic_rate_present_vps_flag[i][j]" ); |
---|
| 1238 | } |
---|
| 1239 | if( vps->getBitRatePresentFlag(i, j) ) |
---|
| 1240 | { |
---|
| 1241 | WRITE_CODE( vps->getAvgBitRate( i, j ), 16, "avg_bit_rate[i][j]" ); |
---|
| 1242 | WRITE_CODE( vps->getAvgBitRate( i, j ), 16, "max_bit_rate[i][j]" ); |
---|
| 1243 | } |
---|
| 1244 | if( vps->getPicRatePresentFlag(i, j) ) |
---|
| 1245 | { |
---|
| 1246 | WRITE_CODE( vps->getConstPicRateIdc( i, j), 2 , "constant_pic_rate_idc[i][j]" ); |
---|
| 1247 | WRITE_CODE( vps->getConstPicRateIdc( i, j), 16, "avg_pic_rate[i][j]" ); |
---|
| 1248 | } |
---|
| 1249 | } |
---|
| 1250 | } |
---|
| 1251 | } |
---|
| 1252 | #endif |
---|
[530] | 1253 | #if VPS_VUI_TILES_NOT_IN_USE__FLAG |
---|
| 1254 | UInt layerIdx; |
---|
| 1255 | WRITE_FLAG( vps->getTilesNotInUseFlag() ? 1 : 0 , "tiles_not_in_use_flag" ); |
---|
| 1256 | if (!vps->getTilesNotInUseFlag()) |
---|
| 1257 | { |
---|
| 1258 | for(i = 0; i < vps->getMaxLayers(); i++) |
---|
| 1259 | { |
---|
| 1260 | WRITE_FLAG( vps->getTilesInUseFlag(i) ? 1 : 0 , "tiles_in_use_flag[ i ]" ); |
---|
| 1261 | if (vps->getTilesInUseFlag(i)) |
---|
| 1262 | { |
---|
| 1263 | WRITE_FLAG( vps->getLoopFilterNotAcrossTilesFlag(i) ? 1 : 0 , "loop_filter_not_across_tiles_flag[ i ]" ); |
---|
| 1264 | } |
---|
| 1265 | } |
---|
| 1266 | #endif |
---|
[442] | 1267 | #if TILE_BOUNDARY_ALIGNED_FLAG |
---|
[530] | 1268 | for(i = 1; i < vps->getMaxLayers(); i++) |
---|
| 1269 | { |
---|
| 1270 | for(j = 0; j < vps->getNumDirectRefLayers(vps->getLayerIdInNuh(i)); j++) |
---|
| 1271 | { |
---|
| 1272 | #if VPS_VUI_TILES_NOT_IN_USE__FLAG |
---|
| 1273 | layerIdx = vps->getLayerIdInVps(vps->getRefLayerId(vps->getLayerIdInNuh(i), j)); |
---|
| 1274 | if (vps->getTilesInUseFlag(i) && vps->getTilesInUseFlag(layerIdx)) { |
---|
| 1275 | WRITE_FLAG( vps->getTileBoundariesAlignedFlag(i,j) ? 1 : 0 , "tile_boundaries_aligned_flag[i][j]" ); |
---|
| 1276 | } |
---|
| 1277 | #else |
---|
| 1278 | WRITE_FLAG( vps->getTileBoundariesAlignedFlag(i,j) ? 1 : 0 , "tile_boundaries_aligned_flag[i][j]" ); |
---|
| 1279 | #endif |
---|
| 1280 | } |
---|
| 1281 | } |
---|
| 1282 | #endif |
---|
| 1283 | #if VPS_VUI_TILES_NOT_IN_USE__FLAG |
---|
| 1284 | } |
---|
| 1285 | #endif |
---|
| 1286 | #if VPS_VUI_WPP_NOT_IN_USE__FLAG |
---|
| 1287 | WRITE_FLAG( vps->getWppNotInUseFlag() ? 1 : 0 , "wpp_not_in_use_flag" ); |
---|
| 1288 | if (!vps->getWppNotInUseFlag()) |
---|
[442] | 1289 | { |
---|
[530] | 1290 | for(i = 0; i < vps->getMaxLayers(); i++) |
---|
[442] | 1291 | { |
---|
[530] | 1292 | WRITE_FLAG( vps->getWppInUseFlag(i) ? 1 : 0 , "wpp_in_use_flag[ i ]" ); |
---|
[442] | 1293 | } |
---|
[530] | 1294 | } |
---|
| 1295 | #endif |
---|
[544] | 1296 | |
---|
| 1297 | #if O0109_O0199_FLAGS_TO_VUI |
---|
| 1298 | #if M0040_ADAPTIVE_RESOLUTION_CHANGE |
---|
| 1299 | WRITE_FLAG(vps->getSingleLayerForNonIrapFlag(), "single_layer_for_non_irap_flag" ); |
---|
| 1300 | #endif |
---|
| 1301 | #if HIGHER_LAYER_IRAP_SKIP_FLAG |
---|
| 1302 | WRITE_FLAG(vps->getHigherLayerIrapSkipFlag(), "higher_layer_irap_skip_flag" ); |
---|
| 1303 | #endif |
---|
| 1304 | #endif |
---|
[442] | 1305 | #if N0160_VUI_EXT_ILP_REF |
---|
| 1306 | WRITE_FLAG( vps->getNumIlpRestrictedRefLayers() ? 1 : 0 , "num_ilp_restricted_ref_layers" ); |
---|
| 1307 | if( vps->getNumIlpRestrictedRefLayers()) |
---|
| 1308 | { |
---|
| 1309 | for(i = 1; i < vps->getMaxLayers(); i++) |
---|
| 1310 | { |
---|
| 1311 | for(j = 0; j < vps->getNumDirectRefLayers(vps->getLayerIdInNuh(i)); j++) |
---|
| 1312 | { |
---|
| 1313 | WRITE_UVLC(vps->getMinSpatialSegmentOffsetPlus1( i, j), "min_spatial_segment_offset_plus1[i][j]"); |
---|
| 1314 | |
---|
| 1315 | if( vps->getMinSpatialSegmentOffsetPlus1(i,j ) > 0 ) |
---|
| 1316 | { |
---|
| 1317 | WRITE_FLAG( vps->getCtuBasedOffsetEnabledFlag( i, j) ? 1 : 0 , "ctu_based_offset_enabled_flag[i][j]" ); |
---|
| 1318 | |
---|
| 1319 | if(vps->getCtuBasedOffsetEnabledFlag(i,j)) |
---|
| 1320 | { |
---|
| 1321 | WRITE_UVLC(vps->getMinHorizontalCtuOffsetPlus1( i, j), "min_horizontal_ctu_offset_plus1[i][j]"); |
---|
| 1322 | } |
---|
| 1323 | } |
---|
| 1324 | } |
---|
| 1325 | } |
---|
| 1326 | } |
---|
| 1327 | #endif |
---|
[525] | 1328 | #if VPS_VUI_VIDEO_SIGNAL |
---|
| 1329 | WRITE_FLAG( vps->getVideoSigPresentVpsFlag(), "video_signal_info_idx_present_flag" ); |
---|
| 1330 | if (vps->getVideoSigPresentVpsFlag()) |
---|
| 1331 | { |
---|
| 1332 | WRITE_CODE(vps->getNumVideoSignalInfo()-1, 4, "vps_num_video_signal_info_minus1" ); |
---|
| 1333 | } |
---|
| 1334 | |
---|
| 1335 | for(i = 0; i < vps->getNumVideoSignalInfo(); i++) |
---|
| 1336 | { |
---|
| 1337 | WRITE_CODE(vps->getVideoVPSFormat(i), 3, "video_vps_format" ); |
---|
| 1338 | WRITE_FLAG(vps->getVideoFullRangeVpsFlag(i), "video_full_range_vps_flag" ); |
---|
| 1339 | WRITE_CODE(vps->getColorPrimaries(i), 8, "color_primaries_vps" ); |
---|
| 1340 | WRITE_CODE(vps->getTransCharacter(i), 8, "transfer_characteristics_vps" ); |
---|
| 1341 | WRITE_CODE(vps->getMaxtrixCoeff(i), 8, "matrix_coeffs_vps" ); |
---|
| 1342 | } |
---|
| 1343 | |
---|
| 1344 | if (vps->getVideoSigPresentVpsFlag() && vps->getNumVideoSignalInfo() > 1 ) |
---|
| 1345 | { |
---|
| 1346 | for (i=1; i < vps->getMaxLayers(); i++) |
---|
| 1347 | WRITE_CODE(vps->getVideoSignalInfoIdx(i), 4, "vps_video_signal_info_idx" ); |
---|
| 1348 | } |
---|
| 1349 | #endif |
---|
[442] | 1350 | } |
---|
| 1351 | #endif |
---|
[494] | 1352 | #endif //SVC_EXTENSION |
---|
[442] | 1353 | |
---|
[313] | 1354 | Void TEncCavlc::codeSliceHeader ( TComSlice* pcSlice ) |
---|
| 1355 | { |
---|
| 1356 | #if ENC_DEC_TRACE |
---|
| 1357 | xTraceSliceHeader (pcSlice); |
---|
| 1358 | #endif |
---|
| 1359 | |
---|
| 1360 | //calculate number of bits required for slice address |
---|
| 1361 | Int maxSliceSegmentAddress = pcSlice->getPic()->getNumCUsInFrame(); |
---|
| 1362 | Int bitsSliceSegmentAddress = 0; |
---|
| 1363 | while(maxSliceSegmentAddress>(1<<bitsSliceSegmentAddress)) |
---|
| 1364 | { |
---|
| 1365 | bitsSliceSegmentAddress++; |
---|
| 1366 | } |
---|
| 1367 | Int ctuAddress; |
---|
| 1368 | if (pcSlice->isNextSlice()) |
---|
| 1369 | { |
---|
| 1370 | // Calculate slice address |
---|
| 1371 | ctuAddress = (pcSlice->getSliceCurStartCUAddr()/pcSlice->getPic()->getNumPartInCU()); |
---|
| 1372 | } |
---|
| 1373 | else |
---|
| 1374 | { |
---|
| 1375 | // Calculate slice address |
---|
| 1376 | ctuAddress = (pcSlice->getSliceSegmentCurStartCUAddr()/pcSlice->getPic()->getNumPartInCU()); |
---|
| 1377 | } |
---|
| 1378 | //write slice address |
---|
| 1379 | Int sliceSegmentAddress = pcSlice->getPic()->getPicSym()->getCUOrderMap(ctuAddress); |
---|
| 1380 | |
---|
| 1381 | WRITE_FLAG( sliceSegmentAddress==0, "first_slice_segment_in_pic_flag" ); |
---|
| 1382 | if ( pcSlice->getRapPicFlag() ) |
---|
| 1383 | { |
---|
| 1384 | WRITE_FLAG( 0, "no_output_of_prior_pics_flag" ); |
---|
| 1385 | } |
---|
| 1386 | WRITE_UVLC( pcSlice->getPPS()->getPPSId(), "slice_pic_parameter_set_id" ); |
---|
| 1387 | pcSlice->setDependentSliceSegmentFlag(!pcSlice->isNextSlice()); |
---|
| 1388 | if ( pcSlice->getPPS()->getDependentSliceSegmentsEnabledFlag() && (sliceSegmentAddress!=0) ) |
---|
| 1389 | { |
---|
| 1390 | WRITE_FLAG( pcSlice->getDependentSliceSegmentFlag() ? 1 : 0, "dependent_slice_segment_flag" ); |
---|
| 1391 | } |
---|
| 1392 | if(sliceSegmentAddress>0) |
---|
| 1393 | { |
---|
| 1394 | WRITE_CODE( sliceSegmentAddress, bitsSliceSegmentAddress, "slice_segment_address" ); |
---|
| 1395 | } |
---|
| 1396 | if ( !pcSlice->getDependentSliceSegmentFlag() ) |
---|
| 1397 | { |
---|
[494] | 1398 | #if SVC_EXTENSION |
---|
[442] | 1399 | #if POC_RESET_FLAG |
---|
| 1400 | Int iBits = 0; |
---|
| 1401 | if( pcSlice->getPPS()->getNumExtraSliceHeaderBits() > iBits ) |
---|
| 1402 | { |
---|
| 1403 | WRITE_FLAG( pcSlice->getPocResetFlag(), "poc_reset_flag" ); |
---|
| 1404 | iBits++; |
---|
| 1405 | } |
---|
| 1406 | if( pcSlice->getPPS()->getNumExtraSliceHeaderBits() > iBits ) |
---|
| 1407 | { |
---|
| 1408 | assert(!!"discardable_flag"); |
---|
| 1409 | WRITE_FLAG(pcSlice->getDiscardableFlag(), "discardable_flag"); |
---|
| 1410 | iBits++; |
---|
| 1411 | } |
---|
[531] | 1412 | #if O0149_CROSS_LAYER_BLA_FLAG |
---|
| 1413 | if( pcSlice->getPPS()->getNumExtraSliceHeaderBits() > iBits ) |
---|
| 1414 | { |
---|
| 1415 | assert(!!"cross_layer_bla_flag"); |
---|
| 1416 | WRITE_FLAG(pcSlice->getCrossLayerBLAFlag(), "cross_layer_bla_flag"); |
---|
| 1417 | iBits++; |
---|
| 1418 | } |
---|
| 1419 | #endif |
---|
[442] | 1420 | for ( ; iBits < pcSlice->getPPS()->getNumExtraSliceHeaderBits(); iBits++) |
---|
| 1421 | { |
---|
| 1422 | assert(!!"slice_reserved_undetermined_flag[]"); |
---|
| 1423 | WRITE_FLAG(0, "slice_reserved_undetermined_flag[]"); |
---|
| 1424 | } |
---|
| 1425 | #else |
---|
[313] | 1426 | if (pcSlice->getPPS()->getNumExtraSliceHeaderBits()>0) |
---|
| 1427 | { |
---|
| 1428 | assert(!!"discardable_flag"); |
---|
| 1429 | WRITE_FLAG(pcSlice->getDiscardableFlag(), "discardable_flag"); |
---|
| 1430 | } |
---|
| 1431 | for (Int i = 1; i < pcSlice->getPPS()->getNumExtraSliceHeaderBits(); i++) |
---|
| 1432 | { |
---|
| 1433 | assert(!!"slice_reserved_undetermined_flag[]"); |
---|
| 1434 | WRITE_FLAG(0, "slice_reserved_undetermined_flag[]"); |
---|
| 1435 | } |
---|
[494] | 1436 | #endif |
---|
| 1437 | #else //SVC_EXTENSION |
---|
[313] | 1438 | for (Int i = 0; i < pcSlice->getPPS()->getNumExtraSliceHeaderBits(); i++) |
---|
| 1439 | { |
---|
| 1440 | assert(!!"slice_reserved_undetermined_flag[]"); |
---|
| 1441 | WRITE_FLAG(0, "slice_reserved_undetermined_flag[]"); |
---|
| 1442 | } |
---|
[494] | 1443 | #endif //SVC_EXTENSION |
---|
[313] | 1444 | |
---|
| 1445 | WRITE_UVLC( pcSlice->getSliceType(), "slice_type" ); |
---|
| 1446 | |
---|
| 1447 | if( pcSlice->getPPS()->getOutputFlagPresentFlag() ) |
---|
| 1448 | { |
---|
| 1449 | WRITE_FLAG( pcSlice->getPicOutputFlag() ? 1 : 0, "pic_output_flag" ); |
---|
| 1450 | } |
---|
| 1451 | |
---|
[494] | 1452 | #if !AUXILIARY_PICTURES |
---|
[442] | 1453 | #if REPN_FORMAT_IN_VPS |
---|
[313] | 1454 | // in the first version chroma_format_idc is equal to one, thus colour_plane_id will not be present |
---|
[442] | 1455 | assert( pcSlice->getChromaFormatIdc() == 1 ); |
---|
| 1456 | #else |
---|
| 1457 | // in the first version chroma_format_idc is equal to one, thus colour_plane_id will not be present |
---|
[313] | 1458 | assert (pcSlice->getSPS()->getChromaFormatIdc() == 1 ); |
---|
[442] | 1459 | #endif |
---|
[494] | 1460 | #endif |
---|
[313] | 1461 | // if( separate_colour_plane_flag == 1 ) |
---|
| 1462 | // colour_plane_id u(2) |
---|
| 1463 | |
---|
[442] | 1464 | #if N0065_LAYER_POC_ALIGNMENT |
---|
[494] | 1465 | #if O0062_POC_LSB_NOT_PRESENT_FLAG |
---|
| 1466 | if( (pcSlice->getLayerId() > 0 && !pcSlice->getVPS()->getPocLsbNotPresentFlag( pcSlice->getVPS()->getLayerIdInVps(pcSlice->getLayerId())) ) || !pcSlice->getIdrPicFlag()) |
---|
| 1467 | #else |
---|
[442] | 1468 | if( pcSlice->getLayerId() > 0 || !pcSlice->getIdrPicFlag() ) |
---|
[494] | 1469 | #endif |
---|
[442] | 1470 | #else |
---|
[313] | 1471 | if( !pcSlice->getIdrPicFlag() ) |
---|
[442] | 1472 | #endif |
---|
[313] | 1473 | { |
---|
[442] | 1474 | #if POC_RESET_FLAG |
---|
| 1475 | Int picOrderCntLSB; |
---|
| 1476 | if( !pcSlice->getPocResetFlag() ) |
---|
| 1477 | { |
---|
| 1478 | picOrderCntLSB = (pcSlice->getPOC()-pcSlice->getLastIDR()+(1<<pcSlice->getSPS()->getBitsForPOC())) & ((1<<pcSlice->getSPS()->getBitsForPOC())-1); |
---|
| 1479 | } |
---|
| 1480 | else |
---|
| 1481 | { |
---|
| 1482 | picOrderCntLSB = (pcSlice->getPocValueBeforeReset()-pcSlice->getLastIDR()+(1<<pcSlice->getSPS()->getBitsForPOC())) & ((1<<pcSlice->getSPS()->getBitsForPOC())-1); |
---|
| 1483 | } |
---|
| 1484 | #else |
---|
| 1485 | Int picOrderCntLSB = (pcSlice->getPOC()-pcSlice->getLastIDR()+(1<<pcSlice->getSPS()->getBitsForPOC())) & ((1<<pcSlice->getSPS()->getBitsForPOC())-1); |
---|
| 1486 | #endif |
---|
[313] | 1487 | WRITE_CODE( picOrderCntLSB, pcSlice->getSPS()->getBitsForPOC(), "pic_order_cnt_lsb"); |
---|
[442] | 1488 | |
---|
| 1489 | #if N0065_LAYER_POC_ALIGNMENT |
---|
[494] | 1490 | #if SHM_FIX7 |
---|
| 1491 | } |
---|
| 1492 | #endif |
---|
[442] | 1493 | if( !pcSlice->getIdrPicFlag() ) |
---|
| 1494 | { |
---|
| 1495 | #endif |
---|
[313] | 1496 | TComReferencePictureSet* rps = pcSlice->getRPS(); |
---|
| 1497 | |
---|
| 1498 | // check for bitstream restriction stating that: |
---|
| 1499 | // If the current picture is a BLA or CRA picture, the value of NumPocTotalCurr shall be equal to 0. |
---|
| 1500 | // Ideally this process should not be repeated for each slice in a picture |
---|
| 1501 | #if SVC_EXTENSION |
---|
| 1502 | if( pcSlice->getLayerId() == 0 ) |
---|
| 1503 | #endif |
---|
| 1504 | if (pcSlice->isIRAP()) |
---|
| 1505 | { |
---|
| 1506 | for (Int picIdx = 0; picIdx < rps->getNumberOfPictures(); picIdx++) |
---|
| 1507 | { |
---|
| 1508 | assert (!rps->getUsed(picIdx)); |
---|
| 1509 | } |
---|
| 1510 | } |
---|
| 1511 | |
---|
| 1512 | if(pcSlice->getRPSidx() < 0) |
---|
| 1513 | { |
---|
| 1514 | WRITE_FLAG( 0, "short_term_ref_pic_set_sps_flag"); |
---|
| 1515 | codeShortTermRefPicSet(pcSlice->getSPS(), rps, true, pcSlice->getSPS()->getRPSList()->getNumberOfReferencePictureSets()); |
---|
| 1516 | } |
---|
| 1517 | else |
---|
| 1518 | { |
---|
| 1519 | WRITE_FLAG( 1, "short_term_ref_pic_set_sps_flag"); |
---|
| 1520 | Int numBits = 0; |
---|
| 1521 | while ((1 << numBits) < pcSlice->getSPS()->getRPSList()->getNumberOfReferencePictureSets()) |
---|
| 1522 | { |
---|
| 1523 | numBits++; |
---|
| 1524 | } |
---|
| 1525 | if (numBits > 0) |
---|
| 1526 | { |
---|
| 1527 | WRITE_CODE( pcSlice->getRPSidx(), numBits, "short_term_ref_pic_set_idx" ); |
---|
| 1528 | } |
---|
| 1529 | } |
---|
| 1530 | if(pcSlice->getSPS()->getLongTermRefsPresent()) |
---|
| 1531 | { |
---|
| 1532 | Int numLtrpInSH = rps->getNumberOfLongtermPictures(); |
---|
| 1533 | Int ltrpInSPS[MAX_NUM_REF_PICS]; |
---|
| 1534 | Int numLtrpInSPS = 0; |
---|
| 1535 | UInt ltrpIndex; |
---|
| 1536 | Int counter = 0; |
---|
| 1537 | for(Int k = rps->getNumberOfPictures()-1; k > rps->getNumberOfPictures()-rps->getNumberOfLongtermPictures()-1; k--) |
---|
| 1538 | { |
---|
| 1539 | if (findMatchingLTRP(pcSlice, <rpIndex, rps->getPOC(k), rps->getUsed(k))) |
---|
| 1540 | { |
---|
| 1541 | ltrpInSPS[numLtrpInSPS] = ltrpIndex; |
---|
| 1542 | numLtrpInSPS++; |
---|
| 1543 | } |
---|
| 1544 | else |
---|
| 1545 | { |
---|
| 1546 | counter++; |
---|
| 1547 | } |
---|
| 1548 | } |
---|
| 1549 | numLtrpInSH -= numLtrpInSPS; |
---|
| 1550 | |
---|
| 1551 | Int bitsForLtrpInSPS = 0; |
---|
| 1552 | while (pcSlice->getSPS()->getNumLongTermRefPicSPS() > (1 << bitsForLtrpInSPS)) |
---|
| 1553 | { |
---|
| 1554 | bitsForLtrpInSPS++; |
---|
| 1555 | } |
---|
| 1556 | if (pcSlice->getSPS()->getNumLongTermRefPicSPS() > 0) |
---|
| 1557 | { |
---|
| 1558 | WRITE_UVLC( numLtrpInSPS, "num_long_term_sps"); |
---|
| 1559 | } |
---|
| 1560 | WRITE_UVLC( numLtrpInSH, "num_long_term_pics"); |
---|
| 1561 | // Note that the LSBs of the LT ref. pic. POCs must be sorted before. |
---|
| 1562 | // Not sorted here because LT ref indices will be used in setRefPicList() |
---|
| 1563 | Int prevDeltaMSB = 0, prevLSB = 0; |
---|
| 1564 | Int offset = rps->getNumberOfNegativePictures() + rps->getNumberOfPositivePictures(); |
---|
| 1565 | for(Int i=rps->getNumberOfPictures()-1 ; i > offset-1; i--) |
---|
| 1566 | { |
---|
| 1567 | if (counter < numLtrpInSPS) |
---|
| 1568 | { |
---|
| 1569 | if (bitsForLtrpInSPS > 0) |
---|
| 1570 | { |
---|
| 1571 | WRITE_CODE( ltrpInSPS[counter], bitsForLtrpInSPS, "lt_idx_sps[i]"); |
---|
| 1572 | } |
---|
| 1573 | } |
---|
| 1574 | else |
---|
| 1575 | { |
---|
| 1576 | WRITE_CODE( rps->getPocLSBLT(i), pcSlice->getSPS()->getBitsForPOC(), "poc_lsb_lt"); |
---|
| 1577 | WRITE_FLAG( rps->getUsed(i), "used_by_curr_pic_lt_flag"); |
---|
| 1578 | } |
---|
| 1579 | WRITE_FLAG( rps->getDeltaPocMSBPresentFlag(i), "delta_poc_msb_present_flag"); |
---|
| 1580 | |
---|
| 1581 | if(rps->getDeltaPocMSBPresentFlag(i)) |
---|
| 1582 | { |
---|
| 1583 | Bool deltaFlag = false; |
---|
| 1584 | // First LTRP from SPS || First LTRP from SH || curr LSB != prev LSB |
---|
| 1585 | if( (i == rps->getNumberOfPictures()-1) || (i == rps->getNumberOfPictures()-1-numLtrpInSPS) || (rps->getPocLSBLT(i) != prevLSB) ) |
---|
| 1586 | { |
---|
| 1587 | deltaFlag = true; |
---|
| 1588 | } |
---|
| 1589 | if(deltaFlag) |
---|
| 1590 | { |
---|
| 1591 | WRITE_UVLC( rps->getDeltaPocMSBCycleLT(i), "delta_poc_msb_cycle_lt[i]" ); |
---|
| 1592 | } |
---|
| 1593 | else |
---|
| 1594 | { |
---|
| 1595 | Int differenceInDeltaMSB = rps->getDeltaPocMSBCycleLT(i) - prevDeltaMSB; |
---|
| 1596 | assert(differenceInDeltaMSB >= 0); |
---|
| 1597 | WRITE_UVLC( differenceInDeltaMSB, "delta_poc_msb_cycle_lt[i]" ); |
---|
| 1598 | } |
---|
| 1599 | prevLSB = rps->getPocLSBLT(i); |
---|
| 1600 | prevDeltaMSB = rps->getDeltaPocMSBCycleLT(i); |
---|
| 1601 | } |
---|
| 1602 | } |
---|
| 1603 | } |
---|
| 1604 | if (pcSlice->getSPS()->getTMVPFlagsPresent()) |
---|
| 1605 | { |
---|
| 1606 | WRITE_FLAG( pcSlice->getEnableTMVPFlag() ? 1 : 0, "slice_temporal_mvp_enable_flag" ); |
---|
| 1607 | } |
---|
[494] | 1608 | #if N0065_LAYER_POC_ALIGNMENT && !SHM_FIX7 |
---|
[442] | 1609 | } |
---|
| 1610 | #endif |
---|
[313] | 1611 | } |
---|
| 1612 | |
---|
[345] | 1613 | #if JCTVC_M0458_INTERLAYER_RPS_SIG |
---|
| 1614 | #if ILP_SSH_SIG |
---|
[494] | 1615 | #if ILP_SSH_SIG_FIX |
---|
| 1616 | if((pcSlice->getSPS()->getLayerId() > 0) && !(pcSlice->getVPS()->getIlpSshSignalingEnabledFlag()) && (pcSlice->getNumILRRefIdx() > 0) ) |
---|
| 1617 | #else |
---|
[345] | 1618 | if((pcSlice->getSPS()->getLayerId() > 0) && pcSlice->getVPS()->getIlpSshSignalingEnabledFlag() && (pcSlice->getNumILRRefIdx() > 0) ) |
---|
[494] | 1619 | #endif |
---|
[345] | 1620 | #else |
---|
| 1621 | if((pcSlice->getSPS()->getLayerId() > 0) && (pcSlice->getNumILRRefIdx() > 0) ) |
---|
| 1622 | #endif |
---|
[313] | 1623 | { |
---|
| 1624 | WRITE_FLAG(pcSlice->getInterLayerPredEnabledFlag(),"inter_layer_pred_enabled_flag"); |
---|
| 1625 | if( pcSlice->getInterLayerPredEnabledFlag()) |
---|
| 1626 | { |
---|
| 1627 | if(pcSlice->getNumILRRefIdx() > 1) |
---|
| 1628 | { |
---|
| 1629 | Int numBits = 1; |
---|
| 1630 | while ((1 << numBits) < pcSlice->getNumILRRefIdx()) |
---|
| 1631 | { |
---|
| 1632 | numBits++; |
---|
| 1633 | } |
---|
| 1634 | if( !pcSlice->getVPS()->getMaxOneActiveRefLayerFlag()) |
---|
| 1635 | { |
---|
| 1636 | WRITE_CODE(pcSlice->getActiveNumILRRefIdx() - 1, numBits,"num_inter_layer_ref_pics_minus1"); |
---|
| 1637 | } |
---|
[345] | 1638 | #if ILP_NUM_REF_CHK |
---|
| 1639 | if( pcSlice->getNumILRRefIdx() != pcSlice->getActiveNumILRRefIdx() ) |
---|
| 1640 | { |
---|
| 1641 | #endif |
---|
[313] | 1642 | for(Int i = 0; i < pcSlice->getActiveNumILRRefIdx(); i++ ) |
---|
| 1643 | { |
---|
| 1644 | WRITE_CODE(pcSlice->getInterLayerPredLayerIdc(i),numBits,"inter_layer_pred_layer_idc[i]"); |
---|
| 1645 | } |
---|
[345] | 1646 | #if ILP_NUM_REF_CHK |
---|
| 1647 | } |
---|
| 1648 | #endif |
---|
[313] | 1649 | } |
---|
| 1650 | } |
---|
| 1651 | } |
---|
| 1652 | #if M0457_IL_SAMPLE_PRED_ONLY_FLAG |
---|
| 1653 | if( pcSlice->getNumSamplePredRefLayers() > 0 && pcSlice->getActiveNumILRRefIdx() > 0 ) |
---|
| 1654 | { |
---|
| 1655 | WRITE_FLAG( pcSlice->getInterLayerSamplePredOnlyFlag(), "inter_layer_sample_pred_only_flag" ); |
---|
| 1656 | } |
---|
| 1657 | #endif |
---|
| 1658 | #endif |
---|
| 1659 | |
---|
| 1660 | if(pcSlice->getSPS()->getUseSAO()) |
---|
| 1661 | { |
---|
| 1662 | if (pcSlice->getSPS()->getUseSAO()) |
---|
| 1663 | { |
---|
[532] | 1664 | WRITE_FLAG( pcSlice->getSaoEnabledFlag(), "slice_sao_luma_flag" ); |
---|
| 1665 | #if AUXILIARY_PICTURES |
---|
| 1666 | if (pcSlice->getChromaFormatIdc() != CHROMA_400) |
---|
[313] | 1667 | { |
---|
[494] | 1668 | #endif |
---|
[532] | 1669 | #if HM_CLEANUP_SAO |
---|
| 1670 | WRITE_FLAG( pcSlice->getSaoEnabledFlagChroma(), "slice_sao_chroma_flag" ); |
---|
| 1671 | #else |
---|
| 1672 | { |
---|
[313] | 1673 | SAOParam *saoParam = pcSlice->getPic()->getPicSym()->getSaoParam(); |
---|
[532] | 1674 | WRITE_FLAG( saoParam->bSaoFlag[1], "slice_sao_chroma_flag" ); |
---|
| 1675 | } |
---|
| 1676 | #endif |
---|
[494] | 1677 | #if AUXILIARY_PICTURES |
---|
[532] | 1678 | } |
---|
[494] | 1679 | #endif |
---|
[313] | 1680 | } |
---|
[532] | 1681 | } |
---|
[313] | 1682 | |
---|
| 1683 | //check if numrefidxes match the defaults. If not, override |
---|
| 1684 | |
---|
| 1685 | if (!pcSlice->isIntra()) |
---|
| 1686 | { |
---|
| 1687 | Bool overrideFlag = (pcSlice->getNumRefIdx( REF_PIC_LIST_0 )!=pcSlice->getPPS()->getNumRefIdxL0DefaultActive()||(pcSlice->isInterB()&&pcSlice->getNumRefIdx( REF_PIC_LIST_1 )!=pcSlice->getPPS()->getNumRefIdxL1DefaultActive())); |
---|
| 1688 | WRITE_FLAG( overrideFlag ? 1 : 0, "num_ref_idx_active_override_flag"); |
---|
| 1689 | if (overrideFlag) |
---|
| 1690 | { |
---|
| 1691 | WRITE_UVLC( pcSlice->getNumRefIdx( REF_PIC_LIST_0 ) - 1, "num_ref_idx_l0_active_minus1" ); |
---|
| 1692 | if (pcSlice->isInterB()) |
---|
| 1693 | { |
---|
| 1694 | WRITE_UVLC( pcSlice->getNumRefIdx( REF_PIC_LIST_1 ) - 1, "num_ref_idx_l1_active_minus1" ); |
---|
| 1695 | } |
---|
| 1696 | else |
---|
| 1697 | { |
---|
| 1698 | pcSlice->setNumRefIdx(REF_PIC_LIST_1, 0); |
---|
| 1699 | } |
---|
| 1700 | } |
---|
| 1701 | } |
---|
| 1702 | else |
---|
| 1703 | { |
---|
| 1704 | pcSlice->setNumRefIdx(REF_PIC_LIST_0, 0); |
---|
| 1705 | pcSlice->setNumRefIdx(REF_PIC_LIST_1, 0); |
---|
| 1706 | } |
---|
| 1707 | |
---|
| 1708 | if( pcSlice->getPPS()->getListsModificationPresentFlag() && pcSlice->getNumRpsCurrTempList() > 1) |
---|
| 1709 | { |
---|
| 1710 | TComRefPicListModification* refPicListModification = pcSlice->getRefPicListModification(); |
---|
| 1711 | if(!pcSlice->isIntra()) |
---|
| 1712 | { |
---|
| 1713 | WRITE_FLAG(pcSlice->getRefPicListModification()->getRefPicListModificationFlagL0() ? 1 : 0, "ref_pic_list_modification_flag_l0" ); |
---|
| 1714 | if (pcSlice->getRefPicListModification()->getRefPicListModificationFlagL0()) |
---|
| 1715 | { |
---|
| 1716 | Int numRpsCurrTempList0 = pcSlice->getNumRpsCurrTempList(); |
---|
| 1717 | if (numRpsCurrTempList0 > 1) |
---|
| 1718 | { |
---|
| 1719 | Int length = 1; |
---|
| 1720 | numRpsCurrTempList0 --; |
---|
| 1721 | while ( numRpsCurrTempList0 >>= 1) |
---|
| 1722 | { |
---|
| 1723 | length ++; |
---|
| 1724 | } |
---|
| 1725 | for(Int i = 0; i < pcSlice->getNumRefIdx( REF_PIC_LIST_0 ); i++) |
---|
| 1726 | { |
---|
| 1727 | WRITE_CODE( refPicListModification->getRefPicSetIdxL0(i), length, "list_entry_l0"); |
---|
| 1728 | } |
---|
| 1729 | } |
---|
| 1730 | } |
---|
| 1731 | } |
---|
| 1732 | if(pcSlice->isInterB()) |
---|
| 1733 | { |
---|
| 1734 | WRITE_FLAG(pcSlice->getRefPicListModification()->getRefPicListModificationFlagL1() ? 1 : 0, "ref_pic_list_modification_flag_l1" ); |
---|
| 1735 | if (pcSlice->getRefPicListModification()->getRefPicListModificationFlagL1()) |
---|
| 1736 | { |
---|
| 1737 | Int numRpsCurrTempList1 = pcSlice->getNumRpsCurrTempList(); |
---|
| 1738 | if ( numRpsCurrTempList1 > 1 ) |
---|
| 1739 | { |
---|
| 1740 | Int length = 1; |
---|
| 1741 | numRpsCurrTempList1 --; |
---|
| 1742 | while ( numRpsCurrTempList1 >>= 1) |
---|
| 1743 | { |
---|
| 1744 | length ++; |
---|
| 1745 | } |
---|
| 1746 | for(Int i = 0; i < pcSlice->getNumRefIdx( REF_PIC_LIST_1 ); i++) |
---|
| 1747 | { |
---|
| 1748 | WRITE_CODE( refPicListModification->getRefPicSetIdxL1(i), length, "list_entry_l1"); |
---|
| 1749 | } |
---|
| 1750 | } |
---|
| 1751 | } |
---|
| 1752 | } |
---|
| 1753 | } |
---|
| 1754 | |
---|
| 1755 | if (pcSlice->isInterB()) |
---|
| 1756 | { |
---|
| 1757 | WRITE_FLAG( pcSlice->getMvdL1ZeroFlag() ? 1 : 0, "mvd_l1_zero_flag"); |
---|
| 1758 | } |
---|
| 1759 | |
---|
| 1760 | if(!pcSlice->isIntra()) |
---|
| 1761 | { |
---|
| 1762 | if (!pcSlice->isIntra() && pcSlice->getPPS()->getCabacInitPresentFlag()) |
---|
| 1763 | { |
---|
| 1764 | SliceType sliceType = pcSlice->getSliceType(); |
---|
| 1765 | Int encCABACTableIdx = pcSlice->getPPS()->getEncCABACTableIdx(); |
---|
| 1766 | Bool encCabacInitFlag = (sliceType!=encCABACTableIdx && encCABACTableIdx!=I_SLICE) ? true : false; |
---|
| 1767 | pcSlice->setCabacInitFlag( encCabacInitFlag ); |
---|
| 1768 | WRITE_FLAG( encCabacInitFlag?1:0, "cabac_init_flag" ); |
---|
| 1769 | } |
---|
| 1770 | } |
---|
| 1771 | |
---|
| 1772 | if ( pcSlice->getEnableTMVPFlag() ) |
---|
| 1773 | { |
---|
[442] | 1774 | #if SVC_EXTENSION && M0457_COL_PICTURE_SIGNALING && !REMOVE_COL_PICTURE_SIGNALING |
---|
[313] | 1775 | if ( !pcSlice->getIdrPicFlag() && pcSlice->getLayerId() > 0 && pcSlice->getActiveNumILRRefIdx() > 0 && pcSlice->getNumMotionPredRefLayers() > 0 ) |
---|
| 1776 | { |
---|
| 1777 | WRITE_FLAG( pcSlice->getAltColIndicationFlag() ? 1 : 0, "alt_collocated_indication_flag" ); |
---|
| 1778 | if (pcSlice->getAltColIndicationFlag() && pcSlice->getNumMotionPredRefLayers() > 1) |
---|
| 1779 | { |
---|
| 1780 | WRITE_UVLC(0, "collocated_ref_layer_idx"); |
---|
| 1781 | } |
---|
| 1782 | } |
---|
| 1783 | else |
---|
| 1784 | { |
---|
| 1785 | #endif |
---|
| 1786 | if ( pcSlice->getSliceType() == B_SLICE ) |
---|
| 1787 | { |
---|
| 1788 | WRITE_FLAG( pcSlice->getColFromL0Flag(), "collocated_from_l0_flag" ); |
---|
| 1789 | } |
---|
| 1790 | |
---|
| 1791 | if ( pcSlice->getSliceType() != I_SLICE && |
---|
| 1792 | ((pcSlice->getColFromL0Flag()==1 && pcSlice->getNumRefIdx(REF_PIC_LIST_0)>1)|| |
---|
| 1793 | (pcSlice->getColFromL0Flag()==0 && pcSlice->getNumRefIdx(REF_PIC_LIST_1)>1))) |
---|
| 1794 | { |
---|
| 1795 | WRITE_UVLC( pcSlice->getColRefIdx(), "collocated_ref_idx" ); |
---|
| 1796 | } |
---|
[442] | 1797 | #if SVC_EXTENSION && M0457_COL_PICTURE_SIGNALING && !REMOVE_COL_PICTURE_SIGNALING |
---|
[313] | 1798 | } |
---|
| 1799 | #endif |
---|
| 1800 | } |
---|
| 1801 | if ( (pcSlice->getPPS()->getUseWP() && pcSlice->getSliceType()==P_SLICE) || (pcSlice->getPPS()->getWPBiPred() && pcSlice->getSliceType()==B_SLICE) ) |
---|
| 1802 | { |
---|
| 1803 | xCodePredWeightTable( pcSlice ); |
---|
| 1804 | } |
---|
| 1805 | assert(pcSlice->getMaxNumMergeCand()<=MRG_MAX_NUM_CANDS); |
---|
| 1806 | if (!pcSlice->isIntra()) |
---|
| 1807 | { |
---|
| 1808 | WRITE_UVLC(MRG_MAX_NUM_CANDS - pcSlice->getMaxNumMergeCand(), "five_minus_max_num_merge_cand"); |
---|
| 1809 | } |
---|
| 1810 | Int iCode = pcSlice->getSliceQp() - ( pcSlice->getPPS()->getPicInitQPMinus26() + 26 ); |
---|
| 1811 | WRITE_SVLC( iCode, "slice_qp_delta" ); |
---|
| 1812 | if (pcSlice->getPPS()->getSliceChromaQpFlag()) |
---|
| 1813 | { |
---|
| 1814 | iCode = pcSlice->getSliceQpDeltaCb(); |
---|
| 1815 | WRITE_SVLC( iCode, "slice_qp_delta_cb" ); |
---|
| 1816 | iCode = pcSlice->getSliceQpDeltaCr(); |
---|
| 1817 | WRITE_SVLC( iCode, "slice_qp_delta_cr" ); |
---|
| 1818 | } |
---|
| 1819 | if (pcSlice->getPPS()->getDeblockingFilterControlPresentFlag()) |
---|
| 1820 | { |
---|
| 1821 | if (pcSlice->getPPS()->getDeblockingFilterOverrideEnabledFlag() ) |
---|
| 1822 | { |
---|
| 1823 | WRITE_FLAG(pcSlice->getDeblockingFilterOverrideFlag(), "deblocking_filter_override_flag"); |
---|
| 1824 | } |
---|
| 1825 | if (pcSlice->getDeblockingFilterOverrideFlag()) |
---|
| 1826 | { |
---|
| 1827 | WRITE_FLAG(pcSlice->getDeblockingFilterDisable(), "slice_disable_deblocking_filter_flag"); |
---|
| 1828 | if(!pcSlice->getDeblockingFilterDisable()) |
---|
| 1829 | { |
---|
| 1830 | WRITE_SVLC (pcSlice->getDeblockingFilterBetaOffsetDiv2(), "slice_beta_offset_div2"); |
---|
| 1831 | WRITE_SVLC (pcSlice->getDeblockingFilterTcOffsetDiv2(), "slice_tc_offset_div2"); |
---|
| 1832 | } |
---|
| 1833 | } |
---|
| 1834 | } |
---|
| 1835 | |
---|
| 1836 | Bool isSAOEnabled = (!pcSlice->getSPS()->getUseSAO())?(false):(pcSlice->getSaoEnabledFlag()||pcSlice->getSaoEnabledFlagChroma()); |
---|
| 1837 | Bool isDBFEnabled = (!pcSlice->getDeblockingFilterDisable()); |
---|
| 1838 | |
---|
| 1839 | if(pcSlice->getPPS()->getLoopFilterAcrossSlicesEnabledFlag() && ( isSAOEnabled || isDBFEnabled )) |
---|
| 1840 | { |
---|
| 1841 | WRITE_FLAG(pcSlice->getLFCrossSliceBoundaryFlag()?1:0, "slice_loop_filter_across_slices_enabled_flag"); |
---|
| 1842 | } |
---|
| 1843 | } |
---|
| 1844 | if(pcSlice->getPPS()->getSliceHeaderExtensionPresentFlag()) |
---|
| 1845 | { |
---|
| 1846 | WRITE_UVLC(0,"slice_header_extension_length"); |
---|
| 1847 | } |
---|
| 1848 | } |
---|
| 1849 | |
---|
| 1850 | Void TEncCavlc::codePTL( TComPTL* pcPTL, Bool profilePresentFlag, Int maxNumSubLayersMinus1) |
---|
| 1851 | { |
---|
| 1852 | if(profilePresentFlag) |
---|
| 1853 | { |
---|
| 1854 | codeProfileTier(pcPTL->getGeneralPTL()); // general_... |
---|
| 1855 | } |
---|
| 1856 | WRITE_CODE( pcPTL->getGeneralPTL()->getLevelIdc(), 8, "general_level_idc" ); |
---|
| 1857 | |
---|
| 1858 | for (Int i = 0; i < maxNumSubLayersMinus1; i++) |
---|
| 1859 | { |
---|
| 1860 | if(profilePresentFlag) |
---|
| 1861 | { |
---|
| 1862 | WRITE_FLAG( pcPTL->getSubLayerProfilePresentFlag(i), "sub_layer_profile_present_flag[i]" ); |
---|
| 1863 | } |
---|
| 1864 | |
---|
| 1865 | WRITE_FLAG( pcPTL->getSubLayerLevelPresentFlag(i), "sub_layer_level_present_flag[i]" ); |
---|
| 1866 | } |
---|
| 1867 | |
---|
| 1868 | if (maxNumSubLayersMinus1 > 0) |
---|
| 1869 | { |
---|
| 1870 | for (Int i = maxNumSubLayersMinus1; i < 8; i++) |
---|
| 1871 | { |
---|
| 1872 | WRITE_CODE(0, 2, "reserved_zero_2bits"); |
---|
| 1873 | } |
---|
| 1874 | } |
---|
| 1875 | |
---|
| 1876 | for(Int i = 0; i < maxNumSubLayersMinus1; i++) |
---|
| 1877 | { |
---|
| 1878 | if( profilePresentFlag && pcPTL->getSubLayerProfilePresentFlag(i) ) |
---|
| 1879 | { |
---|
| 1880 | codeProfileTier(pcPTL->getSubLayerPTL(i)); // sub_layer_... |
---|
| 1881 | } |
---|
| 1882 | if( pcPTL->getSubLayerLevelPresentFlag(i) ) |
---|
| 1883 | { |
---|
| 1884 | WRITE_CODE( pcPTL->getSubLayerPTL(i)->getLevelIdc(), 8, "sub_layer_level_idc[i]" ); |
---|
| 1885 | } |
---|
| 1886 | } |
---|
| 1887 | } |
---|
| 1888 | Void TEncCavlc::codeProfileTier( ProfileTierLevel* ptl ) |
---|
| 1889 | { |
---|
| 1890 | WRITE_CODE( ptl->getProfileSpace(), 2 , "XXX_profile_space[]"); |
---|
| 1891 | WRITE_FLAG( ptl->getTierFlag (), "XXX_tier_flag[]" ); |
---|
| 1892 | WRITE_CODE( ptl->getProfileIdc (), 5 , "XXX_profile_idc[]" ); |
---|
| 1893 | for(Int j = 0; j < 32; j++) |
---|
| 1894 | { |
---|
| 1895 | WRITE_FLAG( ptl->getProfileCompatibilityFlag(j), "XXX_profile_compatibility_flag[][j]"); |
---|
| 1896 | } |
---|
| 1897 | |
---|
| 1898 | WRITE_FLAG(ptl->getProgressiveSourceFlag(), "general_progressive_source_flag"); |
---|
| 1899 | WRITE_FLAG(ptl->getInterlacedSourceFlag(), "general_interlaced_source_flag"); |
---|
| 1900 | WRITE_FLAG(ptl->getNonPackedConstraintFlag(), "general_non_packed_constraint_flag"); |
---|
| 1901 | WRITE_FLAG(ptl->getFrameOnlyConstraintFlag(), "general_frame_only_constraint_flag"); |
---|
| 1902 | |
---|
| 1903 | WRITE_CODE(0 , 16, "XXX_reserved_zero_44bits[0..15]"); |
---|
| 1904 | WRITE_CODE(0 , 16, "XXX_reserved_zero_44bits[16..31]"); |
---|
| 1905 | WRITE_CODE(0 , 12, "XXX_reserved_zero_44bits[32..43]"); |
---|
| 1906 | } |
---|
| 1907 | |
---|
| 1908 | /** |
---|
| 1909 | - write wavefront substreams sizes for the slice header. |
---|
| 1910 | . |
---|
| 1911 | \param pcSlice Where we find the substream size information. |
---|
| 1912 | */ |
---|
| 1913 | Void TEncCavlc::codeTilesWPPEntryPoint( TComSlice* pSlice ) |
---|
| 1914 | { |
---|
| 1915 | if (!pSlice->getPPS()->getTilesEnabledFlag() && !pSlice->getPPS()->getEntropyCodingSyncEnabledFlag()) |
---|
| 1916 | { |
---|
| 1917 | return; |
---|
| 1918 | } |
---|
| 1919 | UInt numEntryPointOffsets = 0, offsetLenMinus1 = 0, maxOffset = 0; |
---|
| 1920 | Int numZeroSubstreamsAtStartOfSlice = 0; |
---|
| 1921 | UInt *entryPointOffset = NULL; |
---|
| 1922 | if ( pSlice->getPPS()->getTilesEnabledFlag() ) |
---|
| 1923 | { |
---|
| 1924 | numEntryPointOffsets = pSlice->getTileLocationCount(); |
---|
| 1925 | entryPointOffset = new UInt[numEntryPointOffsets]; |
---|
| 1926 | for (Int idx=0; idx<pSlice->getTileLocationCount(); idx++) |
---|
| 1927 | { |
---|
| 1928 | if ( idx == 0 ) |
---|
| 1929 | { |
---|
| 1930 | entryPointOffset [ idx ] = pSlice->getTileLocation( 0 ); |
---|
| 1931 | } |
---|
| 1932 | else |
---|
| 1933 | { |
---|
| 1934 | entryPointOffset [ idx ] = pSlice->getTileLocation( idx ) - pSlice->getTileLocation( idx-1 ); |
---|
| 1935 | } |
---|
| 1936 | |
---|
| 1937 | if ( entryPointOffset[ idx ] > maxOffset ) |
---|
| 1938 | { |
---|
| 1939 | maxOffset = entryPointOffset[ idx ]; |
---|
| 1940 | } |
---|
| 1941 | } |
---|
| 1942 | } |
---|
| 1943 | else if ( pSlice->getPPS()->getEntropyCodingSyncEnabledFlag() ) |
---|
| 1944 | { |
---|
| 1945 | UInt* pSubstreamSizes = pSlice->getSubstreamSizes(); |
---|
| 1946 | Int maxNumParts = pSlice->getPic()->getNumPartInCU(); |
---|
| 1947 | numZeroSubstreamsAtStartOfSlice = pSlice->getSliceSegmentCurStartCUAddr()/maxNumParts/pSlice->getPic()->getFrameWidthInCU(); |
---|
| 1948 | Int numZeroSubstreamsAtEndOfSlice = pSlice->getPic()->getFrameHeightInCU()-1 - ((pSlice->getSliceSegmentCurEndCUAddr()-1)/maxNumParts/pSlice->getPic()->getFrameWidthInCU()); |
---|
| 1949 | numEntryPointOffsets = pSlice->getPPS()->getNumSubstreams() - numZeroSubstreamsAtStartOfSlice - numZeroSubstreamsAtEndOfSlice - 1; |
---|
| 1950 | pSlice->setNumEntryPointOffsets(numEntryPointOffsets); |
---|
| 1951 | entryPointOffset = new UInt[numEntryPointOffsets]; |
---|
| 1952 | for (Int idx=0; idx<numEntryPointOffsets; idx++) |
---|
| 1953 | { |
---|
| 1954 | entryPointOffset[ idx ] = ( pSubstreamSizes[ idx+numZeroSubstreamsAtStartOfSlice ] >> 3 ) ; |
---|
| 1955 | if ( entryPointOffset[ idx ] > maxOffset ) |
---|
| 1956 | { |
---|
| 1957 | maxOffset = entryPointOffset[ idx ]; |
---|
| 1958 | } |
---|
| 1959 | } |
---|
| 1960 | } |
---|
| 1961 | // Determine number of bits "offsetLenMinus1+1" required for entry point information |
---|
| 1962 | offsetLenMinus1 = 0; |
---|
| 1963 | while (maxOffset >= (1u << (offsetLenMinus1 + 1))) |
---|
| 1964 | { |
---|
| 1965 | offsetLenMinus1++; |
---|
| 1966 | assert(offsetLenMinus1 + 1 < 32); |
---|
| 1967 | } |
---|
| 1968 | |
---|
| 1969 | WRITE_UVLC(numEntryPointOffsets, "num_entry_point_offsets"); |
---|
| 1970 | if (numEntryPointOffsets>0) |
---|
| 1971 | { |
---|
| 1972 | WRITE_UVLC(offsetLenMinus1, "offset_len_minus1"); |
---|
| 1973 | } |
---|
| 1974 | |
---|
| 1975 | for (UInt idx=0; idx<numEntryPointOffsets; idx++) |
---|
| 1976 | { |
---|
| 1977 | WRITE_CODE(entryPointOffset[ idx ]-1, offsetLenMinus1+1, "entry_point_offset_minus1"); |
---|
| 1978 | } |
---|
| 1979 | |
---|
| 1980 | delete [] entryPointOffset; |
---|
| 1981 | } |
---|
| 1982 | |
---|
| 1983 | Void TEncCavlc::codeTerminatingBit ( UInt uilsLast ) |
---|
| 1984 | { |
---|
| 1985 | } |
---|
| 1986 | |
---|
| 1987 | Void TEncCavlc::codeSliceFinish () |
---|
| 1988 | { |
---|
| 1989 | } |
---|
| 1990 | |
---|
| 1991 | Void TEncCavlc::codeMVPIdx ( TComDataCU* pcCU, UInt uiAbsPartIdx, RefPicList eRefList ) |
---|
| 1992 | { |
---|
| 1993 | assert(0); |
---|
| 1994 | } |
---|
| 1995 | |
---|
| 1996 | Void TEncCavlc::codePartSize( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth ) |
---|
| 1997 | { |
---|
| 1998 | assert(0); |
---|
| 1999 | } |
---|
| 2000 | |
---|
| 2001 | Void TEncCavlc::codePredMode( TComDataCU* pcCU, UInt uiAbsPartIdx ) |
---|
| 2002 | { |
---|
| 2003 | assert(0); |
---|
| 2004 | } |
---|
| 2005 | |
---|
| 2006 | Void TEncCavlc::codeMergeFlag ( TComDataCU* pcCU, UInt uiAbsPartIdx ) |
---|
| 2007 | { |
---|
| 2008 | assert(0); |
---|
| 2009 | } |
---|
| 2010 | |
---|
| 2011 | Void TEncCavlc::codeMergeIndex ( TComDataCU* pcCU, UInt uiAbsPartIdx ) |
---|
| 2012 | { |
---|
| 2013 | assert(0); |
---|
| 2014 | } |
---|
| 2015 | |
---|
| 2016 | Void TEncCavlc::codeInterModeFlag( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, UInt uiEncMode ) |
---|
| 2017 | { |
---|
| 2018 | assert(0); |
---|
| 2019 | } |
---|
| 2020 | |
---|
| 2021 | Void TEncCavlc::codeCUTransquantBypassFlag( TComDataCU* pcCU, UInt uiAbsPartIdx ) |
---|
| 2022 | { |
---|
| 2023 | assert(0); |
---|
| 2024 | } |
---|
| 2025 | |
---|
| 2026 | Void TEncCavlc::codeSkipFlag( TComDataCU* pcCU, UInt uiAbsPartIdx ) |
---|
| 2027 | { |
---|
| 2028 | assert(0); |
---|
| 2029 | } |
---|
| 2030 | |
---|
| 2031 | Void TEncCavlc::codeSplitFlag ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth ) |
---|
| 2032 | { |
---|
| 2033 | assert(0); |
---|
| 2034 | } |
---|
| 2035 | |
---|
| 2036 | Void TEncCavlc::codeTransformSubdivFlag( UInt uiSymbol, UInt uiCtx ) |
---|
| 2037 | { |
---|
| 2038 | assert(0); |
---|
| 2039 | } |
---|
| 2040 | |
---|
| 2041 | Void TEncCavlc::codeQtCbf( TComDataCU* pcCU, UInt uiAbsPartIdx, TextType eType, UInt uiTrDepth ) |
---|
| 2042 | { |
---|
| 2043 | assert(0); |
---|
| 2044 | } |
---|
| 2045 | |
---|
| 2046 | Void TEncCavlc::codeQtRootCbf( TComDataCU* pcCU, UInt uiAbsPartIdx ) |
---|
| 2047 | { |
---|
| 2048 | assert(0); |
---|
| 2049 | } |
---|
| 2050 | |
---|
| 2051 | Void TEncCavlc::codeQtCbfZero( TComDataCU* pcCU, TextType eType, UInt uiTrDepth ) |
---|
| 2052 | { |
---|
| 2053 | assert(0); |
---|
| 2054 | } |
---|
| 2055 | Void TEncCavlc::codeQtRootCbfZero( TComDataCU* pcCU ) |
---|
| 2056 | { |
---|
| 2057 | assert(0); |
---|
| 2058 | } |
---|
| 2059 | |
---|
| 2060 | Void TEncCavlc::codeTransformSkipFlags (TComDataCU* pcCU, UInt uiAbsPartIdx, UInt width, UInt height, TextType eTType ) |
---|
| 2061 | { |
---|
| 2062 | assert(0); |
---|
| 2063 | } |
---|
| 2064 | |
---|
| 2065 | /** Code I_PCM information. |
---|
| 2066 | * \param pcCU pointer to CU |
---|
| 2067 | * \param uiAbsPartIdx CU index |
---|
| 2068 | * \returns Void |
---|
| 2069 | */ |
---|
| 2070 | Void TEncCavlc::codeIPCMInfo( TComDataCU* pcCU, UInt uiAbsPartIdx ) |
---|
| 2071 | { |
---|
| 2072 | assert(0); |
---|
| 2073 | } |
---|
| 2074 | |
---|
| 2075 | Void TEncCavlc::codeIntraDirLumaAng( TComDataCU* pcCU, UInt uiAbsPartIdx, Bool isMultiple) |
---|
| 2076 | { |
---|
| 2077 | assert(0); |
---|
| 2078 | } |
---|
| 2079 | |
---|
| 2080 | Void TEncCavlc::codeIntraDirChroma( TComDataCU* pcCU, UInt uiAbsPartIdx ) |
---|
| 2081 | { |
---|
| 2082 | assert(0); |
---|
| 2083 | } |
---|
| 2084 | |
---|
| 2085 | Void TEncCavlc::codeInterDir( TComDataCU* pcCU, UInt uiAbsPartIdx ) |
---|
| 2086 | { |
---|
| 2087 | assert(0); |
---|
| 2088 | } |
---|
| 2089 | |
---|
| 2090 | Void TEncCavlc::codeRefFrmIdx( TComDataCU* pcCU, UInt uiAbsPartIdx, RefPicList eRefList ) |
---|
| 2091 | { |
---|
| 2092 | assert(0); |
---|
| 2093 | } |
---|
| 2094 | |
---|
| 2095 | Void TEncCavlc::codeMvd( TComDataCU* pcCU, UInt uiAbsPartIdx, RefPicList eRefList ) |
---|
| 2096 | { |
---|
| 2097 | assert(0); |
---|
| 2098 | } |
---|
| 2099 | |
---|
| 2100 | Void TEncCavlc::codeDeltaQP( TComDataCU* pcCU, UInt uiAbsPartIdx ) |
---|
| 2101 | { |
---|
| 2102 | Int iDQp = pcCU->getQP( uiAbsPartIdx ) - pcCU->getRefQP( uiAbsPartIdx ); |
---|
| 2103 | |
---|
[442] | 2104 | #if REPN_FORMAT_IN_VPS |
---|
| 2105 | Int qpBdOffsetY = pcCU->getSlice()->getQpBDOffsetY(); |
---|
| 2106 | #else |
---|
[313] | 2107 | Int qpBdOffsetY = pcCU->getSlice()->getSPS()->getQpBDOffsetY(); |
---|
[442] | 2108 | #endif |
---|
[313] | 2109 | iDQp = (iDQp + 78 + qpBdOffsetY + (qpBdOffsetY/2)) % (52 + qpBdOffsetY) - 26 - (qpBdOffsetY/2); |
---|
| 2110 | |
---|
| 2111 | xWriteSvlc( iDQp ); |
---|
| 2112 | |
---|
| 2113 | return; |
---|
| 2114 | } |
---|
| 2115 | |
---|
| 2116 | Void TEncCavlc::codeCoeffNxN ( TComDataCU* pcCU, TCoeff* pcCoef, UInt uiAbsPartIdx, UInt uiWidth, UInt uiHeight, UInt uiDepth, TextType eTType ) |
---|
| 2117 | { |
---|
| 2118 | assert(0); |
---|
| 2119 | } |
---|
| 2120 | |
---|
| 2121 | Void TEncCavlc::estBit( estBitsSbacStruct* pcEstBitsCabac, Int width, Int height, TextType eTType ) |
---|
| 2122 | { |
---|
| 2123 | // printf("error : no VLC mode support in this version\n"); |
---|
| 2124 | return; |
---|
| 2125 | } |
---|
| 2126 | |
---|
| 2127 | // ==================================================================================================================== |
---|
| 2128 | // Protected member functions |
---|
| 2129 | // ==================================================================================================================== |
---|
| 2130 | |
---|
| 2131 | /** code explicit wp tables |
---|
| 2132 | * \param TComSlice* pcSlice |
---|
| 2133 | * \returns Void |
---|
| 2134 | */ |
---|
| 2135 | Void TEncCavlc::xCodePredWeightTable( TComSlice* pcSlice ) |
---|
| 2136 | { |
---|
| 2137 | wpScalingParam *wp; |
---|
| 2138 | Bool bChroma = true; // color always present in HEVC ? |
---|
| 2139 | Int iNbRef = (pcSlice->getSliceType() == B_SLICE ) ? (2) : (1); |
---|
| 2140 | Bool bDenomCoded = false; |
---|
| 2141 | UInt uiMode = 0; |
---|
| 2142 | UInt uiTotalSignalledWeightFlags = 0; |
---|
[494] | 2143 | #if AUXILIARY_PICTURES |
---|
| 2144 | if (pcSlice->getChromaFormatIdc() == CHROMA_400) |
---|
| 2145 | { |
---|
| 2146 | bChroma = false; |
---|
| 2147 | } |
---|
| 2148 | #endif |
---|
[313] | 2149 | if ( (pcSlice->getSliceType()==P_SLICE && pcSlice->getPPS()->getUseWP()) || (pcSlice->getSliceType()==B_SLICE && pcSlice->getPPS()->getWPBiPred()) ) |
---|
| 2150 | { |
---|
| 2151 | uiMode = 1; // explicit |
---|
| 2152 | } |
---|
| 2153 | if(uiMode == 1) |
---|
| 2154 | { |
---|
| 2155 | |
---|
| 2156 | for ( Int iNumRef=0 ; iNumRef<iNbRef ; iNumRef++ ) |
---|
| 2157 | { |
---|
| 2158 | RefPicList eRefPicList = ( iNumRef ? REF_PIC_LIST_1 : REF_PIC_LIST_0 ); |
---|
| 2159 | |
---|
| 2160 | for ( Int iRefIdx=0 ; iRefIdx<pcSlice->getNumRefIdx(eRefPicList) ; iRefIdx++ ) |
---|
| 2161 | { |
---|
| 2162 | pcSlice->getWpScaling(eRefPicList, iRefIdx, wp); |
---|
| 2163 | if ( !bDenomCoded ) |
---|
| 2164 | { |
---|
| 2165 | Int iDeltaDenom; |
---|
| 2166 | WRITE_UVLC( wp[0].uiLog2WeightDenom, "luma_log2_weight_denom" ); // ue(v): luma_log2_weight_denom |
---|
| 2167 | |
---|
| 2168 | if( bChroma ) |
---|
| 2169 | { |
---|
| 2170 | iDeltaDenom = (wp[1].uiLog2WeightDenom - wp[0].uiLog2WeightDenom); |
---|
| 2171 | WRITE_SVLC( iDeltaDenom, "delta_chroma_log2_weight_denom" ); // se(v): delta_chroma_log2_weight_denom |
---|
| 2172 | } |
---|
| 2173 | bDenomCoded = true; |
---|
| 2174 | } |
---|
| 2175 | WRITE_FLAG( wp[0].bPresentFlag, "luma_weight_lX_flag" ); // u(1): luma_weight_lX_flag |
---|
| 2176 | uiTotalSignalledWeightFlags += wp[0].bPresentFlag; |
---|
| 2177 | } |
---|
| 2178 | if (bChroma) |
---|
| 2179 | { |
---|
| 2180 | for ( Int iRefIdx=0 ; iRefIdx<pcSlice->getNumRefIdx(eRefPicList) ; iRefIdx++ ) |
---|
| 2181 | { |
---|
| 2182 | pcSlice->getWpScaling(eRefPicList, iRefIdx, wp); |
---|
| 2183 | WRITE_FLAG( wp[1].bPresentFlag, "chroma_weight_lX_flag" ); // u(1): chroma_weight_lX_flag |
---|
| 2184 | uiTotalSignalledWeightFlags += 2*wp[1].bPresentFlag; |
---|
| 2185 | } |
---|
| 2186 | } |
---|
| 2187 | |
---|
| 2188 | for ( Int iRefIdx=0 ; iRefIdx<pcSlice->getNumRefIdx(eRefPicList) ; iRefIdx++ ) |
---|
| 2189 | { |
---|
| 2190 | pcSlice->getWpScaling(eRefPicList, iRefIdx, wp); |
---|
| 2191 | if ( wp[0].bPresentFlag ) |
---|
| 2192 | { |
---|
| 2193 | Int iDeltaWeight = (wp[0].iWeight - (1<<wp[0].uiLog2WeightDenom)); |
---|
| 2194 | WRITE_SVLC( iDeltaWeight, "delta_luma_weight_lX" ); // se(v): delta_luma_weight_lX |
---|
| 2195 | WRITE_SVLC( wp[0].iOffset, "luma_offset_lX" ); // se(v): luma_offset_lX |
---|
| 2196 | } |
---|
| 2197 | |
---|
| 2198 | if ( bChroma ) |
---|
| 2199 | { |
---|
| 2200 | if ( wp[1].bPresentFlag ) |
---|
| 2201 | { |
---|
| 2202 | for ( Int j=1 ; j<3 ; j++ ) |
---|
| 2203 | { |
---|
| 2204 | Int iDeltaWeight = (wp[j].iWeight - (1<<wp[1].uiLog2WeightDenom)); |
---|
| 2205 | WRITE_SVLC( iDeltaWeight, "delta_chroma_weight_lX" ); // se(v): delta_chroma_weight_lX |
---|
| 2206 | |
---|
| 2207 | Int pred = ( 128 - ( ( 128*wp[j].iWeight)>>(wp[j].uiLog2WeightDenom) ) ); |
---|
| 2208 | Int iDeltaChroma = (wp[j].iOffset - pred); |
---|
| 2209 | WRITE_SVLC( iDeltaChroma, "delta_chroma_offset_lX" ); // se(v): delta_chroma_offset_lX |
---|
| 2210 | } |
---|
| 2211 | } |
---|
| 2212 | } |
---|
| 2213 | } |
---|
| 2214 | } |
---|
| 2215 | assert(uiTotalSignalledWeightFlags<=24); |
---|
| 2216 | } |
---|
| 2217 | } |
---|
| 2218 | |
---|
| 2219 | /** code quantization matrix |
---|
| 2220 | * \param scalingList quantization matrix information |
---|
| 2221 | */ |
---|
| 2222 | Void TEncCavlc::codeScalingList( TComScalingList* scalingList ) |
---|
| 2223 | { |
---|
| 2224 | UInt listId,sizeId; |
---|
| 2225 | Bool scalingListPredModeFlag; |
---|
| 2226 | |
---|
| 2227 | //for each size |
---|
| 2228 | for(sizeId = 0; sizeId < SCALING_LIST_SIZE_NUM; sizeId++) |
---|
| 2229 | { |
---|
| 2230 | for(listId = 0; listId < g_scalingListNum[sizeId]; listId++) |
---|
| 2231 | { |
---|
| 2232 | scalingListPredModeFlag = scalingList->checkPredMode( sizeId, listId ); |
---|
| 2233 | WRITE_FLAG( scalingListPredModeFlag, "scaling_list_pred_mode_flag" ); |
---|
| 2234 | if(!scalingListPredModeFlag)// Copy Mode |
---|
| 2235 | { |
---|
| 2236 | WRITE_UVLC( (Int)listId - (Int)scalingList->getRefMatrixId (sizeId,listId), "scaling_list_pred_matrix_id_delta"); |
---|
| 2237 | } |
---|
| 2238 | else// DPCM Mode |
---|
| 2239 | { |
---|
| 2240 | xCodeScalingList(scalingList, sizeId, listId); |
---|
| 2241 | } |
---|
| 2242 | } |
---|
| 2243 | } |
---|
| 2244 | return; |
---|
| 2245 | } |
---|
| 2246 | /** code DPCM |
---|
| 2247 | * \param scalingList quantization matrix information |
---|
| 2248 | * \param sizeIdc size index |
---|
| 2249 | * \param listIdc list index |
---|
| 2250 | */ |
---|
| 2251 | Void TEncCavlc::xCodeScalingList(TComScalingList* scalingList, UInt sizeId, UInt listId) |
---|
| 2252 | { |
---|
| 2253 | Int coefNum = min(MAX_MATRIX_COEF_NUM,(Int)g_scalingListSize[sizeId]); |
---|
| 2254 | UInt* scan = (sizeId == 0) ? g_auiSigLastScan [ SCAN_DIAG ] [ 1 ] : g_sigLastScanCG32x32; |
---|
| 2255 | Int nextCoef = SCALING_LIST_START_VALUE; |
---|
| 2256 | Int data; |
---|
| 2257 | Int *src = scalingList->getScalingListAddress(sizeId, listId); |
---|
[529] | 2258 | if( sizeId > SCALING_LIST_8x8 ) |
---|
| 2259 | { |
---|
| 2260 | WRITE_SVLC( scalingList->getScalingListDC(sizeId,listId) - 8, "scaling_list_dc_coef_minus8"); |
---|
| 2261 | nextCoef = scalingList->getScalingListDC(sizeId,listId); |
---|
| 2262 | } |
---|
| 2263 | for(Int i=0;i<coefNum;i++) |
---|
| 2264 | { |
---|
| 2265 | data = src[scan[i]] - nextCoef; |
---|
| 2266 | nextCoef = src[scan[i]]; |
---|
| 2267 | if(data > 127) |
---|
[313] | 2268 | { |
---|
[529] | 2269 | data = data - 256; |
---|
[313] | 2270 | } |
---|
[529] | 2271 | if(data < -128) |
---|
[313] | 2272 | { |
---|
[529] | 2273 | data = data + 256; |
---|
| 2274 | } |
---|
[442] | 2275 | |
---|
[529] | 2276 | WRITE_SVLC( data, "scaling_list_delta_coef"); |
---|
| 2277 | } |
---|
[313] | 2278 | } |
---|
| 2279 | Bool TEncCavlc::findMatchingLTRP ( TComSlice* pcSlice, UInt *ltrpsIndex, Int ltrpPOC, Bool usedFlag ) |
---|
| 2280 | { |
---|
| 2281 | // Bool state = true, state2 = false; |
---|
[442] | 2282 | Int lsb = ltrpPOC & ((1<<pcSlice->getSPS()->getBitsForPOC())-1); |
---|
[313] | 2283 | for (Int k = 0; k < pcSlice->getSPS()->getNumLongTermRefPicSPS(); k++) |
---|
| 2284 | { |
---|
| 2285 | if ( (lsb == pcSlice->getSPS()->getLtRefPicPocLsbSps(k)) && (usedFlag == pcSlice->getSPS()->getUsedByCurrPicLtSPSFlag(k)) ) |
---|
| 2286 | { |
---|
| 2287 | *ltrpsIndex = k; |
---|
| 2288 | return true; |
---|
| 2289 | } |
---|
| 2290 | } |
---|
| 2291 | return false; |
---|
| 2292 | } |
---|
| 2293 | Bool TComScalingList::checkPredMode(UInt sizeId, UInt listId) |
---|
| 2294 | { |
---|
| 2295 | for(Int predListIdx = (Int)listId ; predListIdx >= 0; predListIdx--) |
---|
| 2296 | { |
---|
| 2297 | if( !memcmp(getScalingListAddress(sizeId,listId),((listId == predListIdx) ? |
---|
| 2298 | getScalingListDefaultAddress(sizeId, predListIdx): getScalingListAddress(sizeId, predListIdx)),sizeof(Int)*min(MAX_MATRIX_COEF_NUM,(Int)g_scalingListSize[sizeId])) // check value of matrix |
---|
| 2299 | && ((sizeId < SCALING_LIST_16x16) || (getScalingListDC(sizeId,listId) == getScalingListDC(sizeId,predListIdx)))) // check DC value |
---|
| 2300 | { |
---|
| 2301 | setRefMatrixId(sizeId, listId, predListIdx); |
---|
| 2302 | return false; |
---|
| 2303 | } |
---|
| 2304 | } |
---|
| 2305 | return true; |
---|
| 2306 | } |
---|
| 2307 | //! \} |
---|