HEVC Test Model (HM)  HM-16.18
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
TDecGop.cpp
Go to the documentation of this file.
1 /* The copyright in this software is being made available under the BSD
2  * License, included below. This software may be subject to other third party
3  * and contributor rights, including patent rights, and no such rights are
4  * granted under this license.
5  *
6  * Copyright (c) 2010-2017, ITU/ISO/IEC
7  * All rights reserved.
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted provided that the following conditions are met:
11  *
12  * * Redistributions of source code must retain the above copyright notice,
13  * this list of conditions and the following disclaimer.
14  * * Redistributions in binary form must reproduce the above copyright notice,
15  * this list of conditions and the following disclaimer in the documentation
16  * and/or other materials provided with the distribution.
17  * * Neither the name of the ITU/ISO/IEC nor the names of its contributors may
18  * be used to endorse or promote products derived from this software without
19  * specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS
25  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
31  * THE POSSIBILITY OF SUCH DAMAGE.
32  */
33 
38 #include "TDecGop.h"
39 #include "TDecCAVLC.h"
40 #include "TDecSbac.h"
41 #include "TDecBinCoder.h"
42 #include "TDecBinCoderCABAC.h"
43 #include "libmd5/MD5.h"
44 #include "TLibCommon/SEI.h"
45 
46 #include <time.h>
47 
50 static Void calcAndPrintHashStatus(TComPicYuv& pic, const SEIDecodedPictureHash* pictureHashSEI, const BitDepths &bitDepths, UInt &numChecksumErrors);
51 // ====================================================================================================================
52 // Constructor / destructor / initialization / destroy
53 // ====================================================================================================================
54 
56  : m_numberOfChecksumErrorsDetected(0)
57 {
58  m_dDecTime = 0;
59 }
60 
62 {
63 
64 }
65 
67 {
68 
69 }
70 
71 
73 {
74 }
75 
76 Void TDecGop::init( TDecEntropy* pcEntropyDecoder,
77  TDecSbac* pcSbacDecoder,
78  TDecBinCABAC* pcBinCABAC,
79  TDecCavlc* pcCavlcDecoder,
80  TDecSlice* pcSliceDecoder,
81  TComLoopFilter* pcLoopFilter,
83  )
84 {
85  m_pcEntropyDecoder = pcEntropyDecoder;
86  m_pcSbacDecoder = pcSbacDecoder;
87  m_pcBinCABAC = pcBinCABAC;
88  m_pcCavlcDecoder = pcCavlcDecoder;
89  m_pcSliceDecoder = pcSliceDecoder;
90  m_pcLoopFilter = pcLoopFilter;
91  m_pcSAO = pcSAO;
93 }
94 
95 
96 // ====================================================================================================================
97 // Private member functions
98 // ====================================================================================================================
99 // ====================================================================================================================
100 // Public member functions
101 // ====================================================================================================================
102 
104 {
105  TComSlice* pcSlice = pcPic->getSlice(pcPic->getCurrSliceIdx());
106  // Table of extracted substreams.
107  // These must be deallocated AND their internal fifos, too.
108  TComInputBitstream **ppcSubstreams = NULL;
109 
110  //-- For time output for each slice
111  clock_t iBeforeTime = clock();
114 
115  const UInt uiNumSubstreams = pcSlice->getNumberOfSubstreamSizes()+1;
116 
117  // init each couple {EntropyDecoder, Substream}
118  ppcSubstreams = new TComInputBitstream*[uiNumSubstreams];
119  for ( UInt ui = 0 ; ui < uiNumSubstreams ; ui++ )
120  {
121  ppcSubstreams[ui] = pcBitstream->extractSubstream(ui+1 < uiNumSubstreams ? (pcSlice->getSubstreamSize(ui)<<3) : pcBitstream->getNumBitsLeft());
122  }
123 
124  m_pcSliceDecoder->decompressSlice( ppcSubstreams, pcPic, m_pcSbacDecoder);
125  // deallocate all created substreams, including internal buffers.
126  for (UInt ui = 0; ui < uiNumSubstreams; ui++)
127  {
128  delete ppcSubstreams[ui];
129  }
130  delete[] ppcSubstreams;
131 
132  m_dDecTime += (Double)(clock()-iBeforeTime) / CLOCKS_PER_SEC;
133 }
134 
136 {
137  TComSlice* pcSlice = pcPic->getSlice(pcPic->getCurrSliceIdx());
138 
139  //-- For time output for each slice
140  clock_t iBeforeTime = clock();
141 
142  // deblocking filter
143  Bool bLFCrossTileBoundary = pcSlice->getPPS()->getLoopFilterAcrossTilesEnabledFlag();
144  m_pcLoopFilter->setCfg(bLFCrossTileBoundary);
145  m_pcLoopFilter->loopFilterPic( pcPic );
146 
147  if( pcSlice->getSPS()->getUseSAO() )
148  {
150  m_pcSAO->SAOProcess(pcPic);
152  }
153 
154  pcPic->compressMotion();
155  TChar c = (pcSlice->isIntra() ? 'I' : pcSlice->isInterP() ? 'P' : 'B');
156  if (!pcSlice->isReferenced())
157  {
158  c += 32;
159  }
160 
161  //-- For time output for each slice
162  printf("POC %4d TId: %1d ( %c-SLICE, QP%3d ) ", pcSlice->getPOC(),
163  pcSlice->getTLayer(),
164  c,
165  pcSlice->getSliceQp() );
166 
167  m_dDecTime += (Double)(clock()-iBeforeTime) / CLOCKS_PER_SEC;
168  printf ("[DT %6.3f] ", m_dDecTime );
169  m_dDecTime = 0;
170 
171  for (Int iRefList = 0; iRefList < 2; iRefList++)
172  {
173  printf ("[L%d ", iRefList);
174  for (Int iRefIndex = 0; iRefIndex < pcSlice->getNumRefIdx(RefPicList(iRefList)); iRefIndex++)
175  {
176  printf ("%d ", pcSlice->getRefPOC(RefPicList(iRefList), iRefIndex));
177  }
178  printf ("] ");
179  }
181  {
182  SEIMessages pictureHashes = getSeisByType(pcPic->getSEIs(), SEI::DECODED_PICTURE_HASH );
183  const SEIDecodedPictureHash *hash = ( pictureHashes.size() > 0 ) ? (SEIDecodedPictureHash*) *(pictureHashes.begin()) : NULL;
184  if (pictureHashes.size() > 1)
185  {
186  printf ("Warning: Got multiple decoded picture hash SEI messages. Using first.");
187  }
189  }
190 
191  printf("\n");
192 
193  pcPic->setOutputMark(pcPic->getSlice(0)->getPicOutputFlag() ? true : false);
194  pcPic->setReconMark(true);
195 }
196 
208 static Void calcAndPrintHashStatus(TComPicYuv& pic, const SEIDecodedPictureHash* pictureHashSEI, const BitDepths &bitDepths, UInt &numChecksumErrors)
209 {
210  /* calculate MD5sum for entire reconstructed picture */
211  TComPictureHash recon_digest;
212  Int numChar=0;
213  const TChar* hashType = "\0";
214 
215  if (pictureHashSEI)
216  {
217  switch (pictureHashSEI->method)
218  {
219  case HASHTYPE_MD5:
220  {
221  hashType = "MD5";
222  numChar = calcMD5(pic, recon_digest, bitDepths);
223  break;
224  }
225  case HASHTYPE_CRC:
226  {
227  hashType = "CRC";
228  numChar = calcCRC(pic, recon_digest, bitDepths);
229  break;
230  }
231  case HASHTYPE_CHECKSUM:
232  {
233  hashType = "Checksum";
234  numChar = calcChecksum(pic, recon_digest, bitDepths);
235  break;
236  }
237  default:
238  {
239  assert (!"unknown hash type");
240  break;
241  }
242  }
243  }
244 
245  /* compare digest against received version */
246  const TChar* ok = "(unk)";
247  Bool mismatch = false;
248 
249  if (pictureHashSEI)
250  {
251  ok = "(OK)";
252  if (recon_digest != pictureHashSEI->m_pictureHash)
253  {
254  ok = "(***ERROR***)";
255  mismatch = true;
256  }
257  }
258 
259  printf("[%s:%s,%s] ", hashType, hashToString(recon_digest, numChar).c_str(), ok);
260 
261  if (mismatch)
262  {
263  numChecksumErrors++;
264  printf("[rx%s:%s] ", hashType, hashToString(pictureHashSEI->m_pictureHash, numChar).c_str());
265  }
266 }
Int m_decodedPictureHashSEIEnabled
Checksum(3)/CRC(2)/MD5(1)/disable(0) acting on decoded picture hash SEI message.
Definition: TDecGop.h:81
Bool getPicOutputFlag() const
Definition: TComSlice.h:1337
TComSampleAdaptiveOffset * m_pcSAO
Definition: TDecGop.h:79
SBAC decoder class (header)
picture YUV buffer class
Definition: TComPicYuv.h:55
Void init(TDecEntropy *pcEntropyDecoder, TDecSbac *pcSbacDecoder, TDecBinCABAC *pcBinCABAC, TDecCavlc *pcCavlcDecoder, TDecSlice *pcSliceDecoder, TComLoopFilter *pcLoopFilter, TComSampleAdaptiveOffset *pcSAO)
Definition: TDecGop.cpp:76
Void decompressSlice(TComInputBitstream **ppcSubstreams, TComPic *pcPic, TDecSbac *pcSbacDecoder)
Definition: TDecSlice.cpp:71
picture class (symbol + YUV buffers)
Definition: TComPic.h:56
UInt getSubstreamSize(Int idx)
Definition: TComSlice.h:1526
TComLoopFilter * m_pcLoopFilter
Definition: TDecGop.h:77
void Void
Definition: TypeDef.h:203
TComInputBitstream * extractSubstream(UInt uiNumBits)
UInt calcChecksum(const TComPicYuv &pic, TComPictureHash &digest, const BitDepths &bitDepths)
SEIMessages getSeisByType(SEIMessages &seiList, SEI::PayloadType seiType)
output a selection of SEI messages by payload type. Ownership stays in original message list...
Definition: SEI.cpp:42
#define NULL
Definition: CommonDef.h:107
TDecGop()
Definition: TDecGop.cpp:55
TComSlice * getSlice(Int i)
Definition: TComPic.h:113
unsigned int UInt
Definition: TypeDef.h:212
Bool getUseSAO() const
Definition: TComSlice.h:908
Bool isReferenced() const
Definition: TComSlice.h:1387
deblocking filter class
Void decompressSlice(TComInputBitstream *pcBitstream, TComPic *pcPic)
Definition: TDecGop.cpp:103
GOP decoder class (header)
CAVLC decoder class.
Definition: TDecCAVLC.h:56
Int getNumRefIdx(RefPicList e) const
Definition: TComSlice.h:1370
Void filterPicture(TComPic *pcPic)
Definition: TDecGop.cpp:135
TDecSlice * m_pcSliceDecoder
Definition: TDecGop.h:76
char TChar
Definition: TypeDef.h:206
HashType method
Definition: SEI.h:566
UInt calcMD5(const TComPicYuv &pic, TComPictureHash &digest, const BitDepths &bitDepths)
SBAC decoder class.
Definition: TDecSbac.h:63
Void setEntropyDecoder(TDecEntropyIf *p)
Definition: TDecEntropy.cpp:51
TComPicYuv * getPicYuvRec()
Definition: TComPic.h:120
Void init(TDecBinIf *p)
Definition: TDecSbac.h:69
CAVLC decoder class (header)
TDecBinCABAC * m_pcBinCABAC
Definition: TDecGop.h:74
UInt m_numberOfChecksumErrorsDetected
Definition: TDecGop.h:82
bool Bool
Definition: TypeDef.h:204
TDecSbac * m_pcSbacDecoder
Definition: TDecGop.h:73
TComPictureHash m_pictureHash
Definition: SEI.h:568
UInt getNumberOfSubstreamSizes()
Definition: TComSlice.h:1524
TDecEntropy * m_pcEntropyDecoder
Definition: TDecGop.h:72
Int getRefPOC(RefPicList e, Int iRefIdx) const
Definition: TComSlice.h:1375
RefPicList
reference list index
Definition: TypeDef.h:370
TComPicSym * getPicSym()
Definition: TComPic.h:111
const BitDepths & getBitDepths() const
Definition: TComSlice.h:900
Void PCMLFDisableProcess(TComPic *pcPic)
const TComPPS * getPPS() const
Definition: TComSlice.h:1332
Void loopFilterPic(TComPic *pcPic)
picture-level deblocking filter
Bool isIntra() const
Definition: TComSlice.h:1423
entropy decoder class
Definition: TDecEntropy.h:117
Void setCfg(Bool bLFCrossTileBoundary)
set configuration
UInt getCurrSliceIdx() const
Definition: TComPic.h:148
Int getPOC() const
Definition: TComSlice.h:1354
Bool isInterP() const
Definition: TComSlice.h:1425
Void setOutputMark(Bool b)
Definition: TComPic.h:144
virtual ~TDecGop()
Definition: TDecGop.cpp:61
TDecCavlc * m_pcCavlcDecoder
Definition: TDecGop.h:75
Void compressMotion()
Definition: TComPic.cpp:206
Void setReconMark(Bool b)
Definition: TComPic.h:142
std::list< SEI * > SEIMessages
Definition: SEI.h:123
int Int
Definition: TypeDef.h:211
Void destroy()
Definition: TDecGop.cpp:72
Int getSliceQp() const
Definition: TComSlice.h:1355
Bool getLoopFilterAcrossTilesEnabledFlag() const
Definition: TComSlice.h:1148
Void reconstructBlkSAOParams(TComPic *pic, SAOBlkParam *saoBlkParams)
Double m_dDecTime
Definition: TDecGop.h:80
SEIMessages & getSEIs()
Definition: TComPic.h:174
double Double
Definition: TypeDef.h:213
std::string hashToString(const TComPictureHash &digest, Int numChar)
static Void calcAndPrintHashStatus(TComPicYuv &pic, const SEIDecodedPictureHash *pictureHashSEI, const BitDepths &bitDepths, UInt &numChecksumErrors)
Definition: TDecGop.cpp:208
binary entropy decoder interface
slice header class
Definition: TComSlice.h:1225
UInt getTLayer() const
Definition: TComSlice.h:1453
slice decoder class
Definition: TDecSlice.h:63
UInt calcCRC(const TComPicYuv &pic, TComPictureHash &digest, const BitDepths &bitDepths)
Void create()
Definition: TDecGop.cpp:66
binary entropy decoder of CABAC
const TComSPS * getSPS() const
Definition: TComSlice.h:1329
SAOBlkParam * getSAOBlkParam()
Definition: TComPicSym.h:186