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/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.46k
  StopClock() : m_startTime(), m_timer() {}
76
77
1.15k
  int  getTimerInSec() const { return (int)std::chrono::duration_cast<std::chrono::seconds>( m_timer ).count(); };
78
3.46k
  void resetTimer()          { m_timer = std::chrono::steady_clock::duration::zero(); }
79
4.62k
  void startTimer()          { m_startTime  = std::chrono::steady_clock::now(); }
80
4.62k
  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.24k
    : spatAct       { 0, 0 }
91
9.24k
    , prevTL0spatAct{ 0, 0 }
92
9.24k
    , visAct        ( 0 )
93
9.24k
    , visActTL0     ( 0 )
94
9.24k
  {
95
9.24k
  }
96
4.62k
  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.62k
    : m_bResetAMaxBT( true )
110
4.62k
  {
111
4.62k
  }
112
113
  ~BlkStat()
114
4.62k
  {
115
4.62k
  }
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.15k
  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
  // The reconstruction and the motion field are needed from the start of the picture's encoding
152
  // until the picture is released, not while it waits in the GOP queue.
153
  void createEncodingBuffers();
154
  void releaseEncodingBuffers();
155
156
  void extendPicBorder();
157
  void finalInit( const VPS& vps, const SPS& sps, const PPS& pps, PicHeader* picHeader, XUCache& unitCache, std::mutex* mutex, APS** alfAps );
158
  void setSccFlags( const VVEncCfg* encCfg );
159
160
2.31k
  int  getPOC()                                                     const { return poc; }
161
162
0
  const PelStorage& getOrigBuffer()                                       { return *m_sharedBufs[       PIC_ORIGINAL]; }
163
26.7k
         PelUnitBuf getOrigBuf()                                          { return getSharedBuf(        PIC_ORIGINAL); }
164
0
  const CPelUnitBuf getOrigBuf()                                    const { return getSharedBuf(        PIC_ORIGINAL); }
165
4.62k
  const CPelBuf     getOrigBuf(const ComponentID compID)            const { return getSharedBuf(compID, PIC_ORIGINAL); }
166
191k
  const CPelBuf     getOrigBuf(const CompArea& blk)                 const { return getSharedBuf(blk,    PIC_ORIGINAL); }
167
3.50k
  const CPelUnitBuf getOrigBuf(const UnitArea& unit)                const { return getSharedBuf(unit,   PIC_ORIGINAL); }
168
169
0
         PelBuf     getRecoBuf(const ComponentID compID)                  { return getPicBuf(compID, PIC_RECONSTRUCTION); }
170
0
  const CPelBuf     getRecoBuf(const ComponentID compID)            const { return getPicBuf(compID, PIC_RECONSTRUCTION); }
171
1.55M
         PelBuf     getRecoBuf(const CompArea& blk)                       { return getPicBuf(blk,    PIC_RECONSTRUCTION); }
172
0
  const CPelBuf     getRecoBuf(const CompArea& blk)                 const { return getPicBuf(blk,    PIC_RECONSTRUCTION); }
173
116k
         PelUnitBuf getRecoBuf(const UnitArea& unit)                      { return getPicBuf(unit,   PIC_RECONSTRUCTION); }
174
0
  const CPelUnitBuf getRecoBuf(const UnitArea& unit)                const { return getPicBuf(unit,   PIC_RECONSTRUCTION); }
175
19.2k
         PelUnitBuf getRecoBuf()                                          { return getPicBuf(        PIC_RECONSTRUCTION); }
176
1.15k
  const CPelUnitBuf getRecoBuf()                                    const { return getPicBuf(        PIC_RECONSTRUCTION); }
177
21.1k
         int        getRecoBufStride(const ComponentID compID)      const { return m_picBufs[PIC_RECONSTRUCTION].bufs[compID].stride; }
178
21.1k
  const  Pel*       getRecoBufPtr   (const ComponentID compID)      const { return m_picBufs[PIC_RECONSTRUCTION].bufs[compID].buf; }
179
180
167k
        PelStorage& getFilteredOrigBuffer()                               { return *m_sharedBufs[       PIC_FILT_ORIGINAL]; }
181
0
         PelUnitBuf getFiltOrigBuf()                                      { return getSharedBuf(        PIC_FILT_ORIGINAL); }
182
0
  const CPelUnitBuf getFiltOrigBuf()                                const { return getSharedBuf(        PIC_FILT_ORIGINAL); }
183
0
  const CPelBuf     getFiltOrigBuf(const ComponentID compID)        const { return getSharedBuf(compID, PIC_FILT_ORIGINAL); }
184
0
  const CPelBuf     getFiltOrigBuf(const CompArea& blk)             const { return getSharedBuf(blk,    PIC_FILT_ORIGINAL); }
185
0
  const CPelUnitBuf getFiltOrigBuf(const UnitArea& unit)            const { return getSharedBuf(unit,   PIC_FILT_ORIGINAL); }
186
187
  const CPelBuf     getOrigBufPrev(const CompArea &blk, const PrevFrameType type) const;
188
  const CPelUnitBuf getOrigBufPrev(const PrevFrameType type) const;
189
  const CPelBuf     getOrigBufPrev(const ComponentID compID, const PrevFrameType type) const;
190
191
private:
192
19.2k
         PelUnitBuf getPicBuf(                          const PictureType type)         { return m_picBufs[ type ]; }
193
1.15k
  const CPelUnitBuf getPicBuf(                          const PictureType type)   const { return m_picBufs[ type ]; }
194
0
         PelBuf     getPicBuf(const ComponentID compID, const PictureType type)         { return m_picBufs[ type ].getBuf( compID ); }
195
0
  const CPelBuf     getPicBuf(const ComponentID compID, const PictureType type)   const { return m_picBufs[ type ].getBuf( compID ); }
196
1.90M
         PelBuf     getPicBuf(const CompArea& blk,      const PictureType type)         { return ( !blk.valid() ) ? PelBuf() : m_picBufs[ type ].getBuf( blk ); }
197
0
  const CPelBuf     getPicBuf(const CompArea& blk,      const PictureType type)   const { return ( !blk.valid() ) ? PelBuf() : m_picBufs[ type ].getBuf( blk ); }
198
         PelUnitBuf getPicBuf(const UnitArea& unit,     const PictureType type);
199
  const CPelUnitBuf getPicBuf(const UnitArea& unit,     const PictureType type) const;
200
201
26.7k
         PelUnitBuf getSharedBuf(                          const PictureType type)         { return *m_sharedBufs[ type ]; }
202
0
  const CPelUnitBuf getSharedBuf(                          const PictureType type)   const { return *m_sharedBufs[ type ]; }
203
0
         PelBuf     getSharedBuf(const ComponentID compID, const PictureType type)         { return  m_sharedBufs[ type ]->getBuf( compID ); }
204
4.62k
  const CPelBuf     getSharedBuf(const ComponentID compID, const PictureType type)   const { return  m_sharedBufs[ type ]->getBuf( compID ); }
205
0
         PelBuf     getSharedBuf(const CompArea& blk,      const PictureType type)         { return ( !blk.valid() ) ? PelBuf() : m_sharedBufs[ type ]->getBuf( blk ); }
206
202k
  const CPelBuf     getSharedBuf(const CompArea& blk,      const PictureType type)   const { return ( !blk.valid() ) ? PelBuf() : m_sharedBufs[ type ]->getBuf( blk ); }
207
         PelUnitBuf getSharedBuf(const UnitArea& unit,     const PictureType type);
208
  const CPelUnitBuf getSharedBuf(const UnitArea& unit,     const PictureType type) const;
209
210
public:
211
  CodingStructure*              cs;
212
  const VPS*                    vps;
213
  const DCI*                    dci;
214
  ParameterSetMap<APS>          picApsMap;
215
  std::deque<Slice*>            slices;
216
  std::vector<const Slice*>     ctuSlice;
217
  SEIMessages                   SEIs;
218
  BlkStat                       picBlkStat;
219
  std::vector<OutputBitstream>  sliceDataStreams;
220
221
  bool                          isInitDone;
222
  std::atomic_bool              isReconstructed;
223
  bool                          isBorderExtended;
224
  bool                          isReferenced;
225
  bool                          isNeededForOutput;
226
  bool                          isFinished;
227
  bool                          isLongTerm;
228
  bool                          isFlush;
229
  bool                          isInProcessList;
230
  bool                          precedingDRAP; // preceding a DRAP picture in decoding order
231
232
  const GOPEntry*               gopEntry;
233
234
  int                           refCounter;
235
  int                           poc;
236
  unsigned                      TLayer;
237
  int                           layerId;
238
  bool                          isSubPicBorderSaved;
239
  int                           sliceDataNumBins;
240
  uint64_t                      cts;
241
  bool                          ctsValid;
242
  int64_t                       picsInMissing;      // summed up missing frames on input
243
  int64_t                       picOutOffset;       // signalization of pic offset to re-calc dts
244
  bool                          isPreAnalysis;
245
246
  PicShared*                    m_picShared;
247
248
  PelStorage                    m_picBufs[ NUM_PIC_TYPES ];
249
  PelStorage*                   m_sharedBufs[ NUM_PIC_TYPES ];
250
  PelStorage*                   m_bufsOrigPrev[ NUM_QPA_PREV_FRAMES ];
251
252
  std::vector<double>           ctuQpaLambda;
253
  std::vector<int>              ctuAdaptedQP;
254
  int                           gopAdaptedQP; // QP offset of GOP (delta relative to base QP)
255
  bool                          force2ndOrder; // force 2nd-order high-pass in activity calc.
256
  bool                          isSceneCutGOP;
257
  bool                          isSceneCutCheckAdjQP;
258
  bool                          isMeanQPLimited;
259
  std::mutex                    wppMutex;
260
  int                           picInitialQP;
261
  double                        picInitialLambda;
262
  int16_t                       picMemorySTA;
263
  PicVisAct                     picVA;
264
  double                        psnr[MAX_NUM_COMP];
265
  double                        mse [MAX_NUM_COMP];
266
267
  StopClock                     encTime;
268
  bool                          isSccWeak;
269
  bool                          isSccStrong;
270
  bool                          useME;
271
  bool                          useMCTF;
272
  bool                          useTS;
273
  bool                          useBDPCM;
274
  bool                          useIBC;
275
  bool                          useSAO;
276
  bool                          useNumRefs;
277
  bool                          useSelectiveRdoq;
278
  int                           useFastMrg;
279
  int                           useQtbttSpeedUpMode;
280
  int                           actualHeadBits;
281
  int                           actualTotalBits;
282
  EncRCPic*                     encRCPic;
283
  PicApsGlobal*                 picApsGlobal;
284
  PicApsGlobal*                 refApsGlobal;
285
286
  std::vector<SAOBlkParam>      m_sao[ 2 ];
287
  std::vector<uint8_t>          m_alfCtuEnabled[ MAX_NUM_COMP ];
288
  std::vector<short>            m_alfCtbFilterIndex;
289
  std::vector<uint8_t>          m_alfCtuAlternative[ MAX_NUM_COMP ];
290
  std::vector<std::atomic<int>>*  m_tileColsDone = nullptr;
291
292
  void*                         userData;
293
294
public:
295
  Slice*          allocateNewSlice();
296
  Slice*          swapSliceObject( Slice* p, uint32_t i );
297
298
7.00k
  SAOBlkParam    *getSAO    (int id = 0)                     { return &m_sao[id][0]; };
299
2.31k
  void            resizeSAO (unsigned numEntries, int dstid) { m_sao[dstid].resize(numEntries); }
300
0
  void            copySAO   (const Picture& src, int dstid)  { std::copy(src.m_sao[0].begin(), src.m_sao[0].end(), m_sao[dstid].begin()); }
301
302
  void            resizeAlfCtuBuffers( int numEntries );
303
};
304
305
int calcAndPrintHashStatus(const CPelUnitBuf& pic, const SEIDecodedPictureHash* pictureHashSEI, const BitDepths &bitDepths, const vvencMsgLevel msgl, MsgLog& logger );
306
307
typedef std::list<Picture*> PicList;
308
309
} // namespace vvenc
310
311
//! \}
312