source: 3DVCSoftware/branches/0.3-nokia/source/App/TAppDecoder/TAppDecTop.cpp @ 1417

Last change on this file since 1417 was 50, checked in by nokia, 13 years ago

FCO bug-fix to 3DV-HTM version 0.4: decoder crushed with texture-only coding.

  • Property svn:eol-style set to native
File size: 23.7 KB
RevLine 
[5]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 */
[2]33
34
[5]35
[2]36/** \file     TAppDecTop.cpp
37    \brief    Decoder application class
38*/
39
40#include <list>
41#include <stdio.h>
42#include <fcntl.h>
43#include <assert.h>
44
45#include "TAppDecTop.h"
46
47// ====================================================================================================================
48// Local constants
49// ====================================================================================================================
50
51/// initial bitstream buffer size
52/// should be large enough for parsing SPS
53/// resized as a function of picture size after parsing SPS
54#define BITS_BUF_SIZE 65536
55
56// ====================================================================================================================
57// Constructor / destructor / initialization / destroy
58// ====================================================================================================================
59
60TAppDecTop::TAppDecTop()
61{
62  ::memset (m_abDecFlag, 0, sizeof (m_abDecFlag));
63  m_bUsingDepth = false;
64//  m_iPOCLastDisplay  = -1;
65  m_pScaleOffsetFile  = 0;
66}
67
68Void TAppDecTop::create()
69{
70  m_apcBitstream  = new TComBitstream;
71 
72  m_apcBitstream->create( BITS_BUF_SIZE );
73}
74
75Void TAppDecTop::destroy()
76{
77  if ( m_apcBitstream )
78  {
79    m_apcBitstream->destroy();
80    delete m_apcBitstream;
81    m_apcBitstream = NULL;
82  }
83  if( m_pchBitstreamFile )
84  {
85    free(m_pchBitstreamFile);
86  }
87  if( m_pchReconFile )
88  {
89    free(m_pchReconFile);
90  }
91}
92
93// ====================================================================================================================
94// Public member functions
95// ====================================================================================================================
96
97/**
98 - create internal class
99 - initialize internal class
100 - until the end of the bitstream, call decoding function in TDecTop class
101 - delete allocated buffers
102 - destroy internal class
103 .
104 */
105Void TAppDecTop::decode()
106{
107  TComBitstream*      pcBitstream = m_apcBitstream;
108  UInt                uiPOC;
109  TComList<TComPic*>* pcListPic;
110  Bool bFirstSliceDecoded = true;
111
112  // create & initialize internal classes
113  xCreateDecLib();
114  xInitDecLib  ();
115#if DCM_SKIP_DECODING_FRAMES
116//  m_iPOCLastDisplay += m_iSkipFrame;      // set the last displayed POC correctly for skip forward.
117#endif
118
119  // main decoder loop
120  Bool  bEos        = false;
121  Bool resizedBitstreamBuffer = false;
122 
123  Bool bIsDepth = false;
124  Int iViewIdx = 0;
125  TComSPS cComSPS ;
126  NalUnitType eNalUnitType;
127
[34]128#if FLEX_CODING_ORDER
129  Int iDepthViewIdx = 0;
130  Bool bCountDepthViewIdx = false;              // a flag which avoid repeating assign a value to iDepthViewIdx   
131  Bool bNewPictureType =true;
132  Bool bFirstDepth = false;
133#endif
[2]134 
135  while ( !bEos )
136  {
137    streampos  lLocation = m_cTVideoIOBitstreamFile.getFileLocation();
138    bEos                 = m_cTVideoIOBitstreamFile.readBits( pcBitstream );
139    if (bEos)
140    {
141      //if (!bFirstSliceDecoded) m_cTDecTop.decode( bEos, pcBitstream, uiPOC, pcListPic, eNalUnitType, cComSPS, m_iSkipFrame, m_iPOCLastDisplay);
142      if( bIsDepth )
143      {
[34]144#if FLEX_CODING_ORDER
145                  if (!bFirstSliceDecoded) m_acTDecDepthTopList[iDepthViewIdx]->decode( bEos, pcBitstream, uiPOC, pcListPic, eNalUnitType, cComSPS, m_iSkipFrame, m_aiDepthPOCLastDisplayList[iDepthViewIdx] ,bNewPictureType);
146                  m_acTDecDepthTopList[iDepthViewIdx]->executeDeblockAndAlf( bEos, pcBitstream, uiPOC, pcListPic, m_iSkipFrame, m_aiDepthPOCLastDisplayList[iDepthViewIdx]);
147
148#else
[2]149        if (!bFirstSliceDecoded) m_acTDecDepthTopList[iViewIdx]->decode( bEos, pcBitstream, uiPOC, pcListPic, eNalUnitType, cComSPS, m_iSkipFrame, m_aiDepthPOCLastDisplayList[iViewIdx] );
150        m_acTDecDepthTopList[iViewIdx]->executeDeblockAndAlf( bEos, pcBitstream, uiPOC, pcListPic, m_iSkipFrame, m_aiDepthPOCLastDisplayList[iViewIdx]);
[34]151#endif
[2]152      }
153      else
154      {
[34]155#if FLEX_CODING_ORDER
156                  if (!bFirstSliceDecoded) m_acTDecTopList[iViewIdx]->decode( bEos, pcBitstream, uiPOC, pcListPic, eNalUnitType, cComSPS, m_iSkipFrame, m_aiPOCLastDisplayList[iViewIdx], bNewPictureType);
157#else
[2]158        if (!bFirstSliceDecoded) m_acTDecTopList[iViewIdx]->decode( bEos, pcBitstream, uiPOC, pcListPic, eNalUnitType, cComSPS, m_iSkipFrame, m_aiPOCLastDisplayList[iViewIdx] );
[34]159#endif
160                m_acTDecTopList[iViewIdx]->executeDeblockAndAlf( bEos, pcBitstream, uiPOC, pcListPic, m_iSkipFrame, m_aiPOCLastDisplayList[iViewIdx]);
[2]161      }
162      if( pcListPic )
163      {
164        // write reconstuction to file
165        xWriteOutput( pcListPic );
166      }
167      break;
168    }
169   
170    // call actual decoding function
171#if DCM_SKIP_DECODING_FRAMES
172    Bool bNewPicture;
173    if( bIsDepth )
[34]174#if FLEX_CODING_ORDER
175                  bNewPicture = m_acTDecDepthTopList[iDepthViewIdx]->decode( bEos, pcBitstream, uiPOC, pcListPic, eNalUnitType, cComSPS, m_iSkipFrame, m_aiDepthPOCLastDisplayList[iDepthViewIdx], bNewPictureType);
176#else
[2]177      bNewPicture = m_acTDecDepthTopList[iViewIdx]->decode( bEos, pcBitstream, uiPOC, pcListPic, eNalUnitType, cComSPS, m_iSkipFrame, m_aiDepthPOCLastDisplayList[iViewIdx] );
[34]178#endif
[2]179    else
[34]180#if FLEX_CODING_ORDER
181                bNewPicture = m_acTDecTopList[iViewIdx]->decode( bEos, pcBitstream, uiPOC, pcListPic, eNalUnitType, cComSPS, m_iSkipFrame, m_aiPOCLastDisplayList[iViewIdx], bNewPictureType );
182#else
[2]183      bNewPicture = m_acTDecTopList[iViewIdx]->decode( bEos, pcBitstream, uiPOC, pcListPic, eNalUnitType, cComSPS, m_iSkipFrame, m_aiPOCLastDisplayList[iViewIdx] );
[34]184#endif
[2]185    bFirstSliceDecoded   = true;
186
[34]187#if FLEX_CODING_ORDER
188          if (eNalUnitType == NAL_UNIT_SPS)
189          {
190                  if( cComSPS.isDepth() && (m_bUsingDepth==false) )  // expected not using depth, but bitstream are using depth
191                  {                                                     // know from sps
192                          assert( cComSPS.getViewId() == 0 && iDepthViewIdx == 0 && !bIsDepth );
193                          startUsingDepth() ;
194                  }
195                  if (cComSPS.isDepth())
196                  {
197                          if (cComSPS.getViewId() >= m_acTVideoIOYuvDepthReconFileList.size())
198                          {
199                                  assert( cComSPS.getViewId() == m_acTVideoIOYuvReconFileList.size() );
200                                  increaseNumberOfViews(cComSPS.getViewId()+1);
201                          }
202                       
203                          m_acTDecDepthTopList[cComSPS.getViewId()]->setSPS(cComSPS);
204                  }
205                  else 
206                  {
207                          if (cComSPS.getViewId() >= m_acTVideoIOYuvReconFileList.size())
208                          {
209                                  assert( cComSPS.getViewId() == m_acTVideoIOYuvReconFileList.size() );
210                                  increaseNumberOfViews(cComSPS.getViewId()+1);
211                          }
212                          m_acTDecTopList[cComSPS.getViewId()]->setSPS(cComSPS);
213                  }
214                  bEos = m_cTVideoIOBitstreamFile.readBits( pcBitstream );
215                  assert( !bEos);
216                  if( cComSPS.isDepth() )
217                          m_acTDecDepthTopList[cComSPS.getViewId()]->decode( bEos, pcBitstream, uiPOC, pcListPic, eNalUnitType, cComSPS, m_iSkipFrame, m_aiDepthPOCLastDisplayList[cComSPS.getViewId()], bNewPictureType); // decode PPS
218                  else
219                          m_acTDecTopList[cComSPS.getViewId()]->decode( bEos, pcBitstream, uiPOC, pcListPic, eNalUnitType, cComSPS, m_iSkipFrame, m_aiPOCLastDisplayList[cComSPS.getViewId()], bNewPictureType); // decode PPS
220                  assert( eNalUnitType == NAL_UNIT_PPS );
221          }
222#else
223
[2]224    if( eNalUnitType == NAL_UNIT_SPS )
225    {
226      if( cComSPS.isDepth() && (m_bUsingDepth==false) )  // expected not using depth, but bitstream are using depth
227      {                                                     // know from sps
228        assert( cComSPS.getViewId() == 0 && iViewIdx == 0 && !bIsDepth );
229        startUsingDepth() ;
230      }
231      if( cComSPS.isDepth() && !bIsDepth )
232      {
233        assert( cComSPS.getViewId() == iViewIdx );
234        m_acTDecDepthTopList[iViewIdx]->setSPS(cComSPS);
235      }
236      else if( cComSPS.getViewId() >= m_acTVideoIOYuvReconFileList.size() ) // expecting iViewIdx, but got cComSPS.getViewIdx()
237      {
238        assert( cComSPS.getViewId() == m_acTVideoIOYuvReconFileList.size() );
239        assert( !cComSPS.isDepth() );
240        increaseNumberOfViews(cComSPS.getViewId()+1);
241        m_acTDecTopList[cComSPS.getViewId()]->setSPS(cComSPS);
242      }
243      bEos = m_cTVideoIOBitstreamFile.readBits( pcBitstream );
244      assert( !bEos);
245      if( cComSPS.isDepth() )
246        m_acTDecDepthTopList[cComSPS.getViewId()]->decode( bEos, pcBitstream, uiPOC, pcListPic, eNalUnitType, cComSPS, m_iSkipFrame, m_aiDepthPOCLastDisplayList[cComSPS.getViewId()]); // decode PPS
247      else
248        m_acTDecTopList[cComSPS.getViewId()]->decode( bEos, pcBitstream, uiPOC, pcListPic, eNalUnitType, cComSPS, m_iSkipFrame, m_aiPOCLastDisplayList[cComSPS.getViewId()]); // decode PPS
249      assert( eNalUnitType == NAL_UNIT_PPS );
250    }
[34]251
252#endif
[2]253    assert( eNalUnitType != NAL_UNIT_SEI ); // not yet supported for MVC
254    if (bNewPicture)
255    {
256      if( bIsDepth )
[34]257#if FLEX_CODING_ORDER
258        m_acTDecDepthTopList[iDepthViewIdx]->executeDeblockAndAlf( bEos, pcBitstream, uiPOC, pcListPic, m_iSkipFrame, m_aiDepthPOCLastDisplayList[iDepthViewIdx]);
259#else
[2]260        m_acTDecDepthTopList[iViewIdx]->executeDeblockAndAlf( bEos, pcBitstream, uiPOC, pcListPic, m_iSkipFrame, m_aiDepthPOCLastDisplayList[iViewIdx]);
[34]261#endif
[2]262      else
263        m_acTDecTopList[iViewIdx]->executeDeblockAndAlf( bEos, pcBitstream, uiPOC, pcListPic, m_iSkipFrame, m_aiPOCLastDisplayList[iViewIdx]);
264      if (!m_cTVideoIOBitstreamFile.good()) m_cTVideoIOBitstreamFile.clear();
265      m_cTVideoIOBitstreamFile.setFileLocation( lLocation );
266      bFirstSliceDecoded = false;
267
[34]268#if FLEX_CODING_ORDER
269      if (m_bUsingDepth)
270      {
271        bIsDepth = bNewPictureType;       
272
273      }
[50]274      if (m_bUsingDepth && bCountDepthViewIdx == false )
[34]275      {
276        bCountDepthViewIdx = true;
277        if (bIsDepth == true)
278        {
279          bFirstDepth = true;
280          bCountDepthViewIdx = true;
281        }
282        if (!bFirstDepth && !bIsDepth)
283        {
284          iViewIdx++;
285          bCountDepthViewIdx = false;
286        }
287
288      }
289      else
290      {
291        if (bIsDepth)
292        {
293          iDepthViewIdx++;
294        }
295        else
296        {
297          iViewIdx ++;
298        }
299
[50]300        if (iViewIdx >= m_acTDecTopList.size() || (m_bUsingDepth && iDepthViewIdx >= m_acTDecDepthTopList.size()))
[34]301        {
302          bFirstDepth = false;
303          iViewIdx = 0;
304          iDepthViewIdx = 0;
305          bCountDepthViewIdx = false;
306          // end of access unit: delete extra pic buffers
307          Int iNumViews = (Int)m_acTVideoIOYuvReconFileList.size();
308          for( Int iVId = 0; iVId < iNumViews; iVId++ )
309          {
310            if( iVId < (Int)m_acTDecTopList.size() &&  m_acTDecTopList[iVId] )
311            {
312              m_acTDecTopList[iVId]->deleteExtraPicBuffers( (Int)uiPOC );
313            }
314            if( iVId < (Int)m_acTDecDepthTopList.size() && m_acTDecDepthTopList[iVId] )
315            {
316              m_acTDecDepthTopList[iVId]->deleteExtraPicBuffers( (Int)uiPOC );
317            }
318          }
319
320#if AMVP_BUFFERCOMPRESS
321          // compress motion for entire access unit
322          for( Int iVId = 0; iVId < iNumViews; iVId++ )
323          {
324            if( iVId < (Int)m_acTDecTopList.size() &&  m_acTDecTopList[iVId] )
325            {
326              m_acTDecTopList[iVId]->compressMotion( (Int)uiPOC );
327            }
328            if( iVId < (Int)m_acTDecDepthTopList.size() && m_acTDecDepthTopList[iVId] )
329            {
330              m_acTDecDepthTopList[iVId]->compressMotion( (Int)uiPOC );
331            }
332          }
333#endif
334        }
335      }
336         
337#else
338
[2]339      if( m_bUsingDepth && !bIsDepth )
340      {
341        bIsDepth = true;
342      }
343      else
344      {
345        bIsDepth = false;
346        if( iViewIdx<m_acTDecTopList.size()-1)
347        {
348          iViewIdx++ ;
349        }
350        else
351        {
352          iViewIdx = 0;
353
354          // end of access unit: delete extra pic buffers
355          Int iNumViews = (Int)m_acTVideoIOYuvReconFileList.size();
356          for( Int iVId = 0; iVId < iNumViews; iVId++ )
357          {
358            if( iVId < (Int)m_acTDecTopList.size() &&  m_acTDecTopList[iVId] )
359            {
360              m_acTDecTopList[iVId]->deleteExtraPicBuffers( (Int)uiPOC );
361            }
362            if( iVId < (Int)m_acTDecDepthTopList.size() && m_acTDecDepthTopList[iVId] )
363            {
364              m_acTDecDepthTopList[iVId]->deleteExtraPicBuffers( (Int)uiPOC );
365            }
366          }
367
368#if AMVP_BUFFERCOMPRESS
369          // compress motion for entire access unit
370          for( Int iVId = 0; iVId < iNumViews; iVId++ )
371          {
372            if( iVId < (Int)m_acTDecTopList.size() &&  m_acTDecTopList[iVId] )
373            {
374              m_acTDecTopList[iVId]->compressMotion( (Int)uiPOC );
375            }
376            if( iVId < (Int)m_acTDecDepthTopList.size() && m_acTDecDepthTopList[iVId] )
377            {
378              m_acTDecDepthTopList[iVId]->compressMotion( (Int)uiPOC );
379            }
380          }
381#endif
382        }
[34]383          }
384#endif
[2]385    }
386#else
387#error
388    m_cTDecTop.decode( bEos, pcBitstream, uiPOC, pcListPic );
389#endif
390
391   
392    if (!resizedBitstreamBuffer)
393    {
394      TComSPS *sps = m_acTDecTopList[0]->getSPS();
395      if (sps)
396      {
397        pcBitstream->destroy();
398        pcBitstream->create(sps->getWidth() * sps->getHeight() * 2);
399        resizedBitstreamBuffer = true;
400      }
401    }
402   
403    if( pcListPic )
404    {
405      // write reconstuction to file
406      xWriteOutput( pcListPic );
407    }
408  }
409 
410  // delete buffers
411  for(Int i=0; i<m_acTDecTopList.size(); i++)
412    m_acTDecTopList[i]->deletePicBuffer();
413
414  if (m_bUsingDepth)
415  {
416    for(Int i=0; i<m_acTDecDepthTopList.size(); i++)
417      m_acTDecDepthTopList[i]->deletePicBuffer();
418  }
419 
420  // destroy internal classes
421  xDestroyDecLib();
422}
423
424// ====================================================================================================================
425// Protected member functions
426// ====================================================================================================================
427
428Void TAppDecTop::xCreateDecLib()
429{
430  // open bitstream file
431  m_cTVideoIOBitstreamFile.openBits( m_pchBitstreamFile, false);  // read mode
432
433  // create decoder class
434//  m_cTDecTop.create();
435  m_acTDecTopList.push_back(new TDecTop) ;// at least one decoder
436  m_acTDecTopList[0]->create() ;
437
438  m_aiPOCLastDisplayList.push_back(-1+m_iSkipFrame) ;
439
440  if( m_pchScaleOffsetFile ) 
441  { 
442    m_pScaleOffsetFile = ::fopen( m_pchScaleOffsetFile, "wt" ); 
443    AOF( m_pScaleOffsetFile ); 
444  }
445  m_cCamParsCollector.init( m_pScaleOffsetFile );
446}
447
448Void TAppDecTop::xDestroyDecLib()
449{
450  // close bitstream file
451  m_cTVideoIOBitstreamFile.closeBits();
452
453  for(Int iViewIdx=0; iViewIdx<m_acTVideoIOYuvReconFileList.size() ; iViewIdx++)
454  {
455    m_acTVideoIOYuvReconFileList[iViewIdx]->close();
456    delete m_acTVideoIOYuvReconFileList[iViewIdx]; m_acTVideoIOYuvReconFileList[iViewIdx] = NULL ;
457  }
458
459  // destroy decoder class
460//  m_cTDecTop.destroy();
461  for(Int iViewIdx=0; iViewIdx<m_acTDecTopList.size() ; iViewIdx++)
462  {
463    m_acTDecTopList[iViewIdx]->destroy() ;
464    delete m_acTDecTopList[iViewIdx] ; m_acTDecTopList[iViewIdx] = NULL ;
465  }
466
467  for(Int iViewIdx=0; iViewIdx<m_acTVideoIOYuvDepthReconFileList.size() ; iViewIdx++)
468  {
469    m_acTVideoIOYuvDepthReconFileList[iViewIdx]->close();
470    delete m_acTVideoIOYuvDepthReconFileList[iViewIdx]; m_acTVideoIOYuvDepthReconFileList[iViewIdx] = NULL ;
471  }
472
473  for(Int iViewIdx=0; iViewIdx<m_acTDecDepthTopList.size() ; iViewIdx++)
474  {
475    m_acTDecDepthTopList[iViewIdx]->destroy() ;
476    delete m_acTDecDepthTopList[iViewIdx] ; m_acTDecDepthTopList[iViewIdx] = NULL ;
477  }
478
479  m_cCamParsCollector.uninit();
480  if( m_pScaleOffsetFile ) 
481  { 
482    ::fclose( m_pScaleOffsetFile ); 
483  }
484}
485
486Void TAppDecTop::xInitDecLib()
487{
488  // initialize decoder class
489  m_acTDecTopList[0]->init( this );
490  m_acTDecTopList[0]->setViewIdx(0);
491  m_acTDecTopList[0]->setPictureDigestEnabled(m_pictureDigestEnabled);
492  m_acTDecTopList[0]->setCamParsCollector( &m_cCamParsCollector );
[21]493#if SONY_COLPIC_AVAILABILITY
494  m_acTDecTopList[0]->setViewOrderIdx(0);
495#endif
[2]496}
497
498/** \param pcListPic list of pictures to be written to file
499    \param bFirst    first picture?
500    \todo            DYN_REF_FREE should be revised
501 */
502Void TAppDecTop::xWriteOutput( TComList<TComPic*>* pcListPic )
503{
504  TComList<TComPic*>::iterator iterPic   = pcListPic->begin();
505
506  while (iterPic != pcListPic->end())
507  {
508    TComPic* pcPic = *(iterPic);
509    Int iViewIdx = pcPic->getViewIdx();
510    Int bIsDepth = pcPic->getSlice(0)->getSPS()->isDepth() ;
511
512    if (!bIsDepth)
513    {
514      if( m_acTVideoIOYuvReconFileList.size() < iViewIdx+1 )
515            increaseNumberOfViews( iViewIdx+1 ) ;
516
517      if ( pcPic->getReconMark() && pcPic->getPOC() == (m_aiPOCLastDisplayList[iViewIdx] + 1) )
518      {
519        // write to file
520        if ( m_pchReconFile )
521        {
522          m_acTVideoIOYuvReconFileList[iViewIdx]->write( pcPic->getPicYuvRec(), pcPic->getSlice(0)->getSPS()->getPad() );
523        }
524
525        // update POC of display order
526        m_aiPOCLastDisplayList[iViewIdx] = pcPic->getPOC();
527
528        // erase non-referenced picture in the reference picture list after display
529        if ( !pcPic->getSlice(0)->isReferenced() && pcPic->getReconMark() == true )
530        {
531  #if !DYN_REF_FREE
532          pcPic->setReconMark(false);
533
534          // mark it should be extended later
535          pcPic->getPicYuvRec()->setBorderExtension( false );
536
537  #else
538          pcPic->destroy();
539          pcListPic->erase( iterPic );
540          iterPic = pcListPic->begin(); // to the beginning, non-efficient way, have to be revised!
541          continue;
542  #endif
543        }
544      }
545    } /// end !bIsDepth
546    else
547    {
548      if( m_acTVideoIOYuvDepthReconFileList.size() < iViewIdx+1 )
549             increaseNumberOfViews( iViewIdx+1 ) ;
550
551      if ( pcPic->getReconMark() && pcPic->getPOC() == (m_aiDepthPOCLastDisplayList[iViewIdx] + 1) )
552      {
553        // write to file
554        if ( m_pchReconFile )
555        {
556          m_acTVideoIOYuvDepthReconFileList[iViewIdx]->write( pcPic->getPicYuvRec(), pcPic->getSlice(0)->getSPS()->getPad() );
557        }
558
559        // update POC of display order
560        m_aiDepthPOCLastDisplayList[iViewIdx] = pcPic->getPOC();
561
562        // erase non-referenced picture in the reference picture list after display
563        if ( !pcPic->getSlice(0)->isReferenced() && pcPic->getReconMark() == true )
564        {
565  #if !DYN_REF_FREE
566          pcPic->setReconMark(false);
567
568          // mark it should be extended later
569          pcPic->getPicYuvRec()->setBorderExtension( false );
570
571  #else
572          pcPic->destroy();
573          pcListPic->erase( iterPic );
574          iterPic = pcListPic->begin(); // to the beginning, non-efficient way, have to be revised!
575          continue;
576  #endif
577        }
578      }
579    } // end bIsDepth
580
581    iterPic++;
582  }
583}
584
585Void TAppDecTop::startUsingDepth()
586{
587  m_bUsingDepth = true ;
588  increaseNumberOfViews( (Int)m_acTVideoIOYuvReconFileList.size() );
589}
590
591Void  TAppDecTop::increaseNumberOfViews  (Int iNewNumberOfViews)
592{
593  while( m_acTVideoIOYuvReconFileList.size() < iNewNumberOfViews)
594  {
595    m_acTVideoIOYuvReconFileList.push_back(new TVideoIOYuv);
596
597// GT FIX
598    Char cBuffer[4]  ;
599    sprintf(cBuffer,"_%i",(Int)m_acTVideoIOYuvReconFileList.size()-1 );
600    Char* pchNextFilename;
601    xAppendToFileNameEnd( m_pchReconFile, cBuffer, pchNextFilename);
602// GT FIX END
603    if ( m_outputBitDepth == 0 )
604      m_outputBitDepth = g_uiBitDepth + g_uiBitIncrement;
605    m_acTVideoIOYuvReconFileList.back()->open( pchNextFilename, true, m_outputBitDepth, g_uiBitDepth + g_uiBitIncrement );
606    free (pchNextFilename);
607  }
608
609  while( m_aiPOCLastDisplayList.size() < iNewNumberOfViews )
610    m_aiPOCLastDisplayList.push_back(-1+m_iSkipFrame) ;
611
612  while( m_acTDecTopList.size() < iNewNumberOfViews)
613  {
614    m_acTDecTopList.push_back(new TDecTop) ;// at least one decoder
615    m_acTDecTopList.back()->create() ;
616    m_acTDecTopList.back()->init( this, false );
617    m_acTDecTopList.back()->setViewIdx((Int)m_acTDecTopList.size()-1);
618    m_acTDecTopList.back()->setPictureDigestEnabled(m_pictureDigestEnabled);
619    m_acTDecTopList.back()->setCamParsCollector( &m_cCamParsCollector );
620  }
621  if( m_bUsingDepth )
622  {
623    while( m_acTVideoIOYuvDepthReconFileList.size() < iNewNumberOfViews  )
624    {
625      m_acTVideoIOYuvDepthReconFileList.push_back(new TVideoIOYuv);
626// GT FIX
627      Char* pchTempFilename = NULL;
628      xAppendToFileNameEnd( m_pchReconFile, "_depth", pchTempFilename);
629      Char cBuffer[4]  ;
630      sprintf(cBuffer,"_%i",(Int)m_acTVideoIOYuvDepthReconFileList.size()-1 );
631      Char* pchDepthFilename = NULL;
632      xAppendToFileNameEnd( pchTempFilename, cBuffer, pchDepthFilename);
633// GT FIX END
634      if ( m_outputBitDepth == 0 )
635        m_outputBitDepth = g_uiBitDepth + g_uiBitIncrement;
636      m_acTVideoIOYuvDepthReconFileList.back()->open( pchDepthFilename, true, m_outputBitDepth, g_uiBitDepth + g_uiBitIncrement );
637      free (pchTempFilename);
638      free( pchDepthFilename );
639    }
640    while( m_aiDepthPOCLastDisplayList.size() < iNewNumberOfViews )
641      m_aiDepthPOCLastDisplayList.push_back(-1+m_iSkipFrame) ;
642    while( m_acTDecDepthTopList.size() < iNewNumberOfViews)
643    {
644      m_acTDecDepthTopList.push_back(new TDecTop) ;// at least one decoder
645      m_acTDecDepthTopList.back()->create() ;
646      m_acTDecDepthTopList.back()->init( this, false );
[34]647#if FLEX_CODING_ORDER
648      Int iNumofgen = (Int)m_acTDecDepthTopList.size();
649      m_acTDecDepthTopList.back()->setViewIdx(iNumofgen-1);
650#else
651          m_acTDecDepthTopList.back()->setViewIdx((Int)m_acTDecTopList.size()-1);
652#endif
653
[2]654      m_acTDecDepthTopList.back()->setPictureDigestEnabled(m_pictureDigestEnabled);
655      m_acTDecDepthTopList.back()->setToDepth( true );
656      m_acTDecDepthTopList.back()->setCamParsCollector( &m_cCamParsCollector );
657    }
658  }
659}
660
661
662// GT FIX
663std::vector<TComPic*> TAppDecTop::getSpatialRefPics( Int iViewIdx, Int iPoc, Bool bIsDepth ) // only for mvc functionality yet
664{
665  std::vector<TComPic*> apcRefPics( iViewIdx, (TComPic*)NULL );
666  for( int iRefViewIdx = 0; iRefViewIdx < iViewIdx; iRefViewIdx++ )
667  {
668    TComPic* pcRefPic = getPicFromView( iRefViewIdx, iPoc, bIsDepth );
669    assert( pcRefPic != NULL );
670    apcRefPics[iRefViewIdx] = pcRefPic;
671  }
672  return apcRefPics;
673}
674
675TComPic* TAppDecTop::getPicFromView( Int iViewIdx, Int iPoc, bool bIsDepth )
676{
677  TComList<TComPic*>* apcListPic = (bIsDepth ? m_acTDecDepthTopList[iViewIdx] : m_acTDecTopList[iViewIdx])->getListPic();
678  TComPic* pcRefPic = NULL;
679  for( TComList<TComPic*>::iterator it=apcListPic->begin(); it!=apcListPic->end(); it++ )
680  {
681    if( (*it)->getPOC() == iPoc )
682    {
683      pcRefPic = *it;
684      break;
685    }
686  }
687  return pcRefPic;
688}
Note: See TracBrowser for help on using the repository browser.