HEVC Test Model (HM)  HM-16.3
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-2015, 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 
48 extern Bool g_md5_mismatch;
49 
52 static Void calcAndPrintHashStatus(TComPicYuv& pic, const SEIDecodedPictureHash* pictureHashSEI);
53 // ====================================================================================================================
54 // Constructor / destructor / initialization / destroy
55 // ====================================================================================================================
56 
58 {
59  m_dDecTime = 0;
60 }
61 
63 {
64 
65 }
66 
68 {
69 
70 }
71 
72 
74 {
75 }
76 
77 Void TDecGop::init( TDecEntropy* pcEntropyDecoder,
78  TDecSbac* pcSbacDecoder,
79  TDecBinCABAC* pcBinCABAC,
80  TDecCavlc* pcCavlcDecoder,
81  TDecSlice* pcSliceDecoder,
82  TComLoopFilter* pcLoopFilter,
84  )
85 {
86  m_pcEntropyDecoder = pcEntropyDecoder;
87  m_pcSbacDecoder = pcSbacDecoder;
88  m_pcBinCABAC = pcBinCABAC;
89  m_pcCavlcDecoder = pcCavlcDecoder;
90  m_pcSliceDecoder = pcSliceDecoder;
91  m_pcLoopFilter = pcLoopFilter;
92  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  ppcSubstreams[ui]->deleteFifo();
129  delete ppcSubstreams[ui];
130  }
131  delete[] ppcSubstreams;
132 
133  m_dDecTime += (Double)(clock()-iBeforeTime) / CLOCKS_PER_SEC;
134 }
135 
137 {
138  TComSlice* pcSlice = pcPic->getSlice(pcPic->getCurrSliceIdx());
139 
140  //-- For time output for each slice
141  clock_t iBeforeTime = clock();
142 
143  // deblocking filter
144  Bool bLFCrossTileBoundary = pcSlice->getPPS()->getLoopFilterAcrossTilesEnabledFlag();
145  m_pcLoopFilter->setCfg(bLFCrossTileBoundary);
146  m_pcLoopFilter->loopFilterPic( pcPic );
147 
148  if( pcSlice->getSPS()->getUseSAO() )
149  {
151  m_pcSAO->SAOProcess(pcPic);
153  }
154 
155  pcPic->compressMotion();
156  Char c = (pcSlice->isIntra() ? 'I' : pcSlice->isInterP() ? 'P' : 'B');
157  if (!pcSlice->isReferenced())
158  {
159  c += 32;
160  }
161 
162  //-- For time output for each slice
163  printf("POC %4d TId: %1d ( %c-SLICE, QP%3d ) ", pcSlice->getPOC(),
164  pcSlice->getTLayer(),
165  c,
166  pcSlice->getSliceQp() );
167 
168  m_dDecTime += (Double)(clock()-iBeforeTime) / CLOCKS_PER_SEC;
169  printf ("[DT %6.3f] ", m_dDecTime );
170  m_dDecTime = 0;
171 
172  for (Int iRefList = 0; iRefList < 2; iRefList++)
173  {
174  printf ("[L%d ", iRefList);
175  for (Int iRefIndex = 0; iRefIndex < pcSlice->getNumRefIdx(RefPicList(iRefList)); iRefIndex++)
176  {
177  printf ("%d ", pcSlice->getRefPOC(RefPicList(iRefList), iRefIndex));
178  }
179  printf ("] ");
180  }
182  {
183  SEIMessages pictureHashes = getSeisByType(pcPic->getSEIs(), SEI::DECODED_PICTURE_HASH );
184  const SEIDecodedPictureHash *hash = ( pictureHashes.size() > 0 ) ? (SEIDecodedPictureHash*) *(pictureHashes.begin()) : NULL;
185  if (pictureHashes.size() > 1)
186  {
187  printf ("Warning: Got multiple decoded picture hash SEI messages. Using first.");
188  }
189  calcAndPrintHashStatus(*(pcPic->getPicYuvRec()), hash);
190  }
191 
192  printf("\n");
193 
194  pcPic->setOutputMark(pcPic->getSlice(0)->getPicOutputFlag() ? true : false);
195  pcPic->setReconMark(true);
196 }
197 
209 static Void calcAndPrintHashStatus(TComPicYuv& pic, const SEIDecodedPictureHash* pictureHashSEI)
210 {
211  /* calculate MD5sum for entire reconstructed picture */
212  TComDigest recon_digest;
213  Int numChar=0;
214  const Char* hashType = "\0";
215 
216  if (pictureHashSEI)
217  {
218  switch (pictureHashSEI->method)
219  {
221  {
222  hashType = "MD5";
223  numChar = calcMD5(pic, recon_digest);
224  break;
225  }
227  {
228  hashType = "CRC";
229  numChar = calcCRC(pic, recon_digest);
230  break;
231  }
233  {
234  hashType = "Checksum";
235  numChar = calcChecksum(pic, recon_digest);
236  break;
237  }
238  default:
239  {
240  assert (!"unknown hash type");
241  break;
242  }
243  }
244  }
245 
246  /* compare digest against received version */
247  const Char* ok = "(unk)";
248  Bool mismatch = false;
249 
250  if (pictureHashSEI)
251  {
252  ok = "(OK)";
253  if (recon_digest != pictureHashSEI->m_digest)
254  {
255  ok = "(***ERROR***)";
256  mismatch = true;
257  }
258  }
259 
260  printf("[%s:%s,%s] ", hashType, digestToString(recon_digest, numChar).c_str(), ok);
261 
262  if (mismatch)
263  {
264  g_md5_mismatch = true;
265  printf("[rx%s:%s] ", hashType, digestToString(pictureHashSEI->m_digest, numChar).c_str());
266  }
267 }
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:1320
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:77
Void decompressSlice(TComInputBitstream **ppcSubstreams, TComPic *pcPic, TDecSbac *pcSbacDecoder)
Definition: TDecSlice.cpp:69
picture class (symbol + YUV buffers)
Definition: TComPic.h:56
UInt getSubstreamSize(Int idx)
Definition: TComSlice.h:1512
TComLoopFilter * m_pcLoopFilter
Definition: TDecGop.h:77
void Void
Definition: TypeDef.h:285
UInt calcChecksum(const TComPicYuv &pic, TComDigest &digest)
TComInputBitstream * extractSubstream(UInt uiNumBits)
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:44
#define NULL
Definition: CommonDef.h:100
TDecGop()
Definition: TDecGop.cpp:57
TComSlice * getSlice(Int i)
Definition: TComPic.h:103
char Char
Definition: TypeDef.h:291
Bool g_md5_mismatch
top level flag to signal when there is a decode problem
Definition: decmain.cpp:46
unsigned int UInt
Definition: TypeDef.h:297
Bool getUseSAO() const
Definition: TComSlice.h:893
Bool isReferenced() const
Definition: TComSlice.h:1368
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:1353
Void filterPicture(TComPic *pcPic)
Definition: TDecGop.cpp:136
TDecSlice * m_pcSliceDecoder
Definition: TDecGop.h:76
SBAC decoder class.
Definition: TDecSbac.h:63
Void setEntropyDecoder(TDecEntropyIf *p)
Definition: TDecEntropy.cpp:52
TComPicYuv * getPicYuvRec()
Definition: TComPic.h:109
Void init(TDecBinIf *p)
Definition: TDecSbac.h:69
CAVLC decoder class (header)
UInt calcCRC(const TComPicYuv &pic, TComDigest &digest)
UInt calcMD5(const TComPicYuv &pic, TComDigest &digest)
TDecBinCABAC * m_pcBinCABAC
Definition: TDecGop.h:74
bool Bool
Definition: TypeDef.h:286
TDecSbac * m_pcSbacDecoder
Definition: TDecGop.h:73
TComDigest m_digest
Definition: SEI.h:134
UInt getNumberOfSubstreamSizes()
Definition: TComSlice.h:1510
TDecEntropy * m_pcEntropyDecoder
Definition: TDecGop.h:72
static Void calcAndPrintHashStatus(TComPicYuv &pic, const SEIDecodedPictureHash *pictureHashSEI)
Definition: TDecGop.cpp:209
RefPicList
reference list index
Definition: TypeDef.h:415
TComPicSym * getPicSym()
Definition: TComPic.h:102
Void PCMLFDisableProcess(TComPic *pcPic)
const TComPPS * getPPS() const
Definition: TComSlice.h:1309
Void loopFilterPic(TComPic *pcPic)
picture-level deblocking filter
Bool isIntra() const
Definition: TComSlice.h:1404
entropy decoder class
Definition: TDecEntropy.h:116
Void setCfg(Bool bLFCrossTileBoundary)
set configuration
UInt getCurrSliceIdx() const
Definition: TComPic.h:137
Int getPOC() const
Definition: TComSlice.h:1338
Bool isInterP() const
Definition: TComSlice.h:1406
Void setOutputMark(Bool b)
Definition: TComPic.h:133
virtual ~TDecGop()
Definition: TDecGop.cpp:62
TDecCavlc * m_pcCavlcDecoder
Definition: TDecGop.h:75
Void compressMotion()
Definition: TComPic.cpp:108
Int getRefPOC(RefPicList e, Int iRefIdx)
Definition: TComSlice.h:1356
Void setReconMark(Bool b)
Definition: TComPic.h:131
std::list< SEI * > SEIMessages
Definition: SEI.h:479
enum SEIDecodedPictureHash::Method method
int Int
Definition: TypeDef.h:296
Void destroy()
Definition: TDecGop.cpp:73
Int getSliceQp() const
Definition: TComSlice.h:1339
Bool getLoopFilterAcrossTilesEnabledFlag() const
Definition: TComSlice.h:1124
Void reconstructBlkSAOParams(TComPic *pic, SAOBlkParam *saoBlkParams)
Double m_dDecTime
Definition: TDecGop.h:80
SEIMessages & getSEIs()
Definition: TComPic.h:163
double Double
Definition: TypeDef.h:298
binary entropy decoder interface
slice header class
Definition: TComSlice.h:1198
UInt getTLayer() const
Definition: TComSlice.h:1434
slice decoder class
Definition: TDecSlice.h:61
Void create()
Definition: TDecGop.cpp:67
std::string digestToString(const TComDigest &digest, Int numChar)
binary entropy decoder of CABAC
const TComSPS * getSPS() const
Definition: TComSlice.h:1306
SAOBlkParam * getSAOBlkParam()
Definition: TComPicSym.h:153