[2] | 1 | /** \file TDecTop.cpp |
---|
| 2 | \brief decoder class |
---|
| 3 | */ |
---|
| 4 | |
---|
| 5 | #include "../../App/TAppDecoder/TAppDecTop.h" |
---|
| 6 | #include "TDecTop.h" |
---|
| 7 | |
---|
| 8 | |
---|
| 9 | |
---|
| 10 | CamParsCollector::CamParsCollector() |
---|
| 11 | : m_bInitialized( false ) |
---|
| 12 | { |
---|
| 13 | m_aaiCodedOffset = new Int* [ MAX_NUMBER_VIEWS ]; |
---|
| 14 | m_aaiCodedScale = new Int* [ MAX_NUMBER_VIEWS ]; |
---|
| 15 | m_aiViewOrderIndex = new Int [ MAX_NUMBER_VIEWS ]; |
---|
| 16 | m_aiViewReceived = new Int [ MAX_NUMBER_VIEWS ]; |
---|
| 17 | for( UInt uiId = 0; uiId < MAX_NUMBER_VIEWS; uiId++ ) |
---|
| 18 | { |
---|
| 19 | m_aaiCodedOffset [ uiId ] = new Int [ MAX_NUMBER_VIEWS ]; |
---|
| 20 | m_aaiCodedScale [ uiId ] = new Int [ MAX_NUMBER_VIEWS ]; |
---|
| 21 | } |
---|
| 22 | } |
---|
| 23 | |
---|
| 24 | CamParsCollector::~CamParsCollector() |
---|
| 25 | { |
---|
| 26 | for( UInt uiId = 0; uiId < MAX_NUMBER_VIEWS; uiId++ ) |
---|
| 27 | { |
---|
| 28 | delete [] m_aaiCodedOffset [ uiId ]; |
---|
| 29 | delete [] m_aaiCodedScale [ uiId ]; |
---|
| 30 | } |
---|
| 31 | delete [] m_aaiCodedOffset; |
---|
| 32 | delete [] m_aaiCodedScale; |
---|
| 33 | delete [] m_aiViewOrderIndex; |
---|
| 34 | delete [] m_aiViewReceived; |
---|
| 35 | } |
---|
| 36 | |
---|
| 37 | Void |
---|
| 38 | CamParsCollector::init( FILE* pCodedScaleOffsetFile ) |
---|
| 39 | { |
---|
| 40 | m_bInitialized = true; |
---|
| 41 | m_pCodedScaleOffsetFile = pCodedScaleOffsetFile; |
---|
| 42 | m_uiCamParsCodedPrecision = 0; |
---|
| 43 | m_bCamParsVaryOverTime = false; |
---|
| 44 | m_iLastViewId = -1; |
---|
| 45 | m_iLastPOC = -1; |
---|
| 46 | m_uiMaxViewId = 0; |
---|
| 47 | } |
---|
| 48 | |
---|
| 49 | Void |
---|
| 50 | CamParsCollector::uninit() |
---|
| 51 | { |
---|
| 52 | m_bInitialized = false; |
---|
| 53 | } |
---|
| 54 | |
---|
| 55 | Void |
---|
| 56 | CamParsCollector::setSlice( TComSlice* pcSlice ) |
---|
| 57 | { |
---|
| 58 | if( pcSlice == 0 ) |
---|
| 59 | { |
---|
| 60 | AOF( xIsComplete() ); |
---|
| 61 | if( m_bCamParsVaryOverTime || m_iLastPOC == 0 ) |
---|
| 62 | { |
---|
| 63 | xOutput( m_iLastPOC ); |
---|
| 64 | } |
---|
| 65 | return; |
---|
| 66 | } |
---|
| 67 | |
---|
| 68 | AOF( pcSlice->getSPS()->getViewId() < MAX_NUMBER_VIEWS ); |
---|
| 69 | if ( pcSlice->getSPS()->isDepth () ) |
---|
| 70 | { |
---|
| 71 | return; |
---|
| 72 | } |
---|
| 73 | Bool bFirstAU = ( pcSlice->getPOC() == 0 ); |
---|
| 74 | Bool bFirstSliceInAU = ( pcSlice->getPOC() != Int ( m_iLastPOC ) ); |
---|
| 75 | Bool bFirstSliceInView = ( pcSlice->getSPS()->getViewId() != UInt( m_iLastViewId ) || bFirstSliceInAU ); |
---|
| 76 | AOT( bFirstSliceInAU && pcSlice->getSPS()->getViewId() != 0 ); |
---|
| 77 | AOT( !bFirstSliceInAU && pcSlice->getSPS()->getViewId() < UInt( m_iLastViewId ) ); |
---|
| 78 | AOT( !bFirstSliceInAU && pcSlice->getSPS()->getViewId() > UInt( m_iLastViewId + 1 ) ); |
---|
| 79 | AOT( !bFirstAU && pcSlice->getSPS()->getViewId() > m_uiMaxViewId ); |
---|
| 80 | if ( !bFirstSliceInView ) |
---|
| 81 | { |
---|
| 82 | if( m_bCamParsVaryOverTime ) // check consistency of slice parameters here |
---|
| 83 | { |
---|
| 84 | UInt uiViewId = pcSlice->getSPS()->getViewId(); |
---|
| 85 | for( UInt uiBaseId = 0; uiBaseId < uiViewId; uiBaseId++ ) |
---|
| 86 | { |
---|
| 87 | AOF( m_aaiCodedScale [ uiBaseId ][ uiViewId ] == pcSlice->getCodedScale () [ uiBaseId ] ); |
---|
| 88 | AOF( m_aaiCodedOffset[ uiBaseId ][ uiViewId ] == pcSlice->getCodedOffset () [ uiBaseId ] ); |
---|
| 89 | AOF( m_aaiCodedScale [ uiViewId ][ uiBaseId ] == pcSlice->getInvCodedScale () [ uiBaseId ] ); |
---|
| 90 | AOF( m_aaiCodedOffset[ uiViewId ][ uiBaseId ] == pcSlice->getInvCodedOffset() [ uiBaseId ] ); |
---|
| 91 | } |
---|
| 92 | } |
---|
| 93 | return; |
---|
| 94 | } |
---|
| 95 | |
---|
| 96 | if( bFirstSliceInAU ) |
---|
| 97 | { |
---|
| 98 | if( !bFirstAU ) |
---|
| 99 | { |
---|
| 100 | AOF( xIsComplete() ); |
---|
| 101 | xOutput( m_iLastPOC ); |
---|
| 102 | } |
---|
| 103 | ::memset( m_aiViewReceived, 0x00, MAX_NUMBER_VIEWS * sizeof( Int ) ); |
---|
| 104 | } |
---|
| 105 | |
---|
| 106 | UInt uiViewId = pcSlice->getSPS()->getViewId(); |
---|
| 107 | m_aiViewReceived[ uiViewId ] = 1; |
---|
| 108 | if( bFirstAU ) |
---|
| 109 | { |
---|
| 110 | m_uiMaxViewId = Max( m_uiMaxViewId, uiViewId ); |
---|
| 111 | m_aiViewOrderIndex[ uiViewId ] = pcSlice->getSPS()->getViewOrderIdx(); |
---|
| 112 | if( uiViewId == 1 ) |
---|
| 113 | { |
---|
| 114 | m_uiCamParsCodedPrecision = pcSlice->getSPS()->getCamParPrecision (); |
---|
| 115 | m_bCamParsVaryOverTime = pcSlice->getSPS()->hasCamParInSliceHeader (); |
---|
| 116 | } |
---|
| 117 | else if( uiViewId > 1 ) |
---|
| 118 | { |
---|
| 119 | AOF( m_uiCamParsCodedPrecision == pcSlice->getSPS()->getCamParPrecision () ); |
---|
| 120 | AOF( m_bCamParsVaryOverTime == pcSlice->getSPS()->hasCamParInSliceHeader () ); |
---|
| 121 | } |
---|
| 122 | for( UInt uiBaseId = 0; uiBaseId < uiViewId; uiBaseId++ ) |
---|
| 123 | { |
---|
| 124 | if( m_bCamParsVaryOverTime ) |
---|
| 125 | { |
---|
| 126 | m_aaiCodedScale [ uiBaseId ][ uiViewId ] = pcSlice->getCodedScale () [ uiBaseId ]; |
---|
| 127 | m_aaiCodedOffset[ uiBaseId ][ uiViewId ] = pcSlice->getCodedOffset () [ uiBaseId ]; |
---|
| 128 | m_aaiCodedScale [ uiViewId ][ uiBaseId ] = pcSlice->getInvCodedScale () [ uiBaseId ]; |
---|
| 129 | m_aaiCodedOffset[ uiViewId ][ uiBaseId ] = pcSlice->getInvCodedOffset() [ uiBaseId ]; |
---|
| 130 | } |
---|
| 131 | else |
---|
| 132 | { |
---|
| 133 | m_aaiCodedScale [ uiBaseId ][ uiViewId ] = pcSlice->getSPS()->getCodedScale () [ uiBaseId ]; |
---|
| 134 | m_aaiCodedOffset[ uiBaseId ][ uiViewId ] = pcSlice->getSPS()->getCodedOffset () [ uiBaseId ]; |
---|
| 135 | m_aaiCodedScale [ uiViewId ][ uiBaseId ] = pcSlice->getSPS()->getInvCodedScale () [ uiBaseId ]; |
---|
| 136 | m_aaiCodedOffset[ uiViewId ][ uiBaseId ] = pcSlice->getSPS()->getInvCodedOffset() [ uiBaseId ]; |
---|
| 137 | } |
---|
| 138 | } |
---|
| 139 | } |
---|
| 140 | else |
---|
| 141 | { |
---|
| 142 | AOF( m_aiViewOrderIndex[ uiViewId ] == pcSlice->getSPS()->getViewOrderIdx() ); |
---|
| 143 | if( m_bCamParsVaryOverTime ) |
---|
| 144 | { |
---|
| 145 | for( UInt uiBaseId = 0; uiBaseId < uiViewId; uiBaseId++ ) |
---|
| 146 | { |
---|
| 147 | m_aaiCodedScale [ uiBaseId ][ uiViewId ] = pcSlice->getCodedScale () [ uiBaseId ]; |
---|
| 148 | m_aaiCodedOffset[ uiBaseId ][ uiViewId ] = pcSlice->getCodedOffset () [ uiBaseId ]; |
---|
| 149 | m_aaiCodedScale [ uiViewId ][ uiBaseId ] = pcSlice->getInvCodedScale () [ uiBaseId ]; |
---|
| 150 | m_aaiCodedOffset[ uiViewId ][ uiBaseId ] = pcSlice->getInvCodedOffset() [ uiBaseId ]; |
---|
| 151 | } |
---|
| 152 | } |
---|
| 153 | } |
---|
| 154 | m_iLastViewId = (Int)pcSlice->getSPS()->getViewId(); |
---|
| 155 | m_iLastPOC = (Int)pcSlice->getPOC(); |
---|
| 156 | } |
---|
| 157 | |
---|
| 158 | Bool |
---|
| 159 | CamParsCollector::xIsComplete() |
---|
| 160 | { |
---|
| 161 | for( UInt uiView = 0; uiView <= m_uiMaxViewId; uiView++ ) |
---|
| 162 | { |
---|
| 163 | if( m_aiViewReceived[ uiView ] == 0 ) |
---|
| 164 | { |
---|
| 165 | return false; |
---|
| 166 | } |
---|
| 167 | } |
---|
| 168 | return true; |
---|
| 169 | } |
---|
| 170 | |
---|
| 171 | Void |
---|
| 172 | CamParsCollector::xOutput( Int iPOC ) |
---|
| 173 | { |
---|
| 174 | if( m_pCodedScaleOffsetFile ) |
---|
| 175 | { |
---|
| 176 | if( iPOC == 0 ) |
---|
| 177 | { |
---|
| 178 | fprintf( m_pCodedScaleOffsetFile, "# ViewId ViewOrderIdx\n" ); |
---|
| 179 | fprintf( m_pCodedScaleOffsetFile, "#----------- ------------\n" ); |
---|
| 180 | for( UInt uiViewId = 0; uiViewId <= m_uiMaxViewId; uiViewId++ ) |
---|
| 181 | { |
---|
| 182 | fprintf( m_pCodedScaleOffsetFile, "%12d %12d\n", uiViewId, m_aiViewOrderIndex[ uiViewId ] ); |
---|
| 183 | } |
---|
| 184 | fprintf( m_pCodedScaleOffsetFile, "\n\n"); |
---|
| 185 | fprintf( m_pCodedScaleOffsetFile, "# StartFrame EndFrame TargetView BaseView CodedScale CodedOffset Precision\n" ); |
---|
| 186 | fprintf( m_pCodedScaleOffsetFile, "#----------- ------------ ------------ ------------ ------------ ------------ ------------\n" ); |
---|
| 187 | } |
---|
| 188 | if( iPOC == 0 || m_bCamParsVaryOverTime ) |
---|
| 189 | { |
---|
| 190 | Int iS = iPOC; |
---|
| 191 | Int iE = ( m_bCamParsVaryOverTime ? iPOC : ~( 1 << 31 ) ); |
---|
| 192 | for( UInt uiViewId = 0; uiViewId <= m_uiMaxViewId; uiViewId++ ) |
---|
| 193 | { |
---|
| 194 | for( UInt uiBaseId = 0; uiBaseId <= m_uiMaxViewId; uiBaseId++ ) |
---|
| 195 | { |
---|
| 196 | if( uiViewId != uiBaseId ) |
---|
| 197 | { |
---|
| 198 | fprintf( m_pCodedScaleOffsetFile, "%12d %12d %12d %12d %12d %12d %12d\n", |
---|
| 199 | iS, iE, uiViewId, uiBaseId, m_aaiCodedScale[ uiBaseId ][ uiViewId ], m_aaiCodedOffset[ uiBaseId ][ uiViewId ], m_uiCamParsCodedPrecision ); |
---|
| 200 | } |
---|
| 201 | } |
---|
| 202 | } |
---|
| 203 | } |
---|
| 204 | } |
---|
| 205 | } |
---|
| 206 | |
---|
| 207 | |
---|
| 208 | |
---|
| 209 | |
---|
| 210 | TDecTop::TDecTop() |
---|
| 211 | : m_SEIs(0) |
---|
| 212 | { |
---|
| 213 | m_iGopSize = 0; |
---|
| 214 | m_bGopSizeSet = false; |
---|
| 215 | m_iMaxRefPicNum = 0; |
---|
| 216 | m_uiValidPS = 0; |
---|
| 217 | m_bIsDepth = false ; |
---|
| 218 | m_iViewIdx = 0 ; |
---|
| 219 | #if ENC_DEC_TRACE |
---|
| 220 | g_hTrace = fopen( "TraceDec.txt", "wb" ); |
---|
| 221 | g_bJustDoIt = g_bEncDecTraceDisable; |
---|
| 222 | g_nSymbolCounter = 0; |
---|
| 223 | #endif |
---|
| 224 | #if DCM_DECODING_REFRESH |
---|
| 225 | m_bRefreshPending = 0; |
---|
| 226 | m_uiPOCCDR = 0; |
---|
| 227 | #if DCM_SKIP_DECODING_FRAMES |
---|
| 228 | m_uiPOCRA = MAX_UINT; |
---|
| 229 | #endif |
---|
| 230 | #endif |
---|
| 231 | m_uiPrevPOC = UInt(-1); |
---|
| 232 | m_bFirstSliceInPicture = true; |
---|
| 233 | m_bFirstSliceInSequence = true; |
---|
| 234 | m_pcCamParsCollector = 0; |
---|
| 235 | } |
---|
| 236 | |
---|
| 237 | TDecTop::~TDecTop() |
---|
| 238 | { |
---|
| 239 | #if ENC_DEC_TRACE |
---|
| 240 | fclose( g_hTrace ); |
---|
| 241 | #endif |
---|
| 242 | } |
---|
| 243 | |
---|
| 244 | Void TDecTop::create() |
---|
| 245 | { |
---|
| 246 | m_cGopDecoder.create(); |
---|
| 247 | m_apcSlicePilot = new TComSlice; |
---|
| 248 | m_uiSliceIdx = m_uiLastSliceIdx = 0; |
---|
| 249 | } |
---|
| 250 | |
---|
| 251 | Void TDecTop::destroy() |
---|
| 252 | { |
---|
| 253 | m_cGopDecoder.destroy(); |
---|
| 254 | |
---|
| 255 | delete m_apcSlicePilot; |
---|
| 256 | m_apcSlicePilot = NULL; |
---|
| 257 | |
---|
| 258 | m_cSliceDecoder.destroy(); |
---|
| 259 | |
---|
| 260 | m_cDepthMapGenerator.destroy(); |
---|
| 261 | m_cResidualGenerator.destroy(); |
---|
| 262 | } |
---|
| 263 | |
---|
| 264 | Void TDecTop::init( TAppDecTop* pcTAppDecTop, Bool bFirstInstance ) |
---|
| 265 | { |
---|
| 266 | // initialize ROM |
---|
| 267 | if( bFirstInstance ) |
---|
| 268 | initROM(); |
---|
| 269 | #if MTK_SAO |
---|
| 270 | m_cGopDecoder. init( &m_cEntropyDecoder, &m_cSbacDecoder, &m_cBinCABAC, &m_cCavlcDecoder, &m_cSliceDecoder, &m_cLoopFilter, &m_cAdaptiveLoopFilter, &m_cSAO, &m_cDepthMapGenerator, &m_cResidualGenerator ); |
---|
| 271 | #else |
---|
| 272 | m_cGopDecoder. init( &m_cEntropyDecoder, &m_cSbacDecoder, &m_cBinCABAC, &m_cCavlcDecoder, &m_cSliceDecoder, &m_cLoopFilter, &m_cAdaptiveLoopFilter, &m_cDepthMapGenerator, &m_cResidualGenerator ); |
---|
| 273 | #endif |
---|
| 274 | m_cSliceDecoder.init( &m_cEntropyDecoder, &m_cCuDecoder ); |
---|
| 275 | m_cEntropyDecoder.init(&m_cPrediction); |
---|
| 276 | |
---|
| 277 | m_pcTAppDecTop = pcTAppDecTop; |
---|
| 278 | m_cDepthMapGenerator.init( &m_cPrediction, m_pcTAppDecTop->getSPSAccess(), m_pcTAppDecTop->getAUPicAccess() ); |
---|
| 279 | m_cResidualGenerator.init( &m_cTrQuant, &m_cDepthMapGenerator ); |
---|
| 280 | } |
---|
| 281 | |
---|
| 282 | Void TDecTop::setSPS(TComSPS cSPS) |
---|
| 283 | { |
---|
| 284 | m_cSPS = cSPS ; |
---|
| 285 | #if SB_MEM_FIX |
---|
| 286 | if ( !m_cAdaptiveLoopFilter.isCreated()) |
---|
| 287 | { |
---|
| 288 | m_cAdaptiveLoopFilter.create( m_cSPS.getWidth(), m_cSPS.getHeight(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth ); |
---|
| 289 | #if MTK_SAO |
---|
| 290 | m_cSAO.create( m_cSPS.getWidth(), m_cSPS.getHeight(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth ); |
---|
| 291 | #endif |
---|
| 292 | m_cLoopFilter. create( g_uiMaxCUDepth ); |
---|
| 293 | } |
---|
| 294 | #else |
---|
| 295 | m_cAdaptiveLoopFilter.create( m_cSPS.getWidth(), m_cSPS.getHeight(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth ); |
---|
| 296 | #if MTK_SAO |
---|
| 297 | m_cSAO.create( m_cSPS.getWidth(), m_cSPS.getHeight(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth ); |
---|
| 298 | #endif |
---|
| 299 | m_cLoopFilter. create( g_uiMaxCUDepth ); |
---|
| 300 | #endif |
---|
| 301 | m_uiValidPS |= 1; |
---|
| 302 | } |
---|
| 303 | |
---|
| 304 | Void TDecTop::deletePicBuffer ( ) |
---|
| 305 | { |
---|
| 306 | TComList<TComPic*>::iterator iterPic = m_cListPic.begin(); |
---|
| 307 | Int iSize = Int( m_cListPic.size() ); |
---|
| 308 | |
---|
| 309 | for (Int i = 0; i < iSize; i++ ) |
---|
| 310 | { |
---|
| 311 | TComPic* pcPic = *(iterPic++); |
---|
| 312 | pcPic->destroy(); |
---|
| 313 | |
---|
| 314 | delete pcPic; |
---|
| 315 | pcPic = NULL; |
---|
| 316 | } |
---|
| 317 | |
---|
| 318 | // destroy ALF temporary buffers |
---|
| 319 | m_cAdaptiveLoopFilter.destroy(); |
---|
| 320 | |
---|
| 321 | #if MTK_SAO |
---|
| 322 | m_cSAO.destroy(); |
---|
| 323 | #endif |
---|
| 324 | |
---|
| 325 | m_cLoopFilter. destroy(); |
---|
| 326 | |
---|
| 327 | // destroy ROM |
---|
| 328 | if( m_iViewIdx <= 0 && !m_bIsDepth) |
---|
| 329 | destroyROM(); |
---|
| 330 | } |
---|
| 331 | |
---|
| 332 | Void TDecTop::xGetNewPicBuffer ( TComSlice* pcSlice, TComPic*& rpcPic ) |
---|
| 333 | { |
---|
| 334 | m_iMaxRefPicNum = getCodedPictureBufferSize( ); |
---|
| 335 | |
---|
| 336 | Bool bNeedPrdDepthMapBuffer = ( !pcSlice->getSPS()->isDepth() && ( pcSlice->getSPS()->getViewId() == 0 || pcSlice->getSPS()->getPredDepthMapGeneration() > 0 ) ); |
---|
| 337 | |
---|
| 338 | if (m_cListPic.size() < (UInt)m_iMaxRefPicNum) |
---|
| 339 | { |
---|
| 340 | rpcPic = new TComPic; |
---|
| 341 | rpcPic->create ( pcSlice->getSPS()->getWidth(), pcSlice->getSPS()->getHeight(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth ); |
---|
| 342 | if( bNeedPrdDepthMapBuffer ) |
---|
| 343 | { |
---|
| 344 | rpcPic->addPrdDepthMapBuffer(); |
---|
| 345 | } |
---|
| 346 | m_cListPic.pushBack( rpcPic ); |
---|
| 347 | |
---|
| 348 | return; |
---|
| 349 | } |
---|
| 350 | |
---|
| 351 | Bool bBufferIsAvailable = false; |
---|
| 352 | TComList<TComPic*>::iterator iterPic = m_cListPic.begin(); |
---|
| 353 | while (iterPic != m_cListPic.end()) |
---|
| 354 | { |
---|
| 355 | rpcPic = *(iterPic++); |
---|
| 356 | if ( rpcPic->getReconMark() == false ) |
---|
| 357 | { |
---|
| 358 | bBufferIsAvailable = true; |
---|
| 359 | break; |
---|
| 360 | } |
---|
| 361 | } |
---|
| 362 | |
---|
| 363 | if ( !bBufferIsAvailable ) |
---|
| 364 | { |
---|
| 365 | pcSlice->sortPicList(m_cListPic); |
---|
| 366 | iterPic = m_cListPic.begin(); |
---|
| 367 | rpcPic = *(iterPic); |
---|
| 368 | rpcPic->setReconMark(false); |
---|
| 369 | |
---|
| 370 | // mark it should be extended |
---|
| 371 | } |
---|
| 372 | rpcPic->getPicYuvRec()->setBorderExtension(false); |
---|
| 373 | |
---|
| 374 | if( bNeedPrdDepthMapBuffer && !rpcPic->getPredDepthMap() ) |
---|
| 375 | { |
---|
| 376 | rpcPic->addPrdDepthMapBuffer(); |
---|
| 377 | } |
---|
| 378 | } |
---|
| 379 | |
---|
| 380 | |
---|
| 381 | Void |
---|
| 382 | TDecTop::deleteExtraPicBuffers( Int iPoc ) |
---|
| 383 | { |
---|
| 384 | TComPic* pcPic = 0; |
---|
| 385 | TComList<TComPic*>::iterator cIter = m_cListPic.begin(); |
---|
| 386 | TComList<TComPic*>::iterator cEnd = m_cListPic.end (); |
---|
| 387 | for( ; cIter != cEnd; cIter++ ) |
---|
| 388 | { |
---|
| 389 | if( (*cIter)->getPOC() == iPoc ) |
---|
| 390 | { |
---|
| 391 | pcPic = *cIter; |
---|
| 392 | break; |
---|
| 393 | } |
---|
| 394 | } |
---|
| 395 | AOF( pcPic ); |
---|
| 396 | if ( pcPic ) |
---|
| 397 | { |
---|
| 398 | pcPic->removeOriginalBuffer (); |
---|
| 399 | pcPic->removeOrgDepthMapBuffer(); |
---|
| 400 | pcPic->removeResidualBuffer (); |
---|
| 401 | pcPic->removeUsedPelsMapBuffer(); |
---|
| 402 | } |
---|
| 403 | } |
---|
| 404 | |
---|
| 405 | |
---|
| 406 | #if AMVP_BUFFERCOMPRESS |
---|
| 407 | Void |
---|
| 408 | TDecTop::compressMotion( Int iPoc ) |
---|
| 409 | { |
---|
| 410 | TComPic* pcPic = 0; |
---|
| 411 | TComList<TComPic*>::iterator cIter = m_cListPic.begin(); |
---|
| 412 | TComList<TComPic*>::iterator cEnd = m_cListPic.end (); |
---|
| 413 | for( ; cIter != cEnd; cIter++ ) |
---|
| 414 | { |
---|
| 415 | if( (*cIter)->getPOC() == iPoc ) |
---|
| 416 | { |
---|
| 417 | pcPic = *cIter; |
---|
| 418 | break; |
---|
| 419 | } |
---|
| 420 | } |
---|
| 421 | AOF( pcPic ); |
---|
| 422 | if ( pcPic ) |
---|
| 423 | { |
---|
| 424 | pcPic->compressMotion(); |
---|
| 425 | } |
---|
| 426 | } |
---|
| 427 | #endif |
---|
| 428 | |
---|
| 429 | |
---|
| 430 | Void TDecTop::executeDeblockAndAlf(Bool bEos, TComBitstream* pcBitstream, UInt& ruiPOC, TComList<TComPic*>*& rpcListPic, Int& iSkipFrame, Int& iPOCLastDisplay) |
---|
| 431 | { |
---|
| 432 | TComPic*& pcPic = m_pcPic; |
---|
| 433 | |
---|
| 434 | // Execute Deblock and ALF only + Cleanup |
---|
| 435 | TComSlice* pcSlice = pcPic->getPicSym()->getSlice( m_uiSliceIdx ); |
---|
| 436 | m_cGopDecoder.decompressGop ( bEos, pcBitstream, pcPic, true); |
---|
| 437 | |
---|
| 438 | if( m_pcCamParsCollector && bEos ) |
---|
| 439 | { |
---|
| 440 | m_pcCamParsCollector->setSlice( 0 ); |
---|
| 441 | } |
---|
| 442 | |
---|
| 443 | pcSlice->sortPicList ( m_cListPic ); // sorting for application output |
---|
| 444 | ruiPOC = pcPic->getSlice(m_uiSliceIdx-1)->getPOC(); |
---|
| 445 | rpcListPic = &m_cListPic; |
---|
| 446 | m_cCuDecoder.destroy(); |
---|
| 447 | m_bFirstSliceInPicture = true; |
---|
| 448 | |
---|
| 449 | return; |
---|
| 450 | } |
---|
| 451 | |
---|
| 452 | #if DCM_SKIP_DECODING_FRAMES |
---|
| 453 | Bool TDecTop::decode (Bool bEos, TComBitstream* pcBitstream, UInt& ruiPOC, TComList<TComPic*>*& rpcListPic, NalUnitType& reNalUnitType, TComSPS& cComSPS, Int& iSkipFrame, Int& iPOCLastDisplay) |
---|
| 454 | #else |
---|
| 455 | Void TDecTop::decode (Bool bEos, TComBitstream* pcBitstream, UInt& ruiPOC, TComList<TComPic*>*& rpcListPic, NalUnitType& reNalUnitType, TComSPS& cComSPS ) |
---|
| 456 | #endif |
---|
| 457 | { |
---|
| 458 | if (m_bFirstSliceInPicture) |
---|
| 459 | { |
---|
| 460 | rpcListPic = NULL; |
---|
| 461 | } |
---|
| 462 | TComPic*& pcPic = m_pcPic; |
---|
| 463 | |
---|
| 464 | // Initialize entropy decoder |
---|
| 465 | m_cEntropyDecoder.setEntropyDecoder (&m_cCavlcDecoder); |
---|
| 466 | m_cEntropyDecoder.setBitstream (pcBitstream); |
---|
| 467 | |
---|
| 468 | NalUnitType eNalUnitType; |
---|
| 469 | UInt TemporalId; |
---|
| 470 | Bool OutputFlag; |
---|
| 471 | |
---|
| 472 | m_cEntropyDecoder.decodeNalUnitHeader(eNalUnitType, TemporalId, OutputFlag); |
---|
| 473 | reNalUnitType = eNalUnitType; |
---|
| 474 | |
---|
| 475 | switch (eNalUnitType) |
---|
| 476 | { |
---|
| 477 | case NAL_UNIT_SPS: |
---|
| 478 | { |
---|
| 479 | TComSPS cTempSPS; |
---|
| 480 | m_cEntropyDecoder.decodeSPS( &cTempSPS ); |
---|
| 481 | |
---|
| 482 | if( (m_iViewIdx == cTempSPS.getViewId()) && ( m_bIsDepth == cTempSPS.isDepth() ) ) |
---|
| 483 | { |
---|
| 484 | m_cSPS = cTempSPS; |
---|
| 485 | cComSPS = m_cSPS; |
---|
| 486 | } |
---|
| 487 | else |
---|
| 488 | { |
---|
| 489 | cComSPS = cTempSPS; |
---|
| 490 | return false; |
---|
| 491 | } |
---|
| 492 | |
---|
| 493 | // create ALF temporary buffer |
---|
| 494 | #if SB_MEM_FIX |
---|
| 495 | if ( !m_cAdaptiveLoopFilter.isCreated()) |
---|
| 496 | { |
---|
| 497 | m_cAdaptiveLoopFilter.create( m_cSPS.getWidth(), m_cSPS.getHeight(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth ); |
---|
| 498 | #if MTK_SAO |
---|
| 499 | m_cSAO.create( m_cSPS.getWidth(), m_cSPS.getHeight(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth ); |
---|
| 500 | #endif |
---|
| 501 | m_cLoopFilter. create( g_uiMaxCUDepth ); |
---|
| 502 | } |
---|
| 503 | #else |
---|
| 504 | m_cAdaptiveLoopFilter.create( m_cSPS.getWidth(), m_cSPS.getHeight(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth ); |
---|
| 505 | #if MTK_SAO |
---|
| 506 | m_cSAO.create( m_cSPS.getWidth(), m_cSPS.getHeight(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth ); |
---|
| 507 | #endif |
---|
| 508 | m_cLoopFilter. create( g_uiMaxCUDepth ); |
---|
| 509 | #endif |
---|
| 510 | m_uiValidPS |= 1; |
---|
| 511 | |
---|
| 512 | return false; |
---|
| 513 | } |
---|
| 514 | |
---|
| 515 | case NAL_UNIT_PPS: |
---|
| 516 | m_cEntropyDecoder.decodePPS( &m_cPPS ); |
---|
| 517 | assert( m_cPPS.getSPSId() == m_cSPS.getSPSId() ); |
---|
| 518 | m_uiValidPS |= 2; |
---|
| 519 | return false; |
---|
| 520 | |
---|
| 521 | case NAL_UNIT_SEI: |
---|
| 522 | m_SEIs = new SEImessages; |
---|
| 523 | m_cEntropyDecoder.decodeSEI(*m_SEIs); |
---|
| 524 | return false; |
---|
| 525 | |
---|
| 526 | case NAL_UNIT_CODED_SLICE: |
---|
| 527 | case NAL_UNIT_CODED_SLICE_IDR: |
---|
| 528 | case NAL_UNIT_CODED_SLICE_CDR: |
---|
| 529 | { |
---|
| 530 | // make sure we already received both parameter sets |
---|
| 531 | assert( 3 == m_uiValidPS ); |
---|
| 532 | if (m_bFirstSliceInPicture) |
---|
| 533 | { |
---|
| 534 | m_apcSlicePilot->initSlice(); |
---|
| 535 | m_uiSliceIdx = 0; |
---|
| 536 | m_uiLastSliceIdx = 0; |
---|
| 537 | } |
---|
| 538 | m_apcSlicePilot->setSliceIdx(m_uiSliceIdx); |
---|
| 539 | |
---|
| 540 | // Read slice header |
---|
| 541 | m_apcSlicePilot->setSPS( &m_cSPS ); |
---|
| 542 | m_apcSlicePilot->setPPS( &m_cPPS ); |
---|
| 543 | m_apcSlicePilot->setSliceIdx(m_uiSliceIdx); |
---|
| 544 | m_apcSlicePilot->setViewIdx( m_cSPS.getViewId() ); |
---|
| 545 | if (!m_bFirstSliceInPicture) |
---|
| 546 | { |
---|
| 547 | memcpy(m_apcSlicePilot, pcPic->getPicSym()->getSlice(m_uiSliceIdx-1), sizeof(TComSlice)); |
---|
| 548 | } |
---|
| 549 | |
---|
| 550 | #if DCM_DECODING_REFRESH |
---|
| 551 | m_apcSlicePilot->setNalUnitType (eNalUnitType); |
---|
| 552 | #endif |
---|
| 553 | m_cEntropyDecoder.decodeSliceHeader (m_apcSlicePilot); |
---|
| 554 | |
---|
| 555 | // if (m_apcSlicePilot->isNextSlice() && m_apcSlicePilot->getPOC()!=m_uiPrevPOC && !m_bFirstSliceInSequence) |
---|
| 556 | // if (m_apcSlicePilot->isNextSlice() && ( m_apcSlicePilot->getPOC()!=m_uiPrevPOC || m_apcSlicePilot->getPPSId() != m_cPPS.getPPSId() ) && !m_bFirstSliceInSequence) |
---|
| 557 | if (m_apcSlicePilot->isNextSlice() && ( m_apcSlicePilot->getPOC()!=m_uiPrevPOC || m_apcSlicePilot->getPPSId() != m_cPPS.getPPSId() ) && !m_bFirstSliceInPicture) |
---|
| 558 | { |
---|
| 559 | m_uiPrevPOC = m_apcSlicePilot->getPOC(); |
---|
| 560 | return true; |
---|
| 561 | } |
---|
| 562 | if (m_apcSlicePilot->isNextSlice()) |
---|
| 563 | m_uiPrevPOC = m_apcSlicePilot->getPOC(); |
---|
| 564 | m_bFirstSliceInSequence = false; |
---|
| 565 | if (m_apcSlicePilot->isNextSlice()) |
---|
| 566 | { |
---|
| 567 | #if DCM_SKIP_DECODING_FRAMES |
---|
| 568 | // Skip pictures due to random access |
---|
| 569 | if (isRandomAccessSkipPicture(iSkipFrame, iPOCLastDisplay)) |
---|
| 570 | { |
---|
| 571 | return false; |
---|
| 572 | } |
---|
| 573 | #endif |
---|
| 574 | } |
---|
| 575 | |
---|
| 576 | if (m_bFirstSliceInPicture) |
---|
| 577 | { |
---|
| 578 | // Buffer initialize for prediction. |
---|
| 579 | m_cPrediction.initTempBuff(); |
---|
| 580 | // Get a new picture buffer |
---|
| 581 | xGetNewPicBuffer (m_apcSlicePilot, pcPic); |
---|
| 582 | |
---|
| 583 | pcPic->setViewIdx( m_cSPS.getViewId() ); |
---|
| 584 | |
---|
| 585 | /* transfer any SEI messages that have been received to the picture */ |
---|
| 586 | pcPic->setSEIs(m_SEIs); |
---|
| 587 | m_SEIs = NULL; |
---|
| 588 | |
---|
| 589 | // Recursive structure |
---|
| 590 | m_cCuDecoder.create ( g_uiMaxCUDepth, g_uiMaxCUWidth, g_uiMaxCUHeight ); |
---|
| 591 | m_cCuDecoder.init ( &m_cEntropyDecoder, &m_cTrQuant, &m_cPrediction ); |
---|
| 592 | m_cTrQuant.init ( g_uiMaxCUWidth, g_uiMaxCUHeight, m_apcSlicePilot->getSPS()->getMaxTrSize()); |
---|
| 593 | |
---|
| 594 | m_cSliceDecoder.create( m_apcSlicePilot, m_apcSlicePilot->getSPS()->getWidth(), m_apcSlicePilot->getSPS()->getHeight(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth ); |
---|
| 595 | |
---|
| 596 | m_cDepthMapGenerator.create( true, m_apcSlicePilot->getSPS()->getWidth(), m_apcSlicePilot->getSPS()->getHeight(), g_uiMaxCUDepth, g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiBitDepth + g_uiBitIncrement ); |
---|
| 597 | m_cResidualGenerator.create( true, m_apcSlicePilot->getSPS()->getWidth(), m_apcSlicePilot->getSPS()->getHeight(), g_uiMaxCUDepth, g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiBitDepth + g_uiBitIncrement ); |
---|
| 598 | } |
---|
| 599 | |
---|
| 600 | // Set picture slice pointer |
---|
| 601 | TComSlice* pcSlice = m_apcSlicePilot; |
---|
| 602 | Bool bNextSlice = pcSlice->isNextSlice(); |
---|
| 603 | if (m_bFirstSliceInPicture) |
---|
| 604 | { |
---|
| 605 | if(pcPic->getNumAllocatedSlice() != 1) |
---|
| 606 | { |
---|
| 607 | pcPic->clearSliceBuffer(); |
---|
| 608 | } |
---|
| 609 | } |
---|
| 610 | else |
---|
| 611 | { |
---|
| 612 | pcPic->allocateNewSlice(); |
---|
| 613 | } |
---|
| 614 | assert(pcPic->getNumAllocatedSlice() == (m_uiSliceIdx + 1)); |
---|
| 615 | m_apcSlicePilot = pcPic->getPicSym()->getSlice(m_uiSliceIdx); |
---|
| 616 | pcPic->getPicSym()->setSlice(pcSlice, m_uiSliceIdx); |
---|
| 617 | |
---|
| 618 | if (bNextSlice) |
---|
| 619 | { |
---|
| 620 | #if DCM_DECODING_REFRESH |
---|
| 621 | // Do decoding refresh marking if any |
---|
| 622 | pcSlice->decodingRefreshMarking(m_uiPOCCDR, m_bRefreshPending, m_cListPic); |
---|
| 623 | #endif |
---|
| 624 | |
---|
| 625 | // Set reference list |
---|
| 626 | std::vector<TComPic*> apcSpatRefPics = getDecTop()->getSpatialRefPics( pcPic->getViewIdx(), pcSlice->getPOC(), m_cSPS.isDepth() ); |
---|
| 627 | TComPic * const pcTexturePic = m_cSPS.isDepth() ? getDecTop()->getPicFromView( pcPic->getViewIdx(), pcSlice->getPOC(), false ) : NULL; |
---|
| 628 | assert( ! m_cSPS.isDepth() || pcTexturePic != NULL ); |
---|
| 629 | pcSlice->setTexturePic( pcTexturePic ); |
---|
| 630 | pcSlice->setViewIdx( pcPic->getViewIdx() ); |
---|
| 631 | pcSlice->setRefPicListExplicitlyDecoderSided(m_cListPic, apcSpatRefPics) ;// temporary solution |
---|
| 632 | |
---|
| 633 | #if DCM_COMB_LIST |
---|
| 634 | if(!pcSlice->getRefPicListModificationFlagLC()) |
---|
| 635 | { |
---|
| 636 | pcSlice->generateCombinedList(); |
---|
| 637 | } |
---|
| 638 | #endif |
---|
| 639 | |
---|
| 640 | pcSlice->setNoBackPredFlag( false ); |
---|
| 641 | #if DCM_COMB_LIST |
---|
| 642 | if ( pcSlice->getSliceType() == B_SLICE && !pcSlice->getRefPicListCombinationFlag()) |
---|
| 643 | #else |
---|
| 644 | if ( pcSlice->getSliceType() == B_SLICE ) |
---|
| 645 | #endif |
---|
| 646 | { |
---|
| 647 | if ( pcSlice->getNumRefIdx(RefPicList( 0 ) ) == pcSlice->getNumRefIdx(RefPicList( 1 ) ) ) |
---|
| 648 | { |
---|
| 649 | pcSlice->setNoBackPredFlag( true ); |
---|
| 650 | int i; |
---|
| 651 | for ( i=0; i < pcSlice->getNumRefIdx(RefPicList( 1 ) ); i++ ) |
---|
| 652 | { |
---|
| 653 | if ( pcSlice->getRefPOC(RefPicList(1), i) != pcSlice->getRefPOC(RefPicList(0), i) ) |
---|
| 654 | { |
---|
| 655 | pcSlice->setNoBackPredFlag( false ); |
---|
| 656 | break; |
---|
| 657 | } |
---|
| 658 | } |
---|
| 659 | } |
---|
| 660 | } |
---|
| 661 | } |
---|
| 662 | |
---|
| 663 | pcPic->setCurrSliceIdx(m_uiSliceIdx); |
---|
| 664 | |
---|
| 665 | #if HHI_DMM_INTRA |
---|
| 666 | if ( m_cSPS.getUseDepthModelModes() && g_aacWedgeLists.empty() && m_bIsDepth ) |
---|
| 667 | { |
---|
| 668 | initWedgeLists(); |
---|
| 669 | } |
---|
| 670 | #endif |
---|
| 671 | |
---|
| 672 | // Decode a picture |
---|
| 673 | m_cGopDecoder.decompressGop ( bEos, pcBitstream, pcPic, false ); |
---|
| 674 | |
---|
| 675 | if( m_pcCamParsCollector ) |
---|
| 676 | { |
---|
| 677 | m_pcCamParsCollector->setSlice( pcSlice ); |
---|
| 678 | } |
---|
| 679 | |
---|
| 680 | m_bFirstSliceInPicture = false; |
---|
| 681 | m_uiSliceIdx++; |
---|
| 682 | } |
---|
| 683 | break; |
---|
| 684 | default: |
---|
| 685 | assert (1); |
---|
| 686 | } |
---|
| 687 | |
---|
| 688 | return false; |
---|
| 689 | } |
---|
| 690 | |
---|
| 691 | #if DCM_SKIP_DECODING_FRAMES |
---|
| 692 | /** Function for checking if picture should be skipped because of random access |
---|
| 693 | * \param iSkipFrame skip frame counter |
---|
| 694 | * \param iPOCLastDisplay POC of last picture displayed |
---|
| 695 | * \returns true if the picture shold be skipped in the random access. |
---|
| 696 | * This function checks the skipping of pictures in the case of -s option random access. |
---|
| 697 | * All pictures prior to the random access point indicated by the counter iSkipFrame are skipped. |
---|
| 698 | * It also checks the type of Nal unit type at the random access point. |
---|
| 699 | * If the random access point is CDR, pictures with POC equal to or greater than the CDR POC are decoded. |
---|
| 700 | * If the random access point is IDR all pictures after the random access point are decoded. |
---|
| 701 | * If the random access point is not IDR or CDR, a warning is issues, and decoding of pictures with POC |
---|
| 702 | * equal to or greater than the random access point POC is attempted. For non IDR/CDR random |
---|
| 703 | * access point there is no guarantee that the decoder will not crash. |
---|
| 704 | */ |
---|
| 705 | Bool TDecTop::isRandomAccessSkipPicture(Int& iSkipFrame, Int& iPOCLastDisplay) |
---|
| 706 | { |
---|
| 707 | if (iSkipFrame) |
---|
| 708 | { |
---|
| 709 | iSkipFrame--; // decrement the counter |
---|
| 710 | return true; |
---|
| 711 | } |
---|
| 712 | else if (m_uiPOCRA == MAX_UINT) // start of random access point, m_uiPOCRA has not been set yet. |
---|
| 713 | { |
---|
| 714 | if (m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_CDR) |
---|
| 715 | { |
---|
| 716 | m_uiPOCRA = m_apcSlicePilot->getPOC(); // set the POC random access since we need to skip the reordered pictures in CDR. |
---|
| 717 | } |
---|
| 718 | else if (m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR) |
---|
| 719 | { |
---|
| 720 | m_uiPOCRA = 0; // no need to skip the reordered pictures in IDR, they are decodable. |
---|
| 721 | } |
---|
| 722 | else |
---|
| 723 | { |
---|
| 724 | printf("\nUnsafe random access point. Decoder may crash."); |
---|
| 725 | m_uiPOCRA = m_apcSlicePilot->getPOC(); // set the POC random access skip the reordered pictures and try to decode if possible. This increases the chances of avoiding a decoder crash. |
---|
| 726 | //m_uiPOCRA = 0; |
---|
| 727 | } |
---|
| 728 | } |
---|
| 729 | else if (m_apcSlicePilot->getPOC() < m_uiPOCRA) // skip the reordered pictures if necessary |
---|
| 730 | { |
---|
| 731 | iPOCLastDisplay++; |
---|
| 732 | return true; |
---|
| 733 | } |
---|
| 734 | // if we reach here, then the picture is not skipped. |
---|
| 735 | return false; |
---|
| 736 | } |
---|
| 737 | #endif |
---|
| 738 | |
---|