[324] | 1 | /* The copyright in this software is being made available under the BSD |
---|
| 2 | * License, included below. This software may be subject to other third party |
---|
| 3 | * and contributor rights, including patent rights, and no such rights are |
---|
| 4 | * granted under this license. |
---|
| 5 | * |
---|
| 6 | * Copyright (c) 2010-2013, ITU/ISO/IEC |
---|
| 7 | * All rights reserved. |
---|
| 8 | * |
---|
| 9 | * Redistribution and use in source and binary forms, with or without |
---|
| 10 | * modification, are permitted provided that the following conditions are met: |
---|
| 11 | * |
---|
| 12 | * * Redistributions of source code must retain the above copyright notice, |
---|
| 13 | * this list of conditions and the following disclaimer. |
---|
| 14 | * * Redistributions in binary form must reproduce the above copyright notice, |
---|
| 15 | * this list of conditions and the following disclaimer in the documentation |
---|
| 16 | * and/or other materials provided with the distribution. |
---|
| 17 | * * Neither the name of the ITU/ISO/IEC nor the names of its contributors may |
---|
| 18 | * be used to endorse or promote products derived from this software without |
---|
| 19 | * specific prior written permission. |
---|
| 20 | * |
---|
| 21 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
---|
| 22 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
---|
| 23 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
---|
| 24 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS |
---|
| 25 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
---|
| 26 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
---|
| 27 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
---|
| 28 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
---|
| 29 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
---|
| 30 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF |
---|
| 31 | * THE POSSIBILITY OF SUCH DAMAGE. |
---|
| 32 | */ |
---|
| 33 | |
---|
| 34 | /** \file 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> |
---|
| 43 | |
---|
| 44 | #include "TAppDecTop.h" |
---|
| 45 | #include "TLibDecoder/AnnexBread.h" |
---|
| 46 | #include "TLibDecoder/NALread.h" |
---|
| 47 | |
---|
| 48 | //! \ingroup TAppDecoder |
---|
| 49 | //! \{ |
---|
| 50 | |
---|
| 51 | // ==================================================================================================================== |
---|
| 52 | // Constructor / destructor / initialization / destroy |
---|
| 53 | // ==================================================================================================================== |
---|
| 54 | |
---|
| 55 | TAppDecTop::TAppDecTop() |
---|
[368] | 56 | #if !H_MV |
---|
[324] | 57 | : m_iPOCLastDisplay(-MAX_INT) |
---|
[368] | 58 | #else |
---|
| 59 | : m_numDecoders( 0 ) |
---|
| 60 | #endif |
---|
[324] | 61 | { |
---|
| 62 | ::memset (m_abDecFlag, 0, sizeof (m_abDecFlag)); |
---|
[368] | 63 | #if H_MV |
---|
| 64 | for (Int i = 0; i < MAX_NUM_LAYER_IDS; i++) m_layerIdToDecIdx[i] = -1; |
---|
| 65 | #endif |
---|
[446] | 66 | #if H_3D |
---|
| 67 | m_pScaleOffsetFile = 0; |
---|
| 68 | #endif |
---|
[324] | 69 | } |
---|
| 70 | |
---|
| 71 | Void TAppDecTop::create() |
---|
| 72 | { |
---|
| 73 | } |
---|
| 74 | |
---|
| 75 | Void TAppDecTop::destroy() |
---|
| 76 | { |
---|
| 77 | if (m_pchBitstreamFile) |
---|
| 78 | { |
---|
| 79 | free (m_pchBitstreamFile); |
---|
| 80 | m_pchBitstreamFile = NULL; |
---|
| 81 | } |
---|
[368] | 82 | #if H_MV |
---|
| 83 | for (Int decIdx = 0; decIdx < m_numDecoders; decIdx++) |
---|
| 84 | { |
---|
| 85 | if (m_pchReconFiles[decIdx]) |
---|
| 86 | { |
---|
| 87 | free (m_pchReconFiles[decIdx]); |
---|
| 88 | m_pchReconFiles[decIdx] = NULL; |
---|
| 89 | } |
---|
| 90 | } |
---|
| 91 | #endif |
---|
[324] | 92 | if (m_pchReconFile) |
---|
| 93 | { |
---|
| 94 | free (m_pchReconFile); |
---|
| 95 | m_pchReconFile = NULL; |
---|
| 96 | } |
---|
[473] | 97 | #if H_3D_FIX |
---|
| 98 | if (m_pchScaleOffsetFile) |
---|
| 99 | { |
---|
| 100 | free (m_pchScaleOffsetFile); |
---|
| 101 | m_pchScaleOffsetFile = NULL; |
---|
| 102 | } |
---|
| 103 | #endif |
---|
[324] | 104 | } |
---|
| 105 | |
---|
| 106 | // ==================================================================================================================== |
---|
| 107 | // Public member functions |
---|
| 108 | // ==================================================================================================================== |
---|
| 109 | |
---|
| 110 | /** |
---|
| 111 | - create internal class |
---|
| 112 | - initialize internal class |
---|
| 113 | - until the end of the bitstream, call decoding function in TDecTop class |
---|
| 114 | - delete allocated buffers |
---|
| 115 | - destroy internal class |
---|
| 116 | . |
---|
| 117 | */ |
---|
| 118 | Void TAppDecTop::decode() |
---|
| 119 | { |
---|
| 120 | Int poc; |
---|
[368] | 121 | #if H_MV |
---|
| 122 | poc = -1; |
---|
| 123 | #endif |
---|
[324] | 124 | TComList<TComPic*>* pcListPic = NULL; |
---|
| 125 | |
---|
| 126 | ifstream bitstreamFile(m_pchBitstreamFile, ifstream::in | ifstream::binary); |
---|
| 127 | if (!bitstreamFile) |
---|
| 128 | { |
---|
| 129 | fprintf(stderr, "\nfailed to open bitstream file `%s' for reading\n", m_pchBitstreamFile); |
---|
| 130 | exit(EXIT_FAILURE); |
---|
| 131 | } |
---|
| 132 | |
---|
[446] | 133 | #if H_3D |
---|
| 134 | if( m_pchScaleOffsetFile ) |
---|
| 135 | { |
---|
| 136 | m_pScaleOffsetFile = ::fopen( m_pchScaleOffsetFile, "wt" ); |
---|
| 137 | AOF( m_pScaleOffsetFile ); |
---|
| 138 | } |
---|
| 139 | m_cCamParsCollector.init( m_pScaleOffsetFile ); |
---|
| 140 | #endif |
---|
[324] | 141 | InputByteStream bytestream(bitstreamFile); |
---|
| 142 | |
---|
| 143 | // create & initialize internal classes |
---|
| 144 | xCreateDecLib(); |
---|
| 145 | xInitDecLib (); |
---|
[368] | 146 | #if !H_MV |
---|
[324] | 147 | m_iPOCLastDisplay += m_iSkipFrame; // set the last displayed POC correctly for skip forward. |
---|
| 148 | |
---|
| 149 | // main decoder loop |
---|
| 150 | Bool recon_opened = false; // reconstruction file not yet opened. (must be performed after SPS is seen) |
---|
[368] | 151 | #else |
---|
| 152 | Int pocCurrPic = -MAX_INT; |
---|
| 153 | Int pocLastPic = -MAX_INT; |
---|
| 154 | |
---|
| 155 | Int layerIdCurrPic = 0; |
---|
| 156 | |
---|
| 157 | Int decIdxLastPic = 0; |
---|
| 158 | Int decIdxCurrPic = 0; |
---|
| 159 | |
---|
| 160 | Bool firstSlice = true; |
---|
| 161 | #endif |
---|
[324] | 162 | |
---|
| 163 | while (!!bitstreamFile) |
---|
| 164 | { |
---|
| 165 | /* location serves to work around a design fault in the decoder, whereby |
---|
| 166 | * the process of reading a new slice that is the first slice of a new frame |
---|
| 167 | * requires the TDecTop::decode() method to be called again with the same |
---|
| 168 | * nal unit. */ |
---|
| 169 | streampos location = bitstreamFile.tellg(); |
---|
[446] | 170 | #if H_MV |
---|
| 171 | #if ENC_DEC_TRACE |
---|
| 172 | Int64 symCount = g_nSymbolCounter; |
---|
| 173 | #endif |
---|
| 174 | #endif |
---|
[324] | 175 | AnnexBStats stats = AnnexBStats(); |
---|
[368] | 176 | #if !H_MV |
---|
[324] | 177 | Bool bPreviousPictureDecoded = false; |
---|
[368] | 178 | #endif |
---|
[446] | 179 | |
---|
[324] | 180 | vector<uint8_t> nalUnit; |
---|
| 181 | InputNALUnit nalu; |
---|
| 182 | byteStreamNALUnit(bytestream, nalUnit, stats); |
---|
| 183 | |
---|
| 184 | // call actual decoding function |
---|
| 185 | Bool bNewPicture = false; |
---|
[368] | 186 | #if H_MV |
---|
| 187 | Bool newSliceDiffPoc = false; |
---|
| 188 | Bool newSliceDiffLayer = false; |
---|
| 189 | Bool allLayersDecoded = false; |
---|
| 190 | #endif |
---|
[324] | 191 | if (nalUnit.empty()) |
---|
| 192 | { |
---|
| 193 | /* this can happen if the following occur: |
---|
| 194 | * - empty input file |
---|
| 195 | * - two back-to-back start_code_prefixes |
---|
| 196 | * - start_code_prefix immediately followed by EOF |
---|
| 197 | */ |
---|
| 198 | fprintf(stderr, "Warning: Attempt to decode an empty NAL unit\n"); |
---|
| 199 | } |
---|
| 200 | else |
---|
| 201 | { |
---|
| 202 | read(nalu, nalUnit); |
---|
[368] | 203 | #if H_MV |
---|
| 204 | Int decIdx = xGetDecoderIdx( nalu.m_layerId , true ); |
---|
| 205 | |
---|
| 206 | if( (m_iMaxTemporalLayer >= 0 && nalu.m_temporalId > m_iMaxTemporalLayer) || !isNaluWithinTargetDecLayerIdSet(&nalu) ) |
---|
| 207 | { |
---|
| 208 | bNewPicture = false; |
---|
| 209 | } |
---|
| 210 | else |
---|
| 211 | { |
---|
| 212 | newSliceDiffLayer = nalu.isSlice() && ( nalu.m_layerId != layerIdCurrPic ) && !firstSlice; |
---|
| 213 | newSliceDiffPoc = m_tDecTop[decIdx]->decode(nalu, m_iSkipFrame, m_pocLastDisplay[decIdx], newSliceDiffLayer ); |
---|
| 214 | // decode function only returns true when all of the following conditions are true |
---|
| 215 | // - poc in particular layer changes |
---|
| 216 | // - nalu does not belong to first slice in layer |
---|
| 217 | // - nalu.isSlice() == true |
---|
| 218 | |
---|
| 219 | bNewPicture = newSliceDiffLayer || newSliceDiffPoc; |
---|
| 220 | |
---|
| 221 | if ( nalu.isSlice() && firstSlice ) |
---|
| 222 | { |
---|
| 223 | layerIdCurrPic = nalu.m_layerId; |
---|
| 224 | pocCurrPic = m_tDecTop[decIdx]->getCurrPoc(); |
---|
| 225 | decIdxCurrPic = decIdx; |
---|
| 226 | firstSlice = false; |
---|
| 227 | } |
---|
| 228 | |
---|
| 229 | if ( bNewPicture || !bitstreamFile ) |
---|
| 230 | { |
---|
| 231 | layerIdCurrPic = nalu.m_layerId; |
---|
| 232 | |
---|
| 233 | pocLastPic = pocCurrPic; |
---|
| 234 | pocCurrPic = m_tDecTop[decIdx]->getCurrPoc(); |
---|
| 235 | |
---|
| 236 | decIdxLastPic = decIdxCurrPic; |
---|
| 237 | decIdxCurrPic = decIdx; |
---|
| 238 | |
---|
| 239 | allLayersDecoded = ( pocCurrPic != pocLastPic ); |
---|
| 240 | } |
---|
| 241 | |
---|
| 242 | |
---|
| 243 | #else |
---|
[324] | 244 | if( (m_iMaxTemporalLayer >= 0 && nalu.m_temporalId > m_iMaxTemporalLayer) || !isNaluWithinTargetDecLayerIdSet(&nalu) ) |
---|
| 245 | { |
---|
| 246 | if(bPreviousPictureDecoded) |
---|
| 247 | { |
---|
| 248 | bNewPicture = true; |
---|
| 249 | bPreviousPictureDecoded = false; |
---|
| 250 | } |
---|
| 251 | else |
---|
| 252 | { |
---|
| 253 | bNewPicture = false; |
---|
| 254 | } |
---|
| 255 | } |
---|
| 256 | else |
---|
| 257 | { |
---|
| 258 | bNewPicture = m_cTDecTop.decode(nalu, m_iSkipFrame, m_iPOCLastDisplay); |
---|
[368] | 259 | #endif |
---|
[324] | 260 | if (bNewPicture) |
---|
| 261 | { |
---|
| 262 | bitstreamFile.clear(); |
---|
| 263 | /* location points to the current nalunit payload[1] due to the |
---|
| 264 | * need for the annexB parser to read three extra bytes. |
---|
| 265 | * [1] except for the first NAL unit in the file |
---|
| 266 | * (but bNewPicture doesn't happen then) */ |
---|
| 267 | bitstreamFile.seekg(location-streamoff(3)); |
---|
| 268 | bytestream.reset(); |
---|
[446] | 269 | #if H_MV |
---|
| 270 | #if ENC_DEC_TRACE |
---|
| 271 | g_nSymbolCounter = symCount; |
---|
| 272 | #endif |
---|
| 273 | #endif |
---|
[324] | 274 | } |
---|
[368] | 275 | #if !H_MV |
---|
[324] | 276 | bPreviousPictureDecoded = true; |
---|
[368] | 277 | #endif |
---|
[324] | 278 | } |
---|
| 279 | } |
---|
| 280 | if (bNewPicture || !bitstreamFile) |
---|
| 281 | { |
---|
[368] | 282 | #if H_MV |
---|
| 283 | assert( decIdxLastPic != -1 ); |
---|
| 284 | m_tDecTop[decIdxLastPic]->endPicDecoding(poc, pcListPic, m_targetDecLayerIdSet ); |
---|
| 285 | #else |
---|
[324] | 286 | m_cTDecTop.executeLoopFilters(poc, pcListPic); |
---|
[368] | 287 | #endif |
---|
[324] | 288 | } |
---|
[368] | 289 | #if H_3D |
---|
| 290 | if ( allLayersDecoded || !bitstreamFile ) |
---|
| 291 | { |
---|
| 292 | for( Int dI = 0; dI < m_numDecoders; dI++ ) |
---|
| 293 | { |
---|
| 294 | TComPic* picLastCoded = m_ivPicLists.getPic( m_tDecTop[dI]->getLayerId(), pocLastPic ); |
---|
| 295 | assert( picLastCoded != NULL ); |
---|
| 296 | picLastCoded->compressMotion(); |
---|
| 297 | } |
---|
| 298 | } |
---|
| 299 | #endif |
---|
[446] | 300 | |
---|
[324] | 301 | if( pcListPic ) |
---|
| 302 | { |
---|
[368] | 303 | #if H_MV |
---|
| 304 | if ( m_pchReconFiles[decIdxLastPic] && !m_reconOpen[decIdxLastPic] ) |
---|
| 305 | #else |
---|
[324] | 306 | if ( m_pchReconFile && !recon_opened ) |
---|
[368] | 307 | #endif |
---|
[324] | 308 | { |
---|
| 309 | if (!m_outputBitDepthY) { m_outputBitDepthY = g_bitDepthY; } |
---|
| 310 | if (!m_outputBitDepthC) { m_outputBitDepthC = g_bitDepthC; } |
---|
[446] | 311 | |
---|
[368] | 312 | #if H_MV |
---|
| 313 | m_tVideoIOYuvReconFile[decIdxLastPic]->open( m_pchReconFiles[decIdxLastPic], true, m_outputBitDepthY, m_outputBitDepthC, g_bitDepthY, g_bitDepthC ); // write mode |
---|
| 314 | m_reconOpen[decIdxLastPic] = true; |
---|
| 315 | } |
---|
| 316 | if ( bNewPicture && newSliceDiffPoc && |
---|
| 317 | #else |
---|
[324] | 318 | m_cTVideoIOYuvReconFile.open( m_pchReconFile, true, m_outputBitDepthY, m_outputBitDepthC, g_bitDepthY, g_bitDepthC ); // write mode |
---|
| 319 | recon_opened = true; |
---|
| 320 | } |
---|
| 321 | if ( bNewPicture && |
---|
[368] | 322 | #endif |
---|
[446] | 323 | ( nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_IDR_W_RADL |
---|
[324] | 324 | || nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_IDR_N_LP |
---|
| 325 | || nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_BLA_N_LP |
---|
[446] | 326 | || nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_BLA_W_RADL |
---|
| 327 | || nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_BLA_W_LP ) ) |
---|
[324] | 328 | { |
---|
[368] | 329 | #if H_MV |
---|
| 330 | xFlushOutput( pcListPic, decIdxLastPic ); |
---|
| 331 | #else |
---|
[324] | 332 | xFlushOutput( pcListPic ); |
---|
[368] | 333 | #endif |
---|
[324] | 334 | } |
---|
| 335 | // write reconstruction to file |
---|
| 336 | if(bNewPicture) |
---|
| 337 | { |
---|
[368] | 338 | #if H_MV |
---|
| 339 | xWriteOutput( pcListPic, decIdxLastPic, nalu.m_temporalId ); |
---|
| 340 | } |
---|
| 341 | } |
---|
| 342 | } |
---|
| 343 | |
---|
[446] | 344 | #if H_3D |
---|
| 345 | if( m_cCamParsCollector.isInitialized() ) |
---|
| 346 | { |
---|
| 347 | m_cCamParsCollector.setSlice( 0 ); |
---|
| 348 | } |
---|
| 349 | #endif |
---|
[368] | 350 | for(UInt decIdx = 0; decIdx < m_numDecoders; decIdx++) |
---|
| 351 | { |
---|
| 352 | xFlushOutput( m_tDecTop[decIdx]->getListPic(), decIdx ); |
---|
| 353 | } |
---|
| 354 | #else |
---|
[324] | 355 | xWriteOutput( pcListPic, nalu.m_temporalId ); |
---|
| 356 | } |
---|
| 357 | } |
---|
| 358 | } |
---|
| 359 | |
---|
| 360 | xFlushOutput( pcListPic ); |
---|
| 361 | // delete buffers |
---|
| 362 | m_cTDecTop.deletePicBuffer(); |
---|
[368] | 363 | #endif |
---|
[324] | 364 | |
---|
| 365 | // destroy internal classes |
---|
| 366 | xDestroyDecLib(); |
---|
| 367 | } |
---|
| 368 | |
---|
| 369 | // ==================================================================================================================== |
---|
| 370 | // Protected member functions |
---|
| 371 | // ==================================================================================================================== |
---|
| 372 | |
---|
| 373 | Void TAppDecTop::xCreateDecLib() |
---|
| 374 | { |
---|
[368] | 375 | #if H_MV |
---|
| 376 | // initialize global variables |
---|
| 377 | initROM(); |
---|
[459] | 378 | #if H_3D_DIM_DMM |
---|
| 379 | initWedgeLists(); |
---|
| 380 | #endif |
---|
[368] | 381 | #else |
---|
[324] | 382 | // create decoder class |
---|
| 383 | m_cTDecTop.create(); |
---|
[368] | 384 | #endif |
---|
[324] | 385 | } |
---|
| 386 | |
---|
| 387 | Void TAppDecTop::xDestroyDecLib() |
---|
| 388 | { |
---|
[368] | 389 | #if H_MV |
---|
| 390 | // destroy ROM |
---|
| 391 | destroyROM(); |
---|
| 392 | |
---|
| 393 | for(Int decIdx = 0; decIdx < m_numDecoders ; decIdx++) |
---|
| 394 | { |
---|
| 395 | if( m_tVideoIOYuvReconFile[decIdx] ) |
---|
| 396 | { |
---|
| 397 | m_tVideoIOYuvReconFile[decIdx]->close(); |
---|
| 398 | delete m_tVideoIOYuvReconFile[decIdx]; |
---|
| 399 | m_tVideoIOYuvReconFile[decIdx] = NULL ; |
---|
| 400 | } |
---|
| 401 | |
---|
| 402 | if( m_tDecTop[decIdx] ) |
---|
| 403 | { |
---|
| 404 | m_tDecTop[decIdx]->deletePicBuffer(); |
---|
| 405 | m_tDecTop[decIdx]->destroy() ; |
---|
| 406 | } |
---|
| 407 | delete m_tDecTop[decIdx] ; |
---|
| 408 | m_tDecTop[decIdx] = NULL ; |
---|
| 409 | } |
---|
| 410 | #else |
---|
[324] | 411 | if ( m_pchReconFile ) |
---|
| 412 | { |
---|
| 413 | m_cTVideoIOYuvReconFile. close(); |
---|
| 414 | } |
---|
| 415 | |
---|
| 416 | // destroy decoder class |
---|
| 417 | m_cTDecTop.destroy(); |
---|
[368] | 418 | #endif |
---|
[446] | 419 | #if H_3D |
---|
| 420 | m_cCamParsCollector.uninit(); |
---|
| 421 | if( m_pScaleOffsetFile ) |
---|
| 422 | { |
---|
| 423 | ::fclose( m_pScaleOffsetFile ); |
---|
| 424 | } |
---|
| 425 | #endif |
---|
[324] | 426 | } |
---|
| 427 | |
---|
| 428 | Void TAppDecTop::xInitDecLib() |
---|
| 429 | { |
---|
[368] | 430 | #if !H_MV |
---|
[324] | 431 | // initialize decoder class |
---|
| 432 | m_cTDecTop.init(); |
---|
| 433 | m_cTDecTop.setDecodedPictureHashSEIEnabled(m_decodedPictureHashSEIEnabled); |
---|
[368] | 434 | #endif |
---|
[324] | 435 | } |
---|
| 436 | |
---|
| 437 | /** \param pcListPic list of pictures to be written to file |
---|
| 438 | \todo DYN_REF_FREE should be revised |
---|
| 439 | */ |
---|
[368] | 440 | #if H_MV |
---|
| 441 | Void TAppDecTop::xWriteOutput( TComList<TComPic*>* pcListPic, Int decIdx, Int tId ) |
---|
| 442 | #else |
---|
[324] | 443 | Void TAppDecTop::xWriteOutput( TComList<TComPic*>* pcListPic, UInt tId ) |
---|
[368] | 444 | #endif |
---|
[324] | 445 | { |
---|
| 446 | TComList<TComPic*>::iterator iterPic = pcListPic->begin(); |
---|
| 447 | Int not_displayed = 0; |
---|
| 448 | |
---|
| 449 | while (iterPic != pcListPic->end()) |
---|
| 450 | { |
---|
| 451 | TComPic* pcPic = *(iterPic); |
---|
[368] | 452 | #if H_MV |
---|
| 453 | if(pcPic->getOutputMark() && pcPic->getPOC() > m_pocLastDisplay[decIdx]) |
---|
| 454 | #else |
---|
[324] | 455 | if(pcPic->getOutputMark() && pcPic->getPOC() > m_iPOCLastDisplay) |
---|
[368] | 456 | #endif |
---|
[324] | 457 | { |
---|
| 458 | not_displayed++; |
---|
| 459 | } |
---|
| 460 | iterPic++; |
---|
| 461 | } |
---|
| 462 | iterPic = pcListPic->begin(); |
---|
| 463 | |
---|
| 464 | while (iterPic != pcListPic->end()) |
---|
| 465 | { |
---|
| 466 | TComPic* pcPic = *(iterPic); |
---|
| 467 | |
---|
[368] | 468 | #if H_MV |
---|
| 469 | if ( pcPic->getOutputMark() && (not_displayed > pcPic->getNumReorderPics(tId) && pcPic->getPOC() > m_pocLastDisplay[decIdx])) |
---|
| 470 | #else |
---|
[324] | 471 | if ( pcPic->getOutputMark() && (not_displayed > pcPic->getNumReorderPics(tId) && pcPic->getPOC() > m_iPOCLastDisplay)) |
---|
[368] | 472 | #endif |
---|
[324] | 473 | { |
---|
| 474 | // write to file |
---|
| 475 | not_displayed--; |
---|
[368] | 476 | #if H_MV |
---|
| 477 | if ( m_pchReconFiles[decIdx] ) |
---|
| 478 | #else |
---|
[324] | 479 | if ( m_pchReconFile ) |
---|
[368] | 480 | #endif |
---|
[324] | 481 | { |
---|
| 482 | const Window &conf = pcPic->getConformanceWindow(); |
---|
| 483 | const Window &defDisp = m_respectDefDispWindow ? pcPic->getDefDisplayWindow() : Window(); |
---|
[368] | 484 | #if H_MV |
---|
| 485 | m_tVideoIOYuvReconFile[decIdx]->write( pcPic->getPicYuvRec(), |
---|
| 486 | #else |
---|
[324] | 487 | m_cTVideoIOYuvReconFile.write( pcPic->getPicYuvRec(), |
---|
[368] | 488 | #endif |
---|
[324] | 489 | conf.getWindowLeftOffset() + defDisp.getWindowLeftOffset(), |
---|
| 490 | conf.getWindowRightOffset() + defDisp.getWindowRightOffset(), |
---|
| 491 | conf.getWindowTopOffset() + defDisp.getWindowTopOffset(), |
---|
| 492 | conf.getWindowBottomOffset() + defDisp.getWindowBottomOffset() ); |
---|
| 493 | } |
---|
| 494 | |
---|
| 495 | // update POC of display order |
---|
[368] | 496 | #if H_MV |
---|
| 497 | m_pocLastDisplay[decIdx] = pcPic->getPOC(); |
---|
| 498 | #else |
---|
[324] | 499 | m_iPOCLastDisplay = pcPic->getPOC(); |
---|
[368] | 500 | #endif |
---|
[324] | 501 | |
---|
| 502 | // erase non-referenced picture in the reference picture list after display |
---|
| 503 | if ( !pcPic->getSlice(0)->isReferenced() && pcPic->getReconMark() == true ) |
---|
| 504 | { |
---|
| 505 | #if !DYN_REF_FREE |
---|
| 506 | pcPic->setReconMark(false); |
---|
| 507 | |
---|
| 508 | // mark it should be extended later |
---|
| 509 | pcPic->getPicYuvRec()->setBorderExtension( false ); |
---|
| 510 | |
---|
| 511 | #else |
---|
| 512 | pcPic->destroy(); |
---|
| 513 | pcListPic->erase( iterPic ); |
---|
| 514 | iterPic = pcListPic->begin(); // to the beginning, non-efficient way, have to be revised! |
---|
| 515 | continue; |
---|
| 516 | #endif |
---|
| 517 | } |
---|
| 518 | pcPic->setOutputMark(false); |
---|
| 519 | } |
---|
| 520 | |
---|
| 521 | iterPic++; |
---|
| 522 | } |
---|
| 523 | } |
---|
| 524 | |
---|
| 525 | /** \param pcListPic list of pictures to be written to file |
---|
| 526 | \todo DYN_REF_FREE should be revised |
---|
| 527 | */ |
---|
[368] | 528 | #if H_MV |
---|
| 529 | Void TAppDecTop::xFlushOutput( TComList<TComPic*>* pcListPic, Int decIdx ) |
---|
| 530 | #else |
---|
[324] | 531 | Void TAppDecTop::xFlushOutput( TComList<TComPic*>* pcListPic ) |
---|
[368] | 532 | #endif |
---|
[324] | 533 | { |
---|
| 534 | if(!pcListPic) |
---|
| 535 | { |
---|
| 536 | return; |
---|
| 537 | } |
---|
| 538 | TComList<TComPic*>::iterator iterPic = pcListPic->begin(); |
---|
| 539 | |
---|
| 540 | iterPic = pcListPic->begin(); |
---|
| 541 | |
---|
| 542 | while (iterPic != pcListPic->end()) |
---|
| 543 | { |
---|
| 544 | TComPic* pcPic = *(iterPic); |
---|
| 545 | |
---|
| 546 | if ( pcPic->getOutputMark() ) |
---|
| 547 | { |
---|
| 548 | // write to file |
---|
[368] | 549 | #if H_MV |
---|
| 550 | if ( m_pchReconFiles[decIdx] ) |
---|
| 551 | #else |
---|
[324] | 552 | if ( m_pchReconFile ) |
---|
[368] | 553 | #endif |
---|
[324] | 554 | { |
---|
| 555 | const Window &conf = pcPic->getConformanceWindow(); |
---|
| 556 | const Window &defDisp = m_respectDefDispWindow ? pcPic->getDefDisplayWindow() : Window(); |
---|
[368] | 557 | #if H_MV |
---|
| 558 | m_tVideoIOYuvReconFile[decIdx]->write( pcPic->getPicYuvRec(), |
---|
| 559 | #else |
---|
[324] | 560 | m_cTVideoIOYuvReconFile.write( pcPic->getPicYuvRec(), |
---|
[368] | 561 | #endif |
---|
[324] | 562 | conf.getWindowLeftOffset() + defDisp.getWindowLeftOffset(), |
---|
| 563 | conf.getWindowRightOffset() + defDisp.getWindowRightOffset(), |
---|
| 564 | conf.getWindowTopOffset() + defDisp.getWindowTopOffset(), |
---|
| 565 | conf.getWindowBottomOffset() + defDisp.getWindowBottomOffset() ); |
---|
| 566 | } |
---|
| 567 | |
---|
| 568 | // update POC of display order |
---|
[368] | 569 | #if H_MV |
---|
| 570 | m_pocLastDisplay[decIdx] = pcPic->getPOC(); |
---|
| 571 | #else |
---|
[324] | 572 | m_iPOCLastDisplay = pcPic->getPOC(); |
---|
[368] | 573 | #endif |
---|
[324] | 574 | |
---|
| 575 | // erase non-referenced picture in the reference picture list after display |
---|
| 576 | if ( !pcPic->getSlice(0)->isReferenced() && pcPic->getReconMark() == true ) |
---|
| 577 | { |
---|
| 578 | #if !DYN_REF_FREE |
---|
| 579 | pcPic->setReconMark(false); |
---|
| 580 | |
---|
| 581 | // mark it should be extended later |
---|
| 582 | pcPic->getPicYuvRec()->setBorderExtension( false ); |
---|
| 583 | |
---|
| 584 | #else |
---|
| 585 | pcPic->destroy(); |
---|
| 586 | pcListPic->erase( iterPic ); |
---|
| 587 | iterPic = pcListPic->begin(); // to the beginning, non-efficient way, have to be revised! |
---|
| 588 | continue; |
---|
| 589 | #endif |
---|
| 590 | } |
---|
| 591 | pcPic->setOutputMark(false); |
---|
| 592 | } |
---|
[368] | 593 | #if !H_MV |
---|
[324] | 594 | #if !DYN_REF_FREE |
---|
| 595 | if(pcPic) |
---|
| 596 | { |
---|
| 597 | pcPic->destroy(); |
---|
| 598 | delete pcPic; |
---|
| 599 | pcPic = NULL; |
---|
| 600 | } |
---|
| 601 | #endif |
---|
[368] | 602 | #endif |
---|
[324] | 603 | iterPic++; |
---|
| 604 | } |
---|
[368] | 605 | #if H_MV |
---|
| 606 | m_pocLastDisplay[decIdx] = -MAX_INT; |
---|
| 607 | #else |
---|
[324] | 608 | pcListPic->clear(); |
---|
| 609 | m_iPOCLastDisplay = -MAX_INT; |
---|
[368] | 610 | #endif |
---|
[324] | 611 | } |
---|
| 612 | |
---|
| 613 | /** \param nalu Input nalu to check whether its LayerId is within targetDecLayerIdSet |
---|
| 614 | */ |
---|
| 615 | Bool TAppDecTop::isNaluWithinTargetDecLayerIdSet( InputNALUnit* nalu ) |
---|
| 616 | { |
---|
| 617 | if ( m_targetDecLayerIdSet.size() == 0 ) // By default, the set is empty, meaning all LayerIds are allowed |
---|
| 618 | { |
---|
| 619 | return true; |
---|
| 620 | } |
---|
| 621 | for (std::vector<Int>::iterator it = m_targetDecLayerIdSet.begin(); it != m_targetDecLayerIdSet.end(); it++) |
---|
| 622 | { |
---|
[368] | 623 | #if H_MV |
---|
| 624 | if ( nalu->m_layerId == (*it) ) |
---|
| 625 | #else |
---|
[324] | 626 | if ( nalu->m_reservedZero6Bits == (*it) ) |
---|
[368] | 627 | #endif |
---|
[324] | 628 | { |
---|
| 629 | return true; |
---|
| 630 | } |
---|
| 631 | } |
---|
| 632 | return false; |
---|
| 633 | } |
---|
| 634 | |
---|
[446] | 635 | #if H_MV |
---|
| 636 | Int TAppDecTop::xGetDecoderIdx( Int layerId, Bool createFlag /*= false */ ) |
---|
| 637 | { |
---|
| 638 | Int decIdx = -1; |
---|
| 639 | if ( m_layerIdToDecIdx[ layerId ] != -1 ) |
---|
| 640 | { |
---|
| 641 | decIdx = m_layerIdToDecIdx[ layerId ]; |
---|
| 642 | } |
---|
| 643 | else |
---|
| 644 | { |
---|
| 645 | assert ( createFlag ); |
---|
| 646 | assert( m_numDecoders < MAX_NUM_LAYERS ); |
---|
| 647 | |
---|
| 648 | decIdx = m_numDecoders; |
---|
| 649 | |
---|
| 650 | // Init decoder |
---|
| 651 | m_tDecTop[ decIdx ] = new TDecTop; |
---|
| 652 | m_tDecTop[ decIdx ]->create(); |
---|
| 653 | m_tDecTop[ decIdx ]->init( ); |
---|
| 654 | m_tDecTop[ decIdx ]->setLayerId( layerId ); |
---|
| 655 | m_tDecTop[ decIdx ]->setDecodedPictureHashSEIEnabled(m_decodedPictureHashSEIEnabled); |
---|
| 656 | m_tDecTop[ decIdx ]->setIvPicLists( &m_ivPicLists ); |
---|
| 657 | #if H_3D |
---|
| 658 | m_tDecTop[ decIdx ]->setCamParsCollector( &m_cCamParsCollector ); |
---|
| 659 | #endif |
---|
| 660 | |
---|
| 661 | // append pic list of new decoder to PicLists |
---|
| 662 | assert( m_ivPicLists.size() == m_numDecoders ); |
---|
| 663 | m_ivPicLists.push_back( m_tDecTop[ decIdx ]->getListPic() ); |
---|
| 664 | |
---|
| 665 | // create recon file related stuff |
---|
| 666 | Char* pchTempFilename = NULL; |
---|
| 667 | if ( m_pchReconFile ) |
---|
| 668 | { |
---|
| 669 | Char buffer[4]; |
---|
| 670 | sprintf(buffer,"_%i", layerId ); |
---|
| 671 | assert ( m_pchReconFile ); |
---|
| 672 | xAppendToFileNameEnd( m_pchReconFile , buffer, pchTempFilename ); |
---|
| 673 | assert( m_pchReconFiles.size() == m_numDecoders ); |
---|
| 674 | } |
---|
| 675 | |
---|
| 676 | m_pchReconFiles.push_back( pchTempFilename ); |
---|
| 677 | |
---|
| 678 | m_tVideoIOYuvReconFile[ decIdx ] = new TVideoIOYuv; |
---|
| 679 | m_reconOpen [ decIdx ] = false; |
---|
| 680 | |
---|
| 681 | // set others |
---|
| 682 | m_pocLastDisplay [ decIdx ] = -MAX_INT; |
---|
| 683 | m_layerIdToDecIdx [ layerId ] = decIdx; |
---|
| 684 | |
---|
| 685 | m_numDecoders++; |
---|
| 686 | }; |
---|
| 687 | return decIdx; |
---|
| 688 | } |
---|
| 689 | #endif |
---|
[324] | 690 | //! \} |
---|