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