1 /*!
2 * \copy
3 * Copyright (c) 2009-2013, Cisco Systems
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 *
10 * * Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 *
13 * * Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in
15 * the documentation and/or other materials provided with the
16 * distribution.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
21 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
22 * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
23 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
24 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
26 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
28 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
30 *
31 *
32 * \file decoder_context.h
33 *
34 * \brief mainly interface introduced in Wels decoder side
35 *
36 * \date 3/4/2009 Created
37 *
38 *************************************************************************************
39 */
40 #ifndef WELS_DECODER_FRAMEWORK_H__
41 #define WELS_DECODER_FRAMEWORK_H__
42 #include "typedefs.h"
43 #include "utils.h"
44 #include "wels_const.h"
45 #include "wels_common_basis.h"
46 #include "wels_common_defs.h"
47 #include "codec_app_def.h"
48 #include "parameter_sets.h"
49 #include "nalu.h"
50 #include "dec_frame.h"
51 #include "pic_queue.h"
52 #include "vlc_decoder.h"
53 #include "fmo.h"
54 #include "crt_util_safe_x.h"
55 #include "mb_cache.h"
56 #include "expand_pic.h"
57 #include "mc.h"
58 #include "memory_align.h"
59 #include "wels_decoder_thread.h"
60
61 namespace WelsDec {
62 #define MAX_PRED_MODE_ID_I16x16 3
63 #define MAX_PRED_MODE_ID_CHROMA 3
64 #define MAX_PRED_MODE_ID_I4x4 8
65 #define WELS_QP_MAX 51
66
67 #define LONG_TERM_REF
68 #define IMinInt32 -0x7FFFFFFF
69 typedef struct SWels_Cabac_Element {
70 uint8_t uiState;
71 uint8_t uiMPS;
72 } SWelsCabacCtx, *PWelsCabacCtx;
73
74 typedef struct {
75 uint64_t uiRange;
76 uint64_t uiOffset;
77 int32_t iBitsLeft;
78 uint8_t* pBuffStart;
79 uint8_t* pBuffCurr;
80 uint8_t* pBuffEnd;
81 } SWelsCabacDecEngine, *PWelsCabacDecEngine;
82
83 #define NEW_CTX_OFFSET_MB_TYPE_I 3
84 #define NEW_CTX_OFFSET_SKIP 11
85 #define NEW_CTX_OFFSET_SUBMB_TYPE 21
86 #define NEW_CTX_OFFSET_B_SUBMB_TYPE 36
87 #define NEW_CTX_OFFSET_MVD 40
88 #define NEW_CTX_OFFSET_REF_NO 54
89 #define NEW_CTX_OFFSET_DELTA_QP 60
90 #define NEW_CTX_OFFSET_IPR 68
91 #define NEW_CTX_OFFSET_CIPR 64
92 #define NEW_CTX_OFFSET_CBP 73
93 #define NEW_CTX_OFFSET_CBF 85
94 #define NEW_CTX_OFFSET_MAP 105
95 #define NEW_CTX_OFFSET_LAST 166
96 #define NEW_CTX_OFFSET_ONE 227
97 #define NEW_CTX_OFFSET_ABS 232
98 #define NEW_CTX_OFFSET_TS_8x8_FLAG 399
99 #define CTX_NUM_MVD 7
100 #define CTX_NUM_CBP 4
101 // Table 9-34 in Page 270
102 #define NEW_CTX_OFFSET_TRANSFORM_SIZE_8X8_FLAG 399
103 #define NEW_CTX_OFFSET_MAP_8x8 402
104 #define NEW_CTX_OFFSET_LAST_8x8 417
105 #define NEW_CTX_OFFSET_ONE_8x8 426
106 #define NEW_CTX_OFFSET_ABS_8x8 431 // Puzzle, where is the definition?
107
108 typedef struct TagDataBuffer {
109 uint8_t* pHead;
110 uint8_t* pEnd;
111
112 uint8_t* pStartPos;
113 uint8_t* pCurPos;
114 } SDataBuffer;
115
116 //limit size for SPS PPS total permitted size for parse_only
117 #define SPS_PPS_BS_SIZE 128
118 typedef struct TagSpsBsInfo {
119 uint8_t pSpsBsBuf [SPS_PPS_BS_SIZE];
120 int32_t iSpsId;
121 uint16_t uiSpsBsLen;
122 } SSpsBsInfo;
123
124 typedef struct TagPpsBsInfo {
125 uint8_t pPpsBsBuf [SPS_PPS_BS_SIZE];
126 int32_t iPpsId;
127 uint16_t uiPpsBsLen;
128 } SPpsBsInfo;
129 //#ifdef __cplusplus
130 //extern "C" {
131 //#endif//__cplusplus
132
133 /*
134 * Need move below structures to function pointer to seperate module/file later
135 */
136
137 //typedef int32_t (*rec_mb) (Mb *cur_mb, PWelsDecoderContext pCtx);
138
139 /*typedef for get intra predictor func pointer*/
140 typedef void (*PGetIntraPredFunc) (uint8_t* pPred, const int32_t kiLumaStride);
141 typedef void (*PIdctResAddPredFunc) (uint8_t* pPred, const int32_t kiStride, int16_t* pRs);
142 typedef void (*PIdctFourResAddPredFunc) (uint8_t* pPred, int32_t iStride, int16_t* pRs, const int8_t* pNzc);
143 typedef void (*PExpandPictureFunc) (uint8_t* pDst, const int32_t kiStride, const int32_t kiPicWidth,
144 const int32_t kiPicHeight);
145
146 typedef void (*PGetIntraPred8x8Func) (uint8_t* pPred, const int32_t kiLumaStride, bool bTLAvail, bool bTRAvail);
147
148 /**/
149 typedef struct TagRefPic {
150 PPicture pRefList[LIST_A][MAX_DPB_COUNT]; // reference picture marking plus FIFO scheme
151 PPicture pShortRefList[LIST_A][MAX_DPB_COUNT];
152 PPicture pLongRefList[LIST_A][MAX_DPB_COUNT];
153 uint8_t uiRefCount[LIST_A];
154 uint8_t uiShortRefCount[LIST_A];
155 uint8_t uiLongRefCount[LIST_A]; // dependend on ref pic module
156 int32_t iMaxLongTermFrameIdx;
157 } SRefPic, *PRefPic;
158
159 typedef void (*PCopyFunc) (uint8_t* pDst, int32_t iStrideD, uint8_t* pSrc, int32_t iStrideS);
160 typedef struct TagCopyFunc {
161 PCopyFunc pCopyLumaFunc;
162 PCopyFunc pCopyChromaFunc;
163 } SCopyFunc;
164
165 //deblock module defination
166 struct TagDeblockingFunc;
167
168 typedef struct tagDeblockingFilter {
169 uint8_t* pCsData[3]; // pointer to reconstructed picture data
170 int32_t iCsStride[2]; // Cs stride
171 EWelsSliceType eSliceType;
172 int8_t iSliceAlphaC0Offset;
173 int8_t iSliceBetaOffset;
174 int8_t iChromaQP[2];
175 int8_t iLumaQP;
176 struct TagDeblockingFunc* pLoopf;
177 PPicture* pRefPics[LIST_A];
178 } SDeblockingFilter, *PDeblockingFilter;
179
180 typedef void (*PDeblockingFilterMbFunc) (PDqLayer pCurDqLayer, PDeblockingFilter filter, int32_t boundry_flag);
181 typedef void (*PLumaDeblockingLT4Func) (uint8_t* iSampleY, int32_t iStride, int32_t iAlpha, int32_t iBeta,
182 int8_t* iTc);
183 typedef void (*PLumaDeblockingEQ4Func) (uint8_t* iSampleY, int32_t iStride, int32_t iAlpha, int32_t iBeta);
184 typedef void (*PChromaDeblockingLT4Func) (uint8_t* iSampleCb, uint8_t* iSampleCr, int32_t iStride, int32_t iAlpha,
185 int32_t iBeta, int8_t* iTc);
186 typedef void (*PChromaDeblockingEQ4Func) (uint8_t* iSampleCb, uint8_t* iSampleCr, int32_t iStride, int32_t iAlpha,
187 int32_t iBeta);
188 typedef void (*PChromaDeblockingLT4Func2) (uint8_t* iSampleCbr, int32_t iStride, int32_t iAlpha,
189 int32_t iBeta, int8_t* iTc);
190 typedef void (*PChromaDeblockingEQ4Func2) (uint8_t* iSampleCbr, int32_t iStride, int32_t iAlpha,
191 int32_t iBeta);
192
193 typedef struct TagDeblockingFunc {
194 PLumaDeblockingLT4Func pfLumaDeblockingLT4Ver;
195 PLumaDeblockingEQ4Func pfLumaDeblockingEQ4Ver;
196 PLumaDeblockingLT4Func pfLumaDeblockingLT4Hor;
197 PLumaDeblockingEQ4Func pfLumaDeblockingEQ4Hor;
198
199 PChromaDeblockingLT4Func pfChromaDeblockingLT4Ver;
200 PChromaDeblockingEQ4Func pfChromaDeblockingEQ4Ver;
201 PChromaDeblockingLT4Func pfChromaDeblockingLT4Hor;
202 PChromaDeblockingEQ4Func pfChromaDeblockingEQ4Hor;
203
204 PChromaDeblockingLT4Func2 pfChromaDeblockingLT4Ver2;
205 PChromaDeblockingEQ4Func2 pfChromaDeblockingEQ4Ver2;
206 PChromaDeblockingLT4Func2 pfChromaDeblockingLT4Hor2;
207 PChromaDeblockingEQ4Func2 pfChromaDeblockingEQ4Hor2;
208
209 } SDeblockingFunc, *PDeblockingFunc;
210
211 typedef void (*PWelsNonZeroCountFunc) (int8_t* pNonZeroCount);
212 typedef void (*PWelsBlockZeroFunc) (int16_t* block, int32_t stride);
213 typedef struct TagBlockFunc {
214 PWelsNonZeroCountFunc pWelsSetNonZeroCountFunc;
215 PWelsBlockZeroFunc pWelsBlockZero16x16Func;
216 PWelsBlockZeroFunc pWelsBlockZero8x8Func;
217 } SBlockFunc;
218
219 typedef void (*PWelsFillNeighborMbInfoIntra4x4Func) (PWelsNeighAvail pNeighAvail, uint8_t* pNonZeroCount,
220 int8_t* pIntraPredMode, PDqLayer pCurDqLayer);
221 typedef void (*PWelsMapNeighToSample) (PWelsNeighAvail pNeighAvail, int32_t* pSampleAvail);
222 typedef void (*PWelsMap16NeighToSample) (PWelsNeighAvail pNeighAvail, uint8_t* pSampleAvail);
223 typedef int32_t (*PWelsParseIntra4x4ModeFunc) (PWelsNeighAvail pNeighAvail, int8_t* pIntraPredMode, PBitStringAux pBs,
224 PDqLayer pCurDqLayer);
225 typedef int32_t (*PWelsParseIntra16x16ModeFunc) (PWelsNeighAvail pNeighAvail, PBitStringAux pBs, PDqLayer pCurDqLayer);
226
227 enum {
228 OVERWRITE_NONE = 0,
229 OVERWRITE_PPS = 1,
230 OVERWRITE_SPS = 1 << 1,
231 OVERWRITE_SUBSETSPS = 1 << 2
232 };
233
234
235 //Decoder SPS and PPS global CTX
236 typedef struct tagWelsWelsDecoderSpsPpsCTX {
237 SPosOffset sFrameCrop;
238
239 SSps sSpsBuffer[MAX_SPS_COUNT + 1];
240 SPps sPpsBuffer[MAX_PPS_COUNT + 1];
241
242 SSubsetSps sSubsetSpsBuffer[MAX_SPS_COUNT + 1];
243 SNalUnit sPrefixNal;
244
245 PSps pActiveLayerSps[MAX_LAYER_NUM];
246 bool bAvcBasedFlag; // For decoding bitstream:
247
248 // for EC parameter sets
249 bool bSpsExistAheadFlag; // whether does SPS NAL exist ahead of sequence?
250 bool bSubspsExistAheadFlag;// whether does Subset SPS NAL exist ahead of sequence?
251 bool bPpsExistAheadFlag; // whether does PPS NAL exist ahead of sequence?
252
253 int32_t iSpsErrorIgnored;
254 int32_t iSubSpsErrorIgnored;
255 int32_t iPpsErrorIgnored;
256
257 bool bSpsAvailFlags[MAX_SPS_COUNT];
258 bool bSubspsAvailFlags[MAX_SPS_COUNT];
259 bool bPpsAvailFlags[MAX_PPS_COUNT];
260 int32_t iPPSLastInvalidId;
261 int32_t iPPSInvalidNum;
262 int32_t iSPSLastInvalidId;
263 int32_t iSPSInvalidNum;
264 int32_t iSubSPSLastInvalidId;
265 int32_t iSubSPSInvalidNum;
266 int32_t iSeqId; //sequence id
267 int iOverwriteFlags;
268 } SWelsDecoderSpsPpsCTX, *PWelsDecoderSpsPpsCTX;
269
270 //Last Decoded Picture Info
271 typedef struct tagSWelsLastDecPicInfo {
272 // Save the last nal header info
273 SNalUnitHeaderExt sLastNalHdrExt;
274 SSliceHeader sLastSliceHeader;
275 int32_t iPrevPicOrderCntMsb;
276 int32_t iPrevPicOrderCntLsb;
277 PPicture pPreviousDecodedPictureInDpb; //pointer to previously decoded picture in DPB for error concealment
278 int32_t iPrevFrameNum;// frame number of previous frame well decoded for non-truncated mode yet
279 bool bLastHasMmco5;
280 uint32_t uiDecodingTimeStamp; //represent relative decoding time stamps
281 } SWelsLastDecPicInfo, *PWelsLastDecPicInfo;
282
283 typedef struct tagPictInfo {
284 SBufferInfo sBufferInfo;
285 int32_t iPOC;
286 int32_t iPicBuffIdx;
287 uint32_t uiDecodingTimeStamp;
288 bool bLastGOP;
289 } SPictInfo, *PPictInfo;
290
291 typedef struct tagPictReoderingStatus {
292 int32_t iPictInfoIndex;
293 int32_t iMinPOC;
294 int32_t iNumOfPicts;
295 int32_t iLastGOPRemainPicts;
296 int32_t iLastWrittenPOC;
297 int32_t iLargestBufferedPicIndex;
298 bool bHasBSlice;
299 } SPictReoderingStatus, *PPictReoderingStatus;
300
301 /*
302 * SWelsDecoderContext: to maintail all modules data over decoder@framework
303 */
304
305 typedef struct TagWelsDecoderContext {
306 SLogContext sLogCtx;
307 // Input
308 void*
309 pArgDec; // structured arguments for decoder, reserved here for extension in the future
310
311 SDataBuffer sRawData;
312 SDataBuffer sSavedData; //for parse only purpose
313
314 // Configuration
315 SDecodingParam* pParam;
316 uint32_t uiCpuFlag; // CPU compatibility detected
317
318 VIDEO_BITSTREAM_TYPE eVideoType; //indicate the type of video to decide whether or not to do qp_delta error detection.
319 bool bHaveGotMemory; // global memory for decoder context related ever requested?
320
321 int32_t iImgWidthInPixel; // width of image in pixel reconstruction picture to be output
322 int32_t iImgHeightInPixel;// height of image in pixel reconstruction picture to be output
323 int32_t
324 iLastImgWidthInPixel; // width of image in last successful pixel reconstruction picture to be output
325 int32_t
326 iLastImgHeightInPixel;// height of image in last successful pixel reconstruction picture to be output
327 bool bFreezeOutput; // indicating current frame freezing. Default: true
328
329
330 // Derived common elements
331 SNalUnitHeader sCurNalHead;
332 EWelsSliceType eSliceType; // Slice type
333 bool bUsedAsRef; //flag as ref
334 int32_t iFrameNum;
335 int32_t iErrorCode; // error code return while decoding in case packets lost
336 SFmo sFmoList[MAX_PPS_COUNT]; // list for FMO storage
337 PFmo pFmo; // current fmo context after parsed slice_header
338 int32_t iActiveFmoNum; // active count number of fmo context in list
339
340 /*needed info by decode slice level and mb level*/
341 int32_t
342 iDecBlockOffsetArray[24]; // address talbe for sub 4x4 block in intra4x4_mb, so no need to caculta the address every time.
343
344 struct {
345 uint32_t* pMbType[LAYER_NUM_EXCHANGEABLE]; /* mb type */
346 int16_t (*pMv[LAYER_NUM_EXCHANGEABLE][LIST_A])[MB_BLOCK4x4_NUM][MV_A]; //[LAYER_NUM_EXCHANGEABLE MB_BLOCK4x4_NUM*]
347 int8_t (*pRefIndex[LAYER_NUM_EXCHANGEABLE][LIST_A])[MB_BLOCK4x4_NUM];
348 int8_t (*pDirect[LAYER_NUM_EXCHANGEABLE])[MB_BLOCK4x4_NUM];
349 bool* pNoSubMbPartSizeLessThan8x8Flag[LAYER_NUM_EXCHANGEABLE];
350 bool* pTransformSize8x8Flag[LAYER_NUM_EXCHANGEABLE];
351 int8_t* pLumaQp[LAYER_NUM_EXCHANGEABLE]; /*mb luma_qp*/
352 int8_t (*pChromaQp[LAYER_NUM_EXCHANGEABLE])[2]; /*mb chroma_qp*/
353 int16_t (*pMvd[LAYER_NUM_EXCHANGEABLE][LIST_A])[MB_BLOCK4x4_NUM][MV_A]; //[LAYER_NUM_EXCHANGEABLE MB_BLOCK4x4_NUM*]
354 uint16_t* pCbfDc[LAYER_NUM_EXCHANGEABLE];
355 int8_t (*pNzc[LAYER_NUM_EXCHANGEABLE])[24];
356 int8_t (*pNzcRs[LAYER_NUM_EXCHANGEABLE])[24];
357 int16_t (*pScaledTCoeff[LAYER_NUM_EXCHANGEABLE])[MB_COEFF_LIST_SIZE]; /*need be aligned*/
358 int8_t (*pIntraPredMode[LAYER_NUM_EXCHANGEABLE])[8]; //0~3 top4x4 ; 4~6 left 4x4; 7 intra16x16
359 int8_t (*pIntra4x4FinalMode[LAYER_NUM_EXCHANGEABLE])[MB_BLOCK4x4_NUM];
360 uint8_t* pIntraNxNAvailFlag[LAYER_NUM_EXCHANGEABLE];
361 int8_t* pChromaPredMode[LAYER_NUM_EXCHANGEABLE];
362 int8_t* pCbp[LAYER_NUM_EXCHANGEABLE];
363 uint8_t (*pMotionPredFlag[LAYER_NUM_EXCHANGEABLE][LIST_A])[MB_PARTITION_SIZE]; // 8x8
364 uint32_t (*pSubMbType[LAYER_NUM_EXCHANGEABLE])[MB_SUB_PARTITION_SIZE];
365 int32_t* pSliceIdc[LAYER_NUM_EXCHANGEABLE]; // using int32_t for slice_idc
366 int8_t* pResidualPredFlag[LAYER_NUM_EXCHANGEABLE];
367 int8_t* pInterPredictionDoneFlag[LAYER_NUM_EXCHANGEABLE];
368 bool* pMbCorrectlyDecodedFlag[LAYER_NUM_EXCHANGEABLE];
369 bool* pMbRefConcealedFlag[LAYER_NUM_EXCHANGEABLE];
370 uint32_t iMbWidth;
371 uint32_t iMbHeight;
372 } sMb;
373
374
375 // reconstruction picture
376 PPicture pDec; //pointer to current picture being reconstructed
377
378 PPicture
379 pTempDec; //pointer to temp decoder picture to be used only for Bi Prediction.
380
381 // reference pictures
382 SRefPic sRefPic;
383 SRefPic sTmpRefPic; //used to temporarily save RefPic for next active thread
384 SVlcTable* pVlcTable; // vlc table
385
386 SBitStringAux sBs;
387 int32_t iMaxBsBufferSizeInByte; //actual memory size for BS buffer
388
389 /* Global memory external */
390 SWelsDecoderSpsPpsCTX sSpsPpsCtx;
391 bool bHasNewSps;
392
393 SPosOffset sFrameCrop;
394
395 PSliceHeader pSliceHeader;
396
397 PPicBuff pPicBuff; // Initially allocated memory for pictures which are used in decoding.
398 int32_t iPicQueueNumber;
399
400 PAccessUnit pAccessUnitList; // current access unit list to be performed
401 //PSps pActiveLayerSps[MAX_LAYER_NUM];
402 PSps pSps; // used by current AU
403 PPps pPps; // used by current AU
404 // Memory for pAccessUnitList is dynamically held till decoder destruction.
405 PDqLayer
406 pCurDqLayer; // current DQ layer representation, also carry reference base layer if applicable
407 PDqLayer pDqLayersList[LAYER_NUM_EXCHANGEABLE]; // DQ layers list with memory allocated
408 PNalUnit pNalCur; // point to current NAL Nnit
409 uint8_t uiNalRefIdc; // NalRefIdc for easy access;
410 int32_t iPicWidthReq; // picture width have requested the memory
411 int32_t iPicHeightReq; // picture height have requested the memory
412
413 uint8_t uiTargetDqId; // maximal DQ ID in current access unit, meaning target layer ID
414 //bool bAvcBasedFlag; // For decoding bitstream:
415 bool bEndOfStreamFlag; // Flag on end of stream requested by external application layer
416 bool bInstantDecFlag; // Flag for no-delay decoding
417 bool bInitialDqLayersMem; // dq layers related memory is available?
418
419 bool bOnlyOneLayerInCurAuFlag; //only one layer in current AU: 1
420
421 bool bReferenceLostAtT0Flag;
422 int32_t iTotalNumMbRec; //record current number of decoded MB
423 #ifdef LONG_TERM_REF
424 bool bParamSetsLostFlag; //sps or pps do not exist or not correct
425
426 bool
427 bCurAuContainLtrMarkSeFlag; //current AU has the LTR marking syntax element, mark the previous frame or self
428 int32_t iFrameNumOfAuMarkedLtr; //if bCurAuContainLtrMarkSeFlag==true, SHOULD set this variable
429
430 uint16_t uiCurIdrPicId;
431 #endif
432 bool bNewSeqBegin;
433 bool bNextNewSeqBegin;
434
435 //for Parse only
436 bool bFramePending;
437 bool bFrameFinish;
438 int32_t iNalNum;
439 int32_t iMaxNalNum; //permitted max NAL num stored in parser
440 SSpsBsInfo sSpsBsInfo [MAX_SPS_COUNT];
441 SSpsBsInfo sSubsetSpsBsInfo [MAX_PPS_COUNT];
442 SPpsBsInfo sPpsBsInfo [MAX_PPS_COUNT];
443 SParserBsInfo* pParserBsInfo;
444
445 //PPicture pPreviousDecodedPictureInDpb; //pointer to previously decoded picture in DPB for error concealment
446 PGetIntraPredFunc pGetI16x16LumaPredFunc[7]; //h264_predict_copy_16x16;
447 PGetIntraPredFunc pGetI4x4LumaPredFunc[14]; // h264_predict_4x4_t
448 PGetIntraPredFunc pGetIChromaPredFunc[7]; // h264_predict_8x8_t
449 PIdctResAddPredFunc pIdctResAddPredFunc;
450 PIdctFourResAddPredFunc pIdctFourResAddPredFunc;
451 SMcFunc sMcFunc;
452 //Transform8x8
453 PGetIntraPred8x8Func pGetI8x8LumaPredFunc[14];
454 PIdctResAddPredFunc pIdctResAddPredFunc8x8;
455
456 //For error concealment
457 SCopyFunc sCopyFunc;
458 /* For Deblocking */
459 SDeblockingFunc sDeblockingFunc;
460 SExpandPicFunc sExpandPicFunc;
461
462 /* For Block */
463 SBlockFunc sBlockFunc;
464
465 int32_t iCurSeqIntervalTargetDependId;
466 int32_t iCurSeqIntervalMaxPicWidth;
467 int32_t iCurSeqIntervalMaxPicHeight;
468
469 PWelsFillNeighborMbInfoIntra4x4Func pFillInfoCacheIntraNxNFunc;
470 PWelsMapNeighToSample pMapNxNNeighToSampleFunc;
471 PWelsMap16NeighToSample pMap16x16NeighToSampleFunc;
472
473 //feedback whether or not have VCL in current AU, and the temporal ID
474 int32_t iFeedbackVclNalInAu;
475 int32_t iFeedbackTidInAu;
476 int32_t iFeedbackNalRefIdc;
477
478 bool bAuReadyFlag; // true: one au is ready for decoding; false: default value
479
480 bool bPrintFrameErrorTraceFlag; //true: can print info for upper layer
481 int32_t iIgnoredErrorInfoPacketCount; //store the packet number with error decoding info
482 //trace handle
483 void* pTraceHandle;
484
485 PWelsLastDecPicInfo pLastDecPicInfo;
486
487 SWelsCabacCtx sWelsCabacContexts[4][WELS_QP_MAX + 1][WELS_CONTEXT_COUNT];
488 bool bCabacInited;
489 SWelsCabacCtx pCabacCtx[WELS_CONTEXT_COUNT];
490 PWelsCabacDecEngine pCabacDecEngine;
491 double dDecTime;
492 SDecoderStatistics* pDecoderStatistics; // For real time debugging
493 int32_t iMbEcedNum;
494 int32_t iMbEcedPropNum;
495 int32_t iMbNum;
496 bool bMbRefConcealed;
497 bool bRPLRError;
498 int32_t iECMVs[16][2];
499 PPicture pECRefPic[16];
500 unsigned long long uiTimeStamp;
501 uint32_t uiDecodingTimeStamp; //represent relative decoding time stamps
502 // To support scaling list HP
503 uint16_t pDequant_coeff_buffer4x4[6][52][16];
504 uint16_t pDequant_coeff_buffer8x8[6][52][64];
505 uint16_t (*pDequant_coeff4x4[6])[16];// 4x4 sclaing list value pointer
506 uint16_t (*pDequant_coeff8x8[6])[64];//64 residual coeff ,with 6 kinds of residual type, 52 qp level
507 int iDequantCoeffPpsid;//When a new pps actived, reinitialised the scaling list value
508 bool bDequantCoeff4x4Init;
509 bool bUseScalingList;
510 CMemoryAlign* pMemAlign;
511 void* pThreadCtx;
512 void* pLastThreadCtx;
513 WELS_MUTEX* pCsDecoder;
514 int16_t lastReadyHeightOffset[LIST_A][MAX_REF_PIC_COUNT]; //last ready reference MB offset
515 PPictInfo pPictInfoList;
516 PPictReoderingStatus pPictReoderingStatus;
517 } SWelsDecoderContext, *PWelsDecoderContext;
518
519 typedef struct tagSWelsDecThread {
520 SWelsDecSemphore* sIsBusy;
521 SWelsDecSemphore sIsActivated;
522 SWelsDecSemphore sIsIdle;
523 SWelsDecThread sThrHandle;
524 uint32_t uiCommand;
525 uint32_t uiThrNum;
526 uint32_t uiThrMaxNum;
527 uint32_t uiThrStackSize;
528 DECLARE_PROCTHREAD_PTR (pThrProcMain);
529 } SWelsDecThreadInfo, *PWelsDecThreadInfo;
530
531 typedef struct tagSWelsDecThreadCtx {
532 SWelsDecThreadInfo sThreadInfo;
533 PWelsDecoderContext pCtx;
534 void* threadCtxOwner;
535 uint8_t* kpSrc;
536 int32_t kiSrcLen;
537 uint8_t** ppDst;
538 SBufferInfo sDstInfo;
539 PPicture pDec;
540 SWelsDecEvent sImageReady;
541 SWelsDecEvent sSliceDecodeStart;
542 SWelsDecEvent sSliceDecodeFinish;
543 int32_t iPicBuffIdx; //picBuff Index
544 } SWelsDecoderThreadCTX, *PWelsDecoderThreadCTX;
545
ResetActiveSPSForEachLayer(PWelsDecoderContext pCtx)546 static inline void ResetActiveSPSForEachLayer (PWelsDecoderContext pCtx) {
547 if (pCtx->iTotalNumMbRec == 0) {
548 for (int i = 0; i < MAX_LAYER_NUM; i++) {
549 pCtx->sSpsPpsCtx.pActiveLayerSps[i] = NULL;
550 }
551 }
552 }
GetThreadCount(PWelsDecoderContext pCtx)553 static inline int32_t GetThreadCount (PWelsDecoderContext pCtx) {
554 int32_t iThreadCount = 0;
555 if (pCtx->pThreadCtx != NULL) {
556 PWelsDecoderThreadCTX pThreadCtx = (PWelsDecoderThreadCTX)pCtx->pThreadCtx;
557 iThreadCount = pThreadCtx->sThreadInfo.uiThrMaxNum;
558 }
559 return iThreadCount;
560 }
561 //GetPrevFrameNum only applies when thread count >= 2
GetPrevFrameNum(PWelsDecoderContext pCtx)562 static inline int32_t GetPrevFrameNum (PWelsDecoderContext pCtx) {
563 if (pCtx->uiDecodingTimeStamp > 0) {
564 PWelsDecoderThreadCTX pThreadCtx = (PWelsDecoderThreadCTX)pCtx->pThreadCtx;
565 int32_t iThreadCount = int32_t (pThreadCtx->sThreadInfo.uiThrMaxNum);
566 int32_t uiThrNum = int32_t (pThreadCtx->sThreadInfo.uiThrNum);
567 for (int32_t i = 0; i < iThreadCount; ++i) {
568 int32_t id = i - uiThrNum;
569 if (id != 0 && pThreadCtx[id].pCtx->uiDecodingTimeStamp == pCtx->uiDecodingTimeStamp - 1) {
570 if (pThreadCtx[id].pCtx->pDec != NULL) {
571 int32_t iFrameNum = pThreadCtx[id].pCtx->pDec->iFrameNum;
572 if (iFrameNum >= 0) return iFrameNum;
573 }
574 return pThreadCtx[id].pCtx->iFrameNum;
575 }
576 }
577 }
578 return pCtx->pLastDecPicInfo->iPrevFrameNum;
579 }
580 //#ifdef __cplusplus
581 //}
582 //#endif//__cplusplus
583
584
585 } // namespace WelsDec
586
587 #endif//WELS_DECODER_FRAMEWORK_H__
588