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

Last change on this file since 42 was 42, checked in by tech, 12 years ago

Nokia (Flexible Coding Order)
Ericsson ( High Level Syntax )
changes

  • Property svn:eol-style set to native
File size: 26.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 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
538#if BITSTREAM_EXTRACTION
539  UInt        uiLayerId;
540
541  m_cEntropyDecoder.decodeNalUnitHeader(eNalUnitType, TemporalId, uiLayerId);
542#else
543  Bool        OutputFlag;
544
545  m_cEntropyDecoder.decodeNalUnitHeader(eNalUnitType, TemporalId, OutputFlag);
546#endif
547
548  reNalUnitType = eNalUnitType;
549
550  switch (eNalUnitType)
551  {
552    case NAL_UNIT_SPS:
553    {
554      TComSPS cTempSPS;
555      m_cEntropyDecoder.decodeSPS( &cTempSPS );
556#if FLEX_CODING_ORDER
557      m_cNewSPS = cTempSPS;
558#endif
559
560      if( (m_iViewIdx == cTempSPS.getViewId()) && ( m_bIsDepth == cTempSPS.isDepth() ) )
561      {
562        m_cSPS = cTempSPS;
563        cComSPS = m_cSPS;
564      }
565      else
566      {
567        cComSPS = cTempSPS;
568        return false;
569      }
570
571      // create ALF temporary buffer
572      if ( !m_cAdaptiveLoopFilter.isCreated())
573      {
574      m_cAdaptiveLoopFilter.create( m_cSPS.getWidth(), m_cSPS.getHeight(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth );
575#if MTK_SAO
576      m_cSAO.create( m_cSPS.getWidth(), m_cSPS.getHeight(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth );
577#endif
578      m_cLoopFilter.        create( g_uiMaxCUDepth );
579      }
580      m_uiValidPS |= 1;
581
582      return false;
583    }
584
585    case NAL_UNIT_PPS:
586      m_cEntropyDecoder.decodePPS( &m_cPPS );
587      assert( m_cPPS.getSPSId() == m_cSPS.getSPSId() );
588      m_uiValidPS |= 2;
589      return false;
590
591    case NAL_UNIT_SEI:
592      m_SEIs = new SEImessages;
593      m_cEntropyDecoder.decodeSEI(*m_SEIs);
594      return false;
595
596    case NAL_UNIT_CODED_SLICE:
597    case NAL_UNIT_CODED_SLICE_IDR:
598    case NAL_UNIT_CODED_SLICE_CDR:
599    {
600      // make sure we already received both parameter sets
601      assert( 3 == m_uiValidPS );
602      if (m_bFirstSliceInPicture)
603      {
604        m_apcSlicePilot->initSlice();
605        m_uiSliceIdx     = 0;
606        m_uiLastSliceIdx = 0;
607      }
608      m_apcSlicePilot->setSliceIdx(m_uiSliceIdx);
609
610      //  Read slice header
611      m_apcSlicePilot->setSPS( &m_cSPS );
612      m_apcSlicePilot->setPPS( &m_cPPS );
613      m_apcSlicePilot->setSliceIdx(m_uiSliceIdx);
614      m_apcSlicePilot->setViewIdx( m_cSPS.getViewId() );
615#if SONY_COLPIC_AVAILABILITY
616      m_apcSlicePilot->setViewOrderIdx( m_cSPS.getViewOrderIdx());
617#endif
618      if (!m_bFirstSliceInPicture)
619      {
620        memcpy(m_apcSlicePilot, pcPic->getPicSym()->getSlice(m_uiSliceIdx-1), sizeof(TComSlice));
621      }
622
623#if DCM_DECODING_REFRESH
624      m_apcSlicePilot->setNalUnitType        (eNalUnitType);
625#endif
626      m_cEntropyDecoder.decodeSliceHeader (m_apcSlicePilot);
627
628//      if (m_apcSlicePilot->isNextSlice() && m_apcSlicePilot->getPOC()!=m_uiPrevPOC && !m_bFirstSliceInSequence)
629//      if (m_apcSlicePilot->isNextSlice() && ( m_apcSlicePilot->getPOC()!=m_uiPrevPOC || m_apcSlicePilot->getPPSId() != m_cPPS.getPPSId() ) && !m_bFirstSliceInSequence)
630      if (m_apcSlicePilot->isNextSlice() && ( m_apcSlicePilot->getPOC()!=m_uiPrevPOC || m_apcSlicePilot->getPPSId() != m_cPPS.getPPSId() ) && !m_bFirstSliceInPicture)
631      {
632        m_uiPrevPOC = m_apcSlicePilot->getPOC();
633#if FLEX_CODING_ORDER
634        bNewPictureType = m_cNewSPS.isDepth();
635#endif
636        return true;
637      }
638      if (m_apcSlicePilot->isNextSlice())
639        m_uiPrevPOC = m_apcSlicePilot->getPOC();
640      m_bFirstSliceInSequence = false;
641      if (m_apcSlicePilot->isNextSlice())
642      {
643#if DCM_SKIP_DECODING_FRAMES
644        // Skip pictures due to random access
645        if (isRandomAccessSkipPicture(iSkipFrame, iPOCLastDisplay))
646        {
647          return false;
648        }
649#endif
650      }
651
652      if (m_bFirstSliceInPicture)
653      {
654        // Buffer initialize for prediction.
655        m_cPrediction.initTempBuff();
656        //  Get a new picture buffer
657        xGetNewPicBuffer (m_apcSlicePilot, pcPic);
658
659        pcPic->setViewIdx( m_cSPS.getViewId() );
660
661#if SONY_COLPIC_AVAILABILITY
662        pcPic->setViewOrderIdx( m_cSPS.getViewOrderIdx() );
663#endif
664
665        /* transfer any SEI messages that have been received to the picture */
666        pcPic->setSEIs(m_SEIs);
667        m_SEIs = NULL;
668
669        // Recursive structure
670        m_cCuDecoder.create ( g_uiMaxCUDepth, g_uiMaxCUWidth, g_uiMaxCUHeight );
671        m_cCuDecoder.init   ( &m_cEntropyDecoder, &m_cTrQuant, &m_cPrediction );
672        m_cTrQuant.init     ( g_uiMaxCUWidth, g_uiMaxCUHeight, m_apcSlicePilot->getSPS()->getMaxTrSize());
673
674        m_cSliceDecoder.create( m_apcSlicePilot, m_apcSlicePilot->getSPS()->getWidth(), m_apcSlicePilot->getSPS()->getHeight(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth );
675
676#if DEPTH_MAP_GENERATION
677        UInt uiPdm = ( m_cSPS.getViewId() ? m_cSPS.getPredDepthMapGeneration() : getDecTop()->getSPSAccess()->getPdm() );
678        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) );
679        TComDepthMapGenerator* pcDMG0 = getDecTop()->getDecTop0()->getDepthMapGenerator();
680        if( m_cSPS.getViewId() == 1 && ( pcDMG0->getSubSampExpX() != PDM_SUB_SAMP_EXP_X(uiPdm) || pcDMG0->getSubSampExpY() != PDM_SUB_SAMP_EXP_Y(uiPdm) ) )
681        {
682          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) );
683        }
684#endif
685#if HHI_INTER_VIEW_RESIDUAL_PRED
686        m_cResidualGenerator.create( true, m_apcSlicePilot->getSPS()->getWidth(), m_apcSlicePilot->getSPS()->getHeight(), g_uiMaxCUDepth, g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiBitDepth + g_uiBitIncrement );
687#endif
688      }
689
690      //  Set picture slice pointer
691      TComSlice*  pcSlice = m_apcSlicePilot;
692      Bool bNextSlice     = pcSlice->isNextSlice();
693      if (m_bFirstSliceInPicture)
694      {
695        if(pcPic->getNumAllocatedSlice() != 1)
696        {
697          pcPic->clearSliceBuffer();
698        }
699      }
700      else
701      {
702        pcPic->allocateNewSlice();
703      }
704      assert(pcPic->getNumAllocatedSlice() == (m_uiSliceIdx + 1));
705      m_apcSlicePilot = pcPic->getPicSym()->getSlice(m_uiSliceIdx);
706      pcPic->getPicSym()->setSlice(pcSlice, m_uiSliceIdx);
707
708      if (bNextSlice)
709      {
710#if DCM_DECODING_REFRESH
711        // Do decoding refresh marking if any
712        pcSlice->decodingRefreshMarking(m_uiPOCCDR, m_bRefreshPending, m_cListPic);
713#endif
714
715        // Set reference list
716        std::vector<TComPic*> apcSpatRefPics = getDecTop()->getSpatialRefPics( pcPic->getViewIdx(), pcSlice->getPOC(), m_cSPS.isDepth() );
717        TComPic * const pcTexturePic = m_cSPS.isDepth() ? getDecTop()->getPicFromView( pcPic->getViewIdx(), pcSlice->getPOC(), false ) : NULL;
718
719#if FLEX_CODING_ORDER
720        if (pcTexturePic != NULL)
721        {
722          assert( ! m_cSPS.isDepth() || pcTexturePic != NULL );
723          pcSlice->setTexturePic( pcTexturePic );
724        }
725#else
726        assert( ! m_cSPS.isDepth() || pcTexturePic != NULL );
727        pcSlice->setTexturePic( pcTexturePic );
728        pcSlice->setViewIdx( pcPic->getViewIdx() );
729#endif
730#if SONY_COLPIC_AVAILABILITY
731        pcSlice->setViewOrderIdx( pcPic->getViewOrderIdx() );
732#endif
733        pcSlice->setRefPicListExplicitlyDecoderSided(m_cListPic, apcSpatRefPics) ;// temporary solution
734
735#if DCM_COMB_LIST
736        if(!pcSlice->getRefPicListModificationFlagLC())
737        {
738          pcSlice->generateCombinedList();
739        }
740#endif
741
742        pcSlice->setNoBackPredFlag( false );
743#if DCM_COMB_LIST
744        if ( pcSlice->getSliceType() == B_SLICE && !pcSlice->getRefPicListCombinationFlag())
745#else
746          if ( pcSlice->getSliceType() == B_SLICE )
747#endif
748          {
749            if ( pcSlice->getNumRefIdx(RefPicList( 0 ) ) == pcSlice->getNumRefIdx(RefPicList( 1 ) ) )
750            {
751              pcSlice->setNoBackPredFlag( true );
752              int i;
753              for ( i=0; i < pcSlice->getNumRefIdx(RefPicList( 1 ) ); i++ )
754              {
755                if ( pcSlice->getRefPOC(RefPicList(1), i) != pcSlice->getRefPOC(RefPicList(0), i) )
756                {
757                  pcSlice->setNoBackPredFlag( false );
758                  break;
759                }
760              }
761            }
762          }
763      }
764
765      pcPic->setCurrSliceIdx(m_uiSliceIdx);
766
767#if HHI_DMM_WEDGE_INTRA || HHI_DMM_PRED_TEX
768    if ( m_cSPS.getUseDMM() && g_aacWedgeLists.empty() && m_bIsDepth )
769      {
770        initWedgeLists();
771      }
772#endif
773
774      //  Decode a picture
775      m_cGopDecoder.decompressGop ( bEos, pcBitstream, pcPic, false );
776
777      if( m_pcCamParsCollector )
778      {
779        m_pcCamParsCollector->setSlice( pcSlice );
780      }
781
782      m_bFirstSliceInPicture = false;
783      m_uiSliceIdx++;
784    }
785      break;
786    default:
787      assert (1);
788  }
789
790  return false;
791}
792
793#if DCM_SKIP_DECODING_FRAMES
794/** Function for checking if picture should be skipped because of random access
795 * \param iSkipFrame skip frame counter
796 * \param iPOCLastDisplay POC of last picture displayed
797 * \returns true if the picture shold be skipped in the random access.
798 * This function checks the skipping of pictures in the case of -s option random access.
799 * All pictures prior to the random access point indicated by the counter iSkipFrame are skipped.
800 * It also checks the type of Nal unit type at the random access point.
801 * If the random access point is CDR, pictures with POC equal to or greater than the CDR POC are decoded.
802 * If the random access point is IDR all pictures after the random access point are decoded.
803 * If the random access point is not IDR or CDR, a warning is issues, and decoding of pictures with POC
804 * equal to or greater than the random access point POC is attempted. For non IDR/CDR random
805 * access point there is no guarantee that the decoder will not crash.
806 */
807Bool TDecTop::isRandomAccessSkipPicture(Int& iSkipFrame,  Int& iPOCLastDisplay)
808{
809  if (iSkipFrame)
810  {
811    iSkipFrame--;   // decrement the counter
812    return true;
813  }
814  else if (m_uiPOCRA == MAX_UINT) // start of random access point, m_uiPOCRA has not been set yet.
815  {
816    if (m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_CDR)
817    {
818      m_uiPOCRA = m_apcSlicePilot->getPOC(); // set the POC random access since we need to skip the reordered pictures in CDR.
819    }
820    else if (m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR)
821    {
822      m_uiPOCRA = 0; // no need to skip the reordered pictures in IDR, they are decodable.
823    }
824    else
825    {
826      printf("\nUnsafe random access point. Decoder may crash.");
827      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.
828      //m_uiPOCRA = 0;
829    }
830  }
831  else if (m_apcSlicePilot->getPOC() < m_uiPOCRA)  // skip the reordered pictures if necessary
832  {
833    iPOCLastDisplay++;
834    return true;
835  }
836  // if we reach here, then the picture is not skipped.
837  return false;
838}
839#endif
840
Note: See TracBrowser for help on using the repository browser.