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