source: 3DVCSoftware/branches/0.3-ericsson/source/Lib/TLibDecoder/TDecTop.cpp @ 36

Last change on this file since 36 was 34, checked in by nokia, 13 years ago

FlexCO upload

  • Property svn:eol-style set to native
File size: 26.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-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 SONY_COLPIC_AVAILABILITY
253  m_iViewOrderIdx = 0;
254#endif
255#if ENC_DEC_TRACE
256  g_hTrace = fopen( "TraceDec.txt", "wb" );
257  g_bJustDoIt = g_bEncDecTraceDisable;
258  g_nSymbolCounter = 0;
259#endif
260#if DCM_DECODING_REFRESH
261  m_bRefreshPending = 0;
262  m_uiPOCCDR = 0;
263#if DCM_SKIP_DECODING_FRAMES
264  m_uiPOCRA = MAX_UINT;
265#endif
266#endif
267  m_uiPrevPOC               = UInt(-1);
268  m_bFirstSliceInPicture    = true;
269  m_bFirstSliceInSequence   = true;
270  m_pcCamParsCollector = 0;
271}
272
273TDecTop::~TDecTop()
274{
275#if ENC_DEC_TRACE
276  fclose( g_hTrace );
277#endif
278}
279
280Void TDecTop::create()
281{
282  m_cGopDecoder.create();
283  m_apcSlicePilot = new TComSlice;
284  m_uiSliceIdx = m_uiLastSliceIdx = 0;
285}
286
287Void TDecTop::destroy()
288{
289  m_cGopDecoder.destroy();
290
291  delete m_apcSlicePilot;
292  m_apcSlicePilot = NULL;
293
294  m_cSliceDecoder.destroy();
295
296#if DEPTH_MAP_GENERATION
297  m_cDepthMapGenerator.destroy();
298#endif
299#if HHI_INTER_VIEW_RESIDUAL_PRED
300  m_cResidualGenerator.destroy();
301#endif
302}
303
304Void TDecTop::init( TAppDecTop* pcTAppDecTop, Bool bFirstInstance )
305{
306  // initialize ROM
307  if( bFirstInstance )
308    initROM();
309#if MTK_SAO
310  m_cGopDecoder.  init( &m_cEntropyDecoder, &m_cSbacDecoder, &m_cBinCABAC, &m_cCavlcDecoder, &m_cSliceDecoder, &m_cLoopFilter, &m_cAdaptiveLoopFilter, &m_cSAO
311#if DEPTH_MAP_GENERATION
312                      , &m_cDepthMapGenerator
313#endif
314#if HHI_INTER_VIEW_RESIDUAL_PRED
315                      , &m_cResidualGenerator
316#endif
317                      );
318#else
319  m_cGopDecoder.  init( &m_cEntropyDecoder, &m_cSbacDecoder, &m_cBinCABAC, &m_cCavlcDecoder, &m_cSliceDecoder, &m_cLoopFilter, &m_cAdaptiveLoopFilter
320#if DEPTH_MAP_GENERATION
321                      , &m_cDepthMapGenerator
322#endif
323#if HHI_INTER_VIEW_RESIDUAL_PRED
324                      , &m_cResidualGenerator
325#endif
326                      );
327#endif
328  m_cSliceDecoder.init( &m_cEntropyDecoder, &m_cCuDecoder );
329  m_cEntropyDecoder.init(&m_cPrediction);
330
331  m_pcTAppDecTop = pcTAppDecTop;
332#if DEPTH_MAP_GENERATION
333  m_cDepthMapGenerator.init( &m_cPrediction, m_pcTAppDecTop->getSPSAccess(), m_pcTAppDecTop->getAUPicAccess() );
334#endif
335#if HHI_INTER_VIEW_RESIDUAL_PRED
336  m_cResidualGenerator.init( &m_cTrQuant, &m_cDepthMapGenerator );
337#endif
338}
339
340Void TDecTop::setSPS(TComSPS cSPS)
341{
342  m_cSPS = cSPS ;
343      if ( !m_cAdaptiveLoopFilter.isCreated())
344      {
345  m_cAdaptiveLoopFilter.create( m_cSPS.getWidth(), m_cSPS.getHeight(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth );
346#if MTK_SAO
347  m_cSAO.create( m_cSPS.getWidth(), m_cSPS.getHeight(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth );
348#endif
349  m_cLoopFilter.        create( g_uiMaxCUDepth );
350      }
351  m_uiValidPS |= 1;
352}
353
354Void TDecTop::deletePicBuffer ( )
355{
356  TComList<TComPic*>::iterator  iterPic   = m_cListPic.begin();
357  Int iSize = Int( m_cListPic.size() );
358
359  for (Int i = 0; i < iSize; i++ )
360  {
361    TComPic* pcPic = *(iterPic++);
362    pcPic->destroy();
363
364    delete pcPic;
365    pcPic = NULL;
366  }
367
368  // destroy ALF temporary buffers
369  m_cAdaptiveLoopFilter.destroy();
370
371#if MTK_SAO
372  m_cSAO.destroy();
373#endif
374
375  m_cLoopFilter.        destroy();
376
377  // destroy ROM
378  if( m_iViewIdx <= 0 && !m_bIsDepth)
379    destroyROM();
380}
381
382Void TDecTop::xGetNewPicBuffer ( TComSlice* pcSlice, TComPic*& rpcPic )
383{
384  m_iMaxRefPicNum = getCodedPictureBufferSize( );
385
386#if DEPTH_MAP_GENERATION
387  UInt uiPdm                  = ( pcSlice->getSPS()->getViewId() ? pcSlice->getSPS()->getPredDepthMapGeneration() : m_pcTAppDecTop->getSPSAccess()->getPdm() );
388  Bool bNeedPrdDepthMapBuffer = ( !pcSlice->getSPS()->isDepth() && uiPdm > 0 );
389#endif
390
391  if (m_cListPic.size() < (UInt)m_iMaxRefPicNum)
392  {
393    rpcPic = new TComPic;
394    rpcPic->create ( pcSlice->getSPS()->getWidth(), pcSlice->getSPS()->getHeight(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth );
395#if DEPTH_MAP_GENERATION
396    if( bNeedPrdDepthMapBuffer )
397    {
398      rpcPic->addPrdDepthMapBuffer( PDM_SUB_SAMP_EXP_X(uiPdm), PDM_SUB_SAMP_EXP_Y(uiPdm) );
399    }
400#endif
401    m_cListPic.pushBack( rpcPic );
402
403    return;
404  }
405
406  Bool bBufferIsAvailable = false;
407  TComList<TComPic*>::iterator  iterPic   = m_cListPic.begin();
408  while (iterPic != m_cListPic.end())
409  {
410    rpcPic = *(iterPic++);
411    if ( rpcPic->getReconMark() == false )
412    {
413      bBufferIsAvailable = true;
414      break;
415    }
416  }
417
418  if ( !bBufferIsAvailable )
419  {
420    pcSlice->sortPicList(m_cListPic);
421    iterPic = m_cListPic.begin();
422    rpcPic = *(iterPic);
423    rpcPic->setReconMark(false);
424
425    // mark it should be extended
426  }
427  rpcPic->getPicYuvRec()->setBorderExtension(false);
428
429#if DEPTH_MAP_GENERATION
430  if( bNeedPrdDepthMapBuffer && !rpcPic->getPredDepthMap() )
431  {
432    rpcPic->addPrdDepthMapBuffer( PDM_SUB_SAMP_EXP_X(uiPdm), PDM_SUB_SAMP_EXP_Y(uiPdm) );
433  }
434#endif
435}
436
437
438Void
439TDecTop::deleteExtraPicBuffers( Int iPoc )
440{
441  TComPic*                      pcPic = 0;
442  TComList<TComPic*>::iterator  cIter = m_cListPic.begin();
443  TComList<TComPic*>::iterator  cEnd  = m_cListPic.end  ();
444  for( ; cIter != cEnd; cIter++ )
445  {
446    if( (*cIter)->getPOC() == iPoc )
447    {
448      pcPic = *cIter;
449      break;
450    }
451  }
452  AOF( pcPic );
453  if ( pcPic )
454  {
455    pcPic->removeOriginalBuffer   ();
456#if HHI_INTER_VIEW_MOTION_PRED
457    pcPic->removeOrgDepthMapBuffer();
458#endif
459#if HHI_INTER_VIEW_RESIDUAL_PRED
460    pcPic->removeResidualBuffer   ();
461#endif
462#if HHI_INTERVIEW_SKIP
463    pcPic->removeUsedPelsMapBuffer();
464#endif
465  }
466}
467
468#if AMVP_BUFFERCOMPRESS
469Void
470TDecTop::compressMotion( Int iPoc )
471{
472  TComPic*                      pcPic = 0;
473  TComList<TComPic*>::iterator  cIter = m_cListPic.begin();
474  TComList<TComPic*>::iterator  cEnd  = m_cListPic.end  ();
475  for( ; cIter != cEnd; cIter++ )
476  {
477    if( (*cIter)->getPOC() == iPoc )
478    {
479      pcPic = *cIter;
480      break;
481    }
482  }
483  AOF( pcPic );
484  if ( pcPic )
485  {
486    pcPic->compressMotion();
487  }
488}
489#endif
490
491
492Void TDecTop::executeDeblockAndAlf(Bool bEos, TComBitstream* pcBitstream, UInt& ruiPOC, TComList<TComPic*>*& rpcListPic, Int& iSkipFrame,  Int& iPOCLastDisplay)
493{
494  TComPic*&   pcPic         = m_pcPic;
495
496  // Execute Deblock and ALF only + Cleanup
497  TComSlice* pcSlice  = pcPic->getPicSym()->getSlice( m_uiSliceIdx                  );
498  m_cGopDecoder.decompressGop ( bEos, pcBitstream, pcPic, true);
499
500  if( m_pcCamParsCollector && bEos )
501  {
502    m_pcCamParsCollector->setSlice( 0 );
503  }
504
505  pcSlice->sortPicList        ( m_cListPic );       //  sorting for application output
506  ruiPOC              = pcPic->getSlice(m_uiSliceIdx-1)->getPOC();
507  rpcListPic          = &m_cListPic;
508  m_cCuDecoder.destroy();
509  m_bFirstSliceInPicture  = true;
510
511  return;
512}
513
514#if DCM_SKIP_DECODING_FRAMES
515#if FLEX_CODING_ORDER
516Bool TDecTop::decode (Bool bEos, TComBitstream* pcBitstream, UInt& ruiPOC, TComList<TComPic*>*& rpcListPic, NalUnitType& reNalUnitType, TComSPS& cComSPS, Int& iSkipFrame,  Int& iPOCLastDisplay, Bool& bNewPictureType)
517#else
518Bool TDecTop::decode (Bool bEos, TComBitstream* pcBitstream, UInt& ruiPOC, TComList<TComPic*>*& rpcListPic, NalUnitType& reNalUnitType, TComSPS& cComSPS, Int& iSkipFrame,  Int& iPOCLastDisplay)
519
520#endif
521#else
522Void TDecTop::decode (Bool bEos, TComBitstream* pcBitstream, UInt& ruiPOC, TComList<TComPic*>*& rpcListPic, NalUnitType& reNalUnitType, TComSPS& cComSPS )
523#endif
524{
525  if (m_bFirstSliceInPicture)
526  {
527    rpcListPic = NULL;
528  }
529  TComPic*&   pcPic         = m_pcPic;
530
531  // Initialize entropy decoder
532  m_cEntropyDecoder.setEntropyDecoder (&m_cCavlcDecoder);
533  m_cEntropyDecoder.setBitstream      (pcBitstream);
534
535  NalUnitType eNalUnitType;
536  UInt        TemporalId;
537  Bool        OutputFlag;
538
539  m_cEntropyDecoder.decodeNalUnitHeader(eNalUnitType, TemporalId, OutputFlag);
540  reNalUnitType = eNalUnitType;
541
542  switch (eNalUnitType)
543  {
544    case NAL_UNIT_SPS:
545    {
546      TComSPS cTempSPS;
547      m_cEntropyDecoder.decodeSPS( &cTempSPS );
548#if FLEX_CODING_ORDER
549      m_cNewSPS = cTempSPS;
550#endif
551
552      if( (m_iViewIdx == cTempSPS.getViewId()) && ( m_bIsDepth == cTempSPS.isDepth() ) )
553      {
554        m_cSPS = cTempSPS;
555        cComSPS = m_cSPS;
556      }
557      else
558      {
559        cComSPS = cTempSPS;
560        return false;
561      }
562
563      // create ALF temporary buffer
564      if ( !m_cAdaptiveLoopFilter.isCreated())
565      {
566      m_cAdaptiveLoopFilter.create( m_cSPS.getWidth(), m_cSPS.getHeight(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth );
567#if MTK_SAO
568      m_cSAO.create( m_cSPS.getWidth(), m_cSPS.getHeight(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth );
569#endif
570      m_cLoopFilter.        create( g_uiMaxCUDepth );
571      }
572      m_uiValidPS |= 1;
573
574      return false;
575    }
576
577    case NAL_UNIT_PPS:
578      m_cEntropyDecoder.decodePPS( &m_cPPS );
579      assert( m_cPPS.getSPSId() == m_cSPS.getSPSId() );
580      m_uiValidPS |= 2;
581      return false;
582
583    case NAL_UNIT_SEI:
584      m_SEIs = new SEImessages;
585      m_cEntropyDecoder.decodeSEI(*m_SEIs);
586      return false;
587
588    case NAL_UNIT_CODED_SLICE:
589    case NAL_UNIT_CODED_SLICE_IDR:
590    case NAL_UNIT_CODED_SLICE_CDR:
591    {
592      // make sure we already received both parameter sets
593      assert( 3 == m_uiValidPS );
594      if (m_bFirstSliceInPicture)
595      {
596        m_apcSlicePilot->initSlice();
597        m_uiSliceIdx     = 0;
598        m_uiLastSliceIdx = 0;
599      }
600      m_apcSlicePilot->setSliceIdx(m_uiSliceIdx);
601
602      //  Read slice header
603      m_apcSlicePilot->setSPS( &m_cSPS );
604      m_apcSlicePilot->setPPS( &m_cPPS );
605      m_apcSlicePilot->setSliceIdx(m_uiSliceIdx);
606      m_apcSlicePilot->setViewIdx( m_cSPS.getViewId() );
607#if SONY_COLPIC_AVAILABILITY
608      m_apcSlicePilot->setViewOrderIdx( m_cSPS.getViewOrderIdx());
609#endif
610      if (!m_bFirstSliceInPicture)
611      {
612        memcpy(m_apcSlicePilot, pcPic->getPicSym()->getSlice(m_uiSliceIdx-1), sizeof(TComSlice));
613      }
614
615#if DCM_DECODING_REFRESH
616      m_apcSlicePilot->setNalUnitType        (eNalUnitType);
617#endif
618      m_cEntropyDecoder.decodeSliceHeader (m_apcSlicePilot);
619
620//      if (m_apcSlicePilot->isNextSlice() && m_apcSlicePilot->getPOC()!=m_uiPrevPOC && !m_bFirstSliceInSequence)
621//      if (m_apcSlicePilot->isNextSlice() && ( m_apcSlicePilot->getPOC()!=m_uiPrevPOC || m_apcSlicePilot->getPPSId() != m_cPPS.getPPSId() ) && !m_bFirstSliceInSequence)
622      if (m_apcSlicePilot->isNextSlice() && ( m_apcSlicePilot->getPOC()!=m_uiPrevPOC || m_apcSlicePilot->getPPSId() != m_cPPS.getPPSId() ) && !m_bFirstSliceInPicture)
623      {
624        m_uiPrevPOC = m_apcSlicePilot->getPOC();
625#if FLEX_CODING_ORDER
626        bNewPictureType = m_cNewSPS.isDepth();
627#endif
628        return true;
629      }
630      if (m_apcSlicePilot->isNextSlice())
631        m_uiPrevPOC = m_apcSlicePilot->getPOC();
632      m_bFirstSliceInSequence = false;
633      if (m_apcSlicePilot->isNextSlice())
634      {
635#if DCM_SKIP_DECODING_FRAMES
636        // Skip pictures due to random access
637        if (isRandomAccessSkipPicture(iSkipFrame, iPOCLastDisplay))
638        {
639          return false;
640        }
641#endif
642      }
643
644      if (m_bFirstSliceInPicture)
645      {
646        // Buffer initialize for prediction.
647        m_cPrediction.initTempBuff();
648        //  Get a new picture buffer
649        xGetNewPicBuffer (m_apcSlicePilot, pcPic);
650
651        pcPic->setViewIdx( m_cSPS.getViewId() );
652
653#if SONY_COLPIC_AVAILABILITY
654        pcPic->setViewOrderIdx( m_cSPS.getViewOrderIdx() );
655#endif
656
657        /* transfer any SEI messages that have been received to the picture */
658        pcPic->setSEIs(m_SEIs);
659        m_SEIs = NULL;
660
661        // Recursive structure
662        m_cCuDecoder.create ( g_uiMaxCUDepth, g_uiMaxCUWidth, g_uiMaxCUHeight );
663        m_cCuDecoder.init   ( &m_cEntropyDecoder, &m_cTrQuant, &m_cPrediction );
664        m_cTrQuant.init     ( g_uiMaxCUWidth, g_uiMaxCUHeight, m_apcSlicePilot->getSPS()->getMaxTrSize());
665
666        m_cSliceDecoder.create( m_apcSlicePilot, m_apcSlicePilot->getSPS()->getWidth(), m_apcSlicePilot->getSPS()->getHeight(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth );
667
668#if DEPTH_MAP_GENERATION
669        UInt uiPdm = ( m_cSPS.getViewId() ? m_cSPS.getPredDepthMapGeneration() : getDecTop()->getSPSAccess()->getPdm() );
670        m_cDepthMapGenerator.create( true, m_apcSlicePilot->getSPS()->getWidth(), m_apcSlicePilot->getSPS()->getHeight(), g_uiMaxCUDepth, g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiBitDepth + g_uiBitIncrement, PDM_SUB_SAMP_EXP_X(uiPdm), PDM_SUB_SAMP_EXP_Y(uiPdm) );
671        TComDepthMapGenerator* pcDMG0 = getDecTop()->getDecTop0()->getDepthMapGenerator();
672        if( m_cSPS.getViewId() == 1 && ( pcDMG0->getSubSampExpX() != PDM_SUB_SAMP_EXP_X(uiPdm) || pcDMG0->getSubSampExpY() != PDM_SUB_SAMP_EXP_Y(uiPdm) ) )
673        {
674          pcDMG0->create( true, m_apcSlicePilot->getSPS()->getWidth(), m_apcSlicePilot->getSPS()->getHeight(), g_uiMaxCUDepth, g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiBitDepth + g_uiBitIncrement, PDM_SUB_SAMP_EXP_X(uiPdm), PDM_SUB_SAMP_EXP_Y(uiPdm) );
675        }
676#endif
677#if HHI_INTER_VIEW_RESIDUAL_PRED
678        m_cResidualGenerator.create( true, m_apcSlicePilot->getSPS()->getWidth(), m_apcSlicePilot->getSPS()->getHeight(), g_uiMaxCUDepth, g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiBitDepth + g_uiBitIncrement );
679#endif
680      }
681
682      //  Set picture slice pointer
683      TComSlice*  pcSlice = m_apcSlicePilot;
684      Bool bNextSlice     = pcSlice->isNextSlice();
685      if (m_bFirstSliceInPicture)
686      {
687        if(pcPic->getNumAllocatedSlice() != 1)
688        {
689          pcPic->clearSliceBuffer();
690        }
691      }
692      else
693      {
694        pcPic->allocateNewSlice();
695      }
696      assert(pcPic->getNumAllocatedSlice() == (m_uiSliceIdx + 1));
697      m_apcSlicePilot = pcPic->getPicSym()->getSlice(m_uiSliceIdx);
698      pcPic->getPicSym()->setSlice(pcSlice, m_uiSliceIdx);
699
700      if (bNextSlice)
701      {
702#if DCM_DECODING_REFRESH
703        // Do decoding refresh marking if any
704        pcSlice->decodingRefreshMarking(m_uiPOCCDR, m_bRefreshPending, m_cListPic);
705#endif
706
707        // Set reference list
708        std::vector<TComPic*> apcSpatRefPics = getDecTop()->getSpatialRefPics( pcPic->getViewIdx(), pcSlice->getPOC(), m_cSPS.isDepth() );
709        TComPic * const pcTexturePic = m_cSPS.isDepth() ? getDecTop()->getPicFromView( pcPic->getViewIdx(), pcSlice->getPOC(), false ) : NULL;
710
711#if FLEX_CODING_ORDER
712        if (pcTexturePic != NULL)
713        {
714          assert( ! m_cSPS.isDepth() || pcTexturePic != NULL );
715          pcSlice->setTexturePic( pcTexturePic );
716        }
717#else
718        assert( ! m_cSPS.isDepth() || pcTexturePic != NULL );
719        pcSlice->setTexturePic( pcTexturePic );
720        pcSlice->setViewIdx( pcPic->getViewIdx() );
721#endif
722#if SONY_COLPIC_AVAILABILITY
723        pcSlice->setViewOrderIdx( pcPic->getViewOrderIdx() );
724#endif
725        pcSlice->setRefPicListExplicitlyDecoderSided(m_cListPic, apcSpatRefPics) ;// temporary solution
726
727#if DCM_COMB_LIST
728        if(!pcSlice->getRefPicListModificationFlagLC())
729        {
730          pcSlice->generateCombinedList();
731        }
732#endif
733
734        pcSlice->setNoBackPredFlag( false );
735#if DCM_COMB_LIST
736        if ( pcSlice->getSliceType() == B_SLICE && !pcSlice->getRefPicListCombinationFlag())
737#else
738          if ( pcSlice->getSliceType() == B_SLICE )
739#endif
740          {
741            if ( pcSlice->getNumRefIdx(RefPicList( 0 ) ) == pcSlice->getNumRefIdx(RefPicList( 1 ) ) )
742            {
743              pcSlice->setNoBackPredFlag( true );
744              int i;
745              for ( i=0; i < pcSlice->getNumRefIdx(RefPicList( 1 ) ); i++ )
746              {
747                if ( pcSlice->getRefPOC(RefPicList(1), i) != pcSlice->getRefPOC(RefPicList(0), i) )
748                {
749                  pcSlice->setNoBackPredFlag( false );
750                  break;
751                }
752              }
753            }
754          }
755      }
756
757      pcPic->setCurrSliceIdx(m_uiSliceIdx);
758
759#if HHI_DMM_WEDGE_INTRA || HHI_DMM_PRED_TEX
760    if ( m_cSPS.getUseDMM() && g_aacWedgeLists.empty() && m_bIsDepth )
761      {
762        initWedgeLists();
763      }
764#endif
765
766      //  Decode a picture
767      m_cGopDecoder.decompressGop ( bEos, pcBitstream, pcPic, false );
768
769      if( m_pcCamParsCollector )
770      {
771        m_pcCamParsCollector->setSlice( pcSlice );
772      }
773
774      m_bFirstSliceInPicture = false;
775      m_uiSliceIdx++;
776    }
777      break;
778    default:
779      assert (1);
780  }
781
782  return false;
783}
784
785#if DCM_SKIP_DECODING_FRAMES
786/** Function for checking if picture should be skipped because of random access
787 * \param iSkipFrame skip frame counter
788 * \param iPOCLastDisplay POC of last picture displayed
789 * \returns true if the picture shold be skipped in the random access.
790 * This function checks the skipping of pictures in the case of -s option random access.
791 * All pictures prior to the random access point indicated by the counter iSkipFrame are skipped.
792 * It also checks the type of Nal unit type at the random access point.
793 * If the random access point is CDR, pictures with POC equal to or greater than the CDR POC are decoded.
794 * If the random access point is IDR all pictures after the random access point are decoded.
795 * If the random access point is not IDR or CDR, a warning is issues, and decoding of pictures with POC
796 * equal to or greater than the random access point POC is attempted. For non IDR/CDR random
797 * access point there is no guarantee that the decoder will not crash.
798 */
799Bool TDecTop::isRandomAccessSkipPicture(Int& iSkipFrame,  Int& iPOCLastDisplay)
800{
801  if (iSkipFrame)
802  {
803    iSkipFrame--;   // decrement the counter
804    return true;
805  }
806  else if (m_uiPOCRA == MAX_UINT) // start of random access point, m_uiPOCRA has not been set yet.
807  {
808    if (m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_CDR)
809    {
810      m_uiPOCRA = m_apcSlicePilot->getPOC(); // set the POC random access since we need to skip the reordered pictures in CDR.
811    }
812    else if (m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR)
813    {
814      m_uiPOCRA = 0; // no need to skip the reordered pictures in IDR, they are decodable.
815    }
816    else
817    {
818      printf("\nUnsafe random access point. Decoder may crash.");
819      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.
820      //m_uiPOCRA = 0;
821    }
822  }
823  else if (m_apcSlicePilot->getPOC() < m_uiPOCRA)  // skip the reordered pictures if necessary
824  {
825    iPOCLastDisplay++;
826    return true;
827  }
828  // if we reach here, then the picture is not skipped.
829  return false;
830}
831#endif
832
Note: See TracBrowser for help on using the repository browser.