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-2012, 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 | #if !REMOVE_APS |
---|
58 | Void xTraceAPSHeader (TComAPS *pAPS) |
---|
59 | { |
---|
60 | fprintf( g_hTrace, "=========== Adaptation Parameter Set ===========\n"); |
---|
61 | } |
---|
62 | #endif |
---|
63 | |
---|
64 | Void xTraceSliceHeader (TComSlice *pSlice) |
---|
65 | { |
---|
66 | fprintf( g_hTrace, "=========== Slice ===========\n"); |
---|
67 | } |
---|
68 | |
---|
69 | #endif |
---|
70 | |
---|
71 | // ==================================================================================================================== |
---|
72 | // Constructor / destructor / create / destroy |
---|
73 | // ==================================================================================================================== |
---|
74 | |
---|
75 | TDecCavlc::TDecCavlc() |
---|
76 | { |
---|
77 | #if !REMOVE_FGS |
---|
78 | m_iSliceGranularity = 0; |
---|
79 | #endif |
---|
80 | } |
---|
81 | |
---|
82 | TDecCavlc::~TDecCavlc() |
---|
83 | { |
---|
84 | |
---|
85 | } |
---|
86 | |
---|
87 | // ==================================================================================================================== |
---|
88 | // Public member functions |
---|
89 | // ==================================================================================================================== |
---|
90 | |
---|
91 | void TDecCavlc::parseShortTermRefPicSet( TComSPS* sps, TComReferencePictureSet* rps, Int idx ) |
---|
92 | { |
---|
93 | UInt code; |
---|
94 | UInt interRPSPred; |
---|
95 | READ_FLAG(interRPSPred, "inter_ref_pic_set_prediction_flag"); rps->setInterRPSPrediction(interRPSPred); |
---|
96 | if (interRPSPred) |
---|
97 | { |
---|
98 | UInt bit; |
---|
99 | #if J0234_INTER_RPS_SIMPL |
---|
100 | if(idx == sps->getRPSList()->getNumberOfReferencePictureSets()) |
---|
101 | { |
---|
102 | READ_UVLC(code, "delta_idx_minus1" ); // delta index of the Reference Picture Set used for prediction minus 1 |
---|
103 | } |
---|
104 | else |
---|
105 | { |
---|
106 | code = 0; |
---|
107 | } |
---|
108 | 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 |
---|
109 | #else |
---|
110 | READ_UVLC(code, "delta_idx_minus1" ); // delta index of the Reference Picture Set used for prediction minus 1 |
---|
111 | #endif |
---|
112 | Int rIdx = idx - 1 - code; |
---|
113 | #if J0234_INTER_RPS_SIMPL |
---|
114 | 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 |
---|
115 | #else |
---|
116 | assert (rIdx <= idx && rIdx >= 0); |
---|
117 | #endif |
---|
118 | TComReferencePictureSet* rpsRef = sps->getRPSList()->getReferencePictureSet(rIdx); |
---|
119 | Int k = 0, k0 = 0, k1 = 0; |
---|
120 | READ_CODE(1, bit, "delta_rps_sign"); // delta_RPS_sign |
---|
121 | READ_UVLC(code, "abs_delta_rps_minus1"); // absolute delta RPS minus 1 |
---|
122 | Int deltaRPS = (1 - (bit<<1)) * (code + 1); // delta_RPS |
---|
123 | for(Int j=0 ; j <= rpsRef->getNumberOfPictures(); j++) |
---|
124 | { |
---|
125 | READ_CODE(1, bit, "used_by_curr_pic_flag" ); //first bit is "1" if Idc is 1 |
---|
126 | Int refIdc = bit; |
---|
127 | if (refIdc == 0) |
---|
128 | { |
---|
129 | READ_CODE(1, bit, "use_delta_flag" ); //second bit is "1" if Idc is 2, "0" otherwise. |
---|
130 | refIdc = bit<<1; //second bit is "1" if refIdc is 2, "0" if refIdc = 0. |
---|
131 | } |
---|
132 | if (refIdc == 1 || refIdc == 2) |
---|
133 | { |
---|
134 | Int deltaPOC = deltaRPS + ((j < rpsRef->getNumberOfPictures())? rpsRef->getDeltaPOC(j) : 0); |
---|
135 | rps->setDeltaPOC(k, deltaPOC); |
---|
136 | rps->setUsed(k, (refIdc == 1)); |
---|
137 | |
---|
138 | if (deltaPOC < 0) { |
---|
139 | k0++; |
---|
140 | } |
---|
141 | else |
---|
142 | { |
---|
143 | k1++; |
---|
144 | } |
---|
145 | k++; |
---|
146 | } |
---|
147 | rps->setRefIdc(j,refIdc); |
---|
148 | } |
---|
149 | rps->setNumRefIdc(rpsRef->getNumberOfPictures()+1); |
---|
150 | rps->setNumberOfPictures(k); |
---|
151 | rps->setNumberOfNegativePictures(k0); |
---|
152 | rps->setNumberOfPositivePictures(k1); |
---|
153 | rps->sortDeltaPOC(); |
---|
154 | } |
---|
155 | else |
---|
156 | { |
---|
157 | READ_UVLC(code, "num_negative_pics"); rps->setNumberOfNegativePictures(code); |
---|
158 | READ_UVLC(code, "num_positive_pics"); rps->setNumberOfPositivePictures(code); |
---|
159 | Int prev = 0; |
---|
160 | Int poc; |
---|
161 | for(Int j=0 ; j < rps->getNumberOfNegativePictures(); j++) |
---|
162 | { |
---|
163 | READ_UVLC(code, "delta_poc_s0_minus1"); |
---|
164 | poc = prev-code-1; |
---|
165 | prev = poc; |
---|
166 | rps->setDeltaPOC(j,poc); |
---|
167 | READ_FLAG(code, "used_by_curr_pic_s0_flag"); rps->setUsed(j,code); |
---|
168 | } |
---|
169 | prev = 0; |
---|
170 | for(Int j=rps->getNumberOfNegativePictures(); j < rps->getNumberOfNegativePictures()+rps->getNumberOfPositivePictures(); j++) |
---|
171 | { |
---|
172 | READ_UVLC(code, "delta_poc_s1_minus1"); |
---|
173 | poc = prev+code+1; |
---|
174 | prev = poc; |
---|
175 | rps->setDeltaPOC(j,poc); |
---|
176 | READ_FLAG(code, "used_by_curr_pic_s1_flag"); rps->setUsed(j,code); |
---|
177 | } |
---|
178 | rps->setNumberOfPictures(rps->getNumberOfNegativePictures()+rps->getNumberOfPositivePictures()); |
---|
179 | } |
---|
180 | #if PRINT_RPS_INFO |
---|
181 | rps->printDeltaPOC(); |
---|
182 | #endif |
---|
183 | } |
---|
184 | |
---|
185 | #if !REMOVE_APS |
---|
186 | Void TDecCavlc::parseAPS(TComAPS* aps) |
---|
187 | { |
---|
188 | #if ENC_DEC_TRACE |
---|
189 | xTraceAPSHeader(aps); |
---|
190 | #endif |
---|
191 | |
---|
192 | UInt uiCode; |
---|
193 | READ_UVLC(uiCode, "aps_id"); aps->setAPSID(uiCode); |
---|
194 | #if !REMOVE_ALF |
---|
195 | for(Int compIdx=0; compIdx< 3; compIdx++) |
---|
196 | { |
---|
197 | xParseAlfParam( (aps->getAlfParam())[compIdx]); |
---|
198 | } |
---|
199 | #endif |
---|
200 | READ_FLAG( uiCode, "aps_extension_flag"); |
---|
201 | if (uiCode) |
---|
202 | { |
---|
203 | while ( xMoreRbspData() ) |
---|
204 | { |
---|
205 | READ_FLAG( uiCode, "aps_extension_data_flag"); |
---|
206 | } |
---|
207 | } |
---|
208 | |
---|
209 | } |
---|
210 | #endif |
---|
211 | |
---|
212 | /** copy SAO parameter |
---|
213 | * \param dst |
---|
214 | * \param src |
---|
215 | */ |
---|
216 | inline Void copySaoOneLcuParam(SaoLcuParam* dst, SaoLcuParam* src) |
---|
217 | { |
---|
218 | Int i; |
---|
219 | dst->partIdx = src->partIdx; |
---|
220 | dst->typeIdx = src->typeIdx; |
---|
221 | if (dst->typeIdx != -1) |
---|
222 | { |
---|
223 | #if SAO_TYPE_CODING |
---|
224 | dst->subTypeIdx = src->subTypeIdx ; |
---|
225 | #else |
---|
226 | if (dst->typeIdx == SAO_BO) |
---|
227 | { |
---|
228 | dst->bandPosition = src->bandPosition ; |
---|
229 | } |
---|
230 | else |
---|
231 | { |
---|
232 | dst->bandPosition = 0; |
---|
233 | } |
---|
234 | #endif |
---|
235 | dst->length = src->length; |
---|
236 | for (i=0;i<dst->length;i++) |
---|
237 | { |
---|
238 | dst->offset[i] = src->offset[i]; |
---|
239 | } |
---|
240 | } |
---|
241 | else |
---|
242 | { |
---|
243 | dst->length = 0; |
---|
244 | for (i=0;i<SAO_BO_LEN;i++) |
---|
245 | { |
---|
246 | dst->offset[i] = 0; |
---|
247 | } |
---|
248 | } |
---|
249 | } |
---|
250 | |
---|
251 | #if !REMOVE_ALF |
---|
252 | Void TDecCavlc::xParseAlfParam(ALFParam* pAlfParam) |
---|
253 | { |
---|
254 | UInt uiSymbol; |
---|
255 | char syntaxString[50]; |
---|
256 | sprintf(syntaxString, "alf_aps_filter_flag[%d]", pAlfParam->componentID); |
---|
257 | READ_FLAG(uiSymbol, syntaxString); |
---|
258 | pAlfParam->alf_flag = uiSymbol; |
---|
259 | if(pAlfParam->alf_flag ==0) |
---|
260 | { |
---|
261 | return; |
---|
262 | } |
---|
263 | Int iSymbol; |
---|
264 | pAlfParam->num_coeff = (Int)ALF_MAX_NUM_COEF; |
---|
265 | switch(pAlfParam->componentID) |
---|
266 | { |
---|
267 | case ALF_Cb: |
---|
268 | case ALF_Cr: |
---|
269 | { |
---|
270 | pAlfParam->filter_shape = ALF_CROSS9x7_SQUARE3x3; |
---|
271 | pAlfParam->filters_per_group = 1; |
---|
272 | for(Int pos=0; pos< pAlfParam->num_coeff; pos++) |
---|
273 | { |
---|
274 | READ_SVLC(iSymbol, "alf_filt_coeff"); |
---|
275 | pAlfParam->coeffmulti[0][pos] = iSymbol; |
---|
276 | } |
---|
277 | } |
---|
278 | break; |
---|
279 | case ALF_Y: |
---|
280 | { |
---|
281 | pAlfParam->filters_per_group = 0; |
---|
282 | memset (pAlfParam->filterPattern, 0 , sizeof(Int)*NO_VAR_BINS); |
---|
283 | pAlfParam->filter_shape = 0; |
---|
284 | // filters_per_fr |
---|
285 | READ_UVLC (uiSymbol, "alf_no_filters_minus1"); |
---|
286 | pAlfParam->filters_per_group = uiSymbol + 1; |
---|
287 | |
---|
288 | if(uiSymbol == 1) // filters_per_group == 2 |
---|
289 | { |
---|
290 | READ_UVLC (uiSymbol, "alf_start_second_filter"); |
---|
291 | pAlfParam->startSecondFilter = uiSymbol; |
---|
292 | pAlfParam->filterPattern [uiSymbol] = 1; |
---|
293 | } |
---|
294 | else if (uiSymbol > 1) // filters_per_group > 2 |
---|
295 | { |
---|
296 | pAlfParam->filters_per_group = 1; |
---|
297 | Int numMergeFlags = 16; |
---|
298 | for (Int i=1; i<numMergeFlags; i++) |
---|
299 | { |
---|
300 | READ_FLAG (uiSymbol, "alf_filter_pattern"); |
---|
301 | pAlfParam->filterPattern[i] = uiSymbol; |
---|
302 | pAlfParam->filters_per_group += uiSymbol; |
---|
303 | } |
---|
304 | } |
---|
305 | for(Int idx = 0; idx < pAlfParam->filters_per_group; ++idx) |
---|
306 | { |
---|
307 | for(Int i = 0; i < pAlfParam->num_coeff; i++) |
---|
308 | { |
---|
309 | pAlfParam->coeffmulti[idx][i] = xGolombDecode(kTableTabShapes[ALF_CROSS9x7_SQUARE3x3][i]); |
---|
310 | } |
---|
311 | } |
---|
312 | } |
---|
313 | break; |
---|
314 | default: |
---|
315 | { |
---|
316 | printf("Not a legal component ID for ALF\n"); |
---|
317 | assert(0); |
---|
318 | exit(-1); |
---|
319 | } |
---|
320 | } |
---|
321 | } |
---|
322 | |
---|
323 | Int TDecCavlc::xGolombDecode(Int k) |
---|
324 | { |
---|
325 | Int coeff; |
---|
326 | UInt symbol; |
---|
327 | xReadEpExGolomb( symbol, k ); |
---|
328 | coeff = symbol; |
---|
329 | if(symbol != 0) |
---|
330 | { |
---|
331 | xReadFlag(symbol); |
---|
332 | if(symbol == 0) |
---|
333 | { |
---|
334 | coeff = -coeff; |
---|
335 | } |
---|
336 | } |
---|
337 | #if ENC_DEC_TRACE |
---|
338 | fprintf( g_hTrace, "%8lld ", g_nSymbolCounter++ ); |
---|
339 | fprintf( g_hTrace, "%-40s se(v) : %d\n", "alf_filt_coeff", coeff ); |
---|
340 | #endif |
---|
341 | return coeff; |
---|
342 | } |
---|
343 | #endif |
---|
344 | |
---|
345 | Void TDecCavlc::parsePPS(TComPPS* pcPPS) |
---|
346 | { |
---|
347 | #if ENC_DEC_TRACE |
---|
348 | xTracePPSHeader (pcPPS); |
---|
349 | #endif |
---|
350 | UInt uiCode; |
---|
351 | |
---|
352 | Int iCode; |
---|
353 | |
---|
354 | READ_UVLC( uiCode, "pic_parameter_set_id"); pcPPS->setPPSId (uiCode); |
---|
355 | READ_UVLC( uiCode, "seq_parameter_set_id"); pcPPS->setSPSId (uiCode); |
---|
356 | |
---|
357 | READ_FLAG ( uiCode, "sign_data_hiding_flag" ); pcPPS->setSignHideFlag( uiCode ); |
---|
358 | |
---|
359 | READ_FLAG( uiCode, "cabac_init_present_flag" ); pcPPS->setCabacInitPresentFlag( uiCode ? true : false ); |
---|
360 | |
---|
361 | READ_UVLC(uiCode, "num_ref_idx_l0_default_active_minus1"); pcPPS->setNumRefIdxL0DefaultActive(uiCode+1); |
---|
362 | READ_UVLC(uiCode, "num_ref_idx_l1_default_active_minus1"); pcPPS->setNumRefIdxL1DefaultActive(uiCode+1); |
---|
363 | |
---|
364 | READ_SVLC(iCode, "pic_init_qp_minus26" ); pcPPS->setPicInitQPMinus26(iCode); |
---|
365 | READ_FLAG( uiCode, "constrained_intra_pred_flag" ); pcPPS->setConstrainedIntraPred( uiCode ? true : false ); |
---|
366 | #if PPS_TS_FLAG |
---|
367 | READ_FLAG( uiCode, "transform_skip_enabled_flag" ); |
---|
368 | pcPPS->setUseTransformSkip ( uiCode ? true : false ); |
---|
369 | #endif |
---|
370 | |
---|
371 | #if !REMOVE_FGS |
---|
372 | READ_CODE( 2, uiCode, "slice_granularity" ); pcPPS->setSliceGranularity(uiCode); |
---|
373 | #endif |
---|
374 | |
---|
375 | // alf_param() ? |
---|
376 | #if CU_DQP_ENABLE_FLAG |
---|
377 | READ_FLAG( uiCode, "cu_qp_delta_enabled_flag" ); pcPPS->setUseDQP( uiCode ? true : false ); |
---|
378 | if( pcPPS->getUseDQP() ) |
---|
379 | { |
---|
380 | READ_UVLC( uiCode, "diff_cu_qp_delta_depth" ); |
---|
381 | #if REMOVE_FGS |
---|
382 | pcPPS->setMaxCuDQPDepth( uiCode ); |
---|
383 | #else |
---|
384 | pcPPS->setMaxCuDQPDepth( uiCode + pcPPS->getSliceGranularity() ); |
---|
385 | #endif |
---|
386 | } |
---|
387 | else |
---|
388 | { |
---|
389 | pcPPS->setMaxCuDQPDepth( 0 ); |
---|
390 | } |
---|
391 | #else |
---|
392 | READ_UVLC( uiCode, "diff_cu_qp_delta_depth"); |
---|
393 | if(uiCode == 0) |
---|
394 | { |
---|
395 | pcPPS->setUseDQP (false); |
---|
396 | pcPPS->setMaxCuDQPDepth( 0 ); |
---|
397 | } |
---|
398 | else |
---|
399 | { |
---|
400 | pcPPS->setUseDQP (true); |
---|
401 | #if REMOVE_FGS |
---|
402 | pcPPS->setMaxCuDQPDepth(uiCode - 1); |
---|
403 | #else |
---|
404 | pcPPS->setMaxCuDQPDepth(uiCode + pcPPS->getSliceGranularity() - 1); |
---|
405 | #endif |
---|
406 | } |
---|
407 | #endif |
---|
408 | READ_SVLC( iCode, "cb_qp_offset"); |
---|
409 | pcPPS->setChromaCbQpOffset(iCode); |
---|
410 | #if CHROMA_QP_EXTENSION |
---|
411 | assert( pcPPS->getChromaCbQpOffset() >= -12 ); |
---|
412 | assert( pcPPS->getChromaCbQpOffset() <= 12 ); |
---|
413 | #endif |
---|
414 | |
---|
415 | READ_SVLC( iCode, "cr_qp_offset"); |
---|
416 | pcPPS->setChromaCrQpOffset(iCode); |
---|
417 | #if CHROMA_QP_EXTENSION |
---|
418 | assert( pcPPS->getChromaCrQpOffset() >= -12 ); |
---|
419 | assert( pcPPS->getChromaCrQpOffset() <= 12 ); |
---|
420 | #endif |
---|
421 | |
---|
422 | #if CHROMA_QP_EXTENSION |
---|
423 | READ_FLAG( uiCode, "slicelevel_chroma_qp_flag" ); |
---|
424 | pcPPS->setSliceChromaQpFlag( uiCode ? true : false ); |
---|
425 | #endif |
---|
426 | |
---|
427 | READ_FLAG( uiCode, "weighted_pred_flag" ); // Use of Weighting Prediction (P_SLICE) |
---|
428 | pcPPS->setUseWP( uiCode==1 ); |
---|
429 | READ_FLAG( uiCode, "weighted_bipred_flag" ); // Use of Bi-Directional Weighting Prediction (B_SLICE) |
---|
430 | pcPPS->setWPBiPred( uiCode==1 ); |
---|
431 | printf("TDecCavlc::parsePPS():\tm_bUseWeightPred=%d\tm_uiBiPredIdc=%d\n", pcPPS->getUseWP(), pcPPS->getWPBiPred()); |
---|
432 | |
---|
433 | READ_FLAG( uiCode, "output_flag_present_flag" ); |
---|
434 | pcPPS->setOutputFlagPresentFlag( uiCode==1 ); |
---|
435 | |
---|
436 | #if !TILES_WPP_ENTROPYSLICES_FLAGS |
---|
437 | #if DEPENDENT_SLICES |
---|
438 | READ_FLAG( uiCode, "dependent_slices_enabled_flag" ); |
---|
439 | pcPPS->setDependentSliceEnabledFlag( uiCode==1 ); |
---|
440 | #endif |
---|
441 | #endif |
---|
442 | |
---|
443 | READ_FLAG( uiCode, "transquant_bypass_enable_flag"); |
---|
444 | pcPPS->setTransquantBypassEnableFlag(uiCode ? true : false); |
---|
445 | |
---|
446 | #if TILES_WPP_ENTROPYSLICES_FLAGS |
---|
447 | #if DEPENDENT_SLICES |
---|
448 | READ_FLAG( uiCode, "dependent_slices_enabled_flag" ); pcPPS->setDependentSliceEnabledFlag ( uiCode == 1 ); |
---|
449 | #endif |
---|
450 | READ_FLAG( uiCode, "tiles_enabled_flag" ); pcPPS->setTilesEnabledFlag ( uiCode == 1 ); |
---|
451 | READ_FLAG( uiCode, "entropy_coding_sync_enabled_flag" ); pcPPS->setEntropyCodingSyncEnabledFlag( uiCode == 1 ); |
---|
452 | READ_FLAG( uiCode, "entropy_slice_enabled_flag" ); pcPPS->setEntropySliceEnabledFlag ( uiCode == 1 ); |
---|
453 | |
---|
454 | if( pcPPS->getTilesEnabledFlag() ) |
---|
455 | #else |
---|
456 | READ_CODE(2, uiCode, "tiles_or_entropy_coding_sync_idc"); pcPPS->setTilesOrEntropyCodingSyncIdc(uiCode); |
---|
457 | if(pcPPS->getTilesOrEntropyCodingSyncIdc() == 1) |
---|
458 | #endif |
---|
459 | { |
---|
460 | READ_UVLC ( uiCode, "num_tile_columns_minus1" ); pcPPS->setNumColumnsMinus1( uiCode ); |
---|
461 | READ_UVLC ( uiCode, "num_tile_rows_minus1" ); pcPPS->setNumRowsMinus1( uiCode ); |
---|
462 | READ_FLAG ( uiCode, "uniform_spacing_flag" ); pcPPS->setUniformSpacingFlag( uiCode ); |
---|
463 | |
---|
464 | if( !pcPPS->getUniformSpacingFlag()) |
---|
465 | { |
---|
466 | UInt* columnWidth = (UInt*)malloc(pcPPS->getNumColumnsMinus1()*sizeof(UInt)); |
---|
467 | for(UInt i=0; i<pcPPS->getNumColumnsMinus1(); i++) |
---|
468 | { |
---|
469 | READ_UVLC( uiCode, "column_width_minus1" ); |
---|
470 | columnWidth[i] = uiCode+1; |
---|
471 | } |
---|
472 | pcPPS->setColumnWidth(columnWidth); |
---|
473 | free(columnWidth); |
---|
474 | |
---|
475 | UInt* rowHeight = (UInt*)malloc(pcPPS->getNumRowsMinus1()*sizeof(UInt)); |
---|
476 | for(UInt i=0; i<pcPPS->getNumRowsMinus1(); i++) |
---|
477 | { |
---|
478 | READ_UVLC( uiCode, "row_height_minus1" ); |
---|
479 | rowHeight[i] = uiCode + 1; |
---|
480 | } |
---|
481 | pcPPS->setRowHeight(rowHeight); |
---|
482 | free(rowHeight); |
---|
483 | } |
---|
484 | |
---|
485 | if(pcPPS->getNumColumnsMinus1() !=0 || pcPPS->getNumRowsMinus1() !=0) |
---|
486 | { |
---|
487 | READ_FLAG ( uiCode, "loop_filter_across_tiles_enabled_flag" ); pcPPS->setLoopFilterAcrossTilesEnabledFlag( uiCode ? true : false ); |
---|
488 | } |
---|
489 | } |
---|
490 | #if !TILES_WPP_ENTROPYSLICES_FLAGS |
---|
491 | #if DEPENDENT_SLICES |
---|
492 | else if( pcPPS->getTilesOrEntropyCodingSyncIdc()==3 ) |
---|
493 | { |
---|
494 | READ_FLAG ( uiCode, "cabac_independent_flag" ); |
---|
495 | pcPPS->setCabacIndependentFlag( (uiCode == 1)? true : false ); |
---|
496 | } |
---|
497 | #endif |
---|
498 | #endif |
---|
499 | #if MOVE_LOOP_FILTER_SLICES_FLAG |
---|
500 | READ_FLAG( uiCode, "loop_filter_across_slices_enabled_flag" ); pcPPS->setLoopFilterAcrossSlicesEnabledFlag( uiCode ? true : false ); |
---|
501 | #endif |
---|
502 | READ_FLAG( uiCode, "deblocking_filter_control_present_flag" ); pcPPS->setDeblockingFilterControlPresentFlag( uiCode ? true : false ); |
---|
503 | if(pcPPS->getDeblockingFilterControlPresentFlag()) |
---|
504 | { |
---|
505 | READ_FLAG( uiCode, "deblocking_filter_override_enabled_flag" ); pcPPS->setDeblockingFilterOverrideEnabledFlag( uiCode ? true : false ); |
---|
506 | READ_FLAG( uiCode, "pic_disable_deblocking_filter_flag" ); pcPPS->setPicDisableDeblockingFilterFlag(uiCode ? true : false ); |
---|
507 | if(!pcPPS->getPicDisableDeblockingFilterFlag()) |
---|
508 | { |
---|
509 | READ_SVLC ( iCode, "pps_beta_offset_div2" ); pcPPS->setDeblockingFilterBetaOffsetDiv2( iCode ); |
---|
510 | READ_SVLC ( iCode, "pps_tc_offset_div2" ); pcPPS->setDeblockingFilterTcOffsetDiv2( iCode ); |
---|
511 | } |
---|
512 | } |
---|
513 | READ_FLAG( uiCode, "pps_scaling_list_data_present_flag" ); pcPPS->setScalingListPresentFlag( uiCode ? true : false ); |
---|
514 | if(pcPPS->getScalingListPresentFlag ()) |
---|
515 | { |
---|
516 | parseScalingList( pcPPS->getScalingList() ); |
---|
517 | } |
---|
518 | READ_UVLC( uiCode, "log2_parallel_merge_level_minus2"); |
---|
519 | pcPPS->setLog2ParallelMergeLevelMinus2 (uiCode); |
---|
520 | |
---|
521 | #if SLICE_HEADER_EXTENSION |
---|
522 | READ_FLAG( uiCode, "slice_header_extension_present_flag"); |
---|
523 | pcPPS->setSliceHeaderExtensionPresentFlag(uiCode); |
---|
524 | #endif |
---|
525 | |
---|
526 | READ_FLAG( uiCode, "pps_extension_flag"); |
---|
527 | if (uiCode) |
---|
528 | { |
---|
529 | while ( xMoreRbspData() ) |
---|
530 | { |
---|
531 | READ_FLAG( uiCode, "pps_extension_data_flag"); |
---|
532 | } |
---|
533 | } |
---|
534 | } |
---|
535 | |
---|
536 | #if SUPPORT_FOR_VUI |
---|
537 | #if !BUFFERING_PERIOD_AND_TIMING_SEI |
---|
538 | Void TDecCavlc::parseVUI(TComVUI* pcVUI) |
---|
539 | #else |
---|
540 | Void TDecCavlc::parseVUI(TComVUI* pcVUI, TComSPS *pcSPS) |
---|
541 | #endif |
---|
542 | { |
---|
543 | #if ENC_DEC_TRACE |
---|
544 | fprintf( g_hTrace, "----------- vui_parameters -----------\n"); |
---|
545 | #endif |
---|
546 | UInt uiCode; |
---|
547 | |
---|
548 | READ_FLAG( uiCode, "aspect_ratio_info_present_flag"); pcVUI->setAspectRatioInfoPresentFlag(uiCode); |
---|
549 | if (pcVUI->getAspectRatioInfoPresentFlag()) |
---|
550 | { |
---|
551 | READ_CODE(8, uiCode, "aspect_ratio_idc"); pcVUI->setAspectRatioIdc(uiCode); |
---|
552 | if (pcVUI->getAspectRatioIdc() == 255) |
---|
553 | { |
---|
554 | READ_CODE(16, uiCode, "sar_width"); pcVUI->setSarWidth(uiCode); |
---|
555 | READ_CODE(16, uiCode, "sar_height"); pcVUI->setSarWidth(uiCode); |
---|
556 | } |
---|
557 | } |
---|
558 | |
---|
559 | READ_FLAG( uiCode, "overscan_info_present_flag"); pcVUI->setOverscanInfoPresentFlag(uiCode); |
---|
560 | if (pcVUI->getOverscanInfoPresentFlag()) |
---|
561 | { |
---|
562 | READ_FLAG( uiCode, "overscan_appropriate_flag"); pcVUI->setOverscanAppropriateFlag(uiCode); |
---|
563 | } |
---|
564 | |
---|
565 | READ_FLAG( uiCode, "video_signal_type_present_flag"); pcVUI->setVideoSignalTypePresentFlag(uiCode); |
---|
566 | if (pcVUI->getVideoSignalTypePresentFlag()) |
---|
567 | { |
---|
568 | READ_CODE(3, uiCode, "video_format"); pcVUI->setVideoFormat(uiCode); |
---|
569 | READ_FLAG( uiCode, "video_full_range_flag"); pcVUI->setVideoFullRangeFlag(uiCode); |
---|
570 | READ_FLAG( uiCode, "colour_description_present_flag"); pcVUI->setColourDescriptionPresentFlag(uiCode); |
---|
571 | if (pcVUI->getColourDescriptionPresentFlag()) |
---|
572 | { |
---|
573 | READ_CODE(8, uiCode, "colour_primaries"); pcVUI->setColourPrimaries(uiCode); |
---|
574 | READ_CODE(8, uiCode, "transfer_characteristics"); pcVUI->setTransferCharacteristics(uiCode); |
---|
575 | READ_CODE(8, uiCode, "matrix_coefficients"); pcVUI->setMatrixCoefficients(uiCode); |
---|
576 | } |
---|
577 | } |
---|
578 | |
---|
579 | READ_FLAG( uiCode, "chroma_loc_info_present_flag"); pcVUI->setChromaLocInfoPresentFlag(uiCode); |
---|
580 | if (pcVUI->getChromaLocInfoPresentFlag()) |
---|
581 | { |
---|
582 | READ_UVLC( uiCode, "chroma_sample_loc_type_top_field" ); pcVUI->setChromaSampleLocTypeTopField(uiCode); |
---|
583 | READ_UVLC( uiCode, "chroma_sample_loc_type_bottom_field" ); pcVUI->setChromaSampleLocTypeBottomField(uiCode); |
---|
584 | } |
---|
585 | |
---|
586 | READ_FLAG( uiCode, "neutral_chroma_indication_flag"); pcVUI->setNeutralChromaIndicationFlag(uiCode); |
---|
587 | |
---|
588 | READ_FLAG( uiCode, "field_seq_flag"); pcVUI->setFieldSeqFlag(uiCode); |
---|
589 | assert(pcVUI->getFieldSeqFlag() == false); // not supported yet |
---|
590 | |
---|
591 | READ_FLAG( uiCode, "hrd_parameters_present_flag"); pcVUI->setHrdParametersPresentFlag(uiCode); |
---|
592 | #if !BUFFERING_PERIOD_AND_TIMING_SEI |
---|
593 | assert(pcVUI->getHrdParametersPresentFlag() == false); // not supported yet |
---|
594 | #else |
---|
595 | if( pcVUI->getHrdParametersPresentFlag() ) |
---|
596 | { |
---|
597 | READ_FLAG( uiCode, "timing_info_present_flag" ); pcVUI->setTimingInfoPresentFlag( uiCode ); |
---|
598 | if( pcVUI->getTimingInfoPresentFlag() ) |
---|
599 | { |
---|
600 | READ_CODE( 32, uiCode, "num_units_in_tick" ); pcVUI->setNumUnitsInTick( uiCode ); |
---|
601 | READ_CODE( 32, uiCode, "time_scale" ); pcVUI->setTimeScale( uiCode ); |
---|
602 | } |
---|
603 | READ_FLAG( uiCode, "nal_hrd_parameters_present_flag" ); pcVUI->setNalHrdParametersPresentFlag( uiCode ); |
---|
604 | READ_FLAG( uiCode, "vcl_hrd_parameters_present_flag" ); pcVUI->setVclHrdParametersPresentFlag( uiCode ); |
---|
605 | if( pcVUI->getNalHrdParametersPresentFlag() || pcVUI->getVclHrdParametersPresentFlag() ) |
---|
606 | { |
---|
607 | READ_FLAG( uiCode, "sub_pic_Cpb_params_present_flag" ); pcVUI->setSubPicCpbParamsPresentFlag( uiCode ); |
---|
608 | if( pcVUI->getSubPicCpbParamsPresentFlag() ) |
---|
609 | { |
---|
610 | READ_CODE( 8, uiCode, "tick_divisor_minus2" ); pcVUI->setTickDivisorMinus2( uiCode ); |
---|
611 | READ_CODE( 5, uiCode, "du_cpb_removal_delay_length_minus1" ); pcVUI->setDuCpbRemovalDelayLengthMinus1( uiCode ); |
---|
612 | } |
---|
613 | READ_CODE( 4, uiCode, "bit_rate_scale" ); pcVUI->setBitRateScale( uiCode ); |
---|
614 | READ_CODE( 4, uiCode, "cpb_size_scale" ); pcVUI->setCpbSizeScale( uiCode ); |
---|
615 | READ_CODE( 5, uiCode, "initial_cpb_removal_delay_length_minus1" ); pcVUI->setInitialCpbRemovalDelayLengthMinus1( uiCode ); |
---|
616 | READ_CODE( 5, uiCode, "cpb_removal_delay_length_minus1" ); pcVUI->setCpbRemovalDelayLengthMinus1( uiCode ); |
---|
617 | READ_CODE( 5, uiCode, "dpb_output_delay_length_minus1" ); pcVUI->setDpbOutputDelayLengthMinus1( uiCode ); |
---|
618 | } |
---|
619 | |
---|
620 | Int i, j, nalOrVcl; |
---|
621 | for( i = 0; i < pcSPS->getMaxTLayers(); i ++ ) |
---|
622 | { |
---|
623 | READ_FLAG( uiCode, "fixed_pic_rate_flag" ); pcVUI->setFixedPicRateFlag( i, uiCode ); |
---|
624 | if( pcVUI->getFixedPicRateFlag( i ) ) |
---|
625 | { |
---|
626 | READ_UVLC( uiCode, "pic_duration_in_tc_minus1" ); pcVUI->setPicDurationInTcMinus1( i, uiCode ); |
---|
627 | } |
---|
628 | READ_FLAG( uiCode, "low_delay_hrd_flag" ); pcVUI->setLowDelayHrdFlag( i, uiCode ); |
---|
629 | READ_UVLC( uiCode, "cpb_cnt_minus1" ); pcVUI->setCpbCntMinus1( i, uiCode ); |
---|
630 | for( nalOrVcl = 0; nalOrVcl < 2; nalOrVcl ++ ) |
---|
631 | { |
---|
632 | if( ( ( nalOrVcl == 0 ) && ( pcVUI->getNalHrdParametersPresentFlag() ) ) || |
---|
633 | ( ( nalOrVcl == 1 ) && ( pcVUI->getVclHrdParametersPresentFlag() ) ) ) |
---|
634 | { |
---|
635 | for( j = 0; j < ( pcVUI->getCpbCntMinus1( i ) + 1 ); j ++ ) |
---|
636 | { |
---|
637 | READ_UVLC( uiCode, "bit_size_value_minus1" ); pcVUI->setBitRateValueMinus1( i, j, nalOrVcl, uiCode ); |
---|
638 | READ_UVLC( uiCode, "cpb_size_value_minus1" ); pcVUI->setCpbSizeValueMinus1( i, j, nalOrVcl, uiCode ); |
---|
639 | READ_FLAG( uiCode, "cbr_flag" ); pcVUI->setCbrFlag( i, j, nalOrVcl, uiCode ); |
---|
640 | } |
---|
641 | } |
---|
642 | } |
---|
643 | } |
---|
644 | } |
---|
645 | #endif |
---|
646 | READ_FLAG( uiCode, "bitstream_restriction_flag"); pcVUI->setBitstreamRestrictionFlag(uiCode); |
---|
647 | if (pcVUI->getBitstreamRestrictionFlag()) |
---|
648 | { |
---|
649 | READ_FLAG( uiCode, "tiles_fixed_structure_flag"); pcVUI->setTilesFixedStructureFlag(uiCode); |
---|
650 | READ_FLAG( uiCode, "motion_vectors_over_pic_boundaries_flag"); pcVUI->setMotionVectorsOverPicBoundariesFlag(uiCode); |
---|
651 | READ_UVLC( uiCode, "max_bytes_per_pic_denom" ); pcVUI->setMaxBytesPerPicDenom(uiCode); |
---|
652 | READ_UVLC( uiCode, "max_bits_per_mincu_denom" ); pcVUI->setMaxBitsPerMinCuDenom(uiCode); |
---|
653 | READ_UVLC( uiCode, "log2_max_mv_length_horizontal" ); pcVUI->setLog2MaxMvLengthHorizontal(uiCode); |
---|
654 | READ_UVLC( uiCode, "log2_max_mv_length_vertical" ); pcVUI->setLog2MaxMvLengthVertical(uiCode); |
---|
655 | } |
---|
656 | } |
---|
657 | #endif |
---|
658 | |
---|
659 | Void TDecCavlc::parseSPS(TComSPS* pcSPS) |
---|
660 | { |
---|
661 | #if ENC_DEC_TRACE |
---|
662 | xTraceSPSHeader (pcSPS); |
---|
663 | #endif |
---|
664 | |
---|
665 | UInt uiCode; |
---|
666 | #if SPS_SYNTAX_CHANGES |
---|
667 | READ_CODE( 4, uiCode, "video_parameter_set_id"); pcSPS->setVPSId ( uiCode ); |
---|
668 | READ_CODE( 3, uiCode, "sps_max_sub_layers_minus1" ); pcSPS->setMaxTLayers ( uiCode+1 ); |
---|
669 | READ_FLAG( uiCode, "sps_reserved_zero_bit"); assert(uiCode == 0); |
---|
670 | parsePTL(pcSPS->getPTL(), 1, pcSPS->getMaxTLayers() - 1); |
---|
671 | READ_UVLC( uiCode, "seq_parameter_set_id" ); pcSPS->setSPSId( uiCode ); |
---|
672 | READ_UVLC( uiCode, "chroma_format_idc" ); pcSPS->setChromaFormatIdc( uiCode ); |
---|
673 | // 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 |
---|
674 | assert (uiCode == 1); |
---|
675 | if( uiCode == 3 ) |
---|
676 | { |
---|
677 | READ_FLAG( uiCode, "separate_colour_plane_flag"); assert(uiCode == 0); |
---|
678 | } |
---|
679 | |
---|
680 | #else |
---|
681 | READ_CODE( 3, uiCode, "profile_space" ); pcSPS->setProfileSpace( uiCode ); |
---|
682 | READ_CODE( 5, uiCode, "profile_idc" ); pcSPS->setProfileIdc( uiCode ); |
---|
683 | READ_CODE(16, uiCode, "reserved_indicator_flags" ); pcSPS->setRsvdIndFlags( uiCode ); |
---|
684 | READ_CODE( 8, uiCode, "level_idc" ); pcSPS->setLevelIdc( uiCode ); |
---|
685 | READ_CODE(32, uiCode, "profile_compatibility"); pcSPS->setProfileCompat( uiCode ); |
---|
686 | READ_UVLC( uiCode, "seq_parameter_set_id" ); pcSPS->setSPSId( uiCode ); |
---|
687 | READ_UVLC( uiCode, "video_parameter_set_id" ); pcSPS->setVPSId( uiCode ); |
---|
688 | READ_UVLC( uiCode, "chroma_format_idc" ); pcSPS->setChromaFormatIdc( uiCode ); |
---|
689 | READ_CODE( 3, uiCode, "max_temporal_layers_minus1" ); pcSPS->setMaxTLayers( uiCode+1 ); |
---|
690 | #endif |
---|
691 | READ_UVLC ( uiCode, "pic_width_in_luma_samples" ); pcSPS->setPicWidthInLumaSamples ( uiCode ); |
---|
692 | READ_UVLC ( uiCode, "pic_height_in_luma_samples" ); pcSPS->setPicHeightInLumaSamples( uiCode ); |
---|
693 | READ_FLAG( uiCode, "pic_cropping_flag"); pcSPS->setPicCroppingFlag ( uiCode ? true : false ); |
---|
694 | if (uiCode != 0) |
---|
695 | { |
---|
696 | READ_UVLC( uiCode, "pic_crop_left_offset" ); pcSPS->setPicCropLeftOffset ( uiCode * TComSPS::getCropUnitX( pcSPS->getChromaFormatIdc() ) ); |
---|
697 | READ_UVLC( uiCode, "pic_crop_right_offset" ); pcSPS->setPicCropRightOffset ( uiCode * TComSPS::getCropUnitX( pcSPS->getChromaFormatIdc() ) ); |
---|
698 | READ_UVLC( uiCode, "pic_crop_top_offset" ); pcSPS->setPicCropTopOffset ( uiCode * TComSPS::getCropUnitY( pcSPS->getChromaFormatIdc() ) ); |
---|
699 | READ_UVLC( uiCode, "pic_crop_bottom_offset" ); pcSPS->setPicCropBottomOffset( uiCode * TComSPS::getCropUnitY( pcSPS->getChromaFormatIdc() ) ); |
---|
700 | } |
---|
701 | |
---|
702 | #if FULL_NBIT |
---|
703 | READ_UVLC( uiCode, "bit_depth_luma_minus8" ); |
---|
704 | g_uiBitDepth = 8 + uiCode; |
---|
705 | g_uiBitIncrement = 0; |
---|
706 | pcSPS->setBitDepth(g_uiBitDepth); |
---|
707 | pcSPS->setBitIncrement(g_uiBitIncrement); |
---|
708 | UInt m_uiSaoBitIncrease = g_uiBitDepth + (g_uiBitDepth-8) - min((Int)(g_uiBitDepth + (g_uiBitDepth-8)), 10); |
---|
709 | #else |
---|
710 | READ_UVLC( uiCode, "bit_depth_luma_minus8" ); |
---|
711 | g_uiBitDepth = 8; |
---|
712 | g_uiBitIncrement = uiCode; |
---|
713 | pcSPS->setBitDepth(g_uiBitDepth); |
---|
714 | pcSPS->setBitIncrement(g_uiBitIncrement); |
---|
715 | #endif |
---|
716 | pcSPS->setQpBDOffsetY( (Int) (6*uiCode) ); |
---|
717 | |
---|
718 | g_uiBASE_MAX = ((1<<(g_uiBitDepth))-1); |
---|
719 | |
---|
720 | #if IBDI_NOCLIP_RANGE |
---|
721 | g_uiIBDI_MAX = g_uiBASE_MAX << g_uiBitIncrement; |
---|
722 | #else |
---|
723 | g_uiIBDI_MAX = ((1<<(g_uiBitDepth+g_uiBitIncrement))-1); |
---|
724 | #endif |
---|
725 | READ_UVLC( uiCode, "bit_depth_chroma_minus8" ); |
---|
726 | pcSPS->setQpBDOffsetC( (Int) (6*uiCode) ); |
---|
727 | |
---|
728 | READ_FLAG( uiCode, "pcm_enabled_flag" ); pcSPS->setUsePCM( uiCode ? true : false ); |
---|
729 | |
---|
730 | if( pcSPS->getUsePCM() ) |
---|
731 | { |
---|
732 | READ_CODE( 4, uiCode, "pcm_bit_depth_luma_minus1" ); pcSPS->setPCMBitDepthLuma ( 1 + uiCode ); |
---|
733 | READ_CODE( 4, uiCode, "pcm_bit_depth_chroma_minus1" ); pcSPS->setPCMBitDepthChroma ( 1 + uiCode ); |
---|
734 | } |
---|
735 | |
---|
736 | READ_UVLC( uiCode, "log2_max_pic_order_cnt_lsb_minus4" ); pcSPS->setBitsForPOC( 4 + uiCode ); |
---|
737 | for(UInt i=0; i <= pcSPS->getMaxTLayers()-1; i++) |
---|
738 | { |
---|
739 | READ_UVLC ( uiCode, "max_dec_pic_buffering"); |
---|
740 | pcSPS->setMaxDecPicBuffering( uiCode, i); |
---|
741 | READ_UVLC ( uiCode, "num_reorder_pics" ); |
---|
742 | pcSPS->setNumReorderPics(uiCode, i); |
---|
743 | READ_UVLC ( uiCode, "max_latency_increase"); |
---|
744 | pcSPS->setMaxLatencyIncrease( uiCode, i ); |
---|
745 | } |
---|
746 | |
---|
747 | READ_FLAG( uiCode, "restricted_ref_pic_lists_flag" ); |
---|
748 | pcSPS->setRestrictedRefPicListsFlag( uiCode ); |
---|
749 | if( pcSPS->getRestrictedRefPicListsFlag() ) |
---|
750 | { |
---|
751 | READ_FLAG( uiCode, "lists_modification_present_flag" ); |
---|
752 | pcSPS->setListsModificationPresentFlag(uiCode); |
---|
753 | } |
---|
754 | else |
---|
755 | { |
---|
756 | pcSPS->setListsModificationPresentFlag(true); |
---|
757 | } |
---|
758 | READ_UVLC( uiCode, "log2_min_coding_block_size_minus3" ); |
---|
759 | UInt log2MinCUSize = uiCode + 3; |
---|
760 | READ_UVLC( uiCode, "log2_diff_max_min_coding_block_size" ); |
---|
761 | UInt uiMaxCUDepthCorrect = uiCode; |
---|
762 | pcSPS->setMaxCUWidth ( 1<<(log2MinCUSize + uiMaxCUDepthCorrect) ); g_uiMaxCUWidth = 1<<(log2MinCUSize + uiMaxCUDepthCorrect); |
---|
763 | pcSPS->setMaxCUHeight ( 1<<(log2MinCUSize + uiMaxCUDepthCorrect) ); g_uiMaxCUHeight = 1<<(log2MinCUSize + uiMaxCUDepthCorrect); |
---|
764 | READ_UVLC( uiCode, "log2_min_transform_block_size_minus2" ); pcSPS->setQuadtreeTULog2MinSize( uiCode + 2 ); |
---|
765 | |
---|
766 | READ_UVLC( uiCode, "log2_diff_max_min_transform_block_size" ); pcSPS->setQuadtreeTULog2MaxSize( uiCode + pcSPS->getQuadtreeTULog2MinSize() ); |
---|
767 | pcSPS->setMaxTrSize( 1<<(uiCode + pcSPS->getQuadtreeTULog2MinSize()) ); |
---|
768 | if( pcSPS->getUsePCM() ) |
---|
769 | { |
---|
770 | READ_UVLC( uiCode, "log2_min_pcm_coding_block_size_minus3" ); pcSPS->setPCMLog2MinSize (uiCode+3); |
---|
771 | READ_UVLC( uiCode, "log2_diff_max_min_pcm_coding_block_size" ); pcSPS->setPCMLog2MaxSize ( uiCode+pcSPS->getPCMLog2MinSize() ); |
---|
772 | } |
---|
773 | |
---|
774 | READ_UVLC( uiCode, "max_transform_hierarchy_depth_inter" ); pcSPS->setQuadtreeTUMaxDepthInter( uiCode+1 ); |
---|
775 | READ_UVLC( uiCode, "max_transform_hierarchy_depth_intra" ); pcSPS->setQuadtreeTUMaxDepthIntra( uiCode+1 ); |
---|
776 | g_uiAddCUDepth = 0; |
---|
777 | while( ( pcSPS->getMaxCUWidth() >> uiMaxCUDepthCorrect ) > ( 1 << ( pcSPS->getQuadtreeTULog2MinSize() + g_uiAddCUDepth ) ) ) |
---|
778 | { |
---|
779 | g_uiAddCUDepth++; |
---|
780 | } |
---|
781 | pcSPS->setMaxCUDepth( uiMaxCUDepthCorrect+g_uiAddCUDepth ); |
---|
782 | g_uiMaxCUDepth = uiMaxCUDepthCorrect+g_uiAddCUDepth; |
---|
783 | // BB: these parameters may be removed completly and replaced by the fixed values |
---|
784 | pcSPS->setMinTrDepth( 0 ); |
---|
785 | pcSPS->setMaxTrDepth( 1 ); |
---|
786 | READ_FLAG( uiCode, "scaling_list_enabled_flag" ); pcSPS->setScalingListFlag ( uiCode ); |
---|
787 | if(pcSPS->getScalingListFlag()) |
---|
788 | { |
---|
789 | READ_FLAG( uiCode, "sps_scaling_list_data_present_flag" ); pcSPS->setScalingListPresentFlag ( uiCode ); |
---|
790 | if(pcSPS->getScalingListPresentFlag ()) |
---|
791 | { |
---|
792 | parseScalingList( pcSPS->getScalingList() ); |
---|
793 | } |
---|
794 | } |
---|
795 | #if !REMOVE_LMCHROMA |
---|
796 | READ_FLAG( uiCode, "chroma_pred_from_luma_enabled_flag" ); pcSPS->setUseLMChroma ( uiCode ? true : false ); |
---|
797 | #endif |
---|
798 | #if !PPS_TS_FLAG |
---|
799 | READ_FLAG( uiCode, "transform_skip_enabled_flag" ); pcSPS->setUseTransformSkip ( uiCode ? true : false ); |
---|
800 | #endif |
---|
801 | #if !MOVE_LOOP_FILTER_SLICES_FLAG |
---|
802 | READ_FLAG( uiCode, "loop_filter_across_slice_flag" ); pcSPS->setLFCrossSliceBoundaryFlag( uiCode ? true : false); |
---|
803 | #endif |
---|
804 | READ_FLAG( uiCode, "asymmetric_motion_partitions_enabled_flag" ); pcSPS->setUseAMP( uiCode ); |
---|
805 | #if !REMOVE_NSQT |
---|
806 | READ_FLAG( uiCode, "non_square_quadtree_enabled_flag" ); pcSPS->setUseNSQT( uiCode ); |
---|
807 | #endif |
---|
808 | READ_FLAG( uiCode, "sample_adaptive_offset_enabled_flag" ); pcSPS->setUseSAO ( uiCode ? true : false ); |
---|
809 | #if !REMOVE_ALF |
---|
810 | READ_FLAG( uiCode, "adaptive_loop_filter_enabled_flag" ); pcSPS->setUseALF ( uiCode ? true : false ); |
---|
811 | #endif |
---|
812 | if( pcSPS->getUsePCM() ) |
---|
813 | { |
---|
814 | READ_FLAG( uiCode, "pcm_loop_filter_disable_flag" ); pcSPS->setPCMFilterDisableFlag ( uiCode ? true : false ); |
---|
815 | } |
---|
816 | |
---|
817 | READ_FLAG( uiCode, "temporal_id_nesting_flag" ); pcSPS->setTemporalIdNestingFlag ( uiCode > 0 ? true : false ); |
---|
818 | |
---|
819 | READ_UVLC( uiCode, "num_short_term_ref_pic_sets" ); |
---|
820 | pcSPS->createRPSList(uiCode); |
---|
821 | |
---|
822 | TComRPSList* rpsList = pcSPS->getRPSList(); |
---|
823 | TComReferencePictureSet* rps; |
---|
824 | |
---|
825 | for(UInt i=0; i< rpsList->getNumberOfReferencePictureSets(); i++) |
---|
826 | { |
---|
827 | rps = rpsList->getReferencePictureSet(i); |
---|
828 | parseShortTermRefPicSet(pcSPS,rps,i); |
---|
829 | } |
---|
830 | READ_FLAG( uiCode, "long_term_ref_pics_present_flag" ); pcSPS->setLongTermRefsPresent(uiCode); |
---|
831 | #if LTRP_IN_SPS |
---|
832 | if (pcSPS->getLongTermRefsPresent()) |
---|
833 | { |
---|
834 | READ_UVLC( uiCode, "num_long_term_ref_pic_sps" ); |
---|
835 | pcSPS->setNumLongTermRefPicSPS(uiCode); |
---|
836 | for (UInt k = 0; k < pcSPS->getNumLongTermRefPicSPS(); k++) |
---|
837 | { |
---|
838 | READ_CODE( pcSPS->getBitsForPOC(), uiCode, "lt_ref_pic_poc_lsb_sps" ); |
---|
839 | pcSPS->setLtRefPicPocLsbSps(uiCode, k); |
---|
840 | READ_FLAG( uiCode, "used_by_curr_pic_lt_sps_flag[i]"); |
---|
841 | pcSPS->setUsedByCurrPicLtSPSFlag(k, uiCode?1:0); |
---|
842 | } |
---|
843 | } |
---|
844 | #endif |
---|
845 | READ_FLAG( uiCode, "sps_temporal_mvp_enable_flag" ); pcSPS->setTMVPFlagsPresent(uiCode); |
---|
846 | #if REF_IDX_MFM |
---|
847 | if(pcSPS->getLayerId() > 0) |
---|
848 | { |
---|
849 | READ_FLAG( uiCode, "sps_enh_mfm_enable_flag" ); |
---|
850 | pcSPS->setMFMEnabledFlag( uiCode ? true : false ); |
---|
851 | assert(pcSPS->getMFMEnabledFlag()); |
---|
852 | } |
---|
853 | #endif |
---|
854 | #if SUPPORT_FOR_VUI |
---|
855 | READ_FLAG( uiCode, "vui_parameters_present_flag" ); pcSPS->setVuiParametersPresentFlag(uiCode); |
---|
856 | |
---|
857 | if (pcSPS->getVuiParametersPresentFlag()) |
---|
858 | { |
---|
859 | #if !BUFFERING_PERIOD_AND_TIMING_SEI |
---|
860 | parseVUI(pcSPS->getVuiParameters()); |
---|
861 | #else |
---|
862 | parseVUI(pcSPS->getVuiParameters(), pcSPS); |
---|
863 | #endif |
---|
864 | } |
---|
865 | #endif |
---|
866 | #if !SPS_AMVP_CLEANUP |
---|
867 | // AMVP mode for each depth (AM_NONE or AM_EXPL) |
---|
868 | for (Int i = 0; i < pcSPS->getMaxCUDepth(); i++) |
---|
869 | { |
---|
870 | xReadFlag( uiCode ); |
---|
871 | pcSPS->setAMVPMode( i, (AMVP_MODE)uiCode ); |
---|
872 | } |
---|
873 | #endif |
---|
874 | READ_FLAG( uiCode, "sps_extension_flag"); |
---|
875 | if (uiCode) |
---|
876 | { |
---|
877 | while ( xMoreRbspData() ) |
---|
878 | { |
---|
879 | READ_FLAG( uiCode, "sps_extension_data_flag"); |
---|
880 | } |
---|
881 | } |
---|
882 | } |
---|
883 | |
---|
884 | Void TDecCavlc::parseVPS(TComVPS* pcVPS) |
---|
885 | { |
---|
886 | UInt uiCode; |
---|
887 | |
---|
888 | #if VPS_SYNTAX_CHANGES |
---|
889 | READ_CODE( 4, uiCode, "video_parameter_set_id" ); pcVPS->setVPSId( uiCode ); |
---|
890 | READ_FLAG( uiCode, "vps_temporal_id_nesting_flag" ); pcVPS->setTemporalNestingFlag( uiCode ? true:false ); |
---|
891 | READ_CODE( 2, uiCode, "vps_reserved_zero_2bits" ); assert(uiCode == 0); |
---|
892 | READ_CODE( 6, uiCode, "vps_reserved_zero_6bits" ); assert(uiCode == 0); |
---|
893 | READ_CODE( 3, uiCode, "vps_max_sub_layers_minus1" ); pcVPS->setMaxTLayers( uiCode + 1 ); |
---|
894 | parsePTL ( pcVPS->getPTL(), true, pcVPS->getMaxTLayers()-1); |
---|
895 | READ_CODE( 12, uiCode, "vps_reserved_zero_12bits" ); assert(uiCode == 0); |
---|
896 | #else |
---|
897 | READ_CODE( 3, uiCode, "vps_max_temporal_layers_minus1" ); pcVPS->setMaxTLayers( uiCode + 1 ); |
---|
898 | READ_CODE( 5, uiCode, "vps_max_layers_minus1" ); pcVPS->setMaxLayers( uiCode + 1 ); |
---|
899 | READ_UVLC( uiCode, "video_parameter_set_id" ); pcVPS->setVPSId( uiCode ); |
---|
900 | READ_FLAG( uiCode, "vps_temporal_id_nesting_flag" ); pcVPS->setTemporalNestingFlag( uiCode ? true:false ); |
---|
901 | #endif |
---|
902 | for(UInt i = 0; i <= pcVPS->getMaxTLayers()-1; i++) |
---|
903 | { |
---|
904 | READ_UVLC( uiCode, "vps_max_dec_pic_buffering[i]" ); pcVPS->setMaxDecPicBuffering( uiCode, i ); |
---|
905 | READ_UVLC( uiCode, "vps_num_reorder_pics[i]" ); pcVPS->setNumReorderPics( uiCode, i ); |
---|
906 | READ_UVLC( uiCode, "vps_max_latency_increase[i]" ); pcVPS->setMaxLatencyIncrease( uiCode, i ); |
---|
907 | } |
---|
908 | #if VPS_SYNTAX_CHANGES |
---|
909 | READ_UVLC( uiCode, "vps_num_hrd_parameters" ); assert(uiCode == 0); |
---|
910 | // hrd_parameters |
---|
911 | #endif |
---|
912 | READ_FLAG( uiCode, "vps_extension_flag" ); assert(!uiCode); |
---|
913 | //future extensions go here.. |
---|
914 | |
---|
915 | return; |
---|
916 | } |
---|
917 | |
---|
918 | Void TDecCavlc::parseSliceHeader (TComSlice*& rpcSlice, ParameterSetManagerDecoder *parameterSetManager) |
---|
919 | { |
---|
920 | UInt uiCode; |
---|
921 | Int iCode; |
---|
922 | |
---|
923 | #if ENC_DEC_TRACE |
---|
924 | xTraceSliceHeader(rpcSlice); |
---|
925 | #endif |
---|
926 | TComPPS* pps = NULL; |
---|
927 | TComSPS* sps = NULL; |
---|
928 | |
---|
929 | UInt firstSliceInPic; |
---|
930 | READ_FLAG( firstSliceInPic, "first_slice_in_pic_flag" ); |
---|
931 | #if SPLICING_FRIENDLY_PARAMS |
---|
932 | if( rpcSlice->getRapPicFlag()) |
---|
933 | { |
---|
934 | READ_FLAG( uiCode, "no_output_of_prior_pics_flag" ); //ignored |
---|
935 | } |
---|
936 | #endif |
---|
937 | READ_UVLC ( uiCode, "pic_parameter_set_id" ); rpcSlice->setPPSId(uiCode); |
---|
938 | pps = parameterSetManager->getPrefetchedPPS(uiCode); |
---|
939 | //!KS: need to add error handling code here, if PPS is not available |
---|
940 | assert(pps!=0); |
---|
941 | sps = parameterSetManager->getPrefetchedSPS(pps->getSPSId()); |
---|
942 | //!KS: need to add error handling code here, if SPS is not available |
---|
943 | assert(sps!=0); |
---|
944 | rpcSlice->setSPS(sps); |
---|
945 | rpcSlice->setPPS(pps); |
---|
946 | |
---|
947 | Int numCUs = ((sps->getPicWidthInLumaSamples()+sps->getMaxCUWidth()-1)/sps->getMaxCUWidth())*((sps->getPicHeightInLumaSamples()+sps->getMaxCUHeight()-1)/sps->getMaxCUHeight()); |
---|
948 | Int maxParts = (1<<(sps->getMaxCUDepth()<<1)); |
---|
949 | #if REMOVE_FGS |
---|
950 | Int numParts = 0; |
---|
951 | #else |
---|
952 | Int numParts = (1<<(pps->getSliceGranularity()<<1)); |
---|
953 | #endif |
---|
954 | UInt lCUAddress = 0; |
---|
955 | Int reqBitsOuter = 0; |
---|
956 | while(numCUs>(1<<reqBitsOuter)) |
---|
957 | { |
---|
958 | reqBitsOuter++; |
---|
959 | } |
---|
960 | Int reqBitsInner = 0; |
---|
961 | while((numParts)>(1<<reqBitsInner)) |
---|
962 | { |
---|
963 | reqBitsInner++; |
---|
964 | } |
---|
965 | |
---|
966 | UInt innerAddress = 0; |
---|
967 | Int sliceAddress = 0; |
---|
968 | if(!firstSliceInPic) |
---|
969 | { |
---|
970 | UInt address; |
---|
971 | READ_CODE( reqBitsOuter+reqBitsInner, address, "slice_address" ); |
---|
972 | lCUAddress = address >> reqBitsInner; |
---|
973 | innerAddress = address - (lCUAddress<<reqBitsInner); |
---|
974 | } |
---|
975 | //set uiCode to equal slice start address (or dependent slice start address) |
---|
976 | #if REMOVE_FGS |
---|
977 | sliceAddress=(maxParts*lCUAddress)+(innerAddress); |
---|
978 | #else |
---|
979 | sliceAddress=(maxParts*lCUAddress)+(innerAddress*(maxParts>>(pps->getSliceGranularity()<<1))); |
---|
980 | #endif |
---|
981 | rpcSlice->setDependentSliceCurStartCUAddr( sliceAddress ); |
---|
982 | rpcSlice->setDependentSliceCurEndCUAddr(numCUs*maxParts); |
---|
983 | |
---|
984 | #if SLICEHEADER_SYNTAX_FIX |
---|
985 | if( pps->getDependentSliceEnabledFlag() && (sliceAddress !=0 )) |
---|
986 | { |
---|
987 | READ_FLAG( uiCode, "dependent_slice_flag" ); rpcSlice->setDependentSliceFlag(uiCode ? true : false); |
---|
988 | } |
---|
989 | else |
---|
990 | { |
---|
991 | rpcSlice->setDependentSliceFlag(false); |
---|
992 | } |
---|
993 | |
---|
994 | if (rpcSlice->getDependentSliceFlag()) |
---|
995 | { |
---|
996 | rpcSlice->setNextSlice ( false ); |
---|
997 | rpcSlice->setNextDependentSlice ( true ); |
---|
998 | } |
---|
999 | else |
---|
1000 | { |
---|
1001 | rpcSlice->setNextSlice ( true ); |
---|
1002 | rpcSlice->setNextDependentSlice ( false ); |
---|
1003 | |
---|
1004 | rpcSlice->setSliceCurStartCUAddr(sliceAddress); |
---|
1005 | rpcSlice->setSliceCurEndCUAddr(numCUs*maxParts); |
---|
1006 | } |
---|
1007 | |
---|
1008 | if(!rpcSlice->getDependentSliceFlag()) |
---|
1009 | { |
---|
1010 | #endif |
---|
1011 | READ_UVLC ( uiCode, "slice_type" ); rpcSlice->setSliceType((SliceType)uiCode); |
---|
1012 | #if !SLICEHEADER_SYNTAX_FIX |
---|
1013 | // lightweight_slice_flag |
---|
1014 | READ_FLAG( uiCode, "dependent_slice_flag" ); |
---|
1015 | Bool bDependentSlice = uiCode ? true : false; |
---|
1016 | #if DEPENDENT_SLICES |
---|
1017 | if( rpcSlice->getPPS()->getDependentSliceEnabledFlag()) |
---|
1018 | { |
---|
1019 | if(bDependentSlice) |
---|
1020 | { |
---|
1021 | rpcSlice->setNextSlice ( false ); |
---|
1022 | rpcSlice->setNextDependentSlice( true ); |
---|
1023 | #if BYTE_ALIGNMENT |
---|
1024 | m_pcBitstream->readByteAlignment(); |
---|
1025 | #else |
---|
1026 | m_pcBitstream->readOutTrailingBits(); |
---|
1027 | #endif |
---|
1028 | return; |
---|
1029 | } |
---|
1030 | } |
---|
1031 | #endif |
---|
1032 | if (bDependentSlice) |
---|
1033 | { |
---|
1034 | rpcSlice->setNextSlice ( false ); |
---|
1035 | rpcSlice->setNextDependentSlice ( true ); |
---|
1036 | } |
---|
1037 | else |
---|
1038 | { |
---|
1039 | rpcSlice->setNextSlice ( true ); |
---|
1040 | rpcSlice->setNextDependentSlice ( false ); |
---|
1041 | |
---|
1042 | rpcSlice->setSliceCurStartCUAddr(sliceAddress); |
---|
1043 | rpcSlice->setSliceCurEndCUAddr(numCUs*maxParts); |
---|
1044 | } |
---|
1045 | |
---|
1046 | if (!bDependentSlice) |
---|
1047 | { |
---|
1048 | #endif // !SLICEHEADER_SYNTAX_FIX |
---|
1049 | if( pps->getOutputFlagPresentFlag() ) |
---|
1050 | { |
---|
1051 | READ_FLAG( uiCode, "pic_output_flag" ); rpcSlice->setPicOutputFlag( uiCode ? true : false ); |
---|
1052 | } |
---|
1053 | else |
---|
1054 | { |
---|
1055 | rpcSlice->setPicOutputFlag( true ); |
---|
1056 | } |
---|
1057 | // in the first version chroma_format_idc is equal to one, thus colour_plane_id will not be present |
---|
1058 | assert (sps->getChromaFormatIdc() == 1 ); |
---|
1059 | // if( separate_colour_plane_flag == 1 ) |
---|
1060 | // colour_plane_id u(2) |
---|
1061 | |
---|
1062 | #if !SPLICING_FRIENDLY_PARAMS |
---|
1063 | if( rpcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR |
---|
1064 | #if SUPPORT_FOR_RAP_N_LP |
---|
1065 | || rpcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_N_LP |
---|
1066 | || rpcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_N_LP |
---|
1067 | #endif |
---|
1068 | || rpcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLANT |
---|
1069 | || rpcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA |
---|
1070 | #if !NAL_UNIT_TYPES_J1003_D7 |
---|
1071 | || rpcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_CRANT |
---|
1072 | #endif |
---|
1073 | || rpcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_CRA ) |
---|
1074 | { |
---|
1075 | READ_UVLC( uiCode, "rap_pic_id" ); //ignored |
---|
1076 | READ_FLAG( uiCode, "no_output_of_prior_pics_flag" ); //ignored |
---|
1077 | } |
---|
1078 | #endif |
---|
1079 | #if SUPPORT_FOR_RAP_N_LP |
---|
1080 | if( rpcSlice->getIdrPicFlag() ) |
---|
1081 | #else |
---|
1082 | if( rpcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR ) |
---|
1083 | #endif |
---|
1084 | { |
---|
1085 | rpcSlice->setPOC(0); |
---|
1086 | TComReferencePictureSet* rps = rpcSlice->getLocalRPS(); |
---|
1087 | rps->setNumberOfNegativePictures(0); |
---|
1088 | rps->setNumberOfPositivePictures(0); |
---|
1089 | rps->setNumberOfLongtermPictures(0); |
---|
1090 | rps->setNumberOfPictures(0); |
---|
1091 | rpcSlice->setRPS(rps); |
---|
1092 | } |
---|
1093 | else |
---|
1094 | { |
---|
1095 | READ_CODE(sps->getBitsForPOC(), uiCode, "pic_order_cnt_lsb"); |
---|
1096 | Int iPOClsb = uiCode; |
---|
1097 | Int iPrevPOC = rpcSlice->getPrevPOC(); |
---|
1098 | Int iMaxPOClsb = 1<< sps->getBitsForPOC(); |
---|
1099 | Int iPrevPOClsb = iPrevPOC%iMaxPOClsb; |
---|
1100 | Int iPrevPOCmsb = iPrevPOC-iPrevPOClsb; |
---|
1101 | Int iPOCmsb; |
---|
1102 | if( ( iPOClsb < iPrevPOClsb ) && ( ( iPrevPOClsb - iPOClsb ) >= ( iMaxPOClsb / 2 ) ) ) |
---|
1103 | { |
---|
1104 | iPOCmsb = iPrevPOCmsb + iMaxPOClsb; |
---|
1105 | } |
---|
1106 | else if( (iPOClsb > iPrevPOClsb ) && ( (iPOClsb - iPrevPOClsb ) > ( iMaxPOClsb / 2 ) ) ) |
---|
1107 | { |
---|
1108 | iPOCmsb = iPrevPOCmsb - iMaxPOClsb; |
---|
1109 | } |
---|
1110 | else |
---|
1111 | { |
---|
1112 | iPOCmsb = iPrevPOCmsb; |
---|
1113 | } |
---|
1114 | #if SUPPORT_FOR_RAP_N_LP |
---|
1115 | if ( rpcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA |
---|
1116 | || rpcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLANT |
---|
1117 | || rpcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_N_LP ) |
---|
1118 | #else |
---|
1119 | if( rpcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA |
---|
1120 | || rpcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLANT ) |
---|
1121 | #endif |
---|
1122 | { |
---|
1123 | // For BLA picture types, POCmsb is set to 0. |
---|
1124 | iPOCmsb = 0; |
---|
1125 | } |
---|
1126 | rpcSlice->setPOC (iPOCmsb+iPOClsb); |
---|
1127 | |
---|
1128 | TComReferencePictureSet* rps; |
---|
1129 | READ_FLAG( uiCode, "short_term_ref_pic_set_sps_flag" ); |
---|
1130 | if(uiCode == 0) // use short-term reference picture set explicitly signalled in slice header |
---|
1131 | { |
---|
1132 | rps = rpcSlice->getLocalRPS(); |
---|
1133 | parseShortTermRefPicSet(sps,rps, sps->getRPSList()->getNumberOfReferencePictureSets()); |
---|
1134 | rpcSlice->setRPS(rps); |
---|
1135 | } |
---|
1136 | else // use reference to short-term reference picture set in PPS |
---|
1137 | { |
---|
1138 | READ_UVLC( uiCode, "short_term_ref_pic_set_idx"); rpcSlice->setRPS(sps->getRPSList()->getReferencePictureSet(uiCode)); |
---|
1139 | rps = rpcSlice->getRPS(); |
---|
1140 | } |
---|
1141 | if(sps->getLongTermRefsPresent()) |
---|
1142 | { |
---|
1143 | Int offset = rps->getNumberOfNegativePictures()+rps->getNumberOfPositivePictures(); |
---|
1144 | #if LTRP_IN_SPS |
---|
1145 | UInt numOfLtrp = 0; |
---|
1146 | UInt numLtrpInSPS = 0; |
---|
1147 | if (rpcSlice->getSPS()->getNumLongTermRefPicSPS() > 0) |
---|
1148 | { |
---|
1149 | READ_UVLC( uiCode, "num_long_term_sps"); |
---|
1150 | numLtrpInSPS = uiCode; |
---|
1151 | numOfLtrp += numLtrpInSPS; |
---|
1152 | rps->setNumberOfLongtermPictures(numOfLtrp); |
---|
1153 | } |
---|
1154 | Int bitsForLtrpInSPS = 1; |
---|
1155 | while (rpcSlice->getSPS()->getNumLongTermRefPicSPS() > (1 << bitsForLtrpInSPS)) |
---|
1156 | bitsForLtrpInSPS++; |
---|
1157 | READ_UVLC( uiCode, "num_long_term_pics"); rps->setNumberOfLongtermPictures(uiCode); |
---|
1158 | numOfLtrp += uiCode; |
---|
1159 | rps->setNumberOfLongtermPictures(numOfLtrp); |
---|
1160 | #else |
---|
1161 | READ_UVLC( uiCode, "num_long_term_pics"); rps->setNumberOfLongtermPictures(uiCode); |
---|
1162 | #endif |
---|
1163 | Int maxPicOrderCntLSB = 1 << rpcSlice->getSPS()->getBitsForPOC(); |
---|
1164 | Int prevLSB = 0, prevDeltaMSB = 0, deltaPocMSBCycleLT = 0;; |
---|
1165 | #if LTRP_IN_SPS |
---|
1166 | for(Int j=offset+rps->getNumberOfLongtermPictures()-1, k = 0; k < numOfLtrp; j--, k++) |
---|
1167 | #else |
---|
1168 | for(Int j=offset+rps->getNumberOfLongtermPictures()-1 ; j > offset-1; j--) |
---|
1169 | #endif |
---|
1170 | { |
---|
1171 | #if LTRP_IN_SPS |
---|
1172 | if (k < numLtrpInSPS) |
---|
1173 | { |
---|
1174 | READ_CODE(bitsForLtrpInSPS, uiCode, "lt_idx_sps[i]"); |
---|
1175 | Int usedByCurrFromSPS=rpcSlice->getSPS()->getUsedByCurrPicLtSPSFlag(uiCode); |
---|
1176 | |
---|
1177 | uiCode = rpcSlice->getSPS()->getLtRefPicPocLsbSps(uiCode); |
---|
1178 | rps->setUsed(j,usedByCurrFromSPS); |
---|
1179 | } |
---|
1180 | else |
---|
1181 | { |
---|
1182 | READ_CODE(rpcSlice->getSPS()->getBitsForPOC(), uiCode, "poc_lsb_lt"); |
---|
1183 | READ_FLAG( uiCode, "used_by_curr_pic_lt_flag"); rps->setUsed(j,uiCode); |
---|
1184 | } |
---|
1185 | #else |
---|
1186 | READ_CODE(rpcSlice->getSPS()->getBitsForPOC(), uiCode, "poc_lsb_lt"); |
---|
1187 | #endif |
---|
1188 | Int poc_lsb_lt = uiCode; |
---|
1189 | READ_FLAG(uiCode,"delta_poc_msb_present_flag"); |
---|
1190 | Bool mSBPresentFlag = uiCode ? true : false; |
---|
1191 | if(mSBPresentFlag) |
---|
1192 | { |
---|
1193 | READ_UVLC( uiCode, "delta_poc_msb_cycle_lt[i]" ); |
---|
1194 | Bool deltaFlag = false; |
---|
1195 | #if LTRP_IN_SPS |
---|
1196 | // First LTRP || First LTRP from SH || curr LSB != prev LSB |
---|
1197 | if( (j == offset+rps->getNumberOfLongtermPictures()-1) || (j == offset+(numOfLtrp-numLtrpInSPS)-1) || (poc_lsb_lt != prevLSB) ) |
---|
1198 | #else |
---|
1199 | // First LTRP || curr LSB != prev LSB |
---|
1200 | if( (j == offset+rps->getNumberOfLongtermPictures()-1) || (poc_lsb_lt != prevLSB) ) |
---|
1201 | #endif |
---|
1202 | { |
---|
1203 | deltaFlag = true; |
---|
1204 | } |
---|
1205 | if(deltaFlag) |
---|
1206 | { |
---|
1207 | deltaPocMSBCycleLT = uiCode; |
---|
1208 | } |
---|
1209 | else |
---|
1210 | { |
---|
1211 | deltaPocMSBCycleLT = uiCode + prevDeltaMSB; |
---|
1212 | } |
---|
1213 | |
---|
1214 | Int pocLTCurr = rpcSlice->getPOC() - deltaPocMSBCycleLT * maxPicOrderCntLSB |
---|
1215 | - iPOClsb + poc_lsb_lt; |
---|
1216 | rps->setPOC (j, pocLTCurr); |
---|
1217 | rps->setDeltaPOC(j, - rpcSlice->getPOC() + pocLTCurr); |
---|
1218 | rps->setCheckLTMSBPresent(j,true); |
---|
1219 | } |
---|
1220 | else |
---|
1221 | { |
---|
1222 | rps->setPOC (j, poc_lsb_lt); |
---|
1223 | rps->setDeltaPOC(j, - rpcSlice->getPOC() + poc_lsb_lt); |
---|
1224 | rps->setCheckLTMSBPresent(j,false); |
---|
1225 | } |
---|
1226 | #if !LTRP_IN_SPS |
---|
1227 | READ_FLAG( uiCode, "used_by_curr_pic_lt_flag"); rps->setUsed(j,uiCode); |
---|
1228 | #endif |
---|
1229 | prevLSB = poc_lsb_lt; |
---|
1230 | prevDeltaMSB = deltaPocMSBCycleLT; |
---|
1231 | } |
---|
1232 | offset += rps->getNumberOfLongtermPictures(); |
---|
1233 | rps->setNumberOfPictures(offset); |
---|
1234 | } |
---|
1235 | #if SUPPORT_FOR_RAP_N_LP |
---|
1236 | if ( rpcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA |
---|
1237 | || rpcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLANT |
---|
1238 | || rpcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_N_LP ) |
---|
1239 | #else |
---|
1240 | if( rpcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA |
---|
1241 | || rpcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLANT ) |
---|
1242 | #endif |
---|
1243 | { |
---|
1244 | // In the case of BLA picture types, rps data is read from slice header but ignored |
---|
1245 | rps = rpcSlice->getLocalRPS(); |
---|
1246 | rps->setNumberOfNegativePictures(0); |
---|
1247 | rps->setNumberOfPositivePictures(0); |
---|
1248 | rps->setNumberOfLongtermPictures(0); |
---|
1249 | rps->setNumberOfPictures(0); |
---|
1250 | rpcSlice->setRPS(rps); |
---|
1251 | } |
---|
1252 | } |
---|
1253 | #if REMOVE_ALF |
---|
1254 | if(sps->getUseSAO()) |
---|
1255 | #else |
---|
1256 | if(sps->getUseSAO() || sps->getUseALF()) |
---|
1257 | #endif |
---|
1258 | { |
---|
1259 | if (sps->getUseSAO()) |
---|
1260 | { |
---|
1261 | READ_FLAG(uiCode, "slice_sao_luma_flag"); rpcSlice->setSaoEnabledFlag((Bool)uiCode); |
---|
1262 | #if !SAO_LUM_CHROMA_ONOFF_FLAGS |
---|
1263 | if (rpcSlice->getSaoEnabledFlag() ) |
---|
1264 | #endif |
---|
1265 | { |
---|
1266 | #if SAO_TYPE_SHARING |
---|
1267 | READ_FLAG(uiCode, "slice_sao_chroma_flag"); rpcSlice->setSaoEnabledFlagChroma((Bool)uiCode); |
---|
1268 | #else |
---|
1269 | READ_FLAG(uiCode, "sao_cb_enable_flag"); rpcSlice->setSaoEnabledFlagCb((Bool)uiCode); |
---|
1270 | READ_FLAG(uiCode, "sao_cr_enable_flag"); rpcSlice->setSaoEnabledFlagCr((Bool)uiCode); |
---|
1271 | #endif |
---|
1272 | } |
---|
1273 | #if !SAO_LUM_CHROMA_ONOFF_FLAGS |
---|
1274 | else |
---|
1275 | { |
---|
1276 | #if SAO_TYPE_SHARING |
---|
1277 | rpcSlice->setSaoEnabledFlagChroma(0); |
---|
1278 | #else |
---|
1279 | rpcSlice->setSaoEnabledFlagCb(0); |
---|
1280 | rpcSlice->setSaoEnabledFlagCr(0); |
---|
1281 | #endif |
---|
1282 | } |
---|
1283 | #endif |
---|
1284 | } |
---|
1285 | #if !REMOVE_APS |
---|
1286 | READ_UVLC ( uiCode, "aps_id" ); rpcSlice->setAPSId(uiCode); |
---|
1287 | #endif |
---|
1288 | } |
---|
1289 | if (!rpcSlice->isIntra()) |
---|
1290 | { |
---|
1291 | if (rpcSlice->getSPS()->getTMVPFlagsPresent()) |
---|
1292 | { |
---|
1293 | READ_FLAG( uiCode, "enable_temporal_mvp_flag" ); |
---|
1294 | rpcSlice->setEnableTMVPFlag(uiCode); |
---|
1295 | } |
---|
1296 | else |
---|
1297 | { |
---|
1298 | rpcSlice->setEnableTMVPFlag(false); |
---|
1299 | } |
---|
1300 | READ_FLAG( uiCode, "num_ref_idx_active_override_flag"); |
---|
1301 | if (uiCode) |
---|
1302 | { |
---|
1303 | READ_UVLC (uiCode, "num_ref_idx_l0_active_minus1" ); rpcSlice->setNumRefIdx( REF_PIC_LIST_0, uiCode + 1 ); |
---|
1304 | if (rpcSlice->isInterB()) |
---|
1305 | { |
---|
1306 | READ_UVLC (uiCode, "num_ref_idx_l1_active_minus1" ); rpcSlice->setNumRefIdx( REF_PIC_LIST_1, uiCode + 1 ); |
---|
1307 | } |
---|
1308 | else |
---|
1309 | { |
---|
1310 | rpcSlice->setNumRefIdx(REF_PIC_LIST_1, 0); |
---|
1311 | } |
---|
1312 | } |
---|
1313 | else |
---|
1314 | { |
---|
1315 | rpcSlice->setNumRefIdx(REF_PIC_LIST_0, rpcSlice->getPPS()->getNumRefIdxL0DefaultActive()); |
---|
1316 | if (rpcSlice->isInterB()) |
---|
1317 | { |
---|
1318 | rpcSlice->setNumRefIdx(REF_PIC_LIST_1, rpcSlice->getPPS()->getNumRefIdxL1DefaultActive()); |
---|
1319 | } |
---|
1320 | else |
---|
1321 | { |
---|
1322 | rpcSlice->setNumRefIdx(REF_PIC_LIST_1,0); |
---|
1323 | } |
---|
1324 | } |
---|
1325 | } |
---|
1326 | // } |
---|
1327 | TComRefPicListModification* refPicListModification = rpcSlice->getRefPicListModification(); |
---|
1328 | if(!rpcSlice->isIntra()) |
---|
1329 | { |
---|
1330 | if( !rpcSlice->getSPS()->getListsModificationPresentFlag() ) |
---|
1331 | { |
---|
1332 | refPicListModification->setRefPicListModificationFlagL0( 0 ); |
---|
1333 | } |
---|
1334 | else |
---|
1335 | { |
---|
1336 | READ_FLAG( uiCode, "ref_pic_list_modification_flag_l0" ); refPicListModification->setRefPicListModificationFlagL0( uiCode ? 1 : 0 ); |
---|
1337 | } |
---|
1338 | |
---|
1339 | if(refPicListModification->getRefPicListModificationFlagL0()) |
---|
1340 | { |
---|
1341 | uiCode = 0; |
---|
1342 | Int i = 0; |
---|
1343 | Int numRpsCurrTempList0 = rpcSlice->getNumRpsCurrTempList(); |
---|
1344 | if ( numRpsCurrTempList0 > 1 ) |
---|
1345 | { |
---|
1346 | Int length = 1; |
---|
1347 | numRpsCurrTempList0 --; |
---|
1348 | while ( numRpsCurrTempList0 >>= 1) |
---|
1349 | { |
---|
1350 | length ++; |
---|
1351 | } |
---|
1352 | for (i = 0; i < rpcSlice->getNumRefIdx(REF_PIC_LIST_0); i ++) |
---|
1353 | { |
---|
1354 | READ_CODE( length, uiCode, "list_entry_l0" ); |
---|
1355 | refPicListModification->setRefPicSetIdxL0(i, uiCode ); |
---|
1356 | } |
---|
1357 | } |
---|
1358 | else |
---|
1359 | { |
---|
1360 | for (i = 0; i < rpcSlice->getNumRefIdx(REF_PIC_LIST_0); i ++) |
---|
1361 | { |
---|
1362 | refPicListModification->setRefPicSetIdxL0(i, 0 ); |
---|
1363 | } |
---|
1364 | } |
---|
1365 | } |
---|
1366 | } |
---|
1367 | else |
---|
1368 | { |
---|
1369 | refPicListModification->setRefPicListModificationFlagL0(0); |
---|
1370 | } |
---|
1371 | if(rpcSlice->isInterB()) |
---|
1372 | { |
---|
1373 | if( !rpcSlice->getSPS()->getListsModificationPresentFlag() ) |
---|
1374 | { |
---|
1375 | refPicListModification->setRefPicListModificationFlagL1( 0 ); |
---|
1376 | } |
---|
1377 | else |
---|
1378 | { |
---|
1379 | READ_FLAG( uiCode, "ref_pic_list_modification_flag_l1" ); refPicListModification->setRefPicListModificationFlagL1( uiCode ? 1 : 0 ); |
---|
1380 | } |
---|
1381 | if(refPicListModification->getRefPicListModificationFlagL1()) |
---|
1382 | { |
---|
1383 | uiCode = 0; |
---|
1384 | Int i = 0; |
---|
1385 | Int numRpsCurrTempList1 = rpcSlice->getNumRpsCurrTempList(); |
---|
1386 | if ( numRpsCurrTempList1 > 1 ) |
---|
1387 | { |
---|
1388 | Int length = 1; |
---|
1389 | numRpsCurrTempList1 --; |
---|
1390 | while ( numRpsCurrTempList1 >>= 1) |
---|
1391 | { |
---|
1392 | length ++; |
---|
1393 | } |
---|
1394 | for (i = 0; i < rpcSlice->getNumRefIdx(REF_PIC_LIST_1); i ++) |
---|
1395 | { |
---|
1396 | READ_CODE( length, uiCode, "list_entry_l1" ); |
---|
1397 | refPicListModification->setRefPicSetIdxL1(i, uiCode ); |
---|
1398 | } |
---|
1399 | } |
---|
1400 | else |
---|
1401 | { |
---|
1402 | for (i = 0; i < rpcSlice->getNumRefIdx(REF_PIC_LIST_1); i ++) |
---|
1403 | { |
---|
1404 | refPicListModification->setRefPicSetIdxL1(i, 0 ); |
---|
1405 | } |
---|
1406 | } |
---|
1407 | } |
---|
1408 | } |
---|
1409 | else |
---|
1410 | { |
---|
1411 | refPicListModification->setRefPicListModificationFlagL1(0); |
---|
1412 | } |
---|
1413 | #if !SLICEHEADER_SYNTAX_FIX |
---|
1414 | } |
---|
1415 | else |
---|
1416 | { |
---|
1417 | // initialize from previous slice |
---|
1418 | pps = rpcSlice->getPPS(); |
---|
1419 | sps = rpcSlice->getSPS(); |
---|
1420 | } |
---|
1421 | #endif |
---|
1422 | if (rpcSlice->isInterB()) |
---|
1423 | { |
---|
1424 | READ_FLAG( uiCode, "mvd_l1_zero_flag" ); rpcSlice->setMvdL1ZeroFlag( (uiCode ? true : false) ); |
---|
1425 | } |
---|
1426 | |
---|
1427 | rpcSlice->setCabacInitFlag( false ); // default |
---|
1428 | if(pps->getCabacInitPresentFlag() && !rpcSlice->isIntra()) |
---|
1429 | { |
---|
1430 | READ_FLAG(uiCode, "cabac_init_flag"); |
---|
1431 | rpcSlice->setCabacInitFlag( uiCode ? true : false ); |
---|
1432 | } |
---|
1433 | |
---|
1434 | #if !SLICEHEADER_SYNTAX_FIX |
---|
1435 | if(!bDependentSlice) |
---|
1436 | { |
---|
1437 | #else |
---|
1438 | if ( rpcSlice->getEnableTMVPFlag() ) |
---|
1439 | { |
---|
1440 | if ( rpcSlice->getSliceType() == B_SLICE ) |
---|
1441 | { |
---|
1442 | READ_FLAG( uiCode, "collocated_from_l0_flag" ); |
---|
1443 | rpcSlice->setColFromL0Flag(uiCode); |
---|
1444 | } |
---|
1445 | else |
---|
1446 | { |
---|
1447 | rpcSlice->setColFromL0Flag( 1 ); |
---|
1448 | } |
---|
1449 | |
---|
1450 | if ( rpcSlice->getSliceType() != I_SLICE && |
---|
1451 | ((rpcSlice->getColFromL0Flag()==1 && rpcSlice->getNumRefIdx(REF_PIC_LIST_0)>1)|| |
---|
1452 | (rpcSlice->getColFromL0Flag() ==0 && rpcSlice->getNumRefIdx(REF_PIC_LIST_1)>1))) |
---|
1453 | { |
---|
1454 | READ_UVLC( uiCode, "collocated_ref_idx" ); |
---|
1455 | rpcSlice->setColRefIdx(uiCode); |
---|
1456 | } |
---|
1457 | else |
---|
1458 | { |
---|
1459 | rpcSlice->setColRefIdx(0); |
---|
1460 | } |
---|
1461 | } |
---|
1462 | if ( (pps->getUseWP() && rpcSlice->getSliceType()==P_SLICE) || (pps->getWPBiPred() && rpcSlice->getSliceType()==B_SLICE) ) |
---|
1463 | { |
---|
1464 | xParsePredWeightTable(rpcSlice); |
---|
1465 | rpcSlice->initWpScaling(); |
---|
1466 | } |
---|
1467 | READ_UVLC( uiCode, "five_minus_max_num_merge_cand"); |
---|
1468 | rpcSlice->setMaxNumMergeCand(MRG_MAX_NUM_CANDS - uiCode); |
---|
1469 | |
---|
1470 | #endif |
---|
1471 | READ_SVLC( iCode, "slice_qp_delta" ); |
---|
1472 | rpcSlice->setSliceQp (26 + pps->getPicInitQPMinus26() + iCode); |
---|
1473 | |
---|
1474 | assert( rpcSlice->getSliceQp() >= -sps->getQpBDOffsetY() ); |
---|
1475 | assert( rpcSlice->getSliceQp() <= 51 ); |
---|
1476 | |
---|
1477 | #if CHROMA_QP_EXTENSION |
---|
1478 | if (rpcSlice->getPPS()->getSliceChromaQpFlag()) |
---|
1479 | { |
---|
1480 | READ_SVLC( iCode, "slice_qp_delta_cb" ); |
---|
1481 | rpcSlice->setSliceQpDeltaCb( iCode ); |
---|
1482 | assert( rpcSlice->getSliceQpDeltaCb() >= -12 ); |
---|
1483 | assert( rpcSlice->getSliceQpDeltaCb() <= 12 ); |
---|
1484 | assert( (rpcSlice->getPPS()->getChromaCbQpOffset() + rpcSlice->getSliceQpDeltaCb()) >= -12 ); |
---|
1485 | assert( (rpcSlice->getPPS()->getChromaCbQpOffset() + rpcSlice->getSliceQpDeltaCb()) <= 12 ); |
---|
1486 | |
---|
1487 | READ_SVLC( iCode, "slice_qp_delta_cr" ); |
---|
1488 | rpcSlice->setSliceQpDeltaCr( iCode ); |
---|
1489 | assert( rpcSlice->getSliceQpDeltaCr() >= -12 ); |
---|
1490 | assert( rpcSlice->getSliceQpDeltaCr() <= 12 ); |
---|
1491 | assert( (rpcSlice->getPPS()->getChromaCrQpOffset() + rpcSlice->getSliceQpDeltaCr()) >= -12 ); |
---|
1492 | assert( (rpcSlice->getPPS()->getChromaCrQpOffset() + rpcSlice->getSliceQpDeltaCr()) <= 12 ); |
---|
1493 | } |
---|
1494 | #endif |
---|
1495 | |
---|
1496 | if (rpcSlice->getPPS()->getDeblockingFilterControlPresentFlag()) |
---|
1497 | { |
---|
1498 | if(rpcSlice->getPPS()->getDeblockingFilterOverrideEnabledFlag()) |
---|
1499 | { |
---|
1500 | READ_FLAG ( uiCode, "deblocking_filter_override_flag" ); rpcSlice->setDeblockingFilterOverrideFlag(uiCode ? true : false); |
---|
1501 | } |
---|
1502 | else |
---|
1503 | { |
---|
1504 | rpcSlice->setDeblockingFilterOverrideFlag(0); |
---|
1505 | } |
---|
1506 | if(rpcSlice->getDeblockingFilterOverrideFlag()) |
---|
1507 | { |
---|
1508 | READ_FLAG ( uiCode, "slice_disable_deblocking_filter_flag" ); rpcSlice->setDeblockingFilterDisable(uiCode ? 1 : 0); |
---|
1509 | if(!rpcSlice->getDeblockingFilterDisable()) |
---|
1510 | { |
---|
1511 | READ_SVLC( iCode, "beta_offset_div2" ); rpcSlice->setDeblockingFilterBetaOffsetDiv2(iCode); |
---|
1512 | READ_SVLC( iCode, "tc_offset_div2" ); rpcSlice->setDeblockingFilterTcOffsetDiv2(iCode); |
---|
1513 | } |
---|
1514 | } |
---|
1515 | else |
---|
1516 | { |
---|
1517 | rpcSlice->setDeblockingFilterDisable ( rpcSlice->getPPS()->getPicDisableDeblockingFilterFlag() ); |
---|
1518 | rpcSlice->setDeblockingFilterBetaOffsetDiv2( rpcSlice->getPPS()->getDeblockingFilterBetaOffsetDiv2() ); |
---|
1519 | rpcSlice->setDeblockingFilterTcOffsetDiv2 ( rpcSlice->getPPS()->getDeblockingFilterTcOffsetDiv2() ); |
---|
1520 | } |
---|
1521 | } |
---|
1522 | #if !SLICEHEADER_SYNTAX_FIX |
---|
1523 | if ( rpcSlice->getEnableTMVPFlag() ) |
---|
1524 | { |
---|
1525 | if ( rpcSlice->getSliceType() == B_SLICE ) |
---|
1526 | { |
---|
1527 | READ_FLAG( uiCode, "collocated_from_l0_flag" ); |
---|
1528 | rpcSlice->setColFromL0Flag(uiCode); |
---|
1529 | } |
---|
1530 | |
---|
1531 | if ( rpcSlice->getSliceType() != I_SLICE && |
---|
1532 | ((rpcSlice->getColFromL0Flag()==1 && rpcSlice->getNumRefIdx(REF_PIC_LIST_0)>1)|| |
---|
1533 | (rpcSlice->getColFromL0Flag() ==0 && rpcSlice->getNumRefIdx(REF_PIC_LIST_1)>1))) |
---|
1534 | { |
---|
1535 | READ_UVLC( uiCode, "collocated_ref_idx" ); |
---|
1536 | rpcSlice->setColRefIdx(uiCode); |
---|
1537 | } |
---|
1538 | else |
---|
1539 | { |
---|
1540 | rpcSlice->setColRefIdx(0); |
---|
1541 | } |
---|
1542 | } |
---|
1543 | if ( (pps->getUseWP() && rpcSlice->getSliceType()==P_SLICE) || (pps->getWPBiPred() && rpcSlice->getSliceType()==B_SLICE) ) |
---|
1544 | { |
---|
1545 | xParsePredWeightTable(rpcSlice); |
---|
1546 | rpcSlice->initWpScaling(); |
---|
1547 | } |
---|
1548 | } |
---|
1549 | |
---|
1550 | READ_UVLC( uiCode, "five_minus_max_num_merge_cand"); |
---|
1551 | rpcSlice->setMaxNumMergeCand(MRG_MAX_NUM_CANDS - uiCode); |
---|
1552 | |
---|
1553 | if (!bDependentSlice) |
---|
1554 | { |
---|
1555 | #endif |
---|
1556 | #if !REMOVE_ALF |
---|
1557 | if(sps->getUseALF()) |
---|
1558 | { |
---|
1559 | char syntaxString[50]; |
---|
1560 | for(Int compIdx=0; compIdx< 3; compIdx++) |
---|
1561 | { |
---|
1562 | sprintf(syntaxString, "alf_slice_filter_flag[%d]", compIdx); |
---|
1563 | READ_FLAG(uiCode, syntaxString); |
---|
1564 | rpcSlice->setAlfEnabledFlag( (uiCode ==1), compIdx); |
---|
1565 | } |
---|
1566 | } |
---|
1567 | Bool isAlfEnabled = (!rpcSlice->getSPS()->getUseALF())?(false):(rpcSlice->getAlfEnabledFlag(0)||rpcSlice->getAlfEnabledFlag(1)||rpcSlice->getAlfEnabledFlag(2)); |
---|
1568 | #endif |
---|
1569 | #if !SAO_LUM_CHROMA_ONOFF_FLAGS |
---|
1570 | Bool isSAOEnabled = (!rpcSlice->getSPS()->getUseSAO())?(false):(rpcSlice->getSaoEnabledFlag()); |
---|
1571 | #else |
---|
1572 | Bool isSAOEnabled = (!rpcSlice->getSPS()->getUseSAO())?(false):(rpcSlice->getSaoEnabledFlag()||rpcSlice->getSaoEnabledFlagChroma()); |
---|
1573 | #endif |
---|
1574 | Bool isDBFEnabled = (!rpcSlice->getDeblockingFilterDisable()); |
---|
1575 | |
---|
1576 | #if REMOVE_ALF |
---|
1577 | #if MOVE_LOOP_FILTER_SLICES_FLAG |
---|
1578 | if(rpcSlice->getPPS()->getLoopFilterAcrossSlicesEnabledFlag() && ( isSAOEnabled || isDBFEnabled )) |
---|
1579 | #else |
---|
1580 | if(rpcSlice->getSPS()->getLFCrossSliceBoundaryFlag() && ( isSAOEnabled || isDBFEnabled )) |
---|
1581 | #endif |
---|
1582 | #else |
---|
1583 | if(rpcSlice->getSPS()->getLFCrossSliceBoundaryFlag() && ( isAlfEnabled || isSAOEnabled || isDBFEnabled )) |
---|
1584 | #endif |
---|
1585 | { |
---|
1586 | READ_FLAG( uiCode, "slice_loop_filter_across_slices_enabled_flag"); |
---|
1587 | } |
---|
1588 | else |
---|
1589 | { |
---|
1590 | #if MOVE_LOOP_FILTER_SLICES_FLAG |
---|
1591 | uiCode = rpcSlice->getPPS()->getLoopFilterAcrossSlicesEnabledFlag()?1:0; |
---|
1592 | #else |
---|
1593 | uiCode = rpcSlice->getSPS()->getLFCrossSliceBoundaryFlag()?1:0; |
---|
1594 | #endif |
---|
1595 | } |
---|
1596 | rpcSlice->setLFCrossSliceBoundaryFlag( (uiCode==1)?true:false); |
---|
1597 | |
---|
1598 | #if !SLICEHEADER_SYNTAX_FIX |
---|
1599 | } |
---|
1600 | #else |
---|
1601 | } |
---|
1602 | if( pps->getTilesEnabledFlag() || pps->getEntropyCodingSyncEnabledFlag() ) |
---|
1603 | #endif |
---|
1604 | { |
---|
1605 | #if !SLICEHEADER_SYNTAX_FIX |
---|
1606 | Int tilesOrEntropyCodingSyncIdc = pps->getTilesOrEntropyCodingSyncIdc(); |
---|
1607 | #endif |
---|
1608 | UInt *entryPointOffset = NULL; |
---|
1609 | UInt numEntryPointOffsets, offsetLenMinus1; |
---|
1610 | |
---|
1611 | #if !SLICEHEADER_SYNTAX_FIX |
---|
1612 | rpcSlice->setNumEntryPointOffsets ( 0 ); // default |
---|
1613 | |
---|
1614 | if (tilesOrEntropyCodingSyncIdc>0) |
---|
1615 | { |
---|
1616 | #endif |
---|
1617 | READ_UVLC(numEntryPointOffsets, "num_entry_point_offsets"); rpcSlice->setNumEntryPointOffsets ( numEntryPointOffsets ); |
---|
1618 | if (numEntryPointOffsets>0) |
---|
1619 | { |
---|
1620 | READ_UVLC(offsetLenMinus1, "offset_len_minus1"); |
---|
1621 | } |
---|
1622 | entryPointOffset = new UInt[numEntryPointOffsets]; |
---|
1623 | for (UInt idx=0; idx<numEntryPointOffsets; idx++) |
---|
1624 | { |
---|
1625 | READ_CODE(offsetLenMinus1+1, uiCode, "entry_point_offset"); |
---|
1626 | entryPointOffset[ idx ] = uiCode; |
---|
1627 | } |
---|
1628 | #if !SLICEHEADER_SYNTAX_FIX |
---|
1629 | } |
---|
1630 | #endif |
---|
1631 | |
---|
1632 | #if !SLICEHEADER_SYNTAX_FIX |
---|
1633 | if ( tilesOrEntropyCodingSyncIdc == 1 ) // tiles |
---|
1634 | #else |
---|
1635 | if ( pps->getTilesEnabledFlag() ) |
---|
1636 | #endif |
---|
1637 | { |
---|
1638 | rpcSlice->setTileLocationCount( numEntryPointOffsets ); |
---|
1639 | |
---|
1640 | UInt prevPos = 0; |
---|
1641 | for (Int idx=0; idx<rpcSlice->getTileLocationCount(); idx++) |
---|
1642 | { |
---|
1643 | rpcSlice->setTileLocation( idx, prevPos + entryPointOffset [ idx ] ); |
---|
1644 | prevPos += entryPointOffset[ idx ]; |
---|
1645 | } |
---|
1646 | } |
---|
1647 | #if !SLICEHEADER_SYNTAX_FIX |
---|
1648 | else if ( tilesOrEntropyCodingSyncIdc == 2 ) // wavefront |
---|
1649 | #else |
---|
1650 | else if ( pps->getEntropyCodingSyncEnabledFlag() ) |
---|
1651 | #endif |
---|
1652 | { |
---|
1653 | Int numSubstreams = rpcSlice->getNumEntryPointOffsets()+1; |
---|
1654 | rpcSlice->allocSubstreamSizes(numSubstreams); |
---|
1655 | UInt *pSubstreamSizes = rpcSlice->getSubstreamSizes(); |
---|
1656 | for (Int idx=0; idx<numSubstreams-1; idx++) |
---|
1657 | { |
---|
1658 | if ( idx < numEntryPointOffsets ) |
---|
1659 | { |
---|
1660 | pSubstreamSizes[ idx ] = ( entryPointOffset[ idx ] << 3 ) ; |
---|
1661 | } |
---|
1662 | else |
---|
1663 | { |
---|
1664 | pSubstreamSizes[ idx ] = 0; |
---|
1665 | } |
---|
1666 | } |
---|
1667 | } |
---|
1668 | |
---|
1669 | if (entryPointOffset) |
---|
1670 | { |
---|
1671 | delete [] entryPointOffset; |
---|
1672 | } |
---|
1673 | } |
---|
1674 | #if SLICEHEADER_SYNTAX_FIX |
---|
1675 | else |
---|
1676 | { |
---|
1677 | rpcSlice->setNumEntryPointOffsets ( 0 ); |
---|
1678 | } |
---|
1679 | #endif |
---|
1680 | |
---|
1681 | #if SLICE_HEADER_EXTENSION |
---|
1682 | if(pps->getSliceHeaderExtensionPresentFlag()) |
---|
1683 | { |
---|
1684 | READ_UVLC(uiCode,"slice_header_extension_length"); |
---|
1685 | for(Int i=0; i<uiCode; i++) |
---|
1686 | { |
---|
1687 | UInt ignore; |
---|
1688 | READ_CODE(8,ignore,"slice_header_extension_data_byte"); |
---|
1689 | } |
---|
1690 | } |
---|
1691 | #endif |
---|
1692 | #if BYTE_ALIGNMENT |
---|
1693 | m_pcBitstream->readByteAlignment(); |
---|
1694 | #else |
---|
1695 | if (!bDependentSlice) |
---|
1696 | { |
---|
1697 | // Reading location information |
---|
1698 | // read out trailing bits |
---|
1699 | m_pcBitstream->readOutTrailingBits(); |
---|
1700 | } |
---|
1701 | #endif |
---|
1702 | return; |
---|
1703 | } |
---|
1704 | |
---|
1705 | #if PROFILE_TIER_LEVEL_SYNTAX |
---|
1706 | Void TDecCavlc::parsePTL( TComPTL *rpcPTL, Bool profilePresentFlag, Int maxNumSubLayersMinus1 ) |
---|
1707 | { |
---|
1708 | UInt uiCode; |
---|
1709 | if(profilePresentFlag) |
---|
1710 | { |
---|
1711 | parseProfileTier(rpcPTL->getGeneralPTL()); |
---|
1712 | } |
---|
1713 | READ_CODE( 8, uiCode, "general_level_idc" ); rpcPTL->getGeneralPTL()->setLevelIdc(uiCode); |
---|
1714 | |
---|
1715 | for(Int i = 0; i < maxNumSubLayersMinus1; i++) |
---|
1716 | { |
---|
1717 | READ_FLAG( uiCode, "sub_layer_profile_present_flag[i]" ); rpcPTL->setSubLayerProfilePresentFlag(i, uiCode); |
---|
1718 | READ_FLAG( uiCode, "sub_layer_level_present_flag[i]" ); rpcPTL->setSubLayerLevelPresentFlag (i, uiCode); |
---|
1719 | if( profilePresentFlag && rpcPTL->getSubLayerProfilePresentFlag(i) ) |
---|
1720 | { |
---|
1721 | parseProfileTier(rpcPTL->getSubLayerPTL(i)); |
---|
1722 | } |
---|
1723 | if(rpcPTL->getSubLayerLevelPresentFlag(i)) |
---|
1724 | { |
---|
1725 | READ_CODE( 8, uiCode, "sub_layer_level_idc[i]" ); rpcPTL->getSubLayerPTL(i)->setLevelIdc(uiCode); |
---|
1726 | } |
---|
1727 | } |
---|
1728 | } |
---|
1729 | Void TDecCavlc::parseProfileTier(ProfileTierLevel *ptl) |
---|
1730 | { |
---|
1731 | UInt uiCode; |
---|
1732 | READ_CODE(2 , uiCode, "XXX_profile_space[]"); ptl->setProfileSpace(uiCode); |
---|
1733 | READ_FLAG( uiCode, "XXX_tier_flag[]" ); ptl->setTierFlag (uiCode ? 1 : 0); |
---|
1734 | READ_CODE(5 , uiCode, "XXX_profile_idc[]" ); ptl->setProfileIdc (uiCode); |
---|
1735 | for(Int j = 0; j < 32; j++) |
---|
1736 | { |
---|
1737 | READ_FLAG( uiCode, "XXX_profile_compatibility_flag[][j]"); ptl->setProfileCompatibilityFlag(j, uiCode ? 1 : 0); |
---|
1738 | } |
---|
1739 | READ_CODE(16, uiCode, "XXX_reserved_zero_16bits[]"); assert( uiCode == 0 ); |
---|
1740 | } |
---|
1741 | #endif |
---|
1742 | Void TDecCavlc::parseTerminatingBit( UInt& ruiBit ) |
---|
1743 | { |
---|
1744 | ruiBit = false; |
---|
1745 | Int iBitsLeft = m_pcBitstream->getNumBitsLeft(); |
---|
1746 | if(iBitsLeft <= 8) |
---|
1747 | { |
---|
1748 | UInt uiPeekValue = m_pcBitstream->peekBits(iBitsLeft); |
---|
1749 | if (uiPeekValue == (1<<(iBitsLeft-1))) |
---|
1750 | { |
---|
1751 | ruiBit = true; |
---|
1752 | } |
---|
1753 | } |
---|
1754 | } |
---|
1755 | |
---|
1756 | Void TDecCavlc::parseSkipFlag( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth ) |
---|
1757 | { |
---|
1758 | assert(0); |
---|
1759 | } |
---|
1760 | |
---|
1761 | Void TDecCavlc::parseCUTransquantBypassFlag( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth ) |
---|
1762 | { |
---|
1763 | assert(0); |
---|
1764 | } |
---|
1765 | |
---|
1766 | #if INTRA_BL |
---|
1767 | Void TDecCavlc::parseIntraBLFlag ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiPartIdx, UInt uiDepth ) |
---|
1768 | { |
---|
1769 | assert(0); |
---|
1770 | } |
---|
1771 | #endif |
---|
1772 | |
---|
1773 | Void TDecCavlc::parseMVPIdx( Int& riMVPIdx ) |
---|
1774 | { |
---|
1775 | assert(0); |
---|
1776 | } |
---|
1777 | |
---|
1778 | Void TDecCavlc::parseSplitFlag ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth ) |
---|
1779 | { |
---|
1780 | assert(0); |
---|
1781 | } |
---|
1782 | |
---|
1783 | Void TDecCavlc::parsePartSize( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth ) |
---|
1784 | { |
---|
1785 | assert(0); |
---|
1786 | } |
---|
1787 | |
---|
1788 | Void TDecCavlc::parsePredMode( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth ) |
---|
1789 | { |
---|
1790 | assert(0); |
---|
1791 | } |
---|
1792 | |
---|
1793 | /** Parse I_PCM information. |
---|
1794 | * \param pcCU pointer to CU |
---|
1795 | * \param uiAbsPartIdx CU index |
---|
1796 | * \param uiDepth CU depth |
---|
1797 | * \returns Void |
---|
1798 | * |
---|
1799 | * If I_PCM flag indicates that the CU is I_PCM, parse its PCM alignment bits and codes. |
---|
1800 | */ |
---|
1801 | Void TDecCavlc::parseIPCMInfo( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth ) |
---|
1802 | { |
---|
1803 | assert(0); |
---|
1804 | } |
---|
1805 | |
---|
1806 | Void TDecCavlc::parseIntraDirLumaAng ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth ) |
---|
1807 | { |
---|
1808 | assert(0); |
---|
1809 | } |
---|
1810 | |
---|
1811 | Void TDecCavlc::parseIntraDirChroma( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth ) |
---|
1812 | { |
---|
1813 | assert(0); |
---|
1814 | } |
---|
1815 | |
---|
1816 | Void TDecCavlc::parseInterDir( TComDataCU* pcCU, UInt& ruiInterDir, UInt uiAbsPartIdx, UInt uiDepth ) |
---|
1817 | { |
---|
1818 | assert(0); |
---|
1819 | } |
---|
1820 | |
---|
1821 | Void TDecCavlc::parseRefFrmIdx( TComDataCU* pcCU, Int& riRefFrmIdx, UInt uiAbsPartIdx, UInt uiDepth, RefPicList eRefList ) |
---|
1822 | { |
---|
1823 | assert(0); |
---|
1824 | } |
---|
1825 | |
---|
1826 | Void TDecCavlc::parseMvd( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiPartIdx, UInt uiDepth, RefPicList eRefList ) |
---|
1827 | { |
---|
1828 | assert(0); |
---|
1829 | } |
---|
1830 | |
---|
1831 | Void TDecCavlc::parseDeltaQP( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth ) |
---|
1832 | { |
---|
1833 | Int qp; |
---|
1834 | Int iDQp; |
---|
1835 | |
---|
1836 | xReadSvlc( iDQp ); |
---|
1837 | |
---|
1838 | Int qpBdOffsetY = pcCU->getSlice()->getSPS()->getQpBDOffsetY(); |
---|
1839 | qp = (((Int) pcCU->getRefQP( uiAbsPartIdx ) + iDQp + 52 + 2*qpBdOffsetY )%(52+ qpBdOffsetY)) - qpBdOffsetY; |
---|
1840 | |
---|
1841 | UInt uiAbsQpCUPartIdx = (uiAbsPartIdx>>((g_uiMaxCUDepth - pcCU->getSlice()->getPPS()->getMaxCuDQPDepth())<<1))<<((g_uiMaxCUDepth - pcCU->getSlice()->getPPS()->getMaxCuDQPDepth())<<1) ; |
---|
1842 | UInt uiQpCUDepth = min(uiDepth,pcCU->getSlice()->getPPS()->getMaxCuDQPDepth()) ; |
---|
1843 | |
---|
1844 | pcCU->setQPSubParts( qp, uiAbsQpCUPartIdx, uiQpCUDepth ); |
---|
1845 | } |
---|
1846 | |
---|
1847 | Void TDecCavlc::parseCoeffNxN( TComDataCU* pcCU, TCoeff* pcCoef, UInt uiAbsPartIdx, UInt uiWidth, UInt uiHeight, UInt uiDepth, TextType eTType ) |
---|
1848 | { |
---|
1849 | assert(0); |
---|
1850 | } |
---|
1851 | |
---|
1852 | Void TDecCavlc::parseTransformSubdivFlag( UInt& ruiSubdivFlag, UInt uiLog2TransformBlockSize ) |
---|
1853 | { |
---|
1854 | assert(0); |
---|
1855 | } |
---|
1856 | |
---|
1857 | Void TDecCavlc::parseQtCbf( TComDataCU* pcCU, UInt uiAbsPartIdx, TextType eType, UInt uiTrDepth, UInt uiDepth ) |
---|
1858 | { |
---|
1859 | assert(0); |
---|
1860 | } |
---|
1861 | |
---|
1862 | Void TDecCavlc::parseQtRootCbf( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, UInt& uiQtRootCbf ) |
---|
1863 | { |
---|
1864 | assert(0); |
---|
1865 | } |
---|
1866 | |
---|
1867 | Void TDecCavlc::parseTransformSkipFlags (TComDataCU* pcCU, UInt uiAbsPartIdx, UInt width, UInt height, UInt uiDepth, TextType eTType) |
---|
1868 | { |
---|
1869 | assert(0); |
---|
1870 | } |
---|
1871 | |
---|
1872 | Void TDecCavlc::parseMergeFlag ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, UInt uiPUIdx ) |
---|
1873 | { |
---|
1874 | assert(0); |
---|
1875 | } |
---|
1876 | |
---|
1877 | Void TDecCavlc::parseMergeIndex ( TComDataCU* pcCU, UInt& ruiMergeIndex, UInt uiAbsPartIdx, UInt uiDepth ) |
---|
1878 | { |
---|
1879 | assert(0); |
---|
1880 | } |
---|
1881 | |
---|
1882 | // ==================================================================================================================== |
---|
1883 | // Protected member functions |
---|
1884 | // ==================================================================================================================== |
---|
1885 | |
---|
1886 | |
---|
1887 | /** Parse PCM alignment zero bits. |
---|
1888 | * \returns Void |
---|
1889 | */ |
---|
1890 | Void TDecCavlc::xReadPCMAlignZero( ) |
---|
1891 | { |
---|
1892 | UInt uiNumberOfBits = m_pcBitstream->getNumBitsUntilByteAligned(); |
---|
1893 | |
---|
1894 | if(uiNumberOfBits) |
---|
1895 | { |
---|
1896 | UInt uiBits; |
---|
1897 | UInt uiSymbol; |
---|
1898 | |
---|
1899 | for(uiBits = 0; uiBits < uiNumberOfBits; uiBits++) |
---|
1900 | { |
---|
1901 | xReadFlag( uiSymbol ); |
---|
1902 | |
---|
1903 | if(uiSymbol) |
---|
1904 | { |
---|
1905 | printf("\nWarning! pcm_align_zero include a non-zero value.\n"); |
---|
1906 | } |
---|
1907 | } |
---|
1908 | } |
---|
1909 | } |
---|
1910 | |
---|
1911 | Void TDecCavlc::xReadUnaryMaxSymbol( UInt& ruiSymbol, UInt uiMaxSymbol ) |
---|
1912 | { |
---|
1913 | if (uiMaxSymbol == 0) |
---|
1914 | { |
---|
1915 | ruiSymbol = 0; |
---|
1916 | return; |
---|
1917 | } |
---|
1918 | |
---|
1919 | xReadFlag( ruiSymbol ); |
---|
1920 | |
---|
1921 | if (ruiSymbol == 0 || uiMaxSymbol == 1) |
---|
1922 | { |
---|
1923 | return; |
---|
1924 | } |
---|
1925 | |
---|
1926 | UInt uiSymbol = 0; |
---|
1927 | UInt uiCont; |
---|
1928 | |
---|
1929 | do |
---|
1930 | { |
---|
1931 | xReadFlag( uiCont ); |
---|
1932 | uiSymbol++; |
---|
1933 | } |
---|
1934 | while( uiCont && (uiSymbol < uiMaxSymbol-1) ); |
---|
1935 | |
---|
1936 | if( uiCont && (uiSymbol == uiMaxSymbol-1) ) |
---|
1937 | { |
---|
1938 | uiSymbol++; |
---|
1939 | } |
---|
1940 | |
---|
1941 | ruiSymbol = uiSymbol; |
---|
1942 | } |
---|
1943 | |
---|
1944 | Void TDecCavlc::xReadExGolombLevel( UInt& ruiSymbol ) |
---|
1945 | { |
---|
1946 | UInt uiSymbol ; |
---|
1947 | UInt uiCount = 0; |
---|
1948 | do |
---|
1949 | { |
---|
1950 | xReadFlag( uiSymbol ); |
---|
1951 | uiCount++; |
---|
1952 | } |
---|
1953 | while( uiSymbol && (uiCount != 13)); |
---|
1954 | |
---|
1955 | ruiSymbol = uiCount-1; |
---|
1956 | |
---|
1957 | if( uiSymbol ) |
---|
1958 | { |
---|
1959 | xReadEpExGolomb( uiSymbol, 0 ); |
---|
1960 | ruiSymbol += uiSymbol+1; |
---|
1961 | } |
---|
1962 | |
---|
1963 | return; |
---|
1964 | } |
---|
1965 | |
---|
1966 | Void TDecCavlc::xReadEpExGolomb( UInt& ruiSymbol, UInt uiCount ) |
---|
1967 | { |
---|
1968 | UInt uiSymbol = 0; |
---|
1969 | UInt uiBit = 1; |
---|
1970 | |
---|
1971 | |
---|
1972 | while( uiBit ) |
---|
1973 | { |
---|
1974 | xReadFlag( uiBit ); |
---|
1975 | uiSymbol += uiBit << uiCount++; |
---|
1976 | } |
---|
1977 | |
---|
1978 | uiCount--; |
---|
1979 | while( uiCount-- ) |
---|
1980 | { |
---|
1981 | xReadFlag( uiBit ); |
---|
1982 | uiSymbol += uiBit << uiCount; |
---|
1983 | } |
---|
1984 | |
---|
1985 | ruiSymbol = uiSymbol; |
---|
1986 | |
---|
1987 | return; |
---|
1988 | } |
---|
1989 | |
---|
1990 | UInt TDecCavlc::xGetBit() |
---|
1991 | { |
---|
1992 | UInt ruiCode; |
---|
1993 | m_pcBitstream->read( 1, ruiCode ); |
---|
1994 | return ruiCode; |
---|
1995 | } |
---|
1996 | |
---|
1997 | |
---|
1998 | /** parse explicit wp tables |
---|
1999 | * \param TComSlice* pcSlice |
---|
2000 | * \returns Void |
---|
2001 | */ |
---|
2002 | Void TDecCavlc::xParsePredWeightTable( TComSlice* pcSlice ) |
---|
2003 | { |
---|
2004 | wpScalingParam *wp; |
---|
2005 | Bool bChroma = true; // color always present in HEVC ? |
---|
2006 | TComPPS* pps = pcSlice->getPPS(); |
---|
2007 | SliceType eSliceType = pcSlice->getSliceType(); |
---|
2008 | Int iNbRef = (eSliceType == B_SLICE ) ? (2) : (1); |
---|
2009 | UInt uiLog2WeightDenomLuma, uiLog2WeightDenomChroma; |
---|
2010 | UInt uiMode = 0; |
---|
2011 | #if NUM_WP_LIMIT |
---|
2012 | UInt uiTotalSignalledWeightFlags = 0; |
---|
2013 | #endif |
---|
2014 | if ( (eSliceType==P_SLICE && pps->getUseWP()) || (eSliceType==B_SLICE && pps->getWPBiPred()) ) |
---|
2015 | { |
---|
2016 | uiMode = 1; // explicit |
---|
2017 | } |
---|
2018 | if ( uiMode == 1 ) // explicit |
---|
2019 | { |
---|
2020 | printf("\nTDecCavlc::xParsePredWeightTable(poc=%d) explicit...\n", pcSlice->getPOC()); |
---|
2021 | Int iDeltaDenom; |
---|
2022 | // decode delta_luma_log2_weight_denom : |
---|
2023 | READ_UVLC( uiLog2WeightDenomLuma, "luma_log2_weight_denom" ); // ue(v): luma_log2_weight_denom |
---|
2024 | if( bChroma ) |
---|
2025 | { |
---|
2026 | READ_SVLC( iDeltaDenom, "delta_chroma_log2_weight_denom" ); // se(v): delta_chroma_log2_weight_denom |
---|
2027 | assert((iDeltaDenom + (Int)uiLog2WeightDenomLuma)>=0); |
---|
2028 | uiLog2WeightDenomChroma = (UInt)(iDeltaDenom + uiLog2WeightDenomLuma); |
---|
2029 | } |
---|
2030 | |
---|
2031 | for ( Int iNumRef=0 ; iNumRef<iNbRef ; iNumRef++ ) |
---|
2032 | { |
---|
2033 | RefPicList eRefPicList = ( iNumRef ? REF_PIC_LIST_1 : REF_PIC_LIST_0 ); |
---|
2034 | for ( Int iRefIdx=0 ; iRefIdx<pcSlice->getNumRefIdx(eRefPicList) ; iRefIdx++ ) |
---|
2035 | { |
---|
2036 | pcSlice->getWpScaling(eRefPicList, iRefIdx, wp); |
---|
2037 | |
---|
2038 | wp[0].uiLog2WeightDenom = uiLog2WeightDenomLuma; |
---|
2039 | wp[1].uiLog2WeightDenom = uiLog2WeightDenomChroma; |
---|
2040 | wp[2].uiLog2WeightDenom = uiLog2WeightDenomChroma; |
---|
2041 | |
---|
2042 | UInt uiCode; |
---|
2043 | READ_FLAG( uiCode, "luma_weight_lX_flag" ); // u(1): luma_weight_l0_flag |
---|
2044 | wp[0].bPresentFlag = ( uiCode == 1 ); |
---|
2045 | #if NUM_WP_LIMIT |
---|
2046 | uiTotalSignalledWeightFlags += wp[0].bPresentFlag; |
---|
2047 | } |
---|
2048 | if ( bChroma ) |
---|
2049 | { |
---|
2050 | UInt uiCode; |
---|
2051 | for ( Int iRefIdx=0 ; iRefIdx<pcSlice->getNumRefIdx(eRefPicList) ; iRefIdx++ ) |
---|
2052 | { |
---|
2053 | pcSlice->getWpScaling(eRefPicList, iRefIdx, wp); |
---|
2054 | READ_FLAG( uiCode, "chroma_weight_lX_flag" ); // u(1): chroma_weight_l0_flag |
---|
2055 | wp[1].bPresentFlag = ( uiCode == 1 ); |
---|
2056 | wp[2].bPresentFlag = ( uiCode == 1 ); |
---|
2057 | uiTotalSignalledWeightFlags += 2*wp[1].bPresentFlag; |
---|
2058 | } |
---|
2059 | } |
---|
2060 | for ( Int iRefIdx=0 ; iRefIdx<pcSlice->getNumRefIdx(eRefPicList) ; iRefIdx++ ) |
---|
2061 | { |
---|
2062 | pcSlice->getWpScaling(eRefPicList, iRefIdx, wp); |
---|
2063 | #endif |
---|
2064 | if ( wp[0].bPresentFlag ) |
---|
2065 | { |
---|
2066 | Int iDeltaWeight; |
---|
2067 | READ_SVLC( iDeltaWeight, "delta_luma_weight_lX" ); // se(v): delta_luma_weight_l0[i] |
---|
2068 | wp[0].iWeight = (iDeltaWeight + (1<<wp[0].uiLog2WeightDenom)); |
---|
2069 | READ_SVLC( wp[0].iOffset, "luma_offset_lX" ); // se(v): luma_offset_l0[i] |
---|
2070 | } |
---|
2071 | else |
---|
2072 | { |
---|
2073 | wp[0].iWeight = (1 << wp[0].uiLog2WeightDenom); |
---|
2074 | wp[0].iOffset = 0; |
---|
2075 | } |
---|
2076 | if ( bChroma ) |
---|
2077 | { |
---|
2078 | #if !NUM_WP_LIMIT |
---|
2079 | READ_FLAG( uiCode, "chroma_weight_lX_flag" ); // u(1): chroma_weight_l0_flag |
---|
2080 | wp[1].bPresentFlag = ( uiCode == 1 ); |
---|
2081 | wp[2].bPresentFlag = ( uiCode == 1 ); |
---|
2082 | #endif |
---|
2083 | if ( wp[1].bPresentFlag ) |
---|
2084 | { |
---|
2085 | for ( Int j=1 ; j<3 ; j++ ) |
---|
2086 | { |
---|
2087 | Int iDeltaWeight; |
---|
2088 | READ_SVLC( iDeltaWeight, "delta_chroma_weight_lX" ); // se(v): chroma_weight_l0[i][j] |
---|
2089 | wp[j].iWeight = (iDeltaWeight + (1<<wp[1].uiLog2WeightDenom)); |
---|
2090 | |
---|
2091 | Int iDeltaChroma; |
---|
2092 | READ_SVLC( iDeltaChroma, "delta_chroma_offset_lX" ); // se(v): delta_chroma_offset_l0[i][j] |
---|
2093 | Int shift = ((1<<(g_uiBitDepth+g_uiBitIncrement-1))); |
---|
2094 | Int pred = ( shift - ( ( shift*wp[j].iWeight)>>(wp[j].uiLog2WeightDenom) ) ); |
---|
2095 | #if WP_PARAM_RANGE_LIMIT |
---|
2096 | wp[j].iOffset = Clip3(-128, 127, (iDeltaChroma + pred) ); |
---|
2097 | #else |
---|
2098 | wp[j].iOffset = iDeltaChroma + pred; |
---|
2099 | #endif |
---|
2100 | } |
---|
2101 | } |
---|
2102 | else |
---|
2103 | { |
---|
2104 | for ( Int j=1 ; j<3 ; j++ ) |
---|
2105 | { |
---|
2106 | wp[j].iWeight = (1 << wp[j].uiLog2WeightDenom); |
---|
2107 | wp[j].iOffset = 0; |
---|
2108 | } |
---|
2109 | } |
---|
2110 | } |
---|
2111 | } |
---|
2112 | |
---|
2113 | for ( Int iRefIdx=pcSlice->getNumRefIdx(eRefPicList) ; iRefIdx<MAX_NUM_REF ; iRefIdx++ ) |
---|
2114 | { |
---|
2115 | pcSlice->getWpScaling(eRefPicList, iRefIdx, wp); |
---|
2116 | |
---|
2117 | wp[0].bPresentFlag = false; |
---|
2118 | wp[1].bPresentFlag = false; |
---|
2119 | wp[2].bPresentFlag = false; |
---|
2120 | } |
---|
2121 | } |
---|
2122 | #if NUM_WP_LIMIT |
---|
2123 | assert(uiTotalSignalledWeightFlags<=24); |
---|
2124 | #endif |
---|
2125 | } |
---|
2126 | else |
---|
2127 | { |
---|
2128 | printf("\n wrong weight pred table syntax \n "); |
---|
2129 | assert(0); |
---|
2130 | } |
---|
2131 | } |
---|
2132 | |
---|
2133 | /** decode quantization matrix |
---|
2134 | * \param scalingList quantization matrix information |
---|
2135 | */ |
---|
2136 | Void TDecCavlc::parseScalingList(TComScalingList* scalingList) |
---|
2137 | { |
---|
2138 | UInt code, sizeId, listId; |
---|
2139 | Bool scalingListPredModeFlag; |
---|
2140 | //for each size |
---|
2141 | for(sizeId = 0; sizeId < SCALING_LIST_SIZE_NUM; sizeId++) |
---|
2142 | { |
---|
2143 | for(listId = 0; listId < g_scalingListNum[sizeId]; listId++) |
---|
2144 | { |
---|
2145 | READ_FLAG( code, "scaling_list_pred_mode_flag"); |
---|
2146 | scalingListPredModeFlag = (code) ? true : false; |
---|
2147 | if(!scalingListPredModeFlag) //Copy Mode |
---|
2148 | { |
---|
2149 | READ_UVLC( code, "scaling_list_pred_matrix_id_delta"); |
---|
2150 | scalingList->setRefMatrixId (sizeId,listId,(UInt)((Int)(listId)-(code))); |
---|
2151 | if( sizeId > SCALING_LIST_8x8 ) |
---|
2152 | { |
---|
2153 | scalingList->setScalingListDC(sizeId,listId,((listId == scalingList->getRefMatrixId (sizeId,listId))? 16 :scalingList->getScalingListDC(sizeId, scalingList->getRefMatrixId (sizeId,listId)))); |
---|
2154 | } |
---|
2155 | scalingList->processRefMatrix( sizeId, listId, scalingList->getRefMatrixId (sizeId,listId)); |
---|
2156 | |
---|
2157 | } |
---|
2158 | else //DPCM Mode |
---|
2159 | { |
---|
2160 | xDecodeScalingList(scalingList, sizeId, listId); |
---|
2161 | } |
---|
2162 | } |
---|
2163 | } |
---|
2164 | |
---|
2165 | return; |
---|
2166 | } |
---|
2167 | /** decode DPCM |
---|
2168 | * \param scalingList quantization matrix information |
---|
2169 | * \param sizeId size index |
---|
2170 | * \param listId list index |
---|
2171 | */ |
---|
2172 | Void TDecCavlc::xDecodeScalingList(TComScalingList *scalingList, UInt sizeId, UInt listId) |
---|
2173 | { |
---|
2174 | Int i,coefNum = min(MAX_MATRIX_COEF_NUM,(Int)g_scalingListSize[sizeId]); |
---|
2175 | Int data; |
---|
2176 | Int scalingListDcCoefMinus8 = 0; |
---|
2177 | Int nextCoef = SCALING_LIST_START_VALUE; |
---|
2178 | #if REMOVE_ZIGZAG_SCAN |
---|
2179 | UInt* scan = (sizeId == 0) ? g_auiSigLastScan [ SCAN_DIAG ] [ 1 ] : g_sigLastScanCG32x32; |
---|
2180 | #else |
---|
2181 | UInt* scan = g_auiFrameScanXY [ (sizeId == 0)? 1 : 2 ]; |
---|
2182 | #endif |
---|
2183 | Int *dst = scalingList->getScalingListAddress(sizeId, listId); |
---|
2184 | |
---|
2185 | if( sizeId > SCALING_LIST_8x8 ) |
---|
2186 | { |
---|
2187 | READ_SVLC( scalingListDcCoefMinus8, "scaling_list_dc_coef_minus8"); |
---|
2188 | scalingList->setScalingListDC(sizeId,listId,scalingListDcCoefMinus8 + 8); |
---|
2189 | nextCoef = scalingList->getScalingListDC(sizeId,listId); |
---|
2190 | } |
---|
2191 | |
---|
2192 | for(i = 0; i < coefNum; i++) |
---|
2193 | { |
---|
2194 | READ_SVLC( data, "scaling_list_delta_coef"); |
---|
2195 | nextCoef = (nextCoef + data + 256 ) % 256; |
---|
2196 | dst[scan[i]] = nextCoef; |
---|
2197 | } |
---|
2198 | } |
---|
2199 | |
---|
2200 | Bool TDecCavlc::xMoreRbspData() |
---|
2201 | { |
---|
2202 | Int bitsLeft = m_pcBitstream->getNumBitsLeft(); |
---|
2203 | |
---|
2204 | // if there are more than 8 bits, it cannot be rbsp_trailing_bits |
---|
2205 | if (bitsLeft > 8) |
---|
2206 | { |
---|
2207 | return true; |
---|
2208 | } |
---|
2209 | |
---|
2210 | UChar lastByte = m_pcBitstream->peekBits(bitsLeft); |
---|
2211 | Int cnt = bitsLeft; |
---|
2212 | |
---|
2213 | // remove trailing bits equal to zero |
---|
2214 | while ((cnt>0) && ((lastByte & 1) == 0)) |
---|
2215 | { |
---|
2216 | lastByte >>= 1; |
---|
2217 | cnt--; |
---|
2218 | } |
---|
2219 | // remove bit equal to one |
---|
2220 | cnt--; |
---|
2221 | |
---|
2222 | // we should not have a negative number of bits |
---|
2223 | assert (cnt>=0); |
---|
2224 | |
---|
2225 | // we have more data, if cnt is not zero |
---|
2226 | return (cnt>0); |
---|
2227 | } |
---|
2228 | |
---|
2229 | //! \} |
---|
2230 | |
---|