[5] | 1 | /* The copyright in this software is being made available under the BSD |
---|
| 2 | * License, included below. This software may be subject to other third party |
---|
| 3 | * and contributor rights, including patent rights, and no such rights are |
---|
[56] | 4 | * granted under this license. |
---|
[5] | 5 | * |
---|
[608] | 6 | * Copyright (c) 2010-2013, ITU/ISO/IEC |
---|
[5] | 7 | * All rights reserved. |
---|
| 8 | * |
---|
| 9 | * Redistribution and use in source and binary forms, with or without |
---|
| 10 | * modification, are permitted provided that the following conditions are met: |
---|
| 11 | * |
---|
| 12 | * * Redistributions of source code must retain the above copyright notice, |
---|
| 13 | * this list of conditions and the following disclaimer. |
---|
| 14 | * * Redistributions in binary form must reproduce the above copyright notice, |
---|
| 15 | * this list of conditions and the following disclaimer in the documentation |
---|
| 16 | * and/or other materials provided with the distribution. |
---|
[56] | 17 | * * Neither the name of the ITU/ISO/IEC nor the names of its contributors may |
---|
[5] | 18 | * be used to endorse or promote products derived from this software without |
---|
| 19 | * specific prior written permission. |
---|
| 20 | * |
---|
| 21 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
---|
| 22 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
---|
| 23 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
---|
| 24 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS |
---|
| 25 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
---|
| 26 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
---|
| 27 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
---|
| 28 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
---|
| 29 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
---|
| 30 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF |
---|
| 31 | * THE POSSIBILITY OF SUCH DAMAGE. |
---|
| 32 | */ |
---|
[2] | 33 | |
---|
| 34 | /** \file TDecGop.cpp |
---|
| 35 | \brief GOP decoder class |
---|
| 36 | */ |
---|
| 37 | |
---|
| 38 | #include "TDecGop.h" |
---|
| 39 | #include "TDecCAVLC.h" |
---|
| 40 | #include "TDecSbac.h" |
---|
| 41 | #include "TDecBinCoder.h" |
---|
| 42 | #include "TDecBinCoderCABAC.h" |
---|
[56] | 43 | #include "libmd5/MD5.h" |
---|
| 44 | #include "TLibCommon/SEI.h" |
---|
[2] | 45 | |
---|
| 46 | #include <time.h> |
---|
| 47 | |
---|
[608] | 48 | extern Bool g_md5_mismatch; ///< top level flag to signal when there is a decode problem |
---|
| 49 | |
---|
[56] | 50 | //! \ingroup TLibDecoder |
---|
| 51 | //! \{ |
---|
[608] | 52 | static void calcAndPrintHashStatus(TComPicYuv& pic, const SEIDecodedPictureHash* pictureHashSEI); |
---|
[2] | 53 | // ==================================================================================================================== |
---|
| 54 | // Constructor / destructor / initialization / destroy |
---|
| 55 | // ==================================================================================================================== |
---|
| 56 | |
---|
| 57 | TDecGop::TDecGop() |
---|
| 58 | { |
---|
| 59 | m_dDecTime = 0; |
---|
[56] | 60 | m_pcSbacDecoders = NULL; |
---|
| 61 | m_pcBinCABACs = NULL; |
---|
[2] | 62 | } |
---|
| 63 | |
---|
| 64 | TDecGop::~TDecGop() |
---|
| 65 | { |
---|
| 66 | |
---|
| 67 | } |
---|
| 68 | |
---|
| 69 | Void TDecGop::create() |
---|
| 70 | { |
---|
| 71 | |
---|
| 72 | } |
---|
| 73 | |
---|
| 74 | |
---|
| 75 | Void TDecGop::destroy() |
---|
| 76 | { |
---|
| 77 | } |
---|
| 78 | |
---|
| 79 | Void TDecGop::init( TDecEntropy* pcEntropyDecoder, |
---|
| 80 | TDecSbac* pcSbacDecoder, |
---|
| 81 | TDecBinCABAC* pcBinCABAC, |
---|
| 82 | TDecCavlc* pcCavlcDecoder, |
---|
| 83 | TDecSlice* pcSliceDecoder, |
---|
[608] | 84 | TComLoopFilter* pcLoopFilter, |
---|
| 85 | TComSampleAdaptiveOffset* pcSAO |
---|
[56] | 86 | ) |
---|
[2] | 87 | { |
---|
| 88 | m_pcEntropyDecoder = pcEntropyDecoder; |
---|
| 89 | m_pcSbacDecoder = pcSbacDecoder; |
---|
| 90 | m_pcBinCABAC = pcBinCABAC; |
---|
| 91 | m_pcCavlcDecoder = pcCavlcDecoder; |
---|
| 92 | m_pcSliceDecoder = pcSliceDecoder; |
---|
| 93 | m_pcLoopFilter = pcLoopFilter; |
---|
| 94 | m_pcSAO = pcSAO; |
---|
| 95 | } |
---|
| 96 | |
---|
[56] | 97 | |
---|
[2] | 98 | // ==================================================================================================================== |
---|
[56] | 99 | // Private member functions |
---|
| 100 | // ==================================================================================================================== |
---|
| 101 | // ==================================================================================================================== |
---|
[2] | 102 | // Public member functions |
---|
| 103 | // ==================================================================================================================== |
---|
| 104 | |
---|
[608] | 105 | Void TDecGop::decompressSlice(TComInputBitstream* pcBitstream, TComPic*& rpcPic) |
---|
[2] | 106 | { |
---|
| 107 | TComSlice* pcSlice = rpcPic->getSlice(rpcPic->getCurrSliceIdx()); |
---|
[56] | 108 | // Table of extracted substreams. |
---|
| 109 | // These must be deallocated AND their internal fifos, too. |
---|
| 110 | TComInputBitstream **ppcSubstreams = NULL; |
---|
[2] | 111 | |
---|
| 112 | //-- For time output for each slice |
---|
| 113 | long iBeforeTime = clock(); |
---|
| 114 | |
---|
[608] | 115 | UInt uiStartCUAddr = pcSlice->getSliceSegmentCurStartCUAddr(); |
---|
[56] | 116 | |
---|
[608] | 117 | UInt uiSliceStartCuAddr = pcSlice->getSliceCurStartCUAddr(); |
---|
| 118 | if(uiSliceStartCuAddr == uiStartCUAddr) |
---|
[2] | 119 | { |
---|
[608] | 120 | m_sliceStartCUAddress.push_back(uiSliceStartCuAddr); |
---|
| 121 | } |
---|
[56] | 122 | |
---|
[608] | 123 | m_pcSbacDecoder->init( (TDecBinIf*)m_pcBinCABAC ); |
---|
| 124 | m_pcEntropyDecoder->setEntropyDecoder (m_pcSbacDecoder); |
---|
[56] | 125 | |
---|
[608] | 126 | UInt uiNumSubstreams = pcSlice->getPPS()->getEntropyCodingSyncEnabledFlag() ? pcSlice->getNumEntryPointOffsets()+1 : pcSlice->getPPS()->getNumSubstreams(); |
---|
[56] | 127 | |
---|
[608] | 128 | // init each couple {EntropyDecoder, Substream} |
---|
| 129 | UInt *puiSubstreamSizes = pcSlice->getSubstreamSizes(); |
---|
| 130 | ppcSubstreams = new TComInputBitstream*[uiNumSubstreams]; |
---|
| 131 | m_pcSbacDecoders = new TDecSbac[uiNumSubstreams]; |
---|
| 132 | m_pcBinCABACs = new TDecBinCABAC[uiNumSubstreams]; |
---|
| 133 | for ( UInt ui = 0 ; ui < uiNumSubstreams ; ui++ ) |
---|
| 134 | { |
---|
| 135 | m_pcSbacDecoders[ui].init(&m_pcBinCABACs[ui]); |
---|
| 136 | ppcSubstreams[ui] = pcBitstream->extractSubstream(ui+1 < uiNumSubstreams ? puiSubstreamSizes[ui] : pcBitstream->getNumBitsLeft()); |
---|
| 137 | } |
---|
[2] | 138 | |
---|
[608] | 139 | for ( UInt ui = 0 ; ui+1 < uiNumSubstreams; ui++ ) |
---|
| 140 | { |
---|
| 141 | m_pcEntropyDecoder->setEntropyDecoder ( &m_pcSbacDecoders[uiNumSubstreams - 1 - ui] ); |
---|
| 142 | m_pcEntropyDecoder->setBitstream ( ppcSubstreams [uiNumSubstreams - 1 - ui] ); |
---|
[2] | 143 | m_pcEntropyDecoder->resetEntropy (pcSlice); |
---|
[608] | 144 | } |
---|
[56] | 145 | |
---|
[608] | 146 | m_pcEntropyDecoder->setEntropyDecoder ( m_pcSbacDecoder ); |
---|
| 147 | m_pcEntropyDecoder->setBitstream ( ppcSubstreams[0] ); |
---|
| 148 | m_pcEntropyDecoder->resetEntropy (pcSlice); |
---|
[2] | 149 | |
---|
[608] | 150 | if(uiSliceStartCuAddr == uiStartCUAddr) |
---|
| 151 | { |
---|
| 152 | m_LFCrossSliceBoundaryFlag.push_back( pcSlice->getLFCrossSliceBoundaryFlag()); |
---|
| 153 | } |
---|
| 154 | #if H_3D_NBDV |
---|
| 155 | if(pcSlice->getViewIndex() && !pcSlice->getIsDepth()) //Notes from QC: this condition shall be changed once the configuration is completed, e.g. in pcSlice->getSPS()->getMultiviewMvPredMode() || ARP in prev. HTM. Remove this comment once it is done. |
---|
| 156 | { |
---|
| 157 | Int iColPoc = pcSlice->getRefPOC(RefPicList(1-pcSlice->getColFromL0Flag()), pcSlice->getColRefIdx()); |
---|
| 158 | rpcPic->setNumDdvCandPics(rpcPic->getDisCandRefPictures(iColPoc)); |
---|
| 159 | } |
---|
[100] | 160 | #endif |
---|
[608] | 161 | #if MTK_NBDV_TN_FIX_E0172 |
---|
| 162 | if(pcSlice->getViewIndex() && !pcSlice->getIsDepth() && !pcSlice->isIntra()) //Notes from QC: this condition shall be changed once the configuration is completed, e.g. in pcSlice->getSPS()->getMultiviewMvPredMode() || ARP in prev. HTM. Remove this comment once it is done. |
---|
| 163 | { |
---|
| 164 | rpcPic->checkTemporalIVRef(); |
---|
| 165 | } |
---|
[5] | 166 | #endif |
---|
[608] | 167 | #if MTK_TEXTURE_MRGCAND_BUGFIX_E0182 |
---|
| 168 | if(pcSlice->getIsDepth()) |
---|
| 169 | { |
---|
| 170 | rpcPic->checkTextureRef(); |
---|
| 171 | } |
---|
[5] | 172 | #endif |
---|
[608] | 173 | #if H_3D |
---|
| 174 | pcSlice->setDepthToDisparityLUTs(); |
---|
[189] | 175 | #endif |
---|
[608] | 176 | m_pcSbacDecoders[0].load(m_pcSbacDecoder); |
---|
| 177 | m_pcSliceDecoder->decompressSlice( ppcSubstreams, rpcPic, m_pcSbacDecoder, m_pcSbacDecoders); |
---|
| 178 | m_pcEntropyDecoder->setBitstream( ppcSubstreams[uiNumSubstreams-1] ); |
---|
| 179 | // deallocate all created substreams, including internal buffers. |
---|
| 180 | for (UInt ui = 0; ui < uiNumSubstreams; ui++) |
---|
| 181 | { |
---|
| 182 | ppcSubstreams[ui]->deleteFifo(); |
---|
| 183 | delete ppcSubstreams[ui]; |
---|
| 184 | } |
---|
| 185 | delete[] ppcSubstreams; |
---|
| 186 | delete[] m_pcSbacDecoders; m_pcSbacDecoders = NULL; |
---|
| 187 | delete[] m_pcBinCABACs; m_pcBinCABACs = NULL; |
---|
[56] | 188 | |
---|
[608] | 189 | m_dDecTime += (Double)(clock()-iBeforeTime) / CLOCKS_PER_SEC; |
---|
| 190 | } |
---|
| 191 | |
---|
| 192 | Void TDecGop::filterPicture(TComPic*& rpcPic) |
---|
| 193 | { |
---|
| 194 | TComSlice* pcSlice = rpcPic->getSlice(rpcPic->getCurrSliceIdx()); |
---|
| 195 | |
---|
| 196 | //-- For time output for each slice |
---|
| 197 | long iBeforeTime = clock(); |
---|
| 198 | |
---|
| 199 | // deblocking filter |
---|
| 200 | Bool bLFCrossTileBoundary = pcSlice->getPPS()->getLoopFilterAcrossTilesEnabledFlag(); |
---|
| 201 | m_pcLoopFilter->setCfg(bLFCrossTileBoundary); |
---|
| 202 | m_pcLoopFilter->loopFilterPic( rpcPic ); |
---|
| 203 | |
---|
| 204 | if(pcSlice->getSPS()->getUseSAO()) |
---|
| 205 | { |
---|
| 206 | m_sliceStartCUAddress.push_back(rpcPic->getNumCUsInFrame()* rpcPic->getNumPartInCU()); |
---|
| 207 | rpcPic->createNonDBFilterInfo(m_sliceStartCUAddress, 0, &m_LFCrossSliceBoundaryFlag, rpcPic->getPicSym()->getNumTiles(), bLFCrossTileBoundary); |
---|
| 208 | } |
---|
| 209 | |
---|
| 210 | if( pcSlice->getSPS()->getUseSAO() ) |
---|
| 211 | { |
---|
[56] | 212 | { |
---|
[608] | 213 | SAOParam *saoParam = rpcPic->getPicSym()->getSaoParam(); |
---|
| 214 | saoParam->bSaoFlag[0] = pcSlice->getSaoEnabledFlag(); |
---|
| 215 | saoParam->bSaoFlag[1] = pcSlice->getSaoEnabledFlagChroma(); |
---|
| 216 | m_pcSAO->setSaoLcuBasedOptimization(1); |
---|
| 217 | m_pcSAO->createPicSaoInfo(rpcPic); |
---|
| 218 | m_pcSAO->SAOProcess(saoParam); |
---|
| 219 | m_pcSAO->PCMLFDisableProcess(rpcPic); |
---|
| 220 | m_pcSAO->destroyPicSaoInfo(); |
---|
[56] | 221 | } |
---|
[2] | 222 | } |
---|
[608] | 223 | |
---|
| 224 | if(pcSlice->getSPS()->getUseSAO()) |
---|
[2] | 225 | { |
---|
[608] | 226 | rpcPic->destroyNonDBFilterInfo(); |
---|
| 227 | } |
---|
| 228 | #if MTK_SONY_PROGRESSIVE_MV_COMPRESSION_E0170 |
---|
| 229 | rpcPic->compressMotion(2); |
---|
[5] | 230 | #endif |
---|
[608] | 231 | #if !H_3D |
---|
| 232 | rpcPic->compressMotion(); |
---|
[5] | 233 | #endif |
---|
[608] | 234 | Char c = (pcSlice->isIntra() ? 'I' : pcSlice->isInterP() ? 'P' : 'B'); |
---|
| 235 | if (!pcSlice->isReferenced()) c += 32; |
---|
[56] | 236 | |
---|
[608] | 237 | //-- For time output for each slice |
---|
| 238 | #if H_MV |
---|
| 239 | printf("\nLayer %2d POC %4d TId: %1d ( %c-SLICE, QP%3d ) ", pcSlice->getLayerId(), |
---|
| 240 | pcSlice->getPOC(), |
---|
| 241 | pcSlice->getTLayer(), |
---|
| 242 | c, |
---|
| 243 | pcSlice->getSliceQp() ); |
---|
[443] | 244 | #else |
---|
[608] | 245 | printf("\nPOC %4d TId: %1d ( %c-SLICE, QP%3d ) ", pcSlice->getPOC(), |
---|
| 246 | pcSlice->getTLayer(), |
---|
| 247 | c, |
---|
| 248 | pcSlice->getSliceQp() ); |
---|
[443] | 249 | #endif |
---|
[56] | 250 | |
---|
[608] | 251 | m_dDecTime += (Double)(clock()-iBeforeTime) / CLOCKS_PER_SEC; |
---|
| 252 | printf ("[DT %6.3f] ", m_dDecTime ); |
---|
| 253 | m_dDecTime = 0; |
---|
[56] | 254 | |
---|
[608] | 255 | for (Int iRefList = 0; iRefList < 2; iRefList++) |
---|
| 256 | { |
---|
| 257 | printf ("[L%d ", iRefList); |
---|
| 258 | for (Int iRefIndex = 0; iRefIndex < pcSlice->getNumRefIdx(RefPicList(iRefList)); iRefIndex++) |
---|
[2] | 259 | { |
---|
[608] | 260 | #if H_MV |
---|
| 261 | if( pcSlice->getLayerId() != pcSlice->getRefLayerId( RefPicList(iRefList), iRefIndex ) ) |
---|
[2] | 262 | { |
---|
[608] | 263 | printf( "V%d ", pcSlice->getRefLayerId( RefPicList(iRefList), iRefIndex ) ); |
---|
[2] | 264 | } |
---|
[608] | 265 | else |
---|
[2] | 266 | { |
---|
[608] | 267 | #endif |
---|
| 268 | printf ("%d ", pcSlice->getRefPOC(RefPicList(iRefList), iRefIndex)); |
---|
| 269 | #if H_MV |
---|
[2] | 270 | } |
---|
[608] | 271 | #endif |
---|
[2] | 272 | } |
---|
[608] | 273 | printf ("] "); |
---|
| 274 | } |
---|
| 275 | if (m_decodedPictureHashSEIEnabled) |
---|
| 276 | { |
---|
| 277 | SEIMessages pictureHashes = getSeisByType(rpcPic->getSEIs(), SEI::DECODED_PICTURE_HASH ); |
---|
| 278 | const SEIDecodedPictureHash *hash = ( pictureHashes.size() > 0 ) ? (SEIDecodedPictureHash*) *(pictureHashes.begin()) : NULL; |
---|
| 279 | if (pictureHashes.size() > 1) |
---|
[56] | 280 | { |
---|
[608] | 281 | printf ("Warning: Got multiple decoded picture hash SEI messages. Using first."); |
---|
[2] | 282 | } |
---|
[608] | 283 | calcAndPrintHashStatus(*rpcPic->getPicYuvRec(), hash); |
---|
| 284 | } |
---|
[2] | 285 | |
---|
[608] | 286 | rpcPic->setOutputMark(true); |
---|
| 287 | rpcPic->setReconMark(true); |
---|
| 288 | m_sliceStartCUAddress.clear(); |
---|
| 289 | m_LFCrossSliceBoundaryFlag.clear(); |
---|
[2] | 290 | } |
---|
| 291 | |
---|
| 292 | /** |
---|
[608] | 293 | * Calculate and print hash for pic, compare to picture_digest SEI if |
---|
| 294 | * present in seis. seis may be NULL. Hash is printed to stdout, in |
---|
[2] | 295 | * a manner suitable for the status line. Theformat is: |
---|
[608] | 296 | * [Hash_type:xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx,(yyy)] |
---|
| 297 | * Where, x..x is the hash |
---|
[2] | 298 | * yyy has the following meanings: |
---|
[608] | 299 | * OK - calculated hash matches the SEI message |
---|
| 300 | * ***ERROR*** - calculated hash does not match the SEI message |
---|
[2] | 301 | * unk - no SEI message was available for comparison |
---|
| 302 | */ |
---|
[608] | 303 | static void calcAndPrintHashStatus(TComPicYuv& pic, const SEIDecodedPictureHash* pictureHashSEI) |
---|
[2] | 304 | { |
---|
| 305 | /* calculate MD5sum for entire reconstructed picture */ |
---|
[608] | 306 | UChar recon_digest[3][16]; |
---|
| 307 | Int numChar=0; |
---|
| 308 | const Char* hashType = "\0"; |
---|
[2] | 309 | |
---|
[608] | 310 | if (pictureHashSEI) |
---|
| 311 | { |
---|
| 312 | switch (pictureHashSEI->method) |
---|
| 313 | { |
---|
| 314 | case SEIDecodedPictureHash::MD5: |
---|
| 315 | { |
---|
| 316 | hashType = "MD5"; |
---|
| 317 | calcMD5(pic, recon_digest); |
---|
| 318 | numChar = 16; |
---|
| 319 | break; |
---|
| 320 | } |
---|
| 321 | case SEIDecodedPictureHash::CRC: |
---|
| 322 | { |
---|
| 323 | hashType = "CRC"; |
---|
| 324 | calcCRC(pic, recon_digest); |
---|
| 325 | numChar = 2; |
---|
| 326 | break; |
---|
| 327 | } |
---|
| 328 | case SEIDecodedPictureHash::CHECKSUM: |
---|
| 329 | { |
---|
| 330 | hashType = "Checksum"; |
---|
| 331 | calcChecksum(pic, recon_digest); |
---|
| 332 | numChar = 4; |
---|
| 333 | break; |
---|
| 334 | } |
---|
| 335 | default: |
---|
| 336 | { |
---|
| 337 | assert (!"unknown hash type"); |
---|
| 338 | } |
---|
| 339 | } |
---|
| 340 | } |
---|
| 341 | |
---|
[2] | 342 | /* compare digest against received version */ |
---|
[608] | 343 | const Char* ok = "(unk)"; |
---|
| 344 | Bool mismatch = false; |
---|
[2] | 345 | |
---|
[608] | 346 | if (pictureHashSEI) |
---|
[2] | 347 | { |
---|
[608] | 348 | ok = "(OK)"; |
---|
| 349 | for(Int yuvIdx = 0; yuvIdx < 3; yuvIdx++) |
---|
[2] | 350 | { |
---|
[608] | 351 | for (UInt i = 0; i < numChar; i++) |
---|
[2] | 352 | { |
---|
[608] | 353 | if (recon_digest[yuvIdx][i] != pictureHashSEI->digest[yuvIdx][i]) |
---|
| 354 | { |
---|
| 355 | ok = "(***ERROR***)"; |
---|
| 356 | mismatch = true; |
---|
| 357 | } |
---|
[2] | 358 | } |
---|
| 359 | } |
---|
| 360 | } |
---|
| 361 | |
---|
[608] | 362 | printf("[%s:%s,%s] ", hashType, digestToString(recon_digest, numChar), ok); |
---|
| 363 | |
---|
| 364 | if (mismatch) |
---|
[2] | 365 | { |
---|
| 366 | g_md5_mismatch = true; |
---|
[608] | 367 | printf("[rx%s:%s] ", hashType, digestToString(pictureHashSEI->digest, numChar)); |
---|
[2] | 368 | } |
---|
| 369 | } |
---|
[56] | 370 | //! \} |
---|