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