| 1 | /* The copyright in this software is being made available under the BSD |
|---|
| 2 | * License, included below. This software may be subject to other third party |
|---|
| 3 | * and contributor rights, including patent rights, and no such rights are |
|---|
| 4 | * granted under this license. |
|---|
| 5 | * |
|---|
| 6 | * Copyright (c) 2010-2012, ITU/ISO/IEC |
|---|
| 7 | * All rights reserved. |
|---|
| 8 | * |
|---|
| 9 | * Redistribution and use in source and binary forms, with or without |
|---|
| 10 | * modification, are permitted provided that the following conditions are met: |
|---|
| 11 | * |
|---|
| 12 | * * Redistributions of source code must retain the above copyright notice, |
|---|
| 13 | * this list of conditions and the following disclaimer. |
|---|
| 14 | * * Redistributions in binary form must reproduce the above copyright notice, |
|---|
| 15 | * this list of conditions and the following disclaimer in the documentation |
|---|
| 16 | * and/or other materials provided with the distribution. |
|---|
| 17 | * * Neither the name of the ITU/ISO/IEC nor the names of its contributors may |
|---|
| 18 | * be used to endorse or promote products derived from this software without |
|---|
| 19 | * specific prior written permission. |
|---|
| 20 | * |
|---|
| 21 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
|---|
| 22 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
|---|
| 23 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
|---|
| 24 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS |
|---|
| 25 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
|---|
| 26 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
|---|
| 27 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
|---|
| 28 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
|---|
| 29 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
|---|
| 30 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF |
|---|
| 31 | * THE POSSIBILITY OF SUCH DAMAGE. |
|---|
| 32 | */ |
|---|
| 33 | |
|---|
| 34 | /** \file TAppDecTop.cpp |
|---|
| 35 | \brief Decoder application class |
|---|
| 36 | */ |
|---|
| 37 | |
|---|
| 38 | #include <list> |
|---|
| 39 | #include <vector> |
|---|
| 40 | #include <stdio.h> |
|---|
| 41 | #include <fcntl.h> |
|---|
| 42 | #include <assert.h> |
|---|
| 43 | |
|---|
| 44 | #include "TAppDecTop.h" |
|---|
| 45 | #include "TLibDecoder/AnnexBread.h" |
|---|
| 46 | #include "TLibDecoder/NALread.h" |
|---|
| 47 | |
|---|
| 48 | //! \ingroup TAppDecoder |
|---|
| 49 | //! \{ |
|---|
| 50 | |
|---|
| 51 | // ==================================================================================================================== |
|---|
| 52 | // Constructor / destructor / initialization / destroy |
|---|
| 53 | // ==================================================================================================================== |
|---|
| 54 | |
|---|
| 55 | TAppDecTop::TAppDecTop() |
|---|
| 56 | { |
|---|
| 57 | ::memset (m_abDecFlag, 0, sizeof (m_abDecFlag)); |
|---|
| 58 | m_useDepth = false; |
|---|
| 59 | m_pScaleOffsetFile = 0; |
|---|
| 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 | { |
|---|
| 84 | #if VIDYO_VPS_INTEGRATION|QC_MVHEVC_B0046 |
|---|
| 85 | increaseNumberOfViews( 0, 0, 0 ); |
|---|
| 86 | #else |
|---|
| 87 | increaseNumberOfViews( 1 ); |
|---|
| 88 | #endif |
|---|
| 89 | |
|---|
| 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 | |
|---|
| 98 | #if SONY_COLPIC_AVAILABILITY |
|---|
| 99 | m_tDecTop[0]->setViewOrderIdx(0); |
|---|
| 100 | #endif |
|---|
| 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; |
|---|
| 112 | #if FLEX_CODING_ORDER_M23723 |
|---|
| 113 | m_fcoOrder[i]=NULL; |
|---|
| 114 | #endif |
|---|
| 115 | |
|---|
| 116 | } |
|---|
| 117 | |
|---|
| 118 | ifstream bitstreamFile(m_pchBitstreamFile, ifstream::in | ifstream::binary); |
|---|
| 119 | if (!bitstreamFile) |
|---|
| 120 | { |
|---|
| 121 | fprintf(stderr, "\nfailed to open bitstream file `%s' for reading\n", m_pchBitstreamFile); |
|---|
| 122 | exit(EXIT_FAILURE); |
|---|
| 123 | } |
|---|
| 124 | |
|---|
| 125 | if( m_pchScaleOffsetFile ) |
|---|
| 126 | { |
|---|
| 127 | m_pScaleOffsetFile = ::fopen( m_pchScaleOffsetFile, "wt" ); |
|---|
| 128 | AOF( m_pScaleOffsetFile ); |
|---|
| 129 | } |
|---|
| 130 | m_cCamParsCollector.init( m_pScaleOffsetFile ); |
|---|
| 131 | |
|---|
| 132 | InputByteStream bytestream(bitstreamFile); |
|---|
| 133 | |
|---|
| 134 | while (!!bitstreamFile) |
|---|
| 135 | { |
|---|
| 136 | /* location serves to work around a design fault in the decoder, whereby |
|---|
| 137 | * the process of reading a new slice that is the first slice of a new frame |
|---|
| 138 | * requires the TDecTop::decode() method to be called again with the same |
|---|
| 139 | * nal unit. */ |
|---|
| 140 | streampos location = bitstreamFile.tellg(); |
|---|
| 141 | AnnexBStats stats = AnnexBStats(); |
|---|
| 142 | vector<uint8_t> nalUnit; |
|---|
| 143 | InputNALUnit nalu; |
|---|
| 144 | byteStreamNALUnit(bytestream, nalUnit, stats); |
|---|
| 145 | |
|---|
| 146 | // call actual decoding function |
|---|
| 147 | if (nalUnit.empty()) |
|---|
| 148 | { |
|---|
| 149 | /* this can happen if the following occur: |
|---|
| 150 | * - empty input file |
|---|
| 151 | * - two back-to-back start_code_prefixes |
|---|
| 152 | * - start_code_prefix immediately followed by EOF |
|---|
| 153 | */ |
|---|
| 154 | fprintf(stderr, "Warning: Attempt to decode an empty NAL unit\n"); |
|---|
| 155 | } |
|---|
| 156 | else |
|---|
| 157 | { |
|---|
| 158 | read(nalu, nalUnit); |
|---|
| 159 | #if QC_MVHEVC_B0046 |
|---|
| 160 | viewDepthId = nalu.m_layerId; |
|---|
| 161 | Int depth = 0; |
|---|
| 162 | Int viewId = viewDepthId; |
|---|
| 163 | #else |
|---|
| 164 | #if VIDYO_VPS_INTEGRATION |
|---|
| 165 | Int viewId = 0; |
|---|
| 166 | Int depth = 0; |
|---|
| 167 | |
|---|
| 168 | if(nalu.m_nalUnitType != NAL_UNIT_VPS || nalu.m_layerId) |
|---|
| 169 | { |
|---|
| 170 | // code assumes that the first nal unit is VPS |
|---|
| 171 | // currently, this is a hack that requires non-first VPSs have non-zero layer_id |
|---|
| 172 | viewId = getVPSAccess()->getActiveVPS()->getViewId(nalu.m_layerId); |
|---|
| 173 | depth = getVPSAccess()->getActiveVPS()->getDepthFlag(nalu.m_layerId); |
|---|
| 174 | } |
|---|
| 175 | #if FLEX_CODING_ORDER_M23723 |
|---|
| 176 | if (viewId>0) |
|---|
| 177 | { |
|---|
| 178 | viewIdZero=false; |
|---|
| 179 | } |
|---|
| 180 | if (viewIdZero==false&&viewId==0) |
|---|
| 181 | { |
|---|
| 182 | 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 |
|---|
| 183 | } |
|---|
| 184 | if (firstFrame) |
|---|
| 185 | { // if the current view is first frame, we set the viewDepthId as texture plus depth and get the FCO order |
|---|
| 186 | viewDepthId = iDepthViewIdx+iTextureViewIdx; |
|---|
| 187 | m_fcoViewDepthId=viewDepthId; |
|---|
| 188 | } |
|---|
| 189 | else |
|---|
| 190 | {//if current view is not first frame, we set the viewDepthId depended on the FCO order |
|---|
| 191 | viewDepthId=0; |
|---|
| 192 | if (depth) |
|---|
| 193 | { |
|---|
| 194 | for (fcoIndex=0;fcoIndex<2*MAX_VIEW_NUM;fcoIndex++ ) |
|---|
| 195 | { |
|---|
| 196 | if (m_fcoOrder[fcoIndex]=='D') |
|---|
| 197 | { |
|---|
| 198 | if (viewId==viewDepthId) |
|---|
| 199 | break; |
|---|
| 200 | else |
|---|
| 201 | viewDepthId++; |
|---|
| 202 | } |
|---|
| 203 | } |
|---|
| 204 | } |
|---|
| 205 | else |
|---|
| 206 | { |
|---|
| 207 | for (fcoIndex=0;fcoIndex<2*MAX_VIEW_NUM;fcoIndex++ ) |
|---|
| 208 | { |
|---|
| 209 | if (m_fcoOrder[fcoIndex]=='T') |
|---|
| 210 | { |
|---|
| 211 | if (viewId==viewDepthId) |
|---|
| 212 | break; |
|---|
| 213 | else |
|---|
| 214 | viewDepthId++; |
|---|
| 215 | } |
|---|
| 216 | } |
|---|
| 217 | } |
|---|
| 218 | |
|---|
| 219 | viewDepthId=fcoIndex; |
|---|
| 220 | |
|---|
| 221 | } |
|---|
| 222 | |
|---|
| 223 | |
|---|
| 224 | #else |
|---|
| 225 | viewDepthId = nalu.m_layerId; // coding order T0D0T1D1T2D2 |
|---|
| 226 | #endif |
|---|
| 227 | |
|---|
| 228 | #else |
|---|
| 229 | Int viewId = nalu.m_viewId; |
|---|
| 230 | Int depth = nalu.m_isDepth ? 1 : 0; |
|---|
| 231 | #if FLEX_CODING_ORDER_M23723 |
|---|
| 232 | if (viewId>0) |
|---|
| 233 | { |
|---|
| 234 | viewIdZero=false; |
|---|
| 235 | } |
|---|
| 236 | if (viewIdZero==false&&viewId==0) |
|---|
| 237 | { |
|---|
| 238 | firstFrame=0; |
|---|
| 239 | } |
|---|
| 240 | if (firstFrame) |
|---|
| 241 | { |
|---|
| 242 | viewDepthId = iDepthViewIdx+iTextureViewIdx; |
|---|
| 243 | m_fcoViewDepthId=viewDepthId; |
|---|
| 244 | } |
|---|
| 245 | else |
|---|
| 246 | { |
|---|
| 247 | viewDepthId=0; |
|---|
| 248 | if (depth) |
|---|
| 249 | { |
|---|
| 250 | for (fcoIndex=0;fcoIndex<2*MAX_VIEW_NUM;fcoIndex++ ) |
|---|
| 251 | { |
|---|
| 252 | if (m_fcoOrder[fcoIndex]=='D') |
|---|
| 253 | { |
|---|
| 254 | if (viewId==viewDepthId) |
|---|
| 255 | break; |
|---|
| 256 | else |
|---|
| 257 | viewDepthId++; |
|---|
| 258 | } |
|---|
| 259 | } |
|---|
| 260 | } |
|---|
| 261 | else |
|---|
| 262 | { |
|---|
| 263 | for (fcoIndex=0;fcoIndex<2*MAX_VIEW_NUM;fcoIndex++ ) |
|---|
| 264 | { |
|---|
| 265 | if (m_fcoOrder[fcoIndex]=='T') |
|---|
| 266 | { |
|---|
| 267 | if (viewId==viewDepthId) |
|---|
| 268 | break; |
|---|
| 269 | else |
|---|
| 270 | viewDepthId++; |
|---|
| 271 | } |
|---|
| 272 | } |
|---|
| 273 | } |
|---|
| 274 | viewDepthId=fcoIndex; |
|---|
| 275 | } |
|---|
| 276 | #else |
|---|
| 277 | viewDepthId = viewId * 2 + depth; // coding order T0D0T1D1T2D2 |
|---|
| 278 | #endif |
|---|
| 279 | #endif |
|---|
| 280 | #endif |
|---|
| 281 | newPicture[viewDepthId] = false; |
|---|
| 282 | if( viewDepthId >= m_tDecTop.size() ) |
|---|
| 283 | { |
|---|
| 284 | #if VIDYO_VPS_INTEGRATION|QC_MVHEVC_B0046 |
|---|
| 285 | increaseNumberOfViews( viewDepthId, viewId, depth ); |
|---|
| 286 | #else |
|---|
| 287 | increaseNumberOfViews( viewDepthId +1 ); |
|---|
| 288 | #endif |
|---|
| 289 | } |
|---|
| 290 | if(m_iMaxTemporalLayer >= 0 && nalu.m_temporalId > m_iMaxTemporalLayer) |
|---|
| 291 | { |
|---|
| 292 | previousPictureDecoded = false; |
|---|
| 293 | } |
|---|
| 294 | if(m_tDecTop.size() > 1 && (viewDepthId != previousViewDepthId) && previousPictureDecoded ) |
|---|
| 295 | { |
|---|
| 296 | m_tDecTop[previousViewDepthId]->executeDeblockAndAlf(uiPOC[previousViewDepthId], pcListPic[previousViewDepthId], m_iSkipFrame, m_pocLastDisplay[previousViewDepthId]); |
|---|
| 297 | } |
|---|
| 298 | if( ( viewDepthId == 0 && (viewDepthId != previousViewDepthId) ) || m_tDecTop.size() == 1 ) |
|---|
| 299 | { |
|---|
| 300 | #if HHI_INTER_VIEW_RESIDUAL_PRED |
|---|
| 301 | for( Int i = 0; i < m_tDecTop.size(); i++ ) |
|---|
| 302 | { |
|---|
| 303 | m_tDecTop[i]->deleteExtraPicBuffers( uiPOC[i] ); |
|---|
| 304 | } |
|---|
| 305 | #endif |
|---|
| 306 | for( Int i = 0; i < m_tDecTop.size(); i++ ) |
|---|
| 307 | { |
|---|
| 308 | m_tDecTop[i]->compressMotion( uiPOC[i] ); |
|---|
| 309 | } |
|---|
| 310 | } |
|---|
| 311 | if( !(m_iMaxTemporalLayer >= 0 && nalu.m_temporalId > m_iMaxTemporalLayer) ) |
|---|
| 312 | { |
|---|
| 313 | #if QC_MVHEVC_B0046 |
|---|
| 314 | if(viewDepthId && m_tDecTop[viewDepthId]->m_bFirstNal== false) |
|---|
| 315 | { |
|---|
| 316 | m_tDecTop[viewDepthId]->m_bFirstNal = true; |
|---|
| 317 | ParameterSetManagerDecoder* pDecV0 = m_tDecTop[0]->xGetParaSetDec(); |
|---|
| 318 | m_tDecTop[viewDepthId]->xCopyVPS(pDecV0->getPrefetchedVPS(0)); |
|---|
| 319 | m_tDecTop[viewDepthId]->xCopySPS(pDecV0->getPrefetchedSPS(0)); |
|---|
| 320 | m_tDecTop[viewDepthId]->xCopyPPS(pDecV0->getPrefetchedPPS(0)); |
|---|
| 321 | } |
|---|
| 322 | #endif |
|---|
| 323 | newPicture[viewDepthId] = m_tDecTop[viewDepthId]->decode(nalu, m_iSkipFrame, m_pocLastDisplay[viewDepthId]); |
|---|
| 324 | if (newPicture[viewDepthId]) |
|---|
| 325 | { |
|---|
| 326 | bitstreamFile.clear(); |
|---|
| 327 | /* location points to the current nalunit payload[1] due to the |
|---|
| 328 | * need for the annexB parser to read three extra bytes. |
|---|
| 329 | * [1] except for the first NAL unit in the file |
|---|
| 330 | * (but bNewPicture doesn't happen then) */ |
|---|
| 331 | bitstreamFile.seekg(location-streamoff(3)); |
|---|
| 332 | bytestream.reset(); |
|---|
| 333 | } |
|---|
| 334 | if( nalu.isSlice() ) |
|---|
| 335 | { |
|---|
| 336 | previousPictureDecoded = true; |
|---|
| 337 | #if FLEX_CODING_ORDER_M23723 |
|---|
| 338 | if (firstFrame) |
|---|
| 339 | { |
|---|
| 340 | if (depth) |
|---|
| 341 | { |
|---|
| 342 | iDepthViewIdx++; |
|---|
| 343 | m_fcoOrder[viewDepthId]='D'; |
|---|
| 344 | } |
|---|
| 345 | else |
|---|
| 346 | { |
|---|
| 347 | iTextureViewIdx++; |
|---|
| 348 | m_fcoOrder[viewDepthId]='T'; |
|---|
| 349 | } |
|---|
| 350 | } |
|---|
| 351 | |
|---|
| 352 | #endif |
|---|
| 353 | } |
|---|
| 354 | } |
|---|
| 355 | } |
|---|
| 356 | if( ( (newPicture[viewDepthId] || !bitstreamFile) && m_tDecTop.size() == 1) || (!bitstreamFile && previousPictureDecoded == true) ) |
|---|
| 357 | { |
|---|
| 358 | m_tDecTop[viewDepthId]->executeDeblockAndAlf(uiPOC[viewDepthId], pcListPic[viewDepthId], m_iSkipFrame, m_pocLastDisplay[viewDepthId]); |
|---|
| 359 | } |
|---|
| 360 | if( pcListPic[viewDepthId] ) |
|---|
| 361 | { |
|---|
| 362 | #if QC_REM_IDV_B0046 |
|---|
| 363 | Int iviewId = m_tDecTop[viewDepthId]->getViewId(); |
|---|
| 364 | 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)) ) |
|---|
| 365 | #else |
|---|
| 366 | 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)) ) |
|---|
| 367 | #endif |
|---|
| 368 | { |
|---|
| 369 | xFlushOutput( pcListPic[viewDepthId], viewDepthId ); |
|---|
| 370 | } |
|---|
| 371 | // write reconstruction to file |
|---|
| 372 | if(newPicture[viewDepthId]) |
|---|
| 373 | { |
|---|
| 374 | #if H0567_DPB_PARAMETERS_PER_TEMPORAL_LAYER |
|---|
| 375 | xWriteOutput( pcListPic[viewDepthId], viewDepthId, nalu.m_temporalId ); |
|---|
| 376 | #else |
|---|
| 377 | xWriteOutput( pcListPic[viewDepthId], viewDepthId ); |
|---|
| 378 | #endif |
|---|
| 379 | } |
|---|
| 380 | } |
|---|
| 381 | previousViewDepthId = viewDepthId; |
|---|
| 382 | } |
|---|
| 383 | if( m_cCamParsCollector.isInitialized() ) |
|---|
| 384 | { |
|---|
| 385 | m_cCamParsCollector.setSlice( 0 ); |
|---|
| 386 | } |
|---|
| 387 | // last frame |
|---|
| 388 | for( Int viewDepthIdx = 0; viewDepthIdx < m_tDecTop.size(); viewDepthIdx++ ) |
|---|
| 389 | { |
|---|
| 390 | xFlushOutput( pcListPic[viewDepthIdx], viewDepthIdx ); |
|---|
| 391 | } |
|---|
| 392 | xDestroyDecLib(); |
|---|
| 393 | } |
|---|
| 394 | |
|---|
| 395 | // ==================================================================================================================== |
|---|
| 396 | // Protected member functions |
|---|
| 397 | // ==================================================================================================================== |
|---|
| 398 | |
|---|
| 399 | Void TAppDecTop::xDestroyDecLib() |
|---|
| 400 | { |
|---|
| 401 | |
|---|
| 402 | for(Int viewDepthIdx=0; viewDepthIdx<m_tVideoIOYuvReconFile.size() ; viewDepthIdx++) |
|---|
| 403 | { |
|---|
| 404 | if( m_tVideoIOYuvReconFile[viewDepthIdx] ) |
|---|
| 405 | { |
|---|
| 406 | m_tVideoIOYuvReconFile[viewDepthIdx]->close(); |
|---|
| 407 | delete m_tVideoIOYuvReconFile[viewDepthIdx]; |
|---|
| 408 | m_tVideoIOYuvReconFile[viewDepthIdx] = NULL ; |
|---|
| 409 | } |
|---|
| 410 | } |
|---|
| 411 | |
|---|
| 412 | for(Int viewDepthIdx=0; viewDepthIdx<m_tDecTop.size() ; viewDepthIdx++) |
|---|
| 413 | { |
|---|
| 414 | if( m_tDecTop[viewDepthIdx] ) |
|---|
| 415 | { |
|---|
| 416 | if( !m_useDepth && (viewDepthIdx % 2 == 1) ) |
|---|
| 417 | { |
|---|
| 418 | } |
|---|
| 419 | else |
|---|
| 420 | { |
|---|
| 421 | m_tDecTop[viewDepthIdx]->deletePicBuffer(); |
|---|
| 422 | m_tDecTop[viewDepthIdx]->destroy() ; |
|---|
| 423 | } |
|---|
| 424 | #if QC_MVHEVC_B0046 |
|---|
| 425 | if(viewDepthIdx) |
|---|
| 426 | { |
|---|
| 427 | //Call clear function to remove the record, which has been freed during viewDepthIdx = 0 case. |
|---|
| 428 | m_tDecTop[viewDepthIdx]->xGetParaSetDec()->clearSPS(); |
|---|
| 429 | m_tDecTop[viewDepthIdx]->xGetParaSetDec()->clearVPS(); |
|---|
| 430 | m_tDecTop[viewDepthIdx]->xGetParaSetDec()->clearPPS(); |
|---|
| 431 | } |
|---|
| 432 | #endif |
|---|
| 433 | delete m_tDecTop[viewDepthIdx] ; |
|---|
| 434 | m_tDecTop[viewDepthIdx] = NULL ; |
|---|
| 435 | } |
|---|
| 436 | } |
|---|
| 437 | |
|---|
| 438 | m_cCamParsCollector.uninit(); |
|---|
| 439 | if( m_pScaleOffsetFile ) |
|---|
| 440 | { |
|---|
| 441 | ::fclose( m_pScaleOffsetFile ); |
|---|
| 442 | } |
|---|
| 443 | } |
|---|
| 444 | |
|---|
| 445 | #if H0567_DPB_PARAMETERS_PER_TEMPORAL_LAYER |
|---|
| 446 | Void TAppDecTop::xWriteOutput( TComList<TComPic*>* pcListPic, Int viewDepthId, UInt tId ) |
|---|
| 447 | #else |
|---|
| 448 | Void TAppDecTop::xWriteOutput( TComList<TComPic*>* pcListPic, Int viewDepthId ) |
|---|
| 449 | #endif |
|---|
| 450 | { |
|---|
| 451 | TComList<TComPic*>::iterator iterPic = pcListPic->begin(); |
|---|
| 452 | Int not_displayed = 0; |
|---|
| 453 | |
|---|
| 454 | while (iterPic != pcListPic->end()) |
|---|
| 455 | { |
|---|
| 456 | TComPic* pcPic = *(iterPic); |
|---|
| 457 | if(pcPic->getOutputMark() && pcPic->getPOC() > m_pocLastDisplay[viewDepthId]) |
|---|
| 458 | { |
|---|
| 459 | not_displayed++; |
|---|
| 460 | } |
|---|
| 461 | iterPic++; |
|---|
| 462 | } |
|---|
| 463 | iterPic = pcListPic->begin(); |
|---|
| 464 | |
|---|
| 465 | while (iterPic != pcListPic->end()) |
|---|
| 466 | { |
|---|
| 467 | TComPic* pcPic = *(iterPic); |
|---|
| 468 | #if PIC_CROPPING |
|---|
| 469 | TComSPS *sps = pcPic->getSlice(0)->getSPS(); |
|---|
| 470 | #endif |
|---|
| 471 | |
|---|
| 472 | #if H0567_DPB_PARAMETERS_PER_TEMPORAL_LAYER |
|---|
| 473 | if ( pcPic->getOutputMark() && (not_displayed > pcPic->getSlice(0)->getSPS()->getNumReorderPics(tId) && pcPic->getPOC() > m_pocLastDisplay[viewDepthId])) |
|---|
| 474 | #else |
|---|
| 475 | if ( pcPic->getOutputMark() && (not_displayed > pcPic->getSlice(0)->getSPS()->getNumReorderFrames() && pcPic->getPOC() > m_pocLastDisplay[viewDepthId])) |
|---|
| 476 | #endif |
|---|
| 477 | { |
|---|
| 478 | // write to file |
|---|
| 479 | not_displayed--; |
|---|
| 480 | if ( m_pchReconFile ) |
|---|
| 481 | { |
|---|
| 482 | #if PIC_CROPPING |
|---|
| 483 | m_tVideoIOYuvReconFile[viewDepthId]->write( pcPic->getPicYuvRec(), sps->getPicCropLeftOffset(), sps->getPicCropRightOffset(), sps->getPicCropTopOffset(), sps->getPicCropBottomOffset() ); |
|---|
| 484 | #else |
|---|
| 485 | m_tVideoIOYuvReconFile[viewDepthId]->write( pcPic->getPicYuvRec(), pcPic->getSlice(0)->getSPS()->getPad() ); |
|---|
| 486 | #endif |
|---|
| 487 | } |
|---|
| 488 | |
|---|
| 489 | // update POC of display order |
|---|
| 490 | m_pocLastDisplay[viewDepthId] = pcPic->getPOC(); |
|---|
| 491 | |
|---|
| 492 | // erase non-referenced picture in the reference picture list after display |
|---|
| 493 | if ( !pcPic->getSlice(0)->isReferenced() && pcPic->getReconMark() == true ) |
|---|
| 494 | { |
|---|
| 495 | #if !DYN_REF_FREE |
|---|
| 496 | pcPic->setReconMark(false); |
|---|
| 497 | |
|---|
| 498 | // mark it should be extended later |
|---|
| 499 | pcPic->getPicYuvRec()->setBorderExtension( false ); |
|---|
| 500 | |
|---|
| 501 | #else |
|---|
| 502 | pcPic->destroy(); |
|---|
| 503 | pcListPic->erase( iterPic ); |
|---|
| 504 | iterPic = pcListPic->begin(); // to the beginning, non-efficient way, have to be revised! |
|---|
| 505 | continue; |
|---|
| 506 | #endif |
|---|
| 507 | } |
|---|
| 508 | pcPic->setOutputMark(false); |
|---|
| 509 | } |
|---|
| 510 | |
|---|
| 511 | iterPic++; |
|---|
| 512 | } |
|---|
| 513 | } |
|---|
| 514 | |
|---|
| 515 | /** \param pcListPic list of pictures to be written to file |
|---|
| 516 | \todo DYN_REF_FREE should be revised |
|---|
| 517 | */ |
|---|
| 518 | Void TAppDecTop::xFlushOutput( TComList<TComPic*>* pcListPic, Int viewDepthId ) |
|---|
| 519 | { |
|---|
| 520 | if(!pcListPic) |
|---|
| 521 | { |
|---|
| 522 | return; |
|---|
| 523 | } |
|---|
| 524 | TComList<TComPic*>::iterator iterPic = pcListPic->begin(); |
|---|
| 525 | |
|---|
| 526 | iterPic = pcListPic->begin(); |
|---|
| 527 | |
|---|
| 528 | while (iterPic != pcListPic->end()) |
|---|
| 529 | { |
|---|
| 530 | TComPic* pcPic = *(iterPic); |
|---|
| 531 | #if PIC_CROPPING |
|---|
| 532 | TComSPS *sps = pcPic->getSlice(0)->getSPS(); |
|---|
| 533 | #endif |
|---|
| 534 | |
|---|
| 535 | if ( pcPic->getOutputMark() ) |
|---|
| 536 | { |
|---|
| 537 | // write to file |
|---|
| 538 | if ( m_pchReconFile ) |
|---|
| 539 | { |
|---|
| 540 | #if PIC_CROPPING |
|---|
| 541 | m_tVideoIOYuvReconFile[viewDepthId]->write( pcPic->getPicYuvRec(), sps->getPicCropLeftOffset(), sps->getPicCropRightOffset(), sps->getPicCropTopOffset(), sps->getPicCropBottomOffset() ); |
|---|
| 542 | #else |
|---|
| 543 | m_tVideoIOYuvReconFile[viewDepthId]->write( pcPic->getPicYuvRec(), pcPic->getSlice(0)->getSPS()->getPad() ); |
|---|
| 544 | #endif |
|---|
| 545 | } |
|---|
| 546 | |
|---|
| 547 | // update POC of display order |
|---|
| 548 | m_pocLastDisplay[viewDepthId] = pcPic->getPOC(); |
|---|
| 549 | |
|---|
| 550 | // erase non-referenced picture in the reference picture list after display |
|---|
| 551 | if ( !pcPic->getSlice(0)->isReferenced() && pcPic->getReconMark() == true ) |
|---|
| 552 | { |
|---|
| 553 | #if !DYN_REF_FREE |
|---|
| 554 | pcPic->setReconMark(false); |
|---|
| 555 | |
|---|
| 556 | // mark it should be extended later |
|---|
| 557 | pcPic->getPicYuvRec()->setBorderExtension( false ); |
|---|
| 558 | |
|---|
| 559 | #else |
|---|
| 560 | pcPic->destroy(); |
|---|
| 561 | pcListPic->erase( iterPic ); |
|---|
| 562 | iterPic = pcListPic->begin(); // to the beginning, non-efficient way, have to be revised! |
|---|
| 563 | continue; |
|---|
| 564 | #endif |
|---|
| 565 | } |
|---|
| 566 | pcPic->setOutputMark(false); |
|---|
| 567 | } |
|---|
| 568 | |
|---|
| 569 | iterPic++; |
|---|
| 570 | } |
|---|
| 571 | pcListPic->clear(); |
|---|
| 572 | m_pocLastDisplay[viewDepthId] = -MAX_INT; |
|---|
| 573 | } |
|---|
| 574 | #if VIDYO_VPS_INTEGRATION|QC_MVHEVC_B0046 |
|---|
| 575 | Void TAppDecTop::increaseNumberOfViews ( UInt layerId, UInt viewId, UInt isDepth ) |
|---|
| 576 | #else |
|---|
| 577 | Void TAppDecTop::increaseNumberOfViews ( Int newNumberOfViewDepth ) |
|---|
| 578 | #endif |
|---|
| 579 | { |
|---|
| 580 | #if VIDYO_VPS_INTEGRATION|QC_MVHEVC_B0046 |
|---|
| 581 | Int newNumberOfViewDepth = layerId + 1; |
|---|
| 582 | #endif |
|---|
| 583 | if ( m_outputBitDepth == 0 ) |
|---|
| 584 | { |
|---|
| 585 | m_outputBitDepth = g_uiBitDepth + g_uiBitIncrement; |
|---|
| 586 | } |
|---|
| 587 | #if !VIDYO_VPS_INTEGRATION&!QC_MVHEVC_B0046 |
|---|
| 588 | Int viewId = (newNumberOfViewDepth-1)>>1; // coding order T0D0T1D1T2D2 |
|---|
| 589 | Bool isDepth = ((newNumberOfViewDepth % 2) == 0); // coding order T0D0T1D1T2D2 |
|---|
| 590 | #endif |
|---|
| 591 | if( isDepth ) |
|---|
| 592 | m_useDepth = true; |
|---|
| 593 | |
|---|
| 594 | if ( m_pchReconFile ) |
|---|
| 595 | { |
|---|
| 596 | while( m_tVideoIOYuvReconFile.size() < newNumberOfViewDepth) |
|---|
| 597 | { |
|---|
| 598 | m_tVideoIOYuvReconFile.push_back(new TVideoIOYuv); |
|---|
| 599 | Char buffer[4]; |
|---|
| 600 | #if VIDYO_VPS_INTEGRATION|QC_MVHEVC_B0046 |
|---|
| 601 | sprintf(buffer,"_%i", viewId ); |
|---|
| 602 | #else |
|---|
| 603 | sprintf(buffer,"_%i", (Int)(m_tVideoIOYuvReconFile.size()-1) / 2 ); |
|---|
| 604 | #endif |
|---|
| 605 | Char* nextFilename = NULL; |
|---|
| 606 | #if VIDYO_VPS_INTEGRATION|QC_MVHEVC_B0046 |
|---|
| 607 | if( isDepth) |
|---|
| 608 | #else |
|---|
| 609 | if( (m_tVideoIOYuvReconFile.size() % 2) == 0 ) |
|---|
| 610 | #endif |
|---|
| 611 | { |
|---|
| 612 | Char* pchTempFilename = NULL; |
|---|
| 613 | xAppendToFileNameEnd( m_pchReconFile, "_depth", pchTempFilename); |
|---|
| 614 | xAppendToFileNameEnd( pchTempFilename, buffer, nextFilename); |
|---|
| 615 | free ( pchTempFilename ); |
|---|
| 616 | } |
|---|
| 617 | else |
|---|
| 618 | { |
|---|
| 619 | xAppendToFileNameEnd( m_pchReconFile, buffer, nextFilename); |
|---|
| 620 | } |
|---|
| 621 | #if !VIDYO_VPS_INTEGRATION&!QC_MVHEVC_B0046 |
|---|
| 622 | if( isDepth || ( !isDepth && (m_tVideoIOYuvReconFile.size() % 2) == 1 ) ) |
|---|
| 623 | #endif |
|---|
| 624 | { |
|---|
| 625 | m_tVideoIOYuvReconFile.back()->open( nextFilename, true, m_outputBitDepth, g_uiBitDepth + g_uiBitIncrement ); |
|---|
| 626 | } |
|---|
| 627 | free ( nextFilename ); |
|---|
| 628 | } |
|---|
| 629 | } |
|---|
| 630 | |
|---|
| 631 | while( m_pocLastDisplay.size() < newNumberOfViewDepth ) |
|---|
| 632 | { |
|---|
| 633 | m_pocLastDisplay.push_back(-MAX_INT+m_iSkipFrame); |
|---|
| 634 | } |
|---|
| 635 | while( m_tDecTop.size() < newNumberOfViewDepth) |
|---|
| 636 | { |
|---|
| 637 | m_tDecTop.push_back(new TDecTop); |
|---|
| 638 | #if !VIDYO_VPS_INTEGRATION&!QC_MVHEVC_B0046 |
|---|
| 639 | if( isDepth || ( !isDepth && (m_tVideoIOYuvReconFile.size() % 2) == 1 ) ) |
|---|
| 640 | { |
|---|
| 641 | #endif |
|---|
| 642 | m_tDecTop.back()->create(); |
|---|
| 643 | m_tDecTop.back()->init( this, newNumberOfViewDepth == 1); |
|---|
| 644 | m_tDecTop.back()->setViewId( viewId ); |
|---|
| 645 | m_tDecTop.back()->setIsDepth( isDepth ); |
|---|
| 646 | m_tDecTop.back()->setPictureDigestEnabled(m_pictureDigestEnabled); |
|---|
| 647 | m_tDecTop.back()->setCamParsCollector( &m_cCamParsCollector ); |
|---|
| 648 | #if !VIDYO_VPS_INTEGRATION&!QC_MVHEVC_B0046 |
|---|
| 649 | } |
|---|
| 650 | #endif |
|---|
| 651 | } |
|---|
| 652 | } |
|---|
| 653 | |
|---|
| 654 | TDecTop* TAppDecTop::getTDecTop( Int viewId, Bool isDepth ) |
|---|
| 655 | { |
|---|
| 656 | #if FLEX_CODING_ORDER_M23723 |
|---|
| 657 | Int viewnumber=0; |
|---|
| 658 | Int i=0; |
|---|
| 659 | Bool fcoFlag=0; |
|---|
| 660 | if (viewId>m_fcoViewDepthId) |
|---|
| 661 | { |
|---|
| 662 | return NULL; |
|---|
| 663 | } |
|---|
| 664 | else |
|---|
| 665 | { |
|---|
| 666 | if (isDepth) |
|---|
| 667 | { |
|---|
| 668 | for ( i=0; i<=m_fcoViewDepthId;i++) |
|---|
| 669 | { |
|---|
| 670 | if (m_fcoOrder[i]=='D') |
|---|
| 671 | { |
|---|
| 672 | if (viewnumber==viewId) |
|---|
| 673 | { |
|---|
| 674 | fcoFlag=1; |
|---|
| 675 | break; |
|---|
| 676 | } |
|---|
| 677 | else |
|---|
| 678 | viewnumber++; |
|---|
| 679 | } |
|---|
| 680 | } |
|---|
| 681 | } |
|---|
| 682 | else |
|---|
| 683 | { |
|---|
| 684 | for ( i=0; i<=m_fcoViewDepthId;i++) |
|---|
| 685 | { |
|---|
| 686 | if (m_fcoOrder[i]=='T') |
|---|
| 687 | { |
|---|
| 688 | if (viewnumber==viewId) |
|---|
| 689 | { |
|---|
| 690 | fcoFlag=1; |
|---|
| 691 | break; |
|---|
| 692 | } |
|---|
| 693 | else |
|---|
| 694 | viewnumber++; |
|---|
| 695 | } |
|---|
| 696 | } |
|---|
| 697 | } |
|---|
| 698 | if (fcoFlag) |
|---|
| 699 | { |
|---|
| 700 | return m_tDecTop[i]; |
|---|
| 701 | } |
|---|
| 702 | else |
|---|
| 703 | return NULL; |
|---|
| 704 | |
|---|
| 705 | } |
|---|
| 706 | |
|---|
| 707 | // coding order T0D0T1D1T2D2 |
|---|
| 708 | #else |
|---|
| 709 | return m_tDecTop[(isDepth ? 1 : 0) + viewId * 2]; // coding order T0D0T1D1T2D2 |
|---|
| 710 | #endif |
|---|
| 711 | |
|---|
| 712 | } |
|---|
| 713 | |
|---|
| 714 | std::vector<TComPic*> TAppDecTop::getInterViewRefPics( Int viewId, Int poc, Bool isDepth, TComSPS* sps ) |
|---|
| 715 | { |
|---|
| 716 | std::vector<TComPic*> apcRefPics( sps->getNumberOfUsableInterViewRefs(), (TComPic*)NULL ); |
|---|
| 717 | for( Int k = 0; k < sps->getNumberOfUsableInterViewRefs(); k++ ) |
|---|
| 718 | { |
|---|
| 719 | TComPic* pcRefPic = xGetPicFromView( sps->getUsableInterViewRef( k ) + viewId, poc, isDepth ); |
|---|
| 720 | assert( pcRefPic != NULL ); |
|---|
| 721 | apcRefPics[k] = pcRefPic; |
|---|
| 722 | } |
|---|
| 723 | return apcRefPics; |
|---|
| 724 | } |
|---|
| 725 | |
|---|
| 726 | TComPic* TAppDecTop::xGetPicFromView( Int viewId, Int poc, Bool isDepth ) |
|---|
| 727 | { |
|---|
| 728 | assert( ( viewId >= 0 ) ); |
|---|
| 729 | |
|---|
| 730 | #if FLEX_CODING_ORDER_M23723 |
|---|
| 731 | if (getTDecTop(viewId,isDepth)) |
|---|
| 732 | { |
|---|
| 733 | TComList<TComPic*>* apcListPic = getTDecTop( viewId, isDepth )->getListPic(); |
|---|
| 734 | TComPic* pcPic = NULL; |
|---|
| 735 | for( TComList<TComPic*>::iterator it=apcListPic->begin(); it!=apcListPic->end(); it++ ) |
|---|
| 736 | { |
|---|
| 737 | if( (*it)->getPOC() == poc ) |
|---|
| 738 | { |
|---|
| 739 | pcPic = *it; |
|---|
| 740 | break; |
|---|
| 741 | } |
|---|
| 742 | } |
|---|
| 743 | return pcPic; |
|---|
| 744 | } |
|---|
| 745 | else |
|---|
| 746 | return NULL; |
|---|
| 747 | #else |
|---|
| 748 | |
|---|
| 749 | TComList<TComPic*>* apcListPic = getTDecTop( viewId, isDepth )->getListPic(); |
|---|
| 750 | TComPic* pcPic = NULL; |
|---|
| 751 | for( TComList<TComPic*>::iterator it=apcListPic->begin(); it!=apcListPic->end(); it++ ) |
|---|
| 752 | { |
|---|
| 753 | if( (*it)->getPOC() == poc ) |
|---|
| 754 | { |
|---|
| 755 | pcPic = *it; |
|---|
| 756 | break; |
|---|
| 757 | } |
|---|
| 758 | } |
|---|
| 759 | return pcPic; |
|---|
| 760 | #endif |
|---|
| 761 | } |
|---|
| 762 | //! \} |
|---|