History

Pretty printed the C++ code with astyle

Ethan Hugg committed 12 years ago

Commit ff6b6691 parent 063709c225 files · +48457 −51954Browse files

Showing the changes to codec/decoder/core/src/decoder_core.cpp (1 of 225 files). Show all

Unified · Split

codec/decoder/core/src/decoder_core.cpp+1714−1838
@@ -59,242 +59,232 @@ · 58 unmodified lines
59 59
60namespace WelsDec {60namespace WelsDec {
61 61
62static inline int32_t DecodeFrameConstruction( PWelsDecoderContext pCtx, uint8_t **ppDst, int32_t *pDstLen, int32_t *pWidth, int32_t *pHeight, SBufferInfo *pDstInfo )62static inline int32_t DecodeFrameConstruction (PWelsDecoderContext pCtx, uint8_t** ppDst, int32_t* pDstLen,
63{63 int32_t* pWidth, int32_t* pHeight, SBufferInfo* pDstInfo) {
64 PDqLayer pCurDq = pCtx->pCurDqLayer; 64 PDqLayer pCurDq = pCtx->pCurDqLayer;
65 PPicture pPic = pCtx->pDec;65 PPicture pPic = pCtx->pDec;
66 66
67 const int32_t kiWidth = pCurDq->iMbWidth << 4;67 const int32_t kiWidth = pCurDq->iMbWidth << 4;
68 const int32_t kiHeight= pCurDq->iMbHeight << 4;68 const int32_t kiHeight = pCurDq->iMbHeight << 4;
69 69
70 const int32_t kiTotalNumMbInCurLayer = pCurDq->iMbWidth * pCurDq->iMbHeight;70 const int32_t kiTotalNumMbInCurLayer = pCurDq->iMbWidth * pCurDq->iMbHeight;
71 71
72 if ( pPic->iTotalNumMbRec != kiTotalNumMbInCurLayer )72 if (pPic->iTotalNumMbRec != kiTotalNumMbInCurLayer) {
73 {73 WelsLog (pCtx, WELS_LOG_WARNING,
74 WelsLog( pCtx, WELS_LOG_WARNING, "DecodeFrameConstruction():::iTotalNumMbRec:%d, total_num_mb_sps:%d, cur_layer_mb_width:%d, cur_layer_mb_height:%d \n",74 "DecodeFrameConstruction():::iTotalNumMbRec:%d, total_num_mb_sps:%d, cur_layer_mb_width:%d, cur_layer_mb_height:%d \n",
75 pPic->iTotalNumMbRec, kiTotalNumMbInCurLayer, pCurDq->iMbWidth, pCurDq->iMbHeight );75 pPic->iTotalNumMbRec, kiTotalNumMbInCurLayer, pCurDq->iMbWidth, pCurDq->iMbHeight);
76 return -1;76 return -1;
77 }77 }
78#ifdef NO_WAITING_AU78#ifdef NO_WAITING_AU
79 pPic->iTotalNumMbRec = 0;79 pPic->iTotalNumMbRec = 0;
80#endif80#endif
81 81
82 if ( I_SLICE == pCurDq->sLayerInfo.sSliceInLayer.eSliceType )82 if (I_SLICE == pCurDq->sLayerInfo.sSliceInLayer.eSliceType) {
83 {83 memcpy (& (pCtx->sFrameCrop), & (pCurDq->sLayerInfo.sSliceInLayer.sSliceHeaderExt.sSliceHeader.pSps->sFrameCrop),
84 memcpy( &(pCtx->sFrameCrop), &(pCurDq->sLayerInfo.sSliceInLayer.sSliceHeaderExt.sSliceHeader.pSps->sFrameCrop), sizeof(SPosOffset) );//confirmed_safe_unsafe_usage84 sizeof (SPosOffset)); //confirmed_safe_unsafe_usage
85#ifdef LONG_TERM_REF85#ifdef LONG_TERM_REF
86 pCtx->bParamSetsLostFlag = false;86 pCtx->bParamSetsLostFlag = false;
87#else87#else
88 pCtx->bReferenceLostAtT0Flag = false; // need initialize it due I_SLICE, 6/4/201088 pCtx->bReferenceLostAtT0Flag = false; // need initialize it due I_SLICE, 6/4/2010
89#endif //LONG_TERM_REF89#endif //LONG_TERM_REF
90 WelsLog( pCtx, WELS_LOG_INFO, "DecodeFrameConstruction()::::output good I frame, %d x %d, crop_left:%d, crop_right:%d, crop_top:%d, crop_bottom:%d.\n",90 WelsLog (pCtx, WELS_LOG_INFO,
91 kiWidth, kiHeight, pCtx->sFrameCrop.iLeftOffset, pCtx->sFrameCrop.iRightOffset, pCtx->sFrameCrop.iTopOffset, pCtx->sFrameCrop.iBottomOffset );91 "DecodeFrameConstruction()::::output good I frame, %d x %d, crop_left:%d, crop_right:%d, crop_top:%d, crop_bottom:%d.\n",
92 WelsLog( pCtx, WELS_LOG_INFO, "After decoding, set_mode:[%s], eWorkMode:[%s], eBufferProperty:[%s]\n",92 kiWidth, kiHeight, pCtx->sFrameCrop.iLeftOffset, pCtx->sFrameCrop.iRightOffset, pCtx->sFrameCrop.iTopOffset,
93 DECODER_MODE_NAME(pCtx->iSetMode), DECODER_MODE_NAME(pCtx->iDecoderMode), OUTPUT_PROPERTY_NAME(pDstInfo->eBufferProperty));93 pCtx->sFrameCrop.iBottomOffset);
94 }94 WelsLog (pCtx, WELS_LOG_INFO, "After decoding, set_mode:[%s], eWorkMode:[%s], eBufferProperty:[%s]\n",
95 95 DECODER_MODE_NAME (pCtx->iSetMode), DECODER_MODE_NAME (pCtx->iDecoderMode),
96 //////output:::normal path96 OUTPUT_PROPERTY_NAME (pDstInfo->eBufferProperty));
97 ppDst[0] = pPic->pData[0];97 }
98 ppDst[1] = pPic->pData[1];98
99 ppDst[2] = pPic->pData[2];99 //////output:::normal path
100 *pDstLen = pPic->iLinesize[0]; 100 ppDst[0] = pPic->pData[0];
101 *(pDstLen+1) = pPic->iLinesize[1];101 ppDst[1] = pPic->pData[1];
102 *pWidth = kiWidth;102 ppDst[2] = pPic->pData[2];
103 *pHeight = kiHeight;103 *pDstLen = pPic->iLinesize[0];
104 104 * (pDstLen + 1) = pPic->iLinesize[1];
105 pDstInfo->UsrData.sSystemBuffer.iFormat = videoFormatI420;105 *pWidth = kiWidth;
106 106 *pHeight = kiHeight;
107 pDstInfo->UsrData.sSystemBuffer.iWidth = kiWidth - (pCtx->sFrameCrop.iLeftOffset + pCtx->sFrameCrop.iRightOffset)*2;107
108 pDstInfo->UsrData.sSystemBuffer.iHeight = kiHeight - (pCtx->sFrameCrop.iTopOffset + pCtx->sFrameCrop.iBottomOffset)*2;108 pDstInfo->UsrData.sSystemBuffer.iFormat = videoFormatI420;
109 pDstInfo->UsrData.sSystemBuffer.iStride[0] = pPic->iLinesize[0];109
110 pDstInfo->UsrData.sSystemBuffer.iStride[1] = pPic->iLinesize[1];110 pDstInfo->UsrData.sSystemBuffer.iWidth = kiWidth - (pCtx->sFrameCrop.iLeftOffset + pCtx->sFrameCrop.iRightOffset) * 2;
111 ppDst[0] = ppDst[0] + pCtx->sFrameCrop.iTopOffset*2*pPic->iLinesize[0] + pCtx->sFrameCrop.iLeftOffset*2;111 pDstInfo->UsrData.sSystemBuffer.iHeight = kiHeight - (pCtx->sFrameCrop.iTopOffset + pCtx->sFrameCrop.iBottomOffset) * 2;
112 ppDst[1] = ppDst[1] + pCtx->sFrameCrop.iTopOffset *pPic->iLinesize[1] + pCtx->sFrameCrop.iLeftOffset;112 pDstInfo->UsrData.sSystemBuffer.iStride[0] = pPic->iLinesize[0];
113 ppDst[2] = ppDst[2] + pCtx->sFrameCrop.iTopOffset *pPic->iLinesize[1] + pCtx->sFrameCrop.iLeftOffset;113 pDstInfo->UsrData.sSystemBuffer.iStride[1] = pPic->iLinesize[1];
114 pDstInfo->eBufferProperty = BUFFER_HOST;114 ppDst[0] = ppDst[0] + pCtx->sFrameCrop.iTopOffset * 2 * pPic->iLinesize[0] + pCtx->sFrameCrop.iLeftOffset * 2;
115 pDstInfo->iBufferStatus = 1;115 ppDst[1] = ppDst[1] + pCtx->sFrameCrop.iTopOffset * pPic->iLinesize[1] + pCtx->sFrameCrop.iLeftOffset;
116 116 ppDst[2] = ppDst[2] + pCtx->sFrameCrop.iTopOffset * pPic->iLinesize[1] + pCtx->sFrameCrop.iLeftOffset;
117 return 0;117 pDstInfo->eBufferProperty = BUFFER_HOST;
118 pDstInfo->iBufferStatus = 1;
119
120 return 0;
118}121}
119 122
120inline BOOL_T CheckSliceNeedReconstruct(int16_t iCurDid, int16_t iCurQid, bool_t bStoreRefBasePicFlag, 123inline BOOL_T CheckSliceNeedReconstruct (int16_t iCurDid, int16_t iCurQid, bool_t bStoreRefBasePicFlag,
121 uint8_t uiDidMax, uint8_t uiLayerDqId, uint8_t uiTargetDqId)124 uint8_t uiDidMax, uint8_t uiLayerDqId, uint8_t uiTargetDqId) {
122{125 return ((iCurDid == uiDidMax) && (iCurQid == BASE_QUALITY_ID) && (bStoreRefBasePicFlag)) // store base
123 return ( (iCurDid == uiDidMax) && (iCurQid == BASE_QUALITY_ID) && (bStoreRefBasePicFlag) ) // store base126 || (uiLayerDqId == uiTargetDqId); // target layer
124 || (uiLayerDqId == uiTargetDqId); // target layer
125}127}
126 128
127inline uint8_t GetTargetDqId(uint8_t uiTargetDqId, SDecodingParam * psParam)129inline uint8_t GetTargetDqId (uint8_t uiTargetDqId, SDecodingParam* psParam) {
128{130 uint8_t uiRequiredDqId = psParam ? psParam->uiTargetDqLayer : (uint8_t)255;
129 uint8_t uiRequiredDqId = psParam ? psParam->uiTargetDqLayer : (uint8_t)255;
130 131
131 return WELS_MIN(uiTargetDqId, uiRequiredDqId);132 return WELS_MIN (uiTargetDqId, uiRequiredDqId);
132}133}
133
134 134
135inline void_t HandleReferenceLostL0(PWelsDecoderContext pCtx, PNalUnit pCurNal)135
136{136inline void_t HandleReferenceLostL0 (PWelsDecoderContext pCtx, PNalUnit pCurNal) {
137 if( 0 == pCurNal->sNalHeaderExt.uiTemporalId ){137 if (0 == pCurNal->sNalHeaderExt.uiTemporalId) {
138 pCtx->bReferenceLostAtT0Flag = true;138 pCtx->bReferenceLostAtT0Flag = true;
139 }139 }
140#ifndef LONG_TERM_REF140#ifndef LONG_TERM_REF
141 if( pCtx->bReferenceLostAtT0Flag ){141 if (pCtx->bReferenceLostAtT0Flag) {
142 ResetParameterSetsState(pCtx);142 ResetParameterSetsState (pCtx);
143 } 143 }
144#endif144#endif
145 pCtx->iErrorCode |= dsBitstreamError;145 pCtx->iErrorCode |= dsBitstreamError;
146}146}
147 147
148inline void_t HandleReferenceLost(PWelsDecoderContext pCtx, PNalUnit pCurNal)148inline void_t HandleReferenceLost (PWelsDecoderContext pCtx, PNalUnit pCurNal) {
149{149 if ((0 == pCurNal->sNalHeaderExt.uiTemporalId) || (1 == pCurNal->sNalHeaderExt.uiTemporalId)) {
150 if( (0 == pCurNal->sNalHeaderExt.uiTemporalId) || (1 == pCurNal->sNalHeaderExt.uiTemporalId) ){150 pCtx->bReferenceLostAtT0Flag = true;
151 pCtx->bReferenceLostAtT0Flag = true;151 }
152 }
153#ifndef LONG_TERM_REF152#ifndef LONG_TERM_REF
154 if( pCtx->bReferenceLostAtT0Flag ){153 if (pCtx->bReferenceLostAtT0Flag) {
155 ResetParameterSetsState(pCtx);154 ResetParameterSetsState (pCtx);
156 }155 }
157#endif156#endif
158 pCtx->iErrorCode |= dsRefLost;157 pCtx->iErrorCode |= dsRefLost;
159}158}
160 159
161inline int32_t WelsDecodeConstructSlice(PWelsDecoderContext pCtx, PNalUnit pCurNal)160inline int32_t WelsDecodeConstructSlice (PWelsDecoderContext pCtx, PNalUnit pCurNal) {
162{161 int32_t iRet = WelsTargetSliceConstruction (pCtx);
163 int32_t iRet = WelsTargetSliceConstruction(pCtx);
164 162
165 if( iRet ){163 if (iRet) {
166 HandleReferenceLostL0(pCtx, pCurNal);164 HandleReferenceLostL0 (pCtx, pCurNal);
167 }165 }
168 166
169 return iRet;167 return iRet;
170}168}
171 169
172/*170/*
173 * Predeclared function routines ..171 * Predeclared function routines ..
174 */172 */
175int32_t ParseRefPicListReordering ( PBitStringAux pBs, PSliceHeader pSh )173int32_t ParseRefPicListReordering (PBitStringAux pBs, PSliceHeader pSh) {
176{174 int32_t iList = 0;
177 int32_t iList = 0;175 const ESliceType keSt = pSh->eSliceType;
178 const ESliceType keSt = pSh->eSliceType;176 PRefPicListReorderSyn pRefPicListReordering = &pSh->pRefPicListReordering;
179 PRefPicListReorderSyn pRefPicListReordering = &pSh->pRefPicListReordering;177
180 178 if (keSt == I_SLICE || keSt == SI_SLICE)
181 if ( keSt == I_SLICE || keSt == SI_SLICE )179 return ERR_NONE;
182 return ERR_NONE;180
183 181 // Common syntaxs for P or B slices: list0, list1 followed if B slices used.
184 // Common syntaxs for P or B slices: list0, list1 followed if B slices used.182 do {
185 do {183 pRefPicListReordering->bRefPicListReorderingFlag[iList] = !!BsGetOneBit (pBs);
186 pRefPicListReordering->bRefPicListReorderingFlag[iList] = !!BsGetOneBit( pBs);184
187 185 if (pRefPicListReordering->bRefPicListReorderingFlag[iList]) {
188 if ( pRefPicListReordering->bRefPicListReorderingFlag[iList] ){186 int32_t iIdx = 0;
189 int32_t iIdx = 0;187 do {
190 do {188 const uint8_t kuiIdc = BsGetUe (pBs);
191 const uint8_t kuiIdc = BsGetUe( pBs ); 189
192 190 //Fixed the referrence list reordering crash issue.(fault kIdc value > 3 case)---
193 //Fixed the referrence list reordering crash issue.(fault kIdc value > 3 case)---191 if ((iIdx >= MAX_REF_PIC_COUNT) || (kuiIdc > 3)) {
194 if ((iIdx >= MAX_REF_PIC_COUNT )||(kuiIdc > 3))192 return GENERATE_ERROR_NO (ERR_LEVEL_SLICE_HEADER, ERR_INFO_INVALID_REF_REORDERING);
195 {193 }
196 return GENERATE_ERROR_NO(ERR_LEVEL_SLICE_HEADER, ERR_INFO_INVALID_REF_REORDERING);194 pRefPicListReordering->sReorderingSyn[iList][iIdx].uiReorderingOfPicNumsIdc = kuiIdc;
197 }195 if (kuiIdc == 3)
198 pRefPicListReordering->sReorderingSyn[iList][iIdx].uiReorderingOfPicNumsIdc = kuiIdc;196 break;
199 if ( kuiIdc == 3 )197
200 break;198 if (iIdx >= pSh->uiRefCount[iList] || iIdx >= MAX_REF_PIC_COUNT)
201 199 return GENERATE_ERROR_NO (ERR_LEVEL_SLICE_HEADER, ERR_INFO_INVALID_REF_REORDERING);
202 if ( iIdx >= pSh->uiRefCount[iList] || iIdx >= MAX_REF_PIC_COUNT )200
203 return GENERATE_ERROR_NO(ERR_LEVEL_SLICE_HEADER, ERR_INFO_INVALID_REF_REORDERING);201 if (kuiIdc == 0 || kuiIdc == 1) {
204 202 pRefPicListReordering->sReorderingSyn[iList][iIdx].uiAbsDiffPicNumMinus1 = BsGetUe (pBs); // uiAbsDiffPicNumMinus1
205 if (kuiIdc == 0 || kuiIdc == 1){203 } else if (kuiIdc == 2) {
206 pRefPicListReordering->sReorderingSyn[iList][iIdx].uiAbsDiffPicNumMinus1 = BsGetUe( pBs ); // uiAbsDiffPicNumMinus1204 pRefPicListReordering->sReorderingSyn[iList][iIdx].uiLongTermPicNum = BsGetUe (pBs);
207 }205 }
208 else if (kuiIdc == 2){ 206
209 pRefPicListReordering->sReorderingSyn[iList][iIdx].uiLongTermPicNum= BsGetUe( pBs ); 207 ++ iIdx;
210 }208 } while (true);
211 209 }
212 ++ iIdx;210 if (keSt != B_SLICE)
213 } while(true);211 break;
214 }212 ++ iList;
215 if (keSt != B_SLICE)213 } while (iList < LIST_A);
216 break;214
217 ++ iList;215 return ERR_NONE;
218 } while(iList < LIST_A);
219
220 return ERR_NONE;
221}216}
222 217
223int32_t ParseDecRefPicMarking ( PWelsDecoderContext pCtx, PBitStringAux pBs, PSliceHeader pSh, PSps pSps, const bool_t kbIdrFlag)218int32_t ParseDecRefPicMarking (PWelsDecoderContext pCtx, PBitStringAux pBs, PSliceHeader pSh, PSps pSps,
224{219 const bool_t kbIdrFlag) {
225 PRefPicMarking const kpRefMarking = &pSh->sRefMarking;220 PRefPicMarking const kpRefMarking = &pSh->sRefMarking;
226 221
227 if ( kbIdrFlag ){222 if (kbIdrFlag) {
228 kpRefMarking->bNoOutputOfPriorPicsFlag = !!BsGetOneBit( pBs );223 kpRefMarking->bNoOutputOfPriorPicsFlag = !!BsGetOneBit (pBs);
229 kpRefMarking->bLongTermRefFlag = !!BsGetOneBit( pBs );224 kpRefMarking->bLongTermRefFlag = !!BsGetOneBit (pBs);
230 }225 } else {
231 else{226 kpRefMarking->bAdaptiveRefPicMarkingModeFlag = !!BsGetOneBit (pBs);
232 kpRefMarking->bAdaptiveRefPicMarkingModeFlag = !!BsGetOneBit( pBs );227 if (kpRefMarking->bAdaptiveRefPicMarkingModeFlag) {
233 if (kpRefMarking->bAdaptiveRefPicMarkingModeFlag){228 int32_t iIdx = 0;
234 int32_t iIdx = 0;229 do {
235 do {230 const int32_t kiMmco = BsGetUe (pBs);
236 const int32_t kiMmco = BsGetUe( pBs );231
237 232 kpRefMarking->sMmcoRef[iIdx].uiMmcoType = kiMmco;
238 kpRefMarking->sMmcoRef[iIdx].uiMmcoType = kiMmco;233 if (kiMmco == MMCO_END)
239 if (kiMmco == MMCO_END)234 break;
240 break;235
241 236 if (kiMmco == MMCO_SHORT2UNUSED || kiMmco == MMCO_SHORT2LONG) {
242 if (kiMmco == MMCO_SHORT2UNUSED || kiMmco == MMCO_SHORT2LONG)237 kpRefMarking->sMmcoRef[iIdx].iDiffOfPicNum = 1 + BsGetUe (pBs);
243 {238 kpRefMarking->sMmcoRef[iIdx].iShortFrameNum = (pSh->iFrameNum - kpRefMarking->sMmcoRef[iIdx].iDiffOfPicNum) & ((
244 kpRefMarking->sMmcoRef[iIdx].iDiffOfPicNum = 1 + BsGetUe( pBs );239 1 << pSps->uiLog2MaxFrameNum) - 1);
245 kpRefMarking->sMmcoRef[iIdx].iShortFrameNum = (pSh->iFrameNum - kpRefMarking->sMmcoRef[iIdx].iDiffOfPicNum) & ((1<<pSps->uiLog2MaxFrameNum)-1);240 } else if (kiMmco == MMCO_LONG2UNUSED)
246 }241 kpRefMarking->sMmcoRef[iIdx].uiLongTermPicNum = BsGetUe (pBs);
247 else if (kiMmco == MMCO_LONG2UNUSED)242
248 kpRefMarking->sMmcoRef[iIdx].uiLongTermPicNum = BsGetUe( pBs );243 if (kiMmco == MMCO_SHORT2LONG || kiMmco == MMCO_LONG) {
249 244 kpRefMarking->sMmcoRef[iIdx].iLongTermFrameIdx = BsGetUe (pBs);
250 if (kiMmco == MMCO_SHORT2LONG || kiMmco == MMCO_LONG)245 } else if (kiMmco == MMCO_SET_MAX_LONG)
251 {246 kpRefMarking->sMmcoRef[iIdx].iMaxLongTermFrameIdx = -1 + BsGetUe (pBs);
252 kpRefMarking->sMmcoRef[iIdx].iLongTermFrameIdx = BsGetUe( pBs );247 ++ iIdx;
253 }248
254 else if (kiMmco == MMCO_SET_MAX_LONG)249 } while (iIdx < MAX_MMCO_COUNT);
255 kpRefMarking->sMmcoRef[iIdx].iMaxLongTermFrameIdx = -1 + BsGetUe( pBs );250 }
256 ++ iIdx;251 }
257 252
258 } while(iIdx < MAX_MMCO_COUNT);253 return ERR_NONE;
259 }
260 }
261
262 return ERR_NONE;
263}254}
264 255
265bool_t FillDefaultSliceHeaderExt ( PSliceHeaderExt pShExt, PNalUnitHeaderExt pNalExt )256bool_t FillDefaultSliceHeaderExt (PSliceHeaderExt pShExt, PNalUnitHeaderExt pNalExt) {
266{257 if (pShExt == NULL || pNalExt == NULL)
267 if ( pShExt == NULL || pNalExt == NULL )258 return false;
268 return false;259
269 260 if (pNalExt->iNoInterLayerPredFlag || pNalExt->uiQualityId > 0)
270 if ( pNalExt->iNoInterLayerPredFlag || pNalExt->uiQualityId > 0 )261 pShExt->bBasePredWeightTableFlag = false;
271 pShExt->bBasePredWeightTableFlag = false;262 else
272 else263 pShExt->bBasePredWeightTableFlag = true;
273 pShExt->bBasePredWeightTableFlag = true;264 pShExt->uiRefLayerDqId = (uint8_t) - 1;
274 pShExt->uiRefLayerDqId = (uint8_t)-1;265 pShExt->uiDisableInterLayerDeblockingFilterIdc = 0;
275 pShExt->uiDisableInterLayerDeblockingFilterIdc = 0;266 pShExt->iInterLayerSliceAlphaC0Offset = 0;
276 pShExt->iInterLayerSliceAlphaC0Offset = 0;267 pShExt->iInterLayerSliceBetaOffset = 0;
277 pShExt->iInterLayerSliceBetaOffset = 0;268 pShExt->bConstrainedIntraResamplingFlag = false;
278 pShExt->bConstrainedIntraResamplingFlag = false;269 pShExt->uiRefLayerChromaPhaseXPlus1Flag = 0;
279 pShExt->uiRefLayerChromaPhaseXPlus1Flag = 0;270 pShExt->uiRefLayerChromaPhaseYPlus1 = 1;
280 pShExt->uiRefLayerChromaPhaseYPlus1 = 1;271 //memset(&pShExt->sScaledRefLayer, 0, sizeof(SPosOffset));
281 //memset(&pShExt->sScaledRefLayer, 0, sizeof(SPosOffset));272
282 273 pShExt->iScaledRefLayerPicWidthInSampleLuma = pShExt->sSliceHeader.iMbWidth << 4;
283 pShExt->iScaledRefLayerPicWidthInSampleLuma = pShExt->sSliceHeader.iMbWidth << 4;274 pShExt->iScaledRefLayerPicHeightInSampleLuma = pShExt->sSliceHeader.iMbHeight << 4;
284 pShExt->iScaledRefLayerPicHeightInSampleLuma = pShExt->sSliceHeader.iMbHeight << 4;275
285 276 pShExt->bSliceSkipFlag = false;
286 pShExt->bSliceSkipFlag = false;277 pShExt->bAdaptiveBaseModeFlag = false;
287 pShExt->bAdaptiveBaseModeFlag = false;278 pShExt->bDefaultBaseModeFlag = false;
288 pShExt->bDefaultBaseModeFlag = false;279 pShExt->bAdaptiveMotionPredFlag = false;
289 pShExt->bAdaptiveMotionPredFlag = false;280 pShExt->bDefaultMotionPredFlag = false;
290 pShExt->bDefaultMotionPredFlag = false;281 pShExt->bAdaptiveResidualPredFlag = false;
291 pShExt->bAdaptiveResidualPredFlag = false;282 pShExt->bDefaultResidualPredFlag = false;
292 pShExt->bDefaultResidualPredFlag = false;283 pShExt->bTCoeffLevelPredFlag = false;
293 pShExt->bTCoeffLevelPredFlag = false;284 pShExt->uiScanIdxStart = 0;
294 pShExt->uiScanIdxStart = 0;285 pShExt->uiScanIdxEnd = 15;
295 pShExt->uiScanIdxEnd = 15;286
296 287 return true;
297 return true;
298}288}
299 289
300/*290/*
@@ -305,58 +295,54 @@ bool_t FillDefaultSliceHeaderExt ( PSliceHeaderExt pShExt, PNalUnitHeaderExt pNa · 4 unmodified lines
305 * return:295 * return:
306 * 0 - success; otherwise returned error_no defined in error_no.h.296 * 0 - success; otherwise returned error_no defined in error_no.h.
307*/297*/
308int32_t WelsInitMemory( PWelsDecoderContext pCtx )298int32_t WelsInitMemory (PWelsDecoderContext pCtx) {
309{299 if (pCtx == NULL) {
310 if (pCtx == NULL){300 return ERR_INFO_INVALID_PTR;
311 return ERR_INFO_INVALID_PTR;301 }
312 }302
313 303 if (MemInitNalList (&pCtx->pAccessUnitList, MAX_NAL_UNIT_NUM_IN_AU) != 0)
314 if ( MemInitNalList( &pCtx->pAccessUnitList, MAX_NAL_UNIT_NUM_IN_AU ) != 0 )304 return ERR_INFO_OUT_OF_MEMORY;
315 return ERR_INFO_OUT_OF_MEMORY; 305
316 306 if ((pCtx->sRawData.pHead = static_cast<uint8_t*> (WelsMalloc (MAX_ACCESS_UINT_CAPACITY,
317 if ( ( pCtx->sRawData.pHead = static_cast<uint8_t*> (WelsMalloc( MAX_ACCESS_UINT_CAPACITY, "pCtx->sRawData->pHead" )) ) == NULL )307 "pCtx->sRawData->pHead"))) == NULL) {
318 {308 return ERR_INFO_OUT_OF_MEMORY;
319 return ERR_INFO_OUT_OF_MEMORY;309 }
320 }310 pCtx->sRawData.pStartPos =
321 pCtx->sRawData.pStartPos =311 pCtx->sRawData.pCurPos = pCtx->sRawData.pHead;
322 pCtx->sRawData.pCurPos = pCtx->sRawData.pHead;312 pCtx->sRawData.pEnd = pCtx->sRawData.pHead + MAX_ACCESS_UINT_CAPACITY;
323 pCtx->sRawData.pEnd = pCtx->sRawData.pHead + MAX_ACCESS_UINT_CAPACITY; 313
324 314 pCtx->uiTargetDqId = (uint8_t) - 1;
325 pCtx->uiTargetDqId = (uint8_t)-1;315 pCtx->bEndOfStreamFlag = false;
326 pCtx->bEndOfStreamFlag = false;316 pCtx->iImgWidthInPixel = 0;
327 pCtx->iImgWidthInPixel = 0;317 pCtx->iImgHeightInPixel = 0;
328 pCtx->iImgHeightInPixel = 0; 318
329 319 return ERR_NONE;
330 return ERR_NONE;
331}320}
332 321
333/*322/*
334 * WelsFreeMemory323 * WelsFreeMemory
335 * Free memory introduced in WelsInitMemory at destruction of decoder.324 * Free memory introduced in WelsInitMemory at destruction of decoder.
336 * 325 *
337 */326 */
338void_t WelsFreeMemory( PWelsDecoderContext pCtx )327void_t WelsFreeMemory (PWelsDecoderContext pCtx) {
339{328 if (pCtx == NULL)
340 if ( pCtx == NULL )329 return;
341 return;330
342 331 if (NULL != pCtx->pParam) {
343 if ( NULL != pCtx->pParam )332 WelsFree (pCtx->pParam, "pCtx->pParam");
344 {333
345 WelsFree( pCtx->pParam, "pCtx->pParam" );334 pCtx->pParam = NULL;
346 335 }
347 pCtx->pParam = NULL;336
348 }337 MemFreeNalList (&pCtx->pAccessUnitList);
349 338
350 MemFreeNalList( &pCtx->pAccessUnitList );339 if (pCtx->sRawData.pHead) {
351 340 WelsFree (pCtx->sRawData.pHead, "pCtx->sRawData->pHead");
352 if ( pCtx->sRawData.pHead )341 }
353 {342 pCtx->sRawData.pHead = NULL;
354 WelsFree(pCtx->sRawData.pHead, "pCtx->sRawData->pHead"); 343 pCtx->sRawData.pEnd = NULL;
355 }344 pCtx->sRawData.pStartPos = NULL;
356 pCtx->sRawData.pHead = NULL;345 pCtx->sRawData.pCurPos = NULL;
357 pCtx->sRawData.pEnd = NULL;
358 pCtx->sRawData.pStartPos = NULL;
359 pCtx->sRawData.pCurPos = NULL;
360}346}
361 347
362/*348/*
@@ -366,138 +352,117 @@ void_t WelsFreeMemory( PWelsDecoderContext pCtx ) · 3 unmodified lines
366 * pNal: target NALUnit ptr352 * pNal: target NALUnit ptr
367 * pSrc: NAL Unit bitstream353 * pSrc: NAL Unit bitstream
368 */354 */
369void_t DecodeNalHeaderExt( PNalUnit pNal, uint8_t* pSrc )355void_t DecodeNalHeaderExt (PNalUnit pNal, uint8_t* pSrc) {
370{356 PNalUnitHeaderExt pHeaderExt = &pNal->sNalHeaderExt;
371 PNalUnitHeaderExt pHeaderExt = &pNal->sNalHeaderExt; 357
372 358 uint8_t uiCurByte = *pSrc;
373 uint8_t uiCurByte = *pSrc; 359 pHeaderExt->bIdrFlag = !! (uiCurByte & 0x40);
374 pHeaderExt->bIdrFlag = !!(uiCurByte & 0x40);360 pHeaderExt->uiPriorityId = uiCurByte & 0x3F;
375 pHeaderExt->uiPriorityId = uiCurByte & 0x3F;361
376 362 uiCurByte = * (++pSrc);
377 uiCurByte = *(++pSrc);363 pHeaderExt->iNoInterLayerPredFlag = uiCurByte >> 7;
378 pHeaderExt->iNoInterLayerPredFlag = uiCurByte >> 7;364 pHeaderExt->uiDependencyId = (uiCurByte & 0x70) >> 4;
379 pHeaderExt->uiDependencyId = (uiCurByte & 0x70) >> 4;365 pHeaderExt->uiQualityId = uiCurByte & 0x0F;
380 pHeaderExt->uiQualityId = uiCurByte & 0x0F;366 uiCurByte = * (++pSrc);
381 uiCurByte = *(++pSrc);367 pHeaderExt->uiTemporalId = uiCurByte >> 5;
382 pHeaderExt->uiTemporalId = uiCurByte >> 5;368 pHeaderExt->bUseRefBasePicFlag = !! (uiCurByte & 0x10);
383 pHeaderExt->bUseRefBasePicFlag = !!(uiCurByte & 0x10);369 pHeaderExt->bDiscardableFlag = !! (uiCurByte & 0x08);
384 pHeaderExt->bDiscardableFlag = !!(uiCurByte & 0x08);370 pHeaderExt->bOutputFlag = !! (uiCurByte & 0x04);
385 pHeaderExt->bOutputFlag = !!(uiCurByte & 0x04);371 pHeaderExt->uiReservedThree2Bits = uiCurByte & 0x03;
386 pHeaderExt->uiReservedThree2Bits = uiCurByte & 0x03; 372 pHeaderExt->uiLayerDqId = (pHeaderExt->uiDependencyId << 4) | pHeaderExt->uiQualityId;
387 pHeaderExt->uiLayerDqId = (pHeaderExt->uiDependencyId << 4) | pHeaderExt->uiQualityId;
388}373}
389 374
390 375
391#ifdef MOSAIC_AVOID_BASED_ON_SPS_PPS_ID376#ifdef MOSAIC_AVOID_BASED_ON_SPS_PPS_ID
392int32_t CheckPpsId( PWelsDecoderContext pCtx, PPps* ppPps, uint32_t uiPpsId )377int32_t CheckPpsId (PWelsDecoderContext pCtx, PPps* ppPps, uint32_t uiPpsId) {
393{378 PPps pPpsList = pCtx->sPpsBuffer;
394 PPps pPpsList = pCtx->sPpsBuffer;379 int32_t iPpsNum = pCtx->iPpsTotalNum;
395 int32_t iPpsNum = pCtx->iPpsTotalNum;380 int32_t i = 0;
396 int32_t i = 0;381
397 382 if (iPpsNum <= 0) {
398 if ( iPpsNum <= 0 )383 pCtx->iErrorCode |= dsNoParamSets;
399 {384
400 pCtx->iErrorCode |= dsNoParamSets;385 WelsLog (pCtx, WELS_LOG_WARNING, "CheckPpsId():::::PPS list is empty...NO PPS!!!\n");
401 386 return dsNoParamSets;
402 WelsLog( pCtx, WELS_LOG_WARNING, "CheckPpsId():::::PPS list is empty...NO PPS!!!\n" );387 }
403 return dsNoParamSets;388
404 }389 while (i < iPpsNum) {
405 390 if (uiPpsId == pPpsList[i].iPpsId) {
406 while ( i < iPpsNum )391 *ppPps = &pPpsList[i];
407 {392 break;
408 if ( uiPpsId == pPpsList[i].iPpsId )393 } else {
409 {394 ++i;
410 *ppPps = &pPpsList[i];395 }
411 break;396 }
412 }397
413 else398 if (i == iPpsNum) {
414 {399 pCtx->iErrorCode |= dsNoParamSets;
415 ++i;400
416 }401 WelsLog (pCtx, WELS_LOG_WARNING, "CheckPpsId()::::::CAN NOT find the matching from the PPS List. iPpsId:%d\n",
417 }402 uiPpsId);
418 403 return dsNoParamSets;
419 if ( i == iPpsNum )404 }
420 {405
421 pCtx->iErrorCode |= dsNoParamSets;406 return 0;
422
423 WelsLog( pCtx, WELS_LOG_WARNING, "CheckPpsId()::::::CAN NOT find the matching from the PPS List. iPpsId:%d\n", uiPpsId );
424 return dsNoParamSets;
425 }
426
427 return 0;
428}407}
429 408
430int32_t CheckSpsId( PWelsDecoderContext pCtx, PSubsetSps* ppSubsetSps, PSps* ppSps, int32_t iSpsId, bool_t bExtensionFlag )409int32_t CheckSpsId (PWelsDecoderContext pCtx, PSubsetSps* ppSubsetSps, PSps* ppSps, int32_t iSpsId,
431{410 bool_t bExtensionFlag) {
432 PSps pSpsList = pCtx->sSpsBuffer;411 PSps pSpsList = pCtx->sSpsBuffer;
433 PSubsetSps pSubspsList = pCtx->sSubsetSpsBuffer;412 PSubsetSps pSubspsList = pCtx->sSubsetSpsBuffer;
434 413
435 int32_t iSpsNum = pCtx->iSpsTotalNum;414 int32_t iSpsNum = pCtx->iSpsTotalNum;
436 int32_t iSubspsNum = pCtx->iSubspsTotalNum;415 int32_t iSubspsNum = pCtx->iSubspsTotalNum;
437 int32_t i = 0;416 int32_t i = 0;
438 417
439 if ( bExtensionFlag )418 if (bExtensionFlag) {
440 {419 if (iSubspsNum <= 0) {
441 if ( iSubspsNum <= 0 )420 pCtx->iErrorCode |= dsNoParamSets;
442 {421
443 pCtx->iErrorCode |= dsNoParamSets;422 WelsLog (pCtx, WELS_LOG_WARNING, "CheckSpsId()::::SUBSPS list is empty....NO SUBSPS\n");
444 423 return dsNoParamSets;
445 WelsLog( pCtx, WELS_LOG_WARNING, "CheckSpsId()::::SUBSPS list is empty....NO SUBSPS\n" );424 }
446 return dsNoParamSets;425 while (i < iSubspsNum) {
447 }426 if (iSpsId == pSubspsList[i].sSps.iSpsId) {
448 while ( i < iSubspsNum )427 *ppSubsetSps = &pSubspsList[i];
449 {428 *ppSps = &pSubspsList[i].sSps;
450 if ( iSpsId == pSubspsList[i].sSps.iSpsId )429 break;
451 {430 } else {
452 *ppSubsetSps = &pSubspsList[i];431 ++i;
453 *ppSps = &pSubspsList[i].sSps;432 }
454 break;433 }
455 }434 if (i == iSubspsNum) {
456 else435 pCtx->iErrorCode |= dsNoParamSets;
457 {436
458 ++i;437 WelsLog (pCtx, WELS_LOG_WARNING, "CheckSpsId()::::::CAN NOT find the matching from the SUBSPS List. iSpsId:%d\n",
459 }438 iSpsId);
460 }439 return dsNoParamSets;
461 if ( i == iSubspsNum )440 }
462 {441 } else {
463 pCtx->iErrorCode |= dsNoParamSets;442 if (iSpsNum <= 0) {
464 443 pCtx->iErrorCode |= dsNoParamSets;
465 WelsLog( pCtx, WELS_LOG_WARNING, "CheckSpsId()::::::CAN NOT find the matching from the SUBSPS List. iSpsId:%d\n", iSpsId );444
466 return dsNoParamSets;445 WelsLog (pCtx, WELS_LOG_WARNING, "CheckSpsId()::::SPS list is empty....NO SPS\n");
467 }446 return dsNoParamSets;
468 }447 }
469 else448 while (i < iSpsNum) {
470 {449 if (iSpsId == pSpsList[i].iSpsId) {
471 if ( iSpsNum <= 0 )450 *ppSubsetSps = NULL;
472 {451 *ppSps = &pSpsList[i];
473 pCtx->iErrorCode |= dsNoParamSets;452 break;
474 453 } else {
475 WelsLog( pCtx, WELS_LOG_WARNING, "CheckSpsId()::::SPS list is empty....NO SPS\n" );454 ++i;
476 return dsNoParamSets;455 }
477 }456 }
478 while ( i < iSpsNum )457 if (i == iSpsNum) {
479 {458 pCtx->iErrorCode |= dsNoParamSets;
480 if ( iSpsId == pSpsList[i].iSpsId )459
481 {460 WelsLog (pCtx, WELS_LOG_WARNING, "CheckSpsId()::::::CAN NOT find the matching from the SPS List. iSpsId:%d\n", iSpsId);
482 *ppSubsetSps = NULL;461 return dsNoParamSets;
483 *ppSps = &pSpsList[i];462 }
484 break;463 }
485 }464
486 else465 return 0;
487 {
488 ++i;
489 }
490 }
491 if ( i == iSpsNum )
492 {
493 pCtx->iErrorCode |= dsNoParamSets;
494
495 WelsLog( pCtx, WELS_LOG_WARNING, "CheckSpsId()::::::CAN NOT find the matching from the SPS List. iSpsId:%d\n", iSpsId );
496 return dsNoParamSets;
497 }
498 }
499
500 return 0;
501}466}
502 467
503#endif468#endif
@@ -505,384 +470,371 @@ int32_t CheckSpsId( PWelsDecoderContext pCtx, PSubsetSps* ppSubsetSps, PSps* ppS · 1 unmodified line
505 * decode_slice_header_avc470 * decode_slice_header_avc
506 * Parse slice header of bitstream in avc for storing data structure471 * Parse slice header of bitstream in avc for storing data structure
507 */472 */
508int32_t ParseSliceHeaderSyntaxs ( PWelsDecoderContext pCtx, PBitStringAux pBs, const bool_t kbExtensionFlag )473int32_t ParseSliceHeaderSyntaxs (PWelsDecoderContext pCtx, PBitStringAux pBs, const bool_t kbExtensionFlag) {
509{474 PNalUnit const kpCurNal = pCtx->pAccessUnitList->pNalUnitsList[pCtx->pAccessUnitList->uiAvailUnitsNum - 1];
510 PNalUnit const kpCurNal = pCtx->pAccessUnitList->pNalUnitsList[pCtx->pAccessUnitList->uiAvailUnitsNum-1];475
511 476 PNalUnitHeaderExt pNalHeaderExt = NULL;
512 PNalUnitHeaderExt pNalHeaderExt = NULL;477 PSliceHeader pSliceHead = NULL;
513 PSliceHeader pSliceHead = NULL;478 PSliceHeaderExt pSliceHeadExt = NULL;
514 PSliceHeaderExt pSliceHeadExt = NULL;479 PSubsetSps pSubsetSps = NULL;
515 PSubsetSps pSubsetSps = NULL;480 PSps pSps = NULL;
516 PSps pSps = NULL;481 PPps pPps = NULL;
517 PPps pPps = NULL;482 ENalUnitType eNalType = static_cast<ENalUnitType> (0);
518 ENalUnitType eNalType = static_cast<ENalUnitType> (0);483 int32_t iPpsId = 0;
519 int32_t iPpsId = 0;484 int32_t iRet = ERR_NONE;
520 int32_t iRet = ERR_NONE;485 uint8_t uiSliceType = 0;
521 uint8_t uiSliceType = 0;486 uint8_t uiQualityId = BASE_QUALITY_ID;
522 uint8_t uiQualityId = BASE_QUALITY_ID;487 bool_t bIdrFlag = false;
523 bool_t bIdrFlag = false;488 bool_t bSgChangeCycleInvolved = false; // involved slice group change cycle ?
524 bool_t bSgChangeCycleInvolved = false; // involved slice group change cycle ?489
525 490 if (kpCurNal == NULL) {
526 if (kpCurNal == NULL)491 return ERR_INFO_OUT_OF_MEMORY;
527 { 492 }
528 return ERR_INFO_OUT_OF_MEMORY;493
529 }494 pNalHeaderExt = &kpCurNal->sNalHeaderExt;
530 495 pSliceHead = &kpCurNal->sNalData.sVclNal.sSliceHeaderExt.sSliceHeader;
531 pNalHeaderExt = &kpCurNal->sNalHeaderExt;496 eNalType = pNalHeaderExt->sNalUnitHeader.eNalUnitType;
532 pSliceHead = &kpCurNal->sNalData.sVclNal.sSliceHeaderExt.sSliceHeader;497
533 eNalType = pNalHeaderExt->sNalUnitHeader.eNalUnitType;498 pSliceHeadExt = &kpCurNal->sNalData.sVclNal.sSliceHeaderExt;
534 499
535 pSliceHeadExt = &kpCurNal->sNalData.sVclNal.sSliceHeaderExt;500 if (pSliceHeadExt) {
536 501 SRefBasePicMarking sBaseMarking;
537 if ( pSliceHeadExt ){502 const bool_t kbStoreRefBaseFlag = pSliceHeadExt->bStoreRefBasePicFlag;
538 SRefBasePicMarking sBaseMarking;503 memcpy (&sBaseMarking, &pSliceHeadExt->sRefBasePicMarking, sizeof (SRefBasePicMarking)); //confirmed_safe_unsafe_usage
539 const bool_t kbStoreRefBaseFlag = pSliceHeadExt->bStoreRefBasePicFlag;504 memset (pSliceHeadExt, 0, sizeof (SSliceHeaderExt));
540 memcpy(&sBaseMarking, &pSliceHeadExt->sRefBasePicMarking, sizeof(SRefBasePicMarking));//confirmed_safe_unsafe_usage505 pSliceHeadExt->bStoreRefBasePicFlag = kbStoreRefBaseFlag;
541 memset(pSliceHeadExt, 0, sizeof(SSliceHeaderExt));506 memcpy (&pSliceHeadExt->sRefBasePicMarking, &sBaseMarking, sizeof (SRefBasePicMarking)); //confirmed_safe_unsafe_usage
542 pSliceHeadExt->bStoreRefBasePicFlag = kbStoreRefBaseFlag;507 }
543 memcpy(&pSliceHeadExt->sRefBasePicMarking, &sBaseMarking, sizeof(SRefBasePicMarking));//confirmed_safe_unsafe_usage508
544 }509 kpCurNal->sNalData.sVclNal.bSliceHeaderExtFlag = kbExtensionFlag;
545 510
546 kpCurNal->sNalData.sVclNal.bSliceHeaderExtFlag = kbExtensionFlag;511 pSliceHead->iFirstMbInSlice = BsGetUe (pBs);
547 512
548 pSliceHead->iFirstMbInSlice = BsGetUe( pBs );513 uiSliceType = BsGetUe (pBs);
549 514 if (uiSliceType > 9) {
550 uiSliceType= BsGetUe( pBs );515 WelsLog (pCtx, WELS_LOG_WARNING, "slice type too large (%d) at first_mb(%d)\n", uiSliceType,
551 if(uiSliceType > 9)516 pSliceHead->iFirstMbInSlice);
552 {517 return GENERATE_ERROR_NO (ERR_LEVEL_SLICE_HEADER, ERR_INFO_INVALID_SLICE_TYPE);
553 WelsLog( pCtx, WELS_LOG_WARNING, "slice type too large (%d) at first_mb(%d)\n", uiSliceType, pSliceHead->iFirstMbInSlice);518 }
554 return GENERATE_ERROR_NO(ERR_LEVEL_SLICE_HEADER, ERR_INFO_INVALID_SLICE_TYPE);519 if (uiSliceType > 4)
555 }520 uiSliceType -= 5;
556 if(uiSliceType > 4)521
557 uiSliceType -= 5;522 if (kbExtensionFlag) {
558 523 if (uiSliceType > 2) {
559 if ( kbExtensionFlag ){ 524 WelsLog (pCtx, WELS_LOG_WARNING, "Invalid slice type(%d).\n", uiSliceType);
560 if (uiSliceType > 2){525 return GENERATE_ERROR_NO (ERR_LEVEL_SLICE_HEADER, ERR_INFO_INVALID_SLICE_TYPE);
561 WelsLog( pCtx, WELS_LOG_WARNING, "Invalid slice type(%d).\n", uiSliceType);
562 return GENERATE_ERROR_NO(ERR_LEVEL_SLICE_HEADER, ERR_INFO_INVALID_SLICE_TYPE);
563 }
564 }
565
566 pSliceHead->eSliceType = static_cast <ESliceType> (uiSliceType);
567
568 iPpsId= BsGetUe( pBs );
569
570 if(iPpsId >= MAX_PPS_COUNT){
571 WelsLog( pCtx, WELS_LOG_WARNING, "iPpsId out of range\n");
572 return GENERATE_ERROR_NO(ERR_LEVEL_SLICE_HEADER, ERR_INFO_PPS_ID_OVERFLOW);
573 }526 }
527 }
528
529 pSliceHead->eSliceType = static_cast <ESliceType> (uiSliceType);
530
531 iPpsId = BsGetUe (pBs);
532
533 if (iPpsId >= MAX_PPS_COUNT) {
534 WelsLog (pCtx, WELS_LOG_WARNING, "iPpsId out of range\n");
535 return GENERATE_ERROR_NO (ERR_LEVEL_SLICE_HEADER, ERR_INFO_PPS_ID_OVERFLOW);
536 }
574 537
575#ifdef MOSAIC_AVOID_BASED_ON_SPS_PPS_ID538#ifdef MOSAIC_AVOID_BASED_ON_SPS_PPS_ID
576 if ( CheckPpsId( pCtx, &pPps, iPpsId ) )539 if (CheckPpsId (pCtx, &pPps, iPpsId)) {
577 {540 return dsNoParamSets;
578 return dsNoParamSets;541 }
579 }
580#else542#else
581 pPps = &pCtx->sPpsBuffer[iPpsId];543 pPps = &pCtx->sPpsBuffer[iPpsId];
582#endif //MOSAIC_AVOID_BASED_ON_SPS_PPS_ID544#endif //MOSAIC_AVOID_BASED_ON_SPS_PPS_ID
583 545
584 if (pPps->uiNumSliceGroups == 0){546 if (pPps->uiNumSliceGroups == 0) {
585 WelsLog( pCtx, WELS_LOG_WARNING, "non existing PPS referenced\n");547 WelsLog (pCtx, WELS_LOG_WARNING, "non existing PPS referenced\n");
586 return GENERATE_ERROR_NO(ERR_LEVEL_SLICE_HEADER, ERR_INFO_NO_PARAM_SETS);548 return GENERATE_ERROR_NO (ERR_LEVEL_SLICE_HEADER, ERR_INFO_NO_PARAM_SETS);
587 }549 }
550
551 if (pPps->iSpsId >= MAX_SPS_COUNT) {
552 WelsLog (pCtx, WELS_LOG_WARNING, "iSpsId out of range\n");
553 return GENERATE_ERROR_NO (ERR_LEVEL_SLICE_HEADER, ERR_INFO_SPS_ID_OVERFLOW);
554 }
588 555
589 if (pPps->iSpsId >= MAX_SPS_COUNT){
590 WelsLog( pCtx, WELS_LOG_WARNING, "iSpsId out of range\n");
591 return GENERATE_ERROR_NO(ERR_LEVEL_SLICE_HEADER, ERR_INFO_SPS_ID_OVERFLOW);
592 }
593 556
594
595#ifdef MOSAIC_AVOID_BASED_ON_SPS_PPS_ID557#ifdef MOSAIC_AVOID_BASED_ON_SPS_PPS_ID
596 if ( CheckSpsId( pCtx, &pSubsetSps, &pSps, pPps->iSpsId, kExtensionFlag ) )558 if (CheckSpsId (pCtx, &pSubsetSps, &pSps, pPps->iSpsId, kExtensionFlag)) {
597 {559 return dsNoParamSets;
598 return dsNoParamSets;560 }
599 }561#else
600#else 562 if (kbExtensionFlag) {
601 if ( kbExtensionFlag )563 pSubsetSps = &pCtx->sSubsetSpsBuffer[pPps->iSpsId];
602 {564 pSps = &pSubsetSps->sSps;
603 pSubsetSps = &pCtx->sSubsetSpsBuffer[pPps->iSpsId];565 } else {
604 pSps = &pSubsetSps->sSps;566 pSps = &pCtx->sSpsBuffer[pPps->iSpsId];
605 }567 }
606 else568 pCtx->pSps = pSps;
607 {
608 pSps = &pCtx->sSpsBuffer[pPps->iSpsId];
609 }
610 pCtx->pSps = pSps;
611#endif //MOSAIC_AVOID_BASED_ON_SPS_PPS_ID569#endif //MOSAIC_AVOID_BASED_ON_SPS_PPS_ID
612 pSliceHead->iPpsId = iPpsId;570 pSliceHead->iPpsId = iPpsId;
613 pSliceHead->iSpsId = pPps->iSpsId; 571 pSliceHead->iSpsId = pPps->iSpsId;
614 pSliceHead->pPps = pPps;572 pSliceHead->pPps = pPps;
615 pSliceHead->pSps = pSps;573 pSliceHead->pSps = pSps;
616 574
617 pSliceHeadExt->pSubsetSps = pSubsetSps;575 pSliceHeadExt->pSubsetSps = pSubsetSps;
618 576
619 bIdrFlag = (!kbExtensionFlag && eNalType == NAL_UNIT_CODED_SLICE_IDR) || (kbExtensionFlag && pNalHeaderExt->bIdrFlag);577 bIdrFlag = (!kbExtensionFlag && eNalType == NAL_UNIT_CODED_SLICE_IDR) || (kbExtensionFlag && pNalHeaderExt->bIdrFlag);
620 578
621 if(pSps->uiLog2MaxFrameNum == 0){579 if (pSps->uiLog2MaxFrameNum == 0) {
622 WelsLog( pCtx, WELS_LOG_WARNING, "non existing SPS referenced\n");580 WelsLog (pCtx, WELS_LOG_WARNING, "non existing SPS referenced\n");
623 return GENERATE_ERROR_NO(ERR_LEVEL_SLICE_HEADER, ERR_INFO_NO_PARAM_SETS);581 return GENERATE_ERROR_NO (ERR_LEVEL_SLICE_HEADER, ERR_INFO_NO_PARAM_SETS);
582 }
583 pSliceHead->iFrameNum = BsGetBits (pBs, pSps->uiLog2MaxFrameNum);
584
585 pSliceHead->bFieldPicFlag = false;
586 pSliceHead->bBottomFiledFlag = false;
587 if (!pSps->bFrameMbsOnlyFlag) {
588 WelsLog (pCtx, WELS_LOG_WARNING, "ParseSliceHeaderSyntaxs(): frame_mbs_only_flag = %d not supported. \n",
589 pSps->bFrameMbsOnlyFlag);
590 return GENERATE_ERROR_NO (ERR_LEVEL_SLICE_HEADER, ERR_INFO_UNSUPPORTED_MBAFF);
591 }
592 pSliceHead->iMbWidth = pSps->iMbWidth;
593 pSliceHead->iMbHeight = pSps->iMbHeight / (1 + pSliceHead->bFieldPicFlag);
594
595 if (bIdrFlag) {
596 if (pSliceHead->iFrameNum != 0) {
597 WelsLog (pCtx, WELS_LOG_WARNING, "ParseSliceHeaderSyntaxs(), invaild frame number: %d due to IDR frame introduced!\n",
598 pSliceHead->iFrameNum);
599 return GENERATE_ERROR_NO (ERR_LEVEL_SLICE_HEADER, ERR_INFO_INVALID_FRAME_NUM);
624 }600 }
625 pSliceHead->iFrameNum = BsGetBits(pBs, pSps->uiLog2MaxFrameNum); 601 pSliceHead->uiIdrPicId = BsGetUe (pBs); /* uiIdrPicId */
626
627 pSliceHead->bFieldPicFlag = false;
628 pSliceHead->bBottomFiledFlag = false;
629 if( !pSps->bFrameMbsOnlyFlag ){
630 WelsLog( pCtx, WELS_LOG_WARNING, "ParseSliceHeaderSyntaxs(): frame_mbs_only_flag = %d not supported. \n", pSps->bFrameMbsOnlyFlag );
631 return GENERATE_ERROR_NO(ERR_LEVEL_SLICE_HEADER, ERR_INFO_UNSUPPORTED_MBAFF);
632 }
633 pSliceHead->iMbWidth = pSps->iMbWidth;
634 pSliceHead->iMbHeight = pSps->iMbHeight / (1 + pSliceHead->bFieldPicFlag);
635
636 if ( bIdrFlag ){
637 if ( pSliceHead->iFrameNum != 0 ){
638 WelsLog( pCtx, WELS_LOG_WARNING, "ParseSliceHeaderSyntaxs(), invaild frame number: %d due to IDR frame introduced!\n", pSliceHead->iFrameNum);
639 return GENERATE_ERROR_NO(ERR_LEVEL_SLICE_HEADER, ERR_INFO_INVALID_FRAME_NUM);
640 }
641 pSliceHead->uiIdrPicId = BsGetUe(pBs); /* uiIdrPicId */
642#ifdef LONG_TERM_REF602#ifdef LONG_TERM_REF
643 pCtx->uiCurIdrPicId = pSliceHead->uiIdrPicId;603 pCtx->uiCurIdrPicId = pSliceHead->uiIdrPicId;
644#endif604#endif
645 }605 }
646 606
647 pSliceHead->iDeltaPicOrderCntBottom = 0;607 pSliceHead->iDeltaPicOrderCntBottom = 0;
648 pSliceHead->iDeltaPicOrderCnt[0] =608 pSliceHead->iDeltaPicOrderCnt[0] =
649 pSliceHead->iDeltaPicOrderCnt[1] = 0;609 pSliceHead->iDeltaPicOrderCnt[1] = 0;
650 if(pSps->uiPocType == 0){610 if (pSps->uiPocType == 0) {
651 pSliceHead->iPicOrderCntLsb = BsGetBits(pBs, pSps->iLog2MaxPocLsb); 611 pSliceHead->iPicOrderCntLsb = BsGetBits (pBs, pSps->iLog2MaxPocLsb);
652 if( pPps->bPicOrderPresentFlag && !pSliceHead->bFieldPicFlag ){612 if (pPps->bPicOrderPresentFlag && !pSliceHead->bFieldPicFlag) {
653 pSliceHead->iDeltaPicOrderCntBottom = BsGetSe(pBs);613 pSliceHead->iDeltaPicOrderCntBottom = BsGetSe (pBs);
654 }614 }
655 }615 } else if (pSps->uiPocType == 1 && !pSps->bDeltaPicOrderAlwaysZeroFlag) {
656 else if(pSps->uiPocType == 1 && !pSps->bDeltaPicOrderAlwaysZeroFlag ){616 pSliceHead->iDeltaPicOrderCnt[0] = BsGetSe (pBs);
657 pSliceHead->iDeltaPicOrderCnt[0] = BsGetSe(pBs);617 if (pPps->bPicOrderPresentFlag && !pSliceHead->bFieldPicFlag)
658 if( pPps->bPicOrderPresentFlag && !pSliceHead->bFieldPicFlag )618 pSliceHead->iDeltaPicOrderCnt[1] = BsGetSe (pBs);
659 pSliceHead->iDeltaPicOrderCnt[1]= BsGetSe(pBs);619 }
660 }620
661 621 pSliceHead->iRedundantPicCnt = 0;
662 pSliceHead->iRedundantPicCnt = 0;622 if (pPps->bRedundantPicCntPresentFlag) {
663 if( pPps->bRedundantPicCntPresentFlag ){623 pSliceHead->iRedundantPicCnt = BsGetUe (pBs);
664 pSliceHead->iRedundantPicCnt = BsGetUe(pBs);624 }
665 }625
666 626 //set defaults, might be overriden a few line later
667 //set defaults, might be overriden a few line later627 pSliceHead->uiRefCount[0] = pPps->uiNumRefIdxL0Active;
668 pSliceHead->uiRefCount[0] = pPps->uiNumRefIdxL0Active;628 pSliceHead->uiRefCount[1] = pPps->uiNumRefIdxL1Active;
669 pSliceHead->uiRefCount[1] = pPps->uiNumRefIdxL1Active;629 if (kbExtensionFlag) {
670 if ( kbExtensionFlag ){630 uiQualityId = pNalHeaderExt->uiQualityId;
671 uiQualityId = pNalHeaderExt->uiQualityId;631 if (BASE_QUALITY_ID == uiQualityId && (EP_SLICE == uiSliceType || EB_SLICE == uiSliceType)) {
672 if ( BASE_QUALITY_ID == uiQualityId && (EP_SLICE == uiSliceType || EB_SLICE == uiSliceType) ){632 const bool_t kbBipredFlag = (EB_SLICE == uiSliceType);
673 const bool_t kbBipredFlag = (EB_SLICE == uiSliceType);633 if (kbBipredFlag) {
674 if ( kbBipredFlag )634 WelsLog (pCtx, WELS_LOG_WARNING, "ParseSliceHeaderSyntaxs(): kbBipredFlag = 1 not supported.\n");
675 {635 return GENERATE_ERROR_NO (ERR_LEVEL_SLICE_HEADER, ERR_INFO_UNSUPPORTED_BIPRED);
676 WelsLog ( pCtx, WELS_LOG_WARNING, "ParseSliceHeaderSyntaxs(): kbBipredFlag = 1 not supported.\n");636 }
677 return GENERATE_ERROR_NO(ERR_LEVEL_SLICE_HEADER, ERR_INFO_UNSUPPORTED_BIPRED);637 pSliceHead->bNumRefIdxActiveOverrideFlag = !!BsGetOneBit (pBs);
678 }638 if (pSliceHead->bNumRefIdxActiveOverrideFlag) {
679 pSliceHead->bNumRefIdxActiveOverrideFlag = !!BsGetOneBit(pBs);639 pSliceHead->uiRefCount[0] = 1 + BsGetUe (pBs);
680 if ( pSliceHead->bNumRefIdxActiveOverrideFlag ){640 }
681 pSliceHead->uiRefCount[0] = 1 + BsGetUe(pBs);641 }
682 }642 } else if (uiSliceType == P_SLICE || uiSliceType == SP_SLICE || uiSliceType == B_SLICE) {
683 }643 const bool_t kbBipredFlag = (B_SLICE == uiSliceType);
684 }644 if (kbBipredFlag) {
685 else if(uiSliceType == P_SLICE || uiSliceType == SP_SLICE || uiSliceType == B_SLICE){645 WelsLog (pCtx, WELS_LOG_WARNING, "ParseSliceHeaderSyntaxs(): kbBipredFlag = 1 not supported.\n");
686 const bool_t kbBipredFlag = (B_SLICE == uiSliceType);646 return GENERATE_ERROR_NO (ERR_LEVEL_SLICE_HEADER, ERR_INFO_UNSUPPORTED_BIPRED);
687 if( kbBipredFlag ){647 }
688 WelsLog ( pCtx, WELS_LOG_WARNING, "ParseSliceHeaderSyntaxs(): kbBipredFlag = 1 not supported.\n");648 pSliceHead->bNumRefIdxActiveOverrideFlag = !!BsGetOneBit (pBs);
689 return GENERATE_ERROR_NO(ERR_LEVEL_SLICE_HEADER, ERR_INFO_UNSUPPORTED_BIPRED);649 if (pSliceHead->bNumRefIdxActiveOverrideFlag) {
690 }650 pSliceHead->uiRefCount[0] = 1 + BsGetUe (pBs);
691 pSliceHead->bNumRefIdxActiveOverrideFlag = !!BsGetOneBit(pBs);651 }
692 if( pSliceHead->bNumRefIdxActiveOverrideFlag ){652 }
693 pSliceHead->uiRefCount[0] = 1 + BsGetUe(pBs);653
694 }654 if (pSliceHead->uiRefCount[0] > MAX_REF_PIC_COUNT || pSliceHead->uiRefCount[1] > MAX_REF_PIC_COUNT) {
655 WelsLog (pCtx, WELS_LOG_WARNING, "reference overflow\n");
656 return GENERATE_ERROR_NO (ERR_LEVEL_SLICE_HEADER, ERR_INFO_REF_COUNT_OVERFLOW);
657 }
658
659 if (BASE_QUALITY_ID == uiQualityId) {
660 iRet = ParseRefPicListReordering (pBs, pSliceHead);
661 if (iRet != ERR_NONE) {
662 WelsLog (pCtx, WELS_LOG_WARNING, "invalid ref pPic list reordering syntaxs!\n");
663 return iRet;
695 }664 }
696 665
697 if( pSliceHead->uiRefCount[0] > MAX_REF_PIC_COUNT || pSliceHead->uiRefCount[1] > MAX_REF_PIC_COUNT){666 if (kbExtensionFlag) {
698 WelsLog( pCtx, WELS_LOG_WARNING, "reference overflow\n");667 if (pNalHeaderExt->iNoInterLayerPredFlag || pNalHeaderExt->uiQualityId > 0)
699 return GENERATE_ERROR_NO(ERR_LEVEL_SLICE_HEADER, ERR_INFO_REF_COUNT_OVERFLOW);668 pSliceHeadExt->bBasePredWeightTableFlag = false;
700 }669 else
701 670 pSliceHeadExt->bBasePredWeightTableFlag = true;
702 if ( BASE_QUALITY_ID == uiQualityId ){
703 iRet = ParseRefPicListReordering(pBs, pSliceHead);
704 if (iRet != ERR_NONE){
705 WelsLog( pCtx, WELS_LOG_WARNING, "invalid ref pPic list reordering syntaxs!\n");
706 return iRet;
707 }
708
709 if ( kbExtensionFlag ){
710 if ( pNalHeaderExt->iNoInterLayerPredFlag || pNalHeaderExt->uiQualityId > 0 )
711 pSliceHeadExt->bBasePredWeightTableFlag = false;
712 else
713 pSliceHeadExt->bBasePredWeightTableFlag = true;
714 }
715
716 if( kpCurNal->sNalHeaderExt.sNalUnitHeader.uiNalRefIdc != 0 ){
717 iRet = ParseDecRefPicMarking(pCtx, pBs, pSliceHead, pSps, bIdrFlag );
718 if (iRet != ERR_NONE){
719 return iRet;
720 }
721
722 if ( kbExtensionFlag && !pSubsetSps->sSpsSvcExt.bSliceHeaderRestrictionFlag ){
723 pSliceHeadExt->bStoreRefBasePicFlag = !!BsGetOneBit(pBs);
724 if ( (pNalHeaderExt->bUseRefBasePicFlag || pSliceHeadExt->bStoreRefBasePicFlag) && !bIdrFlag ){
725 WelsLog( pCtx, WELS_LOG_WARNING, "ParseSliceHeaderSyntaxs(): bUseRefBasePicFlag or bStoreRefBasePicFlag = 1 not supported.\n" );
726 return GENERATE_ERROR_NO(ERR_LEVEL_SLICE_HEADER, ERR_INFO_UNSUPPORTED_ILP);
727 }
728 }
729 }
730 }
731
732 if ( pPps->bEntropyCodingModeFlag ){
733 WelsLog( pCtx, WELS_LOG_WARNING, "ParseSliceHeaderSyntaxs(): CABAC in Enhancement layer not supported.\n" );
734 return GENERATE_ERROR_NO(ERR_LEVEL_SLICE_HEADER, ERR_INFO_UNSUPPORTED_CABAC_EL);
735 }
736
737 pSliceHead->iSliceQpDelta = BsGetSe(pBs);
738 pSliceHead->iSliceQp = pPps->iPicInitQp + pSliceHead->iSliceQpDelta;
739 if( pSliceHead->iSliceQp < 0 || pSliceHead->iSliceQp > 51 ){
740 WelsLog( pCtx, WELS_LOG_WARNING, "QP %d out of range\n", pSliceHead->iSliceQp);
741 return GENERATE_ERROR_NO(ERR_LEVEL_SLICE_HEADER, ERR_INFO_INVALID_QP);
742 }671 }
743 672
744 //FIXME qscale / qp ... stuff673 if (kpCurNal->sNalHeaderExt.sNalUnitHeader.uiNalRefIdc != 0) {
745 if ( !kbExtensionFlag ){674 iRet = ParseDecRefPicMarking (pCtx, pBs, pSliceHead, pSps, bIdrFlag);
746 if( uiSliceType == SP_SLICE || uiSliceType == SI_SLICE )675 if (iRet != ERR_NONE) {
747 {676 return iRet;
748 WelsLog( pCtx, WELS_LOG_WARNING, "SP/SI not supported\n");677 }
749 return GENERATE_ERROR_NO(ERR_LEVEL_SLICE_HEADER, ERR_INFO_UNSUPPORTED_SPSI);678
679 if (kbExtensionFlag && !pSubsetSps->sSpsSvcExt.bSliceHeaderRestrictionFlag) {
680 pSliceHeadExt->bStoreRefBasePicFlag = !!BsGetOneBit (pBs);
681 if ((pNalHeaderExt->bUseRefBasePicFlag || pSliceHeadExt->bStoreRefBasePicFlag) && !bIdrFlag) {
682 WelsLog (pCtx, WELS_LOG_WARNING,
683 "ParseSliceHeaderSyntaxs(): bUseRefBasePicFlag or bStoreRefBasePicFlag = 1 not supported.\n");
684 return GENERATE_ERROR_NO (ERR_LEVEL_SLICE_HEADER, ERR_INFO_UNSUPPORTED_ILP);
750 }685 }
751 }686 }
752 687 }
753 pSliceHead->uiDisableDeblockingFilterIdc = 0;688 }
754 pSliceHead->iSliceAlphaC0Offset = 0;689
755 pSliceHead->iSliceBetaOffset = 0;690 if (pPps->bEntropyCodingModeFlag) {
756 if ( pPps->bDeblockingFilterControlPresentFlag ){691 WelsLog (pCtx, WELS_LOG_WARNING, "ParseSliceHeaderSyntaxs(): CABAC in Enhancement layer not supported.\n");
757 pSliceHead->uiDisableDeblockingFilterIdc = BsGetUe(pBs);692 return GENERATE_ERROR_NO (ERR_LEVEL_SLICE_HEADER, ERR_INFO_UNSUPPORTED_CABAC_EL);
758 //refer to JVT-X201wcm1.doc G.7.4.3.4--2010.4.20693 }
759 if ( pSliceHead->uiDisableDeblockingFilterIdc > 6 )694
760 {695 pSliceHead->iSliceQpDelta = BsGetSe (pBs);
761 WelsLog( pCtx, WELS_LOG_WARNING, "disable_deblock_filter_idc (%d) out of range [0, 6]\n", pSliceHead->uiDisableDeblockingFilterIdc );696 pSliceHead->iSliceQp = pPps->iPicInitQp + pSliceHead->iSliceQpDelta;
762 return ERR_INFO_INVALID_DBLOCKING_IDC;697 if (pSliceHead->iSliceQp < 0 || pSliceHead->iSliceQp > 51) {
763 }698 WelsLog (pCtx, WELS_LOG_WARNING, "QP %d out of range\n", pSliceHead->iSliceQp);
764 if (pSliceHead->uiDisableDeblockingFilterIdc != 1){699 return GENERATE_ERROR_NO (ERR_LEVEL_SLICE_HEADER, ERR_INFO_INVALID_QP);
765 pSliceHead->iSliceAlphaC0Offset = BsGetSe(pBs) << 1; // slice_alpha_c0_offset_div2700 }
766 pSliceHead->iSliceBetaOffset = BsGetSe(pBs) << 1; // iSliceBetaOffset701
767 }702 //FIXME qscale / qp ... stuff
768 }703 if (!kbExtensionFlag) {
769 704 if (uiSliceType == SP_SLICE || uiSliceType == SI_SLICE) {
770 bSgChangeCycleInvolved = (pPps->uiNumSliceGroups > 1 && pPps->uiSliceGroupMapType >= 3 && pPps->uiSliceGroupMapType <= 5);705 WelsLog (pCtx, WELS_LOG_WARNING, "SP/SI not supported\n");
771 if ( kbExtensionFlag && bSgChangeCycleInvolved )706 return GENERATE_ERROR_NO (ERR_LEVEL_SLICE_HEADER, ERR_INFO_UNSUPPORTED_SPSI);
772 bSgChangeCycleInvolved= (bSgChangeCycleInvolved && (uiQualityId == BASE_QUALITY_ID));707 }
773 if ( bSgChangeCycleInvolved ){708 }
774 if ( pPps->uiSliceGroupChangeRate > 0 ){709
775 const int32_t kiNumBits = (int32_t)WELS_CEIL(log(static_cast<double>(1 + pPps->uiPicSizeInMapUnits / pPps->uiSliceGroupChangeRate)));710 pSliceHead->uiDisableDeblockingFilterIdc = 0;
776 pSliceHead->iSliceGroupChangeCycle = BsGetBits(pBs, kiNumBits); // For FMO extra types711 pSliceHead->iSliceAlphaC0Offset = 0;
777 }712 pSliceHead->iSliceBetaOffset = 0;
778 else713 if (pPps->bDeblockingFilterControlPresentFlag) {
779 pSliceHead->iSliceGroupChangeCycle = 0;714 pSliceHead->uiDisableDeblockingFilterIdc = BsGetUe (pBs);
780 } 715 //refer to JVT-X201wcm1.doc G.7.4.3.4--2010.4.20
781 716 if (pSliceHead->uiDisableDeblockingFilterIdc > 6) {
782 if ( !kbExtensionFlag ){717 WelsLog (pCtx, WELS_LOG_WARNING, "disable_deblock_filter_idc (%d) out of range [0, 6]\n",
783 FillDefaultSliceHeaderExt ( pSliceHeadExt, pNalHeaderExt );718 pSliceHead->uiDisableDeblockingFilterIdc);
784 }719 return ERR_INFO_INVALID_DBLOCKING_IDC;
785 else{720 }
786 /* Extra syntax elements newly introduced */721 if (pSliceHead->uiDisableDeblockingFilterIdc != 1) {
787 pSliceHeadExt->pSubsetSps = pSubsetSps;722 pSliceHead->iSliceAlphaC0Offset = BsGetSe (pBs) << 1; // slice_alpha_c0_offset_div2
788 723 pSliceHead->iSliceBetaOffset = BsGetSe (pBs) << 1; // iSliceBetaOffset
789 if ( !pNalHeaderExt->iNoInterLayerPredFlag && BASE_QUALITY_ID == uiQualityId ){724 }
790 //the following should be deleted for CODE_CLEAN725 }
791 pSliceHeadExt->uiRefLayerDqId = BsGetUe(pBs);726
792 if ( pSubsetSps->sSpsSvcExt.bInterLayerDeblockingFilterCtrlPresentFlag )727 bSgChangeCycleInvolved = (pPps->uiNumSliceGroups > 1 && pPps->uiSliceGroupMapType >= 3
793 {728 && pPps->uiSliceGroupMapType <= 5);
794 pSliceHeadExt->uiDisableInterLayerDeblockingFilterIdc = BsGetUe(pBs);729 if (kbExtensionFlag && bSgChangeCycleInvolved)
795 //refer to JVT-X201wcm1.doc G.7.4.3.4--2010.4.20730 bSgChangeCycleInvolved = (bSgChangeCycleInvolved && (uiQualityId == BASE_QUALITY_ID));
796 if ( pSliceHeadExt->uiDisableInterLayerDeblockingFilterIdc > 6 ) 731 if (bSgChangeCycleInvolved) {
797 {732 if (pPps->uiSliceGroupChangeRate > 0) {
798 WelsLog( pCtx, WELS_LOG_WARNING, "disable_inter_layer_deblock_filter_idc (%d) out of range [0, 6]\n", pSliceHeadExt->uiDisableInterLayerDeblockingFilterIdc );733 const int32_t kiNumBits = (int32_t)WELS_CEIL (log (static_cast<double> (1 + pPps->uiPicSizeInMapUnits /
799 return ERR_INFO_INVALID_DBLOCKING_IDC;734 pPps->uiSliceGroupChangeRate)));
800 }735 pSliceHead->iSliceGroupChangeCycle = BsGetBits (pBs, kiNumBits); // For FMO extra types
801 if ( pSliceHeadExt->uiDisableInterLayerDeblockingFilterIdc != 1 ){736 } else
802 pSliceHeadExt->iInterLayerSliceAlphaC0Offset = BsGetSe(pBs) << 1;737 pSliceHead->iSliceGroupChangeCycle = 0;
803 pSliceHeadExt->iInterLayerSliceBetaOffset = BsGetSe(pBs) << 1;738 }
804 }739
805 }740 if (!kbExtensionFlag) {
806 741 FillDefaultSliceHeaderExt (pSliceHeadExt, pNalHeaderExt);
807 pSliceHeadExt->uiRefLayerChromaPhaseXPlus1Flag = pSubsetSps->sSpsSvcExt.uiSeqRefLayerChromaPhaseXPlus1Flag;742 } else {
808 pSliceHeadExt->uiRefLayerChromaPhaseYPlus1 = pSubsetSps->sSpsSvcExt.uiSeqRefLayerChromaPhaseYPlus1;743 /* Extra syntax elements newly introduced */
809 744 pSliceHeadExt->pSubsetSps = pSubsetSps;
810 pSliceHeadExt->bConstrainedIntraResamplingFlag = !!BsGetOneBit(pBs);745
811 746 if (!pNalHeaderExt->iNoInterLayerPredFlag && BASE_QUALITY_ID == uiQualityId) {
812 {747 //the following should be deleted for CODE_CLEAN
813 SPosOffset pos;748 pSliceHeadExt->uiRefLayerDqId = BsGetUe (pBs);
814 pos.iLeftOffset = pSubsetSps->sSpsSvcExt.sSeqScaledRefLayer.iLeftOffset;749 if (pSubsetSps->sSpsSvcExt.bInterLayerDeblockingFilterCtrlPresentFlag) {
815 pos.iTopOffset = pSubsetSps->sSpsSvcExt.sSeqScaledRefLayer.iTopOffset * (2 - pSps->bFrameMbsOnlyFlag);750 pSliceHeadExt->uiDisableInterLayerDeblockingFilterIdc = BsGetUe (pBs);
816 pos.iRightOffset= pSubsetSps->sSpsSvcExt.sSeqScaledRefLayer.iRightOffset;751 //refer to JVT-X201wcm1.doc G.7.4.3.4--2010.4.20
817 pos.iBottomOffset=pSubsetSps->sSpsSvcExt.sSeqScaledRefLayer.iBottomOffset * (2 - pSps->bFrameMbsOnlyFlag); 752 if (pSliceHeadExt->uiDisableInterLayerDeblockingFilterIdc > 6) {
818 //memcpy(&pSliceHeadExt->sScaledRefLayer, &pos, sizeof(SPosOffset));//confirmed_safe_unsafe_usage753 WelsLog (pCtx, WELS_LOG_WARNING, "disable_inter_layer_deblock_filter_idc (%d) out of range [0, 6]\n",
819 pSliceHeadExt->iScaledRefLayerPicWidthInSampleLuma = (pSliceHead->iMbWidth << 4) - (pos.iLeftOffset+pos.iRightOffset);754 pSliceHeadExt->uiDisableInterLayerDeblockingFilterIdc);
820 pSliceHeadExt->iScaledRefLayerPicHeightInSampleLuma = (pSliceHead->iMbHeight << 4) - (pos.iTopOffset+pos.iBottomOffset) / (1 + pSliceHead->bFieldPicFlag);755 return ERR_INFO_INVALID_DBLOCKING_IDC;
821 }756 }
822 }757 if (pSliceHeadExt->uiDisableInterLayerDeblockingFilterIdc != 1) {
823 else if (uiQualityId > BASE_QUALITY_ID){758 pSliceHeadExt->iInterLayerSliceAlphaC0Offset = BsGetSe (pBs) << 1;
824 WelsLog( pCtx, WELS_LOG_WARNING, "MGS not supported.\n" );759 pSliceHeadExt->iInterLayerSliceBetaOffset = BsGetSe (pBs) << 1;
825 return GENERATE_ERROR_NO(ERR_LEVEL_SLICE_HEADER, ERR_INFO_UNSUPPORTED_MGS);760 }
826 pSliceHeadExt->uiRefLayerDqId = pNalHeaderExt->uiLayerDqId - 1;761 }
827 }762
828 else{763 pSliceHeadExt->uiRefLayerChromaPhaseXPlus1Flag = pSubsetSps->sSpsSvcExt.uiSeqRefLayerChromaPhaseXPlus1Flag;
829 pSliceHeadExt->uiRefLayerDqId = (uint8_t)-1;764 pSliceHeadExt->uiRefLayerChromaPhaseYPlus1 = pSubsetSps->sSpsSvcExt.uiSeqRefLayerChromaPhaseYPlus1;
830 }765
831 766 pSliceHeadExt->bConstrainedIntraResamplingFlag = !!BsGetOneBit (pBs);
832 pSliceHeadExt->bSliceSkipFlag = false;767
833 pSliceHeadExt->bAdaptiveBaseModeFlag = false;768 {
834 pSliceHeadExt->bDefaultBaseModeFlag = false;769 SPosOffset pos;
835 pSliceHeadExt->bAdaptiveMotionPredFlag = false;770 pos.iLeftOffset = pSubsetSps->sSpsSvcExt.sSeqScaledRefLayer.iLeftOffset;
836 pSliceHeadExt->bDefaultMotionPredFlag = false;771 pos.iTopOffset = pSubsetSps->sSpsSvcExt.sSeqScaledRefLayer.iTopOffset * (2 - pSps->bFrameMbsOnlyFlag);
837 pSliceHeadExt->bAdaptiveResidualPredFlag = false;772 pos.iRightOffset = pSubsetSps->sSpsSvcExt.sSeqScaledRefLayer.iRightOffset;
838 pSliceHeadExt->bDefaultResidualPredFlag = false;773 pos.iBottomOffset = pSubsetSps->sSpsSvcExt.sSeqScaledRefLayer.iBottomOffset * (2 - pSps->bFrameMbsOnlyFlag);
839 if ( pNalHeaderExt->iNoInterLayerPredFlag )774 //memcpy(&pSliceHeadExt->sScaledRefLayer, &pos, sizeof(SPosOffset));//confirmed_safe_unsafe_usage
840 pSliceHeadExt->bTCoeffLevelPredFlag = false;775 pSliceHeadExt->iScaledRefLayerPicWidthInSampleLuma = (pSliceHead->iMbWidth << 4) - (pos.iLeftOffset + pos.iRightOffset);
841 else776 pSliceHeadExt->iScaledRefLayerPicHeightInSampleLuma = (pSliceHead->iMbHeight << 4) -
842 pSliceHeadExt->bTCoeffLevelPredFlag = pSubsetSps->sSpsSvcExt.bSeqTCoeffLevelPredFlag;777 (pos.iTopOffset + pos.iBottomOffset) / (1 + pSliceHead->bFieldPicFlag);
843 778 }
844 if ( !pNalHeaderExt->iNoInterLayerPredFlag ){779 } else if (uiQualityId > BASE_QUALITY_ID) {
845 pSliceHeadExt->bSliceSkipFlag = !!BsGetOneBit(pBs);780 WelsLog (pCtx, WELS_LOG_WARNING, "MGS not supported.\n");
846 if ( pSliceHeadExt->bSliceSkipFlag ){781 return GENERATE_ERROR_NO (ERR_LEVEL_SLICE_HEADER, ERR_INFO_UNSUPPORTED_MGS);
847 pSliceHeadExt->uiNumMbsInSlice = 1 + BsGetUe(pBs);782 pSliceHeadExt->uiRefLayerDqId = pNalHeaderExt->uiLayerDqId - 1;
848 }783 } else {
849 else{784 pSliceHeadExt->uiRefLayerDqId = (uint8_t) - 1;
850 pSliceHeadExt->bAdaptiveBaseModeFlag = !!BsGetOneBit(pBs);785 }
851 if ( !pSliceHeadExt->bAdaptiveBaseModeFlag ){786
852 pSliceHeadExt->bDefaultBaseModeFlag = !!BsGetOneBit(pBs);787 pSliceHeadExt->bSliceSkipFlag = false;
853 }788 pSliceHeadExt->bAdaptiveBaseModeFlag = false;
854 if ( !pSliceHeadExt->bDefaultBaseModeFlag ){789 pSliceHeadExt->bDefaultBaseModeFlag = false;
855 pSliceHeadExt->bAdaptiveMotionPredFlag = !!BsGetOneBit(pBs);790 pSliceHeadExt->bAdaptiveMotionPredFlag = false;
856 if ( !pSliceHeadExt->bAdaptiveMotionPredFlag )791 pSliceHeadExt->bDefaultMotionPredFlag = false;
857 pSliceHeadExt->bDefaultMotionPredFlag = !!BsGetOneBit(pBs);792 pSliceHeadExt->bAdaptiveResidualPredFlag = false;
858 }793 pSliceHeadExt->bDefaultResidualPredFlag = false;
859 794 if (pNalHeaderExt->iNoInterLayerPredFlag)
860 pSliceHeadExt->bAdaptiveResidualPredFlag = !!BsGetOneBit(pBs);795 pSliceHeadExt->bTCoeffLevelPredFlag = false;
861 if ( !pSliceHeadExt->bAdaptiveResidualPredFlag ){796 else
862 pSliceHeadExt->bDefaultResidualPredFlag = !!BsGetOneBit(pBs);797 pSliceHeadExt->bTCoeffLevelPredFlag = pSubsetSps->sSpsSvcExt.bSeqTCoeffLevelPredFlag;
863 }798
864 }799 if (!pNalHeaderExt->iNoInterLayerPredFlag) {
865 if ( pSubsetSps->sSpsSvcExt.bAdaptiveTCoeffLevelPredFlag )800 pSliceHeadExt->bSliceSkipFlag = !!BsGetOneBit (pBs);
866 pSliceHeadExt->bTCoeffLevelPredFlag = !!BsGetOneBit(pBs);801 if (pSliceHeadExt->bSliceSkipFlag) {
867 }802 pSliceHeadExt->uiNumMbsInSlice = 1 + BsGetUe (pBs);
868 803 } else {
869 if ( !pSubsetSps->sSpsSvcExt.bSliceHeaderRestrictionFlag )804 pSliceHeadExt->bAdaptiveBaseModeFlag = !!BsGetOneBit (pBs);
870 {805 if (!pSliceHeadExt->bAdaptiveBaseModeFlag) {
871 pSliceHeadExt->uiScanIdxStart = BsGetBits(pBs, 4);806 pSliceHeadExt->bDefaultBaseModeFlag = !!BsGetOneBit (pBs);
872 pSliceHeadExt->uiScanIdxEnd = BsGetBits(pBs, 4);807 }
873 if( pSliceHeadExt->uiScanIdxStart != 0 || pSliceHeadExt->uiScanIdxEnd != 15 )808 if (!pSliceHeadExt->bDefaultBaseModeFlag) {
874 {809 pSliceHeadExt->bAdaptiveMotionPredFlag = !!BsGetOneBit (pBs);
875 WelsLog( pCtx, WELS_LOG_WARNING, "uiScanIdxStart (%d) != 0 and uiScanIdxEnd (%d) !=15 not supported here\n", pSliceHeadExt->uiScanIdxStart, pSliceHeadExt->uiScanIdxEnd );810 if (!pSliceHeadExt->bAdaptiveMotionPredFlag)
876 return GENERATE_ERROR_NO(ERR_LEVEL_SLICE_HEADER, ERR_INFO_UNSUPPORTED_MGS);811 pSliceHeadExt->bDefaultMotionPredFlag = !!BsGetOneBit (pBs);
877 }812 }
878 }813
879 else{814 pSliceHeadExt->bAdaptiveResidualPredFlag = !!BsGetOneBit (pBs);
880 pSliceHeadExt->uiScanIdxStart = 0;815 if (!pSliceHeadExt->bAdaptiveResidualPredFlag) {
881 pSliceHeadExt->uiScanIdxEnd = 15;816 pSliceHeadExt->bDefaultResidualPredFlag = !!BsGetOneBit (pBs);
882 }817 }
883 }818 }
884 819 if (pSubsetSps->sSpsSvcExt.bAdaptiveTCoeffLevelPredFlag)
885 return ERR_NONE;820 pSliceHeadExt->bTCoeffLevelPredFlag = !!BsGetOneBit (pBs);
821 }
822
823 if (!pSubsetSps->sSpsSvcExt.bSliceHeaderRestrictionFlag) {
824 pSliceHeadExt->uiScanIdxStart = BsGetBits (pBs, 4);
825 pSliceHeadExt->uiScanIdxEnd = BsGetBits (pBs, 4);
826 if (pSliceHeadExt->uiScanIdxStart != 0 || pSliceHeadExt->uiScanIdxEnd != 15) {
827 WelsLog (pCtx, WELS_LOG_WARNING, "uiScanIdxStart (%d) != 0 and uiScanIdxEnd (%d) !=15 not supported here\n",
828 pSliceHeadExt->uiScanIdxStart, pSliceHeadExt->uiScanIdxEnd);
829 return GENERATE_ERROR_NO (ERR_LEVEL_SLICE_HEADER, ERR_INFO_UNSUPPORTED_MGS);
830 }
831 } else {
832 pSliceHeadExt->uiScanIdxStart = 0;
833 pSliceHeadExt->uiScanIdxEnd = 15;
834 }
835 }
836
837 return ERR_NONE;
886}838}
887 839
888/*840/*
@@ -890,397 +842,390 @@ int32_t ParseSliceHeaderSyntaxs ( PWelsDecoderContext pCtx, PBitStringAux pBs, c · 1 unmodified line
890 * pSrc: mark as decoded prefix NAL842 * pSrc: mark as decoded prefix NAL
891 * ppDst: succeeded VCL NAL based AVC (I/P Slice)843 * ppDst: succeeded VCL NAL based AVC (I/P Slice)
892 */844 */
893bool_t PrefetchNalHeaderExtSyntax ( PWelsDecoderContext pCtx, PNalUnit const kppDst, PNalUnit const kpSrc)845bool_t PrefetchNalHeaderExtSyntax (PWelsDecoderContext pCtx, PNalUnit const kppDst, PNalUnit const kpSrc) {
894{846 PNalUnitHeaderExt pNalHdrExtD = NULL, pNalHdrExtS = NULL;
895 PNalUnitHeaderExt pNalHdrExtD = NULL, pNalHdrExtS = NULL;847 PSliceHeaderExt pShExtD = NULL;
896 PSliceHeaderExt pShExtD = NULL;848 PPrefixNalUnit pPrefixS = NULL;
897 PPrefixNalUnit pPrefixS = NULL;849 PSps pSps = NULL;
898 PSps pSps = NULL;850 int32_t iIdx = 0;
899 int32_t iIdx = 0;851
900 852 if (kppDst == NULL || kpSrc == NULL)
901 if ( kppDst == NULL || kpSrc == NULL )853 return false;
902 return false; 854
903 855 pNalHdrExtD = &kppDst->sNalHeaderExt;
904 pNalHdrExtD = &kppDst->sNalHeaderExt;856 pNalHdrExtS = &kpSrc->sNalHeaderExt;
905 pNalHdrExtS = &kpSrc->sNalHeaderExt;857 pShExtD = &kppDst->sNalData.sVclNal.sSliceHeaderExt;
906 pShExtD = &kppDst->sNalData.sVclNal.sSliceHeaderExt;858 pPrefixS = &kpSrc->sNalData.sPrefixNal;
907 pPrefixS = &kpSrc->sNalData.sPrefixNal;859 pSps = &pCtx->sSpsBuffer[pCtx->sPpsBuffer[pShExtD->sSliceHeader.iPpsId].iSpsId];
908 pSps = &pCtx->sSpsBuffer[pCtx->sPpsBuffer[pShExtD->sSliceHeader.iPpsId].iSpsId];860
909 861 pNalHdrExtD->uiDependencyId = pNalHdrExtS->uiDependencyId;
910 pNalHdrExtD->uiDependencyId = pNalHdrExtS->uiDependencyId;862 pNalHdrExtD->uiQualityId = pNalHdrExtS->uiQualityId;
911 pNalHdrExtD->uiQualityId = pNalHdrExtS->uiQualityId;863 pNalHdrExtD->uiTemporalId = pNalHdrExtS->uiTemporalId;
912 pNalHdrExtD->uiTemporalId = pNalHdrExtS->uiTemporalId;864 pNalHdrExtD->uiPriorityId = pNalHdrExtS->uiPriorityId;
913 pNalHdrExtD->uiPriorityId = pNalHdrExtS->uiPriorityId;865 pNalHdrExtD->bIdrFlag = pNalHdrExtS->bIdrFlag;
914 pNalHdrExtD->bIdrFlag = pNalHdrExtS->bIdrFlag;866 pNalHdrExtD->iNoInterLayerPredFlag = pNalHdrExtS->iNoInterLayerPredFlag;
915 pNalHdrExtD->iNoInterLayerPredFlag = pNalHdrExtS->iNoInterLayerPredFlag;867 pNalHdrExtD->bDiscardableFlag = pNalHdrExtS->bDiscardableFlag;
916 pNalHdrExtD->bDiscardableFlag = pNalHdrExtS->bDiscardableFlag;868 pNalHdrExtD->bOutputFlag = pNalHdrExtS->bOutputFlag;
917 pNalHdrExtD->bOutputFlag = pNalHdrExtS->bOutputFlag;869 pNalHdrExtD->bUseRefBasePicFlag = pNalHdrExtS->bUseRefBasePicFlag;
918 pNalHdrExtD->bUseRefBasePicFlag = pNalHdrExtS->bUseRefBasePicFlag;870 pNalHdrExtD->uiLayerDqId = pNalHdrExtS->uiLayerDqId;
919 pNalHdrExtD->uiLayerDqId = pNalHdrExtS->uiLayerDqId;871
920 872 pShExtD->bStoreRefBasePicFlag = pPrefixS->bStoreRefBasePicFlag;
921 pShExtD->bStoreRefBasePicFlag = pPrefixS->bStoreRefBasePicFlag;873 memcpy (&pShExtD->sRefBasePicMarking, &pPrefixS->sRefPicBaseMarking,
922 memcpy(&pShExtD->sRefBasePicMarking, &pPrefixS->sRefPicBaseMarking, sizeof(SRefBasePicMarking));//confirmed_safe_unsafe_usage874 sizeof (SRefBasePicMarking)); //confirmed_safe_unsafe_usage
923 if (pShExtD->sRefBasePicMarking.bAdaptiveRefBasePicMarkingModeFlag){875 if (pShExtD->sRefBasePicMarking.bAdaptiveRefBasePicMarkingModeFlag) {
924 PRefBasePicMarking pRefBasePicMarking = &pShExtD->sRefBasePicMarking;876 PRefBasePicMarking pRefBasePicMarking = &pShExtD->sRefBasePicMarking;
925 iIdx = 0;877 iIdx = 0;
926 do {878 do {
927 if (pRefBasePicMarking->mmco_base[iIdx].uiMmcoType == MMCO_END)879 if (pRefBasePicMarking->mmco_base[iIdx].uiMmcoType == MMCO_END)
928 break;880 break;
929 if (pRefBasePicMarking->mmco_base[iIdx].uiMmcoType == MMCO_SHORT2UNUSED)881 if (pRefBasePicMarking->mmco_base[iIdx].uiMmcoType == MMCO_SHORT2UNUSED)
930 pRefBasePicMarking->mmco_base[iIdx].iShortFrameNum = (pShExtD->sSliceHeader.iFrameNum-pRefBasePicMarking->mmco_base[iIdx].uiDiffOfPicNums) & ((1<<pSps->uiLog2MaxFrameNum)-1);882 pRefBasePicMarking->mmco_base[iIdx].iShortFrameNum = (pShExtD->sSliceHeader.iFrameNum -
931 ++ iIdx;883 pRefBasePicMarking->mmco_base[iIdx].uiDiffOfPicNums) & ((1 << pSps->uiLog2MaxFrameNum) - 1);
932 } while(iIdx < MAX_MMCO_COUNT);884 ++ iIdx;
933 }885 } while (iIdx < MAX_MMCO_COUNT);
934 886 }
935 return true;887
888 return true;
936}889}
937 890
938 891
939 892
940int32_t UpdateAccessUnit ( PWelsDecoderContext pCtx )893int32_t UpdateAccessUnit (PWelsDecoderContext pCtx) {
941{894 PAccessUnit pCurAu = pCtx->pAccessUnitList;
942 PAccessUnit pCurAu = pCtx->pAccessUnitList; 895 int32_t iIdx = pCurAu->uiEndPos;
943 int32_t iIdx = pCurAu->uiEndPos;
944
945 // Conversed iterator
946 pCtx->uiTargetDqId = pCurAu->pNalUnitsList[iIdx]->sNalHeaderExt.uiLayerDqId;
947 pCurAu->uiActualUnitsNum = iIdx + 1;
948 pCurAu->bCompletedAuFlag = true;
949 896
950 // Added for mosaic avoidance, 11/19/2009897 // Conversed iterator
898 pCtx->uiTargetDqId = pCurAu->pNalUnitsList[iIdx]->sNalHeaderExt.uiLayerDqId;
899 pCurAu->uiActualUnitsNum = iIdx + 1;
900 pCurAu->bCompletedAuFlag = true;
901
902 // Added for mosaic avoidance, 11/19/2009
951#ifdef LONG_TERM_REF903#ifdef LONG_TERM_REF
952 if ( pCtx->bParamSetsLostFlag )904 if (pCtx->bParamSetsLostFlag)
953#else905#else
954 if ( pCtx->bReferenceLostAtT0Flag )906 if (pCtx->bReferenceLostAtT0Flag)
955#endif 907#endif
956 {908 {
957 uint32_t uiActualIdx = 0;909 uint32_t uiActualIdx = 0;
958 while ( uiActualIdx < pCurAu->uiActualUnitsNum ) {910 while (uiActualIdx < pCurAu->uiActualUnitsNum) {
959 PNalUnit nal = pCurAu->pNalUnitsList[uiActualIdx];911 PNalUnit nal = pCurAu->pNalUnitsList[uiActualIdx];
960 912
961 if ( nal->sNalHeaderExt.sNalUnitHeader.eNalUnitType == NAL_UNIT_CODED_SLICE_IDR || nal->sNalHeaderExt.bIdrFlag )913 if (nal->sNalHeaderExt.sNalUnitHeader.eNalUnitType == NAL_UNIT_CODED_SLICE_IDR || nal->sNalHeaderExt.bIdrFlag) {
962 {914 break;
963 break;915 }
964 }916 ++ uiActualIdx;
965 ++ uiActualIdx;917 }
966 }918 if (uiActualIdx ==
967 if ( uiActualIdx == pCurAu->uiActualUnitsNum ) // no found IDR nal within incoming AU, need exit to avoid mosaic issue, 11/19/2009919 pCurAu->uiActualUnitsNum) { // no found IDR nal within incoming AU, need exit to avoid mosaic issue, 11/19/2009
968 {920 WelsLog (pCtx, WELS_LOG_WARNING, "UpdateAccessUnit():::::Key frame lost.....CAN NOT find IDR from current AU.\n");
969 WelsLog( pCtx, WELS_LOG_WARNING, "UpdateAccessUnit():::::Key frame lost.....CAN NOT find IDR from current AU.\n" );
970#ifdef LONG_TERM_REF921#ifdef LONG_TERM_REF
971 pCtx->iErrorCode |= dsNoParamSets;922 pCtx->iErrorCode |= dsNoParamSets;
972 return dsNoParamSets;923 return dsNoParamSets;
973#else924#else
974 pCtx->iErrorCode |= dsRefLost;925 pCtx->iErrorCode |= dsRefLost;
975 return ERR_INFO_REFERENCE_PIC_LOST;926 return ERR_INFO_REFERENCE_PIC_LOST;
976#endif 927#endif
977 }928 }
978 } 929 }
979 930
980 return ERR_NONE;931 return ERR_NONE;
981}932}
982 933
983int32_t InitialDqLayersContext ( PWelsDecoderContext pCtx, const int32_t kiMaxWidth, const int32_t kiMaxHeight )934int32_t InitialDqLayersContext (PWelsDecoderContext pCtx, const int32_t kiMaxWidth, const int32_t kiMaxHeight) {
984{935 const int32_t kiPicStride = ((kiMaxWidth + 15) & 0xfffff0) + (PADDING_LENGTH << 1);
985 const int32_t kiPicStride = ((kiMaxWidth + 15) & 0xfffff0) + (PADDING_LENGTH<<1);936 const int32_t kiPicLines = ((kiMaxHeight + 15) & 0xfffff0);
986 const int32_t kiPicLines = ((kiMaxHeight + 15) & 0xfffff0);937
987 938 int32_t i = 0;
988 int32_t i = 0;939
989 940 WELS_VERIFY_RETURN_IF (ERR_INFO_INVALID_PARAM, (NULL == pCtx || kiMaxWidth <= 0 || kiMaxHeight <= 0))
990 WELS_VERIFY_RETURN_IF( ERR_INFO_INVALID_PARAM, ( NULL == pCtx || kiMaxWidth <= 0 || kiMaxHeight <= 0 ) )941 pCtx->sMb.iMbWidth = (kiMaxWidth + 15) >> 4;
991 pCtx->sMb.iMbWidth = (kiMaxWidth + 15) >> 4;942 pCtx->sMb.iMbHeight = (kiMaxHeight + 15) >> 4;
992 pCtx->sMb.iMbHeight = (kiMaxHeight + 15) >> 4;943
993 944 if (pCtx->bInitialDqLayersMem && kiMaxWidth <= pCtx->iPicWidthReq
994 if ( pCtx->bInitialDqLayersMem && kiMaxWidth <= pCtx->iPicWidthReq && kiMaxHeight <= pCtx->iPicHeightReq ) // have same dimension memory, skipped945 && kiMaxHeight <= pCtx->iPicHeightReq) // have same dimension memory, skipped
995 return ERR_NONE;946 return ERR_NONE;
996 947
997 948
998 UninitialDqLayersContext( pCtx );949 UninitialDqLayersContext (pCtx);
999 950
1000 do {951 do {
1001 PDqLayer pDq = (PDqLayer )WelsMalloc(sizeof(SDqLayer), "PDqLayer");952 PDqLayer pDq = (PDqLayer)WelsMalloc (sizeof (SDqLayer), "PDqLayer");
1002 953
1003 int32_t iPlaneIdx = 0;954 int32_t iPlaneIdx = 0;
1004 955
1005 if ( pDq == NULL )956 if (pDq == NULL)
1006 return ERR_INFO_OUT_OF_MEMORY;957 return ERR_INFO_OUT_OF_MEMORY;
1007 958
1008 memset(pDq, 0, sizeof(SDqLayer));959 memset (pDq, 0, sizeof (SDqLayer));
1009 if(pCtx->iDecoderMode == SW_MODE)960 if (pCtx->iDecoderMode == SW_MODE) {
1010 {961
1011 962 do {
1012 do {963 const int32_t kiHshift = iPlaneIdx ? 1 : 0;
1013 const int32_t kiHshift = iPlaneIdx ? 1 : 0;964 const int32_t kiVshift = kiHshift;
1014 const int32_t kiVshift = kiHshift;965 const int32_t kiStride = WELS_ALIGN ((kiPicStride >> kiHshift), (16 << (1 - kiHshift)));
1015 const int32_t kiStride = WELS_ALIGN( (kiPicStride >> kiHshift), (16 << (1-kiHshift)) );966 const int32_t kiLine = (kiPicLines + (PADDING_LENGTH << 1)) >> kiVshift;
1016 const int32_t kiLine = (kiPicLines + (PADDING_LENGTH<<1)) >> kiVshift;967 const int32_t kiSize = kiStride * kiLine;
1017 const int32_t kiSize = kiStride * kiLine;968
1018 969 pCtx->pCsListXchg[i][iPlaneIdx] = (uint8_t*)WelsMalloc (kiSize * sizeof (uint8_t), "pCtx->pCsListXchg[][]");
1019 pCtx->pCsListXchg[i][iPlaneIdx] = (uint8_t *)WelsMalloc( kiSize * sizeof(uint8_t), "pCtx->pCsListXchg[][]" );970
1020 971 WELS_VERIFY_RETURN_IF (ERR_INFO_OUT_OF_MEMORY, (NULL == pCtx->pCsListXchg[i][iPlaneIdx]))
1021 WELS_VERIFY_RETURN_IF( ERR_INFO_OUT_OF_MEMORY, (NULL == pCtx->pCsListXchg[i][iPlaneIdx]) )972 pCtx->iCsStride[iPlaneIdx] = kiStride;
1022 pCtx->iCsStride[iPlaneIdx] = kiStride;973
1023 974
1024 975 pCtx->pRsListXchg[i][iPlaneIdx] = (int16_t*)WelsMalloc (kiSize * sizeof (int16_t), "pCtx->pRsListXchg[][]");
1025 pCtx->pRsListXchg[i][iPlaneIdx] = (int16_t *)WelsMalloc( kiSize * sizeof(int16_t), "pCtx->pRsListXchg[][]" );976
1026 977 WELS_VERIFY_RETURN_IF (ERR_INFO_OUT_OF_MEMORY , (NULL == pCtx->pRsListXchg[i][iPlaneIdx]))
1027 WELS_VERIFY_RETURN_IF( ERR_INFO_OUT_OF_MEMORY , (NULL == pCtx->pRsListXchg[i][iPlaneIdx]) )978 pCtx->iRsStride[iPlaneIdx] = kiStride;
1028 pCtx->iRsStride[iPlaneIdx] = kiStride;979
1029 980 ++ iPlaneIdx;
1030 ++ iPlaneIdx;981 } while (iPlaneIdx < 3);
1031 } while(iPlaneIdx < 3);982
1032 983
1033 984 pCtx->sMb.pMbType[i] = (int8_t*)WelsMalloc (pCtx->sMb.iMbWidth * pCtx->sMb.iMbHeight * sizeof (int8_t),
1034 pCtx->sMb.pMbType[i] = (int8_t *)WelsMalloc( pCtx->sMb.iMbWidth * pCtx->sMb.iMbHeight *sizeof(int8_t), "pCtx->sMb.pMbType[]" );985 "pCtx->sMb.pMbType[]");
1035 pCtx->sMb.pMv[i][0] = (int16_t (*)[16][2])WelsMalloc( pCtx->sMb.iMbWidth * pCtx->sMb.iMbHeight * sizeof(int16_t) * MV_A * MB_BLOCK4x4_NUM, "pCtx->sMb.pMv[][]"); 986 pCtx->sMb.pMv[i][0] = (int16_t (*)[16][2])WelsMalloc (pCtx->sMb.iMbWidth * pCtx->sMb.iMbHeight * sizeof (
1036 pCtx->sMb.pRefIndex[i][0] = (int8_t (*)[MB_BLOCK4x4_NUM])WelsMalloc( pCtx->sMb.iMbWidth * pCtx->sMb.iMbHeight * sizeof(int8_t) * MB_BLOCK4x4_NUM, "pCtx->sMb.pRefIndex[][]");987 int16_t) * MV_A * MB_BLOCK4x4_NUM, "pCtx->sMb.pMv[][]");
1037 pCtx->sMb.pLumaQp[i] = (int8_t *)WelsMalloc( pCtx->sMb.iMbWidth * pCtx->sMb.iMbHeight * sizeof(int8_t), "pCtx->sMb.pLumaQp[]");988 pCtx->sMb.pRefIndex[i][0] = (int8_t (*)[MB_BLOCK4x4_NUM])WelsMalloc (pCtx->sMb.iMbWidth * pCtx->sMb.iMbHeight * sizeof (
1038 pCtx->sMb.pChromaQp[i] = (int8_t *)WelsMalloc(pCtx->sMb.iMbWidth * pCtx->sMb.iMbHeight * sizeof(int8_t), "pCtx->sMb.pChromaQp[]");989 int8_t) * MB_BLOCK4x4_NUM, "pCtx->sMb.pRefIndex[][]");
1039 pCtx->sMb.pNzc[i] = (int8_t (*)[24])WelsMalloc(pCtx->sMb.iMbWidth * pCtx->sMb.iMbHeight * sizeof(int8_t) * 24, "pCtx->sMb.pNzc[]");990 pCtx->sMb.pLumaQp[i] = (int8_t*)WelsMalloc (pCtx->sMb.iMbWidth * pCtx->sMb.iMbHeight * sizeof (int8_t),
1040 pCtx->sMb.pNzcRs[i] = (int8_t (*)[24])WelsMalloc(pCtx->sMb.iMbWidth * pCtx->sMb.iMbHeight * sizeof(int8_t) * 24, "pCtx->sMb.pNzcRs[]");991 "pCtx->sMb.pLumaQp[]");
1041 pCtx->sMb.pScaledTCoeff[i] = (int16_t (*)[MB_COEFF_LIST_SIZE])WelsMalloc(pCtx->sMb.iMbWidth * pCtx->sMb.iMbHeight * sizeof(int16_t) * MB_COEFF_LIST_SIZE, "pCtx->sMb.pScaledTCoeff[]"); 992 pCtx->sMb.pChromaQp[i] = (int8_t*)WelsMalloc (pCtx->sMb.iMbWidth * pCtx->sMb.iMbHeight * sizeof (int8_t),
1042 pCtx->sMb.pIntraPredMode[i] = (int8_t (*)[8])WelsMalloc(pCtx->sMb.iMbWidth * pCtx->sMb.iMbHeight * sizeof(int8_t) * 8, "pCtx->sMb.pIntraPredMode[]");993 "pCtx->sMb.pChromaQp[]");
1043 pCtx->sMb.pIntra4x4FinalMode[i] = (int8_t (*)[MB_BLOCK4x4_NUM])WelsMalloc(pCtx->sMb.iMbWidth * pCtx->sMb.iMbHeight * sizeof(int8_t) * MB_BLOCK4x4_NUM, "pCtx->sMb.pIntra4x4FinalMode[]"); 994 pCtx->sMb.pNzc[i] = (int8_t (*)[24])WelsMalloc (pCtx->sMb.iMbWidth * pCtx->sMb.iMbHeight * sizeof (int8_t) * 24,
1044 pCtx->sMb.pChromaPredMode[i] = (int8_t *)WelsMalloc(pCtx->sMb.iMbWidth * pCtx->sMb.iMbHeight * sizeof(int8_t), "pCtx->sMb.pChromaPredMode[]");995 "pCtx->sMb.pNzc[]");
1045 pCtx->sMb.pCbp[i] = (int8_t *)WelsMalloc(pCtx->sMb.iMbWidth * pCtx->sMb.iMbHeight *sizeof(int8_t), "pCtx->sMb.pCbp[]");996 pCtx->sMb.pNzcRs[i] = (int8_t (*)[24])WelsMalloc (pCtx->sMb.iMbWidth * pCtx->sMb.iMbHeight * sizeof (int8_t) * 24,
1046 pCtx->sMb.pSubMbType[i] = (int8_t (*)[MB_PARTITION_SIZE])WelsMalloc(pCtx->sMb.iMbWidth * pCtx->sMb.iMbHeight * sizeof(int8_t) * MB_PARTITION_SIZE, "pCtx->sMb.pSubMbType[]");997 "pCtx->sMb.pNzcRs[]");
1047 pCtx->sMb.pSliceIdc[i] = (int32_t *) WelsMalloc(pCtx->sMb.iMbWidth * pCtx->sMb.iMbHeight * sizeof(int32_t), "pCtx->sMb.pSliceIdc[]"); // using int32_t for slice_idc, 4/21/2010998 pCtx->sMb.pScaledTCoeff[i] = (int16_t (*)[MB_COEFF_LIST_SIZE])WelsMalloc (pCtx->sMb.iMbWidth * pCtx->sMb.iMbHeight *
1048 if ( pCtx->sMb.pSliceIdc[i] != NULL )999 sizeof (int16_t) * MB_COEFF_LIST_SIZE, "pCtx->sMb.pScaledTCoeff[]");
1049 memset(pCtx->sMb.pSliceIdc[i], 0xff, (pCtx->sMb.iMbWidth * pCtx->sMb.iMbHeight * sizeof(int32_t)) );1000 pCtx->sMb.pIntraPredMode[i] = (int8_t (*)[8])WelsMalloc (pCtx->sMb.iMbWidth * pCtx->sMb.iMbHeight * sizeof (int8_t) * 8,
1050 pCtx->sMb.pResidualPredFlag[i] = (int8_t *) WelsMalloc(pCtx->sMb.iMbWidth * pCtx->sMb.iMbHeight * sizeof(int8_t), "pCtx->sMb.pResidualPredFlag[]");1001 "pCtx->sMb.pIntraPredMode[]");
1051 //pCtx->sMb.pMotionPredFlag[i] = (uint8_t *) WelsMalloc(pCtx->sMb.iMbWidth * pCtx->sMb.iMbHeight * sizeof(uint8_t), "pCtx->sMb.pMotionPredFlag[]");1002 pCtx->sMb.pIntra4x4FinalMode[i] = (int8_t (*)[MB_BLOCK4x4_NUM])WelsMalloc (pCtx->sMb.iMbWidth * pCtx->sMb.iMbHeight *
1052 pCtx->sMb.pInterPredictionDoneFlag[i] = (int8_t *) WelsMalloc(pCtx->sMb.iMbWidth * pCtx->sMb.iMbHeight * sizeof(int8_t), "pCtx->sMb.pInterPredictionDoneFlag[]");1003 sizeof (int8_t) * MB_BLOCK4x4_NUM, "pCtx->sMb.pIntra4x4FinalMode[]");
1053 1004 pCtx->sMb.pChromaPredMode[i] = (int8_t*)WelsMalloc (pCtx->sMb.iMbWidth * pCtx->sMb.iMbHeight * sizeof (int8_t),
1054 // check memory block valid due above allocated..1005 "pCtx->sMb.pChromaPredMode[]");
1055 WELS_VERIFY_RETURN_IF ( ERR_INFO_OUT_OF_MEMORY,1006 pCtx->sMb.pCbp[i] = (int8_t*)WelsMalloc (pCtx->sMb.iMbWidth * pCtx->sMb.iMbHeight * sizeof (int8_t),
1056 ( (NULL == pCtx->sMb.pMbType[i]) ||1007 "pCtx->sMb.pCbp[]");
1057 (NULL == pCtx->sMb.pMv[i][0]) ||1008 pCtx->sMb.pSubMbType[i] = (int8_t (*)[MB_PARTITION_SIZE])WelsMalloc (pCtx->sMb.iMbWidth * pCtx->sMb.iMbHeight * sizeof (
1058 (NULL == pCtx->sMb.pRefIndex[i][0]) ||1009 int8_t) * MB_PARTITION_SIZE, "pCtx->sMb.pSubMbType[]");
1059 (NULL == pCtx->sMb.pLumaQp[i]) ||1010 pCtx->sMb.pSliceIdc[i] = (int32_t*) WelsMalloc (pCtx->sMb.iMbWidth * pCtx->sMb.iMbHeight * sizeof (int32_t),
1060 (NULL == pCtx->sMb.pChromaQp[i]) ||1011 "pCtx->sMb.pSliceIdc[]"); // using int32_t for slice_idc, 4/21/2010
1061 (NULL == pCtx->sMb.pNzc[i]) ||1012 if (pCtx->sMb.pSliceIdc[i] != NULL)
1062 (NULL == pCtx->sMb.pNzcRs[i]) ||1013 memset (pCtx->sMb.pSliceIdc[i], 0xff, (pCtx->sMb.iMbWidth * pCtx->sMb.iMbHeight * sizeof (int32_t)));
1063 (NULL == pCtx->sMb.pScaledTCoeff[i]) ||1014 pCtx->sMb.pResidualPredFlag[i] = (int8_t*) WelsMalloc (pCtx->sMb.iMbWidth * pCtx->sMb.iMbHeight * sizeof (int8_t),
1064 (NULL == pCtx->sMb.pIntraPredMode[i]) ||1015 "pCtx->sMb.pResidualPredFlag[]");
1065 (NULL == pCtx->sMb.pIntra4x4FinalMode[i]) ||1016 //pCtx->sMb.pMotionPredFlag[i] = (uint8_t *) WelsMalloc(pCtx->sMb.iMbWidth * pCtx->sMb.iMbHeight * sizeof(uint8_t), "pCtx->sMb.pMotionPredFlag[]");
1066 (NULL == pCtx->sMb.pChromaPredMode[i]) ||1017 pCtx->sMb.pInterPredictionDoneFlag[i] = (int8_t*) WelsMalloc (pCtx->sMb.iMbWidth * pCtx->sMb.iMbHeight * sizeof (
1067 (NULL == pCtx->sMb.pCbp[i]) ||1018 int8_t), "pCtx->sMb.pInterPredictionDoneFlag[]");
1068 (NULL == pCtx->sMb.pSubMbType[i]) ||1019
1069 (NULL == pCtx->sMb.pSliceIdc[i]) ||1020 // check memory block valid due above allocated..
1070 (NULL == pCtx->sMb.pResidualPredFlag[i]) ||1021 WELS_VERIFY_RETURN_IF (ERR_INFO_OUT_OF_MEMORY,
1071 (NULL == pCtx->sMb.pInterPredictionDoneFlag[i])1022 ((NULL == pCtx->sMb.pMbType[i]) ||
1072 )1023 (NULL == pCtx->sMb.pMv[i][0]) ||
1073 )1024 (NULL == pCtx->sMb.pRefIndex[i][0]) ||
1074 } // end of if(pCtx->iDecoderMode == SW_MODE)1025 (NULL == pCtx->sMb.pLumaQp[i]) ||
1075 1026 (NULL == pCtx->sMb.pChromaQp[i]) ||
1076 pCtx->pDqLayersList[i] = pDq;1027 (NULL == pCtx->sMb.pNzc[i]) ||
1077 ++ i;1028 (NULL == pCtx->sMb.pNzcRs[i]) ||
1078 } while( i < LAYER_NUM_EXCHANGEABLE );1029 (NULL == pCtx->sMb.pScaledTCoeff[i]) ||
1079 1030 (NULL == pCtx->sMb.pIntraPredMode[i]) ||
1080 1031 (NULL == pCtx->sMb.pIntra4x4FinalMode[i]) ||
1081 pCtx->bInitialDqLayersMem = true;1032 (NULL == pCtx->sMb.pChromaPredMode[i]) ||
1082 pCtx->iPicWidthReq = kiMaxWidth;1033 (NULL == pCtx->sMb.pCbp[i]) ||
1083 pCtx->iPicHeightReq = kiMaxHeight;1034 (NULL == pCtx->sMb.pSubMbType[i]) ||
1084 1035 (NULL == pCtx->sMb.pSliceIdc[i]) ||
1085 return ERR_NONE;1036 (NULL == pCtx->sMb.pResidualPredFlag[i]) ||
1037 (NULL == pCtx->sMb.pInterPredictionDoneFlag[i])
1038 )
1039 )
1040 } // end of if(pCtx->iDecoderMode == SW_MODE)
1041
1042 pCtx->pDqLayersList[i] = pDq;
1043 ++ i;
1044 } while (i < LAYER_NUM_EXCHANGEABLE);
1045
1046
1047 pCtx->bInitialDqLayersMem = true;
1048 pCtx->iPicWidthReq = kiMaxWidth;
1049 pCtx->iPicHeightReq = kiMaxHeight;
1050
1051 return ERR_NONE;
1086}1052}
1087 1053
1088void_t UninitialDqLayersContext ( PWelsDecoderContext pCtx )1054void_t UninitialDqLayersContext (PWelsDecoderContext pCtx) {
1089{1055 int32_t i = 0;
1090 int32_t i = 0;1056 int32_t j = 0;
1091 int32_t j = 0;1057
1092 1058 do {
1093 do {1059 PDqLayer pDq = pCtx->pDqLayersList[i];
1094 PDqLayer pDq = pCtx->pDqLayersList[i]; 1060 if (pDq == NULL) {
1095 if ( pDq == NULL ){1061 ++ i;
1096 ++ i;1062 continue;
1097 continue;1063 }
1098 }1064
1099 1065 if (pCtx->pCsListXchg[i]) { // cs picture
1100 if ( pCtx->pCsListXchg[i] ){ // cs picture1066 j = 0;
1101 j = 0;1067 do {
1102 do {1068 if (NULL != pCtx->pCsListXchg[i][j]) {
1103 if ( NULL != pCtx->pCsListXchg[i][j] )1069 WelsFree (pCtx->pCsListXchg[i][j], "pCtx->pCsListXchg[][]");
1104 {1070
1105 WelsFree( pCtx->pCsListXchg[i][j], "pCtx->pCsListXchg[][]" );1071 pCtx->pCsListXchg[i][j] = NULL;
1106 1072 }
1107 pCtx->pCsListXchg[i][j] = NULL;1073 pCtx->iCsStride[j] = 0;
1108 }1074 ++ j;
1109 pCtx->iCsStride[j] = 0;1075 } while (j < 3);
1110 ++ j;1076
1111 } while( j < 3 ); 1077 pDq->pCsData[i] = NULL; // for safe
1112 1078 pDq->iCsStride[i] = 0;
1113 pDq->pCsData[i] = NULL; // for safe1079 }
1114 pDq->iCsStride[i] = 0;1080 if (pCtx->pRsListXchg[i]) {
1115 }1081 j = 0;
1116 if ( pCtx->pRsListXchg[i] ){ 1082 do {
1117 j = 0;1083 if (NULL != pCtx->pRsListXchg[i][j]) {
1118 do {1084 WelsFree (pCtx->pRsListXchg[i][j], "pCtx->pRsListXchg[][]");
1119 if ( NULL != pCtx->pRsListXchg[i][j] )1085
1120 {1086 pCtx->pRsListXchg[i][j] = NULL;
1121 WelsFree( pCtx->pRsListXchg[i][j], "pCtx->pRsListXchg[][]" );1087 }
1122 1088 pCtx->iRsStride[j] = 0;
1123 pCtx->pRsListXchg[i][j] = NULL;1089 ++ j;
1124 }1090 } while (j < 3);
1125 pCtx->iRsStride[j] = 0;1091 }
1126 ++ j;1092
1127 } while(j < 3);1093 if (pCtx->sMb.pMbType[i]) {
1128 }1094 WelsFree (pCtx->sMb.pMbType[i], "pCtx->sMb.pMbType[]");
1129 1095
1130 if (pCtx->sMb.pMbType[i])1096 pCtx->sMb.pMbType[i] = NULL;
1131 { 1097 }
1132 WelsFree( pCtx->sMb.pMbType[i], "pCtx->sMb.pMbType[]");1098
1133 1099 if (pCtx->sMb.pMv[i][0]) {
1134 pCtx->sMb.pMbType[i] = NULL; 1100 WelsFree (pCtx->sMb.pMv[i][0], "pCtx->sMb.pMv[][]");
1135 }1101
1136 1102 pCtx->sMb.pMv[i][0] = NULL;
1137 if (pCtx->sMb.pMv[i][0])1103 }
1138 {1104
1139 WelsFree( pCtx->sMb.pMv[i][0], "pCtx->sMb.pMv[][]" );1105 if (pCtx->sMb.pRefIndex[i][0]) {
1140 1106 WelsFree (pCtx->sMb.pRefIndex[i][0], "pCtx->sMb.pRefIndex[][]");
1141 pCtx->sMb.pMv[i][0] = NULL;1107
1142 }1108 pCtx->sMb.pRefIndex[i][0] = NULL;
1143 1109 }
1144 if (pCtx->sMb.pRefIndex[i][0])
1145 {
1146 WelsFree( pCtx->sMb.pRefIndex[i][0], "pCtx->sMb.pRefIndex[][]" );
1147
1148 pCtx->sMb.pRefIndex[i][0] = NULL;
1149 }
1150
1151 if (pCtx->sMb.pLumaQp[i])
1152 {
1153 WelsFree(pCtx->sMb.pLumaQp[i], "pCtx->sMb.pLumaQp[]");
1154
1155 pCtx->sMb.pLumaQp[i] = NULL;
1156 }
1157
1158 if (pCtx->sMb.pChromaQp[i])
1159 {
1160 WelsFree(pCtx->sMb.pChromaQp[i], "pCtx->sMb.pChromaQp[]");
1161
1162 pCtx->sMb.pChromaQp[i] = NULL;
1163 }
1164
1165 if (pCtx->sMb.pNzc[i])
1166 {
1167 WelsFree(pCtx->sMb.pNzc[i], "pCtx->sMb.pNzc[]");
1168
1169 pCtx->sMb.pNzc[i] = NULL;
1170 }
1171
1172 if (pCtx->sMb.pNzcRs[i])
1173 {
1174 WelsFree(pCtx->sMb.pNzcRs[i], "pCtx->sMb.pNzcRs[]");
1175
1176 pCtx->sMb.pNzcRs[i] = NULL;
1177 }
1178
1179 if (pCtx->sMb.pScaledTCoeff[i])
1180 {
1181 WelsFree(pCtx->sMb.pScaledTCoeff[i], "pCtx->sMb.pScaledTCoeff[]");
1182
1183 pCtx->sMb.pScaledTCoeff[i] = NULL;
1184 }
1185
1186 if (pCtx->sMb.pIntraPredMode[i])
1187 {
1188 WelsFree(pCtx->sMb.pIntraPredMode[i], "pCtx->sMb.pIntraPredMode[]");
1189
1190 pCtx->sMb.pIntraPredMode[i] = NULL;
1191 }
1192
1193 if (pCtx->sMb.pIntra4x4FinalMode[i])
1194 {
1195 WelsFree(pCtx->sMb.pIntra4x4FinalMode[i], "pCtx->sMb.pIntra4x4FinalMode[]");
1196
1197 pCtx->sMb.pIntra4x4FinalMode[i] = NULL;
1198 }
1199
1200 if (pCtx->sMb.pChromaPredMode[i])
1201 {
1202 WelsFree(pCtx->sMb.pChromaPredMode[i], "pCtx->sMb.pChromaPredMode[]");
1203
1204 pCtx->sMb.pChromaPredMode[i] = NULL;
1205 }
1206
1207 if (pCtx->sMb.pCbp[i])
1208 {
1209 WelsFree( pCtx->sMb.pCbp[i], "pCtx->sMb.pCbp[]" );
1210
1211 pCtx->sMb.pCbp[i] = NULL;
1212 }
1213
1214 // if (pCtx->sMb.pMotionPredFlag[i])
1215 //{
1216 // WelsFree( pCtx->sMb.pMotionPredFlag[i], "pCtx->sMb.pMotionPredFlag[]" );
1217
1218 // pCtx->sMb.pMotionPredFlag[i] = NULL;
1219 //}
1220
1221 if (pCtx->sMb.pSubMbType[i])
1222 {
1223 WelsFree(pCtx->sMb.pSubMbType[i], "pCtx->sMb.pSubMbType[]");
1224
1225 pCtx->sMb.pSubMbType[i] = NULL;
1226 }
1227
1228 if (pCtx->sMb.pSliceIdc[i])
1229 {
1230 WelsFree( pCtx->sMb.pSliceIdc[i], "pCtx->sMb.pSliceIdc[]" );
1231
1232 pCtx->sMb.pSliceIdc[i] = NULL;
1233 }
1234
1235 if (pCtx->sMb.pResidualPredFlag[i])
1236 {
1237 WelsFree( pCtx->sMb.pResidualPredFlag[i], "pCtx->sMb.pResidualPredFlag[]" );
1238 1110
1239 pCtx->sMb.pResidualPredFlag[i] = NULL;1111 if (pCtx->sMb.pLumaQp[i]) {
1240 }1112 WelsFree (pCtx->sMb.pLumaQp[i], "pCtx->sMb.pLumaQp[]");
1241 1113
1242 if (pCtx->sMb.pInterPredictionDoneFlag[i])1114 pCtx->sMb.pLumaQp[i] = NULL;
1243 {1115 }
1244 WelsFree( pCtx->sMb.pInterPredictionDoneFlag[i], "pCtx->sMb.pInterPredictionDoneFlag[]" );1116
1117 if (pCtx->sMb.pChromaQp[i]) {
1118 WelsFree (pCtx->sMb.pChromaQp[i], "pCtx->sMb.pChromaQp[]");
1119
1120 pCtx->sMb.pChromaQp[i] = NULL;
1121 }
1122
1123 if (pCtx->sMb.pNzc[i]) {
1124 WelsFree (pCtx->sMb.pNzc[i], "pCtx->sMb.pNzc[]");
1125
1126 pCtx->sMb.pNzc[i] = NULL;
1127 }
1245 1128
1246 pCtx->sMb.pInterPredictionDoneFlag[i] = NULL;1129 if (pCtx->sMb.pNzcRs[i]) {
1247 }1130 WelsFree (pCtx->sMb.pNzcRs[i], "pCtx->sMb.pNzcRs[]");
1248 WelsFree( pDq, "pDq" );
1249 1131
1250 pDq = NULL;1132 pCtx->sMb.pNzcRs[i] = NULL;
1251 pCtx->pDqLayersList[i] = NULL;1133 }
1252 1134
1253 ++ i;1135 if (pCtx->sMb.pScaledTCoeff[i]) {
1254 } while( i < LAYER_NUM_EXCHANGEABLE );1136 WelsFree (pCtx->sMb.pScaledTCoeff[i], "pCtx->sMb.pScaledTCoeff[]");
1255 1137
1256 pCtx->iPicWidthReq = 0;1138 pCtx->sMb.pScaledTCoeff[i] = NULL;
1257 pCtx->iPicHeightReq = 0;1139 }
1258 pCtx->bInitialDqLayersMem = false;1140
1141 if (pCtx->sMb.pIntraPredMode[i]) {
1142 WelsFree (pCtx->sMb.pIntraPredMode[i], "pCtx->sMb.pIntraPredMode[]");
1143
1144 pCtx->sMb.pIntraPredMode[i] = NULL;
1145 }
1146
1147 if (pCtx->sMb.pIntra4x4FinalMode[i]) {
1148 WelsFree (pCtx->sMb.pIntra4x4FinalMode[i], "pCtx->sMb.pIntra4x4FinalMode[]");
1149
1150 pCtx->sMb.pIntra4x4FinalMode[i] = NULL;
1151 }
1152
1153 if (pCtx->sMb.pChromaPredMode[i]) {
1154 WelsFree (pCtx->sMb.pChromaPredMode[i], "pCtx->sMb.pChromaPredMode[]");
1155
1156 pCtx->sMb.pChromaPredMode[i] = NULL;
1157 }
1158
1159 if (pCtx->sMb.pCbp[i]) {
1160 WelsFree (pCtx->sMb.pCbp[i], "pCtx->sMb.pCbp[]");
1161
1162 pCtx->sMb.pCbp[i] = NULL;
1163 }
1164
1165 // if (pCtx->sMb.pMotionPredFlag[i])
1166 //{
1167 // WelsFree( pCtx->sMb.pMotionPredFlag[i], "pCtx->sMb.pMotionPredFlag[]" );
1168
1169 // pCtx->sMb.pMotionPredFlag[i] = NULL;
1170 //}
1171
1172 if (pCtx->sMb.pSubMbType[i]) {
1173 WelsFree (pCtx->sMb.pSubMbType[i], "pCtx->sMb.pSubMbType[]");
1174
1175 pCtx->sMb.pSubMbType[i] = NULL;
1176 }
1177
1178 if (pCtx->sMb.pSliceIdc[i]) {
1179 WelsFree (pCtx->sMb.pSliceIdc[i], "pCtx->sMb.pSliceIdc[]");
1180
1181 pCtx->sMb.pSliceIdc[i] = NULL;
1182 }
1183
1184 if (pCtx->sMb.pResidualPredFlag[i]) {
1185 WelsFree (pCtx->sMb.pResidualPredFlag[i], "pCtx->sMb.pResidualPredFlag[]");
1186
1187 pCtx->sMb.pResidualPredFlag[i] = NULL;
1188 }
1189
1190 if (pCtx->sMb.pInterPredictionDoneFlag[i]) {
1191 WelsFree (pCtx->sMb.pInterPredictionDoneFlag[i], "pCtx->sMb.pInterPredictionDoneFlag[]");
1192
1193 pCtx->sMb.pInterPredictionDoneFlag[i] = NULL;
1194 }
1195 WelsFree (pDq, "pDq");
1196
1197 pDq = NULL;
1198 pCtx->pDqLayersList[i] = NULL;
1199
1200 ++ i;
1201 } while (i < LAYER_NUM_EXCHANGEABLE);
1202
1203 pCtx->iPicWidthReq = 0;
1204 pCtx->iPicHeightReq = 0;
1205 pCtx->bInitialDqLayersMem = false;
1259}1206}
1260 1207
1261void_t ResetCurrentAccessUnit ( PWelsDecoderContext pCtx )1208void_t ResetCurrentAccessUnit (PWelsDecoderContext pCtx) {
1262{1209 PAccessUnit pCurAu = pCtx->pAccessUnitList;
1263 PAccessUnit pCurAu = pCtx->pAccessUnitList;1210
1264 1211 pCurAu->uiEndPos = 0;
1265 pCurAu->uiEndPos = 0;1212 pCurAu->bCompletedAuFlag = false;
1266 pCurAu->bCompletedAuFlag = false;1213 if (pCurAu->uiActualUnitsNum > 0) {
1267 if (pCurAu->uiActualUnitsNum > 0){1214 uint32_t iIdx = 0;
1268 uint32_t iIdx = 0;1215 const uint32_t kuiActualNum = pCurAu->uiActualUnitsNum;
1269 const uint32_t kuiActualNum = pCurAu->uiActualUnitsNum; 1216 // a more simpler method to do nal units list management prefered here
1270 // a more simpler method to do nal units list management prefered here 1217 const uint32_t kuiAvailNum = pCurAu->uiAvailUnitsNum;
1271 const uint32_t kuiAvailNum = pCurAu->uiAvailUnitsNum;1218 const uint32_t kuiLeftNum = kuiAvailNum - kuiActualNum;
1272 const uint32_t kuiLeftNum = kuiAvailNum - kuiActualNum; 1219
1273 1220 // Swapping active nal unit nodes of succeeding AU with leading of list
1274 // Swapping active nal unit nodes of succeeding AU with leading of list1221 while (iIdx < kuiLeftNum) {
1275 while (iIdx < kuiLeftNum)1222 PNalUnit t = pCurAu->pNalUnitsList[kuiActualNum + iIdx];
1276 {1223 pCurAu->pNalUnitsList[kuiActualNum + iIdx] = pCurAu->pNalUnitsList[iIdx];
1277 PNalUnit t = pCurAu->pNalUnitsList[kuiActualNum+iIdx];1224 pCurAu->pNalUnitsList[iIdx] = t;
1278 pCurAu->pNalUnitsList[kuiActualNum+iIdx] = pCurAu->pNalUnitsList[iIdx];1225 ++ iIdx;
1279 pCurAu->pNalUnitsList[iIdx] = t;1226 }
1280 ++ iIdx;1227 pCurAu->uiActualUnitsNum = pCurAu->uiAvailUnitsNum = kuiLeftNum;
1281 }1228 }
1282 pCurAu->uiActualUnitsNum = pCurAu->uiAvailUnitsNum = kuiLeftNum;
1283 }
1284}1229}
1285 1230
1286/*!1231/*!
@@ -1288,396 +1233,341 @@ void_t ResetCurrentAccessUnit ( PWelsDecoderContext pCtx ) · 1 unmodified line
1288 * \author1233 * \author
1289 * \history 11/16/20091234 * \history 11/16/2009
1290 */1235 */
1291void_t ForceResetCurrentAccessUnit( PAccessUnit pAu )1236void_t ForceResetCurrentAccessUnit (PAccessUnit pAu) {
1292{1237 uint32_t uiSucAuIdx = pAu->uiEndPos + 1;
1293 uint32_t uiSucAuIdx = pAu->uiEndPos + 1;1238 uint32_t uiCurAuIdx = 0;
1294 uint32_t uiCurAuIdx = 0;1239
1295 1240 // swap the succeeding AU's nal units to the front
1296 // swap the succeeding AU's nal units to the front1241 while (uiSucAuIdx < pAu->uiAvailUnitsNum) {
1297 while(uiSucAuIdx < pAu->uiAvailUnitsNum)1242 PNalUnit t = pAu->pNalUnitsList[uiSucAuIdx];
1298 {1243 pAu->pNalUnitsList[uiSucAuIdx] = pAu->pNalUnitsList[uiCurAuIdx];
1299 PNalUnit t = pAu->pNalUnitsList[uiSucAuIdx];1244 pAu->pNalUnitsList[uiCurAuIdx] = t;
1300 pAu->pNalUnitsList[uiSucAuIdx] = pAu->pNalUnitsList[uiCurAuIdx];1245 ++ uiSucAuIdx;
1301 pAu->pNalUnitsList[uiCurAuIdx] = t;1246 ++ uiCurAuIdx;
1302 ++ uiSucAuIdx;1247 }
1303 ++ uiCurAuIdx;1248
1304 }1249 // Update avail/actual units num accordingly for next AU parsing
1305 1250 if (pAu->uiAvailUnitsNum > pAu->uiEndPos)
1306 // Update avail/actual units num accordingly for next AU parsing1251 pAu->uiAvailUnitsNum -= (pAu->uiEndPos + 1);
1307 if ( pAu->uiAvailUnitsNum > pAu->uiEndPos )1252 else
1308 pAu->uiAvailUnitsNum -= (pAu->uiEndPos+1);1253 pAu->uiAvailUnitsNum = 0;
1309 else1254 pAu->uiActualUnitsNum = 0;
1310 pAu->uiAvailUnitsNum = 0;1255 pAu->uiEndPos = 0;
1311 pAu->uiActualUnitsNum = 0;1256 pAu->bCompletedAuFlag = false;
1312 pAu->uiEndPos = 0;
1313 pAu->bCompletedAuFlag = false;
1314}1257}
1315 1258
1316//clear current corrupted NAL from pNalUnitsList1259//clear current corrupted NAL from pNalUnitsList
1317void_t ForceClearCurrentNal( PAccessUnit pAu )1260void_t ForceClearCurrentNal (PAccessUnit pAu) {
1318{ 1261 if (pAu->uiAvailUnitsNum > 0)
1319 if (pAu->uiAvailUnitsNum > 0)1262 -- pAu->uiAvailUnitsNum;
1320 -- pAu->uiAvailUnitsNum;
1321}1263}
1322 1264
1323 1265
1324void_t CheckAvailNalUnitsListContinuity( PWelsDecoderContext pCtx, int32_t iStartIdx, int32_t iEndIdx )1266void_t CheckAvailNalUnitsListContinuity (PWelsDecoderContext pCtx, int32_t iStartIdx, int32_t iEndIdx) {
1325{1267 PAccessUnit pCurAu = pCtx->pAccessUnitList;
1326 PAccessUnit pCurAu = pCtx->pAccessUnitList;1268
1327 1269 uint8_t uiLastNuDependencyId, uiLastNuLayerDqId;
1328 uint8_t uiLastNuDependencyId, uiLastNuLayerDqId;1270 uint8_t uiCurNuDependencyId, uiCurNuQualityId, uiCurNuLayerDqId, uiCurNuRefLayerDqId;
1329 uint8_t uiCurNuDependencyId, uiCurNuQualityId, uiCurNuLayerDqId, uiCurNuRefLayerDqId;1271
1330 1272 int32_t iCurNalUnitIdx = 0;
1331 int32_t iCurNalUnitIdx = 0; 1273
1332 1274 //check the continuity of pNalUnitsList forwards (from pIdxNoInterLayerPred to end_postion)
1333 //check the continuity of pNalUnitsList forwards (from pIdxNoInterLayerPred to end_postion) 1275 uiLastNuDependencyId = pCurAu->pNalUnitsList[iStartIdx]->sNalHeaderExt.uiDependencyId;//starting nal unit
1334 uiLastNuDependencyId = pCurAu->pNalUnitsList[iStartIdx]->sNalHeaderExt.uiDependencyId;//starting nal unit1276 uiLastNuLayerDqId = pCurAu->pNalUnitsList[iStartIdx]->sNalHeaderExt.uiLayerDqId;//starting nal unit
1335 uiLastNuLayerDqId = pCurAu->pNalUnitsList[iStartIdx]->sNalHeaderExt.uiLayerDqId;//starting nal unit1277 iCurNalUnitIdx = iStartIdx + 1;//current nal unit
1336 iCurNalUnitIdx = iStartIdx + 1;//current nal unit1278 while (iCurNalUnitIdx <= iEndIdx) {
1337 while ( iCurNalUnitIdx <= iEndIdx )1279 uiCurNuDependencyId = pCurAu->pNalUnitsList[iCurNalUnitIdx]->sNalHeaderExt.uiDependencyId;
1338 {1280 uiCurNuQualityId = pCurAu->pNalUnitsList[iCurNalUnitIdx]->sNalHeaderExt.uiQualityId;
1339 uiCurNuDependencyId = pCurAu->pNalUnitsList[iCurNalUnitIdx]->sNalHeaderExt.uiDependencyId;1281 uiCurNuLayerDqId = pCurAu->pNalUnitsList[iCurNalUnitIdx]->sNalHeaderExt.uiLayerDqId;
1340 uiCurNuQualityId = pCurAu->pNalUnitsList[iCurNalUnitIdx]->sNalHeaderExt.uiQualityId;1282 uiCurNuRefLayerDqId = pCurAu->pNalUnitsList[iCurNalUnitIdx]->sNalData.sVclNal.sSliceHeaderExt.uiRefLayerDqId;
1341 uiCurNuLayerDqId = pCurAu->pNalUnitsList[iCurNalUnitIdx]->sNalHeaderExt.uiLayerDqId;1283
1342 uiCurNuRefLayerDqId = pCurAu->pNalUnitsList[iCurNalUnitIdx]->sNalData.sVclNal.sSliceHeaderExt.uiRefLayerDqId;1284 if (uiCurNuDependencyId == uiLastNuDependencyId) {
1343 1285 uiLastNuLayerDqId = uiCurNuLayerDqId;
1344 if ( uiCurNuDependencyId == uiLastNuDependencyId ) 1286 ++ iCurNalUnitIdx;
1345 {1287 } else { //uiCurNuDependencyId != uiLastNuDependencyId, new dependency arrive
1346 uiLastNuLayerDqId = uiCurNuLayerDqId;1288 if (uiCurNuQualityId == 0) {
1347 ++ iCurNalUnitIdx;1289 uiLastNuDependencyId = uiCurNuDependencyId;
1348 }1290 if (uiCurNuRefLayerDqId == uiLastNuLayerDqId) {
1349 else //uiCurNuDependencyId != uiLastNuDependencyId, new dependency arrive1291 uiLastNuLayerDqId = uiCurNuLayerDqId;
1350 {1292 ++ iCurNalUnitIdx;
1351 if ( uiCurNuQualityId == 0 ) 1293 } else { //cur_nu_layer_id != next_nu_ref_layer_dq_id, the chain is broken at this point
1352 {1294 break;
1353 uiLastNuDependencyId = uiCurNuDependencyId;1295 }
1354 if ( uiCurNuRefLayerDqId == uiLastNuLayerDqId ) 1296 } else { //new dependency arrive, but no base quality layer, so we must stop in this point
1355 {1297 break;
1356 uiLastNuLayerDqId = uiCurNuLayerDqId;1298 }
1357 ++ iCurNalUnitIdx;1299 }
1358 }1300 }
1359 else //cur_nu_layer_id != next_nu_ref_layer_dq_id, the chain is broken at this point1301
1360 {1302 -- iCurNalUnitIdx;
1361 break;1303 pCurAu->uiEndPos = iCurNalUnitIdx;
1362 }1304 pCtx->uiTargetDqId = pCurAu->pNalUnitsList[iCurNalUnitIdx]->sNalHeaderExt.uiLayerDqId;
1363 }
1364 else //new dependency arrive, but no base quality layer, so we must stop in this point
1365 {
1366 break;
1367 }
1368 }
1369 }
1370
1371 -- iCurNalUnitIdx;
1372 pCurAu->uiEndPos = iCurNalUnitIdx;
1373 pCtx->uiTargetDqId = pCurAu->pNalUnitsList[iCurNalUnitIdx]->sNalHeaderExt.uiLayerDqId;
1374}1305}
1375 1306
1376//main purpose: to support multi-slice and to include all slice which have the same uiDependencyId, uiQualityId and frame_num1307//main purpose: to support multi-slice and to include all slice which have the same uiDependencyId, uiQualityId and frame_num
1377//for single slice, pIdxNoInterLayerPred SHOULD NOT be modified1308//for single slice, pIdxNoInterLayerPred SHOULD NOT be modified
1378void_t RefineIdxNoInterLayerPred( PAccessUnit pCurAu, int32_t* pIdxNoInterLayerPred )1309void_t RefineIdxNoInterLayerPred (PAccessUnit pCurAu, int32_t* pIdxNoInterLayerPred) {
1379{1310 int32_t iLastNalDependId = pCurAu->pNalUnitsList[*pIdxNoInterLayerPred]->sNalHeaderExt.uiDependencyId;
1380 int32_t iLastNalDependId = pCurAu->pNalUnitsList[*pIdxNoInterLayerPred]->sNalHeaderExt.uiDependencyId;1311 int32_t iLastNalQualityId = pCurAu->pNalUnitsList[*pIdxNoInterLayerPred]->sNalHeaderExt.uiQualityId;
1381 int32_t iLastNalQualityId = pCurAu->pNalUnitsList[*pIdxNoInterLayerPred]->sNalHeaderExt.uiQualityId;1312 uint8_t uiLastNalTId = pCurAu->pNalUnitsList[*pIdxNoInterLayerPred]->sNalHeaderExt.uiTemporalId;
1382 uint8_t uiLastNalTId = pCurAu->pNalUnitsList[*pIdxNoInterLayerPred]->sNalHeaderExt.uiTemporalId;1313 int32_t iLastNalFrameNum =
1383 int32_t iLastNalFrameNum = pCurAu->pNalUnitsList[*pIdxNoInterLayerPred]->sNalData.sVclNal.sSliceHeaderExt.sSliceHeader.iFrameNum;1314 pCurAu->pNalUnitsList[*pIdxNoInterLayerPred]->sNalData.sVclNal.sSliceHeaderExt.sSliceHeader.iFrameNum;
1384 int32_t iLastNalPoc = pCurAu->pNalUnitsList[*pIdxNoInterLayerPred]->sNalData.sVclNal.sSliceHeaderExt.sSliceHeader.iPicOrderCntLsb;1315 int32_t iLastNalPoc =
1385 int32_t iLastNalFirstMb = pCurAu->pNalUnitsList[*pIdxNoInterLayerPred]->sNalData.sVclNal.sSliceHeaderExt.sSliceHeader.iFirstMbInSlice;1316 pCurAu->pNalUnitsList[*pIdxNoInterLayerPred]->sNalData.sVclNal.sSliceHeaderExt.sSliceHeader.iPicOrderCntLsb;
1386 int32_t iCurNalDependId, iCurNalQualityId, iCurNalTId, iCurNalFrameNum, iCurNalPoc, iCurNalFirstMb, iCurIdx, iFinalIdxNoInterLayerPred;1317 int32_t iLastNalFirstMb =
1387 1318 pCurAu->pNalUnitsList[*pIdxNoInterLayerPred]->sNalData.sVclNal.sSliceHeaderExt.sSliceHeader.iFirstMbInSlice;
1388 bool_t bMultiSliceFind = false;1319 int32_t iCurNalDependId, iCurNalQualityId, iCurNalTId, iCurNalFrameNum, iCurNalPoc, iCurNalFirstMb, iCurIdx,
1389 1320 iFinalIdxNoInterLayerPred;
1390 iFinalIdxNoInterLayerPred = 0;1321
1391 iCurIdx = *pIdxNoInterLayerPred - 1;1322 bool_t bMultiSliceFind = false;
1392 while ( iCurIdx >= 0 )1323
1393 {1324 iFinalIdxNoInterLayerPred = 0;
1394 if ( pCurAu->pNalUnitsList[iCurIdx]->sNalHeaderExt.iNoInterLayerPredFlag )1325 iCurIdx = *pIdxNoInterLayerPred - 1;
1395 {1326 while (iCurIdx >= 0) {
1396 iCurNalDependId = pCurAu->pNalUnitsList[iCurIdx]->sNalHeaderExt.uiDependencyId;1327 if (pCurAu->pNalUnitsList[iCurIdx]->sNalHeaderExt.iNoInterLayerPredFlag) {
1397 iCurNalQualityId = pCurAu->pNalUnitsList[iCurIdx]->sNalHeaderExt.uiQualityId;1328 iCurNalDependId = pCurAu->pNalUnitsList[iCurIdx]->sNalHeaderExt.uiDependencyId;
1398 iCurNalTId = pCurAu->pNalUnitsList[iCurIdx]->sNalHeaderExt.uiTemporalId;1329 iCurNalQualityId = pCurAu->pNalUnitsList[iCurIdx]->sNalHeaderExt.uiQualityId;
1399 iCurNalFrameNum = pCurAu->pNalUnitsList[iCurIdx]->sNalData.sVclNal.sSliceHeaderExt.sSliceHeader.iFrameNum;1330 iCurNalTId = pCurAu->pNalUnitsList[iCurIdx]->sNalHeaderExt.uiTemporalId;
1400 iCurNalPoc = pCurAu->pNalUnitsList[iCurIdx]->sNalData.sVclNal.sSliceHeaderExt.sSliceHeader.iPicOrderCntLsb;1331 iCurNalFrameNum = pCurAu->pNalUnitsList[iCurIdx]->sNalData.sVclNal.sSliceHeaderExt.sSliceHeader.iFrameNum;
1401 iCurNalFirstMb = pCurAu->pNalUnitsList[iCurIdx]->sNalData.sVclNal.sSliceHeaderExt.sSliceHeader.iFirstMbInSlice;1332 iCurNalPoc = pCurAu->pNalUnitsList[iCurIdx]->sNalData.sVclNal.sSliceHeaderExt.sSliceHeader.iPicOrderCntLsb;
1402 1333 iCurNalFirstMb = pCurAu->pNalUnitsList[iCurIdx]->sNalData.sVclNal.sSliceHeaderExt.sSliceHeader.iFirstMbInSlice;
1403 if ( iCurNalDependId == iLastNalDependId && 1334
1404 iCurNalQualityId == iLastNalQualityId && 1335 if (iCurNalDependId == iLastNalDependId &&
1405 iCurNalTId == uiLastNalTId &&1336 iCurNalQualityId == iLastNalQualityId &&
1406 iCurNalFrameNum == iLastNalFrameNum && 1337 iCurNalTId == uiLastNalTId &&
1407 iCurNalPoc == iLastNalPoc &&1338 iCurNalFrameNum == iLastNalFrameNum &&
1408 iCurNalFirstMb != iLastNalFirstMb ) 1339 iCurNalPoc == iLastNalPoc &&
1409 {1340 iCurNalFirstMb != iLastNalFirstMb) {
1410 bMultiSliceFind = true;1341 bMultiSliceFind = true;
1411 iFinalIdxNoInterLayerPred = iCurIdx;1342 iFinalIdxNoInterLayerPred = iCurIdx;
1412 --iCurIdx;1343 --iCurIdx;
1413 continue;1344 continue;
1414 }1345 } else {
1415 else1346 break;
1416 {1347 }
1417 break;1348 }
1418 }1349 --iCurIdx;
1419 }1350 }
1420 --iCurIdx;1351
1421 }1352 if (bMultiSliceFind && *pIdxNoInterLayerPred != iFinalIdxNoInterLayerPred) {
1422 1353 *pIdxNoInterLayerPred = iFinalIdxNoInterLayerPred;
1423 if ( bMultiSliceFind && *pIdxNoInterLayerPred != iFinalIdxNoInterLayerPred )1354 }
1424 {
1425 *pIdxNoInterLayerPred = iFinalIdxNoInterLayerPred;
1426 }
1427}1355}
1428 1356
1429bool_t CheckPocOfCurValidNalUnits( PAccessUnit pCurAu, int32_t pIdxNoInterLayerPred )1357bool_t CheckPocOfCurValidNalUnits (PAccessUnit pCurAu, int32_t pIdxNoInterLayerPred) {
1430{ 1358 int32_t iEndIdx = pCurAu->uiEndPos;
1431 int32_t iEndIdx = pCurAu->uiEndPos;1359 int32_t iCurAuPoc =
1432 int32_t iCurAuPoc = pCurAu->pNalUnitsList[pIdxNoInterLayerPred]->sNalData.sVclNal.sSliceHeaderExt.sSliceHeader.iPicOrderCntLsb;1360 pCurAu->pNalUnitsList[pIdxNoInterLayerPred]->sNalData.sVclNal.sSliceHeaderExt.sSliceHeader.iPicOrderCntLsb;
1433 int32_t iTmpPoc, i;1361 int32_t iTmpPoc, i;
1434 for ( i = pIdxNoInterLayerPred+1; i < iEndIdx; i++ )1362 for (i = pIdxNoInterLayerPred + 1; i < iEndIdx; i++) {
1435 {1363 iTmpPoc = pCurAu->pNalUnitsList[i]->sNalData.sVclNal.sSliceHeaderExt.sSliceHeader.iPicOrderCntLsb;
1436 iTmpPoc = pCurAu->pNalUnitsList[i]->sNalData.sVclNal.sSliceHeaderExt.sSliceHeader.iPicOrderCntLsb;1364 if (iTmpPoc != iCurAuPoc) {
1437 if ( iTmpPoc != iCurAuPoc )1365 return false;
1438 {1366 }
1439 return false;1367 }
1440 }1368
1441 }1369 return true;
1442
1443 return true;
1444}1370}
1445 1371
1446bool_t CheckIntegrityNalUnitsList( PWelsDecoderContext pCtx )1372bool_t CheckIntegrityNalUnitsList (PWelsDecoderContext pCtx) {
1447{1373 PAccessUnit pCurAu = pCtx->pAccessUnitList;
1448 PAccessUnit pCurAu = pCtx->pAccessUnitList;1374 const int32_t kiEndPos = pCurAu->uiEndPos;
1449 const int32_t kiEndPos = pCurAu->uiEndPos;1375 int32_t iIdxNoInterLayerPred = 0;
1450 int32_t iIdxNoInterLayerPred = 0;1376 int32_t iCurNalUnitIdx = kiEndPos;
1451 int32_t iCurNalUnitIdx = kiEndPos;1377
1452 1378 ESliceType eSliceType = static_cast<ESliceType> (0);//EC 2009.11.12
1453 ESliceType eSliceType = static_cast<ESliceType> (0);//EC 2009.11.121379
1454 1380 if (!pCurAu->bCompletedAuFlag)
1455 if ( !pCurAu->bCompletedAuFlag )1381 return false;
1456 return false;1382
1457 1383 eSliceType = pCurAu->pNalUnitsList[iCurNalUnitIdx]->sNalData.sVclNal.sSliceHeaderExt.sSliceHeader.eSliceType;
1458 eSliceType = pCurAu->pNalUnitsList[iCurNalUnitIdx]->sNalData.sVclNal.sSliceHeaderExt.sSliceHeader.eSliceType;1384
1459 1385 if (I_SLICE == eSliceType) {
1460 if ( I_SLICE == eSliceType )1386 pCurAu->uiStartPos = 0;
1461 {1387 //step1: search the pNalUnit whose iNoInterLayerPredFlag equal to 1 backwards (from uiEndPos to 0)
1462 pCurAu->uiStartPos = 0;1388 iIdxNoInterLayerPred = kiEndPos;
1463 //step1: search the pNalUnit whose iNoInterLayerPredFlag equal to 1 backwards (from uiEndPos to 0)1389 while (iIdxNoInterLayerPred >= 0) {
1464 iIdxNoInterLayerPred = kiEndPos;1390 if (pCurAu->pNalUnitsList[iIdxNoInterLayerPred]->sNalHeaderExt.iNoInterLayerPredFlag) {
1465 while ( iIdxNoInterLayerPred >= 0 ) 1391 break;
1466 {1392 }
1467 if ( pCurAu->pNalUnitsList[iIdxNoInterLayerPred]->sNalHeaderExt.iNoInterLayerPredFlag ) 1393 --iIdxNoInterLayerPred;
1468 {1394 }
1469 break;1395 if (iIdxNoInterLayerPred < 0) {
1470 }1396 //can not find the Nal Unit whose no_inter_pred_falg equal to 1, MUST STOP decode
1471 --iIdxNoInterLayerPred;1397 return false;
1472 }1398 }
1473 if ( iIdxNoInterLayerPred < 0 )1399
1474 {1400 //step2: support multi-slice, to include all base layer slice
1475 //can not find the Nal Unit whose no_inter_pred_falg equal to 1, MUST STOP decode1401 RefineIdxNoInterLayerPred (pCurAu, &iIdxNoInterLayerPred);
1476 return false;1402 pCurAu->uiStartPos = iIdxNoInterLayerPred;
1477 } 1403 CheckAvailNalUnitsListContinuity (pCtx, iIdxNoInterLayerPred, kiEndPos);
1478 1404
1479 //step2: support multi-slice, to include all base layer slice1405 if (!CheckPocOfCurValidNalUnits (pCurAu, iIdxNoInterLayerPred)) {
1480 RefineIdxNoInterLayerPred( pCurAu, &iIdxNoInterLayerPred ); 1406 return false;
1481 pCurAu->uiStartPos = iIdxNoInterLayerPred;1407 }
1482 CheckAvailNalUnitsListContinuity( pCtx, iIdxNoInterLayerPred, kiEndPos );1408
1483 1409 pCtx->iCurSeqIntervalTargetDependId = pCurAu->pNalUnitsList[pCurAu->uiEndPos]->sNalHeaderExt.uiDependencyId;
1484 if ( !CheckPocOfCurValidNalUnits( pCurAu, iIdxNoInterLayerPred ) ) 1410 pCtx->iCurSeqIntervalMaxPicWidth =
1485 {1411 pCurAu->pNalUnitsList[pCurAu->uiEndPos]->sNalData.sVclNal.sSliceHeaderExt.sSliceHeader.iMbWidth << 4;
1486 return false;1412 pCtx->iCurSeqIntervalMaxPicHeight =
1487 }1413 pCurAu->pNalUnitsList[pCurAu->uiEndPos]->sNalData.sVclNal.sSliceHeaderExt.sSliceHeader.iMbHeight << 4;
1488 1414 } else { //P_SLICE
1489 pCtx->iCurSeqIntervalTargetDependId = pCurAu->pNalUnitsList[pCurAu->uiEndPos]->sNalHeaderExt.uiDependencyId;1415 //step 1: search uiDependencyId equal to pCtx->cur_seq_interval_target_dependency_id
1490 pCtx->iCurSeqIntervalMaxPicWidth = pCurAu->pNalUnitsList[pCurAu->uiEndPos]->sNalData.sVclNal.sSliceHeaderExt.sSliceHeader.iMbWidth << 4;1416 bool_t bGetDependId = false;
1491 pCtx->iCurSeqIntervalMaxPicHeight = pCurAu->pNalUnitsList[pCurAu->uiEndPos]->sNalData.sVclNal.sSliceHeaderExt.sSliceHeader.iMbHeight << 4;1417 int32_t iIdxDependId = 0;
1492 }1418
1493 else //P_SLICE1419 iIdxDependId = kiEndPos;
1494 {1420 while (iIdxDependId >= 0) {
1495 //step 1: search uiDependencyId equal to pCtx->cur_seq_interval_target_dependency_id1421 if (pCtx->iCurSeqIntervalTargetDependId == pCurAu->pNalUnitsList[iIdxDependId]->sNalHeaderExt.uiDependencyId) {
1496 bool_t bGetDependId = false;1422 bGetDependId = true;
1497 int32_t iIdxDependId = 0;1423 break;
1498 1424 } else {
1499 iIdxDependId = kiEndPos;1425 --iIdxDependId;
1500 while ( iIdxDependId >= 0 ) 1426 }
1501 {1427 }
1502 if ( pCtx->iCurSeqIntervalTargetDependId == pCurAu->pNalUnitsList[iIdxDependId]->sNalHeaderExt.uiDependencyId )1428
1503 {1429 //step 2: switch according to whether or not find the index of pNalUnit whose uiDependencyId equal to iCurSeqIntervalTargetDependId
1504 bGetDependId = true;1430 if (bGetDependId) { //get the index of pNalUnit whose uiDependencyId equal to iCurSeqIntervalTargetDependId
1505 break;1431 bool_t bGetNoInterPredFront = false;
1506 }1432 //step 2a: search iNoInterLayerPredFlag [0....iIdxDependId]
1507 else1433 iIdxNoInterLayerPred = iIdxDependId;
1508 {1434 while (iIdxNoInterLayerPred >= 0) {
1509 --iIdxDependId;1435 if (pCurAu->pNalUnitsList[iIdxNoInterLayerPred]->sNalHeaderExt.iNoInterLayerPredFlag) {
1510 }1436 bGetNoInterPredFront = true;
1511 }1437 break;
1512 1438 }
1513 //step 2: switch according to whether or not find the index of pNalUnit whose uiDependencyId equal to iCurSeqIntervalTargetDependId1439 --iIdxNoInterLayerPred;
1514 if ( bGetDependId ) //get the index of pNalUnit whose uiDependencyId equal to iCurSeqIntervalTargetDependId1440 }
1515 {1441 //step 2b: switch, whether or not find the NAL unit whose no_inter_pred_flag equal to 1 among [0....iIdxDependId]
1516 bool_t bGetNoInterPredFront = false;1442 if (bGetNoInterPredFront) { //YES
1517 //step 2a: search iNoInterLayerPredFlag [0....iIdxDependId]1443 RefineIdxNoInterLayerPred (pCurAu, &iIdxNoInterLayerPred);
1518 iIdxNoInterLayerPred = iIdxDependId;1444 pCurAu->uiStartPos = iIdxNoInterLayerPred;
1519 while ( iIdxNoInterLayerPred >= 0 )1445 CheckAvailNalUnitsListContinuity (pCtx, iIdxNoInterLayerPred, iIdxDependId);
1520 {1446
1521 if ( pCurAu->pNalUnitsList[iIdxNoInterLayerPred]->sNalHeaderExt.iNoInterLayerPredFlag )1447 if (!CheckPocOfCurValidNalUnits (pCurAu, iIdxNoInterLayerPred)) {
1522 {1448 return false;
1523 bGetNoInterPredFront = true;1449 }
1524 break;1450 } else { //NO, should find the NAL unit whose no_inter_pred_flag equal to 1 among [iIdxDependId....uiEndPos]
1525 }1451 iIdxNoInterLayerPred = iIdxDependId;
1526 --iIdxNoInterLayerPred;1452 while (iIdxNoInterLayerPred <= kiEndPos) {
1527 }1453 if (pCurAu->pNalUnitsList[iIdxNoInterLayerPred]->sNalHeaderExt.iNoInterLayerPredFlag) {
1528 //step 2b: switch, whether or not find the NAL unit whose no_inter_pred_flag equal to 1 among [0....iIdxDependId] 1454 break;
1529 if ( bGetNoInterPredFront ) //YES1455 }
1530 {1456 ++iIdxNoInterLayerPred;
1531 RefineIdxNoInterLayerPred( pCurAu, &iIdxNoInterLayerPred );1457 }
1532 pCurAu->uiStartPos = iIdxNoInterLayerPred;1458
1533 CheckAvailNalUnitsListContinuity( pCtx, iIdxNoInterLayerPred, iIdxDependId );1459 if (iIdxNoInterLayerPred > kiEndPos) {
1534 1460 return false; //cann't find the index of pNalUnit whose no_inter_pred_flag = 1
1535 if ( !CheckPocOfCurValidNalUnits( pCurAu, iIdxNoInterLayerPred ) ) 1461 }
1536 {1462
1537 return false;1463 RefineIdxNoInterLayerPred (pCurAu, &iIdxNoInterLayerPred);
1538 }1464 pCurAu->uiStartPos = iIdxNoInterLayerPred;
1539 }1465 CheckAvailNalUnitsListContinuity (pCtx, iIdxNoInterLayerPred, kiEndPos);
1540 else //NO, should find the NAL unit whose no_inter_pred_flag equal to 1 among [iIdxDependId....uiEndPos]1466
1541 {1467 if (!CheckPocOfCurValidNalUnits (pCurAu, iIdxNoInterLayerPred)) {
1542 iIdxNoInterLayerPred = iIdxDependId;1468 return false;
1543 while ( iIdxNoInterLayerPred <= kiEndPos )1469 }
1544 {1470 }
1545 if ( pCurAu->pNalUnitsList[iIdxNoInterLayerPred]->sNalHeaderExt.iNoInterLayerPredFlag )1471 } else { //without the index of pNalUnit, should process this AU as common case
1546 {1472 iIdxNoInterLayerPred = kiEndPos;
1547 break;1473 while (iIdxNoInterLayerPred >= 0) {
1548 } 1474 if (pCurAu->pNalUnitsList[iIdxNoInterLayerPred]->sNalHeaderExt.iNoInterLayerPredFlag) {
1549 ++iIdxNoInterLayerPred;1475 break;
1550 }1476 }
1551 1477 --iIdxNoInterLayerPred;
1552 if ( iIdxNoInterLayerPred > kiEndPos )1478 }
1553 {1479 if (iIdxNoInterLayerPred < 0) {
1554 return false; //cann't find the index of pNalUnit whose no_inter_pred_flag = 11480 return false; //cann't find the index of pNalUnit whose iNoInterLayerPredFlag = 1
1555 }1481 }
1556 1482
1557 RefineIdxNoInterLayerPred( pCurAu, &iIdxNoInterLayerPred ); 1483 RefineIdxNoInterLayerPred (pCurAu, &iIdxNoInterLayerPred);
1558 pCurAu->uiStartPos = iIdxNoInterLayerPred;1484 pCurAu->uiStartPos = iIdxNoInterLayerPred;
1559 CheckAvailNalUnitsListContinuity( pCtx, iIdxNoInterLayerPred, kiEndPos );1485 CheckAvailNalUnitsListContinuity (pCtx, iIdxNoInterLayerPred, kiEndPos);
1560 1486
1561 if ( !CheckPocOfCurValidNalUnits( pCurAu, iIdxNoInterLayerPred ) ) 1487 if (!CheckPocOfCurValidNalUnits (pCurAu, iIdxNoInterLayerPred)) {
1562 {1488 return false;
1563 return false;1489 }
1564 } 1490 }
1565 }1491 }
1566 }1492
1567 else //without the index of pNalUnit, should process this AU as common case1493 return true;
1568 {
1569 iIdxNoInterLayerPred = kiEndPos;
1570 while (iIdxNoInterLayerPred >= 0)
1571 {
1572 if ( pCurAu->pNalUnitsList[iIdxNoInterLayerPred]->sNalHeaderExt.iNoInterLayerPredFlag )
1573 {
1574 break;
1575 }
1576 --iIdxNoInterLayerPred;
1577 }
1578 if (iIdxNoInterLayerPred < 0)
1579 {
1580 return false; //cann't find the index of pNalUnit whose iNoInterLayerPredFlag = 1
1581 }
1582
1583 RefineIdxNoInterLayerPred( pCurAu, &iIdxNoInterLayerPred );
1584 pCurAu->uiStartPos = iIdxNoInterLayerPred;
1585 CheckAvailNalUnitsListContinuity( pCtx, iIdxNoInterLayerPred, kiEndPos );
1586
1587 if ( !CheckPocOfCurValidNalUnits( pCurAu, iIdxNoInterLayerPred ) )
1588 {
1589 return false;
1590 }
1591 }
1592 }
1593
1594 return true;
1595}1494}
1596 1495
1597void_t CheckOnlyOneLayerInAu( PWelsDecoderContext pCtx )1496void_t CheckOnlyOneLayerInAu (PWelsDecoderContext pCtx) {
1598{1497 PAccessUnit pCurAu = pCtx->pAccessUnitList;
1599 PAccessUnit pCurAu = pCtx->pAccessUnitList;
1600 1498
1601 int32_t iEndIdx = pCurAu->uiEndPos; 1499 int32_t iEndIdx = pCurAu->uiEndPos;
1602 int32_t iCurIdx = pCurAu->uiStartPos;1500 int32_t iCurIdx = pCurAu->uiStartPos;
1603 uint8_t uiDId = pCurAu->pNalUnitsList[iCurIdx]->sNalHeaderExt.uiDependencyId;1501 uint8_t uiDId = pCurAu->pNalUnitsList[iCurIdx]->sNalHeaderExt.uiDependencyId;
1604 uint8_t uiQId = pCurAu->pNalUnitsList[iCurIdx]->sNalHeaderExt.uiQualityId;1502 uint8_t uiQId = pCurAu->pNalUnitsList[iCurIdx]->sNalHeaderExt.uiQualityId;
1605 uint8_t uiTId = pCurAu->pNalUnitsList[iCurIdx]->sNalHeaderExt.uiTemporalId;1503 uint8_t uiTId = pCurAu->pNalUnitsList[iCurIdx]->sNalHeaderExt.uiTemporalId;
1606 1504
1607 uint8_t uiCurDId, uiCurQId, uiCurTId; 1505 uint8_t uiCurDId, uiCurQId, uiCurTId;
1608 1506
1609 pCtx->bOnlyOneLayerInCurAuFlag = true;1507 pCtx->bOnlyOneLayerInCurAuFlag = true;
1610 1508
1611 if ( iEndIdx == iCurIdx ) //only one NAL in pNalUnitsList1509 if (iEndIdx == iCurIdx) { //only one NAL in pNalUnitsList
1612 {1510 return;
1613 return;1511 }
1614 }
1615 1512
1616 ++iCurIdx;1513 ++iCurIdx;
1617 while ( iCurIdx <= iEndIdx )1514 while (iCurIdx <= iEndIdx) {
1618 {1515 uiCurDId = pCurAu->pNalUnitsList[iCurIdx]->sNalHeaderExt.uiDependencyId;
1619 uiCurDId = pCurAu->pNalUnitsList[iCurIdx]->sNalHeaderExt.uiDependencyId;1516 uiCurQId = pCurAu->pNalUnitsList[iCurIdx]->sNalHeaderExt.uiQualityId;
1620 uiCurQId = pCurAu->pNalUnitsList[iCurIdx]->sNalHeaderExt.uiQualityId;1517 uiCurTId = pCurAu->pNalUnitsList[iCurIdx]->sNalHeaderExt.uiTemporalId;
1621 uiCurTId = pCurAu->pNalUnitsList[iCurIdx]->sNalHeaderExt.uiTemporalId;
1622 1518
1623 if ( uiDId != uiCurDId || uiQId != uiCurQId || uiTId != uiCurTId )1519 if (uiDId != uiCurDId || uiQId != uiCurQId || uiTId != uiCurTId) {
1624 {1520 pCtx->bOnlyOneLayerInCurAuFlag = false;
1625 pCtx->bOnlyOneLayerInCurAuFlag = false;1521 return;
1626 return;1522 }
1627 }
1628 1523
1629 ++iCurIdx;1524 ++iCurIdx;
1630 }1525 }
1631}1526}
1632 1527
1633int32_t WelsDecodeAccessUnitStart ( PWelsDecoderContext pCtx )1528int32_t WelsDecodeAccessUnitStart (PWelsDecoderContext pCtx) {
1634{1529 // Roll back NAL units not being belong to current access unit list for proceeded access unit
1635 // Roll back NAL units not being belong to current access unit list for proceeded access unit1530 int32_t iRet = UpdateAccessUnit (pCtx);
1636 int32_t iRet = UpdateAccessUnit ( pCtx );1531 if (iRet != ERR_NONE)
1637 if ( iRet != ERR_NONE )1532 return iRet;
1638 return iRet;1533
1639 1534 pCtx->pAccessUnitList->uiStartPos = 0;
1640 pCtx->pAccessUnitList->uiStartPos = 0;1535 if (!pCtx->bAvcBasedFlag && !CheckIntegrityNalUnitsList (pCtx)) {
1641 if ( !pCtx->bAvcBasedFlag && !CheckIntegrityNalUnitsList( pCtx ) ) 1536 pCtx->iErrorCode |= dsBitstreamError;
1642 {1537 return dsBitstreamError;
1643 pCtx->iErrorCode |= dsBitstreamError;1538 }
1644 return dsBitstreamError;1539
1645 }1540 //check current AU has only one layer or not
1646 1541 //If YES, can use deblocking based on AVC
1647 //check current AU has only one layer or not1542 if (!pCtx->bAvcBasedFlag) {
1648 //If YES, can use deblocking based on AVC1543 CheckOnlyOneLayerInAu (pCtx);
1649 if ( !pCtx->bAvcBasedFlag )1544 }
1650 {1545
1651 CheckOnlyOneLayerInAu( pCtx );1546 return ERR_NONE;
1652 }
1653
1654 return ERR_NONE;
1655}1547}
1656 1548
1657void_t WelsDecodeAccessUnitEnd ( PWelsDecoderContext pCtx )1549void_t WelsDecodeAccessUnitEnd (PWelsDecoderContext pCtx) {
1658{1550 // uninitialize context of current access unit and rbsp buffer clean
1659 // uninitialize context of current access unit and rbsp buffer clean1551 ResetCurrentAccessUnit (pCtx);
1660 ResetCurrentAccessUnit ( pCtx );
1661}1552}
1662 1553
1663 1554
1664int32_t CheckBSBound(int32_t iWidth, int32_t iHeight, int32_t sliceNum, int32_t ppsId)1555int32_t CheckBSBound (int32_t iWidth, int32_t iHeight, int32_t sliceNum, int32_t ppsId) {
1665{1556 int32_t iRet = 0;
1666 int32_t iRet = 0;1557
1667 1558#if defined(WIN32)
1668#if defined(WIN32) 1559 iRet = ((iWidth == 80) && (iHeight = 45) && (sliceNum < 60));
1669 iRet = ((iWidth == 80) && (iHeight = 45) && (sliceNum < 60));1560
1670 1561#elif defined(MACOS)
1671#elif defined(MACOS) 1562 iRet = ((iWidth == 80) && (iHeight = 45) && (ppsId < 57));
1672 iRet = ((iWidth == 80) && (iHeight = 45) && (ppsId < 57));1563
1673
1674#elif defined(ANDROID)1564#elif defined(ANDROID)
1675 iRet = ((iWidth == 40) && (iHeight = 22));1565 iRet = ((iWidth == 40) && (iHeight = 22));
1676 1566
1677#endif1567#endif
1678 1568
1679 return iRet;1569 return iRet;
1680 1570
1681}1571}
1682 1572
1683 1573
@@ -1694,413 +1584,399 @@ int32_t CheckBSBound(int32_t iWidth, int32_t iHeight, int32_t sliceNum, int32_t · 10 unmodified lines
1694 * return:1584 * return:
1695 * 0 - success; otherwise returned error_no defined in error_no.h1585 * 0 - success; otherwise returned error_no defined in error_no.h
1696 */1586 */
1697int32_t ConstructAccessUnit( PWelsDecoderContext pCtx, uint8_t** ppDst, SBufferInfo *pDstInfo)1587int32_t ConstructAccessUnit (PWelsDecoderContext pCtx, uint8_t** ppDst, SBufferInfo* pDstInfo) {
1698{1588 int32_t iErr;
1699 int32_t iErr;1589 int32_t iWidth;
1700 int32_t iWidth;1590 int32_t iHeight;
1701 int32_t iHeight;1591 int32_t iStride[2] = { 0 };
1702 int32_t iStride[2] = { 0 };1592
1703 1593 PAccessUnit pCurAu = pCtx->pAccessUnitList;
1704 PAccessUnit pCurAu = pCtx->pAccessUnitList;1594
1705 1595 pCtx->bAuReadyFlag = false;
1706 pCtx->bAuReadyFlag = false;1596 pCtx->bLastHasMmco5 = false;
1707 pCtx->bLastHasMmco5 = false;1597
1708 1598 iErr = WelsDecodeAccessUnitStart (pCtx);
1709 iErr = WelsDecodeAccessUnitStart( pCtx );1599 GetVclNalTemporalId (pCtx);
1710 GetVclNalTemporalId( pCtx );1600
1711 1601 if (ERR_NONE != iErr) {
1712 if ( ERR_NONE != iErr )1602 ForceResetCurrentAccessUnit (pCtx->pAccessUnitList);
1713 {1603 pDstInfo->iBufferStatus = 0;
1714 ForceResetCurrentAccessUnit( pCtx->pAccessUnitList );1604 return iErr;
1715 pDstInfo->iBufferStatus = 0;1605 }
1716 return iErr;1606
1717 }1607 pCtx->pSps = pCurAu->pNalUnitsList[pCurAu->uiStartPos]->sNalData.sVclNal.sSliceHeaderExt.sSliceHeader.pSps;
1718 1608 pCtx->pPps = pCurAu->pNalUnitsList[pCurAu->uiStartPos]->sNalData.sVclNal.sSliceHeaderExt.sSliceHeader.pPps;
1719 pCtx->pSps = pCurAu->pNalUnitsList[pCurAu->uiStartPos]->sNalData.sVclNal.sSliceHeaderExt.sSliceHeader.pSps;1609
1720 pCtx->pPps = pCurAu->pNalUnitsList[pCurAu->uiStartPos]->sNalData.sVclNal.sSliceHeaderExt.sSliceHeader.pPps;1610 //try to allocate or relocate DPB memory only when IDR arrival.
1721 1611 if (NAL_UNIT_CODED_SLICE_IDR == pCurAu->pNalUnitsList[pCurAu->uiStartPos]->sNalHeaderExt.sNalUnitHeader.eNalUnitType ||
1722 //try to allocate or relocate DPB memory only when IDR arrival.1612 pCurAu->pNalUnitsList[pCurAu->uiStartPos]->sNalHeaderExt.bIdrFlag) {
1723 if ( NAL_UNIT_CODED_SLICE_IDR == pCurAu->pNalUnitsList[pCurAu->uiStartPos]->sNalHeaderExt.sNalUnitHeader.eNalUnitType ||1613 WelsResetRefPic (pCtx); //clear ref pPic when IDR NAL
1724 pCurAu->pNalUnitsList[pCurAu->uiStartPos]->sNalHeaderExt.bIdrFlag )1614 iErr = SyncPictureResolutionExt (pCtx, (pCtx->iMaxWidthInSps + 15) >> 4, (pCtx->iMaxHeightInSps + 15) >> 4);
1725 {1615
1726 WelsResetRefPic(pCtx); //clear ref pPic when IDR NAL1616 if (ERR_NONE != iErr) {
1727 iErr = SyncPictureResolutionExt( pCtx, (pCtx->iMaxWidthInSps+15)>>4, (pCtx->iMaxHeightInSps+15)>>4 ); 1617 WelsLog (pCtx, WELS_LOG_WARNING, "sync picture resolution ext failed, the error is %d", iErr);
1728 1618 return iErr;
1729 if( ERR_NONE != iErr ){1619 }
1730 WelsLog(pCtx, WELS_LOG_WARNING, "sync picture resolution ext failed, the error is %d", iErr);1620 }
1731 return iErr;1621
1732 } 1622
1733 }1623 pDstInfo->eBufferProperty = (EBufferProperty)pCtx->iDecoderOutputProperty;
1734 1624
1735 1625 iErr = DecodeCurrentAccessUnit (pCtx, ppDst, iStride, &iWidth, &iHeight, pDstInfo);
1736 pDstInfo->eBufferProperty = (EBufferProperty)pCtx->iDecoderOutputProperty;1626
1737 1627 WelsDecodeAccessUnitEnd (pCtx);
1738 iErr = DecodeCurrentAccessUnit( pCtx, ppDst, iStride, &iWidth, &iHeight, pDstInfo );1628
1739 1629 if (ERR_NONE != iErr) {
1740 WelsDecodeAccessUnitEnd( pCtx );1630 WelsLog (pCtx, WELS_LOG_INFO, "returned error from decoding:[0x%x]\n", iErr);
1741 1631
1742 if ( ERR_NONE != iErr )1632 pDstInfo->iBufferStatus = 0;
1743 {1633 return iErr;
1744 WelsLog( pCtx, WELS_LOG_INFO, "returned error from decoding:[0x%x]\n", iErr);1634 }
1745 1635
1746 pDstInfo->iBufferStatus = 0;1636 return 0;
1747 return iErr;
1748 }
1749
1750 return 0;
1751}1637}
1752 1638
1753static inline void_t InitDqLayerInfo( PDqLayer pDqLayer, PLayerInfo pLayerInfo, PNalUnit pNalUnit, PPicture pPicDec )1639static inline void_t InitDqLayerInfo (PDqLayer pDqLayer, PLayerInfo pLayerInfo, PNalUnit pNalUnit, PPicture pPicDec) {
1754{1640 PNalUnitHeaderExt pNalHdrExt = &pNalUnit->sNalHeaderExt;
1755 PNalUnitHeaderExt pNalHdrExt = &pNalUnit->sNalHeaderExt;1641 PSliceHeaderExt pShExt = &pNalUnit->sNalData.sVclNal.sSliceHeaderExt;
1756 PSliceHeaderExt pShExt = &pNalUnit->sNalData.sVclNal.sSliceHeaderExt;1642 PSliceHeader pSh = &pShExt->sSliceHeader;
1757 PSliceHeader pSh = &pShExt->sSliceHeader;1643 const uint8_t kuiQualityId = pNalHdrExt->uiQualityId;
1758 const uint8_t kuiQualityId = pNalHdrExt->uiQualityId;1644
1759 1645 memcpy (&pDqLayer->sLayerInfo, pLayerInfo, sizeof (SLayerInfo)); //confirmed_safe_unsafe_usage
1760 memcpy(&pDqLayer->sLayerInfo, pLayerInfo, sizeof(SLayerInfo));//confirmed_safe_unsafe_usage1646
1761 1647 pDqLayer->pDec = pPicDec;
1762 pDqLayer->pDec = pPicDec;1648 pDqLayer->iMbWidth = pSh->iMbWidth; // MB width of this picture
1763 pDqLayer->iMbWidth = pSh->iMbWidth; // MB width of this picture1649 pDqLayer->iMbHeight = pSh->iMbHeight;// MB height of this picture
1764 pDqLayer->iMbHeight = pSh->iMbHeight;// MB height of this picture 1650
1765 1651 pDqLayer->iSliceIdcBackup = (pSh->iFirstMbInSlice << 7) | (pNalHdrExt->uiDependencyId << 4) | (pNalHdrExt->uiQualityId);
1766 pDqLayer->iSliceIdcBackup = (pSh->iFirstMbInSlice << 7) | (pNalHdrExt->uiDependencyId << 4) | (pNalHdrExt->uiQualityId);1652
1767 1653 /* Common syntax elements across all slices of a DQLayer */
1768 /* Common syntax elements across all slices of a DQLayer */ 1654 pDqLayer->uiPpsId = pLayerInfo->pPps->iPpsId;
1769 pDqLayer->uiPpsId = pLayerInfo->pPps->iPpsId;1655 pDqLayer->uiDisableInterLayerDeblockingFilterIdc = pShExt->uiDisableInterLayerDeblockingFilterIdc;
1770 pDqLayer->uiDisableInterLayerDeblockingFilterIdc = pShExt->uiDisableInterLayerDeblockingFilterIdc;1656 pDqLayer->iInterLayerSliceAlphaC0Offset = pShExt->iInterLayerSliceAlphaC0Offset;
1771 pDqLayer->iInterLayerSliceAlphaC0Offset = pShExt->iInterLayerSliceAlphaC0Offset;1657 pDqLayer->iInterLayerSliceBetaOffset = pShExt->iInterLayerSliceBetaOffset;
1772 pDqLayer->iInterLayerSliceBetaOffset = pShExt->iInterLayerSliceBetaOffset; 1658 pDqLayer->iSliceGroupChangeCycle = pSh->iSliceGroupChangeCycle;
1773 pDqLayer->iSliceGroupChangeCycle = pSh->iSliceGroupChangeCycle;1659 pDqLayer->bStoreRefBasePicFlag = pShExt->bStoreRefBasePicFlag;
1774 pDqLayer->bStoreRefBasePicFlag = pShExt->bStoreRefBasePicFlag;1660 pDqLayer->bTCoeffLevelPredFlag = pShExt->bTCoeffLevelPredFlag;
1775 pDqLayer->bTCoeffLevelPredFlag = pShExt->bTCoeffLevelPredFlag;1661 pDqLayer->bConstrainedIntraResamplingFlag = pShExt->bConstrainedIntraResamplingFlag;
1776 pDqLayer->bConstrainedIntraResamplingFlag = pShExt->bConstrainedIntraResamplingFlag;1662 pDqLayer->uiRefLayerDqId = pShExt->uiRefLayerDqId;
1777 pDqLayer->uiRefLayerDqId = pShExt->uiRefLayerDqId;1663 pDqLayer->uiRefLayerChromaPhaseXPlus1Flag = pShExt->uiRefLayerChromaPhaseXPlus1Flag;
1778 pDqLayer->uiRefLayerChromaPhaseXPlus1Flag = pShExt->uiRefLayerChromaPhaseXPlus1Flag;1664 pDqLayer->uiRefLayerChromaPhaseYPlus1 = pShExt->uiRefLayerChromaPhaseYPlus1;
1779 pDqLayer->uiRefLayerChromaPhaseYPlus1 = pShExt->uiRefLayerChromaPhaseYPlus1;1665 //memcpy(&pDqLayer->sScaledRefLayer, &pShExt->sScaledRefLayer, sizeof(SPosOffset));//confirmed_safe_unsafe_usage
1780 //memcpy(&pDqLayer->sScaledRefLayer, &pShExt->sScaledRefLayer, sizeof(SPosOffset));//confirmed_safe_unsafe_usage1666
1781 1667 if (kuiQualityId == BASE_QUALITY_ID) {
1782 if ( kuiQualityId == BASE_QUALITY_ID ){1668 pDqLayer->pRefPicListReordering = &pSh->pRefPicListReordering;
1783 pDqLayer->pRefPicListReordering = &pSh->pRefPicListReordering;1669 pDqLayer->pRefPicMarking = &pSh->sRefMarking;
1784 pDqLayer->pRefPicMarking = &pSh->sRefMarking;1670 pDqLayer->pRefPicBaseMarking = &pShExt->sRefBasePicMarking;
1785 pDqLayer->pRefPicBaseMarking = &pShExt->sRefBasePicMarking;1671 }
1786 } 1672
1787 1673 pDqLayer->uiLayerDqId = pNalHdrExt->uiLayerDqId; // dq_id of current layer
1788 pDqLayer->uiLayerDqId = pNalHdrExt->uiLayerDqId; // dq_id of current layer1674 pDqLayer->bUseRefBasePicFlag = pNalHdrExt->bUseRefBasePicFlag;
1789 pDqLayer->bUseRefBasePicFlag = pNalHdrExt->bUseRefBasePicFlag;
1790}1675}
1791 1676
1792void_t WelsDqLayerDecodeStart ( PWelsDecoderContext pCtx, PNalUnit pCurNal, PSps pSps, PPps pPps )1677void_t WelsDqLayerDecodeStart (PWelsDecoderContext pCtx, PNalUnit pCurNal, PSps pSps, PPps pPps) {
1793{ 1678 SNalUnitHeader* pNalHdr = &pCurNal->sNalHeaderExt.sNalUnitHeader;
1794 SNalUnitHeader *pNalHdr = &pCurNal->sNalHeaderExt.sNalUnitHeader;1679 PSliceHeader pSh = &pCurNal->sNalData.sVclNal.sSliceHeaderExt.sSliceHeader;
1795 PSliceHeader pSh = &pCurNal->sNalData.sVclNal.sSliceHeaderExt.sSliceHeader;1680
1796 1681 pCtx->eSliceType = pSh->eSliceType;
1797 pCtx->eSliceType = pSh->eSliceType; 1682 pCtx->pSliceHeader = pSh;
1798 pCtx->pSliceHeader = pSh;1683
1799 1684 pCtx->iFrameNum = pSh->iFrameNum;
1800 pCtx->iFrameNum = pSh->iFrameNum;1685
1801 1686 if ((pNalHdr->eNalUnitType == NAL_UNIT_CODED_SLICE_IDR ||
1802 if ((pNalHdr->eNalUnitType == NAL_UNIT_CODED_SLICE_IDR || 1687 (pCurNal->sNalHeaderExt.uiQualityId == BASE_QUALITY_ID && pCurNal->sNalHeaderExt.bIdrFlag)) &&
1803 (pCurNal->sNalHeaderExt.uiQualityId == BASE_QUALITY_ID && pCurNal->sNalHeaderExt.bIdrFlag)) &&1688 pSh->iFrameNum == 0) { //pSh->iFrameNum == 0 this condition can deleted??????
1804 pSh->iFrameNum == 0) //pSh->iFrameNum == 0 this condition can deleted??????1689 WelsResetRefPic (pCtx); // Reset decoded picture buffer lists due to an IDR frame incomes
1805 {1690 }
1806 WelsResetRefPic ( pCtx ); // Reset decoded picture buffer lists due to an IDR frame incomes
1807 }
1808}1691}
1809 1692
1810int32_t InitRefPicList ( PWelsDecoderContext pCtx, const uint8_t kuiNRi, const bool_t kbFirstSlice, int32_t iPoc)1693int32_t InitRefPicList (PWelsDecoderContext pCtx, const uint8_t kuiNRi, const bool_t kbFirstSlice, int32_t iPoc) {
1811{1694 int32_t iRet = ERR_NONE;
1812 int32_t iRet = ERR_NONE;1695 if (kbFirstSlice)
1813 if( kbFirstSlice)1696 iRet = WelsInitRefList (pCtx, iPoc);
1814 iRet = WelsInitRefList( pCtx, iPoc );1697 if ((pCtx->eSliceType != I_SLICE && pCtx->eSliceType != SI_SLICE) && kbFirstSlice) {
1815 if ( (pCtx->eSliceType!=I_SLICE && pCtx->eSliceType!=SI_SLICE) && kbFirstSlice ){1698 iRet = WelsReorderRefList (pCtx);
1816 iRet = WelsReorderRefList ( pCtx );1699 }
1817 }1700
1818 1701 return iRet;
1819 return iRet;
1820}1702}
1821 1703
1822void_t InitCurDqLayerData( PWelsDecoderContext pCtx, PDqLayer pCurDq )1704void_t InitCurDqLayerData (PWelsDecoderContext pCtx, PDqLayer pCurDq) {
1823{1705 if (NULL != pCtx && NULL != pCurDq) {
1824 if ( NULL != pCtx && NULL != pCurDq )1706 pCurDq->pCsData[0] = pCtx->pCsListXchg[0][0];
1825 {1707 pCurDq->pCsData[1] = pCtx->pCsListXchg[0][1];
1826 pCurDq->pCsData[0] = pCtx->pCsListXchg[0][0];1708 pCurDq->pCsData[2] = pCtx->pCsListXchg[0][2];
1827 pCurDq->pCsData[1] = pCtx->pCsListXchg[0][1];1709 pCurDq->iCsStride[0] = pCtx->iCsStride[0];
1828 pCurDq->pCsData[2] = pCtx->pCsListXchg[0][2];1710 pCurDq->iCsStride[1] = pCtx->iCsStride[1];
1829 pCurDq->iCsStride[0] = pCtx->iCsStride[0];1711 pCurDq->iCsStride[2] = pCtx->iCsStride[2];
1830 pCurDq->iCsStride[1] = pCtx->iCsStride[1];1712
1831 pCurDq->iCsStride[2] = pCtx->iCsStride[2];1713 pCurDq->pMbType = pCtx->sMb.pMbType[0];
1832 1714 pCurDq->pSliceIdc = pCtx->sMb.pSliceIdc[0];
1833 pCurDq->pMbType = pCtx->sMb.pMbType[0];1715 pCurDq->pMv[0] = pCtx->sMb.pMv[0][0];
1834 pCurDq->pSliceIdc = pCtx->sMb.pSliceIdc[0];1716 pCurDq->pRefIndex[0] = pCtx->sMb.pRefIndex[0][0];
1835 pCurDq->pMv[0] = pCtx->sMb.pMv[0][0];1717 pCurDq->pLumaQp = pCtx->sMb.pLumaQp[0];
1836 pCurDq->pRefIndex[0] = pCtx->sMb.pRefIndex[0][0];1718 pCurDq->pChromaQp = pCtx->sMb.pChromaQp[0];
1837 pCurDq->pLumaQp = pCtx->sMb.pLumaQp[0];1719 pCurDq->pNzc = pCtx->sMb.pNzc[0];
1838 pCurDq->pChromaQp = pCtx->sMb.pChromaQp[0];1720 pCurDq->pNzcRs = pCtx->sMb.pNzcRs[0];
1839 pCurDq->pNzc = pCtx->sMb.pNzc[0];1721 pCurDq->pScaledTCoeff = pCtx->sMb.pScaledTCoeff[0];
1840 pCurDq->pNzcRs = pCtx->sMb.pNzcRs[0];1722 pCurDq->pIntraPredMode = pCtx->sMb.pIntraPredMode[0];
1841 pCurDq->pScaledTCoeff = pCtx->sMb.pScaledTCoeff[0];1723 pCurDq->pIntra4x4FinalMode = pCtx->sMb.pIntra4x4FinalMode[0];
1842 pCurDq->pIntraPredMode = pCtx->sMb.pIntraPredMode[0];1724 pCurDq->pChromaPredMode = pCtx->sMb.pChromaPredMode[0];
1843 pCurDq->pIntra4x4FinalMode = pCtx->sMb.pIntra4x4FinalMode[0];1725 pCurDq->pCbp = pCtx->sMb.pCbp[0];
1844 pCurDq->pChromaPredMode = pCtx->sMb.pChromaPredMode[0];1726 pCurDq->pSubMbType = pCtx->sMb.pSubMbType[0];
1845 pCurDq->pCbp = pCtx->sMb.pCbp[0];1727 pCurDq->pInterPredictionDoneFlag = pCtx->sMb.pInterPredictionDoneFlag[0];
1846 pCurDq->pSubMbType = pCtx->sMb.pSubMbType[0];1728 pCurDq->pResidualPredFlag = pCtx->sMb.pResidualPredFlag[0];
1847 pCurDq->pInterPredictionDoneFlag = pCtx->sMb.pInterPredictionDoneFlag[0];1729 }
1848 pCurDq->pResidualPredFlag = pCtx->sMb.pResidualPredFlag[0];
1849 }
1850}1730}
1851 1731
1852// added to reset state of parameter sets to waiting successive incoming IDR, 6/4/20101732// added to reset state of parameter sets to waiting successive incoming IDR, 6/4/2010
1853// It will be called in case packets lost/ broken and decoded failed at temporal level 01733// It will be called in case packets lost/ broken and decoded failed at temporal level 0
1854void_t ResetParameterSetsState( PWelsDecoderContext pCtx )1734void_t ResetParameterSetsState (PWelsDecoderContext pCtx) {
1855{1735 pCtx->bSpsExistAheadFlag = false;
1856 pCtx->bSpsExistAheadFlag = false;1736 pCtx->bSubspsExistAheadFlag = false;
1857 pCtx->bSubspsExistAheadFlag = false;1737 pCtx->bPpsExistAheadFlag = false;
1858 pCtx->bPpsExistAheadFlag = false;
1859}1738}
1860 1739
1861/*1740/*
1862 * DecodeCurrentAccessUnit1741 * DecodeCurrentAccessUnit
1863 * Decode current access unit when current AU is completed.1742 * Decode current access unit when current AU is completed.
1864 */1743 */
1865int32_t DecodeCurrentAccessUnit( PWelsDecoderContext pCtx, uint8_t **ppDst, int32_t *pDstLen, int32_t *pWidth, int32_t *pHeight, SBufferInfo *pDstInfo )1744int32_t DecodeCurrentAccessUnit (PWelsDecoderContext pCtx, uint8_t** ppDst, int32_t* pDstLen, int32_t* pWidth,
1866{ 1745 int32_t* pHeight, SBufferInfo* pDstInfo) {
1867 int32_t iRefCount[LIST_A]; 1746 int32_t iRefCount[LIST_A];
1868 PNalUnit pNalCur = NULL;1747 PNalUnit pNalCur = NULL;
1869 PAccessUnit pCurAu = pCtx->pAccessUnitList;1748 PAccessUnit pCurAu = pCtx->pAccessUnitList;
1870 1749
1871 int32_t iIdx = pCurAu->uiStartPos;1750 int32_t iIdx = pCurAu->uiStartPos;
1872 int32_t iEndIdx = pCurAu->uiEndPos;1751 int32_t iEndIdx = pCurAu->uiEndPos;
1873 1752
1874 int32_t iPpsId = 0;1753 int32_t iPpsId = 0;
1875 int32_t iRet = ERR_NONE;1754 int32_t iRet = ERR_NONE;
1876 1755
1877 const uint8_t kuiTargetLayerDqId = GetTargetDqId(pCtx->uiTargetDqId, pCtx->pParam); 1756 const uint8_t kuiTargetLayerDqId = GetTargetDqId (pCtx->uiTargetDqId, pCtx->pParam);
1878 const uint8_t kuiDependencyIdMax = (kuiTargetLayerDqId & 0x7F) >> 4;1757 const uint8_t kuiDependencyIdMax = (kuiTargetLayerDqId & 0x7F) >> 4;
1879 int16_t iLastIdD = -1, iLastIdQ = -1;1758 int16_t iLastIdD = -1, iLastIdQ = -1;
1880 int16_t iCurrIdD = 0, iCurrIdQ = 0;1759 int16_t iCurrIdD = 0, iCurrIdQ = 0;
1881 uint8_t uiNalRefIdc = 0;1760 uint8_t uiNalRefIdc = 0;
1882 bool_t bFreshSliceAvailable = true; // Another fresh slice comingup for given dq layer, for multiple slices in case of header parts of slices sometimes loss over error-prone channels, 8/14/20081761 bool_t bFreshSliceAvailable =
1883 PPicture pStoreBasePic = NULL; 1762 true; // Another fresh slice comingup for given dq layer, for multiple slices in case of header parts of slices sometimes loss over error-prone channels, 8/14/2008
1884 1763 PPicture pStoreBasePic = NULL;
1885 //update pCurDqLayer at the starting of AU decoding1764
1886 if ( pCtx->bInitialDqLayersMem )1765 //update pCurDqLayer at the starting of AU decoding
1887 { 1766 if (pCtx->bInitialDqLayersMem) {
1888 pCtx->pCurDqLayer = pCtx->pDqLayersList[0];1767 pCtx->pCurDqLayer = pCtx->pDqLayersList[0];
1889 }1768 }
1890 1769
1891 InitCurDqLayerData( pCtx, pCtx->pCurDqLayer );1770 InitCurDqLayerData (pCtx, pCtx->pCurDqLayer);
1892 1771
1893 pNalCur = pCurAu->pNalUnitsList[iIdx]; 1772 pNalCur = pCurAu->pNalUnitsList[iIdx];
1894 while ( iIdx <= iEndIdx )1773 while (iIdx <= iEndIdx) {
1895 {1774 PDqLayer dq_cur = pCtx->pCurDqLayer;
1896 PDqLayer dq_cur = pCtx->pCurDqLayer;1775 SLayerInfo pLayerInfo;
1897 SLayerInfo pLayerInfo;1776 PSliceHeaderExt pShExt = NULL;
1898 PSliceHeaderExt pShExt = NULL;1777 PSliceHeader pSh = NULL;
1899 PSliceHeader pSh = NULL; 1778
1900 1779 if (pCtx->pDec == NULL) {
1901 if( pCtx->pDec == NULL ){1780 pCtx->pDec = PrefetchPic (pCtx->pPicBuff[0]);
1902 pCtx->pDec = PrefetchPic(pCtx->pPicBuff[0]);1781
1903 1782 if (NULL == pCtx->pDec) {
1904 if( NULL == pCtx->pDec ){1783 WelsLog (pCtx, WELS_LOG_ERROR, "DecodeCurrentAccessUnit()::::::PrefetchPic ERROR, pSps->iNumRefFrames:%d.\n",
1905 WelsLog( pCtx, WELS_LOG_ERROR, "DecodeCurrentAccessUnit()::::::PrefetchPic ERROR, pSps->iNumRefFrames:%d.\n", 1784 pCtx->pSps->iNumRefFrames);
1906 pCtx->pSps->iNumRefFrames );1785 pCtx->iErrorCode |= dsOutOfMemory;
1907 pCtx->iErrorCode |= dsOutOfMemory;1786 return ERR_INFO_REF_COUNT_OVERFLOW;
1908 return ERR_INFO_REF_COUNT_OVERFLOW;1787 }
1909 }1788 }
1910 }
1911 1789
1912#ifdef NO_WAITING_AU1790#ifdef NO_WAITING_AU
1913 //For fixing the nal lossing issue1791 //For fixing the nal lossing issue
1914 if ((pCtx->pDec->iTotalNumMbRec != 0)&&1792 if ((pCtx->pDec->iTotalNumMbRec != 0) &&
1915 (CheckAccessUnitBoundaryExt(&pCtx->sLastNalHdrExt, &pNalCur->sNalHeaderExt, &pCtx->sLastSliceHeader, &pNalCur->sNalData.sVclNal.sSliceHeaderExt.sSliceHeader)))1793 (CheckAccessUnitBoundaryExt (&pCtx->sLastNalHdrExt, &pNalCur->sNalHeaderExt, &pCtx->sLastSliceHeader,
1916 {1794 &pNalCur->sNalData.sVclNal.sSliceHeaderExt.sSliceHeader))) {
1917 pCtx->pDec->iTotalNumMbRec = 0; 1795 pCtx->pDec->iTotalNumMbRec = 0;
1918 }1796 }
1919#else1797#else
1920 //initialize at the starting of AU.1798 //initialize at the starting of AU.
1921 pCtx->pDec->iTotalNumMbRec = 0; 1799 pCtx->pDec->iTotalNumMbRec = 0;
1922#endif1800#endif
1923 if(pCtx->pDec->iTotalNumMbRec == 0) //Picture start to decode1801 if (pCtx->pDec->iTotalNumMbRec == 0) { //Picture start to decode
1924 {1802 for (int32_t i = 0; i < LAYER_NUM_EXCHANGEABLE; ++ i)
1925 for( int32_t i = 0; i < LAYER_NUM_EXCHANGEABLE; ++ i)1803 memset (pCtx->sMb.pSliceIdc[i], 0xff, (pCtx->sMb.iMbWidth * pCtx->sMb.iMbHeight * sizeof (int32_t)));
1926 memset(pCtx->sMb.pSliceIdc[i], 0xff, (pCtx->sMb.iMbWidth * pCtx->sMb.iMbHeight * sizeof(int32_t)) );1804 }
1927 }1805 GetI4LumaIChromaAddrTable (pCtx->iDecBlockOffsetArray, pCtx->pDec->iLinesize[0], pCtx->pDec->iLinesize[1]);
1928 GetI4LumaIChromaAddrTable(pCtx->iDecBlockOffsetArray, pCtx->pDec->iLinesize[0], pCtx->pDec->iLinesize[1]);1806
1929 1807 if (pNalCur->sNalHeaderExt.uiLayerDqId > kuiTargetLayerDqId) {
1930 if ( pNalCur->sNalHeaderExt.uiLayerDqId > kuiTargetLayerDqId ) {1808 break; // Per formance it need not to decode the remaining bits any more due to given uiLayerDqId required, 9/2/2009
1931 break; // Per formance it need not to decode the remaining bits any more due to given uiLayerDqId required, 9/2/20091809 }
1932 }1810
1933 1811 memset (&pLayerInfo, 0, sizeof (SLayerInfo));
1934 memset(&pLayerInfo, 0, sizeof(SLayerInfo));1812
1935 1813 /*
1936 /*1814 * Loop decoding for slices (even FMO and/ multiple slices) within a dq layer
1937 * Loop decoding for slices (even FMO and/ multiple slices) within a dq layer1815 */
1938 */1816 while (iIdx <= iEndIdx) {
1939 while ( iIdx <= iEndIdx )1817 BOOL_T bReconstructSlice;
1940 { 1818 iCurrIdQ = pNalCur->sNalHeaderExt.uiQualityId;
1941 BOOL_T bReconstructSlice;1819 iCurrIdD = pNalCur->sNalHeaderExt.uiDependencyId;
1942 iCurrIdQ = pNalCur->sNalHeaderExt.uiQualityId;1820 pSh = &pNalCur->sNalData.sVclNal.sSliceHeaderExt.sSliceHeader;
1943 iCurrIdD = pNalCur->sNalHeaderExt.uiDependencyId;1821 pShExt = &pNalCur->sNalData.sVclNal.sSliceHeaderExt;
1944 pSh = &pNalCur->sNalData.sVclNal.sSliceHeaderExt.sSliceHeader;1822
1945 pShExt = &pNalCur->sNalData.sVclNal.sSliceHeaderExt;1823 bReconstructSlice = CheckSliceNeedReconstruct (iCurrIdD, iCurrIdQ, pShExt->bStoreRefBasePicFlag,
1946 1824 kuiDependencyIdMax, pNalCur->sNalHeaderExt.uiLayerDqId, kuiTargetLayerDqId);
1947 bReconstructSlice = CheckSliceNeedReconstruct(iCurrIdD, iCurrIdQ, pShExt->bStoreRefBasePicFlag, 1825
1948 kuiDependencyIdMax, pNalCur->sNalHeaderExt.uiLayerDqId, kuiTargetLayerDqId);1826 memcpy (&pLayerInfo.sNalHeaderExt, &pNalCur->sNalHeaderExt, sizeof (SNalUnitHeaderExt)); //confirmed_safe_unsafe_usage
1949 1827
1950 memcpy(&pLayerInfo.sNalHeaderExt, &pNalCur->sNalHeaderExt, sizeof(SNalUnitHeaderExt));//confirmed_safe_unsafe_usage1828 pCtx->pDec->iFrameNum = pSh->iFrameNum;
1951 1829
1952 pCtx->pDec->iFrameNum = pSh->iFrameNum; 1830 memcpy (&pLayerInfo.sSliceInLayer.sSliceHeaderExt, pShExt, sizeof (SSliceHeaderExt)); //confirmed_safe_unsafe_usage
1953 1831 pLayerInfo.sSliceInLayer.bSliceHeaderExtFlag = pNalCur->sNalData.sVclNal.bSliceHeaderExtFlag;
1954 memcpy(&pLayerInfo.sSliceInLayer.sSliceHeaderExt, pShExt, sizeof(SSliceHeaderExt));//confirmed_safe_unsafe_usage1832 pLayerInfo.sSliceInLayer.eSliceType = pSh->eSliceType;
1955 pLayerInfo.sSliceInLayer.bSliceHeaderExtFlag = pNalCur->sNalData.sVclNal.bSliceHeaderExtFlag;1833 pLayerInfo.sSliceInLayer.iLastMbQp = pSh->iSliceQp;
1956 pLayerInfo.sSliceInLayer.eSliceType = pSh->eSliceType;1834 dq_cur->pBitStringAux = &pNalCur->sNalData.sVclNal.sSliceBitsRead;
1957 pLayerInfo.sSliceInLayer.iLastMbQp = pSh->iSliceQp;1835
1958 dq_cur->pBitStringAux = &pNalCur->sNalData.sVclNal.sSliceBitsRead;1836 uiNalRefIdc = pNalCur->sNalHeaderExt.sNalUnitHeader.uiNalRefIdc;
1959 1837
1960 uiNalRefIdc = pNalCur->sNalHeaderExt.sNalUnitHeader.uiNalRefIdc; 1838 iPpsId = pSh->iPpsId;
1961 1839
1962 iPpsId = pSh->iPpsId;1840 pLayerInfo.pPps = pSh->pPps;
1963 1841 pLayerInfo.pSps = pSh->pSps;
1964 pLayerInfo.pPps = pSh->pPps;1842 pLayerInfo.pSubsetSps = pShExt->pSubsetSps;
1965 pLayerInfo.pSps = pSh->pSps;1843
1966 pLayerInfo.pSubsetSps = pShExt->pSubsetSps; 1844 pCtx->pFmo = &pCtx->sFmoList[iPpsId];
1967 1845 if (!FmoParamUpdate (pCtx->pFmo, pLayerInfo.pSps, pLayerInfo.pPps, &pCtx->iActiveFmoNum)) {
1968 pCtx->pFmo = &pCtx->sFmoList[iPpsId];1846 pCtx->iErrorCode |= dsBitstreamError;
1969 if ( !FmoParamUpdate( pCtx->pFmo, pLayerInfo.pSps, pLayerInfo.pPps, &pCtx->iActiveFmoNum ) ) {1847 WelsLog (pCtx, WELS_LOG_WARNING, "DecodeCurrentAccessUnit(), FmoParamUpdate failed, eSliceType: %d.\n",
1970 pCtx->iErrorCode |= dsBitstreamError;1848 pSh->eSliceType);
1971 WelsLog( pCtx, WELS_LOG_WARNING, "DecodeCurrentAccessUnit(), FmoParamUpdate failed, eSliceType: %d.\n", pSh->eSliceType);1849 return GENERATE_ERROR_NO (ERR_LEVEL_SLICE_HEADER, ERR_INFO_FMO_INIT_FAIL);
1972 return GENERATE_ERROR_NO(ERR_LEVEL_SLICE_HEADER, ERR_INFO_FMO_INIT_FAIL);1850 }
1973 }1851
1974 1852 bFreshSliceAvailable = (iCurrIdD != iLastIdD
1975 bFreshSliceAvailable = (iCurrIdD != iLastIdD || iCurrIdQ != iLastIdQ); // do not need condition of (first_mb == 0) due multiple slices might be disorder1853 || iCurrIdQ != iLastIdQ); // do not need condition of (first_mb == 0) due multiple slices might be disorder
1976 1854
1977 WelsDqLayerDecodeStart ( pCtx, pNalCur, pLayerInfo.pSps, pLayerInfo.pPps );1855 WelsDqLayerDecodeStart (pCtx, pNalCur, pLayerInfo.pSps, pLayerInfo.pPps);
1978 1856
1979 if ( iCurrIdQ == BASE_QUALITY_ID )1857 if (iCurrIdQ == BASE_QUALITY_ID) {
1980 {1858 ST64 (iRefCount, LD64 (pLayerInfo.sSliceInLayer.sSliceHeaderExt.sSliceHeader.uiRefCount));
1981 ST64(iRefCount, LD64(pLayerInfo.sSliceInLayer.sSliceHeaderExt.sSliceHeader.uiRefCount));1859 }
1982 }1860
1983 1861 if ((iLastIdD < 0) || //case 1: first layer
1984 if ( (iLastIdD < 0) || //case 1: first layer1862 (iLastIdD == iCurrIdD)) { //case 2: same uiDId
1985 ( iLastIdD == iCurrIdD) ) //case 2: same uiDId1863 InitDqLayerInfo (dq_cur, &pLayerInfo, pNalCur, pCtx->pDec);
1986 {1864
1987 InitDqLayerInfo( dq_cur, &pLayerInfo, pNalCur, pCtx->pDec );1865 if (!dq_cur->sLayerInfo.pSps->bGapsInFrameNumValueAllowedFlag) {
1988 1866 const bool_t kbIdrFlag = dq_cur->sLayerInfo.sNalHeaderExt.bIdrFlag
1989 if ( !dq_cur->sLayerInfo.pSps->bGapsInFrameNumValueAllowedFlag )1867 || (dq_cur->sLayerInfo.sNalHeaderExt.sNalUnitHeader.eNalUnitType == NAL_UNIT_CODED_SLICE_IDR);
1990 {1868 // Subclause 8.2.5.2 Decoding process for gaps in frame_num
1991 const bool_t kbIdrFlag = dq_cur->sLayerInfo.sNalHeaderExt.bIdrFlag || (dq_cur->sLayerInfo.sNalHeaderExt.sNalUnitHeader.eNalUnitType == NAL_UNIT_CODED_SLICE_IDR);1869 if (!kbIdrFlag &&
1992 // Subclause 8.2.5.2 Decoding process for gaps in frame_num1870 pSh->iFrameNum != pCtx->iPrevFrameNum &&
1993 if ( !kbIdrFlag && 1871 pSh->iFrameNum != ((pCtx->iPrevFrameNum + 1) & ((1 << dq_cur->sLayerInfo.pSps->uiLog2MaxFrameNum) - 1))) {
1994 pSh->iFrameNum != pCtx->iPrevFrameNum &&1872 WelsLog (pCtx, WELS_LOG_WARNING,
1995 pSh->iFrameNum != ((pCtx->iPrevFrameNum+1) & ((1<<dq_cur->sLayerInfo.pSps->uiLog2MaxFrameNum)-1)) )1873 "referencing pictures lost due frame gaps exist, prev_frame_num: %d, curr_frame_num: %d\n", pCtx->iPrevFrameNum,
1996 {1874 pSh->iFrameNum);
1997 WelsLog( pCtx, WELS_LOG_WARNING, "referencing pictures lost due frame gaps exist, prev_frame_num: %d, curr_frame_num: %d\n", pCtx->iPrevFrameNum, pSh->iFrameNum);
1998 1875
1999#ifdef LONG_TERM_REF1876#ifdef LONG_TERM_REF
2000 pCtx->bParamSetsLostFlag = true;1877 pCtx->bParamSetsLostFlag = true;
2001#else1878#else
2002 pCtx->bReferenceLostAtT0Flag = true;1879 pCtx->bReferenceLostAtT0Flag = true;
2003#endif1880#endif
2004 ResetParameterSetsState( pCtx ); 1881 ResetParameterSetsState (pCtx);
2005 1882
2006 pCtx->iErrorCode |= dsRefLost;1883 pCtx->iErrorCode |= dsRefLost;
2007 return ERR_INFO_REFERENCE_PIC_LOST;1884 return ERR_INFO_REFERENCE_PIC_LOST;
2008 }1885 }
2009 }1886 }
2010 1887
2011 if ( iCurrIdD == kuiDependencyIdMax && iCurrIdQ == BASE_QUALITY_ID )1888 if (iCurrIdD == kuiDependencyIdMax && iCurrIdQ == BASE_QUALITY_ID) {
2012 {1889 iRet = InitRefPicList (pCtx, uiNalRefIdc, bFreshSliceAvailable, pSh->iPicOrderCntLsb);
2013 iRet = InitRefPicList ( pCtx, uiNalRefIdc, bFreshSliceAvailable, pSh->iPicOrderCntLsb);1890 if (iRet) {
2014 if ( iRet )1891 HandleReferenceLost (pCtx, pNalCur);
2015 {1892 WelsLog (pCtx, WELS_LOG_WARNING, "reference picture introduced by this frame is lost during transmission! uiTId: %d\n",
2016 HandleReferenceLost(pCtx, pNalCur);1893 pNalCur->sNalHeaderExt.uiTemporalId);
2017 WelsLog( pCtx, WELS_LOG_WARNING, "reference picture introduced by this frame is lost during transmission! uiTId: %d\n", pNalCur->sNalHeaderExt.uiTemporalId );1894 return iRet;
2018 return iRet;1895 }
2019 }1896 }
2020 }1897
2021 1898 iRet = WelsDecodeSlice (pCtx, bFreshSliceAvailable, pNalCur);
2022 iRet = WelsDecodeSlice ( pCtx, bFreshSliceAvailable, pNalCur );1899
2023 1900 //Output good store_base reconstruction when enhancement quality layer occurred error for MGS key picture case
2024 //Output good store_base reconstruction when enhancement quality layer occurred error for MGS key picture case1901 if (iRet != ERR_NONE) {
2025 if ( iRet != ERR_NONE )1902 WelsLog (pCtx, WELS_LOG_WARNING, "DecodeCurrentAccessUnit() failed (%d) in frame: %d uiDId: %d uiQId: %d\n",
2026 {1903 iRet, pSh->iFrameNum, iCurrIdD, iCurrIdQ);
2027 WelsLog( pCtx, WELS_LOG_WARNING, "DecodeCurrentAccessUnit() failed (%d) in frame: %d uiDId: %d uiQId: %d\n",1904 HandleReferenceLostL0 (pCtx, pNalCur);
2028 iRet, pSh->iFrameNum, iCurrIdD, iCurrIdQ);1905 return iRet;
2029 HandleReferenceLostL0(pCtx, pNalCur);1906 }
2030 return iRet;1907 if (bReconstructSlice) {
2031 }1908 if (WelsDecodeConstructSlice (pCtx, pNalCur)) {
2032 if( bReconstructSlice ) { 1909 return -1;
2033 if( WelsDecodeConstructSlice(pCtx, pNalCur) ){1910 }
2034 return -1;1911 }
2035 }1912 }
2036 }
2037 }
2038#if defined (_DEBUG) && !defined (CODEC_FOR_TESTBED)1913#if defined (_DEBUG) && !defined (CODEC_FOR_TESTBED)
2039 fprintf( stderr, "cur_frame : %d iCurrIdD : %d\n ", 1914 fprintf (stderr, "cur_frame : %d iCurrIdD : %d\n ",
2040 dq_cur->sLayerInfo.sSliceInLayer.sSliceHeaderExt.sSliceHeader.iFrameNum, iCurrIdD );1915 dq_cur->sLayerInfo.sSliceInLayer.sSliceHeaderExt.sSliceHeader.iFrameNum, iCurrIdD);
2041#endif//#if !CODEC_FOR_TESTBED1916#endif//#if !CODEC_FOR_TESTBED
2042 iLastIdD = iCurrIdD;1917 iLastIdD = iCurrIdD;
2043 iLastIdQ = iCurrIdQ; 1918 iLastIdQ = iCurrIdQ;
2044 1919
2045 //pNalUnitsList overflow.1920 //pNalUnitsList overflow.
2046 ++ iIdx;1921 ++ iIdx;
2047 if (iIdx <= iEndIdx)1922 if (iIdx <= iEndIdx) {
2048 { 1923 pNalCur = pCurAu->pNalUnitsList[iIdx];
2049 pNalCur = pCurAu->pNalUnitsList[iIdx];1924 } else {
2050 }1925 pNalCur = NULL;
2051 else1926 }
2052 {1927
2053 pNalCur = NULL;1928 if (pNalCur == NULL ||
2054 }1929 iLastIdD != pNalCur->sNalHeaderExt.uiDependencyId ||
2055 1930 iLastIdQ != pNalCur->sNalHeaderExt.uiQualityId)
2056 if ( pNalCur == NULL ||1931 break;
2057 iLastIdD != pNalCur->sNalHeaderExt.uiDependencyId || 1932 }
2058 iLastIdQ != pNalCur->sNalHeaderExt.uiQualityId )1933
2059 break;1934 // A dq layer decoded here
2060 }
2061
2062 // A dq layer decoded here
2063#if defined (_DEBUG) && !defined (CODEC_FOR_TESTBED)1935#if defined (_DEBUG) && !defined (CODEC_FOR_TESTBED)
2064#undef fprintf1936#undef fprintf
2065 fprintf(stderr, "POC: #%d, FRAME: #%d, D: %d, Q: %d, T: %d, P: %d, %d\n",1937 fprintf (stderr, "POC: #%d, FRAME: #%d, D: %d, Q: %d, T: %d, P: %d, %d\n",
2066 pSh->iPicOrderCntLsb, pSh->iFrameNum, iCurrIdD, iCurrIdQ, dq_cur->sLayerInfo.sNalHeaderExt.uiTemporalId, dq_cur->sLayerInfo.sNalHeaderExt.uiPriorityId,dq_cur->sLayerInfo.sSliceInLayer.sSliceHeaderExt.sSliceHeader.iSliceQp);1938 pSh->iPicOrderCntLsb, pSh->iFrameNum, iCurrIdD, iCurrIdQ, dq_cur->sLayerInfo.sNalHeaderExt.uiTemporalId,
1939 dq_cur->sLayerInfo.sNalHeaderExt.uiPriorityId, dq_cur->sLayerInfo.sSliceInLayer.sSliceHeaderExt.sSliceHeader.iSliceQp);
2067#endif//#if !CODEC_FOR_TESTBED1940#endif//#if !CODEC_FOR_TESTBED
2068 1941
2069 if( dq_cur->uiLayerDqId == kuiTargetLayerDqId ){1942 if (dq_cur->uiLayerDqId == kuiTargetLayerDqId) {
2070 if( DecodeFrameConstruction( pCtx, ppDst, pDstLen, pWidth, pHeight, pDstInfo) ){1943 if (DecodeFrameConstruction (pCtx, ppDst, pDstLen, pWidth, pHeight, pDstInfo)) {
2071#ifdef NO_WAITING_AU1944#ifdef NO_WAITING_AU
2072 memcpy(&pCtx->sLastNalHdrExt, &pCurAu->pNalUnitsList[iIdx-1]->sNalHeaderExt, sizeof(SNalUnitHeaderExt));1945 memcpy (&pCtx->sLastNalHdrExt, &pCurAu->pNalUnitsList[iIdx - 1]->sNalHeaderExt, sizeof (SNalUnitHeaderExt));
2073 memcpy(&pCtx->sLastSliceHeader, &pCurAu->pNalUnitsList[iIdx-1]->sNalData.sVclNal.sSliceHeaderExt.sSliceHeader, sizeof(SSliceHeader));1946 memcpy (&pCtx->sLastSliceHeader, &pCurAu->pNalUnitsList[iIdx - 1]->sNalData.sVclNal.sSliceHeaderExt.sSliceHeader,
2074 return ERR_NONE;1947 sizeof (SSliceHeader));
1948 return ERR_NONE;
2075#else1949#else
2076 pCtx->iErrorCode |= dsBitstreamError;1950 pCtx->iErrorCode |= dsBitstreamError;
2077 return -1;1951 return -1;
2078#endif1952#endif
2079
2080 }
2081 if( (uiNalRefIdc > 0) && ( iCurrIdQ || (!dq_cur->bStoreRefBasePicFlag) ) ){
2082 WelsMarkAsRef(pCtx, false);
2083 ExpandReferencingPicture(pCtx->pDec, pCtx->sExpandPicFunc.pExpandLumaPicture, pCtx->sExpandPicFunc.pExpandChromaPicture);
2084 pCtx->pDec = NULL;
2085 }
2086 }
2087 1953
2088 if( (iCurrIdD == kuiDependencyIdMax) && (iCurrIdQ == BASE_QUALITY_ID) && (dq_cur->bStoreRefBasePicFlag) ){1954 }
2089 pStoreBasePic = pCtx->pDec;1955 if ((uiNalRefIdc > 0) && (iCurrIdQ || (!dq_cur->bStoreRefBasePicFlag))) {
2090 1956 WelsMarkAsRef (pCtx, false);
2091 if( uiNalRefIdc > 0 ){1957 ExpandReferencingPicture (pCtx->pDec, pCtx->sExpandPicFunc.pExpandLumaPicture,
2092 WelsMarkAsRef(pCtx, true);1958 pCtx->sExpandPicFunc.pExpandChromaPicture);
2093 ExpandReferencingPicture(pCtx->pDec, pCtx->sExpandPicFunc.pExpandLumaPicture, pCtx->sExpandPicFunc.pExpandChromaPicture);1959 pCtx->pDec = NULL;
2094 pCtx->pDec = NULL;1960 }
2095 }1961 }
2096 } 1962
2097 // need update frame_num due current frame is well decoded1963 if ((iCurrIdD == kuiDependencyIdMax) && (iCurrIdQ == BASE_QUALITY_ID) && (dq_cur->bStoreRefBasePicFlag)) {
2098 pCtx->iPrevFrameNum = pSh->iFrameNum;1964 pStoreBasePic = pCtx->pDec;
2099 if( pCtx->bLastHasMmco5 ) 1965
2100 pCtx->iPrevFrameNum = 0;1966 if (uiNalRefIdc > 0) {
2101 } 1967 WelsMarkAsRef (pCtx, true);
2102 1968 ExpandReferencingPicture (pCtx->pDec, pCtx->sExpandPicFunc.pExpandLumaPicture,
2103 return ERR_NONE;1969 pCtx->sExpandPicFunc.pExpandChromaPicture);
1970 pCtx->pDec = NULL;
1971 }
1972 }
1973 // need update frame_num due current frame is well decoded
1974 pCtx->iPrevFrameNum = pSh->iFrameNum;
1975 if (pCtx->bLastHasMmco5)
1976 pCtx->iPrevFrameNum = 0;
1977 }
1978
1979 return ERR_NONE;
2104}1980}
2105 1981
2106} // namespace WelsDec1982} // namespace WelsDec

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t