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/decode_slice.cpp (1 of 225 files). Show all

Unified · Split

codec/decoder/core/src/decode_slice.cpp+1051−1239
@@ -60,1302 +60,1114 @@ · 59 unmodified lines
60 60
61namespace WelsDec {61namespace WelsDec {
62 62
63int32_t WelsTargetSliceConstruction( PWelsDecoderContext pCtx )63int32_t WelsTargetSliceConstruction (PWelsDecoderContext pCtx) {
64{64 int32_t iPreQP = 0;
65 int32_t iPreQP = 0;
66
67 PDqLayer pCurLayer = pCtx->pCurDqLayer;
68 PSlice pCurSlice = &pCurLayer->sLayerInfo.sSliceInLayer;
69 PSliceHeader pSliceHeader = &pCurSlice->sSliceHeaderExt.sSliceHeader;
70
71 int32_t iTotalMbTargetLayer = pSliceHeader->pSps->uiTotalMbCount;
72
73 int32_t iCurLayerWidth = pCurLayer->iMbWidth << 4;
74 int32_t iCurLayerHeight = pCurLayer->iMbHeight << 4;
75
76 int32_t iNextMbXyIndex = 0;
77 PFmo pFmo = pCtx->pFmo;
78
79 int32_t iTotalNumMb = pCurSlice->iTotalMbInCurSlice;
80 int32_t iCountNumMb = 0;
81 PDeblockingFilterMbFunc pDeblockMb;
82
83 if ( !pCtx->bAvcBasedFlag && iCurLayerWidth != pCtx->iCurSeqIntervalMaxPicWidth )
84 {
85 return -1;
86 }
87
88 iNextMbXyIndex = pSliceHeader->iFirstMbInSlice;
89 pCurLayer->iMbX = iNextMbXyIndex % pCurLayer->iMbWidth;
90 pCurLayer->iMbY = iNextMbXyIndex / pCurLayer->iMbWidth;
91 pCurLayer->iMbXyIndex = iNextMbXyIndex;
92
93 if ( 0 == iNextMbXyIndex )
94 {
95 pCurLayer->pDec->iSpsId = pSliceHeader->iSpsId;
96 pCurLayer->pDec->iPpsId = pSliceHeader->iPpsId;
97
98 pCurLayer->pDec->uiQualityId = pCurLayer->sLayerInfo.sNalHeaderExt.uiQualityId;
99 }
100
101 do
102 {
103 iPreQP = pCurLayer->pLumaQp[pCurLayer->iMbXyIndex];
104
105 if ( WelsTargetMbConstruction( pCtx ) )
106 {
107 WelsLog( pCtx, WELS_LOG_WARNING, "WelsTargetSliceConstruction():::MB(%d, %d) construction error. pCurSlice_type:%d\n",
108 pCurLayer->iMbX, pCurLayer->iMbY, pCurSlice->eSliceType );
109
110 return -1;
111 }
112
113 ++iCountNumMb;
114 ++pCurLayer->pDec->iTotalNumMbRec;
115 if ( iCountNumMb >= iTotalNumMb )
116 {
117 break;
118 }
119 if ( pCurLayer->pDec->iTotalNumMbRec > iTotalMbTargetLayer )
120 {
121 WelsLog( pCtx, WELS_LOG_WARNING, "WelsTargetSliceConstruction():::fdec->iTotalNumMbRec:%d, iTotalMbTargetLayer:%d\n",
122 pCurLayer->pDec->iTotalNumMbRec, iTotalMbTargetLayer );
123
124 return -1;
125 }
126
127 if ( pSliceHeader->pPps->uiNumSliceGroups > 1 )
128 {
129 iNextMbXyIndex = FmoNextMb( pFmo, iNextMbXyIndex );
130 }
131 else
132 {
133 ++iNextMbXyIndex;
134 }
135 if ( -1 == iNextMbXyIndex || iNextMbXyIndex >= iTotalMbTargetLayer ) // slice group boundary or end of a frame
136 {
137 break;
138 }
139 pCurLayer->iMbX = iNextMbXyIndex % pCurLayer->iMbWidth;
140 pCurLayer->iMbY = iNextMbXyIndex / pCurLayer->iMbWidth;
141 pCurLayer->iMbXyIndex = iNextMbXyIndex;
142 } while (1);
143
144 pCtx->pDec->iWidthInPixel = iCurLayerWidth;
145 pCtx->pDec->iHeightInPixel = iCurLayerHeight;
146
147 if((pCurSlice->eSliceType != I_SLICE)&&(pCurSlice->eSliceType != P_SLICE))
148 return 0;
149
150 pDeblockMb = WelsDeblockingMb;
151
152 if ( 1 == pSliceHeader->uiDisableDeblockingFilterIdc )
153 {
154 return 0;//NO_SUPPORTED_FILTER_IDX
155 }
156 else
157 {
158 WelsDeblockingFilterSlice( pCtx, pDeblockMb );
159
160 }
161 // any other filter_idc not supported here, 7/22/2010
162
163 return 0;
164}
165 65
166int32_t WelsMbInterSampleConstruction( PWelsDecoderContext pCtx, PDqLayer pCurLayer, 66 PDqLayer pCurLayer = pCtx->pCurDqLayer;
167 uint8_t* pDstY, uint8_t* pDstU, uint8_t* pDstV, int32_t iStrideL, int32_t iStrideC )67 PSlice pCurSlice = &pCurLayer->sLayerInfo.sSliceInLayer;
168{68 PSliceHeader pSliceHeader = &pCurSlice->sSliceHeaderExt.sSliceHeader;
169 int32_t iMbXy = pCurLayer->iMbXyIndex;69
170 int32_t i, iIndex, iOffset;70 int32_t iTotalMbTargetLayer = pSliceHeader->pSps->uiTotalMbCount;
171 71
172 WelsChromaDcIdct( pCurLayer->pScaledTCoeff[iMbXy] + 256 ); // 256 = 16*1672 int32_t iCurLayerWidth = pCurLayer->iMbWidth << 4;
173 WelsChromaDcIdct( pCurLayer->pScaledTCoeff[iMbXy] + 320 ); // 320 = 16*16 + 16*473 int32_t iCurLayerHeight = pCurLayer->iMbHeight << 4;
174 74
175 for(i=0; i<16; i++) //luma75 int32_t iNextMbXyIndex = 0;
176 {76 PFmo pFmo = pCtx->pFmo;
177 iIndex = g_kuiMbNonZeroCountIdx[i];77
178 if( pCurLayer->pNzc[iMbXy][iIndex] )78 int32_t iTotalNumMb = pCurSlice->iTotalMbInCurSlice;
179 {79 int32_t iCountNumMb = 0;
180 iOffset = ((iIndex>>2)<<2) * iStrideL + ((iIndex%4)<<2); 80 PDeblockingFilterMbFunc pDeblockMb;
181 pCtx->pIdctResAddPredFunc( pDstY+iOffset, iStrideL, pCurLayer->pScaledTCoeff[iMbXy]+(i<<4) );81
182 }82 if (!pCtx->bAvcBasedFlag && iCurLayerWidth != pCtx->iCurSeqIntervalMaxPicWidth) {
183 }83 return -1;
184 84 }
185 for ( i = 0; i < 4; i++ ) //chroma85
186 {86 iNextMbXyIndex = pSliceHeader->iFirstMbInSlice;
187 iIndex = g_kuiMbNonZeroCountIdx[i+16]; //Cb87 pCurLayer->iMbX = iNextMbXyIndex % pCurLayer->iMbWidth;
188 if ( pCurLayer->pNzc[iMbXy][iIndex] || *(pCurLayer->pScaledTCoeff[iMbXy]+((i+16)<<4)) )88 pCurLayer->iMbY = iNextMbXyIndex / pCurLayer->iMbWidth;
189 {89 pCurLayer->iMbXyIndex = iNextMbXyIndex;
190 iOffset = (((iIndex-16)>>2)<<2) * iStrideC + (((iIndex-16)%4)<<2); 90
191 pCtx->pIdctResAddPredFunc( pDstU+iOffset, iStrideC, pCurLayer->pScaledTCoeff[iMbXy]+((i+16)<<4) );91 if (0 == iNextMbXyIndex) {
192 }92 pCurLayer->pDec->iSpsId = pSliceHeader->iSpsId;
193 93 pCurLayer->pDec->iPpsId = pSliceHeader->iPpsId;
194 iIndex = g_kuiMbNonZeroCountIdx[i+20]; //Cr94
195 if ( pCurLayer->pNzc[iMbXy][iIndex] || *(pCurLayer->pScaledTCoeff[iMbXy]+((i+20)<<4)) )95 pCurLayer->pDec->uiQualityId = pCurLayer->sLayerInfo.sNalHeaderExt.uiQualityId;
196 {96 }
197 iOffset = (((iIndex-18)>>2)<<2) * iStrideC + (((iIndex-18)%4)<<2);
198 pCtx->pIdctResAddPredFunc( pDstV+iOffset, iStrideC , pCurLayer->pScaledTCoeff[iMbXy]+((i+20)<<4));
199 }
200 }
201
202 return 0;
203}
204int32_t WelsMbInterConstruction(PWelsDecoderContext pCtx, PDqLayer pCurLayer)
205{
206 int32_t iMbX = pCurLayer->iMbX;
207 int32_t iMbY = pCurLayer->iMbY;
208 uint8_t *pDstY, *pDstCb, *pDstCr;
209 97
210 int32_t iLumaStride = pCtx->pDec->iLinesize[0];98 do {
211 int32_t iChromaStride = pCtx->pDec->iLinesize[1];99 iPreQP = pCurLayer->pLumaQp[pCurLayer->iMbXyIndex];
100
101 if (WelsTargetMbConstruction (pCtx)) {
102 WelsLog (pCtx, WELS_LOG_WARNING, "WelsTargetSliceConstruction():::MB(%d, %d) construction error. pCurSlice_type:%d\n",
103 pCurLayer->iMbX, pCurLayer->iMbY, pCurSlice->eSliceType);
104
105 return -1;
106 }
107
108 ++iCountNumMb;
109 ++pCurLayer->pDec->iTotalNumMbRec;
110 if (iCountNumMb >= iTotalNumMb) {
111 break;
112 }
113 if (pCurLayer->pDec->iTotalNumMbRec > iTotalMbTargetLayer) {
114 WelsLog (pCtx, WELS_LOG_WARNING, "WelsTargetSliceConstruction():::fdec->iTotalNumMbRec:%d, iTotalMbTargetLayer:%d\n",
115 pCurLayer->pDec->iTotalNumMbRec, iTotalMbTargetLayer);
116
117 return -1;
118 }
119
120 if (pSliceHeader->pPps->uiNumSliceGroups > 1) {
121 iNextMbXyIndex = FmoNextMb (pFmo, iNextMbXyIndex);
122 } else {
123 ++iNextMbXyIndex;
124 }
125 if (-1 == iNextMbXyIndex || iNextMbXyIndex >= iTotalMbTargetLayer) { // slice group boundary or end of a frame
126 break;
127 }
128 pCurLayer->iMbX = iNextMbXyIndex % pCurLayer->iMbWidth;
129 pCurLayer->iMbY = iNextMbXyIndex / pCurLayer->iMbWidth;
130 pCurLayer->iMbXyIndex = iNextMbXyIndex;
131 } while (1);
212 132
213 pDstY = pCurLayer->pDec->pData[0] + ((iMbY * iLumaStride + iMbX)<<4);133 pCtx->pDec->iWidthInPixel = iCurLayerWidth;
214 pDstCb = pCurLayer->pDec->pData[1] + ((iMbY * iChromaStride + iMbX)<<3);134 pCtx->pDec->iHeightInPixel = iCurLayerHeight;
215 pDstCr = pCurLayer->pDec->pData[2] + ((iMbY * iChromaStride + iMbX)<<3);
216 135
217 GetInterPred(pDstY, pDstCb, pDstCr, pCtx);136 if ((pCurSlice->eSliceType != I_SLICE) && (pCurSlice->eSliceType != P_SLICE))
218 WelsMbInterSampleConstruction( pCtx, pCurLayer, pDstY, pDstCb, pDstCr, iLumaStride, iChromaStride );137 return 0;
219 138
220 pCtx->sBlockFunc.pWelsSetNonZeroCountFunc(NULL, pCurLayer->pNzc[pCurLayer->iMbXyIndex]);// set all none-zero nzc to 1; dbk can be opti!139 pDeblockMb = WelsDeblockingMb;
221 return 0;140
141 if (1 == pSliceHeader->uiDisableDeblockingFilterIdc) {
142 return 0;//NO_SUPPORTED_FILTER_IDX
143 } else {
144 WelsDeblockingFilterSlice (pCtx, pDeblockMb);
145
146 }
147 // any other filter_idc not supported here, 7/22/2010
148
149 return 0;
222}150}
223 151
224void_t WelsLumaDcDequantIdct(int16_t *pBlock, int32_t iQp){152int32_t WelsMbInterSampleConstruction (PWelsDecoderContext pCtx, PDqLayer pCurLayer,
225 const int32_t kiQMul= g_kuiDequantCoeff[iQp][0];153 uint8_t* pDstY, uint8_t* pDstU, uint8_t* pDstV, int32_t iStrideL, int32_t iStrideC) {
226#define STRIDE 16154 int32_t iMbXy = pCurLayer->iMbXyIndex;
227 int32_t i;155 int32_t i, iIndex, iOffset;
228 int32_t iTemp[16]; //FIXME check if this is a good idea156
229 int16_t* pBlk = pBlock;157 WelsChromaDcIdct (pCurLayer->pScaledTCoeff[iMbXy] + 256); // 256 = 16*16
230 static const int32_t kiXOffset[4]={0, STRIDE, STRIDE<<2, 5*STRIDE};158 WelsChromaDcIdct (pCurLayer->pScaledTCoeff[iMbXy] + 320); // 320 = 16*16 + 16*4
231 static const int32_t kiYOffset[4]={0, STRIDE<<1, STRIDE<<3, 10*STRIDE};159
232 160 for (i = 0; i < 16; i++) { //luma
233 for(i=0; i<4; i++){161 iIndex = g_kuiMbNonZeroCountIdx[i];
234 const int32_t kiOffset= kiYOffset[i];162 if (pCurLayer->pNzc[iMbXy][iIndex]) {
235 const int32_t kiX1 = kiOffset + kiXOffset[2];163 iOffset = ((iIndex >> 2) << 2) * iStrideL + ((iIndex % 4) << 2);
236 const int32_t kiX2 = STRIDE + kiOffset;164 pCtx->pIdctResAddPredFunc (pDstY + iOffset, iStrideL, pCurLayer->pScaledTCoeff[iMbXy] + (i << 4));
237 const int32_t kiX3 = kiOffset + kiXOffset[3];
238 const int32_t kiI4 = i << 2; // 4*i
239 const int32_t kiZ0= pBlk[kiOffset] + pBlk[kiX1];
240 const int32_t kiZ1= pBlk[kiOffset] - pBlk[kiX1];
241 const int32_t kiZ2= pBlk[kiX2] - pBlk[kiX3];
242 const int32_t kiZ3= pBlk[kiX2] + pBlk[kiX3];
243
244 iTemp[kiI4] = kiZ0+kiZ3;
245 iTemp[1+kiI4]= kiZ1+kiZ2;
246 iTemp[2+kiI4]= kiZ1-kiZ2;
247 iTemp[3+kiI4]= kiZ0-kiZ3;
248 }165 }
166 }
249 167
250 for(i=0; i<4; i++){168 for (i = 0; i < 4; i++) { //chroma
251 const int32_t kiOffset= kiXOffset[i];169 iIndex = g_kuiMbNonZeroCountIdx[i + 16]; //Cb
252 const int32_t kiI4 = 4 + i;170 if (pCurLayer->pNzc[iMbXy][iIndex] || * (pCurLayer->pScaledTCoeff[iMbXy] + ((i + 16) << 4))) {
253 const int32_t kiZ0= iTemp[i] + iTemp[4+kiI4];171 iOffset = (((iIndex - 16) >> 2) << 2) * iStrideC + (((iIndex - 16) % 4) << 2);
254 const int32_t kiZ1= iTemp[i] - iTemp[4+kiI4];172 pCtx->pIdctResAddPredFunc (pDstU + iOffset, iStrideC, pCurLayer->pScaledTCoeff[iMbXy] + ((i + 16) << 4));
255 const int32_t kiZ2= iTemp[kiI4] - iTemp[8+kiI4];
256 const int32_t kiZ3= iTemp[kiI4] + iTemp[8+kiI4];
257
258 pBlk[kiOffset]= ((kiZ0 + kiZ3)*kiQMul + 2)>>2; //FIXME think about merging this into decode_resdual
259 pBlk[kiYOffset[1] +kiOffset]= ((kiZ1 + kiZ2)*kiQMul + 2)>>2;
260 pBlk[kiYOffset[2] +kiOffset]= ((kiZ1 - kiZ2)*kiQMul + 2)>>2;
261 pBlk[kiYOffset[3] +kiOffset]= ((kiZ0 - kiZ3)*kiQMul + 2)>>2;
262 }173 }
263 #undef STRIDE174
175 iIndex = g_kuiMbNonZeroCountIdx[i + 20]; //Cr
176 if (pCurLayer->pNzc[iMbXy][iIndex] || * (pCurLayer->pScaledTCoeff[iMbXy] + ((i + 20) << 4))) {
177 iOffset = (((iIndex - 18) >> 2) << 2) * iStrideC + (((iIndex - 18) % 4) << 2);
178 pCtx->pIdctResAddPredFunc (pDstV + iOffset, iStrideC , pCurLayer->pScaledTCoeff[iMbXy] + ((i + 20) << 4));
179 }
180 }
181
182 return 0;
264}183}
184int32_t WelsMbInterConstruction (PWelsDecoderContext pCtx, PDqLayer pCurLayer) {
185 int32_t iMbX = pCurLayer->iMbX;
186 int32_t iMbY = pCurLayer->iMbY;
187 uint8_t* pDstY, *pDstCb, *pDstCr;
265 188
266int32_t WelsMbIntraPredictionConstruction(PWelsDecoderContext pCtx, PDqLayer pCurLayer, bool_t bOutput)189 int32_t iLumaStride = pCtx->pDec->iLinesize[0];
267{190 int32_t iChromaStride = pCtx->pDec->iLinesize[1];
191
192 pDstY = pCurLayer->pDec->pData[0] + ((iMbY * iLumaStride + iMbX) << 4);
193 pDstCb = pCurLayer->pDec->pData[1] + ((iMbY * iChromaStride + iMbX) << 3);
194 pDstCr = pCurLayer->pDec->pData[2] + ((iMbY * iChromaStride + iMbX) << 3);
195
196 GetInterPred (pDstY, pDstCb, pDstCr, pCtx);
197 WelsMbInterSampleConstruction (pCtx, pCurLayer, pDstY, pDstCb, pDstCr, iLumaStride, iChromaStride);
198
199 pCtx->sBlockFunc.pWelsSetNonZeroCountFunc (NULL,
200 pCurLayer->pNzc[pCurLayer->iMbXyIndex]); // set all none-zero nzc to 1; dbk can be opti!
201 return 0;
202}
203
204void_t WelsLumaDcDequantIdct (int16_t* pBlock, int32_t iQp) {
205 const int32_t kiQMul = g_kuiDequantCoeff[iQp][0];
206#define STRIDE 16
207 int32_t i;
208 int32_t iTemp[16]; //FIXME check if this is a good idea
209 int16_t* pBlk = pBlock;
210 static const int32_t kiXOffset[4] = {0, STRIDE, STRIDE << 2, 5 * STRIDE};
211 static const int32_t kiYOffset[4] = {0, STRIDE << 1, STRIDE << 3, 10 * STRIDE};
212
213 for (i = 0; i < 4; i++) {
214 const int32_t kiOffset = kiYOffset[i];
215 const int32_t kiX1 = kiOffset + kiXOffset[2];
216 const int32_t kiX2 = STRIDE + kiOffset;
217 const int32_t kiX3 = kiOffset + kiXOffset[3];
218 const int32_t kiI4 = i << 2; // 4*i
219 const int32_t kiZ0 = pBlk[kiOffset] + pBlk[kiX1];
220 const int32_t kiZ1 = pBlk[kiOffset] - pBlk[kiX1];
221 const int32_t kiZ2 = pBlk[kiX2] - pBlk[kiX3];
222 const int32_t kiZ3 = pBlk[kiX2] + pBlk[kiX3];
223
224 iTemp[kiI4] = kiZ0 + kiZ3;
225 iTemp[1 + kiI4] = kiZ1 + kiZ2;
226 iTemp[2 + kiI4] = kiZ1 - kiZ2;
227 iTemp[3 + kiI4] = kiZ0 - kiZ3;
228 }
229
230 for (i = 0; i < 4; i++) {
231 const int32_t kiOffset = kiXOffset[i];
232 const int32_t kiI4 = 4 + i;
233 const int32_t kiZ0 = iTemp[i] + iTemp[4 + kiI4];
234 const int32_t kiZ1 = iTemp[i] - iTemp[4 + kiI4];
235 const int32_t kiZ2 = iTemp[kiI4] - iTemp[8 + kiI4];
236 const int32_t kiZ3 = iTemp[kiI4] + iTemp[8 + kiI4];
237
238 pBlk[kiOffset] = ((kiZ0 + kiZ3) * kiQMul + 2) >> 2; //FIXME think about merging this into decode_resdual
239 pBlk[kiYOffset[1] + kiOffset] = ((kiZ1 + kiZ2) * kiQMul + 2) >> 2;
240 pBlk[kiYOffset[2] + kiOffset] = ((kiZ1 - kiZ2) * kiQMul + 2) >> 2;
241 pBlk[kiYOffset[3] + kiOffset] = ((kiZ0 - kiZ3) * kiQMul + 2) >> 2;
242 }
243#undef STRIDE
244}
245
246int32_t WelsMbIntraPredictionConstruction (PWelsDecoderContext pCtx, PDqLayer pCurLayer, bool_t bOutput) {
268//seems IPCM should not enter this path247//seems IPCM should not enter this path
269 int32_t iMbXy = pCurLayer->iMbXyIndex;248 int32_t iMbXy = pCurLayer->iMbXyIndex;
270 249
271 FORCE_STACK_ALIGN_1D( int16_t, pTempScaledTCoeff, MB_COEFF_LIST_SIZE, 16 );250 FORCE_STACK_ALIGN_1D (int16_t, pTempScaledTCoeff, MB_COEFF_LIST_SIZE, 16);
272 251
273 memcpy(pTempScaledTCoeff, pCurLayer->pScaledTCoeff[iMbXy], 384*sizeof(pCurLayer->pScaledTCoeff[iMbXy][0]));252 memcpy (pTempScaledTCoeff, pCurLayer->pScaledTCoeff[iMbXy], 384 * sizeof (pCurLayer->pScaledTCoeff[iMbXy][0]));
274 253
275 WelsFillRecNeededMbInfo(pCtx, bOutput, pCurLayer);254 WelsFillRecNeededMbInfo (pCtx, bOutput, pCurLayer);
276 255
277 if(IS_INTRA16x16(pCurLayer->pMbType[iMbXy]))256 if (IS_INTRA16x16 (pCurLayer->pMbType[iMbXy])) {
278 {257 int32_t i, j;
279 int32_t i,j;258 // really need?
280 // really need?259 for (i = 0; i < 16; i++) {
281 for(i=0; i<16; i++)260 j = g_kuiLumaDcZigzagScan[i];
282 {261 pTempScaledTCoeff[j] = pCurLayer->pScaledTCoeff[iMbXy][j];
283 j = g_kuiLumaDcZigzagScan[i];262 }
284 pTempScaledTCoeff[j] = pCurLayer->pScaledTCoeff[iMbXy][j];263 WelsLumaDcDequantIdct (pTempScaledTCoeff, pCurLayer->pLumaQp[iMbXy]);
285 }264 RecI16x16Mb (iMbXy, pCtx, pTempScaledTCoeff, pCurLayer);
286 WelsLumaDcDequantIdct(pTempScaledTCoeff, pCurLayer->pLumaQp[iMbXy]);265
287 RecI16x16Mb(iMbXy, pCtx,pTempScaledTCoeff,pCurLayer);266 return 0;
288 267 }
289 return 0;268
290 }269 if (IS_INTRA4x4 (pCurLayer->pMbType[iMbXy]))
291 270 RecI4x4Mb (iMbXy, pCtx, pTempScaledTCoeff, pCurLayer);
292 if(IS_INTRA4x4(pCurLayer->pMbType[iMbXy]))271
293 RecI4x4Mb(iMbXy, pCtx,pTempScaledTCoeff,pCurLayer);272 return 0;
294
295 return 0;
296}273}
297 274
298int32_t WelsMbInterPrediction(PWelsDecoderContext pCtx, PDqLayer pCurLayer)275int32_t WelsMbInterPrediction (PWelsDecoderContext pCtx, PDqLayer pCurLayer) {
299{276 int32_t iMbX = pCurLayer->iMbX;
300 int32_t iMbX = pCurLayer->iMbX;277 int32_t iMbY = pCurLayer->iMbY;
301 int32_t iMbY = pCurLayer->iMbY;278 uint8_t* pDstY, *pDstCb, *pDstCr;
302 uint8_t *pDstY, *pDstCb, *pDstCr;
303 279
304 int32_t iLumaStride = pCtx->pDec->iLinesize[0];280 int32_t iLumaStride = pCtx->pDec->iLinesize[0];
305 int32_t iChromaStride = pCtx->pDec->iLinesize[1];281 int32_t iChromaStride = pCtx->pDec->iLinesize[1];
306 282
307 pDstY = pCurLayer->pDec->pData[0] + ((iMbY * iLumaStride + iMbX)<<4);283 pDstY = pCurLayer->pDec->pData[0] + ((iMbY * iLumaStride + iMbX) << 4);
308 pDstCb = pCurLayer->pDec->pData[1] + ((iMbY * iChromaStride + iMbX)<<3);284 pDstCb = pCurLayer->pDec->pData[1] + ((iMbY * iChromaStride + iMbX) << 3);
309 pDstCr = pCurLayer->pDec->pData[2] + ((iMbY * iChromaStride + iMbX)<<3);285 pDstCr = pCurLayer->pDec->pData[2] + ((iMbY * iChromaStride + iMbX) << 3);
310 286
311 GetInterPred(pDstY, pDstCb, pDstCr, pCtx);287 GetInterPred (pDstY, pDstCb, pDstCr, pCtx);
312 288
313 return 0;289 return 0;
314}290}
315 291
316void_t WelsMbCopy( uint8_t *pDst, int32_t iStrideDst, uint8_t *pSrc, int32_t iStrideSrc, 292void_t WelsMbCopy (uint8_t* pDst, int32_t iStrideDst, uint8_t* pSrc, int32_t iStrideSrc,
317 int32_t iHeight, int32_t iWidth )293 int32_t iHeight, int32_t iWidth) {
318{294 int32_t i;
319 int32_t i;295 int32_t iOffsetDst = 0, iOffsetSrc = 0;
320 int32_t iOffsetDst = 0, iOffsetSrc = 0;296 for (i = 0; i < iHeight; i++) {
321 for ( i = 0; i < iHeight; i++ )297 memcpy (pDst + iOffsetDst, pSrc + iOffsetSrc, iWidth);
322 {298 iOffsetDst += iStrideDst;
323 memcpy( pDst+iOffsetDst, pSrc+iOffsetSrc, iWidth );299 iOffsetSrc += iStrideSrc;
324 iOffsetDst += iStrideDst;300 }
325 iOffsetSrc += iStrideSrc;
326 }
327}301}
328 302
329 303
330int32_t WelsTargetMbConstruction(PWelsDecoderContext pCtx)304int32_t WelsTargetMbConstruction (PWelsDecoderContext pCtx) {
331{305 PDqLayer pCurLayer = pCtx->pCurDqLayer;
332 PDqLayer pCurLayer = pCtx->pCurDqLayer; 306 if (MB_TYPE_INTRA_PCM == pCurLayer->pMbType[pCurLayer->iMbXyIndex]) {
333 if ( MB_TYPE_INTRA_PCM == pCurLayer->pMbType[pCurLayer->iMbXyIndex] )307 //copy cs into fdec
334 { 308 int32_t iCsStrideL = pCurLayer->iCsStride[0];
335 //copy cs into fdec309 int32_t iCsStrideC = pCurLayer->iCsStride[1];
336 int32_t iCsStrideL = pCurLayer->iCsStride[0];310
337 int32_t iCsStrideC = pCurLayer->iCsStride[1];311 int32_t iDecStrideL = pCurLayer->pDec->iLinesize[0];
338 312 int32_t iDecStrideC = pCurLayer->pDec->iLinesize[1];
339 int32_t iDecStrideL = pCurLayer->pDec->iLinesize[0]; 313
340 int32_t iDecStrideC = pCurLayer->pDec->iLinesize[1]; 314 int32_t iCsOffsetL = (pCurLayer->iMbX + pCurLayer->iMbY * iCsStrideL) << 4;
341 315 int32_t iCsOffsetC = (pCurLayer->iMbX + pCurLayer->iMbY * iCsStrideC) << 3;
342 int32_t iCsOffsetL = ( pCurLayer->iMbX + pCurLayer->iMbY * iCsStrideL ) << 4;316
343 int32_t iCsOffsetC = ( pCurLayer->iMbX + pCurLayer->iMbY * iCsStrideC ) << 3;317 int32_t iDecOffsetL = (pCurLayer->iMbX + pCurLayer->iMbY * iDecStrideL) << 4;
344 318 int32_t iDecOffsetC = (pCurLayer->iMbX + pCurLayer->iMbY * iDecStrideC) << 3;
345 int32_t iDecOffsetL = ( pCurLayer->iMbX + pCurLayer->iMbY * iDecStrideL ) << 4;319
346 int32_t iDecOffsetC = ( pCurLayer->iMbX + pCurLayer->iMbY * iDecStrideC ) << 3;320 uint8_t* pSrcY = pCurLayer->pCsData[0] + iCsOffsetL;
347 321 uint8_t* pSrcU = pCurLayer->pCsData[1] + iCsOffsetC;
348 uint8_t* pSrcY = pCurLayer->pCsData[0] + iCsOffsetL;322 uint8_t* pSrcV = pCurLayer->pCsData[2] + iCsOffsetC;
349 uint8_t* pSrcU = pCurLayer->pCsData[1] + iCsOffsetC;323
350 uint8_t* pSrcV = pCurLayer->pCsData[2] + iCsOffsetC;324 uint8_t* pDecY = pCurLayer->pDec->pData[0] + iDecOffsetL;
351 325 uint8_t* pDecU = pCurLayer->pDec->pData[1] + iDecOffsetC;
352 uint8_t* pDecY = pCurLayer->pDec->pData[0] + iDecOffsetL;326 uint8_t* pDecV = pCurLayer->pDec->pData[2] + iDecOffsetC;
353 uint8_t* pDecU = pCurLayer->pDec->pData[1] + iDecOffsetC;327
354 uint8_t* pDecV = pCurLayer->pDec->pData[2] + iDecOffsetC;328 WelsMbCopy (pDecY, iDecStrideL, pSrcY, iCsStrideL, 16, 16);
355 329 WelsMbCopy (pDecU, iDecStrideC, pSrcU, iCsStrideC, 8, 8);
356 WelsMbCopy( pDecY, iDecStrideL, pSrcY, iCsStrideL, 16, 16 );330 WelsMbCopy (pDecV, iDecStrideC, pSrcV, iCsStrideC, 8, 8);
357 WelsMbCopy( pDecU, iDecStrideC, pSrcU, iCsStrideC, 8, 8 );331
358 WelsMbCopy( pDecV, iDecStrideC, pSrcV, iCsStrideC, 8, 8 );332 return 0;
359 333 } else if (IS_INTRA (pCurLayer->pMbType[pCurLayer->iMbXyIndex])) {
360 return 0;334 WelsMbIntraPredictionConstruction (pCtx, pCurLayer, 1);
361 }335 } else if (IS_INTER (pCurLayer->pMbType[pCurLayer->iMbXyIndex])) { //InterMB
362 else if(IS_INTRA(pCurLayer->pMbType[pCurLayer->iMbXyIndex]))336 if (0 == pCurLayer->pCbp[pCurLayer->iMbXyIndex]) { //uiCbp==0 include SKIP
363 {337 WelsMbInterPrediction (pCtx, pCurLayer);
364 WelsMbIntraPredictionConstruction(pCtx, pCurLayer, 1);338 } else {
365 }339 WelsMbInterConstruction (pCtx, pCurLayer);
366 else if ( IS_INTER( pCurLayer->pMbType[pCurLayer->iMbXyIndex] ) ) //InterMB340 }
367 {341 } else {
368 if ( 0 == pCurLayer->pCbp[pCurLayer->iMbXyIndex] ) //uiCbp==0 include SKIP342 WelsLog (pCtx, WELS_LOG_WARNING, "WelsTargetMbConstruction():::::Unknown MB type: %d\n",
369 {343 pCurLayer->pMbType[pCurLayer->iMbXyIndex]);
370 WelsMbInterPrediction( pCtx, pCurLayer );344 return -1;
371 }345 }
372 else346
373 {347 return 0;
374 WelsMbInterConstruction( pCtx, pCurLayer );
375 }
376 }
377 else
378 {
379 WelsLog( pCtx, WELS_LOG_WARNING, "WelsTargetMbConstruction():::::Unknown MB type: %d\n", pCurLayer->pMbType[pCurLayer->iMbXyIndex] );
380 return -1;
381 }
382
383 return 0;
384}348}
385 349
386void_t WelsChromaDcIdct( int16_t *pBlock )350void_t WelsChromaDcIdct (int16_t* pBlock) {
387{351 int32_t iStride = 32;
388 int32_t iStride= 32;352 int32_t iXStride = 16;
389 int32_t iXStride= 16;353 int32_t iStride1 = iXStride + iStride;
390 int32_t iStride1 = iXStride + iStride;354 int16_t* pBlk = pBlock;
391 int16_t* pBlk = pBlock;355 int32_t iA, iB, iC, iD, iE;
392 int32_t iA,iB,iC,iD,iE;356
393 357 iA = pBlk[0];
394 iA= pBlk[0];358 iB = pBlk[iXStride];
395 iB= pBlk[iXStride];359 iC = pBlk[iStride];
396 iC= pBlk[iStride];360 iD = pBlk[iStride1];
397 iD= pBlk[iStride1];361
398 362 iE = iA - iB;
399 iE = iA-iB;363 iA += iB;
400 iA += iB;364 iB = iC - iD;
401 iB = iC-iD;365 iC += iD;
402 iC += iD;366
403 367 pBlk[0] = (iA + iC) >> 1;
404 pBlk[0]= (iA+iC) >> 1;368 pBlk[iXStride] = (iE + iB) >> 1;
405 pBlk[iXStride]= (iE+iB) >> 1;369 pBlk[iStride] = (iA - iC) >> 1;
406 pBlk[iStride]= (iA-iC) >> 1;370 pBlk[iStride1] = (iE - iB) >> 1;
407 pBlk[iStride1]= (iE-iB) >> 1;
408}371}
409 372
410int32_t WelsDecodeSlice(PWelsDecoderContext pCtx, bool_t bFirstSliceInLayer, PNalUnit pNalCur)373int32_t WelsDecodeSlice (PWelsDecoderContext pCtx, bool_t bFirstSliceInLayer, PNalUnit pNalCur) {
411{374 PDqLayer pCurLayer = pCtx->pCurDqLayer;
412 PDqLayer pCurLayer = pCtx->pCurDqLayer;375 PFmo pFmo = pCtx->pFmo;
413 PFmo pFmo = pCtx->pFmo;376 int32_t i, iRet;
414 int32_t i, iRet;377 int32_t iNextMbXyIndex, iSliceIdc;
415 int32_t iNextMbXyIndex, iSliceIdc; 378
416 379 PSlice pSlice = &pCurLayer->sLayerInfo.sSliceInLayer;
417 PSlice pSlice = &pCurLayer->sLayerInfo.sSliceInLayer;380 PSliceHeaderExt pSliceHeaderExt = &pSlice->sSliceHeaderExt;
418 PSliceHeaderExt pSliceHeaderExt = &pSlice->sSliceHeaderExt;381 PSliceHeader pSliceHeader = &pSliceHeaderExt->sSliceHeader;
419 PSliceHeader pSliceHeader = &pSliceHeaderExt->sSliceHeader;382 int32_t iMbX, iMbY;
420 int32_t iMbX, iMbY;383 const int32_t kiCountNumMb = pSliceHeader->pSps->uiTotalMbCount; //need to be correct when fmo or multi slice
421 const int32_t kiCountNumMb = pSliceHeader->pSps->uiTotalMbCount; //need to be correct when fmo or multi slice384 PBitStringAux pBs = pCurLayer->pBitStringAux;
422 PBitStringAux pBs = pCurLayer->pBitStringAux; 385 int32_t iUsedBits = 0;
423 int32_t iUsedBits = 0;386
424 387 PWelsDecMbCavlcFunc pDecMbCavlcFunc;
425 PWelsDecMbCavlcFunc pDecMbCavlcFunc; 388
426 389 pSlice->iTotalMbInCurSlice = 0; //initialize at the starting of slice decoding.
427 pSlice->iTotalMbInCurSlice = 0; //initialize at the starting of slice decoding.390
428 391 if (P_SLICE == pSliceHeader->eSliceType) {
429 if ( P_SLICE == pSliceHeader->eSliceType ) 392 pDecMbCavlcFunc = WelsDecodeMbCavlcPSlice;
430 {393 } else { //I_SLICE
431 pDecMbCavlcFunc = WelsDecodeMbCavlcPSlice;394 pDecMbCavlcFunc = WelsDecodeMbCavlcISlice;
432 }395 }
433 else //I_SLICE396
434 {397 if (pSliceHeader->pPps->bConstainedIntraPredFlag) {
435 pDecMbCavlcFunc = WelsDecodeMbCavlcISlice;398 pCtx->pFillInfoCacheIntra4x4Func = WelsFillCacheConstrain1Intra4x4;
436 }399 pCtx->pParseIntra4x4ModeFunc = ParseIntra4x4ModeConstrain1;
437 400 pCtx->pParseIntra16x16ModeFunc = ParseIntra16x16ModeConstrain1;
438 if ( pSliceHeader->pPps->bConstainedIntraPredFlag )401 } else {
439 {402 pCtx->pFillInfoCacheIntra4x4Func = WelsFillCacheConstrain0Intra4x4;
440 pCtx->pFillInfoCacheIntra4x4Func = WelsFillCacheConstrain1Intra4x4;403 pCtx->pParseIntra4x4ModeFunc = ParseIntra4x4ModeConstrain0;
441 pCtx->pParseIntra4x4ModeFunc = ParseIntra4x4ModeConstrain1;404 pCtx->pParseIntra16x16ModeFunc = ParseIntra16x16ModeConstrain0;
442 pCtx->pParseIntra16x16ModeFunc = ParseIntra16x16ModeConstrain1;405 }
443 }406
444 else407 pCtx->eSliceType = pSliceHeader->eSliceType;
445 {408
446 pCtx->pFillInfoCacheIntra4x4Func = WelsFillCacheConstrain0Intra4x4;409 if (pCurLayer->sLayerInfo.pPps->bEntropyCodingModeFlag == 1) {
447 pCtx->pParseIntra4x4ModeFunc = ParseIntra4x4ModeConstrain0;410 //CABAC encoding is unsupported yet!
448 pCtx->pParseIntra16x16ModeFunc = ParseIntra16x16ModeConstrain0;411 return -1;
449 }412 }
450 413
451 pCtx->eSliceType = pSliceHeader->eSliceType;414 iNextMbXyIndex = pSliceHeader->iFirstMbInSlice;
452 415
453 if (pCurLayer->sLayerInfo.pPps->bEntropyCodingModeFlag == 1)416 if (iNextMbXyIndex >= kiCountNumMb) {
454 {417 WelsLog (pCtx, WELS_LOG_ERROR,
455 //CABAC encoding is unsupported yet!418 "WelsDecodeSlice()::iFirstMbInSlice(%d) > pSps->kiTotalMb(%d). ERROR!!! resolution change....\n",
456 return -1;419 iNextMbXyIndex, kiCountNumMb);
457 }420 pCtx->iErrorCode |= dsNoParamSets;
458 421 return dsNoParamSets;
459 iNextMbXyIndex = pSliceHeader->iFirstMbInSlice;422 }
460 423
461 if ( iNextMbXyIndex >= kiCountNumMb )424 iMbX = iNextMbXyIndex % pCurLayer->iMbWidth;
462 {425 iMbY = iNextMbXyIndex / pCurLayer->iMbWidth; // error is introduced by multiple slices case, 11/23/2009
463 WelsLog(pCtx, WELS_LOG_ERROR, "WelsDecodeSlice()::iFirstMbInSlice(%d) > pSps->kiTotalMb(%d). ERROR!!! resolution change....\n", 426 pSlice->iMbSkipRun = -1;
464 iNextMbXyIndex, kiCountNumMb);427 iSliceIdc = (pSliceHeader->iFirstMbInSlice << 7) + pCurLayer->uiLayerDqId;
465 pCtx->iErrorCode |= dsNoParamSets;428
466 return dsNoParamSets;429 pCurLayer->iMbX = iMbX;
467 } 430 pCurLayer->iMbY = iMbY;
468 431 pCurLayer->iMbXyIndex = iNextMbXyIndex;
469 iMbX = iNextMbXyIndex % pCurLayer->iMbWidth;432
470 iMbY = iNextMbXyIndex / pCurLayer->iMbWidth; // error is introduced by multiple slices case, 11/23/2009433 if (pSliceHeaderExt->bSliceSkipFlag == 1) {
471 pSlice->iMbSkipRun = -1;434 for (i = 0; i < (int32_t)pSliceHeaderExt->uiNumMbsInSlice; i++) {
472 iSliceIdc = (pSliceHeader->iFirstMbInSlice<<7)+pCurLayer->uiLayerDqId;435 pCurLayer->pSliceIdc[iNextMbXyIndex] = iSliceIdc;
473 436
474 pCurLayer->iMbX = iMbX;437
475 pCurLayer->iMbY = iMbY;438 pCurLayer->pResidualPredFlag[iNextMbXyIndex] = 1;
476 pCurLayer->iMbXyIndex = iNextMbXyIndex;439
477 440 if (pSliceHeaderExt->sSliceHeader.pPps->uiNumSliceGroups > 1) {
478 if(pSliceHeaderExt->bSliceSkipFlag == 1)441 iNextMbXyIndex = FmoNextMb (pFmo, iNextMbXyIndex);
479 {442 } else {
480 for(i=0; i<(int32_t)pSliceHeaderExt->uiNumMbsInSlice; i++)443 ++iNextMbXyIndex;
481 {444 }
482 pCurLayer->pSliceIdc[iNextMbXyIndex] = iSliceIdc;445
483 446 iMbX = iNextMbXyIndex % pCurLayer->iMbWidth;
484 447 iMbY = iNextMbXyIndex % pCurLayer->iMbHeight;
485 pCurLayer->pResidualPredFlag[iNextMbXyIndex] = 1; 448
486 449 pCurLayer->iMbX = iMbX;
487 if ( pSliceHeaderExt->sSliceHeader.pPps->uiNumSliceGroups > 1 )450 pCurLayer->iMbY = iMbY;
488 {451 pCurLayer->iMbXyIndex = iNextMbXyIndex;
489 iNextMbXyIndex = FmoNextMb( pFmo, iNextMbXyIndex );452 }
490 }453 return 0;
491 else454 }
492 {455
493 ++iNextMbXyIndex;456 do {
494 }457 pCurLayer->pSliceIdc[iNextMbXyIndex] = iSliceIdc;
495 458 iRet = pDecMbCavlcFunc (pCtx, pNalCur);
496 iMbX = iNextMbXyIndex%pCurLayer->iMbWidth;459
497 iMbY = iNextMbXyIndex%pCurLayer->iMbHeight;460 if (iRet != ERR_NONE) {
498 461 return iRet;
499 pCurLayer->iMbX = iMbX;462 }
500 pCurLayer->iMbY = iMbY;463
501 pCurLayer->iMbXyIndex = iNextMbXyIndex;464 ++pSlice->iTotalMbInCurSlice;
502 }465
503 return 0;466 if (pSliceHeader->pPps->uiNumSliceGroups > 1) {
504 }467 iNextMbXyIndex = FmoNextMb (pFmo, iNextMbXyIndex);
505 468 } else {
506 do{469 ++iNextMbXyIndex;
507 pCurLayer->pSliceIdc[iNextMbXyIndex] = iSliceIdc;470 }
508 iRet = pDecMbCavlcFunc( pCtx, pNalCur );471 if ((-1 == iNextMbXyIndex) || (iNextMbXyIndex >= kiCountNumMb)) { // slice group boundary or end of a frame
509 472 break;
510 if (iRet != ERR_NONE){473 }
511 return iRet;474
512 }475 // check whether there is left bits to read next time in case multiple slices
513 476 iUsedBits = ((pBs->pCurBuf - pBs->pStartBuf) << 3) - (16 - pBs->iLeftBits);
514 ++pSlice->iTotalMbInCurSlice;477 if (iUsedBits == pBs->iBits && 0 >= pCurLayer->sLayerInfo.sSliceInLayer.iMbSkipRun) { // slice boundary
515 478 break;
516 if ( pSliceHeader->pPps->uiNumSliceGroups > 1 )479 }
517 {480 if (iUsedBits > pBs->iBits) { //When BS incomplete, as long as find it, SHOULD stop decoding to avoid mosaic or crash.
518 iNextMbXyIndex = FmoNextMb( pFmo, iNextMbXyIndex );481 WelsLog (pCtx, WELS_LOG_WARNING,
519 }482 "WelsDecodeSlice()::::pBs incomplete, iUsedBits:%d > pBs->iBits:%d, MUST stop decoding.\n",
520 else483 iUsedBits, pBs->iBits);
521 {484 return -1;
522 ++iNextMbXyIndex;485 }
523 }486 iMbX = iNextMbXyIndex % pCurLayer->iMbWidth;
524 if ( (-1 == iNextMbXyIndex) || (iNextMbXyIndex >= kiCountNumMb) ) // slice group boundary or end of a frame487 iMbY = iNextMbXyIndex / pCurLayer->iMbWidth;
525 {488 pCurLayer->iMbX = iMbX;
526 break;489 pCurLayer->iMbY = iMbY;
527 }490 pCurLayer->iMbXyIndex = iNextMbXyIndex;
528 491 } while (1);
529 // check whether there is left bits to read next time in case multiple slices492
530 iUsedBits = ((pBs->pCurBuf-pBs->pStartBuf)<<3) - (16-pBs->iLeftBits);493 return ERR_NONE;
531 if ( iUsedBits == pBs->iBits && 0 >= pCurLayer->sLayerInfo.sSliceInLayer.iMbSkipRun ) // slice boundary494}
532 {495
533 break;496int32_t WelsActualDecodeMbCavlcISlice (PWelsDecoderContext pCtx) {
534 } 497 SVlcTable* pVlcTable = &pCtx->sVlcTable;
535 if ( iUsedBits > pBs->iBits )//When BS incomplete, as long as find it, SHOULD stop decoding to avoid mosaic or crash.498 PDqLayer pCurLayer = pCtx->pCurDqLayer;
536 {499 PBitStringAux pBs = pCurLayer->pBitStringAux;
537 WelsLog( pCtx, WELS_LOG_WARNING, "WelsDecodeSlice()::::pBs incomplete, iUsedBits:%d > pBs->iBits:%d, MUST stop decoding.\n", 500 PSlice pSlice = &pCurLayer->sLayerInfo.sSliceInLayer;
538 iUsedBits, pBs->iBits );501 PSliceHeader pSliceHeader = &pSlice->sSliceHeaderExt.sSliceHeader;
539 return -1;502
540 }503 SNeighAvail sNeighAvail;
541 iMbX = iNextMbXyIndex % pCurLayer->iMbWidth;504
542 iMbY = iNextMbXyIndex / pCurLayer->iMbWidth;505 int32_t iScanIdxStart = pSlice->sSliceHeaderExt.uiScanIdxStart;
543 pCurLayer->iMbX = iMbX;506 int32_t iScanIdxEnd = pSlice->sSliceHeaderExt.uiScanIdxEnd;
544 pCurLayer->iMbY = iMbY;507
545 pCurLayer->iMbXyIndex = iNextMbXyIndex;508 int32_t iMbX = pCurLayer->iMbX;
546 }while(1);509 int32_t iMbY = pCurLayer->iMbY;
547 510 int32_t iMbXy = pCurLayer->iMbXyIndex;
548 return ERR_NONE;511 int32_t iNMbMode, i;
512 uint32_t uiMbType = 0, uiCbp = 0, uiCbpL = 0, uiCbpC = 0;
513
514 FORCE_STACK_ALIGN_1D (uint8_t, pNonZeroCount, 48, 16);
515
516 pCurLayer->pInterPredictionDoneFlag[iMbXy] = 0;
517 pCurLayer->pResidualPredFlag[iMbXy] = pSlice->sSliceHeaderExt.bDefaultResidualPredFlag;
518
519 uiMbType = BsGetUe (pBs);
520 if (uiMbType > 25) {
521 return ERR_INFO_INVALID_MB_TYPE;
522 }
523
524 if (25 == uiMbType) {
525 int32_t iDecStrideL = pCurLayer->pDec->iLinesize[0];
526 int32_t iDecStrideC = pCurLayer->pDec->iLinesize[1];
527
528 int32_t iOffsetL = (iMbX + iMbY * iDecStrideL) << 4;
529 int32_t iOffsetC = (iMbX + iMbY * iDecStrideC) << 3;
530
531 uint8_t* pDecY = pCurLayer->pCsData[0] + iOffsetL;
532 uint8_t* pDecU = pCurLayer->pCsData[1] + iOffsetC;
533 uint8_t* pDecV = pCurLayer->pCsData[2] + iOffsetC;
534
535 uint8_t* pTmpBsBuf;
536
537 int32_t i;
538 int32_t iCopySizeY = (sizeof (uint8_t) << 4);
539 int32_t iCopySizeUV = (sizeof (uint8_t) << 3);
540
541 int32_t iIndex = ((-pBs->iLeftBits) >> 3) + 2;
542
543 pCurLayer->pMbType[iMbXy] = MB_TYPE_INTRA_PCM;
544
545 //step 1: locating bit-stream pointer [must align into integer byte]
546 pBs->pCurBuf -= iIndex;
547
548 //step 2: copy pixel from bit-stream into fdec [reconstruction]
549 pTmpBsBuf = pBs->pCurBuf;
550 for (i = 0; i < 16; i++) { //luma
551 memcpy (pDecY , pTmpBsBuf, iCopySizeY);
552 pDecY += iDecStrideL;
553 pTmpBsBuf += 16;
554 }
555 for (i = 0; i < 8; i++) { //cb
556 memcpy (pDecU, pTmpBsBuf, iCopySizeUV);
557 pDecU += iDecStrideC;
558 pTmpBsBuf += 8;
559 }
560 for (i = 0; i < 8; i++) { //cr
561 memcpy (pDecV, pTmpBsBuf, iCopySizeUV);
562 pDecV += iDecStrideC;
563 pTmpBsBuf += 8;
564 }
565
566 pBs->pCurBuf += 384;
567 InitReadBits (pBs);
568
569 //step 3: update QP and pNonZeroCount
570 pCurLayer->pLumaQp[iMbXy] = 0;
571 pCurLayer->pChromaQp[iMbXy] = 0;
572 memset (pCurLayer->pNzc[iMbXy], 16, sizeof (pCurLayer->pNzc[iMbXy])); //JVT-x201wcm1.doc, page229, 2009.10.23
573 return 0;
574 } else if (0 == uiMbType) { //reference to JM
575 FORCE_STACK_ALIGN_1D (int8_t, pIntraPredMode, 48, 16);
576 pCurLayer->pMbType[iMbXy] = MB_TYPE_INTRA4x4;
577 pCtx->pFillInfoCacheIntra4x4Func (&sNeighAvail, pNonZeroCount, pIntraPredMode, pCurLayer);
578 if (pCtx->pParseIntra4x4ModeFunc (&sNeighAvail, pIntraPredMode, pBs, pCurLayer)) {
579 return -1;
580 }
581
582 //uiCbp
583 uiCbp = BsGetUe (pBs);
584 //G.9.1 Alternative parsing process for coded pBlock pattern
585 if (uiCbp > 47)
586 return ERR_INFO_INVALID_CBP;
587
588 uiCbp = g_kuiIntra4x4CbpTable[uiCbp];
589
590 pCurLayer->pCbp[iMbXy] = uiCbp;
591 uiCbpC = uiCbp >> 4;
592 uiCbpL = uiCbp & 15;
593 } else { //I_PCM exclude, we can ignore it
594 pCurLayer->pMbType[iMbXy] = MB_TYPE_INTRA16x16;
595 pCurLayer->pIntraPredMode[iMbXy][7] = (uiMbType - 1) & 3;
596 pCurLayer->pCbp[iMbXy] = g_kuiI16CbpTable[ (uiMbType - 1) >> 2];
597 uiCbpC = pCurLayer->pCbp[iMbXy] >> 4;
598 uiCbpL = pCurLayer->pCbp[iMbXy] & 15;
599 WelsFillCacheNonZeroCount (&sNeighAvail, pNonZeroCount, pCurLayer);
600 if (pCtx->pParseIntra16x16ModeFunc (&sNeighAvail, pBs, pCurLayer)) {
601 return -1;
602 }
603 }
604
605 iNMbMode = BASE_MB;
606
607 memset (pCurLayer->pScaledTCoeff[iMbXy], 0, 384 * sizeof (pCurLayer->pScaledTCoeff[iMbXy][0]));
608 ST32 (&pCurLayer->pNzc[iMbXy][0], 0);
609 ST32 (&pCurLayer->pNzc[iMbXy][4], 0);
610 ST32 (&pCurLayer->pNzc[iMbXy][8], 0);
611 ST32 (&pCurLayer->pNzc[iMbXy][12], 0);
612 ST32 (&pCurLayer->pNzc[iMbXy][16], 0);
613 ST32 (&pCurLayer->pNzc[iMbXy][20], 0);
614
615 if (pCurLayer->pCbp[iMbXy] == 0 && IS_INTRA4x4 (pCurLayer->pMbType[iMbXy])) {
616 pCurLayer->pLumaQp[iMbXy] = pSlice->iLastMbQp;
617 pCurLayer->pChromaQp[iMbXy] = g_kuiChromaQp[WELS_CLIP3 (pCurLayer->pLumaQp[iMbXy] +
618 pSliceHeader->pPps->iChromaQpIndexOffset, 0, 51)];
619
620 }
621
622 if (pCurLayer->pCbp[iMbXy] || MB_TYPE_INTRA16x16 == pCurLayer->pMbType[iMbXy]) {
623 int32_t iQpDelta, iId8x8, iId4x4;
624
625 iQpDelta = BsGetSe (pBs);
626
627 if (iQpDelta > 25 || iQpDelta < -26) { //out of iQpDelta range
628 return ERR_INFO_INVALID_QP;
629 }
630
631 pCurLayer->pLumaQp[iMbXy] = pSlice->iLastMbQp + iQpDelta; //update iLastMbQp
632 //refer to JVT-X201wcm1.doc equation(7-35)
633 if ((unsigned) (pCurLayer->pLumaQp[iMbXy]) > 51) {
634 if (pCurLayer->pLumaQp[iMbXy] < 0) {
635 pCurLayer->pLumaQp[iMbXy] += 52;
636 } else {
637 pCurLayer->pLumaQp[iMbXy] -= 52;
638 }
639 }
640 //QP should be in the range of [0, 51]
641 if (pCurLayer->pLumaQp[iMbXy] < 0 || pCurLayer->pLumaQp[iMbXy] > 51) {
642 return ERR_INFO_INVALID_QP;
643 }
644 pSlice->iLastMbQp = pCurLayer->pLumaQp[iMbXy];
645 pCurLayer->pChromaQp[iMbXy] = g_kuiChromaQp[WELS_CLIP3 (pSlice->iLastMbQp + pSliceHeader->pPps->iChromaQpIndexOffset, 0,
646 51)];
647
648
649 BsStartCavlc (pBs);
650
651 if (MB_TYPE_INTRA16x16 == pCurLayer->pMbType[iMbXy]) {
652 //step1: Luma DC
653 if (WelsResidualBlockCavlc (pVlcTable, pNonZeroCount, pBs, 0, 16,
654 g_kuiLumaDcZigzagScan, I16_LUMA_DC, pCurLayer->pScaledTCoeff[iMbXy], iNMbMode, pCurLayer->pLumaQp[iMbXy], pCtx)) {
655 return -1;//abnormal
656 }
657 //step2: Luma AC
658 if (uiCbpL) {
659 for (i = 0; i < 16; i++) {
660 if (WelsResidualBlockCavlc (pVlcTable, pNonZeroCount, pBs, i,
661 iScanIdxEnd - WELS_MAX (iScanIdxStart, 1) + 1, g_kuiZigzagScan + WELS_MAX (iScanIdxStart, 1),
662 I16_LUMA_AC, pCurLayer->pScaledTCoeff[iMbXy] + (i << 4), iNMbMode, pCurLayer->pLumaQp[iMbXy], pCtx)) {
663 return -1;//abnormal
664 }
665 }
666 ST32 (&pCurLayer->pNzc[iMbXy][0], LD32 (&pNonZeroCount[1 + 8 * 1]));
667 ST32 (&pCurLayer->pNzc[iMbXy][4], LD32 (&pNonZeroCount[1 + 8 * 2]));
668 ST32 (&pCurLayer->pNzc[iMbXy][8], LD32 (&pNonZeroCount[1 + 8 * 3]));
669 ST32 (&pCurLayer->pNzc[iMbXy][12], LD32 (&pNonZeroCount[1 + 8 * 4]));
670 } else { //pNonZeroCount = 0
671 ST32 (&pCurLayer->pNzc[iMbXy][0], 0);
672 ST32 (&pCurLayer->pNzc[iMbXy][4], 0);
673 ST32 (&pCurLayer->pNzc[iMbXy][8], 0);
674 ST32 (&pCurLayer->pNzc[iMbXy][12], 0);
675 }
676 } else { //non-MB_TYPE_INTRA16x16
677 for (iId8x8 = 0; iId8x8 < 4; iId8x8++) {
678 if (uiCbpL & (1 << iId8x8)) {
679 int32_t iIndex = (iId8x8 << 2);
680 for (iId4x4 = 0; iId4x4 < 4; iId4x4++) {
681 //Luma (DC and AC decoding together)
682 if (WelsResidualBlockCavlc (pVlcTable, pNonZeroCount, pBs, iIndex,
683 iScanIdxEnd - iScanIdxStart + 1, g_kuiZigzagScan + iScanIdxStart,
684 LUMA_DC_AC, pCurLayer->pScaledTCoeff[iMbXy] + (iIndex << 4), iNMbMode, pCurLayer->pLumaQp[iMbXy], pCtx)) {
685 return -1;//abnormal
686 }
687 iIndex++;
688 }
689 } else {
690 ST16 (&pNonZeroCount[g_kuiCacheNzcScanIdx[ (iId8x8 << 2)]], 0);
691 ST16 (&pNonZeroCount[g_kuiCacheNzcScanIdx[ (iId8x8 << 2) + 2]], 0);
692 }
693 }
694 ST32 (&pCurLayer->pNzc[iMbXy][0], LD32 (&pNonZeroCount[1 + 8 * 1]));
695 ST32 (&pCurLayer->pNzc[iMbXy][4], LD32 (&pNonZeroCount[1 + 8 * 2]));
696 ST32 (&pCurLayer->pNzc[iMbXy][8], LD32 (&pNonZeroCount[1 + 8 * 3]));
697 ST32 (&pCurLayer->pNzc[iMbXy][12], LD32 (&pNonZeroCount[1 + 8 * 4]));
698 }
699
700 //chroma
701 //step1: DC
702 if (1 == uiCbpC || 2 == uiCbpC) {
703 for (i = 0; i < 2; i++) { //Cb Cr
704 if (WelsResidualBlockCavlc (pVlcTable, pNonZeroCount, pBs,
705 16 + (i << 2), 4, g_kuiChromaDcScan, CHROMA_DC, pCurLayer->pScaledTCoeff[iMbXy] + 256 + (i << 6),
706 iNMbMode, pCurLayer->pChromaQp[iMbXy], pCtx)) {
707 return -1;//abnormal
708 }
709 }
710 }
711
712 //step2: AC
713 if (2 == uiCbpC) {
714 for (i = 0; i < 2; i++) { //Cb Cr
715 int32_t iIndex = 16 + (i << 2);
716 for (iId4x4 = 0; iId4x4 < 4; iId4x4++) {
717 if (WelsResidualBlockCavlc (pVlcTable, pNonZeroCount, pBs, iIndex,
718 iScanIdxEnd - WELS_MAX (iScanIdxStart, 1) + 1, g_kuiZigzagScan + WELS_MAX (iScanIdxStart, 1),
719 CHROMA_AC, pCurLayer->pScaledTCoeff[iMbXy] + (iIndex << 4), iNMbMode, pCurLayer->pChromaQp[iMbXy], pCtx)) {
720 return -1;//abnormal
721 }
722 iIndex++;
723 }
724 }
725 ST16 (&pCurLayer->pNzc[iMbXy][16], LD16 (&pNonZeroCount[6 + 8 * 1]));
726 ST16 (&pCurLayer->pNzc[iMbXy][20], LD16 (&pNonZeroCount[6 + 8 * 2]));
727 ST16 (&pCurLayer->pNzc[iMbXy][18], LD16 (&pNonZeroCount[6 + 8 * 4]));
728 ST16 (&pCurLayer->pNzc[iMbXy][22], LD16 (&pNonZeroCount[6 + 8 * 5]));
729 } else {
730 ST16 (&pCurLayer->pNzc[iMbXy][16], 0);
731 ST16 (&pCurLayer->pNzc[iMbXy][20], 0);
732 ST16 (&pCurLayer->pNzc[iMbXy][18], 0);
733 ST16 (&pCurLayer->pNzc[iMbXy][22], 0);
734 }
735 BsEndCavlc (pBs);
736 } else {
737 ST32 (&pCurLayer->pNzc[iMbXy][0], 0);
738 ST32 (&pCurLayer->pNzc[iMbXy][4], 0);
739 ST32 (&pCurLayer->pNzc[iMbXy][8], 0);
740 ST32 (&pCurLayer->pNzc[iMbXy][12], 0);
741 ST32 (&pCurLayer->pNzc[iMbXy][16], 0);
742 ST32 (&pCurLayer->pNzc[iMbXy][20], 0);
743 }
744
745 return 0;
549}746}
550 747
551int32_t WelsActualDecodeMbCavlcISlice(PWelsDecoderContext pCtx)748int32_t WelsDecodeMbCavlcISlice (PWelsDecoderContext pCtx, PNalUnit pNalCur) {
552{ 749 PDqLayer pCurLayer = pCtx->pCurDqLayer;
553 SVlcTable* pVlcTable = &pCtx->sVlcTable;750 PBitStringAux pBs = pCurLayer->pBitStringAux;
554 PDqLayer pCurLayer = pCtx->pCurDqLayer;751 PSliceHeaderExt pSliceHeaderExt = &pCurLayer->sLayerInfo.sSliceInLayer.sSliceHeaderExt;
555 PBitStringAux pBs = pCurLayer->pBitStringAux;752 int32_t iBaseModeFlag;
556 PSlice pSlice = &pCurLayer->sLayerInfo.sSliceInLayer;753 int32_t iRet = 0; //should have the return value to indicate decoding error or not, It's NECESSARY--2010.4.15
557 PSliceHeader pSliceHeader = &pSlice->sSliceHeaderExt.sSliceHeader;754
558 755 if (pSliceHeaderExt->bAdaptiveBaseModeFlag == 1) {
559 SNeighAvail sNeighAvail;756 iBaseModeFlag = BsGetOneBit (pBs);
560 757 } else {
561 int32_t iScanIdxStart = pSlice->sSliceHeaderExt.uiScanIdxStart;758 iBaseModeFlag = pSliceHeaderExt->bDefaultBaseModeFlag;
562 int32_t iScanIdxEnd = pSlice->sSliceHeaderExt.uiScanIdxEnd; 759 }
563 760 if (!iBaseModeFlag) {
564 int32_t iMbX = pCurLayer->iMbX;761 iRet = WelsActualDecodeMbCavlcISlice (pCtx);
565 int32_t iMbY = pCurLayer->iMbY;762 } else {
566 int32_t iMbXy = pCurLayer->iMbXyIndex;763 WelsLog (pCtx, WELS_LOG_WARNING, "iBaseModeFlag (%d) != 0, inter-layer prediction not supported.\n", iBaseModeFlag);
567 int32_t iNMbMode, i;764 return GENERATE_ERROR_NO (ERR_LEVEL_SLICE_HEADER, ERR_INFO_UNSUPPORTED_ILP);
568 uint32_t uiMbType = 0, uiCbp = 0, uiCbpL = 0, uiCbpC = 0;765 }
569 766 if (iRet) { //occur error when parsing, MUST STOP decoding
570 FORCE_STACK_ALIGN_1D( uint8_t, pNonZeroCount, 48, 16 );767 return iRet;
571 768 }
572 pCurLayer->pInterPredictionDoneFlag[iMbXy] = 0;769
573 pCurLayer->pResidualPredFlag[iMbXy] = pSlice->sSliceHeaderExt.bDefaultResidualPredFlag;770 return 0;
574
575 uiMbType = BsGetUe(pBs);
576 if ( uiMbType > 25 )
577 {
578 return ERR_INFO_INVALID_MB_TYPE;
579 }
580
581 if ( 25 == uiMbType )
582 {
583 int32_t iDecStrideL = pCurLayer->pDec->iLinesize[0];
584 int32_t iDecStrideC = pCurLayer->pDec->iLinesize[1];
585
586 int32_t iOffsetL = ( iMbX + iMbY * iDecStrideL ) << 4;
587 int32_t iOffsetC = ( iMbX + iMbY * iDecStrideC ) << 3;
588
589 uint8_t* pDecY = pCurLayer->pCsData[0] + iOffsetL;
590 uint8_t* pDecU = pCurLayer->pCsData[1] + iOffsetC;
591 uint8_t* pDecV = pCurLayer->pCsData[2] + iOffsetC;
592
593 uint8_t *pTmpBsBuf;
594
595 int32_t i;
596 int32_t iCopySizeY = ( sizeof( uint8_t ) << 4 );
597 int32_t iCopySizeUV = ( sizeof( uint8_t ) << 3 );
598
599 int32_t iIndex = ((-pBs->iLeftBits)>>3) + 2;
600
601 pCurLayer->pMbType[iMbXy] = MB_TYPE_INTRA_PCM;
602
603 //step 1: locating bit-stream pointer [must align into integer byte]
604 pBs->pCurBuf -= iIndex;
605
606 //step 2: copy pixel from bit-stream into fdec [reconstruction]
607 pTmpBsBuf = pBs->pCurBuf;
608 for ( i = 0; i < 16; i++ ) //luma
609 {
610 memcpy( pDecY , pTmpBsBuf, iCopySizeY );
611 pDecY += iDecStrideL;
612 pTmpBsBuf += 16;
613 }
614 for ( i = 0; i < 8; i++ ) //cb
615 {
616 memcpy( pDecU, pTmpBsBuf, iCopySizeUV );
617 pDecU += iDecStrideC;
618 pTmpBsBuf += 8;
619 }
620 for ( i = 0; i < 8; i++ ) //cr
621 {
622 memcpy( pDecV, pTmpBsBuf, iCopySizeUV );
623 pDecV += iDecStrideC;
624 pTmpBsBuf += 8;
625 }
626
627 pBs->pCurBuf += 384;
628 InitReadBits( pBs );
629
630 //step 3: update QP and pNonZeroCount
631 pCurLayer->pLumaQp[iMbXy] = 0;
632 pCurLayer->pChromaQp[iMbXy] = 0;
633 memset( pCurLayer->pNzc[iMbXy], 16, sizeof( pCurLayer->pNzc[iMbXy] ) ); //JVT-x201wcm1.doc, page229, 2009.10.23
634 return 0;
635 }
636 else if (0 == uiMbType) //reference to JM
637 {
638 FORCE_STACK_ALIGN_1D( int8_t, pIntraPredMode, 48, 16 );
639 pCurLayer->pMbType[iMbXy] = MB_TYPE_INTRA4x4;
640 pCtx->pFillInfoCacheIntra4x4Func( &sNeighAvail, pNonZeroCount, pIntraPredMode, pCurLayer );
641 if ( pCtx->pParseIntra4x4ModeFunc( &sNeighAvail, pIntraPredMode, pBs, pCurLayer ) )
642 {
643 return -1;
644 }
645
646 //uiCbp
647 uiCbp = BsGetUe(pBs);
648 //G.9.1 Alternative parsing process for coded pBlock pattern
649 if ( uiCbp > 47 )
650 return ERR_INFO_INVALID_CBP;
651
652 uiCbp = g_kuiIntra4x4CbpTable[uiCbp];
653
654 pCurLayer->pCbp[iMbXy] = uiCbp;
655 uiCbpC = uiCbp >> 4;
656 uiCbpL = uiCbp & 15;
657 }
658 else //I_PCM exclude, we can ignore it
659 {
660 pCurLayer->pMbType[iMbXy] = MB_TYPE_INTRA16x16;
661 pCurLayer->pIntraPredMode[iMbXy][7] = (uiMbType-1) & 3;
662 pCurLayer->pCbp[iMbXy] = g_kuiI16CbpTable[(uiMbType-1)>>2];
663 uiCbpC = pCurLayer->pCbp[iMbXy] >> 4;
664 uiCbpL = pCurLayer->pCbp[iMbXy] & 15;
665 WelsFillCacheNonZeroCount( &sNeighAvail, pNonZeroCount, pCurLayer );
666 if ( pCtx->pParseIntra16x16ModeFunc( &sNeighAvail, pBs, pCurLayer ) )
667 {
668 return -1;
669 }
670 }
671
672 iNMbMode = BASE_MB;
673
674 memset(pCurLayer->pScaledTCoeff[iMbXy], 0, 384*sizeof(pCurLayer->pScaledTCoeff[iMbXy][0]));
675 ST32(&pCurLayer->pNzc[iMbXy][0], 0);
676 ST32(&pCurLayer->pNzc[iMbXy][4], 0);
677 ST32(&pCurLayer->pNzc[iMbXy][8], 0);
678 ST32(&pCurLayer->pNzc[iMbXy][12], 0);
679 ST32(&pCurLayer->pNzc[iMbXy][16], 0);
680 ST32(&pCurLayer->pNzc[iMbXy][20], 0);
681
682 if( pCurLayer->pCbp[iMbXy] == 0 && IS_INTRA4x4(pCurLayer->pMbType[iMbXy]))
683 {
684 pCurLayer->pLumaQp[iMbXy] = pSlice->iLastMbQp;
685 pCurLayer->pChromaQp[iMbXy] = g_kuiChromaQp[WELS_CLIP3(pCurLayer->pLumaQp[iMbXy] +
686 pSliceHeader->pPps->iChromaQpIndexOffset, 0, 51)];
687
688 }
689
690 if ( pCurLayer->pCbp[iMbXy] || MB_TYPE_INTRA16x16 == pCurLayer->pMbType[iMbXy] )
691 {
692 int32_t iQpDelta, iId8x8, iId4x4;
693
694 iQpDelta = BsGetSe(pBs);
695
696 if (iQpDelta > 25 || iQpDelta < -26) //out of iQpDelta range
697 {
698 return ERR_INFO_INVALID_QP;
699 }
700
701 pCurLayer->pLumaQp[iMbXy] = pSlice->iLastMbQp + iQpDelta; //update iLastMbQp
702 //refer to JVT-X201wcm1.doc equation(7-35)
703 if ( (unsigned)(pCurLayer->pLumaQp[iMbXy]) > 51 )
704 {
705 if ( pCurLayer->pLumaQp[iMbXy] < 0 )
706 {
707 pCurLayer->pLumaQp[iMbXy] += 52;
708 }
709 else
710 {
711 pCurLayer->pLumaQp[iMbXy] -= 52;
712 }
713 }
714 //QP should be in the range of [0, 51]
715 if ( pCurLayer->pLumaQp[iMbXy] < 0 || pCurLayer->pLumaQp[iMbXy] > 51 )
716 {
717 return ERR_INFO_INVALID_QP;
718 }
719 pSlice->iLastMbQp = pCurLayer->pLumaQp[iMbXy];
720 pCurLayer->pChromaQp[iMbXy] = g_kuiChromaQp[WELS_CLIP3(pSlice->iLastMbQp + pSliceHeader->pPps->iChromaQpIndexOffset, 0, 51)];
721
722
723 BsStartCavlc( pBs );
724
725 if ( MB_TYPE_INTRA16x16 == pCurLayer->pMbType[iMbXy] )
726 {
727 //step1: Luma DC
728 if ( WelsResidualBlockCavlc( pVlcTable, pNonZeroCount, pBs, 0, 16,
729 g_kuiLumaDcZigzagScan, I16_LUMA_DC, pCurLayer->pScaledTCoeff[iMbXy], iNMbMode, pCurLayer->pLumaQp[iMbXy], pCtx) )
730 {
731 return -1;//abnormal
732 }
733 //step2: Luma AC
734 if (uiCbpL)
735 {
736 for (i = 0; i < 16; i++)
737 {
738 if ( WelsResidualBlockCavlc( pVlcTable, pNonZeroCount, pBs, i,
739 iScanIdxEnd - WELS_MAX(iScanIdxStart, 1) + 1, g_kuiZigzagScan+ WELS_MAX(iScanIdxStart,1),
740 I16_LUMA_AC, pCurLayer->pScaledTCoeff[iMbXy] + (i<<4), iNMbMode, pCurLayer->pLumaQp[iMbXy], pCtx) )
741 {
742 return -1;//abnormal
743 }
744 }
745 ST32(&pCurLayer->pNzc[iMbXy][0], LD32(&pNonZeroCount[1+8*1]));
746 ST32(&pCurLayer->pNzc[iMbXy][4], LD32(&pNonZeroCount[1+8*2]));
747 ST32(&pCurLayer->pNzc[iMbXy][8], LD32(&pNonZeroCount[1+8*3]));
748 ST32(&pCurLayer->pNzc[iMbXy][12], LD32(&pNonZeroCount[1+8*4]));
749 }
750 else //pNonZeroCount = 0
751 {
752 ST32(&pCurLayer->pNzc[iMbXy][0], 0);
753 ST32(&pCurLayer->pNzc[iMbXy][4], 0);
754 ST32(&pCurLayer->pNzc[iMbXy][8], 0);
755 ST32(&pCurLayer->pNzc[iMbXy][12], 0);
756 }
757 }
758 else //non-MB_TYPE_INTRA16x16
759 {
760 for (iId8x8 = 0; iId8x8 < 4; iId8x8++)
761 {
762 if (uiCbpL & (1 << iId8x8))
763 {
764 int32_t iIndex = (iId8x8 << 2);
765 for (iId4x4 = 0; iId4x4 < 4; iId4x4++)
766 {
767 //Luma (DC and AC decoding together)
768 if ( WelsResidualBlockCavlc( pVlcTable, pNonZeroCount, pBs, iIndex,
769 iScanIdxEnd - iScanIdxStart + 1, g_kuiZigzagScan+iScanIdxStart,
770 LUMA_DC_AC, pCurLayer->pScaledTCoeff[iMbXy] + (iIndex<<4), iNMbMode, pCurLayer->pLumaQp[iMbXy], pCtx) )
771 {
772 return -1;//abnormal
773 }
774 iIndex++;
775 }
776 }
777 else
778 {
779 ST16(&pNonZeroCount[g_kuiCacheNzcScanIdx[(iId8x8<<2)]], 0);
780 ST16(&pNonZeroCount[g_kuiCacheNzcScanIdx[(iId8x8<<2)+2]], 0);
781 }
782 }
783 ST32(&pCurLayer->pNzc[iMbXy][0], LD32(&pNonZeroCount[1+8*1]));
784 ST32(&pCurLayer->pNzc[iMbXy][4], LD32(&pNonZeroCount[1+8*2]));
785 ST32(&pCurLayer->pNzc[iMbXy][8], LD32(&pNonZeroCount[1+8*3]));
786 ST32(&pCurLayer->pNzc[iMbXy][12], LD32(&pNonZeroCount[1+8*4]));
787 }
788
789 //chroma
790 //step1: DC
791 if ( 1 == uiCbpC || 2 == uiCbpC )
792 {
793 for (i = 0; i < 2; i++) //Cb Cr
794 {
795 if ( WelsResidualBlockCavlc( pVlcTable, pNonZeroCount, pBs,
796 16 + (i << 2), 4, g_kuiChromaDcScan, CHROMA_DC, pCurLayer->pScaledTCoeff[iMbXy] + 256 + (i<<6),
797 iNMbMode, pCurLayer->pChromaQp[iMbXy], pCtx) )
798 {
799 return -1;//abnormal
800 }
801 }
802 }
803
804 //step2: AC
805 if (2 == uiCbpC)
806 {
807 for (i = 0; i < 2; i++) //Cb Cr
808 {
809 int32_t iIndex = 16 + (i<<2);
810 for (iId4x4 = 0; iId4x4 < 4; iId4x4++)
811 {
812 if ( WelsResidualBlockCavlc( pVlcTable, pNonZeroCount, pBs, iIndex,
813 iScanIdxEnd - WELS_MAX(iScanIdxStart, 1) + 1, g_kuiZigzagScan + WELS_MAX(iScanIdxStart,1),
814 CHROMA_AC, pCurLayer->pScaledTCoeff[iMbXy]+(iIndex<<4), iNMbMode, pCurLayer->pChromaQp[iMbXy], pCtx) )
815 {
816 return -1;//abnormal
817 }
818 iIndex++;
819 }
820 }
821 ST16(&pCurLayer->pNzc[iMbXy][16], LD16(&pNonZeroCount[6+8*1]));
822 ST16(&pCurLayer->pNzc[iMbXy][20], LD16(&pNonZeroCount[6+8*2]));
823 ST16(&pCurLayer->pNzc[iMbXy][18], LD16(&pNonZeroCount[6+8*4]));
824 ST16(&pCurLayer->pNzc[iMbXy][22], LD16(&pNonZeroCount[6+8*5]));
825 }
826 else
827 {
828 ST16(&pCurLayer->pNzc[iMbXy][16], 0);
829 ST16(&pCurLayer->pNzc[iMbXy][20], 0);
830 ST16(&pCurLayer->pNzc[iMbXy][18], 0);
831 ST16(&pCurLayer->pNzc[iMbXy][22], 0);
832 }
833 BsEndCavlc( pBs );
834 }
835 else
836 {
837 ST32(&pCurLayer->pNzc[iMbXy][0], 0);
838 ST32(&pCurLayer->pNzc[iMbXy][4], 0);
839 ST32(&pCurLayer->pNzc[iMbXy][8], 0);
840 ST32(&pCurLayer->pNzc[iMbXy][12], 0);
841 ST32(&pCurLayer->pNzc[iMbXy][16], 0);
842 ST32(&pCurLayer->pNzc[iMbXy][20], 0);
843 }
844
845 return 0;
846}771}
847 772
848int32_t WelsDecodeMbCavlcISlice(PWelsDecoderContext pCtx, PNalUnit pNalCur)773int32_t WelsActualDecodeMbCavlcPSlice (PWelsDecoderContext pCtx) {
849{774 SVlcTable* pVlcTable = &pCtx->sVlcTable;
850 PDqLayer pCurLayer = pCtx->pCurDqLayer;775 PDqLayer pCurLayer = pCtx->pCurDqLayer;
851 PBitStringAux pBs = pCurLayer->pBitStringAux; 776 PBitStringAux pBs = pCurLayer->pBitStringAux;
852 PSliceHeaderExt pSliceHeaderExt = &pCurLayer->sLayerInfo.sSliceInLayer.sSliceHeaderExt;777 PSlice pSlice = &pCurLayer->sLayerInfo.sSliceInLayer;
853 int32_t iBaseModeFlag; 778 PSliceHeader pSliceHeader = &pSlice->sSliceHeaderExt.sSliceHeader;
854 int32_t iRet = 0; //should have the return value to indicate decoding error or not, It's NECESSARY--2010.4.15779
855 780 SNeighAvail sNeighAvail;
856 if( pSliceHeaderExt->bAdaptiveBaseModeFlag == 1)781
857 {782 int32_t iScanIdxStart = pSlice->sSliceHeaderExt.uiScanIdxStart;
858 iBaseModeFlag = BsGetOneBit(pBs);783 int32_t iScanIdxEnd = pSlice->sSliceHeaderExt.uiScanIdxEnd;
859 }784
860 else785 int32_t iMbX = pCurLayer->iMbX;
861 {786 int32_t iMbY = pCurLayer->iMbY;
862 iBaseModeFlag = pSliceHeaderExt->bDefaultBaseModeFlag;787 int32_t iMbXy = pCurLayer->iMbXyIndex;
863 }788
864 if( !iBaseModeFlag )789 int32_t iNMbMode, i;
865 {790 uint32_t uiMbType = 0, uiCbp = 0, uiCbpL = 0, uiCbpC = 0;
866 iRet = WelsActualDecodeMbCavlcISlice( pCtx);791
792 FORCE_STACK_ALIGN_1D (uint8_t, pNonZeroCount, 48, 16);
793 pCurLayer->pInterPredictionDoneFlag[iMbXy] = 0;//2009.10.23
794
795 uiMbType = BsGetUe (pBs);
796 if (uiMbType < 5) { //inter MB type
797 int16_t iMotionVector[LIST_A][30][MV_A];
798
799 int8_t iRefIndex[LIST_A][30];
800 pCurLayer->pMbType[iMbXy] = g_ksInterMbTypeInfo[uiMbType].iType;
801 WelsFillCacheInter (&sNeighAvail, pNonZeroCount, iMotionVector, iRefIndex, pCurLayer);
802 if (ParseInterInfo (pCtx, iMotionVector, iRefIndex, pBs)) {
803 return -1;//abnormal
804 }
805
806 if (pSlice->sSliceHeaderExt.bAdaptiveResidualPredFlag == 1) {
807 pCurLayer->pResidualPredFlag[iMbXy] = BsGetOneBit (pBs);
808 } else {
809 pCurLayer->pResidualPredFlag[iMbXy] = pSlice->sSliceHeaderExt.bDefaultResidualPredFlag;
810 }
811
812 if (pCurLayer->pResidualPredFlag[iMbXy] == 0) {
813 iNMbMode = BASE_MB;
814 pCurLayer->pInterPredictionDoneFlag[iMbXy] = 0;
815 } else {
816 WelsLog (pCtx, WELS_LOG_WARNING, "residual_pred_flag = 1 not supported.\n");
817 return -1;
818 }
819 } else { //intra MB type
820 uiMbType -= 5;
821 if (uiMbType > 25) {
822 return ERR_INFO_INVALID_MB_TYPE;
823 }
824
825 if (25 == uiMbType) {
826 int32_t iDecStrideL = pCurLayer->pDec->iLinesize[0];
827 int32_t iDecStrideC = pCurLayer->pDec->iLinesize[1];
828
829 int32_t iOffsetL = (iMbX + iMbY * iDecStrideL) << 4;
830 int32_t iOffsetC = (iMbX + iMbY * iDecStrideC) << 3;
831
832 uint8_t* pDecY = pCurLayer->pCsData[0] + iOffsetL;
833 uint8_t* pDecU = pCurLayer->pCsData[1] + iOffsetC;
834 uint8_t* pDecV = pCurLayer->pCsData[2] + iOffsetC;
835
836 uint8_t* pTmpBsBuf;
837
838 int32_t i;
839 int32_t iCopySizeY = (sizeof (uint8_t) << 4);
840 int32_t iCopySizeUV = (sizeof (uint8_t) << 3);
841
842 int32_t iIndex = ((-pBs->iLeftBits) >> 3) + 2;
843
844 pCurLayer->pMbType[iMbXy] = MB_TYPE_INTRA_PCM;
845
846 //step 1: locating bit-stream pointer [must align into integer byte]
847 pBs->pCurBuf -= iIndex;
848
849 //step 2: copy pixel from bit-stream into fdec [reconstruction]
850 pTmpBsBuf = pBs->pCurBuf;
851 for (i = 0; i < 16; i++) { //luma
852 memcpy (pDecY , pTmpBsBuf, iCopySizeY);
853 pDecY += iDecStrideL;
854 pTmpBsBuf += 16;
855 }
856
857 for (i = 0; i < 8; i++) { //cb
858 memcpy (pDecU, pTmpBsBuf, iCopySizeUV);
859 pDecU += iDecStrideC;
860 pTmpBsBuf += 8;
861 }
862 for (i = 0; i < 8; i++) { //cr
863 memcpy (pDecV, pTmpBsBuf, iCopySizeUV);
864 pDecV += iDecStrideC;
865 pTmpBsBuf += 8;
866 }
867
868 pBs->pCurBuf += 384;
869 InitReadBits (pBs);
870
871 //step 3: update QP and pNonZeroCount
872 pCurLayer->pLumaQp[iMbXy] = 0;
873 pCurLayer->pChromaQp[iMbXy] = 0;
874 ST32 (&pCurLayer->pNzc[iMbXy][0], 0);
875 ST32 (&pCurLayer->pNzc[iMbXy][4], 0);
876 ST32 (&pCurLayer->pNzc[iMbXy][8], 0);
877 ST32 (&pCurLayer->pNzc[iMbXy][12], 0);
878 return 0;
879 } else {
880 if (0 == uiMbType) {
881 FORCE_STACK_ALIGN_1D (int8_t, pIntraPredMode, 48, 16);
882 pCurLayer->pMbType[iMbXy] = MB_TYPE_INTRA4x4;
883 pCtx->pFillInfoCacheIntra4x4Func (&sNeighAvail, pNonZeroCount, pIntraPredMode, pCurLayer);
884 if (pCtx->pParseIntra4x4ModeFunc (&sNeighAvail, pIntraPredMode, pBs, pCurLayer)) {
885 return -1;
886 }
887 iNMbMode = BASE_MB;
888 } else { //I_PCM exclude, we can ignore it
889 pCurLayer->pMbType[iMbXy] = MB_TYPE_INTRA16x16;
890 pCurLayer->pIntraPredMode[iMbXy][7] = (uiMbType - 1) & 3;
891 pCurLayer->pCbp[iMbXy] = g_kuiI16CbpTable[ (uiMbType - 1) >> 2];
892 uiCbpC = pCurLayer->pCbp[iMbXy] >> 4;
893 uiCbpL = pCurLayer->pCbp[iMbXy] & 15;
894 WelsFillCacheNonZeroCount (&sNeighAvail, pNonZeroCount, pCurLayer);
895 if (pCtx->pParseIntra16x16ModeFunc (&sNeighAvail, pBs, pCurLayer)) {
896 return -1;
897 }
898 iNMbMode = BASE_MB;
899 }
867 }900 }
868 else901 }
902
903 if (MB_TYPE_INTRA16x16 != pCurLayer->pMbType[iMbXy]) {
904 uiCbp = BsGetUe (pBs);
869 {905 {
870 WelsLog( pCtx, WELS_LOG_WARNING, "iBaseModeFlag (%d) != 0, inter-layer prediction not supported.\n", iBaseModeFlag);906 if (uiCbp > 47)
871 return GENERATE_ERROR_NO(ERR_LEVEL_SLICE_HEADER, ERR_INFO_UNSUPPORTED_ILP);907 return ERR_INFO_INVALID_CBP;
908
909 if (MB_TYPE_INTRA4x4 == pCurLayer->pMbType[iMbXy]) {
910 uiCbp = g_kuiIntra4x4CbpTable[uiCbp];
911 } else //inter
912 uiCbp = g_kuiInterCbpTable[uiCbp];
872 }913 }
873 if ( iRet ) //occur error when parsing, MUST STOP decoding
874 {
875 return iRet;
876 }
877 914
878 return 0;915 pCurLayer->pCbp[iMbXy] = uiCbp;
879}916 uiCbpC = pCurLayer->pCbp[iMbXy] >> 4;
917 uiCbpL = pCurLayer->pCbp[iMbXy] & 15;
918 }
919
920 if (iNMbMode == BASE_MB) {
921 pCtx->sBlockFunc.pWelsBlockZero16x16Func (pCurLayer->pScaledTCoeff[iMbXy], 16);
922 pCtx->sBlockFunc.pWelsBlockZero8x8Func (pCurLayer->pScaledTCoeff[iMbXy] + 256, 8);
923 pCtx->sBlockFunc.pWelsBlockZero8x8Func (pCurLayer->pScaledTCoeff[iMbXy] + 256 + 64, 8);
924
925 ST32 (&pCurLayer->pNzc[iMbXy][0], 0);
926 ST32 (&pCurLayer->pNzc[iMbXy][4], 0);
927 ST32 (&pCurLayer->pNzc[iMbXy][8], 0);
928 ST32 (&pCurLayer->pNzc[iMbXy][12], 0);
929 ST32 (&pCurLayer->pNzc[iMbXy][20], 0);
930 if (pCurLayer->pCbp[iMbXy] == 0 && !IS_INTRA16x16 (pCurLayer->pMbType[iMbXy]) && !IS_I_BL (pCurLayer->pMbType[iMbXy])) {
931 pCurLayer->pLumaQp[iMbXy] = pSlice->iLastMbQp;
932 pCurLayer->pChromaQp[iMbXy] = g_kuiChromaQp[WELS_CLIP3 (pCurLayer->pLumaQp[iMbXy] +
933 pSliceHeader->pPps->iChromaQpIndexOffset, 0, 51)];
934 }
935 }
880 936
881int32_t WelsActualDecodeMbCavlcPSlice(PWelsDecoderContext pCtx)937 if (pCurLayer->pCbp[iMbXy] || MB_TYPE_INTRA16x16 == pCurLayer->pMbType[iMbXy]) {
882{938 int32_t iQpDelta, iId8x8, iId4x4;
883 SVlcTable* pVlcTable = &pCtx->sVlcTable;939
884 PDqLayer pCurLayer = pCtx->pCurDqLayer;940 iQpDelta = BsGetSe (pBs);
885 PBitStringAux pBs = pCurLayer->pBitStringAux;941
886 PSlice pSlice = &pCurLayer->sLayerInfo.sSliceInLayer;942 if (iQpDelta > 25 || iQpDelta < -26) { //out of iQpDelta range
887 PSliceHeader pSliceHeader = &pSlice->sSliceHeaderExt.sSliceHeader;943 return ERR_INFO_INVALID_QP;
888 944 }
889 SNeighAvail sNeighAvail;945
890 946 pCurLayer->pLumaQp[iMbXy] = pSlice->iLastMbQp + iQpDelta; //update iLastMbQp
891 int32_t iScanIdxStart = pSlice->sSliceHeaderExt.uiScanIdxStart;947 //refer to JVT-X201wcm1.doc equation(7-35)
892 int32_t iScanIdxEnd = pSlice->sSliceHeaderExt.uiScanIdxEnd; 948 if ((unsigned) (pCurLayer->pLumaQp[iMbXy]) > 51) {
893 949 if (pCurLayer->pLumaQp[iMbXy] < 0) {
894 int32_t iMbX = pCurLayer->iMbX;950 pCurLayer->pLumaQp[iMbXy] += 52;
895 int32_t iMbY = pCurLayer->iMbY;951 } else {
896 int32_t iMbXy = pCurLayer->iMbXyIndex;952 pCurLayer->pLumaQp[iMbXy] -= 52;
897 953 }
898 int32_t iNMbMode, i;954 }
899 uint32_t uiMbType = 0, uiCbp = 0, uiCbpL = 0, uiCbpC = 0;955 //QP should be in the range of [0, 51]
900 956 if (pCurLayer->pLumaQp[iMbXy] < 0 || pCurLayer->pLumaQp[iMbXy] > 51) {
901 FORCE_STACK_ALIGN_1D( uint8_t, pNonZeroCount, 48, 16 );957 return ERR_INFO_INVALID_QP;
902 pCurLayer->pInterPredictionDoneFlag[iMbXy] = 0;//2009.10.23958 }
903 959 pSlice->iLastMbQp = pCurLayer->pLumaQp[iMbXy];
904 uiMbType = BsGetUe(pBs); 960 pCurLayer->pChromaQp[iMbXy] = g_kuiChromaQp[WELS_CLIP3 (pSlice->iLastMbQp + pSliceHeader->pPps->iChromaQpIndexOffset, 0,
905 if (uiMbType < 5) //inter MB type961 51)];
906 {962
907 int16_t iMotionVector[LIST_A][30][MV_A]; 963 BsStartCavlc (pBs);
908 964
909 int8_t iRefIndex[LIST_A][30];965 if (MB_TYPE_INTRA16x16 == pCurLayer->pMbType[iMbXy]) {
910 pCurLayer->pMbType[iMbXy] = g_ksInterMbTypeInfo[uiMbType].iType;966 //step1: Luma DC
911 WelsFillCacheInter( &sNeighAvail, pNonZeroCount, iMotionVector, iRefIndex, pCurLayer );967 if (WelsResidualBlockCavlc (pVlcTable, pNonZeroCount, pBs, 0, 16, g_kuiLumaDcZigzagScan,
912 if ( ParseInterInfo(pCtx, iMotionVector, iRefIndex, pBs) )968 I16_LUMA_DC, pCurLayer->pScaledTCoeff[iMbXy], iNMbMode, pCurLayer->pLumaQp[iMbXy], pCtx)) {
913 {969 return -1;//abnormal
914 return -1;//abnormal970 }
915 }971 //step2: Luma AC
916 972 if (uiCbpL) {
917 if( pSlice->sSliceHeaderExt.bAdaptiveResidualPredFlag ==1 )973 for (i = 0; i < 16; i++) {
918 {974 if (WelsResidualBlockCavlc (pVlcTable, pNonZeroCount, pBs, i,
919 pCurLayer->pResidualPredFlag[iMbXy] = BsGetOneBit(pBs);975 iScanIdxEnd - WELS_MAX (iScanIdxStart, 1) + 1, g_kuiZigzagScan + WELS_MAX (iScanIdxStart, 1),
920 }976 I16_LUMA_AC, pCurLayer->pScaledTCoeff[iMbXy] + (i << 4), iNMbMode, pCurLayer->pLumaQp[iMbXy], pCtx)) {
921 else977 return -1;//abnormal
922 {978 }
923 pCurLayer->pResidualPredFlag[iMbXy] = pSlice->sSliceHeaderExt.bDefaultResidualPredFlag;979 }
924 }980 ST32 (&pCurLayer->pNzc[iMbXy][0], LD32 (&pNonZeroCount[1 + 8 * 1]));
925 981 ST32 (&pCurLayer->pNzc[iMbXy][4], LD32 (&pNonZeroCount[1 + 8 * 2]));
926 if(pCurLayer->pResidualPredFlag[iMbXy] == 0)982 ST32 (&pCurLayer->pNzc[iMbXy][8], LD32 (&pNonZeroCount[1 + 8 * 3]));
927 {983 ST32 (&pCurLayer->pNzc[iMbXy][12], LD32 (&pNonZeroCount[1 + 8 * 4]));
928 iNMbMode = BASE_MB;984 } else { //pNonZeroCount = 0
929 pCurLayer->pInterPredictionDoneFlag[iMbXy] = 0;985 ST32 (&pCurLayer->pNzc[iMbXy][0], 0);
930 }986 ST32 (&pCurLayer->pNzc[iMbXy][4], 0);
931 else 987 ST32 (&pCurLayer->pNzc[iMbXy][8], 0);
932 {988 ST32 (&pCurLayer->pNzc[iMbXy][12], 0);
933 WelsLog(pCtx, WELS_LOG_WARNING, "residual_pred_flag = 1 not supported.\n");989 }
934 return -1;990 } else { //non-MB_TYPE_INTRA16x16
935 }991 for (iId8x8 = 0; iId8x8 < 4; iId8x8++) {
936 }992 if (uiCbpL & (1 << iId8x8)) {
937 else //intra MB type993 int32_t iIndex = (iId8x8 << 2);
938 {994 for (iId4x4 = 0; iId4x4 < 4; iId4x4++) {
939 uiMbType -= 5;995 //Luma (DC and AC decoding together)
940 if ( uiMbType > 25 )996 if (WelsResidualBlockCavlc (pVlcTable, pNonZeroCount, pBs, iIndex,
941 {997 iScanIdxEnd - iScanIdxStart + 1, g_kuiZigzagScan + iScanIdxStart, LUMA_DC_AC,
942 return ERR_INFO_INVALID_MB_TYPE;998 pCurLayer->pScaledTCoeff[iMbXy] + (iIndex << 4), iNMbMode, pCurLayer->pLumaQp[iMbXy], pCtx)) {
943 }999 return -1;//abnormal
944 1000 }
945 if ( 25 == uiMbType )1001 iIndex++;
946 {1002 }
947 int32_t iDecStrideL = pCurLayer->pDec->iLinesize[0]; 1003 } else {
948 int32_t iDecStrideC = pCurLayer->pDec->iLinesize[1]; 1004 ST16 (&pNonZeroCount[g_kuiCacheNzcScanIdx[iId8x8 << 2]], 0);
949 1005 ST16 (&pNonZeroCount[g_kuiCacheNzcScanIdx[ (iId8x8 << 2) + 2]], 0);
950 int32_t iOffsetL = ( iMbX + iMbY * iDecStrideL ) << 4;
951 int32_t iOffsetC = ( iMbX + iMbY * iDecStrideC ) << 3;
952
953 uint8_t* pDecY = pCurLayer->pCsData[0] + iOffsetL;
954 uint8_t* pDecU = pCurLayer->pCsData[1] + iOffsetC;
955 uint8_t* pDecV = pCurLayer->pCsData[2] + iOffsetC;
956
957 uint8_t *pTmpBsBuf;
958
959 int32_t i;
960 int32_t iCopySizeY = ( sizeof( uint8_t ) << 4 );
961 int32_t iCopySizeUV = ( sizeof( uint8_t ) << 3 );
962
963 int32_t iIndex = ((-pBs->iLeftBits)>>3) + 2;
964
965 pCurLayer->pMbType[iMbXy] = MB_TYPE_INTRA_PCM;
966
967 //step 1: locating bit-stream pointer [must align into integer byte]
968 pBs->pCurBuf -= iIndex;
969
970 //step 2: copy pixel from bit-stream into fdec [reconstruction]
971 pTmpBsBuf = pBs->pCurBuf;
972 for ( i = 0; i < 16; i++ ) //luma
973 {
974 memcpy( pDecY , pTmpBsBuf, iCopySizeY );
975 pDecY += iDecStrideL;
976 pTmpBsBuf += 16;
977 }
978
979 for ( i = 0; i < 8; i++ ) //cb
980 {
981 memcpy( pDecU, pTmpBsBuf, iCopySizeUV );
982 pDecU += iDecStrideC;
983 pTmpBsBuf += 8;
984 }
985 for ( i = 0; i < 8; i++ ) //cr
986 {
987 memcpy( pDecV, pTmpBsBuf, iCopySizeUV );
988 pDecV += iDecStrideC;
989 pTmpBsBuf += 8;
990 }
991
992 pBs->pCurBuf += 384;
993 InitReadBits( pBs );
994
995 //step 3: update QP and pNonZeroCount
996 pCurLayer->pLumaQp[iMbXy] = 0;
997 pCurLayer->pChromaQp[iMbXy] = 0;
998 ST32(&pCurLayer->pNzc[iMbXy][0], 0);
999 ST32(&pCurLayer->pNzc[iMbXy][4], 0);
1000 ST32(&pCurLayer->pNzc[iMbXy][8], 0);
1001 ST32(&pCurLayer->pNzc[iMbXy][12], 0);
1002 return 0;
1003 }
1004 else
1005 {
1006 if (0 == uiMbType)
1007 {
1008 FORCE_STACK_ALIGN_1D( int8_t, pIntraPredMode, 48, 16 );
1009 pCurLayer->pMbType[iMbXy] = MB_TYPE_INTRA4x4;
1010 pCtx->pFillInfoCacheIntra4x4Func( &sNeighAvail, pNonZeroCount, pIntraPredMode, pCurLayer );
1011 if ( pCtx->pParseIntra4x4ModeFunc( &sNeighAvail, pIntraPredMode, pBs, pCurLayer ) )
1012 {
1013 return -1;
1014 }
1015 iNMbMode = BASE_MB;
1016 }
1017 else //I_PCM exclude, we can ignore it
1018 {
1019 pCurLayer->pMbType[iMbXy] = MB_TYPE_INTRA16x16;
1020 pCurLayer->pIntraPredMode[iMbXy][7] = (uiMbType-1) & 3;
1021 pCurLayer->pCbp[iMbXy] = g_kuiI16CbpTable[(uiMbType-1)>>2];
1022 uiCbpC = pCurLayer->pCbp[iMbXy] >> 4;
1023 uiCbpL = pCurLayer->pCbp[iMbXy] & 15;
1024 WelsFillCacheNonZeroCount( &sNeighAvail, pNonZeroCount, pCurLayer );
1025 if ( pCtx->pParseIntra16x16ModeFunc( &sNeighAvail, pBs, pCurLayer ) )
1026 {
1027 return -1;
1028 }
1029 iNMbMode = BASE_MB;
1030 }
1031 }
1032 }
1033
1034 if ( MB_TYPE_INTRA16x16 != pCurLayer->pMbType[iMbXy] )
1035 {
1036 uiCbp = BsGetUe(pBs);
1037 {
1038 if ( uiCbp > 47 )
1039 return ERR_INFO_INVALID_CBP;
1040
1041 if (MB_TYPE_INTRA4x4 == pCurLayer->pMbType[iMbXy])
1042 {
1043 uiCbp = g_kuiIntra4x4CbpTable[uiCbp];
1044 }
1045 else //inter
1046 uiCbp = g_kuiInterCbpTable[uiCbp];
1047 }
1048
1049 pCurLayer->pCbp[iMbXy] = uiCbp;
1050 uiCbpC = pCurLayer->pCbp[iMbXy] >> 4;
1051 uiCbpL = pCurLayer->pCbp[iMbXy] & 15;
1052 }
1053
1054 if(iNMbMode == BASE_MB)
1055 {
1056 pCtx->sBlockFunc.pWelsBlockZero16x16Func(pCurLayer->pScaledTCoeff[iMbXy], 16);
1057 pCtx->sBlockFunc.pWelsBlockZero8x8Func(pCurLayer->pScaledTCoeff[iMbXy]+256, 8);
1058 pCtx->sBlockFunc.pWelsBlockZero8x8Func(pCurLayer->pScaledTCoeff[iMbXy]+256+64, 8);
1059
1060 ST32(&pCurLayer->pNzc[iMbXy][0], 0);
1061 ST32(&pCurLayer->pNzc[iMbXy][4], 0);
1062 ST32(&pCurLayer->pNzc[iMbXy][8], 0);
1063 ST32(&pCurLayer->pNzc[iMbXy][12], 0);
1064 ST32(&pCurLayer->pNzc[iMbXy][20], 0);
1065 if( pCurLayer->pCbp[iMbXy] == 0 && !IS_INTRA16x16(pCurLayer->pMbType[iMbXy]) && !IS_I_BL(pCurLayer->pMbType[iMbXy]))
1066 {
1067 pCurLayer->pLumaQp[iMbXy] = pSlice->iLastMbQp;
1068 pCurLayer->pChromaQp[iMbXy] = g_kuiChromaQp[WELS_CLIP3(pCurLayer->pLumaQp[iMbXy] + pSliceHeader->pPps->iChromaQpIndexOffset, 0, 51)];
1069 }
1070 }
1071
1072 if ( pCurLayer->pCbp[iMbXy] || MB_TYPE_INTRA16x16 == pCurLayer->pMbType[iMbXy] )
1073 {
1074 int32_t iQpDelta, iId8x8, iId4x4;
1075
1076 iQpDelta = BsGetSe(pBs);
1077
1078 if (iQpDelta > 25 || iQpDelta < -26) //out of iQpDelta range
1079 {
1080 return ERR_INFO_INVALID_QP;
1081 }
1082
1083 pCurLayer->pLumaQp[iMbXy] = pSlice->iLastMbQp + iQpDelta; //update iLastMbQp
1084 //refer to JVT-X201wcm1.doc equation(7-35)
1085 if ( (unsigned)(pCurLayer->pLumaQp[iMbXy]) > 51 )
1086 {
1087 if ( pCurLayer->pLumaQp[iMbXy] < 0 )
1088 {
1089 pCurLayer->pLumaQp[iMbXy] += 52;
1090 }
1091 else
1092 {
1093 pCurLayer->pLumaQp[iMbXy] -= 52;
1094 }
1095 }
1096 //QP should be in the range of [0, 51]
1097 if ( pCurLayer->pLumaQp[iMbXy] < 0 || pCurLayer->pLumaQp[iMbXy] > 51 )
1098 {
1099 return ERR_INFO_INVALID_QP;
1100 }
1101 pSlice->iLastMbQp = pCurLayer->pLumaQp[iMbXy];
1102 pCurLayer->pChromaQp[iMbXy] = g_kuiChromaQp[WELS_CLIP3(pSlice->iLastMbQp + pSliceHeader->pPps->iChromaQpIndexOffset, 0, 51)];
1103
1104 BsStartCavlc( pBs );
1105
1106 if ( MB_TYPE_INTRA16x16 == pCurLayer->pMbType[iMbXy] )
1107 {
1108 //step1: Luma DC
1109 if ( WelsResidualBlockCavlc( pVlcTable, pNonZeroCount, pBs, 0, 16, g_kuiLumaDcZigzagScan,
1110 I16_LUMA_DC, pCurLayer->pScaledTCoeff[iMbXy], iNMbMode, pCurLayer->pLumaQp[iMbXy], pCtx) )
1111 {
1112 return -1;//abnormal
1113 }
1114 //step2: Luma AC
1115 if (uiCbpL)
1116 {
1117 for (i = 0; i < 16; i++)
1118 {
1119 if ( WelsResidualBlockCavlc( pVlcTable, pNonZeroCount,pBs, i,
1120 iScanIdxEnd - WELS_MAX(iScanIdxStart, 1) + 1, g_kuiZigzagScan + WELS_MAX(iScanIdxStart,1),
1121 I16_LUMA_AC, pCurLayer->pScaledTCoeff[iMbXy] + (i<<4), iNMbMode, pCurLayer->pLumaQp[iMbXy], pCtx) )
1122 {
1123 return -1;//abnormal
1124 }
1125 }
1126 ST32(&pCurLayer->pNzc[iMbXy][0], LD32(&pNonZeroCount[1+8*1]));
1127 ST32(&pCurLayer->pNzc[iMbXy][4], LD32(&pNonZeroCount[1+8*2]));
1128 ST32(&pCurLayer->pNzc[iMbXy][8], LD32(&pNonZeroCount[1+8*3]));
1129 ST32(&pCurLayer->pNzc[iMbXy][12], LD32(&pNonZeroCount[1+8*4]));
1130 }
1131 else //pNonZeroCount = 0
1132 {
1133 ST32(&pCurLayer->pNzc[iMbXy][0], 0);
1134 ST32(&pCurLayer->pNzc[iMbXy][4], 0);
1135 ST32(&pCurLayer->pNzc[iMbXy][8], 0);
1136 ST32(&pCurLayer->pNzc[iMbXy][12], 0);
1137 }
1138 }
1139 else //non-MB_TYPE_INTRA16x16
1140 {
1141 for (iId8x8 = 0; iId8x8 < 4; iId8x8++)
1142 {
1143 if (uiCbpL & (1 << iId8x8))
1144 {
1145 int32_t iIndex = (iId8x8 << 2);
1146 for (iId4x4 = 0; iId4x4 < 4; iId4x4++)
1147 {
1148 //Luma (DC and AC decoding together)
1149 if ( WelsResidualBlockCavlc( pVlcTable, pNonZeroCount, pBs, iIndex,
1150 iScanIdxEnd - iScanIdxStart + 1, g_kuiZigzagScan+iScanIdxStart, LUMA_DC_AC,
1151 pCurLayer->pScaledTCoeff[iMbXy] + (iIndex<<4), iNMbMode, pCurLayer->pLumaQp[iMbXy], pCtx) )
1152 {
1153 return -1;//abnormal
1154 }
1155 iIndex++;
1156 }
1157 }
1158 else
1159 {
1160 ST16(&pNonZeroCount[g_kuiCacheNzcScanIdx[iId8x8<<2]],0);
1161 ST16(&pNonZeroCount[g_kuiCacheNzcScanIdx[(iId8x8<<2)+2]],0);
1162 }
1163 }
1164 ST32(&pCurLayer->pNzc[iMbXy][0], LD32(&pNonZeroCount[1+8*1]));
1165 ST32(&pCurLayer->pNzc[iMbXy][4], LD32(&pNonZeroCount[1+8*2]));
1166 ST32(&pCurLayer->pNzc[iMbXy][8], LD32(&pNonZeroCount[1+8*3]));
1167 ST32(&pCurLayer->pNzc[iMbXy][12], LD32(&pNonZeroCount[1+8*4]));
1168 }1006 }
1007 }
1008 ST32 (&pCurLayer->pNzc[iMbXy][0], LD32 (&pNonZeroCount[1 + 8 * 1]));
1009 ST32 (&pCurLayer->pNzc[iMbXy][4], LD32 (&pNonZeroCount[1 + 8 * 2]));
1010 ST32 (&pCurLayer->pNzc[iMbXy][8], LD32 (&pNonZeroCount[1 + 8 * 3]));
1011 ST32 (&pCurLayer->pNzc[iMbXy][12], LD32 (&pNonZeroCount[1 + 8 * 4]));
1012 }
1169 1013
1170 1014
1171 //chroma 1015 //chroma
1172 //step1: DC1016 //step1: DC
1173 if ( 1 == uiCbpC || 2 == uiCbpC )1017 if (1 == uiCbpC || 2 == uiCbpC) {
1174 { 1018 for (i = 0; i < 2; i++) { //Cb Cr
1175 for (i = 0; i < 2; i++) //Cb Cr1019 if (WelsResidualBlockCavlc (pVlcTable, pNonZeroCount, pBs,
1176 { 1020 16 + (i << 2), 4, g_kuiChromaDcScan, CHROMA_DC, pCurLayer->pScaledTCoeff[iMbXy] + 256 + (i << 6),
1177 if ( WelsResidualBlockCavlc( pVlcTable, pNonZeroCount, pBs,1021 iNMbMode, pCurLayer->pChromaQp[iMbXy], pCtx)) {
1178 16 + (i << 2), 4, g_kuiChromaDcScan, CHROMA_DC, pCurLayer->pScaledTCoeff[iMbXy] + 256 + (i<<6),1022 return -1;//abnormal
1179 iNMbMode, pCurLayer->pChromaQp[iMbXy], pCtx) ) 1023 }
1180 {1024 }
1181 return -1;//abnormal1025 } else {
1182 }1026 }
1183 }1027 //step2: AC
1184 }1028 if (2 == uiCbpC) {
1185 else1029 for (i = 0; i < 2; i++) { //Cb Cr
1186 {1030 int32_t iIndex = 16 + (i << 2);
1187 }1031 for (iId4x4 = 0; iId4x4 < 4; iId4x4++) {
1188 //step2: AC1032 if (WelsResidualBlockCavlc (pVlcTable, pNonZeroCount, pBs, iIndex,
1189 if (2 == uiCbpC)1033 iScanIdxEnd - WELS_MAX (iScanIdxStart, 1) + 1, g_kuiZigzagScan + WELS_MAX (iScanIdxStart, 1),
1190 {1034 CHROMA_AC, pCurLayer->pScaledTCoeff[iMbXy] + (iIndex << 4), iNMbMode, pCurLayer->pChromaQp[iMbXy], pCtx)) {
1191 for (i = 0; i < 2; i++) //Cb Cr1035 return -1;//abnormal
1192 {1036 }
1193 int32_t iIndex= 16 + (i<<2);1037 iIndex++;
1194 for (iId4x4 = 0; iId4x4 < 4; iId4x4++) 1038 }
1195 {1039 }
1196 if ( WelsResidualBlockCavlc( pVlcTable, pNonZeroCount, pBs, iIndex,1040 ST16 (&pCurLayer->pNzc[iMbXy][16], LD16 (&pNonZeroCount[6 + 8 * 1]));
1197 iScanIdxEnd - WELS_MAX(iScanIdxStart, 1) + 1, g_kuiZigzagScan + WELS_MAX(iScanIdxStart,1),1041 ST16 (&pCurLayer->pNzc[iMbXy][20], LD16 (&pNonZeroCount[6 + 8 * 2]));
1198 CHROMA_AC, pCurLayer->pScaledTCoeff[iMbXy]+(iIndex<<4), iNMbMode, pCurLayer->pChromaQp[iMbXy], pCtx) )1042 ST16 (&pCurLayer->pNzc[iMbXy][18], LD16 (&pNonZeroCount[6 + 8 * 4]));
1199 {1043 ST16 (&pCurLayer->pNzc[iMbXy][22], LD16 (&pNonZeroCount[6 + 8 * 5]));
1200 return -1;//abnormal1044 } else {
1201 }1045 ST32 (&pCurLayer->pNzc[iMbXy][16], 0);
1202 iIndex++;1046 ST32 (&pCurLayer->pNzc[iMbXy][20], 0);
1203 }1047 }
1204 }1048 BsEndCavlc (pBs);
1205 ST16(&pCurLayer->pNzc[iMbXy][16], LD16(&pNonZeroCount[6+8*1]));1049 } else {
1206 ST16(&pCurLayer->pNzc[iMbXy][20], LD16(&pNonZeroCount[6+8*2]));1050 ST32 (&pCurLayer->pNzc[iMbXy][0], 0);
1207 ST16(&pCurLayer->pNzc[iMbXy][18], LD16(&pNonZeroCount[6+8*4]));1051 ST32 (&pCurLayer->pNzc[iMbXy][4], 0);
1208 ST16(&pCurLayer->pNzc[iMbXy][22], LD16(&pNonZeroCount[6+8*5]));1052 ST32 (&pCurLayer->pNzc[iMbXy][8], 0);
1209 }1053 ST32 (&pCurLayer->pNzc[iMbXy][12], 0);
1210 else 1054 ST32 (&pCurLayer->pNzc[iMbXy][16], 0);
1211 {1055 ST32 (&pCurLayer->pNzc[iMbXy][20], 0);
1212 ST32(&pCurLayer->pNzc[iMbXy][16], 0);1056 }
1213 ST32(&pCurLayer->pNzc[iMbXy][20], 0); 1057
1214 }1058 return 0;
1215 BsEndCavlc( pBs );
1216 }
1217 else
1218 {
1219 ST32(&pCurLayer->pNzc[iMbXy][0], 0);
1220 ST32(&pCurLayer->pNzc[iMbXy][4], 0);
1221 ST32(&pCurLayer->pNzc[iMbXy][8], 0);
1222 ST32(&pCurLayer->pNzc[iMbXy][12], 0);
1223 ST32(&pCurLayer->pNzc[iMbXy][16], 0);
1224 ST32(&pCurLayer->pNzc[iMbXy][20], 0);
1225 }
1226
1227 return 0;
1228}1059}
1229 1060
1230int32_t WelsDecodeMbCavlcPSlice(PWelsDecoderContext pCtx, PNalUnit pNalCur)1061int32_t WelsDecodeMbCavlcPSlice (PWelsDecoderContext pCtx, PNalUnit pNalCur) {
1231{1062 PDqLayer pCurLayer = pCtx->pCurDqLayer;
1232 PDqLayer pCurLayer = pCtx->pCurDqLayer;1063 PBitStringAux pBs = pCurLayer->pBitStringAux;
1233 PBitStringAux pBs = pCurLayer->pBitStringAux;1064 PSlice pSlice = &pCurLayer->sLayerInfo.sSliceInLayer;
1234 PSlice pSlice = &pCurLayer->sLayerInfo.sSliceInLayer;1065 PSliceHeader pSliceHeader = &pSlice->sSliceHeaderExt.sSliceHeader;
1235 PSliceHeader pSliceHeader = &pSlice->sSliceHeaderExt.sSliceHeader;1066
1236 1067 int32_t iMbXy = pCurLayer->iMbXyIndex;
1237 int32_t iMbXy = pCurLayer->iMbXyIndex;1068 int32_t iBaseModeFlag, i;
1238 int32_t iBaseModeFlag, i;1069 int32_t iRet = 0; //should have the return value to indicate decoding error or not, It's NECESSARY--2010.4.15
1239 int32_t iRet = 0; //should have the return value to indicate decoding error or not, It's NECESSARY--2010.4.151070
1240 1071 if (-1 == pSlice->iMbSkipRun) {
1241 if (-1 == pSlice->iMbSkipRun) 1072 pSlice->iMbSkipRun = BsGetUe (pBs);
1242 {1073 if (-1 == pSlice->iMbSkipRun) {
1243 pSlice->iMbSkipRun = BsGetUe(pBs);1074 return -1;
1244 if ( -1 == pSlice->iMbSkipRun )
1245 {
1246 return -1;
1247 }
1248
1249 }
1250 if (pSlice->iMbSkipRun--)
1251 {
1252 int16_t iMv[2] = {0};
1253
1254 pCurLayer->pMbType[iMbXy] = MB_TYPE_SKIP;
1255 ST32(&pCurLayer->pNzc[iMbXy][0], 0);
1256 ST32(&pCurLayer->pNzc[iMbXy][4], 0);
1257 ST32(&pCurLayer->pNzc[iMbXy][8], 0);
1258 ST32(&pCurLayer->pNzc[iMbXy][12], 0);
1259 ST32(&pCurLayer->pNzc[iMbXy][16], 0);
1260 ST32(&pCurLayer->pNzc[iMbXy][20], 0);
1261
1262 pCurLayer->pInterPredictionDoneFlag[iMbXy] = 0;
1263 memset(pCurLayer->pRefIndex[0][iMbXy], 0, sizeof(int8_t) * 16);
1264
1265 //predict iMv
1266 PredPSkipMvFromNeighbor( pCurLayer, iMv );
1267 for (i = 0; i < 16; i++)
1268 {
1269 ST32( pCurLayer->pMv[0][iMbXy][i], *(uint32_t*)iMv );
1270 }
1271
1272 if(!pSlice->sSliceHeaderExt.bDefaultResidualPredFlag)
1273 {
1274 memset(pCurLayer->pScaledTCoeff[iMbXy], 0, 384*sizeof(int16_t));
1275 }
1276
1277 //reset rS
1278 if(!pSlice->sSliceHeaderExt.bDefaultResidualPredFlag ||
1279 (pNalCur->sNalHeaderExt.uiQualityId==0 && pNalCur->sNalHeaderExt.uiDependencyId==0))
1280 {
1281 pCurLayer->pLumaQp[iMbXy] = pSlice->iLastMbQp;
1282 pCurLayer->pChromaQp[iMbXy] = g_kuiChromaQp[WELS_CLIP3(pCurLayer->pLumaQp[iMbXy] + pSliceHeader->pPps->iChromaQpIndexOffset, 0, 51)];
1283 }
1284
1285 pCurLayer->pCbp[iMbXy] = 0;
1286
1287 return 0;
1288 }
1289
1290 if( pSlice->sSliceHeaderExt.bAdaptiveBaseModeFlag == 1)
1291 {
1292 iBaseModeFlag = BsGetOneBit(pBs);
1293 }
1294 else
1295 {
1296 iBaseModeFlag = pSlice->sSliceHeaderExt.bDefaultBaseModeFlag;
1297 }
1298 if( !iBaseModeFlag )
1299 {
1300 iRet = WelsActualDecodeMbCavlcPSlice( pCtx );
1301 }1075 }
1302 else1076
1303 {1077 }
1304 WelsLog( pCtx, WELS_LOG_WARNING, "iBaseModeFlag (%d) != 0, inter-layer prediction not supported.\n", iBaseModeFlag);1078 if (pSlice->iMbSkipRun--) {
1305 return GENERATE_ERROR_NO(ERR_LEVEL_SLICE_HEADER, ERR_INFO_UNSUPPORTED_ILP);1079 int16_t iMv[2] = {0};
1080
1081 pCurLayer->pMbType[iMbXy] = MB_TYPE_SKIP;
1082 ST32 (&pCurLayer->pNzc[iMbXy][0], 0);
1083 ST32 (&pCurLayer->pNzc[iMbXy][4], 0);
1084 ST32 (&pCurLayer->pNzc[iMbXy][8], 0);
1085 ST32 (&pCurLayer->pNzc[iMbXy][12], 0);
1086 ST32 (&pCurLayer->pNzc[iMbXy][16], 0);
1087 ST32 (&pCurLayer->pNzc[iMbXy][20], 0);
1088
1089 pCurLayer->pInterPredictionDoneFlag[iMbXy] = 0;
1090 memset (pCurLayer->pRefIndex[0][iMbXy], 0, sizeof (int8_t) * 16);
1091
1092 //predict iMv
1093 PredPSkipMvFromNeighbor (pCurLayer, iMv);
1094 for (i = 0; i < 16; i++) {
1095 ST32 (pCurLayer->pMv[0][iMbXy][i], * (uint32_t*)iMv);
1096 }
1097
1098 if (!pSlice->sSliceHeaderExt.bDefaultResidualPredFlag) {
1099 memset (pCurLayer->pScaledTCoeff[iMbXy], 0, 384 * sizeof (int16_t));
1306 }1100 }
1307 if ( iRet ) //occur error when parsing, MUST STOP decoding
1308 {
1309 return iRet;
1310 }
1311 1101
1312 return 0;1102 //reset rS
1103 if (!pSlice->sSliceHeaderExt.bDefaultResidualPredFlag ||
1104 (pNalCur->sNalHeaderExt.uiQualityId == 0 && pNalCur->sNalHeaderExt.uiDependencyId == 0)) {
1105 pCurLayer->pLumaQp[iMbXy] = pSlice->iLastMbQp;
1106 pCurLayer->pChromaQp[iMbXy] = g_kuiChromaQp[WELS_CLIP3 (pCurLayer->pLumaQp[iMbXy] +
1107 pSliceHeader->pPps->iChromaQpIndexOffset, 0, 51)];
1108 }
1109
1110 pCurLayer->pCbp[iMbXy] = 0;
1111
1112 return 0;
1113 }
1114
1115 if (pSlice->sSliceHeaderExt.bAdaptiveBaseModeFlag == 1) {
1116 iBaseModeFlag = BsGetOneBit (pBs);
1117 } else {
1118 iBaseModeFlag = pSlice->sSliceHeaderExt.bDefaultBaseModeFlag;
1119 }
1120 if (!iBaseModeFlag) {
1121 iRet = WelsActualDecodeMbCavlcPSlice (pCtx);
1122 } else {
1123 WelsLog (pCtx, WELS_LOG_WARNING, "iBaseModeFlag (%d) != 0, inter-layer prediction not supported.\n", iBaseModeFlag);
1124 return GENERATE_ERROR_NO (ERR_LEVEL_SLICE_HEADER, ERR_INFO_UNSUPPORTED_ILP);
1125 }
1126 if (iRet) { //occur error when parsing, MUST STOP decoding
1127 return iRet;
1128 }
1129
1130 return 0;
1313}1131}
1314 1132
1315void_t WelsBlockInit(int16_t* pBlock, int32_t iWidth, int32_t iHeight, int32_t iStride, uint8_t uiVal)1133void_t WelsBlockInit (int16_t* pBlock, int32_t iWidth, int32_t iHeight, int32_t iStride, uint8_t uiVal) {
1316{1134 int32_t i;
1317 int32_t i;1135 int16_t* pDst = pBlock;
1318 int16_t* pDst = pBlock;1136
1319 1137 for (i = 0; i < iHeight; i++) {
1320 for(i=0; i<iHeight; i++)1138 memset (pDst, uiVal, iWidth * sizeof (int16_t));
1321 {1139 pDst += iStride;
1322 memset(pDst, uiVal, iWidth*sizeof(int16_t));1140 }
1323 pDst += iStride;
1324 }
1325}1141}
1326 1142
1327void_t WelsBlockFuncInit(SBlockFunc * pFunc, int32_t iCpu)1143void_t WelsBlockFuncInit (SBlockFunc* pFunc, int32_t iCpu) {
1328{1144 pFunc->pWelsBlockZero16x16Func = WelsBlockZero16x16_c;
1329 pFunc->pWelsBlockZero16x16Func = WelsBlockZero16x16_c;1145 pFunc->pWelsBlockZero8x8Func = WelsBlockZero8x8_c;
1330 pFunc->pWelsBlockZero8x8Func = WelsBlockZero8x8_c;1146 pFunc->pWelsSetNonZeroCountFunc = SetNonZeroCount_c;
1331 pFunc->pWelsSetNonZeroCountFunc = SetNonZeroCount_c;
1332 1147
1333#ifdef X86_ASM1148#ifdef X86_ASM
1334 if( iCpu & WELS_CPU_SSE2 ){1149 if (iCpu & WELS_CPU_SSE2) {
1335 pFunc->pWelsBlockZero16x16Func = WelsResBlockZero16x16_sse2;1150 pFunc->pWelsBlockZero16x16Func = WelsResBlockZero16x16_sse2;
1336 pFunc->pWelsBlockZero8x8Func = WelsResBlockZero8x8_sse2;1151 pFunc->pWelsBlockZero8x8Func = WelsResBlockZero8x8_sse2;
1337 }1152 }
1338#endif1153#endif
1339}1154}
1340void_t WelsBlockZero16x16_c(int16_t * pBlock, int32_t iStride)1155void_t WelsBlockZero16x16_c (int16_t* pBlock, int32_t iStride) {
1341{1156 WelsBlockInit (pBlock, 16, 16, iStride, 0);
1342 WelsBlockInit(pBlock,16,16,iStride,0);
1343}1157}
1344 1158
1345void_t WelsBlockZero8x8_c(int16_t * pBlock, int32_t iStride)1159void_t WelsBlockZero8x8_c (int16_t* pBlock, int32_t iStride) {
1346{1160 WelsBlockInit (pBlock, 8, 8, iStride, 0);
1347 WelsBlockInit(pBlock,8,8,iStride,0);
1348}1161}
1349 1162
1350void_t SetNonZeroCount_c(int16_t* pBlock, int8_t* pNonZeroCount)1163void_t SetNonZeroCount_c (int16_t* pBlock, int8_t* pNonZeroCount) {
1351{1164 int32_t i;
1352 int32_t i;1165 int32_t iIndex;
1353 int32_t iIndex;
1354 1166
1355 for( i=0;i<24;i++ ){1167 for (i = 0; i < 24; i++) {
1356 iIndex = g_kuiMbNonZeroCountIdx[i];1168 iIndex = g_kuiMbNonZeroCountIdx[i];
1357 pNonZeroCount[iIndex] = !!pNonZeroCount[iIndex];1169 pNonZeroCount[iIndex] = !!pNonZeroCount[iIndex];
1358 }1170 }
1359}1171}
1360 1172
1361} // namespace WelsDec1173} // 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