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

Last change on this file since 1263 was 1259, checked in by seregin, 9 years ago

port rev 4256

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