1 | /* The copyright in this software is being made available under the BSD |
---|
2 | * License, included below. This software may be subject to other third party |
---|
3 | * and contributor rights, including patent rights, and no such rights are |
---|
4 | * granted under this license. |
---|
5 | * |
---|
6 | * Copyright (c) 2010-2013, ITU/ISO/IEC |
---|
7 | * All rights reserved. |
---|
8 | * |
---|
9 | * Redistribution and use in source and binary forms, with or without |
---|
10 | * modification, are permitted provided that the following conditions are met: |
---|
11 | * |
---|
12 | * * Redistributions of source code must retain the above copyright notice, |
---|
13 | * this list of conditions and the following disclaimer. |
---|
14 | * * Redistributions in binary form must reproduce the above copyright notice, |
---|
15 | * this list of conditions and the following disclaimer in the documentation |
---|
16 | * and/or other materials provided with the distribution. |
---|
17 | * * Neither the name of the ITU/ISO/IEC nor the names of its contributors may |
---|
18 | * be used to endorse or promote products derived from this software without |
---|
19 | * specific prior written permission. |
---|
20 | * |
---|
21 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
---|
22 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
---|
23 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
---|
24 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS |
---|
25 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
---|
26 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
---|
27 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
---|
28 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
---|
29 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
---|
30 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF |
---|
31 | * THE POSSIBILITY OF SUCH DAMAGE. |
---|
32 | */ |
---|
33 | |
---|
34 | /** \file TComSlice.cpp |
---|
35 | \brief slice header and SPS class |
---|
36 | */ |
---|
37 | |
---|
38 | #include "CommonDef.h" |
---|
39 | #include "TComSlice.h" |
---|
40 | #include "TComPic.h" |
---|
41 | #include "TLibEncoder/TEncSbac.h" |
---|
42 | #include "TLibDecoder/TDecSbac.h" |
---|
43 | |
---|
44 | //! \ingroup TLibCommon |
---|
45 | //! \{ |
---|
46 | |
---|
47 | TComSlice::TComSlice() |
---|
48 | : m_iPPSId ( -1 ) |
---|
49 | , m_iPOC ( 0 ) |
---|
50 | , m_iLastIDR ( 0 ) |
---|
51 | , m_eNalUnitType ( NAL_UNIT_CODED_SLICE_IDR_W_RADL ) |
---|
52 | , m_eSliceType ( I_SLICE ) |
---|
53 | , m_iSliceQp ( 0 ) |
---|
54 | , m_dependentSliceSegmentFlag ( false ) |
---|
55 | #if ADAPTIVE_QP_SELECTION |
---|
56 | , m_iSliceQpBase ( 0 ) |
---|
57 | #endif |
---|
58 | , m_deblockingFilterDisable ( false ) |
---|
59 | , m_deblockingFilterOverrideFlag ( false ) |
---|
60 | , m_deblockingFilterBetaOffsetDiv2 ( 0 ) |
---|
61 | , m_deblockingFilterTcOffsetDiv2 ( 0 ) |
---|
62 | , m_bCheckLDC ( false ) |
---|
63 | , m_iSliceQpDelta ( 0 ) |
---|
64 | , m_iSliceQpDeltaCb ( 0 ) |
---|
65 | , m_iSliceQpDeltaCr ( 0 ) |
---|
66 | , m_iDepth ( 0 ) |
---|
67 | , m_bRefenced ( false ) |
---|
68 | , m_pcSPS ( NULL ) |
---|
69 | , m_pcPPS ( NULL ) |
---|
70 | , m_pcPic ( NULL ) |
---|
71 | , m_colFromL0Flag ( 1 ) |
---|
72 | , m_colRefIdx ( 0 ) |
---|
73 | #if SAO_CHROMA_LAMBDA |
---|
74 | , m_dLambdaLuma( 0.0 ) |
---|
75 | , m_dLambdaChroma( 0.0 ) |
---|
76 | #else |
---|
77 | , m_dLambda ( 0.0 ) |
---|
78 | #endif |
---|
79 | , m_uiTLayer ( 0 ) |
---|
80 | , m_bTLayerSwitchingFlag ( false ) |
---|
81 | , m_sliceMode ( 0 ) |
---|
82 | , m_sliceArgument ( 0 ) |
---|
83 | , m_sliceCurStartCUAddr ( 0 ) |
---|
84 | , m_sliceCurEndCUAddr ( 0 ) |
---|
85 | , m_sliceIdx ( 0 ) |
---|
86 | , m_sliceSegmentMode ( 0 ) |
---|
87 | , m_sliceSegmentArgument ( 0 ) |
---|
88 | , m_sliceSegmentCurStartCUAddr ( 0 ) |
---|
89 | , m_sliceSegmentCurEndCUAddr ( 0 ) |
---|
90 | , m_nextSlice ( false ) |
---|
91 | , m_nextSliceSegment ( false ) |
---|
92 | , m_sliceBits ( 0 ) |
---|
93 | , m_sliceSegmentBits ( 0 ) |
---|
94 | , m_bFinalized ( false ) |
---|
95 | , m_uiTileOffstForMultES ( 0 ) |
---|
96 | , m_puiSubstreamSizes ( NULL ) |
---|
97 | , m_cabacInitFlag ( false ) |
---|
98 | , m_bLMvdL1Zero ( false ) |
---|
99 | , m_numEntryPointOffsets ( 0 ) |
---|
100 | , m_temporalLayerNonReferenceFlag ( false ) |
---|
101 | , m_enableTMVPFlag ( true ) |
---|
102 | #if H_MV |
---|
103 | , m_refPicSetInterLayer0 ( NULL ) |
---|
104 | , m_refPicSetInterLayer1 ( NULL ) |
---|
105 | , m_layerId (0) |
---|
106 | , m_viewId (0) |
---|
107 | , m_viewIndex (0) |
---|
108 | #if H_3D |
---|
109 | , m_isDepth (false) |
---|
110 | #endif |
---|
111 | , m_pocResetFlag (false) |
---|
112 | #if H_MV |
---|
113 | , m_crossLayerBlaFlag (false) |
---|
114 | #endif |
---|
115 | , m_discardableFlag (false) |
---|
116 | , m_interLayerPredEnabledFlag (false) |
---|
117 | , m_numInterLayerRefPicsMinus1 (0) |
---|
118 | #if H_3D_IC |
---|
119 | , m_bApplyIC ( false ) |
---|
120 | , m_icSkipParseFlag ( false ) |
---|
121 | #endif |
---|
122 | #if H_3D |
---|
123 | , m_depthToDisparityB ( NULL ) |
---|
124 | , m_depthToDisparityF ( NULL ) |
---|
125 | #endif |
---|
126 | #endif |
---|
127 | { |
---|
128 | m_aiNumRefIdx[0] = m_aiNumRefIdx[1] = 0; |
---|
129 | |
---|
130 | initEqualRef(); |
---|
131 | |
---|
132 | for ( Int idx = 0; idx < MAX_NUM_REF; idx++ ) |
---|
133 | { |
---|
134 | m_list1IdxToList0Idx[idx] = -1; |
---|
135 | } |
---|
136 | for(Int iNumCount = 0; iNumCount < MAX_NUM_REF; iNumCount++) |
---|
137 | { |
---|
138 | m_apcRefPicList [0][iNumCount] = NULL; |
---|
139 | m_apcRefPicList [1][iNumCount] = NULL; |
---|
140 | m_aiRefPOCList [0][iNumCount] = 0; |
---|
141 | m_aiRefPOCList [1][iNumCount] = 0; |
---|
142 | #if H_MV |
---|
143 | m_aiRefLayerIdList[0][iNumCount] = 0; |
---|
144 | m_aiRefLayerIdList[1][iNumCount] = 0; |
---|
145 | #endif |
---|
146 | } |
---|
147 | resetWpScaling(); |
---|
148 | initWpAcDcParam(); |
---|
149 | m_saoEnabledFlag = false; |
---|
150 | #if H_MV |
---|
151 | for (Int i = 0; i < MAX_NUM_LAYERS; i++ ) |
---|
152 | { |
---|
153 | m_interLayerPredLayerIdc[ i ] = -1; |
---|
154 | } |
---|
155 | #endif |
---|
156 | } |
---|
157 | |
---|
158 | TComSlice::~TComSlice() |
---|
159 | { |
---|
160 | delete[] m_puiSubstreamSizes; |
---|
161 | m_puiSubstreamSizes = NULL; |
---|
162 | #if H_3D |
---|
163 | for( UInt i = 0; i < getViewIndex(); i++ ) |
---|
164 | { |
---|
165 | if ( m_depthToDisparityB && m_depthToDisparityB[ i ] ) |
---|
166 | { |
---|
167 | delete[] m_depthToDisparityB [ i ]; |
---|
168 | } |
---|
169 | |
---|
170 | if ( m_depthToDisparityF && m_depthToDisparityF[ i ] ) |
---|
171 | { |
---|
172 | delete[] m_depthToDisparityF [ i ]; |
---|
173 | } |
---|
174 | } |
---|
175 | |
---|
176 | if ( m_depthToDisparityF ) |
---|
177 | { |
---|
178 | delete[] m_depthToDisparityF; |
---|
179 | } |
---|
180 | |
---|
181 | m_depthToDisparityF = NULL; |
---|
182 | |
---|
183 | if ( m_depthToDisparityB ) |
---|
184 | delete[] m_depthToDisparityB; |
---|
185 | |
---|
186 | m_depthToDisparityB = NULL; |
---|
187 | #endif |
---|
188 | } |
---|
189 | |
---|
190 | |
---|
191 | Void TComSlice::initSlice() |
---|
192 | { |
---|
193 | m_aiNumRefIdx[0] = 0; |
---|
194 | m_aiNumRefIdx[1] = 0; |
---|
195 | |
---|
196 | m_colFromL0Flag = 1; |
---|
197 | |
---|
198 | m_colRefIdx = 0; |
---|
199 | initEqualRef(); |
---|
200 | m_bCheckLDC = false; |
---|
201 | m_iSliceQpDeltaCb = 0; |
---|
202 | m_iSliceQpDeltaCr = 0; |
---|
203 | |
---|
204 | #if H_3D_IV_MERGE |
---|
205 | m_maxNumMergeCand = MRG_MAX_NUM_CANDS_MEM; |
---|
206 | #else |
---|
207 | m_maxNumMergeCand = MRG_MAX_NUM_CANDS; |
---|
208 | #endif |
---|
209 | |
---|
210 | m_bFinalized=false; |
---|
211 | |
---|
212 | m_tileByteLocation.clear(); |
---|
213 | m_cabacInitFlag = false; |
---|
214 | m_numEntryPointOffsets = 0; |
---|
215 | m_enableTMVPFlag = true; |
---|
216 | #if H_3D_TMVP |
---|
217 | m_aiAlterRefIdx[0] = -1; |
---|
218 | m_aiAlterRefIdx[1] = -1; |
---|
219 | #endif |
---|
220 | } |
---|
221 | |
---|
222 | Bool TComSlice::getRapPicFlag() |
---|
223 | { |
---|
224 | return getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_W_RADL |
---|
225 | || getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_N_LP |
---|
226 | || getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_N_LP |
---|
227 | || getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_RADL |
---|
228 | || getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_LP |
---|
229 | || getNalUnitType() == NAL_UNIT_CODED_SLICE_CRA; |
---|
230 | } |
---|
231 | |
---|
232 | /** |
---|
233 | - allocate table to contain substream sizes to be written to the slice header. |
---|
234 | . |
---|
235 | \param uiNumSubstreams Number of substreams -- the allocation will be this value - 1. |
---|
236 | */ |
---|
237 | Void TComSlice::allocSubstreamSizes(UInt uiNumSubstreams) |
---|
238 | { |
---|
239 | delete[] m_puiSubstreamSizes; |
---|
240 | m_puiSubstreamSizes = new UInt[uiNumSubstreams > 0 ? uiNumSubstreams-1 : 0]; |
---|
241 | } |
---|
242 | |
---|
243 | Void TComSlice::sortPicList (TComList<TComPic*>& rcListPic) |
---|
244 | { |
---|
245 | TComPic* pcPicExtract; |
---|
246 | TComPic* pcPicInsert; |
---|
247 | |
---|
248 | TComList<TComPic*>::iterator iterPicExtract; |
---|
249 | TComList<TComPic*>::iterator iterPicExtract_1; |
---|
250 | TComList<TComPic*>::iterator iterPicInsert; |
---|
251 | |
---|
252 | for (Int i = 1; i < (Int)(rcListPic.size()); i++) |
---|
253 | { |
---|
254 | iterPicExtract = rcListPic.begin(); |
---|
255 | for (Int j = 0; j < i; j++) iterPicExtract++; |
---|
256 | pcPicExtract = *(iterPicExtract); |
---|
257 | pcPicExtract->setCurrSliceIdx(0); |
---|
258 | |
---|
259 | iterPicInsert = rcListPic.begin(); |
---|
260 | while (iterPicInsert != iterPicExtract) |
---|
261 | { |
---|
262 | pcPicInsert = *(iterPicInsert); |
---|
263 | pcPicInsert->setCurrSliceIdx(0); |
---|
264 | if (pcPicInsert->getPOC() >= pcPicExtract->getPOC()) |
---|
265 | { |
---|
266 | break; |
---|
267 | } |
---|
268 | |
---|
269 | iterPicInsert++; |
---|
270 | } |
---|
271 | |
---|
272 | iterPicExtract_1 = iterPicExtract; iterPicExtract_1++; |
---|
273 | |
---|
274 | // swap iterPicExtract and iterPicInsert, iterPicExtract = curr. / iterPicInsert = insertion position |
---|
275 | rcListPic.insert (iterPicInsert, iterPicExtract, iterPicExtract_1); |
---|
276 | rcListPic.erase (iterPicExtract); |
---|
277 | } |
---|
278 | } |
---|
279 | |
---|
280 | TComPic* TComSlice::xGetRefPic (TComList<TComPic*>& rcListPic, |
---|
281 | Int poc) |
---|
282 | { |
---|
283 | TComList<TComPic*>::iterator iterPic = rcListPic.begin(); |
---|
284 | TComPic* pcPic = *(iterPic); |
---|
285 | while ( iterPic != rcListPic.end() ) |
---|
286 | { |
---|
287 | if(pcPic->getPOC() == poc) |
---|
288 | { |
---|
289 | break; |
---|
290 | } |
---|
291 | iterPic++; |
---|
292 | pcPic = *(iterPic); |
---|
293 | } |
---|
294 | return pcPic; |
---|
295 | } |
---|
296 | |
---|
297 | |
---|
298 | TComPic* TComSlice::xGetLongTermRefPic(TComList<TComPic*>& rcListPic, Int poc, Bool pocHasMsb) |
---|
299 | { |
---|
300 | TComList<TComPic*>::iterator iterPic = rcListPic.begin(); |
---|
301 | TComPic* pcPic = *(iterPic); |
---|
302 | TComPic* pcStPic = pcPic; |
---|
303 | |
---|
304 | Int pocCycle = 1 << getSPS()->getBitsForPOC(); |
---|
305 | if (!pocHasMsb) |
---|
306 | { |
---|
307 | poc = poc & (pocCycle - 1); |
---|
308 | } |
---|
309 | |
---|
310 | while ( iterPic != rcListPic.end() ) |
---|
311 | { |
---|
312 | pcPic = *(iterPic); |
---|
313 | if (pcPic && pcPic->getPOC()!=this->getPOC() && pcPic->getSlice( 0 )->isReferenced()) |
---|
314 | { |
---|
315 | Int picPoc = pcPic->getPOC(); |
---|
316 | if (!pocHasMsb) |
---|
317 | { |
---|
318 | picPoc = picPoc & (pocCycle - 1); |
---|
319 | } |
---|
320 | |
---|
321 | if (poc == picPoc) |
---|
322 | { |
---|
323 | if(pcPic->getIsLongTerm()) |
---|
324 | { |
---|
325 | return pcPic; |
---|
326 | } |
---|
327 | else |
---|
328 | { |
---|
329 | pcStPic = pcPic; |
---|
330 | } |
---|
331 | break; |
---|
332 | } |
---|
333 | } |
---|
334 | |
---|
335 | iterPic++; |
---|
336 | } |
---|
337 | |
---|
338 | return pcStPic; |
---|
339 | } |
---|
340 | |
---|
341 | Void TComSlice::setRefPOCList () |
---|
342 | { |
---|
343 | for (Int iDir = 0; iDir < 2; iDir++) |
---|
344 | { |
---|
345 | for (Int iNumRefIdx = 0; iNumRefIdx < m_aiNumRefIdx[iDir]; iNumRefIdx++) |
---|
346 | { |
---|
347 | m_aiRefPOCList[iDir][iNumRefIdx] = m_apcRefPicList[iDir][iNumRefIdx]->getPOC(); |
---|
348 | #if H_MV |
---|
349 | m_aiRefLayerIdList[iDir][iNumRefIdx] = m_apcRefPicList[iDir][iNumRefIdx]->getLayerId(); |
---|
350 | #endif |
---|
351 | } |
---|
352 | } |
---|
353 | |
---|
354 | } |
---|
355 | |
---|
356 | Void TComSlice::setList1IdxToList0Idx() |
---|
357 | { |
---|
358 | Int idxL0, idxL1; |
---|
359 | for ( idxL1 = 0; idxL1 < getNumRefIdx( REF_PIC_LIST_1 ); idxL1++ ) |
---|
360 | { |
---|
361 | m_list1IdxToList0Idx[idxL1] = -1; |
---|
362 | for ( idxL0 = 0; idxL0 < getNumRefIdx( REF_PIC_LIST_0 ); idxL0++ ) |
---|
363 | { |
---|
364 | if ( m_apcRefPicList[REF_PIC_LIST_0][idxL0]->getPOC() == m_apcRefPicList[REF_PIC_LIST_1][idxL1]->getPOC() ) |
---|
365 | { |
---|
366 | m_list1IdxToList0Idx[idxL1] = idxL0; |
---|
367 | break; |
---|
368 | } |
---|
369 | } |
---|
370 | } |
---|
371 | } |
---|
372 | #if !H_MV |
---|
373 | #if FIX1071 |
---|
374 | Void TComSlice::setRefPicList( TComList<TComPic*>& rcListPic, Bool checkNumPocTotalCurr ) |
---|
375 | #else |
---|
376 | Void TComSlice::setRefPicList( TComList<TComPic*>& rcListPic ) |
---|
377 | #endif |
---|
378 | { |
---|
379 | #if FIX1071 |
---|
380 | if (!checkNumPocTotalCurr) |
---|
381 | #endif |
---|
382 | { |
---|
383 | if (m_eSliceType == I_SLICE) |
---|
384 | { |
---|
385 | ::memset( m_apcRefPicList, 0, sizeof (m_apcRefPicList)); |
---|
386 | ::memset( m_aiNumRefIdx, 0, sizeof ( m_aiNumRefIdx )); |
---|
387 | |
---|
388 | return; |
---|
389 | } |
---|
390 | |
---|
391 | m_aiNumRefIdx[0] = getNumRefIdx(REF_PIC_LIST_0); |
---|
392 | m_aiNumRefIdx[1] = getNumRefIdx(REF_PIC_LIST_1); |
---|
393 | } |
---|
394 | |
---|
395 | TComPic* pcRefPic= NULL; |
---|
396 | TComPic* RefPicSetStCurr0[16]; |
---|
397 | TComPic* RefPicSetStCurr1[16]; |
---|
398 | TComPic* RefPicSetLtCurr[16]; |
---|
399 | UInt NumPocStCurr0 = 0; |
---|
400 | UInt NumPocStCurr1 = 0; |
---|
401 | UInt NumPocLtCurr = 0; |
---|
402 | Int i; |
---|
403 | |
---|
404 | for(i=0; i < m_pcRPS->getNumberOfNegativePictures(); i++) |
---|
405 | { |
---|
406 | if(m_pcRPS->getUsed(i)) |
---|
407 | { |
---|
408 | pcRefPic = xGetRefPic(rcListPic, getPOC()+m_pcRPS->getDeltaPOC(i)); |
---|
409 | pcRefPic->setIsLongTerm(0); |
---|
410 | pcRefPic->getPicYuvRec()->extendPicBorder(); |
---|
411 | RefPicSetStCurr0[NumPocStCurr0] = pcRefPic; |
---|
412 | NumPocStCurr0++; |
---|
413 | pcRefPic->setCheckLTMSBPresent(false); |
---|
414 | } |
---|
415 | } |
---|
416 | |
---|
417 | for(; i < m_pcRPS->getNumberOfNegativePictures()+m_pcRPS->getNumberOfPositivePictures(); i++) |
---|
418 | { |
---|
419 | if(m_pcRPS->getUsed(i)) |
---|
420 | { |
---|
421 | pcRefPic = xGetRefPic(rcListPic, getPOC()+m_pcRPS->getDeltaPOC(i)); |
---|
422 | pcRefPic->setIsLongTerm(0); |
---|
423 | pcRefPic->getPicYuvRec()->extendPicBorder(); |
---|
424 | RefPicSetStCurr1[NumPocStCurr1] = pcRefPic; |
---|
425 | NumPocStCurr1++; |
---|
426 | pcRefPic->setCheckLTMSBPresent(false); |
---|
427 | } |
---|
428 | } |
---|
429 | |
---|
430 | for(i = m_pcRPS->getNumberOfNegativePictures()+m_pcRPS->getNumberOfPositivePictures()+m_pcRPS->getNumberOfLongtermPictures()-1; i > m_pcRPS->getNumberOfNegativePictures()+m_pcRPS->getNumberOfPositivePictures()-1 ; i--) |
---|
431 | { |
---|
432 | if(m_pcRPS->getUsed(i)) |
---|
433 | { |
---|
434 | pcRefPic = xGetLongTermRefPic(rcListPic, m_pcRPS->getPOC(i), m_pcRPS->getCheckLTMSBPresent(i)); |
---|
435 | pcRefPic->setIsLongTerm(1); |
---|
436 | pcRefPic->getPicYuvRec()->extendPicBorder(); |
---|
437 | RefPicSetLtCurr[NumPocLtCurr] = pcRefPic; |
---|
438 | NumPocLtCurr++; |
---|
439 | } |
---|
440 | if(pcRefPic==NULL) |
---|
441 | { |
---|
442 | pcRefPic = xGetLongTermRefPic(rcListPic, m_pcRPS->getPOC(i), m_pcRPS->getCheckLTMSBPresent(i)); |
---|
443 | } |
---|
444 | pcRefPic->setCheckLTMSBPresent(m_pcRPS->getCheckLTMSBPresent(i)); |
---|
445 | } |
---|
446 | |
---|
447 | // ref_pic_list_init |
---|
448 | TComPic* rpsCurrList0[MAX_NUM_REF+1]; |
---|
449 | TComPic* rpsCurrList1[MAX_NUM_REF+1]; |
---|
450 | Int numPocTotalCurr = NumPocStCurr0 + NumPocStCurr1 + NumPocLtCurr; |
---|
451 | |
---|
452 | #if FIX1071 |
---|
453 | if (checkNumPocTotalCurr) |
---|
454 | { |
---|
455 | // The variable NumPocTotalCurr is derived as specified in subclause 7.4.7.2. It is a requirement of bitstream conformance that the following applies to the value of NumPocTotalCurr: |
---|
456 | // ?If the current picture is a BLA or CRA picture, the value of NumPocTotalCurr shall be equal to 0. |
---|
457 | // ?Otherwise, when the current picture contains a P or B slice, the value of NumPocTotalCurr shall not be equal to 0. |
---|
458 | if (getRapPicFlag()) |
---|
459 | { |
---|
460 | assert(numPocTotalCurr == 0); |
---|
461 | } |
---|
462 | |
---|
463 | if (m_eSliceType == I_SLICE) |
---|
464 | { |
---|
465 | ::memset( m_apcRefPicList, 0, sizeof (m_apcRefPicList)); |
---|
466 | ::memset( m_aiNumRefIdx, 0, sizeof ( m_aiNumRefIdx )); |
---|
467 | |
---|
468 | return; |
---|
469 | } |
---|
470 | |
---|
471 | assert(numPocTotalCurr > 0); |
---|
472 | |
---|
473 | m_aiNumRefIdx[0] = getNumRefIdx(REF_PIC_LIST_0); |
---|
474 | m_aiNumRefIdx[1] = getNumRefIdx(REF_PIC_LIST_1); |
---|
475 | } |
---|
476 | #endif |
---|
477 | |
---|
478 | Int cIdx = 0; |
---|
479 | for ( i=0; i<NumPocStCurr0; i++, cIdx++) |
---|
480 | { |
---|
481 | rpsCurrList0[cIdx] = RefPicSetStCurr0[i]; |
---|
482 | } |
---|
483 | for ( i=0; i<NumPocStCurr1; i++, cIdx++) |
---|
484 | { |
---|
485 | rpsCurrList0[cIdx] = RefPicSetStCurr1[i]; |
---|
486 | } |
---|
487 | for ( i=0; i<NumPocLtCurr; i++, cIdx++) |
---|
488 | { |
---|
489 | rpsCurrList0[cIdx] = RefPicSetLtCurr[i]; |
---|
490 | } |
---|
491 | assert(cIdx == numPocTotalCurr); |
---|
492 | |
---|
493 | if (m_eSliceType==B_SLICE) |
---|
494 | { |
---|
495 | cIdx = 0; |
---|
496 | for ( i=0; i<NumPocStCurr1; i++, cIdx++) |
---|
497 | { |
---|
498 | rpsCurrList1[cIdx] = RefPicSetStCurr1[i]; |
---|
499 | } |
---|
500 | for ( i=0; i<NumPocStCurr0; i++, cIdx++) |
---|
501 | { |
---|
502 | rpsCurrList1[cIdx] = RefPicSetStCurr0[i]; |
---|
503 | } |
---|
504 | for ( i=0; i<NumPocLtCurr; i++, cIdx++) |
---|
505 | { |
---|
506 | rpsCurrList1[cIdx] = RefPicSetLtCurr[i]; |
---|
507 | } |
---|
508 | assert(cIdx == numPocTotalCurr); |
---|
509 | } |
---|
510 | |
---|
511 | ::memset(m_bIsUsedAsLongTerm, 0, sizeof(m_bIsUsedAsLongTerm)); |
---|
512 | |
---|
513 | for (Int rIdx = 0; rIdx < m_aiNumRefIdx[0]; rIdx ++) |
---|
514 | { |
---|
515 | cIdx = m_RefPicListModification.getRefPicListModificationFlagL0() ? m_RefPicListModification.getRefPicSetIdxL0(rIdx) : rIdx % numPocTotalCurr; |
---|
516 | assert(cIdx >= 0 && cIdx < numPocTotalCurr); |
---|
517 | m_apcRefPicList[0][rIdx] = rpsCurrList0[ cIdx ]; |
---|
518 | m_bIsUsedAsLongTerm[0][rIdx] = ( cIdx >= NumPocStCurr0 + NumPocStCurr1 ); |
---|
519 | } |
---|
520 | if ( m_eSliceType != B_SLICE ) |
---|
521 | { |
---|
522 | m_aiNumRefIdx[1] = 0; |
---|
523 | ::memset( m_apcRefPicList[1], 0, sizeof(m_apcRefPicList[1])); |
---|
524 | } |
---|
525 | else |
---|
526 | { |
---|
527 | for (Int rIdx = 0; rIdx < m_aiNumRefIdx[1]; rIdx ++) |
---|
528 | { |
---|
529 | cIdx = m_RefPicListModification.getRefPicListModificationFlagL1() ? m_RefPicListModification.getRefPicSetIdxL1(rIdx) : rIdx % numPocTotalCurr; |
---|
530 | assert(cIdx >= 0 && cIdx < numPocTotalCurr); |
---|
531 | m_apcRefPicList[1][rIdx] = rpsCurrList1[ cIdx ]; |
---|
532 | m_bIsUsedAsLongTerm[1][rIdx] = ( cIdx >= NumPocStCurr0 + NumPocStCurr1 ); |
---|
533 | } |
---|
534 | } |
---|
535 | } |
---|
536 | |
---|
537 | #else |
---|
538 | Void TComSlice::getTempRefPicLists( TComList<TComPic*>& rcListPic, std::vector<TComPic*>& refPicSetInterLayer0, std::vector<TComPic*>& refPicSetInterLayer1, |
---|
539 | std::vector<TComPic*> rpsCurrList[2], std::vector<Bool> usedAsLongTerm[2], Int& numPocTotalCurr, Bool checkNumPocTotalCurr ) |
---|
540 | { |
---|
541 | if (!checkNumPocTotalCurr) |
---|
542 | { |
---|
543 | if (m_eSliceType == I_SLICE) |
---|
544 | { |
---|
545 | return; |
---|
546 | } |
---|
547 | } |
---|
548 | |
---|
549 | TComPic* pcRefPic= NULL; |
---|
550 | TComPic* RefPicSetStCurr0[16]; |
---|
551 | TComPic* RefPicSetStCurr1[16]; |
---|
552 | TComPic* RefPicSetLtCurr[16]; |
---|
553 | UInt NumPocStCurr0 = 0; |
---|
554 | UInt NumPocStCurr1 = 0; |
---|
555 | UInt NumPocLtCurr = 0; |
---|
556 | Int i; |
---|
557 | |
---|
558 | for(i=0; i < m_pcRPS->getNumberOfNegativePictures(); i++) |
---|
559 | { |
---|
560 | if(m_pcRPS->getUsed(i)) |
---|
561 | { |
---|
562 | pcRefPic = xGetRefPic(rcListPic, getPOC()+m_pcRPS->getDeltaPOC(i)); |
---|
563 | pcRefPic->setIsLongTerm(0); |
---|
564 | pcRefPic->getPicYuvRec()->extendPicBorder(); |
---|
565 | RefPicSetStCurr0[NumPocStCurr0] = pcRefPic; |
---|
566 | NumPocStCurr0++; |
---|
567 | pcRefPic->setCheckLTMSBPresent(false); |
---|
568 | } |
---|
569 | } |
---|
570 | |
---|
571 | for(; i < m_pcRPS->getNumberOfNegativePictures()+m_pcRPS->getNumberOfPositivePictures(); i++) |
---|
572 | { |
---|
573 | if(m_pcRPS->getUsed(i)) |
---|
574 | { |
---|
575 | pcRefPic = xGetRefPic(rcListPic, getPOC()+m_pcRPS->getDeltaPOC(i)); |
---|
576 | pcRefPic->setIsLongTerm(0); |
---|
577 | pcRefPic->getPicYuvRec()->extendPicBorder(); |
---|
578 | RefPicSetStCurr1[NumPocStCurr1] = pcRefPic; |
---|
579 | NumPocStCurr1++; |
---|
580 | pcRefPic->setCheckLTMSBPresent(false); |
---|
581 | } |
---|
582 | } |
---|
583 | |
---|
584 | for(i = m_pcRPS->getNumberOfNegativePictures()+m_pcRPS->getNumberOfPositivePictures()+m_pcRPS->getNumberOfLongtermPictures()-1; i > m_pcRPS->getNumberOfNegativePictures()+m_pcRPS->getNumberOfPositivePictures()-1 ; i--) |
---|
585 | { |
---|
586 | if(m_pcRPS->getUsed(i)) |
---|
587 | { |
---|
588 | pcRefPic = xGetLongTermRefPic(rcListPic, m_pcRPS->getPOC(i), m_pcRPS->getCheckLTMSBPresent(i)); |
---|
589 | pcRefPic->setIsLongTerm(1); |
---|
590 | pcRefPic->getPicYuvRec()->extendPicBorder(); |
---|
591 | RefPicSetLtCurr[NumPocLtCurr] = pcRefPic; |
---|
592 | NumPocLtCurr++; |
---|
593 | } |
---|
594 | if(pcRefPic==NULL) |
---|
595 | { |
---|
596 | pcRefPic = xGetLongTermRefPic(rcListPic, m_pcRPS->getPOC(i), m_pcRPS->getCheckLTMSBPresent(i)); |
---|
597 | } |
---|
598 | pcRefPic->setCheckLTMSBPresent(m_pcRPS->getCheckLTMSBPresent(i)); |
---|
599 | } |
---|
600 | |
---|
601 | Int numPocInterCurr = NumPocStCurr0 + NumPocStCurr1 + NumPocLtCurr; |
---|
602 | numPocTotalCurr = numPocInterCurr + getNumActiveRefLayerPics( ); |
---|
603 | assert( numPocTotalCurr == getNumRpsCurrTempList() ); |
---|
604 | |
---|
605 | if (checkNumPocTotalCurr) |
---|
606 | { |
---|
607 | // The variable NumPocTotalCurr is derived as specified in subclause 7.4.7.2. It is a requirement of bitstream conformance that the following applies to the value of NumPocTotalCurr: |
---|
608 | // - If nuh_layer_id is equal to 0 and the current picture is a BLA picture or a CRA picture, the value of NumPocTotalCurr shall be equal to 0. |
---|
609 | // - Otherwise, when the current picture contains a P or B slice, the value of NumPocTotalCurr shall not be equal to 0. |
---|
610 | if ( getRapPicFlag() && m_layerId == 0 ) |
---|
611 | { |
---|
612 | assert(numPocTotalCurr == 0); |
---|
613 | } |
---|
614 | |
---|
615 | if (m_eSliceType == I_SLICE) |
---|
616 | { |
---|
617 | ::memset( m_apcRefPicList, 0, sizeof (m_apcRefPicList)); |
---|
618 | ::memset( m_aiNumRefIdx, 0, sizeof ( m_aiNumRefIdx )); |
---|
619 | |
---|
620 | return; |
---|
621 | } |
---|
622 | |
---|
623 | assert(numPocTotalCurr > 0); |
---|
624 | |
---|
625 | m_aiNumRefIdx[0] = getNumRefIdx(REF_PIC_LIST_0); |
---|
626 | m_aiNumRefIdx[1] = getNumRefIdx(REF_PIC_LIST_1); |
---|
627 | } |
---|
628 | |
---|
629 | std::vector<TComPic*>* refPicSetInterLayer[2] = { &refPicSetInterLayer0, &refPicSetInterLayer1}; |
---|
630 | Int numPocInterLayer[2] = { getNumActiveRefLayerPics0( ), getNumActiveRefLayerPics1( ) }; |
---|
631 | |
---|
632 | TComPic** refPicSetStCurr [2] = { RefPicSetStCurr0, RefPicSetStCurr1 }; |
---|
633 | Int numPocStCurr[2] = { NumPocStCurr0, NumPocStCurr1 }; |
---|
634 | |
---|
635 | for (Int li = 0; li < ((m_eSliceType==B_SLICE) ? 2 : 1); li++) |
---|
636 | { |
---|
637 | rpsCurrList [li].resize(MAX_NUM_REF+1,NULL ); |
---|
638 | usedAsLongTerm[li].resize(MAX_NUM_REF+1,false); |
---|
639 | |
---|
640 | Int cIdx = 0; |
---|
641 | for ( i=0; i < numPocStCurr[li]; i++, cIdx++) |
---|
642 | { |
---|
643 | rpsCurrList[li][cIdx] = refPicSetStCurr[li][i]; |
---|
644 | usedAsLongTerm [li][cIdx] = false; |
---|
645 | } |
---|
646 | |
---|
647 | for ( i=0; i < numPocInterLayer[li]; i++, cIdx++) |
---|
648 | { |
---|
649 | rpsCurrList[li][cIdx] = (*refPicSetInterLayer[li])[i]; |
---|
650 | usedAsLongTerm [li][cIdx] = true; |
---|
651 | } |
---|
652 | |
---|
653 | for ( i=0; i < numPocStCurr[1-li]; i++, cIdx++) |
---|
654 | { |
---|
655 | rpsCurrList[li][cIdx] = refPicSetStCurr[1-li][i]; |
---|
656 | usedAsLongTerm [li][cIdx] = false; |
---|
657 | } |
---|
658 | |
---|
659 | for ( i=0; i<NumPocLtCurr; i++, cIdx++) |
---|
660 | { |
---|
661 | rpsCurrList[li][cIdx] = RefPicSetLtCurr[i]; |
---|
662 | usedAsLongTerm [li][cIdx] = true; |
---|
663 | } |
---|
664 | |
---|
665 | for ( i=0; i < numPocInterLayer[1-li]; i++, cIdx++) |
---|
666 | { |
---|
667 | assert( cIdx < MAX_NUM_REF ); |
---|
668 | rpsCurrList[li][cIdx] = (*refPicSetInterLayer[1-li])[i]; |
---|
669 | usedAsLongTerm [li][cIdx] = true; |
---|
670 | } |
---|
671 | |
---|
672 | assert(cIdx == numPocTotalCurr); |
---|
673 | } |
---|
674 | } |
---|
675 | |
---|
676 | Void TComSlice::setRefPicList( std::vector<TComPic*> rpsCurrList[2], std::vector<Bool> usedAsLongTerm[2], Int numPocTotalCurr, Bool checkNumPocTotalCurr ) |
---|
677 | |
---|
678 | { |
---|
679 | if (!checkNumPocTotalCurr) |
---|
680 | { |
---|
681 | if (m_eSliceType == I_SLICE) |
---|
682 | { |
---|
683 | ::memset( m_apcRefPicList, 0, sizeof (m_apcRefPicList)); |
---|
684 | ::memset( m_aiNumRefIdx, 0, sizeof ( m_aiNumRefIdx )); |
---|
685 | |
---|
686 | return; |
---|
687 | } |
---|
688 | } |
---|
689 | |
---|
690 | ::memset(m_bIsUsedAsLongTerm, 0, sizeof(m_bIsUsedAsLongTerm)); |
---|
691 | |
---|
692 | for (Int li = 0; li < 2; li++) |
---|
693 | { |
---|
694 | if ( m_eSliceType == P_SLICE && li == 1 ) |
---|
695 | { |
---|
696 | m_aiNumRefIdx[1] = 0; |
---|
697 | ::memset( m_apcRefPicList[1], 0, sizeof(m_apcRefPicList[1])); |
---|
698 | } |
---|
699 | else |
---|
700 | { |
---|
701 | for (Int rIdx = 0; rIdx <= (m_aiNumRefIdx[ li ] - 1 ); rIdx ++) |
---|
702 | { |
---|
703 | Bool listModified = m_RefPicListModification.getRefPicListModificationFlagL( li ); |
---|
704 | Int orgIdx = listModified ? m_RefPicListModification.getRefPicSetIdxL(li, rIdx) : (rIdx % numPocTotalCurr); |
---|
705 | |
---|
706 | assert( rpsCurrList[li][ orgIdx ] != NULL ); |
---|
707 | m_apcRefPicList [li][rIdx] = rpsCurrList [li][ orgIdx ]; |
---|
708 | m_bIsUsedAsLongTerm[li][rIdx] = usedAsLongTerm [li][ orgIdx ] ; |
---|
709 | } |
---|
710 | } |
---|
711 | } |
---|
712 | } |
---|
713 | #endif |
---|
714 | Int TComSlice::getNumRpsCurrTempList() |
---|
715 | { |
---|
716 | Int numRpsCurrTempList = 0; |
---|
717 | |
---|
718 | if (m_eSliceType == I_SLICE) |
---|
719 | { |
---|
720 | return 0; |
---|
721 | } |
---|
722 | for(UInt i=0; i < m_pcRPS->getNumberOfNegativePictures()+ m_pcRPS->getNumberOfPositivePictures() + m_pcRPS->getNumberOfLongtermPictures(); i++) |
---|
723 | { |
---|
724 | if(m_pcRPS->getUsed(i)) |
---|
725 | { |
---|
726 | numRpsCurrTempList++; |
---|
727 | } |
---|
728 | } |
---|
729 | #if H_MV |
---|
730 | numRpsCurrTempList = numRpsCurrTempList + getNumActiveRefLayerPics(); |
---|
731 | #endif |
---|
732 | return numRpsCurrTempList; |
---|
733 | } |
---|
734 | |
---|
735 | Void TComSlice::initEqualRef() |
---|
736 | { |
---|
737 | for (Int iDir = 0; iDir < 2; iDir++) |
---|
738 | { |
---|
739 | for (Int iRefIdx1 = 0; iRefIdx1 < MAX_NUM_REF; iRefIdx1++) |
---|
740 | { |
---|
741 | for (Int iRefIdx2 = iRefIdx1; iRefIdx2 < MAX_NUM_REF; iRefIdx2++) |
---|
742 | { |
---|
743 | m_abEqualRef[iDir][iRefIdx1][iRefIdx2] = m_abEqualRef[iDir][iRefIdx2][iRefIdx1] = (iRefIdx1 == iRefIdx2? true : false); |
---|
744 | } |
---|
745 | } |
---|
746 | } |
---|
747 | } |
---|
748 | #if H_3D |
---|
749 | #if H_3D_TMVP |
---|
750 | Void TComSlice::generateAlterRefforTMVP() |
---|
751 | { |
---|
752 | for ( UInt uiRefListIdx = 0; uiRefListIdx < 2; uiRefListIdx++ ) |
---|
753 | { |
---|
754 | if ( this->getNumRefIdx( RefPicList( uiRefListIdx ) ) == 0) |
---|
755 | { |
---|
756 | continue; |
---|
757 | } |
---|
758 | Bool bZeroIdxLtFlag = this->getRefPic(RefPicList(uiRefListIdx), 0)->getIsLongTerm(); |
---|
759 | for(Int i = 1; i < this->getNumRefIdx(RefPicList(uiRefListIdx)); i++ ) |
---|
760 | { |
---|
761 | if ( ( bZeroIdxLtFlag && !this->getRefPic(RefPicList(uiRefListIdx), i)->getIsLongTerm() ) || |
---|
762 | (!bZeroIdxLtFlag && this->getRefPic(RefPicList(uiRefListIdx), i)->getIsLongTerm() ) ) |
---|
763 | { |
---|
764 | this->setAlterRefIdx(RefPicList(uiRefListIdx),i); |
---|
765 | break; |
---|
766 | } |
---|
767 | } |
---|
768 | } |
---|
769 | } |
---|
770 | #endif |
---|
771 | Void TComSlice::setCamparaSlice( Int** aaiScale, Int** aaiOffset ) |
---|
772 | { |
---|
773 | if( m_pcVPS->hasCamParInSliceHeader( m_viewIndex ) ) |
---|
774 | { |
---|
775 | for( UInt uiBaseViewIndex = 0; uiBaseViewIndex < m_viewIndex; uiBaseViewIndex++ ) |
---|
776 | { |
---|
777 | m_aaiCodedScale [ 0 ][ uiBaseViewIndex ] = aaiScale [ uiBaseViewIndex ][ m_viewIndex ]; |
---|
778 | m_aaiCodedScale [ 1 ][ uiBaseViewIndex ] = aaiScale [ m_viewIndex ][ uiBaseViewIndex ]; |
---|
779 | m_aaiCodedOffset[ 0 ][ uiBaseViewIndex ] = aaiOffset[ uiBaseViewIndex ][ m_viewIndex ]; |
---|
780 | m_aaiCodedOffset[ 1 ][ uiBaseViewIndex ] = aaiOffset[ m_viewIndex ][ uiBaseViewIndex ]; |
---|
781 | } |
---|
782 | } |
---|
783 | } |
---|
784 | #endif |
---|
785 | |
---|
786 | Void TComSlice::checkColRefIdx(UInt curSliceIdx, TComPic* pic) |
---|
787 | { |
---|
788 | Int i; |
---|
789 | TComSlice* curSlice = pic->getSlice(curSliceIdx); |
---|
790 | Int currColRefPOC = curSlice->getRefPOC( RefPicList(1-curSlice->getColFromL0Flag()), curSlice->getColRefIdx()); |
---|
791 | TComSlice* preSlice; |
---|
792 | Int preColRefPOC; |
---|
793 | for(i=curSliceIdx-1; i>=0; i--) |
---|
794 | { |
---|
795 | preSlice = pic->getSlice(i); |
---|
796 | if(preSlice->getSliceType() != I_SLICE) |
---|
797 | { |
---|
798 | preColRefPOC = preSlice->getRefPOC( RefPicList(1-preSlice->getColFromL0Flag()), preSlice->getColRefIdx()); |
---|
799 | if(currColRefPOC != preColRefPOC) |
---|
800 | { |
---|
801 | printf("Collocated_ref_idx shall always be the same for all slices of a coded picture!\n"); |
---|
802 | exit(EXIT_FAILURE); |
---|
803 | } |
---|
804 | else |
---|
805 | { |
---|
806 | break; |
---|
807 | } |
---|
808 | } |
---|
809 | } |
---|
810 | } |
---|
811 | |
---|
812 | Void TComSlice::checkCRA(TComReferencePictureSet *pReferencePictureSet, Int& pocCRA, NalUnitType& associatedIRAPType, TComList<TComPic *>& rcListPic) |
---|
813 | { |
---|
814 | for(Int i = 0; i < pReferencePictureSet->getNumberOfNegativePictures()+pReferencePictureSet->getNumberOfPositivePictures(); i++) |
---|
815 | { |
---|
816 | if(pocCRA < MAX_UINT && getPOC() > pocCRA) |
---|
817 | { |
---|
818 | assert(getPOC()+pReferencePictureSet->getDeltaPOC(i) >= pocCRA); |
---|
819 | } |
---|
820 | } |
---|
821 | for(Int i = pReferencePictureSet->getNumberOfNegativePictures()+pReferencePictureSet->getNumberOfPositivePictures(); i < pReferencePictureSet->getNumberOfPictures(); i++) |
---|
822 | { |
---|
823 | if(pocCRA < MAX_UINT && getPOC() > pocCRA) |
---|
824 | { |
---|
825 | if (!pReferencePictureSet->getCheckLTMSBPresent(i)) |
---|
826 | { |
---|
827 | assert(xGetLongTermRefPic(rcListPic, pReferencePictureSet->getPOC(i), false)->getPOC() >= pocCRA); |
---|
828 | } |
---|
829 | else |
---|
830 | { |
---|
831 | assert(pReferencePictureSet->getPOC(i) >= pocCRA); |
---|
832 | } |
---|
833 | } |
---|
834 | } |
---|
835 | if ( getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_W_RADL || getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_N_LP ) // IDR picture found |
---|
836 | { |
---|
837 | pocCRA = getPOC(); |
---|
838 | associatedIRAPType = getNalUnitType(); |
---|
839 | } |
---|
840 | else if ( getNalUnitType() == NAL_UNIT_CODED_SLICE_CRA ) // CRA picture found |
---|
841 | { |
---|
842 | pocCRA = getPOC(); |
---|
843 | associatedIRAPType = getNalUnitType(); |
---|
844 | } |
---|
845 | else if ( getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_LP |
---|
846 | || getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_RADL |
---|
847 | || getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_N_LP ) // BLA picture found |
---|
848 | { |
---|
849 | pocCRA = getPOC(); |
---|
850 | associatedIRAPType = getNalUnitType(); |
---|
851 | } |
---|
852 | } |
---|
853 | |
---|
854 | /** Function for marking the reference pictures when an IDR/CRA/CRANT/BLA/BLANT is encountered. |
---|
855 | * \param pocCRA POC of the CRA/CRANT/BLA/BLANT picture |
---|
856 | * \param bRefreshPending flag indicating if a deferred decoding refresh is pending |
---|
857 | * \param rcListPic reference to the reference picture list |
---|
858 | * This function marks the reference pictures as "unused for reference" in the following conditions. |
---|
859 | * If the nal_unit_type is IDR/BLA/BLANT, all pictures in the reference picture list |
---|
860 | * are marked as "unused for reference" |
---|
861 | * If the nal_unit_type is BLA/BLANT, set the pocCRA to the temporal reference of the current picture. |
---|
862 | * Otherwise |
---|
863 | * If the bRefreshPending flag is true (a deferred decoding refresh is pending) and the current |
---|
864 | * temporal reference is greater than the temporal reference of the latest CRA/CRANT/BLA/BLANT picture (pocCRA), |
---|
865 | * mark all reference pictures except the latest CRA/CRANT/BLA/BLANT picture as "unused for reference" and set |
---|
866 | * the bRefreshPending flag to false. |
---|
867 | * If the nal_unit_type is CRA/CRANT, set the bRefreshPending flag to true and pocCRA to the temporal |
---|
868 | * reference of the current picture. |
---|
869 | * Note that the current picture is already placed in the reference list and its marking is not changed. |
---|
870 | * If the current picture has a nal_ref_idc that is not 0, it will remain marked as "used for reference". |
---|
871 | */ |
---|
872 | Void TComSlice::decodingRefreshMarking(Int& pocCRA, Bool& bRefreshPending, TComList<TComPic*>& rcListPic) |
---|
873 | { |
---|
874 | TComPic* rpcPic; |
---|
875 | setAssociatedIRAPPOC(pocCRA); |
---|
876 | Int pocCurr = getPOC(); |
---|
877 | |
---|
878 | if ( getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_LP |
---|
879 | || getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_RADL |
---|
880 | || getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_N_LP |
---|
881 | || getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_W_RADL |
---|
882 | || getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_N_LP ) // IDR or BLA picture |
---|
883 | { |
---|
884 | // mark all pictures as not used for reference |
---|
885 | TComList<TComPic*>::iterator iterPic = rcListPic.begin(); |
---|
886 | while (iterPic != rcListPic.end()) |
---|
887 | { |
---|
888 | rpcPic = *(iterPic); |
---|
889 | rpcPic->setCurrSliceIdx(0); |
---|
890 | if (rpcPic->getPOC() != pocCurr) rpcPic->getSlice(0)->setReferenced(false); |
---|
891 | iterPic++; |
---|
892 | } |
---|
893 | if ( getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_LP |
---|
894 | || getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_RADL |
---|
895 | || getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_N_LP ) |
---|
896 | { |
---|
897 | pocCRA = pocCurr; |
---|
898 | } |
---|
899 | } |
---|
900 | else // CRA or No DR |
---|
901 | { |
---|
902 | if (bRefreshPending==true && pocCurr > pocCRA) // CRA reference marking pending |
---|
903 | { |
---|
904 | TComList<TComPic*>::iterator iterPic = rcListPic.begin(); |
---|
905 | while (iterPic != rcListPic.end()) |
---|
906 | { |
---|
907 | rpcPic = *(iterPic); |
---|
908 | if (rpcPic->getPOC() != pocCurr && rpcPic->getPOC() != pocCRA) |
---|
909 | { |
---|
910 | rpcPic->getSlice(0)->setReferenced(false); |
---|
911 | } |
---|
912 | iterPic++; |
---|
913 | } |
---|
914 | bRefreshPending = false; |
---|
915 | } |
---|
916 | if ( getNalUnitType() == NAL_UNIT_CODED_SLICE_CRA ) // CRA picture found |
---|
917 | { |
---|
918 | bRefreshPending = true; |
---|
919 | pocCRA = pocCurr; |
---|
920 | } |
---|
921 | } |
---|
922 | } |
---|
923 | |
---|
924 | Void TComSlice::copySliceInfo(TComSlice *pSrc) |
---|
925 | { |
---|
926 | assert( pSrc != NULL ); |
---|
927 | |
---|
928 | Int i, j, k; |
---|
929 | |
---|
930 | m_iPOC = pSrc->m_iPOC; |
---|
931 | m_eNalUnitType = pSrc->m_eNalUnitType; |
---|
932 | #if H_MV |
---|
933 | m_layerId = pSrc->m_layerId; |
---|
934 | // GT: Copying of several other values might be be missing here, or is above not necessary? |
---|
935 | #endif |
---|
936 | m_eSliceType = pSrc->m_eSliceType; |
---|
937 | m_iSliceQp = pSrc->m_iSliceQp; |
---|
938 | #if ADAPTIVE_QP_SELECTION |
---|
939 | m_iSliceQpBase = pSrc->m_iSliceQpBase; |
---|
940 | #endif |
---|
941 | m_deblockingFilterDisable = pSrc->m_deblockingFilterDisable; |
---|
942 | m_deblockingFilterOverrideFlag = pSrc->m_deblockingFilterOverrideFlag; |
---|
943 | m_deblockingFilterBetaOffsetDiv2 = pSrc->m_deblockingFilterBetaOffsetDiv2; |
---|
944 | m_deblockingFilterTcOffsetDiv2 = pSrc->m_deblockingFilterTcOffsetDiv2; |
---|
945 | |
---|
946 | for (i = 0; i < 2; i++) |
---|
947 | { |
---|
948 | m_aiNumRefIdx[i] = pSrc->m_aiNumRefIdx[i]; |
---|
949 | } |
---|
950 | |
---|
951 | for (i = 0; i < MAX_NUM_REF; i++) |
---|
952 | { |
---|
953 | m_list1IdxToList0Idx[i] = pSrc->m_list1IdxToList0Idx[i]; |
---|
954 | } |
---|
955 | m_bCheckLDC = pSrc->m_bCheckLDC; |
---|
956 | m_iSliceQpDelta = pSrc->m_iSliceQpDelta; |
---|
957 | m_iSliceQpDeltaCb = pSrc->m_iSliceQpDeltaCb; |
---|
958 | m_iSliceQpDeltaCr = pSrc->m_iSliceQpDeltaCr; |
---|
959 | for (i = 0; i < 2; i++) |
---|
960 | { |
---|
961 | for (j = 0; j < MAX_NUM_REF; j++) |
---|
962 | { |
---|
963 | m_apcRefPicList[i][j] = pSrc->m_apcRefPicList[i][j]; |
---|
964 | m_aiRefPOCList[i][j] = pSrc->m_aiRefPOCList[i][j]; |
---|
965 | #if H_MV |
---|
966 | m_aiRefLayerIdList[i][j] = pSrc->m_aiRefLayerIdList[i][j]; |
---|
967 | #endif |
---|
968 | } |
---|
969 | } |
---|
970 | for (i = 0; i < 2; i++) |
---|
971 | { |
---|
972 | for (j = 0; j < MAX_NUM_REF + 1; j++) |
---|
973 | { |
---|
974 | m_bIsUsedAsLongTerm[i][j] = pSrc->m_bIsUsedAsLongTerm[i][j]; |
---|
975 | } |
---|
976 | } |
---|
977 | m_iDepth = pSrc->m_iDepth; |
---|
978 | |
---|
979 | // referenced slice |
---|
980 | m_bRefenced = pSrc->m_bRefenced; |
---|
981 | |
---|
982 | // access channel |
---|
983 | #if H_MV |
---|
984 | m_pcVPS = pSrc->m_pcVPS; |
---|
985 | #endif |
---|
986 | m_pcSPS = pSrc->m_pcSPS; |
---|
987 | m_pcPPS = pSrc->m_pcPPS; |
---|
988 | m_pcRPS = pSrc->m_pcRPS; |
---|
989 | m_iLastIDR = pSrc->m_iLastIDR; |
---|
990 | |
---|
991 | m_pcPic = pSrc->m_pcPic; |
---|
992 | |
---|
993 | m_colFromL0Flag = pSrc->m_colFromL0Flag; |
---|
994 | m_colRefIdx = pSrc->m_colRefIdx; |
---|
995 | #if SAO_CHROMA_LAMBDA |
---|
996 | m_dLambdaLuma = pSrc->m_dLambdaLuma; |
---|
997 | m_dLambdaChroma = pSrc->m_dLambdaChroma; |
---|
998 | #else |
---|
999 | m_dLambda = pSrc->m_dLambda; |
---|
1000 | #endif |
---|
1001 | for (i = 0; i < 2; i++) |
---|
1002 | { |
---|
1003 | for (j = 0; j < MAX_NUM_REF; j++) |
---|
1004 | { |
---|
1005 | for (k =0; k < MAX_NUM_REF; k++) |
---|
1006 | { |
---|
1007 | m_abEqualRef[i][j][k] = pSrc->m_abEqualRef[i][j][k]; |
---|
1008 | } |
---|
1009 | } |
---|
1010 | } |
---|
1011 | |
---|
1012 | m_uiTLayer = pSrc->m_uiTLayer; |
---|
1013 | m_bTLayerSwitchingFlag = pSrc->m_bTLayerSwitchingFlag; |
---|
1014 | |
---|
1015 | m_sliceMode = pSrc->m_sliceMode; |
---|
1016 | m_sliceArgument = pSrc->m_sliceArgument; |
---|
1017 | m_sliceCurStartCUAddr = pSrc->m_sliceCurStartCUAddr; |
---|
1018 | m_sliceCurEndCUAddr = pSrc->m_sliceCurEndCUAddr; |
---|
1019 | m_sliceIdx = pSrc->m_sliceIdx; |
---|
1020 | m_sliceSegmentMode = pSrc->m_sliceSegmentMode; |
---|
1021 | m_sliceSegmentArgument = pSrc->m_sliceSegmentArgument; |
---|
1022 | m_sliceSegmentCurStartCUAddr = pSrc->m_sliceSegmentCurStartCUAddr; |
---|
1023 | m_sliceSegmentCurEndCUAddr = pSrc->m_sliceSegmentCurEndCUAddr; |
---|
1024 | m_nextSlice = pSrc->m_nextSlice; |
---|
1025 | m_nextSliceSegment = pSrc->m_nextSliceSegment; |
---|
1026 | for ( Int e=0 ; e<2 ; e++ ) |
---|
1027 | { |
---|
1028 | for ( Int n=0 ; n<MAX_NUM_REF ; n++ ) |
---|
1029 | { |
---|
1030 | memcpy(m_weightPredTable[e][n], pSrc->m_weightPredTable[e][n], sizeof(wpScalingParam)*3 ); |
---|
1031 | } |
---|
1032 | } |
---|
1033 | m_saoEnabledFlag = pSrc->m_saoEnabledFlag; |
---|
1034 | m_saoEnabledFlagChroma = pSrc->m_saoEnabledFlagChroma; |
---|
1035 | m_cabacInitFlag = pSrc->m_cabacInitFlag; |
---|
1036 | m_numEntryPointOffsets = pSrc->m_numEntryPointOffsets; |
---|
1037 | |
---|
1038 | m_bLMvdL1Zero = pSrc->m_bLMvdL1Zero; |
---|
1039 | m_LFCrossSliceBoundaryFlag = pSrc->m_LFCrossSliceBoundaryFlag; |
---|
1040 | m_enableTMVPFlag = pSrc->m_enableTMVPFlag; |
---|
1041 | m_maxNumMergeCand = pSrc->m_maxNumMergeCand; |
---|
1042 | |
---|
1043 | #if H_MV |
---|
1044 | // Additional slice header syntax elements |
---|
1045 | m_pocResetFlag = pSrc->m_pocResetFlag; |
---|
1046 | m_discardableFlag = pSrc->m_discardableFlag; |
---|
1047 | m_interLayerPredEnabledFlag = pSrc->m_interLayerPredEnabledFlag; |
---|
1048 | m_numInterLayerRefPicsMinus1 = pSrc->m_numInterLayerRefPicsMinus1; |
---|
1049 | |
---|
1050 | for (Int layer = 0; layer < MAX_NUM_LAYERS; layer++ ) |
---|
1051 | { |
---|
1052 | m_interLayerPredLayerIdc[ layer ] = pSrc->m_interLayerPredLayerIdc[ layer ]; |
---|
1053 | } |
---|
1054 | #endif |
---|
1055 | #if H_3D_IC |
---|
1056 | m_bApplyIC = pSrc->m_bApplyIC; |
---|
1057 | m_icSkipParseFlag = pSrc->m_icSkipParseFlag; |
---|
1058 | #endif |
---|
1059 | } |
---|
1060 | |
---|
1061 | Int TComSlice::m_prevTid0POC = 0; |
---|
1062 | |
---|
1063 | /** Function for setting the slice's temporal layer ID and corresponding temporal_layer_switching_point_flag. |
---|
1064 | * \param uiTLayer Temporal layer ID of the current slice |
---|
1065 | * The decoder calls this function to set temporal_layer_switching_point_flag for each temporal layer based on |
---|
1066 | * the SPS's temporal_id_nesting_flag and the parsed PPS. Then, current slice's temporal layer ID and |
---|
1067 | * temporal_layer_switching_point_flag is set accordingly. |
---|
1068 | */ |
---|
1069 | Void TComSlice::setTLayerInfo( UInt uiTLayer ) |
---|
1070 | { |
---|
1071 | m_uiTLayer = uiTLayer; |
---|
1072 | } |
---|
1073 | |
---|
1074 | /** Function for checking if this is a switching-point |
---|
1075 | */ |
---|
1076 | Bool TComSlice::isTemporalLayerSwitchingPoint( TComList<TComPic*>& rcListPic ) |
---|
1077 | { |
---|
1078 | TComPic* rpcPic; |
---|
1079 | // loop through all pictures in the reference picture buffer |
---|
1080 | TComList<TComPic*>::iterator iterPic = rcListPic.begin(); |
---|
1081 | while ( iterPic != rcListPic.end()) |
---|
1082 | { |
---|
1083 | rpcPic = *(iterPic++); |
---|
1084 | if(rpcPic->getSlice(0)->isReferenced() && rpcPic->getPOC() != getPOC()) |
---|
1085 | { |
---|
1086 | if(rpcPic->getTLayer() >= getTLayer()) |
---|
1087 | { |
---|
1088 | return false; |
---|
1089 | } |
---|
1090 | } |
---|
1091 | } |
---|
1092 | return true; |
---|
1093 | } |
---|
1094 | |
---|
1095 | /** Function for checking if this is a STSA candidate |
---|
1096 | */ |
---|
1097 | Bool TComSlice::isStepwiseTemporalLayerSwitchingPointCandidate( TComList<TComPic*>& rcListPic ) |
---|
1098 | { |
---|
1099 | TComPic* rpcPic; |
---|
1100 | |
---|
1101 | TComList<TComPic*>::iterator iterPic = rcListPic.begin(); |
---|
1102 | while ( iterPic != rcListPic.end()) |
---|
1103 | { |
---|
1104 | rpcPic = *(iterPic++); |
---|
1105 | if(rpcPic->getSlice(0)->isReferenced() && (rpcPic->getUsedByCurr()==true) && rpcPic->getPOC() != getPOC()) |
---|
1106 | { |
---|
1107 | if(rpcPic->getTLayer() >= getTLayer()) |
---|
1108 | { |
---|
1109 | return false; |
---|
1110 | } |
---|
1111 | } |
---|
1112 | } |
---|
1113 | return true; |
---|
1114 | } |
---|
1115 | |
---|
1116 | |
---|
1117 | Void TComSlice::checkLeadingPictureRestrictions(TComList<TComPic*>& rcListPic) |
---|
1118 | { |
---|
1119 | TComPic* rpcPic; |
---|
1120 | |
---|
1121 | Int nalUnitType = this->getNalUnitType(); |
---|
1122 | |
---|
1123 | // When a picture is a leading picture, it shall be a RADL or RASL picture. |
---|
1124 | if(this->getAssociatedIRAPPOC() > this->getPOC()) |
---|
1125 | { |
---|
1126 | // Do not check IRAP pictures since they may get a POC lower than their associated IRAP |
---|
1127 | if(nalUnitType < NAL_UNIT_CODED_SLICE_BLA_W_LP || |
---|
1128 | nalUnitType > NAL_UNIT_RESERVED_IRAP_VCL23) |
---|
1129 | { |
---|
1130 | assert(nalUnitType == NAL_UNIT_CODED_SLICE_RASL_N || |
---|
1131 | nalUnitType == NAL_UNIT_CODED_SLICE_RASL_R || |
---|
1132 | nalUnitType == NAL_UNIT_CODED_SLICE_RADL_N || |
---|
1133 | nalUnitType == NAL_UNIT_CODED_SLICE_RADL_R); |
---|
1134 | } |
---|
1135 | } |
---|
1136 | |
---|
1137 | // When a picture is a trailing picture, it shall not be a RADL or RASL picture. |
---|
1138 | if(this->getAssociatedIRAPPOC() < this->getPOC()) |
---|
1139 | { |
---|
1140 | assert(nalUnitType != NAL_UNIT_CODED_SLICE_RASL_N && |
---|
1141 | nalUnitType != NAL_UNIT_CODED_SLICE_RASL_R && |
---|
1142 | nalUnitType != NAL_UNIT_CODED_SLICE_RADL_N && |
---|
1143 | nalUnitType != NAL_UNIT_CODED_SLICE_RADL_R); |
---|
1144 | } |
---|
1145 | |
---|
1146 | // No RASL pictures shall be present in the bitstream that are associated |
---|
1147 | // with a BLA picture having nal_unit_type equal to BLA_W_RADL or BLA_N_LP. |
---|
1148 | if(nalUnitType == NAL_UNIT_CODED_SLICE_RASL_N || |
---|
1149 | nalUnitType == NAL_UNIT_CODED_SLICE_RASL_R) |
---|
1150 | { |
---|
1151 | assert(this->getAssociatedIRAPType() != NAL_UNIT_CODED_SLICE_BLA_W_RADL && |
---|
1152 | this->getAssociatedIRAPType() != NAL_UNIT_CODED_SLICE_BLA_N_LP); |
---|
1153 | } |
---|
1154 | |
---|
1155 | // No RASL pictures shall be present in the bitstream that are associated with |
---|
1156 | // an IDR picture. |
---|
1157 | if(nalUnitType == NAL_UNIT_CODED_SLICE_RASL_N || |
---|
1158 | nalUnitType == NAL_UNIT_CODED_SLICE_RASL_R) |
---|
1159 | { |
---|
1160 | assert(this->getAssociatedIRAPType() != NAL_UNIT_CODED_SLICE_IDR_N_LP && |
---|
1161 | this->getAssociatedIRAPType() != NAL_UNIT_CODED_SLICE_IDR_W_RADL); |
---|
1162 | } |
---|
1163 | |
---|
1164 | // No RADL pictures shall be present in the bitstream that are associated with |
---|
1165 | // a BLA picture having nal_unit_type equal to BLA_N_LP or that are associated |
---|
1166 | // with an IDR picture having nal_unit_type equal to IDR_N_LP. |
---|
1167 | if(nalUnitType == NAL_UNIT_CODED_SLICE_RADL_N || |
---|
1168 | nalUnitType == NAL_UNIT_CODED_SLICE_RADL_R) |
---|
1169 | { |
---|
1170 | assert(this->getAssociatedIRAPType() != NAL_UNIT_CODED_SLICE_BLA_N_LP && |
---|
1171 | this->getAssociatedIRAPType() != NAL_UNIT_CODED_SLICE_IDR_N_LP); |
---|
1172 | } |
---|
1173 | |
---|
1174 | // loop through all pictures in the reference picture buffer |
---|
1175 | TComList<TComPic*>::iterator iterPic = rcListPic.begin(); |
---|
1176 | while ( iterPic != rcListPic.end()) |
---|
1177 | { |
---|
1178 | rpcPic = *(iterPic++); |
---|
1179 | if (rpcPic->getPOC() == this->getPOC()) |
---|
1180 | { |
---|
1181 | continue; |
---|
1182 | } |
---|
1183 | |
---|
1184 | // Any picture that has PicOutputFlag equal to 1 that precedes an IRAP picture |
---|
1185 | // in decoding order shall precede the IRAP picture in output order. |
---|
1186 | // (Note that any picture following in output order would be present in the DPB) |
---|
1187 | if(rpcPic->getSlice(0)->getPicOutputFlag() == 1) |
---|
1188 | { |
---|
1189 | if(nalUnitType == NAL_UNIT_CODED_SLICE_BLA_N_LP || |
---|
1190 | nalUnitType == NAL_UNIT_CODED_SLICE_BLA_W_LP || |
---|
1191 | nalUnitType == NAL_UNIT_CODED_SLICE_BLA_W_RADL || |
---|
1192 | nalUnitType == NAL_UNIT_CODED_SLICE_CRA || |
---|
1193 | nalUnitType == NAL_UNIT_CODED_SLICE_IDR_N_LP || |
---|
1194 | nalUnitType == NAL_UNIT_CODED_SLICE_IDR_W_RADL) |
---|
1195 | { |
---|
1196 | assert(rpcPic->getPOC() < this->getPOC()); |
---|
1197 | } |
---|
1198 | } |
---|
1199 | |
---|
1200 | // Any picture that has PicOutputFlag equal to 1 that precedes an IRAP picture |
---|
1201 | // in decoding order shall precede any RADL picture associated with the IRAP |
---|
1202 | // picture in output order. |
---|
1203 | if(rpcPic->getSlice(0)->getPicOutputFlag() == 1) |
---|
1204 | { |
---|
1205 | if((nalUnitType == NAL_UNIT_CODED_SLICE_RADL_N || |
---|
1206 | nalUnitType == NAL_UNIT_CODED_SLICE_RADL_R)) |
---|
1207 | { |
---|
1208 | // rpcPic precedes the IRAP in decoding order |
---|
1209 | if(this->getAssociatedIRAPPOC() > rpcPic->getSlice(0)->getAssociatedIRAPPOC()) |
---|
1210 | { |
---|
1211 | // rpcPic must not be the IRAP picture |
---|
1212 | if(this->getAssociatedIRAPPOC() != rpcPic->getPOC()) |
---|
1213 | { |
---|
1214 | assert(rpcPic->getPOC() < this->getPOC()); |
---|
1215 | } |
---|
1216 | } |
---|
1217 | } |
---|
1218 | } |
---|
1219 | |
---|
1220 | // When a picture is a leading picture, it shall precede, in decoding order, |
---|
1221 | // all trailing pictures that are associated with the same IRAP picture. |
---|
1222 | if(nalUnitType == NAL_UNIT_CODED_SLICE_RASL_N || |
---|
1223 | nalUnitType == NAL_UNIT_CODED_SLICE_RASL_R || |
---|
1224 | nalUnitType == NAL_UNIT_CODED_SLICE_RADL_N || |
---|
1225 | nalUnitType == NAL_UNIT_CODED_SLICE_RADL_R) |
---|
1226 | { |
---|
1227 | if(rpcPic->getSlice(0)->getAssociatedIRAPPOC() == this->getAssociatedIRAPPOC()) |
---|
1228 | { |
---|
1229 | // rpcPic is a picture that preceded the leading in decoding order since it exist in the DPB |
---|
1230 | // rpcPic would violate the constraint if it was a trailing picture |
---|
1231 | assert(rpcPic->getPOC() <= this->getAssociatedIRAPPOC()); |
---|
1232 | } |
---|
1233 | } |
---|
1234 | |
---|
1235 | // Any RASL picture associated with a CRA or BLA picture shall precede any |
---|
1236 | // RADL picture associated with the CRA or BLA picture in output order |
---|
1237 | if(nalUnitType == NAL_UNIT_CODED_SLICE_RASL_N || |
---|
1238 | nalUnitType == NAL_UNIT_CODED_SLICE_RASL_R) |
---|
1239 | { |
---|
1240 | if((this->getAssociatedIRAPType() == NAL_UNIT_CODED_SLICE_BLA_N_LP || |
---|
1241 | this->getAssociatedIRAPType() == NAL_UNIT_CODED_SLICE_BLA_W_LP || |
---|
1242 | this->getAssociatedIRAPType() == NAL_UNIT_CODED_SLICE_BLA_W_RADL || |
---|
1243 | this->getAssociatedIRAPType() == NAL_UNIT_CODED_SLICE_CRA) && |
---|
1244 | this->getAssociatedIRAPPOC() == rpcPic->getSlice(0)->getAssociatedIRAPPOC()) |
---|
1245 | { |
---|
1246 | if(rpcPic->getSlice(0)->getNalUnitType() == NAL_UNIT_CODED_SLICE_RADL_N || |
---|
1247 | rpcPic->getSlice(0)->getNalUnitType() == NAL_UNIT_CODED_SLICE_RADL_R) |
---|
1248 | { |
---|
1249 | assert(rpcPic->getPOC() > this->getPOC()); |
---|
1250 | } |
---|
1251 | } |
---|
1252 | } |
---|
1253 | |
---|
1254 | // Any RASL picture associated with a CRA picture shall follow, in output |
---|
1255 | // order, any IRAP picture that precedes the CRA picture in decoding order. |
---|
1256 | if(nalUnitType == NAL_UNIT_CODED_SLICE_RASL_N || |
---|
1257 | nalUnitType == NAL_UNIT_CODED_SLICE_RASL_R) |
---|
1258 | { |
---|
1259 | if(this->getAssociatedIRAPType() == NAL_UNIT_CODED_SLICE_CRA) |
---|
1260 | { |
---|
1261 | if(rpcPic->getSlice(0)->getPOC() < this->getAssociatedIRAPPOC() && |
---|
1262 | (rpcPic->getSlice(0)->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_N_LP || |
---|
1263 | rpcPic->getSlice(0)->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_LP || |
---|
1264 | rpcPic->getSlice(0)->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_RADL || |
---|
1265 | rpcPic->getSlice(0)->getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_N_LP || |
---|
1266 | rpcPic->getSlice(0)->getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_W_RADL || |
---|
1267 | rpcPic->getSlice(0)->getNalUnitType() == NAL_UNIT_CODED_SLICE_CRA)) |
---|
1268 | { |
---|
1269 | assert(this->getPOC() > rpcPic->getSlice(0)->getPOC()); |
---|
1270 | } |
---|
1271 | } |
---|
1272 | } |
---|
1273 | } |
---|
1274 | } |
---|
1275 | |
---|
1276 | |
---|
1277 | |
---|
1278 | /** Function for applying picture marking based on the Reference Picture Set in pReferencePictureSet. |
---|
1279 | */ |
---|
1280 | Void TComSlice::applyReferencePictureSet( TComList<TComPic*>& rcListPic, TComReferencePictureSet *pReferencePictureSet) |
---|
1281 | { |
---|
1282 | TComPic* rpcPic; |
---|
1283 | Int i, isReference; |
---|
1284 | |
---|
1285 | checkLeadingPictureRestrictions(rcListPic); |
---|
1286 | |
---|
1287 | // loop through all pictures in the reference picture buffer |
---|
1288 | TComList<TComPic*>::iterator iterPic = rcListPic.begin(); |
---|
1289 | while ( iterPic != rcListPic.end()) |
---|
1290 | { |
---|
1291 | rpcPic = *(iterPic++); |
---|
1292 | |
---|
1293 | if(!rpcPic->getSlice( 0 )->isReferenced()) |
---|
1294 | { |
---|
1295 | continue; |
---|
1296 | } |
---|
1297 | |
---|
1298 | isReference = 0; |
---|
1299 | // loop through all pictures in the Reference Picture Set |
---|
1300 | // to see if the picture should be kept as reference picture |
---|
1301 | for(i=0;i<pReferencePictureSet->getNumberOfPositivePictures()+pReferencePictureSet->getNumberOfNegativePictures();i++) |
---|
1302 | { |
---|
1303 | if(!rpcPic->getIsLongTerm() && rpcPic->getPicSym()->getSlice(0)->getPOC() == this->getPOC() + pReferencePictureSet->getDeltaPOC(i)) |
---|
1304 | { |
---|
1305 | isReference = 1; |
---|
1306 | rpcPic->setUsedByCurr(pReferencePictureSet->getUsed(i)); |
---|
1307 | rpcPic->setIsLongTerm(0); |
---|
1308 | } |
---|
1309 | } |
---|
1310 | for(;i<pReferencePictureSet->getNumberOfPictures();i++) |
---|
1311 | { |
---|
1312 | if(pReferencePictureSet->getCheckLTMSBPresent(i)==true) |
---|
1313 | { |
---|
1314 | if(rpcPic->getIsLongTerm() && (rpcPic->getPicSym()->getSlice(0)->getPOC()) == pReferencePictureSet->getPOC(i)) |
---|
1315 | { |
---|
1316 | isReference = 1; |
---|
1317 | rpcPic->setUsedByCurr(pReferencePictureSet->getUsed(i)); |
---|
1318 | } |
---|
1319 | } |
---|
1320 | else |
---|
1321 | { |
---|
1322 | Int pocCycle = 1<<rpcPic->getPicSym()->getSlice(0)->getSPS()->getBitsForPOC(); |
---|
1323 | Int curPoc = rpcPic->getPicSym()->getSlice(0)->getPOC() & (pocCycle-1); |
---|
1324 | Int refPoc = pReferencePictureSet->getPOC(i) & (pocCycle-1); |
---|
1325 | if(rpcPic->getIsLongTerm() && curPoc == refPoc) |
---|
1326 | { |
---|
1327 | isReference = 1; |
---|
1328 | rpcPic->setUsedByCurr(pReferencePictureSet->getUsed(i)); |
---|
1329 | } |
---|
1330 | } |
---|
1331 | |
---|
1332 | } |
---|
1333 | // mark the picture as "unused for reference" if it is not in |
---|
1334 | // the Reference Picture Set |
---|
1335 | if(rpcPic->getPicSym()->getSlice(0)->getPOC() != this->getPOC() && isReference == 0) |
---|
1336 | { |
---|
1337 | rpcPic->getSlice( 0 )->setReferenced( false ); |
---|
1338 | rpcPic->setUsedByCurr(0); |
---|
1339 | rpcPic->setIsLongTerm(0); |
---|
1340 | } |
---|
1341 | //check that pictures of higher temporal layers are not used |
---|
1342 | assert(rpcPic->getSlice( 0 )->isReferenced()==0||rpcPic->getUsedByCurr()==0||rpcPic->getTLayer()<=this->getTLayer()); |
---|
1343 | //check that pictures of higher or equal temporal layer are not in the RPS if the current picture is a TSA picture |
---|
1344 | if(this->getNalUnitType() == NAL_UNIT_CODED_SLICE_TLA_R || this->getNalUnitType() == NAL_UNIT_CODED_SLICE_TSA_N) |
---|
1345 | { |
---|
1346 | assert(rpcPic->getSlice( 0 )->isReferenced()==0||rpcPic->getTLayer()<this->getTLayer()); |
---|
1347 | } |
---|
1348 | //check that pictures marked as temporal layer non-reference pictures are not used for reference |
---|
1349 | if(rpcPic->getPicSym()->getSlice(0)->getPOC() != this->getPOC() && rpcPic->getTLayer()==this->getTLayer()) |
---|
1350 | { |
---|
1351 | assert(rpcPic->getSlice( 0 )->isReferenced()==0||rpcPic->getUsedByCurr()==0||rpcPic->getSlice( 0 )->getTemporalLayerNonReferenceFlag()==false); |
---|
1352 | } |
---|
1353 | } |
---|
1354 | } |
---|
1355 | |
---|
1356 | /** Function for applying picture marking based on the Reference Picture Set in pReferencePictureSet. |
---|
1357 | */ |
---|
1358 | Int TComSlice::checkThatAllRefPicsAreAvailable( TComList<TComPic*>& rcListPic, TComReferencePictureSet *pReferencePictureSet, Bool printErrors, Int pocRandomAccess) |
---|
1359 | { |
---|
1360 | TComPic* rpcPic; |
---|
1361 | Int i, isAvailable; |
---|
1362 | Int atLeastOneLost = 0; |
---|
1363 | Int atLeastOneRemoved = 0; |
---|
1364 | Int iPocLost = 0; |
---|
1365 | |
---|
1366 | // loop through all long-term pictures in the Reference Picture Set |
---|
1367 | // to see if the picture should be kept as reference picture |
---|
1368 | for(i=pReferencePictureSet->getNumberOfNegativePictures()+pReferencePictureSet->getNumberOfPositivePictures();i<pReferencePictureSet->getNumberOfPictures();i++) |
---|
1369 | { |
---|
1370 | isAvailable = 0; |
---|
1371 | // loop through all pictures in the reference picture buffer |
---|
1372 | TComList<TComPic*>::iterator iterPic = rcListPic.begin(); |
---|
1373 | while ( iterPic != rcListPic.end()) |
---|
1374 | { |
---|
1375 | rpcPic = *(iterPic++); |
---|
1376 | if(pReferencePictureSet->getCheckLTMSBPresent(i)==true) |
---|
1377 | { |
---|
1378 | if(rpcPic->getIsLongTerm() && (rpcPic->getPicSym()->getSlice(0)->getPOC()) == pReferencePictureSet->getPOC(i) && rpcPic->getSlice(0)->isReferenced()) |
---|
1379 | { |
---|
1380 | isAvailable = 1; |
---|
1381 | } |
---|
1382 | } |
---|
1383 | else |
---|
1384 | { |
---|
1385 | Int pocCycle = 1<<rpcPic->getPicSym()->getSlice(0)->getSPS()->getBitsForPOC(); |
---|
1386 | Int curPoc = rpcPic->getPicSym()->getSlice(0)->getPOC() & (pocCycle-1); |
---|
1387 | Int refPoc = pReferencePictureSet->getPOC(i) & (pocCycle-1); |
---|
1388 | if(rpcPic->getIsLongTerm() && curPoc == refPoc && rpcPic->getSlice(0)->isReferenced()) |
---|
1389 | { |
---|
1390 | isAvailable = 1; |
---|
1391 | } |
---|
1392 | } |
---|
1393 | } |
---|
1394 | // if there was no such long-term check the short terms |
---|
1395 | if(!isAvailable) |
---|
1396 | { |
---|
1397 | iterPic = rcListPic.begin(); |
---|
1398 | while ( iterPic != rcListPic.end()) |
---|
1399 | { |
---|
1400 | rpcPic = *(iterPic++); |
---|
1401 | |
---|
1402 | Int pocCycle = 1 << rpcPic->getPicSym()->getSlice(0)->getSPS()->getBitsForPOC(); |
---|
1403 | Int curPoc = rpcPic->getPicSym()->getSlice(0)->getPOC(); |
---|
1404 | Int refPoc = pReferencePictureSet->getPOC(i); |
---|
1405 | if (!pReferencePictureSet->getCheckLTMSBPresent(i)) |
---|
1406 | { |
---|
1407 | curPoc = curPoc & (pocCycle - 1); |
---|
1408 | refPoc = refPoc & (pocCycle - 1); |
---|
1409 | } |
---|
1410 | |
---|
1411 | if (rpcPic->getSlice(0)->isReferenced() && curPoc == refPoc) |
---|
1412 | { |
---|
1413 | isAvailable = 1; |
---|
1414 | rpcPic->setIsLongTerm(1); |
---|
1415 | break; |
---|
1416 | } |
---|
1417 | } |
---|
1418 | } |
---|
1419 | // report that a picture is lost if it is in the Reference Picture Set |
---|
1420 | // but not available as reference picture |
---|
1421 | if(isAvailable == 0) |
---|
1422 | { |
---|
1423 | if (this->getPOC() + pReferencePictureSet->getDeltaPOC(i) >= pocRandomAccess) |
---|
1424 | { |
---|
1425 | if(!pReferencePictureSet->getUsed(i) ) |
---|
1426 | { |
---|
1427 | if(printErrors) |
---|
1428 | { |
---|
1429 | printf("\nLong-term reference picture with POC = %3d seems to have been removed or not correctly decoded.", this->getPOC() + pReferencePictureSet->getDeltaPOC(i)); |
---|
1430 | } |
---|
1431 | atLeastOneRemoved = 1; |
---|
1432 | } |
---|
1433 | else |
---|
1434 | { |
---|
1435 | if(printErrors) |
---|
1436 | { |
---|
1437 | printf("\nLong-term reference picture with POC = %3d is lost or not correctly decoded!", this->getPOC() + pReferencePictureSet->getDeltaPOC(i)); |
---|
1438 | } |
---|
1439 | atLeastOneLost = 1; |
---|
1440 | iPocLost=this->getPOC() + pReferencePictureSet->getDeltaPOC(i); |
---|
1441 | } |
---|
1442 | } |
---|
1443 | } |
---|
1444 | } |
---|
1445 | // loop through all short-term pictures in the Reference Picture Set |
---|
1446 | // to see if the picture should be kept as reference picture |
---|
1447 | for(i=0;i<pReferencePictureSet->getNumberOfNegativePictures()+pReferencePictureSet->getNumberOfPositivePictures();i++) |
---|
1448 | { |
---|
1449 | isAvailable = 0; |
---|
1450 | // loop through all pictures in the reference picture buffer |
---|
1451 | TComList<TComPic*>::iterator iterPic = rcListPic.begin(); |
---|
1452 | while ( iterPic != rcListPic.end()) |
---|
1453 | { |
---|
1454 | rpcPic = *(iterPic++); |
---|
1455 | |
---|
1456 | if(!rpcPic->getIsLongTerm() && rpcPic->getPicSym()->getSlice(0)->getPOC() == this->getPOC() + pReferencePictureSet->getDeltaPOC(i) && rpcPic->getSlice(0)->isReferenced()) |
---|
1457 | { |
---|
1458 | isAvailable = 1; |
---|
1459 | } |
---|
1460 | } |
---|
1461 | // report that a picture is lost if it is in the Reference Picture Set |
---|
1462 | // but not available as reference picture |
---|
1463 | if(isAvailable == 0) |
---|
1464 | { |
---|
1465 | if (this->getPOC() + pReferencePictureSet->getDeltaPOC(i) >= pocRandomAccess) |
---|
1466 | { |
---|
1467 | if(!pReferencePictureSet->getUsed(i) ) |
---|
1468 | { |
---|
1469 | if(printErrors) |
---|
1470 | { |
---|
1471 | printf("\nShort-term reference picture with POC = %3d seems to have been removed or not correctly decoded.", this->getPOC() + pReferencePictureSet->getDeltaPOC(i)); |
---|
1472 | } |
---|
1473 | atLeastOneRemoved = 1; |
---|
1474 | } |
---|
1475 | else |
---|
1476 | { |
---|
1477 | if(printErrors) |
---|
1478 | { |
---|
1479 | printf("\nShort-term reference picture with POC = %3d is lost or not correctly decoded!", this->getPOC() + pReferencePictureSet->getDeltaPOC(i)); |
---|
1480 | } |
---|
1481 | atLeastOneLost = 1; |
---|
1482 | iPocLost=this->getPOC() + pReferencePictureSet->getDeltaPOC(i); |
---|
1483 | } |
---|
1484 | } |
---|
1485 | } |
---|
1486 | } |
---|
1487 | if(atLeastOneLost) |
---|
1488 | { |
---|
1489 | return iPocLost+1; |
---|
1490 | } |
---|
1491 | if(atLeastOneRemoved) |
---|
1492 | { |
---|
1493 | return -2; |
---|
1494 | } |
---|
1495 | else |
---|
1496 | { |
---|
1497 | return 0; |
---|
1498 | } |
---|
1499 | } |
---|
1500 | |
---|
1501 | /** Function for constructing an explicit Reference Picture Set out of the available pictures in a referenced Reference Picture Set |
---|
1502 | */ |
---|
1503 | #if FIX1071 |
---|
1504 | Void TComSlice::createExplicitReferencePictureSetFromReference( TComList<TComPic*>& rcListPic, TComReferencePictureSet *pReferencePictureSet, Bool isRAP) |
---|
1505 | #else |
---|
1506 | Void TComSlice::createExplicitReferencePictureSetFromReference( TComList<TComPic*>& rcListPic, TComReferencePictureSet *pReferencePictureSet) |
---|
1507 | #endif |
---|
1508 | { |
---|
1509 | TComPic* rpcPic; |
---|
1510 | Int i, j; |
---|
1511 | Int k = 0; |
---|
1512 | Int nrOfNegativePictures = 0; |
---|
1513 | Int nrOfPositivePictures = 0; |
---|
1514 | TComReferencePictureSet* pcRPS = this->getLocalRPS(); |
---|
1515 | |
---|
1516 | // loop through all pictures in the Reference Picture Set |
---|
1517 | for(i=0;i<pReferencePictureSet->getNumberOfPictures();i++) |
---|
1518 | { |
---|
1519 | j = 0; |
---|
1520 | // loop through all pictures in the reference picture buffer |
---|
1521 | TComList<TComPic*>::iterator iterPic = rcListPic.begin(); |
---|
1522 | while ( iterPic != rcListPic.end()) |
---|
1523 | { |
---|
1524 | j++; |
---|
1525 | rpcPic = *(iterPic++); |
---|
1526 | |
---|
1527 | if(rpcPic->getPicSym()->getSlice(0)->getPOC() == this->getPOC() + pReferencePictureSet->getDeltaPOC(i) && rpcPic->getSlice(0)->isReferenced()) |
---|
1528 | { |
---|
1529 | // This picture exists as a reference picture |
---|
1530 | // and should be added to the explicit Reference Picture Set |
---|
1531 | pcRPS->setDeltaPOC(k, pReferencePictureSet->getDeltaPOC(i)); |
---|
1532 | #if FIX1071 |
---|
1533 | pcRPS->setUsed(k, pReferencePictureSet->getUsed(i) && (!isRAP)); |
---|
1534 | #else |
---|
1535 | pcRPS->setUsed(k, pReferencePictureSet->getUsed(i)); |
---|
1536 | #endif |
---|
1537 | if(pcRPS->getDeltaPOC(k) < 0) |
---|
1538 | { |
---|
1539 | nrOfNegativePictures++; |
---|
1540 | } |
---|
1541 | else |
---|
1542 | { |
---|
1543 | nrOfPositivePictures++; |
---|
1544 | } |
---|
1545 | k++; |
---|
1546 | } |
---|
1547 | } |
---|
1548 | } |
---|
1549 | pcRPS->setNumberOfNegativePictures(nrOfNegativePictures); |
---|
1550 | pcRPS->setNumberOfPositivePictures(nrOfPositivePictures); |
---|
1551 | pcRPS->setNumberOfPictures(nrOfNegativePictures+nrOfPositivePictures); |
---|
1552 | // This is a simplistic inter rps example. A smarter encoder will look for a better reference RPS to do the |
---|
1553 | // inter RPS prediction with. Here we just use the reference used by pReferencePictureSet. |
---|
1554 | // If pReferencePictureSet is not inter_RPS_predicted, then inter_RPS_prediction is for the current RPS also disabled. |
---|
1555 | if (!pReferencePictureSet->getInterRPSPrediction()) |
---|
1556 | { |
---|
1557 | pcRPS->setInterRPSPrediction(false); |
---|
1558 | pcRPS->setNumRefIdc(0); |
---|
1559 | } |
---|
1560 | else |
---|
1561 | { |
---|
1562 | Int rIdx = this->getRPSidx() - pReferencePictureSet->getDeltaRIdxMinus1() - 1; |
---|
1563 | Int deltaRPS = pReferencePictureSet->getDeltaRPS(); |
---|
1564 | TComReferencePictureSet* pcRefRPS = this->getSPS()->getRPSList()->getReferencePictureSet(rIdx); |
---|
1565 | Int iRefPics = pcRefRPS->getNumberOfPictures(); |
---|
1566 | Int iNewIdc=0; |
---|
1567 | for(i=0; i<= iRefPics; i++) |
---|
1568 | { |
---|
1569 | Int deltaPOC = ((i != iRefPics)? pcRefRPS->getDeltaPOC(i) : 0); // check if the reference abs POC is >= 0 |
---|
1570 | Int iRefIdc = 0; |
---|
1571 | for (j=0; j < pcRPS->getNumberOfPictures(); j++) // loop through the pictures in the new RPS |
---|
1572 | { |
---|
1573 | if ( (deltaPOC + deltaRPS) == pcRPS->getDeltaPOC(j)) |
---|
1574 | { |
---|
1575 | if (pcRPS->getUsed(j)) |
---|
1576 | { |
---|
1577 | iRefIdc = 1; |
---|
1578 | } |
---|
1579 | else |
---|
1580 | { |
---|
1581 | iRefIdc = 2; |
---|
1582 | } |
---|
1583 | } |
---|
1584 | } |
---|
1585 | pcRPS->setRefIdc(i, iRefIdc); |
---|
1586 | iNewIdc++; |
---|
1587 | } |
---|
1588 | pcRPS->setInterRPSPrediction(true); |
---|
1589 | pcRPS->setNumRefIdc(iNewIdc); |
---|
1590 | pcRPS->setDeltaRPS(deltaRPS); |
---|
1591 | pcRPS->setDeltaRIdxMinus1(pReferencePictureSet->getDeltaRIdxMinus1() + this->getSPS()->getRPSList()->getNumberOfReferencePictureSets() - this->getRPSidx()); |
---|
1592 | } |
---|
1593 | |
---|
1594 | this->setRPS(pcRPS); |
---|
1595 | this->setRPSidx(-1); |
---|
1596 | } |
---|
1597 | |
---|
1598 | /** get AC and DC values for weighted pred |
---|
1599 | * \param *wp |
---|
1600 | * \returns Void |
---|
1601 | */ |
---|
1602 | Void TComSlice::getWpAcDcParam(wpACDCParam *&wp) |
---|
1603 | { |
---|
1604 | wp = m_weightACDCParam; |
---|
1605 | } |
---|
1606 | |
---|
1607 | /** init AC and DC values for weighted pred |
---|
1608 | * \returns Void |
---|
1609 | */ |
---|
1610 | Void TComSlice::initWpAcDcParam() |
---|
1611 | { |
---|
1612 | for(Int iComp = 0; iComp < 3; iComp++ ) |
---|
1613 | { |
---|
1614 | m_weightACDCParam[iComp].iAC = 0; |
---|
1615 | m_weightACDCParam[iComp].iDC = 0; |
---|
1616 | } |
---|
1617 | } |
---|
1618 | |
---|
1619 | /** get WP tables for weighted pred |
---|
1620 | * \param RefPicList |
---|
1621 | * \param iRefIdx |
---|
1622 | * \param *&wpScalingParam |
---|
1623 | * \returns Void |
---|
1624 | */ |
---|
1625 | Void TComSlice::getWpScaling( RefPicList e, Int iRefIdx, wpScalingParam *&wp ) |
---|
1626 | { |
---|
1627 | wp = m_weightPredTable[e][iRefIdx]; |
---|
1628 | } |
---|
1629 | |
---|
1630 | /** reset Default WP tables settings : no weight. |
---|
1631 | * \param wpScalingParam |
---|
1632 | * \returns Void |
---|
1633 | */ |
---|
1634 | Void TComSlice::resetWpScaling() |
---|
1635 | { |
---|
1636 | for ( Int e=0 ; e<2 ; e++ ) |
---|
1637 | { |
---|
1638 | for ( Int i=0 ; i<MAX_NUM_REF ; i++ ) |
---|
1639 | { |
---|
1640 | for ( Int yuv=0 ; yuv<3 ; yuv++ ) |
---|
1641 | { |
---|
1642 | wpScalingParam *pwp = &(m_weightPredTable[e][i][yuv]); |
---|
1643 | pwp->bPresentFlag = false; |
---|
1644 | pwp->uiLog2WeightDenom = 0; |
---|
1645 | pwp->uiLog2WeightDenom = 0; |
---|
1646 | pwp->iWeight = 1; |
---|
1647 | pwp->iOffset = 0; |
---|
1648 | } |
---|
1649 | } |
---|
1650 | } |
---|
1651 | } |
---|
1652 | |
---|
1653 | /** init WP table |
---|
1654 | * \returns Void |
---|
1655 | */ |
---|
1656 | Void TComSlice::initWpScaling() |
---|
1657 | { |
---|
1658 | for ( Int e=0 ; e<2 ; e++ ) |
---|
1659 | { |
---|
1660 | for ( Int i=0 ; i<MAX_NUM_REF ; i++ ) |
---|
1661 | { |
---|
1662 | for ( Int yuv=0 ; yuv<3 ; yuv++ ) |
---|
1663 | { |
---|
1664 | wpScalingParam *pwp = &(m_weightPredTable[e][i][yuv]); |
---|
1665 | if ( !pwp->bPresentFlag ) |
---|
1666 | { |
---|
1667 | // Inferring values not present : |
---|
1668 | pwp->iWeight = (1 << pwp->uiLog2WeightDenom); |
---|
1669 | pwp->iOffset = 0; |
---|
1670 | } |
---|
1671 | |
---|
1672 | pwp->w = pwp->iWeight; |
---|
1673 | Int bitDepth = yuv ? g_bitDepthC : g_bitDepthY; |
---|
1674 | pwp->o = pwp->iOffset << (bitDepth-8); |
---|
1675 | pwp->shift = pwp->uiLog2WeightDenom; |
---|
1676 | pwp->round = (pwp->uiLog2WeightDenom>=1) ? (1 << (pwp->uiLog2WeightDenom-1)) : (0); |
---|
1677 | } |
---|
1678 | } |
---|
1679 | } |
---|
1680 | } |
---|
1681 | |
---|
1682 | // ------------------------------------------------------------------------------------------------ |
---|
1683 | // Video parameter set (VPS) |
---|
1684 | // ------------------------------------------------------------------------------------------------ |
---|
1685 | TComVPS::TComVPS() |
---|
1686 | : m_VPSId ( 0) |
---|
1687 | , m_uiMaxTLayers ( 1) |
---|
1688 | #if H_MV |
---|
1689 | , m_uiMaxLayersMinus1 ( 0) |
---|
1690 | #else |
---|
1691 | , m_uiMaxLayers ( 1) |
---|
1692 | #endif |
---|
1693 | , m_bTemporalIdNestingFlag (false) |
---|
1694 | , m_numHrdParameters ( 0) |
---|
1695 | #if H_MV |
---|
1696 | , m_maxLayerId ( 0) |
---|
1697 | #else |
---|
1698 | , m_maxNuhReservedZeroLayerId ( 0) |
---|
1699 | #endif |
---|
1700 | , m_hrdParameters (NULL) |
---|
1701 | , m_hrdOpSetIdx (NULL) |
---|
1702 | , m_cprmsPresentFlag (NULL) |
---|
1703 | #if H_MV |
---|
1704 | , m_dpbSize (NULL) |
---|
1705 | , m_vpsVUI ( NULL ) |
---|
1706 | #endif |
---|
1707 | { |
---|
1708 | for( Int i = 0; i < MAX_TLAYER; i++) |
---|
1709 | { |
---|
1710 | m_numReorderPics[i] = 0; |
---|
1711 | m_uiMaxDecPicBuffering[i] = 1; |
---|
1712 | m_uiMaxLatencyIncrease[i] = 0; |
---|
1713 | } |
---|
1714 | #if H_MV |
---|
1715 | for (Int lsIdx = 0; lsIdx < MAX_VPS_OP_SETS_PLUS1; lsIdx++ ) |
---|
1716 | { |
---|
1717 | for( Int layerId = 0; layerId < MAX_VPS_NUH_LAYER_ID_PLUS1; layerId++ ) |
---|
1718 | { |
---|
1719 | m_layerIdIncludedFlag[lsIdx][layerId] = (( lsIdx == 0 ) && ( layerId == 0 )) ; |
---|
1720 | } |
---|
1721 | } |
---|
1722 | |
---|
1723 | m_vpsNumberLayerSetsMinus1 = -1; |
---|
1724 | m_vpsNumProfileTierLevelMinus1 = -1; |
---|
1725 | |
---|
1726 | for ( Int i = 0; i < MAX_VPS_PROFILE_TIER_LEVEL; i++) |
---|
1727 | { |
---|
1728 | m_profileRefMinus1[ i ] = -1; |
---|
1729 | } |
---|
1730 | |
---|
1731 | m_moreOutputLayerSetsThanDefaultFlag = false; |
---|
1732 | m_numAddOutputLayerSetsMinus1 = -1; |
---|
1733 | m_defaultOneTargetOutputLayerIdc = 0; |
---|
1734 | |
---|
1735 | for ( Int i = 0; i < MAX_VPS_OUTPUTLAYER_SETS; i++) |
---|
1736 | { |
---|
1737 | m_outputLayerSetIdxMinus1[i] = -1; |
---|
1738 | m_profileLevelTierIdx[i] = 0; |
---|
1739 | for ( Int j = 0; j < MAX_VPS_NUH_LAYER_ID_PLUS1; j++) |
---|
1740 | { |
---|
1741 | m_outputLayerFlag[i][j] = false; |
---|
1742 | } |
---|
1743 | } |
---|
1744 | m_altOutputLayerFlag = false; |
---|
1745 | m_maxOneActiveRefLayerFlag = false; |
---|
1746 | m_directDepTypeLenMinus2 = 0; |
---|
1747 | |
---|
1748 | |
---|
1749 | m_avcBaseLayerFlag = false; |
---|
1750 | m_vpsVuiOffset = 0; |
---|
1751 | m_splittingFlag = false; |
---|
1752 | |
---|
1753 | for( Int i = 0; i < MAX_NUM_SCALABILITY_TYPES; i++ ) |
---|
1754 | { |
---|
1755 | m_scalabilityMaskFlag[i] = false; |
---|
1756 | m_dimensionIdLen [i] = -1; |
---|
1757 | } |
---|
1758 | |
---|
1759 | m_vpsNuhLayerIdPresentFlag = false; |
---|
1760 | |
---|
1761 | for( Int i = 0; i < MAX_VPS_OP_SETS_PLUS1; i++ ) |
---|
1762 | { |
---|
1763 | m_vpsProfilePresentFlag [i] = false; |
---|
1764 | m_profileRefMinus1[i] = 0; |
---|
1765 | m_outputLayerSetIdxMinus1 [i] = 0; |
---|
1766 | for( Int j = 0; j < MAX_VPS_NUH_LAYER_ID_PLUS1; j++ ) |
---|
1767 | { |
---|
1768 | m_outputLayerFlag[i][j] = false; |
---|
1769 | } |
---|
1770 | } |
---|
1771 | |
---|
1772 | for( Int i = 0; i < MAX_NUM_LAYER_IDS; i++ ) |
---|
1773 | { |
---|
1774 | m_layerIdInVps[i] = (i == 0 ) ? 0 : -1; |
---|
1775 | } |
---|
1776 | |
---|
1777 | for( Int i = 0; i < MAX_NUM_LAYERS; i++ ) |
---|
1778 | { |
---|
1779 | m_layerIdInNuh [i] = ( i == 0 ) ? 0 : -1; |
---|
1780 | m_numDirectRefLayers[i] = 0; |
---|
1781 | m_vpsRepFormatIdx [i] = 0; |
---|
1782 | m_pocLsbNotPresentFlag[i] = 0; |
---|
1783 | m_repFormat [i] = NULL; |
---|
1784 | m_viewIdVal [i] = 0; |
---|
1785 | |
---|
1786 | #if H_3D |
---|
1787 | m_viewIndex [i] = -1; |
---|
1788 | m_vpsDepthModesFlag [i] = false; |
---|
1789 | m_ivMvScalingFlag = true; |
---|
1790 | #endif |
---|
1791 | |
---|
1792 | for( Int j = 0; j < MAX_NUM_LAYERS; j++ ) |
---|
1793 | { |
---|
1794 | m_directDependencyFlag[i][j] = false; |
---|
1795 | m_directDependencyType[i][j] = -1; |
---|
1796 | m_refLayerId[i][j] = -1; |
---|
1797 | m_maxTidIlRefPicsPlus1[i][j] = 7; |
---|
1798 | } |
---|
1799 | |
---|
1800 | for( Int j = 0; j < MAX_NUM_SCALABILITY_TYPES; j++ ) |
---|
1801 | { |
---|
1802 | m_dimensionId[i][j] = 0; |
---|
1803 | } |
---|
1804 | #if H_3D_ARP |
---|
1805 | m_uiUseAdvResPred[i] = 0; |
---|
1806 | m_uiARPStepNum[i] = 1; |
---|
1807 | #endif |
---|
1808 | } |
---|
1809 | m_vpsVUI = new TComVPSVUI; |
---|
1810 | m_dpbSize = new TComDpbSize; |
---|
1811 | |
---|
1812 | #if H_3D |
---|
1813 | for( Int i = 0; i < MAX_NUM_LAYERS; i++ ) |
---|
1814 | { |
---|
1815 | #if H_3D_IV_MERGE |
---|
1816 | m_ivMvPredFlag [ i ] = false; |
---|
1817 | #if H_3D_SPIVMP |
---|
1818 | m_iSubPULog2Size [ i ] = 0; |
---|
1819 | #endif |
---|
1820 | #endif |
---|
1821 | #if H_3D_VSP |
---|
1822 | m_viewSynthesisPredFlag[ i ] = false; |
---|
1823 | #endif |
---|
1824 | #if H_3D_NBDV_REF |
---|
1825 | m_depthRefinementFlag [ i ] = false; |
---|
1826 | #endif |
---|
1827 | #if H_3D_INTER_SDC |
---|
1828 | m_bInterSDCFlag [ i ] = false; |
---|
1829 | #endif |
---|
1830 | #if H_3D_IV_MERGE |
---|
1831 | m_bMPIFlag [ i ] = false; |
---|
1832 | #endif |
---|
1833 | } |
---|
1834 | #endif |
---|
1835 | #endif |
---|
1836 | } |
---|
1837 | |
---|
1838 | TComVPS::~TComVPS() |
---|
1839 | { |
---|
1840 | if( m_hrdParameters != NULL ) delete[] m_hrdParameters; |
---|
1841 | if( m_hrdOpSetIdx != NULL ) delete[] m_hrdOpSetIdx; |
---|
1842 | if( m_cprmsPresentFlag != NULL ) delete[] m_cprmsPresentFlag; |
---|
1843 | #if H_MV |
---|
1844 | if ( m_vpsVUI != NULL ) delete m_vpsVUI; |
---|
1845 | if ( m_dpbSize != NULL ) delete m_dpbSize; |
---|
1846 | |
---|
1847 | for( Int i = 0; i < MAX_NUM_LAYERS; i++ ) |
---|
1848 | { |
---|
1849 | if (m_repFormat[ i ] != NULL ) delete m_repFormat[ i ]; |
---|
1850 | } |
---|
1851 | #endif |
---|
1852 | #if H_3D |
---|
1853 | deleteCamPars(); |
---|
1854 | #endif |
---|
1855 | } |
---|
1856 | |
---|
1857 | #if H_MV |
---|
1858 | |
---|
1859 | Bool TComVPS::checkVPSExtensionSyntax() |
---|
1860 | { |
---|
1861 | for( Int layer = 1; layer <= getMaxLayersMinus1(); layer++ ) |
---|
1862 | { |
---|
1863 | // check layer_id_in_nuh constraint |
---|
1864 | assert( getLayerIdInNuh( layer ) > getLayerIdInNuh( layer -1 ) ); |
---|
1865 | } |
---|
1866 | return true; |
---|
1867 | } |
---|
1868 | |
---|
1869 | Int TComVPS::getNumScalabilityTypes() |
---|
1870 | { |
---|
1871 | return scalTypeToScalIdx( ScalabilityType(MAX_NUM_SCALABILITY_TYPES) ); |
---|
1872 | } |
---|
1873 | |
---|
1874 | Int TComVPS::scalTypeToScalIdx( ScalabilityType scalType ) |
---|
1875 | { |
---|
1876 | assert( scalType >= 0 && scalType <= MAX_NUM_SCALABILITY_TYPES ); |
---|
1877 | assert( scalType == MAX_NUM_SCALABILITY_TYPES || getScalabilityMaskFlag( scalType ) ); |
---|
1878 | Int scalIdx = 0; |
---|
1879 | for( Int curScalType = 0; curScalType < scalType; curScalType++ ) |
---|
1880 | { |
---|
1881 | scalIdx += ( getScalabilityMaskFlag( curScalType ) ? 1 : 0 ); |
---|
1882 | |
---|
1883 | } |
---|
1884 | |
---|
1885 | return scalIdx; |
---|
1886 | } |
---|
1887 | Void TComVPS::setScalabilityMaskFlag( UInt val ) |
---|
1888 | { |
---|
1889 | for ( Int scalType = 0; scalType < MAX_NUM_SCALABILITY_TYPES; scalType++ ) |
---|
1890 | { |
---|
1891 | setScalabilityMaskFlag( scalType, ( val & (1 << scalType ) ) != 0 ); |
---|
1892 | } |
---|
1893 | } |
---|
1894 | |
---|
1895 | Void TComVPS::setRefLayers() |
---|
1896 | { |
---|
1897 | for( Int i = 0; i <= getMaxLayersMinus1(); i++ ) |
---|
1898 | { |
---|
1899 | Int iNuhLId = getLayerIdInNuh( i ); |
---|
1900 | m_numDirectRefLayers[ iNuhLId ] = 0; |
---|
1901 | for( Int j = 0; j < i; j++ ) |
---|
1902 | { |
---|
1903 | if( getDirectDependencyFlag(i , j) ) |
---|
1904 | { |
---|
1905 | m_refLayerId[ iNuhLId ][m_numDirectRefLayers[ iNuhLId ]++ ] = getLayerIdInNuh( j ); |
---|
1906 | } |
---|
1907 | } |
---|
1908 | } |
---|
1909 | } |
---|
1910 | |
---|
1911 | Int TComVPS::getRefLayerId( Int layerIdInNuh, Int idx ) |
---|
1912 | { |
---|
1913 | assert( idx >= 0 && idx < m_numDirectRefLayers[layerIdInNuh] ); |
---|
1914 | Int refLayerIdInNuh = m_refLayerId[ layerIdInNuh ][ idx ]; |
---|
1915 | assert ( refLayerIdInNuh >= 0 ); |
---|
1916 | return refLayerIdInNuh; |
---|
1917 | } |
---|
1918 | |
---|
1919 | Int TComVPS::getScalabilityId( Int layerIdInVps, ScalabilityType scalType ) |
---|
1920 | { |
---|
1921 | return getScalabilityMaskFlag( scalType ) ? getDimensionId( layerIdInVps, scalTypeToScalIdx( scalType ) ) : 0; |
---|
1922 | } |
---|
1923 | |
---|
1924 | #if H_3D |
---|
1925 | Int TComVPS::getLayerIdInNuh( Int viewIndex, Bool depthFlag ) |
---|
1926 | { |
---|
1927 | Int foundLayerIdinNuh = -1; |
---|
1928 | |
---|
1929 | for (Int layerIdInVps = 0 ; layerIdInVps <= getMaxLayersMinus1(); layerIdInVps++ ) |
---|
1930 | { |
---|
1931 | Int layerIdInNuh = getLayerIdInNuh( layerIdInVps ); |
---|
1932 | if( ( getViewIndex( layerIdInNuh ) == viewIndex ) && ( getDepthId( layerIdInNuh ) == ( depthFlag ? 1 : 0 ) ) ) |
---|
1933 | { |
---|
1934 | foundLayerIdinNuh = layerIdInNuh; |
---|
1935 | break; |
---|
1936 | } |
---|
1937 | } |
---|
1938 | assert( foundLayerIdinNuh != -1 ); |
---|
1939 | |
---|
1940 | return foundLayerIdinNuh; |
---|
1941 | } |
---|
1942 | |
---|
1943 | Void TComVPS::createCamPars(Int iNumViews) |
---|
1944 | { |
---|
1945 | Int i = 0, j = 0; |
---|
1946 | |
---|
1947 | m_bCamParPresent = new Bool[ iNumViews ]; |
---|
1948 | m_bCamParInSliceHeader = new Bool[ iNumViews ]; |
---|
1949 | |
---|
1950 | m_aaaiCodedScale = new Int**[ iNumViews ]; |
---|
1951 | m_aaaiCodedOffset = new Int**[ iNumViews ]; |
---|
1952 | for ( i = 0; i < iNumViews ; i++ ) |
---|
1953 | { |
---|
1954 | m_aaaiCodedScale[i] = new Int*[ 2 ]; |
---|
1955 | m_aaaiCodedOffset[i] = new Int*[ 2 ]; |
---|
1956 | for ( j = 0; j < 2; j++ ) |
---|
1957 | { |
---|
1958 | m_aaaiCodedScale[i][j] = new Int[ MAX_NUM_LAYERS ]; |
---|
1959 | m_aaaiCodedOffset[i][j] = new Int[ MAX_NUM_LAYERS ]; |
---|
1960 | for ( Int k = 0; k < MAX_NUM_LAYERS; k++ ) |
---|
1961 | { |
---|
1962 | m_aaaiCodedScale[i][j][k] = 0; |
---|
1963 | m_aaaiCodedOffset[i][j][k] = 0; |
---|
1964 | } |
---|
1965 | } |
---|
1966 | } |
---|
1967 | } |
---|
1968 | |
---|
1969 | Void TComVPS::deleteCamPars() |
---|
1970 | { |
---|
1971 | Int iNumViews = getNumViews(); |
---|
1972 | Int i = 0, j = 0; |
---|
1973 | |
---|
1974 | if ( m_bCamParPresent != NULL ) |
---|
1975 | { |
---|
1976 | delete [] m_bCamParPresent; |
---|
1977 | } |
---|
1978 | if ( m_bCamParInSliceHeader != NULL ) |
---|
1979 | { |
---|
1980 | delete [] m_bCamParInSliceHeader; |
---|
1981 | } |
---|
1982 | |
---|
1983 | if ( m_aaaiCodedScale != NULL ) |
---|
1984 | { |
---|
1985 | for ( i = 0; i < iNumViews ; i++ ) |
---|
1986 | { |
---|
1987 | for ( j = 0; j < 2; j++ ) |
---|
1988 | { |
---|
1989 | delete [] m_aaaiCodedScale[i][j]; |
---|
1990 | } |
---|
1991 | delete [] m_aaaiCodedScale[i]; |
---|
1992 | } |
---|
1993 | delete [] m_aaaiCodedScale; |
---|
1994 | } |
---|
1995 | |
---|
1996 | if ( m_aaaiCodedOffset != NULL ) |
---|
1997 | { |
---|
1998 | for ( i = 0; i < iNumViews ; i++ ) |
---|
1999 | { |
---|
2000 | for ( j = 0; j < 2; j++ ) |
---|
2001 | { |
---|
2002 | delete [] m_aaaiCodedOffset[i][j]; |
---|
2003 | } |
---|
2004 | delete [] m_aaaiCodedOffset[i]; |
---|
2005 | } |
---|
2006 | delete [] m_aaaiCodedOffset; |
---|
2007 | } |
---|
2008 | } |
---|
2009 | |
---|
2010 | |
---|
2011 | Void |
---|
2012 | TComVPS::initCamParaVPS( UInt uiViewIndex, Bool bCamParPresent, UInt uiCamParPrecision, Bool bCamParSlice, Int** aaiScale, Int** aaiOffset ) |
---|
2013 | { |
---|
2014 | AOT( uiViewIndex != 0 && !bCamParSlice && ( aaiScale == 0 || aaiOffset == 0 ) ); |
---|
2015 | |
---|
2016 | m_uiCamParPrecision = ( ( uiViewIndex != 0 )? uiCamParPrecision : 0 ); |
---|
2017 | m_bCamParPresent[ uiViewIndex ] = (( uiViewIndex != 0 )? bCamParPresent : false ); |
---|
2018 | m_bCamParInSliceHeader[ uiViewIndex ] = ( (uiViewIndex != 0)? bCamParSlice : false ); |
---|
2019 | |
---|
2020 | if( !m_bCamParInSliceHeader[ uiViewIndex ] ) |
---|
2021 | { |
---|
2022 | for( UInt uiBaseViewIndex = 0; uiBaseViewIndex < uiViewIndex; uiBaseViewIndex++ ) |
---|
2023 | { |
---|
2024 | m_aaaiCodedScale [ uiViewIndex ][ 0 ][ uiBaseViewIndex ] = aaiScale [ uiBaseViewIndex ][ uiViewIndex ]; |
---|
2025 | m_aaaiCodedScale [ uiViewIndex ][ 1 ][ uiBaseViewIndex ] = aaiScale [ uiViewIndex ][ uiBaseViewIndex ]; |
---|
2026 | m_aaaiCodedOffset[ uiViewIndex ][ 0 ][ uiBaseViewIndex ] = aaiOffset[ uiBaseViewIndex ][ uiViewIndex ]; |
---|
2027 | m_aaaiCodedOffset[ uiViewIndex ][ 1 ][ uiBaseViewIndex ] = aaiOffset[ uiViewIndex ][ uiBaseViewIndex ]; |
---|
2028 | } |
---|
2029 | } |
---|
2030 | } |
---|
2031 | |
---|
2032 | #endif // H_3D |
---|
2033 | |
---|
2034 | |
---|
2035 | Int TComVPS::xGetDimBitOffset( Int j ) |
---|
2036 | { |
---|
2037 | Int dimBitOffset = 0; |
---|
2038 | if ( getSplittingFlag() && j == getNumScalabilityTypes() ) |
---|
2039 | { |
---|
2040 | dimBitOffset = 6; |
---|
2041 | } |
---|
2042 | else |
---|
2043 | { |
---|
2044 | for (Int dimIdx = 0; dimIdx <= j-1; dimIdx++) |
---|
2045 | { |
---|
2046 | dimBitOffset += getDimensionIdLen( dimIdx ); |
---|
2047 | } |
---|
2048 | } |
---|
2049 | return dimBitOffset; |
---|
2050 | } |
---|
2051 | |
---|
2052 | Int TComVPS::inferDimensionId( Int i, Int j ) |
---|
2053 | { |
---|
2054 | return ( ( getLayerIdInNuh( i ) & ( (1 << xGetDimBitOffset( j + 1 ) ) - 1) ) >> xGetDimBitOffset( j ) ); |
---|
2055 | } |
---|
2056 | |
---|
2057 | Int TComVPS::inferLastDimsionIdLenMinus1() |
---|
2058 | { |
---|
2059 | return ( 5 - xGetDimBitOffset( getNumScalabilityTypes() - 1 ) ); |
---|
2060 | } |
---|
2061 | |
---|
2062 | Int TComVPS::getNumLayersInIdList( Int lsIdx ) |
---|
2063 | { |
---|
2064 | assert( lsIdx >= 0 ); |
---|
2065 | assert( lsIdx <= getVpsNumLayerSetsMinus1() ); |
---|
2066 | return (Int) m_layerSetLayerIdList[ lsIdx ].size(); |
---|
2067 | } |
---|
2068 | |
---|
2069 | Int TComVPS::getNumOutputLayerSets() |
---|
2070 | { |
---|
2071 | Int numOutputLayerSets = getVpsNumberLayerSetsMinus1( ) + 1; |
---|
2072 | if ( getMoreOutputLayerSetsThanDefaultFlag( ) ) |
---|
2073 | { |
---|
2074 | numOutputLayerSets += (getNumAddOutputLayerSetsMinus1( ) + 1); |
---|
2075 | } |
---|
2076 | return numOutputLayerSets; |
---|
2077 | } |
---|
2078 | |
---|
2079 | Int TComVPS::getNumViews() |
---|
2080 | { |
---|
2081 | Int numViews = 1; |
---|
2082 | for( Int i = 0; i <= getMaxLayersMinus1(); i++ ) |
---|
2083 | { |
---|
2084 | Int lId = getLayerIdInNuh( i ); |
---|
2085 | if ( i > 0 && ( getViewIndex( lId ) != getScalabilityId( i - 1, VIEW_ORDER_INDEX ) ) ) |
---|
2086 | { |
---|
2087 | numViews++; |
---|
2088 | } |
---|
2089 | } |
---|
2090 | |
---|
2091 | return numViews; |
---|
2092 | } |
---|
2093 | |
---|
2094 | Bool TComVPS::getInDirectDependencyFlag( Int depLayeridInVps, Int refLayeridInVps, Int depth /*= 0 */ ) |
---|
2095 | { |
---|
2096 | assert( depth < 65 ); |
---|
2097 | Bool dependentFlag = getDirectDependencyFlag( depLayeridInVps, refLayeridInVps ); |
---|
2098 | |
---|
2099 | for( Int i = 0; i < depLayeridInVps && !dependentFlag; i++ ) |
---|
2100 | { |
---|
2101 | if ( getDirectDependencyFlag( depLayeridInVps, i ) ) |
---|
2102 | { |
---|
2103 | dependentFlag = getInDirectDependencyFlag( i, refLayeridInVps, depth++ ); |
---|
2104 | } |
---|
2105 | } |
---|
2106 | return dependentFlag; |
---|
2107 | } |
---|
2108 | |
---|
2109 | Void TComVPS::deriveLayerSetLayerIdList() |
---|
2110 | { |
---|
2111 | m_layerSetLayerIdList.resize( getVpsNumLayerSetsMinus1() + 1 ); |
---|
2112 | for (Int i = 0; i <= getVpsNumLayerSetsMinus1(); i++ ) |
---|
2113 | { |
---|
2114 | for( Int m = 0; m <= getVpsMaxLayerId(); m++ ) |
---|
2115 | { |
---|
2116 | if( getLayerIdIncludedFlag( i, m) ) |
---|
2117 | { |
---|
2118 | m_layerSetLayerIdList[ i ].push_back( m ); |
---|
2119 | } |
---|
2120 | } |
---|
2121 | } |
---|
2122 | } |
---|
2123 | |
---|
2124 | Void TComVPS::deriveTargetLayerIdLists() |
---|
2125 | { |
---|
2126 | m_targetDecLayerIdLists.resize( getNumOutputLayerSets() ); |
---|
2127 | m_targetOptLayerIdLists.resize( getNumOutputLayerSets() ); |
---|
2128 | |
---|
2129 | for (Int targetOptLayerSetIdx = 0; targetOptLayerSetIdx < getNumOutputLayerSets(); targetOptLayerSetIdx++ ) |
---|
2130 | { |
---|
2131 | Int targetDecLayerSetIdx = getOutputLayerSetIdxMinus1( targetOptLayerSetIdx ) + 1; |
---|
2132 | Int lsIdx = targetDecLayerSetIdx; |
---|
2133 | |
---|
2134 | for( Int j = 0; j < getNumLayersInIdList( lsIdx ); j++ ) |
---|
2135 | { |
---|
2136 | m_targetDecLayerIdLists[targetOptLayerSetIdx].push_back( m_layerSetLayerIdList[ lsIdx ][ j ] ); |
---|
2137 | if( getOutputLayerFlag( targetOptLayerSetIdx, j )) // This seems to be wrong in draft text |
---|
2138 | { |
---|
2139 | m_targetOptLayerIdLists[targetOptLayerSetIdx].push_back( m_layerSetLayerIdList[ lsIdx ][ j ] ); |
---|
2140 | } |
---|
2141 | } |
---|
2142 | } |
---|
2143 | } |
---|
2144 | #endif // H_MV |
---|
2145 | |
---|
2146 | // ------------------------------------------------------------------------------------------------ |
---|
2147 | // Sequence parameter set (SPS) |
---|
2148 | // ------------------------------------------------------------------------------------------------ |
---|
2149 | |
---|
2150 | TComSPS::TComSPS() |
---|
2151 | : m_SPSId ( 0) |
---|
2152 | , m_VPSId ( 0) |
---|
2153 | , m_chromaFormatIdc (CHROMA_420) |
---|
2154 | , m_uiMaxTLayers ( 1) |
---|
2155 | // Structure |
---|
2156 | , m_picWidthInLumaSamples (352) |
---|
2157 | , m_picHeightInLumaSamples (288) |
---|
2158 | , m_log2MinCodingBlockSize ( 0) |
---|
2159 | , m_log2DiffMaxMinCodingBlockSize (0) |
---|
2160 | , m_uiMaxCUWidth ( 32) |
---|
2161 | , m_uiMaxCUHeight ( 32) |
---|
2162 | , m_uiMaxCUDepth ( 3) |
---|
2163 | , m_bLongTermRefsPresent (false) |
---|
2164 | , m_uiQuadtreeTULog2MaxSize ( 0) |
---|
2165 | , m_uiQuadtreeTULog2MinSize ( 0) |
---|
2166 | , m_uiQuadtreeTUMaxDepthInter ( 0) |
---|
2167 | , m_uiQuadtreeTUMaxDepthIntra ( 0) |
---|
2168 | // Tool list |
---|
2169 | , m_usePCM (false) |
---|
2170 | , m_pcmLog2MaxSize ( 5) |
---|
2171 | , m_uiPCMLog2MinSize ( 7) |
---|
2172 | #if H_3D_QTLPC |
---|
2173 | , m_bUseQTL (false) |
---|
2174 | , m_bUsePC (false) |
---|
2175 | #endif |
---|
2176 | , m_bitDepthY ( 8) |
---|
2177 | , m_bitDepthC ( 8) |
---|
2178 | , m_qpBDOffsetY ( 0) |
---|
2179 | , m_qpBDOffsetC ( 0) |
---|
2180 | , m_useLossless (false) |
---|
2181 | , m_uiPCMBitDepthLuma ( 8) |
---|
2182 | , m_uiPCMBitDepthChroma ( 8) |
---|
2183 | , m_bPCMFilterDisableFlag (false) |
---|
2184 | , m_uiBitsForPOC ( 8) |
---|
2185 | , m_numLongTermRefPicSPS ( 0) |
---|
2186 | , m_uiMaxTrSize ( 32) |
---|
2187 | , m_bUseSAO (false) |
---|
2188 | , m_bTemporalIdNestingFlag (false) |
---|
2189 | , m_scalingListEnabledFlag (false) |
---|
2190 | , m_useStrongIntraSmoothing (false) |
---|
2191 | , m_vuiParametersPresentFlag (false) |
---|
2192 | , m_vuiParameters () |
---|
2193 | #if H_MV |
---|
2194 | , m_pcVPS ( NULL ) |
---|
2195 | , m_spsInferScalingListFlag ( false ) |
---|
2196 | , m_spsScalingListRefLayerId ( 0 ) |
---|
2197 | |
---|
2198 | , m_updateRepFormatFlag ( false ) |
---|
2199 | , m_spsRepFormatIdx ( 0 ) |
---|
2200 | , m_interViewMvVertConstraintFlag (false) |
---|
2201 | #endif |
---|
2202 | #if H_3D |
---|
2203 | , m_bCamParInSliceHeader (false) |
---|
2204 | #endif |
---|
2205 | { |
---|
2206 | for ( Int i = 0; i < MAX_TLAYER; i++ ) |
---|
2207 | { |
---|
2208 | m_uiMaxLatencyIncrease[i] = 0; |
---|
2209 | m_uiMaxDecPicBuffering[i] = 1; |
---|
2210 | m_numReorderPics[i] = 0; |
---|
2211 | } |
---|
2212 | m_scalingList = new TComScalingList; |
---|
2213 | ::memset(m_ltRefPicPocLsbSps, 0, sizeof(m_ltRefPicPocLsbSps)); |
---|
2214 | ::memset(m_usedByCurrPicLtSPSFlag, 0, sizeof(m_usedByCurrPicLtSPSFlag)); |
---|
2215 | #if H_MV |
---|
2216 | m_spsExtensionFlag = false; |
---|
2217 | for( Int i = 0; i < PS_EX_T_MAX_NUM; i++ ) |
---|
2218 | { |
---|
2219 | m_spsExtensionTypeFlag[ i ] = false; |
---|
2220 | } |
---|
2221 | m_numScaledRefLayerOffsets = 0; |
---|
2222 | |
---|
2223 | for (Int i = 0; i < MAX_NUM_SCALED_REF_LAYERS; i++ ) |
---|
2224 | { |
---|
2225 | m_scaledRefLayerId [i] = -1; |
---|
2226 | } |
---|
2227 | |
---|
2228 | for (Int i = 0; i < MAX_NUM_LAYERS; i++ ) |
---|
2229 | { |
---|
2230 | m_scaledRefLayerLeftOffset [i] = 0; |
---|
2231 | m_scaledRefLayerTopOffset [i] = 0; |
---|
2232 | m_scaledRefLayerRightOffset [i] = 0; |
---|
2233 | m_scaledRefLayerBottomOffset [i] = 0; |
---|
2234 | } |
---|
2235 | #endif |
---|
2236 | } |
---|
2237 | |
---|
2238 | TComSPS::~TComSPS() |
---|
2239 | { |
---|
2240 | delete m_scalingList; |
---|
2241 | m_RPSList.destroy(); |
---|
2242 | } |
---|
2243 | |
---|
2244 | Void TComSPS::createRPSList( Int numRPS ) |
---|
2245 | { |
---|
2246 | m_RPSList.destroy(); |
---|
2247 | m_RPSList.create(numRPS); |
---|
2248 | } |
---|
2249 | |
---|
2250 | Void TComSPS::setHrdParameters( UInt frameRate, UInt numDU, UInt bitRate, Bool randomAccess ) |
---|
2251 | { |
---|
2252 | if( !getVuiParametersPresentFlag() ) |
---|
2253 | { |
---|
2254 | return; |
---|
2255 | } |
---|
2256 | |
---|
2257 | TComVUI *vui = getVuiParameters(); |
---|
2258 | TComHRD *hrd = vui->getHrdParameters(); |
---|
2259 | |
---|
2260 | TimingInfo *timingInfo = vui->getTimingInfo(); |
---|
2261 | timingInfo->setTimingInfoPresentFlag( true ); |
---|
2262 | switch( frameRate ) |
---|
2263 | { |
---|
2264 | case 24: |
---|
2265 | timingInfo->setNumUnitsInTick( 1125000 ); timingInfo->setTimeScale ( 27000000 ); |
---|
2266 | break; |
---|
2267 | case 25: |
---|
2268 | timingInfo->setNumUnitsInTick( 1080000 ); timingInfo->setTimeScale ( 27000000 ); |
---|
2269 | break; |
---|
2270 | case 30: |
---|
2271 | timingInfo->setNumUnitsInTick( 900900 ); timingInfo->setTimeScale ( 27000000 ); |
---|
2272 | break; |
---|
2273 | case 50: |
---|
2274 | timingInfo->setNumUnitsInTick( 540000 ); timingInfo->setTimeScale ( 27000000 ); |
---|
2275 | break; |
---|
2276 | case 60: |
---|
2277 | timingInfo->setNumUnitsInTick( 450450 ); timingInfo->setTimeScale ( 27000000 ); |
---|
2278 | break; |
---|
2279 | default: |
---|
2280 | timingInfo->setNumUnitsInTick( 1001 ); timingInfo->setTimeScale ( 60000 ); |
---|
2281 | break; |
---|
2282 | } |
---|
2283 | |
---|
2284 | Bool rateCnt = ( bitRate > 0 ); |
---|
2285 | hrd->setNalHrdParametersPresentFlag( rateCnt ); |
---|
2286 | hrd->setVclHrdParametersPresentFlag( rateCnt ); |
---|
2287 | |
---|
2288 | hrd->setSubPicCpbParamsPresentFlag( ( numDU > 1 ) ); |
---|
2289 | |
---|
2290 | if( hrd->getSubPicCpbParamsPresentFlag() ) |
---|
2291 | { |
---|
2292 | hrd->setTickDivisorMinus2( 100 - 2 ); // |
---|
2293 | hrd->setDuCpbRemovalDelayLengthMinus1( 7 ); // 8-bit precision ( plus 1 for last DU in AU ) |
---|
2294 | hrd->setSubPicCpbParamsInPicTimingSEIFlag( true ); |
---|
2295 | hrd->setDpbOutputDelayDuLengthMinus1( 5 + 7 ); // With sub-clock tick factor of 100, at least 7 bits to have the same value as AU dpb delay |
---|
2296 | } |
---|
2297 | else |
---|
2298 | { |
---|
2299 | hrd->setSubPicCpbParamsInPicTimingSEIFlag( false ); |
---|
2300 | } |
---|
2301 | |
---|
2302 | hrd->setBitRateScale( 4 ); // in units of 2~( 6 + 4 ) = 1,024 bps |
---|
2303 | hrd->setCpbSizeScale( 6 ); // in units of 2~( 4 + 4 ) = 1,024 bit |
---|
2304 | hrd->setDuCpbSizeScale( 6 ); // in units of 2~( 4 + 4 ) = 1,024 bit |
---|
2305 | |
---|
2306 | hrd->setInitialCpbRemovalDelayLengthMinus1(15); // assuming 0.5 sec, log2( 90,000 * 0.5 ) = 16-bit |
---|
2307 | if( randomAccess ) |
---|
2308 | { |
---|
2309 | hrd->setCpbRemovalDelayLengthMinus1(5); // 32 = 2^5 (plus 1) |
---|
2310 | hrd->setDpbOutputDelayLengthMinus1 (5); // 32 + 3 = 2^6 |
---|
2311 | } |
---|
2312 | else |
---|
2313 | { |
---|
2314 | hrd->setCpbRemovalDelayLengthMinus1(9); // max. 2^10 |
---|
2315 | hrd->setDpbOutputDelayLengthMinus1 (9); // max. 2^10 |
---|
2316 | } |
---|
2317 | |
---|
2318 | /* |
---|
2319 | Note: only the case of "vps_max_temporal_layers_minus1 = 0" is supported. |
---|
2320 | */ |
---|
2321 | Int i, j; |
---|
2322 | UInt birateValue, cpbSizeValue; |
---|
2323 | UInt ducpbSizeValue; |
---|
2324 | UInt duBitRateValue = 0; |
---|
2325 | |
---|
2326 | for( i = 0; i < MAX_TLAYER; i ++ ) |
---|
2327 | { |
---|
2328 | hrd->setFixedPicRateFlag( i, 1 ); |
---|
2329 | hrd->setPicDurationInTcMinus1( i, 0 ); |
---|
2330 | hrd->setLowDelayHrdFlag( i, 0 ); |
---|
2331 | hrd->setCpbCntMinus1( i, 0 ); |
---|
2332 | |
---|
2333 | birateValue = bitRate; |
---|
2334 | cpbSizeValue = bitRate; // 1 second |
---|
2335 | ducpbSizeValue = bitRate/numDU; |
---|
2336 | duBitRateValue = bitRate; |
---|
2337 | for( j = 0; j < ( hrd->getCpbCntMinus1( i ) + 1 ); j ++ ) |
---|
2338 | { |
---|
2339 | hrd->setBitRateValueMinus1( i, j, 0, ( birateValue - 1 ) ); |
---|
2340 | hrd->setCpbSizeValueMinus1( i, j, 0, ( cpbSizeValue - 1 ) ); |
---|
2341 | hrd->setDuCpbSizeValueMinus1( i, j, 0, ( ducpbSizeValue - 1 ) ); |
---|
2342 | hrd->setCbrFlag( i, j, 0, ( j == 0 ) ); |
---|
2343 | |
---|
2344 | hrd->setBitRateValueMinus1( i, j, 1, ( birateValue - 1) ); |
---|
2345 | hrd->setCpbSizeValueMinus1( i, j, 1, ( cpbSizeValue - 1 ) ); |
---|
2346 | hrd->setDuCpbSizeValueMinus1( i, j, 1, ( ducpbSizeValue - 1 ) ); |
---|
2347 | hrd->setDuBitRateValueMinus1( i, j, 1, ( duBitRateValue - 1 ) ); |
---|
2348 | hrd->setCbrFlag( i, j, 1, ( j == 0 ) ); |
---|
2349 | } |
---|
2350 | } |
---|
2351 | } |
---|
2352 | const Int TComSPS::m_winUnitX[]={1,2,2,1}; |
---|
2353 | const Int TComSPS::m_winUnitY[]={1,2,1,1}; |
---|
2354 | |
---|
2355 | TComPPS::TComPPS() |
---|
2356 | : m_PPSId (0) |
---|
2357 | , m_SPSId (0) |
---|
2358 | , m_picInitQPMinus26 (0) |
---|
2359 | , m_useDQP (false) |
---|
2360 | , m_bConstrainedIntraPred (false) |
---|
2361 | , m_bSliceChromaQpFlag (false) |
---|
2362 | , m_pcSPS (NULL) |
---|
2363 | , m_uiMaxCuDQPDepth (0) |
---|
2364 | , m_uiMinCuDQPSize (0) |
---|
2365 | , m_chromaCbQpOffset (0) |
---|
2366 | , m_chromaCrQpOffset (0) |
---|
2367 | , m_numRefIdxL0DefaultActive (1) |
---|
2368 | , m_numRefIdxL1DefaultActive (1) |
---|
2369 | , m_TransquantBypassEnableFlag (false) |
---|
2370 | , m_useTransformSkip (false) |
---|
2371 | , m_dependentSliceSegmentsEnabledFlag (false) |
---|
2372 | , m_tilesEnabledFlag (false) |
---|
2373 | , m_entropyCodingSyncEnabledFlag (false) |
---|
2374 | , m_loopFilterAcrossTilesEnabledFlag (true) |
---|
2375 | , m_uniformSpacingFlag (0) |
---|
2376 | , m_iNumColumnsMinus1 (0) |
---|
2377 | , m_puiColumnWidth (NULL) |
---|
2378 | , m_iNumRowsMinus1 (0) |
---|
2379 | , m_puiRowHeight (NULL) |
---|
2380 | , m_iNumSubstreams (1) |
---|
2381 | , m_signHideFlag(0) |
---|
2382 | , m_cabacInitPresentFlag (false) |
---|
2383 | , m_encCABACTableIdx (I_SLICE) |
---|
2384 | , m_sliceHeaderExtensionPresentFlag (false) |
---|
2385 | , m_loopFilterAcrossSlicesEnabledFlag (false) |
---|
2386 | , m_listsModificationPresentFlag( 0) |
---|
2387 | , m_numExtraSliceHeaderBits(0) |
---|
2388 | #if H_MV |
---|
2389 | , m_ppsInferScalingListFlag(false) |
---|
2390 | , m_ppsScalingListRefLayerId(0) |
---|
2391 | #if H_3D |
---|
2392 | , m_pcDLT(NULL) |
---|
2393 | #endif |
---|
2394 | #endif |
---|
2395 | { |
---|
2396 | m_scalingList = new TComScalingList; |
---|
2397 | } |
---|
2398 | |
---|
2399 | TComPPS::~TComPPS() |
---|
2400 | { |
---|
2401 | if( m_iNumColumnsMinus1 > 0 && m_uniformSpacingFlag == 0 ) |
---|
2402 | { |
---|
2403 | if (m_puiColumnWidth) delete [] m_puiColumnWidth; |
---|
2404 | m_puiColumnWidth = NULL; |
---|
2405 | } |
---|
2406 | if( m_iNumRowsMinus1 > 0 && m_uniformSpacingFlag == 0 ) |
---|
2407 | { |
---|
2408 | if (m_puiRowHeight) delete [] m_puiRowHeight; |
---|
2409 | m_puiRowHeight = NULL; |
---|
2410 | } |
---|
2411 | delete m_scalingList; |
---|
2412 | } |
---|
2413 | |
---|
2414 | #if H_3D |
---|
2415 | TComDLT::TComDLT() |
---|
2416 | : m_bDltPresentFlag(false) |
---|
2417 | , m_iNumDepthViews(0) |
---|
2418 | , m_uiDepthViewBitDepth(8) |
---|
2419 | { |
---|
2420 | m_uiDepthViewBitDepth = g_bitDepthY; |
---|
2421 | |
---|
2422 | for( Int i = 0; i < MAX_NUM_LAYERS; i++ ) |
---|
2423 | { |
---|
2424 | m_bUseDLTFlag [i] = false; |
---|
2425 | m_bInterViewDltPredEnableFlag [i] = false; |
---|
2426 | |
---|
2427 | // allocate some memory and initialize with default mapping |
---|
2428 | m_iNumDepthmapValues[i] = ((1 << m_uiDepthViewBitDepth)-1)+1; |
---|
2429 | m_iBitsPerDepthValue[i] = numBitsForValue(m_iNumDepthmapValues[i]); |
---|
2430 | |
---|
2431 | m_iDepthValue2Idx[i] = (Int*) xMalloc(Int, m_iNumDepthmapValues[i]); |
---|
2432 | m_iIdx2DepthValue[i] = (Int*) xMalloc(Int, m_iNumDepthmapValues[i]); |
---|
2433 | |
---|
2434 | //default mapping |
---|
2435 | for (Int d=0; d<m_iNumDepthmapValues[i]; d++) |
---|
2436 | { |
---|
2437 | m_iDepthValue2Idx[i][d] = d; |
---|
2438 | m_iIdx2DepthValue[i][d] = d; |
---|
2439 | } |
---|
2440 | } |
---|
2441 | } |
---|
2442 | |
---|
2443 | TComDLT::~TComDLT() |
---|
2444 | { |
---|
2445 | for( Int i = 0; i < MAX_NUM_LAYERS; i++ ) |
---|
2446 | { |
---|
2447 | if ( m_iDepthValue2Idx[i] != NULL ) |
---|
2448 | { |
---|
2449 | xFree( m_iDepthValue2Idx[i] ); |
---|
2450 | m_iDepthValue2Idx[i] = NULL; |
---|
2451 | } |
---|
2452 | |
---|
2453 | if ( m_iIdx2DepthValue[i] != NULL ) |
---|
2454 | { |
---|
2455 | xFree( m_iIdx2DepthValue[i] ); |
---|
2456 | m_iIdx2DepthValue[i] = NULL; |
---|
2457 | } |
---|
2458 | } |
---|
2459 | } |
---|
2460 | |
---|
2461 | Void TComDLT::setDepthLUTs(Int layerIdInVps, Int* idxToDepthValueTable, Int iNumDepthValues) |
---|
2462 | { |
---|
2463 | if( idxToDepthValueTable == NULL || iNumDepthValues == 0 ) // default mapping only |
---|
2464 | return; |
---|
2465 | |
---|
2466 | // copy idx2DepthValue to internal array |
---|
2467 | memcpy(m_iIdx2DepthValue[layerIdInVps], idxToDepthValueTable, iNumDepthValues*sizeof(UInt)); |
---|
2468 | |
---|
2469 | UInt uiMaxDepthValue = ((1 << g_bitDepthY)-1); |
---|
2470 | for(Int p=0; p<=uiMaxDepthValue; p++) |
---|
2471 | { |
---|
2472 | Int iIdxDown = 0; |
---|
2473 | Int iIdxUp = iNumDepthValues-1; |
---|
2474 | Bool bFound = false; |
---|
2475 | |
---|
2476 | // iterate over indices to find lower closest depth |
---|
2477 | Int i = 1; |
---|
2478 | while(!bFound && i<iNumDepthValues) |
---|
2479 | { |
---|
2480 | if( m_iIdx2DepthValue[layerIdInVps][i] > p ) |
---|
2481 | { |
---|
2482 | iIdxDown = i-1; |
---|
2483 | bFound = true; |
---|
2484 | } |
---|
2485 | |
---|
2486 | i++; |
---|
2487 | } |
---|
2488 | // iterate over indices to find upper closest depth |
---|
2489 | i = iNumDepthValues-2; |
---|
2490 | bFound = false; |
---|
2491 | while(!bFound && i>=0) |
---|
2492 | { |
---|
2493 | if( m_iIdx2DepthValue[layerIdInVps][i] < p ) |
---|
2494 | { |
---|
2495 | iIdxUp = i+1; |
---|
2496 | bFound = true; |
---|
2497 | } |
---|
2498 | |
---|
2499 | i--; |
---|
2500 | } |
---|
2501 | |
---|
2502 | // assert monotony |
---|
2503 | assert(iIdxDown<=iIdxUp); |
---|
2504 | |
---|
2505 | // assign closer depth value/idx |
---|
2506 | if( abs(p-m_iIdx2DepthValue[layerIdInVps][iIdxDown]) < abs(p-m_iIdx2DepthValue[layerIdInVps][iIdxUp]) ) |
---|
2507 | { |
---|
2508 | m_iDepthValue2Idx[layerIdInVps][p] = iIdxDown; |
---|
2509 | } |
---|
2510 | else |
---|
2511 | { |
---|
2512 | m_iDepthValue2Idx[layerIdInVps][p] = iIdxUp; |
---|
2513 | } |
---|
2514 | |
---|
2515 | } |
---|
2516 | |
---|
2517 | // update DLT variables |
---|
2518 | m_iNumDepthmapValues[layerIdInVps] = iNumDepthValues; |
---|
2519 | m_iBitsPerDepthValue[layerIdInVps] = numBitsForValue(m_iNumDepthmapValues[layerIdInVps]); |
---|
2520 | } |
---|
2521 | |
---|
2522 | #if H_3D_DELTA_DLT |
---|
2523 | Void TComDLT::getDeltaDLT( Int layerIdInVps, Int* piDLTInRef, UInt uiDLTInRefNum, Int* piDeltaDLTOut, UInt *puiDeltaDLTOutNum ) |
---|
2524 | { |
---|
2525 | Bool abBM0[ 256 ]; |
---|
2526 | Bool abBM1[ 256 ]; |
---|
2527 | |
---|
2528 | memset( abBM0, 0, sizeof( abBM0 )); |
---|
2529 | memset( abBM1, 0, sizeof( abBM1 )); |
---|
2530 | |
---|
2531 | // convert reference DLT to bit string |
---|
2532 | for( Int i = 0; i < uiDLTInRefNum; i++ ) |
---|
2533 | { |
---|
2534 | abBM0[ piDLTInRef[ i ] ] = true; |
---|
2535 | } |
---|
2536 | // convert internal DLT to bit string |
---|
2537 | for( Int i = 0; i < m_iNumDepthmapValues[ layerIdInVps ]; i++ ) |
---|
2538 | { |
---|
2539 | abBM1[ m_iIdx2DepthValue[ layerIdInVps ][ i ] ] = true; |
---|
2540 | } |
---|
2541 | |
---|
2542 | *puiDeltaDLTOutNum = 0; |
---|
2543 | for( Int i = 0; i < 256; i++ ) |
---|
2544 | { |
---|
2545 | if( abBM0[ i ] ^ abBM1[ i ] ) |
---|
2546 | { |
---|
2547 | piDeltaDLTOut[ *puiDeltaDLTOutNum ] = i; |
---|
2548 | *puiDeltaDLTOutNum = *puiDeltaDLTOutNum + 1; |
---|
2549 | } |
---|
2550 | } |
---|
2551 | } |
---|
2552 | |
---|
2553 | Void TComDLT::setDeltaDLT( Int layerIdInVps, Int* piDLTInRef, UInt uiDLTInRefNum, Int* piDeltaDLTIn, UInt uiDeltaDLTInNum ) |
---|
2554 | { |
---|
2555 | Bool abBM0[ 256 ]; |
---|
2556 | Bool abBM1[ 256 ]; |
---|
2557 | |
---|
2558 | memset( abBM0, 0, sizeof( abBM0 )); |
---|
2559 | memset( abBM1, 0, sizeof( abBM1 )); |
---|
2560 | |
---|
2561 | // convert reference DLT to bit string |
---|
2562 | for( Int i = 0; i < uiDLTInRefNum; i++ ) |
---|
2563 | { |
---|
2564 | abBM0[ piDLTInRef[ i ] ] = true; |
---|
2565 | } |
---|
2566 | // convert delta DLT to bit string |
---|
2567 | for( Int i = 0; i < uiDeltaDLTInNum; i++ ) |
---|
2568 | { |
---|
2569 | abBM1[ piDeltaDLTIn[ i ] ] = true; |
---|
2570 | } |
---|
2571 | |
---|
2572 | Int aiIdx2DepthValue[256]; |
---|
2573 | UInt uiNumDepthValues = 0; |
---|
2574 | memset( aiIdx2DepthValue, 0, sizeof( aiIdx2DepthValue )); |
---|
2575 | |
---|
2576 | for( Int i = 0; i < 256; i++ ) |
---|
2577 | { |
---|
2578 | if( abBM0[ i ] ^ abBM1[ i ] ) |
---|
2579 | { |
---|
2580 | aiIdx2DepthValue[ uiNumDepthValues++ ] = i; |
---|
2581 | } |
---|
2582 | } |
---|
2583 | |
---|
2584 | // update internal tables |
---|
2585 | setDepthLUTs(layerIdInVps, aiIdx2DepthValue, uiNumDepthValues); |
---|
2586 | } |
---|
2587 | #endif |
---|
2588 | |
---|
2589 | #endif |
---|
2590 | |
---|
2591 | #if H_MV |
---|
2592 | Void TComSPS::inferRepFormat( TComVPS* vps, Int layerIdCurr ) |
---|
2593 | { |
---|
2594 | if ( layerIdCurr > 0 ) |
---|
2595 | { |
---|
2596 | Int repFormatIdx = getUpdateRepFormatFlag() ? getSpsRepFormatIdx() : vps->getVpsRepFormatIdx( vps->getLayerIdInVps( layerIdCurr ) ) ; |
---|
2597 | TComRepFormat* repFormat = vps->getRepFormat( repFormatIdx ); |
---|
2598 | setChromaFormatIdc( repFormat->getChromaFormatVpsIdc() ); |
---|
2599 | //// ToDo: add when supported: |
---|
2600 | // setSeperateColourPlaneFlag( repFormat->getSeparateColourPlaneVpsFlag() ) ; |
---|
2601 | |
---|
2602 | setPicWidthInLumaSamples ( repFormat->getPicWidthVpsInLumaSamples() ); |
---|
2603 | setPicHeightInLumaSamples( repFormat->getPicHeightVpsInLumaSamples() ); |
---|
2604 | |
---|
2605 | setBitDepthY ( repFormat->getBitDepthVpsLumaMinus8() + 8 ); |
---|
2606 | setQpBDOffsetY ( (Int) (6*( getBitDepthY() - 8 )) ); |
---|
2607 | |
---|
2608 | setBitDepthC ( repFormat->getBitDepthVpsChromaMinus8() + 8 ); |
---|
2609 | setQpBDOffsetC ( (Int) (6* ( getBitDepthC() -8 ) ) ); |
---|
2610 | if ( getLayerId() > 0 && getUpdateRepFormatFlag() ) |
---|
2611 | { |
---|
2612 | assert( getChromaFormatIdc() <= repFormat->getChromaFormatVpsIdc() ); |
---|
2613 | //// ToDo: add when supported: |
---|
2614 | // assert( getSeperateColourPlaneFlag() <= repFormat->getSeparateColourPlaneVpsFlag() ) ; |
---|
2615 | |
---|
2616 | assert( getPicWidthInLumaSamples() <= repFormat->getPicWidthVpsInLumaSamples() ); |
---|
2617 | assert( getPicHeightInLumaSamples() <= repFormat->getPicHeightVpsInLumaSamples() ); |
---|
2618 | |
---|
2619 | assert( getBitDepthY() <= repFormat->getBitDepthVpsLumaMinus8() + 8 ); |
---|
2620 | assert( getBitDepthC() <= repFormat->getBitDepthVpsChromaMinus8() + 8 ); |
---|
2621 | } |
---|
2622 | } |
---|
2623 | |
---|
2624 | // Set conformance window |
---|
2625 | Int scal = TComSPS::getWinUnitX( getChromaFormatIdc() ) ; |
---|
2626 | getConformanceWindow().scaleOffsets( scal ); |
---|
2627 | getVuiParameters()->getDefaultDisplayWindow().scaleOffsets( scal ); |
---|
2628 | } |
---|
2629 | |
---|
2630 | Void TComSPS::inferScalingList( TComSPS* spsSrc ) |
---|
2631 | { |
---|
2632 | if ( getSpsInferScalingListFlag() ) |
---|
2633 | { |
---|
2634 | assert( spsSrc != NULL ); |
---|
2635 | assert( !spsSrc->getSpsInferScalingListFlag() ); |
---|
2636 | getScalingList()->inferFrom( spsSrc->getScalingList() ); |
---|
2637 | } |
---|
2638 | } |
---|
2639 | #endif |
---|
2640 | |
---|
2641 | TComReferencePictureSet::TComReferencePictureSet() |
---|
2642 | : m_numberOfPictures (0) |
---|
2643 | , m_numberOfNegativePictures (0) |
---|
2644 | , m_numberOfPositivePictures (0) |
---|
2645 | , m_numberOfLongtermPictures (0) |
---|
2646 | , m_interRPSPrediction (0) |
---|
2647 | , m_deltaRIdxMinus1 (0) |
---|
2648 | , m_deltaRPS (0) |
---|
2649 | , m_numRefIdc (0) |
---|
2650 | { |
---|
2651 | ::memset( m_deltaPOC, 0, sizeof(m_deltaPOC) ); |
---|
2652 | ::memset( m_POC, 0, sizeof(m_POC) ); |
---|
2653 | ::memset( m_used, 0, sizeof(m_used) ); |
---|
2654 | ::memset( m_refIdc, 0, sizeof(m_refIdc) ); |
---|
2655 | } |
---|
2656 | |
---|
2657 | TComReferencePictureSet::~TComReferencePictureSet() |
---|
2658 | { |
---|
2659 | } |
---|
2660 | |
---|
2661 | Void TComReferencePictureSet::setUsed(Int bufferNum, Bool used) |
---|
2662 | { |
---|
2663 | m_used[bufferNum] = used; |
---|
2664 | } |
---|
2665 | |
---|
2666 | Void TComReferencePictureSet::setDeltaPOC(Int bufferNum, Int deltaPOC) |
---|
2667 | { |
---|
2668 | m_deltaPOC[bufferNum] = deltaPOC; |
---|
2669 | } |
---|
2670 | |
---|
2671 | Void TComReferencePictureSet::setNumberOfPictures(Int numberOfPictures) |
---|
2672 | { |
---|
2673 | m_numberOfPictures = numberOfPictures; |
---|
2674 | } |
---|
2675 | |
---|
2676 | Int TComReferencePictureSet::getUsed(Int bufferNum) |
---|
2677 | { |
---|
2678 | return m_used[bufferNum]; |
---|
2679 | } |
---|
2680 | |
---|
2681 | Int TComReferencePictureSet::getDeltaPOC(Int bufferNum) |
---|
2682 | { |
---|
2683 | return m_deltaPOC[bufferNum]; |
---|
2684 | } |
---|
2685 | |
---|
2686 | Int TComReferencePictureSet::getNumberOfPictures() |
---|
2687 | { |
---|
2688 | return m_numberOfPictures; |
---|
2689 | } |
---|
2690 | |
---|
2691 | Int TComReferencePictureSet::getPOC(Int bufferNum) |
---|
2692 | { |
---|
2693 | return m_POC[bufferNum]; |
---|
2694 | } |
---|
2695 | |
---|
2696 | Void TComReferencePictureSet::setPOC(Int bufferNum, Int POC) |
---|
2697 | { |
---|
2698 | m_POC[bufferNum] = POC; |
---|
2699 | } |
---|
2700 | |
---|
2701 | Bool TComReferencePictureSet::getCheckLTMSBPresent(Int bufferNum) |
---|
2702 | { |
---|
2703 | return m_bCheckLTMSB[bufferNum]; |
---|
2704 | } |
---|
2705 | |
---|
2706 | Void TComReferencePictureSet::setCheckLTMSBPresent(Int bufferNum, Bool b) |
---|
2707 | { |
---|
2708 | m_bCheckLTMSB[bufferNum] = b; |
---|
2709 | } |
---|
2710 | |
---|
2711 | /** set the reference idc value at uiBufferNum entry to the value of iRefIdc |
---|
2712 | * \param uiBufferNum |
---|
2713 | * \param iRefIdc |
---|
2714 | * \returns Void |
---|
2715 | */ |
---|
2716 | Void TComReferencePictureSet::setRefIdc(Int bufferNum, Int refIdc) |
---|
2717 | { |
---|
2718 | m_refIdc[bufferNum] = refIdc; |
---|
2719 | } |
---|
2720 | |
---|
2721 | /** get the reference idc value at uiBufferNum |
---|
2722 | * \param uiBufferNum |
---|
2723 | * \returns Int |
---|
2724 | */ |
---|
2725 | Int TComReferencePictureSet::getRefIdc(Int bufferNum) |
---|
2726 | { |
---|
2727 | return m_refIdc[bufferNum]; |
---|
2728 | } |
---|
2729 | |
---|
2730 | /** Sorts the deltaPOC and Used by current values in the RPS based on the deltaPOC values. |
---|
2731 | * deltaPOC values are sorted with -ve values before the +ve values. -ve values are in decreasing order. |
---|
2732 | * +ve values are in increasing order. |
---|
2733 | * \returns Void |
---|
2734 | */ |
---|
2735 | Void TComReferencePictureSet::sortDeltaPOC() |
---|
2736 | { |
---|
2737 | // sort in increasing order (smallest first) |
---|
2738 | for(Int j=1; j < getNumberOfPictures(); j++) |
---|
2739 | { |
---|
2740 | Int deltaPOC = getDeltaPOC(j); |
---|
2741 | Bool used = getUsed(j); |
---|
2742 | for (Int k=j-1; k >= 0; k--) |
---|
2743 | { |
---|
2744 | Int temp = getDeltaPOC(k); |
---|
2745 | if (deltaPOC < temp) |
---|
2746 | { |
---|
2747 | setDeltaPOC(k+1, temp); |
---|
2748 | setUsed(k+1, getUsed(k)); |
---|
2749 | setDeltaPOC(k, deltaPOC); |
---|
2750 | setUsed(k, used); |
---|
2751 | } |
---|
2752 | } |
---|
2753 | } |
---|
2754 | // flip the negative values to largest first |
---|
2755 | Int numNegPics = getNumberOfNegativePictures(); |
---|
2756 | for(Int j=0, k=numNegPics-1; j < numNegPics>>1; j++, k--) |
---|
2757 | { |
---|
2758 | Int deltaPOC = getDeltaPOC(j); |
---|
2759 | Bool used = getUsed(j); |
---|
2760 | setDeltaPOC(j, getDeltaPOC(k)); |
---|
2761 | setUsed(j, getUsed(k)); |
---|
2762 | setDeltaPOC(k, deltaPOC); |
---|
2763 | setUsed(k, used); |
---|
2764 | } |
---|
2765 | } |
---|
2766 | |
---|
2767 | /** Prints the deltaPOC and RefIdc (if available) values in the RPS. |
---|
2768 | * A "*" is added to the deltaPOC value if it is Used bu current. |
---|
2769 | * \returns Void |
---|
2770 | */ |
---|
2771 | Void TComReferencePictureSet::printDeltaPOC() |
---|
2772 | { |
---|
2773 | printf("DeltaPOC = { "); |
---|
2774 | for(Int j=0; j < getNumberOfPictures(); j++) |
---|
2775 | { |
---|
2776 | printf("%d%s ", getDeltaPOC(j), (getUsed(j)==1)?"*":""); |
---|
2777 | } |
---|
2778 | if (getInterRPSPrediction()) |
---|
2779 | { |
---|
2780 | printf("}, RefIdc = { "); |
---|
2781 | for(Int j=0; j < getNumRefIdc(); j++) |
---|
2782 | { |
---|
2783 | printf("%d ", getRefIdc(j)); |
---|
2784 | } |
---|
2785 | } |
---|
2786 | printf("}\n"); |
---|
2787 | } |
---|
2788 | |
---|
2789 | TComRPSList::TComRPSList() |
---|
2790 | :m_referencePictureSets (NULL) |
---|
2791 | { |
---|
2792 | } |
---|
2793 | |
---|
2794 | TComRPSList::~TComRPSList() |
---|
2795 | { |
---|
2796 | } |
---|
2797 | |
---|
2798 | Void TComRPSList::create( Int numberOfReferencePictureSets) |
---|
2799 | { |
---|
2800 | m_numberOfReferencePictureSets = numberOfReferencePictureSets; |
---|
2801 | m_referencePictureSets = new TComReferencePictureSet[numberOfReferencePictureSets]; |
---|
2802 | } |
---|
2803 | |
---|
2804 | Void TComRPSList::destroy() |
---|
2805 | { |
---|
2806 | if (m_referencePictureSets) |
---|
2807 | { |
---|
2808 | delete [] m_referencePictureSets; |
---|
2809 | } |
---|
2810 | m_numberOfReferencePictureSets = 0; |
---|
2811 | m_referencePictureSets = NULL; |
---|
2812 | } |
---|
2813 | |
---|
2814 | |
---|
2815 | |
---|
2816 | TComReferencePictureSet* TComRPSList::getReferencePictureSet(Int referencePictureSetNum) |
---|
2817 | { |
---|
2818 | return &m_referencePictureSets[referencePictureSetNum]; |
---|
2819 | } |
---|
2820 | |
---|
2821 | Int TComRPSList::getNumberOfReferencePictureSets() |
---|
2822 | { |
---|
2823 | return m_numberOfReferencePictureSets; |
---|
2824 | } |
---|
2825 | |
---|
2826 | Void TComRPSList::setNumberOfReferencePictureSets(Int numberOfReferencePictureSets) |
---|
2827 | { |
---|
2828 | m_numberOfReferencePictureSets = numberOfReferencePictureSets; |
---|
2829 | } |
---|
2830 | |
---|
2831 | TComRefPicListModification::TComRefPicListModification() |
---|
2832 | : m_bRefPicListModificationFlagL0 (false) |
---|
2833 | , m_bRefPicListModificationFlagL1 (false) |
---|
2834 | { |
---|
2835 | ::memset( m_RefPicSetIdxL0, 0, sizeof(m_RefPicSetIdxL0) ); |
---|
2836 | ::memset( m_RefPicSetIdxL1, 0, sizeof(m_RefPicSetIdxL1) ); |
---|
2837 | } |
---|
2838 | |
---|
2839 | TComRefPicListModification::~TComRefPicListModification() |
---|
2840 | { |
---|
2841 | } |
---|
2842 | |
---|
2843 | TComScalingList::TComScalingList() |
---|
2844 | { |
---|
2845 | init(); |
---|
2846 | } |
---|
2847 | TComScalingList::~TComScalingList() |
---|
2848 | { |
---|
2849 | destroy(); |
---|
2850 | } |
---|
2851 | |
---|
2852 | /** set default quantization matrix to array |
---|
2853 | */ |
---|
2854 | Void TComSlice::setDefaultScalingList() |
---|
2855 | { |
---|
2856 | for(UInt sizeId = 0; sizeId < SCALING_LIST_SIZE_NUM; sizeId++) |
---|
2857 | { |
---|
2858 | for(UInt listId=0;listId<g_scalingListNum[sizeId];listId++) |
---|
2859 | { |
---|
2860 | getScalingList()->processDefaultMarix(sizeId, listId); |
---|
2861 | } |
---|
2862 | } |
---|
2863 | } |
---|
2864 | /** check if use default quantization matrix |
---|
2865 | * \returns true if use default quantization matrix in all size |
---|
2866 | */ |
---|
2867 | Bool TComSlice::checkDefaultScalingList() |
---|
2868 | { |
---|
2869 | UInt defaultCounter=0; |
---|
2870 | |
---|
2871 | for(UInt sizeId = 0; sizeId < SCALING_LIST_SIZE_NUM; sizeId++) |
---|
2872 | { |
---|
2873 | for(UInt listId=0;listId<g_scalingListNum[sizeId];listId++) |
---|
2874 | { |
---|
2875 | if( !memcmp(getScalingList()->getScalingListAddress(sizeId,listId), getScalingList()->getScalingListDefaultAddress(sizeId, listId),sizeof(Int)*min(MAX_MATRIX_COEF_NUM,(Int)g_scalingListSize[sizeId])) // check value of matrix |
---|
2876 | && ((sizeId < SCALING_LIST_16x16) || (getScalingList()->getScalingListDC(sizeId,listId) == 16))) // check DC value |
---|
2877 | { |
---|
2878 | defaultCounter++; |
---|
2879 | } |
---|
2880 | } |
---|
2881 | } |
---|
2882 | return (defaultCounter == (SCALING_LIST_NUM * SCALING_LIST_SIZE_NUM - 4)) ? false : true; // -4 for 32x32 |
---|
2883 | } |
---|
2884 | |
---|
2885 | #if H_MV |
---|
2886 | Void TComSlice::createInterLayerReferencePictureSet( TComPicLists* ivPicLists, std::vector<TComPic*>& refPicSetInterLayer0, std::vector<TComPic*>& refPicSetInterLayer1 ) |
---|
2887 | { |
---|
2888 | refPicSetInterLayer0.clear(); |
---|
2889 | refPicSetInterLayer1.clear(); |
---|
2890 | |
---|
2891 | for( Int i = 0; i < getNumActiveRefLayerPics(); i++ ) |
---|
2892 | { |
---|
2893 | Int layerIdRef = getRefPicLayerId( i ); |
---|
2894 | TComPic* picRef = ivPicLists->getPic( layerIdRef, getPOC() ) ; |
---|
2895 | assert ( picRef != 0 ); |
---|
2896 | |
---|
2897 | picRef->getPicYuvRec()->extendPicBorder(); |
---|
2898 | picRef->setIsLongTerm( true ); |
---|
2899 | picRef->getSlice(0)->setReferenced( true ); |
---|
2900 | |
---|
2901 | Int viewIdCur = getVPS()->getViewId( getLayerId() ); |
---|
2902 | Int viewIdZero = getVPS()->getViewId( 0 ); |
---|
2903 | Int viewIdRef = getVPS()->getViewId( layerIdRef ); |
---|
2904 | |
---|
2905 | if ( ( viewIdCur <= viewIdZero && viewIdCur <= viewIdRef ) || ( viewIdCur >= viewIdZero && viewIdCur >= viewIdRef ) ) |
---|
2906 | { |
---|
2907 | refPicSetInterLayer0.push_back( picRef ); |
---|
2908 | } |
---|
2909 | else |
---|
2910 | { |
---|
2911 | refPicSetInterLayer1.push_back( picRef ); |
---|
2912 | } |
---|
2913 | // Consider to check here: |
---|
2914 | // "If the current picture is a RADL picture, there shall be no entry in the RefPicSetInterLayer0 and RefPicSetInterLayer1 that is a RASL picture. " |
---|
2915 | } |
---|
2916 | } |
---|
2917 | |
---|
2918 | Void TComSlice::markIvRefPicsAsShortTerm( std::vector<TComPic*> refPicSetInterLayer0, std::vector<TComPic*> refPicSetInterLayer1 ) |
---|
2919 | { |
---|
2920 | // Mark as shortterm |
---|
2921 | for ( Int i = 0; i < refPicSetInterLayer0.size(); i++ ) |
---|
2922 | { |
---|
2923 | refPicSetInterLayer0[i]->setIsLongTerm( false ); |
---|
2924 | } |
---|
2925 | |
---|
2926 | for ( Int i = 0; i < refPicSetInterLayer1.size(); i++ ) |
---|
2927 | { |
---|
2928 | refPicSetInterLayer1[i]->setIsLongTerm( false ); |
---|
2929 | } |
---|
2930 | |
---|
2931 | } |
---|
2932 | Void TComSlice::markIvRefPicsAsUnused( TComPicLists* ivPicLists, std::vector<Int> targetDecLayerIdSet, TComVPS* vps, Int curLayerId, Int curPoc ) |
---|
2933 | { |
---|
2934 | // Fill targetDecLayerIdSet with all layers if empty (at encoder side) |
---|
2935 | if (targetDecLayerIdSet.size() == 0 ) |
---|
2936 | { |
---|
2937 | for ( Int layerIdInVps = 0; layerIdInVps <= vps->getMaxLayersMinus1(); layerIdInVps++ ) |
---|
2938 | { |
---|
2939 | targetDecLayerIdSet.push_back( vps->getLayerIdInNuh( layerIdInVps ) ); |
---|
2940 | } |
---|
2941 | } |
---|
2942 | |
---|
2943 | Int numTargetDecLayers = (Int) targetDecLayerIdSet.size(); |
---|
2944 | Int latestDecIdx; |
---|
2945 | for ( latestDecIdx = 0; latestDecIdx < numTargetDecLayers; latestDecIdx++) |
---|
2946 | { |
---|
2947 | if ( targetDecLayerIdSet[ latestDecIdx ] == curLayerId ) |
---|
2948 | { |
---|
2949 | break; |
---|
2950 | } |
---|
2951 | } |
---|
2952 | |
---|
2953 | for( Int i = 0; i <= latestDecIdx; i++ ) |
---|
2954 | { |
---|
2955 | if ( vps->nuhLayerIdIncluded( targetDecLayerIdSet[ i ] ) ) |
---|
2956 | { |
---|
2957 | TComPic* pcPic = ivPicLists->getPic( targetDecLayerIdSet[ i ], curPoc ); |
---|
2958 | if ( pcPic ) |
---|
2959 | { |
---|
2960 | if( pcPic->getSlice(0)->isReferenced() && pcPic->getSlice(0)->getTemporalLayerNonReferenceFlag() ) |
---|
2961 | { |
---|
2962 | Bool remainingInterLayerReferencesFlag = false; |
---|
2963 | for( Int j = latestDecIdx + 1; j < numTargetDecLayers; j++ ) |
---|
2964 | { |
---|
2965 | TComVPS* vpsSlice = pcPic->getSlice(0)->getVPS(); |
---|
2966 | if ( vps->nuhLayerIdIncluded( targetDecLayerIdSet[ j ] ) ) |
---|
2967 | { |
---|
2968 | for( Int k = 0; k < vpsSlice->getNumDirectRefLayers( targetDecLayerIdSet[ j ] ); k++ ) |
---|
2969 | { |
---|
2970 | if ( targetDecLayerIdSet[ i ] == vpsSlice->getRefLayerId( targetDecLayerIdSet[ j ], k ) ) |
---|
2971 | { |
---|
2972 | remainingInterLayerReferencesFlag = true; |
---|
2973 | } |
---|
2974 | } |
---|
2975 | } |
---|
2976 | } |
---|
2977 | if( !remainingInterLayerReferencesFlag ) |
---|
2978 | { |
---|
2979 | pcPic->getSlice(0)->setReferenced( false ); |
---|
2980 | } |
---|
2981 | } |
---|
2982 | } |
---|
2983 | } |
---|
2984 | } |
---|
2985 | } |
---|
2986 | |
---|
2987 | Void TComSlice::printRefPicList() |
---|
2988 | { |
---|
2989 | for ( Int li = 0; li < 2; li++) |
---|
2990 | { |
---|
2991 | std::cout << std::endl << "RefPicListL" << li << ":" << std::endl; |
---|
2992 | for (Int rIdx = 0; rIdx <= (m_aiNumRefIdx[li]-1); rIdx ++) |
---|
2993 | { |
---|
2994 | if (rIdx == 0 && li == 0) m_apcRefPicList[li][rIdx]->print( true ); |
---|
2995 | |
---|
2996 | m_apcRefPicList[li][rIdx]->print( false ); |
---|
2997 | } |
---|
2998 | } |
---|
2999 | } |
---|
3000 | |
---|
3001 | Void TComSlice::markCurrPic( TComPic* currPic ) |
---|
3002 | { |
---|
3003 | if ( !currPic->getSlice(0)->getDiscardableFlag() ) |
---|
3004 | { |
---|
3005 | currPic->getSlice(0)->setReferenced( true ) ; |
---|
3006 | currPic->setIsLongTerm( false ); |
---|
3007 | } |
---|
3008 | else |
---|
3009 | { |
---|
3010 | currPic->getSlice(0)->setReferenced( false ) ; |
---|
3011 | } |
---|
3012 | } |
---|
3013 | |
---|
3014 | Void TComSlice::setRefPicSetInterLayer( std::vector<TComPic*>* refPicSetInterLayer0, std::vector<TComPic*>* refPicSetInterLayer1 ) |
---|
3015 | { |
---|
3016 | m_refPicSetInterLayer0 = refPicSetInterLayer0; |
---|
3017 | m_refPicSetInterLayer1 = refPicSetInterLayer1; |
---|
3018 | } |
---|
3019 | |
---|
3020 | TComPic* TComSlice::getPicFromRefPicSetInterLayer(Int setIdc, Int layerId ) |
---|
3021 | { |
---|
3022 | assert ( setIdc == 0 || setIdc == 1); |
---|
3023 | std::vector<TComPic*>* refPicSetInterLayer = ( setIdc == 0 ? m_refPicSetInterLayer0 : m_refPicSetInterLayer1); |
---|
3024 | assert( refPicSetInterLayer != 0 ); |
---|
3025 | |
---|
3026 | TComPic* pcPic = NULL; |
---|
3027 | for ( Int i = 0; i < (*refPicSetInterLayer).size(); i++ ) |
---|
3028 | { |
---|
3029 | if ((*refPicSetInterLayer)[ i ]->getLayerId() == layerId ) |
---|
3030 | { |
---|
3031 | pcPic = (*refPicSetInterLayer)[ i ]; |
---|
3032 | } |
---|
3033 | } |
---|
3034 | |
---|
3035 | assert(pcPic != NULL); |
---|
3036 | return pcPic; |
---|
3037 | } |
---|
3038 | |
---|
3039 | |
---|
3040 | Int TComSlice::getRefLayerPicFlag( Int i ) |
---|
3041 | { |
---|
3042 | TComVPS* vps = getVPS(); |
---|
3043 | Int refLayerIdx = vps->getLayerIdInVps( vps->getRefLayerId( getLayerId(), i ) ); |
---|
3044 | |
---|
3045 | Bool refLayerPicFlag = ( vps->getSubLayersVpsMaxMinus1( refLayerIdx ) >= getTLayer() ) && |
---|
3046 | ( vps->getMaxTidIlRefPicsPlus1( refLayerIdx, vps->getLayerIdInVps( getLayerId() )) > getTLayer() ); |
---|
3047 | |
---|
3048 | return refLayerPicFlag; |
---|
3049 | } |
---|
3050 | |
---|
3051 | Int TComSlice::getRefLayerPicIdc( Int j ) |
---|
3052 | { |
---|
3053 | Int refLayerPicIdc = -1; |
---|
3054 | Int curj = 0; |
---|
3055 | for( Int i = 0; i < getVPS()->getNumDirectRefLayers( getLayerId()) ; i++ ) |
---|
3056 | { |
---|
3057 | if( getRefLayerPicFlag( i ) ) |
---|
3058 | { |
---|
3059 | if ( curj == j ) |
---|
3060 | { |
---|
3061 | refLayerPicIdc = i; |
---|
3062 | break; |
---|
3063 | } |
---|
3064 | curj++; |
---|
3065 | } |
---|
3066 | } |
---|
3067 | |
---|
3068 | assert( curj == j ); |
---|
3069 | assert( refLayerPicIdc != -1 ); |
---|
3070 | return refLayerPicIdc; |
---|
3071 | } |
---|
3072 | |
---|
3073 | Int TComSlice::getNumRefLayerPics( ) |
---|
3074 | { |
---|
3075 | Int numRefLayerPics = 0; |
---|
3076 | for( Int i = 0; i < getVPS()->getNumDirectRefLayers( getLayerId()) ; i++ ) |
---|
3077 | { |
---|
3078 | numRefLayerPics += getRefLayerPicFlag( i ); |
---|
3079 | } |
---|
3080 | return numRefLayerPics; |
---|
3081 | } |
---|
3082 | |
---|
3083 | |
---|
3084 | |
---|
3085 | Int TComSlice::getNumActiveRefLayerPics() |
---|
3086 | { |
---|
3087 | Int numActiveRefLayerPics; |
---|
3088 | |
---|
3089 | if( getLayerId() == 0 || getVPS()->getNumDirectRefLayers( getLayerId() ) == 0 ) |
---|
3090 | { |
---|
3091 | numActiveRefLayerPics = 0; |
---|
3092 | } |
---|
3093 | else if (getVPS()->getAllRefLayersActiveFlag() ) |
---|
3094 | { |
---|
3095 | numActiveRefLayerPics = getNumRefLayerPics(); |
---|
3096 | } |
---|
3097 | else if ( !getInterLayerPredEnabledFlag() ) |
---|
3098 | { |
---|
3099 | numActiveRefLayerPics = 0; |
---|
3100 | } |
---|
3101 | else if( getVPS()->getMaxOneActiveRefLayerFlag() || getVPS()->getNumDirectRefLayers( getLayerId() ) == 1 ) |
---|
3102 | { |
---|
3103 | numActiveRefLayerPics = getRefLayerPicFlag( 0 ) ? 1 : 0; |
---|
3104 | } |
---|
3105 | else |
---|
3106 | { |
---|
3107 | numActiveRefLayerPics = getNumInterLayerRefPicsMinus1() + 1; |
---|
3108 | } |
---|
3109 | return numActiveRefLayerPics; |
---|
3110 | } |
---|
3111 | |
---|
3112 | Int TComSlice::getRefPicLayerId( Int i ) |
---|
3113 | { |
---|
3114 | return getVPS()->getRefLayerId( getLayerId(), getInterLayerPredLayerIdc( i ) ); |
---|
3115 | } |
---|
3116 | |
---|
3117 | #if H_3D_ARP |
---|
3118 | Void TComSlice::setARPStepNum( TComPicLists*ivPicLists ) |
---|
3119 | { |
---|
3120 | Bool tempRefPicInListsFlag = false; |
---|
3121 | if(!getVPS()->getUseAdvRP(getLayerId()) || this->isIRAP()) |
---|
3122 | { |
---|
3123 | m_nARPStepNum = 0; |
---|
3124 | } |
---|
3125 | else |
---|
3126 | { |
---|
3127 | setFirstTRefIdx (REF_PIC_LIST_0, -1); |
---|
3128 | setFirstTRefIdx (REF_PIC_LIST_1, -1); |
---|
3129 | for ( Int refListIdx = 0; refListIdx < ((m_eSliceType==B_SLICE) ? 2 : 1); refListIdx++ ) |
---|
3130 | { |
---|
3131 | for(Int i = 0; i < getNumRefIdx(RefPicList(refListIdx)); i++ ) |
---|
3132 | { |
---|
3133 | if ( getRefPic(RefPicList(refListIdx), i)->getPOC() != getPOC() ) |
---|
3134 | { |
---|
3135 | setFirstTRefIdx (RefPicList(refListIdx), i); |
---|
3136 | break; |
---|
3137 | } |
---|
3138 | } |
---|
3139 | } |
---|
3140 | tempRefPicInListsFlag = getFirstTRefIdx(REF_PIC_LIST_0) >= 0 || getFirstTRefIdx(REF_PIC_LIST_1) >= 0; |
---|
3141 | m_nARPStepNum = tempRefPicInListsFlag ? getVPS()->getARPStepNum(getLayerId()) : 0; |
---|
3142 | } |
---|
3143 | |
---|
3144 | if (tempRefPicInListsFlag) |
---|
3145 | { |
---|
3146 | for ( Int refListIdx = 0; refListIdx < ((m_eSliceType==B_SLICE) ? 2 : 1); refListIdx++ ) |
---|
3147 | { |
---|
3148 | RefPicList eRefPicList = RefPicList( refListIdx ); |
---|
3149 | Int prevPOC = getRefPic(eRefPicList, getFirstTRefIdx(eRefPicList) )->getPOC(); |
---|
3150 | for( Int i = 0; i < getNumActiveRefLayerPics(); i++ ) |
---|
3151 | { |
---|
3152 | Int layerIdInNuh = getRefPicLayerId( i ); |
---|
3153 | Int viewIdx = getVPS()->getViewId( layerIdInNuh ); |
---|
3154 | TComPic*pcPicPrev = ivPicLists->getPic(viewIdx, 0, prevPOC); |
---|
3155 | if (getFirstTRefIdx(eRefPicList) >= 0 && pcPicPrev && pcPicPrev->getSlice( 0 )->isReferenced()) |
---|
3156 | { |
---|
3157 | m_arpRefPicAvailable[eRefPicList][layerIdInNuh] = true; |
---|
3158 | } |
---|
3159 | else |
---|
3160 | { |
---|
3161 | m_arpRefPicAvailable[eRefPicList][layerIdInNuh] = false; |
---|
3162 | } |
---|
3163 | } |
---|
3164 | } |
---|
3165 | } |
---|
3166 | } |
---|
3167 | #endif |
---|
3168 | #if H_3D_IC |
---|
3169 | Void TComSlice::xSetApplyIC() |
---|
3170 | { |
---|
3171 | Int iMaxPelValue = ( 1 << g_bitDepthY ); |
---|
3172 | Int *aiRefOrgHist; |
---|
3173 | Int *aiCurrHist; |
---|
3174 | aiRefOrgHist = (Int *) xMalloc( Int,iMaxPelValue ); |
---|
3175 | aiCurrHist = (Int *) xMalloc( Int,iMaxPelValue ); |
---|
3176 | memset( aiRefOrgHist, 0, iMaxPelValue*sizeof(Int) ); |
---|
3177 | memset( aiCurrHist, 0, iMaxPelValue*sizeof(Int) ); |
---|
3178 | // Reference Idx Number |
---|
3179 | Int iNumRefIdx = getNumRefIdx( REF_PIC_LIST_0 ); |
---|
3180 | TComPic* pcCurrPic = NULL; |
---|
3181 | TComPic* pcRefPic = NULL; |
---|
3182 | TComPicYuv* pcCurrPicYuv = NULL; |
---|
3183 | TComPicYuv* pcRefPicYuvOrg = NULL; |
---|
3184 | pcCurrPic = getPic(); |
---|
3185 | pcCurrPicYuv = pcCurrPic->getPicYuvOrg(); |
---|
3186 | Int iWidth = pcCurrPicYuv->getWidth(); |
---|
3187 | Int iHeight = pcCurrPicYuv->getHeight(); |
---|
3188 | |
---|
3189 | |
---|
3190 | // Get InterView Reference picture |
---|
3191 | // !!!!! Assume only one Interview Reference Picture in L0 |
---|
3192 | for ( Int i = 0; i < iNumRefIdx; i++ ) |
---|
3193 | { |
---|
3194 | pcRefPic = getRefPic( REF_PIC_LIST_0, i ); |
---|
3195 | if ( pcRefPic != NULL ) |
---|
3196 | { |
---|
3197 | if ( pcCurrPic->getViewIndex() != pcRefPic->getViewIndex() ) |
---|
3198 | { |
---|
3199 | pcRefPicYuvOrg = pcRefPic->getPicYuvOrg(); |
---|
3200 | } |
---|
3201 | } |
---|
3202 | } |
---|
3203 | |
---|
3204 | if ( pcRefPicYuvOrg != NULL ) |
---|
3205 | { |
---|
3206 | Pel* pCurrY = pcCurrPicYuv ->getLumaAddr(); |
---|
3207 | Pel* pRefOrgY = pcRefPicYuvOrg ->getLumaAddr(); |
---|
3208 | Int iCurrStride = pcCurrPicYuv->getStride(); |
---|
3209 | Int iRefStride = pcRefPicYuvOrg->getStride(); |
---|
3210 | Int iSumOrgSAD = 0; |
---|
3211 | Double dThresholdOrgSAD = getIsDepth() ? 0.1 : 0.05; |
---|
3212 | |
---|
3213 | // Histogram building - luminance |
---|
3214 | for ( Int y = 0; y < iHeight; y++ ) |
---|
3215 | { |
---|
3216 | for ( Int x = 0; x < iWidth; x++ ) |
---|
3217 | { |
---|
3218 | aiCurrHist[pCurrY[x]]++; |
---|
3219 | aiRefOrgHist[pRefOrgY[x]]++; |
---|
3220 | } |
---|
3221 | pCurrY += iCurrStride; |
---|
3222 | pRefOrgY += iRefStride; |
---|
3223 | } |
---|
3224 | // Histogram SAD |
---|
3225 | for ( Int i = 0; i < iMaxPelValue; i++ ) |
---|
3226 | { |
---|
3227 | iSumOrgSAD += abs( aiCurrHist[i] - aiRefOrgHist[i] ); |
---|
3228 | } |
---|
3229 | // Setting |
---|
3230 | if ( iSumOrgSAD > Int( dThresholdOrgSAD * iWidth * iHeight ) ) |
---|
3231 | { |
---|
3232 | m_bApplyIC = true; |
---|
3233 | } |
---|
3234 | else |
---|
3235 | { |
---|
3236 | m_bApplyIC = false; |
---|
3237 | } |
---|
3238 | } |
---|
3239 | |
---|
3240 | xFree( aiCurrHist ); |
---|
3241 | xFree( aiRefOrgHist ); |
---|
3242 | aiCurrHist = NULL; |
---|
3243 | aiRefOrgHist = NULL; |
---|
3244 | } |
---|
3245 | #endif |
---|
3246 | #if H_3D |
---|
3247 | Void TComSlice::setIvPicLists( TComPicLists* m_ivPicLists ) |
---|
3248 | { |
---|
3249 | for (Int i = 0; i < MAX_NUM_LAYERS; i++ ) |
---|
3250 | { |
---|
3251 | for ( Int depthId = 0; depthId < 2; depthId++ ) |
---|
3252 | { |
---|
3253 | m_ivPicsCurrPoc[ depthId ][ i ] = ( i <= m_viewIndex ) ? m_ivPicLists->getPic( i, ( depthId == 1) , getPOC() ) : NULL; |
---|
3254 | } |
---|
3255 | } |
---|
3256 | } |
---|
3257 | Void TComSlice::setDepthToDisparityLUTs() |
---|
3258 | { |
---|
3259 | Bool setupLUT = false; |
---|
3260 | Int layerIdInVPS = getVPS()->getLayerIdInNuh( m_layerId ); |
---|
3261 | |
---|
3262 | #if H_3D_VSP |
---|
3263 | setupLUT = setupLUT || getVPS()->getViewSynthesisPredFlag( layerIdInVPS); |
---|
3264 | #endif |
---|
3265 | |
---|
3266 | #if H_3D_NBDV_REF |
---|
3267 | setupLUT = setupLUT || getVPS()->getDepthRefinementFlag( layerIdInVPS ); |
---|
3268 | #endif |
---|
3269 | |
---|
3270 | #if H_3D_IV_MERGE |
---|
3271 | setupLUT = setupLUT || ( getVPS()->getIvMvPredFlag(layerIdInVPS ) && getIsDepth() ); |
---|
3272 | #endif |
---|
3273 | |
---|
3274 | if( !setupLUT ) |
---|
3275 | return; |
---|
3276 | |
---|
3277 | /// GT: Allocation should be moved to a better place later; |
---|
3278 | if ( m_depthToDisparityB == NULL ) |
---|
3279 | { |
---|
3280 | m_depthToDisparityB = new Int*[ getViewIndex() ]; |
---|
3281 | for ( Int i = 0; i < getViewIndex(); i++ ) |
---|
3282 | { |
---|
3283 | m_depthToDisparityB[ i ] = new Int[ Int(1 << g_bitDepthY) ]; |
---|
3284 | } |
---|
3285 | } |
---|
3286 | |
---|
3287 | if ( m_depthToDisparityF == NULL ) |
---|
3288 | { |
---|
3289 | m_depthToDisparityF= new Int*[ getViewIndex() ]; |
---|
3290 | for ( Int i = 0; i < getViewIndex(); i++ ) |
---|
3291 | { |
---|
3292 | m_depthToDisparityF[ i ] = new Int[ Int(1 << g_bitDepthY) ]; |
---|
3293 | } |
---|
3294 | } |
---|
3295 | |
---|
3296 | assert( m_depthToDisparityB != NULL ); |
---|
3297 | assert( m_depthToDisparityF != NULL ); |
---|
3298 | |
---|
3299 | TComVPS* vps = getVPS(); |
---|
3300 | |
---|
3301 | Int log2Div = g_bitDepthY - 1 + vps->getCamParPrecision(); |
---|
3302 | Int viewIndex = getViewIndex(); |
---|
3303 | |
---|
3304 | Bool camParaSH = vps->hasCamParInSliceHeader( viewIndex ); |
---|
3305 | |
---|
3306 | Int* codScale = camParaSH ? m_aaiCodedScale [ 0 ] : vps->getCodedScale ( viewIndex ); |
---|
3307 | Int* codOffset = camParaSH ? m_aaiCodedOffset[ 0 ] : vps->getCodedOffset ( viewIndex ); |
---|
3308 | Int* invCodScale = camParaSH ? m_aaiCodedScale [ 1 ] : vps->getInvCodedScale ( viewIndex ); |
---|
3309 | Int* invCodOffset = camParaSH ? m_aaiCodedOffset[ 1 ] : vps->getInvCodedOffset( viewIndex ); |
---|
3310 | |
---|
3311 | for (Int i = 0; i <= ( getViewIndex() - 1); i++) |
---|
3312 | { |
---|
3313 | for ( Int d = 0; d <= ( ( 1 << g_bitDepthY ) - 1 ); d++ ) |
---|
3314 | { |
---|
3315 | Int offset = ( codOffset [ i ] << g_bitDepthY ) + ( ( 1 << log2Div ) >> 1 ); |
---|
3316 | m_depthToDisparityB[ i ][ d ] = ( codScale [ i ] * d + offset ) >> log2Div; |
---|
3317 | |
---|
3318 | Int invOffset = ( invCodOffset[ i ] << g_bitDepthY ) + ( ( 1 << log2Div ) >> 1 ); |
---|
3319 | m_depthToDisparityF[ i ][ d ] = ( invCodScale[ i ] * d + invOffset ) >> log2Div; |
---|
3320 | } |
---|
3321 | } |
---|
3322 | } |
---|
3323 | #endif |
---|
3324 | #endif |
---|
3325 | /** get scaling matrix from RefMatrixID |
---|
3326 | * \param sizeId size index |
---|
3327 | * \param Index of input matrix |
---|
3328 | * \param Index of reference matrix |
---|
3329 | */ |
---|
3330 | Void TComScalingList::processRefMatrix( UInt sizeId, UInt listId , UInt refListId ) |
---|
3331 | { |
---|
3332 | ::memcpy(getScalingListAddress(sizeId, listId),((listId == refListId)? getScalingListDefaultAddress(sizeId, refListId): getScalingListAddress(sizeId, refListId)),sizeof(Int)*min(MAX_MATRIX_COEF_NUM,(Int)g_scalingListSize[sizeId])); |
---|
3333 | } |
---|
3334 | |
---|
3335 | /** parse syntax infomation |
---|
3336 | * \param pchFile syntax infomation |
---|
3337 | * \returns false if successful |
---|
3338 | */ |
---|
3339 | Bool TComScalingList::xParseScalingList(Char* pchFile) |
---|
3340 | { |
---|
3341 | FILE *fp; |
---|
3342 | Char line[1024]; |
---|
3343 | UInt sizeIdc,listIdc; |
---|
3344 | UInt i,size = 0; |
---|
3345 | Int *src=0,data; |
---|
3346 | Char *ret; |
---|
3347 | UInt retval; |
---|
3348 | |
---|
3349 | if((fp = fopen(pchFile,"r")) == (FILE*)NULL) |
---|
3350 | { |
---|
3351 | printf("can't open file %s :: set Default Matrix\n",pchFile); |
---|
3352 | return true; |
---|
3353 | } |
---|
3354 | |
---|
3355 | for(sizeIdc = 0; sizeIdc < SCALING_LIST_SIZE_NUM; sizeIdc++) |
---|
3356 | { |
---|
3357 | size = min(MAX_MATRIX_COEF_NUM,(Int)g_scalingListSize[sizeIdc]); |
---|
3358 | for(listIdc = 0; listIdc < g_scalingListNum[sizeIdc]; listIdc++) |
---|
3359 | { |
---|
3360 | src = getScalingListAddress(sizeIdc, listIdc); |
---|
3361 | |
---|
3362 | fseek(fp,0,0); |
---|
3363 | do |
---|
3364 | { |
---|
3365 | ret = fgets(line, 1024, fp); |
---|
3366 | if ((ret==NULL)||(strstr(line, MatrixType[sizeIdc][listIdc])==NULL && feof(fp))) |
---|
3367 | { |
---|
3368 | printf("Error: can't read Matrix :: set Default Matrix\n"); |
---|
3369 | return true; |
---|
3370 | } |
---|
3371 | } |
---|
3372 | while (strstr(line, MatrixType[sizeIdc][listIdc]) == NULL); |
---|
3373 | for (i=0; i<size; i++) |
---|
3374 | { |
---|
3375 | retval = fscanf(fp, "%d,", &data); |
---|
3376 | if (retval!=1) |
---|
3377 | { |
---|
3378 | printf("Error: can't read Matrix :: set Default Matrix\n"); |
---|
3379 | return true; |
---|
3380 | } |
---|
3381 | src[i] = data; |
---|
3382 | } |
---|
3383 | //set DC value for default matrix check |
---|
3384 | setScalingListDC(sizeIdc,listIdc,src[0]); |
---|
3385 | |
---|
3386 | if(sizeIdc > SCALING_LIST_8x8) |
---|
3387 | { |
---|
3388 | fseek(fp,0,0); |
---|
3389 | do |
---|
3390 | { |
---|
3391 | ret = fgets(line, 1024, fp); |
---|
3392 | if ((ret==NULL)||(strstr(line, MatrixType_DC[sizeIdc][listIdc])==NULL && feof(fp))) |
---|
3393 | { |
---|
3394 | printf("Error: can't read DC :: set Default Matrix\n"); |
---|
3395 | return true; |
---|
3396 | } |
---|
3397 | } |
---|
3398 | while (strstr(line, MatrixType_DC[sizeIdc][listIdc]) == NULL); |
---|
3399 | retval = fscanf(fp, "%d,", &data); |
---|
3400 | if (retval!=1) |
---|
3401 | { |
---|
3402 | printf("Error: can't read Matrix :: set Default Matrix\n"); |
---|
3403 | return true; |
---|
3404 | } |
---|
3405 | //overwrite DC value when size of matrix is larger than 16x16 |
---|
3406 | setScalingListDC(sizeIdc,listIdc,data); |
---|
3407 | } |
---|
3408 | } |
---|
3409 | } |
---|
3410 | fclose(fp); |
---|
3411 | return false; |
---|
3412 | } |
---|
3413 | |
---|
3414 | #if H_MV |
---|
3415 | Void TComScalingList::inferFrom( TComScalingList* srcScLi ) |
---|
3416 | { |
---|
3417 | for(Int sizeId = 0; sizeId < SCALING_LIST_SIZE_NUM; sizeId++) |
---|
3418 | { |
---|
3419 | for(Int listId = 0; listId < g_scalingListNum[sizeId]; listId++) |
---|
3420 | { |
---|
3421 | setRefMatrixId (sizeId,listId, srcScLi->getRefMatrixId (sizeId,listId)); |
---|
3422 | setScalingListDC(sizeId,listId, srcScLi->getScalingListDC(sizeId,listId)); |
---|
3423 | ::memcpy(getScalingListAddress(sizeId, listId),srcScLi->getScalingListAddress(sizeId, listId),sizeof(Int)*min(MAX_MATRIX_COEF_NUM,(Int)g_scalingListSize[sizeId])); |
---|
3424 | } |
---|
3425 | } |
---|
3426 | } |
---|
3427 | #endif |
---|
3428 | /** initialization process of quantization matrix array |
---|
3429 | */ |
---|
3430 | Void TComScalingList::init() |
---|
3431 | { |
---|
3432 | for(UInt sizeId = 0; sizeId < SCALING_LIST_SIZE_NUM; sizeId++) |
---|
3433 | { |
---|
3434 | for(UInt listId = 0; listId < g_scalingListNum[sizeId]; listId++) |
---|
3435 | { |
---|
3436 | m_scalingListCoef[sizeId][listId] = new Int [min(MAX_MATRIX_COEF_NUM,(Int)g_scalingListSize[sizeId])]; |
---|
3437 | } |
---|
3438 | } |
---|
3439 | m_scalingListCoef[SCALING_LIST_32x32][3] = m_scalingListCoef[SCALING_LIST_32x32][1]; // copy address for 32x32 |
---|
3440 | } |
---|
3441 | |
---|
3442 | /** destroy quantization matrix array |
---|
3443 | */ |
---|
3444 | Void TComScalingList::destroy() |
---|
3445 | { |
---|
3446 | for(UInt sizeId = 0; sizeId < SCALING_LIST_SIZE_NUM; sizeId++) |
---|
3447 | { |
---|
3448 | for(UInt listId = 0; listId < g_scalingListNum[sizeId]; listId++) |
---|
3449 | { |
---|
3450 | if(m_scalingListCoef[sizeId][listId]) delete [] m_scalingListCoef[sizeId][listId]; |
---|
3451 | } |
---|
3452 | } |
---|
3453 | } |
---|
3454 | |
---|
3455 | /** get default address of quantization matrix |
---|
3456 | * \param sizeId size index |
---|
3457 | * \param listId list index |
---|
3458 | * \returns pointer of quantization matrix |
---|
3459 | */ |
---|
3460 | Int* TComScalingList::getScalingListDefaultAddress(UInt sizeId, UInt listId) |
---|
3461 | { |
---|
3462 | Int *src = 0; |
---|
3463 | switch(sizeId) |
---|
3464 | { |
---|
3465 | case SCALING_LIST_4x4: |
---|
3466 | src = g_quantTSDefault4x4; |
---|
3467 | break; |
---|
3468 | case SCALING_LIST_8x8: |
---|
3469 | src = (listId<3) ? g_quantIntraDefault8x8 : g_quantInterDefault8x8; |
---|
3470 | break; |
---|
3471 | case SCALING_LIST_16x16: |
---|
3472 | src = (listId<3) ? g_quantIntraDefault8x8 : g_quantInterDefault8x8; |
---|
3473 | break; |
---|
3474 | case SCALING_LIST_32x32: |
---|
3475 | src = (listId<1) ? g_quantIntraDefault8x8 : g_quantInterDefault8x8; |
---|
3476 | break; |
---|
3477 | default: |
---|
3478 | assert(0); |
---|
3479 | src = NULL; |
---|
3480 | break; |
---|
3481 | } |
---|
3482 | return src; |
---|
3483 | } |
---|
3484 | |
---|
3485 | /** process of default matrix |
---|
3486 | * \param sizeId size index |
---|
3487 | * \param Index of input matrix |
---|
3488 | */ |
---|
3489 | Void TComScalingList::processDefaultMarix(UInt sizeId, UInt listId) |
---|
3490 | { |
---|
3491 | ::memcpy(getScalingListAddress(sizeId, listId),getScalingListDefaultAddress(sizeId,listId),sizeof(Int)*min(MAX_MATRIX_COEF_NUM,(Int)g_scalingListSize[sizeId])); |
---|
3492 | setScalingListDC(sizeId,listId,SCALING_LIST_DC); |
---|
3493 | } |
---|
3494 | |
---|
3495 | /** check DC value of matrix for default matrix signaling |
---|
3496 | */ |
---|
3497 | Void TComScalingList::checkDcOfMatrix() |
---|
3498 | { |
---|
3499 | for(UInt sizeId = 0; sizeId < SCALING_LIST_SIZE_NUM; sizeId++) |
---|
3500 | { |
---|
3501 | for(UInt listId = 0; listId < g_scalingListNum[sizeId]; listId++) |
---|
3502 | { |
---|
3503 | //check default matrix? |
---|
3504 | if(getScalingListDC(sizeId,listId) == 0) |
---|
3505 | { |
---|
3506 | processDefaultMarix(sizeId, listId); |
---|
3507 | } |
---|
3508 | } |
---|
3509 | } |
---|
3510 | } |
---|
3511 | |
---|
3512 | ParameterSetManager::ParameterSetManager() |
---|
3513 | : m_vpsMap(MAX_NUM_VPS) |
---|
3514 | , m_spsMap(MAX_NUM_SPS) |
---|
3515 | , m_ppsMap(MAX_NUM_PPS) |
---|
3516 | , m_activeVPSId(-1) |
---|
3517 | #if !H_MV |
---|
3518 | , m_activeSPSId(-1) |
---|
3519 | , m_activePPSId(-1) |
---|
3520 | { |
---|
3521 | #else |
---|
3522 | { |
---|
3523 | for (Int i = 0; i < MAX_NUM_LAYERS; i++ ) |
---|
3524 | { |
---|
3525 | m_activeSPSId[ i ] = -1; |
---|
3526 | m_activePPSId[ i ] = -1; |
---|
3527 | } |
---|
3528 | #endif |
---|
3529 | } |
---|
3530 | |
---|
3531 | |
---|
3532 | ParameterSetManager::~ParameterSetManager() |
---|
3533 | { |
---|
3534 | } |
---|
3535 | |
---|
3536 | //! activate a SPS from a active parameter sets SEI message |
---|
3537 | //! \returns true, if activation is successful |
---|
3538 | #if H_MV |
---|
3539 | Bool ParameterSetManager::activateSPSWithSEI(Int spsId, Int layerId ) |
---|
3540 | #else |
---|
3541 | Bool ParameterSetManager::activateSPSWithSEI(Int spsId) |
---|
3542 | #endif |
---|
3543 | { |
---|
3544 | TComSPS *sps = m_spsMap.getPS(spsId); |
---|
3545 | if (sps) |
---|
3546 | { |
---|
3547 | Int vpsId = sps->getVPSId(); |
---|
3548 | if (m_vpsMap.getPS(vpsId)) |
---|
3549 | { |
---|
3550 | m_activeVPSId = vpsId; |
---|
3551 | #if H_MV |
---|
3552 | m_activeSPSId[ layerId ] = spsId; |
---|
3553 | #else |
---|
3554 | m_activeSPSId = spsId; |
---|
3555 | #endif |
---|
3556 | return true; |
---|
3557 | } |
---|
3558 | else |
---|
3559 | { |
---|
3560 | printf("Warning: tried to activate SPS using an Active parameter sets SEI message. Referenced VPS does not exist."); |
---|
3561 | } |
---|
3562 | } |
---|
3563 | else |
---|
3564 | { |
---|
3565 | printf("Warning: tried to activate non-existing SPS using an Active parameter sets SEI message."); |
---|
3566 | } |
---|
3567 | return false; |
---|
3568 | } |
---|
3569 | |
---|
3570 | //! activate a PPS and depending on isIDR parameter also SPS and VPS |
---|
3571 | //! \returns true, if activation is successful |
---|
3572 | #if H_MV |
---|
3573 | Bool ParameterSetManager::activatePPS(Int ppsId, Bool isIRAP, Int layerId ) |
---|
3574 | #else |
---|
3575 | Bool ParameterSetManager::activatePPS(Int ppsId, Bool isIRAP) |
---|
3576 | #endif |
---|
3577 | { |
---|
3578 | TComPPS *pps = m_ppsMap.getPS(ppsId); |
---|
3579 | if (pps) |
---|
3580 | { |
---|
3581 | Int spsId = pps->getSPSId(); |
---|
3582 | #if H_MV |
---|
3583 | if (!isIRAP && (spsId != m_activeSPSId[ layerId ])) |
---|
3584 | #else |
---|
3585 | if (!isIRAP && (spsId != m_activeSPSId)) |
---|
3586 | #endif |
---|
3587 | { |
---|
3588 | printf("Warning: tried to activate PPS referring to a inactive SPS at non-IRAP."); |
---|
3589 | return false; |
---|
3590 | } |
---|
3591 | |
---|
3592 | TComSPS *sps = m_spsMap.getPS(spsId); |
---|
3593 | if (sps) |
---|
3594 | { |
---|
3595 | Int vpsId = sps->getVPSId(); |
---|
3596 | if (!isIRAP && (vpsId != m_activeVPSId)) |
---|
3597 | { |
---|
3598 | printf("Warning: tried to activate PPS referring to a inactive VPS at non-IRAP."); |
---|
3599 | return false; |
---|
3600 | } |
---|
3601 | if (m_vpsMap.getPS(vpsId)) |
---|
3602 | { |
---|
3603 | #if H_MV |
---|
3604 | m_activePPSId[ layerId ] = ppsId; |
---|
3605 | m_activeVPSId = vpsId; |
---|
3606 | m_activeSPSId[ layerId ] = spsId; |
---|
3607 | #else |
---|
3608 | m_activePPSId = ppsId; |
---|
3609 | m_activeVPSId = vpsId; |
---|
3610 | m_activeSPSId = spsId; |
---|
3611 | #endif |
---|
3612 | return true; |
---|
3613 | } |
---|
3614 | else |
---|
3615 | { |
---|
3616 | printf("Warning: tried to activate PPS that refers to a non-existing VPS."); |
---|
3617 | } |
---|
3618 | } |
---|
3619 | else |
---|
3620 | { |
---|
3621 | printf("Warning: tried to activate a PPS that refers to a non-existing SPS."); |
---|
3622 | } |
---|
3623 | } |
---|
3624 | else |
---|
3625 | { |
---|
3626 | printf("Warning: tried to activate non-existing PPS."); |
---|
3627 | } |
---|
3628 | return false; |
---|
3629 | } |
---|
3630 | |
---|
3631 | ProfileTierLevel::ProfileTierLevel() |
---|
3632 | : m_profileSpace (0) |
---|
3633 | , m_tierFlag (false) |
---|
3634 | , m_profileIdc (0) |
---|
3635 | , m_levelIdc (0) |
---|
3636 | , m_progressiveSourceFlag (false) |
---|
3637 | , m_interlacedSourceFlag (false) |
---|
3638 | , m_nonPackedConstraintFlag(false) |
---|
3639 | , m_frameOnlyConstraintFlag(false) |
---|
3640 | { |
---|
3641 | ::memset(m_profileCompatibilityFlag, 0, sizeof(m_profileCompatibilityFlag)); |
---|
3642 | } |
---|
3643 | |
---|
3644 | TComPTL::TComPTL() |
---|
3645 | { |
---|
3646 | ::memset(m_subLayerProfilePresentFlag, 0, sizeof(m_subLayerProfilePresentFlag)); |
---|
3647 | ::memset(m_subLayerLevelPresentFlag, 0, sizeof(m_subLayerLevelPresentFlag )); |
---|
3648 | } |
---|
3649 | |
---|
3650 | #if H_MV |
---|
3651 | Void TComPTL::copyLevelFrom( TComPTL* source ) |
---|
3652 | { |
---|
3653 | getGeneralPTL()->setLevelIdc( source->getGeneralPTL()->getLevelIdc() ); |
---|
3654 | for( Int subLayer = 0; subLayer < 6; subLayer++ ) |
---|
3655 | { |
---|
3656 | setSubLayerLevelPresentFlag( subLayer, source->getSubLayerLevelPresentFlag( subLayer ) ); |
---|
3657 | getSubLayerPTL( subLayer )->setLevelIdc( source->getSubLayerPTL( subLayer )->getLevelIdc() ); |
---|
3658 | } |
---|
3659 | } |
---|
3660 | #endif |
---|
3661 | //! \} |
---|
3662 | |
---|
3663 | #if H_MV |
---|
3664 | TComVPSVUI::TComVPSVUI() |
---|
3665 | { |
---|
3666 | m_crossLayerIrapAlignedFlag = true; |
---|
3667 | m_bitRatePresentVpsFlag = false; |
---|
3668 | m_picRatePresentVpsFlag = false; |
---|
3669 | for ( Int i = 0; i < MAX_VPS_OP_SETS_PLUS1; i++) |
---|
3670 | { |
---|
3671 | for ( Int j = 0; j < MAX_TLAYER; j++) |
---|
3672 | { |
---|
3673 | m_bitRatePresentFlag [i][j] = false; |
---|
3674 | m_picRatePresentFlag [i][j] = false; |
---|
3675 | m_avgBitRate [i][j] = -1; |
---|
3676 | m_maxBitRate [i][j] = -1; |
---|
3677 | m_constantPicRateIdc [i][j] = -1; |
---|
3678 | m_avgPicRate [i][j] = -1; |
---|
3679 | } |
---|
3680 | } |
---|
3681 | |
---|
3682 | m_ilpRestrictedRefLayersFlag = false; |
---|
3683 | |
---|
3684 | for ( Int i = 0; i < MAX_NUM_LAYERS; i++) |
---|
3685 | { |
---|
3686 | for ( Int j = 0; j < MAX_NUM_LAYERS; j++) |
---|
3687 | { |
---|
3688 | m_tileBoundariesAlignedFlag [i][j] = false; |
---|
3689 | m_minSpatialSegmentOffsetPlus1[i][j] = 0; |
---|
3690 | m_ctuBasedOffsetEnabledFlag [i][j] = false; |
---|
3691 | m_minHorizontalCtuOffsetPlus1 [i][j] = -1; |
---|
3692 | } |
---|
3693 | } |
---|
3694 | for ( Int i = 0; i < MAX_NUM_VIDEO_SIGNAL_INFO; i++ ) |
---|
3695 | { |
---|
3696 | m_videoSignalInfo [i] = NULL; |
---|
3697 | } |
---|
3698 | |
---|
3699 | m_vpsVuiBspHrdPresentFlag = false; |
---|
3700 | m_vpsVuiBspHrdParameters = new TComVpsVuiBspHrdParameters(); |
---|
3701 | } |
---|
3702 | |
---|
3703 | TComVPSVUI::~TComVPSVUI() |
---|
3704 | { |
---|
3705 | for ( Int i = 0; i < MAX_NUM_VIDEO_SIGNAL_INFO; i++ ) |
---|
3706 | { |
---|
3707 | if (m_videoSignalInfo[ i ] != NULL ) delete m_videoSignalInfo[ i ]; |
---|
3708 | m_videoSignalInfo [ i ] = NULL; |
---|
3709 | } |
---|
3710 | |
---|
3711 | if ( m_vpsVuiBspHrdParameters ) delete m_vpsVuiBspHrdParameters; |
---|
3712 | m_vpsVuiBspHrdParameters = NULL; |
---|
3713 | } |
---|
3714 | |
---|
3715 | Void TComRepFormat::inferChromaAndBitDepth( TComRepFormat* prevRepFormat, Bool encoderFlag ) |
---|
3716 | { |
---|
3717 | if ( !encoderFlag ) |
---|
3718 | { |
---|
3719 | setChromaAndBitDepthVpsPresentFlag( prevRepFormat->getChromaAndBitDepthVpsPresentFlag() ); |
---|
3720 | setSeparateColourPlaneVpsFlag ( prevRepFormat->getSeparateColourPlaneVpsFlag () ); |
---|
3721 | setBitDepthVpsLumaMinus8 ( prevRepFormat->getBitDepthVpsLumaMinus8 () ); |
---|
3722 | setBitDepthVpsChromaMinus8 ( prevRepFormat->getBitDepthVpsChromaMinus8 () ); |
---|
3723 | } |
---|
3724 | else |
---|
3725 | { |
---|
3726 | assert( getChromaAndBitDepthVpsPresentFlag() == prevRepFormat->getChromaAndBitDepthVpsPresentFlag() ); |
---|
3727 | assert( getSeparateColourPlaneVpsFlag () == prevRepFormat->getSeparateColourPlaneVpsFlag () ); |
---|
3728 | assert( getBitDepthVpsLumaMinus8 () == prevRepFormat->getBitDepthVpsLumaMinus8 () ); |
---|
3729 | assert( getBitDepthVpsChromaMinus8 () == prevRepFormat->getBitDepthVpsChromaMinus8 () ); |
---|
3730 | } |
---|
3731 | } |
---|
3732 | |
---|
3733 | Void TComVpsVuiBspHrdParameters::checkLayerInBspFlag( TComVPS* vps, Int h ) |
---|
3734 | { |
---|
3735 | // It is a requirement of bitstream conformance that bitstream partition with index j shall not include |
---|
3736 | // direct or indirect reference layers of any layers in bitstream partition i for any values of i and j |
---|
3737 | // in the range of 0 to num_bitstream_partitions[ h ] ?1, inclusive, such that i is less than j. |
---|
3738 | |
---|
3739 | for ( Int partJ = 0; partJ < getNumBitstreamPartitions( h ); partJ++ ) |
---|
3740 | { |
---|
3741 | for ( Int partI = 0; partI < partJ; partI++ ) |
---|
3742 | { |
---|
3743 | for ( Int layerJ = 0; layerJ < vps->getMaxLayersMinus1(); layerJ++ ) |
---|
3744 | { |
---|
3745 | if ( m_layerInBspFlag[ h ][partJ][layerJ ] ) |
---|
3746 | { |
---|
3747 | for ( Int layerI = 0; layerI < vps->getMaxLayersMinus1(); layerI++ ) |
---|
3748 | { |
---|
3749 | if ( m_layerInBspFlag[ h ][partI][layerI] ) |
---|
3750 | { |
---|
3751 | assert( !vps->getInDirectDependencyFlag( layerI, layerJ ) ); |
---|
3752 | } |
---|
3753 | } |
---|
3754 | } |
---|
3755 | } |
---|
3756 | } |
---|
3757 | } |
---|
3758 | } |
---|
3759 | |
---|
3760 | Void TComVUI::inferVideoSignalInfo( TComVPS* vps, Int layerIdCurr ) |
---|
3761 | { |
---|
3762 | if ( layerIdCurr == 0 || !vps->getVpsVuiPresentFlag() ) |
---|
3763 | { |
---|
3764 | return; |
---|
3765 | } |
---|
3766 | |
---|
3767 | TComVPSVUI* vpsVUI = vps->getVPSVUI(); |
---|
3768 | assert( vpsVUI != NULL ); |
---|
3769 | |
---|
3770 | TComVideoSignalInfo* videoSignalInfo = vpsVUI->getVideoSignalInfo( vpsVUI->getVpsVideoSignalInfoIdx( vps->getLayerIdInVps( layerIdCurr ) ) ); |
---|
3771 | assert( videoSignalInfo != NULL ); |
---|
3772 | |
---|
3773 | setVideoFormat ( videoSignalInfo->getVideoVpsFormat () ); |
---|
3774 | setVideoFullRangeFlag ( videoSignalInfo->getVideoFullRangeVpsFlag () ); |
---|
3775 | setColourPrimaries ( videoSignalInfo->getColourPrimariesVps () ); |
---|
3776 | setTransferCharacteristics( videoSignalInfo->getTransferCharacteristicsVps() ); |
---|
3777 | setMatrixCoefficients ( videoSignalInfo->getMatrixCoeffsVps () ); |
---|
3778 | } |
---|
3779 | #endif |
---|