source: 3DVCSoftware/trunk/source/Lib/TLibCommon/TComPic.cpp @ 1413

Last change on this file since 1413 was 1413, checked in by tech, 7 years ago

Merged HTM-16.2-dev@1412

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