source: 3DVCSoftware/branches/HTM-16.0-MV-draft-5/source/Lib/TLibDecoder/TDecGop.cpp

Last change on this file was 1390, checked in by tech, 9 years ago

Removed 3D.

  • Property svn:eol-style set to native
File size: 9.8 KB
Line 
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
34/** \file     TDecGop.cpp
35    \brief    GOP decoder class
36*/
37
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//! \ingroup TLibDecoder
49//! \{
50static Void calcAndPrintHashStatus(TComPicYuv& pic, const SEIDecodedPictureHash* pictureHashSEI, const BitDepths &bitDepths, UInt &numChecksumErrors);
51// ====================================================================================================================
52// Constructor / destructor / initialization / destroy
53// ====================================================================================================================
54
55TDecGop::TDecGop()
56 : m_numberOfChecksumErrorsDetected(0)
57{
58  m_dDecTime = 0;
59}
60
61TDecGop::~TDecGop()
62{
63
64}
65
66Void TDecGop::create()
67{
68
69}
70
71
72Void TDecGop::destroy()
73{
74}
75
76Void TDecGop::init( TDecEntropy*            pcEntropyDecoder,
77                   TDecSbac*               pcSbacDecoder,
78                   TDecBinCABAC*           pcBinCABAC,
79                   TDecCavlc*              pcCavlcDecoder,
80                   TDecSlice*              pcSliceDecoder,
81                   TComLoopFilter*         pcLoopFilter,
82                   TComSampleAdaptiveOffset* pcSAO
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;
92  m_numberOfChecksumErrorsDetected = 0;
93}
94
95
96// ====================================================================================================================
97// Private member functions
98// ====================================================================================================================
99// ====================================================================================================================
100// Public member functions
101// ====================================================================================================================
102
103Void TDecGop::decompressSlice(TComInputBitstream* pcBitstream, TComPic* pcPic)
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();
112  m_pcSbacDecoder->init( (TDecBinIf*)m_pcBinCABAC );
113  m_pcEntropyDecoder->setEntropyDecoder (m_pcSbacDecoder);
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
125  m_pcSliceDecoder->decompressSlice( ppcSubstreams, pcPic, m_pcSbacDecoder);
126  // deallocate all created substreams, including internal buffers.
127  for (UInt ui = 0; ui < uiNumSubstreams; ui++)
128  {
129    delete ppcSubstreams[ui];
130  }
131  delete[] ppcSubstreams;
132
133  m_dDecTime += (Double)(clock()-iBeforeTime) / CLOCKS_PER_SEC;
134}
135
136Void TDecGop::filterPicture(TComPic* pcPic)
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  {
150    m_pcSAO->reconstructBlkSAOParams(pcPic, pcPic->getPicSym()->getSAOBlkParam());
151    m_pcSAO->SAOProcess(pcPic);
152    m_pcSAO->PCMLFDisableProcess(pcPic);
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#if NH_MV
163  printf("Layer %2d   POC %4d TId: %1d ( %c-SLICE, QP%3d ) ", pcSlice->getLayerId(),
164                                                              pcSlice->getPOC(),
165                                                              pcSlice->getTLayer(),
166                                                              c,
167                                                              pcSlice->getSliceQp() );
168#else
169  printf("POC %4d TId: %1d ( %c-SLICE, QP%3d ) ", pcSlice->getPOC(),
170                                                  pcSlice->getTLayer(),
171                                                  c,
172                                                  pcSlice->getSliceQp() );
173#endif
174
175  m_dDecTime += (Double)(clock()-iBeforeTime) / CLOCKS_PER_SEC;
176  printf ("[DT %6.3f] ", m_dDecTime );
177  m_dDecTime  = 0;
178
179  for (Int iRefList = 0; iRefList < 2; iRefList++)
180  {
181    printf ("[L%d ", iRefList);
182    for (Int iRefIndex = 0; iRefIndex < pcSlice->getNumRefIdx(RefPicList(iRefList)); iRefIndex++)
183    {
184#if NH_MV
185      if( pcSlice->getLayerId() != pcSlice->getRefLayerId( RefPicList(iRefList), iRefIndex ) )
186      {
187        printf( "V%d ", pcSlice->getRefLayerId( RefPicList(iRefList), iRefIndex ) );
188      }
189      else
190      {
191#endif
192      printf ("%d ", pcSlice->getRefPOC(RefPicList(iRefList), iRefIndex));
193#if NH_MV
194      }
195#endif
196    }
197    printf ("] ");
198  }
199  if (m_decodedPictureHashSEIEnabled)
200  {
201    SEIMessages pictureHashes = getSeisByType(pcPic->getSEIs(), SEI::DECODED_PICTURE_HASH );
202    const SEIDecodedPictureHash *hash = ( pictureHashes.size() > 0 ) ? (SEIDecodedPictureHash*) *(pictureHashes.begin()) : NULL;
203    if (pictureHashes.size() > 1)
204    {
205      printf ("Warning: Got multiple decoded picture hash SEI messages. Using first.");
206    }
207    calcAndPrintHashStatus(*(pcPic->getPicYuvRec()), hash, pcSlice->getSPS()->getBitDepths(), m_numberOfChecksumErrorsDetected);
208  }
209
210  printf("\n");
211#if !NH_MV
212  pcPic->setOutputMark(pcPic->getSlice(0)->getPicOutputFlag() ? true : false);
213  pcPic->setReconMark(true);
214#endif
215}
216
217/**
218 * Calculate and print hash for pic, compare to picture_digest SEI if
219 * present in seis.  seis may be NULL.  Hash is printed to stdout, in
220 * a manner suitable for the status line. Theformat is:
221 *  [Hash_type:xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx,(yyy)]
222 * Where, x..x is the hash
223 *        yyy has the following meanings:
224 *            OK          - calculated hash matches the SEI message
225 *            ***ERROR*** - calculated hash does not match the SEI message
226 *            unk         - no SEI message was available for comparison
227 */
228static Void calcAndPrintHashStatus(TComPicYuv& pic, const SEIDecodedPictureHash* pictureHashSEI, const BitDepths &bitDepths, UInt &numChecksumErrors)
229{
230  /* calculate MD5sum for entire reconstructed picture */
231  TComPictureHash recon_digest;
232  Int numChar=0;
233  const TChar* hashType = "\0";
234
235  if (pictureHashSEI)
236  {
237    switch (pictureHashSEI->method)
238    {
239      case HASHTYPE_MD5:
240        {
241          hashType = "MD5";
242          numChar = calcMD5(pic, recon_digest, bitDepths);
243          break;
244        }
245      case HASHTYPE_CRC:
246        {
247          hashType = "CRC";
248          numChar = calcCRC(pic, recon_digest, bitDepths);
249          break;
250        }
251      case HASHTYPE_CHECKSUM:
252        {
253          hashType = "Checksum";
254          numChar = calcChecksum(pic, recon_digest, bitDepths);
255          break;
256        }
257      default:
258        {
259          assert (!"unknown hash type");
260          break;
261        }
262    }
263  }
264
265  /* compare digest against received version */
266  const TChar* ok = "(unk)";
267  Bool mismatch = false;
268
269  if (pictureHashSEI)
270  {
271    ok = "(OK)";
272    if (recon_digest != pictureHashSEI->m_pictureHash)
273    {
274      ok = "(***ERROR***)";
275      mismatch = true;
276    }
277  }
278
279  printf("[%s:%s,%s] ", hashType, hashToString(recon_digest, numChar).c_str(), ok);
280
281  if (mismatch)
282  {
283    numChecksumErrors++;
284    printf("[rx%s:%s] ", hashType, hashToString(pictureHashSEI->m_pictureHash, numChar).c_str());
285  }
286}
287//! \}
Note: See TracBrowser for help on using the repository browser.