[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 | * |
---|
[56] | 6 | * Copyright (c) 2010-2012, 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() |
---|
| 56 | { |
---|
| 57 | ::memset (m_abDecFlag, 0, sizeof (m_abDecFlag)); |
---|
[56] | 58 | m_useDepth = false; |
---|
[57] | 59 | m_pScaleOffsetFile = 0; |
---|
[2] | 60 | } |
---|
| 61 | |
---|
| 62 | Void TAppDecTop::create() |
---|
| 63 | { |
---|
| 64 | } |
---|
| 65 | |
---|
| 66 | Void TAppDecTop::destroy() |
---|
| 67 | { |
---|
| 68 | } |
---|
| 69 | |
---|
| 70 | // ==================================================================================================================== |
---|
| 71 | // Public member functions |
---|
| 72 | // ==================================================================================================================== |
---|
| 73 | |
---|
| 74 | /** |
---|
| 75 | - create internal class |
---|
| 76 | - initialize internal class |
---|
| 77 | - until the end of the bitstream, call decoding function in TDecTop class |
---|
| 78 | - delete allocated buffers |
---|
| 79 | - destroy internal class |
---|
| 80 | . |
---|
| 81 | */ |
---|
| 82 | Void TAppDecTop::decode() |
---|
| 83 | { |
---|
[210] | 84 | #if VIDYO_VPS_INTEGRATION|QC_MVHEVC_B0046 |
---|
[77] | 85 | increaseNumberOfViews( 0, 0, 0 ); |
---|
| 86 | #else |
---|
[56] | 87 | increaseNumberOfViews( 1 ); |
---|
[77] | 88 | #endif |
---|
| 89 | |
---|
[210] | 90 | #if FLEX_CODING_ORDER_M23723 |
---|
| 91 | Int iDepthViewIdx = 0; |
---|
| 92 | Int iTextureViewIdx=0; |
---|
| 93 | Bool firstFrame=1; |
---|
| 94 | Bool viewIdZero=true; |
---|
| 95 | Int fcoIndex=0; //when the current frame is not first frame,use FCO_index stand for viewDepth. |
---|
| 96 | #endif |
---|
| 97 | |
---|
[56] | 98 | #if SONY_COLPIC_AVAILABILITY |
---|
| 99 | m_tDecTop[0]->setViewOrderIdx(0); |
---|
[2] | 100 | #endif |
---|
[56] | 101 | Int viewDepthId = 0; |
---|
| 102 | Int previousViewDepthId = 0; |
---|
| 103 | UInt uiPOC[MAX_VIEW_NUM*2]; |
---|
| 104 | TComList<TComPic*>* pcListPic[MAX_VIEW_NUM*2]; |
---|
| 105 | Bool newPicture[MAX_VIEW_NUM*2]; |
---|
| 106 | Bool previousPictureDecoded = false; |
---|
| 107 | for( Int i = 0; i < MAX_VIEW_NUM*2; i++ ) |
---|
| 108 | { |
---|
| 109 | uiPOC[i] = 0; |
---|
| 110 | pcListPic[i] = NULL; |
---|
| 111 | newPicture[i] = false; |
---|
[210] | 112 | #if FLEX_CODING_ORDER_M23723 |
---|
| 113 | #if FIX_FCO_COMP_WARNING |
---|
| 114 | m_fcoOrder[i] = ' '; |
---|
| 115 | #else |
---|
| 116 | m_fcoOrder[i]=NULL; |
---|
| 117 | #endif |
---|
| 118 | #endif |
---|
| 119 | |
---|
[56] | 120 | } |
---|
[2] | 121 | |
---|
[56] | 122 | ifstream bitstreamFile(m_pchBitstreamFile, ifstream::in | ifstream::binary); |
---|
| 123 | if (!bitstreamFile) |
---|
| 124 | { |
---|
| 125 | fprintf(stderr, "\nfailed to open bitstream file `%s' for reading\n", m_pchBitstreamFile); |
---|
| 126 | exit(EXIT_FAILURE); |
---|
| 127 | } |
---|
[2] | 128 | |
---|
[56] | 129 | if( m_pchScaleOffsetFile ) |
---|
| 130 | { |
---|
| 131 | m_pScaleOffsetFile = ::fopen( m_pchScaleOffsetFile, "wt" ); |
---|
| 132 | AOF( m_pScaleOffsetFile ); |
---|
| 133 | } |
---|
| 134 | m_cCamParsCollector.init( m_pScaleOffsetFile ); |
---|
| 135 | |
---|
| 136 | InputByteStream bytestream(bitstreamFile); |
---|
| 137 | |
---|
| 138 | while (!!bitstreamFile) |
---|
[2] | 139 | { |
---|
[56] | 140 | /* location serves to work around a design fault in the decoder, whereby |
---|
| 141 | * the process of reading a new slice that is the first slice of a new frame |
---|
| 142 | * requires the TDecTop::decode() method to be called again with the same |
---|
| 143 | * nal unit. */ |
---|
| 144 | streampos location = bitstreamFile.tellg(); |
---|
| 145 | AnnexBStats stats = AnnexBStats(); |
---|
| 146 | vector<uint8_t> nalUnit; |
---|
| 147 | InputNALUnit nalu; |
---|
| 148 | byteStreamNALUnit(bytestream, nalUnit, stats); |
---|
| 149 | |
---|
| 150 | // call actual decoding function |
---|
| 151 | if (nalUnit.empty()) |
---|
[2] | 152 | { |
---|
[56] | 153 | /* this can happen if the following occur: |
---|
| 154 | * - empty input file |
---|
| 155 | * - two back-to-back start_code_prefixes |
---|
| 156 | * - start_code_prefix immediately followed by EOF |
---|
| 157 | */ |
---|
| 158 | fprintf(stderr, "Warning: Attempt to decode an empty NAL unit\n"); |
---|
[2] | 159 | } |
---|
| 160 | else |
---|
| 161 | { |
---|
[56] | 162 | read(nalu, nalUnit); |
---|
[210] | 163 | #if QC_MVHEVC_B0046 |
---|
| 164 | viewDepthId = nalu.m_layerId; |
---|
| 165 | Int depth = 0; |
---|
| 166 | Int viewId = viewDepthId; |
---|
| 167 | #else |
---|
[77] | 168 | #if VIDYO_VPS_INTEGRATION |
---|
| 169 | Int viewId = 0; |
---|
| 170 | Int depth = 0; |
---|
| 171 | |
---|
| 172 | if(nalu.m_nalUnitType != NAL_UNIT_VPS || nalu.m_layerId) |
---|
| 173 | { |
---|
| 174 | // code assumes that the first nal unit is VPS |
---|
| 175 | // currently, this is a hack that requires non-first VPSs have non-zero layer_id |
---|
| 176 | viewId = getVPSAccess()->getActiveVPS()->getViewId(nalu.m_layerId); |
---|
| 177 | depth = getVPSAccess()->getActiveVPS()->getDepthFlag(nalu.m_layerId); |
---|
| 178 | } |
---|
[210] | 179 | #if FLEX_CODING_ORDER_M23723 |
---|
| 180 | if (viewId>0) |
---|
| 181 | { |
---|
| 182 | viewIdZero=false; |
---|
| 183 | } |
---|
| 184 | if (viewIdZero==false&&viewId==0) |
---|
| 185 | { |
---|
| 186 | firstFrame=0; //if viewId has been more than zero and now it set to zero again, we can see that it is not the first view |
---|
| 187 | } |
---|
| 188 | if (firstFrame) |
---|
| 189 | { // if the current view is first frame, we set the viewDepthId as texture plus depth and get the FCO order |
---|
| 190 | viewDepthId = iDepthViewIdx+iTextureViewIdx; |
---|
| 191 | m_fcoViewDepthId=viewDepthId; |
---|
| 192 | } |
---|
| 193 | else |
---|
| 194 | {//if current view is not first frame, we set the viewDepthId depended on the FCO order |
---|
| 195 | viewDepthId=0; |
---|
| 196 | if (depth) |
---|
| 197 | { |
---|
| 198 | for (fcoIndex=0;fcoIndex<2*MAX_VIEW_NUM;fcoIndex++ ) |
---|
| 199 | { |
---|
| 200 | if (m_fcoOrder[fcoIndex]=='D') |
---|
| 201 | { |
---|
| 202 | if (viewId==viewDepthId) |
---|
| 203 | break; |
---|
| 204 | else |
---|
| 205 | viewDepthId++; |
---|
| 206 | } |
---|
| 207 | } |
---|
| 208 | } |
---|
| 209 | else |
---|
| 210 | { |
---|
| 211 | for (fcoIndex=0;fcoIndex<2*MAX_VIEW_NUM;fcoIndex++ ) |
---|
| 212 | { |
---|
| 213 | if (m_fcoOrder[fcoIndex]=='T') |
---|
| 214 | { |
---|
| 215 | if (viewId==viewDepthId) |
---|
| 216 | break; |
---|
| 217 | else |
---|
| 218 | viewDepthId++; |
---|
| 219 | } |
---|
| 220 | } |
---|
| 221 | } |
---|
| 222 | |
---|
| 223 | viewDepthId=fcoIndex; |
---|
| 224 | |
---|
| 225 | } |
---|
| 226 | |
---|
| 227 | |
---|
| 228 | #else |
---|
[77] | 229 | viewDepthId = nalu.m_layerId; // coding order T0D0T1D1T2D2 |
---|
[210] | 230 | #endif |
---|
| 231 | |
---|
[77] | 232 | #else |
---|
[56] | 233 | Int viewId = nalu.m_viewId; |
---|
| 234 | Int depth = nalu.m_isDepth ? 1 : 0; |
---|
[210] | 235 | #if FLEX_CODING_ORDER_M23723 |
---|
| 236 | if (viewId>0) |
---|
| 237 | { |
---|
| 238 | viewIdZero=false; |
---|
| 239 | } |
---|
| 240 | if (viewIdZero==false&&viewId==0) |
---|
| 241 | { |
---|
| 242 | firstFrame=0; |
---|
| 243 | } |
---|
| 244 | if (firstFrame) |
---|
| 245 | { |
---|
| 246 | viewDepthId = iDepthViewIdx+iTextureViewIdx; |
---|
| 247 | m_fcoViewDepthId=viewDepthId; |
---|
| 248 | } |
---|
| 249 | else |
---|
| 250 | { |
---|
| 251 | viewDepthId=0; |
---|
| 252 | if (depth) |
---|
| 253 | { |
---|
| 254 | for (fcoIndex=0;fcoIndex<2*MAX_VIEW_NUM;fcoIndex++ ) |
---|
| 255 | { |
---|
| 256 | if (m_fcoOrder[fcoIndex]=='D') |
---|
| 257 | { |
---|
| 258 | if (viewId==viewDepthId) |
---|
| 259 | break; |
---|
| 260 | else |
---|
| 261 | viewDepthId++; |
---|
| 262 | } |
---|
| 263 | } |
---|
| 264 | } |
---|
| 265 | else |
---|
| 266 | { |
---|
| 267 | for (fcoIndex=0;fcoIndex<2*MAX_VIEW_NUM;fcoIndex++ ) |
---|
| 268 | { |
---|
| 269 | if (m_fcoOrder[fcoIndex]=='T') |
---|
| 270 | { |
---|
| 271 | if (viewId==viewDepthId) |
---|
| 272 | break; |
---|
| 273 | else |
---|
| 274 | viewDepthId++; |
---|
| 275 | } |
---|
| 276 | } |
---|
| 277 | } |
---|
| 278 | viewDepthId=fcoIndex; |
---|
| 279 | } |
---|
| 280 | #else |
---|
[56] | 281 | viewDepthId = viewId * 2 + depth; // coding order T0D0T1D1T2D2 |
---|
[77] | 282 | #endif |
---|
[210] | 283 | #endif |
---|
| 284 | #endif |
---|
[56] | 285 | newPicture[viewDepthId] = false; |
---|
| 286 | if( viewDepthId >= m_tDecTop.size() ) |
---|
[2] | 287 | { |
---|
[210] | 288 | #if VIDYO_VPS_INTEGRATION|QC_MVHEVC_B0046 |
---|
[77] | 289 | increaseNumberOfViews( viewDepthId, viewId, depth ); |
---|
| 290 | #else |
---|
[56] | 291 | increaseNumberOfViews( viewDepthId +1 ); |
---|
[77] | 292 | #endif |
---|
[2] | 293 | } |
---|
[56] | 294 | if(m_iMaxTemporalLayer >= 0 && nalu.m_temporalId > m_iMaxTemporalLayer) |
---|
[2] | 295 | { |
---|
[56] | 296 | previousPictureDecoded = false; |
---|
[2] | 297 | } |
---|
[56] | 298 | if(m_tDecTop.size() > 1 && (viewDepthId != previousViewDepthId) && previousPictureDecoded ) |
---|
[42] | 299 | { |
---|
[56] | 300 | m_tDecTop[previousViewDepthId]->executeDeblockAndAlf(uiPOC[previousViewDepthId], pcListPic[previousViewDepthId], m_iSkipFrame, m_pocLastDisplay[previousViewDepthId]); |
---|
| 301 | } |
---|
| 302 | if( ( viewDepthId == 0 && (viewDepthId != previousViewDepthId) ) || m_tDecTop.size() == 1 ) |
---|
[42] | 303 | { |
---|
[56] | 304 | #if HHI_INTER_VIEW_RESIDUAL_PRED |
---|
| 305 | for( Int i = 0; i < m_tDecTop.size(); i++ ) |
---|
[42] | 306 | { |
---|
[56] | 307 | m_tDecTop[i]->deleteExtraPicBuffers( uiPOC[i] ); |
---|
[42] | 308 | } |
---|
[56] | 309 | #endif |
---|
| 310 | for( Int i = 0; i < m_tDecTop.size(); i++ ) |
---|
[42] | 311 | { |
---|
[56] | 312 | m_tDecTop[i]->compressMotion( uiPOC[i] ); |
---|
[42] | 313 | } |
---|
[56] | 314 | } |
---|
| 315 | if( !(m_iMaxTemporalLayer >= 0 && nalu.m_temporalId > m_iMaxTemporalLayer) ) |
---|
[42] | 316 | { |
---|
[210] | 317 | #if QC_MVHEVC_B0046 |
---|
| 318 | if(viewDepthId && m_tDecTop[viewDepthId]->m_bFirstNal== false) |
---|
| 319 | { |
---|
| 320 | m_tDecTop[viewDepthId]->m_bFirstNal = true; |
---|
| 321 | ParameterSetManagerDecoder* pDecV0 = m_tDecTop[0]->xGetParaSetDec(); |
---|
| 322 | m_tDecTop[viewDepthId]->xCopyVPS(pDecV0->getPrefetchedVPS(0)); |
---|
| 323 | m_tDecTop[viewDepthId]->xCopySPS(pDecV0->getPrefetchedSPS(0)); |
---|
| 324 | m_tDecTop[viewDepthId]->xCopyPPS(pDecV0->getPrefetchedPPS(0)); |
---|
| 325 | } |
---|
| 326 | #endif |
---|
[56] | 327 | newPicture[viewDepthId] = m_tDecTop[viewDepthId]->decode(nalu, m_iSkipFrame, m_pocLastDisplay[viewDepthId]); |
---|
| 328 | if (newPicture[viewDepthId]) |
---|
[42] | 329 | { |
---|
[56] | 330 | bitstreamFile.clear(); |
---|
| 331 | /* location points to the current nalunit payload[1] due to the |
---|
| 332 | * need for the annexB parser to read three extra bytes. |
---|
| 333 | * [1] except for the first NAL unit in the file |
---|
| 334 | * (but bNewPicture doesn't happen then) */ |
---|
| 335 | bitstreamFile.seekg(location-streamoff(3)); |
---|
| 336 | bytestream.reset(); |
---|
[42] | 337 | } |
---|
[56] | 338 | if( nalu.isSlice() ) |
---|
[42] | 339 | { |
---|
[56] | 340 | previousPictureDecoded = true; |
---|
[210] | 341 | #if FLEX_CODING_ORDER_M23723 |
---|
| 342 | if (firstFrame) |
---|
| 343 | { |
---|
| 344 | if (depth) |
---|
| 345 | { |
---|
| 346 | iDepthViewIdx++; |
---|
| 347 | m_fcoOrder[viewDepthId]='D'; |
---|
| 348 | } |
---|
| 349 | else |
---|
| 350 | { |
---|
| 351 | iTextureViewIdx++; |
---|
| 352 | m_fcoOrder[viewDepthId]='T'; |
---|
| 353 | } |
---|
| 354 | } |
---|
| 355 | |
---|
| 356 | #endif |
---|
[42] | 357 | } |
---|
| 358 | } |
---|
[56] | 359 | } |
---|
| 360 | if( ( (newPicture[viewDepthId] || !bitstreamFile) && m_tDecTop.size() == 1) || (!bitstreamFile && previousPictureDecoded == true) ) |
---|
| 361 | { |
---|
| 362 | m_tDecTop[viewDepthId]->executeDeblockAndAlf(uiPOC[viewDepthId], pcListPic[viewDepthId], m_iSkipFrame, m_pocLastDisplay[viewDepthId]); |
---|
| 363 | } |
---|
| 364 | if( pcListPic[viewDepthId] ) |
---|
| 365 | { |
---|
[210] | 366 | #if QC_REM_IDV_B0046 |
---|
| 367 | Int iviewId = m_tDecTop[viewDepthId]->getViewId(); |
---|
| 368 | if( newPicture[viewDepthId] && (nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_IDR || ((nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_IDR && iviewId) && m_tDecTop[viewDepthId]->getNalUnitTypeBaseView() == NAL_UNIT_CODED_SLICE_IDR)) ) |
---|
| 369 | #else |
---|
[56] | 370 | if( newPicture[viewDepthId] && (nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_IDR || (nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_IDV && m_tDecTop[viewDepthId]->getNalUnitTypeBaseView() == NAL_UNIT_CODED_SLICE_IDR)) ) |
---|
[210] | 371 | #endif |
---|
[2] | 372 | { |
---|
[56] | 373 | xFlushOutput( pcListPic[viewDepthId], viewDepthId ); |
---|
[2] | 374 | } |
---|
[56] | 375 | // write reconstruction to file |
---|
| 376 | if(newPicture[viewDepthId]) |
---|
[2] | 377 | { |
---|
[56] | 378 | #if H0567_DPB_PARAMETERS_PER_TEMPORAL_LAYER |
---|
| 379 | xWriteOutput( pcListPic[viewDepthId], viewDepthId, nalu.m_temporalId ); |
---|
[2] | 380 | #else |
---|
[56] | 381 | xWriteOutput( pcListPic[viewDepthId], viewDepthId ); |
---|
[2] | 382 | #endif |
---|
| 383 | } |
---|
| 384 | } |
---|
[56] | 385 | previousViewDepthId = viewDepthId; |
---|
| 386 | } |
---|
[57] | 387 | if( m_cCamParsCollector.isInitialized() ) |
---|
| 388 | { |
---|
| 389 | m_cCamParsCollector.setSlice( 0 ); |
---|
| 390 | } |
---|
[56] | 391 | // last frame |
---|
| 392 | for( Int viewDepthIdx = 0; viewDepthIdx < m_tDecTop.size(); viewDepthIdx++ ) |
---|
[2] | 393 | { |
---|
[56] | 394 | xFlushOutput( pcListPic[viewDepthIdx], viewDepthIdx ); |
---|
| 395 | } |
---|
[2] | 396 | xDestroyDecLib(); |
---|
| 397 | } |
---|
| 398 | |
---|
| 399 | // ==================================================================================================================== |
---|
| 400 | // Protected member functions |
---|
| 401 | // ==================================================================================================================== |
---|
| 402 | |
---|
| 403 | Void TAppDecTop::xDestroyDecLib() |
---|
| 404 | { |
---|
| 405 | |
---|
[56] | 406 | for(Int viewDepthIdx=0; viewDepthIdx<m_tVideoIOYuvReconFile.size() ; viewDepthIdx++) |
---|
[2] | 407 | { |
---|
[56] | 408 | if( m_tVideoIOYuvReconFile[viewDepthIdx] ) |
---|
| 409 | { |
---|
| 410 | m_tVideoIOYuvReconFile[viewDepthIdx]->close(); |
---|
| 411 | delete m_tVideoIOYuvReconFile[viewDepthIdx]; |
---|
| 412 | m_tVideoIOYuvReconFile[viewDepthIdx] = NULL ; |
---|
| 413 | } |
---|
[2] | 414 | } |
---|
| 415 | |
---|
[56] | 416 | for(Int viewDepthIdx=0; viewDepthIdx<m_tDecTop.size() ; viewDepthIdx++) |
---|
[2] | 417 | { |
---|
[56] | 418 | if( m_tDecTop[viewDepthIdx] ) |
---|
| 419 | { |
---|
| 420 | if( !m_useDepth && (viewDepthIdx % 2 == 1) ) |
---|
| 421 | { |
---|
| 422 | } |
---|
| 423 | else |
---|
| 424 | { |
---|
| 425 | m_tDecTop[viewDepthIdx]->deletePicBuffer(); |
---|
| 426 | m_tDecTop[viewDepthIdx]->destroy() ; |
---|
| 427 | } |
---|
[210] | 428 | #if QC_MVHEVC_B0046 |
---|
| 429 | if(viewDepthIdx) |
---|
| 430 | { |
---|
| 431 | //Call clear function to remove the record, which has been freed during viewDepthIdx = 0 case. |
---|
| 432 | m_tDecTop[viewDepthIdx]->xGetParaSetDec()->clearSPS(); |
---|
| 433 | m_tDecTop[viewDepthIdx]->xGetParaSetDec()->clearVPS(); |
---|
| 434 | m_tDecTop[viewDepthIdx]->xGetParaSetDec()->clearPPS(); |
---|
| 435 | } |
---|
| 436 | #endif |
---|
[56] | 437 | delete m_tDecTop[viewDepthIdx] ; |
---|
| 438 | m_tDecTop[viewDepthIdx] = NULL ; |
---|
| 439 | } |
---|
[2] | 440 | } |
---|
[57] | 441 | |
---|
| 442 | m_cCamParsCollector.uninit(); |
---|
| 443 | if( m_pScaleOffsetFile ) |
---|
| 444 | { |
---|
| 445 | ::fclose( m_pScaleOffsetFile ); |
---|
| 446 | } |
---|
[56] | 447 | } |
---|
[2] | 448 | |
---|
[56] | 449 | #if H0567_DPB_PARAMETERS_PER_TEMPORAL_LAYER |
---|
| 450 | Void TAppDecTop::xWriteOutput( TComList<TComPic*>* pcListPic, Int viewDepthId, UInt tId ) |
---|
| 451 | #else |
---|
| 452 | Void TAppDecTop::xWriteOutput( TComList<TComPic*>* pcListPic, Int viewDepthId ) |
---|
| 453 | #endif |
---|
| 454 | { |
---|
| 455 | TComList<TComPic*>::iterator iterPic = pcListPic->begin(); |
---|
| 456 | Int not_displayed = 0; |
---|
| 457 | |
---|
| 458 | while (iterPic != pcListPic->end()) |
---|
[2] | 459 | { |
---|
[56] | 460 | TComPic* pcPic = *(iterPic); |
---|
| 461 | if(pcPic->getOutputMark() && pcPic->getPOC() > m_pocLastDisplay[viewDepthId]) |
---|
| 462 | { |
---|
| 463 | not_displayed++; |
---|
| 464 | } |
---|
| 465 | iterPic++; |
---|
[2] | 466 | } |
---|
[56] | 467 | iterPic = pcListPic->begin(); |
---|
| 468 | |
---|
| 469 | while (iterPic != pcListPic->end()) |
---|
[2] | 470 | { |
---|
[56] | 471 | TComPic* pcPic = *(iterPic); |
---|
| 472 | #if PIC_CROPPING |
---|
| 473 | TComSPS *sps = pcPic->getSlice(0)->getSPS(); |
---|
| 474 | #endif |
---|
| 475 | |
---|
| 476 | #if H0567_DPB_PARAMETERS_PER_TEMPORAL_LAYER |
---|
| 477 | if ( pcPic->getOutputMark() && (not_displayed > pcPic->getSlice(0)->getSPS()->getNumReorderPics(tId) && pcPic->getPOC() > m_pocLastDisplay[viewDepthId])) |
---|
| 478 | #else |
---|
| 479 | if ( pcPic->getOutputMark() && (not_displayed > pcPic->getSlice(0)->getSPS()->getNumReorderFrames() && pcPic->getPOC() > m_pocLastDisplay[viewDepthId])) |
---|
| 480 | #endif |
---|
| 481 | { |
---|
| 482 | // write to file |
---|
| 483 | not_displayed--; |
---|
| 484 | if ( m_pchReconFile ) |
---|
| 485 | { |
---|
| 486 | #if PIC_CROPPING |
---|
| 487 | m_tVideoIOYuvReconFile[viewDepthId]->write( pcPic->getPicYuvRec(), sps->getPicCropLeftOffset(), sps->getPicCropRightOffset(), sps->getPicCropTopOffset(), sps->getPicCropBottomOffset() ); |
---|
| 488 | #else |
---|
| 489 | m_tVideoIOYuvReconFile[viewDepthId]->write( pcPic->getPicYuvRec(), pcPic->getSlice(0)->getSPS()->getPad() ); |
---|
| 490 | #endif |
---|
| 491 | } |
---|
| 492 | |
---|
| 493 | // update POC of display order |
---|
| 494 | m_pocLastDisplay[viewDepthId] = pcPic->getPOC(); |
---|
| 495 | |
---|
| 496 | // erase non-referenced picture in the reference picture list after display |
---|
| 497 | if ( !pcPic->getSlice(0)->isReferenced() && pcPic->getReconMark() == true ) |
---|
| 498 | { |
---|
| 499 | #if !DYN_REF_FREE |
---|
| 500 | pcPic->setReconMark(false); |
---|
| 501 | |
---|
| 502 | // mark it should be extended later |
---|
| 503 | pcPic->getPicYuvRec()->setBorderExtension( false ); |
---|
| 504 | |
---|
| 505 | #else |
---|
| 506 | pcPic->destroy(); |
---|
| 507 | pcListPic->erase( iterPic ); |
---|
| 508 | iterPic = pcListPic->begin(); // to the beginning, non-efficient way, have to be revised! |
---|
| 509 | continue; |
---|
| 510 | #endif |
---|
| 511 | } |
---|
| 512 | pcPic->setOutputMark(false); |
---|
| 513 | } |
---|
| 514 | |
---|
| 515 | iterPic++; |
---|
[2] | 516 | } |
---|
| 517 | } |
---|
| 518 | |
---|
| 519 | /** \param pcListPic list of pictures to be written to file |
---|
| 520 | \todo DYN_REF_FREE should be revised |
---|
| 521 | */ |
---|
[56] | 522 | Void TAppDecTop::xFlushOutput( TComList<TComPic*>* pcListPic, Int viewDepthId ) |
---|
[2] | 523 | { |
---|
[56] | 524 | if(!pcListPic) |
---|
| 525 | { |
---|
| 526 | return; |
---|
| 527 | } |
---|
[2] | 528 | TComList<TComPic*>::iterator iterPic = pcListPic->begin(); |
---|
| 529 | |
---|
[56] | 530 | iterPic = pcListPic->begin(); |
---|
| 531 | |
---|
[2] | 532 | while (iterPic != pcListPic->end()) |
---|
| 533 | { |
---|
| 534 | TComPic* pcPic = *(iterPic); |
---|
[56] | 535 | #if PIC_CROPPING |
---|
| 536 | TComSPS *sps = pcPic->getSlice(0)->getSPS(); |
---|
| 537 | #endif |
---|
[2] | 538 | |
---|
[56] | 539 | if ( pcPic->getOutputMark() ) |
---|
[2] | 540 | { |
---|
[56] | 541 | // write to file |
---|
| 542 | if ( m_pchReconFile ) |
---|
[2] | 543 | { |
---|
[56] | 544 | #if PIC_CROPPING |
---|
| 545 | m_tVideoIOYuvReconFile[viewDepthId]->write( pcPic->getPicYuvRec(), sps->getPicCropLeftOffset(), sps->getPicCropRightOffset(), sps->getPicCropTopOffset(), sps->getPicCropBottomOffset() ); |
---|
| 546 | #else |
---|
| 547 | m_tVideoIOYuvReconFile[viewDepthId]->write( pcPic->getPicYuvRec(), pcPic->getSlice(0)->getSPS()->getPad() ); |
---|
| 548 | #endif |
---|
[2] | 549 | } |
---|
[56] | 550 | |
---|
| 551 | // update POC of display order |
---|
| 552 | m_pocLastDisplay[viewDepthId] = pcPic->getPOC(); |
---|
| 553 | |
---|
| 554 | // erase non-referenced picture in the reference picture list after display |
---|
| 555 | if ( !pcPic->getSlice(0)->isReferenced() && pcPic->getReconMark() == true ) |
---|
[2] | 556 | { |
---|
[56] | 557 | #if !DYN_REF_FREE |
---|
| 558 | pcPic->setReconMark(false); |
---|
| 559 | |
---|
| 560 | // mark it should be extended later |
---|
| 561 | pcPic->getPicYuvRec()->setBorderExtension( false ); |
---|
| 562 | |
---|
| 563 | #else |
---|
| 564 | pcPic->destroy(); |
---|
| 565 | pcListPic->erase( iterPic ); |
---|
| 566 | iterPic = pcListPic->begin(); // to the beginning, non-efficient way, have to be revised! |
---|
| 567 | continue; |
---|
| 568 | #endif |
---|
[2] | 569 | } |
---|
[56] | 570 | pcPic->setOutputMark(false); |
---|
| 571 | } |
---|
| 572 | |
---|
[2] | 573 | iterPic++; |
---|
| 574 | } |
---|
[56] | 575 | pcListPic->clear(); |
---|
| 576 | m_pocLastDisplay[viewDepthId] = -MAX_INT; |
---|
[2] | 577 | } |
---|
[210] | 578 | #if VIDYO_VPS_INTEGRATION|QC_MVHEVC_B0046 |
---|
[77] | 579 | Void TAppDecTop::increaseNumberOfViews ( UInt layerId, UInt viewId, UInt isDepth ) |
---|
| 580 | #else |
---|
[56] | 581 | Void TAppDecTop::increaseNumberOfViews ( Int newNumberOfViewDepth ) |
---|
[77] | 582 | #endif |
---|
[2] | 583 | { |
---|
[210] | 584 | #if VIDYO_VPS_INTEGRATION|QC_MVHEVC_B0046 |
---|
[77] | 585 | Int newNumberOfViewDepth = layerId + 1; |
---|
| 586 | #endif |
---|
[56] | 587 | if ( m_outputBitDepth == 0 ) |
---|
[2] | 588 | { |
---|
[56] | 589 | m_outputBitDepth = g_uiBitDepth + g_uiBitIncrement; |
---|
[2] | 590 | } |
---|
[210] | 591 | #if !VIDYO_VPS_INTEGRATION&!QC_MVHEVC_B0046 |
---|
[56] | 592 | Int viewId = (newNumberOfViewDepth-1)>>1; // coding order T0D0T1D1T2D2 |
---|
| 593 | Bool isDepth = ((newNumberOfViewDepth % 2) == 0); // coding order T0D0T1D1T2D2 |
---|
[77] | 594 | #endif |
---|
[56] | 595 | if( isDepth ) |
---|
| 596 | m_useDepth = true; |
---|
[105] | 597 | |
---|
| 598 | if ( m_pchReconFile ) |
---|
| 599 | { |
---|
| 600 | while( m_tVideoIOYuvReconFile.size() < newNumberOfViewDepth) |
---|
| 601 | { |
---|
| 602 | m_tVideoIOYuvReconFile.push_back(new TVideoIOYuv); |
---|
| 603 | Char buffer[4]; |
---|
[210] | 604 | #if VIDYO_VPS_INTEGRATION|QC_MVHEVC_B0046 |
---|
[105] | 605 | sprintf(buffer,"_%i", viewId ); |
---|
[81] | 606 | #else |
---|
[105] | 607 | sprintf(buffer,"_%i", (Int)(m_tVideoIOYuvReconFile.size()-1) / 2 ); |
---|
[81] | 608 | #endif |
---|
[105] | 609 | Char* nextFilename = NULL; |
---|
[210] | 610 | #if VIDYO_VPS_INTEGRATION|QC_MVHEVC_B0046 |
---|
[105] | 611 | if( isDepth) |
---|
[81] | 612 | #else |
---|
[105] | 613 | if( (m_tVideoIOYuvReconFile.size() % 2) == 0 ) |
---|
[81] | 614 | #endif |
---|
[105] | 615 | { |
---|
| 616 | Char* pchTempFilename = NULL; |
---|
| 617 | xAppendToFileNameEnd( m_pchReconFile, "_depth", pchTempFilename); |
---|
| 618 | xAppendToFileNameEnd( pchTempFilename, buffer, nextFilename); |
---|
| 619 | free ( pchTempFilename ); |
---|
| 620 | } |
---|
| 621 | else |
---|
| 622 | { |
---|
| 623 | xAppendToFileNameEnd( m_pchReconFile, buffer, nextFilename); |
---|
| 624 | } |
---|
[210] | 625 | #if !VIDYO_VPS_INTEGRATION&!QC_MVHEVC_B0046 |
---|
[105] | 626 | if( isDepth || ( !isDepth && (m_tVideoIOYuvReconFile.size() % 2) == 1 ) ) |
---|
[81] | 627 | #endif |
---|
[105] | 628 | { |
---|
| 629 | m_tVideoIOYuvReconFile.back()->open( nextFilename, true, m_outputBitDepth, g_uiBitDepth + g_uiBitIncrement ); |
---|
| 630 | } |
---|
| 631 | free ( nextFilename ); |
---|
[56] | 632 | } |
---|
[2] | 633 | } |
---|
[105] | 634 | |
---|
[56] | 635 | while( m_pocLastDisplay.size() < newNumberOfViewDepth ) |
---|
| 636 | { |
---|
| 637 | m_pocLastDisplay.push_back(-MAX_INT+m_iSkipFrame); |
---|
| 638 | } |
---|
| 639 | while( m_tDecTop.size() < newNumberOfViewDepth) |
---|
| 640 | { |
---|
| 641 | m_tDecTop.push_back(new TDecTop); |
---|
[210] | 642 | #if !VIDYO_VPS_INTEGRATION&!QC_MVHEVC_B0046 |
---|
[56] | 643 | if( isDepth || ( !isDepth && (m_tVideoIOYuvReconFile.size() % 2) == 1 ) ) |
---|
| 644 | { |
---|
[81] | 645 | #endif |
---|
[56] | 646 | m_tDecTop.back()->create(); |
---|
| 647 | m_tDecTop.back()->init( this, newNumberOfViewDepth == 1); |
---|
| 648 | m_tDecTop.back()->setViewId( viewId ); |
---|
| 649 | m_tDecTop.back()->setIsDepth( isDepth ); |
---|
| 650 | m_tDecTop.back()->setPictureDigestEnabled(m_pictureDigestEnabled); |
---|
[57] | 651 | m_tDecTop.back()->setCamParsCollector( &m_cCamParsCollector ); |
---|
[210] | 652 | #if !VIDYO_VPS_INTEGRATION&!QC_MVHEVC_B0046 |
---|
[56] | 653 | } |
---|
[81] | 654 | #endif |
---|
[56] | 655 | } |
---|
[2] | 656 | } |
---|
| 657 | |
---|
[56] | 658 | TDecTop* TAppDecTop::getTDecTop( Int viewId, Bool isDepth ) |
---|
| 659 | { |
---|
[210] | 660 | #if FLEX_CODING_ORDER_M23723 |
---|
| 661 | Int viewnumber=0; |
---|
| 662 | Int i=0; |
---|
| 663 | Bool fcoFlag=0; |
---|
| 664 | if (viewId>m_fcoViewDepthId) |
---|
| 665 | { |
---|
| 666 | return NULL; |
---|
| 667 | } |
---|
| 668 | else |
---|
| 669 | { |
---|
| 670 | if (isDepth) |
---|
| 671 | { |
---|
| 672 | for ( i=0; i<=m_fcoViewDepthId;i++) |
---|
| 673 | { |
---|
| 674 | if (m_fcoOrder[i]=='D') |
---|
| 675 | { |
---|
| 676 | if (viewnumber==viewId) |
---|
| 677 | { |
---|
| 678 | fcoFlag=1; |
---|
| 679 | break; |
---|
| 680 | } |
---|
| 681 | else |
---|
| 682 | viewnumber++; |
---|
| 683 | } |
---|
| 684 | } |
---|
| 685 | } |
---|
| 686 | else |
---|
| 687 | { |
---|
| 688 | for ( i=0; i<=m_fcoViewDepthId;i++) |
---|
| 689 | { |
---|
| 690 | if (m_fcoOrder[i]=='T') |
---|
| 691 | { |
---|
| 692 | if (viewnumber==viewId) |
---|
| 693 | { |
---|
| 694 | fcoFlag=1; |
---|
| 695 | break; |
---|
| 696 | } |
---|
| 697 | else |
---|
| 698 | viewnumber++; |
---|
| 699 | } |
---|
| 700 | } |
---|
| 701 | } |
---|
| 702 | if (fcoFlag) |
---|
| 703 | { |
---|
| 704 | return m_tDecTop[i]; |
---|
| 705 | } |
---|
| 706 | else |
---|
| 707 | return NULL; |
---|
| 708 | |
---|
| 709 | } |
---|
| 710 | |
---|
| 711 | // coding order T0D0T1D1T2D2 |
---|
| 712 | #else |
---|
[56] | 713 | return m_tDecTop[(isDepth ? 1 : 0) + viewId * 2]; // coding order T0D0T1D1T2D2 |
---|
[210] | 714 | #endif |
---|
| 715 | |
---|
[56] | 716 | } |
---|
[2] | 717 | |
---|
[56] | 718 | std::vector<TComPic*> TAppDecTop::getInterViewRefPics( Int viewId, Int poc, Bool isDepth, TComSPS* sps ) |
---|
[2] | 719 | { |
---|
[56] | 720 | std::vector<TComPic*> apcRefPics( sps->getNumberOfUsableInterViewRefs(), (TComPic*)NULL ); |
---|
| 721 | for( Int k = 0; k < sps->getNumberOfUsableInterViewRefs(); k++ ) |
---|
[2] | 722 | { |
---|
[56] | 723 | TComPic* pcRefPic = xGetPicFromView( sps->getUsableInterViewRef( k ) + viewId, poc, isDepth ); |
---|
[2] | 724 | assert( pcRefPic != NULL ); |
---|
[56] | 725 | apcRefPics[k] = pcRefPic; |
---|
[2] | 726 | } |
---|
| 727 | return apcRefPics; |
---|
| 728 | } |
---|
| 729 | |
---|
[56] | 730 | TComPic* TAppDecTop::xGetPicFromView( Int viewId, Int poc, Bool isDepth ) |
---|
[2] | 731 | { |
---|
[56] | 732 | assert( ( viewId >= 0 ) ); |
---|
| 733 | |
---|
[210] | 734 | #if FLEX_CODING_ORDER_M23723 |
---|
| 735 | if (getTDecTop(viewId,isDepth)) |
---|
| 736 | { |
---|
[56] | 737 | TComList<TComPic*>* apcListPic = getTDecTop( viewId, isDepth )->getListPic(); |
---|
| 738 | TComPic* pcPic = NULL; |
---|
[2] | 739 | for( TComList<TComPic*>::iterator it=apcListPic->begin(); it!=apcListPic->end(); it++ ) |
---|
| 740 | { |
---|
[56] | 741 | if( (*it)->getPOC() == poc ) |
---|
[2] | 742 | { |
---|
[56] | 743 | pcPic = *it; |
---|
[2] | 744 | break; |
---|
| 745 | } |
---|
| 746 | } |
---|
[56] | 747 | return pcPic; |
---|
[2] | 748 | } |
---|
[210] | 749 | else |
---|
| 750 | return NULL; |
---|
| 751 | #else |
---|
| 752 | |
---|
| 753 | TComList<TComPic*>* apcListPic = getTDecTop( viewId, isDepth )->getListPic(); |
---|
| 754 | TComPic* pcPic = NULL; |
---|
| 755 | for( TComList<TComPic*>::iterator it=apcListPic->begin(); it!=apcListPic->end(); it++ ) |
---|
| 756 | { |
---|
| 757 | if( (*it)->getPOC() == poc ) |
---|
| 758 | { |
---|
| 759 | pcPic = *it; |
---|
| 760 | break; |
---|
| 761 | } |
---|
| 762 | } |
---|
| 763 | return pcPic; |
---|
| 764 | #endif |
---|
| 765 | } |
---|
[231] | 766 | |
---|
| 767 | #if MERL_VSP_C0152 |
---|
| 768 | Void TAppDecTop::setBWVSPLUT(TComSlice* pcSlice, Int iCodedViewIdx, Int iCurPoc) |
---|
| 769 | { |
---|
| 770 | //first view does not have VSP |
---|
| 771 | if((iCodedViewIdx == 0)) return; |
---|
| 772 | |
---|
| 773 | AOT( iCodedViewIdx <= 0); |
---|
| 774 | //AOT( iCodedViewIdx >= m_iNumberOfViews ); |
---|
| 775 | Int iNeighborViewId = 0; |
---|
| 776 | // Int* piShiftLUT = bRenderFromLeft ? m_cCamParsCollector.getBaseViewShiftLUTI()[iCodedViewIdx][iNeighborViewId][0] : m_cCamParsCollector.getBaseViewShiftLUTI()[iNeighborViewId][iCodedViewIdx][0]; |
---|
| 777 | Int* piShiftLUT = m_cCamParsCollector.getBaseViewShiftLUTI()[iNeighborViewId][iCodedViewIdx][0]; |
---|
| 778 | pcSlice->setBWVSPLUTParam(piShiftLUT, 2-LOG2_DISP_PREC_LUT ); |
---|
| 779 | } |
---|
| 780 | #endif |
---|
| 781 | |
---|
[56] | 782 | //! \} |
---|