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_DBBP |
---|
1831 | m_dbbpFlag [ i ] = false; |
---|
1832 | #endif |
---|
1833 | #if H_3D_IV_MERGE |
---|
1834 | m_bMPIFlag [ i ] = false; |
---|
1835 | #endif |
---|
1836 | } |
---|
1837 | #endif |
---|
1838 | #endif |
---|
1839 | } |
---|
1840 | |
---|
1841 | TComVPS::~TComVPS() |
---|
1842 | { |
---|
1843 | if( m_hrdParameters != NULL ) delete[] m_hrdParameters; |
---|
1844 | if( m_hrdOpSetIdx != NULL ) delete[] m_hrdOpSetIdx; |
---|
1845 | if( m_cprmsPresentFlag != NULL ) delete[] m_cprmsPresentFlag; |
---|
1846 | #if H_MV |
---|
1847 | if ( m_vpsVUI != NULL ) delete m_vpsVUI; |
---|
1848 | if ( m_dpbSize != NULL ) delete m_dpbSize; |
---|
1849 | |
---|
1850 | for( Int i = 0; i < MAX_NUM_LAYERS; i++ ) |
---|
1851 | { |
---|
1852 | if (m_repFormat[ i ] != NULL ) delete m_repFormat[ i ]; |
---|
1853 | } |
---|
1854 | #endif |
---|
1855 | #if H_3D |
---|
1856 | deleteCamPars(); |
---|
1857 | #endif |
---|
1858 | } |
---|
1859 | |
---|
1860 | #if H_MV |
---|
1861 | |
---|
1862 | Bool TComVPS::checkVPSExtensionSyntax() |
---|
1863 | { |
---|
1864 | for( Int layer = 1; layer <= getMaxLayersMinus1(); layer++ ) |
---|
1865 | { |
---|
1866 | // check layer_id_in_nuh constraint |
---|
1867 | assert( getLayerIdInNuh( layer ) > getLayerIdInNuh( layer -1 ) ); |
---|
1868 | } |
---|
1869 | return true; |
---|
1870 | } |
---|
1871 | |
---|
1872 | Int TComVPS::getNumScalabilityTypes() |
---|
1873 | { |
---|
1874 | return scalTypeToScalIdx( ScalabilityType(MAX_NUM_SCALABILITY_TYPES) ); |
---|
1875 | } |
---|
1876 | |
---|
1877 | Int TComVPS::scalTypeToScalIdx( ScalabilityType scalType ) |
---|
1878 | { |
---|
1879 | assert( scalType >= 0 && scalType <= MAX_NUM_SCALABILITY_TYPES ); |
---|
1880 | assert( scalType == MAX_NUM_SCALABILITY_TYPES || getScalabilityMaskFlag( scalType ) ); |
---|
1881 | Int scalIdx = 0; |
---|
1882 | for( Int curScalType = 0; curScalType < scalType; curScalType++ ) |
---|
1883 | { |
---|
1884 | scalIdx += ( getScalabilityMaskFlag( curScalType ) ? 1 : 0 ); |
---|
1885 | |
---|
1886 | } |
---|
1887 | |
---|
1888 | return scalIdx; |
---|
1889 | } |
---|
1890 | Void TComVPS::setScalabilityMaskFlag( UInt val ) |
---|
1891 | { |
---|
1892 | for ( Int scalType = 0; scalType < MAX_NUM_SCALABILITY_TYPES; scalType++ ) |
---|
1893 | { |
---|
1894 | setScalabilityMaskFlag( scalType, ( val & (1 << scalType ) ) != 0 ); |
---|
1895 | } |
---|
1896 | } |
---|
1897 | |
---|
1898 | Void TComVPS::setRefLayers() |
---|
1899 | { |
---|
1900 | for( Int i = 0; i <= getMaxLayersMinus1(); i++ ) |
---|
1901 | { |
---|
1902 | Int iNuhLId = getLayerIdInNuh( i ); |
---|
1903 | m_numDirectRefLayers[ iNuhLId ] = 0; |
---|
1904 | for( Int j = 0; j < i; j++ ) |
---|
1905 | { |
---|
1906 | if( getDirectDependencyFlag(i , j) ) |
---|
1907 | { |
---|
1908 | m_refLayerId[ iNuhLId ][m_numDirectRefLayers[ iNuhLId ]++ ] = getLayerIdInNuh( j ); |
---|
1909 | } |
---|
1910 | } |
---|
1911 | } |
---|
1912 | } |
---|
1913 | |
---|
1914 | Int TComVPS::getRefLayerId( Int layerIdInNuh, Int idx ) |
---|
1915 | { |
---|
1916 | assert( idx >= 0 && idx < m_numDirectRefLayers[layerIdInNuh] ); |
---|
1917 | Int refLayerIdInNuh = m_refLayerId[ layerIdInNuh ][ idx ]; |
---|
1918 | assert ( refLayerIdInNuh >= 0 ); |
---|
1919 | return refLayerIdInNuh; |
---|
1920 | } |
---|
1921 | |
---|
1922 | Int TComVPS::getScalabilityId( Int layerIdInVps, ScalabilityType scalType ) |
---|
1923 | { |
---|
1924 | return getScalabilityMaskFlag( scalType ) ? getDimensionId( layerIdInVps, scalTypeToScalIdx( scalType ) ) : 0; |
---|
1925 | } |
---|
1926 | |
---|
1927 | #if H_3D |
---|
1928 | Int TComVPS::getLayerIdInNuh( Int viewIndex, Bool depthFlag ) |
---|
1929 | { |
---|
1930 | Int foundLayerIdinNuh = -1; |
---|
1931 | |
---|
1932 | for (Int layerIdInVps = 0 ; layerIdInVps <= getMaxLayersMinus1(); layerIdInVps++ ) |
---|
1933 | { |
---|
1934 | Int layerIdInNuh = getLayerIdInNuh( layerIdInVps ); |
---|
1935 | if( ( getViewIndex( layerIdInNuh ) == viewIndex ) && ( getDepthId( layerIdInNuh ) == ( depthFlag ? 1 : 0 ) ) ) |
---|
1936 | { |
---|
1937 | foundLayerIdinNuh = layerIdInNuh; |
---|
1938 | break; |
---|
1939 | } |
---|
1940 | } |
---|
1941 | assert( foundLayerIdinNuh != -1 ); |
---|
1942 | |
---|
1943 | return foundLayerIdinNuh; |
---|
1944 | } |
---|
1945 | |
---|
1946 | Void TComVPS::createCamPars(Int iNumViews) |
---|
1947 | { |
---|
1948 | Int i = 0, j = 0; |
---|
1949 | |
---|
1950 | m_bCamParPresent = new Bool[ iNumViews ]; |
---|
1951 | m_bCamParInSliceHeader = new Bool[ iNumViews ]; |
---|
1952 | |
---|
1953 | m_aaaiCodedScale = new Int**[ iNumViews ]; |
---|
1954 | m_aaaiCodedOffset = new Int**[ iNumViews ]; |
---|
1955 | for ( i = 0; i < iNumViews ; i++ ) |
---|
1956 | { |
---|
1957 | m_aaaiCodedScale[i] = new Int*[ 2 ]; |
---|
1958 | m_aaaiCodedOffset[i] = new Int*[ 2 ]; |
---|
1959 | for ( j = 0; j < 2; j++ ) |
---|
1960 | { |
---|
1961 | m_aaaiCodedScale[i][j] = new Int[ MAX_NUM_LAYERS ]; |
---|
1962 | m_aaaiCodedOffset[i][j] = new Int[ MAX_NUM_LAYERS ]; |
---|
1963 | for ( Int k = 0; k < MAX_NUM_LAYERS; k++ ) |
---|
1964 | { |
---|
1965 | m_aaaiCodedScale[i][j][k] = 0; |
---|
1966 | m_aaaiCodedOffset[i][j][k] = 0; |
---|
1967 | } |
---|
1968 | } |
---|
1969 | } |
---|
1970 | } |
---|
1971 | |
---|
1972 | Void TComVPS::deleteCamPars() |
---|
1973 | { |
---|
1974 | Int iNumViews = getNumViews(); |
---|
1975 | Int i = 0, j = 0; |
---|
1976 | |
---|
1977 | if ( m_bCamParPresent != NULL ) |
---|
1978 | { |
---|
1979 | delete [] m_bCamParPresent; |
---|
1980 | } |
---|
1981 | if ( m_bCamParInSliceHeader != NULL ) |
---|
1982 | { |
---|
1983 | delete [] m_bCamParInSliceHeader; |
---|
1984 | } |
---|
1985 | |
---|
1986 | if ( m_aaaiCodedScale != NULL ) |
---|
1987 | { |
---|
1988 | for ( i = 0; i < iNumViews ; i++ ) |
---|
1989 | { |
---|
1990 | for ( j = 0; j < 2; j++ ) |
---|
1991 | { |
---|
1992 | delete [] m_aaaiCodedScale[i][j]; |
---|
1993 | } |
---|
1994 | delete [] m_aaaiCodedScale[i]; |
---|
1995 | } |
---|
1996 | delete [] m_aaaiCodedScale; |
---|
1997 | } |
---|
1998 | |
---|
1999 | if ( m_aaaiCodedOffset != NULL ) |
---|
2000 | { |
---|
2001 | for ( i = 0; i < iNumViews ; i++ ) |
---|
2002 | { |
---|
2003 | for ( j = 0; j < 2; j++ ) |
---|
2004 | { |
---|
2005 | delete [] m_aaaiCodedOffset[i][j]; |
---|
2006 | } |
---|
2007 | delete [] m_aaaiCodedOffset[i]; |
---|
2008 | } |
---|
2009 | delete [] m_aaaiCodedOffset; |
---|
2010 | } |
---|
2011 | } |
---|
2012 | |
---|
2013 | |
---|
2014 | Void |
---|
2015 | TComVPS::initCamParaVPS( UInt uiViewIndex, Bool bCamParPresent, UInt uiCamParPrecision, Bool bCamParSlice, Int** aaiScale, Int** aaiOffset ) |
---|
2016 | { |
---|
2017 | AOT( uiViewIndex != 0 && !bCamParSlice && ( aaiScale == 0 || aaiOffset == 0 ) ); |
---|
2018 | |
---|
2019 | m_uiCamParPrecision = ( ( uiViewIndex != 0 )? uiCamParPrecision : 0 ); |
---|
2020 | m_bCamParPresent[ uiViewIndex ] = (( uiViewIndex != 0 )? bCamParPresent : false ); |
---|
2021 | m_bCamParInSliceHeader[ uiViewIndex ] = ( (uiViewIndex != 0)? bCamParSlice : false ); |
---|
2022 | |
---|
2023 | if( !m_bCamParInSliceHeader[ uiViewIndex ] ) |
---|
2024 | { |
---|
2025 | for( UInt uiBaseViewIndex = 0; uiBaseViewIndex < uiViewIndex; uiBaseViewIndex++ ) |
---|
2026 | { |
---|
2027 | m_aaaiCodedScale [ uiViewIndex ][ 0 ][ uiBaseViewIndex ] = aaiScale [ uiBaseViewIndex ][ uiViewIndex ]; |
---|
2028 | m_aaaiCodedScale [ uiViewIndex ][ 1 ][ uiBaseViewIndex ] = aaiScale [ uiViewIndex ][ uiBaseViewIndex ]; |
---|
2029 | m_aaaiCodedOffset[ uiViewIndex ][ 0 ][ uiBaseViewIndex ] = aaiOffset[ uiBaseViewIndex ][ uiViewIndex ]; |
---|
2030 | m_aaaiCodedOffset[ uiViewIndex ][ 1 ][ uiBaseViewIndex ] = aaiOffset[ uiViewIndex ][ uiBaseViewIndex ]; |
---|
2031 | } |
---|
2032 | } |
---|
2033 | } |
---|
2034 | |
---|
2035 | #endif // H_3D |
---|
2036 | |
---|
2037 | |
---|
2038 | Int TComVPS::xGetDimBitOffset( Int j ) |
---|
2039 | { |
---|
2040 | Int dimBitOffset = 0; |
---|
2041 | if ( getSplittingFlag() && j == getNumScalabilityTypes() ) |
---|
2042 | { |
---|
2043 | dimBitOffset = 6; |
---|
2044 | } |
---|
2045 | else |
---|
2046 | { |
---|
2047 | for (Int dimIdx = 0; dimIdx <= j-1; dimIdx++) |
---|
2048 | { |
---|
2049 | dimBitOffset += getDimensionIdLen( dimIdx ); |
---|
2050 | } |
---|
2051 | } |
---|
2052 | return dimBitOffset; |
---|
2053 | } |
---|
2054 | |
---|
2055 | Int TComVPS::inferDimensionId( Int i, Int j ) |
---|
2056 | { |
---|
2057 | return ( ( getLayerIdInNuh( i ) & ( (1 << xGetDimBitOffset( j + 1 ) ) - 1) ) >> xGetDimBitOffset( j ) ); |
---|
2058 | } |
---|
2059 | |
---|
2060 | Int TComVPS::inferLastDimsionIdLenMinus1() |
---|
2061 | { |
---|
2062 | return ( 5 - xGetDimBitOffset( getNumScalabilityTypes() - 1 ) ); |
---|
2063 | } |
---|
2064 | |
---|
2065 | Int TComVPS::getNumLayersInIdList( Int lsIdx ) |
---|
2066 | { |
---|
2067 | assert( lsIdx >= 0 ); |
---|
2068 | assert( lsIdx <= getVpsNumLayerSetsMinus1() ); |
---|
2069 | return (Int) m_layerSetLayerIdList[ lsIdx ].size(); |
---|
2070 | } |
---|
2071 | |
---|
2072 | Int TComVPS::getNumOutputLayerSets() |
---|
2073 | { |
---|
2074 | Int numOutputLayerSets = getVpsNumberLayerSetsMinus1( ) + 1; |
---|
2075 | if ( getMoreOutputLayerSetsThanDefaultFlag( ) ) |
---|
2076 | { |
---|
2077 | numOutputLayerSets += (getNumAddOutputLayerSetsMinus1( ) + 1); |
---|
2078 | } |
---|
2079 | return numOutputLayerSets; |
---|
2080 | } |
---|
2081 | |
---|
2082 | Int TComVPS::getNumViews() |
---|
2083 | { |
---|
2084 | Int numViews = 1; |
---|
2085 | for( Int i = 0; i <= getMaxLayersMinus1(); i++ ) |
---|
2086 | { |
---|
2087 | Int lId = getLayerIdInNuh( i ); |
---|
2088 | if ( i > 0 && ( getViewIndex( lId ) != getScalabilityId( i - 1, VIEW_ORDER_INDEX ) ) ) |
---|
2089 | { |
---|
2090 | numViews++; |
---|
2091 | } |
---|
2092 | } |
---|
2093 | |
---|
2094 | return numViews; |
---|
2095 | } |
---|
2096 | |
---|
2097 | Bool TComVPS::getInDirectDependencyFlag( Int depLayeridInVps, Int refLayeridInVps, Int depth /*= 0 */ ) |
---|
2098 | { |
---|
2099 | assert( depth < 65 ); |
---|
2100 | Bool dependentFlag = getDirectDependencyFlag( depLayeridInVps, refLayeridInVps ); |
---|
2101 | |
---|
2102 | for( Int i = 0; i < depLayeridInVps && !dependentFlag; i++ ) |
---|
2103 | { |
---|
2104 | if ( getDirectDependencyFlag( depLayeridInVps, i ) ) |
---|
2105 | { |
---|
2106 | dependentFlag = getInDirectDependencyFlag( i, refLayeridInVps, depth++ ); |
---|
2107 | } |
---|
2108 | } |
---|
2109 | return dependentFlag; |
---|
2110 | } |
---|
2111 | |
---|
2112 | Void TComVPS::deriveLayerSetLayerIdList() |
---|
2113 | { |
---|
2114 | m_layerSetLayerIdList.resize( getVpsNumLayerSetsMinus1() + 1 ); |
---|
2115 | for (Int i = 0; i <= getVpsNumLayerSetsMinus1(); i++ ) |
---|
2116 | { |
---|
2117 | for( Int m = 0; m <= getVpsMaxLayerId(); m++ ) |
---|
2118 | { |
---|
2119 | if( getLayerIdIncludedFlag( i, m) ) |
---|
2120 | { |
---|
2121 | m_layerSetLayerIdList[ i ].push_back( m ); |
---|
2122 | } |
---|
2123 | } |
---|
2124 | } |
---|
2125 | } |
---|
2126 | |
---|
2127 | Void TComVPS::deriveTargetLayerIdLists() |
---|
2128 | { |
---|
2129 | m_targetDecLayerIdLists.resize( getNumOutputLayerSets() ); |
---|
2130 | m_targetOptLayerIdLists.resize( getNumOutputLayerSets() ); |
---|
2131 | |
---|
2132 | for (Int targetOptLayerSetIdx = 0; targetOptLayerSetIdx < getNumOutputLayerSets(); targetOptLayerSetIdx++ ) |
---|
2133 | { |
---|
2134 | Int targetDecLayerSetIdx = getOutputLayerSetIdxMinus1( targetOptLayerSetIdx ) + 1; |
---|
2135 | Int lsIdx = targetDecLayerSetIdx; |
---|
2136 | |
---|
2137 | for( Int j = 0; j < getNumLayersInIdList( lsIdx ); j++ ) |
---|
2138 | { |
---|
2139 | m_targetDecLayerIdLists[targetOptLayerSetIdx].push_back( m_layerSetLayerIdList[ lsIdx ][ j ] ); |
---|
2140 | if( getOutputLayerFlag( targetOptLayerSetIdx, j )) // This seems to be wrong in draft text |
---|
2141 | { |
---|
2142 | m_targetOptLayerIdLists[targetOptLayerSetIdx].push_back( m_layerSetLayerIdList[ lsIdx ][ j ] ); |
---|
2143 | } |
---|
2144 | } |
---|
2145 | } |
---|
2146 | } |
---|
2147 | #endif // H_MV |
---|
2148 | |
---|
2149 | // ------------------------------------------------------------------------------------------------ |
---|
2150 | // Sequence parameter set (SPS) |
---|
2151 | // ------------------------------------------------------------------------------------------------ |
---|
2152 | |
---|
2153 | TComSPS::TComSPS() |
---|
2154 | : m_SPSId ( 0) |
---|
2155 | , m_VPSId ( 0) |
---|
2156 | , m_chromaFormatIdc (CHROMA_420) |
---|
2157 | , m_uiMaxTLayers ( 1) |
---|
2158 | // Structure |
---|
2159 | , m_picWidthInLumaSamples (352) |
---|
2160 | , m_picHeightInLumaSamples (288) |
---|
2161 | , m_log2MinCodingBlockSize ( 0) |
---|
2162 | , m_log2DiffMaxMinCodingBlockSize (0) |
---|
2163 | , m_uiMaxCUWidth ( 32) |
---|
2164 | , m_uiMaxCUHeight ( 32) |
---|
2165 | , m_uiMaxCUDepth ( 3) |
---|
2166 | , m_bLongTermRefsPresent (false) |
---|
2167 | , m_uiQuadtreeTULog2MaxSize ( 0) |
---|
2168 | , m_uiQuadtreeTULog2MinSize ( 0) |
---|
2169 | , m_uiQuadtreeTUMaxDepthInter ( 0) |
---|
2170 | , m_uiQuadtreeTUMaxDepthIntra ( 0) |
---|
2171 | // Tool list |
---|
2172 | , m_usePCM (false) |
---|
2173 | , m_pcmLog2MaxSize ( 5) |
---|
2174 | , m_uiPCMLog2MinSize ( 7) |
---|
2175 | #if H_3D_QTLPC |
---|
2176 | , m_bUseQTL (false) |
---|
2177 | , m_bUsePC (false) |
---|
2178 | #endif |
---|
2179 | , m_bitDepthY ( 8) |
---|
2180 | , m_bitDepthC ( 8) |
---|
2181 | , m_qpBDOffsetY ( 0) |
---|
2182 | , m_qpBDOffsetC ( 0) |
---|
2183 | , m_useLossless (false) |
---|
2184 | , m_uiPCMBitDepthLuma ( 8) |
---|
2185 | , m_uiPCMBitDepthChroma ( 8) |
---|
2186 | , m_bPCMFilterDisableFlag (false) |
---|
2187 | , m_uiBitsForPOC ( 8) |
---|
2188 | , m_numLongTermRefPicSPS ( 0) |
---|
2189 | , m_uiMaxTrSize ( 32) |
---|
2190 | , m_bUseSAO (false) |
---|
2191 | , m_bTemporalIdNestingFlag (false) |
---|
2192 | , m_scalingListEnabledFlag (false) |
---|
2193 | , m_useStrongIntraSmoothing (false) |
---|
2194 | , m_vuiParametersPresentFlag (false) |
---|
2195 | , m_vuiParameters () |
---|
2196 | #if H_MV |
---|
2197 | , m_pcVPS ( NULL ) |
---|
2198 | , m_spsInferScalingListFlag ( false ) |
---|
2199 | , m_spsScalingListRefLayerId ( 0 ) |
---|
2200 | |
---|
2201 | , m_updateRepFormatFlag ( false ) |
---|
2202 | , m_spsRepFormatIdx ( 0 ) |
---|
2203 | , m_interViewMvVertConstraintFlag (false) |
---|
2204 | #endif |
---|
2205 | #if H_3D |
---|
2206 | , m_bCamParInSliceHeader (false) |
---|
2207 | #endif |
---|
2208 | { |
---|
2209 | for ( Int i = 0; i < MAX_TLAYER; i++ ) |
---|
2210 | { |
---|
2211 | m_uiMaxLatencyIncrease[i] = 0; |
---|
2212 | m_uiMaxDecPicBuffering[i] = 1; |
---|
2213 | m_numReorderPics[i] = 0; |
---|
2214 | } |
---|
2215 | m_scalingList = new TComScalingList; |
---|
2216 | ::memset(m_ltRefPicPocLsbSps, 0, sizeof(m_ltRefPicPocLsbSps)); |
---|
2217 | ::memset(m_usedByCurrPicLtSPSFlag, 0, sizeof(m_usedByCurrPicLtSPSFlag)); |
---|
2218 | #if H_MV |
---|
2219 | m_spsExtensionFlag = false; |
---|
2220 | for( Int i = 0; i < PS_EX_T_MAX_NUM; i++ ) |
---|
2221 | { |
---|
2222 | m_spsExtensionTypeFlag[ i ] = false; |
---|
2223 | } |
---|
2224 | m_numScaledRefLayerOffsets = 0; |
---|
2225 | |
---|
2226 | for (Int i = 0; i < MAX_NUM_SCALED_REF_LAYERS; i++ ) |
---|
2227 | { |
---|
2228 | m_scaledRefLayerId [i] = -1; |
---|
2229 | } |
---|
2230 | |
---|
2231 | for (Int i = 0; i < MAX_NUM_LAYERS; i++ ) |
---|
2232 | { |
---|
2233 | m_scaledRefLayerLeftOffset [i] = 0; |
---|
2234 | m_scaledRefLayerTopOffset [i] = 0; |
---|
2235 | m_scaledRefLayerRightOffset [i] = 0; |
---|
2236 | m_scaledRefLayerBottomOffset [i] = 0; |
---|
2237 | } |
---|
2238 | #endif |
---|
2239 | } |
---|
2240 | |
---|
2241 | TComSPS::~TComSPS() |
---|
2242 | { |
---|
2243 | delete m_scalingList; |
---|
2244 | m_RPSList.destroy(); |
---|
2245 | } |
---|
2246 | |
---|
2247 | Void TComSPS::createRPSList( Int numRPS ) |
---|
2248 | { |
---|
2249 | m_RPSList.destroy(); |
---|
2250 | m_RPSList.create(numRPS); |
---|
2251 | } |
---|
2252 | |
---|
2253 | Void TComSPS::setHrdParameters( UInt frameRate, UInt numDU, UInt bitRate, Bool randomAccess ) |
---|
2254 | { |
---|
2255 | if( !getVuiParametersPresentFlag() ) |
---|
2256 | { |
---|
2257 | return; |
---|
2258 | } |
---|
2259 | |
---|
2260 | TComVUI *vui = getVuiParameters(); |
---|
2261 | TComHRD *hrd = vui->getHrdParameters(); |
---|
2262 | |
---|
2263 | TimingInfo *timingInfo = vui->getTimingInfo(); |
---|
2264 | timingInfo->setTimingInfoPresentFlag( true ); |
---|
2265 | switch( frameRate ) |
---|
2266 | { |
---|
2267 | case 24: |
---|
2268 | timingInfo->setNumUnitsInTick( 1125000 ); timingInfo->setTimeScale ( 27000000 ); |
---|
2269 | break; |
---|
2270 | case 25: |
---|
2271 | timingInfo->setNumUnitsInTick( 1080000 ); timingInfo->setTimeScale ( 27000000 ); |
---|
2272 | break; |
---|
2273 | case 30: |
---|
2274 | timingInfo->setNumUnitsInTick( 900900 ); timingInfo->setTimeScale ( 27000000 ); |
---|
2275 | break; |
---|
2276 | case 50: |
---|
2277 | timingInfo->setNumUnitsInTick( 540000 ); timingInfo->setTimeScale ( 27000000 ); |
---|
2278 | break; |
---|
2279 | case 60: |
---|
2280 | timingInfo->setNumUnitsInTick( 450450 ); timingInfo->setTimeScale ( 27000000 ); |
---|
2281 | break; |
---|
2282 | default: |
---|
2283 | timingInfo->setNumUnitsInTick( 1001 ); timingInfo->setTimeScale ( 60000 ); |
---|
2284 | break; |
---|
2285 | } |
---|
2286 | |
---|
2287 | Bool rateCnt = ( bitRate > 0 ); |
---|
2288 | hrd->setNalHrdParametersPresentFlag( rateCnt ); |
---|
2289 | hrd->setVclHrdParametersPresentFlag( rateCnt ); |
---|
2290 | |
---|
2291 | hrd->setSubPicCpbParamsPresentFlag( ( numDU > 1 ) ); |
---|
2292 | |
---|
2293 | if( hrd->getSubPicCpbParamsPresentFlag() ) |
---|
2294 | { |
---|
2295 | hrd->setTickDivisorMinus2( 100 - 2 ); // |
---|
2296 | hrd->setDuCpbRemovalDelayLengthMinus1( 7 ); // 8-bit precision ( plus 1 for last DU in AU ) |
---|
2297 | hrd->setSubPicCpbParamsInPicTimingSEIFlag( true ); |
---|
2298 | hrd->setDpbOutputDelayDuLengthMinus1( 5 + 7 ); // With sub-clock tick factor of 100, at least 7 bits to have the same value as AU dpb delay |
---|
2299 | } |
---|
2300 | else |
---|
2301 | { |
---|
2302 | hrd->setSubPicCpbParamsInPicTimingSEIFlag( false ); |
---|
2303 | } |
---|
2304 | |
---|
2305 | hrd->setBitRateScale( 4 ); // in units of 2~( 6 + 4 ) = 1,024 bps |
---|
2306 | hrd->setCpbSizeScale( 6 ); // in units of 2~( 4 + 4 ) = 1,024 bit |
---|
2307 | hrd->setDuCpbSizeScale( 6 ); // in units of 2~( 4 + 4 ) = 1,024 bit |
---|
2308 | |
---|
2309 | hrd->setInitialCpbRemovalDelayLengthMinus1(15); // assuming 0.5 sec, log2( 90,000 * 0.5 ) = 16-bit |
---|
2310 | if( randomAccess ) |
---|
2311 | { |
---|
2312 | hrd->setCpbRemovalDelayLengthMinus1(5); // 32 = 2^5 (plus 1) |
---|
2313 | hrd->setDpbOutputDelayLengthMinus1 (5); // 32 + 3 = 2^6 |
---|
2314 | } |
---|
2315 | else |
---|
2316 | { |
---|
2317 | hrd->setCpbRemovalDelayLengthMinus1(9); // max. 2^10 |
---|
2318 | hrd->setDpbOutputDelayLengthMinus1 (9); // max. 2^10 |
---|
2319 | } |
---|
2320 | |
---|
2321 | /* |
---|
2322 | Note: only the case of "vps_max_temporal_layers_minus1 = 0" is supported. |
---|
2323 | */ |
---|
2324 | Int i, j; |
---|
2325 | UInt birateValue, cpbSizeValue; |
---|
2326 | UInt ducpbSizeValue; |
---|
2327 | UInt duBitRateValue = 0; |
---|
2328 | |
---|
2329 | for( i = 0; i < MAX_TLAYER; i ++ ) |
---|
2330 | { |
---|
2331 | hrd->setFixedPicRateFlag( i, 1 ); |
---|
2332 | hrd->setPicDurationInTcMinus1( i, 0 ); |
---|
2333 | hrd->setLowDelayHrdFlag( i, 0 ); |
---|
2334 | hrd->setCpbCntMinus1( i, 0 ); |
---|
2335 | |
---|
2336 | birateValue = bitRate; |
---|
2337 | cpbSizeValue = bitRate; // 1 second |
---|
2338 | ducpbSizeValue = bitRate/numDU; |
---|
2339 | duBitRateValue = bitRate; |
---|
2340 | for( j = 0; j < ( hrd->getCpbCntMinus1( i ) + 1 ); j ++ ) |
---|
2341 | { |
---|
2342 | hrd->setBitRateValueMinus1( i, j, 0, ( birateValue - 1 ) ); |
---|
2343 | hrd->setCpbSizeValueMinus1( i, j, 0, ( cpbSizeValue - 1 ) ); |
---|
2344 | hrd->setDuCpbSizeValueMinus1( i, j, 0, ( ducpbSizeValue - 1 ) ); |
---|
2345 | hrd->setCbrFlag( i, j, 0, ( j == 0 ) ); |
---|
2346 | |
---|
2347 | hrd->setBitRateValueMinus1( i, j, 1, ( birateValue - 1) ); |
---|
2348 | hrd->setCpbSizeValueMinus1( i, j, 1, ( cpbSizeValue - 1 ) ); |
---|
2349 | hrd->setDuCpbSizeValueMinus1( i, j, 1, ( ducpbSizeValue - 1 ) ); |
---|
2350 | hrd->setDuBitRateValueMinus1( i, j, 1, ( duBitRateValue - 1 ) ); |
---|
2351 | hrd->setCbrFlag( i, j, 1, ( j == 0 ) ); |
---|
2352 | } |
---|
2353 | } |
---|
2354 | } |
---|
2355 | const Int TComSPS::m_winUnitX[]={1,2,2,1}; |
---|
2356 | const Int TComSPS::m_winUnitY[]={1,2,1,1}; |
---|
2357 | |
---|
2358 | TComPPS::TComPPS() |
---|
2359 | : m_PPSId (0) |
---|
2360 | , m_SPSId (0) |
---|
2361 | , m_picInitQPMinus26 (0) |
---|
2362 | , m_useDQP (false) |
---|
2363 | , m_bConstrainedIntraPred (false) |
---|
2364 | , m_bSliceChromaQpFlag (false) |
---|
2365 | , m_pcSPS (NULL) |
---|
2366 | , m_uiMaxCuDQPDepth (0) |
---|
2367 | , m_uiMinCuDQPSize (0) |
---|
2368 | , m_chromaCbQpOffset (0) |
---|
2369 | , m_chromaCrQpOffset (0) |
---|
2370 | , m_numRefIdxL0DefaultActive (1) |
---|
2371 | , m_numRefIdxL1DefaultActive (1) |
---|
2372 | , m_TransquantBypassEnableFlag (false) |
---|
2373 | , m_useTransformSkip (false) |
---|
2374 | , m_dependentSliceSegmentsEnabledFlag (false) |
---|
2375 | , m_tilesEnabledFlag (false) |
---|
2376 | , m_entropyCodingSyncEnabledFlag (false) |
---|
2377 | , m_loopFilterAcrossTilesEnabledFlag (true) |
---|
2378 | , m_uniformSpacingFlag (0) |
---|
2379 | , m_iNumColumnsMinus1 (0) |
---|
2380 | , m_puiColumnWidth (NULL) |
---|
2381 | , m_iNumRowsMinus1 (0) |
---|
2382 | , m_puiRowHeight (NULL) |
---|
2383 | , m_iNumSubstreams (1) |
---|
2384 | , m_signHideFlag(0) |
---|
2385 | , m_cabacInitPresentFlag (false) |
---|
2386 | , m_encCABACTableIdx (I_SLICE) |
---|
2387 | , m_sliceHeaderExtensionPresentFlag (false) |
---|
2388 | , m_loopFilterAcrossSlicesEnabledFlag (false) |
---|
2389 | , m_listsModificationPresentFlag( 0) |
---|
2390 | , m_numExtraSliceHeaderBits(0) |
---|
2391 | #if H_MV |
---|
2392 | , m_ppsInferScalingListFlag(false) |
---|
2393 | , m_ppsScalingListRefLayerId(0) |
---|
2394 | #if H_3D |
---|
2395 | , m_pcDLT(NULL) |
---|
2396 | #endif |
---|
2397 | #endif |
---|
2398 | { |
---|
2399 | m_scalingList = new TComScalingList; |
---|
2400 | } |
---|
2401 | |
---|
2402 | TComPPS::~TComPPS() |
---|
2403 | { |
---|
2404 | if( m_iNumColumnsMinus1 > 0 && m_uniformSpacingFlag == 0 ) |
---|
2405 | { |
---|
2406 | if (m_puiColumnWidth) delete [] m_puiColumnWidth; |
---|
2407 | m_puiColumnWidth = NULL; |
---|
2408 | } |
---|
2409 | if( m_iNumRowsMinus1 > 0 && m_uniformSpacingFlag == 0 ) |
---|
2410 | { |
---|
2411 | if (m_puiRowHeight) delete [] m_puiRowHeight; |
---|
2412 | m_puiRowHeight = NULL; |
---|
2413 | } |
---|
2414 | delete m_scalingList; |
---|
2415 | } |
---|
2416 | |
---|
2417 | #if H_3D |
---|
2418 | TComDLT::TComDLT() |
---|
2419 | : m_bDltPresentFlag(false) |
---|
2420 | , m_iNumDepthViews(0) |
---|
2421 | , m_uiDepthViewBitDepth(8) |
---|
2422 | { |
---|
2423 | m_uiDepthViewBitDepth = g_bitDepthY; |
---|
2424 | |
---|
2425 | for( Int i = 0; i < MAX_NUM_LAYERS; i++ ) |
---|
2426 | { |
---|
2427 | m_bUseDLTFlag [i] = false; |
---|
2428 | m_bInterViewDltPredEnableFlag [i] = false; |
---|
2429 | |
---|
2430 | // allocate some memory and initialize with default mapping |
---|
2431 | m_iNumDepthmapValues[i] = ((1 << m_uiDepthViewBitDepth)-1)+1; |
---|
2432 | m_iBitsPerDepthValue[i] = numBitsForValue(m_iNumDepthmapValues[i]); |
---|
2433 | |
---|
2434 | m_iDepthValue2Idx[i] = (Int*) xMalloc(Int, m_iNumDepthmapValues[i]); |
---|
2435 | m_iIdx2DepthValue[i] = (Int*) xMalloc(Int, m_iNumDepthmapValues[i]); |
---|
2436 | |
---|
2437 | //default mapping |
---|
2438 | for (Int d=0; d<m_iNumDepthmapValues[i]; d++) |
---|
2439 | { |
---|
2440 | m_iDepthValue2Idx[i][d] = d; |
---|
2441 | m_iIdx2DepthValue[i][d] = d; |
---|
2442 | } |
---|
2443 | } |
---|
2444 | } |
---|
2445 | |
---|
2446 | TComDLT::~TComDLT() |
---|
2447 | { |
---|
2448 | for( Int i = 0; i < MAX_NUM_LAYERS; i++ ) |
---|
2449 | { |
---|
2450 | if ( m_iDepthValue2Idx[i] != NULL ) |
---|
2451 | { |
---|
2452 | xFree( m_iDepthValue2Idx[i] ); |
---|
2453 | m_iDepthValue2Idx[i] = NULL; |
---|
2454 | } |
---|
2455 | |
---|
2456 | if ( m_iIdx2DepthValue[i] != NULL ) |
---|
2457 | { |
---|
2458 | xFree( m_iIdx2DepthValue[i] ); |
---|
2459 | m_iIdx2DepthValue[i] = NULL; |
---|
2460 | } |
---|
2461 | } |
---|
2462 | } |
---|
2463 | |
---|
2464 | Void TComDLT::setDepthLUTs(Int layerIdInVps, Int* idxToDepthValueTable, Int iNumDepthValues) |
---|
2465 | { |
---|
2466 | if( idxToDepthValueTable == NULL || iNumDepthValues == 0 ) // default mapping only |
---|
2467 | return; |
---|
2468 | |
---|
2469 | // copy idx2DepthValue to internal array |
---|
2470 | memcpy(m_iIdx2DepthValue[layerIdInVps], idxToDepthValueTable, iNumDepthValues*sizeof(UInt)); |
---|
2471 | |
---|
2472 | UInt uiMaxDepthValue = ((1 << g_bitDepthY)-1); |
---|
2473 | for(Int p=0; p<=uiMaxDepthValue; p++) |
---|
2474 | { |
---|
2475 | Int iIdxDown = 0; |
---|
2476 | Int iIdxUp = iNumDepthValues-1; |
---|
2477 | Bool bFound = false; |
---|
2478 | |
---|
2479 | // iterate over indices to find lower closest depth |
---|
2480 | Int i = 1; |
---|
2481 | while(!bFound && i<iNumDepthValues) |
---|
2482 | { |
---|
2483 | if( m_iIdx2DepthValue[layerIdInVps][i] > p ) |
---|
2484 | { |
---|
2485 | iIdxDown = i-1; |
---|
2486 | bFound = true; |
---|
2487 | } |
---|
2488 | |
---|
2489 | i++; |
---|
2490 | } |
---|
2491 | // iterate over indices to find upper closest depth |
---|
2492 | i = iNumDepthValues-2; |
---|
2493 | bFound = false; |
---|
2494 | while(!bFound && i>=0) |
---|
2495 | { |
---|
2496 | if( m_iIdx2DepthValue[layerIdInVps][i] < p ) |
---|
2497 | { |
---|
2498 | iIdxUp = i+1; |
---|
2499 | bFound = true; |
---|
2500 | } |
---|
2501 | |
---|
2502 | i--; |
---|
2503 | } |
---|
2504 | |
---|
2505 | // assert monotony |
---|
2506 | assert(iIdxDown<=iIdxUp); |
---|
2507 | |
---|
2508 | // assign closer depth value/idx |
---|
2509 | if( abs(p-m_iIdx2DepthValue[layerIdInVps][iIdxDown]) < abs(p-m_iIdx2DepthValue[layerIdInVps][iIdxUp]) ) |
---|
2510 | { |
---|
2511 | m_iDepthValue2Idx[layerIdInVps][p] = iIdxDown; |
---|
2512 | } |
---|
2513 | else |
---|
2514 | { |
---|
2515 | m_iDepthValue2Idx[layerIdInVps][p] = iIdxUp; |
---|
2516 | } |
---|
2517 | |
---|
2518 | } |
---|
2519 | |
---|
2520 | // update DLT variables |
---|
2521 | m_iNumDepthmapValues[layerIdInVps] = iNumDepthValues; |
---|
2522 | m_iBitsPerDepthValue[layerIdInVps] = numBitsForValue(m_iNumDepthmapValues[layerIdInVps]); |
---|
2523 | } |
---|
2524 | |
---|
2525 | #if H_3D_DELTA_DLT |
---|
2526 | Void TComDLT::getDeltaDLT( Int layerIdInVps, Int* piDLTInRef, UInt uiDLTInRefNum, Int* piDeltaDLTOut, UInt *puiDeltaDLTOutNum ) |
---|
2527 | { |
---|
2528 | Bool abBM0[ 256 ]; |
---|
2529 | Bool abBM1[ 256 ]; |
---|
2530 | |
---|
2531 | memset( abBM0, 0, sizeof( abBM0 )); |
---|
2532 | memset( abBM1, 0, sizeof( abBM1 )); |
---|
2533 | |
---|
2534 | // convert reference DLT to bit string |
---|
2535 | for( Int i = 0; i < uiDLTInRefNum; i++ ) |
---|
2536 | { |
---|
2537 | abBM0[ piDLTInRef[ i ] ] = true; |
---|
2538 | } |
---|
2539 | // convert internal DLT to bit string |
---|
2540 | for( Int i = 0; i < m_iNumDepthmapValues[ layerIdInVps ]; i++ ) |
---|
2541 | { |
---|
2542 | abBM1[ m_iIdx2DepthValue[ layerIdInVps ][ i ] ] = true; |
---|
2543 | } |
---|
2544 | |
---|
2545 | *puiDeltaDLTOutNum = 0; |
---|
2546 | for( Int i = 0; i < 256; i++ ) |
---|
2547 | { |
---|
2548 | if( abBM0[ i ] ^ abBM1[ i ] ) |
---|
2549 | { |
---|
2550 | piDeltaDLTOut[ *puiDeltaDLTOutNum ] = i; |
---|
2551 | *puiDeltaDLTOutNum = *puiDeltaDLTOutNum + 1; |
---|
2552 | } |
---|
2553 | } |
---|
2554 | } |
---|
2555 | |
---|
2556 | Void TComDLT::setDeltaDLT( Int layerIdInVps, Int* piDLTInRef, UInt uiDLTInRefNum, Int* piDeltaDLTIn, UInt uiDeltaDLTInNum ) |
---|
2557 | { |
---|
2558 | Bool abBM0[ 256 ]; |
---|
2559 | Bool abBM1[ 256 ]; |
---|
2560 | |
---|
2561 | memset( abBM0, 0, sizeof( abBM0 )); |
---|
2562 | memset( abBM1, 0, sizeof( abBM1 )); |
---|
2563 | |
---|
2564 | // convert reference DLT to bit string |
---|
2565 | for( Int i = 0; i < uiDLTInRefNum; i++ ) |
---|
2566 | { |
---|
2567 | abBM0[ piDLTInRef[ i ] ] = true; |
---|
2568 | } |
---|
2569 | // convert delta DLT to bit string |
---|
2570 | for( Int i = 0; i < uiDeltaDLTInNum; i++ ) |
---|
2571 | { |
---|
2572 | abBM1[ piDeltaDLTIn[ i ] ] = true; |
---|
2573 | } |
---|
2574 | |
---|
2575 | Int aiIdx2DepthValue[256]; |
---|
2576 | UInt uiNumDepthValues = 0; |
---|
2577 | memset( aiIdx2DepthValue, 0, sizeof( aiIdx2DepthValue )); |
---|
2578 | |
---|
2579 | for( Int i = 0; i < 256; i++ ) |
---|
2580 | { |
---|
2581 | if( abBM0[ i ] ^ abBM1[ i ] ) |
---|
2582 | { |
---|
2583 | aiIdx2DepthValue[ uiNumDepthValues++ ] = i; |
---|
2584 | } |
---|
2585 | } |
---|
2586 | |
---|
2587 | // update internal tables |
---|
2588 | setDepthLUTs(layerIdInVps, aiIdx2DepthValue, uiNumDepthValues); |
---|
2589 | } |
---|
2590 | #endif |
---|
2591 | |
---|
2592 | #endif |
---|
2593 | |
---|
2594 | #if H_MV |
---|
2595 | Void TComSPS::inferRepFormat( TComVPS* vps, Int layerIdCurr ) |
---|
2596 | { |
---|
2597 | if ( layerIdCurr > 0 ) |
---|
2598 | { |
---|
2599 | Int repFormatIdx = getUpdateRepFormatFlag() ? getSpsRepFormatIdx() : vps->getVpsRepFormatIdx( vps->getLayerIdInVps( layerIdCurr ) ) ; |
---|
2600 | TComRepFormat* repFormat = vps->getRepFormat( repFormatIdx ); |
---|
2601 | setChromaFormatIdc( repFormat->getChromaFormatVpsIdc() ); |
---|
2602 | //// ToDo: add when supported: |
---|
2603 | // setSeperateColourPlaneFlag( repFormat->getSeparateColourPlaneVpsFlag() ) ; |
---|
2604 | |
---|
2605 | setPicWidthInLumaSamples ( repFormat->getPicWidthVpsInLumaSamples() ); |
---|
2606 | setPicHeightInLumaSamples( repFormat->getPicHeightVpsInLumaSamples() ); |
---|
2607 | |
---|
2608 | setBitDepthY ( repFormat->getBitDepthVpsLumaMinus8() + 8 ); |
---|
2609 | setQpBDOffsetY ( (Int) (6*( getBitDepthY() - 8 )) ); |
---|
2610 | |
---|
2611 | setBitDepthC ( repFormat->getBitDepthVpsChromaMinus8() + 8 ); |
---|
2612 | setQpBDOffsetC ( (Int) (6* ( getBitDepthC() -8 ) ) ); |
---|
2613 | if ( getLayerId() > 0 && getUpdateRepFormatFlag() ) |
---|
2614 | { |
---|
2615 | assert( getChromaFormatIdc() <= repFormat->getChromaFormatVpsIdc() ); |
---|
2616 | //// ToDo: add when supported: |
---|
2617 | // assert( getSeperateColourPlaneFlag() <= repFormat->getSeparateColourPlaneVpsFlag() ) ; |
---|
2618 | |
---|
2619 | assert( getPicWidthInLumaSamples() <= repFormat->getPicWidthVpsInLumaSamples() ); |
---|
2620 | assert( getPicHeightInLumaSamples() <= repFormat->getPicHeightVpsInLumaSamples() ); |
---|
2621 | |
---|
2622 | assert( getBitDepthY() <= repFormat->getBitDepthVpsLumaMinus8() + 8 ); |
---|
2623 | assert( getBitDepthC() <= repFormat->getBitDepthVpsChromaMinus8() + 8 ); |
---|
2624 | } |
---|
2625 | } |
---|
2626 | |
---|
2627 | // Set conformance window |
---|
2628 | Int scal = TComSPS::getWinUnitX( getChromaFormatIdc() ) ; |
---|
2629 | getConformanceWindow().scaleOffsets( scal ); |
---|
2630 | getVuiParameters()->getDefaultDisplayWindow().scaleOffsets( scal ); |
---|
2631 | } |
---|
2632 | |
---|
2633 | Void TComSPS::inferScalingList( TComSPS* spsSrc ) |
---|
2634 | { |
---|
2635 | if ( getSpsInferScalingListFlag() ) |
---|
2636 | { |
---|
2637 | assert( spsSrc != NULL ); |
---|
2638 | assert( !spsSrc->getSpsInferScalingListFlag() ); |
---|
2639 | getScalingList()->inferFrom( spsSrc->getScalingList() ); |
---|
2640 | } |
---|
2641 | } |
---|
2642 | #endif |
---|
2643 | |
---|
2644 | TComReferencePictureSet::TComReferencePictureSet() |
---|
2645 | : m_numberOfPictures (0) |
---|
2646 | , m_numberOfNegativePictures (0) |
---|
2647 | , m_numberOfPositivePictures (0) |
---|
2648 | , m_numberOfLongtermPictures (0) |
---|
2649 | , m_interRPSPrediction (0) |
---|
2650 | , m_deltaRIdxMinus1 (0) |
---|
2651 | , m_deltaRPS (0) |
---|
2652 | , m_numRefIdc (0) |
---|
2653 | { |
---|
2654 | ::memset( m_deltaPOC, 0, sizeof(m_deltaPOC) ); |
---|
2655 | ::memset( m_POC, 0, sizeof(m_POC) ); |
---|
2656 | ::memset( m_used, 0, sizeof(m_used) ); |
---|
2657 | ::memset( m_refIdc, 0, sizeof(m_refIdc) ); |
---|
2658 | } |
---|
2659 | |
---|
2660 | TComReferencePictureSet::~TComReferencePictureSet() |
---|
2661 | { |
---|
2662 | } |
---|
2663 | |
---|
2664 | Void TComReferencePictureSet::setUsed(Int bufferNum, Bool used) |
---|
2665 | { |
---|
2666 | m_used[bufferNum] = used; |
---|
2667 | } |
---|
2668 | |
---|
2669 | Void TComReferencePictureSet::setDeltaPOC(Int bufferNum, Int deltaPOC) |
---|
2670 | { |
---|
2671 | m_deltaPOC[bufferNum] = deltaPOC; |
---|
2672 | } |
---|
2673 | |
---|
2674 | Void TComReferencePictureSet::setNumberOfPictures(Int numberOfPictures) |
---|
2675 | { |
---|
2676 | m_numberOfPictures = numberOfPictures; |
---|
2677 | } |
---|
2678 | |
---|
2679 | Int TComReferencePictureSet::getUsed(Int bufferNum) |
---|
2680 | { |
---|
2681 | return m_used[bufferNum]; |
---|
2682 | } |
---|
2683 | |
---|
2684 | Int TComReferencePictureSet::getDeltaPOC(Int bufferNum) |
---|
2685 | { |
---|
2686 | return m_deltaPOC[bufferNum]; |
---|
2687 | } |
---|
2688 | |
---|
2689 | Int TComReferencePictureSet::getNumberOfPictures() |
---|
2690 | { |
---|
2691 | return m_numberOfPictures; |
---|
2692 | } |
---|
2693 | |
---|
2694 | Int TComReferencePictureSet::getPOC(Int bufferNum) |
---|
2695 | { |
---|
2696 | return m_POC[bufferNum]; |
---|
2697 | } |
---|
2698 | |
---|
2699 | Void TComReferencePictureSet::setPOC(Int bufferNum, Int POC) |
---|
2700 | { |
---|
2701 | m_POC[bufferNum] = POC; |
---|
2702 | } |
---|
2703 | |
---|
2704 | Bool TComReferencePictureSet::getCheckLTMSBPresent(Int bufferNum) |
---|
2705 | { |
---|
2706 | return m_bCheckLTMSB[bufferNum]; |
---|
2707 | } |
---|
2708 | |
---|
2709 | Void TComReferencePictureSet::setCheckLTMSBPresent(Int bufferNum, Bool b) |
---|
2710 | { |
---|
2711 | m_bCheckLTMSB[bufferNum] = b; |
---|
2712 | } |
---|
2713 | |
---|
2714 | /** set the reference idc value at uiBufferNum entry to the value of iRefIdc |
---|
2715 | * \param uiBufferNum |
---|
2716 | * \param iRefIdc |
---|
2717 | * \returns Void |
---|
2718 | */ |
---|
2719 | Void TComReferencePictureSet::setRefIdc(Int bufferNum, Int refIdc) |
---|
2720 | { |
---|
2721 | m_refIdc[bufferNum] = refIdc; |
---|
2722 | } |
---|
2723 | |
---|
2724 | /** get the reference idc value at uiBufferNum |
---|
2725 | * \param uiBufferNum |
---|
2726 | * \returns Int |
---|
2727 | */ |
---|
2728 | Int TComReferencePictureSet::getRefIdc(Int bufferNum) |
---|
2729 | { |
---|
2730 | return m_refIdc[bufferNum]; |
---|
2731 | } |
---|
2732 | |
---|
2733 | /** Sorts the deltaPOC and Used by current values in the RPS based on the deltaPOC values. |
---|
2734 | * deltaPOC values are sorted with -ve values before the +ve values. -ve values are in decreasing order. |
---|
2735 | * +ve values are in increasing order. |
---|
2736 | * \returns Void |
---|
2737 | */ |
---|
2738 | Void TComReferencePictureSet::sortDeltaPOC() |
---|
2739 | { |
---|
2740 | // sort in increasing order (smallest first) |
---|
2741 | for(Int j=1; j < getNumberOfPictures(); j++) |
---|
2742 | { |
---|
2743 | Int deltaPOC = getDeltaPOC(j); |
---|
2744 | Bool used = getUsed(j); |
---|
2745 | for (Int k=j-1; k >= 0; k--) |
---|
2746 | { |
---|
2747 | Int temp = getDeltaPOC(k); |
---|
2748 | if (deltaPOC < temp) |
---|
2749 | { |
---|
2750 | setDeltaPOC(k+1, temp); |
---|
2751 | setUsed(k+1, getUsed(k)); |
---|
2752 | setDeltaPOC(k, deltaPOC); |
---|
2753 | setUsed(k, used); |
---|
2754 | } |
---|
2755 | } |
---|
2756 | } |
---|
2757 | // flip the negative values to largest first |
---|
2758 | Int numNegPics = getNumberOfNegativePictures(); |
---|
2759 | for(Int j=0, k=numNegPics-1; j < numNegPics>>1; j++, k--) |
---|
2760 | { |
---|
2761 | Int deltaPOC = getDeltaPOC(j); |
---|
2762 | Bool used = getUsed(j); |
---|
2763 | setDeltaPOC(j, getDeltaPOC(k)); |
---|
2764 | setUsed(j, getUsed(k)); |
---|
2765 | setDeltaPOC(k, deltaPOC); |
---|
2766 | setUsed(k, used); |
---|
2767 | } |
---|
2768 | } |
---|
2769 | |
---|
2770 | /** Prints the deltaPOC and RefIdc (if available) values in the RPS. |
---|
2771 | * A "*" is added to the deltaPOC value if it is Used bu current. |
---|
2772 | * \returns Void |
---|
2773 | */ |
---|
2774 | Void TComReferencePictureSet::printDeltaPOC() |
---|
2775 | { |
---|
2776 | printf("DeltaPOC = { "); |
---|
2777 | for(Int j=0; j < getNumberOfPictures(); j++) |
---|
2778 | { |
---|
2779 | printf("%d%s ", getDeltaPOC(j), (getUsed(j)==1)?"*":""); |
---|
2780 | } |
---|
2781 | if (getInterRPSPrediction()) |
---|
2782 | { |
---|
2783 | printf("}, RefIdc = { "); |
---|
2784 | for(Int j=0; j < getNumRefIdc(); j++) |
---|
2785 | { |
---|
2786 | printf("%d ", getRefIdc(j)); |
---|
2787 | } |
---|
2788 | } |
---|
2789 | printf("}\n"); |
---|
2790 | } |
---|
2791 | |
---|
2792 | TComRPSList::TComRPSList() |
---|
2793 | :m_referencePictureSets (NULL) |
---|
2794 | { |
---|
2795 | } |
---|
2796 | |
---|
2797 | TComRPSList::~TComRPSList() |
---|
2798 | { |
---|
2799 | } |
---|
2800 | |
---|
2801 | Void TComRPSList::create( Int numberOfReferencePictureSets) |
---|
2802 | { |
---|
2803 | m_numberOfReferencePictureSets = numberOfReferencePictureSets; |
---|
2804 | m_referencePictureSets = new TComReferencePictureSet[numberOfReferencePictureSets]; |
---|
2805 | } |
---|
2806 | |
---|
2807 | Void TComRPSList::destroy() |
---|
2808 | { |
---|
2809 | if (m_referencePictureSets) |
---|
2810 | { |
---|
2811 | delete [] m_referencePictureSets; |
---|
2812 | } |
---|
2813 | m_numberOfReferencePictureSets = 0; |
---|
2814 | m_referencePictureSets = NULL; |
---|
2815 | } |
---|
2816 | |
---|
2817 | |
---|
2818 | |
---|
2819 | TComReferencePictureSet* TComRPSList::getReferencePictureSet(Int referencePictureSetNum) |
---|
2820 | { |
---|
2821 | return &m_referencePictureSets[referencePictureSetNum]; |
---|
2822 | } |
---|
2823 | |
---|
2824 | Int TComRPSList::getNumberOfReferencePictureSets() |
---|
2825 | { |
---|
2826 | return m_numberOfReferencePictureSets; |
---|
2827 | } |
---|
2828 | |
---|
2829 | Void TComRPSList::setNumberOfReferencePictureSets(Int numberOfReferencePictureSets) |
---|
2830 | { |
---|
2831 | m_numberOfReferencePictureSets = numberOfReferencePictureSets; |
---|
2832 | } |
---|
2833 | |
---|
2834 | TComRefPicListModification::TComRefPicListModification() |
---|
2835 | : m_bRefPicListModificationFlagL0 (false) |
---|
2836 | , m_bRefPicListModificationFlagL1 (false) |
---|
2837 | { |
---|
2838 | ::memset( m_RefPicSetIdxL0, 0, sizeof(m_RefPicSetIdxL0) ); |
---|
2839 | ::memset( m_RefPicSetIdxL1, 0, sizeof(m_RefPicSetIdxL1) ); |
---|
2840 | } |
---|
2841 | |
---|
2842 | TComRefPicListModification::~TComRefPicListModification() |
---|
2843 | { |
---|
2844 | } |
---|
2845 | |
---|
2846 | TComScalingList::TComScalingList() |
---|
2847 | { |
---|
2848 | init(); |
---|
2849 | } |
---|
2850 | TComScalingList::~TComScalingList() |
---|
2851 | { |
---|
2852 | destroy(); |
---|
2853 | } |
---|
2854 | |
---|
2855 | /** set default quantization matrix to array |
---|
2856 | */ |
---|
2857 | Void TComSlice::setDefaultScalingList() |
---|
2858 | { |
---|
2859 | for(UInt sizeId = 0; sizeId < SCALING_LIST_SIZE_NUM; sizeId++) |
---|
2860 | { |
---|
2861 | for(UInt listId=0;listId<g_scalingListNum[sizeId];listId++) |
---|
2862 | { |
---|
2863 | getScalingList()->processDefaultMarix(sizeId, listId); |
---|
2864 | } |
---|
2865 | } |
---|
2866 | } |
---|
2867 | /** check if use default quantization matrix |
---|
2868 | * \returns true if use default quantization matrix in all size |
---|
2869 | */ |
---|
2870 | Bool TComSlice::checkDefaultScalingList() |
---|
2871 | { |
---|
2872 | UInt defaultCounter=0; |
---|
2873 | |
---|
2874 | for(UInt sizeId = 0; sizeId < SCALING_LIST_SIZE_NUM; sizeId++) |
---|
2875 | { |
---|
2876 | for(UInt listId=0;listId<g_scalingListNum[sizeId];listId++) |
---|
2877 | { |
---|
2878 | 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 |
---|
2879 | && ((sizeId < SCALING_LIST_16x16) || (getScalingList()->getScalingListDC(sizeId,listId) == 16))) // check DC value |
---|
2880 | { |
---|
2881 | defaultCounter++; |
---|
2882 | } |
---|
2883 | } |
---|
2884 | } |
---|
2885 | return (defaultCounter == (SCALING_LIST_NUM * SCALING_LIST_SIZE_NUM - 4)) ? false : true; // -4 for 32x32 |
---|
2886 | } |
---|
2887 | |
---|
2888 | #if H_MV |
---|
2889 | Void TComSlice::createInterLayerReferencePictureSet( TComPicLists* ivPicLists, std::vector<TComPic*>& refPicSetInterLayer0, std::vector<TComPic*>& refPicSetInterLayer1 ) |
---|
2890 | { |
---|
2891 | refPicSetInterLayer0.clear(); |
---|
2892 | refPicSetInterLayer1.clear(); |
---|
2893 | |
---|
2894 | for( Int i = 0; i < getNumActiveRefLayerPics(); i++ ) |
---|
2895 | { |
---|
2896 | Int layerIdRef = getRefPicLayerId( i ); |
---|
2897 | TComPic* picRef = ivPicLists->getPic( layerIdRef, getPOC() ) ; |
---|
2898 | assert ( picRef != 0 ); |
---|
2899 | |
---|
2900 | picRef->getPicYuvRec()->extendPicBorder(); |
---|
2901 | picRef->setIsLongTerm( true ); |
---|
2902 | picRef->getSlice(0)->setReferenced( true ); |
---|
2903 | |
---|
2904 | Int viewIdCur = getVPS()->getViewId( getLayerId() ); |
---|
2905 | Int viewIdZero = getVPS()->getViewId( 0 ); |
---|
2906 | Int viewIdRef = getVPS()->getViewId( layerIdRef ); |
---|
2907 | |
---|
2908 | if ( ( viewIdCur <= viewIdZero && viewIdCur <= viewIdRef ) || ( viewIdCur >= viewIdZero && viewIdCur >= viewIdRef ) ) |
---|
2909 | { |
---|
2910 | refPicSetInterLayer0.push_back( picRef ); |
---|
2911 | } |
---|
2912 | else |
---|
2913 | { |
---|
2914 | refPicSetInterLayer1.push_back( picRef ); |
---|
2915 | } |
---|
2916 | // Consider to check here: |
---|
2917 | // "If the current picture is a RADL picture, there shall be no entry in the RefPicSetInterLayer0 and RefPicSetInterLayer1 that is a RASL picture. " |
---|
2918 | } |
---|
2919 | } |
---|
2920 | |
---|
2921 | Void TComSlice::markIvRefPicsAsShortTerm( std::vector<TComPic*> refPicSetInterLayer0, std::vector<TComPic*> refPicSetInterLayer1 ) |
---|
2922 | { |
---|
2923 | // Mark as shortterm |
---|
2924 | for ( Int i = 0; i < refPicSetInterLayer0.size(); i++ ) |
---|
2925 | { |
---|
2926 | refPicSetInterLayer0[i]->setIsLongTerm( false ); |
---|
2927 | } |
---|
2928 | |
---|
2929 | for ( Int i = 0; i < refPicSetInterLayer1.size(); i++ ) |
---|
2930 | { |
---|
2931 | refPicSetInterLayer1[i]->setIsLongTerm( false ); |
---|
2932 | } |
---|
2933 | |
---|
2934 | } |
---|
2935 | Void TComSlice::markIvRefPicsAsUnused( TComPicLists* ivPicLists, std::vector<Int> targetDecLayerIdSet, TComVPS* vps, Int curLayerId, Int curPoc ) |
---|
2936 | { |
---|
2937 | // Fill targetDecLayerIdSet with all layers if empty (at encoder side) |
---|
2938 | if (targetDecLayerIdSet.size() == 0 ) |
---|
2939 | { |
---|
2940 | for ( Int layerIdInVps = 0; layerIdInVps <= vps->getMaxLayersMinus1(); layerIdInVps++ ) |
---|
2941 | { |
---|
2942 | targetDecLayerIdSet.push_back( vps->getLayerIdInNuh( layerIdInVps ) ); |
---|
2943 | } |
---|
2944 | } |
---|
2945 | |
---|
2946 | Int numTargetDecLayers = (Int) targetDecLayerIdSet.size(); |
---|
2947 | Int latestDecIdx; |
---|
2948 | for ( latestDecIdx = 0; latestDecIdx < numTargetDecLayers; latestDecIdx++) |
---|
2949 | { |
---|
2950 | if ( targetDecLayerIdSet[ latestDecIdx ] == curLayerId ) |
---|
2951 | { |
---|
2952 | break; |
---|
2953 | } |
---|
2954 | } |
---|
2955 | |
---|
2956 | for( Int i = 0; i <= latestDecIdx; i++ ) |
---|
2957 | { |
---|
2958 | if ( vps->nuhLayerIdIncluded( targetDecLayerIdSet[ i ] ) ) |
---|
2959 | { |
---|
2960 | TComPic* pcPic = ivPicLists->getPic( targetDecLayerIdSet[ i ], curPoc ); |
---|
2961 | if ( pcPic ) |
---|
2962 | { |
---|
2963 | if( pcPic->getSlice(0)->isReferenced() && pcPic->getSlice(0)->getTemporalLayerNonReferenceFlag() ) |
---|
2964 | { |
---|
2965 | Bool remainingInterLayerReferencesFlag = false; |
---|
2966 | for( Int j = latestDecIdx + 1; j < numTargetDecLayers; j++ ) |
---|
2967 | { |
---|
2968 | TComVPS* vpsSlice = pcPic->getSlice(0)->getVPS(); |
---|
2969 | if ( vps->nuhLayerIdIncluded( targetDecLayerIdSet[ j ] ) ) |
---|
2970 | { |
---|
2971 | for( Int k = 0; k < vpsSlice->getNumDirectRefLayers( targetDecLayerIdSet[ j ] ); k++ ) |
---|
2972 | { |
---|
2973 | if ( targetDecLayerIdSet[ i ] == vpsSlice->getRefLayerId( targetDecLayerIdSet[ j ], k ) ) |
---|
2974 | { |
---|
2975 | remainingInterLayerReferencesFlag = true; |
---|
2976 | } |
---|
2977 | } |
---|
2978 | } |
---|
2979 | } |
---|
2980 | if( !remainingInterLayerReferencesFlag ) |
---|
2981 | { |
---|
2982 | pcPic->getSlice(0)->setReferenced( false ); |
---|
2983 | } |
---|
2984 | } |
---|
2985 | } |
---|
2986 | } |
---|
2987 | } |
---|
2988 | } |
---|
2989 | |
---|
2990 | Void TComSlice::printRefPicList() |
---|
2991 | { |
---|
2992 | for ( Int li = 0; li < 2; li++) |
---|
2993 | { |
---|
2994 | std::cout << std::endl << "RefPicListL" << li << ":" << std::endl; |
---|
2995 | for (Int rIdx = 0; rIdx <= (m_aiNumRefIdx[li]-1); rIdx ++) |
---|
2996 | { |
---|
2997 | if (rIdx == 0 && li == 0) m_apcRefPicList[li][rIdx]->print( true ); |
---|
2998 | |
---|
2999 | m_apcRefPicList[li][rIdx]->print( false ); |
---|
3000 | } |
---|
3001 | } |
---|
3002 | } |
---|
3003 | |
---|
3004 | Void TComSlice::markCurrPic( TComPic* currPic ) |
---|
3005 | { |
---|
3006 | if ( !currPic->getSlice(0)->getDiscardableFlag() ) |
---|
3007 | { |
---|
3008 | currPic->getSlice(0)->setReferenced( true ) ; |
---|
3009 | currPic->setIsLongTerm( false ); |
---|
3010 | } |
---|
3011 | else |
---|
3012 | { |
---|
3013 | currPic->getSlice(0)->setReferenced( false ) ; |
---|
3014 | } |
---|
3015 | } |
---|
3016 | |
---|
3017 | Void TComSlice::setRefPicSetInterLayer( std::vector<TComPic*>* refPicSetInterLayer0, std::vector<TComPic*>* refPicSetInterLayer1 ) |
---|
3018 | { |
---|
3019 | m_refPicSetInterLayer0 = refPicSetInterLayer0; |
---|
3020 | m_refPicSetInterLayer1 = refPicSetInterLayer1; |
---|
3021 | } |
---|
3022 | |
---|
3023 | TComPic* TComSlice::getPicFromRefPicSetInterLayer(Int setIdc, Int layerId ) |
---|
3024 | { |
---|
3025 | assert ( setIdc == 0 || setIdc == 1); |
---|
3026 | std::vector<TComPic*>* refPicSetInterLayer = ( setIdc == 0 ? m_refPicSetInterLayer0 : m_refPicSetInterLayer1); |
---|
3027 | assert( refPicSetInterLayer != 0 ); |
---|
3028 | |
---|
3029 | TComPic* pcPic = NULL; |
---|
3030 | for ( Int i = 0; i < (*refPicSetInterLayer).size(); i++ ) |
---|
3031 | { |
---|
3032 | if ((*refPicSetInterLayer)[ i ]->getLayerId() == layerId ) |
---|
3033 | { |
---|
3034 | pcPic = (*refPicSetInterLayer)[ i ]; |
---|
3035 | } |
---|
3036 | } |
---|
3037 | |
---|
3038 | assert(pcPic != NULL); |
---|
3039 | return pcPic; |
---|
3040 | } |
---|
3041 | |
---|
3042 | |
---|
3043 | Int TComSlice::getRefLayerPicFlag( Int i ) |
---|
3044 | { |
---|
3045 | TComVPS* vps = getVPS(); |
---|
3046 | Int refLayerIdx = vps->getLayerIdInVps( vps->getRefLayerId( getLayerId(), i ) ); |
---|
3047 | |
---|
3048 | Bool refLayerPicFlag = ( vps->getSubLayersVpsMaxMinus1( refLayerIdx ) >= getTLayer() ) && |
---|
3049 | ( vps->getMaxTidIlRefPicsPlus1( refLayerIdx, vps->getLayerIdInVps( getLayerId() )) > getTLayer() ); |
---|
3050 | |
---|
3051 | return refLayerPicFlag; |
---|
3052 | } |
---|
3053 | |
---|
3054 | Int TComSlice::getRefLayerPicIdc( Int j ) |
---|
3055 | { |
---|
3056 | Int refLayerPicIdc = -1; |
---|
3057 | Int curj = 0; |
---|
3058 | for( Int i = 0; i < getVPS()->getNumDirectRefLayers( getLayerId()) ; i++ ) |
---|
3059 | { |
---|
3060 | if( getRefLayerPicFlag( i ) ) |
---|
3061 | { |
---|
3062 | if ( curj == j ) |
---|
3063 | { |
---|
3064 | refLayerPicIdc = i; |
---|
3065 | break; |
---|
3066 | } |
---|
3067 | curj++; |
---|
3068 | } |
---|
3069 | } |
---|
3070 | |
---|
3071 | assert( curj == j ); |
---|
3072 | assert( refLayerPicIdc != -1 ); |
---|
3073 | return refLayerPicIdc; |
---|
3074 | } |
---|
3075 | |
---|
3076 | Int TComSlice::getNumRefLayerPics( ) |
---|
3077 | { |
---|
3078 | Int numRefLayerPics = 0; |
---|
3079 | for( Int i = 0; i < getVPS()->getNumDirectRefLayers( getLayerId()) ; i++ ) |
---|
3080 | { |
---|
3081 | numRefLayerPics += getRefLayerPicFlag( i ); |
---|
3082 | } |
---|
3083 | return numRefLayerPics; |
---|
3084 | } |
---|
3085 | |
---|
3086 | |
---|
3087 | |
---|
3088 | Int TComSlice::getNumActiveRefLayerPics() |
---|
3089 | { |
---|
3090 | Int numActiveRefLayerPics; |
---|
3091 | |
---|
3092 | if( getLayerId() == 0 || getVPS()->getNumDirectRefLayers( getLayerId() ) == 0 ) |
---|
3093 | { |
---|
3094 | numActiveRefLayerPics = 0; |
---|
3095 | } |
---|
3096 | else if (getVPS()->getAllRefLayersActiveFlag() ) |
---|
3097 | { |
---|
3098 | numActiveRefLayerPics = getNumRefLayerPics(); |
---|
3099 | } |
---|
3100 | else if ( !getInterLayerPredEnabledFlag() ) |
---|
3101 | { |
---|
3102 | numActiveRefLayerPics = 0; |
---|
3103 | } |
---|
3104 | else if( getVPS()->getMaxOneActiveRefLayerFlag() || getVPS()->getNumDirectRefLayers( getLayerId() ) == 1 ) |
---|
3105 | { |
---|
3106 | numActiveRefLayerPics = getRefLayerPicFlag( 0 ) ? 1 : 0; |
---|
3107 | } |
---|
3108 | else |
---|
3109 | { |
---|
3110 | numActiveRefLayerPics = getNumInterLayerRefPicsMinus1() + 1; |
---|
3111 | } |
---|
3112 | return numActiveRefLayerPics; |
---|
3113 | } |
---|
3114 | |
---|
3115 | Int TComSlice::getRefPicLayerId( Int i ) |
---|
3116 | { |
---|
3117 | return getVPS()->getRefLayerId( getLayerId(), getInterLayerPredLayerIdc( i ) ); |
---|
3118 | } |
---|
3119 | |
---|
3120 | #if H_3D_ARP |
---|
3121 | Void TComSlice::setARPStepNum( TComPicLists*ivPicLists ) |
---|
3122 | { |
---|
3123 | Bool tempRefPicInListsFlag = false; |
---|
3124 | if(!getVPS()->getUseAdvRP(getLayerId()) || this->isIRAP()) |
---|
3125 | { |
---|
3126 | m_nARPStepNum = 0; |
---|
3127 | } |
---|
3128 | else |
---|
3129 | { |
---|
3130 | setFirstTRefIdx (REF_PIC_LIST_0, -1); |
---|
3131 | setFirstTRefIdx (REF_PIC_LIST_1, -1); |
---|
3132 | for ( Int refListIdx = 0; refListIdx < ((m_eSliceType==B_SLICE) ? 2 : 1); refListIdx++ ) |
---|
3133 | { |
---|
3134 | #if MTK_ARP_REF_SELECTION_G0053 |
---|
3135 | Int diffPOC=MAX_INT; |
---|
3136 | Int idx=-1; |
---|
3137 | #endif |
---|
3138 | for(Int i = 0; i < getNumRefIdx(RefPicList(refListIdx)); i++ ) |
---|
3139 | { |
---|
3140 | if ( getRefPic(RefPicList(refListIdx), i)->getPOC() != getPOC() ) |
---|
3141 | { |
---|
3142 | #if MTK_ARP_REF_SELECTION_G0053 |
---|
3143 | if( abs(getRefPic(RefPicList(refListIdx), i)->getPOC() - getPOC()) < diffPOC) |
---|
3144 | { |
---|
3145 | diffPOC=abs(getRefPic(RefPicList(refListIdx), i)->getPOC() - getPOC()); |
---|
3146 | idx=i; |
---|
3147 | } |
---|
3148 | #else |
---|
3149 | setFirstTRefIdx (RefPicList(refListIdx), i); |
---|
3150 | break; |
---|
3151 | #endif |
---|
3152 | } |
---|
3153 | #if MTK_ARP_REF_SELECTION_G0053 |
---|
3154 | if(idx>=0) |
---|
3155 | { |
---|
3156 | setFirstTRefIdx (RefPicList(refListIdx), idx); |
---|
3157 | } |
---|
3158 | #endif |
---|
3159 | } |
---|
3160 | } |
---|
3161 | tempRefPicInListsFlag = getFirstTRefIdx(REF_PIC_LIST_0) >= 0 || getFirstTRefIdx(REF_PIC_LIST_1) >= 0; |
---|
3162 | m_nARPStepNum = tempRefPicInListsFlag ? getVPS()->getARPStepNum(getLayerId()) : 0; |
---|
3163 | } |
---|
3164 | |
---|
3165 | if (tempRefPicInListsFlag) |
---|
3166 | { |
---|
3167 | for ( Int refListIdx = 0; refListIdx < ((m_eSliceType==B_SLICE) ? 2 : 1); refListIdx++ ) |
---|
3168 | { |
---|
3169 | RefPicList eRefPicList = RefPicList( refListIdx ); |
---|
3170 | Int prevPOC = getRefPic(eRefPicList, getFirstTRefIdx(eRefPicList) )->getPOC(); |
---|
3171 | for( Int i = 0; i < getNumActiveRefLayerPics(); i++ ) |
---|
3172 | { |
---|
3173 | Int layerIdInNuh = getRefPicLayerId( i ); |
---|
3174 | Int viewIdx = getVPS()->getViewId( layerIdInNuh ); |
---|
3175 | TComPic*pcPicPrev = ivPicLists->getPic(viewIdx, 0, prevPOC); |
---|
3176 | if (getFirstTRefIdx(eRefPicList) >= 0 && pcPicPrev && pcPicPrev->getSlice( 0 )->isReferenced()) |
---|
3177 | { |
---|
3178 | m_arpRefPicAvailable[eRefPicList][layerIdInNuh] = true; |
---|
3179 | } |
---|
3180 | else |
---|
3181 | { |
---|
3182 | m_arpRefPicAvailable[eRefPicList][layerIdInNuh] = false; |
---|
3183 | } |
---|
3184 | } |
---|
3185 | } |
---|
3186 | } |
---|
3187 | } |
---|
3188 | #endif |
---|
3189 | #if H_3D_IC |
---|
3190 | Void TComSlice::xSetApplyIC() |
---|
3191 | { |
---|
3192 | Int iMaxPelValue = ( 1 << g_bitDepthY ); |
---|
3193 | Int *aiRefOrgHist; |
---|
3194 | Int *aiCurrHist; |
---|
3195 | aiRefOrgHist = (Int *) xMalloc( Int,iMaxPelValue ); |
---|
3196 | aiCurrHist = (Int *) xMalloc( Int,iMaxPelValue ); |
---|
3197 | memset( aiRefOrgHist, 0, iMaxPelValue*sizeof(Int) ); |
---|
3198 | memset( aiCurrHist, 0, iMaxPelValue*sizeof(Int) ); |
---|
3199 | // Reference Idx Number |
---|
3200 | Int iNumRefIdx = getNumRefIdx( REF_PIC_LIST_0 ); |
---|
3201 | TComPic* pcCurrPic = NULL; |
---|
3202 | TComPic* pcRefPic = NULL; |
---|
3203 | TComPicYuv* pcCurrPicYuv = NULL; |
---|
3204 | TComPicYuv* pcRefPicYuvOrg = NULL; |
---|
3205 | pcCurrPic = getPic(); |
---|
3206 | pcCurrPicYuv = pcCurrPic->getPicYuvOrg(); |
---|
3207 | Int iWidth = pcCurrPicYuv->getWidth(); |
---|
3208 | Int iHeight = pcCurrPicYuv->getHeight(); |
---|
3209 | |
---|
3210 | |
---|
3211 | // Get InterView Reference picture |
---|
3212 | // !!!!! Assume only one Interview Reference Picture in L0 |
---|
3213 | for ( Int i = 0; i < iNumRefIdx; i++ ) |
---|
3214 | { |
---|
3215 | pcRefPic = getRefPic( REF_PIC_LIST_0, i ); |
---|
3216 | if ( pcRefPic != NULL ) |
---|
3217 | { |
---|
3218 | if ( pcCurrPic->getViewIndex() != pcRefPic->getViewIndex() ) |
---|
3219 | { |
---|
3220 | pcRefPicYuvOrg = pcRefPic->getPicYuvOrg(); |
---|
3221 | } |
---|
3222 | } |
---|
3223 | } |
---|
3224 | |
---|
3225 | if ( pcRefPicYuvOrg != NULL ) |
---|
3226 | { |
---|
3227 | Pel* pCurrY = pcCurrPicYuv ->getLumaAddr(); |
---|
3228 | Pel* pRefOrgY = pcRefPicYuvOrg ->getLumaAddr(); |
---|
3229 | Int iCurrStride = pcCurrPicYuv->getStride(); |
---|
3230 | Int iRefStride = pcRefPicYuvOrg->getStride(); |
---|
3231 | Int iSumOrgSAD = 0; |
---|
3232 | Double dThresholdOrgSAD = getIsDepth() ? 0.1 : 0.05; |
---|
3233 | |
---|
3234 | // Histogram building - luminance |
---|
3235 | for ( Int y = 0; y < iHeight; y++ ) |
---|
3236 | { |
---|
3237 | for ( Int x = 0; x < iWidth; x++ ) |
---|
3238 | { |
---|
3239 | aiCurrHist[pCurrY[x]]++; |
---|
3240 | aiRefOrgHist[pRefOrgY[x]]++; |
---|
3241 | } |
---|
3242 | pCurrY += iCurrStride; |
---|
3243 | pRefOrgY += iRefStride; |
---|
3244 | } |
---|
3245 | // Histogram SAD |
---|
3246 | for ( Int i = 0; i < iMaxPelValue; i++ ) |
---|
3247 | { |
---|
3248 | iSumOrgSAD += abs( aiCurrHist[i] - aiRefOrgHist[i] ); |
---|
3249 | } |
---|
3250 | // Setting |
---|
3251 | if ( iSumOrgSAD > Int( dThresholdOrgSAD * iWidth * iHeight ) ) |
---|
3252 | { |
---|
3253 | m_bApplyIC = true; |
---|
3254 | } |
---|
3255 | else |
---|
3256 | { |
---|
3257 | m_bApplyIC = false; |
---|
3258 | } |
---|
3259 | } |
---|
3260 | |
---|
3261 | xFree( aiCurrHist ); |
---|
3262 | xFree( aiRefOrgHist ); |
---|
3263 | aiCurrHist = NULL; |
---|
3264 | aiRefOrgHist = NULL; |
---|
3265 | } |
---|
3266 | #endif |
---|
3267 | #if H_3D |
---|
3268 | Void TComSlice::setIvPicLists( TComPicLists* m_ivPicLists ) |
---|
3269 | { |
---|
3270 | for (Int i = 0; i < MAX_NUM_LAYERS; i++ ) |
---|
3271 | { |
---|
3272 | for ( Int depthId = 0; depthId < 2; depthId++ ) |
---|
3273 | { |
---|
3274 | m_ivPicsCurrPoc[ depthId ][ i ] = ( i <= m_viewIndex ) ? m_ivPicLists->getPic( i, ( depthId == 1) , getPOC() ) : NULL; |
---|
3275 | } |
---|
3276 | } |
---|
3277 | } |
---|
3278 | Void TComSlice::setDepthToDisparityLUTs() |
---|
3279 | { |
---|
3280 | Bool setupLUT = false; |
---|
3281 | Int layerIdInVPS = getVPS()->getLayerIdInNuh( m_layerId ); |
---|
3282 | |
---|
3283 | #if H_3D_VSP |
---|
3284 | setupLUT = setupLUT || getVPS()->getViewSynthesisPredFlag( layerIdInVPS); |
---|
3285 | #endif |
---|
3286 | |
---|
3287 | #if H_3D_NBDV_REF |
---|
3288 | setupLUT = setupLUT || getVPS()->getDepthRefinementFlag( layerIdInVPS ); |
---|
3289 | #endif |
---|
3290 | |
---|
3291 | #if H_3D_IV_MERGE |
---|
3292 | setupLUT = setupLUT || ( getVPS()->getIvMvPredFlag(layerIdInVPS ) && getIsDepth() ); |
---|
3293 | #endif |
---|
3294 | |
---|
3295 | #if MTK_DDD_G0063 |
---|
3296 | if( getIsDepth() && getViewIndex() > 0 ) |
---|
3297 | { |
---|
3298 | TComSlice *pcTextSlice = getTexturePic()->getSlice( 0 ); |
---|
3299 | memcpy( m_aiDDDInvScale, pcTextSlice->m_aiDDDInvScale, sizeof( Int ) * getViewIndex() ); |
---|
3300 | memcpy( m_aiDDDInvOffset, pcTextSlice->m_aiDDDInvOffset, sizeof( Int ) * getViewIndex() ); |
---|
3301 | memcpy( m_aiDDDShift, pcTextSlice->m_aiDDDShift, sizeof( Int ) * getViewIndex() ); |
---|
3302 | } |
---|
3303 | #endif |
---|
3304 | |
---|
3305 | if( !setupLUT ) |
---|
3306 | return; |
---|
3307 | |
---|
3308 | /// GT: Allocation should be moved to a better place later; |
---|
3309 | if ( m_depthToDisparityB == NULL ) |
---|
3310 | { |
---|
3311 | m_depthToDisparityB = new Int*[ getViewIndex() ]; |
---|
3312 | for ( Int i = 0; i < getViewIndex(); i++ ) |
---|
3313 | { |
---|
3314 | m_depthToDisparityB[ i ] = new Int[ Int(1 << g_bitDepthY) ]; |
---|
3315 | } |
---|
3316 | } |
---|
3317 | |
---|
3318 | if ( m_depthToDisparityF == NULL ) |
---|
3319 | { |
---|
3320 | m_depthToDisparityF= new Int*[ getViewIndex() ]; |
---|
3321 | for ( Int i = 0; i < getViewIndex(); i++ ) |
---|
3322 | { |
---|
3323 | m_depthToDisparityF[ i ] = new Int[ Int(1 << g_bitDepthY) ]; |
---|
3324 | } |
---|
3325 | } |
---|
3326 | |
---|
3327 | assert( m_depthToDisparityB != NULL ); |
---|
3328 | assert( m_depthToDisparityF != NULL ); |
---|
3329 | |
---|
3330 | TComVPS* vps = getVPS(); |
---|
3331 | |
---|
3332 | Int log2Div = g_bitDepthY - 1 + vps->getCamParPrecision(); |
---|
3333 | Int viewIndex = getViewIndex(); |
---|
3334 | |
---|
3335 | Bool camParaSH = vps->hasCamParInSliceHeader( viewIndex ); |
---|
3336 | |
---|
3337 | Int* codScale = camParaSH ? m_aaiCodedScale [ 0 ] : vps->getCodedScale ( viewIndex ); |
---|
3338 | Int* codOffset = camParaSH ? m_aaiCodedOffset[ 0 ] : vps->getCodedOffset ( viewIndex ); |
---|
3339 | Int* invCodScale = camParaSH ? m_aaiCodedScale [ 1 ] : vps->getInvCodedScale ( viewIndex ); |
---|
3340 | Int* invCodOffset = camParaSH ? m_aaiCodedOffset[ 1 ] : vps->getInvCodedOffset( viewIndex ); |
---|
3341 | |
---|
3342 | for (Int i = 0; i <= ( getViewIndex() - 1); i++) |
---|
3343 | { |
---|
3344 | for ( Int d = 0; d <= ( ( 1 << g_bitDepthY ) - 1 ); d++ ) |
---|
3345 | { |
---|
3346 | Int offset = ( codOffset [ i ] << g_bitDepthY ) + ( ( 1 << log2Div ) >> 1 ); |
---|
3347 | m_depthToDisparityB[ i ][ d ] = ( codScale [ i ] * d + offset ) >> log2Div; |
---|
3348 | |
---|
3349 | Int invOffset = ( invCodOffset[ i ] << g_bitDepthY ) + ( ( 1 << log2Div ) >> 1 ); |
---|
3350 | m_depthToDisparityF[ i ][ d ] = ( invCodScale[ i ] * d + invOffset ) >> log2Div; |
---|
3351 | } |
---|
3352 | |
---|
3353 | #if MTK_DDD_G0063 |
---|
3354 | InitializeDDDPara( vps->getCamParPrecision(), codScale[ i ], codOffset[ i ], i ); |
---|
3355 | #endif |
---|
3356 | } |
---|
3357 | } |
---|
3358 | #endif |
---|
3359 | #endif |
---|
3360 | |
---|
3361 | #if MTK_DDD_G0063 |
---|
3362 | Void TComSlice::InitializeDDDPara( UInt uiCamParsCodedPrecision, Int iCodedScale,Int iCodedOffset, Int iBaseViewIdx ) |
---|
3363 | { |
---|
3364 | UInt uiViewId = getViewIndex(); |
---|
3365 | |
---|
3366 | if( uiViewId == 0 ) |
---|
3367 | { |
---|
3368 | m_aiDDDInvScale[ iBaseViewIdx ] = m_aiDDDInvOffset[ iBaseViewIdx ] = m_aiDDDShift[ iBaseViewIdx ] = 0; |
---|
3369 | return; |
---|
3370 | } |
---|
3371 | |
---|
3372 | |
---|
3373 | Int iSign = iCodedScale >= 0 ? 1 : -1; |
---|
3374 | iCodedScale = abs( iCodedScale ); |
---|
3375 | |
---|
3376 | Int iBitWidth = 0; |
---|
3377 | |
---|
3378 | const Int iInvPres = 9; |
---|
3379 | |
---|
3380 | while( ((( 1 << iBitWidth ) << 1 ) <= iCodedScale ) ) |
---|
3381 | { |
---|
3382 | iBitWidth ++; |
---|
3383 | } |
---|
3384 | iBitWidth += iInvPres; |
---|
3385 | Int iTargetValue = 1 << iBitWidth; |
---|
3386 | |
---|
3387 | Int iMinError = MAX_INT; |
---|
3388 | Int iBestD = 1 << ( iInvPres - 1 ); |
---|
3389 | for( Int d = 1 << ( iInvPres - 1 ); d < ( 1 << iInvPres ); d++ ) |
---|
3390 | { |
---|
3391 | Int iError = abs( iCodedScale * d - iTargetValue ); |
---|
3392 | if( iError < iMinError ) |
---|
3393 | { |
---|
3394 | iMinError = iError; |
---|
3395 | iBestD = d; |
---|
3396 | } |
---|
3397 | if( iMinError == 0 ) |
---|
3398 | { |
---|
3399 | break; |
---|
3400 | } |
---|
3401 | } |
---|
3402 | Int iRoundingDir = 0; |
---|
3403 | if( iCodedScale * iBestD > iTargetValue ) |
---|
3404 | { |
---|
3405 | iRoundingDir = -1; |
---|
3406 | } |
---|
3407 | else if( iCodedScale * iBestD < iTargetValue ) |
---|
3408 | { |
---|
3409 | iRoundingDir = 1; |
---|
3410 | } |
---|
3411 | Int iCamPres = uiCamParsCodedPrecision - 1; |
---|
3412 | m_aiDDDInvScale [ iBaseViewIdx ] = ( iBestD << ( iCamPres + g_bitDepthY )) * iSign; |
---|
3413 | m_aiDDDInvOffset[ iBaseViewIdx ] = -iSign * iBestD * ( iCodedOffset << g_bitDepthY ); |
---|
3414 | m_aiDDDShift [ iBaseViewIdx ] = iBitWidth; |
---|
3415 | m_aiDDDInvOffset[ iBaseViewIdx ] += 1 << ( m_aiDDDShift[ iBaseViewIdx ] - 1 ); |
---|
3416 | m_aiDDDInvOffset[ iBaseViewIdx ] += ( 1 << ( m_aiDDDShift[ iBaseViewIdx ] - 4 ) ) * iRoundingDir; |
---|
3417 | |
---|
3418 | return; |
---|
3419 | } |
---|
3420 | #endif |
---|
3421 | |
---|
3422 | /** get scaling matrix from RefMatrixID |
---|
3423 | * \param sizeId size index |
---|
3424 | * \param Index of input matrix |
---|
3425 | * \param Index of reference matrix |
---|
3426 | */ |
---|
3427 | Void TComScalingList::processRefMatrix( UInt sizeId, UInt listId , UInt refListId ) |
---|
3428 | { |
---|
3429 | ::memcpy(getScalingListAddress(sizeId, listId),((listId == refListId)? getScalingListDefaultAddress(sizeId, refListId): getScalingListAddress(sizeId, refListId)),sizeof(Int)*min(MAX_MATRIX_COEF_NUM,(Int)g_scalingListSize[sizeId])); |
---|
3430 | } |
---|
3431 | |
---|
3432 | /** parse syntax infomation |
---|
3433 | * \param pchFile syntax infomation |
---|
3434 | * \returns false if successful |
---|
3435 | */ |
---|
3436 | Bool TComScalingList::xParseScalingList(Char* pchFile) |
---|
3437 | { |
---|
3438 | FILE *fp; |
---|
3439 | Char line[1024]; |
---|
3440 | UInt sizeIdc,listIdc; |
---|
3441 | UInt i,size = 0; |
---|
3442 | Int *src=0,data; |
---|
3443 | Char *ret; |
---|
3444 | UInt retval; |
---|
3445 | |
---|
3446 | if((fp = fopen(pchFile,"r")) == (FILE*)NULL) |
---|
3447 | { |
---|
3448 | printf("can't open file %s :: set Default Matrix\n",pchFile); |
---|
3449 | return true; |
---|
3450 | } |
---|
3451 | |
---|
3452 | for(sizeIdc = 0; sizeIdc < SCALING_LIST_SIZE_NUM; sizeIdc++) |
---|
3453 | { |
---|
3454 | size = min(MAX_MATRIX_COEF_NUM,(Int)g_scalingListSize[sizeIdc]); |
---|
3455 | for(listIdc = 0; listIdc < g_scalingListNum[sizeIdc]; listIdc++) |
---|
3456 | { |
---|
3457 | src = getScalingListAddress(sizeIdc, listIdc); |
---|
3458 | |
---|
3459 | fseek(fp,0,0); |
---|
3460 | do |
---|
3461 | { |
---|
3462 | ret = fgets(line, 1024, fp); |
---|
3463 | if ((ret==NULL)||(strstr(line, MatrixType[sizeIdc][listIdc])==NULL && feof(fp))) |
---|
3464 | { |
---|
3465 | printf("Error: can't read Matrix :: set Default Matrix\n"); |
---|
3466 | return true; |
---|
3467 | } |
---|
3468 | } |
---|
3469 | while (strstr(line, MatrixType[sizeIdc][listIdc]) == NULL); |
---|
3470 | for (i=0; i<size; i++) |
---|
3471 | { |
---|
3472 | retval = fscanf(fp, "%d,", &data); |
---|
3473 | if (retval!=1) |
---|
3474 | { |
---|
3475 | printf("Error: can't read Matrix :: set Default Matrix\n"); |
---|
3476 | return true; |
---|
3477 | } |
---|
3478 | src[i] = data; |
---|
3479 | } |
---|
3480 | //set DC value for default matrix check |
---|
3481 | setScalingListDC(sizeIdc,listIdc,src[0]); |
---|
3482 | |
---|
3483 | if(sizeIdc > SCALING_LIST_8x8) |
---|
3484 | { |
---|
3485 | fseek(fp,0,0); |
---|
3486 | do |
---|
3487 | { |
---|
3488 | ret = fgets(line, 1024, fp); |
---|
3489 | if ((ret==NULL)||(strstr(line, MatrixType_DC[sizeIdc][listIdc])==NULL && feof(fp))) |
---|
3490 | { |
---|
3491 | printf("Error: can't read DC :: set Default Matrix\n"); |
---|
3492 | return true; |
---|
3493 | } |
---|
3494 | } |
---|
3495 | while (strstr(line, MatrixType_DC[sizeIdc][listIdc]) == NULL); |
---|
3496 | retval = fscanf(fp, "%d,", &data); |
---|
3497 | if (retval!=1) |
---|
3498 | { |
---|
3499 | printf("Error: can't read Matrix :: set Default Matrix\n"); |
---|
3500 | return true; |
---|
3501 | } |
---|
3502 | //overwrite DC value when size of matrix is larger than 16x16 |
---|
3503 | setScalingListDC(sizeIdc,listIdc,data); |
---|
3504 | } |
---|
3505 | } |
---|
3506 | } |
---|
3507 | fclose(fp); |
---|
3508 | return false; |
---|
3509 | } |
---|
3510 | |
---|
3511 | #if H_MV |
---|
3512 | Void TComScalingList::inferFrom( TComScalingList* srcScLi ) |
---|
3513 | { |
---|
3514 | for(Int sizeId = 0; sizeId < SCALING_LIST_SIZE_NUM; sizeId++) |
---|
3515 | { |
---|
3516 | for(Int listId = 0; listId < g_scalingListNum[sizeId]; listId++) |
---|
3517 | { |
---|
3518 | setRefMatrixId (sizeId,listId, srcScLi->getRefMatrixId (sizeId,listId)); |
---|
3519 | setScalingListDC(sizeId,listId, srcScLi->getScalingListDC(sizeId,listId)); |
---|
3520 | ::memcpy(getScalingListAddress(sizeId, listId),srcScLi->getScalingListAddress(sizeId, listId),sizeof(Int)*min(MAX_MATRIX_COEF_NUM,(Int)g_scalingListSize[sizeId])); |
---|
3521 | } |
---|
3522 | } |
---|
3523 | } |
---|
3524 | #endif |
---|
3525 | /** initialization process of quantization matrix array |
---|
3526 | */ |
---|
3527 | Void TComScalingList::init() |
---|
3528 | { |
---|
3529 | for(UInt sizeId = 0; sizeId < SCALING_LIST_SIZE_NUM; sizeId++) |
---|
3530 | { |
---|
3531 | for(UInt listId = 0; listId < g_scalingListNum[sizeId]; listId++) |
---|
3532 | { |
---|
3533 | m_scalingListCoef[sizeId][listId] = new Int [min(MAX_MATRIX_COEF_NUM,(Int)g_scalingListSize[sizeId])]; |
---|
3534 | } |
---|
3535 | } |
---|
3536 | m_scalingListCoef[SCALING_LIST_32x32][3] = m_scalingListCoef[SCALING_LIST_32x32][1]; // copy address for 32x32 |
---|
3537 | } |
---|
3538 | |
---|
3539 | /** destroy quantization matrix array |
---|
3540 | */ |
---|
3541 | Void TComScalingList::destroy() |
---|
3542 | { |
---|
3543 | for(UInt sizeId = 0; sizeId < SCALING_LIST_SIZE_NUM; sizeId++) |
---|
3544 | { |
---|
3545 | for(UInt listId = 0; listId < g_scalingListNum[sizeId]; listId++) |
---|
3546 | { |
---|
3547 | if(m_scalingListCoef[sizeId][listId]) delete [] m_scalingListCoef[sizeId][listId]; |
---|
3548 | } |
---|
3549 | } |
---|
3550 | } |
---|
3551 | |
---|
3552 | /** get default address of quantization matrix |
---|
3553 | * \param sizeId size index |
---|
3554 | * \param listId list index |
---|
3555 | * \returns pointer of quantization matrix |
---|
3556 | */ |
---|
3557 | Int* TComScalingList::getScalingListDefaultAddress(UInt sizeId, UInt listId) |
---|
3558 | { |
---|
3559 | Int *src = 0; |
---|
3560 | switch(sizeId) |
---|
3561 | { |
---|
3562 | case SCALING_LIST_4x4: |
---|
3563 | src = g_quantTSDefault4x4; |
---|
3564 | break; |
---|
3565 | case SCALING_LIST_8x8: |
---|
3566 | src = (listId<3) ? g_quantIntraDefault8x8 : g_quantInterDefault8x8; |
---|
3567 | break; |
---|
3568 | case SCALING_LIST_16x16: |
---|
3569 | src = (listId<3) ? g_quantIntraDefault8x8 : g_quantInterDefault8x8; |
---|
3570 | break; |
---|
3571 | case SCALING_LIST_32x32: |
---|
3572 | src = (listId<1) ? g_quantIntraDefault8x8 : g_quantInterDefault8x8; |
---|
3573 | break; |
---|
3574 | default: |
---|
3575 | assert(0); |
---|
3576 | src = NULL; |
---|
3577 | break; |
---|
3578 | } |
---|
3579 | return src; |
---|
3580 | } |
---|
3581 | |
---|
3582 | /** process of default matrix |
---|
3583 | * \param sizeId size index |
---|
3584 | * \param Index of input matrix |
---|
3585 | */ |
---|
3586 | Void TComScalingList::processDefaultMarix(UInt sizeId, UInt listId) |
---|
3587 | { |
---|
3588 | ::memcpy(getScalingListAddress(sizeId, listId),getScalingListDefaultAddress(sizeId,listId),sizeof(Int)*min(MAX_MATRIX_COEF_NUM,(Int)g_scalingListSize[sizeId])); |
---|
3589 | setScalingListDC(sizeId,listId,SCALING_LIST_DC); |
---|
3590 | } |
---|
3591 | |
---|
3592 | /** check DC value of matrix for default matrix signaling |
---|
3593 | */ |
---|
3594 | Void TComScalingList::checkDcOfMatrix() |
---|
3595 | { |
---|
3596 | for(UInt sizeId = 0; sizeId < SCALING_LIST_SIZE_NUM; sizeId++) |
---|
3597 | { |
---|
3598 | for(UInt listId = 0; listId < g_scalingListNum[sizeId]; listId++) |
---|
3599 | { |
---|
3600 | //check default matrix? |
---|
3601 | if(getScalingListDC(sizeId,listId) == 0) |
---|
3602 | { |
---|
3603 | processDefaultMarix(sizeId, listId); |
---|
3604 | } |
---|
3605 | } |
---|
3606 | } |
---|
3607 | } |
---|
3608 | |
---|
3609 | ParameterSetManager::ParameterSetManager() |
---|
3610 | : m_vpsMap(MAX_NUM_VPS) |
---|
3611 | , m_spsMap(MAX_NUM_SPS) |
---|
3612 | , m_ppsMap(MAX_NUM_PPS) |
---|
3613 | , m_activeVPSId(-1) |
---|
3614 | #if !H_MV |
---|
3615 | , m_activeSPSId(-1) |
---|
3616 | , m_activePPSId(-1) |
---|
3617 | { |
---|
3618 | #else |
---|
3619 | { |
---|
3620 | for (Int i = 0; i < MAX_NUM_LAYERS; i++ ) |
---|
3621 | { |
---|
3622 | m_activeSPSId[ i ] = -1; |
---|
3623 | m_activePPSId[ i ] = -1; |
---|
3624 | } |
---|
3625 | #endif |
---|
3626 | } |
---|
3627 | |
---|
3628 | |
---|
3629 | ParameterSetManager::~ParameterSetManager() |
---|
3630 | { |
---|
3631 | } |
---|
3632 | |
---|
3633 | //! activate a SPS from a active parameter sets SEI message |
---|
3634 | //! \returns true, if activation is successful |
---|
3635 | #if H_MV |
---|
3636 | Bool ParameterSetManager::activateSPSWithSEI(Int spsId, Int layerId ) |
---|
3637 | #else |
---|
3638 | Bool ParameterSetManager::activateSPSWithSEI(Int spsId) |
---|
3639 | #endif |
---|
3640 | { |
---|
3641 | TComSPS *sps = m_spsMap.getPS(spsId); |
---|
3642 | if (sps) |
---|
3643 | { |
---|
3644 | Int vpsId = sps->getVPSId(); |
---|
3645 | if (m_vpsMap.getPS(vpsId)) |
---|
3646 | { |
---|
3647 | m_activeVPSId = vpsId; |
---|
3648 | #if H_MV |
---|
3649 | m_activeSPSId[ layerId ] = spsId; |
---|
3650 | #else |
---|
3651 | m_activeSPSId = spsId; |
---|
3652 | #endif |
---|
3653 | return true; |
---|
3654 | } |
---|
3655 | else |
---|
3656 | { |
---|
3657 | printf("Warning: tried to activate SPS using an Active parameter sets SEI message. Referenced VPS does not exist."); |
---|
3658 | } |
---|
3659 | } |
---|
3660 | else |
---|
3661 | { |
---|
3662 | printf("Warning: tried to activate non-existing SPS using an Active parameter sets SEI message."); |
---|
3663 | } |
---|
3664 | return false; |
---|
3665 | } |
---|
3666 | |
---|
3667 | //! activate a PPS and depending on isIDR parameter also SPS and VPS |
---|
3668 | //! \returns true, if activation is successful |
---|
3669 | #if H_MV |
---|
3670 | Bool ParameterSetManager::activatePPS(Int ppsId, Bool isIRAP, Int layerId ) |
---|
3671 | #else |
---|
3672 | Bool ParameterSetManager::activatePPS(Int ppsId, Bool isIRAP) |
---|
3673 | #endif |
---|
3674 | { |
---|
3675 | TComPPS *pps = m_ppsMap.getPS(ppsId); |
---|
3676 | if (pps) |
---|
3677 | { |
---|
3678 | Int spsId = pps->getSPSId(); |
---|
3679 | #if H_MV |
---|
3680 | if (!isIRAP && (spsId != m_activeSPSId[ layerId ])) |
---|
3681 | #else |
---|
3682 | if (!isIRAP && (spsId != m_activeSPSId)) |
---|
3683 | #endif |
---|
3684 | { |
---|
3685 | printf("Warning: tried to activate PPS referring to a inactive SPS at non-IRAP."); |
---|
3686 | return false; |
---|
3687 | } |
---|
3688 | |
---|
3689 | TComSPS *sps = m_spsMap.getPS(spsId); |
---|
3690 | if (sps) |
---|
3691 | { |
---|
3692 | Int vpsId = sps->getVPSId(); |
---|
3693 | if (!isIRAP && (vpsId != m_activeVPSId)) |
---|
3694 | { |
---|
3695 | printf("Warning: tried to activate PPS referring to a inactive VPS at non-IRAP."); |
---|
3696 | return false; |
---|
3697 | } |
---|
3698 | if (m_vpsMap.getPS(vpsId)) |
---|
3699 | { |
---|
3700 | #if H_MV |
---|
3701 | m_activePPSId[ layerId ] = ppsId; |
---|
3702 | m_activeVPSId = vpsId; |
---|
3703 | m_activeSPSId[ layerId ] = spsId; |
---|
3704 | #else |
---|
3705 | m_activePPSId = ppsId; |
---|
3706 | m_activeVPSId = vpsId; |
---|
3707 | m_activeSPSId = spsId; |
---|
3708 | #endif |
---|
3709 | return true; |
---|
3710 | } |
---|
3711 | else |
---|
3712 | { |
---|
3713 | printf("Warning: tried to activate PPS that refers to a non-existing VPS."); |
---|
3714 | } |
---|
3715 | } |
---|
3716 | else |
---|
3717 | { |
---|
3718 | printf("Warning: tried to activate a PPS that refers to a non-existing SPS."); |
---|
3719 | } |
---|
3720 | } |
---|
3721 | else |
---|
3722 | { |
---|
3723 | printf("Warning: tried to activate non-existing PPS."); |
---|
3724 | } |
---|
3725 | return false; |
---|
3726 | } |
---|
3727 | |
---|
3728 | ProfileTierLevel::ProfileTierLevel() |
---|
3729 | : m_profileSpace (0) |
---|
3730 | , m_tierFlag (false) |
---|
3731 | , m_profileIdc (0) |
---|
3732 | , m_levelIdc (0) |
---|
3733 | , m_progressiveSourceFlag (false) |
---|
3734 | , m_interlacedSourceFlag (false) |
---|
3735 | , m_nonPackedConstraintFlag(false) |
---|
3736 | , m_frameOnlyConstraintFlag(false) |
---|
3737 | { |
---|
3738 | ::memset(m_profileCompatibilityFlag, 0, sizeof(m_profileCompatibilityFlag)); |
---|
3739 | } |
---|
3740 | |
---|
3741 | TComPTL::TComPTL() |
---|
3742 | { |
---|
3743 | ::memset(m_subLayerProfilePresentFlag, 0, sizeof(m_subLayerProfilePresentFlag)); |
---|
3744 | ::memset(m_subLayerLevelPresentFlag, 0, sizeof(m_subLayerLevelPresentFlag )); |
---|
3745 | } |
---|
3746 | |
---|
3747 | #if H_MV |
---|
3748 | Void TComPTL::copyLevelFrom( TComPTL* source ) |
---|
3749 | { |
---|
3750 | getGeneralPTL()->setLevelIdc( source->getGeneralPTL()->getLevelIdc() ); |
---|
3751 | for( Int subLayer = 0; subLayer < 6; subLayer++ ) |
---|
3752 | { |
---|
3753 | setSubLayerLevelPresentFlag( subLayer, source->getSubLayerLevelPresentFlag( subLayer ) ); |
---|
3754 | getSubLayerPTL( subLayer )->setLevelIdc( source->getSubLayerPTL( subLayer )->getLevelIdc() ); |
---|
3755 | } |
---|
3756 | } |
---|
3757 | #endif |
---|
3758 | //! \} |
---|
3759 | |
---|
3760 | #if H_MV |
---|
3761 | TComVPSVUI::TComVPSVUI() |
---|
3762 | { |
---|
3763 | m_crossLayerIrapAlignedFlag = true; |
---|
3764 | m_bitRatePresentVpsFlag = false; |
---|
3765 | m_picRatePresentVpsFlag = false; |
---|
3766 | for ( Int i = 0; i < MAX_VPS_OP_SETS_PLUS1; i++) |
---|
3767 | { |
---|
3768 | for ( Int j = 0; j < MAX_TLAYER; j++) |
---|
3769 | { |
---|
3770 | m_bitRatePresentFlag [i][j] = false; |
---|
3771 | m_picRatePresentFlag [i][j] = false; |
---|
3772 | m_avgBitRate [i][j] = -1; |
---|
3773 | m_maxBitRate [i][j] = -1; |
---|
3774 | m_constantPicRateIdc [i][j] = -1; |
---|
3775 | m_avgPicRate [i][j] = -1; |
---|
3776 | } |
---|
3777 | } |
---|
3778 | |
---|
3779 | m_ilpRestrictedRefLayersFlag = false; |
---|
3780 | |
---|
3781 | for ( Int i = 0; i < MAX_NUM_LAYERS; i++) |
---|
3782 | { |
---|
3783 | for ( Int j = 0; j < MAX_NUM_LAYERS; j++) |
---|
3784 | { |
---|
3785 | m_tileBoundariesAlignedFlag [i][j] = false; |
---|
3786 | m_minSpatialSegmentOffsetPlus1[i][j] = 0; |
---|
3787 | m_ctuBasedOffsetEnabledFlag [i][j] = false; |
---|
3788 | m_minHorizontalCtuOffsetPlus1 [i][j] = -1; |
---|
3789 | } |
---|
3790 | } |
---|
3791 | for ( Int i = 0; i < MAX_NUM_VIDEO_SIGNAL_INFO; i++ ) |
---|
3792 | { |
---|
3793 | m_videoSignalInfo [i] = NULL; |
---|
3794 | } |
---|
3795 | |
---|
3796 | m_vpsVuiBspHrdPresentFlag = false; |
---|
3797 | m_vpsVuiBspHrdParameters = new TComVpsVuiBspHrdParameters(); |
---|
3798 | } |
---|
3799 | |
---|
3800 | TComVPSVUI::~TComVPSVUI() |
---|
3801 | { |
---|
3802 | for ( Int i = 0; i < MAX_NUM_VIDEO_SIGNAL_INFO; i++ ) |
---|
3803 | { |
---|
3804 | if (m_videoSignalInfo[ i ] != NULL ) delete m_videoSignalInfo[ i ]; |
---|
3805 | m_videoSignalInfo [ i ] = NULL; |
---|
3806 | } |
---|
3807 | |
---|
3808 | if ( m_vpsVuiBspHrdParameters ) delete m_vpsVuiBspHrdParameters; |
---|
3809 | m_vpsVuiBspHrdParameters = NULL; |
---|
3810 | } |
---|
3811 | |
---|
3812 | Void TComRepFormat::inferChromaAndBitDepth( TComRepFormat* prevRepFormat, Bool encoderFlag ) |
---|
3813 | { |
---|
3814 | if ( !encoderFlag ) |
---|
3815 | { |
---|
3816 | setChromaAndBitDepthVpsPresentFlag( prevRepFormat->getChromaAndBitDepthVpsPresentFlag() ); |
---|
3817 | setSeparateColourPlaneVpsFlag ( prevRepFormat->getSeparateColourPlaneVpsFlag () ); |
---|
3818 | setBitDepthVpsLumaMinus8 ( prevRepFormat->getBitDepthVpsLumaMinus8 () ); |
---|
3819 | setBitDepthVpsChromaMinus8 ( prevRepFormat->getBitDepthVpsChromaMinus8 () ); |
---|
3820 | } |
---|
3821 | else |
---|
3822 | { |
---|
3823 | assert( getChromaAndBitDepthVpsPresentFlag() == prevRepFormat->getChromaAndBitDepthVpsPresentFlag() ); |
---|
3824 | assert( getSeparateColourPlaneVpsFlag () == prevRepFormat->getSeparateColourPlaneVpsFlag () ); |
---|
3825 | assert( getBitDepthVpsLumaMinus8 () == prevRepFormat->getBitDepthVpsLumaMinus8 () ); |
---|
3826 | assert( getBitDepthVpsChromaMinus8 () == prevRepFormat->getBitDepthVpsChromaMinus8 () ); |
---|
3827 | } |
---|
3828 | } |
---|
3829 | |
---|
3830 | Void TComVpsVuiBspHrdParameters::checkLayerInBspFlag( TComVPS* vps, Int h ) |
---|
3831 | { |
---|
3832 | // It is a requirement of bitstream conformance that bitstream partition with index j shall not include |
---|
3833 | // direct or indirect reference layers of any layers in bitstream partition i for any values of i and j |
---|
3834 | // in the range of 0 to num_bitstream_partitions[ h ] ?1, inclusive, such that i is less than j. |
---|
3835 | |
---|
3836 | for ( Int partJ = 0; partJ < getNumBitstreamPartitions( h ); partJ++ ) |
---|
3837 | { |
---|
3838 | for ( Int partI = 0; partI < partJ; partI++ ) |
---|
3839 | { |
---|
3840 | for ( Int layerJ = 0; layerJ < vps->getMaxLayersMinus1(); layerJ++ ) |
---|
3841 | { |
---|
3842 | if ( m_layerInBspFlag[ h ][partJ][layerJ ] ) |
---|
3843 | { |
---|
3844 | for ( Int layerI = 0; layerI < vps->getMaxLayersMinus1(); layerI++ ) |
---|
3845 | { |
---|
3846 | if ( m_layerInBspFlag[ h ][partI][layerI] ) |
---|
3847 | { |
---|
3848 | assert( !vps->getInDirectDependencyFlag( layerI, layerJ ) ); |
---|
3849 | } |
---|
3850 | } |
---|
3851 | } |
---|
3852 | } |
---|
3853 | } |
---|
3854 | } |
---|
3855 | } |
---|
3856 | |
---|
3857 | Void TComVUI::inferVideoSignalInfo( TComVPS* vps, Int layerIdCurr ) |
---|
3858 | { |
---|
3859 | if ( layerIdCurr == 0 || !vps->getVpsVuiPresentFlag() ) |
---|
3860 | { |
---|
3861 | return; |
---|
3862 | } |
---|
3863 | |
---|
3864 | TComVPSVUI* vpsVUI = vps->getVPSVUI(); |
---|
3865 | assert( vpsVUI != NULL ); |
---|
3866 | |
---|
3867 | TComVideoSignalInfo* videoSignalInfo = vpsVUI->getVideoSignalInfo( vpsVUI->getVpsVideoSignalInfoIdx( vps->getLayerIdInVps( layerIdCurr ) ) ); |
---|
3868 | assert( videoSignalInfo != NULL ); |
---|
3869 | |
---|
3870 | setVideoFormat ( videoSignalInfo->getVideoVpsFormat () ); |
---|
3871 | setVideoFullRangeFlag ( videoSignalInfo->getVideoFullRangeVpsFlag () ); |
---|
3872 | setColourPrimaries ( videoSignalInfo->getColourPrimariesVps () ); |
---|
3873 | setTransferCharacteristics( videoSignalInfo->getTransferCharacteristicsVps() ); |
---|
3874 | setMatrixCoefficients ( videoSignalInfo->getMatrixCoeffsVps () ); |
---|
3875 | } |
---|
3876 | #endif |
---|