source: 3DVCSoftware/branches/HTM-10.0rc1-dev0/source/App/TAppDecoder/TAppDecTop.cpp @ 840

Last change on this file since 840 was 840, checked in by tech, 10 years ago

Further fixes.

  • Property svn:eol-style set to native
File size: 28.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-2014, ITU/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 ITU/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     TAppDecTop.cpp
35    \brief    Decoder application class
36*/
37
38#include <list>
39#include <vector>
40#include <stdio.h>
41#include <fcntl.h>
42#include <assert.h>
43
44#include "TAppDecTop.h"
45#include "TLibDecoder/AnnexBread.h"
46#include "TLibDecoder/NALread.h"
47
48//! \ingroup TAppDecoder
49//! \{
50
51// ====================================================================================================================
52// Constructor / destructor / initialization / destroy
53// ====================================================================================================================
54
55TAppDecTop::TAppDecTop()
56#if !H_MV
57: m_iPOCLastDisplay(-MAX_INT)
58#else
59: m_numDecoders( 0 )
60#endif
61{
62#if H_MV
63  for (Int i = 0; i < MAX_NUM_LAYER_IDS; i++) 
64  {
65    m_layerIdToDecIdx[i] = -1; 
66    m_layerInitilizedFlags[i] = false; 
67  }
68#endif
69#if H_3D
70    m_pScaleOffsetFile  = 0;
71#endif
72}
73
74Void TAppDecTop::create()
75{
76}
77
78Void TAppDecTop::destroy()
79{
80  if (m_pchBitstreamFile)
81  {
82    free (m_pchBitstreamFile);
83    m_pchBitstreamFile = NULL;
84  }
85#if H_MV
86  for (Int decIdx = 0; decIdx < m_numDecoders; decIdx++)
87  {
88    if (m_pchReconFiles[decIdx])
89    {
90      free (m_pchReconFiles[decIdx]);
91      m_pchReconFiles[decIdx] = NULL;
92    }
93  }
94#endif
95  if (m_pchReconFile)
96  {
97    free (m_pchReconFile);
98    m_pchReconFile = NULL;
99  }
100#if H_3D
101  if (m_pchScaleOffsetFile)
102  {
103    free (m_pchScaleOffsetFile);
104    m_pchScaleOffsetFile = NULL; 
105  }
106#endif
107}
108
109// ====================================================================================================================
110// Public member functions
111// ====================================================================================================================
112
113/**
114 - create internal class
115 - initialize internal class
116 - until the end of the bitstream, call decoding function in TDecTop class
117 - delete allocated buffers
118 - destroy internal class
119 .
120 */
121Void TAppDecTop::decode()
122{
123  Int                 poc;
124#if H_MV
125  poc = -1; 
126#endif
127  TComList<TComPic*>* pcListPic = NULL;
128
129  ifstream bitstreamFile(m_pchBitstreamFile, ifstream::in | ifstream::binary);
130  if (!bitstreamFile)
131  {
132    fprintf(stderr, "\nfailed to open bitstream file `%s' for reading\n", m_pchBitstreamFile);
133    exit(EXIT_FAILURE);
134  }
135
136#if H_3D
137  if( m_pchScaleOffsetFile ) 
138  { 
139    m_pScaleOffsetFile = ::fopen( m_pchScaleOffsetFile, "wt" ); 
140    AOF( m_pScaleOffsetFile ); 
141  }
142  m_cCamParsCollector.init( m_pScaleOffsetFile );
143#endif
144  InputByteStream bytestream(bitstreamFile);
145
146  // create & initialize internal classes
147  xCreateDecLib();
148  xInitDecLib  ();
149#if !H_MV
150  m_iPOCLastDisplay += m_iSkipFrame;      // set the last displayed POC correctly for skip forward.
151
152  // main decoder loop
153  Bool openedReconFile = false; // reconstruction file not yet opened. (must be performed after SPS is seen)
154#else
155#if H_3D
156  Int  pocCurrPic        = -MAX_INT;     
157  Int  pocLastPic        = -MAX_INT;   
158#endif
159
160  Int  layerIdCurrPic    = 0; 
161
162  Int  decIdxLastPic     = 0; 
163  Int  decIdxCurrPic     = 0; 
164
165  Bool firstSlice        = true; 
166#endif
167  Bool loopFiltered = false;
168
169  while (!!bitstreamFile)
170  {
171    /* location serves to work around a design fault in the decoder, whereby
172     * the process of reading a new slice that is the first slice of a new frame
173     * requires the TDecTop::decode() method to be called again with the same
174     * nal unit. */
175    streampos location = bitstreamFile.tellg();
176#if H_MV
177#if ENC_DEC_TRACE
178    Int64 symCount = g_nSymbolCounter;
179#endif
180#endif
181    AnnexBStats stats = AnnexBStats();
182    vector<uint8_t> nalUnit;
183    InputNALUnit nalu;
184    byteStreamNALUnit(bytestream, nalUnit, stats);
185
186    // call actual decoding function
187    Bool bNewPicture = false;
188#if H_MV
189    Bool newSliceDiffPoc   = false;
190    Bool newSliceDiffLayer = false;
191    Bool sliceSkippedFlag = false; 
192#if H_3D
193    Bool allLayersDecoded  = false;     
194#endif
195#endif
196    if (nalUnit.empty())
197    {
198      /* this can happen if the following occur:
199       *  - empty input file
200       *  - two back-to-back start_code_prefixes
201       *  - start_code_prefix immediately followed by EOF
202       */
203      fprintf(stderr, "Warning: Attempt to decode an empty NAL unit\n");
204    }
205    else
206    {
207      read(nalu, nalUnit);
208#if H_MV     
209      if( (m_iMaxTemporalLayer >= 0 && nalu.m_temporalId > m_iMaxTemporalLayer) || !isNaluWithinTargetDecLayerIdSet(&nalu) || nalu.m_layerId > MAX_NUM_LAYER_IDS-1 ) 
210      {
211        bNewPicture = false;
212        if ( !bitstreamFile )
213        {
214          decIdxLastPic     = decIdxCurrPic; 
215        }
216      }
217      else
218      { 
219        Int decIdx     = xGetDecoderIdx( nalu.m_layerId , true );     
220        newSliceDiffLayer = nalu.isSlice() && ( nalu.m_layerId != layerIdCurrPic ) && !firstSlice;
221        newSliceDiffPoc   = m_tDecTop[decIdx]->decode(nalu, m_iSkipFrame, m_pocLastDisplay[decIdx], newSliceDiffLayer, sliceSkippedFlag );
222        // decode function only returns true when all of the following conditions are true
223        // - poc in particular layer changes
224        // - nalu does not belong to first slice in layer
225        // - nalu.isSlice() == true     
226
227        // Update TargetDecLayerIdList only when not specified by layer id file, specification by file might actually out of conformance.
228        if (nalu.m_nalUnitType == NAL_UNIT_VPS && m_targetDecLayerIdSetFileEmpty )
229        {
230          TComVPS* vps = m_tDecTop[decIdx]->getPrefetchedVPS(); 
231          if ( m_targetOptLayerSetIdx == -1 )
232          {
233            // Not normative! Corresponds to specification by "External Means". (Should be set equal to 0, when no external means available. )
234            m_targetOptLayerSetIdx = vps->getVpsNumLayerSetsMinus1(); 
235          }
236
237          m_targetDecLayerIdSet = vps->getTargetDecLayerIdList( m_targetOptLayerSetIdx ); 
238        }
239        bNewPicture       = ( newSliceDiffLayer || newSliceDiffPoc ) && !sliceSkippedFlag; 
240        if ( nalu.isSlice() && firstSlice && !sliceSkippedFlag )       
241        {
242          layerIdCurrPic = nalu.m_layerId; 
243#if H_3D
244          pocCurrPic     = m_tDecTop[decIdx]->getCurrPoc(); 
245#endif
246          decIdxCurrPic  = decIdx; 
247          firstSlice     = false; 
248        }
249
250        if ( bNewPicture || !bitstreamFile )
251        { 
252          layerIdCurrPic    = nalu.m_layerId; 
253#if H_3D         
254          pocLastPic        = pocCurrPic; 
255          pocCurrPic        = m_tDecTop[decIdx]->getCurrPoc(); 
256#endif         
257          decIdxLastPic     = decIdxCurrPic; 
258          decIdxCurrPic     = decIdx; 
259#if H_3D
260          allLayersDecoded = ( pocCurrPic != pocLastPic );
261#endif
262        }
263#else
264      if( (m_iMaxTemporalLayer >= 0 && nalu.m_temporalId > m_iMaxTemporalLayer) || !isNaluWithinTargetDecLayerIdSet(&nalu)  )
265      {
266        bNewPicture = false;
267      }
268      else
269      {
270        bNewPicture = m_cTDecTop.decode(nalu, m_iSkipFrame, m_iPOCLastDisplay);
271#endif
272        if (bNewPicture)
273        {
274          bitstreamFile.clear();
275          /* location points to the current nalunit payload[1] due to the
276           * need for the annexB parser to read three extra bytes.
277           * [1] except for the first NAL unit in the file
278           *     (but bNewPicture doesn't happen then) */
279          bitstreamFile.seekg(location-streamoff(3));
280          bytestream.reset();
281#if H_MV_ENC_DEC_TRAC
282#if ENC_DEC_TRACE
283          const Bool resetCounter = false; 
284          if ( resetCounter )
285          {
286            g_nSymbolCounter  = symCount; // Only reset counter SH becomes traced twice
287          }
288          else
289          {
290            g_disableHLSTrace = true;     // Trancing of second parsing of SH is not carried out
291          }     
292#endif
293#endif
294        }
295      }
296    }
297    if (bNewPicture || !bitstreamFile || nalu.m_nalUnitType == NAL_UNIT_EOS )
298    {
299#if H_MV
300      assert( decIdxLastPic != -1 ); 
301      // TODO add loop filtered variable here
302      m_tDecTop[decIdxLastPic]->endPicDecoding(poc, pcListPic, m_targetDecLayerIdSet );
303#else
304      if (!loopFiltered || bitstreamFile)
305      {
306        m_cTDecTop.executeLoopFilters(poc, pcListPic);
307      }
308      loopFiltered = (nalu.m_nalUnitType == NAL_UNIT_EOS);
309#endif
310    }
311#if H_3D
312    if ( allLayersDecoded || !bitstreamFile )
313    {
314      for( Int dI = 0; dI < m_numDecoders; dI++ )
315      {
316        TComPic* picLastCoded = m_ivPicLists.getPic( m_tDecTop[dI]->getLayerId(), pocLastPic );
317        assert( picLastCoded != NULL );       
318        picLastCoded->compressMotion(1);
319      }
320    }
321#endif
322
323    if( pcListPic )
324    {
325#if H_MV
326      if ( m_pchReconFiles[decIdxLastPic] && !m_reconOpen[decIdxLastPic] )
327#else
328      if ( m_pchReconFile && !openedReconFile  )
329#endif
330      {
331        if (!m_outputBitDepthY) { m_outputBitDepthY = g_bitDepthY; }
332        if (!m_outputBitDepthC) { m_outputBitDepthC = g_bitDepthC; }
333
334#if H_MV
335        m_tVideoIOYuvReconFile[decIdxLastPic]->open( m_pchReconFiles[decIdxLastPic], true, m_outputBitDepthY, m_outputBitDepthC, g_bitDepthY, g_bitDepthC ); // write mode
336        m_reconOpen[decIdxLastPic] = true;
337      }
338      if ( bNewPicture && newSliceDiffPoc && 
339#else
340        m_cTVideoIOYuvReconFile.open( m_pchReconFile, true, m_outputBitDepthY, m_outputBitDepthC, g_bitDepthY, g_bitDepthC ); // write mode
341        openedReconFile  = true;
342      }
343      if ( bNewPicture && 
344#endif
345           (   nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_IDR_W_RADL
346            || nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_IDR_N_LP
347            || nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_BLA_N_LP
348            || nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_BLA_W_RADL
349            || nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_BLA_W_LP ) )
350      {
351#if H_MV
352        xFlushOutput( pcListPic, decIdxLastPic );
353#else
354        xFlushOutput( pcListPic );
355#endif
356      }
357      if (nalu.m_nalUnitType == NAL_UNIT_EOS)
358      {
359#if H_MV
360        xFlushOutput( pcListPic, decIdxLastPic );
361#else
362        xFlushOutput( pcListPic );
363#endif
364      }
365      // write reconstruction to file
366      if(bNewPicture)
367      {
368#if H_MV
369        xWriteOutput( pcListPic, decIdxLastPic, nalu.m_temporalId );
370      }
371    }
372  }
373
374#if H_3D
375  if( m_cCamParsCollector.isInitialized() )
376  {
377    m_cCamParsCollector.setSlice( 0 );
378  }
379#endif
380  for(UInt decIdx = 0; decIdx < m_numDecoders; decIdx++)
381  {
382    xFlushOutput( m_tDecTop[decIdx]->getListPic(), decIdx );
383  }
384#else
385        xWriteOutput( pcListPic, nalu.m_temporalId );
386      }
387    }
388  }
389 
390  xFlushOutput( pcListPic );
391  // delete buffers
392  m_cTDecTop.deletePicBuffer();
393#endif
394     
395  // destroy internal classes
396  xDestroyDecLib();
397}
398
399// ====================================================================================================================
400// Protected member functions
401// ====================================================================================================================
402
403Void TAppDecTop::xCreateDecLib()
404{
405#if H_MV
406  // initialize global variables
407  initROM(); 
408#if H_3D_DIM_DMM
409  initWedgeLists();
410#endif
411#else
412  // create decoder class
413  m_cTDecTop.create();
414#endif
415}
416
417Void TAppDecTop::xDestroyDecLib()
418{
419#if H_MV
420  // destroy ROM
421  destroyROM();
422
423  for(Int decIdx = 0; decIdx < m_numDecoders ; decIdx++)
424  {
425    if( m_tVideoIOYuvReconFile[decIdx] )
426    {
427      m_tVideoIOYuvReconFile[decIdx]->close();
428      delete m_tVideoIOYuvReconFile[decIdx]; 
429      m_tVideoIOYuvReconFile[decIdx] = NULL ;
430    }
431
432    if( m_tDecTop[decIdx] )
433    {
434      m_tDecTop[decIdx]->deletePicBuffer();
435      m_tDecTop[decIdx]->destroy() ;
436    }
437    delete m_tDecTop[decIdx] ; 
438    m_tDecTop[decIdx] = NULL ;
439  }
440#else
441  if ( m_pchReconFile )
442  {
443    m_cTVideoIOYuvReconFile. close();
444  }
445 
446  // destroy decoder class
447  m_cTDecTop.destroy();
448#endif
449#if H_3D
450  m_cCamParsCollector.uninit();
451  if( m_pScaleOffsetFile ) 
452  { 
453    ::fclose( m_pScaleOffsetFile ); 
454  }
455#endif
456}
457
458Void TAppDecTop::xInitDecLib()
459{
460#if !H_MV
461  // initialize decoder class
462  m_cTDecTop.init();
463  m_cTDecTop.setDecodedPictureHashSEIEnabled(m_decodedPictureHashSEIEnabled);
464#endif
465}
466
467/** \param pcListPic list of pictures to be written to file
468    \todo            DYN_REF_FREE should be revised
469 */
470#if H_MV
471Void TAppDecTop::xWriteOutput( TComList<TComPic*>* pcListPic, Int decIdx, Int tId )
472#else
473Void TAppDecTop::xWriteOutput( TComList<TComPic*>* pcListPic, UInt tId )
474#endif
475{
476
477  if (pcListPic->empty())
478  {
479    return;
480  }
481
482  TComList<TComPic*>::iterator iterPic   = pcListPic->begin();
483  Int numPicsNotYetDisplayed = 0;
484 
485  while (iterPic != pcListPic->end())
486  {
487    TComPic* pcPic = *(iterPic);
488#if H_MV
489    if(pcPic->getOutputMark() && pcPic->getPOC() > m_pocLastDisplay[decIdx])
490#else
491    if(pcPic->getOutputMark() && pcPic->getPOC() > m_iPOCLastDisplay)
492#endif
493    {
494      numPicsNotYetDisplayed++;
495    }
496    iterPic++;
497  }
498  iterPic   = pcListPic->begin();
499  if (numPicsNotYetDisplayed>2)
500  {
501    iterPic++;
502  }
503 
504  TComPic* pcPic = *(iterPic);
505  if (numPicsNotYetDisplayed>2 && pcPic->isField()) //Field Decoding
506  {
507    TComList<TComPic*>::iterator endPic   = pcListPic->end();
508    endPic--;
509    iterPic   = pcListPic->begin();
510    while (iterPic != endPic)
511    {
512      TComPic* pcPicTop = *(iterPic);
513      iterPic++;
514      TComPic* pcPicBottom = *(iterPic);
515     
516#if H_MV
517      if ( pcPicTop->getOutputMark() && (numPicsNotYetDisplayed >  pcPicTop->getNumReorderPics(tId) && !(pcPicTop->getPOC()%2) && pcPicBottom->getPOC() == pcPicTop->getPOC()+1)
518          && pcPicBottom->getOutputMark() && (numPicsNotYetDisplayed >  pcPicBottom->getNumReorderPics(tId) && (pcPicTop->getPOC() == m_pocLastDisplay[decIdx]+1 || m_pocLastDisplay[decIdx]<0)))
519#else
520      if ( pcPicTop->getOutputMark() && (numPicsNotYetDisplayed >  pcPicTop->getNumReorderPics(tId) && !(pcPicTop->getPOC()%2) && pcPicBottom->getPOC() == pcPicTop->getPOC()+1)
521          && pcPicBottom->getOutputMark() && (numPicsNotYetDisplayed >  pcPicBottom->getNumReorderPics(tId) && (pcPicTop->getPOC() == m_iPOCLastDisplay+1 || m_iPOCLastDisplay<0)))
522#endif
523      {
524        // write to file
525        numPicsNotYetDisplayed = numPicsNotYetDisplayed-2;
526#if H_MV
527      if ( m_pchReconFiles[decIdx] )
528#else
529        if ( m_pchReconFile )
530#endif
531        {
532          const Window &conf = pcPicTop->getConformanceWindow();
533          const Window &defDisp = m_respectDefDispWindow ? pcPicTop->getDefDisplayWindow() : Window();
534
535          const Bool isTff = pcPicTop->isTopField();
536#if H_MV
537        assert( conf   .getScaledFlag() );
538        assert( defDisp.getScaledFlag() );
539        m_tVideoIOYuvReconFile[decIdx]->write( pcPicTop->getPicYuvRec(), pcPicBottom->getPicYuvRec(),
540#else
541          m_cTVideoIOYuvReconFile.write( pcPicTop->getPicYuvRec(), pcPicBottom->getPicYuvRec(),
542#endif
543                                        conf.getWindowLeftOffset() + defDisp.getWindowLeftOffset(),
544                                        conf.getWindowRightOffset() + defDisp.getWindowRightOffset(),
545                                        conf.getWindowTopOffset() + defDisp.getWindowTopOffset(),
546                                        conf.getWindowBottomOffset() + defDisp.getWindowBottomOffset(), isTff );
547        }
548       
549        // update POC of display order
550#if H_MV
551        m_pocLastDisplay[decIdx] = pcPic->getPOC();
552#else
553        m_iPOCLastDisplay = pcPicBottom->getPOC();
554#endif
555       
556        // erase non-referenced picture in the reference picture list after display
557        if ( !pcPicTop->getSlice(0)->isReferenced() && pcPicTop->getReconMark() == true )
558        {
559#if !DYN_REF_FREE
560          pcPicTop->setReconMark(false);
561         
562          // mark it should be extended later
563          pcPicTop->getPicYuvRec()->setBorderExtension( false );
564         
565#else
566          pcPicTop->destroy();
567          pcListPic->erase( iterPic );
568          iterPic = pcListPic->begin(); // to the beginning, non-efficient way, have to be revised!
569          continue;
570#endif
571        }
572        if ( !pcPicBottom->getSlice(0)->isReferenced() && pcPicBottom->getReconMark() == true )
573        {
574#if !DYN_REF_FREE
575          pcPicBottom->setReconMark(false);
576         
577          // mark it should be extended later
578          pcPicBottom->getPicYuvRec()->setBorderExtension( false );
579         
580#else
581          pcPicBottom->destroy();
582          pcListPic->erase( iterPic );
583          iterPic = pcListPic->begin(); // to the beginning, non-efficient way, have to be revised!
584          continue;
585#endif
586        }
587        pcPicTop->setOutputMark(false);
588        pcPicBottom->setOutputMark(false);
589      }
590    }
591  }
592  else if (!pcPic->isField()) //Frame Decoding
593  {
594    iterPic = pcListPic->begin();
595    while (iterPic != pcListPic->end())
596    {
597      pcPic = *(iterPic);
598
599#if H_MV
600      if ( pcPic->getOutputMark() && (numPicsNotYetDisplayed >  pcPic->getNumReorderPics(tId) && pcPic->getPOC() > m_pocLastDisplay[decIdx]))
601#else     
602      if ( pcPic->getOutputMark() && (numPicsNotYetDisplayed >  pcPic->getNumReorderPics(tId) && pcPic->getPOC() > m_iPOCLastDisplay))
603#endif
604      {
605        // write to file
606        numPicsNotYetDisplayed--;
607#if H_MV
608      if ( m_pchReconFiles[decIdx] )
609#else
610        if ( m_pchReconFile )
611#endif
612        {
613          const Window &conf = pcPic->getConformanceWindow();
614          const Window &defDisp = m_respectDefDispWindow ? pcPic->getDefDisplayWindow() : Window();
615#if H_MV
616        assert( conf   .getScaledFlag() );
617        assert( defDisp.getScaledFlag() );
618        m_tVideoIOYuvReconFile[decIdx]->write( pcPic->getPicYuvRec(),
619#else
620          m_cTVideoIOYuvReconFile.write( pcPic->getPicYuvRec(),
621#endif
622                                        conf.getWindowLeftOffset() + defDisp.getWindowLeftOffset(),
623                                        conf.getWindowRightOffset() + defDisp.getWindowRightOffset(),
624                                        conf.getWindowTopOffset() + defDisp.getWindowTopOffset(),
625                                        conf.getWindowBottomOffset() + defDisp.getWindowBottomOffset() );
626        }
627       
628        // update POC of display order
629#if H_MV
630        m_pocLastDisplay[decIdx] = pcPic->getPOC();
631#else
632        m_iPOCLastDisplay = pcPic->getPOC();
633#endif
634       
635        // erase non-referenced picture in the reference picture list after display
636        if ( !pcPic->getSlice(0)->isReferenced() && pcPic->getReconMark() == true )
637        {
638#if !DYN_REF_FREE
639          pcPic->setReconMark(false);
640         
641          // mark it should be extended later
642          pcPic->getPicYuvRec()->setBorderExtension( false );
643         
644#else
645          pcPic->destroy();
646          pcListPic->erase( iterPic );
647          iterPic = pcListPic->begin(); // to the beginning, non-efficient way, have to be revised!
648          continue;
649#endif
650        }
651        pcPic->setOutputMark(false);
652      }
653     
654      iterPic++;
655    }
656  }
657}
658/** \param pcListPic list of pictures to be written to file
659    \todo            DYN_REF_FREE should be revised
660 */
661#if H_MV
662Void TAppDecTop::xFlushOutput( TComList<TComPic*>* pcListPic, Int decIdx )
663#else
664Void TAppDecTop::xFlushOutput( TComList<TComPic*>* pcListPic )
665#endif
666{
667  if(!pcListPic || pcListPic->empty())
668  {
669    return;
670  }
671  TComList<TComPic*>::iterator iterPic   = pcListPic->begin();
672 
673  iterPic   = pcListPic->begin();
674  TComPic* pcPic = *(iterPic);
675 
676  if (pcPic->isField()) //Field Decoding
677  {
678    TComList<TComPic*>::iterator endPic   = pcListPic->end();
679    endPic--;
680    TComPic *pcPicTop, *pcPicBottom = NULL;
681    while (iterPic != endPic)
682    {
683      pcPicTop = *(iterPic);
684      iterPic++;
685      pcPicBottom = *(iterPic);
686     
687      if ( pcPicTop->getOutputMark() && pcPicBottom->getOutputMark() && !(pcPicTop->getPOC()%2) && (pcPicBottom->getPOC() == pcPicTop->getPOC()+1) )
688      {
689        // write to file
690#if H_MV
691      if ( m_pchReconFiles[decIdx] )
692#else
693        if ( m_pchReconFile )
694#endif
695        {
696          const Window &conf = pcPicTop->getConformanceWindow();
697          const Window &defDisp = m_respectDefDispWindow ? pcPicTop->getDefDisplayWindow() : Window();
698          const Bool isTff = pcPicTop->isTopField();
699#if H_MV
700        assert( conf   .getScaledFlag() );
701        assert( defDisp.getScaledFlag() );
702        m_tVideoIOYuvReconFile[decIdx]->write( pcPicTop->getPicYuvRec(), pcPicBottom->getPicYuvRec(),
703#else
704          m_cTVideoIOYuvReconFile.write( pcPicTop->getPicYuvRec(), pcPicBottom->getPicYuvRec(),
705#endif
706                                        conf.getWindowLeftOffset() + defDisp.getWindowLeftOffset(),
707                                        conf.getWindowRightOffset() + defDisp.getWindowRightOffset(),
708                                        conf.getWindowTopOffset() + defDisp.getWindowTopOffset(),
709                                        conf.getWindowBottomOffset() + defDisp.getWindowBottomOffset(), isTff );
710        }
711       
712        // update POC of display order
713#if H_MV
714      m_pocLastDisplay[decIdx] = pcPic->getPOC();
715#else
716      m_iPOCLastDisplay = pcPicBottom->getPOC();
717#endif       
718        // erase non-referenced picture in the reference picture list after display
719        if ( !pcPicTop->getSlice(0)->isReferenced() && pcPicTop->getReconMark() == true )
720        {
721#if !DYN_REF_FREE
722          pcPicTop->setReconMark(false);
723         
724          // mark it should be extended later
725          pcPicTop->getPicYuvRec()->setBorderExtension( false );
726         
727#else
728          pcPicTop->destroy();
729          pcListPic->erase( iterPic );
730          iterPic = pcListPic->begin(); // to the beginning, non-efficient way, have to be revised!
731          continue;
732#endif
733        }
734        if ( !pcPicBottom->getSlice(0)->isReferenced() && pcPicBottom->getReconMark() == true )
735        {
736#if !DYN_REF_FREE
737          pcPicBottom->setReconMark(false);
738         
739          // mark it should be extended later
740          pcPicBottom->getPicYuvRec()->setBorderExtension( false );
741         
742#else
743          pcPicBottom->destroy();
744          pcListPic->erase( iterPic );
745          iterPic = pcListPic->begin(); // to the beginning, non-efficient way, have to be revised!
746          continue;
747#endif
748        }
749        pcPicTop->setOutputMark(false);
750        pcPicBottom->setOutputMark(false);
751       
752#if !DYN_REF_FREE
753        if(pcPicTop)
754        {
755          pcPicTop->destroy();
756          delete pcPicTop;
757          pcPicTop = NULL;
758        }
759#endif
760      }
761    }
762    if(pcPicBottom)
763    {
764      pcPicBottom->destroy();
765      delete pcPicBottom;
766      pcPicBottom = NULL;
767    }
768  }
769  else //Frame decoding
770  {
771    while (iterPic != pcListPic->end())
772    {
773      pcPic = *(iterPic);
774     
775      if ( pcPic->getOutputMark() )
776      {
777        // write to file
778#if H_MV
779      if ( m_pchReconFiles[decIdx] )
780#else
781        if ( m_pchReconFile )
782#endif
783        {
784          const Window &conf = pcPic->getConformanceWindow();
785          const Window &defDisp = m_respectDefDispWindow ? pcPic->getDefDisplayWindow() : Window();
786#if H_MV
787        assert( conf   .getScaledFlag() );
788        assert( defDisp.getScaledFlag() );
789        m_tVideoIOYuvReconFile[decIdx]->write( pcPic->getPicYuvRec(),
790#else
791          m_cTVideoIOYuvReconFile.write( pcPic->getPicYuvRec(),
792#endif
793                                        conf.getWindowLeftOffset() + defDisp.getWindowLeftOffset(),
794                                        conf.getWindowRightOffset() + defDisp.getWindowRightOffset(),
795                                        conf.getWindowTopOffset() + defDisp.getWindowTopOffset(),
796                                        conf.getWindowBottomOffset() + defDisp.getWindowBottomOffset() );
797        }
798       
799        // update POC of display order
800#if H_MV
801      m_pocLastDisplay[decIdx] = pcPic->getPOC();
802#else
803        m_iPOCLastDisplay = pcPic->getPOC();
804#endif
805       
806        // erase non-referenced picture in the reference picture list after display
807        if ( !pcPic->getSlice(0)->isReferenced() && pcPic->getReconMark() == true )
808        {
809#if !DYN_REF_FREE
810          pcPic->setReconMark(false);
811         
812          // mark it should be extended later
813          pcPic->getPicYuvRec()->setBorderExtension( false );
814         
815#else
816          pcPic->destroy();
817          pcListPic->erase( iterPic );
818          iterPic = pcListPic->begin(); // to the beginning, non-efficient way, have to be revised!
819          continue;
820#endif
821        }
822        pcPic->setOutputMark(false);
823      }
824#if !H_MV
825#if !DYN_REF_FREE
826      if(pcPic)
827      {
828        pcPic->destroy();
829        delete pcPic;
830        pcPic = NULL;
831      }
832#endif   
833#endif
834      iterPic++;
835    }
836  }
837#if H_MV
838  m_pocLastDisplay[decIdx] = -MAX_INT;
839#else
840  pcListPic->clear();
841  m_iPOCLastDisplay = -MAX_INT;
842#endif
843}
844
845/** \param nalu Input nalu to check whether its LayerId is within targetDecLayerIdSet
846 */
847Bool TAppDecTop::isNaluWithinTargetDecLayerIdSet( InputNALUnit* nalu )
848{
849  if ( m_targetDecLayerIdSet.size() == 0 ) // By default, the set is empty, meaning all LayerIds are allowed
850  {
851    return true;
852  }
853  for (std::vector<Int>::iterator it = m_targetDecLayerIdSet.begin(); it != m_targetDecLayerIdSet.end(); it++)
854  {
855#if H_MV
856    if ( nalu->m_layerId == (*it) )
857#else
858    if ( nalu->m_reservedZero6Bits == (*it) )
859#endif
860    {
861      return true;
862    }
863  }
864  return false;
865}
866
867#if H_MV
868Int TAppDecTop::xGetDecoderIdx( Int layerId, Bool createFlag /*= false */ )
869{
870  Int decIdx = -1; 
871
872  if ( layerId > MAX_NUM_LAYER_IDS-1 ) 
873  {
874    return decIdx; 
875  }
876
877  if ( m_layerIdToDecIdx[ layerId ] != -1 ) 
878  {     
879    decIdx = m_layerIdToDecIdx[ layerId ]; 
880  }
881  else
882  {     
883    assert ( createFlag ); 
884    assert( m_numDecoders < MAX_NUM_LAYERS ); 
885
886    decIdx = m_numDecoders; 
887
888    // Init decoder
889    m_tDecTop[ decIdx ] =  new TDecTop;
890    m_tDecTop[ decIdx ]->create();
891    m_tDecTop[ decIdx ]->init( );
892    m_tDecTop[ decIdx ]->setLayerId( layerId );
893    m_tDecTop[ decIdx ]->setDecodedPictureHashSEIEnabled(m_decodedPictureHashSEIEnabled);
894    m_tDecTop[ decIdx ]->setIvPicLists( &m_ivPicLists ); 
895    m_tDecTop[ decIdx ]->setLayerInitilizedFlags( m_layerInitilizedFlags );
896
897#if H_3D
898   m_tDecTop[ decIdx ]->setCamParsCollector( &m_cCamParsCollector );
899#endif
900
901    // append pic list of new decoder to PicLists
902    assert( m_ivPicLists.size() == m_numDecoders );
903    m_ivPicLists.push_back( m_tDecTop[ decIdx ]->getListPic() );
904
905    // create recon file related stuff     
906    Char* pchTempFilename = NULL;
907    if ( m_pchReconFile )
908    {     
909      Char buffer[4];     
910      sprintf(buffer,"_%i", layerId );
911      assert ( m_pchReconFile ); 
912      xAppendToFileNameEnd( m_pchReconFile , buffer, pchTempFilename );
913      assert( m_pchReconFiles.size() == m_numDecoders );
914    }
915
916    m_pchReconFiles.push_back( pchTempFilename );   
917
918    m_tVideoIOYuvReconFile[ decIdx ] = new TVideoIOYuv;
919    m_reconOpen           [ decIdx ] = false;
920
921    // set others
922    m_pocLastDisplay      [ decIdx ] = -MAX_INT;
923    m_layerIdToDecIdx     [ layerId ] = decIdx; 
924
925    m_numDecoders++; 
926  };
927  return decIdx;
928}
929#endif
930//! \}
Note: See TracBrowser for help on using the repository browser.