Coverage Report

Created: 2026-10-17 06:56

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
  NUM_PIC_TYPES,
72
};
73
74
// ---------------------------------------------------------------------------
75
// coding structure
76
// ---------------------------------------------------------------------------
77
78
class CodingStructure
79
{
80
public:
81
82
  UnitArea         area;
83
  UnitArea         _maxArea;
84
85
  Picture*         picture;
86
  CodingStructure* parent;
87
  CodingStructure* lumaCS;
88
  Slice*           slice;
89
90
  UnitScale        unitScale[MAX_NUM_COMP];
91
92
  int         baseQP;
93
  int         prevQP[MAX_NUM_CH];
94
  int         currQP[MAX_NUM_CH];
95
  int         chromaQpAdj; //th this seems to belong to CUCtx rather than to cs
96
  const SPS*  sps;
97
  const PPS*  pps;
98
  PicHeader*  picHeader;
99
  APS*        alfAps[ALF_CTB_MAX_NUM_APS];
100
  APS*        scalinglistAps;
101
  const VPS*  vps;
102
  const PreCalcValues* pcv;
103
104
  CodingStructure( XUCache& unitCache, std::mutex* mutex );
105
  void createPicLevel( const UnitArea& _unit, const PreCalcValues* _pcv );
106
  void createForSearch( const ChromaFormat _chromaFormat, const Area& _area );
107
  void destroy();
108
  void releaseIntermediateData();
109
110
  void rebindPicBufs();
111
  void createCoeffs();
112
  void destroyCoeffs();
113
  void createMotionBuf();
114
  void destroyMotionBuf();
115
  // Other pictures read the motion of a picture only for temporal motion vector prediction, on an 8x8
116
  // grid (see CU::getColocatedMVP). When that prediction is enabled, each picture keeps its motion on
117
  // that grid in a colocated motion field, which the CTU tasks fill (CS::setColocatedMotionCTU), so that
118
  // the full motion field can be freed as soon as the picture is encoded.
119
  void createColocatedMotionBuf();
120
137k
  void destroyFullMotionBuf()        { delete[] m_motionBuf; m_motionBuf = nullptr; }
121
3.50k
  bool hasColocatedMotionBuf() const { return m_colocatedMotion != nullptr; }
122
  MotionInfo&       colocatedMotionInfo   ( const Position& pos );
123
  const MotionInfo& getColocatedMotionInfo( const Position& pos ) const;
124
125
  void allocateVectorsAtPicLevel();
126
  void releaseVectorsAtPicLevel();
127
128
  // ---------------------------------------------------------------------------
129
  // global accessors
130
  // ---------------------------------------------------------------------------
131
132
  const CodingUnit*    getCU(const Position& pos, const ChannelType _chType, const TreeType _treeType) const;
133
  const TransformUnit* getTU(const Position& pos, const ChannelType _chType, const int subTuIdx = -1) const;
134
135
  CodingUnit*          getCU(const Position& pos, const ChannelType _chType, const TreeType _treeType);
136
  CodingUnit*          getLumaCU( const Position& pos );
137
  TransformUnit*       getTU(const Position& pos, const ChannelType _chType, const int subTuIdx = -1);
138
139
0
  const CodingUnit*    getCU(const ChannelType& _chType, const TreeType _treeType) const { return getCU(area.blocks[_chType].pos(), _chType, _treeType); }
140
0
  const TransformUnit* getTU(const ChannelType& _chType) const { return getTU(area.blocks[_chType].pos(), _chType); }
141
142
614k
  CodingUnit*          getCU(const ChannelType& _chType, const TreeType _treeType ) { return getCU(area.blocks[_chType].pos(), _chType, _treeType); }
143
80.0k
  TransformUnit*       getTU(const ChannelType& _chType ) { return getTU(area.blocks[_chType].pos(), _chType); }
144
145
  const CodingUnit*    getCURestricted(const Position& pos, const Position curPos, const unsigned curSliceIdx, const unsigned curTileIdx, const ChannelType _chType, const TreeType treeType) const;
146
  const CodingUnit*    getCURestricted(const Position& pos, const CodingUnit& curCu,    const ChannelType _chType) const;
147
  const TransformUnit* getTURestricted(const Position& pos, const TransformUnit& curTu, const ChannelType _chType) const;
148
149
  CodingUnit&     addCU(const UnitArea& unit, const ChannelType _chType, CodingUnit* cuInit = nullptr);
150
  TransformUnit&  addTU(const UnitArea& unit, const ChannelType _chType, CodingUnit* cu, TransformUnit* tuInit = nullptr);
151
  void addEmptyTUs( Partitioner &partitioner, CodingUnit* cu );
152
153
  CUTraverser     traverseCUs(const UnitArea& _unit, const ChannelType _chType);
154
  TUTraverser     traverseTUs(const UnitArea& _unit, const ChannelType _chType);
155
156
  cCUTraverser    traverseCUs(const UnitArea& _unit, const ChannelType _chType) const;
157
  cTUTraverser    traverseTUs(const UnitArea& _unit, const ChannelType _chType) const;
158
  // ---------------------------------------------------------------------------
159
  // encoding search utilities
160
  // ---------------------------------------------------------------------------
161
162
  double      cost;
163
  double      costDbOffset;
164
  double      lumaCost;
165
  uint64_t    fracBits;
166
  Distortion  dist;
167
  Distortion  interHad;
168
169
  void initStructData  ( const int QP = MAX_INT, const bool skipMotBuf = true, const UnitArea* area = nullptr );
170
  void initSubStructure(      CodingStructure& cs, const ChannelType chType, const UnitArea& subArea, const bool isTuEnc, PelStorage* pOrgBuffer = nullptr );
171
  void compactResize   ( const UnitArea& area );
172
173
  void copyStructure   (const CodingStructure& cs, const ChannelType chType, const TreeType treeType, const bool copyTUs = false, const bool copyRecoBuffer = false);
174
  void useSubStructure (      CodingStructure& cs, const ChannelType chType, const TreeType treeType, const UnitArea& subArea, const bool cpyRecoToPic = true);
175
176
  void clearTUs( bool force = false );
177
  void clearCUs( bool force = false );
178
179
  void createTempBuffers( const bool isTopLayer );
180
  void destroyTempBuffers();
181
private:
182
  void createInternals(const UnitArea& _unit, const bool isTopLayer);
183
184
public:
185
186
187
  std::vector<    CodingUnit*> cus;
188
  std::vector< TransformUnit*> tus;
189
190
  LutMotionCand motionLut;
191
  std::vector<LutMotionCand> motionLutBuf;
192
  void addMiToLut(static_vector<HPMVInfo, MAX_NUM_HMVP_CANDS>& lut, const HPMVInfo &mi);
193
194
private:
195
196
  // needed for TU encoding
197
  bool m_isTuEnc;
198
199
  CodingUnit**      m_cuPtr   [MAX_NUM_CH];
200
201
  unsigned m_numCUs;
202
  unsigned m_numTUs;
203
204
  CUCache& m_cuCache;
205
  TUCache& m_tuCache;
206
  std::mutex* m_unitCacheMutex;
207
208
  std::vector<SAOBlkParam> m_sao;
209
210
  PelStorage  m_pred;
211
  PelStorage  m_resi;
212
  PelStorage  m_reco;
213
  PelStorage* m_org;
214
215
  TCoeffSig*  m_coeffs [MAX_NUM_COMP];
216
  int         m_offsets[MAX_NUM_COMP];
217
218
  std::vector<Mv>   m_dmvrMvCache;
219
  int               m_dmvrMvCacheOffset;
220
221
  MotionInfo*       m_motionBuf;
222
  MotionInfo*       m_colocatedMotion;        ///< motion on the temporal prediction grid, see createColocatedMotionBuf
223
  int               m_colocatedMotionStride;
224
225
  LoopFilterParam*  m_lfParam[NUM_EDGE_DIR];
226
227
  Size              m_mapSize[MAX_NUM_CH];
228
229
230
public:
231
  CodingStructure*  bestParent;
232
  bool              resetIBCBuffer;
233
234
  MotionBuf getMotionBuf( const     Area& _area );
235
118k
  MotionBuf getMotionBuf( const UnitArea& _area ) { return getMotionBuf( _area.Y() ); }
236
213k
  MotionBuf getMotionBuf()                        { return getMotionBuf(  area.Y() ); }
237
238
  const CMotionBuf getMotionBuf( const     Area& _area ) const;
239
0
  const CMotionBuf getMotionBuf( const UnitArea& _area ) const { return getMotionBuf( _area.Y() ); }
240
0
  const CMotionBuf getMotionBuf()                        const { return getMotionBuf(  area.Y() ); }
241
242
  MotionInfo& getMotionInfo( const Position& pos );
243
  const MotionInfo& getMotionInfo( const Position& pos ) const;
244
245
0
  MotionInfo const* getMiMapPtr()    const { return m_motionBuf; }
246
0
  MotionInfo      * getMiMapPtr()          { return m_motionBuf; }
247
0
  ptrdiff_t         getMiMapStride() const { return ( ptrdiff_t ) g_miScaling.scaleHor( area.Y().width ); }
248
249
  LFPBuf getLoopFilterParamBuf(const DeblockEdgeDir& edgeDir);
250
  const CLFPBuf getLoopFilterParamBuf(const DeblockEdgeDir& edgeDir) const;
251
252
0
  LoopFilterParam const* getLFPMapPtr   ( const DeblockEdgeDir edgeDir ) const { return m_lfParam[edgeDir]; }
253
537k
  LoopFilterParam      * getLFPMapPtr   ( const DeblockEdgeDir edgeDir )       { return m_lfParam[edgeDir]; }
254
416k
  ptrdiff_t              getLFPMapStride() const { return ( ptrdiff_t ) m_mapSize[CH_L].width; }
255
256
  UnitScale getScaling(const UnitScale::ScaliningType type, const ChannelType chType = CH_L) const
257
534k
  {
258
534k
    return type == UnitScale::MI_MAP ? g_miScaling : unitScale[chType];
259
534k
  }
260
261
public:
262
  // ---------------------------------------------------------------------------
263
  // temporary (shadowed) data accessors
264
  // ---------------------------------------------------------------------------
265
1.93M
         PelBuf       getPredBuf(const CompArea& blk)           { return getBuf(blk,  PIC_PREDICTION); }
266
0
  const CPelBuf       getPredBuf(const CompArea& blk)     const { return getBuf(blk,  PIC_PREDICTION); }
267
0
         PelUnitBuf   getPredBuf(const UnitArea& unit)          { return getBuf(unit, PIC_PREDICTION); }
268
0
  const CPelUnitBuf   getPredBuf(const UnitArea& unit)    const { return getBuf(unit, PIC_PREDICTION); }
269
270
3.83M
         PelBuf       getResiBuf(const CompArea& blk)           { return getBuf(blk,  PIC_RESIDUAL); }
271
0
  const CPelBuf       getResiBuf(const CompArea& blk)     const { return getBuf(blk,  PIC_RESIDUAL); }
272
21.1k
         PelUnitBuf   getResiBuf(const UnitArea& unit)          { return getBuf(unit, PIC_RESIDUAL); }
273
0
  const CPelUnitBuf   getResiBuf(const UnitArea& unit)    const { return getBuf(unit, PIC_RESIDUAL); }
274
275
8.86M
         PelBuf       getRecoBuf(const CompArea& blk)           { return getBuf(blk,  PIC_RECONSTRUCTION); }
276
0
  const CPelBuf       getRecoBuf(const CompArea& blk)     const { return getBuf(blk,  PIC_RECONSTRUCTION); }
277
286k
         PelUnitBuf   getRecoBuf(const UnitArea& unit)          { return getBuf(unit, PIC_RECONSTRUCTION); }
278
0
  const CPelUnitBuf   getRecoBuf(const UnitArea& unit)    const { return getBuf(unit, PIC_RECONSTRUCTION); }
279
280
1.86M
         PelBuf       getOrgBuf(const CompArea& blk)            { return getBuf(blk,  PIC_ORIGINAL); }
281
25.5k
  const CPelBuf       getOrgBuf(const CompArea& blk)      const { return getBuf(blk,  PIC_ORIGINAL); }
282
143k
         PelUnitBuf   getOrgBuf(const UnitArea& unit)           { return getBuf(unit, PIC_ORIGINAL); }
283
0
  const CPelUnitBuf   getOrgBuf(const UnitArea& unit)     const { return getBuf(unit, PIC_ORIGINAL); }
284
285
0
         PelUnitBuf&  getRecoBufRef()                           { return m_reco; }
286
287
1.11M
         PelBuf       getOrgBuf(const ComponentID compID)       { return m_org->get(compID); }
288
0
  const CPelBuf       getOrgBuf(const ComponentID compID) const { return m_org->get(compID); }
289
0
         PelUnitBuf&  getOrgBuf()                               { return *m_org; }
290
0
  const CPelUnitBuf   getOrgBuf()                         const { return *m_org; }
291
292
  // pred buffer
293
2.34M
         PelBuf       getPredBuf(const ComponentID compID)      { return m_pred.get(compID); }
294
0
  const CPelBuf       getPredBuf(const ComponentID compID)const { return m_pred.get(compID); }
295
42.2k
         PelUnitBuf&  getPredBuf()                              { return m_pred; }
296
0
  const CPelUnitBuf   getPredBuf()                        const { return m_pred; }
297
298
  // resi buffer
299
2.23M
         PelBuf       getResiBuf(const ComponentID compID)      { return m_resi.get(compID); }
300
0
  const CPelBuf       getResiBuf(const ComponentID compID)const { return m_resi.get(compID); }
301
42.1k
         PelUnitBuf&  getResiBuf()                              { return m_resi; }
302
0
  const CPelUnitBuf   getResiBuf()                        const { return m_resi; }
303
304
  // reco buffer
305
10.5k
  const CPelBuf       getRecoBuf(const ComponentID compID)const { return m_reco.get(compID); }
306
2.07M
         PelBuf       getRecoBuf(const ComponentID compID)      { return m_reco.get(compID); }
307
25.8k
         PelUnitBuf&  getRecoBuf()                              { return m_reco; }
308
0
  const CPelUnitBuf   getRecoBuf()                        const { return m_reco; }
309
310
private:
311
312
         PelBuf       getBuf(const CompArea& blk,  const PictureType type);
313
  const CPelBuf       getBuf(const CompArea& blk,  const PictureType type) const;
314
         PelUnitBuf   getBuf(const UnitArea& unit, const PictureType type);
315
  const CPelUnitBuf   getBuf(const UnitArea& unit, const PictureType type) const;
316
};
317
318
319
4.57M
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
319
37.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
319
42.2k
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
319
311k
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
319
4.18M
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&)
320
321
} // namespace vvenc
322
323
//! \}
324