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-2017, 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 TDecTop.h |
---|
35 | \brief decoder class (header) |
---|
36 | */ |
---|
37 | |
---|
38 | #ifndef __TDECTOP__ |
---|
39 | #define __TDECTOP__ |
---|
40 | |
---|
41 | #include "TLibCommon/CommonDef.h" |
---|
42 | #include "TLibCommon/TComList.h" |
---|
43 | #include "TLibCommon/TComPicYuv.h" |
---|
44 | #include "TLibCommon/TComPic.h" |
---|
45 | #include "TLibCommon/TComTrQuant.h" |
---|
46 | #include "TLibCommon/TComPrediction.h" |
---|
47 | #include "TLibCommon/SEI.h" |
---|
48 | |
---|
49 | #include "TDecGop.h" |
---|
50 | #include "TDecEntropy.h" |
---|
51 | #include "TDecSbac.h" |
---|
52 | #include "TDecCAVLC.h" |
---|
53 | #include "SEIread.h" |
---|
54 | #include "TDecConformance.h" |
---|
55 | |
---|
56 | class InputNALUnit; |
---|
57 | |
---|
58 | //! \ingroup TLibDecoder |
---|
59 | //! \{ |
---|
60 | |
---|
61 | // ==================================================================================================================== |
---|
62 | // Class definition |
---|
63 | // ==================================================================================================================== |
---|
64 | |
---|
65 | #if NH_MV |
---|
66 | class TAppDecTop; |
---|
67 | #endif |
---|
68 | #if NH_3D |
---|
69 | class CamParsCollector |
---|
70 | { |
---|
71 | public: |
---|
72 | CamParsCollector (); |
---|
73 | ~CamParsCollector (); |
---|
74 | |
---|
75 | Void init ( const TComVPS* vps ); |
---|
76 | Void setCodeScaleOffsetFile( FILE* pCodedScaleOffsetFile ) { m_pCodedScaleOffsetFile = pCodedScaleOffsetFile; }; |
---|
77 | |
---|
78 | Void uninit (); |
---|
79 | Void setSlice ( const TComSlice* pcSlice ); |
---|
80 | |
---|
81 | Bool isInitialized() const { return m_bInitialized; } |
---|
82 | Int**** getBaseViewShiftLUTI() { return m_aiBaseViewShiftLUT; } |
---|
83 | |
---|
84 | private: |
---|
85 | Void xResetReceivedIdc( Bool overWriteFlag ); |
---|
86 | Void xOutput ( Int iPOC ); |
---|
87 | |
---|
88 | private: |
---|
89 | Bool m_bInitialized; |
---|
90 | FILE* m_pCodedScaleOffsetFile; |
---|
91 | |
---|
92 | Int** m_aaiCodedOffset; |
---|
93 | Int** m_aaiCodedScale; |
---|
94 | |
---|
95 | const TComVPS* m_vps; |
---|
96 | Int** m_receivedIdc; |
---|
97 | Int m_lastPoc; |
---|
98 | Int m_firstReceivedPoc; |
---|
99 | |
---|
100 | |
---|
101 | Bool m_bCamParsVaryOverTime; |
---|
102 | |
---|
103 | UInt m_uiBitDepthForLUT; |
---|
104 | UInt m_iLog2Precision; |
---|
105 | // UInt m_uiInputBitDepth; |
---|
106 | |
---|
107 | // look-up tables |
---|
108 | Double**** m_adBaseViewShiftLUT; ///< Disparity LUT |
---|
109 | Int**** m_aiBaseViewShiftLUT; ///< Disparity LUT |
---|
110 | Void xCreateLUTs( UInt uiNumberSourceViews, UInt uiNumberTargetViews, Double****& radLUT, Int****& raiLUT); |
---|
111 | Void xInitLUTs( UInt uiSourceView, UInt uiTargetView, Int iScale, Int iOffset, Double****& radLUT, Int****& raiLUT); |
---|
112 | template<class T> Void xDeleteArray ( T*& rpt, UInt uiSize1, UInt uiSize2, UInt uiSize3 ); |
---|
113 | template<class T> Void xDeleteArray ( T*& rpt, UInt uiSize1, UInt uiSize2 ); |
---|
114 | template<class T> Void xDeleteArray ( T*& rpt, UInt uiSize ); |
---|
115 | |
---|
116 | }; |
---|
117 | |
---|
118 | template <class T> |
---|
119 | Void CamParsCollector::xDeleteArray( T*& rpt, UInt uiSize1, UInt uiSize2, UInt uiSize3 ) |
---|
120 | { |
---|
121 | if( rpt ) |
---|
122 | { |
---|
123 | for( UInt uiK = 0; uiK < uiSize1; uiK++ ) |
---|
124 | { |
---|
125 | for( UInt uiL = 0; uiL < uiSize2; uiL++ ) |
---|
126 | { |
---|
127 | for( UInt uiM = 0; uiM < uiSize3; uiM++ ) |
---|
128 | { |
---|
129 | delete[] rpt[ uiK ][ uiL ][ uiM ]; |
---|
130 | } |
---|
131 | delete[] rpt[ uiK ][ uiL ]; |
---|
132 | } |
---|
133 | delete[] rpt[ uiK ]; |
---|
134 | } |
---|
135 | delete[] rpt; |
---|
136 | } |
---|
137 | rpt = NULL; |
---|
138 | }; |
---|
139 | |
---|
140 | |
---|
141 | template <class T> |
---|
142 | Void CamParsCollector::xDeleteArray( T*& rpt, UInt uiSize1, UInt uiSize2 ) |
---|
143 | { |
---|
144 | if( rpt ) |
---|
145 | { |
---|
146 | for( UInt uiK = 0; uiK < uiSize1; uiK++ ) |
---|
147 | { |
---|
148 | for( UInt uiL = 0; uiL < uiSize2; uiL++ ) |
---|
149 | { |
---|
150 | delete[] rpt[ uiK ][ uiL ]; |
---|
151 | } |
---|
152 | delete[] rpt[ uiK ]; |
---|
153 | } |
---|
154 | delete[] rpt; |
---|
155 | } |
---|
156 | rpt = NULL; |
---|
157 | }; |
---|
158 | |
---|
159 | |
---|
160 | template <class T> |
---|
161 | Void CamParsCollector::xDeleteArray( T*& rpt, UInt uiSize ) |
---|
162 | { |
---|
163 | if( rpt ) |
---|
164 | { |
---|
165 | for( UInt uiK = 0; uiK < uiSize; uiK++ ) |
---|
166 | { |
---|
167 | delete[] rpt[ uiK ]; |
---|
168 | } |
---|
169 | delete[] rpt; |
---|
170 | } |
---|
171 | rpt = NULL; |
---|
172 | }; |
---|
173 | |
---|
174 | #endif //NH_3D |
---|
175 | /// decoder class |
---|
176 | class TDecTop |
---|
177 | { |
---|
178 | private: |
---|
179 | Int m_iMaxRefPicNum; |
---|
180 | |
---|
181 | NalUnitType m_associatedIRAPType; ///< NAL unit type of the associated IRAP picture |
---|
182 | #if !NH_MV |
---|
183 | Int m_pocCRA; ///< POC number of the latest CRA picture |
---|
184 | Int m_pocRandomAccess; ///< POC number of the random access point (the first IDR or CRA picture) |
---|
185 | |
---|
186 | TComList<TComPic*> m_cListPic; // Dynamic buffer |
---|
187 | ParameterSetManager m_parameterSetManager; // storage for parameter sets |
---|
188 | #endif |
---|
189 | |
---|
190 | TComSlice* m_apcSlicePilot; |
---|
191 | |
---|
192 | SEIMessages m_SEIs; ///< List of SEI messages that have been received before the first slice and between slices, excluding prefix SEIs... |
---|
193 | |
---|
194 | // functional classes |
---|
195 | TComPrediction m_cPrediction; |
---|
196 | TComTrQuant m_cTrQuant; |
---|
197 | TDecGop m_cGopDecoder; |
---|
198 | TDecSlice m_cSliceDecoder; |
---|
199 | TDecCu m_cCuDecoder; |
---|
200 | TDecEntropy m_cEntropyDecoder; |
---|
201 | TDecCavlc m_cCavlcDecoder; |
---|
202 | TDecSbac m_cSbacDecoder; |
---|
203 | TDecBinCABAC m_cBinCABAC; |
---|
204 | SEIReader m_seiReader; |
---|
205 | TComLoopFilter m_cLoopFilter; |
---|
206 | TComSampleAdaptiveOffset m_cSAO; |
---|
207 | TDecConformanceCheck m_conformanceCheck; |
---|
208 | |
---|
209 | Bool isSkipPictureForBLA(Int& iPOCLastDisplay); |
---|
210 | #if !NH_MV |
---|
211 | Bool isRandomAccessSkipPicture(Int& iSkipFrame, Int& iPOCLastDisplay); |
---|
212 | #endif |
---|
213 | |
---|
214 | TComPic* m_pcPic; |
---|
215 | UInt m_uiSliceIdx; |
---|
216 | #if !NH_MV |
---|
217 | Int m_prevPOC; |
---|
218 | Int m_prevTid0POC; |
---|
219 | Bool m_bFirstSliceInPicture; |
---|
220 | Bool m_bFirstSliceInSequence; |
---|
221 | Bool m_prevSliceSkipped; |
---|
222 | Int m_skippedPOC; |
---|
223 | Bool m_bFirstSliceInBitstream; |
---|
224 | Int m_lastPOCNoOutputPriorPics; |
---|
225 | Bool m_isNoOutputPriorPics; |
---|
226 | Bool m_craNoRaslOutputFlag; //value of variable NoRaslOutputFlag of the last CRA pic |
---|
227 | #endif |
---|
228 | |
---|
229 | #if O0043_BEST_EFFORT_DECODING |
---|
230 | UInt m_forceDecodeBitDepth; |
---|
231 | #endif |
---|
232 | |
---|
233 | |
---|
234 | std::ostream *m_pDecodedSEIOutputStream; |
---|
235 | |
---|
236 | #if !NH_MV |
---|
237 | Bool m_warningMessageSkipPicture; |
---|
238 | #endif |
---|
239 | |
---|
240 | #if MCTS_ENC_CHECK |
---|
241 | Bool m_tmctsCheckEnabled; |
---|
242 | |
---|
243 | #endif |
---|
244 | |
---|
245 | #if NH_MV |
---|
246 | // Class interface |
---|
247 | static ParameterSetManager m_parameterSetManager; // storage for parameter sets |
---|
248 | TComPicLists* m_dpb; |
---|
249 | #if NH_3D |
---|
250 | CamParsCollector* m_pcCamParsCollector; |
---|
251 | #endif |
---|
252 | |
---|
253 | // Layer identification |
---|
254 | Int m_layerId; |
---|
255 | Int m_viewId; |
---|
256 | #if NH_3D || NH_3D_VSO |
---|
257 | Int m_viewIndex; |
---|
258 | Bool m_isDepth; |
---|
259 | #endif |
---|
260 | |
---|
261 | // Layer set |
---|
262 | Int m_targetOlsIdx; |
---|
263 | Int m_smallestLayerId; |
---|
264 | Bool m_isInOwnTargetDecLayerIdList; |
---|
265 | |
---|
266 | // Decoding processes |
---|
267 | DecodingProcess m_decodingProcess; |
---|
268 | DecodingProcess m_decProcPocAndRps; |
---|
269 | |
---|
270 | // Decoding state |
---|
271 | Bool* m_firstPicInLayerDecodedFlag; |
---|
272 | |
---|
273 | Int m_prevPicOrderCnt; |
---|
274 | Int m_prevTid0PicPicOrderCntMsb; |
---|
275 | Int m_prevTid0PicSlicePicOrderCntLsb; |
---|
276 | |
---|
277 | Int* m_lastPresentPocResetIdc; |
---|
278 | Bool* m_pocDecrementedInDpbFlag; |
---|
279 | |
---|
280 | Int m_prevIrapPoc; |
---|
281 | Int64 m_prevIrapDecodingOrder; |
---|
282 | Int64 m_prevStsaDecOrder; |
---|
283 | Int m_prevStsaTemporalId; |
---|
284 | #endif |
---|
285 | |
---|
286 | std::list<InputNALUnit*> m_prefixSEINALUs; /// Buffered up prefix SEI NAL Units. |
---|
287 | public: |
---|
288 | TDecTop(); |
---|
289 | virtual ~TDecTop(); |
---|
290 | |
---|
291 | Void create (); |
---|
292 | Void destroy (); |
---|
293 | |
---|
294 | Void setDecodedPictureHashSEIEnabled(Int enabled) { m_cGopDecoder.setDecodedPictureHashSEIEnabled(enabled); } |
---|
295 | #if MCTS_ENC_CHECK |
---|
296 | Void setTMctsCheckEnabled(Bool enabled) { m_tmctsCheckEnabled = enabled; } |
---|
297 | #endif |
---|
298 | Void init(); |
---|
299 | #if !NH_MV |
---|
300 | Bool decode(InputNALUnit& nalu, Int& iSkipFrame, Int& iPOCLastDisplay); |
---|
301 | Void deletePicBuffer(); |
---|
302 | |
---|
303 | Void executeLoopFilters(Int& poc, TComList<TComPic*>*& rpcListPic); |
---|
304 | Void checkNoOutputPriorPics (TComList<TComPic*>* rpcListPic); |
---|
305 | |
---|
306 | Bool getNoOutputPriorPicsFlag () { return m_isNoOutputPriorPics; } |
---|
307 | Void setNoOutputPriorPicsFlag (Bool val) { m_isNoOutputPriorPics = val; } |
---|
308 | |
---|
309 | Void setFirstSliceInPicture (bool val) { m_bFirstSliceInPicture = val; } |
---|
310 | |
---|
311 | Bool getFirstSliceInSequence () { return m_bFirstSliceInSequence; } |
---|
312 | Void setFirstSliceInSequence (bool val) { m_bFirstSliceInSequence = val; } |
---|
313 | #endif |
---|
314 | |
---|
315 | #if O0043_BEST_EFFORT_DECODING |
---|
316 | Void setForceDecodeBitDepth(UInt bitDepth) { m_forceDecodeBitDepth = bitDepth; } |
---|
317 | #endif |
---|
318 | |
---|
319 | Void setDecodedSEIMessageOutputStream(std::ostream *pOpStream) { m_pDecodedSEIOutputStream = pOpStream; } |
---|
320 | UInt getNumberOfChecksumErrorsDetected() const { return m_cGopDecoder.getNumberOfChecksumErrorsDetected(); } |
---|
321 | |
---|
322 | #if NH_MV |
---|
323 | |
---|
324 | ///////////////////////// |
---|
325 | // For access from TAppDecTop |
---|
326 | ///////////////////////// |
---|
327 | |
---|
328 | // Non VCL decoding |
---|
329 | Bool decodeNonVclNalu ( InputNALUnit& nalu ); |
---|
330 | |
---|
331 | // Start picture decoding |
---|
332 | Int preDecodePoc ( Bool firstPicInLayerDecodedFlag, Bool isFstPicOfAllLayOfPocResetPer, Bool isPocResettingPicture ); |
---|
333 | Void inferPocResetPeriodId ( ); |
---|
334 | Void decodeSliceHeader ( InputNALUnit &nalu ); |
---|
335 | |
---|
336 | // Picture decoding |
---|
337 | Void activatePSsAndInitPicOrSlice( TComPic* newPic ); |
---|
338 | Void decodePocAndRps ( ); |
---|
339 | Void genUnavailableRefPics ( ); |
---|
340 | Void decodeSliceSegment ( InputNALUnit &nalu ); |
---|
341 | |
---|
342 | // End Picture decoding |
---|
343 | Void executeLoopFilters ( ); |
---|
344 | Void finalizePic( ); |
---|
345 | |
---|
346 | ////////////////////////// |
---|
347 | // For access from slice |
---|
348 | ///////////////////////// |
---|
349 | Void initFromActiveVps ( const TComVPS* vps ); |
---|
350 | |
---|
351 | ////////////////////////// |
---|
352 | // General access |
---|
353 | ///////////////////////// |
---|
354 | |
---|
355 | // Picture identification |
---|
356 | Void setLayerId ( Int layer ) { m_layerId = layer; } |
---|
357 | Int getLayerId ( ) { return m_layerId; } |
---|
358 | Void setViewId ( Int viewId ) { m_viewId = viewId; } |
---|
359 | Int getViewId ( ) { return m_viewId; } |
---|
360 | #if NH_3D |
---|
361 | Void setViewIndex ( Int viewIndex ) { m_viewIndex = viewIndex; } |
---|
362 | Int getViewIndex ( ) { return m_viewIndex; } |
---|
363 | Void setIsDepth ( Bool isDepth ) { m_isDepth = isDepth; } |
---|
364 | Bool getIsDepth ( ) { return m_isDepth; } |
---|
365 | #endif |
---|
366 | |
---|
367 | // Classes |
---|
368 | Void setDpb ( TComPicLists* picLists) { m_dpb = picLists; } |
---|
369 | #if NH_3D |
---|
370 | Void setCamParsCollector ( CamParsCollector* pcCamParsCollector ) { m_pcCamParsCollector = pcCamParsCollector; } |
---|
371 | #endif |
---|
372 | |
---|
373 | // Slice pilot access |
---|
374 | TComSlice* getSlicePilot ( ) { return m_apcSlicePilot; } |
---|
375 | |
---|
376 | // Decoding state |
---|
377 | Bool getFirstSliceSegementInPicFlag( ); |
---|
378 | Void setFirstPicInLayerDecodedFlag(Bool* val ) { m_firstPicInLayerDecodedFlag = val; } |
---|
379 | Void setPocDecrementedInDPBFlag (Bool* val ) { m_pocDecrementedInDpbFlag = val; } |
---|
380 | Void setLastPresentPocResetIdc (Int* val ) { m_lastPresentPocResetIdc = val; } |
---|
381 | |
---|
382 | // Layer sets |
---|
383 | Void setTargetOlsIdx ( Int targetOlsIdx ) { m_targetOlsIdx = targetOlsIdx; } |
---|
384 | Int getTargetOlsIdx ( ) { return m_targetOlsIdx; } |
---|
385 | Int getSmallestLayerId ( ) { return m_smallestLayerId; } |
---|
386 | Bool getIsInOwnTargetDecLayerIdList() { return m_isInOwnTargetDecLayerIdList; } |
---|
387 | |
---|
388 | // Decoding processes identification |
---|
389 | Bool decProcClause8( ) { return ( m_decodingProcess == CLAUSE_8 ); } |
---|
390 | Bool decProcAnnexF ( ) { return ( decProcAnnexG() || decProcAnnexH() || decProcAnnexI() ); } |
---|
391 | Bool decProcAnnexG ( ) { return ( m_decodingProcess == ANNEX_G || decProcAnnexI() ); } |
---|
392 | Bool decProcAnnexH ( ) { return ( m_decodingProcess == ANNEX_H ); } |
---|
393 | Bool decProcAnnexI ( ) { return ( m_decodingProcess == ANNEX_I ); } |
---|
394 | |
---|
395 | DecodingProcess getDecodingProcess ( ) const { return m_decodingProcess; } |
---|
396 | Void setDecProcPocAndRps( DecodingProcess decProc ) { m_decProcPocAndRps = decProc; } |
---|
397 | #endif |
---|
398 | |
---|
399 | protected: |
---|
400 | |
---|
401 | #if !NH_MV |
---|
402 | Void xGetNewPicBuffer (const TComSPS &sps, const TComPPS &pps, TComPic*& rpcPic, const UInt temporalLayer); |
---|
403 | Void xCreateLostPicture (Int iLostPOC); |
---|
404 | Void xActivateParameterSets(); |
---|
405 | Bool xDecodeSlice (InputNALUnit &nalu, Int &iSkipFrame, Int iPOCLastDisplay); |
---|
406 | #endif |
---|
407 | |
---|
408 | Void xDecodeVPS(const std::vector<UChar> &naluData); |
---|
409 | Void xDecodeSPS(const std::vector<UChar> &naluData); |
---|
410 | Void xDecodePPS(const std::vector<UChar> &naluData); |
---|
411 | #if !NH_MV |
---|
412 | Void xUpdatePreviousTid0POC( TComSlice *pSlice ) { if ((pSlice->getTLayer()==0) && (pSlice->isReferenceNalu() && (pSlice->getNalUnitType()!=NAL_UNIT_CODED_SLICE_RASL_R)&& (pSlice->getNalUnitType()!=NAL_UNIT_CODED_SLICE_RADL_R))) { m_prevTid0POC=pSlice->getPOC(); } } |
---|
413 | #endif |
---|
414 | |
---|
415 | Void xParsePrefixSEImessages(); |
---|
416 | #if MCTS_ENC_CHECK |
---|
417 | Void xAnalysePrefixSEImessages(); |
---|
418 | #endif |
---|
419 | Void xParsePrefixSEIsForUnknownVCLNal(); |
---|
420 | |
---|
421 | #if NH_MV |
---|
422 | // POC |
---|
423 | Void x831DecProcForPicOrderCount ( ); |
---|
424 | Void xF831DecProcForPicOrderCount ( ); |
---|
425 | Int xGetCurrMsb ( Int cl, Int pl, Int pm, Int ml ); |
---|
426 | |
---|
427 | //RPS |
---|
428 | Void x832DecProcForRefPicSet ( Bool annexFModifications ); |
---|
429 | Void xF832DecProcForRefPicSet ( ); |
---|
430 | Void xG813DecProcForInterLayerRefPicSet ( ); |
---|
431 | |
---|
432 | // Unavailable Pics |
---|
433 | Void x8331GenDecProcForGenUnavilRefPics ( ); |
---|
434 | TComPic* x8332GenOfOneUnavailPic ( Bool calledFromCl8331 ); |
---|
435 | Void xF817DecProcForGenUnavRefPicForPicsFrstInDecOrderInLay(); |
---|
436 | Void xF833DecProcForGenUnavRefPics ( ); |
---|
437 | Void xCheckUnavailableRefPics ( ); |
---|
438 | #endif |
---|
439 | |
---|
440 | };// END CLASS DEFINITION TDecTop |
---|
441 | |
---|
442 | |
---|
443 | //! \} |
---|
444 | #endif // __TDECTOP__ |
---|
445 | |
---|