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