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