Ticket #1070: lf_fix.patch

File lf_fix.patch, 14.0 KB (added by pieterkapsenberg, 11 years ago)
  • App/TAppDecoder/TAppDecTop.cpp

     
    126126
    127127    // call actual decoding function
    128128    Bool bNewPicture = false;
     129    Bool bPicComplete = false;
    129130    if (nalUnit.empty())
    130131    {
    131132      /* this can happen if the following occur:
     
    152153      }
    153154      else
    154155      {
    155         bNewPicture = m_cTDecTop.decode(nalu, m_iSkipFrame, m_iPOCLastDisplay);
     156        bNewPicture = m_cTDecTop.decode(nalu, m_iSkipFrame, m_iPOCLastDisplay, bPicComplete);
     157        if(bPicComplete)
     158        {
     159          m_cTDecTop.executeLoopFilters(poc, pcListPic);
     160        }
    156161        if (bNewPicture)
    157162        {
    158163          bitstreamFile.clear();
     
    166171        bPreviousPictureDecoded = true;
    167172      }
    168173    }
    169     if (bNewPicture || !bitstreamFile)
    170     {
    171       m_cTDecTop.executeLoopFilters(poc, pcListPic);
    172     }
    173 
    174174    if( pcListPic )
    175175    {
    176176      if ( m_pchReconFile && !recon_opened )
  • Lib/TLibDecoder/TDecGop.cpp

     
    4040#include "TDecSbac.h"
    4141#include "TDecBinCoder.h"
    4242#include "TDecBinCoderCABAC.h"
    43 #include "libmd5/MD5.h"
    44 #include "TLibCommon/SEI.h"
    4543
    4644#include <time.h>
    4745
    48 extern Bool g_md5_mismatch; ///< top level flag to signal when there is a decode problem
    49 
    5046//! \ingroup TLibDecoder
    5147//! \{
    52 static void calcAndPrintHashStatus(TComPicYuv& pic, const SEIDecodedPictureHash* pictureHashSEI);
     48
    5349// ====================================================================================================================
    5450// Constructor / destructor / initialization / destroy
    5551// ====================================================================================================================
     
    10298// Public member functions
    10399// ====================================================================================================================
    104100
    105 Void TDecGop::decompressSlice(TComInputBitstream* pcBitstream, TComPic*& rpcPic)
     101Void TDecGop::decompressSlice(TComInputBitstream* pcBitstream, TComPic*& rpcPic, Bool& bPicComplete)
    106102{
    107103  TComSlice*  pcSlice = rpcPic->getSlice(rpcPic->getCurrSliceIdx());
    108104  // Table of extracted substreams.
     
    152148    m_LFCrossSliceBoundaryFlag.push_back( pcSlice->getLFCrossSliceBoundaryFlag());
    153149  }
    154150  m_pcSbacDecoders[0].load(m_pcSbacDecoder);
    155   m_pcSliceDecoder->decompressSlice( ppcSubstreams, rpcPic, m_pcSbacDecoder, m_pcSbacDecoders);
     151  m_pcSliceDecoder->decompressSlice( ppcSubstreams, rpcPic, m_pcSbacDecoder, m_pcSbacDecoders, bPicComplete);
    156152  m_pcEntropyDecoder->setBitstream(  ppcSubstreams[uiNumSubstreams-1] );
    157153  // deallocate all created substreams, including internal buffers.
    158154  for (UInt ui = 0; ui < uiNumSubstreams; ui++)
     
    227223    }
    228224    printf ("] ");
    229225  }
    230   if (m_decodedPictureHashSEIEnabled)
    231   {
    232     SEIMessages pictureHashes = getSeisByType(rpcPic->getSEIs(), SEI::DECODED_PICTURE_HASH );
    233     const SEIDecodedPictureHash *hash = ( pictureHashes.size() > 0 ) ? (SEIDecodedPictureHash*) *(pictureHashes.begin()) : NULL;
    234     if (pictureHashes.size() > 1)
    235     {
    236       printf ("Warning: Got multiple decoded picture hash SEI messages. Using first.");
    237     }
    238     calcAndPrintHashStatus(*rpcPic->getPicYuvRec(), hash);
    239   }
    240226
    241227  rpcPic->setOutputMark(true);
    242228  rpcPic->setReconMark(true);
     
    244230  m_LFCrossSliceBoundaryFlag.clear();
    245231}
    246232
    247 /**
    248  * Calculate and print hash for pic, compare to picture_digest SEI if
    249  * present in seis.  seis may be NULL.  Hash is printed to stdout, in
    250  * a manner suitable for the status line. Theformat is:
    251  *  [Hash_type:xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx,(yyy)]
    252  * Where, x..x is the hash
    253  *        yyy has the following meanings:
    254  *            OK          - calculated hash matches the SEI message
    255  *            ***ERROR*** - calculated hash does not match the SEI message
    256  *            unk         - no SEI message was available for comparison
    257  */
    258 static void calcAndPrintHashStatus(TComPicYuv& pic, const SEIDecodedPictureHash* pictureHashSEI)
    259 {
    260   /* calculate MD5sum for entire reconstructed picture */
    261   UChar recon_digest[3][16];
    262   Int numChar=0;
    263   const Char* hashType = "\0";
    264233
    265   if (pictureHashSEI)
    266   {
    267     switch (pictureHashSEI->method)
    268     {
    269     case SEIDecodedPictureHash::MD5:
    270       {
    271         hashType = "MD5";
    272         calcMD5(pic, recon_digest);
    273         numChar = 16;
    274         break;
    275       }
    276     case SEIDecodedPictureHash::CRC:
    277       {
    278         hashType = "CRC";
    279         calcCRC(pic, recon_digest);
    280         numChar = 2;
    281         break;
    282       }
    283     case SEIDecodedPictureHash::CHECKSUM:
    284       {
    285         hashType = "Checksum";
    286         calcChecksum(pic, recon_digest);
    287         numChar = 4;
    288         break;
    289       }
    290     default:
    291       {
    292         assert (!"unknown hash type");
    293       }
    294     }
    295   }
    296 
    297   /* compare digest against received version */
    298   const Char* ok = "(unk)";
    299   Bool mismatch = false;
    300 
    301   if (pictureHashSEI)
    302   {
    303     ok = "(OK)";
    304     for(Int yuvIdx = 0; yuvIdx < 3; yuvIdx++)
    305     {
    306       for (UInt i = 0; i < numChar; i++)
    307       {
    308         if (recon_digest[yuvIdx][i] != pictureHashSEI->digest[yuvIdx][i])
    309         {
    310           ok = "(***ERROR***)";
    311           mismatch = true;
    312         }
    313       }
    314     }
    315   }
    316 
    317   printf("[%s:%s,%s] ", hashType, digestToString(recon_digest, numChar), ok);
    318 
    319   if (mismatch)
    320   {
    321     g_md5_mismatch = true;
    322     printf("[rx%s:%s] ", hashType, digestToString(pictureHashSEI->digest, numChar));
    323   }
    324 }
    325234//! \}
  • Lib/TLibDecoder/TDecGop.h

     
    8080 
    8181  TComSampleAdaptiveOffset*     m_pcSAO;
    8282  Double                m_dDecTime;
    83   Int                   m_decodedPictureHashSEIEnabled;  ///< Checksum(3)/CRC(2)/MD5(1)/disable(0) acting on decoded picture hash SEI message
    8483
    8584  //! list that contains the CU address of each slice plus the end address
    8685  std::vector<Int> m_sliceStartCUAddress;
     
    10099                 );
    101100  Void  create  ();
    102101  Void  destroy ();
    103   Void  decompressSlice(TComInputBitstream* pcBitstream, TComPic*& rpcPic );
     102  Void  decompressSlice(TComInputBitstream* pcBitstream, TComPic*& rpcPic, Bool &bPicComplete);
    104103  Void  filterPicture  (TComPic*& rpcPic );
    105104
    106   void setDecodedPictureHashSEIEnabled(Int enabled) { m_decodedPictureHashSEIEnabled = enabled; }
    107105
    108106};
    109107
  • Lib/TLibDecoder/TDecSlice.cpp

     
    105105  m_pcCuDecoder       = pcCuDecoder;
    106106}
    107107
    108 Void TDecSlice::decompressSlice(TComInputBitstream** ppcSubstreams, TComPic*& rpcPic, TDecSbac* pcSbacDecoder, TDecSbac* pcSbacDecoders)
     108Void TDecSlice::decompressSlice(TComInputBitstream** ppcSubstreams, TComPic*& rpcPic, TDecSbac* pcSbacDecoder, TDecSbac* pcSbacDecoders, Bool& bPicComplete)
    109109{
    110110  TComDataCU* pcCU;
    111111  UInt        uiIsLast = 0;
     
    381381      CTXMem[0]->loadContexts( pcSbacDecoder );//ctx end of dep.slice
    382382      return;
    383383    }
     384  bPicComplete = iCUAddr == (rpcPic->getNumCUsInFrame()-1);
    384385  }
    385386}
    386387
  • Lib/TLibDecoder/TDecSlice.h

     
    8080  Void  create            ();
    8181  Void  destroy           ();
    8282 
    83   Void  decompressSlice   ( TComInputBitstream** ppcSubstreams,   TComPic*& rpcPic, TDecSbac* pcSbacDecoder, TDecSbac* pcSbacDecoders );
     83  Void  decompressSlice   ( TComInputBitstream** ppcSubstreams,   TComPic*& rpcPic, TDecSbac* pcSbacDecoder, TDecSbac* pcSbacDecoders, Bool& bPicComplete );
    8484  Void      initCtxMem(  UInt i );
    8585  Void      setCtxMem( TDecSbac* sb, Int b )   { CTXMem[b] = sb; }
    8686};
  • Lib/TLibDecoder/TDecTop.cpp

     
    3737
    3838#include "NALread.h"
    3939#include "TDecTop.h"
     40#include "libmd5/MD5.h"
     41#include "TLibCommon/SEI.h"
    4042
    4143//! \ingroup TLibDecoder
     44extern Bool g_md5_mismatch; ///< top level flag to signal when there is a decode problem
     45
     46static void calcAndPrintHashStatus(TComPicYuv& pic, const SEIDecodedPictureHash* pictureHashSEI);
     47
    4248//! \{
    4349
    4450TDecTop::TDecTop()
     
    282288  m_cLoopFilter.        create( g_uiMaxCUDepth );
    283289}
    284290
    285 Bool TDecTop::xDecodeSlice(InputNALUnit &nalu, Int &iSkipFrame, Int iPOCLastDisplay )
     291Bool TDecTop::xDecodeSlice(InputNALUnit &nalu, Int &iSkipFrame, Int iPOCLastDisplay, Bool &bPicComplete )
    286292{
    287293  TComPic*&   pcPic         = m_pcPic;
    288294  m_apcSlicePilot->initSlice();
     
    570576  }
    571577
    572578  //  Decode a picture
    573   m_cGopDecoder.decompressSlice(nalu.m_Bitstream, pcPic);
    574 
     579  m_cGopDecoder.decompressSlice(nalu.m_Bitstream, pcPic, bPicComplete);
     580 
    575581  m_bFirstSliceInPicture = false;
    576582  m_uiSliceIdx++;
    577583
     
    618624  if(nalUnitType == NAL_UNIT_SEI_SUFFIX)
    619625  {
    620626    m_seiReader.parseSEImessage( bs, m_pcPic->getSEIs(), nalUnitType, m_parameterSetManagerDecoder.getActiveSPS() );
     627    if (m_decodedPictureHashSEIEnabled)
     628    {
     629      SEIMessages pictureHashes = getSeisByType(m_pcPic->getSEIs(), SEI::DECODED_PICTURE_HASH );
     630      const SEIDecodedPictureHash *hash = ( pictureHashes.size() > 0 ) ? (SEIDecodedPictureHash*) *(pictureHashes.begin()) : NULL;
     631      if (pictureHashes.size() > 1)
     632      {
     633        printf ("Warning: Got multiple decoded picture hash SEI messages. Using first.");
     634      }
     635      calcAndPrintHashStatus(*m_pcPic->getPicYuvRec(), hash);
     636    }
    621637  }
    622638  else
    623639  {
     
    636652  }
    637653}
    638654
    639 Bool TDecTop::decode(InputNALUnit& nalu, Int& iSkipFrame, Int& iPOCLastDisplay)
     655Bool TDecTop::decode(InputNALUnit& nalu, Int& iSkipFrame, Int& iPOCLastDisplay, Bool& bPicComplete)
    640656{
    641657  // Initialize entropy decoder
    642658  m_cEntropyDecoder.setEntropyDecoder (&m_cCavlcDecoder);
     
    677693    case NAL_UNIT_CODED_SLICE_DLP:
    678694    case NAL_UNIT_CODED_SLICE_RASL_N:
    679695    case NAL_UNIT_CODED_SLICE_TFD:
    680       return xDecodeSlice(nalu, iSkipFrame, iPOCLastDisplay);
     696      return xDecodeSlice(nalu, iSkipFrame, iPOCLastDisplay, bPicComplete);
    681697      break;
    682698    default:
    683699      assert (1);
     
    757773  return false;
    758774}
    759775
     776/**
     777 * Calculate and print hash for pic, compare to picture_digest SEI if
     778 * present in seis.  seis may be NULL.  Hash is printed to stdout, in
     779 * a manner suitable for the status line. Theformat is:
     780 *  [Hash_type:xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx,(yyy)]
     781 * Where, x..x is the hash
     782 *        yyy has the following meanings:
     783 *            OK          - calculated hash matches the SEI message
     784 *            ***ERROR*** - calculated hash does not match the SEI message
     785 *            unk         - no SEI message was available for comparison
     786 */
     787static void calcAndPrintHashStatus(TComPicYuv& pic, const SEIDecodedPictureHash* pictureHashSEI)
     788{
     789  /* calculate MD5sum for entire reconstructed picture */
     790  UChar recon_digest[3][16];
     791  Int numChar=0;
     792  const Char* hashType = "\0";
     793
     794  if (pictureHashSEI)
     795  {
     796    switch (pictureHashSEI->method)
     797    {
     798    case SEIDecodedPictureHash::MD5:
     799      {
     800        hashType = "MD5";
     801        calcMD5(pic, recon_digest);
     802        numChar = 16;
     803        break;
     804      }
     805    case SEIDecodedPictureHash::CRC:
     806      {
     807        hashType = "CRC";
     808        calcCRC(pic, recon_digest);
     809        numChar = 2;
     810        break;
     811      }
     812    case SEIDecodedPictureHash::CHECKSUM:
     813      {
     814        hashType = "Checksum";
     815        calcChecksum(pic, recon_digest);
     816        numChar = 4;
     817        break;
     818      }
     819    default:
     820      {
     821        assert (!"unknown hash type");
     822      }
     823    }
     824  }
     825
     826  /* compare digest against received version */
     827  const Char* ok = "(unk)";
     828  Bool mismatch = false;
     829
     830  if (pictureHashSEI)
     831  {
     832    ok = "(OK)";
     833    for(Int yuvIdx = 0; yuvIdx < 3; yuvIdx++)
     834    {
     835      for (UInt i = 0; i < numChar; i++)
     836      {
     837        if (recon_digest[yuvIdx][i] != pictureHashSEI->digest[yuvIdx][i])
     838        {
     839          ok = "(***ERROR***)";
     840          mismatch = true;
     841        }
     842      }
     843    }
     844  }
     845
     846  printf("[%s:%s,%s] ", hashType, digestToString(recon_digest, numChar), ok);
     847
     848  if (mismatch)
     849  {
     850    g_md5_mismatch = true;
     851    printf("[rx%s:%s] ", hashType, digestToString(pictureHashSEI->digest, numChar));
     852  }
     853}
     854
    760855//! \}
  • Lib/TLibDecoder/TDecTop.h

     
    9797  Int                     m_prevPOC;
    9898  Bool                    m_bFirstSliceInPicture;
    9999  Bool                    m_bFirstSliceInSequence;
     100  Int                     m_decodedPictureHashSEIEnabled;  ///< Checksum(3)/CRC(2)/MD5(1)/disable(0) acting on decoded picture hash SEI message
    100101
    101102public:
    102103  TDecTop();
     
    105106  Void  create  ();
    106107  Void  destroy ();
    107108
    108   void setDecodedPictureHashSEIEnabled(Int enabled) { m_cGopDecoder.setDecodedPictureHashSEIEnabled(enabled); }
     109  void setDecodedPictureHashSEIEnabled(Int enabled) { m_decodedPictureHashSEIEnabled = enabled; }
    109110
    110111  Void  init();
    111   Bool  decode(InputNALUnit& nalu, Int& iSkipFrame, Int& iPOCLastDisplay);
     112  Bool  decode(InputNALUnit& nalu, Int& iSkipFrame, Int& iPOCLastDisplay, Bool &bPicComplete);
    112113 
    113114  Void  deletePicBuffer();
    114115
     
    119120  Void  xCreateLostPicture (Int iLostPOC);
    120121
    121122  Void      xActivateParameterSets();
    122   Bool      xDecodeSlice(InputNALUnit &nalu, Int &iSkipFrame, Int iPOCLastDisplay);
     123  Bool      xDecodeSlice(InputNALUnit &nalu, Int &iSkipFrame, Int iPOCLastDisplay, Bool &bPicComplete);
    123124  Void      xDecodeVPS();
    124125  Void      xDecodeSPS();
    125126  Void      xDecodePPS();