source: 3DVCSoftware/trunk/source/Lib/TLibDecoder/TDecTop.cpp @ 5

Last change on this file since 5 was 5, checked in by hhi, 12 years ago

Clean version with cfg-files

  • Property svn:eol-style set to native
File size: 24.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-2011, 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 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     TDecTop.cpp
35    \brief    decoder class
36*/
37
38#include "../../App/TAppDecoder/TAppDecTop.h"
39#include "TDecTop.h"
40
41
42
43CamParsCollector::CamParsCollector()
44: m_bInitialized( false )
45{
46  m_aaiCodedOffset         = new Int* [ MAX_NUMBER_VIEWS ];
47  m_aaiCodedScale          = new Int* [ MAX_NUMBER_VIEWS ];
48  m_aiViewOrderIndex       = new Int  [ MAX_NUMBER_VIEWS ];
49  m_aiViewReceived         = new Int  [ MAX_NUMBER_VIEWS ];
50  for( UInt uiId = 0; uiId < MAX_NUMBER_VIEWS; uiId++ )
51  {
52    m_aaiCodedOffset      [ uiId ] = new Int [ MAX_NUMBER_VIEWS ];
53    m_aaiCodedScale       [ uiId ] = new Int [ MAX_NUMBER_VIEWS ];
54  }
55}
56
57CamParsCollector::~CamParsCollector()
58{
59  for( UInt uiId = 0; uiId < MAX_NUMBER_VIEWS; uiId++ )
60  {
61    delete [] m_aaiCodedOffset      [ uiId ];
62    delete [] m_aaiCodedScale       [ uiId ];
63  }
64  delete [] m_aaiCodedOffset;
65  delete [] m_aaiCodedScale;
66  delete [] m_aiViewOrderIndex;
67  delete [] m_aiViewReceived;
68}
69
70Void
71CamParsCollector::init( FILE* pCodedScaleOffsetFile )
72{
73  m_bInitialized            = true;
74  m_pCodedScaleOffsetFile   = pCodedScaleOffsetFile;
75  m_uiCamParsCodedPrecision = 0;
76  m_bCamParsVaryOverTime    = false;
77  m_iLastViewId             = -1;
78  m_iLastPOC                = -1;
79  m_uiMaxViewId             = 0;
80}
81
82Void
83CamParsCollector::uninit()
84{
85  m_bInitialized = false;
86}
87
88Void
89CamParsCollector::setSlice( TComSlice* pcSlice )
90{
91  if( pcSlice == 0 )
92  {
93    AOF( xIsComplete() );
94    if( m_bCamParsVaryOverTime || m_iLastPOC == 0 )
95    {
96      xOutput( m_iLastPOC );
97    }
98    return;
99  }
100
101  AOF( pcSlice->getSPS()->getViewId() < MAX_NUMBER_VIEWS );
102  if ( pcSlice->getSPS()->isDepth  () )
103  {
104    return;
105  }
106  Bool  bFirstAU          = ( pcSlice->getPOC()               == 0 );
107  Bool  bFirstSliceInAU   = ( pcSlice->getPOC()               != Int ( m_iLastPOC ) );
108  Bool  bFirstSliceInView = ( pcSlice->getSPS()->getViewId()  != UInt( m_iLastViewId ) || bFirstSliceInAU );
109  AOT(  bFirstSliceInAU  &&   pcSlice->getSPS()->getViewId()  != 0 );
110  AOT( !bFirstSliceInAU  &&   pcSlice->getSPS()->getViewId()   < UInt( m_iLastViewId ) );
111  AOT( !bFirstSliceInAU  &&   pcSlice->getSPS()->getViewId()   > UInt( m_iLastViewId + 1 ) );
112  AOT( !bFirstAU         &&   pcSlice->getSPS()->getViewId()   > m_uiMaxViewId );
113  if ( !bFirstSliceInView )
114  {
115    if( m_bCamParsVaryOverTime ) // check consistency of slice parameters here
116    {
117      UInt uiViewId = pcSlice->getSPS()->getViewId();
118      for( UInt uiBaseId = 0; uiBaseId < uiViewId; uiBaseId++ )
119      {
120        AOF( m_aaiCodedScale [ uiBaseId ][ uiViewId ] == pcSlice->getCodedScale    () [ uiBaseId ] );
121        AOF( m_aaiCodedOffset[ uiBaseId ][ uiViewId ] == pcSlice->getCodedOffset   () [ uiBaseId ] );
122        AOF( m_aaiCodedScale [ uiViewId ][ uiBaseId ] == pcSlice->getInvCodedScale () [ uiBaseId ] );
123        AOF( m_aaiCodedOffset[ uiViewId ][ uiBaseId ] == pcSlice->getInvCodedOffset() [ uiBaseId ] );
124      }
125    }
126    return;
127  }
128
129  if( bFirstSliceInAU )
130  {
131    if( !bFirstAU )
132    {
133      AOF( xIsComplete() );
134      xOutput( m_iLastPOC );
135    }
136    ::memset( m_aiViewReceived, 0x00, MAX_NUMBER_VIEWS * sizeof( Int ) );
137  }
138
139  UInt uiViewId                 = pcSlice->getSPS()->getViewId();
140  m_aiViewReceived[ uiViewId ]  = 1;
141  if( bFirstAU )
142  {
143    m_uiMaxViewId                     = Max( m_uiMaxViewId, uiViewId );
144    m_aiViewOrderIndex[ uiViewId ]    = pcSlice->getSPS()->getViewOrderIdx();
145    if( uiViewId == 1 )
146    {
147      m_uiCamParsCodedPrecision       = pcSlice->getSPS()->getCamParPrecision     ();
148      m_bCamParsVaryOverTime          = pcSlice->getSPS()->hasCamParInSliceHeader ();
149    }
150    else if( uiViewId > 1 )
151    {
152      AOF( m_uiCamParsCodedPrecision == pcSlice->getSPS()->getCamParPrecision     () );
153      AOF( m_bCamParsVaryOverTime    == pcSlice->getSPS()->hasCamParInSliceHeader () );
154    }
155    for( UInt uiBaseId = 0; uiBaseId < uiViewId; uiBaseId++ )
156    {
157      if( m_bCamParsVaryOverTime )
158      {
159        m_aaiCodedScale [ uiBaseId ][ uiViewId ]  = pcSlice->getCodedScale    () [ uiBaseId ];
160        m_aaiCodedOffset[ uiBaseId ][ uiViewId ]  = pcSlice->getCodedOffset   () [ uiBaseId ];
161        m_aaiCodedScale [ uiViewId ][ uiBaseId ]  = pcSlice->getInvCodedScale () [ uiBaseId ];
162        m_aaiCodedOffset[ uiViewId ][ uiBaseId ]  = pcSlice->getInvCodedOffset() [ uiBaseId ];
163      }
164      else
165      {
166        m_aaiCodedScale [ uiBaseId ][ uiViewId ]  = pcSlice->getSPS()->getCodedScale    () [ uiBaseId ];
167        m_aaiCodedOffset[ uiBaseId ][ uiViewId ]  = pcSlice->getSPS()->getCodedOffset   () [ uiBaseId ];
168        m_aaiCodedScale [ uiViewId ][ uiBaseId ]  = pcSlice->getSPS()->getInvCodedScale () [ uiBaseId ];
169        m_aaiCodedOffset[ uiViewId ][ uiBaseId ]  = pcSlice->getSPS()->getInvCodedOffset() [ uiBaseId ];
170      }
171    }
172  }
173  else
174  {
175    AOF( m_aiViewOrderIndex[ uiViewId ] == pcSlice->getSPS()->getViewOrderIdx() );
176    if( m_bCamParsVaryOverTime )
177    {
178      for( UInt uiBaseId = 0; uiBaseId < uiViewId; uiBaseId++ )
179      {
180        m_aaiCodedScale [ uiBaseId ][ uiViewId ]  = pcSlice->getCodedScale    () [ uiBaseId ];
181        m_aaiCodedOffset[ uiBaseId ][ uiViewId ]  = pcSlice->getCodedOffset   () [ uiBaseId ];
182        m_aaiCodedScale [ uiViewId ][ uiBaseId ]  = pcSlice->getInvCodedScale () [ uiBaseId ];
183        m_aaiCodedOffset[ uiViewId ][ uiBaseId ]  = pcSlice->getInvCodedOffset() [ uiBaseId ];
184      }
185    }
186  }
187  m_iLastViewId = (Int)pcSlice->getSPS()->getViewId();
188  m_iLastPOC    = (Int)pcSlice->getPOC();
189}
190
191Bool
192CamParsCollector::xIsComplete()
193{
194  for( UInt uiView = 0; uiView <= m_uiMaxViewId; uiView++ )
195  {
196    if( m_aiViewReceived[ uiView ] == 0 )
197    {
198      return false;
199    }
200  }
201  return true;
202}
203
204Void
205CamParsCollector::xOutput( Int iPOC )
206{
207  if( m_pCodedScaleOffsetFile )
208  {
209    if( iPOC == 0 )
210    {
211      fprintf( m_pCodedScaleOffsetFile, "#     ViewId ViewOrderIdx\n" );
212      fprintf( m_pCodedScaleOffsetFile, "#----------- ------------\n" );
213      for( UInt uiViewId = 0; uiViewId <= m_uiMaxViewId; uiViewId++ )
214      {
215        fprintf( m_pCodedScaleOffsetFile, "%12d %12d\n", uiViewId, m_aiViewOrderIndex[ uiViewId ] );
216      }
217      fprintf( m_pCodedScaleOffsetFile, "\n\n");
218      fprintf( m_pCodedScaleOffsetFile, "# StartFrame     EndFrame   TargetView     BaseView   CodedScale  CodedOffset    Precision\n" );
219      fprintf( m_pCodedScaleOffsetFile, "#----------- ------------ ------------ ------------ ------------ ------------ ------------\n" );
220    }
221    if( iPOC == 0 || m_bCamParsVaryOverTime )
222    {
223      Int iS = iPOC;
224      Int iE = ( m_bCamParsVaryOverTime ? iPOC : ~( 1 << 31 ) );
225      for( UInt uiViewId = 0; uiViewId <= m_uiMaxViewId; uiViewId++ )
226      {
227        for( UInt uiBaseId = 0; uiBaseId <= m_uiMaxViewId; uiBaseId++ )
228        {
229          if( uiViewId != uiBaseId )
230          {
231            fprintf( m_pCodedScaleOffsetFile, "%12d %12d %12d %12d %12d %12d %12d\n",
232                     iS, iE, uiViewId, uiBaseId, m_aaiCodedScale[ uiBaseId ][ uiViewId ], m_aaiCodedOffset[ uiBaseId ][ uiViewId ], m_uiCamParsCodedPrecision );
233          }
234        }
235      }
236    }
237  }
238}
239
240
241
242
243TDecTop::TDecTop()
244: m_SEIs(0)
245{
246  m_iGopSize      = 0;
247  m_bGopSizeSet   = false;
248  m_iMaxRefPicNum = 0;
249  m_uiValidPS = 0;
250  m_bIsDepth = false ;
251  m_iViewIdx = 0 ;
252#if ENC_DEC_TRACE
253  g_hTrace = fopen( "TraceDec.txt", "wb" );
254  g_bJustDoIt = g_bEncDecTraceDisable;
255  g_nSymbolCounter = 0;
256#endif
257#if DCM_DECODING_REFRESH
258  m_bRefreshPending = 0;
259  m_uiPOCCDR = 0;
260#if DCM_SKIP_DECODING_FRAMES
261  m_uiPOCRA = MAX_UINT;
262#endif
263#endif
264  m_uiPrevPOC               = UInt(-1);
265  m_bFirstSliceInPicture    = true;
266  m_bFirstSliceInSequence   = true;
267  m_pcCamParsCollector = 0;
268}
269
270TDecTop::~TDecTop()
271{
272#if ENC_DEC_TRACE
273  fclose( g_hTrace );
274#endif
275}
276
277Void TDecTop::create()
278{
279  m_cGopDecoder.create();
280  m_apcSlicePilot = new TComSlice;
281  m_uiSliceIdx = m_uiLastSliceIdx = 0;
282}
283
284Void TDecTop::destroy()
285{
286  m_cGopDecoder.destroy();
287
288  delete m_apcSlicePilot;
289  m_apcSlicePilot = NULL;
290
291  m_cSliceDecoder.destroy();
292
293#if DEPTH_MAP_GENERATION
294  m_cDepthMapGenerator.destroy();
295#endif
296#if HHI_INTER_VIEW_RESIDUAL_PRED
297  m_cResidualGenerator.destroy();
298#endif
299}
300
301Void TDecTop::init( TAppDecTop* pcTAppDecTop, Bool bFirstInstance )
302{
303  // initialize ROM
304  if( bFirstInstance )
305    initROM();
306#if MTK_SAO
307  m_cGopDecoder.  init( &m_cEntropyDecoder, &m_cSbacDecoder, &m_cBinCABAC, &m_cCavlcDecoder, &m_cSliceDecoder, &m_cLoopFilter, &m_cAdaptiveLoopFilter, &m_cSAO
308#if DEPTH_MAP_GENERATION
309                      , &m_cDepthMapGenerator
310#endif
311#if HHI_INTER_VIEW_RESIDUAL_PRED
312                      , &m_cResidualGenerator
313#endif
314                      );
315#else
316  m_cGopDecoder.  init( &m_cEntropyDecoder, &m_cSbacDecoder, &m_cBinCABAC, &m_cCavlcDecoder, &m_cSliceDecoder, &m_cLoopFilter, &m_cAdaptiveLoopFilter
317#if DEPTH_MAP_GENERATION
318                      , &m_cDepthMapGenerator
319#endif
320#if HHI_INTER_VIEW_RESIDUAL_PRED
321                      , &m_cResidualGenerator
322#endif
323                      );
324#endif
325  m_cSliceDecoder.init( &m_cEntropyDecoder, &m_cCuDecoder );
326  m_cEntropyDecoder.init(&m_cPrediction);
327
328  m_pcTAppDecTop = pcTAppDecTop;
329#if DEPTH_MAP_GENERATION
330  m_cDepthMapGenerator.init( &m_cPrediction, m_pcTAppDecTop->getSPSAccess(), m_pcTAppDecTop->getAUPicAccess() );
331#endif
332#if HHI_INTER_VIEW_RESIDUAL_PRED
333  m_cResidualGenerator.init( &m_cTrQuant, &m_cDepthMapGenerator );
334#endif
335}
336
337Void TDecTop::setSPS(TComSPS cSPS)
338{
339  m_cSPS = cSPS ;
340      if ( !m_cAdaptiveLoopFilter.isCreated())
341      {
342  m_cAdaptiveLoopFilter.create( m_cSPS.getWidth(), m_cSPS.getHeight(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth );
343#if MTK_SAO
344  m_cSAO.create( m_cSPS.getWidth(), m_cSPS.getHeight(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth );
345#endif
346  m_cLoopFilter.        create( g_uiMaxCUDepth );
347      }
348  m_uiValidPS |= 1;
349}
350
351Void TDecTop::deletePicBuffer ( )
352{
353  TComList<TComPic*>::iterator  iterPic   = m_cListPic.begin();
354  Int iSize = Int( m_cListPic.size() );
355
356  for (Int i = 0; i < iSize; i++ )
357  {
358    TComPic* pcPic = *(iterPic++);
359    pcPic->destroy();
360
361    delete pcPic;
362    pcPic = NULL;
363  }
364
365  // destroy ALF temporary buffers
366  m_cAdaptiveLoopFilter.destroy();
367
368#if MTK_SAO
369  m_cSAO.destroy();
370#endif
371
372  m_cLoopFilter.        destroy();
373
374  // destroy ROM
375  if( m_iViewIdx <= 0 && !m_bIsDepth)
376    destroyROM();
377}
378
379Void TDecTop::xGetNewPicBuffer ( TComSlice* pcSlice, TComPic*& rpcPic )
380{
381  m_iMaxRefPicNum = getCodedPictureBufferSize( );
382
383#if DEPTH_MAP_GENERATION
384  Bool bNeedPrdDepthMapBuffer = ( !pcSlice->getSPS()->isDepth() && ( pcSlice->getSPS()->getViewId() == 0 || pcSlice->getSPS()->getPredDepthMapGeneration() > 0 ) );
385#endif
386
387  if (m_cListPic.size() < (UInt)m_iMaxRefPicNum)
388  {
389    rpcPic = new TComPic;
390    rpcPic->create ( pcSlice->getSPS()->getWidth(), pcSlice->getSPS()->getHeight(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth );
391#if DEPTH_MAP_GENERATION
392    if( bNeedPrdDepthMapBuffer )
393    {
394      rpcPic->addPrdDepthMapBuffer();
395    }
396#endif
397    m_cListPic.pushBack( rpcPic );
398
399    return;
400  }
401
402  Bool bBufferIsAvailable = false;
403  TComList<TComPic*>::iterator  iterPic   = m_cListPic.begin();
404  while (iterPic != m_cListPic.end())
405  {
406    rpcPic = *(iterPic++);
407    if ( rpcPic->getReconMark() == false )
408    {
409      bBufferIsAvailable = true;
410      break;
411    }
412  }
413
414  if ( !bBufferIsAvailable )
415  {
416    pcSlice->sortPicList(m_cListPic);
417    iterPic = m_cListPic.begin();
418    rpcPic = *(iterPic);
419    rpcPic->setReconMark(false);
420
421    // mark it should be extended
422  }
423  rpcPic->getPicYuvRec()->setBorderExtension(false);
424
425#if DEPTH_MAP_GENERATION
426  if( bNeedPrdDepthMapBuffer && !rpcPic->getPredDepthMap() )
427  {
428    rpcPic->addPrdDepthMapBuffer();
429  }
430#endif
431}
432
433
434Void
435TDecTop::deleteExtraPicBuffers( Int iPoc )
436{
437  TComPic*                      pcPic = 0;
438  TComList<TComPic*>::iterator  cIter = m_cListPic.begin();
439  TComList<TComPic*>::iterator  cEnd  = m_cListPic.end  ();
440  for( ; cIter != cEnd; cIter++ )
441  {
442    if( (*cIter)->getPOC() == iPoc )
443    {
444      pcPic = *cIter;
445      break;
446    }
447  }
448  AOF( pcPic );
449  if ( pcPic )
450  {
451    pcPic->removeOriginalBuffer   ();
452#if HHI_INTER_VIEW_MOTION_PRED
453    pcPic->removeOrgDepthMapBuffer();
454#endif
455#if HHI_INTER_VIEW_RESIDUAL_PRED
456    pcPic->removeResidualBuffer   ();
457#endif
458#if HHI_INTERVIEW_SKIP
459    pcPic->removeUsedPelsMapBuffer();
460#endif
461  }
462}
463
464#if AMVP_BUFFERCOMPRESS
465Void
466TDecTop::compressMotion( Int iPoc )
467{
468  TComPic*                      pcPic = 0;
469  TComList<TComPic*>::iterator  cIter = m_cListPic.begin();
470  TComList<TComPic*>::iterator  cEnd  = m_cListPic.end  ();
471  for( ; cIter != cEnd; cIter++ )
472  {
473    if( (*cIter)->getPOC() == iPoc )
474    {
475      pcPic = *cIter;
476      break;
477    }
478  }
479  AOF( pcPic );
480  if ( pcPic )
481  {
482    pcPic->compressMotion();
483  }
484}
485#endif
486
487
488Void TDecTop::executeDeblockAndAlf(Bool bEos, TComBitstream* pcBitstream, UInt& ruiPOC, TComList<TComPic*>*& rpcListPic, Int& iSkipFrame,  Int& iPOCLastDisplay)
489{
490  TComPic*&   pcPic         = m_pcPic;
491
492  // Execute Deblock and ALF only + Cleanup
493  TComSlice* pcSlice  = pcPic->getPicSym()->getSlice( m_uiSliceIdx                  );
494  m_cGopDecoder.decompressGop ( bEos, pcBitstream, pcPic, true);
495
496  if( m_pcCamParsCollector && bEos )
497  {
498    m_pcCamParsCollector->setSlice( 0 );
499  }
500
501  pcSlice->sortPicList        ( m_cListPic );       //  sorting for application output
502  ruiPOC              = pcPic->getSlice(m_uiSliceIdx-1)->getPOC();
503  rpcListPic          = &m_cListPic;
504  m_cCuDecoder.destroy();
505  m_bFirstSliceInPicture  = true;
506
507  return;
508}
509
510#if DCM_SKIP_DECODING_FRAMES
511Bool TDecTop::decode (Bool bEos, TComBitstream* pcBitstream, UInt& ruiPOC, TComList<TComPic*>*& rpcListPic, NalUnitType& reNalUnitType, TComSPS& cComSPS, Int& iSkipFrame,  Int& iPOCLastDisplay)
512#else
513Void TDecTop::decode (Bool bEos, TComBitstream* pcBitstream, UInt& ruiPOC, TComList<TComPic*>*& rpcListPic, NalUnitType& reNalUnitType, TComSPS& cComSPS )
514#endif
515{
516  if (m_bFirstSliceInPicture)
517  {
518    rpcListPic = NULL;
519  }
520  TComPic*&   pcPic         = m_pcPic;
521
522  // Initialize entropy decoder
523  m_cEntropyDecoder.setEntropyDecoder (&m_cCavlcDecoder);
524  m_cEntropyDecoder.setBitstream      (pcBitstream);
525
526  NalUnitType eNalUnitType;
527  UInt        TemporalId;
528  Bool        OutputFlag;
529
530  m_cEntropyDecoder.decodeNalUnitHeader(eNalUnitType, TemporalId, OutputFlag);
531  reNalUnitType = eNalUnitType;
532
533  switch (eNalUnitType)
534  {
535    case NAL_UNIT_SPS:
536    {
537      TComSPS cTempSPS;
538      m_cEntropyDecoder.decodeSPS( &cTempSPS );
539
540      if( (m_iViewIdx == cTempSPS.getViewId()) && ( m_bIsDepth == cTempSPS.isDepth() ) )
541      {
542        m_cSPS = cTempSPS;
543        cComSPS = m_cSPS;
544      }
545      else
546      {
547        cComSPS = cTempSPS;
548        return false;
549      }
550
551      // create ALF temporary buffer
552      if ( !m_cAdaptiveLoopFilter.isCreated())
553      {
554      m_cAdaptiveLoopFilter.create( m_cSPS.getWidth(), m_cSPS.getHeight(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth );
555#if MTK_SAO
556      m_cSAO.create( m_cSPS.getWidth(), m_cSPS.getHeight(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth );
557#endif
558      m_cLoopFilter.        create( g_uiMaxCUDepth );
559      }
560      m_uiValidPS |= 1;
561
562      return false;
563    }
564
565    case NAL_UNIT_PPS:
566      m_cEntropyDecoder.decodePPS( &m_cPPS );
567      assert( m_cPPS.getSPSId() == m_cSPS.getSPSId() );
568      m_uiValidPS |= 2;
569      return false;
570
571    case NAL_UNIT_SEI:
572      m_SEIs = new SEImessages;
573      m_cEntropyDecoder.decodeSEI(*m_SEIs);
574      return false;
575
576    case NAL_UNIT_CODED_SLICE:
577    case NAL_UNIT_CODED_SLICE_IDR:
578    case NAL_UNIT_CODED_SLICE_CDR:
579    {
580      // make sure we already received both parameter sets
581      assert( 3 == m_uiValidPS );
582      if (m_bFirstSliceInPicture)
583      {
584        m_apcSlicePilot->initSlice();
585        m_uiSliceIdx     = 0;
586        m_uiLastSliceIdx = 0;
587      }
588      m_apcSlicePilot->setSliceIdx(m_uiSliceIdx);
589
590      //  Read slice header
591      m_apcSlicePilot->setSPS( &m_cSPS );
592      m_apcSlicePilot->setPPS( &m_cPPS );
593      m_apcSlicePilot->setSliceIdx(m_uiSliceIdx);
594      m_apcSlicePilot->setViewIdx( m_cSPS.getViewId() );
595      if (!m_bFirstSliceInPicture)
596      {
597        memcpy(m_apcSlicePilot, pcPic->getPicSym()->getSlice(m_uiSliceIdx-1), sizeof(TComSlice));
598      }
599
600#if DCM_DECODING_REFRESH
601      m_apcSlicePilot->setNalUnitType        (eNalUnitType);
602#endif
603      m_cEntropyDecoder.decodeSliceHeader (m_apcSlicePilot);
604
605//      if (m_apcSlicePilot->isNextSlice() && m_apcSlicePilot->getPOC()!=m_uiPrevPOC && !m_bFirstSliceInSequence)
606//      if (m_apcSlicePilot->isNextSlice() && ( m_apcSlicePilot->getPOC()!=m_uiPrevPOC || m_apcSlicePilot->getPPSId() != m_cPPS.getPPSId() ) && !m_bFirstSliceInSequence)
607      if (m_apcSlicePilot->isNextSlice() && ( m_apcSlicePilot->getPOC()!=m_uiPrevPOC || m_apcSlicePilot->getPPSId() != m_cPPS.getPPSId() ) && !m_bFirstSliceInPicture)
608      {
609        m_uiPrevPOC = m_apcSlicePilot->getPOC();
610        return true;
611      }
612      if (m_apcSlicePilot->isNextSlice())
613        m_uiPrevPOC = m_apcSlicePilot->getPOC();
614      m_bFirstSliceInSequence = false;
615      if (m_apcSlicePilot->isNextSlice())
616      {
617#if DCM_SKIP_DECODING_FRAMES
618        // Skip pictures due to random access
619        if (isRandomAccessSkipPicture(iSkipFrame, iPOCLastDisplay))
620        {
621          return false;
622        }
623#endif
624      }
625
626      if (m_bFirstSliceInPicture)
627      {
628        // Buffer initialize for prediction.
629        m_cPrediction.initTempBuff();
630        //  Get a new picture buffer
631        xGetNewPicBuffer (m_apcSlicePilot, pcPic);
632
633        pcPic->setViewIdx( m_cSPS.getViewId() );
634
635        /* transfer any SEI messages that have been received to the picture */
636        pcPic->setSEIs(m_SEIs);
637        m_SEIs = NULL;
638
639        // Recursive structure
640        m_cCuDecoder.create ( g_uiMaxCUDepth, g_uiMaxCUWidth, g_uiMaxCUHeight );
641        m_cCuDecoder.init   ( &m_cEntropyDecoder, &m_cTrQuant, &m_cPrediction );
642        m_cTrQuant.init     ( g_uiMaxCUWidth, g_uiMaxCUHeight, m_apcSlicePilot->getSPS()->getMaxTrSize());
643
644        m_cSliceDecoder.create( m_apcSlicePilot, m_apcSlicePilot->getSPS()->getWidth(), m_apcSlicePilot->getSPS()->getHeight(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth );
645
646#if DEPTH_MAP_GENERATION
647        m_cDepthMapGenerator.create( true, m_apcSlicePilot->getSPS()->getWidth(), m_apcSlicePilot->getSPS()->getHeight(), g_uiMaxCUDepth, g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiBitDepth + g_uiBitIncrement );
648#endif
649#if HHI_INTER_VIEW_RESIDUAL_PRED
650        m_cResidualGenerator.create( true, m_apcSlicePilot->getSPS()->getWidth(), m_apcSlicePilot->getSPS()->getHeight(), g_uiMaxCUDepth, g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiBitDepth + g_uiBitIncrement );
651#endif
652      }
653
654      //  Set picture slice pointer
655      TComSlice*  pcSlice = m_apcSlicePilot;
656      Bool bNextSlice     = pcSlice->isNextSlice();
657      if (m_bFirstSliceInPicture)
658      {
659        if(pcPic->getNumAllocatedSlice() != 1)
660        {
661          pcPic->clearSliceBuffer();
662        }
663      }
664      else
665      {
666        pcPic->allocateNewSlice();
667      }
668      assert(pcPic->getNumAllocatedSlice() == (m_uiSliceIdx + 1));
669      m_apcSlicePilot = pcPic->getPicSym()->getSlice(m_uiSliceIdx);
670      pcPic->getPicSym()->setSlice(pcSlice, m_uiSliceIdx);
671
672      if (bNextSlice)
673      {
674#if DCM_DECODING_REFRESH
675        // Do decoding refresh marking if any
676        pcSlice->decodingRefreshMarking(m_uiPOCCDR, m_bRefreshPending, m_cListPic);
677#endif
678
679        // Set reference list
680        std::vector<TComPic*> apcSpatRefPics = getDecTop()->getSpatialRefPics( pcPic->getViewIdx(), pcSlice->getPOC(), m_cSPS.isDepth() );
681        TComPic * const pcTexturePic = m_cSPS.isDepth() ? getDecTop()->getPicFromView( pcPic->getViewIdx(), pcSlice->getPOC(), false ) : NULL;
682        assert( ! m_cSPS.isDepth() || pcTexturePic != NULL );
683        pcSlice->setTexturePic( pcTexturePic );
684        pcSlice->setViewIdx( pcPic->getViewIdx() );
685        pcSlice->setRefPicListExplicitlyDecoderSided(m_cListPic, apcSpatRefPics) ;// temporary solution
686
687#if DCM_COMB_LIST
688        if(!pcSlice->getRefPicListModificationFlagLC())
689        {
690          pcSlice->generateCombinedList();
691        }
692#endif
693
694        pcSlice->setNoBackPredFlag( false );
695#if DCM_COMB_LIST
696        if ( pcSlice->getSliceType() == B_SLICE && !pcSlice->getRefPicListCombinationFlag())
697#else
698          if ( pcSlice->getSliceType() == B_SLICE )
699#endif
700          {
701            if ( pcSlice->getNumRefIdx(RefPicList( 0 ) ) == pcSlice->getNumRefIdx(RefPicList( 1 ) ) )
702            {
703              pcSlice->setNoBackPredFlag( true );
704              int i;
705              for ( i=0; i < pcSlice->getNumRefIdx(RefPicList( 1 ) ); i++ )
706              {
707                if ( pcSlice->getRefPOC(RefPicList(1), i) != pcSlice->getRefPOC(RefPicList(0), i) )
708                {
709                  pcSlice->setNoBackPredFlag( false );
710                  break;
711                }
712              }
713            }
714          }
715      }
716
717      pcPic->setCurrSliceIdx(m_uiSliceIdx);
718
719#if HHI_DMM_WEDGE_INTRA || HHI_DMM_PRED_TEX
720    if ( m_cSPS.getUseDMM() && g_aacWedgeLists.empty() && m_bIsDepth )
721      {
722        initWedgeLists();
723      }
724#endif
725
726      //  Decode a picture
727      m_cGopDecoder.decompressGop ( bEos, pcBitstream, pcPic, false );
728
729      if( m_pcCamParsCollector )
730      {
731        m_pcCamParsCollector->setSlice( pcSlice );
732      }
733
734      m_bFirstSliceInPicture = false;
735      m_uiSliceIdx++;
736    }
737      break;
738    default:
739      assert (1);
740  }
741
742  return false;
743}
744
745#if DCM_SKIP_DECODING_FRAMES
746/** Function for checking if picture should be skipped because of random access
747 * \param iSkipFrame skip frame counter
748 * \param iPOCLastDisplay POC of last picture displayed
749 * \returns true if the picture shold be skipped in the random access.
750 * This function checks the skipping of pictures in the case of -s option random access.
751 * All pictures prior to the random access point indicated by the counter iSkipFrame are skipped.
752 * It also checks the type of Nal unit type at the random access point.
753 * If the random access point is CDR, pictures with POC equal to or greater than the CDR POC are decoded.
754 * If the random access point is IDR all pictures after the random access point are decoded.
755 * If the random access point is not IDR or CDR, a warning is issues, and decoding of pictures with POC
756 * equal to or greater than the random access point POC is attempted. For non IDR/CDR random
757 * access point there is no guarantee that the decoder will not crash.
758 */
759Bool TDecTop::isRandomAccessSkipPicture(Int& iSkipFrame,  Int& iPOCLastDisplay)
760{
761  if (iSkipFrame)
762  {
763    iSkipFrame--;   // decrement the counter
764    return true;
765  }
766  else if (m_uiPOCRA == MAX_UINT) // start of random access point, m_uiPOCRA has not been set yet.
767  {
768    if (m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_CDR)
769    {
770      m_uiPOCRA = m_apcSlicePilot->getPOC(); // set the POC random access since we need to skip the reordered pictures in CDR.
771    }
772    else if (m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR)
773    {
774      m_uiPOCRA = 0; // no need to skip the reordered pictures in IDR, they are decodable.
775    }
776    else
777    {
778      printf("\nUnsafe random access point. Decoder may crash.");
779      m_uiPOCRA = m_apcSlicePilot->getPOC(); // set the POC random access skip the reordered pictures and try to decode if possible.  This increases the chances of avoiding a decoder crash.
780      //m_uiPOCRA = 0;
781    }
782  }
783  else if (m_apcSlicePilot->getPOC() < m_uiPOCRA)  // skip the reordered pictures if necessary
784  {
785    iPOCLastDisplay++;
786    return true;
787  }
788  // if we reach here, then the picture is not skipped.
789  return false;
790}
791#endif
792
Note: See TracBrowser for help on using the repository browser.