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

Last change on this file since 847 was 841, checked in by seregin, 10 years ago

print scalability ratio

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