[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 |
---|
[1313] | 4 | * granted under this license. |
---|
[5] | 5 | * |
---|
[1413] | 6 | * Copyright (c) 2010-2017, 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 | |
---|
[56] | 48 | //! \ingroup TLibDecoder |
---|
| 49 | //! \{ |
---|
[1313] | 50 | static Void calcAndPrintHashStatus(TComPicYuv& pic, const SEIDecodedPictureHash* pictureHashSEI, const BitDepths &bitDepths, UInt &numChecksumErrors); |
---|
[2] | 51 | // ==================================================================================================================== |
---|
| 52 | // Constructor / destructor / initialization / destroy |
---|
| 53 | // ==================================================================================================================== |
---|
| 54 | |
---|
| 55 | TDecGop::TDecGop() |
---|
[1313] | 56 | : m_numberOfChecksumErrorsDetected(0) |
---|
[2] | 57 | { |
---|
| 58 | m_dDecTime = 0; |
---|
| 59 | } |
---|
| 60 | |
---|
| 61 | TDecGop::~TDecGop() |
---|
| 62 | { |
---|
[1313] | 63 | |
---|
[2] | 64 | } |
---|
| 65 | |
---|
| 66 | Void TDecGop::create() |
---|
| 67 | { |
---|
[1313] | 68 | |
---|
[2] | 69 | } |
---|
| 70 | |
---|
| 71 | |
---|
| 72 | Void TDecGop::destroy() |
---|
| 73 | { |
---|
| 74 | } |
---|
| 75 | |
---|
[1313] | 76 | Void TDecGop::init( TDecEntropy* pcEntropyDecoder, |
---|
| 77 | TDecSbac* pcSbacDecoder, |
---|
[2] | 78 | TDecBinCABAC* pcBinCABAC, |
---|
[1313] | 79 | TDecCavlc* pcCavlcDecoder, |
---|
| 80 | TDecSlice* pcSliceDecoder, |
---|
[608] | 81 | TComLoopFilter* pcLoopFilter, |
---|
| 82 | TComSampleAdaptiveOffset* pcSAO |
---|
[56] | 83 | ) |
---|
[2] | 84 | { |
---|
| 85 | m_pcEntropyDecoder = pcEntropyDecoder; |
---|
| 86 | m_pcSbacDecoder = pcSbacDecoder; |
---|
| 87 | m_pcBinCABAC = pcBinCABAC; |
---|
| 88 | m_pcCavlcDecoder = pcCavlcDecoder; |
---|
| 89 | m_pcSliceDecoder = pcSliceDecoder; |
---|
| 90 | m_pcLoopFilter = pcLoopFilter; |
---|
[1313] | 91 | m_pcSAO = pcSAO; |
---|
| 92 | m_numberOfChecksumErrorsDetected = 0; |
---|
[2] | 93 | } |
---|
| 94 | |
---|
[56] | 95 | |
---|
[2] | 96 | // ==================================================================================================================== |
---|
[56] | 97 | // Private member functions |
---|
| 98 | // ==================================================================================================================== |
---|
| 99 | // ==================================================================================================================== |
---|
[2] | 100 | // Public member functions |
---|
| 101 | // ==================================================================================================================== |
---|
| 102 | |
---|
[1313] | 103 | Void TDecGop::decompressSlice(TComInputBitstream* pcBitstream, TComPic* pcPic) |
---|
[2] | 104 | { |
---|
[1313] | 105 | TComSlice* pcSlice = pcPic->getSlice(pcPic->getCurrSliceIdx()); |
---|
[56] | 106 | // Table of extracted substreams. |
---|
| 107 | // These must be deallocated AND their internal fifos, too. |
---|
| 108 | TComInputBitstream **ppcSubstreams = NULL; |
---|
[2] | 109 | |
---|
| 110 | //-- For time output for each slice |
---|
[1313] | 111 | clock_t iBeforeTime = clock(); |
---|
[608] | 112 | m_pcSbacDecoder->init( (TDecBinIf*)m_pcBinCABAC ); |
---|
| 113 | m_pcEntropyDecoder->setEntropyDecoder (m_pcSbacDecoder); |
---|
[56] | 114 | |
---|
[1313] | 115 | const UInt uiNumSubstreams = pcSlice->getNumberOfSubstreamSizes()+1; |
---|
[56] | 116 | |
---|
[608] | 117 | // init each couple {EntropyDecoder, Substream} |
---|
| 118 | ppcSubstreams = new TComInputBitstream*[uiNumSubstreams]; |
---|
| 119 | for ( UInt ui = 0 ; ui < uiNumSubstreams ; ui++ ) |
---|
| 120 | { |
---|
[1313] | 121 | ppcSubstreams[ui] = pcBitstream->extractSubstream(ui+1 < uiNumSubstreams ? (pcSlice->getSubstreamSize(ui)<<3) : pcBitstream->getNumBitsLeft()); |
---|
[608] | 122 | } |
---|
[2] | 123 | |
---|
[1413] | 124 | #if NH_3D |
---|
[608] | 125 | 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. |
---|
| 126 | { |
---|
[1313] | 127 | Int iColPoc = pcSlice->getRefPOC(RefPicList(1 - pcSlice->getColFromL0Flag()), pcSlice->getColRefIdx()); |
---|
| 128 | pcPic->setNumDdvCandPics(pcPic->getDisCandRefPictures(iColPoc)); |
---|
[608] | 129 | } |
---|
[655] | 130 | |
---|
[608] | 131 | 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. |
---|
| 132 | { |
---|
[1313] | 133 | pcPic->checkTemporalIVRef(); |
---|
[608] | 134 | } |
---|
[655] | 135 | |
---|
[608] | 136 | if(pcSlice->getIsDepth()) |
---|
| 137 | { |
---|
[1313] | 138 | pcPic->checkTextureRef(); |
---|
[608] | 139 | } |
---|
[5] | 140 | #endif |
---|
[1313] | 141 | #if NH_3D |
---|
[608] | 142 | pcSlice->setDepthToDisparityLUTs(); |
---|
[189] | 143 | #endif |
---|
[1313] | 144 | |
---|
| 145 | m_pcSliceDecoder->decompressSlice( ppcSubstreams, pcPic, m_pcSbacDecoder); |
---|
[608] | 146 | // deallocate all created substreams, including internal buffers. |
---|
| 147 | for (UInt ui = 0; ui < uiNumSubstreams; ui++) |
---|
| 148 | { |
---|
| 149 | delete ppcSubstreams[ui]; |
---|
| 150 | } |
---|
| 151 | delete[] ppcSubstreams; |
---|
[56] | 152 | |
---|
[608] | 153 | m_dDecTime += (Double)(clock()-iBeforeTime) / CLOCKS_PER_SEC; |
---|
| 154 | } |
---|
| 155 | |
---|
[1313] | 156 | Void TDecGop::filterPicture(TComPic* pcPic) |
---|
[608] | 157 | { |
---|
[1313] | 158 | TComSlice* pcSlice = pcPic->getSlice(pcPic->getCurrSliceIdx()); |
---|
[608] | 159 | |
---|
| 160 | //-- For time output for each slice |
---|
[1313] | 161 | clock_t iBeforeTime = clock(); |
---|
[608] | 162 | |
---|
| 163 | // deblocking filter |
---|
| 164 | Bool bLFCrossTileBoundary = pcSlice->getPPS()->getLoopFilterAcrossTilesEnabledFlag(); |
---|
| 165 | m_pcLoopFilter->setCfg(bLFCrossTileBoundary); |
---|
[1313] | 166 | m_pcLoopFilter->loopFilterPic( pcPic ); |
---|
| 167 | |
---|
[608] | 168 | if( pcSlice->getSPS()->getUseSAO() ) |
---|
| 169 | { |
---|
[1313] | 170 | m_pcSAO->reconstructBlkSAOParams(pcPic, pcPic->getPicSym()->getSAOBlkParam()); |
---|
| 171 | m_pcSAO->SAOProcess(pcPic); |
---|
| 172 | m_pcSAO->PCMLFDisableProcess(pcPic); |
---|
[2] | 173 | } |
---|
[1313] | 174 | #if NH_3D |
---|
| 175 | pcPic->compressMotion(2); |
---|
| 176 | #else |
---|
| 177 | pcPic->compressMotion(); |
---|
[5] | 178 | #endif |
---|
[1386] | 179 | TChar c = (pcSlice->isIntra() ? 'I' : pcSlice->isInterP() ? 'P' : 'B'); |
---|
[1313] | 180 | if (!pcSlice->isReferenced()) |
---|
| 181 | { |
---|
| 182 | c += 32; |
---|
| 183 | } |
---|
[56] | 184 | |
---|
[608] | 185 | //-- For time output for each slice |
---|
[1313] | 186 | #if NH_MV |
---|
| 187 | printf("Layer %2d POC %4d TId: %1d ( %c-SLICE, QP%3d ) ", pcSlice->getLayerId(), |
---|
[608] | 188 | pcSlice->getPOC(), |
---|
| 189 | pcSlice->getTLayer(), |
---|
| 190 | c, |
---|
| 191 | pcSlice->getSliceQp() ); |
---|
[443] | 192 | #else |
---|
[1313] | 193 | printf("POC %4d TId: %1d ( %c-SLICE, QP%3d ) ", pcSlice->getPOC(), |
---|
| 194 | pcSlice->getTLayer(), |
---|
| 195 | c, |
---|
| 196 | pcSlice->getSliceQp() ); |
---|
[443] | 197 | #endif |
---|
[56] | 198 | |
---|
[608] | 199 | m_dDecTime += (Double)(clock()-iBeforeTime) / CLOCKS_PER_SEC; |
---|
| 200 | printf ("[DT %6.3f] ", m_dDecTime ); |
---|
| 201 | m_dDecTime = 0; |
---|
[56] | 202 | |
---|
[608] | 203 | for (Int iRefList = 0; iRefList < 2; iRefList++) |
---|
| 204 | { |
---|
| 205 | printf ("[L%d ", iRefList); |
---|
| 206 | for (Int iRefIndex = 0; iRefIndex < pcSlice->getNumRefIdx(RefPicList(iRefList)); iRefIndex++) |
---|
[2] | 207 | { |
---|
[1313] | 208 | #if NH_MV |
---|
[608] | 209 | if( pcSlice->getLayerId() != pcSlice->getRefLayerId( RefPicList(iRefList), iRefIndex ) ) |
---|
[2] | 210 | { |
---|
[608] | 211 | printf( "V%d ", pcSlice->getRefLayerId( RefPicList(iRefList), iRefIndex ) ); |
---|
[2] | 212 | } |
---|
[608] | 213 | else |
---|
[2] | 214 | { |
---|
[608] | 215 | #endif |
---|
| 216 | printf ("%d ", pcSlice->getRefPOC(RefPicList(iRefList), iRefIndex)); |
---|
[1313] | 217 | #if NH_MV |
---|
[2] | 218 | } |
---|
[608] | 219 | #endif |
---|
[2] | 220 | } |
---|
[608] | 221 | printf ("] "); |
---|
| 222 | } |
---|
| 223 | if (m_decodedPictureHashSEIEnabled) |
---|
| 224 | { |
---|
[1313] | 225 | SEIMessages pictureHashes = getSeisByType(pcPic->getSEIs(), SEI::DECODED_PICTURE_HASH ); |
---|
[608] | 226 | const SEIDecodedPictureHash *hash = ( pictureHashes.size() > 0 ) ? (SEIDecodedPictureHash*) *(pictureHashes.begin()) : NULL; |
---|
| 227 | if (pictureHashes.size() > 1) |
---|
[56] | 228 | { |
---|
[608] | 229 | printf ("Warning: Got multiple decoded picture hash SEI messages. Using first."); |
---|
[2] | 230 | } |
---|
[1313] | 231 | calcAndPrintHashStatus(*(pcPic->getPicYuvRec()), hash, pcSlice->getSPS()->getBitDepths(), m_numberOfChecksumErrorsDetected); |
---|
[608] | 232 | } |
---|
[1313] | 233 | |
---|
| 234 | printf("\n"); |
---|
| 235 | #if !NH_MV |
---|
| 236 | pcPic->setOutputMark(pcPic->getSlice(0)->getPicOutputFlag() ? true : false); |
---|
| 237 | pcPic->setReconMark(true); |
---|
[1084] | 238 | #endif |
---|
[2] | 239 | } |
---|
| 240 | |
---|
| 241 | /** |
---|
[608] | 242 | * Calculate and print hash for pic, compare to picture_digest SEI if |
---|
| 243 | * present in seis. seis may be NULL. Hash is printed to stdout, in |
---|
[2] | 244 | * a manner suitable for the status line. Theformat is: |
---|
[608] | 245 | * [Hash_type:xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx,(yyy)] |
---|
| 246 | * Where, x..x is the hash |
---|
[2] | 247 | * yyy has the following meanings: |
---|
[608] | 248 | * OK - calculated hash matches the SEI message |
---|
| 249 | * ***ERROR*** - calculated hash does not match the SEI message |
---|
[2] | 250 | * unk - no SEI message was available for comparison |
---|
| 251 | */ |
---|
[1313] | 252 | static Void calcAndPrintHashStatus(TComPicYuv& pic, const SEIDecodedPictureHash* pictureHashSEI, const BitDepths &bitDepths, UInt &numChecksumErrors) |
---|
[2] | 253 | { |
---|
| 254 | /* calculate MD5sum for entire reconstructed picture */ |
---|
[1313] | 255 | TComPictureHash recon_digest; |
---|
[608] | 256 | Int numChar=0; |
---|
[1386] | 257 | const TChar* hashType = "\0"; |
---|
[2] | 258 | |
---|
[608] | 259 | if (pictureHashSEI) |
---|
| 260 | { |
---|
| 261 | switch (pictureHashSEI->method) |
---|
| 262 | { |
---|
[1386] | 263 | case HASHTYPE_MD5: |
---|
[1313] | 264 | { |
---|
| 265 | hashType = "MD5"; |
---|
| 266 | numChar = calcMD5(pic, recon_digest, bitDepths); |
---|
| 267 | break; |
---|
| 268 | } |
---|
[1386] | 269 | case HASHTYPE_CRC: |
---|
[1313] | 270 | { |
---|
| 271 | hashType = "CRC"; |
---|
| 272 | numChar = calcCRC(pic, recon_digest, bitDepths); |
---|
| 273 | break; |
---|
| 274 | } |
---|
[1386] | 275 | case HASHTYPE_CHECKSUM: |
---|
[1313] | 276 | { |
---|
| 277 | hashType = "Checksum"; |
---|
| 278 | numChar = calcChecksum(pic, recon_digest, bitDepths); |
---|
| 279 | break; |
---|
| 280 | } |
---|
| 281 | default: |
---|
| 282 | { |
---|
| 283 | assert (!"unknown hash type"); |
---|
| 284 | break; |
---|
| 285 | } |
---|
[608] | 286 | } |
---|
| 287 | } |
---|
| 288 | |
---|
[2] | 289 | /* compare digest against received version */ |
---|
[1386] | 290 | const TChar* ok = "(unk)"; |
---|
[608] | 291 | Bool mismatch = false; |
---|
[2] | 292 | |
---|
[608] | 293 | if (pictureHashSEI) |
---|
[2] | 294 | { |
---|
[608] | 295 | ok = "(OK)"; |
---|
[1313] | 296 | if (recon_digest != pictureHashSEI->m_pictureHash) |
---|
[2] | 297 | { |
---|
[1313] | 298 | ok = "(***ERROR***)"; |
---|
| 299 | mismatch = true; |
---|
[2] | 300 | } |
---|
| 301 | } |
---|
| 302 | |
---|
[1313] | 303 | printf("[%s:%s,%s] ", hashType, hashToString(recon_digest, numChar).c_str(), ok); |
---|
[608] | 304 | |
---|
| 305 | if (mismatch) |
---|
[2] | 306 | { |
---|
[1313] | 307 | numChecksumErrors++; |
---|
| 308 | printf("[rx%s:%s] ", hashType, hashToString(pictureHashSEI->m_pictureHash, numChar).c_str()); |
---|
[2] | 309 | } |
---|
| 310 | } |
---|
[56] | 311 | //! \} |
---|