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