| [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 |
|---|
| [1029] | 4 | * granted under this license. |
|---|
| [313] | 5 | * |
|---|
| [1259] | 6 | * Copyright (c) 2010-2015, ITU/ISO/IEC |
|---|
| [313] | 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 | |
|---|
| [1351] | 47 | Void xTraceVPSHeader () |
|---|
| [313] | 48 | { |
|---|
| [1351] | 49 | fprintf( g_hTrace, "=========== Video Parameter Set ===========\n" ); |
|---|
| [313] | 50 | } |
|---|
| 51 | |
|---|
| [1351] | 52 | Void xTraceSPSHeader () |
|---|
| [313] | 53 | { |
|---|
| [1351] | 54 | fprintf( g_hTrace, "=========== Sequence Parameter Set ===========\n" ); |
|---|
| [313] | 55 | } |
|---|
| 56 | |
|---|
| [1351] | 57 | Void xTracePPSHeader () |
|---|
| [313] | 58 | { |
|---|
| [1351] | 59 | fprintf( g_hTrace, "=========== Picture Parameter Set ===========\n"); |
|---|
| 60 | } |
|---|
| 61 | |
|---|
| 62 | Void xTraceSliceHeader () |
|---|
| 63 | { |
|---|
| [313] | 64 | fprintf( g_hTrace, "=========== Slice ===========\n"); |
|---|
| 65 | } |
|---|
| 66 | |
|---|
| [1434] | 67 | Void xTraceAccessUnitDelimiter () |
|---|
| 68 | { |
|---|
| 69 | fprintf( g_hTrace, "=========== Access Unit Delimiter ===========\n"); |
|---|
| 70 | } |
|---|
| 71 | |
|---|
| [313] | 72 | #endif |
|---|
| 73 | |
|---|
| [1415] | 74 | Void AUDWriter::codeAUD(TComBitIf& bs, const Int pictureType) |
|---|
| 75 | { |
|---|
| 76 | #if ENC_DEC_TRACE |
|---|
| 77 | xTraceAccessUnitDelimiter(); |
|---|
| 78 | #endif |
|---|
| [313] | 79 | |
|---|
| [1415] | 80 | assert (pictureType < 3); |
|---|
| 81 | setBitstream(&bs); |
|---|
| 82 | WRITE_CODE(pictureType, 3, "pic_type"); |
|---|
| 83 | xWriteRbspTrailingBits(); |
|---|
| 84 | } |
|---|
| [313] | 85 | |
|---|
| 86 | // ==================================================================================================================== |
|---|
| 87 | // Constructor / destructor / create / destroy |
|---|
| 88 | // ==================================================================================================================== |
|---|
| 89 | |
|---|
| 90 | TEncCavlc::TEncCavlc() |
|---|
| 91 | { |
|---|
| 92 | m_pcBitIf = NULL; |
|---|
| 93 | } |
|---|
| 94 | |
|---|
| 95 | TEncCavlc::~TEncCavlc() |
|---|
| 96 | { |
|---|
| 97 | } |
|---|
| 98 | |
|---|
| 99 | |
|---|
| 100 | // ==================================================================================================================== |
|---|
| 101 | // Public member functions |
|---|
| 102 | // ==================================================================================================================== |
|---|
| 103 | |
|---|
| [1307] | 104 | Void TEncCavlc::resetEntropy(const TComSlice* /*pSlice*/) |
|---|
| [313] | 105 | { |
|---|
| 106 | } |
|---|
| 107 | |
|---|
| 108 | |
|---|
| [1235] | 109 | Void TEncCavlc::codeShortTermRefPicSet( const TComReferencePictureSet* rps, Bool calledFromSliceHeader, Int idx) |
|---|
| [313] | 110 | { |
|---|
| 111 | #if PRINT_RPS_INFO |
|---|
| 112 | Int lastBits = getNumberOfWrittenBits(); |
|---|
| 113 | #endif |
|---|
| 114 | if (idx > 0) |
|---|
| 115 | { |
|---|
| 116 | WRITE_FLAG( rps->getInterRPSPrediction(), "inter_ref_pic_set_prediction_flag" ); // inter_RPS_prediction_flag |
|---|
| 117 | } |
|---|
| 118 | if (rps->getInterRPSPrediction()) |
|---|
| 119 | { |
|---|
| 120 | Int deltaRPS = rps->getDeltaRPS(); |
|---|
| 121 | if(calledFromSliceHeader) |
|---|
| 122 | { |
|---|
| 123 | WRITE_UVLC( rps->getDeltaRIdxMinus1(), "delta_idx_minus1" ); // delta index of the Reference Picture Set used for prediction minus 1 |
|---|
| 124 | } |
|---|
| 125 | |
|---|
| 126 | WRITE_CODE( (deltaRPS >=0 ? 0: 1), 1, "delta_rps_sign" ); //delta_rps_sign |
|---|
| 127 | WRITE_UVLC( abs(deltaRPS) - 1, "abs_delta_rps_minus1"); // absolute delta RPS minus 1 |
|---|
| 128 | |
|---|
| 129 | for(Int j=0; j < rps->getNumRefIdc(); j++) |
|---|
| 130 | { |
|---|
| 131 | Int refIdc = rps->getRefIdc(j); |
|---|
| [1029] | 132 | WRITE_CODE( (refIdc==1? 1: 0), 1, "used_by_curr_pic_flag" ); //first bit is "1" if Idc is 1 |
|---|
| 133 | if (refIdc != 1) |
|---|
| [313] | 134 | { |
|---|
| 135 | WRITE_CODE( refIdc>>1, 1, "use_delta_flag" ); //second bit is "1" if Idc is 2, "0" otherwise. |
|---|
| 136 | } |
|---|
| 137 | } |
|---|
| 138 | } |
|---|
| 139 | else |
|---|
| 140 | { |
|---|
| 141 | WRITE_UVLC( rps->getNumberOfNegativePictures(), "num_negative_pics" ); |
|---|
| 142 | WRITE_UVLC( rps->getNumberOfPositivePictures(), "num_positive_pics" ); |
|---|
| 143 | Int prev = 0; |
|---|
| 144 | for(Int j=0 ; j < rps->getNumberOfNegativePictures(); j++) |
|---|
| 145 | { |
|---|
| 146 | WRITE_UVLC( prev-rps->getDeltaPOC(j)-1, "delta_poc_s0_minus1" ); |
|---|
| 147 | prev = rps->getDeltaPOC(j); |
|---|
| [1029] | 148 | WRITE_FLAG( rps->getUsed(j), "used_by_curr_pic_s0_flag"); |
|---|
| [313] | 149 | } |
|---|
| 150 | prev = 0; |
|---|
| 151 | for(Int j=rps->getNumberOfNegativePictures(); j < rps->getNumberOfNegativePictures()+rps->getNumberOfPositivePictures(); j++) |
|---|
| 152 | { |
|---|
| 153 | WRITE_UVLC( rps->getDeltaPOC(j)-prev-1, "delta_poc_s1_minus1" ); |
|---|
| 154 | prev = rps->getDeltaPOC(j); |
|---|
| [1029] | 155 | WRITE_FLAG( rps->getUsed(j), "used_by_curr_pic_s1_flag" ); |
|---|
| [313] | 156 | } |
|---|
| 157 | } |
|---|
| 158 | |
|---|
| 159 | #if PRINT_RPS_INFO |
|---|
| 160 | printf("irps=%d (%2d bits) ", rps->getInterRPSPrediction(), getNumberOfWrittenBits() - lastBits); |
|---|
| 161 | rps->printDeltaPOC(); |
|---|
| 162 | #endif |
|---|
| 163 | } |
|---|
| 164 | |
|---|
| 165 | |
|---|
| [1212] | 166 | #if CGS_3D_ASYMLUT |
|---|
| [1235] | 167 | Void TEncCavlc::codePPS( const TComPPS* pcPPS, TEnc3DAsymLUT * pc3DAsymLUT ) |
|---|
| 168 | #else |
|---|
| 169 | Void TEncCavlc::codePPS( const TComPPS* pcPPS ) |
|---|
| [713] | 170 | #endif |
|---|
| [313] | 171 | { |
|---|
| [1029] | 172 | #if ENC_DEC_TRACE |
|---|
| [1351] | 173 | xTracePPSHeader (); |
|---|
| [313] | 174 | #endif |
|---|
| [1029] | 175 | |
|---|
| [313] | 176 | WRITE_UVLC( pcPPS->getPPSId(), "pps_pic_parameter_set_id" ); |
|---|
| 177 | WRITE_UVLC( pcPPS->getSPSId(), "pps_seq_parameter_set_id" ); |
|---|
| 178 | WRITE_FLAG( pcPPS->getDependentSliceSegmentsEnabledFlag() ? 1 : 0, "dependent_slice_segments_enabled_flag" ); |
|---|
| 179 | WRITE_FLAG( pcPPS->getOutputFlagPresentFlag() ? 1 : 0, "output_flag_present_flag" ); |
|---|
| 180 | WRITE_CODE( pcPPS->getNumExtraSliceHeaderBits(), 3, "num_extra_slice_header_bits"); |
|---|
| 181 | WRITE_FLAG( pcPPS->getSignHideFlag(), "sign_data_hiding_flag" ); |
|---|
| 182 | WRITE_FLAG( pcPPS->getCabacInitPresentFlag() ? 1 : 0, "cabac_init_present_flag" ); |
|---|
| 183 | WRITE_UVLC( pcPPS->getNumRefIdxL0DefaultActive()-1, "num_ref_idx_l0_default_active_minus1"); |
|---|
| 184 | WRITE_UVLC( pcPPS->getNumRefIdxL1DefaultActive()-1, "num_ref_idx_l1_default_active_minus1"); |
|---|
| 185 | |
|---|
| 186 | WRITE_SVLC( pcPPS->getPicInitQPMinus26(), "init_qp_minus26"); |
|---|
| 187 | WRITE_FLAG( pcPPS->getConstrainedIntraPred() ? 1 : 0, "constrained_intra_pred_flag" ); |
|---|
| [1029] | 188 | WRITE_FLAG( pcPPS->getUseTransformSkip() ? 1 : 0, "transform_skip_enabled_flag" ); |
|---|
| [313] | 189 | WRITE_FLAG( pcPPS->getUseDQP() ? 1 : 0, "cu_qp_delta_enabled_flag" ); |
|---|
| 190 | if ( pcPPS->getUseDQP() ) |
|---|
| 191 | { |
|---|
| 192 | WRITE_UVLC( pcPPS->getMaxCuDQPDepth(), "diff_cu_qp_delta_depth" ); |
|---|
| 193 | } |
|---|
| [1029] | 194 | |
|---|
| [1235] | 195 | WRITE_SVLC( pcPPS->getQpOffset(COMPONENT_Cb), "pps_cb_qp_offset" ); |
|---|
| 196 | WRITE_SVLC( pcPPS->getQpOffset(COMPONENT_Cr), "pps_cr_qp_offset" ); |
|---|
| [1029] | 197 | |
|---|
| [313] | 198 | WRITE_FLAG( pcPPS->getSliceChromaQpFlag() ? 1 : 0, "pps_slice_chroma_qp_offsets_present_flag" ); |
|---|
| 199 | |
|---|
| 200 | WRITE_FLAG( pcPPS->getUseWP() ? 1 : 0, "weighted_pred_flag" ); // Use of Weighting Prediction (P_SLICE) |
|---|
| 201 | WRITE_FLAG( pcPPS->getWPBiPred() ? 1 : 0, "weighted_bipred_flag" ); // Use of Weighting Bi-Prediction (B_SLICE) |
|---|
| 202 | WRITE_FLAG( pcPPS->getTransquantBypassEnableFlag() ? 1 : 0, "transquant_bypass_enable_flag" ); |
|---|
| 203 | WRITE_FLAG( pcPPS->getTilesEnabledFlag() ? 1 : 0, "tiles_enabled_flag" ); |
|---|
| 204 | WRITE_FLAG( pcPPS->getEntropyCodingSyncEnabledFlag() ? 1 : 0, "entropy_coding_sync_enabled_flag" ); |
|---|
| 205 | if( pcPPS->getTilesEnabledFlag() ) |
|---|
| 206 | { |
|---|
| [823] | 207 | WRITE_UVLC( pcPPS->getNumTileColumnsMinus1(), "num_tile_columns_minus1" ); |
|---|
| [1029] | 208 | WRITE_UVLC( pcPPS->getNumTileRowsMinus1(), "num_tile_rows_minus1" ); |
|---|
| [823] | 209 | WRITE_FLAG( pcPPS->getTileUniformSpacingFlag(), "uniform_spacing_flag" ); |
|---|
| 210 | if( !pcPPS->getTileUniformSpacingFlag() ) |
|---|
| [313] | 211 | { |
|---|
| [823] | 212 | for(UInt i=0; i<pcPPS->getNumTileColumnsMinus1(); i++) |
|---|
| [313] | 213 | { |
|---|
| [823] | 214 | WRITE_UVLC( pcPPS->getTileColumnWidth(i)-1, "column_width_minus1" ); |
|---|
| [313] | 215 | } |
|---|
| [1029] | 216 | for(UInt i=0; i<pcPPS->getNumTileRowsMinus1(); i++) |
|---|
| [313] | 217 | { |
|---|
| [823] | 218 | WRITE_UVLC( pcPPS->getTileRowHeight(i)-1, "row_height_minus1" ); |
|---|
| [313] | 219 | } |
|---|
| 220 | } |
|---|
| [1029] | 221 | if(pcPPS->getNumTileColumnsMinus1() !=0 || pcPPS->getNumTileRowsMinus1() !=0) |
|---|
| [313] | 222 | { |
|---|
| 223 | WRITE_FLAG( pcPPS->getLoopFilterAcrossTilesEnabledFlag()?1 : 0, "loop_filter_across_tiles_enabled_flag"); |
|---|
| 224 | } |
|---|
| 225 | } |
|---|
| [1257] | 226 | WRITE_FLAG( pcPPS->getLoopFilterAcrossSlicesEnabledFlag()?1 : 0, "pps_loop_filter_across_slices_enabled_flag"); |
|---|
| [313] | 227 | WRITE_FLAG( pcPPS->getDeblockingFilterControlPresentFlag()?1 : 0, "deblocking_filter_control_present_flag"); |
|---|
| 228 | if(pcPPS->getDeblockingFilterControlPresentFlag()) |
|---|
| 229 | { |
|---|
| [1029] | 230 | WRITE_FLAG( pcPPS->getDeblockingFilterOverrideEnabledFlag() ? 1 : 0, "deblocking_filter_override_enabled_flag" ); |
|---|
| [313] | 231 | WRITE_FLAG( pcPPS->getPicDisableDeblockingFilterFlag() ? 1 : 0, "pps_disable_deblocking_filter_flag" ); |
|---|
| 232 | if(!pcPPS->getPicDisableDeblockingFilterFlag()) |
|---|
| 233 | { |
|---|
| 234 | WRITE_SVLC( pcPPS->getDeblockingFilterBetaOffsetDiv2(), "pps_beta_offset_div2" ); |
|---|
| 235 | WRITE_SVLC( pcPPS->getDeblockingFilterTcOffsetDiv2(), "pps_tc_offset_div2" ); |
|---|
| 236 | } |
|---|
| 237 | } |
|---|
| [1029] | 238 | WRITE_FLAG( pcPPS->getScalingListPresentFlag() ? 1 : 0, "pps_scaling_list_data_present_flag" ); |
|---|
| 239 | if( pcPPS->getScalingListPresentFlag() ) |
|---|
| [540] | 240 | { |
|---|
| [1235] | 241 | codeScalingList( pcPPS->getScalingList() ); |
|---|
| [540] | 242 | } |
|---|
| [1029] | 243 | WRITE_FLAG( pcPPS->getListsModificationPresentFlag(), "lists_modification_present_flag"); |
|---|
| 244 | WRITE_UVLC( pcPPS->getLog2ParallelMergeLevelMinus2(), "log2_parallel_merge_level_minus2"); |
|---|
| 245 | WRITE_FLAG( pcPPS->getSliceHeaderExtensionPresentFlag() ? 1 : 0, "slice_segment_header_extension_present_flag"); |
|---|
| [540] | 246 | |
|---|
| [1029] | 247 | Bool pps_extension_present_flag=false; |
|---|
| 248 | Bool pps_extension_flags[NUM_PPS_EXTENSION_FLAGS]={false}; |
|---|
| [540] | 249 | |
|---|
| [1316] | 250 | pps_extension_flags[PPS_EXT__REXT] = pcPPS->getPpsRangeExtension().settingsDifferFromDefaults(pcPPS->getUseTransformSkip()); |
|---|
| [1029] | 251 | |
|---|
| 252 | // Other PPS extension flags checked here. |
|---|
| 253 | |
|---|
| 254 | #if SVC_EXTENSION |
|---|
| 255 | pps_extension_flags[PPS_EXT__MLAYER] = pcPPS->getExtensionFlag() ? 1 : 0; |
|---|
| [1212] | 256 | #if CGS_3D_ASYMLUT |
|---|
| [1029] | 257 | UInt bits = 0; |
|---|
| [442] | 258 | #endif |
|---|
| [898] | 259 | #endif |
|---|
| [442] | 260 | |
|---|
| [1029] | 261 | for(Int i=0; i<NUM_PPS_EXTENSION_FLAGS; i++) |
|---|
| [313] | 262 | { |
|---|
| [1029] | 263 | pps_extension_present_flag|=pps_extension_flags[i]; |
|---|
| [540] | 264 | } |
|---|
| [442] | 265 | |
|---|
| [1029] | 266 | WRITE_FLAG( (pps_extension_present_flag?1:0), "pps_extension_present_flag" ); |
|---|
| [815] | 267 | |
|---|
| [1029] | 268 | if (pps_extension_present_flag) |
|---|
| [644] | 269 | { |
|---|
| [1257] | 270 | #if ENC_DEC_TRACE || RExt__DECODER_DEBUG_BIT_STATISTICS |
|---|
| [1442] | 271 | static const TChar *syntaxStrings[]={ "pps_range_extension_flag", |
|---|
| 272 | "pps_multilayer_extension_flag", |
|---|
| 273 | "pps_extension_6bits[0]", |
|---|
| 274 | "pps_extension_6bits[1]", |
|---|
| 275 | "pps_extension_6bits[2]", |
|---|
| 276 | "pps_extension_6bits[3]", |
|---|
| 277 | "pps_extension_6bits[4]", |
|---|
| 278 | "pps_extension_6bits[5]" }; |
|---|
| [1257] | 279 | #endif |
|---|
| 280 | |
|---|
| [1029] | 281 | for(Int i=0; i<NUM_PPS_EXTENSION_FLAGS; i++) |
|---|
| [644] | 282 | { |
|---|
| [1257] | 283 | WRITE_FLAG( pps_extension_flags[i]?1:0, syntaxStrings[i] ); |
|---|
| [644] | 284 | } |
|---|
| [1029] | 285 | |
|---|
| 286 | for(Int i=0; i<NUM_PPS_EXTENSION_FLAGS; i++) // loop used so that the order is determined by the enum. |
|---|
| [644] | 287 | { |
|---|
| [1029] | 288 | if (pps_extension_flags[i]) |
|---|
| [849] | 289 | { |
|---|
| [1029] | 290 | switch (PPSExtensionFlagIndex(i)) |
|---|
| [849] | 291 | { |
|---|
| [1029] | 292 | case PPS_EXT__REXT: |
|---|
| 293 | { |
|---|
| [1316] | 294 | const TComPPSRExt &ppsRangeExtension = pcPPS->getPpsRangeExtension(); |
|---|
| 295 | if (pcPPS->getUseTransformSkip()) |
|---|
| 296 | { |
|---|
| 297 | WRITE_UVLC( ppsRangeExtension.getLog2MaxTransformSkipBlockSize()-2, "log2_max_transform_skip_block_size_minus2"); |
|---|
| 298 | } |
|---|
| [1029] | 299 | |
|---|
| [1316] | 300 | WRITE_FLAG((ppsRangeExtension.getCrossComponentPredictionEnabledFlag() ? 1 : 0), "cross_component_prediction_enabled_flag" ); |
|---|
| [1029] | 301 | |
|---|
| [1316] | 302 | WRITE_FLAG(UInt(ppsRangeExtension.getChromaQpOffsetListEnabledFlag()), "chroma_qp_offset_list_enabled_flag" ); |
|---|
| 303 | if (ppsRangeExtension.getChromaQpOffsetListEnabledFlag()) |
|---|
| [1029] | 304 | { |
|---|
| [1316] | 305 | WRITE_UVLC(ppsRangeExtension.getDiffCuChromaQpOffsetDepth(), "diff_cu_chroma_qp_offset_depth"); |
|---|
| 306 | WRITE_UVLC(ppsRangeExtension.getChromaQpOffsetListLen() - 1, "chroma_qp_offset_list_len_minus1"); |
|---|
| 307 | /* skip zero index */ |
|---|
| 308 | for (Int cuChromaQpOffsetIdx = 0; cuChromaQpOffsetIdx < ppsRangeExtension.getChromaQpOffsetListLen(); cuChromaQpOffsetIdx++) |
|---|
| 309 | { |
|---|
| 310 | WRITE_SVLC(ppsRangeExtension.getChromaQpOffsetListEntry(cuChromaQpOffsetIdx+1).u.comp.CbOffset, "cb_qp_offset_list[i]"); |
|---|
| 311 | WRITE_SVLC(ppsRangeExtension.getChromaQpOffsetListEntry(cuChromaQpOffsetIdx+1).u.comp.CrOffset, "cr_qp_offset_list[i]"); |
|---|
| 312 | } |
|---|
| [1029] | 313 | } |
|---|
| [1316] | 314 | |
|---|
| 315 | WRITE_UVLC( ppsRangeExtension.getLog2SaoOffsetScale(CHANNEL_TYPE_LUMA), "log2_sao_offset_scale_luma" ); |
|---|
| 316 | WRITE_UVLC( ppsRangeExtension.getLog2SaoOffsetScale(CHANNEL_TYPE_CHROMA), "log2_sao_offset_scale_chroma" ); |
|---|
| [1029] | 317 | } |
|---|
| [1316] | 318 | break; |
|---|
| [1029] | 319 | |
|---|
| 320 | #if SVC_EXTENSION |
|---|
| 321 | case PPS_EXT__MLAYER: |
|---|
| 322 | WRITE_FLAG( pcPPS->getPocResetInfoPresentFlag() ? 1 : 0, "poc_reset_info_present_flag" ); |
|---|
| [1223] | 323 | |
|---|
| [1029] | 324 | WRITE_FLAG( pcPPS->getInferScalingListFlag() ? 1 : 0, "pps_infer_scaling_list_flag" ); |
|---|
| 325 | if( pcPPS->getInferScalingListFlag() ) |
|---|
| 326 | { |
|---|
| 327 | // The value of pps_scaling_list_ref_layer_id shall be in the range of 0 to 62, inclusive |
|---|
| 328 | assert( pcPPS->getScalingListRefLayerId() <= 62 ); |
|---|
| 329 | WRITE_CODE( pcPPS->getScalingListRefLayerId(), 6, "pps_scaling_list_ref_layer_id" ); |
|---|
| 330 | } |
|---|
| [898] | 331 | |
|---|
| [1030] | 332 | WRITE_UVLC( pcPPS->getNumRefLayerLocationOffsets(), "num_ref_loc_offsets" ); |
|---|
| 333 | for(Int k = 0; k < pcPPS->getNumRefLayerLocationOffsets(); k++) |
|---|
| [1029] | 334 | { |
|---|
| [1030] | 335 | WRITE_CODE( pcPPS->getRefLocationOffsetLayerId(k), 6, "ref_loc_offset_layer_id" ); |
|---|
| [1029] | 336 | WRITE_FLAG( pcPPS->getScaledRefLayerOffsetPresentFlag(k) ? 1 : 0, "scaled_ref_layer_offset_prsent_flag" ); |
|---|
| [1235] | 337 | if( pcPPS->getScaledRefLayerOffsetPresentFlag(k) ) |
|---|
| [1029] | 338 | { |
|---|
| 339 | Window scaledWindow = pcPPS->getScaledRefLayerWindow(k); |
|---|
| 340 | WRITE_SVLC( scaledWindow.getWindowLeftOffset() >> 1, "scaled_ref_layer_left_offset" ); |
|---|
| 341 | WRITE_SVLC( scaledWindow.getWindowTopOffset() >> 1, "scaled_ref_layer_top_offset" ); |
|---|
| 342 | WRITE_SVLC( scaledWindow.getWindowRightOffset() >> 1, "scaled_ref_layer_right_offset" ); |
|---|
| 343 | WRITE_SVLC( scaledWindow.getWindowBottomOffset() >> 1, "scaled_ref_layer_bottom_offset" ); |
|---|
| 344 | } |
|---|
| [1235] | 345 | |
|---|
| [1029] | 346 | WRITE_FLAG( pcPPS->getRefRegionOffsetPresentFlag(k) ? 1 : 0, "ref_region_offset_prsent_flag" ); |
|---|
| [1235] | 347 | |
|---|
| 348 | if( pcPPS->getRefRegionOffsetPresentFlag(k) ) |
|---|
| [1029] | 349 | { |
|---|
| [1235] | 350 | const Window refWindow = pcPPS->getRefLayerWindow(k); |
|---|
| [1029] | 351 | WRITE_SVLC( refWindow.getWindowLeftOffset() >> 1, "ref_region_left_offset" ); |
|---|
| 352 | WRITE_SVLC( refWindow.getWindowTopOffset() >> 1, "ref_region_top_offset" ); |
|---|
| 353 | WRITE_SVLC( refWindow.getWindowRightOffset() >> 1, "ref_region_right_offset" ); |
|---|
| 354 | WRITE_SVLC( refWindow.getWindowBottomOffset() >> 1, "ref_region_bottom_offset" ); |
|---|
| 355 | } |
|---|
| [1235] | 356 | |
|---|
| [1029] | 357 | WRITE_FLAG( pcPPS->getResamplePhaseSetPresentFlag(k) ? 1 : 0, "resample_phase_set_present_flag" ); |
|---|
| [1235] | 358 | |
|---|
| 359 | if( pcPPS->getResamplePhaseSetPresentFlag(k) ) |
|---|
| [1029] | 360 | { |
|---|
| 361 | WRITE_UVLC( pcPPS->getPhaseHorLuma(k), "phase_hor_luma" ); |
|---|
| 362 | WRITE_UVLC( pcPPS->getPhaseVerLuma(k), "phase_ver_luma" ); |
|---|
| 363 | WRITE_UVLC( pcPPS->getPhaseHorChroma(k) + 8, "phase_hor_chroma_plus8" ); |
|---|
| 364 | WRITE_UVLC( pcPPS->getPhaseVerChroma(k) + 8, "phase_ver_chroma_plus8" ); |
|---|
| 365 | } |
|---|
| 366 | } |
|---|
| [1212] | 367 | #if CGS_3D_ASYMLUT |
|---|
| [1029] | 368 | bits = getNumberOfWrittenBits(); |
|---|
| 369 | WRITE_FLAG( pcPPS->getCGSFlag() , "colour_mapping_enabled_flag" ); |
|---|
| 370 | if( pcPPS->getCGSFlag() ) |
|---|
| 371 | { |
|---|
| 372 | assert( pc3DAsymLUT != NULL ); |
|---|
| 373 | xCode3DAsymLUT( pc3DAsymLUT ); |
|---|
| 374 | } |
|---|
| 375 | pc3DAsymLUT->setPPSBit( getNumberOfWrittenBits() - bits ); |
|---|
| [898] | 376 | #endif |
|---|
| [1029] | 377 | break; |
|---|
| [898] | 378 | #endif |
|---|
| [1029] | 379 | default: |
|---|
| 380 | assert(pps_extension_flags[i]==false); // Should never get here with an active PPS extension flag. |
|---|
| 381 | break; |
|---|
| 382 | } // switch |
|---|
| 383 | } // if flag present |
|---|
| 384 | } // loop over PPS flags |
|---|
| 385 | } // pps_extension_present_flag is non-zero |
|---|
| [1352] | 386 | xWriteRbspTrailingBits(); |
|---|
| [313] | 387 | } |
|---|
| 388 | |
|---|
| [1235] | 389 | Void TEncCavlc::codeVUI( const TComVUI *pcVUI, const TComSPS* pcSPS ) |
|---|
| [313] | 390 | { |
|---|
| 391 | #if ENC_DEC_TRACE |
|---|
| 392 | fprintf( g_hTrace, "----------- vui_parameters -----------\n"); |
|---|
| 393 | #endif |
|---|
| 394 | WRITE_FLAG(pcVUI->getAspectRatioInfoPresentFlag(), "aspect_ratio_info_present_flag"); |
|---|
| 395 | if (pcVUI->getAspectRatioInfoPresentFlag()) |
|---|
| 396 | { |
|---|
| 397 | WRITE_CODE(pcVUI->getAspectRatioIdc(), 8, "aspect_ratio_idc" ); |
|---|
| 398 | if (pcVUI->getAspectRatioIdc() == 255) |
|---|
| 399 | { |
|---|
| 400 | WRITE_CODE(pcVUI->getSarWidth(), 16, "sar_width"); |
|---|
| 401 | WRITE_CODE(pcVUI->getSarHeight(), 16, "sar_height"); |
|---|
| 402 | } |
|---|
| 403 | } |
|---|
| 404 | WRITE_FLAG(pcVUI->getOverscanInfoPresentFlag(), "overscan_info_present_flag"); |
|---|
| 405 | if (pcVUI->getOverscanInfoPresentFlag()) |
|---|
| 406 | { |
|---|
| 407 | WRITE_FLAG(pcVUI->getOverscanAppropriateFlag(), "overscan_appropriate_flag"); |
|---|
| 408 | } |
|---|
| 409 | WRITE_FLAG(pcVUI->getVideoSignalTypePresentFlag(), "video_signal_type_present_flag"); |
|---|
| 410 | if (pcVUI->getVideoSignalTypePresentFlag()) |
|---|
| 411 | { |
|---|
| 412 | WRITE_CODE(pcVUI->getVideoFormat(), 3, "video_format"); |
|---|
| 413 | WRITE_FLAG(pcVUI->getVideoFullRangeFlag(), "video_full_range_flag"); |
|---|
| 414 | WRITE_FLAG(pcVUI->getColourDescriptionPresentFlag(), "colour_description_present_flag"); |
|---|
| 415 | if (pcVUI->getColourDescriptionPresentFlag()) |
|---|
| 416 | { |
|---|
| 417 | WRITE_CODE(pcVUI->getColourPrimaries(), 8, "colour_primaries"); |
|---|
| 418 | WRITE_CODE(pcVUI->getTransferCharacteristics(), 8, "transfer_characteristics"); |
|---|
| [1257] | 419 | WRITE_CODE(pcVUI->getMatrixCoefficients(), 8, "matrix_coeffs"); |
|---|
| [313] | 420 | } |
|---|
| 421 | } |
|---|
| 422 | |
|---|
| 423 | WRITE_FLAG(pcVUI->getChromaLocInfoPresentFlag(), "chroma_loc_info_present_flag"); |
|---|
| 424 | if (pcVUI->getChromaLocInfoPresentFlag()) |
|---|
| 425 | { |
|---|
| 426 | WRITE_UVLC(pcVUI->getChromaSampleLocTypeTopField(), "chroma_sample_loc_type_top_field"); |
|---|
| 427 | WRITE_UVLC(pcVUI->getChromaSampleLocTypeBottomField(), "chroma_sample_loc_type_bottom_field"); |
|---|
| 428 | } |
|---|
| 429 | |
|---|
| 430 | WRITE_FLAG(pcVUI->getNeutralChromaIndicationFlag(), "neutral_chroma_indication_flag"); |
|---|
| 431 | WRITE_FLAG(pcVUI->getFieldSeqFlag(), "field_seq_flag"); |
|---|
| 432 | WRITE_FLAG(pcVUI->getFrameFieldInfoPresentFlag(), "frame_field_info_present_flag"); |
|---|
| 433 | |
|---|
| 434 | Window defaultDisplayWindow = pcVUI->getDefaultDisplayWindow(); |
|---|
| 435 | WRITE_FLAG(defaultDisplayWindow.getWindowEnabledFlag(), "default_display_window_flag"); |
|---|
| 436 | if( defaultDisplayWindow.getWindowEnabledFlag() ) |
|---|
| 437 | { |
|---|
| [823] | 438 | WRITE_UVLC(defaultDisplayWindow.getWindowLeftOffset() / TComSPS::getWinUnitX(pcSPS->getChromaFormatIdc()), "def_disp_win_left_offset"); |
|---|
| 439 | WRITE_UVLC(defaultDisplayWindow.getWindowRightOffset() / TComSPS::getWinUnitX(pcSPS->getChromaFormatIdc()), "def_disp_win_right_offset"); |
|---|
| 440 | WRITE_UVLC(defaultDisplayWindow.getWindowTopOffset() / TComSPS::getWinUnitY(pcSPS->getChromaFormatIdc()), "def_disp_win_top_offset"); |
|---|
| 441 | WRITE_UVLC(defaultDisplayWindow.getWindowBottomOffset()/ TComSPS::getWinUnitY(pcSPS->getChromaFormatIdc()), "def_disp_win_bottom_offset"); |
|---|
| [313] | 442 | } |
|---|
| [1235] | 443 | const TimingInfo *timingInfo = pcVUI->getTimingInfo(); |
|---|
| [313] | 444 | WRITE_FLAG(timingInfo->getTimingInfoPresentFlag(), "vui_timing_info_present_flag"); |
|---|
| 445 | if(timingInfo->getTimingInfoPresentFlag()) |
|---|
| 446 | { |
|---|
| 447 | WRITE_CODE(timingInfo->getNumUnitsInTick(), 32, "vui_num_units_in_tick"); |
|---|
| 448 | WRITE_CODE(timingInfo->getTimeScale(), 32, "vui_time_scale"); |
|---|
| 449 | WRITE_FLAG(timingInfo->getPocProportionalToTimingFlag(), "vui_poc_proportional_to_timing_flag"); |
|---|
| 450 | if(timingInfo->getPocProportionalToTimingFlag()) |
|---|
| 451 | { |
|---|
| 452 | WRITE_UVLC(timingInfo->getNumTicksPocDiffOneMinus1(), "vui_num_ticks_poc_diff_one_minus1"); |
|---|
| 453 | } |
|---|
| [1257] | 454 | WRITE_FLAG(pcVUI->getHrdParametersPresentFlag(), "vui_hrd_parameters_present_flag"); |
|---|
| [1029] | 455 | if( pcVUI->getHrdParametersPresentFlag() ) |
|---|
| 456 | { |
|---|
| 457 | codeHrdParameters(pcVUI->getHrdParameters(), 1, pcSPS->getMaxTLayers() - 1 ); |
|---|
| 458 | } |
|---|
| [313] | 459 | } |
|---|
| 460 | |
|---|
| 461 | WRITE_FLAG(pcVUI->getBitstreamRestrictionFlag(), "bitstream_restriction_flag"); |
|---|
| 462 | if (pcVUI->getBitstreamRestrictionFlag()) |
|---|
| 463 | { |
|---|
| 464 | WRITE_FLAG(pcVUI->getTilesFixedStructureFlag(), "tiles_fixed_structure_flag"); |
|---|
| 465 | WRITE_FLAG(pcVUI->getMotionVectorsOverPicBoundariesFlag(), "motion_vectors_over_pic_boundaries_flag"); |
|---|
| 466 | WRITE_FLAG(pcVUI->getRestrictedRefPicListsFlag(), "restricted_ref_pic_lists_flag"); |
|---|
| 467 | WRITE_UVLC(pcVUI->getMinSpatialSegmentationIdc(), "min_spatial_segmentation_idc"); |
|---|
| 468 | WRITE_UVLC(pcVUI->getMaxBytesPerPicDenom(), "max_bytes_per_pic_denom"); |
|---|
| [1257] | 469 | WRITE_UVLC(pcVUI->getMaxBitsPerMinCuDenom(), "max_bits_per_min_cu_denom"); |
|---|
| [313] | 470 | WRITE_UVLC(pcVUI->getLog2MaxMvLengthHorizontal(), "log2_max_mv_length_horizontal"); |
|---|
| 471 | WRITE_UVLC(pcVUI->getLog2MaxMvLengthVertical(), "log2_max_mv_length_vertical"); |
|---|
| 472 | } |
|---|
| 473 | } |
|---|
| 474 | |
|---|
| [1235] | 475 | Void TEncCavlc::codeHrdParameters( const TComHRD *hrd, Bool commonInfPresentFlag, UInt maxNumSubLayersMinus1 ) |
|---|
| [313] | 476 | { |
|---|
| 477 | if( commonInfPresentFlag ) |
|---|
| 478 | { |
|---|
| 479 | WRITE_FLAG( hrd->getNalHrdParametersPresentFlag() ? 1 : 0 , "nal_hrd_parameters_present_flag" ); |
|---|
| 480 | WRITE_FLAG( hrd->getVclHrdParametersPresentFlag() ? 1 : 0 , "vcl_hrd_parameters_present_flag" ); |
|---|
| 481 | if( hrd->getNalHrdParametersPresentFlag() || hrd->getVclHrdParametersPresentFlag() ) |
|---|
| 482 | { |
|---|
| [1257] | 483 | WRITE_FLAG( hrd->getSubPicCpbParamsPresentFlag() ? 1 : 0, "sub_pic_hrd_params_present_flag" ); |
|---|
| [313] | 484 | if( hrd->getSubPicCpbParamsPresentFlag() ) |
|---|
| 485 | { |
|---|
| 486 | WRITE_CODE( hrd->getTickDivisorMinus2(), 8, "tick_divisor_minus2" ); |
|---|
| [1257] | 487 | WRITE_CODE( hrd->getDuCpbRemovalDelayLengthMinus1(), 5, "du_cpb_removal_delay_increment_length_minus1" ); |
|---|
| [313] | 488 | WRITE_FLAG( hrd->getSubPicCpbParamsInPicTimingSEIFlag() ? 1 : 0, "sub_pic_cpb_params_in_pic_timing_sei_flag" ); |
|---|
| 489 | WRITE_CODE( hrd->getDpbOutputDelayDuLengthMinus1(), 5, "dpb_output_delay_du_length_minus1" ); |
|---|
| 490 | } |
|---|
| 491 | WRITE_CODE( hrd->getBitRateScale(), 4, "bit_rate_scale" ); |
|---|
| 492 | WRITE_CODE( hrd->getCpbSizeScale(), 4, "cpb_size_scale" ); |
|---|
| 493 | if( hrd->getSubPicCpbParamsPresentFlag() ) |
|---|
| 494 | { |
|---|
| [1029] | 495 | WRITE_CODE( hrd->getDuCpbSizeScale(), 4, "du_cpb_size_scale" ); |
|---|
| [313] | 496 | } |
|---|
| 497 | WRITE_CODE( hrd->getInitialCpbRemovalDelayLengthMinus1(), 5, "initial_cpb_removal_delay_length_minus1" ); |
|---|
| 498 | WRITE_CODE( hrd->getCpbRemovalDelayLengthMinus1(), 5, "au_cpb_removal_delay_length_minus1" ); |
|---|
| 499 | WRITE_CODE( hrd->getDpbOutputDelayLengthMinus1(), 5, "dpb_output_delay_length_minus1" ); |
|---|
| 500 | } |
|---|
| 501 | } |
|---|
| 502 | Int i, j, nalOrVcl; |
|---|
| 503 | for( i = 0; i <= maxNumSubLayersMinus1; i ++ ) |
|---|
| 504 | { |
|---|
| 505 | WRITE_FLAG( hrd->getFixedPicRateFlag( i ) ? 1 : 0, "fixed_pic_rate_general_flag"); |
|---|
| [1235] | 506 | Bool fixedPixRateWithinCvsFlag = true; |
|---|
| [313] | 507 | if( !hrd->getFixedPicRateFlag( i ) ) |
|---|
| 508 | { |
|---|
| [1235] | 509 | fixedPixRateWithinCvsFlag = hrd->getFixedPicRateWithinCvsFlag( i ); |
|---|
| [313] | 510 | WRITE_FLAG( hrd->getFixedPicRateWithinCvsFlag( i ) ? 1 : 0, "fixed_pic_rate_within_cvs_flag"); |
|---|
| 511 | } |
|---|
| [1235] | 512 | if( fixedPixRateWithinCvsFlag ) |
|---|
| [313] | 513 | { |
|---|
| 514 | WRITE_UVLC( hrd->getPicDurationInTcMinus1( i ), "elemental_duration_in_tc_minus1"); |
|---|
| 515 | } |
|---|
| 516 | else |
|---|
| 517 | { |
|---|
| 518 | WRITE_FLAG( hrd->getLowDelayHrdFlag( i ) ? 1 : 0, "low_delay_hrd_flag"); |
|---|
| 519 | } |
|---|
| 520 | if (!hrd->getLowDelayHrdFlag( i )) |
|---|
| 521 | { |
|---|
| 522 | WRITE_UVLC( hrd->getCpbCntMinus1( i ), "cpb_cnt_minus1"); |
|---|
| 523 | } |
|---|
| [1029] | 524 | |
|---|
| [313] | 525 | for( nalOrVcl = 0; nalOrVcl < 2; nalOrVcl ++ ) |
|---|
| 526 | { |
|---|
| 527 | if( ( ( nalOrVcl == 0 ) && ( hrd->getNalHrdParametersPresentFlag() ) ) || |
|---|
| 528 | ( ( nalOrVcl == 1 ) && ( hrd->getVclHrdParametersPresentFlag() ) ) ) |
|---|
| 529 | { |
|---|
| 530 | for( j = 0; j <= ( hrd->getCpbCntMinus1( i ) ); j ++ ) |
|---|
| 531 | { |
|---|
| 532 | WRITE_UVLC( hrd->getBitRateValueMinus1( i, j, nalOrVcl ), "bit_rate_value_minus1"); |
|---|
| 533 | WRITE_UVLC( hrd->getCpbSizeValueMinus1( i, j, nalOrVcl ), "cpb_size_value_minus1"); |
|---|
| 534 | if( hrd->getSubPicCpbParamsPresentFlag() ) |
|---|
| 535 | { |
|---|
| [1029] | 536 | WRITE_UVLC( hrd->getDuCpbSizeValueMinus1( i, j, nalOrVcl ), "cpb_size_du_value_minus1"); |
|---|
| [313] | 537 | WRITE_UVLC( hrd->getDuBitRateValueMinus1( i, j, nalOrVcl ), "bit_rate_du_value_minus1"); |
|---|
| 538 | } |
|---|
| 539 | WRITE_FLAG( hrd->getCbrFlag( i, j, nalOrVcl ) ? 1 : 0, "cbr_flag"); |
|---|
| 540 | } |
|---|
| 541 | } |
|---|
| 542 | } |
|---|
| 543 | } |
|---|
| 544 | } |
|---|
| 545 | |
|---|
| [1235] | 546 | Void TEncCavlc::codeSPS( const TComSPS* pcSPS ) |
|---|
| [313] | 547 | { |
|---|
| [1029] | 548 | #if SVC_EXTENSION |
|---|
| 549 | Bool V1CompatibleSPSFlag = !(pcSPS->getLayerId() != 0 && pcSPS->getNumDirectRefLayers() != 0); |
|---|
| [898] | 550 | #endif |
|---|
| [1029] | 551 | |
|---|
| 552 | const ChromaFormat format = pcSPS->getChromaFormatIdc(); |
|---|
| 553 | const Bool chromaEnabled = isChromaEnabled(format); |
|---|
| 554 | |
|---|
| 555 | #if ENC_DEC_TRACE |
|---|
| [1351] | 556 | xTraceSPSHeader (); |
|---|
| [313] | 557 | #endif |
|---|
| 558 | WRITE_CODE( pcSPS->getVPSId (), 4, "sps_video_parameter_set_id" ); |
|---|
| [494] | 559 | #if SVC_EXTENSION |
|---|
| [313] | 560 | if(pcSPS->getLayerId() == 0) |
|---|
| 561 | { |
|---|
| 562 | #endif |
|---|
| [1029] | 563 | WRITE_CODE( pcSPS->getMaxTLayers() - 1, 3, "sps_max_sub_layers_minus1" ); |
|---|
| [898] | 564 | #if SVC_EXTENSION |
|---|
| 565 | } |
|---|
| 566 | else |
|---|
| 567 | { |
|---|
| [1029] | 568 | WRITE_CODE( V1CompatibleSPSFlag ? (pcSPS->getMaxTLayers() - 1) : 7, 3, "sps_ext_or_max_sub_layers_minus1" ); |
|---|
| [898] | 569 | } |
|---|
| 570 | |
|---|
| [1029] | 571 | if( V1CompatibleSPSFlag ) |
|---|
| [898] | 572 | { |
|---|
| 573 | #endif |
|---|
| [1257] | 574 | WRITE_FLAG( pcSPS->getTemporalIdNestingFlag() ? 1 : 0, "sps_temporal_id_nesting_flag" ); |
|---|
| [1029] | 575 | codePTL(pcSPS->getPTL(), 1, pcSPS->getMaxTLayers() - 1); |
|---|
| [494] | 576 | #if SVC_EXTENSION |
|---|
| [313] | 577 | } |
|---|
| 578 | #endif |
|---|
| 579 | WRITE_UVLC( pcSPS->getSPSId (), "sps_seq_parameter_set_id" ); |
|---|
| [1029] | 580 | #if SVC_EXTENSION |
|---|
| 581 | if( !V1CompatibleSPSFlag ) |
|---|
| [313] | 582 | { |
|---|
| [442] | 583 | WRITE_FLAG( pcSPS->getUpdateRepFormatFlag(), "update_rep_format_flag" ); |
|---|
| [1029] | 584 | |
|---|
| 585 | if( pcSPS->getUpdateRepFormatFlag()) |
|---|
| 586 | { |
|---|
| 587 | WRITE_CODE( pcSPS->getUpdateRepFormatIndex(), 8, "sps_rep_format_idx"); |
|---|
| 588 | } |
|---|
| [313] | 589 | } |
|---|
| [1029] | 590 | else |
|---|
| [898] | 591 | { |
|---|
| 592 | #endif |
|---|
| [1029] | 593 | WRITE_UVLC( Int(pcSPS->getChromaFormatIdc ()), "chroma_format_idc" ); |
|---|
| 594 | if( format == CHROMA_444 ) |
|---|
| [898] | 595 | { |
|---|
| [1029] | 596 | WRITE_FLAG( 0, "separate_colour_plane_flag"); |
|---|
| [442] | 597 | } |
|---|
| [313] | 598 | |
|---|
| [1029] | 599 | WRITE_UVLC( pcSPS->getPicWidthInLumaSamples (), "pic_width_in_luma_samples" ); |
|---|
| 600 | WRITE_UVLC( pcSPS->getPicHeightInLumaSamples(), "pic_height_in_luma_samples" ); |
|---|
| 601 | Window conf = pcSPS->getConformanceWindow(); |
|---|
| 602 | |
|---|
| 603 | WRITE_FLAG( conf.getWindowEnabledFlag(), "conformance_window_flag" ); |
|---|
| 604 | if (conf.getWindowEnabledFlag()) |
|---|
| [313] | 605 | { |
|---|
| [1203] | 606 | #if SVC_EXTENSION |
|---|
| [1029] | 607 | WRITE_UVLC( conf.getWindowLeftOffset(), "conf_win_left_offset" ); |
|---|
| 608 | WRITE_UVLC( conf.getWindowRightOffset(), "conf_win_right_offset" ); |
|---|
| 609 | WRITE_UVLC( conf.getWindowTopOffset(), "conf_win_top_offset" ); |
|---|
| 610 | WRITE_UVLC( conf.getWindowBottomOffset(), "conf_win_bottom_offset" ); |
|---|
| [713] | 611 | #else |
|---|
| [1029] | 612 | WRITE_UVLC( conf.getWindowLeftOffset() / TComSPS::getWinUnitX(pcSPS->getChromaFormatIdc() ), "conf_win_left_offset" ); |
|---|
| 613 | WRITE_UVLC( conf.getWindowRightOffset() / TComSPS::getWinUnitX(pcSPS->getChromaFormatIdc() ), "conf_win_right_offset" ); |
|---|
| 614 | WRITE_UVLC( conf.getWindowTopOffset() / TComSPS::getWinUnitY(pcSPS->getChromaFormatIdc() ), "conf_win_top_offset" ); |
|---|
| 615 | WRITE_UVLC( conf.getWindowBottomOffset() / TComSPS::getWinUnitY(pcSPS->getChromaFormatIdc() ), "conf_win_bottom_offset" ); |
|---|
| [713] | 616 | #endif |
|---|
| [313] | 617 | } |
|---|
| [1029] | 618 | #if SVC_EXTENSION |
|---|
| 619 | } |
|---|
| [313] | 620 | |
|---|
| [1029] | 621 | if( V1CompatibleSPSFlag ) |
|---|
| [442] | 622 | { |
|---|
| 623 | #endif |
|---|
| [1029] | 624 | WRITE_UVLC( pcSPS->getBitDepth(CHANNEL_TYPE_LUMA) - 8, "bit_depth_luma_minus8" ); |
|---|
| 625 | |
|---|
| 626 | WRITE_UVLC( chromaEnabled ? (pcSPS->getBitDepth(CHANNEL_TYPE_CHROMA) - 8):0, "bit_depth_chroma_minus8" ); |
|---|
| 627 | #if SVC_EXTENSION |
|---|
| [442] | 628 | } |
|---|
| 629 | #endif |
|---|
| [898] | 630 | |
|---|
| [313] | 631 | WRITE_UVLC( pcSPS->getBitsForPOC()-4, "log2_max_pic_order_cnt_lsb_minus4" ); |
|---|
| 632 | |
|---|
| [1029] | 633 | #if SVC_EXTENSION |
|---|
| 634 | if( V1CompatibleSPSFlag ) |
|---|
| 635 | { |
|---|
| [898] | 636 | #endif |
|---|
| [1029] | 637 | const Bool subLayerOrderingInfoPresentFlag = 1; |
|---|
| 638 | WRITE_FLAG(subLayerOrderingInfoPresentFlag, "sps_sub_layer_ordering_info_present_flag"); |
|---|
| 639 | for(UInt i=0; i <= pcSPS->getMaxTLayers()-1; i++) |
|---|
| [644] | 640 | { |
|---|
| [1029] | 641 | WRITE_UVLC( pcSPS->getMaxDecPicBuffering(i) - 1, "sps_max_dec_pic_buffering_minus1[i]" ); |
|---|
| [1257] | 642 | WRITE_UVLC( pcSPS->getNumReorderPics(i), "sps_max_num_reorder_pics[i]" ); |
|---|
| [1464] | 643 | WRITE_UVLC( pcSPS->getMaxLatencyIncreasePlus1(i), "sps_max_latency_increase_plus1[i]" ); |
|---|
| [1029] | 644 | if (!subLayerOrderingInfoPresentFlag) |
|---|
| [313] | 645 | { |
|---|
| [1029] | 646 | break; |
|---|
| [313] | 647 | } |
|---|
| [644] | 648 | } |
|---|
| [1029] | 649 | #if SVC_EXTENSION |
|---|
| 650 | } |
|---|
| [644] | 651 | #endif |
|---|
| [313] | 652 | assert( pcSPS->getMaxCUWidth() == pcSPS->getMaxCUHeight() ); |
|---|
| [1257] | 653 | WRITE_UVLC( pcSPS->getLog2MinCodingBlockSize() - 3, "log2_min_luma_coding_block_size_minus3" ); |
|---|
| 654 | WRITE_UVLC( pcSPS->getLog2DiffMaxMinCodingBlockSize(), "log2_diff_max_min_luma_coding_block_size" ); |
|---|
| 655 | WRITE_UVLC( pcSPS->getQuadtreeTULog2MinSize() - 2, "log2_min_luma_transform_block_size_minus2" ); |
|---|
| 656 | WRITE_UVLC( pcSPS->getQuadtreeTULog2MaxSize() - pcSPS->getQuadtreeTULog2MinSize(), "log2_diff_max_min_luma_transform_block_size" ); |
|---|
| [313] | 657 | WRITE_UVLC( pcSPS->getQuadtreeTUMaxDepthInter() - 1, "max_transform_hierarchy_depth_inter" ); |
|---|
| 658 | WRITE_UVLC( pcSPS->getQuadtreeTUMaxDepthIntra() - 1, "max_transform_hierarchy_depth_intra" ); |
|---|
| [1029] | 659 | WRITE_FLAG( pcSPS->getScalingListFlag() ? 1 : 0, "scaling_list_enabled_flag" ); |
|---|
| [313] | 660 | if(pcSPS->getScalingListFlag()) |
|---|
| 661 | { |
|---|
| [1223] | 662 | #if SVC_EXTENSION |
|---|
| [1029] | 663 | if( !V1CompatibleSPSFlag ) |
|---|
| [313] | 664 | { |
|---|
| [540] | 665 | WRITE_FLAG( pcSPS->getInferScalingListFlag() ? 1 : 0, "sps_infer_scaling_list_flag" ); |
|---|
| 666 | } |
|---|
| [442] | 667 | |
|---|
| [540] | 668 | if( pcSPS->getInferScalingListFlag() ) |
|---|
| [442] | 669 | { |
|---|
| [540] | 670 | // The value of pps_scaling_list_ref_layer_id shall be in the range of 0 to 62, inclusive |
|---|
| 671 | assert( pcSPS->getScalingListRefLayerId() <= 62 ); |
|---|
| [442] | 672 | |
|---|
| [937] | 673 | WRITE_CODE( pcSPS->getScalingListRefLayerId(), 6, "sps_scaling_list_ref_layer_id" ); |
|---|
| [442] | 674 | } |
|---|
| 675 | else |
|---|
| 676 | { |
|---|
| [540] | 677 | #endif |
|---|
| [1029] | 678 | WRITE_FLAG( pcSPS->getScalingListPresentFlag() ? 1 : 0, "sps_scaling_list_data_present_flag" ); |
|---|
| 679 | if(pcSPS->getScalingListPresentFlag()) |
|---|
| 680 | { |
|---|
| [1235] | 681 | codeScalingList( pcSPS->getScalingList() ); |
|---|
| [1029] | 682 | } |
|---|
| [1223] | 683 | #if SVC_EXTENSION |
|---|
| [540] | 684 | } |
|---|
| [442] | 685 | #endif |
|---|
| [313] | 686 | } |
|---|
| 687 | WRITE_FLAG( pcSPS->getUseAMP() ? 1 : 0, "amp_enabled_flag" ); |
|---|
| 688 | WRITE_FLAG( pcSPS->getUseSAO() ? 1 : 0, "sample_adaptive_offset_enabled_flag"); |
|---|
| 689 | |
|---|
| 690 | WRITE_FLAG( pcSPS->getUsePCM() ? 1 : 0, "pcm_enabled_flag"); |
|---|
| 691 | if( pcSPS->getUsePCM() ) |
|---|
| 692 | { |
|---|
| [1029] | 693 | WRITE_CODE( pcSPS->getPCMBitDepth(CHANNEL_TYPE_LUMA) - 1, 4, "pcm_sample_bit_depth_luma_minus1" ); |
|---|
| 694 | WRITE_CODE( chromaEnabled ? (pcSPS->getPCMBitDepth(CHANNEL_TYPE_CHROMA) - 1) : 0, 4, "pcm_sample_bit_depth_chroma_minus1" ); |
|---|
| [313] | 695 | WRITE_UVLC( pcSPS->getPCMLog2MinSize() - 3, "log2_min_pcm_luma_coding_block_size_minus3" ); |
|---|
| 696 | WRITE_UVLC( pcSPS->getPCMLog2MaxSize() - pcSPS->getPCMLog2MinSize(), "log2_diff_max_min_pcm_luma_coding_block_size" ); |
|---|
| 697 | WRITE_FLAG( pcSPS->getPCMFilterDisableFlag()?1 : 0, "pcm_loop_filter_disable_flag"); |
|---|
| 698 | } |
|---|
| 699 | |
|---|
| [1029] | 700 | assert( pcSPS->getMaxTLayers() > 0 ); |
|---|
| [313] | 701 | |
|---|
| [1235] | 702 | const TComRPSList* rpsList = pcSPS->getRPSList(); |
|---|
| [1029] | 703 | |
|---|
| [313] | 704 | WRITE_UVLC(rpsList->getNumberOfReferencePictureSets(), "num_short_term_ref_pic_sets" ); |
|---|
| 705 | for(Int i=0; i < rpsList->getNumberOfReferencePictureSets(); i++) |
|---|
| 706 | { |
|---|
| [1235] | 707 | const TComReferencePictureSet*rps = rpsList->getReferencePictureSet(i); |
|---|
| 708 | codeShortTermRefPicSet( rps,false, i); |
|---|
| [313] | 709 | } |
|---|
| 710 | WRITE_FLAG( pcSPS->getLongTermRefsPresent() ? 1 : 0, "long_term_ref_pics_present_flag" ); |
|---|
| [1029] | 711 | if (pcSPS->getLongTermRefsPresent()) |
|---|
| [313] | 712 | { |
|---|
| [1257] | 713 | WRITE_UVLC(pcSPS->getNumLongTermRefPicSPS(), "num_long_term_ref_pics_sps" ); |
|---|
| [313] | 714 | for (UInt k = 0; k < pcSPS->getNumLongTermRefPicSPS(); k++) |
|---|
| 715 | { |
|---|
| 716 | WRITE_CODE( pcSPS->getLtRefPicPocLsbSps(k), pcSPS->getBitsForPOC(), "lt_ref_pic_poc_lsb_sps"); |
|---|
| [1257] | 717 | WRITE_FLAG( pcSPS->getUsedByCurrPicLtSPSFlag(k), "used_by_curr_pic_lt_sps_flag[i]"); |
|---|
| [313] | 718 | } |
|---|
| 719 | } |
|---|
| 720 | WRITE_FLAG( pcSPS->getTMVPFlagsPresent() ? 1 : 0, "sps_temporal_mvp_enable_flag" ); |
|---|
| [595] | 721 | |
|---|
| [313] | 722 | WRITE_FLAG( pcSPS->getUseStrongIntraSmoothing(), "sps_strong_intra_smoothing_enable_flag" ); |
|---|
| 723 | |
|---|
| 724 | WRITE_FLAG( pcSPS->getVuiParametersPresentFlag(), "vui_parameters_present_flag" ); |
|---|
| 725 | if (pcSPS->getVuiParametersPresentFlag()) |
|---|
| 726 | { |
|---|
| 727 | codeVUI(pcSPS->getVuiParameters(), pcSPS); |
|---|
| 728 | } |
|---|
| 729 | |
|---|
| [1029] | 730 | Bool sps_extension_present_flag=false; |
|---|
| 731 | Bool sps_extension_flags[NUM_SPS_EXTENSION_FLAGS]={false}; |
|---|
| 732 | |
|---|
| [1316] | 733 | sps_extension_flags[SPS_EXT__REXT] = pcSPS->getSpsRangeExtension().settingsDifferFromDefaults(); |
|---|
| [1029] | 734 | |
|---|
| 735 | // Other SPS extension flags checked here. |
|---|
| [815] | 736 | #if SVC_EXTENSION |
|---|
| [1029] | 737 | sps_extension_flags[SPS_EXT__MLAYER] = pcSPS->getExtensionFlag() ? 1 : 0; |
|---|
| [898] | 738 | #endif |
|---|
| [815] | 739 | |
|---|
| [1029] | 740 | for(Int i=0; i<NUM_SPS_EXTENSION_FLAGS; i++) |
|---|
| [313] | 741 | { |
|---|
| [1029] | 742 | sps_extension_present_flag|=sps_extension_flags[i]; |
|---|
| 743 | } |
|---|
| 744 | |
|---|
| 745 | WRITE_FLAG( (sps_extension_present_flag?1:0), "sps_extension_present_flag" ); |
|---|
| 746 | |
|---|
| 747 | if (sps_extension_present_flag) |
|---|
| 748 | { |
|---|
| [1257] | 749 | #if ENC_DEC_TRACE || RExt__DECODER_DEBUG_BIT_STATISTICS |
|---|
| [1442] | 750 | static const TChar *syntaxStrings[]={ "sps_range_extension_flag", |
|---|
| 751 | "sps_multilayer_extension_flag", |
|---|
| 752 | "sps_extension_6bits[0]", |
|---|
| 753 | "sps_extension_6bits[1]", |
|---|
| 754 | "sps_extension_6bits[2]", |
|---|
| 755 | "sps_extension_6bits[3]", |
|---|
| 756 | "sps_extension_6bits[4]", |
|---|
| 757 | "sps_extension_6bits[5]" }; |
|---|
| [1257] | 758 | #endif |
|---|
| 759 | |
|---|
| [1029] | 760 | for(Int i=0; i<NUM_SPS_EXTENSION_FLAGS; i++) |
|---|
| [540] | 761 | { |
|---|
| [1257] | 762 | WRITE_FLAG( sps_extension_flags[i]?1:0, syntaxStrings[i] ); |
|---|
| [540] | 763 | } |
|---|
| [1029] | 764 | |
|---|
| 765 | for(Int i=0; i<NUM_SPS_EXTENSION_FLAGS; i++) // loop used so that the order is determined by the enum. |
|---|
| [540] | 766 | { |
|---|
| [1029] | 767 | if (sps_extension_flags[i]) |
|---|
| 768 | { |
|---|
| 769 | switch (SPSExtensionFlagIndex(i)) |
|---|
| 770 | { |
|---|
| 771 | case SPS_EXT__REXT: |
|---|
| [1316] | 772 | { |
|---|
| 773 | const TComSPSRExt &spsRangeExtension=pcSPS->getSpsRangeExtension(); |
|---|
| [815] | 774 | |
|---|
| [1316] | 775 | WRITE_FLAG( (spsRangeExtension.getTransformSkipRotationEnabledFlag() ? 1 : 0), "transform_skip_rotation_enabled_flag"); |
|---|
| 776 | WRITE_FLAG( (spsRangeExtension.getTransformSkipContextEnabledFlag() ? 1 : 0), "transform_skip_context_enabled_flag"); |
|---|
| 777 | WRITE_FLAG( (spsRangeExtension.getRdpcmEnabledFlag(RDPCM_SIGNAL_IMPLICIT) ? 1 : 0), "implicit_rdpcm_enabled_flag" ); |
|---|
| 778 | WRITE_FLAG( (spsRangeExtension.getRdpcmEnabledFlag(RDPCM_SIGNAL_EXPLICIT) ? 1 : 0), "explicit_rdpcm_enabled_flag" ); |
|---|
| 779 | WRITE_FLAG( (spsRangeExtension.getExtendedPrecisionProcessingFlag() ? 1 : 0), "extended_precision_processing_flag" ); |
|---|
| 780 | WRITE_FLAG( (spsRangeExtension.getIntraSmoothingDisabledFlag() ? 1 : 0), "intra_smoothing_disabled_flag" ); |
|---|
| 781 | WRITE_FLAG( (spsRangeExtension.getHighPrecisionOffsetsEnabledFlag() ? 1 : 0), "high_precision_offsets_enabled_flag" ); |
|---|
| 782 | WRITE_FLAG( (spsRangeExtension.getPersistentRiceAdaptationEnabledFlag() ? 1 : 0), "persistent_rice_adaptation_enabled_flag" ); |
|---|
| 783 | WRITE_FLAG( (spsRangeExtension.getCabacBypassAlignmentEnabledFlag() ? 1 : 0), "cabac_bypass_alignment_enabled_flag" ); |
|---|
| [1029] | 784 | break; |
|---|
| [1316] | 785 | } |
|---|
| [815] | 786 | #if SVC_EXTENSION |
|---|
| [1029] | 787 | case SPS_EXT__MLAYER: |
|---|
| 788 | codeSPSExtension( pcSPS ); //it is sps_multilayer_extension |
|---|
| 789 | break; |
|---|
| [540] | 790 | #endif |
|---|
| [1029] | 791 | default: |
|---|
| 792 | assert(sps_extension_flags[i]==false); // Should never get here with an active SPS extension flag. |
|---|
| 793 | break; |
|---|
| 794 | } |
|---|
| 795 | } |
|---|
| [313] | 796 | } |
|---|
| 797 | } |
|---|
| [1352] | 798 | xWriteRbspTrailingBits(); |
|---|
| [313] | 799 | } |
|---|
| [815] | 800 | |
|---|
| [1235] | 801 | Void TEncCavlc::codeVPS( const TComVPS* pcVPS ) |
|---|
| [313] | 802 | { |
|---|
| [1351] | 803 | #if ENC_DEC_TRACE |
|---|
| 804 | xTraceVPSHeader(); |
|---|
| 805 | #endif |
|---|
| [313] | 806 | WRITE_CODE( pcVPS->getVPSId(), 4, "vps_video_parameter_set_id" ); |
|---|
| [1180] | 807 | #if SVC_EXTENSION |
|---|
| [836] | 808 | WRITE_FLAG( pcVPS->getBaseLayerInternalFlag(), "vps_base_layer_internal_flag"); |
|---|
| 809 | WRITE_FLAG( pcVPS->getBaseLayerAvailableFlag(), "vps_base_layer_available_flag"); |
|---|
| [954] | 810 | WRITE_CODE( pcVPS->getMaxLayers() - 1, 6, "vps_max_layers_minus1" ); |
|---|
| [1029] | 811 | assert( pcVPS->getBaseLayerInternalFlag() || pcVPS->getMaxLayers() > 1 ); |
|---|
| [313] | 812 | #else |
|---|
| [1257] | 813 | WRITE_FLAG( 1, "vps_base_layer_internal_flag" ); |
|---|
| 814 | WRITE_FLAG( 1, "vps_base_layer_available_flag" ); |
|---|
| [1237] | 815 | WRITE_CODE( 0, 6, "vps_max_layers_minus1" ); |
|---|
| [313] | 816 | #endif |
|---|
| 817 | WRITE_CODE( pcVPS->getMaxTLayers() - 1, 3, "vps_max_sub_layers_minus1" ); |
|---|
| 818 | WRITE_FLAG( pcVPS->getTemporalNestingFlag(), "vps_temporal_id_nesting_flag" ); |
|---|
| 819 | assert (pcVPS->getMaxTLayers()>1||pcVPS->getTemporalNestingFlag()); |
|---|
| [1257] | 820 | WRITE_CODE( 0xffff, 16, "vps_reserved_0xffff_16bits" ); |
|---|
| [313] | 821 | codePTL( pcVPS->getPTL(), true, pcVPS->getMaxTLayers() - 1 ); |
|---|
| 822 | const Bool subLayerOrderingInfoPresentFlag = 1; |
|---|
| 823 | WRITE_FLAG(subLayerOrderingInfoPresentFlag, "vps_sub_layer_ordering_info_present_flag"); |
|---|
| 824 | for(UInt i=0; i <= pcVPS->getMaxTLayers()-1; i++) |
|---|
| 825 | { |
|---|
| 826 | WRITE_UVLC( pcVPS->getMaxDecPicBuffering(i) - 1, "vps_max_dec_pic_buffering_minus1[i]" ); |
|---|
| [1257] | 827 | WRITE_UVLC( pcVPS->getNumReorderPics(i), "vps_max_num_reorder_pics[i]" ); |
|---|
| [313] | 828 | WRITE_UVLC( pcVPS->getMaxLatencyIncrease(i), "vps_max_latency_increase_plus1[i]" ); |
|---|
| 829 | if (!subLayerOrderingInfoPresentFlag) |
|---|
| 830 | { |
|---|
| 831 | break; |
|---|
| 832 | } |
|---|
| 833 | } |
|---|
| 834 | |
|---|
| [815] | 835 | #if SVC_EXTENSION |
|---|
| [313] | 836 | assert( pcVPS->getNumHrdParameters() <= MAX_VPS_LAYER_SETS_PLUS1 ); |
|---|
| [1048] | 837 | assert( pcVPS->getMaxLayerId() < MAX_VPS_LAYER_IDX_PLUS1 ); |
|---|
| [1171] | 838 | |
|---|
| [313] | 839 | WRITE_CODE( pcVPS->getMaxLayerId(), 6, "vps_max_layer_id" ); |
|---|
| [815] | 840 | WRITE_UVLC(pcVPS->getVpsNumLayerSetsMinus1(), "vps_num_layer_sets_minus1"); |
|---|
| [1172] | 841 | |
|---|
| 842 | for( UInt opsIdx = 1; opsIdx <= pcVPS->getVpsNumLayerSetsMinus1(); opsIdx++ ) |
|---|
| [313] | 843 | { |
|---|
| 844 | // Operation point set |
|---|
| 845 | for( UInt i = 0; i <= pcVPS->getMaxLayerId(); i ++ ) |
|---|
| [1171] | 846 | { |
|---|
| [313] | 847 | #else |
|---|
| 848 | assert( pcVPS->getNumHrdParameters() <= MAX_VPS_NUM_HRD_PARAMETERS ); |
|---|
| 849 | assert( pcVPS->getMaxNuhReservedZeroLayerId() < MAX_VPS_NUH_RESERVED_ZERO_LAYER_ID_PLUS1 ); |
|---|
| [1257] | 850 | WRITE_CODE( pcVPS->getMaxNuhReservedZeroLayerId(), 6, "vps_max_layer_id" ); |
|---|
| 851 | WRITE_UVLC( pcVPS->getMaxOpSets() - 1, "vps_num_layer_sets_minus1" ); |
|---|
| [313] | 852 | for( UInt opsIdx = 1; opsIdx <= ( pcVPS->getMaxOpSets() - 1 ); opsIdx ++ ) |
|---|
| 853 | { |
|---|
| 854 | // Operation point set |
|---|
| 855 | for( UInt i = 0; i <= pcVPS->getMaxNuhReservedZeroLayerId(); i ++ ) |
|---|
| 856 | { |
|---|
| 857 | // Only applicable for version 1 |
|---|
| [1235] | 858 | // pcVPS->setLayerIdIncludedFlag( true, opsIdx, i ); |
|---|
| [313] | 859 | #endif |
|---|
| 860 | WRITE_FLAG( pcVPS->getLayerIdIncludedFlag( opsIdx, i ) ? 1 : 0, "layer_id_included_flag[opsIdx][i]" ); |
|---|
| 861 | } |
|---|
| 862 | } |
|---|
| [1235] | 863 | const TimingInfo *timingInfo = pcVPS->getTimingInfo(); |
|---|
| [313] | 864 | WRITE_FLAG(timingInfo->getTimingInfoPresentFlag(), "vps_timing_info_present_flag"); |
|---|
| 865 | if(timingInfo->getTimingInfoPresentFlag()) |
|---|
| 866 | { |
|---|
| 867 | WRITE_CODE(timingInfo->getNumUnitsInTick(), 32, "vps_num_units_in_tick"); |
|---|
| 868 | WRITE_CODE(timingInfo->getTimeScale(), 32, "vps_time_scale"); |
|---|
| 869 | WRITE_FLAG(timingInfo->getPocProportionalToTimingFlag(), "vps_poc_proportional_to_timing_flag"); |
|---|
| 870 | if(timingInfo->getPocProportionalToTimingFlag()) |
|---|
| 871 | { |
|---|
| 872 | WRITE_UVLC(timingInfo->getNumTicksPocDiffOneMinus1(), "vps_num_ticks_poc_diff_one_minus1"); |
|---|
| 873 | } |
|---|
| 874 | WRITE_UVLC( pcVPS->getNumHrdParameters(), "vps_num_hrd_parameters" ); |
|---|
| 875 | |
|---|
| 876 | if( pcVPS->getNumHrdParameters() > 0 ) |
|---|
| 877 | { |
|---|
| [1235] | 878 | for( UInt i = 0; i < pcVPS->getNumHrdParameters(); i ++ ) |
|---|
| [313] | 879 | { |
|---|
| [1235] | 880 | // Only applicable for version 1 |
|---|
| [1257] | 881 | WRITE_UVLC( pcVPS->getHrdOpSetIdx( i ), "hrd_layer_set_idx" ); |
|---|
| [1235] | 882 | if( i > 0 ) |
|---|
| 883 | { |
|---|
| 884 | WRITE_FLAG( pcVPS->getCprmsPresentFlag( i ) ? 1 : 0, "cprms_present_flag[i]" ); |
|---|
| 885 | } |
|---|
| 886 | codeHrdParameters(pcVPS->getHrdParameters(i), pcVPS->getCprmsPresentFlag( i ), pcVPS->getMaxTLayers() - 1); |
|---|
| [313] | 887 | } |
|---|
| 888 | } |
|---|
| 889 | } |
|---|
| [815] | 890 | #if SVC_EXTENSION |
|---|
| [713] | 891 | // When MaxLayersMinus1 is greater than 0, vps_extension_flag shall be equal to 1. |
|---|
| 892 | if( pcVPS->getMaxLayers() > 1 ) |
|---|
| [442] | 893 | { |
|---|
| [713] | 894 | assert( pcVPS->getVpsExtensionFlag() == true ); |
|---|
| 895 | } |
|---|
| 896 | |
|---|
| 897 | WRITE_FLAG( pcVPS->getVpsExtensionFlag() ? 1 : 0, "vps_extension_flag" ); |
|---|
| 898 | |
|---|
| 899 | if( pcVPS->getVpsExtensionFlag() ) |
|---|
| 900 | { |
|---|
| [442] | 901 | while ( m_pcBitIf->getNumberOfWrittenBits() % 8 != 0 ) |
|---|
| 902 | { |
|---|
| 903 | WRITE_FLAG(1, "vps_extension_alignment_bit_equal_to_one"); |
|---|
| 904 | } |
|---|
| 905 | codeVPSExtension(pcVPS); |
|---|
| 906 | WRITE_FLAG( 0, "vps_extension2_flag" ); // Flag value of 1 reserved |
|---|
| 907 | } |
|---|
| [713] | 908 | #else |
|---|
| 909 | WRITE_FLAG( 0, "vps_extension_flag" ); |
|---|
| [1352] | 910 | #endif |
|---|
| 911 | |
|---|
| [313] | 912 | //future extensions here.. |
|---|
| [1352] | 913 | xWriteRbspTrailingBits(); |
|---|
| [313] | 914 | } |
|---|
| 915 | |
|---|
| [1029] | 916 | Void TEncCavlc::codeSliceHeader ( TComSlice* pcSlice ) |
|---|
| 917 | { |
|---|
| 918 | #if ENC_DEC_TRACE |
|---|
| [1351] | 919 | xTraceSliceHeader (); |
|---|
| [1029] | 920 | #endif |
|---|
| 921 | |
|---|
| 922 | const ChromaFormat format = pcSlice->getSPS()->getChromaFormatIdc(); |
|---|
| 923 | const UInt numberValidComponents = getNumberValidComponents(format); |
|---|
| 924 | const Bool chromaEnabled = isChromaEnabled(format); |
|---|
| 925 | |
|---|
| 926 | //calculate number of bits required for slice address |
|---|
| 927 | Int maxSliceSegmentAddress = pcSlice->getPic()->getNumberOfCtusInFrame(); |
|---|
| 928 | Int bitsSliceSegmentAddress = 0; |
|---|
| 929 | while(maxSliceSegmentAddress>(1<<bitsSliceSegmentAddress)) |
|---|
| 930 | { |
|---|
| 931 | bitsSliceSegmentAddress++; |
|---|
| 932 | } |
|---|
| 933 | const Int ctuTsAddress = pcSlice->getSliceSegmentCurStartCtuTsAddr(); |
|---|
| 934 | |
|---|
| 935 | //write slice address |
|---|
| 936 | const Int sliceSegmentRsAddress = pcSlice->getPic()->getPicSym()->getCtuTsToRsAddrMap(ctuTsAddress); |
|---|
| 937 | |
|---|
| 938 | WRITE_FLAG( sliceSegmentRsAddress==0, "first_slice_segment_in_pic_flag" ); |
|---|
| 939 | if ( pcSlice->getRapPicFlag() ) |
|---|
| 940 | { |
|---|
| 941 | WRITE_FLAG( pcSlice->getNoOutputPriorPicsFlag() ? 1 : 0, "no_output_of_prior_pics_flag" ); |
|---|
| 942 | } |
|---|
| 943 | WRITE_UVLC( pcSlice->getPPS()->getPPSId(), "slice_pic_parameter_set_id" ); |
|---|
| 944 | if ( pcSlice->getPPS()->getDependentSliceSegmentsEnabledFlag() && (sliceSegmentRsAddress!=0) ) |
|---|
| 945 | { |
|---|
| 946 | WRITE_FLAG( pcSlice->getDependentSliceSegmentFlag() ? 1 : 0, "dependent_slice_segment_flag" ); |
|---|
| 947 | } |
|---|
| 948 | if(sliceSegmentRsAddress>0) |
|---|
| 949 | { |
|---|
| 950 | WRITE_CODE( sliceSegmentRsAddress, bitsSliceSegmentAddress, "slice_segment_address" ); |
|---|
| 951 | } |
|---|
| 952 | if ( !pcSlice->getDependentSliceSegmentFlag() ) |
|---|
| 953 | { |
|---|
| [494] | 954 | #if SVC_EXTENSION |
|---|
| [1029] | 955 | Int iBits = 0; |
|---|
| 956 | if(pcSlice->getPPS()->getNumExtraSliceHeaderBits() > iBits) |
|---|
| 957 | { |
|---|
| 958 | assert(!!"discardable_flag"); |
|---|
| [1183] | 959 | |
|---|
| [1029] | 960 | if (pcSlice->getDiscardableFlag()) |
|---|
| 961 | { |
|---|
| 962 | assert(pcSlice->getNalUnitType() != NAL_UNIT_CODED_SLICE_TRAIL_R && |
|---|
| 963 | pcSlice->getNalUnitType() != NAL_UNIT_CODED_SLICE_TSA_R && |
|---|
| 964 | pcSlice->getNalUnitType() != NAL_UNIT_CODED_SLICE_STSA_R && |
|---|
| 965 | pcSlice->getNalUnitType() != NAL_UNIT_CODED_SLICE_RADL_R && |
|---|
| 966 | pcSlice->getNalUnitType() != NAL_UNIT_CODED_SLICE_RASL_R); |
|---|
| 967 | } |
|---|
| [1183] | 968 | |
|---|
| [1029] | 969 | WRITE_FLAG(pcSlice->getDiscardableFlag(), "discardable_flag"); |
|---|
| 970 | iBits++; |
|---|
| 971 | } |
|---|
| [1108] | 972 | |
|---|
| [1029] | 973 | if( pcSlice->getPPS()->getNumExtraSliceHeaderBits() > iBits ) |
|---|
| 974 | { |
|---|
| 975 | assert(!!"cross_layer_bla_flag"); |
|---|
| 976 | WRITE_FLAG(pcSlice->getCrossLayerBLAFlag(), "cross_layer_bla_flag"); |
|---|
| 977 | iBits++; |
|---|
| 978 | } |
|---|
| [1108] | 979 | |
|---|
| [1029] | 980 | for (; iBits < pcSlice->getPPS()->getNumExtraSliceHeaderBits(); iBits++) |
|---|
| 981 | { |
|---|
| 982 | assert(!!"slice_reserved_undetermined_flag[]"); |
|---|
| 983 | WRITE_FLAG(0, "slice_reserved_undetermined_flag[]"); |
|---|
| 984 | } |
|---|
| 985 | #else //SVC_EXTENSION |
|---|
| 986 | for (Int i = 0; i < pcSlice->getPPS()->getNumExtraSliceHeaderBits(); i++) |
|---|
| 987 | { |
|---|
| [1257] | 988 | WRITE_FLAG(0, "slice_reserved_flag[]"); |
|---|
| [1029] | 989 | } |
|---|
| 990 | #endif //SVC_EXTENSION |
|---|
| 991 | |
|---|
| 992 | WRITE_UVLC( pcSlice->getSliceType(), "slice_type" ); |
|---|
| 993 | |
|---|
| 994 | if( pcSlice->getPPS()->getOutputFlagPresentFlag() ) |
|---|
| 995 | { |
|---|
| 996 | WRITE_FLAG( pcSlice->getPicOutputFlag() ? 1 : 0, "pic_output_flag" ); |
|---|
| 997 | } |
|---|
| 998 | |
|---|
| [1187] | 999 | #if SVC_EXTENSION |
|---|
| [1043] | 1000 | if( (pcSlice->getLayerId() > 0 && !pcSlice->getVPS()->getPocLsbNotPresentFlag( pcSlice->getVPS()->getLayerIdxInVps(pcSlice->getLayerId())) ) || !pcSlice->getIdrPicFlag()) |
|---|
| [1029] | 1001 | #else |
|---|
| 1002 | if( !pcSlice->getIdrPicFlag() ) |
|---|
| 1003 | #endif |
|---|
| 1004 | { |
|---|
| [1209] | 1005 | #if SVC_POC |
|---|
| [1029] | 1006 | Int picOrderCntLSB; |
|---|
| 1007 | if( pcSlice->getPocResetIdc() == 2 ) // i.e. the LSB is reset |
|---|
| 1008 | { |
|---|
| 1009 | picOrderCntLSB = pcSlice->getPicOrderCntLsb(); // This will be the LSB value w.r.t to the previous POC reset period. |
|---|
| 1010 | } |
|---|
| 1011 | else |
|---|
| 1012 | { |
|---|
| 1013 | picOrderCntLSB = (pcSlice->getPOC() + (1<<pcSlice->getSPS()->getBitsForPOC())) & ((1<<pcSlice->getSPS()->getBitsForPOC())-1); |
|---|
| 1014 | } |
|---|
| 1015 | #else |
|---|
| 1016 | Int picOrderCntLSB = (pcSlice->getPOC()-pcSlice->getLastIDR()+(1<<pcSlice->getSPS()->getBitsForPOC())) & ((1<<pcSlice->getSPS()->getBitsForPOC())-1); |
|---|
| 1017 | #endif |
|---|
| [1257] | 1018 | WRITE_CODE( picOrderCntLSB, pcSlice->getSPS()->getBitsForPOC(), "slice_pic_order_cnt_lsb"); |
|---|
| [1029] | 1019 | |
|---|
| [1187] | 1020 | #if SVC_EXTENSION |
|---|
| [1029] | 1021 | } |
|---|
| [1101] | 1022 | if( !pcSlice->getIdrPicFlag() ) |
|---|
| 1023 | { |
|---|
| [1029] | 1024 | #endif |
|---|
| [1235] | 1025 | const TComReferencePictureSet* rps = pcSlice->getRPS(); |
|---|
| [1029] | 1026 | |
|---|
| 1027 | // check for bitstream restriction stating that: |
|---|
| 1028 | // If the current picture is a BLA or CRA picture, the value of NumPocTotalCurr shall be equal to 0. |
|---|
| 1029 | // Ideally this process should not be repeated for each slice in a picture |
|---|
| 1030 | #if SVC_EXTENSION |
|---|
| 1031 | if( pcSlice->getLayerId() == 0 ) |
|---|
| 1032 | #endif |
|---|
| 1033 | if (pcSlice->isIRAP()) |
|---|
| 1034 | { |
|---|
| 1035 | for (Int picIdx = 0; picIdx < rps->getNumberOfPictures(); picIdx++) |
|---|
| 1036 | { |
|---|
| 1037 | assert (!rps->getUsed(picIdx)); |
|---|
| 1038 | } |
|---|
| 1039 | } |
|---|
| 1040 | |
|---|
| 1041 | if(pcSlice->getRPSidx() < 0) |
|---|
| 1042 | { |
|---|
| 1043 | WRITE_FLAG( 0, "short_term_ref_pic_set_sps_flag"); |
|---|
| [1235] | 1044 | codeShortTermRefPicSet( rps, true, pcSlice->getSPS()->getRPSList()->getNumberOfReferencePictureSets()); |
|---|
| [1029] | 1045 | } |
|---|
| 1046 | else |
|---|
| 1047 | { |
|---|
| 1048 | WRITE_FLAG( 1, "short_term_ref_pic_set_sps_flag"); |
|---|
| 1049 | Int numBits = 0; |
|---|
| 1050 | while ((1 << numBits) < pcSlice->getSPS()->getRPSList()->getNumberOfReferencePictureSets()) |
|---|
| 1051 | { |
|---|
| 1052 | numBits++; |
|---|
| 1053 | } |
|---|
| 1054 | if (numBits > 0) |
|---|
| 1055 | { |
|---|
| 1056 | WRITE_CODE( pcSlice->getRPSidx(), numBits, "short_term_ref_pic_set_idx" ); |
|---|
| 1057 | } |
|---|
| 1058 | } |
|---|
| 1059 | if(pcSlice->getSPS()->getLongTermRefsPresent()) |
|---|
| 1060 | { |
|---|
| 1061 | Int numLtrpInSH = rps->getNumberOfLongtermPictures(); |
|---|
| 1062 | Int ltrpInSPS[MAX_NUM_REF_PICS]; |
|---|
| 1063 | Int numLtrpInSPS = 0; |
|---|
| 1064 | UInt ltrpIndex; |
|---|
| 1065 | Int counter = 0; |
|---|
| [1231] | 1066 | // WARNING: The following code only works only if a matching long-term RPS is |
|---|
| 1067 | // found in the SPS for ALL long-term pictures |
|---|
| 1068 | // The problem is that the SPS coded long-term pictures are moved to the |
|---|
| 1069 | // beginning of the list which causes a mismatch when no reference picture |
|---|
| 1070 | // list reordering is used |
|---|
| 1071 | // NB: Long-term coding is currently not supported in general by the HM encoder |
|---|
| [1029] | 1072 | for(Int k = rps->getNumberOfPictures()-1; k > rps->getNumberOfPictures()-rps->getNumberOfLongtermPictures()-1; k--) |
|---|
| 1073 | { |
|---|
| 1074 | if (findMatchingLTRP(pcSlice, <rpIndex, rps->getPOC(k), rps->getUsed(k))) |
|---|
| 1075 | { |
|---|
| 1076 | ltrpInSPS[numLtrpInSPS] = ltrpIndex; |
|---|
| 1077 | numLtrpInSPS++; |
|---|
| 1078 | } |
|---|
| 1079 | else |
|---|
| 1080 | { |
|---|
| 1081 | counter++; |
|---|
| 1082 | } |
|---|
| 1083 | } |
|---|
| 1084 | numLtrpInSH -= numLtrpInSPS; |
|---|
| [1231] | 1085 | // check that either all long-term pictures are coded in SPS or in slice header (no mixing) |
|---|
| [1250] | 1086 | assert (numLtrpInSH==0 || numLtrpInSPS==0); |
|---|
| [1029] | 1087 | |
|---|
| 1088 | Int bitsForLtrpInSPS = 0; |
|---|
| 1089 | while (pcSlice->getSPS()->getNumLongTermRefPicSPS() > (1 << bitsForLtrpInSPS)) |
|---|
| 1090 | { |
|---|
| 1091 | bitsForLtrpInSPS++; |
|---|
| 1092 | } |
|---|
| 1093 | if (pcSlice->getSPS()->getNumLongTermRefPicSPS() > 0) |
|---|
| 1094 | { |
|---|
| 1095 | WRITE_UVLC( numLtrpInSPS, "num_long_term_sps"); |
|---|
| 1096 | } |
|---|
| 1097 | WRITE_UVLC( numLtrpInSH, "num_long_term_pics"); |
|---|
| 1098 | // Note that the LSBs of the LT ref. pic. POCs must be sorted before. |
|---|
| 1099 | // Not sorted here because LT ref indices will be used in setRefPicList() |
|---|
| 1100 | Int prevDeltaMSB = 0, prevLSB = 0; |
|---|
| 1101 | Int offset = rps->getNumberOfNegativePictures() + rps->getNumberOfPositivePictures(); |
|---|
| [1231] | 1102 | counter = 0; |
|---|
| 1103 | // Warning: If some pictures are moved to ltrpInSPS, i is referring to a wrong index |
|---|
| 1104 | // (mapping would be required) |
|---|
| 1105 | for(Int i=rps->getNumberOfPictures()-1 ; i > offset-1; i--, counter++) |
|---|
| [1029] | 1106 | { |
|---|
| 1107 | if (counter < numLtrpInSPS) |
|---|
| 1108 | { |
|---|
| 1109 | if (bitsForLtrpInSPS > 0) |
|---|
| 1110 | { |
|---|
| 1111 | WRITE_CODE( ltrpInSPS[counter], bitsForLtrpInSPS, "lt_idx_sps[i]"); |
|---|
| 1112 | } |
|---|
| 1113 | } |
|---|
| 1114 | else |
|---|
| 1115 | { |
|---|
| 1116 | WRITE_CODE( rps->getPocLSBLT(i), pcSlice->getSPS()->getBitsForPOC(), "poc_lsb_lt"); |
|---|
| 1117 | WRITE_FLAG( rps->getUsed(i), "used_by_curr_pic_lt_flag"); |
|---|
| 1118 | } |
|---|
| 1119 | WRITE_FLAG( rps->getDeltaPocMSBPresentFlag(i), "delta_poc_msb_present_flag"); |
|---|
| 1120 | |
|---|
| 1121 | if(rps->getDeltaPocMSBPresentFlag(i)) |
|---|
| 1122 | { |
|---|
| 1123 | Bool deltaFlag = false; |
|---|
| 1124 | // First LTRP from SPS || First LTRP from SH || curr LSB != prev LSB |
|---|
| 1125 | if( (i == rps->getNumberOfPictures()-1) || (i == rps->getNumberOfPictures()-1-numLtrpInSPS) || (rps->getPocLSBLT(i) != prevLSB) ) |
|---|
| 1126 | { |
|---|
| 1127 | deltaFlag = true; |
|---|
| 1128 | } |
|---|
| 1129 | if(deltaFlag) |
|---|
| 1130 | { |
|---|
| 1131 | WRITE_UVLC( rps->getDeltaPocMSBCycleLT(i), "delta_poc_msb_cycle_lt[i]" ); |
|---|
| 1132 | } |
|---|
| 1133 | else |
|---|
| 1134 | { |
|---|
| 1135 | Int differenceInDeltaMSB = rps->getDeltaPocMSBCycleLT(i) - prevDeltaMSB; |
|---|
| 1136 | assert(differenceInDeltaMSB >= 0); |
|---|
| 1137 | WRITE_UVLC( differenceInDeltaMSB, "delta_poc_msb_cycle_lt[i]" ); |
|---|
| 1138 | } |
|---|
| 1139 | prevLSB = rps->getPocLSBLT(i); |
|---|
| 1140 | prevDeltaMSB = rps->getDeltaPocMSBCycleLT(i); |
|---|
| 1141 | } |
|---|
| 1142 | } |
|---|
| 1143 | } |
|---|
| 1144 | if (pcSlice->getSPS()->getTMVPFlagsPresent()) |
|---|
| 1145 | { |
|---|
| [1257] | 1146 | WRITE_FLAG( pcSlice->getEnableTMVPFlag() ? 1 : 0, "slice_temporal_mvp_enabled_flag" ); |
|---|
| [1029] | 1147 | } |
|---|
| 1148 | } |
|---|
| 1149 | |
|---|
| 1150 | #if SVC_EXTENSION |
|---|
| 1151 | if((pcSlice->getLayerId() > 0) && !(pcSlice->getVPS()->getIlpSshSignalingEnabledFlag()) && (pcSlice->getNumILRRefIdx() > 0) ) |
|---|
| 1152 | { |
|---|
| 1153 | WRITE_FLAG(pcSlice->getInterLayerPredEnabledFlag(),"inter_layer_pred_enabled_flag"); |
|---|
| 1154 | if( pcSlice->getInterLayerPredEnabledFlag()) |
|---|
| 1155 | { |
|---|
| 1156 | if(pcSlice->getNumILRRefIdx() > 1) |
|---|
| 1157 | { |
|---|
| 1158 | Int numBits = 1; |
|---|
| 1159 | while ((1 << numBits) < pcSlice->getNumILRRefIdx()) |
|---|
| 1160 | { |
|---|
| 1161 | numBits++; |
|---|
| 1162 | } |
|---|
| 1163 | if( !pcSlice->getVPS()->getMaxOneActiveRefLayerFlag()) |
|---|
| 1164 | { |
|---|
| 1165 | WRITE_CODE(pcSlice->getActiveNumILRRefIdx() - 1, numBits,"num_inter_layer_ref_pics_minus1"); |
|---|
| 1166 | } |
|---|
| 1167 | |
|---|
| 1168 | if( pcSlice->getNumILRRefIdx() != pcSlice->getActiveNumILRRefIdx() ) |
|---|
| 1169 | { |
|---|
| 1170 | for(Int i = 0; i < pcSlice->getActiveNumILRRefIdx(); i++ ) |
|---|
| 1171 | { |
|---|
| 1172 | WRITE_CODE(pcSlice->getInterLayerPredLayerIdc(i),numBits,"inter_layer_pred_layer_idc[i]"); |
|---|
| 1173 | } |
|---|
| 1174 | } |
|---|
| 1175 | } |
|---|
| 1176 | } |
|---|
| 1177 | } |
|---|
| 1178 | #endif //SVC_EXTENSION |
|---|
| 1179 | |
|---|
| 1180 | if(pcSlice->getSPS()->getUseSAO()) |
|---|
| 1181 | { |
|---|
| 1182 | WRITE_FLAG( pcSlice->getSaoEnabledFlag(CHANNEL_TYPE_LUMA), "slice_sao_luma_flag" ); |
|---|
| [1246] | 1183 | if (chromaEnabled) |
|---|
| 1184 | { |
|---|
| 1185 | WRITE_FLAG( pcSlice->getSaoEnabledFlag(CHANNEL_TYPE_CHROMA), "slice_sao_chroma_flag" ); |
|---|
| 1186 | } |
|---|
| [1029] | 1187 | } |
|---|
| 1188 | |
|---|
| 1189 | //check if numrefidxes match the defaults. If not, override |
|---|
| 1190 | |
|---|
| 1191 | if (!pcSlice->isIntra()) |
|---|
| 1192 | { |
|---|
| 1193 | Bool overrideFlag = (pcSlice->getNumRefIdx( REF_PIC_LIST_0 )!=pcSlice->getPPS()->getNumRefIdxL0DefaultActive()||(pcSlice->isInterB()&&pcSlice->getNumRefIdx( REF_PIC_LIST_1 )!=pcSlice->getPPS()->getNumRefIdxL1DefaultActive())); |
|---|
| 1194 | WRITE_FLAG( overrideFlag ? 1 : 0, "num_ref_idx_active_override_flag"); |
|---|
| 1195 | if (overrideFlag) |
|---|
| 1196 | { |
|---|
| 1197 | WRITE_UVLC( pcSlice->getNumRefIdx( REF_PIC_LIST_0 ) - 1, "num_ref_idx_l0_active_minus1" ); |
|---|
| 1198 | if (pcSlice->isInterB()) |
|---|
| 1199 | { |
|---|
| 1200 | WRITE_UVLC( pcSlice->getNumRefIdx( REF_PIC_LIST_1 ) - 1, "num_ref_idx_l1_active_minus1" ); |
|---|
| 1201 | } |
|---|
| 1202 | else |
|---|
| 1203 | { |
|---|
| 1204 | pcSlice->setNumRefIdx(REF_PIC_LIST_1, 0); |
|---|
| 1205 | } |
|---|
| 1206 | } |
|---|
| 1207 | } |
|---|
| 1208 | else |
|---|
| 1209 | { |
|---|
| 1210 | pcSlice->setNumRefIdx(REF_PIC_LIST_0, 0); |
|---|
| 1211 | pcSlice->setNumRefIdx(REF_PIC_LIST_1, 0); |
|---|
| 1212 | } |
|---|
| 1213 | |
|---|
| 1214 | if( pcSlice->getPPS()->getListsModificationPresentFlag() && pcSlice->getNumRpsCurrTempList() > 1) |
|---|
| 1215 | { |
|---|
| 1216 | TComRefPicListModification* refPicListModification = pcSlice->getRefPicListModification(); |
|---|
| 1217 | if(!pcSlice->isIntra()) |
|---|
| 1218 | { |
|---|
| 1219 | WRITE_FLAG(pcSlice->getRefPicListModification()->getRefPicListModificationFlagL0() ? 1 : 0, "ref_pic_list_modification_flag_l0" ); |
|---|
| 1220 | if (pcSlice->getRefPicListModification()->getRefPicListModificationFlagL0()) |
|---|
| 1221 | { |
|---|
| 1222 | Int numRpsCurrTempList0 = pcSlice->getNumRpsCurrTempList(); |
|---|
| 1223 | if (numRpsCurrTempList0 > 1) |
|---|
| 1224 | { |
|---|
| 1225 | Int length = 1; |
|---|
| 1226 | numRpsCurrTempList0 --; |
|---|
| 1227 | while ( numRpsCurrTempList0 >>= 1) |
|---|
| 1228 | { |
|---|
| 1229 | length ++; |
|---|
| 1230 | } |
|---|
| 1231 | for(Int i = 0; i < pcSlice->getNumRefIdx( REF_PIC_LIST_0 ); i++) |
|---|
| 1232 | { |
|---|
| 1233 | WRITE_CODE( refPicListModification->getRefPicSetIdxL0(i), length, "list_entry_l0"); |
|---|
| 1234 | } |
|---|
| 1235 | } |
|---|
| 1236 | } |
|---|
| 1237 | } |
|---|
| 1238 | if(pcSlice->isInterB()) |
|---|
| 1239 | { |
|---|
| 1240 | WRITE_FLAG(pcSlice->getRefPicListModification()->getRefPicListModificationFlagL1() ? 1 : 0, "ref_pic_list_modification_flag_l1" ); |
|---|
| 1241 | if (pcSlice->getRefPicListModification()->getRefPicListModificationFlagL1()) |
|---|
| 1242 | { |
|---|
| 1243 | Int numRpsCurrTempList1 = pcSlice->getNumRpsCurrTempList(); |
|---|
| 1244 | if ( numRpsCurrTempList1 > 1 ) |
|---|
| 1245 | { |
|---|
| 1246 | Int length = 1; |
|---|
| 1247 | numRpsCurrTempList1 --; |
|---|
| 1248 | while ( numRpsCurrTempList1 >>= 1) |
|---|
| 1249 | { |
|---|
| 1250 | length ++; |
|---|
| 1251 | } |
|---|
| 1252 | for(Int i = 0; i < pcSlice->getNumRefIdx( REF_PIC_LIST_1 ); i++) |
|---|
| 1253 | { |
|---|
| 1254 | WRITE_CODE( refPicListModification->getRefPicSetIdxL1(i), length, "list_entry_l1"); |
|---|
| 1255 | } |
|---|
| 1256 | } |
|---|
| 1257 | } |
|---|
| 1258 | } |
|---|
| 1259 | } |
|---|
| 1260 | |
|---|
| 1261 | if (pcSlice->isInterB()) |
|---|
| 1262 | { |
|---|
| 1263 | WRITE_FLAG( pcSlice->getMvdL1ZeroFlag() ? 1 : 0, "mvd_l1_zero_flag"); |
|---|
| 1264 | } |
|---|
| 1265 | |
|---|
| 1266 | if(!pcSlice->isIntra()) |
|---|
| 1267 | { |
|---|
| 1268 | if (!pcSlice->isIntra() && pcSlice->getPPS()->getCabacInitPresentFlag()) |
|---|
| 1269 | { |
|---|
| 1270 | SliceType sliceType = pcSlice->getSliceType(); |
|---|
| [1235] | 1271 | SliceType encCABACTableIdx = pcSlice->getEncCABACTableIdx(); |
|---|
| [1029] | 1272 | Bool encCabacInitFlag = (sliceType!=encCABACTableIdx && encCABACTableIdx!=I_SLICE) ? true : false; |
|---|
| 1273 | pcSlice->setCabacInitFlag( encCabacInitFlag ); |
|---|
| 1274 | WRITE_FLAG( encCabacInitFlag?1:0, "cabac_init_flag" ); |
|---|
| 1275 | } |
|---|
| 1276 | } |
|---|
| 1277 | |
|---|
| 1278 | if ( pcSlice->getEnableTMVPFlag() ) |
|---|
| 1279 | { |
|---|
| 1280 | if ( pcSlice->getSliceType() == B_SLICE ) |
|---|
| 1281 | { |
|---|
| 1282 | WRITE_FLAG( pcSlice->getColFromL0Flag(), "collocated_from_l0_flag" ); |
|---|
| 1283 | } |
|---|
| 1284 | |
|---|
| 1285 | if ( pcSlice->getSliceType() != I_SLICE && |
|---|
| 1286 | ((pcSlice->getColFromL0Flag()==1 && pcSlice->getNumRefIdx(REF_PIC_LIST_0)>1)|| |
|---|
| 1287 | (pcSlice->getColFromL0Flag()==0 && pcSlice->getNumRefIdx(REF_PIC_LIST_1)>1))) |
|---|
| 1288 | { |
|---|
| 1289 | WRITE_UVLC( pcSlice->getColRefIdx(), "collocated_ref_idx" ); |
|---|
| 1290 | } |
|---|
| 1291 | } |
|---|
| 1292 | if ( (pcSlice->getPPS()->getUseWP() && pcSlice->getSliceType()==P_SLICE) || (pcSlice->getPPS()->getWPBiPred() && pcSlice->getSliceType()==B_SLICE) ) |
|---|
| 1293 | { |
|---|
| 1294 | xCodePredWeightTable( pcSlice ); |
|---|
| 1295 | } |
|---|
| 1296 | assert(pcSlice->getMaxNumMergeCand()<=MRG_MAX_NUM_CANDS); |
|---|
| 1297 | if (!pcSlice->isIntra()) |
|---|
| 1298 | { |
|---|
| 1299 | WRITE_UVLC(MRG_MAX_NUM_CANDS - pcSlice->getMaxNumMergeCand(), "five_minus_max_num_merge_cand"); |
|---|
| 1300 | } |
|---|
| 1301 | Int iCode = pcSlice->getSliceQp() - ( pcSlice->getPPS()->getPicInitQPMinus26() + 26 ); |
|---|
| 1302 | WRITE_SVLC( iCode, "slice_qp_delta" ); |
|---|
| 1303 | if (pcSlice->getPPS()->getSliceChromaQpFlag()) |
|---|
| 1304 | { |
|---|
| [1246] | 1305 | if (numberValidComponents > COMPONENT_Cb) |
|---|
| 1306 | { |
|---|
| [1257] | 1307 | WRITE_SVLC( pcSlice->getSliceChromaQpDelta(COMPONENT_Cb), "slice_cb_qp_offset" ); |
|---|
| [1246] | 1308 | } |
|---|
| 1309 | if (numberValidComponents > COMPONENT_Cr) |
|---|
| 1310 | { |
|---|
| [1257] | 1311 | WRITE_SVLC( pcSlice->getSliceChromaQpDelta(COMPONENT_Cr), "slice_cr_qp_offset" ); |
|---|
| [1246] | 1312 | } |
|---|
| [1029] | 1313 | assert(numberValidComponents <= COMPONENT_Cr+1); |
|---|
| 1314 | } |
|---|
| 1315 | |
|---|
| [1316] | 1316 | if (pcSlice->getPPS()->getPpsRangeExtension().getChromaQpOffsetListEnabledFlag()) |
|---|
| [1029] | 1317 | { |
|---|
| [1257] | 1318 | WRITE_FLAG(pcSlice->getUseChromaQpAdj(), "cu_chroma_qp_offset_enabled_flag"); |
|---|
| [1029] | 1319 | } |
|---|
| 1320 | |
|---|
| 1321 | if (pcSlice->getPPS()->getDeblockingFilterControlPresentFlag()) |
|---|
| 1322 | { |
|---|
| 1323 | if (pcSlice->getPPS()->getDeblockingFilterOverrideEnabledFlag() ) |
|---|
| 1324 | { |
|---|
| 1325 | WRITE_FLAG(pcSlice->getDeblockingFilterOverrideFlag(), "deblocking_filter_override_flag"); |
|---|
| 1326 | } |
|---|
| 1327 | if (pcSlice->getDeblockingFilterOverrideFlag()) |
|---|
| 1328 | { |
|---|
| 1329 | WRITE_FLAG(pcSlice->getDeblockingFilterDisable(), "slice_disable_deblocking_filter_flag"); |
|---|
| 1330 | if(!pcSlice->getDeblockingFilterDisable()) |
|---|
| 1331 | { |
|---|
| 1332 | WRITE_SVLC (pcSlice->getDeblockingFilterBetaOffsetDiv2(), "slice_beta_offset_div2"); |
|---|
| 1333 | WRITE_SVLC (pcSlice->getDeblockingFilterTcOffsetDiv2(), "slice_tc_offset_div2"); |
|---|
| 1334 | } |
|---|
| 1335 | } |
|---|
| 1336 | } |
|---|
| 1337 | |
|---|
| 1338 | Bool isSAOEnabled = pcSlice->getSPS()->getUseSAO() && (pcSlice->getSaoEnabledFlag(CHANNEL_TYPE_LUMA) || (chromaEnabled && pcSlice->getSaoEnabledFlag(CHANNEL_TYPE_CHROMA))); |
|---|
| 1339 | Bool isDBFEnabled = (!pcSlice->getDeblockingFilterDisable()); |
|---|
| 1340 | |
|---|
| 1341 | if(pcSlice->getPPS()->getLoopFilterAcrossSlicesEnabledFlag() && ( isSAOEnabled || isDBFEnabled )) |
|---|
| 1342 | { |
|---|
| 1343 | WRITE_FLAG(pcSlice->getLFCrossSliceBoundaryFlag()?1:0, "slice_loop_filter_across_slices_enabled_flag"); |
|---|
| 1344 | } |
|---|
| 1345 | } |
|---|
| [1250] | 1346 | #if !SVC_EXTENSION |
|---|
| 1347 | if(pcSlice->getPPS()->getSliceHeaderExtensionPresentFlag()) |
|---|
| 1348 | { |
|---|
| [1257] | 1349 | WRITE_UVLC(0,"slice_segment_header_extension_length"); |
|---|
| [1250] | 1350 | } |
|---|
| 1351 | #endif |
|---|
| [1029] | 1352 | } |
|---|
| 1353 | |
|---|
| [1235] | 1354 | Void TEncCavlc::codePTL( const TComPTL* pcPTL, Bool profilePresentFlag, Int maxNumSubLayersMinus1) |
|---|
| [1029] | 1355 | { |
|---|
| 1356 | if(profilePresentFlag) |
|---|
| 1357 | { |
|---|
| [1257] | 1358 | codeProfileTier(pcPTL->getGeneralPTL(), false); // general_... |
|---|
| [1029] | 1359 | } |
|---|
| 1360 | WRITE_CODE( Int(pcPTL->getGeneralPTL()->getLevelIdc()), 8, "general_level_idc" ); |
|---|
| 1361 | |
|---|
| 1362 | for (Int i = 0; i < maxNumSubLayersMinus1; i++) |
|---|
| 1363 | { |
|---|
| 1364 | WRITE_FLAG( pcPTL->getSubLayerProfilePresentFlag(i), "sub_layer_profile_present_flag[i]" ); |
|---|
| 1365 | WRITE_FLAG( pcPTL->getSubLayerLevelPresentFlag(i), "sub_layer_level_present_flag[i]" ); |
|---|
| 1366 | } |
|---|
| 1367 | |
|---|
| 1368 | if (maxNumSubLayersMinus1 > 0) |
|---|
| 1369 | { |
|---|
| 1370 | for (Int i = maxNumSubLayersMinus1; i < 8; i++) |
|---|
| 1371 | { |
|---|
| 1372 | WRITE_CODE(0, 2, "reserved_zero_2bits"); |
|---|
| 1373 | } |
|---|
| 1374 | } |
|---|
| 1375 | |
|---|
| 1376 | for(Int i = 0; i < maxNumSubLayersMinus1; i++) |
|---|
| 1377 | { |
|---|
| 1378 | if( pcPTL->getSubLayerProfilePresentFlag(i) ) |
|---|
| 1379 | { |
|---|
| [1257] | 1380 | codeProfileTier(pcPTL->getSubLayerPTL(i), true); // sub_layer_... |
|---|
| [1029] | 1381 | } |
|---|
| 1382 | if( pcPTL->getSubLayerLevelPresentFlag(i) ) |
|---|
| 1383 | { |
|---|
| 1384 | WRITE_CODE( Int(pcPTL->getSubLayerPTL(i)->getLevelIdc()), 8, "sub_layer_level_idc[i]" ); |
|---|
| 1385 | } |
|---|
| 1386 | } |
|---|
| 1387 | } |
|---|
| [1257] | 1388 | |
|---|
| 1389 | #if ENC_DEC_TRACE || RExt__DECODER_DEBUG_BIT_STATISTICS |
|---|
| 1390 | Void TEncCavlc::codeProfileTier( const ProfileTierLevel* ptl, const Bool bIsSubLayer ) |
|---|
| 1391 | #define PTL_TRACE_TEXT(txt) bIsSubLayer?("sub_layer_" txt) : ("general_" txt) |
|---|
| 1392 | #else |
|---|
| 1393 | Void TEncCavlc::codeProfileTier( const ProfileTierLevel* ptl, const Bool /*bIsSubLayer*/ ) |
|---|
| 1394 | #define PTL_TRACE_TEXT(txt) txt |
|---|
| 1395 | #endif |
|---|
| [1029] | 1396 | { |
|---|
| [1257] | 1397 | WRITE_CODE( ptl->getProfileSpace(), 2 , PTL_TRACE_TEXT("profile_space" )); |
|---|
| 1398 | WRITE_FLAG( ptl->getTierFlag()==Level::HIGH, PTL_TRACE_TEXT("tier_flag" )); |
|---|
| [1182] | 1399 | #if SVC_EXTENSION |
|---|
| [1257] | 1400 | WRITE_CODE( (ptl->getProfileIdc() == Profile::SCALABLEMAIN || ptl->getProfileIdc() == Profile::SCALABLEMAIN10) ? 7 : Int(ptl->getProfileIdc()), 5 , PTL_TRACE_TEXT("profile_idc") ); |
|---|
| [1029] | 1401 | #else |
|---|
| [1257] | 1402 | WRITE_CODE( Int(ptl->getProfileIdc()), 5 , PTL_TRACE_TEXT("profile_idc" )); |
|---|
| [1029] | 1403 | #endif |
|---|
| 1404 | for(Int j = 0; j < 32; j++) |
|---|
| 1405 | { |
|---|
| [1257] | 1406 | WRITE_FLAG( ptl->getProfileCompatibilityFlag(j), PTL_TRACE_TEXT("profile_compatibility_flag[][j]" )); |
|---|
| [1029] | 1407 | } |
|---|
| 1408 | |
|---|
| [1257] | 1409 | WRITE_FLAG(ptl->getProgressiveSourceFlag(), PTL_TRACE_TEXT("progressive_source_flag" )); |
|---|
| 1410 | WRITE_FLAG(ptl->getInterlacedSourceFlag(), PTL_TRACE_TEXT("interlaced_source_flag" )); |
|---|
| 1411 | WRITE_FLAG(ptl->getNonPackedConstraintFlag(), PTL_TRACE_TEXT("non_packed_constraint_flag" )); |
|---|
| 1412 | WRITE_FLAG(ptl->getFrameOnlyConstraintFlag(), PTL_TRACE_TEXT("frame_only_constraint_flag" )); |
|---|
| [1029] | 1413 | |
|---|
| [1487] | 1414 | if (ptl->getProfileIdc() == Profile::MAINREXT || ptl->getProfileIdc() == Profile::HIGHTHROUGHPUTREXT |
|---|
| 1415 | #if SCALABLE_REXT |
|---|
| 1416 | || ptl->getProfileIdc() == Profile::SCALABLEREXT |
|---|
| 1417 | #endif |
|---|
| 1418 | ) |
|---|
| [1029] | 1419 | { |
|---|
| 1420 | const UInt bitDepthConstraint=ptl->getBitDepthConstraint(); |
|---|
| [1257] | 1421 | WRITE_FLAG(bitDepthConstraint<=12, PTL_TRACE_TEXT("max_12bit_constraint_flag" )); |
|---|
| 1422 | WRITE_FLAG(bitDepthConstraint<=10, PTL_TRACE_TEXT("max_10bit_constraint_flag" )); |
|---|
| 1423 | WRITE_FLAG(bitDepthConstraint<= 8, PTL_TRACE_TEXT("max_8bit_constraint_flag" )); |
|---|
| [1029] | 1424 | const ChromaFormat chromaFmtConstraint=ptl->getChromaFormatConstraint(); |
|---|
| [1257] | 1425 | WRITE_FLAG(chromaFmtConstraint==CHROMA_422||chromaFmtConstraint==CHROMA_420||chromaFmtConstraint==CHROMA_400, PTL_TRACE_TEXT("max_422chroma_constraint_flag" )); |
|---|
| 1426 | WRITE_FLAG(chromaFmtConstraint==CHROMA_420||chromaFmtConstraint==CHROMA_400, PTL_TRACE_TEXT("max_420chroma_constraint_flag" )); |
|---|
| 1427 | WRITE_FLAG(chromaFmtConstraint==CHROMA_400, PTL_TRACE_TEXT("max_monochrome_constraint_flag")); |
|---|
| [1356] | 1428 | WRITE_FLAG(ptl->getIntraConstraintFlag(), PTL_TRACE_TEXT("intra_constraint_flag" )); |
|---|
| 1429 | WRITE_FLAG(ptl->getOnePictureOnlyConstraintFlag(), PTL_TRACE_TEXT("one_picture_only_constraint_flag")); |
|---|
| 1430 | WRITE_FLAG(ptl->getLowerBitRateConstraintFlag(), PTL_TRACE_TEXT("lower_bit_rate_constraint_flag" )); |
|---|
| [1182] | 1431 | #if SVC_EXTENSION |
|---|
| [1029] | 1432 | WRITE_CODE(0, 32, "general_reserved_zero_34bits"); WRITE_CODE(0, 2, "general_reserved_zero_34bits"); |
|---|
| 1433 | } |
|---|
| 1434 | else if( ptl->getProfileIdc() == Profile::SCALABLEMAIN || ptl->getProfileIdc() == Profile::SCALABLEMAIN10 ) // at encoder side, scalable-main10 profile has a profile idc equal to 8, which is converted to 7 during signalling |
|---|
| 1435 | { |
|---|
| 1436 | WRITE_FLAG(true, "general_max_12bit_constraint_flag"); |
|---|
| 1437 | WRITE_FLAG(true, "general_max_10bit_constraint_flag"); |
|---|
| 1438 | WRITE_FLAG((ptl->getProfileIdc() == Profile::SCALABLEMAIN) ? true : false, "general_max_8bit_constraint_flag"); |
|---|
| 1439 | WRITE_FLAG(true, "general_max_422chroma_constraint_flag"); |
|---|
| 1440 | WRITE_FLAG(true, "general_max_420chroma_constraint_flag"); |
|---|
| 1441 | WRITE_FLAG(false, "general_max_monochrome_constraint_flag"); |
|---|
| 1442 | WRITE_FLAG(false, "general_intra_constraint_flag"); |
|---|
| 1443 | WRITE_FLAG(false, "general_one_picture_only_constraint_flag"); |
|---|
| 1444 | WRITE_FLAG(true, "general_lower_bit_rate_constraint_flag"); |
|---|
| 1445 | WRITE_CODE(0, 32, "general_reserved_zero_34bits"); WRITE_CODE(0, 2, "general_reserved_zero_34bits"); |
|---|
| 1446 | } |
|---|
| 1447 | else |
|---|
| 1448 | { |
|---|
| 1449 | WRITE_CODE(0, 32, "general_reserved_zero_43bits"); WRITE_CODE(0, 11, "general_reserved_zero_43bits"); |
|---|
| 1450 | } |
|---|
| 1451 | #else |
|---|
| [1257] | 1452 | WRITE_CODE(0 , 16, PTL_TRACE_TEXT("reserved_zero_34bits[0..15]" )); |
|---|
| 1453 | WRITE_CODE(0 , 16, PTL_TRACE_TEXT("reserved_zero_34bits[16..31]" )); |
|---|
| 1454 | WRITE_CODE(0 , 2, PTL_TRACE_TEXT("reserved_zero_34bits[32..33]" )); |
|---|
| [1029] | 1455 | } |
|---|
| 1456 | else |
|---|
| 1457 | { |
|---|
| [1257] | 1458 | WRITE_CODE(0x0000 , 16, PTL_TRACE_TEXT("reserved_zero_43bits[0..15]" )); |
|---|
| 1459 | WRITE_CODE(0x0000 , 16, PTL_TRACE_TEXT("reserved_zero_43bits[16..31]" )); |
|---|
| [1266] | 1460 | WRITE_CODE(0x000 , 11, PTL_TRACE_TEXT("reserved_zero_43bits[32..42]" )); |
|---|
| [1029] | 1461 | } |
|---|
| 1462 | #endif |
|---|
| [1257] | 1463 | WRITE_FLAG(false, PTL_TRACE_TEXT("inbld_flag" )); |
|---|
| 1464 | #undef PTL_TRACE_TEXT |
|---|
| [1029] | 1465 | } |
|---|
| 1466 | |
|---|
| 1467 | /** |
|---|
| [1260] | 1468 | * Write tiles and wavefront substreams sizes for the slice header (entry points). |
|---|
| 1469 | * |
|---|
| 1470 | * \param pSlice TComSlice structure that contains the substream size information. |
|---|
| [1029] | 1471 | */ |
|---|
| 1472 | Void TEncCavlc::codeTilesWPPEntryPoint( TComSlice* pSlice ) |
|---|
| 1473 | { |
|---|
| 1474 | if (!pSlice->getPPS()->getTilesEnabledFlag() && !pSlice->getPPS()->getEntropyCodingSyncEnabledFlag()) |
|---|
| 1475 | { |
|---|
| 1476 | return; |
|---|
| 1477 | } |
|---|
| 1478 | UInt maxOffset = 0; |
|---|
| 1479 | for(Int idx=0; idx<pSlice->getNumberOfSubstreamSizes(); idx++) |
|---|
| 1480 | { |
|---|
| 1481 | UInt offset=pSlice->getSubstreamSize(idx); |
|---|
| 1482 | if ( offset > maxOffset ) |
|---|
| 1483 | { |
|---|
| 1484 | maxOffset = offset; |
|---|
| 1485 | } |
|---|
| 1486 | } |
|---|
| 1487 | |
|---|
| 1488 | // Determine number of bits "offsetLenMinus1+1" required for entry point information |
|---|
| 1489 | UInt offsetLenMinus1 = 0; |
|---|
| 1490 | while (maxOffset >= (1u << (offsetLenMinus1 + 1))) |
|---|
| 1491 | { |
|---|
| 1492 | offsetLenMinus1++; |
|---|
| 1493 | assert(offsetLenMinus1 + 1 < 32); |
|---|
| 1494 | } |
|---|
| 1495 | |
|---|
| 1496 | WRITE_UVLC(pSlice->getNumberOfSubstreamSizes(), "num_entry_point_offsets"); |
|---|
| 1497 | if (pSlice->getNumberOfSubstreamSizes()>0) |
|---|
| 1498 | { |
|---|
| 1499 | WRITE_UVLC(offsetLenMinus1, "offset_len_minus1"); |
|---|
| 1500 | |
|---|
| 1501 | for (UInt idx=0; idx<pSlice->getNumberOfSubstreamSizes(); idx++) |
|---|
| 1502 | { |
|---|
| 1503 | WRITE_CODE(pSlice->getSubstreamSize(idx)-1, offsetLenMinus1+1, "entry_point_offset_minus1"); |
|---|
| 1504 | } |
|---|
| 1505 | } |
|---|
| 1506 | } |
|---|
| 1507 | |
|---|
| [1307] | 1508 | Void TEncCavlc::codeTerminatingBit ( UInt /*uilsLast*/ ) |
|---|
| [1029] | 1509 | { |
|---|
| 1510 | } |
|---|
| 1511 | |
|---|
| 1512 | Void TEncCavlc::codeSliceFinish () |
|---|
| 1513 | { |
|---|
| 1514 | } |
|---|
| 1515 | |
|---|
| [1307] | 1516 | Void TEncCavlc::codeMVPIdx ( TComDataCU* /*pcCU*/, UInt /*uiAbsPartIdx*/, RefPicList /*eRefList*/ ) |
|---|
| [1029] | 1517 | { |
|---|
| 1518 | assert(0); |
|---|
| 1519 | } |
|---|
| 1520 | |
|---|
| [1307] | 1521 | Void TEncCavlc::codePartSize( TComDataCU* /*pcCU*/, UInt /*uiAbsPartIdx*/, UInt /*uiDepth*/ ) |
|---|
| [1029] | 1522 | { |
|---|
| 1523 | assert(0); |
|---|
| 1524 | } |
|---|
| 1525 | |
|---|
| [1307] | 1526 | Void TEncCavlc::codePredMode( TComDataCU* /*pcCU*/, UInt /*uiAbsPartIdx*/ ) |
|---|
| [1029] | 1527 | { |
|---|
| 1528 | assert(0); |
|---|
| 1529 | } |
|---|
| 1530 | |
|---|
| [1307] | 1531 | Void TEncCavlc::codeMergeFlag ( TComDataCU* /*pcCU*/, UInt /*uiAbsPartIdx*/ ) |
|---|
| [1029] | 1532 | { |
|---|
| 1533 | assert(0); |
|---|
| 1534 | } |
|---|
| 1535 | |
|---|
| [1307] | 1536 | Void TEncCavlc::codeMergeIndex ( TComDataCU* /*pcCU*/, UInt /*uiAbsPartIdx*/ ) |
|---|
| [1029] | 1537 | { |
|---|
| 1538 | assert(0); |
|---|
| 1539 | } |
|---|
| 1540 | |
|---|
| [1307] | 1541 | Void TEncCavlc::codeInterModeFlag( TComDataCU* /*pcCU*/, UInt /*uiAbsPartIdx*/, UInt /*uiDepth*/, UInt /*uiEncMode*/ ) |
|---|
| [1029] | 1542 | { |
|---|
| 1543 | assert(0); |
|---|
| 1544 | } |
|---|
| 1545 | |
|---|
| [1307] | 1546 | Void TEncCavlc::codeCUTransquantBypassFlag( TComDataCU* /*pcCU*/, UInt /*uiAbsPartIdx*/ ) |
|---|
| [1029] | 1547 | { |
|---|
| 1548 | assert(0); |
|---|
| 1549 | } |
|---|
| 1550 | |
|---|
| [1307] | 1551 | Void TEncCavlc::codeSkipFlag( TComDataCU* /*pcCU*/, UInt /*uiAbsPartIdx*/ ) |
|---|
| [1029] | 1552 | { |
|---|
| 1553 | assert(0); |
|---|
| 1554 | } |
|---|
| 1555 | |
|---|
| [1307] | 1556 | Void TEncCavlc::codeSplitFlag ( TComDataCU* /*pcCU*/, UInt /*uiAbsPartIdx*/, UInt /*uiDepth*/ ) |
|---|
| [1029] | 1557 | { |
|---|
| 1558 | assert(0); |
|---|
| 1559 | } |
|---|
| 1560 | |
|---|
| [1307] | 1561 | Void TEncCavlc::codeTransformSubdivFlag( UInt /*uiSymbol*/, UInt /*uiCtx*/ ) |
|---|
| [1029] | 1562 | { |
|---|
| 1563 | assert(0); |
|---|
| 1564 | } |
|---|
| 1565 | |
|---|
| [1307] | 1566 | Void TEncCavlc::codeQtCbf( TComTU& /*rTu*/, const ComponentID /*compID*/, const Bool /*lowestLevel*/ ) |
|---|
| [1029] | 1567 | { |
|---|
| 1568 | assert(0); |
|---|
| 1569 | } |
|---|
| 1570 | |
|---|
| [1307] | 1571 | Void TEncCavlc::codeQtRootCbf( TComDataCU* /*pcCU*/, UInt /*uiAbsPartIdx*/ ) |
|---|
| [1029] | 1572 | { |
|---|
| 1573 | assert(0); |
|---|
| 1574 | } |
|---|
| 1575 | |
|---|
| [1307] | 1576 | Void TEncCavlc::codeQtCbfZero( TComTU& /*rTu*/, const ChannelType /*chType*/ ) |
|---|
| [1029] | 1577 | { |
|---|
| 1578 | assert(0); |
|---|
| 1579 | } |
|---|
| [1307] | 1580 | Void TEncCavlc::codeQtRootCbfZero( ) |
|---|
| [1029] | 1581 | { |
|---|
| 1582 | assert(0); |
|---|
| 1583 | } |
|---|
| 1584 | |
|---|
| [1307] | 1585 | Void TEncCavlc::codeTransformSkipFlags (TComTU& /*rTu*/, ComponentID /*component*/ ) |
|---|
| [1029] | 1586 | { |
|---|
| 1587 | assert(0); |
|---|
| 1588 | } |
|---|
| 1589 | |
|---|
| 1590 | /** Code I_PCM information. |
|---|
| 1591 | * \param pcCU pointer to CU |
|---|
| 1592 | * \param uiAbsPartIdx CU index |
|---|
| 1593 | * \returns Void |
|---|
| 1594 | */ |
|---|
| [1307] | 1595 | Void TEncCavlc::codeIPCMInfo( TComDataCU* /*pcCU*/, UInt /*uiAbsPartIdx*/ ) |
|---|
| [1029] | 1596 | { |
|---|
| 1597 | assert(0); |
|---|
| 1598 | } |
|---|
| 1599 | |
|---|
| [1307] | 1600 | Void TEncCavlc::codeIntraDirLumaAng( TComDataCU* /*pcCU*/, UInt /*uiAbsPartIdx*/, Bool /*isMultiple*/) |
|---|
| [1029] | 1601 | { |
|---|
| 1602 | assert(0); |
|---|
| 1603 | } |
|---|
| 1604 | |
|---|
| [1307] | 1605 | Void TEncCavlc::codeIntraDirChroma( TComDataCU* /*pcCU*/, UInt /*uiAbsPartIdx*/ ) |
|---|
| [1029] | 1606 | { |
|---|
| 1607 | assert(0); |
|---|
| 1608 | } |
|---|
| 1609 | |
|---|
| [1307] | 1610 | Void TEncCavlc::codeInterDir( TComDataCU* /*pcCU*/, UInt /*uiAbsPartIdx*/ ) |
|---|
| [1029] | 1611 | { |
|---|
| 1612 | assert(0); |
|---|
| 1613 | } |
|---|
| 1614 | |
|---|
| [1307] | 1615 | Void TEncCavlc::codeRefFrmIdx( TComDataCU* /*pcCU*/, UInt /*uiAbsPartIdx*/, RefPicList /*eRefList*/ ) |
|---|
| [1029] | 1616 | { |
|---|
| 1617 | assert(0); |
|---|
| 1618 | } |
|---|
| 1619 | |
|---|
| [1307] | 1620 | Void TEncCavlc::codeMvd( TComDataCU* /*pcCU*/, UInt /*uiAbsPartIdx*/, RefPicList /*eRefList*/ ) |
|---|
| [1029] | 1621 | { |
|---|
| 1622 | assert(0); |
|---|
| 1623 | } |
|---|
| 1624 | |
|---|
| 1625 | Void TEncCavlc::codeCrossComponentPrediction( TComTU& /*rTu*/, ComponentID /*compID*/ ) |
|---|
| 1626 | { |
|---|
| 1627 | assert(0); |
|---|
| 1628 | } |
|---|
| 1629 | |
|---|
| 1630 | Void TEncCavlc::codeDeltaQP( TComDataCU* pcCU, UInt uiAbsPartIdx ) |
|---|
| 1631 | { |
|---|
| 1632 | Int iDQp = pcCU->getQP( uiAbsPartIdx ) - pcCU->getRefQP( uiAbsPartIdx ); |
|---|
| 1633 | |
|---|
| 1634 | Int qpBdOffsetY = pcCU->getSlice()->getSPS()->getQpBDOffset(CHANNEL_TYPE_LUMA); |
|---|
| 1635 | iDQp = (iDQp + 78 + qpBdOffsetY + (qpBdOffsetY/2)) % (52 + qpBdOffsetY) - 26 - (qpBdOffsetY/2); |
|---|
| 1636 | |
|---|
| 1637 | xWriteSvlc( iDQp ); |
|---|
| 1638 | |
|---|
| 1639 | return; |
|---|
| 1640 | } |
|---|
| 1641 | |
|---|
| [1307] | 1642 | Void TEncCavlc::codeChromaQpAdjustment( TComDataCU* /*pcCU*/, UInt /*uiAbsPartIdx*/ ) |
|---|
| [1029] | 1643 | { |
|---|
| 1644 | assert(0); |
|---|
| 1645 | } |
|---|
| 1646 | |
|---|
| [1307] | 1647 | Void TEncCavlc::codeCoeffNxN ( TComTU& /*rTu*/, TCoeff* /*pcCoef*/, const ComponentID /*compID*/ ) |
|---|
| [1029] | 1648 | { |
|---|
| 1649 | assert(0); |
|---|
| 1650 | } |
|---|
| 1651 | |
|---|
| [1307] | 1652 | Void TEncCavlc::estBit( estBitsSbacStruct* /*pcEstBitsCabac*/, Int /*width*/, Int /*height*/, ChannelType /*chType*/ ) |
|---|
| [1029] | 1653 | { |
|---|
| 1654 | // printf("error : no VLC mode support in this version\n"); |
|---|
| 1655 | return; |
|---|
| 1656 | } |
|---|
| 1657 | |
|---|
| 1658 | // ==================================================================================================================== |
|---|
| 1659 | // Protected member functions |
|---|
| 1660 | // ==================================================================================================================== |
|---|
| 1661 | |
|---|
| [1260] | 1662 | //! Code weighted prediction tables |
|---|
| [1029] | 1663 | Void TEncCavlc::xCodePredWeightTable( TComSlice* pcSlice ) |
|---|
| 1664 | { |
|---|
| 1665 | WPScalingParam *wp; |
|---|
| 1666 | const ChromaFormat format = pcSlice->getPic()->getChromaFormat(); |
|---|
| 1667 | const UInt numberValidComponents = getNumberValidComponents(format); |
|---|
| 1668 | const Bool bChroma = isChromaEnabled(format); |
|---|
| 1669 | const Int iNbRef = (pcSlice->getSliceType() == B_SLICE ) ? (2) : (1); |
|---|
| 1670 | Bool bDenomCoded = false; |
|---|
| 1671 | UInt uiTotalSignalledWeightFlags = 0; |
|---|
| 1672 | |
|---|
| 1673 | if ( (pcSlice->getSliceType()==P_SLICE && pcSlice->getPPS()->getUseWP()) || (pcSlice->getSliceType()==B_SLICE && pcSlice->getPPS()->getWPBiPred()) ) |
|---|
| 1674 | { |
|---|
| [1257] | 1675 | for ( Int iNumRef=0 ; iNumRef<iNbRef ; iNumRef++ ) // loop over l0 and l1 syntax elements |
|---|
| [1029] | 1676 | { |
|---|
| 1677 | RefPicList eRefPicList = ( iNumRef ? REF_PIC_LIST_1 : REF_PIC_LIST_0 ); |
|---|
| 1678 | |
|---|
| 1679 | // NOTE: wp[].uiLog2WeightDenom and wp[].bPresentFlag are actually per-channel-type settings. |
|---|
| 1680 | |
|---|
| 1681 | for ( Int iRefIdx=0 ; iRefIdx<pcSlice->getNumRefIdx(eRefPicList) ; iRefIdx++ ) |
|---|
| 1682 | { |
|---|
| 1683 | pcSlice->getWpScaling(eRefPicList, iRefIdx, wp); |
|---|
| 1684 | if ( !bDenomCoded ) |
|---|
| 1685 | { |
|---|
| 1686 | Int iDeltaDenom; |
|---|
| [1257] | 1687 | WRITE_UVLC( wp[COMPONENT_Y].uiLog2WeightDenom, "luma_log2_weight_denom" ); |
|---|
| [1029] | 1688 | |
|---|
| 1689 | if( bChroma ) |
|---|
| 1690 | { |
|---|
| 1691 | assert(wp[COMPONENT_Cb].uiLog2WeightDenom == wp[COMPONENT_Cr].uiLog2WeightDenom); // check the channel-type settings are consistent across components. |
|---|
| 1692 | iDeltaDenom = (wp[COMPONENT_Cb].uiLog2WeightDenom - wp[COMPONENT_Y].uiLog2WeightDenom); |
|---|
| [1257] | 1693 | WRITE_SVLC( iDeltaDenom, "delta_chroma_log2_weight_denom" ); |
|---|
| [1029] | 1694 | } |
|---|
| 1695 | bDenomCoded = true; |
|---|
| 1696 | } |
|---|
| [1257] | 1697 | WRITE_FLAG( wp[COMPONENT_Y].bPresentFlag, iNumRef==0?"luma_weight_l0_flag[i]":"luma_weight_l1_flag[i]" ); |
|---|
| [1029] | 1698 | uiTotalSignalledWeightFlags += wp[COMPONENT_Y].bPresentFlag; |
|---|
| 1699 | } |
|---|
| 1700 | if (bChroma) |
|---|
| 1701 | { |
|---|
| 1702 | for ( Int iRefIdx=0 ; iRefIdx<pcSlice->getNumRefIdx(eRefPicList) ; iRefIdx++ ) |
|---|
| 1703 | { |
|---|
| 1704 | pcSlice->getWpScaling(eRefPicList, iRefIdx, wp); |
|---|
| 1705 | assert(wp[COMPONENT_Cb].bPresentFlag == wp[COMPONENT_Cr].bPresentFlag); // check the channel-type settings are consistent across components. |
|---|
| [1257] | 1706 | WRITE_FLAG( wp[COMPONENT_Cb].bPresentFlag, iNumRef==0?"chroma_weight_l0_flag[i]":"chroma_weight_l1_flag[i]" ); |
|---|
| [1029] | 1707 | uiTotalSignalledWeightFlags += 2*wp[COMPONENT_Cb].bPresentFlag; |
|---|
| 1708 | } |
|---|
| 1709 | } |
|---|
| 1710 | |
|---|
| 1711 | for ( Int iRefIdx=0 ; iRefIdx<pcSlice->getNumRefIdx(eRefPicList) ; iRefIdx++ ) |
|---|
| 1712 | { |
|---|
| 1713 | pcSlice->getWpScaling(eRefPicList, iRefIdx, wp); |
|---|
| 1714 | if ( wp[COMPONENT_Y].bPresentFlag ) |
|---|
| 1715 | { |
|---|
| 1716 | Int iDeltaWeight = (wp[COMPONENT_Y].iWeight - (1<<wp[COMPONENT_Y].uiLog2WeightDenom)); |
|---|
| [1257] | 1717 | WRITE_SVLC( iDeltaWeight, iNumRef==0?"delta_luma_weight_l0[i]":"delta_luma_weight_l1[i]" ); |
|---|
| 1718 | WRITE_SVLC( wp[COMPONENT_Y].iOffset, iNumRef==0?"luma_offset_l0[i]":"luma_offset_l1[i]" ); |
|---|
| [1029] | 1719 | } |
|---|
| 1720 | |
|---|
| 1721 | if ( bChroma ) |
|---|
| 1722 | { |
|---|
| 1723 | if ( wp[COMPONENT_Cb].bPresentFlag ) |
|---|
| 1724 | { |
|---|
| 1725 | for ( Int j = COMPONENT_Cb ; j < numberValidComponents ; j++ ) |
|---|
| 1726 | { |
|---|
| 1727 | assert(wp[COMPONENT_Cb].uiLog2WeightDenom == wp[COMPONENT_Cr].uiLog2WeightDenom); |
|---|
| 1728 | Int iDeltaWeight = (wp[j].iWeight - (1<<wp[COMPONENT_Cb].uiLog2WeightDenom)); |
|---|
| [1257] | 1729 | WRITE_SVLC( iDeltaWeight, iNumRef==0?"delta_chroma_weight_l0[i]":"delta_chroma_weight_l1[i]" ); |
|---|
| [1029] | 1730 | |
|---|
| [1316] | 1731 | Int range=pcSlice->getSPS()->getSpsRangeExtension().getHighPrecisionOffsetsEnabledFlag() ? (1<<pcSlice->getSPS()->getBitDepth(CHANNEL_TYPE_CHROMA))/2 : 128; |
|---|
| [1029] | 1732 | Int pred = ( range - ( ( range*wp[j].iWeight)>>(wp[j].uiLog2WeightDenom) ) ); |
|---|
| 1733 | Int iDeltaChroma = (wp[j].iOffset - pred); |
|---|
| [1257] | 1734 | WRITE_SVLC( iDeltaChroma, iNumRef==0?"delta_chroma_offset_l0[i]":"delta_chroma_offset_l1[i]" ); |
|---|
| [1029] | 1735 | } |
|---|
| 1736 | } |
|---|
| 1737 | } |
|---|
| 1738 | } |
|---|
| 1739 | } |
|---|
| 1740 | assert(uiTotalSignalledWeightFlags<=24); |
|---|
| 1741 | } |
|---|
| 1742 | } |
|---|
| 1743 | |
|---|
| 1744 | /** code quantization matrix |
|---|
| 1745 | * \param scalingList quantization matrix information |
|---|
| 1746 | */ |
|---|
| [1235] | 1747 | Void TEncCavlc::codeScalingList( const TComScalingList &scalingList ) |
|---|
| [1029] | 1748 | { |
|---|
| 1749 | //for each size |
|---|
| [1235] | 1750 | for(UInt sizeId = 0; sizeId < SCALING_LIST_SIZE_NUM; sizeId++) |
|---|
| [1029] | 1751 | { |
|---|
| [1235] | 1752 | const Int predListStep = (sizeId == SCALING_LIST_32x32? (SCALING_LIST_NUM/NUMBER_OF_PREDICTION_MODES) : 1); // if 32x32, skip over chroma entries. |
|---|
| [1029] | 1753 | |
|---|
| [1235] | 1754 | for(UInt listId = 0; listId < SCALING_LIST_NUM; listId+=predListStep) |
|---|
| [1029] | 1755 | { |
|---|
| [1235] | 1756 | Bool scalingListPredModeFlag = scalingList.getScalingListPredModeFlag(sizeId, listId); |
|---|
| [1029] | 1757 | WRITE_FLAG( scalingListPredModeFlag, "scaling_list_pred_mode_flag" ); |
|---|
| 1758 | if(!scalingListPredModeFlag)// Copy Mode |
|---|
| 1759 | { |
|---|
| 1760 | if (sizeId == SCALING_LIST_32x32) |
|---|
| 1761 | { |
|---|
| 1762 | // adjust the code, to cope with the missing chroma entries |
|---|
| [1235] | 1763 | WRITE_UVLC( ((Int)listId - (Int)scalingList.getRefMatrixId (sizeId,listId)) / (SCALING_LIST_NUM/NUMBER_OF_PREDICTION_MODES), "scaling_list_pred_matrix_id_delta"); |
|---|
| [1029] | 1764 | } |
|---|
| 1765 | else |
|---|
| 1766 | { |
|---|
| [1235] | 1767 | WRITE_UVLC( (Int)listId - (Int)scalingList.getRefMatrixId (sizeId,listId), "scaling_list_pred_matrix_id_delta"); |
|---|
| [1029] | 1768 | } |
|---|
| 1769 | } |
|---|
| 1770 | else// DPCM Mode |
|---|
| 1771 | { |
|---|
| [1235] | 1772 | xCodeScalingList(&scalingList, sizeId, listId); |
|---|
| [1029] | 1773 | } |
|---|
| 1774 | } |
|---|
| 1775 | } |
|---|
| 1776 | return; |
|---|
| 1777 | } |
|---|
| 1778 | /** code DPCM |
|---|
| 1779 | * \param scalingList quantization matrix information |
|---|
| [1260] | 1780 | * \param sizeId size index |
|---|
| 1781 | * \param listId list index |
|---|
| [1029] | 1782 | */ |
|---|
| [1235] | 1783 | Void TEncCavlc::xCodeScalingList(const TComScalingList* scalingList, UInt sizeId, UInt listId) |
|---|
| [1029] | 1784 | { |
|---|
| 1785 | Int coefNum = min(MAX_MATRIX_COEF_NUM,(Int)g_scalingListSize[sizeId]); |
|---|
| 1786 | UInt* scan = g_scanOrder[SCAN_UNGROUPED][SCAN_DIAG][sizeId==0 ? 2 : 3][sizeId==0 ? 2 : 3]; |
|---|
| 1787 | Int nextCoef = SCALING_LIST_START_VALUE; |
|---|
| 1788 | Int data; |
|---|
| [1235] | 1789 | const Int *src = scalingList->getScalingListAddress(sizeId, listId); |
|---|
| [1417] | 1790 | if( sizeId > SCALING_LIST_8x8 ) |
|---|
| 1791 | { |
|---|
| 1792 | WRITE_SVLC( scalingList->getScalingListDC(sizeId,listId) - 8, "scaling_list_dc_coef_minus8"); |
|---|
| 1793 | nextCoef = scalingList->getScalingListDC(sizeId,listId); |
|---|
| 1794 | } |
|---|
| 1795 | for(Int i=0;i<coefNum;i++) |
|---|
| 1796 | { |
|---|
| 1797 | data = src[scan[i]] - nextCoef; |
|---|
| 1798 | nextCoef = src[scan[i]]; |
|---|
| 1799 | if(data > 127) |
|---|
| [1029] | 1800 | { |
|---|
| [1417] | 1801 | data = data - 256; |
|---|
| [1029] | 1802 | } |
|---|
| [1417] | 1803 | if(data < -128) |
|---|
| [1029] | 1804 | { |
|---|
| [1417] | 1805 | data = data + 256; |
|---|
| 1806 | } |
|---|
| [1029] | 1807 | |
|---|
| [1417] | 1808 | WRITE_SVLC( data, "scaling_list_delta_coef"); |
|---|
| 1809 | } |
|---|
| [1029] | 1810 | } |
|---|
| [1417] | 1811 | |
|---|
| [1029] | 1812 | Bool TEncCavlc::findMatchingLTRP ( TComSlice* pcSlice, UInt *ltrpsIndex, Int ltrpPOC, Bool usedFlag ) |
|---|
| 1813 | { |
|---|
| 1814 | // Bool state = true, state2 = false; |
|---|
| 1815 | Int lsb = ltrpPOC & ((1<<pcSlice->getSPS()->getBitsForPOC())-1); |
|---|
| 1816 | for (Int k = 0; k < pcSlice->getSPS()->getNumLongTermRefPicSPS(); k++) |
|---|
| 1817 | { |
|---|
| 1818 | if ( (lsb == pcSlice->getSPS()->getLtRefPicPocLsbSps(k)) && (usedFlag == pcSlice->getSPS()->getUsedByCurrPicLtSPSFlag(k)) ) |
|---|
| 1819 | { |
|---|
| 1820 | *ltrpsIndex = k; |
|---|
| 1821 | return true; |
|---|
| 1822 | } |
|---|
| 1823 | } |
|---|
| 1824 | return false; |
|---|
| 1825 | } |
|---|
| 1826 | |
|---|
| [1307] | 1827 | Void TEncCavlc::codeExplicitRdpcmMode( TComTU& /*rTu*/, const ComponentID /*compID*/ ) |
|---|
| [1029] | 1828 | { |
|---|
| 1829 | assert(0); |
|---|
| 1830 | } |
|---|
| 1831 | |
|---|
| 1832 | #if SVC_EXTENSION |
|---|
| [1207] | 1833 | Void TEncCavlc::codeSliceHeaderExtn( TComSlice* slice, Int shBitsWrittenTillNow ) |
|---|
| [1029] | 1834 | { |
|---|
| 1835 | Int tmpBitsBeforeWriting = getNumberOfWrittenBits(); |
|---|
| 1836 | Int maxPocLsb = 1 << slice->getSPS()->getBitsForPOC(); |
|---|
| 1837 | if(slice->getPPS()->getSliceHeaderExtensionPresentFlag()) |
|---|
| 1838 | { |
|---|
| 1839 | // Derive the value of PocMsbValRequiredFlag |
|---|
| 1840 | slice->setPocMsbValRequiredFlag( (slice->getCraPicFlag() || slice->getBlaPicFlag()) |
|---|
| 1841 | && (!slice->getVPS()->getVpsPocLsbAlignedFlag() || |
|---|
| 1842 | (slice->getVPS()->getVpsPocLsbAlignedFlag() && slice->getVPS()->getNumDirectRefLayers(slice->getLayerId()) == 0)) |
|---|
| 1843 | ); |
|---|
| 1844 | |
|---|
| 1845 | // Determine value of SH extension length. |
|---|
| 1846 | Int shExtnLengthInBit = 0; |
|---|
| [1207] | 1847 | if( slice->getPPS()->getPocResetInfoPresentFlag() ) |
|---|
| [1029] | 1848 | { |
|---|
| 1849 | shExtnLengthInBit += 2; |
|---|
| 1850 | } |
|---|
| [1207] | 1851 | |
|---|
| 1852 | if( slice->getPocResetIdc() > 0 ) |
|---|
| [1029] | 1853 | { |
|---|
| 1854 | shExtnLengthInBit += 6; |
|---|
| 1855 | } |
|---|
| [1207] | 1856 | |
|---|
| 1857 | if( slice->getPocResetIdc() == 3 ) |
|---|
| [1029] | 1858 | { |
|---|
| 1859 | shExtnLengthInBit += (slice->getSPS()->getBitsForPOC() + 1); |
|---|
| 1860 | } |
|---|
| 1861 | |
|---|
| [1207] | 1862 | if( !slice->getPocMsbValRequiredFlag() && slice->getVPS()->getVpsPocLsbAlignedFlag() ) |
|---|
| [1029] | 1863 | { |
|---|
| 1864 | shExtnLengthInBit++; |
|---|
| 1865 | } |
|---|
| 1866 | else |
|---|
| 1867 | { |
|---|
| 1868 | if( slice->getPocMsbValRequiredFlag() ) |
|---|
| 1869 | { |
|---|
| 1870 | slice->setPocMsbValPresentFlag( true ); |
|---|
| 1871 | } |
|---|
| 1872 | else |
|---|
| 1873 | { |
|---|
| 1874 | slice->setPocMsbValPresentFlag( false ); |
|---|
| 1875 | } |
|---|
| 1876 | } |
|---|
| 1877 | |
|---|
| [1207] | 1878 | if( slice->getPocMsbNeeded() ) |
|---|
| [1029] | 1879 | { |
|---|
| 1880 | slice->setPocMsbValPresentFlag(true); |
|---|
| 1881 | } |
|---|
| 1882 | |
|---|
| [1207] | 1883 | if( slice->getPocMsbValPresentFlag() ) |
|---|
| [1029] | 1884 | { |
|---|
| 1885 | UInt lengthVal = 1; |
|---|
| 1886 | UInt tempVal = (slice->getPocMsbVal() / maxPocLsb) + 1; |
|---|
| 1887 | assert ( tempVal ); |
|---|
| 1888 | while( 1 != tempVal ) |
|---|
| 1889 | { |
|---|
| 1890 | tempVal >>= 1; |
|---|
| 1891 | lengthVal += 2; |
|---|
| 1892 | } |
|---|
| 1893 | shExtnLengthInBit += lengthVal; |
|---|
| 1894 | } |
|---|
| [1207] | 1895 | |
|---|
| [1029] | 1896 | Int shExtnAdditionalBits = 0; |
|---|
| [1207] | 1897 | |
|---|
| 1898 | if( shExtnLengthInBit % 8 != 0 ) |
|---|
| [1029] | 1899 | { |
|---|
| 1900 | shExtnAdditionalBits = 8 - (shExtnLengthInBit % 8); |
|---|
| 1901 | } |
|---|
| [1207] | 1902 | |
|---|
| [1029] | 1903 | Int shExtnLength = (shExtnLengthInBit + shExtnAdditionalBits) / 8; |
|---|
| 1904 | WRITE_UVLC( shExtnLength, "slice_header_extension_length" ); |
|---|
| 1905 | |
|---|
| [1207] | 1906 | if( slice->getPPS()->getPocResetInfoPresentFlag() ) |
|---|
| [1029] | 1907 | { |
|---|
| 1908 | WRITE_CODE( slice->getPocResetIdc(), 2, "poc_reset_idc"); |
|---|
| 1909 | } |
|---|
| [1207] | 1910 | if( slice->getPocResetIdc() > 0 ) |
|---|
| [1029] | 1911 | { |
|---|
| 1912 | WRITE_CODE( slice->getPocResetPeriodId(), 6, "poc_reset_period_id"); |
|---|
| 1913 | } |
|---|
| [1207] | 1914 | if( slice->getPocResetIdc() == 3 ) |
|---|
| [1029] | 1915 | { |
|---|
| 1916 | WRITE_FLAG( slice->getFullPocResetFlag() ? 1 : 0, "full_poc_reset_flag"); |
|---|
| 1917 | WRITE_CODE( slice->getPocLsbVal(), slice->getSPS()->getBitsForPOC(), "poc_lsb_val"); |
|---|
| 1918 | } |
|---|
| 1919 | |
|---|
| [1199] | 1920 | if( !slice->getPocMsbValRequiredFlag() && slice->getVPS()->getVpsPocLsbAlignedFlag() ) |
|---|
| [1029] | 1921 | { |
|---|
| 1922 | WRITE_FLAG( slice->getPocMsbValPresentFlag(), "poc_msb_cycle_val_present_flag" ); |
|---|
| 1923 | } |
|---|
| [1199] | 1924 | |
|---|
| 1925 | if( slice->getPocMsbValPresentFlag() ) |
|---|
| [1029] | 1926 | { |
|---|
| 1927 | assert(slice->getPocMsbVal() % maxPocLsb == 0); |
|---|
| 1928 | WRITE_UVLC(slice->getPocMsbVal() / maxPocLsb, "poc_msb_cycle_val"); |
|---|
| 1929 | } |
|---|
| [1199] | 1930 | |
|---|
| [1207] | 1931 | for(Int i = 0; i < shExtnAdditionalBits; i++) |
|---|
| [1029] | 1932 | { |
|---|
| 1933 | WRITE_FLAG( 1, "slice_segment_header_extension_data_bit"); |
|---|
| 1934 | } |
|---|
| 1935 | } |
|---|
| [1199] | 1936 | |
|---|
| [1029] | 1937 | shBitsWrittenTillNow += ( getNumberOfWrittenBits() - tmpBitsBeforeWriting ); |
|---|
| 1938 | |
|---|
| 1939 | // Slice header byte_alignment() included in xAttachSliceDataToNalUnit |
|---|
| 1940 | } |
|---|
| 1941 | |
|---|
| [1235] | 1942 | Void TEncCavlc::codeVPSExtension( const TComVPS *vps ) |
|---|
| [313] | 1943 | { |
|---|
| [644] | 1944 | Int NumOutputLayersInOutputLayerSet[MAX_VPS_LAYER_SETS_PLUS1]; |
|---|
| 1945 | Int OlsHighestOutputLayerId[MAX_VPS_LAYER_SETS_PLUS1]; |
|---|
| [1169] | 1946 | |
|---|
| [864] | 1947 | if( vps->getMaxLayers() > 1 && vps->getBaseLayerInternalFlag() ) |
|---|
| 1948 | { |
|---|
| [942] | 1949 | codePTL( vps->getPTL(1), false, vps->getMaxTLayers() - 1 ); |
|---|
| [864] | 1950 | } |
|---|
| [1161] | 1951 | |
|---|
| [313] | 1952 | UInt i = 0, j = 0; |
|---|
| [1113] | 1953 | |
|---|
| [313] | 1954 | WRITE_FLAG( vps->getSplittingFlag(), "splitting_flag" ); |
|---|
| 1955 | |
|---|
| 1956 | for(i = 0; i < MAX_VPS_NUM_SCALABILITY_TYPES; i++) |
|---|
| 1957 | { |
|---|
| 1958 | WRITE_FLAG( vps->getScalabilityMask(i), "scalability_mask[i]" ); |
|---|
| 1959 | } |
|---|
| 1960 | |
|---|
| 1961 | for(j = 0; j < vps->getNumScalabilityTypes() - vps->getSplittingFlag(); j++) |
|---|
| 1962 | { |
|---|
| 1963 | WRITE_CODE( vps->getDimensionIdLen(j) - 1, 3, "dimension_id_len_minus1[j]" ); |
|---|
| 1964 | } |
|---|
| 1965 | |
|---|
| [815] | 1966 | // The value of dimBitOffset[ NumScalabilityTypes ] is set equal to 6. |
|---|
| [345] | 1967 | if(vps->getSplittingFlag()) |
|---|
| 1968 | { |
|---|
| 1969 | UInt splDimSum=0; |
|---|
| 1970 | for(j = 0; j < vps->getNumScalabilityTypes(); j++) |
|---|
| 1971 | { |
|---|
| 1972 | splDimSum+=(vps->getDimensionIdLen(j)); |
|---|
| 1973 | } |
|---|
| 1974 | assert(splDimSum<=6); |
|---|
| 1975 | } |
|---|
| 1976 | |
|---|
| [313] | 1977 | WRITE_FLAG( vps->getNuhLayerIdPresentFlag(), "vps_nuh_layer_id_present_flag" ); |
|---|
| 1978 | for(i = 1; i < vps->getMaxLayers(); i++) |
|---|
| 1979 | { |
|---|
| 1980 | if( vps->getNuhLayerIdPresentFlag() ) |
|---|
| 1981 | { |
|---|
| 1982 | WRITE_CODE( vps->getLayerIdInNuh(i), 6, "layer_id_in_nuh[i]" ); |
|---|
| 1983 | } |
|---|
| [494] | 1984 | |
|---|
| 1985 | if( !vps->getSplittingFlag() ) |
|---|
| 1986 | { |
|---|
| [1057] | 1987 | for(j = 0; j < vps->getNumScalabilityTypes(); j++) |
|---|
| 1988 | { |
|---|
| 1989 | UInt bits = vps->getDimensionIdLen(j); |
|---|
| 1990 | WRITE_CODE( vps->getDimensionId(i, j), bits, "dimension_id[i][j]" ); |
|---|
| 1991 | } |
|---|
| [313] | 1992 | } |
|---|
| 1993 | } |
|---|
| [1161] | 1994 | |
|---|
| [1190] | 1995 | WRITE_CODE( vps->getViewIdLen( ), 4, "view_id_len" ); |
|---|
| 1996 | assert ( vps->getNumViews() >= (1<<vps->getViewIdLen()) ); |
|---|
| [442] | 1997 | |
|---|
| [547] | 1998 | if ( vps->getViewIdLen() > 0 ) |
|---|
| 1999 | { |
|---|
| [1190] | 2000 | for( i = 0; i < vps->getNumViews(); i++ ) |
|---|
| 2001 | { |
|---|
| 2002 | WRITE_CODE( vps->getViewIdVal( i ), vps->getViewIdLen( ), "view_id_val[i]" ); |
|---|
| 2003 | } |
|---|
| [1029] | 2004 | } |
|---|
| [547] | 2005 | |
|---|
| [1057] | 2006 | for( Int layerCtr = 1; layerCtr < vps->getMaxLayers(); layerCtr++) |
|---|
| [313] | 2007 | { |
|---|
| 2008 | for( Int refLayerCtr = 0; refLayerCtr < layerCtr; refLayerCtr++) |
|---|
| 2009 | { |
|---|
| 2010 | WRITE_FLAG(vps->getDirectDependencyFlag(layerCtr, refLayerCtr), "direct_dependency_flag[i][j]" ); |
|---|
| 2011 | } |
|---|
| 2012 | } |
|---|
| [1148] | 2013 | |
|---|
| [1172] | 2014 | if( vps->getNumIndependentLayers() > 1 ) |
|---|
| [862] | 2015 | { |
|---|
| 2016 | WRITE_UVLC( vps->getNumAddLayerSets(), "num_add_layer_sets" ); |
|---|
| [1172] | 2017 | |
|---|
| 2018 | for( i = 0; i < vps->getNumAddLayerSets(); i++ ) |
|---|
| [862] | 2019 | { |
|---|
| [1172] | 2020 | for( j = 1; j < vps->getNumIndependentLayers(); j++ ) |
|---|
| [862] | 2021 | { |
|---|
| [1172] | 2022 | Int len = 1; |
|---|
| 2023 | while( (1 << len) < (vps->getNumLayersInTreePartition(j) + 1) ) |
|---|
| [862] | 2024 | { |
|---|
| 2025 | len++; |
|---|
| 2026 | } |
|---|
| 2027 | WRITE_CODE(vps->getHighestLayerIdxPlus1(i, j), len, "highest_layer_idx_plus1[i][j]"); |
|---|
| 2028 | } |
|---|
| 2029 | } |
|---|
| 2030 | } |
|---|
| [1152] | 2031 | |
|---|
| 2032 | WRITE_FLAG( vps->getMaxTSLayersPresentFlag(), "vps_sub_layers_max_minus1_present_flag"); |
|---|
| 2033 | if( vps->getMaxTSLayersPresentFlag() ) |
|---|
| 2034 | { |
|---|
| 2035 | for( i = 0; i < vps->getMaxLayers(); i++ ) |
|---|
| [540] | 2036 | { |
|---|
| [1152] | 2037 | WRITE_CODE(vps->getMaxTSLayersMinus1(i), 3, "sub_layers_vps_max_minus1[i]" ); |
|---|
| [540] | 2038 | } |
|---|
| [1152] | 2039 | } |
|---|
| 2040 | |
|---|
| [442] | 2041 | WRITE_FLAG( vps->getMaxTidRefPresentFlag(), "max_tid_ref_present_flag"); |
|---|
| 2042 | if (vps->getMaxTidRefPresentFlag()) |
|---|
| [345] | 2043 | { |
|---|
| 2044 | for( i = 0; i < vps->getMaxLayers() - 1; i++) |
|---|
| 2045 | { |
|---|
| [494] | 2046 | for( j = i+1; j <= vps->getMaxLayers() - 1; j++) |
|---|
| 2047 | { |
|---|
| 2048 | if(vps->getDirectDependencyFlag(j, i)) |
|---|
| 2049 | { |
|---|
| 2050 | WRITE_CODE(vps->getMaxTidIlRefPicsPlus1(i,j), 3, "max_tid_il_ref_pics_plus1[i][j]" ); |
|---|
| 2051 | } |
|---|
| 2052 | } |
|---|
| [345] | 2053 | } |
|---|
| 2054 | } |
|---|
| [815] | 2055 | WRITE_FLAG( vps->getIlpSshSignalingEnabledFlag(), "all_ref_layers_active_flag" ); |
|---|
| [1170] | 2056 | |
|---|
| [313] | 2057 | // Profile-tier-level signalling |
|---|
| [588] | 2058 | WRITE_UVLC( vps->getNumProfileTierLevel() - 1, "vps_num_profile_tier_level_minus1"); |
|---|
| [1154] | 2059 | |
|---|
| [866] | 2060 | Int const numBitsForPtlIdx = vps->calculateLenOfSyntaxElement( vps->getNumProfileTierLevel() ); |
|---|
| [1154] | 2061 | |
|---|
| [942] | 2062 | //Do something here to make sure the loop is correct to consider base layer internal stuff |
|---|
| [1182] | 2063 | |
|---|
| 2064 | for( Int idx = vps->getBaseLayerInternalFlag() ? 2 : 1; idx < vps->getNumProfileTierLevel(); idx++ ) |
|---|
| [313] | 2065 | { |
|---|
| 2066 | WRITE_FLAG( vps->getProfilePresentFlag(idx), "vps_profile_present_flag[i]" ); |
|---|
| [1182] | 2067 | |
|---|
| [942] | 2068 | codePTL( vps->getPTL(idx), vps->getProfilePresentFlag(idx), vps->getMaxTLayers() - 1 ); |
|---|
| [313] | 2069 | } |
|---|
| 2070 | |
|---|
| [713] | 2071 | Int numOutputLayerSets = vps->getNumOutputLayerSets(); |
|---|
| 2072 | Int numAddOutputLayerSets = numOutputLayerSets - (Int)vps->getNumLayerSets(); |
|---|
| 2073 | |
|---|
| [815] | 2074 | // The value of num_add_olss shall be in the range of 0 to 1023, inclusive. |
|---|
| [713] | 2075 | assert( numAddOutputLayerSets >= 0 && numAddOutputLayerSets < 1024 ); |
|---|
| 2076 | |
|---|
| 2077 | if( vps->getNumLayerSets() > 1 ) |
|---|
| 2078 | { |
|---|
| [815] | 2079 | WRITE_UVLC( numAddOutputLayerSets, "num_add_olss" ); |
|---|
| 2080 | WRITE_CODE( vps->getDefaultTargetOutputLayerIdc(), 2, "default_output_layer_idc" ); |
|---|
| [713] | 2081 | } |
|---|
| 2082 | |
|---|
| [313] | 2083 | for(i = 1; i < numOutputLayerSets; i++) |
|---|
| 2084 | { |
|---|
| [866] | 2085 | Int layerSetIdxForOutputLayerSet = vps->getOutputLayerSetIdx(i); |
|---|
| [1029] | 2086 | if( vps->getNumLayerSets() > 2 && i >= vps->getNumLayerSets() ) |
|---|
| [313] | 2087 | { |
|---|
| 2088 | Int numBits = 1; |
|---|
| 2089 | while ((1 << numBits) < (vps->getNumLayerSets() - 1)) |
|---|
| 2090 | { |
|---|
| 2091 | numBits++; |
|---|
| 2092 | } |
|---|
| [815] | 2093 | WRITE_CODE( vps->getOutputLayerSetIdx(i) - 1, numBits, "layer_set_idx_for_ols_minus1"); |
|---|
| [588] | 2094 | } |
|---|
| [1172] | 2095 | |
|---|
| 2096 | if( i > vps->getVpsNumLayerSetsMinus1() || vps->getDefaultTargetOutputLayerIdc() >= 2 ) //Instead of == 2, >= 2 is used to follow the agreement that value 3 should be interpreted as 2 |
|---|
| [588] | 2097 | { |
|---|
| [1172] | 2098 | for( j = 0; j < vps->getNumLayersInIdList(layerSetIdxForOutputLayerSet); j++ ) |
|---|
| [313] | 2099 | { |
|---|
| 2100 | WRITE_FLAG( vps->getOutputLayerFlag(i,j), "output_layer_flag[i][j]"); |
|---|
| 2101 | } |
|---|
| 2102 | } |
|---|
| [1153] | 2103 | |
|---|
| 2104 | for( j = 0; j < vps->getNumLayersInIdList(layerSetIdxForOutputLayerSet); j++ ) |
|---|
| [866] | 2105 | { |
|---|
| [1029] | 2106 | if( vps->getNecessaryLayerFlag(i, j) && (vps->getNumProfileTierLevel() - 1) > 0 ) |
|---|
| [866] | 2107 | { |
|---|
| [1275] | 2108 | WRITE_CODE( vps->getProfileLevelTierIdx(i, j), numBitsForPtlIdx, "profile_tier_level_idx[i]" ); |
|---|
| [866] | 2109 | } |
|---|
| 2110 | } |
|---|
| [1124] | 2111 | |
|---|
| [644] | 2112 | NumOutputLayersInOutputLayerSet[i] = 0; |
|---|
| [1156] | 2113 | |
|---|
| 2114 | for( j = 0; j < vps->getNumLayersInIdList(layerSetIdxForOutputLayerSet); j++ ) |
|---|
| [644] | 2115 | { |
|---|
| 2116 | NumOutputLayersInOutputLayerSet[i] += vps->getOutputLayerFlag(i, j); |
|---|
| [1156] | 2117 | if( vps->getOutputLayerFlag(i, j) ) |
|---|
| [644] | 2118 | { |
|---|
| 2119 | OlsHighestOutputLayerId[i] = vps->getLayerSetLayerIdList(layerSetIdxForOutputLayerSet, j); |
|---|
| 2120 | } |
|---|
| 2121 | } |
|---|
| [1156] | 2122 | if( NumOutputLayersInOutputLayerSet[i] == 1 && vps->getNumDirectRefLayers(OlsHighestOutputLayerId[i]) > 0 ) |
|---|
| [644] | 2123 | { |
|---|
| 2124 | WRITE_FLAG(vps->getAltOuputLayerFlag(i), "alt_output_layer_flag[i]"); |
|---|
| 2125 | } |
|---|
| [713] | 2126 | |
|---|
| [1156] | 2127 | assert( NumOutputLayersInOutputLayerSet[i] > 0 ); |
|---|
| [313] | 2128 | } |
|---|
| [442] | 2129 | |
|---|
| [713] | 2130 | // The value of vps_num_rep_formats_minus1 shall be in the range of 0 to 255, inclusive. |
|---|
| 2131 | assert( vps->getVpsNumRepFormats() > 0 && vps->getVpsNumRepFormats() <= 256 ); |
|---|
| 2132 | |
|---|
| 2133 | WRITE_UVLC( vps->getVpsNumRepFormats() - 1, "vps_num_rep_formats_minus1" ); |
|---|
| 2134 | |
|---|
| 2135 | for(i = 0; i < vps->getVpsNumRepFormats(); i++) |
|---|
| 2136 | { |
|---|
| 2137 | // Write rep_format_structures |
|---|
| 2138 | codeRepFormat( vps->getVpsRepFormat(i) ); |
|---|
| 2139 | } |
|---|
| 2140 | |
|---|
| 2141 | if( vps->getVpsNumRepFormats() > 1 ) |
|---|
| 2142 | { |
|---|
| 2143 | WRITE_FLAG( vps->getRepFormatIdxPresentFlag(), "rep_format_idx_present_flag"); |
|---|
| 2144 | } |
|---|
| 2145 | else |
|---|
| 2146 | { |
|---|
| 2147 | // When not present, the value of rep_format_idx_present_flag is inferred to be equal to 0 |
|---|
| 2148 | assert( !vps->getRepFormatIdxPresentFlag() ); |
|---|
| 2149 | } |
|---|
| 2150 | |
|---|
| 2151 | if( vps->getRepFormatIdxPresentFlag() ) |
|---|
| 2152 | { |
|---|
| [1029] | 2153 | for( i = vps->getBaseLayerInternalFlag() ? 1 : 0; i < vps->getMaxLayers(); i++ ) |
|---|
| [713] | 2154 | { |
|---|
| 2155 | Int numBits = 1; |
|---|
| 2156 | while ((1 << numBits) < (vps->getVpsNumRepFormats())) |
|---|
| 2157 | { |
|---|
| 2158 | numBits++; |
|---|
| 2159 | } |
|---|
| 2160 | WRITE_CODE( vps->getVpsRepFormatIdx(i), numBits, "vps_rep_format_idx[i]" ); |
|---|
| 2161 | } |
|---|
| 2162 | } |
|---|
| [1119] | 2163 | |
|---|
| [588] | 2164 | WRITE_FLAG(vps->getMaxOneActiveRefLayerFlag(), "max_one_active_ref_layer_flag"); |
|---|
| [1199] | 2165 | |
|---|
| [903] | 2166 | WRITE_FLAG(vps->getVpsPocLsbAlignedFlag(), "vps_poc_lsb_aligned_flag"); |
|---|
| [1198] | 2167 | |
|---|
| 2168 | for( i = 1; i< vps->getMaxLayers(); i++ ) |
|---|
| [313] | 2169 | { |
|---|
| [494] | 2170 | if( vps->getNumDirectRefLayers( vps->getLayerIdInNuh(i) ) == 0 ) |
|---|
| [313] | 2171 | { |
|---|
| [494] | 2172 | WRITE_FLAG(vps->getPocLsbNotPresentFlag(i), "poc_lsb_not_present_flag[i]"); |
|---|
| [313] | 2173 | } |
|---|
| 2174 | } |
|---|
| [1125] | 2175 | |
|---|
| [588] | 2176 | codeVpsDpbSizeTable(vps); |
|---|
| [1148] | 2177 | |
|---|
| [313] | 2178 | WRITE_UVLC( vps->getDirectDepTypeLen()-2, "direct_dep_type_len_minus2"); |
|---|
| [1146] | 2179 | |
|---|
| [1275] | 2180 | WRITE_FLAG(vps->getDefaultDirectDependencyTypeFlag(), "direct_dependency_all_layers_flag"); |
|---|
| [1146] | 2181 | |
|---|
| 2182 | if( vps->getDefaultDirectDependencyTypeFlag() ) |
|---|
| [313] | 2183 | { |
|---|
| [1275] | 2184 | WRITE_CODE( vps->getDefaultDirectDependencyType(), vps->getDirectDepTypeLen(), "direct_dependency_all_layers_type" ); |
|---|
| [540] | 2185 | } |
|---|
| 2186 | else |
|---|
| 2187 | { |
|---|
| [1029] | 2188 | for( i = vps->getBaseLayerInternalFlag() ? 1 : 2; i < vps->getMaxLayers(); i++ ) |
|---|
| [313] | 2189 | { |
|---|
| [1029] | 2190 | for( j = vps->getBaseLayerInternalFlag() ? 0 : 1; j < i; j++ ) |
|---|
| [313] | 2191 | { |
|---|
| [540] | 2192 | if (vps->getDirectDependencyFlag(i, j)) |
|---|
| 2193 | { |
|---|
| 2194 | WRITE_CODE( vps->getDirectDependencyType(i, j), vps->getDirectDepTypeLen(), "direct_dependency_type[i][j]" ); |
|---|
| 2195 | } |
|---|
| [313] | 2196 | } |
|---|
| 2197 | } |
|---|
| 2198 | } |
|---|
| [547] | 2199 | |
|---|
| [713] | 2200 | // The value of vps_non_vui_extension_length shall be in the range of 0 to 4096, inclusive. |
|---|
| 2201 | assert( vps->getVpsNonVuiExtLength() >= 0 && vps->getVpsNonVuiExtLength() <= 4096 ); |
|---|
| 2202 | |
|---|
| [588] | 2203 | WRITE_UVLC( vps->getVpsNonVuiExtLength(), "vps_non_vui_extension_length" ); |
|---|
| [1165] | 2204 | |
|---|
| 2205 | for( i = 1; i <= vps->getVpsNonVuiExtLength(); i++ ) |
|---|
| [644] | 2206 | { |
|---|
| 2207 | WRITE_CODE(1, 8, "vps_non_vui_extension_data_byte"); |
|---|
| 2208 | } |
|---|
| [1235] | 2209 | |
|---|
| [713] | 2210 | WRITE_FLAG( vps->getVpsVuiPresentFlag() ? 1 : 0, "vps_vui_present_flag" ); |
|---|
| [1113] | 2211 | |
|---|
| [547] | 2212 | if(vps->getVpsVuiPresentFlag()) // Should be conditioned on the value of vps_vui_present_flag |
|---|
| 2213 | { |
|---|
| 2214 | while ( m_pcBitIf->getNumberOfWrittenBits() % 8 != 0 ) |
|---|
| 2215 | { |
|---|
| 2216 | WRITE_FLAG(1, "vps_vui_alignment_bit_equal_to_one"); |
|---|
| 2217 | } |
|---|
| [1113] | 2218 | |
|---|
| [547] | 2219 | codeVPSVUI(vps); |
|---|
| 2220 | } |
|---|
| [313] | 2221 | } |
|---|
| [815] | 2222 | |
|---|
| [1235] | 2223 | Void TEncCavlc::codeRepFormat( const RepFormat *repFormat ) |
|---|
| [442] | 2224 | { |
|---|
| [713] | 2225 | WRITE_CODE( repFormat->getPicWidthVpsInLumaSamples (), 16, "pic_width_vps_in_luma_samples" ); |
|---|
| 2226 | WRITE_CODE( repFormat->getPicHeightVpsInLumaSamples(), 16, "pic_height_vps_in_luma_samples" ); |
|---|
| 2227 | WRITE_FLAG( repFormat->getChromaAndBitDepthVpsPresentFlag(), "chroma_and_bit_depth_vps_present_flag" ); |
|---|
| [540] | 2228 | |
|---|
| [713] | 2229 | if( repFormat->getChromaAndBitDepthVpsPresentFlag() ) |
|---|
| 2230 | { |
|---|
| 2231 | WRITE_CODE( repFormat->getChromaFormatVpsIdc(), 2, "chroma_format_vps_idc" ); |
|---|
| [540] | 2232 | |
|---|
| [713] | 2233 | if( repFormat->getChromaFormatVpsIdc() == 3 ) |
|---|
| 2234 | { |
|---|
| 2235 | WRITE_FLAG( repFormat->getSeparateColourPlaneVpsFlag(), "separate_colour_plane_vps_flag" ); |
|---|
| 2236 | } |
|---|
| [540] | 2237 | |
|---|
| [713] | 2238 | assert( repFormat->getBitDepthVpsLuma() >= 8 ); |
|---|
| 2239 | assert( repFormat->getBitDepthVpsChroma() >= 8 ); |
|---|
| 2240 | WRITE_CODE( repFormat->getBitDepthVpsLuma() - 8, 4, "bit_depth_vps_luma_minus8" ); |
|---|
| 2241 | WRITE_CODE( repFormat->getBitDepthVpsChroma() - 8, 4, "bit_depth_vps_chroma_minus8" ); |
|---|
| 2242 | } |
|---|
| [313] | 2243 | |
|---|
| [869] | 2244 | Window conf = repFormat->getConformanceWindowVps(); |
|---|
| 2245 | |
|---|
| 2246 | WRITE_FLAG( conf.getWindowEnabledFlag(), "conformance_window_vps_flag" ); |
|---|
| 2247 | if (conf.getWindowEnabledFlag()) |
|---|
| 2248 | { |
|---|
| 2249 | WRITE_UVLC( conf.getWindowLeftOffset(), "conf_win_vps_left_offset" ); |
|---|
| 2250 | WRITE_UVLC( conf.getWindowRightOffset(), "conf_win_vps_right_offset" ); |
|---|
| 2251 | WRITE_UVLC( conf.getWindowTopOffset(), "conf_win_vps_top_offset" ); |
|---|
| 2252 | WRITE_UVLC( conf.getWindowBottomOffset(), "conf_win_vps_bottom_offset" ); |
|---|
| 2253 | } |
|---|
| [442] | 2254 | } |
|---|
| [1203] | 2255 | |
|---|
| [1235] | 2256 | Void TEncCavlc::codeVpsDpbSizeTable( const TComVPS *vps ) |
|---|
| [588] | 2257 | { |
|---|
| [1189] | 2258 | for( Int i = 1; i < vps->getNumOutputLayerSets(); i++ ) |
|---|
| [588] | 2259 | { |
|---|
| 2260 | Int layerSetIdxForOutputLayerSet = vps->getOutputLayerSetIdx( i ); |
|---|
| [1135] | 2261 | |
|---|
| [644] | 2262 | WRITE_FLAG( vps->getSubLayerFlagInfoPresentFlag( i ), "sub_layer_flag_info_present_flag[i]"); |
|---|
| [1136] | 2263 | |
|---|
| [872] | 2264 | for(Int j = 0; j <= vps->getMaxSLayersInLayerSetMinus1( layerSetIdxForOutputLayerSet ); j++) |
|---|
| [588] | 2265 | { |
|---|
| 2266 | if( j > 0 && vps->getSubLayerFlagInfoPresentFlag(i) ) |
|---|
| 2267 | { |
|---|
| 2268 | WRITE_FLAG( vps->getSubLayerDpbInfoPresentFlag( i, j), "sub_layer_dpb_info_present_flag[i]"); |
|---|
| 2269 | } |
|---|
| [1189] | 2270 | |
|---|
| [588] | 2271 | if( vps->getSubLayerDpbInfoPresentFlag(i, j) ) |
|---|
| 2272 | { |
|---|
| [815] | 2273 | for(Int k = 0; k < vps->getNumLayersInIdList( layerSetIdxForOutputLayerSet ); k++) |
|---|
| [588] | 2274 | { |
|---|
| [1189] | 2275 | if( vps->getNecessaryLayerFlag(i, k) && (vps->getBaseLayerInternalFlag() || (vps->getLayerSetLayerIdList(layerSetIdxForOutputLayerSet, k) != 0)) ) |
|---|
| 2276 | { |
|---|
| 2277 | WRITE_UVLC( vps->getMaxVpsDecPicBufferingMinus1( i, k, j ), "max_vps_dec_pic_buffering_minus1[i][k][j]" ); |
|---|
| 2278 | } |
|---|
| [588] | 2279 | } |
|---|
| [1189] | 2280 | |
|---|
| [1029] | 2281 | WRITE_UVLC( vps->getMaxVpsNumReorderPics( i, j), "max_vps_num_reorder_pics[i][j]" ); |
|---|
| [1100] | 2282 | |
|---|
| [588] | 2283 | WRITE_UVLC( vps->getMaxVpsLatencyIncreasePlus1( i, j), "max_vps_latency_increase_plus1[i][j]" ); |
|---|
| 2284 | } |
|---|
| 2285 | } |
|---|
| 2286 | } |
|---|
| 2287 | } |
|---|
| [815] | 2288 | |
|---|
| [1235] | 2289 | Void TEncCavlc::codeVPSVUI( const TComVPS *vps ) |
|---|
| [442] | 2290 | { |
|---|
| 2291 | Int i,j; |
|---|
| [540] | 2292 | WRITE_FLAG(vps->getCrossLayerPictureTypeAlignFlag(), "cross_layer_pic_type_aligned_flag"); |
|---|
| [1235] | 2293 | |
|---|
| 2294 | if( !vps->getCrossLayerPictureTypeAlignFlag() ) |
|---|
| [540] | 2295 | { |
|---|
| 2296 | WRITE_FLAG(vps->getCrossLayerIrapAlignFlag(), "cross_layer_irap_aligned_flag"); |
|---|
| 2297 | } |
|---|
| [1011] | 2298 | else |
|---|
| 2299 | { |
|---|
| [1128] | 2300 | // When not present, the value of cross_layer_irap_aligned_flag is inferred to be equal to vps_vui_present_flag, |
|---|
| [1235] | 2301 | assert( vps->getCrossLayerIrapAlignFlag() == true ); |
|---|
| [1011] | 2302 | } |
|---|
| [1126] | 2303 | |
|---|
| [1128] | 2304 | if( vps->getCrossLayerIrapAlignFlag() ) |
|---|
| [1011] | 2305 | { |
|---|
| 2306 | WRITE_FLAG(vps->getCrossLayerAlignedIdrOnlyFlag(), "all_layers_idr_aligned_flag"); |
|---|
| 2307 | } |
|---|
| 2308 | |
|---|
| [442] | 2309 | WRITE_FLAG( vps->getBitRatePresentVpsFlag(), "bit_rate_present_vps_flag" ); |
|---|
| 2310 | WRITE_FLAG( vps->getPicRatePresentVpsFlag(), "pic_rate_present_vps_flag" ); |
|---|
| 2311 | |
|---|
| 2312 | if( vps->getBitRatePresentVpsFlag() || vps->getPicRatePresentVpsFlag() ) |
|---|
| 2313 | { |
|---|
| [889] | 2314 | for( i = vps->getBaseLayerInternalFlag() ? 0 : 1; i < vps->getNumLayerSets(); i++ ) |
|---|
| [442] | 2315 | { |
|---|
| [815] | 2316 | for( j = 0; j <= vps->getMaxSLayersInLayerSetMinus1(i); j++ ) |
|---|
| [442] | 2317 | { |
|---|
| 2318 | if( vps->getBitRatePresentVpsFlag() ) |
|---|
| 2319 | { |
|---|
| [713] | 2320 | WRITE_FLAG( vps->getBitRatePresentFlag( i, j), "bit_rate_present_flag[i][j]" ); |
|---|
| [442] | 2321 | } |
|---|
| [1172] | 2322 | |
|---|
| [442] | 2323 | if( vps->getPicRatePresentVpsFlag() ) |
|---|
| 2324 | { |
|---|
| [713] | 2325 | WRITE_FLAG( vps->getPicRatePresentFlag( i, j), "pic_rate_present_flag[i][j]" ); |
|---|
| [442] | 2326 | } |
|---|
| [1172] | 2327 | |
|---|
| [442] | 2328 | if( vps->getBitRatePresentFlag(i, j) ) |
|---|
| 2329 | { |
|---|
| 2330 | WRITE_CODE( vps->getAvgBitRate( i, j ), 16, "avg_bit_rate[i][j]" ); |
|---|
| 2331 | WRITE_CODE( vps->getAvgBitRate( i, j ), 16, "max_bit_rate[i][j]" ); |
|---|
| 2332 | } |
|---|
| [1172] | 2333 | |
|---|
| [442] | 2334 | if( vps->getPicRatePresentFlag(i, j) ) |
|---|
| 2335 | { |
|---|
| 2336 | WRITE_CODE( vps->getConstPicRateIdc( i, j), 2 , "constant_pic_rate_idc[i][j]" ); |
|---|
| 2337 | WRITE_CODE( vps->getConstPicRateIdc( i, j), 16, "avg_pic_rate[i][j]" ); |
|---|
| 2338 | } |
|---|
| 2339 | } |
|---|
| 2340 | } |
|---|
| 2341 | } |
|---|
| [1167] | 2342 | |
|---|
| [588] | 2343 | WRITE_FLAG( vps->getVideoSigPresentVpsFlag(), "video_signal_info_idx_present_flag" ); |
|---|
| 2344 | if (vps->getVideoSigPresentVpsFlag()) |
|---|
| 2345 | { |
|---|
| 2346 | WRITE_CODE(vps->getNumVideoSignalInfo()-1, 4, "vps_num_video_signal_info_minus1" ); |
|---|
| 2347 | } |
|---|
| 2348 | |
|---|
| 2349 | for(i = 0; i < vps->getNumVideoSignalInfo(); i++) |
|---|
| 2350 | { |
|---|
| 2351 | WRITE_CODE(vps->getVideoVPSFormat(i), 3, "video_vps_format" ); |
|---|
| 2352 | WRITE_FLAG(vps->getVideoFullRangeVpsFlag(i), "video_full_range_vps_flag" ); |
|---|
| [1497] | 2353 | WRITE_CODE(vps->getColorPrimaries(i), 8, "colour_primaries_vps" ); |
|---|
| [588] | 2354 | WRITE_CODE(vps->getTransCharacter(i), 8, "transfer_characteristics_vps" ); |
|---|
| 2355 | WRITE_CODE(vps->getMaxtrixCoeff(i), 8, "matrix_coeffs_vps" ); |
|---|
| 2356 | } |
|---|
| 2357 | |
|---|
| [1166] | 2358 | if( vps->getVideoSigPresentVpsFlag() && vps->getNumVideoSignalInfo() > 1 ) |
|---|
| [588] | 2359 | { |
|---|
| [1166] | 2360 | for( i = vps->getBaseLayerInternalFlag() ? 0 : 1; i < vps->getMaxLayers(); i++ ) |
|---|
| [839] | 2361 | { |
|---|
| 2362 | WRITE_CODE( vps->getVideoSignalInfoIdx(i), 4, "vps_video_signal_info_idx" ); |
|---|
| 2363 | } |
|---|
| [588] | 2364 | } |
|---|
| [1167] | 2365 | |
|---|
| [540] | 2366 | WRITE_FLAG( vps->getTilesNotInUseFlag() ? 1 : 0 , "tiles_not_in_use_flag" ); |
|---|
| [1176] | 2367 | |
|---|
| 2368 | if( !vps->getTilesNotInUseFlag() ) |
|---|
| [540] | 2369 | { |
|---|
| [1029] | 2370 | for( i = vps->getBaseLayerInternalFlag() ? 0 : 1; i < vps->getMaxLayers(); i++ ) |
|---|
| [540] | 2371 | { |
|---|
| 2372 | WRITE_FLAG( vps->getTilesInUseFlag(i) ? 1 : 0 , "tiles_in_use_flag[ i ]" ); |
|---|
| [1176] | 2373 | |
|---|
| 2374 | if( vps->getTilesInUseFlag(i) ) |
|---|
| [540] | 2375 | { |
|---|
| 2376 | WRITE_FLAG( vps->getLoopFilterNotAcrossTilesFlag(i) ? 1 : 0 , "loop_filter_not_across_tiles_flag[ i ]" ); |
|---|
| 2377 | } |
|---|
| 2378 | } |
|---|
| [815] | 2379 | |
|---|
| [1029] | 2380 | for( i = vps->getBaseLayerInternalFlag() ? 1 : 2; i < vps->getMaxLayers(); i++ ) |
|---|
| [540] | 2381 | { |
|---|
| 2382 | for(j = 0; j < vps->getNumDirectRefLayers(vps->getLayerIdInNuh(i)); j++) |
|---|
| 2383 | { |
|---|
| [1176] | 2384 | UInt layerIdx = vps->getLayerIdxInVps(vps->getRefLayerId(vps->getLayerIdInNuh(i), j)); |
|---|
| 2385 | |
|---|
| 2386 | if( vps->getTilesInUseFlag(i) && vps->getTilesInUseFlag(layerIdx) ) |
|---|
| 2387 | { |
|---|
| [540] | 2388 | WRITE_FLAG( vps->getTileBoundariesAlignedFlag(i,j) ? 1 : 0 , "tile_boundaries_aligned_flag[i][j]" ); |
|---|
| 2389 | } |
|---|
| 2390 | } |
|---|
| 2391 | } |
|---|
| 2392 | } |
|---|
| [1176] | 2393 | |
|---|
| [540] | 2394 | WRITE_FLAG( vps->getWppNotInUseFlag() ? 1 : 0 , "wpp_not_in_use_flag" ); |
|---|
| [1176] | 2395 | |
|---|
| 2396 | if( !vps->getWppNotInUseFlag() ) |
|---|
| [442] | 2397 | { |
|---|
| [1029] | 2398 | for( i = vps->getBaseLayerInternalFlag() ? 0 : 1; i < vps->getMaxLayers(); i++ ) |
|---|
| [442] | 2399 | { |
|---|
| [540] | 2400 | WRITE_FLAG( vps->getWppInUseFlag(i) ? 1 : 0 , "wpp_in_use_flag[ i ]" ); |
|---|
| [442] | 2401 | } |
|---|
| [540] | 2402 | } |
|---|
| [547] | 2403 | |
|---|
| 2404 | WRITE_FLAG(vps->getSingleLayerForNonIrapFlag(), "single_layer_for_non_irap_flag" ); |
|---|
| [1128] | 2405 | |
|---|
| [713] | 2406 | // When single_layer_for_non_irap_flag is equal to 0, higher_layer_irap_skip_flag shall be equal to 0 |
|---|
| 2407 | if( !vps->getSingleLayerForNonIrapFlag() ) |
|---|
| 2408 | { |
|---|
| 2409 | assert( !vps->getHigherLayerIrapSkipFlag() ); |
|---|
| 2410 | } |
|---|
| 2411 | |
|---|
| [547] | 2412 | WRITE_FLAG(vps->getHigherLayerIrapSkipFlag(), "higher_layer_irap_skip_flag" ); |
|---|
| [1128] | 2413 | |
|---|
| [588] | 2414 | WRITE_FLAG( vps->getIlpRestrictedRefLayersFlag() ? 1 : 0 , "ilp_restricted_ref_layers_flag" ); |
|---|
| 2415 | if( vps->getIlpRestrictedRefLayersFlag()) |
|---|
| [442] | 2416 | { |
|---|
| 2417 | for(i = 1; i < vps->getMaxLayers(); i++) |
|---|
| 2418 | { |
|---|
| 2419 | for(j = 0; j < vps->getNumDirectRefLayers(vps->getLayerIdInNuh(i)); j++) |
|---|
| [980] | 2420 | { |
|---|
| 2421 | if (vps->getBaseLayerInternalFlag() || vps->getRefLayerId(vps->getLayerIdInNuh(i), j)) |
|---|
| 2422 | { |
|---|
| 2423 | WRITE_UVLC(vps->getMinSpatialSegmentOffsetPlus1( i, j), "min_spatial_segment_offset_plus1[i][j]"); |
|---|
| 2424 | |
|---|
| 2425 | if( vps->getMinSpatialSegmentOffsetPlus1(i,j ) > 0 ) |
|---|
| [1029] | 2426 | { |
|---|
| 2427 | WRITE_FLAG( vps->getCtuBasedOffsetEnabledFlag( i, j) ? 1 : 0 , "ctu_based_offset_enabled_flag[i][j]" ); |
|---|
| 2428 | |
|---|
| 2429 | if(vps->getCtuBasedOffsetEnabledFlag(i,j)) |
|---|
| [980] | 2430 | { |
|---|
| [1029] | 2431 | WRITE_UVLC(vps->getMinHorizontalCtuOffsetPlus1( i, j), "min_horizontal_ctu_offset_plus1[i][j]"); |
|---|
| [980] | 2432 | } |
|---|
| [442] | 2433 | } |
|---|
| [980] | 2434 | } |
|---|
| [1029] | 2435 | } |
|---|
| [442] | 2436 | } |
|---|
| 2437 | } |
|---|
| [1167] | 2438 | |
|---|
| [644] | 2439 | #if O0164_MULTI_LAYER_HRD |
|---|
| [1185] | 2440 | WRITE_FLAG(vps->getVpsVuiBspHrdPresentFlag(), "vps_vui_bsp_hrd_present_flag" ); |
|---|
| 2441 | |
|---|
| 2442 | if( vps->getVpsVuiBspHrdPresentFlag() ) |
|---|
| 2443 | { |
|---|
| 2444 | codeVpsVuiBspHrdParams(vps); |
|---|
| 2445 | } |
|---|
| [815] | 2446 | #endif |
|---|
| [1163] | 2447 | |
|---|
| [1185] | 2448 | for( i = 1; i < vps->getMaxLayers(); i++ ) |
|---|
| 2449 | { |
|---|
| 2450 | if( vps->getNumRefLayers(vps->getLayerIdInNuh(i)) == 0 ) |
|---|
| [644] | 2451 | { |
|---|
| [1185] | 2452 | WRITE_FLAG(vps->getBaseLayerPSCompatibilityFlag(i), "base_layer_parameter_set_compatibility_flag" ); |
|---|
| [644] | 2453 | } |
|---|
| [1185] | 2454 | } |
|---|
| [442] | 2455 | } |
|---|
| 2456 | |
|---|
| [1235] | 2457 | Void TEncCavlc::codeSPSExtension( const TComSPS* pcSPS ) |
|---|
| [313] | 2458 | { |
|---|
| [1029] | 2459 | // more syntax elements to be written here |
|---|
| [313] | 2460 | |
|---|
| [1029] | 2461 | // Vertical MV component restriction is not used in SHVC CTC |
|---|
| 2462 | WRITE_FLAG( 0, "inter_view_mv_vert_constraint_flag" ); |
|---|
| [313] | 2463 | } |
|---|
| 2464 | |
|---|
| [1235] | 2465 | Void TEncCavlc::codeVpsVuiBspHrdParams( const TComVPS* vps ) |
|---|
| [1215] | 2466 | { |
|---|
| 2467 | WRITE_UVLC( vps->getVpsNumAddHrdParams(), "vps_num_add_hrd_params" ); |
|---|
| 2468 | |
|---|
| 2469 | for( Int i = vps->getNumHrdParameters(), j = 0; i < vps->getNumHrdParameters() + vps->getVpsNumAddHrdParams(); i++, j++ ) // j = i - vps->getNumHrdParameters() |
|---|
| 2470 | { |
|---|
| 2471 | if( i > 0 ) |
|---|
| 2472 | { |
|---|
| 2473 | WRITE_FLAG( vps->getCprmsAddPresentFlag(j), "cprms_add_present_flag[i]" ); |
|---|
| 2474 | } |
|---|
| 2475 | |
|---|
| 2476 | WRITE_UVLC( vps->getNumSubLayerHrdMinus1(j), "num_sub_layer_hrd_minus1[i]" ); |
|---|
| 2477 | |
|---|
| 2478 | codeHrdParameters(vps->getBspHrd(j), i == 0 ? true : vps->getCprmsAddPresentFlag(j), vps->getNumSubLayerHrdMinus1(j)); |
|---|
| 2479 | } |
|---|
| 2480 | |
|---|
| 2481 | if( vps->getNumHrdParameters() + vps->getVpsNumAddHrdParams() > 0 ) |
|---|
| 2482 | { |
|---|
| 2483 | for( Int h = 1; h < vps->getNumOutputLayerSets(); h++ ) |
|---|
| 2484 | { |
|---|
| 2485 | Int lsIdx = vps->getOutputLayerSetIdx( h ); |
|---|
| 2486 | |
|---|
| 2487 | WRITE_UVLC( vps->getNumSignalledPartitioningSchemes(h), "num_signalled_partitioning_schemes[h]"); |
|---|
| 2488 | |
|---|
| 2489 | for( Int j = 1; j < vps->getNumSignalledPartitioningSchemes(h) + 1; j++ ) |
|---|
| 2490 | { |
|---|
| 2491 | WRITE_UVLC( vps->getNumPartitionsInSchemeMinus1(h, j), "num_partitions_in_scheme_minus1[h][j]" ); |
|---|
| 2492 | |
|---|
| 2493 | for( Int k = 0; k <= vps->getNumPartitionsInSchemeMinus1(h, j); k++ ) |
|---|
| 2494 | { |
|---|
| 2495 | for( Int r = 0; r < vps->getNumLayersInIdList( lsIdx ); r++ ) |
|---|
| 2496 | { |
|---|
| 2497 | WRITE_FLAG( vps->getLayerIncludedInPartitionFlag(h, j, k, r), "layer_included_in_partition_flag[h][j][k][r]" ); |
|---|
| 2498 | } |
|---|
| 2499 | } |
|---|
| 2500 | } |
|---|
| 2501 | |
|---|
| 2502 | for( Int i = 0; i < vps->getNumSignalledPartitioningSchemes(h) + 1; i++ ) |
|---|
| 2503 | { |
|---|
| 2504 | for( Int t = 0; t <= vps->getMaxSLayersInLayerSetMinus1(lsIdx); t++ ) |
|---|
| 2505 | { |
|---|
| 2506 | WRITE_UVLC(vps->getNumBspSchedulesMinus1(h, i, t), "num_bsp_schedules_minus1[h][i][t]"); |
|---|
| 2507 | |
|---|
| 2508 | for( Int j = 0; j <= vps->getNumBspSchedulesMinus1(h, i, t); j++ ) |
|---|
| 2509 | { |
|---|
| 2510 | for( Int k = 0; k <= vps->getNumPartitionsInSchemeMinus1(h, i); k++ ) |
|---|
| 2511 | { |
|---|
| 2512 | if( vps->getNumHrdParameters() + vps->getVpsNumAddHrdParams() > 1 ) |
|---|
| 2513 | { |
|---|
| 2514 | Int numBits = 1; |
|---|
| 2515 | while ((1 << numBits) < (vps->getNumHrdParameters() + vps->getVpsNumAddHrdParams())) |
|---|
| 2516 | { |
|---|
| 2517 | numBits++; |
|---|
| 2518 | } |
|---|
| 2519 | |
|---|
| [1235] | 2520 | WRITE_CODE(vps->getBspHrdIdx(h, i, t, j, k), numBits, "bsp_hrd_idx[h][i][t][j][k]"); |
|---|
| [1215] | 2521 | } |
|---|
| 2522 | |
|---|
| [1235] | 2523 | WRITE_UVLC( vps->getBspSchedIdx(h, i, t, j, k), "bsp_sched_idx[h][i][t][j][k]"); |
|---|
| [1215] | 2524 | } |
|---|
| 2525 | } |
|---|
| 2526 | } |
|---|
| 2527 | } |
|---|
| 2528 | } |
|---|
| 2529 | } |
|---|
| 2530 | } |
|---|
| 2531 | |
|---|
| 2532 | |
|---|
| [1212] | 2533 | #if CGS_3D_ASYMLUT |
|---|
| [713] | 2534 | Void TEncCavlc::xCode3DAsymLUT( TCom3DAsymLUT * pc3DAsymLUT ) |
|---|
| 2535 | { |
|---|
| [825] | 2536 | UInt uiNumRefLayers = ( UInt )pc3DAsymLUT->getRefLayerNum(); |
|---|
| 2537 | WRITE_UVLC( uiNumRefLayers - 1 , "num_cm_ref_layers_minus1" ); |
|---|
| 2538 | for( UInt i = 0 ; i < uiNumRefLayers ; i++ ) |
|---|
| 2539 | { |
|---|
| 2540 | WRITE_CODE( pc3DAsymLUT->getRefLayerId( i ) , 6 , "cm_ref_layer_id" ); |
|---|
| 2541 | } |
|---|
| [1213] | 2542 | |
|---|
| [713] | 2543 | assert( pc3DAsymLUT->getCurOctantDepth() < 4 ); |
|---|
| 2544 | WRITE_CODE( pc3DAsymLUT->getCurOctantDepth() , 2 , "cm_octant_depth" ); |
|---|
| 2545 | assert( pc3DAsymLUT->getCurYPartNumLog2() < 4 ); |
|---|
| 2546 | WRITE_CODE( pc3DAsymLUT->getCurYPartNumLog2() , 2 , "cm_y_part_num_log2" ); |
|---|
| 2547 | assert( pc3DAsymLUT->getInputBitDepthY() < 16 ); |
|---|
| [1213] | 2548 | |
|---|
| [882] | 2549 | WRITE_UVLC( pc3DAsymLUT->getInputBitDepthY() - 8 , "cm_input_luma_bit_depth_minus8" ); |
|---|
| 2550 | WRITE_UVLC( pc3DAsymLUT->getInputBitDepthC() - 8 , "cm_input_chroma_bit_depth_minus8" ); |
|---|
| 2551 | WRITE_UVLC( pc3DAsymLUT->getOutputBitDepthY() - 8 , "cm_output_luma_bit_depth_minus8" ); |
|---|
| 2552 | WRITE_UVLC( pc3DAsymLUT->getOutputBitDepthC() - 8 , "cm_output_chroma_bit_depth_minus8" ); |
|---|
| [1213] | 2553 | |
|---|
| [713] | 2554 | assert( pc3DAsymLUT->getResQuantBit() < 4 ); |
|---|
| 2555 | WRITE_CODE( pc3DAsymLUT->getResQuantBit() , 2 , "cm_res_quant_bit" ); |
|---|
| [1215] | 2556 | |
|---|
| [826] | 2557 | xFindDeltaBits( pc3DAsymLUT ); |
|---|
| 2558 | assert(pc3DAsymLUT->getDeltaBits() >=1 && pc3DAsymLUT->getDeltaBits() <= 4); |
|---|
| 2559 | WRITE_CODE( pc3DAsymLUT->getDeltaBits()-1 , 2 , "cm_delta_bit" ); |
|---|
| [1214] | 2560 | |
|---|
| [825] | 2561 | if( pc3DAsymLUT->getCurOctantDepth() == 1 ) |
|---|
| 2562 | { |
|---|
| 2563 | WRITE_SVLC( pc3DAsymLUT->getAdaptChromaThresholdU() - ( 1 << ( pc3DAsymLUT->getInputBitDepthC() - 1 ) ) , "cm_adapt_threshold_u_delta" ); |
|---|
| 2564 | WRITE_SVLC( pc3DAsymLUT->getAdaptChromaThresholdV() - ( 1 << ( pc3DAsymLUT->getInputBitDepthC() - 1 ) ) , "cm_adapt_threshold_v_delta" ); |
|---|
| 2565 | } |
|---|
| [713] | 2566 | |
|---|
| [852] | 2567 | #if R0164_CGS_LUT_BUGFIX_CHECK |
|---|
| [825] | 2568 | pc3DAsymLUT->xInitCuboids(); |
|---|
| 2569 | #endif |
|---|
| [713] | 2570 | xCode3DAsymLUTOctant( pc3DAsymLUT , 0 , 0 , 0 , 0 , 1 << pc3DAsymLUT->getCurOctantDepth() ); |
|---|
| [852] | 2571 | #if R0164_CGS_LUT_BUGFIX_CHECK |
|---|
| 2572 | xCuboidsFilledCheck( false ); |
|---|
| 2573 | pc3DAsymLUT->display( false ); |
|---|
| [825] | 2574 | #endif |
|---|
| [713] | 2575 | } |
|---|
| 2576 | |
|---|
| 2577 | Void TEncCavlc::xCode3DAsymLUTOctant( TCom3DAsymLUT * pc3DAsymLUT , Int nDepth , Int yIdx , Int uIdx , Int vIdx , Int nLength ) |
|---|
| 2578 | { |
|---|
| 2579 | UInt uiOctantSplit = nDepth < pc3DAsymLUT->getCurOctantDepth(); |
|---|
| 2580 | if( nDepth < pc3DAsymLUT->getCurOctantDepth() ) |
|---|
| 2581 | WRITE_FLAG( uiOctantSplit , "split_octant_flag" ); |
|---|
| 2582 | Int nYPartNum = 1 << pc3DAsymLUT->getCurYPartNumLog2(); |
|---|
| 2583 | if( uiOctantSplit ) |
|---|
| 2584 | { |
|---|
| 2585 | Int nHalfLength = nLength >> 1; |
|---|
| 2586 | for( Int l = 0 ; l < 2 ; l++ ) |
|---|
| 2587 | { |
|---|
| 2588 | for( Int m = 0 ; m < 2 ; m++ ) |
|---|
| 2589 | { |
|---|
| 2590 | for( Int n = 0 ; n < 2 ; n++ ) |
|---|
| 2591 | { |
|---|
| 2592 | xCode3DAsymLUTOctant( pc3DAsymLUT , nDepth + 1 , yIdx + l * nHalfLength * nYPartNum , uIdx + m * nHalfLength , vIdx + n * nHalfLength , nHalfLength ); |
|---|
| 2593 | } |
|---|
| 2594 | } |
|---|
| 2595 | } |
|---|
| 2596 | } |
|---|
| 2597 | else |
|---|
| 2598 | { |
|---|
| [826] | 2599 | Int nFLCbits = pc3DAsymLUT->getMappingShift()-pc3DAsymLUT->getResQuantBit()-pc3DAsymLUT->getDeltaBits() ; |
|---|
| 2600 | nFLCbits = nFLCbits >= 0 ? nFLCbits : 0; |
|---|
| [1215] | 2601 | |
|---|
| [713] | 2602 | for( Int l = 0 ; l < nYPartNum ; l++ ) |
|---|
| 2603 | { |
|---|
| [878] | 2604 | Int shift = pc3DAsymLUT->getCurOctantDepth() - nDepth ; |
|---|
| [1217] | 2605 | |
|---|
| [713] | 2606 | for( Int nVertexIdx = 0 ; nVertexIdx < 4 ; nVertexIdx++ ) |
|---|
| 2607 | { |
|---|
| [825] | 2608 | SYUVP sRes = pc3DAsymLUT->getCuboidVertexResTree( yIdx + (l<<shift) , uIdx , vIdx , nVertexIdx ); |
|---|
| [1217] | 2609 | |
|---|
| [713] | 2610 | UInt uiCodeVertex = sRes.Y != 0 || sRes.U != 0 || sRes.V != 0; |
|---|
| 2611 | WRITE_FLAG( uiCodeVertex , "coded_vertex_flag" ); |
|---|
| 2612 | if( uiCodeVertex ) |
|---|
| 2613 | { |
|---|
| [826] | 2614 | xWriteParam( sRes.Y, nFLCbits ); |
|---|
| 2615 | xWriteParam( sRes.U, nFLCbits ); |
|---|
| 2616 | xWriteParam( sRes.V, nFLCbits ); |
|---|
| [713] | 2617 | } |
|---|
| 2618 | } |
|---|
| [852] | 2619 | #if R0164_CGS_LUT_BUGFIX_CHECK |
|---|
| [825] | 2620 | pc3DAsymLUT->xSetExplicit( yIdx + (l<<shift) , uIdx , vIdx ); |
|---|
| 2621 | #endif |
|---|
| [713] | 2622 | } |
|---|
| 2623 | } |
|---|
| 2624 | } |
|---|
| [825] | 2625 | |
|---|
| [826] | 2626 | Void TEncCavlc::xWriteParam( Int param, UInt rParam) |
|---|
| [825] | 2627 | { |
|---|
| 2628 | Int codeNumber = abs(param); |
|---|
| 2629 | WRITE_UVLC(codeNumber / (1 << rParam), "quotient"); |
|---|
| 2630 | WRITE_CODE((codeNumber % (1 << rParam)), rParam, "remainder"); |
|---|
| 2631 | if (abs(param)) |
|---|
| 2632 | WRITE_FLAG( param <0, "sign"); |
|---|
| 2633 | } |
|---|
| 2634 | |
|---|
| [826] | 2635 | Void TEncCavlc::xFindDeltaBits( TCom3DAsymLUT * pc3DAsymLUT ) |
|---|
| 2636 | { |
|---|
| 2637 | Int nDeltaBits; |
|---|
| 2638 | Int nBestDeltaBits = -1; |
|---|
| 2639 | Int nBestBits = MAX_INT; |
|---|
| 2640 | for( nDeltaBits = 1; nDeltaBits < 5; nDeltaBits++) |
|---|
| 2641 | { |
|---|
| 2642 | Int nCurBits = 0; |
|---|
| 2643 | xTally3DAsymLUTOctantBits( pc3DAsymLUT , 0 , 0 , 0 , 0 , 1 << pc3DAsymLUT->getCurOctantDepth(), nDeltaBits, nCurBits ); |
|---|
| 2644 | //printf("%d, %d, %d\n", nDeltaBits, nCurBits, nBestBits); |
|---|
| 2645 | if(nCurBits < nBestBits) |
|---|
| 2646 | { |
|---|
| 2647 | nBestDeltaBits = nDeltaBits; |
|---|
| 2648 | nBestBits = nCurBits; |
|---|
| 2649 | } |
|---|
| 2650 | } |
|---|
| 2651 | |
|---|
| 2652 | assert(nBestDeltaBits >=1 && nBestDeltaBits < 5); |
|---|
| 2653 | pc3DAsymLUT->setDeltaBits(nBestDeltaBits); |
|---|
| 2654 | } |
|---|
| 2655 | |
|---|
| 2656 | Void TEncCavlc::xTally3DAsymLUTOctantBits( TCom3DAsymLUT * pc3DAsymLUT , Int nDepth , Int yIdx , Int uIdx , Int vIdx , Int nLength, Int nDeltaBits, Int& nCurBits ) |
|---|
| 2657 | { |
|---|
| 2658 | UInt uiOctantSplit = nDepth < pc3DAsymLUT->getCurOctantDepth(); |
|---|
| 2659 | if( nDepth < pc3DAsymLUT->getCurOctantDepth() ) |
|---|
| 2660 | nCurBits ++; |
|---|
| 2661 | Int nYPartNum = 1 << pc3DAsymLUT->getCurYPartNumLog2(); |
|---|
| 2662 | if( uiOctantSplit ) |
|---|
| 2663 | { |
|---|
| 2664 | Int nHalfLength = nLength >> 1; |
|---|
| 2665 | for( Int l = 0 ; l < 2 ; l++ ) |
|---|
| 2666 | { |
|---|
| 2667 | for( Int m = 0 ; m < 2 ; m++ ) |
|---|
| 2668 | { |
|---|
| 2669 | for( Int n = 0 ; n < 2 ; n++ ) |
|---|
| 2670 | { |
|---|
| 2671 | xTally3DAsymLUTOctantBits( pc3DAsymLUT , nDepth + 1 , yIdx + l * nHalfLength * nYPartNum , uIdx + m * nHalfLength , vIdx + n * nHalfLength , nHalfLength, nDeltaBits, nCurBits ); |
|---|
| 2672 | } |
|---|
| 2673 | } |
|---|
| 2674 | } |
|---|
| 2675 | } |
|---|
| 2676 | else |
|---|
| 2677 | { |
|---|
| 2678 | Int nFLCbits = pc3DAsymLUT->getMappingShift()-pc3DAsymLUT->getResQuantBit()-nDeltaBits ; |
|---|
| 2679 | nFLCbits = nFLCbits >= 0 ? nFLCbits:0; |
|---|
| 2680 | //printf("nFLCbits = %d\n", nFLCbits); |
|---|
| 2681 | |
|---|
| 2682 | for( Int l = 0 ; l < nYPartNum ; l++ ) |
|---|
| 2683 | { |
|---|
| 2684 | for( Int nVertexIdx = 0 ; nVertexIdx < 4 ; nVertexIdx++ ) |
|---|
| 2685 | { |
|---|
| 2686 | SYUVP sRes = pc3DAsymLUT->getCuboidVertexResTree( yIdx + l , uIdx , vIdx , nVertexIdx ); |
|---|
| 2687 | |
|---|
| 2688 | UInt uiCodeVertex = sRes.Y != 0 || sRes.U != 0 || sRes.V != 0; |
|---|
| 2689 | nCurBits++; |
|---|
| 2690 | if( uiCodeVertex ) |
|---|
| 2691 | { |
|---|
| 2692 | xCheckParamBits( sRes.Y, nFLCbits, nCurBits ); |
|---|
| 2693 | xCheckParamBits( sRes.U, nFLCbits, nCurBits ); |
|---|
| 2694 | xCheckParamBits( sRes.V, nFLCbits, nCurBits ); |
|---|
| 2695 | } |
|---|
| 2696 | } |
|---|
| 2697 | } |
|---|
| 2698 | } |
|---|
| 2699 | } |
|---|
| 2700 | |
|---|
| 2701 | Void TEncCavlc::xCheckParamBits( Int param, Int rParam, Int &nBits) |
|---|
| 2702 | { |
|---|
| 2703 | Int codeNumber = abs(param); |
|---|
| 2704 | Int codeQuotient = codeNumber >> rParam; |
|---|
| 2705 | Int qLen; |
|---|
| 2706 | |
|---|
| 2707 | UInt uiLength = 1; |
|---|
| 2708 | UInt uiTemp = ++codeQuotient; |
|---|
| 2709 | |
|---|
| 2710 | while( 1 != uiTemp ) |
|---|
| 2711 | { |
|---|
| 2712 | uiTemp >>= 1; |
|---|
| 2713 | uiLength += 2; |
|---|
| 2714 | } |
|---|
| 2715 | |
|---|
| 2716 | qLen = (uiLength >> 1); |
|---|
| 2717 | qLen += ((uiLength+1) >> 1); |
|---|
| 2718 | |
|---|
| 2719 | nBits += qLen; |
|---|
| 2720 | nBits += rParam; |
|---|
| 2721 | if (abs(param)) |
|---|
| 2722 | nBits++; |
|---|
| 2723 | } |
|---|
| [1215] | 2724 | #endif //CGS_3D_ASYMLUT |
|---|
| [1185] | 2725 | |
|---|
| 2726 | #endif //SVC_EXTENSION |
|---|
| [313] | 2727 | //! \} |
|---|