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