source: SHVCSoftware/branches/SHM-5.1-dev/source/App/TAppDecoder/TAppDecTop.cpp @ 1465

Last change on this file since 1465 was 627, checked in by qualcomm, 11 years ago

JCTVC-P312: vertical phase adjustment for interlace-to-progressive scalability, from Jianle Chen (cjianle@…)

  • Property svn:eol-style set to native
File size: 48.3 KB
RevLine 
[313]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
[494]4 * granted under this license.
[313]5 *
[595]6 * Copyright (c) 2010-2014, ITU/ISO/IEC
[313]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>
[612]43#include <iostream>
[313]44#include "TAppDecTop.h"
45#include "TLibDecoder/AnnexBread.h"
46#include "TLibDecoder/NALread.h"
47//! \ingroup TAppDecoder
48//! \{
49
50// ====================================================================================================================
51// Constructor / destructor / initialization / destroy
52// ====================================================================================================================
53
54#if SVC_EXTENSION
55TAppDecTop::TAppDecTop()
56{
57  for(UInt layer=0; layer < MAX_LAYERS; layer++)
58  {
59    m_aiPOCLastDisplay[layer]  = -MAX_INT;
60    m_apcTDecTop[layer] = &m_acTDecTop[layer];
61  }
62}
63#else
64TAppDecTop::TAppDecTop()
65: m_iPOCLastDisplay(-MAX_INT)
66{
67}
68#endif
69
70Void TAppDecTop::create()
71{
72}
73
74Void TAppDecTop::destroy()
75{
76  if (m_pchBitstreamFile)
77  {
78    free (m_pchBitstreamFile);
79    m_pchBitstreamFile = NULL;
80  }
[494]81#if SVC_EXTENSION
[588]82  for( Int i = 0; i <= m_tgtLayerId; i++ )
[313]83  {
84    if( m_pchReconFile[i] )
85    {
86      free ( m_pchReconFile[i] );
87      m_pchReconFile[i] = NULL;
88    }
[494]89  }
[313]90#if AVC_BASE
91  if( m_pchBLReconFile )
92  {
93    free ( m_pchBLReconFile );
94    m_pchBLReconFile = NULL;
95  }
96#endif
97#else
98  if (m_pchReconFile)
99  {
100    free (m_pchReconFile);
101    m_pchReconFile = NULL;
102  }
103#endif
104#if AVC_SYNTAX || SYNTAX_OUTPUT
105  if( m_pchBLSyntaxFile )
106  {
107    free ( m_pchBLSyntaxFile );
108    m_pchBLSyntaxFile = NULL;
109  }
110#endif
111}
112
113// ====================================================================================================================
114// Public member functions
115// ====================================================================================================================
116
117/**
118 - create internal class
119 - initialize internal class
120 - until the end of the bitstream, call decoding function in TDecTop class
121 - delete allocated buffers
122 - destroy internal class
123 .
124 */
125#if SVC_EXTENSION
126Void TAppDecTop::decode()
127{
128  Int                poc;
129  TComList<TComPic*>* pcListPic = NULL;
130
131  ifstream bitstreamFile(m_pchBitstreamFile, ifstream::in | ifstream::binary);
132  if (!bitstreamFile)
133  {
134    fprintf(stderr, "\nfailed to open bitstream file `%s' for reading\n", m_pchBitstreamFile);
135    exit(EXIT_FAILURE);
136  }
137
138  InputByteStream bytestream(bitstreamFile);
139
140  // create & initialize internal classes
141  xCreateDecLib();
142  xInitDecLib  ();
143
144  // main decoder loop
[442]145  Bool openedReconFile[MAX_LAYERS]; // reconstruction file not yet opened. (must be performed after SPS is seen)
[540]146  Bool loopFiltered[MAX_LAYERS];
147  memset( loopFiltered, false, sizeof( loopFiltered ) );
148
[313]149  for(UInt layer=0; layer<=m_tgtLayerId; layer++)
150  {
[442]151    openedReconFile[layer] = false;
[313]152    m_aiPOCLastDisplay[layer] += m_iSkipFrame;      // set the last displayed POC correctly for skip forward.
153  }
154
155  UInt curLayerId = 0;     // current layer to be reconstructed
156
157#if AVC_BASE
158  TComPic pcBLPic;
159  fstream streamYUV;
160  if( m_pchBLReconFile )
161  {
162    streamYUV.open( m_pchBLReconFile, fstream::in | fstream::binary );
163  }
164  TComList<TComPic*> *cListPic = m_acTDecTop[0].getListPic();
165  m_acTDecTop[0].setBLsize( m_iBLSourceWidth, m_iBLSourceHeight );
166  m_acTDecTop[0].setBLReconFile( &streamYUV );
167  pcBLPic.setLayerId( 0 );
168  cListPic->pushBack( &pcBLPic );
169#if AVC_SYNTAX
170  fstream streamSyntaxFile;
171  if( m_pchBLSyntaxFile )
172  {
173    streamSyntaxFile.open( m_pchBLSyntaxFile, fstream::in | fstream::binary );
174  }
175  m_acTDecTop[0].setBLSyntaxFile( &streamSyntaxFile );
176#endif
177#endif
178
179  while (!!bitstreamFile)
180  {
181    /* location serves to work around a design fault in the decoder, whereby
182     * the process of reading a new slice that is the first slice of a new frame
183     * requires the TDecTop::decode() method to be called again with the same
184     * nal unit. */
185    streampos location = bitstreamFile.tellg();
186    AnnexBStats stats = AnnexBStats();
187
188    vector<uint8_t> nalUnit;
189    InputNALUnit nalu;
190    byteStreamNALUnit(bytestream, nalUnit, stats);
191
192    // call actual decoding function
193    Bool bNewPicture = false;
194    Bool bNewPOC = false;
195    if (nalUnit.empty())
196    {
197      /* this can happen if the following occur:
198       *  - empty input file
199       *  - two back-to-back start_code_prefixes
200       *  - start_code_prefix immediately followed by EOF
201       */
202      fprintf(stderr, "Warning: Attempt to decode an empty NAL unit\n");
203    }
204    else
205    {
206      read(nalu, nalUnit);
207      if( (m_iMaxTemporalLayer >= 0 && nalu.m_temporalId > m_iMaxTemporalLayer) || !isNaluWithinTargetDecLayerIdSet(&nalu)  ||
208        (nalu.m_layerId > m_tgtLayerId) )
209      {
210        bNewPicture = false;
211      }
212      else
213      {
214        bNewPicture = m_acTDecTop[nalu.m_layerId].decode(nalu, m_iSkipFrame, m_aiPOCLastDisplay[nalu.m_layerId], curLayerId, bNewPOC);
215        if (bNewPicture)
216        {
217          bitstreamFile.clear();
218          /* location points to the current nalunit payload[1] due to the
219           * need for the annexB parser to read three extra bytes.
220           * [1] except for the first NAL unit in the file
221           *     (but bNewPicture doesn't happen then) */
222          bitstreamFile.seekg(location-streamoff(3));
223          bytestream.reset();
224        }
225      }
226    }
[540]227
228    if (bNewPicture || !bitstreamFile || nalu.m_nalUnitType == NAL_UNIT_EOS)
[313]229    {
[494]230#if O0194_DIFFERENT_BITDEPTH_EL_BL
231      //Bug fix: The bit depth was not set correctly for each layer when doing DBF
232      g_bitDepthY = g_bitDepthYLayer[curLayerId];
233      g_bitDepthC = g_bitDepthCLayer[curLayerId];
234#endif
[540]235      if (!loopFiltered[curLayerId] || bitstreamFile)
236      {
237        m_acTDecTop[curLayerId].executeLoopFilters(poc, pcListPic);
238      }
239      loopFiltered[curLayerId] = (nalu.m_nalUnitType == NAL_UNIT_EOS);
[442]240#if EARLY_REF_PIC_MARKING
241      m_acTDecTop[curLayerId].earlyPicMarking(m_iMaxTemporalLayer, m_targetDecLayerIdSet);
242#endif
[313]243    }
244
245    if( pcListPic )
246    {
[442]247      if ( m_pchReconFile[curLayerId] && !openedReconFile[curLayerId] )
[313]248      {
[494]249        if (!m_outputBitDepthY) { m_outputBitDepthY = g_bitDepthY; }
[313]250        if (!m_outputBitDepthC) { m_outputBitDepthC = g_bitDepthC; }
251
252        m_acTVideoIOYuvReconFile[curLayerId].open( m_pchReconFile[curLayerId], true, m_outputBitDepthY, m_outputBitDepthC, g_bitDepthY, g_bitDepthC ); // write mode
253
[442]254        openedReconFile[curLayerId] = true;
[313]255      }
[612]256#if ALIGNED_BUMPING
257      Bool outputPicturesFlag = true; 
[625]258#if NO_OUTPUT_OF_PRIOR_PICS
259      if( m_acTDecTop[nalu.m_layerId].getNoOutputOfPriorPicsFlags() )
260      {
261        outputPicturesFlag = false;
262      }
263#endif
[612]264
265      if (nalu.m_nalUnitType == NAL_UNIT_EOS) // End of sequence
266      {
267        flushAllPictures( nalu.m_layerId, outputPicturesFlag );       
268      }
269      if( bNewPicture ) // New picture, slice header parsed but picture not decoded
270      {
[625]271#if NO_OUTPUT_OF_PRIOR_PICS
272        if( 
273#else
[612]274        if ( bNewPOC &&
[625]275#endif
[612]276           (   nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_IDR_W_RADL
277            || nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_IDR_N_LP
278            || nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_BLA_N_LP
279            || nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_BLA_W_RADL
280            || nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_BLA_W_LP ) )
281        {
282          flushAllPictures( nalu.m_layerId, outputPicturesFlag );
283        }
284        else
285        {
286          this->checkOutputBeforeDecoding( nalu.m_layerId );
287        }
288      }
289
290      /* The following code has to be executed when the last DU of the picture is decoded
291         TODO: Need code to identify end of decoding a picture
292      {
293        this->checkOutputAfterDecoding( );
294      } */
295#else
[494]296      if ( bNewPicture && bNewPOC &&
[313]297           (   nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_IDR_W_RADL
298            || nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_IDR_N_LP
299            || nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_BLA_N_LP
300            || nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_BLA_W_RADL
301            || nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_BLA_W_LP ) )
302      {
303        xFlushOutput( pcListPic, curLayerId );
304      }
[540]305      if (nalu.m_nalUnitType == NAL_UNIT_EOS)
306      {
307        xFlushOutput( pcListPic, curLayerId );       
308      }
[313]309      // write reconstruction to file
310      if(bNewPicture)
311      {
312        xWriteOutput( pcListPic, curLayerId, nalu.m_temporalId );
313      }
[612]314#endif
[313]315    }
316  }
[612]317#if ALIGNED_BUMPING
318   flushAllPictures( true );   
319#else
[313]320  for(UInt layer = 0; layer <= m_tgtLayerId; layer++)
321  {
322    xFlushOutput( m_acTDecTop[layer].getListPic(), layer );
323  }
[612]324#endif
[313]325  // delete buffers
326#if AVC_BASE
[442]327  UInt layerIdmin = m_acTDecTop[0].getBLReconFile()->is_open() ? 1 : 0;
328
[313]329  if( streamYUV.is_open() )
330  {
331    streamYUV.close();
332  }
333#if AVC_SYNTAX
334  if( streamSyntaxFile.is_open() )
335  {
336    streamSyntaxFile.close();
337  }
338#endif
[494]339  pcBLPic.destroy();
[313]340
[442]341  for(UInt layer = layerIdmin; layer <= m_tgtLayerId; layer++)
[313]342#else
343  for(UInt layer = 0; layer <= m_tgtLayerId; layer++)
344#endif
345  {
346    m_acTDecTop[layer].deletePicBuffer();
347  }
[494]348
[313]349  // destroy internal classes
350  xDestroyDecLib();
351}
352#else
353Void TAppDecTop::decode()
354{
355  Int                 poc;
356  TComList<TComPic*>* pcListPic = NULL;
357
358  ifstream bitstreamFile(m_pchBitstreamFile, ifstream::in | ifstream::binary);
359  if (!bitstreamFile)
360  {
361    fprintf(stderr, "\nfailed to open bitstream file `%s' for reading\n", m_pchBitstreamFile);
362    exit(EXIT_FAILURE);
363  }
364
365  InputByteStream bytestream(bitstreamFile);
366
367  // create & initialize internal classes
368  xCreateDecLib();
369  xInitDecLib  ();
370  m_iPOCLastDisplay += m_iSkipFrame;      // set the last displayed POC correctly for skip forward.
371
372  // main decoder loop
[442]373  Bool openedReconFile = false; // reconstruction file not yet opened. (must be performed after SPS is seen)
[540]374  Bool loopFiltered = false;
[313]375
376#if SYNTAX_OUTPUT
377  if( !m_pchBLSyntaxFile )
378  {
379    printf( "Wrong base layer syntax file\n" );
380    exit(EXIT_FAILURE);
381  }
382  fstream streamSyntaxFile( m_pchBLSyntaxFile, fstream::out | fstream::binary );
383  if( !streamSyntaxFile.good() )
384  {
385    printf( "Base layer syntax input reading error\n" );
386    exit(EXIT_FAILURE);
387  }
388  m_cTDecTop.setBLSyntaxFile( &streamSyntaxFile );
389
390  for( Int i = m_iBLFrames * m_iBLSourceWidth * m_iBLSourceHeight * SYNTAX_BYTES / 16; i >= 0; i-- )
391  {
392    streamSyntaxFile.put( 0 );
393  }
394  streamSyntaxFile.seekp( 0 );
395#endif
396
397  while (!!bitstreamFile)
398  {
399    /* location serves to work around a design fault in the decoder, whereby
400     * the process of reading a new slice that is the first slice of a new frame
401     * requires the TDecTop::decode() method to be called again with the same
402     * nal unit. */
403    streampos location = bitstreamFile.tellg();
404    AnnexBStats stats = AnnexBStats();
405
406    vector<uint8_t> nalUnit;
407    InputNALUnit nalu;
408    byteStreamNALUnit(bytestream, nalUnit, stats);
409
410    // call actual decoding function
411    Bool bNewPicture = false;
412    if (nalUnit.empty())
413    {
414      /* this can happen if the following occur:
415       *  - empty input file
416       *  - two back-to-back start_code_prefixes
417       *  - start_code_prefix immediately followed by EOF
418       */
419      fprintf(stderr, "Warning: Attempt to decode an empty NAL unit\n");
420    }
421    else
422    {
423      read(nalu, nalUnit);
424      if( (m_iMaxTemporalLayer >= 0 && nalu.m_temporalId > m_iMaxTemporalLayer) || !isNaluWithinTargetDecLayerIdSet(&nalu)  )
425      {
426          bNewPicture = false;
427        }
428      else
429      {
430        bNewPicture = m_cTDecTop.decode(nalu, m_iSkipFrame, m_iPOCLastDisplay);
431        if (bNewPicture)
432        {
433          bitstreamFile.clear();
434          /* location points to the current nalunit payload[1] due to the
435           * need for the annexB parser to read three extra bytes.
436           * [1] except for the first NAL unit in the file
437           *     (but bNewPicture doesn't happen then) */
438          bitstreamFile.seekg(location-streamoff(3));
439          bytestream.reset();
440        }
441      }
442    }
[540]443    if (bNewPicture || !bitstreamFile || nalu.m_nalUnitType == NAL_UNIT_EOS)
[313]444    {
[540]445      if (!loopFiltered || bitstreamFile)
446      {
447        m_cTDecTop.executeLoopFilters(poc, pcListPic);
448      }
449      loopFiltered = (nalu.m_nalUnitType == NAL_UNIT_EOS);
[313]450    }
451
452    if( pcListPic )
453    {
[442]454      if ( m_pchReconFile && !openedReconFile )
[313]455      {
456        if (!m_outputBitDepthY) { m_outputBitDepthY = g_bitDepthY; }
457        if (!m_outputBitDepthC) { m_outputBitDepthC = g_bitDepthC; }
458
459        m_cTVideoIOYuvReconFile.open( m_pchReconFile, true, m_outputBitDepthY, m_outputBitDepthC, g_bitDepthY, g_bitDepthC ); // write mode
[442]460        openedReconFile = true;
[313]461      }
[494]462      if ( bNewPicture &&
[313]463           (   nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_IDR_W_RADL
464            || nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_IDR_N_LP
465            || nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_BLA_N_LP
466            || nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_BLA_W_RADL
467            || nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_BLA_W_LP ) )
468      {
469        xFlushOutput( pcListPic );
470      }
[540]471      if (nalu.m_nalUnitType == NAL_UNIT_EOS)
472      {
473        xFlushOutput( pcListPic );       
474      }
[313]475      // write reconstruction to file
476      if(bNewPicture)
477      {
478        xWriteOutput( pcListPic, nalu.m_temporalId );
479      }
480    }
481  }
[494]482
[313]483#if SYNTAX_OUTPUT
484  if( streamSyntaxFile.is_open() )
485  {
486    streamSyntaxFile.close();
487  }
488#endif
[494]489
[313]490  xFlushOutput( pcListPic );
491  // delete buffers
492  m_cTDecTop.deletePicBuffer();
[494]493
[313]494  // destroy internal classes
495  xDestroyDecLib();
496}
497#endif
498
499// ====================================================================================================================
500// Protected member functions
501// ====================================================================================================================
502
503Void TAppDecTop::xCreateDecLib()
504{
505#if SVC_EXTENSION
506  // initialize global variables
[494]507  initROM();
[313]508
509  for(UInt layer = 0; layer <= m_tgtLayerId; layer++)
510  {
511    // set layer ID
512    m_acTDecTop[layer].setLayerId                      ( layer );
513
514    // create decoder class
515    m_acTDecTop[layer].create();
516
[494]517    m_acTDecTop[layer].setLayerDec(m_apcTDecTop);
[313]518  }
519#else
520  // create decoder class
521  m_cTDecTop.create();
522#endif
523}
524
525Void TAppDecTop::xDestroyDecLib()
526{
527#if SVC_EXTENSION
528  // destroy ROM
529  destroyROM();
530
531  for(UInt layer = 0; layer <= m_tgtLayerId; layer++)
532  {
533    if ( m_pchReconFile[layer] )
534    {
[442]535      m_acTVideoIOYuvReconFile[layer].close();
[313]536    }
537
538    // destroy decoder class
539    m_acTDecTop[layer].destroy();
540  }
541#else
542  if ( m_pchReconFile )
543  {
544    m_cTVideoIOYuvReconFile. close();
545  }
[494]546
[313]547  // destroy decoder class
548  m_cTDecTop.destroy();
549#endif
550}
551
552Void TAppDecTop::xInitDecLib()
553{
554  // initialize decoder class
555#if SVC_EXTENSION
556  for(UInt layer = 0; layer <= m_tgtLayerId; layer++)
557  {
558    m_acTDecTop[layer].init();
559    m_acTDecTop[layer].setDecodedPictureHashSEIEnabled(m_decodedPictureHashSEIEnabled);
560    m_acTDecTop[layer].setNumLayer( m_tgtLayerId + 1 );
[540]561#if OUTPUT_LAYER_SET_INDEX
562    m_acTDecTop[layer].setCommonDecoderParams( this->getCommonDecoderParams() );
563#endif
[313]564  }
565
566#else
567  m_cTDecTop.init();
568  m_cTDecTop.setDecodedPictureHashSEIEnabled(m_decodedPictureHashSEIEnabled);
569#endif
570}
571
572/** \param pcListPic list of pictures to be written to file
[540]573    \todo            DYN_REF_FREE should be revised
574 */
[313]575#if SVC_EXTENSION
576Void TAppDecTop::xWriteOutput( TComList<TComPic*>* pcListPic, UInt layerId, UInt tId )
577#else
578Void TAppDecTop::xWriteOutput( TComList<TComPic*>* pcListPic, UInt tId )
579#endif
580{
[540]581  if (pcListPic->empty())
582  {
583    return;
584  }
585
[313]586  TComList<TComPic*>::iterator iterPic   = pcListPic->begin();
[442]587  Int numPicsNotYetDisplayed = 0;
[313]588
589  while (iterPic != pcListPic->end())
590  {
591    TComPic* pcPic = *(iterPic);
592#if SVC_EXTENSION
593    if(pcPic->getOutputMark() && pcPic->getPOC() > m_aiPOCLastDisplay[layerId])
594#else
595    if(pcPic->getOutputMark() && pcPic->getPOC() > m_iPOCLastDisplay)
596#endif
597    {
[442]598      numPicsNotYetDisplayed++;
[313]599    }
600    iterPic++;
601  }
602  iterPic   = pcListPic->begin();
[442]603  if (numPicsNotYetDisplayed>2)
[313]604  {
[442]605    iterPic++;
606  }
607
608  TComPic* pcPic = *(iterPic);
609  if (numPicsNotYetDisplayed>2 && pcPic->isField()) //Field Decoding
610  {
611    TComList<TComPic*>::iterator endPic   = pcListPic->end();
612    endPic--;
613    iterPic   = pcListPic->begin();
614    while (iterPic != endPic)
615    {
616      TComPic* pcPicTop = *(iterPic);
617      iterPic++;
618      TComPic* pcPicBottom = *(iterPic);
619
[313]620#if SVC_EXTENSION
[442]621      if ( pcPicTop->getOutputMark() && (numPicsNotYetDisplayed >  pcPicTop->getNumReorderPics(tId) && !(pcPicTop->getPOC()%2) && pcPicBottom->getPOC() == pcPicTop->getPOC()+1)
622        && pcPicBottom->getOutputMark() && (numPicsNotYetDisplayed >  pcPicBottom->getNumReorderPics(tId) && (pcPicTop->getPOC() == m_aiPOCLastDisplay[layerId]+1 || m_aiPOCLastDisplay[layerId]<0)))
[313]623#else
[442]624      if ( pcPicTop->getOutputMark() && (numPicsNotYetDisplayed >  pcPicTop->getNumReorderPics(tId) && !(pcPicTop->getPOC()%2) && pcPicBottom->getPOC() == pcPicTop->getPOC()+1)
625        && pcPicBottom->getOutputMark() && (numPicsNotYetDisplayed >  pcPicBottom->getNumReorderPics(tId) && (pcPicTop->getPOC() == m_iPOCLastDisplay+1 || m_iPOCLastDisplay<0)))
[313]626#endif
[442]627      {
628        // write to file
629        numPicsNotYetDisplayed = numPicsNotYetDisplayed-2;
630#if SVC_EXTENSION
631        if ( m_pchReconFile[layerId] )
632        {
633          const Window &conf = pcPicTop->getConformanceWindow();
634          const Window &defDisp = m_respectDefDispWindow ? pcPicTop->getDefDisplayWindow() : Window();
635          const Bool isTff = pcPicTop->isTopField();
636#if REPN_FORMAT_IN_VPS
637          UInt chromaFormatIdc = pcPic->getSlice(0)->getChromaFormatIdc();
638          Int xScal =  TComSPS::getWinUnitX( chromaFormatIdc ), yScal = TComSPS::getWinUnitY( chromaFormatIdc );
639          m_acTVideoIOYuvReconFile[layerId].write( pcPicTop->getPicYuvRec(), pcPicBottom->getPicYuvRec(),
640            conf.getWindowLeftOffset()  * xScal + defDisp.getWindowLeftOffset(),
641            conf.getWindowRightOffset() * xScal + defDisp.getWindowRightOffset(),
642            conf.getWindowTopOffset()   * yScal + defDisp.getWindowTopOffset(),
643            conf.getWindowBottomOffset()* yScal + defDisp.getWindowBottomOffset(), isTff );
644
645#else
[494]646#if O0194_DIFFERENT_BITDEPTH_EL_BL
647          // Compile time bug-fix
648          m_acTVideoIOYuvReconFile[layerId].write( pcPicTop->getPicYuvRec(), pcPicBottom->getPicYuvRec(),
649#else
[442]650          m_cTVideoIOYuvReconFile.write( pcPicTop->getPicYuvRec(), pcPicBottom->getPicYuvRec(),
[494]651#endif
[442]652            conf.getWindowLeftOffset() + defDisp.getWindowLeftOffset(),
653            conf.getWindowRightOffset() + defDisp.getWindowRightOffset(),
654            conf.getWindowTopOffset() + defDisp.getWindowTopOffset(),
655            conf.getWindowBottomOffset() + defDisp.getWindowBottomOffset(), isTff );
656#endif
657        }
658
659        // update POC of display order
660        m_aiPOCLastDisplay[layerId] = pcPicBottom->getPOC();
661#else
662        if ( m_pchReconFile )
663        {
664          const Window &conf = pcPicTop->getConformanceWindow();
665          const Window &defDisp = m_respectDefDispWindow ? pcPicTop->getDefDisplayWindow() : Window();
666          const Bool isTff = pcPicTop->isTopField();
667          m_cTVideoIOYuvReconFile.write( pcPicTop->getPicYuvRec(), pcPicBottom->getPicYuvRec(),
668            conf.getWindowLeftOffset() + defDisp.getWindowLeftOffset(),
669            conf.getWindowRightOffset() + defDisp.getWindowRightOffset(),
670            conf.getWindowTopOffset() + defDisp.getWindowTopOffset(),
671            conf.getWindowBottomOffset() + defDisp.getWindowBottomOffset(), isTff );
672        }
673
674        // update POC of display order
675        m_iPOCLastDisplay = pcPicBottom->getPOC();
676#endif
677
678        // erase non-referenced picture in the reference picture list after display
679        if ( !pcPicTop->getSlice(0)->isReferenced() && pcPicTop->getReconMark() == true )
680        {
681#if !DYN_REF_FREE
682          pcPicTop->setReconMark(false);
683
684          // mark it should be extended later
685          pcPicTop->getPicYuvRec()->setBorderExtension( false );
686
687#else
688          pcPicTop->destroy();
689          pcListPic->erase( iterPic );
690          iterPic = pcListPic->begin(); // to the beginning, non-efficient way, have to be revised!
691          continue;
692#endif
693        }
694        if ( !pcPicBottom->getSlice(0)->isReferenced() && pcPicBottom->getReconMark() == true )
695        {
696#if !DYN_REF_FREE
697          pcPicBottom->setReconMark(false);
698
699          // mark it should be extended later
700          pcPicBottom->getPicYuvRec()->setBorderExtension( false );
701
702#else
703          pcPicBottom->destroy();
704          pcListPic->erase( iterPic );
705          iterPic = pcListPic->begin(); // to the beginning, non-efficient way, have to be revised!
706          continue;
707#endif
708        }
709        pcPicTop->setOutputMark(false);
710        pcPicBottom->setOutputMark(false);
711      }
712    }
713  }
714  else if (!pcPic->isField()) //Frame Decoding
715  {
716    iterPic = pcListPic->begin();
717    while (iterPic != pcListPic->end())
[313]718    {
[442]719      pcPic = *(iterPic);
720
[313]721#if SVC_EXTENSION
[442]722      if ( pcPic->getOutputMark() && (numPicsNotYetDisplayed >  pcPic->getNumReorderPics(tId) && pcPic->getPOC() > m_aiPOCLastDisplay[layerId]))
[313]723#else
[442]724      if ( pcPic->getOutputMark() && (numPicsNotYetDisplayed >  pcPic->getNumReorderPics(tId) && pcPic->getPOC() > m_iPOCLastDisplay))
725#endif
[313]726      {
[442]727        // write to file
728        numPicsNotYetDisplayed--;
729#if SVC_EXTENSION
730        if ( m_pchReconFile[layerId] )
731        {
732          const Window &conf = pcPic->getConformanceWindow();
733          const Window &defDisp = m_respectDefDispWindow ? pcPic->getDefDisplayWindow() : Window();
734#if REPN_FORMAT_IN_VPS
735          UInt chromaFormatIdc = pcPic->getSlice(0)->getChromaFormatIdc();
736          Int xScal =  TComSPS::getWinUnitX( chromaFormatIdc ), yScal = TComSPS::getWinUnitY( chromaFormatIdc );
737          m_acTVideoIOYuvReconFile[layerId].write( pcPic->getPicYuvRec(),
738            conf.getWindowLeftOffset()  * xScal + defDisp.getWindowLeftOffset(),
739            conf.getWindowRightOffset() * xScal + defDisp.getWindowRightOffset(),
740            conf.getWindowTopOffset()   * yScal + defDisp.getWindowTopOffset(),
741            conf.getWindowBottomOffset()* yScal + defDisp.getWindowBottomOffset() );
742
[313]743#else
[442]744          m_acTVideoIOYuvReconFile[layerId].write( pcPic->getPicYuvRec(),
745            conf.getWindowLeftOffset() + defDisp.getWindowLeftOffset(),
746            conf.getWindowRightOffset() + defDisp.getWindowRightOffset(),
747            conf.getWindowTopOffset() + defDisp.getWindowTopOffset(),
748            conf.getWindowBottomOffset() + defDisp.getWindowBottomOffset() );
[313]749#endif
[442]750        }
751
752        // update POC of display order
753        m_aiPOCLastDisplay[layerId] = pcPic->getPOC();
754#else
755        if ( m_pchReconFile )
756        {
757#if SYNTAX_OUTPUT
758          const Window &conf = pcPic->getConformanceWindow();
759          const Window &defDisp = m_respectDefDispWindow ? pcPic->getDefDisplayWindow() : Window();
760          m_cTVideoIOYuvReconFile.write( pcPic->getPicYuvRec(),
761            conf.getWindowLeftOffset() + defDisp.getWindowLeftOffset(),
762            conf.getWindowRightOffset() + defDisp.getWindowRightOffset(),
763            conf.getWindowTopOffset() + defDisp.getWindowTopOffset(),
764            conf.getWindowBottomOffset() + defDisp.getWindowBottomOffset() );
[313]765#endif
[442]766        }
767
768        // update POC of display order
769        m_iPOCLastDisplay = pcPic->getPOC();
770#endif
771
772        // erase non-referenced picture in the reference picture list after display
773        if ( !pcPic->getSlice(0)->isReferenced() && pcPic->getReconMark() == true )
774        {
[313]775#if !DYN_REF_FREE
[442]776          pcPic->setReconMark(false);
777
778          // mark it should be extended later
779          pcPic->getPicYuvRec()->setBorderExtension( false );
780
[313]781#else
[442]782          pcPic->destroy();
783          pcListPic->erase( iterPic );
784          iterPic = pcListPic->begin(); // to the beginning, non-efficient way, have to be revised!
785          continue;
[313]786#endif
[442]787        }
788        pcPic->setOutputMark(false);
[313]789      }
[442]790
791      iterPic++;
[313]792    }
793  }
794}
795
796/** \param pcListPic list of pictures to be written to file
797    \todo            DYN_REF_FREE should be revised
798 */
799#if SVC_EXTENSION
800Void TAppDecTop::xFlushOutput( TComList<TComPic*>* pcListPic, UInt layerId )
801#else
802Void TAppDecTop::xFlushOutput( TComList<TComPic*>* pcListPic )
803#endif
804{
[540]805  if(!pcListPic || pcListPic->empty())
[313]806  {
807    return;
[494]808  }
[313]809  TComList<TComPic*>::iterator iterPic   = pcListPic->begin();
810
811  iterPic   = pcListPic->begin();
[442]812  TComPic* pcPic = *(iterPic);
813
814  if (pcPic->isField()) //Field Decoding
[313]815  {
[442]816    TComList<TComPic*>::iterator endPic   = pcListPic->end();
817    endPic--;
818    TComPic *pcPicTop, *pcPicBottom = NULL;
819    while (iterPic != endPic)
820    {
821      pcPicTop = *(iterPic);
822      iterPic++;
823      pcPicBottom = *(iterPic);
[313]824
[442]825      if ( pcPicTop->getOutputMark() && pcPicBottom->getOutputMark() && !(pcPicTop->getPOC()%2) && (pcPicBottom->getPOC() == pcPicTop->getPOC()+1) )
826      {
827        // write to file
828#if SVC_EXTENSION
829        if ( m_pchReconFile[layerId] )
830        {
831          const Window &conf = pcPicTop->getConformanceWindow();
832          const Window &defDisp = m_respectDefDispWindow ? pcPicTop->getDefDisplayWindow() : Window();
833          const Bool isTff = pcPicTop->isTopField();
834#if REPN_FORMAT_IN_VPS
835          UInt chromaFormatIdc = pcPic->getSlice(0)->getChromaFormatIdc();
836          Int xScal =  TComSPS::getWinUnitX( chromaFormatIdc ), yScal = TComSPS::getWinUnitY( chromaFormatIdc );
837          m_acTVideoIOYuvReconFile[layerId].write( pcPicTop->getPicYuvRec(), pcPicBottom->getPicYuvRec(),
838            conf.getWindowLeftOffset()  *xScal + defDisp.getWindowLeftOffset(),
839            conf.getWindowRightOffset() *xScal + defDisp.getWindowRightOffset(),
840            conf.getWindowTopOffset()   *yScal + defDisp.getWindowTopOffset(),
841            conf.getWindowBottomOffset()*yScal + defDisp.getWindowBottomOffset(), isTff );
842
843#else
[494]844#if O0194_DIFFERENT_BITDEPTH_EL_BL
845          // Compile time bug-fix
846          m_acTVideoIOYuvReconFile[layerId].write( pcPicTop->getPicYuvRec(), pcPicBottom->getPicYuvRec(),
847#else
[442]848          m_cTVideoIOYuvReconFile[layerId].write( pcPicTop->getPicYuvRec(), pcPicBottom->getPicYuvRec(),
[494]849#endif
[442]850            conf.getWindowLeftOffset() + defDisp.getWindowLeftOffset(),
851            conf.getWindowRightOffset() + defDisp.getWindowRightOffset(),
852            conf.getWindowTopOffset() + defDisp.getWindowTopOffset(),
853            conf.getWindowBottomOffset() + defDisp.getWindowBottomOffset(), isTff );
854#endif
855        }
856
857        // update POC of display order
858        m_aiPOCLastDisplay[layerId] = pcPicBottom->getPOC();
859#else
860        if ( m_pchReconFile )
861        {
862          const Window &conf = pcPicTop->getConformanceWindow();
863          const Window &defDisp = m_respectDefDispWindow ? pcPicTop->getDefDisplayWindow() : Window();
864          const Bool isTff = pcPicTop->isTopField();
865          m_cTVideoIOYuvReconFile.write( pcPicTop->getPicYuvRec(), pcPicBottom->getPicYuvRec(),
866            conf.getWindowLeftOffset() + defDisp.getWindowLeftOffset(),
867            conf.getWindowRightOffset() + defDisp.getWindowRightOffset(),
868            conf.getWindowTopOffset() + defDisp.getWindowTopOffset(),
869            conf.getWindowBottomOffset() + defDisp.getWindowBottomOffset(), isTff );
870        }
871
872        // update POC of display order
873        m_iPOCLastDisplay = pcPicBottom->getPOC();
874#endif
875
876        // erase non-referenced picture in the reference picture list after display
877        if ( !pcPicTop->getSlice(0)->isReferenced() && pcPicTop->getReconMark() == true )
878        {
879#if !DYN_REF_FREE
880          pcPicTop->setReconMark(false);
881
882          // mark it should be extended later
883          pcPicTop->getPicYuvRec()->setBorderExtension( false );
884
885#else
886          pcPicTop->destroy();
887          pcListPic->erase( iterPic );
888          iterPic = pcListPic->begin(); // to the beginning, non-efficient way, have to be revised!
889          continue;
890#endif
891        }
892        if ( !pcPicBottom->getSlice(0)->isReferenced() && pcPicBottom->getReconMark() == true )
893        {
894#if !DYN_REF_FREE
895          pcPicBottom->setReconMark(false);
896
897          // mark it should be extended later
898          pcPicBottom->getPicYuvRec()->setBorderExtension( false );
899
900#else
901          pcPicBottom->destroy();
902          pcListPic->erase( iterPic );
903          iterPic = pcListPic->begin(); // to the beginning, non-efficient way, have to be revised!
904          continue;
905#endif
906        }
907        pcPicTop->setOutputMark(false);
908        pcPicBottom->setOutputMark(false);
909
910#if !DYN_REF_FREE
911        if(pcPicTop)
912        {
913          pcPicTop->destroy();
914          delete pcPicTop;
915          pcPicTop = NULL;
916        }
917#endif
918      }
919    }
920    if(pcPicBottom)
[313]921    {
[442]922      pcPicBottom->destroy();
923      delete pcPicBottom;
924      pcPicBottom = NULL;
925    }
926  }
927  else //Frame decoding
928  {
929    while (iterPic != pcListPic->end())
930    {
931      pcPic = *(iterPic);
932
933      if ( pcPic->getOutputMark() )
934      {
935        // write to file
[313]936#if SVC_EXTENSION
[442]937        if ( m_pchReconFile[layerId] )
938        {
939          const Window &conf = pcPic->getConformanceWindow();
940          const Window &defDisp = m_respectDefDispWindow ? pcPic->getDefDisplayWindow() : Window();
941#if REPN_FORMAT_IN_VPS
942          UInt chromaFormatIdc = pcPic->getSlice(0)->getChromaFormatIdc();
943          Int xScal =  TComSPS::getWinUnitX( chromaFormatIdc ), yScal = TComSPS::getWinUnitY( chromaFormatIdc );
944          m_acTVideoIOYuvReconFile[layerId].write( pcPic->getPicYuvRec(),
945            conf.getWindowLeftOffset()  *xScal + defDisp.getWindowLeftOffset(),
946            conf.getWindowRightOffset() *xScal + defDisp.getWindowRightOffset(),
947            conf.getWindowTopOffset()   *yScal + defDisp.getWindowTopOffset(),
948            conf.getWindowBottomOffset()*yScal + defDisp.getWindowBottomOffset() );
949
[313]950#else
[442]951          m_acTVideoIOYuvReconFile[layerId].write( pcPic->getPicYuvRec(),
952            conf.getWindowLeftOffset() + defDisp.getWindowLeftOffset(),
953            conf.getWindowRightOffset() + defDisp.getWindowRightOffset(),
954            conf.getWindowTopOffset() + defDisp.getWindowTopOffset(),
955            conf.getWindowBottomOffset() + defDisp.getWindowBottomOffset() );
[313]956#endif
[442]957        }
958
959        // update POC of display order
960        m_aiPOCLastDisplay[layerId] = pcPic->getPOC();
961#else
962        if ( m_pchReconFile )
963        {
964          const Window &conf = pcPic->getConformanceWindow();
965          const Window &defDisp = m_respectDefDispWindow ? pcPic->getDefDisplayWindow() : Window();
966          m_cTVideoIOYuvReconFile.write( pcPic->getPicYuvRec(),
967            conf.getWindowLeftOffset() + defDisp.getWindowLeftOffset(),
968            conf.getWindowRightOffset() + defDisp.getWindowRightOffset(),
969            conf.getWindowTopOffset() + defDisp.getWindowTopOffset(),
970            conf.getWindowBottomOffset() + defDisp.getWindowBottomOffset() );
971        }
972
973        // update POC of display order
974        m_iPOCLastDisplay = pcPic->getPOC();
975#endif
976
977        // erase non-referenced picture in the reference picture list after display
978        if ( !pcPic->getSlice(0)->isReferenced() && pcPic->getReconMark() == true )
979        {
[313]980#if !DYN_REF_FREE
[442]981          pcPic->setReconMark(false);
982
983          // mark it should be extended later
984          pcPic->getPicYuvRec()->setBorderExtension( false );
985
[313]986#else
[442]987          pcPic->destroy();
988          pcListPic->erase( iterPic );
989          iterPic = pcListPic->begin(); // to the beginning, non-efficient way, have to be revised!
990          continue;
[313]991#endif
[442]992        }
993        pcPic->setOutputMark(false);
[313]994      }
995#if !SVC_EXTENSION
996#if !DYN_REF_FREE
[442]997      if(pcPic)
998      {
999        pcPic->destroy();
1000        delete pcPic;
1001        pcPic = NULL;
1002      }
[313]1003#endif
[494]1004#endif
[442]1005      iterPic++;
1006    }
[313]1007  }
1008#if SVC_EXTENSION
1009  m_aiPOCLastDisplay[layerId] = -MAX_INT;
1010#else
1011  pcListPic->clear();
1012  m_iPOCLastDisplay = -MAX_INT;
1013#endif
1014}
1015
1016/** \param nalu Input nalu to check whether its LayerId is within targetDecLayerIdSet
1017 */
1018Bool TAppDecTop::isNaluWithinTargetDecLayerIdSet( InputNALUnit* nalu )
1019{
1020  if ( m_targetDecLayerIdSet.size() == 0 ) // By default, the set is empty, meaning all LayerIds are allowed
1021  {
1022    return true;
1023  }
1024  for (std::vector<Int>::iterator it = m_targetDecLayerIdSet.begin(); it != m_targetDecLayerIdSet.end(); it++)
1025  {
1026    if ( nalu->m_reservedZero6Bits == (*it) )
1027    {
1028      return true;
1029    }
1030  }
1031  return false;
1032}
[612]1033#if ALIGNED_BUMPING
1034// Function outputs a picture, and marks it as not needed for output.
1035Void TAppDecTop::xOutputAndMarkPic( TComPic *pic, const Char *reconFile, const Int layerIdx, Int &pocLastDisplay, DpbStatus &dpbStatus )
1036{
1037  if ( reconFile )
1038  {
1039    const Window &conf = pic->getConformanceWindow();
1040    const Window &defDisp = m_respectDefDispWindow ? pic->getDefDisplayWindow() : Window();
1041    Int xScal =  1, yScal = 1;
[626]1042#if REPN_FORMAT_IN_VPS
[612]1043    UInt chromaFormatIdc = pic->getSlice(0)->getChromaFormatIdc();
1044    xScal = TComSPS::getWinUnitX( chromaFormatIdc );
1045    yScal = TComSPS::getWinUnitY( chromaFormatIdc );
1046#endif
1047    m_acTVideoIOYuvReconFile[layerIdx].write( pic->getPicYuvRec(),
1048      conf.getWindowLeftOffset()  * xScal + defDisp.getWindowLeftOffset(),
1049      conf.getWindowRightOffset() * xScal + defDisp.getWindowRightOffset(),
1050      conf.getWindowTopOffset()   * yScal + defDisp.getWindowTopOffset(),
1051      conf.getWindowBottomOffset()* yScal + defDisp.getWindowBottomOffset() );
1052  }
1053  // update POC of display order
1054  pocLastDisplay = pic->getPOC();
[313]1055
[612]1056  // Mark as not needed for output
1057  pic->setOutputMark(false);
1058
1059  // "erase" non-referenced picture in the reference picture list after display
1060  if ( !pic->getSlice(0)->isReferenced() && pic->getReconMark() == true )
1061  {
1062    pic->setReconMark(false);
1063
1064    // mark it should be extended later
1065    pic->getPicYuvRec()->setBorderExtension( false );
1066
1067    dpbStatus.m_numPicsInLayer[layerIdx]--;
1068  }
1069}
1070
1071Void TAppDecTop::flushAllPictures(Int layerId, Bool outputPictures)
1072{
1073  // First "empty" all pictures that are not used for reference and not needed for output
1074  emptyUnusedPicturesNotNeededForOutput();
1075
1076  if( outputPictures )  // All pictures in the DPB in that layer are to be output; this means other pictures would also be output
1077  {
1078    std::vector<Int>  listOfPocs;
1079    std::vector<Int>  listOfPocsInEachLayer[MAX_LAYERS];
1080    std::vector<Int>  listOfPocsPositionInEachLayer[MAX_LAYERS];
1081    DpbStatus dpbStatus;
1082
1083    // Find the status of the DPB
1084    xFindDPBStatus(listOfPocs, listOfPocsInEachLayer, listOfPocsPositionInEachLayer, dpbStatus);
1085
1086    if( listOfPocs.size() )
1087    {
1088      while( listOfPocsInEachLayer[layerId].size() )    // As long as there picture in the layer to be output
1089      {
1090        bumpingProcess( listOfPocs, listOfPocsInEachLayer, listOfPocsPositionInEachLayer, dpbStatus );
1091      }
1092    }
1093  }
1094
1095  // Now remove all pictures from the layer DPB?
1096  markAllPicturesAsErased(layerId);
1097}
1098Void TAppDecTop::flushAllPictures(Bool outputPictures)
1099{
1100  // First "empty" all pictures that are not used for reference and not needed for output
1101  emptyUnusedPicturesNotNeededForOutput();
1102
1103  if( outputPictures )  // All pictures in the DPB are to be output
1104  {
1105    std::vector<Int>  listOfPocs;
1106    std::vector<Int>  listOfPocsInEachLayer[MAX_LAYERS];
1107    std::vector<Int>  listOfPocsPositionInEachLayer[MAX_LAYERS];
1108    DpbStatus dpbStatus;
1109
1110    // Find the status of the DPB
1111    xFindDPBStatus(listOfPocs, listOfPocsInEachLayer, listOfPocsPositionInEachLayer, dpbStatus);
1112
1113    while( dpbStatus.m_numAUsNotDisplayed )
1114    {
1115      bumpingProcess( listOfPocs, listOfPocsInEachLayer, listOfPocsPositionInEachLayer, dpbStatus );
1116    }
1117  }
1118
1119  // Now remove all pictures from the DPB?
1120  markAllPicturesAsErased();
1121}
1122
1123Void TAppDecTop::markAllPicturesAsErased()
1124{
1125  for(Int i = 0; i < MAX_LAYERS; i++)
1126  {
1127    m_acTDecTop[i].getListPic()->clear();
1128  }
1129}
1130
1131Void TAppDecTop::markAllPicturesAsErased(Int layerIdx)
1132{
1133  m_acTDecTop[layerIdx].getListPic()->clear();
1134}
1135
1136Void TAppDecTop::checkOutputBeforeDecoding(Int layerIdx)
1137{
1138   
1139  std::vector<Int>  listOfPocs;
1140  std::vector<Int>  listOfPocsInEachLayer[MAX_LAYERS];
1141  std::vector<Int>  listOfPocsPositionInEachLayer[MAX_LAYERS];
1142  DpbStatus dpbStatus;
1143
1144  // First "empty" all pictures that are not used for reference and not needed for output
1145  emptyUnusedPicturesNotNeededForOutput();
1146
1147  // Find the status of the DPB
1148  xFindDPBStatus(listOfPocs, listOfPocsInEachLayer, listOfPocsPositionInEachLayer, dpbStatus);
1149
1150  // If not picture to be output, return
1151  if( listOfPocs.size() == 0 )
1152  {
1153    return;
1154  }
1155
1156  // Find DPB-information from the VPS
1157  DpbStatus maxDpbLimit;
[619]1158  Int targetLsIdx, subDpbIdx;
[612]1159  TComVPS *vps = findDpbParametersFromVps(listOfPocs, listOfPocsInEachLayer, listOfPocsPositionInEachLayer, maxDpbLimit);
[619]1160  if( getCommonDecoderParams()->getTargetOutputLayerSetIdx() == 0 )
1161  {
1162    targetLsIdx = 0;
1163    subDpbIdx   = 0; 
1164  }
1165  else
1166  {
1167    targetLsIdx = vps->getOutputLayerSetIdx( getCommonDecoderParams()->getTargetOutputLayerSetIdx() );
1168    subDpbIdx   = vps->getSubDpbAssigned( targetLsIdx, layerIdx );
1169  }
[612]1170  // Assume that listOfPocs is sorted in increasing order - if not have to sort it.
1171  while( ifInvokeBumpingBeforeDecoding(dpbStatus, maxDpbLimit, layerIdx, subDpbIdx) )
1172  {
1173    bumpingProcess( listOfPocs, listOfPocsInEachLayer, listOfPocsPositionInEachLayer, dpbStatus );
1174  } 
1175}
1176
1177Void TAppDecTop::checkOutputAfterDecoding()
1178{   
1179  std::vector<Int>  listOfPocs;
1180  std::vector<Int>  listOfPocsInEachLayer[MAX_LAYERS];
1181  std::vector<Int>  listOfPocsPositionInEachLayer[MAX_LAYERS];
1182  DpbStatus dpbStatus;
1183
1184  // First "empty" all pictures that are not used for reference and not needed for output
1185  emptyUnusedPicturesNotNeededForOutput();
1186
1187  // Find the status of the DPB
1188  xFindDPBStatus(listOfPocs, listOfPocsInEachLayer, listOfPocsPositionInEachLayer, dpbStatus);
1189
1190  // If not picture to be output, return
1191  if( listOfPocs.size() == 0 )
1192  {
1193    return;
1194  }
1195
1196  // Find DPB-information from the VPS
1197  DpbStatus maxDpbLimit;
1198  findDpbParametersFromVps(listOfPocs, listOfPocsInEachLayer, listOfPocsPositionInEachLayer, maxDpbLimit);
1199
1200  // Assume that listOfPocs is sorted in increasing order - if not have to sort it.
1201  while( ifInvokeBumpingAfterDecoding(dpbStatus, maxDpbLimit) )
1202  {
1203    bumpingProcess( listOfPocs, listOfPocsInEachLayer, listOfPocsPositionInEachLayer, dpbStatus );
1204  } 
1205}
1206
1207Void TAppDecTop::bumpingProcess(std::vector<Int> &listOfPocs, std::vector<Int> *listOfPocsInEachLayer, std::vector<Int> *listOfPocsPositionInEachLayer, DpbStatus &dpbStatus)
1208{
1209  // Choose the smallest POC value
1210  Int pocValue = *(listOfPocs.begin());
1211  std::vector<int>::iterator it;
1212  TComList<TComPic*>::iterator iterPic;
1213  for( Int layerIdx = 0; layerIdx < dpbStatus.m_numLayers; layerIdx++)
1214  {
1215    // Check if picture with pocValue is present.
1216    it = find( listOfPocsInEachLayer[layerIdx].begin(), listOfPocsInEachLayer[layerIdx].end(), pocValue );
1217    if( it != listOfPocsInEachLayer[layerIdx].end() )  // picture found.
1218    {
1219      Int picPosition = std::distance( listOfPocsInEachLayer[layerIdx].begin(), it );
1220      Int j;
1221      for(j = 0, iterPic = m_acTDecTop[layerIdx].getListPic()->begin(); j < listOfPocsPositionInEachLayer[layerIdx][picPosition]; j++) // Picture to be output
1222      {
1223        iterPic++;
1224      }
1225      TComPic *pic = *iterPic;
1226
1227      xOutputAndMarkPic( pic, m_pchReconFile[layerIdx], layerIdx, m_aiPOCLastDisplay[layerIdx], dpbStatus );
1228
1229      listOfPocsInEachLayer[layerIdx].erase( it );
1230      listOfPocsPositionInEachLayer[layerIdx].erase( listOfPocsPositionInEachLayer[layerIdx].begin() + picPosition );
1231    }
1232  }
1233  // Update sub-DPB status
1234  for( Int subDpbIdx = 0; subDpbIdx < dpbStatus.m_numSubDpbs; subDpbIdx++)
1235  {
1236    dpbStatus.m_numPicsInSubDpb[subDpbIdx]--;
1237  }
1238  dpbStatus.m_numAUsNotDisplayed--;   
1239
1240  // Remove the picture from the listOfPocs
1241  listOfPocs.erase( listOfPocs.begin() );
1242}
1243
1244TComVPS *TAppDecTop::findDpbParametersFromVps(std::vector<Int> const &listOfPocs, std::vector<Int> const *listOfPocsInEachLayer, std::vector<Int> const *listOfPocsPositionInEachLayer, DpbStatus &maxDpbLimit)
1245{
[619]1246  Int targetOutputLsIdx = getCommonDecoderParams()->getTargetOutputLayerSetIdx();
[627]1247  TComVPS *vps = NULL;
[619]1248
1249  if( targetOutputLsIdx == 0 )   // Only base layer is output
[612]1250  {
[619]1251    TComSPS *sps = NULL;
1252    assert( listOfPocsInEachLayer[0].size() != 0 );
1253    TComList<TComPic*>::iterator iterPic;
1254    Int j;
1255    for(j = 0, iterPic = m_acTDecTop[0].getListPic()->begin(); j < listOfPocsPositionInEachLayer[0][0]; j++) // Picture to be output
[612]1256    {
[619]1257      iterPic++;
[612]1258    }
[619]1259    TComPic *pic = *iterPic;
1260    sps = pic->getSlice(0)->getSPS();   assert( sps->getLayerId() == 0 );
1261    vps = pic->getSlice(0)->getVPS();
1262    Int highestTId = sps->getMaxTLayers() - 1;
1263
1264    maxDpbLimit.m_numAUsNotDisplayed = sps->getNumReorderPics( highestTId ); // m_numAUsNotDisplayed is only variable name - stores reorderpics
1265    maxDpbLimit.m_maxLatencyIncrease = sps->getMaxLatencyIncrease( highestTId ) > 0;
1266    if( maxDpbLimit.m_maxLatencyIncrease )
[612]1267    {
[619]1268      maxDpbLimit.m_maxLatencyPictures = sps->getMaxLatencyIncrease( highestTId ) + sps->getNumReorderPics( highestTId ) - 1;
1269    }
1270    maxDpbLimit.m_numPicsInLayer[0] = sps->getMaxDecPicBuffering( highestTId );
1271    maxDpbLimit.m_numPicsInSubDpb[0] = sps->getMaxDecPicBuffering( highestTId );
1272  }
1273  else
1274  {
1275    // -------------------------------------
1276    // Find the VPS used for the pictures
1277    // -------------------------------------
1278    for(Int i = 0; i < MAX_LAYERS; i++)
1279    {
1280      if( m_acTDecTop[i].getListPic()->empty() )
[612]1281      {
[619]1282        assert( listOfPocsInEachLayer[i].size() == 0 );
1283        continue;
[612]1284      }
[619]1285      std::vector<Int>::const_iterator it;
1286      it = find( listOfPocsInEachLayer[i].begin(), listOfPocsInEachLayer[i].end(), listOfPocs[0] );
1287      TComList<TComPic*>::iterator iterPic;
1288      if( it != listOfPocsInEachLayer[i].end() )
1289      {
1290        Int picPosition = std::distance( listOfPocsInEachLayer[i].begin(), it );
1291        Int j;
1292        for(j = 0, iterPic = m_acTDecTop[i].getListPic()->begin(); j < listOfPocsPositionInEachLayer[i][picPosition]; j++) // Picture to be output
1293        {
1294          iterPic++;
1295        }
1296        TComPic *pic = *iterPic;
1297        vps = pic->getSlice(0)->getVPS();
1298        break;
1299      }
[612]1300    }
1301
[619]1302    Int targetLsIdx       = vps->getOutputLayerSetIdx( getCommonDecoderParams()->getTargetOutputLayerSetIdx() );
1303    Int highestTId = vps->getMaxTLayers() - 1;
1304
1305    maxDpbLimit.m_numAUsNotDisplayed = vps->getMaxVpsNumReorderPics( targetOutputLsIdx, highestTId ); // m_numAUsNotDisplayed is only variable name - stores reorderpics
1306    maxDpbLimit.m_maxLatencyIncrease  = vps->getMaxVpsLatencyIncreasePlus1(targetOutputLsIdx, highestTId ) > 0;
1307    if( maxDpbLimit.m_maxLatencyIncrease )
1308    {
1309      maxDpbLimit.m_maxLatencyPictures = vps->getMaxVpsNumReorderPics( targetOutputLsIdx, highestTId ) + vps->getMaxVpsLatencyIncreasePlus1(targetOutputLsIdx, highestTId ) - 1;
1310    }
1311    for(Int i = 0; i < vps->getNumLayersInIdList( targetLsIdx ); i++)
1312    {
1313      maxDpbLimit.m_numPicsInLayer[i] = vps->getMaxVpsLayerDecPicBuffMinus1( targetOutputLsIdx, i, highestTId ) + 1;
1314      maxDpbLimit.m_numPicsInSubDpb[vps->getSubDpbAssigned( targetLsIdx, i )] = vps->getMaxVpsDecPicBufferingMinus1( targetOutputLsIdx, vps->getSubDpbAssigned( targetLsIdx, i ), highestTId) + 1;
1315    }
1316    // -------------------------------------
[612]1317  }
1318  return vps;
1319}
1320Void TAppDecTop::emptyUnusedPicturesNotNeededForOutput()
1321{
1322  for(Int layerIdx = 0; layerIdx < MAX_LAYERS; layerIdx++)
1323  {
1324    TComList <TComPic*> *pcListPic = m_acTDecTop[layerIdx].getListPic();
1325    TComList<TComPic*>::iterator iterPic = pcListPic->begin();
1326    while ( iterPic != pcListPic->end() )
1327    {
1328      TComPic *pic = *iterPic;
1329      if( !pic->getSlice(0)->isReferenced() && !pic->getOutputMark() )
1330      {
1331        // Emtpy the picture buffer
1332        pic->setReconMark( false );
1333      }
1334      iterPic++;
1335    }
1336  }
1337}
1338
1339Bool TAppDecTop::ifInvokeBumpingBeforeDecoding( const DpbStatus &dpbStatus, const DpbStatus &dpbLimit, const Int layerIdx, const Int subDpbIdx )
1340{
1341  Bool retVal = false;
1342  // Number of reorder picutres
1343  retVal |= ( dpbStatus.m_numAUsNotDisplayed > dpbLimit.m_numAUsNotDisplayed );
1344
1345  // Number of pictures in each sub-DPB
1346  retVal |= ( dpbStatus.m_numPicsInSubDpb[subDpbIdx] >= dpbLimit.m_numPicsInSubDpb[subDpbIdx] );
1347 
1348  // Number of pictures in each layer
1349  retVal |= ( dpbStatus.m_numPicsInLayer[layerIdx] >= dpbLimit.m_numPicsInLayer[layerIdx]);
1350
1351  return retVal;
1352}
1353
1354Bool TAppDecTop::ifInvokeBumpingAfterDecoding( const DpbStatus &dpbStatus, const DpbStatus &dpbLimit )
1355{
1356  Bool retVal = false;
1357
1358  // Number of reorder picutres
1359  retVal |= ( dpbStatus.m_numAUsNotDisplayed > dpbLimit.m_numAUsNotDisplayed );
1360
1361  return retVal;
1362}
1363
1364Void TAppDecTop::xFindDPBStatus( std::vector<Int> &listOfPocs
1365                            , std::vector<Int> *listOfPocsInEachLayer
1366                            , std::vector<Int> *listOfPocsPositionInEachLayer
1367                            , DpbStatus &dpbStatus
1368                            )
1369{
1370  TComVPS *vps = NULL;
1371  dpbStatus.init();
1372  for( Int i = 0; i < MAX_LAYERS; i++ )
1373  {
1374    if( m_acTDecTop[i].getListPic()->empty() )
1375    {
1376      continue;
1377    }
1378   
1379    // To check # AUs that have at least one picture not output,
1380    // For each layer, populate listOfPOcs if not already present
1381    TComList<TComPic*>::iterator iterPic = m_acTDecTop[i].getListPic()->begin();
1382    Int picPositionInList = 0;
1383    while (iterPic != m_acTDecTop[i].getListPic()->end())
1384    {
1385      TComPic* pic = *(iterPic);
1386      if( pic->getReconMark() )
1387      {
1388        if( vps == NULL )
1389        {
1390          vps = pic->getSlice(0)->getVPS();
1391        }
1392
1393        std::vector<Int>::iterator it;
1394        if( pic->getOutputMark() ) // && pic->getPOC() > m_aiPOCLastDisplay[i])
1395        {
1396          it = find( listOfPocs.begin(), listOfPocs.end(), pic->getPOC() ); // Check if already included
1397          if( it == listOfPocs.end() )  // New POC value - i.e. new AU - add to the list
1398          {
1399            listOfPocs.push_back( pic->getPOC() );
1400          }
1401          listOfPocsInEachLayer         [i].push_back( pic->getPOC()    );    // POC to be output in each layer
1402          listOfPocsPositionInEachLayer [i].push_back( picPositionInList  );  // For ease of access
1403        }
1404        if( pic->getSlice(0)->isReferenced() || pic->getOutputMark() )
1405        {
1406          dpbStatus.m_numPicsInLayer[i]++;  // Count pictures that are "used for reference" or "needed for output"
1407        }
1408      }
1409      iterPic++;
1410      picPositionInList++;
1411    }
1412  }
1413
1414  assert( vps != NULL );    // No picture in any DPB?
1415  std::sort( listOfPocs.begin(), listOfPocs.end() );    // Sort in increasing order of POC
1416  Int targetLsIdx = vps->getOutputLayerSetIdx( getCommonDecoderParams()->getTargetOutputLayerSetIdx() );
1417  // Update status
1418  dpbStatus.m_numAUsNotDisplayed = listOfPocs.size();   // Number of AUs not displayed
[619]1419  dpbStatus.m_numLayers = vps->getNumLayersInIdList( targetLsIdx );
[612]1420  dpbStatus.m_numSubDpbs = vps->getNumSubDpbs( vps->getOutputLayerSetIdx(
1421                                                      this->getCommonDecoderParams()->getTargetOutputLayerSetIdx() ) );
1422
1423  for(Int i = 0; i < dpbStatus.m_numLayers; i++)
1424  {
1425    dpbStatus.m_numPicsNotDisplayedInLayer[i] = listOfPocsInEachLayer[i].size();
1426    dpbStatus.m_numPicsInSubDpb[vps->getSubDpbAssigned(targetLsIdx,i)] += dpbStatus.m_numPicsInLayer[i];
1427  }
1428  assert( dpbStatus.m_numAUsNotDisplayed != -1 );
1429
1430
1431} 
1432#endif
[313]1433//! \}
Note: See TracBrowser for help on using the repository browser.