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