Coverage Report

Created: 2026-12-01 06:52

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/work/vvdec/source/Lib/CommonLib/Slice.cpp
Line
Count
Source
1
/* -----------------------------------------------------------------------------
2
The copyright in this software is being made available under the Clear BSD
3
License, included below. No patent rights, trademark rights and/or 
4
other Intellectual Property Rights other than the copyrights concerning 
5
the Software are granted under this license.
6
7
The Clear BSD License
8
9
Copyright (c) 2018-2026, Fraunhofer-Gesellschaft zur Förderung der angewandten Forschung e.V. & The VVdeC Authors.
10
All rights reserved.
11
12
Redistribution and use in source and binary forms, with or without modification,
13
are permitted (subject to the limitations in the disclaimer below) provided that
14
the following conditions are met:
15
16
     * Redistributions of source code must retain the above copyright notice,
17
     this list of conditions and the following disclaimer.
18
19
     * Redistributions in binary form must reproduce the above copyright
20
     notice, this list of conditions and the following disclaimer in the
21
     documentation and/or other materials provided with the distribution.
22
23
     * Neither the name of the copyright holder nor the names of its
24
     contributors may be used to endorse or promote products derived from this
25
     software without specific prior written permission.
26
27
NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED BY
28
THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
29
CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
30
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
31
PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
32
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
33
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
34
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
35
BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
36
IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
37
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
38
POSSIBILITY OF SUCH DAMAGE.
39
40
41
------------------------------------------------------------------------------------------- */
42
43
/** \file     Slice.cpp
44
    \brief    slice header and SPS class
45
*/
46
47
#include "CommonDef.h"
48
#include "Unit.h"
49
#include "Slice.h"
50
#include "Picture.h"
51
#include "dtrace_next.h"
52
53
#include "UnitTools.h"
54
#include "vvdec/sei.h"
55
56
namespace vvdec
57
{
58
59
void VPS::deriveOutputLayerSets()
60
0
{
61
0
  if( m_uiMaxLayers == 1 )
62
0
  {
63
0
    m_totalNumOLSs = 1;
64
0
  }
65
0
  else if( m_vpsEachLayerIsAnOlsFlag || m_vpsOlsModeIdc < 2 )
66
0
  {
67
0
    m_totalNumOLSs = m_uiMaxLayers;
68
0
  }
69
0
  else if( m_vpsOlsModeIdc == 2 )
70
0
  {
71
0
    m_totalNumOLSs = m_vpsNumOutputLayerSets;
72
0
  }
73
74
0
  m_olsDpbParamsIdx.resize( m_totalNumOLSs );
75
0
  m_olsDpbPicSize.resize( m_totalNumOLSs, Size(0, 0) );
76
0
  m_numOutputLayersInOls.resize( m_totalNumOLSs );
77
0
  m_numLayersInOls.resize( m_totalNumOLSs );
78
0
  m_outputLayerIdInOls.resize( m_totalNumOLSs, std::vector<int>( m_uiMaxLayers, NOT_VALID ) );
79
0
  m_layerIdInOls.resize( m_totalNumOLSs, std::vector<int>( m_uiMaxLayers, NOT_VALID ) );
80
81
0
  std::vector<int> numRefLayers( m_uiMaxLayers );
82
0
  std::vector<std::vector<int>> outputLayerIdx( m_totalNumOLSs, std::vector<int>( m_uiMaxLayers, NOT_VALID ) );
83
0
  std::vector<std::vector<int>> layerIncludedInOlsFlag( m_totalNumOLSs, std::vector<int>( m_uiMaxLayers, 0 ) );
84
0
  std::vector<std::vector<int>> dependencyFlag( m_uiMaxLayers, std::vector<int>( m_uiMaxLayers, NOT_VALID ) );
85
0
  std::vector<std::vector<int>> refLayerIdx( m_uiMaxLayers, std::vector<int>( m_uiMaxLayers, NOT_VALID ) );
86
0
  std::vector<int> layerUsedAsRefLayerFlag( m_uiMaxLayers, 0 );
87
0
  std::vector<int> layerUsedAsOutputLayerFlag( m_uiMaxLayers, NOT_VALID );
88
0
  for( int i = 0; i < m_uiMaxLayers; i++ )
89
0
  {
90
0
    int r = 0;
91
92
0
    for( int j = 0; j < m_uiMaxLayers; j++ )
93
0
    {
94
0
      dependencyFlag[i][j] = m_vpsDirectRefLayerFlag[i][j];
95
96
0
      for( int k = 0; k < i; k++ )
97
0
      {
98
0
        if( m_vpsDirectRefLayerFlag[i][k] && dependencyFlag[k][j] )
99
0
        {
100
0
          dependencyFlag[i][j] = 1;
101
0
        }
102
0
      }
103
0
      if (m_vpsDirectRefLayerFlag[i][j])
104
0
      {
105
0
        layerUsedAsRefLayerFlag[j] = 1;
106
0
      }
107
0
      if( dependencyFlag[i][j] )
108
0
      {
109
0
        refLayerIdx[i][r++] = j;
110
0
      }
111
0
    }
112
113
0
    numRefLayers[i] = r;
114
0
  }
115
116
0
  m_numOutputLayersInOls[0] = 1;
117
0
  m_outputLayerIdInOls[0][0] = m_vpsLayerId[0];
118
0
  layerUsedAsOutputLayerFlag[0] = 1;
119
0
  for (int i = 1; i < m_uiMaxLayers; i++)
120
0
  {
121
0
    if (m_vpsEachLayerIsAnOlsFlag || m_vpsOlsModeIdc < 2)
122
0
    {
123
0
      layerUsedAsOutputLayerFlag[i] = 1;
124
0
    }
125
0
    else
126
0
    {
127
0
      layerUsedAsOutputLayerFlag[i] = 0;
128
0
    }
129
0
  }
130
0
  for( int i = 1; i < m_totalNumOLSs; i++ )
131
0
  {
132
0
    if( m_vpsEachLayerIsAnOlsFlag || m_vpsOlsModeIdc == 0 )
133
0
    {
134
0
      m_numOutputLayersInOls[i] = 1;
135
0
      m_outputLayerIdInOls[i][0] = m_vpsLayerId[i];
136
0
    }
137
0
    else if( m_vpsOlsModeIdc == 1 )
138
0
    {
139
0
      m_numOutputLayersInOls[i] = i + 1;
140
141
0
      for( int j = 0; j < m_numOutputLayersInOls[i]; j++ )
142
0
      {
143
0
        m_outputLayerIdInOls[i][j] = m_vpsLayerId[j];
144
0
      }
145
0
    }
146
0
    else if( m_vpsOlsModeIdc == 2 )
147
0
    {
148
0
      int j = 0;
149
0
      for( int k = 0; k < m_uiMaxLayers; k++ )
150
0
      {
151
0
        if( m_vpsOlsOutputLayerFlag[i][k] )
152
0
        {
153
0
          layerIncludedInOlsFlag[i][k] = 1;
154
0
          layerUsedAsOutputLayerFlag[k] = 1;
155
0
          outputLayerIdx[i][j] = k;
156
0
          m_outputLayerIdInOls[i][j++] = m_vpsLayerId[k];
157
0
        }
158
0
      }
159
0
      m_numOutputLayersInOls[i] = j;
160
161
0
      for( j = 0; j < m_numOutputLayersInOls[i]; j++ )
162
0
      {
163
0
        int idx = outputLayerIdx[i][j];
164
0
        for( int k = 0; k < numRefLayers[idx]; k++ )
165
0
        {
166
0
          layerIncludedInOlsFlag[i][refLayerIdx[idx][k]] = 1;
167
0
        }
168
0
      }
169
0
    }
170
0
  }
171
0
  for (int i = 0; i < m_uiMaxLayers; i++)
172
0
  {
173
0
    CHECK(layerUsedAsRefLayerFlag[i] == 0 && layerUsedAsOutputLayerFlag[i] == 0, "There shall be no layer that is neither an output layer nor a direct reference layer");
174
0
  }
175
176
0
  m_numLayersInOls[0]   = 1;
177
0
  m_layerIdInOls[0][0]  = m_vpsLayerId[0];
178
0
  m_numMultiLayeredOlss = 0;
179
180
0
  for( int i = 1; i < m_totalNumOLSs; i++ )
181
0
  {
182
0
    if( m_vpsEachLayerIsAnOlsFlag )
183
0
    {
184
0
      m_numLayersInOls[i] = 1;
185
0
      m_layerIdInOls[i][0] = m_vpsLayerId[i];
186
0
    }
187
0
    else if( m_vpsOlsModeIdc == 0 || m_vpsOlsModeIdc == 1 )
188
0
    {
189
0
      m_numLayersInOls[i] = i + 1;
190
0
      for( int j = 0; j < m_numLayersInOls[i]; j++ )
191
0
      {
192
0
        m_layerIdInOls[i][j] = m_vpsLayerId[j];
193
0
      }
194
0
    }
195
0
    else if( m_vpsOlsModeIdc == 2 )
196
0
    {
197
0
      int j = 0;
198
0
      for( int k = 0; k < m_uiMaxLayers; k++ )
199
0
      {
200
0
        if( layerIncludedInOlsFlag[i][k] )
201
0
        {
202
0
          m_layerIdInOls[i][j++] = m_vpsLayerId[k];
203
0
        }
204
0
      }
205
206
0
      m_numLayersInOls[i] = j;
207
0
    }
208
0
    if( m_numLayersInOls[i] > 1 )
209
0
    {
210
0
      m_multiLayerOlsIdx[i] = m_numMultiLayeredOlss;
211
0
      m_numMultiLayeredOlss++;
212
0
    }
213
0
  }
214
0
  m_multiLayerOlsIdxToOlsIdx.resize(m_numMultiLayeredOlss);
215
216
0
  for (int i=0, j=0; i<m_totalNumOLSs; i++)
217
0
  {
218
0
    if (m_numLayersInOls[i] > 1)
219
0
    {
220
0
      m_multiLayerOlsIdxToOlsIdx[j] = i;
221
0
    }
222
0
  }
223
0
}
224
225
void VPS::checkVPS()
226
0
{
227
0
  for (int multiLayerOlsIdx=0; multiLayerOlsIdx < m_numMultiLayeredOlss; multiLayerOlsIdx++)
228
0
  {
229
0
    const int olsIdx = m_multiLayerOlsIdxToOlsIdx[multiLayerOlsIdx];
230
0
    const int olsHrdIdx = getOlsHrdIdx(multiLayerOlsIdx);
231
0
    const int olsPtlIdx = getOlsPtlIdx(olsIdx);
232
0
    CHECK( getHrdMaxTid(olsHrdIdx) < getPtlMaxTemporalId(olsPtlIdx),
233
0
           "The value of vps_hrd_max_tid[vps_ols_timing_hrd_idx[m]] shall be greater than or equal to "
234
0
           "vps_ptl_max_tid[ vps_ols_ptl_idx[n]] for each m-th multi-layer OLS for m from 0 to "
235
0
           "NumMultiLayerOlss - 1, inclusive, and n being the OLS index of the m-th multi-layer OLS among all OLSs." );
236
0
    const int olsDpbParamsIdx = getOlsDpbParamsIdx(multiLayerOlsIdx);
237
0
    CHECK( m_dpbMaxTemporalId[olsDpbParamsIdx] < getPtlMaxTemporalId(olsPtlIdx),
238
0
           "The value of vps_dpb_max_tid[vps_ols_dpb_params_idx[m]] shall be greater than or equal to "
239
0
           "vps_ptl_max_tid[ vps_ols_ptl_idx[n]] for each m-th multi-layer OLS for m from 0 to "
240
0
           "NumMultiLayerOlss - 1, inclusive, and n being the OLS index of the m-th multi-layer OLS among all OLSs." );
241
0
  }
242
0
}
243
244
void VPS::deriveTargetOutputLayerSet( int targetOlsIdx )
245
0
{
246
0
  m_iTargetLayer = targetOlsIdx < 0 ? m_uiMaxLayers - 1 : targetOlsIdx;
247
0
  m_targetOutputLayerIdSet.clear();
248
0
  m_targetLayerIdSet.clear();
249
250
0
  for( int i = 0; i < m_numOutputLayersInOls[m_iTargetLayer]; i++ )
251
0
  {
252
0
    m_targetOutputLayerIdSet.push_back( m_outputLayerIdInOls[m_iTargetLayer][i] );
253
0
  }
254
255
0
  for( int i = 0; i < m_numLayersInOls[m_iTargetLayer]; i++ )
256
0
  {
257
0
    m_targetLayerIdSet.push_back( m_layerIdInOls[m_iTargetLayer][i] );
258
0
  }
259
0
}
260
261
Slice::Slice()
262
591
{
263
1.77k
  for( uint32_t i = 0; i < NUM_REF_PIC_LIST_01; i++ )
264
1.18k
  {
265
20.0k
    for(int iNumCount = 0; iNumCount < MAX_NUM_REF; iNumCount++)
266
18.9k
    {
267
18.9k
      m_apcRefPicList [i][iNumCount] = nullptr;
268
18.9k
      m_aiRefPOCList  [i][iNumCount] = 0;
269
18.9k
    }
270
271
1.18k
    m_apcRefPicList[i][MAX_NUM_REF] = nullptr;
272
1.18k
    m_aiRefPOCList [i][MAX_NUM_REF] = 0;
273
1.18k
  }
274
275
591
  resetWpScaling();
276
591
  initWpAcDcParam();
277
278
591
  clearAlfAPSs();
279
591
}
280
281
282
void Slice::initSlice()
283
18
{
284
54
  for(uint32_t i=0; i<NUM_REF_PIC_LIST_01; i++)
285
36
  {
286
36
    m_aiNumRefIdx[i]      = 0;
287
36
  }
288
18
  m_colFromL0Flag = true;
289
18
  m_colRefIdx = 0;
290
291
18
  m_bCheckLDC = false;
292
293
18
  m_biDirPred = false;
294
18
  m_symRefIdx[0] = -1;
295
18
  m_symRefIdx[1] = -1;
296
297
72
  for (uint32_t component = 0; component < MAX_NUM_COMPONENT; component++)
298
54
  {
299
54
    m_iSliceChromaQpDelta[component] = 0;
300
54
  }
301
18
  m_iSliceChromaQpDelta[JOINT_CbCr] = 0;
302
303
304
18
  m_substreamSizes.clear();
305
18
  m_cabacInitFlag        = false;
306
18
  resetAlfEnabledFlag();
307
18
  resetCcAlfEnabledFlags();
308
18
  m_sliceMap.resetSliceMap();
309
18
}
310
311
void Slice::inheritFromPicHeader( const PicHeader* picHeader, const PPS* pps, const SPS* sps )
312
0
{
313
0
  if( pps->getRplInfoInPhFlag() )
314
0
  {
315
0
    for( auto l: { REF_PIC_LIST_0, REF_PIC_LIST_1 } )
316
0
    {
317
#if 0
318
      // this is how it's implemented in VTM, but overridden later in parseSliceHeader()
319
      const int rplIdx = picHeader->getRPLIdx( l );
320
      m_RPLIdx[l]      = rplIdx;
321
      m_RPL[l]         = rplIdx == -1 ? *picHeader->getRPL( l ) : sps->getRPLList( l )[m_RPLIdx[l]];
322
#else
323
      // this is how it's overridden later
324
0
      setRPLIdx( l, picHeader->getRPLIdx( l ) );
325
0
      setRPL( l, *picHeader->getRPL( l ) );
326
0
#endif
327
0
    }
328
0
  }
329
0
  setColFromL0Flag( isInterB() ? picHeader->getPicColFromL0Flag() : true );
330
0
  setColRefIdx( pps->getRplInfoInPhFlag() ? picHeader->getColRefIdx() : 0 );
331
332
0
  if( pps->getQpDeltaInfoInPhFlag() )
333
0
  {
334
0
    setSliceQp( 26 + pps->getPicInitQPMinus26() + picHeader->getQpDelta() );
335
0
  }
336
337
0
  setDeblockingFilterDisable( picHeader->getDeblockingFilterDisable() );
338
0
  setDeblockingFilterBetaOffsetDiv2( picHeader->getDeblockingFilterBetaOffsetDiv2() );
339
0
  setDeblockingFilterTcOffsetDiv2  ( picHeader->getDeblockingFilterTcOffsetDiv2()   );
340
0
  if( pps->getPPSChromaToolFlag() )
341
0
  {
342
0
    setDeblockingFilterCbBetaOffsetDiv2( picHeader->getDeblockingFilterCbBetaOffsetDiv2() );
343
0
    setDeblockingFilterCbTcOffsetDiv2  ( picHeader->getDeblockingFilterCbTcOffsetDiv2()   );
344
0
    setDeblockingFilterCrBetaOffsetDiv2( picHeader->getDeblockingFilterCrBetaOffsetDiv2() );
345
0
    setDeblockingFilterCrTcOffsetDiv2  ( picHeader->getDeblockingFilterCrTcOffsetDiv2()   );
346
0
  }
347
0
  else
348
0
  {
349
0
    setDeblockingFilterCbBetaOffsetDiv2( getDeblockingFilterBetaOffsetDiv2() );
350
0
    setDeblockingFilterCbTcOffsetDiv2  ( getDeblockingFilterTcOffsetDiv2()   );
351
0
    setDeblockingFilterCrBetaOffsetDiv2( getDeblockingFilterBetaOffsetDiv2() );
352
0
    setDeblockingFilterCrTcOffsetDiv2  ( getDeblockingFilterTcOffsetDiv2()   );
353
0
  }
354
355
0
  setSaoEnabledFlag( CHANNEL_TYPE_LUMA,   picHeader->getSaoEnabledFlag( CHANNEL_TYPE_LUMA ) );
356
0
  setSaoEnabledFlag( CHANNEL_TYPE_CHROMA, picHeader->getSaoEnabledFlag( CHANNEL_TYPE_CHROMA ) );
357
358
0
  setAlfEnabledFlag( COMPONENT_Y,  picHeader->getAlfEnabledFlag( COMPONENT_Y ) );
359
0
  setAlfEnabledFlag( COMPONENT_Cb, picHeader->getAlfEnabledFlag( COMPONENT_Cb ) );
360
0
  setAlfEnabledFlag( COMPONENT_Cr, picHeader->getAlfEnabledFlag( COMPONENT_Cr ) );
361
362
0
  setNumAlfAps( picHeader->getNumAlfAps() );
363
0
  setAlfApsIdsLuma( picHeader->getAlfAPSIds() );
364
0
  setAlfApsIdChroma( picHeader->getAlfApsIdChroma() );
365
0
  setCcAlfCbEnabledFlag( picHeader->getCcAlfEnabledFlag( COMPONENT_Cb ) );
366
0
  setCcAlfCrEnabledFlag( picHeader->getCcAlfEnabledFlag( COMPONENT_Cr ) );
367
0
  setCcAlfCbApsId( picHeader->getCcAlfCbApsId() );
368
0
  setCcAlfCrApsId( picHeader->getCcAlfCrApsId() );
369
370
0
  setLmcsEnabledFlag        ( getPictureHeaderInSliceHeader() ? picHeader->getLmcsEnabledFlag()                : false );
371
0
  setExplicitScalingListUsed( getPictureHeaderInSliceHeader() ? picHeader->getExplicitScalingListEnabledFlag() : false );
372
0
}
373
374
void  Slice::setNumEntryPoints( const SPS *sps, const PPS *pps )
375
0
{
376
0
  m_numEntryPoints = 0;
377
378
0
  if( !sps->getEntryPointsPresentFlag() )
379
0
  {
380
0
    return;
381
0
  }
382
383
0
  uint32_t prevCtuX = m_sliceMap.getCtuAddrInSlice( 0 ) % pps->getPicWidthInCtu();
384
0
  uint32_t prevCtuY = m_sliceMap.getCtuAddrInSlice( 0 ) / pps->getPicWidthInCtu();
385
  // count the number of CTUs that align with either the start of a tile, or with an entropy coding sync point
386
  // ignore the first CTU since it doesn't count as an entry point
387
0
  for( uint32_t i = 1; i < m_sliceMap.getNumCtuInSlice(); i++ )
388
0
  {
389
0
    const uint32_t ctuAddr = m_sliceMap.getCtuAddrInSlice( i );
390
0
    const uint32_t ctuX    = ctuAddr % pps->getPicWidthInCtu();
391
0
    const uint32_t ctuY    = ctuAddr / pps->getPicWidthInCtu();
392
393
0
    if( pps->ctuToTileRowBd( ctuY ) != pps->ctuToTileRowBd( prevCtuY )
394
0
        || pps->ctuToTileColBd( ctuX ) != pps->ctuToTileColBd( prevCtuX )
395
0
        || ( ctuY != prevCtuY && sps->getEntropyCodingSyncEnabledFlag() ) )
396
0
    {
397
0
      m_numEntryPoints++;
398
0
    }
399
400
0
    prevCtuX = ctuX;
401
0
    prevCtuY = ctuY;
402
0
  }
403
0
}
404
405
void Slice::setDefaultClpRng( const SPS& sps )
406
0
{
407
0
  m_clpRngs.bd = sps.getBitDepth();
408
0
}
409
410
411
bool Slice::getRapPicFlag() const
412
0
{
413
0
  return getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_W_RADL
414
0
      || getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_N_LP
415
0
      || getNalUnitType() == NAL_UNIT_CODED_SLICE_CRA;
416
0
}
417
418
Picture* Slice::xGetRefPic( const PicList& rcListPic, int poc, const int layerId )
419
0
{
420
  // return a nullptr, if picture is not found
421
0
  for( auto& pcPic: rcListPic )
422
0
  {
423
0
    if( pcPic && pcPic->getPOC() == poc && pcPic->dpbReferenceMark && pcPic->layerId == layerId )
424
0
    {
425
0
      pcPic->stillReferenced = true;
426
0
      return pcPic;
427
0
    }
428
0
  }
429
430
0
  return nullptr;
431
0
}
432
433
Picture* Slice::xGetLongTermRefPic( const PicList& rcListPic, int poc, bool pocHasMsb, const int layerId, bool getCandidate )
434
0
{
435
0
  for( auto& pcPic: rcListPic )
436
0
  {
437
0
    if( pcPic && pcPic->getPOC() != this->getPOC() && pcPic->dpbReferenceMark && pcPic->layerId == layerId )
438
0
    {
439
0
      if( isLTPocEqual( poc, pcPic->getPOC(), getSPS()->getBitsForPOC(), pocHasMsb ) )
440
0
      {
441
0
        if( getCandidate || pcPic->dpbReferenceMark == Picture::LongTerm )
442
0
        {
443
0
          pcPic->stillReferenced = true;
444
0
          return pcPic;
445
0
        }
446
447
0
        return nullptr;
448
0
      }
449
0
    }
450
0
  }
451
452
0
  return nullptr;
453
0
}
454
455
void Slice::constructRefPicLists( const PicList& rcPicList )
456
0
{
457
0
  ::memset(m_bIsUsedAsLongTerm, 0, sizeof(m_bIsUsedAsLongTerm));
458
0
  if (m_eSliceType == I_SLICE)
459
0
  {
460
0
    ::memset(m_apcRefPicList, 0, sizeof(m_apcRefPicList));
461
0
    ::memset(m_aiRefPOCList, 0, sizeof(m_aiRefPOCList));
462
0
    ::memset(m_aiNumRefIdx, 0, sizeof(m_aiNumRefIdx));
463
0
    return;
464
0
  }
465
466
0
  constructSingleRefPicList( rcPicList, REF_PIC_LIST_0 );
467
0
  constructSingleRefPicList( rcPicList, REF_PIC_LIST_1 );
468
0
}
469
470
void Slice::constructSingleRefPicList( const PicList& rcPicList, RefPicList listId )
471
0
{
472
0
  ReferencePictureList& rRPL = m_RPL[listId];
473
474
0
  uint32_t numOfActiveRef = getNumRefIdx( listId );
475
0
  CHECK( rRPL.getNumRefEntries() < numOfActiveRef,
476
0
         "For each i equal to 0 or 1, num_ref_entries[ i ][ RplsIdx[ i ] ] shall not be less than NumRefIdxActive[ i ]." );
477
0
  for( int ii = 0; ii < rRPL.getNumRefEntries(); ii++ )
478
0
  {
479
0
    Picture* pcRefPic = nullptr;
480
0
    int      refPOC   = 0;
481
482
0
    if( !rRPL.isRefPicLongterm( ii ) )
483
0
    {
484
0
      refPOC   = getPOC() + rRPL.getRefPicIdentifier( ii );
485
      // A same-layer STRP entry must not resolve to the current POC: that is either the current
486
      // picture or a stale POC-colliding picture, neither valid for inter prediction (only the
487
      // separate inter-layer path may reference the current POC, in a different layer).
488
0
      CHECK( refPOC == getPOC(), "An STRP entry must not refer to a picture with the current POC" );
489
0
      pcRefPic = xGetRefPic( rcPicList, refPOC, m_pcPic->layerId );
490
0
      CHECK( !pcRefPic, "Picture pointer missing from ref pic list" );
491
492
0
      pcRefPic->dpbReferenceMark = Picture::ShortTerm;
493
0
    }
494
0
    else
495
0
    {
496
0
      refPOC   = rRPL.calcLTRefPOC( getPOC(), getSPS()->getBitsForPOC(), ii );
497
0
      pcRefPic = xGetLongTermRefPic( rcPicList, refPOC, rRPL.getDeltaPocMSBPresentFlag( ii ), m_pcPic->layerId, true );
498
0
      CHECK( !pcRefPic, "Picture pointer missing from ref pic list" );
499
0
      if( !rRPL.getDeltaPocMSBPresentFlag( ii ) )
500
0
        refPOC = pcRefPic->getPOC();
501
502
0
      CHECK( getPOC() - refPOC >= ( 1 << 24 ),
503
0
             "There shall be no LTRP entry in RefPicList[ 0 ] or RefPicList[ 1 ] for which the difference between the PicOrderCntVal of the"
504
0
             " current picture and the PicOrderCntVal of the picture referred to by the entry is greater than or equal to 2^24." );
505
506
0
      pcRefPic->dpbReferenceMark = Picture::LongTerm;
507
0
    }
508
509
0
    CHECK( pcRefPic->getPOC() != refPOC, "reference picture as wrong POC" );
510
0
    CHECK_FATAL(pcRefPic->chromaFormat != getPic()->chromaFormat,"reference picture has wrong chroma format");
511
    // buffers of a reference decoded under a different SPS may lack the margin or wrap-around buffer prediction relies on
512
0
    CHECK( pcRefPic->margin != getPic()->margin, "reference picture has wrong margin" );
513
0
    CHECK( getSPS()->getUseWrapAround() && !pcRefPic->cs->sps->getUseWrapAround(), "reference picture has no wrap-around buffer" );
514
515
0
    if( ii < numOfActiveRef )
516
0
    {
517
0
      m_apcRefPicList    [listId][ii] = pcRefPic;
518
0
      m_aiRefPOCList     [listId][ii] = refPOC;
519
0
      m_bIsUsedAsLongTerm[listId][ii] = pcRefPic->dpbReferenceMark == Picture::LongTerm;
520
521
0
      CHECK( !m_apcRefPicList[listId][ii] || m_apcRefPicList[listId][ii]->getTLayer() > getTLayer(),
522
0
             "The picture referred to by each active entry in RefPicList[ 0 ] or RefPicList[ 1 ] shall be present in the DPB and shall"
523
0
             " have TemporalId less than or equal to that of the current picture." );
524
0
      CHECK( !m_pcPic, "m_pcPic not set yet" );
525
      // a generated reference picture has no picture header, and ph_non_ref_pic_flag equal to 0 (8.3.4.2)
526
0
      const bool nonReferencePictureFlag = m_apcRefPicList[listId][ii]->cs->picHeader && m_apcRefPicList[listId][ii]->cs->picHeader->getNonReferencePictureFlag();
527
0
      CHECK( m_apcRefPicList[listId][ii] == m_pcPic || nonReferencePictureFlag,
528
0
             "The picture referred to by each entry in RefPicList[ 0 ] or RefPicList[ 1 ] shall not be the current picture"
529
0
             " and shall have ph_non_ref_pic_flag equal to 0." );
530
0
      CHECK( getNalUnitType() == NAL_UNIT_CODED_SLICE_STSA && m_apcRefPicList[listId][ii]->getTLayer() == getTLayer()
531
0
               && !m_apcRefPicList[listId][ii]->wasLost, // the TemporalId of a lost picture is unknown
532
0
             "When the current slice has nal_unit_type equal to STSA_NUT, there shall be no active entry in RefPicList[ 0 ] or RefPicList[ 1 ]"
533
0
             " that has TemporalId equal to that of the current picture and nuh_layer_id equal to that of the current picture." );
534
535
0
      for( int j = 0; j < ii; ++j )
536
0
      {
537
0
        CHECK( m_apcRefPicList[listId][j] == m_apcRefPicList[listId][ii] && m_bIsUsedAsLongTerm[listId][j] != m_bIsUsedAsLongTerm[listId][ii],
538
0
               "An STRP entry in RefPicList[ 0 ] or RefPicList[ 1 ] of a slice of a picture and an LTRP entry in RefPicList[ 0 ] or RefPicList[ 1 ]"
539
0
               " of the same slice or a different slice of the same picture shall not refer to the same picture." )
540
0
      }
541
0
    }
542
0
  }
543
0
}
544
545
void Slice::checkColRefIdx(uint32_t curSliceSegmentIdx, const Picture* pic)
546
0
{
547
0
  int i;
548
0
  Slice* curSlice = pic->slices[curSliceSegmentIdx];
549
0
  int currColRefPOC =  curSlice->getRefPOC( RefPicList(1 - curSlice->getColFromL0Flag()), curSlice->getColRefIdx());
550
551
0
  for(i=curSliceSegmentIdx-1; i>=0; i--)
552
0
  {
553
0
    const Slice* preSlice = pic->slices[i];
554
0
    if(preSlice->getSliceType() != I_SLICE)
555
0
    {
556
0
      const int preColRefPOC  = preSlice->getRefPOC( RefPicList(1 - preSlice->getColFromL0Flag()), preSlice->getColRefIdx());
557
0
      if(currColRefPOC != preColRefPOC)
558
0
      {
559
0
        THROW_RECOVERABLE( "Collocated_ref_idx shall always be the same for all slices of a coded picture!" );
560
0
      }
561
0
      else
562
0
      {
563
0
        break;
564
0
      }
565
0
    }
566
0
  }
567
0
}
568
569
void Slice::checkCRA( int& pocCRA, NalUnitType& associatedIRAPType, const PicList& rcListPic )
570
0
{
571
0
  if( pocCRA < MAX_UINT && getPOC() > pocCRA )
572
0
  {
573
0
    for( int l = 0; l < NUM_REF_PIC_LIST_01; ++l )
574
0
    {
575
0
      const uint32_t numRefPic = m_RPL[l].getNumberOfShorttermPictures() + m_RPL[l].getNumberOfLongtermPictures();
576
0
      for( int i = 0; i < numRefPic; i++ )
577
0
      {
578
0
        if( !m_RPL[l].isRefPicLongterm( i ) )
579
0
        {
580
0
          CHECK( getPOC() + m_RPL[l].getRefPicIdentifier( i ) < pocCRA, "Invalid state" );
581
0
        }
582
0
        else
583
0
        {
584
0
          CHECK( xGetLongTermRefPic( rcListPic, m_RPL[l].getRefPicIdentifier( i ), m_RPL[l].getDeltaPocMSBPresentFlag( i ), m_pcPic->layerId )->getPOC() < pocCRA, "Invalid state" );
585
0
        }
586
0
      }
587
0
    }
588
0
  }
589
0
  if (getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_W_RADL || getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_N_LP) // IDR picture found
590
0
  {
591
0
    pocCRA = getPOC();
592
0
    associatedIRAPType = getNalUnitType();
593
0
  }
594
0
  else if (getNalUnitType() == NAL_UNIT_CODED_SLICE_CRA) // CRA picture found
595
0
  {
596
0
    pocCRA = getPOC();
597
0
    associatedIRAPType = getNalUnitType();
598
0
  }
599
0
}
600
601
void Slice::checkSTSA( const PicList& rcListPic )
602
0
{
603
0
  int ii;
604
0
  Picture* pcRefPic = NULL;
605
0
  int numOfActiveRef = getNumRefIdx(REF_PIC_LIST_0);
606
607
0
  for (ii = 0; ii < numOfActiveRef; ii++)
608
0
  {
609
0
    pcRefPic = m_apcRefPicList[REF_PIC_LIST_0][ii];
610
611
0
    if( m_eNalUnitType == NAL_UNIT_CODED_SLICE_STSA && pcRefPic->layerId == m_pcPic->layerId && !pcRefPic->wasLost )   // the TemporalId of a lost picture is unknown
612
0
    {
613
0
      CHECK( pcRefPic->tempLayer == m_uiTLayer, "When the current picture is an STSA picture and nuh_layer_id equal to that of the current picture, there shall be no active entry in the RPL that has TemporalId equal to that of the current picture" );
614
0
    }
615
    
616
    // Checking this: "When the current picture is a picture that follows, in decoding order, an STSA picture that has TemporalId equal to that of the current picture, there shall be no
617
    // picture that has TemporalId equal to that of the current picture included as an active entry in RefPicList[ 0 ] or RefPicList[ 1 ] that precedes the STSA picture in decoding order."
618
0
    CHECK(pcRefPic->subLayerNonReferencePictureDueToSTSA, "The RPL of the current picture contains a picture that is not allowed in this temporal layer due to an earlier STSA picture");
619
0
  }
620
621
0
  numOfActiveRef = getNumRefIdx(REF_PIC_LIST_1);
622
0
  for (ii = 0; ii < numOfActiveRef; ii++)
623
0
  {
624
0
    pcRefPic = m_apcRefPicList[REF_PIC_LIST_1][ii];
625
626
0
    if( m_eNalUnitType == NAL_UNIT_CODED_SLICE_STSA && pcRefPic->layerId == m_pcPic->layerId && !pcRefPic->wasLost )   // the TemporalId of a lost picture is unknown
627
0
    {
628
0
      CHECK( pcRefPic->tempLayer == m_uiTLayer, "When the current picture is an STSA picture and nuh_layer_id equal to that of the current picture, there shall be no active entry in the RPL that has TemporalId equal to that of the current picture" );
629
0
    }
630
    
631
    // Checking this: "When the current picture is a picture that follows, in decoding order, an STSA picture that has TemporalId equal to that of the current picture, there shall be no
632
    // picture that has TemporalId equal to that of the current picture included as an active entry in RefPicList[ 0 ] or RefPicList[ 1 ] that precedes the STSA picture in decoding order."
633
0
    CHECK(pcRefPic->subLayerNonReferencePictureDueToSTSA, "The active RPL part of the current picture contains a picture that is not allowed in this temporal layer due to an earlier STSA picture");
634
0
  }
635
636
  // If the current picture is an STSA picture, make all reference pictures in the DPB with temporal
637
  // id equal to the temproal id of the current picture sub-layer non-reference pictures. The flag
638
  // subLayerNonReferencePictureDueToSTSA equal to true means that the picture may not be used for
639
  // reference by a picture that follows the current STSA picture in decoding order
640
0
  if (getNalUnitType() == NAL_UNIT_CODED_SLICE_STSA)
641
0
  {
642
0
    for( auto & pcPic: rcListPic )
643
0
    {
644
0
      if( !pcPic->dpbReferenceMark || pcPic->getPOC() == m_iPOC )
645
0
      {
646
0
        continue;
647
0
      }
648
649
0
      if( pcPic->tempLayer == m_uiTLayer )
650
0
      {
651
0
        pcPic->subLayerNonReferencePictureDueToSTSA = true;
652
0
      }
653
0
    }
654
0
  }
655
0
}
656
657
void Slice::checkRPL(const ReferencePictureList* pRPL0, const ReferencePictureList* pRPL1, const int associatedIRAPDecodingOrderNumber, const PicList& rcListPic)
658
0
{
659
0
  Picture* pcRefPic;
660
0
  int refPicPOC;
661
0
  int refPicDecodingOrderNumber;
662
663
0
  int irapPOC = getAssociatedIRAPPOC();
664
  
665
0
  const int                   numEntries[]       = { pRPL0->getNumberOfShorttermPictures() + pRPL0->getNumberOfLongtermPictures() + pRPL0->getNumberOfInterLayerPictures(),
666
0
                                                     pRPL1->getNumberOfShorttermPictures() + pRPL1->getNumberOfLongtermPictures() + pRPL1->getNumberOfInterLayerPictures() };
667
0
  const int numActiveEntries[] = { getNumRefIdx( REF_PIC_LIST_0 ), getNumRefIdx( REF_PIC_LIST_1 ) };
668
0
  const ReferencePictureList* rpl[] = { pRPL0, pRPL1 };
669
0
  const bool fieldSeqFlag = getSPS()->getFieldSeqFlag();
670
0
  const int layerIdx = m_pcPic->cs->vps == nullptr ? 0 : m_pcPic->cs->vps->getGeneralLayerIdx( m_pcPic->layerId );
671
672
0
  for( int refPicList = 0; refPicList < 2; refPicList++ )
673
0
  {
674
0
    for( int i = 0; i < numEntries[refPicList]; i++ )
675
0
    {
676
0
      if( rpl[refPicList]->isInterLayerRefPic( i ) )
677
0
      {
678
0
        int refLayerId = m_pcPic->cs->vps->getLayerId( m_pcPic->cs->vps->getDirectRefLayerIdx( layerIdx, rpl[refPicList]->getInterLayerRefPicIdx( i ) ) );
679
0
        pcRefPic = xGetRefPic( rcListPic, getPOC(), refLayerId );
680
0
        refPicPOC = pcRefPic->getPOC();
681
0
      }
682
0
      else if( !rpl[refPicList]->isRefPicLongterm( i ) )
683
0
      {
684
0
        refPicPOC = getPOC() + rpl[refPicList]->getRefPicIdentifier(i);
685
0
        pcRefPic = xGetRefPic( rcListPic, refPicPOC, m_pcPic->layerId );
686
0
      }
687
0
      else
688
0
      {
689
0
        int ltrpPoc = rpl[refPicList]->calcLTRefPOC( getPOC(), getSPS()->getBitsForPOC(), i );
690
691
0
        pcRefPic = xGetLongTermRefPic( rcListPic, ltrpPoc, rpl[refPicList]->getDeltaPocMSBPresentFlag( i ), m_pcPic->layerId );
692
0
        refPicPOC = pcRefPic->getPOC();
693
0
      }
694
0
      if( !pcRefPic )
695
0
      {
696
        // can't check decoding order for unavailable reference pictures
697
0
        continue;
698
0
      }
699
0
      refPicDecodingOrderNumber = pcRefPic->getDecodingOrderNumber();
700
701
0
      if( m_eNalUnitType == NAL_UNIT_CODED_SLICE_CRA || m_eNalUnitType == NAL_UNIT_CODED_SLICE_IDR_W_RADL || m_eNalUnitType == NAL_UNIT_CODED_SLICE_IDR_N_LP )
702
0
      {
703
0
        CHECK( refPicPOC < irapPOC || refPicDecodingOrderNumber < associatedIRAPDecodingOrderNumber, "When the current picture, with nuh_layer_id equal to a particular value layerId, "
704
0
          "is an IRAP picture, there shall be no picture referred to by an entry in RefPicList[ 0 ] that precedes, in output order or decoding order, any preceding IRAP picture "
705
0
          "with nuh_layer_id equal to layerId in decoding order (when present)." );
706
0
      }
707
708
0
      if( irapPOC < getPOC() && !fieldSeqFlag )
709
0
      {
710
0
        CHECK( refPicPOC < irapPOC || refPicDecodingOrderNumber < associatedIRAPDecodingOrderNumber, "When the current picture follows an IRAP picture having the same value "
711
0
          "of nuh_layer_id and the leading pictures, if any, associated with that IRAP picture, in both decoding order and output order, there shall be no picture referred "
712
0
          "to by an entry in RefPicList[ 0 ] or RefPicList[ 1 ] that precedes that IRAP picture in output order or decoding order." );
713
0
      }
714
715
      // a generated reference picture has no picture header, and ph_non_ref_pic_flag equal to 0 (8.3.4.2)
716
0
      const bool nonReferencePictureFlag = pcRefPic->cs->picHeader && pcRefPic->cs->picHeader->getNonReferencePictureFlag();
717
0
      CHECK( pcRefPic == m_pcPic || nonReferencePictureFlag, "The picture referred to by each entry in RefPicList[ 0 ] or RefPicList[ 1 ] shall not be the current picture and shall have ph_non_ref_pic_flag equal to 0" );
718
719
0
      if( i < numActiveEntries[refPicList] )
720
0
      {
721
0
        if( irapPOC < getPOC() )
722
0
        {
723
0
          CHECK( refPicPOC < irapPOC || refPicDecodingOrderNumber < associatedIRAPDecodingOrderNumber, "When the current picture follows an IRAP picture having the same value "
724
0
            "of nuh_layer_id in both decoding order and output order, there shall be no picture referred to by an active entry in RefPicList[ 0 ] or RefPicList[ 1 ] that "
725
0
            "precedes that IRAP picture in output order or decoding order." );
726
0
        }
727
728
        // Checking this: "When the current picture is a RADL picture, there shall be no active entry in RefPicList[ 0 ] or
729
        // RefPicList[ 1 ] that is any of the following: A picture that precedes the associated IRAP picture in decoding order"
730
0
        if( m_eNalUnitType == NAL_UNIT_CODED_SLICE_RADL )
731
0
        {
732
0
          CHECK( refPicDecodingOrderNumber < associatedIRAPDecodingOrderNumber, "RADL picture detected that violate the rule that no active entry in RefPicList[] shall precede the associated IRAP picture in decoding order" );
733
0
        }
734
735
0
        CHECK( pcRefPic->tempLayer > m_pcPic->tempLayer, "The picture referred to by each active entry in RefPicList[ 0 ] or RefPicList[ 1 ] shall be present in the DPB and shall have TemporalId less than or equal to that of the current picture." );
736
0
      }
737
0
    }
738
0
  }
739
0
}
740
741
void Slice::copySliceInfo( Slice* pSrc, bool cpyAlmostAll )
742
0
{
743
0
  CHECK_FATAL( !pSrc, "Source is NULL" );
744
745
0
  m_iPOC         = pSrc->m_iPOC;
746
0
  m_eNalUnitType = pSrc->m_eNalUnitType;
747
0
  m_eSliceType   = pSrc->m_eSliceType;
748
0
  m_uiTLayer     = pSrc->m_uiTLayer;
749
750
0
  m_clpRngs      = pSrc->m_clpRngs;
751
0
  m_iSliceQp     = pSrc->m_iSliceQp;
752
753
0
  m_bCheckLDC    = pSrc->m_bCheckLDC;
754
0
  m_iLastIDR     = pSrc->m_iLastIDR;
755
756
0
  m_pcPicHeader  = pSrc->m_pcPicHeader;
757
0
  if( cpyAlmostAll )
758
0
  {
759
0
    m_pcPic      = pSrc->m_pcPic;
760
0
  }
761
762
  // TODO: check remaining fields if it really makes sense to copy (GH)
763
764
0
  m_sliceMap     = pSrc->m_sliceMap;
765
766
0
  m_biDirPred    = pSrc->m_biDirPred;
767
0
  m_symRefIdx[0] = pSrc->m_symRefIdx[0];
768
0
  m_symRefIdx[1] = pSrc->m_symRefIdx[1];
769
770
0
  memcpy( m_apcRefPicList,     pSrc->m_apcRefPicList,     sizeof( m_apcRefPicList ) );
771
0
  memcpy( m_aiRefPOCList,      pSrc->m_aiRefPOCList,      sizeof( m_aiRefPOCList ) );
772
0
  memcpy( m_bIsUsedAsLongTerm, pSrc->m_bIsUsedAsLongTerm, sizeof( m_bIsUsedAsLongTerm ) );
773
0
  if( cpyAlmostAll )
774
0
  {
775
0
    memcpy( m_RPL,             pSrc->m_RPL,               sizeof( m_RPL ) );
776
0
  }
777
0
  memcpy( m_weightPredTable,   pSrc->m_weightPredTable,   sizeof( m_weightPredTable ) );
778
0
}
779
780
void Slice::checkLeadingPictureRestrictions( const PicList & rcListPic ) const
781
0
{
782
0
  int nalUnitType = this->getNalUnitType();
783
784
  // When a picture is a leading picture, it shall be a RADL or RASL picture.
785
0
  if(this->getAssociatedIRAPPOC() > this->getPOC())
786
0
  {
787
    // Do not check IRAP pictures since they may get a POC lower than their associated IRAP
788
0
    if (nalUnitType < NAL_UNIT_CODED_SLICE_IDR_W_RADL ||
789
0
        nalUnitType > NAL_UNIT_CODED_SLICE_CRA)
790
0
    {
791
0
      CHECK(nalUnitType != NAL_UNIT_CODED_SLICE_RASL &&
792
0
            nalUnitType != NAL_UNIT_CODED_SLICE_RADL, "Invalid NAL unit type");
793
0
    }
794
0
  }
795
796
  // When a picture is a trailing picture, it shall not be a RADL or RASL picture.
797
0
  if(this->getAssociatedIRAPPOC() < this->getPOC())
798
0
  {
799
0
    CHECK(nalUnitType == NAL_UNIT_CODED_SLICE_RASL ||
800
0
          nalUnitType == NAL_UNIT_CODED_SLICE_RADL, "Invalid NAL unit type");
801
0
  }
802
803
804
  // No RASL pictures shall be present in the bitstream that are associated with
805
  // an IDR picture.
806
0
  if (nalUnitType == NAL_UNIT_CODED_SLICE_RASL)
807
0
  {
808
0
    CHECK( this->getAssociatedIRAPType() == NAL_UNIT_CODED_SLICE_IDR_N_LP   ||
809
0
           this->getAssociatedIRAPType() == NAL_UNIT_CODED_SLICE_IDR_W_RADL, "Invalid NAL unit type");
810
0
  }
811
812
  // No RADL pictures shall be present in the bitstream that are associated with
813
  // a BLA picture having nal_unit_type equal to BLA_N_LP or that are associated
814
  // with an IDR picture having nal_unit_type equal to IDR_N_LP.
815
0
  if (nalUnitType == NAL_UNIT_CODED_SLICE_RADL)
816
0
  {
817
0
    CHECK (this->getAssociatedIRAPType() == NAL_UNIT_CODED_SLICE_IDR_N_LP, "Invalid NAL unit type");
818
0
  }
819
820
  // loop through all pictures in the reference picture buffer
821
0
  for( auto & pcPic: rcListPic )
822
0
  {
823
0
    if( pcPic->progress < Picture::reconstructed || pcPic->wasLost || pcPic->error )
824
0
    {
825
0
      continue;
826
0
    }
827
0
    if( pcPic->poc == this->getPOC())
828
0
    {
829
0
      continue;
830
0
    }
831
0
    const Slice* pcSlice = pcPic->slices[0];
832
833
    // Any picture that has PicOutputFlag equal to 1 that precedes an IRAP picture
834
    // in decoding order shall precede the IRAP picture in output order.
835
    // (Note that any picture following in output order would be present in the DPB)
836
//    if(pcSlice->getPicHeader()->getPicOutputFlag() == 1 && !this->getPicHeader()->getNoOutputOfPriorPicsFlag())
837
0
    if(pcSlice->getPicHeader()->getPicOutputFlag() == 1 && !this->getNoOutputOfPriorPicsFlag()) 
838
0
    {
839
0
      if (nalUnitType == NAL_UNIT_CODED_SLICE_CRA ||
840
0
          nalUnitType == NAL_UNIT_CODED_SLICE_IDR_N_LP ||
841
0
          nalUnitType == NAL_UNIT_CODED_SLICE_IDR_W_RADL)
842
0
      {
843
0
        CHECK(pcPic->poc >= this->getPOC(), "Invalid POC");
844
0
      }
845
0
    }
846
847
    // Any picture that has PicOutputFlag equal to 1 that precedes an IRAP picture
848
    // in decoding order shall precede any RADL picture associated with the IRAP
849
    // picture in output order.
850
0
    if(pcSlice->getPicHeader()->getPicOutputFlag() == 1)
851
0
    {
852
0
      if (nalUnitType == NAL_UNIT_CODED_SLICE_RADL)
853
0
      {
854
        // rpcPic precedes the IRAP in decoding order
855
0
        if(this->getAssociatedIRAPPOC() > pcSlice->getAssociatedIRAPPOC())
856
0
        {
857
          // rpcPic must not be the IRAP picture
858
0
          if(this->getAssociatedIRAPPOC() != pcPic->poc)
859
0
          {
860
0
            CHECK( pcPic->poc >= this->getPOC(), "Invalid POC");
861
0
          }
862
0
        }
863
0
      }
864
0
    }
865
866
    // When a picture is a leading picture, it shall precede, in decoding order,
867
    // all trailing pictures that are associated with the same IRAP picture.
868
0
    if (nalUnitType == NAL_UNIT_CODED_SLICE_RASL ||
869
0
        nalUnitType == NAL_UNIT_CODED_SLICE_RADL )
870
0
      {
871
0
        if(pcSlice->getAssociatedIRAPPOC() == this->getAssociatedIRAPPOC())
872
0
        {
873
          // rpcPic is a picture that preceded the leading in decoding order since it exist in the DPB
874
          // rpcPic would violate the constraint if it was a trailing picture
875
0
          CHECK( pcPic->poc > this->getAssociatedIRAPPOC(), "Invalid POC");
876
0
        }
877
0
      }
878
879
    // Any RASL picture associated with a CRA or BLA picture shall precede any
880
    // RADL picture associated with the CRA or BLA picture in output order
881
0
    if (nalUnitType == NAL_UNIT_CODED_SLICE_RASL)
882
0
    {
883
0
      if ((this->getAssociatedIRAPType() == NAL_UNIT_CODED_SLICE_CRA) &&
884
0
          this->getAssociatedIRAPPOC() == pcSlice->getAssociatedIRAPPOC())
885
0
      {
886
0
        if (pcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_RADL)
887
0
        {
888
0
          CHECK( pcPic->poc <= this->getPOC(), "Invalid POC");
889
0
        }
890
0
      }
891
0
    }
892
893
    // Any RASL picture associated with a CRA picture shall follow, in output
894
    // order, any IRAP picture that precedes the CRA picture in decoding order.
895
0
    if (nalUnitType == NAL_UNIT_CODED_SLICE_RASL)
896
0
    {
897
0
      if(this->getAssociatedIRAPType() == NAL_UNIT_CODED_SLICE_CRA)
898
0
      {
899
0
        if(pcSlice->getPOC() < this->getAssociatedIRAPPOC() &&
900
0
          (
901
0
            pcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_N_LP   ||
902
0
            pcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_W_RADL ||
903
0
            pcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_CRA))
904
0
        {
905
0
          CHECK(this->getPOC() <= pcSlice->getPOC(), "Invalid POC");
906
0
        }
907
0
      }
908
0
    }
909
0
  }
910
0
}
911
912
bool Slice::checkThatAllRefPicsAreAvailable( const PicList&              rcListPic,
913
                                             const ReferencePictureList* pRPL,
914
                                             int                         numActiveRefPics,
915
                                             int                         currPicBitsForPoc,
916
                                             int*                        missingPOC,
917
                                             int*                        missingRefPicIndex ) const
918
0
{
919
0
  if( this->isIDR() )
920
0
    return true;   // Assume that all pic in the DPB will be flushed anyway so no need to check.
921
922
0
  *missingPOC         = 0;
923
0
  *missingRefPicIndex = 0;
924
925
  // Check long term ref pics
926
0
  for( int ii = 0; pRPL->getNumberOfLongtermPictures() > 0 && ii < numActiveRefPics; ii++ )
927
0
  {
928
0
    if( !pRPL->isRefPicLongterm( ii ) )
929
0
      continue;
930
931
    // RefPicLtPocList (8.3.2): the full POC when the MSB is signalled, so the picture generated for it (8.3.4.1) matches
932
0
    const int checkPoc    = pRPL->calcLTRefPOC( this->getPOC(), currPicBitsForPoc, ii );
933
0
    bool      isAvailable = 0;
934
0
    for( auto& rpcPic: rcListPic )
935
0
    {
936
0
      const int bitsForPoc = rpcPic->cs->sps->getBitsForPOC();
937
0
      const int poc        = rpcPic->getPOC();
938
0
      const int refPoc     = pRPL->calcLTRefPOC( this->getPOC(), bitsForPoc, ii );
939
940
0
      if( rpcPic->dpbReferenceMark == Picture::LongTerm && isLTPocEqual( poc, refPoc, bitsForPoc, pRPL->getDeltaPocMSBPresentFlag( ii ) )  )
941
0
      {
942
0
        isAvailable = 1;
943
0
        break;
944
0
      }
945
0
    }
946
0
    if( isAvailable )
947
0
      continue;
948
949
    // if there was no such long-term check the short terms
950
0
    for( auto& rpcPic: rcListPic )
951
0
    {
952
0
      const int bitsForPoc = rpcPic->cs->sps->getBitsForPOC();
953
0
      const int poc        = rpcPic->getPOC();
954
0
      const int refPoc     = pRPL->calcLTRefPOC( this->getPOC(), bitsForPoc, ii );
955
956
0
      if( rpcPic->dpbReferenceMark == Picture::ShortTerm && isLTPocEqual( poc, refPoc, bitsForPoc, pRPL->getDeltaPocMSBPresentFlag( ii ) )  )
957
0
      {
958
0
        isAvailable      = 1;
959
0
        rpcPic->dpbReferenceMark  = Picture::LongTerm;
960
0
        break;
961
0
      }
962
0
    }
963
964
0
    if( !isAvailable )
965
0
    {
966
0
      msg( ERROR, "Current picture: %d Long-term reference picture with POC = %3d seems to have been removed or not correctly decoded.\n", this->getPOC(), checkPoc );
967
968
0
      *missingPOC         = checkPoc;
969
0
      *missingRefPicIndex = ii;
970
0
      return false;
971
0
    }
972
0
  }
973
974
  // Check short term ref pics
975
0
  for( int ii = 0; ii < numActiveRefPics; ii++ )
976
0
  {
977
0
    if( pRPL->isRefPicLongterm( ii ) )
978
0
      continue;
979
980
0
    const int checkPoc    = this->getPOC() + pRPL->getRefPicIdentifier( ii );
981
0
    bool      isAvailable = false;
982
0
    for( auto& rpcPic: rcListPic )
983
0
    {
984
0
      if( rpcPic->getPOC() == checkPoc && rpcPic->dpbReferenceMark )
985
0
      {
986
0
        isAvailable = true;
987
0
        break;
988
0
      }
989
0
    }
990
991
    // report that a picture is lost if it is in the Reference Picture List but not in the DPB
992
0
    if( !isAvailable && pRPL->getNumberOfShorttermPictures() > 0 )
993
0
    {
994
0
      msg( ERROR, "Current picture: %d Short-term reference picture with POC = %3d seems to have been removed or not correctly decoded.\n", this->getPOC(), checkPoc );
995
996
0
      *missingPOC         = checkPoc;
997
0
      *missingRefPicIndex = ii;
998
0
      return false;
999
0
    }
1000
0
  }
1001
1002
0
  return true;
1003
0
}
1004
1005
//! get AC and DC values for weighted pred
1006
void  Slice::getWpAcDcParam(const WPACDCParam *&wp) const
1007
0
{
1008
0
  wp = m_weightACDCParam;
1009
0
}
1010
1011
//! init AC and DC values for weighted pred
1012
void  Slice::initWpAcDcParam()
1013
591
{
1014
2.36k
  for(int iComp = 0; iComp < MAX_NUM_COMPONENT; iComp++ )
1015
1.77k
  {
1016
1.77k
    m_weightACDCParam[iComp].iAC = 0;
1017
1.77k
    m_weightACDCParam[iComp].iDC = 0;
1018
1.77k
  }
1019
591
}
1020
1021
//! get tables for weighted prediction
1022
void Slice::getWpScaling( RefPicList e, int iRefIdx, const WPScalingParam*& wp ) const
1023
0
{
1024
0
  CHECK( e >= NUM_REF_PIC_LIST_01, "Invalid picture reference list" );
1025
0
  wp = m_weightPredTable[e][iRefIdx >= 0 ? iRefIdx : 0];   // iRefIdx can be -1
1026
0
}
1027
1028
void Slice::getWpScaling( RefPicList e, int iRefIdx, WPScalingParam*& wp )
1029
0
{
1030
0
  CHECK( e >= NUM_REF_PIC_LIST_01, "Invalid picture reference list" );
1031
0
  wp = m_weightPredTable[e][iRefIdx >= 0 ? iRefIdx : 0];   // iRefIdx can be -1
1032
0
}
1033
1034
//! reset Default WP tables settings : no weight.
1035
void  Slice::resetWpScaling()
1036
591
{
1037
1.77k
  for ( int e=0 ; e<NUM_REF_PIC_LIST_01 ; e++ )
1038
1.18k
  {
1039
20.0k
    for ( int i=0 ; i<MAX_NUM_REF ; i++ )
1040
18.9k
    {
1041
75.6k
      for ( int yuv=0 ; yuv<MAX_NUM_COMPONENT ; yuv++ )
1042
56.7k
      {
1043
56.7k
        WPScalingParam  *pwp = &(m_weightPredTable[e][i][yuv]);
1044
56.7k
        pwp->bPresentFlag      = false;
1045
56.7k
        pwp->uiLog2WeightDenom = 0;
1046
56.7k
        pwp->uiLog2WeightDenom = 0;
1047
56.7k
        pwp->iWeight           = 1;
1048
56.7k
        pwp->iOffset           = 0;
1049
56.7k
      }
1050
18.9k
    }
1051
1.18k
  }
1052
591
}
1053
1054
//! init WP table
1055
void  Slice::initWpScaling(const SPS *sps)
1056
0
{
1057
0
  const bool bUseHighPrecisionPredictionWeighting = false;// sps->getSpsRangeExtension().getHighPrecisionOffsetsEnabledFlag();
1058
0
  for ( int e=0 ; e<NUM_REF_PIC_LIST_01 ; e++ )
1059
0
  {
1060
0
    for ( int i=0 ; i<MAX_NUM_REF ; i++ )
1061
0
    {
1062
0
      for ( int yuv=0 ; yuv<MAX_NUM_COMPONENT ; yuv++ )
1063
0
      {
1064
0
        WPScalingParam  *pwp = &(m_weightPredTable[e][i][yuv]);
1065
0
        if ( !pwp->bPresentFlag )
1066
0
        {
1067
          // Inferring values not present :
1068
0
          pwp->iWeight = (1 << pwp->uiLog2WeightDenom);
1069
0
          pwp->iOffset = 0;
1070
0
        }
1071
1072
0
        const int offsetScalingFactor = bUseHighPrecisionPredictionWeighting ? 1 : ( 1 << ( sps->getBitDepth() - 8 ) );
1073
1074
0
        pwp->w      = pwp->iWeight;
1075
0
        pwp->o      = pwp->iOffset * offsetScalingFactor; //NOTE: This value of the ".o" variable is never used - .o is set immediately before it gets used
1076
0
        pwp->shift  = pwp->uiLog2WeightDenom;
1077
0
        pwp->round  = (pwp->uiLog2WeightDenom>=1) ? (1 << (pwp->uiLog2WeightDenom-1)) : (0);
1078
0
      }
1079
0
    }
1080
0
  }
1081
0
}
1082
1083
void PicHeader::getWpScaling(RefPicList e, int iRefIdx, WPScalingParam *&wp) const
1084
0
{
1085
0
  CHECK(e >= NUM_REF_PIC_LIST_01, "Invalid picture reference list");
1086
0
  wp = (WPScalingParam *) m_weightPredTable[e][iRefIdx];
1087
0
}
1088
1089
// ------------------------------------------------------------------------------------------------
1090
// Sequence parameter set (SPS)
1091
// ------------------------------------------------------------------------------------------------
1092
1093
1094
1095
RPLList& SPS::createRPLList( int l, int numRPL )
1096
324
{
1097
324
  m_RPLList[l].resize( numRPL );
1098
324
  m_numRPL[l] = numRPL;
1099
324
  m_rpl1IdxPresentFlag = ( m_RPLList[0].size() != m_RPLList[1].size() );
1100
324
  return m_RPLList[l];
1101
324
}
1102
1103
1104
const int SPS::m_winUnitX[] = { 1,2,2,1 };
1105
const int SPS::m_winUnitY[] = { 1,2,1,1 };
1106
1107
1108
void ChromaQpMappingTable::deriveChromaQPMappingTables()
1109
170
{
1110
488
  for (int i = 0; i < getNumQpTables(); i++)
1111
325
  {
1112
325
    const int qpBdOffsetC = m_qpBdOffset;
1113
325
    const int numPtsInCQPTableMinus1 = getNumPtsInCQPTableMinus1(i);
1114
325
    std::vector<int> qpInVal( numPtsInCQPTableMinus1 + 2 );
1115
325
    std::vector<int> qpOutVal( numPtsInCQPTableMinus1 + 2 );
1116
1117
325
    qpInVal[0] = getQpTableStartMinus26(i) + 26;
1118
325
    qpOutVal[0] = qpInVal[0];
1119
1.02k
    for (int j = 0; j <= numPtsInCQPTableMinus1; j++)
1120
704
    {
1121
704
      qpInVal[j + 1] = qpInVal[j] + getDeltaQpInValMinus1(i, j) + 1;
1122
704
      qpOutVal[j + 1] = qpOutVal[j] + getDeltaQpOutVal(i, j);
1123
704
    }
1124
1125
1.33k
    for( int j = 0; j <= numPtsInCQPTableMinus1 + 1; j++ )
1126
1.01k
    {
1127
1.01k
      CHECK(qpInVal[j]  < -qpBdOffsetC || qpInVal[j]  > MAX_QP, "qpInVal out of range");
1128
1.01k
      CHECK(qpOutVal[j] < -qpBdOffsetC || qpOutVal[j] > MAX_QP, "qpOutVal out of range");
1129
1.00k
    }
1130
1131
318
    m_chromaQpMappingTables[i].resize( MAX_QP + qpBdOffsetC + 1 );
1132
318
    m_chromaQpMappingTables[i][qpInVal[0] + qpBdOffsetC] = qpOutVal[0];   // +qpBdOffsetC, because we use a vector here, instead of a map as in VTM
1133
9.79k
    for( int k = qpInVal[0] - 1; k >= -qpBdOffsetC; k-- )
1134
9.47k
    {
1135
9.47k
      m_chromaQpMappingTables[i][k + qpBdOffsetC] = Clip3( -qpBdOffsetC, MAX_QP, m_chromaQpMappingTables[i][k + 1 + qpBdOffsetC] - 1 );
1136
9.47k
    }
1137
957
    for( int j = 0; j <= numPtsInCQPTableMinus1; j++ )
1138
639
    {
1139
639
      int sh = ( getDeltaQpInValMinus1( i, j ) + 1 ) >> 1;
1140
1.83k
      for( int k = qpInVal[j] + 1, m = 1; k <= qpInVal[j + 1]; k++, m++ )
1141
1.19k
      {
1142
1.19k
        m_chromaQpMappingTables[i][k + qpBdOffsetC] =
1143
1.19k
          m_chromaQpMappingTables[i][qpInVal[j] + qpBdOffsetC] + ( ( qpOutVal[j + 1] - qpOutVal[j] ) * m + sh ) / ( getDeltaQpInValMinus1( i, j ) + 1 );
1144
1.19k
      }
1145
639
    }
1146
11.5k
    for( int k = qpInVal[numPtsInCQPTableMinus1 + 1] + 1; k <= MAX_QP; k++ )
1147
11.2k
    {
1148
11.2k
      m_chromaQpMappingTables[i][k + qpBdOffsetC] = Clip3( -qpBdOffsetC, MAX_QP, m_chromaQpMappingTables[i][k - 1 + qpBdOffsetC] + 1 );
1149
11.2k
    }
1150
318
  }
1151
170
}
1152
1153
1154
void PPS::resetTileSliceInfo()
1155
0
{
1156
0
  m_numExpTileCols = 0;
1157
0
  m_numExpTileRows = 0;
1158
0
  m_numTileCols    = 0;
1159
0
  m_numTileRows    = 0;
1160
0
  m_numSlicesInPic = 0;
1161
0
  m_tileColumnWidth.clear();
1162
0
  m_tileRowHeight.clear();
1163
0
  m_tileColBd.clear();
1164
0
  m_tileRowBd.clear();
1165
0
  m_ctuToTileCol.clear();
1166
0
  m_ctuToTileRow.clear();
1167
0
  m_rectSlices.clear();
1168
0
  m_sliceMap.clear();
1169
0
}
1170
1171
/**
1172
 - initialize tile row/column sizes and boundaries
1173
 */
1174
void PPS::initTiles()
1175
0
{
1176
0
  int       colIdx, rowIdx;
1177
0
  int       ctuX, ctuY;
1178
  
1179
  // check explicit tile column sizes
1180
0
  uint32_t  remainingWidthInCtu  = m_picWidthInCtu;
1181
0
  for( colIdx = 0; colIdx < m_numExpTileCols; colIdx++ )
1182
0
  {
1183
0
    CHECK(m_tileColumnWidth[colIdx] > remainingWidthInCtu,    "Tile column width exceeds picture width");
1184
0
    remainingWidthInCtu -= m_tileColumnWidth[colIdx];
1185
0
  }
1186
1187
  // divide remaining picture width into uniform tile columns
1188
0
  uint32_t  uniformTileColWidth = m_tileColumnWidth[colIdx-1];
1189
0
  while( remainingWidthInCtu > 0 )
1190
0
  {
1191
0
    CHECK(colIdx >= MAX_TILE_COLS, "Number of tile columns exceeds valid range");
1192
0
    uniformTileColWidth = std::min(remainingWidthInCtu, uniformTileColWidth);
1193
0
    m_tileColumnWidth.push_back( uniformTileColWidth );
1194
0
    remainingWidthInCtu -= uniformTileColWidth;
1195
0
    colIdx++;
1196
0
  }
1197
0
  m_numTileCols = colIdx;
1198
    
1199
  // check explicit tile row sizes
1200
0
  uint32_t  remainingHeightInCtu  = m_picHeightInCtu;
1201
0
  for( rowIdx = 0; rowIdx < m_numExpTileRows; rowIdx++ )
1202
0
  {
1203
0
    CHECK(m_tileRowHeight[rowIdx] > remainingHeightInCtu,     "Tile row height exceeds picture height");
1204
0
    remainingHeightInCtu -= m_tileRowHeight[rowIdx];
1205
0
  }
1206
    
1207
  // divide remaining picture height into uniform tile rows
1208
0
  uint32_t  uniformTileRowHeight = m_tileRowHeight[rowIdx - 1];
1209
0
  while( remainingHeightInCtu > 0 )
1210
0
  {
1211
0
    uniformTileRowHeight = std::min(remainingHeightInCtu, uniformTileRowHeight);
1212
0
    m_tileRowHeight.push_back( uniformTileRowHeight );
1213
0
    remainingHeightInCtu -= uniformTileRowHeight;
1214
0
    rowIdx++;
1215
0
  }
1216
0
  m_numTileRows = rowIdx;
1217
1218
  // set left column bounaries
1219
0
  m_tileColBd.push_back( 0 );
1220
0
  for( colIdx = 0; colIdx < m_numTileCols; colIdx++ )
1221
0
  {
1222
0
    m_tileColBd.push_back( m_tileColBd[ colIdx ] + m_tileColumnWidth[ colIdx ] );
1223
0
  }
1224
  
1225
  // set top row bounaries
1226
0
  m_tileRowBd.push_back( 0 );
1227
0
  for( rowIdx = 0; rowIdx < m_numTileRows; rowIdx++ )
1228
0
  {
1229
0
    m_tileRowBd.push_back( m_tileRowBd[ rowIdx ] + m_tileRowHeight[ rowIdx ] );
1230
0
  }
1231
1232
  // set mapping between horizontal CTU address and tile column index
1233
0
  colIdx = 0;
1234
0
  for( ctuX = 0; ctuX <= m_picWidthInCtu; ctuX++ )
1235
0
  {
1236
0
    if( ctuX == m_tileColBd[ colIdx + 1 ] )
1237
0
    {
1238
0
      colIdx++;
1239
0
    }
1240
0
    m_ctuToTileCol.push_back( colIdx );
1241
0
  }
1242
  
1243
  // set mapping between vertical CTU address and tile row index
1244
0
  rowIdx = 0;
1245
0
  for( ctuY = 0; ctuY <= m_picHeightInCtu; ctuY++ )
1246
0
  {
1247
0
    if( ctuY == m_tileRowBd[ rowIdx + 1 ] )
1248
0
    {
1249
0
      rowIdx++;
1250
0
    }
1251
0
    m_ctuToTileRow.push_back( rowIdx );
1252
0
  }
1253
0
}
1254
1255
void PPS::initRectSlices()
1256
0
{
1257
0
  CHECK(m_numSlicesInPic > MAX_SLICES, "Number of slices in picture exceeds valid range");
1258
0
  m_rectSlices.resize(m_numSlicesInPic);
1259
0
}
1260
1261
/**
1262
 - initialize mapping between rectangular slices and CTUs
1263
 */
1264
void PPS::initRectSliceMap(const SPS  *sps)
1265
0
{
1266
0
  if( getSingleSlicePerSubPicFlag() )
1267
0
  {
1268
0
    CHECK (sps==nullptr, "RectSliceMap can only be initialized for slice_per_sub_pic_flag with a valid SPS");
1269
0
    m_numSlicesInPic = sps->getNumSubPics();
1270
1271
    // allocate new memory for slice list
1272
0
    CHECK(m_numSlicesInPic > MAX_SLICES, "Number of slices in picture exceeds valid range");
1273
0
    m_sliceMap.resize( m_numSlicesInPic );
1274
1275
0
    if (sps->getNumSubPics() > 1)
1276
0
    {
1277
      // Q2001 v15 equation 29
1278
0
      std::vector<uint32_t> subpicWidthInTiles;
1279
0
      std::vector<uint32_t> subpicHeightInTiles;
1280
0
      std::vector<uint32_t> subpicHeightLessThanOneTileFlag;
1281
0
      subpicWidthInTiles.resize(sps->getNumSubPics());
1282
0
      subpicHeightInTiles.resize(sps->getNumSubPics());
1283
0
      subpicHeightLessThanOneTileFlag.resize(sps->getNumSubPics());
1284
0
      for (uint32_t i = 0; i <sps->getNumSubPics(); i++)
1285
0
      {
1286
0
        uint32_t leftX = sps->getSubPicCtuTopLeftX(i);
1287
0
        uint32_t rightX = leftX + sps->getSubPicWidth(i) - 1;
1288
0
        subpicWidthInTiles[i] = m_ctuToTileCol[rightX] + 1 - m_ctuToTileCol[leftX];
1289
1290
0
        uint32_t topY = sps->getSubPicCtuTopLeftY(i);
1291
0
        uint32_t bottomY = topY + sps->getSubPicHeight(i) - 1;
1292
0
        subpicHeightInTiles[i] = m_ctuToTileRow[bottomY] + 1 - m_ctuToTileRow[topY];
1293
1294
0
        if (subpicHeightInTiles[i] == 1 && sps->getSubPicHeight(i) < m_tileRowHeight[m_ctuToTileRow[topY]] )
1295
0
        {
1296
0
          subpicHeightLessThanOneTileFlag[i] = 1;
1297
0
        }
1298
0
        else
1299
0
        {
1300
0
          subpicHeightLessThanOneTileFlag[i] = 0;
1301
0
        }
1302
0
      }
1303
1304
0
      for( int i = 0; i < m_numSlicesInPic; i++ )
1305
0
      {
1306
0
        CHECK(m_numSlicesInPic != sps->getNumSubPics(), "in single slice per subpic mode, number of slice and subpic shall be equal");
1307
0
        m_sliceMap[ i ].resetSliceMap();
1308
0
        if (subpicHeightLessThanOneTileFlag[i])
1309
0
        {
1310
0
          m_sliceMap[i].addCtusToSlice(sps->getSubPicCtuTopLeftX(i), sps->getSubPicCtuTopLeftX(i) + sps->getSubPicWidth(i),
1311
0
                                       sps->getSubPicCtuTopLeftY(i), sps->getSubPicCtuTopLeftY(i) + sps->getSubPicHeight(i), m_picWidthInCtu);
1312
0
        }
1313
0
        else
1314
0
        {
1315
0
          uint32_t tileX = m_ctuToTileCol[sps->getSubPicCtuTopLeftX(i)];
1316
0
          uint32_t tileY = m_ctuToTileRow[sps->getSubPicCtuTopLeftY(i)];
1317
0
          for (uint32_t j = 0; j< subpicHeightInTiles[i]; j++)
1318
0
          {
1319
0
            for (uint32_t k = 0; k < subpicWidthInTiles[i]; k++)
1320
0
            {
1321
0
              m_sliceMap[i].addCtusToSlice(getTileColumnBd(tileX + k), getTileColumnBd(tileX + k + 1), getTileRowBd(tileY + j), getTileRowBd(tileY + j + 1), m_picWidthInCtu);
1322
0
            }
1323
0
          }
1324
0
        }
1325
0
      }
1326
0
      subpicWidthInTiles.clear();
1327
0
      subpicHeightInTiles.clear();
1328
0
      subpicHeightLessThanOneTileFlag.clear();
1329
0
    }
1330
0
    else
1331
0
    {
1332
0
      m_sliceMap[0].resetSliceMap();
1333
0
      for (int tileY=0; tileY<m_numTileRows; tileY++)
1334
0
      {
1335
0
        for (int tileX=0; tileX<m_numTileCols; tileX++)
1336
0
        {
1337
0
          m_sliceMap[0].addCtusToSlice(getTileColumnBd(tileX), getTileColumnBd(tileX + 1),
1338
0
                                       getTileRowBd(tileY), getTileRowBd(tileY + 1), m_picWidthInCtu);
1339
0
        }
1340
0
      }
1341
0
      m_sliceMap[0].setSliceID(0);
1342
0
    }
1343
0
  }
1344
0
  else
1345
0
  {
1346
    // allocate new memory for slice list
1347
0
    CHECK(m_numSlicesInPic > MAX_SLICES, "Number of slices in picture exceeds valid range");
1348
0
    m_sliceMap.resize( m_numSlicesInPic );
1349
    // generate CTU maps for all rectangular slices in picture
1350
0
    for( uint32_t i = 0; i < m_numSlicesInPic; i++ )
1351
0
    {
1352
0
      m_sliceMap[ i ].resetSliceMap();
1353
1354
      // get position of first tile in slice
1355
0
      uint32_t tileX =  m_rectSlices[ i ].getTileIdx() % m_numTileCols;
1356
0
      uint32_t tileY =  m_rectSlices[ i ].getTileIdx() / m_numTileCols;
1357
1358
      // infer slice size for last slice in picture
1359
0
      if( i == m_numSlicesInPic-1 )
1360
0
      {
1361
0
        m_rectSlices[ i ].setSliceWidthInTiles ( m_numTileCols - tileX );
1362
0
        m_rectSlices[ i ].setSliceHeightInTiles( m_numTileRows - tileY );
1363
0
        m_rectSlices[ i ].setNumSlicesInTile( 1 );
1364
0
      }
1365
1366
      // set slice index
1367
0
      m_sliceMap[ i ].setSliceID(i);
1368
1369
      // complete tiles within a single slice case
1370
0
      if( m_rectSlices[ i ].getSliceWidthInTiles( ) > 1 || m_rectSlices[ i ].getSliceHeightInTiles( ) > 1)
1371
0
      {
1372
0
        for( uint32_t j = 0; j < m_rectSlices[ i ].getSliceHeightInTiles( ); j++ )
1373
0
        {
1374
0
          for( uint32_t k = 0; k < m_rectSlices[ i ].getSliceWidthInTiles( ); k++ )
1375
0
          {
1376
0
            m_sliceMap[ i ].addCtusToSlice( getTileColumnBd(tileX + k), getTileColumnBd(tileX + k +1),
1377
0
                                            getTileRowBd(tileY + j), getTileRowBd(tileY + j +1), m_picWidthInCtu);
1378
0
          }
1379
0
        }
1380
0
      }
1381
      // multiple slices within a single tile case
1382
0
      else
1383
0
      {
1384
0
        uint32_t  numSlicesInTile = m_rectSlices[ i ].getNumSlicesInTile( );
1385
1386
0
        uint32_t ctuY = getTileRowBd( tileY );
1387
0
        for( uint32_t j = 0; j < numSlicesInTile-1; j++ )
1388
0
        {
1389
0
          m_sliceMap[ i ].addCtusToSlice( getTileColumnBd(tileX), getTileColumnBd(tileX+1),
1390
0
                                          ctuY, ctuY + m_rectSlices[ i ].getSliceHeightInCtu(), m_picWidthInCtu);
1391
0
          ctuY += m_rectSlices[ i ].getSliceHeightInCtu();
1392
0
          i++;
1393
0
          m_sliceMap[ i ].resetSliceMap();
1394
0
          m_sliceMap[ i ].setSliceID(i);
1395
0
        }
1396
1397
        // infer slice height for last slice in tile
1398
0
        CHECK( ctuY >= getTileRowBd( tileY + 1 ), "Invalid rectangular slice signalling");
1399
0
        m_rectSlices[ i ].setSliceHeightInCtu( getTileRowBd( tileY + 1 ) - ctuY );
1400
0
        m_sliceMap[ i ].addCtusToSlice( getTileColumnBd(tileX), getTileColumnBd(tileX+1),
1401
0
                                        ctuY, getTileRowBd( tileY + 1 ), m_picWidthInCtu);
1402
0
      }
1403
0
    }
1404
0
  }
1405
  // check for valid rectangular slice map
1406
0
  checkSliceMap();
1407
0
}
1408
1409
/**
1410
- initialize mapping between subpicture and CTUs
1411
*/
1412
void PPS::initSubPic( const SPS &sps )
1413
0
{
1414
0
  if( getSubPicIdMappingPresentFlag() )
1415
0
  {
1416
    // When signalled, the number of subpictures has to match in PPS and SPS
1417
0
    CHECK( getNumSubPics() != sps.getNumSubPics(), "pps_num_subpics_minus1 shall be equal to sps_num_subpics_minus1" );
1418
0
  }
1419
0
  else
1420
0
  {
1421
    // When not signalled  set the numer equal for convenient access
1422
0
    setNumSubPics( sps.getNumSubPics() );
1423
0
  }
1424
1425
0
  CHECK( getNumSubPics() > MAX_NUM_SUB_PICS, "Number of sub-pictures in picture exceeds valid range" );
1426
0
  m_subPics.resize(getNumSubPics());
1427
1428
  // Check that no subpicture is specified outside of the conformance cropping window
1429
0
  for(int i = 0; i < sps.getNumSubPics(); i++)
1430
0
  {
1431
0
    CHECK( (sps.getSubPicCtuTopLeftX(i) * sps.getCTUSize()) >=
1432
0
          (sps.getMaxPicWidthInLumaSamples() - sps.getConformanceWindow().getWindowRightOffset() * SPS::getWinUnitX(sps.getChromaFormatIdc())),
1433
0
          "No subpicture can be located completely outside of the conformance cropping window");
1434
0
    CHECK( ((sps.getSubPicCtuTopLeftX(i) + sps.getSubPicWidth(i)) * sps.getCTUSize()) <= (sps.getConformanceWindow().getWindowLeftOffset() * SPS::getWinUnitX(sps.getChromaFormatIdc())),
1435
0
          "No subpicture can be located completely outside of the conformance cropping window" );
1436
0
    CHECK( (sps.getSubPicCtuTopLeftY(i) * sps.getCTUSize()) >=
1437
0
          (sps.getMaxPicHeightInLumaSamples()  - sps.getConformanceWindow().getWindowBottomOffset() * SPS::getWinUnitY(sps.getChromaFormatIdc())),
1438
0
          "No subpicture can be located completely outside of the conformance cropping window");
1439
0
    CHECK( ((sps.getSubPicCtuTopLeftY(i) + sps.getSubPicHeight(i)) * sps.getCTUSize()) <= (sps.getConformanceWindow().getWindowTopOffset() * SPS::getWinUnitY(sps.getChromaFormatIdc())),
1440
0
          "No subpicture can be located completely outside of the conformance cropping window");
1441
0
  }
1442
1443
  // m_ctuSize,  m_picWidthInCtu, and m_picHeightInCtu might not be initialized yet.
1444
0
  if( m_ctuSize == 0 || m_picWidthInCtu == 0 || m_picHeightInCtu == 0 )
1445
0
  {
1446
0
    m_ctuSize = sps.getCTUSize();
1447
0
    m_picWidthInCtu = (m_picWidthInLumaSamples + m_ctuSize - 1) / m_ctuSize;
1448
0
    m_picHeightInCtu = (m_picHeightInLumaSamples + m_ctuSize - 1) / m_ctuSize;
1449
0
  }
1450
0
  for( int i=0; i< getNumSubPics(); i++ )
1451
0
  {
1452
0
    m_subPics[i].setSubPicIdx(i);
1453
0
    if( sps.getSubPicIdMappingExplicitlySignalledFlag() )
1454
0
    {
1455
0
      if( m_subPicIdMappingPresentFlag )
1456
0
      {
1457
0
        m_subPics[i].setSubPicID( m_subPicId[i] );
1458
0
      }
1459
0
      else
1460
0
      {
1461
0
        m_subPics[i].setSubPicID( sps.getSubPicId(i) );
1462
0
      }
1463
0
    }
1464
0
    else
1465
0
    {
1466
0
      m_subPics[i].setSubPicID(i);
1467
0
    }
1468
0
    m_subPics[i].setSubPicCtuTopLeftX(sps.getSubPicCtuTopLeftX(i));
1469
0
    m_subPics[i].setSubPicCtuTopLeftY(sps.getSubPicCtuTopLeftY(i));
1470
0
    m_subPics[i].setSubPicWidthInCTUs(sps.getSubPicWidth(i));
1471
0
    m_subPics[i].setSubPicHeightInCTUs(sps.getSubPicHeight(i));
1472
1473
0
    uint32_t firstCTU = sps.getSubPicCtuTopLeftY(i) * m_picWidthInCtu + sps.getSubPicCtuTopLeftX(i);
1474
0
    m_subPics[i].setFirstCTUInSubPic(firstCTU);
1475
0
    uint32_t lastCTU = (sps.getSubPicCtuTopLeftY(i) + sps.getSubPicHeight(i) - 1) * m_picWidthInCtu + sps.getSubPicCtuTopLeftX(i) + sps.getSubPicWidth(i) - 1;
1476
0
    m_subPics[i].setLastCTUInSubPic(lastCTU);
1477
1478
0
    uint32_t left = sps.getSubPicCtuTopLeftX(i) * m_ctuSize;
1479
0
    m_subPics[i].setSubPicLeft(left);
1480
1481
0
    uint32_t right = std::min(m_picWidthInLumaSamples - 1, (sps.getSubPicCtuTopLeftX(i) + sps.getSubPicWidth(i)) * m_ctuSize - 1);
1482
0
    m_subPics[i].setSubPicRight(right);
1483
1484
0
    m_subPics[i].setSubPicWidthInLumaSample(right - left + 1);
1485
1486
0
    uint32_t top = sps.getSubPicCtuTopLeftY(i) * m_ctuSize;
1487
0
    m_subPics[i].setSubPicTop(top);
1488
1489
0
    uint32_t bottom = std::min(m_picHeightInLumaSamples - 1, (sps.getSubPicCtuTopLeftY(i) + sps.getSubPicHeight(i)) * m_ctuSize - 1);
1490
1491
0
    m_subPics[i].setSubPicHeightInLumaSample(bottom - top + 1);
1492
1493
0
    m_subPics[i].setSubPicBottom(bottom);
1494
1495
0
    m_subPics[i].clearCTUAddrList();
1496
1497
0
    if( m_numSlicesInPic == 1 )
1498
0
    {
1499
0
      CHECK( getNumSubPics() != 1, "only one slice in picture, but number of subpic is not one" );
1500
0
      m_subPics[i].addAllCtusInPicToSubPic(0, getPicWidthInCtu(), 0, getPicHeightInCtu(), getPicWidthInCtu());
1501
0
      m_subPics[i].setNumSlicesInSubPic(1);
1502
0
    }
1503
0
    else
1504
0
    {
1505
0
      int numSlicesInSubPic = 0;
1506
0
      int idxLastSliceInSubpic = -1;
1507
0
      int idxFirstSliceAfterSubpic = m_numSlicesInPic;
1508
0
      for( int j = 0; j < m_numSlicesInPic; j++ )
1509
0
      {
1510
0
        uint32_t ctu = m_sliceMap[j].getCtuAddrInSlice(0);
1511
0
        uint32_t ctu_x = ctu % m_picWidthInCtu;
1512
0
        uint32_t ctu_y = ctu / m_picWidthInCtu;
1513
0
        if (ctu_x >= sps.getSubPicCtuTopLeftX(i) &&
1514
0
          ctu_x < (sps.getSubPicCtuTopLeftX(i) + sps.getSubPicWidth(i)) &&
1515
0
          ctu_y >= sps.getSubPicCtuTopLeftY(i) &&
1516
0
          ctu_y < (sps.getSubPicCtuTopLeftY(i) + sps.getSubPicHeight(i)))
1517
0
        {
1518
          // add ctus in a slice to the subpicture it belongs to
1519
0
          m_subPics[i].addCTUsToSubPic(m_sliceMap[j].getCtuAddrList());
1520
0
          numSlicesInSubPic++;
1521
0
          idxLastSliceInSubpic = j;
1522
0
        }
1523
0
        else if (idxFirstSliceAfterSubpic == m_numSlicesInPic && idxLastSliceInSubpic != -1)
1524
0
        {
1525
0
          idxFirstSliceAfterSubpic = j;
1526
0
        }
1527
0
      }
1528
0
      CHECK( idxFirstSliceAfterSubpic < idxLastSliceInSubpic, "The signalling order of slices shall follow the coding order" );
1529
0
      m_subPics[i].setNumSlicesInSubPic(numSlicesInSubPic);
1530
0
    }
1531
0
    m_subPics[i].setTreatedAsPicFlag(sps.getSubPicTreatedAsPicFlag(i));
1532
0
    m_subPics[i].setloopFilterAcrossSubPicEnabledFlag(sps.getLoopFilterAcrossSubpicEnabledFlag(i));
1533
0
  }
1534
0
}
1535
1536
const SubPic& PPS::getSubPicFromPos(const Position& pos)  const
1537
0
{
1538
0
  for (int i = 0; i< m_numSubPics; i++)
1539
0
  {
1540
0
    if (m_subPics[i].isContainingPos(pos))
1541
0
    {
1542
0
      return m_subPics[i];
1543
0
    }
1544
0
  }
1545
0
  return m_subPics[0];
1546
0
}
1547
1548
const SubPic& PPS::getSubPicFromCU(const CodingUnit& cu) const
1549
0
{
1550
0
  const Position lumaPos = cu.Y().valid() ? cu.Y().pos() : recalcPosition(cu.chromaFormat, cu.chType(), CHANNEL_TYPE_LUMA, cu.blocks[cu.chType()].pos());
1551
0
  return getSubPicFromPos(lumaPos);
1552
0
}
1553
1554
uint32_t PPS::getSubPicIdxFromSubPicId( uint32_t subPicId ) const
1555
0
{
1556
0
  for (int i = 0; i < m_numSubPics; i++)
1557
0
  {
1558
0
    if(m_subPics[i].getSubPicID() == subPicId)
1559
0
    {
1560
0
      return i;
1561
0
    }
1562
0
  }
1563
0
  THROW_RECOVERABLE( "subpicture ID does not match any subpicture of the PPS" );
1564
0
}
1565
1566
void PPS::checkSliceMap()
1567
0
{
1568
0
  uint32_t i;
1569
0
  std::vector<uint32_t>  ctuList, sliceList;
1570
0
  uint32_t picSizeInCtu = getPicWidthInCtu() * getPicHeightInCtu();
1571
0
  for( i = 0; i < m_numSlicesInPic; i++ )
1572
0
  {
1573
0
    sliceList = m_sliceMap[ i ].getCtuAddrList();
1574
0
    ctuList.insert( ctuList.end(), sliceList.begin(), sliceList.end() );
1575
0
  }
1576
0
  CHECK( ctuList.size() < picSizeInCtu, "Slice map contains too few CTUs");
1577
0
  CHECK( ctuList.size() > picSizeInCtu, "Slice map contains too many CTUs");
1578
0
  std::sort( ctuList.begin(), ctuList.end() );
1579
0
  for( i = 1; i < ctuList.size(); i++ )
1580
0
  {
1581
0
    CHECK( ctuList[i] > ctuList[i-1]+1, "CTU missing in slice map");
1582
0
    CHECK( ctuList[i] == ctuList[i-1],  "CTU duplicated in slice map");
1583
0
  }
1584
0
}
1585
1586
void PPS::finalizePPSPartitioning( const SPS* pcSPS )
1587
0
{
1588
  // initialize tile/slice info for no partitioning case
1589
0
  if( getNoPicPartitionFlag() )
1590
0
  {
1591
0
    resetTileSliceInfo();
1592
0
    setLog2CtuSize( ( int ) ceil( log2( pcSPS->getCTUSize() ) ) );
1593
0
    setNumExpTileColumns( 1 );
1594
0
    setNumExpTileRows( 1 );
1595
0
    addTileColumnWidth( getPicWidthInCtu()  );
1596
0
    addTileRowHeight  ( getPicHeightInCtu() );
1597
0
    initTiles();
1598
0
    setRectSliceFlag( 1 );
1599
0
    setNumSlicesInPic( 1 );
1600
0
    initRectSlices();
1601
0
    setTileIdxDeltaPresentFlag( 0 );
1602
0
    setSliceTileIdx( 0, 0 );
1603
0
    initRectSliceMap( pcSPS );
1604
    // when no Pic partition, number of sub picture shall be less than 2
1605
0
    CHECK( getNumSubPics() >= 2, "error, no picture partitions, but have equal to or more than 2 sub pictures" );
1606
0
  }
1607
0
  else
1608
0
  {
1609
0
    CHECK( getCtuSize() != pcSPS->getCTUSize(), "PPS CTU size does not match CTU size in SPS" );
1610
0
    if( getRectSliceFlag() )
1611
0
    {
1612
0
      initRectSliceMap( pcSPS );
1613
0
    }
1614
0
  }
1615
1616
0
  initSubPic( *pcSPS );
1617
0
}
1618
1619
1620
SliceMap::SliceMap()
1621
591
{
1622
591
  m_ctuAddrInSlice.clear();
1623
591
}
1624
1625
SliceMap::~SliceMap()
1626
591
{
1627
591
  m_numCtuInSlice = 0;
1628
591
  m_ctuAddrInSlice.clear();
1629
591
}
1630
1631
/** Sorts the deltaPOC and Used by current values in the RPS based on the deltaPOC values.
1632
 *  deltaPOC values are sorted with -ve values before the +ve values.  -ve values are in decreasing order.
1633
 *  +ve values are in increasing order.
1634
 * \returns void
1635
 */
1636
1637
ReferencePictureList::ReferencePictureList()
1638
2.56k
{
1639
2.56k
  ::memset( this, 0, sizeof( *this ) );
1640
2.56k
}
1641
1642
void ReferencePictureList::clear()
1643
0
{
1644
0
  ::memset( this, 0, sizeof( *this ) );
1645
0
}
1646
1647
void ReferencePictureList::setRefPicIdentifier( int idx, int identifier, bool isLongterm, bool isInterLayerRefPic, int interLayerIdx )
1648
1.11k
{
1649
1.11k
  CHECK( idx >= MAX_NUM_REF_PICS, "RPL setRefPicIdentifier out of range (0-15)" );
1650
1.11k
  m_refPicIdentifier[idx] = identifier;
1651
1.11k
  m_isLongtermRefPic[idx] = isLongterm;
1652
1653
1.11k
  m_deltaPocMSBPresentFlag[idx] = false;
1654
1.11k
  m_deltaPOCMSBCycleLT[idx] = 0;
1655
  
1656
1.11k
  m_isInterLayerRefPic[idx] = isInterLayerRefPic;
1657
1.11k
  m_interLayerRefPicIdx[idx] = interLayerIdx;
1658
1.11k
}
1659
1660
int ReferencePictureList::getRefPicIdentifier(int idx) const
1661
0
{
1662
0
  return m_refPicIdentifier[idx];
1663
0
}
1664
1665
1666
bool ReferencePictureList::isRefPicLongterm(int idx) const
1667
0
{
1668
0
  return m_isLongtermRefPic[idx];
1669
0
}
1670
1671
void ReferencePictureList::setRefPicLongterm(int idx,bool isLongterm)
1672
0
{
1673
0
  CHECK( idx >= MAX_NUM_REF_PICS, "RPL setRefPicLongterm out of range (0-15)" );
1674
0
  m_isLongtermRefPic[idx] = isLongterm;
1675
0
}
1676
1677
void ReferencePictureList::setNumberOfShorttermPictures(int numberOfStrp)
1678
827
{
1679
827
  m_numberOfShorttermPictures = numberOfStrp;
1680
827
}
1681
1682
int ReferencePictureList::getNumberOfShorttermPictures() const
1683
0
{
1684
0
  return m_numberOfShorttermPictures;
1685
0
}
1686
1687
void ReferencePictureList::setNumberOfLongtermPictures(int numberOfLtrp)
1688
956
{
1689
956
  m_numberOfLongtermPictures = numberOfLtrp;
1690
956
}
1691
1692
int ReferencePictureList::getNumberOfLongtermPictures() const
1693
0
{
1694
0
  return m_numberOfLongtermPictures;
1695
0
}
1696
1697
void ReferencePictureList::setPOC(int idx, int POC)
1698
0
{
1699
0
  CHECK( idx >= MAX_NUM_REF_PICS, "RPL setPOC out of range (0-15)" );
1700
0
  m_POC[idx] = POC;
1701
0
}
1702
1703
int ReferencePictureList::getPOC(int idx) const
1704
0
{
1705
0
  return m_POC[idx];
1706
0
}
1707
1708
void ReferencePictureList::setDeltaPocMSBCycleLT(int idx, int x)
1709
0
{
1710
0
  CHECK( idx >= MAX_NUM_REF_PICS, "RPL setDeltaPocMSBCycleLT out of range (0-15)" );
1711
0
  m_deltaPOCMSBCycleLT[idx] = x;
1712
0
}
1713
1714
void ReferencePictureList::setDeltaPocMSBPresentFlag(int idx, bool x)
1715
0
{
1716
0
  CHECK( idx >= MAX_NUM_REF_PICS, "RPL setDeltaPocMSBPresentFlag out of range (0-15)" );
1717
0
  m_deltaPocMSBPresentFlag[idx] = x;
1718
0
}
1719
1720
void ReferencePictureList::setInterLayerRefPicIdx( int idx, int layerIdc )
1721
0
{
1722
0
  CHECK( idx >= MAX_NUM_REF_PICS, "RPL setInterLayerRefPicIdx out of range (0-15)" );
1723
0
  m_interLayerRefPicIdx[idx] = layerIdc;
1724
0
}
1725
1726
void ReferencePictureList::printRefPicInfo() const
1727
0
{
1728
0
  DTRACE(g_trace_ctx, D_RPSINFO, "RefPics = { ");
1729
0
  int numRefPic = getNumberOfShorttermPictures() + getNumberOfLongtermPictures();
1730
0
  for (int ii = 0; ii < numRefPic; ii++)
1731
0
  {
1732
0
    DTRACE(g_trace_ctx, D_RPSINFO, "%d%s ", m_refPicIdentifier[ii], (m_isLongtermRefPic[ii] == 1) ? "[LT]" : "[ST]");
1733
0
  }
1734
0
  DTRACE(g_trace_ctx, D_RPSINFO, "}\n");
1735
0
}
1736
1737
bool ReferencePictureList::findInRefPicList( const Picture* checkRefPic, int currPicPoc, int layerId ) const
1738
0
{
1739
  // loop through all pictures in the Reference Picture Set
1740
  // to see if the picture should be kept as reference picture
1741
0
  for( int i = 0; i < getNumRefEntries(); i++ )
1742
0
  {
1743
0
    if( isInterLayerRefPic( i ) )
1744
0
    {
1745
      // Diagonal inter-layer prediction is not allowed
1746
0
      CHECK( getRefPicIdentifier( i ), "ILRP identifier should be 0" );
1747
1748
0
      if( checkRefPic->poc == currPicPoc )
1749
0
      {
1750
0
        CHECK( checkRefPic->dpbReferenceMark != Picture::LongTerm, "LTRP needs long term mark" );
1751
0
        return true;
1752
0
      }
1753
0
    }
1754
0
    else if( checkRefPic->layerId == layerId )
1755
0
    {
1756
0
      if( isRefPicLongterm( i ) )
1757
0
      {
1758
0
        const int bitsForPoc = checkRefPic->cs->sps->getBitsForPOC();
1759
0
        const int curPoc     = checkRefPic->getPOC();
1760
0
        const int ltRefPoc   = calcLTRefPOC( currPicPoc, bitsForPoc, i );
1761
0
        if( checkRefPic->dpbReferenceMark == Picture::LongTerm && isLTPocEqual( curPoc, ltRefPoc, bitsForPoc, getDeltaPocMSBPresentFlag( i ) ) )
1762
0
        {
1763
0
          return true;
1764
0
        }
1765
0
      }
1766
0
      else
1767
0
      {
1768
0
        if( checkRefPic->poc == currPicPoc + getRefPicIdentifier( i ) )
1769
0
        {
1770
0
          return true;
1771
0
        }
1772
0
      }
1773
0
    }
1774
0
  }
1775
0
  return false;
1776
0
}
1777
1778
int ReferencePictureList::calcLTRefPOC( int currPoc, int bitsForPoc, int refPicIdentifier, bool pocMSBPresent, int deltaPocMSBCycle )
1779
0
{
1780
0
  const int pocCycle = 1 << bitsForPoc;
1781
0
  int64_t   ltrpPoc  = refPicIdentifier & ( pocCycle - 1 );
1782
0
  if( pocMSBPresent )
1783
0
  {
1784
    // 64 bit, because delta_poc_msb_cycle_lt * MaxPicOrderCntLsb can exceed 32 bit
1785
0
    ltrpPoc += currPoc - (int64_t) deltaPocMSBCycle * pocCycle - ( currPoc & ( pocCycle - 1 ) );
1786
0
    CHECK( ltrpPoc < std::numeric_limits<int>::min() || ltrpPoc > std::numeric_limits<int>::max(),
1787
0
           "ltrpPoc overflows 32 bit" );
1788
0
  }
1789
0
  return (int) ltrpPoc;
1790
0
}
1791
1792
int ReferencePictureList::calcLTRefPOC( int currPoc, int bitsForPoc, int refPicIdx ) const
1793
0
{
1794
0
  return calcLTRefPOC( currPoc,
1795
0
                       bitsForPoc,
1796
0
                       this->getRefPicIdentifier( refPicIdx ),
1797
0
                       this->getDeltaPocMSBPresentFlag( refPicIdx ),
1798
0
                       this->getDeltaPocMSBCycleLT( refPicIdx ) );
1799
0
}
1800
1801
bool isLTPocEqual( int poc1, int poc2, int bitsForPoc, bool msbPresent )
1802
0
{
1803
0
  if( msbPresent )
1804
0
  {
1805
0
    return poc1 == poc2;
1806
0
  }
1807
1808
0
  const int pocCycle = 1 << bitsForPoc;
1809
0
  return ( poc1 & ( pocCycle - 1 ) ) == ( poc2 & ( pocCycle - 1 ) );
1810
0
}
1811
1812
1813
ScalingList::ScalingList()
1814
441
{
1815
441
  reset();
1816
441
}
1817
1818
void ScalingList::reset()
1819
491
{
1820
491
  memset( m_scalingListDC, 0, sizeof( m_scalingListDC ) );
1821
1822
14.2k
  for (uint32_t id = 0; id < 28; id++)
1823
13.7k
  {
1824
13.7k
    const int matrixSize = ScalingList::matrixSize( id );
1825
13.7k
    m_scalingListCoef[id].assign( matrixSize * matrixSize, 0 );
1826
13.7k
  }
1827
491
}
1828
1829
void Slice::scaleRefPicList()
1830
0
{
1831
0
  const SPS* sps = getSPS();
1832
0
  const PPS* pps = getPPS();
1833
1834
0
  if( m_eSliceType == I_SLICE )
1835
0
  {
1836
0
    return;
1837
0
  }
1838
  
1839
0
  for( int refList = 0; refList < NUM_REF_PIC_LIST_01; refList++ )
1840
0
  {
1841
0
    if( refList == 1 && m_eSliceType != B_SLICE )
1842
0
    {
1843
0
      continue;
1844
0
    }
1845
1846
0
    for( int rIdx = 0; rIdx < m_aiNumRefIdx[refList]; rIdx++ )
1847
0
    {
1848
      // if rescaling is needed, otherwise just reuse the original picture pointer; it is needed for motion field, otherwise motion field
1849
      // requires a copy as well reference resampling for the whole picture is not applied at decoder
1850
1851
0
      CHECK( !m_apcRefPicList[refList][rIdx], "scaleRefPicList missing ref pic" );
1852
1853
      // the sample processing assumes the value range and planes of the current picture
1854
0
      const SPS* refSps = m_apcRefPicList[refList][rIdx]->slices[0]->getSPS();
1855
0
      CHECK( refSps->getBitDepth() != sps->getBitDepth() || refSps->getChromaFormatIdc() != sps->getChromaFormatIdc(),
1856
0
             "reference picture with a different bit depth or chroma format" );
1857
1858
0
      int xScale, yScale;
1859
0
      CU::getRprScaling( sps, pps, m_apcRefPicList[refList][rIdx]->slices[0]->getPPS(), xScale, yScale );
1860
0
      m_scalingRatio[refList][rIdx] = std::pair<int, int>( xScale, yScale );
1861
0
    }
1862
0
  }
1863
1864
  // the collocated motion field is indexed with the current picture's layout (7.4.8)
1865
0
  if( getPicHeader()->getEnableTMVPFlag() )
1866
0
  {
1867
0
    const RefPicList colList = RefPicList( isInterB() ? 1 - getColFromL0Flag() : 0 );
1868
0
    CHECK( getColRefIdx() >= getNumRefIdx( colList ), "collocated_ref_idx shall be less than NumRefIdxActive" );
1869
1870
0
    const Picture* colPic = getRefPic( colList, getColRefIdx() );
1871
0
    CHECK( colPic->isRefScaled( pps ), "the collocated picture shall have the same size and scaling window as the current picture" );
1872
0
  }
1873
0
}
1874
1875
bool             operator == (const ConstraintInfo& op1, const ConstraintInfo& op2)
1876
0
{
1877
0
  if( op1.m_intraOnlyConstraintFlag                      != op2.m_intraOnlyConstraintFlag                        ) return false;
1878
0
  if( op1.m_maxBitDepthConstraintIdc                     != op2.m_maxBitDepthConstraintIdc                       ) return false;
1879
0
  if( op1.m_maxChromaFormatConstraintIdc                 != op2.m_maxChromaFormatConstraintIdc                   ) return false;
1880
0
  if( op1.m_onePictureOnlyConstraintFlag                 != op2.m_onePictureOnlyConstraintFlag                   ) return false;
1881
0
  if( op1.m_lowerBitRateConstraintFlag                   != op2.m_lowerBitRateConstraintFlag                     ) return false;
1882
0
  if (op1.m_allLayersIndependentConstraintFlag           != op2.m_allLayersIndependentConstraintFlag             ) return false;
1883
0
  if (op1.m_noMrlConstraintFlag                          != op2.m_noMrlConstraintFlag                            ) return false;
1884
0
  if (op1.m_noIspConstraintFlag                          != op2.m_noIspConstraintFlag                            ) return false;
1885
0
  if (op1.m_noMipConstraintFlag                          != op2.m_noMipConstraintFlag                            ) return false;
1886
0
  if (op1.m_noLfnstConstraintFlag                        != op2.m_noLfnstConstraintFlag                          ) return false;
1887
0
  if (op1.m_noMmvdConstraintFlag                         != op2.m_noMmvdConstraintFlag                           ) return false;
1888
0
  if (op1.m_noSmvdConstraintFlag                         != op2.m_noSmvdConstraintFlag                           ) return false;
1889
0
  if (op1.m_noProfConstraintFlag                         != op2.m_noProfConstraintFlag                           ) return false;
1890
0
  if (op1.m_noPaletteConstraintFlag                      != op2.m_noPaletteConstraintFlag                        ) return false;
1891
0
  if (op1.m_noActConstraintFlag                          != op2.m_noActConstraintFlag                            ) return false;
1892
0
  if (op1.m_noLmcsConstraintFlag                         != op2.m_noLmcsConstraintFlag                           ) return false;
1893
0
  if (op1.m_noExplicitScaleListConstraintFlag            != op2.m_noExplicitScaleListConstraintFlag              ) return false;
1894
0
  if (op1.m_noVirtualBoundaryConstraintFlag              != op2.m_noVirtualBoundaryConstraintFlag                ) return false;
1895
0
  if (op1.m_noChromaQpOffsetConstraintFlag               != op2.m_noChromaQpOffsetConstraintFlag                 ) return false;
1896
0
  if (op1.m_noRprConstraintFlag                          != op2.m_noRprConstraintFlag                            ) return false;
1897
0
  if (op1.m_noResChangeInClvsConstraintFlag              != op2.m_noResChangeInClvsConstraintFlag                ) return false;
1898
0
  if (op1.m_noMttConstraintFlag                          != op2.m_noMttConstraintFlag                            ) return false;
1899
0
  if( op1.m_noQtbttDualTreeIntraConstraintFlag           != op2.m_noQtbttDualTreeIntraConstraintFlag             ) return false;
1900
0
  if( op1.m_noPartitionConstraintsOverrideConstraintFlag != op2.m_noPartitionConstraintsOverrideConstraintFlag   ) return false;
1901
0
  if( op1.m_noSaoConstraintFlag                          != op2.m_noSaoConstraintFlag                            ) return false;
1902
0
  if( op1.m_noAlfConstraintFlag                          != op2.m_noAlfConstraintFlag                            ) return false;
1903
0
  if( op1.m_noCCAlfConstraintFlag                        != op2.m_noCCAlfConstraintFlag                          ) return false;
1904
0
  if (op1.m_noWeightedPredictionConstraintFlag           != op2.m_noWeightedPredictionConstraintFlag             ) return false;
1905
0
  if( op1.m_noRefWraparoundConstraintFlag                != op2.m_noRefWraparoundConstraintFlag                  ) return false;
1906
0
  if( op1.m_noTemporalMvpConstraintFlag                  != op2.m_noTemporalMvpConstraintFlag                    ) return false;
1907
0
  if( op1.m_noSbtmvpConstraintFlag                       != op2.m_noSbtmvpConstraintFlag                         ) return false;
1908
0
  if( op1.m_noAmvrConstraintFlag                         != op2.m_noAmvrConstraintFlag                           ) return false;
1909
0
  if( op1.m_noBdofConstraintFlag                         != op2.m_noBdofConstraintFlag                           ) return false;
1910
0
  if( op1.m_noDmvrConstraintFlag                         != op2.m_noDmvrConstraintFlag                           ) return false;
1911
0
  if( op1.m_noCclmConstraintFlag                         != op2.m_noCclmConstraintFlag                           ) return false;
1912
0
  if( op1.m_noMtsConstraintFlag                          != op2.m_noMtsConstraintFlag                            ) return false;
1913
0
  if( op1.m_noSbtConstraintFlag                          != op2.m_noSbtConstraintFlag                            ) return false;
1914
0
  if( op1.m_noAffineMotionConstraintFlag                 != op2.m_noAffineMotionConstraintFlag                   ) return false;
1915
0
  if( op1.m_noBcwConstraintFlag                          != op2.m_noBcwConstraintFlag                            ) return false;
1916
0
  if( op1.m_noIbcConstraintFlag                          != op2.m_noIbcConstraintFlag                            ) return false;
1917
0
  if( op1.m_noCiipConstraintFlag                         != op2.m_noCiipConstraintFlag                           ) return false;
1918
0
  if( op1.m_noLadfConstraintFlag                         != op2.m_noLadfConstraintFlag                           ) return false;
1919
0
  if( op1.m_noTransformSkipConstraintFlag                != op2.m_noTransformSkipConstraintFlag                  ) return false;
1920
0
  if( op1.m_noBDPCMConstraintFlag                        != op2.m_noBDPCMConstraintFlag                          ) return false;
1921
0
  if( op1.m_noJointCbCrConstraintFlag                    != op2.m_noJointCbCrConstraintFlag                      ) return false;
1922
0
  if( op1.m_noQpDeltaConstraintFlag                      != op2.m_noQpDeltaConstraintFlag                        ) return false;
1923
0
  if( op1.m_noDepQuantConstraintFlag                     != op2.m_noDepQuantConstraintFlag                       ) return false;
1924
0
  if( op1.m_noSignDataHidingConstraintFlag               != op2.m_noSignDataHidingConstraintFlag                 ) return false;
1925
0
  if( op1.m_noTrailConstraintFlag                        != op2.m_noTrailConstraintFlag                          ) return false;
1926
0
  if( op1.m_noStsaConstraintFlag                         != op2.m_noStsaConstraintFlag                           ) return false;
1927
0
  if( op1.m_noRaslConstraintFlag                         != op2.m_noRaslConstraintFlag                           ) return false;
1928
0
  if( op1.m_noRadlConstraintFlag                         != op2.m_noRadlConstraintFlag                           ) return false;
1929
0
  if( op1.m_noIdrConstraintFlag                          != op2.m_noIdrConstraintFlag                            ) return false;
1930
0
  if( op1.m_noCraConstraintFlag                          != op2.m_noCraConstraintFlag                            ) return false;
1931
0
  if( op1.m_noGdrConstraintFlag                          != op2.m_noGdrConstraintFlag                            ) return false;
1932
0
  if( op1.m_noApsConstraintFlag                          != op2.m_noApsConstraintFlag                            ) return false;
1933
0
  return true;
1934
0
}
1935
bool             operator != (const ConstraintInfo& op1, const ConstraintInfo& op2)
1936
0
{
1937
0
  return !(op1 == op2);
1938
0
}
1939
1940
bool             operator == (const ProfileTierLevel& op1, const ProfileTierLevel& op2)
1941
0
{
1942
0
  if (op1.m_tierFlag        != op2.m_tierFlag) return false;
1943
0
  if (op1.m_profileIdc      != op2.m_profileIdc) return false;
1944
0
  if (op1.m_numSubProfile   != op2.m_numSubProfile) return false;
1945
0
  if (op1.m_levelIdc        != op2.m_levelIdc) return false;
1946
0
  if (op1.m_frameOnlyConstraintFlag != op2.m_frameOnlyConstraintFlag) return false;
1947
0
  if (op1.m_multiLayerEnabledFlag   != op2.m_multiLayerEnabledFlag) return false;
1948
0
  if (op1.m_constraintInfo  != op2.m_constraintInfo) return false;
1949
0
  if (op1.m_subProfileIdc   != op2.m_subProfileIdc) return false;
1950
1951
0
  for (int i = 0; i < MAX_TLAYER - 1; i++)
1952
0
  {
1953
0
    if (op1.m_subLayerLevelPresentFlag[i] != op2.m_subLayerLevelPresentFlag[i])
1954
0
    {
1955
0
      return false;
1956
0
    }
1957
0
  }
1958
0
  for (int i = 0; i < MAX_TLAYER; i++)
1959
0
  {
1960
0
    if (op1.m_subLayerLevelIdc[i] != op2.m_subLayerLevelIdc[i])
1961
0
    {
1962
0
      return false;
1963
0
    }
1964
0
  }
1965
0
  return true;
1966
0
}
1967
bool             operator != (const ProfileTierLevel& op1, const ProfileTierLevel& op2)
1968
0
{
1969
0
  return !(op1 == op2);
1970
0
}
1971
1972
uint32_t
1973
LevelTierFeatures::getMaxPicWidthInLumaSamples()  const
1974
0
{
1975
0
  return uint32_t(sqrt(maxLumaPs*8.0));
1976
0
}
1977
1978
uint32_t
1979
LevelTierFeatures::getMaxPicHeightInLumaSamples() const
1980
0
{
1981
0
  return uint32_t(sqrt(maxLumaPs*8.0));
1982
0
}
1983
1984
static const uint64_t MAX_CNFUINT64 = std::numeric_limits<uint64_t>::max();
1985
1986
static const LevelTierFeatures mainLevelTierInfo[] =
1987
{
1988
      //  level,       maxlumaps,      maxcpb[tier],,  maxSlicesPerAu,maxTilesPerAu,cols, maxLumaSr,       maxBr[tier],,    minCr[tier],,
1989
    { vvdecLevel::VVDEC_LEVEL1  ,    36864, {      350,        0 },       16,        1,        1,     552960ULL, {     128,        0 }, { 2, 2} },
1990
    { vvdecLevel::VVDEC_LEVEL2  ,   122880, {     1500,        0 },       16,        1,        1,    3686400ULL, {    1500,        0 }, { 2, 2} },
1991
    { vvdecLevel::VVDEC_LEVEL2_1,   245760, {     3000,        0 },       20,        1,        1,    7372800ULL, {    3000,        0 }, { 2, 2} },
1992
    { vvdecLevel::VVDEC_LEVEL3  ,   552960, {     6000,        0 },       30,        4,        2,   16588800ULL, {    6000,        0 }, { 2, 2} },
1993
    { vvdecLevel::VVDEC_LEVEL3_1,   983040, {    10000,        0 },       40,        9,        3,   33177600ULL, {   10000,        0 }, { 2, 2} },
1994
    { vvdecLevel::VVDEC_LEVEL4  ,  2228224, {    12000,    30000 },       75,       25,        5,   66846720ULL, {   12000,    30000 }, { 4, 4} },
1995
    { vvdecLevel::VVDEC_LEVEL4_1,  2228224, {    20000,    50000 },       75,       25,        5,  133693440ULL, {   20000,    50000 }, { 4, 4} },
1996
    { vvdecLevel::VVDEC_LEVEL5  ,  8912896, {    25000,   100000 },      200,      110,       10,  267386880ULL, {   25000,   100000 }, { 6, 4} },
1997
    { vvdecLevel::VVDEC_LEVEL5_1,  8912896, {    40000,   160000 },      200,      110,       10,  534773760ULL, {   40000,   160000 }, { 8, 4} },
1998
    { vvdecLevel::VVDEC_LEVEL5_2,  8912896, {    60000,   240000 },      200,      110,       10, 1069547520ULL, {   60000,   240000 }, { 8, 4} },
1999
    { vvdecLevel::VVDEC_LEVEL6  , 35651584, {    80000,   240000 },      600,      440,       20, 1069547520ULL, {   60000,   240000 }, { 8, 4} },
2000
    { vvdecLevel::VVDEC_LEVEL6_1, 35651584, {   120000,   480000 },      600,      440,       20, 2139095040ULL, {  120000,   480000 }, { 8, 4} },
2001
    { vvdecLevel::VVDEC_LEVEL6_2, 35651584, {   180000,   800000 },      600,      440,       20, 4278190080ULL, {  240000,   800000 }, { 8, 4} },
2002
    { vvdecLevel::VVDEC_LEVEL15_5, MAX_UINT,{ MAX_UINT, MAX_UINT }, MAX_UINT, MAX_UINT, MAX_UINT, MAX_CNFUINT64, {MAX_UINT, MAX_UINT }, { 0, 0} },
2003
    { vvdecLevel::VVDEC_LEVEL_NONE    }
2004
};
2005
2006
static const ProfileFeatures validProfiles[] = {
2007
// profile, pNameString, maxBitDepth, maxChrFmt, lvl15.5, cpbvcl, cpbnal, fcf*1000, mincr*100, levelInfo
2008
// most constrained profiles must appear first.
2009
  { Profile::MAIN_10_STILL_PICTURE, "Main_10_Still_Picture", 10, CHROMA_420, true, 1000, 1100, 1875, 100,
2010
    mainLevelTierInfo, true },
2011
  { Profile::MULTILAYER_MAIN_10_STILL_PICTURE, "Multilayer_Main_10_Still_Picture", 10, CHROMA_420, true, 1000, 1100,
2012
    1875, 100, mainLevelTierInfo, true },
2013
  { Profile::MAIN_10_444_STILL_PICTURE, "Main_444_10_Still_Picture", 10, CHROMA_444, true, 2500, 2750, 3750, 75,
2014
    mainLevelTierInfo, true },
2015
  { Profile::MULTILAYER_MAIN_10_444_STILL_PICTURE, "Multilayer_Main_444_10_Still_Picture", 10, CHROMA_444, true, 2500,
2016
    2750, 3750, 75, mainLevelTierInfo, true },
2017
  { Profile::MAIN_10, "Main_10", 10, CHROMA_420, false, 1000, 1100, 1875, 100, mainLevelTierInfo, false },
2018
  { Profile::MULTILAYER_MAIN_10, "Multilayer_Main_10", 10, CHROMA_420, false, 1000, 1100, 1875, 100, mainLevelTierInfo,
2019
    false },
2020
  { Profile::MAIN_10_444, "Main_444_10", 10, CHROMA_444, false, 2500, 2750, 3750, 75, mainLevelTierInfo, false },
2021
  { Profile::MULTILAYER_MAIN_10_444, "Multilayer_Main_444_10", 10, CHROMA_444, false, 2500, 2750, 3750, 75,
2022
    mainLevelTierInfo, false },
2023
  { Profile::NONE, 0 },
2024
};
2025
2026
const ProfileFeatures *ProfileFeatures::getProfileFeatures(const Profile::Name p)
2027
8
{
2028
8
  int i;
2029
62
  for (i = 0; validProfiles[i].profile != Profile::NONE; i++)
2030
56
  {
2031
56
    if (validProfiles[i].profile == p)
2032
2
    {
2033
2
      return &validProfiles[i];
2034
2
    }
2035
56
  }
2036
2037
6
  return &validProfiles[i];
2038
8
}
2039
2040
void
2041
ProfileLevelTierFeatures::extractPTLInformation(const SPS &sps)
2042
0
{
2043
0
  const ProfileTierLevel &spsPtl =*(sps.getProfileTierLevel());
2044
2045
0
  m_tier = spsPtl.getTierFlag();
2046
2047
  // Identify the profile from the profile Idc, and possibly other constraints.
2048
0
  for(int32_t i=0; validProfiles[i].profile != Profile::NONE; i++)
2049
0
  {
2050
0
    if (spsPtl.getProfileIdc() == validProfiles[i].profile)
2051
0
    {
2052
0
      m_pProfile = &(validProfiles[i]);
2053
0
      break;
2054
0
    }
2055
0
  }
2056
2057
0
  if (m_pProfile != 0)
2058
0
  {
2059
    // Now identify the level:
2060
0
    const LevelTierFeatures *pLTF  = m_pProfile->pLevelTiersListInfo;
2061
0
    const vvdecLevel spsLevelName  = spsPtl.getLevelIdc();
2062
0
    if (spsLevelName!=vvdecLevel::VVDEC_LEVEL15_5 || m_pProfile->canUseLevel15p5)
2063
0
    {
2064
0
      for(int i=0; pLTF[i].level!=vvdecLevel::VVDEC_LEVEL_NONE; i++)
2065
0
      {
2066
0
        if (pLTF[i].level == spsLevelName)
2067
0
        {
2068
0
          m_pLevelTier = &(pLTF[i]);
2069
0
        }
2070
0
      }
2071
0
    }
2072
0
  }
2073
0
}
2074
2075
uint64_t ProfileLevelTierFeatures::getCpbSizeInBits() const
2076
0
{
2077
0
  return (m_pLevelTier!=0 && m_pProfile!=0) ? uint64_t(m_pProfile->cpbVclFactor) * m_pLevelTier->maxCpb[m_tier?1:0] : uint64_t(0);
2078
0
}
2079
2080
uint32_t ProfileLevelTierFeatures::getMaxDpbSize( uint32_t picSizeMaxInSamplesY ) const
2081
0
{
2082
0
  const uint32_t maxDpbPicBuf = 8;
2083
0
  uint32_t       maxDpbSize;
2084
2085
0
  if (m_pLevelTier->level == vvdecLevel::VVDEC_LEVEL15_5)
2086
0
  {
2087
    // maxDpbSize is unconstrained in this case
2088
0
    maxDpbSize = std::numeric_limits<uint32_t>::max();
2089
0
  }
2090
0
  else if (2 * picSizeMaxInSamplesY <= m_pLevelTier->maxLumaPs)
2091
0
  {
2092
0
    maxDpbSize = 2 * maxDpbPicBuf;
2093
0
  }
2094
0
  else if (3 * picSizeMaxInSamplesY <= 2 * m_pLevelTier->maxLumaPs)
2095
0
  {
2096
0
    maxDpbSize = 3 * maxDpbPicBuf / 2;
2097
0
  }
2098
0
  else
2099
0
  {
2100
0
    maxDpbSize = maxDpbPicBuf;
2101
0
  }
2102
2103
0
  return maxDpbSize;
2104
0
}
2105
2106
#if ENABLE_TRACING
2107
void xTraceVPSHeader()
2108
{
2109
  DTRACE( g_trace_ctx, D_HEADER, "=========== Video Parameter Set     ===========\n" );
2110
}
2111
void xTraceDCIHeader()
2112
{
2113
  DTRACE( g_trace_ctx, D_HEADER, "=========== DCI     ===========\n" );
2114
}
2115
void xTraceSPSHeader()
2116
{
2117
  DTRACE( g_trace_ctx, D_HEADER, "=========== Sequence Parameter Set  ===========\n" );
2118
}
2119
2120
void xTracePPSHeader()
2121
{
2122
  DTRACE( g_trace_ctx, D_HEADER, "=========== Picture Parameter Set  ===========\n" );
2123
}
2124
2125
void xTraceAPSHeader()
2126
{
2127
  DTRACE(g_trace_ctx, D_HEADER, "=========== Adaptation Parameter Set  ===========\n");
2128
}
2129
2130
void xTracePictureHeader()
2131
{
2132
  DTRACE( g_trace_ctx, D_HEADER, "=========== Picture Header ===========\n" );
2133
}
2134
2135
void xTraceSliceHeader()
2136
{
2137
  DTRACE( g_trace_ctx, D_HEADER, "=========== Slice ===========\n" );
2138
}
2139
2140
void xTraceAccessUnitDelimiter()
2141
{
2142
  DTRACE( g_trace_ctx, D_HEADER, "=========== Access Unit Delimiter ===========\n" );
2143
}
2144
#endif
2145
2146
}