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/Picture.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     Picture.h
43
 *  \brief    Description of a coded picture
44
 */
45
46
#pragma once
47
48
#include "CommonDef.h"
49
#include "Common.h"
50
#include "Unit.h"
51
#include "Slice.h"
52
#include "CodingStructure.h"
53
#include "BitStream.h"
54
#include "Reshape.h"
55
56
#include <deque>
57
#include <chrono>
58
#include <atomic>
59
60
//! \ingroup CommonLib
61
//! \{
62
63
namespace vvenc {
64
65
class SEI;
66
class SEIDecodedPictureHash;
67
class EncRCPic;
68
class PicShared;
69
class MsgLog;
70
71
typedef std::list<SEI*> SEIMessages;
72
73
74
struct StopClock
75
{
76
0
  StopClock() : m_startTime(), m_timer() {}
77
78
0
  int  getTimerInSec() const { return (int)std::chrono::duration_cast<std::chrono::seconds>( m_timer ).count(); };
79
0
  void resetTimer()          { m_timer = std::chrono::steady_clock::duration::zero(); }
80
0
  void startTimer()          { m_startTime  = std::chrono::steady_clock::now(); }
81
0
  void stopTimer()           { auto endTime = std::chrono::steady_clock::now(); m_timer += endTime - m_startTime; m_startTime = endTime; }
82
83
  std::chrono::steady_clock::time_point m_startTime;
84
  std::chrono::steady_clock::duration   m_timer;
85
};
86
87
88
struct PicVisAct
89
{
90
  PicVisAct()
91
0
    : spatAct       { 0, 0 }
92
0
    , prevTL0spatAct{ 0, 0 }
93
0
    , visAct        ( 0 )
94
0
    , visActTL0     ( 0 )
95
0
  {
96
0
  }
97
0
  void reset() { *this = PicVisAct(); }
98
  uint16_t spatAct[MAX_NUM_CH];
99
  uint16_t prevTL0spatAct[MAX_NUM_CH];
100
  uint16_t visAct;
101
  uint16_t visActTL0;
102
};
103
104
struct Picture;
105
106
class BlkStat
107
{
108
public:
109
  BlkStat()
110
0
    : m_bResetAMaxBT( true )
111
0
  {
112
0
  }
113
114
  ~BlkStat()
115
0
  {
116
0
  }
117
118
  void storeBlkSize ( const Picture& pic );
119
  void updateMaxBT  ( const Slice& slice, const BlkStat& blkStat );
120
  void setSliceMaxBT( Slice& slice );
121
122
protected:
123
  uint32_t m_uiBlkSize[NUM_AMAXBT_LAYER];
124
  uint32_t m_uiNumBlk[NUM_AMAXBT_LAYER];
125
  uint32_t m_uiPrevISlicePOC;
126
  bool     m_bResetAMaxBT;
127
};
128
129
struct PicApsGlobal{
130
  int      poc;
131
  unsigned tid;
132
  bool     initalized = false;
133
  int      refCnt = 0;
134
  ParameterSetMap<APS> apsMap;
135
0
  PicApsGlobal( int _p ) : poc(_p), tid(MAX_UINT), apsMap( MAX_NUM_APS * MAX_NUM_APS_TYPE ) {}
136
0
  PicApsGlobal( int _p, unsigned _t ) : poc(_p), tid(_t), apsMap( MAX_NUM_APS * MAX_NUM_APS_TYPE ) {}
137
};
138
139
struct Picture : public UnitArea
140
{
141
  uint32_t margin;
142
  Picture();
143
144
  void create( ChromaFormat _chromaFormat, const Size& size, unsigned _maxCUSize, unsigned _margin, bool _decoder );
145
  void reset();
146
  void destroy( bool bPicHeader );
147
148
  void linkSharedBuffers( PelStorage* origBuf, PelStorage* filteredBuf, PelStorage* prevOrigBufs[ NUM_QPA_PREV_FRAMES ], PicShared* picShared );
149
  void releasePrevBuffers();
150
  void releaseSharedBuffers();
151
152
  void createTempBuffers( unsigned _maxCUSize );
153
  void destroyTempBuffers();
154
155
  void extendPicBorder();
156
  void finalInit( const VPS& vps, const SPS& sps, const PPS& pps, PicHeader* picHeader, XUCache& unitCache, std::mutex* mutex, APS** alfAps, APS* lmcsAps );
157
  void setSccFlags( const VVEncCfg* encCfg );
158
159
0
  int  getPOC()                                                     const { return poc; }
160
161
0
  const PelStorage& getOrigBuffer()                                       { return *m_sharedBufs[       PIC_ORIGINAL]; }
162
0
         PelUnitBuf getOrigBuf()                                          { return getSharedBuf(        PIC_ORIGINAL); }
163
0
  const CPelUnitBuf getOrigBuf()                                    const { return getSharedBuf(        PIC_ORIGINAL); }
164
0
  const CPelBuf     getOrigBuf(const ComponentID compID)            const { return getSharedBuf(compID, PIC_ORIGINAL); }
165
0
  const CPelBuf     getOrigBuf(const CompArea& blk)                 const { return getSharedBuf(blk,    PIC_ORIGINAL); }
166
0
  const CPelUnitBuf getOrigBuf(const UnitArea& unit)                const { return getSharedBuf(unit,   PIC_ORIGINAL); }
167
168
0
         PelBuf     getRecoBuf(const ComponentID compID)                  { return getPicBuf(compID, PIC_RECONSTRUCTION); }
169
0
  const CPelBuf     getRecoBuf(const ComponentID compID)            const { return getPicBuf(compID, PIC_RECONSTRUCTION); }
170
0
         PelBuf     getRecoBuf(const CompArea& blk)                       { return getPicBuf(blk,    PIC_RECONSTRUCTION); }
171
0
  const CPelBuf     getRecoBuf(const CompArea& blk)                 const { return getPicBuf(blk,    PIC_RECONSTRUCTION); }
172
0
         PelUnitBuf getRecoBuf(const UnitArea& unit)                      { return getPicBuf(unit,   PIC_RECONSTRUCTION); }
173
0
  const CPelUnitBuf getRecoBuf(const UnitArea& unit)                const { return getPicBuf(unit,   PIC_RECONSTRUCTION); }
174
0
         PelUnitBuf getRecoBuf()                                          { return getPicBuf(        PIC_RECONSTRUCTION); }
175
0
  const CPelUnitBuf getRecoBuf()                                    const { return getPicBuf(        PIC_RECONSTRUCTION); }
176
0
         int        getRecoBufStride(const ComponentID compID)      const { return m_picBufs[PIC_RECONSTRUCTION].bufs[compID].stride; }
177
0
  const  Pel*       getRecoBufPtr   (const ComponentID compID)      const { return m_picBufs[PIC_RECONSTRUCTION].bufs[compID].buf; }
178
179
0
         PelUnitBuf getSaoBuf()                                           { return getPicBuf(        PIC_SAO_TEMP); }
180
0
  const CPelUnitBuf getSaoBuf()                                     const { return getPicBuf(        PIC_SAO_TEMP); }
181
182
0
        PelStorage& getFilteredOrigBuffer()                               { return *m_sharedBufs[       PIC_ORIGINAL_RSP]; }
183
0
         PelUnitBuf getRspOrigBuf()                                       { return getSharedBuf(        PIC_ORIGINAL_RSP); }
184
0
  const CPelUnitBuf getRspOrigBuf()                                 const { return getSharedBuf(        PIC_ORIGINAL_RSP); }
185
0
  const CPelBuf     getRspOrigBuf(const ComponentID compID)         const { return getSharedBuf(compID, PIC_ORIGINAL_RSP); }
186
0
  const CPelBuf     getRspOrigBuf(const CompArea& blk)              const { return getSharedBuf(blk,    PIC_ORIGINAL_RSP); }
187
0
  const CPelUnitBuf getRspOrigBuf(const UnitArea& unit)             const { return getSharedBuf(unit,   PIC_ORIGINAL_RSP); }
188
189
  const CPelBuf     getOrigBufPrev(const CompArea &blk, const PrevFrameType type) const;
190
  const CPelUnitBuf getOrigBufPrev(const PrevFrameType type) const;
191
  const CPelBuf     getOrigBufPrev(const ComponentID compID, const PrevFrameType type) const;
192
193
private:
194
0
         PelUnitBuf getPicBuf(                          const PictureType type)         { return m_picBufs[ type ]; }
195
0
  const CPelUnitBuf getPicBuf(                          const PictureType type)   const { return m_picBufs[ type ]; }
196
0
         PelBuf     getPicBuf(const ComponentID compID, const PictureType type)         { return m_picBufs[ type ].getBuf( compID ); }
197
0
  const CPelBuf     getPicBuf(const ComponentID compID, const PictureType type)   const { return m_picBufs[ type ].getBuf( compID ); }
198
0
         PelBuf     getPicBuf(const CompArea& blk,      const PictureType type)         { return ( !blk.valid() ) ? PelBuf() : m_picBufs[ type ].getBuf( blk ); }
199
0
  const CPelBuf     getPicBuf(const CompArea& blk,      const PictureType type)   const { return ( !blk.valid() ) ? PelBuf() : m_picBufs[ type ].getBuf( blk ); }
200
         PelUnitBuf getPicBuf(const UnitArea& unit,     const PictureType type);
201
  const CPelUnitBuf getPicBuf(const UnitArea& unit,     const PictureType type) const;
202
203
0
         PelUnitBuf getSharedBuf(                          const PictureType type)         { return *m_sharedBufs[ type ]; }
204
0
  const CPelUnitBuf getSharedBuf(                          const PictureType type)   const { return *m_sharedBufs[ type ]; }
205
0
         PelBuf     getSharedBuf(const ComponentID compID, const PictureType type)         { return  m_sharedBufs[ type ]->getBuf( compID ); }
206
0
  const CPelBuf     getSharedBuf(const ComponentID compID, const PictureType type)   const { return  m_sharedBufs[ type ]->getBuf( compID ); }
207
0
         PelBuf     getSharedBuf(const CompArea& blk,      const PictureType type)         { return ( !blk.valid() ) ? PelBuf() : m_sharedBufs[ type ]->getBuf( blk ); }
208
0
  const CPelBuf     getSharedBuf(const CompArea& blk,      const PictureType type)   const { return ( !blk.valid() ) ? PelBuf() : m_sharedBufs[ type ]->getBuf( blk ); }
209
         PelUnitBuf getSharedBuf(const UnitArea& unit,     const PictureType type);
210
  const CPelUnitBuf getSharedBuf(const UnitArea& unit,     const PictureType type) const;
211
212
public:
213
  CodingStructure*              cs;
214
  const VPS*                    vps;
215
  const DCI*                    dci;
216
  ParameterSetMap<APS>          picApsMap;
217
  std::deque<Slice*>            slices;
218
  std::vector<const Slice*>     ctuSlice;
219
  ReshapeData                   reshapeData;
220
  SEIMessages                   SEIs;
221
  BlkStat                       picBlkStat;
222
  std::vector<OutputBitstream>  sliceDataStreams;
223
224
  bool                          isInitDone;
225
  std::atomic_bool              isReconstructed;
226
  bool                          isBorderExtended;
227
  bool                          isReferenced;
228
  bool                          isNeededForOutput;
229
  bool                          isFinished;
230
  bool                          isLongTerm;
231
  bool                          isFlush;
232
  bool                          isInProcessList;
233
  bool                          precedingDRAP; // preceding a DRAP picture in decoding order
234
235
  const GOPEntry*               gopEntry;
236
237
  int                           refCounter;
238
  int                           poc;
239
  unsigned                      TLayer;
240
  int                           layerId;
241
  bool                          isSubPicBorderSaved;
242
  int                           sliceDataNumBins;
243
  uint64_t                      cts;
244
  bool                          ctsValid;
245
  int64_t                       picsInMissing;      // summed up missing frames on input
246
  int64_t                       picOutOffset;       // signalization of pic offset to re-calc dts
247
  bool                          isPreAnalysis;
248
249
  PicShared*                    m_picShared;
250
251
  PelStorage                    m_picBufs[ NUM_PIC_TYPES ];
252
  PelStorage*                   m_sharedBufs[ NUM_PIC_TYPES ];
253
  PelStorage*                   m_bufsOrigPrev[ NUM_QPA_PREV_FRAMES ];
254
255
  std::vector<double>           ctuQpaLambda;
256
  std::vector<int>              ctuAdaptedQP;
257
  int                           gopAdaptedQP; // QP offset of GOP (delta relative to base QP)
258
  bool                          force2ndOrder; // force 2nd-order high-pass in activity calc.
259
  bool                          isSceneCutGOP;
260
  bool                          isSceneCutCheckAdjQP;
261
  bool                          isMeanQPLimited;
262
  std::mutex                    wppMutex;
263
  int                           picInitialQP;
264
  double                        picInitialLambda;
265
  int16_t                       picMemorySTA;
266
  PicVisAct                     picVA;
267
  double                        psnr[MAX_NUM_COMP];
268
  double                        mse [MAX_NUM_COMP];
269
270
  StopClock                     encTime;
271
  bool                          isSccWeak;
272
  bool                          isSccStrong;
273
  bool                          useME;
274
  bool                          useMCTF;
275
  bool                          useTS;
276
  bool                          useBDPCM;
277
  bool                          useIBC;
278
  bool                          useLMCS;
279
  bool                          useSAO;
280
  bool                          useNumRefs;
281
  bool                          useSelectiveRdoq;
282
  int                           useFastMrg;
283
  int                           useQtbttSpeedUpMode;
284
  int                           actualHeadBits;
285
  int                           actualTotalBits;
286
  EncRCPic*                     encRCPic;
287
  PicApsGlobal*                 picApsGlobal;
288
  PicApsGlobal*                 refApsGlobal;
289
290
  std::vector<SAOBlkParam>      m_sao[ 2 ];
291
  std::vector<uint8_t>          m_alfCtuEnabled[ MAX_NUM_COMP ];
292
  std::vector<short>            m_alfCtbFilterIndex;
293
  std::vector<uint8_t>          m_alfCtuAlternative[ MAX_NUM_COMP ];
294
  std::vector<std::atomic<int>>*  m_tileColsDone = nullptr;
295
296
  void*                         userData;
297
298
public:
299
  Slice*          allocateNewSlice();
300
  Slice*          swapSliceObject( Slice* p, uint32_t i );
301
302
0
  SAOBlkParam    *getSAO    (int id = 0)                     { return &m_sao[id][0]; };
303
0
  void            resizeSAO (unsigned numEntries, int dstid) { m_sao[dstid].resize(numEntries); }
304
0
  void            copySAO   (const Picture& src, int dstid)  { std::copy(src.m_sao[0].begin(), src.m_sao[0].end(), m_sao[dstid].begin()); }
305
306
  void            resizeAlfCtuBuffers( int numEntries );
307
};
308
309
int calcAndPrintHashStatus(const CPelUnitBuf& pic, const SEIDecodedPictureHash* pictureHashSEI, const BitDepths &bitDepths, const vvencMsgLevel msgl, MsgLog& logger );
310
311
typedef std::list<Picture*> PicList;
312
313
} // namespace vvenc
314
315
//! \}
316