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_refPicSetInterLayer ( NULL ) |
---|
104 | , m_layerId (0) |
---|
105 | , m_viewId (0) |
---|
106 | #if H_3D |
---|
107 | , m_viewIndex (0) |
---|
108 | , m_isDepth (false) |
---|
109 | #endif |
---|
110 | , m_discardableFlag (false) |
---|
111 | , m_interLayerPredEnabledFlag (false) |
---|
112 | , m_numInterLayerRefPicsMinus1 (0) |
---|
113 | , m_interLayerSamplePredOnlyFlag (false) |
---|
114 | , m_altCollocatedIndicationFlag (0) |
---|
115 | , m_collocatedRefLayerIdx (0) |
---|
116 | #if H_3D_IC |
---|
117 | , m_bApplyIC ( false ) |
---|
118 | , m_icSkipParseFlag ( false ) |
---|
119 | #endif |
---|
120 | #if H_3D |
---|
121 | , m_depthToDisparityB ( NULL ) |
---|
122 | , m_depthToDisparityF ( NULL ) |
---|
123 | #endif |
---|
124 | #endif |
---|
125 | { |
---|
126 | m_aiNumRefIdx[0] = m_aiNumRefIdx[1] = 0; |
---|
127 | |
---|
128 | initEqualRef(); |
---|
129 | |
---|
130 | for ( Int idx = 0; idx < MAX_NUM_REF; idx++ ) |
---|
131 | { |
---|
132 | m_list1IdxToList0Idx[idx] = -1; |
---|
133 | } |
---|
134 | for(Int iNumCount = 0; iNumCount < MAX_NUM_REF; iNumCount++) |
---|
135 | { |
---|
136 | m_apcRefPicList [0][iNumCount] = NULL; |
---|
137 | m_apcRefPicList [1][iNumCount] = NULL; |
---|
138 | m_aiRefPOCList [0][iNumCount] = 0; |
---|
139 | m_aiRefPOCList [1][iNumCount] = 0; |
---|
140 | #if H_MV |
---|
141 | m_aiRefLayerIdList[0][iNumCount] = 0; |
---|
142 | m_aiRefLayerIdList[1][iNumCount] = 0; |
---|
143 | #endif |
---|
144 | } |
---|
145 | resetWpScaling(); |
---|
146 | initWpAcDcParam(); |
---|
147 | m_saoEnabledFlag = false; |
---|
148 | #if H_MV |
---|
149 | for (Int i = 0; i < MAX_NUM_LAYERS; i++ ) |
---|
150 | { |
---|
151 | m_interLayerPredLayerIdc[ i ] = 0; |
---|
152 | } |
---|
153 | #endif |
---|
154 | } |
---|
155 | |
---|
156 | TComSlice::~TComSlice() |
---|
157 | { |
---|
158 | delete[] m_puiSubstreamSizes; |
---|
159 | m_puiSubstreamSizes = NULL; |
---|
160 | #if H_3D |
---|
161 | for( UInt i = 0; i < getViewIndex(); i++ ) |
---|
162 | { |
---|
163 | if ( m_depthToDisparityB && m_depthToDisparityB[ i ] ) |
---|
164 | delete[] m_depthToDisparityB [ i ]; |
---|
165 | |
---|
166 | if ( m_depthToDisparityF && m_depthToDisparityF[ i ] ) |
---|
167 | delete[] m_depthToDisparityF [ i ]; |
---|
168 | } |
---|
169 | |
---|
170 | if ( m_depthToDisparityF ) |
---|
171 | delete[] m_depthToDisparityF; |
---|
172 | |
---|
173 | m_depthToDisparityF = NULL; |
---|
174 | |
---|
175 | if ( m_depthToDisparityB ) |
---|
176 | delete[] m_depthToDisparityB; |
---|
177 | |
---|
178 | m_depthToDisparityB = NULL; |
---|
179 | #endif |
---|
180 | } |
---|
181 | |
---|
182 | |
---|
183 | Void TComSlice::initSlice() |
---|
184 | { |
---|
185 | m_aiNumRefIdx[0] = 0; |
---|
186 | m_aiNumRefIdx[1] = 0; |
---|
187 | |
---|
188 | m_colFromL0Flag = 1; |
---|
189 | |
---|
190 | m_colRefIdx = 0; |
---|
191 | initEqualRef(); |
---|
192 | m_bCheckLDC = false; |
---|
193 | m_iSliceQpDeltaCb = 0; |
---|
194 | m_iSliceQpDeltaCr = 0; |
---|
195 | |
---|
196 | #if H_3D_IV_MERGE |
---|
197 | m_maxNumMergeCand = MRG_MAX_NUM_CANDS_MEM; |
---|
198 | #else |
---|
199 | m_maxNumMergeCand = MRG_MAX_NUM_CANDS; |
---|
200 | #endif |
---|
201 | |
---|
202 | m_bFinalized=false; |
---|
203 | |
---|
204 | m_tileByteLocation.clear(); |
---|
205 | m_cabacInitFlag = false; |
---|
206 | m_numEntryPointOffsets = 0; |
---|
207 | m_enableTMVPFlag = true; |
---|
208 | #if H_3D_TMVP |
---|
209 | m_aiAlterRefIdx[0] = -1; |
---|
210 | m_aiAlterRefIdx[1] = -1; |
---|
211 | #endif |
---|
212 | } |
---|
213 | |
---|
214 | Bool TComSlice::getRapPicFlag() |
---|
215 | { |
---|
216 | return getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_W_RADL |
---|
217 | || getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_N_LP |
---|
218 | || getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_N_LP |
---|
219 | || getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_RADL |
---|
220 | || getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_LP |
---|
221 | || getNalUnitType() == NAL_UNIT_CODED_SLICE_CRA; |
---|
222 | } |
---|
223 | |
---|
224 | /** |
---|
225 | - allocate table to contain substream sizes to be written to the slice header. |
---|
226 | . |
---|
227 | \param uiNumSubstreams Number of substreams -- the allocation will be this value - 1. |
---|
228 | */ |
---|
229 | Void TComSlice::allocSubstreamSizes(UInt uiNumSubstreams) |
---|
230 | { |
---|
231 | delete[] m_puiSubstreamSizes; |
---|
232 | m_puiSubstreamSizes = new UInt[uiNumSubstreams > 0 ? uiNumSubstreams-1 : 0]; |
---|
233 | } |
---|
234 | |
---|
235 | Void TComSlice::sortPicList (TComList<TComPic*>& rcListPic) |
---|
236 | { |
---|
237 | TComPic* pcPicExtract; |
---|
238 | TComPic* pcPicInsert; |
---|
239 | |
---|
240 | TComList<TComPic*>::iterator iterPicExtract; |
---|
241 | TComList<TComPic*>::iterator iterPicExtract_1; |
---|
242 | TComList<TComPic*>::iterator iterPicInsert; |
---|
243 | |
---|
244 | for (Int i = 1; i < (Int)(rcListPic.size()); i++) |
---|
245 | { |
---|
246 | iterPicExtract = rcListPic.begin(); |
---|
247 | for (Int j = 0; j < i; j++) iterPicExtract++; |
---|
248 | pcPicExtract = *(iterPicExtract); |
---|
249 | pcPicExtract->setCurrSliceIdx(0); |
---|
250 | |
---|
251 | iterPicInsert = rcListPic.begin(); |
---|
252 | while (iterPicInsert != iterPicExtract) |
---|
253 | { |
---|
254 | pcPicInsert = *(iterPicInsert); |
---|
255 | pcPicInsert->setCurrSliceIdx(0); |
---|
256 | if (pcPicInsert->getPOC() >= pcPicExtract->getPOC()) |
---|
257 | { |
---|
258 | break; |
---|
259 | } |
---|
260 | |
---|
261 | iterPicInsert++; |
---|
262 | } |
---|
263 | |
---|
264 | iterPicExtract_1 = iterPicExtract; iterPicExtract_1++; |
---|
265 | |
---|
266 | // swap iterPicExtract and iterPicInsert, iterPicExtract = curr. / iterPicInsert = insertion position |
---|
267 | rcListPic.insert (iterPicInsert, iterPicExtract, iterPicExtract_1); |
---|
268 | rcListPic.erase (iterPicExtract); |
---|
269 | } |
---|
270 | } |
---|
271 | |
---|
272 | TComPic* TComSlice::xGetRefPic (TComList<TComPic*>& rcListPic, |
---|
273 | Int poc) |
---|
274 | { |
---|
275 | TComList<TComPic*>::iterator iterPic = rcListPic.begin(); |
---|
276 | TComPic* pcPic = *(iterPic); |
---|
277 | while ( iterPic != rcListPic.end() ) |
---|
278 | { |
---|
279 | if(pcPic->getPOC() == poc) |
---|
280 | { |
---|
281 | break; |
---|
282 | } |
---|
283 | iterPic++; |
---|
284 | pcPic = *(iterPic); |
---|
285 | } |
---|
286 | return pcPic; |
---|
287 | } |
---|
288 | |
---|
289 | |
---|
290 | TComPic* TComSlice::xGetLongTermRefPic(TComList<TComPic*>& rcListPic, Int poc, Bool pocHasMsb) |
---|
291 | { |
---|
292 | TComList<TComPic*>::iterator iterPic = rcListPic.begin(); |
---|
293 | TComPic* pcPic = *(iterPic); |
---|
294 | TComPic* pcStPic = pcPic; |
---|
295 | |
---|
296 | Int pocCycle = 1 << getSPS()->getBitsForPOC(); |
---|
297 | if (!pocHasMsb) |
---|
298 | { |
---|
299 | poc = poc % pocCycle; |
---|
300 | } |
---|
301 | |
---|
302 | while ( iterPic != rcListPic.end() ) |
---|
303 | { |
---|
304 | pcPic = *(iterPic); |
---|
305 | if (pcPic && pcPic->getPOC()!=this->getPOC() && pcPic->getSlice( 0 )->isReferenced()) |
---|
306 | { |
---|
307 | Int picPoc = pcPic->getPOC(); |
---|
308 | if (!pocHasMsb) |
---|
309 | { |
---|
310 | picPoc = picPoc % pocCycle; |
---|
311 | } |
---|
312 | |
---|
313 | if (poc == picPoc) |
---|
314 | { |
---|
315 | if(pcPic->getIsLongTerm()) |
---|
316 | { |
---|
317 | return pcPic; |
---|
318 | } |
---|
319 | else |
---|
320 | { |
---|
321 | pcStPic = pcPic; |
---|
322 | } |
---|
323 | break; |
---|
324 | } |
---|
325 | } |
---|
326 | |
---|
327 | iterPic++; |
---|
328 | } |
---|
329 | |
---|
330 | return pcStPic; |
---|
331 | } |
---|
332 | |
---|
333 | Void TComSlice::setRefPOCList () |
---|
334 | { |
---|
335 | for (Int iDir = 0; iDir < 2; iDir++) |
---|
336 | { |
---|
337 | for (Int iNumRefIdx = 0; iNumRefIdx < m_aiNumRefIdx[iDir]; iNumRefIdx++) |
---|
338 | { |
---|
339 | m_aiRefPOCList[iDir][iNumRefIdx] = m_apcRefPicList[iDir][iNumRefIdx]->getPOC(); |
---|
340 | #if H_MV |
---|
341 | m_aiRefLayerIdList[iDir][iNumRefIdx] = m_apcRefPicList[iDir][iNumRefIdx]->getLayerId(); |
---|
342 | #endif |
---|
343 | } |
---|
344 | } |
---|
345 | |
---|
346 | } |
---|
347 | |
---|
348 | Void TComSlice::setList1IdxToList0Idx() |
---|
349 | { |
---|
350 | Int idxL0, idxL1; |
---|
351 | for ( idxL1 = 0; idxL1 < getNumRefIdx( REF_PIC_LIST_1 ); idxL1++ ) |
---|
352 | { |
---|
353 | m_list1IdxToList0Idx[idxL1] = -1; |
---|
354 | for ( idxL0 = 0; idxL0 < getNumRefIdx( REF_PIC_LIST_0 ); idxL0++ ) |
---|
355 | { |
---|
356 | if ( m_apcRefPicList[REF_PIC_LIST_0][idxL0]->getPOC() == m_apcRefPicList[REF_PIC_LIST_1][idxL1]->getPOC() ) |
---|
357 | { |
---|
358 | m_list1IdxToList0Idx[idxL1] = idxL0; |
---|
359 | break; |
---|
360 | } |
---|
361 | } |
---|
362 | } |
---|
363 | } |
---|
364 | #if H_MV |
---|
365 | Void TComSlice::setRefPicList( TComList<TComPic*>& rcListPic, std::vector<TComPic*>& refPicSetInterLayer , Bool checkNumPocTotalCurr) |
---|
366 | #else |
---|
367 | #if FIX1071 |
---|
368 | Void TComSlice::setRefPicList( TComList<TComPic*>& rcListPic, Bool checkNumPocTotalCurr ) |
---|
369 | #else |
---|
370 | Void TComSlice::setRefPicList( TComList<TComPic*>& rcListPic ) |
---|
371 | #endif |
---|
372 | #endif |
---|
373 | { |
---|
374 | #if FIX1071 |
---|
375 | if (!checkNumPocTotalCurr) |
---|
376 | #endif |
---|
377 | { |
---|
378 | if (m_eSliceType == I_SLICE) |
---|
379 | { |
---|
380 | ::memset( m_apcRefPicList, 0, sizeof (m_apcRefPicList)); |
---|
381 | ::memset( m_aiNumRefIdx, 0, sizeof ( m_aiNumRefIdx )); |
---|
382 | |
---|
383 | return; |
---|
384 | } |
---|
385 | |
---|
386 | #if !H_MV |
---|
387 | m_aiNumRefIdx[0] = getNumRefIdx(REF_PIC_LIST_0); |
---|
388 | m_aiNumRefIdx[1] = getNumRefIdx(REF_PIC_LIST_1); |
---|
389 | #endif |
---|
390 | } |
---|
391 | |
---|
392 | TComPic* pcRefPic= NULL; |
---|
393 | TComPic* RefPicSetStCurr0[16]; |
---|
394 | TComPic* RefPicSetStCurr1[16]; |
---|
395 | TComPic* RefPicSetLtCurr[16]; |
---|
396 | UInt NumPocStCurr0 = 0; |
---|
397 | UInt NumPocStCurr1 = 0; |
---|
398 | UInt NumPocLtCurr = 0; |
---|
399 | Int i; |
---|
400 | |
---|
401 | for(i=0; i < m_pcRPS->getNumberOfNegativePictures(); i++) |
---|
402 | { |
---|
403 | if(m_pcRPS->getUsed(i)) |
---|
404 | { |
---|
405 | pcRefPic = xGetRefPic(rcListPic, getPOC()+m_pcRPS->getDeltaPOC(i)); |
---|
406 | pcRefPic->setIsLongTerm(0); |
---|
407 | pcRefPic->getPicYuvRec()->extendPicBorder(); |
---|
408 | RefPicSetStCurr0[NumPocStCurr0] = pcRefPic; |
---|
409 | NumPocStCurr0++; |
---|
410 | pcRefPic->setCheckLTMSBPresent(false); |
---|
411 | } |
---|
412 | } |
---|
413 | |
---|
414 | for(; i < m_pcRPS->getNumberOfNegativePictures()+m_pcRPS->getNumberOfPositivePictures(); i++) |
---|
415 | { |
---|
416 | if(m_pcRPS->getUsed(i)) |
---|
417 | { |
---|
418 | pcRefPic = xGetRefPic(rcListPic, getPOC()+m_pcRPS->getDeltaPOC(i)); |
---|
419 | pcRefPic->setIsLongTerm(0); |
---|
420 | pcRefPic->getPicYuvRec()->extendPicBorder(); |
---|
421 | RefPicSetStCurr1[NumPocStCurr1] = pcRefPic; |
---|
422 | NumPocStCurr1++; |
---|
423 | pcRefPic->setCheckLTMSBPresent(false); |
---|
424 | } |
---|
425 | } |
---|
426 | |
---|
427 | for(i = m_pcRPS->getNumberOfNegativePictures()+m_pcRPS->getNumberOfPositivePictures()+m_pcRPS->getNumberOfLongtermPictures()-1; i > m_pcRPS->getNumberOfNegativePictures()+m_pcRPS->getNumberOfPositivePictures()-1 ; i--) |
---|
428 | { |
---|
429 | if(m_pcRPS->getUsed(i)) |
---|
430 | { |
---|
431 | pcRefPic = xGetLongTermRefPic(rcListPic, m_pcRPS->getPOC(i), m_pcRPS->getCheckLTMSBPresent(i)); |
---|
432 | pcRefPic->setIsLongTerm(1); |
---|
433 | pcRefPic->getPicYuvRec()->extendPicBorder(); |
---|
434 | RefPicSetLtCurr[NumPocLtCurr] = pcRefPic; |
---|
435 | NumPocLtCurr++; |
---|
436 | } |
---|
437 | if(pcRefPic==NULL) |
---|
438 | { |
---|
439 | pcRefPic = xGetLongTermRefPic(rcListPic, m_pcRPS->getPOC(i), m_pcRPS->getCheckLTMSBPresent(i)); |
---|
440 | } |
---|
441 | pcRefPic->setCheckLTMSBPresent(m_pcRPS->getCheckLTMSBPresent(i)); |
---|
442 | } |
---|
443 | |
---|
444 | // ref_pic_list_init |
---|
445 | TComPic* rpsCurrList0[MAX_NUM_REF+1]; |
---|
446 | TComPic* rpsCurrList1[MAX_NUM_REF+1]; |
---|
447 | #if H_MV |
---|
448 | Int numPocInterCurr = NumPocStCurr0 + NumPocStCurr1 + NumPocLtCurr; |
---|
449 | assert( numPocInterCurr == 0 || getInterRefEnabledInRPLFlag() ); |
---|
450 | Int numPocTotalCurr = numPocInterCurr + getNumActiveRefLayerPics( ); |
---|
451 | assert( numPocTotalCurr == getNumRpsCurrTempList() ); |
---|
452 | #else |
---|
453 | Int numPocTotalCurr = NumPocStCurr0 + NumPocStCurr1 + NumPocLtCurr; |
---|
454 | #endif |
---|
455 | #if FIX1071 |
---|
456 | if (checkNumPocTotalCurr) |
---|
457 | { |
---|
458 | // 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: |
---|
459 | #if H_MV |
---|
460 | // – 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. |
---|
461 | // – Otherwise, when the current picture contains a P or B slice, the value of NumPocTotalCurr shall not be equal to 0. |
---|
462 | if ( getRapPicFlag() && m_layerId == 0 ) |
---|
463 | #else |
---|
464 | // – If the current picture is a BLA or CRA picture, the value of NumPocTotalCurr shall be equal to 0. |
---|
465 | // – Otherwise, when the current picture contains a P or B slice, the value of NumPocTotalCurr shall not be equal to 0. |
---|
466 | if (getRapPicFlag()) |
---|
467 | #endif |
---|
468 | { |
---|
469 | assert(numPocTotalCurr == 0); |
---|
470 | } |
---|
471 | |
---|
472 | if (m_eSliceType == I_SLICE) |
---|
473 | { |
---|
474 | ::memset( m_apcRefPicList, 0, sizeof (m_apcRefPicList)); |
---|
475 | ::memset( m_aiNumRefIdx, 0, sizeof ( m_aiNumRefIdx )); |
---|
476 | |
---|
477 | return; |
---|
478 | } |
---|
479 | |
---|
480 | assert(numPocTotalCurr > 0); |
---|
481 | |
---|
482 | m_aiNumRefIdx[0] = getNumRefIdx(REF_PIC_LIST_0); |
---|
483 | m_aiNumRefIdx[1] = getNumRefIdx(REF_PIC_LIST_1); |
---|
484 | } |
---|
485 | #endif |
---|
486 | |
---|
487 | Int cIdx = 0; |
---|
488 | #if H_MV |
---|
489 | if ( getInterRefEnabledInRPLFlag() ) |
---|
490 | { |
---|
491 | #endif |
---|
492 | for ( i=0; i<NumPocStCurr0; i++, cIdx++) |
---|
493 | { |
---|
494 | rpsCurrList0[cIdx] = RefPicSetStCurr0[i]; |
---|
495 | } |
---|
496 | for ( i=0; i<NumPocStCurr1; i++, cIdx++) |
---|
497 | { |
---|
498 | rpsCurrList0[cIdx] = RefPicSetStCurr1[i]; |
---|
499 | } |
---|
500 | for ( i=0; i<NumPocLtCurr; i++, cIdx++) |
---|
501 | { |
---|
502 | rpsCurrList0[cIdx] = RefPicSetLtCurr[i]; |
---|
503 | } |
---|
504 | #if H_MV |
---|
505 | } |
---|
506 | for ( i=0; i < getNumActiveRefLayerPics( ); i++, cIdx++) |
---|
507 | { |
---|
508 | assert( cIdx < MAX_NUM_REF ); |
---|
509 | rpsCurrList0[cIdx] = refPicSetInterLayer[i]; |
---|
510 | } |
---|
511 | #endif |
---|
512 | assert(cIdx == numPocTotalCurr); |
---|
513 | |
---|
514 | if (m_eSliceType==B_SLICE) |
---|
515 | { |
---|
516 | cIdx = 0; |
---|
517 | #if H_MV |
---|
518 | if ( getInterRefEnabledInRPLFlag() ) |
---|
519 | { |
---|
520 | #endif |
---|
521 | for ( i=0; i<NumPocStCurr1; i++, cIdx++) |
---|
522 | { |
---|
523 | rpsCurrList1[cIdx] = RefPicSetStCurr1[i]; |
---|
524 | } |
---|
525 | for ( i=0; i<NumPocStCurr0; i++, cIdx++) |
---|
526 | { |
---|
527 | rpsCurrList1[cIdx] = RefPicSetStCurr0[i]; |
---|
528 | } |
---|
529 | for ( i=0; i<NumPocLtCurr; i++, cIdx++) |
---|
530 | { |
---|
531 | rpsCurrList1[cIdx] = RefPicSetLtCurr[i]; |
---|
532 | } |
---|
533 | #if H_MV |
---|
534 | } |
---|
535 | for ( i=0; i < getNumActiveRefLayerPics( ); i++, cIdx++) |
---|
536 | { |
---|
537 | assert( cIdx < MAX_NUM_REF ); |
---|
538 | rpsCurrList1[cIdx] = refPicSetInterLayer[i]; |
---|
539 | } |
---|
540 | #endif |
---|
541 | assert(cIdx == numPocTotalCurr); |
---|
542 | } |
---|
543 | |
---|
544 | ::memset(m_bIsUsedAsLongTerm, 0, sizeof(m_bIsUsedAsLongTerm)); |
---|
545 | |
---|
546 | #if H_MV |
---|
547 | Int numPocSt = NumPocStCurr0 + NumPocStCurr1; |
---|
548 | assert( getInterRefEnabledInRPLFlag( ) || numPocSt == 0 ); |
---|
549 | |
---|
550 | for (Int li = 0; li < 2; li++) |
---|
551 | { |
---|
552 | if ( m_eSliceType == P_SLICE && li == 1 ) |
---|
553 | { |
---|
554 | m_aiNumRefIdx[1] = 0; |
---|
555 | ::memset( m_apcRefPicList[1], 0, sizeof(m_apcRefPicList[1])); |
---|
556 | } |
---|
557 | else |
---|
558 | { |
---|
559 | for (Int rIdx = 0; rIdx <= (m_aiNumRefIdx[ li ] - 1 ); rIdx ++) |
---|
560 | { |
---|
561 | Bool listModified = m_RefPicListModification.getRefPicListModificationFlagL( li ); |
---|
562 | Int orgIdx = listModified ? m_RefPicListModification.getRefPicSetIdxL(li, rIdx) : (rIdx % numPocTotalCurr); |
---|
563 | |
---|
564 | m_apcRefPicList [li][rIdx] = ( li == 0 ) ? rpsCurrList0[ orgIdx ] : rpsCurrList1[ orgIdx ]; |
---|
565 | m_bIsUsedAsLongTerm[li][rIdx] = ( orgIdx >= numPocSt ) ; |
---|
566 | } |
---|
567 | } |
---|
568 | } |
---|
569 | #else |
---|
570 | for (Int rIdx = 0; rIdx < m_aiNumRefIdx[0]; rIdx ++) |
---|
571 | { |
---|
572 | cIdx = m_RefPicListModification.getRefPicListModificationFlagL0() ? m_RefPicListModification.getRefPicSetIdxL0(rIdx) : rIdx % numPocTotalCurr; |
---|
573 | assert(cIdx >= 0 && cIdx < numPocTotalCurr); |
---|
574 | m_apcRefPicList[0][rIdx] = rpsCurrList0[ cIdx ]; |
---|
575 | m_bIsUsedAsLongTerm[0][rIdx] = ( cIdx >= NumPocStCurr0 + NumPocStCurr1 ); |
---|
576 | } |
---|
577 | if ( m_eSliceType != B_SLICE ) |
---|
578 | { |
---|
579 | m_aiNumRefIdx[1] = 0; |
---|
580 | ::memset( m_apcRefPicList[1], 0, sizeof(m_apcRefPicList[1])); |
---|
581 | } |
---|
582 | else |
---|
583 | { |
---|
584 | for (Int rIdx = 0; rIdx < m_aiNumRefIdx[1]; rIdx ++) |
---|
585 | { |
---|
586 | cIdx = m_RefPicListModification.getRefPicListModificationFlagL1() ? m_RefPicListModification.getRefPicSetIdxL1(rIdx) : rIdx % numPocTotalCurr; |
---|
587 | assert(cIdx >= 0 && cIdx < numPocTotalCurr); |
---|
588 | m_apcRefPicList[1][rIdx] = rpsCurrList1[ cIdx ]; |
---|
589 | m_bIsUsedAsLongTerm[1][rIdx] = ( cIdx >= NumPocStCurr0 + NumPocStCurr1 ); |
---|
590 | } |
---|
591 | } |
---|
592 | #endif |
---|
593 | } |
---|
594 | |
---|
595 | Int TComSlice::getNumRpsCurrTempList() |
---|
596 | { |
---|
597 | Int numRpsCurrTempList = 0; |
---|
598 | |
---|
599 | if (m_eSliceType == I_SLICE) |
---|
600 | { |
---|
601 | return 0; |
---|
602 | } |
---|
603 | for(UInt i=0; i < m_pcRPS->getNumberOfNegativePictures()+ m_pcRPS->getNumberOfPositivePictures() + m_pcRPS->getNumberOfLongtermPictures(); i++) |
---|
604 | { |
---|
605 | if(m_pcRPS->getUsed(i)) |
---|
606 | { |
---|
607 | numRpsCurrTempList++; |
---|
608 | } |
---|
609 | } |
---|
610 | #if H_MV |
---|
611 | assert( ( numRpsCurrTempList == 0 ) || getInterRefEnabledInRPLFlag() ); |
---|
612 | numRpsCurrTempList = numRpsCurrTempList + getNumActiveRefLayerPics(); |
---|
613 | #endif |
---|
614 | return numRpsCurrTempList; |
---|
615 | } |
---|
616 | |
---|
617 | Void TComSlice::initEqualRef() |
---|
618 | { |
---|
619 | for (Int iDir = 0; iDir < 2; iDir++) |
---|
620 | { |
---|
621 | for (Int iRefIdx1 = 0; iRefIdx1 < MAX_NUM_REF; iRefIdx1++) |
---|
622 | { |
---|
623 | for (Int iRefIdx2 = iRefIdx1; iRefIdx2 < MAX_NUM_REF; iRefIdx2++) |
---|
624 | { |
---|
625 | m_abEqualRef[iDir][iRefIdx1][iRefIdx2] = m_abEqualRef[iDir][iRefIdx2][iRefIdx1] = (iRefIdx1 == iRefIdx2? true : false); |
---|
626 | } |
---|
627 | } |
---|
628 | } |
---|
629 | } |
---|
630 | #if H_3D |
---|
631 | #if H_3D_TMVP |
---|
632 | Void TComSlice::generateAlterRefforTMVP() |
---|
633 | { |
---|
634 | for ( UInt uiRefListIdx = 0; uiRefListIdx < 2; uiRefListIdx++ ) |
---|
635 | { |
---|
636 | if ( this->getNumRefIdx( RefPicList( uiRefListIdx ) ) == 0) |
---|
637 | continue; |
---|
638 | |
---|
639 | Bool bZeroIdxLtFlag = this->getRefPic(RefPicList(uiRefListIdx), 0)->getIsLongTerm(); |
---|
640 | for(Int i = 1; i < this->getNumRefIdx(RefPicList(uiRefListIdx)); i++ ) |
---|
641 | { |
---|
642 | if ( ( bZeroIdxLtFlag && !this->getRefPic(RefPicList(uiRefListIdx), i)->getIsLongTerm() ) || |
---|
643 | (!bZeroIdxLtFlag && this->getRefPic(RefPicList(uiRefListIdx), i)->getIsLongTerm() ) ) |
---|
644 | { |
---|
645 | this->setAlterRefIdx(RefPicList(uiRefListIdx),i); |
---|
646 | break; |
---|
647 | } |
---|
648 | } |
---|
649 | } |
---|
650 | } |
---|
651 | #endif |
---|
652 | Void TComSlice::setCamparaSlice( Int** aaiScale, Int** aaiOffset ) |
---|
653 | { |
---|
654 | if( m_pcSPS->hasCamParInSliceHeader() ) |
---|
655 | { |
---|
656 | for( UInt uiBaseViewIndex = 0; uiBaseViewIndex < m_viewIndex; uiBaseViewIndex++ ) |
---|
657 | { |
---|
658 | m_aaiCodedScale [ 0 ][ uiBaseViewIndex ] = aaiScale [ uiBaseViewIndex ][ m_viewIndex ]; |
---|
659 | m_aaiCodedScale [ 1 ][ uiBaseViewIndex ] = aaiScale [ m_viewIndex ][ uiBaseViewIndex ]; |
---|
660 | m_aaiCodedOffset[ 0 ][ uiBaseViewIndex ] = aaiOffset[ uiBaseViewIndex ][ m_viewIndex ]; |
---|
661 | m_aaiCodedOffset[ 1 ][ uiBaseViewIndex ] = aaiOffset[ m_viewIndex ][ uiBaseViewIndex ]; |
---|
662 | } |
---|
663 | } |
---|
664 | } |
---|
665 | #endif |
---|
666 | |
---|
667 | Void TComSlice::checkColRefIdx(UInt curSliceIdx, TComPic* pic) |
---|
668 | { |
---|
669 | Int i; |
---|
670 | TComSlice* curSlice = pic->getSlice(curSliceIdx); |
---|
671 | Int currColRefPOC = curSlice->getRefPOC( RefPicList(1-curSlice->getColFromL0Flag()), curSlice->getColRefIdx()); |
---|
672 | TComSlice* preSlice; |
---|
673 | Int preColRefPOC; |
---|
674 | for(i=curSliceIdx-1; i>=0; i--) |
---|
675 | { |
---|
676 | preSlice = pic->getSlice(i); |
---|
677 | if(preSlice->getSliceType() != I_SLICE) |
---|
678 | { |
---|
679 | preColRefPOC = preSlice->getRefPOC( RefPicList(1-preSlice->getColFromL0Flag()), preSlice->getColRefIdx()); |
---|
680 | if(currColRefPOC != preColRefPOC) |
---|
681 | { |
---|
682 | printf("Collocated_ref_idx shall always be the same for all slices of a coded picture!\n"); |
---|
683 | exit(EXIT_FAILURE); |
---|
684 | } |
---|
685 | else |
---|
686 | { |
---|
687 | break; |
---|
688 | } |
---|
689 | } |
---|
690 | } |
---|
691 | } |
---|
692 | |
---|
693 | Void TComSlice::checkCRA(TComReferencePictureSet *pReferencePictureSet, Int& pocCRA, Bool& prevRAPisBLA, TComList<TComPic *>& rcListPic) |
---|
694 | { |
---|
695 | for(Int i = 0; i < pReferencePictureSet->getNumberOfNegativePictures()+pReferencePictureSet->getNumberOfPositivePictures(); i++) |
---|
696 | { |
---|
697 | if(pocCRA < MAX_UINT && getPOC() > pocCRA) |
---|
698 | { |
---|
699 | assert(getPOC()+pReferencePictureSet->getDeltaPOC(i) >= pocCRA); |
---|
700 | } |
---|
701 | } |
---|
702 | for(Int i = pReferencePictureSet->getNumberOfNegativePictures()+pReferencePictureSet->getNumberOfPositivePictures(); i < pReferencePictureSet->getNumberOfPictures(); i++) |
---|
703 | { |
---|
704 | if(pocCRA < MAX_UINT && getPOC() > pocCRA) |
---|
705 | { |
---|
706 | if (!pReferencePictureSet->getCheckLTMSBPresent(i)) |
---|
707 | { |
---|
708 | assert(xGetLongTermRefPic(rcListPic, pReferencePictureSet->getPOC(i), false)->getPOC() >= pocCRA); |
---|
709 | } |
---|
710 | else |
---|
711 | { |
---|
712 | assert(pReferencePictureSet->getPOC(i) >= pocCRA); |
---|
713 | } |
---|
714 | } |
---|
715 | } |
---|
716 | if ( getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_W_RADL || getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_N_LP ) // IDR picture found |
---|
717 | { |
---|
718 | pocCRA = getPOC(); |
---|
719 | prevRAPisBLA = false; |
---|
720 | } |
---|
721 | else if ( getNalUnitType() == NAL_UNIT_CODED_SLICE_CRA ) // CRA picture found |
---|
722 | { |
---|
723 | pocCRA = getPOC(); |
---|
724 | prevRAPisBLA = false; |
---|
725 | } |
---|
726 | else if ( getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_LP |
---|
727 | || getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_RADL |
---|
728 | || getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_N_LP ) // BLA picture found |
---|
729 | { |
---|
730 | pocCRA = getPOC(); |
---|
731 | prevRAPisBLA = true; |
---|
732 | } |
---|
733 | } |
---|
734 | |
---|
735 | /** Function for marking the reference pictures when an IDR/CRA/CRANT/BLA/BLANT is encountered. |
---|
736 | * \param pocCRA POC of the CRA/CRANT/BLA/BLANT picture |
---|
737 | * \param bRefreshPending flag indicating if a deferred decoding refresh is pending |
---|
738 | * \param rcListPic reference to the reference picture list |
---|
739 | * This function marks the reference pictures as "unused for reference" in the following conditions. |
---|
740 | * If the nal_unit_type is IDR/BLA/BLANT, all pictures in the reference picture list |
---|
741 | * are marked as "unused for reference" |
---|
742 | * If the nal_unit_type is BLA/BLANT, set the pocCRA to the temporal reference of the current picture. |
---|
743 | * Otherwise |
---|
744 | * If the bRefreshPending flag is true (a deferred decoding refresh is pending) and the current |
---|
745 | * temporal reference is greater than the temporal reference of the latest CRA/CRANT/BLA/BLANT picture (pocCRA), |
---|
746 | * mark all reference pictures except the latest CRA/CRANT/BLA/BLANT picture as "unused for reference" and set |
---|
747 | * the bRefreshPending flag to false. |
---|
748 | * If the nal_unit_type is CRA/CRANT, set the bRefreshPending flag to true and pocCRA to the temporal |
---|
749 | * reference of the current picture. |
---|
750 | * Note that the current picture is already placed in the reference list and its marking is not changed. |
---|
751 | * If the current picture has a nal_ref_idc that is not 0, it will remain marked as "used for reference". |
---|
752 | */ |
---|
753 | Void TComSlice::decodingRefreshMarking(Int& pocCRA, Bool& bRefreshPending, TComList<TComPic*>& rcListPic) |
---|
754 | { |
---|
755 | TComPic* rpcPic; |
---|
756 | Int pocCurr = getPOC(); |
---|
757 | |
---|
758 | if ( getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_LP |
---|
759 | || getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_RADL |
---|
760 | || getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_N_LP |
---|
761 | || getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_W_RADL |
---|
762 | || getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_N_LP ) // IDR or BLA picture |
---|
763 | { |
---|
764 | // mark all pictures as not used for reference |
---|
765 | TComList<TComPic*>::iterator iterPic = rcListPic.begin(); |
---|
766 | while (iterPic != rcListPic.end()) |
---|
767 | { |
---|
768 | rpcPic = *(iterPic); |
---|
769 | rpcPic->setCurrSliceIdx(0); |
---|
770 | if (rpcPic->getPOC() != pocCurr) rpcPic->getSlice(0)->setReferenced(false); |
---|
771 | iterPic++; |
---|
772 | } |
---|
773 | if ( getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_LP |
---|
774 | || getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_RADL |
---|
775 | || getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_N_LP ) |
---|
776 | { |
---|
777 | pocCRA = pocCurr; |
---|
778 | } |
---|
779 | } |
---|
780 | else // CRA or No DR |
---|
781 | { |
---|
782 | if (bRefreshPending==true && pocCurr > pocCRA) // CRA reference marking pending |
---|
783 | { |
---|
784 | TComList<TComPic*>::iterator iterPic = rcListPic.begin(); |
---|
785 | while (iterPic != rcListPic.end()) |
---|
786 | { |
---|
787 | rpcPic = *(iterPic); |
---|
788 | if (rpcPic->getPOC() != pocCurr && rpcPic->getPOC() != pocCRA) |
---|
789 | { |
---|
790 | rpcPic->getSlice(0)->setReferenced(false); |
---|
791 | } |
---|
792 | iterPic++; |
---|
793 | } |
---|
794 | bRefreshPending = false; |
---|
795 | } |
---|
796 | if ( getNalUnitType() == NAL_UNIT_CODED_SLICE_CRA ) // CRA picture found |
---|
797 | { |
---|
798 | bRefreshPending = true; |
---|
799 | pocCRA = pocCurr; |
---|
800 | } |
---|
801 | } |
---|
802 | } |
---|
803 | |
---|
804 | Void TComSlice::copySliceInfo(TComSlice *pSrc) |
---|
805 | { |
---|
806 | assert( pSrc != NULL ); |
---|
807 | |
---|
808 | Int i, j, k; |
---|
809 | |
---|
810 | m_iPOC = pSrc->m_iPOC; |
---|
811 | m_eNalUnitType = pSrc->m_eNalUnitType; |
---|
812 | #if H_MV |
---|
813 | m_layerId = pSrc->m_layerId; |
---|
814 | // GT: Copying of several other values might be be missing here, or is above not necessary? |
---|
815 | #endif |
---|
816 | m_eSliceType = pSrc->m_eSliceType; |
---|
817 | m_iSliceQp = pSrc->m_iSliceQp; |
---|
818 | #if ADAPTIVE_QP_SELECTION |
---|
819 | m_iSliceQpBase = pSrc->m_iSliceQpBase; |
---|
820 | #endif |
---|
821 | m_deblockingFilterDisable = pSrc->m_deblockingFilterDisable; |
---|
822 | m_deblockingFilterOverrideFlag = pSrc->m_deblockingFilterOverrideFlag; |
---|
823 | m_deblockingFilterBetaOffsetDiv2 = pSrc->m_deblockingFilterBetaOffsetDiv2; |
---|
824 | m_deblockingFilterTcOffsetDiv2 = pSrc->m_deblockingFilterTcOffsetDiv2; |
---|
825 | |
---|
826 | for (i = 0; i < 2; i++) |
---|
827 | { |
---|
828 | m_aiNumRefIdx[i] = pSrc->m_aiNumRefIdx[i]; |
---|
829 | } |
---|
830 | |
---|
831 | for (i = 0; i < MAX_NUM_REF; i++) |
---|
832 | { |
---|
833 | m_list1IdxToList0Idx[i] = pSrc->m_list1IdxToList0Idx[i]; |
---|
834 | } |
---|
835 | m_bCheckLDC = pSrc->m_bCheckLDC; |
---|
836 | m_iSliceQpDelta = pSrc->m_iSliceQpDelta; |
---|
837 | m_iSliceQpDeltaCb = pSrc->m_iSliceQpDeltaCb; |
---|
838 | m_iSliceQpDeltaCr = pSrc->m_iSliceQpDeltaCr; |
---|
839 | for (i = 0; i < 2; i++) |
---|
840 | { |
---|
841 | for (j = 0; j < MAX_NUM_REF; j++) |
---|
842 | { |
---|
843 | m_apcRefPicList[i][j] = pSrc->m_apcRefPicList[i][j]; |
---|
844 | m_aiRefPOCList[i][j] = pSrc->m_aiRefPOCList[i][j]; |
---|
845 | #if H_MV |
---|
846 | m_aiRefLayerIdList[i][j] = pSrc->m_aiRefLayerIdList[i][j]; |
---|
847 | #endif |
---|
848 | } |
---|
849 | } |
---|
850 | for (i = 0; i < 2; i++) |
---|
851 | { |
---|
852 | for (j = 0; j < MAX_NUM_REF + 1; j++) |
---|
853 | { |
---|
854 | m_bIsUsedAsLongTerm[i][j] = pSrc->m_bIsUsedAsLongTerm[i][j]; |
---|
855 | } |
---|
856 | } |
---|
857 | m_iDepth = pSrc->m_iDepth; |
---|
858 | |
---|
859 | // referenced slice |
---|
860 | m_bRefenced = pSrc->m_bRefenced; |
---|
861 | |
---|
862 | // access channel |
---|
863 | #if H_MV |
---|
864 | m_pcVPS = pSrc->m_pcVPS; |
---|
865 | #endif |
---|
866 | m_pcSPS = pSrc->m_pcSPS; |
---|
867 | m_pcPPS = pSrc->m_pcPPS; |
---|
868 | m_pcRPS = pSrc->m_pcRPS; |
---|
869 | m_iLastIDR = pSrc->m_iLastIDR; |
---|
870 | |
---|
871 | m_pcPic = pSrc->m_pcPic; |
---|
872 | |
---|
873 | m_colFromL0Flag = pSrc->m_colFromL0Flag; |
---|
874 | m_colRefIdx = pSrc->m_colRefIdx; |
---|
875 | #if SAO_CHROMA_LAMBDA |
---|
876 | m_dLambdaLuma = pSrc->m_dLambdaLuma; |
---|
877 | m_dLambdaChroma = pSrc->m_dLambdaChroma; |
---|
878 | #else |
---|
879 | m_dLambda = pSrc->m_dLambda; |
---|
880 | #endif |
---|
881 | for (i = 0; i < 2; i++) |
---|
882 | { |
---|
883 | for (j = 0; j < MAX_NUM_REF; j++) |
---|
884 | { |
---|
885 | for (k =0; k < MAX_NUM_REF; k++) |
---|
886 | { |
---|
887 | m_abEqualRef[i][j][k] = pSrc->m_abEqualRef[i][j][k]; |
---|
888 | } |
---|
889 | } |
---|
890 | } |
---|
891 | |
---|
892 | m_uiTLayer = pSrc->m_uiTLayer; |
---|
893 | m_bTLayerSwitchingFlag = pSrc->m_bTLayerSwitchingFlag; |
---|
894 | |
---|
895 | m_sliceMode = pSrc->m_sliceMode; |
---|
896 | m_sliceArgument = pSrc->m_sliceArgument; |
---|
897 | m_sliceCurStartCUAddr = pSrc->m_sliceCurStartCUAddr; |
---|
898 | m_sliceCurEndCUAddr = pSrc->m_sliceCurEndCUAddr; |
---|
899 | m_sliceIdx = pSrc->m_sliceIdx; |
---|
900 | m_sliceSegmentMode = pSrc->m_sliceSegmentMode; |
---|
901 | m_sliceSegmentArgument = pSrc->m_sliceSegmentArgument; |
---|
902 | m_sliceSegmentCurStartCUAddr = pSrc->m_sliceSegmentCurStartCUAddr; |
---|
903 | m_sliceSegmentCurEndCUAddr = pSrc->m_sliceSegmentCurEndCUAddr; |
---|
904 | m_nextSlice = pSrc->m_nextSlice; |
---|
905 | m_nextSliceSegment = pSrc->m_nextSliceSegment; |
---|
906 | for ( Int e=0 ; e<2 ; e++ ) |
---|
907 | { |
---|
908 | for ( Int n=0 ; n<MAX_NUM_REF ; n++ ) |
---|
909 | { |
---|
910 | memcpy(m_weightPredTable[e][n], pSrc->m_weightPredTable[e][n], sizeof(wpScalingParam)*3 ); |
---|
911 | } |
---|
912 | } |
---|
913 | m_saoEnabledFlag = pSrc->m_saoEnabledFlag; |
---|
914 | m_saoEnabledFlagChroma = pSrc->m_saoEnabledFlagChroma; |
---|
915 | m_cabacInitFlag = pSrc->m_cabacInitFlag; |
---|
916 | m_numEntryPointOffsets = pSrc->m_numEntryPointOffsets; |
---|
917 | |
---|
918 | m_bLMvdL1Zero = pSrc->m_bLMvdL1Zero; |
---|
919 | m_LFCrossSliceBoundaryFlag = pSrc->m_LFCrossSliceBoundaryFlag; |
---|
920 | m_enableTMVPFlag = pSrc->m_enableTMVPFlag; |
---|
921 | m_maxNumMergeCand = pSrc->m_maxNumMergeCand; |
---|
922 | |
---|
923 | #if H_MV |
---|
924 | // Additional slice header syntax elements |
---|
925 | m_discardableFlag = pSrc->m_discardableFlag; |
---|
926 | m_interLayerPredEnabledFlag = pSrc->m_interLayerPredEnabledFlag; |
---|
927 | m_numInterLayerRefPicsMinus1 = pSrc->m_numInterLayerRefPicsMinus1; |
---|
928 | |
---|
929 | for (Int layer = 0; layer < MAX_NUM_LAYERS; layer++ ) |
---|
930 | { |
---|
931 | m_interLayerPredLayerIdc[ layer ] = pSrc->m_interLayerPredLayerIdc[ layer ]; |
---|
932 | } |
---|
933 | |
---|
934 | m_interLayerSamplePredOnlyFlag = pSrc->m_interLayerSamplePredOnlyFlag; |
---|
935 | m_altCollocatedIndicationFlag = pSrc->m_altCollocatedIndicationFlag ; |
---|
936 | m_collocatedRefLayerIdx = pSrc->m_collocatedRefLayerIdx ; |
---|
937 | m_numActiveMotionPredRefLayers = pSrc->m_numActiveMotionPredRefLayers; |
---|
938 | |
---|
939 | for (Int layer = 0; layer < MAX_NUM_LAYER_IDS; layer++) |
---|
940 | { |
---|
941 | m_interLayerPredLayerIdc[layer] = pSrc->m_interLayerPredLayerIdc[layer]; |
---|
942 | } |
---|
943 | #endif |
---|
944 | #if H_3D_IC |
---|
945 | m_bApplyIC = pSrc->m_bApplyIC; |
---|
946 | m_icSkipParseFlag = pSrc->m_icSkipParseFlag; |
---|
947 | #endif |
---|
948 | } |
---|
949 | |
---|
950 | Int TComSlice::m_prevPOC = 0; |
---|
951 | |
---|
952 | /** Function for setting the slice's temporal layer ID and corresponding temporal_layer_switching_point_flag. |
---|
953 | * \param uiTLayer Temporal layer ID of the current slice |
---|
954 | * The decoder calls this function to set temporal_layer_switching_point_flag for each temporal layer based on |
---|
955 | * the SPS's temporal_id_nesting_flag and the parsed PPS. Then, current slice's temporal layer ID and |
---|
956 | * temporal_layer_switching_point_flag is set accordingly. |
---|
957 | */ |
---|
958 | Void TComSlice::setTLayerInfo( UInt uiTLayer ) |
---|
959 | { |
---|
960 | m_uiTLayer = uiTLayer; |
---|
961 | } |
---|
962 | |
---|
963 | /** Function for checking if this is a switching-point |
---|
964 | */ |
---|
965 | Bool TComSlice::isTemporalLayerSwitchingPoint( TComList<TComPic*>& rcListPic ) |
---|
966 | { |
---|
967 | TComPic* rpcPic; |
---|
968 | // loop through all pictures in the reference picture buffer |
---|
969 | TComList<TComPic*>::iterator iterPic = rcListPic.begin(); |
---|
970 | while ( iterPic != rcListPic.end()) |
---|
971 | { |
---|
972 | rpcPic = *(iterPic++); |
---|
973 | if(rpcPic->getSlice(0)->isReferenced() && rpcPic->getPOC() != getPOC()) |
---|
974 | { |
---|
975 | if(rpcPic->getTLayer() >= getTLayer()) |
---|
976 | { |
---|
977 | return false; |
---|
978 | } |
---|
979 | } |
---|
980 | } |
---|
981 | return true; |
---|
982 | } |
---|
983 | |
---|
984 | /** Function for checking if this is a STSA candidate |
---|
985 | */ |
---|
986 | Bool TComSlice::isStepwiseTemporalLayerSwitchingPointCandidate( TComList<TComPic*>& rcListPic ) |
---|
987 | { |
---|
988 | TComPic* rpcPic; |
---|
989 | |
---|
990 | TComList<TComPic*>::iterator iterPic = rcListPic.begin(); |
---|
991 | while ( iterPic != rcListPic.end()) |
---|
992 | { |
---|
993 | rpcPic = *(iterPic++); |
---|
994 | if(rpcPic->getSlice(0)->isReferenced() && (rpcPic->getUsedByCurr()==true) && rpcPic->getPOC() != getPOC()) |
---|
995 | { |
---|
996 | if(rpcPic->getTLayer() >= getTLayer()) |
---|
997 | { |
---|
998 | return false; |
---|
999 | } |
---|
1000 | } |
---|
1001 | } |
---|
1002 | return true; |
---|
1003 | } |
---|
1004 | |
---|
1005 | /** Function for applying picture marking based on the Reference Picture Set in pReferencePictureSet. |
---|
1006 | */ |
---|
1007 | Void TComSlice::applyReferencePictureSet( TComList<TComPic*>& rcListPic, TComReferencePictureSet *pReferencePictureSet) |
---|
1008 | { |
---|
1009 | TComPic* rpcPic; |
---|
1010 | Int i, isReference; |
---|
1011 | |
---|
1012 | // loop through all pictures in the reference picture buffer |
---|
1013 | TComList<TComPic*>::iterator iterPic = rcListPic.begin(); |
---|
1014 | while ( iterPic != rcListPic.end()) |
---|
1015 | { |
---|
1016 | rpcPic = *(iterPic++); |
---|
1017 | |
---|
1018 | if(!rpcPic->getSlice( 0 )->isReferenced()) |
---|
1019 | { |
---|
1020 | continue; |
---|
1021 | } |
---|
1022 | |
---|
1023 | isReference = 0; |
---|
1024 | // loop through all pictures in the Reference Picture Set |
---|
1025 | // to see if the picture should be kept as reference picture |
---|
1026 | for(i=0;i<pReferencePictureSet->getNumberOfPositivePictures()+pReferencePictureSet->getNumberOfNegativePictures();i++) |
---|
1027 | { |
---|
1028 | if(!rpcPic->getIsLongTerm() && rpcPic->getPicSym()->getSlice(0)->getPOC() == this->getPOC() + pReferencePictureSet->getDeltaPOC(i)) |
---|
1029 | { |
---|
1030 | isReference = 1; |
---|
1031 | rpcPic->setUsedByCurr(pReferencePictureSet->getUsed(i)); |
---|
1032 | rpcPic->setIsLongTerm(0); |
---|
1033 | } |
---|
1034 | } |
---|
1035 | for(;i<pReferencePictureSet->getNumberOfPictures();i++) |
---|
1036 | { |
---|
1037 | if(pReferencePictureSet->getCheckLTMSBPresent(i)==true) |
---|
1038 | { |
---|
1039 | if(rpcPic->getIsLongTerm() && (rpcPic->getPicSym()->getSlice(0)->getPOC()) == pReferencePictureSet->getPOC(i)) |
---|
1040 | { |
---|
1041 | isReference = 1; |
---|
1042 | rpcPic->setUsedByCurr(pReferencePictureSet->getUsed(i)); |
---|
1043 | } |
---|
1044 | } |
---|
1045 | else |
---|
1046 | { |
---|
1047 | if(rpcPic->getIsLongTerm() && (rpcPic->getPicSym()->getSlice(0)->getPOC()%(1<<rpcPic->getPicSym()->getSlice(0)->getSPS()->getBitsForPOC())) == pReferencePictureSet->getPOC(i)%(1<<rpcPic->getPicSym()->getSlice(0)->getSPS()->getBitsForPOC())) |
---|
1048 | { |
---|
1049 | isReference = 1; |
---|
1050 | rpcPic->setUsedByCurr(pReferencePictureSet->getUsed(i)); |
---|
1051 | } |
---|
1052 | } |
---|
1053 | |
---|
1054 | } |
---|
1055 | // mark the picture as "unused for reference" if it is not in |
---|
1056 | // the Reference Picture Set |
---|
1057 | if(rpcPic->getPicSym()->getSlice(0)->getPOC() != this->getPOC() && isReference == 0) |
---|
1058 | { |
---|
1059 | rpcPic->getSlice( 0 )->setReferenced( false ); |
---|
1060 | rpcPic->setUsedByCurr(0); |
---|
1061 | rpcPic->setIsLongTerm(0); |
---|
1062 | } |
---|
1063 | //check that pictures of higher temporal layers are not used |
---|
1064 | assert(rpcPic->getSlice( 0 )->isReferenced()==0||rpcPic->getUsedByCurr()==0||rpcPic->getTLayer()<=this->getTLayer()); |
---|
1065 | //check that pictures of higher or equal temporal layer are not in the RPS if the current picture is a TSA picture |
---|
1066 | if(this->getNalUnitType() == NAL_UNIT_CODED_SLICE_TLA_R || this->getNalUnitType() == NAL_UNIT_CODED_SLICE_TSA_N) |
---|
1067 | { |
---|
1068 | assert(rpcPic->getSlice( 0 )->isReferenced()==0||rpcPic->getTLayer()<this->getTLayer()); |
---|
1069 | } |
---|
1070 | //check that pictures marked as temporal layer non-reference pictures are not used for reference |
---|
1071 | if(rpcPic->getPicSym()->getSlice(0)->getPOC() != this->getPOC() && rpcPic->getTLayer()==this->getTLayer()) |
---|
1072 | { |
---|
1073 | assert(rpcPic->getSlice( 0 )->isReferenced()==0||rpcPic->getUsedByCurr()==0||rpcPic->getSlice( 0 )->getTemporalLayerNonReferenceFlag()==false); |
---|
1074 | } |
---|
1075 | } |
---|
1076 | } |
---|
1077 | |
---|
1078 | /** Function for applying picture marking based on the Reference Picture Set in pReferencePictureSet. |
---|
1079 | */ |
---|
1080 | Int TComSlice::checkThatAllRefPicsAreAvailable( TComList<TComPic*>& rcListPic, TComReferencePictureSet *pReferencePictureSet, Bool printErrors, Int pocRandomAccess) |
---|
1081 | { |
---|
1082 | TComPic* rpcPic; |
---|
1083 | Int i, isAvailable; |
---|
1084 | Int atLeastOneLost = 0; |
---|
1085 | Int atLeastOneRemoved = 0; |
---|
1086 | Int iPocLost = 0; |
---|
1087 | |
---|
1088 | // loop through all long-term pictures in the Reference Picture Set |
---|
1089 | // to see if the picture should be kept as reference picture |
---|
1090 | for(i=pReferencePictureSet->getNumberOfNegativePictures()+pReferencePictureSet->getNumberOfPositivePictures();i<pReferencePictureSet->getNumberOfPictures();i++) |
---|
1091 | { |
---|
1092 | isAvailable = 0; |
---|
1093 | // loop through all pictures in the reference picture buffer |
---|
1094 | TComList<TComPic*>::iterator iterPic = rcListPic.begin(); |
---|
1095 | while ( iterPic != rcListPic.end()) |
---|
1096 | { |
---|
1097 | rpcPic = *(iterPic++); |
---|
1098 | if(pReferencePictureSet->getCheckLTMSBPresent(i)==true) |
---|
1099 | { |
---|
1100 | if(rpcPic->getIsLongTerm() && (rpcPic->getPicSym()->getSlice(0)->getPOC()) == pReferencePictureSet->getPOC(i) && rpcPic->getSlice(0)->isReferenced()) |
---|
1101 | { |
---|
1102 | isAvailable = 1; |
---|
1103 | } |
---|
1104 | } |
---|
1105 | else |
---|
1106 | { |
---|
1107 | if(rpcPic->getIsLongTerm() && (rpcPic->getPicSym()->getSlice(0)->getPOC()%(1<<rpcPic->getPicSym()->getSlice(0)->getSPS()->getBitsForPOC())) == pReferencePictureSet->getPOC(i)%(1<<rpcPic->getPicSym()->getSlice(0)->getSPS()->getBitsForPOC()) && rpcPic->getSlice(0)->isReferenced()) |
---|
1108 | { |
---|
1109 | isAvailable = 1; |
---|
1110 | } |
---|
1111 | } |
---|
1112 | } |
---|
1113 | // if there was no such long-term check the short terms |
---|
1114 | if(!isAvailable) |
---|
1115 | { |
---|
1116 | iterPic = rcListPic.begin(); |
---|
1117 | while ( iterPic != rcListPic.end()) |
---|
1118 | { |
---|
1119 | rpcPic = *(iterPic++); |
---|
1120 | |
---|
1121 | Int pocCycle = 1 << rpcPic->getPicSym()->getSlice(0)->getSPS()->getBitsForPOC(); |
---|
1122 | Int curPoc = rpcPic->getPicSym()->getSlice(0)->getPOC(); |
---|
1123 | Int refPoc = pReferencePictureSet->getPOC(i); |
---|
1124 | if (!pReferencePictureSet->getCheckLTMSBPresent(i)) |
---|
1125 | { |
---|
1126 | curPoc = curPoc % pocCycle; |
---|
1127 | refPoc = refPoc % pocCycle; |
---|
1128 | } |
---|
1129 | |
---|
1130 | if (rpcPic->getSlice(0)->isReferenced() && curPoc == refPoc) |
---|
1131 | { |
---|
1132 | isAvailable = 1; |
---|
1133 | rpcPic->setIsLongTerm(1); |
---|
1134 | break; |
---|
1135 | } |
---|
1136 | } |
---|
1137 | } |
---|
1138 | // report that a picture is lost if it is in the Reference Picture Set |
---|
1139 | // but not available as reference picture |
---|
1140 | if(isAvailable == 0) |
---|
1141 | { |
---|
1142 | if (this->getPOC() + pReferencePictureSet->getDeltaPOC(i) >= pocRandomAccess) |
---|
1143 | { |
---|
1144 | if(!pReferencePictureSet->getUsed(i) ) |
---|
1145 | { |
---|
1146 | if(printErrors) |
---|
1147 | { |
---|
1148 | printf("\nLong-term reference picture with POC = %3d seems to have been removed or not correctly decoded.", this->getPOC() + pReferencePictureSet->getDeltaPOC(i)); |
---|
1149 | } |
---|
1150 | atLeastOneRemoved = 1; |
---|
1151 | } |
---|
1152 | else |
---|
1153 | { |
---|
1154 | if(printErrors) |
---|
1155 | { |
---|
1156 | printf("\nLong-term reference picture with POC = %3d is lost or not correctly decoded!", this->getPOC() + pReferencePictureSet->getDeltaPOC(i)); |
---|
1157 | } |
---|
1158 | atLeastOneLost = 1; |
---|
1159 | iPocLost=this->getPOC() + pReferencePictureSet->getDeltaPOC(i); |
---|
1160 | } |
---|
1161 | } |
---|
1162 | } |
---|
1163 | } |
---|
1164 | // loop through all short-term pictures in the Reference Picture Set |
---|
1165 | // to see if the picture should be kept as reference picture |
---|
1166 | for(i=0;i<pReferencePictureSet->getNumberOfNegativePictures()+pReferencePictureSet->getNumberOfPositivePictures();i++) |
---|
1167 | { |
---|
1168 | isAvailable = 0; |
---|
1169 | // loop through all pictures in the reference picture buffer |
---|
1170 | TComList<TComPic*>::iterator iterPic = rcListPic.begin(); |
---|
1171 | while ( iterPic != rcListPic.end()) |
---|
1172 | { |
---|
1173 | rpcPic = *(iterPic++); |
---|
1174 | |
---|
1175 | if(!rpcPic->getIsLongTerm() && rpcPic->getPicSym()->getSlice(0)->getPOC() == this->getPOC() + pReferencePictureSet->getDeltaPOC(i) && rpcPic->getSlice(0)->isReferenced()) |
---|
1176 | { |
---|
1177 | isAvailable = 1; |
---|
1178 | } |
---|
1179 | } |
---|
1180 | // report that a picture is lost if it is in the Reference Picture Set |
---|
1181 | // but not available as reference picture |
---|
1182 | if(isAvailable == 0) |
---|
1183 | { |
---|
1184 | if (this->getPOC() + pReferencePictureSet->getDeltaPOC(i) >= pocRandomAccess) |
---|
1185 | { |
---|
1186 | if(!pReferencePictureSet->getUsed(i) ) |
---|
1187 | { |
---|
1188 | if(printErrors) |
---|
1189 | { |
---|
1190 | printf("\nShort-term reference picture with POC = %3d seems to have been removed or not correctly decoded.", this->getPOC() + pReferencePictureSet->getDeltaPOC(i)); |
---|
1191 | } |
---|
1192 | atLeastOneRemoved = 1; |
---|
1193 | } |
---|
1194 | else |
---|
1195 | { |
---|
1196 | if(printErrors) |
---|
1197 | { |
---|
1198 | printf("\nShort-term reference picture with POC = %3d is lost or not correctly decoded!", this->getPOC() + pReferencePictureSet->getDeltaPOC(i)); |
---|
1199 | } |
---|
1200 | atLeastOneLost = 1; |
---|
1201 | iPocLost=this->getPOC() + pReferencePictureSet->getDeltaPOC(i); |
---|
1202 | } |
---|
1203 | } |
---|
1204 | } |
---|
1205 | } |
---|
1206 | if(atLeastOneLost) |
---|
1207 | { |
---|
1208 | return iPocLost+1; |
---|
1209 | } |
---|
1210 | if(atLeastOneRemoved) |
---|
1211 | { |
---|
1212 | return -2; |
---|
1213 | } |
---|
1214 | else |
---|
1215 | { |
---|
1216 | return 0; |
---|
1217 | } |
---|
1218 | } |
---|
1219 | |
---|
1220 | /** Function for constructing an explicit Reference Picture Set out of the available pictures in a referenced Reference Picture Set |
---|
1221 | */ |
---|
1222 | #if FIX1071 |
---|
1223 | Void TComSlice::createExplicitReferencePictureSetFromReference( TComList<TComPic*>& rcListPic, TComReferencePictureSet *pReferencePictureSet, Bool isRAP) |
---|
1224 | #else |
---|
1225 | Void TComSlice::createExplicitReferencePictureSetFromReference( TComList<TComPic*>& rcListPic, TComReferencePictureSet *pReferencePictureSet) |
---|
1226 | #endif |
---|
1227 | { |
---|
1228 | TComPic* rpcPic; |
---|
1229 | Int i, j; |
---|
1230 | Int k = 0; |
---|
1231 | Int nrOfNegativePictures = 0; |
---|
1232 | Int nrOfPositivePictures = 0; |
---|
1233 | TComReferencePictureSet* pcRPS = this->getLocalRPS(); |
---|
1234 | |
---|
1235 | // loop through all pictures in the Reference Picture Set |
---|
1236 | for(i=0;i<pReferencePictureSet->getNumberOfPictures();i++) |
---|
1237 | { |
---|
1238 | j = 0; |
---|
1239 | // loop through all pictures in the reference picture buffer |
---|
1240 | TComList<TComPic*>::iterator iterPic = rcListPic.begin(); |
---|
1241 | while ( iterPic != rcListPic.end()) |
---|
1242 | { |
---|
1243 | j++; |
---|
1244 | rpcPic = *(iterPic++); |
---|
1245 | |
---|
1246 | if(rpcPic->getPicSym()->getSlice(0)->getPOC() == this->getPOC() + pReferencePictureSet->getDeltaPOC(i) && rpcPic->getSlice(0)->isReferenced()) |
---|
1247 | { |
---|
1248 | // This picture exists as a reference picture |
---|
1249 | // and should be added to the explicit Reference Picture Set |
---|
1250 | pcRPS->setDeltaPOC(k, pReferencePictureSet->getDeltaPOC(i)); |
---|
1251 | #if FIX1071 |
---|
1252 | pcRPS->setUsed(k, pReferencePictureSet->getUsed(i) && (!isRAP)); |
---|
1253 | #else |
---|
1254 | pcRPS->setUsed(k, pReferencePictureSet->getUsed(i)); |
---|
1255 | #endif |
---|
1256 | if(pcRPS->getDeltaPOC(k) < 0) |
---|
1257 | { |
---|
1258 | nrOfNegativePictures++; |
---|
1259 | } |
---|
1260 | else |
---|
1261 | { |
---|
1262 | nrOfPositivePictures++; |
---|
1263 | } |
---|
1264 | k++; |
---|
1265 | } |
---|
1266 | } |
---|
1267 | } |
---|
1268 | pcRPS->setNumberOfNegativePictures(nrOfNegativePictures); |
---|
1269 | pcRPS->setNumberOfPositivePictures(nrOfPositivePictures); |
---|
1270 | pcRPS->setNumberOfPictures(nrOfNegativePictures+nrOfPositivePictures); |
---|
1271 | // This is a simplistic inter rps example. A smarter encoder will look for a better reference RPS to do the |
---|
1272 | // inter RPS prediction with. Here we just use the reference used by pReferencePictureSet. |
---|
1273 | // If pReferencePictureSet is not inter_RPS_predicted, then inter_RPS_prediction is for the current RPS also disabled. |
---|
1274 | if (!pReferencePictureSet->getInterRPSPrediction()) |
---|
1275 | { |
---|
1276 | pcRPS->setInterRPSPrediction(false); |
---|
1277 | pcRPS->setNumRefIdc(0); |
---|
1278 | } |
---|
1279 | else |
---|
1280 | { |
---|
1281 | Int rIdx = this->getRPSidx() - pReferencePictureSet->getDeltaRIdxMinus1() - 1; |
---|
1282 | Int deltaRPS = pReferencePictureSet->getDeltaRPS(); |
---|
1283 | TComReferencePictureSet* pcRefRPS = this->getSPS()->getRPSList()->getReferencePictureSet(rIdx); |
---|
1284 | Int iRefPics = pcRefRPS->getNumberOfPictures(); |
---|
1285 | Int iNewIdc=0; |
---|
1286 | for(i=0; i<= iRefPics; i++) |
---|
1287 | { |
---|
1288 | Int deltaPOC = ((i != iRefPics)? pcRefRPS->getDeltaPOC(i) : 0); // check if the reference abs POC is >= 0 |
---|
1289 | Int iRefIdc = 0; |
---|
1290 | for (j=0; j < pcRPS->getNumberOfPictures(); j++) // loop through the pictures in the new RPS |
---|
1291 | { |
---|
1292 | if ( (deltaPOC + deltaRPS) == pcRPS->getDeltaPOC(j)) |
---|
1293 | { |
---|
1294 | if (pcRPS->getUsed(j)) |
---|
1295 | { |
---|
1296 | iRefIdc = 1; |
---|
1297 | } |
---|
1298 | else |
---|
1299 | { |
---|
1300 | iRefIdc = 2; |
---|
1301 | } |
---|
1302 | } |
---|
1303 | } |
---|
1304 | pcRPS->setRefIdc(i, iRefIdc); |
---|
1305 | iNewIdc++; |
---|
1306 | } |
---|
1307 | pcRPS->setInterRPSPrediction(true); |
---|
1308 | pcRPS->setNumRefIdc(iNewIdc); |
---|
1309 | pcRPS->setDeltaRPS(deltaRPS); |
---|
1310 | pcRPS->setDeltaRIdxMinus1(pReferencePictureSet->getDeltaRIdxMinus1() + this->getSPS()->getRPSList()->getNumberOfReferencePictureSets() - this->getRPSidx()); |
---|
1311 | } |
---|
1312 | |
---|
1313 | this->setRPS(pcRPS); |
---|
1314 | this->setRPSidx(-1); |
---|
1315 | } |
---|
1316 | |
---|
1317 | /** get AC and DC values for weighted pred |
---|
1318 | * \param *wp |
---|
1319 | * \returns Void |
---|
1320 | */ |
---|
1321 | Void TComSlice::getWpAcDcParam(wpACDCParam *&wp) |
---|
1322 | { |
---|
1323 | wp = m_weightACDCParam; |
---|
1324 | } |
---|
1325 | |
---|
1326 | /** init AC and DC values for weighted pred |
---|
1327 | * \returns Void |
---|
1328 | */ |
---|
1329 | Void TComSlice::initWpAcDcParam() |
---|
1330 | { |
---|
1331 | for(Int iComp = 0; iComp < 3; iComp++ ) |
---|
1332 | { |
---|
1333 | m_weightACDCParam[iComp].iAC = 0; |
---|
1334 | m_weightACDCParam[iComp].iDC = 0; |
---|
1335 | } |
---|
1336 | } |
---|
1337 | |
---|
1338 | /** get WP tables for weighted pred |
---|
1339 | * \param RefPicList |
---|
1340 | * \param iRefIdx |
---|
1341 | * \param *&wpScalingParam |
---|
1342 | * \returns Void |
---|
1343 | */ |
---|
1344 | Void TComSlice::getWpScaling( RefPicList e, Int iRefIdx, wpScalingParam *&wp ) |
---|
1345 | { |
---|
1346 | wp = m_weightPredTable[e][iRefIdx]; |
---|
1347 | } |
---|
1348 | |
---|
1349 | /** reset Default WP tables settings : no weight. |
---|
1350 | * \param wpScalingParam |
---|
1351 | * \returns Void |
---|
1352 | */ |
---|
1353 | Void TComSlice::resetWpScaling() |
---|
1354 | { |
---|
1355 | for ( Int e=0 ; e<2 ; e++ ) |
---|
1356 | { |
---|
1357 | for ( Int i=0 ; i<MAX_NUM_REF ; i++ ) |
---|
1358 | { |
---|
1359 | for ( Int yuv=0 ; yuv<3 ; yuv++ ) |
---|
1360 | { |
---|
1361 | wpScalingParam *pwp = &(m_weightPredTable[e][i][yuv]); |
---|
1362 | pwp->bPresentFlag = false; |
---|
1363 | pwp->uiLog2WeightDenom = 0; |
---|
1364 | pwp->uiLog2WeightDenom = 0; |
---|
1365 | pwp->iWeight = 1; |
---|
1366 | pwp->iOffset = 0; |
---|
1367 | } |
---|
1368 | } |
---|
1369 | } |
---|
1370 | } |
---|
1371 | |
---|
1372 | /** init WP table |
---|
1373 | * \returns Void |
---|
1374 | */ |
---|
1375 | Void TComSlice::initWpScaling() |
---|
1376 | { |
---|
1377 | for ( Int e=0 ; e<2 ; e++ ) |
---|
1378 | { |
---|
1379 | for ( Int i=0 ; i<MAX_NUM_REF ; i++ ) |
---|
1380 | { |
---|
1381 | for ( Int yuv=0 ; yuv<3 ; yuv++ ) |
---|
1382 | { |
---|
1383 | wpScalingParam *pwp = &(m_weightPredTable[e][i][yuv]); |
---|
1384 | if ( !pwp->bPresentFlag ) |
---|
1385 | { |
---|
1386 | // Inferring values not present : |
---|
1387 | pwp->iWeight = (1 << pwp->uiLog2WeightDenom); |
---|
1388 | pwp->iOffset = 0; |
---|
1389 | } |
---|
1390 | |
---|
1391 | pwp->w = pwp->iWeight; |
---|
1392 | Int bitDepth = yuv ? g_bitDepthC : g_bitDepthY; |
---|
1393 | pwp->o = pwp->iOffset << (bitDepth-8); |
---|
1394 | pwp->shift = pwp->uiLog2WeightDenom; |
---|
1395 | pwp->round = (pwp->uiLog2WeightDenom>=1) ? (1 << (pwp->uiLog2WeightDenom-1)) : (0); |
---|
1396 | } |
---|
1397 | } |
---|
1398 | } |
---|
1399 | } |
---|
1400 | |
---|
1401 | // ------------------------------------------------------------------------------------------------ |
---|
1402 | // Video parameter set (VPS) |
---|
1403 | // ------------------------------------------------------------------------------------------------ |
---|
1404 | TComVPS::TComVPS() |
---|
1405 | : m_VPSId ( 0) |
---|
1406 | , m_uiMaxTLayers ( 1) |
---|
1407 | , m_uiMaxLayers ( 1) |
---|
1408 | , m_bTemporalIdNestingFlag (false) |
---|
1409 | , m_numHrdParameters ( 0) |
---|
1410 | #if H_MV |
---|
1411 | , m_maxLayerId ( 0) |
---|
1412 | #else |
---|
1413 | , m_maxNuhReservedZeroLayerId ( 0) |
---|
1414 | #endif |
---|
1415 | , m_hrdParameters (NULL) |
---|
1416 | , m_hrdOpSetIdx (NULL) |
---|
1417 | , m_cprmsPresentFlag (NULL) |
---|
1418 | { |
---|
1419 | for( Int i = 0; i < MAX_TLAYER; i++) |
---|
1420 | { |
---|
1421 | m_numReorderPics[i] = 0; |
---|
1422 | m_uiMaxDecPicBuffering[i] = 1; |
---|
1423 | m_uiMaxLatencyIncrease[i] = 0; |
---|
1424 | } |
---|
1425 | #if H_MV |
---|
1426 | for (Int lsIdx = 0; lsIdx < MAX_VPS_OP_SETS_PLUS1; lsIdx++ ) |
---|
1427 | { |
---|
1428 | for( Int layerId = 0; layerId < MAX_VPS_NUH_LAYER_ID_PLUS1; layerId++ ) |
---|
1429 | { |
---|
1430 | m_layerIdIncludedFlag[lsIdx][layerId] = false; |
---|
1431 | } |
---|
1432 | } |
---|
1433 | |
---|
1434 | m_vpsNumberLayerSetsMinus1 = -1; |
---|
1435 | m_vpsNumProfileTierLevelMinus1 = -1; |
---|
1436 | |
---|
1437 | for ( Int i = 0; i < MAX_VPS_PROFILE_TIER_LEVEL; i++) |
---|
1438 | { |
---|
1439 | m_profileRefMinus1[ i ] = -1; |
---|
1440 | } |
---|
1441 | |
---|
1442 | m_moreOutputLayerSetsThanDefaultFlag = false; |
---|
1443 | m_numAddOutputLayerSetsMinus1 = -1; |
---|
1444 | m_defaultOneTargetOutputLayerFlag = false; |
---|
1445 | |
---|
1446 | for ( Int i = 0; i < MAX_VPS_OUTPUTLAYER_SETS; i++) |
---|
1447 | { |
---|
1448 | m_outputLayerSetIdxMinus1[i] = -1; |
---|
1449 | m_profileLevelTierIdx[i] = 0; |
---|
1450 | for ( Int j = 0; j < MAX_VPS_NUH_LAYER_ID_PLUS1; j++) |
---|
1451 | { |
---|
1452 | m_outputLayerFlag[i][j] = false; |
---|
1453 | } |
---|
1454 | } |
---|
1455 | |
---|
1456 | m_maxOneActiveRefLayerFlag = false; |
---|
1457 | m_directDepTypeLenMinus2 = 0; |
---|
1458 | |
---|
1459 | |
---|
1460 | m_avcBaseLayerFlag = false; |
---|
1461 | m_splittingFlag = false; |
---|
1462 | |
---|
1463 | for( Int i = 0; i < MAX_NUM_SCALABILITY_TYPES; i++ ) |
---|
1464 | { |
---|
1465 | m_scalabilityMask[i] = false; |
---|
1466 | m_dimensionIdLen [i] = -1; |
---|
1467 | } |
---|
1468 | |
---|
1469 | m_vpsNuhLayerIdPresentFlag = false; |
---|
1470 | |
---|
1471 | for( Int i = 0; i < MAX_VPS_OP_SETS_PLUS1; i++ ) |
---|
1472 | { |
---|
1473 | m_vpsProfilePresentFlag [i] = false; |
---|
1474 | m_profileRefMinus1[i] = 0; |
---|
1475 | m_outputLayerSetIdxMinus1 [i] = 0; |
---|
1476 | for( Int j = 0; j < MAX_VPS_NUH_LAYER_ID_PLUS1; j++ ) |
---|
1477 | { |
---|
1478 | m_outputLayerFlag[i][j] = false; |
---|
1479 | } |
---|
1480 | } |
---|
1481 | |
---|
1482 | for( Int i = 0; i < MAX_NUM_LAYER_IDS; i++ ) |
---|
1483 | { |
---|
1484 | m_layerIdInVps[i] = (i == 0 ) ? 0 : -1; |
---|
1485 | } |
---|
1486 | |
---|
1487 | for( Int i = 0; i < MAX_NUM_LAYERS; i++ ) |
---|
1488 | { |
---|
1489 | m_layerIdInNuh [i] = ( i == 0 ) ? 0 : -1; |
---|
1490 | m_numDirectRefLayers[i] = 0; |
---|
1491 | m_maxTidIlRefPicPlus1[i] = -1; |
---|
1492 | #if H_3D |
---|
1493 | m_viewIndex [i] = -1; |
---|
1494 | m_vpsDepthModesFlag [i] = false; |
---|
1495 | #if H_3D_DIM_DLT |
---|
1496 | m_bUseDLTFlag [i] = false; |
---|
1497 | |
---|
1498 | // allocate some memory and initialize with default mapping |
---|
1499 | m_iNumDepthmapValues[i] = ((1 << g_bitDepthY)-1)+1; |
---|
1500 | m_iBitsPerDepthValue[i] = numBitsForValue(m_iNumDepthmapValues[i]); |
---|
1501 | |
---|
1502 | m_iDepthValue2Idx[i] = (Int*) xMalloc(Int, m_iNumDepthmapValues[i]); |
---|
1503 | m_iIdx2DepthValue[i] = (Int*) xMalloc(Int, m_iNumDepthmapValues[i]); |
---|
1504 | |
---|
1505 | //default mapping |
---|
1506 | for (Int d=0; d<m_iNumDepthmapValues[i]; d++) |
---|
1507 | { |
---|
1508 | m_iDepthValue2Idx[i][d] = d; |
---|
1509 | m_iIdx2DepthValue[i][d] = d; |
---|
1510 | } |
---|
1511 | #endif |
---|
1512 | m_ivMvScalingFlag = true; |
---|
1513 | #endif |
---|
1514 | |
---|
1515 | for( Int j = 0; j < MAX_NUM_LAYERS; j++ ) |
---|
1516 | { |
---|
1517 | m_directDependencyFlag[i][j] = false; |
---|
1518 | m_directDependencyType[i][j] = -1; |
---|
1519 | m_refLayerId[i][j] = -1; |
---|
1520 | } |
---|
1521 | |
---|
1522 | for( Int j = 0; j < MAX_NUM_SCALABILITY_TYPES; j++ ) |
---|
1523 | { |
---|
1524 | m_dimensionId[i][j] = 0; |
---|
1525 | } |
---|
1526 | #if H_3D_ARP |
---|
1527 | m_uiUseAdvResPred[i] = 0; |
---|
1528 | m_uiARPStepNum[i] = 1; |
---|
1529 | #endif |
---|
1530 | } |
---|
1531 | #if H_3D |
---|
1532 | for( Int i = 0; i < MAX_NUM_LAYERS; i++ ) |
---|
1533 | { |
---|
1534 | #if H_3D_IV_MERGE |
---|
1535 | m_ivMvPredFlag [ i ] = false; |
---|
1536 | #endif |
---|
1537 | #if H_3D_VSP |
---|
1538 | m_viewSynthesisPredFlag[ i ] = false; |
---|
1539 | #endif |
---|
1540 | #if H_3D_NBDV_REF |
---|
1541 | m_depthRefinementFlag [ i ] = false; |
---|
1542 | #endif |
---|
1543 | } |
---|
1544 | #endif |
---|
1545 | #endif |
---|
1546 | } |
---|
1547 | |
---|
1548 | TComVPS::~TComVPS() |
---|
1549 | { |
---|
1550 | if( m_hrdParameters != NULL ) delete[] m_hrdParameters; |
---|
1551 | if( m_hrdOpSetIdx != NULL ) delete[] m_hrdOpSetIdx; |
---|
1552 | if( m_cprmsPresentFlag != NULL ) delete[] m_cprmsPresentFlag; |
---|
1553 | #if H_3D_DIM_DLT |
---|
1554 | for( Int i = 0; i < MAX_NUM_LAYERS; i++ ) |
---|
1555 | { |
---|
1556 | if ( m_iDepthValue2Idx[i] != 0 ) |
---|
1557 | { |
---|
1558 | xFree( m_iDepthValue2Idx[i] ); |
---|
1559 | m_iDepthValue2Idx[i] = 0; |
---|
1560 | } |
---|
1561 | |
---|
1562 | if ( m_iIdx2DepthValue[i] != 0 ) |
---|
1563 | { |
---|
1564 | xFree( m_iIdx2DepthValue[i] ); |
---|
1565 | m_iIdx2DepthValue[i] = 0; |
---|
1566 | |
---|
1567 | } |
---|
1568 | } |
---|
1569 | #endif |
---|
1570 | } |
---|
1571 | |
---|
1572 | #if H_3D_DIM_DLT |
---|
1573 | Void TComVPS::setDepthLUTs(Int layerIdInVps, Int* idxToDepthValueTable, Int iNumDepthValues) |
---|
1574 | { |
---|
1575 | if( idxToDepthValueTable == NULL || iNumDepthValues == 0 ) // default mapping only |
---|
1576 | return; |
---|
1577 | |
---|
1578 | // copy idx2DepthValue to internal array |
---|
1579 | memcpy(m_iIdx2DepthValue[layerIdInVps], idxToDepthValueTable, iNumDepthValues*sizeof(UInt)); |
---|
1580 | |
---|
1581 | UInt uiMaxDepthValue = ((1 << g_bitDepthY)-1); |
---|
1582 | for(Int p=0; p<=uiMaxDepthValue; p++) |
---|
1583 | { |
---|
1584 | Int iIdxDown = 0; |
---|
1585 | Int iIdxUp = iNumDepthValues-1; |
---|
1586 | Bool bFound = false; |
---|
1587 | |
---|
1588 | // iterate over indices to find lower closest depth |
---|
1589 | Int i = 1; |
---|
1590 | while(!bFound && i<iNumDepthValues) |
---|
1591 | { |
---|
1592 | if( m_iIdx2DepthValue[layerIdInVps][i] > p ) |
---|
1593 | { |
---|
1594 | iIdxDown = i-1; |
---|
1595 | bFound = true; |
---|
1596 | } |
---|
1597 | |
---|
1598 | i++; |
---|
1599 | } |
---|
1600 | // iterate over indices to find upper closest depth |
---|
1601 | i = iNumDepthValues-2; |
---|
1602 | bFound = false; |
---|
1603 | while(!bFound && i>=0) |
---|
1604 | { |
---|
1605 | if( m_iIdx2DepthValue[layerIdInVps][i] < p ) |
---|
1606 | { |
---|
1607 | iIdxUp = i+1; |
---|
1608 | bFound = true; |
---|
1609 | } |
---|
1610 | |
---|
1611 | i--; |
---|
1612 | } |
---|
1613 | |
---|
1614 | // assert monotony |
---|
1615 | assert(iIdxDown<=iIdxUp); |
---|
1616 | |
---|
1617 | // assign closer depth value/idx |
---|
1618 | if( abs(p-m_iIdx2DepthValue[layerIdInVps][iIdxDown]) < abs(p-m_iIdx2DepthValue[layerIdInVps][iIdxUp]) ) |
---|
1619 | { |
---|
1620 | m_iDepthValue2Idx[layerIdInVps][p] = iIdxDown; |
---|
1621 | } |
---|
1622 | else |
---|
1623 | { |
---|
1624 | m_iDepthValue2Idx[layerIdInVps][p] = iIdxUp; |
---|
1625 | } |
---|
1626 | |
---|
1627 | } |
---|
1628 | |
---|
1629 | // update DLT variables |
---|
1630 | m_iNumDepthmapValues[layerIdInVps] = iNumDepthValues; |
---|
1631 | m_iBitsPerDepthValue[layerIdInVps] = numBitsForValue(m_iNumDepthmapValues[layerIdInVps]); |
---|
1632 | } |
---|
1633 | #endif |
---|
1634 | |
---|
1635 | #if H_MV |
---|
1636 | |
---|
1637 | Bool TComVPS::checkVPSExtensionSyntax() |
---|
1638 | { |
---|
1639 | for( Int layer = 1; layer < getMaxLayers(); layer++ ) |
---|
1640 | { |
---|
1641 | // check layer_id_in_nuh constraint |
---|
1642 | assert( getLayerIdInNuh( layer ) > getLayerIdInNuh( layer -1 ) ); |
---|
1643 | } |
---|
1644 | return true; |
---|
1645 | } |
---|
1646 | |
---|
1647 | Int TComVPS::getNumScalabilityTypes() |
---|
1648 | { |
---|
1649 | return scalTypeToScalIdx( ScalabilityType(MAX_NUM_SCALABILITY_TYPES) ); |
---|
1650 | } |
---|
1651 | |
---|
1652 | Int TComVPS::scalTypeToScalIdx( ScalabilityType scalType ) |
---|
1653 | { |
---|
1654 | assert( scalType >= 0 && scalType <= MAX_NUM_SCALABILITY_TYPES ); |
---|
1655 | assert( scalType == MAX_NUM_SCALABILITY_TYPES || getScalabilityMask( scalType ) ); |
---|
1656 | |
---|
1657 | Int scalIdx = 0; |
---|
1658 | for( Int curScalType = 0; curScalType < scalType; curScalType++ ) |
---|
1659 | { |
---|
1660 | scalIdx += ( getScalabilityMask( curScalType ) ? 1 : 0 ); |
---|
1661 | } |
---|
1662 | |
---|
1663 | return scalIdx; |
---|
1664 | } |
---|
1665 | |
---|
1666 | Void TComVPS::setScalabilityMask( UInt val ) |
---|
1667 | { |
---|
1668 | for ( Int scalType = 0; scalType < MAX_NUM_SCALABILITY_TYPES; scalType++ ) |
---|
1669 | setScalabilityMask( scalType, ( val & (1 << scalType ) ) != 0 ); |
---|
1670 | } |
---|
1671 | |
---|
1672 | Void TComVPS::setRefLayers() |
---|
1673 | { |
---|
1674 | for( Int i = 0; i < MAX_NUM_LAYERS; i++ ) |
---|
1675 | { |
---|
1676 | m_numSamplePredRefLayers[ i ] = 0; |
---|
1677 | m_numMotionPredRefLayers[ i ] = 0; |
---|
1678 | m_numDirectRefLayers[ i ] = 0; |
---|
1679 | for( Int j = 0; j < MAX_NUM_LAYERS; j++ ) { |
---|
1680 | m_samplePredEnabledFlag[ i ][ j ] = 0; |
---|
1681 | m_motionPredEnabledFlag[ i ][ j ] = 0; |
---|
1682 | m_refLayerId[ i ][ j ] = 0; |
---|
1683 | m_samplePredRefLayerId[ i ][ j ] = 0; |
---|
1684 | m_motionPredRefLayerId[ i ][ j ] = 0; |
---|
1685 | } |
---|
1686 | } |
---|
1687 | |
---|
1688 | for( Int i = 1; i <= getMaxLayers()- 1; i++ ) |
---|
1689 | { |
---|
1690 | for( Int j = 0; j < i; j++ ) |
---|
1691 | { |
---|
1692 | if( getDirectDependencyFlag(i,j) ) |
---|
1693 | { |
---|
1694 | m_refLayerId[ i ][m_numDirectRefLayers[ i ]++ ] = getLayerIdInNuh( j ); |
---|
1695 | |
---|
1696 | m_samplePredEnabledFlag [ i ][ j ] = ( ( getDirectDependencyType( i , j ) + 1 ) & 1 ) == 1; |
---|
1697 | m_numSamplePredRefLayers[ i ] += m_samplePredEnabledFlag [ i ][ j ] ? 1 : 0; |
---|
1698 | m_motionPredEnabledFlag [ i ][ j ] = ( ( ( getDirectDependencyType( i , j ) + 1 ) & 2 ) >> 1 ) == 1; |
---|
1699 | m_numMotionPredRefLayers[ i ] += m_motionPredEnabledFlag [ i][ j ] ? 1 : 0; |
---|
1700 | } |
---|
1701 | } |
---|
1702 | } |
---|
1703 | |
---|
1704 | for( Int i = 1, mIdx = 0, sIdx = 0; i <= getMaxLayers()- 1; i++ ) |
---|
1705 | { |
---|
1706 | for( Int j = 0 ; j < i; j++ ) |
---|
1707 | { |
---|
1708 | if( m_motionPredEnabledFlag[ i ][ j ] ) |
---|
1709 | { |
---|
1710 | m_motionPredRefLayerId[ i ][ mIdx++ ] = getLayerIdInNuh( j ); |
---|
1711 | } |
---|
1712 | |
---|
1713 | if( m_samplePredEnabledFlag[ i ][ j ] ) |
---|
1714 | { |
---|
1715 | m_samplePredRefLayerId[ i ][ sIdx++ ] = getLayerIdInNuh( j ); |
---|
1716 | } |
---|
1717 | } |
---|
1718 | } |
---|
1719 | } |
---|
1720 | |
---|
1721 | Int TComVPS::getRefLayerId( Int layerIdInVps, Int idx ) |
---|
1722 | { |
---|
1723 | assert( idx >= 0 && idx < m_numDirectRefLayers[layerIdInVps] ); |
---|
1724 | Int layerIdInNuh = m_refLayerId[ layerIdInVps ][ idx ]; |
---|
1725 | assert ( layerIdInNuh >= 0 ); |
---|
1726 | return layerIdInNuh; |
---|
1727 | } |
---|
1728 | |
---|
1729 | Int TComVPS::getScalabilityId( Int layerIdInVps, ScalabilityType scalType ) |
---|
1730 | { |
---|
1731 | return getScalabilityMask( scalType ) ? getDimensionId( layerIdInVps, scalTypeToScalIdx( scalType ) ) : 0; |
---|
1732 | } |
---|
1733 | |
---|
1734 | #if H_3D |
---|
1735 | Void TComVPS::initViewIndex() |
---|
1736 | { |
---|
1737 | Int viewIdList [ MAX_NUM_LAYERS ]; // ed. should be changed to MAX_VIEW_ID |
---|
1738 | Int viewIndexList[ MAX_NUM_LAYERS ]; |
---|
1739 | Int numViewIds = 0; |
---|
1740 | |
---|
1741 | for ( Int i = 0 ; i < m_uiMaxLayers; i++ ) |
---|
1742 | { |
---|
1743 | Int currViewId = getViewId( i ); |
---|
1744 | |
---|
1745 | Bool viewIdInListFlag = false; |
---|
1746 | for ( Int j = 0; j < numViewIds; j ++ ) |
---|
1747 | { |
---|
1748 | viewIdInListFlag = viewIdInListFlag || ( currViewId == viewIdList[ j ] ); |
---|
1749 | } |
---|
1750 | |
---|
1751 | if ( !viewIdInListFlag ) |
---|
1752 | { |
---|
1753 | viewIdList [ numViewIds ] = currViewId; |
---|
1754 | viewIndexList[ currViewId ] = numViewIds; |
---|
1755 | |
---|
1756 | numViewIds++; |
---|
1757 | } |
---|
1758 | |
---|
1759 | m_viewIndex[ i ] = viewIndexList[ currViewId ]; |
---|
1760 | } |
---|
1761 | } |
---|
1762 | |
---|
1763 | Int TComVPS::getLayerIdInNuh( Int viewIndex, Bool depthFlag ) |
---|
1764 | { |
---|
1765 | Int foundlayerId = -1; |
---|
1766 | |
---|
1767 | for (Int layer = 0 ; layer < m_uiMaxLayers; layer++ ) |
---|
1768 | { |
---|
1769 | if( ( getViewIndex( layer ) == viewIndex ) && ( getDepthId( layer ) == ( depthFlag ? 1 : 0 ) ) ) |
---|
1770 | { |
---|
1771 | foundlayerId = layer; |
---|
1772 | break; |
---|
1773 | } |
---|
1774 | } |
---|
1775 | assert( foundlayerId != -1 ); |
---|
1776 | |
---|
1777 | return getLayerIdInNuh( foundlayerId ); |
---|
1778 | } |
---|
1779 | |
---|
1780 | #endif // H_3D |
---|
1781 | |
---|
1782 | Int TComVPS::xCeilLog2( Int val ) |
---|
1783 | { |
---|
1784 | assert( val > 0 ); |
---|
1785 | Int ceilLog2 = 0; |
---|
1786 | while( val > ( 1 << ceilLog2 ) ) ceilLog2++; |
---|
1787 | return ceilLog2; |
---|
1788 | } |
---|
1789 | |
---|
1790 | |
---|
1791 | Int TComVPS::xGetDimBitOffset( Int j ) |
---|
1792 | { |
---|
1793 | Int dimBitOffset = 0; |
---|
1794 | if ( getSplittingFlag() && j == getNumScalabilityTypes() ) |
---|
1795 | { |
---|
1796 | dimBitOffset = 6; |
---|
1797 | } |
---|
1798 | else |
---|
1799 | { |
---|
1800 | for (Int dimIdx = 0; dimIdx <= j-1; dimIdx++) |
---|
1801 | { |
---|
1802 | dimBitOffset += getDimensionIdLen( dimIdx ); |
---|
1803 | } |
---|
1804 | } |
---|
1805 | return dimBitOffset; |
---|
1806 | } |
---|
1807 | |
---|
1808 | Int TComVPS::inferDimensionId( Int i, Int j ) |
---|
1809 | { |
---|
1810 | return ( ( getLayerIdInNuh( i ) & ( (1 << xGetDimBitOffset( j + 1 ) ) - 1) ) >> xGetDimBitOffset( j ) ); |
---|
1811 | } |
---|
1812 | |
---|
1813 | Int TComVPS::inferLastDimsionIdLenMinus1() |
---|
1814 | { |
---|
1815 | return ( 5 - xGetDimBitOffset( getNumScalabilityTypes() - 1 ) ); |
---|
1816 | } |
---|
1817 | |
---|
1818 | Int TComVPS::getNumLayersInIdList( Int lsIdx ) |
---|
1819 | { |
---|
1820 | assert( lsIdx >= 0 ); |
---|
1821 | assert( lsIdx <= getVpsNumLayerSetsMinus1() ); |
---|
1822 | Int numLayersInIdList = 0; |
---|
1823 | for (Int layerId = 0; layerId < getVpsMaxLayerId(); layerId++ ) |
---|
1824 | { |
---|
1825 | numLayersInIdList += ( getLayerIdIncludedFlag( lsIdx, layerId ) ); |
---|
1826 | } |
---|
1827 | return numLayersInIdList; |
---|
1828 | } |
---|
1829 | #endif // H_MV |
---|
1830 | |
---|
1831 | // ------------------------------------------------------------------------------------------------ |
---|
1832 | // Sequence parameter set (SPS) |
---|
1833 | // ------------------------------------------------------------------------------------------------ |
---|
1834 | |
---|
1835 | TComSPS::TComSPS() |
---|
1836 | : m_SPSId ( 0) |
---|
1837 | , m_VPSId ( 0) |
---|
1838 | , m_chromaFormatIdc (CHROMA_420) |
---|
1839 | , m_uiMaxTLayers ( 1) |
---|
1840 | // Structure |
---|
1841 | , m_picWidthInLumaSamples (352) |
---|
1842 | , m_picHeightInLumaSamples (288) |
---|
1843 | , m_log2MinCodingBlockSize ( 0) |
---|
1844 | , m_log2DiffMaxMinCodingBlockSize (0) |
---|
1845 | , m_uiMaxCUWidth ( 32) |
---|
1846 | , m_uiMaxCUHeight ( 32) |
---|
1847 | , m_uiMaxCUDepth ( 3) |
---|
1848 | , m_bLongTermRefsPresent (false) |
---|
1849 | , m_uiQuadtreeTULog2MaxSize ( 0) |
---|
1850 | , m_uiQuadtreeTULog2MinSize ( 0) |
---|
1851 | , m_uiQuadtreeTUMaxDepthInter ( 0) |
---|
1852 | , m_uiQuadtreeTUMaxDepthIntra ( 0) |
---|
1853 | // Tool list |
---|
1854 | , m_usePCM (false) |
---|
1855 | , m_pcmLog2MaxSize ( 5) |
---|
1856 | , m_uiPCMLog2MinSize ( 7) |
---|
1857 | #if H_3D_QTLPC |
---|
1858 | , m_bUseQTL (false) |
---|
1859 | , m_bUsePC (false) |
---|
1860 | #endif |
---|
1861 | , m_bitDepthY ( 8) |
---|
1862 | , m_bitDepthC ( 8) |
---|
1863 | , m_qpBDOffsetY ( 0) |
---|
1864 | , m_qpBDOffsetC ( 0) |
---|
1865 | , m_useLossless (false) |
---|
1866 | , m_uiPCMBitDepthLuma ( 8) |
---|
1867 | , m_uiPCMBitDepthChroma ( 8) |
---|
1868 | , m_bPCMFilterDisableFlag (false) |
---|
1869 | , m_uiBitsForPOC ( 8) |
---|
1870 | , m_numLongTermRefPicSPS ( 0) |
---|
1871 | , m_uiMaxTrSize ( 32) |
---|
1872 | , m_bUseSAO (false) |
---|
1873 | , m_bTemporalIdNestingFlag (false) |
---|
1874 | , m_scalingListEnabledFlag (false) |
---|
1875 | , m_useStrongIntraSmoothing (false) |
---|
1876 | , m_vuiParametersPresentFlag (false) |
---|
1877 | , m_vuiParameters () |
---|
1878 | #if H_MV |
---|
1879 | , m_interViewMvVertConstraintFlag (false) |
---|
1880 | , m_numIlpRestrictedRefLayers ( 0 ) |
---|
1881 | #endif |
---|
1882 | #if H_3D |
---|
1883 | , m_bCamParInSliceHeader (false) |
---|
1884 | #endif |
---|
1885 | { |
---|
1886 | for ( Int i = 0; i < MAX_TLAYER; i++ ) |
---|
1887 | { |
---|
1888 | m_uiMaxLatencyIncrease[i] = 0; |
---|
1889 | m_uiMaxDecPicBuffering[i] = 1; |
---|
1890 | m_numReorderPics[i] = 0; |
---|
1891 | } |
---|
1892 | m_scalingList = new TComScalingList; |
---|
1893 | ::memset(m_ltRefPicPocLsbSps, 0, sizeof(m_ltRefPicPocLsbSps)); |
---|
1894 | ::memset(m_usedByCurrPicLtSPSFlag, 0, sizeof(m_usedByCurrPicLtSPSFlag)); |
---|
1895 | #if H_MV |
---|
1896 | for (Int i = 0; i < MAX_NUM_LAYERS; i++ ) |
---|
1897 | { |
---|
1898 | m_minSpatialSegmentOffsetPlus1[ i ] = 0; |
---|
1899 | m_ctuBasedOffsetEnabledFlag [ i ] = false; |
---|
1900 | m_minHorizontalCtuOffsetPlus1 [ i ] = 0; |
---|
1901 | } |
---|
1902 | #endif |
---|
1903 | } |
---|
1904 | |
---|
1905 | TComSPS::~TComSPS() |
---|
1906 | { |
---|
1907 | delete m_scalingList; |
---|
1908 | m_RPSList.destroy(); |
---|
1909 | } |
---|
1910 | |
---|
1911 | Void TComSPS::createRPSList( Int numRPS ) |
---|
1912 | { |
---|
1913 | m_RPSList.destroy(); |
---|
1914 | m_RPSList.create(numRPS); |
---|
1915 | } |
---|
1916 | |
---|
1917 | Void TComSPS::setHrdParameters( UInt frameRate, UInt numDU, UInt bitRate, Bool randomAccess ) |
---|
1918 | { |
---|
1919 | if( !getVuiParametersPresentFlag() ) |
---|
1920 | { |
---|
1921 | return; |
---|
1922 | } |
---|
1923 | |
---|
1924 | TComVUI *vui = getVuiParameters(); |
---|
1925 | TComHRD *hrd = vui->getHrdParameters(); |
---|
1926 | |
---|
1927 | TimingInfo *timingInfo = vui->getTimingInfo(); |
---|
1928 | timingInfo->setTimingInfoPresentFlag( true ); |
---|
1929 | switch( frameRate ) |
---|
1930 | { |
---|
1931 | case 24: |
---|
1932 | timingInfo->setNumUnitsInTick( 1125000 ); timingInfo->setTimeScale ( 27000000 ); |
---|
1933 | break; |
---|
1934 | case 25: |
---|
1935 | timingInfo->setNumUnitsInTick( 1080000 ); timingInfo->setTimeScale ( 27000000 ); |
---|
1936 | break; |
---|
1937 | case 30: |
---|
1938 | timingInfo->setNumUnitsInTick( 900900 ); timingInfo->setTimeScale ( 27000000 ); |
---|
1939 | break; |
---|
1940 | case 50: |
---|
1941 | timingInfo->setNumUnitsInTick( 540000 ); timingInfo->setTimeScale ( 27000000 ); |
---|
1942 | break; |
---|
1943 | case 60: |
---|
1944 | timingInfo->setNumUnitsInTick( 450450 ); timingInfo->setTimeScale ( 27000000 ); |
---|
1945 | break; |
---|
1946 | default: |
---|
1947 | timingInfo->setNumUnitsInTick( 1001 ); timingInfo->setTimeScale ( 60000 ); |
---|
1948 | break; |
---|
1949 | } |
---|
1950 | |
---|
1951 | Bool rateCnt = ( bitRate > 0 ); |
---|
1952 | hrd->setNalHrdParametersPresentFlag( rateCnt ); |
---|
1953 | hrd->setVclHrdParametersPresentFlag( rateCnt ); |
---|
1954 | |
---|
1955 | hrd->setSubPicCpbParamsPresentFlag( ( numDU > 1 ) ); |
---|
1956 | |
---|
1957 | if( hrd->getSubPicCpbParamsPresentFlag() ) |
---|
1958 | { |
---|
1959 | hrd->setTickDivisorMinus2( 100 - 2 ); // |
---|
1960 | hrd->setDuCpbRemovalDelayLengthMinus1( 7 ); // 8-bit precision ( plus 1 for last DU in AU ) |
---|
1961 | hrd->setSubPicCpbParamsInPicTimingSEIFlag( true ); |
---|
1962 | hrd->setDpbOutputDelayDuLengthMinus1( 5 + 7 ); // With sub-clock tick factor of 100, at least 7 bits to have the same value as AU dpb delay |
---|
1963 | } |
---|
1964 | else |
---|
1965 | { |
---|
1966 | hrd->setSubPicCpbParamsInPicTimingSEIFlag( false ); |
---|
1967 | } |
---|
1968 | |
---|
1969 | hrd->setBitRateScale( 4 ); // in units of 2~( 6 + 4 ) = 1,024 bps |
---|
1970 | hrd->setCpbSizeScale( 6 ); // in units of 2~( 4 + 4 ) = 1,024 bit |
---|
1971 | hrd->setDuCpbSizeScale( 6 ); // in units of 2~( 4 + 4 ) = 1,024 bit |
---|
1972 | |
---|
1973 | hrd->setInitialCpbRemovalDelayLengthMinus1(15); // assuming 0.5 sec, log2( 90,000 * 0.5 ) = 16-bit |
---|
1974 | if( randomAccess ) |
---|
1975 | { |
---|
1976 | hrd->setCpbRemovalDelayLengthMinus1(5); // 32 = 2^5 (plus 1) |
---|
1977 | hrd->setDpbOutputDelayLengthMinus1 (5); // 32 + 3 = 2^6 |
---|
1978 | } |
---|
1979 | else |
---|
1980 | { |
---|
1981 | hrd->setCpbRemovalDelayLengthMinus1(9); // max. 2^10 |
---|
1982 | hrd->setDpbOutputDelayLengthMinus1 (9); // max. 2^10 |
---|
1983 | } |
---|
1984 | |
---|
1985 | /* |
---|
1986 | Note: only the case of "vps_max_temporal_layers_minus1 = 0" is supported. |
---|
1987 | */ |
---|
1988 | Int i, j; |
---|
1989 | UInt birateValue, cpbSizeValue; |
---|
1990 | UInt ducpbSizeValue; |
---|
1991 | UInt duBitRateValue = 0; |
---|
1992 | |
---|
1993 | for( i = 0; i < MAX_TLAYER; i ++ ) |
---|
1994 | { |
---|
1995 | hrd->setFixedPicRateFlag( i, 1 ); |
---|
1996 | hrd->setPicDurationInTcMinus1( i, 0 ); |
---|
1997 | hrd->setLowDelayHrdFlag( i, 0 ); |
---|
1998 | hrd->setCpbCntMinus1( i, 0 ); |
---|
1999 | |
---|
2000 | birateValue = bitRate; |
---|
2001 | cpbSizeValue = bitRate; // 1 second |
---|
2002 | ducpbSizeValue = bitRate/numDU; |
---|
2003 | duBitRateValue = bitRate; |
---|
2004 | for( j = 0; j < ( hrd->getCpbCntMinus1( i ) + 1 ); j ++ ) |
---|
2005 | { |
---|
2006 | hrd->setBitRateValueMinus1( i, j, 0, ( birateValue - 1 ) ); |
---|
2007 | hrd->setCpbSizeValueMinus1( i, j, 0, ( cpbSizeValue - 1 ) ); |
---|
2008 | hrd->setDuCpbSizeValueMinus1( i, j, 0, ( ducpbSizeValue - 1 ) ); |
---|
2009 | hrd->setCbrFlag( i, j, 0, ( j == 0 ) ); |
---|
2010 | |
---|
2011 | hrd->setBitRateValueMinus1( i, j, 1, ( birateValue - 1) ); |
---|
2012 | hrd->setCpbSizeValueMinus1( i, j, 1, ( cpbSizeValue - 1 ) ); |
---|
2013 | hrd->setDuCpbSizeValueMinus1( i, j, 1, ( ducpbSizeValue - 1 ) ); |
---|
2014 | hrd->setDuBitRateValueMinus1( i, j, 1, ( duBitRateValue - 1 ) ); |
---|
2015 | hrd->setCbrFlag( i, j, 1, ( j == 0 ) ); |
---|
2016 | } |
---|
2017 | } |
---|
2018 | } |
---|
2019 | const Int TComSPS::m_winUnitX[]={1,2,2,1}; |
---|
2020 | const Int TComSPS::m_winUnitY[]={1,2,1,1}; |
---|
2021 | |
---|
2022 | TComPPS::TComPPS() |
---|
2023 | : m_PPSId (0) |
---|
2024 | , m_SPSId (0) |
---|
2025 | , m_picInitQPMinus26 (0) |
---|
2026 | , m_useDQP (false) |
---|
2027 | , m_bConstrainedIntraPred (false) |
---|
2028 | , m_bSliceChromaQpFlag (false) |
---|
2029 | , m_pcSPS (NULL) |
---|
2030 | , m_uiMaxCuDQPDepth (0) |
---|
2031 | , m_uiMinCuDQPSize (0) |
---|
2032 | , m_chromaCbQpOffset (0) |
---|
2033 | , m_chromaCrQpOffset (0) |
---|
2034 | , m_numRefIdxL0DefaultActive (1) |
---|
2035 | , m_numRefIdxL1DefaultActive (1) |
---|
2036 | , m_TransquantBypassEnableFlag (false) |
---|
2037 | , m_useTransformSkip (false) |
---|
2038 | , m_dependentSliceSegmentsEnabledFlag (false) |
---|
2039 | , m_tilesEnabledFlag (false) |
---|
2040 | , m_entropyCodingSyncEnabledFlag (false) |
---|
2041 | , m_loopFilterAcrossTilesEnabledFlag (true) |
---|
2042 | , m_uniformSpacingFlag (0) |
---|
2043 | , m_iNumColumnsMinus1 (0) |
---|
2044 | , m_puiColumnWidth (NULL) |
---|
2045 | , m_iNumRowsMinus1 (0) |
---|
2046 | , m_puiRowHeight (NULL) |
---|
2047 | , m_iNumSubstreams (1) |
---|
2048 | , m_signHideFlag(0) |
---|
2049 | , m_cabacInitPresentFlag (false) |
---|
2050 | , m_encCABACTableIdx (I_SLICE) |
---|
2051 | , m_sliceHeaderExtensionPresentFlag (false) |
---|
2052 | , m_loopFilterAcrossSlicesEnabledFlag (false) |
---|
2053 | , m_listsModificationPresentFlag( 0) |
---|
2054 | , m_numExtraSliceHeaderBits(0) |
---|
2055 | { |
---|
2056 | m_scalingList = new TComScalingList; |
---|
2057 | } |
---|
2058 | |
---|
2059 | TComPPS::~TComPPS() |
---|
2060 | { |
---|
2061 | if( m_iNumColumnsMinus1 > 0 && m_uniformSpacingFlag == 0 ) |
---|
2062 | { |
---|
2063 | if (m_puiColumnWidth) delete [] m_puiColumnWidth; |
---|
2064 | m_puiColumnWidth = NULL; |
---|
2065 | } |
---|
2066 | if( m_iNumRowsMinus1 > 0 && m_uniformSpacingFlag == 0 ) |
---|
2067 | { |
---|
2068 | if (m_puiRowHeight) delete [] m_puiRowHeight; |
---|
2069 | m_puiRowHeight = NULL; |
---|
2070 | } |
---|
2071 | delete m_scalingList; |
---|
2072 | } |
---|
2073 | |
---|
2074 | #if H_3D |
---|
2075 | Void |
---|
2076 | TComSPS::initCamParaSPS( UInt uiViewIndex, UInt uiCamParPrecision, Bool bCamParSlice, Int** aaiScale, Int** aaiOffset ) |
---|
2077 | { |
---|
2078 | AOT( uiViewIndex != 0 && !bCamParSlice && ( aaiScale == 0 || aaiOffset == 0 ) ); |
---|
2079 | |
---|
2080 | m_uiCamParPrecision = ( uiViewIndex ? uiCamParPrecision : 0 ); |
---|
2081 | m_bCamParInSliceHeader = ( uiViewIndex ? bCamParSlice : false ); |
---|
2082 | ::memset( m_aaiCodedScale, 0x00, sizeof( m_aaiCodedScale ) ); |
---|
2083 | ::memset( m_aaiCodedOffset, 0x00, sizeof( m_aaiCodedOffset ) ); |
---|
2084 | |
---|
2085 | if( !m_bCamParInSliceHeader ) |
---|
2086 | { |
---|
2087 | for( UInt uiBaseViewIndex = 0; uiBaseViewIndex < uiViewIndex; uiBaseViewIndex++ ) |
---|
2088 | { |
---|
2089 | m_aaiCodedScale [ 0 ][ uiBaseViewIndex ] = aaiScale [ uiBaseViewIndex ][ uiViewIndex ]; |
---|
2090 | m_aaiCodedScale [ 1 ][ uiBaseViewIndex ] = aaiScale [ uiViewIndex ][ uiBaseViewIndex ]; |
---|
2091 | m_aaiCodedOffset[ 0 ][ uiBaseViewIndex ] = aaiOffset[ uiBaseViewIndex ][ uiViewIndex ]; |
---|
2092 | m_aaiCodedOffset[ 1 ][ uiBaseViewIndex ] = aaiOffset[ uiViewIndex ][ uiBaseViewIndex ]; |
---|
2093 | } |
---|
2094 | } |
---|
2095 | } |
---|
2096 | #endif |
---|
2097 | TComReferencePictureSet::TComReferencePictureSet() |
---|
2098 | : m_numberOfPictures (0) |
---|
2099 | , m_numberOfNegativePictures (0) |
---|
2100 | , m_numberOfPositivePictures (0) |
---|
2101 | , m_numberOfLongtermPictures (0) |
---|
2102 | , m_interRPSPrediction (0) |
---|
2103 | , m_deltaRIdxMinus1 (0) |
---|
2104 | , m_deltaRPS (0) |
---|
2105 | , m_numRefIdc (0) |
---|
2106 | { |
---|
2107 | ::memset( m_deltaPOC, 0, sizeof(m_deltaPOC) ); |
---|
2108 | ::memset( m_POC, 0, sizeof(m_POC) ); |
---|
2109 | ::memset( m_used, 0, sizeof(m_used) ); |
---|
2110 | ::memset( m_refIdc, 0, sizeof(m_refIdc) ); |
---|
2111 | } |
---|
2112 | |
---|
2113 | TComReferencePictureSet::~TComReferencePictureSet() |
---|
2114 | { |
---|
2115 | } |
---|
2116 | |
---|
2117 | Void TComReferencePictureSet::setUsed(Int bufferNum, Bool used) |
---|
2118 | { |
---|
2119 | m_used[bufferNum] = used; |
---|
2120 | } |
---|
2121 | |
---|
2122 | Void TComReferencePictureSet::setDeltaPOC(Int bufferNum, Int deltaPOC) |
---|
2123 | { |
---|
2124 | m_deltaPOC[bufferNum] = deltaPOC; |
---|
2125 | } |
---|
2126 | |
---|
2127 | Void TComReferencePictureSet::setNumberOfPictures(Int numberOfPictures) |
---|
2128 | { |
---|
2129 | m_numberOfPictures = numberOfPictures; |
---|
2130 | } |
---|
2131 | |
---|
2132 | Int TComReferencePictureSet::getUsed(Int bufferNum) |
---|
2133 | { |
---|
2134 | return m_used[bufferNum]; |
---|
2135 | } |
---|
2136 | |
---|
2137 | Int TComReferencePictureSet::getDeltaPOC(Int bufferNum) |
---|
2138 | { |
---|
2139 | return m_deltaPOC[bufferNum]; |
---|
2140 | } |
---|
2141 | |
---|
2142 | Int TComReferencePictureSet::getNumberOfPictures() |
---|
2143 | { |
---|
2144 | return m_numberOfPictures; |
---|
2145 | } |
---|
2146 | |
---|
2147 | Int TComReferencePictureSet::getPOC(Int bufferNum) |
---|
2148 | { |
---|
2149 | return m_POC[bufferNum]; |
---|
2150 | } |
---|
2151 | |
---|
2152 | Void TComReferencePictureSet::setPOC(Int bufferNum, Int POC) |
---|
2153 | { |
---|
2154 | m_POC[bufferNum] = POC; |
---|
2155 | } |
---|
2156 | |
---|
2157 | Bool TComReferencePictureSet::getCheckLTMSBPresent(Int bufferNum) |
---|
2158 | { |
---|
2159 | return m_bCheckLTMSB[bufferNum]; |
---|
2160 | } |
---|
2161 | |
---|
2162 | Void TComReferencePictureSet::setCheckLTMSBPresent(Int bufferNum, Bool b) |
---|
2163 | { |
---|
2164 | m_bCheckLTMSB[bufferNum] = b; |
---|
2165 | } |
---|
2166 | |
---|
2167 | /** set the reference idc value at uiBufferNum entry to the value of iRefIdc |
---|
2168 | * \param uiBufferNum |
---|
2169 | * \param iRefIdc |
---|
2170 | * \returns Void |
---|
2171 | */ |
---|
2172 | Void TComReferencePictureSet::setRefIdc(Int bufferNum, Int refIdc) |
---|
2173 | { |
---|
2174 | m_refIdc[bufferNum] = refIdc; |
---|
2175 | } |
---|
2176 | |
---|
2177 | /** get the reference idc value at uiBufferNum |
---|
2178 | * \param uiBufferNum |
---|
2179 | * \returns Int |
---|
2180 | */ |
---|
2181 | Int TComReferencePictureSet::getRefIdc(Int bufferNum) |
---|
2182 | { |
---|
2183 | return m_refIdc[bufferNum]; |
---|
2184 | } |
---|
2185 | |
---|
2186 | /** Sorts the deltaPOC and Used by current values in the RPS based on the deltaPOC values. |
---|
2187 | * deltaPOC values are sorted with -ve values before the +ve values. -ve values are in decreasing order. |
---|
2188 | * +ve values are in increasing order. |
---|
2189 | * \returns Void |
---|
2190 | */ |
---|
2191 | Void TComReferencePictureSet::sortDeltaPOC() |
---|
2192 | { |
---|
2193 | // sort in increasing order (smallest first) |
---|
2194 | for(Int j=1; j < getNumberOfPictures(); j++) |
---|
2195 | { |
---|
2196 | Int deltaPOC = getDeltaPOC(j); |
---|
2197 | Bool used = getUsed(j); |
---|
2198 | for (Int k=j-1; k >= 0; k--) |
---|
2199 | { |
---|
2200 | Int temp = getDeltaPOC(k); |
---|
2201 | if (deltaPOC < temp) |
---|
2202 | { |
---|
2203 | setDeltaPOC(k+1, temp); |
---|
2204 | setUsed(k+1, getUsed(k)); |
---|
2205 | setDeltaPOC(k, deltaPOC); |
---|
2206 | setUsed(k, used); |
---|
2207 | } |
---|
2208 | } |
---|
2209 | } |
---|
2210 | // flip the negative values to largest first |
---|
2211 | Int numNegPics = getNumberOfNegativePictures(); |
---|
2212 | for(Int j=0, k=numNegPics-1; j < numNegPics>>1; j++, k--) |
---|
2213 | { |
---|
2214 | Int deltaPOC = getDeltaPOC(j); |
---|
2215 | Bool used = getUsed(j); |
---|
2216 | setDeltaPOC(j, getDeltaPOC(k)); |
---|
2217 | setUsed(j, getUsed(k)); |
---|
2218 | setDeltaPOC(k, deltaPOC); |
---|
2219 | setUsed(k, used); |
---|
2220 | } |
---|
2221 | } |
---|
2222 | |
---|
2223 | /** Prints the deltaPOC and RefIdc (if available) values in the RPS. |
---|
2224 | * A "*" is added to the deltaPOC value if it is Used bu current. |
---|
2225 | * \returns Void |
---|
2226 | */ |
---|
2227 | Void TComReferencePictureSet::printDeltaPOC() |
---|
2228 | { |
---|
2229 | printf("DeltaPOC = { "); |
---|
2230 | for(Int j=0; j < getNumberOfPictures(); j++) |
---|
2231 | { |
---|
2232 | printf("%d%s ", getDeltaPOC(j), (getUsed(j)==1)?"*":""); |
---|
2233 | } |
---|
2234 | if (getInterRPSPrediction()) |
---|
2235 | { |
---|
2236 | printf("}, RefIdc = { "); |
---|
2237 | for(Int j=0; j < getNumRefIdc(); j++) |
---|
2238 | { |
---|
2239 | printf("%d ", getRefIdc(j)); |
---|
2240 | } |
---|
2241 | } |
---|
2242 | printf("}\n"); |
---|
2243 | } |
---|
2244 | |
---|
2245 | TComRPSList::TComRPSList() |
---|
2246 | :m_referencePictureSets (NULL) |
---|
2247 | { |
---|
2248 | } |
---|
2249 | |
---|
2250 | TComRPSList::~TComRPSList() |
---|
2251 | { |
---|
2252 | } |
---|
2253 | |
---|
2254 | Void TComRPSList::create( Int numberOfReferencePictureSets) |
---|
2255 | { |
---|
2256 | m_numberOfReferencePictureSets = numberOfReferencePictureSets; |
---|
2257 | m_referencePictureSets = new TComReferencePictureSet[numberOfReferencePictureSets]; |
---|
2258 | } |
---|
2259 | |
---|
2260 | Void TComRPSList::destroy() |
---|
2261 | { |
---|
2262 | if (m_referencePictureSets) |
---|
2263 | { |
---|
2264 | delete [] m_referencePictureSets; |
---|
2265 | } |
---|
2266 | m_numberOfReferencePictureSets = 0; |
---|
2267 | m_referencePictureSets = NULL; |
---|
2268 | } |
---|
2269 | |
---|
2270 | |
---|
2271 | |
---|
2272 | TComReferencePictureSet* TComRPSList::getReferencePictureSet(Int referencePictureSetNum) |
---|
2273 | { |
---|
2274 | return &m_referencePictureSets[referencePictureSetNum]; |
---|
2275 | } |
---|
2276 | |
---|
2277 | Int TComRPSList::getNumberOfReferencePictureSets() |
---|
2278 | { |
---|
2279 | return m_numberOfReferencePictureSets; |
---|
2280 | } |
---|
2281 | |
---|
2282 | Void TComRPSList::setNumberOfReferencePictureSets(Int numberOfReferencePictureSets) |
---|
2283 | { |
---|
2284 | m_numberOfReferencePictureSets = numberOfReferencePictureSets; |
---|
2285 | } |
---|
2286 | |
---|
2287 | TComRefPicListModification::TComRefPicListModification() |
---|
2288 | : m_bRefPicListModificationFlagL0 (false) |
---|
2289 | , m_bRefPicListModificationFlagL1 (false) |
---|
2290 | { |
---|
2291 | ::memset( m_RefPicSetIdxL0, 0, sizeof(m_RefPicSetIdxL0) ); |
---|
2292 | ::memset( m_RefPicSetIdxL1, 0, sizeof(m_RefPicSetIdxL1) ); |
---|
2293 | } |
---|
2294 | |
---|
2295 | TComRefPicListModification::~TComRefPicListModification() |
---|
2296 | { |
---|
2297 | } |
---|
2298 | |
---|
2299 | TComScalingList::TComScalingList() |
---|
2300 | { |
---|
2301 | m_useTransformSkip = false; |
---|
2302 | init(); |
---|
2303 | } |
---|
2304 | TComScalingList::~TComScalingList() |
---|
2305 | { |
---|
2306 | destroy(); |
---|
2307 | } |
---|
2308 | |
---|
2309 | /** set default quantization matrix to array |
---|
2310 | */ |
---|
2311 | Void TComSlice::setDefaultScalingList() |
---|
2312 | { |
---|
2313 | for(UInt sizeId = 0; sizeId < SCALING_LIST_SIZE_NUM; sizeId++) |
---|
2314 | { |
---|
2315 | for(UInt listId=0;listId<g_scalingListNum[sizeId];listId++) |
---|
2316 | { |
---|
2317 | getScalingList()->processDefaultMarix(sizeId, listId); |
---|
2318 | } |
---|
2319 | } |
---|
2320 | } |
---|
2321 | /** check if use default quantization matrix |
---|
2322 | * \returns true if use default quantization matrix in all size |
---|
2323 | */ |
---|
2324 | Bool TComSlice::checkDefaultScalingList() |
---|
2325 | { |
---|
2326 | UInt defaultCounter=0; |
---|
2327 | |
---|
2328 | for(UInt sizeId = 0; sizeId < SCALING_LIST_SIZE_NUM; sizeId++) |
---|
2329 | { |
---|
2330 | for(UInt listId=0;listId<g_scalingListNum[sizeId];listId++) |
---|
2331 | { |
---|
2332 | 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 |
---|
2333 | && ((sizeId < SCALING_LIST_16x16) || (getScalingList()->getScalingListDC(sizeId,listId) == 16))) // check DC value |
---|
2334 | { |
---|
2335 | defaultCounter++; |
---|
2336 | } |
---|
2337 | } |
---|
2338 | } |
---|
2339 | return (defaultCounter == (SCALING_LIST_NUM * SCALING_LIST_SIZE_NUM - 4)) ? false : true; // -4 for 32x32 |
---|
2340 | } |
---|
2341 | |
---|
2342 | #if H_MV |
---|
2343 | Void TComSlice::createAndApplyIvReferencePictureSet( TComPicLists* ivPicLists, std::vector<TComPic*>& refPicSetInterLayer ) |
---|
2344 | { |
---|
2345 | refPicSetInterLayer.clear(); |
---|
2346 | |
---|
2347 | for( Int i = 0; i < getNumActiveRefLayerPics(); i++ ) |
---|
2348 | { |
---|
2349 | Int layerIdRef = getRefPicLayerId( i ); |
---|
2350 | TComPic* picRef = ivPicLists->getPic( layerIdRef, getPOC() ) ; |
---|
2351 | assert ( picRef != 0 ); |
---|
2352 | |
---|
2353 | picRef->getPicYuvRec()->extendPicBorder(); |
---|
2354 | picRef->setIsLongTerm( true ); |
---|
2355 | picRef->getSlice(0)->setReferenced( true ); |
---|
2356 | |
---|
2357 | // Consider to check here: |
---|
2358 | // "If the current picture is a RADL picture, there shall be no entry in the RefPicSetInterLayer that is a RASL picture. " |
---|
2359 | refPicSetInterLayer.push_back( picRef ); |
---|
2360 | } |
---|
2361 | } |
---|
2362 | |
---|
2363 | Void TComSlice::markIvRefPicsAsShortTerm( std::vector<TComPic*> refPicSetInterLayer ) |
---|
2364 | { |
---|
2365 | // Mark as shortterm |
---|
2366 | for ( Int i = 0; i < refPicSetInterLayer.size(); i++ ) |
---|
2367 | { |
---|
2368 | refPicSetInterLayer[i]->setIsLongTerm( false ); |
---|
2369 | } |
---|
2370 | } |
---|
2371 | |
---|
2372 | Void TComSlice::markIvRefPicsAsUnused( TComPicLists* ivPicLists, std::vector<Int> targetDecLayerIdSet, TComVPS* vps, Int curLayerId, Int curPoc ) |
---|
2373 | { |
---|
2374 | // Fill targetDecLayerIdSet with all layers if empty. |
---|
2375 | if (targetDecLayerIdSet.size() == 0 ) |
---|
2376 | { |
---|
2377 | for ( Int layerIdInVps = 0; layerIdInVps < vps->getMaxLayers(); layerIdInVps++ ) |
---|
2378 | { |
---|
2379 | targetDecLayerIdSet.push_back( vps->getLayerIdInNuh( layerIdInVps ) ); |
---|
2380 | } |
---|
2381 | } |
---|
2382 | |
---|
2383 | Int numTargetDecLayers = (Int) targetDecLayerIdSet.size(); |
---|
2384 | Int latestDecIdx; |
---|
2385 | for ( latestDecIdx = 0; latestDecIdx < numTargetDecLayers; latestDecIdx++) |
---|
2386 | { |
---|
2387 | if ( targetDecLayerIdSet[ latestDecIdx ] == curLayerId ) |
---|
2388 | break; |
---|
2389 | } |
---|
2390 | |
---|
2391 | for( Int i = 0; i <= latestDecIdx; i++ ) |
---|
2392 | { |
---|
2393 | if ( vps->nuhLayerIdIncluded( targetDecLayerIdSet[ i ] ) ) |
---|
2394 | { |
---|
2395 | TComPic* pcPic = ivPicLists->getPic( targetDecLayerIdSet[ i ], curPoc ); |
---|
2396 | if( pcPic->getSlice(0)->isReferenced() && pcPic->getSlice(0)->getTemporalLayerNonReferenceFlag() ) |
---|
2397 | { |
---|
2398 | Bool remainingInterLayerReferencesFlag = false; |
---|
2399 | for( Int j = latestDecIdx + 1; j < numTargetDecLayers; j++ ) |
---|
2400 | { |
---|
2401 | TComVPS* vpsSlice = pcPic->getSlice(0)->getVPS(); |
---|
2402 | if ( vps->nuhLayerIdIncluded( targetDecLayerIdSet[ j ] ) ) |
---|
2403 | { |
---|
2404 | Int targetDecLayerIdinVPS = vpsSlice->getLayerIdInVps( targetDecLayerIdSet[ j ] ); |
---|
2405 | for( Int k = 0; k < vpsSlice->getNumDirectRefLayers( targetDecLayerIdinVPS ); k++ ) |
---|
2406 | if ( targetDecLayerIdSet[ i ] == vpsSlice->getRefLayerId( targetDecLayerIdinVPS, k ) ) |
---|
2407 | remainingInterLayerReferencesFlag = true; |
---|
2408 | } |
---|
2409 | } |
---|
2410 | if( !remainingInterLayerReferencesFlag ) |
---|
2411 | pcPic->getSlice(0)->setReferenced( false ); |
---|
2412 | } |
---|
2413 | } |
---|
2414 | } |
---|
2415 | } |
---|
2416 | |
---|
2417 | Void TComSlice::xPrintRefPicList() |
---|
2418 | { |
---|
2419 | for ( Int li = 0; li < 2; li++) |
---|
2420 | { |
---|
2421 | std::cout << std::endl << "RefPicListL" << li << ":" << std::endl; |
---|
2422 | for (Int rIdx = 0; rIdx <= (m_aiNumRefIdx[li]-1); rIdx ++) |
---|
2423 | { |
---|
2424 | if (rIdx == 0 && li == 0) m_apcRefPicList[li][rIdx]->print( true ); |
---|
2425 | |
---|
2426 | m_apcRefPicList[li][rIdx]->print( false ); |
---|
2427 | } |
---|
2428 | } |
---|
2429 | } |
---|
2430 | Int TComSlice::xCeilLog2( Int val ) |
---|
2431 | { |
---|
2432 | assert( val > 0 ); |
---|
2433 | Int ceilLog2 = 0; |
---|
2434 | while( val > ( 1 << ceilLog2 ) ) ceilLog2++; |
---|
2435 | return ceilLog2; |
---|
2436 | } |
---|
2437 | |
---|
2438 | Void TComSlice::markCurrPic( TComPic* currPic ) |
---|
2439 | { |
---|
2440 | if ( !currPic->getSlice(0)->getDiscardableFlag() ) |
---|
2441 | { |
---|
2442 | currPic->getSlice(0)->setReferenced( true ) ; |
---|
2443 | currPic->setIsLongTerm( false ); |
---|
2444 | } |
---|
2445 | else |
---|
2446 | { |
---|
2447 | currPic->getSlice(0)->setReferenced( false ) ; |
---|
2448 | } |
---|
2449 | } |
---|
2450 | |
---|
2451 | Void TComSlice::setRefPicSetInterLayer( std::vector<TComPic*>* refPicSetInterLayer ) |
---|
2452 | { |
---|
2453 | m_refPicSetInterLayer = refPicSetInterLayer; |
---|
2454 | } |
---|
2455 | |
---|
2456 | TComPic* TComSlice::getPicFromRefPicSetInterLayer( Int layerId ) |
---|
2457 | { |
---|
2458 | assert( m_refPicSetInterLayer != 0 ); |
---|
2459 | assert( (*m_refPicSetInterLayer).size() == getNumActiveRefLayerPics() ); |
---|
2460 | TComPic* pcPic = NULL; |
---|
2461 | for ( Int i = 0; i < getNumActiveRefLayerPics(); i++ ) |
---|
2462 | { |
---|
2463 | if ((*m_refPicSetInterLayer)[ i ]->getLayerId() == layerId) |
---|
2464 | { |
---|
2465 | pcPic = (*m_refPicSetInterLayer)[ i ]; |
---|
2466 | } |
---|
2467 | } |
---|
2468 | assert(pcPic != NULL); |
---|
2469 | return pcPic; |
---|
2470 | } |
---|
2471 | |
---|
2472 | Int TComSlice::getNumActiveRefLayerPics() |
---|
2473 | { |
---|
2474 | Int numActiveRefLayerPics; |
---|
2475 | |
---|
2476 | if( getLayerId() == 0 || getVPS()->getNumDirectRefLayers( getLayerIdInVps() ) == 0 || !getInterLayerPredEnabledFlag() ) |
---|
2477 | { |
---|
2478 | numActiveRefLayerPics = 0; |
---|
2479 | } |
---|
2480 | else if( getVPS()->getMaxOneActiveRefLayerFlag() || getVPS()->getNumDirectRefLayers( getLayerIdInVps() ) == 1 ) |
---|
2481 | { |
---|
2482 | numActiveRefLayerPics = 1; |
---|
2483 | } |
---|
2484 | else |
---|
2485 | { |
---|
2486 | numActiveRefLayerPics = getNumInterLayerRefPicsMinus1() + 1; |
---|
2487 | } |
---|
2488 | return numActiveRefLayerPics; |
---|
2489 | } |
---|
2490 | |
---|
2491 | Int TComSlice::getRefPicLayerId( Int i ) |
---|
2492 | { |
---|
2493 | return getVPS()->getRefLayerId( getLayerIdInVps(), getInterLayerPredLayerIdc( i ) ); |
---|
2494 | } |
---|
2495 | |
---|
2496 | Void TComSlice::setActiveMotionPredRefLayers() |
---|
2497 | { |
---|
2498 | Int j = 0; |
---|
2499 | for( Int i = 0; i < getNumActiveRefLayerPics(); i++) |
---|
2500 | { |
---|
2501 | if( getVPS()->getMotionPredEnabledFlag( getLayerIdInVps(), getInterLayerPredLayerIdc( i )) ) |
---|
2502 | { |
---|
2503 | m_activeMotionPredRefLayerId[ j++ ] = getVPS()->getRefLayerId( getLayerIdInVps(), i ); |
---|
2504 | } |
---|
2505 | } |
---|
2506 | m_numActiveMotionPredRefLayers = j; |
---|
2507 | |
---|
2508 | // Consider incorporating bitstream conformance tests on derived variables here. |
---|
2509 | } |
---|
2510 | |
---|
2511 | Bool TComSlice::getInterRefEnabledInRPLFlag() |
---|
2512 | { |
---|
2513 | Bool interRefEnabledInRPLFlag; |
---|
2514 | if ( getVPS()->getNumSamplePredRefLayers( getLayerIdInVps() ) > 0 && getNumActiveRefLayerPics() > 0 ) |
---|
2515 | { |
---|
2516 | interRefEnabledInRPLFlag = !getInterLayerSamplePredOnlyFlag(); |
---|
2517 | } |
---|
2518 | else |
---|
2519 | { |
---|
2520 | interRefEnabledInRPLFlag = 1; |
---|
2521 | } |
---|
2522 | return interRefEnabledInRPLFlag; |
---|
2523 | } |
---|
2524 | #if H_3D_ARP |
---|
2525 | Void TComSlice::setARPStepNum() |
---|
2526 | { |
---|
2527 | Bool bAllIvRef = true; |
---|
2528 | |
---|
2529 | if(!getVPS()->getUseAdvRP(getLayerId())) |
---|
2530 | { |
---|
2531 | m_nARPStepNum = 0; |
---|
2532 | } |
---|
2533 | else |
---|
2534 | { |
---|
2535 | for( Int iRefListId = 0; iRefListId < 2; iRefListId++ ) |
---|
2536 | { |
---|
2537 | RefPicList eRefPicList = RefPicList( iRefListId ); |
---|
2538 | Int iNumRefIdx = getNumRefIdx(eRefPicList); |
---|
2539 | |
---|
2540 | if( iNumRefIdx <= 0 ) |
---|
2541 | { |
---|
2542 | continue; |
---|
2543 | } |
---|
2544 | |
---|
2545 | for ( Int i = 0; i < iNumRefIdx; i++ ) |
---|
2546 | { |
---|
2547 | if( getRefPic( eRefPicList, i)->getPOC() != getPOC() ) |
---|
2548 | { |
---|
2549 | bAllIvRef = false; |
---|
2550 | break; |
---|
2551 | } |
---|
2552 | } |
---|
2553 | |
---|
2554 | if( bAllIvRef == false ) { break; } |
---|
2555 | } |
---|
2556 | m_nARPStepNum = !bAllIvRef ? getVPS()->getARPStepNum(getLayerId()) : 0; |
---|
2557 | } |
---|
2558 | } |
---|
2559 | #endif |
---|
2560 | #if H_3D_IC |
---|
2561 | Void TComSlice::xSetApplyIC() |
---|
2562 | { |
---|
2563 | Int iMaxPelValue = ( 1 << g_bitDepthY ); |
---|
2564 | Int *aiRefOrgHist; |
---|
2565 | Int *aiCurrHist; |
---|
2566 | aiRefOrgHist = (Int *) xMalloc( Int,iMaxPelValue ); |
---|
2567 | aiCurrHist = (Int *) xMalloc( Int,iMaxPelValue ); |
---|
2568 | memset( aiRefOrgHist, 0, iMaxPelValue*sizeof(Int) ); |
---|
2569 | memset( aiCurrHist, 0, iMaxPelValue*sizeof(Int) ); |
---|
2570 | // Reference Idx Number |
---|
2571 | Int iNumRefIdx = getNumRefIdx( REF_PIC_LIST_0 ); |
---|
2572 | TComPic* pcCurrPic = NULL; |
---|
2573 | TComPic* pcRefPic = NULL; |
---|
2574 | TComPicYuv* pcCurrPicYuv = NULL; |
---|
2575 | TComPicYuv* pcRefPicYuvOrg = NULL; |
---|
2576 | pcCurrPic = getPic(); |
---|
2577 | pcCurrPicYuv = pcCurrPic->getPicYuvOrg(); |
---|
2578 | Int iWidth = pcCurrPicYuv->getWidth(); |
---|
2579 | Int iHeight = pcCurrPicYuv->getHeight(); |
---|
2580 | |
---|
2581 | |
---|
2582 | // Get InterView Reference picture |
---|
2583 | // !!!!! Assume only one Interview Reference Picture in L0 |
---|
2584 | for ( Int i = 0; i < iNumRefIdx; i++ ) |
---|
2585 | { |
---|
2586 | pcRefPic = getRefPic( REF_PIC_LIST_0, i ); |
---|
2587 | if ( pcRefPic != NULL ) |
---|
2588 | { |
---|
2589 | if ( pcCurrPic->getViewIndex() != pcRefPic->getViewIndex() ) |
---|
2590 | { |
---|
2591 | pcRefPicYuvOrg = pcRefPic->getPicYuvOrg(); |
---|
2592 | } |
---|
2593 | } |
---|
2594 | } |
---|
2595 | |
---|
2596 | if ( pcRefPicYuvOrg != NULL ) |
---|
2597 | { |
---|
2598 | Pel* pCurrY = pcCurrPicYuv ->getLumaAddr(); |
---|
2599 | Pel* pRefOrgY = pcRefPicYuvOrg ->getLumaAddr(); |
---|
2600 | Int iCurrStride = pcCurrPicYuv->getStride(); |
---|
2601 | Int iRefStride = pcRefPicYuvOrg->getStride(); |
---|
2602 | Int iSumOrgSAD = 0; |
---|
2603 | Double dThresholdOrgSAD = getIsDepth() ? 0.1 : 0.05; |
---|
2604 | |
---|
2605 | // Histogram building - luminance |
---|
2606 | for ( Int y = 0; y < iHeight; y++ ) |
---|
2607 | { |
---|
2608 | for ( Int x = 0; x < iWidth; x++ ) |
---|
2609 | { |
---|
2610 | aiCurrHist[pCurrY[x]]++; |
---|
2611 | aiRefOrgHist[pRefOrgY[x]]++; |
---|
2612 | } |
---|
2613 | pCurrY += iCurrStride; |
---|
2614 | pRefOrgY += iRefStride; |
---|
2615 | } |
---|
2616 | // Histogram SAD |
---|
2617 | for ( Int i = 0; i < iMaxPelValue; i++ ) |
---|
2618 | { |
---|
2619 | iSumOrgSAD += abs( aiCurrHist[i] - aiRefOrgHist[i] ); |
---|
2620 | } |
---|
2621 | // Setting |
---|
2622 | if ( iSumOrgSAD > Int( dThresholdOrgSAD * iWidth * iHeight ) ) |
---|
2623 | { |
---|
2624 | m_bApplyIC = true; |
---|
2625 | } |
---|
2626 | else |
---|
2627 | { |
---|
2628 | m_bApplyIC = false; |
---|
2629 | } |
---|
2630 | } |
---|
2631 | |
---|
2632 | xFree( aiCurrHist ); |
---|
2633 | xFree( aiRefOrgHist ); |
---|
2634 | aiCurrHist = NULL; |
---|
2635 | aiRefOrgHist = NULL; |
---|
2636 | } |
---|
2637 | #endif |
---|
2638 | #if H_3D |
---|
2639 | Void TComSlice::setIvPicLists( TComPicLists* m_ivPicLists ) |
---|
2640 | { |
---|
2641 | for (Int i = 0; i < MAX_NUM_LAYERS; i++ ) |
---|
2642 | { |
---|
2643 | for ( Int depthId = 0; depthId < 2; depthId++ ) |
---|
2644 | { |
---|
2645 | m_ivPicsCurrPoc[ depthId ][ i ] = ( i <= m_viewIndex ) ? m_ivPicLists->getPic( i, ( depthId == 1) , getPOC() ) : NULL; |
---|
2646 | } |
---|
2647 | } |
---|
2648 | } |
---|
2649 | Void TComSlice::setDepthToDisparityLUTs() |
---|
2650 | { |
---|
2651 | Bool setupLUT = false; |
---|
2652 | Int layerIdInVPS = getVPS()->getLayerIdInNuh( m_layerId ); |
---|
2653 | |
---|
2654 | #if H_3D_VSP |
---|
2655 | setupLUT = setupLUT || getVPS()->getViewSynthesisPredFlag( layerIdInVPS); |
---|
2656 | #endif |
---|
2657 | |
---|
2658 | #if H_3D_NBDV_REF |
---|
2659 | setupLUT = setupLUT || getVPS()->getDepthRefinementFlag( layerIdInVPS ); |
---|
2660 | #endif |
---|
2661 | |
---|
2662 | if( !setupLUT ) |
---|
2663 | return; |
---|
2664 | |
---|
2665 | /// GT: Allocation should be moved to a better place later; |
---|
2666 | if ( m_depthToDisparityB == NULL ) |
---|
2667 | { |
---|
2668 | m_depthToDisparityB = new Int*[ getViewIndex() ]; |
---|
2669 | for ( Int i = 0; i < getViewIndex(); i++ ) |
---|
2670 | { |
---|
2671 | m_depthToDisparityB[ i ] = new Int[ Int(1 << g_bitDepthY) ]; |
---|
2672 | } |
---|
2673 | } |
---|
2674 | |
---|
2675 | if ( m_depthToDisparityF == NULL ) |
---|
2676 | { |
---|
2677 | m_depthToDisparityF= new Int*[ getViewIndex() ]; |
---|
2678 | for ( Int i = 0; i < getViewIndex(); i++ ) |
---|
2679 | { |
---|
2680 | m_depthToDisparityF[ i ] = new Int[ Int(1 << g_bitDepthY) ]; |
---|
2681 | } |
---|
2682 | } |
---|
2683 | |
---|
2684 | assert( m_depthToDisparityB != NULL ); |
---|
2685 | assert( m_depthToDisparityF != NULL ); |
---|
2686 | |
---|
2687 | TComSPS* sps = getSPS(); |
---|
2688 | |
---|
2689 | Int log2Div = g_bitDepthY - 1 + sps->getCamParPrecision(); |
---|
2690 | |
---|
2691 | Bool camParaSH = m_pcSPS->hasCamParInSliceHeader(); |
---|
2692 | |
---|
2693 | Int* codScale = camParaSH ? m_aaiCodedScale [ 0 ] : sps->getCodedScale (); |
---|
2694 | Int* codOffset = camParaSH ? m_aaiCodedOffset[ 0 ] : sps->getCodedOffset (); |
---|
2695 | Int* invCodScale = camParaSH ? m_aaiCodedScale [ 1 ] : sps->getInvCodedScale (); |
---|
2696 | Int* invCodOffset = camParaSH ? m_aaiCodedOffset[ 1 ] : sps->getInvCodedOffset(); |
---|
2697 | |
---|
2698 | for (Int i = 0; i <= ( getViewIndex() - 1); i++) |
---|
2699 | { |
---|
2700 | for ( Int d = 0; d <= ( ( 1 << g_bitDepthY ) - 1 ); d++ ) |
---|
2701 | { |
---|
2702 | Int offset = ( codOffset [ i ] << g_bitDepthY ) + ( ( 1 << log2Div ) >> 1 ); |
---|
2703 | m_depthToDisparityB[ i ][ d ] = ( codScale [ i ] * d + offset ) >> log2Div; |
---|
2704 | |
---|
2705 | Int invOffset = ( invCodOffset[ i ] << g_bitDepthY ) + ( ( 1 << log2Div ) >> 1 ); |
---|
2706 | m_depthToDisparityF[ i ][ d ] = ( invCodScale[ i ] * d + invOffset ) >> log2Div; |
---|
2707 | } |
---|
2708 | } |
---|
2709 | } |
---|
2710 | #endif |
---|
2711 | #endif |
---|
2712 | /** get scaling matrix from RefMatrixID |
---|
2713 | * \param sizeId size index |
---|
2714 | * \param Index of input matrix |
---|
2715 | * \param Index of reference matrix |
---|
2716 | */ |
---|
2717 | Void TComScalingList::processRefMatrix( UInt sizeId, UInt listId , UInt refListId ) |
---|
2718 | { |
---|
2719 | ::memcpy(getScalingListAddress(sizeId, listId),((listId == refListId)? getScalingListDefaultAddress(sizeId, refListId): getScalingListAddress(sizeId, refListId)),sizeof(Int)*min(MAX_MATRIX_COEF_NUM,(Int)g_scalingListSize[sizeId])); |
---|
2720 | } |
---|
2721 | |
---|
2722 | /** parse syntax infomation |
---|
2723 | * \param pchFile syntax infomation |
---|
2724 | * \returns false if successful |
---|
2725 | */ |
---|
2726 | Bool TComScalingList::xParseScalingList(Char* pchFile) |
---|
2727 | { |
---|
2728 | FILE *fp; |
---|
2729 | Char line[1024]; |
---|
2730 | UInt sizeIdc,listIdc; |
---|
2731 | UInt i,size = 0; |
---|
2732 | Int *src=0,data; |
---|
2733 | Char *ret; |
---|
2734 | UInt retval; |
---|
2735 | |
---|
2736 | if((fp = fopen(pchFile,"r")) == (FILE*)NULL) |
---|
2737 | { |
---|
2738 | printf("can't open file %s :: set Default Matrix\n",pchFile); |
---|
2739 | return true; |
---|
2740 | } |
---|
2741 | |
---|
2742 | for(sizeIdc = 0; sizeIdc < SCALING_LIST_SIZE_NUM; sizeIdc++) |
---|
2743 | { |
---|
2744 | size = min(MAX_MATRIX_COEF_NUM,(Int)g_scalingListSize[sizeIdc]); |
---|
2745 | for(listIdc = 0; listIdc < g_scalingListNum[sizeIdc]; listIdc++) |
---|
2746 | { |
---|
2747 | src = getScalingListAddress(sizeIdc, listIdc); |
---|
2748 | |
---|
2749 | fseek(fp,0,0); |
---|
2750 | do |
---|
2751 | { |
---|
2752 | ret = fgets(line, 1024, fp); |
---|
2753 | if ((ret==NULL)||(strstr(line, MatrixType[sizeIdc][listIdc])==NULL && feof(fp))) |
---|
2754 | { |
---|
2755 | printf("Error: can't read Matrix :: set Default Matrix\n"); |
---|
2756 | return true; |
---|
2757 | } |
---|
2758 | } |
---|
2759 | while (strstr(line, MatrixType[sizeIdc][listIdc]) == NULL); |
---|
2760 | for (i=0; i<size; i++) |
---|
2761 | { |
---|
2762 | retval = fscanf(fp, "%d,", &data); |
---|
2763 | if (retval!=1) |
---|
2764 | { |
---|
2765 | printf("Error: can't read Matrix :: set Default Matrix\n"); |
---|
2766 | return true; |
---|
2767 | } |
---|
2768 | src[i] = data; |
---|
2769 | } |
---|
2770 | //set DC value for default matrix check |
---|
2771 | setScalingListDC(sizeIdc,listIdc,src[0]); |
---|
2772 | |
---|
2773 | if(sizeIdc > SCALING_LIST_8x8) |
---|
2774 | { |
---|
2775 | fseek(fp,0,0); |
---|
2776 | do |
---|
2777 | { |
---|
2778 | ret = fgets(line, 1024, fp); |
---|
2779 | if ((ret==NULL)||(strstr(line, MatrixType_DC[sizeIdc][listIdc])==NULL && feof(fp))) |
---|
2780 | { |
---|
2781 | printf("Error: can't read DC :: set Default Matrix\n"); |
---|
2782 | return true; |
---|
2783 | } |
---|
2784 | } |
---|
2785 | while (strstr(line, MatrixType_DC[sizeIdc][listIdc]) == NULL); |
---|
2786 | retval = fscanf(fp, "%d,", &data); |
---|
2787 | if (retval!=1) |
---|
2788 | { |
---|
2789 | printf("Error: can't read Matrix :: set Default Matrix\n"); |
---|
2790 | return true; |
---|
2791 | } |
---|
2792 | //overwrite DC value when size of matrix is larger than 16x16 |
---|
2793 | setScalingListDC(sizeIdc,listIdc,data); |
---|
2794 | } |
---|
2795 | } |
---|
2796 | } |
---|
2797 | fclose(fp); |
---|
2798 | return false; |
---|
2799 | } |
---|
2800 | |
---|
2801 | /** initialization process of quantization matrix array |
---|
2802 | */ |
---|
2803 | Void TComScalingList::init() |
---|
2804 | { |
---|
2805 | for(UInt sizeId = 0; sizeId < SCALING_LIST_SIZE_NUM; sizeId++) |
---|
2806 | { |
---|
2807 | for(UInt listId = 0; listId < g_scalingListNum[sizeId]; listId++) |
---|
2808 | { |
---|
2809 | m_scalingListCoef[sizeId][listId] = new Int [min(MAX_MATRIX_COEF_NUM,(Int)g_scalingListSize[sizeId])]; |
---|
2810 | } |
---|
2811 | } |
---|
2812 | m_scalingListCoef[SCALING_LIST_32x32][3] = m_scalingListCoef[SCALING_LIST_32x32][1]; // copy address for 32x32 |
---|
2813 | } |
---|
2814 | |
---|
2815 | /** destroy quantization matrix array |
---|
2816 | */ |
---|
2817 | Void TComScalingList::destroy() |
---|
2818 | { |
---|
2819 | for(UInt sizeId = 0; sizeId < SCALING_LIST_SIZE_NUM; sizeId++) |
---|
2820 | { |
---|
2821 | for(UInt listId = 0; listId < g_scalingListNum[sizeId]; listId++) |
---|
2822 | { |
---|
2823 | if(m_scalingListCoef[sizeId][listId]) delete [] m_scalingListCoef[sizeId][listId]; |
---|
2824 | } |
---|
2825 | } |
---|
2826 | } |
---|
2827 | |
---|
2828 | /** get default address of quantization matrix |
---|
2829 | * \param sizeId size index |
---|
2830 | * \param listId list index |
---|
2831 | * \returns pointer of quantization matrix |
---|
2832 | */ |
---|
2833 | Int* TComScalingList::getScalingListDefaultAddress(UInt sizeId, UInt listId) |
---|
2834 | { |
---|
2835 | Int *src = 0; |
---|
2836 | switch(sizeId) |
---|
2837 | { |
---|
2838 | case SCALING_LIST_4x4: |
---|
2839 | src = g_quantTSDefault4x4; |
---|
2840 | break; |
---|
2841 | case SCALING_LIST_8x8: |
---|
2842 | src = (listId<3) ? g_quantIntraDefault8x8 : g_quantInterDefault8x8; |
---|
2843 | break; |
---|
2844 | case SCALING_LIST_16x16: |
---|
2845 | src = (listId<3) ? g_quantIntraDefault8x8 : g_quantInterDefault8x8; |
---|
2846 | break; |
---|
2847 | case SCALING_LIST_32x32: |
---|
2848 | src = (listId<1) ? g_quantIntraDefault8x8 : g_quantInterDefault8x8; |
---|
2849 | break; |
---|
2850 | default: |
---|
2851 | assert(0); |
---|
2852 | src = NULL; |
---|
2853 | break; |
---|
2854 | } |
---|
2855 | return src; |
---|
2856 | } |
---|
2857 | |
---|
2858 | /** process of default matrix |
---|
2859 | * \param sizeId size index |
---|
2860 | * \param Index of input matrix |
---|
2861 | */ |
---|
2862 | Void TComScalingList::processDefaultMarix(UInt sizeId, UInt listId) |
---|
2863 | { |
---|
2864 | ::memcpy(getScalingListAddress(sizeId, listId),getScalingListDefaultAddress(sizeId,listId),sizeof(Int)*min(MAX_MATRIX_COEF_NUM,(Int)g_scalingListSize[sizeId])); |
---|
2865 | setScalingListDC(sizeId,listId,SCALING_LIST_DC); |
---|
2866 | } |
---|
2867 | |
---|
2868 | /** check DC value of matrix for default matrix signaling |
---|
2869 | */ |
---|
2870 | Void TComScalingList::checkDcOfMatrix() |
---|
2871 | { |
---|
2872 | for(UInt sizeId = 0; sizeId < SCALING_LIST_SIZE_NUM; sizeId++) |
---|
2873 | { |
---|
2874 | for(UInt listId = 0; listId < g_scalingListNum[sizeId]; listId++) |
---|
2875 | { |
---|
2876 | //check default matrix? |
---|
2877 | if(getScalingListDC(sizeId,listId) == 0) |
---|
2878 | { |
---|
2879 | processDefaultMarix(sizeId, listId); |
---|
2880 | } |
---|
2881 | } |
---|
2882 | } |
---|
2883 | } |
---|
2884 | |
---|
2885 | ParameterSetManager::ParameterSetManager() |
---|
2886 | : m_vpsMap(MAX_NUM_VPS) |
---|
2887 | , m_spsMap(MAX_NUM_SPS) |
---|
2888 | , m_ppsMap(MAX_NUM_PPS) |
---|
2889 | , m_activeVPSId(-1) |
---|
2890 | , m_activeSPSId(-1) |
---|
2891 | , m_activePPSId(-1) |
---|
2892 | { |
---|
2893 | } |
---|
2894 | |
---|
2895 | |
---|
2896 | ParameterSetManager::~ParameterSetManager() |
---|
2897 | { |
---|
2898 | } |
---|
2899 | |
---|
2900 | //! activate a SPS from a active parameter sets SEI message |
---|
2901 | //! \returns true, if activation is successful |
---|
2902 | Bool ParameterSetManager::activateSPSWithSEI(Int spsId) |
---|
2903 | { |
---|
2904 | TComSPS *sps = m_spsMap.getPS(spsId); |
---|
2905 | if (sps) |
---|
2906 | { |
---|
2907 | Int vpsId = sps->getVPSId(); |
---|
2908 | if (m_vpsMap.getPS(vpsId)) |
---|
2909 | { |
---|
2910 | m_activeVPSId = vpsId; |
---|
2911 | m_activeSPSId = spsId; |
---|
2912 | return true; |
---|
2913 | } |
---|
2914 | else |
---|
2915 | { |
---|
2916 | printf("Warning: tried to activate SPS using an Active parameter sets SEI message. Referenced VPS does not exist."); |
---|
2917 | } |
---|
2918 | } |
---|
2919 | else |
---|
2920 | { |
---|
2921 | printf("Warning: tried to activate non-existing SPS using an Active parameter sets SEI message."); |
---|
2922 | } |
---|
2923 | return false; |
---|
2924 | } |
---|
2925 | |
---|
2926 | //! activate a PPS and depending on isIDR parameter also SPS and VPS |
---|
2927 | //! \returns true, if activation is successful |
---|
2928 | Bool ParameterSetManager::activatePPS(Int ppsId, Bool isIRAP) |
---|
2929 | { |
---|
2930 | TComPPS *pps = m_ppsMap.getPS(ppsId); |
---|
2931 | if (pps) |
---|
2932 | { |
---|
2933 | Int spsId = pps->getSPSId(); |
---|
2934 | #if H_MV |
---|
2935 | // active parameter sets per layer should be used here |
---|
2936 | #else |
---|
2937 | if (!isIRAP && (spsId != m_activeSPSId)) |
---|
2938 | { |
---|
2939 | printf("Warning: tried to activate PPS referring to a inactive SPS at non-IRAP."); |
---|
2940 | return false; |
---|
2941 | } |
---|
2942 | #endif |
---|
2943 | TComSPS *sps = m_spsMap.getPS(spsId); |
---|
2944 | if (sps) |
---|
2945 | { |
---|
2946 | Int vpsId = sps->getVPSId(); |
---|
2947 | if (!isIRAP && (vpsId != m_activeVPSId)) |
---|
2948 | { |
---|
2949 | printf("Warning: tried to activate PPS referring to a inactive VPS at non-IRAP."); |
---|
2950 | return false; |
---|
2951 | } |
---|
2952 | if (m_vpsMap.getPS(vpsId)) |
---|
2953 | { |
---|
2954 | m_activePPSId = ppsId; |
---|
2955 | m_activeVPSId = vpsId; |
---|
2956 | m_activeSPSId = spsId; |
---|
2957 | return true; |
---|
2958 | } |
---|
2959 | else |
---|
2960 | { |
---|
2961 | printf("Warning: tried to activate PPS that refers to a non-existing VPS."); |
---|
2962 | } |
---|
2963 | } |
---|
2964 | else |
---|
2965 | { |
---|
2966 | printf("Warning: tried to activate a PPS that refers to a non-existing SPS."); |
---|
2967 | } |
---|
2968 | } |
---|
2969 | else |
---|
2970 | { |
---|
2971 | printf("Warning: tried to activate non-existing PPS."); |
---|
2972 | } |
---|
2973 | return false; |
---|
2974 | } |
---|
2975 | |
---|
2976 | ProfileTierLevel::ProfileTierLevel() |
---|
2977 | : m_profileSpace (0) |
---|
2978 | , m_tierFlag (false) |
---|
2979 | , m_profileIdc (0) |
---|
2980 | , m_levelIdc (0) |
---|
2981 | , m_progressiveSourceFlag (false) |
---|
2982 | , m_interlacedSourceFlag (false) |
---|
2983 | , m_nonPackedConstraintFlag(false) |
---|
2984 | , m_frameOnlyConstraintFlag(false) |
---|
2985 | { |
---|
2986 | ::memset(m_profileCompatibilityFlag, 0, sizeof(m_profileCompatibilityFlag)); |
---|
2987 | } |
---|
2988 | |
---|
2989 | TComPTL::TComPTL() |
---|
2990 | { |
---|
2991 | ::memset(m_subLayerProfilePresentFlag, 0, sizeof(m_subLayerProfilePresentFlag)); |
---|
2992 | ::memset(m_subLayerLevelPresentFlag, 0, sizeof(m_subLayerLevelPresentFlag )); |
---|
2993 | } |
---|
2994 | |
---|
2995 | #if H_MV |
---|
2996 | Void TComPTL::copyLevelFrom( TComPTL* source ) |
---|
2997 | { |
---|
2998 | getGeneralPTL()->setLevelIdc( source->getGeneralPTL()->getLevelIdc() ); |
---|
2999 | for( Int subLayer = 0; subLayer < 6; subLayer++ ) |
---|
3000 | { |
---|
3001 | setSubLayerLevelPresentFlag( subLayer, source->getSubLayerLevelPresentFlag( subLayer ) ); |
---|
3002 | getSubLayerPTL( subLayer )->setLevelIdc( source->getSubLayerPTL( subLayer )->getLevelIdc() ); |
---|
3003 | } |
---|
3004 | } |
---|
3005 | #endif |
---|
3006 | #if SIGNAL_BITRATE_PICRATE_IN_VPS |
---|
3007 | TComBitRatePicRateInfo::TComBitRatePicRateInfo() |
---|
3008 | { |
---|
3009 | ::memset(m_bitRateInfoPresentFlag, 0, sizeof(m_bitRateInfoPresentFlag)); |
---|
3010 | ::memset(m_picRateInfoPresentFlag, 0, sizeof(m_picRateInfoPresentFlag)); |
---|
3011 | ::memset(m_avgBitRate, 0, sizeof(m_avgBitRate)); |
---|
3012 | ::memset(m_maxBitRate, 0, sizeof(m_maxBitRate)); |
---|
3013 | ::memset(m_constantPicRateIdc, 0, sizeof(m_constantPicRateIdc)); |
---|
3014 | ::memset(m_avgPicRate, 0, sizeof(m_avgPicRate)); |
---|
3015 | } |
---|
3016 | #endif |
---|
3017 | //! \} |
---|