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