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 SUPPORT_FOR_VUI |
---|
847 | READ_FLAG( uiCode, "vui_parameters_present_flag" ); pcSPS->setVuiParametersPresentFlag(uiCode); |
---|
848 | |
---|
849 | if (pcSPS->getVuiParametersPresentFlag()) |
---|
850 | { |
---|
851 | #if !BUFFERING_PERIOD_AND_TIMING_SEI |
---|
852 | parseVUI(pcSPS->getVuiParameters()); |
---|
853 | #else |
---|
854 | parseVUI(pcSPS->getVuiParameters(), pcSPS); |
---|
855 | #endif |
---|
856 | } |
---|
857 | #endif |
---|
858 | #if !SPS_AMVP_CLEANUP |
---|
859 | // AMVP mode for each depth (AM_NONE or AM_EXPL) |
---|
860 | for (Int i = 0; i < pcSPS->getMaxCUDepth(); i++) |
---|
861 | { |
---|
862 | xReadFlag( uiCode ); |
---|
863 | pcSPS->setAMVPMode( i, (AMVP_MODE)uiCode ); |
---|
864 | } |
---|
865 | #endif |
---|
866 | READ_FLAG( uiCode, "sps_extension_flag"); |
---|
867 | if (uiCode) |
---|
868 | { |
---|
869 | while ( xMoreRbspData() ) |
---|
870 | { |
---|
871 | READ_FLAG( uiCode, "sps_extension_data_flag"); |
---|
872 | } |
---|
873 | } |
---|
874 | } |
---|
875 | |
---|
876 | Void TDecCavlc::parseVPS(TComVPS* pcVPS) |
---|
877 | { |
---|
878 | UInt uiCode; |
---|
879 | |
---|
880 | #if VPS_SYNTAX_CHANGES |
---|
881 | READ_CODE( 4, uiCode, "video_parameter_set_id" ); pcVPS->setVPSId( uiCode ); |
---|
882 | READ_FLAG( uiCode, "vps_temporal_id_nesting_flag" ); pcVPS->setTemporalNestingFlag( uiCode ? true:false ); |
---|
883 | READ_CODE( 2, uiCode, "vps_reserved_zero_2bits" ); assert(uiCode == 0); |
---|
884 | READ_CODE( 6, uiCode, "vps_reserved_zero_6bits" ); assert(uiCode == 0); |
---|
885 | READ_CODE( 3, uiCode, "vps_max_sub_layers_minus1" ); pcVPS->setMaxTLayers( uiCode + 1 ); |
---|
886 | parsePTL ( pcVPS->getPTL(), true, pcVPS->getMaxTLayers()-1); |
---|
887 | READ_CODE( 12, uiCode, "vps_reserved_zero_12bits" ); assert(uiCode == 0); |
---|
888 | #else |
---|
889 | READ_CODE( 3, uiCode, "vps_max_temporal_layers_minus1" ); pcVPS->setMaxTLayers( uiCode + 1 ); |
---|
890 | READ_CODE( 5, uiCode, "vps_max_layers_minus1" ); pcVPS->setMaxLayers( uiCode + 1 ); |
---|
891 | READ_UVLC( uiCode, "video_parameter_set_id" ); pcVPS->setVPSId( uiCode ); |
---|
892 | READ_FLAG( uiCode, "vps_temporal_id_nesting_flag" ); pcVPS->setTemporalNestingFlag( uiCode ? true:false ); |
---|
893 | #endif |
---|
894 | for(UInt i = 0; i <= pcVPS->getMaxTLayers()-1; i++) |
---|
895 | { |
---|
896 | READ_UVLC( uiCode, "vps_max_dec_pic_buffering[i]" ); pcVPS->setMaxDecPicBuffering( uiCode, i ); |
---|
897 | READ_UVLC( uiCode, "vps_num_reorder_pics[i]" ); pcVPS->setNumReorderPics( uiCode, i ); |
---|
898 | READ_UVLC( uiCode, "vps_max_latency_increase[i]" ); pcVPS->setMaxLatencyIncrease( uiCode, i ); |
---|
899 | } |
---|
900 | #if VPS_SYNTAX_CHANGES |
---|
901 | READ_UVLC( uiCode, "vps_num_hrd_parameters" ); assert(uiCode == 0); |
---|
902 | // hrd_parameters |
---|
903 | #endif |
---|
904 | READ_FLAG( uiCode, "vps_extension_flag" ); assert(!uiCode); |
---|
905 | //future extensions go here.. |
---|
906 | |
---|
907 | return; |
---|
908 | } |
---|
909 | |
---|
910 | Void TDecCavlc::parseSliceHeader (TComSlice*& rpcSlice, ParameterSetManagerDecoder *parameterSetManager) |
---|
911 | { |
---|
912 | UInt uiCode; |
---|
913 | Int iCode; |
---|
914 | |
---|
915 | #if ENC_DEC_TRACE |
---|
916 | xTraceSliceHeader(rpcSlice); |
---|
917 | #endif |
---|
918 | TComPPS* pps = NULL; |
---|
919 | TComSPS* sps = NULL; |
---|
920 | |
---|
921 | UInt firstSliceInPic; |
---|
922 | READ_FLAG( firstSliceInPic, "first_slice_in_pic_flag" ); |
---|
923 | #if SPLICING_FRIENDLY_PARAMS |
---|
924 | if( rpcSlice->getRapPicFlag()) |
---|
925 | { |
---|
926 | READ_FLAG( uiCode, "no_output_of_prior_pics_flag" ); //ignored |
---|
927 | } |
---|
928 | #endif |
---|
929 | READ_UVLC ( uiCode, "pic_parameter_set_id" ); rpcSlice->setPPSId(uiCode); |
---|
930 | pps = parameterSetManager->getPrefetchedPPS(uiCode); |
---|
931 | //!KS: need to add error handling code here, if PPS is not available |
---|
932 | assert(pps!=0); |
---|
933 | sps = parameterSetManager->getPrefetchedSPS(pps->getSPSId()); |
---|
934 | //!KS: need to add error handling code here, if SPS is not available |
---|
935 | assert(sps!=0); |
---|
936 | rpcSlice->setSPS(sps); |
---|
937 | rpcSlice->setPPS(pps); |
---|
938 | |
---|
939 | Int numCUs = ((sps->getPicWidthInLumaSamples()+sps->getMaxCUWidth()-1)/sps->getMaxCUWidth())*((sps->getPicHeightInLumaSamples()+sps->getMaxCUHeight()-1)/sps->getMaxCUHeight()); |
---|
940 | Int maxParts = (1<<(sps->getMaxCUDepth()<<1)); |
---|
941 | #if REMOVE_FGS |
---|
942 | Int numParts = 0; |
---|
943 | #else |
---|
944 | Int numParts = (1<<(pps->getSliceGranularity()<<1)); |
---|
945 | #endif |
---|
946 | UInt lCUAddress = 0; |
---|
947 | Int reqBitsOuter = 0; |
---|
948 | while(numCUs>(1<<reqBitsOuter)) |
---|
949 | { |
---|
950 | reqBitsOuter++; |
---|
951 | } |
---|
952 | Int reqBitsInner = 0; |
---|
953 | while((numParts)>(1<<reqBitsInner)) |
---|
954 | { |
---|
955 | reqBitsInner++; |
---|
956 | } |
---|
957 | |
---|
958 | UInt innerAddress = 0; |
---|
959 | Int sliceAddress = 0; |
---|
960 | if(!firstSliceInPic) |
---|
961 | { |
---|
962 | UInt address; |
---|
963 | READ_CODE( reqBitsOuter+reqBitsInner, address, "slice_address" ); |
---|
964 | lCUAddress = address >> reqBitsInner; |
---|
965 | innerAddress = address - (lCUAddress<<reqBitsInner); |
---|
966 | } |
---|
967 | //set uiCode to equal slice start address (or dependent slice start address) |
---|
968 | #if REMOVE_FGS |
---|
969 | sliceAddress=(maxParts*lCUAddress)+(innerAddress); |
---|
970 | #else |
---|
971 | sliceAddress=(maxParts*lCUAddress)+(innerAddress*(maxParts>>(pps->getSliceGranularity()<<1))); |
---|
972 | #endif |
---|
973 | rpcSlice->setDependentSliceCurStartCUAddr( sliceAddress ); |
---|
974 | rpcSlice->setDependentSliceCurEndCUAddr(numCUs*maxParts); |
---|
975 | |
---|
976 | #if SLICEHEADER_SYNTAX_FIX |
---|
977 | if( pps->getDependentSliceEnabledFlag() && (sliceAddress !=0 )) |
---|
978 | { |
---|
979 | READ_FLAG( uiCode, "dependent_slice_flag" ); rpcSlice->setDependentSliceFlag(uiCode ? true : false); |
---|
980 | } |
---|
981 | else |
---|
982 | { |
---|
983 | rpcSlice->setDependentSliceFlag(false); |
---|
984 | } |
---|
985 | |
---|
986 | if (rpcSlice->getDependentSliceFlag()) |
---|
987 | { |
---|
988 | rpcSlice->setNextSlice ( false ); |
---|
989 | rpcSlice->setNextDependentSlice ( true ); |
---|
990 | } |
---|
991 | else |
---|
992 | { |
---|
993 | rpcSlice->setNextSlice ( true ); |
---|
994 | rpcSlice->setNextDependentSlice ( false ); |
---|
995 | |
---|
996 | rpcSlice->setSliceCurStartCUAddr(sliceAddress); |
---|
997 | rpcSlice->setSliceCurEndCUAddr(numCUs*maxParts); |
---|
998 | } |
---|
999 | |
---|
1000 | if(!rpcSlice->getDependentSliceFlag()) |
---|
1001 | { |
---|
1002 | #endif |
---|
1003 | READ_UVLC ( uiCode, "slice_type" ); rpcSlice->setSliceType((SliceType)uiCode); |
---|
1004 | #if !SLICEHEADER_SYNTAX_FIX |
---|
1005 | // lightweight_slice_flag |
---|
1006 | READ_FLAG( uiCode, "dependent_slice_flag" ); |
---|
1007 | Bool bDependentSlice = uiCode ? true : false; |
---|
1008 | #if DEPENDENT_SLICES |
---|
1009 | if( rpcSlice->getPPS()->getDependentSliceEnabledFlag()) |
---|
1010 | { |
---|
1011 | if(bDependentSlice) |
---|
1012 | { |
---|
1013 | rpcSlice->setNextSlice ( false ); |
---|
1014 | rpcSlice->setNextDependentSlice( true ); |
---|
1015 | #if BYTE_ALIGNMENT |
---|
1016 | m_pcBitstream->readByteAlignment(); |
---|
1017 | #else |
---|
1018 | m_pcBitstream->readOutTrailingBits(); |
---|
1019 | #endif |
---|
1020 | return; |
---|
1021 | } |
---|
1022 | } |
---|
1023 | #endif |
---|
1024 | if (bDependentSlice) |
---|
1025 | { |
---|
1026 | rpcSlice->setNextSlice ( false ); |
---|
1027 | rpcSlice->setNextDependentSlice ( true ); |
---|
1028 | } |
---|
1029 | else |
---|
1030 | { |
---|
1031 | rpcSlice->setNextSlice ( true ); |
---|
1032 | rpcSlice->setNextDependentSlice ( false ); |
---|
1033 | |
---|
1034 | rpcSlice->setSliceCurStartCUAddr(sliceAddress); |
---|
1035 | rpcSlice->setSliceCurEndCUAddr(numCUs*maxParts); |
---|
1036 | } |
---|
1037 | |
---|
1038 | if (!bDependentSlice) |
---|
1039 | { |
---|
1040 | #endif // !SLICEHEADER_SYNTAX_FIX |
---|
1041 | if( pps->getOutputFlagPresentFlag() ) |
---|
1042 | { |
---|
1043 | READ_FLAG( uiCode, "pic_output_flag" ); rpcSlice->setPicOutputFlag( uiCode ? true : false ); |
---|
1044 | } |
---|
1045 | else |
---|
1046 | { |
---|
1047 | rpcSlice->setPicOutputFlag( true ); |
---|
1048 | } |
---|
1049 | // in the first version chroma_format_idc is equal to one, thus colour_plane_id will not be present |
---|
1050 | assert (sps->getChromaFormatIdc() == 1 ); |
---|
1051 | // if( separate_colour_plane_flag == 1 ) |
---|
1052 | // colour_plane_id u(2) |
---|
1053 | |
---|
1054 | #if !SPLICING_FRIENDLY_PARAMS |
---|
1055 | if( rpcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR |
---|
1056 | #if SUPPORT_FOR_RAP_N_LP |
---|
1057 | || rpcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_N_LP |
---|
1058 | || rpcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_N_LP |
---|
1059 | #endif |
---|
1060 | || rpcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLANT |
---|
1061 | || rpcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA |
---|
1062 | #if !NAL_UNIT_TYPES_J1003_D7 |
---|
1063 | || rpcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_CRANT |
---|
1064 | #endif |
---|
1065 | || rpcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_CRA ) |
---|
1066 | { |
---|
1067 | READ_UVLC( uiCode, "rap_pic_id" ); //ignored |
---|
1068 | READ_FLAG( uiCode, "no_output_of_prior_pics_flag" ); //ignored |
---|
1069 | } |
---|
1070 | #endif |
---|
1071 | #if SUPPORT_FOR_RAP_N_LP |
---|
1072 | if( rpcSlice->getIdrPicFlag() ) |
---|
1073 | #else |
---|
1074 | if( rpcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR ) |
---|
1075 | #endif |
---|
1076 | { |
---|
1077 | rpcSlice->setPOC(0); |
---|
1078 | TComReferencePictureSet* rps = rpcSlice->getLocalRPS(); |
---|
1079 | rps->setNumberOfNegativePictures(0); |
---|
1080 | rps->setNumberOfPositivePictures(0); |
---|
1081 | rps->setNumberOfLongtermPictures(0); |
---|
1082 | rps->setNumberOfPictures(0); |
---|
1083 | rpcSlice->setRPS(rps); |
---|
1084 | } |
---|
1085 | else |
---|
1086 | { |
---|
1087 | READ_CODE(sps->getBitsForPOC(), uiCode, "pic_order_cnt_lsb"); |
---|
1088 | Int iPOClsb = uiCode; |
---|
1089 | Int iPrevPOC = rpcSlice->getPrevPOC(); |
---|
1090 | Int iMaxPOClsb = 1<< sps->getBitsForPOC(); |
---|
1091 | Int iPrevPOClsb = iPrevPOC%iMaxPOClsb; |
---|
1092 | Int iPrevPOCmsb = iPrevPOC-iPrevPOClsb; |
---|
1093 | Int iPOCmsb; |
---|
1094 | if( ( iPOClsb < iPrevPOClsb ) && ( ( iPrevPOClsb - iPOClsb ) >= ( iMaxPOClsb / 2 ) ) ) |
---|
1095 | { |
---|
1096 | iPOCmsb = iPrevPOCmsb + iMaxPOClsb; |
---|
1097 | } |
---|
1098 | else if( (iPOClsb > iPrevPOClsb ) && ( (iPOClsb - iPrevPOClsb ) > ( iMaxPOClsb / 2 ) ) ) |
---|
1099 | { |
---|
1100 | iPOCmsb = iPrevPOCmsb - iMaxPOClsb; |
---|
1101 | } |
---|
1102 | else |
---|
1103 | { |
---|
1104 | iPOCmsb = iPrevPOCmsb; |
---|
1105 | } |
---|
1106 | #if SUPPORT_FOR_RAP_N_LP |
---|
1107 | if ( rpcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA |
---|
1108 | || rpcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLANT |
---|
1109 | || rpcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_N_LP ) |
---|
1110 | #else |
---|
1111 | if( rpcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA |
---|
1112 | || rpcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLANT ) |
---|
1113 | #endif |
---|
1114 | { |
---|
1115 | // For BLA picture types, POCmsb is set to 0. |
---|
1116 | iPOCmsb = 0; |
---|
1117 | } |
---|
1118 | rpcSlice->setPOC (iPOCmsb+iPOClsb); |
---|
1119 | |
---|
1120 | TComReferencePictureSet* rps; |
---|
1121 | READ_FLAG( uiCode, "short_term_ref_pic_set_sps_flag" ); |
---|
1122 | if(uiCode == 0) // use short-term reference picture set explicitly signalled in slice header |
---|
1123 | { |
---|
1124 | rps = rpcSlice->getLocalRPS(); |
---|
1125 | parseShortTermRefPicSet(sps,rps, sps->getRPSList()->getNumberOfReferencePictureSets()); |
---|
1126 | rpcSlice->setRPS(rps); |
---|
1127 | } |
---|
1128 | else // use reference to short-term reference picture set in PPS |
---|
1129 | { |
---|
1130 | READ_UVLC( uiCode, "short_term_ref_pic_set_idx"); rpcSlice->setRPS(sps->getRPSList()->getReferencePictureSet(uiCode)); |
---|
1131 | rps = rpcSlice->getRPS(); |
---|
1132 | } |
---|
1133 | if(sps->getLongTermRefsPresent()) |
---|
1134 | { |
---|
1135 | Int offset = rps->getNumberOfNegativePictures()+rps->getNumberOfPositivePictures(); |
---|
1136 | #if LTRP_IN_SPS |
---|
1137 | UInt numOfLtrp = 0; |
---|
1138 | UInt numLtrpInSPS = 0; |
---|
1139 | if (rpcSlice->getSPS()->getNumLongTermRefPicSPS() > 0) |
---|
1140 | { |
---|
1141 | READ_UVLC( uiCode, "num_long_term_sps"); |
---|
1142 | numLtrpInSPS = uiCode; |
---|
1143 | numOfLtrp += numLtrpInSPS; |
---|
1144 | rps->setNumberOfLongtermPictures(numOfLtrp); |
---|
1145 | } |
---|
1146 | Int bitsForLtrpInSPS = 1; |
---|
1147 | while (rpcSlice->getSPS()->getNumLongTermRefPicSPS() > (1 << bitsForLtrpInSPS)) |
---|
1148 | bitsForLtrpInSPS++; |
---|
1149 | READ_UVLC( uiCode, "num_long_term_pics"); rps->setNumberOfLongtermPictures(uiCode); |
---|
1150 | numOfLtrp += uiCode; |
---|
1151 | rps->setNumberOfLongtermPictures(numOfLtrp); |
---|
1152 | #else |
---|
1153 | READ_UVLC( uiCode, "num_long_term_pics"); rps->setNumberOfLongtermPictures(uiCode); |
---|
1154 | #endif |
---|
1155 | Int maxPicOrderCntLSB = 1 << rpcSlice->getSPS()->getBitsForPOC(); |
---|
1156 | Int prevLSB = 0, prevDeltaMSB = 0, deltaPocMSBCycleLT = 0;; |
---|
1157 | #if LTRP_IN_SPS |
---|
1158 | for(Int j=offset+rps->getNumberOfLongtermPictures()-1, k = 0; k < numOfLtrp; j--, k++) |
---|
1159 | #else |
---|
1160 | for(Int j=offset+rps->getNumberOfLongtermPictures()-1 ; j > offset-1; j--) |
---|
1161 | #endif |
---|
1162 | { |
---|
1163 | #if LTRP_IN_SPS |
---|
1164 | if (k < numLtrpInSPS) |
---|
1165 | { |
---|
1166 | READ_CODE(bitsForLtrpInSPS, uiCode, "lt_idx_sps[i]"); |
---|
1167 | Int usedByCurrFromSPS=rpcSlice->getSPS()->getUsedByCurrPicLtSPSFlag(uiCode); |
---|
1168 | |
---|
1169 | uiCode = rpcSlice->getSPS()->getLtRefPicPocLsbSps(uiCode); |
---|
1170 | rps->setUsed(j,usedByCurrFromSPS); |
---|
1171 | } |
---|
1172 | else |
---|
1173 | { |
---|
1174 | READ_CODE(rpcSlice->getSPS()->getBitsForPOC(), uiCode, "poc_lsb_lt"); |
---|
1175 | READ_FLAG( uiCode, "used_by_curr_pic_lt_flag"); rps->setUsed(j,uiCode); |
---|
1176 | } |
---|
1177 | #else |
---|
1178 | READ_CODE(rpcSlice->getSPS()->getBitsForPOC(), uiCode, "poc_lsb_lt"); |
---|
1179 | #endif |
---|
1180 | Int poc_lsb_lt = uiCode; |
---|
1181 | READ_FLAG(uiCode,"delta_poc_msb_present_flag"); |
---|
1182 | Bool mSBPresentFlag = uiCode ? true : false; |
---|
1183 | if(mSBPresentFlag) |
---|
1184 | { |
---|
1185 | READ_UVLC( uiCode, "delta_poc_msb_cycle_lt[i]" ); |
---|
1186 | Bool deltaFlag = false; |
---|
1187 | #if LTRP_IN_SPS |
---|
1188 | // First LTRP || First LTRP from SH || curr LSB != prev LSB |
---|
1189 | if( (j == offset+rps->getNumberOfLongtermPictures()-1) || (j == offset+(numOfLtrp-numLtrpInSPS)-1) || (poc_lsb_lt != prevLSB) ) |
---|
1190 | #else |
---|
1191 | // First LTRP || curr LSB != prev LSB |
---|
1192 | if( (j == offset+rps->getNumberOfLongtermPictures()-1) || (poc_lsb_lt != prevLSB) ) |
---|
1193 | #endif |
---|
1194 | { |
---|
1195 | deltaFlag = true; |
---|
1196 | } |
---|
1197 | if(deltaFlag) |
---|
1198 | { |
---|
1199 | deltaPocMSBCycleLT = uiCode; |
---|
1200 | } |
---|
1201 | else |
---|
1202 | { |
---|
1203 | deltaPocMSBCycleLT = uiCode + prevDeltaMSB; |
---|
1204 | } |
---|
1205 | |
---|
1206 | Int pocLTCurr = rpcSlice->getPOC() - deltaPocMSBCycleLT * maxPicOrderCntLSB |
---|
1207 | - iPOClsb + poc_lsb_lt; |
---|
1208 | rps->setPOC (j, pocLTCurr); |
---|
1209 | rps->setDeltaPOC(j, - rpcSlice->getPOC() + pocLTCurr); |
---|
1210 | rps->setCheckLTMSBPresent(j,true); |
---|
1211 | } |
---|
1212 | else |
---|
1213 | { |
---|
1214 | rps->setPOC (j, poc_lsb_lt); |
---|
1215 | rps->setDeltaPOC(j, - rpcSlice->getPOC() + poc_lsb_lt); |
---|
1216 | rps->setCheckLTMSBPresent(j,false); |
---|
1217 | } |
---|
1218 | #if !LTRP_IN_SPS |
---|
1219 | READ_FLAG( uiCode, "used_by_curr_pic_lt_flag"); rps->setUsed(j,uiCode); |
---|
1220 | #endif |
---|
1221 | prevLSB = poc_lsb_lt; |
---|
1222 | prevDeltaMSB = deltaPocMSBCycleLT; |
---|
1223 | } |
---|
1224 | offset += rps->getNumberOfLongtermPictures(); |
---|
1225 | rps->setNumberOfPictures(offset); |
---|
1226 | } |
---|
1227 | #if SUPPORT_FOR_RAP_N_LP |
---|
1228 | if ( rpcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA |
---|
1229 | || rpcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLANT |
---|
1230 | || rpcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_N_LP ) |
---|
1231 | #else |
---|
1232 | if( rpcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA |
---|
1233 | || rpcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLANT ) |
---|
1234 | #endif |
---|
1235 | { |
---|
1236 | // In the case of BLA picture types, rps data is read from slice header but ignored |
---|
1237 | rps = rpcSlice->getLocalRPS(); |
---|
1238 | rps->setNumberOfNegativePictures(0); |
---|
1239 | rps->setNumberOfPositivePictures(0); |
---|
1240 | rps->setNumberOfLongtermPictures(0); |
---|
1241 | rps->setNumberOfPictures(0); |
---|
1242 | rpcSlice->setRPS(rps); |
---|
1243 | } |
---|
1244 | } |
---|
1245 | #if REMOVE_ALF |
---|
1246 | if(sps->getUseSAO()) |
---|
1247 | #else |
---|
1248 | if(sps->getUseSAO() || sps->getUseALF()) |
---|
1249 | #endif |
---|
1250 | { |
---|
1251 | if (sps->getUseSAO()) |
---|
1252 | { |
---|
1253 | READ_FLAG(uiCode, "slice_sao_luma_flag"); rpcSlice->setSaoEnabledFlag((Bool)uiCode); |
---|
1254 | #if !SAO_LUM_CHROMA_ONOFF_FLAGS |
---|
1255 | if (rpcSlice->getSaoEnabledFlag() ) |
---|
1256 | #endif |
---|
1257 | { |
---|
1258 | #if SAO_TYPE_SHARING |
---|
1259 | READ_FLAG(uiCode, "slice_sao_chroma_flag"); rpcSlice->setSaoEnabledFlagChroma((Bool)uiCode); |
---|
1260 | #else |
---|
1261 | READ_FLAG(uiCode, "sao_cb_enable_flag"); rpcSlice->setSaoEnabledFlagCb((Bool)uiCode); |
---|
1262 | READ_FLAG(uiCode, "sao_cr_enable_flag"); rpcSlice->setSaoEnabledFlagCr((Bool)uiCode); |
---|
1263 | #endif |
---|
1264 | } |
---|
1265 | #if !SAO_LUM_CHROMA_ONOFF_FLAGS |
---|
1266 | else |
---|
1267 | { |
---|
1268 | #if SAO_TYPE_SHARING |
---|
1269 | rpcSlice->setSaoEnabledFlagChroma(0); |
---|
1270 | #else |
---|
1271 | rpcSlice->setSaoEnabledFlagCb(0); |
---|
1272 | rpcSlice->setSaoEnabledFlagCr(0); |
---|
1273 | #endif |
---|
1274 | } |
---|
1275 | #endif |
---|
1276 | } |
---|
1277 | #if !REMOVE_APS |
---|
1278 | READ_UVLC ( uiCode, "aps_id" ); rpcSlice->setAPSId(uiCode); |
---|
1279 | #endif |
---|
1280 | } |
---|
1281 | if (!rpcSlice->isIntra()) |
---|
1282 | { |
---|
1283 | if (rpcSlice->getSPS()->getTMVPFlagsPresent()) |
---|
1284 | { |
---|
1285 | READ_FLAG( uiCode, "enable_temporal_mvp_flag" ); |
---|
1286 | rpcSlice->setEnableTMVPFlag(uiCode); |
---|
1287 | } |
---|
1288 | else |
---|
1289 | { |
---|
1290 | rpcSlice->setEnableTMVPFlag(false); |
---|
1291 | } |
---|
1292 | READ_FLAG( uiCode, "num_ref_idx_active_override_flag"); |
---|
1293 | if (uiCode) |
---|
1294 | { |
---|
1295 | READ_UVLC (uiCode, "num_ref_idx_l0_active_minus1" ); rpcSlice->setNumRefIdx( REF_PIC_LIST_0, uiCode + 1 ); |
---|
1296 | if (rpcSlice->isInterB()) |
---|
1297 | { |
---|
1298 | READ_UVLC (uiCode, "num_ref_idx_l1_active_minus1" ); rpcSlice->setNumRefIdx( REF_PIC_LIST_1, uiCode + 1 ); |
---|
1299 | } |
---|
1300 | else |
---|
1301 | { |
---|
1302 | rpcSlice->setNumRefIdx(REF_PIC_LIST_1, 0); |
---|
1303 | } |
---|
1304 | } |
---|
1305 | else |
---|
1306 | { |
---|
1307 | rpcSlice->setNumRefIdx(REF_PIC_LIST_0, rpcSlice->getPPS()->getNumRefIdxL0DefaultActive()); |
---|
1308 | if (rpcSlice->isInterB()) |
---|
1309 | { |
---|
1310 | rpcSlice->setNumRefIdx(REF_PIC_LIST_1, rpcSlice->getPPS()->getNumRefIdxL1DefaultActive()); |
---|
1311 | } |
---|
1312 | else |
---|
1313 | { |
---|
1314 | rpcSlice->setNumRefIdx(REF_PIC_LIST_1,0); |
---|
1315 | } |
---|
1316 | } |
---|
1317 | } |
---|
1318 | // } |
---|
1319 | TComRefPicListModification* refPicListModification = rpcSlice->getRefPicListModification(); |
---|
1320 | if(!rpcSlice->isIntra()) |
---|
1321 | { |
---|
1322 | if( !rpcSlice->getSPS()->getListsModificationPresentFlag() ) |
---|
1323 | { |
---|
1324 | refPicListModification->setRefPicListModificationFlagL0( 0 ); |
---|
1325 | } |
---|
1326 | else |
---|
1327 | { |
---|
1328 | READ_FLAG( uiCode, "ref_pic_list_modification_flag_l0" ); refPicListModification->setRefPicListModificationFlagL0( uiCode ? 1 : 0 ); |
---|
1329 | } |
---|
1330 | |
---|
1331 | if(refPicListModification->getRefPicListModificationFlagL0()) |
---|
1332 | { |
---|
1333 | uiCode = 0; |
---|
1334 | Int i = 0; |
---|
1335 | Int numRpsCurrTempList0 = rpcSlice->getNumRpsCurrTempList(); |
---|
1336 | if ( numRpsCurrTempList0 > 1 ) |
---|
1337 | { |
---|
1338 | Int length = 1; |
---|
1339 | numRpsCurrTempList0 --; |
---|
1340 | while ( numRpsCurrTempList0 >>= 1) |
---|
1341 | { |
---|
1342 | length ++; |
---|
1343 | } |
---|
1344 | for (i = 0; i < rpcSlice->getNumRefIdx(REF_PIC_LIST_0); i ++) |
---|
1345 | { |
---|
1346 | READ_CODE( length, uiCode, "list_entry_l0" ); |
---|
1347 | refPicListModification->setRefPicSetIdxL0(i, uiCode ); |
---|
1348 | } |
---|
1349 | } |
---|
1350 | else |
---|
1351 | { |
---|
1352 | for (i = 0; i < rpcSlice->getNumRefIdx(REF_PIC_LIST_0); i ++) |
---|
1353 | { |
---|
1354 | refPicListModification->setRefPicSetIdxL0(i, 0 ); |
---|
1355 | } |
---|
1356 | } |
---|
1357 | } |
---|
1358 | } |
---|
1359 | else |
---|
1360 | { |
---|
1361 | refPicListModification->setRefPicListModificationFlagL0(0); |
---|
1362 | } |
---|
1363 | if(rpcSlice->isInterB()) |
---|
1364 | { |
---|
1365 | if( !rpcSlice->getSPS()->getListsModificationPresentFlag() ) |
---|
1366 | { |
---|
1367 | refPicListModification->setRefPicListModificationFlagL1( 0 ); |
---|
1368 | } |
---|
1369 | else |
---|
1370 | { |
---|
1371 | READ_FLAG( uiCode, "ref_pic_list_modification_flag_l1" ); refPicListModification->setRefPicListModificationFlagL1( uiCode ? 1 : 0 ); |
---|
1372 | } |
---|
1373 | if(refPicListModification->getRefPicListModificationFlagL1()) |
---|
1374 | { |
---|
1375 | uiCode = 0; |
---|
1376 | Int i = 0; |
---|
1377 | Int numRpsCurrTempList1 = rpcSlice->getNumRpsCurrTempList(); |
---|
1378 | if ( numRpsCurrTempList1 > 1 ) |
---|
1379 | { |
---|
1380 | Int length = 1; |
---|
1381 | numRpsCurrTempList1 --; |
---|
1382 | while ( numRpsCurrTempList1 >>= 1) |
---|
1383 | { |
---|
1384 | length ++; |
---|
1385 | } |
---|
1386 | for (i = 0; i < rpcSlice->getNumRefIdx(REF_PIC_LIST_1); i ++) |
---|
1387 | { |
---|
1388 | READ_CODE( length, uiCode, "list_entry_l1" ); |
---|
1389 | refPicListModification->setRefPicSetIdxL1(i, uiCode ); |
---|
1390 | } |
---|
1391 | } |
---|
1392 | else |
---|
1393 | { |
---|
1394 | for (i = 0; i < rpcSlice->getNumRefIdx(REF_PIC_LIST_1); i ++) |
---|
1395 | { |
---|
1396 | refPicListModification->setRefPicSetIdxL1(i, 0 ); |
---|
1397 | } |
---|
1398 | } |
---|
1399 | } |
---|
1400 | } |
---|
1401 | else |
---|
1402 | { |
---|
1403 | refPicListModification->setRefPicListModificationFlagL1(0); |
---|
1404 | } |
---|
1405 | #if !SLICEHEADER_SYNTAX_FIX |
---|
1406 | } |
---|
1407 | else |
---|
1408 | { |
---|
1409 | // initialize from previous slice |
---|
1410 | pps = rpcSlice->getPPS(); |
---|
1411 | sps = rpcSlice->getSPS(); |
---|
1412 | } |
---|
1413 | #endif |
---|
1414 | if (rpcSlice->isInterB()) |
---|
1415 | { |
---|
1416 | READ_FLAG( uiCode, "mvd_l1_zero_flag" ); rpcSlice->setMvdL1ZeroFlag( (uiCode ? true : false) ); |
---|
1417 | } |
---|
1418 | |
---|
1419 | rpcSlice->setCabacInitFlag( false ); // default |
---|
1420 | if(pps->getCabacInitPresentFlag() && !rpcSlice->isIntra()) |
---|
1421 | { |
---|
1422 | READ_FLAG(uiCode, "cabac_init_flag"); |
---|
1423 | rpcSlice->setCabacInitFlag( uiCode ? true : false ); |
---|
1424 | } |
---|
1425 | |
---|
1426 | #if !SLICEHEADER_SYNTAX_FIX |
---|
1427 | if(!bDependentSlice) |
---|
1428 | { |
---|
1429 | #else |
---|
1430 | if ( rpcSlice->getEnableTMVPFlag() ) |
---|
1431 | { |
---|
1432 | if ( rpcSlice->getSliceType() == B_SLICE ) |
---|
1433 | { |
---|
1434 | READ_FLAG( uiCode, "collocated_from_l0_flag" ); |
---|
1435 | rpcSlice->setColFromL0Flag(uiCode); |
---|
1436 | } |
---|
1437 | else |
---|
1438 | { |
---|
1439 | rpcSlice->setColFromL0Flag( 1 ); |
---|
1440 | } |
---|
1441 | |
---|
1442 | if ( rpcSlice->getSliceType() != I_SLICE && |
---|
1443 | ((rpcSlice->getColFromL0Flag()==1 && rpcSlice->getNumRefIdx(REF_PIC_LIST_0)>1)|| |
---|
1444 | (rpcSlice->getColFromL0Flag() ==0 && rpcSlice->getNumRefIdx(REF_PIC_LIST_1)>1))) |
---|
1445 | { |
---|
1446 | READ_UVLC( uiCode, "collocated_ref_idx" ); |
---|
1447 | rpcSlice->setColRefIdx(uiCode); |
---|
1448 | } |
---|
1449 | else |
---|
1450 | { |
---|
1451 | rpcSlice->setColRefIdx(0); |
---|
1452 | } |
---|
1453 | } |
---|
1454 | if ( (pps->getUseWP() && rpcSlice->getSliceType()==P_SLICE) || (pps->getWPBiPred() && rpcSlice->getSliceType()==B_SLICE) ) |
---|
1455 | { |
---|
1456 | xParsePredWeightTable(rpcSlice); |
---|
1457 | rpcSlice->initWpScaling(); |
---|
1458 | } |
---|
1459 | READ_UVLC( uiCode, "five_minus_max_num_merge_cand"); |
---|
1460 | rpcSlice->setMaxNumMergeCand(MRG_MAX_NUM_CANDS - uiCode); |
---|
1461 | |
---|
1462 | #endif |
---|
1463 | READ_SVLC( iCode, "slice_qp_delta" ); |
---|
1464 | rpcSlice->setSliceQp (26 + pps->getPicInitQPMinus26() + iCode); |
---|
1465 | |
---|
1466 | assert( rpcSlice->getSliceQp() >= -sps->getQpBDOffsetY() ); |
---|
1467 | assert( rpcSlice->getSliceQp() <= 51 ); |
---|
1468 | |
---|
1469 | #if CHROMA_QP_EXTENSION |
---|
1470 | if (rpcSlice->getPPS()->getSliceChromaQpFlag()) |
---|
1471 | { |
---|
1472 | READ_SVLC( iCode, "slice_qp_delta_cb" ); |
---|
1473 | rpcSlice->setSliceQpDeltaCb( iCode ); |
---|
1474 | assert( rpcSlice->getSliceQpDeltaCb() >= -12 ); |
---|
1475 | assert( rpcSlice->getSliceQpDeltaCb() <= 12 ); |
---|
1476 | assert( (rpcSlice->getPPS()->getChromaCbQpOffset() + rpcSlice->getSliceQpDeltaCb()) >= -12 ); |
---|
1477 | assert( (rpcSlice->getPPS()->getChromaCbQpOffset() + rpcSlice->getSliceQpDeltaCb()) <= 12 ); |
---|
1478 | |
---|
1479 | READ_SVLC( iCode, "slice_qp_delta_cr" ); |
---|
1480 | rpcSlice->setSliceQpDeltaCr( iCode ); |
---|
1481 | assert( rpcSlice->getSliceQpDeltaCr() >= -12 ); |
---|
1482 | assert( rpcSlice->getSliceQpDeltaCr() <= 12 ); |
---|
1483 | assert( (rpcSlice->getPPS()->getChromaCrQpOffset() + rpcSlice->getSliceQpDeltaCr()) >= -12 ); |
---|
1484 | assert( (rpcSlice->getPPS()->getChromaCrQpOffset() + rpcSlice->getSliceQpDeltaCr()) <= 12 ); |
---|
1485 | } |
---|
1486 | #endif |
---|
1487 | |
---|
1488 | if (rpcSlice->getPPS()->getDeblockingFilterControlPresentFlag()) |
---|
1489 | { |
---|
1490 | if(rpcSlice->getPPS()->getDeblockingFilterOverrideEnabledFlag()) |
---|
1491 | { |
---|
1492 | READ_FLAG ( uiCode, "deblocking_filter_override_flag" ); rpcSlice->setDeblockingFilterOverrideFlag(uiCode ? true : false); |
---|
1493 | } |
---|
1494 | else |
---|
1495 | { |
---|
1496 | rpcSlice->setDeblockingFilterOverrideFlag(0); |
---|
1497 | } |
---|
1498 | if(rpcSlice->getDeblockingFilterOverrideFlag()) |
---|
1499 | { |
---|
1500 | READ_FLAG ( uiCode, "slice_disable_deblocking_filter_flag" ); rpcSlice->setDeblockingFilterDisable(uiCode ? 1 : 0); |
---|
1501 | if(!rpcSlice->getDeblockingFilterDisable()) |
---|
1502 | { |
---|
1503 | READ_SVLC( iCode, "beta_offset_div2" ); rpcSlice->setDeblockingFilterBetaOffsetDiv2(iCode); |
---|
1504 | READ_SVLC( iCode, "tc_offset_div2" ); rpcSlice->setDeblockingFilterTcOffsetDiv2(iCode); |
---|
1505 | } |
---|
1506 | } |
---|
1507 | else |
---|
1508 | { |
---|
1509 | rpcSlice->setDeblockingFilterDisable ( rpcSlice->getPPS()->getPicDisableDeblockingFilterFlag() ); |
---|
1510 | rpcSlice->setDeblockingFilterBetaOffsetDiv2( rpcSlice->getPPS()->getDeblockingFilterBetaOffsetDiv2() ); |
---|
1511 | rpcSlice->setDeblockingFilterTcOffsetDiv2 ( rpcSlice->getPPS()->getDeblockingFilterTcOffsetDiv2() ); |
---|
1512 | } |
---|
1513 | } |
---|
1514 | #if !SLICEHEADER_SYNTAX_FIX |
---|
1515 | if ( rpcSlice->getEnableTMVPFlag() ) |
---|
1516 | { |
---|
1517 | if ( rpcSlice->getSliceType() == B_SLICE ) |
---|
1518 | { |
---|
1519 | READ_FLAG( uiCode, "collocated_from_l0_flag" ); |
---|
1520 | rpcSlice->setColFromL0Flag(uiCode); |
---|
1521 | } |
---|
1522 | |
---|
1523 | if ( rpcSlice->getSliceType() != I_SLICE && |
---|
1524 | ((rpcSlice->getColFromL0Flag()==1 && rpcSlice->getNumRefIdx(REF_PIC_LIST_0)>1)|| |
---|
1525 | (rpcSlice->getColFromL0Flag() ==0 && rpcSlice->getNumRefIdx(REF_PIC_LIST_1)>1))) |
---|
1526 | { |
---|
1527 | READ_UVLC( uiCode, "collocated_ref_idx" ); |
---|
1528 | rpcSlice->setColRefIdx(uiCode); |
---|
1529 | } |
---|
1530 | else |
---|
1531 | { |
---|
1532 | rpcSlice->setColRefIdx(0); |
---|
1533 | } |
---|
1534 | } |
---|
1535 | if ( (pps->getUseWP() && rpcSlice->getSliceType()==P_SLICE) || (pps->getWPBiPred() && rpcSlice->getSliceType()==B_SLICE) ) |
---|
1536 | { |
---|
1537 | xParsePredWeightTable(rpcSlice); |
---|
1538 | rpcSlice->initWpScaling(); |
---|
1539 | } |
---|
1540 | } |
---|
1541 | |
---|
1542 | READ_UVLC( uiCode, "five_minus_max_num_merge_cand"); |
---|
1543 | rpcSlice->setMaxNumMergeCand(MRG_MAX_NUM_CANDS - uiCode); |
---|
1544 | |
---|
1545 | if (!bDependentSlice) |
---|
1546 | { |
---|
1547 | #endif |
---|
1548 | #if !REMOVE_ALF |
---|
1549 | if(sps->getUseALF()) |
---|
1550 | { |
---|
1551 | char syntaxString[50]; |
---|
1552 | for(Int compIdx=0; compIdx< 3; compIdx++) |
---|
1553 | { |
---|
1554 | sprintf(syntaxString, "alf_slice_filter_flag[%d]", compIdx); |
---|
1555 | READ_FLAG(uiCode, syntaxString); |
---|
1556 | rpcSlice->setAlfEnabledFlag( (uiCode ==1), compIdx); |
---|
1557 | } |
---|
1558 | } |
---|
1559 | Bool isAlfEnabled = (!rpcSlice->getSPS()->getUseALF())?(false):(rpcSlice->getAlfEnabledFlag(0)||rpcSlice->getAlfEnabledFlag(1)||rpcSlice->getAlfEnabledFlag(2)); |
---|
1560 | #endif |
---|
1561 | #if !SAO_LUM_CHROMA_ONOFF_FLAGS |
---|
1562 | Bool isSAOEnabled = (!rpcSlice->getSPS()->getUseSAO())?(false):(rpcSlice->getSaoEnabledFlag()); |
---|
1563 | #else |
---|
1564 | Bool isSAOEnabled = (!rpcSlice->getSPS()->getUseSAO())?(false):(rpcSlice->getSaoEnabledFlag()||rpcSlice->getSaoEnabledFlagChroma()); |
---|
1565 | #endif |
---|
1566 | Bool isDBFEnabled = (!rpcSlice->getDeblockingFilterDisable()); |
---|
1567 | |
---|
1568 | #if REMOVE_ALF |
---|
1569 | #if MOVE_LOOP_FILTER_SLICES_FLAG |
---|
1570 | if(rpcSlice->getPPS()->getLoopFilterAcrossSlicesEnabledFlag() && ( isSAOEnabled || isDBFEnabled )) |
---|
1571 | #else |
---|
1572 | if(rpcSlice->getSPS()->getLFCrossSliceBoundaryFlag() && ( isSAOEnabled || isDBFEnabled )) |
---|
1573 | #endif |
---|
1574 | #else |
---|
1575 | if(rpcSlice->getSPS()->getLFCrossSliceBoundaryFlag() && ( isAlfEnabled || isSAOEnabled || isDBFEnabled )) |
---|
1576 | #endif |
---|
1577 | { |
---|
1578 | READ_FLAG( uiCode, "slice_loop_filter_across_slices_enabled_flag"); |
---|
1579 | } |
---|
1580 | else |
---|
1581 | { |
---|
1582 | #if MOVE_LOOP_FILTER_SLICES_FLAG |
---|
1583 | uiCode = rpcSlice->getPPS()->getLoopFilterAcrossSlicesEnabledFlag()?1:0; |
---|
1584 | #else |
---|
1585 | uiCode = rpcSlice->getSPS()->getLFCrossSliceBoundaryFlag()?1:0; |
---|
1586 | #endif |
---|
1587 | } |
---|
1588 | rpcSlice->setLFCrossSliceBoundaryFlag( (uiCode==1)?true:false); |
---|
1589 | |
---|
1590 | #if !SLICEHEADER_SYNTAX_FIX |
---|
1591 | } |
---|
1592 | #else |
---|
1593 | } |
---|
1594 | if( pps->getTilesEnabledFlag() || pps->getEntropyCodingSyncEnabledFlag() ) |
---|
1595 | #endif |
---|
1596 | { |
---|
1597 | #if !SLICEHEADER_SYNTAX_FIX |
---|
1598 | Int tilesOrEntropyCodingSyncIdc = pps->getTilesOrEntropyCodingSyncIdc(); |
---|
1599 | #endif |
---|
1600 | UInt *entryPointOffset = NULL; |
---|
1601 | UInt numEntryPointOffsets, offsetLenMinus1; |
---|
1602 | |
---|
1603 | #if !SLICEHEADER_SYNTAX_FIX |
---|
1604 | rpcSlice->setNumEntryPointOffsets ( 0 ); // default |
---|
1605 | |
---|
1606 | if (tilesOrEntropyCodingSyncIdc>0) |
---|
1607 | { |
---|
1608 | #endif |
---|
1609 | READ_UVLC(numEntryPointOffsets, "num_entry_point_offsets"); rpcSlice->setNumEntryPointOffsets ( numEntryPointOffsets ); |
---|
1610 | if (numEntryPointOffsets>0) |
---|
1611 | { |
---|
1612 | READ_UVLC(offsetLenMinus1, "offset_len_minus1"); |
---|
1613 | } |
---|
1614 | entryPointOffset = new UInt[numEntryPointOffsets]; |
---|
1615 | for (UInt idx=0; idx<numEntryPointOffsets; idx++) |
---|
1616 | { |
---|
1617 | READ_CODE(offsetLenMinus1+1, uiCode, "entry_point_offset"); |
---|
1618 | entryPointOffset[ idx ] = uiCode; |
---|
1619 | } |
---|
1620 | #if !SLICEHEADER_SYNTAX_FIX |
---|
1621 | } |
---|
1622 | #endif |
---|
1623 | |
---|
1624 | #if !SLICEHEADER_SYNTAX_FIX |
---|
1625 | if ( tilesOrEntropyCodingSyncIdc == 1 ) // tiles |
---|
1626 | #else |
---|
1627 | if ( pps->getTilesEnabledFlag() ) |
---|
1628 | #endif |
---|
1629 | { |
---|
1630 | rpcSlice->setTileLocationCount( numEntryPointOffsets ); |
---|
1631 | |
---|
1632 | UInt prevPos = 0; |
---|
1633 | for (Int idx=0; idx<rpcSlice->getTileLocationCount(); idx++) |
---|
1634 | { |
---|
1635 | rpcSlice->setTileLocation( idx, prevPos + entryPointOffset [ idx ] ); |
---|
1636 | prevPos += entryPointOffset[ idx ]; |
---|
1637 | } |
---|
1638 | } |
---|
1639 | #if !SLICEHEADER_SYNTAX_FIX |
---|
1640 | else if ( tilesOrEntropyCodingSyncIdc == 2 ) // wavefront |
---|
1641 | #else |
---|
1642 | else if ( pps->getEntropyCodingSyncEnabledFlag() ) |
---|
1643 | #endif |
---|
1644 | { |
---|
1645 | Int numSubstreams = rpcSlice->getNumEntryPointOffsets()+1; |
---|
1646 | rpcSlice->allocSubstreamSizes(numSubstreams); |
---|
1647 | UInt *pSubstreamSizes = rpcSlice->getSubstreamSizes(); |
---|
1648 | for (Int idx=0; idx<numSubstreams-1; idx++) |
---|
1649 | { |
---|
1650 | if ( idx < numEntryPointOffsets ) |
---|
1651 | { |
---|
1652 | pSubstreamSizes[ idx ] = ( entryPointOffset[ idx ] << 3 ) ; |
---|
1653 | } |
---|
1654 | else |
---|
1655 | { |
---|
1656 | pSubstreamSizes[ idx ] = 0; |
---|
1657 | } |
---|
1658 | } |
---|
1659 | } |
---|
1660 | |
---|
1661 | if (entryPointOffset) |
---|
1662 | { |
---|
1663 | delete [] entryPointOffset; |
---|
1664 | } |
---|
1665 | } |
---|
1666 | #if SLICEHEADER_SYNTAX_FIX |
---|
1667 | else |
---|
1668 | { |
---|
1669 | rpcSlice->setNumEntryPointOffsets ( 0 ); |
---|
1670 | } |
---|
1671 | #endif |
---|
1672 | |
---|
1673 | #if SLICE_HEADER_EXTENSION |
---|
1674 | if(pps->getSliceHeaderExtensionPresentFlag()) |
---|
1675 | { |
---|
1676 | READ_UVLC(uiCode,"slice_header_extension_length"); |
---|
1677 | for(Int i=0; i<uiCode; i++) |
---|
1678 | { |
---|
1679 | UInt ignore; |
---|
1680 | READ_CODE(8,ignore,"slice_header_extension_data_byte"); |
---|
1681 | } |
---|
1682 | } |
---|
1683 | #endif |
---|
1684 | #if BYTE_ALIGNMENT |
---|
1685 | m_pcBitstream->readByteAlignment(); |
---|
1686 | #else |
---|
1687 | if (!bDependentSlice) |
---|
1688 | { |
---|
1689 | // Reading location information |
---|
1690 | // read out trailing bits |
---|
1691 | m_pcBitstream->readOutTrailingBits(); |
---|
1692 | } |
---|
1693 | #endif |
---|
1694 | return; |
---|
1695 | } |
---|
1696 | |
---|
1697 | #if PROFILE_TIER_LEVEL_SYNTAX |
---|
1698 | Void TDecCavlc::parsePTL( TComPTL *rpcPTL, Bool profilePresentFlag, Int maxNumSubLayersMinus1 ) |
---|
1699 | { |
---|
1700 | UInt uiCode; |
---|
1701 | if(profilePresentFlag) |
---|
1702 | { |
---|
1703 | parseProfileTier(rpcPTL->getGeneralPTL()); |
---|
1704 | } |
---|
1705 | READ_CODE( 8, uiCode, "general_level_idc" ); rpcPTL->getGeneralPTL()->setLevelIdc(uiCode); |
---|
1706 | |
---|
1707 | for(Int i = 0; i < maxNumSubLayersMinus1; i++) |
---|
1708 | { |
---|
1709 | READ_FLAG( uiCode, "sub_layer_profile_present_flag[i]" ); rpcPTL->setSubLayerProfilePresentFlag(i, uiCode); |
---|
1710 | READ_FLAG( uiCode, "sub_layer_level_present_flag[i]" ); rpcPTL->setSubLayerLevelPresentFlag (i, uiCode); |
---|
1711 | if( profilePresentFlag && rpcPTL->getSubLayerProfilePresentFlag(i) ) |
---|
1712 | { |
---|
1713 | parseProfileTier(rpcPTL->getSubLayerPTL(i)); |
---|
1714 | } |
---|
1715 | if(rpcPTL->getSubLayerLevelPresentFlag(i)) |
---|
1716 | { |
---|
1717 | READ_CODE( 8, uiCode, "sub_layer_level_idc[i]" ); rpcPTL->getSubLayerPTL(i)->setLevelIdc(uiCode); |
---|
1718 | } |
---|
1719 | } |
---|
1720 | } |
---|
1721 | Void TDecCavlc::parseProfileTier(ProfileTierLevel *ptl) |
---|
1722 | { |
---|
1723 | UInt uiCode; |
---|
1724 | READ_CODE(2 , uiCode, "XXX_profile_space[]"); ptl->setProfileSpace(uiCode); |
---|
1725 | READ_FLAG( uiCode, "XXX_tier_flag[]" ); ptl->setTierFlag (uiCode ? 1 : 0); |
---|
1726 | READ_CODE(5 , uiCode, "XXX_profile_idc[]" ); ptl->setProfileIdc (uiCode); |
---|
1727 | for(Int j = 0; j < 32; j++) |
---|
1728 | { |
---|
1729 | READ_FLAG( uiCode, "XXX_profile_compatibility_flag[][j]"); ptl->setProfileCompatibilityFlag(j, uiCode ? 1 : 0); |
---|
1730 | } |
---|
1731 | READ_CODE(16, uiCode, "XXX_reserved_zero_16bits[]"); assert( uiCode == 0 ); |
---|
1732 | } |
---|
1733 | #endif |
---|
1734 | Void TDecCavlc::parseTerminatingBit( UInt& ruiBit ) |
---|
1735 | { |
---|
1736 | ruiBit = false; |
---|
1737 | Int iBitsLeft = m_pcBitstream->getNumBitsLeft(); |
---|
1738 | if(iBitsLeft <= 8) |
---|
1739 | { |
---|
1740 | UInt uiPeekValue = m_pcBitstream->peekBits(iBitsLeft); |
---|
1741 | if (uiPeekValue == (1<<(iBitsLeft-1))) |
---|
1742 | { |
---|
1743 | ruiBit = true; |
---|
1744 | } |
---|
1745 | } |
---|
1746 | } |
---|
1747 | |
---|
1748 | Void TDecCavlc::parseSkipFlag( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth ) |
---|
1749 | { |
---|
1750 | assert(0); |
---|
1751 | } |
---|
1752 | |
---|
1753 | Void TDecCavlc::parseCUTransquantBypassFlag( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth ) |
---|
1754 | { |
---|
1755 | assert(0); |
---|
1756 | } |
---|
1757 | |
---|
1758 | #if INTRA_BL |
---|
1759 | Void TDecCavlc::parseIntraBLFlag ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiPartIdx, UInt uiDepth ) |
---|
1760 | { |
---|
1761 | assert(0); |
---|
1762 | } |
---|
1763 | #endif |
---|
1764 | |
---|
1765 | Void TDecCavlc::parseMVPIdx( Int& riMVPIdx ) |
---|
1766 | { |
---|
1767 | assert(0); |
---|
1768 | } |
---|
1769 | |
---|
1770 | Void TDecCavlc::parseSplitFlag ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth ) |
---|
1771 | { |
---|
1772 | assert(0); |
---|
1773 | } |
---|
1774 | |
---|
1775 | Void TDecCavlc::parsePartSize( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth ) |
---|
1776 | { |
---|
1777 | assert(0); |
---|
1778 | } |
---|
1779 | |
---|
1780 | Void TDecCavlc::parsePredMode( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth ) |
---|
1781 | { |
---|
1782 | assert(0); |
---|
1783 | } |
---|
1784 | |
---|
1785 | /** Parse I_PCM information. |
---|
1786 | * \param pcCU pointer to CU |
---|
1787 | * \param uiAbsPartIdx CU index |
---|
1788 | * \param uiDepth CU depth |
---|
1789 | * \returns Void |
---|
1790 | * |
---|
1791 | * If I_PCM flag indicates that the CU is I_PCM, parse its PCM alignment bits and codes. |
---|
1792 | */ |
---|
1793 | Void TDecCavlc::parseIPCMInfo( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth ) |
---|
1794 | { |
---|
1795 | assert(0); |
---|
1796 | } |
---|
1797 | |
---|
1798 | Void TDecCavlc::parseIntraDirLumaAng ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth ) |
---|
1799 | { |
---|
1800 | assert(0); |
---|
1801 | } |
---|
1802 | |
---|
1803 | Void TDecCavlc::parseIntraDirChroma( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth ) |
---|
1804 | { |
---|
1805 | assert(0); |
---|
1806 | } |
---|
1807 | |
---|
1808 | Void TDecCavlc::parseInterDir( TComDataCU* pcCU, UInt& ruiInterDir, UInt uiAbsPartIdx, UInt uiDepth ) |
---|
1809 | { |
---|
1810 | assert(0); |
---|
1811 | } |
---|
1812 | |
---|
1813 | Void TDecCavlc::parseRefFrmIdx( TComDataCU* pcCU, Int& riRefFrmIdx, UInt uiAbsPartIdx, UInt uiDepth, RefPicList eRefList ) |
---|
1814 | { |
---|
1815 | assert(0); |
---|
1816 | } |
---|
1817 | |
---|
1818 | Void TDecCavlc::parseMvd( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiPartIdx, UInt uiDepth, RefPicList eRefList ) |
---|
1819 | { |
---|
1820 | assert(0); |
---|
1821 | } |
---|
1822 | |
---|
1823 | Void TDecCavlc::parseDeltaQP( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth ) |
---|
1824 | { |
---|
1825 | Int qp; |
---|
1826 | Int iDQp; |
---|
1827 | |
---|
1828 | xReadSvlc( iDQp ); |
---|
1829 | |
---|
1830 | Int qpBdOffsetY = pcCU->getSlice()->getSPS()->getQpBDOffsetY(); |
---|
1831 | qp = (((Int) pcCU->getRefQP( uiAbsPartIdx ) + iDQp + 52 + 2*qpBdOffsetY )%(52+ qpBdOffsetY)) - qpBdOffsetY; |
---|
1832 | |
---|
1833 | UInt uiAbsQpCUPartIdx = (uiAbsPartIdx>>((g_uiMaxCUDepth - pcCU->getSlice()->getPPS()->getMaxCuDQPDepth())<<1))<<((g_uiMaxCUDepth - pcCU->getSlice()->getPPS()->getMaxCuDQPDepth())<<1) ; |
---|
1834 | UInt uiQpCUDepth = min(uiDepth,pcCU->getSlice()->getPPS()->getMaxCuDQPDepth()) ; |
---|
1835 | |
---|
1836 | pcCU->setQPSubParts( qp, uiAbsQpCUPartIdx, uiQpCUDepth ); |
---|
1837 | } |
---|
1838 | |
---|
1839 | Void TDecCavlc::parseCoeffNxN( TComDataCU* pcCU, TCoeff* pcCoef, UInt uiAbsPartIdx, UInt uiWidth, UInt uiHeight, UInt uiDepth, TextType eTType ) |
---|
1840 | { |
---|
1841 | assert(0); |
---|
1842 | } |
---|
1843 | |
---|
1844 | Void TDecCavlc::parseTransformSubdivFlag( UInt& ruiSubdivFlag, UInt uiLog2TransformBlockSize ) |
---|
1845 | { |
---|
1846 | assert(0); |
---|
1847 | } |
---|
1848 | |
---|
1849 | Void TDecCavlc::parseQtCbf( TComDataCU* pcCU, UInt uiAbsPartIdx, TextType eType, UInt uiTrDepth, UInt uiDepth ) |
---|
1850 | { |
---|
1851 | assert(0); |
---|
1852 | } |
---|
1853 | |
---|
1854 | Void TDecCavlc::parseQtRootCbf( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, UInt& uiQtRootCbf ) |
---|
1855 | { |
---|
1856 | assert(0); |
---|
1857 | } |
---|
1858 | |
---|
1859 | Void TDecCavlc::parseTransformSkipFlags (TComDataCU* pcCU, UInt uiAbsPartIdx, UInt width, UInt height, UInt uiDepth, TextType eTType) |
---|
1860 | { |
---|
1861 | assert(0); |
---|
1862 | } |
---|
1863 | |
---|
1864 | Void TDecCavlc::parseMergeFlag ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, UInt uiPUIdx ) |
---|
1865 | { |
---|
1866 | assert(0); |
---|
1867 | } |
---|
1868 | |
---|
1869 | Void TDecCavlc::parseMergeIndex ( TComDataCU* pcCU, UInt& ruiMergeIndex, UInt uiAbsPartIdx, UInt uiDepth ) |
---|
1870 | { |
---|
1871 | assert(0); |
---|
1872 | } |
---|
1873 | |
---|
1874 | // ==================================================================================================================== |
---|
1875 | // Protected member functions |
---|
1876 | // ==================================================================================================================== |
---|
1877 | |
---|
1878 | |
---|
1879 | /** Parse PCM alignment zero bits. |
---|
1880 | * \returns Void |
---|
1881 | */ |
---|
1882 | Void TDecCavlc::xReadPCMAlignZero( ) |
---|
1883 | { |
---|
1884 | UInt uiNumberOfBits = m_pcBitstream->getNumBitsUntilByteAligned(); |
---|
1885 | |
---|
1886 | if(uiNumberOfBits) |
---|
1887 | { |
---|
1888 | UInt uiBits; |
---|
1889 | UInt uiSymbol; |
---|
1890 | |
---|
1891 | for(uiBits = 0; uiBits < uiNumberOfBits; uiBits++) |
---|
1892 | { |
---|
1893 | xReadFlag( uiSymbol ); |
---|
1894 | |
---|
1895 | if(uiSymbol) |
---|
1896 | { |
---|
1897 | printf("\nWarning! pcm_align_zero include a non-zero value.\n"); |
---|
1898 | } |
---|
1899 | } |
---|
1900 | } |
---|
1901 | } |
---|
1902 | |
---|
1903 | Void TDecCavlc::xReadUnaryMaxSymbol( UInt& ruiSymbol, UInt uiMaxSymbol ) |
---|
1904 | { |
---|
1905 | if (uiMaxSymbol == 0) |
---|
1906 | { |
---|
1907 | ruiSymbol = 0; |
---|
1908 | return; |
---|
1909 | } |
---|
1910 | |
---|
1911 | xReadFlag( ruiSymbol ); |
---|
1912 | |
---|
1913 | if (ruiSymbol == 0 || uiMaxSymbol == 1) |
---|
1914 | { |
---|
1915 | return; |
---|
1916 | } |
---|
1917 | |
---|
1918 | UInt uiSymbol = 0; |
---|
1919 | UInt uiCont; |
---|
1920 | |
---|
1921 | do |
---|
1922 | { |
---|
1923 | xReadFlag( uiCont ); |
---|
1924 | uiSymbol++; |
---|
1925 | } |
---|
1926 | while( uiCont && (uiSymbol < uiMaxSymbol-1) ); |
---|
1927 | |
---|
1928 | if( uiCont && (uiSymbol == uiMaxSymbol-1) ) |
---|
1929 | { |
---|
1930 | uiSymbol++; |
---|
1931 | } |
---|
1932 | |
---|
1933 | ruiSymbol = uiSymbol; |
---|
1934 | } |
---|
1935 | |
---|
1936 | Void TDecCavlc::xReadExGolombLevel( UInt& ruiSymbol ) |
---|
1937 | { |
---|
1938 | UInt uiSymbol ; |
---|
1939 | UInt uiCount = 0; |
---|
1940 | do |
---|
1941 | { |
---|
1942 | xReadFlag( uiSymbol ); |
---|
1943 | uiCount++; |
---|
1944 | } |
---|
1945 | while( uiSymbol && (uiCount != 13)); |
---|
1946 | |
---|
1947 | ruiSymbol = uiCount-1; |
---|
1948 | |
---|
1949 | if( uiSymbol ) |
---|
1950 | { |
---|
1951 | xReadEpExGolomb( uiSymbol, 0 ); |
---|
1952 | ruiSymbol += uiSymbol+1; |
---|
1953 | } |
---|
1954 | |
---|
1955 | return; |
---|
1956 | } |
---|
1957 | |
---|
1958 | Void TDecCavlc::xReadEpExGolomb( UInt& ruiSymbol, UInt uiCount ) |
---|
1959 | { |
---|
1960 | UInt uiSymbol = 0; |
---|
1961 | UInt uiBit = 1; |
---|
1962 | |
---|
1963 | |
---|
1964 | while( uiBit ) |
---|
1965 | { |
---|
1966 | xReadFlag( uiBit ); |
---|
1967 | uiSymbol += uiBit << uiCount++; |
---|
1968 | } |
---|
1969 | |
---|
1970 | uiCount--; |
---|
1971 | while( uiCount-- ) |
---|
1972 | { |
---|
1973 | xReadFlag( uiBit ); |
---|
1974 | uiSymbol += uiBit << uiCount; |
---|
1975 | } |
---|
1976 | |
---|
1977 | ruiSymbol = uiSymbol; |
---|
1978 | |
---|
1979 | return; |
---|
1980 | } |
---|
1981 | |
---|
1982 | UInt TDecCavlc::xGetBit() |
---|
1983 | { |
---|
1984 | UInt ruiCode; |
---|
1985 | m_pcBitstream->read( 1, ruiCode ); |
---|
1986 | return ruiCode; |
---|
1987 | } |
---|
1988 | |
---|
1989 | |
---|
1990 | /** parse explicit wp tables |
---|
1991 | * \param TComSlice* pcSlice |
---|
1992 | * \returns Void |
---|
1993 | */ |
---|
1994 | Void TDecCavlc::xParsePredWeightTable( TComSlice* pcSlice ) |
---|
1995 | { |
---|
1996 | wpScalingParam *wp; |
---|
1997 | Bool bChroma = true; // color always present in HEVC ? |
---|
1998 | TComPPS* pps = pcSlice->getPPS(); |
---|
1999 | SliceType eSliceType = pcSlice->getSliceType(); |
---|
2000 | Int iNbRef = (eSliceType == B_SLICE ) ? (2) : (1); |
---|
2001 | UInt uiLog2WeightDenomLuma, uiLog2WeightDenomChroma; |
---|
2002 | UInt uiMode = 0; |
---|
2003 | #if NUM_WP_LIMIT |
---|
2004 | UInt uiTotalSignalledWeightFlags = 0; |
---|
2005 | #endif |
---|
2006 | if ( (eSliceType==P_SLICE && pps->getUseWP()) || (eSliceType==B_SLICE && pps->getWPBiPred()) ) |
---|
2007 | { |
---|
2008 | uiMode = 1; // explicit |
---|
2009 | } |
---|
2010 | if ( uiMode == 1 ) // explicit |
---|
2011 | { |
---|
2012 | printf("\nTDecCavlc::xParsePredWeightTable(poc=%d) explicit...\n", pcSlice->getPOC()); |
---|
2013 | Int iDeltaDenom; |
---|
2014 | // decode delta_luma_log2_weight_denom : |
---|
2015 | READ_UVLC( uiLog2WeightDenomLuma, "luma_log2_weight_denom" ); // ue(v): luma_log2_weight_denom |
---|
2016 | if( bChroma ) |
---|
2017 | { |
---|
2018 | READ_SVLC( iDeltaDenom, "delta_chroma_log2_weight_denom" ); // se(v): delta_chroma_log2_weight_denom |
---|
2019 | assert((iDeltaDenom + (Int)uiLog2WeightDenomLuma)>=0); |
---|
2020 | uiLog2WeightDenomChroma = (UInt)(iDeltaDenom + uiLog2WeightDenomLuma); |
---|
2021 | } |
---|
2022 | |
---|
2023 | for ( Int iNumRef=0 ; iNumRef<iNbRef ; iNumRef++ ) |
---|
2024 | { |
---|
2025 | RefPicList eRefPicList = ( iNumRef ? REF_PIC_LIST_1 : REF_PIC_LIST_0 ); |
---|
2026 | for ( Int iRefIdx=0 ; iRefIdx<pcSlice->getNumRefIdx(eRefPicList) ; iRefIdx++ ) |
---|
2027 | { |
---|
2028 | pcSlice->getWpScaling(eRefPicList, iRefIdx, wp); |
---|
2029 | |
---|
2030 | wp[0].uiLog2WeightDenom = uiLog2WeightDenomLuma; |
---|
2031 | wp[1].uiLog2WeightDenom = uiLog2WeightDenomChroma; |
---|
2032 | wp[2].uiLog2WeightDenom = uiLog2WeightDenomChroma; |
---|
2033 | |
---|
2034 | UInt uiCode; |
---|
2035 | READ_FLAG( uiCode, "luma_weight_lX_flag" ); // u(1): luma_weight_l0_flag |
---|
2036 | wp[0].bPresentFlag = ( uiCode == 1 ); |
---|
2037 | #if NUM_WP_LIMIT |
---|
2038 | uiTotalSignalledWeightFlags += wp[0].bPresentFlag; |
---|
2039 | } |
---|
2040 | if ( bChroma ) |
---|
2041 | { |
---|
2042 | UInt uiCode; |
---|
2043 | for ( Int iRefIdx=0 ; iRefIdx<pcSlice->getNumRefIdx(eRefPicList) ; iRefIdx++ ) |
---|
2044 | { |
---|
2045 | pcSlice->getWpScaling(eRefPicList, iRefIdx, wp); |
---|
2046 | READ_FLAG( uiCode, "chroma_weight_lX_flag" ); // u(1): chroma_weight_l0_flag |
---|
2047 | wp[1].bPresentFlag = ( uiCode == 1 ); |
---|
2048 | wp[2].bPresentFlag = ( uiCode == 1 ); |
---|
2049 | uiTotalSignalledWeightFlags += 2*wp[1].bPresentFlag; |
---|
2050 | } |
---|
2051 | } |
---|
2052 | for ( Int iRefIdx=0 ; iRefIdx<pcSlice->getNumRefIdx(eRefPicList) ; iRefIdx++ ) |
---|
2053 | { |
---|
2054 | pcSlice->getWpScaling(eRefPicList, iRefIdx, wp); |
---|
2055 | #endif |
---|
2056 | if ( wp[0].bPresentFlag ) |
---|
2057 | { |
---|
2058 | Int iDeltaWeight; |
---|
2059 | READ_SVLC( iDeltaWeight, "delta_luma_weight_lX" ); // se(v): delta_luma_weight_l0[i] |
---|
2060 | wp[0].iWeight = (iDeltaWeight + (1<<wp[0].uiLog2WeightDenom)); |
---|
2061 | READ_SVLC( wp[0].iOffset, "luma_offset_lX" ); // se(v): luma_offset_l0[i] |
---|
2062 | } |
---|
2063 | else |
---|
2064 | { |
---|
2065 | wp[0].iWeight = (1 << wp[0].uiLog2WeightDenom); |
---|
2066 | wp[0].iOffset = 0; |
---|
2067 | } |
---|
2068 | if ( bChroma ) |
---|
2069 | { |
---|
2070 | #if !NUM_WP_LIMIT |
---|
2071 | READ_FLAG( uiCode, "chroma_weight_lX_flag" ); // u(1): chroma_weight_l0_flag |
---|
2072 | wp[1].bPresentFlag = ( uiCode == 1 ); |
---|
2073 | wp[2].bPresentFlag = ( uiCode == 1 ); |
---|
2074 | #endif |
---|
2075 | if ( wp[1].bPresentFlag ) |
---|
2076 | { |
---|
2077 | for ( Int j=1 ; j<3 ; j++ ) |
---|
2078 | { |
---|
2079 | Int iDeltaWeight; |
---|
2080 | READ_SVLC( iDeltaWeight, "delta_chroma_weight_lX" ); // se(v): chroma_weight_l0[i][j] |
---|
2081 | wp[j].iWeight = (iDeltaWeight + (1<<wp[1].uiLog2WeightDenom)); |
---|
2082 | |
---|
2083 | Int iDeltaChroma; |
---|
2084 | READ_SVLC( iDeltaChroma, "delta_chroma_offset_lX" ); // se(v): delta_chroma_offset_l0[i][j] |
---|
2085 | Int shift = ((1<<(g_uiBitDepth+g_uiBitIncrement-1))); |
---|
2086 | Int pred = ( shift - ( ( shift*wp[j].iWeight)>>(wp[j].uiLog2WeightDenom) ) ); |
---|
2087 | #if WP_PARAM_RANGE_LIMIT |
---|
2088 | wp[j].iOffset = Clip3(-128, 127, (iDeltaChroma + pred) ); |
---|
2089 | #else |
---|
2090 | wp[j].iOffset = iDeltaChroma + pred; |
---|
2091 | #endif |
---|
2092 | } |
---|
2093 | } |
---|
2094 | else |
---|
2095 | { |
---|
2096 | for ( Int j=1 ; j<3 ; j++ ) |
---|
2097 | { |
---|
2098 | wp[j].iWeight = (1 << wp[j].uiLog2WeightDenom); |
---|
2099 | wp[j].iOffset = 0; |
---|
2100 | } |
---|
2101 | } |
---|
2102 | } |
---|
2103 | } |
---|
2104 | |
---|
2105 | for ( Int iRefIdx=pcSlice->getNumRefIdx(eRefPicList) ; iRefIdx<MAX_NUM_REF ; iRefIdx++ ) |
---|
2106 | { |
---|
2107 | pcSlice->getWpScaling(eRefPicList, iRefIdx, wp); |
---|
2108 | |
---|
2109 | wp[0].bPresentFlag = false; |
---|
2110 | wp[1].bPresentFlag = false; |
---|
2111 | wp[2].bPresentFlag = false; |
---|
2112 | } |
---|
2113 | } |
---|
2114 | #if NUM_WP_LIMIT |
---|
2115 | assert(uiTotalSignalledWeightFlags<=24); |
---|
2116 | #endif |
---|
2117 | } |
---|
2118 | else |
---|
2119 | { |
---|
2120 | printf("\n wrong weight pred table syntax \n "); |
---|
2121 | assert(0); |
---|
2122 | } |
---|
2123 | } |
---|
2124 | |
---|
2125 | /** decode quantization matrix |
---|
2126 | * \param scalingList quantization matrix information |
---|
2127 | */ |
---|
2128 | Void TDecCavlc::parseScalingList(TComScalingList* scalingList) |
---|
2129 | { |
---|
2130 | UInt code, sizeId, listId; |
---|
2131 | Bool scalingListPredModeFlag; |
---|
2132 | //for each size |
---|
2133 | for(sizeId = 0; sizeId < SCALING_LIST_SIZE_NUM; sizeId++) |
---|
2134 | { |
---|
2135 | for(listId = 0; listId < g_scalingListNum[sizeId]; listId++) |
---|
2136 | { |
---|
2137 | READ_FLAG( code, "scaling_list_pred_mode_flag"); |
---|
2138 | scalingListPredModeFlag = (code) ? true : false; |
---|
2139 | if(!scalingListPredModeFlag) //Copy Mode |
---|
2140 | { |
---|
2141 | READ_UVLC( code, "scaling_list_pred_matrix_id_delta"); |
---|
2142 | scalingList->setRefMatrixId (sizeId,listId,(UInt)((Int)(listId)-(code))); |
---|
2143 | if( sizeId > SCALING_LIST_8x8 ) |
---|
2144 | { |
---|
2145 | scalingList->setScalingListDC(sizeId,listId,((listId == scalingList->getRefMatrixId (sizeId,listId))? 16 :scalingList->getScalingListDC(sizeId, scalingList->getRefMatrixId (sizeId,listId)))); |
---|
2146 | } |
---|
2147 | scalingList->processRefMatrix( sizeId, listId, scalingList->getRefMatrixId (sizeId,listId)); |
---|
2148 | |
---|
2149 | } |
---|
2150 | else //DPCM Mode |
---|
2151 | { |
---|
2152 | xDecodeScalingList(scalingList, sizeId, listId); |
---|
2153 | } |
---|
2154 | } |
---|
2155 | } |
---|
2156 | |
---|
2157 | return; |
---|
2158 | } |
---|
2159 | /** decode DPCM |
---|
2160 | * \param scalingList quantization matrix information |
---|
2161 | * \param sizeId size index |
---|
2162 | * \param listId list index |
---|
2163 | */ |
---|
2164 | Void TDecCavlc::xDecodeScalingList(TComScalingList *scalingList, UInt sizeId, UInt listId) |
---|
2165 | { |
---|
2166 | Int i,coefNum = min(MAX_MATRIX_COEF_NUM,(Int)g_scalingListSize[sizeId]); |
---|
2167 | Int data; |
---|
2168 | Int scalingListDcCoefMinus8 = 0; |
---|
2169 | Int nextCoef = SCALING_LIST_START_VALUE; |
---|
2170 | #if REMOVE_ZIGZAG_SCAN |
---|
2171 | UInt* scan = (sizeId == 0) ? g_auiSigLastScan [ SCAN_DIAG ] [ 1 ] : g_sigLastScanCG32x32; |
---|
2172 | #else |
---|
2173 | UInt* scan = g_auiFrameScanXY [ (sizeId == 0)? 1 : 2 ]; |
---|
2174 | #endif |
---|
2175 | Int *dst = scalingList->getScalingListAddress(sizeId, listId); |
---|
2176 | |
---|
2177 | if( sizeId > SCALING_LIST_8x8 ) |
---|
2178 | { |
---|
2179 | READ_SVLC( scalingListDcCoefMinus8, "scaling_list_dc_coef_minus8"); |
---|
2180 | scalingList->setScalingListDC(sizeId,listId,scalingListDcCoefMinus8 + 8); |
---|
2181 | nextCoef = scalingList->getScalingListDC(sizeId,listId); |
---|
2182 | } |
---|
2183 | |
---|
2184 | for(i = 0; i < coefNum; i++) |
---|
2185 | { |
---|
2186 | READ_SVLC( data, "scaling_list_delta_coef"); |
---|
2187 | nextCoef = (nextCoef + data + 256 ) % 256; |
---|
2188 | dst[scan[i]] = nextCoef; |
---|
2189 | } |
---|
2190 | } |
---|
2191 | |
---|
2192 | Bool TDecCavlc::xMoreRbspData() |
---|
2193 | { |
---|
2194 | Int bitsLeft = m_pcBitstream->getNumBitsLeft(); |
---|
2195 | |
---|
2196 | // if there are more than 8 bits, it cannot be rbsp_trailing_bits |
---|
2197 | if (bitsLeft > 8) |
---|
2198 | { |
---|
2199 | return true; |
---|
2200 | } |
---|
2201 | |
---|
2202 | UChar lastByte = m_pcBitstream->peekBits(bitsLeft); |
---|
2203 | Int cnt = bitsLeft; |
---|
2204 | |
---|
2205 | // remove trailing bits equal to zero |
---|
2206 | while ((cnt>0) && ((lastByte & 1) == 0)) |
---|
2207 | { |
---|
2208 | lastByte >>= 1; |
---|
2209 | cnt--; |
---|
2210 | } |
---|
2211 | // remove bit equal to one |
---|
2212 | cnt--; |
---|
2213 | |
---|
2214 | // we should not have a negative number of bits |
---|
2215 | assert (cnt>=0); |
---|
2216 | |
---|
2217 | // we have more data, if cnt is not zero |
---|
2218 | return (cnt>0); |
---|
2219 | } |
---|
2220 | |
---|
2221 | //! \} |
---|
2222 | |
---|