Coverage Report

Created: 2026-06-16 07:20

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/vvdec/source/Lib/CommonLib/ParameterSetManager.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
#include "ParameterSetManager.h"
44
45
namespace vvdec
46
{
47
48
ParameterSetManager::ActivePSs ParameterSetManager::xActivateParameterSets( const bool isFirstSlice, const Slice* pSlicePilot, const PicHeader* picHeader )
49
714
{
50
714
  PPS* pps = getPPS( picHeader->getPPSId() );
51
714
  CHECK( pps == 0, "No PPS present" );
52
53
714
  SPS* sps = getSPS( pps->getSPSId() );
54
714
  CHECK( sps == 0, "No SPS present" );
55
56
714
  if( isFirstSlice )
57
714
  {
58
714
    CHECK( !pps->pcv->isCorrect( *sps, *pps ), "PPS has PCV already, but values chaged???" );
59
60
714
    sps->clearChangedFlag();
61
714
    pps->clearChangedFlag();
62
63
714
    if( false == activatePPS( picHeader->getPPSId(), pSlicePilot->isIRAP() ) )
64
0
    {
65
0
      THROW_RECOVERABLE( "Parameter set activation failed!" );
66
0
    }
67
68
714
    m_alfAPSs.fill( nullptr );
69
714
    m_apsMap.clearActive();
70
714
  }
71
72
  // luma APSs
73
1.27k
  for( int i = 0; i < pSlicePilot->getAlfApsIdsLuma().size(); i++ )
74
561
  {
75
561
    int apsId = pSlicePilot->getAlfApsIdsLuma()[i];
76
561
    APS *alfApsL = getAPS( apsId, ALF_APS );
77
78
561
    if( alfApsL )
79
561
    {
80
561
      if( isFirstSlice ) alfApsL->clearChangedFlag();
81
561
      m_alfAPSs[apsId] = alfApsL;
82
561
      if( false == activateAPS( apsId, ALF_APS ) )
83
0
      {
84
0
        THROW_RECOVERABLE( "APS activation failed!" );
85
0
      }
86
87
561
      CHECK( sps->getUseCCALF() == false && ( alfApsL->getCcAlfAPSParam().newCcAlfFilter[0] || alfApsL->getCcAlfAPSParam().newCcAlfFilter[1] ),
88
561
             "When sps_ccalf_enabled_flag is 0, the values of alf_cc_cb_filter_signal_flag and alf_cc_cr_filter_signal_flag shall be equal to 0" );
89
561
      CHECK( sps->getChromaFormatIdc() == CHROMA_400 && alfApsL->chromaPresentFlag,
90
561
             "When ChromaArrayType is equal to 0, the value of aps_chroma_present_flag of an ALF_APS shall be equal to 0" );
91
561
    }
92
561
  }
93
94
714
  if( pSlicePilot->getAlfEnabledFlag( COMPONENT_Cb ) || pSlicePilot->getAlfEnabledFlag( COMPONENT_Cr ) )
95
705
  {
96
    // chroma APS
97
705
    int apsId = pSlicePilot->getAlfApsIdChroma();
98
705
    APS* alfApsC = getAPS( apsId , ALF_APS );
99
705
    if( alfApsC )
100
705
    {
101
705
      if( isFirstSlice ) alfApsC->clearChangedFlag();
102
705
      m_alfAPSs[apsId] = alfApsC;
103
705
      if( false == activateAPS( apsId, ALF_APS ) )
104
0
      {
105
0
        THROW_RECOVERABLE( "APS activation failed!" );
106
0
      }
107
705
      CHECK( sps->getUseCCALF() == false && ( alfApsC->getCcAlfAPSParam().newCcAlfFilter[0] || alfApsC->getCcAlfAPSParam().newCcAlfFilter[1] ),
108
705
             "When sps_ccalf_enabled_flag is 0, the values of alf_cc_cb_filter_signal_flag and alf_cc_cr_filter_signal_flag shall be equal to 0" );
109
705
    }
110
705
  }
111
714
  if( pSlicePilot->getCcAlfCbEnabledFlag() )
112
0
  {
113
0
    if( !m_alfAPSs[pSlicePilot->getCcAlfCbApsId()] )
114
0
    {
115
0
      int apsId = pSlicePilot->getCcAlfCbApsId();
116
0
      APS *aps = getAPS( apsId, ALF_APS );
117
0
      if( aps )
118
0
      {
119
0
        m_alfAPSs[apsId] = aps;
120
121
0
        if( false == activateAPS( apsId, ALF_APS ) )
122
0
        {
123
0
          THROW_RECOVERABLE( "APS activation failed!" );
124
0
        }
125
0
      }
126
0
    }
127
0
  }
128
129
714
  if( pSlicePilot->getCcAlfCrEnabledFlag() )
130
0
  {
131
0
    if( !m_alfAPSs[pSlicePilot->getCcAlfCrApsId()] )
132
0
    {
133
0
      int apsId = pSlicePilot->getCcAlfCrApsId();
134
0
      APS *aps = getAPS( apsId, ALF_APS );
135
0
      if( aps )
136
0
      {
137
0
        m_alfAPSs[apsId] = aps;
138
0
        if( false == activateAPS( apsId, ALF_APS ) )
139
0
        {
140
0
          THROW_RECOVERABLE( "APS activation failed!" );
141
0
        }
142
0
      }
143
0
    }
144
0
  }
145
146
714
  APS* lmcsAPS = nullptr;
147
714
  if( picHeader->getLmcsAPSId() != -1 )
148
0
  {
149
0
    lmcsAPS = getAPS( picHeader->getLmcsAPSId(), LMCS_APS );
150
0
    CHECK( lmcsAPS == 0, "No LMCS APS present" );
151
0
  }
152
153
714
  if( lmcsAPS )
154
0
  {
155
0
    if( isFirstSlice ) lmcsAPS->clearChangedFlag();
156
0
    if( false == activateAPS( picHeader->getLmcsAPSId(), LMCS_APS ) )
157
0
    {
158
0
      THROW_RECOVERABLE( "LMCS APS activation failed!" );
159
0
    }
160
161
0
    CHECK( sps->getChromaFormatIdc() == CHROMA_400 && lmcsAPS->chromaPresentFlag,
162
0
           "When ChromaArrayType is equal to 0, the value of aps_chroma_present_flag of an LMCS_APS shall be equal to 0");
163
0
    CHECK( lmcsAPS->getReshaperAPSInfo().maxNbitsNeededDeltaCW - 1 < 0 || lmcsAPS->getReshaperAPSInfo().maxNbitsNeededDeltaCW - 1 > sps->getBitDepth() - 2,
164
0
           "The value of lmcs_delta_cw_prec_minus1 of an LMCS_APS shall be in the range of 0 to BitDepth 2, inclusive" );
165
0
  }
166
167
714
  APS* scalingListAPS = nullptr;
168
714
  if( picHeader->getScalingListAPSId() != -1 )
169
0
  {
170
0
    scalingListAPS = getAPS( picHeader->getScalingListAPSId(), SCALING_LIST_APS );
171
0
    CHECK( scalingListAPS == 0, "No ScalingList APS present" );
172
0
  }
173
174
714
  if( scalingListAPS )
175
0
  {
176
0
    if( isFirstSlice ) scalingListAPS->clearChangedFlag();
177
178
0
    if( false == activateAPS( picHeader->getScalingListAPSId(), SCALING_LIST_APS ) )
179
0
    {
180
0
      THROW_RECOVERABLE( "LMCS APS activation failed!" );
181
0
    }
182
183
0
    CHECK( ( sps->getChromaFormatIdc() == CHROMA_400 && scalingListAPS->chromaPresentFlag ) || ( sps->getChromaFormatIdc() != CHROMA_400 && !scalingListAPS->chromaPresentFlag ),
184
0
           "The value of aps_chroma_present_flag of the APS NAL unit having aps_params_type equal to SCALING_APS and adaptation_parameter_set_id equal to ph_scaling_list_aps_id shall be equal to ChromaArrayType  = =  0 ? 0 : 1" );
185
0
  }
186
187
714
  return { sps, pps, &m_alfAPSs, lmcsAPS, scalingListAPS };
188
714
}
189
190
//! activate a PPS and depending on isIDR parameter also SPS
191
//! \returns true, if activation is successful
192
bool ParameterSetManager::activatePPS( int ppsId, bool isIRAP )
193
714
{
194
714
  PPS* pps = m_ppsMap.getPS( ppsId );
195
714
  if( pps )
196
714
  {
197
714
    int spsId = pps->getSPSId();
198
714
    {
199
714
      SPS* sps = m_spsMap.getPS( spsId );
200
714
      if( sps )
201
714
      {
202
714
        int vpsId = sps->getVPSId();
203
714
        if( vpsId != 0 )
204
0
        {
205
0
          VPS *vps = m_vpsMap.getPS(vpsId);
206
0
          if( vps )
207
0
          {
208
0
            m_activeVPSId = vpsId;
209
0
            m_vpsMap.setActive(vpsId);
210
0
          }
211
0
          else
212
0
          {
213
0
            msg( WARNING, "Warning: tried to activate PPS that refers to non-existing VPS." );
214
0
          }
215
0
        }
216
714
        else
217
714
        {
218
          //No actual VPS
219
714
          m_activeVPSId = -1;
220
714
          m_vpsMap.clearActive();
221
714
        }
222
223
714
        m_spsMap.clearActive();
224
714
        m_spsMap.setActive( spsId );
225
714
        m_activeSPSId = spsId;
226
227
714
        m_ppsMap.clearActive();
228
714
        m_ppsMap.setActive( ppsId );
229
714
        return true;
230
714
      }
231
0
      else
232
0
      {
233
0
        msg( WARNING, "Warning: tried to activate a PPS that refers to a non-existing SPS." );
234
0
      }
235
714
    }
236
714
  }
237
0
  else
238
0
  {
239
0
    msg( WARNING, "Warning: tried to activate non-existing PPS." );
240
0
  }
241
242
  // Failed to activate if reach here.
243
0
  m_activeSPSId = -1;
244
0
  return false;
245
714
}
246
247
bool ParameterSetManager::activateAPS( int apsId, int apsType )
248
1.26k
{
249
1.26k
  APS* aps = m_apsMap.getPS( ( apsId << NUM_APS_TYPE_LEN ) + apsType );
250
1.26k
  if( aps )
251
1.26k
  {
252
1.26k
    m_apsMap.setActive( ( apsId << NUM_APS_TYPE_LEN ) + apsType );
253
1.26k
    return true;
254
1.26k
  }
255
0
  else
256
0
  {
257
0
    msg( WARNING, "Warning: tried to activate non-existing APS." );
258
0
  }
259
0
  return false;
260
1.26k
}
261
262
}