source: 3DVCSoftware/branches/HTM-15.0-dev0/source/Lib/TLibCommon/TComPic.cpp @ 1317

Last change on this file since 1317 was 1317, checked in by tech, 9 years ago

Clean-ups. HLS.

  • Property svn:eol-style set to native
File size: 28.0 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-2015, 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     TComPic.cpp
35    \brief    picture class
36*/
37
38#include "TComPic.h"
39#include "SEI.h"
40
41//! \ingroup TLibCommon
42//! \{
43
44// ====================================================================================================================
45// Constructor / destructor / create / destroy
46// ====================================================================================================================
47
48TComPic::TComPic()
49: m_uiTLayer                              (0)
50, m_bUsedByCurr                           (false)
51, m_bIsLongTerm                           (false)
52, m_pcPicYuvPred                          (NULL)
53, m_pcPicYuvResi                          (NULL)
54, m_bReconstructed                        (false)
55, m_bNeededForOutput                      (false)
56, m_uiCurrSliceIdx                        (0)
57, m_bCheckLTMSB                           (false)
58#if NH_MV
59, m_layerId                               (0)
60, m_viewId                                (0)
61, m_bPicOutputFlag                        (false)
62#if NH_3D
63, m_viewIndex                             (0)
64, m_isDepth                               (false)
65, m_aaiCodedScale                         (0)
66, m_aaiCodedOffset                        (0)
67#endif
68#endif
69
70{
71  for(UInt i=0; i<NUM_PIC_YUV; i++)
72  {
73    m_apcPicYuv[i]      = NULL;
74  }
75#if NH_3D_QTLPC
76  m_bReduceBitsQTL    = 0;
77#endif
78#if NH_3D_NBDV
79  m_iNumDdvCandPics   = 0;
80  m_eRapRefList       = REF_PIC_LIST_0;
81  m_uiRapRefIdx       = 0;
82#endif
83#if NH_MV
84  m_isPocResettingPic = false;   
85  m_hasGeneratedRefPics = false; 
86  m_isFstPicOfAllLayOfPocResetPer = false; 
87  m_decodingOrder     = 0; 
88  m_noRaslOutputFlag  = false; 
89  m_noClrasOutputFlag = false; 
90  m_picLatencyCount   = 0; 
91  m_isGenerated       = false;
92  m_isGeneratedCl833  = false; 
93  m_activatesNewVps   = false; 
94#endif
95}
96
97TComPic::~TComPic()
98{
99}
100
101Void TComPic::create( const TComSPS &sps, const TComPPS &pps, const Bool bIsVirtual)
102{
103  const ChromaFormat chromaFormatIDC = sps.getChromaFormatIdc();
104  const Int          iWidth          = sps.getPicWidthInLumaSamples();
105  const Int          iHeight         = sps.getPicHeightInLumaSamples();
106  const UInt         uiMaxCuWidth    = sps.getMaxCUWidth();
107  const UInt         uiMaxCuHeight   = sps.getMaxCUHeight();
108  const UInt         uiMaxDepth      = sps.getMaxTotalCUDepth();
109
110  m_picSym.create( sps, pps, uiMaxDepth );
111  if (!bIsVirtual)
112  {
113    m_apcPicYuv[PIC_YUV_ORG    ]   = new TComPicYuv;  m_apcPicYuv[PIC_YUV_ORG     ]->create( iWidth, iHeight, chromaFormatIDC, uiMaxCuWidth, uiMaxCuHeight, uiMaxDepth, true );
114    m_apcPicYuv[PIC_YUV_TRUE_ORG]  = new TComPicYuv;  m_apcPicYuv[PIC_YUV_TRUE_ORG]->create( iWidth, iHeight, chromaFormatIDC, uiMaxCuWidth, uiMaxCuHeight, uiMaxDepth, true );
115  }
116  m_apcPicYuv[PIC_YUV_REC]  = new TComPicYuv;  m_apcPicYuv[PIC_YUV_REC]->create( iWidth, iHeight, chromaFormatIDC, uiMaxCuWidth, uiMaxCuHeight, uiMaxDepth, true );
117
118  // there are no SEI messages associated with this picture initially
119  if (m_SEIs.size() > 0)
120  {
121    deleteSEIs (m_SEIs);
122  }
123  m_bUsedByCurr = false;
124
125#if H_3D_FCO
126/* initialize the texture to depth reference status */
127  for (int j=0; j<2; j++)
128  {
129      for (int i=0; i<MAX_NUM_REF; i++)
130      {
131          m_aiTexToDepRef[j][i] = -1;
132      }
133  }
134#endif
135
136}
137
138Void TComPic::destroy()
139{
140  m_picSym.destroy();
141
142  for(UInt i=0; i<NUM_PIC_YUV; i++)
143  {
144    if (m_apcPicYuv[i])
145    {
146      m_apcPicYuv[i]->destroy();
147      delete m_apcPicYuv[i];
148      m_apcPicYuv[i]  = NULL;
149    }
150  }
151
152  deleteSEIs(m_SEIs);
153}
154#if NH_3D
155#if NH_3D_ARP
156Void TComPic::getCUAddrAndPartIdx( Int iX, Int iY, Int& riCuAddr, Int& riAbsZorderIdx )
157{
158  Int iMaxCUWidth   = (Int) ( getPicSym()->getSPS().getMaxCUWidth()  );
159  Int iMaxCuHeight  = (Int) ( getPicSym()->getSPS().getMaxCUHeight() );
160
161  UInt uiMaxTotalCUDepth = getPicSym()->getSPS().getMaxTotalCUDepth(); 
162  Int iBaseUnitWidth  = iMaxCUWidth >> uiMaxTotalCUDepth;
163  Int iBaseUnitHeight = iMaxCUWidth >> uiMaxTotalCUDepth;
164
165  Int iNumCuInWidth   = getPicYuvRec()->getWidth(COMPONENT_Y) / iMaxCUWidth;
166  iNumCuInWidth      += ( getPicYuvRec()->getWidth(COMPONENT_Y) % iMaxCUWidth ) ? 1 : 0;
167
168
169  Int iCuX            = iX / iMaxCUWidth;
170  Int iCuY            = iY / iMaxCuHeight;
171  Int iBaseX          = ( iX - iCuX * iMaxCUWidth  ) / iBaseUnitWidth;
172  Int iBaseY          = ( iY - iCuY * iMaxCuHeight ) / iBaseUnitHeight;
173  Int iCuSizeInBases  = iMaxCuHeight                 / iBaseUnitWidth;
174
175  riCuAddr            = iCuY   * iNumCuInWidth + iCuX;
176  Int iRastPartIdx    = iBaseY * iCuSizeInBases  + iBaseX;
177  riAbsZorderIdx      = g_auiRasterToZscan[ iRastPartIdx ];
178}
179#endif
180Void TComPic::compressMotion(Int scale)
181#else
182Void TComPic::compressMotion()
183#endif
184{
185  TComPicSym* pPicSym = getPicSym();
186  for ( UInt uiCUAddr = 0; uiCUAddr < pPicSym->getNumberOfCtusInFrame(); uiCUAddr++ )
187  {
188    TComDataCU* pCtu = pPicSym->getCtu(uiCUAddr);
189#if NH_3D
190    pCtu->compressMV(scale); 
191#else
192    pCtu->compressMV();
193#endif
194   
195  }
196}
197
198
199Bool  TComPic::getSAOMergeAvailability(Int currAddr, Int mergeAddr)
200{
201  Bool mergeCtbInSliceSeg = (mergeAddr >= getPicSym()->getCtuTsToRsAddrMap(getCtu(currAddr)->getSlice()->getSliceCurStartCtuTsAddr()));
202  Bool mergeCtbInTile     = (getPicSym()->getTileIdxMap(mergeAddr) == getPicSym()->getTileIdxMap(currAddr));
203  return (mergeCtbInSliceSeg && mergeCtbInTile);
204}
205
206UInt TComPic::getSubstreamForCtuAddr(const UInt ctuAddr, const Bool bAddressInRaster, TComSlice *pcSlice)
207{
208  UInt subStrm;
209  const bool bWPPEnabled=pcSlice->getPPS()->getEntropyCodingSyncEnabledFlag();
210  const TComPicSym &picSym            = *(getPicSym());
211
212  if ((bWPPEnabled && picSym.getFrameHeightInCtus()>1) || (picSym.getNumTiles()>1)) // wavefronts, and possibly tiles being used.
213  {
214    if (bWPPEnabled)
215    {
216      const UInt ctuRsAddr                = bAddressInRaster?ctuAddr : picSym.getCtuTsToRsAddrMap(ctuAddr);
217      const UInt frameWidthInCtus         = picSym.getFrameWidthInCtus();
218      const UInt tileIndex                = picSym.getTileIdxMap(ctuRsAddr);
219      const UInt numTileColumns           = (picSym.getNumTileColumnsMinus1()+1);
220      const TComTile *pTile               = picSym.getTComTile(tileIndex);
221      const UInt firstCtuRsAddrOfTile     = pTile->getFirstCtuRsAddr();
222      const UInt tileYInCtus              = firstCtuRsAddrOfTile / frameWidthInCtus;
223      // independent tiles => substreams are "per tile"
224      const UInt ctuLine                  = ctuRsAddr / frameWidthInCtus;
225      const UInt startingSubstreamForTile =(tileYInCtus*numTileColumns) + (pTile->getTileHeightInCtus()*(tileIndex%numTileColumns));
226      subStrm = startingSubstreamForTile + (ctuLine - tileYInCtus);
227    }
228    else
229    {
230      const UInt ctuRsAddr                = bAddressInRaster?ctuAddr : picSym.getCtuTsToRsAddrMap(ctuAddr);
231      const UInt tileIndex                = picSym.getTileIdxMap(ctuRsAddr);
232      subStrm=tileIndex;
233    }
234  }
235  else
236  {
237    // dependent tiles => substreams are "per frame".
238    subStrm = 0;
239  }
240  return subStrm;
241}
242
243#if NH_MV
244Bool TComPic::getPocResetPeriodId()
245{
246  return getSlice(0)->getPocResetIdc(); 
247}
248
249Void TComPic::markAsUsedForShortTermReference()
250{
251  getSlice(0)->setReferenced( true );
252  setIsLongTerm( false ); 
253}
254
255Void TComPic::markAsUsedForLongTermReference()
256{
257  getSlice(0)->setReferenced( true );
258  setIsLongTerm( true ); 
259}
260
261
262Void TComPic::markAsUnusedForReference()
263{
264  getSlice(0)->setReferenced( false );
265  setIsLongTerm( false ); 
266}
267
268
269Bool TComPic::getMarkedUnUsedForReference()
270{
271  return !getSlice(0)->isReferenced( );
272}
273
274
275Bool TComPic::getMarkedAsShortTerm()
276{
277  return ( getSlice(0)->isReferenced( ) && !getIsLongTerm() );
278}
279
280Void TComPic::print( Int outputLevel )
281{
282  if ( outputLevel== 0  )
283  {
284    std::cout  << std::endl
285      << "LId"
286      << "\t" << "POC"
287      << "\t" << "Rec"
288      << "\t" << "Ref"
289      << "\t" << "LT"
290      << "\t" << "OutMark"
291      << "\t" << "OutFlag" 
292      << "\t" << "Type"
293      << "\t" << "PReFlag"
294      << std::endl;
295  }
296  else if( outputLevel == 1  )
297  {
298    std::cout  << getLayerId()
299      << "\t" << getPOC()
300      << "\t" << getReconMark()
301      << "\t" << getSlice(0)->isReferenced()
302      << "\t" << getIsLongTerm()
303      << "\t" << getOutputMark()
304      << "\t" << getSlice(0)->getPicOutputFlag()
305      << "\t" << getSlice(0)->getNalUnitTypeString()
306      << "\t" << getSlice(0)->getPocResetFlag() 
307      << std::endl;
308  }
309  else if ( outputLevel == 2  )
310  {
311    std::cout  << std:: setfill(' ')
312      << " LayerId: "         << std::setw(2) << getLayerId()
313      << "\t"  << " POC: "             << std::setw(5) << getPOC()
314      << "\t"  << " Dec. Order: "      << std::setw(5) << getDecodingOrder()
315      << "\t"  << " Referenced: "      << std::setw(1) << getSlice(0)->isReferenced()
316      << "\t"  << " Pic type: "        <<                 getSlice(0)->getNalUnitTypeString()
317      << "\t"  << " Generated: "       << std::setw(1) << getIsGenerated()
318      << "\t"  << " Gen. Ref. Pics: "  << std::setw(1) << getHasGeneratedRefPics();
319  }
320  else if ( outputLevel == 4  )
321  {
322    std::cout  << std:: setfill(' ')
323      << " LayerId: "         << std::setw(2) << getLayerId()
324      << "\t"  << " POC: "             << std::setw(5) << getPOC()     
325      << "\t"  << " Referenced: "      << std::setw(1) << getSlice(0)->isReferenced() << std::endl; 
326  }
327}
328
329#if NH_3D
330Void TComPic::printMotion()
331{
332  TComPicSym* pPicSym = getPicSym();
333  for ( UInt uiCUAddr = 0; uiCUAddr < pPicSym->getNumberOfCtusInFrame(); uiCUAddr++ )
334  {
335    TComDataCU* pCtu = pPicSym->getCtu(uiCUAddr);
336    std::cout << "CUAddr " << uiCUAddr << std::endl; 
337    pCtu->printMV();
338    std::cout << std::endl; 
339  }
340}
341
342#if NH_3D_NBDV
343Int TComPic::getDisCandRefPictures(Int iColPOC)
344{
345  UInt       uiTempLayerCurr = 7;
346  TComSlice* currSlice       = getSlice(getCurrSliceIdx());
347  UInt       numDdvCandPics  = 0;
348
349  if(!currSlice->getEnableTMVPFlag())
350  {
351    return numDdvCandPics;
352  }
353
354  numDdvCandPics += 1;
355
356  UInt pocCurr = currSlice->getPOC();
357  UInt pocDiff = 255;
358
359  for(UInt lpNr = 0; lpNr < (currSlice->isInterB() ? 2: 1); lpNr++)
360  {
361    Bool x = lpNr ? currSlice->getColFromL0Flag() : 1 - currSlice->getColFromL0Flag();
362
363    for(UInt i = 0; i < currSlice->getNumRefIdx(RefPicList(x)); i++)
364    {
365      if(currSlice->getViewIndex() == currSlice->getRefPic((RefPicList)x, i)->getViewIndex() 
366         && (x == currSlice->getColFromL0Flag() || currSlice->getRefPOC((RefPicList)x, i) != iColPOC) && numDdvCandPics != 2)
367      {
368        TComSlice* refSlice    = currSlice->getRefPic((RefPicList)x, i)->getSlice(getCurrSliceIdx());
369        Bool       bRAP        = (refSlice->getViewIndex() && refSlice->isIRAP()) ? 1 : 0; 
370        UInt       uiTempLayer = currSlice->getRefPic((RefPicList)x, i)->getSlice(getCurrSliceIdx())->getTLayer(); 
371       
372        if(bRAP)
373        {
374          this->setRapRefIdx(i);
375          this->setRapRefList((RefPicList)x);
376          numDdvCandPics = 2;
377
378          return numDdvCandPics;
379        }
380        else if (uiTempLayerCurr > uiTempLayer) 
381        {
382           uiTempLayerCurr = uiTempLayer; 
383        }
384      }
385    }
386  }
387
388  UInt z   = -1; // GT: Added to make code compile needs to be checked!
389  UInt idx = 0;
390 
391  for(UInt lpNr = 0; lpNr < (currSlice->isInterB() ? 2 : 1); lpNr++)
392  {
393    Bool x = lpNr ? currSlice->getColFromL0Flag() : 1 - currSlice->getColFromL0Flag();
394   
395    for(UInt i = 0; i < currSlice->getNumRefIdx(RefPicList(x)); i++)
396    {
397      Int iTempPoc = currSlice->getRefPic((RefPicList)x, i)->getPOC();
398      Int iTempDiff = (iTempPoc > pocCurr) ? (iTempPoc - pocCurr) : (pocCurr - iTempPoc);
399     
400      if(currSlice->getViewIndex() == currSlice->getRefPic((RefPicList)x, i)->getViewIndex() && (x == currSlice->getColFromL0Flag() || currSlice->getRefPOC((RefPicList)x, i) != iColPOC) 
401         && currSlice->getRefPic((RefPicList)x, i)->getSlice(getCurrSliceIdx())->getTLayer() == uiTempLayerCurr && pocDiff > iTempDiff)
402      {
403        pocDiff = iTempDiff;
404        z       = x;
405        idx     = i;
406      }
407    }
408  }
409
410  if(pocDiff < 255)
411  {
412    this->setRapRefIdx(idx);
413    this->setRapRefList((RefPicList) z);
414    numDdvCandPics = 2;
415  }
416
417  return numDdvCandPics;
418}
419
420Void TComPic::checkTemporalIVRef()
421{
422  TComSlice* currSlice = getSlice(getCurrSliceIdx());
423  const Int numCandPics = this->getNumDdvCandPics();
424
425  for(Int curCandPic = 0; curCandPic < numCandPics; curCandPic++)
426  {
427    RefPicList eCurRefPicList   = REF_PIC_LIST_0 ;
428    Int        curCandPicRefIdx = 0;
429    if(curCandPic == 0) 
430    { 
431      eCurRefPicList   = RefPicList(currSlice->isInterB() ? 1 - currSlice->getColFromL0Flag() : 0);
432      curCandPicRefIdx = currSlice->getColRefIdx();
433    }
434    else                 
435    {
436      eCurRefPicList   = this->getRapRefList();
437      curCandPicRefIdx = this->getRapRefIdx();
438    }
439
440    TComPic* pcCandColPic = currSlice->getRefPic(eCurRefPicList, curCandPicRefIdx);
441    TComSlice* pcCandColSlice = pcCandColPic->getSlice(0); // currently only support single slice
442
443    if(!pcCandColSlice->isIntra())
444    {
445      for(Int iColRefDir = 0; iColRefDir < (pcCandColSlice->isInterB() ? 2 : 1); iColRefDir++)
446      {
447        for(Int iColRefIdx = 0; iColRefIdx < pcCandColSlice->getNumRefIdx((RefPicList)iColRefDir); iColRefIdx++)
448        {
449          m_abTIVRINCurrRL[curCandPic][iColRefDir][iColRefIdx] = false;
450          Int iColViewIdx    = pcCandColSlice->getViewIndex();
451#if H_3D_FIX_ARP_CHECK_NOT_IN_DPB
452          // The picture pcCandColSlice->getRefPic((RefPicList)iColRefDir, iColRefIdx) might not be in DPB anymore
453          // So don't access it directly.
454          Int iColRefViewIdx = pcCandColSlice->getVPS()->getViewOrderIdx( pcCandColSlice->getRefLayerId( (RefPicList)iColRefDir, iColRefIdx ) );       
455#else
456          Int iColRefViewIdx = pcCandColSlice->getRefPic((RefPicList)iColRefDir, iColRefIdx)->getViewIndex();
457#endif
458          if(iColViewIdx == iColRefViewIdx)
459          {
460            continue;
461          }
462
463          for(Int iCurrRefDir = 0; (iCurrRefDir < (currSlice->isInterB() ? 2 : 1)) && (m_abTIVRINCurrRL[curCandPic][iColRefDir][iColRefIdx] == false); iCurrRefDir++)
464          {
465            for(Int iCurrRefIdx = 0; iCurrRefIdx < currSlice->getNumRefIdx((RefPicList)iCurrRefDir); iCurrRefIdx++)
466            {
467              if(currSlice->getRefPic((RefPicList)iCurrRefDir, iCurrRefIdx)->getViewIndex() == iColRefViewIdx)
468              { 
469                m_abTIVRINCurrRL[curCandPic][iColRefDir][iColRefIdx] = true;
470                break;
471              }
472            }
473          }
474        }
475      }
476    }
477  }
478}
479
480Bool TComPic::isTempIVRefValid(Int currCandPic, Int iColRefDir, Int iColRefIdx)
481{
482  return m_abTIVRINCurrRL[currCandPic][iColRefDir][iColRefIdx];
483}
484
485Void TComPic::checkTextureRef()
486{
487  TComSlice* pcCurrSlice = getSlice(getCurrSliceIdx());
488  TComPic* pcTextPic = pcCurrSlice->getIvPic(0, getViewIndex());
489#if H_3D_FCO
490  if ( pcTextPic )
491  {
492#endif
493    TComSlice* pcTextSlice = pcTextPic->getSlice(0); // currently only support single slice
494
495    for(Int iTextRefDir = 0; (iTextRefDir < (pcTextSlice->isInterB() ? 2 :1) ) && !pcTextSlice->isIntra(); iTextRefDir++)
496    {
497      for(Int iTextRefIdx =0; iTextRefIdx < pcTextSlice->getNumRefIdx((RefPicList)iTextRefDir); iTextRefIdx++)
498      {
499        Int iTextRefPOC    = pcTextSlice->getRefPOC((RefPicList)iTextRefDir, iTextRefIdx);
500        Int iTextRefViewId = pcTextSlice->getRefPic((RefPicList)iTextRefDir, iTextRefIdx)->getViewIndex();
501        m_aiTexToDepRef[iTextRefDir][iTextRefIdx] = -1;
502        Int iCurrRefDir = iTextRefDir;
503
504        for(Int iCurrRefIdx = 0; (iCurrRefIdx<pcCurrSlice->getNumRefIdx((RefPicList)iCurrRefDir)) && (m_aiTexToDepRef[iTextRefDir][iTextRefIdx] < 0); iCurrRefIdx++)
505        {
506          if(pcCurrSlice->getRefPOC((RefPicList)iCurrRefDir, iCurrRefIdx ) == iTextRefPOC && 
507            pcCurrSlice->getRefPic((RefPicList)iCurrRefDir, iCurrRefIdx)->getViewIndex() == iTextRefViewId)
508          { 
509            m_aiTexToDepRef[iTextRefDir][iTextRefIdx] = iCurrRefIdx;           
510          }
511        }
512      }
513    }
514#if H_3D_FCO
515  }
516#endif
517}
518
519Int TComPic::isTextRefValid(Int iTextRefDir, Int iTextRefIdx)
520{
521  return m_aiTexToDepRef[iTextRefDir][iTextRefIdx];
522}
523#endif
524#endif
525
526Void TComAu::setPicLatencyCount( Int picLatenyCount )
527{
528  for(TComList<TComPic*>::iterator itP= begin();  itP!= end(); itP++)
529  {     
530    (*itP)->setPicLatencyCount( picLatenyCount ); 
531  }
532}
533
534TComPic* TComAu::getPic( Int nuhLayerId )
535{
536  TComPic* pic = NULL; 
537  for(TComList<TComPic*>::iterator itP= begin(); ( itP!= end() && (pic == NULL) ); itP++)
538  {     
539    if ( (*itP)->getLayerId() == nuhLayerId )
540    {
541      pic = (*itP); 
542    }
543  }
544  return pic;
545}
546
547Void TComAu::addPic( TComPic* pic, Bool pocUnkown )
548{
549  if ( !empty() )
550  {
551    if (!pocUnkown)
552    {
553      assert( pic->getPOC()   == ( getPoc() ));
554    }     
555    pic->setPicLatencyCount( getPicLatencyCount() ); 
556
557    assert( getPic( pic->getLayerId() ) == NULL );
558
559    // Add sorted
560    TComAu::iterator itP = begin(); 
561    Bool inserted = false; 
562    while( !inserted )
563    {
564      if ( ( itP == end()) || pic->getLayerId() < (*itP)->getLayerId() )
565      {
566        insert(itP, pic ); 
567        inserted = true; 
568      }
569      else
570      {
571        ++itP; 
572      }       
573    }     
574  } 
575  else
576  { 
577    pushBack( pic );     
578  }
579}
580
581Bool TComAu::containsPic( TComPic* pic )
582{
583  Bool isInList = false; 
584  for(TComList<TComPic*>::iterator itP= begin(); ( itP!= end() && (!isInList) ); itP++)
585  { 
586    isInList = isInList || ( pic == (*itP)); 
587  }
588  return isInList;
589}
590
591TComSubDpb::TComSubDpb( Int nuhLayerid )
592{
593  m_nuhLayerId = nuhLayerid;
594}
595
596TComPic* TComSubDpb::getPic( Int poc )
597{
598  TComPic* pic = NULL; 
599  for(TComList<TComPic*>::iterator itP= begin(); ( itP!= end() && (pic == NULL) ); itP++)
600  {     
601    if ( (*itP)->getPOC() == poc )
602    {
603      pic = (*itP); 
604    }
605  }
606  return pic;
607}
608
609TComPic* TComSubDpb::getPicFromLsb( Int pocLsb, Int maxPicOrderCntLsb )
610{
611  TComPic* pic = NULL; 
612  for(TComList<TComPic*>::iterator itP= begin(); ( itP!= end() && (pic == NULL) ); itP++)
613  {     
614    if ( ( (*itP)->getPOC() & ( maxPicOrderCntLsb - 1 ) ) == pocLsb )
615    {
616      pic = (*itP); 
617    }
618  }
619  return pic;
620}
621
622TComPic* TComSubDpb::getShortTermRefPic( Int poc )
623{
624  TComPic* pic = NULL; 
625  for(TComList<TComPic*>::iterator itP= begin(); ( itP!= end() && (pic == NULL) ); itP++)
626  {     
627    if ( (*itP)->getPOC() == poc && (*itP)->getMarkedAsShortTerm() )
628    {
629      pic = (*itP); 
630    }
631  }
632  return pic;
633}
634
635TComList<TComPic*> TComSubDpb::getPicsMarkedNeedForOutput()
636{
637  TComList<TComPic*> picsMarkedNeedForOutput; 
638
639  for(TComList<TComPic*>::iterator itP= begin();  itP!= end() ; itP++ )
640  {     
641    if ( (*itP)->getOutputMark() )
642    {
643      picsMarkedNeedForOutput.push_back( (*itP) );
644    }
645  }
646  return picsMarkedNeedForOutput;
647}
648
649Void TComSubDpb::markAllAsUnusedForReference()
650{
651  for(TComList<TComPic*>::iterator itP= begin();  itP!= end() ; itP++ )
652  {     
653    (*itP)->markAsUnusedForReference(); 
654  }
655}
656
657Void TComSubDpb::addPic( TComPic* pic )
658{
659  assert( pic != NULL ); 
660  assert( m_nuhLayerId == pic->getLayerId() || m_nuhLayerId == -1);     
661  if ( !empty() )
662  {
663    assert( getPic( pic->getPOC() ) == NULL ); // Don't add twice; assert( pic->getLayerId() == m_nuhLayerId );           
664
665    // Add sorted
666    TComSubDpb::iterator itP = begin(); 
667    Bool inserted = false; 
668    while( !inserted )
669    {
670      if ( ( itP == end()) || pic->getPOC() < (*itP)->getPOC() )
671      {
672        insert(itP, pic ); 
673        inserted = true; 
674      }
675      else
676      {
677        ++itP; 
678      }       
679    }     
680  } 
681  else
682  { 
683    pushBack( pic );
684  }
685}
686
687Void TComSubDpb::removePics( std::vector<TComPic*> picToRemove )
688{
689  for (Int i = 0; i < picToRemove.size(); i++ )
690  {
691    if( picToRemove[i] != NULL)
692    {
693      remove( picToRemove[i] ); 
694    }
695  }
696}
697
698Bool TComSubDpb::areAllPicsMarkedNotNeedForOutput()
699{
700  return ( getPicsMarkedNeedForOutput().size() == 0 );
701}
702
703
704TComPicLists::~TComPicLists()
705{
706  emptyAllSubDpbs();
707  for(TComList<TComSubDpb*>::iterator itL = m_subDpbs.begin(); ( itL != m_subDpbs.end()); itL++)
708  {     
709    if ( (*itL) != NULL )
710    {
711      delete (*itL); 
712      (*itL) = NULL; 
713    }
714  }
715}
716
717Void TComPicLists::addNewPic( TComPic* pic )
718{
719  getSubDpb ( pic->getLayerId() , true )->addPic( pic ); 
720  getAu     ( pic->getPOC()     , true )->addPic( pic , false ); 
721  if ( m_printPicOutput )
722  {
723    std::cout << "  Add    picture: ";
724    pic->print( 2 );
725    std::cout << std::endl;
726  }
727}
728
729Void TComPicLists::removePic( TComPic* pic )
730{
731  if (pic != NULL)
732  {
733
734    TComSubDpb* curSubDpb = getSubDpb( pic->getLayerId(), false ); 
735    curSubDpb->remove( pic );
736
737    TComAu* curAu = getAu     ( pic->getPOC(), false );       
738
739    if (curAu != NULL)
740    {   
741      curAu->remove( pic );
742      // Remove AU when empty.
743      if (curAu->empty() )
744      {
745        m_aus.remove( curAu ); 
746        delete curAu; 
747      }
748    }
749
750    if ( m_printPicOutput )
751    {
752      std::cout << "  Remove picture: ";
753      pic->print( 2 );
754      std::cout << std::endl;
755    }
756
757    pic->destroy();
758    delete pic; 
759  }
760}
761
762TComPic* TComPicLists::getPic( Int layerIdInNuh, Int poc )
763{
764  TComPic* pcPic = NULL;
765  TComSubDpb* subDpb = getSubDpb( layerIdInNuh, false ); 
766  if ( subDpb != NULL )
767  {
768    pcPic = subDpb->getPic( poc ); 
769  }
770  return pcPic;
771}
772
773TComPicYuv* TComPicLists::getPicYuv( Int layerIdInNuh, Int poc, Bool reconFlag )
774{
775  TComPic*    pcPic = getPic( layerIdInNuh, poc );
776  TComPicYuv* pcPicYuv = NULL;
777
778  if (pcPic != NULL)
779  {
780    if( reconFlag )
781    {
782      if ( pcPic->getReconMark() )
783      {
784        pcPicYuv = pcPic->getPicYuvRec();
785      }
786    }
787    else
788    {
789      pcPicYuv = pcPic->getPicYuvOrg();
790    }
791  };
792
793  return pcPicYuv;
794}
795
796TComSubDpb* TComPicLists::getSubDpb( Int nuhLayerId, Bool create )
797{
798  TComSubDpb* subDpb = NULL;
799  for(TComList<TComSubDpb*>::iterator itL = m_subDpbs.begin(); ( itL != m_subDpbs.end() && subDpb == NULL ); itL++)
800  {     
801    if ( (*itL)->getLayerId() == nuhLayerId )
802    {       
803      subDpb = (*itL); 
804    }
805  } 
806  if ( subDpb == NULL && create )
807  {
808    m_subDpbs.push_back( new TComSubDpb(nuhLayerId) ); 
809  }
810  return subDpb;
811}
812
813TComList<TComSubDpb*>* TComPicLists::getSubDpbs()
814{
815  return (&m_subDpbs);
816}
817
818TComAu* TComPicLists::addAu( Int poc )
819{
820  TComList<TComAu*>::iterator itA = m_aus.begin(); 
821
822  assert( getAu(poc, false) == NULL );
823  Bool inserted = false; 
824  while( !inserted)
825  {     
826    if ( ( itA == m_aus.end()) || poc < (*itA)->getPoc() )
827    {       
828      m_aus.insert(itA, new TComAu );       
829      inserted = true; 
830      --itA; 
831    }
832    else
833    {
834      ++itA; 
835    }
836  }
837  return (*itA);
838}
839
840TComAu* TComPicLists::getAu( Int poc, Bool create )
841{
842  TComAu* au = NULL;
843
844  for( TComList<TComAu*>::iterator itA = m_aus.begin(); ( itA != m_aus.end() && au == NULL ); itA++)
845  { 
846    if ( (*itA)->getPoc() == poc )
847    {       
848      au = (*itA); 
849    }
850  } 
851
852  if ( au == NULL && create )
853  {
854    au = addAu( poc ); 
855  }
856  return au;
857}
858
859TComList<TComAu*>* TComPicLists::getAus()
860{
861  return (&m_aus);
862}
863
864TComList<TComAu*> TComPicLists::getAusHavingPicsMarkedForOutput()
865{
866  TComList<TComAu*> ausHavingPicsForOutput; 
867  for(TComList<TComAu*>::iterator itA= m_aus.begin(); ( itA!=m_aus.end()); itA++)
868  {
869    Bool hasPicMarkedAsNeedForOutput = false;
870    for( TComAu::iterator itP= (*itA)->begin(); (itP!=(*itA)->end() && !hasPicMarkedAsNeedForOutput); itP++  )
871    {
872      if( (*itP)->getOutputMark() )
873      {
874        hasPicMarkedAsNeedForOutput = true; 
875      }
876    }
877    if (hasPicMarkedAsNeedForOutput)
878    {
879      ausHavingPicsForOutput.pushBack( (*itA) );
880    }
881  }
882  return ausHavingPicsForOutput;
883}
884
885Void TComPicLists::markSubDpbAsUnusedForReference( Int layerIdInNuh )
886{
887  TComSubDpb* subDpb = getSubDpb( layerIdInNuh, false ); 
888  markSubDpbAsUnusedForReference( *subDpb );
889}
890
891Void TComPicLists::markSubDpbAsUnusedForReference( TComSubDpb& subDpb )
892{
893  for(TComList<TComPic*>::iterator itP=subDpb.begin(); ( itP!=subDpb.end()); itP++)
894  {
895    (*itP)->markAsUnusedForReference(); 
896  }
897}
898
899Void TComPicLists::markAllSubDpbAsUnusedForReference()
900{
901  for(TComList<TComSubDpb*>::iterator itS= m_subDpbs.begin(); ( itS!=m_subDpbs.end()); itS++)
902  {
903    markSubDpbAsUnusedForReference( *(*itS) ); 
904  }
905}
906
907Void TComPicLists::decrementPocsInSubDpb( Int nuhLayerId, Int deltaPocVal )
908{
909  TComSubDpb* subDpb = getSubDpb( nuhLayerId, false ); 
910
911  for(TComSubDpb::iterator itP = subDpb->begin(); itP!=subDpb->end(); itP++)
912  {
913    TComPic* pic = (*itP); 
914    for (Int i = 0; i < pic->getNumAllocatedSlice(); i++)
915    {
916      TComSlice* slice = pic->getSlice(i);
917      slice->setPOC( slice->getPOC() - deltaPocVal ); 
918    }   
919  }
920}
921Void TComPicLists::emptyAllSubDpbs()
922{
923  emptySubDpbs( &m_subDpbs );
924}
925
926Void TComPicLists::emptySubDpbs( TComList<TComSubDpb*>* subDpbs )
927{
928  assert( subDpbs != NULL ); 
929  for( TComList<TComSubDpb*>::iterator itS = subDpbs->begin(); itS != subDpbs->end(); itS++ )
930  {
931    emptySubDpb( (*itS) ); 
932  }
933}
934
935Void TComPicLists::emptySubDpb( TComSubDpb* subDpb )
936{
937  if(subDpb != NULL)
938  {
939    while( !subDpb->empty() )
940    {
941      TComPic* curPic = *(subDpb->begin()); 
942      removePic( curPic ); 
943    }
944  }
945}
946
947Void TComPicLists::emptySubDpb( Int nuhLayerId )
948{
949  emptySubDpb( getSubDpb( nuhLayerId , false) );
950}
951
952Void TComPicLists::emptyNotNeedForOutputAndUnusedForRef()
953{
954  for(TComList<TComSubDpb*>::iterator itS= m_subDpbs.begin(); ( itS!=m_subDpbs.end()); itS++)
955  {
956    emptySubDpbNotNeedForOutputAndUnusedForRef( *(*itS) ); 
957  }
958}
959
960Void TComPicLists::emptySubDpbNotNeedForOutputAndUnusedForRef( Int layerId )
961{
962  TComSubDpb* subDpb = getSubDpb( layerId, false ); 
963  emptySubDpbNotNeedForOutputAndUnusedForRef( *subDpb );
964}
965
966Void TComPicLists::emptySubDpbNotNeedForOutputAndUnusedForRef( TComSubDpb subDpb )
967{
968  for(TComSubDpb::iterator itP= subDpb.begin(); ( itP!=subDpb.end()); itP++)
969  {
970    TComPic* pic = (*itP); 
971    if ( !pic->getOutputMark() && pic->getMarkedUnUsedForReference() )
972    {
973      removePic( pic ); 
974    }
975  }
976}
977
978Void TComPicLists::print()
979{
980  Bool first = true;     
981  for(TComList<TComSubDpb*>::iterator itL = m_subDpbs.begin(); ( itL != m_subDpbs.end() ); itL++)
982  {   
983    for(TComList<TComPic*>::iterator itP=(*itL)->begin(); ( itP!=(*itL)->end() ); itP++)
984    {
985      if ( first )
986      {
987        (*itP)->print( true );       
988        first = false; 
989      }
990      (*itP)->print( false );       
991    }
992  }
993}
994
995#if NH_3D
996TComPicYuv* TComPicLists::getPicYuv( Int viewIndex, Bool depthFlag, Int poc, Bool recon )
997{ 
998  Int layerIdInNuh = m_vps->getLayerIdInNuh( viewIndex, depthFlag ); 
999  return getPicYuv( layerIdInNuh, poc, recon );
1000}
1001
1002TComPic* TComPicLists::getPic( Int viewIndex, Bool depthFlag, Int poc )
1003{
1004  return getPic   ( m_vps->getLayerIdInNuh( viewIndex, depthFlag ), poc );
1005}
1006
1007#endif
1008
1009#endif
1010
1011
1012
1013
1014//! \}
1015
Note: See TracBrowser for help on using the repository browser.