source: 3DVCSoftware/branches/HTM-10.0-dev0/source/Lib/TLibDecoder/TDecGop.cpp @ 854

Last change on this file since 854 was 854, checked in by tech, 10 years ago

Integrated following MV-HEVC HLS 7 items:

H_MV_HLS7_GEN Stub for further integrations (not tested)
H_MV_HLS_7_OUTPUT_LAYERS_5_10_22_27
Output layer sets, various

(VPS/P0300/alt output layer flag) #27 Change alt output layer flag to be signalled within the loop of output layer sets, from JCTVC-P0300-v2. Decision: Adopt.
(VPS/P0156/Num of output_layer_flag) #10 Proposal 3: The output_layer_flag[ i ][ j ] is signalled for j equal to 0 to NumLayersInIdList[ lsIdx ] inclusive. It was remarked that we might be able to just assume that the top layer is always output; however, this was not entirely clear , so the safe thing to do may be to also send the flag for this layer.
(VPS/P0295/Default output layer sets) #5 Discussion from (P0110). Decision: Three-state approach (text in P0295, decoder shall allow 3 to be present and shall treat 3 the same as the value 2).

H_MV_HLS_7_HRD_P0156_7 (HRD/P0156/MaxSubLayersInLayerSetMinus1) #7 Proposal 1: signal, in the VPS extension, the DPB parameters for an output layer set for sub-DPBs only up to the maximum temporal sub-layers in the corresponding layer set
H_MV_HLS_7_VPS_P0048_14
(VPS/P0048/profile_ref_minus1 rem) #14 Remove profile_ref_minus1 from the VPS extension, from JCTVC-P0048
H_MV_HLS_7_VPS_P0076_15 (VPS/P0076/video signal info move) #15 Move video signal information syntax structure earlier in the VPS VUI.
H_MV_HLS_7_SPS_P0155_16_32
(SPS/P0155/sps_sub_layer_ordering_info) #16, #32 Not signal the sps_max_num_reorder_pics[], sps_max_latency_increase_plus1[], and sps_max_dec_pic_buffering_minus1[] syntax elements in the SPS when nuh_layer_id > 0.
H_MV_HLS_7_GEN_P0166_PPS_EXTENSION (GEN/P0166/pps_extension) #17 Add PPS extension type flags for conditional presence of syntax extensions per extension type, aligned with the SPS extension type flags, from JCTVC-P0166. Further align the SPS extension type flags syntax between RExt and MV-HEVC/SHVC
H_MV_HLS_7_FIX_SET_DPB_SIZE
Fix derivation dpb size parameters
H_MV_HLS_7_RESERVED_FLAGS Added flags

(SPS/P0312/SHVC reserved flag) The flag will be used for the syntax vert_phase_position_enable_flag in SHVC draft
(VPS/O0215/SHVC reserved flag): this flag will be used for the syntax cross_layer_phase_alignment_flag in SHVC draft.
(VPS VUI/O0199,P0312/SHVC reserved flags) the 3 reserved bits will be used for the syntaxes single_layer_for_non_irap_flag, higher_layer_irap_skip_flag and vert_phase_position_not_in_use_flag in SHVC draft.

H_MV_FIX_VPS_LAYER_ID_NOT_EQUAL_ZERO Discard VPS with nuh_layer_Id > 0
H_MV_HLS_7_MISC_P0130_EOS
(MISC/P0130/EOS NAL layer id) #19 Require that end of bitstream NAL unit shall have nuh_layer_id equal to 0, from JCTVC-P0130. Decoders shall allow an end of bitstream NAL unit with nuh_layer_id > 0 to be present, and shall ignore the NAL unit.
H_MV_HLS_7_MISC_P0182_13 (MISC/P0182/BL PS Compatibility flag) #13 Define the flag (in VPS VUI) with the proposed semantics, without specifying an associated extraction process. Editors to select the position in the VPS VUI.
H_MV_HLS_7_MISC_P0068_21
(MISC/P0068/all irap idr flag) #21 Add flag in VUI to indicate that all IRAP pictures are IDRs and that all layer pictures in an AU are IDR aligned, from JCTVC-P0068 proposal 1.
H_MV_HLS_7_FIX_INFER_CROSS_LAYER_IRAP_ALIGNED_FLAG Fix inference of cross_layer_irap_aligned_flag
H_MV_HLS_7_MISC_P0079_18
(MISC/P0079/NumActiveRefLayerPics) #18 Modification of derivation of variable NumActiveRefLayerPics.

  • Property svn:eol-style set to native
File size: 11.7 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
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  m_pcSbacDecoder->init( (TDecBinIf*)m_pcBinCABAC );
115  m_pcEntropyDecoder->setEntropyDecoder (m_pcSbacDecoder);
116
117  UInt uiNumSubstreams = pcSlice->getPPS()->getEntropyCodingSyncEnabledFlag() ? pcSlice->getNumEntryPointOffsets()+1 : pcSlice->getPPS()->getNumSubstreams();
118
119  // init each couple {EntropyDecoder, Substream}
120  UInt *puiSubstreamSizes = pcSlice->getSubstreamSizes();
121  ppcSubstreams    = new TComInputBitstream*[uiNumSubstreams];
122  m_pcSbacDecoders = new TDecSbac[uiNumSubstreams];
123  m_pcBinCABACs    = new TDecBinCABAC[uiNumSubstreams];
124  for ( UInt ui = 0 ; ui < uiNumSubstreams ; ui++ )
125  {
126    m_pcSbacDecoders[ui].init(&m_pcBinCABACs[ui]);
127    ppcSubstreams[ui] = pcBitstream->extractSubstream(ui+1 < uiNumSubstreams ? puiSubstreamSizes[ui] : pcBitstream->getNumBitsLeft());
128  }
129
130  for ( UInt ui = 0 ; ui+1 < uiNumSubstreams; ui++ )
131  {
132    m_pcEntropyDecoder->setEntropyDecoder ( &m_pcSbacDecoders[uiNumSubstreams - 1 - ui] );
133    m_pcEntropyDecoder->setBitstream      (  ppcSubstreams   [uiNumSubstreams - 1 - ui] );
134    m_pcEntropyDecoder->resetEntropy      (pcSlice);
135  }
136
137  m_pcEntropyDecoder->setEntropyDecoder ( m_pcSbacDecoder  );
138  m_pcEntropyDecoder->setBitstream      ( ppcSubstreams[0] );
139  m_pcEntropyDecoder->resetEntropy      (pcSlice);
140#if H_3D_NBDV
141  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.
142  {
143    Int iColPoc = pcSlice->getRefPOC(RefPicList(1-pcSlice->getColFromL0Flag()), pcSlice->getColRefIdx());
144    rpcPic->setNumDdvCandPics(rpcPic->getDisCandRefPictures(iColPoc));
145  }
146
147  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.
148  {
149    rpcPic->checkTemporalIVRef();
150  }
151
152  if(pcSlice->getIsDepth())
153  {
154    rpcPic->checkTextureRef();
155  }
156#endif
157#if H_3D
158  pcSlice->setDepthToDisparityLUTs(); 
159#endif
160  m_pcSbacDecoders[0].load(m_pcSbacDecoder);
161  m_pcSliceDecoder->decompressSlice( ppcSubstreams, rpcPic, m_pcSbacDecoder, m_pcSbacDecoders);
162  m_pcEntropyDecoder->setBitstream(  ppcSubstreams[uiNumSubstreams-1] );
163  // deallocate all created substreams, including internal buffers.
164  for (UInt ui = 0; ui < uiNumSubstreams; ui++)
165  {
166    ppcSubstreams[ui]->deleteFifo();
167    delete ppcSubstreams[ui];
168  }
169  delete[] ppcSubstreams;
170  delete[] m_pcSbacDecoders; m_pcSbacDecoders = NULL;
171  delete[] m_pcBinCABACs; m_pcBinCABACs = NULL;
172
173  m_dDecTime += (Double)(clock()-iBeforeTime) / CLOCKS_PER_SEC;
174}
175
176Void TDecGop::filterPicture(TComPic*& rpcPic)
177{
178  TComSlice*  pcSlice = rpcPic->getSlice(rpcPic->getCurrSliceIdx());
179
180  //-- For time output for each slice
181  long iBeforeTime = clock();
182
183  // deblocking filter
184  Bool bLFCrossTileBoundary = pcSlice->getPPS()->getLoopFilterAcrossTilesEnabledFlag();
185  m_pcLoopFilter->setCfg(bLFCrossTileBoundary);
186  m_pcLoopFilter->loopFilterPic( rpcPic );
187  if( pcSlice->getSPS()->getUseSAO() )
188  {
189    m_pcSAO->reconstructBlkSAOParams(rpcPic, rpcPic->getPicSym()->getSAOBlkParam());
190    m_pcSAO->SAOProcess(rpcPic);
191    m_pcSAO->PCMLFDisableProcess(rpcPic);
192  }
193#if H_3D
194  rpcPic->compressMotion(2); 
195#endif
196#if !H_3D
197  rpcPic->compressMotion(); 
198#endif
199  Char c = (pcSlice->isIntra() ? 'I' : pcSlice->isInterP() ? 'P' : 'B');
200  if (!pcSlice->isReferenced()) c += 32;
201
202  //-- For time output for each slice
203#if H_MV
204  printf("\nLayer %2d   POC %4d TId: %1d ( %c-SLICE, QP%3d ) ", pcSlice->getLayerId(),
205                                                              pcSlice->getPOC(),
206                                                              pcSlice->getTLayer(),
207                                                              c,
208                                                              pcSlice->getSliceQp() );
209#else
210  printf("\nPOC %4d TId: %1d ( %c-SLICE, QP%3d ) ", pcSlice->getPOC(),
211                                                    pcSlice->getTLayer(),
212                                                    c,
213                                                    pcSlice->getSliceQp() );
214#endif
215
216  m_dDecTime += (Double)(clock()-iBeforeTime) / CLOCKS_PER_SEC;
217  printf ("[DT %6.3f] ", m_dDecTime );
218  m_dDecTime  = 0;
219
220  for (Int iRefList = 0; iRefList < 2; iRefList++)
221  {
222    printf ("[L%d ", iRefList);
223    for (Int iRefIndex = 0; iRefIndex < pcSlice->getNumRefIdx(RefPicList(iRefList)); iRefIndex++)
224    {
225#if H_MV
226      if( pcSlice->getLayerId() != pcSlice->getRefLayerId( RefPicList(iRefList), iRefIndex ) )
227      {
228        printf( "V%d ", pcSlice->getRefLayerId( RefPicList(iRefList), iRefIndex ) );
229      }
230      else
231      {
232#endif
233      printf ("%d ", pcSlice->getRefPOC(RefPicList(iRefList), iRefIndex));
234#if H_MV
235      }
236#endif
237    }
238    printf ("] ");
239  }
240  if (m_decodedPictureHashSEIEnabled)
241  {
242    SEIMessages pictureHashes = getSeisByType(rpcPic->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(*rpcPic->getPicYuvRec(), hash);
249  }
250
251  rpcPic->setOutputMark(true);
252  rpcPic->setReconMark(true);
253}
254
255/**
256 * Calculate and print hash for pic, compare to picture_digest SEI if
257 * present in seis.  seis may be NULL.  Hash is printed to stdout, in
258 * a manner suitable for the status line. Theformat is:
259 *  [Hash_type:xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx,(yyy)]
260 * Where, x..x is the hash
261 *        yyy has the following meanings:
262 *            OK          - calculated hash matches the SEI message
263 *            ***ERROR*** - calculated hash does not match the SEI message
264 *            unk         - no SEI message was available for comparison
265 */
266static void calcAndPrintHashStatus(TComPicYuv& pic, const SEIDecodedPictureHash* pictureHashSEI)
267{
268  /* calculate MD5sum for entire reconstructed picture */
269  UChar recon_digest[3][16];
270  Int numChar=0;
271  const Char* hashType = "\0";
272
273  if (pictureHashSEI)
274  {
275    switch (pictureHashSEI->method)
276    {
277    case SEIDecodedPictureHash::MD5:
278      {
279        hashType = "MD5";
280        calcMD5(pic, recon_digest);
281        numChar = 16;
282        break;
283      }
284    case SEIDecodedPictureHash::CRC:
285      {
286        hashType = "CRC";
287        calcCRC(pic, recon_digest);
288        numChar = 2;
289        break;
290      }
291    case SEIDecodedPictureHash::CHECKSUM:
292      {
293        hashType = "Checksum";
294        calcChecksum(pic, recon_digest);
295        numChar = 4;
296        break;
297      }
298    default:
299      {
300        assert (!"unknown hash type");
301      }
302    }
303  }
304
305  /* compare digest against received version */
306  const Char* ok = "(unk)";
307  Bool mismatch = false;
308
309  if (pictureHashSEI)
310  {
311    ok = "(OK)";
312    for(Int yuvIdx = 0; yuvIdx < 3; yuvIdx++)
313    {
314      for (UInt i = 0; i < numChar; i++)
315      {
316        if (recon_digest[yuvIdx][i] != pictureHashSEI->digest[yuvIdx][i])
317        {
318          ok = "(***ERROR***)";
319          mismatch = true;
320        }
321      }
322    }
323  }
324
325  printf("[%s:%s,%s] ", hashType, digestToString(recon_digest, numChar), ok);
326
327  if (mismatch)
328  {
329    g_md5_mismatch = true;
330    printf("[rx%s:%s] ", hashType, digestToString(pictureHashSEI->digest, numChar));
331  }
332}
333//! \}
Note: See TracBrowser for help on using the repository browser.