[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 | } |
---|
| 97 | } |
---|
| 98 | |
---|
| 99 | // ==================================================================================================================== |
---|
| 100 | // Public member functions |
---|
| 101 | // ==================================================================================================================== |
---|
| 102 | |
---|
| 103 | /** |
---|
| 104 | - create internal class |
---|
| 105 | - initialize internal class |
---|
| 106 | - until the end of the bitstream, call decoding function in TDecTop class |
---|
| 107 | - delete allocated buffers |
---|
| 108 | - destroy internal class |
---|
| 109 | . |
---|
| 110 | */ |
---|
| 111 | Void TAppDecTop::decode() |
---|
| 112 | { |
---|
| 113 | Int poc; |
---|
[368] | 114 | #if H_MV |
---|
| 115 | poc = -1; |
---|
| 116 | #endif |
---|
[324] | 117 | TComList<TComPic*>* pcListPic = NULL; |
---|
| 118 | |
---|
| 119 | ifstream bitstreamFile(m_pchBitstreamFile, ifstream::in | ifstream::binary); |
---|
| 120 | if (!bitstreamFile) |
---|
| 121 | { |
---|
| 122 | fprintf(stderr, "\nfailed to open bitstream file `%s' for reading\n", m_pchBitstreamFile); |
---|
| 123 | exit(EXIT_FAILURE); |
---|
| 124 | } |
---|
| 125 | |
---|
[446] | 126 | #if H_3D |
---|
| 127 | if( m_pchScaleOffsetFile ) |
---|
| 128 | { |
---|
| 129 | m_pScaleOffsetFile = ::fopen( m_pchScaleOffsetFile, "wt" ); |
---|
| 130 | AOF( m_pScaleOffsetFile ); |
---|
| 131 | } |
---|
| 132 | m_cCamParsCollector.init( m_pScaleOffsetFile ); |
---|
| 133 | #endif |
---|
[324] | 134 | InputByteStream bytestream(bitstreamFile); |
---|
| 135 | |
---|
| 136 | // create & initialize internal classes |
---|
| 137 | xCreateDecLib(); |
---|
| 138 | xInitDecLib (); |
---|
[368] | 139 | #if !H_MV |
---|
[324] | 140 | m_iPOCLastDisplay += m_iSkipFrame; // set the last displayed POC correctly for skip forward. |
---|
| 141 | |
---|
| 142 | // main decoder loop |
---|
| 143 | Bool recon_opened = false; // reconstruction file not yet opened. (must be performed after SPS is seen) |
---|
[368] | 144 | #else |
---|
| 145 | Int pocCurrPic = -MAX_INT; |
---|
| 146 | Int pocLastPic = -MAX_INT; |
---|
| 147 | |
---|
| 148 | Int layerIdLastPic = 0; |
---|
| 149 | Int layerIdCurrPic = 0; |
---|
| 150 | |
---|
| 151 | Int decIdxLastPic = 0; |
---|
| 152 | Int decIdxCurrPic = 0; |
---|
| 153 | |
---|
| 154 | Bool firstSlice = true; |
---|
| 155 | #endif |
---|
[324] | 156 | |
---|
| 157 | while (!!bitstreamFile) |
---|
| 158 | { |
---|
| 159 | /* location serves to work around a design fault in the decoder, whereby |
---|
| 160 | * the process of reading a new slice that is the first slice of a new frame |
---|
| 161 | * requires the TDecTop::decode() method to be called again with the same |
---|
| 162 | * nal unit. */ |
---|
| 163 | streampos location = bitstreamFile.tellg(); |
---|
[446] | 164 | #if H_MV |
---|
| 165 | #if ENC_DEC_TRACE |
---|
| 166 | Int64 symCount = g_nSymbolCounter; |
---|
| 167 | #endif |
---|
| 168 | #endif |
---|
[324] | 169 | AnnexBStats stats = AnnexBStats(); |
---|
[368] | 170 | #if !H_MV |
---|
[324] | 171 | Bool bPreviousPictureDecoded = false; |
---|
[368] | 172 | #endif |
---|
[446] | 173 | |
---|
[324] | 174 | vector<uint8_t> nalUnit; |
---|
| 175 | InputNALUnit nalu; |
---|
| 176 | byteStreamNALUnit(bytestream, nalUnit, stats); |
---|
| 177 | |
---|
| 178 | // call actual decoding function |
---|
| 179 | Bool bNewPicture = false; |
---|
[368] | 180 | #if H_MV |
---|
| 181 | Bool newSliceDiffPoc = false; |
---|
| 182 | Bool newSliceDiffLayer = false; |
---|
| 183 | Bool allLayersDecoded = false; |
---|
| 184 | #endif |
---|
[324] | 185 | if (nalUnit.empty()) |
---|
| 186 | { |
---|
| 187 | /* this can happen if the following occur: |
---|
| 188 | * - empty input file |
---|
| 189 | * - two back-to-back start_code_prefixes |
---|
| 190 | * - start_code_prefix immediately followed by EOF |
---|
| 191 | */ |
---|
| 192 | fprintf(stderr, "Warning: Attempt to decode an empty NAL unit\n"); |
---|
| 193 | } |
---|
| 194 | else |
---|
| 195 | { |
---|
| 196 | read(nalu, nalUnit); |
---|
[368] | 197 | #if H_MV |
---|
| 198 | Int decIdx = xGetDecoderIdx( nalu.m_layerId , true ); |
---|
| 199 | |
---|
| 200 | if( (m_iMaxTemporalLayer >= 0 && nalu.m_temporalId > m_iMaxTemporalLayer) || !isNaluWithinTargetDecLayerIdSet(&nalu) ) |
---|
| 201 | { |
---|
| 202 | bNewPicture = false; |
---|
| 203 | } |
---|
| 204 | else |
---|
| 205 | { |
---|
| 206 | newSliceDiffLayer = nalu.isSlice() && ( nalu.m_layerId != layerIdCurrPic ) && !firstSlice; |
---|
| 207 | newSliceDiffPoc = m_tDecTop[decIdx]->decode(nalu, m_iSkipFrame, m_pocLastDisplay[decIdx], newSliceDiffLayer ); |
---|
| 208 | // decode function only returns true when all of the following conditions are true |
---|
| 209 | // - poc in particular layer changes |
---|
| 210 | // - nalu does not belong to first slice in layer |
---|
| 211 | // - nalu.isSlice() == true |
---|
| 212 | |
---|
| 213 | bNewPicture = newSliceDiffLayer || newSliceDiffPoc; |
---|
| 214 | |
---|
| 215 | if ( nalu.isSlice() && firstSlice ) |
---|
| 216 | { |
---|
| 217 | layerIdCurrPic = nalu.m_layerId; |
---|
| 218 | pocCurrPic = m_tDecTop[decIdx]->getCurrPoc(); |
---|
| 219 | decIdxCurrPic = decIdx; |
---|
| 220 | firstSlice = false; |
---|
| 221 | } |
---|
| 222 | |
---|
| 223 | if ( bNewPicture || !bitstreamFile ) |
---|
| 224 | { |
---|
| 225 | layerIdLastPic = layerIdCurrPic; |
---|
| 226 | layerIdCurrPic = nalu.m_layerId; |
---|
| 227 | |
---|
| 228 | pocLastPic = pocCurrPic; |
---|
| 229 | pocCurrPic = m_tDecTop[decIdx]->getCurrPoc(); |
---|
| 230 | |
---|
| 231 | decIdxLastPic = decIdxCurrPic; |
---|
| 232 | decIdxCurrPic = decIdx; |
---|
| 233 | |
---|
| 234 | allLayersDecoded = ( pocCurrPic != pocLastPic ); |
---|
| 235 | } |
---|
| 236 | |
---|
| 237 | |
---|
| 238 | #else |
---|
[324] | 239 | if( (m_iMaxTemporalLayer >= 0 && nalu.m_temporalId > m_iMaxTemporalLayer) || !isNaluWithinTargetDecLayerIdSet(&nalu) ) |
---|
| 240 | { |
---|
| 241 | if(bPreviousPictureDecoded) |
---|
| 242 | { |
---|
| 243 | bNewPicture = true; |
---|
| 244 | bPreviousPictureDecoded = false; |
---|
| 245 | } |
---|
| 246 | else |
---|
| 247 | { |
---|
| 248 | bNewPicture = false; |
---|
| 249 | } |
---|
| 250 | } |
---|
| 251 | else |
---|
| 252 | { |
---|
| 253 | bNewPicture = m_cTDecTop.decode(nalu, m_iSkipFrame, m_iPOCLastDisplay); |
---|
[368] | 254 | #endif |
---|
[324] | 255 | if (bNewPicture) |
---|
| 256 | { |
---|
| 257 | bitstreamFile.clear(); |
---|
| 258 | /* location points to the current nalunit payload[1] due to the |
---|
| 259 | * need for the annexB parser to read three extra bytes. |
---|
| 260 | * [1] except for the first NAL unit in the file |
---|
| 261 | * (but bNewPicture doesn't happen then) */ |
---|
| 262 | bitstreamFile.seekg(location-streamoff(3)); |
---|
| 263 | bytestream.reset(); |
---|
[446] | 264 | #if H_MV |
---|
| 265 | #if ENC_DEC_TRACE |
---|
| 266 | g_nSymbolCounter = symCount; |
---|
| 267 | #endif |
---|
| 268 | #endif |
---|
[324] | 269 | } |
---|
[368] | 270 | #if !H_MV |
---|
[324] | 271 | bPreviousPictureDecoded = true; |
---|
[368] | 272 | #endif |
---|
[324] | 273 | } |
---|
| 274 | } |
---|
| 275 | if (bNewPicture || !bitstreamFile) |
---|
| 276 | { |
---|
[368] | 277 | #if H_MV |
---|
| 278 | assert( decIdxLastPic != -1 ); |
---|
| 279 | m_tDecTop[decIdxLastPic]->endPicDecoding(poc, pcListPic, m_targetDecLayerIdSet ); |
---|
| 280 | #else |
---|
[324] | 281 | m_cTDecTop.executeLoopFilters(poc, pcListPic); |
---|
[368] | 282 | #endif |
---|
[324] | 283 | } |
---|
[368] | 284 | #if H_3D |
---|
| 285 | if ( allLayersDecoded || !bitstreamFile ) |
---|
| 286 | { |
---|
| 287 | for( Int dI = 0; dI < m_numDecoders; dI++ ) |
---|
| 288 | { |
---|
| 289 | TComPic* picLastCoded = m_ivPicLists.getPic( m_tDecTop[dI]->getLayerId(), pocLastPic ); |
---|
| 290 | assert( picLastCoded != NULL ); |
---|
| 291 | picLastCoded->compressMotion(); |
---|
| 292 | } |
---|
| 293 | } |
---|
| 294 | #endif |
---|
[446] | 295 | |
---|
[324] | 296 | if( pcListPic ) |
---|
| 297 | { |
---|
[368] | 298 | #if H_MV |
---|
| 299 | if ( m_pchReconFiles[decIdxLastPic] && !m_reconOpen[decIdxLastPic] ) |
---|
| 300 | #else |
---|
[324] | 301 | if ( m_pchReconFile && !recon_opened ) |
---|
[368] | 302 | #endif |
---|
[324] | 303 | { |
---|
| 304 | if (!m_outputBitDepthY) { m_outputBitDepthY = g_bitDepthY; } |
---|
| 305 | if (!m_outputBitDepthC) { m_outputBitDepthC = g_bitDepthC; } |
---|
[446] | 306 | |
---|
[368] | 307 | #if H_MV |
---|
| 308 | m_tVideoIOYuvReconFile[decIdxLastPic]->open( m_pchReconFiles[decIdxLastPic], true, m_outputBitDepthY, m_outputBitDepthC, g_bitDepthY, g_bitDepthC ); // write mode |
---|
| 309 | m_reconOpen[decIdxLastPic] = true; |
---|
| 310 | } |
---|
| 311 | if ( bNewPicture && newSliceDiffPoc && |
---|
| 312 | #else |
---|
[324] | 313 | m_cTVideoIOYuvReconFile.open( m_pchReconFile, true, m_outputBitDepthY, m_outputBitDepthC, g_bitDepthY, g_bitDepthC ); // write mode |
---|
| 314 | recon_opened = true; |
---|
| 315 | } |
---|
| 316 | if ( bNewPicture && |
---|
[368] | 317 | #endif |
---|
[446] | 318 | ( nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_IDR_W_RADL |
---|
[324] | 319 | || nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_IDR_N_LP |
---|
| 320 | || nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_BLA_N_LP |
---|
[446] | 321 | || nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_BLA_W_RADL |
---|
| 322 | || nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_BLA_W_LP ) ) |
---|
[324] | 323 | { |
---|
[368] | 324 | #if H_MV |
---|
| 325 | xFlushOutput( pcListPic, decIdxLastPic ); |
---|
| 326 | #else |
---|
[324] | 327 | xFlushOutput( pcListPic ); |
---|
[368] | 328 | #endif |
---|
[324] | 329 | } |
---|
| 330 | // write reconstruction to file |
---|
| 331 | if(bNewPicture) |
---|
| 332 | { |
---|
[368] | 333 | #if H_MV |
---|
| 334 | xWriteOutput( pcListPic, decIdxLastPic, nalu.m_temporalId ); |
---|
| 335 | } |
---|
| 336 | } |
---|
| 337 | } |
---|
| 338 | |
---|
[446] | 339 | #if H_3D |
---|
| 340 | if( m_cCamParsCollector.isInitialized() ) |
---|
| 341 | { |
---|
| 342 | m_cCamParsCollector.setSlice( 0 ); |
---|
| 343 | } |
---|
| 344 | #endif |
---|
[368] | 345 | for(UInt decIdx = 0; decIdx < m_numDecoders; decIdx++) |
---|
| 346 | { |
---|
| 347 | xFlushOutput( m_tDecTop[decIdx]->getListPic(), decIdx ); |
---|
| 348 | } |
---|
| 349 | #else |
---|
[324] | 350 | xWriteOutput( pcListPic, nalu.m_temporalId ); |
---|
| 351 | } |
---|
| 352 | } |
---|
| 353 | } |
---|
| 354 | |
---|
| 355 | xFlushOutput( pcListPic ); |
---|
| 356 | // delete buffers |
---|
| 357 | m_cTDecTop.deletePicBuffer(); |
---|
[368] | 358 | #endif |
---|
[324] | 359 | |
---|
| 360 | // destroy internal classes |
---|
| 361 | xDestroyDecLib(); |
---|
| 362 | } |
---|
| 363 | |
---|
| 364 | // ==================================================================================================================== |
---|
| 365 | // Protected member functions |
---|
| 366 | // ==================================================================================================================== |
---|
| 367 | |
---|
| 368 | Void TAppDecTop::xCreateDecLib() |
---|
| 369 | { |
---|
[368] | 370 | #if H_MV |
---|
| 371 | // initialize global variables |
---|
| 372 | initROM(); |
---|
| 373 | #else |
---|
[324] | 374 | // create decoder class |
---|
| 375 | m_cTDecTop.create(); |
---|
[368] | 376 | #endif |
---|
[324] | 377 | } |
---|
| 378 | |
---|
| 379 | Void TAppDecTop::xDestroyDecLib() |
---|
| 380 | { |
---|
[368] | 381 | #if H_MV |
---|
| 382 | // destroy ROM |
---|
| 383 | destroyROM(); |
---|
| 384 | |
---|
| 385 | for(Int decIdx = 0; decIdx < m_numDecoders ; decIdx++) |
---|
| 386 | { |
---|
| 387 | if( m_tVideoIOYuvReconFile[decIdx] ) |
---|
| 388 | { |
---|
| 389 | m_tVideoIOYuvReconFile[decIdx]->close(); |
---|
| 390 | delete m_tVideoIOYuvReconFile[decIdx]; |
---|
| 391 | m_tVideoIOYuvReconFile[decIdx] = NULL ; |
---|
| 392 | } |
---|
| 393 | |
---|
| 394 | if( m_tDecTop[decIdx] ) |
---|
| 395 | { |
---|
| 396 | m_tDecTop[decIdx]->deletePicBuffer(); |
---|
| 397 | m_tDecTop[decIdx]->destroy() ; |
---|
| 398 | } |
---|
| 399 | delete m_tDecTop[decIdx] ; |
---|
| 400 | m_tDecTop[decIdx] = NULL ; |
---|
| 401 | } |
---|
| 402 | #else |
---|
[324] | 403 | if ( m_pchReconFile ) |
---|
| 404 | { |
---|
| 405 | m_cTVideoIOYuvReconFile. close(); |
---|
| 406 | } |
---|
| 407 | |
---|
| 408 | // destroy decoder class |
---|
| 409 | m_cTDecTop.destroy(); |
---|
[368] | 410 | #endif |
---|
[446] | 411 | #if H_3D |
---|
| 412 | m_cCamParsCollector.uninit(); |
---|
| 413 | if( m_pScaleOffsetFile ) |
---|
| 414 | { |
---|
| 415 | ::fclose( m_pScaleOffsetFile ); |
---|
| 416 | } |
---|
| 417 | #endif |
---|
[324] | 418 | } |
---|
| 419 | |
---|
| 420 | Void TAppDecTop::xInitDecLib() |
---|
| 421 | { |
---|
[368] | 422 | #if !H_MV |
---|
[324] | 423 | // initialize decoder class |
---|
| 424 | m_cTDecTop.init(); |
---|
| 425 | m_cTDecTop.setDecodedPictureHashSEIEnabled(m_decodedPictureHashSEIEnabled); |
---|
[368] | 426 | #endif |
---|
[324] | 427 | } |
---|
| 428 | |
---|
| 429 | /** \param pcListPic list of pictures to be written to file |
---|
| 430 | \todo DYN_REF_FREE should be revised |
---|
| 431 | */ |
---|
[368] | 432 | #if H_MV |
---|
| 433 | Void TAppDecTop::xWriteOutput( TComList<TComPic*>* pcListPic, Int decIdx, Int tId ) |
---|
| 434 | #else |
---|
[324] | 435 | Void TAppDecTop::xWriteOutput( TComList<TComPic*>* pcListPic, UInt tId ) |
---|
[368] | 436 | #endif |
---|
[324] | 437 | { |
---|
| 438 | TComList<TComPic*>::iterator iterPic = pcListPic->begin(); |
---|
| 439 | Int not_displayed = 0; |
---|
| 440 | |
---|
| 441 | while (iterPic != pcListPic->end()) |
---|
| 442 | { |
---|
| 443 | TComPic* pcPic = *(iterPic); |
---|
[368] | 444 | #if H_MV |
---|
| 445 | if(pcPic->getOutputMark() && pcPic->getPOC() > m_pocLastDisplay[decIdx]) |
---|
| 446 | #else |
---|
[324] | 447 | if(pcPic->getOutputMark() && pcPic->getPOC() > m_iPOCLastDisplay) |
---|
[368] | 448 | #endif |
---|
[324] | 449 | { |
---|
| 450 | not_displayed++; |
---|
| 451 | } |
---|
| 452 | iterPic++; |
---|
| 453 | } |
---|
| 454 | iterPic = pcListPic->begin(); |
---|
| 455 | |
---|
| 456 | while (iterPic != pcListPic->end()) |
---|
| 457 | { |
---|
| 458 | TComPic* pcPic = *(iterPic); |
---|
| 459 | |
---|
[368] | 460 | #if H_MV |
---|
| 461 | if ( pcPic->getOutputMark() && (not_displayed > pcPic->getNumReorderPics(tId) && pcPic->getPOC() > m_pocLastDisplay[decIdx])) |
---|
| 462 | #else |
---|
[324] | 463 | if ( pcPic->getOutputMark() && (not_displayed > pcPic->getNumReorderPics(tId) && pcPic->getPOC() > m_iPOCLastDisplay)) |
---|
[368] | 464 | #endif |
---|
[324] | 465 | { |
---|
| 466 | // write to file |
---|
| 467 | not_displayed--; |
---|
[368] | 468 | #if H_MV |
---|
| 469 | if ( m_pchReconFiles[decIdx] ) |
---|
| 470 | #else |
---|
[324] | 471 | if ( m_pchReconFile ) |
---|
[368] | 472 | #endif |
---|
[324] | 473 | { |
---|
| 474 | const Window &conf = pcPic->getConformanceWindow(); |
---|
| 475 | const Window &defDisp = m_respectDefDispWindow ? pcPic->getDefDisplayWindow() : Window(); |
---|
[368] | 476 | #if H_MV |
---|
| 477 | m_tVideoIOYuvReconFile[decIdx]->write( pcPic->getPicYuvRec(), |
---|
| 478 | #else |
---|
[324] | 479 | m_cTVideoIOYuvReconFile.write( pcPic->getPicYuvRec(), |
---|
[368] | 480 | #endif |
---|
[324] | 481 | conf.getWindowLeftOffset() + defDisp.getWindowLeftOffset(), |
---|
| 482 | conf.getWindowRightOffset() + defDisp.getWindowRightOffset(), |
---|
| 483 | conf.getWindowTopOffset() + defDisp.getWindowTopOffset(), |
---|
| 484 | conf.getWindowBottomOffset() + defDisp.getWindowBottomOffset() ); |
---|
| 485 | } |
---|
| 486 | |
---|
| 487 | // update POC of display order |
---|
[368] | 488 | #if H_MV |
---|
| 489 | m_pocLastDisplay[decIdx] = pcPic->getPOC(); |
---|
| 490 | #else |
---|
[324] | 491 | m_iPOCLastDisplay = pcPic->getPOC(); |
---|
[368] | 492 | #endif |
---|
[324] | 493 | |
---|
| 494 | // erase non-referenced picture in the reference picture list after display |
---|
| 495 | if ( !pcPic->getSlice(0)->isReferenced() && pcPic->getReconMark() == true ) |
---|
| 496 | { |
---|
| 497 | #if !DYN_REF_FREE |
---|
| 498 | pcPic->setReconMark(false); |
---|
| 499 | |
---|
| 500 | // mark it should be extended later |
---|
| 501 | pcPic->getPicYuvRec()->setBorderExtension( false ); |
---|
| 502 | |
---|
| 503 | #else |
---|
| 504 | pcPic->destroy(); |
---|
| 505 | pcListPic->erase( iterPic ); |
---|
| 506 | iterPic = pcListPic->begin(); // to the beginning, non-efficient way, have to be revised! |
---|
| 507 | continue; |
---|
| 508 | #endif |
---|
| 509 | } |
---|
| 510 | pcPic->setOutputMark(false); |
---|
| 511 | } |
---|
| 512 | |
---|
| 513 | iterPic++; |
---|
| 514 | } |
---|
| 515 | } |
---|
| 516 | |
---|
| 517 | /** \param pcListPic list of pictures to be written to file |
---|
| 518 | \todo DYN_REF_FREE should be revised |
---|
| 519 | */ |
---|
[368] | 520 | #if H_MV |
---|
| 521 | Void TAppDecTop::xFlushOutput( TComList<TComPic*>* pcListPic, Int decIdx ) |
---|
| 522 | #else |
---|
[324] | 523 | Void TAppDecTop::xFlushOutput( TComList<TComPic*>* pcListPic ) |
---|
[368] | 524 | #endif |
---|
[324] | 525 | { |
---|
| 526 | if(!pcListPic) |
---|
| 527 | { |
---|
| 528 | return; |
---|
| 529 | } |
---|
| 530 | TComList<TComPic*>::iterator iterPic = pcListPic->begin(); |
---|
| 531 | |
---|
| 532 | iterPic = pcListPic->begin(); |
---|
| 533 | |
---|
| 534 | while (iterPic != pcListPic->end()) |
---|
| 535 | { |
---|
| 536 | TComPic* pcPic = *(iterPic); |
---|
| 537 | |
---|
| 538 | if ( pcPic->getOutputMark() ) |
---|
| 539 | { |
---|
| 540 | // write to file |
---|
[368] | 541 | #if H_MV |
---|
| 542 | if ( m_pchReconFiles[decIdx] ) |
---|
| 543 | #else |
---|
[324] | 544 | if ( m_pchReconFile ) |
---|
[368] | 545 | #endif |
---|
[324] | 546 | { |
---|
| 547 | const Window &conf = pcPic->getConformanceWindow(); |
---|
| 548 | const Window &defDisp = m_respectDefDispWindow ? pcPic->getDefDisplayWindow() : Window(); |
---|
[368] | 549 | #if H_MV |
---|
| 550 | m_tVideoIOYuvReconFile[decIdx]->write( pcPic->getPicYuvRec(), |
---|
| 551 | #else |
---|
[324] | 552 | m_cTVideoIOYuvReconFile.write( pcPic->getPicYuvRec(), |
---|
[368] | 553 | #endif |
---|
[324] | 554 | conf.getWindowLeftOffset() + defDisp.getWindowLeftOffset(), |
---|
| 555 | conf.getWindowRightOffset() + defDisp.getWindowRightOffset(), |
---|
| 556 | conf.getWindowTopOffset() + defDisp.getWindowTopOffset(), |
---|
| 557 | conf.getWindowBottomOffset() + defDisp.getWindowBottomOffset() ); |
---|
| 558 | } |
---|
| 559 | |
---|
| 560 | // update POC of display order |
---|
[368] | 561 | #if H_MV |
---|
| 562 | m_pocLastDisplay[decIdx] = pcPic->getPOC(); |
---|
| 563 | #else |
---|
[324] | 564 | m_iPOCLastDisplay = pcPic->getPOC(); |
---|
[368] | 565 | #endif |
---|
[324] | 566 | |
---|
| 567 | // erase non-referenced picture in the reference picture list after display |
---|
| 568 | if ( !pcPic->getSlice(0)->isReferenced() && pcPic->getReconMark() == true ) |
---|
| 569 | { |
---|
| 570 | #if !DYN_REF_FREE |
---|
| 571 | pcPic->setReconMark(false); |
---|
| 572 | |
---|
| 573 | // mark it should be extended later |
---|
| 574 | pcPic->getPicYuvRec()->setBorderExtension( false ); |
---|
| 575 | |
---|
| 576 | #else |
---|
| 577 | pcPic->destroy(); |
---|
| 578 | pcListPic->erase( iterPic ); |
---|
| 579 | iterPic = pcListPic->begin(); // to the beginning, non-efficient way, have to be revised! |
---|
| 580 | continue; |
---|
| 581 | #endif |
---|
| 582 | } |
---|
| 583 | pcPic->setOutputMark(false); |
---|
| 584 | } |
---|
[368] | 585 | #if !H_MV |
---|
[324] | 586 | #if !DYN_REF_FREE |
---|
| 587 | if(pcPic) |
---|
| 588 | { |
---|
| 589 | pcPic->destroy(); |
---|
| 590 | delete pcPic; |
---|
| 591 | pcPic = NULL; |
---|
| 592 | } |
---|
| 593 | #endif |
---|
[368] | 594 | #endif |
---|
[324] | 595 | iterPic++; |
---|
| 596 | } |
---|
[368] | 597 | #if H_MV |
---|
| 598 | m_pocLastDisplay[decIdx] = -MAX_INT; |
---|
| 599 | #else |
---|
[324] | 600 | pcListPic->clear(); |
---|
| 601 | m_iPOCLastDisplay = -MAX_INT; |
---|
[368] | 602 | #endif |
---|
[324] | 603 | } |
---|
| 604 | |
---|
| 605 | /** \param nalu Input nalu to check whether its LayerId is within targetDecLayerIdSet |
---|
| 606 | */ |
---|
| 607 | Bool TAppDecTop::isNaluWithinTargetDecLayerIdSet( InputNALUnit* nalu ) |
---|
| 608 | { |
---|
| 609 | if ( m_targetDecLayerIdSet.size() == 0 ) // By default, the set is empty, meaning all LayerIds are allowed |
---|
| 610 | { |
---|
| 611 | return true; |
---|
| 612 | } |
---|
| 613 | for (std::vector<Int>::iterator it = m_targetDecLayerIdSet.begin(); it != m_targetDecLayerIdSet.end(); it++) |
---|
| 614 | { |
---|
[368] | 615 | #if H_MV |
---|
| 616 | if ( nalu->m_layerId == (*it) ) |
---|
| 617 | #else |
---|
[324] | 618 | if ( nalu->m_reservedZero6Bits == (*it) ) |
---|
[368] | 619 | #endif |
---|
[324] | 620 | { |
---|
| 621 | return true; |
---|
| 622 | } |
---|
| 623 | } |
---|
| 624 | return false; |
---|
| 625 | } |
---|
| 626 | |
---|
[446] | 627 | #if H_MV |
---|
| 628 | Int TAppDecTop::xGetDecoderIdx( Int layerId, Bool createFlag /*= false */ ) |
---|
| 629 | { |
---|
| 630 | Int decIdx = -1; |
---|
| 631 | if ( m_layerIdToDecIdx[ layerId ] != -1 ) |
---|
| 632 | { |
---|
| 633 | decIdx = m_layerIdToDecIdx[ layerId ]; |
---|
| 634 | } |
---|
| 635 | else |
---|
| 636 | { |
---|
| 637 | assert ( createFlag ); |
---|
| 638 | assert( m_numDecoders < MAX_NUM_LAYERS ); |
---|
| 639 | |
---|
| 640 | decIdx = m_numDecoders; |
---|
| 641 | |
---|
| 642 | // Init decoder |
---|
| 643 | m_tDecTop[ decIdx ] = new TDecTop; |
---|
| 644 | m_tDecTop[ decIdx ]->create(); |
---|
| 645 | m_tDecTop[ decIdx ]->init( ); |
---|
| 646 | m_tDecTop[ decIdx ]->setLayerId( layerId ); |
---|
| 647 | m_tDecTop[ decIdx ]->setDecodedPictureHashSEIEnabled(m_decodedPictureHashSEIEnabled); |
---|
| 648 | m_tDecTop[ decIdx ]->setIvPicLists( &m_ivPicLists ); |
---|
| 649 | #if H_3D |
---|
| 650 | m_tDecTop[ decIdx ]->setCamParsCollector( &m_cCamParsCollector ); |
---|
| 651 | #endif |
---|
| 652 | |
---|
| 653 | // append pic list of new decoder to PicLists |
---|
| 654 | assert( m_ivPicLists.size() == m_numDecoders ); |
---|
| 655 | m_ivPicLists.push_back( m_tDecTop[ decIdx ]->getListPic() ); |
---|
| 656 | |
---|
| 657 | // create recon file related stuff |
---|
| 658 | Char* pchTempFilename = NULL; |
---|
| 659 | if ( m_pchReconFile ) |
---|
| 660 | { |
---|
| 661 | Char buffer[4]; |
---|
| 662 | sprintf(buffer,"_%i", layerId ); |
---|
| 663 | assert ( m_pchReconFile ); |
---|
| 664 | xAppendToFileNameEnd( m_pchReconFile , buffer, pchTempFilename ); |
---|
| 665 | assert( m_pchReconFiles.size() == m_numDecoders ); |
---|
| 666 | } |
---|
| 667 | |
---|
| 668 | m_pchReconFiles.push_back( pchTempFilename ); |
---|
| 669 | |
---|
| 670 | m_tVideoIOYuvReconFile[ decIdx ] = new TVideoIOYuv; |
---|
| 671 | m_reconOpen [ decIdx ] = false; |
---|
| 672 | |
---|
| 673 | // set others |
---|
| 674 | m_pocLastDisplay [ decIdx ] = -MAX_INT; |
---|
| 675 | m_layerIdToDecIdx [ layerId ] = decIdx; |
---|
| 676 | |
---|
| 677 | m_numDecoders++; |
---|
| 678 | }; |
---|
| 679 | return decIdx; |
---|
| 680 | } |
---|
| 681 | #endif |
---|
[324] | 682 | //! \} |
---|