Coverage Report

Created: 2026-12-01 06:52

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/work/vvenc/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) 2019-2026, Fraunhofer-Gesellschaft zur Förderung der angewandten Forschung e.V. & The VVenC 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
44
/** \file     Slice.cpp
45
    \brief    slice header and SPS class
46
*/
47
48
#include "CommonDef.h"
49
#include "Unit.h"
50
#include "Slice.h"
51
#include "Picture.h"
52
#include "UnitTools.h"
53
#include "dtrace_next.h"
54
55
//! \ingroup CommonLib
56
//! \{
57
58
namespace vvenc {
59
60
Slice::Slice()
61
1.43k
  : ppsId                               ( -1 )
62
//  , picOutputFlag                       ( true )
63
1.43k
  , poc                                 ( 0 )
64
1.43k
  , lastIDR                             ( 0 )
65
1.43k
  , prevGDRInSameLayerPOC               ( 0 )
66
1.43k
  , associatedIRAP                      ( 0 )
67
1.43k
  , associatedIRAPType                  ( VVENC_NAL_UNIT_INVALID )
68
1.43k
  , enableDRAPSEI                       ( false )
69
1.43k
  , useLTforDRAP                        ( false )
70
1.43k
  , isDRAP                              ( false )
71
1.43k
  , latestDRAPPOC                       ( 0 )
72
1.43k
  , colourPlaneId                       ( 0 )
73
1.43k
  , pictureHeaderInSliceHeader          ( true )
74
1.43k
  , nuhLayerId                          ( 0 )
75
1.43k
  , nalUnitType                         ( VVENC_NAL_UNIT_CODED_SLICE_IDR_W_RADL )
76
1.43k
  , sliceType                           ( VVENC_I_SLICE )
77
1.43k
  , sliceQp                             ( 0 )
78
1.43k
  , chromaQpAdjEnabled                  ( false )
79
1.43k
  , explicitScalingListUsed             ( 0 )
80
1.43k
  , deblockingFilterDisable             ( false )
81
1.43k
  , deblockingFilterOverride            ( false )
82
1.43k
  , deblockingFilterBetaOffsetDiv2      { 0 }
83
1.43k
  , deblockingFilterTcOffsetDiv2        { 0 }
84
1.43k
  , depQuantEnabled                     ( false )
85
1.43k
  , signDataHidingEnabled               ( false )
86
1.43k
  , tsResidualCodingDisabled            ( false )
87
1.43k
  , pendingRasInit                      ( false )
88
1.43k
  , checkLDC                            ( false )
89
1.43k
  , biDirPred                           ( false )
90
1.43k
  , lmChromaCheckDisable                { false }
91
1.43k
  , symRefIdx                           { -1, -1 }
92
1.43k
  , vps                                 ( nullptr )
93
1.43k
  , dci                                 ( nullptr )
94
1.43k
  , sps                                 ( nullptr )
95
1.43k
  , pps                                 ( nullptr )
96
1.43k
  , pic                                 ( nullptr )
97
1.43k
  , picHeader                           ( nullptr )
98
1.43k
  , colFromL0Flag                       ( true )
99
1.43k
  , colRefIdx                           ( 0 )
100
1.43k
  , TLayer                              ( 0 )
101
1.43k
  , TLayerSwitchingFlag                 ( false )
102
1.43k
  , independentSliceIdx                 ( 0 )
103
1.43k
  , cabacInitFlag                       ( false )
104
1.43k
  , sliceSubPicId                       ( 0 )
105
1.43k
  , encCABACTableIdx                    ( VVENC_I_SLICE )
106
1.43k
  , numAps                     ( 0 )
107
1.43k
  , chromaApsId                ( -1 )
108
1.43k
  , ccAlfCbEnabled             ( false )
109
1.43k
  , ccAlfCrEnabled             ( false )
110
1.43k
  , ccAlfCbApsId               ( -1 )
111
1.43k
  , ccAlfCrApsId               ( -1 )
112
1.43k
  , isLossless                          ( false )
113
1.43k
{
114
1.43k
  ::memset( saoEnabled,              0, sizeof( saoEnabled ) );
115
1.43k
  ::memset( numRefIdx,               0, sizeof( numRefIdx ) );
116
1.43k
  ::memset( sliceChromaQpDelta,      0, sizeof( sliceChromaQpDelta ) );
117
1.43k
  ::memset( lambdas,                 0, sizeof( lambdas ) );
118
1.43k
  ::memset( alfEnabled,              0, sizeof( alfEnabled ) );
119
1.43k
  ::memset( alfAps,                  0, sizeof( alfAps ) );
120
1.43k
  ::memset( refPicList,              0, sizeof( refPicList ) );
121
1.43k
  ::memset( refPOCList,              0, sizeof( refPOCList ) );
122
1.43k
  ::memset( isUsedAsLongTerm,        0, sizeof( isUsedAsLongTerm ) );
123
1.43k
  ::memset( ccAlfFilterControl,      0, sizeof( ccAlfFilterControl ) );
124
125
24.3k
  for ( int idx = 0; idx < MAX_NUM_REF; idx++ )
126
22.9k
  {
127
22.9k
    list1IdxToList0Idx[idx] = -1;
128
22.9k
  }
129
130
4.29k
  for ( int idx = 0; idx < NUM_REF_PIC_LIST_01; idx++ )
131
2.86k
  {
132
2.86k
    rpl[idx]                = nullptr;
133
2.86k
    rplIdx[idx]             = -1;
134
2.86k
  }
135
  
136
1.43k
  resetWpScaling();
137
1.43k
}
138
139
Slice::~Slice()
140
1.43k
{
141
1.43k
}
142
143
144
void Slice::resetSlicePart()
145
0
{
146
0
  colFromL0Flag        = true;
147
0
  colRefIdx            = 0;
148
0
  checkLDC             = false;
149
0
  biDirPred            = false;
150
0
  symRefIdx[0]         = -1;
151
0
  symRefIdx[1]         = -1;
152
0
  cabacInitFlag        = false;
153
154
0
  substreamSizes.clear();
155
156
0
  ::memset( numRefIdx,           0, sizeof( numRefIdx ) );
157
0
  ::memset( sliceChromaQpDelta,  0, sizeof( sliceChromaQpDelta ) );
158
0
  ::memset( lambdas,             0, sizeof( lambdas ) );
159
0
  ::memset( alfEnabled,          0, sizeof( alfEnabled ) );
160
161
0
  ccAlfFilterParam.reset();
162
0
  ccAlfCbEnabled = false;
163
0
  ccAlfCrEnabled = false;
164
165
0
  sliceMap = SliceMap();
166
0
}
167
168
void Slice::setDefaultClpRng( const SPS& sps )
169
1.43k
{
170
1.43k
  CHECK( sps.bitDepths[CH_L] != sps.bitDepths[CH_C], "Different luma/chroma bitdepths not supported!" );
171
172
1.43k
  clpRngs.bd = sps.bitDepths[CH_L];
173
1.43k
}
174
175
176
bool Slice::getRapPicFlag() const
177
0
{
178
0
  return nalUnitType == VVENC_NAL_UNIT_CODED_SLICE_IDR_W_RADL
179
0
      || nalUnitType == VVENC_NAL_UNIT_CODED_SLICE_IDR_N_LP
180
0
      || nalUnitType == VVENC_NAL_UNIT_CODED_SLICE_CRA;
181
0
}
182
183
184
void  Slice::sortPicList        (PicList& rcListPic)
185
0
{
186
0
  Picture*    picExtract;
187
0
  Picture*    picInsert;
188
189
0
  PicList::iterator    iterPicExtract;
190
0
  PicList::iterator    iterPicExtract_1;
191
0
  PicList::iterator    iterPicInsert;
192
193
0
  for (int i = 1; i < (int)(rcListPic.size()); i++)
194
0
  {
195
0
    iterPicExtract = rcListPic.begin();
196
0
    for (int j = 0; j < i; j++)
197
0
    {
198
0
      iterPicExtract++;
199
0
    }
200
0
    picExtract = *(iterPicExtract);
201
202
0
    iterPicInsert = rcListPic.begin();
203
0
    while (iterPicInsert != iterPicExtract)
204
0
    {
205
0
      picInsert = *(iterPicInsert);
206
0
      if (picInsert->getPOC() >= picExtract->getPOC())
207
0
      {
208
0
        break;
209
0
      }
210
211
0
      iterPicInsert++;
212
0
    }
213
214
0
    iterPicExtract_1 = iterPicExtract;    iterPicExtract_1++;
215
216
    //  swap iterPicExtract and iterPicInsert, iterPicExtract = curr. / iterPicInsert = insertion position
217
0
    rcListPic.insert( iterPicInsert, iterPicExtract, iterPicExtract_1 );
218
0
    rcListPic.erase( iterPicExtract );
219
0
  }
220
0
}
221
222
223
Picture* Slice::xGetLongTermRefPic( const PicList& rcListPic, int poc, bool pocHasMsb)
224
0
{
225
0
  PicList::const_iterator  iterPic = rcListPic.begin();
226
0
  Picture*           picCand = *(iterPic);
227
0
  Picture*           pcStPic = picCand;
228
229
0
  int pocCycle = 1 << sps->bitsForPOC;
230
0
  if (!pocHasMsb)
231
0
  {
232
0
    poc = poc & (pocCycle - 1);
233
0
  }
234
235
0
  while ( iterPic != rcListPic.end() )
236
0
  {
237
0
    picCand = *(iterPic);
238
0
    if (picCand && picCand->poc != this->poc && picCand->isReferenced)
239
0
    {
240
0
      int picPoc = picCand->poc;
241
0
      if (!pocHasMsb)
242
0
      {
243
0
        picPoc = picPoc & (pocCycle - 1);
244
0
      }
245
246
0
      if (poc == picPoc)
247
0
      {
248
0
        if(picCand->isLongTerm)
249
0
        {
250
0
          return picCand;
251
0
        }
252
253
0
        pcStPic = picCand;
254
0
        break;
255
0
      }
256
0
    }
257
258
0
    iterPic++;
259
0
  }
260
261
0
  return pcStPic;
262
0
}
263
264
void Slice::setRefPOCList       ()
265
1.43k
{
266
4.29k
  for (int iDir = 0; iDir < NUM_REF_PIC_LIST_01; iDir++)
267
2.86k
  {
268
2.86k
    for (int iNumRefIdx = 0; iNumRefIdx < numRefIdx[iDir]; iNumRefIdx++)
269
0
    {
270
0
      refPOCList[iDir][iNumRefIdx] = refPicList[iDir][iNumRefIdx]->getPOC();
271
0
    }
272
2.86k
  }
273
274
1.43k
}
275
276
void Slice::setSMVDParam()
277
1.43k
{
278
1.43k
  if ( sps->SMVD && checkLDC == false && picHeader->mvdL1Zero == false )
279
1.43k
  {
280
1.43k
    int currPOC  = poc;
281
1.43k
    int forwardPOC = poc;
282
1.43k
    int backwardPOC = poc;
283
1.43k
    int ref = 0;
284
1.43k
    int refIdx0 = -1;
285
1.43k
    int refIdx1 = -1;
286
287
    // search nearest forward POC in List 0
288
1.43k
    for (ref = 0; ref < numRefIdx[REF_PIC_LIST_0]; ref++)
289
0
    {
290
0
      const int refPoc = getRefPic(REF_PIC_LIST_0, ref)->getPOC();
291
0
      const bool isRefLongTerm = getRefPic(REF_PIC_LIST_0, ref)->isLongTerm;
292
0
      if (refPoc < currPOC && (refPoc > forwardPOC || refIdx0 == -1) && !isRefLongTerm)
293
0
      {
294
0
        forwardPOC = refPoc;
295
0
        refIdx0 = ref;
296
0
      }
297
0
    }
298
299
    // search nearest backward POC in List 1
300
1.43k
    for (ref = 0; ref < numRefIdx[REF_PIC_LIST_1]; ref++)
301
0
    {
302
0
      const int refPoc = getRefPic(REF_PIC_LIST_1, ref)->getPOC();
303
0
      const bool isRefLongTerm = getRefPic(REF_PIC_LIST_1, ref)->isLongTerm;
304
0
      if (refPoc > currPOC && (refPoc < backwardPOC || refIdx1 == -1) && !isRefLongTerm)
305
0
      {
306
0
        backwardPOC = refPoc;
307
0
        refIdx1 = ref;
308
0
      }
309
0
    }
310
311
1.43k
    if (!(forwardPOC < currPOC && backwardPOC > currPOC))
312
1.43k
    {
313
1.43k
      forwardPOC = currPOC;
314
1.43k
      backwardPOC = currPOC;
315
1.43k
      refIdx0 = -1;
316
1.43k
      refIdx1 = -1;
317
318
      // search nearest backward POC in List 0
319
1.43k
      for (ref = 0; ref < numRefIdx[REF_PIC_LIST_0]; ref++)
320
0
      {
321
0
        const int refPoc = getRefPic(REF_PIC_LIST_0, ref)->getPOC();
322
0
        const bool isRefLongTerm = getRefPic(REF_PIC_LIST_0, ref)->isLongTerm;
323
0
        if (refPoc > currPOC && (refPoc < backwardPOC || refIdx0 == -1) && !isRefLongTerm)
324
0
        {
325
0
          backwardPOC = refPoc;
326
0
          refIdx0 = ref;
327
0
        }
328
0
      }
329
330
      // search nearest forward POC in List 1
331
1.43k
      for (ref = 0; ref < numRefIdx[REF_PIC_LIST_1]; ref++)
332
0
      {
333
0
        const int refPoc = getRefPic(REF_PIC_LIST_1, ref)->getPOC();
334
0
        const bool isRefLongTerm = getRefPic(REF_PIC_LIST_1, ref)->isLongTerm;
335
0
        if (refPoc < currPOC && (refPoc > forwardPOC || refIdx1 == -1) && !isRefLongTerm)
336
0
        {
337
0
          forwardPOC = refPoc;
338
0
          refIdx1 = ref;
339
0
        }
340
0
      }
341
1.43k
    }
342
343
1.43k
    if (forwardPOC < currPOC && backwardPOC > currPOC)
344
0
    {
345
0
      biDirPred    = true;
346
0
      symRefIdx[0] = refIdx0;
347
0
      symRefIdx[1] = refIdx1;
348
0
      return;
349
0
    }
350
1.43k
  }
351
352
1.43k
  biDirPred    = false;
353
1.43k
  symRefIdx[0] = -1;
354
1.43k
  symRefIdx[1] = -1;
355
1.43k
}
356
357
void Slice::setList1IdxToList0Idx()
358
1.43k
{
359
1.43k
  int idxL0, idxL1;
360
1.43k
  for ( idxL1 = 0; idxL1 < numRefIdx[ REF_PIC_LIST_1 ]; idxL1++ )
361
0
  {
362
0
    list1IdxToList0Idx[idxL1] = -1;
363
0
    for ( idxL0 = 0; idxL0 < numRefIdx[ REF_PIC_LIST_0 ]; idxL0++ )
364
0
    {
365
0
      if ( refPicList[REF_PIC_LIST_0][idxL0]->getPOC() == refPicList[REF_PIC_LIST_1][idxL1]->getPOC() )
366
0
      {
367
0
        list1IdxToList0Idx[idxL1] = idxL0;
368
0
        break;
369
0
      }
370
0
    }
371
0
  }
372
1.43k
}
373
374
void Slice::constructRefPicList(const PicList& rcListPic, bool extBorder, const bool usingLongTerm)
375
1.43k
{
376
1.43k
  ::memset(isUsedAsLongTerm, 0, sizeof(isUsedAsLongTerm));
377
1.43k
  if (sliceType == VVENC_I_SLICE)
378
1.43k
  {
379
1.43k
    ::memset(refPicList, 0, sizeof(refPicList));
380
1.43k
    ::memset(numRefIdx, 0, sizeof(numRefIdx));
381
1.43k
    return;
382
1.43k
  }
383
384
0
  Picture*  pcRefPic = NULL;
385
0
  uint32_t numOfActiveRef = 0;
386
  //construct L0
387
0
  for (int refList = 0; refList < NUM_REF_PIC_LIST_01; refList++)
388
0
  {
389
0
    RefPicList eRefList = RefPicList(refList);
390
0
    numOfActiveRef = numRefIdx[ eRefList ];
391
0
    for (int ii = 0; ii < numOfActiveRef; ii++)
392
0
    {
393
0
      if (!rpl[eRefList]->isLongtermRefPic[ii])
394
0
      {
395
0
        int poc_ = poc + rpl[eRefList]->refPicIdentifier[ii];
396
397
0
        PicList::const_iterator  iterPic = rcListPic.begin();
398
0
        pcRefPic   = *(iterPic);
399
400
0
        while ( iterPic != rcListPic.end() )
401
0
        {
402
0
          if(pcRefPic->getPOC() == poc_)
403
0
          {
404
0
            break;
405
0
          }
406
0
          iterPic++;
407
0
          pcRefPic = *(iterPic);
408
0
        }
409
410
0
        if(usingLongTerm)
411
0
          pcRefPic->isLongTerm = false;
412
0
      }
413
0
      else
414
0
      {
415
0
        CHECK(!usingLongTerm, "Wrong state: using long term when it's not supported by the encoder configuration");
416
0
        int pocBits = sps->bitsForPOC;
417
0
        int pocMask = (1 << pocBits) - 1;
418
0
        int ltrpPoc = rpl[eRefList]->refPicIdentifier[ii] & pocMask;
419
0
        ltrpPoc += rpl[eRefList]->deltaPocMSBPresent[ii] ? (pocMask + 1) * rpl[eRefList]->deltaPocMSBCycleLT[ii] : 0;
420
0
        pcRefPic = xGetLongTermRefPic(rcListPic, ltrpPoc, rpl[eRefList]->deltaPocMSBPresent[ii]);
421
0
        pcRefPic->isLongTerm = true;
422
0
      }
423
0
      if ( extBorder )
424
0
      {
425
0
        pcRefPic->extendPicBorder();
426
0
      }
427
0
      refPicList[eRefList][ii] = pcRefPic;
428
0
      isUsedAsLongTerm[eRefList][ii] = usingLongTerm ? pcRefPic->isLongTerm: false;
429
0
    }
430
0
  }
431
0
}
432
433
void Slice::updateRefPicCounter( int step )
434
2.86k
{
435
8.59k
  for ( int refList = 0; refList < NUM_REF_PIC_LIST_01; refList++ )
436
5.72k
  {
437
5.72k
    int numOfActiveRef = numRefIdx[ refList ];
438
5.72k
    for ( int i = 0; i < numOfActiveRef; i++ )
439
0
    {
440
0
      refPicList[ refList ][ i ]->refCounter += step;
441
0
    }
442
5.72k
  }
443
2.86k
}
444
445
bool Slice::checkAllRefPicsReconstructed() const
446
1.43k
{
447
4.29k
  for ( int refList = 0; refList < NUM_REF_PIC_LIST_01; refList++ )
448
2.86k
  {
449
2.86k
    int numOfActiveRef = numRefIdx[ refList ];
450
2.86k
    for ( int i = 0; i < numOfActiveRef; i++ )
451
0
    {
452
0
      if ( ! refPicList[ refList ][ i ]->isReconstructed )
453
0
      {
454
0
        return false;
455
0
      }
456
0
    }
457
2.86k
  }
458
459
1.43k
  return true;
460
1.43k
}
461
462
bool Slice::checkAllRefPicsAccessible() const
463
0
{
464
0
  for ( int refList = 0; refList < NUM_REF_PIC_LIST_01; refList++ )
465
0
  {
466
0
    int numOfActiveRef = numRefIdx[ refList ];
467
0
    for ( int i = 0; i < numOfActiveRef; i++ )
468
0
    {
469
0
      if ( ! refPicList[ refList ][ i ]->isInProcessList )
470
0
      {
471
0
        return false;
472
0
      }
473
0
    }
474
0
  }
475
476
0
  return true;
477
0
}
478
479
void Slice::checkColRefIdx(uint32_t curSliceSegmentIdx, const Picture* pic) const
480
0
{
481
0
  Slice* curSlice   = pic->slices[ curSliceSegmentIdx ];
482
0
  int currColRefPOC =  curSlice->getRefPOC( RefPicList( 1 - curSlice->colFromL0Flag ), curSlice->colRefIdx );
483
484
0
  for( int i = curSliceSegmentIdx - 1; i >= 0; i-- )
485
0
  {
486
0
    const Slice* preSlice = pic->slices[i];
487
0
    if( preSlice->sliceType != VVENC_I_SLICE )
488
0
    {
489
0
      const int preColRefPOC  = preSlice->getRefPOC( RefPicList( 1 - preSlice->colFromL0Flag ), preSlice->colRefIdx );
490
0
      if( currColRefPOC != preColRefPOC )
491
0
      {
492
0
        THROW( "Collocated_ref_idx shall always be the same for all slices of a coded picture!" );
493
0
      }
494
0
      else
495
0
      {
496
0
        break;
497
0
      }
498
0
    }
499
0
  }
500
0
}
501
502
void Slice::checkCRA(const ReferencePictureList* pRPL0, const ReferencePictureList* pRPL1, int& pocCRA, vvencNalUnitType& associatedIRAPType, PicList& rcListPic)
503
0
{
504
0
  if (pocCRA < MAX_UINT && poc > pocCRA)
505
0
  {
506
0
    uint32_t numRefPic = pRPL0->numberOfShorttermPictures + pRPL0->numberOfLongtermPictures;
507
0
    for (int i = 0; i < numRefPic; i++)
508
0
    {
509
0
      if (!pRPL0->isLongtermRefPic[i])
510
0
      {
511
0
        CHECK(poc + pRPL0->refPicIdentifier[i] < pocCRA, "Invalid state");
512
0
      }
513
0
      else
514
0
      {
515
0
        CHECK(xGetLongTermRefPic(rcListPic, pRPL0->refPicIdentifier[i], pRPL0->deltaPocMSBPresent[i])->getPOC() < pocCRA, "Invalid state");
516
0
      }
517
0
    }
518
0
    numRefPic = pRPL1->numberOfShorttermPictures + pRPL1->numberOfLongtermPictures;
519
0
    for (int i = 0; i < numRefPic; i++)
520
0
    {
521
0
      if (!pRPL1->isLongtermRefPic[i])
522
0
      {
523
0
        CHECK(poc + pRPL1->refPicIdentifier[i] < pocCRA, "Invalid state");
524
0
      }
525
0
      else
526
0
      {
527
0
        CHECK(xGetLongTermRefPic(rcListPic, pRPL1->refPicIdentifier[i], pRPL1->deltaPocMSBPresent[i])->getPOC() < pocCRA, "Invalid state");
528
0
      }
529
0
    }
530
0
  }
531
0
  if (nalUnitType == VVENC_NAL_UNIT_CODED_SLICE_IDR_W_RADL || nalUnitType == VVENC_NAL_UNIT_CODED_SLICE_IDR_N_LP) // IDR picture found
532
0
  {
533
0
    pocCRA = poc;
534
0
    associatedIRAPType = nalUnitType;
535
0
  }
536
0
  else if (nalUnitType == VVENC_NAL_UNIT_CODED_SLICE_CRA) // CRA picture found
537
0
  {
538
0
    pocCRA = poc;
539
0
    associatedIRAPType = nalUnitType;
540
0
  }
541
0
}
542
543
/** Function for marking the reference pictures when an IDR/CRA/CRANT/BLA/BLANT is encountered.
544
 * \param pocCRA POC of the CRA/CRANT/BLA/BLANT picture
545
 * \param bRefreshPending flag indicating if a deferred decoding refresh is pending
546
 * \param rcListPic reference to the reference picture list
547
 * This function marks the reference pictures as "unused for reference" in the following conditions.
548
 * If the nal_unit_type is IDR/BLA/BLANT, all pictures in the reference picture list
549
 * are marked as "unused for reference"
550
 *    If the nal_unit_type is BLA/BLANT, set the pocCRA to the temporal reference of the current picture.
551
 * Otherwise
552
 *    If the bRefreshPending flag is true (a deferred decoding refresh is pending) and the current
553
 *    temporal reference is greater than that of the IRAP picture that set it (the later of the last IDR and the
554
 *    latest CRA/CRANT/BLA/BLANT picture), mark all reference pictures except that IRAP picture as "unused for
555
 *    reference" and set the bRefreshPending flag to false.
556
 *    If the nal_unit_type is CRA/CRANT, set the bRefreshPending flag to true and pocCRA to the temporal
557
 *    reference of the current picture.
558
 * Note that the current picture is already placed in the reference list and its marking is not changed.
559
 * If the current picture has a nal_ref_idc that is not 0, it will remain marked as "used for reference".
560
 */
561
void Slice::setDecodingRefreshMarking( int& pocCRA, bool& bRefreshPending, const PicList& rcListPic )
562
1.43k
{
563
1.43k
  const bool bEfficientFieldIRAPEnabled = true;
564
1.43k
  Picture* rpcPic;
565
1.43k
  int      pocCurr = poc;
566
567
1.43k
  if ( nalUnitType == VVENC_NAL_UNIT_CODED_SLICE_IDR_W_RADL
568
0
    || nalUnitType == VVENC_NAL_UNIT_CODED_SLICE_IDR_N_LP)  // IDR picture
569
1.43k
  {
570
    // mark all pictures as not used for reference
571
1.43k
    PicList::const_iterator iterPic = rcListPic.begin();
572
2.86k
    while (iterPic != rcListPic.end())
573
1.43k
    {
574
1.43k
      rpcPic = *(iterPic);
575
1.43k
      if (rpcPic->getPOC() != pocCurr)
576
0
      {
577
0
        rpcPic->isReferenced = false;
578
0
      }
579
1.43k
      iterPic++;
580
1.43k
    }
581
1.43k
    if (bEfficientFieldIRAPEnabled)
582
1.43k
    {
583
1.43k
      bRefreshPending = true;
584
1.43k
    }
585
1.43k
  }
586
0
  else // CRA or No DR
587
0
  {
588
0
    if(bEfficientFieldIRAPEnabled && (associatedIRAPType == VVENC_NAL_UNIT_CODED_SLICE_IDR_N_LP || associatedIRAPType == VVENC_NAL_UNIT_CODED_SLICE_IDR_W_RADL))
589
0
    {
590
0
      if (bRefreshPending==true && pocCurr > lastIDR) // IDR reference marking pending
591
0
      {
592
0
        PicList::const_iterator iterPic = rcListPic.begin();
593
0
        while (iterPic != rcListPic.end())
594
0
        {
595
0
          rpcPic = *(iterPic);
596
0
          if (rpcPic->getPOC() != pocCurr && rpcPic->getPOC() != lastIDR)
597
0
          {
598
0
            rpcPic->isReferenced = false;
599
0
          }
600
0
          iterPic++;
601
0
        }
602
0
        bRefreshPending = false;
603
0
      }
604
0
    }
605
0
    else
606
0
    {
607
      // Keep the IRAP picture that set the pending marking: the later of the last IDR and the last CRA (IRAP POCs
608
      // increase in decoding order). pocCRA is 0 until the first CRA, so at the first CRA after an IDR with a POC above
609
      // 0 (POC0IDR 0) the IDR must be kept, or the CRA's leading pictures lose it as a reference.
610
0
      const int pendingIrapPoc = std::max( lastIDR, pocCRA );
611
0
      if (bRefreshPending==true && pocCurr > pendingIrapPoc) // IRAP reference marking pending
612
0
      {
613
0
        PicList::const_iterator iterPic = rcListPic.begin();
614
0
        while (iterPic != rcListPic.end())
615
0
        {
616
0
          rpcPic = *(iterPic);
617
0
          if (rpcPic->getPOC() != pocCurr && rpcPic->getPOC() != pendingIrapPoc)
618
0
          {
619
0
            rpcPic->isReferenced = false;
620
0
          }
621
0
          iterPic++;
622
0
        }
623
0
        bRefreshPending = false;
624
0
      }
625
0
    }
626
0
    if ( nalUnitType == VVENC_NAL_UNIT_CODED_SLICE_CRA ) // CRA picture found
627
0
    {
628
0
      bRefreshPending = true;
629
0
      pocCRA = pocCurr;
630
0
    }
631
0
  }
632
1.43k
}
633
634
void Slice::copySliceInfo( const Slice* slice, bool cpyAlmostAll)
635
0
{
636
0
  CHECK(!slice, "Source is NULL");
637
638
0
  int i, j;
639
640
0
  poc                             = slice->poc;
641
0
  nalUnitType                     = slice->nalUnitType;
642
0
  sliceType                       = slice->sliceType;
643
0
  sliceQp                         = slice->sliceQp;
644
0
  chromaQpAdjEnabled              = slice->chromaQpAdjEnabled;
645
0
  deblockingFilterDisable         = slice->deblockingFilterDisable;
646
0
  deblockingFilterOverride        = slice->deblockingFilterOverride;
647
0
  for( int comp = 0; comp < MAX_NUM_COMP; comp++ )
648
0
  {
649
0
    deblockingFilterBetaOffsetDiv2[comp]  = slice->deblockingFilterBetaOffsetDiv2[comp];
650
0
    deblockingFilterTcOffsetDiv2[comp]    = slice->deblockingFilterTcOffsetDiv2[comp];
651
0
  }
652
653
0
  for (i = 0; i < NUM_REF_PIC_LIST_01; i++)
654
0
  {
655
0
    numRefIdx[i] = slice->numRefIdx[i];
656
0
  }
657
658
0
  for (i = 0; i < MAX_NUM_REF; i++)
659
0
  {
660
0
    list1IdxToList0Idx[i] = slice->list1IdxToList0Idx[i];
661
0
  }
662
663
0
  checkLDC      = slice->checkLDC;
664
665
0
  biDirPred     = slice->biDirPred;
666
0
  symRefIdx[0]  = slice->symRefIdx[0];
667
0
  symRefIdx[1]  = slice->symRefIdx[1];
668
669
0
  for (uint32_t component = 0; component < MAX_NUM_COMP; component++)
670
0
  {
671
0
    sliceChromaQpDelta[component] = slice->sliceChromaQpDelta[component];
672
0
  }
673
0
  sliceChromaQpDelta[COMP_JOINT_CbCr] = slice->sliceChromaQpDelta[COMP_JOINT_CbCr];
674
0
  if( cpyAlmostAll )
675
0
  {
676
0
    for( i = 0; i < NUM_REF_PIC_LIST_01; i++ )
677
0
    {
678
0
      for( j = 0; j < MAX_NUM_REF; j++ )
679
0
      {
680
0
        refPicList[i][j] = slice->refPicList[i][j];
681
0
        refPOCList[i][j] = slice->refPOCList[i][j];
682
0
        isUsedAsLongTerm[i][j] = slice->isUsedAsLongTerm[i][j];
683
0
      }
684
0
      isUsedAsLongTerm[i][MAX_NUM_REF] = slice->isUsedAsLongTerm[i][MAX_NUM_REF];
685
0
    }
686
0
  }
687
688
  // access channel
689
0
  if (cpyAlmostAll) rpl[0] = slice->rpl[0];
690
0
  if (cpyAlmostAll) rpl[1] = slice->rpl[1];
691
0
  lastIDR             = slice->lastIDR;
692
693
0
  if( cpyAlmostAll ) pic  = slice->pic;
694
695
0
  colFromL0Flag        = slice->colFromL0Flag;
696
0
  colRefIdx            = slice->colRefIdx;
697
698
0
  if( cpyAlmostAll ) setLambdas(slice->getLambdas());
699
700
0
  TLayer                        = slice->TLayer;
701
0
  TLayerSwitchingFlag           = slice->TLayerSwitchingFlag;
702
0
  independentSliceIdx           = slice->independentSliceIdx;
703
0
  clpRngs                       = slice->clpRngs;
704
0
  explicitScalingListUsed       = slice->explicitScalingListUsed;
705
0
  pendingRasInit                = slice->pendingRasInit;
706
707
0
  for( uint32_t ch = 0 ; ch < MAX_NUM_CH; ch++)
708
0
  {
709
0
    saoEnabled[ch] = slice->saoEnabled[ch];
710
0
  }
711
712
0
  cabacInitFlag                 = slice->cabacInitFlag;
713
0
  memcpy( alfAps, slice->alfAps, sizeof(alfAps)); // this might be quite unsafe
714
0
  memcpy( alfEnabled, slice->alfEnabled, sizeof(alfEnabled));
715
0
  numAps               = slice->numAps;
716
0
  lumaApsId            = slice->lumaApsId;
717
0
  chromaApsId          = slice->chromaApsId;
718
0
  isLossless                    = slice->isLossless;
719
720
0
  sliceMap                      = slice->sliceMap;
721
722
0
  ccAlfFilterParam              = slice->ccAlfFilterParam;
723
0
  ccAlfFilterControl[0]         = slice->ccAlfFilterControl[0];
724
0
  ccAlfFilterControl[1]         = slice->ccAlfFilterControl[1];
725
0
  ccAlfCbEnabled       = slice->ccAlfCbEnabled;
726
0
  ccAlfCrEnabled       = slice->ccAlfCrEnabled;
727
0
  ccAlfCbApsId         = slice->ccAlfCbApsId;
728
0
  ccAlfCrApsId         = slice->ccAlfCrApsId;
729
730
0
  if( cpyAlmostAll ) encCABACTableIdx  = slice->encCABACTableIdx;
731
0
}
732
733
/** Function for checking if this is a STSA candidate
734
 */
735
bool Slice::isStepwiseTemporalLayerSwitchingPointCandidate(const PicList& rcListPic) const
736
0
{
737
0
  PicList::const_iterator iterPic = rcListPic.begin();
738
0
  while ( iterPic != rcListPic.end())
739
0
  {
740
0
    const Picture* pic = *(iterPic++);
741
0
    if( pic->isInitDone && pic->isReferenced && pic->poc != poc)
742
0
    {
743
0
      if( pic->TLayer >= TLayer)
744
0
      {
745
0
        return false;
746
0
      }
747
0
    }
748
0
  }
749
0
  return true;
750
0
}
751
752
753
void Slice::checkLeadingPictureRestrictions(const PicList& rcListPic) const
754
1.43k
{
755
  // When a picture is a leading picture, it shall be a RADL or RASL picture.
756
1.43k
  if(associatedIRAP > poc && !pps->mixedNaluTypesInPic)
757
0
  {
758
    // Do not check IRAP pictures since they may get a POC lower than their associated IRAP
759
0
    if (nalUnitType < VVENC_NAL_UNIT_CODED_SLICE_IDR_W_RADL ||
760
0
        nalUnitType > VVENC_NAL_UNIT_CODED_SLICE_CRA)
761
0
    {
762
0
      CHECK(nalUnitType != VVENC_NAL_UNIT_CODED_SLICE_RASL &&
763
0
            nalUnitType != VVENC_NAL_UNIT_CODED_SLICE_RADL, "Invalid NAL unit type");
764
0
    }
765
0
  }
766
767
  // When a picture is a trailing picture, it shall not be a RADL or RASL picture.
768
1.43k
  if(associatedIRAP < poc && !pps->mixedNaluTypesInPic)
769
0
  {
770
0
    CHECK(nalUnitType == VVENC_NAL_UNIT_CODED_SLICE_RASL ||
771
0
          nalUnitType == VVENC_NAL_UNIT_CODED_SLICE_RADL, "Invalid NAL unit type");
772
0
  }
773
774
775
  // No RASL pictures shall be present in the bitstream that are associated with
776
  // an IDR picture.
777
1.43k
  if (nalUnitType == VVENC_NAL_UNIT_CODED_SLICE_RASL)
778
0
  {
779
0
    CHECK( associatedIRAPType == VVENC_NAL_UNIT_CODED_SLICE_IDR_N_LP   ||
780
0
           associatedIRAPType == VVENC_NAL_UNIT_CODED_SLICE_IDR_W_RADL, "Invalid NAL unit type");
781
0
  }
782
783
  // No RADL pictures shall be present in the bitstream that are associated with
784
  // a BLA picture having nal_unit_type equal to BLA_N_LP or that are associated
785
  // with an IDR picture having nal_unit_type equal to IDR_N_LP.
786
1.43k
  if (nalUnitType == VVENC_NAL_UNIT_CODED_SLICE_RADL)
787
0
  {
788
0
    CHECK (associatedIRAPType == VVENC_NAL_UNIT_CODED_SLICE_IDR_N_LP, "Invalid NAL unit type");
789
0
  }
790
791
  // loop through all pictures in the reference picture buffer
792
1.43k
  PicList::const_iterator iterPic = rcListPic.begin();
793
2.86k
  while ( iterPic != rcListPic.end())
794
1.43k
  {
795
1.43k
    Picture* pic = *(iterPic++);
796
1.43k
    if( ! pic->isReconstructed )
797
1.43k
    {
798
1.43k
      continue;
799
1.43k
    }
800
0
    if( pic->poc == poc)
801
0
    {
802
0
      continue;
803
0
    }
804
0
    const Slice* slice = pic->slices[0];
805
806
0
    if (slice->picHeader->picOutputFlag == 1 && !picHeader->noOutputOfPriorPics && pic->layerId == nuhLayerId)
807
0
    {
808
0
      if (nalUnitType == VVENC_NAL_UNIT_CODED_SLICE_CRA || nalUnitType == VVENC_NAL_UNIT_CODED_SLICE_IDR_N_LP || nalUnitType == VVENC_NAL_UNIT_CODED_SLICE_IDR_W_RADL)
809
0
      {
810
0
        CHECK(pic->poc >= poc, "Any picture, with nuh_layer_id equal to a particular value layerId, that precedes an IRAP picture with nuh_layer_id "
811
0
              "equal to layerId in decoding order shall precede the IRAP picture in output order.");
812
0
      }
813
0
    }
814
815
0
    if (slice->picHeader->picOutputFlag == 1 && !picHeader->noOutputBeforeRecovery && pic->layerId == nuhLayerId)
816
0
    {
817
0
      if (poc == picHeader->recoveryPocCnt + prevGDRInSameLayerPOC)
818
0
      {
819
0
        CHECK(pic->poc >= poc, "Any picture, with nuh_layer_id equal to a particular value layerId, that precedes a recovery point picture with "
820
0
              "nuh_layer_id equal to layerId in decoding order shall precede the recovery point picture in output order.");
821
0
      }
822
0
    }
823
824
0
    if (nalUnitType == VVENC_NAL_UNIT_CODED_SLICE_RASL)
825
0
    {
826
0
      if ((associatedIRAPType == VVENC_NAL_UNIT_CODED_SLICE_CRA) &&
827
0
          associatedIRAP == slice->associatedIRAP)
828
0
      {
829
0
        if (slice->nalUnitType == VVENC_NAL_UNIT_CODED_SLICE_RADL)
830
0
        {
831
0
          CHECK(pic->poc <= poc, "Any RASL picture associated with a CRA picture shall precede any RADL picture associated with the CRA picture in output order.");
832
0
        }
833
0
      }
834
0
    }
835
836
0
    if (nalUnitType == VVENC_NAL_UNIT_CODED_SLICE_RASL)
837
0
    {
838
0
      if(associatedIRAPType == VVENC_NAL_UNIT_CODED_SLICE_CRA)
839
0
      {
840
0
        if(slice->poc < associatedIRAP &&
841
0
          (
842
0
            slice->nalUnitType == VVENC_NAL_UNIT_CODED_SLICE_IDR_N_LP   ||
843
0
            slice->nalUnitType == VVENC_NAL_UNIT_CODED_SLICE_IDR_W_RADL ||
844
0
            slice->nalUnitType == VVENC_NAL_UNIT_CODED_SLICE_CRA ||
845
0
            slice->nalUnitType == VVENC_NAL_UNIT_CODED_SLICE_GDR) &&
846
0
            pic->layerId == nuhLayerId)
847
0
        {
848
0
          CHECK(poc <= slice->poc, "Any RASL picture, with nuh_layer_id equal to a particular value layerId, associated with a CRA picture shall follow, "
849
0
               "in output order, any IRAP or GDR picture with nuh_layer_id equal to layerId that precedes the CRA picture in decoding order.");
850
0
        }
851
0
      }
852
0
    }
853
0
  }
854
1.43k
}
855
856
857
//Function for applying picture marking based on the Reference Picture List
858
void Slice::applyReferencePictureListBasedMarking(const PicList& rcListPic, const ReferencePictureList* pRPL0, const ReferencePictureList* pRPL1, const int layerId, const PPS& pps, const bool usingLongTerm ) const
859
1.43k
{
860
1.43k
  int i, isReference;
861
1.43k
  checkLeadingPictureRestrictions(rcListPic);
862
863
1.43k
  bool isNeedToCheck = ( nalUnitType == VVENC_NAL_UNIT_CODED_SLICE_IDR_N_LP || nalUnitType == VVENC_NAL_UNIT_CODED_SLICE_IDR_W_RADL ) ? false : true;
864
865
  // loop through all pictures in the reference picture buffer
866
1.43k
  PicList::const_iterator iterPic = rcListPic.begin();
867
2.86k
  while( iterPic != rcListPic.end() )
868
1.43k
  {
869
1.43k
    Picture* pic = *( iterPic++ );
870
871
1.43k
    if( !pic->isReferenced )
872
0
      continue;
873
874
1.43k
    isReference = 0;
875
    // loop through all pictures in the Reference Picture Set
876
    // to see if the picture should be kept as reference picture
877
1.43k
    for( i = 0; isNeedToCheck && !isReference && i < pRPL0->numberOfShorttermPictures + pRPL0->numberOfLongtermPictures + pRPL0->numberOfInterLayerPictures; i++ )
878
0
    {
879
0
      if( pRPL0->isInterLayerRefPic[ i ] )
880
0
      {
881
        // Diagonal inter-layer prediction is not allowed
882
0
        CHECK( pRPL0->refPicIdentifier[i], "ILRP identifier should be 0" );
883
884
0
        if( pic->poc == poc )
885
0
        {
886
0
          isReference = 1;
887
0
          if( usingLongTerm && !pic->isLongTerm ) pic->isLongTerm = true;
888
0
        }
889
0
      }
890
0
      else if( pic->layerId == layerId )
891
0
      {
892
0
        if( !pRPL0->isLongtermRefPic[i] )
893
0
        {
894
0
          if( pic->poc == poc + pRPL0->refPicIdentifier[i] )
895
0
          {
896
0
            isReference = 1;
897
0
            if( usingLongTerm && pic->isLongTerm ) pic->isLongTerm = false;
898
0
          }
899
0
        }
900
0
        else
901
0
        {
902
0
          int pocCycle = 1 << (pic->cs->sps->bitsForPOC);
903
0
          int curPoc = pic->poc & (pocCycle - 1);
904
0
          if( usingLongTerm && pic->isLongTerm && curPoc == pRPL0->refPicIdentifier[i] )
905
0
          {
906
0
            isReference = 1;
907
0
          }
908
0
        }
909
0
      }
910
0
    }
911
1.43k
    for( i = 0; isNeedToCheck && !isReference && i < pRPL1->numberOfShorttermPictures + pRPL1->numberOfLongtermPictures + pRPL1->numberOfInterLayerPictures; i++ )
912
0
    {
913
0
      if( pRPL1->isInterLayerRefPic[i] )
914
0
      {
915
        // Diagonal inter-layer prediction is not allowed
916
0
        CHECK( pRPL1->refPicIdentifier[i], "ILRP identifier should be 0" );
917
918
0
        if( pic->poc == poc )
919
0
        {
920
0
          isReference = 1;
921
0
          if( usingLongTerm && !pic->isLongTerm ) pic->isLongTerm = true;
922
0
        }
923
0
      }
924
0
      else if( pic->layerId == layerId )
925
0
      {
926
0
        if( !pRPL1->isLongtermRefPic[i] )
927
0
        {
928
0
          if( pic->poc == poc + pRPL1->refPicIdentifier[i] )
929
0
          {
930
0
            isReference = 1;
931
0
            if( usingLongTerm && pic->isLongTerm ) pic->isLongTerm = false;
932
0
          }
933
0
        }
934
0
        else
935
0
        {
936
0
          int pocCycle = 1 << ( pic->cs->sps->bitsForPOC );
937
0
          int curPoc = pic->poc & ( pocCycle - 1 );
938
0
          if( usingLongTerm && pic->isLongTerm && curPoc == pRPL1->refPicIdentifier[i] )
939
0
          {
940
0
            isReference = 1;
941
0
          }
942
0
        }
943
0
      }
944
0
    }
945
    // mark the picture as "unused for reference" if it is not in
946
    // the Reference Picture List
947
1.43k
    if ( pic->layerId == layerId && pic->isInitDone && pic->poc != poc && isReference == 0 )
948
0
    {
949
0
      pic->isReferenced = false;
950
0
      if( usingLongTerm )
951
0
        pic->isLongTerm   = false;
952
0
    }
953
1.43k
  }
954
1.43k
}
955
956
// int Slice::checkThatAllRefPicsAreAvailable( const PicList& rcListPic, const ReferencePictureList *pRPL, int rplIdx ) const
957
bool Slice::isRplPicMissing( const PicList& rcListPic, const RefPicList refList, int& missingPoc, int ip ) const
958
2.86k
{
959
2.86k
  if( isIDRorBLA() ) return false; // assume that all pic in the DPB will be flushed anyway so no need to check.
960
961
0
  const ReferencePictureList* pRPL = rpl[ refList ];
962
0
  int numberOfPictures             = pRPL->numberOfLongtermPictures + pRPL->numberOfShorttermPictures + pRPL->numberOfInterLayerPictures;
963
964
  // check long term ref pics
965
0
  if( pRPL->numberOfLongtermPictures > 0 )
966
0
  {
967
0
    for( int ii = 0; ii < numberOfPictures; ii++ )
968
0
    {
969
0
      if( ! pRPL->isLongtermRefPic[ii] || pRPL->isInterLayerRefPic[ii] )
970
0
        continue;
971
972
0
      bool isAvailable = false;
973
0
      int  checkPoc    = pRPL->refPicIdentifier[ii];
974
975
0
      for( auto& pic : rcListPic )
976
0
      {
977
0
        int pocCycle = 1 << (pic->cs->sps->bitsForPOC);
978
0
        int curPoc   = pic->getPOC() & (pocCycle - 1);
979
0
        int refPoc   = pRPL->refPicIdentifier[ii] & (pocCycle - 1);
980
0
        if( pRPL->deltaPocMSBPresent[ii] )
981
0
        {
982
0
          refPoc += poc - pRPL->deltaPocMSBCycleLT[ii] * pocCycle - (poc & (pocCycle - 1));
983
0
        }
984
0
        else
985
0
        {
986
0
          curPoc = curPoc & (pocCycle - 1);
987
0
        }
988
0
        if( pic->isLongTerm && curPoc == refPoc && pic->isReferenced )
989
0
        {
990
0
          isAvailable = true;
991
0
          break;
992
0
        }
993
0
      }
994
995
      // if there was no such long-term check the short terms
996
0
      if( ! isAvailable )
997
0
      {
998
0
        for( auto& pic : rcListPic )
999
0
        {
1000
0
          int pocCycle = 1 << (pic->cs->sps->bitsForPOC);
1001
0
          int curPoc   = pic->getPOC() & (pocCycle - 1);
1002
0
          int refPoc   = pRPL->refPicIdentifier[ii] & (pocCycle - 1);
1003
0
          if( pRPL->deltaPocMSBPresent[ii] )
1004
0
          {
1005
0
            refPoc += poc - pRPL->deltaPocMSBCycleLT[ii] * pocCycle - (poc & (pocCycle - 1));
1006
0
          }
1007
0
          else
1008
0
          {
1009
0
            curPoc = curPoc & (pocCycle - 1);
1010
0
          }
1011
0
          if( ! pic->isLongTerm && curPoc == refPoc && pic->isReferenced )
1012
0
          {
1013
0
            isAvailable     = true;
1014
0
            pic->isLongTerm = true;
1015
0
            break;
1016
0
          }
1017
0
        }
1018
0
      }
1019
1020
0
      if( ! isAvailable )
1021
0
      {
1022
0
        missingPoc = checkPoc;
1023
0
        return true;
1024
0
      }
1025
0
    }
1026
0
  }
1027
1028
  // check short term ref pics
1029
0
  for( int ii = 0; ii < numberOfPictures; ii++ )
1030
0
  {
1031
0
    if( pRPL->isLongtermRefPic[ii] )
1032
0
      continue;
1033
1034
0
    bool isAvailable = false;
1035
0
    int  checkPoc    = poc + pRPL->refPicIdentifier[ii];
1036
1037
0
    for( auto& pic : rcListPic )
1038
0
    {
1039
0
      if( ! pic->isLongTerm && pic->getPOC() == poc + pRPL->refPicIdentifier[ii] && pic->isReferenced && !refPicIsFutureIDRnoLP( pic->getPOC(), ip ) )
1040
0
      {
1041
0
        isAvailable = true;
1042
0
        break;
1043
0
      }
1044
0
    }
1045
0
    if( ! isAvailable && pRPL->numberOfShorttermPictures > 0 )
1046
0
    {
1047
0
      missingPoc = checkPoc;
1048
0
      return true;
1049
0
    }
1050
0
  }
1051
1052
0
  return false;
1053
0
}
1054
1055
void Slice::createExplicitReferencePictureSetFromReference(const PicList& rcListPic, const ReferencePictureList* pRPL0, const ReferencePictureList* pRPL1, int ip)
1056
0
{
1057
0
  Picture* picCand;;
1058
0
  int pocCycle = 0;
1059
1060
0
  if ( isIDRorBLA() ) return; //Assume that all pic in the DPB will be flushed anyway so no need to check.
1061
1062
0
  ReferencePictureList rplSrc0 = *pRPL0;
1063
0
  ReferencePictureList rplSrc1 = *pRPL1;
1064
1065
0
  ReferencePictureList* pLocalRPL0 = &rplLocal[0];
1066
0
  (*pLocalRPL0) = ReferencePictureList();
1067
1068
0
  uint32_t numOfSTRPL0 = 0;
1069
0
  uint32_t numOfLTRPL0 = 0;
1070
0
  uint32_t numOfILRPL0 = 0;
1071
0
  uint32_t numOfRefPic = rplSrc0.numberOfShorttermPictures + rplSrc0.numberOfLongtermPictures;
1072
0
  uint32_t refPicIdxL0 = 0;
1073
0
  for (int ii = 0; ii < numOfRefPic; ii++)
1074
0
  {
1075
    // loop through all pictures in the reference picture buffer
1076
0
    PicList::const_iterator iterPic = rcListPic.begin();
1077
0
    bool isAvailable = false;
1078
1079
0
    pocCycle = 1 << (sps->bitsForPOC);
1080
0
    while (iterPic != rcListPic.end())
1081
0
    {
1082
0
      picCand = *(iterPic++);
1083
0
      if( pic->layerId == picCand->layerId && picCand->isReferenced)
1084
0
      {
1085
0
        if (!rplSrc0.isLongtermRefPic[ii] && picCand->poc == poc + rplSrc0.refPicIdentifier[ii] && !isPocRestrictedByDRAP(picCand->poc, picCand->precedingDRAP) && !refPicIsFutureIDRnoLP(picCand->poc, ip))
1086
0
        {
1087
0
          isAvailable = true;
1088
0
          break;
1089
0
        }
1090
0
        else if (rplSrc0.isLongtermRefPic[ii] && (picCand->poc & (pocCycle - 1)) == rplSrc0.refPicIdentifier[ii] && !isPocRestrictedByDRAP(picCand->poc, picCand->precedingDRAP))
1091
0
        {
1092
0
          isAvailable = true;
1093
0
          break;
1094
0
        }
1095
0
      }
1096
0
    }
1097
0
    if (isAvailable)
1098
0
    {
1099
0
      pLocalRPL0->setRefPicIdentifier(refPicIdxL0, rplSrc0.refPicIdentifier[ii], rplSrc0.isLongtermRefPic[ii], rplSrc0.isInterLayerRefPic[ii], rplSrc0.interLayerRefPicIdx[ii]);
1100
0
      refPicIdxL0++;
1101
0
      numOfSTRPL0 = numOfSTRPL0 + ((rplSrc0.isLongtermRefPic[ii]) ? 0 : 1);
1102
0
      numOfLTRPL0 = numOfLTRPL0 + ((rplSrc0.isLongtermRefPic[ii]) ? 1 : 0);
1103
0
      isAvailable = false;
1104
0
    }
1105
0
  }
1106
1107
0
  if( enableDRAPSEI)
1108
0
  {
1109
0
    pLocalRPL0->numberOfShorttermPictures = (numOfSTRPL0);
1110
0
    pLocalRPL0->numberOfLongtermPictures = (numOfLTRPL0);
1111
0
    if( !isIRAP() && !pLocalRPL0->isPOCInRefPicList(associatedIRAP, poc))
1112
0
    {
1113
0
      if (useLTforDRAP && !rplSrc1.isPOCInRefPicList(associatedIRAP, poc))
1114
0
      {
1115
        // Adding associated IRAP as longterm picture
1116
0
        pLocalRPL0->setRefPicIdentifier(refPicIdxL0, associatedIRAP, true, false, 0);
1117
0
        refPicIdxL0++;
1118
0
        numOfLTRPL0++;
1119
0
      }
1120
0
      else
1121
0
      {
1122
        // Adding associated IRAP as shortterm picture
1123
0
        pLocalRPL0->setRefPicIdentifier(refPicIdxL0, associatedIRAP - poc, false, false, 0);
1124
0
        refPicIdxL0++;
1125
0
        numOfSTRPL0++;
1126
0
      }
1127
0
    }
1128
0
  }
1129
1130
0
  ReferencePictureList* pLocalRPL1 = &rplLocal[1];
1131
0
  (*pLocalRPL1) = ReferencePictureList();
1132
1133
0
  uint32_t numOfSTRPL1 = 0;
1134
0
  uint32_t numOfLTRPL1 = 0;
1135
0
  uint32_t numOfILRPL1 = 0;
1136
0
  numOfRefPic = rplSrc1.numberOfShorttermPictures + rplSrc1.numberOfLongtermPictures;
1137
0
  uint32_t refPicIdxL1 = 0;
1138
0
  for (int ii = 0; ii < numOfRefPic; ii++)
1139
0
  {
1140
    // loop through all pictures in the reference picture buffer
1141
0
    PicList::const_iterator iterPic = rcListPic.begin();
1142
0
    bool isAvailable = false;
1143
0
    pocCycle = 1 << sps->bitsForPOC;
1144
0
    while (iterPic != rcListPic.end())
1145
0
    {
1146
0
      picCand = *(iterPic++);
1147
0
      if( pic->layerId == picCand->layerId && picCand->isReferenced )
1148
0
      {
1149
0
        if (!rplSrc1.isLongtermRefPic[ii] && picCand->poc == poc + rplSrc1.refPicIdentifier[ii] && !isPocRestrictedByDRAP(picCand->poc, picCand->precedingDRAP) && !refPicIsFutureIDRnoLP(picCand->poc, ip))
1150
0
        {
1151
0
          isAvailable = true;
1152
0
          break;
1153
0
        }
1154
0
        else if (rplSrc1.isLongtermRefPic[ii] && (picCand->poc & (pocCycle - 1)) == rplSrc1.refPicIdentifier[ii] && !isPocRestrictedByDRAP(picCand->poc, picCand->precedingDRAP))
1155
0
        {
1156
0
          isAvailable = true;
1157
0
          break;
1158
0
        }
1159
0
      }
1160
0
    }
1161
0
    if (isAvailable)
1162
0
    {
1163
0
      pLocalRPL1->setRefPicIdentifier(refPicIdxL1, rplSrc1.refPicIdentifier[ii], rplSrc1.isLongtermRefPic[ii], rplSrc1.isInterLayerRefPic[ii], rplSrc1.interLayerRefPicIdx[ii]);
1164
0
      refPicIdxL1++;
1165
0
      numOfSTRPL1 = numOfSTRPL1 + ((rplSrc1.isLongtermRefPic[ii]) ? 0 : 1);
1166
0
      numOfLTRPL1 = numOfLTRPL1 + ((rplSrc1.isLongtermRefPic[ii]) ? 1 : 0);
1167
0
      isAvailable = false;
1168
0
    }
1169
0
  }
1170
1171
  //Copy from L1 if we have less than active ref pic
1172
0
  int numOfNeedToFill = rplSrc0.numberOfActivePictures - (numOfLTRPL0 + numOfSTRPL0);
1173
0
  bool isDisallowMixedRefPic = sps->allRplEntriesHasSameSign;
1174
0
  int originalL0StrpNum = numOfSTRPL0;
1175
0
  int originalL0LtrpNum = numOfLTRPL0;
1176
0
  int originalL0IlrpNum = numOfILRPL0;
1177
1178
0
  for (int ii = 0; numOfNeedToFill > 0 && ii < (numOfLTRPL1 + numOfSTRPL1 + numOfILRPL1); ii++)
1179
0
  {
1180
0
    if (ii <= (numOfLTRPL1 + numOfSTRPL1 + numOfILRPL1 - 1))
1181
0
    {
1182
      //Make sure this copy is not already in L0
1183
0
      bool canIncludeThis = true;
1184
0
      for (int jj = 0; jj < refPicIdxL0; jj++)
1185
0
      {
1186
0
        if ((pLocalRPL1->refPicIdentifier[ii] == pLocalRPL0->refPicIdentifier[jj])
1187
0
         && (pLocalRPL1->isLongtermRefPic[ii] == pLocalRPL0->isLongtermRefPic[jj])
1188
0
         && (pLocalRPL1->isInterLayerRefPic[ii] == pLocalRPL0->isInterLayerRefPic[jj]) )
1189
0
        {
1190
0
          canIncludeThis = false;
1191
0
        }
1192
0
        bool sameSign = (pLocalRPL1->refPicIdentifier[ii] > 0) == (pLocalRPL0->refPicIdentifier[0] > 0);
1193
0
        if (isDisallowMixedRefPic && canIncludeThis && !pLocalRPL1->isLongtermRefPic[ii] && !sameSign)
1194
0
        {
1195
0
          canIncludeThis = false;
1196
0
        }
1197
0
      }
1198
0
      if (canIncludeThis)
1199
0
      {
1200
0
        pLocalRPL0->setRefPicIdentifier(refPicIdxL0, pLocalRPL1->refPicIdentifier[ii], pLocalRPL1->isLongtermRefPic[ii], pLocalRPL1->isInterLayerRefPic[ii], pLocalRPL1->interLayerRefPicIdx[ii]);
1201
0
        refPicIdxL0++;
1202
0
        numOfSTRPL0 +=  rplSrc1.isLongtermRefPic[ii] ? 0 : 1;
1203
0
        numOfLTRPL0 += (rplSrc1.isLongtermRefPic[ii] && !rplSrc1.isInterLayerRefPic[ii]) ? 1 : 0;
1204
0
        numOfILRPL0 +=  rplSrc1.isInterLayerRefPic[ ii] ? 1 : 0;
1205
1206
0
        numOfNeedToFill--;
1207
0
      }
1208
0
    }
1209
0
  }
1210
0
  pLocalRPL0->numberOfLongtermPictures  = numOfLTRPL0;
1211
0
  pLocalRPL0->numberOfShorttermPictures = numOfSTRPL0;
1212
0
  pLocalRPL0->numberOfInterLayerPictures = numOfILRPL0;
1213
1214
0
  int numPics = numOfLTRPL0 + numOfSTRPL0;
1215
0
  pLocalRPL0->numberOfActivePictures  = ( numPics < rpl[0]->numberOfActivePictures ? numPics : rpl[0]->numberOfActivePictures ) + numOfILRPL0;
1216
0
  pLocalRPL0->ltrpInSliceHeader = rpl[0]->ltrpInSliceHeader;
1217
1218
0
  pLocalRPL0->numberOfActivePictures    = (numOfLTRPL0 + numOfSTRPL0 < rplSrc0.numberOfActivePictures) ? numOfLTRPL0 + numOfSTRPL0 : rplSrc0.numberOfActivePictures;
1219
0
  pLocalRPL0->ltrpInSliceHeader = rplSrc0.ltrpInSliceHeader;
1220
0
  rplIdx[0] = -1;
1221
0
  rpl[0]    = pLocalRPL0;
1222
1223
  //Copy from L0 if we have less than active ref pic
1224
0
  numOfNeedToFill = pLocalRPL0->numberOfActivePictures - (numOfLTRPL1 + numOfSTRPL1);
1225
0
  for (int ii = 0; numOfNeedToFill > 0 && ii < (pLocalRPL0->numberOfLongtermPictures + pLocalRPL0->numberOfShorttermPictures + pLocalRPL0->numberOfInterLayerPictures ); ii++)
1226
0
  {
1227
0
    if (ii <= (originalL0StrpNum + originalL0LtrpNum + originalL0IlrpNum - 1))
1228
0
    {
1229
      //Make sure this copy is not already in L0
1230
0
      bool canIncludeThis = true;
1231
0
      for (int jj = 0; jj < refPicIdxL1; jj++)
1232
0
      {
1233
0
        if ((pLocalRPL0->refPicIdentifier[ii] == pLocalRPL1->refPicIdentifier[jj])
1234
0
          && (pLocalRPL0->isLongtermRefPic[ii] == pLocalRPL1->isLongtermRefPic[jj])
1235
0
          && (pLocalRPL0->isInterLayerRefPic[ii] == pLocalRPL1->isInterLayerRefPic[jj]))
1236
0
        {
1237
0
          canIncludeThis = false;
1238
0
        }
1239
0
        bool sameSign = (pLocalRPL0->refPicIdentifier[ii] > 0) == (pLocalRPL1->refPicIdentifier[0] > 0);
1240
0
        if (isDisallowMixedRefPic && canIncludeThis && !pLocalRPL0->isLongtermRefPic[ii] && !sameSign)
1241
0
        {
1242
0
          canIncludeThis = false;
1243
0
        }
1244
0
      }
1245
0
      if (canIncludeThis)
1246
0
      {
1247
0
        pLocalRPL1->setRefPicIdentifier(refPicIdxL1, pLocalRPL0->refPicIdentifier[ii], pLocalRPL0->isLongtermRefPic[ii], pLocalRPL0->isInterLayerRefPic[ii], pLocalRPL0->interLayerRefPicIdx[ii]);
1248
0
        refPicIdxL1++;
1249
0
        numOfSTRPL1 += pLocalRPL0->isLongtermRefPic[ii] ? 0 : 1;
1250
0
        numOfLTRPL1 += (pLocalRPL0->isLongtermRefPic[ii] && !pLocalRPL0->isInterLayerRefPic[ii]) ? 1 : 0;
1251
0
        numOfLTRPL1 += pLocalRPL0->isInterLayerRefPic[ii] ? 1 : 0;
1252
1253
0
        numOfNeedToFill--;
1254
0
      }
1255
0
    }
1256
0
  }
1257
0
  pLocalRPL1->numberOfLongtermPictures  = numOfLTRPL1;
1258
0
  pLocalRPL1->numberOfShorttermPictures = numOfSTRPL1;
1259
0
  pLocalRPL1->numberOfInterLayerPictures = numOfILRPL1;
1260
0
  numPics = numOfLTRPL1 + numOfSTRPL1;
1261
1262
0
  pLocalRPL1->numberOfActivePictures    = (isDisallowMixedRefPic) ? numPics : ((numPics < rplSrc1.numberOfActivePictures) ? numPics : rplSrc1.numberOfActivePictures);
1263
0
  pLocalRPL1->ltrpInSliceHeader         = rplSrc1.ltrpInSliceHeader;
1264
0
  rplIdx[1] = -1;
1265
0
  rpl[1]    = pLocalRPL1;
1266
0
}
1267
1268
//! get tables for weighted prediction
1269
void  Slice::getWpScaling( RefPicList e, int iRefIdx, WPScalingParam *&wp ) const
1270
0
{
1271
0
 CHECK(e>=NUM_REF_PIC_LIST_01, "Invalid picture reference list");
1272
0
  wp = (WPScalingParam*) weightPredTable[e][iRefIdx];
1273
0
}
1274
1275
void PicHeader::getWpScaling(RefPicList e, int iRefIdx, WPScalingParam *&wp) const
1276
0
{
1277
0
  CHECK(e >= NUM_REF_PIC_LIST_01, "Invalid picture reference list");
1278
0
  wp = (WPScalingParam *) weightPredTable[e][iRefIdx];
1279
0
}
1280
1281
//! reset Default WP tables settings : no weight.
1282
void  Slice::resetWpScaling()
1283
1.43k
{
1284
4.29k
  for ( int e=0 ; e<NUM_REF_PIC_LIST_01 ; e++ )
1285
2.86k
  {
1286
48.6k
    for ( int i=0 ; i<MAX_NUM_REF ; i++ )
1287
45.8k
    {
1288
183k
      for ( int yuv=0 ; yuv<MAX_NUM_COMP ; yuv++ )
1289
137k
      {
1290
137k
        WPScalingParam  *pwp = &(weightPredTable[e][i][yuv]);
1291
137k
        pwp->presentFlag     = false;
1292
137k
        pwp->log2WeightDenom = 0;
1293
137k
        pwp->iWeight         = 1;
1294
137k
        pwp->iOffset         = 0;
1295
137k
      }
1296
45.8k
    }
1297
2.86k
  }
1298
1.43k
}
1299
1300
unsigned Slice::getMinPictureDistance() const
1301
4.65k
{
1302
4.65k
  int minPicDist = MAX_INT;
1303
4.65k
  if (sps->IBC)
1304
4.65k
  {
1305
4.65k
    minPicDist = 0;
1306
4.65k
  }
1307
0
  else
1308
0
  if( ! isIntra() )
1309
0
  {
1310
0
    const int currPOC  = poc;
1311
0
    for (int refIdx = 0; refIdx < numRefIdx[ REF_PIC_LIST_0 ]; refIdx++)
1312
0
    {
1313
0
      minPicDist = std::min( minPicDist, std::abs(currPOC - getRefPic(REF_PIC_LIST_0, refIdx)->getPOC()));
1314
0
    }
1315
0
    if( sliceType == VVENC_B_SLICE )
1316
0
    {
1317
0
      for (int refIdx = 0; refIdx < numRefIdx[ REF_PIC_LIST_1 ]; refIdx++)
1318
0
      {
1319
0
        minPicDist = std::min(minPicDist, std::abs(currPOC - getRefPic(REF_PIC_LIST_1, refIdx)->getPOC()));
1320
0
      }
1321
0
    }
1322
0
  }
1323
4.65k
  return (unsigned) minPicDist;
1324
4.65k
}
1325
1326
bool Slice::isPocRestrictedByDRAP( int poc, bool precedingDRAPInDecodingOrder ) const
1327
0
{
1328
0
  if (!enableDRAPSEI)
1329
0
  {
1330
0
    return false;
1331
0
  }
1332
0
  return ( isDRAP && poc != associatedIRAP ) || ( latestDRAPPOC != MAX_INT && poc > latestDRAPPOC && (precedingDRAPInDecodingOrder || poc < latestDRAPPOC) );
1333
0
}
1334
1335
bool Slice::refPicIsFutureIDRnoLP( int candPoc, int ipc ) const
1336
0
{
1337
  //check if we are not trying to reference a future IDR picture
1338
0
  if( ipc != 0 && associatedIRAP + ipc == candPoc )
1339
0
  {
1340
0
    return true;
1341
0
  }
1342
0
  return false;
1343
0
}
1344
1345
void Slice::setAlfApsIds( const std::vector<int>& ApsIDs)
1346
0
{
1347
0
  lumaApsId.resize(numAps);
1348
0
  for (int i = 0; i < numAps; i++)
1349
0
  {
1350
0
    lumaApsId[i] = ApsIDs[i];
1351
0
  }
1352
0
}
1353
1354
1355
void PicHeader::copyPicInfo( const PicHeader* other, bool cpyAll)
1356
0
{
1357
0
  pocLsb                                  = other->pocLsb;                                
1358
0
  nonRefPic                               = other->nonRefPic;                             
1359
0
  gdrOrIrapPic                            = other->gdrOrIrapPic;                          
1360
0
  gdrPic                                  = other->gdrPic;                                
1361
0
  noOutputOfPriorPics                     = other->noOutputOfPriorPics;                   
1362
0
  recoveryPocCnt                          = other->recoveryPocCnt;                        
1363
0
  noOutputBeforeRecovery                  = other->noOutputBeforeRecovery;                
1364
0
  handleCraAsCvsStart                     = other->handleCraAsCvsStart;                   
1365
0
  handleGdrAsCvsStart                     = other->handleGdrAsCvsStart;                   
1366
0
  spsId                                   = other->spsId;                                 
1367
0
  ppsId                                   = other->ppsId;                                 
1368
0
  pocMsbPresent                           = other->pocMsbPresent;                         
1369
0
  pocMsbVal                               = other->pocMsbVal;                             
1370
0
  virtualBoundariesEnabled                = other->virtualBoundariesEnabled;              
1371
0
  virtualBoundariesPresent                = other->virtualBoundariesPresent;              
1372
0
  numVerVirtualBoundaries                 = other->numVerVirtualBoundaries;               
1373
0
  numHorVirtualBoundaries                 = other->numHorVirtualBoundaries;               
1374
//  virtualBoundariesPosX[3];               = other->virtualBoundariesPosX[3];              
1375
//  virtualBoundariesPosY[3];               = other->virtualBoundariesPosY[3];              
1376
0
  picOutputFlag                           = other->picOutputFlag;                         
1377
//pic                                     = other->pic;                                   
1378
//  pRPL[NUM_REF_PIC_LIST_01]              = other->pRPL[NUM_REF_PIC_LIST_01];             
1379
0
  localRPL[L0]                            = other->localRPL[L0];         
1380
0
  localRPL[L1]                            = other->localRPL[L1];         
1381
0
  rplIdx[L0]                              = other->rplIdx[L0];           
1382
0
  rplIdx[L1]                              = other->rplIdx[L1];           
1383
0
  picInterSliceAllowed                    = other->picInterSliceAllowed;                  
1384
0
  picIntraSliceAllowed                    = other->picIntraSliceAllowed;                  
1385
0
  splitConsOverride                       = other->splitConsOverride;                     
1386
0
  cuQpDeltaSubdivIntra                    = other->cuQpDeltaSubdivIntra;                  
1387
0
  cuQpDeltaSubdivInter                    = other->cuQpDeltaSubdivInter;                  
1388
0
  cuChromaQpOffsetSubdivIntra             = other->cuChromaQpOffsetSubdivIntra;           
1389
0
  cuChromaQpOffsetSubdivInter             = other->cuChromaQpOffsetSubdivInter;           
1390
0
  enableTMVP                              = other->enableTMVP;                            
1391
0
  picColFromL0                            = other->picColFromL0;                          
1392
0
  colRefIdx                               = other->colRefIdx;
1393
0
  mvdL1Zero                               = other->mvdL1Zero;                             
1394
0
  maxNumAffineMergeCand                   = other->maxNumAffineMergeCand;                 
1395
0
  disFracMMVD                             = other->disFracMMVD;                           
1396
0
  disBdofFlag                             = other->disBdofFlag;                           
1397
0
  disDmvrFlag                             = other->disDmvrFlag;                           
1398
0
  disProfFlag                             = other->disProfFlag;                           
1399
0
  jointCbCrSign                           = other->jointCbCrSign;                         
1400
0
  qpDelta                                 = other->qpDelta;                               
1401
0
  memcpy(saoEnabled, other->saoEnabled, sizeof(saoEnabled));                
1402
0
  memcpy(alfEnabled, other->alfEnabled, sizeof(alfEnabled));              
1403
0
  numAlfAps                               = other->numAlfAps;                             
1404
0
  alfApsId                                = other->alfApsId;                              
1405
0
  alfChromaApsId                          = other->alfChromaApsId;                        
1406
0
  memcpy(ccalfEnabled, other->ccalfEnabled, sizeof(ccalfEnabled));                
1407
0
  ccalfCbApsId                            = other->ccalfCbApsId;
1408
0
  ccalfCrApsId                            = other->ccalfCrApsId;
1409
0
  deblockingFilterOverride                = other->deblockingFilterOverride;                
1410
0
  deblockingFilterDisable                 = other->deblockingFilterDisable;                
1411
0
  memcpy(deblockingFilterBetaOffsetDiv2,  other->deblockingFilterBetaOffsetDiv2,  sizeof(deblockingFilterBetaOffsetDiv2));                
1412
0
  memcpy(deblockingFilterTcOffsetDiv2,    other->deblockingFilterTcOffsetDiv2,    sizeof(deblockingFilterTcOffsetDiv2));                
1413
0
  explicitScalingListEnabled              = other->explicitScalingListEnabled;
1414
0
  scalingListApsId                        = other->scalingListApsId;                      
1415
//scalingListAps;                         = other->scalingListAps;                        
1416
0
  memcpy(minQTSize,   other->minQTSize, sizeof(minQTSize));                
1417
0
  memcpy(maxMTTDepth, other->maxMTTDepth, sizeof(maxMTTDepth));                
1418
0
  memcpy(maxBTSize,   other->maxBTSize, sizeof(maxBTSize));                
1419
0
  memcpy(maxTTSize,   other->maxTTSize, sizeof(maxTTSize));                
1420
1421
//  memcpy(weightPredTable,   other->weightPredTable, sizeof(weightPredTable));                
1422
0
  numL0Weights                            = other->numL0Weights;                          
1423
0
  numL1Weights                            = other->numL1Weights;                          
1424
1425
0
}
1426
1427
// ------------------------------------------------------------------------------------------------
1428
// Sequence parameter set (SPS)
1429
// ------------------------------------------------------------------------------------------------
1430
1431
SPS::SPS()
1432
1.43k
: spsId                           (  0 )
1433
1.43k
, dciId                           (  0 )
1434
1.43k
, vpsId                           (  0 )
1435
1.43k
, layerId                         ( 0 )
1436
1.43k
, AffineAmvr                      ( false )
1437
1.43k
, DMVR                            ( false )
1438
1.43k
, MMVD                            ( false )
1439
1.43k
, SBT                             ( false )
1440
1.43k
, ISP                             ( false )
1441
1.43k
, chromaFormatIdc                 ( CHROMA_420 )
1442
1.43k
, separateColourPlane             ( false )
1443
1.43k
, maxTLayers                      ( 1 )
1444
1.43k
, ptlDpbHrdParamsPresent          ( true )
1445
1.43k
, subLayerDpbParams               ( false )
1446
1.43k
, maxPicWidthInLumaSamples        ( 352 )
1447
1.43k
, maxPicHeightInLumaSamples       ( 288 )
1448
1.43k
, subPicInfoPresent               ( false )
1449
1.43k
, numSubPics                      ( 0 )
1450
1.43k
, independentSubPicsFlag          ( false )
1451
1.43k
, subPicIdMappingExplicitlySignalled ( false )
1452
1.43k
, log2MinCodingBlockSize          ( 0 )
1453
1.43k
, CTUSize                         ( 0 )
1454
1.43k
, partitionOverrideEnabled        ( 1 )
1455
1.43k
, minQTSize                       { 0, 0, 0 }
1456
1.43k
, maxMTTDepth                     { MAX_BT_DEPTH, MAX_BT_DEPTH_INTER, 0 }
1457
1.43k
, maxBTSize                       { 0,  0,  0 }
1458
1.43k
, maxTTSize                       { 0,  0,  0 }
1459
1.43k
, idrRefParamList                 ( false )
1460
1.43k
, dualITree                       ( 0 )
1461
1.43k
, rpl1CopyFromRpl0                ( false )
1462
1.43k
, rpl1IdxPresent                  ( false )
1463
1.43k
, allRplEntriesHasSameSign        ( true )
1464
1.43k
, longTermRefsPresent             ( false )
1465
1.43k
, temporalMVPEnabled              ( 0 )
1466
1.43k
, transformSkip                   ( false )
1467
1.43k
, log2MaxTransformSkipBlockSize   ( 0 )
1468
1.43k
, BDPCM                           ( false )
1469
1.43k
, jointCbCr                       ( false )
1470
1.43k
, entropyCodingSyncEnabled        ( false )
1471
1.43k
, entryPointsPresent              ( false )
1472
1.43k
, qpBDOffset                      { 0,0 }
1473
1.43k
, internalMinusInputBitDepth      { 0,0 }
1474
1.43k
, SbtMvp                          ( false)
1475
1.43k
, BDOF                            ( false)
1476
1.43k
, fpelMmvd                        ( false )
1477
1.43k
, BdofPresent                     ( false )
1478
1.43k
, DmvrPresent                     ( false )
1479
1.43k
, ProfPresent                     ( false )
1480
1.43k
, bitsForPOC                      ( 8 )
1481
1.43k
, pocMsbFlag                      ( false )
1482
1.43k
, pocMsbLen                       ( 0 )
1483
1.43k
, numExtraPHBitsBytes             ( 0 )
1484
1.43k
, numExtraSHBitsBytes             ( 0 )
1485
1.43k
, numLongTermRefPicSPS            ( 0 )
1486
1.43k
, log2MaxTbSize                   ( 6 )
1487
1.43k
, weightPred                      ( false )
1488
1.43k
, weightedBiPred                  ( false )
1489
1.43k
, saoEnabled                      ( false )
1490
1.43k
, temporalIdNesting               ( false )
1491
1.43k
, scalingListEnabled              ( false )
1492
1.43k
, depQuantEnabled                 ( false )
1493
1.43k
, signDataHidingEnabled           ( false )
1494
1.43k
, virtualBoundariesEnabled        ( false )
1495
1.43k
, virtualBoundariesPresent        ( false )
1496
1.43k
, numVerVirtualBoundaries         ( 0 )
1497
1.43k
, numHorVirtualBoundaries         ( 0 )
1498
1.43k
, virtualBoundariesPosX           { 0,  0,  0 }
1499
1.43k
, virtualBoundariesPosY           { 0,  0,  0 }
1500
1.43k
, hrdParametersPresent            ( false )
1501
1.43k
, subLayerParametersPresent       ( false )
1502
1.43k
, fieldSeqFlag                    ( false )
1503
1.43k
, vuiParametersPresent            ( false )
1504
1.43k
, vuiPayloadSize                  ( 0 )
1505
1.43k
, vuiParameters                   ()
1506
1.43k
, alfEnabled                      ( false )
1507
1.43k
, ccalfEnabled                    ( false )
1508
1.43k
, wrapAroundEnabled               ( false )
1509
1.43k
, IBC                             ( false )
1510
1.43k
, useColorTrans                   ( false )
1511
1.43k
, PLT                             ( false )
1512
1.43k
, AMVR                            ( false )
1513
1.43k
, LMChroma                        ( false )
1514
1.43k
, horCollocatedChroma             ( false )
1515
1.43k
, verCollocatedChroma             ( false )
1516
1.43k
, MTS                             ( false )
1517
1.43k
, MTSIntra                        ( false )
1518
1.43k
, MTSInter                        ( false )
1519
1.43k
, LFNST                           ( false )
1520
1.43k
, SMVD                            ( false )
1521
1.43k
, Affine                          ( false )
1522
1.43k
, AffineType                      ( false )
1523
1.43k
, PROF                            ( false )
1524
1.43k
, BCW                             ( false )
1525
1.43k
, CIIP                            ( false )
1526
1.43k
, GEO                             ( false )
1527
1.43k
, LADF                            ( false )
1528
1.43k
, MRL                             ( false )
1529
1.43k
, MIP                             ( false )
1530
1.43k
, GDR                             ( true )
1531
1.43k
, subLayerCbpParametersPresent    ( true)
1532
1.43k
, rprEnabled                      ( false )
1533
1.43k
, resChangeInClvsEnabled          ( false )
1534
1.43k
, interLayerPresent               ( false )
1535
1.43k
, log2ParallelMergeLevelMinus2    ( 0 )
1536
1.43k
, maxNumMergeCand                 ( 0 )
1537
1.43k
, maxNumAffineMergeCand           ( 0 )
1538
1.43k
, maxNumIBCMergeCand              ( 0 )
1539
1.43k
, maxNumGeoCand                   ( 0 )
1540
1.43k
, scalingMatrixAlternativeColourSpaceDisabled ( false )
1541
1.43k
, scalingMatrixDesignatedColourSpace          ( false )
1542
1.43k
, disableScalingMatrixForLfnstBlks            ( false )
1543
1544
1.43k
{
1545
4.29k
  for(int ch=0; ch<MAX_NUM_CH; ch++)
1546
2.86k
  {
1547
2.86k
    bitDepths.recon[ch] = 8;
1548
2.86k
    qpBDOffset   [ch] = 0;
1549
2.86k
  }
1550
1551
11.4k
  for ( int i = 0; i < VVENC_MAX_TLAYER; i++ )
1552
10.0k
  {
1553
10.0k
    maxLatencyIncreasePlus1[i] = 0;
1554
10.0k
    maxDecPicBuffering[i] = 1;
1555
10.0k
    numReorderPics[i]       = 0;
1556
10.0k
  }
1557
1558
1.43k
  ::memset(ltRefPicPocLsbSps, 0, sizeof(ltRefPicPocLsbSps));
1559
1.43k
  ::memset(usedByCurrPicLtSPS, 0, sizeof(usedByCurrPicLtSPS));
1560
1561
93.8M
  for( int i = 0; i < MAX_NUM_SUB_PICS; i++ )
1562
93.8M
  {
1563
93.8M
    subPicCtuTopLeftX[i] = 0;
1564
93.8M
    subPicCtuTopLeftY[i] = 0;
1565
93.8M
    subPicWidth[i] = 0;
1566
93.8M
    subPicHeight[i] = 0;
1567
93.8M
    subPicTreatedAsPic[i] = false;
1568
93.8M
    loopFilterAcrossSubpicEnabled[i] = false;
1569
93.8M
    subPicId[i] = 0;
1570
93.8M
  }
1571
1.43k
}
1572
1573
void ChromaQpMappingTable::setParams(const vvencChromaQpMappingTableParams &params, const int qpBdOffset)
1574
1.43k
{
1575
1.43k
  m_qpBdOffset = qpBdOffset;
1576
1.43k
  m_sameCQPTableForAllChromaFlag = params.m_sameCQPTableForAllChromaFlag;
1577
1578
5.72k
  for (int i = 0; i < VVENC_MAX_NUM_CQP_MAPPING_TABLES; i++)
1579
4.29k
  {
1580
4.29k
    m_qpTableStartMinus26[i] = params.m_qpTableStartMinus26[i];
1581
4.29k
    m_numPtsInCQPTableMinus1[i] = params.m_numPtsInCQPTableMinus1[i];
1582
4.29k
    memcpy(m_deltaQpInValMinus1[i], params.m_deltaQpInValMinus1[i], sizeof m_deltaQpInValMinus1[i]);
1583
4.29k
    memcpy(m_deltaQpOutVal[i], params.m_deltaQpOutVal[i], sizeof m_deltaQpOutVal[i]);
1584
4.29k
    m_chromaQpMappingTables[i].resize( MAX_QP + qpBdOffset + 1 );
1585
4.29k
  }
1586
1.43k
}
1587
1588
void ChromaQpMappingTable::derivedChromaQPMappingTables()
1589
1.43k
{
1590
2.86k
  for (int i = 0; i < m_numQpTables; i++)
1591
1.43k
  {
1592
1.43k
    const int qpBdOffsetC = m_qpBdOffset;
1593
1.43k
    const int numPtsInCQPTableMinus1 = m_numPtsInCQPTableMinus1[i];
1594
1.43k
    std::vector<int> qpInVal(numPtsInCQPTableMinus1 + 2), qpOutVal(numPtsInCQPTableMinus1 + 2);
1595
1596
1.43k
    qpInVal[0] = m_qpTableStartMinus26[i] + 26;
1597
1.43k
    qpOutVal[0] = qpInVal[0];
1598
5.72k
    for (int j = 0; j <= m_numPtsInCQPTableMinus1[i]; j++)
1599
4.29k
    {
1600
4.29k
      qpInVal[j+1] = qpInVal[j] + m_deltaQpInValMinus1[i][j] + 1;
1601
4.29k
      qpOutVal[j+1] = qpOutVal[j] + m_deltaQpOutVal[i][j];
1602
4.29k
    }
1603
1604
5.72k
    for (int j = 0; j <= m_numPtsInCQPTableMinus1[i]; j++)
1605
4.29k
    {
1606
4.29k
      CHECK(qpInVal[j]  < -qpBdOffsetC || qpInVal[j]  > MAX_QP, "qpInVal out of range");
1607
4.29k
      CHECK(qpOutVal[j] < -qpBdOffsetC || qpOutVal[j] > MAX_QP, "qpOutVal out of range");
1608
4.29k
    }
1609
1610
1.43k
    m_chromaQpMappingTables[i][qpInVal[0] + qpBdOffsetC] = qpOutVal[0];
1611
25.7k
    for (int k = qpInVal[0] - 1; k >= -qpBdOffsetC; k--)
1612
24.3k
    {
1613
24.3k
      m_chromaQpMappingTables[i][k + qpBdOffsetC] = Clip3(-qpBdOffsetC, MAX_QP, m_chromaQpMappingTables[i][k + 1 + qpBdOffsetC] - 1);
1614
24.3k
    }
1615
5.72k
    for (int j = 0; j <= numPtsInCQPTableMinus1; j++)
1616
4.29k
    {
1617
4.29k
      int sh = (m_deltaQpInValMinus1[i][j] + 1) >> 1;
1618
40.0k
      for (int k = qpInVal[j] + 1, m = 1; k <= qpInVal[j + 1]; k++, m++)
1619
35.8k
      {
1620
35.8k
        m_chromaQpMappingTables[i][k + qpBdOffsetC] = m_chromaQpMappingTables[i][qpInVal[j] + qpBdOffsetC]
1621
35.8k
          + ((qpOutVal[j + 1] - qpOutVal[j]) * m + sh) / (m_deltaQpInValMinus1[i][j]+ 1);
1622
35.8k
      }
1623
4.29k
    }
1624
31.5k
    for (int k = qpInVal[numPtsInCQPTableMinus1+1]+1; k <= MAX_QP; k++)
1625
30.0k
    {
1626
30.0k
      m_chromaQpMappingTables[i][k + qpBdOffsetC] = Clip3(-qpBdOffsetC, MAX_QP, m_chromaQpMappingTables[i][k - 1 + qpBdOffsetC] + 1);
1627
30.0k
    }
1628
1.43k
  }
1629
1.43k
}
1630
1631
1632
PPS::PPS()
1633
1.43k
: ppsId                              (0)
1634
1.43k
, spsId                              (0)
1635
1.43k
, picInitQPMinus26                   (0)
1636
1.43k
, useDQP                             (false)
1637
1.43k
, usePPSChromaTool                   (false)
1638
1.43k
, sliceChromaQpFlag                  (false)
1639
1.43k
, layerId                            (0)
1640
1.43k
, temporalId                         (0)
1641
1.43k
, chromaQpOffset                     { 0 }
1642
1.43k
, jointCbCrQpOffsetPresent           (false)
1643
1.43k
, chromaQpOffsetListLen              (0)
1644
1.43k
, numRefIdxL0DefaultActive           (1)
1645
1.43k
, numRefIdxL1DefaultActive           (1)
1646
1.43k
, rpl1IdxPresent                     (false)
1647
1.43k
, weightPred                         (false)
1648
1.43k
, weightedBiPred                     (0)
1649
1.43k
, outputFlagPresent                  (false)
1650
1.43k
, numSubPics                         (0)
1651
1.43k
, subPicIdMappingInPps               (false)
1652
1.43k
, subPicIdLen                        (0)
1653
//,   subPicId[MAX_NUM_SUB_PICS];        //!< sub-picture ID for each sub-picture in the sequence
1654
1.43k
, noPicPartition                     (false)
1655
1.43k
, log2CtuSize                        (0)
1656
1.43k
, ctuSize                            (0)
1657
1.43k
, picWidthInCtu                      (0)
1658
1.43k
, picHeightInCtu                     (0)
1659
1.43k
, numExpTileCols                     (1)
1660
1.43k
, numExpTileRows                     (1)
1661
1.43k
, numTileCols                        (1)
1662
1.43k
, numTileRows                        (1)
1663
1.43k
, rectSlice                          (true)
1664
1.43k
, singleSlicePerSubPic               (false)
1665
1.43k
, numSlicesInPic                     (1)
1666
1.43k
, tileIdxDeltaPresent                (false)
1667
1.43k
, loopFilterAcrossTilesEnabled       (false)
1668
1.43k
, loopFilterAcrossSlicesEnabled      (false)
1669
1.43k
, cabacInitPresent                   (false)
1670
1.43k
, pictureHeaderExtensionPresent      (false)
1671
1.43k
, sliceHeaderExtensionPresent        (false)
1672
1.43k
, deblockingFilterControlPresent     (true)
1673
1.43k
, deblockingFilterOverrideEnabled    (0)
1674
1.43k
, deblockingFilterDisabled           (true)
1675
1.43k
, deblockingFilterBetaOffsetDiv2     {0}
1676
1.43k
, deblockingFilterTcOffsetDiv2       {0}
1677
1.43k
, listsModificationPresent           (false)
1678
1.43k
, rplInfoInPh                        (false)
1679
1.43k
, dbfInfoInPh                        (false)
1680
1.43k
, saoInfoInPh                        (false)
1681
1.43k
, alfInfoInPh                        (false)
1682
1.43k
, wpInfoInPh                         (false)
1683
1.43k
, qpDeltaInfoInPh                    (false)
1684
1.43k
, mixedNaluTypesInPic                (false)
1685
1.43k
, picWidthInLumaSamples              (0)
1686
1.43k
, picHeightInLumaSamples             (0)
1687
1.43k
, wrapAroundEnabled                  (false)
1688
1.43k
, picWidthMinusWrapAroundOffset      (0)
1689
1.43k
, wrapAroundOffset                   (0)
1690
1.43k
, pcv                                (NULL)
1691
1.43k
{
1692
1.43k
  chromaQpAdjTableIncludingNullEntry[0].u.comp.CbOffset = 0; // Array includes entry [0] for the null offset used when cu_chroma_qp_offset_flag=0. This is initialised here and never subsequently changed.
1693
1.43k
  chromaQpAdjTableIncludingNullEntry[0].u.comp.CrOffset = 0;
1694
1.43k
  chromaQpAdjTableIncludingNullEntry[0].u.comp.JointCbCrOffset = 0;
1695
1.43k
}
1696
1697
PPS::~PPS()
1698
1.43k
{
1699
1.43k
  delete pcv;
1700
1.43k
}
1701
1702
/**
1703
 - initialize tile row/column sizes and boundaries
1704
 */
1705
void PPS::initTiles()
1706
1.43k
{
1707
1.43k
  int colIdx, rowIdx;
1708
1.43k
  int ctuX, ctuY;
1709
1710
  // check explicit tile column sizes
1711
1.43k
  uint32_t  remainingWidthInCtu  = picWidthInCtu;
1712
2.86k
  for( colIdx = 0; colIdx < numExpTileCols; colIdx++ )
1713
1.43k
  {
1714
1.43k
    CHECK(tileColWidth[colIdx] > remainingWidthInCtu,    "Tile column width exceeds picture width");
1715
1.43k
    remainingWidthInCtu -= tileColWidth[colIdx];
1716
1.43k
  }
1717
1718
  // divide remaining picture width into uniform tile columns
1719
1.43k
  uint32_t  uniformTileColWidth = tileColWidth[colIdx-1];
1720
1.43k
  while( remainingWidthInCtu > 0 )
1721
0
  {
1722
0
    CHECK(colIdx >= MAX_TILE_COLS, "Number of tile columns exceeds valid range");
1723
0
    uniformTileColWidth = std::min(remainingWidthInCtu, uniformTileColWidth);
1724
0
    tileColWidth.push_back( uniformTileColWidth );
1725
0
    remainingWidthInCtu -= uniformTileColWidth;
1726
0
    colIdx++;
1727
0
  }
1728
1.43k
  numTileCols = colIdx;
1729
1730
  // check explicit tile row sizes
1731
1.43k
  uint32_t  remainingHeightInCtu  = picHeightInCtu;
1732
2.86k
  for( rowIdx = 0; rowIdx < numExpTileRows; rowIdx++ )
1733
1.43k
  {
1734
1.43k
    CHECK(tileRowHeight[rowIdx] > remainingHeightInCtu,     "Tile row height exceeds picture height");
1735
1.43k
    remainingHeightInCtu -= tileRowHeight[rowIdx];
1736
1.43k
  }
1737
1738
  // divide remaining picture height into uniform tile rows
1739
1.43k
  uint32_t  uniformTileRowHeight = tileRowHeight[rowIdx - 1];
1740
1.43k
  while( remainingHeightInCtu > 0 )
1741
0
  {
1742
0
    uniformTileRowHeight = std::min(remainingHeightInCtu, uniformTileRowHeight);
1743
0
    tileRowHeight.push_back( uniformTileRowHeight );
1744
0
    remainingHeightInCtu -= uniformTileRowHeight;
1745
0
    rowIdx++;
1746
0
  }
1747
1.43k
  numTileRows = rowIdx;
1748
1749
  // set left column bounaries
1750
1.43k
  tileColBd.push_back( 0 );
1751
2.86k
  for( colIdx = 0; colIdx < numTileCols; colIdx++ )
1752
1.43k
  {
1753
1.43k
    tileColBd.push_back( tileColBd[ colIdx ] + tileColWidth[ colIdx ] );
1754
1.43k
  }
1755
1756
  // set top row bounaries
1757
1.43k
  tileRowBd.push_back( 0 );
1758
2.86k
  for( rowIdx = 0; rowIdx < numTileRows; rowIdx++ )
1759
1.43k
  {
1760
1.43k
    tileRowBd.push_back( tileRowBd[ rowIdx ] + tileRowHeight[ rowIdx ] );
1761
1.43k
  }
1762
1763
  // set right column bounaries
1764
2.86k
  for( colIdx = 0; colIdx < numTileCols; colIdx++ )
1765
1.43k
  {
1766
1.43k
    tileColBdRgt.push_back( std::min( ( tileColBd[ colIdx ] + tileColWidth[ colIdx ] ) << log2CtuSize, picWidthInLumaSamples ) );
1767
1.43k
  }
1768
1769
  // set bottom row bounaries
1770
2.86k
  for( rowIdx = 0; rowIdx < numTileRows; rowIdx++ )
1771
1.43k
  {
1772
1.43k
    tileRowBdBot.push_back( std::min( ( tileRowBd[ rowIdx ] + tileRowHeight[ rowIdx ] ) << log2CtuSize, picHeightInLumaSamples ) );
1773
1.43k
  }
1774
1775
  // set mapping between horizontal CTU address and tile column index
1776
1.43k
  colIdx = 0;
1777
5.35k
  for( ctuX = 0; ctuX <= picWidthInCtu; ctuX++ )
1778
3.92k
  {
1779
3.92k
    if( ctuX == tileColBd[ colIdx + 1 ] )
1780
1.43k
    {
1781
1.43k
      colIdx++;
1782
1.43k
    }
1783
3.92k
    ctuToTileCol.push_back( colIdx );
1784
3.92k
  }
1785
1786
  // set mapping between vertical CTU address and tile row index
1787
1.43k
  rowIdx = 0;
1788
5.42k
  for( ctuY = 0; ctuY <= picHeightInCtu; ctuY++ )
1789
3.99k
  {
1790
3.99k
    if( ctuY == tileRowBd[ rowIdx + 1 ] )
1791
1.43k
    {
1792
1.43k
      rowIdx++;
1793
1.43k
    }
1794
3.99k
    ctuToTileRow.push_back( rowIdx );
1795
3.99k
  }
1796
1.43k
}
1797
1798
/**
1799
 - initialize memory for rectangular slice parameters
1800
 */
1801
void PPS::initRectSliceMap( const SPS* sps )
1802
0
{
1803
  //currently only one slice is allowed
1804
0
  if( sps )
1805
0
  {
1806
0
    CHECK( sps->numSubPics > 1, "SubPic encoding not yet supported" );
1807
0
  }
1808
  
1809
0
  CHECK( numSlicesInPic > MAX_SLICES, "Number of slices in picture exceeds valid range" );
1810
0
  sliceMap.resize( numSlicesInPic );
1811
1812
0
  sliceMap[0].initSliceMap();
1813
  
1814
0
  uint32_t tileX = 0, tileY = 0;  
1815
0
  for( uint32_t j = 0; j < numTileRows; j++ )
1816
0
  {
1817
0
    for( uint32_t k = 0; k < numTileCols; k++ )
1818
0
    {
1819
0
      sliceMap[0].addCtusToSlice( tileColBd[tileX + k], tileColBd[tileX + k +1],
1820
0
                                  tileRowBd[tileY + j], tileRowBd[tileY + j +1], picWidthInCtu );
1821
0
    }
1822
0
  }
1823
1824
0
  checkSliceMap();
1825
0
}
1826
1827
void PPS::checkSliceMap()
1828
0
{
1829
0
  uint32_t i;
1830
0
  std::vector<int>  ctuList, sliceList;
1831
0
  uint32_t picSizeInCtu = picWidthInCtu * picHeightInCtu;
1832
0
  for( i = 0; i < numSlicesInPic; i++ )
1833
0
  {
1834
0
    sliceList = sliceMap[ i ].ctuAddrInSlice;
1835
0
    ctuList.insert( ctuList.end(), sliceList.begin(), sliceList.end() );
1836
0
  }
1837
0
  CHECK( ctuList.size() < picSizeInCtu, "Slice map contains too few CTUs");
1838
0
  CHECK( ctuList.size() > picSizeInCtu, "Slice map contains too many CTUs");
1839
0
  std::sort( ctuList.begin(), ctuList.end() );
1840
0
  for( i = 1; i < ctuList.size(); i++ )
1841
0
  {
1842
0
    CHECK( ctuList[i] > ctuList[i-1]+1, "CTU missing in slice map");
1843
0
    CHECK( ctuList[i] == ctuList[i-1],  "CTU duplicated in slice map");
1844
0
  }
1845
0
}
1846
1847
int Slice::getNumEntryPoints( const SPS& sps, const PPS& pps ) const
1848
1.43k
{
1849
1.43k
  if (!sps.entryPointsPresent )
1850
0
  {
1851
0
    return 0;
1852
0
  }
1853
1854
1.43k
  uint32_t ctuAddr, ctuX, ctuY, prevCtuX = 0, prevCtuY = 0;
1855
1.43k
  int numEntryPoints = 0;
1856
1857
  // count the number of CTUs that align with either the start of a tile, or with an entropy coding sync point
1858
  // ignore the first CTU since it doesn't count as an entry point
1859
6.08k
  for( uint32_t i = 0; i < sliceMap.numCtuInSlice; i++ )
1860
4.65k
  {
1861
4.65k
    ctuAddr = sliceMap.ctuAddrInSlice[i];
1862
4.65k
    ctuX = ( ctuAddr % pps.picWidthInCtu );
1863
4.65k
    ctuY = ( ctuAddr / pps.picWidthInCtu );
1864
1865
4.65k
    if( i != 0 && ( pps.tileRowBd[pps.ctuToTileRow[ctuY]] != pps.tileRowBd[pps.ctuToTileRow[prevCtuY]] || pps.tileColBd[pps.ctuToTileCol[ctuX]] != pps.tileColBd[pps.ctuToTileCol[prevCtuX]] || ( ctuY != prevCtuY && sps.entropyCodingSyncEnabled ) ) )
1866
0
    {
1867
0
      numEntryPoints++;
1868
0
    }
1869
    
1870
4.65k
    prevCtuX    = ctuX;
1871
4.65k
    prevCtuY    = ctuY;
1872
4.65k
  }
1873
1.43k
  return numEntryPoints;
1874
1.43k
}
1875
1876
1877
uint32_t PPS::getSubPicIdxFromSubPicId( uint32_t subPicId ) const
1878
1.43k
{
1879
1.43k
  for (int i = 0; i < numSubPics; i++)
1880
0
  {
1881
0
    if(subPics[i].subPicID == subPicId)
1882
0
    {
1883
0
      return i;
1884
0
    }
1885
0
  }
1886
1.43k
  return 0;
1887
1.43k
}
1888
1889
1890
const SubPic& PPS::getSubPicFromPos(const Position& pos)  const
1891
64.7k
{
1892
64.7k
  for (int i = 0; i< numSubPics; i++)
1893
0
  {
1894
0
    if (subPics[i].isContainingPos(pos))
1895
0
    {
1896
0
      return subPics[i];
1897
0
    }
1898
0
  }
1899
64.7k
  return subPics[0];
1900
64.7k
}
1901
1902
1903
const SubPic& PPS::getSubPicFromCU(const CodingUnit& cu) const
1904
4.68k
{
1905
4.68k
  const Position lumaPos = cu.Y().valid() ? cu.Y().pos() : recalcPosition(cu.chromaFormat, cu.chType, CH_L, cu.blocks[cu.chType].pos());
1906
4.68k
  return getSubPicFromPos(lumaPos);
1907
4.68k
}
1908
1909
1910
ReferencePictureList::ReferencePictureList()
1911
146k
  : numberOfShorttermPictures (0)
1912
146k
  , numberOfLongtermPictures  (0)
1913
146k
  , numberOfActivePictures    (0)
1914
146k
  , ltrpInSliceHeader         (0)
1915
146k
  , interLayerPresent     (false)
1916
146k
  , numberOfInterLayerPictures(0)
1917
1918
146k
{
1919
146k
  ::memset(isLongtermRefPic,    0, sizeof(isLongtermRefPic));
1920
146k
  ::memset(refPicIdentifier,    0, sizeof(refPicIdentifier));
1921
146k
  ::memset(deltaPocMSBCycleLT,  0, sizeof(deltaPocMSBCycleLT));
1922
146k
  ::memset(deltaPocMSBPresent,  0, sizeof(deltaPocMSBPresent));
1923
146k
  ::memset(POC,                 0, sizeof(POC));
1924
146k
  ::memset(isInterLayerRefPic,  0, sizeof(isInterLayerRefPic));
1925
146k
  ::memset(interLayerRefPicIdx, 0, sizeof(interLayerRefPicIdx));
1926
146k
}
1927
1928
void ReferencePictureList::initFromGopEntry( const GOPEntry& gopEntry, int l )
1929
68.7k
{
1930
68.7k
  *this = ReferencePictureList();
1931
68.7k
  numberOfShorttermPictures = gopEntry.m_numRefPics[ l ];
1932
68.7k
  numberOfLongtermPictures  = 0;
1933
68.7k
  numberOfActivePictures    = gopEntry.m_numRefPicsActive[ l ];
1934
236k
  for( int j = 0; j < gopEntry.m_numRefPics[ l ]; j++ )
1935
167k
  {
1936
167k
    setRefPicIdentifier( j, -gopEntry.m_deltaRefPics[ l ][ j ], 0, false, 0 );
1937
167k
  }
1938
68.7k
}
1939
1940
void ReferencePictureList::setRefPicIdentifier(int idx, int identifier, bool isLongterm, bool _isInterLayerRefPic, int interLayerIdx)
1941
167k
{
1942
167k
  refPicIdentifier[idx] = identifier;
1943
167k
  isLongtermRefPic[idx] = isLongterm;
1944
1945
167k
  deltaPocMSBPresent[idx] = false;
1946
167k
  deltaPocMSBCycleLT[idx] = 0;
1947
1948
167k
  isInterLayerRefPic[idx] = _isInterLayerRefPic;
1949
167k
  interLayerRefPicIdx[idx] = interLayerIdx;
1950
167k
}
1951
1952
bool ReferencePictureList::isPOCInRefPicList( const int poc, const int currPoc ) const
1953
0
{
1954
0
  for (int i = 0; i < numberOfLongtermPictures + numberOfShorttermPictures; i++)
1955
0
  {
1956
0
    if (isLongtermRefPic[i] ? (poc == refPicIdentifier[i]) : (poc == currPoc - refPicIdentifier[i]) )
1957
0
    {
1958
0
      return true;
1959
0
    }
1960
0
  }
1961
0
  return false;
1962
0
}
1963
1964
1965
ParameterSetManager::ParameterSetManager()
1966
0
: m_spsMap      (MAX_NUM_SPS)
1967
0
, m_ppsMap      (MAX_NUM_PPS)
1968
0
, m_apsMap      (MAX_NUM_APS * MAX_NUM_APS_TYPE)
1969
0
, m_dciMap      (MAX_NUM_DCI)
1970
0
, m_vpsMap      (MAX_NUM_VPS)
1971
0
, m_activeDCIId (-1)
1972
0
, m_activeSPSId (-1)
1973
0
, m_activeVPSId (-1)
1974
0
{
1975
0
}
1976
1977
1978
ParameterSetManager::~ParameterSetManager()
1979
0
{
1980
0
}
1981
1982
1983
//! activate a PPS and depending on isIDR parameter also SPS
1984
//! \returns true, if activation is successful
1985
ParameterSetManager::PPSErrCodes ParameterSetManager::activatePPS(int ppsId, bool isIRAP)
1986
0
{
1987
0
  PPSErrCodes ret=PPS_OK;
1988
1989
0
  PPS *pps = m_ppsMap.getPS(ppsId);
1990
0
  if (pps)
1991
0
  {
1992
0
    int spsId = pps->spsId;
1993
0
    if (!isIRAP && (spsId != m_activeSPSId ))
1994
0
    {
1995
0
      ret=PPS_ERR_INACTIVE_SPS;
1996
0
    }
1997
0
    else
1998
0
    {
1999
0
      SPS *sps = m_spsMap.getPS(spsId);
2000
0
      if (sps)
2001
0
      {
2002
0
        int dciId = sps->dciId;
2003
0
        if ((m_activeDCIId!=-1) && (dciId != m_activeDCIId ))
2004
0
        {
2005
0
          ret=PPS_WARN_DCI_ID;
2006
0
        }
2007
0
        else
2008
0
        {
2009
0
          if (dciId != 0)
2010
0
          {
2011
0
            DCI *dci =m_dciMap.getPS(dciId);
2012
0
            if (dci)
2013
0
            {
2014
0
              m_activeDCIId = dciId;
2015
0
              m_dciMap.setActive(dciId);
2016
0
            }
2017
0
            else
2018
0
            {
2019
0
              ret=PPS_WARN_NO_DCI;
2020
0
            }
2021
0
          }
2022
0
          else
2023
0
          {
2024
            // set zero as active DCI ID (special reserved value, no actual DCI)
2025
0
            m_activeDCIId = dciId;
2026
0
            m_dciMap.setActive(dciId);
2027
0
          }
2028
0
        }
2029
2030
0
        m_spsMap.clearActive();
2031
0
        m_spsMap.setActive(spsId);
2032
0
        m_activeSPSId = spsId;
2033
0
        m_ppsMap.clearActive();
2034
0
        m_ppsMap.setActive(ppsId);
2035
0
        return ret;
2036
0
      }
2037
0
      else
2038
0
      {
2039
0
        ret=PPS_ERR_NO_SPS;
2040
0
      }
2041
0
    }
2042
0
  }
2043
0
  else
2044
0
  {
2045
0
    ret=PPS_ERR_NO_PPS;
2046
0
  }
2047
2048
  // Failed to activate if reach here.
2049
0
  m_activeSPSId=-1;
2050
0
  m_activeDCIId=-1;
2051
0
  return ret;
2052
0
}
2053
2054
bool ParameterSetManager::activateAPS(int apsId, int apsType)
2055
0
{
2056
0
  APS *aps = m_apsMap.getPS((apsId << NUM_APS_TYPE_LEN) + apsType);
2057
0
  if (aps)
2058
0
  {
2059
0
    m_apsMap.setActive((apsId << NUM_APS_TYPE_LEN) + apsType);
2060
0
    return true;
2061
0
  }
2062
2063
0
  return false;
2064
0
}
2065
2066
template <>
2067
void ParameterSetMap<APS>::setID(APS* parameterSet, const int psId)
2068
0
{
2069
0
  parameterSet->apsId = psId;
2070
0
}
2071
template <>
2072
void ParameterSetMap<PPS>::setID(PPS* parameterSet, const int psId)
2073
1.43k
{
2074
1.43k
  parameterSet->ppsId = psId;
2075
1.43k
}
2076
2077
template <>
2078
void ParameterSetMap<SPS>::setID(SPS* parameterSet, const int psId)
2079
1.43k
{
2080
1.43k
  parameterSet->spsId = psId;
2081
1.43k
}
2082
2083
void calculateParameterSetChangedFlag(bool& bChanged, const std::vector<uint8_t>* pOldData, const std::vector<uint8_t>* pNewData)
2084
0
{
2085
0
  if (!bChanged)
2086
0
  {
2087
0
    if ((pOldData==0 && pNewData!=0) || (pOldData!=0 && pNewData==0))
2088
0
    {
2089
0
      bChanged=true;
2090
0
    }
2091
0
    else if (pOldData!=0 && pNewData!=0)
2092
0
    {
2093
      // compare the two
2094
0
      if (pOldData->size() != pNewData->size())
2095
0
      {
2096
0
        bChanged=true;
2097
0
      }
2098
0
      else
2099
0
      {
2100
0
        const uint8_t *pNewDataArray=&(*pNewData)[0];
2101
0
        const uint8_t *pOldDataArray=&(*pOldData)[0];
2102
0
        if (memcmp(pOldDataArray, pNewDataArray, pOldData->size()))
2103
0
        {
2104
0
          bChanged=true;
2105
0
        }
2106
0
      }
2107
0
    }
2108
0
  }
2109
0
}
2110
2111
//! \}
2112
2113
uint32_t PreCalcValues::getValIdx( const Slice &slice, const ChannelType chType ) const
2114
759k
{
2115
759k
  return slice.isIntra() ? ( ISingleTree ? 0 : ( chType << 1 ) ) : 1;
2116
759k
}
2117
2118
uint32_t PreCalcValues::getMaxMTTDepth( const Slice &slice, const ChannelType chType ) const
2119
622k
{
2120
622k
  if ( slice.picHeader->splitConsOverride )
2121
0
    { return slice.sliceType == VVENC_I_SLICE ? ((ISingleTree || CH_L == chType) ? slice.picHeader->maxMTTDepth[0] : slice.picHeader->maxMTTDepth[2]) : slice.picHeader->maxMTTDepth[1]; }
2122
622k
  else
2123
622k
    return maxMTTDepth[getValIdx( slice, chType )];
2124
622k
}
2125
2126
uint32_t PreCalcValues::getMinTSize( const Slice &slice, const ChannelType chType ) const
2127
27.9k
{
2128
27.9k
  return minTSize[getValIdx( slice, chType )];
2129
27.9k
}
2130
2131
uint32_t PreCalcValues::getMaxBtSize( const Slice &slice, const ChannelType chType ) const
2132
27.9k
{
2133
27.9k
  if (slice.picHeader->splitConsOverride)
2134
0
    return slice.picHeader->maxBTSize[getValIdx(slice, ISingleTree ? CH_L : chType)];
2135
27.9k
  else
2136
27.9k
    return maxBtSize[getValIdx(slice, chType)];
2137
27.9k
}
2138
2139
uint32_t PreCalcValues::getMaxTtSize( const Slice &slice, const ChannelType chType ) const
2140
27.9k
{
2141
27.9k
  if ( slice.picHeader->splitConsOverride )
2142
0
    return slice.picHeader->maxTTSize[getValIdx(slice, ISingleTree ? CH_L : chType)];
2143
27.9k
  else
2144
27.9k
    return maxTtSize[getValIdx( slice, chType )];
2145
27.9k
}
2146
2147
uint32_t PreCalcValues::getMinQtSize( const Slice &slice, const ChannelType chType ) const
2148
52.9k
{
2149
52.9k
  if ( slice.picHeader->splitConsOverride )
2150
0
    return slice.picHeader->minQTSize[getValIdx(slice, ISingleTree ? CH_L : chType)];
2151
52.9k
  else
2152
52.9k
    return minQtSize[getValIdx( slice, chType )];
2153
52.9k
}
2154
2155
Area PreCalcValues::getCtuArea( const int ctuPosX, const int ctuPosY ) const
2156
13.9k
{
2157
13.9k
  CHECKD( ctuPosX >= widthInCtus || ctuPosY >= heightInCtus, "CTU idx overflow" );
2158
13.9k
  const int x = ctuPosX << maxCUSizeLog2;
2159
13.9k
  const int y = ctuPosY << maxCUSizeLog2;
2160
13.9k
  const int width = std::min( maxCUSize, lumaWidth - x );
2161
13.9k
  const int height = std::min( maxCUSize, lumaHeight - y );
2162
13.9k
  return Area( x, y, width, height );
2163
13.9k
}
2164
2165
2166
void VPS::deriveOutputLayerSets()
2167
0
{
2168
0
  if( maxLayers == 1 )
2169
0
  {
2170
0
    totalNumOLSs = 1;
2171
0
  }
2172
0
  else if( eachLayerIsAnOls || olsModeIdc < 2 )
2173
0
  {
2174
0
    totalNumOLSs = maxLayers;
2175
0
  }
2176
0
  else if( olsModeIdc == 2 )
2177
0
  {
2178
0
    totalNumOLSs = numOutputLayerSets;
2179
0
  }
2180
2181
0
  olsDpbParamsIdx.resize( totalNumOLSs );
2182
0
  olsDpbPicSize.resize( totalNumOLSs, Size(0, 0) );
2183
0
  numOutputLayersInOls.resize( totalNumOLSs );
2184
0
  numLayersInOls.resize( totalNumOLSs );
2185
0
  outputLayerIdInOls.resize( totalNumOLSs, std::vector<int>( maxLayers, NOT_VALID ) );
2186
0
  layerIdInOls.resize( totalNumOLSs, std::vector<int>( maxLayers, NOT_VALID ) );
2187
2188
0
  std::vector<int> numRefLayers( maxLayers );
2189
0
  std::vector<std::vector<int>> outputLayerIdx( totalNumOLSs, std::vector<int>( maxLayers, NOT_VALID ) );
2190
0
  std::vector<std::vector<int>> layerIncludedInOlsFlag( totalNumOLSs, std::vector<int>( maxLayers, 0 ) );
2191
0
  std::vector<std::vector<int>> dependencyFlag( maxLayers, std::vector<int>( maxLayers, NOT_VALID ) );
2192
0
  std::vector<std::vector<int>> refLayerIdx( maxLayers, std::vector<int>( maxLayers, NOT_VALID ) );
2193
2194
0
  for( int i = 0; i < maxLayers; i++ )
2195
0
  {
2196
0
    int r = 0;
2197
2198
0
    for( int j = 0; j < maxLayers; j++ )
2199
0
    {
2200
0
      dependencyFlag[i][j] = directRefLayer[i][j];
2201
2202
0
      for( int k = 0; k < i; k++ )
2203
0
      {
2204
0
        if( directRefLayer[i][k] && dependencyFlag[k][j] )
2205
0
        {
2206
0
          dependencyFlag[i][j] = 1;
2207
0
        }
2208
0
      }
2209
2210
0
      if( dependencyFlag[i][j] )
2211
0
      {
2212
0
        refLayerIdx[i][r++] = j;
2213
0
      }
2214
0
    }
2215
2216
0
    numRefLayers[i] = r;
2217
0
  }
2218
2219
0
  numOutputLayersInOls[0] = 1;
2220
0
  outputLayerIdInOls[0][0] = layerId[0];
2221
2222
0
  for( int i = 1; i < totalNumOLSs; i++ )
2223
0
  {
2224
0
    if( eachLayerIsAnOls || olsModeIdc == 0 )
2225
0
    {
2226
0
      numOutputLayersInOls[i] = 1;
2227
0
      outputLayerIdInOls[i][0] = layerId[i];
2228
0
    }
2229
0
    else if( olsModeIdc == 1 )
2230
0
    {
2231
0
      numOutputLayersInOls[i] = i + 1;
2232
2233
0
      for( int j = 0; j < numOutputLayersInOls[i]; j++ )
2234
0
      {
2235
0
        outputLayerIdInOls[i][j] = layerId[j];
2236
0
      }
2237
0
    }
2238
0
    else if( olsModeIdc == 2 )
2239
0
    {
2240
0
      int j = 0;
2241
0
      for( int k = 0; k < maxLayers; k++ )
2242
0
      {
2243
0
        if( olsOutputLayer[i][k] )
2244
0
        {
2245
0
          layerIncludedInOlsFlag[i][k] = 1;
2246
0
          outputLayerIdx[i][j] = k;
2247
0
          outputLayerIdInOls[i][j++] = layerId[k];
2248
0
        }
2249
0
      }
2250
0
      numOutputLayersInOls[i] = j;
2251
2252
0
      for( j = 0; j < numOutputLayersInOls[i]; j++ )
2253
0
      {
2254
0
        int idx = outputLayerIdx[i][j];
2255
0
        for( int k = 0; k < numRefLayers[idx]; k++ )
2256
0
        {
2257
0
          layerIncludedInOlsFlag[i][refLayerIdx[idx][k]] = 1;
2258
0
        }
2259
0
      }
2260
0
    }
2261
0
  }
2262
2263
0
  numLayersInOls[0] = 1;
2264
0
  layerIdInOls[0][0] = layerId[0];
2265
2266
0
  for( int i = 1; i < totalNumOLSs; i++ )
2267
0
  {
2268
0
    if( eachLayerIsAnOls )
2269
0
    {
2270
0
      numLayersInOls[i] = 1;
2271
0
      layerIdInOls[i][0] = layerId[i];
2272
0
    }
2273
0
    else if( olsModeIdc == 0 || olsModeIdc == 1 )
2274
0
    {
2275
0
      numLayersInOls[i] = i + 1;
2276
0
      for( int j = 0; j < numLayersInOls[i]; j++ )
2277
0
      {
2278
0
        layerIdInOls[i][j] = layerId[j];
2279
0
      }
2280
0
    }
2281
0
    else if( olsModeIdc == 2 )
2282
0
    {
2283
0
      int j = 0;
2284
0
      for( int k = 0; k < maxLayers; k++ )
2285
0
      {
2286
0
        if( layerIncludedInOlsFlag[i][k] )
2287
0
        {
2288
0
          layerIdInOls[i][j++] = layerId[k];
2289
0
        }
2290
0
      }
2291
2292
0
      numLayersInOls[i] = j;
2293
0
    }
2294
0
  }
2295
0
}
2296
2297
} // namespace vvenc
2298
2299
//! \}
2300