Coverage Report

Created: 2026-04-01 07:49

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
0
{
50
0
  PPS* pps = getPPS( picHeader->getPPSId() );
51
0
  CHECK( pps == 0, "No PPS present" );
52
53
0
  SPS* sps = getSPS( pps->getSPSId() );
54
0
  CHECK( sps == 0, "No SPS present" );
55
56
0
  if( isFirstSlice )
57
0
  {
58
0
    CHECK( !pps->pcv->isCorrect( *sps, *pps ), "PPS has PCV already, but values chaged???" );
59
60
0
    sps->clearChangedFlag();
61
0
    pps->clearChangedFlag();
62
63
0
    if( false == activatePPS( picHeader->getPPSId(), pSlicePilot->isIRAP() ) )
64
0
    {
65
0
      THROW_RECOVERABLE( "Parameter set activation failed!" );
66
0
    }
67
68
0
    m_alfAPSs.fill( nullptr );
69
0
    m_apsMap.clearActive();
70
0
  }
71
72
  // luma APSs
73
0
  for( int i = 0; i < pSlicePilot->getAlfApsIdsLuma().size(); i++ )
74
0
  {
75
0
    int apsId = pSlicePilot->getAlfApsIdsLuma()[i];
76
0
    APS *alfApsL = getAPS( apsId, ALF_APS );
77
78
0
    if( alfApsL )
79
0
    {
80
0
      if( isFirstSlice ) alfApsL->clearChangedFlag();
81
0
      m_alfAPSs[apsId] = alfApsL;
82
0
      if( false == activateAPS( apsId, ALF_APS ) )
83
0
      {
84
0
        THROW_RECOVERABLE( "APS activation failed!" );
85
0
      }
86
87
0
      CHECK( sps->getUseCCALF() == false && ( alfApsL->getCcAlfAPSParam().newCcAlfFilter[0] || alfApsL->getCcAlfAPSParam().newCcAlfFilter[1] ),
88
0
             "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
0
      CHECK( sps->getChromaFormatIdc() == CHROMA_400 && alfApsL->chromaPresentFlag,
90
0
             "When ChromaArrayType is equal to 0, the value of aps_chroma_present_flag of an ALF_APS shall be equal to 0" );
91
0
    }
92
0
  }
93
94
0
  if( pSlicePilot->getAlfEnabledFlag( COMPONENT_Cb ) || pSlicePilot->getAlfEnabledFlag( COMPONENT_Cr ) )
95
0
  {
96
    // chroma APS
97
0
    int apsId = pSlicePilot->getAlfApsIdChroma();
98
0
    APS* alfApsC = getAPS( apsId , ALF_APS );
99
0
    if( alfApsC )
100
0
    {
101
0
      if( isFirstSlice ) alfApsC->clearChangedFlag();
102
0
      m_alfAPSs[apsId] = alfApsC;
103
0
      if( false == activateAPS( apsId, ALF_APS ) )
104
0
      {
105
0
        THROW_RECOVERABLE( "APS activation failed!" );
106
0
      }
107
0
      CHECK( sps->getUseCCALF() == false && ( alfApsC->getCcAlfAPSParam().newCcAlfFilter[0] || alfApsC->getCcAlfAPSParam().newCcAlfFilter[1] ),
108
0
             "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
0
    }
110
0
  }
111
0
  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
0
  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
0
  APS* lmcsAPS = nullptr;
147
0
  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
0
  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
0
  APS* scalingListAPS = nullptr;
168
0
  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
0
  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
0
  return { sps, pps, &m_alfAPSs, lmcsAPS, scalingListAPS };
188
0
}
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
0
{
194
0
  PPS* pps = m_ppsMap.getPS( ppsId );
195
0
  if( pps )
196
0
  {
197
0
    int spsId = pps->getSPSId();
198
0
    {
199
0
      SPS* sps = m_spsMap.getPS( spsId );
200
0
      if( sps )
201
0
      {
202
0
        int vpsId = sps->getVPSId();
203
0
        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
0
        else
217
0
        {
218
          //No actual VPS
219
0
          m_activeVPSId = -1;
220
0
          m_vpsMap.clearActive();
221
0
        }
222
223
0
        m_spsMap.clearActive();
224
0
        m_spsMap.setActive( spsId );
225
0
        m_activeSPSId = spsId;
226
227
0
        m_ppsMap.clearActive();
228
0
        m_ppsMap.setActive( ppsId );
229
0
        return true;
230
0
      }
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
0
    }
236
0
  }
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
0
}
246
247
bool ParameterSetManager::activateAPS( int apsId, int apsType )
248
0
{
249
0
  APS* aps = m_apsMap.getPS( ( apsId << NUM_APS_TYPE_LEN ) + apsType );
250
0
  if( aps )
251
0
  {
252
0
    m_apsMap.setActive( ( apsId << NUM_APS_TYPE_LEN ) + apsType );
253
0
    return true;
254
0
  }
255
0
  else
256
0
  {
257
0
    msg( WARNING, "Warning: tried to activate non-existing APS." );
258
0
  }
259
0
  return false;
260
0
}
261
262
}