DecLib.h 15.3 KB
Newer Older
1
2
3
4
5
/* The copyright in this software is being made available under the BSD
 * License, included below. This software may be subject to other third party
 * and contributor rights, including patent rights, and no such rights are
 * granted under this license.
 *
6
 * Copyright (c) 2010-2021, ITU/ISO/IEC
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 *  * Redistributions of source code must retain the above copyright notice,
 *    this list of conditions and the following disclaimer.
 *  * Redistributions in binary form must reproduce the above copyright notice,
 *    this list of conditions and the following disclaimer in the documentation
 *    and/or other materials provided with the distribution.
 *  * Neither the name of the ITU/ISO/IEC nor the names of its contributors may
 *    be used to endorse or promote products derived from this software without
 *    specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS
 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
 * THE POSSIBILITY OF SUCH DAMAGE.
 */

/** \file     DecLib.h
    \brief    decoder class (header)
*/

#ifndef __DECLIB__
#define __DECLIB__

#include "DecSlice.h"
#include "CABACReader.h"
#include "VLCReader.h"
#include "SEIread.h"
#include "CacheModel.h"

#include "CommonLib/CommonDef.h"
#include "CommonLib/Picture.h"
#include "CommonLib/TrQuant.h"
#include "CommonLib/InterPrediction.h"
#include "CommonLib/IntraPrediction.h"
#include "CommonLib/LoopFilter.h"
#include "CommonLib/AdaptiveLoopFilter.h"
#include "CommonLib/SEI.h"
#include "CommonLib/Unit.h"
Taoran Lu's avatar
Taoran Lu committed
56
#include "CommonLib/Reshape.h"
57
58
59
60
61
62

class InputNALUnit;

//! \ingroup DecoderLib
//! \{

63
bool tryDecodePicture( Picture* pcPic, const int expectedPoc, const std::string& bitstreamFileName, ParameterSetMap<APS> *apsMap = nullptr, bool bDecodeUntilPocFound = false, int debugCTU = -1, int debugPOC = -1 );
64
65
66
67
68
69
70
71
// Class definition
// ====================================================================================================================

/// decoder class
class DecLib
{
private:
  int                     m_iMaxRefPicNum;
72
73
  bool m_isFirstGeneralHrd;
  GeneralHrdParams        m_prevGeneralHrdParams;
74

Zhipin Deng's avatar
cleanup    
Zhipin Deng committed
75
  int                     m_prevGDRInSameLayerPOC[MAX_VPS_LAYERS]; ///< POC number of the latest GDR picture
Jack Enhorn's avatar
Jack Enhorn committed
76
  int                     m_prevGDRInSameLayerRecoveryPOC[MAX_VPS_LAYERS]; ///< Recovery POC number of the latest GDR picture
77
78
79
  NalUnitType             m_associatedIRAPType[MAX_VPS_LAYERS]; ///< NAL unit type of the previous IRAP picture
  int                     m_pocCRA[MAX_VPS_LAYERS];            ///< POC number of the previous CRA picture
  int                     m_associatedIRAPDecodingOrderNumber[MAX_VPS_LAYERS]; ///< Decoding order number of the previous IRAP picture
80
  int                     m_decodingOrderCounter;
81
82
  int                     m_puCounter;
  bool                    m_seiInclusionFlag;
83
84
85
86
  int                     m_prevGDRSubpicPOC[MAX_VPS_LAYERS][MAX_NUM_SUB_PICS];
  int                     m_prevIRAPSubpicPOC[MAX_VPS_LAYERS][MAX_NUM_SUB_PICS];
  NalUnitType             m_prevIRAPSubpicType[MAX_VPS_LAYERS][MAX_NUM_SUB_PICS];
  int                     m_prevIRAPSubpicDecOrderNo[MAX_VPS_LAYERS][MAX_NUM_SUB_PICS];
87
88
  int                     m_pocRandomAccess;   ///< POC number of the random access point (the first IDR or CRA picture)
  int                     m_lastRasPoc;
89
  bool                    m_prevEOS[MAX_VPS_LAYERS];
90
91
92

  PicList                 m_cListPic;         //  Dynamic buffer
  ParameterSetManager     m_parameterSetManager;  // storage for parameter sets
Brian Heng's avatar
Brian Heng committed
93
  PicHeader               m_picHeader;            // picture header
94
95
96
97
98
  Slice*                  m_apcSlicePilot;


  SEIMessages             m_SEIs; ///< List of SEI messages that have been received before the first slice and between slices, excluding prefix SEIs...

99

100
101
102
103
104
  // functional classes
  IntraPrediction         m_cIntraPred;
  InterPrediction         m_cInterPred;
  TrQuant                 m_cTrQuant;
  DecSlice                m_cSliceDecoder;
105
  TrQuant                 m_cTrQuantScalingList;
106
107
108
109
  DecCu                   m_cCuDecoder;
  HLSyntaxReader          m_HLSReader;
  CABACDecoder            m_CABACDecoder;
  SEIReader               m_seiReader;
110
111
112
#if JVET_S0257_DUMP_360SEI_MESSAGE
  SeiCfgFileDump          m_seiCfgDump;
#endif
113
114
115
  LoopFilter              m_cLoopFilter;
  SampleAdaptiveOffset    m_cSAO;
  AdaptiveLoopFilter      m_cALF;
Taoran Lu's avatar
Taoran Lu committed
116
  Reshape                 m_cReshaper;                        ///< reshaper class
117
  HRD                     m_HRD;
118
119
120
121
  // decoder side RD cost computation
  RdCost                  m_cRdCost;                      ///< RD cost computation class
#if JVET_J0090_MEMORY_BANDWITH_MEASURE
  CacheModel              m_cacheModel;
122
#endif
Jack Enhorn's avatar
Jack Enhorn committed
123
  bool isRandomAccessSkipPicture(int& iSkipFrame, int& iPOCLastDisplay, bool mixedNaluInPicFlag, uint32_t layerId);
124
  Picture*                m_pcPic;
125
  uint32_t                m_uiSliceSegmentIdx;
Brian Heng's avatar
Brian Heng committed
126
  uint32_t                m_prevLayerID;
127
  int                     m_prevPOC;
128
  int                     m_prevPicPOC;
129
130
  int                     m_prevTid0POC;
  bool                    m_bFirstSliceInPicture;
131
132
  bool                    m_firstSliceInSequence[MAX_VPS_LAYERS];
  bool                    m_firstSliceInBitstream;
133
134
  bool                    m_isFirstAuInCvs;
  bool                    m_accessUnitEos[MAX_VPS_LAYERS];
135
136
  bool                    m_prevSliceSkipped;
  int                     m_skippedPOC;
Jack Enhorn's avatar
Jack Enhorn committed
137
  uint32_t                m_skippedLayerID;
138
139
  int                     m_lastPOCNoOutputPriorPics;
  bool                    m_isNoOutputPriorPics;
140
  bool                    m_lastNoOutputBeforeRecoveryFlag[MAX_VPS_LAYERS];    //value of variable NoOutputBeforeRecoveryFlag of the assocated CRA/GDR pic
141
  int                     m_sliceLmcsApsId;         //value of LmcsApsId, constraint is same id for all slices in one picture
142
  std::ostream           *m_pDecodedSEIOutputStream;
143
  uint32_t                m_audIrapOrGdrAuFlag;
144
145
146
#if JVET_S0257_DUMP_360SEI_MESSAGE
  std::string             m_decoded360SeiDumpFileName;
#endif
147
148

  int                     m_decodedPictureHashSEIEnabled;  ///< Checksum(3)/CRC(2)/MD5(1)/disable(0) acting on decoded picture hash SEI message
149
  uint32_t                m_numberOfChecksumErrorsDetected;
150
151
152
153

  bool                    m_warningMessageSkipPicture;

  std::list<InputNALUnit*> m_prefixSEINALUs; /// Buffered up prefix SEI NAL Units.
Tobias Hinz's avatar
Tobias Hinz committed
154
155
  int                     m_debugPOC;
  int                     m_debugCTU;
156

157
158
159
160
161
162
163
  struct AccessUnitInfo
  {
    NalUnitType     m_nalUnitType; ///< nal_unit_type
    uint32_t        m_temporalId;  ///< temporal_id
    uint32_t        m_nuhLayerId;  ///< nuh_layer_id
  };
  std::vector<AccessUnitInfo> m_accessUnitNals;
164
165
166
167
168
169
170
171
  struct AccessUnitPicInfo
  {
    NalUnitType     m_nalUnitType; ///< nal_unit_type
    uint32_t        m_temporalId;  ///< temporal_id
    uint32_t        m_nuhLayerId;  ///< nuh_layer_id
    int             m_POC;
  };
  std::vector<AccessUnitPicInfo> m_accessUnitPicInfo;
172
  std::vector<AccessUnitPicInfo> m_firstAccessUnitPicInfo;
173
174
175
176
177
  struct NalUnitInfo
  {
    NalUnitType     m_nalUnitType; ///< nal_unit_type
    uint32_t        m_nuhLayerId;  ///< nuh_layer_id
    uint32_t        m_firstCTUinSlice; /// the first CTU in slice, specified with raster scan order ctu address
178
    int             m_POC;             /// the picture order
179
  };
Biao Wang's avatar
Biao Wang committed
180
  std::vector<NalUnitInfo> m_nalUnitInfo[MAX_VPS_LAYERS];
181
  std::vector<int> m_accessUnitApsNals;
182
  std::vector<int> m_accessUnitSeiTids;
183
  std::vector<bool> m_accessUnitNoOutputPriorPicFlags;
184

185
186
  // NAL unit type, layer ID, and SEI payloadType
  std::vector<std::tuple<NalUnitType, int, SEI::PayloadType>> m_accessUnitSeiPayLoadTypes;
187
188

  std::vector<NalUnitType> m_pictureUnitNals;
189
  std::list<InputNALUnit*> m_pictureSeiNalus; 
190
  std::list<InputNALUnit*> m_suffixApsNalus; 
191

192
193
194
195
196
  OPI*                    m_opi;
  bool                    m_mTidExternalSet;
  bool                    m_mTidOpiSet;
  bool                    m_tOlsIdxTidExternalSet;
  bool                    m_tOlsIdxTidOpiSet;
197
  VPS*                    m_vps;
198
199
  int                     m_maxDecSubPicIdx;
  int                     m_maxDecSliceAddrInSubPic;
200
  int                     m_clsVPSid;
201

Biao Wang's avatar
Biao Wang committed
202
203
public:
  int                     m_targetSubPicIdx;
204
205

  DCI*                    m_dci;
206
  ParameterSetMap<APS>*   m_apsMapEnc;
207
208
209
210
211
212
213
214
215
216
217
218
219
220
public:
  DecLib();
  virtual ~DecLib();

  void  create  ();
  void  destroy ();

  void  setDecodedPictureHashSEIEnabled(int enabled) { m_decodedPictureHashSEIEnabled=enabled; }

  void  init(
#if JVET_J0090_MEMORY_BANDWITH_MEASURE
    const std::string& cacheCfgFileName
#endif
  );
221
  bool  decode(InputNALUnit& nalu, int& iSkipFrame, int& iPOCLastDisplay, int iTargetOlsIdx);
222
223
224
  void  deletePicBuffer();

  void  executeLoopFilters();
225
  void finishPicture(int &poc, PicList *&rpcListPic, MsgLevel msgl = INFO, bool associatedWithNewClvs = false);
226
227
  void  finishPictureLight(int& poc, PicList*& rpcListPic );
  void  checkNoOutputPriorPics (PicList* rpcListPic);
228
  void  checkNalUnitConstraints( uint32_t naluType );
229
  void  checkPicTypeAfterEos();
230
  void  updateAssociatedIRAP();
231
  void  updatePrevGDRInSameLayer();
232
  void  updatePrevIRAPAndGDRSubpic();
Jack Enhorn's avatar
Jack Enhorn committed
233
  bool  getGDRRecoveryPocReached()          { return ( m_pcPic->getPOC() >= m_prevGDRInSameLayerPOC[m_pcPic->layerId] + m_prevGDRInSameLayerRecoveryPOC[m_pcPic->layerId] ); }
234

235
236
237
#if JVET_S0078_NOOUTPUTPRIORPICFLAG
  bool  getAudIrapOrGdrAuFlag() const       { return m_audIrapOrGdrAuFlag;  }
#endif
238
239
240
  bool  getNoOutputPriorPicsFlag () const   { return m_isNoOutputPriorPics; }
  void  setNoOutputPriorPicsFlag (bool val) { m_isNoOutputPriorPics = val; }
  void  setFirstSliceInPicture (bool val)  { m_bFirstSliceInPicture = val; }
241
  bool  getFirstSliceInPicture () const  { return m_bFirstSliceInPicture; }
242
243
  bool  getFirstSliceInSequence(int layerId) const { return m_firstSliceInSequence[layerId]; }
  void  setFirstSliceInSequence(bool val, int layerId) { m_firstSliceInSequence[layerId] = val; }
244
  void  setDecodedSEIMessageOutputStream(std::ostream *pOpStream) { m_pDecodedSEIOutputStream = pOpStream; }
245
246
247
#if JVET_S0257_DUMP_360SEI_MESSAGE
  void  setDecoded360SEIMessageFileName(std::string &Dump360SeiFileName) { m_decoded360SeiDumpFileName = Dump360SeiFileName; }
#endif
248
249
  uint32_t  getNumberOfChecksumErrorsDetected() const { return m_numberOfChecksumErrorsDetected; }

Tobias Hinz's avatar
Tobias Hinz committed
250
251
252
253
  int  getDebugCTU( )               const { return m_debugCTU; }
  void setDebugCTU( int debugCTU )        { m_debugCTU = debugCTU; }
  int  getDebugPOC( )               const { return m_debugPOC; };
  void setDebugPOC( int debugPOC )        { m_debugPOC = debugPOC; };
Brian Heng's avatar
Brian Heng committed
254
  void resetAccessUnitNals()              { m_accessUnitNals.clear();    }
255
  void resetAccessUnitPicInfo()              { m_accessUnitPicInfo.clear();    }
Brian Heng's avatar
Brian Heng committed
256
  void resetAccessUnitApsNals()           { m_accessUnitApsNals.clear(); }
257
  void resetAccessUnitSeiTids()           { m_accessUnitSeiTids.clear(); }
258
259
  void resetAudIrapOrGdrAuFlag()          { m_audIrapOrGdrAuFlag = false; }
  void resetAccessUnitEos()               { memset(m_accessUnitEos, false, sizeof(m_accessUnitEos)); }
260
  void checkTidLayerIdInAccessUnit();
261
262
  void resetAccessUnitSeiPayLoadTypes()   { m_accessUnitSeiPayLoadTypes.clear(); }
  void checkSEIInAccessUnit();
263
  void checkLayerIdIncludedInCvss();
264
265
  void CheckNoOutputPriorPicFlagsInAccessUnit();
  void resetAccessUnitNoOutputPriorPicFlags() { m_accessUnitNoOutputPriorPicFlags.clear(); }
266
267
  void checkSeiInPictureUnit();
  void resetPictureSeiNalus();
Brian Heng's avatar
Brian Heng committed
268
  bool isSliceNaluFirstInAU( bool newPicture, InputNALUnit &nalu );
269
  void processSuffixApsNalus();
270

271
272
273
  void checkAPSInPictureUnit();
  void resetPictureUnitNals() { m_pictureUnitNals.clear(); }

274
  const VPS* getVPS()                     { return m_vps; }
275
276
  void deriveTargetOutputLayerSet( const int targetOlsIdx ) { if( m_vps != nullptr ) m_vps->deriveTargetOutputLayerSet( targetOlsIdx ); }

277
278
279
280
  void  initScalingList()
  {
    m_cTrQuantScalingList.init(nullptr, MAX_TB_SIZEY, false, false, false, false);
  }
281

282
283
284
  void  setAPSMapEnc( ParameterSetMap<APS>* apsMap ) { m_apsMapEnc = apsMap;  }
  bool  isNewPicture( std::ifstream *bitstreamFile, class InputByteStream *bytestream );
  bool  isNewAccessUnit( bool newPicture, std::ifstream *bitstreamFile, class InputByteStream *bytestream );
285

286
287
288
289
290
291
292
293
294
295
  bool      getHTidExternalSetFlag()               const { return m_mTidExternalSet; }
  void      setHTidExternalSetFlag(bool mTidExternalSet)  { m_mTidExternalSet = mTidExternalSet; }
  bool      getHTidOpiSetFlag()               const { return m_mTidOpiSet; }
  void      setHTidOpiSetFlag(bool mTidOpiSet)  { m_mTidOpiSet = mTidOpiSet; }
  bool      getTOlsIdxExternalFlag()               const { return m_tOlsIdxTidExternalSet; }
  void      setTOlsIdxExternalFlag (bool tOlsIdxExternalSet)  { m_tOlsIdxTidExternalSet = tOlsIdxExternalSet; }
  bool      getTOlsIdxOpiFlag()               const { return m_tOlsIdxTidOpiSet; }
  void      setTOlsIdxOpiFlag(bool tOlsIdxOpiSet)  { m_tOlsIdxTidOpiSet = tOlsIdxOpiSet; }
  const OPI* getOPI()                     { return m_opi; }

296
297
  bool      getMixedNaluTypesInPicFlag();

298
299
300
protected:
  void  xUpdateRasInit(Slice* slice);

Vadim Seregin's avatar
Vadim Seregin committed
301
302
  Picture * xGetNewPicBuffer( const SPS &sps, const PPS &pps, const uint32_t temporalLayer, const int layerId );
  void  xCreateLostPicture( int iLostPOC, const int layerId );
303
  void  xCreateUnavailablePicture( const PPS *pps, const int iUnavailablePoc, const bool longTermFlag, const int temporalId, const int layerId, const bool interLayerRefPicFlag );
304
305
  void  checkParameterSetsInclusionSEIconstraints(const InputNALUnit nalu);
  void  xActivateParameterSets( const InputNALUnit nalu );
306
  void  xCheckParameterSetConstraints( const int layerId );
Brian Heng's avatar
Brian Heng committed
307
  void      xDecodePicHeader( InputNALUnit& nalu );
308
  bool      xDecodeSlice(InputNALUnit &nalu, int &iSkipFrame, int iPOCLastDisplay);
309
  void      xDecodeOPI( InputNALUnit& nalu );
310
  void      xDecodeVPS( InputNALUnit& nalu );
311
  void      xDecodeDCI( InputNALUnit& nalu );
312
313
  void      xDecodeSPS( InputNALUnit& nalu );
  void      xDecodePPS( InputNALUnit& nalu );
Hendry's avatar
Hendry committed
314
  void      xDecodeAPS(InputNALUnit& nalu);
315
316
317
318
319
320
321
  void      xUpdatePreviousTid0POC(Slice *pSlice)
  {
    if( (pSlice->getTLayer() == 0) && (pSlice->getNalUnitType() != NAL_UNIT_CODED_SLICE_RASL) && (pSlice->getNalUnitType() != NAL_UNIT_CODED_SLICE_RADL) && !pSlice->getPicHeader()->getNonReferencePictureFlag() )
    { 
      m_prevTid0POC = pSlice->getPOC(); 
    }  
  }
322
323
  void      xParsePrefixSEImessages();
  void      xParsePrefixSEIsForUnknownVCLNal();
324
  void      xCheckPrefixSEIMessages( SEIMessages& prefixSEIs );
325

326
  void  xCheckNalUnitConstraintFlags( const ConstraintInfo *cInfo, uint32_t naluType );
327
  void     xCheckMixedNalUnit(Slice* pcSlice, SPS *sps, InputNALUnit &nalu);
328
329
330
331
332
333
334
};// END CLASS DEFINITION DecLib


//! \}

#endif // __DECTOP__