| 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 | |
|---|
| 48 | TComPic::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 | #endif |
|---|
| 63 | |
|---|
| 64 | { |
|---|
| 65 | for(UInt i=0; i<NUM_PIC_YUV; i++) |
|---|
| 66 | { |
|---|
| 67 | m_apcPicYuv[i] = NULL; |
|---|
| 68 | } |
|---|
| 69 | #if NH_MV |
|---|
| 70 | m_isPocResettingPic = false; |
|---|
| 71 | m_hasGeneratedRefPics = false; |
|---|
| 72 | m_isFstPicOfAllLayOfPocResetPer = false; |
|---|
| 73 | m_decodingOrder = 0; |
|---|
| 74 | m_noRaslOutputFlag = false; |
|---|
| 75 | m_noClrasOutputFlag = false; |
|---|
| 76 | m_picLatencyCount = 0; |
|---|
| 77 | m_isGenerated = false; |
|---|
| 78 | m_isGeneratedCl833 = false; |
|---|
| 79 | m_activatesNewVps = false; |
|---|
| 80 | #endif |
|---|
| 81 | } |
|---|
| 82 | |
|---|
| 83 | TComPic::~TComPic() |
|---|
| 84 | { |
|---|
| 85 | } |
|---|
| 86 | |
|---|
| 87 | Void TComPic::create( const TComSPS &sps, const TComPPS &pps, const Bool bIsVirtual) |
|---|
| 88 | { |
|---|
| 89 | const ChromaFormat chromaFormatIDC = sps.getChromaFormatIdc(); |
|---|
| 90 | const Int iWidth = sps.getPicWidthInLumaSamples(); |
|---|
| 91 | const Int iHeight = sps.getPicHeightInLumaSamples(); |
|---|
| 92 | const UInt uiMaxCuWidth = sps.getMaxCUWidth(); |
|---|
| 93 | const UInt uiMaxCuHeight = sps.getMaxCUHeight(); |
|---|
| 94 | const UInt uiMaxDepth = sps.getMaxTotalCUDepth(); |
|---|
| 95 | |
|---|
| 96 | m_picSym.create( sps, pps, uiMaxDepth ); |
|---|
| 97 | if (!bIsVirtual) |
|---|
| 98 | { |
|---|
| 99 | m_apcPicYuv[PIC_YUV_ORG ] = new TComPicYuv; m_apcPicYuv[PIC_YUV_ORG ]->create( iWidth, iHeight, chromaFormatIDC, uiMaxCuWidth, uiMaxCuHeight, uiMaxDepth, true ); |
|---|
| 100 | m_apcPicYuv[PIC_YUV_TRUE_ORG] = new TComPicYuv; m_apcPicYuv[PIC_YUV_TRUE_ORG]->create( iWidth, iHeight, chromaFormatIDC, uiMaxCuWidth, uiMaxCuHeight, uiMaxDepth, true ); |
|---|
| 101 | } |
|---|
| 102 | m_apcPicYuv[PIC_YUV_REC] = new TComPicYuv; m_apcPicYuv[PIC_YUV_REC]->create( iWidth, iHeight, chromaFormatIDC, uiMaxCuWidth, uiMaxCuHeight, uiMaxDepth, true ); |
|---|
| 103 | |
|---|
| 104 | // there are no SEI messages associated with this picture initially |
|---|
| 105 | if (m_SEIs.size() > 0) |
|---|
| 106 | { |
|---|
| 107 | deleteSEIs (m_SEIs); |
|---|
| 108 | } |
|---|
| 109 | m_bUsedByCurr = false; |
|---|
| 110 | |
|---|
| 111 | |
|---|
| 112 | } |
|---|
| 113 | |
|---|
| 114 | Void TComPic::destroy() |
|---|
| 115 | { |
|---|
| 116 | m_picSym.destroy(); |
|---|
| 117 | |
|---|
| 118 | for(UInt i=0; i<NUM_PIC_YUV; i++) |
|---|
| 119 | { |
|---|
| 120 | if (m_apcPicYuv[i]) |
|---|
| 121 | { |
|---|
| 122 | m_apcPicYuv[i]->destroy(); |
|---|
| 123 | delete m_apcPicYuv[i]; |
|---|
| 124 | m_apcPicYuv[i] = NULL; |
|---|
| 125 | } |
|---|
| 126 | } |
|---|
| 127 | |
|---|
| 128 | deleteSEIs(m_SEIs); |
|---|
| 129 | } |
|---|
| 130 | Void TComPic::compressMotion() |
|---|
| 131 | { |
|---|
| 132 | TComPicSym* pPicSym = getPicSym(); |
|---|
| 133 | for ( UInt uiCUAddr = 0; uiCUAddr < pPicSym->getNumberOfCtusInFrame(); uiCUAddr++ ) |
|---|
| 134 | { |
|---|
| 135 | TComDataCU* pCtu = pPicSym->getCtu(uiCUAddr); |
|---|
| 136 | pCtu->compressMV(); |
|---|
| 137 | |
|---|
| 138 | } |
|---|
| 139 | } |
|---|
| 140 | |
|---|
| 141 | |
|---|
| 142 | Bool TComPic::getSAOMergeAvailability(Int currAddr, Int mergeAddr) |
|---|
| 143 | { |
|---|
| 144 | Bool mergeCtbInSliceSeg = (mergeAddr >= getPicSym()->getCtuTsToRsAddrMap(getCtu(currAddr)->getSlice()->getSliceCurStartCtuTsAddr())); |
|---|
| 145 | Bool mergeCtbInTile = (getPicSym()->getTileIdxMap(mergeAddr) == getPicSym()->getTileIdxMap(currAddr)); |
|---|
| 146 | return (mergeCtbInSliceSeg && mergeCtbInTile); |
|---|
| 147 | } |
|---|
| 148 | |
|---|
| 149 | UInt TComPic::getSubstreamForCtuAddr(const UInt ctuAddr, const Bool bAddressInRaster, TComSlice *pcSlice) |
|---|
| 150 | { |
|---|
| 151 | UInt subStrm; |
|---|
| 152 | const bool bWPPEnabled=pcSlice->getPPS()->getEntropyCodingSyncEnabledFlag(); |
|---|
| 153 | const TComPicSym &picSym = *(getPicSym()); |
|---|
| 154 | |
|---|
| 155 | if ((bWPPEnabled && picSym.getFrameHeightInCtus()>1) || (picSym.getNumTiles()>1)) // wavefronts, and possibly tiles being used. |
|---|
| 156 | { |
|---|
| 157 | if (bWPPEnabled) |
|---|
| 158 | { |
|---|
| 159 | const UInt ctuRsAddr = bAddressInRaster?ctuAddr : picSym.getCtuTsToRsAddrMap(ctuAddr); |
|---|
| 160 | const UInt frameWidthInCtus = picSym.getFrameWidthInCtus(); |
|---|
| 161 | const UInt tileIndex = picSym.getTileIdxMap(ctuRsAddr); |
|---|
| 162 | const UInt numTileColumns = (picSym.getNumTileColumnsMinus1()+1); |
|---|
| 163 | const TComTile *pTile = picSym.getTComTile(tileIndex); |
|---|
| 164 | const UInt firstCtuRsAddrOfTile = pTile->getFirstCtuRsAddr(); |
|---|
| 165 | const UInt tileYInCtus = firstCtuRsAddrOfTile / frameWidthInCtus; |
|---|
| 166 | // independent tiles => substreams are "per tile" |
|---|
| 167 | const UInt ctuLine = ctuRsAddr / frameWidthInCtus; |
|---|
| 168 | const UInt startingSubstreamForTile =(tileYInCtus*numTileColumns) + (pTile->getTileHeightInCtus()*(tileIndex%numTileColumns)); |
|---|
| 169 | subStrm = startingSubstreamForTile + (ctuLine - tileYInCtus); |
|---|
| 170 | } |
|---|
| 171 | else |
|---|
| 172 | { |
|---|
| 173 | const UInt ctuRsAddr = bAddressInRaster?ctuAddr : picSym.getCtuTsToRsAddrMap(ctuAddr); |
|---|
| 174 | const UInt tileIndex = picSym.getTileIdxMap(ctuRsAddr); |
|---|
| 175 | subStrm=tileIndex; |
|---|
| 176 | } |
|---|
| 177 | } |
|---|
| 178 | else |
|---|
| 179 | { |
|---|
| 180 | // dependent tiles => substreams are "per frame". |
|---|
| 181 | subStrm = 0; |
|---|
| 182 | } |
|---|
| 183 | return subStrm; |
|---|
| 184 | } |
|---|
| 185 | |
|---|
| 186 | #if NH_MV |
|---|
| 187 | Bool TComPic::getPocResetPeriodId() |
|---|
| 188 | { |
|---|
| 189 | return getSlice(0)->getPocResetIdc(); |
|---|
| 190 | } |
|---|
| 191 | |
|---|
| 192 | Void TComPic::markAsUsedForShortTermReference() |
|---|
| 193 | { |
|---|
| 194 | getSlice(0)->setReferenced( true ); |
|---|
| 195 | setIsLongTerm( false ); |
|---|
| 196 | } |
|---|
| 197 | |
|---|
| 198 | Void TComPic::markAsUsedForLongTermReference() |
|---|
| 199 | { |
|---|
| 200 | getSlice(0)->setReferenced( true ); |
|---|
| 201 | setIsLongTerm( true ); |
|---|
| 202 | } |
|---|
| 203 | |
|---|
| 204 | |
|---|
| 205 | Void TComPic::markAsUnusedForReference() |
|---|
| 206 | { |
|---|
| 207 | getSlice(0)->setReferenced( false ); |
|---|
| 208 | setIsLongTerm( false ); |
|---|
| 209 | } |
|---|
| 210 | |
|---|
| 211 | |
|---|
| 212 | Bool TComPic::getMarkedUnUsedForReference() |
|---|
| 213 | { |
|---|
| 214 | return !getSlice(0)->isReferenced( ); |
|---|
| 215 | } |
|---|
| 216 | |
|---|
| 217 | |
|---|
| 218 | Bool TComPic::getMarkedAsShortTerm() |
|---|
| 219 | { |
|---|
| 220 | return ( getSlice(0)->isReferenced( ) && !getIsLongTerm() ); |
|---|
| 221 | } |
|---|
| 222 | |
|---|
| 223 | Void TComPic::print( Int outputLevel ) |
|---|
| 224 | { |
|---|
| 225 | if ( outputLevel== 0 ) |
|---|
| 226 | { |
|---|
| 227 | std::cout << std::endl |
|---|
| 228 | << "LId" |
|---|
| 229 | << "\t" << "POC" |
|---|
| 230 | << "\t" << "Rec" |
|---|
| 231 | << "\t" << "Ref" |
|---|
| 232 | << "\t" << "LT" |
|---|
| 233 | << "\t" << "OutMark" |
|---|
| 234 | << "\t" << "OutFlag" |
|---|
| 235 | << "\t" << "Type" |
|---|
| 236 | << "\t" << "PReFlag" |
|---|
| 237 | << std::endl; |
|---|
| 238 | } |
|---|
| 239 | else if( outputLevel == 1 ) |
|---|
| 240 | { |
|---|
| 241 | std::cout << getLayerId() |
|---|
| 242 | << "\t" << getPOC() |
|---|
| 243 | << "\t" << getReconMark() |
|---|
| 244 | << "\t" << getSlice(0)->isReferenced() |
|---|
| 245 | << "\t" << getIsLongTerm() |
|---|
| 246 | << "\t" << getOutputMark() |
|---|
| 247 | << "\t" << getSlice(0)->getPicOutputFlag() |
|---|
| 248 | << "\t" << getSlice(0)->getNalUnitTypeString() |
|---|
| 249 | << "\t" << getSlice(0)->getPocResetFlag() |
|---|
| 250 | << std::endl; |
|---|
| 251 | } |
|---|
| 252 | else if ( outputLevel == 2 ) |
|---|
| 253 | { |
|---|
| 254 | std::cout << std:: setfill(' ') |
|---|
| 255 | << " LayerId: " << std::setw(2) << getLayerId() |
|---|
| 256 | << "\t" << " POC: " << std::setw(5) << getPOC() |
|---|
| 257 | << "\t" << " Dec. Order: " << std::setw(5) << getDecodingOrder() |
|---|
| 258 | << "\t" << " Referenced: " << std::setw(1) << getSlice(0)->isReferenced() |
|---|
| 259 | << "\t" << " Pic type: " << getSlice(0)->getNalUnitTypeString() |
|---|
| 260 | << "\t" << " Generated: " << std::setw(1) << getIsGenerated() |
|---|
| 261 | << "\t" << " Gen. Ref. Pics: " << std::setw(1) << getHasGeneratedRefPics(); |
|---|
| 262 | } |
|---|
| 263 | else if ( outputLevel == 4 ) |
|---|
| 264 | { |
|---|
| 265 | std::cout << std:: setfill(' ') |
|---|
| 266 | << " LayerId: " << std::setw(2) << getLayerId() |
|---|
| 267 | << "\t" << " POC: " << std::setw(5) << getPOC() |
|---|
| 268 | << "\t" << " Referenced: " << std::setw(1) << getSlice(0)->isReferenced() << std::endl; |
|---|
| 269 | } |
|---|
| 270 | } |
|---|
| 271 | |
|---|
| 272 | |
|---|
| 273 | Void TComAu::setPicLatencyCount( Int picLatenyCount ) |
|---|
| 274 | { |
|---|
| 275 | for(TComList<TComPic*>::iterator itP= begin(); itP!= end(); itP++) |
|---|
| 276 | { |
|---|
| 277 | (*itP)->setPicLatencyCount( picLatenyCount ); |
|---|
| 278 | } |
|---|
| 279 | } |
|---|
| 280 | |
|---|
| 281 | TComPic* TComAu::getPic( Int nuhLayerId ) |
|---|
| 282 | { |
|---|
| 283 | TComPic* pic = NULL; |
|---|
| 284 | for(TComList<TComPic*>::iterator itP= begin(); ( itP!= end() && (pic == NULL) ); itP++) |
|---|
| 285 | { |
|---|
| 286 | if ( (*itP)->getLayerId() == nuhLayerId ) |
|---|
| 287 | { |
|---|
| 288 | pic = (*itP); |
|---|
| 289 | } |
|---|
| 290 | } |
|---|
| 291 | return pic; |
|---|
| 292 | } |
|---|
| 293 | |
|---|
| 294 | Void TComAu::addPic( TComPic* pic, Bool pocUnkown ) |
|---|
| 295 | { |
|---|
| 296 | if ( !empty() ) |
|---|
| 297 | { |
|---|
| 298 | if (!pocUnkown) |
|---|
| 299 | { |
|---|
| 300 | assert( pic->getPOC() == ( getPoc() )); |
|---|
| 301 | } |
|---|
| 302 | pic->setPicLatencyCount( getPicLatencyCount() ); |
|---|
| 303 | |
|---|
| 304 | assert( getPic( pic->getLayerId() ) == NULL ); |
|---|
| 305 | |
|---|
| 306 | // Add sorted |
|---|
| 307 | TComAu::iterator itP = begin(); |
|---|
| 308 | Bool inserted = false; |
|---|
| 309 | while( !inserted ) |
|---|
| 310 | { |
|---|
| 311 | if ( ( itP == end()) || pic->getLayerId() < (*itP)->getLayerId() ) |
|---|
| 312 | { |
|---|
| 313 | insert(itP, pic ); |
|---|
| 314 | inserted = true; |
|---|
| 315 | } |
|---|
| 316 | else |
|---|
| 317 | { |
|---|
| 318 | ++itP; |
|---|
| 319 | } |
|---|
| 320 | } |
|---|
| 321 | } |
|---|
| 322 | else |
|---|
| 323 | { |
|---|
| 324 | pushBack( pic ); |
|---|
| 325 | } |
|---|
| 326 | } |
|---|
| 327 | |
|---|
| 328 | Bool TComAu::containsPic( TComPic* pic ) |
|---|
| 329 | { |
|---|
| 330 | Bool isInList = false; |
|---|
| 331 | for(TComList<TComPic*>::iterator itP= begin(); ( itP!= end() && (!isInList) ); itP++) |
|---|
| 332 | { |
|---|
| 333 | isInList = isInList || ( pic == (*itP)); |
|---|
| 334 | } |
|---|
| 335 | return isInList; |
|---|
| 336 | } |
|---|
| 337 | |
|---|
| 338 | TComSubDpb::TComSubDpb( Int nuhLayerid ) |
|---|
| 339 | { |
|---|
| 340 | m_nuhLayerId = nuhLayerid; |
|---|
| 341 | } |
|---|
| 342 | |
|---|
| 343 | TComPic* TComSubDpb::getPic( Int poc ) |
|---|
| 344 | { |
|---|
| 345 | TComPic* pic = NULL; |
|---|
| 346 | for(TComList<TComPic*>::iterator itP= begin(); ( itP!= end() && (pic == NULL) ); itP++) |
|---|
| 347 | { |
|---|
| 348 | if ( (*itP)->getPOC() == poc ) |
|---|
| 349 | { |
|---|
| 350 | pic = (*itP); |
|---|
| 351 | } |
|---|
| 352 | } |
|---|
| 353 | return pic; |
|---|
| 354 | } |
|---|
| 355 | |
|---|
| 356 | TComPic* TComSubDpb::getPicFromLsb( Int pocLsb, Int maxPicOrderCntLsb ) |
|---|
| 357 | { |
|---|
| 358 | TComPic* pic = NULL; |
|---|
| 359 | for(TComList<TComPic*>::iterator itP= begin(); ( itP!= end() && (pic == NULL) ); itP++) |
|---|
| 360 | { |
|---|
| 361 | if ( ( (*itP)->getPOC() & ( maxPicOrderCntLsb - 1 ) ) == pocLsb ) |
|---|
| 362 | { |
|---|
| 363 | pic = (*itP); |
|---|
| 364 | } |
|---|
| 365 | } |
|---|
| 366 | return pic; |
|---|
| 367 | } |
|---|
| 368 | |
|---|
| 369 | TComPic* TComSubDpb::getShortTermRefPic( Int poc ) |
|---|
| 370 | { |
|---|
| 371 | TComPic* pic = NULL; |
|---|
| 372 | for(TComList<TComPic*>::iterator itP= begin(); ( itP!= end() && (pic == NULL) ); itP++) |
|---|
| 373 | { |
|---|
| 374 | if ( (*itP)->getPOC() == poc && (*itP)->getMarkedAsShortTerm() ) |
|---|
| 375 | { |
|---|
| 376 | pic = (*itP); |
|---|
| 377 | } |
|---|
| 378 | } |
|---|
| 379 | return pic; |
|---|
| 380 | } |
|---|
| 381 | |
|---|
| 382 | TComList<TComPic*> TComSubDpb::getPicsMarkedNeedForOutput() |
|---|
| 383 | { |
|---|
| 384 | TComList<TComPic*> picsMarkedNeedForOutput; |
|---|
| 385 | |
|---|
| 386 | for(TComList<TComPic*>::iterator itP= begin(); itP!= end() ; itP++ ) |
|---|
| 387 | { |
|---|
| 388 | if ( (*itP)->getOutputMark() ) |
|---|
| 389 | { |
|---|
| 390 | picsMarkedNeedForOutput.push_back( (*itP) ); |
|---|
| 391 | } |
|---|
| 392 | } |
|---|
| 393 | return picsMarkedNeedForOutput; |
|---|
| 394 | } |
|---|
| 395 | |
|---|
| 396 | Void TComSubDpb::markAllAsUnusedForReference() |
|---|
| 397 | { |
|---|
| 398 | for(TComList<TComPic*>::iterator itP= begin(); itP!= end() ; itP++ ) |
|---|
| 399 | { |
|---|
| 400 | (*itP)->markAsUnusedForReference(); |
|---|
| 401 | } |
|---|
| 402 | } |
|---|
| 403 | |
|---|
| 404 | Void TComSubDpb::addPic( TComPic* pic ) |
|---|
| 405 | { |
|---|
| 406 | assert( pic != NULL ); |
|---|
| 407 | assert( m_nuhLayerId == pic->getLayerId() || m_nuhLayerId == -1); |
|---|
| 408 | if ( !empty() ) |
|---|
| 409 | { |
|---|
| 410 | assert( getPic( pic->getPOC() ) == NULL ); // Don't add twice; assert( pic->getLayerId() == m_nuhLayerId ); |
|---|
| 411 | |
|---|
| 412 | // Add sorted |
|---|
| 413 | TComSubDpb::iterator itP = begin(); |
|---|
| 414 | Bool inserted = false; |
|---|
| 415 | while( !inserted ) |
|---|
| 416 | { |
|---|
| 417 | if ( ( itP == end()) || pic->getPOC() < (*itP)->getPOC() ) |
|---|
| 418 | { |
|---|
| 419 | insert(itP, pic ); |
|---|
| 420 | inserted = true; |
|---|
| 421 | } |
|---|
| 422 | else |
|---|
| 423 | { |
|---|
| 424 | ++itP; |
|---|
| 425 | } |
|---|
| 426 | } |
|---|
| 427 | } |
|---|
| 428 | else |
|---|
| 429 | { |
|---|
| 430 | pushBack( pic ); |
|---|
| 431 | } |
|---|
| 432 | } |
|---|
| 433 | |
|---|
| 434 | Void TComSubDpb::removePics( std::vector<TComPic*> picToRemove ) |
|---|
| 435 | { |
|---|
| 436 | for (Int i = 0; i < picToRemove.size(); i++ ) |
|---|
| 437 | { |
|---|
| 438 | if( picToRemove[i] != NULL) |
|---|
| 439 | { |
|---|
| 440 | remove( picToRemove[i] ); |
|---|
| 441 | } |
|---|
| 442 | } |
|---|
| 443 | } |
|---|
| 444 | |
|---|
| 445 | Bool TComSubDpb::areAllPicsMarkedNotNeedForOutput() |
|---|
| 446 | { |
|---|
| 447 | return ( getPicsMarkedNeedForOutput().size() == 0 ); |
|---|
| 448 | } |
|---|
| 449 | |
|---|
| 450 | |
|---|
| 451 | TComPicLists::~TComPicLists() |
|---|
| 452 | { |
|---|
| 453 | emptyAllSubDpbs(); |
|---|
| 454 | for(TComList<TComSubDpb*>::iterator itL = m_subDpbs.begin(); ( itL != m_subDpbs.end()); itL++) |
|---|
| 455 | { |
|---|
| 456 | if ( (*itL) != NULL ) |
|---|
| 457 | { |
|---|
| 458 | delete (*itL); |
|---|
| 459 | (*itL) = NULL; |
|---|
| 460 | } |
|---|
| 461 | } |
|---|
| 462 | } |
|---|
| 463 | |
|---|
| 464 | Void TComPicLists::addNewPic( TComPic* pic ) |
|---|
| 465 | { |
|---|
| 466 | getSubDpb ( pic->getLayerId() , true )->addPic( pic ); |
|---|
| 467 | getAu ( pic->getPOC() , true )->addPic( pic , false ); |
|---|
| 468 | if ( m_printPicOutput ) |
|---|
| 469 | { |
|---|
| 470 | std::cout << " Add picture: "; |
|---|
| 471 | pic->print( 2 ); |
|---|
| 472 | std::cout << std::endl; |
|---|
| 473 | } |
|---|
| 474 | } |
|---|
| 475 | |
|---|
| 476 | Void TComPicLists::removePic( TComPic* pic ) |
|---|
| 477 | { |
|---|
| 478 | if (pic != NULL) |
|---|
| 479 | { |
|---|
| 480 | |
|---|
| 481 | TComSubDpb* curSubDpb = getSubDpb( pic->getLayerId(), false ); |
|---|
| 482 | curSubDpb->remove( pic ); |
|---|
| 483 | |
|---|
| 484 | TComAu* curAu = getAu ( pic->getPOC(), false ); |
|---|
| 485 | |
|---|
| 486 | if (curAu != NULL) |
|---|
| 487 | { |
|---|
| 488 | curAu->remove( pic ); |
|---|
| 489 | // Remove AU when empty. |
|---|
| 490 | if (curAu->empty() ) |
|---|
| 491 | { |
|---|
| 492 | m_aus.remove( curAu ); |
|---|
| 493 | delete curAu; |
|---|
| 494 | } |
|---|
| 495 | } |
|---|
| 496 | |
|---|
| 497 | if ( m_printPicOutput ) |
|---|
| 498 | { |
|---|
| 499 | std::cout << " Remove picture: "; |
|---|
| 500 | pic->print( 2 ); |
|---|
| 501 | std::cout << std::endl; |
|---|
| 502 | } |
|---|
| 503 | |
|---|
| 504 | pic->destroy(); |
|---|
| 505 | delete pic; |
|---|
| 506 | } |
|---|
| 507 | } |
|---|
| 508 | |
|---|
| 509 | TComPic* TComPicLists::getPic( Int layerIdInNuh, Int poc ) |
|---|
| 510 | { |
|---|
| 511 | TComPic* pcPic = NULL; |
|---|
| 512 | TComSubDpb* subDpb = getSubDpb( layerIdInNuh, false ); |
|---|
| 513 | if ( subDpb != NULL ) |
|---|
| 514 | { |
|---|
| 515 | pcPic = subDpb->getPic( poc ); |
|---|
| 516 | } |
|---|
| 517 | return pcPic; |
|---|
| 518 | } |
|---|
| 519 | |
|---|
| 520 | TComPicYuv* TComPicLists::getPicYuv( Int layerIdInNuh, Int poc, Bool reconFlag ) |
|---|
| 521 | { |
|---|
| 522 | TComPic* pcPic = getPic( layerIdInNuh, poc ); |
|---|
| 523 | TComPicYuv* pcPicYuv = NULL; |
|---|
| 524 | |
|---|
| 525 | if (pcPic != NULL) |
|---|
| 526 | { |
|---|
| 527 | if( reconFlag ) |
|---|
| 528 | { |
|---|
| 529 | if ( pcPic->getReconMark() ) |
|---|
| 530 | { |
|---|
| 531 | pcPicYuv = pcPic->getPicYuvRec(); |
|---|
| 532 | } |
|---|
| 533 | } |
|---|
| 534 | else |
|---|
| 535 | { |
|---|
| 536 | pcPicYuv = pcPic->getPicYuvOrg(); |
|---|
| 537 | } |
|---|
| 538 | }; |
|---|
| 539 | |
|---|
| 540 | return pcPicYuv; |
|---|
| 541 | } |
|---|
| 542 | |
|---|
| 543 | TComSubDpb* TComPicLists::getSubDpb( Int nuhLayerId, Bool create ) |
|---|
| 544 | { |
|---|
| 545 | TComSubDpb* subDpb = NULL; |
|---|
| 546 | for(TComList<TComSubDpb*>::iterator itL = m_subDpbs.begin(); ( itL != m_subDpbs.end() && subDpb == NULL ); itL++) |
|---|
| 547 | { |
|---|
| 548 | if ( (*itL)->getLayerId() == nuhLayerId ) |
|---|
| 549 | { |
|---|
| 550 | subDpb = (*itL); |
|---|
| 551 | } |
|---|
| 552 | } |
|---|
| 553 | if ( subDpb == NULL && create ) |
|---|
| 554 | { |
|---|
| 555 | m_subDpbs.push_back( new TComSubDpb(nuhLayerId) ); |
|---|
| 556 | } |
|---|
| 557 | return subDpb; |
|---|
| 558 | } |
|---|
| 559 | |
|---|
| 560 | TComList<TComSubDpb*>* TComPicLists::getSubDpbs() |
|---|
| 561 | { |
|---|
| 562 | return (&m_subDpbs); |
|---|
| 563 | } |
|---|
| 564 | |
|---|
| 565 | TComAu* TComPicLists::addAu( Int poc ) |
|---|
| 566 | { |
|---|
| 567 | TComList<TComAu*>::iterator itA = m_aus.begin(); |
|---|
| 568 | |
|---|
| 569 | assert( getAu(poc, false) == NULL ); |
|---|
| 570 | Bool inserted = false; |
|---|
| 571 | while( !inserted) |
|---|
| 572 | { |
|---|
| 573 | if ( ( itA == m_aus.end()) || poc < (*itA)->getPoc() ) |
|---|
| 574 | { |
|---|
| 575 | m_aus.insert(itA, new TComAu ); |
|---|
| 576 | inserted = true; |
|---|
| 577 | --itA; |
|---|
| 578 | } |
|---|
| 579 | else |
|---|
| 580 | { |
|---|
| 581 | ++itA; |
|---|
| 582 | } |
|---|
| 583 | } |
|---|
| 584 | return (*itA); |
|---|
| 585 | } |
|---|
| 586 | |
|---|
| 587 | TComAu* TComPicLists::getAu( Int poc, Bool create ) |
|---|
| 588 | { |
|---|
| 589 | TComAu* au = NULL; |
|---|
| 590 | |
|---|
| 591 | for( TComList<TComAu*>::iterator itA = m_aus.begin(); ( itA != m_aus.end() && au == NULL ); itA++) |
|---|
| 592 | { |
|---|
| 593 | if ( (*itA)->getPoc() == poc ) |
|---|
| 594 | { |
|---|
| 595 | au = (*itA); |
|---|
| 596 | } |
|---|
| 597 | } |
|---|
| 598 | |
|---|
| 599 | if ( au == NULL && create ) |
|---|
| 600 | { |
|---|
| 601 | au = addAu( poc ); |
|---|
| 602 | } |
|---|
| 603 | return au; |
|---|
| 604 | } |
|---|
| 605 | |
|---|
| 606 | TComList<TComAu*>* TComPicLists::getAus() |
|---|
| 607 | { |
|---|
| 608 | return (&m_aus); |
|---|
| 609 | } |
|---|
| 610 | |
|---|
| 611 | TComList<TComAu*> TComPicLists::getAusHavingPicsMarkedForOutput() |
|---|
| 612 | { |
|---|
| 613 | TComList<TComAu*> ausHavingPicsForOutput; |
|---|
| 614 | for(TComList<TComAu*>::iterator itA= m_aus.begin(); ( itA!=m_aus.end()); itA++) |
|---|
| 615 | { |
|---|
| 616 | Bool hasPicMarkedAsNeedForOutput = false; |
|---|
| 617 | for( TComAu::iterator itP= (*itA)->begin(); (itP!=(*itA)->end() && !hasPicMarkedAsNeedForOutput); itP++ ) |
|---|
| 618 | { |
|---|
| 619 | if( (*itP)->getOutputMark() ) |
|---|
| 620 | { |
|---|
| 621 | hasPicMarkedAsNeedForOutput = true; |
|---|
| 622 | } |
|---|
| 623 | } |
|---|
| 624 | if (hasPicMarkedAsNeedForOutput) |
|---|
| 625 | { |
|---|
| 626 | ausHavingPicsForOutput.pushBack( (*itA) ); |
|---|
| 627 | } |
|---|
| 628 | } |
|---|
| 629 | return ausHavingPicsForOutput; |
|---|
| 630 | } |
|---|
| 631 | |
|---|
| 632 | Void TComPicLists::markSubDpbAsUnusedForReference( Int layerIdInNuh ) |
|---|
| 633 | { |
|---|
| 634 | TComSubDpb* subDpb = getSubDpb( layerIdInNuh, false ); |
|---|
| 635 | markSubDpbAsUnusedForReference( *subDpb ); |
|---|
| 636 | } |
|---|
| 637 | |
|---|
| 638 | Void TComPicLists::markSubDpbAsUnusedForReference( TComSubDpb& subDpb ) |
|---|
| 639 | { |
|---|
| 640 | for(TComList<TComPic*>::iterator itP=subDpb.begin(); ( itP!=subDpb.end()); itP++) |
|---|
| 641 | { |
|---|
| 642 | (*itP)->markAsUnusedForReference(); |
|---|
| 643 | } |
|---|
| 644 | } |
|---|
| 645 | |
|---|
| 646 | Void TComPicLists::markAllSubDpbAsUnusedForReference() |
|---|
| 647 | { |
|---|
| 648 | for(TComList<TComSubDpb*>::iterator itS= m_subDpbs.begin(); ( itS!=m_subDpbs.end()); itS++) |
|---|
| 649 | { |
|---|
| 650 | markSubDpbAsUnusedForReference( *(*itS) ); |
|---|
| 651 | } |
|---|
| 652 | } |
|---|
| 653 | |
|---|
| 654 | Void TComPicLists::decrementPocsInSubDpb( Int nuhLayerId, Int deltaPocVal ) |
|---|
| 655 | { |
|---|
| 656 | TComSubDpb* subDpb = getSubDpb( nuhLayerId, false ); |
|---|
| 657 | |
|---|
| 658 | for(TComSubDpb::iterator itP = subDpb->begin(); itP!=subDpb->end(); itP++) |
|---|
| 659 | { |
|---|
| 660 | TComPic* pic = (*itP); |
|---|
| 661 | for (Int i = 0; i < pic->getNumAllocatedSlice(); i++) |
|---|
| 662 | { |
|---|
| 663 | TComSlice* slice = pic->getSlice(i); |
|---|
| 664 | slice->setPOC( slice->getPOC() - deltaPocVal ); |
|---|
| 665 | } |
|---|
| 666 | } |
|---|
| 667 | } |
|---|
| 668 | Void TComPicLists::emptyAllSubDpbs() |
|---|
| 669 | { |
|---|
| 670 | emptySubDpbs( &m_subDpbs ); |
|---|
| 671 | } |
|---|
| 672 | |
|---|
| 673 | Void TComPicLists::emptySubDpbs( TComList<TComSubDpb*>* subDpbs ) |
|---|
| 674 | { |
|---|
| 675 | assert( subDpbs != NULL ); |
|---|
| 676 | for( TComList<TComSubDpb*>::iterator itS = subDpbs->begin(); itS != subDpbs->end(); itS++ ) |
|---|
| 677 | { |
|---|
| 678 | emptySubDpb( (*itS) ); |
|---|
| 679 | } |
|---|
| 680 | } |
|---|
| 681 | |
|---|
| 682 | Void TComPicLists::emptySubDpb( TComSubDpb* subDpb ) |
|---|
| 683 | { |
|---|
| 684 | if(subDpb != NULL) |
|---|
| 685 | { |
|---|
| 686 | while( !subDpb->empty() ) |
|---|
| 687 | { |
|---|
| 688 | TComPic* curPic = *(subDpb->begin()); |
|---|
| 689 | removePic( curPic ); |
|---|
| 690 | } |
|---|
| 691 | } |
|---|
| 692 | } |
|---|
| 693 | |
|---|
| 694 | Void TComPicLists::emptySubDpb( Int nuhLayerId ) |
|---|
| 695 | { |
|---|
| 696 | emptySubDpb( getSubDpb( nuhLayerId , false) ); |
|---|
| 697 | } |
|---|
| 698 | |
|---|
| 699 | Void TComPicLists::emptyNotNeedForOutputAndUnusedForRef() |
|---|
| 700 | { |
|---|
| 701 | for(TComList<TComSubDpb*>::iterator itS= m_subDpbs.begin(); ( itS!=m_subDpbs.end()); itS++) |
|---|
| 702 | { |
|---|
| 703 | emptySubDpbNotNeedForOutputAndUnusedForRef( *(*itS) ); |
|---|
| 704 | } |
|---|
| 705 | } |
|---|
| 706 | |
|---|
| 707 | Void TComPicLists::emptySubDpbNotNeedForOutputAndUnusedForRef( Int layerId ) |
|---|
| 708 | { |
|---|
| 709 | TComSubDpb* subDpb = getSubDpb( layerId, false ); |
|---|
| 710 | emptySubDpbNotNeedForOutputAndUnusedForRef( *subDpb ); |
|---|
| 711 | } |
|---|
| 712 | |
|---|
| 713 | Void TComPicLists::emptySubDpbNotNeedForOutputAndUnusedForRef( TComSubDpb subDpb ) |
|---|
| 714 | { |
|---|
| 715 | for(TComSubDpb::iterator itP= subDpb.begin(); ( itP!=subDpb.end()); itP++) |
|---|
| 716 | { |
|---|
| 717 | TComPic* pic = (*itP); |
|---|
| 718 | if ( !pic->getOutputMark() && pic->getMarkedUnUsedForReference() ) |
|---|
| 719 | { |
|---|
| 720 | removePic( pic ); |
|---|
| 721 | } |
|---|
| 722 | } |
|---|
| 723 | } |
|---|
| 724 | |
|---|
| 725 | Void TComPicLists::print() |
|---|
| 726 | { |
|---|
| 727 | Bool first = true; |
|---|
| 728 | for(TComList<TComSubDpb*>::iterator itL = m_subDpbs.begin(); ( itL != m_subDpbs.end() ); itL++) |
|---|
| 729 | { |
|---|
| 730 | for(TComList<TComPic*>::iterator itP=(*itL)->begin(); ( itP!=(*itL)->end() ); itP++) |
|---|
| 731 | { |
|---|
| 732 | if ( first ) |
|---|
| 733 | { |
|---|
| 734 | (*itP)->print( true ); |
|---|
| 735 | first = false; |
|---|
| 736 | } |
|---|
| 737 | (*itP)->print( false ); |
|---|
| 738 | } |
|---|
| 739 | } |
|---|
| 740 | } |
|---|
| 741 | |
|---|
| 742 | |
|---|
| 743 | #endif |
|---|
| 744 | |
|---|
| 745 | |
|---|
| 746 | |
|---|
| 747 | |
|---|
| 748 | //! \} |
|---|
| 749 | |
|---|