source: SHVCSoftware/branches/SHM-dev/source/Lib/TLibDecoder/TDecGop.cpp @ 1598

Last change on this file since 1598 was 1549, checked in by seregin, 9 years ago

port rev 4732, update copyright notice to include 2016

  • Property svn:eol-style set to native
File size: 11.5 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-2016, 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#if SVC_EXTENSION
46#include "TDecTop.h"
47#if CONFORMANCE_BITSTREAM_MODE
48#include <algorithm>
49#endif
50#endif
51
52#include <time.h>
53
54#if CONFORMANCE_BITSTREAM_MODE
55Bool pocCompareFunction( const TComPic &pic1, const TComPic &pic2 )
56{
57  return (const_cast<TComPic&>(pic1).getPOC() < const_cast<TComPic&>(pic2).getPOC());
58}
59#endif
60
61//! \ingroup TLibDecoder
62//! \{
63static Void calcAndPrintHashStatus(TComPicYuv& pic, const SEIDecodedPictureHash* pictureHashSEI, const BitDepths &bitDepths, UInt &numChecksumErrors);
64// ====================================================================================================================
65// Constructor / destructor / initialization / destroy
66// ====================================================================================================================
67
68TDecGop::TDecGop()
69 : m_numberOfChecksumErrorsDetected(0)
70{
71  m_dDecTime = 0;
72}
73
74TDecGop::~TDecGop()
75{
76
77}
78
79Void TDecGop::create()
80{
81
82}
83
84
85Void TDecGop::destroy()
86{
87}
88
89#if SVC_EXTENSION
90Void TDecGop::init( TDecTop**               ppcDecTop,
91                    TDecEntropy*            pcEntropyDecoder,
92#else
93Void TDecGop::init( TDecEntropy*            pcEntropyDecoder,
94#endif
95                   TDecSbac*               pcSbacDecoder,
96                   TDecBinCABAC*           pcBinCABAC,
97                   TDecCavlc*              pcCavlcDecoder,
98                   TDecSlice*              pcSliceDecoder,
99                   TComLoopFilter*         pcLoopFilter,
100                   TComSampleAdaptiveOffset* pcSAO
101                   )
102{
103  m_pcEntropyDecoder      = pcEntropyDecoder;
104  m_pcSbacDecoder         = pcSbacDecoder;
105  m_pcBinCABAC            = pcBinCABAC;
106  m_pcCavlcDecoder        = pcCavlcDecoder;
107  m_pcSliceDecoder        = pcSliceDecoder;
108  m_pcLoopFilter          = pcLoopFilter;
109  m_pcSAO                 = pcSAO;
110  m_numberOfChecksumErrorsDetected = 0;
111
112#if SVC_EXTENSION   
113  m_ppcTDecTop            = ppcDecTop;
114#endif
115}
116
117
118// ====================================================================================================================
119// Private member functions
120// ====================================================================================================================
121// ====================================================================================================================
122// Public member functions
123// ====================================================================================================================
124
125Void TDecGop::decompressSlice(TComInputBitstream* pcBitstream, TComPic* pcPic)
126{
127  TComSlice*  pcSlice = pcPic->getSlice(pcPic->getCurrSliceIdx());
128  // Table of extracted substreams.
129  // These must be deallocated AND their internal fifos, too.
130  TComInputBitstream **ppcSubstreams = NULL;
131
132  //-- For time output for each slice
133  clock_t iBeforeTime = clock();
134  m_pcSbacDecoder->init( (TDecBinIf*)m_pcBinCABAC );
135  m_pcEntropyDecoder->setEntropyDecoder (m_pcSbacDecoder);
136
137  const UInt uiNumSubstreams = pcSlice->getNumberOfSubstreamSizes()+1;
138
139  // init each couple {EntropyDecoder, Substream}
140  ppcSubstreams    = new TComInputBitstream*[uiNumSubstreams];
141  for ( UInt ui = 0 ; ui < uiNumSubstreams ; ui++ )
142  {
143    ppcSubstreams[ui] = pcBitstream->extractSubstream(ui+1 < uiNumSubstreams ? (pcSlice->getSubstreamSize(ui)<<3) : pcBitstream->getNumBitsLeft());
144  }
145
146  m_pcSliceDecoder->decompressSlice( ppcSubstreams, pcPic, m_pcSbacDecoder);
147  // deallocate all created substreams, including internal buffers.
148  for (UInt ui = 0; ui < uiNumSubstreams; ui++)
149  {
150    delete ppcSubstreams[ui];
151  }
152  delete[] ppcSubstreams;
153
154  m_dDecTime += (Double)(clock()-iBeforeTime) / CLOCKS_PER_SEC;
155}
156
157Void TDecGop::filterPicture(TComPic* pcPic)
158{
159  TComSlice*  pcSlice = pcPic->getSlice(pcPic->getCurrSliceIdx());
160
161  //-- For time output for each slice
162  clock_t iBeforeTime = clock();
163
164  // deblocking filter
165  Bool bLFCrossTileBoundary = pcSlice->getPPS()->getLoopFilterAcrossTilesEnabledFlag();
166  m_pcLoopFilter->setCfg(bLFCrossTileBoundary);
167  m_pcLoopFilter->loopFilterPic( pcPic );
168
169  if( pcSlice->getSPS()->getUseSAO() )
170  {
171    m_pcSAO->reconstructBlkSAOParams(pcPic, pcPic->getPicSym()->getSAOBlkParam());
172    m_pcSAO->SAOProcess(pcPic);
173    m_pcSAO->PCMLFDisableProcess(pcPic);
174  }
175
176  pcPic->compressMotion();
177  TChar c = (pcSlice->isIntra() ? 'I' : pcSlice->isInterP() ? 'P' : 'B');
178  if (!pcSlice->isReferenced())
179  {
180    c += 32;
181  }
182
183  //-- For time output for each slice
184#if SVC_EXTENSION
185  printf("POC %4d LId: %1d TId: %1d ( %c-SLICE %s, QP%3d ) ", pcSlice->getPOC(),
186                                                    pcPic->getLayerId(),
187                                                    pcSlice->getTLayer(),
188                                                    c,
189                                                    nalUnitTypeToString( pcSlice->getNalUnitType() ),
190                                                    pcSlice->getSliceQp() );
191#else
192  printf("POC %4d TId: %1d ( %c-SLICE, QP%3d ) ", pcSlice->getPOC(),
193                                                  pcSlice->getTLayer(),
194                                                  c,
195                                                  pcSlice->getSliceQp() );
196
197#endif
198  m_dDecTime += (Double)(clock()-iBeforeTime) / CLOCKS_PER_SEC;
199  printf ("[DT %6.3f] ", m_dDecTime );
200  m_dDecTime  = 0;
201
202  for (Int iRefList = 0; iRefList < 2; iRefList++)
203  {
204    printf ("[L%d ", iRefList);
205    for (Int iRefIndex = 0; iRefIndex < pcSlice->getNumRefIdx(RefPicList(iRefList)); iRefIndex++)
206    {
207#if SVC_EXTENSION
208      if( pcSlice->getRefPic(RefPicList(iRefList), iRefIndex)->isILR( pcSlice->getLayerId() ) )
209      {
210        UInt refLayerId = pcSlice->getRefPic(RefPicList(iRefList), iRefIndex)->getLayerId();
211        UInt refLayerIdc = pcSlice->getReferenceLayerIdc(refLayerId);
212        assert( pcSlice->getPic()->getPosScalingFactor(refLayerIdc, 0) );
213        assert( pcSlice->getPic()->getPosScalingFactor(refLayerIdc, 1) );
214
215        printf( "%d(%d, {%1.2f, %1.2f}x)", pcSlice->getRefPOC(RefPicList(iRefList), iRefIndex), refLayerId, (Double)POS_SCALING_FACTOR_1X/pcSlice->getPic()->getPosScalingFactor(refLayerIdc, 0), (Double)POS_SCALING_FACTOR_1X/pcSlice->getPic()->getPosScalingFactor(refLayerIdc, 1) );
216      }
217      else
218      {
219        printf ("%d", pcSlice->getRefPOC(RefPicList(iRefList), iRefIndex));
220      }
221
222      if( pcSlice->getEnableTMVPFlag() && iRefList == 1 - pcSlice->getColFromL0Flag() && iRefIndex == pcSlice->getColRefIdx() )
223      {
224        printf( "c" );
225      }
226
227      printf( " " );
228#else
229      printf ("%d ", pcSlice->getRefPOC(RefPicList(iRefList), iRefIndex));
230#endif
231    }
232    printf ("] ");
233  }
234  if (m_decodedPictureHashSEIEnabled)
235  {
236    SEIMessages pictureHashes = getSeisByType(pcPic->getSEIs(), SEI::DECODED_PICTURE_HASH );
237    const SEIDecodedPictureHash *hash = ( pictureHashes.size() > 0 ) ? (SEIDecodedPictureHash*) *(pictureHashes.begin()) : NULL;
238    if (pictureHashes.size() > 1)
239    {
240      printf ("Warning: Got multiple decoded picture hash SEI messages. Using first.");
241    }
242    calcAndPrintHashStatus(*(pcPic->getPicYuvRec()), hash, pcSlice->getSPS()->getBitDepths(), m_numberOfChecksumErrorsDetected);
243  }
244#if CONFORMANCE_BITSTREAM_MODE
245  if( this->getLayerDec(pcPic->getLayerId())->getConfModeFlag() )
246  {
247    // Add this reconstructed picture to the parallel buffer.
248    std::vector<TComPic> *thisLayerBuffer = (this->getLayerDec(pcPic->getLayerId()))->getConfListPic();
249    thisLayerBuffer->push_back(*pcPic);
250    std::sort( thisLayerBuffer->begin(), thisLayerBuffer->end(), pocCompareFunction );
251  }
252#endif
253
254  printf("\n");
255
256  pcPic->setOutputMark(pcPic->getSlice(0)->getPicOutputFlag() ? true : false);
257  pcPic->setReconMark(true);
258}
259
260/**
261 * Calculate and print hash for pic, compare to picture_digest SEI if
262 * present in seis.  seis may be NULL.  Hash is printed to stdout, in
263 * a manner suitable for the status line. Theformat is:
264 *  [Hash_type:xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx,(yyy)]
265 * Where, x..x is the hash
266 *        yyy has the following meanings:
267 *            OK          - calculated hash matches the SEI message
268 *            ***ERROR*** - calculated hash does not match the SEI message
269 *            unk         - no SEI message was available for comparison
270 */
271static Void calcAndPrintHashStatus(TComPicYuv& pic, const SEIDecodedPictureHash* pictureHashSEI, const BitDepths &bitDepths, UInt &numChecksumErrors)
272{
273  /* calculate MD5sum for entire reconstructed picture */
274  TComPictureHash recon_digest;
275  Int numChar=0;
276  const TChar* hashType = "\0";
277
278  if (pictureHashSEI)
279  {
280    switch (pictureHashSEI->method)
281    {
282      case HASHTYPE_MD5:
283        {
284          hashType = "MD5";
285          numChar = calcMD5(pic, recon_digest, bitDepths);
286          break;
287        }
288      case HASHTYPE_CRC:
289        {
290          hashType = "CRC";
291          numChar = calcCRC(pic, recon_digest, bitDepths);
292          break;
293        }
294      case HASHTYPE_CHECKSUM:
295        {
296          hashType = "Checksum";
297          numChar = calcChecksum(pic, recon_digest, bitDepths);
298          break;
299        }
300      default:
301        {
302          assert (!"unknown hash type");
303          break;
304        }
305    }
306  }
307
308  /* compare digest against received version */
309  const TChar* ok = "(unk)";
310  Bool mismatch = false;
311
312  if (pictureHashSEI)
313  {
314    ok = "(OK)";
315    if (recon_digest != pictureHashSEI->m_pictureHash)
316    {
317      ok = "(***ERROR***)";
318      mismatch = true;
319    }
320  }
321
322  printf("[%s:%s,%s] ", hashType, hashToString(recon_digest, numChar).c_str(), ok);
323
324  if (mismatch)
325  {
326    numChecksumErrors++;
327    printf("[rx%s:%s] ", hashType, hashToString(pictureHashSEI->m_pictureHash, numChar).c_str());
328  }
329}
330//! \}
Note: See TracBrowser for help on using the repository browser.