source: 3DVCSoftware/branches/0.2-poznan-univ/source/Lib/TLibDecoder/TDecTop.cpp @ 11

Last change on this file since 11 was 11, checked in by poznan-univ, 13 years ago

Poznan disocclusion coding - CU Skip

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