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