Coverage Report

Created: 2026-08-13 07:23

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/work/vvenc/source/Lib/CommonLib/CodingStructure.h
Line
Count
Source
1
/* -----------------------------------------------------------------------------
2
The copyright in this software is being made available under the Clear BSD
3
License, included below. No patent rights, trademark rights and/or 
4
other Intellectual Property Rights other than the copyrights concerning 
5
the Software are granted under this license.
6
7
The Clear BSD License
8
9
Copyright (c) 2019-2026, Fraunhofer-Gesellschaft zur Förderung der angewandten Forschung e.V. & The VVenC Authors.
10
All rights reserved.
11
12
Redistribution and use in source and binary forms, with or without modification,
13
are permitted (subject to the limitations in the disclaimer below) provided that
14
the following conditions are met:
15
16
     * Redistributions of source code must retain the above copyright notice,
17
     this list of conditions and the following disclaimer.
18
19
     * Redistributions in binary form must reproduce the above copyright
20
     notice, this list of conditions and the following disclaimer in the
21
     documentation and/or other materials provided with the distribution.
22
23
     * Neither the name of the copyright holder nor the names of its
24
     contributors may be used to endorse or promote products derived from this
25
     software without specific prior written permission.
26
27
NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED BY
28
THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
29
CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
30
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
31
PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
32
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
33
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
34
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
35
BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
36
IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
37
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
38
POSSIBILITY OF SUCH DAMAGE.
39
40
41
------------------------------------------------------------------------------------------- */
42
/** \file     CodingStructure.h
43
 *  \brief    A class managing the coding information for a specific image part
44
 */
45
46
#pragma once
47
48
#include "Unit.h"
49
#include "CommonDef.h"
50
#include "UnitPartitioner.h"
51
#include "Slice.h"
52
53
#include <vector>
54
#include <mutex>
55
56
//! \ingroup CommonLib
57
//! \{
58
59
namespace vvenc {
60
61
struct Picture;
62
63
64
enum PictureType
65
{
66
  PIC_RECONSTRUCTION = 0,
67
  PIC_ORIGINAL,
68
  PIC_FILT_ORIGINAL,
69
  PIC_PREDICTION,
70
  PIC_RESIDUAL,
71
  PIC_SAO_TEMP,
72
  NUM_PIC_TYPES,
73
};
74
75
// ---------------------------------------------------------------------------
76
// coding structure
77
// ---------------------------------------------------------------------------
78
79
class CodingStructure
80
{
81
public:
82
83
  UnitArea         area;
84
  UnitArea         _maxArea;
85
86
  Picture*         picture;
87
  CodingStructure* parent;
88
  CodingStructure* lumaCS;
89
  Slice*           slice;
90
91
  UnitScale        unitScale[MAX_NUM_COMP];
92
93
  int         baseQP;
94
  int         prevQP[MAX_NUM_CH];
95
  int         currQP[MAX_NUM_CH];
96
  int         chromaQpAdj; //th this seems to belong to CUCtx rather than to cs
97
  const SPS*  sps;
98
  const PPS*  pps;
99
  PicHeader*  picHeader;
100
  APS*        alfAps[ALF_CTB_MAX_NUM_APS];
101
  APS*        scalinglistAps;
102
  const VPS*  vps;
103
  const PreCalcValues* pcv;
104
105
  CodingStructure( XUCache& unitCache, std::mutex* mutex );
106
  void createPicLevel( const UnitArea& _unit, const PreCalcValues* _pcv );
107
  void createForSearch( const ChromaFormat _chromaFormat, const Area& _area );
108
  void destroy();
109
  void releaseIntermediateData();
110
111
  void rebindPicBufs();
112
  void createCoeffs();
113
  void destroyCoeffs();
114
115
  void allocateVectorsAtPicLevel();
116
117
  // ---------------------------------------------------------------------------
118
  // global accessors
119
  // ---------------------------------------------------------------------------
120
121
  const CodingUnit*    getCU(const Position& pos, const ChannelType _chType, const TreeType _treeType) const;
122
  const TransformUnit* getTU(const Position& pos, const ChannelType _chType, const int subTuIdx = -1) const;
123
124
  CodingUnit*          getCU(const Position& pos, const ChannelType _chType, const TreeType _treeType);
125
  CodingUnit*          getLumaCU( const Position& pos );
126
  TransformUnit*       getTU(const Position& pos, const ChannelType _chType, const int subTuIdx = -1);
127
128
0
  const CodingUnit*    getCU(const ChannelType& _chType, const TreeType _treeType) const { return getCU(area.blocks[_chType].pos(), _chType, _treeType); }
129
0
  const TransformUnit* getTU(const ChannelType& _chType) const { return getTU(area.blocks[_chType].pos(), _chType); }
130
131
651k
  CodingUnit*          getCU(const ChannelType& _chType, const TreeType _treeType ) { return getCU(area.blocks[_chType].pos(), _chType, _treeType); }
132
84.7k
  TransformUnit*       getTU(const ChannelType& _chType ) { return getTU(area.blocks[_chType].pos(), _chType); }
133
134
  const CodingUnit*    getCURestricted(const Position& pos, const Position curPos, const unsigned curSliceIdx, const unsigned curTileIdx, const ChannelType _chType, const TreeType treeType) const;
135
  const CodingUnit*    getCURestricted(const Position& pos, const CodingUnit& curCu,    const ChannelType _chType) const;
136
  const TransformUnit* getTURestricted(const Position& pos, const TransformUnit& curTu, const ChannelType _chType) const;
137
138
  CodingUnit&     addCU(const UnitArea& unit, const ChannelType _chType, CodingUnit* cuInit = nullptr);
139
  TransformUnit&  addTU(const UnitArea& unit, const ChannelType _chType, CodingUnit* cu, TransformUnit* tuInit = nullptr);
140
  void addEmptyTUs( Partitioner &partitioner, CodingUnit* cu );
141
142
  CUTraverser     traverseCUs(const UnitArea& _unit, const ChannelType _chType);
143
  TUTraverser     traverseTUs(const UnitArea& _unit, const ChannelType _chType);
144
145
  cCUTraverser    traverseCUs(const UnitArea& _unit, const ChannelType _chType) const;
146
  cTUTraverser    traverseTUs(const UnitArea& _unit, const ChannelType _chType) const;
147
  // ---------------------------------------------------------------------------
148
  // encoding search utilities
149
  // ---------------------------------------------------------------------------
150
151
  double      cost;
152
  double      costDbOffset;
153
  double      lumaCost;
154
  uint64_t    fracBits;
155
  Distortion  dist;
156
  Distortion  interHad;
157
158
  void initStructData  ( const int QP = MAX_INT, const bool skipMotBuf = true, const UnitArea* area = nullptr );
159
  void initSubStructure(      CodingStructure& cs, const ChannelType chType, const UnitArea& subArea, const bool isTuEnc, PelStorage* pOrgBuffer = nullptr, PelStorage* pFiltOrgBuffer = nullptr);
160
  void compactResize   ( const UnitArea& area );
161
162
  void copyStructure   (const CodingStructure& cs, const ChannelType chType, const TreeType treeType, const bool copyTUs = false, const bool copyRecoBuffer = false);
163
  void useSubStructure (      CodingStructure& cs, const ChannelType chType, const TreeType treeType, const UnitArea& subArea, const bool cpyRecoToPic = true);
164
165
  void clearTUs( bool force = false );
166
  void clearCUs( bool force = false );
167
168
  void createTempBuffers( const bool isTopLayer );
169
  void destroyTempBuffers();
170
private:
171
  void createInternals(const UnitArea& _unit, const bool isTopLayer);
172
173
public:
174
175
176
  std::vector<    CodingUnit*> cus;
177
  std::vector< TransformUnit*> tus;
178
179
  LutMotionCand motionLut;
180
  std::vector<LutMotionCand> motionLutBuf;
181
  void addMiToLut(static_vector<HPMVInfo, MAX_NUM_HMVP_CANDS>& lut, const HPMVInfo &mi);
182
183
private:
184
185
  // needed for TU encoding
186
  bool m_isTuEnc;
187
188
  CodingUnit**      m_cuPtr   [MAX_NUM_CH];
189
190
  unsigned m_numCUs;
191
  unsigned m_numTUs;
192
193
  CUCache& m_cuCache;
194
  TUCache& m_tuCache;
195
  std::mutex* m_unitCacheMutex;
196
197
  std::vector<SAOBlkParam> m_sao;
198
199
  PelStorage  m_pred;
200
  PelStorage  m_resi;
201
  PelStorage  m_reco;
202
  PelStorage  m_rspreco;
203
  PelStorage* m_org;
204
  PelStorage* m_filtorg;
205
206
  TCoeffSig*  m_coeffs [MAX_NUM_COMP];
207
  int         m_offsets[MAX_NUM_COMP];
208
209
  std::vector<Mv>   m_dmvrMvCache;
210
  int               m_dmvrMvCacheOffset;
211
212
  MotionInfo*       m_motionBuf;
213
214
  LoopFilterParam*  m_lfParam[NUM_EDGE_DIR];
215
216
  Size              m_mapSize[MAX_NUM_CH];
217
218
219
public:
220
  CodingStructure*  bestParent;
221
  bool              resetIBCBuffer;
222
223
  MotionBuf getMotionBuf( const     Area& _area );
224
127k
  MotionBuf getMotionBuf( const UnitArea& _area ) { return getMotionBuf( _area.Y() ); }
225
644k
  MotionBuf getMotionBuf()                        { return getMotionBuf(  area.Y() ); }
226
227
  const CMotionBuf getMotionBuf( const     Area& _area ) const;
228
0
  const CMotionBuf getMotionBuf( const UnitArea& _area ) const { return getMotionBuf( _area.Y() ); }
229
0
  const CMotionBuf getMotionBuf()                        const { return getMotionBuf(  area.Y() ); }
230
231
  MotionInfo& getMotionInfo( const Position& pos );
232
  const MotionInfo& getMotionInfo( const Position& pos ) const;
233
234
0
  MotionInfo const* getMiMapPtr()    const { return m_motionBuf; }
235
0
  MotionInfo      * getMiMapPtr()          { return m_motionBuf; }
236
0
  ptrdiff_t         getMiMapStride() const { return ( ptrdiff_t ) g_miScaling.scaleHor( area.Y().width ); }
237
238
  LFPBuf getLoopFilterParamBuf(const DeblockEdgeDir& edgeDir);
239
  const CLFPBuf getLoopFilterParamBuf(const DeblockEdgeDir& edgeDir) const;
240
241
0
  LoopFilterParam const* getLFPMapPtr   ( const DeblockEdgeDir edgeDir ) const { return m_lfParam[edgeDir]; }
242
579k
  LoopFilterParam      * getLFPMapPtr   ( const DeblockEdgeDir edgeDir )       { return m_lfParam[edgeDir]; }
243
449k
  ptrdiff_t              getLFPMapStride() const { return ( ptrdiff_t ) m_mapSize[CH_L].width; }
244
245
  UnitScale getScaling(const UnitScale::ScaliningType type, const ChannelType chType = CH_L) const
246
576k
  {
247
576k
    return type == UnitScale::MI_MAP ? g_miScaling : unitScale[chType];
248
576k
  }
249
250
public:
251
  // ---------------------------------------------------------------------------
252
  // temporary (shadowed) data accessors
253
  // ---------------------------------------------------------------------------
254
2.03M
         PelBuf       getPredBuf(const CompArea& blk)           { return getBuf(blk,  PIC_PREDICTION); }
255
0
  const CPelBuf       getPredBuf(const CompArea& blk)     const { return getBuf(blk,  PIC_PREDICTION); }
256
0
         PelUnitBuf   getPredBuf(const UnitArea& unit)          { return getBuf(unit, PIC_PREDICTION); }
257
0
  const CPelUnitBuf   getPredBuf(const UnitArea& unit)    const { return getBuf(unit, PIC_PREDICTION); }
258
259
4.03M
         PelBuf       getResiBuf(const CompArea& blk)           { return getBuf(blk,  PIC_RESIDUAL); }
260
0
  const CPelBuf       getResiBuf(const CompArea& blk)     const { return getBuf(blk,  PIC_RESIDUAL); }
261
22.7k
         PelUnitBuf   getResiBuf(const UnitArea& unit)          { return getBuf(unit, PIC_RESIDUAL); }
262
0
  const CPelUnitBuf   getResiBuf(const UnitArea& unit)    const { return getBuf(unit, PIC_RESIDUAL); }
263
264
9.34M
         PelBuf       getRecoBuf(const CompArea& blk)           { return getBuf(blk,  PIC_RECONSTRUCTION); }
265
0
  const CPelBuf       getRecoBuf(const CompArea& blk)     const { return getBuf(blk,  PIC_RECONSTRUCTION); }
266
304k
         PelUnitBuf   getRecoBuf(const UnitArea& unit)          { return getBuf(unit, PIC_RECONSTRUCTION); }
267
0
  const CPelUnitBuf   getRecoBuf(const UnitArea& unit)    const { return getBuf(unit, PIC_RECONSTRUCTION); }
268
269
1.96M
         PelBuf       getOrgBuf(const CompArea& blk)            { return getBuf(blk,  PIC_ORIGINAL); }
270
28.3k
  const CPelBuf       getOrgBuf(const CompArea& blk)      const { return getBuf(blk,  PIC_ORIGINAL); }
271
152k
         PelUnitBuf   getOrgBuf(const UnitArea& unit)           { return getBuf(unit, PIC_ORIGINAL); }
272
0
  const CPelUnitBuf   getOrgBuf(const UnitArea& unit)     const { return getBuf(unit, PIC_ORIGINAL); }
273
274
0
         PelBuf       getFiltOrgBuf(const CompArea& blk)        { return getBuf(blk,  PIC_FILT_ORIGINAL); }
275
0
  const CPelBuf       getFiltOrgBuf(const CompArea& blk)  const { return getBuf(blk,  PIC_FILT_ORIGINAL); }
276
277
0
         PelUnitBuf&  getRecoBufRef()                           { return m_reco; }
278
279
0
         PelBuf&      getFiltOrgBuf()                           { return m_filtorg->Y(); }
280
0
  const CPelBuf       getFiltOrgBuf()                     const { return m_filtorg->Y(); }
281
282
1.17M
         PelBuf       getOrgBuf(const ComponentID compID)       { return m_org->get(compID); }
283
0
  const CPelBuf       getOrgBuf(const ComponentID compID) const { return m_org->get(compID); }
284
0
         PelUnitBuf&  getOrgBuf()                               { return *m_org; }
285
0
  const CPelUnitBuf   getOrgBuf()                         const { return *m_org; }
286
287
  // pred buffer
288
2.46M
         PelBuf       getPredBuf(const ComponentID compID)      { return m_pred.get(compID); }
289
0
  const CPelBuf       getPredBuf(const ComponentID compID)const { return m_pred.get(compID); }
290
45.5k
         PelUnitBuf&  getPredBuf()                              { return m_pred; }
291
0
  const CPelUnitBuf   getPredBuf()                        const { return m_pred; }
292
293
  // resi buffer
294
2.35M
         PelBuf       getResiBuf(const ComponentID compID)      { return m_resi.get(compID); }
295
0
  const CPelBuf       getResiBuf(const ComponentID compID)const { return m_resi.get(compID); }
296
45.3k
         PelUnitBuf&  getResiBuf()                              { return m_resi; }
297
0
  const CPelUnitBuf   getResiBuf()                        const { return m_resi; }
298
299
  // reco buffer
300
11.5k
  const CPelBuf       getRecoBuf(const ComponentID compID)const { return m_reco.get(compID); }
301
2.18M
         PelBuf       getRecoBuf(const ComponentID compID)      { return m_reco.get(compID); }
302
27.7k
         PelUnitBuf&  getRecoBuf()                              { return m_reco; }
303
0
  const CPelUnitBuf   getRecoBuf()                        const { return m_reco; }
304
305
private:
306
307
         PelBuf       getBuf(const CompArea& blk,  const PictureType type);
308
  const CPelBuf       getBuf(const CompArea& blk,  const PictureType type) const;
309
         PelUnitBuf   getBuf(const UnitArea& unit, const PictureType type);
310
  const CPelUnitBuf   getBuf(const UnitArea& unit, const PictureType type) const;
311
};
312
313
314
4.81M
static inline uint32_t getNumberValidTBlocks(const PreCalcValues& pcv) { return (pcv.chrFormat==CHROMA_400) ? 1 : MAX_NUM_COMP; }
Unexecuted instantiation: vvencimpl.cpp:vvenc::getNumberValidTBlocks(vvenc::PreCalcValues const&)
Unexecuted instantiation: Rom.cpp:vvenc::getNumberValidTBlocks(vvenc::PreCalcValues const&)
Unexecuted instantiation: Slice.cpp:vvenc::getNumberValidTBlocks(vvenc::PreCalcValues const&)
Unexecuted instantiation: EncLib.cpp:vvenc::getNumberValidTBlocks(vvenc::PreCalcValues const&)
Unexecuted instantiation: PreProcess.cpp:vvenc::getNumberValidTBlocks(vvenc::PreCalcValues const&)
Unexecuted instantiation: RateCtrl.cpp:vvenc::getNumberValidTBlocks(vvenc::PreCalcValues const&)
Unexecuted instantiation: MCTF.cpp:vvenc::getNumberValidTBlocks(vvenc::PreCalcValues const&)
Unexecuted instantiation: Picture.cpp:vvenc::getNumberValidTBlocks(vvenc::PreCalcValues const&)
Unit.cpp:vvenc::getNumberValidTBlocks(vvenc::PreCalcValues const&)
Line
Count
Source
314
40.1k
static inline uint32_t getNumberValidTBlocks(const PreCalcValues& pcv) { return (pcv.chrFormat==CHROMA_400) ? 1 : MAX_NUM_COMP; }
Unexecuted instantiation: UnitTools.cpp:vvenc::getNumberValidTBlocks(vvenc::PreCalcValues const&)
Unexecuted instantiation: BitAllocation.cpp:vvenc::getNumberValidTBlocks(vvenc::PreCalcValues const&)
Unexecuted instantiation: EncGOP.cpp:vvenc::getNumberValidTBlocks(vvenc::PreCalcValues const&)
Unexecuted instantiation: EncPicture.cpp:vvenc::getNumberValidTBlocks(vvenc::PreCalcValues const&)
Unexecuted instantiation: EncSlice.cpp:vvenc::getNumberValidTBlocks(vvenc::PreCalcValues const&)
Unexecuted instantiation: GOPCfg.cpp:vvenc::getNumberValidTBlocks(vvenc::PreCalcValues const&)
InterSearch.cpp:vvenc::getNumberValidTBlocks(vvenc::PreCalcValues const&)
Line
Count
Source
314
45.4k
static inline uint32_t getNumberValidTBlocks(const PreCalcValues& pcv) { return (pcv.chrFormat==CHROMA_400) ? 1 : MAX_NUM_COMP; }
Unexecuted instantiation: SEIFilmGrainAnalyzer.cpp:vvenc::getNumberValidTBlocks(vvenc::PreCalcValues const&)
Unexecuted instantiation: SEIwrite.cpp:vvenc::getNumberValidTBlocks(vvenc::PreCalcValues const&)
Unexecuted instantiation: VLCWriter.cpp:vvenc::getNumberValidTBlocks(vvenc::PreCalcValues const&)
Unexecuted instantiation: AdaptiveLoopFilter.cpp:vvenc::getNumberValidTBlocks(vvenc::PreCalcValues const&)
Unexecuted instantiation: CodingStructure.cpp:vvenc::getNumberValidTBlocks(vvenc::PreCalcValues const&)
Unexecuted instantiation: ContextModelling.cpp:vvenc::getNumberValidTBlocks(vvenc::PreCalcValues const&)
Unexecuted instantiation: InterPrediction.cpp:vvenc::getNumberValidTBlocks(vvenc::PreCalcValues const&)
Unexecuted instantiation: LoopFilter.cpp:vvenc::getNumberValidTBlocks(vvenc::PreCalcValues const&)
Unexecuted instantiation: Mv.cpp:vvenc::getNumberValidTBlocks(vvenc::PreCalcValues const&)
Unexecuted instantiation: PicYuvMD5.cpp:vvenc::getNumberValidTBlocks(vvenc::PreCalcValues const&)
Unexecuted instantiation: Quant.cpp:vvenc::getNumberValidTBlocks(vvenc::PreCalcValues const&)
Unexecuted instantiation: SampleAdaptiveOffset.cpp:vvenc::getNumberValidTBlocks(vvenc::PreCalcValues const&)
Unexecuted instantiation: TrQuant.cpp:vvenc::getNumberValidTBlocks(vvenc::PreCalcValues const&)
Unexecuted instantiation: UnitPartitioner.cpp:vvenc::getNumberValidTBlocks(vvenc::PreCalcValues const&)
Unexecuted instantiation: CABACWriter.cpp:vvenc::getNumberValidTBlocks(vvenc::PreCalcValues const&)
Unexecuted instantiation: EncAdaptiveLoopFilter.cpp:vvenc::getNumberValidTBlocks(vvenc::PreCalcValues const&)
EncCu.cpp:vvenc::getNumberValidTBlocks(vvenc::PreCalcValues const&)
Line
Count
Source
314
329k
static inline uint32_t getNumberValidTBlocks(const PreCalcValues& pcv) { return (pcv.chrFormat==CHROMA_400) ? 1 : MAX_NUM_COMP; }
Unexecuted instantiation: EncModeCtrl.cpp:vvenc::getNumberValidTBlocks(vvenc::PreCalcValues const&)
Unexecuted instantiation: EncSampleAdaptiveOffset.cpp:vvenc::getNumberValidTBlocks(vvenc::PreCalcValues const&)
IntraSearch.cpp:vvenc::getNumberValidTBlocks(vvenc::PreCalcValues const&)
Line
Count
Source
314
4.40M
static inline uint32_t getNumberValidTBlocks(const PreCalcValues& pcv) { return (pcv.chrFormat==CHROMA_400) ? 1 : MAX_NUM_COMP; }
Unexecuted instantiation: DepQuant.cpp:vvenc::getNumberValidTBlocks(vvenc::PreCalcValues const&)
Unexecuted instantiation: IntraPrediction.cpp:vvenc::getNumberValidTBlocks(vvenc::PreCalcValues const&)
Unexecuted instantiation: MatrixIntraPrediction.cpp:vvenc::getNumberValidTBlocks(vvenc::PreCalcValues const&)
Unexecuted instantiation: QuantRDOQ2.cpp:vvenc::getNumberValidTBlocks(vvenc::PreCalcValues const&)
Unexecuted instantiation: DecCu.cpp:vvenc::getNumberValidTBlocks(vvenc::PreCalcValues const&)
Unexecuted instantiation: QuantRDOQ.cpp:vvenc::getNumberValidTBlocks(vvenc::PreCalcValues const&)
315
316
} // namespace vvenc
317
318
//! \}
319