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-2011, 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 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 | |
---|
35 | |
---|
36 | /** \file TDecGop.cpp |
---|
37 | \brief GOP decoder class |
---|
38 | */ |
---|
39 | |
---|
40 | extern bool g_md5_mismatch; ///< top level flag to signal when there is a decode problem |
---|
41 | |
---|
42 | #include "TDecGop.h" |
---|
43 | #include "TDecCAVLC.h" |
---|
44 | #include "TDecSbac.h" |
---|
45 | #include "TDecBinCoder.h" |
---|
46 | #include "TDecBinCoderCABAC.h" |
---|
47 | #include "../libmd5/MD5.h" |
---|
48 | #include "../TLibCommon/SEI.h" |
---|
49 | |
---|
50 | #include <time.h> |
---|
51 | |
---|
52 | static void calcAndPrintMD5Status(TComPicYuv& pic, const SEImessages* seis); |
---|
53 | |
---|
54 | // ==================================================================================================================== |
---|
55 | // Constructor / destructor / initialization / destroy |
---|
56 | // ==================================================================================================================== |
---|
57 | |
---|
58 | TDecGop::TDecGop() |
---|
59 | { |
---|
60 | m_iGopSize = 0; |
---|
61 | m_dDecTime = 0; |
---|
62 | } |
---|
63 | |
---|
64 | TDecGop::~TDecGop() |
---|
65 | { |
---|
66 | |
---|
67 | } |
---|
68 | |
---|
69 | Void TDecGop::create() |
---|
70 | { |
---|
71 | |
---|
72 | } |
---|
73 | |
---|
74 | |
---|
75 | Void TDecGop::destroy() |
---|
76 | { |
---|
77 | |
---|
78 | } |
---|
79 | |
---|
80 | Void TDecGop::init( TDecEntropy* pcEntropyDecoder, |
---|
81 | TDecSbac* pcSbacDecoder, |
---|
82 | TDecBinCABAC* pcBinCABAC, |
---|
83 | TDecCavlc* pcCavlcDecoder, |
---|
84 | TDecSlice* pcSliceDecoder, |
---|
85 | TComLoopFilter* pcLoopFilter, |
---|
86 | TComAdaptiveLoopFilter* pcAdaptiveLoopFilter, |
---|
87 | #if MTK_SAO |
---|
88 | TComSampleAdaptiveOffset* pcSAO |
---|
89 | #endif |
---|
90 | #if DEPTH_MAP_GENERATION |
---|
91 | ,TComDepthMapGenerator* pcDepthMapGenerator |
---|
92 | #endif |
---|
93 | #if HHI_INTER_VIEW_RESIDUAL_PRED |
---|
94 | ,TComResidualGenerator* pcResidualGenerator |
---|
95 | #endif |
---|
96 | ) |
---|
97 | { |
---|
98 | m_pcEntropyDecoder = pcEntropyDecoder; |
---|
99 | m_pcSbacDecoder = pcSbacDecoder; |
---|
100 | m_pcBinCABAC = pcBinCABAC; |
---|
101 | m_pcCavlcDecoder = pcCavlcDecoder; |
---|
102 | m_pcSliceDecoder = pcSliceDecoder; |
---|
103 | m_pcLoopFilter = pcLoopFilter; |
---|
104 | m_pcAdaptiveLoopFilter = pcAdaptiveLoopFilter; |
---|
105 | #if MTK_SAO |
---|
106 | m_pcSAO = pcSAO; |
---|
107 | #endif |
---|
108 | #if DEPTH_MAP_GENERATION |
---|
109 | m_pcDepthMapGenerator = pcDepthMapGenerator; |
---|
110 | #endif |
---|
111 | #if HHI_INTER_VIEW_RESIDUAL_PRED |
---|
112 | m_pcResidualGenerator = pcResidualGenerator; |
---|
113 | #endif |
---|
114 | } |
---|
115 | |
---|
116 | // ==================================================================================================================== |
---|
117 | // Public member functions |
---|
118 | // ==================================================================================================================== |
---|
119 | |
---|
120 | Void TDecGop::decompressGop (Bool bEos, TComBitstream* pcBitstream, TComPic*& rpcPic, Bool bExecuteDeblockAndAlf) |
---|
121 | { |
---|
122 | TComSlice* pcSlice = rpcPic->getSlice(rpcPic->getCurrSliceIdx()); |
---|
123 | |
---|
124 | //-- For time output for each slice |
---|
125 | long iBeforeTime = clock(); |
---|
126 | |
---|
127 | UInt uiStartCUAddr = pcSlice->getEntropySliceCurStartCUAddr(); |
---|
128 | #if MTK_NONCROSS_INLOOP_FILTER |
---|
129 | static Bool bFirst = true; |
---|
130 | static UInt uiILSliceCount; |
---|
131 | static UInt* puiILSliceStartLCU; |
---|
132 | if (!bExecuteDeblockAndAlf) |
---|
133 | { |
---|
134 | if(bFirst) |
---|
135 | { |
---|
136 | uiILSliceCount = 0; |
---|
137 | if(!pcSlice->getSPS()->getLFCrossSliceBoundaryFlag()) |
---|
138 | { |
---|
139 | puiILSliceStartLCU = new UInt[rpcPic->getNumCUsInFrame() +1]; |
---|
140 | } |
---|
141 | bFirst = false; |
---|
142 | } |
---|
143 | |
---|
144 | if(!pcSlice->getSPS()->getLFCrossSliceBoundaryFlag()) |
---|
145 | { |
---|
146 | UInt uiSliceStartCuAddr = pcSlice->getSliceCurStartCUAddr(); |
---|
147 | if(uiSliceStartCuAddr == uiStartCUAddr) |
---|
148 | { |
---|
149 | puiILSliceStartLCU[uiILSliceCount] = uiSliceStartCuAddr; |
---|
150 | uiILSliceCount++; |
---|
151 | } |
---|
152 | } |
---|
153 | #endif //MTK_NONCROSS_INLOOP_FILTER |
---|
154 | |
---|
155 | UInt iSymbolMode = pcSlice->getSymbolMode(); |
---|
156 | if (iSymbolMode) |
---|
157 | { |
---|
158 | m_pcSbacDecoder->init( (TDecBinIf*)m_pcBinCABAC ); |
---|
159 | m_pcEntropyDecoder->setEntropyDecoder (m_pcSbacDecoder); |
---|
160 | } |
---|
161 | else |
---|
162 | { |
---|
163 | m_pcEntropyDecoder->setEntropyDecoder (m_pcCavlcDecoder); |
---|
164 | } |
---|
165 | |
---|
166 | m_pcEntropyDecoder->setBitstream (pcBitstream); |
---|
167 | m_pcEntropyDecoder->resetEntropy (pcSlice); |
---|
168 | |
---|
169 | if (uiStartCUAddr==0) // decode ALF params only from first slice header |
---|
170 | { |
---|
171 | #if MTK_SAO |
---|
172 | if( rpcPic->getSlice(0)->getSPS()->getUseSAO() ) |
---|
173 | { |
---|
174 | m_pcSAO->InitSao(&m_cSaoParam); |
---|
175 | m_pcEntropyDecoder->decodeSaoParam(&m_cSaoParam); |
---|
176 | } |
---|
177 | #endif |
---|
178 | |
---|
179 | if ( rpcPic->getSlice(0)->getSPS()->getUseALF() ) |
---|
180 | { |
---|
181 | #if TSB_ALF_HEADER |
---|
182 | m_pcAdaptiveLoopFilter->setNumCUsInFrame(rpcPic); |
---|
183 | #endif |
---|
184 | m_pcAdaptiveLoopFilter->allocALFParam(&m_cAlfParam); |
---|
185 | m_pcEntropyDecoder->decodeAlfParam( &m_cAlfParam ); |
---|
186 | } |
---|
187 | } |
---|
188 | |
---|
189 | #if DEPTH_MAP_GENERATION |
---|
190 | // init view component and predict virtual depth map |
---|
191 | if( uiStartCUAddr == 0 ) |
---|
192 | { |
---|
193 | m_pcDepthMapGenerator->initViewComponent( rpcPic ); |
---|
194 | m_pcDepthMapGenerator->predictDepthMap ( rpcPic ); |
---|
195 | #if HHI_INTER_VIEW_RESIDUAL_PRED |
---|
196 | m_pcResidualGenerator->initViewComponent( rpcPic ); |
---|
197 | #endif |
---|
198 | } |
---|
199 | #endif |
---|
200 | |
---|
201 | // decode slice |
---|
202 | m_pcSliceDecoder->decompressSlice(pcBitstream, rpcPic); |
---|
203 | |
---|
204 | m_dDecTime += (double)(clock()-iBeforeTime) / CLOCKS_PER_SEC; |
---|
205 | } |
---|
206 | else |
---|
207 | { |
---|
208 | #if HHI_INTER_VIEW_RESIDUAL_PRED |
---|
209 | // set residual picture |
---|
210 | m_pcResidualGenerator->setRecResidualPic( rpcPic ); |
---|
211 | #endif |
---|
212 | #if DEPTH_MAP_GENERATION |
---|
213 | // update virtual depth map |
---|
214 | m_pcDepthMapGenerator->updateDepthMap( rpcPic ); |
---|
215 | #endif |
---|
216 | |
---|
217 | // deblocking filter |
---|
218 | m_pcLoopFilter->setCfg(pcSlice->getLoopFilterDisable(), 0, 0); |
---|
219 | m_pcLoopFilter->loopFilterPic( rpcPic ); |
---|
220 | #if MTK_SAO |
---|
221 | { |
---|
222 | if( rpcPic->getSlice(0)->getSPS()->getUseSAO()) |
---|
223 | { |
---|
224 | m_pcSAO->SAOProcess(rpcPic, &m_cSaoParam); |
---|
225 | } |
---|
226 | } |
---|
227 | #endif |
---|
228 | // adaptive loop filter |
---|
229 | if( pcSlice->getSPS()->getUseALF() ) |
---|
230 | { |
---|
231 | #if MTK_NONCROSS_INLOOP_FILTER |
---|
232 | if(pcSlice->getSPS()->getLFCrossSliceBoundaryFlag()) |
---|
233 | { |
---|
234 | m_pcAdaptiveLoopFilter->setUseNonCrossAlf(false); |
---|
235 | } |
---|
236 | else |
---|
237 | { |
---|
238 | puiILSliceStartLCU[uiILSliceCount] = rpcPic->getNumCUsInFrame(); |
---|
239 | m_pcAdaptiveLoopFilter->setUseNonCrossAlf( (uiILSliceCount > 1) ); |
---|
240 | if(m_pcAdaptiveLoopFilter->getUseNonCrossAlf()) |
---|
241 | { |
---|
242 | m_pcAdaptiveLoopFilter->setNumSlicesInPic( uiILSliceCount ); |
---|
243 | m_pcAdaptiveLoopFilter->createSlice(); |
---|
244 | for(UInt i=0; i< uiILSliceCount ; i++) |
---|
245 | { |
---|
246 | (*m_pcAdaptiveLoopFilter)[i].create(rpcPic, i, puiILSliceStartLCU[i], puiILSliceStartLCU[i+1]-1); |
---|
247 | } |
---|
248 | } |
---|
249 | } |
---|
250 | #endif |
---|
251 | m_pcAdaptiveLoopFilter->ALFProcess(rpcPic, &m_cAlfParam); |
---|
252 | #if MTK_NONCROSS_INLOOP_FILTER |
---|
253 | if(m_pcAdaptiveLoopFilter->getUseNonCrossAlf()) |
---|
254 | { |
---|
255 | m_pcAdaptiveLoopFilter->destroySlice(); |
---|
256 | } |
---|
257 | #endif |
---|
258 | m_pcAdaptiveLoopFilter->freeALFParam(&m_cAlfParam); |
---|
259 | } |
---|
260 | |
---|
261 | /*#if AMVP_BUFFERCOMPRESS |
---|
262 | rpcPic->compressMotion(); // move to end of access unit |
---|
263 | #endif */ |
---|
264 | |
---|
265 | //-- For time output for each slice |
---|
266 | if(rpcPic->getViewIdx()!=-1) |
---|
267 | { |
---|
268 | if( !pcSlice->getSPS()->isDepth()) |
---|
269 | { |
---|
270 | printf("\nView \t\t%4d\t POC %4d ( %c-SLICE, QP%3d ) ", |
---|
271 | rpcPic->getViewIdx(), |
---|
272 | pcSlice->getPOC(), |
---|
273 | pcSlice->isIntra() ? 'I' : pcSlice->isInterP() ? 'P' : 'B', |
---|
274 | pcSlice->getSliceQp() ); |
---|
275 | } |
---|
276 | else |
---|
277 | { |
---|
278 | printf("\nDepth View \t%4d\t POC %4d ( %c-SLICE, QP%3d ) ", |
---|
279 | rpcPic->getViewIdx(), |
---|
280 | pcSlice->getPOC(), |
---|
281 | pcSlice->isIntra() ? 'I' : pcSlice->isInterP() ? 'P' : 'B', |
---|
282 | pcSlice->getSliceQp() ); |
---|
283 | } |
---|
284 | } |
---|
285 | else |
---|
286 | printf("\nPOC %4d ( %c-SLICE, QP%3d ) ", |
---|
287 | pcSlice->getPOC(), |
---|
288 | pcSlice->isIntra() ? 'I' : pcSlice->isInterP() ? 'P' : 'B', |
---|
289 | pcSlice->getSliceQp() ); |
---|
290 | |
---|
291 | m_dDecTime += (double)(clock()-iBeforeTime) / CLOCKS_PER_SEC; |
---|
292 | printf ("[DT %6.3f] ", m_dDecTime ); |
---|
293 | m_dDecTime = 0; |
---|
294 | |
---|
295 | for (Int iRefList = 0; iRefList < 2; iRefList++) |
---|
296 | { |
---|
297 | printf ("[L%d ", iRefList); |
---|
298 | for (Int iRefIndex = 0; iRefIndex < pcSlice->getNumRefIdx(RefPicList(iRefList)); iRefIndex++) |
---|
299 | { |
---|
300 | if( pcSlice->getViewIdx() != pcSlice->getRefViewIdx( RefPicList(iRefList), iRefIndex ) ) |
---|
301 | { |
---|
302 | printf( "V%d", pcSlice->getRefViewIdx( RefPicList(iRefList), iRefIndex ) ); |
---|
303 | if( pcSlice->getPOC() != pcSlice->getRefPOC( RefPicList(iRefList), iRefIndex ) ) |
---|
304 | printf( "(%d)", pcSlice->getRefPOC( RefPicList(iRefList), iRefIndex ) ); |
---|
305 | printf( " " ); |
---|
306 | } |
---|
307 | else |
---|
308 | printf ("%d ", pcSlice->getRefPOC(RefPicList(iRefList), iRefIndex)); |
---|
309 | } |
---|
310 | printf ("] "); |
---|
311 | } |
---|
312 | #if DCM_COMB_LIST |
---|
313 | if(pcSlice->getNumRefIdx(REF_PIC_LIST_C)>0 && !pcSlice->getNoBackPredFlag()) |
---|
314 | { |
---|
315 | printf ("[LC "); |
---|
316 | for (Int iRefIndex = 0; iRefIndex < pcSlice->getNumRefIdx(REF_PIC_LIST_C); iRefIndex++) |
---|
317 | { |
---|
318 | if( pcSlice->getViewIdx() != pcSlice->getRefViewIdx( (RefPicList)pcSlice->getListIdFromIdxOfLC(iRefIndex), pcSlice->getRefIdxFromIdxOfLC(iRefIndex) ) ) |
---|
319 | { |
---|
320 | printf( "V%d", pcSlice->getRefViewIdx( (RefPicList)pcSlice->getListIdFromIdxOfLC(iRefIndex), pcSlice->getRefIdxFromIdxOfLC(iRefIndex) ) ); |
---|
321 | if( pcSlice->getPOC() != pcSlice->getRefPOC( (RefPicList)pcSlice->getListIdFromIdxOfLC(iRefIndex), pcSlice->getRefIdxFromIdxOfLC(iRefIndex) ) ) |
---|
322 | printf( "(%d)", pcSlice->getRefPOC( (RefPicList)pcSlice->getListIdFromIdxOfLC(iRefIndex), pcSlice->getRefIdxFromIdxOfLC(iRefIndex) ) ); |
---|
323 | printf( " " ); |
---|
324 | } |
---|
325 | else |
---|
326 | printf ("%d ", pcSlice->getRefPOC((RefPicList)pcSlice->getListIdFromIdxOfLC(iRefIndex), pcSlice->getRefIdxFromIdxOfLC(iRefIndex))); |
---|
327 | } |
---|
328 | printf ("] "); |
---|
329 | } |
---|
330 | #endif |
---|
331 | #if FIXED_ROUNDING_FRAME_MEMORY |
---|
332 | rpcPic->getPicYuvRec()->xFixedRoundingPic(); |
---|
333 | #endif |
---|
334 | |
---|
335 | if (m_pictureDigestEnabled) { |
---|
336 | calcAndPrintMD5Status(*rpcPic->getPicYuvRec(), rpcPic->getSEIs()); |
---|
337 | } |
---|
338 | |
---|
339 | rpcPic->setReconMark(true); |
---|
340 | #if MTK_NONCROSS_INLOOP_FILTER |
---|
341 | uiILSliceCount = 0; |
---|
342 | #endif |
---|
343 | } |
---|
344 | } |
---|
345 | |
---|
346 | /** |
---|
347 | * Calculate and print MD5 for @pic, compare to picture_digest SEI if |
---|
348 | * present in @seis. @seis may be NULL. MD5 is printed to stdout, in |
---|
349 | * a manner suitable for the status line. Theformat is: |
---|
350 | * [MD5:xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx,(yyy)] |
---|
351 | * Where, x..x is the md5 |
---|
352 | * yyy has the following meanings: |
---|
353 | * OK - calculated MD5 matches the SEI message |
---|
354 | * ***ERROR*** - calculated MD5 does not match the SEI message |
---|
355 | * unk - no SEI message was available for comparison |
---|
356 | */ |
---|
357 | static void calcAndPrintMD5Status(TComPicYuv& pic, const SEImessages* seis) |
---|
358 | { |
---|
359 | /* calculate MD5sum for entire reconstructed picture */ |
---|
360 | unsigned char recon_digest[16]; |
---|
361 | calcMD5(pic, recon_digest); |
---|
362 | |
---|
363 | /* compare digest against received version */ |
---|
364 | const char* md5_ok = "(unk)"; |
---|
365 | bool md5_mismatch = false; |
---|
366 | |
---|
367 | if (seis && seis->picture_digest) |
---|
368 | { |
---|
369 | md5_ok = "(OK)"; |
---|
370 | for (unsigned i = 0; i < 16; i++) |
---|
371 | { |
---|
372 | if (recon_digest[i] != seis->picture_digest->digest[i]) |
---|
373 | { |
---|
374 | md5_ok = "(***ERROR***)"; |
---|
375 | md5_mismatch = true; |
---|
376 | } |
---|
377 | } |
---|
378 | } |
---|
379 | |
---|
380 | printf("[MD5:%s,%s] ", digestToString(recon_digest), md5_ok); |
---|
381 | if (md5_mismatch) |
---|
382 | { |
---|
383 | g_md5_mismatch = true; |
---|
384 | printf("[rxMD5:%s] ", digestToString(seis->picture_digest->digest)); |
---|
385 | } |
---|
386 | } |
---|