Coverage Report

Created: 2026-08-31 06:22

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/work/vvdec/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) 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
/** \file     CodingStructure.h
44
 *  \brief    A class managing the coding information for a specific image part
45
 */
46
47
#pragma once
48
49
#include "Rom.h"
50
#include "Unit.h"
51
#include "Buffer.h"
52
#include "CommonDef.h"
53
#include "UnitPartitioner.h"
54
#include "Slice.h"
55
56
#include <vector>
57
58
namespace vvdec
59
{
60
61
struct Picture;
62
63
enum PictureType
64
{
65
  PIC_RECONSTRUCTION,
66
  PIC_RECON_WRAP,
67
  NUM_PIC_TYPES
68
};
69
70
#define NUM_PARTS_IN_CTU ( MAX_CU_SIZE * MAX_CU_SIZE ) >> (   MIN_CU_LOG2       << 1 )
71
// num collocated motion
72
#define NUM_COMOT_IN_CTU ( MAX_CU_SIZE * MAX_CU_SIZE ) >> ( ( MIN_CU_LOG2 + 1 ) << 1 )
73
74
75
struct CtuAlfData
76
{
77
  uint8_t ccAlfFilterControl[MAX_NUM_COMPONENT - 1];
78
  uint8_t alfCtuEnableFlag  [MAX_NUM_COMPONENT];
79
  uint8_t alfCtuAlternative [MAX_NUM_COMPONENT - 1];
80
  short   alfCtbFilterIndex;
81
82
0
  CtuAlfData() : ccAlfFilterControl{ 0, 0 }, alfCtuEnableFlag{ 0, 0, 0 } {}
83
};
84
85
struct CtuData
86
{
87
  SAOBlkParam           saoParam;
88
  CtuAlfData            alfParam;
89
  const Slice*          slice;
90
  const PPS*            pps;
91
  const SPS*            sps;
92
  const PicHeader*      ph;
93
  int                   lineIdx, colIdx, ctuIdx;
94
95
  CodingUnit           *firstCU, *lastCU;
96
  unsigned              numCUs, numTUs;
97
98
  ptrdiff_t             predBufOffset;
99
  ptrdiff_t             dmvrMvCacheOffset;
100
101
  CodingUnit**          cuPtr  [MAX_NUM_CHANNEL_TYPE];
102
  LoopFilterParam*      lfParam[NUM_EDGE_DIR];
103
  MotionInfo*           motion;
104
  ColocatedMotionInfo*  colMotion;
105
};
106
// ---------------------------------------------------------------------------
107
// coding structure
108
// ---------------------------------------------------------------------------
109
110
class CodingStructure
111
{
112
public:
113
114
  UnitArea         area;
115
116
  Picture         *picture;
117
118
  UnitScale        unitScale[MAX_NUM_COMPONENT];
119
  int              chromaQpAdj;
120
  std::shared_ptr<const VPS> vps;
121
  std::shared_ptr<const SPS> sps;
122
  std::shared_ptr<const PPS> pps;
123
  std::shared_ptr<PicHeader> picHeader;
124
  std::shared_ptr<const APS> alfApss[ALF_CTB_MAX_NUM_APS];
125
  std::shared_ptr<const APS> lmcsAps;
126
  const PreCalcValues*       pcv;
127
128
  std::unique_ptr<CtuData[]> m_ctuData;
129
  size_t                     m_ctuDataSize;
130
131
  // data for which memory is partially borrowed from DecLibRecon
132
  Pel*              m_predBuf;
133
  Mv*               m_dmvrMvCache;
134
  // end of partially borrowed data
135
  
136
  CodingStructure( CUChunkCache* cuChunkCache, TUChunkCache* tuChunkCache );
137
0
  ~CodingStructure() { destroy(); }
138
139
  void create(const UnitArea &_unit);
140
  void create(const ChromaFormat &_chromaFormat, const Area& _area);
141
  void destroy();
142
143
  void resetForUse();
144
  void rebindPicBufs();
145
146
  // ---------------------------------------------------------------------------
147
  // global accessors
148
  // ---------------------------------------------------------------------------
149
150
#if _DEBUG
151
  const CodingUnit*     getCU(Position pos, ChannelType _chType) const
152
0
  {
153
0
    if( area.blocks[_chType].contains( pos ) )
154
0
    {
155
0
      int rsAddr = ctuRsAddr( pos, _chType );
156
0
      int inCtu  = inCtuPos ( pos, _chType );
157
0
      return getCtuData( rsAddr ).cuPtr[_chType][inCtu];
158
0
    }
159
0
    else return nullptr;
160
0
  }
161
162
  CodingUnit*     getCU(Position pos, ChannelType _chType)
163
0
  {
164
0
    if( area.blocks[_chType].contains( pos ) )
165
0
    {
166
0
      int rsAddr = ctuRsAddr( pos, _chType );
167
0
      int inCtu  = inCtuPos ( pos, _chType );
168
0
      return getCtuData( rsAddr ).cuPtr[_chType][inCtu];
169
0
    }
170
0
    else return nullptr;
171
0
  }
172
#else
173
  const CodingUnit*     getCU(Position pos, ChannelType _chType) const { if( area.blocks[_chType].contains( pos ) ) return getCtuData( ctuRsAddr( pos, _chType ) ).cuPtr[_chType][inCtuPos( pos, _chType )]; else return nullptr; }
174
        CodingUnit*     getCU(Position pos, ChannelType _chType)       { if( area.blocks[_chType].contains( pos ) ) return getCtuData( ctuRsAddr( pos, _chType ) ).cuPtr[_chType][inCtuPos( pos, _chType )]; else return nullptr; }
175
#endif
176
177
  const CodingUnit*     getCURestricted(const Position &pos, const Position curPos, const unsigned curSliceIdx, const unsigned curTileIdx, const ChannelType _chType) const;
178
  const CodingUnit*     getCURestricted(const Position &pos, const CodingUnit& curCu,                                                      const ChannelType _chType, const CodingUnit* guess = nullptr) const;
179
180
  CodingUnit&     addCU(const UnitArea &unit, const ChannelType _chType, const TreeType treeType, const ModeType modeType, const CodingUnit* cuLeft, const CodingUnit* cuAbove );
181
  TransformUnit&  addTU(const UnitArea &unit, const ChannelType _chType, CodingUnit &cu);
182
  void            addEmptyTUs(Partitioner &partitioner, CodingUnit& cu);
183
  CUTraverser     traverseCUs(const int ctuRsAddr);
184
185
  void initStructData();
186
187
  void allocTempInternals();
188
  void deallocTempInternals();
189
190
  void createInternals(const UnitArea& _unit);
191
192
  CUCache    m_cuCache;
193
  TUCache    m_tuCache;
194
195
  PelStorage m_reco;
196
  PelStorage m_rec_wrap;
197
198
  unsigned int         m_widthInCtus;
199
  PosType              m_ctuSizeMask[2];
200
  PosType              m_ctuWidthLog2[2];
201
202
  std::unique_ptr<CodingUnit*[]>         m_cuMap;
203
  ptrdiff_t                              m_cuMapSize;
204
  std::unique_ptr<ColocatedMotionInfo[]> m_colMiMap;
205
  ptrdiff_t                              m_colMiMapSize;
206
207
public:
208
209
  // in CTU coordinates
210
0
  int ctuRsAddr( int col, int line ) const { return col + ( line * m_widthInCtus ); }
211
  // in sample coordinates
212
0
  int ctuRsAddr( Position pos, ChannelType chType ) const { Position posL = recalcPosition( area.chromaFormat, chType, CH_L, pos ); return ctuRsAddr( posL.x >> pcv->maxCUWidthLog2, posL.y >> pcv->maxCUHeightLog2 ); }
213
  // 4x4 luma block position within the CTU
214
0
  int inCtuPos ( Position pos, ChannelType chType ) const { return ( unitScale[chType].scaleHor( pos.x ) & m_ctuSizeMask[chType] ) + ( ( unitScale[chType].scaleVer( pos.y ) & m_ctuSizeMask[chType] ) << m_ctuWidthLog2[chType] ); }
215
  // 8x8 luma block position within the CTU
216
0
  int colMotPos( Position pos )                     const { return ( g_colMiScaling.scaleHor( pos.x ) & ( m_ctuSizeMask[CH_L] >> 1 ) ) + ( ( g_colMiScaling.scaleVer( pos.y ) & ( m_ctuSizeMask[CH_L] >> 1 ) ) << ( m_ctuWidthLog2[CH_L] - 1 ) ); }
217
218
0
        CtuData& getCtuData( int col, int line )       { return m_ctuData[ctuRsAddr( col, line )]; }
219
0
  const CtuData& getCtuData( int col, int line ) const { return m_ctuData[ctuRsAddr( col, line )]; }
220
221
0
        CtuData& getCtuData( int addr )       { return m_ctuData[addr]; }
222
0
  const CtuData& getCtuData( int addr ) const { return m_ctuData[addr]; }
223
224
  int m_IBCBufferWidth;
225
  std::vector<PelStorage> m_virtualIBCbuf;
226
  std::vector<char>       hasIbcBlock;
227
  void initVIbcBuf( int numCtuLines, ChromaFormat chromaFormatIDC, int ctuSize );
228
  void fillIBCbuffer( CodingUnit &cu, int lineIdx );
229
230
  MotionBuf getMotionBuf( const     Area& _area );
231
0
  MotionBuf getMotionBuf( const UnitArea& _area ) { return getMotionBuf( _area.Y() ); }
232
233
  const CMotionBuf getMotionBuf( const     Area& _area ) const;
234
0
  const CMotionBuf getMotionBuf( const UnitArea& _area ) const { return getMotionBuf( _area.Y() ); }
235
236
0
        MotionInfo& getMotionInfo( const Position& pos )       { return getCtuData( ctuRsAddr( pos, CH_L ) ).motion[inCtuPos( pos, CH_L )]; }
237
0
  const MotionInfo& getMotionInfo( const Position& pos ) const { return getCtuData( ctuRsAddr( pos, CH_L ) ).motion[inCtuPos( pos, CH_L )]; }
238
  
239
240
  const ColocatedMotionInfo& getColInfo( const Position &pos, const Slice*& pColSlice ) const;
241
242
0
  LoopFilterParam const* getLFPMapPtr   ( const DeblockEdgeDir edgeDir, ptrdiff_t _ctuRsAddr ) const { return m_ctuData[_ctuRsAddr].lfParam[edgeDir]; }
243
0
  LoopFilterParam      * getLFPMapPtr   ( const DeblockEdgeDir edgeDir, ptrdiff_t _ctuRsAddr )       { return m_ctuData[_ctuRsAddr].lfParam[edgeDir]; }
244
0
  ptrdiff_t              get4x4MapStride() const { return ( ptrdiff_t( 1 ) << m_ctuWidthLog2[CH_L] ); }
245
246
  UnitScale getScaling( const UnitScale::ScaliningType type, const ChannelType chType = CH_L ) const
247
0
  {
248
0
    return type == UnitScale::MI_MAP ? g_miScaling : unitScale[chType];
249
0
  }
250
251
public:
252
253
0
         PelBuf       getRecoBuf(const CompArea &blk)        { return m_reco.bufs[blk.compID()].subBuf( blk ); }
254
0
  const CPelBuf       getRecoBuf(const CompArea &blk) const  { return m_reco.bufs[blk.compID()].subBuf( blk ); }
255
0
         PelUnitBuf   getRecoBuf(const UnitArea &unit)       { return m_reco.subBuf( unit ); }
256
0
  const CPelUnitBuf   getRecoBuf(const UnitArea &unit) const { return m_reco.subBuf( unit ); }
257
258
259
260
  // reco buffer
261
0
         PelBuf       getRecoBuf(const ComponentID compID, bool wrap=false)         { return wrap ? m_rec_wrap.get(compID) : m_reco.get(compID); }
262
0
  const CPelBuf       getRecoBuf(const ComponentID compID, bool wrap=false)   const { return wrap ? m_rec_wrap.get(compID) : m_reco.get(compID); }
263
0
         PelUnitBuf   getRecoBuf(bool wrap=false)                                   { return wrap ? m_rec_wrap : m_reco; }
264
0
  const CPelUnitBuf   getRecoBuf(bool wrap=false)                             const { return wrap ? m_rec_wrap : m_reco; }
265
266
         PelUnitBuf   getPredBuf(const CodingUnit &cu);
267
  const CPelUnitBuf   getPredBuf(const CodingUnit &cu) const;
268
};
269
270
}