source: 3DVCSoftware/branches/HTM-DEV-2.0-dev1-Mediatek/source/Lib/TLibDecoder/TDecGop.cpp @ 566

Last change on this file since 566 was 566, checked in by mediatek-htm, 11 years ago

Integration of JCT3V-E0172. The MACRO is "MTK_RVS_BUGFIX_E0172".

By Na Zhang (na.zhang@…)

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