Coverage Report

Created: 2026-04-01 07:49

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/vvenc/source/Lib/CommonLib/Slice.h
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
/** \file     Slice.h
43
    \brief    slice header and SPS class (header)
44
*/
45
46
#pragma once
47
48
#include "CommonDef.h"
49
#include "Rom.h"
50
#include "AlfParameters.h"
51
#include "Common.h"
52
#include "MotionInfo.h"
53
#include "HRD.h"
54
55
#include "vvenc/vvencCfg.h"
56
57
58
#include <cstring>
59
#include <list>
60
#include <map>
61
#include <vector>
62
#include <cstdint>
63
64
//! \ingroup CommonLib
65
//! \{
66
67
namespace vvenc {
68
69
struct  MotionInfo;
70
struct  Picture;
71
class   Pic;
72
class   TrQuant;
73
class   PreCalcValues;
74
typedef std::list<Picture*> PicList;
75
76
// ====================================================================================================================
77
// Constants
78
// ====================================================================================================================
79
static const uint32_t REF_PIC_LIST_NUM_IDX=32;
80
81
82
// ====================================================================================================================
83
// Class definition
84
// ====================================================================================================================
85
struct DpbParameters
86
{
87
  int maxDecPicBuffering     [VVENC_MAX_TLAYER] = { 0 };
88
  int numReorderPics         [VVENC_MAX_TLAYER] = { 0 };
89
  int maxLatencyIncreasePlus1[VVENC_MAX_TLAYER] = { 0 };
90
};
91
92
struct ReferencePictureList
93
{
94
  int       numberOfShorttermPictures;
95
  int       numberOfLongtermPictures;
96
  int       numberOfActivePictures;
97
  bool      isLongtermRefPic[VVENC_MAX_NUM_REF_PICS];
98
  int       refPicIdentifier[VVENC_MAX_NUM_REF_PICS];  //This can be delta POC for STRP or POC LSB for LTRP
99
  int       POC[VVENC_MAX_NUM_REF_PICS];
100
  uint32_t  deltaPocMSBCycleLT[VVENC_MAX_NUM_REF_PICS];
101
  bool      deltaPocMSBPresent[VVENC_MAX_NUM_REF_PICS];
102
  bool      ltrpInSliceHeader;
103
  bool      interLayerPresent;
104
  bool      isInterLayerRefPic[VVENC_MAX_NUM_REF_PICS];
105
  int       interLayerRefPicIdx[VVENC_MAX_NUM_REF_PICS];
106
  int       numberOfInterLayerPictures;
107
108
  ReferencePictureList();
109
110
  void     initFromGopEntry     ( const GOPEntry& gopEntry, int l );
111
  void     setRefPicIdentifier  ( int idx, int identifier, bool isLongterm, bool isInterLayerRefPic, int interLayerIdx );
112
0
  int      getNumRefEntries     ()  const { return numberOfShorttermPictures + numberOfLongtermPictures; }
113
  bool     isPOCInRefPicList    ( const int poc, const int currPoc ) const;
114
};
115
116
/// Reference Picture List set class
117
typedef std::vector<ReferencePictureList> RPLList;
118
119
struct ConstraintInfo
120
{
121
  bool      gciPresent;
122
  bool      noRprConstraintFlag;
123
  bool      noResChangeInClvsConstraintFlag;
124
  bool      oneTilePerPicConstraintFlag;
125
  bool      picHeaderInSliceHeaderConstraintFlag;
126
  bool      oneSlicePerPicConstraintFlag;
127
  bool      noIdrRplConstraintFlag;
128
  bool      noRectSliceConstraintFlag;
129
  bool      oneSlicePerSubpicConstraintFlag;
130
  bool      noSubpicInfoConstraintFlag;
131
  bool      intraOnlyConstraintFlag;
132
  uint32_t  maxBitDepthConstraintIdc;
133
  int       maxChromaFormatConstraintIdc;
134
  bool      onePictureOnlyConstraintFlag;
135
  bool      lowerBitRateConstraintFlag;
136
  bool      allLayersIndependentConstraintFlag;
137
  bool      noMrlConstraintFlag;
138
  bool      noIspConstraintFlag;
139
  bool      noMipConstraintFlag;
140
  bool      noLfnstConstraintFlag;
141
  bool      noMmvdConstraintFlag;
142
  bool      noSmvdConstraintFlag;
143
  bool      noProfConstraintFlag;
144
  bool      noPaletteConstraintFlag;
145
  bool      noActConstraintFlag;
146
  bool      noLmcsConstraintFlag;
147
  bool      noExplicitScaleListConstraintFlag;
148
  bool      noVirtualBoundaryConstraintFlag;
149
  bool      noMttConstraintFlag;
150
  bool      noChromaQpOffsetConstraintFlag;
151
  bool      noQtbttDualTreeIntraConstraintFlag;
152
  int       maxLog2CtuSizeConstraintIdc;
153
  bool      noPartitionConstraintsOverrideConstraintFlag;
154
  bool      noSaoConstraintFlag;
155
  bool      noAlfConstraintFlag;
156
  bool      noCCAlfConstraintFlag;
157
  bool      noWeightedPredictionConstraintFlag;
158
  bool      noRefWraparoundConstraintFlag;
159
  bool      noTemporalMvpConstraintFlag;
160
  bool      noSbtmvpConstraintFlag;
161
  bool      noAmvrConstraintFlag;
162
  bool      noBdofConstraintFlag;
163
  bool      noDmvrConstraintFlag;
164
  bool      noCclmConstraintFlag;
165
  bool      noMtsConstraintFlag;
166
  bool      noSbtConstraintFlag;
167
  bool      noAffineMotionConstraintFlag;
168
  bool      noBcwConstraintFlag;
169
  bool      noIbcConstraintFlag;
170
  bool      noCiipConstraintFlag;
171
  bool      noGeoConstraintFlag;
172
  bool      noLadfConstraintFlag;
173
  bool      noTransformSkipConstraintFlag;
174
  bool      noLumaTransformSize64ConstraintFlag;
175
  bool      noBDPCMConstraintFlag;
176
  bool      noJointCbCrConstraintFlag;
177
  bool      noQpDeltaConstraintFlag;
178
  bool      noDepQuantConstraintFlag;
179
  bool      noSignDataHidingConstraintFlag;
180
  bool      noMixedNaluTypesInPicConstraintFlag;
181
  bool      noTrailConstraintFlag;
182
  bool      noStsaConstraintFlag;
183
  bool      noRaslConstraintFlag;
184
  bool      noRadlConstraintFlag;
185
  bool      noIdrConstraintFlag;
186
  bool      noCraConstraintFlag;
187
  bool      noGdrConstraintFlag;
188
  bool      noApsConstraintFlag;
189
190
191
  ConstraintInfo()
192
0
    : gciPresent                                      ( false )
193
0
    , noRprConstraintFlag                             ( false )
194
0
    , noResChangeInClvsConstraintFlag                 ( false )
195
0
    , oneTilePerPicConstraintFlag                     ( false )
196
0
    , picHeaderInSliceHeaderConstraintFlag            ( false )
197
0
    , oneSlicePerPicConstraintFlag                    ( false )
198
0
    , noIdrRplConstraintFlag                          ( false )
199
0
    , noRectSliceConstraintFlag                       ( false )
200
0
    , oneSlicePerSubpicConstraintFlag                 ( false )
201
0
    , noSubpicInfoConstraintFlag                      ( false )
202
0
    , intraOnlyConstraintFlag                         ( false )
203
0
    , maxBitDepthConstraintIdc                        ( false )
204
0
    , maxChromaFormatConstraintIdc                    ( CHROMA_420 )
205
0
    , onePictureOnlyConstraintFlag                    ( false )
206
0
    , lowerBitRateConstraintFlag                      ( false )
207
0
    , allLayersIndependentConstraintFlag              ( false )
208
0
    , noMrlConstraintFlag                             ( false )
209
0
    , noIspConstraintFlag                             ( false )
210
0
    , noMipConstraintFlag                             ( false )
211
0
    , noLfnstConstraintFlag                           ( false )
212
0
    , noMmvdConstraintFlag                            ( false )
213
0
    , noSmvdConstraintFlag                            ( false )
214
0
    , noProfConstraintFlag                            ( false )
215
0
    , noPaletteConstraintFlag                         ( false )
216
0
    , noActConstraintFlag                             ( false )
217
0
    , noLmcsConstraintFlag                            ( false )
218
0
    , noExplicitScaleListConstraintFlag               ( false )
219
0
    , noVirtualBoundaryConstraintFlag                 ( false )
220
0
    , noMttConstraintFlag                             ( false )
221
0
    , noChromaQpOffsetConstraintFlag                  ( false )
222
0
    , noQtbttDualTreeIntraConstraintFlag              ( false )
223
0
    , maxLog2CtuSizeConstraintIdc                     ( 0 )
224
0
    , noPartitionConstraintsOverrideConstraintFlag    ( false )
225
0
    , noSaoConstraintFlag                             ( false )
226
0
    , noAlfConstraintFlag                             ( false )
227
0
    , noCCAlfConstraintFlag                           ( false )
228
0
    , noWeightedPredictionConstraintFlag              ( false )
229
0
    , noRefWraparoundConstraintFlag                   ( false )
230
0
    , noTemporalMvpConstraintFlag                     ( false )
231
0
    , noSbtmvpConstraintFlag                          ( false )
232
0
    , noAmvrConstraintFlag                            ( false )
233
0
    , noBdofConstraintFlag                            ( false )
234
0
    , noDmvrConstraintFlag                            ( false )
235
0
    , noCclmConstraintFlag                            ( false )
236
0
    , noMtsConstraintFlag                             ( false )
237
0
    , noSbtConstraintFlag                             ( false )
238
0
    , noAffineMotionConstraintFlag                    ( false )
239
0
    , noBcwConstraintFlag                             ( false )
240
0
    , noIbcConstraintFlag                             ( false )
241
0
    , noCiipConstraintFlag                            ( false )
242
0
    , noGeoConstraintFlag                             ( false )
243
0
    , noLadfConstraintFlag                            ( false )
244
0
    , noTransformSkipConstraintFlag                   ( false )
245
0
    , noLumaTransformSize64ConstraintFlag             ( false )
246
0
    , noBDPCMConstraintFlag                           ( false )
247
0
    , noJointCbCrConstraintFlag                       ( false )
248
0
    , noQpDeltaConstraintFlag                         ( false )
249
0
    , noDepQuantConstraintFlag                        ( false )
250
0
    , noSignDataHidingConstraintFlag                  ( false )
251
0
    , noMixedNaluTypesInPicConstraintFlag             ( false )
252
0
    , noTrailConstraintFlag                           ( false )
253
0
    , noStsaConstraintFlag                            ( false )
254
0
    , noRaslConstraintFlag                            ( false )
255
0
    , noRadlConstraintFlag                            ( false )
256
0
    , noIdrConstraintFlag                             ( false )
257
0
    , noCraConstraintFlag                             ( false )
258
0
    , noGdrConstraintFlag                             ( false )
259
0
    , noApsConstraintFlag                             ( false )
260
0
  {}
261
};
262
263
struct ProfileTierLevel
264
{
265
  vvencTier             tierFlag;
266
  vvencProfile          profileIdc;
267
  uint8_t               numSubProfile;
268
  std::vector<uint32_t> subProfileIdc;
269
  vvencLevel                 levelIdc;
270
  bool                  frameOnlyConstraintFlag;
271
  bool                  multiLayerEnabledFlag;
272
  ConstraintInfo        constraintInfo;
273
  bool                  subLayerLevelPresent[VVENC_MAX_TLAYER - 1];
274
  vvencLevel            subLayerLevelIdc[VVENC_MAX_TLAYER - 1];
275
276
  ProfileTierLevel()
277
0
    : tierFlag        ( VVENC_TIER_MAIN )
278
0
    , profileIdc      ( VVENC_PROFILE_AUTO )
279
0
    , numSubProfile   (0)
280
0
    , subProfileIdc   (0)
281
0
    , levelIdc        ( VVENC_LEVEL_AUTO )
282
0
    , frameOnlyConstraintFlag ( true )
283
0
    , multiLayerEnabledFlag   ( false )
284
0
  {
285
0
    ::memset( subLayerLevelPresent, 0, sizeof(subLayerLevelPresent ));
286
0
    ::memset( subLayerLevelIdc,     0, sizeof(subLayerLevelIdc ));
287
0
  }
288
};
289
290
291
struct LmcsParam
292
{
293
  LmcsParam()
294
0
  : sliceReshaperEnabled( false )
295
0
  , sliceReshaperModelPresent( false )
296
0
  , enableChromaAdj(0)
297
0
  , reshaperModelMinBinIdx(0)
298
0
  , reshaperModelMaxBinIdx(0)
299
0
  , reshaperModelBinCWDelta { 0 }
300
0
  , maxNbitsNeededDeltaCW (0)
301
0
  , chrResScalingOffset (0)
302
0
  {
303
0
  }
304
305
  bool      sliceReshaperEnabled;
306
  bool      sliceReshaperModelPresent;
307
  unsigned  enableChromaAdj;
308
  uint32_t  reshaperModelMinBinIdx;
309
  uint32_t  reshaperModelMaxBinIdx;
310
  int       reshaperModelBinCWDelta[PIC_CODE_CW_BINS];
311
  int       maxNbitsNeededDeltaCW;
312
  int       chrResScalingOffset;
313
};
314
315
316
struct ChromaQpAdj
317
{
318
  union
319
  {
320
    struct {
321
      int CbOffset;
322
      int CrOffset;
323
      int JointCbCrOffset;
324
    } comp;
325
    int offset[3];
326
  } u;
327
};
328
329
struct ChromaQpMappingTable : vvencChromaQpMappingTableParams
330
{
331
0
  int       getMappedChromaQpValue(ComponentID compID, const int qpVal)  const { return m_chromaQpMappingTables[m_sameCQPTableForAllChromaFlag ? 0 : (int)compID - 1].at(qpVal + m_qpBdOffset); }
332
  void      derivedChromaQPMappingTables();
333
  void      setParams(const vvencChromaQpMappingTableParams &params, const int qpBdOffset);
334
private:
335
  std::vector<int> m_chromaQpMappingTables[VVENC_MAX_NUM_CQP_MAPPING_TABLES];
336
};
337
338
struct SliceMap
339
{
340
  uint32_t               sliceID;                           //!< slice identifier (slice index for rectangular slices, slice address for raser-scan slices)
341
  uint32_t               numTilesInSlice;                   //!< number of tiles in slice (raster-scan slices only)
342
  uint32_t               numCtuInSlice;                     //!< number of CTUs in the slice
343
  std::vector<int>       ctuAddrInSlice;                    //!< raster-scan addresses of all the CTUs in the slice
344
345
  SliceMap()
346
0
   : sliceID            ( 0 )
347
0
   , numTilesInSlice    ( 0 )
348
0
   , numCtuInSlice      ( 0 )
349
0
   , ctuAddrInSlice     ( )
350
0
  {
351
0
  }
352
353
  void  initSliceMap()
354
0
  {
355
0
    sliceID = 0;
356
0
    numTilesInSlice = 0;
357
0
    numCtuInSlice = 0;
358
0
    ctuAddrInSlice.clear();
359
0
  }
360
361
  void  addCtusToSlice( uint32_t startX, uint32_t stopX, uint32_t startY, uint32_t stopY, uint32_t picWidthInCtbsY )
362
0
  {
363
0
    CHECK( startX >= stopX || startY >= stopY, "Invalid slice definition");
364
0
    for( uint32_t ctbY = startY; ctbY < stopY; ctbY++ )
365
0
    {
366
0
      for( uint32_t ctbX = startX; ctbX < stopX; ctbX++ )
367
0
      {
368
0
        ctuAddrInSlice.push_back( ctbY * picWidthInCtbsY + ctbX );
369
0
        numCtuInSlice++;
370
0
      }
371
0
    }
372
0
  }
373
};
374
375
struct RectSlice
376
{
377
  uint32_t         tileIdx;                           //!< tile index corresponding to the first CTU in the slice
378
  uint32_t         sliceWidthInTiles;                 //!< slice width in units of tiles
379
  uint32_t         sliceHeightInTiles;                //!< slice height in units of tiles
380
  uint32_t         numSlicesInTile;                   //!< number of slices in current tile for the special case of multiple slices inside a single tile
381
  uint32_t         sliceHeightInCtu;                  //!< slice height in units of CTUs for the special case of multiple slices inside a single tile
382
383
0
  RectSlice()  {}
384
};
385
386
struct SubPic
387
{
388
  uint32_t         subPicID;                                  //!< ID of subpicture
389
  uint32_t         subPicIdx;                                 //!< Index of subpicture
390
  uint32_t         numCTUsInSubPic;                           //!< number of CTUs contained in this sub-picture
391
  uint32_t         subPicCtuTopLeftX;                         //!< horizontal position of top left CTU of the subpicture in unit of CTU
392
  uint32_t         subPicCtuTopLeftY;                         //!< vertical position of top left CTU of the subpicture in unit of CTU
393
  uint32_t         subPicWidth;                               //!< the width of subpicture in units of CTU
394
  uint32_t         subPicHeight;                              //!< the height of subpicture in units of CTU
395
  uint32_t         subPicWidthInLumaSample;                   //!< the width of subpicture in units of luma sample
396
  uint32_t         subPicHeightInLumaSample;                  //!< the height of subpicture in units of luma sample
397
  uint32_t         firstCtuInSubPic;                          //!< the raster scan index of the first CTU in a subpicture
398
  uint32_t         lastCtuInSubPic;                           //!< the raster scan index of the last CTU in a subpicture
399
  uint32_t         subPicLeft;                                //!< the position of left boundary
400
  uint32_t         subPicRight;                               //!< the position of right boundary
401
  uint32_t         subPicTop;                                 //!< the position of top boundary
402
  uint32_t         subPicBottom;                              //!< the position of bottom boundary
403
  std::vector<uint32_t> ctuAddrInSubPic;                      //!< raster scan addresses of all the CTUs in the slice
404
405
  bool             treatedAsPic;                          //!< whether the subpicture is treated as a picture in the decoding process excluding in-loop filtering operations
406
  bool             loopFilterAcrossSubPicEnabled;         //!< whether in-loop filtering operations may be performed across the boundaries of the subpicture
407
  uint32_t         numSlicesInSubPic;                         //!< Number of slices contained in this subpicture
408
409
  bool             isContainingPos(const Position& pos) const
410
0
  {
411
0
    return pos.x >= subPicLeft && pos.x <= subPicRight && pos.y >= subPicTop  && pos.y <= subPicBottom;
412
0
  }
413
414
  void init( unsigned picWithInCtu, unsigned picHeightInCtu, unsigned picWithInSamples, unsigned picHeighthInSamples )
415
0
  {
416
0
    unsigned numCtus          = picWithInCtu * picHeightInCtu;
417
0
    numCTUsInSubPic           = numCtus;
418
0
    subPicWidth               = picWithInCtu;
419
0
    subPicHeight              = picHeightInCtu;
420
0
    subPicWidthInLumaSample   = picWithInSamples;
421
0
    subPicHeightInLumaSample  = picHeighthInSamples;
422
0
    lastCtuInSubPic           = numCtus;
423
0
    subPicRight               = picWithInSamples-1;
424
0
    subPicBottom              = picHeighthInSamples-1;
425
0
    ctuAddrInSubPic.resize( numCtus );
426
0
    for( unsigned i = 0; i < numCtus; i++)
427
0
    {
428
0
      ctuAddrInSubPic[i] = i;
429
0
    }
430
0
  }
431
432
  SubPic()
433
0
  : subPicID(0)
434
0
  , subPicIdx(0)
435
0
  , numCTUsInSubPic(UINT32_MAX)
436
0
  , subPicCtuTopLeftX(0)
437
0
  , subPicCtuTopLeftY(0)
438
0
  , subPicWidth(UINT32_MAX)
439
0
  , subPicHeight(UINT32_MAX)
440
0
  , subPicWidthInLumaSample(UINT32_MAX)
441
0
  , subPicHeightInLumaSample(UINT32_MAX)
442
0
  , firstCtuInSubPic(0)
443
0
  , lastCtuInSubPic(UINT32_MAX)
444
0
  , subPicLeft(0)
445
0
  , subPicRight(0)
446
0
  , subPicTop(0)
447
0
  , subPicBottom(0)
448
0
  , treatedAsPic(true)
449
0
  , loopFilterAcrossSubPicEnabled(true)
450
0
  , numSlicesInSubPic(1)
451
0
  {
452
0
  }
453
};
454
455
struct DCI
456
{
457
  uint32_t   dciId;
458
  std::vector<ProfileTierLevel> profileTierLevel;
459
460
0
  DCI() : dciId(0) {}
461
};
462
463
struct VPS
464
{
465
  uint32_t              vpsId;
466
  uint32_t              maxLayers;
467
  uint32_t              maxSubLayers;
468
  uint32_t              layerId[MAX_VPS_LAYERS];
469
  bool                  defaultPtlDpbHrdMaxTidFlag;
470
  bool                  allLayersSameNumSubLayers;
471
  bool                  allIndependentLayers;
472
  uint32_t              vpsCfgPredDirection[MAX_VPS_SUBLAYERS];
473
  bool                  independentLayer[MAX_VPS_LAYERS];
474
  bool                  directRefLayer[MAX_VPS_LAYERS][MAX_VPS_LAYERS];
475
  uint8_t               maxTidIlRefPicsPlus1[MAX_VPS_LAYERS][MAX_VPS_LAYERS];
476
  bool                  eachLayerIsAnOls;
477
  uint32_t              olsModeIdc;
478
  uint32_t              numOutputLayerSets;
479
  bool                  olsOutputLayer[MAX_NUM_OLSS][MAX_VPS_LAYERS];
480
  uint32_t              directRefLayerIdx[MAX_VPS_LAYERS][MAX_VPS_LAYERS];
481
  uint32_t              generalLayerIdx[MAX_VPS_LAYERS];
482
  uint32_t              numPtls;
483
  bool                  ptPresent[MAX_NUM_OLSS];
484
  uint32_t              ptlMaxTemporalId[MAX_NUM_OLSS];
485
  std::vector<ProfileTierLevel> profileTierLevel;
486
  uint32_t              olsPtlIdx[MAX_NUM_OLSS];
487
488
  // stores index ( ilrp_idx within 0 .. NumDirectRefLayers ) of the dependent reference layers
489
  uint32_t              interLayerRefIdx[MAX_VPS_LAYERS][MAX_VPS_LAYERS];
490
  bool                  extension;
491
492
  bool                  generalHrdParamsPresent;
493
  bool                  sublayerCpbParamsPresent;
494
  uint32_t              numOlsHrdParamsMinus1;
495
  uint32_t              hrdMaxTid[MAX_NUM_OLSS];
496
  uint32_t              olsHrdIdx[MAX_NUM_OLSS];
497
  GeneralHrdParams      generalHrdParams;
498
  OlsHrdParams          olsHrdParams[VVENC_MAX_TLAYER];
499
  std::vector<Size>             olsDpbPicSize;
500
  std::vector<int>              olsDpbParamsIdx;
501
  std::vector<std::vector<int>> outputLayerIdInOls;
502
  std::vector<std::vector<int>> numSubLayersInLayerInOLS;
503
504
  std::vector<int>              olsDpbChromaFormatIdc;
505
  std::vector<int>              olsDpbBitDepthMinus8;
506
507
  int                           totalNumOLSs;
508
  int                           numMultiLayeredOlss;
509
  uint32_t                      multiLayerOlsIdx[MAX_NUM_OLSS];
510
  int                           numDpbParams;
511
  std::vector<DpbParameters>    dpbParameters;
512
  bool                          sublayerDpbParamsPresent;
513
  std::vector<int>              dpbMaxTemporalId;
514
  std::vector<int>              targetOutputLayerIdSet;          ///< set of LayerIds to be outputted
515
  std::vector<int>              targetLayerIdSet;                ///< set of LayerIds to be included in the sub-bitstream extraction process.
516
  int                           targetOlsIdx;
517
  std::vector<int>              numOutputLayersInOls;
518
  std::vector<int>              numLayersInOls;
519
  std::vector<std::vector<int>> layerIdInOls;
520
521
  VPS()
522
0
  : vpsId                       ( 0 )
523
0
  , maxLayers                   ( 0 )
524
0
  , maxSubLayers                ( 0 )
525
0
  , defaultPtlDpbHrdMaxTidFlag  ( false )
526
0
  , allLayersSameNumSubLayers   ( false )
527
0
  , allIndependentLayers        ( false )
528
0
  , eachLayerIsAnOls            ( false )
529
0
  , olsModeIdc                  ( 0 )
530
0
  , numOutputLayerSets          ( 0 )
531
0
  , numPtls                     ( 0 )
532
0
  , extension                   ( false )
533
0
  , totalNumOLSs                ( 0 )
534
0
  , numDpbParams                ( 0 )
535
0
  , sublayerDpbParamsPresent    ( false)
536
0
  , targetOlsIdx                ( 0 )
537
0
  {
538
0
    memset( layerId,            0, sizeof(layerId));
539
0
    memset( independentLayer,   0, sizeof(independentLayer));
540
0
    memset( directRefLayer,     0, sizeof(directRefLayer));
541
0
    memset( maxTidIlRefPicsPlus1, 7, sizeof(maxTidIlRefPicsPlus1));
542
0
    memset( olsOutputLayer,     0, sizeof(olsOutputLayer));
543
0
    memset( directRefLayerIdx,  0, sizeof(directRefLayerIdx));
544
0
    memset( generalLayerIdx,    0, sizeof(generalLayerIdx));
545
0
    memset( ptPresent,          0, sizeof(ptPresent));
546
0
    memset( ptlMaxTemporalId,   0, sizeof(ptlMaxTemporalId));
547
0
    memset( olsPtlIdx,          0, sizeof(olsPtlIdx));
548
0
    memset( interLayerRefIdx,   0, sizeof(interLayerRefIdx));
549
0
  }
550
  void deriveOutputLayerSets();
551
0
  int               getMaxDecPicBuffering( int temporalId ) const        { return dpbParameters[olsDpbParamsIdx[targetOlsIdx]].maxDecPicBuffering[temporalId]; }
552
0
  int               getNumReorderPics( int temporalId ) const            { return dpbParameters[olsDpbParamsIdx[targetOlsIdx]].numReorderPics[temporalId]; }
553
554
};
555
556
struct Window
557
{
558
  bool enabledFlag;
559
  int  winLeftOffset;
560
  int  winRightOffset;
561
  int  winTopOffset;
562
  int  winBottomOffset;
563
564
  Window()
565
0
  : enabledFlag    (false)
566
0
  , winLeftOffset  (0)
567
0
  , winRightOffset (0)
568
0
  , winTopOffset   (0)
569
0
  , winBottomOffset(0)
570
0
  { }
571
572
  void setWindow(int offsetLeft, int offsetLRight, int offsetLTop, int offsetLBottom)
573
0
  {
574
0
    enabledFlag     = offsetLeft || offsetLRight || offsetLTop || offsetLBottom;
575
0
    winLeftOffset   = offsetLeft;
576
0
    winRightOffset  = offsetLRight;
577
0
    winTopOffset    = offsetLTop;
578
0
    winBottomOffset = offsetLBottom;
579
0
  }
580
581
  bool operator!=( const Window& other ) const
582
0
  {
583
0
    return (winLeftOffset   != other.winLeftOffset
584
0
         || winRightOffset  != other.winRightOffset
585
0
         || winTopOffset    != other.winTopOffset
586
0
         || winBottomOffset != other.winBottomOffset);
587
0
  }
588
589
};
590
591
592
struct VUI
593
{
594
  bool       progressiveSourceFlag;
595
  bool       interlacedSourceFlag;
596
  bool       nonPackedFlag;
597
  bool       nonProjectedFlag;
598
  bool       aspectRatioInfoPresent;
599
  bool       aspectRatioConstantFlag;
600
  uint32_t   aspectRatioIdc;
601
  uint32_t   sarWidth;
602
  uint32_t   sarHeight;
603
  bool       overscanInfoPresent;
604
  bool       overscanAppropriateFlag;
605
  bool       colourDescriptionPresent;
606
  uint32_t   colourPrimaries;
607
  uint32_t   transferCharacteristics;
608
  uint32_t   matrixCoefficients;
609
  bool       videoFullRangeFlag;
610
  bool       chromaLocInfoPresent;
611
  uint32_t   chromaSampleLocTypeTopField;
612
  uint32_t   chromaSampleLocTypeBottomField;
613
  uint32_t   chromaSampleLocType;
614
615
  VUI()
616
0
    : progressiveSourceFlag         (true)
617
0
    , interlacedSourceFlag          (false)
618
0
    , nonPackedFlag                 (true)
619
0
    , nonProjectedFlag              (true)
620
0
    , aspectRatioInfoPresent        (false) //TODO: This initialiser list contains magic numbers
621
0
    , aspectRatioConstantFlag       (false)
622
0
    , aspectRatioIdc                    (0)
623
0
    , sarWidth                          (0)
624
0
    , sarHeight                         (0)
625
0
    , overscanInfoPresent           (false)
626
0
    , overscanAppropriateFlag       (false)
627
0
    , colourDescriptionPresent      (false)
628
0
    , colourPrimaries                   (2)
629
0
    , transferCharacteristics           (2)
630
0
    , matrixCoefficients                (2)
631
0
    , videoFullRangeFlag            (false)
632
0
    , chromaLocInfoPresent          (false)
633
0
    , chromaSampleLocTypeTopField       (0)
634
0
    , chromaSampleLocTypeBottomField    (0)
635
0
    , chromaSampleLocType               (0)
636
0
  {}
637
};
638
639
640
/// SPS class
641
struct SPS
642
{
643
  int               spsId;
644
  int               dciId;
645
  int               vpsId;
646
  int               layerId;
647
648
  bool              AffineAmvr;
649
  bool              DMVR;
650
  bool              MMVD;
651
  bool              SBT;
652
  bool              ISP;
653
  ChromaFormat      chromaFormatIdc;
654
  bool              separateColourPlane;     //!< separate colour plane
655
  uint32_t          maxTLayers;           // maximum number of temporal layers
656
  bool              ptlDpbHrdParamsPresent;
657
  bool              subLayerDpbParams;
658
659
  // Structure
660
  uint32_t          maxPicWidthInLumaSamples;
661
  uint32_t          maxPicHeightInLumaSamples;
662
  Window            conformanceWindow;
663
  bool              subPicInfoPresent;
664
  uint8_t           numSubPics;                        //!< number of sub-pictures used
665
  bool              independentSubPicsFlag;
666
  uint32_t          subPicCtuTopLeftX[MAX_NUM_SUB_PICS];
667
  uint32_t          subPicCtuTopLeftY[MAX_NUM_SUB_PICS];
668
  uint32_t          subPicWidth[MAX_NUM_SUB_PICS];
669
  uint32_t          subPicHeight[MAX_NUM_SUB_PICS];
670
  bool              subPicTreatedAsPic[MAX_NUM_SUB_PICS];
671
  bool              loopFilterAcrossSubpicEnabled[MAX_NUM_SUB_PICS];
672
  bool              subPicIdMappingExplicitlySignalled;
673
  uint32_t          subPicIdLen;                       //!< sub-picture ID length in bits
674
  uint8_t           subPicId[MAX_NUM_SUB_PICS];        //!< sub-picture ID for each sub-picture in the sequence
675
676
  int               log2MinCodingBlockSize;
677
  unsigned          CTUSize;
678
  unsigned          partitionOverrideEnabled;       // enable partition constraints override function
679
  unsigned          minQTSize[3];   // 0: I slice luma; 1: P/B slice; 2: I slice chroma
680
  unsigned          maxMTTDepth[3];
681
  unsigned          maxBTSize[3];
682
  unsigned          maxTTSize[3];
683
  bool              idrRefParamList;
684
  unsigned          dualITree;
685
686
  RPLList           rplList[NUM_REF_PIC_LIST_01];
687
  bool              rpl1CopyFromRpl0;
688
  bool              rpl1IdxPresent;
689
  bool              allRplEntriesHasSameSign;
690
  bool              longTermRefsPresent;
691
  bool              temporalMVPEnabled;
692
  int               numReorderPics[VVENC_MAX_TLAYER];
693
694
  // Tool list
695
  bool              transformSkip;
696
  int               log2MaxTransformSkipBlockSize;
697
  bool              BDPCM;
698
  bool              jointCbCr;
699
  // Parameter
700
  BitDepths         bitDepths;
701
  bool              entropyCodingSyncEnabled;
702
  bool              entryPointsPresent;
703
  int               qpBDOffset[MAX_NUM_CH];
704
  int               internalMinusInputBitDepth[MAX_NUM_CH]; //  max(0, internal bitdepth - input bitdepth);
705
706
  bool              SbtMvp;
707
  bool              BDOF;
708
  bool              fpelMmvd;
709
  bool              BdofPresent;
710
  bool              DmvrPresent;
711
  bool              ProfPresent;
712
  uint32_t          bitsForPOC;
713
714
  bool              pocMsbFlag;
715
  uint32_t          pocMsbLen;
716
  int               numExtraPHBitsBytes;
717
  int               numExtraSHBitsBytes;
718
  std::vector<bool> extraPHBitPresent;
719
  std::vector<bool> extraSHBitPresent;
720
721
  uint32_t          numLongTermRefPicSPS;
722
  uint32_t          ltRefPicPocLsbSps[MAX_NUM_LONG_TERM_REF_PICS];
723
  bool              usedByCurrPicLtSPS[MAX_NUM_LONG_TERM_REF_PICS];
724
  uint32_t          log2MaxTbSize;
725
  bool              weightPred;                     //!< Use of Weighting Prediction (P_SLICE)
726
  bool              weightedBiPred;                 //!< Use of Weighting Bi-Prediction (B_SLICE)
727
728
  bool              saoEnabled;
729
730
  bool              temporalIdNesting; // temporal_id_nesting_flag
731
732
  bool              scalingListEnabled;
733
  bool              depQuantEnabled;            //!< dependent quantization enabled flag
734
  bool              signDataHidingEnabled;      //!< sign data hiding enabled flag
735
  bool              virtualBoundariesEnabled;   //!< Enable virtual boundaries tool
736
  bool              virtualBoundariesPresent    ;   //!< disable loop filtering across virtual boundaries
737
  unsigned          numVerVirtualBoundaries;                         //!< number of vertical virtual boundaries
738
  unsigned          numHorVirtualBoundaries;                         //!< number of horizontal virtual boundaries
739
  unsigned          virtualBoundariesPosX[3];                        //!< horizontal position of each vertical virtual boundary
740
  unsigned          virtualBoundariesPosY[3];                        //!< vertical position of each horizontal virtual boundary
741
  uint32_t          maxDecPicBuffering[VVENC_MAX_TLAYER];
742
  uint32_t          maxLatencyIncreasePlus1[VVENC_MAX_TLAYER];
743
744
745
  bool              hrdParametersPresent;
746
  bool              subLayerParametersPresent;
747
  GeneralHrdParams  generalHrdParams;
748
  OlsHrdParams      olsHrdParams[VVENC_MAX_TLAYER];
749
  bool              fieldSeqFlag;
750
  bool              vuiParametersPresent;
751
  unsigned          vuiPayloadSize;
752
  VUI               vuiParameters;
753
754
//  TimingInfo        timingInfo;
755
  ProfileTierLevel  profileTierLevel;
756
757
  bool              alfEnabled;
758
  bool              ccalfEnabled;
759
  bool              wrapAroundEnabled;
760
  bool              IBC;
761
  bool              useColorTrans;
762
  bool              PLT;
763
764
  bool              lumaReshapeEnable;
765
  bool              AMVR;
766
  bool              LMChroma;
767
  bool              horCollocatedChroma;
768
  bool              verCollocatedChroma;
769
  bool              MTS;
770
  bool              MTSIntra;                   // 18
771
  bool              MTSInter;                   // 19
772
  bool              LFNST;
773
  bool              SMVD;
774
  bool              Affine;
775
  bool              AffineType;
776
  bool              PROF;
777
  bool              BCW;
778
  bool              CIIP;
779
  bool              GEO;
780
  bool              LADF;
781
  bool              MRL;
782
  bool              MIP;
783
  ChromaQpMappingTable chromaQpMappingTable;
784
  bool              GDR;
785
  bool              subLayerCbpParametersPresent;
786
787
  bool              rprEnabled;
788
  bool              resChangeInClvsEnabled;
789
  bool              interLayerPresent;
790
791
  uint32_t          log2ParallelMergeLevelMinus2; // th fix this
792
  uint32_t          maxNumMergeCand;
793
  uint32_t          maxNumAffineMergeCand;
794
  uint32_t          maxNumIBCMergeCand;
795
  uint32_t          maxNumGeoCand;
796
  bool              scalingMatrixAlternativeColourSpaceDisabled;
797
  bool              scalingMatrixDesignatedColourSpace;
798
  bool              disableScalingMatrixForLfnstBlks;
799
800
  SPS();
801
0
  int               getNumRPL( int idx)                                                 const { return (int)rplList[idx].size()-1;}
802
0
  int               getMaxLog2TrDynamicRange()                                          const { return 15; }
803
0
  uint32_t          getMaxTbSize()                                                      const { return  1 << log2MaxTbSize;                                        }
804
0
  bool              getUseImplicitMTS     ()                                            const { return MTS && !MTSIntra; }
805
806
  static int        getWinUnitX (int chromaFormatIdc)
807
0
  {
808
0
    CHECK(chromaFormatIdc < 0 || chromaFormatIdc >= NUM_CHROMA_FORMAT, "Invalid chroma format parameter");
809
0
    return (chromaFormatIdc == 1 || chromaFormatIdc == 2) ? 2 : 1;
810
0
  }
811
  static int        getWinUnitY (int chromaFormatIdc)
812
0
  {
813
0
    CHECK(chromaFormatIdc < 0 || chromaFormatIdc >= NUM_CHROMA_FORMAT, "Invalid chroma format parameter");
814
0
    return (chromaFormatIdc == 1) ? 2 : 1;
815
0
  }
816
817
private:
818
  static const int  m_winUnitX[NUM_CHROMA_FORMAT];
819
  static const int  m_winUnitY[NUM_CHROMA_FORMAT];
820
};
821
822
823
/// Reference Picture Lists class
824
825
/// PPS class
826
struct PPS
827
{
828
  int              ppsId;                    // pic_parameter_set_id
829
  int              spsId;                    // seq_parameter_set_id
830
  int              picInitQPMinus26;
831
  bool             useDQP;
832
  bool             usePPSChromaTool;
833
  bool             sliceChromaQpFlag;       // slicelevel_chroma_qp_flag
834
  int              layerId;
835
  int              temporalId;
836
837
  // access channel
838
  int              chromaQpOffset[MAX_NUM_COMP+1]; //also includes JointCbCr
839
  bool             jointCbCrQpOffsetPresent;
840
  ChromaQpAdj      chromaQpAdjTableIncludingNullEntry[1+MAX_QP_OFFSET_LIST_SIZE]; //!< Array includes entry [0] for the null offset used when cu_chroma_qp_offset_flag=0, and entries [cu_chroma_qp_offset_idx+1...] otherwise
841
842
  // Chroma QP Adjustments
843
  int              chromaQpOffsetListLen; // size (excludes the null entry used in the following array).
844
  ChromaQpAdj      ChromaQpAdjTableIncludingNullEntry[1+MAX_QP_OFFSET_LIST_SIZE]; //!< Array includes entry [0] for the null offset used when cu_chroma_qp_offset_flag=0, and entries [cu_chroma_qp_offset_idx+1...] otherwise
845
846
  uint32_t         numRefIdxL0DefaultActive;
847
  uint32_t         numRefIdxL1DefaultActive;
848
849
  bool             rpl1IdxPresent;
850
851
  bool             weightPred;                    //!< Use of Weighting Prediction (P_SLICE)
852
  bool             weightedBiPred;                 //!< Use of Weighting Bi-Prediction (B_SLICE)
853
  bool             outputFlagPresent;             //!< Indicates the presence of output_flag in slice header
854
  uint8_t          numSubPics;                        //!< number of sub-p
855
  bool             subPicIdMappingInPps;
856
  uint32_t         subPicIdLen;                       //!< sub-picture ID length in bits
857
  uint8_t          subPicId[MAX_NUM_SUB_PICS];        //!< sub-picture ID for each sub-picture in the sequence
858
  bool             noPicPartition;                //!< no picture partitioning flag - single slice, single tile
859
  uint8_t          log2CtuSize;                       //!< log2 of the CTU size - required to match corresponding value in SPS
860
  uint8_t          ctuSize;                           //!< CTU size
861
  uint32_t         picWidthInCtu;                     //!< picture width in units of CTUs
862
  uint32_t         picHeightInCtu;                    //!< picture height in units of CTUs
863
  uint32_t         numExpTileCols;                    //!< number of explicitly specified tile columns
864
  uint32_t         numExpTileRows;                    //!< number of explicitly specified tile rows
865
  uint32_t         numTileCols;                       //!< number of tile columns
866
  uint32_t         numTileRows;                       //!< number of tile rows
867
868
  std::vector<uint32_t>  tileColWidth;                 //!< tile column widths in units of CTUs
869
  std::vector<uint32_t>  tileRowHeight;                //!< tile row heights in units of CTUs
870
  std::vector<uint32_t>  tileColBd;                    //!< tile column left-boundaries in units of CTUs
871
  std::vector<uint32_t>  tileRowBd;                    //!< tile row top-boundaries in units of CTUs
872
  std::vector<uint32_t>  tileColBdRgt;                 //!< tile column right-boundaries in luma samples
873
  std::vector<uint32_t>  tileRowBdBot;                 //!< tile row bottom-boundaries in luma samples
874
  std::vector<uint32_t>  ctuToTileCol;                 //!< mapping between CTU horizontal address and tile column index
875
  std::vector<uint32_t>  ctuToTileRow;                 //!< mapping between CTU vertical address and tile row index
876
  bool                   rectSlice;                    //!< rectangular slice flag
877
  bool                   singleSlicePerSubPic;         //!< single slice per sub-picture flag
878
  std::vector<uint32_t>  ctuToSubPicIdx;               //!< mapping between CTU and Sub-picture index
879
  uint32_t               numSlicesInPic;               //!< number of rectangular slices in the picture (raster-scan slice specified at slice level)
880
  bool                   tileIdxDeltaPresent;          //!< tile index delta present flag
881
882
  std::vector<SliceMap>  sliceMap;                     //!< list of CTU maps for each slice in the picture
883
  std::vector<SubPic>    subPics;                      //!< list of subpictures in the picture
884
885
  bool             loopFilterAcrossTilesEnabled;        //!< loop filtering applied across tiles flag
886
  bool             loopFilterAcrossSlicesEnabled;       //!< loop filtering applied across slices flag
887
888
  bool             cabacInitPresent;
889
  bool             pictureHeaderExtensionPresent;   //< picture header extension flags present in picture headers or not
890
891
  bool             sliceHeaderExtensionPresent;
892
  bool             deblockingFilterControlPresent;
893
  bool             deblockingFilterOverrideEnabled;
894
  bool             deblockingFilterDisabled;
895
  int              deblockingFilterBetaOffsetDiv2[MAX_NUM_COMP];    //< beta offset for deblocking filter
896
  int              deblockingFilterTcOffsetDiv2[MAX_NUM_COMP];      //< tc offset for deblocking filter
897
  bool             listsModificationPresent;
898
  bool             rplInfoInPh;
899
  bool             dbfInfoInPh;
900
  bool             saoInfoInPh;
901
  bool             alfInfoInPh;
902
  bool             wpInfoInPh;
903
  bool             qpDeltaInfoInPh;
904
  bool             mixedNaluTypesInPic;
905
  uint32_t         picWidthInLumaSamples;
906
  uint32_t         picHeightInLumaSamples;
907
  Window           conformanceWindow;
908
  Window           scalingWindow;
909
  bool             wrapAroundEnabled;               //< reference wrap around enabled or not
910
  unsigned         picWidthMinusWrapAroundOffset;          // <pic_width_in_minCbSizeY - wraparound_offset_in_minCbSizeY
911
  unsigned         wrapAroundOffset;                    //< reference wrap around offset in luma samples
912
913
  PreCalcValues   *pcv;
914
915
public:
916
917
                  PPS();
918
  virtual         ~PPS();
919
  uint32_t        getSubPicIdxFromSubPicId( uint32_t subPicId ) const;
920
  const ChromaQpAdj&     getChromaQpOffsetListEntry( int cuChromaQpOffsetIdxPlus1 ) const
921
0
  {
922
0
    CHECK(cuChromaQpOffsetIdxPlus1 >= chromaQpOffsetListLen+1, "Invalid chroma QP offset");
923
0
    return chromaQpAdjTableIncludingNullEntry[cuChromaQpOffsetIdxPlus1]; // Array includes entry [0] for the null offset used when cu_chroma_qp_offset_flag=0, and entries [cu_chroma_qp_offset_idx+1...] otherwise
924
0
  }
925
926
927
  void                   setChromaQpOffsetListEntry( int cuChromaQpOffsetIdxPlus1, int cbOffset, int crOffset, int jointCbCrOffset )
928
0
  {
929
0
    CHECK(cuChromaQpOffsetIdxPlus1 == 0 || cuChromaQpOffsetIdxPlus1 > MAX_QP_OFFSET_LIST_SIZE, "Invalid chroma QP offset");
930
0
    chromaQpAdjTableIncludingNullEntry[cuChromaQpOffsetIdxPlus1].u.comp.CbOffset = cbOffset; // Array includes entry [0] for the null offset used when cu_chroma_qp_offset_flag=0, and entries [cu_chroma_qp_offset_idx+1...] otherwise
931
0
    chromaQpAdjTableIncludingNullEntry[cuChromaQpOffsetIdxPlus1].u.comp.CrOffset = crOffset;
932
0
    chromaQpAdjTableIncludingNullEntry[cuChromaQpOffsetIdxPlus1].u.comp.JointCbCrOffset = jointCbCrOffset;
933
0
    chromaQpOffsetListLen = std::max(chromaQpOffsetListLen, cuChromaQpOffsetIdxPlus1);
934
0
  }
935
936
937
0
  bool               isRefScaled( const PPS& pps ) const                             { return  picWidthInLumaSamples  != pps.picWidthInLumaSamples        ||
938
0
                                                                                               picHeightInLumaSamples != pps.picHeightInLumaSamples       ||
939
0
                                                                                               scalingWindow          != pps.scalingWindow; }
940
941
0
  uint32_t               getNumTiles() const                                         { return numTileCols * numTileRows; }
942
0
  uint32_t               getTileIdx( uint32_t ctuX, uint32_t ctuY ) const            { return (ctuToTileRow[ctuY] * numTileCols) + ctuToTileCol[ctuX]; }
943
0
  uint32_t               getTileIdx( uint32_t ctuRsAddr ) const                      { return getTileIdx( ctuRsAddr % picWidthInCtu,  ctuRsAddr / picWidthInCtu ); }
944
0
  uint32_t               getTileIdx( const Position& pos ) const                     { return getTileIdx( pos.x >> log2CtuSize, pos.y >> log2CtuSize ); }
945
0
  uint32_t               getTileHeight( const int tileIdx ) const                    { return tileRowHeight[tileIdx / numTileCols]; }
946
0
  uint32_t               getTileWidth( const int tileIdx ) const                     { return tileColWidth[tileIdx % numTileCols]; }
947
  uint32_t               getNumTileLineIds() const // number of lines in all the tiles (each tile consisting of indepdent rows
948
0
  {
949
0
    int countTileRows = 0;
950
0
    for( int tileIdx = 0; tileIdx < getNumTiles(); tileIdx++ ) countTileRows += getTileHeight( tileIdx );
951
0
    return countTileRows;
952
0
  }
953
  uint32_t               getTileLineId( uint32_t ctuX, uint32_t ctuY ) const // unique id for a tile line at the given position
954
0
  {
955
0
    if( numTileCols == 1 ) return ctuY;
956
957
0
    const int currTileIdx = getTileIdx( ctuX, ctuY );
958
0
    int tileRowResIdx = 0;
959
0
    for( int tileIdx = 0; tileIdx < currTileIdx; tileIdx++ ) tileRowResIdx += getTileHeight( tileIdx );
960
961
0
    const int tileRowResIdxRest = ctuY - tileRowBd[ctuToTileRow[ctuY]];
962
963
0
    return tileRowResIdx + tileRowResIdxRest;
964
0
  }
965
0
  bool                   canFilterCtuBdry( int ctuX, int ctuY, int offX, int offY ) const { return loopFilterAcrossTilesEnabled || getTileIdx( ctuX, ctuY ) == getTileIdx( ctuX + offX, ctuY + offY ); }
966
  
967
  const SubPic&          getSubPicFromPos(const Position& pos)  const;
968
  const SubPic&          getSubPicFromCU (const CodingUnit& cu) const;
969
970
  void initTiles();
971
  void initRectSliceMap( const SPS* sps );
972
  void checkSliceMap();
973
974
};
975
976
struct APS
977
{
978
  uint32_t               apsId;                    // adaptation_parameter_set_id
979
  int                    temporalId;
980
  int                    layerId;
981
  uint32_t               apsType;                  // aps_params_type
982
  AlfParam               alfParam;
983
  LmcsParam              lmcsParam;
984
  CcAlfFilterParam       ccAlfParam;
985
  bool                   hasPrefixNalUnitType;
986
  bool                   chromaPresent;
987
  int                    poc;
988
0
  APS() : apsId(MAX_UINT), temporalId( 0 ), layerId( 0 ), apsType(0), hasPrefixNalUnitType(false), chromaPresent( false ), poc(-1)
989
0
  { }
990
};
991
992
struct WPScalingParam
993
{
994
  // Explicit weighted prediction parameters parsed in slice header,
995
  // or Implicit weighted prediction parameters (8 bits depth values).
996
  bool      presentFlag;
997
  uint32_t  log2WeightDenom;
998
  int       iWeight;
999
  int       iOffset;
1000
1001
  // Weighted prediction scaling values built from above parameters (bitdepth scaled):
1002
  int       w;
1003
  int       o;
1004
  int       offset;
1005
  int       shift;
1006
  int       round;
1007
};
1008
1009
struct WPACDCParam
1010
{
1011
  int64_t iAC;
1012
  int64_t iDC;
1013
};
1014
1015
 // picture header class
1016
struct PicHeader
1017
{
1018
  Picture*                    pic;                                                    //!< pointer to picture structure
1019
  int                         pocLsb;                                                 //!< least significant bits of picture order count
1020
  bool                        nonRefPic;                                              //!< non-reference picture flag
1021
  bool                        gdrOrIrapPic;                                           //!< gdr or irap picture flag
1022
  bool                        gdrPic;                                                 //!< gradual decoding refresh picture flag
1023
  bool                        noOutputOfPriorPics;                                    //!< no output of prior pictures flag
1024
  uint32_t                    recoveryPocCnt;                                         //!< recovery POC count
1025
  bool                        noOutputBeforeRecovery;                             //!< NoOutputBeforeRecoveryFlag
1026
  bool                        handleCraAsCvsStart;                                //!< HandleCraAsCvsStartFlag
1027
  bool                        handleGdrAsCvsStart;                                //!< HandleGdrAsCvsStartFlag
1028
  int                         spsId;                                                  //!< sequence parameter set ID
1029
  int                         ppsId;                                                  //!< picture parameter set ID
1030
  bool                        pocMsbPresent;                                          //!< ph_poc_msb_present_flag
1031
  int                         pocMsbVal;                                              //!< poc_msb_val
1032
  bool                        virtualBoundariesEnabled;              //!< loop filtering across virtual boundaries disabled
1033
  bool                        virtualBoundariesPresent;              //!< loop filtering across virtual boundaries disabled
1034
  unsigned                    numVerVirtualBoundaries;                                //!< number of vertical virtual boundaries
1035
  unsigned                    numHorVirtualBoundaries;                                //!< number of horizontal virtual boundaries
1036
  unsigned                    virtualBoundariesPosX[3];                               //!< horizontal virtual boundary positions
1037
  unsigned                    virtualBoundariesPosY[3];                               //!< vertical virtual boundary positions
1038
  bool                        picOutputFlag;                                          //!< picture output flag
1039
  const ReferencePictureList* pRPL[NUM_REF_PIC_LIST_01];                              //!< pointer to RPL for L0, either in the SPS or the local RPS in the picture header
1040
  ReferencePictureList        localRPL[NUM_REF_PIC_LIST_01];                          //!< RPL for L0 when present in picture header
1041
  int                         rplIdx[NUM_REF_PIC_LIST_01];                            //!< index of used RPL in the SPS or -1 for local RPL in the picture header
1042
  bool                        picInterSliceAllowed;                                   //!< inter slice allowed flag in PH
1043
  bool                        picIntraSliceAllowed;                                   //!< intra slice allowed flag in PH
1044
  bool                        splitConsOverride;                                      //!< partitioning constraint override flag
1045
  uint32_t                    cuQpDeltaSubdivIntra;                                   //!< CU QP delta maximum subdivision for intra slices
1046
  uint32_t                    cuQpDeltaSubdivInter;                                   //!< CU QP delta maximum subdivision for inter slices
1047
  uint32_t                    cuChromaQpOffsetSubdivIntra;                            //!< CU chroma QP offset maximum subdivision for intra slices
1048
  uint32_t                    cuChromaQpOffsetSubdivInter;                            //!< CU chroma QP offset maximum subdivision for inter slices
1049
  bool                        enableTMVP;                                             //!< enable temporal motion vector prediction
1050
  bool                        picColFromL0;                                           //!< syntax element collocated_from_l0_flag
1051
  uint32_t                    colRefIdx;
1052
  bool                        mvdL1Zero;                                              //!< L1 MVD set to zero flag
1053
  uint32_t                    maxNumAffineMergeCand;                                  //!< max number of sub-block merge candidates
1054
  bool                        disFracMMVD;                                            //!< fractional MMVD offsets disabled flag
1055
  bool                        disBdofFlag;                                            //!< picture level BDOF disable flag
1056
  bool                        disDmvrFlag;                                            //!< picture level DMVR disable flag
1057
  bool                        disProfFlag;                                            //!< picture level PROF disable flag
1058
  bool                        jointCbCrSign;                                          //!< joint Cb/Cr residual sign flag
1059
  int                         qpDelta;                                                //!< value of Qp delta
1060
  bool                        saoEnabled[MAX_NUM_CH];                                 //!< sao enabled flags for each channel
1061
  bool                        alfEnabled[MAX_NUM_COMP];                               //!< alf enabled flags for each component
1062
  int                         numAlfAps;                                              //!< number of alf aps active for the picture
1063
  std::vector<int>            alfApsId;                                               //!< list of alf aps for the picture
1064
  int                         alfChromaApsId;                                         //!< chroma alf aps ID
1065
  bool                        ccalfEnabled[MAX_NUM_COMP];
1066
  int                         ccalfCbApsId;
1067
  int                         ccalfCrApsId;
1068
  bool                        deblockingFilterOverride;                               //!< deblocking filter override controls enabled
1069
  bool                        deblockingFilterDisable;                                //!< deblocking filter disabled flag
1070
  int                         deblockingFilterBetaOffsetDiv2[MAX_NUM_COMP];           //!< beta offset for deblocking filter
1071
  int                         deblockingFilterTcOffsetDiv2[MAX_NUM_COMP];              //!< tc offset for deblocking filter
1072
  bool                        lmcsEnabled;                                            //!< lmcs enabled flag
1073
  int                         lmcsApsId;                                              //!< lmcs APS ID
1074
  APS*                        lmcsAps;                                                //!< lmcs APS
1075
  bool                        lmcsChromaResidualScale;                                //!< lmcs chroma residual scale flag
1076
  bool                        explicitScalingListEnabled;                             //!< quantization scaling lists present
1077
  int                         scalingListApsId;                                       //!< quantization scaling list APS ID
1078
  APS*                        scalingListAps;                                         //!< quantization scaling list APS
1079
  unsigned                    minQTSize[3];                                           //!< minimum quad-tree size  0: I slice luma; 1: P/B slice; 2: I slice chroma
1080
  unsigned                    maxMTTDepth[3];                                         //!< maximum MTT depth
1081
  unsigned                    maxBTSize[3];                                           //!< maximum BT size
1082
  unsigned                    maxTTSize[3];                                           //!< maximum TT size
1083
1084
  WPScalingParam              weightPredTable[NUM_REF_PIC_LIST_01][MAX_NUM_REF][MAX_NUM_COMP];   // [REF_PIC_LIST_0 or REF_PIC_LIST_1][refIdx][0:Y, 1:U, 2:V]
1085
  int                         numL0Weights;                                           //!< number of weights for L0 list
1086
  int                         numL1Weights;                                           //!< number of weights for L1 list
1087
1088
0
  PicHeader() { initPicHeader(); }
1089
  void getWpScaling(RefPicList e, int iRefIdx, WPScalingParam *&wp) const;
1090
1091
  void copyPicInfo( const PicHeader* other, bool cpyAll);
1092
1093
  void initPicHeader()
1094
0
  {
1095
0
    pic                                           = nullptr;
1096
0
    nonRefPic                                     = false;
1097
0
    gdrPic                                        = 0;
1098
0
    noOutputOfPriorPics                           = 0;
1099
0
    recoveryPocCnt                                = UINT32_MAX;
1100
0
    noOutputBeforeRecovery                        = false;
1101
0
    handleCraAsCvsStart                           = false;
1102
0
    handleGdrAsCvsStart                           = false;
1103
0
    spsId                                         = -1;
1104
0
    ppsId                                         = -1;
1105
0
    pocMsbPresent                                 = 0;
1106
0
    pocMsbVal                                     = 0;
1107
0
    virtualBoundariesEnabled                      = 0;
1108
0
    virtualBoundariesPresent                      = 0;
1109
0
    numVerVirtualBoundaries                       = 0;
1110
0
    numHorVirtualBoundaries                       = 0;
1111
0
    picOutputFlag                                 = true;
1112
0
    splitConsOverride                             = false;
1113
0
    cuQpDeltaSubdivIntra                          = 0;
1114
0
    cuQpDeltaSubdivInter                          = 0;
1115
0
    cuChromaQpOffsetSubdivIntra                   = 0;
1116
0
    cuChromaQpOffsetSubdivInter                   = 0;
1117
0
    enableTMVP                                    = false;
1118
0
    picColFromL0                                  = true;
1119
0
    colRefIdx                                     = 0;
1120
0
    mvdL1Zero                                     = 0;
1121
0
    maxNumAffineMergeCand                         = 0;
1122
0
    disFracMMVD                                   = 0;
1123
0
    disBdofFlag                                   = 0;
1124
0
    disDmvrFlag                                   = 0;
1125
0
    disProfFlag                                   = 0;
1126
0
    jointCbCrSign                                 = 0;
1127
0
    qpDelta                                       = 0;
1128
0
    numAlfAps                                     = 0;
1129
0
    alfChromaApsId                                = -1;
1130
0
    ccalfCbApsId                                  = -1;
1131
0
    ccalfCrApsId                                  = -1;
1132
0
    deblockingFilterOverride                      = 0;
1133
0
    deblockingFilterDisable                       = 0;
1134
0
    deblockingFilterBetaOffsetDiv2[COMP_Y]        = 0;
1135
0
    deblockingFilterTcOffsetDiv2[COMP_Y]          = 0;
1136
0
    deblockingFilterBetaOffsetDiv2[COMP_Cb]       = 0;
1137
0
    deblockingFilterTcOffsetDiv2[COMP_Cb]         = 0;
1138
0
    deblockingFilterBetaOffsetDiv2[COMP_Cr]       = 0;
1139
0
    deblockingFilterTcOffsetDiv2[COMP_Cr]         = 0;
1140
0
    lmcsEnabled                                   = 0;
1141
0
    lmcsApsId                                     = 0;
1142
0
    lmcsAps                                       = nullptr;
1143
0
    lmcsChromaResidualScale                       = 0;
1144
0
    explicitScalingListEnabled                    = 0;
1145
0
    scalingListApsId                              = -1;
1146
0
    scalingListAps                                = nullptr;
1147
0
    numL0Weights                                  = 0;
1148
0
    numL1Weights                                  = 0;
1149
1150
0
    for( int i = 0; i < 2; i++)
1151
0
    {
1152
0
      pRPL[i] = nullptr;
1153
0
      rplIdx[i]  = 0;
1154
1155
0
      localRPL[i].numberOfActivePictures = (0);
1156
0
      localRPL[i].numberOfShorttermPictures = (0);
1157
0
      localRPL[i].numberOfLongtermPictures = (0);
1158
0
      localRPL[i].ltrpInSliceHeader = false;
1159
0
    }
1160
1161
0
    alfApsId.resize(0);
1162
1163
0
    memset(virtualBoundariesPosX, 0, sizeof(virtualBoundariesPosX));
1164
0
    memset(virtualBoundariesPosY, 0, sizeof(virtualBoundariesPosY));
1165
0
    memset(saoEnabled,            0, sizeof(saoEnabled));
1166
0
    memset(alfEnabled,            0, sizeof(alfEnabled));
1167
0
    memset(ccalfEnabled,          0, sizeof(ccalfEnabled));
1168
1169
0
    memset(minQTSize,             0, sizeof(minQTSize));
1170
0
    memset(maxMTTDepth,           0, sizeof(maxMTTDepth));
1171
0
    memset(maxBTSize,             0, sizeof(maxBTSize));
1172
0
    memset(maxTTSize,             0, sizeof(maxTTSize));
1173
0
  }
1174
1175
};
1176
1177
/// slice header class
1178
class Slice
1179
{
1180
1181
  public:
1182
  //  Bitstream writing
1183
  bool                        saoEnabled[MAX_NUM_CH];
1184
  int                         ppsId;               ///< picture parameter set ID
1185
  int                         poc;
1186
  int                         lastIDR;
1187
  int                         prevGDRInSameLayerPOC;  //< the previous GDR in the same layer
1188
  int                         associatedIRAP;
1189
  vvencNalUnitType            associatedIRAPType;
1190
  bool                        enableDRAPSEI;
1191
  bool                        useLTforDRAP;
1192
  bool                        isDRAP;
1193
  int                         latestDRAPPOC;
1194
1195
  const ReferencePictureList* rpl[NUM_REF_PIC_LIST_01];                 //< pointer to RPL for L0, either in the SPS or the local RPS in the same slice header
1196
  ReferencePictureList        rplLocal[NUM_REF_PIC_LIST_01];            //< RPL for L0 when present in slice header
1197
  int                         rplIdx[NUM_REF_PIC_LIST_01];              //< index of used RPL in the SPS or -1 for local RPL in the slice header
1198
  int                         colourPlaneId;                         //!< 4:4:4 colour plane ID
1199
  bool                        pictureHeaderInSliceHeader;
1200
  uint32_t                    nuhLayerId;
1201
  vvencNalUnitType            nalUnitType;         ///< Nal unit type for the slice
1202
  SliceType                   sliceType;
1203
  int                         sliceQp;
1204
  bool                        chromaQpAdjEnabled;
1205
  bool                        lmcsEnabled;
1206
  bool                        explicitScalingListUsed;
1207
  bool                        deblockingFilterDisable;
1208
  bool                        deblockingFilterOverride;      //< offsets for deblocking filter inherit from PPS
1209
  int                         deblockingFilterBetaOffsetDiv2[MAX_NUM_COMP];    //< beta offset for deblocking filter
1210
  int                         deblockingFilterTcOffsetDiv2[MAX_NUM_COMP];      //< tc offset for deblocking filter
1211
  bool                        depQuantEnabled;               //!< dependent quantization enabled flag
1212
  bool                        signDataHidingEnabled;         //!< sign data hiding enabled flag
1213
  bool                        tsResidualCodingDisabled;
1214
  int                         list1IdxToList0Idx[MAX_NUM_REF];
1215
  int                         numRefIdx   [NUM_REF_PIC_LIST_01];    //  for multiple reference of current slice
1216
  bool                        pendingRasInit;
1217
  bool                        checkLDC;
1218
  bool                        biDirPred;
1219
  bool                        lmChromaCheckDisable;
1220
  int                         symRefIdx[2];
1221
1222
  //  Data
1223
  int                         sliceChromaQpDelta[MAX_NUM_COMP+1];
1224
  Picture*                    refPicList [NUM_REF_PIC_LIST_01][MAX_NUM_REF+1];
1225
  int                         refPOCList  [NUM_REF_PIC_LIST_01][MAX_NUM_REF+1];
1226
  bool                        isUsedAsLongTerm[NUM_REF_PIC_LIST_01][MAX_NUM_REF+1];
1227
1228
  // access channel
1229
  const VPS*                  vps;
1230
  const DCI*                  dci;
1231
  const SPS*                  sps;
1232
  const PPS*                  pps;
1233
  Picture*                    pic;
1234
  PicHeader*                  picHeader;    //!< pointer to picture header structure
1235
  bool                        colFromL0Flag;  // collocated picture from List0 flag
1236
  uint32_t                    colRefIdx;
1237
  double                      lambdas[MAX_NUM_COMP];
1238
  uint32_t                    TLayer;
1239
  bool                        TLayerSwitchingFlag;
1240
  SliceMap                    sliceMap;
1241
  uint32_t                    independentSliceIdx;
1242
  WPScalingParam              weightPredTable[NUM_REF_PIC_LIST_01][MAX_NUM_REF][MAX_NUM_COMP];
1243
  WPACDCParam                 weightACDCParam[MAX_NUM_COMP];
1244
  ClpRngs                     clpRngs;
1245
  std::vector<uint32_t>       substreamSizes;
1246
  bool                        cabacInitFlag;
1247
  uint32_t                    sliceSubPicId;
1248
  SliceType                   encCABACTableIdx;           // Used to transmit table selection across slices.
1249
  APS*                        alfAps[ALF_CTB_MAX_NUM_APS];
1250
  bool                        alfEnabled[MAX_NUM_COMP];
1251
  int                         numAps;
1252
  std::vector<int>            lumaApsId;
1253
  int                         chromaApsId;
1254
  bool                        ccAlfCbEnabled;
1255
  bool                        ccAlfCrEnabled;
1256
  int                         ccAlfCbApsId;
1257
  int                         ccAlfCrApsId;
1258
1259
  bool                        isLossless;
1260
  CcAlfFilterParam            ccAlfFilterParam;
1261
  uint8_t*                    ccAlfFilterControl[2];
1262
1263
public:
1264
                              Slice();
1265
  virtual                     ~Slice();
1266
  void                        resetSlicePart();
1267
  void                        constructRefPicList(const PicList& rcListPic, bool extBorder, const bool usingLongTerm = true);
1268
  void                        updateRefPicCounter( int step );
1269
  bool                        checkAllRefPicsAccessible() const;
1270
  bool                        checkAllRefPicsReconstructed() const;
1271
  void                        setRefPOCList();
1272
  void                        setSMVDParam();
1273
  void                        checkColRefIdx(uint32_t curSliceSegmentIdx, const Picture* pic) const;
1274
0
  void                        setAlfAPSs(APS** apss)                                 { memcpy(alfAps, apss, sizeof(alfAps)); }
1275
1276
0
  const Picture*              getRefPic( RefPicList e, int iRefIdx) const            { return refPicList[e][iRefIdx]; }
1277
0
  int                         getRefPOC( RefPicList e, int iRefIdx) const            { return refPOCList[e][iRefIdx]; }
1278
  int                         getNumEntryPoints(const SPS& sps, const PPS& pps) const;
1279
1280
  bool                        getRapPicFlag() const;
1281
0
  bool                        getIdrPicFlag() const                                  { return nalUnitType == VVENC_NAL_UNIT_CODED_SLICE_IDR_W_RADL || nalUnitType == VVENC_NAL_UNIT_CODED_SLICE_IDR_N_LP; }
1282
0
  bool                        isIRAP() const { return (nalUnitType >= VVENC_NAL_UNIT_CODED_SLICE_IDR_W_RADL) && (nalUnitType <= VVENC_NAL_UNIT_CODED_SLICE_CRA); }
1283
0
  bool                        isIDRorBLA() const { return (nalUnitType == VVENC_NAL_UNIT_CODED_SLICE_IDR_W_RADL) || (nalUnitType == VVENC_NAL_UNIT_CODED_SLICE_IDR_N_LP); }
1284
  void                        checkCRA(const ReferencePictureList* pRPL0, const ReferencePictureList* pRPL1, int& pocCRA, vvencNalUnitType& associatedIRAPType, PicList& rcListPic);
1285
  void                        setDecodingRefreshMarking(int& pocCRA, bool& bRefreshPending, const PicList& rcListPic);
1286
1287
0
  bool                        isIntra() const                                        { return sliceType == VVENC_I_SLICE; }
1288
0
  bool                        isInterB() const                                       { return sliceType == VVENC_B_SLICE; }
1289
0
  bool                        isInterP() const                                       { return sliceType == VVENC_P_SLICE; }
1290
1291
0
  void                        setLambdas( const double lambdas_[MAX_NUM_COMP] )  { for (int component = 0; component < MAX_NUM_COMP; component++) lambdas[component] = lambdas_[component]; }
1292
0
  const double*               getLambdas() const                                     { return lambdas;                                             }
1293
1294
  static void                 sortPicList( PicList& rcListPic );
1295
  void                        setList1IdxToList0Idx();
1296
1297
  void                        copySliceInfo( const Slice* slice, bool cpyAlmostAll = true);
1298
1299
  void                        checkLeadingPictureRestrictions( const PicList& rcListPic ) const;
1300
  void                        applyReferencePictureListBasedMarking( const PicList& rcListPic, const ReferencePictureList* pRPL0, const ReferencePictureList* pRPL1, const int layerId, const PPS& pps, const bool usingLongTerm = true )  const;
1301
  bool                        isStepwiseTemporalLayerSwitchingPointCandidate( const PicList& rcListPic ) const;
1302
  bool                        isRplPicMissing( const PicList& rcListPic, const RefPicList refList, int& missingPoc, int ip ) const;
1303
  void                        createExplicitReferencePictureSetFromReference( const PicList& rcListPic, const ReferencePictureList* pRPL0, const ReferencePictureList* pRPL1, int ip );
1304
  void                        getWpScaling( RefPicList e, int iRefIdx, WPScalingParam *&wp) const;
1305
1306
  void                        resetWpScaling();
1307
1308
0
  void                        clearSubstreamSizes( )                                 { return substreamSizes.clear();                              }
1309
0
  uint32_t                    getNumberOfSubstreamSizes( )                           { return (uint32_t) substreamSizes.size();                    }
1310
0
  void                        addSubstreamSize( uint32_t size )                      { substreamSizes.push_back(size);                             }
1311
0
  uint32_t                    getSubstreamSize( uint32_t idx )                       { CHECK(idx>=getNumberOfSubstreamSizes(),"Invalid index"); return substreamSizes[idx]; }
1312
1313
  void                        setDefaultClpRng( const SPS& sps );
1314
  unsigned                    getMinPictureDistance()                           const ;
1315
1316
  bool                        isPocRestrictedByDRAP( int poc, bool precedingDRAPInDecodingOrder ) const;
1317
  bool                        refPicIsFutureIDRnoLP( int candPoc, int ipc ) const;
1318
1319
  void                        setAlfApsIds( const std::vector<int>& ApsIDs);
1320
private:
1321
  Picture*                    xGetLongTermRefPic(const PicList& rcListPic, int poc, bool pocHasMsb);
1322
};// END CLASS DEFINITION Slice
1323
1324
void calculateParameterSetChangedFlag(bool& bChanged, const std::vector<uint8_t>* pOldData, const std::vector<uint8_t>* pNewData);
1325
1326
template <class T> class ParameterSetMap
1327
{
1328
public:
1329
  template <class Tm>
1330
  struct MapData
1331
  {
1332
    bool                  bChanged;
1333
    std::vector<uint8_t>* pNaluData;
1334
    Tm*                   parameterSet;
1335
  };
1336
1337
1338
private:
1339
  std::map<int,MapData<T> > m_paramsetMap;
1340
  int                       m_maxId;
1341
  std::vector<int>          m_activePsId;
1342
  T*                        m_lastActiveParameterSet;
1343
  int                       m_apsIdStart;
1344
1345
public:
1346
  ParameterSetMap()
1347
  : m_maxId                 ( MAX_NUM_APS * MAX_NUM_APS_TYPE )
1348
  , m_activePsId            ()
1349
  , m_lastActiveParameterSet( nullptr )
1350
  , m_apsIdStart            ( ALF_CTB_MAX_NUM_APS )
1351
  {
1352
  }
1353
1354
  ParameterSetMap( int maxId )
1355
0
  : m_maxId                 ( maxId )
1356
0
  , m_activePsId            ()
1357
0
  , m_lastActiveParameterSet( nullptr )
1358
0
  , m_apsIdStart            ( ALF_CTB_MAX_NUM_APS )
1359
0
  {
1360
0
  }
Unexecuted instantiation: vvenc::ParameterSetMap<vvenc::APS>::ParameterSetMap(int)
Unexecuted instantiation: vvenc::ParameterSetMap<vvenc::SPS>::ParameterSetMap(int)
Unexecuted instantiation: vvenc::ParameterSetMap<vvenc::PPS>::ParameterSetMap(int)
Unexecuted instantiation: vvenc::ParameterSetMap<vvenc::DCI>::ParameterSetMap(int)
Unexecuted instantiation: vvenc::ParameterSetMap<vvenc::VPS>::ParameterSetMap(int)
1361
1362
  ~ParameterSetMap()
1363
0
  {
1364
0
    clearMap();
1365
0
  }
Unexecuted instantiation: vvenc::ParameterSetMap<vvenc::APS>::~ParameterSetMap()
Unexecuted instantiation: vvenc::ParameterSetMap<vvenc::SPS>::~ParameterSetMap()
Unexecuted instantiation: vvenc::ParameterSetMap<vvenc::PPS>::~ParameterSetMap()
Unexecuted instantiation: vvenc::ParameterSetMap<vvenc::DCI>::~ParameterSetMap()
Unexecuted instantiation: vvenc::ParameterSetMap<vvenc::VPS>::~ParameterSetMap()
1366
1367
  T *allocatePS( const int psId )
1368
0
  {
1369
0
    CHECK( psId >= m_maxId, "Invalid PS id" );
1370
0
    if ( m_paramsetMap.find(psId) == m_paramsetMap.end() )
1371
0
    {
1372
0
      m_paramsetMap[psId].bChanged     = true;
1373
0
      m_paramsetMap[psId].pNaluData    = nullptr;
1374
0
      m_paramsetMap[psId].parameterSet = new T;
1375
0
      setID( m_paramsetMap[ psId ].parameterSet, psId );
1376
0
    }
1377
0
    return m_paramsetMap[ psId ].parameterSet;
1378
0
  }
Unexecuted instantiation: vvenc::ParameterSetMap<vvenc::SPS>::allocatePS(int)
Unexecuted instantiation: vvenc::ParameterSetMap<vvenc::PPS>::allocatePS(int)
Unexecuted instantiation: vvenc::ParameterSetMap<vvenc::APS>::allocatePS(int)
1379
1380
  void clearMap()
1381
0
  {
1382
0
    for( typename std::map<int,MapData<T> >::iterator i = m_paramsetMap.begin(); i != m_paramsetMap.end(); i++ )
1383
0
    {
1384
0
      delete (*i).second.pNaluData;
1385
0
      delete (*i).second.parameterSet;
1386
0
    }
1387
0
    delete m_lastActiveParameterSet; m_lastActiveParameterSet = nullptr;
1388
0
    m_paramsetMap.clear();
1389
0
    m_activePsId.clear();
1390
0
  }
Unexecuted instantiation: vvenc::ParameterSetMap<vvenc::APS>::clearMap()
Unexecuted instantiation: vvenc::ParameterSetMap<vvenc::SPS>::clearMap()
Unexecuted instantiation: vvenc::ParameterSetMap<vvenc::PPS>::clearMap()
Unexecuted instantiation: vvenc::ParameterSetMap<vvenc::DCI>::clearMap()
Unexecuted instantiation: vvenc::ParameterSetMap<vvenc::VPS>::clearMap()
1391
1392
  void storePS( int psId, T *ps )
1393
  {
1394
    CHECK( psId >= m_maxId, "Invalid PS id" );
1395
    if( m_paramsetMap.find( psId ) != m_paramsetMap.end() )
1396
    {
1397
      delete m_paramsetMap[psId].parameterSet;
1398
    }
1399
    m_paramsetMap[psId].parameterSet = ps;
1400
    m_paramsetMap[psId].bChanged = true;
1401
  }
1402
1403
  void storePS(int psId, T *ps, const std::vector<uint8_t> *pNaluData)
1404
0
  {
1405
0
    CHECK( psId >= m_maxId, "Invalid PS id" );
1406
0
    if ( m_paramsetMap.find(psId) != m_paramsetMap.end() )
1407
0
    {
1408
0
      MapData<T> &mapData=m_paramsetMap[psId];
1409
0
1410
0
      // work out changed flag
1411
0
      calculateParameterSetChangedFlag(mapData.bChanged, mapData.pNaluData, pNaluData);
1412
0
1413
0
      if( ! mapData.bChanged )
1414
0
      {
1415
0
        // just keep the old one
1416
0
        delete ps;
1417
0
        return;
1418
0
      }
1419
0
1420
0
      if (find(m_activePsId.begin(), m_activePsId.end(), psId) != m_activePsId.end())
1421
0
      {
1422
0
        std::swap( m_paramsetMap[psId].parameterSet, m_lastActiveParameterSet );
1423
0
      }
1424
0
      delete m_paramsetMap[psId].pNaluData;
1425
0
      delete m_paramsetMap[psId].parameterSet;
1426
0
1427
0
      m_paramsetMap[psId].parameterSet = ps;
1428
0
    }
1429
0
    else
1430
0
    {
1431
0
      m_paramsetMap[psId].parameterSet = ps;
1432
0
      m_paramsetMap[psId].bChanged = false;
1433
0
    }
1434
0
    if (pNaluData != 0)
1435
0
    {
1436
0
      m_paramsetMap[psId].pNaluData=new std::vector<uint8_t>;
1437
0
      *(m_paramsetMap[psId].pNaluData) = *pNaluData;
1438
0
    }
1439
0
    else
1440
0
    {
1441
0
      m_paramsetMap[psId].pNaluData=0;
1442
0
    }
1443
0
  }
Unexecuted instantiation: vvenc::ParameterSetMap<vvenc::VPS>::storePS(int, vvenc::VPS*, std::__1::vector<unsigned char, std::__1::allocator<unsigned char> > const*)
Unexecuted instantiation: vvenc::ParameterSetMap<vvenc::DCI>::storePS(int, vvenc::DCI*, std::__1::vector<unsigned char, std::__1::allocator<unsigned char> > const*)
Unexecuted instantiation: vvenc::ParameterSetMap<vvenc::SPS>::storePS(int, vvenc::SPS*, std::__1::vector<unsigned char, std::__1::allocator<unsigned char> > const*)
Unexecuted instantiation: vvenc::ParameterSetMap<vvenc::PPS>::storePS(int, vvenc::PPS*, std::__1::vector<unsigned char, std::__1::allocator<unsigned char> > const*)
Unexecuted instantiation: vvenc::ParameterSetMap<vvenc::APS>::storePS(int, vvenc::APS*, std::__1::vector<unsigned char, std::__1::allocator<unsigned char> > const*)
1444
1445
  void setChangedFlag(int psId, bool bChanged=true)
1446
0
  {
1447
0
    if ( m_paramsetMap.find(psId) != m_paramsetMap.end() )
1448
0
    {
1449
0
      m_paramsetMap[psId].bChanged=bChanged;
1450
0
    }
1451
0
  }
1452
1453
  void clearChangedFlag(int psId)
1454
0
  {
1455
0
    if ( m_paramsetMap.find(psId) != m_paramsetMap.end() )
1456
0
    {
1457
0
      m_paramsetMap[psId].bChanged=false;
1458
0
    }
1459
0
  }
Unexecuted instantiation: vvenc::ParameterSetMap<vvenc::SPS>::clearChangedFlag(int)
Unexecuted instantiation: vvenc::ParameterSetMap<vvenc::PPS>::clearChangedFlag(int)
Unexecuted instantiation: vvenc::ParameterSetMap<vvenc::APS>::clearChangedFlag(int)
1460
1461
  bool getChangedFlag(int psId) const
1462
0
  {
1463
0
    const typename std::map<int,MapData<T> >::const_iterator constit=m_paramsetMap.find(psId);
1464
0
    if ( constit != m_paramsetMap.end() )
1465
0
    {
1466
0
      return constit->second.bChanged;
1467
0
    }
1468
0
    return false;
1469
0
  }
Unexecuted instantiation: vvenc::ParameterSetMap<vvenc::SPS>::getChangedFlag(int) const
Unexecuted instantiation: vvenc::ParameterSetMap<vvenc::PPS>::getChangedFlag(int) const
Unexecuted instantiation: vvenc::ParameterSetMap<vvenc::APS>::getChangedFlag(int) const
1470
1471
  T* getPS(int psId)
1472
0
  {
1473
0
    typename std::map<int,MapData<T> >::iterator it=m_paramsetMap.find(psId);
1474
0
    return ( it == m_paramsetMap.end() ) ? NULL : (it)->second.parameterSet;
1475
0
  }
Unexecuted instantiation: vvenc::ParameterSetMap<vvenc::VPS>::getPS(int)
Unexecuted instantiation: vvenc::ParameterSetMap<vvenc::SPS>::getPS(int)
Unexecuted instantiation: vvenc::ParameterSetMap<vvenc::PPS>::getPS(int)
Unexecuted instantiation: vvenc::ParameterSetMap<vvenc::APS>::getPS(int)
Unexecuted instantiation: vvenc::ParameterSetMap<vvenc::DCI>::getPS(int)
1476
1477
  const T* getPS(int psId) const
1478
0
  {
1479
0
    typename std::map<int,MapData<T> >::const_iterator it=m_paramsetMap.find(psId);
1480
0
    return ( it == m_paramsetMap.end() ) ? NULL : (it)->second.parameterSet;
1481
0
  }
Unexecuted instantiation: vvenc::ParameterSetMap<vvenc::VPS>::getPS(int) const
Unexecuted instantiation: vvenc::ParameterSetMap<vvenc::SPS>::getPS(int) const
Unexecuted instantiation: vvenc::ParameterSetMap<vvenc::DCI>::getPS(int) const
Unexecuted instantiation: vvenc::ParameterSetMap<vvenc::APS>::getPS(int) const
1482
1483
  T* getFirstPS()
1484
0
  {
1485
0
    return (m_paramsetMap.begin() == m_paramsetMap.end() ) ? NULL : m_paramsetMap.begin()->second.parameterSet;
1486
0
  }
Unexecuted instantiation: vvenc::ParameterSetMap<vvenc::SPS>::getFirstPS()
Unexecuted instantiation: vvenc::ParameterSetMap<vvenc::PPS>::getFirstPS()
1487
1488
0
  void      setActive(int psId)           { m_activePsId.push_back(psId); }
Unexecuted instantiation: vvenc::ParameterSetMap<vvenc::DCI>::setActive(int)
Unexecuted instantiation: vvenc::ParameterSetMap<vvenc::SPS>::setActive(int)
Unexecuted instantiation: vvenc::ParameterSetMap<vvenc::PPS>::setActive(int)
Unexecuted instantiation: vvenc::ParameterSetMap<vvenc::APS>::setActive(int)
1489
0
  void      clearActive()                 { m_activePsId.clear(); m_apsIdStart = ALF_CTB_MAX_NUM_APS; }
Unexecuted instantiation: vvenc::ParameterSetMap<vvenc::SPS>::clearActive()
Unexecuted instantiation: vvenc::ParameterSetMap<vvenc::PPS>::clearActive()
Unexecuted instantiation: vvenc::ParameterSetMap<vvenc::APS>::clearActive()
1490
0
  int       getApsIdStart()               { return m_apsIdStart; }
1491
0
  const int getApsIdStart() const         { return m_apsIdStart; }
1492
0
  void      setApsIdStart( const int id ) { m_apsIdStart = id; }
1493
//   void      reset()                       
1494
//   { 
1495
//     m_apsIdStart = m_apsIdStart = ALF_CTB_MAX_NUM_APS; 
1496
//     for( typename std::map<int,MapData<T> >::iterator i = m_paramsetMap.begin(); i != m_paramsetMap.end(); i++ )
1497
//     {
1498
//       (*i).second.bChanged = false;
1499
//     }
1500
//   }
1501
1502
private:
1503
  static void setID(T* parameterSet, const int psId);
1504
};
1505
1506
class ParameterSetManager
1507
{
1508
public:
1509
  enum PPSErrCodes
1510
  {
1511
    PPS_OK    = 0,
1512
    PPS_ERR_INACTIVE_SPS = -1,
1513
    PPS_ERR_NO_SPS       = -2,
1514
    PPS_ERR_NO_PPS       = -3,
1515
    PPS_WARN_DCI_ID      = 1,
1516
    PPS_WARN_NO_DCI      = 2,    
1517
  };
1518
  
1519
public:
1520
                 ParameterSetManager();
1521
  virtual        ~ParameterSetManager();
1522
0
  void           storeVPS(VPS *vps, const std::vector<uint8_t> &naluData)    { m_vpsMap.storePS(vps->vpsId, vps, &naluData); }
1523
0
  VPS*           getVPS( int vpsId )                                         { return m_vpsMap.getPS( vpsId ); };
1524
1525
0
  void           storeDCI(DCI *dci, const std::vector<uint8_t> &naluData)    { m_dciMap.storePS( dci->dciId, dci, &naluData); };
1526
  //DCI*           getDCI(int dciId)                                           { return m_dciMap.getPS(dciId); };
1527
1528
0
  void           storeSPS(SPS *sps, const std::vector<uint8_t> &naluData) { m_spsMap.storePS( sps->spsId, sps, &naluData); };
1529
0
  SPS*           getSPS(int spsId)                                           { return m_spsMap.getPS(spsId); };
1530
0
  bool           getSPSChangedFlag(int spsId) const                          { return m_spsMap.getChangedFlag(spsId); }
1531
0
  void           clearSPSChangedFlag(int spsId)                              { m_spsMap.clearChangedFlag(spsId); }
1532
0
  SPS*           getFirstSPS()                                               { return m_spsMap.getFirstPS(); };
1533
1534
0
  void           storePPS(PPS *pps, const std::vector<uint8_t> &naluData) { m_ppsMap.storePS( pps->ppsId, pps, &naluData); };
1535
0
  PPS*           getPPS(int ppsId)                                           { return m_ppsMap.getPS(ppsId); };
1536
0
  bool           getPPSChangedFlag(int ppsId) const                          { return m_ppsMap.getChangedFlag(ppsId); }
1537
0
  void           clearPPSChangedFlag(int ppsId)                              { m_ppsMap.clearChangedFlag(ppsId); }
1538
0
  PPS*           getFirstPPS()                                               { return m_ppsMap.getFirstPS(); };
1539
1540
  PPSErrCodes    activatePPS(int ppsId, bool isIRAP);
1541
0
  APS**          getAPSs() { return &m_apss[0]; }
1542
0
  ParameterSetMap<APS>* getApsMap() { return &m_apsMap; }
1543
0
  void           storeAPS(APS *aps, const std::vector<uint8_t> &naluData)    { m_apsMap.storePS((aps->apsId << NUM_APS_TYPE_LEN) + aps->apsType, aps, &naluData); };
1544
0
  APS*           getAPS(int apsId, int apsType)                              { return m_apsMap.getPS((apsId << NUM_APS_TYPE_LEN) + apsType); };
1545
0
  bool           getAPSChangedFlag(int apsId, int apsType) const             { return m_apsMap.getChangedFlag((apsId << NUM_APS_TYPE_LEN) + apsType); }
1546
0
  void           clearAPSChangedFlag(int apsId, int apsType)                 { m_apsMap.clearChangedFlag((apsId << NUM_APS_TYPE_LEN) + apsType); }
1547
  bool           activateAPS(int apsId, int apsType);
1548
0
  const VPS*     getActiveVPS()const                                         { return m_vpsMap.getPS(m_activeVPSId); };
1549
0
  const SPS*     getActiveSPS()const                                         { return m_spsMap.getPS(m_activeSPSId); };
1550
0
  const DCI*     getActiveDCI()const                                         { return m_dciMap.getPS(m_activeDCIId); };
1551
1552
protected:
1553
  ParameterSetMap<SPS> m_spsMap;
1554
  ParameterSetMap<PPS> m_ppsMap;
1555
  ParameterSetMap<APS> m_apsMap;
1556
  ParameterSetMap<DCI> m_dciMap;
1557
  ParameterSetMap<VPS> m_vpsMap;
1558
1559
  APS* m_apss[ALF_CTB_MAX_NUM_APS];
1560
1561
  int m_activeDCIId; // -1 for nothing active
1562
  int m_activeSPSId; // -1 for nothing active
1563
  int m_activeVPSId; // -1 for nothing active
1564
};
1565
1566
class PreCalcValues
1567
{
1568
public:
1569
  PreCalcValues( const SPS& sps, const PPS& pps, const unsigned _maxQtSize[3] )
1570
0
    : chrFormat           ( sps.chromaFormatIdc )
1571
0
    , maxCUSize           ( sps.CTUSize )
1572
0
    , maxCUSizeMask       ( maxCUSize  - 1 )
1573
0
    , maxCUSizeLog2       ( Log2( maxCUSize  ) )
1574
0
    , minCUSize           ( 1 << MIN_CU_LOG2 )
1575
0
    , minCUSizeLog2       ( MIN_CU_LOG2 )
1576
0
    , partsInCtuWidth     ( maxCUSize >> MIN_CU_LOG2 )
1577
0
    , partsInCtu          ( partsInCtuWidth*partsInCtuWidth )
1578
0
    , widthInCtus         ( (pps.picWidthInLumaSamples  + sps.CTUSize - 1) / sps.CTUSize )
1579
0
    , heightInCtus        ( (pps.picHeightInLumaSamples + sps.CTUSize - 1) / sps.CTUSize )
1580
0
    , sizeInCtus          ( widthInCtus * heightInCtus )
1581
0
    , lumaWidth           ( pps.picWidthInLumaSamples )
1582
0
    , lumaHeight          ( pps.picHeightInLumaSamples )
1583
0
    , fastDeltaQPCuMaxSize( Clip3<unsigned>( (1 << sps.log2MinCodingBlockSize), sps.CTUSize, 32u) )
1584
0
    , ISingleTree         ( !sps.dualITree )
1585
0
    , maxMTTDepth         { sps.maxMTTDepth[0], sps.maxMTTDepth[1], sps.maxMTTDepth[2] }
1586
0
    , minTSize            { 1u << sps.log2MinCodingBlockSize, 1u << sps.log2MinCodingBlockSize, 1u << sps.log2MinCodingBlockSize }
1587
0
    , maxBtSize           { sps.maxBTSize[0], sps.maxBTSize[1], sps.maxBTSize[2] }
1588
0
    , maxTtSize           { sps.maxTTSize[0], sps.maxTTSize[1], sps.maxTTSize[2] }
1589
0
    , minQtSize           { sps.minQTSize[0], sps.minQTSize[1], sps.minQTSize[2] }
1590
0
    , maxQtSize           { _maxQtSize[0], _maxQtSize[1], _maxQtSize[2] }
1591
0
  {
1592
0
  }
1593
1594
  const ChromaFormat chrFormat;
1595
  const unsigned     maxCUSize;
1596
  // to get CTU position, use (x & maxCUWidthMask) rather than (x % maxCUWidth)
1597
  const unsigned     maxCUSizeMask;
1598
  const unsigned     maxCUSizeLog2;
1599
  const unsigned     minCUSize;
1600
  const unsigned     minCUSizeLog2;
1601
  const unsigned     partsInCtuWidth;
1602
  const unsigned     partsInCtu;
1603
  const unsigned     widthInCtus;
1604
  const unsigned     heightInCtus;
1605
  const unsigned     sizeInCtus;
1606
  const unsigned     lumaWidth;
1607
  const unsigned     lumaHeight;
1608
  const unsigned     fastDeltaQPCuMaxSize;
1609
  const bool         ISingleTree;
1610
1611
private:
1612
  const unsigned     maxMTTDepth[3];
1613
  const unsigned     minTSize   [3];
1614
  const unsigned     maxBtSize  [3];
1615
  const unsigned     maxTtSize  [3];
1616
  const unsigned     minQtSize  [3];
1617
  const unsigned     maxQtSize  [3];
1618
1619
  unsigned getValIdx      ( const Slice &slice, const ChannelType chType ) const;
1620
1621
public:
1622
  unsigned getMaxMTTDepth ( const Slice &slice, const ChannelType chType ) const;
1623
  unsigned getMinTSize    ( const Slice &slice, const ChannelType chType ) const;
1624
  unsigned getMaxBtSize   ( const Slice &slice, const ChannelType chType ) const;
1625
  unsigned getMaxTtSize   ( const Slice &slice, const ChannelType chType ) const;
1626
  unsigned getMinQtSize   ( const Slice &slice, const ChannelType chType ) const;
1627
0
  unsigned getMinDepth    ( const SliceType slicetype, const ChannelType chType )   const { return maxCUSizeLog2 - Log2(slicetype == VVENC_I_SLICE ? (chType == CH_L ? maxQtSize[0] : maxQtSize[2]) : maxQtSize[1]); }
1628
0
  unsigned getMaxDepth    ( const SliceType slicetype, const ChannelType chType )   const { return maxCUSizeLog2 - Log2(slicetype == VVENC_I_SLICE ? (chType == CH_L ? minQtSize[0] : minQtSize[2]) : minQtSize[1]); }
1629
  Area     getCtuArea     ( const int ctuPosX, const int ctuPosY ) const;
1630
};
1631
1632
} // namespace vvenc
1633
1634
//! \}
1635