Coverage Report

Created: 2026-10-28 06:18

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
4.47k
  StopClock() : m_startTime(), m_timer() {}
76
77
1.49k
  int  getTimerInSec() const { return (int)std::chrono::duration_cast<std::chrono::seconds>( m_timer ).count(); };
78
4.47k
  void resetTimer()          { m_timer = std::chrono::steady_clock::duration::zero(); }
79
5.97k
  void startTimer()          { m_startTime  = std::chrono::steady_clock::now(); }
80
5.97k
  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
11.9k
    : spatAct       { 0, 0 }
91
11.9k
    , prevTL0spatAct{ 0, 0 }
92
11.9k
    , visAct        ( 0 )
93
11.9k
    , visActTL0     ( 0 )
94
11.9k
  {
95
11.9k
  }
96
5.97k
  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
5.97k
    : m_bResetAMaxBT( true )
110
5.97k
  {
111
5.97k
  }
112
113
  ~BlkStat()
114
5.97k
  {
115
5.97k
  }
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.49k
  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.98k
  int  getPOC()                                                     const { return poc; }
161
162
0
  const PelStorage& getOrigBuffer()                                       { return *m_sharedBufs[       PIC_ORIGINAL]; }
163
37.2k
         PelUnitBuf getOrigBuf()                                          { return getSharedBuf(        PIC_ORIGINAL); }
164
0
  const CPelUnitBuf getOrigBuf()                                    const { return getSharedBuf(        PIC_ORIGINAL); }
165
5.97k
  const CPelBuf     getOrigBuf(const ComponentID compID)            const { return getSharedBuf(compID, PIC_ORIGINAL); }
166
265k
  const CPelBuf     getOrigBuf(const CompArea& blk)                 const { return getSharedBuf(blk,    PIC_ORIGINAL); }
167
4.97k
  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
2.09M
         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
157k
         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
26.7k
         PelUnitBuf getRecoBuf()                                          { return getPicBuf(        PIC_RECONSTRUCTION); }
176
1.49k
  const CPelUnitBuf getRecoBuf()                                    const { return getPicBuf(        PIC_RECONSTRUCTION); }
177
29.1k
         int        getRecoBufStride(const ComponentID compID)      const { return m_picBufs[PIC_RECONSTRUCTION].bufs[compID].stride; }
178
29.1k
  const  Pel*       getRecoBufPtr   (const ComponentID compID)      const { return m_picBufs[PIC_RECONSTRUCTION].bufs[compID].buf; }
179
180
230k
        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
26.7k
         PelUnitBuf getPicBuf(                          const PictureType type)         { return m_picBufs[ type ]; }
193
1.49k
  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
2.57M
         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
37.2k
         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
5.97k
  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
280k
  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
  double                        picQPFraction; // fractional part of the picture QP with a fractional --qp, applied by QPA
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
9.95k
  SAOBlkParam    *getSAO    (int id = 0)                     { return &m_sao[id][0]; };
300
2.98k
  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