[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 | * |
---|
[608] | 6 | * Copyright (c) 2010-2013, 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 | { |
---|
| 62 | ::memset (m_abDecFlag, 0, sizeof (m_abDecFlag)); |
---|
[608] | 63 | #if H_MV |
---|
| 64 | for (Int i = 0; i < MAX_NUM_LAYER_IDS; i++) m_layerIdToDecIdx[i] = -1; |
---|
| 65 | #endif |
---|
| 66 | #if H_3D |
---|
| 67 | m_pScaleOffsetFile = 0; |
---|
| 68 | #endif |
---|
[2] | 69 | } |
---|
| 70 | |
---|
| 71 | Void TAppDecTop::create() |
---|
| 72 | { |
---|
| 73 | } |
---|
| 74 | |
---|
| 75 | Void TAppDecTop::destroy() |
---|
| 76 | { |
---|
[608] | 77 | if (m_pchBitstreamFile) |
---|
| 78 | { |
---|
| 79 | free (m_pchBitstreamFile); |
---|
| 80 | m_pchBitstreamFile = NULL; |
---|
| 81 | } |
---|
| 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 |
---|
| 92 | if (m_pchReconFile) |
---|
| 93 | { |
---|
| 94 | free (m_pchReconFile); |
---|
| 95 | m_pchReconFile = NULL; |
---|
| 96 | } |
---|
| 97 | #if H_3D |
---|
| 98 | if (m_pchScaleOffsetFile) |
---|
| 99 | { |
---|
| 100 | free (m_pchScaleOffsetFile); |
---|
| 101 | m_pchScaleOffsetFile = NULL; |
---|
| 102 | } |
---|
| 103 | #endif |
---|
[2] | 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 | { |
---|
[608] | 120 | Int poc; |
---|
| 121 | #if H_MV |
---|
| 122 | poc = -1; |
---|
[77] | 123 | #endif |
---|
[608] | 124 | TComList<TComPic*>* pcListPic = NULL; |
---|
[210] | 125 | |
---|
[56] | 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 | } |
---|
[2] | 132 | |
---|
[608] | 133 | #if H_3D |
---|
[56] | 134 | if( m_pchScaleOffsetFile ) |
---|
| 135 | { |
---|
| 136 | m_pScaleOffsetFile = ::fopen( m_pchScaleOffsetFile, "wt" ); |
---|
| 137 | AOF( m_pScaleOffsetFile ); |
---|
| 138 | } |
---|
| 139 | m_cCamParsCollector.init( m_pScaleOffsetFile ); |
---|
[608] | 140 | #endif |
---|
[56] | 141 | InputByteStream bytestream(bitstreamFile); |
---|
| 142 | |
---|
[608] | 143 | // create & initialize internal classes |
---|
| 144 | xCreateDecLib(); |
---|
| 145 | xInitDecLib (); |
---|
| 146 | #if !H_MV |
---|
| 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) |
---|
| 151 | #else |
---|
| 152 | #if H_3D |
---|
| 153 | Int pocCurrPic = -MAX_INT; |
---|
| 154 | Int pocLastPic = -MAX_INT; |
---|
| 155 | #endif |
---|
| 156 | |
---|
| 157 | Int layerIdCurrPic = 0; |
---|
| 158 | |
---|
| 159 | Int decIdxLastPic = 0; |
---|
| 160 | Int decIdxCurrPic = 0; |
---|
| 161 | |
---|
| 162 | Bool firstSlice = true; |
---|
| 163 | #endif |
---|
| 164 | |
---|
[56] | 165 | while (!!bitstreamFile) |
---|
[2] | 166 | { |
---|
[56] | 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(); |
---|
[608] | 172 | #if H_MV |
---|
| 173 | #if ENC_DEC_TRACE |
---|
| 174 | Int64 symCount = g_nSymbolCounter; |
---|
| 175 | #endif |
---|
| 176 | #endif |
---|
[56] | 177 | AnnexBStats stats = AnnexBStats(); |
---|
[608] | 178 | #if !H_MV |
---|
| 179 | Bool bPreviousPictureDecoded = false; |
---|
| 180 | #endif |
---|
| 181 | |
---|
[56] | 182 | vector<uint8_t> nalUnit; |
---|
| 183 | InputNALUnit nalu; |
---|
| 184 | byteStreamNALUnit(bytestream, nalUnit, stats); |
---|
| 185 | |
---|
| 186 | // call actual decoding function |
---|
[608] | 187 | Bool bNewPicture = false; |
---|
| 188 | #if H_MV |
---|
| 189 | Bool newSliceDiffPoc = false; |
---|
| 190 | Bool newSliceDiffLayer = false; |
---|
| 191 | #if H_3D |
---|
| 192 | Bool allLayersDecoded = false; |
---|
| 193 | #endif |
---|
| 194 | #endif |
---|
[56] | 195 | if (nalUnit.empty()) |
---|
[2] | 196 | { |
---|
[56] | 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"); |
---|
[2] | 203 | } |
---|
| 204 | else |
---|
| 205 | { |
---|
[56] | 206 | read(nalu, nalUnit); |
---|
[608] | 207 | #if H_MV |
---|
| 208 | Int decIdx = xGetDecoderIdx( nalu.m_layerId , true ); |
---|
[77] | 209 | |
---|
[608] | 210 | if( (m_iMaxTemporalLayer >= 0 && nalu.m_temporalId > m_iMaxTemporalLayer) || !isNaluWithinTargetDecLayerIdSet(&nalu) ) |
---|
[77] | 211 | { |
---|
[608] | 212 | bNewPicture = false; |
---|
[77] | 213 | } |
---|
[210] | 214 | else |
---|
[608] | 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 ) |
---|
[210] | 226 | { |
---|
[608] | 227 | layerIdCurrPic = nalu.m_layerId; |
---|
| 228 | #if H_3D |
---|
| 229 | pocCurrPic = m_tDecTop[decIdx]->getCurrPoc(); |
---|
| 230 | #endif |
---|
| 231 | decIdxCurrPic = decIdx; |
---|
| 232 | firstSlice = false; |
---|
[210] | 233 | } |
---|
[608] | 234 | |
---|
| 235 | if ( bNewPicture || !bitstreamFile ) |
---|
| 236 | { |
---|
| 237 | layerIdCurrPic = nalu.m_layerId; |
---|
| 238 | #if H_3D |
---|
| 239 | pocLastPic = pocCurrPic; |
---|
| 240 | pocCurrPic = m_tDecTop[decIdx]->getCurrPoc(); |
---|
| 241 | #endif |
---|
| 242 | decIdxLastPic = decIdxCurrPic; |
---|
| 243 | decIdxCurrPic = decIdx; |
---|
| 244 | #if H_3D |
---|
| 245 | allLayersDecoded = ( pocCurrPic != pocLastPic ); |
---|
| 246 | #endif |
---|
[210] | 247 | } |
---|
| 248 | |
---|
[608] | 249 | |
---|
[210] | 250 | #else |
---|
[608] | 251 | if( (m_iMaxTemporalLayer >= 0 && nalu.m_temporalId > m_iMaxTemporalLayer) || !isNaluWithinTargetDecLayerIdSet(&nalu) ) |
---|
[210] | 252 | { |
---|
[608] | 253 | if(bPreviousPictureDecoded) |
---|
[210] | 254 | { |
---|
[608] | 255 | bNewPicture = true; |
---|
| 256 | bPreviousPictureDecoded = false; |
---|
[210] | 257 | } |
---|
| 258 | else |
---|
| 259 | { |
---|
[608] | 260 | bNewPicture = false; |
---|
[210] | 261 | } |
---|
| 262 | } |
---|
[608] | 263 | else |
---|
[2] | 264 | { |
---|
[608] | 265 | bNewPicture = m_cTDecTop.decode(nalu, m_iSkipFrame, m_iPOCLastDisplay); |
---|
[56] | 266 | #endif |
---|
[608] | 267 | if (bNewPicture) |
---|
[42] | 268 | { |
---|
[56] | 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(); |
---|
[608] | 276 | #if ENC_DEC_TRACE |
---|
| 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 |
---|
[210] | 282 | } |
---|
[608] | 283 | else |
---|
| 284 | { |
---|
| 285 | g_disableHLSTrace = true; // Trancing of second parsing of SH is not carried out |
---|
| 286 | } |
---|
| 287 | #else |
---|
| 288 | g_nSymbolCounter = symCount; |
---|
[210] | 289 | #endif |
---|
[608] | 290 | #endif |
---|
[42] | 291 | } |
---|
[608] | 292 | #if !H_MV |
---|
| 293 | bPreviousPictureDecoded = true; |
---|
| 294 | #endif |
---|
[42] | 295 | } |
---|
[56] | 296 | } |
---|
[608] | 297 | if (bNewPicture || !bitstreamFile) |
---|
[56] | 298 | { |
---|
[608] | 299 | #if H_MV |
---|
| 300 | assert( decIdxLastPic != -1 ); |
---|
| 301 | m_tDecTop[decIdxLastPic]->endPicDecoding(poc, pcListPic, m_targetDecLayerIdSet ); |
---|
| 302 | #else |
---|
| 303 | m_cTDecTop.executeLoopFilters(poc, pcListPic); |
---|
| 304 | #endif |
---|
[56] | 305 | } |
---|
[608] | 306 | #if H_3D |
---|
| 307 | if ( allLayersDecoded || !bitstreamFile ) |
---|
[56] | 308 | { |
---|
[608] | 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 | #if MTK_SONY_PROGRESSIVE_MV_COMPRESSION_E0170 |
---|
| 314 | picLastCoded->compressMotion(1); |
---|
[210] | 315 | #else |
---|
[608] | 316 | picLastCoded->compressMotion(); |
---|
[210] | 317 | #endif |
---|
[608] | 318 | } |
---|
| 319 | } |
---|
| 320 | #endif |
---|
| 321 | |
---|
| 322 | if( pcListPic ) |
---|
| 323 | { |
---|
| 324 | #if H_MV |
---|
| 325 | if ( m_pchReconFiles[decIdxLastPic] && !m_reconOpen[decIdxLastPic] ) |
---|
| 326 | #else |
---|
| 327 | if ( m_pchReconFile && !recon_opened ) |
---|
| 328 | #endif |
---|
[2] | 329 | { |
---|
[608] | 330 | if (!m_outputBitDepthY) { m_outputBitDepthY = g_bitDepthY; } |
---|
| 331 | if (!m_outputBitDepthC) { m_outputBitDepthC = g_bitDepthC; } |
---|
| 332 | |
---|
| 333 | #if H_MV |
---|
| 334 | m_tVideoIOYuvReconFile[decIdxLastPic]->open( m_pchReconFiles[decIdxLastPic], true, m_outputBitDepthY, m_outputBitDepthC, g_bitDepthY, g_bitDepthC ); // write mode |
---|
| 335 | m_reconOpen[decIdxLastPic] = true; |
---|
[2] | 336 | } |
---|
[608] | 337 | if ( bNewPicture && newSliceDiffPoc && |
---|
| 338 | #else |
---|
| 339 | m_cTVideoIOYuvReconFile.open( m_pchReconFile, true, m_outputBitDepthY, m_outputBitDepthC, g_bitDepthY, g_bitDepthC ); // write mode |
---|
| 340 | recon_opened = true; |
---|
| 341 | } |
---|
| 342 | if ( bNewPicture && |
---|
| 343 | #endif |
---|
| 344 | ( nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_IDR_W_RADL |
---|
| 345 | || nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_IDR_N_LP |
---|
| 346 | || nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_BLA_N_LP |
---|
| 347 | || nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_BLA_W_RADL |
---|
| 348 | || nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_BLA_W_LP ) ) |
---|
| 349 | { |
---|
| 350 | #if H_MV |
---|
| 351 | xFlushOutput( pcListPic, decIdxLastPic ); |
---|
| 352 | #else |
---|
| 353 | xFlushOutput( pcListPic ); |
---|
| 354 | #endif |
---|
| 355 | } |
---|
[56] | 356 | // write reconstruction to file |
---|
[608] | 357 | if(bNewPicture) |
---|
[2] | 358 | { |
---|
[608] | 359 | #if H_MV |
---|
| 360 | xWriteOutput( pcListPic, decIdxLastPic, nalu.m_temporalId ); |
---|
[2] | 361 | } |
---|
| 362 | } |
---|
[608] | 363 | } |
---|
| 364 | |
---|
| 365 | #if H_3D |
---|
[57] | 366 | if( m_cCamParsCollector.isInitialized() ) |
---|
| 367 | { |
---|
| 368 | m_cCamParsCollector.setSlice( 0 ); |
---|
| 369 | } |
---|
[608] | 370 | #endif |
---|
| 371 | for(UInt decIdx = 0; decIdx < m_numDecoders; decIdx++) |
---|
[2] | 372 | { |
---|
[608] | 373 | xFlushOutput( m_tDecTop[decIdx]->getListPic(), decIdx ); |
---|
| 374 | } |
---|
| 375 | #else |
---|
| 376 | xWriteOutput( pcListPic, nalu.m_temporalId ); |
---|
| 377 | } |
---|
| 378 | } |
---|
| 379 | } |
---|
| 380 | |
---|
| 381 | xFlushOutput( pcListPic ); |
---|
| 382 | // delete buffers |
---|
| 383 | m_cTDecTop.deletePicBuffer(); |
---|
| 384 | #endif |
---|
| 385 | |
---|
| 386 | // destroy internal classes |
---|
[2] | 387 | xDestroyDecLib(); |
---|
| 388 | } |
---|
| 389 | |
---|
| 390 | // ==================================================================================================================== |
---|
| 391 | // Protected member functions |
---|
| 392 | // ==================================================================================================================== |
---|
| 393 | |
---|
[608] | 394 | Void TAppDecTop::xCreateDecLib() |
---|
| 395 | { |
---|
| 396 | #if H_MV |
---|
| 397 | // initialize global variables |
---|
| 398 | initROM(); |
---|
| 399 | #if H_3D_DIM_DMM |
---|
| 400 | initWedgeLists(); |
---|
| 401 | #endif |
---|
| 402 | #else |
---|
| 403 | // create decoder class |
---|
| 404 | m_cTDecTop.create(); |
---|
| 405 | #endif |
---|
| 406 | } |
---|
| 407 | |
---|
[2] | 408 | Void TAppDecTop::xDestroyDecLib() |
---|
| 409 | { |
---|
[608] | 410 | #if H_MV |
---|
| 411 | // destroy ROM |
---|
| 412 | destroyROM(); |
---|
[2] | 413 | |
---|
[608] | 414 | for(Int decIdx = 0; decIdx < m_numDecoders ; decIdx++) |
---|
[2] | 415 | { |
---|
[608] | 416 | if( m_tVideoIOYuvReconFile[decIdx] ) |
---|
[56] | 417 | { |
---|
[608] | 418 | m_tVideoIOYuvReconFile[decIdx]->close(); |
---|
| 419 | delete m_tVideoIOYuvReconFile[decIdx]; |
---|
| 420 | m_tVideoIOYuvReconFile[decIdx] = NULL ; |
---|
[56] | 421 | } |
---|
[2] | 422 | |
---|
[608] | 423 | if( m_tDecTop[decIdx] ) |
---|
[56] | 424 | { |
---|
[608] | 425 | m_tDecTop[decIdx]->deletePicBuffer(); |
---|
| 426 | m_tDecTop[decIdx]->destroy() ; |
---|
[56] | 427 | } |
---|
[608] | 428 | delete m_tDecTop[decIdx] ; |
---|
| 429 | m_tDecTop[decIdx] = NULL ; |
---|
[2] | 430 | } |
---|
[608] | 431 | #else |
---|
| 432 | if ( m_pchReconFile ) |
---|
| 433 | { |
---|
| 434 | m_cTVideoIOYuvReconFile. close(); |
---|
| 435 | } |
---|
| 436 | |
---|
| 437 | // destroy decoder class |
---|
| 438 | m_cTDecTop.destroy(); |
---|
| 439 | #endif |
---|
| 440 | #if H_3D |
---|
[57] | 441 | m_cCamParsCollector.uninit(); |
---|
| 442 | if( m_pScaleOffsetFile ) |
---|
| 443 | { |
---|
| 444 | ::fclose( m_pScaleOffsetFile ); |
---|
| 445 | } |
---|
[608] | 446 | #endif |
---|
[56] | 447 | } |
---|
[2] | 448 | |
---|
[608] | 449 | Void TAppDecTop::xInitDecLib() |
---|
[56] | 450 | { |
---|
[608] | 451 | #if !H_MV |
---|
| 452 | // initialize decoder class |
---|
| 453 | m_cTDecTop.init(); |
---|
| 454 | m_cTDecTop.setDecodedPictureHashSEIEnabled(m_decodedPictureHashSEIEnabled); |
---|
| 455 | #endif |
---|
| 456 | } |
---|
| 457 | |
---|
| 458 | /** \param pcListPic list of pictures to be written to file |
---|
| 459 | \todo DYN_REF_FREE should be revised |
---|
| 460 | */ |
---|
| 461 | #if H_MV |
---|
| 462 | Void TAppDecTop::xWriteOutput( TComList<TComPic*>* pcListPic, Int decIdx, Int tId ) |
---|
| 463 | #else |
---|
| 464 | Void TAppDecTop::xWriteOutput( TComList<TComPic*>* pcListPic, UInt tId ) |
---|
| 465 | #endif |
---|
| 466 | { |
---|
[56] | 467 | TComList<TComPic*>::iterator iterPic = pcListPic->begin(); |
---|
| 468 | Int not_displayed = 0; |
---|
| 469 | |
---|
| 470 | while (iterPic != pcListPic->end()) |
---|
[2] | 471 | { |
---|
[56] | 472 | TComPic* pcPic = *(iterPic); |
---|
[608] | 473 | #if H_MV |
---|
| 474 | if(pcPic->getOutputMark() && pcPic->getPOC() > m_pocLastDisplay[decIdx]) |
---|
| 475 | #else |
---|
| 476 | if(pcPic->getOutputMark() && pcPic->getPOC() > m_iPOCLastDisplay) |
---|
| 477 | #endif |
---|
[56] | 478 | { |
---|
| 479 | not_displayed++; |
---|
| 480 | } |
---|
| 481 | iterPic++; |
---|
[2] | 482 | } |
---|
[56] | 483 | iterPic = pcListPic->begin(); |
---|
| 484 | |
---|
| 485 | while (iterPic != pcListPic->end()) |
---|
[2] | 486 | { |
---|
[56] | 487 | TComPic* pcPic = *(iterPic); |
---|
| 488 | |
---|
[608] | 489 | #if H_MV |
---|
| 490 | if ( pcPic->getOutputMark() && (not_displayed > pcPic->getNumReorderPics(tId) && pcPic->getPOC() > m_pocLastDisplay[decIdx])) |
---|
| 491 | #else |
---|
| 492 | if ( pcPic->getOutputMark() && (not_displayed > pcPic->getNumReorderPics(tId) && pcPic->getPOC() > m_iPOCLastDisplay)) |
---|
| 493 | #endif |
---|
[56] | 494 | { |
---|
| 495 | // write to file |
---|
| 496 | not_displayed--; |
---|
[608] | 497 | #if H_MV |
---|
| 498 | if ( m_pchReconFiles[decIdx] ) |
---|
| 499 | #else |
---|
[56] | 500 | if ( m_pchReconFile ) |
---|
[608] | 501 | #endif |
---|
[56] | 502 | { |
---|
[608] | 503 | const Window &conf = pcPic->getConformanceWindow(); |
---|
| 504 | const Window &defDisp = m_respectDefDispWindow ? pcPic->getDefDisplayWindow() : Window(); |
---|
| 505 | #if H_MV |
---|
[622] | 506 | #if H_MV5 |
---|
| 507 | assert( conf .getScaledFlag() ); |
---|
| 508 | assert( defDisp.getScaledFlag() ); |
---|
| 509 | #endif |
---|
[608] | 510 | m_tVideoIOYuvReconFile[decIdx]->write( pcPic->getPicYuvRec(), |
---|
| 511 | #else |
---|
| 512 | m_cTVideoIOYuvReconFile.write( pcPic->getPicYuvRec(), |
---|
| 513 | #endif |
---|
| 514 | conf.getWindowLeftOffset() + defDisp.getWindowLeftOffset(), |
---|
| 515 | conf.getWindowRightOffset() + defDisp.getWindowRightOffset(), |
---|
| 516 | conf.getWindowTopOffset() + defDisp.getWindowTopOffset(), |
---|
| 517 | conf.getWindowBottomOffset() + defDisp.getWindowBottomOffset() ); |
---|
[56] | 518 | } |
---|
| 519 | |
---|
| 520 | // update POC of display order |
---|
[608] | 521 | #if H_MV |
---|
| 522 | m_pocLastDisplay[decIdx] = pcPic->getPOC(); |
---|
| 523 | #else |
---|
| 524 | m_iPOCLastDisplay = pcPic->getPOC(); |
---|
| 525 | #endif |
---|
[56] | 526 | |
---|
| 527 | // erase non-referenced picture in the reference picture list after display |
---|
| 528 | if ( !pcPic->getSlice(0)->isReferenced() && pcPic->getReconMark() == true ) |
---|
| 529 | { |
---|
| 530 | #if !DYN_REF_FREE |
---|
| 531 | pcPic->setReconMark(false); |
---|
| 532 | |
---|
| 533 | // mark it should be extended later |
---|
| 534 | pcPic->getPicYuvRec()->setBorderExtension( false ); |
---|
| 535 | |
---|
| 536 | #else |
---|
| 537 | pcPic->destroy(); |
---|
| 538 | pcListPic->erase( iterPic ); |
---|
| 539 | iterPic = pcListPic->begin(); // to the beginning, non-efficient way, have to be revised! |
---|
| 540 | continue; |
---|
| 541 | #endif |
---|
| 542 | } |
---|
| 543 | pcPic->setOutputMark(false); |
---|
| 544 | } |
---|
| 545 | |
---|
| 546 | iterPic++; |
---|
[2] | 547 | } |
---|
| 548 | } |
---|
| 549 | |
---|
| 550 | /** \param pcListPic list of pictures to be written to file |
---|
| 551 | \todo DYN_REF_FREE should be revised |
---|
| 552 | */ |
---|
[608] | 553 | #if H_MV |
---|
| 554 | Void TAppDecTop::xFlushOutput( TComList<TComPic*>* pcListPic, Int decIdx ) |
---|
| 555 | #else |
---|
| 556 | Void TAppDecTop::xFlushOutput( TComList<TComPic*>* pcListPic ) |
---|
| 557 | #endif |
---|
[2] | 558 | { |
---|
[56] | 559 | if(!pcListPic) |
---|
| 560 | { |
---|
| 561 | return; |
---|
| 562 | } |
---|
[2] | 563 | TComList<TComPic*>::iterator iterPic = pcListPic->begin(); |
---|
| 564 | |
---|
[56] | 565 | iterPic = pcListPic->begin(); |
---|
| 566 | |
---|
[2] | 567 | while (iterPic != pcListPic->end()) |
---|
| 568 | { |
---|
| 569 | TComPic* pcPic = *(iterPic); |
---|
| 570 | |
---|
[56] | 571 | if ( pcPic->getOutputMark() ) |
---|
[2] | 572 | { |
---|
[56] | 573 | // write to file |
---|
[608] | 574 | #if H_MV |
---|
| 575 | if ( m_pchReconFiles[decIdx] ) |
---|
| 576 | #else |
---|
[56] | 577 | if ( m_pchReconFile ) |
---|
[608] | 578 | #endif |
---|
[2] | 579 | { |
---|
[608] | 580 | const Window &conf = pcPic->getConformanceWindow(); |
---|
| 581 | const Window &defDisp = m_respectDefDispWindow ? pcPic->getDefDisplayWindow() : Window(); |
---|
| 582 | #if H_MV |
---|
[622] | 583 | #if H_MV5 |
---|
| 584 | assert( conf .getScaledFlag() ); |
---|
| 585 | assert( defDisp.getScaledFlag() ); |
---|
| 586 | #endif |
---|
[608] | 587 | m_tVideoIOYuvReconFile[decIdx]->write( pcPic->getPicYuvRec(), |
---|
| 588 | #else |
---|
| 589 | m_cTVideoIOYuvReconFile.write( pcPic->getPicYuvRec(), |
---|
| 590 | #endif |
---|
| 591 | conf.getWindowLeftOffset() + defDisp.getWindowLeftOffset(), |
---|
| 592 | conf.getWindowRightOffset() + defDisp.getWindowRightOffset(), |
---|
| 593 | conf.getWindowTopOffset() + defDisp.getWindowTopOffset(), |
---|
| 594 | conf.getWindowBottomOffset() + defDisp.getWindowBottomOffset() ); |
---|
[2] | 595 | } |
---|
[56] | 596 | |
---|
| 597 | // update POC of display order |
---|
[608] | 598 | #if H_MV |
---|
| 599 | m_pocLastDisplay[decIdx] = pcPic->getPOC(); |
---|
| 600 | #else |
---|
| 601 | m_iPOCLastDisplay = pcPic->getPOC(); |
---|
| 602 | #endif |
---|
[56] | 603 | |
---|
| 604 | // erase non-referenced picture in the reference picture list after display |
---|
| 605 | if ( !pcPic->getSlice(0)->isReferenced() && pcPic->getReconMark() == true ) |
---|
[2] | 606 | { |
---|
[56] | 607 | #if !DYN_REF_FREE |
---|
| 608 | pcPic->setReconMark(false); |
---|
| 609 | |
---|
| 610 | // mark it should be extended later |
---|
| 611 | pcPic->getPicYuvRec()->setBorderExtension( false ); |
---|
| 612 | |
---|
| 613 | #else |
---|
| 614 | pcPic->destroy(); |
---|
| 615 | pcListPic->erase( iterPic ); |
---|
| 616 | iterPic = pcListPic->begin(); // to the beginning, non-efficient way, have to be revised! |
---|
| 617 | continue; |
---|
| 618 | #endif |
---|
[2] | 619 | } |
---|
[56] | 620 | pcPic->setOutputMark(false); |
---|
| 621 | } |
---|
[608] | 622 | #if !H_MV |
---|
| 623 | #if !DYN_REF_FREE |
---|
| 624 | if(pcPic) |
---|
| 625 | { |
---|
| 626 | pcPic->destroy(); |
---|
| 627 | delete pcPic; |
---|
| 628 | pcPic = NULL; |
---|
| 629 | } |
---|
| 630 | #endif |
---|
| 631 | #endif |
---|
[2] | 632 | iterPic++; |
---|
| 633 | } |
---|
[608] | 634 | #if H_MV |
---|
| 635 | m_pocLastDisplay[decIdx] = -MAX_INT; |
---|
| 636 | #else |
---|
[56] | 637 | pcListPic->clear(); |
---|
[608] | 638 | m_iPOCLastDisplay = -MAX_INT; |
---|
| 639 | #endif |
---|
[2] | 640 | } |
---|
[608] | 641 | |
---|
| 642 | /** \param nalu Input nalu to check whether its LayerId is within targetDecLayerIdSet |
---|
| 643 | */ |
---|
| 644 | Bool TAppDecTop::isNaluWithinTargetDecLayerIdSet( InputNALUnit* nalu ) |
---|
[2] | 645 | { |
---|
[608] | 646 | if ( m_targetDecLayerIdSet.size() == 0 ) // By default, the set is empty, meaning all LayerIds are allowed |
---|
[2] | 647 | { |
---|
[608] | 648 | return true; |
---|
[2] | 649 | } |
---|
[608] | 650 | for (std::vector<Int>::iterator it = m_targetDecLayerIdSet.begin(); it != m_targetDecLayerIdSet.end(); it++) |
---|
| 651 | { |
---|
| 652 | #if H_MV |
---|
| 653 | if ( nalu->m_layerId == (*it) ) |
---|
[81] | 654 | #else |
---|
[608] | 655 | if ( nalu->m_reservedZero6Bits == (*it) ) |
---|
[81] | 656 | #endif |
---|
[56] | 657 | { |
---|
[608] | 658 | return true; |
---|
[56] | 659 | } |
---|
| 660 | } |
---|
[608] | 661 | return false; |
---|
[2] | 662 | } |
---|
| 663 | |
---|
[608] | 664 | #if H_MV |
---|
| 665 | Int TAppDecTop::xGetDecoderIdx( Int layerId, Bool createFlag /*= false */ ) |
---|
| 666 | { |
---|
| 667 | Int decIdx = -1; |
---|
| 668 | if ( m_layerIdToDecIdx[ layerId ] != -1 ) |
---|
| 669 | { |
---|
| 670 | decIdx = m_layerIdToDecIdx[ layerId ]; |
---|
[210] | 671 | } |
---|
| 672 | else |
---|
[608] | 673 | { |
---|
| 674 | assert ( createFlag ); |
---|
| 675 | assert( m_numDecoders < MAX_NUM_LAYERS ); |
---|
[210] | 676 | |
---|
[608] | 677 | decIdx = m_numDecoders; |
---|
| 678 | |
---|
| 679 | // Init decoder |
---|
| 680 | m_tDecTop[ decIdx ] = new TDecTop; |
---|
| 681 | m_tDecTop[ decIdx ]->create(); |
---|
| 682 | m_tDecTop[ decIdx ]->init( ); |
---|
| 683 | m_tDecTop[ decIdx ]->setLayerId( layerId ); |
---|
| 684 | m_tDecTop[ decIdx ]->setDecodedPictureHashSEIEnabled(m_decodedPictureHashSEIEnabled); |
---|
| 685 | m_tDecTop[ decIdx ]->setIvPicLists( &m_ivPicLists ); |
---|
| 686 | #if H_3D |
---|
| 687 | m_tDecTop[ decIdx ]->setCamParsCollector( &m_cCamParsCollector ); |
---|
[210] | 688 | #endif |
---|
[2] | 689 | |
---|
[608] | 690 | // append pic list of new decoder to PicLists |
---|
| 691 | assert( m_ivPicLists.size() == m_numDecoders ); |
---|
| 692 | m_ivPicLists.push_back( m_tDecTop[ decIdx ]->getListPic() ); |
---|
[2] | 693 | |
---|
[608] | 694 | // create recon file related stuff |
---|
| 695 | Char* pchTempFilename = NULL; |
---|
| 696 | if ( m_pchReconFile ) |
---|
| 697 | { |
---|
| 698 | Char buffer[4]; |
---|
| 699 | sprintf(buffer,"_%i", layerId ); |
---|
| 700 | assert ( m_pchReconFile ); |
---|
| 701 | xAppendToFileNameEnd( m_pchReconFile , buffer, pchTempFilename ); |
---|
| 702 | assert( m_pchReconFiles.size() == m_numDecoders ); |
---|
[2] | 703 | } |
---|
[210] | 704 | |
---|
[608] | 705 | m_pchReconFiles.push_back( pchTempFilename ); |
---|
[296] | 706 | |
---|
[608] | 707 | m_tVideoIOYuvReconFile[ decIdx ] = new TVideoIOYuv; |
---|
| 708 | m_reconOpen [ decIdx ] = false; |
---|
[443] | 709 | |
---|
[608] | 710 | // set others |
---|
| 711 | m_pocLastDisplay [ decIdx ] = -MAX_INT; |
---|
| 712 | m_layerIdToDecIdx [ layerId ] = decIdx; |
---|
[296] | 713 | |
---|
[608] | 714 | m_numDecoders++; |
---|
| 715 | }; |
---|
| 716 | return decIdx; |
---|
[296] | 717 | } |
---|
| 718 | #endif |
---|
[56] | 719 | //! \} |
---|