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