[313] | 1 | /* The copyright in this software is being made available under the BSD |
---|
| 2 | * License, included below. This software may be subject to other third party |
---|
| 3 | * and contributor rights, including patent rights, and no such rights are |
---|
[494] | 4 | * granted under this license. |
---|
[313] | 5 | * |
---|
[1549] | 6 | * Copyright (c) 2010-2016, ITU/ISO/IEC |
---|
[313] | 7 | * All rights reserved. |
---|
| 8 | * |
---|
| 9 | * Redistribution and use in source and binary forms, with or without |
---|
| 10 | * modification, are permitted provided that the following conditions are met: |
---|
| 11 | * |
---|
| 12 | * * Redistributions of source code must retain the above copyright notice, |
---|
| 13 | * this list of conditions and the following disclaimer. |
---|
| 14 | * * Redistributions in binary form must reproduce the above copyright notice, |
---|
| 15 | * this list of conditions and the following disclaimer in the documentation |
---|
| 16 | * and/or other materials provided with the distribution. |
---|
| 17 | * * Neither the name of the ITU/ISO/IEC nor the names of its contributors may |
---|
| 18 | * be used to endorse or promote products derived from this software without |
---|
| 19 | * specific prior written permission. |
---|
| 20 | * |
---|
| 21 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
---|
| 22 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
---|
| 23 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
---|
| 24 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS |
---|
| 25 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
---|
| 26 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
---|
| 27 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
---|
| 28 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
---|
| 29 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
---|
| 30 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF |
---|
| 31 | * THE POSSIBILITY OF SUCH DAMAGE. |
---|
| 32 | */ |
---|
| 33 | |
---|
| 34 | /** \file TAppDecTop.cpp |
---|
| 35 | \brief Decoder application class |
---|
| 36 | */ |
---|
| 37 | |
---|
| 38 | #include <list> |
---|
| 39 | #include <vector> |
---|
| 40 | #include <stdio.h> |
---|
| 41 | #include <fcntl.h> |
---|
| 42 | #include <assert.h> |
---|
[1029] | 43 | |
---|
[313] | 44 | #include "TAppDecTop.h" |
---|
| 45 | #include "TLibDecoder/AnnexBread.h" |
---|
| 46 | #include "TLibDecoder/NALread.h" |
---|
[1029] | 47 | #if RExt__DECODER_DEBUG_BIT_STATISTICS |
---|
| 48 | #include "TLibCommon/TComCodingStatistics.h" |
---|
| 49 | #endif |
---|
| 50 | #if CONFORMANCE_BITSTREAM_MODE |
---|
[924] | 51 | #include "TLibCommon/TComPicYuv.h" |
---|
| 52 | #include "libmd5/MD5.h" |
---|
[1029] | 53 | #endif |
---|
| 54 | |
---|
[313] | 55 | //! \ingroup TAppDecoder |
---|
| 56 | //! \{ |
---|
| 57 | |
---|
| 58 | // ==================================================================================================================== |
---|
| 59 | // Constructor / destructor / initialization / destroy |
---|
| 60 | // ==================================================================================================================== |
---|
| 61 | |
---|
| 62 | #if SVC_EXTENSION |
---|
| 63 | TAppDecTop::TAppDecTop() |
---|
[1460] | 64 | : m_pcSeiColourRemappingInfoPrevious(NULL) |
---|
[313] | 65 | { |
---|
[1420] | 66 | memset( m_apcTDecTop, 0, sizeof(m_apcTDecTop) ); |
---|
| 67 | memset( m_apcTVideoIOYuvReconFile, 0, sizeof(m_apcTVideoIOYuvReconFile) ); |
---|
[1292] | 68 | |
---|
[313] | 69 | for(UInt layer=0; layer < MAX_LAYERS; layer++) |
---|
| 70 | { |
---|
| 71 | m_aiPOCLastDisplay[layer] = -MAX_INT; |
---|
| 72 | } |
---|
| 73 | } |
---|
| 74 | #else |
---|
| 75 | TAppDecTop::TAppDecTop() |
---|
| 76 | : m_iPOCLastDisplay(-MAX_INT) |
---|
[1460] | 77 | ,m_pcSeiColourRemappingInfoPrevious(NULL) |
---|
[313] | 78 | { |
---|
| 79 | } |
---|
| 80 | #endif |
---|
| 81 | |
---|
| 82 | Void TAppDecTop::create() |
---|
| 83 | { |
---|
| 84 | } |
---|
| 85 | |
---|
| 86 | Void TAppDecTop::destroy() |
---|
| 87 | { |
---|
[1442] | 88 | m_bitstreamFileName.clear(); |
---|
[494] | 89 | #if SVC_EXTENSION |
---|
[1106] | 90 | #if CONFORMANCE_BITSTREAM_MODE |
---|
[1044] | 91 | for(Int i = 0; i < MAX_VPS_LAYER_IDX_PLUS1; i++ ) |
---|
[953] | 92 | #else |
---|
[1524] | 93 | for( Int i = 0; i <= m_commonDecoderParams.getTargetLayerId(); i++ ) |
---|
[953] | 94 | #endif |
---|
[313] | 95 | { |
---|
[1442] | 96 | m_reconFileName[i].clear(); |
---|
[1378] | 97 | |
---|
| 98 | if( m_apcTDecTop[i] ) |
---|
| 99 | { |
---|
| 100 | delete m_apcTDecTop[i]; |
---|
| 101 | m_apcTDecTop[i] = NULL; |
---|
| 102 | } |
---|
| 103 | |
---|
| 104 | if( m_apcTVideoIOYuvReconFile[i] ) |
---|
| 105 | { |
---|
| 106 | delete m_apcTVideoIOYuvReconFile[i]; |
---|
| 107 | m_apcTVideoIOYuvReconFile[i] = NULL; |
---|
| 108 | } |
---|
[494] | 109 | } |
---|
[313] | 110 | #if AVC_BASE |
---|
[1442] | 111 | m_reconFileNameBL.clear(); |
---|
[313] | 112 | #endif |
---|
| 113 | #else |
---|
[1442] | 114 | m_reconFileName.clear(); |
---|
[313] | 115 | #endif |
---|
| 116 | } |
---|
| 117 | |
---|
| 118 | // ==================================================================================================================== |
---|
| 119 | // Public member functions |
---|
| 120 | // ==================================================================================================================== |
---|
| 121 | |
---|
| 122 | /** |
---|
| 123 | - create internal class |
---|
| 124 | - initialize internal class |
---|
| 125 | - until the end of the bitstream, call decoding function in TDecTop class |
---|
| 126 | - delete allocated buffers |
---|
| 127 | - destroy internal class |
---|
| 128 | . |
---|
| 129 | */ |
---|
| 130 | Void TAppDecTop::decode() |
---|
| 131 | { |
---|
[1470] | 132 | Int poc; |
---|
[313] | 133 | TComList<TComPic*>* pcListPic = NULL; |
---|
| 134 | |
---|
[1442] | 135 | ifstream bitstreamFile(m_bitstreamFileName.c_str(), ifstream::in | ifstream::binary); |
---|
[313] | 136 | if (!bitstreamFile) |
---|
| 137 | { |
---|
[1442] | 138 | fprintf(stderr, "\nfailed to open bitstream file `%s' for reading\n", m_bitstreamFileName.c_str()); |
---|
[313] | 139 | exit(EXIT_FAILURE); |
---|
| 140 | } |
---|
| 141 | |
---|
| 142 | InputByteStream bytestream(bitstreamFile); |
---|
| 143 | |
---|
[1029] | 144 | if (!m_outputDecodedSEIMessagesFilename.empty() && m_outputDecodedSEIMessagesFilename!="-") |
---|
| 145 | { |
---|
| 146 | m_seiMessageFileStream.open(m_outputDecodedSEIMessagesFilename.c_str(), std::ios::out); |
---|
| 147 | if (!m_seiMessageFileStream.is_open() || !m_seiMessageFileStream.good()) |
---|
| 148 | { |
---|
| 149 | fprintf(stderr, "\nUnable to open file `%s' for writing decoded SEI messages\n", m_outputDecodedSEIMessagesFilename.c_str()); |
---|
| 150 | exit(EXIT_FAILURE); |
---|
| 151 | } |
---|
| 152 | } |
---|
| 153 | |
---|
[313] | 154 | // create & initialize internal classes |
---|
| 155 | xCreateDecLib(); |
---|
[1470] | 156 | xInitDecLib (); |
---|
[1471] | 157 | #if !SVC_EXTENSION |
---|
| 158 | m_iPOCLastDisplay += m_iSkipFrame; // set the last displayed POC correctly for skip forward. |
---|
| 159 | #endif |
---|
[313] | 160 | |
---|
[1470] | 161 | // clear contents of colour-remap-information-SEI output file |
---|
| 162 | if (!m_colourRemapSEIFileName.empty()) |
---|
| 163 | { |
---|
| 164 | std::ofstream ofile(m_colourRemapSEIFileName.c_str()); |
---|
| 165 | if (!ofile.good() || !ofile.is_open()) |
---|
| 166 | { |
---|
| 167 | fprintf(stderr, "\nUnable to open file '%s' for writing colour-remap-information-SEI video\n", m_colourRemapSEIFileName.c_str()); |
---|
| 168 | exit(EXIT_FAILURE); |
---|
| 169 | } |
---|
| 170 | } |
---|
| 171 | |
---|
[313] | 172 | // main decoder loop |
---|
[1471] | 173 | #if SVC_EXTENSION |
---|
[442] | 174 | Bool openedReconFile[MAX_LAYERS]; // reconstruction file not yet opened. (must be performed after SPS is seen) |
---|
[540] | 175 | Bool loopFiltered[MAX_LAYERS]; |
---|
| 176 | memset( loopFiltered, false, sizeof( loopFiltered ) ); |
---|
| 177 | |
---|
[1106] | 178 | #if CONFORMANCE_BITSTREAM_MODE |
---|
[1044] | 179 | for(UInt layer = 0; layer < MAX_VPS_LAYER_IDX_PLUS1; layer++) |
---|
[953] | 180 | #else |
---|
[1524] | 181 | for(UInt layer=0; layer <= m_commonDecoderParams.getTargetLayerId(); layer++) |
---|
[953] | 182 | #endif |
---|
[313] | 183 | { |
---|
[442] | 184 | openedReconFile[layer] = false; |
---|
[313] | 185 | m_aiPOCLastDisplay[layer] += m_iSkipFrame; // set the last displayed POC correctly for skip forward. |
---|
| 186 | } |
---|
| 187 | |
---|
| 188 | UInt curLayerId = 0; // current layer to be reconstructed |
---|
| 189 | |
---|
| 190 | #if AVC_BASE |
---|
| 191 | TComPic pcBLPic; |
---|
| 192 | fstream streamYUV; |
---|
[1442] | 193 | if( !m_reconFileNameBL.empty() ) |
---|
[313] | 194 | { |
---|
[1445] | 195 | streamYUV.open( m_reconFileNameBL.c_str(), fstream::in | fstream::binary ); |
---|
[313] | 196 | } |
---|
[1378] | 197 | m_apcTDecTop[0]->setBLReconFile( &streamYUV ); |
---|
[313] | 198 | pcBLPic.setLayerId( 0 ); |
---|
[1490] | 199 | m_apcTDecTop[0]->setBlPic(&pcBLPic); |
---|
[313] | 200 | #endif |
---|
| 201 | |
---|
| 202 | while (!!bitstreamFile) |
---|
| 203 | { |
---|
| 204 | /* location serves to work around a design fault in the decoder, whereby |
---|
| 205 | * the process of reading a new slice that is the first slice of a new frame |
---|
| 206 | * requires the TDecTop::decode() method to be called again with the same |
---|
| 207 | * nal unit. */ |
---|
[1029] | 208 | #if RExt__DECODER_DEBUG_BIT_STATISTICS |
---|
| 209 | TComCodingStatistics::TComCodingStatisticsData backupStats(TComCodingStatistics::GetStatistics()); |
---|
| 210 | streampos location = bitstreamFile.tellg() - streampos(bytestream.GetNumBufferedBytes()); |
---|
| 211 | #else |
---|
[313] | 212 | streampos location = bitstreamFile.tellg(); |
---|
[1029] | 213 | #endif |
---|
[313] | 214 | AnnexBStats stats = AnnexBStats(); |
---|
| 215 | |
---|
| 216 | InputNALUnit nalu; |
---|
[1319] | 217 | byteStreamNALUnit(bytestream, nalu.getBitstream().getFifo(), stats); |
---|
[1029] | 218 | |
---|
[313] | 219 | // call actual decoding function |
---|
| 220 | Bool bNewPicture = false; |
---|
| 221 | Bool bNewPOC = false; |
---|
[1029] | 222 | |
---|
[1319] | 223 | if (nalu.getBitstream().getFifo().empty()) |
---|
[313] | 224 | { |
---|
| 225 | /* this can happen if the following occur: |
---|
| 226 | * - empty input file |
---|
| 227 | * - two back-to-back start_code_prefixes |
---|
| 228 | * - start_code_prefix immediately followed by EOF |
---|
| 229 | */ |
---|
| 230 | fprintf(stderr, "Warning: Attempt to decode an empty NAL unit\n"); |
---|
| 231 | } |
---|
| 232 | else |
---|
| 233 | { |
---|
[1319] | 234 | read(nalu); |
---|
[1485] | 235 | |
---|
| 236 | // ignore any NAL units with nuh_layer_id == 63 |
---|
| 237 | if( nalu.m_nuhLayerId == 63 ) |
---|
| 238 | { |
---|
| 239 | printf("Ignore NAL unit with m_nuhLayerId equal to 63\n"); |
---|
| 240 | continue; |
---|
| 241 | } |
---|
| 242 | |
---|
[1524] | 243 | if( (m_iMaxTemporalLayer >= 0 && nalu.m_temporalId > m_iMaxTemporalLayer) || !isNaluWithinTargetDecLayerIdSet(&nalu) || nalu.m_nuhLayerId > m_commonDecoderParams.getTargetLayerId() ) |
---|
[313] | 244 | { |
---|
| 245 | bNewPicture = false; |
---|
| 246 | } |
---|
| 247 | else |
---|
| 248 | { |
---|
[1378] | 249 | bNewPicture = m_apcTDecTop[nalu.m_nuhLayerId]->decode(nalu, m_iSkipFrame, m_aiPOCLastDisplay[nalu.m_nuhLayerId], curLayerId, bNewPOC); |
---|
[1210] | 250 | |
---|
| 251 | #if SVC_POC |
---|
[1378] | 252 | if( (bNewPicture && m_apcTDecTop[nalu.m_nuhLayerId]->getParseIdc() == 3) || (m_apcTDecTop[nalu.m_nuhLayerId]->getParseIdc() == 0) ) |
---|
[815] | 253 | #else |
---|
[313] | 254 | if (bNewPicture) |
---|
[815] | 255 | #endif |
---|
[313] | 256 | { |
---|
| 257 | bitstreamFile.clear(); |
---|
| 258 | /* location points to the current nalunit payload[1] due to the |
---|
| 259 | * need for the annexB parser to read three extra bytes. |
---|
| 260 | * [1] except for the first NAL unit in the file |
---|
| 261 | * (but bNewPicture doesn't happen then) */ |
---|
[1029] | 262 | #if RExt__DECODER_DEBUG_BIT_STATISTICS |
---|
| 263 | bitstreamFile.seekg(location); |
---|
| 264 | bytestream.reset(); |
---|
| 265 | TComCodingStatistics::SetStatistics(backupStats); |
---|
| 266 | #else |
---|
[313] | 267 | bitstreamFile.seekg(location-streamoff(3)); |
---|
| 268 | bytestream.reset(); |
---|
[1029] | 269 | #endif |
---|
[313] | 270 | } |
---|
[1210] | 271 | #if SVC_POC |
---|
[1378] | 272 | else if(m_apcTDecTop[nalu.m_nuhLayerId]->getParseIdc() == 1) |
---|
[815] | 273 | { |
---|
| 274 | bitstreamFile.clear(); |
---|
| 275 | // This is before third parse of the NAL unit, and |
---|
| 276 | // location points to correct beginning of the NALU |
---|
| 277 | bitstreamFile.seekg(location); |
---|
| 278 | bytestream.reset(); |
---|
[1029] | 279 | #if RExt__DECODER_DEBUG_BIT_STATISTICS |
---|
| 280 | TComCodingStatistics::SetStatistics(backupStats); |
---|
| 281 | #endif |
---|
[815] | 282 | } |
---|
| 283 | #endif |
---|
[313] | 284 | } |
---|
| 285 | } |
---|
[540] | 286 | |
---|
[1210] | 287 | #if SVC_POC |
---|
[1378] | 288 | if( ( (bNewPicture && m_apcTDecTop[nalu.m_nuhLayerId]->getParseIdc() == 3) || m_apcTDecTop[nalu.m_nuhLayerId]->getParseIdc() == 0 || !bitstreamFile || nalu.m_nalUnitType == NAL_UNIT_EOS ) && |
---|
| 289 | !m_apcTDecTop[nalu.m_nuhLayerId]->getFirstSliceInSequence() ) |
---|
[815] | 290 | #else |
---|
[1029] | 291 | if ( (bNewPicture || !bitstreamFile || nalu.m_nalUnitType == NAL_UNIT_EOS) && |
---|
[1378] | 292 | !m_apcTDecTop[nalu.m_nuhLayerId]->getFirstSliceInSequence() ) |
---|
[815] | 293 | #endif |
---|
[313] | 294 | { |
---|
[540] | 295 | if (!loopFiltered[curLayerId] || bitstreamFile) |
---|
| 296 | { |
---|
[1378] | 297 | m_apcTDecTop[curLayerId]->executeLoopFilters(poc, pcListPic); |
---|
[540] | 298 | } |
---|
| 299 | loopFiltered[curLayerId] = (nalu.m_nalUnitType == NAL_UNIT_EOS); |
---|
[1103] | 300 | |
---|
[1029] | 301 | if (nalu.m_nalUnitType == NAL_UNIT_EOS) |
---|
| 302 | { |
---|
[1378] | 303 | m_apcTDecTop[nalu.m_nuhLayerId]->setFirstSliceInSequence(true); |
---|
[1029] | 304 | } |
---|
[313] | 305 | } |
---|
[1029] | 306 | else if ( (bNewPicture || !bitstreamFile || nalu.m_nalUnitType == NAL_UNIT_EOS ) && |
---|
[1378] | 307 | m_apcTDecTop[nalu.m_nuhLayerId]->getFirstSliceInSequence () ) |
---|
[1029] | 308 | { |
---|
[1378] | 309 | m_apcTDecTop[nalu.m_nuhLayerId]->setFirstSliceInPicture (true); |
---|
[1029] | 310 | } |
---|
[313] | 311 | |
---|
[1210] | 312 | #if SVC_POC |
---|
[1378] | 313 | if( bNewPicture && m_apcTDecTop[nalu.m_nuhLayerId]->getParseIdc() == 0 ) |
---|
[815] | 314 | { |
---|
[1237] | 315 | outputAllPictures( nalu.m_nuhLayerId, true ); |
---|
[815] | 316 | } |
---|
| 317 | #endif |
---|
| 318 | |
---|
[313] | 319 | if( pcListPic ) |
---|
| 320 | { |
---|
[1521] | 321 | if ( !m_reconFileName[curLayerId].empty() && !openedReconFile[curLayerId] && m_apcTDecTop[curLayerId]->getParameterSetManager()->getActiveSPS()) |
---|
[313] | 322 | { |
---|
[1502] | 323 | const BitDepths& bitDepths = m_apcTDecTop[curLayerId]->getParameterSetManager()->getActiveSPS()->getBitDepths(); |
---|
[1472] | 324 | |
---|
| 325 | for( UInt channelType = 0; channelType < MAX_NUM_CHANNEL_TYPE; channelType++) |
---|
[1029] | 326 | { |
---|
[1472] | 327 | if( m_outputBitDepth[curLayerId][channelType] == 0 ) |
---|
[1246] | 328 | { |
---|
[1472] | 329 | m_outputBitDepth[curLayerId][channelType] = bitDepths.recon[channelType]; |
---|
[1246] | 330 | } |
---|
[1029] | 331 | } |
---|
[1472] | 332 | m_apcTVideoIOYuvReconFile[curLayerId]->open( m_reconFileName[curLayerId], true, m_outputBitDepth[curLayerId], m_outputBitDepth[curLayerId], bitDepths.recon ); // write mode |
---|
[313] | 333 | |
---|
[442] | 334 | openedReconFile[curLayerId] = true; |
---|
[313] | 335 | } |
---|
[644] | 336 | #if ALIGNED_BUMPING |
---|
| 337 | Bool outputPicturesFlag = true; |
---|
[1139] | 338 | |
---|
[1378] | 339 | if( m_apcTDecTop[nalu.m_nuhLayerId]->getNoOutputPriorPicsFlag() ) |
---|
[644] | 340 | { |
---|
| 341 | outputPicturesFlag = false; |
---|
| 342 | } |
---|
| 343 | |
---|
| 344 | if (nalu.m_nalUnitType == NAL_UNIT_EOS) // End of sequence |
---|
| 345 | { |
---|
[1237] | 346 | flushAllPictures( nalu.m_nuhLayerId, outputPicturesFlag ); |
---|
[644] | 347 | } |
---|
[815] | 348 | |
---|
[1210] | 349 | #if SVC_POC |
---|
[1378] | 350 | if( bNewPicture && m_apcTDecTop[nalu.m_nuhLayerId]->getParseIdc() != 0 ) |
---|
[815] | 351 | // New picture, slice header parsed but picture not decoded |
---|
| 352 | #else |
---|
[644] | 353 | if( bNewPicture ) // New picture, slice header parsed but picture not decoded |
---|
[815] | 354 | #endif |
---|
[644] | 355 | { |
---|
[1139] | 356 | if( nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_IDR_W_RADL |
---|
[644] | 357 | || nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_IDR_N_LP |
---|
| 358 | || nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_BLA_N_LP |
---|
| 359 | || nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_BLA_W_RADL |
---|
[1139] | 360 | || nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_BLA_W_LP ) |
---|
[644] | 361 | { |
---|
[1237] | 362 | flushAllPictures( nalu.m_nuhLayerId, outputPicturesFlag ); |
---|
[644] | 363 | } |
---|
| 364 | else |
---|
| 365 | { |
---|
[1237] | 366 | this->checkOutputBeforeDecoding( nalu.m_nuhLayerId ); |
---|
[644] | 367 | } |
---|
| 368 | } |
---|
| 369 | |
---|
| 370 | /* The following code has to be executed when the last DU of the picture is decoded |
---|
| 371 | TODO: Need code to identify end of decoding a picture |
---|
| 372 | { |
---|
| 373 | this->checkOutputAfterDecoding( ); |
---|
| 374 | } */ |
---|
| 375 | #else |
---|
[494] | 376 | if ( bNewPicture && bNewPOC && |
---|
[313] | 377 | ( nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_IDR_W_RADL |
---|
| 378 | || nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_IDR_N_LP |
---|
| 379 | || nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_BLA_N_LP |
---|
| 380 | || nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_BLA_W_RADL |
---|
| 381 | || nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_BLA_W_LP ) ) |
---|
| 382 | { |
---|
| 383 | xFlushOutput( pcListPic, curLayerId ); |
---|
| 384 | } |
---|
[540] | 385 | if (nalu.m_nalUnitType == NAL_UNIT_EOS) |
---|
| 386 | { |
---|
| 387 | xFlushOutput( pcListPic, curLayerId ); |
---|
| 388 | } |
---|
[313] | 389 | // write reconstruction to file |
---|
| 390 | if(bNewPicture) |
---|
| 391 | { |
---|
| 392 | xWriteOutput( pcListPic, curLayerId, nalu.m_temporalId ); |
---|
| 393 | } |
---|
[644] | 394 | #endif |
---|
[313] | 395 | } |
---|
| 396 | } |
---|
[644] | 397 | #if ALIGNED_BUMPING |
---|
| 398 | flushAllPictures( true ); |
---|
| 399 | #else |
---|
[313] | 400 | for(UInt layer = 0; layer <= m_tgtLayerId; layer++) |
---|
| 401 | { |
---|
[1378] | 402 | xFlushOutput( m_apcTDecTop[layer]->getListPic(), layer ); |
---|
[313] | 403 | } |
---|
[644] | 404 | #endif |
---|
[313] | 405 | // delete buffers |
---|
| 406 | #if AVC_BASE |
---|
[1378] | 407 | UInt layerIdxmin = m_apcTDecTop[0]->getBLReconFile()->is_open() ? 1 : 0; |
---|
[442] | 408 | |
---|
[313] | 409 | if( streamYUV.is_open() ) |
---|
| 410 | { |
---|
| 411 | streamYUV.close(); |
---|
| 412 | } |
---|
| 413 | |
---|
[1106] | 414 | #if CONFORMANCE_BITSTREAM_MODE |
---|
[1052] | 415 | for(UInt layer = layerIdxmin; layer < MAX_VPS_LAYER_IDX_PLUS1; layer++) |
---|
[953] | 416 | #else |
---|
[1524] | 417 | for(UInt layer = layerIdxmin; layer <= m_commonDecoderParams.getTargetLayerId(); layer++) |
---|
[953] | 418 | #endif |
---|
[313] | 419 | #else |
---|
[1524] | 420 | for(UInt layer = 0; layer <= m_commonDecoderParams.getTargetLayerId(); layer++) |
---|
[313] | 421 | #endif |
---|
| 422 | { |
---|
[1378] | 423 | m_apcTDecTop[layer]->deletePicBuffer(); |
---|
[313] | 424 | } |
---|
[494] | 425 | |
---|
[313] | 426 | // destroy internal classes |
---|
| 427 | xDestroyDecLib(); |
---|
| 428 | #else |
---|
[442] | 429 | Bool openedReconFile = false; // reconstruction file not yet opened. (must be performed after SPS is seen) |
---|
[540] | 430 | Bool loopFiltered = false; |
---|
[313] | 431 | |
---|
| 432 | while (!!bitstreamFile) |
---|
| 433 | { |
---|
| 434 | /* location serves to work around a design fault in the decoder, whereby |
---|
| 435 | * the process of reading a new slice that is the first slice of a new frame |
---|
| 436 | * requires the TDecTop::decode() method to be called again with the same |
---|
| 437 | * nal unit. */ |
---|
[1029] | 438 | #if RExt__DECODER_DEBUG_BIT_STATISTICS |
---|
| 439 | TComCodingStatistics::TComCodingStatisticsData backupStats(TComCodingStatistics::GetStatistics()); |
---|
| 440 | streampos location = bitstreamFile.tellg() - streampos(bytestream.GetNumBufferedBytes()); |
---|
| 441 | #else |
---|
[313] | 442 | streampos location = bitstreamFile.tellg(); |
---|
[1029] | 443 | #endif |
---|
[313] | 444 | AnnexBStats stats = AnnexBStats(); |
---|
| 445 | |
---|
| 446 | InputNALUnit nalu; |
---|
[1319] | 447 | byteStreamNALUnit(bytestream, nalu.getBitstream().getFifo(), stats); |
---|
[313] | 448 | |
---|
| 449 | // call actual decoding function |
---|
| 450 | Bool bNewPicture = false; |
---|
[1319] | 451 | if (nalu.getBitstream().getFifo().empty()) |
---|
[313] | 452 | { |
---|
| 453 | /* this can happen if the following occur: |
---|
| 454 | * - empty input file |
---|
| 455 | * - two back-to-back start_code_prefixes |
---|
| 456 | * - start_code_prefix immediately followed by EOF |
---|
| 457 | */ |
---|
| 458 | fprintf(stderr, "Warning: Attempt to decode an empty NAL unit\n"); |
---|
| 459 | } |
---|
| 460 | else |
---|
| 461 | { |
---|
[1319] | 462 | read(nalu); |
---|
[313] | 463 | if( (m_iMaxTemporalLayer >= 0 && nalu.m_temporalId > m_iMaxTemporalLayer) || !isNaluWithinTargetDecLayerIdSet(&nalu) ) |
---|
| 464 | { |
---|
[1029] | 465 | bNewPicture = false; |
---|
| 466 | } |
---|
[313] | 467 | else |
---|
| 468 | { |
---|
| 469 | bNewPicture = m_cTDecTop.decode(nalu, m_iSkipFrame, m_iPOCLastDisplay); |
---|
| 470 | if (bNewPicture) |
---|
| 471 | { |
---|
| 472 | bitstreamFile.clear(); |
---|
| 473 | /* location points to the current nalunit payload[1] due to the |
---|
| 474 | * need for the annexB parser to read three extra bytes. |
---|
| 475 | * [1] except for the first NAL unit in the file |
---|
| 476 | * (but bNewPicture doesn't happen then) */ |
---|
[1029] | 477 | #if RExt__DECODER_DEBUG_BIT_STATISTICS |
---|
| 478 | bitstreamFile.seekg(location); |
---|
| 479 | bytestream.reset(); |
---|
| 480 | TComCodingStatistics::SetStatistics(backupStats); |
---|
| 481 | #else |
---|
[313] | 482 | bitstreamFile.seekg(location-streamoff(3)); |
---|
| 483 | bytestream.reset(); |
---|
[1029] | 484 | #endif |
---|
[313] | 485 | } |
---|
| 486 | } |
---|
| 487 | } |
---|
[1029] | 488 | |
---|
| 489 | if ( (bNewPicture || !bitstreamFile || nalu.m_nalUnitType == NAL_UNIT_EOS) && |
---|
| 490 | !m_cTDecTop.getFirstSliceInSequence () ) |
---|
[313] | 491 | { |
---|
[540] | 492 | if (!loopFiltered || bitstreamFile) |
---|
| 493 | { |
---|
| 494 | m_cTDecTop.executeLoopFilters(poc, pcListPic); |
---|
| 495 | } |
---|
| 496 | loopFiltered = (nalu.m_nalUnitType == NAL_UNIT_EOS); |
---|
[1029] | 497 | if (nalu.m_nalUnitType == NAL_UNIT_EOS) |
---|
| 498 | { |
---|
| 499 | m_cTDecTop.setFirstSliceInSequence(true); |
---|
| 500 | } |
---|
[313] | 501 | } |
---|
[1029] | 502 | else if ( (bNewPicture || !bitstreamFile || nalu.m_nalUnitType == NAL_UNIT_EOS ) && |
---|
| 503 | m_cTDecTop.getFirstSliceInSequence () ) |
---|
[713] | 504 | { |
---|
[1029] | 505 | m_cTDecTop.setFirstSliceInPicture (true); |
---|
[713] | 506 | } |
---|
[313] | 507 | |
---|
| 508 | if( pcListPic ) |
---|
| 509 | { |
---|
[1442] | 510 | if ( (!m_reconFileName.empty()) && (!openedReconFile) ) |
---|
[313] | 511 | { |
---|
[1287] | 512 | const BitDepths &bitDepths=pcListPic->front()->getPicSym()->getSPS().getBitDepths(); // use bit depths of first reconstructed picture. |
---|
[1029] | 513 | for (UInt channelType = 0; channelType < MAX_NUM_CHANNEL_TYPE; channelType++) |
---|
| 514 | { |
---|
[1246] | 515 | if (m_outputBitDepth[channelType] == 0) |
---|
| 516 | { |
---|
[1287] | 517 | m_outputBitDepth[channelType] = bitDepths.recon[channelType]; |
---|
[1246] | 518 | } |
---|
[1029] | 519 | } |
---|
[313] | 520 | |
---|
[1442] | 521 | m_cTVideoIOYuvReconFile.open( m_reconFileName, true, m_outputBitDepth, m_outputBitDepth, bitDepths.recon ); // write mode |
---|
[442] | 522 | openedReconFile = true; |
---|
[313] | 523 | } |
---|
[713] | 524 | // write reconstruction to file |
---|
| 525 | if( bNewPicture ) |
---|
| 526 | { |
---|
| 527 | xWriteOutput( pcListPic, nalu.m_temporalId ); |
---|
| 528 | } |
---|
| 529 | if ( (bNewPicture || nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_CRA) && m_cTDecTop.getNoOutputPriorPicsFlag() ) |
---|
| 530 | { |
---|
| 531 | m_cTDecTop.checkNoOutputPriorPics( pcListPic ); |
---|
| 532 | m_cTDecTop.setNoOutputPriorPicsFlag (false); |
---|
| 533 | } |
---|
[494] | 534 | if ( bNewPicture && |
---|
[313] | 535 | ( nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_IDR_W_RADL |
---|
| 536 | || nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_IDR_N_LP |
---|
| 537 | || nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_BLA_N_LP |
---|
| 538 | || nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_BLA_W_RADL |
---|
| 539 | || nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_BLA_W_LP ) ) |
---|
| 540 | { |
---|
| 541 | xFlushOutput( pcListPic ); |
---|
| 542 | } |
---|
[540] | 543 | if (nalu.m_nalUnitType == NAL_UNIT_EOS) |
---|
| 544 | { |
---|
[713] | 545 | xWriteOutput( pcListPic, nalu.m_temporalId ); |
---|
[1029] | 546 | m_cTDecTop.setFirstSliceInPicture (false); |
---|
[540] | 547 | } |
---|
[713] | 548 | // write reconstruction to file -- for additional bumping as defined in C.5.2.3 |
---|
| 549 | if(!bNewPicture && nalu.m_nalUnitType >= NAL_UNIT_CODED_SLICE_TRAIL_N && nalu.m_nalUnitType <= NAL_UNIT_RESERVED_VCL31) |
---|
[313] | 550 | { |
---|
| 551 | xWriteOutput( pcListPic, nalu.m_temporalId ); |
---|
| 552 | } |
---|
| 553 | } |
---|
| 554 | } |
---|
[494] | 555 | |
---|
[313] | 556 | xFlushOutput( pcListPic ); |
---|
| 557 | // delete buffers |
---|
| 558 | m_cTDecTop.deletePicBuffer(); |
---|
[494] | 559 | |
---|
[313] | 560 | // destroy internal classes |
---|
| 561 | xDestroyDecLib(); |
---|
[1471] | 562 | #endif |
---|
[313] | 563 | } |
---|
| 564 | |
---|
| 565 | // ==================================================================================================================== |
---|
| 566 | // Protected member functions |
---|
| 567 | // ==================================================================================================================== |
---|
| 568 | |
---|
| 569 | Void TAppDecTop::xCreateDecLib() |
---|
| 570 | { |
---|
| 571 | #if SVC_EXTENSION |
---|
| 572 | // initialize global variables |
---|
[494] | 573 | initROM(); |
---|
[1029] | 574 | |
---|
[1106] | 575 | #if CONFORMANCE_BITSTREAM_MODE |
---|
[1044] | 576 | for(UInt layer = 0; layer < MAX_VPS_LAYER_IDX_PLUS1; layer++) |
---|
[953] | 577 | #else |
---|
[1524] | 578 | for(UInt layer = 0; layer <= m_commonDecoderParams.getTargetLayerId(); layer++) |
---|
[953] | 579 | #endif |
---|
[313] | 580 | { |
---|
[1378] | 581 | m_apcTDecTop[layer] = new TDecTop; |
---|
| 582 | m_apcTVideoIOYuvReconFile[layer] = new TVideoIOYuv; |
---|
| 583 | |
---|
[313] | 584 | // set layer ID |
---|
[1378] | 585 | m_apcTDecTop[layer]->setLayerId ( layer ); |
---|
[313] | 586 | |
---|
| 587 | // create decoder class |
---|
[1378] | 588 | m_apcTDecTop[layer]->create(); |
---|
[313] | 589 | |
---|
[1378] | 590 | m_apcTDecTop[layer]->setLayerDec(m_apcTDecTop); |
---|
[313] | 591 | } |
---|
| 592 | #else |
---|
| 593 | // create decoder class |
---|
| 594 | m_cTDecTop.create(); |
---|
| 595 | #endif |
---|
| 596 | } |
---|
| 597 | |
---|
| 598 | Void TAppDecTop::xDestroyDecLib() |
---|
| 599 | { |
---|
| 600 | #if SVC_EXTENSION |
---|
| 601 | // destroy ROM |
---|
| 602 | destroyROM(); |
---|
[1029] | 603 | |
---|
[1106] | 604 | #if CONFORMANCE_BITSTREAM_MODE |
---|
[1044] | 605 | for(UInt layer = 0; layer < MAX_VPS_LAYER_IDX_PLUS1; layer++) |
---|
[953] | 606 | #else |
---|
[1524] | 607 | for(UInt layer = 0; layer <= m_commonDecoderParams.getTargetLayerId(); layer++) |
---|
[953] | 608 | #endif |
---|
[313] | 609 | { |
---|
[1442] | 610 | if ( !m_reconFileName[layer].empty() ) |
---|
[313] | 611 | { |
---|
[1378] | 612 | m_apcTVideoIOYuvReconFile[layer]->close(); |
---|
[313] | 613 | } |
---|
| 614 | |
---|
| 615 | // destroy decoder class |
---|
[1378] | 616 | m_apcTDecTop[layer]->destroy(); |
---|
[313] | 617 | } |
---|
| 618 | #else |
---|
[1442] | 619 | if ( !m_reconFileName.empty() ) |
---|
[313] | 620 | { |
---|
[1442] | 621 | m_cTVideoIOYuvReconFile.close(); |
---|
[313] | 622 | } |
---|
[494] | 623 | |
---|
[313] | 624 | // destroy decoder class |
---|
| 625 | m_cTDecTop.destroy(); |
---|
| 626 | #endif |
---|
[1470] | 627 | if (m_pcSeiColourRemappingInfoPrevious != NULL) |
---|
| 628 | { |
---|
| 629 | delete m_pcSeiColourRemappingInfoPrevious; |
---|
| 630 | m_pcSeiColourRemappingInfoPrevious = NULL; |
---|
| 631 | } |
---|
[313] | 632 | } |
---|
| 633 | |
---|
| 634 | Void TAppDecTop::xInitDecLib() |
---|
| 635 | { |
---|
| 636 | // initialize decoder class |
---|
| 637 | #if SVC_EXTENSION |
---|
[1106] | 638 | #if CONFORMANCE_BITSTREAM_MODE |
---|
[1044] | 639 | for(UInt layer = 0; layer < MAX_VPS_LAYER_IDX_PLUS1; layer++) |
---|
[953] | 640 | #else |
---|
[1524] | 641 | for(UInt layer = 0; layer <= m_commonDecoderParams.getTargetLayerId(); layer++) |
---|
[953] | 642 | #endif |
---|
[313] | 643 | { |
---|
[1467] | 644 | TDecTop& m_cTDecTop = *m_apcTDecTop[layer]; |
---|
[953] | 645 | #endif |
---|
[1467] | 646 | |
---|
[313] | 647 | m_cTDecTop.init(); |
---|
| 648 | m_cTDecTop.setDecodedPictureHashSEIEnabled(m_decodedPictureHashSEIEnabled); |
---|
[1029] | 649 | #if O0043_BEST_EFFORT_DECODING |
---|
| 650 | m_cTDecTop.setForceDecodeBitDepth(m_forceDecodeBitDepth); |
---|
| 651 | #endif |
---|
| 652 | if (!m_outputDecodedSEIMessagesFilename.empty()) |
---|
| 653 | { |
---|
| 654 | std::ostream &os=m_seiMessageFileStream.is_open() ? m_seiMessageFileStream : std::cout; |
---|
| 655 | m_cTDecTop.setDecodedSEIMessageOutputStream(&os); |
---|
| 656 | } |
---|
[1467] | 657 | |
---|
| 658 | #if SVC_EXTENSION |
---|
| 659 | #if CONFORMANCE_BITSTREAM_MODE |
---|
[1524] | 660 | m_cTDecTop.setConfModeFlag( m_confModeFlag ); |
---|
[313] | 661 | #endif |
---|
[1467] | 662 | m_cTDecTop.setCommonDecoderParams( &m_commonDecoderParams ); |
---|
| 663 | } |
---|
| 664 | #endif |
---|
| 665 | |
---|
[1460] | 666 | if (m_pcSeiColourRemappingInfoPrevious != NULL) |
---|
| 667 | { |
---|
| 668 | delete m_pcSeiColourRemappingInfoPrevious; |
---|
| 669 | m_pcSeiColourRemappingInfoPrevious = NULL; |
---|
| 670 | } |
---|
[313] | 671 | } |
---|
| 672 | |
---|
| 673 | /** \param pcListPic list of pictures to be written to file |
---|
[1260] | 674 | \param tId temporal sub-layer ID |
---|
[540] | 675 | */ |
---|
[313] | 676 | #if SVC_EXTENSION |
---|
| 677 | Void TAppDecTop::xWriteOutput( TComList<TComPic*>* pcListPic, UInt layerId, UInt tId ) |
---|
| 678 | #else |
---|
| 679 | Void TAppDecTop::xWriteOutput( TComList<TComPic*>* pcListPic, UInt tId ) |
---|
| 680 | #endif |
---|
| 681 | { |
---|
[540] | 682 | if (pcListPic->empty()) |
---|
| 683 | { |
---|
| 684 | return; |
---|
| 685 | } |
---|
| 686 | |
---|
[313] | 687 | TComList<TComPic*>::iterator iterPic = pcListPic->begin(); |
---|
[442] | 688 | Int numPicsNotYetDisplayed = 0; |
---|
[713] | 689 | Int dpbFullness = 0; |
---|
[1235] | 690 | const TComSPS* activeSPS = &(pcListPic->front()->getPicSym()->getSPS()); |
---|
[713] | 691 | UInt numReorderPicsHighestTid; |
---|
| 692 | UInt maxDecPicBufferingHighestTid; |
---|
| 693 | UInt maxNrSublayers = activeSPS->getMaxTLayers(); |
---|
[313] | 694 | |
---|
[713] | 695 | if(m_iMaxTemporalLayer == -1 || m_iMaxTemporalLayer >= maxNrSublayers) |
---|
| 696 | { |
---|
| 697 | numReorderPicsHighestTid = activeSPS->getNumReorderPics(maxNrSublayers-1); |
---|
| 698 | maxDecPicBufferingHighestTid = activeSPS->getMaxDecPicBuffering(maxNrSublayers-1); |
---|
| 699 | } |
---|
| 700 | else |
---|
| 701 | { |
---|
| 702 | numReorderPicsHighestTid = activeSPS->getNumReorderPics(m_iMaxTemporalLayer); |
---|
| 703 | maxDecPicBufferingHighestTid = activeSPS->getMaxDecPicBuffering(m_iMaxTemporalLayer); |
---|
| 704 | } |
---|
| 705 | |
---|
[313] | 706 | while (iterPic != pcListPic->end()) |
---|
| 707 | { |
---|
| 708 | TComPic* pcPic = *(iterPic); |
---|
| 709 | #if SVC_EXTENSION |
---|
| 710 | if(pcPic->getOutputMark() && pcPic->getPOC() > m_aiPOCLastDisplay[layerId]) |
---|
| 711 | #else |
---|
| 712 | if(pcPic->getOutputMark() && pcPic->getPOC() > m_iPOCLastDisplay) |
---|
| 713 | #endif |
---|
| 714 | { |
---|
[1029] | 715 | numPicsNotYetDisplayed++; |
---|
[713] | 716 | dpbFullness++; |
---|
[313] | 717 | } |
---|
[713] | 718 | else if(pcPic->getSlice( 0 )->isReferenced()) |
---|
| 719 | { |
---|
| 720 | dpbFullness++; |
---|
| 721 | } |
---|
[313] | 722 | iterPic++; |
---|
| 723 | } |
---|
[1029] | 724 | |
---|
| 725 | iterPic = pcListPic->begin(); |
---|
| 726 | |
---|
[442] | 727 | if (numPicsNotYetDisplayed>2) |
---|
[313] | 728 | { |
---|
[442] | 729 | iterPic++; |
---|
| 730 | } |
---|
| 731 | |
---|
| 732 | TComPic* pcPic = *(iterPic); |
---|
| 733 | if (numPicsNotYetDisplayed>2 && pcPic->isField()) //Field Decoding |
---|
| 734 | { |
---|
| 735 | TComList<TComPic*>::iterator endPic = pcListPic->end(); |
---|
| 736 | endPic--; |
---|
| 737 | iterPic = pcListPic->begin(); |
---|
| 738 | while (iterPic != endPic) |
---|
| 739 | { |
---|
| 740 | TComPic* pcPicTop = *(iterPic); |
---|
| 741 | iterPic++; |
---|
| 742 | TComPic* pcPicBottom = *(iterPic); |
---|
| 743 | |
---|
[313] | 744 | #if SVC_EXTENSION |
---|
[713] | 745 | if( pcPicTop->getOutputMark() && pcPicBottom->getOutputMark() && |
---|
| 746 | (numPicsNotYetDisplayed > numReorderPicsHighestTid || dpbFullness > maxDecPicBufferingHighestTid) && |
---|
| 747 | (!(pcPicTop->getPOC()%2) && pcPicBottom->getPOC() == pcPicTop->getPOC()+1) && |
---|
| 748 | (pcPicTop->getPOC() == m_aiPOCLastDisplay[layerId]+1 || m_aiPOCLastDisplay[layerId]<0) ) |
---|
[313] | 749 | #else |
---|
[713] | 750 | if ( pcPicTop->getOutputMark() && pcPicBottom->getOutputMark() && |
---|
| 751 | (numPicsNotYetDisplayed > numReorderPicsHighestTid || dpbFullness > maxDecPicBufferingHighestTid) && |
---|
| 752 | (!(pcPicTop->getPOC()%2) && pcPicBottom->getPOC() == pcPicTop->getPOC()+1) && |
---|
| 753 | (pcPicTop->getPOC() == m_iPOCLastDisplay+1 || m_iPOCLastDisplay < 0)) |
---|
[313] | 754 | #endif |
---|
[442] | 755 | { |
---|
| 756 | // write to file |
---|
| 757 | numPicsNotYetDisplayed = numPicsNotYetDisplayed-2; |
---|
| 758 | #if SVC_EXTENSION |
---|
[1442] | 759 | if ( !m_reconFileName[layerId].empty() ) |
---|
[442] | 760 | { |
---|
| 761 | const Window &conf = pcPicTop->getConformanceWindow(); |
---|
[1235] | 762 | const Window defDisp = m_respectDefDispWindow ? pcPicTop->getDefDisplayWindow() : Window(); |
---|
[442] | 763 | const Bool isTff = pcPicTop->isTopField(); |
---|
[1029] | 764 | |
---|
| 765 | Bool display = true; |
---|
| 766 | if( m_decodedNoDisplaySEIEnabled ) |
---|
| 767 | { |
---|
| 768 | SEIMessages noDisplay = getSeisByType(pcPic->getSEIs(), SEI::NO_DISPLAY ); |
---|
| 769 | const SEINoDisplay *nd = ( noDisplay.size() > 0 ) ? (SEINoDisplay*) *(noDisplay.begin()) : NULL; |
---|
| 770 | if( (nd != NULL) && nd->m_noDisplay ) |
---|
| 771 | { |
---|
| 772 | display = false; |
---|
| 773 | } |
---|
| 774 | } |
---|
| 775 | |
---|
| 776 | if (display) |
---|
| 777 | { |
---|
[1502] | 778 | UInt chromaFormatIdc = pcPic->getSlice(0)->getSPS()->getChromaFormatIdc(); |
---|
[1029] | 779 | Int xScal = TComSPS::getWinUnitX( chromaFormatIdc ), yScal = TComSPS::getWinUnitY( chromaFormatIdc ); |
---|
[713] | 780 | |
---|
[1378] | 781 | m_apcTVideoIOYuvReconFile[layerId]->write( pcPicTop->getPicYuvRec(), pcPicBottom->getPicYuvRec(), |
---|
[1029] | 782 | m_outputColourSpaceConvert, |
---|
| 783 | conf.getWindowLeftOffset() * xScal + defDisp.getWindowLeftOffset(), |
---|
| 784 | conf.getWindowRightOffset() * xScal + defDisp.getWindowRightOffset(), |
---|
| 785 | conf.getWindowTopOffset() * yScal + defDisp.getWindowTopOffset(), |
---|
| 786 | conf.getWindowBottomOffset()* yScal + defDisp.getWindowBottomOffset(), NUM_CHROMA_FORMAT, isTff ); |
---|
| 787 | } |
---|
[442] | 788 | } |
---|
| 789 | |
---|
| 790 | // update POC of display order |
---|
| 791 | m_aiPOCLastDisplay[layerId] = pcPicBottom->getPOC(); |
---|
| 792 | #else |
---|
[1442] | 793 | if ( !m_reconFileName.empty() ) |
---|
[442] | 794 | { |
---|
| 795 | const Window &conf = pcPicTop->getConformanceWindow(); |
---|
[1235] | 796 | const Window defDisp = m_respectDefDispWindow ? pcPicTop->getDefDisplayWindow() : Window(); |
---|
[442] | 797 | const Bool isTff = pcPicTop->isTopField(); |
---|
[1029] | 798 | |
---|
| 799 | Bool display = true; |
---|
| 800 | if( m_decodedNoDisplaySEIEnabled ) |
---|
| 801 | { |
---|
| 802 | SEIMessages noDisplay = getSeisByType(pcPic->getSEIs(), SEI::NO_DISPLAY ); |
---|
| 803 | const SEINoDisplay *nd = ( noDisplay.size() > 0 ) ? (SEINoDisplay*) *(noDisplay.begin()) : NULL; |
---|
| 804 | if( (nd != NULL) && nd->m_noDisplay ) |
---|
| 805 | { |
---|
| 806 | display = false; |
---|
| 807 | } |
---|
| 808 | } |
---|
| 809 | |
---|
| 810 | if (display) |
---|
| 811 | { |
---|
| 812 | m_cTVideoIOYuvReconFile.write( pcPicTop->getPicYuvRec(), pcPicBottom->getPicYuvRec(), |
---|
| 813 | m_outputColourSpaceConvert, |
---|
| 814 | conf.getWindowLeftOffset() + defDisp.getWindowLeftOffset(), |
---|
| 815 | conf.getWindowRightOffset() + defDisp.getWindowRightOffset(), |
---|
| 816 | conf.getWindowTopOffset() + defDisp.getWindowTopOffset(), |
---|
| 817 | conf.getWindowBottomOffset() + defDisp.getWindowBottomOffset(), NUM_CHROMA_FORMAT, isTff ); |
---|
| 818 | } |
---|
[442] | 819 | } |
---|
| 820 | |
---|
| 821 | // update POC of display order |
---|
| 822 | m_iPOCLastDisplay = pcPicBottom->getPOC(); |
---|
| 823 | #endif |
---|
| 824 | |
---|
| 825 | // erase non-referenced picture in the reference picture list after display |
---|
| 826 | if ( !pcPicTop->getSlice(0)->isReferenced() && pcPicTop->getReconMark() == true ) |
---|
| 827 | { |
---|
| 828 | pcPicTop->setReconMark(false); |
---|
| 829 | |
---|
| 830 | // mark it should be extended later |
---|
| 831 | pcPicTop->getPicYuvRec()->setBorderExtension( false ); |
---|
| 832 | } |
---|
| 833 | if ( !pcPicBottom->getSlice(0)->isReferenced() && pcPicBottom->getReconMark() == true ) |
---|
| 834 | { |
---|
| 835 | pcPicBottom->setReconMark(false); |
---|
| 836 | |
---|
| 837 | // mark it should be extended later |
---|
| 838 | pcPicBottom->getPicYuvRec()->setBorderExtension( false ); |
---|
| 839 | } |
---|
| 840 | pcPicTop->setOutputMark(false); |
---|
| 841 | pcPicBottom->setOutputMark(false); |
---|
| 842 | } |
---|
| 843 | } |
---|
| 844 | } |
---|
| 845 | else if (!pcPic->isField()) //Frame Decoding |
---|
| 846 | { |
---|
| 847 | iterPic = pcListPic->begin(); |
---|
[1029] | 848 | |
---|
[442] | 849 | while (iterPic != pcListPic->end()) |
---|
[313] | 850 | { |
---|
[442] | 851 | pcPic = *(iterPic); |
---|
| 852 | |
---|
[313] | 853 | #if SVC_EXTENSION |
---|
[713] | 854 | if( pcPic->getOutputMark() && pcPic->getPOC() > m_aiPOCLastDisplay[layerId] && |
---|
| 855 | (numPicsNotYetDisplayed > numReorderPicsHighestTid || dpbFullness > maxDecPicBufferingHighestTid) ) |
---|
[313] | 856 | #else |
---|
[713] | 857 | if(pcPic->getOutputMark() && pcPic->getPOC() > m_iPOCLastDisplay && |
---|
| 858 | (numPicsNotYetDisplayed > numReorderPicsHighestTid || dpbFullness > maxDecPicBufferingHighestTid)) |
---|
[442] | 859 | #endif |
---|
[313] | 860 | { |
---|
[442] | 861 | // write to file |
---|
[1029] | 862 | numPicsNotYetDisplayed--; |
---|
[713] | 863 | if(pcPic->getSlice(0)->isReferenced() == false) |
---|
| 864 | { |
---|
| 865 | dpbFullness--; |
---|
| 866 | } |
---|
[442] | 867 | #if SVC_EXTENSION |
---|
[1442] | 868 | if ( !m_reconFileName[layerId].empty() ) |
---|
[442] | 869 | { |
---|
| 870 | const Window &conf = pcPic->getConformanceWindow(); |
---|
[1235] | 871 | const Window defDisp = m_respectDefDispWindow ? pcPic->getDefDisplayWindow() : Window(); |
---|
[1203] | 872 | |
---|
[1502] | 873 | UInt chromaFormatIdc = pcPic->getSlice(0)->getSPS()->getChromaFormatIdc(); |
---|
[442] | 874 | Int xScal = TComSPS::getWinUnitX( chromaFormatIdc ), yScal = TComSPS::getWinUnitY( chromaFormatIdc ); |
---|
[713] | 875 | |
---|
[1378] | 876 | m_apcTVideoIOYuvReconFile[layerId]->write( pcPic->getPicYuvRec(), m_outputColourSpaceConvert, |
---|
[442] | 877 | conf.getWindowLeftOffset() * xScal + defDisp.getWindowLeftOffset(), |
---|
| 878 | conf.getWindowRightOffset() * xScal + defDisp.getWindowRightOffset(), |
---|
| 879 | conf.getWindowTopOffset() * yScal + defDisp.getWindowTopOffset(), |
---|
[1323] | 880 | conf.getWindowBottomOffset()* yScal + defDisp.getWindowBottomOffset(), |
---|
| 881 | NUM_CHROMA_FORMAT, m_bClipOutputVideoToRec709Range ); |
---|
[442] | 882 | } |
---|
| 883 | |
---|
| 884 | // update POC of display order |
---|
| 885 | m_aiPOCLastDisplay[layerId] = pcPic->getPOC(); |
---|
| 886 | #else |
---|
[1442] | 887 | if ( !m_reconFileName.empty() ) |
---|
[442] | 888 | { |
---|
[1029] | 889 | const Window &conf = pcPic->getConformanceWindow(); |
---|
[1235] | 890 | const Window defDisp = m_respectDefDispWindow ? pcPic->getDefDisplayWindow() : Window(); |
---|
[1029] | 891 | |
---|
[820] | 892 | m_cTVideoIOYuvReconFile.write( pcPic->getPicYuvRec(), |
---|
[1029] | 893 | m_outputColourSpaceConvert, |
---|
| 894 | conf.getWindowLeftOffset() + defDisp.getWindowLeftOffset(), |
---|
| 895 | conf.getWindowRightOffset() + defDisp.getWindowRightOffset(), |
---|
| 896 | conf.getWindowTopOffset() + defDisp.getWindowTopOffset(), |
---|
[1323] | 897 | conf.getWindowBottomOffset() + defDisp.getWindowBottomOffset(), |
---|
| 898 | NUM_CHROMA_FORMAT, m_bClipOutputVideoToRec709Range ); |
---|
[442] | 899 | } |
---|
| 900 | |
---|
[1460] | 901 | if (!m_colourRemapSEIFileName.empty()) |
---|
[1089] | 902 | { |
---|
[1470] | 903 | xOutputColourRemapPic(pcPic); |
---|
[1089] | 904 | } |
---|
| 905 | |
---|
[442] | 906 | // update POC of display order |
---|
| 907 | m_iPOCLastDisplay = pcPic->getPOC(); |
---|
| 908 | #endif |
---|
| 909 | |
---|
| 910 | // erase non-referenced picture in the reference picture list after display |
---|
| 911 | if ( !pcPic->getSlice(0)->isReferenced() && pcPic->getReconMark() == true ) |
---|
| 912 | { |
---|
| 913 | pcPic->setReconMark(false); |
---|
| 914 | |
---|
| 915 | // mark it should be extended later |
---|
| 916 | pcPic->getPicYuvRec()->setBorderExtension( false ); |
---|
| 917 | } |
---|
| 918 | pcPic->setOutputMark(false); |
---|
[313] | 919 | } |
---|
[442] | 920 | |
---|
| 921 | iterPic++; |
---|
[313] | 922 | } |
---|
| 923 | } |
---|
| 924 | } |
---|
| 925 | |
---|
| 926 | /** \param pcListPic list of pictures to be written to file |
---|
| 927 | */ |
---|
| 928 | #if SVC_EXTENSION |
---|
| 929 | Void TAppDecTop::xFlushOutput( TComList<TComPic*>* pcListPic, UInt layerId ) |
---|
| 930 | #else |
---|
| 931 | Void TAppDecTop::xFlushOutput( TComList<TComPic*>* pcListPic ) |
---|
| 932 | #endif |
---|
| 933 | { |
---|
[540] | 934 | if(!pcListPic || pcListPic->empty()) |
---|
[313] | 935 | { |
---|
| 936 | return; |
---|
[494] | 937 | } |
---|
[313] | 938 | TComList<TComPic*>::iterator iterPic = pcListPic->begin(); |
---|
| 939 | |
---|
| 940 | iterPic = pcListPic->begin(); |
---|
[442] | 941 | TComPic* pcPic = *(iterPic); |
---|
| 942 | |
---|
| 943 | if (pcPic->isField()) //Field Decoding |
---|
[313] | 944 | { |
---|
[442] | 945 | TComList<TComPic*>::iterator endPic = pcListPic->end(); |
---|
| 946 | endPic--; |
---|
| 947 | TComPic *pcPicTop, *pcPicBottom = NULL; |
---|
| 948 | while (iterPic != endPic) |
---|
| 949 | { |
---|
| 950 | pcPicTop = *(iterPic); |
---|
| 951 | iterPic++; |
---|
| 952 | pcPicBottom = *(iterPic); |
---|
[313] | 953 | |
---|
[442] | 954 | if ( pcPicTop->getOutputMark() && pcPicBottom->getOutputMark() && !(pcPicTop->getPOC()%2) && (pcPicBottom->getPOC() == pcPicTop->getPOC()+1) ) |
---|
| 955 | { |
---|
| 956 | // write to file |
---|
| 957 | #if SVC_EXTENSION |
---|
[1442] | 958 | if ( !m_reconFileName[layerId].empty() ) |
---|
[442] | 959 | { |
---|
| 960 | const Window &conf = pcPicTop->getConformanceWindow(); |
---|
[1235] | 961 | const Window defDisp = m_respectDefDispWindow ? pcPicTop->getDefDisplayWindow() : Window(); |
---|
[1029] | 962 | const Bool isTff = pcPicTop->isTopField(); |
---|
[1203] | 963 | |
---|
[1502] | 964 | UInt chromaFormatIdc = pcPic->getSlice(0)->getSPS()->getChromaFormatIdc(); |
---|
[442] | 965 | Int xScal = TComSPS::getWinUnitX( chromaFormatIdc ), yScal = TComSPS::getWinUnitY( chromaFormatIdc ); |
---|
[713] | 966 | |
---|
[1378] | 967 | m_apcTVideoIOYuvReconFile[layerId]->write( pcPicTop->getPicYuvRec(), pcPicBottom->getPicYuvRec(), m_outputColourSpaceConvert, |
---|
[442] | 968 | conf.getWindowLeftOffset() *xScal + defDisp.getWindowLeftOffset(), |
---|
| 969 | conf.getWindowRightOffset() *xScal + defDisp.getWindowRightOffset(), |
---|
| 970 | conf.getWindowTopOffset() *yScal + defDisp.getWindowTopOffset(), |
---|
[1029] | 971 | conf.getWindowBottomOffset()*yScal + defDisp.getWindowBottomOffset(), NUM_CHROMA_FORMAT, isTff ); |
---|
[442] | 972 | } |
---|
| 973 | |
---|
| 974 | // update POC of display order |
---|
| 975 | m_aiPOCLastDisplay[layerId] = pcPicBottom->getPOC(); |
---|
| 976 | #else |
---|
[1442] | 977 | if ( !m_reconFileName.empty() ) |
---|
[442] | 978 | { |
---|
| 979 | const Window &conf = pcPicTop->getConformanceWindow(); |
---|
[1235] | 980 | const Window defDisp = m_respectDefDispWindow ? pcPicTop->getDefDisplayWindow() : Window(); |
---|
[442] | 981 | const Bool isTff = pcPicTop->isTopField(); |
---|
[1029] | 982 | m_cTVideoIOYuvReconFile.write( pcPicTop->getPicYuvRec(), pcPicBottom->getPicYuvRec(), |
---|
| 983 | m_outputColourSpaceConvert, |
---|
| 984 | conf.getWindowLeftOffset() + defDisp.getWindowLeftOffset(), |
---|
| 985 | conf.getWindowRightOffset() + defDisp.getWindowRightOffset(), |
---|
| 986 | conf.getWindowTopOffset() + defDisp.getWindowTopOffset(), |
---|
| 987 | conf.getWindowBottomOffset() + defDisp.getWindowBottomOffset(), NUM_CHROMA_FORMAT, isTff ); |
---|
[442] | 988 | } |
---|
| 989 | |
---|
| 990 | // update POC of display order |
---|
| 991 | m_iPOCLastDisplay = pcPicBottom->getPOC(); |
---|
| 992 | #endif |
---|
| 993 | |
---|
| 994 | // erase non-referenced picture in the reference picture list after display |
---|
| 995 | if ( !pcPicTop->getSlice(0)->isReferenced() && pcPicTop->getReconMark() == true ) |
---|
| 996 | { |
---|
| 997 | pcPicTop->setReconMark(false); |
---|
| 998 | |
---|
| 999 | // mark it should be extended later |
---|
| 1000 | pcPicTop->getPicYuvRec()->setBorderExtension( false ); |
---|
| 1001 | } |
---|
| 1002 | if ( !pcPicBottom->getSlice(0)->isReferenced() && pcPicBottom->getReconMark() == true ) |
---|
| 1003 | { |
---|
| 1004 | pcPicBottom->setReconMark(false); |
---|
| 1005 | |
---|
| 1006 | // mark it should be extended later |
---|
| 1007 | pcPicBottom->getPicYuvRec()->setBorderExtension( false ); |
---|
| 1008 | } |
---|
| 1009 | pcPicTop->setOutputMark(false); |
---|
| 1010 | pcPicBottom->setOutputMark(false); |
---|
| 1011 | |
---|
| 1012 | if(pcPicTop) |
---|
| 1013 | { |
---|
| 1014 | pcPicTop->destroy(); |
---|
| 1015 | delete pcPicTop; |
---|
| 1016 | pcPicTop = NULL; |
---|
| 1017 | } |
---|
| 1018 | } |
---|
| 1019 | } |
---|
| 1020 | if(pcPicBottom) |
---|
[313] | 1021 | { |
---|
[442] | 1022 | pcPicBottom->destroy(); |
---|
| 1023 | delete pcPicBottom; |
---|
| 1024 | pcPicBottom = NULL; |
---|
| 1025 | } |
---|
| 1026 | } |
---|
| 1027 | else //Frame decoding |
---|
| 1028 | { |
---|
| 1029 | while (iterPic != pcListPic->end()) |
---|
| 1030 | { |
---|
| 1031 | pcPic = *(iterPic); |
---|
| 1032 | |
---|
| 1033 | if ( pcPic->getOutputMark() ) |
---|
| 1034 | { |
---|
| 1035 | // write to file |
---|
[313] | 1036 | #if SVC_EXTENSION |
---|
[1442] | 1037 | if ( !m_reconFileName[layerId].empty() ) |
---|
[442] | 1038 | { |
---|
| 1039 | const Window &conf = pcPic->getConformanceWindow(); |
---|
[1235] | 1040 | const Window defDisp = m_respectDefDispWindow ? pcPic->getDefDisplayWindow() : Window(); |
---|
[1203] | 1041 | |
---|
[1502] | 1042 | UInt chromaFormatIdc = pcPic->getSlice(0)->getSPS()->getChromaFormatIdc(); |
---|
[442] | 1043 | Int xScal = TComSPS::getWinUnitX( chromaFormatIdc ), yScal = TComSPS::getWinUnitY( chromaFormatIdc ); |
---|
[713] | 1044 | |
---|
[1378] | 1045 | m_apcTVideoIOYuvReconFile[layerId]->write( pcPic->getPicYuvRec(), |
---|
[1323] | 1046 | m_outputColourSpaceConvert, |
---|
| 1047 | conf.getWindowLeftOffset() *xScal + defDisp.getWindowLeftOffset(), |
---|
| 1048 | conf.getWindowRightOffset() *xScal + defDisp.getWindowRightOffset(), |
---|
| 1049 | conf.getWindowTopOffset() *yScal + defDisp.getWindowTopOffset(), |
---|
| 1050 | conf.getWindowBottomOffset()*yScal + defDisp.getWindowBottomOffset(), |
---|
| 1051 | NUM_CHROMA_FORMAT, m_bClipOutputVideoToRec709Range ); |
---|
[442] | 1052 | } |
---|
| 1053 | |
---|
| 1054 | // update POC of display order |
---|
| 1055 | m_aiPOCLastDisplay[layerId] = pcPic->getPOC(); |
---|
| 1056 | #else |
---|
[1442] | 1057 | if ( !m_reconFileName.empty() ) |
---|
[442] | 1058 | { |
---|
[1029] | 1059 | const Window &conf = pcPic->getConformanceWindow(); |
---|
[1235] | 1060 | const Window defDisp = m_respectDefDispWindow ? pcPic->getDefDisplayWindow() : Window(); |
---|
[1029] | 1061 | |
---|
| 1062 | m_cTVideoIOYuvReconFile.write( pcPic->getPicYuvRec(), |
---|
| 1063 | m_outputColourSpaceConvert, |
---|
| 1064 | conf.getWindowLeftOffset() + defDisp.getWindowLeftOffset(), |
---|
| 1065 | conf.getWindowRightOffset() + defDisp.getWindowRightOffset(), |
---|
| 1066 | conf.getWindowTopOffset() + defDisp.getWindowTopOffset(), |
---|
[1323] | 1067 | conf.getWindowBottomOffset() + defDisp.getWindowBottomOffset(), |
---|
| 1068 | NUM_CHROMA_FORMAT, m_bClipOutputVideoToRec709Range ); |
---|
[442] | 1069 | } |
---|
| 1070 | |
---|
[1460] | 1071 | if (!m_colourRemapSEIFileName.empty()) |
---|
[1089] | 1072 | { |
---|
[1470] | 1073 | xOutputColourRemapPic(pcPic); |
---|
[1089] | 1074 | } |
---|
| 1075 | |
---|
[442] | 1076 | // update POC of display order |
---|
| 1077 | m_iPOCLastDisplay = pcPic->getPOC(); |
---|
| 1078 | #endif |
---|
| 1079 | |
---|
| 1080 | // erase non-referenced picture in the reference picture list after display |
---|
| 1081 | if ( !pcPic->getSlice(0)->isReferenced() && pcPic->getReconMark() == true ) |
---|
| 1082 | { |
---|
| 1083 | pcPic->setReconMark(false); |
---|
| 1084 | |
---|
| 1085 | // mark it should be extended later |
---|
| 1086 | pcPic->getPicYuvRec()->setBorderExtension( false ); |
---|
| 1087 | } |
---|
| 1088 | pcPic->setOutputMark(false); |
---|
[313] | 1089 | } |
---|
| 1090 | #if !SVC_EXTENSION |
---|
[1338] | 1091 | if(pcPic != NULL) |
---|
[442] | 1092 | { |
---|
| 1093 | pcPic->destroy(); |
---|
| 1094 | delete pcPic; |
---|
| 1095 | pcPic = NULL; |
---|
| 1096 | } |
---|
[313] | 1097 | #endif |
---|
[442] | 1098 | iterPic++; |
---|
| 1099 | } |
---|
[313] | 1100 | } |
---|
| 1101 | #if SVC_EXTENSION |
---|
| 1102 | m_aiPOCLastDisplay[layerId] = -MAX_INT; |
---|
| 1103 | #else |
---|
| 1104 | pcListPic->clear(); |
---|
| 1105 | m_iPOCLastDisplay = -MAX_INT; |
---|
| 1106 | #endif |
---|
| 1107 | } |
---|
| 1108 | |
---|
| 1109 | /** \param nalu Input nalu to check whether its LayerId is within targetDecLayerIdSet |
---|
| 1110 | */ |
---|
| 1111 | Bool TAppDecTop::isNaluWithinTargetDecLayerIdSet( InputNALUnit* nalu ) |
---|
| 1112 | { |
---|
| 1113 | if ( m_targetDecLayerIdSet.size() == 0 ) // By default, the set is empty, meaning all LayerIds are allowed |
---|
| 1114 | { |
---|
| 1115 | return true; |
---|
| 1116 | } |
---|
[1107] | 1117 | #if SVC_EXTENSION |
---|
[1237] | 1118 | if (nalu->m_nuhLayerId == 0 && (nalu->m_nalUnitType == NAL_UNIT_VPS || nalu->m_nalUnitType == NAL_UNIT_SPS || nalu->m_nalUnitType == NAL_UNIT_PPS || nalu->m_nalUnitType == NAL_UNIT_EOS)) |
---|
[1005] | 1119 | { |
---|
| 1120 | return true; |
---|
| 1121 | } |
---|
| 1122 | #endif |
---|
[313] | 1123 | for (std::vector<Int>::iterator it = m_targetDecLayerIdSet.begin(); it != m_targetDecLayerIdSet.end(); it++) |
---|
| 1124 | { |
---|
[1237] | 1125 | if ( nalu->m_nuhLayerId == (*it) ) |
---|
[313] | 1126 | { |
---|
| 1127 | return true; |
---|
| 1128 | } |
---|
| 1129 | } |
---|
| 1130 | return false; |
---|
| 1131 | } |
---|
[1107] | 1132 | |
---|
[1470] | 1133 | Void TAppDecTop::xOutputColourRemapPic(TComPic* pcPic) |
---|
[1460] | 1134 | { |
---|
[1470] | 1135 | const TComSPS &sps=pcPic->getPicSym()->getSPS(); |
---|
[1460] | 1136 | SEIMessages colourRemappingInfo = getSeisByType(pcPic->getSEIs(), SEI::COLOUR_REMAPPING_INFO ); |
---|
| 1137 | SEIColourRemappingInfo *seiColourRemappingInfo = ( colourRemappingInfo.size() > 0 ) ? (SEIColourRemappingInfo*) *(colourRemappingInfo.begin()) : NULL; |
---|
| 1138 | |
---|
| 1139 | if (colourRemappingInfo.size() > 1) |
---|
| 1140 | { |
---|
| 1141 | printf ("Warning: Got multiple Colour Remapping Information SEI messages. Using first."); |
---|
| 1142 | } |
---|
| 1143 | if (seiColourRemappingInfo) |
---|
| 1144 | { |
---|
[1470] | 1145 | applyColourRemapping(*pcPic->getPicYuvRec(), *seiColourRemappingInfo, sps); |
---|
| 1146 | |
---|
| 1147 | // save the last CRI SEI received |
---|
| 1148 | if (m_pcSeiColourRemappingInfoPrevious == NULL) |
---|
| 1149 | { |
---|
| 1150 | m_pcSeiColourRemappingInfoPrevious = new SEIColourRemappingInfo(); |
---|
| 1151 | } |
---|
| 1152 | m_pcSeiColourRemappingInfoPrevious->copyFrom(*seiColourRemappingInfo); |
---|
[1460] | 1153 | } |
---|
| 1154 | else // using the last CRI SEI received |
---|
| 1155 | { |
---|
[1470] | 1156 | // TODO: prevent persistence of CRI SEI across C(L)VS. |
---|
[1460] | 1157 | if (m_pcSeiColourRemappingInfoPrevious != NULL) |
---|
| 1158 | { |
---|
| 1159 | if (m_pcSeiColourRemappingInfoPrevious->m_colourRemapPersistenceFlag == false) |
---|
| 1160 | { |
---|
| 1161 | printf("Warning No SEI-CRI message is present for the current picture, persistence of the CRI is not managed\n"); |
---|
| 1162 | } |
---|
[1470] | 1163 | applyColourRemapping(*pcPic->getPicYuvRec(), *m_pcSeiColourRemappingInfoPrevious, sps); |
---|
[1460] | 1164 | } |
---|
| 1165 | } |
---|
| 1166 | } |
---|
| 1167 | |
---|
| 1168 | // compute lut from SEI |
---|
| 1169 | // use at lutPoints points aligned on a power of 2 value |
---|
| 1170 | // SEI Lut must be in ascending values of coded Values |
---|
| 1171 | static std::vector<Int> |
---|
| 1172 | initColourRemappingInfoLut(const Int bitDepth_in, // bit-depth of the input values of the LUT |
---|
| 1173 | const Int nbDecimalValues, // Position of the fixed point |
---|
| 1174 | const std::vector<SEIColourRemappingInfo::CRIlut> &lut, |
---|
| 1175 | const Int maxValue, // maximum output value |
---|
| 1176 | const Int lutOffset) |
---|
| 1177 | { |
---|
| 1178 | const Int lutPoints = (1 << bitDepth_in) + 1 ; |
---|
| 1179 | std::vector<Int> retLut(lutPoints); |
---|
| 1180 | |
---|
| 1181 | // missing values: need to define default values before first definition (check codedValue[0] == 0) |
---|
| 1182 | Int iTargetPrev = (lut.size() && lut[0].codedValue == 0) ? lut[0].targetValue: 0; |
---|
| 1183 | Int startPivot = (lut.size())? ((lut[0].codedValue == 0)? 1: 0): 1; |
---|
| 1184 | Int iCodedPrev = 0; |
---|
| 1185 | // set max value with the coded bit-depth |
---|
| 1186 | // + ((1 << nbDecimalValues) - 1) is for the added bits |
---|
| 1187 | const Int maxValueFixedPoint = (maxValue << nbDecimalValues) + ((1 << nbDecimalValues) - 1); |
---|
| 1188 | |
---|
| 1189 | Int iValue = 0; |
---|
| 1190 | |
---|
| 1191 | for ( Int iPivot=startPivot ; iPivot < (Int)lut.size(); iPivot++ ) |
---|
| 1192 | { |
---|
| 1193 | Int iCodedNext = lut[iPivot].codedValue; |
---|
| 1194 | Int iTargetNext = lut[iPivot].targetValue; |
---|
| 1195 | |
---|
| 1196 | // ensure correct bit depth and avoid overflow in lut address |
---|
| 1197 | Int iCodedNext_bitDepth = std::min(iCodedNext, (1 << bitDepth_in)); |
---|
| 1198 | |
---|
| 1199 | const Int divValue = (iCodedNext - iCodedPrev > 0)? (iCodedNext - iCodedPrev): 1; |
---|
| 1200 | const Int lutValInit = (lutOffset + iTargetPrev) << nbDecimalValues; |
---|
| 1201 | const Int roundValue = divValue / 2; |
---|
| 1202 | for ( ; iValue<iCodedNext_bitDepth; iValue++ ) |
---|
| 1203 | { |
---|
| 1204 | Int value = iValue; |
---|
| 1205 | Int interpol = ((((value-iCodedPrev) * (iTargetNext - iTargetPrev)) << nbDecimalValues) + roundValue) / divValue; |
---|
| 1206 | retLut[iValue] = std::min(lutValInit + interpol , maxValueFixedPoint); |
---|
| 1207 | } |
---|
| 1208 | iCodedPrev = iCodedNext; |
---|
| 1209 | iTargetPrev = iTargetNext; |
---|
| 1210 | } |
---|
| 1211 | // fill missing values if necessary |
---|
| 1212 | if(iCodedPrev < (1 << bitDepth_in)+1) |
---|
| 1213 | { |
---|
| 1214 | Int iCodedNext = (1 << bitDepth_in); |
---|
| 1215 | Int iTargetNext = (1 << bitDepth_in) - 1; |
---|
| 1216 | |
---|
| 1217 | const Int divValue = (iCodedNext - iCodedPrev > 0)? (iCodedNext - iCodedPrev): 1; |
---|
| 1218 | const Int lutValInit = (lutOffset + iTargetPrev) << nbDecimalValues; |
---|
| 1219 | const Int roundValue = divValue / 2; |
---|
| 1220 | |
---|
| 1221 | for ( ; iValue<=iCodedNext; iValue++ ) |
---|
| 1222 | { |
---|
| 1223 | Int value = iValue; |
---|
| 1224 | Int interpol = ((((value-iCodedPrev) * (iTargetNext - iTargetPrev)) << nbDecimalValues) + roundValue) / divValue; |
---|
| 1225 | retLut[iValue] = std::min(lutValInit + interpol , maxValueFixedPoint); |
---|
| 1226 | } |
---|
| 1227 | } |
---|
| 1228 | return retLut; |
---|
| 1229 | } |
---|
| 1230 | |
---|
| 1231 | static Void |
---|
| 1232 | initColourRemappingInfoLuts(std::vector<Int> (&preLut)[3], |
---|
| 1233 | std::vector<Int> (&postLut)[3], |
---|
| 1234 | SEIColourRemappingInfo &pCriSEI, |
---|
| 1235 | const Int maxBitDepth) |
---|
| 1236 | { |
---|
| 1237 | Int internalBitDepth = pCriSEI.m_colourRemapBitDepth; |
---|
| 1238 | for ( Int c=0 ; c<3 ; c++ ) |
---|
| 1239 | { |
---|
| 1240 | std::sort(pCriSEI.m_preLut[c].begin(), pCriSEI.m_preLut[c].end()); // ensure preLut is ordered in ascending values of codedValues |
---|
| 1241 | preLut[c] = initColourRemappingInfoLut(pCriSEI.m_colourRemapInputBitDepth, maxBitDepth - pCriSEI.m_colourRemapInputBitDepth, pCriSEI.m_preLut[c], ((1 << internalBitDepth) - 1), 0); //Fill preLut |
---|
| 1242 | |
---|
| 1243 | std::sort(pCriSEI.m_postLut[c].begin(), pCriSEI.m_postLut[c].end()); // ensure postLut is ordered in ascending values of codedValues |
---|
| 1244 | postLut[c] = initColourRemappingInfoLut(pCriSEI.m_colourRemapBitDepth, maxBitDepth - pCriSEI.m_colourRemapBitDepth, pCriSEI.m_postLut[c], (1 << internalBitDepth) - 1, 0); //Fill postLut |
---|
| 1245 | } |
---|
| 1246 | } |
---|
| 1247 | |
---|
| 1248 | // apply lut. |
---|
| 1249 | // Input lut values are aligned on power of 2 boundaries |
---|
| 1250 | static Int |
---|
| 1251 | applyColourRemappingInfoLut1D(Int inVal, const std::vector<Int> &lut, const Int inValPrecisionBits) |
---|
| 1252 | { |
---|
| 1253 | const Int roundValue = (inValPrecisionBits)? 1 << (inValPrecisionBits - 1): 0; |
---|
| 1254 | inVal = std::min(std::max(0, inVal), (Int)(((lut.size()-1) << inValPrecisionBits))); |
---|
| 1255 | Int index = (Int) std::min((inVal >> inValPrecisionBits), (Int)(lut.size()-2)); |
---|
| 1256 | Int outVal = (( inVal - (index<<inValPrecisionBits) ) * (lut[index+1] - lut[index]) + roundValue) >> inValPrecisionBits; |
---|
| 1257 | outVal += lut[index] ; |
---|
| 1258 | |
---|
| 1259 | return outVal; |
---|
| 1260 | } |
---|
| 1261 | |
---|
| 1262 | static Int |
---|
| 1263 | applyColourRemappingInfoMatrix(const Int (&colourRemapCoeffs)[3], const Int postOffsetShift, const Int p0, const Int p1, const Int p2, const Int offset) |
---|
| 1264 | { |
---|
| 1265 | Int YUVMat = (colourRemapCoeffs[0]* p0 + colourRemapCoeffs[1]* p1 + colourRemapCoeffs[2]* p2 + offset) >> postOffsetShift; |
---|
| 1266 | return YUVMat; |
---|
| 1267 | } |
---|
| 1268 | |
---|
| 1269 | static Void |
---|
| 1270 | setColourRemappingInfoMatrixOffset(Int (&matrixOffset)[3], Int offset0, Int offset1, Int offset2) |
---|
| 1271 | { |
---|
| 1272 | matrixOffset[0] = offset0; |
---|
| 1273 | matrixOffset[1] = offset1; |
---|
| 1274 | matrixOffset[2] = offset2; |
---|
| 1275 | } |
---|
| 1276 | |
---|
| 1277 | static Void |
---|
| 1278 | setColourRemappingInfoMatrixOffsets( Int (&matrixInputOffset)[3], |
---|
| 1279 | Int (&matrixOutputOffset)[3], |
---|
| 1280 | const Int bitDepth, |
---|
| 1281 | const Bool crInputFullRangeFlag, |
---|
| 1282 | const Int crInputMatrixCoefficients, |
---|
| 1283 | const Bool crFullRangeFlag, |
---|
| 1284 | const Int crMatrixCoefficients) |
---|
| 1285 | { |
---|
| 1286 | // set static matrix offsets |
---|
| 1287 | Int crInputOffsetLuma = (crInputFullRangeFlag)? 0:-(16 << (bitDepth-8)); |
---|
| 1288 | Int crOffsetLuma = (crFullRangeFlag)? 0:(16 << (bitDepth-8)); |
---|
| 1289 | Int crInputOffsetChroma = 0; |
---|
| 1290 | Int crOffsetChroma = 0; |
---|
| 1291 | |
---|
| 1292 | switch(crInputMatrixCoefficients) |
---|
| 1293 | { |
---|
| 1294 | case MATRIX_COEFFICIENTS_RGB: |
---|
| 1295 | crInputOffsetChroma = 0; |
---|
| 1296 | if(!crInputFullRangeFlag) |
---|
| 1297 | { |
---|
| 1298 | fprintf(stderr, "WARNING: crInputMatrixCoefficients set to MATRIX_COEFFICIENTS_RGB and crInputFullRangeFlag not set\n"); |
---|
| 1299 | crInputOffsetLuma = 0; |
---|
| 1300 | } |
---|
| 1301 | break; |
---|
| 1302 | case MATRIX_COEFFICIENTS_UNSPECIFIED: |
---|
| 1303 | case MATRIX_COEFFICIENTS_BT709: |
---|
| 1304 | case MATRIX_COEFFICIENTS_BT2020_NON_CONSTANT_LUMINANCE: |
---|
| 1305 | crInputOffsetChroma = -(1 << (bitDepth-1)); |
---|
| 1306 | break; |
---|
| 1307 | default: |
---|
| 1308 | fprintf(stderr, "WARNING: crInputMatrixCoefficients set to undefined value: %d\n", crInputMatrixCoefficients); |
---|
| 1309 | } |
---|
| 1310 | |
---|
| 1311 | switch(crMatrixCoefficients) |
---|
| 1312 | { |
---|
| 1313 | case MATRIX_COEFFICIENTS_RGB: |
---|
| 1314 | crOffsetChroma = 0; |
---|
| 1315 | if(!crFullRangeFlag) |
---|
| 1316 | { |
---|
| 1317 | fprintf(stderr, "WARNING: crMatrixCoefficients set to MATRIX_COEFFICIENTS_RGB and crInputFullRangeFlag not set\n"); |
---|
| 1318 | crOffsetLuma = 0; |
---|
| 1319 | } |
---|
| 1320 | break; |
---|
| 1321 | case MATRIX_COEFFICIENTS_UNSPECIFIED: |
---|
| 1322 | case MATRIX_COEFFICIENTS_BT709: |
---|
| 1323 | case MATRIX_COEFFICIENTS_BT2020_NON_CONSTANT_LUMINANCE: |
---|
| 1324 | crOffsetChroma = (1 << (bitDepth-1)); |
---|
| 1325 | break; |
---|
| 1326 | default: |
---|
| 1327 | fprintf(stderr, "WARNING: crMatrixCoefficients set to undefined value: %d\n", crMatrixCoefficients); |
---|
| 1328 | } |
---|
| 1329 | |
---|
| 1330 | setColourRemappingInfoMatrixOffset(matrixInputOffset, crInputOffsetLuma, crInputOffsetChroma, crInputOffsetChroma); |
---|
| 1331 | setColourRemappingInfoMatrixOffset(matrixOutputOffset, crOffsetLuma, crOffsetChroma, crOffsetChroma); |
---|
| 1332 | } |
---|
| 1333 | |
---|
| 1334 | Void TAppDecTop::applyColourRemapping(const TComPicYuv& pic, SEIColourRemappingInfo& criSEI, const TComSPS &activeSPS) |
---|
| 1335 | { |
---|
| 1336 | const Int maxBitDepth = 16; |
---|
| 1337 | |
---|
| 1338 | // create colour remapped picture |
---|
[1470] | 1339 | if( !criSEI.m_colourRemapCancelFlag && pic.getChromaFormat()!=CHROMA_400) // 4:0:0 not supported. |
---|
[1460] | 1340 | { |
---|
[1470] | 1341 | const Int iHeight = pic.getHeight(COMPONENT_Y); |
---|
[1466] | 1342 | const Int iWidth = pic.getWidth(COMPONENT_Y); |
---|
[1470] | 1343 | const ChromaFormat chromaFormatIDC = pic.getChromaFormat(); |
---|
[1460] | 1344 | |
---|
[1470] | 1345 | TComPicYuv picYuvColourRemapped; |
---|
| 1346 | picYuvColourRemapped.createWithoutCUInfo( iWidth, iHeight, chromaFormatIDC ); |
---|
[1460] | 1347 | |
---|
[1470] | 1348 | const Int iStrideIn = pic.getStride(COMPONENT_Y); |
---|
| 1349 | const Int iCStrideIn = pic.getStride(COMPONENT_Cb); |
---|
| 1350 | const Int iStrideOut = picYuvColourRemapped.getStride(COMPONENT_Y); |
---|
| 1351 | const Int iCStrideOut = picYuvColourRemapped.getStride(COMPONENT_Cb); |
---|
| 1352 | const Bool b444 = ( pic.getChromaFormat() == CHROMA_444 ); |
---|
| 1353 | const Bool b422 = ( pic.getChromaFormat() == CHROMA_422 ); |
---|
| 1354 | const Bool b420 = ( pic.getChromaFormat() == CHROMA_420 ); |
---|
| 1355 | |
---|
[1460] | 1356 | std::vector<Int> preLut[3]; |
---|
| 1357 | std::vector<Int> postLut[3]; |
---|
| 1358 | Int matrixInputOffset[3]; |
---|
| 1359 | Int matrixOutputOffset[3]; |
---|
| 1360 | const Pel *YUVIn[MAX_NUM_COMPONENT]; |
---|
| 1361 | Pel *YUVOut[MAX_NUM_COMPONENT]; |
---|
| 1362 | YUVIn[COMPONENT_Y] = pic.getAddr(COMPONENT_Y); |
---|
| 1363 | YUVIn[COMPONENT_Cb] = pic.getAddr(COMPONENT_Cb); |
---|
| 1364 | YUVIn[COMPONENT_Cr] = pic.getAddr(COMPONENT_Cr); |
---|
[1470] | 1365 | YUVOut[COMPONENT_Y] = picYuvColourRemapped.getAddr(COMPONENT_Y); |
---|
| 1366 | YUVOut[COMPONENT_Cb] = picYuvColourRemapped.getAddr(COMPONENT_Cb); |
---|
| 1367 | YUVOut[COMPONENT_Cr] = picYuvColourRemapped.getAddr(COMPONENT_Cr); |
---|
[1460] | 1368 | |
---|
[1470] | 1369 | const Int bitDepth = criSEI.m_colourRemapBitDepth; |
---|
| 1370 | BitDepths bitDepthsCriFile; |
---|
| 1371 | bitDepthsCriFile.recon[CHANNEL_TYPE_LUMA] = bitDepth; |
---|
[1466] | 1372 | bitDepthsCriFile.recon[CHANNEL_TYPE_CHROMA] = bitDepth; // Different bitdepth is not implemented |
---|
[1460] | 1373 | |
---|
| 1374 | const Int postOffsetShift = criSEI.m_log2MatrixDenom; |
---|
| 1375 | const Int matrixRound = 1 << (postOffsetShift - 1); |
---|
| 1376 | const Int postLutInputPrecision = (maxBitDepth - criSEI.m_colourRemapBitDepth); |
---|
| 1377 | |
---|
| 1378 | if ( ! criSEI.m_colourRemapVideoSignalInfoPresentFlag ) // setting default |
---|
| 1379 | { |
---|
| 1380 | setColourRemappingInfoMatrixOffsets(matrixInputOffset, matrixOutputOffset, maxBitDepth, |
---|
| 1381 | activeSPS.getVuiParameters()->getVideoFullRangeFlag(), activeSPS.getVuiParameters()->getMatrixCoefficients(), |
---|
| 1382 | activeSPS.getVuiParameters()->getVideoFullRangeFlag(), activeSPS.getVuiParameters()->getMatrixCoefficients()); |
---|
| 1383 | } |
---|
| 1384 | else |
---|
| 1385 | { |
---|
| 1386 | setColourRemappingInfoMatrixOffsets(matrixInputOffset, matrixOutputOffset, maxBitDepth, |
---|
| 1387 | activeSPS.getVuiParameters()->getVideoFullRangeFlag(), activeSPS.getVuiParameters()->getMatrixCoefficients(), |
---|
| 1388 | criSEI.m_colourRemapFullRangeFlag, criSEI.m_colourRemapMatrixCoefficients); |
---|
| 1389 | } |
---|
| 1390 | |
---|
| 1391 | // add matrix rounding to output matrix offsets |
---|
| 1392 | matrixOutputOffset[0] = (matrixOutputOffset[0] << postOffsetShift) + matrixRound; |
---|
| 1393 | matrixOutputOffset[1] = (matrixOutputOffset[1] << postOffsetShift) + matrixRound; |
---|
| 1394 | matrixOutputOffset[2] = (matrixOutputOffset[2] << postOffsetShift) + matrixRound; |
---|
| 1395 | |
---|
| 1396 | // Merge matrixInputOffset and matrixOutputOffset to matrixOutputOffset |
---|
| 1397 | matrixOutputOffset[0] += applyColourRemappingInfoMatrix(criSEI.m_colourRemapCoeffs[0], 0, matrixInputOffset[0], matrixInputOffset[1], matrixInputOffset[2], 0); |
---|
| 1398 | matrixOutputOffset[1] += applyColourRemappingInfoMatrix(criSEI.m_colourRemapCoeffs[1], 0, matrixInputOffset[0], matrixInputOffset[1], matrixInputOffset[2], 0); |
---|
| 1399 | matrixOutputOffset[2] += applyColourRemappingInfoMatrix(criSEI.m_colourRemapCoeffs[2], 0, matrixInputOffset[0], matrixInputOffset[1], matrixInputOffset[2], 0); |
---|
| 1400 | |
---|
| 1401 | // rescaling output: include CRI/output frame difference |
---|
[1466] | 1402 | const Int scaleShiftOut_neg = abs(bitDepth - maxBitDepth); |
---|
[1460] | 1403 | const Int scaleOut_round = 1 << (scaleShiftOut_neg-1); |
---|
| 1404 | |
---|
| 1405 | initColourRemappingInfoLuts(preLut, postLut, criSEI, maxBitDepth); |
---|
| 1406 | |
---|
| 1407 | assert(pic.getChromaFormat() != CHROMA_400); |
---|
| 1408 | const Int hs = pic.getComponentScaleX(ComponentID(COMPONENT_Cb)); |
---|
[1479] | 1409 | const Int maxOutputValue = (1 << bitDepth) - 1; |
---|
[1460] | 1410 | |
---|
| 1411 | for( Int y = 0; y < iHeight; y++ ) |
---|
| 1412 | { |
---|
| 1413 | for( Int x = 0; x < iWidth; x++ ) |
---|
| 1414 | { |
---|
| 1415 | const Int xc = (x>>hs); |
---|
| 1416 | Bool computeChroma = b444 || ((b422 || !(y&1)) && !(x&1)); |
---|
| 1417 | |
---|
| 1418 | Int YUVPre_0 = applyColourRemappingInfoLut1D(YUVIn[COMPONENT_Y][x], preLut[0], 0); |
---|
| 1419 | Int YUVPre_1 = applyColourRemappingInfoLut1D(YUVIn[COMPONENT_Cb][xc], preLut[1], 0); |
---|
| 1420 | Int YUVPre_2 = applyColourRemappingInfoLut1D(YUVIn[COMPONENT_Cr][xc], preLut[2], 0); |
---|
| 1421 | |
---|
| 1422 | Int YUVMat_0 = applyColourRemappingInfoMatrix(criSEI.m_colourRemapCoeffs[0], postOffsetShift, YUVPre_0, YUVPre_1, YUVPre_2, matrixOutputOffset[0]); |
---|
| 1423 | Int YUVLutB_0 = applyColourRemappingInfoLut1D(YUVMat_0, postLut[0], postLutInputPrecision); |
---|
[1479] | 1424 | YUVOut[COMPONENT_Y][x] = std::min(maxOutputValue, (YUVLutB_0 + scaleOut_round) >> scaleShiftOut_neg); |
---|
[1460] | 1425 | |
---|
| 1426 | if( computeChroma ) |
---|
| 1427 | { |
---|
| 1428 | Int YUVMat_1 = applyColourRemappingInfoMatrix(criSEI.m_colourRemapCoeffs[1], postOffsetShift, YUVPre_0, YUVPre_1, YUVPre_2, matrixOutputOffset[1]); |
---|
| 1429 | Int YUVLutB_1 = applyColourRemappingInfoLut1D(YUVMat_1, postLut[1], postLutInputPrecision); |
---|
[1479] | 1430 | YUVOut[COMPONENT_Cb][xc] = std::min(maxOutputValue, (YUVLutB_1 + scaleOut_round) >> scaleShiftOut_neg); |
---|
[1460] | 1431 | |
---|
| 1432 | Int YUVMat_2 = applyColourRemappingInfoMatrix(criSEI.m_colourRemapCoeffs[2], postOffsetShift, YUVPre_0, YUVPre_1, YUVPre_2, matrixOutputOffset[2]); |
---|
| 1433 | Int YUVLutB_2 = applyColourRemappingInfoLut1D(YUVMat_2, postLut[2], postLutInputPrecision); |
---|
[1479] | 1434 | YUVOut[COMPONENT_Cr][xc] = std::min(maxOutputValue, (YUVLutB_2 + scaleOut_round) >> scaleShiftOut_neg); |
---|
[1460] | 1435 | } |
---|
| 1436 | } |
---|
| 1437 | |
---|
[1470] | 1438 | YUVIn[COMPONENT_Y] += iStrideIn; |
---|
| 1439 | YUVOut[COMPONENT_Y] += iStrideOut; |
---|
[1460] | 1440 | if( !(b420 && !(y&1)) ) |
---|
| 1441 | { |
---|
[1470] | 1442 | YUVIn[COMPONENT_Cb] += iCStrideIn; |
---|
| 1443 | YUVIn[COMPONENT_Cr] += iCStrideIn; |
---|
| 1444 | YUVOut[COMPONENT_Cb] += iCStrideOut; |
---|
| 1445 | YUVOut[COMPONENT_Cr] += iCStrideOut; |
---|
[1460] | 1446 | } |
---|
| 1447 | } |
---|
| 1448 | //Write remapped picture in display order |
---|
[1470] | 1449 | picYuvColourRemapped.dump( m_colourRemapSEIFileName, bitDepthsCriFile, true ); |
---|
| 1450 | picYuvColourRemapped.destroy(); |
---|
[1460] | 1451 | } |
---|
| 1452 | } |
---|
| 1453 | |
---|
[644] | 1454 | #if ALIGNED_BUMPING |
---|
| 1455 | // Function outputs a picture, and marks it as not needed for output. |
---|
[1442] | 1456 | Void TAppDecTop::xOutputAndMarkPic( TComPic *pic, std::string& reconFileName, const Int layerId, Int &pocLastDisplay, DpbStatus &dpbStatus ) |
---|
[644] | 1457 | { |
---|
[1442] | 1458 | if( !reconFileName.empty() ) |
---|
[644] | 1459 | { |
---|
| 1460 | const Window &conf = pic->getConformanceWindow(); |
---|
| 1461 | const Window &defDisp = m_respectDefDispWindow ? pic->getDefDisplayWindow() : Window(); |
---|
| 1462 | Int xScal = 1, yScal = 1; |
---|
[1203] | 1463 | |
---|
[1502] | 1464 | UInt chromaFormatIdc = pic->getSlice(0)->getSPS()->getChromaFormatIdc(); |
---|
[644] | 1465 | xScal = TComSPS::getWinUnitX( chromaFormatIdc ); |
---|
| 1466 | yScal = TComSPS::getWinUnitY( chromaFormatIdc ); |
---|
[1203] | 1467 | |
---|
[713] | 1468 | TComPicYuv* pPicCYuvRec = pic->getPicYuvRec(); |
---|
[1378] | 1469 | m_apcTVideoIOYuvReconFile[layerId]->write( pPicCYuvRec, m_outputColourSpaceConvert, |
---|
[644] | 1470 | conf.getWindowLeftOffset() * xScal + defDisp.getWindowLeftOffset(), |
---|
| 1471 | conf.getWindowRightOffset() * xScal + defDisp.getWindowRightOffset(), |
---|
| 1472 | conf.getWindowTopOffset() * yScal + defDisp.getWindowTopOffset(), |
---|
| 1473 | conf.getWindowBottomOffset()* yScal + defDisp.getWindowBottomOffset() ); |
---|
[1089] | 1474 | |
---|
[1470] | 1475 | if( !m_colourRemapSEIFileName.empty() ) |
---|
[1089] | 1476 | { |
---|
[1470] | 1477 | xOutputColourRemapPic(pic); |
---|
[1089] | 1478 | } |
---|
[644] | 1479 | } |
---|
| 1480 | // update POC of display order |
---|
| 1481 | pocLastDisplay = pic->getPOC(); |
---|
[313] | 1482 | |
---|
[644] | 1483 | // Mark as not needed for output |
---|
| 1484 | pic->setOutputMark(false); |
---|
| 1485 | |
---|
| 1486 | // "erase" non-referenced picture in the reference picture list after display |
---|
| 1487 | if ( !pic->getSlice(0)->isReferenced() && pic->getReconMark() == true ) |
---|
| 1488 | { |
---|
| 1489 | pic->setReconMark(false); |
---|
| 1490 | |
---|
| 1491 | // mark it should be extended later |
---|
| 1492 | pic->getPicYuvRec()->setBorderExtension( false ); |
---|
| 1493 | |
---|
[1050] | 1494 | dpbStatus.m_numPicsInSubDpb[dpbStatus.m_layerIdToSubDpbIdMap[layerId]]--; |
---|
[644] | 1495 | } |
---|
| 1496 | } |
---|
| 1497 | |
---|
| 1498 | Void TAppDecTop::flushAllPictures(Int layerId, Bool outputPictures) |
---|
| 1499 | { |
---|
| 1500 | // First "empty" all pictures that are not used for reference and not needed for output |
---|
| 1501 | emptyUnusedPicturesNotNeededForOutput(); |
---|
| 1502 | |
---|
| 1503 | if( outputPictures ) // All pictures in the DPB in that layer are to be output; this means other pictures would also be output |
---|
| 1504 | { |
---|
| 1505 | std::vector<Int> listOfPocs; |
---|
[1044] | 1506 | std::vector<Int> listOfPocsInEachLayer[MAX_VPS_LAYER_IDX_PLUS1]; |
---|
| 1507 | std::vector<Int> listOfPocsPositionInEachLayer[MAX_VPS_LAYER_IDX_PLUS1]; |
---|
[1221] | 1508 | |
---|
[644] | 1509 | DpbStatus dpbStatus; |
---|
| 1510 | |
---|
| 1511 | // Find the status of the DPB |
---|
| 1512 | xFindDPBStatus(listOfPocs, listOfPocsInEachLayer, listOfPocsPositionInEachLayer, dpbStatus); |
---|
| 1513 | |
---|
| 1514 | if( listOfPocs.size() ) |
---|
| 1515 | { |
---|
| 1516 | while( listOfPocsInEachLayer[layerId].size() ) // As long as there picture in the layer to be output |
---|
| 1517 | { |
---|
| 1518 | bumpingProcess( listOfPocs, listOfPocsInEachLayer, listOfPocsPositionInEachLayer, dpbStatus ); |
---|
| 1519 | } |
---|
| 1520 | } |
---|
| 1521 | } |
---|
| 1522 | |
---|
| 1523 | // Now remove all pictures from the layer DPB? |
---|
| 1524 | markAllPicturesAsErased(layerId); |
---|
| 1525 | } |
---|
[1221] | 1526 | |
---|
[644] | 1527 | Void TAppDecTop::flushAllPictures(Bool outputPictures) |
---|
| 1528 | { |
---|
| 1529 | // First "empty" all pictures that are not used for reference and not needed for output |
---|
| 1530 | emptyUnusedPicturesNotNeededForOutput(); |
---|
| 1531 | |
---|
| 1532 | if( outputPictures ) // All pictures in the DPB are to be output |
---|
| 1533 | { |
---|
| 1534 | std::vector<Int> listOfPocs; |
---|
[1044] | 1535 | std::vector<Int> listOfPocsInEachLayer[MAX_VPS_LAYER_IDX_PLUS1]; |
---|
| 1536 | std::vector<Int> listOfPocsPositionInEachLayer[MAX_VPS_LAYER_IDX_PLUS1]; |
---|
[1221] | 1537 | |
---|
[644] | 1538 | DpbStatus dpbStatus; |
---|
| 1539 | |
---|
| 1540 | // Find the status of the DPB |
---|
[815] | 1541 | xFindDPBStatus(listOfPocs, listOfPocsInEachLayer, listOfPocsPositionInEachLayer, dpbStatus, false); |
---|
[644] | 1542 | |
---|
| 1543 | while( dpbStatus.m_numAUsNotDisplayed ) |
---|
| 1544 | { |
---|
| 1545 | bumpingProcess( listOfPocs, listOfPocsInEachLayer, listOfPocsPositionInEachLayer, dpbStatus ); |
---|
| 1546 | } |
---|
| 1547 | } |
---|
| 1548 | |
---|
| 1549 | // Now remove all pictures from the DPB? |
---|
| 1550 | markAllPicturesAsErased(); |
---|
| 1551 | } |
---|
| 1552 | |
---|
| 1553 | Void TAppDecTop::markAllPicturesAsErased() |
---|
| 1554 | { |
---|
[1044] | 1555 | for(Int i = 0; i < MAX_VPS_LAYER_IDX_PLUS1; i++) |
---|
[644] | 1556 | { |
---|
[831] | 1557 | markAllPicturesAsErased(i); |
---|
[644] | 1558 | } |
---|
| 1559 | } |
---|
| 1560 | |
---|
| 1561 | Void TAppDecTop::markAllPicturesAsErased(Int layerIdx) |
---|
| 1562 | { |
---|
[1378] | 1563 | TComList<TComPic*>::iterator iterPic = m_apcTDecTop[layerIdx]->getListPic()->begin(); |
---|
| 1564 | Int iSize = Int( m_apcTDecTop[layerIdx]->getListPic()->size() ); |
---|
[831] | 1565 | |
---|
| 1566 | for (Int i = 0; i < iSize; i++ ) |
---|
| 1567 | { |
---|
| 1568 | TComPic* pcPic = *(iterPic++); |
---|
| 1569 | |
---|
| 1570 | if( pcPic ) |
---|
| 1571 | { |
---|
| 1572 | pcPic->destroy(); |
---|
| 1573 | |
---|
[842] | 1574 | // pcPic is statically created for the external (AVC) base layer, no need to delete it |
---|
[1378] | 1575 | if( !m_apcTDecTop[layerIdx]->getParameterSetManager()->getActiveVPS()->getNonHEVCBaseLayerFlag() || layerIdx ) |
---|
[842] | 1576 | { |
---|
| 1577 | delete pcPic; |
---|
| 1578 | pcPic = NULL; |
---|
| 1579 | } |
---|
[831] | 1580 | } |
---|
| 1581 | } |
---|
| 1582 | |
---|
[1378] | 1583 | m_apcTDecTop[layerIdx]->getListPic()->clear(); |
---|
[644] | 1584 | } |
---|
| 1585 | |
---|
| 1586 | Void TAppDecTop::checkOutputBeforeDecoding(Int layerIdx) |
---|
[1221] | 1587 | { |
---|
[644] | 1588 | std::vector<Int> listOfPocs; |
---|
[1044] | 1589 | std::vector<Int> listOfPocsInEachLayer[MAX_VPS_LAYER_IDX_PLUS1]; |
---|
| 1590 | std::vector<Int> listOfPocsPositionInEachLayer[MAX_VPS_LAYER_IDX_PLUS1]; |
---|
[1221] | 1591 | |
---|
[644] | 1592 | DpbStatus dpbStatus; |
---|
| 1593 | |
---|
| 1594 | // First "empty" all pictures that are not used for reference and not needed for output |
---|
| 1595 | emptyUnusedPicturesNotNeededForOutput(); |
---|
| 1596 | |
---|
| 1597 | // Find the status of the DPB |
---|
| 1598 | xFindDPBStatus(listOfPocs, listOfPocsInEachLayer, listOfPocsPositionInEachLayer, dpbStatus); |
---|
| 1599 | |
---|
| 1600 | // If not picture to be output, return |
---|
| 1601 | if( listOfPocs.size() == 0 ) |
---|
| 1602 | { |
---|
| 1603 | return; |
---|
| 1604 | } |
---|
| 1605 | |
---|
| 1606 | // Find DPB-information from the VPS |
---|
| 1607 | DpbStatus maxDpbLimit; |
---|
[1221] | 1608 | |
---|
| 1609 | Int subDpbIdx = getCommonDecoderParams()->getTargetOutputLayerSetIdx() == 0 ? dpbStatus.m_layerIdToSubDpbIdMap[0] : dpbStatus.m_layerIdToSubDpbIdMap[layerIdx]; |
---|
| 1610 | |
---|
[815] | 1611 | findDpbParametersFromVps(listOfPocs, listOfPocsInEachLayer, listOfPocsPositionInEachLayer, maxDpbLimit); |
---|
[1221] | 1612 | |
---|
[644] | 1613 | // Assume that listOfPocs is sorted in increasing order - if not have to sort it. |
---|
| 1614 | while( ifInvokeBumpingBeforeDecoding(dpbStatus, maxDpbLimit, layerIdx, subDpbIdx) ) |
---|
| 1615 | { |
---|
| 1616 | bumpingProcess( listOfPocs, listOfPocsInEachLayer, listOfPocsPositionInEachLayer, dpbStatus ); |
---|
| 1617 | } |
---|
| 1618 | } |
---|
| 1619 | |
---|
| 1620 | Void TAppDecTop::checkOutputAfterDecoding() |
---|
| 1621 | { |
---|
| 1622 | std::vector<Int> listOfPocs; |
---|
[1044] | 1623 | std::vector<Int> listOfPocsInEachLayer[MAX_VPS_LAYER_IDX_PLUS1]; |
---|
| 1624 | std::vector<Int> listOfPocsPositionInEachLayer[MAX_VPS_LAYER_IDX_PLUS1]; |
---|
[1221] | 1625 | |
---|
[644] | 1626 | DpbStatus dpbStatus; |
---|
| 1627 | |
---|
| 1628 | // First "empty" all pictures that are not used for reference and not needed for output |
---|
| 1629 | emptyUnusedPicturesNotNeededForOutput(); |
---|
| 1630 | |
---|
| 1631 | // Find the status of the DPB |
---|
| 1632 | xFindDPBStatus(listOfPocs, listOfPocsInEachLayer, listOfPocsPositionInEachLayer, dpbStatus); |
---|
| 1633 | |
---|
| 1634 | // If not picture to be output, return |
---|
| 1635 | if( listOfPocs.size() == 0 ) |
---|
| 1636 | { |
---|
| 1637 | return; |
---|
| 1638 | } |
---|
| 1639 | |
---|
| 1640 | // Find DPB-information from the VPS |
---|
| 1641 | DpbStatus maxDpbLimit; |
---|
| 1642 | findDpbParametersFromVps(listOfPocs, listOfPocsInEachLayer, listOfPocsPositionInEachLayer, maxDpbLimit); |
---|
| 1643 | |
---|
| 1644 | // Assume that listOfPocs is sorted in increasing order - if not have to sort it. |
---|
| 1645 | while( ifInvokeBumpingAfterDecoding(dpbStatus, maxDpbLimit) ) |
---|
| 1646 | { |
---|
| 1647 | bumpingProcess( listOfPocs, listOfPocsInEachLayer, listOfPocsPositionInEachLayer, dpbStatus ); |
---|
| 1648 | } |
---|
| 1649 | } |
---|
| 1650 | |
---|
| 1651 | Void TAppDecTop::bumpingProcess(std::vector<Int> &listOfPocs, std::vector<Int> *listOfPocsInEachLayer, std::vector<Int> *listOfPocsPositionInEachLayer, DpbStatus &dpbStatus) |
---|
| 1652 | { |
---|
| 1653 | // Choose the smallest POC value |
---|
| 1654 | Int pocValue = *(listOfPocs.begin()); |
---|
| 1655 | std::vector<int>::iterator it; |
---|
| 1656 | TComList<TComPic*>::iterator iterPic; |
---|
[1221] | 1657 | |
---|
[952] | 1658 | for( Int dpbLayerCtr = 0; dpbLayerCtr < dpbStatus.m_numLayers; dpbLayerCtr++) |
---|
| 1659 | { |
---|
[1050] | 1660 | Int layerId = dpbStatus.m_targetDecLayerIdList[dpbLayerCtr]; |
---|
[1221] | 1661 | |
---|
[644] | 1662 | // Check if picture with pocValue is present. |
---|
[1050] | 1663 | it = find( listOfPocsInEachLayer[layerId].begin(), listOfPocsInEachLayer[layerId].end(), pocValue ); |
---|
| 1664 | if( it != listOfPocsInEachLayer[layerId].end() ) // picture found. |
---|
[644] | 1665 | { |
---|
[1077] | 1666 | Int picPosition = (Int)std::distance( listOfPocsInEachLayer[layerId].begin(), it ); |
---|
[644] | 1667 | Int j; |
---|
[1378] | 1668 | for(j = 0, iterPic = m_apcTDecTop[layerId]->getListPic()->begin(); j < listOfPocsPositionInEachLayer[layerId][picPosition]; j++) // Picture to be output |
---|
[644] | 1669 | { |
---|
| 1670 | iterPic++; |
---|
| 1671 | } |
---|
| 1672 | TComPic *pic = *iterPic; |
---|
| 1673 | |
---|
[1442] | 1674 | xOutputAndMarkPic( pic, m_reconFileName[layerId], layerId, m_aiPOCLastDisplay[layerId], dpbStatus ); |
---|
[644] | 1675 | |
---|
[924] | 1676 | #if CONFORMANCE_BITSTREAM_MODE |
---|
[930] | 1677 | FILE *fptr; |
---|
[1029] | 1678 | if( m_confModeFlag ) |
---|
[930] | 1679 | { |
---|
[1029] | 1680 | if( m_metadataFileRefresh ) |
---|
[930] | 1681 | { |
---|
| 1682 | fptr = fopen( this->getMetadataFileName().c_str(), "w" ); |
---|
| 1683 | fprintf(fptr, " LayerId POC MD5\n"); |
---|
| 1684 | fprintf(fptr, "------------------------\n"); |
---|
| 1685 | } |
---|
| 1686 | else |
---|
| 1687 | { |
---|
| 1688 | fptr = fopen( this->getMetadataFileName().c_str(), "a+" ); |
---|
| 1689 | } |
---|
| 1690 | this->setMetadataFileRefresh(false); |
---|
[1029] | 1691 | |
---|
[1273] | 1692 | TComPictureHash recon_digest; |
---|
[1502] | 1693 | Int numChar = calcMD5(*pic->getPicYuvRec(), recon_digest, pic->getSlice(0)->getSPS()->getBitDepths()); |
---|
[1273] | 1694 | fprintf(fptr, "%8d%9d MD5:%s\n", pic->getLayerId(), pic->getSlice(0)->getPOC(), hashToString(recon_digest, numChar).c_str()); |
---|
[930] | 1695 | fclose(fptr); |
---|
| 1696 | } |
---|
| 1697 | #endif |
---|
[924] | 1698 | |
---|
[1050] | 1699 | listOfPocsInEachLayer[layerId].erase( it ); |
---|
| 1700 | listOfPocsPositionInEachLayer[layerId].erase( listOfPocsPositionInEachLayer[layerId].begin() + picPosition ); |
---|
| 1701 | dpbStatus.m_numPicsInSubDpb[dpbStatus.m_layerIdToSubDpbIdMap[layerId]]--; |
---|
[644] | 1702 | } |
---|
| 1703 | } |
---|
[1221] | 1704 | |
---|
[1029] | 1705 | dpbStatus.m_numAUsNotDisplayed--; |
---|
[644] | 1706 | |
---|
[953] | 1707 | #if CONFORMANCE_BITSTREAM_MODE |
---|
[1029] | 1708 | if( m_confModeFlag ) |
---|
[953] | 1709 | { |
---|
| 1710 | for( Int dpbLayerCtr = 0; dpbLayerCtr < dpbStatus.m_numLayers; dpbLayerCtr++) |
---|
| 1711 | { |
---|
[1049] | 1712 | Int layerId = dpbStatus.m_targetDecLayerIdList[dpbLayerCtr]; |
---|
[953] | 1713 | // Output all picutres "decoded" in that layer that have POC less than the current picture |
---|
[1378] | 1714 | std::vector<TComPic> *layerBuffer = m_apcTDecTop[layerId]->getConfListPic(); |
---|
[953] | 1715 | // Write all pictures to the file. |
---|
[1521] | 1716 | if( this->getDecodedYuvLayerRefresh(layerId) && m_apcTDecTop[layerId]->getParameterSetManager()->getActiveSPS()) |
---|
[953] | 1717 | { |
---|
| 1718 | char tempFileName[256]; |
---|
[1049] | 1719 | strcpy(tempFileName, this->getDecodedYuvLayerFileName( layerId ).c_str()); |
---|
[1287] | 1720 | |
---|
[1378] | 1721 | const TComSPS *sps = m_apcTDecTop[layerId]->getParameterSetManager()->getActiveSPS(); |
---|
[1502] | 1722 | const BitDepths &bitDpeths = sps->getBitDepths(); |
---|
[1287] | 1723 | Int bitDepth[] = {bitDpeths.recon[CHANNEL_TYPE_LUMA], bitDpeths.recon[CHANNEL_TYPE_CHROMA]}; |
---|
| 1724 | |
---|
[1416] | 1725 | m_confReconFile[layerId].open(tempFileName, true, bitDepth, bitDepth, bitDepth ); // write mode |
---|
[1049] | 1726 | this->setDecodedYuvLayerRefresh( layerId, false ); |
---|
[953] | 1727 | } |
---|
| 1728 | |
---|
| 1729 | std::vector<TComPic>::iterator itPic; |
---|
| 1730 | for(itPic = layerBuffer->begin(); itPic != layerBuffer->end(); itPic++) |
---|
| 1731 | { |
---|
| 1732 | TComPic checkPic = *itPic; |
---|
| 1733 | const Window &conf = checkPic.getConformanceWindow(); |
---|
| 1734 | const Window &defDisp = m_respectDefDispWindow ? checkPic.getDefDisplayWindow() : Window(); |
---|
[1029] | 1735 | Int xScal = 1, yScal = 1; |
---|
[1203] | 1736 | |
---|
[1502] | 1737 | UInt chromaFormatIdc = checkPic.getSlice(0)->getSPS()->getChromaFormatIdc(); |
---|
[953] | 1738 | xScal = TComSPS::getWinUnitX( chromaFormatIdc ); |
---|
| 1739 | yScal = TComSPS::getWinUnitY( chromaFormatIdc ); |
---|
[1203] | 1740 | |
---|
[953] | 1741 | if( checkPic.getPOC() <= pocValue ) |
---|
| 1742 | { |
---|
| 1743 | TComPicYuv* pPicCYuvRec = checkPic.getPicYuvRec(); |
---|
[1049] | 1744 | m_confReconFile[layerId].write( pPicCYuvRec, m_outputColourSpaceConvert, |
---|
[953] | 1745 | conf.getWindowLeftOffset() * xScal + defDisp.getWindowLeftOffset(), |
---|
| 1746 | conf.getWindowRightOffset() * xScal + defDisp.getWindowRightOffset(), |
---|
| 1747 | conf.getWindowTopOffset() * yScal + defDisp.getWindowTopOffset(), |
---|
[1416] | 1748 | conf.getWindowBottomOffset()* yScal + defDisp.getWindowBottomOffset(), |
---|
| 1749 | NUM_CHROMA_FORMAT, m_bClipOutputVideoToRec709Range ); |
---|
| 1750 | |
---|
[953] | 1751 | layerBuffer->erase(itPic); |
---|
| 1752 | itPic = layerBuffer->begin(); // Ensure doesn't go to infinite loop |
---|
| 1753 | if(layerBuffer->size() == 0) |
---|
| 1754 | { |
---|
| 1755 | break; |
---|
| 1756 | } |
---|
| 1757 | } |
---|
| 1758 | } |
---|
| 1759 | } |
---|
| 1760 | } |
---|
| 1761 | #endif |
---|
[1029] | 1762 | |
---|
[644] | 1763 | // Remove the picture from the listOfPocs |
---|
| 1764 | listOfPocs.erase( listOfPocs.begin() ); |
---|
| 1765 | } |
---|
| 1766 | |
---|
[1235] | 1767 | const TComVPS *TAppDecTop::findDpbParametersFromVps(std::vector<Int> const &listOfPocs, std::vector<Int> const *listOfPocsInEachLayer, std::vector<Int> const *listOfPocsPositionInEachLayer, DpbStatus &maxDpbLimit) |
---|
[644] | 1768 | { |
---|
| 1769 | Int targetOutputLsIdx = getCommonDecoderParams()->getTargetOutputLayerSetIdx(); |
---|
[1235] | 1770 | const TComVPS *vps = NULL; |
---|
[644] | 1771 | |
---|
| 1772 | if( targetOutputLsIdx == 0 ) // Only base layer is output |
---|
| 1773 | { |
---|
[1235] | 1774 | const TComSPS *sps = NULL; |
---|
[644] | 1775 | assert( listOfPocsInEachLayer[0].size() != 0 ); |
---|
| 1776 | TComList<TComPic*>::iterator iterPic; |
---|
| 1777 | Int j; |
---|
[1378] | 1778 | for(j = 0, iterPic = m_apcTDecTop[0]->getListPic()->begin(); j < listOfPocsPositionInEachLayer[0][0]; j++) // Picture to be output |
---|
[644] | 1779 | { |
---|
| 1780 | iterPic++; |
---|
| 1781 | } |
---|
| 1782 | TComPic *pic = *iterPic; |
---|
| 1783 | sps = pic->getSlice(0)->getSPS(); assert( sps->getLayerId() == 0 ); |
---|
| 1784 | vps = pic->getSlice(0)->getVPS(); |
---|
| 1785 | Int highestTId = sps->getMaxTLayers() - 1; |
---|
| 1786 | |
---|
| 1787 | maxDpbLimit.m_numAUsNotDisplayed = sps->getNumReorderPics( highestTId ); // m_numAUsNotDisplayed is only variable name - stores reorderpics |
---|
[1464] | 1788 | maxDpbLimit.m_maxLatencyIncrease = sps->getMaxLatencyIncreasePlus1( highestTId ) > 0; |
---|
[644] | 1789 | if( maxDpbLimit.m_maxLatencyIncrease ) |
---|
| 1790 | { |
---|
[1464] | 1791 | maxDpbLimit.m_maxLatencyPictures = sps->getMaxLatencyIncreasePlus1( highestTId ) + sps->getNumReorderPics( highestTId ) - 1; |
---|
[644] | 1792 | } |
---|
| 1793 | maxDpbLimit.m_numPicsInSubDpb[0] = sps->getMaxDecPicBuffering( highestTId ); |
---|
| 1794 | } |
---|
| 1795 | else |
---|
| 1796 | { |
---|
| 1797 | // ------------------------------------- |
---|
| 1798 | // Find the VPS used for the pictures |
---|
| 1799 | // ------------------------------------- |
---|
[1221] | 1800 | for( Int i = 0; i < MAX_VPS_LAYER_IDX_PLUS1; i++ ) |
---|
[644] | 1801 | { |
---|
[1378] | 1802 | if( m_apcTDecTop[i]->getListPic()->empty() ) |
---|
[644] | 1803 | { |
---|
| 1804 | assert( listOfPocsInEachLayer[i].size() == 0 ); |
---|
| 1805 | continue; |
---|
| 1806 | } |
---|
[1221] | 1807 | |
---|
[644] | 1808 | std::vector<Int>::const_iterator it; |
---|
| 1809 | it = find( listOfPocsInEachLayer[i].begin(), listOfPocsInEachLayer[i].end(), listOfPocs[0] ); |
---|
| 1810 | TComList<TComPic*>::iterator iterPic; |
---|
[1221] | 1811 | |
---|
[644] | 1812 | if( it != listOfPocsInEachLayer[i].end() ) |
---|
| 1813 | { |
---|
[1077] | 1814 | Int picPosition = (Int)std::distance( listOfPocsInEachLayer[i].begin(), it ); |
---|
[644] | 1815 | Int j; |
---|
[1221] | 1816 | |
---|
| 1817 | // Picture to be output |
---|
[1378] | 1818 | for( j = 0, iterPic = m_apcTDecTop[i]->getListPic()->begin(); j < listOfPocsPositionInEachLayer[i][picPosition]; j++ ) |
---|
[644] | 1819 | { |
---|
| 1820 | iterPic++; |
---|
| 1821 | } |
---|
[1221] | 1822 | |
---|
[644] | 1823 | TComPic *pic = *iterPic; |
---|
| 1824 | vps = pic->getSlice(0)->getVPS(); |
---|
| 1825 | break; |
---|
| 1826 | } |
---|
| 1827 | } |
---|
| 1828 | |
---|
| 1829 | Int targetLsIdx = vps->getOutputLayerSetIdx( getCommonDecoderParams()->getTargetOutputLayerSetIdx() ); |
---|
| 1830 | Int highestTId = vps->getMaxTLayers() - 1; |
---|
| 1831 | |
---|
| 1832 | maxDpbLimit.m_numAUsNotDisplayed = vps->getMaxVpsNumReorderPics( targetOutputLsIdx, highestTId ); // m_numAUsNotDisplayed is only variable name - stores reorderpics |
---|
| 1833 | maxDpbLimit.m_maxLatencyIncrease = vps->getMaxVpsLatencyIncreasePlus1(targetOutputLsIdx, highestTId ) > 0; |
---|
[1221] | 1834 | |
---|
[644] | 1835 | if( maxDpbLimit.m_maxLatencyIncrease ) |
---|
| 1836 | { |
---|
| 1837 | maxDpbLimit.m_maxLatencyPictures = vps->getMaxVpsNumReorderPics( targetOutputLsIdx, highestTId ) + vps->getMaxVpsLatencyIncreasePlus1(targetOutputLsIdx, highestTId ) - 1; |
---|
| 1838 | } |
---|
[1221] | 1839 | |
---|
[644] | 1840 | for(Int i = 0; i < vps->getNumLayersInIdList( targetLsIdx ); i++) |
---|
| 1841 | { |
---|
[815] | 1842 | maxDpbLimit.m_numPicsInSubDpb[i] = vps->getMaxVpsDecPicBufferingMinus1( targetOutputLsIdx, i, highestTId) + 1; |
---|
[644] | 1843 | } |
---|
| 1844 | // ------------------------------------- |
---|
| 1845 | } |
---|
| 1846 | return vps; |
---|
| 1847 | } |
---|
[1221] | 1848 | |
---|
[644] | 1849 | Void TAppDecTop::emptyUnusedPicturesNotNeededForOutput() |
---|
| 1850 | { |
---|
[1221] | 1851 | for( Int layerIdx = 0; layerIdx < MAX_VPS_LAYER_IDX_PLUS1; layerIdx++ ) |
---|
[644] | 1852 | { |
---|
[1378] | 1853 | TComList <TComPic*> *pcListPic = m_apcTDecTop[layerIdx]->getListPic(); |
---|
[644] | 1854 | TComList<TComPic*>::iterator iterPic = pcListPic->begin(); |
---|
| 1855 | while ( iterPic != pcListPic->end() ) |
---|
| 1856 | { |
---|
| 1857 | TComPic *pic = *iterPic; |
---|
[1235] | 1858 | |
---|
| 1859 | assert( pic->getPicSym() ); |
---|
| 1860 | |
---|
[644] | 1861 | if( !pic->getSlice(0)->isReferenced() && !pic->getOutputMark() ) |
---|
| 1862 | { |
---|
| 1863 | // Emtpy the picture buffer |
---|
| 1864 | pic->setReconMark( false ); |
---|
| 1865 | } |
---|
| 1866 | iterPic++; |
---|
| 1867 | } |
---|
| 1868 | } |
---|
| 1869 | } |
---|
| 1870 | |
---|
| 1871 | Bool TAppDecTop::ifInvokeBumpingBeforeDecoding( const DpbStatus &dpbStatus, const DpbStatus &dpbLimit, const Int layerIdx, const Int subDpbIdx ) |
---|
| 1872 | { |
---|
| 1873 | Bool retVal = false; |
---|
| 1874 | // Number of reorder picutres |
---|
| 1875 | retVal |= ( dpbStatus.m_numAUsNotDisplayed > dpbLimit.m_numAUsNotDisplayed ); |
---|
| 1876 | |
---|
| 1877 | // Number of pictures in each sub-DPB |
---|
| 1878 | retVal |= ( dpbStatus.m_numPicsInSubDpb[subDpbIdx] >= dpbLimit.m_numPicsInSubDpb[subDpbIdx] ); |
---|
| 1879 | |
---|
| 1880 | return retVal; |
---|
| 1881 | } |
---|
| 1882 | |
---|
| 1883 | Bool TAppDecTop::ifInvokeBumpingAfterDecoding( const DpbStatus &dpbStatus, const DpbStatus &dpbLimit ) |
---|
| 1884 | { |
---|
| 1885 | Bool retVal = false; |
---|
| 1886 | |
---|
| 1887 | // Number of reorder picutres |
---|
| 1888 | retVal |= ( dpbStatus.m_numAUsNotDisplayed > dpbLimit.m_numAUsNotDisplayed ); |
---|
| 1889 | |
---|
| 1890 | return retVal; |
---|
| 1891 | } |
---|
| 1892 | |
---|
| 1893 | Void TAppDecTop::xFindDPBStatus( std::vector<Int> &listOfPocs |
---|
| 1894 | , std::vector<Int> *listOfPocsInEachLayer |
---|
| 1895 | , std::vector<Int> *listOfPocsPositionInEachLayer |
---|
| 1896 | , DpbStatus &dpbStatus |
---|
[815] | 1897 | , Bool notOutputCurrAu |
---|
[644] | 1898 | ) |
---|
| 1899 | { |
---|
[1235] | 1900 | const TComVPS *vps = NULL; |
---|
[644] | 1901 | dpbStatus.init(); |
---|
[1221] | 1902 | |
---|
[1044] | 1903 | for( Int i = 0; i < MAX_VPS_LAYER_IDX_PLUS1; i++ ) |
---|
[644] | 1904 | { |
---|
[1378] | 1905 | if( m_apcTDecTop[i]->getListPic()->empty() ) |
---|
[644] | 1906 | { |
---|
| 1907 | continue; |
---|
| 1908 | } |
---|
| 1909 | |
---|
| 1910 | // To check # AUs that have at least one picture not output, |
---|
| 1911 | // For each layer, populate listOfPOcs if not already present |
---|
[1378] | 1912 | TComList<TComPic*>::iterator iterPic = m_apcTDecTop[i]->getListPic()->begin(); |
---|
[644] | 1913 | Int picPositionInList = 0; |
---|
[1378] | 1914 | while (iterPic != m_apcTDecTop[i]->getListPic()->end()) |
---|
[644] | 1915 | { |
---|
| 1916 | TComPic* pic = *(iterPic); |
---|
| 1917 | if( pic->getReconMark() ) |
---|
| 1918 | { |
---|
| 1919 | if( vps == NULL ) |
---|
| 1920 | { |
---|
[1504] | 1921 | vps = m_apcTDecTop[i]->getParameterSetManager()->getActiveVPS(); |
---|
[644] | 1922 | } |
---|
[1210] | 1923 | |
---|
[815] | 1924 | if( !(pic->isCurrAu() && notOutputCurrAu ) ) |
---|
[644] | 1925 | { |
---|
[815] | 1926 | std::vector<Int>::iterator it; |
---|
| 1927 | if( pic->getOutputMark() ) // && pic->getPOC() > m_aiPOCLastDisplay[i]) |
---|
[644] | 1928 | { |
---|
[815] | 1929 | it = find( listOfPocs.begin(), listOfPocs.end(), pic->getPOC() ); // Check if already included |
---|
[1210] | 1930 | |
---|
[815] | 1931 | if( it == listOfPocs.end() ) // New POC value - i.e. new AU - add to the list |
---|
| 1932 | { |
---|
| 1933 | listOfPocs.push_back( pic->getPOC() ); |
---|
| 1934 | } |
---|
| 1935 | listOfPocsInEachLayer [i].push_back( pic->getPOC() ); // POC to be output in each layer |
---|
| 1936 | listOfPocsPositionInEachLayer [i].push_back( picPositionInList ); // For ease of access |
---|
[644] | 1937 | } |
---|
[1210] | 1938 | |
---|
[815] | 1939 | if( pic->getSlice(0)->isReferenced() || pic->getOutputMark() ) |
---|
| 1940 | { |
---|
[845] | 1941 | dpbStatus.m_numPicsInSubDpb[i]++; // Count pictures that are "used for reference" or "needed for output" |
---|
[815] | 1942 | } |
---|
[644] | 1943 | } |
---|
| 1944 | } |
---|
[1210] | 1945 | |
---|
[644] | 1946 | iterPic++; |
---|
| 1947 | picPositionInList++; |
---|
| 1948 | } |
---|
| 1949 | } |
---|
| 1950 | |
---|
[1486] | 1951 | #if CONFORMANCE_BITSTREAM_FIX |
---|
| 1952 | if (!vps) return; |
---|
| 1953 | #else |
---|
[644] | 1954 | assert( vps != NULL ); // No picture in any DPB? |
---|
[1486] | 1955 | #endif |
---|
[644] | 1956 | std::sort( listOfPocs.begin(), listOfPocs.end() ); // Sort in increasing order of POC |
---|
| 1957 | Int targetLsIdx = vps->getOutputLayerSetIdx( getCommonDecoderParams()->getTargetOutputLayerSetIdx() ); |
---|
[1221] | 1958 | |
---|
[644] | 1959 | // Update status |
---|
[1077] | 1960 | dpbStatus.m_numAUsNotDisplayed = (Int)listOfPocs.size(); // Number of AUs not displayed |
---|
[644] | 1961 | dpbStatus.m_numLayers = vps->getNumLayersInIdList( targetLsIdx ); |
---|
[1221] | 1962 | |
---|
| 1963 | for( Int i = 0; i < dpbStatus.m_numLayers; i++ ) |
---|
[952] | 1964 | { |
---|
| 1965 | dpbStatus.m_layerIdToSubDpbIdMap[vps->getLayerSetLayerIdList(targetLsIdx, i)] = i; |
---|
| 1966 | dpbStatus.m_targetDecLayerIdList[i] = vps->getLayerSetLayerIdList(targetLsIdx, i); // Layer Id stored in a particular sub-DPB |
---|
| 1967 | } |
---|
| 1968 | dpbStatus.m_numSubDpbs = vps->getNumSubDpbs( targetLsIdx ); |
---|
[644] | 1969 | |
---|
[1221] | 1970 | for( Int i = 0; i < MAX_VPS_LAYER_IDX_PLUS1; i++ ) |
---|
[644] | 1971 | { |
---|
[1077] | 1972 | dpbStatus.m_numPicsNotDisplayedInLayer[i] = (Int)listOfPocsInEachLayer[i].size(); |
---|
[644] | 1973 | } |
---|
| 1974 | assert( dpbStatus.m_numAUsNotDisplayed != -1 ); |
---|
[815] | 1975 | } |
---|
[644] | 1976 | |
---|
[815] | 1977 | Void TAppDecTop::outputAllPictures(Int layerId, Bool notOutputCurrPic) |
---|
| 1978 | { |
---|
| 1979 | { // All pictures in the DPB in that layer are to be output; this means other pictures would also be output |
---|
| 1980 | std::vector<Int> listOfPocs; |
---|
[1044] | 1981 | std::vector<Int> listOfPocsInEachLayer[MAX_VPS_LAYER_IDX_PLUS1]; |
---|
| 1982 | std::vector<Int> listOfPocsPositionInEachLayer[MAX_VPS_LAYER_IDX_PLUS1]; |
---|
[1221] | 1983 | |
---|
[815] | 1984 | DpbStatus dpbStatus; |
---|
[644] | 1985 | |
---|
[815] | 1986 | // Find the status of the DPB |
---|
| 1987 | xFindDPBStatus(listOfPocs, listOfPocsInEachLayer, listOfPocsPositionInEachLayer, dpbStatus, notOutputCurrPic); |
---|
| 1988 | |
---|
| 1989 | if( listOfPocs.size() ) |
---|
| 1990 | { |
---|
| 1991 | while( listOfPocsInEachLayer[layerId].size() ) // As long as there picture in the layer to be output |
---|
| 1992 | { |
---|
| 1993 | bumpingProcess( listOfPocs, listOfPocsInEachLayer, listOfPocsPositionInEachLayer, dpbStatus ); |
---|
| 1994 | } |
---|
| 1995 | } |
---|
| 1996 | } |
---|
| 1997 | } |
---|
[1221] | 1998 | #endif //ALIGNED_BUMPING |
---|
[1089] | 1999 | |
---|
[313] | 2000 | //! \} |
---|