Coverage Report

Created: 2026-12-01 06:52

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/work/vvdec/source/Lib/DecoderLib/HLSyntaxReader.cpp
Line
Count
Source
1
/* -----------------------------------------------------------------------------
2
The copyright in this software is being made available under the Clear BSD
3
License, included below. No patent rights, trademark rights and/or 
4
other Intellectual Property Rights other than the copyrights concerning 
5
the Software are granted under this license.
6
7
The Clear BSD License
8
9
Copyright (c) 2018-2026, Fraunhofer-Gesellschaft zur Förderung der angewandten Forschung e.V. & The VVdeC Authors.
10
All rights reserved.
11
12
Redistribution and use in source and binary forms, with or without modification,
13
are permitted (subject to the limitations in the disclaimer below) provided that
14
the following conditions are met:
15
16
     * Redistributions of source code must retain the above copyright notice,
17
     this list of conditions and the following disclaimer.
18
19
     * Redistributions in binary form must reproduce the above copyright
20
     notice, this list of conditions and the following disclaimer in the
21
     documentation and/or other materials provided with the distribution.
22
23
     * Neither the name of the copyright holder nor the names of its
24
     contributors may be used to endorse or promote products derived from this
25
     software without specific prior written permission.
26
27
NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED BY
28
THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
29
CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
30
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
31
PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
32
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
33
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
34
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
35
BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
36
IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
37
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
38
POSSIBILITY OF SUCH DAMAGE.
39
40
41
------------------------------------------------------------------------------------------- */
42
43
/** \file     HLSyntaxReader.cpp
44
 *  \brief    Reader for high level syntax
45
 */
46
47
//! \ingroup DecoderLib
48
//! \{
49
50
#include "HLSyntaxReader.h"
51
52
#include "CommonLib/CommonDef.h"
53
#include "CommonLib/Rom.h"
54
#include "CommonLib/dtrace_next.h"
55
#include "CommonLib/AdaptiveLoopFilter.h"
56
57
#include "ParameterSetManager.h"
58
59
1.96k
#define CHECK_CONSTRAINT( cond, msg ) CHECK( cond, msg )
60
61
namespace vvdec
62
{
63
64
void AUDReader::parseAccessUnitDelimiter( InputBitstream* bs, uint32_t &picType )
65
2
{
66
2
  setBitstream( bs );
67
68
#if ENABLE_TRACING
69
  xTraceAccessUnitDelimiter();
70
#endif
71
72
2
  X_READ_FLAG( aud_irap_or_gdr_au_flag );
73
2
  (void)aud_irap_or_gdr_au_flag;
74
75
2
  X_READ_CODE_NO_RANGE( aud_pic_type, 3 );
76
2
  picType = aud_pic_type;
77
78
2
  xReadRbspTrailingBits();
79
2
}
80
81
void FDReader::parseFillerData( InputBitstream* bs, uint32_t &fdSize )
82
0
{
83
0
  setBitstream( bs );
84
#if ENABLE_TRACING
85
  DTRACE( g_trace_ctx, D_HEADER, "=========== Filler Data ===========\n" );
86
#endif
87
0
  fdSize = 0;
88
0
  while( m_pcBitstream->getNumBitsLeft() > 8 )
89
0
  {
90
0
    X_READ_CODE_NO_RANGE( fd_ff_byte, 8 );
91
0
    CHECK_WARN( fd_ff_byte != 0xff, "Invalid fillter data not '0xff'" );
92
0
    fdSize++;
93
0
  }
94
0
  xReadRbspTrailingBits();
95
0
}
96
97
98
// ====================================================================================================================
99
// Public member functions
100
// ====================================================================================================================
101
102
void HLSyntaxReader::copyRefPicList( const SPS* sps, const ReferencePictureList* source_rpl, ReferencePictureList* dest_rp )
103
296
{
104
296
  memcpy( dest_rp, source_rpl, sizeof( ReferencePictureList ) );
105
106
296
  if( !sps->getLongTermRefsPresent() )
107
129
  {
108
129
    dest_rp->setNumberOfLongtermPictures( 0 );
109
129
  }
110
296
}
111
112
void HLSyntaxReader::parseRefPicList( ReferencePictureList* rpl, int rplIdx, const SPS* sps )
113
843
{
114
843
  X_READ_UVLC_idx( num_ref_entries, "[ listIdx ][ rplsIdx ]", 0, MAX_NUM_REF_PICS );
115
  // The value of num_ref_entries[ listIdx ][ rplsIdx ] shall be in the range of 0 to MaxDpbSize + 13, inclusive,
116
  //  where MaxDpbSize is as specified in clause A.4.2.
117
118
843
  if( sps->getLongTermRefsPresent() && num_ref_entries > 0 && rplIdx != -1 )   // rplsIdx == -1 means it's called from parsePicOrSliceHeader
119
222
  {
120
222
    X_READ_FLAG_idx( ltrp_in_header_flag, "[ listIdx ][ rplsIdx ]" );
121
222
    rpl->setLtrpInSliceHeaderFlag( ltrp_in_header_flag );
122
222
  }
123
621
  else if( sps->getLongTermRefsPresent() )
124
305
  {
125
    // When sps_long_term_ref_pics_flag is equal to 1 and rplsIdx is equal to sps_num_ref_pic_lists[ listIdx ],
126
    //  the value of ltrp_in_header_flag[ listIdx ][ rplsIdx ] is inferred to be equal to 1.
127
305
    rpl->setLtrpInSliceHeaderFlag( 1 );
128
305
  }
129
130
843
  uint32_t numStrp = 0;
131
843
  uint32_t numLtrp = 0;
132
843
  uint32_t numIlrp = 0;
133
134
843
  rpl->setInterLayerPresentFlag( sps->getInterLayerPresentFlag() );
135
136
843
  int prevDelta = 0;
137
1.96k
  for( unsigned ii = 0; ii < num_ref_entries; ii++ )
138
1.11k
  {
139
1.11k
    if( rpl->getInterLayerPresentFlag() )
140
0
    {
141
0
      X_READ_FLAG_idx( inter_layer_ref_pic_flag, "[ listIdx ][ rplsIdx ][ i ]" );
142
0
      if( inter_layer_ref_pic_flag )
143
0
      {
144
0
        X_READ_UVLC_idx( ilrp_idx, "[ listIdx ][ rplsIdx ][ i ]", 0, MAX_VPS_LAYERS );
145
        // The value of ilrp_idx[ listIdx ][ rplsIdx ][ i ] shall be in the range of 0 to NumDirectRefLayers[ GeneralLayerIdx[ nuh_layer_id ] ] − 1, inclusive.
146
0
        rpl->setRefPicIdentifier( ii, 0, true, true, ilrp_idx );
147
0
        numIlrp++;
148
149
0
        continue;
150
0
      }
151
0
    }
152
153
    // if( !inter_layer_ref_pic_flag )  // implicit due to previous `continue`
154
1.11k
    {
155
1.11k
      bool isLongTerm = false;
156
1.11k
      if( sps->getLongTermRefsPresent() )
157
795
      {
158
795
        X_READ_FLAG_idx( st_ref_pic_flag, "[ listIdx ][ rplsIdx ][ i ]" );
159
795
        isLongTerm = !st_ref_pic_flag;
160
795
      }
161
162
1.11k
      if( !isLongTerm )
163
735
      {
164
735
        X_READ_UVLC_idx( abs_delta_poc_st, "[ listIdx ][ rplsIdx ][ i ]", 0, ( 1 << 15 ) - 1 );
165
735
        int deltaPocSt = abs_delta_poc_st;
166
735
        if( ( !sps->getUseWP() && !sps->getUseWPBiPred() ) || ii == 0 )
167
365
        {
168
365
          deltaPocSt++;
169
365
        }
170
171
735
        if( deltaPocSt > 0 )
172
535
        {
173
535
          X_READ_FLAG_idx( strp_entry_sign_flag, "[ listIdx ][ rplsIdx ][ i ]" );
174
535
          if( strp_entry_sign_flag )
175
301
          {
176
301
            deltaPocSt = -deltaPocSt;
177
301
          }
178
535
        }
179
180
735
        deltaPocSt += prevDelta;
181
735
        prevDelta = deltaPocSt;
182
735
        rpl->setRefPicIdentifier( ii, deltaPocSt, false, false, 0 );
183
735
        numStrp++;
184
735
      }
185
384
      else
186
384
      {
187
384
        if( !rpl->getLtrpInSliceHeaderFlag() )
188
111
        {
189
111
          X_READ_CODE_NO_RANGE_idx( rpls_poc_lsb_lt, "[ listIdx ][ rplsIdx ][ j++ ]", sps->getBitsForPOC() );
190
111
          rpl->setRefPicIdentifier( ii, rpls_poc_lsb_lt, true, false, 0 );
191
111
        }
192
273
        else
193
273
        {
194
273
          rpl->setRefPicIdentifier( ii, 0, true, false, 0 );
195
273
        }
196
384
        numLtrp++;
197
384
      }
198
1.11k
    }
199
1.11k
  }
200
843
  rpl->setNumberOfShorttermPictures( numStrp );
201
843
  rpl->setNumberOfLongtermPictures( numLtrp );
202
843
  rpl->setNumberOfInterLayerPictures( numIlrp );
203
843
}
204
205
void HLSyntaxReader::parsePPS( PPS* pcPPS, const ParameterSetManager* parameterSetManager )
206
4
{
207
#if ENABLE_TRACING
208
  xTracePPSHeader();
209
#endif
210
211
4
  X_READ_CODE_NO_RANGE( pps_pic_parameter_set_id, 6 );
212
4
  pcPPS->setPPSId( pps_pic_parameter_set_id );
213
214
4
  X_READ_CODE( pps_seq_parameter_set_id, 4, 0, 15 );
215
4
  const SPS* sps = parameterSetManager->getSPS( pps_seq_parameter_set_id );
216
4
  CHECK( !sps, "SPS with id " << pps_seq_parameter_set_id << " missing." );
217
4
  pcPPS->setSPSId( pps_seq_parameter_set_id );
218
4
  pcPPS->setParsedWithSPS( sps );
219
220
4
  const int SubWidthC  = 1 << getChannelTypeScaleX( CHANNEL_TYPE_CHROMA, sps->getChromaFormatIdc() );
221
4
  const int SubHeightC = 1 << getChannelTypeScaleY( CHANNEL_TYPE_CHROMA, sps->getChromaFormatIdc() );
222
223
4
  X_READ_FLAG( pps_mixed_nalu_types_in_pic_flag );
224
4
  pcPPS->setMixedNaluTypesInPicFlag( pps_mixed_nalu_types_in_pic_flag == 1 );
225
226
4
  const int CtbSizeY   = sps->getCTUSize();
227
4
  const int MinCbSizeY = 1 << sps->getLog2MinCodingBlockSize();
228
229
4
  X_READ_UVLC( pps_pic_width_in_luma_samples, 1, sps->getMaxPicWidthInLumaSamples() );
230
4
  CHECK( pps_pic_width_in_luma_samples & std::max( 8 - 1, MinCbSizeY - 1 ), "pps_pic_width_in_luma_samples not a multiple of 8 or MinCbSizeY" );
231
4
  CHECK( !sps->getResChangeInClvsEnabledFlag() && pps_pic_width_in_luma_samples != sps->getMaxPicWidthInLumaSamples(),
232
4
         "When sps_res_change_in_clvs_allowed_flag equal to 0, the value of pps_pic_width_in_luma_samples shall be equal"
233
4
         " to sps_pic_width_max_in_luma_samples." )
234
4
  CHECK( sps->getUseWrapAround() && CtbSizeY / MinCbSizeY + 1 > pps_pic_width_in_luma_samples / MinCbSizeY - 1,
235
4
         "When sps_ref_wraparound_enabled_flag is equal to 1, the value of ( CtbSizeY / MinCbSizeY + 1 ) shall be less than or"
236
4
         " equal to the value of ( pps_pic_width_in_luma_samples / MinCbSizeY − 1 )." );
237
4
  pcPPS->setPicWidthInLumaSamples( pps_pic_width_in_luma_samples );
238
239
4
  X_READ_UVLC( pps_pic_height_in_luma_samples, 1, sps->getMaxPicHeightInLumaSamples() );
240
4
  CHECK( pps_pic_height_in_luma_samples & std::max( 8 - 1, MinCbSizeY - 1 ), "pps_pic_height_in_luma_samples not a multiple of 8 or MinCbSizeY" );
241
4
  CHECK( !sps->getResChangeInClvsEnabledFlag() && pps_pic_height_in_luma_samples != sps->getMaxPicHeightInLumaSamples(),
242
4
         "When sps_res_change_in_clvs_allowed_flag equal to 0, the value of pps_pic_height_in_luma_samples shall be equal"
243
4
         " to sps_pic_height_max_in_luma_samples." )
244
4
  pcPPS->setPicHeightInLumaSamples( pps_pic_height_in_luma_samples );
245
246
4
  const unsigned PicWidthInCtbsY     = ( pps_pic_width_in_luma_samples + CtbSizeY - 1 ) / CtbSizeY;      (void) PicWidthInCtbsY;
247
4
  const unsigned PicHeightInCtbsY    = ( pps_pic_height_in_luma_samples + CtbSizeY - 1 ) / CtbSizeY;     (void) PicHeightInCtbsY;
248
4
  const unsigned PicSizeInCtbsY      = PicWidthInCtbsY * PicHeightInCtbsY;                               (void) PicSizeInCtbsY;
249
4
  const unsigned PicWidthInMinCbsY   = pps_pic_width_in_luma_samples / MinCbSizeY;                       (void) PicWidthInMinCbsY;
250
4
  const unsigned PicHeightInMinCbsY  = pps_pic_height_in_luma_samples / MinCbSizeY;                      (void) PicHeightInMinCbsY;
251
4
  const unsigned PicSizeInMinCbsY    = PicWidthInMinCbsY * PicHeightInMinCbsY;                           (void) PicSizeInMinCbsY;
252
4
  const unsigned PicSizeInSamplesY   = pps_pic_width_in_luma_samples * pps_pic_height_in_luma_samples;   (void) PicSizeInSamplesY;
253
4
  const unsigned PicWidthInSamplesC  = pps_pic_width_in_luma_samples / SubWidthC;                        (void) PicWidthInSamplesC;
254
4
  const unsigned PicHeightInSamplesC = pps_pic_height_in_luma_samples / SubHeightC;                      (void) PicHeightInSamplesC;
255
256
4
  X_READ_FLAG( pps_conformance_window_flag );
257
4
  CHECK( pps_conformance_window_flag != 0 && pcPPS->getPicWidthInLumaSamples() == sps->getMaxPicWidthInLumaSamples()
258
4
           && pcPPS->getPicHeightInLumaSamples() == sps->getMaxPicHeightInLumaSamples(),
259
4
         "pps_conformance_window_flag shall be equal to 0" )
260
4
  pcPPS->setConformanceWindowPresentFlag( pps_conformance_window_flag );
261
262
4
  if( pps_conformance_window_flag != 0 )
263
0
  {
264
0
    X_READ_UVLC_NO_RANGE( pps_conf_win_left_offset );
265
0
    X_READ_UVLC_NO_RANGE( pps_conf_win_right_offset );
266
0
    X_READ_UVLC_NO_RANGE( pps_conf_win_top_offset );
267
0
    X_READ_UVLC_NO_RANGE( pps_conf_win_bottom_offset );
268
269
0
    CHECK( SubWidthC * ( uint64_t( pps_conf_win_left_offset ) + pps_conf_win_right_offset ) >= pps_pic_width_in_luma_samples,
270
0
           "pps_conf_win_left_offset + pps_conf_win_right_offset too large" );
271
0
    CHECK( SubHeightC * ( uint64_t( pps_conf_win_top_offset ) + pps_conf_win_bottom_offset ) >= pps_pic_height_in_luma_samples,
272
0
           "pps_conf_win_top_offset + pps_conf_win_bottom_offset too large" );
273
274
0
    Window& conf = pcPPS->getConformanceWindow();
275
0
    conf.setWindowLeftOffset( pps_conf_win_left_offset );
276
0
    conf.setWindowRightOffset( pps_conf_win_right_offset );
277
0
    conf.setWindowTopOffset( pps_conf_win_top_offset );
278
0
    conf.setWindowBottomOffset( pps_conf_win_bottom_offset );
279
0
  }
280
281
4
  X_READ_FLAG_CHECK( pps_scaling_window_explicit_signalling_flag,
282
4
                     !sps->getRprEnabledFlag() && pps_scaling_window_explicit_signalling_flag != 0,
283
4
                     "When sps_ref_pic_resampling_enabled_flag is equal to 0, the value of pps_scaling_window_explicit_signalling_flag shall be equal to 0" );
284
285
4
  if( pps_scaling_window_explicit_signalling_flag != 0 )
286
0
  {
287
0
    X_READ_SVLC_NO_RANGE( pps_scaling_win_left_offset );
288
0
    X_READ_SVLC_NO_RANGE( pps_scaling_win_right_offset );
289
0
    X_READ_SVLC_NO_RANGE( pps_scaling_win_top_offset );
290
0
    X_READ_SVLC_NO_RANGE( pps_scaling_win_bottom_offset );
291
292
0
    CHECK( SubWidthC * int64_t( pps_scaling_win_left_offset ) < -int64_t( pps_pic_width_in_luma_samples ) * 15
293
0
             || SubWidthC * int64_t( pps_scaling_win_left_offset ) >= pps_pic_width_in_luma_samples,
294
0
           "pps_scaling_win_left_offset (" << pps_scaling_win_left_offset << ") out of bounds" );
295
0
    CHECK( SubWidthC * int64_t( pps_scaling_win_right_offset ) < -int64_t( pps_pic_width_in_luma_samples ) * 15
296
0
             || SubWidthC * int64_t( pps_scaling_win_right_offset ) >= pps_pic_width_in_luma_samples,
297
0
           "pps_scaling_win_right_offset (" << pps_scaling_win_right_offset << ") out of bounds" );
298
0
    CHECK( SubHeightC * int64_t( pps_scaling_win_top_offset ) < -int64_t( pps_pic_height_in_luma_samples ) * 15
299
0
             || SubHeightC * int64_t( pps_scaling_win_top_offset ) >= pps_pic_height_in_luma_samples,
300
0
           "pps_scaling_win_top_offset (" << pps_scaling_win_top_offset << ") out of bounds" );
301
0
    CHECK( SubHeightC * int64_t( pps_scaling_win_bottom_offset ) < -int64_t( pps_pic_height_in_luma_samples ) * 15
302
0
             || SubHeightC * int64_t( pps_scaling_win_bottom_offset ) >= pps_pic_height_in_luma_samples,
303
0
           "pps_scaling_win_bottom_offset (" << pps_scaling_win_bottom_offset << ") out of bounds" );
304
305
0
    CHECK( SubWidthC * ( int64_t( pps_scaling_win_left_offset ) + pps_scaling_win_right_offset ) < -int64_t( pps_pic_width_in_luma_samples ) * 15
306
0
             || SubWidthC * ( int64_t( pps_scaling_win_left_offset ) + pps_scaling_win_right_offset ) >= pps_pic_width_in_luma_samples,
307
0
           "SubWidthC * ( pps_scaling_win_left_offset + pps_scaling_win_right_offset ) shall be greater than or equal to"
308
0
           " -pps_pic_width_in_luma_samples * 15 and less than pps_pic_width_in_luma_samples."
309
0
           " (pps_scaling_win_left_offset + pps_scaling_win_right_offset = "
310
0
             << int64_t( pps_scaling_win_left_offset ) + pps_scaling_win_right_offset << ")" );
311
312
0
    CHECK( SubHeightC * ( int64_t( pps_scaling_win_top_offset ) + pps_scaling_win_bottom_offset ) < -int64_t( pps_pic_height_in_luma_samples ) * 15
313
0
             || SubHeightC * ( int64_t( pps_scaling_win_top_offset ) + pps_scaling_win_bottom_offset ) >= pps_pic_height_in_luma_samples,
314
0
           "SubHeightC * ( pps_scaling_win_top_offset + pps_scaling_win_bottom_offset ) shall be greater than or equal to"
315
0
           " -pps_pic_height_in_luma_samples * 15 and less than pps_pic_height_in_luma_samples."
316
0
           " (pps_scaling_win_top_offset + pps_scaling_win_bottom_offset = "
317
0
             << int64_t( pps_scaling_win_top_offset ) + pps_scaling_win_bottom_offset << ")" )
318
319
#if 0
320
    // these checks need to be moved to the creation of ref pic lists
321
    //
322
    const int CurrPicScalWinWidthL  = pps_pic_width_in_luma_samples - SubWidthC * ( pps_scaling_win_right_offset + pps_scaling_win_left_offset );
323
    const int CurrPicScalWinHeightL = pps_pic_height_in_luma_samples - SubHeightC * ( pps_scaling_win_bottom_offset + pps_scaling_win_top_offset );
324
    CHECK( CurrPicScalWinWidthL * 2 < refPicScalWinWidthL,
325
           "Requirement of bitstream conformance: CurrPicScalWinWidthL * 2 is greater than or equal to refPicScalWinWidthL." );
326
    CHECK( CurrPicScalWinHeightL * 2 < refPicScalWinHeightL,
327
           "Requirement of bitstream conformance: CurrPicScalWinHeightL * 2 is greater than or equal to refPicScalWinHeightL." );
328
    CHECK( CurrPicScalWinWidthL > refPicScalWinWidthL * 8,
329
           "Requirement of bitstream conformance: CurrPicScalWinWidthL is less than or equal to refPicScalWinWidthL * 8." );
330
    CHECK( CurrPicScalWinHeightL > refPicScalWinHeightL * 8,
331
           "Requirement of bitstream conformance: CurrPicScalWinHeightL is less than or equal to refPicScalWinHeightL * 8." );
332
    CHECK( CurrPicScalWinWidthL * sps->getMaxPicWidthInLumaSamples() < refPicScalWinWidthL * ( pps_pic_width_in_luma_samples - std::max( 8, MinCbSizeY ) ),
333
           "Requirement of bitstream conformance: CurrPicScalWinWidthL * sps_pic_width_max_in_luma_samples is greater than or equal to"
334
           " refPicScalWinWidthL * ( pps_pic_width_in_luma_samples - Max( 8, MinCbSizeY ) )." );
335
    CHECK( CurrPicScalWinHeightL * sps->getMaxPicHeightInLumaSamples() < refPicScalWinHeightL * ( pps_pic_height_in_luma_samples - std::max( 8, MinCbSizeY ) ),
336
           "Requirement of bitstream conformance: CurrPicScalWinHeightL * sps_pic_height_max_in_luma_samples is greater than or equal to"
337
           " refPicScalWinHeightL * ( pps_pic_height_in_luma_samples - Max( 8, MinCbSizeY ) )." );
338
#endif
339
340
0
    Window& scalingWindow = pcPPS->getScalingWindow();
341
0
    scalingWindow.setWindowLeftOffset( pps_scaling_win_left_offset );
342
0
    scalingWindow.setWindowRightOffset( pps_scaling_win_right_offset );
343
0
    scalingWindow.setWindowTopOffset( pps_scaling_win_top_offset );
344
0
    scalingWindow.setWindowBottomOffset( pps_scaling_win_bottom_offset );
345
0
  }
346
4
  else
347
4
  {
348
4
    pcPPS->setScalingWindow( pcPPS->getConformanceWindow() );
349
4
  }
350
351
4
  X_READ_FLAG( pps_output_flag_present_flag );
352
4
  pcPPS->setOutputFlagPresentFlag( pps_output_flag_present_flag );
353
354
4
  X_READ_FLAG_CHECK( pps_no_pic_partition_flag,
355
4
                     ( sps->getNumSubPics() > 1 || pps_mixed_nalu_types_in_pic_flag == 1 ) && pps_no_pic_partition_flag != 0,
356
4
                     "When sps_num_subpics_minus1 is greater than 0 or pps_mixed_nalu_types_in_pic_flag is equal to 1, the value of pps_no_pic_partition_flag "
357
4
                     "shall be equal to 0." );
358
4
  pcPPS->setNoPicPartitionFlag( pps_no_pic_partition_flag );
359
360
4
  X_READ_FLAG( pps_subpic_id_mapping_present_flag );
361
4
  CHECK( ( sps->getSubPicIdMappingExplicitlySignalledFlag() == 0 || sps->getSubPicIdMappingPresentFlag() == 1 ) && pps_subpic_id_mapping_present_flag != 0,
362
4
         "If sps_subpic_id_mapping_explicitly_signalled_flag is 0 or sps_subpic_id_mapping_present_flag is equal to 1, the value of"
363
4
         " pps_subpic_id_mapping_present_flag shall be equal to 0." );
364
4
  CHECK( ( sps->getSubPicIdMappingExplicitlySignalledFlag() == 1 && sps->getSubPicIdMappingPresentFlag() == 0 ) && pps_subpic_id_mapping_present_flag != 1,
365
4
         "Otherwise (sps_subpic_id_mapping_explicitly_signalled_flag is equal to 1 and sps_subpic_id_mapping_present_flag is equal to 0), the value of"
366
4
         " pps_subpic_id_mapping_present_flag  shall be equal to 1." );
367
4
  pcPPS->setSubPicIdMappingPresentFlag( pps_subpic_id_mapping_present_flag );
368
369
4
  if( pps_subpic_id_mapping_present_flag )
370
0
  {
371
0
    if( !pps_no_pic_partition_flag )
372
0
    {
373
0
      X_READ_UVLC( pps_num_subpics_minus1, 0, MAX_NUM_SUB_PICS - 1 );
374
0
      CHECK( pps_num_subpics_minus1 != sps->getNumSubPics() - 1, "pps_num_subpics_minus1 shall be equal to sps_num_subpics_minus1" );
375
0
      pcPPS->setNumSubPics( pps_num_subpics_minus1 + 1 );
376
0
    }
377
0
    else
378
0
    {
379
      // When pps_no_pic_partition_flag is equal to 1, the value of pps_num_subpics_minus1 is inferred to be equal to 0.
380
0
      pcPPS->setNumSubPics( 1 );
381
0
    }
382
383
0
    X_READ_UVLC( pps_subpic_id_len_minus1, 0, 15 );
384
0
    CHECK( pps_subpic_id_len_minus1 != sps->getSubPicIdLen() - 1, "pps_subpic_id_len_minus1 shall be equal to sps_subpic_id_len_minus1" );
385
0
    CHECK( ( 1 << ( pps_subpic_id_len_minus1 + 1 ) ) < pcPPS->getNumSubPics(), "pps_subpic_id_len too short" );
386
0
    pcPPS->setSubPicIdLen( pps_subpic_id_len_minus1 + 1 );
387
388
0
    for( int picIdx = 0; picIdx < pcPPS->getNumSubPics(); picIdx++ )
389
0
    {
390
0
      X_READ_CODE_NO_RANGE_idx( pps_subpic_id, "[i]", pcPPS->getSubPicIdLen() );
391
0
      pcPPS->setSubPicId( picIdx, pps_subpic_id );
392
0
    }
393
0
  }
394
4
  else
395
4
  {
396
4
    for( int picIdx = 0; picIdx < MAX_NUM_SUB_PICS; picIdx++ )
397
0
    {
398
0
      pcPPS->setSubPicId( picIdx, sps->getSubPicIdMappingExplicitlySignalledFlag() ? sps->getSubPicId( picIdx ) : picIdx );
399
0
    }
400
4
  }
401
4
  for( int i = 0; i < pcPPS->getNumSubPics(); ++i )
402
0
  {
403
0
    for( int j = 0; j < i; ++j )
404
0
    {
405
0
      CHECK( pcPPS->getSubPicId( i ) == pcPPS->getSubPicId( j ),
406
0
                         "It is a requirement of bitstream conformance that, for any two different values of i and j in the range of"
407
0
                         " 0 to sps_num_subpics_minus1, inclusive, SubpicIdVal[ i ] shall not be equal to SubpicIdVal[ j ]." )
408
0
    }
409
0
  }
410
411
4
  pcPPS->resetTileSliceInfo();
412
413
4
  if( !pps_no_pic_partition_flag )
414
0
  {
415
    // CTU size - required to match size in SPS
416
0
    X_READ_CODE( pps_log2_ctu_size_minus5, 2, 0,2 );
417
0
    CHECK( pps_log2_ctu_size_minus5 != getLog2( sps->getCTUSize() ) - 5, "pps_log2_ctu_size_minus5 shall be equal to sps_log2_ctu_size_minus5" );
418
0
    pcPPS->setLog2CtuSize( pps_log2_ctu_size_minus5 + 5 );
419
420
    // number of explicit tile columns/rows
421
422
0
    X_READ_UVLC( pps_num_exp_tile_columns_minus1, 0, PicWidthInCtbsY - 1 );
423
0
    pcPPS->setNumExpTileColumns( pps_num_exp_tile_columns_minus1 + 1 );
424
425
0
    X_READ_UVLC( pps_num_exp_tile_rows_minus1, 0, PicHeightInCtbsY - 1 );
426
0
    pcPPS->setNumExpTileRows( pps_num_exp_tile_rows_minus1 + 1 );
427
0
    CHECK( pcPPS->getNumExpTileColumns() > MAX_TILE_COLS, "Number of explicit tile columns exceeds valid range" );
428
429
    // tile sizes
430
0
    for( int colIdx = 0; colIdx < pcPPS->getNumExpTileColumns(); colIdx++ )
431
0
    {
432
0
      X_READ_UVLC_idx( pps_tile_column_width_minus1, "[i]", 0, PicWidthInCtbsY - 1 );
433
0
      pcPPS->addTileColumnWidth( pps_tile_column_width_minus1 + 1 );
434
0
    }
435
0
    for( int rowIdx = 0; rowIdx < pcPPS->getNumExpTileRows(); rowIdx++ )
436
0
    {
437
0
      X_READ_UVLC_idx( pps_tile_row_height_minus1, "[i]", 0, PicHeightInCtbsY - 1 );
438
0
      pcPPS->addTileRowHeight( pps_tile_row_height_minus1 + 1 );
439
0
    }
440
0
    pcPPS->initTiles();
441
442
    // rectangular slice signalling
443
0
    if( pcPPS->getNumTiles() > 1 )
444
0
    {
445
0
      X_READ_FLAG( pps_loop_filter_across_tiles_enabled_flag );
446
0
      pcPPS->setLoopFilterAcrossTilesEnabledFlag( pps_loop_filter_across_tiles_enabled_flag );
447
0
      X_READ_FLAG( pps_rect_slice_flag );
448
0
      CHECK( ( sps->getSubPicInfoPresentFlag() || pps_mixed_nalu_types_in_pic_flag ) && pps_rect_slice_flag != 1,
449
0
             "When sps_subpic_info_present_flag is equal to 1 or pps_mixed_nalu_types_in_pic_flag is equal to 1,"
450
0
             " the value of pps_rect_slice_flag shall be equal to 1." );
451
0
      pcPPS->setRectSliceFlag( pps_rect_slice_flag );
452
0
    }
453
0
    else
454
0
    {
455
0
      pcPPS->setLoopFilterAcrossTilesEnabledFlag( false );
456
0
      pcPPS->setRectSliceFlag( true );
457
0
    }
458
459
0
    if( pcPPS->getRectSliceFlag() )
460
0
    {
461
0
      X_READ_FLAG( pps_single_slice_per_subpic_flag );
462
0
      pcPPS->setSingleSlicePerSubPicFlag( pps_single_slice_per_subpic_flag );
463
0
    }
464
465
0
    if( pcPPS->getRectSliceFlag() && !pcPPS->getSingleSlicePerSubPicFlag() )
466
0
    {
467
0
      X_READ_UVLC( pps_num_slices_in_pic_minus1, 0, MAX_SLICES - 1 /*  TODO: should be MaxSlicesPerAU -1  */ );
468
0
      pcPPS->setNumSlicesInPic( pps_num_slices_in_pic_minus1 + 1 );
469
470
0
      if( pps_num_slices_in_pic_minus1 > 1 )
471
0
      {
472
0
        X_READ_FLAG( pps_tile_idx_delta_present_flag );
473
0
        pcPPS->setTileIdxDeltaPresentFlag( pps_tile_idx_delta_present_flag );
474
0
      }
475
0
      pcPPS->initRectSlices();
476
477
0
      int32_t tileIdx = 0;
478
      // read rectangular slice parameters
479
0
      for( int sliceIdx = 0; sliceIdx < pcPPS->getNumSlicesInPic() - 1; sliceIdx++ )
480
0
      {
481
0
        pcPPS->setSliceTileIdx( sliceIdx, tileIdx );   // this is SliceTopLeftTileIdx[ i ]
482
483
        // complete tiles within a single slice
484
0
        if( tileIdx % pcPPS->getNumTileColumns() != pcPPS->getNumTileColumns() - 1 )
485
0
        {
486
0
          X_READ_UVLC_idx( pps_slice_width_in_tiles_minus1, "[i]", 0, pcPPS->getNumTileColumns() - 1 );
487
0
          pcPPS->setSliceWidthInTiles( sliceIdx, pps_slice_width_in_tiles_minus1 + 1 );
488
0
        }
489
0
        else
490
0
        {
491
0
          pcPPS->setSliceWidthInTiles( sliceIdx, 1 );
492
0
        }
493
494
0
        if( tileIdx / pcPPS->getNumTileColumns() != pcPPS->getNumTileRows() - 1
495
0
            && ( pcPPS->getTileIdxDeltaPresentFlag() || tileIdx % pcPPS->getNumTileColumns() == 0 ) )
496
0
        {
497
0
          X_READ_UVLC_idx( pps_slice_height_in_tiles_minus1, "[i]", 0, pcPPS->getNumTileRows() - 1 );
498
0
          pcPPS->setSliceHeightInTiles( sliceIdx, pps_slice_height_in_tiles_minus1 + 1 );
499
0
        }
500
0
        else
501
0
        {
502
0
          if( tileIdx / pcPPS->getNumTileColumns() == pcPPS->getNumTileRows() - 1 )
503
0
          {
504
0
            pcPPS->setSliceHeightInTiles( sliceIdx, 1 );
505
0
          }
506
0
          else
507
0
          {
508
0
            pcPPS->setSliceHeightInTiles( sliceIdx, pcPPS->getSliceHeightInTiles( sliceIdx - 1 ) );
509
0
          }
510
0
        }
511
512
        // multiple slices within a single tile special case
513
0
        if( pcPPS->getSliceWidthInTiles( sliceIdx ) == 1 && pcPPS->getSliceHeightInTiles( sliceIdx ) == 1 )
514
0
        {
515
0
          if( pcPPS->getTileRowHeight( tileIdx / pcPPS->getNumTileColumns() ) > 1 )
516
0
          {
517
0
            X_READ_UVLC_idx( pps_num_exp_slices_in_tile, "[i]", 0, pcPPS->getTileRowHeight( tileIdx / pcPPS->getNumTileColumns() ) - 1 );
518
0
            if( pps_num_exp_slices_in_tile == 0 )
519
0
            {
520
0
              pcPPS->setNumSlicesInTile( sliceIdx, 1 );
521
0
              pcPPS->setSliceHeightInCtu( sliceIdx, pcPPS->getTileRowHeight( tileIdx / pcPPS->getNumTileColumns() ) );
522
0
            }
523
0
            else   // ( pps_num_exp_slices_in_tile > 0 )
524
0
            {
525
0
              uint32_t remTileRowHeight         = pcPPS->getTileRowHeight( tileIdx / pcPPS->getNumTileColumns() );
526
0
              uint32_t lastExpSliceHeightInCtus = 0;
527
528
0
              int j = 0;
529
0
              for( ; j < pps_num_exp_slices_in_tile; j++ )
530
0
              {
531
0
                X_READ_UVLC_idx( pps_exp_slice_height_in_ctus_minus1, "[i][j]", 0, pcPPS->getTileRowHeight( tileIdx / pcPPS->getNumTileColumns() ) - 1 );
532
0
                pcPPS->setSliceHeightInCtu( sliceIdx + j, pps_exp_slice_height_in_ctus_minus1 + 1 );
533
0
                remTileRowHeight -= ( pps_exp_slice_height_in_ctus_minus1 + 1 );
534
535
0
                lastExpSliceHeightInCtus = pps_exp_slice_height_in_ctus_minus1 + 1;
536
0
              }
537
538
0
              uint32_t uniformSliceHeight = lastExpSliceHeightInCtus;
539
0
              while( remTileRowHeight >= uniformSliceHeight )
540
0
              {
541
0
                pcPPS->setSliceHeightInCtu( sliceIdx + j, uniformSliceHeight );
542
0
                remTileRowHeight -= uniformSliceHeight;
543
0
                j++;
544
0
              }
545
0
              if( remTileRowHeight > 0 )
546
0
              {
547
0
                pcPPS->setSliceHeightInCtu( sliceIdx + j, remTileRowHeight );
548
0
                j++;
549
0
              }
550
0
              for( int k = 0; k < j; k++ )
551
0
              {
552
0
                pcPPS->setNumSlicesInTile( sliceIdx + k, j );
553
0
                pcPPS->setSliceWidthInTiles( sliceIdx + k, 1 );
554
0
                pcPPS->setSliceHeightInTiles( sliceIdx + k, 1 );
555
0
                pcPPS->setSliceTileIdx( sliceIdx + k, tileIdx );
556
0
              }
557
0
              sliceIdx += ( j - 1 );
558
0
            }    // ( pps_num_exp_slices_in_tile > 0 )
559
0
          }
560
0
          else   // ( pps->getTileRowHeight( tileIdx / pps->getNumTileColumns() ) <= 1 )
561
0
          {
562
0
            pcPPS->setNumSlicesInTile( sliceIdx, 1 );
563
0
            pcPPS->setSliceHeightInCtu( sliceIdx, pcPPS->getTileRowHeight( tileIdx / pcPPS->getNumTileColumns() ) );
564
0
          }
565
0
        }   // ( pps->getSliceWidthInTiles(sliceIdx) == 1 && pps->getSliceHeightInTiles(sliceIdx) == 1 )
566
567
        // tile index offset to start of next slice
568
0
        if( sliceIdx < pps_num_slices_in_pic_minus1 )
569
0
        {
570
0
          if( pcPPS->getTileIdxDeltaPresentFlag() )
571
0
          {
572
0
            X_READ_SVLC_idx( pps_tile_idx_delta_val, "[i]", -(int) pcPPS->getNumTiles() + 1, (int) pcPPS->getNumTiles() - 1 );
573
0
            CHECK( pps_tile_idx_delta_val == 0, "When present, the value of pps_tile_idx_delta_val[ i ] shall not be equal to 0." );
574
575
            // TODO: When pps_rect_slice_flag is equal to 1, it is a requirement of bitstrream conformance that, for any two slices, with picture-
576
            //       level slice indices idxA and idxB, that belong to the same picture and different subpictures, when
577
            //       SubpicIdxForSlice[idxA] is less than SubpicIdxForSlice[idxB], the value of idxA shall be less than idxB.
578
            // CHECK( pps->getRectSliceFlag() && /* TODO */ )
579
580
0
            tileIdx += pps_tile_idx_delta_val;
581
0
            CHECK( tileIdx < 0 || tileIdx >= (int) pcPPS->getNumTiles(), "Invalid tile_idx_delta." );
582
0
          }
583
0
          else
584
0
          {
585
0
            tileIdx += pcPPS->getSliceWidthInTiles( sliceIdx );
586
0
            if( tileIdx % pcPPS->getNumTileColumns() == 0 )
587
0
            {
588
0
              tileIdx += ( pcPPS->getSliceHeightInTiles( sliceIdx ) - 1 ) * pcPPS->getNumTileColumns();
589
0
            }
590
0
          }
591
0
        }
592
        // TODO: hier?
593
0
        CHECK( tileIdx < 0 || tileIdx >= (int) pcPPS->getNumTiles(), "Invalid tile_idx_delta." );
594
595
0
      }   // for( int i = 0; i < pps->getNumSlicesInPic()-1; i++ )
596
0
      pcPPS->setSliceTileIdx( pcPPS->getNumSlicesInPic() - 1, tileIdx );
597
598
0
    }   // if( pps->getRectSliceFlag() && !pps->getSingleSlicePerSubPicFlag() )
599
600
0
    if( !pcPPS->getRectSliceFlag() || pcPPS->getSingleSlicePerSubPicFlag() || pcPPS->getNumSlicesInPic() > 1 )
601
0
    {
602
0
      X_READ_FLAG( pps_loop_filter_across_slices_enabled_flag );
603
0
      pcPPS->setLoopFilterAcrossSlicesEnabledFlag( pps_loop_filter_across_slices_enabled_flag );
604
0
    }
605
0
    else
606
0
    {
607
0
      pcPPS->setLoopFilterAcrossSlicesEnabledFlag( false );
608
0
    }
609
0
  }
610
4
  else   // if( !pps_no_pic_partition_flag )
611
4
  {
612
    // When pps_no_pic_partition_flag is equal to 1, the value of pps_single_slice_per_subpic_flag is inferred to be equal to 1.
613
4
    pcPPS->setSingleSlicePerSubPicFlag( 1 );
614
4
  }
615
616
4
  X_READ_FLAG( pps_cabac_init_present_flag );
617
4
  pcPPS->setCabacInitPresentFlag( pps_cabac_init_present_flag );
618
619
4
  {
620
4
    X_READ_UVLC_idx( pps_num_ref_idx_default_active_minus1, "[0]", 0, 14 );
621
4
    pcPPS->setNumRefIdxL0DefaultActive( pps_num_ref_idx_default_active_minus1 + 1 );
622
4
  }
623
4
  {
624
4
    X_READ_UVLC_idx( pps_num_ref_idx_default_active_minus1, "[1]", 0, 14 );
625
4
    pcPPS->setNumRefIdxL1DefaultActive( pps_num_ref_idx_default_active_minus1 + 1 );
626
4
  }
627
628
4
  X_READ_FLAG( pps_rpl1_idx_present_flag );
629
4
  pcPPS->setRpl1IdxPresentFlag( pps_rpl1_idx_present_flag );
630
631
4
  X_READ_FLAG_CHECK( pps_weighted_pred_flag,
632
4
                     sps->getUseWP() == 0 && pps_weighted_pred_flag != 0,
633
4
                     "sps_weighted_pred_flag is equal to 0, the value of pps_weighted_pred_flag shall be equal to 0." );
634
4
  pcPPS->setUseWP( pps_weighted_pred_flag );
635
636
4
  X_READ_FLAG_CHECK( pps_weighted_bipred_flag,
637
4
                     sps->getUseWPBiPred() == 0 && pps_weighted_bipred_flag != 0,
638
4
                     "When sps_weighted_bipred_flag is equal to 0, the value of pps_weighted_bipred_flag shall be equal to 0." );
639
4
  pcPPS->setWPBiPred( pps_weighted_bipred_flag );
640
641
4
  X_READ_FLAG_CHECK( pps_ref_wraparound_enabled_flag,
642
4
                     ( sps->getUseWrapAround() == 0 || CtbSizeY / MinCbSizeY + 1 > pps_pic_width_in_luma_samples / MinCbSizeY - 1 )
643
4
                       && pps_ref_wraparound_enabled_flag != 0,
644
4
                     "When sps_ref_wraparound_enabled_flag is equal to 0 or the value of CtbSizeY / MinCbSizeY + 1 is greater than"
645
4
                     " pps_pic_width_in_luma_samples / MinCbSizeY − 1, the value of pps_ref_wraparound_enabled_flag shall be equal to 0." );
646
4
  pcPPS->setUseWrapAround( pps_ref_wraparound_enabled_flag );
647
648
4
  if( pps_ref_wraparound_enabled_flag )
649
0
  {
650
0
    X_READ_UVLC( pps_pic_width_minus_wraparound_offset, 0, ( pps_pic_width_in_luma_samples / MinCbSizeY ) - ( CtbSizeY / MinCbSizeY ) - 2 );
651
0
    pcPPS->setPicWidthMinusWrapAroundOffset( pps_pic_width_minus_wraparound_offset );
652
0
  }
653
654
4
  X_READ_SVLC( pps_init_qp_minus26, -( 26 + sps->getQpBDOffset() ), 37 );
655
4
  pcPPS->setPicInitQPMinus26( pps_init_qp_minus26 );
656
657
4
  X_READ_FLAG( pps_cu_qp_delta_enabled_flag );
658
4
  pcPPS->setUseDQP( pps_cu_qp_delta_enabled_flag );
659
660
4
  X_READ_FLAG_CHECK( pps_chroma_tool_offsets_present_flag,
661
4
                     sps->getChromaFormatIdc() == 0 && pps_chroma_tool_offsets_present_flag != 0,
662
4
                     "When sps_chroma_format_idc is equal to 0, the value of pps_chroma_tool_offsets_present_flag shall be equal to 0." );
663
4
  pcPPS->setPPSChromaToolFlag( pps_chroma_tool_offsets_present_flag );
664
665
4
  if( pps_chroma_tool_offsets_present_flag )
666
0
  {
667
0
    X_READ_SVLC( pps_cb_qp_offset, -12, 12 );
668
0
    pcPPS->setQpOffset( COMPONENT_Cb, pps_cb_qp_offset );
669
670
0
    X_READ_SVLC( pps_cr_qp_offset, -12, 12 );
671
0
    pcPPS->setQpOffset( COMPONENT_Cr, pps_cr_qp_offset );
672
673
0
    X_READ_FLAG_CHECK( pps_joint_cbcr_qp_offset_present_flag,
674
0
                       ( sps->getChromaFormatIdc() == 0 || sps->getJointCbCrEnabledFlag() == 0 ) && pps_joint_cbcr_qp_offset_present_flag != 0,
675
0
                       "When sps_chroma_format_idc is equal to 0 or sps_joint_cbcr_enabled_flag is equal to 0, the value of"
676
0
                       " pps_joint_cbcr_qp_offset_present_flag shall be equal to 0." );
677
0
    pcPPS->setJointCbCrQpOffsetPresentFlag( pps_joint_cbcr_qp_offset_present_flag );
678
679
0
    if( pps_joint_cbcr_qp_offset_present_flag )
680
0
    {
681
0
      X_READ_SVLC( pps_joint_cbcr_qp_offset_value, -12, 12 );
682
0
      pcPPS->setQpOffset( JOINT_CbCr, pps_joint_cbcr_qp_offset_value );
683
0
    }
684
0
    else
685
0
    {
686
0
      pcPPS->setQpOffset( JOINT_CbCr, 0 );
687
0
    }
688
689
0
    X_READ_FLAG( pps_slice_chroma_qp_offsets_present_flag );
690
0
    pcPPS->setSliceChromaQpFlag( pps_slice_chroma_qp_offsets_present_flag );
691
692
0
    X_READ_FLAG( pps_cu_chroma_qp_offset_list_enabled_flag );
693
0
    if( !pps_cu_chroma_qp_offset_list_enabled_flag )
694
0
    {
695
0
      pcPPS->clearChromaQpOffsetList();
696
0
    }
697
0
    else
698
0
    {
699
0
      X_READ_UVLC( pps_chroma_qp_offset_list_len_minus1, 0, MAX_QP_OFFSET_LIST_SIZE - 1 );
700
701
0
      for( int cuChromaQpOffsetIdx = 0; cuChromaQpOffsetIdx <= pps_chroma_qp_offset_list_len_minus1; cuChromaQpOffsetIdx++ )
702
0
      {
703
0
        X_READ_SVLC_idx( pps_cb_qp_offset_list, "[i]", -12, 12 );
704
0
        X_READ_SVLC_idx( pps_cr_qp_offset_list, "[i]", -12, 12 );
705
0
        int jointCbCrOffset = 0;
706
0
        if( pps_joint_cbcr_qp_offset_present_flag )
707
0
        {
708
0
          X_READ_SVLC_idx( pps_joint_cbcr_qp_offset_list, "[i]", -12, 12 );
709
0
          jointCbCrOffset = pps_joint_cbcr_qp_offset_list;
710
0
        }
711
        // table uses +1 for index (see comment inside the function)
712
0
        pcPPS->setChromaQpOffsetListEntry( cuChromaQpOffsetIdx + 1, pps_cb_qp_offset_list, pps_cr_qp_offset_list, jointCbCrOffset );
713
0
      }
714
0
      CHECK( pcPPS->getChromaQpOffsetListLen() != pps_chroma_qp_offset_list_len_minus1 + 1, "Invalid chroma QP offset list length" );
715
0
    }
716
0
  }
717
4
  else
718
4
  {
719
4
    pcPPS->setQpOffset( COMPONENT_Cb, 0 );
720
4
    pcPPS->setQpOffset( COMPONENT_Cr, 0 );
721
4
    pcPPS->setJointCbCrQpOffsetPresentFlag( 0 );
722
4
    pcPPS->setSliceChromaQpFlag( 0 );
723
4
    pcPPS->clearChromaQpOffsetList();
724
4
  }
725
726
4
  X_READ_FLAG( pps_deblocking_filter_control_present_flag );
727
4
  pcPPS->setDeblockingFilterControlPresentFlag( pps_deblocking_filter_control_present_flag );
728
729
4
  if( pps_deblocking_filter_control_present_flag )
730
0
  {
731
0
    X_READ_FLAG( pps_deblocking_filter_override_enabled_flag );
732
0
    pcPPS->setDeblockingFilterOverrideEnabledFlag( pps_deblocking_filter_override_enabled_flag );
733
734
0
    X_READ_FLAG( pps_deblocking_filter_disabled_flag );
735
0
    pcPPS->setPPSDeblockingFilterDisabledFlag( pps_deblocking_filter_disabled_flag );
736
737
0
    if( !pps_no_pic_partition_flag && pps_deblocking_filter_override_enabled_flag )
738
0
    {
739
0
      X_READ_FLAG( pps_dbf_info_in_ph_flag );
740
0
      pcPPS->setDbfInfoInPhFlag( pps_dbf_info_in_ph_flag );
741
0
    }
742
743
0
    if( !pps_deblocking_filter_disabled_flag )
744
0
    {
745
0
      X_READ_SVLC( pps_luma_beta_offset_div2, -12, 12 );
746
0
      pcPPS->setDeblockingFilterBetaOffsetDiv2( pps_luma_beta_offset_div2 );
747
748
0
      X_READ_SVLC( pps_luma_tc_offset_div2, -12, 12 );
749
0
      pcPPS->setDeblockingFilterTcOffsetDiv2( pps_luma_tc_offset_div2 );
750
751
0
      if( pps_chroma_tool_offsets_present_flag )
752
0
      {
753
0
        X_READ_SVLC( pps_cb_beta_offset_div2, -12, 12 );
754
0
        pcPPS->setDeblockingFilterCbBetaOffsetDiv2( pps_cb_beta_offset_div2 );
755
756
0
        X_READ_SVLC( pps_cb_tc_offset_div2, -12, 12 );
757
0
        pcPPS->setDeblockingFilterCbTcOffsetDiv2( pps_cb_tc_offset_div2 );
758
759
0
        X_READ_SVLC( pps_cr_beta_offset_div2, -12, 12 );
760
0
        pcPPS->setDeblockingFilterCrBetaOffsetDiv2( pps_cr_beta_offset_div2 );
761
762
0
        X_READ_SVLC( pps_cr_tc_offset_div2, -12, 12 );
763
0
        pcPPS->setDeblockingFilterCrTcOffsetDiv2( pps_cr_tc_offset_div2 );
764
0
      }
765
0
      else
766
0
      {
767
0
        pcPPS->setDeblockingFilterCbBetaOffsetDiv2( pps_luma_beta_offset_div2 );
768
0
        pcPPS->setDeblockingFilterCbTcOffsetDiv2( pps_luma_tc_offset_div2 );
769
0
        pcPPS->setDeblockingFilterCrBetaOffsetDiv2( pps_luma_beta_offset_div2 );
770
0
        pcPPS->setDeblockingFilterCrTcOffsetDiv2( pps_luma_tc_offset_div2 );
771
0
      }
772
0
    }
773
0
  }
774
775
4
  if( !pps_no_pic_partition_flag )
776
0
  {
777
0
    X_READ_FLAG( pps_rpl_info_in_ph_flag );
778
0
    pcPPS->setRplInfoInPhFlag( pps_rpl_info_in_ph_flag );
779
780
0
    X_READ_FLAG( pps_sao_info_in_ph_flag );
781
0
    pcPPS->setSaoInfoInPhFlag( pps_sao_info_in_ph_flag );
782
783
0
    X_READ_FLAG( pps_alf_info_in_ph_flag );
784
0
    pcPPS->setAlfInfoInPhFlag( pps_alf_info_in_ph_flag );
785
786
0
    if( ( pps_weighted_pred_flag || pps_weighted_bipred_flag ) && pps_rpl_info_in_ph_flag )
787
0
    {
788
0
      X_READ_FLAG( pps_wp_info_in_ph_flag );
789
0
      pcPPS->setWpInfoInPhFlag( pps_wp_info_in_ph_flag );
790
0
    }
791
792
0
    X_READ_FLAG( pps_qp_delta_info_in_ph_flag );
793
0
    pcPPS->setQpDeltaInfoInPhFlag( pps_qp_delta_info_in_ph_flag );
794
0
  }
795
796
4
  X_READ_FLAG( pps_picture_header_extension_present_flag );
797
4
  pcPPS->setPictureHeaderExtensionPresentFlag( pps_picture_header_extension_present_flag );
798
799
4
  X_READ_FLAG( pps_slice_header_extension_present_flag );
800
4
  pcPPS->setSliceHeaderExtensionPresentFlag( pps_slice_header_extension_present_flag );
801
802
4
  X_READ_FLAG( pps_extension_flag );
803
4
  if( pps_extension_flag )
804
0
  {
805
0
    while( xMoreRbspData() )
806
0
    {
807
0
      X_READ_FLAG( pps_extension_data_flag );
808
0
      (void) pps_extension_data_flag;
809
0
    }
810
0
  }
811
812
4
  xReadRbspTrailingBits();
813
814
  // ================================
815
  //  PPS READING DONE
816
  // ================================
817
818
4
  if( pcPPS->getPicWidthInLumaSamples() == sps->getMaxPicWidthInLumaSamples() && pcPPS->getPicHeightInLumaSamples() == sps->getMaxPicHeightInLumaSamples() )
819
0
  {
820
0
    CHECK( pcPPS->getConformanceWindowPresentFlag(),
821
0
                       "When pps_pic_width_in_luma_samples is equal to sps_pic_width_max_in_luma_samples and "
822
0
                       "pps_pic_height_in_luma_samples is equal to sps_pic_height_max_in_luma_samples, the value of "
823
0
                       "pps_conformance_window_flag shall be equal to 0" );
824
825
0
    pcPPS->setConformanceWindow( sps->getConformanceWindow() );
826
827
0
    if( !pcPPS->getScalingWindow().getWindowEnabledFlag() )
828
0
    {
829
0
      pcPPS->setScalingWindow( pcPPS->getConformanceWindow() );
830
0
    }
831
0
  }
832
833
4
  pcPPS->finalizePPSPartitioning( sps );
834
835
  // set wraparound offset from PPS and SPS info
836
4
  int minCbSizeY = ( 1 << sps->getLog2MinCodingBlockSize() );
837
4
  CHECK( !sps->getUseWrapAround() && pcPPS->getUseWrapAround(),
838
4
         "When sps_ref_wraparound_enabled_flag is equal to 0, the value of pps_ref_wraparound_enabled_flag shall be equal to 0." );
839
4
  CHECK( sps->getCTUSize() / minCbSizeY + 1 > pcPPS->getPicWidthInLumaSamples() / minCbSizeY - 1 && pcPPS->getUseWrapAround(),
840
4
         "When the value of CtbSizeY / MinCbSizeY + 1 is greater than pic_width_in_luma_samples / MinCbSizeY - 1, the value of "
841
4
         "pps_ref_wraparound_enabled_flag shall be equal to 0." );
842
4
  if( pcPPS->getUseWrapAround() )
843
0
  {
844
0
    CHECK( pcPPS->getPicWidthMinusWrapAroundOffset() > pcPPS->getPicWidthInLumaSamples() / minCbSizeY - sps->getCTUSize() / minCbSizeY - 2,
845
0
           "pps_pic_width_minus_wraparound_ofsfet shall be less than or equal to pps_pic_width_in_luma_samples/MinCbSizeY - CtbSizeY/MinCbSizeY-2" );
846
0
    pcPPS->setWrapAroundOffset( minCbSizeY * ( pcPPS->getPicWidthInLumaSamples() / minCbSizeY - pcPPS->getPicWidthMinusWrapAroundOffset() ) );
847
0
  }
848
4
  else
849
4
  {
850
4
    pcPPS->setWrapAroundOffset( 0 );
851
4
  }
852
853
4
  pcPPS->pcv = std::make_unique<PreCalcValues>( *sps, *pcPPS );
854
4
}
855
856
bool HLSyntaxReader::parseAPS( APS* aps )
857
126
{
858
#if ENABLE_TRACING
859
  xTraceAPSHeader();
860
#endif
861
862
126
  X_READ_CODE_NO_RANGE( aps_params_type, 3 );
863
  // if not in supported range, this APS is ignored `switch() -> default`
864
126
  aps->setAPSType( aps_params_type );
865
866
126
  X_READ_CODE_NO_RANGE( adaptation_parameter_set_id, 5 );
867
  // range check happens later in the `switch( aps_params_type )`
868
126
  aps->setAPSId( adaptation_parameter_set_id );
869
870
126
  X_READ_FLAG( aps_chroma_present_flag );
871
126
  aps->chromaPresentFlag = aps_chroma_present_flag;
872
873
126
  switch( aps_params_type )
874
126
  {
875
45
  case ALF_APS:
876
45
    CHECK_READ_RANGE( adaptation_parameter_set_id, 0, 7, "adaptation_parameter_set_id for ALF_APS" );
877
44
    parseAlfAps( aps );
878
44
    break;
879
24
  case LMCS_APS:
880
24
    CHECK_READ_RANGE( adaptation_parameter_set_id, 0, 3, "adaptation_parameter_set_id for LMCS_APS," );
881
23
    parseLmcsAps( aps );
882
23
    break;
883
51
  case SCALING_LIST_APS:
884
51
    CHECK_READ_RANGE( adaptation_parameter_set_id, 0, 7, "adaptation_parameter_set_id for SCALING_APS" );
885
50
    parseScalingListAps( aps );
886
50
    break;
887
4
  default:
888
4
    WARN( "unknown APS type (" << aps_params_type << ")" );
889
4
    return false;
890
126
  }
891
892
27
  X_READ_FLAG( aps_extension_flag );
893
27
  if( aps_extension_flag )
894
18
  {
895
497
    while( xMoreRbspData() )
896
479
    {
897
479
      X_READ_FLAG( aps_extension_data_flag );
898
479
      (void) aps_extension_data_flag;
899
479
    }
900
18
  }
901
27
  xReadRbspTrailingBits();
902
903
27
  return true;
904
126
}
905
906
void HLSyntaxReader::parseAlfAps( APS* aps )
907
44
{
908
44
  AlfSliceParam& param = aps->getAlfAPSParam();
909
44
  param.reset();
910
911
44
  X_READ_FLAG( alf_luma_new_filter );   //  standard: alf_luma_filter_signal_flag
912
44
  param.newFilterFlag[CHANNEL_TYPE_LUMA] = alf_luma_new_filter;
913
914
44
  CcAlfFilterParam& ccAlfParam = aps->getCcAlfAPSParam();
915
44
  ccAlfParam.reset();
916
44
  if( aps->chromaPresentFlag )
917
27
  {
918
27
    X_READ_FLAG( alf_chroma_new_filter );   // standard: alf_chroma_filter_signal_flag
919
27
    param.newFilterFlag[CHANNEL_TYPE_CHROMA] = alf_chroma_new_filter;
920
921
27
    X_READ_FLAG( alf_cc_cb_filter_signal_flag );
922
27
    ccAlfParam.newCcAlfFilter[COMPONENT_Cb - 1] = alf_cc_cb_filter_signal_flag;
923
924
27
    X_READ_FLAG( alf_cc_cr_filter_signal_flag );
925
27
    ccAlfParam.newCcAlfFilter[COMPONENT_Cr - 1] = alf_cc_cr_filter_signal_flag;
926
27
  }
927
44
  CHECK( param.newFilterFlag[CHANNEL_TYPE_LUMA] == 0 && param.newFilterFlag[CHANNEL_TYPE_CHROMA] == 0
928
44
         && ccAlfParam.newCcAlfFilter[COMPONENT_Cb - 1] == 0 && ccAlfParam.newCcAlfFilter[COMPONENT_Cr - 1] == 0,
929
44
         "bitstream conformance error: one of alf_luma_filter_signal_flag, alf_chroma_filter_signal_flag, "
930
44
         "alf_cross_component_cb_filter_signal_flag, and alf_cross_component_cr_filter_signal_flag shall be nonzero" );
931
932
  // The variable NumAlfFilters specifying the number of different adaptive loop filters is set equal to 25.
933
43
  static constexpr int NumAlfFilters = MAX_NUM_ALF_CLASSES;
934
935
43
  if( alf_luma_new_filter )
936
20
  {
937
20
    X_READ_FLAG( alf_luma_clip );
938
20
    param.nonLinearFlagLuma = alf_luma_clip;
939
940
20
    X_READ_UVLC( alf_luma_num_filters_signalled_minus1, 0, NumAlfFilters - 1 );
941
20
    param.numLumaFilters = alf_luma_num_filters_signalled_minus1 + 1;
942
943
20
    if( alf_luma_num_filters_signalled_minus1 > 0 )
944
12
    {
945
12
      const int length = (int) ceil( log2( alf_luma_num_filters_signalled_minus1 + 1 ) );
946
213
      for( int filtIdx = 0; filtIdx < NumAlfFilters; filtIdx++ )
947
201
      {
948
201
        X_READ_CODE( alf_luma_coeff_delta_idx, length, 0, alf_luma_num_filters_signalled_minus1 );
949
201
        param.filterCoeffDeltaIdx[filtIdx] = alf_luma_coeff_delta_idx;
950
201
      }
951
12
    }
952
953
20
    alfFilterCoeffs( param, false, 0 );
954
20
  }
955
956
43
  if( param.newFilterFlag[CHANNEL_TYPE_CHROMA] )
957
20
  {
958
20
    X_READ_FLAG( alf_nonlinear_enable_flag_chroma );
959
20
    param.nonLinearFlagChroma = alf_nonlinear_enable_flag_chroma;
960
961
20
    X_READ_UVLC( alf_chroma_num_alts_minus1, 0, MAX_NUM_ALF_ALTERNATIVES_CHROMA - 1 );
962
20
    param.numAlternativesChroma = alf_chroma_num_alts_minus1 + 1;
963
964
87
    for( int altIdx = 0; altIdx <= alf_chroma_num_alts_minus1; ++altIdx )
965
67
    {
966
67
      alfFilterCoeffs( param, true, altIdx );
967
67
    }
968
20
  }
969
970
80
  for( int ccIdx = 0; ccIdx < 2; ccIdx++ )
971
41
  {
972
41
    if( ccAlfParam.newCcAlfFilter[ccIdx] )
973
26
    {
974
26
      uint32_t code;
975
26
      READ_UVLC( code, ccIdx == 0 ? "alf_cc_cb_filters_signalled_minus1" : "alf_cc_cr_filters_signalled_minus1" );
976
26
      CHECK_READ_RANGE( code, 0, 3, ( ccIdx == 0 ? "alf_cc_cb_filters_signalled_minus1" : "alf_cc_cr_filters_signalled_minus1" ) )
977
978
22
      ccAlfParam.ccAlfFilterCount[ccIdx] = code + 1;
979
980
62
      for( int filterIdx = 0; filterIdx < ccAlfParam.ccAlfFilterCount[ccIdx]; filterIdx++ )
981
40
      {
982
40
        ccAlfParam.ccAlfFilterIdxEnabled[ccIdx][filterIdx] = true;
983
984
40
        const int numCoeff = g_alfNumCoeff[CC_ALF];
985
986
40
        short* coeff = ccAlfParam.ccAlfCoeff[ccIdx][filterIdx];
987
        // Filter coefficients
988
303
        for( int i = 0; i < numCoeff - 1; i++ )
989
263
        {
990
263
          READ_CODE( 3, code, ccIdx == 0 ? "alf_cc_cb_mapped_coeff_abs" : "alf_cc_cr_mapped_coeff_abs" );
991
263
          if( code )
992
184
          {
993
184
            coeff[i] = 1 << ( code - 1 );
994
995
184
            READ_FLAG( code, ccIdx == 0 ? "alf_cc_cb_coeff_sign" : "alf_cc_cr_coeff_sign" );
996
184
            coeff[i] *= 1 - 2 * code;
997
184
          }
998
79
          else
999
79
          {
1000
79
            coeff[i] = 0;
1001
79
          }
1002
263
        }
1003
1004
40
        DTRACE( g_trace_ctx, D_SYNTAX, "%s coeff filterIdx %d: ", ccIdx == 0 ? "Cb" : "Cr", filterIdx );
1005
320
        for( int i = 0; i < numCoeff; i++ )
1006
280
        {
1007
280
          DTRACE( g_trace_ctx, D_SYNTAX, "%d ", coeff[i] );
1008
280
        }
1009
40
        DTRACE( g_trace_ctx, D_SYNTAX, "\n" );
1010
40
      }
1011
22
    }
1012
41
  }
1013
43
}
1014
1015
void HLSyntaxReader::parseLmcsAps( APS* aps )
1016
23
{
1017
23
  SliceReshapeInfo& info = aps->getReshaperAPSInfo();
1018
23
  info.reset();
1019
1020
23
  X_READ_UVLC( lmcs_min_bin_idx, 0, 15 );
1021
23
  info.reshaperModelMinBinIdx = lmcs_min_bin_idx;
1022
1023
23
  X_READ_UVLC( lmcs_delta_max_bin_idx, 0, 15 );
1024
23
  info.reshaperModelMaxBinIdx = PIC_CODE_CW_BINS - 1 - lmcs_delta_max_bin_idx;
1025
23
  CHECK( info.reshaperModelMaxBinIdx < lmcs_min_bin_idx, "The value of LmcsMaxBinIdx shall be greater than or equal to lmcs_min_bin_idx." );
1026
1027
22
  X_READ_UVLC( lmcs_delta_cw_prec_minus1, 0, 14 );
1028
22
  info.maxNbitsNeededDeltaCW = lmcs_delta_cw_prec_minus1 + 1;
1029
1030
22
  CHECK( info.maxNbitsNeededDeltaCW == 0, "wrong" );
1031
1032
98
  for( uint32_t i = info.reshaperModelMinBinIdx; i <= info.reshaperModelMaxBinIdx; i++ )
1033
76
  {
1034
76
    X_READ_CODE_NO_RANGE_idx( lmcs_delta_abs_cw, "[ i ]", info.maxNbitsNeededDeltaCW );
1035
76
    info.reshaperModelBinCWDelta[i] = lmcs_delta_abs_cw;
1036
76
    if( lmcs_delta_abs_cw )
1037
33
    {
1038
33
      X_READ_FLAG_idx( lmcs_delta_sign_cw_flag, "[ i ]" );
1039
33
      info.reshaperModelBinCWDelta[i] *= 1 - 2 * lmcs_delta_sign_cw_flag;
1040
33
    }
1041
    // lmcsCW[i] range is checked in Reshape::constructReshaper()
1042
76
  }
1043
1044
22
  if( aps->chromaPresentFlag )
1045
4
  {
1046
4
    X_READ_CODE_NO_RANGE( lmcs_delta_abs_crs, 3 );
1047
4
    info.chrResScalingOffset = lmcs_delta_abs_crs;
1048
4
    if( lmcs_delta_abs_crs > 0 )
1049
3
    {
1050
3
      X_READ_FLAG( lmcs_delta_sign_crs_flag );
1051
3
      info.chrResScalingOffset *= ( 1 - 2 * lmcs_delta_sign_crs_flag );
1052
3
    }
1053
    // lmcsDeltaCrs range is checked in Reshape::constructReshaper()
1054
4
  }
1055
22
}
1056
1057
void HLSyntaxReader::parseScalingListAps( APS* aps )
1058
50
{
1059
50
  ScalingList& info = aps->getScalingList();
1060
50
  parseScalingList( &info, aps->chromaPresentFlag );
1061
50
}
1062
1063
static const int SARFixedRatios[][2] =
1064
{
1065
    { 1,  1 },
1066
    { 12, 11 },
1067
    { 10, 11 },
1068
    { 16, 11 },
1069
    { 40, 33 },
1070
    { 24, 11 },
1071
    { 20, 11 },
1072
    { 32, 11 },
1073
    { 80, 33 },
1074
    { 18, 11 },
1075
    { 15, 11 },
1076
    { 64, 33 },
1077
    { 160, 99 },
1078
    { 4, 3 },
1079
    { 3, 2 },
1080
    { 2, 1 },
1081
};
1082
1083
void HLSyntaxReader::parseVUI( VUI* pcVUI, unsigned vuiPayloadSize )
1084
38
{
1085
#if ENABLE_TRACING
1086
  DTRACE( g_trace_ctx, D_HEADER, "----------- vui_parameters -----------\n");
1087
#endif
1088
38
  InputBitstream *bs = getBitstream();
1089
38
  auto substream = bs->extractSubstream( vuiPayloadSize * 8 );
1090
38
  setBitstream( substream.get() );
1091
1092
38
  X_READ_FLAG( vui_general_progressive_source_flag );
1093
38
  pcVUI->setProgressiveSourceFlag( vui_general_progressive_source_flag );
1094
1095
38
  X_READ_FLAG( vui_general_interlaced_source_flag );
1096
38
  pcVUI->setInterlacedSourceFlag( vui_general_interlaced_source_flag );
1097
1098
38
  X_READ_FLAG( vui_non_packed_constraint_flag );
1099
38
  pcVUI->setNonPackedFlag( vui_non_packed_constraint_flag );
1100
1101
38
  X_READ_FLAG( vui_non_projected_constraint_flag );
1102
38
  pcVUI->setNonProjectedFlag( vui_non_projected_constraint_flag );
1103
1104
38
  X_READ_FLAG( vui_aspect_ratio_info_present_flag );
1105
38
  pcVUI->setAspectRatioInfoPresentFlag( vui_aspect_ratio_info_present_flag );
1106
1107
38
  if( vui_aspect_ratio_info_present_flag )
1108
14
  {
1109
14
    X_READ_FLAG( vui_aspect_ratio_constant_flag );
1110
14
    pcVUI->setAspectRatioConstantFlag( vui_aspect_ratio_constant_flag );
1111
1112
14
    X_READ_CODE_NO_RANGE( vui_aspect_ratio_idc, 8 );
1113
14
    pcVUI->setAspectRatioIdc( vui_aspect_ratio_idc );
1114
1115
14
    if( pcVUI->getAspectRatioIdc() == 255 )
1116
3
    {
1117
3
      X_READ_CODE_NO_RANGE( vui_sar_width, 16 );
1118
3
      pcVUI->setSarWidth( vui_sar_width );
1119
1120
3
      X_READ_CODE_NO_RANGE( vui_sar_height, 16 );
1121
3
      pcVUI->setSarHeight( vui_sar_height );
1122
3
    }
1123
11
    else if (pcVUI->getAspectRatioIdc() > 0 && (size_t)pcVUI->getAspectRatioIdc() <= sizeof(SARFixedRatios) / sizeof(SARFixedRatios[0]))
1124
1
    {
1125
1
      pcVUI->setSarWidth( SARFixedRatios[pcVUI->getAspectRatioIdc() - 1][0] );
1126
1
      pcVUI->setSarHeight( SARFixedRatios[pcVUI->getAspectRatioIdc() - 1][1] );
1127
1
    }
1128
14
  }
1129
1130
38
  X_READ_FLAG( vui_overscan_info_present_flag );
1131
38
  pcVUI->setOverscanInfoPresentFlag( vui_overscan_info_present_flag );
1132
1133
38
  if( vui_overscan_info_present_flag )
1134
6
  {
1135
6
    X_READ_FLAG( vui_overscan_appropriate_flag );
1136
6
    pcVUI->setOverscanAppropriateFlag( vui_overscan_appropriate_flag );
1137
6
  }
1138
1139
38
  X_READ_FLAG( vui_colour_description_present_flag );
1140
38
  pcVUI->setColourDescriptionPresentFlag( vui_colour_description_present_flag );
1141
1142
38
  if( vui_colour_description_present_flag )
1143
13
  {
1144
13
    X_READ_CODE_NO_RANGE( vui_colour_primaries, 8 );
1145
13
    pcVUI->setColourPrimaries( vui_colour_primaries );
1146
1147
13
    X_READ_CODE_NO_RANGE( vui_transfer_characteristics, 8 );
1148
13
    pcVUI->setTransferCharacteristics( vui_transfer_characteristics );
1149
1150
13
    X_READ_CODE_NO_RANGE( vui_matrix_coeffs, 8 );
1151
13
    pcVUI->setMatrixCoefficients( vui_matrix_coeffs );
1152
1153
13
    X_READ_FLAG( vui_video_full_range_flag );
1154
13
    pcVUI->setVideoFullRangeFlag( vui_video_full_range_flag );
1155
13
  }
1156
1157
38
  X_READ_FLAG( vui_chroma_loc_info_present_flag );
1158
38
  pcVUI->setChromaLocInfoPresentFlag( vui_chroma_loc_info_present_flag );
1159
1160
38
  if( vui_chroma_loc_info_present_flag )
1161
16
  {
1162
16
    if( vui_general_progressive_source_flag && !vui_general_interlaced_source_flag )
1163
3
    {
1164
3
      X_READ_UVLC( vui_chroma_sample_loc_type_frame, 0, 6 );
1165
3
      pcVUI->setChromaSampleLocType( vui_chroma_sample_loc_type_frame );
1166
3
    }
1167
13
    else
1168
13
    {
1169
13
      X_READ_UVLC( vui_chroma_sample_loc_type_top_field, 0, 6 );
1170
13
      pcVUI->setChromaSampleLocTypeTopField( vui_chroma_sample_loc_type_top_field );
1171
1172
13
      X_READ_UVLC( vui_chroma_sample_loc_type_bottom_field, 0, 6 );
1173
13
      pcVUI->setChromaSampleLocTypeBottomField( vui_chroma_sample_loc_type_bottom_field );
1174
13
    }
1175
16
  }
1176
1177
38
  int payloadBitsRem = getBitstream()->getNumBitsLeft();
1178
38
  if( payloadBitsRem )      //Corresponds to more_data_in_payload()
1179
14
  {
1180
145
    while( payloadBitsRem > 9 )    //payload_extension_present()
1181
131
    {
1182
131
      X_READ_FLAG( vui_reserved_payload_extension_data );
1183
131
      (void) vui_reserved_payload_extension_data;
1184
131
      payloadBitsRem--;
1185
131
    }
1186
14
    int finalBits = getBitstream()->peekBits( payloadBitsRem );
1187
14
    int numFinalZeroBits = 0;
1188
14
    int mask = 0xff;
1189
75
    while( finalBits & (mask >> numFinalZeroBits) )
1190
61
    {
1191
61
      numFinalZeroBits++;
1192
61
    }
1193
62
    while( payloadBitsRem > 9-numFinalZeroBits )     //payload_extension_present()
1194
48
    {
1195
48
      X_READ_FLAG( vui_reserved_payload_extension_data );
1196
48
      (void) vui_reserved_payload_extension_data;
1197
48
      payloadBitsRem--;
1198
48
    }
1199
14
    X_READ_FLAG_CHECK( vui_payload_bit_equal_to_one, vui_payload_bit_equal_to_one != 1, "vui_payload_bit_equal_to_one not equal to 1" );
1200
14
    (void)vui_payload_bit_equal_to_one;
1201
14
    payloadBitsRem--;
1202
57
    while( payloadBitsRem )
1203
43
    {
1204
43
      X_READ_FLAG_CHECK( vui_payload_bit_equal_to_zero, vui_payload_bit_equal_to_zero != 0, "vui_payload_bit_equal_to_zero not equal to 0" );
1205
43
      (void)vui_payload_bit_equal_to_zero;
1206
43
      payloadBitsRem--;
1207
43
    }
1208
14
  }
1209
38
  setBitstream( bs );
1210
38
}
1211
1212
void HLSyntaxReader::parseGeneralHrdParameters( GeneralHrdParams *hrd )
1213
80
{
1214
80
  X_READ_CODE_NO_RANGE( num_units_in_tick, 32 );
1215
80
  CHECK( num_units_in_tick <= 0, "num_units_in_tick shall be greater than 0" );
1216
79
  hrd->setNumUnitsInTick( num_units_in_tick );
1217
1218
79
  X_READ_CODE_NO_RANGE( time_scale, 32 );
1219
79
  CHECK( time_scale <= 0, "The value of time_scale shall be greater than 0." );
1220
79
  hrd->setTimeScale( time_scale );
1221
1222
79
  X_READ_FLAG( general_nal_hrd_params_present_flag );
1223
79
  hrd->setGeneralNalHrdParamsPresentFlag( general_nal_hrd_params_present_flag );
1224
1225
79
  X_READ_FLAG( general_vcl_hrd_params_present_flag );
1226
79
  hrd->setGeneralVclHrdParamsPresentFlag( general_vcl_hrd_params_present_flag );
1227
1228
79
  if( general_nal_hrd_params_present_flag || general_vcl_hrd_params_present_flag )
1229
61
  {
1230
61
    X_READ_FLAG( general_same_pic_timing_in_all_ols_flag );
1231
61
    hrd->setGeneralSamePicTimingInAllOlsFlag( general_same_pic_timing_in_all_ols_flag );
1232
1233
61
    X_READ_FLAG( general_du_hrd_params_present_flag );
1234
61
    hrd->setGeneralDuHrdParamsPresentFlag( general_du_hrd_params_present_flag );
1235
1236
61
    if( general_du_hrd_params_present_flag )
1237
26
    {
1238
26
      X_READ_CODE_NO_RANGE( tick_divisor_minus2, 8 );
1239
26
      hrd->setTickDivisorMinus2( tick_divisor_minus2 );
1240
26
    }
1241
1242
61
    X_READ_CODE_NO_RANGE( bit_rate_scale, 4 );
1243
61
    hrd->setBitRateScale( bit_rate_scale );
1244
1245
61
    X_READ_CODE_NO_RANGE( cpb_size_scale, 4 );
1246
61
    hrd->setCpbSizeScale( cpb_size_scale );
1247
1248
61
    if( general_du_hrd_params_present_flag )
1249
26
    {
1250
26
      X_READ_CODE_NO_RANGE( cpb_size_du_scale, 4 );
1251
26
      hrd->setCpbSizeDuScale( cpb_size_du_scale );
1252
26
    }
1253
1254
61
    X_READ_UVLC( hrd_cpb_cnt_minus1, 0, MAX_CPB_CNT - 1 );
1255
61
    hrd->setHrdCpbCntMinus1( hrd_cpb_cnt_minus1 );
1256
61
  }
1257
79
}
1258
1259
void HLSyntaxReader::parseOlsHrdParameters( GeneralHrdParams * generalHrd, std::vector<OlsHrdParams>& olsHrd, uint32_t firstSubLayer, uint32_t maxNumSubLayersMinus1 )
1260
76
{
1261
76
  olsHrd.resize( maxNumSubLayersMinus1 + 1 );
1262
1263
203
  for( unsigned i = firstSubLayer; i <= maxNumSubLayersMinus1; i++ )
1264
139
  {
1265
139
    OlsHrdParams& hrd = olsHrd[i];
1266
1267
139
    X_READ_FLAG( fixed_pic_rate_general_flag );
1268
139
    hrd.setFixedPicRateGeneralFlag( fixed_pic_rate_general_flag );
1269
1270
    // When fixed_pic_rate_general_flag[ i ] is equal to 1, the value of fixed_pic_rate_within_cvs_flag[ i ] is inferred to be equal to 1.
1271
139
    hrd.setFixedPicRateWithinCvsFlag( fixed_pic_rate_general_flag );
1272
139
    if( !fixed_pic_rate_general_flag )
1273
97
    {
1274
97
      X_READ_FLAG( fixed_pic_rate_within_cvs_flag );
1275
97
      hrd.setFixedPicRateWithinCvsFlag( fixed_pic_rate_within_cvs_flag );
1276
97
    }
1277
1278
    // TODO: It is a requirement of bitstream conformance that when general_nal_hrd_params_present_flag and
1279
    //       general_vcl_hrd_params_present_flag are both equal to 0, there shall be at least one value of
1280
    //       fixed_pic_rate_within_cvs_flag[ i ] equal to 1 for i in the range of 0 to MaxSubLayersVal − 1, inclusive.
1281
1282
139
    hrd.setLowDelayHrdFlag( false );   // Inferred to be 0 when not present
1283
1284
139
    if( hrd.getFixedPicRateWithinCvsFlag() )
1285
89
    {
1286
89
      X_READ_UVLC( elemental_duration_in_tc_minus1, 0, 2047 );
1287
89
      hrd.setElementDurationInTcMinus1( elemental_duration_in_tc_minus1 );
1288
89
    }
1289
50
    else if( ( generalHrd->getGeneralNalHrdParamsPresentFlag() || generalHrd->getGeneralVclHrdParamsPresentFlag() )
1290
29
             && generalHrd->getHrdCpbCntMinus1() == 0 )
1291
24
    {
1292
24
      X_READ_FLAG( low_delay_hrd_flag );
1293
24
      hrd.setLowDelayHrdFlag( low_delay_hrd_flag );
1294
24
    }
1295
1296
139
    using NalOrVcl = enum { NAL = 0, VCL = 1 };
1297
139
    for( NalOrVcl nalOrVcl: { NAL, VCL } )
1298
265
    {
1299
265
      if( ( nalOrVcl == NAL && generalHrd->getGeneralNalHrdParamsPresentFlag() ) ||   //
1300
219
          ( nalOrVcl == VCL && generalHrd->getGeneralVclHrdParamsPresentFlag() ) )
1301
118
      {
1302
265
        for( int j = 0; j <= generalHrd->getHrdCpbCntMinus1(); j++ )
1303
159
        {
1304
159
          CHECK( generalHrd->getHrdCpbCntMinus1() >= MAX_CPB_CNT, "hrd_cpb_cnt_minus1 out of bounds" );
1305
1306
159
          X_READ_UVLC_NO_RANGE( bit_rate_value_minus1 );
1307
159
          CHECK( j > 0 && bit_rate_value_minus1 <= hrd.getBitRateValueMinus1( j - 1, nalOrVcl ),
1308
159
                 "For any j greater than 0 and any particular value of i, bit_rate_value_minus1[ i ][ j ]"
1309
159
                 " shall be greater than bit_rate_value_minus1[ i ][ j − 1 ]." );
1310
151
          hrd.setBitRateValueMinus1( j, nalOrVcl, bit_rate_value_minus1 );
1311
1312
151
          X_READ_UVLC( cpb_size_value_minus1, 0, ( 1ull << 32 ) - 2 );
1313
151
          CHECK( j > 0 && cpb_size_value_minus1 > hrd.getCpbSizeValueMinus1( j - 1, nalOrVcl ),
1314
151
                 "For any j greater than 0 and any particular value of i, cpb_size_value_minus1[ i ][ j ]"
1315
151
                 " shall be less than or equal to cpb_size_value_minus1[ i ][ j − 1 ]." );
1316
149
          hrd.setCpbSizeValueMinus1( j, nalOrVcl, cpb_size_value_minus1 );
1317
1318
149
          if( generalHrd->getGeneralDuHrdParamsPresentFlag() )
1319
46
          {
1320
46
            X_READ_UVLC( cpb_size_du_value_minus1, 0, ( 1ull << 32 ) - 2 );
1321
46
            CHECK( j > 0 && cpb_size_du_value_minus1 > hrd.getDuCpbSizeValueMinus1( j - 1, nalOrVcl ),
1322
46
                   "For any j greater than 0 and any particular value of i, cpb_size_du_value_minus1[ i ][ j ]"
1323
46
                   " shall be less than or equal to cpb_size_du_value_minus1[ i ][ j − 1 ]." )
1324
45
            hrd.setDuCpbSizeValueMinus1( j, nalOrVcl, cpb_size_du_value_minus1 );
1325
1326
45
            X_READ_UVLC( bit_rate_du_value_minus1, 0, ( 1ull << 32 ) - 2 );
1327
45
            CHECK( j > 0 && bit_rate_du_value_minus1 <= hrd.getDuBitRateValueMinus1( j - 1, nalOrVcl ),
1328
45
                   "For any j greater than 0 and any particular value of i, bit_rate_du_value_minus1[ i ][ j ]"
1329
45
                   " shall be greater than bit_rate_du_value_minus1[ i ][ j − 1 ]" )
1330
44
            hrd.setDuBitRateValueMinus1( j, nalOrVcl, bit_rate_du_value_minus1 );
1331
44
          }
1332
147
          X_READ_FLAG( cbr_flag );
1333
147
          hrd.setCbrFlag( j, nalOrVcl, cbr_flag );
1334
147
        }
1335
118
      }
1336
265
    }
1337
139
  }
1338
1339
116
  for( int i = 0; i < firstSubLayer; i++ )
1340
52
  {
1341
52
    OlsHrdParams* hrdHighestTLayer = &( olsHrd[maxNumSubLayersMinus1] );
1342
52
    OlsHrdParams* hrdTemp = &( olsHrd[i] );
1343
52
    bool tempFlag = hrdHighestTLayer->getFixedPicRateGeneralFlag();
1344
52
    hrdTemp->setFixedPicRateGeneralFlag( tempFlag );
1345
52
    tempFlag = hrdHighestTLayer->getFixedPicRateWithinCvsFlag();
1346
52
    hrdTemp->setFixedPicRateWithinCvsFlag( tempFlag );
1347
52
    uint32_t tempElementDurationInTcMinus1 = hrdHighestTLayer->getElementDurationInTcMinus1();
1348
52
    hrdTemp->setElementDurationInTcMinus1( tempElementDurationInTcMinus1 );
1349
156
    for( int nalOrVcl = 0; nalOrVcl < 2; nalOrVcl++ )
1350
104
    {
1351
104
      if( ( nalOrVcl == 0 && generalHrd->getGeneralNalHrdParamsPresentFlag() ) || ( nalOrVcl == 1 && generalHrd->getGeneralVclHrdParamsPresentFlag() ) )
1352
48
      {
1353
127
        for( int j = 0; j <= (generalHrd->getHrdCpbCntMinus1()); j++ )
1354
79
        {
1355
79
          uint32_t bitRate = hrdHighestTLayer->getBitRateValueMinus1( j, nalOrVcl );
1356
79
          hrdTemp->setBitRateValueMinus1( j, nalOrVcl, bitRate );
1357
79
          uint32_t cpbSize = hrdHighestTLayer->getCpbSizeValueMinus1( j, nalOrVcl );
1358
79
          hrdTemp->setCpbSizeValueMinus1( j, nalOrVcl, cpbSize );
1359
79
          if( generalHrd->getGeneralDuHrdParamsPresentFlag() )
1360
26
          {
1361
26
            uint32_t bitRateDu = hrdHighestTLayer->getDuBitRateValueMinus1( j, nalOrVcl );
1362
26
            hrdTemp->setDuBitRateValueMinus1(j, nalOrVcl, bitRateDu);
1363
26
            uint32_t cpbSizeDu = hrdHighestTLayer->getDuCpbSizeValueMinus1( j, nalOrVcl );
1364
26
            hrdTemp->setDuCpbSizeValueMinus1( j, nalOrVcl, cpbSizeDu );
1365
26
          }
1366
79
          bool flag = hrdHighestTLayer->getCbrFlag( j, nalOrVcl );
1367
79
          hrdTemp->setCbrFlag( j, nalOrVcl, flag );
1368
79
        }
1369
48
      }
1370
104
    }
1371
52
  }
1372
64
}
1373
1374
void HLSyntaxReader::dpb_parameters( int maxSubLayersMinus1, bool subLayerInfoFlag, SPS *pcSPS )
1375
220
{
1376
220
  CHECK( maxSubLayersMinus1 >= MAX_TLAYER, "maxSubLayersMinus1 out of bounds" );
1377
456
  for( int i = ( subLayerInfoFlag ? 0 : maxSubLayersMinus1 ); i <= maxSubLayersMinus1; i++ )
1378
239
  {
1379
    // The spec bounds this by MaxDpbSize - 1, which is at most 15 (A.4.2) - except at level 15.5, where it is unbounded.
1380
    // We can't handle more than MAX_NUM_REF_PICS reference pictures anyway, so larger values are rejected at any level.
1381
239
    X_READ_UVLC_idx( dpb_max_dec_pic_buffering_minus1, "[i]", 0, MAX_NUM_REF_PICS - 1 );
1382
239
    CHECK( i > 0 && dpb_max_dec_pic_buffering_minus1 < pcSPS->getMaxDecPicBuffering( i - 1 ) - 1,
1383
239
           "When i is greater than 0, dpb_max_dec_pic_buffering_minus1[ i ] shall be greater than or equal to dpb_max_dec_pic_buffering_minus1[ i − 1 ]." );
1384
237
    pcSPS->setMaxDecPicBuffering( dpb_max_dec_pic_buffering_minus1 + 1, i );
1385
1386
237
    X_READ_UVLC_idx( dpb_max_num_reorder_pics, "[i]", 0, dpb_max_dec_pic_buffering_minus1 );
1387
237
    CHECK( i > 0 && dpb_max_num_reorder_pics < pcSPS->getNumReorderPics( i - 1 ),
1388
237
           "When i is greater than 0, dpb_max_num_reorder_pics[ i ] shall be greater than or equal to dpb_max_num_reorder_pics[ i − 1 ]." );
1389
236
    pcSPS->setNumReorderPics( dpb_max_num_reorder_pics, i );
1390
1391
236
    X_READ_UVLC_idx( dpb_max_latency_increase_plus1, "[i]", 0, ( uint64_t( 1 ) << 32 ) - 2 );
1392
236
    pcSPS->setMaxLatencyIncreasePlus1( dpb_max_latency_increase_plus1, i );
1393
236
  }
1394
220
}
1395
1396
void HLSyntaxReader::parseExtraPHBitsStruct( SPS *sps, int numBytes )
1397
223
{
1398
223
  std::vector<bool> presentFlags;
1399
223
  presentFlags.resize ( 8 * numBytes );
1400
1401
2.06k
  for( int i = 0; i < 8 * numBytes; i++ )
1402
1.84k
  {
1403
1.84k
    X_READ_FLAG_idx( sps_extra_ph_bit_present_flag, "[i]" );
1404
1.84k
    presentFlags[i] = sps_extra_ph_bit_present_flag;
1405
1.84k
  }
1406
1407
223
  sps->setExtraPHBitPresentFlags( std::move( presentFlags ) );
1408
223
}
1409
1410
void HLSyntaxReader::parseExtraSHBitsStruct( SPS *sps, int numBytes )
1411
215
{
1412
215
  std::vector<bool> presentFlags;
1413
215
  presentFlags.resize ( 8 * numBytes );
1414
1415
2.02k
  for( int i = 0; i < 8 * numBytes; i++ )
1416
1.80k
  {
1417
1.80k
    X_READ_FLAG_idx( sps_extra_sh_bit_present_flag, "[i]" );
1418
1.80k
    presentFlags[i] = sps_extra_sh_bit_present_flag;
1419
1.80k
  }
1420
1421
215
  sps->setExtraSHBitPresentFlags( std::move( presentFlags ) );
1422
215
}
1423
1424
void HLSyntaxReader::parseSPS( SPS* sps, const ParameterSetManager* parameterSetManager )
1425
311
{
1426
#if ENABLE_TRACING
1427
  xTraceSPSHeader ();
1428
#endif
1429
1430
311
  X_READ_CODE_NO_RANGE( sps_seq_parameter_set_id, 4 );
1431
311
  sps->setSPSId( sps_seq_parameter_set_id );
1432
1433
311
  X_READ_CODE_NO_RANGE( sps_video_parameter_set_id, 4 );
1434
311
  (void) sps_video_parameter_set_id;   // sps->setVPSId( sps_video_parameter_set_id ); // TODO: change to support VPS
1435
311
  const VPS* vps = nullptr;
1436
#if 0
1437
  if( sps_video_parameter_set_id > 0 && parameterSetManager->getVPS( sps_video_parameter_set_id ) )
1438
  {
1439
    vps = parameterSetManager->getVPS( sps_video_parameter_set_id );
1440
  }
1441
#endif
1442
1443
311
  X_READ_CODE( sps_max_sublayers_minus1, 3, 0, 6 );
1444
311
  CHECK( vps && sps_video_parameter_set_id > vps->getMaxSubLayers(),
1445
311
         "If sps_video_parameter_set_id is greater than 0, the value of sps_max_sublayers_minus1 shall be in the range of 0 to vps_max_sublayers_minus1, "
1446
311
         "inclusive." )
1447
311
  sps->setMaxTLayers( sps_max_sublayers_minus1 + 1 );
1448
1449
311
  X_READ_CODE_NO_RANGE( sps_chroma_format_idc, 2 );
1450
  // it is a requirement of bitstream conformance that the value of sps_chroma_format_idc shall
1451
  // be less than or equal to the value of vps_ols_dpb_chroma_format[ i ].
1452
311
  sps->setChromaFormatIdc( ChromaFormat( sps_chroma_format_idc ) );
1453
1454
311
  X_READ_CODE( sps_log2_ctu_size_minus5, 2, 0, 2 );
1455
311
  sps->setCTUSize( 1 << ( sps_log2_ctu_size_minus5 + 5 ) );
1456
1457
311
  const int CtbLog2SizeY = sps_log2_ctu_size_minus5 + 5;
1458
311
  const int CtbSizeY     = 1 << CtbLog2SizeY;
1459
311
  sps->setMaxCUWidth( sps->getCTUSize() );
1460
311
  sps->setMaxCUHeight( sps->getCTUSize() );
1461
1462
311
  X_READ_FLAG( sps_ptl_dpb_hrd_params_present_flag );
1463
311
  CHECK( sps_video_parameter_set_id == 0 && !sps_ptl_dpb_hrd_params_present_flag,
1464
311
                     "When sps_video_parameter_set_id is equal to 0, the value of sps_ptl_dpb_hrd_params_present_flag shall be equal to 1" );
1465
310
  sps->setPtlDpbHrdParamsPresentFlag( sps_ptl_dpb_hrd_params_present_flag );
1466
1467
310
  if( sps_ptl_dpb_hrd_params_present_flag )
1468
289
  {
1469
289
    parseProfileTierLevel( sps->getProfileTierLevel(), true, sps->getMaxTLayers() - 1 );
1470
289
  }
1471
1472
310
  const ProfileTierLevel* ptl = sps->getProfileTierLevel();
1473
310
  const ConstraintInfo*   gci = ptl->getConstraintInfo();
1474
1475
310
  X_READ_FLAG( sps_gdr_enabled_flag );
1476
310
  CHECK_CONSTRAINT( gci->getNoGdrConstraintFlag() && sps_gdr_enabled_flag,
1477
310
                     "When gci_no_gdr_constraint_flag equal to 1 , the value of sps_gdr_enabled_flag shall be equal to 0" );
1478
310
  sps->setGDREnabledFlag( sps_gdr_enabled_flag );
1479
1480
310
  X_READ_FLAG( sps_ref_pic_resampling_enabled_flag );
1481
310
  CHECK_CONSTRAINT( gci->getNoRprConstraintFlag() && sps_ref_pic_resampling_enabled_flag,
1482
310
                    "When gci_no_ref_pic_resampling_constraint_flag is equal to 1, sps_ref_pic_resampling_enabled_flag shall be equal to 0" );
1483
310
  sps->setRprEnabledFlag( sps_ref_pic_resampling_enabled_flag );
1484
1485
310
  if( sps_ref_pic_resampling_enabled_flag )
1486
11
  {
1487
11
    X_READ_FLAG( sps_res_change_in_clvs_allowed_flag );
1488
11
    CHECK_CONSTRAINT( gci->getNoResChangeInClvsConstraintFlag() && sps_res_change_in_clvs_allowed_flag,
1489
11
                      "When no_res_change_in_clvs_constraint_flag is equal to 1, res_change_in_clvs_allowed_flag shall be equal to 0" );
1490
11
    sps->setResChangeInClvsEnabledFlag( sps_res_change_in_clvs_allowed_flag );
1491
11
  }
1492
1493
310
  X_READ_UVLC_NO_RANGE( sps_pic_width_max_in_luma_samples );
1494
310
  sps->setMaxPicWidthInLumaSamples( sps_pic_width_max_in_luma_samples );
1495
1496
310
  X_READ_UVLC_NO_RANGE( sps_pic_height_max_in_luma_samples );
1497
310
  sps->setMaxPicHeightInLumaSamples( sps_pic_height_max_in_luma_samples );
1498
1499
310
  const int SubWidthC  = 1 << getChannelTypeScaleX( CHANNEL_TYPE_CHROMA, sps->getChromaFormatIdc() );
1500
310
  const int SubHeightC = 1 << getChannelTypeScaleY( CHANNEL_TYPE_CHROMA, sps->getChromaFormatIdc() );
1501
1502
310
  X_READ_FLAG( sps_conformance_window_flag );
1503
310
  sps->setConformanceWindowPresentFlag( sps_conformance_window_flag );
1504
1505
310
  if( sps_conformance_window_flag )
1506
34
  {
1507
34
    X_READ_UVLC_NO_RANGE( sps_conf_win_left_offset );
1508
34
    X_READ_UVLC_NO_RANGE( sps_conf_win_right_offset );
1509
34
    X_READ_UVLC_NO_RANGE( sps_conf_win_top_offset );
1510
34
    X_READ_UVLC_NO_RANGE( sps_conf_win_bottom_offset );
1511
1512
34
    CHECK( SubWidthC * ( uint64_t( sps_conf_win_left_offset ) + sps_conf_win_right_offset ) >= sps_pic_width_max_in_luma_samples,
1513
34
           "The value of SubWidthC * ( sps_conf_win_left_offset + sps_conf_win_right_offset ) shall be less than sps_pic_width_max_in_luma_samples." );
1514
29
    CHECK( SubHeightC * ( uint64_t( sps_conf_win_top_offset ) + sps_conf_win_bottom_offset ) >= sps_pic_height_max_in_luma_samples,
1515
29
           "The value of SubHeightC * ( sps_conf_win_top_offset + sps_conf_win_bottom_offset ) shall be less than sps_pic_height_max_in_luma_samples." );
1516
1517
26
    Window& conf = sps->getConformanceWindow();
1518
26
    conf.setWindowLeftOffset( sps_conf_win_left_offset );
1519
26
    conf.setWindowRightOffset( sps_conf_win_right_offset );
1520
26
    conf.setWindowTopOffset( sps_conf_win_top_offset );
1521
26
    conf.setWindowBottomOffset( sps_conf_win_bottom_offset );
1522
26
  }
1523
302
  X_READ_FLAG( sps_subpic_info_present_flag );
1524
302
  CHECK( sps->getResChangeInClvsEnabledFlag() && sps_subpic_info_present_flag,
1525
302
         "When sps_res_change_in_clvs_allowed_flag is equal to 1, the value of sps_subpic_info_present_flag shall be equal to 0." )
1526
301
  CHECK_CONSTRAINT( gci->getNoSubpicInfoConstraintFlag() && sps_subpic_info_present_flag,
1527
301
                    "When gci_no_subpic_info_constraint_flag is equal to 1, the value of subpic_info_present_flag shall be equal to 0" );
1528
301
  sps->setSubPicInfoPresentFlag( sps_subpic_info_present_flag );
1529
1530
1531
301
  if( sps_subpic_info_present_flag )
1532
42
  {
1533
42
    X_READ_UVLC( sps_num_subpics_minus1, 0, MAX_NUM_SUB_PICS - 1 );
1534
42
    CHECK( sps_num_subpics_minus1 + 1 > ( ( sps_pic_width_max_in_luma_samples + CtbSizeY - 1 ) / CtbSizeY )
1535
42
                                      * ( ( sps_pic_height_max_in_luma_samples + CtbSizeY - 1 ) / CtbSizeY ),
1536
42
           "Invalid sps_num_subpics_minus1 value" );
1537
39
    sps->setNumSubPics( sps_num_subpics_minus1 + 1 );
1538
1539
39
    if( sps_num_subpics_minus1 == 0 )
1540
5
    {
1541
5
      sps->setSubPicCtuTopLeftX( 0, 0 );
1542
5
      sps->setSubPicCtuTopLeftY( 0, 0 );
1543
5
      sps->setSubPicWidth( 0, ( sps->getMaxPicWidthInLumaSamples() + sps->getCTUSize() - 1 ) >> getLog2( sps->getCTUSize() ) );
1544
5
      sps->setSubPicHeight( 0, ( sps->getMaxPicHeightInLumaSamples() + sps->getCTUSize() - 1 ) >> getLog2( sps->getCTUSize() ) );
1545
5
      sps->setIndependentSubPicsFlag( 1 );
1546
5
      sps->setSubPicSameSizeFlag( 0 );
1547
5
      sps->setSubPicTreatedAsPicFlag( 0, 1 );
1548
5
      sps->setLoopFilterAcrossSubpicEnabledFlag( 0, 0 );
1549
5
    }
1550
34
    else   // ( sps_num_subpics_minus1 > 0 )
1551
34
    {
1552
34
      X_READ_FLAG( sps_independent_subpics_flag );
1553
34
      sps->setIndependentSubPicsFlag( sps_independent_subpics_flag );
1554
1555
34
      X_READ_FLAG( sps_subpic_same_size_flag );
1556
34
      sps->setSubPicSameSizeFlag( sps_subpic_same_size_flag );
1557
1558
34
      const uint32_t tmpWidthVal = ( sps->getMaxPicWidthInLumaSamples() + sps->getCTUSize() - 1 ) / sps->getCTUSize();
1559
34
      const uint32_t tmpHeightVal = ( sps->getMaxPicHeightInLumaSamples() + sps->getCTUSize() - 1 ) / sps->getCTUSize();
1560
1561
34
      const int ceilLog2tmpWidth  = (int) ceil( log2( tmpWidthVal ) );
1562
34
      const int ceilLog2tmpHeight = (int) ceil( log2( tmpHeightVal ) );
1563
158
      for( unsigned picIdx = 0; picIdx < sps->getNumSubPics(); picIdx++ )
1564
141
      {
1565
141
        if( !sps_subpic_same_size_flag || picIdx == 0 )
1566
129
        {
1567
129
          if( picIdx > 0 && sps_pic_width_max_in_luma_samples > CtbSizeY )
1568
63
          {
1569
63
            X_READ_CODE_NO_RANGE_idx( sps_subpic_ctu_top_left_x, "[ i ]", ceilLog2tmpWidth );
1570
63
            sps->setSubPicCtuTopLeftX( picIdx, sps_subpic_ctu_top_left_x );
1571
63
          }
1572
66
          else
1573
66
          {
1574
66
            sps->setSubPicCtuTopLeftX( picIdx, 0 );
1575
66
          }
1576
1577
129
          if( picIdx > 0 && sps_pic_height_max_in_luma_samples > CtbSizeY )
1578
49
          {
1579
49
            X_READ_CODE_NO_RANGE_idx( sps_subpic_ctu_top_left_y, "[ i ]", ceilLog2tmpHeight );
1580
49
            sps->setSubPicCtuTopLeftY( picIdx, sps_subpic_ctu_top_left_y );
1581
49
          }
1582
80
          else
1583
80
          {
1584
80
            sps->setSubPicCtuTopLeftY( picIdx, 0 );
1585
80
          }
1586
1587
129
          if( picIdx < sps_num_subpics_minus1 && sps_pic_width_max_in_luma_samples > CtbSizeY )
1588
76
          {
1589
76
            X_READ_CODE_NO_RANGE_idx( sps_subpic_width_minus1, "[ i ]", ceilLog2tmpWidth );
1590
76
            sps->setSubPicWidth( picIdx, sps_subpic_width_minus1 + 1 );
1591
76
          }
1592
53
          else
1593
53
          {
1594
            // If sps_subpic_same_size_flag is equal to 0 or i is equal to 0, the value of sps_subpic_width_minus1[ i ] is inferred
1595
            //   to be equal to tmpWidthVal - sps_subpic_ctu_top_left_x[ i ] - 1.
1596
53
            sps->setSubPicWidth( picIdx, tmpWidthVal - sps->getSubPicCtuTopLeftX( picIdx ) );
1597
53
          }
1598
1599
129
          if( picIdx < sps_num_subpics_minus1 && sps_pic_height_max_in_luma_samples > CtbSizeY )
1600
61
          {
1601
61
            X_READ_CODE_NO_RANGE_idx( sps_subpic_height_minus1, "[ i ]", ceilLog2tmpHeight );
1602
61
            sps->setSubPicHeight( picIdx, sps_subpic_height_minus1 + 1 );
1603
61
          }
1604
68
          else
1605
68
          {
1606
            // If sps_subpic_same_size_flag is equal to 0 or i is equal to 0, the value of sps_subpic_height_minus1[ i ] is inferred
1607
            //   to be equal to tmpHeightVal - sps_subpic_ctu_top_left_y[ i ] − 1.
1608
68
            sps->setSubPicHeight( picIdx, tmpHeightVal - sps->getSubPicCtuTopLeftY( picIdx ) );
1609
68
          }
1610
129
        }
1611
12
        else   // ( sps_subpic_same_size_flag && picIdx != 0 )
1612
12
        {
1613
12
          const int numSubpicCols = tmpWidthVal / sps->getSubPicWidth( 0 );
1614
1615
          // const int numSubpicCols = tmpWidthVal / ( sps->getSubPicWidth( 0 ) + 1 );
1616
12
          CHECK( sps_subpic_same_size_flag && numSubpicCols * tmpHeightVal / sps->getSubPicHeight( 0 ) - 1 != sps_num_subpics_minus1,
1617
12
                 "When sps_subpic_same_size_flag is equal to 1, the value of numSubpicCols * tmpHeightVal / ( sps_subpic_height_minus1[ 0 ] + 1 ) − 1"
1618
12
                 " shall be equal to sps_num_subpics_minus1." )
1619
11
          CHECK( sps_subpic_same_size_flag && tmpWidthVal % sps->getSubPicWidth( 0 ) != 0,
1620
11
                 "When sps_subpic_same_size_flag is equal to 1, the value of tmpWidthVal % ( sps_subpic_width_minus1[ 0 ] + 1 ) shall"
1621
11
                 " be equal to 0." );
1622
10
          CHECK( sps_subpic_same_size_flag && tmpHeightVal % sps->getSubPicHeight( 0 ) != 0,
1623
10
                 "When sps_subpic_same_size_flag is equal to 1, the value of tmpHeightVal % ( sps_subpic_height_minus1[ 0 ] + 1 ) shall"
1624
10
                 " be equal to 0." )
1625
1626
          // Otherwise, the value of sps_subpic_ctu_top_left_x[ i ] is inferred to be equal to ( i % numSubpicCols ) * ( sps_subpic_width_minus1[ 0 ] + 1 ).
1627
          // Otherwise, the value of sps_subpic_ctu_top_left_y[ i ] is inferred to be equal to ( i / numSubpicCols ) * ( sps_subpic_height_minus1[ 0 ] + 1 ).
1628
9
          sps->setSubPicCtuTopLeftX( picIdx, ( picIdx % numSubpicCols ) * sps->getSubPicWidth( 0 ) );
1629
9
          sps->setSubPicCtuTopLeftY( picIdx, ( picIdx / numSubpicCols ) * sps->getSubPicHeight( 0 ) );
1630
          // Otherwise, the value of sps_subpic_width_minus1[ i ] is inferred to be equal to sps_subpic_width_minus1[ 0 ].
1631
          // Otherwise, the value of sps_subpic_height_minus1[ i ] is inferred to be equal to sps_subpic_height_minus1[ 0 ].
1632
9
          sps->setSubPicWidth( picIdx, sps->getSubPicWidth( 0 ) );
1633
9
          sps->setSubPicHeight( picIdx, sps->getSubPicHeight( 0 ) );
1634
9
        }
1635
1636
        // 6.3.1: the subpictures partition the picture, so no CTU of a subpicture may lie outside the picture
1637
138
        CHECK( sps->getSubPicCtuTopLeftX( picIdx ) + sps->getSubPicWidth( picIdx ) > tmpWidthVal,
1638
138
               "Subpicture " << picIdx << " extends beyond the right picture boundary" );
1639
133
        CHECK( sps->getSubPicCtuTopLeftY( picIdx ) + sps->getSubPicHeight( picIdx ) > tmpHeightVal,
1640
133
               "Subpicture " << picIdx << " extends beyond the bottom picture boundary" );
1641
1642
        // TODO: It is a requirement of bitstream conformance that the shapes of the subpictures shall be such that each subpicture, when
1643
        //       decoded, shall have its entire left boundary and entire top boundary consisting of picture boundaries or consisting of
1644
        //       boundaries of previously decoded subpictures.
1645
        //       For each subpicture with subpicture index i in the range of 0 to sps_num_subpics_minus1, inclusive, it is a requirement
1646
        //       of bitstream conformance that all of the following conditions are true:
1647
        //       - The value of ( sps_subpic_ctu_top_left_x[ i ] * CtbSizeY ) shall be less than ( sps_pic_width_max_in_luma_samples - sps_conf_win_right_offset * SubWidthC ).
1648
        //       - The value of ( ( sps_subpic_ctu_top_left_x[ i ] + sps_subpic_width_minus1[ i ] + 1 ) * CtbSizeY ) shall be greater than ( sps_conf_win_left_offset * SubWidthC ).
1649
        //       - The value of ( sps_subpic_ctu_top_left_y[ i ] * CtbSizeY ) shall  be less than ( sps_pic_height_max_in_luma_samples - sps_conf_win_bottom_offset * SubHeightC ).
1650
        //       - The value of ( ( sps_subpic_ctu_top_left_y[ i ] + sps_subpic_height_minus1[ i ] + 1 ) * CtbSizeY ) shall be greater than ( sps_conf_win_top_offset * SubHeightC ).
1651
1652
128
        Window& conf = sps->getConformanceWindow();
1653
128
        CHECK( sps->getSubPicCtuTopLeftX( picIdx ) * CtbSizeY >= sps->getMaxPicWidthInLumaSamples() - conf.getWindowRightOffset() * SubWidthC,
1654
128
               "The value of ( sps_subpic_ctu_top_left_x[ i ] * CtbSizeY )"
1655
128
               " shall be less than ( sps_pic_width_max_in_luma_samples - sps_conf_win_right_offset * SubWidthC )." );
1656
127
        CHECK( ( sps->getSubPicCtuTopLeftX( picIdx ) + sps->getSubPicWidth( picIdx ) ) * CtbSizeY <= conf.getWindowLeftOffset() * SubWidthC,
1657
127
               "The value of ( ( sps_subpic_ctu_top_left_x[ i ] + sps_subpic_width_minus1[ i ] + 1 ) * CtbSizeY )"
1658
127
               " shall be greater than ( sps_conf_win_left_offset * SubWidthC )." );
1659
126
        CHECK( sps->getSubPicCtuTopLeftY( picIdx ) * CtbSizeY >= sps->getMaxPicHeightInLumaSamples() - conf.getWindowBottomOffset() * SubHeightC,
1660
126
               "The value of ( sps_subpic_ctu_top_left_y[ i ] * CtbSizeY )"
1661
126
               " shall  be less than ( sps_pic_height_max_in_luma_samples - sps_conf_win_bottom_offset * SubHeightC )." );
1662
125
        CHECK( ( sps->getSubPicCtuTopLeftY( picIdx ) + sps->getSubPicHeight( picIdx ) ) * CtbSizeY <= conf.getWindowTopOffset() * SubHeightC,
1663
125
               "The value of ( ( sps_subpic_ctu_top_left_y[ i ] + sps_subpic_height_minus1[ i ] + 1 ) * CtbSizeY )"
1664
125
               " shall be greater than ( sps_conf_win_top_offset * SubHeightC )." );
1665
1666
124
        if( !sps_independent_subpics_flag )
1667
43
        {
1668
43
          X_READ_FLAG_idx( sps_subpic_treated_as_pic_flag, "[ i ]" );
1669
43
          sps->setSubPicTreatedAsPicFlag( picIdx, sps_subpic_treated_as_pic_flag );
1670
1671
43
          X_READ_FLAG_idx( sps_loop_filter_across_subpic_enabled_flag, "[ i ]" );
1672
43
          sps->setLoopFilterAcrossSubpicEnabledFlag( picIdx, sps_loop_filter_across_subpic_enabled_flag );
1673
43
        }
1674
81
        else
1675
81
        {
1676
          // should be set as default
1677
81
            sps->setSubPicTreatedAsPicFlag( picIdx, 1 );
1678
81
        }
1679
124
      }   //      for( unsigned picIdx = 0; picIdx < sps->getNumSubPics(); picIdx++ )
1680
34
    }
1681
1682
1683
22
    X_READ_UVLC( sps_subpic_id_len_minus1, 0, 15 );
1684
22
    CHECK( 1 << ( sps_subpic_id_len_minus1 + 1 ) < sps_num_subpics_minus1 + 1,
1685
22
           "The value of 1 << ( sps_subpic_id_len_minus1 + 1 ) shall be greater than or equal to sps_num_subpics_minus1 + 1" );
1686
20
    sps->setSubPicIdLen( sps_subpic_id_len_minus1 + 1 );
1687
1688
20
    X_READ_FLAG( sps_subpic_id_mapping_explicitly_signalled_flag );
1689
20
    sps->setSubPicIdMappingExplicitlySignalledFlag( sps_subpic_id_mapping_explicitly_signalled_flag );
1690
1691
20
    if( sps_subpic_id_mapping_explicitly_signalled_flag )
1692
9
    {
1693
9
      X_READ_FLAG( sps_subpic_id_mapping_present_flag );
1694
9
      sps->setSubPicIdMappingPresentFlag( sps_subpic_id_mapping_present_flag );
1695
1696
9
      if( sps_subpic_id_mapping_present_flag )
1697
6
      {
1698
35
        for( int picIdx = 0; picIdx <= sps_num_subpics_minus1; picIdx++ )
1699
29
        {
1700
29
          X_READ_CODE_NO_RANGE_idx( sps_subpic_id, "[ i ]", sps->getSubPicIdLen() );
1701
29
          sps->setSubPicId( picIdx, sps_subpic_id );
1702
29
        }
1703
6
      }
1704
9
    }
1705
20
  }   // sps_subpic_info_present_flag
1706
259
  else  // ( !sps_subpic_info_present_flag )
1707
259
  {
1708
259
    sps->setSubPicIdMappingExplicitlySignalledFlag( 0 );
1709
259
    sps->setNumSubPics( 1 );
1710
259
    sps->setSubPicCtuTopLeftX( 0, 0 );
1711
259
    sps->setSubPicCtuTopLeftY( 0, 0 );
1712
259
    sps->setSubPicWidth( 0, ( sps->getMaxPicWidthInLumaSamples() + sps->getCTUSize() - 1 ) >> getLog2( sps->getCTUSize() ) );
1713
259
    sps->setSubPicHeight( 0, ( sps->getMaxPicHeightInLumaSamples() + sps->getCTUSize() - 1 ) >> getLog2( sps->getCTUSize() ) );
1714
259
    sps->setSubPicTreatedAsPicFlag( 0, true );
1715
259
    sps->setLoopFilterAcrossSubpicEnabledFlag( 0, false );
1716
259
  }
1717
1718
279
  if( !sps->getSubPicIdMappingExplicitlySignalledFlag() || !sps->getSubPicIdMappingPresentFlag() )
1719
246
  {
1720
511
    for( int picIdx = 0; picIdx < sps->getNumSubPics(); picIdx++ )
1721
265
    {
1722
265
      sps->setSubPicId( picIdx, picIdx );
1723
265
    }
1724
246
  }
1725
1726
279
  X_READ_UVLC( sps_bitdepth_minus8, 0, 8 );
1727
279
  CHECK( sps_bitdepth_minus8 > 2, "bit depths above 10 are not supported" );
1728
275
  const Profile::Name profile = sps->getProfileTierLevel()->getProfileIdc();
1729
275
  if( profile != Profile::NONE )
1730
8
  {
1731
8
    CHECK( sps_bitdepth_minus8 + 8 > ProfileFeatures::getProfileFeatures( profile )->maxBitDepth,
1732
8
                       "sps_bitdepth_minus8 exceeds range supported by signalled profile" );
1733
2
  }
1734
269
  sps->setBitDepth( 8 + sps_bitdepth_minus8 );
1735
269
  sps->setQpBDOffset( 6 * sps_bitdepth_minus8 );
1736
269
  const int BitDepth = 8 + sps_bitdepth_minus8;
1737
269
  const int QpBdOffset = 6 * sps_bitdepth_minus8;
1738
1739
269
  X_READ_FLAG( sps_entropy_coding_sync_enabled_flag );
1740
269
  sps->setEntropyCodingSyncEnabledFlag( sps_entropy_coding_sync_enabled_flag );
1741
1742
269
  X_READ_FLAG( sps_entry_point_offsets_present_flag );
1743
269
  sps->setEntryPointsPresentFlag( sps_entry_point_offsets_present_flag );
1744
1745
269
  X_READ_CODE( sps_log2_max_pic_order_cnt_lsb_minus4, 4, 0, 12 );
1746
269
  sps->setBitsForPOC( sps_log2_max_pic_order_cnt_lsb_minus4 + 4 );
1747
1748
269
  X_READ_FLAG( sps_poc_msb_cycle_flag );
1749
269
  sps->setPocMsbFlag( sps_poc_msb_cycle_flag );
1750
1751
269
  if( sps_poc_msb_cycle_flag )
1752
20
  {
1753
20
    X_READ_UVLC( sps_poc_msb_cycle_len_minus1, 0, 32 - sps_log2_max_pic_order_cnt_lsb_minus4 - 5 );
1754
20
    sps->setPocMsbLen( sps_poc_msb_cycle_len_minus1 + 1 );
1755
20
  }
1756
1757
  // extra bits are for future extensions, we will read, but ignore them,
1758
  // unless a meaning is specified in the spec
1759
269
  X_READ_CODE( sps_num_extra_ph_bytes, 2, 0, 2 );
1760
269
  sps->setNumExtraPHBitsBytes( sps_num_extra_ph_bytes );
1761
269
  if( sps_num_extra_ph_bytes )
1762
223
  {
1763
223
    parseExtraPHBitsStruct( sps, sps_num_extra_ph_bytes );
1764
223
  }
1765
1766
269
  X_READ_CODE( sps_num_extra_sh_bytes, 2, 0, 2 );
1767
269
  sps->setNumExtraSHBitsBytes( sps_num_extra_sh_bytes );
1768
269
  if( sps_num_extra_sh_bytes )
1769
215
  {
1770
215
    parseExtraSHBitsStruct( sps, sps_num_extra_sh_bytes );
1771
215
  }
1772
1773
269
  if( sps_ptl_dpb_hrd_params_present_flag )
1774
220
  {
1775
220
    if( sps_max_sublayers_minus1 > 0 )
1776
219
    {
1777
219
      X_READ_FLAG( sps_sublayer_dpb_params_flag );
1778
219
      sps->setSubLayerDpbParamsFlag( sps_sublayer_dpb_params_flag );
1779
219
    }
1780
220
    dpb_parameters( sps_max_sublayers_minus1, sps->getSubLayerDpbParamsFlag(), sps );
1781
220
  }
1782
1783
269
  X_READ_UVLC( sps_log2_min_luma_coding_block_size_minus2, 0, std::min( 4u, sps_log2_ctu_size_minus5 + 3 ) );
1784
269
  sps->setLog2MinCodingBlockSize( sps_log2_min_luma_coding_block_size_minus2 + 2 );
1785
1786
269
  const int MinCbLog2SizeY = sps_log2_min_luma_coding_block_size_minus2 + 2;
1787
269
  const int MinCbSizeY     = 1 << MinCbLog2SizeY;
1788
269
  const int VSize          = std::min( 64, CtbSizeY );
1789
269
  CHECK( MinCbSizeY > VSize, "The value of MinCbSizeY shall be less than or equal to VSize." )
1790
269
  CHECK( MinCbLog2SizeY > CtbLog2SizeY, "Invalid log2_min_luma_coding_block_size_minus2 signalled" );
1791
1792
  // postponed checks for sps_pic_{width,height}_max_in_luma_samples,
1793
269
  CHECK( sps_pic_width_max_in_luma_samples == 0 || sps_pic_width_max_in_luma_samples & ( std::max( 8, MinCbSizeY ) - 1 ),
1794
269
         "sps_pic_width_max_in_luma_samples shall not be equal to 0 and shall be an integer multiple of Max( 8, MinCbSizeY )" );
1795
265
  CHECK( sps_pic_height_max_in_luma_samples == 0 || sps_pic_height_max_in_luma_samples & ( std::max( 8, MinCbSizeY ) - 1 ),
1796
265
         "sps_pic_height_max_in_luma_samples shall not be equal to 0 and shall be an integer multiple of Max( 8, MinCbSizeY )" );
1797
  // reject picture sizes whose buffer sizes overflow 32 bits
1798
261
  PelStorage::calcCompBufSize( {sps_pic_width_max_in_luma_samples, sps_pic_height_max_in_luma_samples}, CtbSizeY, 16 + CtbSizeY, MEMORY_ALIGN_DEF_SIZE, true, 0, 0 );
1799
1800
261
  const int minCuSize = 1 << sps->getLog2MinCodingBlockSize();
1801
261
  CHECK( ( sps->getMaxPicWidthInLumaSamples() % ( std::max( 8, minCuSize ) ) ) != 0, "Coded frame width must be a multiple of Max(8, the minimum unit size)" );
1802
261
  CHECK( ( sps->getMaxPicHeightInLumaSamples() % ( std::max( 8, minCuSize ) ) ) != 0, "Coded frame height must be a multiple of Max(8, the minimum unit size)" );
1803
1804
261
  X_READ_FLAG( sps_partition_constraints_override_enabled_flag );
1805
261
  sps->setSplitConsOverrideEnabledFlag( sps_partition_constraints_override_enabled_flag );
1806
1807
261
  X_READ_UVLC( sps_log2_diff_min_qt_min_cb_intra_slice_luma, 0, std::min( 6, CtbLog2SizeY ) - MinCbLog2SizeY );
1808
261
  const unsigned MinQtLog2SizeIntraY = sps_log2_diff_min_qt_min_cb_intra_slice_luma + MinCbLog2SizeY;
1809
1810
261
  X_READ_UVLC( sps_max_mtt_hierarchy_depth_intra_slice_luma, 0, 2 * ( CtbLog2SizeY - MinCbLog2SizeY ) );
1811
1812
261
  PartitionConstraints minQT     = { 1u << MinQtLog2SizeIntraY, 0, 0 };
1813
261
  PartitionConstraints maxBTD    = { sps_max_mtt_hierarchy_depth_intra_slice_luma, 0, 0 };
1814
261
  PartitionConstraints maxTTSize = { 1u << MinQtLog2SizeIntraY, 0, 0 };
1815
261
  PartitionConstraints maxBTSize = { 1u << MinQtLog2SizeIntraY, 0, 0 };
1816
1817
261
  int spsLog2DiffMinQtMinCbIntraSliceLuma = 0;
1818
261
  if( sps_max_mtt_hierarchy_depth_intra_slice_luma != 0 )
1819
181
  {
1820
181
    X_READ_UVLC( sps_log2_diff_max_bt_min_qt_intra_slice_luma, 0, CtbLog2SizeY - MinQtLog2SizeIntraY );
1821
181
    maxBTSize[0] <<= sps_log2_diff_max_bt_min_qt_intra_slice_luma;
1822
181
    spsLog2DiffMinQtMinCbIntraSliceLuma = sps_log2_diff_max_bt_min_qt_intra_slice_luma;
1823
1824
181
    X_READ_UVLC( sps_log2_diff_max_tt_min_qt_intra_slice_luma, 0, std::min( 6, CtbLog2SizeY ) - MinQtLog2SizeIntraY );
1825
181
    maxTTSize[0] <<= sps_log2_diff_max_tt_min_qt_intra_slice_luma;
1826
181
  }
1827
261
  CHECK( maxTTSize[0] > 64, "The value of sps_log2_diff_max_tt_min_qt_intra_slice_luma shall be in the range of 0 to min(6,CtbLog2SizeY) - MinQtLog2SizeIntraY" );
1828
1829
261
  if( sps_chroma_format_idc != CHROMA_400 )
1830
189
  {
1831
189
    X_READ_FLAG( sps_qtbtt_dual_tree_intra_flag );
1832
189
    sps->setUseDualITree( sps_qtbtt_dual_tree_intra_flag );
1833
1834
189
    (void)spsLog2DiffMinQtMinCbIntraSliceLuma;
1835
    // this breaks the testset (TREE_C_HHI_3.bit) although specified in the spec
1836
    // CHECK( spsLog2DiffMinQtMinCbIntraSliceLuma > std::min( 6, CtbLog2SizeY ) - MinQtLog2SizeIntraY && sps_qtbtt_dual_tree_intra_flag,
1837
    //        "When sps_log2_diff_max_bt_min_qt_intra_slice_luma is greater than Min( 6, CtbLog2SizeY ) - MinQtLog2SizeIntraY, the value of "
1838
    //        "sps_qtbtt_dual_tree_intra_flag shall be equal to 0." )
1839
189
  }
1840
1841
1842
261
  if( sps->getUseDualITree() )
1843
40
  {
1844
40
    X_READ_UVLC( sps_log2_diff_min_qt_min_cb_intra_slice_chroma, 0, std::min( 6, CtbLog2SizeY ) - MinCbLog2SizeY );
1845
40
    const int MinQtLog2SizeIntraC = sps_log2_diff_min_qt_min_cb_intra_slice_chroma + MinCbLog2SizeY;
1846
1847
40
    X_READ_UVLC( sps_max_mtt_hierarchy_depth_intra_slice_chroma, 0, 2 * ( CtbLog2SizeY - MinCbLog2SizeY ) );
1848
40
    maxBTD[2] = sps_max_mtt_hierarchy_depth_intra_slice_chroma;
1849
1850
40
    minQT[2] = 1 << MinQtLog2SizeIntraC;
1851
40
    maxTTSize[2] = maxBTSize[2] = minQT[2];
1852
40
    if( sps_max_mtt_hierarchy_depth_intra_slice_chroma != 0 )
1853
28
    {
1854
28
      X_READ_UVLC( sps_log2_diff_max_bt_min_qt_intra_slice_chroma, 0, std::min( 6, CtbLog2SizeY ) - MinQtLog2SizeIntraC );
1855
28
      maxBTSize[2] <<= sps_log2_diff_max_bt_min_qt_intra_slice_chroma;
1856
1857
28
      X_READ_UVLC( sps_log2_diff_max_tt_min_qt_intra_slice_chroma, 0, std::min( 6, CtbLog2SizeY ) - MinQtLog2SizeIntraC );
1858
28
      maxTTSize[2] <<= sps_log2_diff_max_tt_min_qt_intra_slice_chroma;
1859
1860
28
      CHECK( maxTTSize[2] > 64, "The value of sps_log2_diff_max_tt_min_qt_intra_slice_chroma shall be in the range of 0 to min(6,CtbLog2SizeY) - MinQtLog2SizeIntraChroma" );
1861
28
      CHECK( maxBTSize[2] > 64, "The value of sps_log2_diff_max_bt_min_qt_intra_slice_chroma shall be in the range of 0 to min(6,CtbLog2SizeY) - MinQtLog2SizeIntraChroma" );
1862
28
    }
1863
40
  }
1864
  // minQT[2] = 1 << MinQtLog2SizeIntraC; // THIS WAS MISSING? -> only read for dual tree
1865
1866
261
  X_READ_UVLC( sps_log2_diff_min_qt_min_cb_inter_slice, 0, std::min( 6, CtbLog2SizeY ) - MinCbLog2SizeY );
1867
261
  const int MinQtLog2SizeInterY = sps_log2_diff_min_qt_min_cb_inter_slice + MinCbLog2SizeY;
1868
1869
261
  X_READ_UVLC( sps_max_mtt_hierarchy_depth_inter_slice, 0, 2 * ( CtbLog2SizeY - MinCbLog2SizeY ) );
1870
261
  maxBTD[1] = sps_max_mtt_hierarchy_depth_inter_slice;
1871
1872
261
  minQT[1] = 1 << MinQtLog2SizeInterY;
1873
261
  maxTTSize[1] = maxBTSize[1] = minQT[1];
1874
261
  if( sps_max_mtt_hierarchy_depth_inter_slice != 0 )
1875
163
  {
1876
163
    X_READ_UVLC( sps_log2_diff_max_bt_min_qt_inter_slice, 0, CtbLog2SizeY - MinQtLog2SizeInterY );
1877
163
    maxBTSize[1] <<= sps_log2_diff_max_bt_min_qt_inter_slice;
1878
1879
163
    X_READ_UVLC( sps_log2_diff_max_tt_min_qt_inter_slice, 0, std::min( 6, CtbLog2SizeY ) - MinQtLog2SizeInterY );
1880
163
    maxTTSize[1] <<= sps_log2_diff_max_tt_min_qt_inter_slice;
1881
163
  }
1882
1883
261
  sps->setMinQTSizes( minQT );
1884
261
  sps->setMaxMTTHierarchyDepths( maxBTD );
1885
261
  sps->setMaxBTSizes( maxBTSize );
1886
261
  sps->setMaxTTSizes( maxTTSize );
1887
1888
261
  if( CtbSizeY > 32 )
1889
174
  {
1890
174
    X_READ_FLAG( sps_max_luma_transform_size_64_flag );
1891
174
    sps->setLog2MaxTbSize( 5 + sps_max_luma_transform_size_64_flag );
1892
174
  }
1893
87
  else
1894
87
  {
1895
87
    sps->setLog2MaxTbSize( 5 );
1896
87
  }
1897
1898
261
  X_READ_FLAG( sps_transform_skip_enabled_flag );
1899
261
  sps->setTransformSkipEnabledFlag( sps_transform_skip_enabled_flag );
1900
1901
261
  if( sps_transform_skip_enabled_flag )
1902
142
  {
1903
142
    X_READ_UVLC( sps_log2_transform_skip_max_size_minus2, 0, 3 );
1904
142
    sps->setLog2MaxTransformSkipBlockSize( sps_log2_transform_skip_max_size_minus2 + 2 );
1905
1906
142
    X_READ_FLAG( sps_bdpcm_enabled_flag );
1907
142
    sps->setBDPCMEnabledFlag( sps_bdpcm_enabled_flag );
1908
142
  }
1909
1910
261
  X_READ_FLAG( sps_mts_enabled_flag );
1911
261
  sps->setUseMTS( sps_mts_enabled_flag );
1912
1913
261
  if( sps_mts_enabled_flag )
1914
161
  {
1915
161
    X_READ_FLAG( sps_explicit_mts_intra_enabled_flag );
1916
161
    sps->setUseIntraMTS( sps_explicit_mts_intra_enabled_flag );
1917
1918
161
    X_READ_FLAG( sps_explicit_mts_inter_enabled_flag );
1919
161
    sps->setUseInterMTS( sps_explicit_mts_inter_enabled_flag );
1920
161
  }
1921
1922
261
  X_READ_FLAG( sps_lfnst_enabled_flag );
1923
261
  sps->setUseLFNST( sps_lfnst_enabled_flag );
1924
1925
261
  if( sps_chroma_format_idc != CHROMA_400 )
1926
180
  {
1927
180
    X_READ_FLAG( sps_joint_cbcr_enabled_flag );
1928
180
    sps->setJointCbCrEnabledFlag( sps_joint_cbcr_enabled_flag );
1929
1930
180
    X_READ_FLAG( sps_same_qp_table_for_chroma_flag );
1931
180
    ChromaQpMappingTableParams chromaQpMappingTableParams;
1932
180
    chromaQpMappingTableParams.setSameCQPTableForAllChromaFlag( sps_same_qp_table_for_chroma_flag );
1933
1934
180
    const int numQpTables = sps_same_qp_table_for_chroma_flag ? 1 : ( sps_joint_cbcr_enabled_flag ? 3 : 2 );
1935
180
    chromaQpMappingTableParams.setNumQpTables( numQpTables );
1936
1937
520
    for( int i = 0; i < numQpTables; i++ )
1938
340
    {
1939
340
      X_READ_SVLC( sps_qp_table_start_minus26, -26 - QpBdOffset, 36 );
1940
340
      chromaQpMappingTableParams.setQpTableStartMinus26( i, sps_qp_table_start_minus26 );
1941
1942
340
      X_READ_UVLC( sps_num_points_in_qp_table_minus1, 0, (unsigned) ( 36 - sps_qp_table_start_minus26 ) ); // cast after subtraction to prevent conversion of sps_qp_table_start_minus26 to unsigned
1943
340
      chromaQpMappingTableParams.setNumPtsInCQPTableMinus1( i, sps_num_points_in_qp_table_minus1 );
1944
1945
340
      std::vector<int> deltaQpInValMinus1( sps_num_points_in_qp_table_minus1 + 1 );
1946
340
      std::vector<int> deltaQpOutVal( sps_num_points_in_qp_table_minus1 + 1 );
1947
1.10k
      for( unsigned j = 0; j <= sps_num_points_in_qp_table_minus1; j++ )
1948
765
      {
1949
        // qpInVal/qpOutVal are checked exactly in deriveChromaQPMappingTables(); these ranges only keep their
1950
        // derivation from overflowing: both qpInVal and the XOR below are bounded by maxDeltaQp
1951
765
        const unsigned maxDeltaQp = MAX_QP + QpBdOffset;
1952
1953
765
        X_READ_UVLC_idx( sps_delta_qp_in_val_minus1, "[ i ][ j ]", 0, maxDeltaQp );
1954
765
        deltaQpInValMinus1[j] = sps_delta_qp_in_val_minus1;
1955
1956
765
        X_READ_UVLC_idx( sps_delta_qp_diff_val, "[ i ][ j ]", 0, 2 * maxDeltaQp + 1 );
1957
765
        deltaQpOutVal[j] = sps_delta_qp_diff_val ^ deltaQpInValMinus1[j];
1958
765
      }
1959
340
      chromaQpMappingTableParams.setDeltaQpInValMinus1( i, deltaQpInValMinus1 );
1960
340
      chromaQpMappingTableParams.setDeltaQpOutVal( i, deltaQpOutVal );
1961
340
    }
1962
180
    chromaQpMappingTableParams.m_qpBdOffset = sps->getQpBDOffset();
1963
180
    sps->setChromaQpMappingTableFromParams( std::move( chromaQpMappingTableParams ) );
1964
180
    sps->deriveChromaQPMappingTables();
1965
180
  }
1966
1967
1968
261
  X_READ_FLAG( sps_sao_enabled_flag );
1969
261
  sps->setUseSAO( sps_sao_enabled_flag );
1970
1971
261
  X_READ_FLAG( sps_alf_enabled_flag );
1972
261
  sps->setUseALF( sps_alf_enabled_flag );
1973
1974
261
  if( sps_alf_enabled_flag && sps_chroma_format_idc != CHROMA_400 )
1975
69
  {
1976
69
    X_READ_FLAG( sps_ccalf_enabled_flag );
1977
69
    sps->setUseCCALF( sps_ccalf_enabled_flag );
1978
69
  }
1979
192
  else
1980
192
  {
1981
192
    sps->setUseCCALF( false );
1982
192
  }
1983
1984
261
  X_READ_FLAG( sps_lmcs_enable_flag );
1985
261
  sps->setUseReshaper( sps_lmcs_enable_flag );
1986
1987
261
  X_READ_FLAG( sps_weighted_pred_flag );
1988
261
  sps->setUseWP( sps_weighted_pred_flag );
1989
1990
261
  X_READ_FLAG( sps_weighted_bipred_flag );
1991
261
  sps->setUseWPBiPred( sps_weighted_bipred_flag );
1992
1993
261
  X_READ_FLAG( sps_long_term_ref_pics_flag );
1994
261
  sps->setLongTermRefsPresent( sps_long_term_ref_pics_flag );
1995
1996
261
  if( sps_video_parameter_set_id > 0 )
1997
5
  {
1998
5
    X_READ_FLAG( sps_inter_layer_prediction_enabled_flag );
1999
5
    CHECK_UNSUPPORTED( sps_inter_layer_prediction_enabled_flag, "Inter-layer prediction not yet supported" );
2000
4
    sps->setInterLayerPresentFlag( sps_inter_layer_prediction_enabled_flag );
2001
    // CHECK( vps->getIndependentLayerFlag( vps->getGeneralLayerIdx( nuh_layer_id ) ) == 1 && sps_inter_layer_prediction_enabled_flag != 0,
2002
    //        "When vps_independent_layer_flag[ GeneralLayerIdx[ nuh_layer_id ] ] is equal to 1,"
2003
    //        " the value of sps_inter_layer_prediction_enabled_flag shall be equal to 0." )
2004
4
  }
2005
2006
260
  X_READ_FLAG( sps_idr_rpl_present_flag );
2007
260
  CHECK_CONSTRAINT( gci->getNoIdrRplConstraintFlag() && sps_idr_rpl_present_flag,
2008
260
                    "When gci_no_idr_rpl_constraint_flag equal to 1, the value of sps_idr_rpl_present_flag shall be equal to 0" );
2009
260
  sps->setIDRRefParamListPresent( sps_idr_rpl_present_flag );
2010
2011
260
  X_READ_FLAG( sps_rpl1_same_as_rpl0_flag );
2012
260
  sps->setRPL1CopyFromRPL0Flag( sps_rpl1_same_as_rpl0_flag );
2013
2014
526
  for( unsigned i = 0; i < ( sps_rpl1_same_as_rpl0_flag ? 1 : 2 ); i++ )
2015
266
  {
2016
266
    X_READ_UVLC_idx( sps_num_ref_pic_lists, "[i]", 0, 64 );
2017
2018
266
    RPLList& rplList = sps->createRPLList( i, sps_num_ref_pic_lists );
2019
1.10k
    for( unsigned j = 0; j < sps_num_ref_pic_lists; j++ )
2020
843
    {
2021
843
      parseRefPicList( &rplList[j], j, sps );
2022
843
    }
2023
266
  }
2024
260
  if( sps_rpl1_same_as_rpl0_flag )
2025
60
  {
2026
60
    const unsigned numberOfRPL   = sps->getNumRPL( 0 );
2027
60
    const RPLList& rplListSource = sps->getRPLList( 0 );
2028
60
    RPLList&       rplListDest   = sps->createRPLList( 1, numberOfRPL );
2029
356
    for( unsigned j = 0; j < numberOfRPL; j++ )
2030
296
    {
2031
296
      copyRefPicList( sps, &rplListSource[j], &rplListDest[j] );
2032
296
    }
2033
60
  }
2034
2035
2036
260
  X_READ_FLAG( sps_ref_wraparound_enabled_flag );
2037
260
  sps->setUseWrapAround( sps_ref_wraparound_enabled_flag );
2038
410
  for( int i = 0; i < sps->getNumSubPics(); ++i )
2039
150
  {
2040
150
    CHECK( sps->getSubPicTreatedAsPicFlag( i ) == 1 && sps->getSubPicWidth( i ) != ( sps_pic_width_max_in_luma_samples + CtbSizeY - 1 ) >> CtbLog2SizeY
2041
150
             && sps_ref_wraparound_enabled_flag != 0,
2042
150
           "It is a requirement of bitstream conformance that, when there is one or more values of i in the range of 0 to sps_num_subpics_minus1, inclusive,"
2043
150
           " for which sps_subpic_treated_as_pic_flag[ i ] is equal to 1 and sps_subpic_width_minus1[ i ] plus 1 is not equal to"
2044
150
           " ( sps_pic_width_max_in_luma_samples + CtbSizeY− 1 ) >> CtbLog2SizeY ), the value of sps_ref_wraparound_enabled_flag shall be equal to 0." );
2045
150
  }
2046
2047
260
  X_READ_FLAG( sps_temporal_mvp_enabled_flag );
2048
260
  sps->setSPSTemporalMVPEnabledFlag( sps_temporal_mvp_enabled_flag );
2049
2050
260
  if( sps_temporal_mvp_enabled_flag )
2051
102
  {
2052
102
    X_READ_FLAG( sps_sbtmvp_enabled_flag );
2053
102
    sps->setSBTMVPEnabledFlag( sps_sbtmvp_enabled_flag );
2054
102
  }
2055
2056
260
  X_READ_FLAG( sps_amvr_enabled_flag );
2057
260
  sps->setAMVREnabledFlag( sps_amvr_enabled_flag );
2058
2059
260
  X_READ_FLAG( sps_bdof_enabled_flag );
2060
260
  sps->setUseBIO( sps_bdof_enabled_flag );
2061
2062
260
  if( sps_bdof_enabled_flag )
2063
74
  {
2064
74
    X_READ_FLAG( sps_bdof_control_present_in_ph_flag );
2065
74
    sps->setBdofControlPresentInPhFlag( sps_bdof_control_present_in_ph_flag );
2066
74
  }
2067
2068
260
  X_READ_FLAG( sps_smvd_enabled_flag );
2069
260
  sps->setUseSMVD( sps_smvd_enabled_flag );
2070
2071
260
  X_READ_FLAG( sps_dmvr_enabled_flag );
2072
260
  sps->setUseDMVR( sps_dmvr_enabled_flag );
2073
2074
260
  if( sps_dmvr_enabled_flag )
2075
95
  {
2076
95
    X_READ_FLAG( sps_dmvr_control_present_in_ph_flag );
2077
95
    sps->setDmvrControlPresentInPhFlag( sps_dmvr_control_present_in_ph_flag );
2078
95
  }
2079
2080
260
  X_READ_FLAG( sps_mmvd_enabled_flag );
2081
260
  sps->setUseMMVD( sps_mmvd_enabled_flag );
2082
2083
260
  if( sps->getUseMMVD() )
2084
100
  {
2085
100
    X_READ_FLAG( sps_mmvd_fullpel_only_flag );
2086
100
    sps->setFpelMmvdEnabledFlag( sps_mmvd_fullpel_only_flag );
2087
100
  }
2088
2089
260
  X_READ_UVLC( sps_six_minus_max_num_merge_cand, 0, 5 );
2090
260
  const unsigned MaxNumMergeCand = MRG_MAX_NUM_CANDS - sps_six_minus_max_num_merge_cand;
2091
260
  sps->setMaxNumMergeCand( MaxNumMergeCand );
2092
2093
260
  X_READ_FLAG( sps_sbt_enabled_flag );
2094
260
  sps->setUseSBT( sps_sbt_enabled_flag );
2095
2096
260
  X_READ_FLAG( sps_affine_enabled_flag );
2097
260
  sps->setUseAffine( sps_affine_enabled_flag );
2098
2099
260
  if( sps_affine_enabled_flag )
2100
83
  {
2101
83
    X_READ_UVLC( sps_five_minus_max_num_subblock_merge_cand, 0, 5 - sps->getSBTMVPEnabledFlag() );
2102
83
    sps->setMaxNumAffineMergeCand( AFFINE_MRG_MAX_NUM_CANDS - sps_five_minus_max_num_subblock_merge_cand );
2103
2104
83
    X_READ_FLAG( sps_6param_affine_enabled_flag );
2105
83
    sps->setUseAffineType( sps_6param_affine_enabled_flag );
2106
2107
83
    if( sps_amvr_enabled_flag )
2108
42
    {
2109
42
      X_READ_FLAG( sps_affine_amvr_enabled_flag );
2110
42
      sps->setAffineAmvrEnabledFlag( sps_affine_amvr_enabled_flag );
2111
42
    }
2112
2113
83
    X_READ_FLAG( sps_affine_prof_enabled_flag );
2114
83
    sps->setUsePROF( sps_affine_prof_enabled_flag );
2115
2116
83
    if( sps_affine_prof_enabled_flag )
2117
57
    {
2118
57
      X_READ_FLAG( sps_prof_control_present_in_ph_flag );
2119
57
      sps->setProfControlPresentInPhFlag( sps_prof_control_present_in_ph_flag );
2120
57
    }
2121
83
  }
2122
2123
260
  X_READ_FLAG( sps_bcw_enabled_flag );
2124
260
  sps->setUseBcw( sps_bcw_enabled_flag );
2125
2126
260
  X_READ_FLAG( sps_ciip_enabled_flag );
2127
260
  sps->setUseCiip( sps_ciip_enabled_flag );
2128
2129
260
  if( MaxNumMergeCand >= 2 )
2130
135
  {
2131
135
    X_READ_FLAG( sps_gpm_enabled_flag );
2132
135
    sps->setUseGeo( sps_gpm_enabled_flag );
2133
2134
135
    if( sps_gpm_enabled_flag && MaxNumMergeCand >= 3 )
2135
86
    {
2136
86
      X_READ_UVLC( sps_max_num_merge_cand_minus_max_num_gpm_cand, 0, MaxNumMergeCand - 2 );
2137
86
      sps->setMaxNumGeoCand( MaxNumMergeCand - sps_max_num_merge_cand_minus_max_num_gpm_cand );
2138
86
    }
2139
49
    else if( sps_gpm_enabled_flag )
2140
2
    {
2141
2
      sps->setMaxNumGeoCand( 2 );
2142
2
    }
2143
135
  }
2144
2145
260
  X_READ_UVLC( sps_log2_parallel_merge_level_minus2, 0, CtbLog2SizeY - 2 );
2146
260
  sps->setLog2ParallelMergeLevelMinus2( sps_log2_parallel_merge_level_minus2 );
2147
2148
260
  X_READ_FLAG( sps_isp_enabled_flag );
2149
260
  sps->setUseISP( sps_isp_enabled_flag );
2150
2151
260
  X_READ_FLAG( sps_mrl_enabled_flag );
2152
260
  sps->setUseMRL( sps_mrl_enabled_flag );
2153
2154
260
  X_READ_FLAG( sps_mip_enabled_flag );
2155
260
  sps->setUseMIP( sps_mip_enabled_flag );
2156
2157
260
  if( sps_chroma_format_idc != CHROMA_400 )
2158
126
  {
2159
126
    X_READ_FLAG( sps_cclm_enabled_flag );
2160
126
    sps->setUseLMChroma( sps_cclm_enabled_flag );
2161
126
  }
2162
2163
260
  if( sps_chroma_format_idc == CHROMA_420 )
2164
1
  {
2165
1
    X_READ_FLAG( sps_chroma_horizontal_collocated_flag );
2166
1
    sps->setHorCollocatedChromaFlag( sps_chroma_horizontal_collocated_flag );
2167
2168
1
    X_READ_FLAG( sps_chroma_vertical_collocated_flag );
2169
1
    sps->setVerCollocatedChromaFlag( sps_chroma_vertical_collocated_flag );
2170
1
  }
2171
2172
260
  X_READ_FLAG( sps_palette_enabled_flag );
2173
260
  CHECK( sps_palette_enabled_flag, "palette mode is not yet supported" );
2174
2175
253
  if( sps_chroma_format_idc == CHROMA_444 && sps->getLog2MaxTbSize() != 6 )
2176
21
  {
2177
21
    X_READ_FLAG( sps_act_enabled_flag );
2178
21
    sps->setUseColorTrans( sps_act_enabled_flag );
2179
21
  }
2180
2181
253
  if( sps_transform_skip_enabled_flag || sps_palette_enabled_flag )
2182
92
  {
2183
92
    X_READ_UVLC( sps_internal_bit_depth_minus_input_bit_depth, 0, 8 );   // Why is this called sps_min_qp_prime_ts in the standard?
2184
92
    sps->setInternalMinusInputBitDepth( sps_internal_bit_depth_minus_input_bit_depth );
2185
92
  }
2186
2187
253
  X_READ_FLAG( sps_ibc_enabled_flag );
2188
253
  sps->setIBCFlag( sps_ibc_enabled_flag );
2189
2190
253
  if( sps_ibc_enabled_flag )
2191
88
  {
2192
88
    X_READ_UVLC( sps_six_minus_max_num_ibc_merge_cand, 0, 5 );
2193
88
    sps->setMaxNumIBCMergeCand( IBC_MRG_MAX_NUM_CANDS - sps_six_minus_max_num_ibc_merge_cand );
2194
88
  }
2195
2196
253
#  if LUMA_ADAPTIVE_DEBLOCKING_FILTER_QP_OFFSET
2197
253
  X_READ_FLAG( sps_ladf_enabled_flag );
2198
253
  sps->setLadfEnabled( sps_ladf_enabled_flag );
2199
2200
253
  if( sps->getLadfEnabled() )
2201
96
  {
2202
96
    X_READ_CODE( sps_num_ladf_intervals_minus2, 2, 0, 3 );
2203
96
    sps->setLadfNumIntervals( sps_num_ladf_intervals_minus2 + 2 );
2204
2205
96
    X_READ_SVLC( sps_ladf_lowest_interval_qp_offset, -63, 63 );
2206
96
    sps->setLadfQpOffset( sps_ladf_lowest_interval_qp_offset, 0 );
2207
2208
321
    for( unsigned i = 0; i < sps_num_ladf_intervals_minus2 + 1; i++ )
2209
225
    {
2210
225
      X_READ_SVLC_idx( sps_ladf_qp_offset, "[i]", -63, 63 );
2211
225
      sps->setLadfQpOffset( sps_ladf_qp_offset, i + 1 );
2212
2213
225
      X_READ_UVLC_idx( sps_ladf_delta_threshold_minus1, "[i]", 0, ( 1 << BitDepth ) - 3 );
2214
225
      sps->setLadfIntervalLowerBound( sps->getLadfIntervalLowerBound( i ) + sps_ladf_delta_threshold_minus1 + 1, i + 1 );
2215
225
    }
2216
96
  }
2217
253
#endif
2218
2219
253
  X_READ_FLAG( sps_explicit_scaling_list_enabled_flag );
2220
253
  CHECK_CONSTRAINT( gci->getNoExplicitScaleListConstraintFlag() && sps_explicit_scaling_list_enabled_flag,
2221
253
                    "When gci_no_explicit_scaling_list_constraint_flag is equal to 1, sps_explicit_scaling_list_enabled_flag shall be equal to 0" );
2222
253
  sps->setScalingListFlag( sps_explicit_scaling_list_enabled_flag );
2223
2224
253
  if( sps_lfnst_enabled_flag && sps_explicit_scaling_list_enabled_flag )
2225
10
  {
2226
10
    X_READ_FLAG( sps_scaling_matrix_for_lfnst_disabled_flag );
2227
10
    sps->setDisableScalingMatrixForLfnstBlks( sps_scaling_matrix_for_lfnst_disabled_flag );
2228
10
  }
2229
2230
253
  if( sps->getUseColorTrans() && sps_explicit_scaling_list_enabled_flag )
2231
10
  {
2232
10
    X_READ_FLAG( sps_scaling_matrix_for_alternative_colour_space_disabled_flag );
2233
10
    sps->setScalingMatrixForAlternativeColourSpaceDisabledFlag( sps_scaling_matrix_for_alternative_colour_space_disabled_flag );
2234
2235
10
    if( sps_scaling_matrix_for_alternative_colour_space_disabled_flag )
2236
7
    {
2237
7
      X_READ_FLAG( sps_scaling_matrix_designated_colour_space_flag );
2238
7
      sps->setScalingMatrixDesignatedColourSpaceFlag( sps_scaling_matrix_designated_colour_space_flag );
2239
7
    }
2240
10
  }
2241
2242
253
  X_READ_FLAG( sps_dep_quant_enabled_flag );
2243
253
  sps->setDepQuantEnabledFlag( sps_dep_quant_enabled_flag );
2244
2245
253
  X_READ_FLAG( sps_sign_data_hiding_enabled_flag );
2246
253
  sps->setSignDataHidingEnabledFlag( sps_sign_data_hiding_enabled_flag );
2247
2248
253
  X_READ_FLAG( sps_virtual_boundaries_enabled_flag );
2249
253
  CHECK_CONSTRAINT( gci->getNoVirtualBoundaryConstraintFlag() && sps_virtual_boundaries_enabled_flag,
2250
253
                    "When gci_no_virtual_boundaries_constraint_flag is equal to 1, sps_virtual_boundaries_enabled_flag shall be equal to 0" );
2251
253
  sps->setVirtualBoundariesEnabledFlag( sps_virtual_boundaries_enabled_flag );
2252
2253
253
  if( sps_virtual_boundaries_enabled_flag )
2254
66
  {
2255
66
    X_READ_FLAG( sps_virtual_boundaries_present_flag );
2256
66
    sps->setVirtualBoundariesPresentFlag( sps_virtual_boundaries_present_flag );
2257
2258
66
    if( sps_virtual_boundaries_present_flag )
2259
21
    {
2260
21
      X_READ_UVLC( sps_num_ver_virtual_boundaries, 0, sps_pic_width_max_in_luma_samples <= 8 ? 0 : 3 );
2261
21
      sps->setNumVerVirtualBoundaries( sps_num_ver_virtual_boundaries );
2262
2263
29
      for( unsigned i = 0; i < sps_num_ver_virtual_boundaries; i++ )
2264
8
      {
2265
8
        X_READ_UVLC_idx( sps_virtual_boundary_pos_x_minus1, "[i]", 0, ( sps_pic_width_max_in_luma_samples + 7 ) / 8 - 2 );
2266
8
        sps->setVirtualBoundariesPosX( ( sps_virtual_boundary_pos_x_minus1 + 1 ) << 3, i );
2267
8
      }
2268
2269
21
      X_READ_UVLC_idx( sps_num_hor_virtual_boundaries, "[i]", 0, sps_pic_height_max_in_luma_samples <= 8 ? 0 : 3  );
2270
21
      sps->setNumHorVirtualBoundaries( sps_num_hor_virtual_boundaries );
2271
2272
21
      for( unsigned i = 0; i <sps_num_hor_virtual_boundaries; i++ )
2273
0
      {
2274
0
        X_READ_UVLC_idx( sps_virtual_boundary_pos_y_minus1, "[i]", 0, ( sps_pic_height_max_in_luma_samples + 7 ) / 8 - 2 );
2275
0
        sps->setVirtualBoundariesPosY( (sps_virtual_boundary_pos_y_minus1 + 1) << 3, i );
2276
0
      }
2277
21
    }
2278
66
  }
2279
2280
253
  if( sps_ptl_dpb_hrd_params_present_flag )
2281
104
  {
2282
104
    X_READ_FLAG( sps_timing_hrd_params_present_flag );
2283
104
    sps->setGeneralHrdParametersPresentFlag( sps_timing_hrd_params_present_flag );
2284
2285
104
    if( sps_timing_hrd_params_present_flag )
2286
80
    {
2287
80
      parseGeneralHrdParameters( sps->getGeneralHrdParameters() );
2288
80
      if( sps_max_sublayers_minus1 > 0 )
2289
76
      {
2290
76
        X_READ_FLAG( sps_sublayer_cpb_params_present_flag );
2291
76
        sps->setSubLayerParametersPresentFlag( sps_sublayer_cpb_params_present_flag );
2292
76
      }
2293
2294
80
      uint32_t firstSubLayer = sps->getSubLayerParametersPresentFlag() ? 0 : sps_max_sublayers_minus1;
2295
80
      parseOlsHrdParameters( sps->getGeneralHrdParameters(), sps->getOlsHrdParameters(), firstSubLayer, sps_max_sublayers_minus1 );
2296
80
    }
2297
104
  }
2298
2299
253
  X_READ_FLAG( sps_field_seq_flag );
2300
253
  sps->setFieldSeqFlag( sps_field_seq_flag );
2301
2302
253
  CHECK_CONSTRAINT( sps->getProfileTierLevel()->getFrameOnlyConstraintFlag() && sps_field_seq_flag,
2303
252
                     "When ptl_frame_only_constraint_flag equal to 1 , the value of sps_field_seq_flag shall be equal to 0" );
2304
2305
252
  X_READ_FLAG( sps_vui_parameters_present_flag );
2306
252
  sps->setVuiParametersPresentFlag( sps_vui_parameters_present_flag );
2307
2308
252
  if( sps_vui_parameters_present_flag )
2309
49
  {
2310
49
    X_READ_UVLC( sps_vui_payload_size_minus1, 0, 1023 );
2311
49
    sps->setVuiPayloadSize( sps_vui_payload_size_minus1 + 1 );
2312
2313
85
    while( !isByteAligned() )
2314
46
    {
2315
46
      X_READ_FLAG( sps_vui_alignment_zero_bit );
2316
46
      CHECK( sps_vui_alignment_zero_bit, "sps_vui_alignment_zero_bit not equal to 0" );
2317
36
    }
2318
2319
39
    parseVUI( sps->getVuiParameters(), sps->getVuiPayloadSize() );
2320
39
  }
2321
2322
242
  X_READ_FLAG( sps_extension_present_flag );
2323
242
  if( sps_extension_present_flag )
2324
16
  {
2325
607
    while( xMoreRbspData() )
2326
591
    {
2327
591
      X_READ_FLAG( sps_extension_data_flag );
2328
591
      (void)sps_extension_data_flag;
2329
591
    }
2330
16
  }
2331
2332
242
  xReadRbspTrailingBits();
2333
242
}
2334
2335
void HLSyntaxReader::parseDCI( DCI* dci )
2336
44
{
2337
#if ENABLE_TRACING
2338
  xTraceDCIHeader();
2339
#endif
2340
44
  X_READ_CODE_NO_RANGE( dci_reserved_zero_4bits, 4 );
2341
44
  (void) dci_reserved_zero_4bits;
2342
2343
44
  X_READ_CODE( dci_num_ptls_minus1, 4, 0, 15 );
2344
44
  CHECK_WARN( dci_num_ptls_minus1 == 15, "reserved dci_num_ptls_minus1==15 used" );
2345
44
  const int numPTLs = dci_num_ptls_minus1 + 1;
2346
2347
44
  std::vector<ProfileTierLevel> ptls( numPTLs );
2348
127
  for( int i = 0; i < numPTLs; i++ )
2349
83
  {
2350
83
    parseProfileTierLevel( &ptls[i], true, 0 );
2351
83
  }
2352
44
  dci->setProfileTierLevel( std::move( ptls ) );
2353
2354
44
  X_READ_FLAG(dci_extension_flag );
2355
44
  if( dci_extension_flag )
2356
11
  {
2357
629
    while( xMoreRbspData() )
2358
618
    {
2359
618
      X_READ_FLAG( dci_extension_data_flag );
2360
618
      (void) dci_extension_data_flag;
2361
618
    }
2362
11
  }
2363
44
  xReadRbspTrailingBits();
2364
44
}
2365
2366
#if 0
2367
// We don't parse the VPS, because the needed bounds checks in parseVPS() are not yet implemented, and we don't process it anyways
2368
void HLSyntaxReader::parseVPS( VPS* pcVPS )
2369
{
2370
#if ENABLE_TRACING
2371
  xTraceVPSHeader();
2372
#endif
2373
  uint32_t  uiCode;
2374
2375
  //CHECK( true, "needs to be adjusted, e.g. sublayer and independent layer stuff -> see VTM-9.0" );
2376
2377
  READ_CODE( 4, uiCode, "vps_video_parameter_set_id" );                      pcVPS->setVPSId( uiCode );
2378
  CHECK( uiCode == 0, "vps_video_parameter_set_id equal to zero is reserved and shall not be used in a bitstream" );
2379
2380
  READ_CODE( 6, uiCode, "vps_max_layers_minus1" );                           pcVPS->setMaxLayers( uiCode + 1 );
2381
  CHECK( uiCode + 1 > MAX_VPS_LAYERS, "Signalled number of layers larger than MAX_VPS_LAYERS." );
2382
2383
  if( pcVPS->getMaxLayers() - 1 == 0 )
2384
  {
2385
    pcVPS->setEachLayerIsAnOlsFlag( 1 );
2386
  }
2387
  READ_CODE( 3, uiCode, "vps_max_sublayers_minus1" );                        pcVPS->setMaxSubLayers( uiCode + 1 );
2388
  CHECK( uiCode + 1 > MAX_VPS_SUBLAYERS, "Signalled number of sublayers larger than MAX_VPS_SUBLAYERS." );
2389
2390
  if( pcVPS->getMaxLayers() > 1 && pcVPS->getMaxSubLayers() > 1 )
2391
  {
2392
    READ_FLAG( uiCode, "vps_default_ptl_dpb_hrd_max_tid_flag" );             pcVPS->setAllLayersSameNumSublayersFlag( uiCode );
2393
  }
2394
  else
2395
  {
2396
    pcVPS->setAllLayersSameNumSublayersFlag( 1 );
2397
  }
2398
  if( pcVPS->getMaxLayers() > 1 )
2399
  {
2400
    READ_FLAG( uiCode, "vps_all_independent_layers_flag" );                  pcVPS->setAllIndependentLayersFlag( uiCode );
2401
    if( pcVPS->getAllIndependentLayersFlag() == 0 )
2402
    {
2403
      pcVPS->setEachLayerIsAnOlsFlag( 0 );
2404
    }
2405
  }
2406
  for( uint32_t i = 0; i < pcVPS->getMaxLayers(); i++ )
2407
  {
2408
    READ_CODE( 6, uiCode, "vps_layer_id[i]" );                             pcVPS->setLayerId( i, uiCode );
2409
    pcVPS->setGeneralLayerIdx( uiCode, i );
2410
2411
    if( i > 0 && !pcVPS->getAllIndependentLayersFlag() )
2412
    {
2413
      READ_FLAG( uiCode, "vps_independent_layer_flag[i]" );                pcVPS->setIndependentLayerFlag( i, uiCode );
2414
      if( !pcVPS->getIndependentLayerFlag( i ) )
2415
      {
2416
        READ_FLAG( uiCode, "vps_max_tid_ref_present_flag[i]" );
2417
        bool vpsMaxTidRefPresentFlag = ( uiCode == 1 );
2418
2419
        uint16_t sumUiCode = 0;
2420
        for( int j = 0, k = 0; j < i; j++ )
2421
        {
2422
          READ_FLAG( uiCode, "vps_direct_ref_layer_flag[ i ][ j ]" );        pcVPS->setDirectRefLayerFlag( i, j, uiCode );
2423
          if( uiCode )
2424
          {
2425
            pcVPS->setInterLayerRefIdc( i, j, k );
2426
            pcVPS->setDirectRefLayerIdx( i, k++, j );
2427
            sumUiCode++;
2428
            if( vpsMaxTidRefPresentFlag )
2429
            {
2430
              READ_CODE( 3, uiCode, "vps_max_tid_il_ref_pics_plus1[i][ j ]" );
2431
//              pcVPS->setMaxTidIlRefPicsPlus1( i, uiCode );
2432
            }
2433
          }
2434
        }
2435
        CHECK(sumUiCode == 0, "There has to be at least one value of j such that the value of vps_direct_dependency_flag[i][ j ] is equal to 1,when vps_independent_layer_flag[i] is equal to 0 " );
2436
//        if( uiCode )
2437
//        {
2438
//          READ_CODE( 3, uiCode, "max_tid_il_ref_pics_plus1[i]" ); pcVPS->setMaxTidIlRefPicsPlus1( i, uiCode );
2439
//        }
2440
//        else
2441
//        {
2442
//          pcVPS->setMaxTidIlRefPicsPlus1( i, 7) ;
2443
//        }
2444
      }
2445
    }
2446
  }
2447
2448
  if( pcVPS->getMaxLayers() > 1 )
2449
  {
2450
    if( pcVPS->getAllIndependentLayersFlag() )
2451
    {
2452
      READ_FLAG( uiCode, "vps_each_layer_is_an_ols_flag" );                  pcVPS->setEachLayerIsAnOlsFlag( uiCode );
2453
      if( pcVPS->getEachLayerIsAnOlsFlag() == 0 )
2454
      {
2455
        pcVPS->setOlsModeIdc( 2 );
2456
      }
2457
    }
2458
    if( !pcVPS->getEachLayerIsAnOlsFlag() )
2459
    {
2460
      if( !pcVPS->getAllIndependentLayersFlag() )
2461
      {
2462
        READ_CODE( 2, uiCode, "vps_ols_mode_idc" );                          pcVPS->setOlsModeIdc( uiCode );
2463
        CHECK( uiCode > MAX_VPS_OLS_MODE_IDC, "ols_mode_idc shall be in the rage of 0 to 2" );
2464
      }
2465
      if( pcVPS->getOlsModeIdc() == 2 )
2466
      {
2467
        READ_CODE( 8, uiCode, "vps_num_output_layer_sets_minus2" );          pcVPS->setNumOutputLayerSets( uiCode + 2 );
2468
        for( uint32_t i = 1; i <= pcVPS->getNumOutputLayerSets() - 1; i++ )
2469
        {
2470
          for( uint32_t j = 0; j < pcVPS->getMaxLayers(); j++ )
2471
          {
2472
            READ_FLAG( uiCode, "vps_ols_output_layer_flag[i][ j ]" );      pcVPS->setOlsOutputLayerFlag( i, j, uiCode );
2473
          }
2474
        }
2475
      }
2476
    }
2477
    READ_CODE( 8, uiCode, "vps_num_ptls_minus1" );                           pcVPS->setNumPtls( uiCode + 1 );
2478
  }
2479
  else
2480
  {
2481
    pcVPS->setNumPtls( 1 );
2482
  }
2483
2484
  pcVPS->deriveOutputLayerSets();
2485
  CHECK( uiCode >= pcVPS->getTotalNumOLSs(), "The value of vps_num_ptls_minus1 shall be less than TotalNumOlss" );
2486
2487
  std::vector<bool> isPTLReferred( pcVPS->getNumPtls(), false );
2488
  for( int i = 0; i < pcVPS->getNumPtls(); i++ )
2489
  {
2490
    if( i > 0 )
2491
    {
2492
      READ_FLAG( uiCode, "pt_present_flag[i]" );                           pcVPS->setPtPresentFlag( i, uiCode );
2493
    }
2494
    else
2495
    {
2496
       pcVPS->setPtPresentFlag( 0, 1 );
2497
    }
2498
2499
    if( !pcVPS->getAllLayersSameNumSublayersFlag() )
2500
    {
2501
      READ_CODE( 3, uiCode, "ptl_max_tid[i]" );                            pcVPS->setPtlMaxTemporalId( i, uiCode );
2502
    }
2503
    else
2504
    {
2505
      pcVPS->setPtlMaxTemporalId( i, pcVPS->getMaxSubLayers() - 1 );
2506
    }
2507
  }
2508
  int cnt = 0;
2509
  while( m_pcBitstream->getNumBitsUntilByteAligned() )
2510
  {
2511
    READ_FLAG( uiCode, "vps_ptl_reserved_zero_bit" );
2512
    CHECK( uiCode!=0, "Alignment bit is not '0'" );
2513
    cnt++;
2514
  }
2515
  CHECK( cnt >= 8, "Read more than '8' alignment bits" );
2516
  {
2517
    std::vector<ProfileTierLevel> ptls( pcVPS->getNumPtls() );
2518
    for( int i = 0; i < pcVPS->getNumPtls(); i++ )
2519
    {
2520
      parseProfileTierLevel( &ptls[i], pcVPS->getPtPresentFlag( i ), pcVPS->getPtlMaxTemporalId( i ) );
2521
    }
2522
    pcVPS->setProfileTierLevel( std::move( ptls ) );
2523
  }
2524
  for( int i = 0; i < pcVPS->getTotalNumOLSs(); i++ )
2525
  {
2526
    if( pcVPS->getNumPtls() > 1 && pcVPS->getNumPtls() != pcVPS->getTotalNumOLSs() )
2527
    {
2528
      READ_CODE( 8, uiCode, "vps_ols_ptl_idx[i]" );                        pcVPS->setOlsPtlIdx( i, uiCode );
2529
    }
2530
    else if( pcVPS->getNumPtls() == pcVPS->getTotalNumOLSs() )
2531
    {
2532
      pcVPS->setOlsPtlIdx( i, i );
2533
    }
2534
    else
2535
    {
2536
      pcVPS->setOlsPtlIdx( i, 0 );
2537
    }
2538
    isPTLReferred[pcVPS->getOlsPtlIdx( i )] = true;
2539
  }
2540
  for( int i = 0; i < pcVPS->getNumPtls(); i++ )
2541
  {
2542
    CHECK( !isPTLReferred[i],"Each profile_tier_level( ) syntax structure in the VPS shall be referred to by at least one value of vps_ols_ptl_idx[i] for i in the range of 0 to TotalNumOlss ? 1, inclusive" );
2543
  }
2544
2545
  if( !pcVPS->getEachLayerIsAnOlsFlag() )
2546
  {
2547
    READ_UVLC( uiCode, "vps_num_dpb_params_minus1" );                        pcVPS->m_numDpbParams = uiCode + 1;
2548
2549
    CHECK( pcVPS->m_numDpbParams > pcVPS->getNumMultiLayeredOlss(), "The value of vps_num_dpb_params_minus1 shall be in the range of 0 to NumMultiLayerOlss - 1, inclusive" );
2550
    std::vector<bool> isDPBParamReferred( pcVPS->m_numDpbParams, false );
2551
2552
    if( pcVPS->m_numDpbParams > 0 && pcVPS->getMaxSubLayers() > 1 )
2553
    {
2554
      READ_FLAG( uiCode, "vps_sublayer_dpb_params_present_flag" );           pcVPS->m_sublayerDpbParamsPresentFlag = uiCode;
2555
    }
2556
2557
    pcVPS->m_dpbParameters.resize( pcVPS->m_numDpbParams );
2558
2559
    for( int i = 0; i < pcVPS->m_numDpbParams; i++ )
2560
    {
2561
      if( !pcVPS->getAllLayersSameNumSublayersFlag() )
2562
      {
2563
        READ_CODE( 3, uiCode, "vps_dpb_max_tid[i]" );
2564
        pcVPS->m_dpbMaxTemporalId.push_back( uiCode );
2565
        CHECK( uiCode > ( pcVPS->getMaxSubLayers() - 1 ), "The value of vps_dpb_max_tid[i] shall be in the range of 0 to vps_max_sublayers_minus1, inclusive." )
2566
      }
2567
      else
2568
      {
2569
        pcVPS->m_dpbMaxTemporalId.push_back( pcVPS->getMaxSubLayers() - 1 );
2570
      }
2571
2572
      for( int j = ( pcVPS->m_sublayerDpbParamsPresentFlag ? 0 : pcVPS->m_dpbMaxTemporalId[i] ); j <= pcVPS->m_dpbMaxTemporalId[i]; j++ )
2573
      {
2574
        READ_UVLC( uiCode, "dpb_max_dec_pic_buffering_minus1[i]" );        pcVPS->m_dpbParameters[i].m_maxDecPicBuffering[j] = uiCode + 1;
2575
        CHECK( uiCode >= MAX_NUM_REF_PICS, "dpb_max_dec_pic_buffering_minus1[i] out of bounds (read:" << uiCode << ")" );
2576
        READ_UVLC( uiCode, "dpb_max_num_reorder_pics[i]" );                pcVPS->m_dpbParameters[i].m_numReorderPics[j] = uiCode;
2577
        READ_UVLC( uiCode, "dpb_max_latency_increase_plus1[i]" );          pcVPS->m_dpbParameters[i].m_maxLatencyIncreasePlus1[j] = uiCode;
2578
      }
2579
2580
      for( int j = ( pcVPS->m_sublayerDpbParamsPresentFlag ? pcVPS->m_dpbMaxTemporalId[i] : 0 ); j < pcVPS->m_dpbMaxTemporalId[i]; j++ )
2581
      {
2582
        // When max_dec_pic_buffering_minus1[i] is not present for i in the range of 0 to maxSubLayersMinus1 - 1, inclusive, due to subLayerInfoFlag being equal to 0, it is inferred to be equal to max_dec_pic_buffering_minus1[ maxSubLayersMinus1 ].
2583
        pcVPS->m_dpbParameters[i].m_maxDecPicBuffering[j] = pcVPS->m_dpbParameters[i].m_maxDecPicBuffering[pcVPS->m_dpbMaxTemporalId[i]];
2584
2585
        // When max_num_reorder_pics[i] is not present for i in the range of 0 to maxSubLayersMinus1 - 1, inclusive, due to subLayerInfoFlag being equal to 0, it is inferred to be equal to max_num_reorder_pics[ maxSubLayersMinus1 ].
2586
        pcVPS->m_dpbParameters[i].m_numReorderPics[j] = pcVPS->m_dpbParameters[i].m_numReorderPics[pcVPS->m_dpbMaxTemporalId[i]];
2587
2588
        // When max_latency_increase_plus1[i] is not present for i in the range of 0 to maxSubLayersMinus1 - 1, inclusive, due to subLayerInfoFlag being equal to 0, it is inferred to be equal to max_latency_increase_plus1[ maxSubLayersMinus1 ].
2589
        pcVPS->m_dpbParameters[i].m_maxLatencyIncreasePlus1[j] = pcVPS->m_dpbParameters[i].m_maxLatencyIncreasePlus1[pcVPS->m_dpbMaxTemporalId[i]];
2590
      }
2591
    }
2592
2593
    for( int i = 0, j=0; i < pcVPS->getTotalNumOLSs(); i++ )
2594
    {
2595
      if( pcVPS->m_numLayersInOls[i] > 1 )
2596
      {
2597
        READ_UVLC( uiCode, "vps_ols_dpb_pic_width[i]" );                   pcVPS->setOlsDpbPicWidth( i, uiCode );
2598
        READ_UVLC( uiCode, "vps_ols_dpb_pic_height[i]" );                  pcVPS->setOlsDpbPicHeight( i, uiCode );
2599
        READ_CODE( 2, uiCode, "vps_ols_dpb_chroma_format[i]" );            pcVPS->setOlsDpbChromaFormatIdc( i, uiCode );
2600
        READ_UVLC( uiCode, "vps_ols_dpb_bitdepth_minus8[i]" );
2601
        CHECK( uiCode > 2, "bit depths above 10 are not supported" );
2602
        pcVPS->setOlsDpbBitDepthMinus8( i, uiCode );
2603
        const Profile::Name profile = pcVPS->getProfileTierLevel( pcVPS->getOlsPtlIdx( i ) ).getProfileIdc();
2604
        if( profile != Profile::NONE )
2605
        {
2606
          CHECK( uiCode + 8 > ProfileFeatures::getProfileFeatures( profile )->maxBitDepth,
2607
                 "vps_ols_dpb_bitdepth_minus8[ i ] exceeds range supported by signalled profile" );
2608
        }
2609
        if( ( pcVPS->m_numDpbParams > 1 ) && ( pcVPS->m_numDpbParams != pcVPS->m_numMultiLayeredOlss) )
2610
        {
2611
          READ_UVLC( uiCode, "vps_ols_dpb_params_idx[i]" );                pcVPS->setOlsDpbParamsIdx( i, uiCode );
2612
        }
2613
        else if( pcVPS->m_numDpbParams == 1 )
2614
        {
2615
          pcVPS->setOlsDpbParamsIdx( i, 0 );
2616
        }
2617
        else
2618
        {
2619
          pcVPS->setOlsDpbParamsIdx( i, j );
2620
        }
2621
        j += 1;
2622
        isDPBParamReferred[pcVPS->getOlsDpbParamsIdx( i )] = true;
2623
      }
2624
    }
2625
    for( int i = 0; i < pcVPS->m_numDpbParams; i++ )
2626
    {
2627
      CHECK( !isDPBParamReferred[i], "Each dpb_parameters() syntax structure in the VPS shall be referred to by at least one value of vps_ols_dpb_params_idx[i] for i in the range of 0 to NumMultiLayerOlss - 1, inclusive" );
2628
    }
2629
  }
2630
2631
  if( !pcVPS->getEachLayerIsAnOlsFlag() )
2632
  {
2633
    READ_FLAG( uiCode, "vps_general_hrd_params_present_flag" );              pcVPS->setVPSGeneralHrdParamsPresentFlag( uiCode );
2634
  }
2635
  if( pcVPS->getVPSGeneralHrdParamsPresentFlag() )
2636
  {
2637
    parseGeneralHrdParameters( pcVPS->getGeneralHrdParameters() );
2638
    if( ( pcVPS->getMaxSubLayers() - 1 ) > 0 )
2639
    {
2640
      READ_FLAG( uiCode, "vps_sublayer_cpb_params_present_flag" );           pcVPS->setVPSSublayerCpbParamsPresentFlag( uiCode );
2641
    }
2642
    else
2643
    {
2644
      pcVPS->setVPSSublayerCpbParamsPresentFlag( 0 );
2645
    }
2646
2647
    READ_UVLC( uiCode, "vps_num_ols_hrd_params_minus1" );                    pcVPS->setNumOlsHrdParamsMinus1( uiCode );
2648
    CHECK( uiCode >= pcVPS->getNumMultiLayeredOlss(), "The value of vps_num_ols_hrd_params_minus1 shall be in the range of 0 to NumMultiLayerOlss - 1, inclusive" );
2649
    std::vector<bool> isHRDParamReferred( uiCode + 1, false );
2650
    pcVPS->m_olsHrdParams.clear();
2651
    pcVPS->m_olsHrdParams.resize( pcVPS->getNumOlsHrdParamsMinus1() + 1, std::vector<OlsHrdParams>( pcVPS->getMaxSubLayers() ) );
2652
    for( int i = 0; i <= pcVPS->getNumOlsHrdParamsMinus1(); i++ )
2653
    {
2654
      if( !pcVPS->getAllLayersSameNumSublayersFlag() )
2655
      {
2656
        READ_CODE( 3, uiCode, "vps_hrd_max_tid[i]" );                      pcVPS->setHrdMaxTid(i, uiCode );
2657
        CHECK( uiCode > ( pcVPS->getMaxSubLayers() - 1 ), "The value of vps_hrd_max_tid[i] shall be in the range of 0 to vps_max_sublayers_minus1, inclusive." );
2658
      }
2659
      else
2660
      {
2661
        pcVPS->setHrdMaxTid( i, pcVPS->getMaxSubLayers() - 1 );
2662
      }
2663
      uint32_t firstSublayer = pcVPS->getVPSSublayerCpbParamsPresentFlag() ? 0 : pcVPS->getHrdMaxTid( i );
2664
      parseOlsHrdParameters( pcVPS->getGeneralHrdParameters(), pcVPS->getOlsHrdParameters( i ), firstSublayer, pcVPS->getHrdMaxTid( i ) );
2665
    }
2666
    for( int i = pcVPS->getNumOlsHrdParamsMinus1() + 1; i < pcVPS->getTotalNumOLSs(); i++ )
2667
    {
2668
      pcVPS->setHrdMaxTid( i, pcVPS->getMaxSubLayers() - 1 );
2669
    }
2670
    for( int i = 0; i < pcVPS->m_numMultiLayeredOlss; i++ )
2671
    {
2672
      if( ( ( pcVPS->getNumOlsHrdParamsMinus1() + 1 ) != pcVPS->m_numMultiLayeredOlss ) && ( pcVPS->getNumOlsHrdParamsMinus1() > 0 ) )
2673
      {
2674
        READ_UVLC( uiCode, "vps_ols_hrd_idx[i]" );                         pcVPS->setOlsHrdIdx( i, uiCode );
2675
        CHECK( uiCode > pcVPS->getNumOlsHrdParamsMinus1(), "The value of ols_hrd_idx[[i] shall be in the range of 0 to num_ols_hrd_params_minus1, inclusive." );
2676
      }
2677
      else if( pcVPS->getNumOlsHrdParamsMinus1() == 0 )
2678
      {
2679
        pcVPS->setOlsHrdIdx( i, 0 );
2680
      }
2681
      else
2682
      {
2683
        pcVPS->setOlsHrdIdx( i, i );
2684
      }
2685
      isHRDParamReferred[pcVPS->getOlsHrdIdx( i )] = true;
2686
    }
2687
    for( int i = 0; i <= pcVPS->getNumOlsHrdParamsMinus1(); i++ )
2688
    {
2689
      CHECK( !isHRDParamReferred[i], "Each ols_hrd_parameters( ) syntax structure in the VPS shall be referred to by at least one value of vps_ols_hrd_idx[i] for i in the range of 1 to NumMultiLayerOlss - 1, inclusive");
2690
    }
2691
  }
2692
  else
2693
  {
2694
    for( int i = 0; i < pcVPS->getTotalNumOLSs(); i++ )
2695
    {
2696
      pcVPS->setHrdMaxTid( i, pcVPS->getMaxSubLayers() - 1 );
2697
    }
2698
  }
2699
2700
2701
  READ_FLAG( uiCode, "vps_extension_flag" );
2702
  if( uiCode )
2703
  {
2704
    while( xMoreRbspData() )
2705
    {
2706
      READ_FLAG( uiCode, "vps_extension_data_flag" );
2707
    }
2708
  }
2709
  pcVPS->checkVPS();
2710
  xReadRbspTrailingBits();
2711
}
2712
#endif
2713
2714
void HLSyntaxReader::parsePictureHeader( PicHeader* picHeader, ParameterSetManager *parameterSetManager, bool readRbspTrailingBits )
2715
7
{
2716
#if ENABLE_TRACING
2717
  xTracePictureHeader();
2718
#endif
2719
2720
7
  X_READ_FLAG( ph_gdr_or_irap_pic_flag );
2721
7
  picHeader->setGdrOrIrapPicFlag( ph_gdr_or_irap_pic_flag );
2722
2723
7
  X_READ_FLAG( ph_non_ref_pic_flag );
2724
7
  picHeader->setNonReferencePictureFlag( ph_non_ref_pic_flag );
2725
2726
7
  if( picHeader->getGdrOrIrapPicFlag() )
2727
4
  {
2728
4
    X_READ_FLAG( ph_gdr_pic_flag );
2729
4
    picHeader->setGdrPicFlag( ph_gdr_pic_flag );
2730
4
  }
2731
2732
7
  X_READ_FLAG( ph_inter_slice_allowed_flag );
2733
7
  picHeader->setPicInterSliceAllowedFlag( ph_inter_slice_allowed_flag );
2734
2735
7
  if( ph_inter_slice_allowed_flag )
2736
3
  {
2737
3
    X_READ_FLAG( ph_intra_slice_allowed_flag );
2738
3
    picHeader->setPicIntraSliceAllowedFlag( ph_intra_slice_allowed_flag );
2739
3
  }
2740
7
  CHECK( picHeader->getPicInterSliceAllowedFlag() == 0 && picHeader->getPicIntraSliceAllowedFlag() == 0,
2741
7
                     "Invalid picture without intra or inter slice" );
2742
2743
  // parameter sets
2744
7
  X_READ_UVLC( ph_pic_parameter_set_id, 0, 63 );
2745
7
  picHeader->setPPSId( ph_pic_parameter_set_id );
2746
2747
7
  const PPS* pps = parameterSetManager->getPPS( picHeader->getPPSId() );
2748
7
  CHECK( !pps, "Invalid PPS" );
2749
2750
7
  picHeader->setSPSId( pps->getSPSId() );
2751
7
  const SPS* sps = parameterSetManager->getSPS( picHeader->getSPSId() );
2752
7
  CHECK( !sps, "Invalid SPS" );
2753
2754
7
  const unsigned CtbSizeY          = sps->getCTUSize();
2755
7
  const unsigned CtbLog2SizeY      = getLog2( CtbSizeY );
2756
7
  const unsigned MinCbLog2SizeY    = sps->getLog2MinCodingBlockSize();
2757
7
  const unsigned MaxPicOrderCntLsb = 1 << sps->getBitsForPOC();
2758
2759
7
  X_READ_CODE_NO_RANGE( ph_pic_order_cnt_lsb, sps->getBitsForPOC() );
2760
7
  picHeader->setPocLsb( ph_pic_order_cnt_lsb );
2761
2762
7
  if( picHeader->getGdrPicFlag() )
2763
0
  {
2764
0
    X_READ_UVLC( ph_recovery_poc_cnt, 0, MaxPicOrderCntLsb );
2765
0
    picHeader->setRecoveryPocCnt( ph_recovery_poc_cnt );
2766
0
  }
2767
7
  else
2768
7
  {
2769
7
    picHeader->setRecoveryPocCnt( -1 );
2770
7
  }
2771
2772
7
  const std::vector<bool>& phExtraBitsPresent = sps->getExtraPHBitPresentFlags();
2773
7
  for( int i = 0; i < sps->getNumExtraPHBitsBytes() * 8; i++ )
2774
0
  {
2775
    // extra bits are ignored (when present)
2776
0
    if( phExtraBitsPresent[i] )
2777
0
    {
2778
0
      X_READ_FLAG_idx( ph_extra_bit, "[i]" );
2779
0
      (void) ph_extra_bit;
2780
0
    }
2781
0
  }
2782
2783
7
  if( sps->getPocMsbFlag() )
2784
0
  {
2785
0
    X_READ_FLAG( ph_poc_msb_cycle_present_flag );
2786
0
    picHeader->setPocMsbPresentFlag( ph_poc_msb_cycle_present_flag );
2787
2788
0
    if( ph_poc_msb_cycle_present_flag )
2789
0
    {
2790
0
      X_READ_CODE_NO_RANGE( ph_poc_msb_cycle_val, sps->getPocMsbLen() );
2791
0
      picHeader->setPocMsbVal( ph_poc_msb_cycle_val );
2792
0
    }
2793
0
  }
2794
2795
  // alf enable flags and aps IDs
2796
7
  if( sps->getUseALF() && pps->getAlfInfoInPhFlag() )
2797
0
  {
2798
0
    X_READ_FLAG( ph_alf_enabled_flag );
2799
0
    picHeader->setAlfEnabledFlag( COMPONENT_Y, ph_alf_enabled_flag );
2800
2801
0
    if( ph_alf_enabled_flag )
2802
0
    {
2803
0
      X_READ_CODE( ph_num_alf_aps_ids_luma, 3, 0, MAX_NUM_ALF_APS_IDS );
2804
0
      picHeader->setNumAlfAps( ph_num_alf_aps_ids_luma );
2805
2806
      // auto* alfAPSs = parameterSetManager->getAlfAPSs();
2807
2808
0
      AlfApsIdVec apsId( ph_num_alf_aps_ids_luma, -1 );
2809
0
      for( int i = 0; i < ph_num_alf_aps_ids_luma; i++ )
2810
0
      {
2811
0
        X_READ_CODE_NO_RANGE_idx( ph_alf_aps_id_luma, "[i]", 3 );
2812
0
        apsId[i] = ph_alf_aps_id_luma;
2813
2814
        // auto* alfAPS = parameterSetManager->getAPS( ALF_APS, ph_alf_aps_id_luma );
2815
        // CHECK( !alfAPS, "ALF APS with ph_alf_aps_id_luma == " << ph_alf_aps_id_luma << " not available.");
2816
        // CHECK( alfAPS->getAlfAPSParam().newFilterFlag[CHANNEL_TYPE_LUMA] != 1,
2817
        //        "The value of alf_luma_filter_signal_flag of the APS NAL unit having aps_params_type equal to ALF_APS "
2818
        //        " and aps_adaptation_parameter_set_id equal to ph_alf_aps_id_luma[ i ] shall be equal to 1." );
2819
        // /*CHECK( parameterSetManager->getAPS( ALF_APS, ph_alf_aps_id_luma )->getTemporalId() > todo: don't know curr temp ID
2820
        //        "The TemporalId of the APS NAL unit having aps_params_type equal to ALF_APS and aps_adaptation_parameter_set_id"
2821
        //        " equal to ph_alf_aps_id_luma[ i ] shall be less than or equal to the TemporalId of the current picture." );*/
2822
        // CHECK( sps->getChromaFormatIdc() == 0 && alfAPS->chromaPresentFlag != 0,
2823
        //        "When sps_chroma_format_idc is equal to 0, the value of aps_chroma_present_flag of the APS NAL unit having aps_params_type"
2824
        //        " equal to ALF_APS and aps_adaptation_parameter_set_id equal to ph_alf_aps_id_luma[ i ] shall be equal to 0." );
2825
        // CHECK( sps->getUseCCALF() == 0
2826
        //          && ( alfAPS->getCcAlfAPSParam().newCcAlfFilter[COMPONENT_Cb - 1] != 0 || alfAPS->getCcAlfAPSParam().newCcAlfFilter[COMPONENT_Cr - 1] != 0 ),
2827
        //        "When sps_ccalf_enabled_flag is equal to 0, the values of alf_cc_cb_filter_signal_flag and alf_cc_cr_filter_signal_flag of the APS NAL unit "
2828
        //        " having aps_params_type equal to ALF_APS and aps_adaptation_parameter_set_id equal to ph_alf_aps_id_luma[ i ] shall be equal to 0." );
2829
0
      }
2830
0
      picHeader->setAlfAPSIds( apsId );
2831
2832
0
      if( sps->getChromaFormatIdc() != CHROMA_400 )
2833
0
      {
2834
0
        X_READ_FLAG( ph_alf_cb_enabled_flag );
2835
0
        picHeader->setAlfEnabledFlag( COMPONENT_Cb, ph_alf_cb_enabled_flag );
2836
2837
0
        X_READ_FLAG( ph_alf_cr_enabled_flag );
2838
0
        picHeader->setAlfEnabledFlag( COMPONENT_Cr, ph_alf_cr_enabled_flag );
2839
0
      }
2840
2841
0
      if( picHeader->getAlfEnabledFlag( COMPONENT_Cb ) || picHeader->getAlfEnabledFlag( COMPONENT_Cr ) )
2842
0
      {
2843
0
        X_READ_CODE_NO_RANGE( ph_alf_aps_id_chroma, 3 );
2844
0
        picHeader->setAlfApsIdChroma( ph_alf_aps_id_chroma );
2845
2846
        // auto* alfAPS = parameterSetManager->getAPS( ALF_APS, ph_alf_aps_id_chroma );
2847
        // CHECK( !alfAPS, "ALF APS with ph_alf_aps_id_chroma == " << ph_alf_aps_id_chroma << " not available.");
2848
2849
        // CHECK( alfAPS->getCcAlfAPSParam().newCcAlfFilter[CHANNEL_TYPE_CHROMA] != 1,
2850
        //        "The value of alf_chroma_filter_signal_flag of the APS NAL unit having aps_params_type equal to ALF_APS and"
2851
        //        " aps_adaptation_parameter_set_id equal to ph_alf_aps_id_chroma shall be equal to 1." );
2852
        // // The TemporalId of the APS NAL unit having aps_params_type equal to ALF_APS and
2853
        // // aps_adaptation_parameter_set_id equal to ph_alf_aps_id_chroma shall be less than or equal to the TemporalId of the
2854
        // // current picture.
2855
2856
        // CHECK( sps->getUseCCALF() == 0
2857
        //          && ( alfAPS->getCcAlfAPSParam().newCcAlfFilter[COMPONENT_Cb - 1] != 0 || alfAPS->getCcAlfAPSParam().newCcAlfFilter[COMPONENT_Cr - 1] != 0 ),
2858
        //        "When sps_ccalf_enabled_flag is equal to 0, the values of alf_cc_cb_filter_signal_flag and alf_cc_cr_filter_signal_flag of the APS NAL unit "
2859
        //        " having aps_params_type equal to ALF_APS and aps_adaptation_parameter_set_id equal to ph_alf_aps_id_chroma shall be equal to 0." );
2860
0
      }
2861
2862
0
      if( sps->getUseCCALF() )
2863
0
      {
2864
0
        X_READ_FLAG( ph_alf_cc_cb_enabled_flag );
2865
0
        picHeader->setCcAlfEnabledFlag( COMPONENT_Cb, ph_alf_cc_cb_enabled_flag );
2866
2867
0
        if( ph_alf_cc_cb_enabled_flag )
2868
0
        {
2869
0
          X_READ_CODE_NO_RANGE( ph_alf_cc_cb_aps_id, 3 );
2870
0
          picHeader->setCcAlfCbApsId( ph_alf_cc_cb_aps_id );
2871
2872
          // auto* alfAPS = parameterSetManager->getAPS( ALF_APS, ph_alf_cc_cb_aps_id );
2873
          // CHECK( !alfAPS, "ALF APS with ph_alf_cc_cb_aps_id == " << ph_alf_cc_cb_aps_id << " not available.");
2874
          // CHECK( alfAPS->getCcAlfAPSParam().newCcAlfFilter[COMPONENT_Cb - 1] != 1,
2875
          //        "The value of alf_cc_cb_filter_signal_flag of the APS NAL unit having aps_params_type equal to ALF_APS and"
2876
          //        " aps_adaptation_parameter_set_id equal to ph_alf_cc_cb_aps_id shall be equal to 1." );
2877
          // // The TemporalId of the APS NAL unit having aps_params_type equal to ALF_APS and
2878
          // // aps_adaptation_parameter_set_id equal to ph_alf_cc_cb_aps_id shall be less than or equal to the TemporalId of the
2879
          // // current picture.
2880
0
        }
2881
2882
0
        X_READ_FLAG( ph_alf_cc_cr_enabled_flag );
2883
0
        picHeader->setCcAlfEnabledFlag( COMPONENT_Cr, ph_alf_cc_cr_enabled_flag );
2884
2885
0
        if( ph_alf_cc_cr_enabled_flag )
2886
0
        {
2887
0
          X_READ_CODE_NO_RANGE( ph_alf_cc_cr_aps_id, 3 );
2888
0
          picHeader->setCcAlfCrApsId( ph_alf_cc_cr_aps_id );
2889
2890
          // auto* alfAPS = parameterSetManager->getAPS( ALF_APS, ph_alf_cc_cr_aps_id );
2891
          // CHECK( !alfAPS, "ALF APS with ph_alf_cc_cr_aps_id == " << ph_alf_cc_cr_aps_id << " not available." );
2892
          // CHECK( alfAPS->getCcAlfAPSParam().newCcAlfFilter[COMPONENT_Cr - 1] != 1,
2893
          //        "The value of alf_cc_cr_filter_signal_flag of the APS NAL unit having aps_params_type equal to ALF_APS and"
2894
          //        " aps_adaptation_parameter_set_id equal to ph_alf_cc_cr_aps_id shall be equal to 1." );
2895
          // // The TemporalId of the APS NAL unit having aps_params_type equal to ALF_APS and
2896
          // // aps_adaptation_parameter_set_id equal to ph_alf_cc_cr_aps_id shall be less than or equal to the TemporalId of the
2897
          // // current picture.
2898
0
        }
2899
0
      }
2900
0
    }   // if( ph_alf_enabled_flag )
2901
0
  }     // if( sps->getUseALF() && pps->getAlfInfoInPhFlag() )
2902
2903
  // luma mapping / chroma scaling controls
2904
7
  if( sps->getUseReshaper() )
2905
0
  {
2906
0
    X_READ_FLAG( ph_lmcs_enabled_flag );
2907
0
    picHeader->setLmcsEnabledFlag( ph_lmcs_enabled_flag );
2908
2909
0
    if( ph_lmcs_enabled_flag )
2910
0
    {
2911
0
      X_READ_CODE_NO_RANGE( ph_lmcs_aps_id, 2 );
2912
0
      picHeader->setLmcsAPSId( ph_lmcs_aps_id );
2913
2914
0
      if( sps->getChromaFormatIdc() != CHROMA_400 )
2915
0
      {
2916
0
        X_READ_FLAG( ph_chroma_residual_scale_flag );
2917
0
        picHeader->setLmcsChromaResidualScaleFlag( ph_chroma_residual_scale_flag );
2918
0
      }
2919
0
    }
2920
0
  }
2921
2922
  // quantization scaling lists
2923
7
  if( sps->getScalingListFlag() )
2924
0
  {
2925
0
    X_READ_FLAG( ph_explicit_scaling_list_enabled_flag );
2926
0
    picHeader->setExplicitScalingListEnabledFlag( ph_explicit_scaling_list_enabled_flag );
2927
2928
0
    if( ph_explicit_scaling_list_enabled_flag )
2929
0
    {
2930
0
      X_READ_CODE_NO_RANGE( ph_scaling_list_aps_id, 3 );
2931
0
      picHeader->setScalingListAPSId( ph_scaling_list_aps_id );
2932
0
    }
2933
0
  }
2934
2935
  // virtual boundaries
2936
7
  if( sps->getVirtualBoundariesEnabledFlag() && !sps->getVirtualBoundariesPresentFlag() )
2937
0
  {
2938
0
    X_READ_FLAG( ph_virtual_boundaries_present_flag );
2939
0
    picHeader->setVirtualBoundariesPresentFlag( ph_virtual_boundaries_present_flag );
2940
2941
0
    if( ph_virtual_boundaries_present_flag )
2942
0
    {
2943
0
      X_READ_UVLC( ph_num_ver_virtual_boundaries, 0, pps->getPicWidthInLumaSamples() <= 8 ? 0 : 3 );
2944
0
      picHeader->setNumVerVirtualBoundaries( ph_num_ver_virtual_boundaries );
2945
2946
0
      for( unsigned i = 0, prevBoundPos = 0; i < ph_num_ver_virtual_boundaries; i++ )
2947
0
      {
2948
0
        X_READ_UVLC_idx( ph_virtual_boundary_pos_x_minus1, "[ i ]", 0, ( pps->getPicWidthInLumaSamples() + 7 ) / 8 - 2 );
2949
2950
0
        const unsigned virtBoundPosX = ( ph_virtual_boundary_pos_x_minus1 + 1 ) << 3;
2951
0
        CHECK( i > 0 && virtBoundPosX < prevBoundPos + CtbSizeY,
2952
0
               "The distance between any two vertical virtual boundaries shall be greater than or equal to CtbSizeY luma samples." );
2953
0
        picHeader->setVirtualBoundariesPosX( virtBoundPosX, i );
2954
2955
0
        prevBoundPos = virtBoundPosX;
2956
0
      }
2957
2958
0
      X_READ_UVLC( ph_num_hor_virtual_boundaries, 0, pps->getPicHeightInLumaSamples() <= 8 ? 0 : 3 );
2959
0
      picHeader->setNumHorVirtualBoundaries( ph_num_hor_virtual_boundaries );
2960
2961
0
      for( unsigned i = 0, prevBoundPos = 0; i < ph_num_hor_virtual_boundaries; i++ )
2962
0
      {
2963
0
        X_READ_UVLC_idx( ph_virtual_boundary_pos_y_minus1, "[ i ]", 0, ( pps->getPicHeightInLumaSamples() + 7 ) / 8 - 2 );
2964
2965
0
        const unsigned virtBoundPosY = ( ph_virtual_boundary_pos_y_minus1 + 1 ) << 3;
2966
0
        CHECK( i > 0 && virtBoundPosY < prevBoundPos + CtbSizeY,
2967
0
               "The distance between any two horizontal virtual boundaries shall be greater than or equal to CtbSizeY luma samples." );
2968
0
        picHeader->setVirtualBoundariesPosY( virtBoundPosY, i );
2969
2970
0
        prevBoundPos = virtBoundPosY;
2971
0
      }
2972
0
      CHECK( ph_num_ver_virtual_boundaries + ph_num_hor_virtual_boundaries <= 0,
2973
0
             "When sps_virtual_boundaries_enabled_flag is equal to 1 and ph_virtual_boundaries_present_flag is equal to 1, the sum"
2974
0
             " of ph_num_ver_virtual_boundaries and ph_num_hor_virtual_boundaries shall be greater than 0." );
2975
0
    }
2976
0
  }
2977
7
  else if( sps->getVirtualBoundariesPresentFlag() )
2978
0
  {
2979
0
    picHeader->setVirtualBoundariesPresentFlag( true );
2980
0
    picHeader->setNumVerVirtualBoundaries( sps->getNumVerVirtualBoundaries() );
2981
0
    picHeader->setNumHorVirtualBoundaries( sps->getNumHorVirtualBoundaries() );
2982
2983
0
    for( unsigned i = 0, prevBoundPosX = 0, prevBoundPosY = 0; i < 3; i++ )
2984
0
    {
2985
0
      picHeader->setVirtualBoundariesPosX( sps->getVirtualBoundariesPosX( i ), i );
2986
0
      picHeader->setVirtualBoundariesPosY( sps->getVirtualBoundariesPosY( i ), i );
2987
2988
0
      CHECK( i > 0 && i < picHeader->getNumVerVirtualBoundaries() && picHeader->getVirtualBoundariesPosX( i ) < prevBoundPosX + CtbSizeY,
2989
0
             "The distance between any two vertical virtual boundaries shall be greater than or equal to CtbSizeY luma samples." );
2990
0
      CHECK( i > 0 && i < picHeader->getNumHorVirtualBoundaries() && picHeader->getVirtualBoundariesPosY( i ) < prevBoundPosY + CtbSizeY,
2991
0
             "The distance between any two horizontal virtual boundaries shall be greater than or equal to CtbSizeY luma samples." );
2992
2993
0
      prevBoundPosX = picHeader->getVirtualBoundariesPosX( i );
2994
0
      prevBoundPosY = picHeader->getVirtualBoundariesPosY( i );
2995
0
    }
2996
0
  }
2997
2998
  // picture output flag
2999
7
  if( pps->getOutputFlagPresentFlag() && !picHeader->getNonReferencePictureFlag() )
3000
0
  {
3001
0
    X_READ_FLAG( ph_pic_output_flag );
3002
0
    picHeader->setPicOutputFlag( ph_pic_output_flag);
3003
0
  }
3004
3005
  // reference picture lists
3006
7
  if( pps->getRplInfoInPhFlag() )
3007
0
  {
3008
0
    parsePicOrSliceHeaderRPL( picHeader, sps, pps );
3009
0
  }
3010
3011
  // partitioning constraint overrides
3012
7
  if( sps->getSplitConsOverrideEnabledFlag() )
3013
0
  {
3014
0
    X_READ_FLAG( ph_partition_constraints_override_flag );
3015
0
    picHeader->setSplitConsOverrideFlag( ph_partition_constraints_override_flag );
3016
0
  }
3017
3018
  // inherit constraint values from SPS
3019
7
  PartitionConstraints minQT     = sps->getMinQTSizes();
3020
7
  PartitionConstraints maxBTD    = sps->getMaxMTTHierarchyDepths();
3021
7
  PartitionConstraints maxBTSize = sps->getMaxBTSizes();
3022
7
  PartitionConstraints maxTTSize = sps->getMaxTTSizes();
3023
3024
7
  if( picHeader->getPicIntraSliceAllowedFlag() )
3025
0
  {
3026
0
    unsigned MinQtLog2SizeIntraY = getLog2( minQT[0] );
3027
0
    if( picHeader->getSplitConsOverrideFlag() )
3028
0
    {
3029
0
      X_READ_UVLC( ph_log2_diff_min_qt_min_cb_intra_slice_luma, 0, std::min( 6u, CtbLog2SizeY ) - MinCbLog2SizeY );
3030
0
      MinQtLog2SizeIntraY = ph_log2_diff_min_qt_min_cb_intra_slice_luma + MinCbLog2SizeY;
3031
0
      minQT[0] = 1 << MinQtLog2SizeIntraY;
3032
3033
0
      X_READ_UVLC( ph_max_mtt_hierarchy_depth_intra_slice_luma, 0, 2 * ( CtbLog2SizeY - MinCbLog2SizeY ) );
3034
0
      maxBTD[0] = ph_max_mtt_hierarchy_depth_intra_slice_luma;
3035
      // TODO: When not present, the value of ph_max_mtt_hierarchy_depth_intra_slice_luma is inferred to be equal to sps_max_mtt_hierarchy_depth_intra_slice_luma.
3036
3037
0
      maxTTSize[0] = maxBTSize[0] = minQT[0];
3038
0
      if( maxBTD[0] != 0 )
3039
0
      {
3040
0
        X_READ_UVLC( ph_log2_diff_max_bt_min_qt_intra_slice_luma,
3041
0
                     0, ( sps->getUseDualITree() ? std::min( 6u, CtbLog2SizeY ) : CtbLog2SizeY ) - MinQtLog2SizeIntraY );
3042
0
        maxBTSize[0] <<= ph_log2_diff_max_bt_min_qt_intra_slice_luma;
3043
        // TODO: When not present, the value of ph_log2_diff_max_bt_min_qt_intra_slice_luma is inferred to be equal to
3044
        //       sps_log2_diff_max_bt_min_qt_intra_slice_luma.
3045
3046
0
        X_READ_UVLC( ph_log2_diff_max_tt_min_qt_intra_slice_luma, 0, std::min( 6u, CtbLog2SizeY ) - MinQtLog2SizeIntraY );
3047
0
        maxTTSize[0] <<= ph_log2_diff_max_tt_min_qt_intra_slice_luma;
3048
        // TODO: When not present, the value of ph_log2_diff_max_tt_min_qt_intra_slice_luma is inferred to be equal to
3049
        //       sps_log2_diff_max_tt_min_qt_intra_slice_luma.
3050
0
      }
3051
0
      if( sps->getUseDualITree() )
3052
0
      {
3053
0
        X_READ_UVLC( ph_log2_diff_min_qt_min_cb_intra_slice_chroma, 0, std::min( 6u, CtbLog2SizeY ) - MinCbLog2SizeY );
3054
0
        unsigned MinQtLog2SizeIntraC = ph_log2_diff_min_qt_min_cb_intra_slice_chroma + MinCbLog2SizeY;
3055
0
        minQT[2] = 1 << MinQtLog2SizeIntraC;
3056
        // TODO: When not present, the value of ph_log2_diff_min_qt_min_cb_intra_slice_chroma is inferred to be equal to
3057
        //       sps_log2_diff_min_qt_min_cb_intra_slice_chroma.
3058
3059
0
        X_READ_UVLC( ph_max_mtt_hierarchy_depth_intra_slice_chroma, 0, 2 * ( CtbLog2SizeY - MinCbLog2SizeY ) );
3060
0
        maxBTD[2]    = ph_max_mtt_hierarchy_depth_intra_slice_chroma;
3061
        // TODO: When not present, the value of ph_max_mtt_hierarchy_depth_intra_slice_chroma is inferred to be equal to
3062
        //       sps_max_mtt_hierarchy_depth_intra_slice_chroma.
3063
3064
0
        maxTTSize[2] = maxBTSize[2] = minQT[2];
3065
0
        if( ph_max_mtt_hierarchy_depth_intra_slice_chroma )
3066
0
        {
3067
0
          X_READ_UVLC( ph_log2_diff_max_bt_min_qt_intra_slice_chroma, 0, std::min( 6u, CtbLog2SizeY ) - MinQtLog2SizeIntraC );
3068
0
          maxBTSize[2] <<= ph_log2_diff_max_bt_min_qt_intra_slice_chroma;
3069
          // TODO: When not present, the value of ph_log2_diff_max_bt_min_qt_intra_slice_chroma is inferred to be equal to
3070
          //       sps_log2_diff_max_bt_min_qt_intra_slice_chroma.
3071
3072
0
          X_READ_UVLC( ph_log2_diff_max_tt_min_qt_intra_slice_chroma, 0, std::min( 6u, CtbLog2SizeY ) - MinQtLog2SizeIntraC );
3073
0
          maxTTSize[2] <<= ph_log2_diff_max_tt_min_qt_intra_slice_chroma;
3074
          // TODO: When not present, the value of ph_log2_diff_max_tt_min_qt_intra_slice_chroma is inferred to be equal to
3075
          //       sps_log2_diff_max_tt_min_qt_intra_slice_chroma.
3076
0
        }
3077
0
      }   // if( sps->getUseDualITree() )
3078
0
    }     // if( picHeader->getSplitConsOverrideFlag() )
3079
3080
    // delta quantization and chrom and chroma offset
3081
0
    if( pps->getUseDQP() )
3082
0
    {
3083
0
      X_READ_UVLC( ph_cu_qp_delta_subdiv_intra_slice,
3084
0
                   0, 2 * ( CtbLog2SizeY - MinQtLog2SizeIntraY + maxBTD[0] /*ph_max_mtt_hierarchy_depth_intra_slice_luma*/ ) );
3085
0
      picHeader->setCuQpDeltaSubdivIntra( ph_cu_qp_delta_subdiv_intra_slice );
3086
0
    }
3087
3088
0
    if( pps->getCuChromaQpOffsetEnabledFlag() )
3089
0
    {
3090
0
      X_READ_UVLC( ph_cu_chroma_qp_offset_subdiv_intra_slice,
3091
0
                   0, 2 * ( CtbLog2SizeY - MinQtLog2SizeIntraY + maxBTD[0] /*ph_max_mtt_hierarchy_depth_intra_slice_luma*/ ) );
3092
0
      picHeader->setCuChromaQpOffsetSubdivIntra( ph_cu_chroma_qp_offset_subdiv_intra_slice );
3093
0
    }
3094
0
  }   // if( picHeader->getPicIntraSliceAllowedFlag() )
3095
3096
7
  if( ph_inter_slice_allowed_flag )
3097
0
  {
3098
0
    unsigned MinQtLog2SizeInterY = MinCbLog2SizeY;
3099
0
    if( picHeader->getSplitConsOverrideFlag() )
3100
0
    {
3101
0
      X_READ_UVLC( ph_log2_diff_min_qt_min_cb_inter_slice, 0, std::min( 6u, CtbLog2SizeY ) - MinCbLog2SizeY );
3102
0
      MinQtLog2SizeInterY += ph_log2_diff_min_qt_min_cb_inter_slice;
3103
0
      minQT[1] = 1 << MinQtLog2SizeInterY;
3104
3105
0
      X_READ_UVLC( ph_max_mtt_hierarchy_depth_inter_slice, 0, 2 * ( CtbLog2SizeY - MinCbLog2SizeY ) );
3106
0
      maxBTD[1] = ph_max_mtt_hierarchy_depth_inter_slice;
3107
3108
0
      maxTTSize[1] = maxBTSize[1] = minQT[1];
3109
0
      if( maxBTD[1] != 0 )
3110
0
      {
3111
0
        X_READ_UVLC( ph_log2_diff_max_bt_min_qt_inter_slice, 0, CtbLog2SizeY - MinQtLog2SizeInterY );
3112
0
        maxBTSize[1] <<= ph_log2_diff_max_bt_min_qt_inter_slice;
3113
3114
0
        X_READ_UVLC( ph_log2_diff_max_tt_min_qt_inter_slice, 0, std::min( 6u, CtbLog2SizeY ) - MinQtLog2SizeInterY );
3115
0
        maxTTSize[1] <<= ph_log2_diff_max_tt_min_qt_inter_slice;
3116
0
      }
3117
0
    }
3118
3119
    // delta quantization and chrom and chroma offset
3120
0
    if( pps->getUseDQP() )
3121
0
    {
3122
0
      X_READ_UVLC( ph_cu_qp_delta_subdiv_inter_slice, 0, 2 * ( CtbLog2SizeY - MinQtLog2SizeInterY + maxBTD[1] /*ph_max_mtt_hierarchy_depth_inter_slice*/ ) );
3123
0
      picHeader->setCuQpDeltaSubdivInter( ph_cu_qp_delta_subdiv_inter_slice );
3124
0
    }
3125
3126
0
    if( pps->getCuChromaQpOffsetEnabledFlag() )
3127
0
    {
3128
0
      X_READ_UVLC( ph_cu_chroma_qp_offset_subdiv_inter_slice,
3129
0
                   0, 2 * ( CtbLog2SizeY - MinQtLog2SizeInterY + maxBTD[1] /*ph_max_mtt_hierarchy_depth_inter_slice*/ ) );
3130
0
      picHeader->setCuChromaQpOffsetSubdivInter( ph_cu_chroma_qp_offset_subdiv_inter_slice );
3131
0
    }
3132
3133
    // temporal motion vector prediction
3134
0
    if( sps->getSPSTemporalMVPEnabledFlag() )
3135
0
    {
3136
0
      X_READ_FLAG( ph_temporal_mvp_enabled_flag );
3137
0
      picHeader->setEnableTMVPFlag( ph_temporal_mvp_enabled_flag );
3138
3139
0
      if( ph_temporal_mvp_enabled_flag && pps->getRplInfoInPhFlag() )
3140
0
      {
3141
0
        if( picHeader->getRPL( REF_PIC_LIST_1 )->getNumRefEntries() > 0 )
3142
0
        {
3143
0
          X_READ_FLAG( ph_collocated_from_l0_flag );
3144
0
          picHeader->setPicColFromL0Flag( ph_collocated_from_l0_flag );
3145
0
        }
3146
0
        else   // ( num_ref_entries[ 1 ][ RplsIdx[ 1 ] ] == 0 )
3147
0
        {
3148
          // When ph_temporal_mvp_enabled_flag and pps_rpl_info_in_ph_flag are both equal to 1 and num_ref_entries[ 1 ][ RplsIdx[ 1 ] ] is equal to 0, the value
3149
          // of ph_collocated_from_l0_flag is inferred to be equal to 1.
3150
0
          picHeader->setPicColFromL0Flag( 1 );
3151
0
        }
3152
3153
0
        if( ( picHeader->getPicColFromL0Flag() && picHeader->getRPL( REF_PIC_LIST_0 )->getNumRefEntries() > 1 )
3154
0
            || ( !picHeader->getPicColFromL0Flag() && picHeader->getRPL( REF_PIC_LIST_1 )->getNumRefEntries() > 1 ) )
3155
0
        {
3156
0
          X_READ_UVLC_NO_RANGE( ph_collocated_ref_idx );
3157
0
          if( picHeader->getPicColFromL0Flag() )
3158
0
          {
3159
0
            CHECK( ph_collocated_ref_idx > picHeader->getRPL( REF_PIC_LIST_0 )->getNumRefEntries() - 1,
3160
0
                   "When ph_collocated_from_l0_flag is equal to 1, ph_collocated_ref_idx refers to an entry in RPL 0, and the value of ph_collocated_ref_idx"
3161
0
                   " shall be in the range of 0 to num_ref_entries[ 0 ][ RplsIdx[ 0 ] ] − 1, inclusive." )
3162
0
          }
3163
0
          else
3164
0
          {
3165
0
            CHECK( ph_collocated_ref_idx > picHeader->getRPL( REF_PIC_LIST_1 )->getNumRefEntries() - 1,
3166
0
                   "When ph_collocated_from_l0_flag is equal to 0, ph_collocated_ref_idx refers to an entry in RPL 1, and the value of ph_collocated_ref_idx"
3167
0
                   " shall be in the range of 0 to num_ref_entries[ 1 ][ RplsIdx[ 1 ] ] − 1, inclusive." );
3168
0
          }
3169
0
          picHeader->setColRefIdx( ph_collocated_ref_idx );
3170
0
        }
3171
0
      }
3172
0
    }
3173
3174
    // merge candidate list size
3175
    // subblock merge candidate list size
3176
0
    if( sps->getUseAffine() )
3177
0
    {
3178
0
      picHeader->setMaxNumAffineMergeCand( sps->getMaxNumAffineMergeCand() );
3179
0
    }
3180
0
    else
3181
0
    {
3182
0
      picHeader->setMaxNumAffineMergeCand( sps->getSBTMVPEnabledFlag() && picHeader->getEnableTMVPFlag() );
3183
0
    }
3184
3185
    // full-pel MMVD flag
3186
0
    if( sps->getFpelMmvdEnabledFlag() )
3187
0
    {
3188
0
      X_READ_FLAG( ph_fpel_mmvd_enabled_flag );
3189
0
      picHeader->setDisFracMMVD( ph_fpel_mmvd_enabled_flag );
3190
0
    }
3191
3192
0
    bool presenceFlag = 0;
3193
0
    if( !pps->getRplInfoInPhFlag() )   // This condition is intentionally not merged into the next, to avoid possible interpretation of RplsIdx[ i ] not having
3194
0
    {                                  // a specified value.
3195
0
      presenceFlag = 1;
3196
0
    }
3197
0
    else if( picHeader->getRPL( REF_PIC_LIST_1 )->getNumRefEntries() > 0 )
3198
0
    {
3199
0
      presenceFlag = 1;
3200
0
    }
3201
3202
    // If sps_bdof_control_present_in_ph_flag is equal to 0, the value of ph_bdof_disabled_flag is inferred to be equal to 1 - sps_bdof_enabled_flag
3203
    // Otherwise (sps_bdof_control_present_in_ph_flag is equal to 1), the value of ph_bdof_disabled_flag is inferred to be  equal to 1.
3204
0
    picHeader->setDisBdofFlag( sps->getBdofControlPresentInPhFlag() == 0 ? 1 - sps->getUseBIO() : 1 );
3205
3206
    // If sps_dmvr_control_present_in_ph_flag is equal to 0, the value of ph_dmvr_disabled_flag is inferred to be equal to 1 - sps_dmvr_enabled_flag.
3207
    // Otherwise (sps_dmvr_control_present_in_ph_flag is equal to 1), the value of ph_dmvr_disabled_flag is inferred to be equal to 1.
3208
0
    picHeader->setDisDmvrFlag( sps->getDmvrControlPresentInPhFlag() == 0 ? 1 - sps->getUseDMVR() : 1 );
3209
3210
0
    if( presenceFlag )
3211
0
    {
3212
      // mvd L1 zero flag
3213
0
      X_READ_FLAG( ph_mvd_l1_zero_flag );
3214
0
      picHeader->setMvdL1ZeroFlag( ph_mvd_l1_zero_flag );
3215
3216
      // picture level BDOF disable flags
3217
0
      if( sps->getBdofControlPresentInPhFlag() )
3218
0
      {
3219
0
        X_READ_FLAG( ph_bdof_disabled_flag );
3220
0
        picHeader->setDisBdofFlag( ph_bdof_disabled_flag );
3221
0
      }
3222
3223
      // picture level DMVR disable flags
3224
0
      if( sps->getDmvrControlPresentInPhFlag() )
3225
0
      {
3226
0
        X_READ_FLAG( ph_dmvr_disabled_flag );
3227
0
        picHeader->setDisDmvrFlag( ph_dmvr_disabled_flag );
3228
0
      }
3229
0
    }
3230
3231
    // picture level PROF disable flags
3232
0
    if( sps->getProfControlPresentInPhFlag() )
3233
0
    {
3234
0
      X_READ_FLAG( ph_prof_disabled_flag );
3235
0
      picHeader->setDisProfFlag( ph_prof_disabled_flag );
3236
0
    }
3237
0
    else
3238
0
    {
3239
      // If sps_affine_prof_enabled_flag is equal to 1, the value of ph_prof_disabled_flag is inferred to be equal to 0.
3240
      // Otherwise (sps_affine_prof_enabled_flag is equal to 0), the value of ph_prof_disabled_flag is inferred to be equal to 1.
3241
3242
0
      picHeader->setDisProfFlag( !sps->getUsePROF() );
3243
0
    }
3244
3245
0
    if( ( pps->getUseWP() || pps->getWPBiPred() ) && pps->getWpInfoInPhFlag() )
3246
0
    {
3247
0
      parsePredWeightTable( picHeader, sps, pps );
3248
0
    }
3249
0
  }   // if( ph_inter_slice_allowed_flag )
3250
3251
7
  picHeader->setMinQTSizes( minQT );
3252
7
  picHeader->setMaxMTTHierarchyDepths( maxBTD );
3253
7
  picHeader->setMaxBTSizes( maxBTSize );
3254
7
  picHeader->setMaxTTSizes( maxTTSize );
3255
3256
  // ibc merge candidate list size
3257
7
  if( pps->getQpDeltaInfoInPhFlag() )
3258
0
  {
3259
0
   X_READ_SVLC_NO_RANGE( ph_qp_delta );
3260
0
   int SliceQpY = 26 + pps->getPicInitQPMinus26() + ph_qp_delta;
3261
0
   CHECK( SliceQpY < -sps->getQpBDOffset() || SliceQpY > 63, "The value of SliceQpY shall be in the range of −QpBdOffset to +63, inclusive." );
3262
0
   picHeader->setQpDelta( ph_qp_delta );
3263
0
  }
3264
3265
  // joint Cb/Cr sign flag
3266
7
  if( sps->getJointCbCrEnabledFlag() )
3267
0
  {
3268
0
    X_READ_FLAG( ph_joint_cbcr_sign_flag );
3269
0
    picHeader->setJointCbCrSignFlag( ph_joint_cbcr_sign_flag );
3270
0
  }
3271
3272
  // sao enable flags
3273
7
  if( sps->getUseSAO() && pps->getSaoInfoInPhFlag() )
3274
0
  {
3275
0
    X_READ_FLAG( ph_sao_luma_enabled_flag );
3276
0
    picHeader->setSaoEnabledFlag( CHANNEL_TYPE_LUMA, ph_sao_luma_enabled_flag );
3277
3278
0
    if( sps->getChromaFormatIdc() != CHROMA_400 )
3279
0
    {
3280
0
      X_READ_FLAG( ph_sao_chroma_enabled_flag );
3281
0
      picHeader->setSaoEnabledFlag( CHANNEL_TYPE_CHROMA, ph_sao_chroma_enabled_flag );
3282
0
    }
3283
0
  }
3284
3285
  // deblocking filter controls
3286
3287
7
  if( pps->getDbfInfoInPhFlag() )
3288
0
  {
3289
0
    X_READ_FLAG( ph_deblocking_params_present_flag );
3290
0
    picHeader->setDeblockingFilterOverrideFlag( ph_deblocking_params_present_flag );
3291
0
  }
3292
3293
7
  if( pps->getPPSDeblockingFilterDisabledFlag() == 1 && picHeader->getDeblockingFilterOverrideFlag() == 1 )
3294
0
  {
3295
    // If pps_deblocking_filter_disabled_flag and ph_deblocking_params_present_flag are both equal to 1, the value of ph_deblocking_filter_disabled_flag
3296
    // is inferred to be equal to 0.
3297
0
    picHeader->setDeblockingFilterDisable( false );
3298
0
  }
3299
7
  else // ( pps->getPPSDeblockingFilterDisabledFlag() == 0 || picHeader->getDeblockingFilterOverrideFlag() == 0 )
3300
7
  {
3301
    // Otherwise (pps_deblocking_filter_disabled_flag or ph_deblocking_params_present_flag is equal to 0), the value of ph_deblocking_filter_disabled_flag is
3302
    // inferred to be equal to pps_deblocking_filter_disabled_flag.
3303
7
    picHeader->setDeblockingFilterDisable( pps->getPPSDeblockingFilterDisabledFlag() );
3304
7
  }
3305
3306
  // When not present, the values of ph_luma_beta_offset_div2 and ph_luma_tc_offset_div2 are inferred to be equal to pps_luma_beta_offset_div2 and
3307
  // pps_luma_tc_offset_div2, respectively.
3308
7
  picHeader->setDeblockingFilterBetaOffsetDiv2( pps->getDeblockingFilterBetaOffsetDiv2() );
3309
7
  picHeader->setDeblockingFilterTcOffsetDiv2( pps->getDeblockingFilterTcOffsetDiv2() );
3310
3311
7
  if( picHeader->getDeblockingFilterOverrideFlag() /*ph_deblocking_params_present_flag*/ )
3312
0
  {
3313
0
    if( !pps->getPPSDeblockingFilterDisabledFlag() )
3314
0
    {
3315
0
      X_READ_FLAG( ph_deblocking_filter_disabled_flag );
3316
0
      picHeader->setDeblockingFilterDisable( ph_deblocking_filter_disabled_flag );
3317
0
    }
3318
3319
0
    if( !picHeader->getDeblockingFilterDisable() )
3320
0
    {
3321
0
      X_READ_SVLC( ph_luma_beta_offset_div2, -12, 12 );
3322
0
      picHeader->setDeblockingFilterBetaOffsetDiv2( ph_luma_beta_offset_div2 );
3323
3324
0
      X_READ_SVLC( ph_luma_tc_offset_div2, -12, 12 );
3325
0
      picHeader->setDeblockingFilterTcOffsetDiv2( ph_luma_tc_offset_div2 );
3326
0
    }
3327
0
  }
3328
3329
7
  if( picHeader->getDeblockingFilterOverrideFlag() /*ph_deblocking_params_present_flag*/
3330
0
      && !picHeader->getDeblockingFilterDisable() && pps->getPPSChromaToolFlag() )
3331
0
  {
3332
0
    X_READ_SVLC( ph_cb_beta_offset_div2, -12, 12 );
3333
0
    picHeader->setDeblockingFilterCbBetaOffsetDiv2( ph_cb_beta_offset_div2 );
3334
3335
0
    X_READ_SVLC( ph_cb_tc_offset_div2, -12, 12 );
3336
0
    picHeader->setDeblockingFilterCbTcOffsetDiv2( ph_cb_tc_offset_div2 );
3337
3338
0
    X_READ_SVLC( ph_cr_beta_offset_div2, -12, 12 );
3339
0
    picHeader->setDeblockingFilterCrBetaOffsetDiv2( ph_cr_beta_offset_div2 );
3340
3341
0
    X_READ_SVLC( ph_cr_tc_offset_div2, -12, 12 );
3342
0
    picHeader->setDeblockingFilterCrTcOffsetDiv2( ph_cr_tc_offset_div2 );
3343
0
  }
3344
7
  else
3345
7
  {
3346
    // When not present, the values of ph_cb_beta_offset_div2 and ph_cb_tc_offset_div2 are inferred as follows:
3347
    // If pps_chroma_tool_offsets_present_flag is equal to 1, the values of ph_cb_beta_offset_div2 and ph_cb_tc_offset_div2 are inferred to be equal to
3348
    // pps_cb_beta_offset_div2 and pps_cb_tc_offset_div2, respectively.
3349
    // Otherwise (pps_chroma_tool_offsets_present_flag is equal to 0), the values of ph_cb_beta_offset_div2 and ph_cb_tc_offset_div2 are inferred to be equal
3350
    // to ph_luma_beta_offset_div2 and ph_luma_tc_offset_div2, respectively.
3351
7
    picHeader->setDeblockingFilterCbBetaOffsetDiv2( pps->getPPSChromaToolFlag() ? pps->getDeblockingFilterCbBetaOffsetDiv2()
3352
7
                                                                                : picHeader->getDeblockingFilterBetaOffsetDiv2() );
3353
7
    picHeader->setDeblockingFilterCbTcOffsetDiv2( pps->getPPSChromaToolFlag() ? pps->getDeblockingFilterCbTcOffsetDiv2()
3354
7
                                                                              : picHeader->getDeblockingFilterTcOffsetDiv2() );
3355
3356
    // When not present, the values of ph_cr_beta_offset_div2 and ph_cr_tc_offset_div2 are inferred as follows:
3357
    // If pps_chroma_tool_offsets_present_flag is equal to 1, the values of ph_cr_beta_offset_div2 and ph_cr_tc_offset_div2 are inferred to be equal to
3358
    // pps_cr_beta_offset_div2 and pps_cr_tc_offset_div2, respectively.
3359
    // Otherwise (pps_chroma_tool_offsets_present_flag is equal to 0), the values of ph_cr_beta_offset_div2 and ph_cr_tc_offset_div2 are inferred to be equal
3360
    // to ph_luma_beta_offset_div2 and ph_luma_tc_offset_div2, respectively.
3361
7
    picHeader->setDeblockingFilterCrBetaOffsetDiv2( pps->getPPSChromaToolFlag() ? pps->getDeblockingFilterCrBetaOffsetDiv2()
3362
7
                                                                                : picHeader->getDeblockingFilterBetaOffsetDiv2() );
3363
7
    picHeader->setDeblockingFilterCrTcOffsetDiv2( pps->getPPSChromaToolFlag() ? pps->getDeblockingFilterCrTcOffsetDiv2()
3364
7
                                                                              : picHeader->getDeblockingFilterTcOffsetDiv2() );
3365
7
  }
3366
3367
  // picture header extension
3368
7
  if( pps->getPictureHeaderExtensionPresentFlag() )
3369
0
  {
3370
0
    X_READ_UVLC( ph_extension_length, 0, 256 );
3371
0
    for( unsigned i = 0; i < ph_extension_length; i++ )
3372
0
    {
3373
0
      X_READ_CODE_NO_RANGE_idx( ph_extension_data_byte, "[i]", 8 );
3374
0
      (void) ph_extension_data_byte;
3375
0
    }
3376
0
  }
3377
3378
7
  if( readRbspTrailingBits )
3379
0
  {
3380
0
    xReadRbspTrailingBits();
3381
0
  }
3382
7
  picHeader->setValid();
3383
7
}
3384
3385
void HLSyntaxReader::checkAlfNaluTidAndPicTid( const Slice* pcSlice, const PicHeader* picHeader, ParameterSetManager *parameterSetManager )
3386
0
{
3387
0
  const SPS* sps = parameterSetManager->getSPS(picHeader->getSPSId());
3388
0
  const PPS* pps = parameterSetManager->getPPS(picHeader->getPPSId());
3389
3390
0
  int  curPicTid = pcSlice->getTLayer();
3391
0
  const APS* aps = nullptr;
3392
3393
0
  if( sps->getUseALF() && pps->getAlfInfoInPhFlag() && picHeader->getAlfEnabledFlag( COMPONENT_Y ) )
3394
0
  {
3395
0
    const auto& apsIds = picHeader->getAlfAPSIds();
3396
    //luma
3397
0
    for( int i = 0; i < picHeader->getNumAlfAps(); i++ )
3398
0
    {
3399
0
      aps = parameterSetManager->getAPS( apsIds[i], ALF_APS );
3400
0
      CHECK( aps->getTemporalId() > curPicTid, "The TemporalId of the APS NAL unit having aps_params_type equal to ALF_APS and adaptation_parameter_set_id equal to ph_alf_aps_id_luma[i] shall be less than or equal to the TemporalId of the picture associated with the PH." );
3401
0
      if( pcSlice->getNalUnitLayerId() != aps->getLayerId() )
3402
0
      {
3403
0
        CHECK( aps->getLayerId() > pcSlice->getNalUnitLayerId(), "Layer Id of APS cannot be greater than layer Id of VCL NAL unit the refer to it" );
3404
0
        CHECK( sps->getVPSId() == 0, "VPSId of the referred SPS cannot be 0 when layer Id of APS and layer Id of current slice are different" );
3405
0
        const VPS* vps = parameterSetManager->getVPS( sps->getVPSId() );
3406
0
        for( int i = 0; i < vps->getNumOutputLayerSets(); i++ )
3407
0
        {
3408
0
          bool isCurrLayerInOls = false;
3409
0
          bool isRefLayerInOls = false;
3410
0
          for( int j = vps->getNumLayersInOls(i) - 1; j >= 0; j-- )
3411
0
          {
3412
0
            if( vps->getLayerIdInOls(i, j) == pcSlice->getNalUnitLayerId() )
3413
0
            {
3414
0
              isCurrLayerInOls = true;
3415
0
            }
3416
0
            if( vps->getLayerIdInOls(i, j) == aps->getLayerId() )
3417
0
            {
3418
0
              isRefLayerInOls = true;
3419
0
            }
3420
0
          }
3421
0
          CHECK( isCurrLayerInOls && !isRefLayerInOls, "When VCL NAl unit in layer A refers to APS in layer B, all OLS that contains layer A shall also contains layer B" );
3422
0
        }
3423
0
      }
3424
0
    }
3425
    //chroma
3426
0
    if( picHeader->getAlfEnabledFlag(COMPONENT_Cb) || picHeader->getAlfEnabledFlag( COMPONENT_Cr ) )
3427
0
    {
3428
0
      int chromaAlfApsId = picHeader->getAlfApsIdChroma();
3429
0
      aps = parameterSetManager->getAPS( chromaAlfApsId, ALF_APS );
3430
0
      CHECK( aps->getTemporalId() > curPicTid, "The TemporalId of the APS NAL unit having aps_params_type equal to ALF_APS and adaptation_parameter_set_id equal to ph_alf_aps_id_chroma shall be less than or equal to the TemporalId of the picture associated with the PH.") ;
3431
0
      if( pcSlice->getNalUnitLayerId() != aps->getLayerId() )
3432
0
      {
3433
0
        CHECK( aps->getLayerId() > pcSlice->getNalUnitLayerId(), "Layer Id of APS cannot be greater than layer Id of VCL NAL unit the refer to it" );
3434
0
        CHECK( sps->getVPSId() == 0, "VPSId of the referred SPS cannot be 0 when layer Id of APS and layer Id of current slice are different" );
3435
0
        const VPS* vps = parameterSetManager->getVPS( sps->getVPSId() );
3436
0
        for( int i = 0; i < vps->getNumOutputLayerSets(); i++ )
3437
0
        {
3438
0
          bool isCurrLayerInOls = false;
3439
0
          bool isRefLayerInOls = false;
3440
0
          for( int j = vps->getNumLayersInOls(i) - 1; j >= 0; j-- )
3441
0
          {
3442
0
            if( vps->getLayerIdInOls( i, j ) == pcSlice->getNalUnitLayerId() )
3443
0
            {
3444
0
              isCurrLayerInOls = true;
3445
0
            }
3446
0
            if( vps->getLayerIdInOls(i, j) == aps->getLayerId() )
3447
0
            {
3448
0
              isRefLayerInOls = true;
3449
0
            }
3450
0
          }
3451
0
          CHECK( isCurrLayerInOls && !isRefLayerInOls, "When VCL NAl unit in layer A refers to APS in layer B, all OLS that contains layer A shall also contains layer B" );
3452
0
        }
3453
0
      }
3454
0
    }
3455
0
  }
3456
0
}
3457
3458
void HLSyntaxReader::parseSliceHeader( Slice*                      pcSlice,
3459
                                       std::shared_ptr<PicHeader>& picHeader,
3460
                                       ParameterSetManager*        parameterSetManager,
3461
                                       const int                   prevTid0POC,
3462
                                       bool&                       firstSliceInPic )
3463
18
{
3464
#if ENABLE_TRACING
3465
  xTraceSliceHeader();
3466
#endif
3467
3468
18
  X_READ_FLAG( sh_picture_header_in_slice_header_flag );
3469
18
  pcSlice->setPictureHeaderInSliceHeader( sh_picture_header_in_slice_header_flag );
3470
3471
18
  if( sh_picture_header_in_slice_header_flag )
3472
5
  {
3473
5
    picHeader.reset( new PicHeader );
3474
5
    parsePictureHeader( picHeader.get(), parameterSetManager, false );
3475
5
  }
3476
18
  CHECK( !picHeader || !picHeader->isValid(), "Picture Header missing" );
3477
3478
9
  checkAlfNaluTidAndPicTid( pcSlice, picHeader.get(), parameterSetManager );
3479
3480
9
  const PPS* pps = parameterSetManager->getPPS( picHeader->getPPSId() );
3481
9
  CHECK( pps == 0, "Invalid PPS" );
3482
9
  const SPS* sps = parameterSetManager->getSPS( pps->getSPSId() );
3483
9
  CHECK( sps == 0, "Invalid SPS" );
3484
3485
9
  auto gci = sps->getProfileTierLevel()->getConstraintInfo();
3486
9
  CHECK_CONSTRAINT( gci->getPicHeaderInSliceHeaderConstraintFlag() && !sh_picture_header_in_slice_header_flag,
3487
9
                    "PH shall be present in SH, when pic_header_in_slice_header_constraint_flag is equal to 1" );
3488
3489
9
  if( sh_picture_header_in_slice_header_flag )
3490
0
  {
3491
0
    CHECK( pps->getRplInfoInPhFlag() == 1, "When sh_picture_header_in_slice_header_flag is equal to 1, rpl_info_in_ph_flag shall be equal to 0" );
3492
0
    CHECK( pps->getDbfInfoInPhFlag() == 1, "When sh_picture_header_in_slice_header_flag is equal to 1, dbf_info_in_ph_flag shall be equal to 0" );
3493
0
    CHECK( pps->getSaoInfoInPhFlag() == 1, "When sh_picture_header_in_slice_header_flag is equal to 1, sao_info_in_ph_flag shall be equal to 0" );
3494
0
    CHECK( pps->getAlfInfoInPhFlag() == 1, "When sh_picture_header_in_slice_header_flag is equal to 1, alf_info_in_ph_flag shall be equal to 0" );
3495
0
    CHECK( pps->getWpInfoInPhFlag() == 1, "When sh_picture_header_in_slice_header_flag is equal to 1, wp_info_in_ph_flag shall be equal to 0" );
3496
0
    CHECK( pps->getQpDeltaInfoInPhFlag() == 1,
3497
0
                       "When sh_picture_header_in_slice_header_flag is equal to 1, qp_delta_info_in_ph_flag shall be equal to 0" );
3498
0
    CHECK( sps->getSubPicInfoPresentFlag() == 1,
3499
0
                       "When sps_subpic_info_present_flag is equal to 1, the value of sh_picture_header_in_slice_header_flag shall be equal to 0" );
3500
0
  }
3501
9
  CHECK( sps->getSubPicInfoPresentFlag() == 1 && sps->getVirtualBoundariesEnabledFlag() == 1 && sps->getVirtualBoundariesPresentFlag() == 0,
3502
9
                     "when sps_subpic_info_present_flag is equal to 1 and sps_virtual_boundaries_enabled_flag is equal to 1, "
3503
9
                     "sps_virtual_boundaries_present_flag shall be equal 1" );
3504
3505
3506
9
  const bool bChroma = sps->getChromaFormatIdc() != CHROMA_400;
3507
3508
  // picture order count
3509
9
  const int iPOClsb    = picHeader->getPocLsb();
3510
9
  const int iMaxPOClsb = 1 << sps->getBitsForPOC();
3511
9
  int64_t   iPOCmsb;   // 64 bit, because ph_poc_msb_cycle_val * MaxPicOrderCntLsb can exceed 32 bit
3512
9
  if( pcSlice->getIdrPicFlag() )
3513
0
  {
3514
0
    if( picHeader->getPocMsbPresentFlag() )
3515
0
    {
3516
0
      iPOCmsb = (int64_t) picHeader->getPocMsbVal() * iMaxPOClsb;
3517
0
    }
3518
0
    else
3519
0
    {
3520
0
      iPOCmsb = 0;
3521
0
    }
3522
0
  }
3523
9
  else
3524
9
  {
3525
9
    const int iPrevPOC    = prevTid0POC;
3526
9
    const int iPrevPOClsb = iPrevPOC & ( iMaxPOClsb - 1 );
3527
9
    const int iPrevPOCmsb = iPrevPOC - iPrevPOClsb;
3528
9
    if( picHeader->getPocMsbPresentFlag() )
3529
0
    {
3530
0
      iPOCmsb = (int64_t) picHeader->getPocMsbVal() * iMaxPOClsb;
3531
0
    }
3532
9
    else
3533
9
    {
3534
9
      if( ( iPOClsb < iPrevPOClsb ) && ( ( iPrevPOClsb - iPOClsb ) >= ( iMaxPOClsb / 2 ) ) )
3535
0
      {
3536
0
        iPOCmsb = iPrevPOCmsb + iMaxPOClsb;
3537
0
      }
3538
9
      else if( ( iPOClsb > iPrevPOClsb ) && ( ( iPOClsb - iPrevPOClsb ) > ( iMaxPOClsb / 2 ) ) )
3539
0
      {
3540
0
        iPOCmsb = iPrevPOCmsb - iMaxPOClsb;
3541
0
      }
3542
9
      else
3543
9
      {
3544
9
        iPOCmsb = iPrevPOCmsb;
3545
9
      }
3546
9
    }
3547
9
  }
3548
3549
9
  const int64_t poc = iPOCmsb + iPOClsb;
3550
9
  CHECK( poc < std::numeric_limits<int>::min() || poc > std::numeric_limits<int>::max(),
3551
9
         "The value of PicOrderCntVal shall be in the range of -2^31 to 2^31 - 1, inclusive" );
3552
9
  pcSlice->setPOC( (int) poc );
3553
3554
9
  if( sps->getSubPicInfoPresentFlag() )
3555
0
  {
3556
0
    X_READ_CODE_NO_RANGE( sh_subpic_id, sps->getSubPicIdLen() );
3557
0
    pcSlice->setSliceSubPicId( sh_subpic_id );
3558
0
  }
3559
3560
9
  const unsigned NumTilesInPic = pps->getNumTiles();
3561
3562
9
  uint32_t sliceAddr = 0;
3563
9
  if( !pps->getRectSliceFlag() )   // raster scan slices
3564
0
  {
3565
0
    if( NumTilesInPic > 1 )
3566
0
    {
3567
      // slice address is the raster scan tile index of first tile in slice
3568
0
      const int bitsSliceAddress = (int) std::ceil( std::log2( NumTilesInPic ) );
3569
0
      X_READ_CODE( sh_slice_address, bitsSliceAddress, 0, NumTilesInPic - 1 );
3570
0
      sliceAddr = sh_slice_address;
3571
0
    }
3572
0
  }
3573
9
  else   // rectangular slices
3574
9
  {
3575
    // slice address is the index of the slice within the current sub-picture
3576
9
    const uint32_t currSubPicIdx         = pps->getSubPicIdxFromSubPicId( pcSlice->getSliceSubPicId() );
3577
9
    const SubPic&  currSubPic            = pps->getSubPic( currSubPicIdx );
3578
9
    const unsigned NumSlicesInCurrSubpic = currSubPic.getNumSlicesInSubPic();
3579
9
    if( NumSlicesInCurrSubpic > 1 )
3580
0
    {
3581
0
      const int bitsSliceAddress = (int) std::ceil( std::log2( NumSlicesInCurrSubpic ) );
3582
0
      X_READ_CODE( sh_slice_address, bitsSliceAddress, 0, NumSlicesInCurrSubpic - 1 );
3583
0
      sliceAddr = sh_slice_address;
3584
0
    }
3585
9
  }
3586
3587
9
  const std::vector<bool>& shExtraBitsPresent = sps->getExtraSHBitPresentFlags();
3588
9
  for( int i = 0; i < sps->getNumExtraSHBitsBytes() * 8; i++ )
3589
0
  {
3590
    // extra bits are ignored (when present)
3591
0
    if( shExtraBitsPresent[i] )
3592
0
    {
3593
0
      X_READ_FLAG_idx( sh_extra_bit, "[i]" );
3594
0
      (void) sh_extra_bit;
3595
0
    }
3596
0
  }
3597
3598
9
  uint32_t numTilesInSlice = 1;
3599
9
  if( !pps->getRectSliceFlag() && (int) NumTilesInPic - (int) sliceAddr > 1 )
3600
0
  {
3601
0
    X_READ_UVLC( sh_num_tiles_in_slice_minus1, 0, NumTilesInPic - 1 );
3602
0
    CHECK_CONSTRAINT( gci->getOneSlicePerPicConstraintFlag() && sh_num_tiles_in_slice_minus1 != NumTilesInPic - 1,
3603
0
                      "When rect_slice_flag is equal to 0 and one_slice_per_pic_constraint_flag equal to 1, the value of num_tiles_in_slice_minus1 present in"
3604
0
                      " each slice header shall be equal to NumTilesInPic - 1" );
3605
0
    numTilesInSlice = sh_num_tiles_in_slice_minus1 + 1;
3606
0
  }
3607
3608
9
  if( !pps->getRectSliceFlag() )
3609
0
  {
3610
0
    CHECK( sliceAddr >= pps->getNumTiles(), "Invalid slice address" );
3611
3612
0
    pcSlice->resetSliceMap();
3613
0
    pcSlice->setSliceID( sliceAddr );
3614
3615
    // NumCtusInCurrSlice = 0;
3616
0
    for( uint32_t tileIdx = sliceAddr; tileIdx < sliceAddr + numTilesInSlice; tileIdx++ )
3617
0
    {
3618
0
      uint32_t tileX = tileIdx % pps->getNumTileColumns();
3619
0
      uint32_t tileY = tileIdx / pps->getNumTileColumns();
3620
0
      CHECK( tileY >= pps->getNumTileRows(), "Number of tiles in slice exceeds the remaining number of tiles in picture" );
3621
3622
0
      pcSlice->addCtusToSlice( pps->getTileColumnBd( tileX ), pps->getTileColumnBd( tileX + 1 ),
3623
0
                               pps->getTileRowBd( tileY ), pps->getTileRowBd( tileY + 1 ), pps->getPicWidthInCtu() );
3624
0
    }
3625
0
  }
3626
9
  else
3627
9
  {
3628
9
    uint32_t       picLevelSliceIdx = sliceAddr;
3629
9
    const uint32_t currSubPicIdx    = pps->getSubPicIdxFromSubPicId( pcSlice->getSliceSubPicId() );
3630
9
    for( int subpic = 0; subpic < currSubPicIdx; subpic++ )
3631
0
    {
3632
0
      picLevelSliceIdx += pps->getSubPic( subpic ).getNumSlicesInSubPic();
3633
0
    }
3634
9
    pcSlice->setSliceMap( pps->getSliceMap( picLevelSliceIdx ) );
3635
9
    pcSlice->setSliceID( picLevelSliceIdx );
3636
9
  }
3637
3638
9
  if( firstSliceInPic != ( pcSlice->getCtuAddrInSlice( 0 ) == 0 ) )
3639
0
  {
3640
    // exit early, because we need to start again with some fields copied from previous slice
3641
0
    firstSliceInPic = false;
3642
0
    return;
3643
0
  }
3644
3645
9
  if( picHeader->getPicInterSliceAllowedFlag() )
3646
0
  {
3647
0
    X_READ_UVLC( sh_slice_type, 0, 2 );
3648
0
    pcSlice->setSliceType( (SliceType) sh_slice_type );
3649
0
  }
3650
9
  else
3651
9
  {
3652
9
    pcSlice->setSliceType( I_SLICE );
3653
9
  }
3654
3655
9
  CHECK( !picHeader->getPicIntraSliceAllowedFlag() && pcSlice->getSliceType() != B_SLICE && pcSlice->getSliceType() != P_SLICE,
3656
9
                     "When ph_intra_slice_allowed_flag is equal to 0, the value of sh_slice_type shall be equal to 0 or 1." );
3657
3658
9
  if( pcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_W_RADL
3659
0
      || pcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_N_LP
3660
0
      || pcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_CRA
3661
0
      || pcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_GDR )
3662
0
  {
3663
0
    X_READ_FLAG( sh_no_output_of_prior_pics_flag );
3664
0
    pcSlice->setNoOutputOfPriorPicsFlag( sh_no_output_of_prior_pics_flag );
3665
0
  }
3666
3667
  // inherit values from picture header
3668
  //   set default values in case slice overrides are disabled
3669
9
  pcSlice->inheritFromPicHeader( picHeader.get(), pps, sps );
3670
3671
9
  if( sps->getUseALF() && !pps->getAlfInfoInPhFlag() )
3672
0
  {
3673
0
    X_READ_FLAG( sh_alf_enabled_flag );
3674
0
    pcSlice->setAlfEnabledFlag( COMPONENT_Y, sh_alf_enabled_flag );
3675
3676
0
    if( sh_alf_enabled_flag )
3677
0
    {
3678
0
      X_READ_CODE_NO_RANGE( sh_num_alf_aps_ids_luma, 3 );
3679
0
      pcSlice->setNumAlfAps( sh_num_alf_aps_ids_luma );
3680
3681
0
      AlfApsIdVec apsId( sh_num_alf_aps_ids_luma, -1 );
3682
0
      for( int i = 0; i < sh_num_alf_aps_ids_luma; i++ )
3683
0
      {
3684
0
        X_READ_CODE_NO_RANGE_idx( sh_alf_aps_id_luma, "[i]", 3 );
3685
0
        apsId[i] = sh_alf_aps_id_luma;
3686
3687
0
        const APS* APStoCheckLuma = parameterSetManager->getAPS( apsId[i], ALF_APS );
3688
0
        CHECK( APStoCheckLuma == nullptr, "referenced APS not found" );
3689
0
        CHECK( APStoCheckLuma->getAlfAPSParam().newFilterFlag[CHANNEL_TYPE_LUMA] != 1,
3690
0
                           "The value of alf_luma_filter_signal_flag of the APS NAL unit having aps_params_type equal to ALF_APS and"
3691
0
                           " aps_adaptation_parameter_set_id equal to sh_alf_aps_id_luma[ i ] shall be equal to 1." );
3692
0
      }
3693
0
      pcSlice->setAlfApsIdsLuma( apsId );
3694
3695
0
      if( bChroma )
3696
0
      {
3697
0
        X_READ_FLAG( sh_alf_cb_enabled_flag );
3698
0
        pcSlice->setAlfEnabledFlag( COMPONENT_Cb, sh_alf_cb_enabled_flag );
3699
3700
0
        X_READ_FLAG( sh_alf_cr_enabled_flag );
3701
0
        pcSlice->setAlfEnabledFlag( COMPONENT_Cr, sh_alf_cr_enabled_flag );
3702
0
      }
3703
3704
0
      if( pcSlice->getAlfEnabledFlag( COMPONENT_Cb ) || pcSlice->getAlfEnabledFlag( COMPONENT_Cr ) )
3705
0
      {
3706
0
        X_READ_CODE_NO_RANGE( sh_alf_aps_id_chroma, 3 );
3707
0
        pcSlice->setAlfApsIdChroma( sh_alf_aps_id_chroma );
3708
3709
0
        const APS* APStoCheckChroma = parameterSetManager->getAPS( sh_alf_aps_id_chroma, ALF_APS );
3710
0
        CHECK( APStoCheckChroma == nullptr, "referenced APS not found" );
3711
0
        CHECK( APStoCheckChroma->getAlfAPSParam().newFilterFlag[CHANNEL_TYPE_CHROMA] != 1,
3712
0
                           "The value of alf_chroma_filter_signal_flag of the APS NAL unit having aps_params_type equal to ALF_APS and"
3713
0
                           " aps_adaptation_parameter_set_id equal to sh_alf_aps_id_chroma shall be equal to 1." );
3714
0
      }
3715
3716
0
      if( sps->getUseCCALF() )
3717
0
      {
3718
0
        X_READ_FLAG( sh_alf_cc_cb_enabled_flag );
3719
0
        pcSlice->setCcAlfCbEnabledFlag( sh_alf_cc_cb_enabled_flag );
3720
3721
0
        if( sh_alf_cc_cb_enabled_flag )
3722
0
        {
3723
0
          X_READ_CODE_NO_RANGE( sh_alf_cc_cb_aps_id, 3 );
3724
0
          pcSlice->setCcAlfCbApsId( sh_alf_cc_cb_aps_id );
3725
3726
0
          const APS* APStoCheckCcCb = parameterSetManager->getAPS( sh_alf_cc_cb_aps_id, ALF_APS );
3727
0
          CHECK( !APStoCheckCcCb, "referenced APS not found" );
3728
0
          CHECK( APStoCheckCcCb->getCcAlfAPSParam().newCcAlfFilter[0] != 1,
3729
0
                             "The value of alf_cc_cb_filter_signal_flag of the APS NAL unit having aps_params_type equal to ALF_APS and "
3730
0
                             "aps_adaptation_parameter_set_id equal to sh_alf_cc_cb_aps_id shall be equal to 1." );
3731
0
        }
3732
3733
0
        X_READ_FLAG( sh_alf_cc_cr_enabled_flag );
3734
0
        pcSlice->setCcAlfCrEnabledFlag( sh_alf_cc_cr_enabled_flag );
3735
3736
0
        if( sh_alf_cc_cr_enabled_flag )
3737
0
        {
3738
0
          X_READ_CODE_NO_RANGE( sh_alf_cc_cr_aps_id, 3 );
3739
0
          pcSlice->setCcAlfCrApsId( sh_alf_cc_cr_aps_id );
3740
3741
0
          const APS* APStoCheckCcCr = parameterSetManager->getAPS( sh_alf_cc_cr_aps_id, ALF_APS );
3742
0
          CHECK( !APStoCheckCcCr, "referenced APS not found" );
3743
0
          CHECK( APStoCheckCcCr->getCcAlfAPSParam().newCcAlfFilter[1] != 1,
3744
0
                             "The value of alf_cc_cr_filter_signal_flag of the APS NAL unit having aps_params_type equal to ALF_APS and "
3745
0
                             "aps_adaptation_parameter_set_id equal to sh_alf_cc_cr_aps_id shall be equal to 1." );
3746
0
        }
3747
0
      }
3748
0
    }
3749
0
  }
3750
3751
9
  if( picHeader->getLmcsEnabledFlag() && !sh_picture_header_in_slice_header_flag )
3752
0
  {
3753
0
    X_READ_FLAG( sh_lmcs_used_flag );
3754
0
    pcSlice->setLmcsEnabledFlag( sh_lmcs_used_flag );
3755
0
  }
3756
3757
9
  if( picHeader->getExplicitScalingListEnabledFlag() && !sh_picture_header_in_slice_header_flag )
3758
0
  {
3759
0
    X_READ_FLAG( sh_explicit_scaling_list_used_flag );
3760
0
    pcSlice->setExplicitScalingListUsed( sh_explicit_scaling_list_used_flag );
3761
0
  }
3762
3763
9
  if( pps->getRplInfoInPhFlag() )
3764
0
  {
3765
    // inheritFromPicHeader() already called
3766
0
  }
3767
9
  else if( pcSlice->getIdrPicFlag() && !sps->getIDRRefParamListPresent() )
3768
0
  {
3769
0
    pcSlice->clearRPL( REF_PIC_LIST_0 );
3770
0
    pcSlice->clearRPL( REF_PIC_LIST_1 );
3771
0
  }
3772
9
  else
3773
9
  {
3774
9
    parsePicOrSliceHeaderRPL( pcSlice, sps, pps );
3775
9
  }
3776
3777
9
  bool     numRefIdxActiveOverrideFlag = true;
3778
9
  unsigned numRefIdxActiveMinus1[2]    = { 0, 0 };
3779
9
  if( ( !pcSlice->isIntra() && pcSlice->getRPL( REF_PIC_LIST_0 )->getNumRefEntries() > 1 ) ||   //
3780
0
      ( pcSlice->isInterB() && pcSlice->getRPL( REF_PIC_LIST_1 )->getNumRefEntries() > 1 ) )
3781
0
  {
3782
0
    X_READ_FLAG( sh_num_ref_idx_active_override_flag );
3783
0
    numRefIdxActiveOverrideFlag = sh_num_ref_idx_active_override_flag;
3784
3785
0
    if( sh_num_ref_idx_active_override_flag )
3786
0
    {
3787
0
      for( int i = 0; i < ( pcSlice->isInterB() ? 2 : 1 ); ++i )
3788
0
      {
3789
0
        if( pcSlice->getRPL( (RefPicList) i )->getNumRefEntries() > 1 )
3790
0
        {
3791
0
          X_READ_UVLC_idx( sh_num_ref_idx_active_minus1, "[ i ]", 0, 14 );
3792
0
          numRefIdxActiveMinus1[i] = sh_num_ref_idx_active_minus1;
3793
0
        }
3794
0
      }
3795
0
    }
3796
0
  }
3797
3798
9
  for( auto i: { REF_PIC_LIST_0, REF_PIC_LIST_1 } )
3799
0
  {
3800
0
    if( pcSlice->isInterB() || ( pcSlice->isInterP() && i == REF_PIC_LIST_0 ) )
3801
0
    {
3802
0
      if( numRefIdxActiveOverrideFlag )
3803
0
      {
3804
0
        pcSlice->setNumRefIdx( i, numRefIdxActiveMinus1[i] + 1 );
3805
0
      }
3806
0
      else
3807
0
      {
3808
0
        const int pps_num_ref_idx_default_active_minus1 = ( i == 0 ? pps->getNumRefIdxL0DefaultActive() : pps->getNumRefIdxL1DefaultActive() ) - 1;
3809
0
        if( pcSlice->getRPL( i )->getNumRefEntries() >= pps_num_ref_idx_default_active_minus1 + 1 )
3810
0
        {
3811
0
          pcSlice->setNumRefIdx( i, pps_num_ref_idx_default_active_minus1 + 1 );
3812
0
        }
3813
0
        else
3814
0
        {
3815
0
          pcSlice->setNumRefIdx( i, pcSlice->getRPL( i )->getNumRefEntries() );
3816
0
        }
3817
0
      }
3818
0
    }
3819
0
    else /* sh_slice_type == I || ( sh_slice_type == P && i == 1 ) */
3820
0
    {
3821
0
      pcSlice->setNumRefIdx( i, 0 );
3822
0
    }
3823
0
  }
3824
3825
9
  if( pcSlice->isInterP() || pcSlice->isInterB() )
3826
0
  {
3827
0
    CHECK( pcSlice->getNumRefIdx( REF_PIC_LIST_0 ) == 0, "Number of active entries in RPL0 of P or B picture shall be greater than 0" );
3828
0
    if( pcSlice->isInterB() )
3829
0
    {
3830
0
      CHECK( pcSlice->getNumRefIdx( REF_PIC_LIST_1 ) == 0, "Number of active entries in RPL1 of B picture shall be greater than 0" );
3831
0
    }
3832
0
  }
3833
3834
9
  if( !pcSlice->isIntra() )
3835
0
  {
3836
0
    if( pps->getCabacInitPresentFlag() )
3837
0
    {
3838
0
      X_READ_FLAG( sh_cabac_init_flag );
3839
0
      pcSlice->setCabacInitFlag( sh_cabac_init_flag );
3840
0
    }
3841
3842
0
    if( picHeader->getEnableTMVPFlag() && !pps->getRplInfoInPhFlag() )
3843
0
    {
3844
0
      if( pcSlice->isInterB() )
3845
0
      {
3846
0
        X_READ_FLAG( sh_collocated_from_l0_flag );
3847
0
        pcSlice->setColFromL0Flag( sh_collocated_from_l0_flag );
3848
0
      }
3849
3850
0
      if( ( pcSlice->getColFromL0Flag() && pcSlice->getNumRefIdx( REF_PIC_LIST_0 ) > 1 )
3851
0
          || ( !pcSlice->getColFromL0Flag() && pcSlice->getNumRefIdx( REF_PIC_LIST_1 ) > 1 ) )
3852
0
      {
3853
0
        X_READ_UVLC( sh_collocated_ref_idx, 0, pcSlice->getNumRefIdx( pcSlice->getColFromL0Flag() ? REF_PIC_LIST_0 : REF_PIC_LIST_1 ) - 1u );
3854
3855
0
        pcSlice->setColRefIdx( sh_collocated_ref_idx );
3856
0
      }
3857
0
    }
3858
3859
0
    if( !pps->getWpInfoInPhFlag() &&
3860
0
        ( ( pps->getUseWP() && pcSlice->isInterP() ) || ( pps->getWPBiPred() && pcSlice->isInterB() ) ) )
3861
0
    {
3862
0
      parsePredWeightTable( pcSlice, sps, pps, { pcSlice->getNumRefIdx( REF_PIC_LIST_0 ), pcSlice->getNumRefIdx( REF_PIC_LIST_1 ) } );
3863
0
    }
3864
3865
0
    if( pps->getWpInfoInPhFlag() )
3866
0
    {
3867
0
      CHECK( pps->getUseWP() && pcSlice->isInterP() && pcSlice->getNumRefIdx( REF_PIC_LIST_0 ) > picHeader->getNumL0Weights(),
3868
0
             "When pps_wp_info_in_ph_flag is equal to 1, pps_weighted_pred_flag is equal to 1, and sh_slice_type is equal to P,"
3869
0
             " NumRefIdxActive[ 0 ] shall be less than or equal to the value of NumWeightsL0." );
3870
0
      CHECK( pps->getWPBiPred() && pcSlice->isInterB() && pcSlice->getNumRefIdx( REF_PIC_LIST_0 ) > picHeader->getNumL0Weights(),
3871
0
             "When pps_wp_info_in_ph_flag is equal to 1, pps_weighted_bipred_flag is equal to 1, and sh_slice_type is equal to B,"
3872
0
             " NumRefIdxActive[ 0 ] shall be less than or equal to the value of NumWeightsL0." );
3873
0
      CHECK( pps->getWPBiPred() && pcSlice->isInterB() && pcSlice->getNumRefIdx( REF_PIC_LIST_1 ) > picHeader->getNumL1Weights(),
3874
0
             "When pps_wp_info_in_ph_flag is equal to 1, pps_weighted_bipred_flag is equal to 1, and sh_slice_type is equal to B, "
3875
0
             " the value of NumRefIdxActive[ 1 ] shall be less than or equal to the value of NumWeightsL1." );
3876
0
    }
3877
0
  }
3878
3879
9
  if( !pps->getQpDeltaInfoInPhFlag() )
3880
0
  {
3881
0
    X_READ_SVLC_NO_RANGE( sh_qp_delta );
3882
3883
0
    int SliceQpY = 26 + pps->getPicInitQPMinus26() + sh_qp_delta;
3884
0
    CHECK_READ_RANGE( SliceQpY, -sps->getQpBDOffset(), MAX_QP, SliceQpY );
3885
3886
0
    pcSlice->setSliceQp( SliceQpY );
3887
0
  }
3888
3889
9
  if( pps->getSliceChromaQpFlag() )
3890
0
  {
3891
0
    X_READ_SVLC( sh_cb_qp_offset, -12, +12 );
3892
0
    CHECK_READ_RANGE( sh_cb_qp_offset + pps->getQpOffset( COMPONENT_Cb ), -12, +12, "pps_cb_qp_offset + sh_cb_qp_offset" );
3893
0
    pcSlice->setSliceChromaQpDelta( COMPONENT_Cb, sh_cb_qp_offset );
3894
3895
0
    X_READ_SVLC( sh_cr_qp_offset, -12, +12 );
3896
0
    CHECK_READ_RANGE( sh_cr_qp_offset + pps->getQpOffset( COMPONENT_Cr ), -12, +12, "pps_cr_qp_offset + sh_cr_qp_offset" );
3897
0
    pcSlice->setSliceChromaQpDelta( COMPONENT_Cr, sh_cr_qp_offset );
3898
3899
0
    if( sps->getJointCbCrEnabledFlag() )
3900
0
    {
3901
0
      X_READ_SVLC( sh_joint_cbcr_qp_offset, -12, +12 );
3902
0
      CHECK_READ_RANGE( sh_joint_cbcr_qp_offset + pps->getQpOffset( JOINT_CbCr ), -12, +12, "pps_joint_cbcr_qp_offset_value + sh_joint_cbcr_qp_offset" );
3903
0
      pcSlice->setSliceChromaQpDelta( JOINT_CbCr, sh_joint_cbcr_qp_offset );
3904
0
    }
3905
0
  }
3906
9
  if( pps->getCuChromaQpOffsetEnabledFlag() )
3907
0
  {
3908
0
    X_READ_FLAG( sh_cu_chroma_qp_offset_enabled_flag );
3909
0
    pcSlice->setUseChromaQpAdj( sh_cu_chroma_qp_offset_enabled_flag );
3910
0
  }
3911
3912
9
  if( sps->getUseSAO() && !pps->getSaoInfoInPhFlag() )
3913
0
  {
3914
0
    X_READ_FLAG( sh_sao_luma_used_flag );
3915
0
    pcSlice->setSaoEnabledFlag( CHANNEL_TYPE_LUMA, sh_sao_luma_used_flag );
3916
3917
0
    if( bChroma )
3918
0
    {
3919
0
      X_READ_FLAG( sh_sao_chroma_used_flag );
3920
0
      pcSlice->setSaoEnabledFlag( CHANNEL_TYPE_CHROMA, sh_sao_chroma_used_flag );
3921
0
    }
3922
0
  }
3923
3924
9
  if( pps->getDeblockingFilterOverrideEnabledFlag() && !pps->getDbfInfoInPhFlag() )
3925
0
  {
3926
0
    X_READ_FLAG( sh_deblocking_params_present_flag );
3927
0
    pcSlice->setDeblockingFilterOverrideFlag( sh_deblocking_params_present_flag );
3928
0
  }
3929
  // If pps_deblocking_filter_disabled_flag and sh_deblocking_params_present_flag are both equal to 1, the value of sh_deblocking_filter_disabled_flag is
3930
  // inferred to be equal to 0.
3931
  // Otherwise (pps_deblocking_filter_disabled_flag or sh_deblocking_params_present_flag is equal to 0), the value of sh_deblocking_filter_disabled_flag is
3932
  // inferred to be equal to ph_deblocking_filter_disabled_flag.
3933
9
  pcSlice->setDeblockingFilterDisable( pps->getPPSDeblockingFilterDisabledFlag() && pcSlice->getDeblockingFilterOverrideFlag()
3934
9
                                       ? 0 : picHeader->getDeblockingFilterDisable() );
3935
3936
9
  if( pcSlice->getDeblockingFilterOverrideFlag() )
3937
0
  {
3938
0
    if( !pps->getPPSDeblockingFilterDisabledFlag() )
3939
0
    {
3940
0
      X_READ_FLAG( sh_deblocking_filter_disabled_flag );
3941
0
      pcSlice->setDeblockingFilterDisable( sh_deblocking_filter_disabled_flag );
3942
0
    }
3943
3944
0
    if( !pcSlice->getDeblockingFilterDisable() )
3945
0
    {
3946
0
      X_READ_SVLC( sh_luma_beta_offset_div2, -12, 12 );
3947
0
      pcSlice->setDeblockingFilterBetaOffsetDiv2( sh_luma_beta_offset_div2 );
3948
0
      X_READ_SVLC( sh_luma_tc_offset_div2, -12, 12 );
3949
0
      pcSlice->setDeblockingFilterTcOffsetDiv2( sh_luma_tc_offset_div2 );
3950
0
    }
3951
0
  }
3952
3953
9
  if( pcSlice->getDeblockingFilterOverrideFlag() && !pcSlice->getDeblockingFilterDisable() && pps->getPPSChromaToolFlag() )
3954
0
  {
3955
0
    X_READ_SVLC( sh_cb_beta_offset_div2, -12, 12 );
3956
0
    pcSlice->setDeblockingFilterCbBetaOffsetDiv2( sh_cb_beta_offset_div2 );
3957
3958
0
    X_READ_SVLC( sh_cb_tc_offset_div2, -12, 12 );
3959
0
    pcSlice->setDeblockingFilterCbTcOffsetDiv2( sh_cb_tc_offset_div2 );
3960
3961
0
    X_READ_SVLC( sh_cr_beta_offset_div2, -12, 12 );
3962
0
    pcSlice->setDeblockingFilterCrBetaOffsetDiv2( sh_cr_beta_offset_div2 );
3963
3964
0
    X_READ_SVLC( sh_cr_tc_offset_div2, -12, 12 );
3965
0
    pcSlice->setDeblockingFilterCrTcOffsetDiv2( sh_cr_tc_offset_div2 );
3966
0
  }
3967
9
  else
3968
9
  {
3969
9
    if( pps->getPPSChromaToolFlag() )
3970
0
    {
3971
      // If pps_chroma_tool_offsets_present_flag is equal to 1, the values of sh_cb_beta_offset_div2 and sh_cb_tc_offset_div2 are inferred to be equal to
3972
      // ph_cb_beta_offset_div2 and ph_cb_tc_offset_div2, respectively.
3973
      // If pps_chroma_tool_offsets_present_flag is equal to 1, the values of sh_cr_beta_offset_div2 and sh_cr_tc_offset_div2 are inferred to be equal to
3974
      // ph_cr_beta_offset_div2 and ph_cr_tc_offset_div2, respectively.
3975
3976
0
      pcSlice->setDeblockingFilterCbBetaOffsetDiv2( picHeader->getDeblockingFilterCbBetaOffsetDiv2() );
3977
0
      pcSlice->setDeblockingFilterCbTcOffsetDiv2  ( picHeader->getDeblockingFilterCbTcOffsetDiv2()   );
3978
0
      pcSlice->setDeblockingFilterCrBetaOffsetDiv2( picHeader->getDeblockingFilterCrBetaOffsetDiv2() );
3979
0
      pcSlice->setDeblockingFilterCrTcOffsetDiv2  ( picHeader->getDeblockingFilterCrTcOffsetDiv2()   );
3980
0
    }
3981
9
    else
3982
9
    {
3983
      // Otherwise (pps_chroma_tool_offsets_present_flag is equal to 0), the values of sh_cb_beta_offset_div2 and sh_cb_tc_offset_div2 are inferred to be equal to
3984
      // sh_luma_beta_offset_div2 and sh_luma_tc_offset_div2, respectively.
3985
      // Otherwise( pps_chroma_tool_offsets_present_flag is equal to 0 ), the values of sh_cr_beta_offset_div2 and sh_cr_tc_offset_div2 are inferred to be equal
3986
      // to sh_luma_beta_offset_div2 and sh_luma_tc_offset_div2, respectively.
3987
3988
9
      pcSlice->setDeblockingFilterCbBetaOffsetDiv2( pcSlice->getDeblockingFilterBetaOffsetDiv2() );
3989
9
      pcSlice->setDeblockingFilterCbTcOffsetDiv2  ( pcSlice->getDeblockingFilterTcOffsetDiv2()   );
3990
9
      pcSlice->setDeblockingFilterCrBetaOffsetDiv2( pcSlice->getDeblockingFilterBetaOffsetDiv2() );
3991
9
      pcSlice->setDeblockingFilterCrTcOffsetDiv2  ( pcSlice->getDeblockingFilterTcOffsetDiv2()   );
3992
9
    }
3993
9
  }
3994
3995
  // dependent quantization
3996
9
  if( sps->getDepQuantEnabledFlag() )
3997
0
  {
3998
0
    X_READ_FLAG( sh_dep_quant_used_flag );
3999
0
    pcSlice->setDepQuantEnabledFlag( sh_dep_quant_used_flag );
4000
0
  }
4001
4002
  // sign data hiding
4003
9
  if( sps->getSignDataHidingEnabledFlag() && !pcSlice->getDepQuantEnabledFlag() )
4004
0
  {
4005
0
    X_READ_FLAG( sh_sign_data_hiding_used_flag );
4006
0
    pcSlice->setSignDataHidingEnabledFlag( sh_sign_data_hiding_used_flag );
4007
0
  }
4008
4009
  // signal TS residual coding disabled flag
4010
9
  if( sps->getTransformSkipEnabledFlag() && !pcSlice->getDepQuantEnabledFlag() && !pcSlice->getSignDataHidingEnabledFlag() )
4011
0
  {
4012
0
    X_READ_FLAG( sh_ts_residual_coding_disabled_flag );
4013
0
    pcSlice->setTSResidualCodingDisabledFlag( sh_ts_residual_coding_disabled_flag );
4014
0
  }
4015
4016
9
  if( pps->getSliceHeaderExtensionPresentFlag() )
4017
0
  {
4018
0
    X_READ_UVLC( sh_slice_header_extension_length, 0, 256 );
4019
0
    for( int i = 0; i < sh_slice_header_extension_length; i++ )
4020
0
    {
4021
0
      X_READ_CODE_NO_RANGE_idx( sh_slice_header_extension_data_byte, "[ i ]", 8 );
4022
0
      (void) sh_slice_header_extension_data_byte;
4023
0
    }
4024
0
  }
4025
4026
9
  std::vector<uint32_t> entryPointOffset;
4027
9
  pcSlice->setNumEntryPoints( sps, pps );
4028
9
  if( pcSlice->getNumEntryPoints() > 0 )
4029
0
  {
4030
0
    entryPointOffset.resize( pcSlice->getNumEntryPoints() );
4031
4032
0
    X_READ_UVLC( sh_entry_offset_len_minus1, 0, 31 );
4033
0
    for( uint32_t idx = 0; idx < pcSlice->getNumEntryPoints(); idx++ )
4034
0
    {
4035
0
      X_READ_CODE_NO_RANGE_idx( sh_entry_point_offset_minus1, "[i]", sh_entry_offset_len_minus1 + 1 );
4036
0
      entryPointOffset[idx] = sh_entry_point_offset_minus1 + 1;
4037
0
    }
4038
0
  }
4039
4040
#if RExt__DECODER_DEBUG_BIT_STATISTICS
4041
  CodingStatistics::IncrementStatisticEP(STATS__BYTE_ALIGNMENT_BITS,m_pcBitstream->readByteAlignment(),0);
4042
#else
4043
9
  m_pcBitstream->readByteAlignment();
4044
9
#endif
4045
4046
4047
9
  if( pcSlice->getFirstCtuRsAddrInSlice() == 0 )
4048
0
  {
4049
0
    pcSlice->setDefaultClpRng( *sps );
4050
0
  }
4051
4052
9
  pcSlice->clearSubstreamSizes();
4053
4054
9
  if( pcSlice->getNumEntryPoints() > 0 )
4055
0
  {
4056
0
    int endOfSliceHeaderLocation = m_pcBitstream->getByteLocation();
4057
4058
    // Adjust endOfSliceHeaderLocation to account for emulation prevention bytes in the slice segment header
4059
0
    for( uint32_t curByteIdx = 0; curByteIdx < m_pcBitstream->numEmulationPreventionBytesRead(); curByteIdx++ )
4060
0
    {
4061
0
      if( m_pcBitstream->getEmulationPreventionByteLocation( curByteIdx ) < endOfSliceHeaderLocation )
4062
0
      {
4063
0
        endOfSliceHeaderLocation++;
4064
0
      }
4065
0
    }
4066
4067
0
    uint32_t prevEntryPoint = 0;
4068
0
    for( uint32_t idx = 0; idx < entryPointOffset.size(); idx++ )
4069
0
    {
4070
0
      const uint32_t currEntryPoint = prevEntryPoint + entryPointOffset[idx];
4071
4072
0
      int emulationPreventionByteCount = 0;
4073
0
      for( uint32_t curByteIdx = 0; curByteIdx < m_pcBitstream->numEmulationPreventionBytesRead(); curByteIdx++ )
4074
0
      {
4075
0
        if( m_pcBitstream->getEmulationPreventionByteLocation( curByteIdx ) >= prevEntryPoint + endOfSliceHeaderLocation
4076
0
            && m_pcBitstream->getEmulationPreventionByteLocation( curByteIdx ) < currEntryPoint + endOfSliceHeaderLocation )
4077
0
        {
4078
0
          emulationPreventionByteCount++;
4079
0
        }
4080
0
      }
4081
4082
0
      entryPointOffset[idx] -= emulationPreventionByteCount;
4083
4084
0
      prevEntryPoint = currEntryPoint;
4085
0
    }
4086
4087
0
    pcSlice->setSubstreamSizes( std::move( entryPointOffset ) );
4088
0
  }
4089
9
}
4090
4091
template<typename HeaderT>
4092
void HLSyntaxReader::parsePicOrSliceHeaderRPL( HeaderT* header, const SPS* sps, const PPS* pps )
4093
0
{
4094
0
  bool rplSpsFlag[2] = { false, false };
4095
4096
  // List0 and List1
4097
0
  for( RefPicList listIdx: { REF_PIC_LIST_0, REF_PIC_LIST_1 } )
4098
0
  {
4099
0
    const unsigned sps_num_ref_pic_lists_i   = sps->getNumRPL( listIdx );
4100
0
    const bool     pps_rpl1_idx_present_flag = pps->getRpl1IdxPresentFlag();
4101
4102
0
    if( sps_num_ref_pic_lists_i > 0 && ( listIdx == 0 || ( listIdx == 1 && pps_rpl1_idx_present_flag ) ) )
4103
0
    {
4104
0
      X_READ_FLAG_idx( ref_pic_list_sps_flag, "[i]" );   // rpl_sps_flag[i] in the standard
4105
0
      rplSpsFlag[listIdx] = ref_pic_list_sps_flag;
4106
0
    }
4107
0
    else if( sps_num_ref_pic_lists_i == 0 )
4108
0
    {
4109
0
      rplSpsFlag[listIdx] = false;
4110
0
    }
4111
0
    else if( sps_num_ref_pic_lists_i > 0 && !pps_rpl1_idx_present_flag && listIdx == REF_PIC_LIST_1 )
4112
0
    {
4113
0
      rplSpsFlag[listIdx] = rplSpsFlag[0];
4114
0
    }
4115
4116
0
    if( rplSpsFlag[listIdx] )
4117
0
    {
4118
      // When rpl_sps_flag[ i ] is equal to 1 and sps_num_ref_pic_lists[ i ] is equal to 1, the value of rpl_idx[ i ] is inferred to be
4119
      // equal to 0. When rpl_sps_flag[ 1 ] is equal to 1, pps_rpl1_idx_present_flag is equal to 0, and sps_num_ref_pic_lists[ 1 ]
4120
      // is greater than 1, the value of rpl_idx[ 1 ] is inferred to be equal to rpl_idx[ 0 ].
4121
0
      int rpl_idx_i = 0;
4122
0
      if( rplSpsFlag[listIdx] && sps_num_ref_pic_lists_i == 1 )
4123
0
      {
4124
0
        rpl_idx_i = 0;
4125
0
      }
4126
0
      else if( listIdx == REF_PIC_LIST_1 && rplSpsFlag[1] && !pps_rpl1_idx_present_flag && sps->getNumRPL( REF_PIC_LIST_1 ) > 1 )
4127
0
      {
4128
0
        rpl_idx_i = header->getRPLIdx( REF_PIC_LIST_0 );
4129
0
      }
4130
4131
0
      if( sps_num_ref_pic_lists_i > 1 && ( listIdx == REF_PIC_LIST_0 || ( listIdx == REF_PIC_LIST_1 && pps_rpl1_idx_present_flag ) ) )
4132
0
      {
4133
0
        int numBits = std::ceil( std::log2( sps_num_ref_pic_lists_i ) );
4134
0
        X_READ_CODE_idx( ref_pic_list_idx, "[ listIdx ]", numBits, 0, sps_num_ref_pic_lists_i - 1 );   // rpl_idx[i] in the standard
4135
0
        rpl_idx_i = ref_pic_list_idx;
4136
0
      }
4137
4138
0
      CHECK( rpl_idx_i < 0 || rpl_idx_i > (int) sps_num_ref_pic_lists_i - 1,
4139
0
             "The value of rpl_idx[ i ] shall be in the range of 0 to sps_num_ref_pic_lists[ i ] - 1, inclusive." );
4140
4141
0
      header->setRPL( listIdx, sps->getRPLList( listIdx )[rpl_idx_i] );
4142
0
      header->setRPLIdx( listIdx, rpl_idx_i );
4143
0
    }
4144
0
    else
4145
0
    {
4146
0
      header->clearRPL( listIdx );
4147
0
      parseRefPicList( header->getRPL( listIdx ), -1, sps );   // ref_pic_list_struct( i, sps_num_ref_pic_lists[ i ] )
4148
0
      header->setRPLIdx( listIdx, -1 );
4149
0
    }
4150
4151
0
    if( std::is_same<HeaderT, PicHeader>::value )   // The contained CHECK is only valid, when we are in a PicHeader.
4152
0
    {
4153
      // The reinterpret_cast<> is a no-op, but it's needed for compilation. It's never executed in the case, when HeaderT is not a PicHeader due to the
4154
      // surrounding if-condition
4155
0
      CHECK( pps->getRplInfoInPhFlag() && reinterpret_cast<PicHeader*>( header )->getPicInterSliceAllowedFlag()
4156
0
               && header->getRPL( REF_PIC_LIST_0 )->getNumRefEntries() <= 0,
4157
0
             "When pps_rpl_info_in_ph_flag is equal to 1 and ph_inter_slice_allowed_flag is equal to 1, the value of"
4158
0
             " num_ref_entries[ 0 ][ RplsIdx[ 0 ] ] shall be greater than 0." )
4159
0
    }
4160
4161
    // Deal POC Msb cycle signalling for LTRP
4162
0
    auto* rpl = header->getRPL( listIdx );
4163
0
    uint32_t deltaPocMsbCycleLt = 0;   // accumulated over the LTRP entries (eq. 148)
4164
0
    for( int j = 0; j < rpl->getNumRefEntries(); ++j )
4165
0
    {
4166
0
      if( !rpl->isRefPicLongterm( j ) )
4167
0
      {
4168
0
        continue;
4169
0
      }
4170
4171
0
      if( rpl->getLtrpInSliceHeaderFlag() )
4172
0
      {
4173
0
        X_READ_CODE_NO_RANGE_idx( poc_lsb_lt, "[i][j]", sps->getBitsForPOC() );
4174
0
        rpl->setRefPicIdentifier( j, poc_lsb_lt, true, false, 0 );
4175
0
      }
4176
4177
0
      X_READ_FLAG_idx( delta_poc_msb_cycle_present_flag, "[i][j]" );
4178
0
      rpl->setDeltaPocMSBPresentFlag( j, delta_poc_msb_cycle_present_flag );
4179
4180
0
      if( delta_poc_msb_cycle_present_flag )
4181
0
      {
4182
0
        const uint32_t maxDeltaPocMsbCycleLt = 1u << ( 32 - sps->getBitsForPOC() );
4183
4184
0
        X_READ_UVLC( delta_poc_msb_cycle_lt, 0, maxDeltaPocMsbCycleLt );
4185
0
        deltaPocMsbCycleLt += delta_poc_msb_cycle_lt;
4186
        // bound the sum like a single value so it can't overflow (FullPocLt has to be a valid POC anyway)
4187
0
        CHECK( deltaPocMsbCycleLt > maxDeltaPocMsbCycleLt, "accumulated delta_poc_msb_cycle_lt out of range" );
4188
0
        rpl->setDeltaPocMSBCycleLT( j, deltaPocMsbCycleLt );
4189
0
      }
4190
0
    }
4191
0
  }
4192
0
}
Unexecuted instantiation: void vvdec::HLSyntaxReader::parsePicOrSliceHeaderRPL<vvdec::PicHeader>(vvdec::PicHeader*, vvdec::SPS const*, vvdec::PPS const*)
Unexecuted instantiation: void vvdec::HLSyntaxReader::parsePicOrSliceHeaderRPL<vvdec::Slice>(vvdec::Slice*, vvdec::SPS const*, vvdec::PPS const*)
4193
4194
void HLSyntaxReader::parseConstraintInfo( ConstraintInfo *cinfo )
4195
363
{
4196
363
  uint32_t symbol;
4197
363
  READ_FLAG( symbol, "gci_present_flag" );                                   cinfo->setGciPresentFlag( symbol ? true : false );
4198
363
  if( cinfo->getGciPresentFlag() )
4199
58
  {
4200
    /* general */
4201
58
    READ_FLAG( symbol, "gci_intra_only_constraint_flag" );                   cinfo->setIntraOnlyConstraintFlag( symbol ? true : false );
4202
58
    READ_FLAG( symbol, "gci_all_layers_independent_constraint_flag" );       cinfo->setAllLayersIndependentConstraintFlag( symbol ? true : false );
4203
58
    READ_FLAG( symbol, "gci_one_au_only_constraint_flag" );                  cinfo->setOnePictureOnlyConstraintFlag( symbol ? true : false );
4204
4205
    /* picture format */
4206
58
    READ_CODE( 4, symbol, "gci_sixteen_minus_max_bitdepth_constraint_idc" ); cinfo->setMaxBitDepthConstraintIdc( symbol>8 ? 16 : ( 16 - symbol ) );
4207
58
    CHECK(symbol>8, "gci_sixteen_minus_max_bitdepth_constraint_idc shall be in the range 0 to 8, inclusive");
4208
56
    READ_CODE( 2, symbol, "gci_three_minus_max_chroma_format_constraint_idc" );
4209
56
    cinfo->setMaxChromaFormatConstraintIdc( (ChromaFormat)( 3 - symbol ) );
4210
4211
    /* NAL unit type related */
4212
56
    READ_FLAG( symbol, "gci_no_mixed_nalu_types_in_pic_constraint_flag" );   cinfo->setNoMixedNaluTypesInPicConstraintFlag( symbol > 0 ? true : false );
4213
56
    READ_FLAG( symbol, "gci_no_trail_constraint_flag" );                     cinfo->setNoTrailConstraintFlag( symbol > 0 ? true : false );
4214
56
    READ_FLAG( symbol, "gci_no_stsa_constraint_flag" );                      cinfo->setNoStsaConstraintFlag( symbol > 0 ? true : false );
4215
56
    READ_FLAG( symbol, "gci_no_rasl_constraint_flag" );                      cinfo->setNoRaslConstraintFlag( symbol > 0 ? true : false );
4216
56
    READ_FLAG( symbol, "gci_no_radl_constraint_flag" );                      cinfo->setNoRadlConstraintFlag( symbol > 0 ? true : false );
4217
56
    READ_FLAG( symbol, "gci_no_idr_constraint_flag" );                       cinfo->setNoIdrConstraintFlag( symbol > 0 ? true : false );
4218
56
    READ_FLAG( symbol, "gci_no_cra_constraint_flag" );                       cinfo->setNoCraConstraintFlag( symbol > 0 ? true : false );
4219
56
    READ_FLAG( symbol, "gci_no_gdr_constraint_flag" );                       cinfo->setNoGdrConstraintFlag( symbol > 0 ? true : false );
4220
56
    READ_FLAG( symbol, "gci_no_aps_constraint_flag" );                       cinfo->setNoApsConstraintFlag( symbol > 0 ? true : false );
4221
56
    READ_FLAG( symbol, "gci_no_idr_rpl_constraint_flag" );                   cinfo->setNoIdrRplConstraintFlag( symbol > 0 ? true : false );
4222
4223
    /* tile, slice, subpicture partitioning */
4224
56
    READ_FLAG( symbol, "gci_one_tile_per_pic_constraint_flag" );             cinfo->setOneTilePerPicConstraintFlag( symbol > 0 ? true : false );
4225
56
    READ_FLAG( symbol, "gci_pic_header_in_slice_header_constraint_flag" );   cinfo->setPicHeaderInSliceHeaderConstraintFlag( symbol > 0 ? true : false );
4226
56
    READ_FLAG( symbol, "gci_one_slice_per_pic_constraint_flag" );            cinfo->setOneSlicePerPicConstraintFlag( symbol > 0 ? true : false );
4227
56
    READ_FLAG( symbol, "gci_no_rectangular_slice_constraint_flag" );         cinfo->setNoRectSliceConstraintFlag( symbol > 0 ? true : false );
4228
56
    READ_FLAG( symbol, "gci_one_slice_per_subpic_constraint_flag" );         cinfo->setOneSlicePerSubpicConstraintFlag( symbol > 0 ? true : false );
4229
56
    READ_FLAG( symbol, "gci_no_subpic_info_constraint_flag" );               cinfo->setNoSubpicInfoConstraintFlag( symbol > 0 ? true : false );
4230
4231
    /* CTU and block partitioning */
4232
56
    READ_CODE( 2, symbol, "gci_three_minus_max_log2_ctu_size_constraint_idc");   cinfo->setMaxLog2CtuSizeConstraintIdc( ( ( 3 - symbol ) + 5 ) );
4233
56
    READ_FLAG( symbol, "gci_no_partition_constraints_override_constraint_flag"); cinfo->setNoPartitionConstraintsOverrideConstraintFlag( symbol > 0 ? true : false );
4234
56
    READ_FLAG( symbol, "gci_no_mtt_constraint_flag");                            cinfo->setNoMttConstraintFlag( symbol > 0 ? true : false);
4235
56
    READ_FLAG( symbol, "gci_no_qtbtt_dual_tree_intra_constraint_flag");          cinfo->setNoQtbttDualTreeIntraConstraintFlag( symbol > 0 ? true : false );
4236
4237
    /* intra */
4238
56
    READ_FLAG( symbol, "gci_no_palette_constraint_flag" );                   cinfo->setNoPaletteConstraintFlag( symbol > 0 ? true : false );
4239
56
    READ_FLAG( symbol, "gci_no_ibc_constraint_flag" );                       cinfo->setNoIbcConstraintFlag( symbol > 0 ? true : false );
4240
56
    READ_FLAG( symbol, "gci_no_isp_constraint_flag" );                       cinfo->setNoIspConstraintFlag( symbol > 0 ? true : false );
4241
56
    READ_FLAG( symbol, "gci_no_mrl_constraint_flag" );                       cinfo->setNoMrlConstraintFlag( symbol > 0 ? true : false );
4242
56
    READ_FLAG( symbol, "gci_no_mip_constraint_flag" );                       cinfo->setNoMipConstraintFlag( symbol > 0 ? true : false );
4243
56
    READ_FLAG( symbol, "gci_no_cclm_constraint_flag" );                      cinfo->setNoCclmConstraintFlag( symbol > 0 ? true : false );
4244
4245
    /* inter */
4246
56
    READ_FLAG( symbol, "gci_no_ref_pic_resampling_constraint_flag" );        cinfo->setNoRprConstraintFlag( symbol > 0 ? true : false );
4247
56
    READ_FLAG( symbol, "gci_no_res_change_in_clvs_constraint_flag" );        cinfo->setNoResChangeInClvsConstraintFlag( symbol > 0 ? true : false );
4248
56
    READ_FLAG( symbol, "gci_no_weighted_prediction_constraint_flag" );       cinfo->setNoWeightedPredictionConstraintFlag( symbol > 0 ? true : false );
4249
56
    READ_FLAG( symbol, "gci_no_ref_wraparound_constraint_flag" );            cinfo->setNoRefWraparoundConstraintFlag( symbol > 0 ? true : false );
4250
56
    READ_FLAG( symbol, "gci_no_temporal_mvp_constraint_flag" );              cinfo->setNoTemporalMvpConstraintFlag( symbol > 0 ? true : false );
4251
56
    READ_FLAG( symbol, "gci_no_sbtmvp_constraint_flag" );                    cinfo->setNoSbtmvpConstraintFlag( symbol > 0 ? true : false );
4252
56
    READ_FLAG( symbol, "gci_no_amvr_constraint_flag" );                      cinfo->setNoAmvrConstraintFlag( symbol > 0 ? true : false );
4253
56
    READ_FLAG( symbol, "gci_no_bdof_constraint_flag" );                      cinfo->setNoBdofConstraintFlag( symbol > 0 ? true : false );
4254
56
    READ_FLAG( symbol, "gci_no_smvd_constraint_flag" );                      cinfo->setNoSmvdConstraintFlag( symbol > 0 ? true : false );
4255
56
    READ_FLAG( symbol, "gci_no_dmvr_constraint_flag" );                      cinfo->setNoDmvrConstraintFlag( symbol > 0 ? true : false );
4256
56
    READ_FLAG( symbol, "gci_no_mmvd_constraint_flag" );                      cinfo->setNoMmvdConstraintFlag( symbol > 0 ? true : false );
4257
56
    READ_FLAG( symbol, "gci_no_affine_motion_constraint_flag" );             cinfo->setNoAffineMotionConstraintFlag( symbol > 0 ? true : false );
4258
56
    READ_FLAG( symbol, "gci_no_prof_constraint_flag" );                      cinfo->setNoProfConstraintFlag( symbol > 0 ? true : false );
4259
56
    READ_FLAG( symbol, "gci_no_bcw_constraint_flag" );                       cinfo->setNoBcwConstraintFlag( symbol > 0 ? true : false  );
4260
56
    READ_FLAG( symbol, "gci_no_ciip_constraint_flag" );                      cinfo->setNoCiipConstraintFlag( symbol > 0 ? true : false );
4261
56
    READ_FLAG( symbol, "gci_no_gpm_constraint_flag" );                       cinfo->setNoGeoConstraintFlag( symbol > 0 ? true : false );
4262
4263
    /* transform, quantization, residual */
4264
56
    READ_FLAG( symbol, "gci_no_luma_transform_size_64_constraint_flag" );    cinfo->setNoLumaTransformSize64ConstraintFlag( symbol > 0 ? true : false );
4265
56
    READ_FLAG( symbol, "gci_no_transform_skip_constraint_flag" );            cinfo->setNoTransformSkipConstraintFlag( symbol > 0 ? true : false );
4266
56
    READ_FLAG( symbol, "gci_no_bdpcm_constraint_flag" );                     cinfo->setNoBDPCMConstraintFlag( symbol > 0 ? true : false );
4267
56
    READ_FLAG( symbol, "gci_no_mts_constraint_flag" );                       cinfo->setNoMtsConstraintFlag( symbol > 0 ? true : false );
4268
56
    READ_FLAG( symbol, "gci_no_lfnst_constraint_flag" );                     cinfo->setNoLfnstConstraintFlag( symbol > 0 ? true : false );
4269
56
    READ_FLAG( symbol, "gci_no_joint_cbcr_constraint_flag" );                cinfo->setNoJointCbCrConstraintFlag( symbol > 0 ? true : false );
4270
56
    READ_FLAG( symbol, "gci_no_sbt_constraint_flag" );                       cinfo->setNoSbtConstraintFlag( symbol > 0 ? true : false );
4271
56
    READ_FLAG( symbol, "gci_no_act_constraint_flag" );                       cinfo->setNoActConstraintFlag( symbol > 0 ? true : false );
4272
56
    READ_FLAG( symbol, "gci_no_explicit_scaling_list_constraint_flag" );     cinfo->setNoExplicitScaleListConstraintFlag( symbol > 0 ? true : false );
4273
56
    READ_FLAG( symbol, "gci_no_dep_quant_constraint_flag" );                 cinfo->setNoDepQuantConstraintFlag( symbol > 0 ? true : false );
4274
56
    READ_FLAG( symbol, "gci_no_sign_data_hiding_constraint_flag" );          cinfo->setNoSignDataHidingConstraintFlag( symbol > 0 ? true : false) ;
4275
56
    READ_FLAG( symbol, "gci_no_cu_qp_delta_constraint_flag" );               cinfo->setNoQpDeltaConstraintFlag( symbol > 0 ? true : false );
4276
56
    READ_FLAG( symbol, "gci_no_chroma_qp_offset_constraint_flag" );          cinfo->setNoChromaQpOffsetConstraintFlag( symbol > 0 ? true : false );
4277
4278
    /* loop filter */
4279
56
    READ_FLAG( symbol, "gci_no_sao_constraint_flag" );                       cinfo->setNoSaoConstraintFlag( symbol > 0 ? true : false );
4280
56
    READ_FLAG( symbol, "gci_no_alf_constraint_flag" );                       cinfo->setNoAlfConstraintFlag( symbol > 0 ? true : false );
4281
56
    READ_FLAG( symbol, "gci_no_ccalf_constraint_flag" );                     cinfo->setNoCCAlfConstraintFlag( symbol > 0 ? true : false );
4282
56
    READ_FLAG( symbol, "gci_no_lmcs_constraint_flag" );                      cinfo->setNoLmcsConstraintFlag( symbol > 0 ? true : false );
4283
56
    READ_FLAG( symbol, "gci_no_ladf_constraint_flag" );                      cinfo->setNoLadfConstraintFlag( symbol > 0 ? true : false );
4284
56
    READ_FLAG( symbol, "gci_no_virtual_boundaries_constraint_flag" );        cinfo->setNoVirtualBoundaryConstraintFlag( symbol > 0 ? true : false );
4285
4286
56
    READ_CODE( 8, symbol, "gci_num_reserved_bits" );
4287
56
    uint32_t const numReservedBits = symbol;
4288
198
    for (int i = 0; i < numReservedBits; i++)
4289
150
    {
4290
150
      READ_FLAG( symbol, "gci_reserved_zero_bit" );                          CHECK( symbol != 0, "gci_reserved_zero_bit not equal to zero" );
4291
142
    }
4292
56
  }
4293
2.03k
  while( !isByteAligned() )
4294
1.68k
  {
4295
1.68k
    READ_FLAG( symbol, "gci_alignment_zero_bit" );                           CHECK( symbol != 0, "gci_alignment_zero_bit not equal to zero" );
4296
1.67k
  }
4297
353
}
4298
4299
4300
void HLSyntaxReader::parseProfileTierLevel( ProfileTierLevel *ptl, bool profileTierPresentFlag, int maxNumSubLayersMinus1 )
4301
372
{
4302
372
  if( profileTierPresentFlag )
4303
372
  {
4304
372
    X_READ_CODE_NO_RANGE( general_profile_idc, 7 );
4305
372
    ptl->setProfileIdc( Profile::Name( general_profile_idc ) );
4306
4307
372
    X_READ_FLAG( general_tier_flag );
4308
372
    ptl->setTierFlag( general_tier_flag ? Tier::HIGH : Tier::MAIN );
4309
372
  }
4310
4311
372
  X_READ_CODE_NO_RANGE( general_level_idc, 8 );
4312
372
  ptl->setLevelIdc( vvdecLevel( general_level_idc ) );
4313
4314
372
  X_READ_FLAG( ptl_frame_only_constraint_flag );
4315
372
  ptl->setFrameOnlyConstraintFlag( ptl_frame_only_constraint_flag );
4316
4317
372
  X_READ_FLAG( ptl_multilayer_enabled_flag );
4318
372
  ptl->setMultiLayerEnabledFlag( ptl_multilayer_enabled_flag );
4319
4320
372
  CHECK( ( ptl->getProfileIdc() == Profile::MAIN_10 || ptl->getProfileIdc() == Profile::MAIN_10_444
4321
372
        || ptl->getProfileIdc() == Profile::MAIN_10_STILL_PICTURE
4322
372
        || ptl->getProfileIdc() == Profile::MAIN_10_444_STILL_PICTURE )
4323
372
          && ptl_multilayer_enabled_flag,
4324
372
        "ptl_multilayer_enabled_flag shall be equal to 0 for non-multilayer profiles");
4325
4326
371
  CHECK_UNSUPPORTED( ptl->getProfileIdc() == Profile::MULTILAYER_MAIN_10 || ptl->getProfileIdc() == Profile::MULTILAYER_MAIN_10_STILL_PICTURE ||
4327
371
         ptl->getProfileIdc() == Profile::MULTILAYER_MAIN_10_444 || ptl->getProfileIdc() == Profile::MULTILAYER_MAIN_10_444_STILL_PICTURE,
4328
371
         "Multilayer profiles not yet supported" );
4329
4330
367
  if( ptl->getProfileIdc() == Profile::MAIN_10_444 || ptl->getProfileIdc() == Profile::MAIN_10_444_STILL_PICTURE )
4331
7
  {
4332
7
    msg( WARNING, "Warning: MAIN_10_444 and MAIN_10_444_STILL_PICTURE is still experimental.\n" );
4333
7
  }
4334
4335
367
  if( profileTierPresentFlag )
4336
363
  {
4337
363
    parseConstraintInfo( ptl->getConstraintInfo() );
4338
363
  }
4339
4340
945
  for( int i = maxNumSubLayersMinus1 - 1; i >= 0; i-- )
4341
578
  {
4342
578
    X_READ_FLAG_idx( sub_layer_level_present_flag, "[i]" );
4343
578
    ptl->setSubLayerLevelPresentFlag( i, sub_layer_level_present_flag );
4344
578
  }
4345
4346
1.98k
  while( !isByteAligned() )
4347
1.61k
  {
4348
1.61k
    X_READ_FLAG( ptl_reserved_zero_bit );
4349
1.61k
    CHECK_WARN( ptl_reserved_zero_bit != 0, "ptl_reserved_zero_bit not equal to zero" );
4350
1.61k
  }
4351
4352
367
  ptl->setSubLayerLevelIdc( maxNumSubLayersMinus1, ptl->getLevelIdc() );
4353
945
  for( int i = maxNumSubLayersMinus1 - 1; i >= 0; i-- )
4354
578
  {
4355
578
    if( ptl->getSubLayerLevelPresentFlag( i ) )
4356
16
    {
4357
16
      X_READ_CODE_NO_RANGE_idx( sub_layer_level_idc, "[i]", 8 );
4358
16
      ptl->setSubLayerLevelIdc( i, vvdecLevel( sub_layer_level_idc ) );
4359
16
    }
4360
562
    else
4361
562
    {
4362
562
      ptl->setSubLayerLevelIdc( i, ptl->getSubLayerLevelIdc( i + 1 ) );
4363
562
    }
4364
578
  }
4365
4366
367
  if( profileTierPresentFlag )
4367
336
  {
4368
336
    X_READ_CODE_NO_RANGE( ptl_num_sub_profiles, 8 );
4369
336
    ptl->setNumSubProfile( ptl_num_sub_profiles );
4370
4371
453
    for( int i = 0; i < ptl_num_sub_profiles; i++ )
4372
117
    {
4373
117
      X_READ_CODE_NO_RANGE_idx( general_sub_profile_idc, "[i]", 32 );
4374
117
      ptl->setSubProfileIdc( i, general_sub_profile_idc );
4375
117
    }
4376
336
  }
4377
367
}
4378
4379
4380
// ====================================================================================================================
4381
// Protected member functions
4382
// ====================================================================================================================
4383
4384
//! parse explicit wp tables
4385
template<typename HeaderT>
4386
void HLSyntaxReader::parsePredWeightTable( HeaderT* sh_or_ph, const SPS* sps, const PPS* pps, std::array<int, 2> numRefIdxActive )
4387
0
{
4388
0
  const bool bChroma                  = sps->getChromaFormatIdc() != CHROMA_400;
4389
0
  const bool pps_wp_info_in_ph_flag   = pps->getWpInfoInPhFlag();
4390
0
  const bool pps_weighted_bipred_flag = pps->getWPBiPred();
4391
4392
0
  uint32_t log2WeightDenomChroma = 0;
4393
0
  uint32_t sumWeightFlags        = 0;
4394
4395
0
  X_READ_UVLC( luma_log2_weight_denom, 0, 7 );
4396
0
  if( bChroma )
4397
0
  {
4398
0
    X_READ_SVLC_NO_RANGE( delta_chroma_log2_weight_denom );
4399
0
    CHECK_READ_RANGE( luma_log2_weight_denom + delta_chroma_log2_weight_denom, 0, 7, "luma_log2_weight_denom + delta_chroma_log2_weight_denom" )
4400
4401
0
    log2WeightDenomChroma = luma_log2_weight_denom + delta_chroma_log2_weight_denom;
4402
0
  }
4403
4404
0
  for( auto& l: { REF_PIC_LIST_0, REF_PIC_LIST_1 } )
4405
0
  {
4406
0
    const int num_ref_entries = sh_or_ph->getRPL( l )->getNumRefEntries();
4407
4408
0
    unsigned numWeights = numRefIdxActive[l];
4409
0
    if( l == REF_PIC_LIST_0 )
4410
0
    {
4411
      // derive NumWeightsL0
4412
0
      if( pps_wp_info_in_ph_flag )
4413
0
      {
4414
0
        X_READ_UVLC( num_l0_weights, 1, std::min<unsigned>( 15, num_ref_entries ) );
4415
0
        numWeights = num_l0_weights;
4416
4417
0
        CHECK( ( !std::is_same<HeaderT, PicHeader>::value ),
4418
0
               "Implementation error: parsePredWeightTable() should not be called with a Slice, when pps_wp_info_in_ph_flag is true." );
4419
0
        if( std::is_same<HeaderT, PicHeader>::value )
4420
0
        {
4421
          // We know HeaderT is a PicHeader, so we use reinterpret_cast here just so it compiles for the HeaderT==Slice case.
4422
0
          reinterpret_cast<PicHeader*>( sh_or_ph )->setNumL0Weights( num_l0_weights );
4423
0
        }
4424
0
      }
4425
0
    }
4426
0
    else if( l == REF_PIC_LIST_1 )
4427
0
    {
4428
      // The variable NumWeightsL1 is derived as follows (semantics section):
4429
0
      if( !pps_weighted_bipred_flag || ( pps_wp_info_in_ph_flag && num_ref_entries == 0 ) )
4430
0
      {
4431
0
        numWeights = 0;
4432
0
      }
4433
0
      else if( pps_weighted_bipred_flag )   // condition from semantics section
4434
0
      {
4435
        // What should numWeights be set, when pps_weighted_bipred_flag && !pps_wp_info_in_ph_flag && num_ref_entries > 0 ?
4436
        // According to the syntax section num_l1_weights isn't read, but the semantics says, we should set NumWeightsL1 = num_l1_weights.
4437
        // It seems to work, when we leave numWeights set to NumRefIdxActive[ 1 ].
4438
        //CHECK( pps_weighted_bipred_flag && !pps_wp_info_in_ph_flag && num_ref_entries > 0,
4439
        //       "don't know how to set NumWeightsL1: it's missing from the spec" );
4440
4441
0
        if( pps_weighted_bipred_flag && pps_wp_info_in_ph_flag && num_ref_entries > 0 )   // condition from syntax section
4442
0
        {
4443
0
          X_READ_UVLC( num_l1_weights, 1, std::min<unsigned>( 15, num_ref_entries ) );
4444
0
          numWeights = num_l1_weights;
4445
4446
0
          CHECK( ( !std::is_same<HeaderT, PicHeader>::value ),
4447
0
                 "Implementation error: parsePredWeightTable() should not be called with a Slice, when pps_wp_info_in_ph_flag is true." );
4448
0
          if( std::is_same<HeaderT, PicHeader>::value )
4449
0
          {
4450
            // We know HeaderT is a PicHeader, so we use reinterpret_cast here just so it compiles for the HeaderT==Slice case.
4451
0
            reinterpret_cast<PicHeader*>( sh_or_ph )->setNumL1Weights( num_l1_weights );
4452
0
          }
4453
0
        }
4454
0
      }
4455
0
    }
4456
4457
0
    for( int i = 0; i < numWeights; i++ )
4458
0
    {
4459
0
      WPScalingParam* wp;
4460
0
      sh_or_ph->getWpScaling( l, i, wp );
4461
4462
0
      X_READ_FLAG_idx( luma_weight_lX_flag, "[i]" );
4463
0
      wp[COMPONENT_Y].bPresentFlag      = luma_weight_lX_flag;
4464
0
      wp[COMPONENT_Y].uiLog2WeightDenom = luma_log2_weight_denom;
4465
4466
0
      sumWeightFlags += luma_weight_lX_flag;
4467
0
    }
4468
4469
0
    if( bChroma )
4470
0
    {
4471
0
      for( int i = 0; i < numWeights; i++ )
4472
0
      {
4473
0
        WPScalingParam* wp;
4474
0
        sh_or_ph->getWpScaling( l, i, wp );
4475
4476
0
        X_READ_FLAG_idx( chroma_weight_lX_flag, "[i]" );
4477
0
        wp[COMPONENT_Cb].bPresentFlag      = wp[COMPONENT_Cr].bPresentFlag      = chroma_weight_lX_flag;
4478
0
        wp[COMPONENT_Cb].uiLog2WeightDenom = wp[COMPONENT_Cr].uiLog2WeightDenom = log2WeightDenomChroma;
4479
4480
0
        sumWeightFlags += 2 * chroma_weight_lX_flag;
4481
0
      }
4482
0
    }
4483
4484
0
    for( int i = 0; i < numWeights; i++ )
4485
0
    {
4486
0
      WPScalingParam* wp;
4487
0
      sh_or_ph->getWpScaling( l, i, wp );
4488
4489
0
      wp[COMPONENT_Y].iWeight = ( 1 << wp[COMPONENT_Y].uiLog2WeightDenom );
4490
0
      wp[COMPONENT_Y].iOffset = 0;
4491
4492
0
      if( wp[COMPONENT_Y].bPresentFlag /*luma_weight_l0_flag[i]*/ )
4493
0
      {
4494
0
        X_READ_SVLC_idx( delta_luma_weight_lX, "[i]", -128, 127 );
4495
0
        wp[COMPONENT_Y].iWeight += delta_luma_weight_lX;
4496
4497
0
        X_READ_SVLC_idx( luma_offset_lX, "[i]", -128, 127 );
4498
0
        wp[COMPONENT_Y].iOffset = luma_offset_lX;
4499
0
      }
4500
4501
0
      for( int j = COMPONENT_Cb; j < MAX_NUM_COMPONENT; j++ )
4502
0
      {
4503
0
        wp[j].iWeight = ( 1 << wp[j].uiLog2WeightDenom );
4504
0
        wp[j].iOffset = 0;
4505
0
        if( wp[j].bPresentFlag /*chroma_weight_l0_flag[i]*/ )
4506
0
        {
4507
0
          X_READ_SVLC_idx( delta_chroma_weight_lX, "[i][j]", -128, 127 );
4508
0
          wp[j].iWeight += delta_chroma_weight_lX;
4509
4510
0
          X_READ_SVLC_idx( delta_chroma_offset_lX, "[i][j]", -4 * 128, 4 * 127 );
4511
0
          wp[j].iOffset = Clip3( -128, 127, 128 + delta_chroma_offset_lX - ( ( 128 * wp[j].iWeight ) >> wp[j].uiLog2WeightDenom ) );
4512
0
        }
4513
0
      }
4514
0
    }
4515
4516
0
    for( int iRefIdx = numWeights; iRefIdx < MAX_NUM_REF; iRefIdx++ )
4517
0
    {
4518
0
      WPScalingParam* wp;
4519
0
      sh_or_ph->getWpScaling( l, iRefIdx, wp );
4520
4521
0
      wp[0].bPresentFlag = false;
4522
0
      wp[1].bPresentFlag = false;
4523
0
      wp[2].bPresentFlag = false;
4524
0
    }
4525
0
  }
4526
4527
0
  CHECK( sumWeightFlags > 24,
4528
0
         "It is a requirement of bitstream conformance that, when sh_slice_type is equal to P, sumWeightL0Flags shall be less than"
4529
0
         " or equal to 24 and when sh_slice_type is equal to B, the sum of sumWeightL0Flags and sumWeightL1Flags shall be less"
4530
0
         " than or equal to 24." );
4531
0
}
Unexecuted instantiation: void vvdec::HLSyntaxReader::parsePredWeightTable<vvdec::PicHeader>(vvdec::PicHeader*, vvdec::SPS const*, vvdec::PPS const*, std::__1::array<int, 2ul>)
Unexecuted instantiation: void vvdec::HLSyntaxReader::parsePredWeightTable<vvdec::Slice>(vvdec::Slice*, vvdec::SPS const*, vvdec::PPS const*, std::__1::array<int, 2ul>)
4532
4533
/** decode quantization matrix
4534
* \param scalingList quantization matrix information
4535
*/
4536
void HLSyntaxReader::parseScalingList( ScalingList *scalingList, bool aps_chromaPresentFlag )
4537
50
{
4538
50
  scalingList->reset();
4539
4540
940
  for( int id = 0; id < 28; id++ )
4541
890
  {
4542
890
    if( aps_chromaPresentFlag || scalingList->isLumaScalingList( id ) )
4543
420
    {
4544
420
      X_READ_FLAG( scaling_list_copy_mode_flag );
4545
4546
420
      bool scalingListPredModeFlag = false;
4547
420
      if( !scaling_list_copy_mode_flag )
4548
108
      {
4549
108
        X_READ_FLAG( scaling_list_pred_mode_flag );
4550
108
        scalingListPredModeFlag = scaling_list_pred_mode_flag;
4551
108
      }
4552
4553
420
      int scalingListPredIdDelta = 0;
4554
420
      if( ( scaling_list_copy_mode_flag || scalingListPredModeFlag )
4555
348
          && id != SCALING_LIST_1D_START_2x2 && id != SCALING_LIST_1D_START_4x4
4556
315
          && id != SCALING_LIST_1D_START_8x8 )   // Copy Mode
4557
282
      {
4558
282
        const unsigned maxIdDelta = id < 2 ? id : ( id < 8 ? id - 2 : id - 8 );
4559
282
        X_READ_UVLC_idx( scaling_list_pred_id_delta, "[id]", 0, maxIdDelta );
4560
4561
282
        scalingListPredIdDelta = scaling_list_pred_id_delta;
4562
282
      }
4563
4564
420
      decodeScalingList( scalingList, id, scalingListPredIdDelta, scaling_list_copy_mode_flag, scalingListPredModeFlag );
4565
420
    }   // ( aps_chromaPresentFlag || scalingList->isLumaScalingList( id ) )
4566
890
  }
4567
4568
50
  return;
4569
50
}
4570
4571
void HLSyntaxReader::decodeScalingList( ScalingList* scalingList, uint32_t id, uint32_t scalingListPredIdDelta, bool scalingListCopyModeFlag , bool scalingListPredModeFlag)
4572
412
{
4573
412
  const unsigned matrixSize = ScalingList::matrixSize( id );
4574
4575
412
  const int refId = id - scalingListPredIdDelta;
4576
412
  CHECK( refId<0, "refId < 0 doesn't make sense" );
4577
4578
412
  int   scalingMatrixDcPred = 0;
4579
412
  auto& scalingMatrixPred   = scalingList->getScalingListVec( id );   // we use the same storage for scalingMatrixPred and scalingMatrixRec
4580
412
  {
4581
    // Derive scalingMatrixPred and scalingMatrixDcPred
4582
4583
412
    const size_t scalingMatrixPred_size = matrixSize * matrixSize;
4584
412
    CHECK( scalingMatrixPred_size != scalingList->getScalingListVec( id ).size(), "wrong scalingMatrixPred/Rec[] size" )
4585
4586
412
    if( scalingListCopyModeFlag == 0 && scalingListPredModeFlag == 0 )
4587
70
    {
4588
70
      scalingMatrixPred.assign( scalingMatrixPred_size, 8 );
4589
70
      scalingMatrixDcPred = 8;
4590
70
    }
4591
342
    else if( scalingListPredIdDelta == 0 )
4592
289
    {
4593
289
      scalingMatrixPred.assign( scalingMatrixPred_size, 16 );
4594
289
      scalingMatrixDcPred = 16;
4595
289
    }
4596
53
    else
4597
53
    {
4598
53
      CHECK( ( scalingListCopyModeFlag == 0 && scalingListPredModeFlag == 0 ) || scalingListPredIdDelta <= 0,
4599
53
             "wrong condition: Otherwise (either scaling_list_copy_mode_flag[ id ] or scaling_list_pred_mode_flag[ id ] is equal to 1 and"
4600
53
             " scaling_list_pred_id_delta[ id ] is greater than 0)," );
4601
4602
53
      CHECK( scalingListCopyModeFlag == 0 && ( scalingListPredModeFlag == 0 || scalingListPredIdDelta <= 0 ),
4603
53
             "wrong condition: Otherwise (either scaling_list_copy_mode_flag[ id ] or scaling_list_pred_mode_flag[ id ] is equal to 1 and"
4604
53
             " scaling_list_pred_id_delta[ id ] is greater than 0)," );
4605
4606
      // scalingMatrixPred is set equal to ScalingMatrixRec[ refId ]
4607
53
      scalingMatrixPred = scalingList->getScalingListVec( refId );
4608
4609
200
#define MINUS_14 -( 14 * 0 )   // TODO: where did the -14 from the standard go ? when it is there, it breaks decoding.
4610
4611
53
      scalingMatrixDcPred = refId > 13 ? scalingList->getScalingListDC( refId MINUS_14 ) : scalingList->getScalingListVec( id )[0];
4612
53
    }
4613
412
  }
4614
4615
412
  if( scalingListCopyModeFlag )
4616
304
  {
4617
    // When not present, the value of scaling_list_dc_coef[id − 14] is inferred to be equal to 0.
4618
304
    if( id >= 14 )
4619
143
    {
4620
143
      scalingList->setScalingListDC( id MINUS_14, scalingMatrixDcPred );
4621
143
    }
4622
304
    return;
4623
304
  }
4624
4625
108
  const auto& DiagScanOrder = g_scanOrder[SCAN_UNGROUPED];
4626
4627
108
  int nextCoef = 0;
4628
108
  if( id > 13 )
4629
27
  {
4630
27
    X_READ_SVLC_idx( scaling_list_dc_coef, "[id-14]", -128, 127 );
4631
27
    nextCoef += scaling_list_dc_coef;
4632
4633
27
    scalingList->setScalingListDC( id MINUS_14, ( scalingMatrixDcPred + scaling_list_dc_coef ) & 255 );
4634
27
    CHECK( scalingList->getScalingListDC( id MINUS_14 ) <= 0, "The value of ScalingMatrixDcRec[" << id MINUS_14 << "] shall be greater than 0." )
4635
27
  }
4636
4637
1.41k
  for( unsigned i = 0; i < matrixSize * matrixSize; i++ )
4638
1.31k
  {
4639
1.31k
    const int numBits = g_sizeIdxInfo.idxFrom( matrixSize );
4640
1.31k
    const int x       = DiagScanOrder[3][3][i] & ( ( 1 << numBits ) - 1 );
4641
1.31k
    const int y       = DiagScanOrder[3][3][i] >> numBits;
4642
4643
1.31k
    if( !( id > 25 && x >= 4 && y >= 4 ) )
4644
1.26k
    {
4645
1.26k
      X_READ_SVLC_idx( scaling_list_delta_coef, "[id][i]", -128, 127 );
4646
1.26k
      nextCoef += scaling_list_delta_coef;
4647
1.26k
    }
4648
4649
1.31k
    int pos = DiagScanOrder[getLog2( matrixSize )][getLog2( matrixSize )][i];
4650
4651
1.31k
    auto& scalingMatrixRec = scalingList->getScalingListVec( id );
4652
1.31k
    scalingMatrixRec[pos]  = ( scalingMatrixPred[pos] + nextCoef ) & 255;
4653
1.31k
    CHECK( scalingMatrixRec[pos] <= 0, "The value of ScalingMatrixRec[" << id << " ][x][y] shall be greater than 0." )
4654
1.31k
  }
4655
107
}
4656
bool HLSyntaxReader::xMoreRbspData()
4657
1.73k
{
4658
1.73k
  int bitsLeft = m_pcBitstream->getNumBitsLeft();
4659
4660
  // if there are more than 8 bits, it cannot be rbsp_trailing_bits
4661
1.73k
  if( bitsLeft > 8 )
4662
1.52k
  {
4663
1.52k
    return true;
4664
1.52k
  }
4665
4666
209
  uint8_t lastByte = m_pcBitstream->peekBits( bitsLeft );
4667
209
  int cnt = bitsLeft;
4668
4669
  // remove trailing bits equal to zero
4670
389
  while( ( cnt > 0 ) && ( ( lastByte & 1 ) == 0 ) )
4671
180
  {
4672
180
    lastByte >>= 1;
4673
180
    cnt--;
4674
180
  }
4675
  // remove bit equal to one
4676
209
  cnt--;
4677
4678
  // we should not have a negative number of bits
4679
209
  CHECK( cnt<0, "Negative number of bits") ;
4680
4681
  // we have more data, if cnt is not zero
4682
202
  return ( cnt>0 );
4683
209
}
4684
4685
4686
void HLSyntaxReader::alfFilterCoeffs( AlfSliceParam& alfSliceParam, const bool isChroma, const int altIdx )
4687
81
{
4688
81
  const bool isLuma = !isChroma;
4689
4690
  // derive maxGolombIdx
4691
81
  const int numCoeff   = g_alfNumCoeff[isLuma];
4692
81
  const int numFilters = isLuma ? alfSliceParam.numLumaFilters : 1;
4693
81
  short*    coeff      = isLuma ? alfSliceParam.lumaCoeff      : alfSliceParam.chromaCoeff + altIdx * MAX_NUM_ALF_CHROMA_COEFF;
4694
81
  short*    clipp      = isLuma ? alfSliceParam.lumaClipp      : alfSliceParam.chromaClipp + altIdx * MAX_NUM_ALF_CHROMA_COEFF;
4695
4696
  // Filter coefficients
4697
178
  for( int sfIdx = 0; sfIdx < numFilters; ++sfIdx )
4698
102
  {
4699
877
    for( int j = 0; j < numCoeff - 1; j++ )
4700
780
    {
4701
780
      uint32_t code;
4702
780
      READ_UVLC( code, isLuma ? "alf_luma_coeff_abs" : "alf_chroma_coeff_abs" );
4703
780
      CHECK_READ_RANGE( code, 0, 128, ( isLuma ? "alf_luma_coeff_abs[sfIdx][j]" : "alf_chroma_coeff_abs[sfIdx][j]" ) );
4704
777
      coeff[sfIdx * MAX_NUM_ALF_LUMA_COEFF + j] = code;
4705
4706
777
      if( code )
4707
339
      {
4708
339
        READ_FLAG( code, isLuma ? "alf_luma_coeff_sign" : "alf_chroma_coeff_sign" );
4709
4710
339
        const int sign = code ? -1 : 1;
4711
339
        coeff[sfIdx * MAX_NUM_ALF_LUMA_COEFF + j] *= sign;
4712
4713
339
        CHECK_READ_RANGE( coeff[sfIdx * MAX_NUM_ALF_LUMA_COEFF + j],
4714
337
                          -( 1 << 7 ), ( 1 << 7 ) - 1,
4715
337
                          ( isLuma ? "AlfLumaCoeff[sfIdx * MAX_NUM_ALF_LUMA_COEFF + j]" : "AlfChromaCoeff[sfIdx * MAX_NUM_ALF_LUMA_COEFF + j]" ) );
4716
337
      }
4717
777
    }
4718
4719
97
    const int factor = 1 << ( AdaptiveLoopFilter::m_NUM_BITS - 1 );
4720
97
    coeff[sfIdx * MAX_NUM_ALF_LUMA_COEFF + numCoeff - 1] = factor;
4721
97
  }
4722
4723
  // Clipping values coding
4724
76
  bool alfClipFlag = isLuma ? alfSliceParam.nonLinearFlagLuma : alfSliceParam.nonLinearFlagChroma;
4725
76
  if( alfClipFlag )
4726
57
  {
4727
    // Filter coefficients
4728
127
    for( int sfIdx = 0; sfIdx < numFilters; ++sfIdx )
4729
70
    {
4730
575
      for( int j = 0; j < numCoeff - 1; j++ )
4731
505
      {
4732
505
        uint32_t code;
4733
505
        READ_CODE( 2, code, isLuma ? "alf_luma_clip_idx" : "alf_chroma_clip_idx" );
4734
505
        clipp[sfIdx * MAX_NUM_ALF_LUMA_COEFF + j] = code;
4735
505
      }
4736
70
    }
4737
57
  }
4738
76
}
4739
4740
}   // namespace vvdec