Coverage Report

Created: 2026-04-01 07:49

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/vvenc/source/Lib/CommonLib/Nal.h
Line
Count
Source
1
/* -----------------------------------------------------------------------------
2
The copyright in this software is being made available under the Clear BSD
3
License, included below. No patent rights, trademark rights and/or 
4
other Intellectual Property Rights other than the copyrights concerning 
5
the Software are granted under this license.
6
7
The Clear BSD License
8
9
Copyright (c) 2019-2026, Fraunhofer-Gesellschaft zur Förderung der angewandten Forschung e.V. & The VVenC Authors.
10
All rights reserved.
11
12
Redistribution and use in source and binary forms, with or without modification,
13
are permitted (subject to the limitations in the disclaimer below) provided that
14
the following conditions are met:
15
16
     * Redistributions of source code must retain the above copyright notice,
17
     this list of conditions and the following disclaimer.
18
19
     * Redistributions in binary form must reproduce the above copyright
20
     notice, this list of conditions and the following disclaimer in the
21
     documentation and/or other materials provided with the distribution.
22
23
     * Neither the name of the copyright holder nor the names of its
24
     contributors may be used to endorse or promote products derived from this
25
     software without specific prior written permission.
26
27
NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED BY
28
THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
29
CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
30
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
31
PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
32
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
33
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
34
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
35
BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
36
IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
37
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
38
POSSIBILITY OF SUCH DAMAGE.
39
40
41
------------------------------------------------------------------------------------------- */
42
#pragma once
43
44
#include <sstream>
45
#include <list>
46
#include "vvenc/vvenc.h"
47
48
//! \ingroup Interface
49
//! \{
50
51
namespace vvenc {
52
53
/**
54
 * Represents a single NALunit header and the associated RBSPayload
55
 */
56
struct NALUnit
57
{
58
  vvencNalUnitType m_nalUnitType; ///< nal_unit_type
59
  uint32_t    m_temporalId;  ///< temporal_id
60
  uint32_t    m_nuhLayerId;  ///< nuh_layer_id
61
  uint32_t    m_forbiddenZeroBit;
62
  uint32_t    m_nuhReservedZeroBit;
63
64
  NALUnit(const NALUnit &src)
65
0
  : m_nalUnitType       (src.m_nalUnitType)
66
0
  , m_temporalId        (src.m_temporalId)
67
0
  , m_nuhLayerId        (src.m_nuhLayerId)
68
0
  , m_forbiddenZeroBit  (src.m_forbiddenZeroBit)
69
0
  , m_nuhReservedZeroBit(src.m_nuhReservedZeroBit)
70
71
0
  { }
72
  /** construct an NALunit structure with given header values. */
73
  NALUnit(
74
    vvencNalUnitType nalUnitType,
75
    uint32_t temporalId = 0,
76
    uint32_t nuhReservedZeroBit = 0,
77
    uint32_t forbiddenZeroBit = 0,
78
    uint32_t nuhLayerId = 0)
79
0
    : m_nalUnitType (nalUnitType)
80
0
    , m_temporalId  (temporalId)
81
0
    , m_nuhLayerId  (nuhLayerId)
82
0
    , m_forbiddenZeroBit(forbiddenZeroBit)
83
0
    , m_nuhReservedZeroBit(nuhReservedZeroBit)
84
0
  {}
85
86
  /** default constructor - no initialization; must be performed by user */
87
0
  NALUnit() {}
88
89
0
  virtual ~NALUnit() { }
90
91
  /** returns true if the NALunit is a slice NALunit */
92
  bool isSlice()
93
0
  {
94
0
    return m_nalUnitType == VVENC_NAL_UNIT_CODED_SLICE_TRAIL
95
0
        || m_nalUnitType == VVENC_NAL_UNIT_CODED_SLICE_STSA
96
0
        || m_nalUnitType == VVENC_NAL_UNIT_CODED_SLICE_IDR_W_RADL
97
0
        || m_nalUnitType == VVENC_NAL_UNIT_CODED_SLICE_IDR_N_LP
98
0
        || m_nalUnitType == VVENC_NAL_UNIT_CODED_SLICE_CRA
99
0
        || m_nalUnitType == VVENC_NAL_UNIT_CODED_SLICE_GDR
100
0
        || m_nalUnitType == VVENC_NAL_UNIT_CODED_SLICE_RADL
101
0
        || m_nalUnitType == VVENC_NAL_UNIT_CODED_SLICE_RASL;
102
0
  }
103
  bool isSei()
104
0
  {
105
0
    return m_nalUnitType == VVENC_NAL_UNIT_PREFIX_SEI
106
0
        || m_nalUnitType == VVENC_NAL_UNIT_SUFFIX_SEI;
107
0
  }
108
109
  bool isVcl()
110
0
  {
111
0
    return m_nalUnitType == VVENC_NAL_UNIT_CODED_SLICE_TRAIL
112
0
        || m_nalUnitType == VVENC_NAL_UNIT_CODED_SLICE_STSA
113
0
        || m_nalUnitType == VVENC_NAL_UNIT_CODED_SLICE_RADL
114
0
        || m_nalUnitType == VVENC_NAL_UNIT_CODED_SLICE_RASL
115
0
        || m_nalUnitType == VVENC_NAL_UNIT_CODED_SLICE_IDR_W_RADL
116
0
        || m_nalUnitType == VVENC_NAL_UNIT_CODED_SLICE_IDR_N_LP
117
0
        || m_nalUnitType == VVENC_NAL_UNIT_CODED_SLICE_CRA
118
0
        || m_nalUnitType == VVENC_NAL_UNIT_CODED_SLICE_GDR;
119
0
120
0
  }
121
};
122
123
struct OutputNALUnit;
124
125
/**
126
 * A single NALunit, with complete payload in EBSP format.
127
 */
128
struct NALUnitEBSP : public NALUnit
129
{
130
  std::ostringstream m_nalUnitData;
131
132
  /**
133
   * convert the OutputNALUnit nalu into EBSP format by writing out
134
   * the NALUnit header, then the rbsp_bytes including any
135
   * emulation_prevention_three_byte symbols.
136
   */
137
  NALUnitEBSP(OutputNALUnit& nalu);
138
};
139
//! \}
140
//! \}
141
142
143
/**
144
 * An AccessUnit is a list of one or more NAL units, according to the
145
 * working draft.  All NAL units within the object belong to the same
146
 * access unit.
147
 *
148
 * NALUnits held in the AccessUnit list are in EBSP format.  Attempting
149
 * to insert an OutputNALUnit into the access unit will automatically cause
150
 * the nalunit to have its headers written and anti-emulation performed.
151
 *
152
 * The AccessUnit owns all pointers stored within.  Destroying the
153
 * AccessUnit will delete all contained objects.
154
 */
155
class AccessUnitList : public std::list<NALUnitEBSP*> // NOTE: Should not inherit from STL.
156
{
157
public:
158
  AccessUnitList()
159
0
  {
160
0
    clearAu();
161
0
  }
162
163
  ~AccessUnitList()
164
0
  {
165
0
    clearAu();
166
0
  }
167
168
  void clearAu()
169
0
  {
170
0
    cts          = 0;
171
0
    dts          = 0;
172
0
    poc          = 0;
173
0
    sliceType     = VVENC_NUMBER_OF_SLICE_TYPES;
174
0
    temporalLayer = 0;
175
0
    status        = 0;
176
0
    ctsValid      = false;
177
0
    dtsValid      = false;
178
0
    rap           = false;
179
0
    refPic        = false;
180
0
    InfoString.clear();
181
0
    userData      = nullptr;
182
183
0
    for( AccessUnitList::iterator it = this->begin(); it != this->end(); it++ )
184
0
    {
185
0
      delete* it;
186
0
    }
187
0
    std::list<NALUnitEBSP*>::clear();
188
0
  }
189
190
  void detachNalUnitList()
191
0
  {
192
0
    std::list<NALUnitEBSP*>::clear();
193
0
  }
194
195
  int64_t         cts;                                   ///< composition time stamp
196
  int64_t         dts;                                   ///< decoding time stamp
197
  uint64_t        poc;                                   ///< picture order count
198
  vvencSliceType  sliceType;                              ///< slice type (I/P/B) */
199
  int             temporalLayer;                          ///< temporal layer
200
  int             status;
201
  bool            ctsValid;                               ///< composition time stamp valid flag
202
  bool            dtsValid;                               ///< decoding time stamp valid flag
203
  bool            rap;                                    ///< random access point flag
204
  bool            refPic;                                 ///< reference picture
205
  std::string     InfoString;
206
  void*           userData;                               ///< user data passed in corresponding input YUV buffer
207
};
208
209
210
static inline const char* nalUnitTypeToString(vvencNalUnitType type)
211
0
{
212
0
  switch (type)
213
0
  {
214
0
  case VVENC_NAL_UNIT_CODED_SLICE_TRAIL:      return "TRAIL";
215
0
  case VVENC_NAL_UNIT_CODED_SLICE_STSA:       return "STSA";
216
0
  case VVENC_NAL_UNIT_CODED_SLICE_RADL:       return "RADL";
217
0
  case VVENC_NAL_UNIT_CODED_SLICE_RASL:       return "RASL";
218
0
  case VVENC_NAL_UNIT_CODED_SLICE_IDR_W_RADL: return "IDR_W_RADL";
219
0
  case VVENC_NAL_UNIT_CODED_SLICE_IDR_N_LP:   return "IDR_N_LP";
220
0
  case VVENC_NAL_UNIT_CODED_SLICE_CRA:        return "CRA";
221
0
  case VVENC_NAL_UNIT_CODED_SLICE_GDR:        return "GDR";
222
0
  case VVENC_NAL_UNIT_DCI:                    return "DCI";
223
0
  case VVENC_NAL_UNIT_VPS:                    return "VPS";
224
0
  case VVENC_NAL_UNIT_SPS:                    return "SPS";
225
0
  case VVENC_NAL_UNIT_PPS:                    return "PPS";
226
0
  case VVENC_NAL_UNIT_PREFIX_APS:             return "Prefix APS";
227
0
  case VVENC_NAL_UNIT_SUFFIX_APS:             return "Suffix APS";
228
0
  case VVENC_NAL_UNIT_PH:                     return "PH";
229
0
  case VVENC_NAL_UNIT_ACCESS_UNIT_DELIMITER:  return "AUD";
230
0
  case VVENC_NAL_UNIT_EOS:                    return "EOS";
231
0
  case VVENC_NAL_UNIT_EOB:                    return "EOB";
232
0
  case VVENC_NAL_UNIT_PREFIX_SEI:             return "Prefix SEI";
233
0
  case VVENC_NAL_UNIT_SUFFIX_SEI:             return "Suffix SEI";
234
0
  case VVENC_NAL_UNIT_FD:                     return "FD";
235
0
  default:                              return "UNK";
236
0
  }
237
0
}
Unexecuted instantiation: vvenc.cpp:vvenc::nalUnitTypeToString(vvencNalUnitType)
Unexecuted instantiation: vvencimpl.cpp:vvenc::nalUnitTypeToString(vvencNalUnitType)
Unexecuted instantiation: InitX86.cpp:vvenc::nalUnitTypeToString(vvencNalUnitType)
Unexecuted instantiation: MCTF_avx41.cpp:vvenc::nalUnitTypeToString(vvencNalUnitType)
Unexecuted instantiation: MCTF_avx2.cpp:vvenc::nalUnitTypeToString(vvencNalUnitType)
Unexecuted instantiation: EncLib.cpp:vvenc::nalUnitTypeToString(vvencNalUnitType)
Unexecuted instantiation: PreProcess.cpp:vvenc::nalUnitTypeToString(vvencNalUnitType)
Unexecuted instantiation: MCTF.cpp:vvenc::nalUnitTypeToString(vvencNalUnitType)
Unexecuted instantiation: BitAllocation.cpp:vvenc::nalUnitTypeToString(vvencNalUnitType)
Unexecuted instantiation: EncGOP.cpp:vvenc::nalUnitTypeToString(vvencNalUnitType)
Unexecuted instantiation: EncPicture.cpp:vvenc::nalUnitTypeToString(vvencNalUnitType)
Unexecuted instantiation: EncSlice.cpp:vvenc::nalUnitTypeToString(vvencNalUnitType)
Unexecuted instantiation: GOPCfg.cpp:vvenc::nalUnitTypeToString(vvencNalUnitType)
Unexecuted instantiation: InterSearch.cpp:vvenc::nalUnitTypeToString(vvencNalUnitType)
Unexecuted instantiation: NALwrite.cpp:vvenc::nalUnitTypeToString(vvencNalUnitType)
Unexecuted instantiation: SEIFilmGrainAnalyzer.cpp:vvenc::nalUnitTypeToString(vvencNalUnitType)
Unexecuted instantiation: CABACWriter.cpp:vvenc::nalUnitTypeToString(vvencNalUnitType)
Unexecuted instantiation: EncCu.cpp:vvenc::nalUnitTypeToString(vvencNalUnitType)
238
239
240
} // namespace vvenc
241
242
//! \}
243