[313] | 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 |
---|
[1029] | 4 | * granted under this license. |
---|
[313] | 5 | * |
---|
[1259] | 6 | * Copyright (c) 2010-2015, ITU/ISO/IEC |
---|
[313] | 7 | * All rights reserved. |
---|
| 8 | * |
---|
| 9 | * Redistribution and use in source and binary forms, with or without |
---|
| 10 | * modification, are permitted provided that the following conditions are met: |
---|
| 11 | * |
---|
| 12 | * * Redistributions of source code must retain the above copyright notice, |
---|
| 13 | * this list of conditions and the following disclaimer. |
---|
| 14 | * * Redistributions in binary form must reproduce the above copyright notice, |
---|
| 15 | * this list of conditions and the following disclaimer in the documentation |
---|
| 16 | * and/or other materials provided with the distribution. |
---|
| 17 | * * Neither the name of the ITU/ISO/IEC nor the names of its contributors may |
---|
| 18 | * be used to endorse or promote products derived from this software without |
---|
| 19 | * specific prior written permission. |
---|
| 20 | * |
---|
| 21 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
---|
| 22 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
---|
| 23 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
---|
| 24 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS |
---|
| 25 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
---|
| 26 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
---|
| 27 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
---|
| 28 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
---|
| 29 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
---|
| 30 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF |
---|
| 31 | * THE POSSIBILITY OF SUCH DAMAGE. |
---|
| 32 | */ |
---|
| 33 | |
---|
| 34 | /** \file 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" |
---|
| 43 | #include "libmd5/MD5.h" |
---|
| 44 | #include "TLibCommon/SEI.h" |
---|
| 45 | #if SVC_EXTENSION |
---|
| 46 | #include "TDecTop.h" |
---|
[1029] | 47 | #if CONFORMANCE_BITSTREAM_MODE |
---|
| 48 | #include <algorithm> |
---|
[313] | 49 | #endif |
---|
[1029] | 50 | #endif |
---|
| 51 | |
---|
[313] | 52 | #include <time.h> |
---|
| 53 | |
---|
[924] | 54 | #if CONFORMANCE_BITSTREAM_MODE |
---|
[930] | 55 | Bool pocCompareFunction( const TComPic &pic1, const TComPic &pic2 ) |
---|
[924] | 56 | { |
---|
[930] | 57 | return (const_cast<TComPic&>(pic1).getPOC() < const_cast<TComPic&>(pic2).getPOC()); |
---|
[924] | 58 | } |
---|
| 59 | #endif |
---|
[1029] | 60 | |
---|
[313] | 61 | //! \ingroup TLibDecoder |
---|
| 62 | //! \{ |
---|
[1292] | 63 | static Void calcAndPrintHashStatus(TComPicYuv& pic, const SEIDecodedPictureHash* pictureHashSEI, const BitDepths &bitDepths, UInt &numChecksumErrors); |
---|
[313] | 64 | // ==================================================================================================================== |
---|
| 65 | // Constructor / destructor / initialization / destroy |
---|
| 66 | // ==================================================================================================================== |
---|
| 67 | |
---|
| 68 | TDecGop::TDecGop() |
---|
[1292] | 69 | : m_numberOfChecksumErrorsDetected(0) |
---|
[313] | 70 | { |
---|
| 71 | m_dDecTime = 0; |
---|
| 72 | } |
---|
| 73 | |
---|
| 74 | TDecGop::~TDecGop() |
---|
| 75 | { |
---|
[1029] | 76 | |
---|
[313] | 77 | } |
---|
| 78 | |
---|
| 79 | Void TDecGop::create() |
---|
| 80 | { |
---|
[1029] | 81 | |
---|
[313] | 82 | } |
---|
| 83 | |
---|
| 84 | Void TDecGop::destroy() |
---|
| 85 | { |
---|
| 86 | } |
---|
[1029] | 87 | |
---|
[313] | 88 | #if SVC_EXTENSION |
---|
[1029] | 89 | Void TDecGop::init( TDecTop** ppcDecTop, |
---|
[1459] | 90 | TDecEntropy* pcEntropyDecoder, |
---|
[313] | 91 | #else |
---|
[1029] | 92 | Void TDecGop::init( TDecEntropy* pcEntropyDecoder, |
---|
[313] | 93 | #endif |
---|
[1029] | 94 | TDecSbac* pcSbacDecoder, |
---|
[313] | 95 | TDecBinCABAC* pcBinCABAC, |
---|
[1029] | 96 | TDecCavlc* pcCavlcDecoder, |
---|
| 97 | TDecSlice* pcSliceDecoder, |
---|
[313] | 98 | TComLoopFilter* pcLoopFilter, |
---|
| 99 | TComSampleAdaptiveOffset* pcSAO |
---|
| 100 | ) |
---|
| 101 | { |
---|
| 102 | m_pcEntropyDecoder = pcEntropyDecoder; |
---|
| 103 | m_pcSbacDecoder = pcSbacDecoder; |
---|
| 104 | m_pcBinCABAC = pcBinCABAC; |
---|
| 105 | m_pcCavlcDecoder = pcCavlcDecoder; |
---|
| 106 | m_pcSliceDecoder = pcSliceDecoder; |
---|
| 107 | m_pcLoopFilter = pcLoopFilter; |
---|
[1292] | 108 | m_pcSAO = pcSAO; |
---|
| 109 | m_numberOfChecksumErrorsDetected = 0; |
---|
| 110 | |
---|
[313] | 111 | #if SVC_EXTENSION |
---|
| 112 | m_ppcTDecTop = ppcDecTop; |
---|
| 113 | #endif |
---|
| 114 | } |
---|
| 115 | |
---|
| 116 | |
---|
| 117 | // ==================================================================================================================== |
---|
| 118 | // Private member functions |
---|
| 119 | // ==================================================================================================================== |
---|
| 120 | // ==================================================================================================================== |
---|
| 121 | // Public member functions |
---|
| 122 | // ==================================================================================================================== |
---|
| 123 | |
---|
[1029] | 124 | Void TDecGop::decompressSlice(TComInputBitstream* pcBitstream, TComPic* pcPic) |
---|
[313] | 125 | { |
---|
[1029] | 126 | TComSlice* pcSlice = pcPic->getSlice(pcPic->getCurrSliceIdx()); |
---|
[313] | 127 | // Table of extracted substreams. |
---|
| 128 | // These must be deallocated AND their internal fifos, too. |
---|
| 129 | TComInputBitstream **ppcSubstreams = NULL; |
---|
| 130 | |
---|
| 131 | //-- For time output for each slice |
---|
[1029] | 132 | clock_t iBeforeTime = clock(); |
---|
[313] | 133 | m_pcSbacDecoder->init( (TDecBinIf*)m_pcBinCABAC ); |
---|
| 134 | m_pcEntropyDecoder->setEntropyDecoder (m_pcSbacDecoder); |
---|
| 135 | |
---|
[1029] | 136 | const UInt uiNumSubstreams = pcSlice->getNumberOfSubstreamSizes()+1; |
---|
[313] | 137 | |
---|
| 138 | // init each couple {EntropyDecoder, Substream} |
---|
| 139 | ppcSubstreams = new TComInputBitstream*[uiNumSubstreams]; |
---|
| 140 | for ( UInt ui = 0 ; ui < uiNumSubstreams ; ui++ ) |
---|
| 141 | { |
---|
[1029] | 142 | ppcSubstreams[ui] = pcBitstream->extractSubstream(ui+1 < uiNumSubstreams ? (pcSlice->getSubstreamSize(ui)<<3) : pcBitstream->getNumBitsLeft()); |
---|
[313] | 143 | } |
---|
| 144 | |
---|
[1029] | 145 | m_pcSliceDecoder->decompressSlice( ppcSubstreams, pcPic, m_pcSbacDecoder); |
---|
[313] | 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; |
---|
| 152 | |
---|
| 153 | m_dDecTime += (Double)(clock()-iBeforeTime) / CLOCKS_PER_SEC; |
---|
| 154 | } |
---|
| 155 | |
---|
[1029] | 156 | Void TDecGop::filterPicture(TComPic* pcPic) |
---|
[313] | 157 | { |
---|
[1029] | 158 | TComSlice* pcSlice = pcPic->getSlice(pcPic->getCurrSliceIdx()); |
---|
[313] | 159 | |
---|
| 160 | //-- For time output for each slice |
---|
[1029] | 161 | clock_t iBeforeTime = clock(); |
---|
[313] | 162 | |
---|
| 163 | // deblocking filter |
---|
| 164 | Bool bLFCrossTileBoundary = pcSlice->getPPS()->getLoopFilterAcrossTilesEnabledFlag(); |
---|
| 165 | m_pcLoopFilter->setCfg(bLFCrossTileBoundary); |
---|
[1029] | 166 | m_pcLoopFilter->loopFilterPic( pcPic ); |
---|
| 167 | |
---|
[313] | 168 | if( pcSlice->getSPS()->getUseSAO() ) |
---|
| 169 | { |
---|
[1029] | 170 | m_pcSAO->reconstructBlkSAOParams(pcPic, pcPic->getPicSym()->getSAOBlkParam()); |
---|
| 171 | m_pcSAO->SAOProcess(pcPic); |
---|
| 172 | m_pcSAO->PCMLFDisableProcess(pcPic); |
---|
[313] | 173 | } |
---|
[1029] | 174 | |
---|
| 175 | pcPic->compressMotion(); |
---|
[1442] | 176 | TChar c = (pcSlice->isIntra() ? 'I' : pcSlice->isInterP() ? 'P' : 'B'); |
---|
[1246] | 177 | if (!pcSlice->isReferenced()) |
---|
| 178 | { |
---|
| 179 | c += 32; |
---|
| 180 | } |
---|
[313] | 181 | |
---|
| 182 | //-- For time output for each slice |
---|
| 183 | #if SVC_EXTENSION |
---|
[1029] | 184 | printf("POC %4d LId: %1d TId: %1d ( %c-SLICE %s, QP%3d ) ", pcSlice->getPOC(), |
---|
| 185 | pcPic->getLayerId(), |
---|
[313] | 186 | pcSlice->getTLayer(), |
---|
| 187 | c, |
---|
[1353] | 188 | nalUnitTypeToString( pcSlice->getNalUnitType() ), |
---|
[313] | 189 | pcSlice->getSliceQp() ); |
---|
| 190 | #else |
---|
[1029] | 191 | printf("POC %4d TId: %1d ( %c-SLICE, QP%3d ) ", pcSlice->getPOC(), |
---|
| 192 | pcSlice->getTLayer(), |
---|
| 193 | c, |
---|
| 194 | pcSlice->getSliceQp() ); |
---|
| 195 | |
---|
[313] | 196 | #endif |
---|
| 197 | m_dDecTime += (Double)(clock()-iBeforeTime) / CLOCKS_PER_SEC; |
---|
| 198 | printf ("[DT %6.3f] ", m_dDecTime ); |
---|
| 199 | m_dDecTime = 0; |
---|
| 200 | |
---|
| 201 | for (Int iRefList = 0; iRefList < 2; iRefList++) |
---|
| 202 | { |
---|
| 203 | printf ("[L%d ", iRefList); |
---|
| 204 | for (Int iRefIndex = 0; iRefIndex < pcSlice->getNumRefIdx(RefPicList(iRefList)); iRefIndex++) |
---|
| 205 | { |
---|
[442] | 206 | #if SVC_EXTENSION |
---|
[1482] | 207 | if( pcSlice->getRefPic(RefPicList(iRefList), iRefIndex)->isILR( pcSlice->getLayerId() ) ) |
---|
[313] | 208 | { |
---|
[840] | 209 | UInt refLayerId = pcSlice->getRefPic(RefPicList(iRefList), iRefIndex)->getLayerId(); |
---|
[890] | 210 | UInt refLayerIdc = pcSlice->getReferenceLayerIdc(refLayerId); |
---|
[1419] | 211 | assert( pcSlice->getPic()->getPosScalingFactor(refLayerIdc, 0) ); |
---|
| 212 | assert( pcSlice->getPic()->getPosScalingFactor(refLayerIdc, 1) ); |
---|
[840] | 213 | |
---|
[1431] | 214 | printf( "%d(%d, {%1.2f, %1.2f}x)", pcSlice->getRefPOC(RefPicList(iRefList), iRefIndex), refLayerId, (Double)POS_SCALING_FACTOR_1X/pcSlice->getPic()->getPosScalingFactor(refLayerIdc, 0), (Double)POS_SCALING_FACTOR_1X/pcSlice->getPic()->getPosScalingFactor(refLayerIdc, 1) ); |
---|
[313] | 215 | } |
---|
| 216 | else |
---|
[442] | 217 | { |
---|
| 218 | printf ("%d", pcSlice->getRefPOC(RefPicList(iRefList), iRefIndex)); |
---|
| 219 | } |
---|
[1148] | 220 | |
---|
[442] | 221 | if( pcSlice->getEnableTMVPFlag() && iRefList == 1 - pcSlice->getColFromL0Flag() && iRefIndex == pcSlice->getColRefIdx() ) |
---|
| 222 | { |
---|
| 223 | printf( "c" ); |
---|
| 224 | } |
---|
| 225 | |
---|
| 226 | printf( " " ); |
---|
| 227 | #else |
---|
[313] | 228 | printf ("%d ", pcSlice->getRefPOC(RefPicList(iRefList), iRefIndex)); |
---|
[442] | 229 | #endif |
---|
[313] | 230 | } |
---|
| 231 | printf ("] "); |
---|
| 232 | } |
---|
| 233 | if (m_decodedPictureHashSEIEnabled) |
---|
| 234 | { |
---|
[1029] | 235 | SEIMessages pictureHashes = getSeisByType(pcPic->getSEIs(), SEI::DECODED_PICTURE_HASH ); |
---|
[313] | 236 | const SEIDecodedPictureHash *hash = ( pictureHashes.size() > 0 ) ? (SEIDecodedPictureHash*) *(pictureHashes.begin()) : NULL; |
---|
| 237 | if (pictureHashes.size() > 1) |
---|
| 238 | { |
---|
| 239 | printf ("Warning: Got multiple decoded picture hash SEI messages. Using first."); |
---|
| 240 | } |
---|
[1287] | 241 | #if SVC_EXTENSION |
---|
[1292] | 242 | calcAndPrintHashStatus(*(pcPic->getPicYuvRec()), hash, pcSlice->getBitDepths(), m_numberOfChecksumErrorsDetected); |
---|
[1287] | 243 | #else |
---|
[1292] | 244 | calcAndPrintHashStatus(*(pcPic->getPicYuvRec()), hash, pcSlice->getSPS()->getBitDepths(), m_numberOfChecksumErrorsDetected); |
---|
[1287] | 245 | #endif |
---|
[313] | 246 | } |
---|
[924] | 247 | #if CONFORMANCE_BITSTREAM_MODE |
---|
[1049] | 248 | if( this->getLayerDec(pcPic->getLayerId())->getConfModeFlag() ) |
---|
[924] | 249 | { |
---|
| 250 | // Add this reconstructed picture to the parallel buffer. |
---|
[1049] | 251 | std::vector<TComPic> *thisLayerBuffer = (this->getLayerDec(pcPic->getLayerId()))->getConfListPic(); |
---|
[1029] | 252 | thisLayerBuffer->push_back(*pcPic); |
---|
[924] | 253 | std::sort( thisLayerBuffer->begin(), thisLayerBuffer->end(), pocCompareFunction ); |
---|
| 254 | } |
---|
| 255 | #endif |
---|
[313] | 256 | |
---|
[1029] | 257 | printf("\n"); |
---|
| 258 | |
---|
| 259 | pcPic->setOutputMark(pcPic->getSlice(0)->getPicOutputFlag() ? true : false); |
---|
| 260 | pcPic->setReconMark(true); |
---|
[313] | 261 | } |
---|
| 262 | |
---|
| 263 | /** |
---|
| 264 | * Calculate and print hash for pic, compare to picture_digest SEI if |
---|
| 265 | * present in seis. seis may be NULL. Hash is printed to stdout, in |
---|
| 266 | * a manner suitable for the status line. Theformat is: |
---|
| 267 | * [Hash_type:xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx,(yyy)] |
---|
| 268 | * Where, x..x is the hash |
---|
| 269 | * yyy has the following meanings: |
---|
| 270 | * OK - calculated hash matches the SEI message |
---|
| 271 | * ***ERROR*** - calculated hash does not match the SEI message |
---|
| 272 | * unk - no SEI message was available for comparison |
---|
| 273 | */ |
---|
[1292] | 274 | static Void calcAndPrintHashStatus(TComPicYuv& pic, const SEIDecodedPictureHash* pictureHashSEI, const BitDepths &bitDepths, UInt &numChecksumErrors) |
---|
[313] | 275 | { |
---|
| 276 | /* calculate MD5sum for entire reconstructed picture */ |
---|
[1273] | 277 | TComPictureHash recon_digest; |
---|
[313] | 278 | Int numChar=0; |
---|
[1442] | 279 | const TChar* hashType = "\0"; |
---|
[313] | 280 | |
---|
| 281 | if (pictureHashSEI) |
---|
| 282 | { |
---|
| 283 | switch (pictureHashSEI->method) |
---|
| 284 | { |
---|
[1459] | 285 | case HASHTYPE_MD5: |
---|
[1029] | 286 | { |
---|
| 287 | hashType = "MD5"; |
---|
[1287] | 288 | numChar = calcMD5(pic, recon_digest, bitDepths); |
---|
[1029] | 289 | break; |
---|
| 290 | } |
---|
[1459] | 291 | case HASHTYPE_CRC: |
---|
[1029] | 292 | { |
---|
| 293 | hashType = "CRC"; |
---|
[1287] | 294 | numChar = calcCRC(pic, recon_digest, bitDepths); |
---|
[1029] | 295 | break; |
---|
| 296 | } |
---|
[1459] | 297 | case HASHTYPE_CHECKSUM: |
---|
[1029] | 298 | { |
---|
| 299 | hashType = "Checksum"; |
---|
[1287] | 300 | numChar = calcChecksum(pic, recon_digest, bitDepths); |
---|
[1029] | 301 | break; |
---|
| 302 | } |
---|
| 303 | default: |
---|
| 304 | { |
---|
| 305 | assert (!"unknown hash type"); |
---|
| 306 | break; |
---|
| 307 | } |
---|
[313] | 308 | } |
---|
| 309 | } |
---|
| 310 | |
---|
| 311 | /* compare digest against received version */ |
---|
[1442] | 312 | const TChar* ok = "(unk)"; |
---|
[313] | 313 | Bool mismatch = false; |
---|
| 314 | |
---|
| 315 | if (pictureHashSEI) |
---|
| 316 | { |
---|
| 317 | ok = "(OK)"; |
---|
[1273] | 318 | if (recon_digest != pictureHashSEI->m_pictureHash) |
---|
[313] | 319 | { |
---|
[1029] | 320 | ok = "(***ERROR***)"; |
---|
| 321 | mismatch = true; |
---|
[313] | 322 | } |
---|
| 323 | } |
---|
| 324 | |
---|
[1273] | 325 | printf("[%s:%s,%s] ", hashType, hashToString(recon_digest, numChar).c_str(), ok); |
---|
[313] | 326 | |
---|
| 327 | if (mismatch) |
---|
| 328 | { |
---|
[1292] | 329 | numChecksumErrors++; |
---|
[1273] | 330 | printf("[rx%s:%s] ", hashType, hashToString(pictureHashSEI->m_pictureHash, numChar).c_str()); |
---|
[313] | 331 | } |
---|
| 332 | } |
---|
| 333 | //! \} |
---|