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

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

Update HM-12.0 -> HM-13.0.

  • 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;     // Tracing 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 (!loopFiltered || bitstreamFile)
300      {
301#if H_MV
302        assert( decIdxLastPic != -1 ); 
303        m_tDecTop[decIdxLastPic]->endPicDecoding(poc, pcListPic, m_targetDecLayerIdSet );
304#else
305        m_cTDecTop.executeLoopFilters(poc, pcListPic);
306#endif
307      }
308      loopFiltered = (nalu.m_nalUnitType == NAL_UNIT_EOS);
309    }
310#if H_3D
311    if ( allLayersDecoded || !bitstreamFile )
312    {
313      for( Int dI = 0; dI < m_numDecoders; dI++ )
314      {
315        TComPic* picLastCoded = m_ivPicLists.getPic( m_tDecTop[dI]->getLayerId(), pocLastPic );
316        assert( picLastCoded != NULL );       
317        picLastCoded->compressMotion(1);
318      }
319    }
320#endif
321
322    if( pcListPic )
323    {
324#if H_MV
325      if ( m_pchReconFiles[decIdxLastPic] && !m_reconOpen[decIdxLastPic] )
326#else
327      if ( m_pchReconFile && !openedReconFile  )
328#endif
329      {
330        if (!m_outputBitDepthY) { m_outputBitDepthY = g_bitDepthY; }
331        if (!m_outputBitDepthC) { m_outputBitDepthC = g_bitDepthC; }
332
333#if H_MV
334        m_tVideoIOYuvReconFile[decIdxLastPic]->open( m_pchReconFiles[decIdxLastPic], true, m_outputBitDepthY, m_outputBitDepthC, g_bitDepthY, g_bitDepthC ); // write mode
335        m_reconOpen[decIdxLastPic] = true;
336      }
337      if ( bNewPicture && newSliceDiffPoc && 
338#else
339        m_cTVideoIOYuvReconFile.open( m_pchReconFile, true, m_outputBitDepthY, m_outputBitDepthC, g_bitDepthY, g_bitDepthC ); // write mode
340        openedReconFile  = true;
341      }
342      if ( bNewPicture && 
343#endif
344           (   nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_IDR_W_RADL
345            || nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_IDR_N_LP
346            || nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_BLA_N_LP
347            || nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_BLA_W_RADL
348            || nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_BLA_W_LP ) )
349      {
350#if H_MV
351        xFlushOutput( pcListPic, decIdxLastPic );
352#else
353        xFlushOutput( pcListPic );
354#endif
355      }
356      if (nalu.m_nalUnitType == NAL_UNIT_EOS)
357      {
358#if H_MV
359        xFlushOutput( pcListPic, decIdxLastPic );
360#else
361        xFlushOutput( pcListPic );
362#endif
363      }
364      // write reconstruction to file
365      if(bNewPicture)
366      {
367#if H_MV
368        xWriteOutput( pcListPic, decIdxLastPic, nalu.m_temporalId );
369      }
370    }
371  }
372
373#if H_3D
374  if( m_cCamParsCollector.isInitialized() )
375  {
376    m_cCamParsCollector.setSlice( 0 );
377  }
378#endif
379  for(UInt decIdx = 0; decIdx < m_numDecoders; decIdx++)
380  {
381    xFlushOutput( m_tDecTop[decIdx]->getListPic(), decIdx );
382  }
383#else
384        xWriteOutput( pcListPic, nalu.m_temporalId );
385      }
386    }
387  }
388 
389  xFlushOutput( pcListPic );
390  // delete buffers
391  m_cTDecTop.deletePicBuffer();
392#endif
393     
394  // destroy internal classes
395  xDestroyDecLib();
396}
397
398// ====================================================================================================================
399// Protected member functions
400// ====================================================================================================================
401
402Void TAppDecTop::xCreateDecLib()
403{
404#if H_MV
405  // initialize global variables
406  initROM(); 
407#if H_3D_DIM_DMM
408  initWedgeLists();
409#endif
410#else
411  // create decoder class
412  m_cTDecTop.create();
413#endif
414}
415
416Void TAppDecTop::xDestroyDecLib()
417{
418#if H_MV
419  // destroy ROM
420  destroyROM();
421
422  for(Int decIdx = 0; decIdx < m_numDecoders ; decIdx++)
423  {
424    if( m_tVideoIOYuvReconFile[decIdx] )
425    {
426      m_tVideoIOYuvReconFile[decIdx]->close();
427      delete m_tVideoIOYuvReconFile[decIdx]; 
428      m_tVideoIOYuvReconFile[decIdx] = NULL ;
429    }
430
431    if( m_tDecTop[decIdx] )
432    {
433      m_tDecTop[decIdx]->deletePicBuffer();
434      m_tDecTop[decIdx]->destroy() ;
435    }
436    delete m_tDecTop[decIdx] ; 
437    m_tDecTop[decIdx] = NULL ;
438  }
439#else
440  if ( m_pchReconFile )
441  {
442    m_cTVideoIOYuvReconFile. close();
443  }
444 
445  // destroy decoder class
446  m_cTDecTop.destroy();
447#endif
448#if H_3D
449  m_cCamParsCollector.uninit();
450  if( m_pScaleOffsetFile ) 
451  { 
452    ::fclose( m_pScaleOffsetFile ); 
453  }
454#endif
455}
456
457Void TAppDecTop::xInitDecLib()
458{
459#if !H_MV
460  // initialize decoder class
461  m_cTDecTop.init();
462  m_cTDecTop.setDecodedPictureHashSEIEnabled(m_decodedPictureHashSEIEnabled);
463#endif
464}
465
466/** \param pcListPic list of pictures to be written to file
467    \todo            DYN_REF_FREE should be revised
468 */
469#if H_MV
470Void TAppDecTop::xWriteOutput( TComList<TComPic*>* pcListPic, Int decIdx, Int tId )
471#else
472Void TAppDecTop::xWriteOutput( TComList<TComPic*>* pcListPic, UInt tId )
473#endif
474{
475
476  if (pcListPic->empty())
477  {
478    return;
479  }
480
481  TComList<TComPic*>::iterator iterPic   = pcListPic->begin();
482  Int numPicsNotYetDisplayed = 0;
483 
484  while (iterPic != pcListPic->end())
485  {
486    TComPic* pcPic = *(iterPic);
487#if H_MV
488    if(pcPic->getOutputMark() && pcPic->getPOC() > m_pocLastDisplay[decIdx])
489#else
490    if(pcPic->getOutputMark() && pcPic->getPOC() > m_iPOCLastDisplay)
491#endif
492    {
493      numPicsNotYetDisplayed++;
494    }
495    iterPic++;
496  }
497  iterPic   = pcListPic->begin();
498  if (numPicsNotYetDisplayed>2)
499  {
500    iterPic++;
501  }
502 
503  TComPic* pcPic = *(iterPic);
504  if (numPicsNotYetDisplayed>2 && pcPic->isField()) //Field Decoding
505  {
506    TComList<TComPic*>::iterator endPic   = pcListPic->end();
507    endPic--;
508    iterPic   = pcListPic->begin();
509    while (iterPic != endPic)
510    {
511      TComPic* pcPicTop = *(iterPic);
512      iterPic++;
513      TComPic* pcPicBottom = *(iterPic);
514     
515#if H_MV
516      if ( pcPicTop->getOutputMark() && (numPicsNotYetDisplayed >  pcPicTop->getNumReorderPics(tId) && !(pcPicTop->getPOC()%2) && pcPicBottom->getPOC() == pcPicTop->getPOC()+1)
517          && pcPicBottom->getOutputMark() && (numPicsNotYetDisplayed >  pcPicBottom->getNumReorderPics(tId) && (pcPicTop->getPOC() == m_pocLastDisplay[decIdx]+1 || m_pocLastDisplay[decIdx]<0)))
518#else
519      if ( pcPicTop->getOutputMark() && (numPicsNotYetDisplayed >  pcPicTop->getNumReorderPics(tId) && !(pcPicTop->getPOC()%2) && pcPicBottom->getPOC() == pcPicTop->getPOC()+1)
520          && pcPicBottom->getOutputMark() && (numPicsNotYetDisplayed >  pcPicBottom->getNumReorderPics(tId) && (pcPicTop->getPOC() == m_iPOCLastDisplay+1 || m_iPOCLastDisplay<0)))
521#endif
522      {
523        // write to file
524        numPicsNotYetDisplayed = numPicsNotYetDisplayed-2;
525#if H_MV
526      if ( m_pchReconFiles[decIdx] )
527#else
528        if ( m_pchReconFile )
529#endif
530        {
531          const Window &conf = pcPicTop->getConformanceWindow();
532          const Window &defDisp = m_respectDefDispWindow ? pcPicTop->getDefDisplayWindow() : Window();
533
534          const Bool isTff = pcPicTop->isTopField();
535#if H_MV
536        assert( conf   .getScaledFlag() );
537        assert( defDisp.getScaledFlag() );
538        m_tVideoIOYuvReconFile[decIdx]->write( pcPicTop->getPicYuvRec(), pcPicBottom->getPicYuvRec(),
539#else
540          m_cTVideoIOYuvReconFile.write( pcPicTop->getPicYuvRec(), pcPicBottom->getPicYuvRec(),
541#endif
542                                        conf.getWindowLeftOffset() + defDisp.getWindowLeftOffset(),
543                                        conf.getWindowRightOffset() + defDisp.getWindowRightOffset(),
544                                        conf.getWindowTopOffset() + defDisp.getWindowTopOffset(),
545                                        conf.getWindowBottomOffset() + defDisp.getWindowBottomOffset(), isTff );
546        }
547       
548        // update POC of display order
549#if H_MV
550        m_pocLastDisplay[decIdx] = pcPic->getPOC();
551#else
552        m_iPOCLastDisplay = pcPicBottom->getPOC();
553#endif
554       
555        // erase non-referenced picture in the reference picture list after display
556        if ( !pcPicTop->getSlice(0)->isReferenced() && pcPicTop->getReconMark() == true )
557        {
558#if !DYN_REF_FREE
559          pcPicTop->setReconMark(false);
560         
561          // mark it should be extended later
562          pcPicTop->getPicYuvRec()->setBorderExtension( false );
563         
564#else
565          pcPicTop->destroy();
566          pcListPic->erase( iterPic );
567          iterPic = pcListPic->begin(); // to the beginning, non-efficient way, have to be revised!
568          continue;
569#endif
570        }
571        if ( !pcPicBottom->getSlice(0)->isReferenced() && pcPicBottom->getReconMark() == true )
572        {
573#if !DYN_REF_FREE
574          pcPicBottom->setReconMark(false);
575         
576          // mark it should be extended later
577          pcPicBottom->getPicYuvRec()->setBorderExtension( false );
578         
579#else
580          pcPicBottom->destroy();
581          pcListPic->erase( iterPic );
582          iterPic = pcListPic->begin(); // to the beginning, non-efficient way, have to be revised!
583          continue;
584#endif
585        }
586        pcPicTop->setOutputMark(false);
587        pcPicBottom->setOutputMark(false);
588      }
589    }
590  }
591  else if (!pcPic->isField()) //Frame Decoding
592  {
593    iterPic = pcListPic->begin();
594    while (iterPic != pcListPic->end())
595    {
596      pcPic = *(iterPic);
597
598#if H_MV
599      if ( pcPic->getOutputMark() && (numPicsNotYetDisplayed >  pcPic->getNumReorderPics(tId) && pcPic->getPOC() > m_pocLastDisplay[decIdx]))
600#else     
601      if ( pcPic->getOutputMark() && (numPicsNotYetDisplayed >  pcPic->getNumReorderPics(tId) && pcPic->getPOC() > m_iPOCLastDisplay))
602#endif
603      {
604        // write to file
605        numPicsNotYetDisplayed--;
606#if H_MV
607      if ( m_pchReconFiles[decIdx] )
608#else
609        if ( m_pchReconFile )
610#endif
611        {
612          const Window &conf = pcPic->getConformanceWindow();
613          const Window &defDisp = m_respectDefDispWindow ? pcPic->getDefDisplayWindow() : Window();
614#if H_MV
615        assert( conf   .getScaledFlag() );
616        assert( defDisp.getScaledFlag() );
617        m_tVideoIOYuvReconFile[decIdx]->write( pcPic->getPicYuvRec(),
618#else
619          m_cTVideoIOYuvReconFile.write( pcPic->getPicYuvRec(),
620#endif
621                                        conf.getWindowLeftOffset() + defDisp.getWindowLeftOffset(),
622                                        conf.getWindowRightOffset() + defDisp.getWindowRightOffset(),
623                                        conf.getWindowTopOffset() + defDisp.getWindowTopOffset(),
624                                        conf.getWindowBottomOffset() + defDisp.getWindowBottomOffset() );
625        }
626       
627        // update POC of display order
628#if H_MV
629        m_pocLastDisplay[decIdx] = pcPic->getPOC();
630#else
631        m_iPOCLastDisplay = pcPic->getPOC();
632#endif
633       
634        // erase non-referenced picture in the reference picture list after display
635        if ( !pcPic->getSlice(0)->isReferenced() && pcPic->getReconMark() == true )
636        {
637#if !DYN_REF_FREE
638          pcPic->setReconMark(false);
639         
640          // mark it should be extended later
641          pcPic->getPicYuvRec()->setBorderExtension( false );
642         
643#else
644          pcPic->destroy();
645          pcListPic->erase( iterPic );
646          iterPic = pcListPic->begin(); // to the beginning, non-efficient way, have to be revised!
647          continue;
648#endif
649        }
650        pcPic->setOutputMark(false);
651      }
652     
653      iterPic++;
654    }
655  }
656}
657/** \param pcListPic list of pictures to be written to file
658    \todo            DYN_REF_FREE should be revised
659 */
660#if H_MV
661Void TAppDecTop::xFlushOutput( TComList<TComPic*>* pcListPic, Int decIdx )
662#else
663Void TAppDecTop::xFlushOutput( TComList<TComPic*>* pcListPic )
664#endif
665{
666  if(!pcListPic || pcListPic->empty())
667  {
668    return;
669  }
670  TComList<TComPic*>::iterator iterPic   = pcListPic->begin();
671 
672  iterPic   = pcListPic->begin();
673  TComPic* pcPic = *(iterPic);
674 
675  if (pcPic->isField()) //Field Decoding
676  {
677    TComList<TComPic*>::iterator endPic   = pcListPic->end();
678    endPic--;
679    TComPic *pcPicTop, *pcPicBottom = NULL;
680    while (iterPic != endPic)
681    {
682      pcPicTop = *(iterPic);
683      iterPic++;
684      pcPicBottom = *(iterPic);
685     
686      if ( pcPicTop->getOutputMark() && pcPicBottom->getOutputMark() && !(pcPicTop->getPOC()%2) && (pcPicBottom->getPOC() == pcPicTop->getPOC()+1) )
687      {
688        // write to file
689#if H_MV
690      if ( m_pchReconFiles[decIdx] )
691#else
692        if ( m_pchReconFile )
693#endif
694        {
695          const Window &conf = pcPicTop->getConformanceWindow();
696          const Window &defDisp = m_respectDefDispWindow ? pcPicTop->getDefDisplayWindow() : Window();
697          const Bool isTff = pcPicTop->isTopField();
698#if H_MV
699        assert( conf   .getScaledFlag() );
700        assert( defDisp.getScaledFlag() );
701        m_tVideoIOYuvReconFile[decIdx]->write( pcPicTop->getPicYuvRec(), pcPicBottom->getPicYuvRec(),
702#else
703          m_cTVideoIOYuvReconFile.write( pcPicTop->getPicYuvRec(), pcPicBottom->getPicYuvRec(),
704#endif
705                                        conf.getWindowLeftOffset() + defDisp.getWindowLeftOffset(),
706                                        conf.getWindowRightOffset() + defDisp.getWindowRightOffset(),
707                                        conf.getWindowTopOffset() + defDisp.getWindowTopOffset(),
708                                        conf.getWindowBottomOffset() + defDisp.getWindowBottomOffset(), isTff );
709        }
710       
711        // update POC of display order
712#if H_MV
713      m_pocLastDisplay[decIdx] = pcPic->getPOC();
714#else
715      m_iPOCLastDisplay = pcPicBottom->getPOC();
716#endif       
717        // erase non-referenced picture in the reference picture list after display
718        if ( !pcPicTop->getSlice(0)->isReferenced() && pcPicTop->getReconMark() == true )
719        {
720#if !DYN_REF_FREE
721          pcPicTop->setReconMark(false);
722         
723          // mark it should be extended later
724          pcPicTop->getPicYuvRec()->setBorderExtension( false );
725         
726#else
727          pcPicTop->destroy();
728          pcListPic->erase( iterPic );
729          iterPic = pcListPic->begin(); // to the beginning, non-efficient way, have to be revised!
730          continue;
731#endif
732        }
733        if ( !pcPicBottom->getSlice(0)->isReferenced() && pcPicBottom->getReconMark() == true )
734        {
735#if !DYN_REF_FREE
736          pcPicBottom->setReconMark(false);
737         
738          // mark it should be extended later
739          pcPicBottom->getPicYuvRec()->setBorderExtension( false );
740         
741#else
742          pcPicBottom->destroy();
743          pcListPic->erase( iterPic );
744          iterPic = pcListPic->begin(); // to the beginning, non-efficient way, have to be revised!
745          continue;
746#endif
747        }
748        pcPicTop->setOutputMark(false);
749        pcPicBottom->setOutputMark(false);
750       
751#if !DYN_REF_FREE
752        if(pcPicTop)
753        {
754          pcPicTop->destroy();
755          delete pcPicTop;
756          pcPicTop = NULL;
757        }
758#endif
759      }
760    }
761    if(pcPicBottom)
762    {
763      pcPicBottom->destroy();
764      delete pcPicBottom;
765      pcPicBottom = NULL;
766    }
767  }
768  else //Frame decoding
769  {
770    while (iterPic != pcListPic->end())
771    {
772      pcPic = *(iterPic);
773     
774      if ( pcPic->getOutputMark() )
775      {
776        // write to file
777#if H_MV
778      if ( m_pchReconFiles[decIdx] )
779#else
780        if ( m_pchReconFile )
781#endif
782        {
783          const Window &conf = pcPic->getConformanceWindow();
784          const Window &defDisp = m_respectDefDispWindow ? pcPic->getDefDisplayWindow() : Window();
785#if H_MV
786        assert( conf   .getScaledFlag() );
787        assert( defDisp.getScaledFlag() );
788        m_tVideoIOYuvReconFile[decIdx]->write( pcPic->getPicYuvRec(),
789#else
790          m_cTVideoIOYuvReconFile.write( pcPic->getPicYuvRec(),
791#endif
792                                        conf.getWindowLeftOffset() + defDisp.getWindowLeftOffset(),
793                                        conf.getWindowRightOffset() + defDisp.getWindowRightOffset(),
794                                        conf.getWindowTopOffset() + defDisp.getWindowTopOffset(),
795                                        conf.getWindowBottomOffset() + defDisp.getWindowBottomOffset() );
796        }
797       
798        // update POC of display order
799#if H_MV
800      m_pocLastDisplay[decIdx] = pcPic->getPOC();
801#else
802        m_iPOCLastDisplay = pcPic->getPOC();
803#endif
804       
805        // erase non-referenced picture in the reference picture list after display
806        if ( !pcPic->getSlice(0)->isReferenced() && pcPic->getReconMark() == true )
807        {
808#if !DYN_REF_FREE
809          pcPic->setReconMark(false);
810         
811          // mark it should be extended later
812          pcPic->getPicYuvRec()->setBorderExtension( false );
813         
814#else
815          pcPic->destroy();
816          pcListPic->erase( iterPic );
817          iterPic = pcListPic->begin(); // to the beginning, non-efficient way, have to be revised!
818          continue;
819#endif
820        }
821        pcPic->setOutputMark(false);
822      }
823#if !H_MV
824#if !DYN_REF_FREE
825      if(pcPic)
826      {
827        pcPic->destroy();
828        delete pcPic;
829        pcPic = NULL;
830      }
831#endif   
832#endif
833      iterPic++;
834    }
835  }
836#if H_MV
837  m_pocLastDisplay[decIdx] = -MAX_INT;
838#else
839  pcListPic->clear();
840  m_iPOCLastDisplay = -MAX_INT;
841#endif
842}
843
844/** \param nalu Input nalu to check whether its LayerId is within targetDecLayerIdSet
845 */
846Bool TAppDecTop::isNaluWithinTargetDecLayerIdSet( InputNALUnit* nalu )
847{
848  if ( m_targetDecLayerIdSet.size() == 0 ) // By default, the set is empty, meaning all LayerIds are allowed
849  {
850    return true;
851  }
852  for (std::vector<Int>::iterator it = m_targetDecLayerIdSet.begin(); it != m_targetDecLayerIdSet.end(); it++)
853  {
854#if H_MV
855    if ( nalu->m_layerId == (*it) )
856#else
857    if ( nalu->m_reservedZero6Bits == (*it) )
858#endif
859    {
860      return true;
861    }
862  }
863  return false;
864}
865
866#if H_MV
867Int TAppDecTop::xGetDecoderIdx( Int layerId, Bool createFlag /*= false */ )
868{
869  Int decIdx = -1; 
870
871  if ( layerId > MAX_NUM_LAYER_IDS-1 ) 
872  {
873    return decIdx; 
874  }
875
876  if ( m_layerIdToDecIdx[ layerId ] != -1 ) 
877  {     
878    decIdx = m_layerIdToDecIdx[ layerId ]; 
879  }
880  else
881  {     
882    assert ( createFlag ); 
883    assert( m_numDecoders < MAX_NUM_LAYERS ); 
884
885    decIdx = m_numDecoders; 
886
887    // Init decoder
888    m_tDecTop[ decIdx ] =  new TDecTop;
889    m_tDecTop[ decIdx ]->create();
890    m_tDecTop[ decIdx ]->init( );
891    m_tDecTop[ decIdx ]->setLayerId( layerId );
892    m_tDecTop[ decIdx ]->setDecodedPictureHashSEIEnabled(m_decodedPictureHashSEIEnabled);
893    m_tDecTop[ decIdx ]->setIvPicLists( &m_ivPicLists ); 
894    m_tDecTop[ decIdx ]->setLayerInitilizedFlags( m_layerInitilizedFlags );
895
896#if H_3D
897   m_tDecTop[ decIdx ]->setCamParsCollector( &m_cCamParsCollector );
898#endif
899
900    // append pic list of new decoder to PicLists
901    assert( m_ivPicLists.size() == m_numDecoders );
902    m_ivPicLists.push_back( m_tDecTop[ decIdx ]->getListPic() );
903
904    // create recon file related stuff     
905    Char* pchTempFilename = NULL;
906    if ( m_pchReconFile )
907    {     
908      Char buffer[4];     
909      sprintf(buffer,"_%i", layerId );
910      assert ( m_pchReconFile ); 
911      xAppendToFileNameEnd( m_pchReconFile , buffer, pchTempFilename );
912      assert( m_pchReconFiles.size() == m_numDecoders );
913    }
914
915    m_pchReconFiles.push_back( pchTempFilename );   
916
917    m_tVideoIOYuvReconFile[ decIdx ] = new TVideoIOYuv;
918    m_reconOpen           [ decIdx ] = false;
919
920    // set others
921    m_pocLastDisplay      [ decIdx ] = -MAX_INT;
922    m_layerIdToDecIdx     [ layerId ] = decIdx; 
923
924    m_numDecoders++; 
925  };
926  return decIdx;
927}
928#endif
929//! \}
Note: See TracBrowser for help on using the repository browser.