source: 3DVCSoftware/branches/HTM-15.2-dev/source/Lib/TLibCommon/TComPic.cpp @ 1374

Last change on this file since 1374 was 1374, checked in by tech, 8 years ago

Macro cleanups.

  • Property svn:eol-style set to native
File size: 27.9 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_VSO
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          // The picture pcCandColSlice->getRefPic((RefPicList)iColRefDir, iColRefIdx) might not be in DPB anymore
452          // So don't access it directly.
453          Int iColRefViewIdx = pcCandColSlice->getVPS()->getViewOrderIdx( pcCandColSlice->getRefLayerId( (RefPicList)iColRefDir, iColRefIdx ) );       
454          if(iColViewIdx == iColRefViewIdx)
455          {
456            continue;
457          }
458
459          for(Int iCurrRefDir = 0; (iCurrRefDir < (currSlice->isInterB() ? 2 : 1)) && (m_abTIVRINCurrRL[curCandPic][iColRefDir][iColRefIdx] == false); iCurrRefDir++)
460          {
461            for(Int iCurrRefIdx = 0; iCurrRefIdx < currSlice->getNumRefIdx((RefPicList)iCurrRefDir); iCurrRefIdx++)
462            {
463              if(currSlice->getRefPic((RefPicList)iCurrRefDir, iCurrRefIdx)->getViewIndex() == iColRefViewIdx)
464              { 
465                m_abTIVRINCurrRL[curCandPic][iColRefDir][iColRefIdx] = true;
466                break;
467              }
468            }
469          }
470        }
471      }
472    }
473  }
474}
475
476Bool TComPic::isTempIVRefValid(Int currCandPic, Int iColRefDir, Int iColRefIdx)
477{
478  return m_abTIVRINCurrRL[currCandPic][iColRefDir][iColRefIdx];
479}
480
481Void TComPic::checkTextureRef()
482{
483  TComSlice* pcCurrSlice = getSlice(getCurrSliceIdx());
484  TComPic* pcTextPic = pcCurrSlice->getIvPic(0, getViewIndex());
485#if H_3D_FCO
486  if ( pcTextPic )
487  {
488#endif
489    TComSlice* pcTextSlice = pcTextPic->getSlice(0); // currently only support single slice
490
491    for(Int iTextRefDir = 0; (iTextRefDir < (pcTextSlice->isInterB() ? 2 :1) ) && !pcTextSlice->isIntra(); iTextRefDir++)
492    {
493      for(Int iTextRefIdx =0; iTextRefIdx < pcTextSlice->getNumRefIdx((RefPicList)iTextRefDir); iTextRefIdx++)
494      {
495        Int iTextRefPOC    = pcTextSlice->getRefPOC((RefPicList)iTextRefDir, iTextRefIdx);
496        Int iTextRefViewId = pcTextSlice->getRefPic((RefPicList)iTextRefDir, iTextRefIdx)->getViewIndex();
497        m_aiTexToDepRef[iTextRefDir][iTextRefIdx] = -1;
498        Int iCurrRefDir = iTextRefDir;
499
500        for(Int iCurrRefIdx = 0; (iCurrRefIdx<pcCurrSlice->getNumRefIdx((RefPicList)iCurrRefDir)) && (m_aiTexToDepRef[iTextRefDir][iTextRefIdx] < 0); iCurrRefIdx++)
501        {
502          if(pcCurrSlice->getRefPOC((RefPicList)iCurrRefDir, iCurrRefIdx ) == iTextRefPOC && 
503            pcCurrSlice->getRefPic((RefPicList)iCurrRefDir, iCurrRefIdx)->getViewIndex() == iTextRefViewId)
504          { 
505            m_aiTexToDepRef[iTextRefDir][iTextRefIdx] = iCurrRefIdx;           
506          }
507        }
508      }
509    }
510#if H_3D_FCO
511  }
512#endif
513}
514
515Int TComPic::isTextRefValid(Int iTextRefDir, Int iTextRefIdx)
516{
517  return m_aiTexToDepRef[iTextRefDir][iTextRefIdx];
518}
519#endif
520#endif
521
522Void TComAu::setPicLatencyCount( Int picLatenyCount )
523{
524  for(TComList<TComPic*>::iterator itP= begin();  itP!= end(); itP++)
525  {     
526    (*itP)->setPicLatencyCount( picLatenyCount ); 
527  }
528}
529
530TComPic* TComAu::getPic( Int nuhLayerId )
531{
532  TComPic* pic = NULL; 
533  for(TComList<TComPic*>::iterator itP= begin(); ( itP!= end() && (pic == NULL) ); itP++)
534  {     
535    if ( (*itP)->getLayerId() == nuhLayerId )
536    {
537      pic = (*itP); 
538    }
539  }
540  return pic;
541}
542
543Void TComAu::addPic( TComPic* pic, Bool pocUnkown )
544{
545  if ( !empty() )
546  {
547    if (!pocUnkown)
548    {
549      assert( pic->getPOC()   == ( getPoc() ));
550    }     
551    pic->setPicLatencyCount( getPicLatencyCount() ); 
552
553    assert( getPic( pic->getLayerId() ) == NULL );
554
555    // Add sorted
556    TComAu::iterator itP = begin(); 
557    Bool inserted = false; 
558    while( !inserted )
559    {
560      if ( ( itP == end()) || pic->getLayerId() < (*itP)->getLayerId() )
561      {
562        insert(itP, pic ); 
563        inserted = true; 
564      }
565      else
566      {
567        ++itP; 
568      }       
569    }     
570  } 
571  else
572  { 
573    pushBack( pic );     
574  }
575}
576
577Bool TComAu::containsPic( TComPic* pic )
578{
579  Bool isInList = false; 
580  for(TComList<TComPic*>::iterator itP= begin(); ( itP!= end() && (!isInList) ); itP++)
581  { 
582    isInList = isInList || ( pic == (*itP)); 
583  }
584  return isInList;
585}
586
587TComSubDpb::TComSubDpb( Int nuhLayerid )
588{
589  m_nuhLayerId = nuhLayerid;
590}
591
592TComPic* TComSubDpb::getPic( Int poc )
593{
594  TComPic* pic = NULL; 
595  for(TComList<TComPic*>::iterator itP= begin(); ( itP!= end() && (pic == NULL) ); itP++)
596  {     
597    if ( (*itP)->getPOC() == poc )
598    {
599      pic = (*itP); 
600    }
601  }
602  return pic;
603}
604
605TComPic* TComSubDpb::getPicFromLsb( Int pocLsb, Int maxPicOrderCntLsb )
606{
607  TComPic* pic = NULL; 
608  for(TComList<TComPic*>::iterator itP= begin(); ( itP!= end() && (pic == NULL) ); itP++)
609  {     
610    if ( ( (*itP)->getPOC() & ( maxPicOrderCntLsb - 1 ) ) == pocLsb )
611    {
612      pic = (*itP); 
613    }
614  }
615  return pic;
616}
617
618TComPic* TComSubDpb::getShortTermRefPic( Int poc )
619{
620  TComPic* pic = NULL; 
621  for(TComList<TComPic*>::iterator itP= begin(); ( itP!= end() && (pic == NULL) ); itP++)
622  {     
623    if ( (*itP)->getPOC() == poc && (*itP)->getMarkedAsShortTerm() )
624    {
625      pic = (*itP); 
626    }
627  }
628  return pic;
629}
630
631TComList<TComPic*> TComSubDpb::getPicsMarkedNeedForOutput()
632{
633  TComList<TComPic*> picsMarkedNeedForOutput; 
634
635  for(TComList<TComPic*>::iterator itP= begin();  itP!= end() ; itP++ )
636  {     
637    if ( (*itP)->getOutputMark() )
638    {
639      picsMarkedNeedForOutput.push_back( (*itP) );
640    }
641  }
642  return picsMarkedNeedForOutput;
643}
644
645Void TComSubDpb::markAllAsUnusedForReference()
646{
647  for(TComList<TComPic*>::iterator itP= begin();  itP!= end() ; itP++ )
648  {     
649    (*itP)->markAsUnusedForReference(); 
650  }
651}
652
653Void TComSubDpb::addPic( TComPic* pic )
654{
655  assert( pic != NULL ); 
656  assert( m_nuhLayerId == pic->getLayerId() || m_nuhLayerId == -1);     
657  if ( !empty() )
658  {
659    assert( getPic( pic->getPOC() ) == NULL ); // Don't add twice; assert( pic->getLayerId() == m_nuhLayerId );           
660
661    // Add sorted
662    TComSubDpb::iterator itP = begin(); 
663    Bool inserted = false; 
664    while( !inserted )
665    {
666      if ( ( itP == end()) || pic->getPOC() < (*itP)->getPOC() )
667      {
668        insert(itP, pic ); 
669        inserted = true; 
670      }
671      else
672      {
673        ++itP; 
674      }       
675    }     
676  } 
677  else
678  { 
679    pushBack( pic );
680  }
681}
682
683Void TComSubDpb::removePics( std::vector<TComPic*> picToRemove )
684{
685  for (Int i = 0; i < picToRemove.size(); i++ )
686  {
687    if( picToRemove[i] != NULL)
688    {
689      remove( picToRemove[i] ); 
690    }
691  }
692}
693
694Bool TComSubDpb::areAllPicsMarkedNotNeedForOutput()
695{
696  return ( getPicsMarkedNeedForOutput().size() == 0 );
697}
698
699
700TComPicLists::~TComPicLists()
701{
702  emptyAllSubDpbs();
703  for(TComList<TComSubDpb*>::iterator itL = m_subDpbs.begin(); ( itL != m_subDpbs.end()); itL++)
704  {     
705    if ( (*itL) != NULL )
706    {
707      delete (*itL); 
708      (*itL) = NULL; 
709    }
710  }
711}
712
713Void TComPicLists::addNewPic( TComPic* pic )
714{
715  getSubDpb ( pic->getLayerId() , true )->addPic( pic ); 
716  getAu     ( pic->getPOC()     , true )->addPic( pic , false ); 
717  if ( m_printPicOutput )
718  {
719    std::cout << "  Add    picture: ";
720    pic->print( 2 );
721    std::cout << std::endl;
722  }
723}
724
725Void TComPicLists::removePic( TComPic* pic )
726{
727  if (pic != NULL)
728  {
729
730    TComSubDpb* curSubDpb = getSubDpb( pic->getLayerId(), false ); 
731    curSubDpb->remove( pic );
732
733    TComAu* curAu = getAu     ( pic->getPOC(), false );       
734
735    if (curAu != NULL)
736    {   
737      curAu->remove( pic );
738      // Remove AU when empty.
739      if (curAu->empty() )
740      {
741        m_aus.remove( curAu ); 
742        delete curAu; 
743      }
744    }
745
746    if ( m_printPicOutput )
747    {
748      std::cout << "  Remove picture: ";
749      pic->print( 2 );
750      std::cout << std::endl;
751    }
752
753    pic->destroy();
754    delete pic; 
755  }
756}
757
758TComPic* TComPicLists::getPic( Int layerIdInNuh, Int poc )
759{
760  TComPic* pcPic = NULL;
761  TComSubDpb* subDpb = getSubDpb( layerIdInNuh, false ); 
762  if ( subDpb != NULL )
763  {
764    pcPic = subDpb->getPic( poc ); 
765  }
766  return pcPic;
767}
768
769TComPicYuv* TComPicLists::getPicYuv( Int layerIdInNuh, Int poc, Bool reconFlag )
770{
771  TComPic*    pcPic = getPic( layerIdInNuh, poc );
772  TComPicYuv* pcPicYuv = NULL;
773
774  if (pcPic != NULL)
775  {
776    if( reconFlag )
777    {
778      if ( pcPic->getReconMark() )
779      {
780        pcPicYuv = pcPic->getPicYuvRec();
781      }
782    }
783    else
784    {
785      pcPicYuv = pcPic->getPicYuvOrg();
786    }
787  };
788
789  return pcPicYuv;
790}
791
792TComSubDpb* TComPicLists::getSubDpb( Int nuhLayerId, Bool create )
793{
794  TComSubDpb* subDpb = NULL;
795  for(TComList<TComSubDpb*>::iterator itL = m_subDpbs.begin(); ( itL != m_subDpbs.end() && subDpb == NULL ); itL++)
796  {     
797    if ( (*itL)->getLayerId() == nuhLayerId )
798    {       
799      subDpb = (*itL); 
800    }
801  } 
802  if ( subDpb == NULL && create )
803  {
804    m_subDpbs.push_back( new TComSubDpb(nuhLayerId) ); 
805  }
806  return subDpb;
807}
808
809TComList<TComSubDpb*>* TComPicLists::getSubDpbs()
810{
811  return (&m_subDpbs);
812}
813
814TComAu* TComPicLists::addAu( Int poc )
815{
816  TComList<TComAu*>::iterator itA = m_aus.begin(); 
817
818  assert( getAu(poc, false) == NULL );
819  Bool inserted = false; 
820  while( !inserted)
821  {     
822    if ( ( itA == m_aus.end()) || poc < (*itA)->getPoc() )
823    {       
824      m_aus.insert(itA, new TComAu );       
825      inserted = true; 
826      --itA; 
827    }
828    else
829    {
830      ++itA; 
831    }
832  }
833  return (*itA);
834}
835
836TComAu* TComPicLists::getAu( Int poc, Bool create )
837{
838  TComAu* au = NULL;
839
840  for( TComList<TComAu*>::iterator itA = m_aus.begin(); ( itA != m_aus.end() && au == NULL ); itA++)
841  { 
842    if ( (*itA)->getPoc() == poc )
843    {       
844      au = (*itA); 
845    }
846  } 
847
848  if ( au == NULL && create )
849  {
850    au = addAu( poc ); 
851  }
852  return au;
853}
854
855TComList<TComAu*>* TComPicLists::getAus()
856{
857  return (&m_aus);
858}
859
860TComList<TComAu*> TComPicLists::getAusHavingPicsMarkedForOutput()
861{
862  TComList<TComAu*> ausHavingPicsForOutput; 
863  for(TComList<TComAu*>::iterator itA= m_aus.begin(); ( itA!=m_aus.end()); itA++)
864  {
865    Bool hasPicMarkedAsNeedForOutput = false;
866    for( TComAu::iterator itP= (*itA)->begin(); (itP!=(*itA)->end() && !hasPicMarkedAsNeedForOutput); itP++  )
867    {
868      if( (*itP)->getOutputMark() )
869      {
870        hasPicMarkedAsNeedForOutput = true; 
871      }
872    }
873    if (hasPicMarkedAsNeedForOutput)
874    {
875      ausHavingPicsForOutput.pushBack( (*itA) );
876    }
877  }
878  return ausHavingPicsForOutput;
879}
880
881Void TComPicLists::markSubDpbAsUnusedForReference( Int layerIdInNuh )
882{
883  TComSubDpb* subDpb = getSubDpb( layerIdInNuh, false ); 
884  markSubDpbAsUnusedForReference( *subDpb );
885}
886
887Void TComPicLists::markSubDpbAsUnusedForReference( TComSubDpb& subDpb )
888{
889  for(TComList<TComPic*>::iterator itP=subDpb.begin(); ( itP!=subDpb.end()); itP++)
890  {
891    (*itP)->markAsUnusedForReference(); 
892  }
893}
894
895Void TComPicLists::markAllSubDpbAsUnusedForReference()
896{
897  for(TComList<TComSubDpb*>::iterator itS= m_subDpbs.begin(); ( itS!=m_subDpbs.end()); itS++)
898  {
899    markSubDpbAsUnusedForReference( *(*itS) ); 
900  }
901}
902
903Void TComPicLists::decrementPocsInSubDpb( Int nuhLayerId, Int deltaPocVal )
904{
905  TComSubDpb* subDpb = getSubDpb( nuhLayerId, false ); 
906
907  for(TComSubDpb::iterator itP = subDpb->begin(); itP!=subDpb->end(); itP++)
908  {
909    TComPic* pic = (*itP); 
910    for (Int i = 0; i < pic->getNumAllocatedSlice(); i++)
911    {
912      TComSlice* slice = pic->getSlice(i);
913      slice->setPOC( slice->getPOC() - deltaPocVal ); 
914    }   
915  }
916}
917Void TComPicLists::emptyAllSubDpbs()
918{
919  emptySubDpbs( &m_subDpbs );
920}
921
922Void TComPicLists::emptySubDpbs( TComList<TComSubDpb*>* subDpbs )
923{
924  assert( subDpbs != NULL ); 
925  for( TComList<TComSubDpb*>::iterator itS = subDpbs->begin(); itS != subDpbs->end(); itS++ )
926  {
927    emptySubDpb( (*itS) ); 
928  }
929}
930
931Void TComPicLists::emptySubDpb( TComSubDpb* subDpb )
932{
933  if(subDpb != NULL)
934  {
935    while( !subDpb->empty() )
936    {
937      TComPic* curPic = *(subDpb->begin()); 
938      removePic( curPic ); 
939    }
940  }
941}
942
943Void TComPicLists::emptySubDpb( Int nuhLayerId )
944{
945  emptySubDpb( getSubDpb( nuhLayerId , false) );
946}
947
948Void TComPicLists::emptyNotNeedForOutputAndUnusedForRef()
949{
950  for(TComList<TComSubDpb*>::iterator itS= m_subDpbs.begin(); ( itS!=m_subDpbs.end()); itS++)
951  {
952    emptySubDpbNotNeedForOutputAndUnusedForRef( *(*itS) ); 
953  }
954}
955
956Void TComPicLists::emptySubDpbNotNeedForOutputAndUnusedForRef( Int layerId )
957{
958  TComSubDpb* subDpb = getSubDpb( layerId, false ); 
959  emptySubDpbNotNeedForOutputAndUnusedForRef( *subDpb );
960}
961
962Void TComPicLists::emptySubDpbNotNeedForOutputAndUnusedForRef( TComSubDpb subDpb )
963{
964  for(TComSubDpb::iterator itP= subDpb.begin(); ( itP!=subDpb.end()); itP++)
965  {
966    TComPic* pic = (*itP); 
967    if ( !pic->getOutputMark() && pic->getMarkedUnUsedForReference() )
968    {
969      removePic( pic ); 
970    }
971  }
972}
973
974Void TComPicLists::print()
975{
976  Bool first = true;     
977  for(TComList<TComSubDpb*>::iterator itL = m_subDpbs.begin(); ( itL != m_subDpbs.end() ); itL++)
978  {   
979    for(TComList<TComPic*>::iterator itP=(*itL)->begin(); ( itP!=(*itL)->end() ); itP++)
980    {
981      if ( first )
982      {
983        (*itP)->print( true );       
984        first = false; 
985      }
986      (*itP)->print( false );       
987    }
988  }
989}
990
991#if NH_3D_VSO
992TComPicYuv* TComPicLists::getPicYuv( Int viewIndex, Bool depthFlag, Int auxId, Int poc, Bool recon )
993{ 
994  Int layerIdInNuh = m_vps->getLayerIdInNuh( viewIndex, depthFlag, auxId ); 
995  return getPicYuv( layerIdInNuh, poc, recon );
996}
997
998TComPic* TComPicLists::getPic( Int viewIndex, Bool depthFlag, Int auxId, Int poc )
999{
1000  return getPic   ( m_vps->getLayerIdInNuh( viewIndex, depthFlag, auxId ), poc );
1001}
1002
1003#endif
1004
1005#endif
1006
1007
1008
1009
1010//! \}
1011
Note: See TracBrowser for help on using the repository browser.