1 | /* The copyright in this software is being made available under the BSD |
---|
2 | * License, included below. This software may be subject to other third party |
---|
3 | * and contributor rights, including patent rights, and no such rights are |
---|
4 | * granted under this license. |
---|
5 | * |
---|
6 | * Copyright (c) 2010-2013, ITU/ISO/IEC |
---|
7 | * All rights reserved. |
---|
8 | * |
---|
9 | * Redistribution and use in source and binary forms, with or without |
---|
10 | * modification, are permitted provided that the following conditions are met: |
---|
11 | * |
---|
12 | * * Redistributions of source code must retain the above copyright notice, |
---|
13 | * this list of conditions and the following disclaimer. |
---|
14 | * * Redistributions in binary form must reproduce the above copyright notice, |
---|
15 | * this list of conditions and the following disclaimer in the documentation |
---|
16 | * and/or other materials provided with the distribution. |
---|
17 | * * Neither the name of the ITU/ISO/IEC nor the names of its contributors may |
---|
18 | * be used to endorse or promote products derived from this software without |
---|
19 | * specific prior written permission. |
---|
20 | * |
---|
21 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
---|
22 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
---|
23 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
---|
24 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS |
---|
25 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
---|
26 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
---|
27 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
---|
28 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
---|
29 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
---|
30 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF |
---|
31 | * THE POSSIBILITY OF SUCH DAMAGE. |
---|
32 | */ |
---|
33 | |
---|
34 | /** \file TDecCAVLC.cpp |
---|
35 | \brief CAVLC decoder class |
---|
36 | */ |
---|
37 | |
---|
38 | #include "TDecCAVLC.h" |
---|
39 | #include "SEIread.h" |
---|
40 | #include "TDecSlice.h" |
---|
41 | |
---|
42 | //! \ingroup TLibDecoder |
---|
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 | // Constructor / destructor / create / destroy |
---|
66 | // ==================================================================================================================== |
---|
67 | |
---|
68 | TDecCavlc::TDecCavlc() |
---|
69 | { |
---|
70 | } |
---|
71 | |
---|
72 | TDecCavlc::~TDecCavlc() |
---|
73 | { |
---|
74 | |
---|
75 | } |
---|
76 | |
---|
77 | // ==================================================================================================================== |
---|
78 | // Public member functions |
---|
79 | // ==================================================================================================================== |
---|
80 | |
---|
81 | void TDecCavlc::parseShortTermRefPicSet( TComSPS* sps, TComReferencePictureSet* rps, Int idx ) |
---|
82 | { |
---|
83 | UInt code; |
---|
84 | UInt interRPSPred; |
---|
85 | if (idx > 0) |
---|
86 | { |
---|
87 | READ_FLAG(interRPSPred, "inter_ref_pic_set_prediction_flag"); rps->setInterRPSPrediction(interRPSPred); |
---|
88 | } |
---|
89 | else |
---|
90 | { |
---|
91 | interRPSPred = false; |
---|
92 | rps->setInterRPSPrediction(false); |
---|
93 | } |
---|
94 | |
---|
95 | if (interRPSPred) |
---|
96 | { |
---|
97 | UInt bit; |
---|
98 | if(idx == sps->getRPSList()->getNumberOfReferencePictureSets()) |
---|
99 | { |
---|
100 | READ_UVLC(code, "delta_idx_minus1" ); // delta index of the Reference Picture Set used for prediction minus 1 |
---|
101 | } |
---|
102 | else |
---|
103 | { |
---|
104 | code = 0; |
---|
105 | } |
---|
106 | assert(code <= idx-1); // delta_idx_minus1 shall not be larger than idx-1, otherwise we will predict from a negative row position that does not exist. When idx equals 0 there is no legal value and interRPSPred must be zero. See J0185-r2 |
---|
107 | Int rIdx = idx - 1 - code; |
---|
108 | assert (rIdx <= idx-1 && rIdx >= 0); // Made assert tighter; if rIdx = idx then prediction is done from itself. rIdx must belong to range 0, idx-1, inclusive, see J0185-r2 |
---|
109 | TComReferencePictureSet* rpsRef = sps->getRPSList()->getReferencePictureSet(rIdx); |
---|
110 | Int k = 0, k0 = 0, k1 = 0; |
---|
111 | READ_CODE(1, bit, "delta_rps_sign"); // delta_RPS_sign |
---|
112 | READ_UVLC(code, "abs_delta_rps_minus1"); // absolute delta RPS minus 1 |
---|
113 | Int deltaRPS = (1 - 2 * bit) * (code + 1); // delta_RPS |
---|
114 | for(Int j=0 ; j <= rpsRef->getNumberOfPictures(); j++) |
---|
115 | { |
---|
116 | READ_CODE(1, bit, "used_by_curr_pic_flag" ); //first bit is "1" if Idc is 1 |
---|
117 | Int refIdc = bit; |
---|
118 | if (refIdc == 0) |
---|
119 | { |
---|
120 | READ_CODE(1, bit, "use_delta_flag" ); //second bit is "1" if Idc is 2, "0" otherwise. |
---|
121 | refIdc = bit<<1; //second bit is "1" if refIdc is 2, "0" if refIdc = 0. |
---|
122 | } |
---|
123 | if (refIdc == 1 || refIdc == 2) |
---|
124 | { |
---|
125 | Int deltaPOC = deltaRPS + ((j < rpsRef->getNumberOfPictures())? rpsRef->getDeltaPOC(j) : 0); |
---|
126 | rps->setDeltaPOC(k, deltaPOC); |
---|
127 | rps->setUsed(k, (refIdc == 1)); |
---|
128 | |
---|
129 | if (deltaPOC < 0) |
---|
130 | { |
---|
131 | k0++; |
---|
132 | } |
---|
133 | else |
---|
134 | { |
---|
135 | k1++; |
---|
136 | } |
---|
137 | k++; |
---|
138 | } |
---|
139 | rps->setRefIdc(j,refIdc); |
---|
140 | } |
---|
141 | rps->setNumRefIdc(rpsRef->getNumberOfPictures()+1); |
---|
142 | rps->setNumberOfPictures(k); |
---|
143 | rps->setNumberOfNegativePictures(k0); |
---|
144 | rps->setNumberOfPositivePictures(k1); |
---|
145 | rps->sortDeltaPOC(); |
---|
146 | } |
---|
147 | else |
---|
148 | { |
---|
149 | READ_UVLC(code, "num_negative_pics"); rps->setNumberOfNegativePictures(code); |
---|
150 | READ_UVLC(code, "num_positive_pics"); rps->setNumberOfPositivePictures(code); |
---|
151 | Int prev = 0; |
---|
152 | Int poc; |
---|
153 | for(Int j=0 ; j < rps->getNumberOfNegativePictures(); j++) |
---|
154 | { |
---|
155 | READ_UVLC(code, "delta_poc_s0_minus1"); |
---|
156 | poc = prev-code-1; |
---|
157 | prev = poc; |
---|
158 | rps->setDeltaPOC(j,poc); |
---|
159 | READ_FLAG(code, "used_by_curr_pic_s0_flag"); rps->setUsed(j,code); |
---|
160 | } |
---|
161 | prev = 0; |
---|
162 | for(Int j=rps->getNumberOfNegativePictures(); j < rps->getNumberOfNegativePictures()+rps->getNumberOfPositivePictures(); j++) |
---|
163 | { |
---|
164 | READ_UVLC(code, "delta_poc_s1_minus1"); |
---|
165 | poc = prev+code+1; |
---|
166 | prev = poc; |
---|
167 | rps->setDeltaPOC(j,poc); |
---|
168 | READ_FLAG(code, "used_by_curr_pic_s1_flag"); rps->setUsed(j,code); |
---|
169 | } |
---|
170 | rps->setNumberOfPictures(rps->getNumberOfNegativePictures()+rps->getNumberOfPositivePictures()); |
---|
171 | } |
---|
172 | #if PRINT_RPS_INFO |
---|
173 | rps->printDeltaPOC(); |
---|
174 | #endif |
---|
175 | } |
---|
176 | |
---|
177 | /** copy SAO parameter |
---|
178 | * \param dst |
---|
179 | * \param src |
---|
180 | */ |
---|
181 | inline Void copySaoOneLcuParam(SaoLcuParam* dst, SaoLcuParam* src) |
---|
182 | { |
---|
183 | Int i; |
---|
184 | dst->partIdx = src->partIdx; |
---|
185 | dst->typeIdx = src->typeIdx; |
---|
186 | if (dst->typeIdx != -1) |
---|
187 | { |
---|
188 | dst->subTypeIdx = src->subTypeIdx ; |
---|
189 | dst->length = src->length; |
---|
190 | for (i=0;i<dst->length;i++) |
---|
191 | { |
---|
192 | dst->offset[i] = src->offset[i]; |
---|
193 | } |
---|
194 | } |
---|
195 | else |
---|
196 | { |
---|
197 | dst->length = 0; |
---|
198 | for (i=0;i<SAO_BO_LEN;i++) |
---|
199 | { |
---|
200 | dst->offset[i] = 0; |
---|
201 | } |
---|
202 | } |
---|
203 | } |
---|
204 | |
---|
205 | Void TDecCavlc::parsePPS(TComPPS* pcPPS) |
---|
206 | { |
---|
207 | #if ENC_DEC_TRACE |
---|
208 | xTracePPSHeader (pcPPS); |
---|
209 | #endif |
---|
210 | UInt uiCode; |
---|
211 | |
---|
212 | Int iCode; |
---|
213 | |
---|
214 | READ_UVLC( uiCode, "pps_pic_parameter_set_id"); pcPPS->setPPSId (uiCode); |
---|
215 | READ_UVLC( uiCode, "pps_seq_parameter_set_id"); pcPPS->setSPSId (uiCode); |
---|
216 | READ_FLAG( uiCode, "dependent_slice_segments_enabled_flag" ); pcPPS->setDependentSliceSegmentsEnabledFlag ( uiCode == 1 ); |
---|
217 | #if L0255_MOVE_PPS_FLAGS |
---|
218 | READ_FLAG( uiCode, "output_flag_present_flag" ); pcPPS->setOutputFlagPresentFlag( uiCode==1 ); |
---|
219 | |
---|
220 | READ_CODE(3, uiCode, "num_extra_slice_header_bits"); pcPPS->setNumExtraSliceHeaderBits(uiCode); |
---|
221 | #endif |
---|
222 | READ_FLAG ( uiCode, "sign_data_hiding_flag" ); pcPPS->setSignHideFlag( uiCode ); |
---|
223 | |
---|
224 | READ_FLAG( uiCode, "cabac_init_present_flag" ); pcPPS->setCabacInitPresentFlag( uiCode ? true : false ); |
---|
225 | |
---|
226 | #if L0323_LIMIT_DEFAULT_LIST_SIZE |
---|
227 | READ_UVLC(uiCode, "num_ref_idx_l0_default_active_minus1"); |
---|
228 | assert(uiCode <= 14); |
---|
229 | pcPPS->setNumRefIdxL0DefaultActive(uiCode+1); |
---|
230 | |
---|
231 | READ_UVLC(uiCode, "num_ref_idx_l1_default_active_minus1"); |
---|
232 | assert(uiCode <= 14); |
---|
233 | pcPPS->setNumRefIdxL1DefaultActive(uiCode+1); |
---|
234 | #else |
---|
235 | READ_UVLC(uiCode, "num_ref_idx_l0_default_active_minus1"); pcPPS->setNumRefIdxL0DefaultActive(uiCode+1); |
---|
236 | READ_UVLC(uiCode, "num_ref_idx_l1_default_active_minus1"); pcPPS->setNumRefIdxL1DefaultActive(uiCode+1); |
---|
237 | #endif |
---|
238 | |
---|
239 | READ_SVLC(iCode, "init_qp_minus26" ); pcPPS->setPicInitQPMinus26(iCode); |
---|
240 | READ_FLAG( uiCode, "constrained_intra_pred_flag" ); pcPPS->setConstrainedIntraPred( uiCode ? true : false ); |
---|
241 | READ_FLAG( uiCode, "transform_skip_enabled_flag" ); |
---|
242 | pcPPS->setUseTransformSkip ( uiCode ? true : false ); |
---|
243 | |
---|
244 | READ_FLAG( uiCode, "cu_qp_delta_enabled_flag" ); pcPPS->setUseDQP( uiCode ? true : false ); |
---|
245 | if( pcPPS->getUseDQP() ) |
---|
246 | { |
---|
247 | READ_UVLC( uiCode, "diff_cu_qp_delta_depth" ); |
---|
248 | pcPPS->setMaxCuDQPDepth( uiCode ); |
---|
249 | } |
---|
250 | else |
---|
251 | { |
---|
252 | pcPPS->setMaxCuDQPDepth( 0 ); |
---|
253 | } |
---|
254 | READ_SVLC( iCode, "pps_cb_qp_offset"); |
---|
255 | pcPPS->setChromaCbQpOffset(iCode); |
---|
256 | assert( pcPPS->getChromaCbQpOffset() >= -12 ); |
---|
257 | assert( pcPPS->getChromaCbQpOffset() <= 12 ); |
---|
258 | |
---|
259 | READ_SVLC( iCode, "pps_cr_qp_offset"); |
---|
260 | pcPPS->setChromaCrQpOffset(iCode); |
---|
261 | assert( pcPPS->getChromaCrQpOffset() >= -12 ); |
---|
262 | assert( pcPPS->getChromaCrQpOffset() <= 12 ); |
---|
263 | |
---|
264 | READ_FLAG( uiCode, "pps_slice_chroma_qp_offsets_present_flag" ); |
---|
265 | pcPPS->setSliceChromaQpFlag( uiCode ? true : false ); |
---|
266 | |
---|
267 | READ_FLAG( uiCode, "weighted_pred_flag" ); // Use of Weighting Prediction (P_SLICE) |
---|
268 | pcPPS->setUseWP( uiCode==1 ); |
---|
269 | READ_FLAG( uiCode, "weighted_bipred_flag" ); // Use of Bi-Directional Weighting Prediction (B_SLICE) |
---|
270 | pcPPS->setWPBiPred( uiCode==1 ); |
---|
271 | |
---|
272 | #if !L0255_MOVE_PPS_FLAGS |
---|
273 | READ_FLAG( uiCode, "output_flag_present_flag" ); |
---|
274 | pcPPS->setOutputFlagPresentFlag( uiCode==1 ); |
---|
275 | #endif |
---|
276 | READ_FLAG( uiCode, "transquant_bypass_enable_flag"); |
---|
277 | pcPPS->setTransquantBypassEnableFlag(uiCode ? true : false); |
---|
278 | READ_FLAG( uiCode, "tiles_enabled_flag" ); pcPPS->setTilesEnabledFlag ( uiCode == 1 ); |
---|
279 | READ_FLAG( uiCode, "entropy_coding_sync_enabled_flag" ); pcPPS->setEntropyCodingSyncEnabledFlag( uiCode == 1 ); |
---|
280 | |
---|
281 | if( pcPPS->getTilesEnabledFlag() ) |
---|
282 | { |
---|
283 | READ_UVLC ( uiCode, "num_tile_columns_minus1" ); pcPPS->setNumColumnsMinus1( uiCode ); |
---|
284 | READ_UVLC ( uiCode, "num_tile_rows_minus1" ); pcPPS->setNumRowsMinus1( uiCode ); |
---|
285 | READ_FLAG ( uiCode, "uniform_spacing_flag" ); pcPPS->setUniformSpacingFlag( uiCode ); |
---|
286 | |
---|
287 | if( !pcPPS->getUniformSpacingFlag()) |
---|
288 | { |
---|
289 | UInt* columnWidth = (UInt*)malloc(pcPPS->getNumColumnsMinus1()*sizeof(UInt)); |
---|
290 | for(UInt i=0; i<pcPPS->getNumColumnsMinus1(); i++) |
---|
291 | { |
---|
292 | READ_UVLC( uiCode, "column_width_minus1" ); |
---|
293 | columnWidth[i] = uiCode+1; |
---|
294 | } |
---|
295 | pcPPS->setColumnWidth(columnWidth); |
---|
296 | free(columnWidth); |
---|
297 | |
---|
298 | UInt* rowHeight = (UInt*)malloc(pcPPS->getNumRowsMinus1()*sizeof(UInt)); |
---|
299 | for(UInt i=0; i<pcPPS->getNumRowsMinus1(); i++) |
---|
300 | { |
---|
301 | READ_UVLC( uiCode, "row_height_minus1" ); |
---|
302 | rowHeight[i] = uiCode + 1; |
---|
303 | } |
---|
304 | pcPPS->setRowHeight(rowHeight); |
---|
305 | free(rowHeight); |
---|
306 | } |
---|
307 | |
---|
308 | if(pcPPS->getNumColumnsMinus1() !=0 || pcPPS->getNumRowsMinus1() !=0) |
---|
309 | { |
---|
310 | READ_FLAG ( uiCode, "loop_filter_across_tiles_enabled_flag" ); pcPPS->setLoopFilterAcrossTilesEnabledFlag( uiCode ? true : false ); |
---|
311 | } |
---|
312 | } |
---|
313 | READ_FLAG( uiCode, "loop_filter_across_slices_enabled_flag" ); pcPPS->setLoopFilterAcrossSlicesEnabledFlag( uiCode ? true : false ); |
---|
314 | READ_FLAG( uiCode, "deblocking_filter_control_present_flag" ); pcPPS->setDeblockingFilterControlPresentFlag( uiCode ? true : false ); |
---|
315 | if(pcPPS->getDeblockingFilterControlPresentFlag()) |
---|
316 | { |
---|
317 | READ_FLAG( uiCode, "deblocking_filter_override_enabled_flag" ); pcPPS->setDeblockingFilterOverrideEnabledFlag( uiCode ? true : false ); |
---|
318 | READ_FLAG( uiCode, "pps_disable_deblocking_filter_flag" ); pcPPS->setPicDisableDeblockingFilterFlag(uiCode ? true : false ); |
---|
319 | if(!pcPPS->getPicDisableDeblockingFilterFlag()) |
---|
320 | { |
---|
321 | READ_SVLC ( iCode, "pps_beta_offset_div2" ); pcPPS->setDeblockingFilterBetaOffsetDiv2( iCode ); |
---|
322 | READ_SVLC ( iCode, "pps_tc_offset_div2" ); pcPPS->setDeblockingFilterTcOffsetDiv2( iCode ); |
---|
323 | } |
---|
324 | } |
---|
325 | READ_FLAG( uiCode, "pps_scaling_list_data_present_flag" ); pcPPS->setScalingListPresentFlag( uiCode ? true : false ); |
---|
326 | if(pcPPS->getScalingListPresentFlag ()) |
---|
327 | { |
---|
328 | parseScalingList( pcPPS->getScalingList() ); |
---|
329 | } |
---|
330 | |
---|
331 | READ_FLAG( uiCode, "lists_modification_present_flag"); |
---|
332 | pcPPS->setListsModificationPresentFlag(uiCode); |
---|
333 | |
---|
334 | READ_UVLC( uiCode, "log2_parallel_merge_level_minus2"); |
---|
335 | pcPPS->setLog2ParallelMergeLevelMinus2 (uiCode); |
---|
336 | |
---|
337 | #if !L0255_MOVE_PPS_FLAGS |
---|
338 | READ_CODE(3, uiCode, "num_extra_slice_header_bits"); |
---|
339 | pcPPS->setNumExtraSliceHeaderBits(uiCode); |
---|
340 | #endif |
---|
341 | READ_FLAG( uiCode, "slice_segment_header_extension_present_flag"); |
---|
342 | pcPPS->setSliceHeaderExtensionPresentFlag(uiCode); |
---|
343 | |
---|
344 | READ_FLAG( uiCode, "pps_extension_flag"); |
---|
345 | if (uiCode) |
---|
346 | { |
---|
347 | while ( xMoreRbspData() ) |
---|
348 | { |
---|
349 | READ_FLAG( uiCode, "pps_extension_data_flag"); |
---|
350 | } |
---|
351 | } |
---|
352 | } |
---|
353 | |
---|
354 | Void TDecCavlc::parseVUI(TComVUI* pcVUI, TComSPS *pcSPS) |
---|
355 | { |
---|
356 | #if ENC_DEC_TRACE |
---|
357 | fprintf( g_hTrace, "----------- vui_parameters -----------\n"); |
---|
358 | #endif |
---|
359 | UInt uiCode; |
---|
360 | |
---|
361 | READ_FLAG( uiCode, "aspect_ratio_info_present_flag"); pcVUI->setAspectRatioInfoPresentFlag(uiCode); |
---|
362 | if (pcVUI->getAspectRatioInfoPresentFlag()) |
---|
363 | { |
---|
364 | READ_CODE(8, uiCode, "aspect_ratio_idc"); pcVUI->setAspectRatioIdc(uiCode); |
---|
365 | if (pcVUI->getAspectRatioIdc() == 255) |
---|
366 | { |
---|
367 | READ_CODE(16, uiCode, "sar_width"); pcVUI->setSarWidth(uiCode); |
---|
368 | READ_CODE(16, uiCode, "sar_height"); pcVUI->setSarHeight(uiCode); |
---|
369 | } |
---|
370 | } |
---|
371 | |
---|
372 | READ_FLAG( uiCode, "overscan_info_present_flag"); pcVUI->setOverscanInfoPresentFlag(uiCode); |
---|
373 | if (pcVUI->getOverscanInfoPresentFlag()) |
---|
374 | { |
---|
375 | READ_FLAG( uiCode, "overscan_appropriate_flag"); pcVUI->setOverscanAppropriateFlag(uiCode); |
---|
376 | } |
---|
377 | |
---|
378 | READ_FLAG( uiCode, "video_signal_type_present_flag"); pcVUI->setVideoSignalTypePresentFlag(uiCode); |
---|
379 | if (pcVUI->getVideoSignalTypePresentFlag()) |
---|
380 | { |
---|
381 | READ_CODE(3, uiCode, "video_format"); pcVUI->setVideoFormat(uiCode); |
---|
382 | READ_FLAG( uiCode, "video_full_range_flag"); pcVUI->setVideoFullRangeFlag(uiCode); |
---|
383 | READ_FLAG( uiCode, "colour_description_present_flag"); pcVUI->setColourDescriptionPresentFlag(uiCode); |
---|
384 | if (pcVUI->getColourDescriptionPresentFlag()) |
---|
385 | { |
---|
386 | READ_CODE(8, uiCode, "colour_primaries"); pcVUI->setColourPrimaries(uiCode); |
---|
387 | READ_CODE(8, uiCode, "transfer_characteristics"); pcVUI->setTransferCharacteristics(uiCode); |
---|
388 | READ_CODE(8, uiCode, "matrix_coefficients"); pcVUI->setMatrixCoefficients(uiCode); |
---|
389 | } |
---|
390 | } |
---|
391 | |
---|
392 | READ_FLAG( uiCode, "chroma_loc_info_present_flag"); pcVUI->setChromaLocInfoPresentFlag(uiCode); |
---|
393 | if (pcVUI->getChromaLocInfoPresentFlag()) |
---|
394 | { |
---|
395 | READ_UVLC( uiCode, "chroma_sample_loc_type_top_field" ); pcVUI->setChromaSampleLocTypeTopField(uiCode); |
---|
396 | READ_UVLC( uiCode, "chroma_sample_loc_type_bottom_field" ); pcVUI->setChromaSampleLocTypeBottomField(uiCode); |
---|
397 | } |
---|
398 | |
---|
399 | READ_FLAG( uiCode, "neutral_chroma_indication_flag"); pcVUI->setNeutralChromaIndicationFlag(uiCode); |
---|
400 | |
---|
401 | READ_FLAG( uiCode, "field_seq_flag"); pcVUI->setFieldSeqFlag(uiCode); |
---|
402 | assert(pcVUI->getFieldSeqFlag() == false); // not supported yet |
---|
403 | |
---|
404 | READ_FLAG(uiCode, "frame_field_info_present_flag"); pcVUI->setFrameFieldInfoPresentFlag(uiCode); |
---|
405 | |
---|
406 | READ_FLAG( uiCode, "default_display_window_flag"); |
---|
407 | if (uiCode != 0) |
---|
408 | { |
---|
409 | Window &defDisp = pcVUI->getDefaultDisplayWindow(); |
---|
410 | READ_UVLC( uiCode, "def_disp_win_left_offset" ); defDisp.setWindowLeftOffset ( uiCode * TComSPS::getWinUnitX( pcSPS->getChromaFormatIdc()) ); |
---|
411 | READ_UVLC( uiCode, "def_disp_win_right_offset" ); defDisp.setWindowRightOffset ( uiCode * TComSPS::getWinUnitX( pcSPS->getChromaFormatIdc()) ); |
---|
412 | READ_UVLC( uiCode, "def_disp_win_top_offset" ); defDisp.setWindowTopOffset ( uiCode * TComSPS::getWinUnitY( pcSPS->getChromaFormatIdc()) ); |
---|
413 | READ_UVLC( uiCode, "def_disp_win_bottom_offset" ); defDisp.setWindowBottomOffset( uiCode * TComSPS::getWinUnitY( pcSPS->getChromaFormatIdc()) ); |
---|
414 | } |
---|
415 | #if L0043_TIMING_INFO |
---|
416 | TimingInfo *timingInfo = pcVUI->getTimingInfo(); |
---|
417 | READ_FLAG( uiCode, "vui_timing_info_present_flag"); timingInfo->setTimingInfoPresentFlag (uiCode ? true : false); |
---|
418 | if(timingInfo->getTimingInfoPresentFlag()) |
---|
419 | { |
---|
420 | READ_CODE( 32, uiCode, "vui_num_units_in_tick"); timingInfo->setNumUnitsInTick (uiCode); |
---|
421 | READ_CODE( 32, uiCode, "vui_time_scale"); timingInfo->setTimeScale (uiCode); |
---|
422 | READ_FLAG( uiCode, "vui_poc_proportional_to_timing_flag"); timingInfo->setPocProportionalToTimingFlag(uiCode ? true : false); |
---|
423 | if(timingInfo->getPocProportionalToTimingFlag()) |
---|
424 | { |
---|
425 | READ_UVLC( uiCode, "vui_num_ticks_poc_diff_one_minus1"); timingInfo->setNumTicksPocDiffOneMinus1 (uiCode); |
---|
426 | } |
---|
427 | #endif |
---|
428 | READ_FLAG( uiCode, "hrd_parameters_present_flag"); pcVUI->setHrdParametersPresentFlag(uiCode); |
---|
429 | if( pcVUI->getHrdParametersPresentFlag() ) |
---|
430 | { |
---|
431 | parseHrdParameters( pcVUI->getHrdParameters(), 1, pcSPS->getMaxTLayers() - 1 ); |
---|
432 | } |
---|
433 | #if L0043_TIMING_INFO |
---|
434 | } |
---|
435 | #endif |
---|
436 | #if !L0043_TIMING_INFO |
---|
437 | READ_FLAG( uiCode, "poc_proportional_to_timing_flag" ); pcVUI->setPocProportionalToTimingFlag(uiCode ? true : false); |
---|
438 | if( pcVUI->getPocProportionalToTimingFlag() && pcVUI->getHrdParameters()->getTimingInfoPresentFlag() ) |
---|
439 | { |
---|
440 | READ_UVLC( uiCode, "num_ticks_poc_diff_one_minus1" ); pcVUI->setNumTicksPocDiffOneMinus1(uiCode); |
---|
441 | } |
---|
442 | #endif |
---|
443 | READ_FLAG( uiCode, "bitstream_restriction_flag"); pcVUI->setBitstreamRestrictionFlag(uiCode); |
---|
444 | if (pcVUI->getBitstreamRestrictionFlag()) |
---|
445 | { |
---|
446 | READ_FLAG( uiCode, "tiles_fixed_structure_flag"); pcVUI->setTilesFixedStructureFlag(uiCode); |
---|
447 | READ_FLAG( uiCode, "motion_vectors_over_pic_boundaries_flag"); pcVUI->setMotionVectorsOverPicBoundariesFlag(uiCode); |
---|
448 | READ_FLAG( uiCode, "restricted_ref_pic_lists_flag"); pcVUI->setRestrictedRefPicListsFlag(uiCode); |
---|
449 | #if L0043_MSS_IDC |
---|
450 | READ_UVLC( uiCode, "min_spatial_segmentation_idc"); pcVUI->setMinSpatialSegmentationIdc(uiCode); |
---|
451 | assert(uiCode < 4096); |
---|
452 | #else |
---|
453 | READ_CODE( 8, uiCode, "min_spatial_segmentation_idc"); pcVUI->setMinSpatialSegmentationIdc(uiCode); |
---|
454 | #endif |
---|
455 | READ_UVLC( uiCode, "max_bytes_per_pic_denom" ); pcVUI->setMaxBytesPerPicDenom(uiCode); |
---|
456 | READ_UVLC( uiCode, "max_bits_per_mincu_denom" ); pcVUI->setMaxBitsPerMinCuDenom(uiCode); |
---|
457 | READ_UVLC( uiCode, "log2_max_mv_length_horizontal" ); pcVUI->setLog2MaxMvLengthHorizontal(uiCode); |
---|
458 | READ_UVLC( uiCode, "log2_max_mv_length_vertical" ); pcVUI->setLog2MaxMvLengthVertical(uiCode); |
---|
459 | } |
---|
460 | } |
---|
461 | |
---|
462 | Void TDecCavlc::parseHrdParameters(TComHRD *hrd, Bool commonInfPresentFlag, UInt maxNumSubLayersMinus1) |
---|
463 | { |
---|
464 | UInt uiCode; |
---|
465 | if( commonInfPresentFlag ) |
---|
466 | { |
---|
467 | #if !L0043_TIMING_INFO |
---|
468 | READ_FLAG( uiCode, "timing_info_present_flag" ); hrd->setTimingInfoPresentFlag( uiCode == 1 ? true : false ); |
---|
469 | if( hrd->getTimingInfoPresentFlag() ) |
---|
470 | { |
---|
471 | READ_CODE( 32, uiCode, "num_units_in_tick" ); hrd->setNumUnitsInTick( uiCode ); |
---|
472 | READ_CODE( 32, uiCode, "time_scale" ); hrd->setTimeScale( uiCode ); |
---|
473 | } |
---|
474 | #endif |
---|
475 | READ_FLAG( uiCode, "nal_hrd_parameters_present_flag" ); hrd->setNalHrdParametersPresentFlag( uiCode == 1 ? true : false ); |
---|
476 | READ_FLAG( uiCode, "vcl_hrd_parameters_present_flag" ); hrd->setVclHrdParametersPresentFlag( uiCode == 1 ? true : false ); |
---|
477 | if( hrd->getNalHrdParametersPresentFlag() || hrd->getVclHrdParametersPresentFlag() ) |
---|
478 | { |
---|
479 | READ_FLAG( uiCode, "sub_pic_cpb_params_present_flag" ); hrd->setSubPicCpbParamsPresentFlag( uiCode == 1 ? true : false ); |
---|
480 | if( hrd->getSubPicCpbParamsPresentFlag() ) |
---|
481 | { |
---|
482 | READ_CODE( 8, uiCode, "tick_divisor_minus2" ); hrd->setTickDivisorMinus2( uiCode ); |
---|
483 | READ_CODE( 5, uiCode, "du_cpb_removal_delay_length_minus1" ); hrd->setDuCpbRemovalDelayLengthMinus1( uiCode ); |
---|
484 | READ_FLAG( uiCode, "sub_pic_cpb_params_in_pic_timing_sei_flag" ); hrd->setSubPicCpbParamsInPicTimingSEIFlag( uiCode == 1 ? true : false ); |
---|
485 | #if L0044_DU_DPB_OUTPUT_DELAY_HRD |
---|
486 | READ_CODE( 5, uiCode, "dpb_output_delay_du_length_minus1" ); hrd->setDpbOutputDelayDuLengthMinus1( uiCode ); |
---|
487 | #endif |
---|
488 | } |
---|
489 | READ_CODE( 4, uiCode, "bit_rate_scale" ); hrd->setBitRateScale( uiCode ); |
---|
490 | READ_CODE( 4, uiCode, "cpb_size_scale" ); hrd->setCpbSizeScale( uiCode ); |
---|
491 | if( hrd->getSubPicCpbParamsPresentFlag() ) |
---|
492 | { |
---|
493 | READ_CODE( 4, uiCode, "cpb_size_du_scale" ); hrd->setDuCpbSizeScale( uiCode ); |
---|
494 | } |
---|
495 | READ_CODE( 5, uiCode, "initial_cpb_removal_delay_length_minus1" ); hrd->setInitialCpbRemovalDelayLengthMinus1( uiCode ); |
---|
496 | READ_CODE( 5, uiCode, "au_cpb_removal_delay_length_minus1" ); hrd->setCpbRemovalDelayLengthMinus1( uiCode ); |
---|
497 | READ_CODE( 5, uiCode, "dpb_output_delay_length_minus1" ); hrd->setDpbOutputDelayLengthMinus1( uiCode ); |
---|
498 | } |
---|
499 | } |
---|
500 | Int i, j, nalOrVcl; |
---|
501 | for( i = 0; i <= maxNumSubLayersMinus1; i ++ ) |
---|
502 | { |
---|
503 | READ_FLAG( uiCode, "fixed_pic_rate_general_flag" ); hrd->setFixedPicRateFlag( i, uiCode == 1 ? true : false ); |
---|
504 | if( !hrd->getFixedPicRateFlag( i ) ) |
---|
505 | { |
---|
506 | READ_FLAG( uiCode, "fixed_pic_rate_within_cvs_flag" ); hrd->setFixedPicRateWithinCvsFlag( i, uiCode == 1 ? true : false ); |
---|
507 | } |
---|
508 | else |
---|
509 | { |
---|
510 | hrd->setFixedPicRateWithinCvsFlag( i, true ); |
---|
511 | } |
---|
512 | #if L0372 |
---|
513 | hrd->setLowDelayHrdFlag( i, 0 ); // Infered to be 0 when not present |
---|
514 | hrd->setCpbCntMinus1 ( i, 0 ); // Infered to be 0 when not present |
---|
515 | #endif |
---|
516 | if( hrd->getFixedPicRateWithinCvsFlag( i ) ) |
---|
517 | { |
---|
518 | READ_UVLC( uiCode, "elemental_duration_in_tc_minus1" ); hrd->setPicDurationInTcMinus1( i, uiCode ); |
---|
519 | } |
---|
520 | #if L0372 |
---|
521 | else |
---|
522 | { |
---|
523 | READ_FLAG( uiCode, "low_delay_hrd_flag" ); hrd->setLowDelayHrdFlag( i, uiCode == 1 ? true : false ); |
---|
524 | } |
---|
525 | if (!hrd->getLowDelayHrdFlag( i )) |
---|
526 | { |
---|
527 | READ_UVLC( uiCode, "cpb_cnt_minus1" ); hrd->setCpbCntMinus1( i, uiCode ); |
---|
528 | } |
---|
529 | #else |
---|
530 | READ_FLAG( uiCode, "low_delay_hrd_flag" ); hrd->setLowDelayHrdFlag( i, uiCode == 1 ? true : false ); |
---|
531 | READ_UVLC( uiCode, "cpb_cnt_minus1" ); hrd->setCpbCntMinus1( i, uiCode ); |
---|
532 | #endif |
---|
533 | for( nalOrVcl = 0; nalOrVcl < 2; nalOrVcl ++ ) |
---|
534 | { |
---|
535 | if( ( ( nalOrVcl == 0 ) && ( hrd->getNalHrdParametersPresentFlag() ) ) || |
---|
536 | ( ( nalOrVcl == 1 ) && ( hrd->getVclHrdParametersPresentFlag() ) ) ) |
---|
537 | { |
---|
538 | for( j = 0; j <= ( hrd->getCpbCntMinus1( i ) ); j ++ ) |
---|
539 | { |
---|
540 | READ_UVLC( uiCode, "bit_rate_value_minus1" ); hrd->setBitRateValueMinus1( i, j, nalOrVcl, uiCode ); |
---|
541 | READ_UVLC( uiCode, "cpb_size_value_minus1" ); hrd->setCpbSizeValueMinus1( i, j, nalOrVcl, uiCode ); |
---|
542 | if( hrd->getSubPicCpbParamsPresentFlag() ) |
---|
543 | { |
---|
544 | #if L0363_DU_BIT_RATE |
---|
545 | READ_UVLC( uiCode, "bit_rate_du_value_minus1" ); hrd->setDuBitRateValueMinus1( i, j, nalOrVcl, uiCode ); |
---|
546 | #endif |
---|
547 | READ_UVLC( uiCode, "cpb_size_du_value_minus1" ); hrd->setDuCpbSizeValueMinus1( i, j, nalOrVcl, uiCode ); |
---|
548 | } |
---|
549 | READ_FLAG( uiCode, "cbr_flag" ); hrd->setCbrFlag( i, j, nalOrVcl, uiCode == 1 ? true : false ); |
---|
550 | } |
---|
551 | } |
---|
552 | } |
---|
553 | } |
---|
554 | } |
---|
555 | |
---|
556 | Void TDecCavlc::parseSPS(TComSPS* pcSPS) |
---|
557 | { |
---|
558 | #if ENC_DEC_TRACE |
---|
559 | xTraceSPSHeader (pcSPS); |
---|
560 | #endif |
---|
561 | |
---|
562 | UInt uiCode; |
---|
563 | READ_CODE( 4, uiCode, "sps_video_parameter_set_id"); pcSPS->setVPSId ( uiCode ); |
---|
564 | READ_CODE( 3, uiCode, "sps_max_sub_layers_minus1" ); pcSPS->setMaxTLayers ( uiCode+1 ); |
---|
565 | READ_FLAG( uiCode, "sps_temporal_id_nesting_flag" ); pcSPS->setTemporalIdNestingFlag ( uiCode > 0 ? true : false ); |
---|
566 | if ( pcSPS->getMaxTLayers() == 1 ) |
---|
567 | { |
---|
568 | // sps_temporal_id_nesting_flag must be 1 when sps_max_sub_layers_minus1 is 0 |
---|
569 | assert( uiCode == 1 ); |
---|
570 | } |
---|
571 | |
---|
572 | parsePTL(pcSPS->getPTL(), 1, pcSPS->getMaxTLayers() - 1); |
---|
573 | READ_UVLC( uiCode, "sps_seq_parameter_set_id" ); pcSPS->setSPSId( uiCode ); |
---|
574 | READ_UVLC( uiCode, "chroma_format_idc" ); pcSPS->setChromaFormatIdc( uiCode ); |
---|
575 | // in the first version we only support chroma_format_idc equal to 1 (4:2:0), so separate_colour_plane_flag cannot appear in the bitstream |
---|
576 | assert (uiCode == 1); |
---|
577 | if( uiCode == 3 ) |
---|
578 | { |
---|
579 | READ_FLAG( uiCode, "separate_colour_plane_flag"); assert(uiCode == 0); |
---|
580 | } |
---|
581 | |
---|
582 | READ_UVLC ( uiCode, "pic_width_in_luma_samples" ); pcSPS->setPicWidthInLumaSamples ( uiCode ); |
---|
583 | READ_UVLC ( uiCode, "pic_height_in_luma_samples" ); pcSPS->setPicHeightInLumaSamples( uiCode ); |
---|
584 | READ_FLAG( uiCode, "conformance_window_flag"); |
---|
585 | if (uiCode != 0) |
---|
586 | { |
---|
587 | Window &conf = pcSPS->getConformanceWindow(); |
---|
588 | READ_UVLC( uiCode, "conf_win_left_offset" ); conf.setWindowLeftOffset ( uiCode * TComSPS::getWinUnitX( pcSPS->getChromaFormatIdc() ) ); |
---|
589 | READ_UVLC( uiCode, "conf_win_right_offset" ); conf.setWindowRightOffset ( uiCode * TComSPS::getWinUnitX( pcSPS->getChromaFormatIdc() ) ); |
---|
590 | READ_UVLC( uiCode, "conf_win_top_offset" ); conf.setWindowTopOffset ( uiCode * TComSPS::getWinUnitY( pcSPS->getChromaFormatIdc() ) ); |
---|
591 | READ_UVLC( uiCode, "conf_win_bottom_offset" ); conf.setWindowBottomOffset( uiCode * TComSPS::getWinUnitY( pcSPS->getChromaFormatIdc() ) ); |
---|
592 | } |
---|
593 | |
---|
594 | READ_UVLC( uiCode, "bit_depth_luma_minus8" ); |
---|
595 | g_bitDepthY = 8 + uiCode; |
---|
596 | pcSPS->setBitDepthY(g_bitDepthY); |
---|
597 | pcSPS->setQpBDOffsetY( (Int) (6*uiCode) ); |
---|
598 | |
---|
599 | READ_UVLC( uiCode, "bit_depth_chroma_minus8" ); |
---|
600 | g_bitDepthC = 8 + uiCode; |
---|
601 | pcSPS->setBitDepthC(g_bitDepthC); |
---|
602 | pcSPS->setQpBDOffsetC( (Int) (6*uiCode) ); |
---|
603 | |
---|
604 | READ_UVLC( uiCode, "log2_max_pic_order_cnt_lsb_minus4" ); pcSPS->setBitsForPOC( 4 + uiCode ); |
---|
605 | |
---|
606 | UInt subLayerOrderingInfoPresentFlag; |
---|
607 | READ_FLAG(subLayerOrderingInfoPresentFlag, "sps_sub_layer_ordering_info_present_flag"); |
---|
608 | for(UInt i=0; i <= pcSPS->getMaxTLayers()-1; i++) |
---|
609 | { |
---|
610 | READ_UVLC ( uiCode, "sps_max_dec_pic_buffering"); |
---|
611 | pcSPS->setMaxDecPicBuffering( uiCode, i); |
---|
612 | READ_UVLC ( uiCode, "sps_num_reorder_pics" ); |
---|
613 | pcSPS->setNumReorderPics(uiCode, i); |
---|
614 | READ_UVLC ( uiCode, "sps_max_latency_increase"); |
---|
615 | pcSPS->setMaxLatencyIncrease( uiCode, i ); |
---|
616 | |
---|
617 | if (!subLayerOrderingInfoPresentFlag) |
---|
618 | { |
---|
619 | for (i++; i <= pcSPS->getMaxTLayers()-1; i++) |
---|
620 | { |
---|
621 | pcSPS->setMaxDecPicBuffering(pcSPS->getMaxDecPicBuffering(0), i); |
---|
622 | pcSPS->setNumReorderPics(pcSPS->getNumReorderPics(0), i); |
---|
623 | pcSPS->setMaxLatencyIncrease(pcSPS->getMaxLatencyIncrease(0), i); |
---|
624 | } |
---|
625 | break; |
---|
626 | } |
---|
627 | } |
---|
628 | |
---|
629 | READ_UVLC( uiCode, "log2_min_coding_block_size_minus3" ); |
---|
630 | UInt log2MinCUSize = uiCode + 3; |
---|
631 | READ_UVLC( uiCode, "log2_diff_max_min_coding_block_size" ); |
---|
632 | UInt uiMaxCUDepthCorrect = uiCode; |
---|
633 | pcSPS->setMaxCUWidth ( 1<<(log2MinCUSize + uiMaxCUDepthCorrect) ); g_uiMaxCUWidth = 1<<(log2MinCUSize + uiMaxCUDepthCorrect); |
---|
634 | pcSPS->setMaxCUHeight ( 1<<(log2MinCUSize + uiMaxCUDepthCorrect) ); g_uiMaxCUHeight = 1<<(log2MinCUSize + uiMaxCUDepthCorrect); |
---|
635 | READ_UVLC( uiCode, "log2_min_transform_block_size_minus2" ); pcSPS->setQuadtreeTULog2MinSize( uiCode + 2 ); |
---|
636 | |
---|
637 | READ_UVLC( uiCode, "log2_diff_max_min_transform_block_size" ); pcSPS->setQuadtreeTULog2MaxSize( uiCode + pcSPS->getQuadtreeTULog2MinSize() ); |
---|
638 | pcSPS->setMaxTrSize( 1<<(uiCode + pcSPS->getQuadtreeTULog2MinSize()) ); |
---|
639 | |
---|
640 | READ_UVLC( uiCode, "max_transform_hierarchy_depth_inter" ); pcSPS->setQuadtreeTUMaxDepthInter( uiCode+1 ); |
---|
641 | READ_UVLC( uiCode, "max_transform_hierarchy_depth_intra" ); pcSPS->setQuadtreeTUMaxDepthIntra( uiCode+1 ); |
---|
642 | g_uiAddCUDepth = 0; |
---|
643 | while( ( pcSPS->getMaxCUWidth() >> uiMaxCUDepthCorrect ) > ( 1 << ( pcSPS->getQuadtreeTULog2MinSize() + g_uiAddCUDepth ) ) ) |
---|
644 | { |
---|
645 | g_uiAddCUDepth++; |
---|
646 | } |
---|
647 | pcSPS->setMaxCUDepth( uiMaxCUDepthCorrect+g_uiAddCUDepth ); |
---|
648 | g_uiMaxCUDepth = uiMaxCUDepthCorrect+g_uiAddCUDepth; |
---|
649 | // BB: these parameters may be removed completly and replaced by the fixed values |
---|
650 | pcSPS->setMinTrDepth( 0 ); |
---|
651 | pcSPS->setMaxTrDepth( 1 ); |
---|
652 | READ_FLAG( uiCode, "scaling_list_enabled_flag" ); pcSPS->setScalingListFlag ( uiCode ); |
---|
653 | if(pcSPS->getScalingListFlag()) |
---|
654 | { |
---|
655 | READ_FLAG( uiCode, "sps_scaling_list_data_present_flag" ); pcSPS->setScalingListPresentFlag ( uiCode ); |
---|
656 | if(pcSPS->getScalingListPresentFlag ()) |
---|
657 | { |
---|
658 | parseScalingList( pcSPS->getScalingList() ); |
---|
659 | } |
---|
660 | } |
---|
661 | READ_FLAG( uiCode, "amp_enabled_flag" ); pcSPS->setUseAMP( uiCode ); |
---|
662 | READ_FLAG( uiCode, "sample_adaptive_offset_enabled_flag" ); pcSPS->setUseSAO ( uiCode ? true : false ); |
---|
663 | |
---|
664 | READ_FLAG( uiCode, "pcm_enabled_flag" ); pcSPS->setUsePCM( uiCode ? true : false ); |
---|
665 | if( pcSPS->getUsePCM() ) |
---|
666 | { |
---|
667 | READ_CODE( 4, uiCode, "pcm_sample_bit_depth_luma_minus1" ); pcSPS->setPCMBitDepthLuma ( 1 + uiCode ); |
---|
668 | READ_CODE( 4, uiCode, "pcm_sample_bit_depth_chroma_minus1" ); pcSPS->setPCMBitDepthChroma ( 1 + uiCode ); |
---|
669 | READ_UVLC( uiCode, "log2_min_pcm_luma_coding_block_size_minus3" ); pcSPS->setPCMLog2MinSize (uiCode+3); |
---|
670 | READ_UVLC( uiCode, "log2_diff_max_min_pcm_luma_coding_block_size" ); pcSPS->setPCMLog2MaxSize ( uiCode+pcSPS->getPCMLog2MinSize() ); |
---|
671 | READ_FLAG( uiCode, "pcm_loop_filter_disable_flag" ); pcSPS->setPCMFilterDisableFlag ( uiCode ? true : false ); |
---|
672 | } |
---|
673 | |
---|
674 | READ_UVLC( uiCode, "num_short_term_ref_pic_sets" ); |
---|
675 | pcSPS->createRPSList(uiCode); |
---|
676 | |
---|
677 | TComRPSList* rpsList = pcSPS->getRPSList(); |
---|
678 | TComReferencePictureSet* rps; |
---|
679 | |
---|
680 | for(UInt i=0; i< rpsList->getNumberOfReferencePictureSets(); i++) |
---|
681 | { |
---|
682 | rps = rpsList->getReferencePictureSet(i); |
---|
683 | parseShortTermRefPicSet(pcSPS,rps,i); |
---|
684 | } |
---|
685 | READ_FLAG( uiCode, "long_term_ref_pics_present_flag" ); pcSPS->setLongTermRefsPresent(uiCode); |
---|
686 | if (pcSPS->getLongTermRefsPresent()) |
---|
687 | { |
---|
688 | READ_UVLC( uiCode, "num_long_term_ref_pic_sps" ); |
---|
689 | pcSPS->setNumLongTermRefPicSPS(uiCode); |
---|
690 | for (UInt k = 0; k < pcSPS->getNumLongTermRefPicSPS(); k++) |
---|
691 | { |
---|
692 | READ_CODE( pcSPS->getBitsForPOC(), uiCode, "lt_ref_pic_poc_lsb_sps" ); |
---|
693 | pcSPS->setLtRefPicPocLsbSps(k, uiCode); |
---|
694 | READ_FLAG( uiCode, "used_by_curr_pic_lt_sps_flag[i]"); |
---|
695 | pcSPS->setUsedByCurrPicLtSPSFlag(k, uiCode?1:0); |
---|
696 | } |
---|
697 | } |
---|
698 | READ_FLAG( uiCode, "sps_temporal_mvp_enable_flag" ); pcSPS->setTMVPFlagsPresent(uiCode); |
---|
699 | |
---|
700 | READ_FLAG( uiCode, "sps_strong_intra_smoothing_enable_flag" ); pcSPS->setUseStrongIntraSmoothing(uiCode); |
---|
701 | |
---|
702 | READ_FLAG( uiCode, "vui_parameters_present_flag" ); pcSPS->setVuiParametersPresentFlag(uiCode); |
---|
703 | |
---|
704 | if (pcSPS->getVuiParametersPresentFlag()) |
---|
705 | { |
---|
706 | parseVUI(pcSPS->getVuiParameters(), pcSPS); |
---|
707 | } |
---|
708 | |
---|
709 | READ_FLAG( uiCode, "sps_extension_flag"); |
---|
710 | if (uiCode) |
---|
711 | { |
---|
712 | while ( xMoreRbspData() ) |
---|
713 | { |
---|
714 | READ_FLAG( uiCode, "sps_extension_data_flag"); |
---|
715 | } |
---|
716 | } |
---|
717 | } |
---|
718 | |
---|
719 | Void TDecCavlc::parseVPS(TComVPS* pcVPS) |
---|
720 | { |
---|
721 | UInt uiCode; |
---|
722 | |
---|
723 | READ_CODE( 4, uiCode, "vps_video_parameter_set_id" ); pcVPS->setVPSId( uiCode ); |
---|
724 | READ_CODE( 2, uiCode, "vps_reserved_three_2bits" ); assert(uiCode == 3); |
---|
725 | #if H_MV |
---|
726 | READ_CODE( 6, uiCode, "vps_max_layers_minus1" ); pcVPS->setMaxLayers( uiCode + 1 ); |
---|
727 | #else |
---|
728 | READ_CODE( 6, uiCode, "vps_reserved_zero_6bits" ); assert(uiCode == 0); |
---|
729 | #endif |
---|
730 | READ_CODE( 3, uiCode, "vps_max_sub_layers_minus1" ); pcVPS->setMaxTLayers( uiCode + 1 ); |
---|
731 | READ_FLAG( uiCode, "vps_temporal_id_nesting_flag" ); pcVPS->setTemporalNestingFlag( uiCode ? true:false ); |
---|
732 | assert (pcVPS->getMaxTLayers()>1||pcVPS->getTemporalNestingFlag()); |
---|
733 | #if H_MV |
---|
734 | READ_CODE( 16, uiCode, "vps_extension_offset" ); |
---|
735 | #else |
---|
736 | READ_CODE( 16, uiCode, "vps_reserved_ffff_16bits" ); assert(uiCode == 0xffff); |
---|
737 | #endif |
---|
738 | parsePTL ( pcVPS->getPTL(), true, pcVPS->getMaxTLayers()-1); |
---|
739 | #if SIGNAL_BITRATE_PICRATE_IN_VPS |
---|
740 | parseBitratePicRateInfo( pcVPS->getBitratePicrateInfo(), 0, pcVPS->getMaxTLayers() - 1); |
---|
741 | #endif |
---|
742 | UInt subLayerOrderingInfoPresentFlag; |
---|
743 | READ_FLAG(subLayerOrderingInfoPresentFlag, "vps_sub_layer_ordering_info_present_flag"); |
---|
744 | for(UInt i = 0; i <= pcVPS->getMaxTLayers()-1; i++) |
---|
745 | { |
---|
746 | READ_UVLC( uiCode, "vps_max_dec_pic_buffering[i]" ); pcVPS->setMaxDecPicBuffering( uiCode, i ); |
---|
747 | READ_UVLC( uiCode, "vps_num_reorder_pics[i]" ); pcVPS->setNumReorderPics( uiCode, i ); |
---|
748 | READ_UVLC( uiCode, "vps_max_latency_increase[i]" ); pcVPS->setMaxLatencyIncrease( uiCode, i ); |
---|
749 | |
---|
750 | if (!subLayerOrderingInfoPresentFlag) |
---|
751 | { |
---|
752 | for (i++; i <= pcVPS->getMaxTLayers()-1; i++) |
---|
753 | { |
---|
754 | pcVPS->setMaxDecPicBuffering(pcVPS->getMaxDecPicBuffering(0), i); |
---|
755 | pcVPS->setNumReorderPics(pcVPS->getNumReorderPics(0), i); |
---|
756 | pcVPS->setMaxLatencyIncrease(pcVPS->getMaxLatencyIncrease(0), i); |
---|
757 | } |
---|
758 | break; |
---|
759 | } |
---|
760 | } |
---|
761 | |
---|
762 | assert( pcVPS->getNumHrdParameters() < MAX_VPS_OP_SETS_PLUS1 ); |
---|
763 | #if H_MV |
---|
764 | assert( pcVPS->getMaxNuhLayerId() < MAX_VPS_NUH_LAYER_ID_PLUS1 ); |
---|
765 | READ_CODE( 6, uiCode, "vps_max_nuh_layer_id" ); pcVPS->setMaxNuhLayerId( uiCode ); |
---|
766 | #else |
---|
767 | assert( pcVPS->getMaxNuhReservedZeroLayerId() < MAX_VPS_NUH_RESERVED_ZERO_LAYER_ID_PLUS1 ); |
---|
768 | READ_CODE( 6, uiCode, "vps_max_nuh_reserved_zero_layer_id" ); pcVPS->setMaxNuhReservedZeroLayerId( uiCode ); |
---|
769 | #endif |
---|
770 | READ_UVLC( uiCode, "vps_max_op_sets_minus1" ); pcVPS->setMaxOpSets( uiCode + 1 ); |
---|
771 | for( UInt opsIdx = 1; opsIdx <= ( pcVPS->getMaxOpSets() - 1 ); opsIdx ++ ) |
---|
772 | { |
---|
773 | // Operation point set |
---|
774 | #if H_MV |
---|
775 | for( UInt i = 0; i <= pcVPS->getMaxNuhLayerId(); i ++ ) |
---|
776 | #else |
---|
777 | for( UInt i = 0; i <= pcVPS->getMaxNuhReservedZeroLayerId(); i ++ ) |
---|
778 | #endif |
---|
779 | { |
---|
780 | READ_FLAG( uiCode, "layer_id_included_flag[opsIdx][i]" ); pcVPS->setLayerIdIncludedFlag( uiCode == 1 ? true : false, opsIdx, i ); |
---|
781 | } |
---|
782 | } |
---|
783 | #if L0043_TIMING_INFO |
---|
784 | TimingInfo *timingInfo = pcVPS->getTimingInfo(); |
---|
785 | READ_FLAG( uiCode, "vps_timing_info_present_flag"); timingInfo->setTimingInfoPresentFlag (uiCode ? true : false); |
---|
786 | if(timingInfo->getTimingInfoPresentFlag()) |
---|
787 | { |
---|
788 | READ_CODE( 32, uiCode, "vps_num_units_in_tick"); timingInfo->setNumUnitsInTick (uiCode); |
---|
789 | READ_CODE( 32, uiCode, "vps_time_scale"); timingInfo->setTimeScale (uiCode); |
---|
790 | READ_FLAG( uiCode, "vps_poc_proportional_to_timing_flag"); timingInfo->setPocProportionalToTimingFlag(uiCode ? true : false); |
---|
791 | if(timingInfo->getPocProportionalToTimingFlag()) |
---|
792 | { |
---|
793 | READ_UVLC( uiCode, "vps_num_ticks_poc_diff_one_minus1"); timingInfo->setNumTicksPocDiffOneMinus1 (uiCode); |
---|
794 | } |
---|
795 | #endif |
---|
796 | READ_UVLC( uiCode, "vps_num_hrd_parameters" ); pcVPS->setNumHrdParameters( uiCode ); |
---|
797 | |
---|
798 | if( pcVPS->getNumHrdParameters() > 0 ) |
---|
799 | { |
---|
800 | pcVPS->createHrdParamBuffer(); |
---|
801 | } |
---|
802 | for( UInt i = 0; i < pcVPS->getNumHrdParameters(); i ++ ) |
---|
803 | { |
---|
804 | READ_UVLC( uiCode, "hrd_op_set_idx" ); pcVPS->setHrdOpSetIdx( uiCode, i ); |
---|
805 | if( i > 0 ) |
---|
806 | { |
---|
807 | READ_FLAG( uiCode, "cprms_present_flag[i]" ); pcVPS->setCprmsPresentFlag( uiCode == 1 ? true : false, i ); |
---|
808 | } |
---|
809 | parseHrdParameters(pcVPS->getHrdParameters(i), pcVPS->getCprmsPresentFlag( i ), pcVPS->getMaxTLayers() - 1); |
---|
810 | } |
---|
811 | #if L0043_TIMING_INFO |
---|
812 | } |
---|
813 | #endif |
---|
814 | READ_FLAG( uiCode, "vps_extension_flag" ); |
---|
815 | if (uiCode) |
---|
816 | { |
---|
817 | #if H_MV |
---|
818 | m_pcBitstream->readOutTrailingBits(); |
---|
819 | |
---|
820 | READ_FLAG( uiCode, "avc_base_layer_flag" ); pcVPS->setAvcBaseLayerFlag( uiCode == 1 ? true : false ); |
---|
821 | READ_FLAG( uiCode, "splitting_flag" ); pcVPS->setSplittingFlag( uiCode == 1 ? true : false ); |
---|
822 | |
---|
823 | // Parse scalability_mask[i] |
---|
824 | for( Int sIdx = 0; sIdx < MAX_NUM_SCALABILITY_TYPES; sIdx++ ) |
---|
825 | { |
---|
826 | READ_FLAG( uiCode, "scalability_mask[i]" ); pcVPS->setScalabilityMask( sIdx, uiCode == 1 ? true : false ); |
---|
827 | } |
---|
828 | |
---|
829 | Int numScalabilityTypes = pcVPS->getNumScalabilityTypes(); |
---|
830 | |
---|
831 | // Parse dimension_id_len_minus1[j] |
---|
832 | for( Int sIdx = 0; sIdx < numScalabilityTypes; sIdx++ ) |
---|
833 | { |
---|
834 | READ_CODE( 3, uiCode, "dimension_id_len_minus1[j]" ); pcVPS->setDimensionIdLen( sIdx, uiCode + 1 ); |
---|
835 | } |
---|
836 | |
---|
837 | // vps_nuh_layer_id_present_flag |
---|
838 | READ_FLAG( uiCode, "vps_nuh_layer_id_present_flag" ); pcVPS->setVpsNuhLayerIdPresentFlag( uiCode == 1 ? true : false ); |
---|
839 | |
---|
840 | // parse layer_id_in_nuh[i] and derive LayerIdInVps |
---|
841 | pcVPS->setLayerIdInNuh( 0, 0 ); pcVPS->setLayerIdInVps( 0, 0 ); |
---|
842 | |
---|
843 | for( Int layer = 1; layer <= pcVPS->getMaxLayers() - 1; layer++ ) |
---|
844 | { |
---|
845 | UInt layerIdInNuh; |
---|
846 | if ( pcVPS->getVpsNuhLayerIdPresentFlag() ) |
---|
847 | { |
---|
848 | READ_CODE( 6, uiCode, "layer_id_in_nuh[i]" ); layerIdInNuh = uiCode; |
---|
849 | } |
---|
850 | else |
---|
851 | { |
---|
852 | layerIdInNuh = layer; |
---|
853 | } |
---|
854 | |
---|
855 | pcVPS->setLayerIdInNuh( layer, layerIdInNuh ); |
---|
856 | pcVPS->setLayerIdInVps( layerIdInNuh, layer ); |
---|
857 | |
---|
858 | // parse dimension_id[i][j] |
---|
859 | for( Int sIdx = 0; sIdx < numScalabilityTypes; sIdx++ ) |
---|
860 | { |
---|
861 | READ_CODE( pcVPS->getDimensionIdLen( sIdx ), uiCode, "dimension_id[i][j]" ); pcVPS->setDimensionId( layer, sIdx, uiCode ); |
---|
862 | } |
---|
863 | } |
---|
864 | |
---|
865 | for( Int layerSet = 1; layerSet <= pcVPS->getMaxOpSets() - 1; layerSet++ ) |
---|
866 | { |
---|
867 | READ_FLAG( uiCode, "vps_profile_present_flag[lsIdx]" ); pcVPS->setVpsProfilePresentFlag( layerSet, uiCode == 1 ? true : false ); |
---|
868 | if( pcVPS->getVpsProfilePresentFlag( layerSet ) == false ) |
---|
869 | { |
---|
870 | READ_UVLC( uiCode, "profile_layer_set_ref_minus1[lsIdx]" ); pcVPS->setProfileLayerSetRefMinus1( layerSet, uiCode ); |
---|
871 | } |
---|
872 | |
---|
873 | parsePTL ( pcVPS->getPTL( layerSet ), pcVPS->getVpsProfilePresentFlag( layerSet ), pcVPS->getMaxTLayers()-1); |
---|
874 | if( pcVPS->getVpsProfilePresentFlag( layerSet ) == false ) |
---|
875 | { |
---|
876 | TComPTL temp = *pcVPS->getPTL( layerSet ); |
---|
877 | *pcVPS->getPTL( layerSet ) = *pcVPS->getPTL( pcVPS->getProfileLayerSetRefMinus1( layerSet ) + 1 ); |
---|
878 | pcVPS->getPTL( layerSet )->copyLevelFrom( &temp ); |
---|
879 | } |
---|
880 | } |
---|
881 | |
---|
882 | READ_UVLC( uiCode, "num_output_layer_sets" ); pcVPS->setNumOutputLayerSets( uiCode ); |
---|
883 | |
---|
884 | for( Int layerSet = 0; layerSet < pcVPS->getNumOutputLayerSets(); layerSet++ ) |
---|
885 | { |
---|
886 | READ_UVLC( uiCode, "output_layer_set_idx[i]" ); pcVPS->setOutputLayerSetIdx( layerSet, uiCode ); |
---|
887 | for( Int layer = 0; layer <= pcVPS->getMaxNuhLayerId(); layer++ ) |
---|
888 | { |
---|
889 | if( pcVPS->getLayerIdIncludedFlag( pcVPS->getOutputLayerSetIdx( layerSet ), layer ) == true ) |
---|
890 | { |
---|
891 | READ_FLAG( uiCode, "output_layer_flag" ); pcVPS->setOutputLayerFlag( layerSet, layer, uiCode == 1 ? true : false ); |
---|
892 | } |
---|
893 | } |
---|
894 | } |
---|
895 | |
---|
896 | for( Int i = 1; i <= pcVPS->getMaxLayers() - 1; i++ ) |
---|
897 | { |
---|
898 | for( Int j = 0; j < i; j++ ) |
---|
899 | { |
---|
900 | READ_FLAG( uiCode, "direct_dependency_flag[i][j]" ); pcVPS->setDirectDependencyFlag( i, j, uiCode ); |
---|
901 | } |
---|
902 | } |
---|
903 | |
---|
904 | READ_FLAG( uiCode, "vps_extension2_flag" ); |
---|
905 | if (uiCode) |
---|
906 | { |
---|
907 | while ( xMoreRbspData() ) |
---|
908 | { |
---|
909 | READ_FLAG( uiCode, "vps_extension2_data_flag"); |
---|
910 | } |
---|
911 | } |
---|
912 | |
---|
913 | pcVPS->checkVPSExtensionSyntax(); |
---|
914 | |
---|
915 | pcVPS->calcIvRefLayers(); |
---|
916 | |
---|
917 | #else |
---|
918 | while ( xMoreRbspData() ) |
---|
919 | { |
---|
920 | READ_FLAG( uiCode, "vps_extension_data_flag"); |
---|
921 | } |
---|
922 | #endif |
---|
923 | } |
---|
924 | |
---|
925 | return; |
---|
926 | } |
---|
927 | |
---|
928 | Void TDecCavlc::parseSliceHeader (TComSlice*& rpcSlice, ParameterSetManagerDecoder *parameterSetManager) |
---|
929 | { |
---|
930 | UInt uiCode; |
---|
931 | Int iCode; |
---|
932 | |
---|
933 | #if ENC_DEC_TRACE |
---|
934 | xTraceSliceHeader(rpcSlice); |
---|
935 | #endif |
---|
936 | TComPPS* pps = NULL; |
---|
937 | TComSPS* sps = NULL; |
---|
938 | #if H_MV |
---|
939 | TComVPS* vps = NULL; |
---|
940 | #endif |
---|
941 | |
---|
942 | UInt firstSliceSegmentInPic; |
---|
943 | READ_FLAG( firstSliceSegmentInPic, "first_slice_segment_in_pic_flag" ); |
---|
944 | if( rpcSlice->getRapPicFlag()) |
---|
945 | { |
---|
946 | READ_FLAG( uiCode, "no_output_of_prior_pics_flag" ); //ignored |
---|
947 | } |
---|
948 | READ_UVLC ( uiCode, "slice_pic_parameter_set_id" ); rpcSlice->setPPSId(uiCode); |
---|
949 | pps = parameterSetManager->getPrefetchedPPS(uiCode); |
---|
950 | //!KS: need to add error handling code here, if PPS is not available |
---|
951 | assert(pps!=0); |
---|
952 | sps = parameterSetManager->getPrefetchedSPS(pps->getSPSId()); |
---|
953 | //!KS: need to add error handling code here, if SPS is not available |
---|
954 | assert(sps!=0); |
---|
955 | #if H_MV |
---|
956 | vps = parameterSetManager->getPrefetchedVPS(sps->getVPSId()); |
---|
957 | assert(vps!=0); |
---|
958 | rpcSlice->setVPS(vps); |
---|
959 | #endif |
---|
960 | rpcSlice->setSPS(sps); |
---|
961 | rpcSlice->setPPS(pps); |
---|
962 | if( pps->getDependentSliceSegmentsEnabledFlag() && ( !firstSliceSegmentInPic )) |
---|
963 | { |
---|
964 | READ_FLAG( uiCode, "dependent_slice_segment_flag" ); rpcSlice->setDependentSliceSegmentFlag(uiCode ? true : false); |
---|
965 | } |
---|
966 | else |
---|
967 | { |
---|
968 | rpcSlice->setDependentSliceSegmentFlag(false); |
---|
969 | } |
---|
970 | Int numCTUs = ((sps->getPicWidthInLumaSamples()+sps->getMaxCUWidth()-1)/sps->getMaxCUWidth())*((sps->getPicHeightInLumaSamples()+sps->getMaxCUHeight()-1)/sps->getMaxCUHeight()); |
---|
971 | Int maxParts = (1<<(sps->getMaxCUDepth()<<1)); |
---|
972 | UInt sliceSegmentAddress = 0; |
---|
973 | Int bitsSliceSegmentAddress = 0; |
---|
974 | while(numCTUs>(1<<bitsSliceSegmentAddress)) |
---|
975 | { |
---|
976 | bitsSliceSegmentAddress++; |
---|
977 | } |
---|
978 | |
---|
979 | if(!firstSliceSegmentInPic) |
---|
980 | { |
---|
981 | READ_CODE( bitsSliceSegmentAddress, sliceSegmentAddress, "slice_segment_address" ); |
---|
982 | } |
---|
983 | //set uiCode to equal slice start address (or dependent slice start address) |
---|
984 | Int startCuAddress = maxParts*sliceSegmentAddress; |
---|
985 | rpcSlice->setSliceSegmentCurStartCUAddr( startCuAddress ); |
---|
986 | rpcSlice->setSliceSegmentCurEndCUAddr(numCTUs*maxParts); |
---|
987 | |
---|
988 | if (rpcSlice->getDependentSliceSegmentFlag()) |
---|
989 | { |
---|
990 | rpcSlice->setNextSlice ( false ); |
---|
991 | rpcSlice->setNextSliceSegment ( true ); |
---|
992 | } |
---|
993 | else |
---|
994 | { |
---|
995 | rpcSlice->setNextSlice ( true ); |
---|
996 | rpcSlice->setNextSliceSegment ( false ); |
---|
997 | |
---|
998 | rpcSlice->setSliceCurStartCUAddr(startCuAddress); |
---|
999 | rpcSlice->setSliceCurEndCUAddr(numCTUs*maxParts); |
---|
1000 | } |
---|
1001 | |
---|
1002 | if(!rpcSlice->getDependentSliceSegmentFlag()) |
---|
1003 | { |
---|
1004 | for (Int i = 0; i < rpcSlice->getPPS()->getNumExtraSliceHeaderBits(); i++) |
---|
1005 | { |
---|
1006 | READ_FLAG(uiCode, "slice_reserved_undetermined_flag[]"); // ignored |
---|
1007 | } |
---|
1008 | |
---|
1009 | READ_UVLC ( uiCode, "slice_type" ); rpcSlice->setSliceType((SliceType)uiCode); |
---|
1010 | if( pps->getOutputFlagPresentFlag() ) |
---|
1011 | { |
---|
1012 | READ_FLAG( uiCode, "pic_output_flag" ); rpcSlice->setPicOutputFlag( uiCode ? true : false ); |
---|
1013 | } |
---|
1014 | else |
---|
1015 | { |
---|
1016 | rpcSlice->setPicOutputFlag( true ); |
---|
1017 | } |
---|
1018 | // in the first version chroma_format_idc is equal to one, thus colour_plane_id will not be present |
---|
1019 | assert (sps->getChromaFormatIdc() == 1 ); |
---|
1020 | // if( separate_colour_plane_flag == 1 ) |
---|
1021 | // colour_plane_id u(2) |
---|
1022 | |
---|
1023 | if( rpcSlice->getIdrPicFlag() ) |
---|
1024 | { |
---|
1025 | rpcSlice->setPOC(0); |
---|
1026 | TComReferencePictureSet* rps = rpcSlice->getLocalRPS(); |
---|
1027 | rps->setNumberOfNegativePictures(0); |
---|
1028 | rps->setNumberOfPositivePictures(0); |
---|
1029 | rps->setNumberOfLongtermPictures(0); |
---|
1030 | rps->setNumberOfPictures(0); |
---|
1031 | rpcSlice->setRPS(rps); |
---|
1032 | } |
---|
1033 | else |
---|
1034 | { |
---|
1035 | READ_CODE(sps->getBitsForPOC(), uiCode, "pic_order_cnt_lsb"); |
---|
1036 | Int iPOClsb = uiCode; |
---|
1037 | Int iPrevPOC = rpcSlice->getPrevPOC(); |
---|
1038 | Int iMaxPOClsb = 1<< sps->getBitsForPOC(); |
---|
1039 | Int iPrevPOClsb = iPrevPOC%iMaxPOClsb; |
---|
1040 | Int iPrevPOCmsb = iPrevPOC-iPrevPOClsb; |
---|
1041 | Int iPOCmsb; |
---|
1042 | if( ( iPOClsb < iPrevPOClsb ) && ( ( iPrevPOClsb - iPOClsb ) >= ( iMaxPOClsb / 2 ) ) ) |
---|
1043 | { |
---|
1044 | iPOCmsb = iPrevPOCmsb + iMaxPOClsb; |
---|
1045 | } |
---|
1046 | else if( (iPOClsb > iPrevPOClsb ) && ( (iPOClsb - iPrevPOClsb ) > ( iMaxPOClsb / 2 ) ) ) |
---|
1047 | { |
---|
1048 | iPOCmsb = iPrevPOCmsb - iMaxPOClsb; |
---|
1049 | } |
---|
1050 | else |
---|
1051 | { |
---|
1052 | iPOCmsb = iPrevPOCmsb; |
---|
1053 | } |
---|
1054 | if ( rpcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA |
---|
1055 | || rpcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLANT |
---|
1056 | || rpcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_N_LP ) |
---|
1057 | { |
---|
1058 | // For BLA picture types, POCmsb is set to 0. |
---|
1059 | iPOCmsb = 0; |
---|
1060 | } |
---|
1061 | rpcSlice->setPOC (iPOCmsb+iPOClsb); |
---|
1062 | |
---|
1063 | TComReferencePictureSet* rps; |
---|
1064 | READ_FLAG( uiCode, "short_term_ref_pic_set_sps_flag" ); |
---|
1065 | if(uiCode == 0) // use short-term reference picture set explicitly signalled in slice header |
---|
1066 | { |
---|
1067 | rps = rpcSlice->getLocalRPS(); |
---|
1068 | parseShortTermRefPicSet(sps,rps, sps->getRPSList()->getNumberOfReferencePictureSets()); |
---|
1069 | rpcSlice->setRPS(rps); |
---|
1070 | } |
---|
1071 | else // use reference to short-term reference picture set in PPS |
---|
1072 | { |
---|
1073 | Int numBits = 0; |
---|
1074 | while ((1 << numBits) < rpcSlice->getSPS()->getRPSList()->getNumberOfReferencePictureSets()) |
---|
1075 | { |
---|
1076 | numBits++; |
---|
1077 | } |
---|
1078 | if (numBits > 0) |
---|
1079 | { |
---|
1080 | READ_CODE( numBits, uiCode, "short_term_ref_pic_set_idx"); |
---|
1081 | } |
---|
1082 | else |
---|
1083 | { |
---|
1084 | uiCode = 0; |
---|
1085 | } |
---|
1086 | rpcSlice->setRPS(sps->getRPSList()->getReferencePictureSet(uiCode)); |
---|
1087 | |
---|
1088 | rps = rpcSlice->getRPS(); |
---|
1089 | } |
---|
1090 | if(sps->getLongTermRefsPresent()) |
---|
1091 | { |
---|
1092 | Int offset = rps->getNumberOfNegativePictures()+rps->getNumberOfPositivePictures(); |
---|
1093 | UInt numOfLtrp = 0; |
---|
1094 | UInt numLtrpInSPS = 0; |
---|
1095 | if (rpcSlice->getSPS()->getNumLongTermRefPicSPS() > 0) |
---|
1096 | { |
---|
1097 | READ_UVLC( uiCode, "num_long_term_sps"); |
---|
1098 | numLtrpInSPS = uiCode; |
---|
1099 | numOfLtrp += numLtrpInSPS; |
---|
1100 | rps->setNumberOfLongtermPictures(numOfLtrp); |
---|
1101 | } |
---|
1102 | Int bitsForLtrpInSPS = 0; |
---|
1103 | while (rpcSlice->getSPS()->getNumLongTermRefPicSPS() > (1 << bitsForLtrpInSPS)) |
---|
1104 | { |
---|
1105 | bitsForLtrpInSPS++; |
---|
1106 | } |
---|
1107 | READ_UVLC( uiCode, "num_long_term_pics"); rps->setNumberOfLongtermPictures(uiCode); |
---|
1108 | numOfLtrp += uiCode; |
---|
1109 | rps->setNumberOfLongtermPictures(numOfLtrp); |
---|
1110 | Int maxPicOrderCntLSB = 1 << rpcSlice->getSPS()->getBitsForPOC(); |
---|
1111 | Int prevLSB = 0, prevDeltaMSB = 0, deltaPocMSBCycleLT = 0;; |
---|
1112 | for(Int j=offset+rps->getNumberOfLongtermPictures()-1, k = 0; k < numOfLtrp; j--, k++) |
---|
1113 | { |
---|
1114 | Int pocLsbLt; |
---|
1115 | if (k < numLtrpInSPS) |
---|
1116 | { |
---|
1117 | uiCode = 0; |
---|
1118 | if (bitsForLtrpInSPS > 0) |
---|
1119 | { |
---|
1120 | READ_CODE(bitsForLtrpInSPS, uiCode, "lt_idx_sps[i]"); |
---|
1121 | } |
---|
1122 | Int usedByCurrFromSPS=rpcSlice->getSPS()->getUsedByCurrPicLtSPSFlag(uiCode); |
---|
1123 | |
---|
1124 | pocLsbLt = rpcSlice->getSPS()->getLtRefPicPocLsbSps(uiCode); |
---|
1125 | rps->setUsed(j,usedByCurrFromSPS); |
---|
1126 | } |
---|
1127 | else |
---|
1128 | { |
---|
1129 | READ_CODE(rpcSlice->getSPS()->getBitsForPOC(), uiCode, "poc_lsb_lt"); pocLsbLt= uiCode; |
---|
1130 | READ_FLAG( uiCode, "used_by_curr_pic_lt_flag"); rps->setUsed(j,uiCode); |
---|
1131 | } |
---|
1132 | READ_FLAG(uiCode,"delta_poc_msb_present_flag"); |
---|
1133 | Bool mSBPresentFlag = uiCode ? true : false; |
---|
1134 | if(mSBPresentFlag) |
---|
1135 | { |
---|
1136 | READ_UVLC( uiCode, "delta_poc_msb_cycle_lt[i]" ); |
---|
1137 | Bool deltaFlag = false; |
---|
1138 | // First LTRP || First LTRP from SH || curr LSB != prev LSB |
---|
1139 | if( (j == offset+rps->getNumberOfLongtermPictures()-1) || (j == offset+(numOfLtrp-numLtrpInSPS)-1) || (pocLsbLt != prevLSB) ) |
---|
1140 | { |
---|
1141 | deltaFlag = true; |
---|
1142 | } |
---|
1143 | if(deltaFlag) |
---|
1144 | { |
---|
1145 | deltaPocMSBCycleLT = uiCode; |
---|
1146 | } |
---|
1147 | else |
---|
1148 | { |
---|
1149 | deltaPocMSBCycleLT = uiCode + prevDeltaMSB; |
---|
1150 | } |
---|
1151 | |
---|
1152 | Int pocLTCurr = rpcSlice->getPOC() - deltaPocMSBCycleLT * maxPicOrderCntLSB |
---|
1153 | - iPOClsb + pocLsbLt; |
---|
1154 | rps->setPOC (j, pocLTCurr); |
---|
1155 | rps->setDeltaPOC(j, - rpcSlice->getPOC() + pocLTCurr); |
---|
1156 | rps->setCheckLTMSBPresent(j,true); |
---|
1157 | } |
---|
1158 | else |
---|
1159 | { |
---|
1160 | rps->setPOC (j, pocLsbLt); |
---|
1161 | rps->setDeltaPOC(j, - rpcSlice->getPOC() + pocLsbLt); |
---|
1162 | rps->setCheckLTMSBPresent(j,false); |
---|
1163 | } |
---|
1164 | prevLSB = pocLsbLt; |
---|
1165 | prevDeltaMSB = deltaPocMSBCycleLT; |
---|
1166 | } |
---|
1167 | offset += rps->getNumberOfLongtermPictures(); |
---|
1168 | rps->setNumberOfPictures(offset); |
---|
1169 | } |
---|
1170 | if ( rpcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA |
---|
1171 | || rpcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLANT |
---|
1172 | || rpcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_N_LP ) |
---|
1173 | { |
---|
1174 | // In the case of BLA picture types, rps data is read from slice header but ignored |
---|
1175 | rps = rpcSlice->getLocalRPS(); |
---|
1176 | rps->setNumberOfNegativePictures(0); |
---|
1177 | rps->setNumberOfPositivePictures(0); |
---|
1178 | rps->setNumberOfLongtermPictures(0); |
---|
1179 | rps->setNumberOfPictures(0); |
---|
1180 | rpcSlice->setRPS(rps); |
---|
1181 | } |
---|
1182 | if (rpcSlice->getSPS()->getTMVPFlagsPresent()) |
---|
1183 | { |
---|
1184 | READ_FLAG( uiCode, "slice_temporal_mvp_enable_flag" ); |
---|
1185 | rpcSlice->setEnableTMVPFlag( uiCode == 1 ? true : false ); |
---|
1186 | } |
---|
1187 | else |
---|
1188 | { |
---|
1189 | rpcSlice->setEnableTMVPFlag(false); |
---|
1190 | } |
---|
1191 | } |
---|
1192 | if(sps->getUseSAO()) |
---|
1193 | { |
---|
1194 | READ_FLAG(uiCode, "slice_sao_luma_flag"); rpcSlice->setSaoEnabledFlag((Bool)uiCode); |
---|
1195 | READ_FLAG(uiCode, "slice_sao_chroma_flag"); rpcSlice->setSaoEnabledFlagChroma((Bool)uiCode); |
---|
1196 | } |
---|
1197 | |
---|
1198 | if (rpcSlice->getIdrPicFlag()) |
---|
1199 | { |
---|
1200 | rpcSlice->setEnableTMVPFlag(false); |
---|
1201 | } |
---|
1202 | if (!rpcSlice->isIntra()) |
---|
1203 | { |
---|
1204 | |
---|
1205 | READ_FLAG( uiCode, "num_ref_idx_active_override_flag"); |
---|
1206 | if (uiCode) |
---|
1207 | { |
---|
1208 | READ_UVLC (uiCode, "num_ref_idx_l0_active_minus1" ); rpcSlice->setNumRefIdx( REF_PIC_LIST_0, uiCode + 1 ); |
---|
1209 | if (rpcSlice->isInterB()) |
---|
1210 | { |
---|
1211 | READ_UVLC (uiCode, "num_ref_idx_l1_active_minus1" ); rpcSlice->setNumRefIdx( REF_PIC_LIST_1, uiCode + 1 ); |
---|
1212 | } |
---|
1213 | else |
---|
1214 | { |
---|
1215 | rpcSlice->setNumRefIdx(REF_PIC_LIST_1, 0); |
---|
1216 | } |
---|
1217 | } |
---|
1218 | else |
---|
1219 | { |
---|
1220 | rpcSlice->setNumRefIdx(REF_PIC_LIST_0, rpcSlice->getPPS()->getNumRefIdxL0DefaultActive()); |
---|
1221 | if (rpcSlice->isInterB()) |
---|
1222 | { |
---|
1223 | rpcSlice->setNumRefIdx(REF_PIC_LIST_1, rpcSlice->getPPS()->getNumRefIdxL1DefaultActive()); |
---|
1224 | } |
---|
1225 | else |
---|
1226 | { |
---|
1227 | rpcSlice->setNumRefIdx(REF_PIC_LIST_1,0); |
---|
1228 | } |
---|
1229 | } |
---|
1230 | } |
---|
1231 | // } |
---|
1232 | TComRefPicListModification* refPicListModification = rpcSlice->getRefPicListModification(); |
---|
1233 | if(!rpcSlice->isIntra()) |
---|
1234 | { |
---|
1235 | if( !rpcSlice->getPPS()->getListsModificationPresentFlag() || rpcSlice->getNumRpsCurrTempList() <= 1 ) |
---|
1236 | { |
---|
1237 | refPicListModification->setRefPicListModificationFlagL0( 0 ); |
---|
1238 | } |
---|
1239 | else |
---|
1240 | { |
---|
1241 | READ_FLAG( uiCode, "ref_pic_list_modification_flag_l0" ); refPicListModification->setRefPicListModificationFlagL0( uiCode ? 1 : 0 ); |
---|
1242 | } |
---|
1243 | |
---|
1244 | if(refPicListModification->getRefPicListModificationFlagL0()) |
---|
1245 | { |
---|
1246 | uiCode = 0; |
---|
1247 | Int i = 0; |
---|
1248 | Int numRpsCurrTempList0 = rpcSlice->getNumRpsCurrTempList(); |
---|
1249 | if ( numRpsCurrTempList0 > 1 ) |
---|
1250 | { |
---|
1251 | Int length = 1; |
---|
1252 | numRpsCurrTempList0 --; |
---|
1253 | while ( numRpsCurrTempList0 >>= 1) |
---|
1254 | { |
---|
1255 | length ++; |
---|
1256 | } |
---|
1257 | for (i = 0; i < rpcSlice->getNumRefIdx(REF_PIC_LIST_0); i ++) |
---|
1258 | { |
---|
1259 | READ_CODE( length, uiCode, "list_entry_l0" ); |
---|
1260 | refPicListModification->setRefPicSetIdxL0(i, uiCode ); |
---|
1261 | } |
---|
1262 | } |
---|
1263 | else |
---|
1264 | { |
---|
1265 | for (i = 0; i < rpcSlice->getNumRefIdx(REF_PIC_LIST_0); i ++) |
---|
1266 | { |
---|
1267 | refPicListModification->setRefPicSetIdxL0(i, 0 ); |
---|
1268 | } |
---|
1269 | } |
---|
1270 | } |
---|
1271 | } |
---|
1272 | else |
---|
1273 | { |
---|
1274 | refPicListModification->setRefPicListModificationFlagL0(0); |
---|
1275 | } |
---|
1276 | if(rpcSlice->isInterB()) |
---|
1277 | { |
---|
1278 | if( !rpcSlice->getPPS()->getListsModificationPresentFlag() || rpcSlice->getNumRpsCurrTempList() <= 1 ) |
---|
1279 | { |
---|
1280 | refPicListModification->setRefPicListModificationFlagL1( 0 ); |
---|
1281 | } |
---|
1282 | else |
---|
1283 | { |
---|
1284 | READ_FLAG( uiCode, "ref_pic_list_modification_flag_l1" ); refPicListModification->setRefPicListModificationFlagL1( uiCode ? 1 : 0 ); |
---|
1285 | } |
---|
1286 | if(refPicListModification->getRefPicListModificationFlagL1()) |
---|
1287 | { |
---|
1288 | uiCode = 0; |
---|
1289 | Int i = 0; |
---|
1290 | Int numRpsCurrTempList1 = rpcSlice->getNumRpsCurrTempList(); |
---|
1291 | if ( numRpsCurrTempList1 > 1 ) |
---|
1292 | { |
---|
1293 | Int length = 1; |
---|
1294 | numRpsCurrTempList1 --; |
---|
1295 | while ( numRpsCurrTempList1 >>= 1) |
---|
1296 | { |
---|
1297 | length ++; |
---|
1298 | } |
---|
1299 | for (i = 0; i < rpcSlice->getNumRefIdx(REF_PIC_LIST_1); i ++) |
---|
1300 | { |
---|
1301 | READ_CODE( length, uiCode, "list_entry_l1" ); |
---|
1302 | refPicListModification->setRefPicSetIdxL1(i, uiCode ); |
---|
1303 | } |
---|
1304 | } |
---|
1305 | else |
---|
1306 | { |
---|
1307 | for (i = 0; i < rpcSlice->getNumRefIdx(REF_PIC_LIST_1); i ++) |
---|
1308 | { |
---|
1309 | refPicListModification->setRefPicSetIdxL1(i, 0 ); |
---|
1310 | } |
---|
1311 | } |
---|
1312 | } |
---|
1313 | } |
---|
1314 | else |
---|
1315 | { |
---|
1316 | refPicListModification->setRefPicListModificationFlagL1(0); |
---|
1317 | } |
---|
1318 | if (rpcSlice->isInterB()) |
---|
1319 | { |
---|
1320 | READ_FLAG( uiCode, "mvd_l1_zero_flag" ); rpcSlice->setMvdL1ZeroFlag( (uiCode ? true : false) ); |
---|
1321 | } |
---|
1322 | |
---|
1323 | rpcSlice->setCabacInitFlag( false ); // default |
---|
1324 | if(pps->getCabacInitPresentFlag() && !rpcSlice->isIntra()) |
---|
1325 | { |
---|
1326 | READ_FLAG(uiCode, "cabac_init_flag"); |
---|
1327 | rpcSlice->setCabacInitFlag( uiCode ? true : false ); |
---|
1328 | } |
---|
1329 | |
---|
1330 | if ( rpcSlice->getEnableTMVPFlag() ) |
---|
1331 | { |
---|
1332 | if ( rpcSlice->getSliceType() == B_SLICE ) |
---|
1333 | { |
---|
1334 | READ_FLAG( uiCode, "collocated_from_l0_flag" ); |
---|
1335 | rpcSlice->setColFromL0Flag(uiCode); |
---|
1336 | } |
---|
1337 | else |
---|
1338 | { |
---|
1339 | rpcSlice->setColFromL0Flag( 1 ); |
---|
1340 | } |
---|
1341 | |
---|
1342 | if ( rpcSlice->getSliceType() != I_SLICE && |
---|
1343 | ((rpcSlice->getColFromL0Flag() == 1 && rpcSlice->getNumRefIdx(REF_PIC_LIST_0) > 1)|| |
---|
1344 | (rpcSlice->getColFromL0Flag() == 0 && rpcSlice->getNumRefIdx(REF_PIC_LIST_1) > 1))) |
---|
1345 | { |
---|
1346 | READ_UVLC( uiCode, "collocated_ref_idx" ); |
---|
1347 | rpcSlice->setColRefIdx(uiCode); |
---|
1348 | } |
---|
1349 | else |
---|
1350 | { |
---|
1351 | rpcSlice->setColRefIdx(0); |
---|
1352 | } |
---|
1353 | } |
---|
1354 | if ( (pps->getUseWP() && rpcSlice->getSliceType()==P_SLICE) || (pps->getWPBiPred() && rpcSlice->getSliceType()==B_SLICE) ) |
---|
1355 | { |
---|
1356 | xParsePredWeightTable(rpcSlice); |
---|
1357 | rpcSlice->initWpScaling(); |
---|
1358 | } |
---|
1359 | if (!rpcSlice->isIntra()) |
---|
1360 | { |
---|
1361 | READ_UVLC( uiCode, "five_minus_max_num_merge_cand"); |
---|
1362 | rpcSlice->setMaxNumMergeCand(MRG_MAX_NUM_CANDS - uiCode); |
---|
1363 | } |
---|
1364 | |
---|
1365 | READ_SVLC( iCode, "slice_qp_delta" ); |
---|
1366 | rpcSlice->setSliceQp (26 + pps->getPicInitQPMinus26() + iCode); |
---|
1367 | |
---|
1368 | assert( rpcSlice->getSliceQp() >= -sps->getQpBDOffsetY() ); |
---|
1369 | assert( rpcSlice->getSliceQp() <= 51 ); |
---|
1370 | |
---|
1371 | if (rpcSlice->getPPS()->getSliceChromaQpFlag()) |
---|
1372 | { |
---|
1373 | READ_SVLC( iCode, "slice_qp_delta_cb" ); |
---|
1374 | rpcSlice->setSliceQpDeltaCb( iCode ); |
---|
1375 | assert( rpcSlice->getSliceQpDeltaCb() >= -12 ); |
---|
1376 | assert( rpcSlice->getSliceQpDeltaCb() <= 12 ); |
---|
1377 | assert( (rpcSlice->getPPS()->getChromaCbQpOffset() + rpcSlice->getSliceQpDeltaCb()) >= -12 ); |
---|
1378 | assert( (rpcSlice->getPPS()->getChromaCbQpOffset() + rpcSlice->getSliceQpDeltaCb()) <= 12 ); |
---|
1379 | |
---|
1380 | READ_SVLC( iCode, "slice_qp_delta_cr" ); |
---|
1381 | rpcSlice->setSliceQpDeltaCr( iCode ); |
---|
1382 | assert( rpcSlice->getSliceQpDeltaCr() >= -12 ); |
---|
1383 | assert( rpcSlice->getSliceQpDeltaCr() <= 12 ); |
---|
1384 | assert( (rpcSlice->getPPS()->getChromaCrQpOffset() + rpcSlice->getSliceQpDeltaCr()) >= -12 ); |
---|
1385 | assert( (rpcSlice->getPPS()->getChromaCrQpOffset() + rpcSlice->getSliceQpDeltaCr()) <= 12 ); |
---|
1386 | } |
---|
1387 | |
---|
1388 | if (rpcSlice->getPPS()->getDeblockingFilterControlPresentFlag()) |
---|
1389 | { |
---|
1390 | if(rpcSlice->getPPS()->getDeblockingFilterOverrideEnabledFlag()) |
---|
1391 | { |
---|
1392 | READ_FLAG ( uiCode, "deblocking_filter_override_flag" ); rpcSlice->setDeblockingFilterOverrideFlag(uiCode ? true : false); |
---|
1393 | } |
---|
1394 | else |
---|
1395 | { |
---|
1396 | rpcSlice->setDeblockingFilterOverrideFlag(0); |
---|
1397 | } |
---|
1398 | if(rpcSlice->getDeblockingFilterOverrideFlag()) |
---|
1399 | { |
---|
1400 | READ_FLAG ( uiCode, "slice_disable_deblocking_filter_flag" ); rpcSlice->setDeblockingFilterDisable(uiCode ? 1 : 0); |
---|
1401 | if(!rpcSlice->getDeblockingFilterDisable()) |
---|
1402 | { |
---|
1403 | READ_SVLC( iCode, "beta_offset_div2" ); rpcSlice->setDeblockingFilterBetaOffsetDiv2(iCode); |
---|
1404 | READ_SVLC( iCode, "tc_offset_div2" ); rpcSlice->setDeblockingFilterTcOffsetDiv2(iCode); |
---|
1405 | } |
---|
1406 | } |
---|
1407 | else |
---|
1408 | { |
---|
1409 | rpcSlice->setDeblockingFilterDisable ( rpcSlice->getPPS()->getPicDisableDeblockingFilterFlag() ); |
---|
1410 | rpcSlice->setDeblockingFilterBetaOffsetDiv2( rpcSlice->getPPS()->getDeblockingFilterBetaOffsetDiv2() ); |
---|
1411 | rpcSlice->setDeblockingFilterTcOffsetDiv2 ( rpcSlice->getPPS()->getDeblockingFilterTcOffsetDiv2() ); |
---|
1412 | } |
---|
1413 | } |
---|
1414 | else |
---|
1415 | { |
---|
1416 | rpcSlice->setDeblockingFilterDisable ( false ); |
---|
1417 | rpcSlice->setDeblockingFilterBetaOffsetDiv2( 0 ); |
---|
1418 | rpcSlice->setDeblockingFilterTcOffsetDiv2 ( 0 ); |
---|
1419 | } |
---|
1420 | |
---|
1421 | Bool isSAOEnabled = (!rpcSlice->getSPS()->getUseSAO())?(false):(rpcSlice->getSaoEnabledFlag()||rpcSlice->getSaoEnabledFlagChroma()); |
---|
1422 | Bool isDBFEnabled = (!rpcSlice->getDeblockingFilterDisable()); |
---|
1423 | |
---|
1424 | if(rpcSlice->getPPS()->getLoopFilterAcrossSlicesEnabledFlag() && ( isSAOEnabled || isDBFEnabled )) |
---|
1425 | { |
---|
1426 | READ_FLAG( uiCode, "slice_loop_filter_across_slices_enabled_flag"); |
---|
1427 | } |
---|
1428 | else |
---|
1429 | { |
---|
1430 | uiCode = rpcSlice->getPPS()->getLoopFilterAcrossSlicesEnabledFlag()?1:0; |
---|
1431 | } |
---|
1432 | rpcSlice->setLFCrossSliceBoundaryFlag( (uiCode==1)?true:false); |
---|
1433 | |
---|
1434 | } |
---|
1435 | |
---|
1436 | if( pps->getTilesEnabledFlag() || pps->getEntropyCodingSyncEnabledFlag() ) |
---|
1437 | { |
---|
1438 | UInt *entryPointOffset = NULL; |
---|
1439 | UInt numEntryPointOffsets, offsetLenMinus1; |
---|
1440 | |
---|
1441 | READ_UVLC(numEntryPointOffsets, "num_entry_point_offsets"); rpcSlice->setNumEntryPointOffsets ( numEntryPointOffsets ); |
---|
1442 | if (numEntryPointOffsets>0) |
---|
1443 | { |
---|
1444 | READ_UVLC(offsetLenMinus1, "offset_len_minus1"); |
---|
1445 | } |
---|
1446 | entryPointOffset = new UInt[numEntryPointOffsets]; |
---|
1447 | for (UInt idx=0; idx<numEntryPointOffsets; idx++) |
---|
1448 | { |
---|
1449 | #if L0116_ENTRY_POINT |
---|
1450 | READ_CODE(offsetLenMinus1+1, uiCode, "entry_point_offset_minus1"); |
---|
1451 | entryPointOffset[ idx ] = uiCode + 1; |
---|
1452 | #else |
---|
1453 | READ_CODE(offsetLenMinus1+1, uiCode, "entry_point_offset"); |
---|
1454 | entryPointOffset[ idx ] = uiCode; |
---|
1455 | #endif |
---|
1456 | } |
---|
1457 | |
---|
1458 | if ( pps->getTilesEnabledFlag() ) |
---|
1459 | { |
---|
1460 | rpcSlice->setTileLocationCount( numEntryPointOffsets ); |
---|
1461 | |
---|
1462 | UInt prevPos = 0; |
---|
1463 | for (Int idx=0; idx<rpcSlice->getTileLocationCount(); idx++) |
---|
1464 | { |
---|
1465 | rpcSlice->setTileLocation( idx, prevPos + entryPointOffset [ idx ] ); |
---|
1466 | prevPos += entryPointOffset[ idx ]; |
---|
1467 | } |
---|
1468 | } |
---|
1469 | else if ( pps->getEntropyCodingSyncEnabledFlag() ) |
---|
1470 | { |
---|
1471 | Int numSubstreams = rpcSlice->getNumEntryPointOffsets()+1; |
---|
1472 | rpcSlice->allocSubstreamSizes(numSubstreams); |
---|
1473 | UInt *pSubstreamSizes = rpcSlice->getSubstreamSizes(); |
---|
1474 | for (Int idx=0; idx<numSubstreams-1; idx++) |
---|
1475 | { |
---|
1476 | if ( idx < numEntryPointOffsets ) |
---|
1477 | { |
---|
1478 | pSubstreamSizes[ idx ] = ( entryPointOffset[ idx ] << 3 ) ; |
---|
1479 | } |
---|
1480 | else |
---|
1481 | { |
---|
1482 | pSubstreamSizes[ idx ] = 0; |
---|
1483 | } |
---|
1484 | } |
---|
1485 | } |
---|
1486 | |
---|
1487 | if (entryPointOffset) |
---|
1488 | { |
---|
1489 | delete [] entryPointOffset; |
---|
1490 | } |
---|
1491 | } |
---|
1492 | else |
---|
1493 | { |
---|
1494 | rpcSlice->setNumEntryPointOffsets ( 0 ); |
---|
1495 | } |
---|
1496 | |
---|
1497 | if(pps->getSliceHeaderExtensionPresentFlag()) |
---|
1498 | { |
---|
1499 | READ_UVLC(uiCode,"slice_header_extension_length"); |
---|
1500 | for(Int i=0; i<uiCode; i++) |
---|
1501 | { |
---|
1502 | UInt ignore; |
---|
1503 | READ_CODE(8,ignore,"slice_header_extension_data_byte"); |
---|
1504 | } |
---|
1505 | } |
---|
1506 | m_pcBitstream->readByteAlignment(); |
---|
1507 | return; |
---|
1508 | } |
---|
1509 | |
---|
1510 | Void TDecCavlc::parsePTL( TComPTL *rpcPTL, Bool profilePresentFlag, Int maxNumSubLayersMinus1 ) |
---|
1511 | { |
---|
1512 | UInt uiCode; |
---|
1513 | if(profilePresentFlag) |
---|
1514 | { |
---|
1515 | parseProfileTier(rpcPTL->getGeneralPTL()); |
---|
1516 | } |
---|
1517 | READ_CODE( 8, uiCode, "general_level_idc" ); rpcPTL->getGeneralPTL()->setLevelIdc(uiCode); |
---|
1518 | |
---|
1519 | #if L0363_BYTE_ALIGN |
---|
1520 | for (Int i = 0; i < maxNumSubLayersMinus1; i++) |
---|
1521 | { |
---|
1522 | #if !H_MV |
---|
1523 | if(profilePresentFlag) |
---|
1524 | { |
---|
1525 | #endif |
---|
1526 | READ_FLAG( uiCode, "sub_layer_profile_present_flag[i]" ); rpcPTL->setSubLayerProfilePresentFlag(i, uiCode); |
---|
1527 | #if H_MV |
---|
1528 | rpcPTL->setSubLayerProfilePresentFlag( i, profilePresentFlag && rpcPTL->getSubLayerProfilePresentFlag(i) ); |
---|
1529 | #else |
---|
1530 | } |
---|
1531 | #endif |
---|
1532 | READ_FLAG( uiCode, "sub_layer_level_present_flag[i]" ); rpcPTL->setSubLayerLevelPresentFlag (i, uiCode); |
---|
1533 | } |
---|
1534 | |
---|
1535 | if (maxNumSubLayersMinus1 > 0) |
---|
1536 | { |
---|
1537 | for (Int i = maxNumSubLayersMinus1; i < 8; i++) |
---|
1538 | { |
---|
1539 | READ_CODE(2, uiCode, "reserved_zero_2bits"); |
---|
1540 | assert(uiCode == 0); |
---|
1541 | } |
---|
1542 | } |
---|
1543 | #endif |
---|
1544 | |
---|
1545 | for(Int i = 0; i < maxNumSubLayersMinus1; i++) |
---|
1546 | { |
---|
1547 | #if !L0363_BYTE_ALIGN |
---|
1548 | if(profilePresentFlag) |
---|
1549 | { |
---|
1550 | READ_FLAG( uiCode, "sub_layer_profile_present_flag[i]" ); rpcPTL->setSubLayerProfilePresentFlag(i, uiCode); |
---|
1551 | } |
---|
1552 | READ_FLAG( uiCode, "sub_layer_level_present_flag[i]" ); rpcPTL->setSubLayerLevelPresentFlag (i, uiCode); |
---|
1553 | #endif |
---|
1554 | if( profilePresentFlag && rpcPTL->getSubLayerProfilePresentFlag(i) ) |
---|
1555 | { |
---|
1556 | parseProfileTier(rpcPTL->getSubLayerPTL(i)); |
---|
1557 | } |
---|
1558 | if(rpcPTL->getSubLayerLevelPresentFlag(i)) |
---|
1559 | { |
---|
1560 | READ_CODE( 8, uiCode, "sub_layer_level_idc[i]" ); rpcPTL->getSubLayerPTL(i)->setLevelIdc(uiCode); |
---|
1561 | } |
---|
1562 | } |
---|
1563 | } |
---|
1564 | |
---|
1565 | Void TDecCavlc::parseProfileTier(ProfileTierLevel *ptl) |
---|
1566 | { |
---|
1567 | UInt uiCode; |
---|
1568 | READ_CODE(2 , uiCode, "XXX_profile_space[]"); ptl->setProfileSpace(uiCode); |
---|
1569 | READ_FLAG( uiCode, "XXX_tier_flag[]" ); ptl->setTierFlag (uiCode ? 1 : 0); |
---|
1570 | READ_CODE(5 , uiCode, "XXX_profile_idc[]" ); ptl->setProfileIdc (uiCode); |
---|
1571 | for(Int j = 0; j < 32; j++) |
---|
1572 | { |
---|
1573 | READ_FLAG( uiCode, "XXX_profile_compatibility_flag[][j]"); ptl->setProfileCompatibilityFlag(j, uiCode ? 1 : 0); |
---|
1574 | } |
---|
1575 | #if L0046_CONSTRAINT_FLAGS |
---|
1576 | READ_FLAG(uiCode, "general_progressive_source_flag"); |
---|
1577 | ptl->setProgressiveSourceFlag(uiCode ? true : false); |
---|
1578 | |
---|
1579 | READ_FLAG(uiCode, "general_interlaced_source_flag"); |
---|
1580 | ptl->setInterlacedSourceFlag(uiCode ? true : false); |
---|
1581 | |
---|
1582 | READ_FLAG(uiCode, "general_non_packed_constraint_flag"); |
---|
1583 | ptl->setNonPackedConstraintFlag(uiCode ? true : false); |
---|
1584 | |
---|
1585 | READ_FLAG(uiCode, "general_frame_only_constraint_flag"); |
---|
1586 | ptl->setFrameOnlyConstraintFlag(uiCode ? true : false); |
---|
1587 | |
---|
1588 | READ_CODE(16, uiCode, "XXX_reserved_zero_44bits[0..15]"); |
---|
1589 | READ_CODE(16, uiCode, "XXX_reserved_zero_44bits[16..31]"); |
---|
1590 | READ_CODE(12, uiCode, "XXX_reserved_zero_44bits[32..43]"); |
---|
1591 | #elif L0363_MORE_BITS |
---|
1592 | READ_CODE(16, uiCode, "XXX_reserved_zero_48bits[0..15]"); |
---|
1593 | READ_CODE(16, uiCode, "XXX_reserved_zero_48bits[16..31]"); |
---|
1594 | READ_CODE(16, uiCode, "XXX_reserved_zero_48bits[32..47]"); |
---|
1595 | #else |
---|
1596 | READ_CODE(16, uiCode, "XXX_reserved_zero_16bits[]"); assert( uiCode == 0 ); |
---|
1597 | #endif |
---|
1598 | } |
---|
1599 | #if SIGNAL_BITRATE_PICRATE_IN_VPS |
---|
1600 | Void TDecCavlc::parseBitratePicRateInfo(TComBitRatePicRateInfo *info, Int tempLevelLow, Int tempLevelHigh) |
---|
1601 | { |
---|
1602 | UInt uiCode; |
---|
1603 | for(Int i = tempLevelLow; i <= tempLevelHigh; i++) |
---|
1604 | { |
---|
1605 | READ_FLAG( uiCode, "bit_rate_info_present_flag[i]" ); info->setBitRateInfoPresentFlag(i, uiCode ? true : false); |
---|
1606 | READ_FLAG( uiCode, "pic_rate_info_present_flag[i]" ); info->setPicRateInfoPresentFlag(i, uiCode ? true : false); |
---|
1607 | if(info->getBitRateInfoPresentFlag(i)) |
---|
1608 | { |
---|
1609 | READ_CODE( 16, uiCode, "avg_bit_rate[i]" ); info->setAvgBitRate(i, uiCode); |
---|
1610 | READ_CODE( 16, uiCode, "max_bit_rate[i]" ); info->setMaxBitRate(i, uiCode); |
---|
1611 | } |
---|
1612 | if(info->getPicRateInfoPresentFlag(i)) |
---|
1613 | { |
---|
1614 | READ_CODE( 2, uiCode, "constant_pic_rate_idc[i]" ); info->setConstantPicRateIdc(i, uiCode); |
---|
1615 | READ_CODE( 16, uiCode, "avg_pic_rate[i]" ); info->setAvgPicRate(i, uiCode); |
---|
1616 | } |
---|
1617 | } |
---|
1618 | } |
---|
1619 | #endif |
---|
1620 | Void TDecCavlc::parseTerminatingBit( UInt& ruiBit ) |
---|
1621 | { |
---|
1622 | ruiBit = false; |
---|
1623 | Int iBitsLeft = m_pcBitstream->getNumBitsLeft(); |
---|
1624 | if(iBitsLeft <= 8) |
---|
1625 | { |
---|
1626 | UInt uiPeekValue = m_pcBitstream->peekBits(iBitsLeft); |
---|
1627 | if (uiPeekValue == (1<<(iBitsLeft-1))) |
---|
1628 | { |
---|
1629 | ruiBit = true; |
---|
1630 | } |
---|
1631 | } |
---|
1632 | } |
---|
1633 | |
---|
1634 | Void TDecCavlc::parseSkipFlag( TComDataCU* /*pcCU*/, UInt /*uiAbsPartIdx*/, UInt /*uiDepth*/ ) |
---|
1635 | { |
---|
1636 | assert(0); |
---|
1637 | } |
---|
1638 | |
---|
1639 | Void TDecCavlc::parseCUTransquantBypassFlag( TComDataCU* /*pcCU*/, UInt /*uiAbsPartIdx*/, UInt /*uiDepth*/ ) |
---|
1640 | { |
---|
1641 | assert(0); |
---|
1642 | } |
---|
1643 | |
---|
1644 | Void TDecCavlc::parseMVPIdx( Int& /*riMVPIdx*/ ) |
---|
1645 | { |
---|
1646 | assert(0); |
---|
1647 | } |
---|
1648 | |
---|
1649 | Void TDecCavlc::parseSplitFlag ( TComDataCU* /*pcCU*/, UInt /*uiAbsPartIdx*/, UInt /*uiDepth*/ ) |
---|
1650 | { |
---|
1651 | assert(0); |
---|
1652 | } |
---|
1653 | |
---|
1654 | Void TDecCavlc::parsePartSize( TComDataCU* /*pcCU*/, UInt /*uiAbsPartIdx*/, UInt /*uiDepth*/ ) |
---|
1655 | { |
---|
1656 | assert(0); |
---|
1657 | } |
---|
1658 | |
---|
1659 | Void TDecCavlc::parsePredMode( TComDataCU* /*pcCU*/, UInt /*uiAbsPartIdx*/, UInt /*uiDepth*/ ) |
---|
1660 | { |
---|
1661 | assert(0); |
---|
1662 | } |
---|
1663 | |
---|
1664 | /** Parse I_PCM information. |
---|
1665 | * \param pcCU pointer to CU |
---|
1666 | * \param uiAbsPartIdx CU index |
---|
1667 | * \param uiDepth CU depth |
---|
1668 | * \returns Void |
---|
1669 | * |
---|
1670 | * If I_PCM flag indicates that the CU is I_PCM, parse its PCM alignment bits and codes. |
---|
1671 | */ |
---|
1672 | Void TDecCavlc::parseIPCMInfo( TComDataCU* /*pcCU*/, UInt /*uiAbsPartIdx*/, UInt /*uiDepth*/ ) |
---|
1673 | { |
---|
1674 | assert(0); |
---|
1675 | } |
---|
1676 | |
---|
1677 | Void TDecCavlc::parseIntraDirLumaAng ( TComDataCU* /*pcCU*/, UInt /*uiAbsPartIdx*/, UInt /*uiDepth*/ ) |
---|
1678 | { |
---|
1679 | assert(0); |
---|
1680 | } |
---|
1681 | |
---|
1682 | Void TDecCavlc::parseIntraDirChroma( TComDataCU* /*pcCU*/, UInt /*uiAbsPartIdx*/, UInt /*uiDepth*/ ) |
---|
1683 | { |
---|
1684 | assert(0); |
---|
1685 | } |
---|
1686 | |
---|
1687 | Void TDecCavlc::parseInterDir( TComDataCU* /*pcCU*/, UInt& /*ruiInterDir*/, UInt /*uiAbsPartIdx*/ ) |
---|
1688 | { |
---|
1689 | assert(0); |
---|
1690 | } |
---|
1691 | |
---|
1692 | Void TDecCavlc::parseRefFrmIdx( TComDataCU* /*pcCU*/, Int& /*riRefFrmIdx*/, RefPicList /*eRefList*/ ) |
---|
1693 | { |
---|
1694 | assert(0); |
---|
1695 | } |
---|
1696 | |
---|
1697 | Void TDecCavlc::parseMvd( TComDataCU* /*pcCU*/, UInt /*uiAbsPartIdx*/, UInt /*uiPartIdx*/, UInt /*uiDepth*/, RefPicList /*eRefList*/ ) |
---|
1698 | { |
---|
1699 | assert(0); |
---|
1700 | } |
---|
1701 | |
---|
1702 | Void TDecCavlc::parseDeltaQP( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth ) |
---|
1703 | { |
---|
1704 | Int qp; |
---|
1705 | Int iDQp; |
---|
1706 | |
---|
1707 | xReadSvlc( iDQp ); |
---|
1708 | |
---|
1709 | Int qpBdOffsetY = pcCU->getSlice()->getSPS()->getQpBDOffsetY(); |
---|
1710 | qp = (((Int) pcCU->getRefQP( uiAbsPartIdx ) + iDQp + 52 + 2*qpBdOffsetY )%(52+ qpBdOffsetY)) - qpBdOffsetY; |
---|
1711 | |
---|
1712 | UInt uiAbsQpCUPartIdx = (uiAbsPartIdx>>((g_uiMaxCUDepth - pcCU->getSlice()->getPPS()->getMaxCuDQPDepth())<<1))<<((g_uiMaxCUDepth - pcCU->getSlice()->getPPS()->getMaxCuDQPDepth())<<1) ; |
---|
1713 | UInt uiQpCUDepth = min(uiDepth,pcCU->getSlice()->getPPS()->getMaxCuDQPDepth()) ; |
---|
1714 | |
---|
1715 | pcCU->setQPSubParts( qp, uiAbsQpCUPartIdx, uiQpCUDepth ); |
---|
1716 | } |
---|
1717 | |
---|
1718 | Void TDecCavlc::parseCoeffNxN( TComDataCU* /*pcCU*/, TCoeff* /*pcCoef*/, UInt /*uiAbsPartIdx*/, UInt /*uiWidth*/, UInt /*uiHeight*/, UInt /*uiDepth*/, TextType /*eTType*/ ) |
---|
1719 | { |
---|
1720 | assert(0); |
---|
1721 | } |
---|
1722 | |
---|
1723 | Void TDecCavlc::parseTransformSubdivFlag( UInt& /*ruiSubdivFlag*/, UInt /*uiLog2TransformBlockSize*/ ) |
---|
1724 | { |
---|
1725 | assert(0); |
---|
1726 | } |
---|
1727 | |
---|
1728 | Void TDecCavlc::parseQtCbf( TComDataCU* /*pcCU*/, UInt /*uiAbsPartIdx*/, TextType /*eType*/, UInt /*uiTrDepth*/, UInt /*uiDepth*/ ) |
---|
1729 | { |
---|
1730 | assert(0); |
---|
1731 | } |
---|
1732 | |
---|
1733 | Void TDecCavlc::parseQtRootCbf( UInt /*uiAbsPartIdx*/, UInt& /*uiQtRootCbf*/ ) |
---|
1734 | { |
---|
1735 | assert(0); |
---|
1736 | } |
---|
1737 | |
---|
1738 | Void TDecCavlc::parseTransformSkipFlags (TComDataCU* /*pcCU*/, UInt /*uiAbsPartIdx*/, UInt /*width*/, UInt /*height*/, UInt /*uiDepth*/, TextType /*eTType*/) |
---|
1739 | { |
---|
1740 | assert(0); |
---|
1741 | } |
---|
1742 | |
---|
1743 | Void TDecCavlc::parseMergeFlag ( TComDataCU* /*pcCU*/, UInt /*uiAbsPartIdx*/, UInt /*uiDepth*/, UInt /*uiPUIdx*/ ) |
---|
1744 | { |
---|
1745 | assert(0); |
---|
1746 | } |
---|
1747 | |
---|
1748 | Void TDecCavlc::parseMergeIndex ( TComDataCU* /*pcCU*/, UInt& /*ruiMergeIndex*/ ) |
---|
1749 | { |
---|
1750 | assert(0); |
---|
1751 | } |
---|
1752 | |
---|
1753 | // ==================================================================================================================== |
---|
1754 | // Protected member functions |
---|
1755 | // ==================================================================================================================== |
---|
1756 | |
---|
1757 | |
---|
1758 | /** Parse PCM alignment zero bits. |
---|
1759 | * \returns Void |
---|
1760 | */ |
---|
1761 | Void TDecCavlc::xReadPCMAlignZero( ) |
---|
1762 | { |
---|
1763 | UInt uiNumberOfBits = m_pcBitstream->getNumBitsUntilByteAligned(); |
---|
1764 | |
---|
1765 | if(uiNumberOfBits) |
---|
1766 | { |
---|
1767 | UInt uiBits; |
---|
1768 | UInt uiSymbol; |
---|
1769 | |
---|
1770 | for(uiBits = 0; uiBits < uiNumberOfBits; uiBits++) |
---|
1771 | { |
---|
1772 | xReadFlag( uiSymbol ); |
---|
1773 | assert( uiSymbol == 0 ); |
---|
1774 | } |
---|
1775 | } |
---|
1776 | } |
---|
1777 | |
---|
1778 | Void TDecCavlc::xReadUnaryMaxSymbol( UInt& ruiSymbol, UInt uiMaxSymbol ) |
---|
1779 | { |
---|
1780 | if (uiMaxSymbol == 0) |
---|
1781 | { |
---|
1782 | ruiSymbol = 0; |
---|
1783 | return; |
---|
1784 | } |
---|
1785 | |
---|
1786 | xReadFlag( ruiSymbol ); |
---|
1787 | |
---|
1788 | if (ruiSymbol == 0 || uiMaxSymbol == 1) |
---|
1789 | { |
---|
1790 | return; |
---|
1791 | } |
---|
1792 | |
---|
1793 | UInt uiSymbol = 0; |
---|
1794 | UInt uiCont; |
---|
1795 | |
---|
1796 | do |
---|
1797 | { |
---|
1798 | xReadFlag( uiCont ); |
---|
1799 | uiSymbol++; |
---|
1800 | } |
---|
1801 | while( uiCont && (uiSymbol < uiMaxSymbol-1) ); |
---|
1802 | |
---|
1803 | if( uiCont && (uiSymbol == uiMaxSymbol-1) ) |
---|
1804 | { |
---|
1805 | uiSymbol++; |
---|
1806 | } |
---|
1807 | |
---|
1808 | ruiSymbol = uiSymbol; |
---|
1809 | } |
---|
1810 | |
---|
1811 | Void TDecCavlc::xReadExGolombLevel( UInt& ruiSymbol ) |
---|
1812 | { |
---|
1813 | UInt uiSymbol ; |
---|
1814 | UInt uiCount = 0; |
---|
1815 | do |
---|
1816 | { |
---|
1817 | xReadFlag( uiSymbol ); |
---|
1818 | uiCount++; |
---|
1819 | } |
---|
1820 | while( uiSymbol && (uiCount != 13)); |
---|
1821 | |
---|
1822 | ruiSymbol = uiCount-1; |
---|
1823 | |
---|
1824 | if( uiSymbol ) |
---|
1825 | { |
---|
1826 | xReadEpExGolomb( uiSymbol, 0 ); |
---|
1827 | ruiSymbol += uiSymbol+1; |
---|
1828 | } |
---|
1829 | |
---|
1830 | return; |
---|
1831 | } |
---|
1832 | |
---|
1833 | Void TDecCavlc::xReadEpExGolomb( UInt& ruiSymbol, UInt uiCount ) |
---|
1834 | { |
---|
1835 | UInt uiSymbol = 0; |
---|
1836 | UInt uiBit = 1; |
---|
1837 | |
---|
1838 | |
---|
1839 | while( uiBit ) |
---|
1840 | { |
---|
1841 | xReadFlag( uiBit ); |
---|
1842 | uiSymbol += uiBit << uiCount++; |
---|
1843 | } |
---|
1844 | |
---|
1845 | uiCount--; |
---|
1846 | while( uiCount-- ) |
---|
1847 | { |
---|
1848 | xReadFlag( uiBit ); |
---|
1849 | uiSymbol += uiBit << uiCount; |
---|
1850 | } |
---|
1851 | |
---|
1852 | ruiSymbol = uiSymbol; |
---|
1853 | |
---|
1854 | return; |
---|
1855 | } |
---|
1856 | |
---|
1857 | UInt TDecCavlc::xGetBit() |
---|
1858 | { |
---|
1859 | UInt ruiCode; |
---|
1860 | m_pcBitstream->read( 1, ruiCode ); |
---|
1861 | return ruiCode; |
---|
1862 | } |
---|
1863 | |
---|
1864 | |
---|
1865 | /** parse explicit wp tables |
---|
1866 | * \param TComSlice* pcSlice |
---|
1867 | * \returns Void |
---|
1868 | */ |
---|
1869 | Void TDecCavlc::xParsePredWeightTable( TComSlice* pcSlice ) |
---|
1870 | { |
---|
1871 | wpScalingParam *wp; |
---|
1872 | Bool bChroma = true; // color always present in HEVC ? |
---|
1873 | SliceType eSliceType = pcSlice->getSliceType(); |
---|
1874 | Int iNbRef = (eSliceType == B_SLICE ) ? (2) : (1); |
---|
1875 | UInt uiLog2WeightDenomLuma, uiLog2WeightDenomChroma; |
---|
1876 | UInt uiTotalSignalledWeightFlags = 0; |
---|
1877 | |
---|
1878 | Int iDeltaDenom; |
---|
1879 | // decode delta_luma_log2_weight_denom : |
---|
1880 | READ_UVLC( uiLog2WeightDenomLuma, "luma_log2_weight_denom" ); // ue(v): luma_log2_weight_denom |
---|
1881 | if( bChroma ) |
---|
1882 | { |
---|
1883 | READ_SVLC( iDeltaDenom, "delta_chroma_log2_weight_denom" ); // se(v): delta_chroma_log2_weight_denom |
---|
1884 | assert((iDeltaDenom + (Int)uiLog2WeightDenomLuma)>=0); |
---|
1885 | uiLog2WeightDenomChroma = (UInt)(iDeltaDenom + uiLog2WeightDenomLuma); |
---|
1886 | } |
---|
1887 | |
---|
1888 | for ( Int iNumRef=0 ; iNumRef<iNbRef ; iNumRef++ ) |
---|
1889 | { |
---|
1890 | RefPicList eRefPicList = ( iNumRef ? REF_PIC_LIST_1 : REF_PIC_LIST_0 ); |
---|
1891 | for ( Int iRefIdx=0 ; iRefIdx<pcSlice->getNumRefIdx(eRefPicList) ; iRefIdx++ ) |
---|
1892 | { |
---|
1893 | pcSlice->getWpScaling(eRefPicList, iRefIdx, wp); |
---|
1894 | |
---|
1895 | wp[0].uiLog2WeightDenom = uiLog2WeightDenomLuma; |
---|
1896 | wp[1].uiLog2WeightDenom = uiLog2WeightDenomChroma; |
---|
1897 | wp[2].uiLog2WeightDenom = uiLog2WeightDenomChroma; |
---|
1898 | |
---|
1899 | UInt uiCode; |
---|
1900 | READ_FLAG( uiCode, "luma_weight_lX_flag" ); // u(1): luma_weight_l0_flag |
---|
1901 | wp[0].bPresentFlag = ( uiCode == 1 ); |
---|
1902 | uiTotalSignalledWeightFlags += wp[0].bPresentFlag; |
---|
1903 | } |
---|
1904 | if ( bChroma ) |
---|
1905 | { |
---|
1906 | UInt uiCode; |
---|
1907 | for ( Int iRefIdx=0 ; iRefIdx<pcSlice->getNumRefIdx(eRefPicList) ; iRefIdx++ ) |
---|
1908 | { |
---|
1909 | pcSlice->getWpScaling(eRefPicList, iRefIdx, wp); |
---|
1910 | READ_FLAG( uiCode, "chroma_weight_lX_flag" ); // u(1): chroma_weight_l0_flag |
---|
1911 | wp[1].bPresentFlag = ( uiCode == 1 ); |
---|
1912 | wp[2].bPresentFlag = ( uiCode == 1 ); |
---|
1913 | uiTotalSignalledWeightFlags += 2*wp[1].bPresentFlag; |
---|
1914 | } |
---|
1915 | } |
---|
1916 | for ( Int iRefIdx=0 ; iRefIdx<pcSlice->getNumRefIdx(eRefPicList) ; iRefIdx++ ) |
---|
1917 | { |
---|
1918 | pcSlice->getWpScaling(eRefPicList, iRefIdx, wp); |
---|
1919 | if ( wp[0].bPresentFlag ) |
---|
1920 | { |
---|
1921 | Int iDeltaWeight; |
---|
1922 | READ_SVLC( iDeltaWeight, "delta_luma_weight_lX" ); // se(v): delta_luma_weight_l0[i] |
---|
1923 | wp[0].iWeight = (iDeltaWeight + (1<<wp[0].uiLog2WeightDenom)); |
---|
1924 | READ_SVLC( wp[0].iOffset, "luma_offset_lX" ); // se(v): luma_offset_l0[i] |
---|
1925 | } |
---|
1926 | else |
---|
1927 | { |
---|
1928 | wp[0].iWeight = (1 << wp[0].uiLog2WeightDenom); |
---|
1929 | wp[0].iOffset = 0; |
---|
1930 | } |
---|
1931 | if ( bChroma ) |
---|
1932 | { |
---|
1933 | if ( wp[1].bPresentFlag ) |
---|
1934 | { |
---|
1935 | for ( Int j=1 ; j<3 ; j++ ) |
---|
1936 | { |
---|
1937 | Int iDeltaWeight; |
---|
1938 | READ_SVLC( iDeltaWeight, "delta_chroma_weight_lX" ); // se(v): chroma_weight_l0[i][j] |
---|
1939 | wp[j].iWeight = (iDeltaWeight + (1<<wp[1].uiLog2WeightDenom)); |
---|
1940 | |
---|
1941 | Int iDeltaChroma; |
---|
1942 | READ_SVLC( iDeltaChroma, "delta_chroma_offset_lX" ); // se(v): delta_chroma_offset_l0[i][j] |
---|
1943 | Int pred = ( 128 - ( ( 128*wp[j].iWeight)>>(wp[j].uiLog2WeightDenom) ) ); |
---|
1944 | wp[j].iOffset = Clip3(-128, 127, (iDeltaChroma + pred) ); |
---|
1945 | } |
---|
1946 | } |
---|
1947 | else |
---|
1948 | { |
---|
1949 | for ( Int j=1 ; j<3 ; j++ ) |
---|
1950 | { |
---|
1951 | wp[j].iWeight = (1 << wp[j].uiLog2WeightDenom); |
---|
1952 | wp[j].iOffset = 0; |
---|
1953 | } |
---|
1954 | } |
---|
1955 | } |
---|
1956 | } |
---|
1957 | |
---|
1958 | for ( Int iRefIdx=pcSlice->getNumRefIdx(eRefPicList) ; iRefIdx<MAX_NUM_REF ; iRefIdx++ ) |
---|
1959 | { |
---|
1960 | pcSlice->getWpScaling(eRefPicList, iRefIdx, wp); |
---|
1961 | |
---|
1962 | wp[0].bPresentFlag = false; |
---|
1963 | wp[1].bPresentFlag = false; |
---|
1964 | wp[2].bPresentFlag = false; |
---|
1965 | } |
---|
1966 | } |
---|
1967 | assert(uiTotalSignalledWeightFlags<=24); |
---|
1968 | } |
---|
1969 | |
---|
1970 | /** decode quantization matrix |
---|
1971 | * \param scalingList quantization matrix information |
---|
1972 | */ |
---|
1973 | Void TDecCavlc::parseScalingList(TComScalingList* scalingList) |
---|
1974 | { |
---|
1975 | UInt code, sizeId, listId; |
---|
1976 | Bool scalingListPredModeFlag; |
---|
1977 | //for each size |
---|
1978 | for(sizeId = 0; sizeId < SCALING_LIST_SIZE_NUM; sizeId++) |
---|
1979 | { |
---|
1980 | for(listId = 0; listId < g_scalingListNum[sizeId]; listId++) |
---|
1981 | { |
---|
1982 | READ_FLAG( code, "scaling_list_pred_mode_flag"); |
---|
1983 | scalingListPredModeFlag = (code) ? true : false; |
---|
1984 | if(!scalingListPredModeFlag) //Copy Mode |
---|
1985 | { |
---|
1986 | READ_UVLC( code, "scaling_list_pred_matrix_id_delta"); |
---|
1987 | scalingList->setRefMatrixId (sizeId,listId,(UInt)((Int)(listId)-(code))); |
---|
1988 | if( sizeId > SCALING_LIST_8x8 ) |
---|
1989 | { |
---|
1990 | scalingList->setScalingListDC(sizeId,listId,((listId == scalingList->getRefMatrixId (sizeId,listId))? 16 :scalingList->getScalingListDC(sizeId, scalingList->getRefMatrixId (sizeId,listId)))); |
---|
1991 | } |
---|
1992 | scalingList->processRefMatrix( sizeId, listId, scalingList->getRefMatrixId (sizeId,listId)); |
---|
1993 | |
---|
1994 | } |
---|
1995 | else //DPCM Mode |
---|
1996 | { |
---|
1997 | xDecodeScalingList(scalingList, sizeId, listId); |
---|
1998 | } |
---|
1999 | } |
---|
2000 | } |
---|
2001 | |
---|
2002 | return; |
---|
2003 | } |
---|
2004 | /** decode DPCM |
---|
2005 | * \param scalingList quantization matrix information |
---|
2006 | * \param sizeId size index |
---|
2007 | * \param listId list index |
---|
2008 | */ |
---|
2009 | Void TDecCavlc::xDecodeScalingList(TComScalingList *scalingList, UInt sizeId, UInt listId) |
---|
2010 | { |
---|
2011 | Int i,coefNum = min(MAX_MATRIX_COEF_NUM,(Int)g_scalingListSize[sizeId]); |
---|
2012 | Int data; |
---|
2013 | Int scalingListDcCoefMinus8 = 0; |
---|
2014 | Int nextCoef = SCALING_LIST_START_VALUE; |
---|
2015 | UInt* scan = (sizeId == 0) ? g_auiSigLastScan [ SCAN_DIAG ] [ 1 ] : g_sigLastScanCG32x32; |
---|
2016 | Int *dst = scalingList->getScalingListAddress(sizeId, listId); |
---|
2017 | |
---|
2018 | if( sizeId > SCALING_LIST_8x8 ) |
---|
2019 | { |
---|
2020 | READ_SVLC( scalingListDcCoefMinus8, "scaling_list_dc_coef_minus8"); |
---|
2021 | scalingList->setScalingListDC(sizeId,listId,scalingListDcCoefMinus8 + 8); |
---|
2022 | nextCoef = scalingList->getScalingListDC(sizeId,listId); |
---|
2023 | } |
---|
2024 | |
---|
2025 | for(i = 0; i < coefNum; i++) |
---|
2026 | { |
---|
2027 | READ_SVLC( data, "scaling_list_delta_coef"); |
---|
2028 | nextCoef = (nextCoef + data + 256 ) % 256; |
---|
2029 | dst[scan[i]] = nextCoef; |
---|
2030 | } |
---|
2031 | } |
---|
2032 | |
---|
2033 | Bool TDecCavlc::xMoreRbspData() |
---|
2034 | { |
---|
2035 | Int bitsLeft = m_pcBitstream->getNumBitsLeft(); |
---|
2036 | |
---|
2037 | // if there are more than 8 bits, it cannot be rbsp_trailing_bits |
---|
2038 | if (bitsLeft > 8) |
---|
2039 | { |
---|
2040 | return true; |
---|
2041 | } |
---|
2042 | |
---|
2043 | UChar lastByte = m_pcBitstream->peekBits(bitsLeft); |
---|
2044 | Int cnt = bitsLeft; |
---|
2045 | |
---|
2046 | // remove trailing bits equal to zero |
---|
2047 | while ((cnt>0) && ((lastByte & 1) == 0)) |
---|
2048 | { |
---|
2049 | lastByte >>= 1; |
---|
2050 | cnt--; |
---|
2051 | } |
---|
2052 | // remove bit equal to one |
---|
2053 | cnt--; |
---|
2054 | |
---|
2055 | // we should not have a negative number of bits |
---|
2056 | assert (cnt>=0); |
---|
2057 | |
---|
2058 | // we have more data, if cnt is not zero |
---|
2059 | return (cnt>0); |
---|
2060 | } |
---|
2061 | |
---|
2062 | //! \} |
---|
2063 | |
---|