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