[5] | 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 |
---|
[56] | 4 | * granted under this license. |
---|
[5] | 5 | * |
---|
[1179] | 6 | * Copyright (c) 2010-2015, ITU/ISO/IEC |
---|
[5] | 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. |
---|
[56] | 17 | * * Neither the name of the ITU/ISO/IEC nor the names of its contributors may |
---|
[5] | 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 | */ |
---|
[2] | 33 | |
---|
| 34 | /** \file TAppDecTop.cpp |
---|
| 35 | \brief Decoder application class |
---|
| 36 | */ |
---|
| 37 | |
---|
| 38 | #include <list> |
---|
[56] | 39 | #include <vector> |
---|
[2] | 40 | #include <stdio.h> |
---|
| 41 | #include <fcntl.h> |
---|
| 42 | #include <assert.h> |
---|
| 43 | |
---|
| 44 | #include "TAppDecTop.h" |
---|
[56] | 45 | #include "TLibDecoder/AnnexBread.h" |
---|
| 46 | #include "TLibDecoder/NALread.h" |
---|
[2] | 47 | |
---|
[56] | 48 | //! \ingroup TAppDecoder |
---|
| 49 | //! \{ |
---|
[2] | 50 | |
---|
| 51 | // ==================================================================================================================== |
---|
| 52 | // Constructor / destructor / initialization / destroy |
---|
| 53 | // ==================================================================================================================== |
---|
| 54 | |
---|
| 55 | TAppDecTop::TAppDecTop() |
---|
[608] | 56 | #if !H_MV |
---|
| 57 | : m_iPOCLastDisplay(-MAX_INT) |
---|
| 58 | #else |
---|
| 59 | : m_numDecoders( 0 ) |
---|
| 60 | #endif |
---|
[2] | 61 | { |
---|
[608] | 62 | #if H_MV |
---|
[738] | 63 | for (Int i = 0; i < MAX_NUM_LAYER_IDS; i++) |
---|
| 64 | { |
---|
| 65 | m_layerIdToDecIdx[i] = -1; |
---|
| 66 | m_layerInitilizedFlags[i] = false; |
---|
| 67 | } |
---|
[608] | 68 | #endif |
---|
| 69 | #if H_3D |
---|
| 70 | m_pScaleOffsetFile = 0; |
---|
| 71 | #endif |
---|
[964] | 72 | |
---|
[976] | 73 | #if H_MV |
---|
[964] | 74 | m_markedForOutput = false; |
---|
| 75 | #endif |
---|
| 76 | |
---|
[2] | 77 | } |
---|
| 78 | |
---|
| 79 | Void TAppDecTop::create() |
---|
| 80 | { |
---|
| 81 | } |
---|
| 82 | |
---|
| 83 | Void TAppDecTop::destroy() |
---|
| 84 | { |
---|
[608] | 85 | if (m_pchBitstreamFile) |
---|
| 86 | { |
---|
| 87 | free (m_pchBitstreamFile); |
---|
| 88 | m_pchBitstreamFile = NULL; |
---|
| 89 | } |
---|
| 90 | #if H_MV |
---|
| 91 | for (Int decIdx = 0; decIdx < m_numDecoders; decIdx++) |
---|
| 92 | { |
---|
| 93 | if (m_pchReconFiles[decIdx]) |
---|
| 94 | { |
---|
| 95 | free (m_pchReconFiles[decIdx]); |
---|
| 96 | m_pchReconFiles[decIdx] = NULL; |
---|
| 97 | } |
---|
| 98 | } |
---|
| 99 | #endif |
---|
| 100 | if (m_pchReconFile) |
---|
| 101 | { |
---|
| 102 | free (m_pchReconFile); |
---|
| 103 | m_pchReconFile = NULL; |
---|
| 104 | } |
---|
| 105 | #if H_3D |
---|
| 106 | if (m_pchScaleOffsetFile) |
---|
| 107 | { |
---|
| 108 | free (m_pchScaleOffsetFile); |
---|
| 109 | m_pchScaleOffsetFile = NULL; |
---|
| 110 | } |
---|
| 111 | #endif |
---|
[2] | 112 | } |
---|
| 113 | |
---|
| 114 | // ==================================================================================================================== |
---|
| 115 | // Public member functions |
---|
| 116 | // ==================================================================================================================== |
---|
| 117 | |
---|
| 118 | /** |
---|
| 119 | - create internal class |
---|
| 120 | - initialize internal class |
---|
| 121 | - until the end of the bitstream, call decoding function in TDecTop class |
---|
| 122 | - delete allocated buffers |
---|
| 123 | - destroy internal class |
---|
| 124 | . |
---|
| 125 | */ |
---|
| 126 | Void TAppDecTop::decode() |
---|
| 127 | { |
---|
[608] | 128 | Int poc; |
---|
| 129 | #if H_MV |
---|
| 130 | poc = -1; |
---|
[77] | 131 | #endif |
---|
[608] | 132 | TComList<TComPic*>* pcListPic = NULL; |
---|
[210] | 133 | |
---|
[56] | 134 | ifstream bitstreamFile(m_pchBitstreamFile, ifstream::in | ifstream::binary); |
---|
| 135 | if (!bitstreamFile) |
---|
| 136 | { |
---|
| 137 | fprintf(stderr, "\nfailed to open bitstream file `%s' for reading\n", m_pchBitstreamFile); |
---|
| 138 | exit(EXIT_FAILURE); |
---|
| 139 | } |
---|
[2] | 140 | |
---|
[608] | 141 | #if H_3D |
---|
[56] | 142 | if( m_pchScaleOffsetFile ) |
---|
| 143 | { |
---|
| 144 | m_pScaleOffsetFile = ::fopen( m_pchScaleOffsetFile, "wt" ); |
---|
| 145 | AOF( m_pScaleOffsetFile ); |
---|
| 146 | } |
---|
[608] | 147 | #endif |
---|
[56] | 148 | InputByteStream bytestream(bitstreamFile); |
---|
| 149 | |
---|
[608] | 150 | // create & initialize internal classes |
---|
| 151 | xCreateDecLib(); |
---|
| 152 | xInitDecLib (); |
---|
| 153 | #if !H_MV |
---|
| 154 | m_iPOCLastDisplay += m_iSkipFrame; // set the last displayed POC correctly for skip forward. |
---|
| 155 | |
---|
| 156 | // main decoder loop |
---|
[655] | 157 | Bool openedReconFile = false; // reconstruction file not yet opened. (must be performed after SPS is seen) |
---|
[608] | 158 | #else |
---|
[964] | 159 | |
---|
[608] | 160 | Int pocCurrPic = -MAX_INT; |
---|
| 161 | Int pocLastPic = -MAX_INT; |
---|
[964] | 162 | |
---|
| 163 | Int layerIdLastPic = -MAX_INT; |
---|
[608] | 164 | Int layerIdCurrPic = 0; |
---|
| 165 | |
---|
| 166 | Int decIdxLastPic = 0; |
---|
| 167 | Int decIdxCurrPic = 0; |
---|
| 168 | |
---|
| 169 | Bool firstSlice = true; |
---|
| 170 | #endif |
---|
[872] | 171 | Bool loopFiltered = false; |
---|
| 172 | |
---|
[56] | 173 | while (!!bitstreamFile) |
---|
[2] | 174 | { |
---|
[56] | 175 | /* location serves to work around a design fault in the decoder, whereby |
---|
| 176 | * the process of reading a new slice that is the first slice of a new frame |
---|
| 177 | * requires the TDecTop::decode() method to be called again with the same |
---|
| 178 | * nal unit. */ |
---|
| 179 | streampos location = bitstreamFile.tellg(); |
---|
[608] | 180 | #if H_MV |
---|
| 181 | #if ENC_DEC_TRACE |
---|
| 182 | Int64 symCount = g_nSymbolCounter; |
---|
| 183 | #endif |
---|
| 184 | #endif |
---|
[56] | 185 | AnnexBStats stats = AnnexBStats(); |
---|
| 186 | vector<uint8_t> nalUnit; |
---|
| 187 | InputNALUnit nalu; |
---|
| 188 | byteStreamNALUnit(bytestream, nalUnit, stats); |
---|
| 189 | |
---|
| 190 | // call actual decoding function |
---|
[608] | 191 | Bool bNewPicture = false; |
---|
| 192 | #if H_MV |
---|
| 193 | Bool newSliceDiffPoc = false; |
---|
| 194 | Bool newSliceDiffLayer = false; |
---|
[964] | 195 | Bool sliceSkippedFlag = false; |
---|
[608] | 196 | Bool allLayersDecoded = false; |
---|
| 197 | #endif |
---|
[56] | 198 | if (nalUnit.empty()) |
---|
[2] | 199 | { |
---|
[56] | 200 | /* this can happen if the following occur: |
---|
| 201 | * - empty input file |
---|
| 202 | * - two back-to-back start_code_prefixes |
---|
| 203 | * - start_code_prefix immediately followed by EOF |
---|
| 204 | */ |
---|
| 205 | fprintf(stderr, "Warning: Attempt to decode an empty NAL unit\n"); |
---|
[2] | 206 | } |
---|
| 207 | else |
---|
| 208 | { |
---|
[56] | 209 | read(nalu, nalUnit); |
---|
[608] | 210 | #if H_MV |
---|
[872] | 211 | if( (m_iMaxTemporalLayer >= 0 && nalu.m_temporalId > m_iMaxTemporalLayer) |
---|
| 212 | || !isNaluWithinTargetDecLayerIdSet(&nalu) |
---|
| 213 | || nalu.m_layerId > MAX_NUM_LAYER_IDS-1 |
---|
| 214 | || (nalu.m_nalUnitType == NAL_UNIT_VPS && nalu.m_layerId > 0) |
---|
[964] | 215 | || (nalu.m_nalUnitType == NAL_UNIT_EOB && nalu.m_layerId > 0) |
---|
| 216 | || (nalu.m_nalUnitType == NAL_UNIT_EOS && nalu.m_layerId > 0) |
---|
[872] | 217 | ) |
---|
[77] | 218 | { |
---|
[608] | 219 | bNewPicture = false; |
---|
[738] | 220 | if ( !bitstreamFile ) |
---|
| 221 | { |
---|
| 222 | decIdxLastPic = decIdxCurrPic; |
---|
| 223 | } |
---|
[77] | 224 | } |
---|
[210] | 225 | else |
---|
[608] | 226 | { |
---|
[738] | 227 | Int decIdx = xGetDecoderIdx( nalu.m_layerId , true ); |
---|
[608] | 228 | newSliceDiffLayer = nalu.isSlice() && ( nalu.m_layerId != layerIdCurrPic ) && !firstSlice; |
---|
[738] | 229 | newSliceDiffPoc = m_tDecTop[decIdx]->decode(nalu, m_iSkipFrame, m_pocLastDisplay[decIdx], newSliceDiffLayer, sliceSkippedFlag ); |
---|
[608] | 230 | // decode function only returns true when all of the following conditions are true |
---|
| 231 | // - poc in particular layer changes |
---|
| 232 | // - nalu does not belong to first slice in layer |
---|
| 233 | // - nalu.isSlice() == true |
---|
| 234 | |
---|
[964] | 235 | if ( nalu.m_nalUnitType == NAL_UNIT_VPS ) |
---|
| 236 | { |
---|
| 237 | m_vps = m_tDecTop[decIdx]->getPrefetchedVPS(); |
---|
| 238 | if ( m_targetDecLayerIdSetFileEmpty ) |
---|
| 239 | { |
---|
| 240 | TComVPS* vps = m_vps; |
---|
[1066] | 241 | if ( m_targetOptLayerSetIdx == -1 ) |
---|
| 242 | { |
---|
| 243 | // Not normative! Corresponds to specification by "External Means". (Should be set equal to 0, when no external means available. ) |
---|
| 244 | m_targetOptLayerSetIdx = vps->getVpsNumLayerSetsMinus1(); |
---|
| 245 | } |
---|
[976] | 246 | |
---|
[1066] | 247 | for (Int dI = 0; dI < m_numDecoders; dI++ ) |
---|
| 248 | { |
---|
| 249 | m_tDecTop[decIdx]->setTargetOptLayerSetIdx( m_targetOptLayerSetIdx ); |
---|
[1196] | 250 | #if H_3D |
---|
[1179] | 251 | m_tDecTop[decIdx]->setProfileIdc( ); |
---|
| 252 | #endif |
---|
[1066] | 253 | } |
---|
| 254 | |
---|
| 255 | if ( m_targetOptLayerSetIdx < 0 || m_targetOptLayerSetIdx >= vps->getNumOutputLayerSets() ) |
---|
| 256 | { |
---|
| 257 | fprintf(stderr, "\ntarget output layer set index must be in the range of 0 to %d, inclusive \n", vps->getNumOutputLayerSets() - 1 ); |
---|
| 258 | exit(EXIT_FAILURE); |
---|
| 259 | } |
---|
| 260 | m_targetDecLayerIdSet = vps->getTargetDecLayerIdList( m_targetOptLayerSetIdx ); |
---|
[964] | 261 | } |
---|
[1066] | 262 | if (m_outputVpsInfo ) |
---|
[872] | 263 | { |
---|
[1066] | 264 | m_vps->printScalabilityId(); |
---|
| 265 | m_vps->printLayerDependencies(); |
---|
| 266 | m_vps->printLayerSets(); |
---|
| 267 | m_vps->printPTL(); |
---|
[872] | 268 | } |
---|
[738] | 269 | } |
---|
[872] | 270 | #if H_3D |
---|
| 271 | if (nalu.m_nalUnitType == NAL_UNIT_VPS ) |
---|
[884] | 272 | { |
---|
[872] | 273 | m_cCamParsCollector.init( m_pScaleOffsetFile, m_tDecTop[decIdx]->getPrefetchedVPS() ); |
---|
| 274 | } |
---|
| 275 | #endif |
---|
[738] | 276 | bNewPicture = ( newSliceDiffLayer || newSliceDiffPoc ) && !sliceSkippedFlag; |
---|
| 277 | if ( nalu.isSlice() && firstSlice && !sliceSkippedFlag ) |
---|
[210] | 278 | { |
---|
[608] | 279 | layerIdCurrPic = nalu.m_layerId; |
---|
| 280 | pocCurrPic = m_tDecTop[decIdx]->getCurrPoc(); |
---|
| 281 | decIdxCurrPic = decIdx; |
---|
| 282 | firstSlice = false; |
---|
[210] | 283 | } |
---|
[608] | 284 | |
---|
| 285 | if ( bNewPicture || !bitstreamFile ) |
---|
| 286 | { |
---|
[964] | 287 | layerIdLastPic = layerIdCurrPic; |
---|
[608] | 288 | layerIdCurrPic = nalu.m_layerId; |
---|
| 289 | pocLastPic = pocCurrPic; |
---|
| 290 | pocCurrPic = m_tDecTop[decIdx]->getCurrPoc(); |
---|
| 291 | decIdxLastPic = decIdxCurrPic; |
---|
| 292 | decIdxCurrPic = decIdx; |
---|
| 293 | allLayersDecoded = ( pocCurrPic != pocLastPic ); |
---|
[210] | 294 | } |
---|
| 295 | #else |
---|
[608] | 296 | if( (m_iMaxTemporalLayer >= 0 && nalu.m_temporalId > m_iMaxTemporalLayer) || !isNaluWithinTargetDecLayerIdSet(&nalu) ) |
---|
[210] | 297 | { |
---|
[655] | 298 | bNewPicture = false; |
---|
[210] | 299 | } |
---|
[608] | 300 | else |
---|
[2] | 301 | { |
---|
[608] | 302 | bNewPicture = m_cTDecTop.decode(nalu, m_iSkipFrame, m_iPOCLastDisplay); |
---|
[56] | 303 | #endif |
---|
[608] | 304 | if (bNewPicture) |
---|
[42] | 305 | { |
---|
[56] | 306 | bitstreamFile.clear(); |
---|
| 307 | /* location points to the current nalunit payload[1] due to the |
---|
| 308 | * need for the annexB parser to read three extra bytes. |
---|
| 309 | * [1] except for the first NAL unit in the file |
---|
| 310 | * (but bNewPicture doesn't happen then) */ |
---|
| 311 | bitstreamFile.seekg(location-streamoff(3)); |
---|
| 312 | bytestream.reset(); |
---|
[872] | 313 | #if H_MV_ENC_DEC_TRAC |
---|
[608] | 314 | #if ENC_DEC_TRACE |
---|
| 315 | const Bool resetCounter = false; |
---|
| 316 | if ( resetCounter ) |
---|
| 317 | { |
---|
| 318 | g_nSymbolCounter = symCount; // Only reset counter SH becomes traced twice |
---|
[210] | 319 | } |
---|
[608] | 320 | else |
---|
| 321 | { |
---|
[872] | 322 | g_disableHLSTrace = true; // Tracing of second parsing of SH is not carried out |
---|
| 323 | } |
---|
[210] | 324 | #endif |
---|
[608] | 325 | #endif |
---|
[42] | 326 | } |
---|
| 327 | } |
---|
[56] | 328 | } |
---|
[872] | 329 | if (bNewPicture || !bitstreamFile || nalu.m_nalUnitType == NAL_UNIT_EOS ) |
---|
[56] | 330 | { |
---|
[872] | 331 | if (!loopFiltered || bitstreamFile) |
---|
| 332 | { |
---|
[608] | 333 | #if H_MV |
---|
[872] | 334 | assert( decIdxLastPic != -1 ); |
---|
| 335 | m_tDecTop[decIdxLastPic]->endPicDecoding(poc, pcListPic, m_targetDecLayerIdSet ); |
---|
[964] | 336 | xMarkForOutput( allLayersDecoded, poc, layerIdLastPic ); |
---|
[608] | 337 | #else |
---|
[872] | 338 | m_cTDecTop.executeLoopFilters(poc, pcListPic); |
---|
[608] | 339 | #endif |
---|
[872] | 340 | } |
---|
| 341 | loopFiltered = (nalu.m_nalUnitType == NAL_UNIT_EOS); |
---|
[56] | 342 | } |
---|
[964] | 343 | #if !FIX_WRITING_OUTPUT |
---|
| 344 | #if SETTING_NO_OUT_PIC_PRIOR |
---|
| 345 | if (bNewPicture && m_cTDecTop.getIsNoOutputPriorPics()) |
---|
| 346 | { |
---|
| 347 | m_cTDecTop.checkNoOutputPriorPics( pcListPic ); |
---|
| 348 | } |
---|
| 349 | #endif |
---|
| 350 | #endif |
---|
[608] | 351 | #if H_3D |
---|
| 352 | if ( allLayersDecoded || !bitstreamFile ) |
---|
[56] | 353 | { |
---|
[608] | 354 | for( Int dI = 0; dI < m_numDecoders; dI++ ) |
---|
| 355 | { |
---|
| 356 | TComPic* picLastCoded = m_ivPicLists.getPic( m_tDecTop[dI]->getLayerId(), pocLastPic ); |
---|
| 357 | assert( picLastCoded != NULL ); |
---|
| 358 | picLastCoded->compressMotion(1); |
---|
| 359 | } |
---|
| 360 | } |
---|
| 361 | #endif |
---|
| 362 | |
---|
| 363 | if( pcListPic ) |
---|
| 364 | { |
---|
| 365 | #if H_MV |
---|
| 366 | if ( m_pchReconFiles[decIdxLastPic] && !m_reconOpen[decIdxLastPic] ) |
---|
| 367 | #else |
---|
[655] | 368 | if ( m_pchReconFile && !openedReconFile ) |
---|
[608] | 369 | #endif |
---|
[2] | 370 | { |
---|
[608] | 371 | if (!m_outputBitDepthY) { m_outputBitDepthY = g_bitDepthY; } |
---|
| 372 | if (!m_outputBitDepthC) { m_outputBitDepthC = g_bitDepthC; } |
---|
| 373 | |
---|
| 374 | #if H_MV |
---|
| 375 | m_tVideoIOYuvReconFile[decIdxLastPic]->open( m_pchReconFiles[decIdxLastPic], true, m_outputBitDepthY, m_outputBitDepthC, g_bitDepthY, g_bitDepthC ); // write mode |
---|
| 376 | m_reconOpen[decIdxLastPic] = true; |
---|
[2] | 377 | } |
---|
[964] | 378 | #if FIX_WRITING_OUTPUT |
---|
| 379 | // write reconstruction to file |
---|
| 380 | if( bNewPicture ) |
---|
| 381 | { |
---|
| 382 | // Bumping after picture has been decoded |
---|
| 383 | #if ENC_DEC_TRACE |
---|
| 384 | g_bJustDoIt = true; |
---|
| 385 | writeToTraceFile( "Bumping after decoding \n", g_decTracePicOutput ); |
---|
| 386 | g_bJustDoIt = false; |
---|
| 387 | #endif |
---|
| 388 | xWriteOutput( pcListPic, decIdxLastPic, nalu.m_temporalId ); |
---|
| 389 | } |
---|
| 390 | #if SETTING_NO_OUT_PIC_PRIOR |
---|
| 391 | if ( (bNewPicture || nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_CRA) && m_tDecTop[decIdxLastPic]->getNoOutputPriorPicsFlag() ) |
---|
| 392 | { |
---|
| 393 | m_tDecTop[decIdxLastPic]->checkNoOutputPriorPics( pcListPic ); |
---|
| 394 | m_tDecTop[decIdxLastPic]->setNoOutputPriorPicsFlag (false); |
---|
| 395 | } |
---|
| 396 | #endif |
---|
| 397 | #endif |
---|
[608] | 398 | if ( bNewPicture && newSliceDiffPoc && |
---|
| 399 | #else |
---|
| 400 | m_cTVideoIOYuvReconFile.open( m_pchReconFile, true, m_outputBitDepthY, m_outputBitDepthC, g_bitDepthY, g_bitDepthC ); // write mode |
---|
[655] | 401 | openedReconFile = true; |
---|
[608] | 402 | } |
---|
[964] | 403 | #if FIX_WRITING_OUTPUT |
---|
| 404 | // write reconstruction to file |
---|
| 405 | if( bNewPicture ) |
---|
| 406 | { |
---|
| 407 | xWriteOutput( pcListPic, nalu.m_temporalId ); |
---|
| 408 | } |
---|
| 409 | #if SETTING_NO_OUT_PIC_PRIOR |
---|
| 410 | if ( (bNewPicture || nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_CRA) && m_cTDecTop.getNoOutputPriorPicsFlag() ) |
---|
| 411 | { |
---|
| 412 | m_cTDecTop.checkNoOutputPriorPics( pcListPic ); |
---|
| 413 | m_cTDecTop.setNoOutputPriorPicsFlag (false); |
---|
| 414 | } |
---|
| 415 | #endif |
---|
| 416 | #endif |
---|
[608] | 417 | if ( bNewPicture && |
---|
| 418 | #endif |
---|
| 419 | ( nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_IDR_W_RADL |
---|
| 420 | || nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_IDR_N_LP |
---|
| 421 | || nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_BLA_N_LP |
---|
| 422 | || nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_BLA_W_RADL |
---|
| 423 | || nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_BLA_W_LP ) ) |
---|
| 424 | { |
---|
| 425 | #if H_MV |
---|
| 426 | xFlushOutput( pcListPic, decIdxLastPic ); |
---|
| 427 | #else |
---|
| 428 | xFlushOutput( pcListPic ); |
---|
| 429 | #endif |
---|
| 430 | } |
---|
[872] | 431 | if (nalu.m_nalUnitType == NAL_UNIT_EOS) |
---|
| 432 | { |
---|
| 433 | #if H_MV |
---|
[964] | 434 | #if FIX_OUTPUT_EOS |
---|
| 435 | xWriteOutput( pcListPic, decIdxLastPic, nalu.m_temporalId ); |
---|
| 436 | #else |
---|
[872] | 437 | xFlushOutput( pcListPic, decIdxLastPic ); |
---|
[964] | 438 | #endif |
---|
[872] | 439 | #else |
---|
[964] | 440 | #if FIX_OUTPUT_EOS |
---|
| 441 | xWriteOutput( pcListPic, nalu.m_temporalId ); |
---|
| 442 | #else |
---|
[872] | 443 | xFlushOutput( pcListPic ); |
---|
| 444 | #endif |
---|
[964] | 445 | |
---|
| 446 | #endif |
---|
[872] | 447 | } |
---|
[964] | 448 | // write reconstruction to file -- for additional bumping as defined in C.5.2.3 |
---|
| 449 | #if H_MV |
---|
| 450 | // Above comment seems to be wrong |
---|
| 451 | #endif |
---|
| 452 | #if FIX_WRITING_OUTPUT |
---|
| 453 | if(!bNewPicture && nalu.m_nalUnitType >= NAL_UNIT_CODED_SLICE_TRAIL_N && nalu.m_nalUnitType <= NAL_UNIT_RESERVED_VCL31) |
---|
| 454 | #else |
---|
[608] | 455 | if(bNewPicture) |
---|
[964] | 456 | #endif |
---|
[2] | 457 | { |
---|
[964] | 458 | #if H_MV |
---|
| 459 | // Bumping after reference picture set has been applied (here after first vcl nalu. |
---|
| 460 | #if ENC_DEC_TRACE |
---|
| 461 | g_bJustDoIt = true; |
---|
| 462 | writeToTraceFile( "Bumping after reference picture set has been applied \n", g_decTracePicOutput ); |
---|
| 463 | g_bJustDoIt = false; |
---|
| 464 | #endif |
---|
| 465 | |
---|
| 466 | xWriteOutput( m_tDecTop[decIdxCurrPic]->getListPic(), decIdxCurrPic, nalu.m_temporalId ); |
---|
| 467 | #else |
---|
| 468 | xWriteOutput( pcListPic, nalu.m_temporalId ); |
---|
| 469 | #endif |
---|
[2] | 470 | } |
---|
| 471 | } |
---|
[608] | 472 | } |
---|
[964] | 473 | #if H_MV |
---|
[608] | 474 | #if H_3D |
---|
[57] | 475 | if( m_cCamParsCollector.isInitialized() ) |
---|
| 476 | { |
---|
| 477 | m_cCamParsCollector.setSlice( 0 ); |
---|
| 478 | } |
---|
[608] | 479 | #endif |
---|
| 480 | for(UInt decIdx = 0; decIdx < m_numDecoders; decIdx++) |
---|
[2] | 481 | { |
---|
[608] | 482 | xFlushOutput( m_tDecTop[decIdx]->getListPic(), decIdx ); |
---|
| 483 | } |
---|
[964] | 484 | #else |
---|
[608] | 485 | xFlushOutput( pcListPic ); |
---|
| 486 | // delete buffers |
---|
| 487 | m_cTDecTop.deletePicBuffer(); |
---|
| 488 | #endif |
---|
| 489 | |
---|
| 490 | // destroy internal classes |
---|
[2] | 491 | xDestroyDecLib(); |
---|
| 492 | } |
---|
| 493 | |
---|
| 494 | // ==================================================================================================================== |
---|
| 495 | // Protected member functions |
---|
| 496 | // ==================================================================================================================== |
---|
| 497 | |
---|
[608] | 498 | Void TAppDecTop::xCreateDecLib() |
---|
| 499 | { |
---|
| 500 | #if H_MV |
---|
| 501 | // initialize global variables |
---|
| 502 | initROM(); |
---|
| 503 | #if H_3D_DIM_DMM |
---|
| 504 | initWedgeLists(); |
---|
| 505 | #endif |
---|
| 506 | #else |
---|
| 507 | // create decoder class |
---|
| 508 | m_cTDecTop.create(); |
---|
| 509 | #endif |
---|
| 510 | } |
---|
| 511 | |
---|
[2] | 512 | Void TAppDecTop::xDestroyDecLib() |
---|
| 513 | { |
---|
[608] | 514 | #if H_MV |
---|
| 515 | // destroy ROM |
---|
| 516 | destroyROM(); |
---|
[2] | 517 | |
---|
[608] | 518 | for(Int decIdx = 0; decIdx < m_numDecoders ; decIdx++) |
---|
[2] | 519 | { |
---|
[608] | 520 | if( m_tVideoIOYuvReconFile[decIdx] ) |
---|
[56] | 521 | { |
---|
[608] | 522 | m_tVideoIOYuvReconFile[decIdx]->close(); |
---|
| 523 | delete m_tVideoIOYuvReconFile[decIdx]; |
---|
| 524 | m_tVideoIOYuvReconFile[decIdx] = NULL ; |
---|
[56] | 525 | } |
---|
[2] | 526 | |
---|
[608] | 527 | if( m_tDecTop[decIdx] ) |
---|
[56] | 528 | { |
---|
[608] | 529 | m_tDecTop[decIdx]->deletePicBuffer(); |
---|
| 530 | m_tDecTop[decIdx]->destroy() ; |
---|
[56] | 531 | } |
---|
[608] | 532 | delete m_tDecTop[decIdx] ; |
---|
| 533 | m_tDecTop[decIdx] = NULL ; |
---|
[2] | 534 | } |
---|
[608] | 535 | #else |
---|
| 536 | if ( m_pchReconFile ) |
---|
| 537 | { |
---|
| 538 | m_cTVideoIOYuvReconFile. close(); |
---|
| 539 | } |
---|
| 540 | |
---|
| 541 | // destroy decoder class |
---|
| 542 | m_cTDecTop.destroy(); |
---|
| 543 | #endif |
---|
| 544 | #if H_3D |
---|
[57] | 545 | m_cCamParsCollector.uninit(); |
---|
| 546 | if( m_pScaleOffsetFile ) |
---|
| 547 | { |
---|
| 548 | ::fclose( m_pScaleOffsetFile ); |
---|
| 549 | } |
---|
[608] | 550 | #endif |
---|
[56] | 551 | } |
---|
[2] | 552 | |
---|
[608] | 553 | Void TAppDecTop::xInitDecLib() |
---|
[56] | 554 | { |
---|
[608] | 555 | #if !H_MV |
---|
| 556 | // initialize decoder class |
---|
| 557 | m_cTDecTop.init(); |
---|
| 558 | m_cTDecTop.setDecodedPictureHashSEIEnabled(m_decodedPictureHashSEIEnabled); |
---|
| 559 | #endif |
---|
| 560 | } |
---|
| 561 | |
---|
| 562 | /** \param pcListPic list of pictures to be written to file |
---|
| 563 | \todo DYN_REF_FREE should be revised |
---|
| 564 | */ |
---|
| 565 | #if H_MV |
---|
| 566 | Void TAppDecTop::xWriteOutput( TComList<TComPic*>* pcListPic, Int decIdx, Int tId ) |
---|
| 567 | #else |
---|
| 568 | Void TAppDecTop::xWriteOutput( TComList<TComPic*>* pcListPic, UInt tId ) |
---|
| 569 | #endif |
---|
| 570 | { |
---|
[872] | 571 | |
---|
| 572 | if (pcListPic->empty()) |
---|
| 573 | { |
---|
| 574 | return; |
---|
| 575 | } |
---|
| 576 | |
---|
[56] | 577 | TComList<TComPic*>::iterator iterPic = pcListPic->begin(); |
---|
[655] | 578 | Int numPicsNotYetDisplayed = 0; |
---|
[964] | 579 | Int dpbFullness = 0; |
---|
| 580 | #if H_MV |
---|
[1066] | 581 | TComSPS* activeSPS = m_tDecTop[ decIdx ]->getActiveSPS(); |
---|
| 582 | #else |
---|
[964] | 583 | TComSPS* activeSPS = m_cTDecTop.getActiveSPS(); |
---|
| 584 | #endif |
---|
| 585 | UInt numReorderPicsHighestTid; |
---|
| 586 | UInt maxDecPicBufferingHighestTid; |
---|
| 587 | UInt maxNrSublayers = activeSPS->getMaxTLayers(); |
---|
| 588 | |
---|
| 589 | if(m_iMaxTemporalLayer == -1 || m_iMaxTemporalLayer >= maxNrSublayers) |
---|
| 590 | { |
---|
| 591 | numReorderPicsHighestTid = activeSPS->getNumReorderPics(maxNrSublayers-1); |
---|
| 592 | maxDecPicBufferingHighestTid = activeSPS->getMaxDecPicBuffering(maxNrSublayers-1); |
---|
| 593 | } |
---|
| 594 | else |
---|
| 595 | { |
---|
| 596 | numReorderPicsHighestTid = activeSPS->getNumReorderPics(m_iMaxTemporalLayer); |
---|
| 597 | maxDecPicBufferingHighestTid = activeSPS->getMaxDecPicBuffering(m_iMaxTemporalLayer); |
---|
| 598 | } |
---|
[655] | 599 | |
---|
[56] | 600 | while (iterPic != pcListPic->end()) |
---|
[2] | 601 | { |
---|
[56] | 602 | TComPic* pcPic = *(iterPic); |
---|
[608] | 603 | #if H_MV |
---|
| 604 | if(pcPic->getOutputMark() && pcPic->getPOC() > m_pocLastDisplay[decIdx]) |
---|
| 605 | #else |
---|
| 606 | if(pcPic->getOutputMark() && pcPic->getPOC() > m_iPOCLastDisplay) |
---|
| 607 | #endif |
---|
[56] | 608 | { |
---|
[655] | 609 | numPicsNotYetDisplayed++; |
---|
[964] | 610 | dpbFullness++; |
---|
[56] | 611 | } |
---|
[964] | 612 | else if(pcPic->getSlice( 0 )->isReferenced()) |
---|
| 613 | { |
---|
| 614 | dpbFullness++; |
---|
| 615 | } |
---|
[56] | 616 | iterPic++; |
---|
[2] | 617 | } |
---|
[56] | 618 | iterPic = pcListPic->begin(); |
---|
[655] | 619 | if (numPicsNotYetDisplayed>2) |
---|
| 620 | { |
---|
| 621 | iterPic++; |
---|
| 622 | } |
---|
[56] | 623 | |
---|
[655] | 624 | TComPic* pcPic = *(iterPic); |
---|
| 625 | if (numPicsNotYetDisplayed>2 && pcPic->isField()) //Field Decoding |
---|
[2] | 626 | { |
---|
[655] | 627 | TComList<TComPic*>::iterator endPic = pcListPic->end(); |
---|
| 628 | endPic--; |
---|
| 629 | iterPic = pcListPic->begin(); |
---|
| 630 | while (iterPic != endPic) |
---|
| 631 | { |
---|
| 632 | TComPic* pcPicTop = *(iterPic); |
---|
| 633 | iterPic++; |
---|
| 634 | TComPic* pcPicBottom = *(iterPic); |
---|
| 635 | |
---|
[608] | 636 | #if H_MV |
---|
[655] | 637 | if ( pcPicTop->getOutputMark() && (numPicsNotYetDisplayed > pcPicTop->getNumReorderPics(tId) && !(pcPicTop->getPOC()%2) && pcPicBottom->getPOC() == pcPicTop->getPOC()+1) |
---|
| 638 | && pcPicBottom->getOutputMark() && (numPicsNotYetDisplayed > pcPicBottom->getNumReorderPics(tId) && (pcPicTop->getPOC() == m_pocLastDisplay[decIdx]+1 || m_pocLastDisplay[decIdx]<0))) |
---|
[608] | 639 | #else |
---|
[964] | 640 | if ( pcPicTop->getOutputMark() && pcPicBottom->getOutputMark() && |
---|
| 641 | (numPicsNotYetDisplayed > numReorderPicsHighestTid || dpbFullness > maxDecPicBufferingHighestTid) && |
---|
| 642 | (!(pcPicTop->getPOC()%2) && pcPicBottom->getPOC() == pcPicTop->getPOC()+1) && |
---|
| 643 | (pcPicTop->getPOC() == m_iPOCLastDisplay+1 || m_iPOCLastDisplay < 0)) |
---|
[608] | 644 | #endif |
---|
[655] | 645 | { |
---|
| 646 | // write to file |
---|
| 647 | numPicsNotYetDisplayed = numPicsNotYetDisplayed-2; |
---|
[608] | 648 | #if H_MV |
---|
| 649 | if ( m_pchReconFiles[decIdx] ) |
---|
| 650 | #else |
---|
[655] | 651 | if ( m_pchReconFile ) |
---|
[608] | 652 | #endif |
---|
[655] | 653 | { |
---|
| 654 | const Window &conf = pcPicTop->getConformanceWindow(); |
---|
| 655 | const Window &defDisp = m_respectDefDispWindow ? pcPicTop->getDefDisplayWindow() : Window(); |
---|
| 656 | |
---|
| 657 | const Bool isTff = pcPicTop->isTopField(); |
---|
[608] | 658 | #if H_MV |
---|
[622] | 659 | assert( conf .getScaledFlag() ); |
---|
| 660 | assert( defDisp.getScaledFlag() ); |
---|
[976] | 661 | #if ENC_DEC_TRACE |
---|
[964] | 662 | g_bJustDoIt = true; |
---|
| 663 | writeToTraceFile( "OutputPic Poc" , pcPic->getPOC (), g_decTracePicOutput ); |
---|
| 664 | writeToTraceFile( "OutputPic LayerId", pcPic->getLayerId(), g_decTracePicOutput ); |
---|
| 665 | g_bJustDoIt = false; |
---|
| 666 | #endif |
---|
[655] | 667 | m_tVideoIOYuvReconFile[decIdx]->write( pcPicTop->getPicYuvRec(), pcPicBottom->getPicYuvRec(), |
---|
| 668 | #else |
---|
| 669 | m_cTVideoIOYuvReconFile.write( pcPicTop->getPicYuvRec(), pcPicBottom->getPicYuvRec(), |
---|
[622] | 670 | #endif |
---|
[655] | 671 | conf.getWindowLeftOffset() + defDisp.getWindowLeftOffset(), |
---|
| 672 | conf.getWindowRightOffset() + defDisp.getWindowRightOffset(), |
---|
| 673 | conf.getWindowTopOffset() + defDisp.getWindowTopOffset(), |
---|
| 674 | conf.getWindowBottomOffset() + defDisp.getWindowBottomOffset(), isTff ); |
---|
| 675 | } |
---|
| 676 | |
---|
| 677 | // update POC of display order |
---|
| 678 | #if H_MV |
---|
| 679 | m_pocLastDisplay[decIdx] = pcPic->getPOC(); |
---|
[608] | 680 | #else |
---|
[655] | 681 | m_iPOCLastDisplay = pcPicBottom->getPOC(); |
---|
[608] | 682 | #endif |
---|
[655] | 683 | |
---|
| 684 | // erase non-referenced picture in the reference picture list after display |
---|
| 685 | if ( !pcPicTop->getSlice(0)->isReferenced() && pcPicTop->getReconMark() == true ) |
---|
| 686 | { |
---|
| 687 | #if !DYN_REF_FREE |
---|
| 688 | pcPicTop->setReconMark(false); |
---|
| 689 | |
---|
| 690 | // mark it should be extended later |
---|
| 691 | pcPicTop->getPicYuvRec()->setBorderExtension( false ); |
---|
| 692 | |
---|
| 693 | #else |
---|
| 694 | pcPicTop->destroy(); |
---|
| 695 | pcListPic->erase( iterPic ); |
---|
| 696 | iterPic = pcListPic->begin(); // to the beginning, non-efficient way, have to be revised! |
---|
| 697 | continue; |
---|
| 698 | #endif |
---|
| 699 | } |
---|
| 700 | if ( !pcPicBottom->getSlice(0)->isReferenced() && pcPicBottom->getReconMark() == true ) |
---|
| 701 | { |
---|
| 702 | #if !DYN_REF_FREE |
---|
| 703 | pcPicBottom->setReconMark(false); |
---|
| 704 | |
---|
| 705 | // mark it should be extended later |
---|
| 706 | pcPicBottom->getPicYuvRec()->setBorderExtension( false ); |
---|
| 707 | |
---|
| 708 | #else |
---|
| 709 | pcPicBottom->destroy(); |
---|
| 710 | pcListPic->erase( iterPic ); |
---|
| 711 | iterPic = pcListPic->begin(); // to the beginning, non-efficient way, have to be revised! |
---|
| 712 | continue; |
---|
| 713 | #endif |
---|
| 714 | } |
---|
| 715 | pcPicTop->setOutputMark(false); |
---|
| 716 | pcPicBottom->setOutputMark(false); |
---|
[56] | 717 | } |
---|
[655] | 718 | } |
---|
| 719 | } |
---|
| 720 | else if (!pcPic->isField()) //Frame Decoding |
---|
| 721 | { |
---|
| 722 | iterPic = pcListPic->begin(); |
---|
| 723 | while (iterPic != pcListPic->end()) |
---|
| 724 | { |
---|
| 725 | pcPic = *(iterPic); |
---|
| 726 | |
---|
[608] | 727 | #if H_MV |
---|
[964] | 728 | if(pcPic->getOutputMark() && pcPic->getPOC() > m_pocLastDisplay[decIdx] && |
---|
| 729 | (numPicsNotYetDisplayed > numReorderPicsHighestTid || dpbFullness > maxDecPicBufferingHighestTid)) |
---|
[655] | 730 | #else |
---|
[964] | 731 | if(pcPic->getOutputMark() && pcPic->getPOC() > m_iPOCLastDisplay && |
---|
| 732 | (numPicsNotYetDisplayed > numReorderPicsHighestTid || dpbFullness > maxDecPicBufferingHighestTid)) |
---|
[655] | 733 | #endif |
---|
| 734 | { |
---|
| 735 | // write to file |
---|
| 736 | numPicsNotYetDisplayed--; |
---|
[964] | 737 | if(pcPic->getSlice(0)->isReferenced() == false) |
---|
| 738 | { |
---|
| 739 | dpbFullness--; |
---|
| 740 | } |
---|
[655] | 741 | #if H_MV |
---|
| 742 | if ( m_pchReconFiles[decIdx] ) |
---|
[608] | 743 | #else |
---|
[655] | 744 | if ( m_pchReconFile ) |
---|
[608] | 745 | #endif |
---|
[655] | 746 | { |
---|
| 747 | const Window &conf = pcPic->getConformanceWindow(); |
---|
| 748 | const Window &defDisp = m_respectDefDispWindow ? pcPic->getDefDisplayWindow() : Window(); |
---|
| 749 | #if H_MV |
---|
| 750 | assert( conf .getScaledFlag() ); |
---|
| 751 | assert( defDisp.getScaledFlag() ); |
---|
[964] | 752 | #if ENC_DEC_TRACE |
---|
| 753 | g_bJustDoIt = true; |
---|
| 754 | writeToTraceFile( "OutputPic Poc" , pcPic->getPOC (), g_decTracePicOutput ); |
---|
| 755 | writeToTraceFile( "OutputPic LayerId", pcPic->getLayerId(), g_decTracePicOutput ); |
---|
| 756 | g_bJustDoIt = false; |
---|
| 757 | #endif |
---|
[655] | 758 | m_tVideoIOYuvReconFile[decIdx]->write( pcPic->getPicYuvRec(), |
---|
| 759 | #else |
---|
| 760 | m_cTVideoIOYuvReconFile.write( pcPic->getPicYuvRec(), |
---|
| 761 | #endif |
---|
| 762 | conf.getWindowLeftOffset() + defDisp.getWindowLeftOffset(), |
---|
| 763 | conf.getWindowRightOffset() + defDisp.getWindowRightOffset(), |
---|
| 764 | conf.getWindowTopOffset() + defDisp.getWindowTopOffset(), |
---|
| 765 | conf.getWindowBottomOffset() + defDisp.getWindowBottomOffset() ); |
---|
| 766 | } |
---|
[56] | 767 | |
---|
[655] | 768 | // update POC of display order |
---|
| 769 | #if H_MV |
---|
| 770 | m_pocLastDisplay[decIdx] = pcPic->getPOC(); |
---|
| 771 | #else |
---|
| 772 | m_iPOCLastDisplay = pcPic->getPOC(); |
---|
| 773 | #endif |
---|
[56] | 774 | |
---|
[655] | 775 | // erase non-referenced picture in the reference picture list after display |
---|
| 776 | if ( !pcPic->getSlice(0)->isReferenced() && pcPic->getReconMark() == true ) |
---|
| 777 | { |
---|
| 778 | #if !DYN_REF_FREE |
---|
| 779 | pcPic->setReconMark(false); |
---|
| 780 | |
---|
| 781 | // mark it should be extended later |
---|
| 782 | pcPic->getPicYuvRec()->setBorderExtension( false ); |
---|
| 783 | |
---|
[56] | 784 | #else |
---|
[655] | 785 | pcPic->destroy(); |
---|
| 786 | pcListPic->erase( iterPic ); |
---|
| 787 | iterPic = pcListPic->begin(); // to the beginning, non-efficient way, have to be revised! |
---|
| 788 | continue; |
---|
[56] | 789 | #endif |
---|
[655] | 790 | } |
---|
| 791 | pcPic->setOutputMark(false); |
---|
[976] | 792 | #if H_MV |
---|
[964] | 793 | pcPic->setPicOutputFlag(false); |
---|
| 794 | #endif |
---|
[56] | 795 | } |
---|
[655] | 796 | |
---|
| 797 | iterPic++; |
---|
[56] | 798 | } |
---|
[2] | 799 | } |
---|
| 800 | } |
---|
| 801 | /** \param pcListPic list of pictures to be written to file |
---|
| 802 | \todo DYN_REF_FREE should be revised |
---|
| 803 | */ |
---|
[608] | 804 | #if H_MV |
---|
| 805 | Void TAppDecTop::xFlushOutput( TComList<TComPic*>* pcListPic, Int decIdx ) |
---|
| 806 | #else |
---|
| 807 | Void TAppDecTop::xFlushOutput( TComList<TComPic*>* pcListPic ) |
---|
| 808 | #endif |
---|
[2] | 809 | { |
---|
[872] | 810 | if(!pcListPic || pcListPic->empty()) |
---|
[56] | 811 | { |
---|
| 812 | return; |
---|
[655] | 813 | } |
---|
[2] | 814 | TComList<TComPic*>::iterator iterPic = pcListPic->begin(); |
---|
[655] | 815 | |
---|
[56] | 816 | iterPic = pcListPic->begin(); |
---|
[655] | 817 | TComPic* pcPic = *(iterPic); |
---|
[56] | 818 | |
---|
[655] | 819 | if (pcPic->isField()) //Field Decoding |
---|
[2] | 820 | { |
---|
[655] | 821 | TComList<TComPic*>::iterator endPic = pcListPic->end(); |
---|
| 822 | endPic--; |
---|
| 823 | TComPic *pcPicTop, *pcPicBottom = NULL; |
---|
| 824 | while (iterPic != endPic) |
---|
[2] | 825 | { |
---|
[655] | 826 | pcPicTop = *(iterPic); |
---|
| 827 | iterPic++; |
---|
| 828 | pcPicBottom = *(iterPic); |
---|
| 829 | |
---|
| 830 | if ( pcPicTop->getOutputMark() && pcPicBottom->getOutputMark() && !(pcPicTop->getPOC()%2) && (pcPicBottom->getPOC() == pcPicTop->getPOC()+1) ) |
---|
| 831 | { |
---|
| 832 | // write to file |
---|
[608] | 833 | #if H_MV |
---|
| 834 | if ( m_pchReconFiles[decIdx] ) |
---|
| 835 | #else |
---|
[655] | 836 | if ( m_pchReconFile ) |
---|
[608] | 837 | #endif |
---|
[655] | 838 | { |
---|
| 839 | const Window &conf = pcPicTop->getConformanceWindow(); |
---|
| 840 | const Window &defDisp = m_respectDefDispWindow ? pcPicTop->getDefDisplayWindow() : Window(); |
---|
| 841 | const Bool isTff = pcPicTop->isTopField(); |
---|
[608] | 842 | #if H_MV |
---|
[622] | 843 | assert( conf .getScaledFlag() ); |
---|
| 844 | assert( defDisp.getScaledFlag() ); |
---|
[964] | 845 | #if ENC_DEC_TRACE |
---|
| 846 | g_bJustDoIt = true; |
---|
| 847 | writeToTraceFile( "OutputPic Poc" , pcPic->getPOC (), g_decTracePicOutput ); |
---|
| 848 | writeToTraceFile( "OutputPic LayerId", pcPic->getLayerId(), g_decTracePicOutput ); |
---|
| 849 | g_bJustDoIt = false; |
---|
| 850 | #endif |
---|
[655] | 851 | m_tVideoIOYuvReconFile[decIdx]->write( pcPicTop->getPicYuvRec(), pcPicBottom->getPicYuvRec(), |
---|
| 852 | #else |
---|
| 853 | m_cTVideoIOYuvReconFile.write( pcPicTop->getPicYuvRec(), pcPicBottom->getPicYuvRec(), |
---|
[622] | 854 | #endif |
---|
[655] | 855 | conf.getWindowLeftOffset() + defDisp.getWindowLeftOffset(), |
---|
| 856 | conf.getWindowRightOffset() + defDisp.getWindowRightOffset(), |
---|
| 857 | conf.getWindowTopOffset() + defDisp.getWindowTopOffset(), |
---|
| 858 | conf.getWindowBottomOffset() + defDisp.getWindowBottomOffset(), isTff ); |
---|
| 859 | } |
---|
| 860 | |
---|
| 861 | // update POC of display order |
---|
| 862 | #if H_MV |
---|
| 863 | m_pocLastDisplay[decIdx] = pcPic->getPOC(); |
---|
[608] | 864 | #else |
---|
[655] | 865 | m_iPOCLastDisplay = pcPicBottom->getPOC(); |
---|
| 866 | #endif |
---|
| 867 | // erase non-referenced picture in the reference picture list after display |
---|
| 868 | if ( !pcPicTop->getSlice(0)->isReferenced() && pcPicTop->getReconMark() == true ) |
---|
| 869 | { |
---|
| 870 | #if !DYN_REF_FREE |
---|
| 871 | pcPicTop->setReconMark(false); |
---|
| 872 | |
---|
| 873 | // mark it should be extended later |
---|
| 874 | pcPicTop->getPicYuvRec()->setBorderExtension( false ); |
---|
| 875 | |
---|
| 876 | #else |
---|
| 877 | pcPicTop->destroy(); |
---|
| 878 | pcListPic->erase( iterPic ); |
---|
| 879 | iterPic = pcListPic->begin(); // to the beginning, non-efficient way, have to be revised! |
---|
| 880 | continue; |
---|
[608] | 881 | #endif |
---|
[655] | 882 | } |
---|
| 883 | if ( !pcPicBottom->getSlice(0)->isReferenced() && pcPicBottom->getReconMark() == true ) |
---|
| 884 | { |
---|
| 885 | #if !DYN_REF_FREE |
---|
| 886 | pcPicBottom->setReconMark(false); |
---|
| 887 | |
---|
| 888 | // mark it should be extended later |
---|
| 889 | pcPicBottom->getPicYuvRec()->setBorderExtension( false ); |
---|
| 890 | |
---|
| 891 | #else |
---|
| 892 | pcPicBottom->destroy(); |
---|
| 893 | pcListPic->erase( iterPic ); |
---|
| 894 | iterPic = pcListPic->begin(); // to the beginning, non-efficient way, have to be revised! |
---|
| 895 | continue; |
---|
| 896 | #endif |
---|
| 897 | } |
---|
| 898 | pcPicTop->setOutputMark(false); |
---|
| 899 | pcPicBottom->setOutputMark(false); |
---|
| 900 | |
---|
| 901 | #if !DYN_REF_FREE |
---|
| 902 | if(pcPicTop) |
---|
| 903 | { |
---|
| 904 | pcPicTop->destroy(); |
---|
| 905 | delete pcPicTop; |
---|
| 906 | pcPicTop = NULL; |
---|
| 907 | } |
---|
| 908 | #endif |
---|
[2] | 909 | } |
---|
[655] | 910 | } |
---|
| 911 | if(pcPicBottom) |
---|
| 912 | { |
---|
| 913 | pcPicBottom->destroy(); |
---|
| 914 | delete pcPicBottom; |
---|
| 915 | pcPicBottom = NULL; |
---|
| 916 | } |
---|
| 917 | } |
---|
| 918 | else //Frame decoding |
---|
| 919 | { |
---|
| 920 | while (iterPic != pcListPic->end()) |
---|
| 921 | { |
---|
| 922 | pcPic = *(iterPic); |
---|
[56] | 923 | |
---|
[655] | 924 | if ( pcPic->getOutputMark() ) |
---|
| 925 | { |
---|
| 926 | // write to file |
---|
[608] | 927 | #if H_MV |
---|
[655] | 928 | if ( m_pchReconFiles[decIdx] ) |
---|
| 929 | #else |
---|
| 930 | if ( m_pchReconFile ) |
---|
| 931 | #endif |
---|
| 932 | { |
---|
| 933 | const Window &conf = pcPic->getConformanceWindow(); |
---|
| 934 | const Window &defDisp = m_respectDefDispWindow ? pcPic->getDefDisplayWindow() : Window(); |
---|
| 935 | #if H_MV |
---|
| 936 | assert( conf .getScaledFlag() ); |
---|
| 937 | assert( defDisp.getScaledFlag() ); |
---|
[964] | 938 | #if ENC_DEC_TRACE |
---|
| 939 | g_bJustDoIt = true; |
---|
| 940 | writeToTraceFile( "OutputPic Poc" , pcPic->getPOC (), g_decTracePicOutput ); |
---|
| 941 | writeToTraceFile( "OutputPic LayerId", pcPic->getLayerId(), g_decTracePicOutput ); |
---|
| 942 | g_bJustDoIt = false; |
---|
| 943 | #endif |
---|
[655] | 944 | m_tVideoIOYuvReconFile[decIdx]->write( pcPic->getPicYuvRec(), |
---|
| 945 | #else |
---|
| 946 | m_cTVideoIOYuvReconFile.write( pcPic->getPicYuvRec(), |
---|
| 947 | #endif |
---|
| 948 | conf.getWindowLeftOffset() + defDisp.getWindowLeftOffset(), |
---|
| 949 | conf.getWindowRightOffset() + defDisp.getWindowRightOffset(), |
---|
| 950 | conf.getWindowTopOffset() + defDisp.getWindowTopOffset(), |
---|
| 951 | conf.getWindowBottomOffset() + defDisp.getWindowBottomOffset() ); |
---|
| 952 | } |
---|
| 953 | |
---|
| 954 | // update POC of display order |
---|
| 955 | #if H_MV |
---|
[608] | 956 | m_pocLastDisplay[decIdx] = pcPic->getPOC(); |
---|
| 957 | #else |
---|
[655] | 958 | m_iPOCLastDisplay = pcPic->getPOC(); |
---|
[608] | 959 | #endif |
---|
[655] | 960 | |
---|
| 961 | // erase non-referenced picture in the reference picture list after display |
---|
| 962 | if ( !pcPic->getSlice(0)->isReferenced() && pcPic->getReconMark() == true ) |
---|
| 963 | { |
---|
[56] | 964 | #if !DYN_REF_FREE |
---|
[655] | 965 | pcPic->setReconMark(false); |
---|
| 966 | |
---|
| 967 | // mark it should be extended later |
---|
| 968 | pcPic->getPicYuvRec()->setBorderExtension( false ); |
---|
| 969 | |
---|
[56] | 970 | #else |
---|
[655] | 971 | pcPic->destroy(); |
---|
| 972 | pcListPic->erase( iterPic ); |
---|
| 973 | iterPic = pcListPic->begin(); // to the beginning, non-efficient way, have to be revised! |
---|
| 974 | continue; |
---|
[56] | 975 | #endif |
---|
[655] | 976 | } |
---|
| 977 | pcPic->setOutputMark(false); |
---|
[976] | 978 | #if H_MV |
---|
[964] | 979 | pcPic->setPicOutputFlag(false); |
---|
| 980 | #endif |
---|
[2] | 981 | } |
---|
[608] | 982 | #if !H_MV |
---|
| 983 | #if !DYN_REF_FREE |
---|
[655] | 984 | if(pcPic) |
---|
| 985 | { |
---|
| 986 | pcPic->destroy(); |
---|
| 987 | delete pcPic; |
---|
| 988 | pcPic = NULL; |
---|
| 989 | } |
---|
| 990 | #endif |
---|
| 991 | #endif |
---|
| 992 | iterPic++; |
---|
[608] | 993 | } |
---|
[2] | 994 | } |
---|
[608] | 995 | #if H_MV |
---|
| 996 | m_pocLastDisplay[decIdx] = -MAX_INT; |
---|
| 997 | #else |
---|
[56] | 998 | pcListPic->clear(); |
---|
[608] | 999 | m_iPOCLastDisplay = -MAX_INT; |
---|
| 1000 | #endif |
---|
[2] | 1001 | } |
---|
[608] | 1002 | |
---|
| 1003 | /** \param nalu Input nalu to check whether its LayerId is within targetDecLayerIdSet |
---|
| 1004 | */ |
---|
| 1005 | Bool TAppDecTop::isNaluWithinTargetDecLayerIdSet( InputNALUnit* nalu ) |
---|
[2] | 1006 | { |
---|
[608] | 1007 | if ( m_targetDecLayerIdSet.size() == 0 ) // By default, the set is empty, meaning all LayerIds are allowed |
---|
[2] | 1008 | { |
---|
[608] | 1009 | return true; |
---|
[2] | 1010 | } |
---|
[608] | 1011 | for (std::vector<Int>::iterator it = m_targetDecLayerIdSet.begin(); it != m_targetDecLayerIdSet.end(); it++) |
---|
| 1012 | { |
---|
| 1013 | #if H_MV |
---|
| 1014 | if ( nalu->m_layerId == (*it) ) |
---|
[81] | 1015 | #else |
---|
[608] | 1016 | if ( nalu->m_reservedZero6Bits == (*it) ) |
---|
[81] | 1017 | #endif |
---|
[56] | 1018 | { |
---|
[608] | 1019 | return true; |
---|
[56] | 1020 | } |
---|
| 1021 | } |
---|
[608] | 1022 | return false; |
---|
[2] | 1023 | } |
---|
| 1024 | |
---|
[608] | 1025 | #if H_MV |
---|
| 1026 | Int TAppDecTop::xGetDecoderIdx( Int layerId, Bool createFlag /*= false */ ) |
---|
| 1027 | { |
---|
| 1028 | Int decIdx = -1; |
---|
[738] | 1029 | |
---|
| 1030 | if ( layerId > MAX_NUM_LAYER_IDS-1 ) |
---|
| 1031 | { |
---|
| 1032 | return decIdx; |
---|
| 1033 | } |
---|
| 1034 | |
---|
[608] | 1035 | if ( m_layerIdToDecIdx[ layerId ] != -1 ) |
---|
| 1036 | { |
---|
| 1037 | decIdx = m_layerIdToDecIdx[ layerId ]; |
---|
[210] | 1038 | } |
---|
| 1039 | else |
---|
[608] | 1040 | { |
---|
| 1041 | assert ( createFlag ); |
---|
| 1042 | assert( m_numDecoders < MAX_NUM_LAYERS ); |
---|
[210] | 1043 | |
---|
[608] | 1044 | decIdx = m_numDecoders; |
---|
| 1045 | |
---|
| 1046 | // Init decoder |
---|
| 1047 | m_tDecTop[ decIdx ] = new TDecTop; |
---|
| 1048 | m_tDecTop[ decIdx ]->create(); |
---|
| 1049 | m_tDecTop[ decIdx ]->init( ); |
---|
| 1050 | m_tDecTop[ decIdx ]->setLayerId( layerId ); |
---|
| 1051 | m_tDecTop[ decIdx ]->setDecodedPictureHashSEIEnabled(m_decodedPictureHashSEIEnabled); |
---|
| 1052 | m_tDecTop[ decIdx ]->setIvPicLists( &m_ivPicLists ); |
---|
[738] | 1053 | m_tDecTop[ decIdx ]->setLayerInitilizedFlags( m_layerInitilizedFlags ); |
---|
[964] | 1054 | m_tDecTop[ decIdx ]->setTargetOptLayerSetIdx( m_targetOptLayerSetIdx ); |
---|
[1196] | 1055 | #if H_3D |
---|
[1179] | 1056 | m_tDecTop[ decIdx ]->setProfileIdc ( ); |
---|
| 1057 | #endif |
---|
[738] | 1058 | |
---|
[608] | 1059 | #if H_3D |
---|
| 1060 | m_tDecTop[ decIdx ]->setCamParsCollector( &m_cCamParsCollector ); |
---|
[210] | 1061 | #endif |
---|
[2] | 1062 | |
---|
[608] | 1063 | // append pic list of new decoder to PicLists |
---|
| 1064 | assert( m_ivPicLists.size() == m_numDecoders ); |
---|
| 1065 | m_ivPicLists.push_back( m_tDecTop[ decIdx ]->getListPic() ); |
---|
[2] | 1066 | |
---|
[608] | 1067 | // create recon file related stuff |
---|
| 1068 | Char* pchTempFilename = NULL; |
---|
| 1069 | if ( m_pchReconFile ) |
---|
| 1070 | { |
---|
| 1071 | Char buffer[4]; |
---|
| 1072 | sprintf(buffer,"_%i", layerId ); |
---|
| 1073 | assert ( m_pchReconFile ); |
---|
| 1074 | xAppendToFileNameEnd( m_pchReconFile , buffer, pchTempFilename ); |
---|
| 1075 | assert( m_pchReconFiles.size() == m_numDecoders ); |
---|
[2] | 1076 | } |
---|
[210] | 1077 | |
---|
[608] | 1078 | m_pchReconFiles.push_back( pchTempFilename ); |
---|
[296] | 1079 | |
---|
[608] | 1080 | m_tVideoIOYuvReconFile[ decIdx ] = new TVideoIOYuv; |
---|
| 1081 | m_reconOpen [ decIdx ] = false; |
---|
[443] | 1082 | |
---|
[608] | 1083 | // set others |
---|
| 1084 | m_pocLastDisplay [ decIdx ] = -MAX_INT; |
---|
| 1085 | m_layerIdToDecIdx [ layerId ] = decIdx; |
---|
[296] | 1086 | |
---|
[608] | 1087 | m_numDecoders++; |
---|
| 1088 | }; |
---|
| 1089 | return decIdx; |
---|
[964] | 1090 | |
---|
[296] | 1091 | } |
---|
[964] | 1092 | |
---|
| 1093 | Void TAppDecTop::xMarkForOutput( Bool allLayersDecoded, Int pocLastPic, Int layerIdLastPic ) |
---|
| 1094 | { |
---|
| 1095 | vector<Int> targetOptLayerIdList = m_vps->getTargetOptLayerIdList( m_targetOptLayerSetIdx ); |
---|
| 1096 | |
---|
| 1097 | if (m_vps->getAltOutputLayerFlagVar( m_targetOptLayerSetIdx ) ) |
---|
| 1098 | { |
---|
| 1099 | assert( targetOptLayerIdList.size() == 1 ); |
---|
| 1100 | Int targetLayerId = targetOptLayerIdList[0]; |
---|
| 1101 | |
---|
| 1102 | TComPic* curPic = m_ivPicLists.getPic( layerIdLastPic, pocLastPic ); |
---|
| 1103 | assert( curPic != NULL ); |
---|
| 1104 | |
---|
| 1105 | if ( layerIdLastPic == targetLayerId ) |
---|
| 1106 | { |
---|
| 1107 | if ( curPic->getPicOutputFlag() ) |
---|
| 1108 | { |
---|
| 1109 | curPic->setOutputMark( true ); |
---|
| 1110 | } |
---|
| 1111 | else |
---|
| 1112 | { |
---|
| 1113 | xMarkAltOutPic( targetLayerId, pocLastPic ); |
---|
| 1114 | } |
---|
| 1115 | m_markedForOutput = true; |
---|
| 1116 | } |
---|
| 1117 | else if ( ( layerIdLastPic > targetLayerId || allLayersDecoded ) && !m_markedForOutput ) |
---|
| 1118 | { |
---|
| 1119 | xMarkAltOutPic( targetLayerId, pocLastPic ); |
---|
| 1120 | } |
---|
| 1121 | |
---|
| 1122 | if ( allLayersDecoded ) |
---|
| 1123 | { |
---|
| 1124 | m_markedForOutput = false; |
---|
| 1125 | } |
---|
| 1126 | } |
---|
| 1127 | else |
---|
| 1128 | { |
---|
| 1129 | for( Int dI = 0; dI < m_numDecoders; dI++ ) |
---|
| 1130 | { |
---|
| 1131 | Int layerId = m_tDecTop[dI]->getLayerId(); |
---|
| 1132 | TComPic* curPic = m_ivPicLists.getPic( layerId, pocLastPic ); |
---|
| 1133 | if ( curPic != NULL ) |
---|
| 1134 | { |
---|
| 1135 | if ( curPic->getReconMark() ) |
---|
| 1136 | { |
---|
| 1137 | Bool isTargetOptLayer = std::find(targetOptLayerIdList.begin(), targetOptLayerIdList.end(), layerId) != targetOptLayerIdList.end(); |
---|
| 1138 | curPic->setOutputMark( isTargetOptLayer ? curPic->getPicOutputFlag() : false ); |
---|
| 1139 | } |
---|
| 1140 | } |
---|
| 1141 | } |
---|
| 1142 | } |
---|
| 1143 | } |
---|
[976] | 1144 | |
---|
| 1145 | Void TAppDecTop::xMarkAltOutPic( Int targetOutputLayer, Int pocLastPic ) |
---|
| 1146 | { |
---|
| 1147 | Int optLayerIdxInVps = m_vps->getLayerIdInNuh( targetOutputLayer ); |
---|
| 1148 | Int highestNuhLayerId = -1; |
---|
| 1149 | TComPic* picWithHighestNuhLayerId = NULL; |
---|
| 1150 | for (Int dIdx = 0; dIdx < m_numDecoders; dIdx++) |
---|
| 1151 | { |
---|
| 1152 | Int curLayerId = m_tDecTop[dIdx]->getLayerId(); |
---|
| 1153 | Int curLayerIdxInVps = m_vps->getLayerIdInNuh( curLayerId ); |
---|
[1066] | 1154 | if ( m_vps->getDependencyFlag(optLayerIdxInVps, curLayerIdxInVps ) ) |
---|
[976] | 1155 | { |
---|
| 1156 | TComPic* curPic = m_ivPicLists.getPic( curLayerId, pocLastPic ); |
---|
| 1157 | if (curPic != NULL) |
---|
| 1158 | { |
---|
| 1159 | if (curPic->getReconMark() && curPic->getPicOutputFlag() ) |
---|
| 1160 | { |
---|
| 1161 | curPic->setOutputMark ( false ); |
---|
| 1162 | curPic->setPicOutputFlag( false ); |
---|
| 1163 | if ( curLayerId > highestNuhLayerId) |
---|
| 1164 | { |
---|
| 1165 | highestNuhLayerId = curLayerId ; |
---|
| 1166 | picWithHighestNuhLayerId = curPic; |
---|
| 1167 | } |
---|
| 1168 | } |
---|
| 1169 | } |
---|
| 1170 | } |
---|
| 1171 | } |
---|
| 1172 | if ( picWithHighestNuhLayerId != NULL ) |
---|
| 1173 | { |
---|
| 1174 | picWithHighestNuhLayerId->setPicOutputFlag(true); |
---|
| 1175 | picWithHighestNuhLayerId->setOutputMark (true); |
---|
| 1176 | } |
---|
| 1177 | } |
---|
| 1178 | |
---|
[296] | 1179 | #endif |
---|
[56] | 1180 | //! \} |
---|