1 /* |
|
2 * Copyright (c) 2010 Ixonos Plc. |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of the "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - Initial contribution |
|
11 * |
|
12 * Contributors: |
|
13 * Ixonos Plc |
|
14 * |
|
15 * Description: |
|
16 * Macroblock decoding functions. |
|
17 * |
|
18 */ |
|
19 |
|
20 |
|
21 /* |
|
22 * Includes |
|
23 */ |
|
24 #include "h263dConfig.h" |
|
25 #include "decmb.h" |
|
26 #include "viddemux.h" |
|
27 #include "decmbdct.h" |
|
28 #include "errcodes.h" |
|
29 /* MVE */ |
|
30 #include "MPEG4Transcoder.h" |
|
31 |
|
32 /* |
|
33 * Global functions |
|
34 */ |
|
35 |
|
36 /* {{-output"dmbGetAndDecodeIFrameMB.txt"}} */ |
|
37 /* |
|
38 * dmbGetAndDecodeIFrameMB |
|
39 * |
|
40 * |
|
41 * Parameters: |
|
42 * inParam input parameters |
|
43 * inOutParam input/output parameters, these parameters |
|
44 * may be modified in the function |
|
45 * fMPEG4 flag indicating if H.263 ("0") or MPEG-4 ("1") |
|
46 * specific block decoding should be used |
|
47 * |
|
48 * Function: |
|
49 * This function gets the coding parameters of a macroblock belonging |
|
50 * to an INTRA frame (from the bitstream) and decodes the macroblock. |
|
51 * |
|
52 * Returns: |
|
53 * >= 0 the function was successful |
|
54 * < 0 an error occured when accessing bit buffer |
|
55 * |
|
56 */ |
|
57 |
|
58 int dmbGetAndDecodeIFrameMB( |
|
59 const dmbIFrameMBInParam_t *inParam, |
|
60 dmbIFrameMBInOutParam_t *inOutParam, |
|
61 u_char fMPEG4, CMPEG4Transcoder *hTranscoder) |
|
62 /* {{-output"dmbGetAndDecodeIFrameMB.txt"}} */ |
|
63 { |
|
64 int |
|
65 bitErrorIndication = 0, |
|
66 /* Carries bit error indication information returned |
|
67 by the video demultiplexer module */ |
|
68 ret = 0; /* Used to check return values of function calls */ |
|
69 |
|
70 vdxGetIMBLayerInputParam_t |
|
71 vdxIn; /* Input parameters for vdxGetIMBLayer */ |
|
72 |
|
73 vdxIMBLayer_t |
|
74 mbLayer; /* Macroblock layer data */ |
|
75 |
|
76 int |
|
77 rightOfBorder, /* There is a border on the left of the current MB */ |
|
78 downOfBorder; /* There is a border on top of the current MB */ |
|
79 |
|
80 int StartByteIndex = inOutParam->StartByteIndex; |
|
81 int StartBitIndex = inOutParam->StartBitIndex; |
|
82 |
|
83 inOutParam->fCodedMBs[inParam->yPosInMBs * |
|
84 inParam->pictParam->numMBsInMBLine + inParam->xPosInMBs] = 1; |
|
85 inOutParam->numOfCodedMBs++; |
|
86 |
|
87 /* Get MB layer parameters */ |
|
88 |
|
89 vdxIn.fMQ = inParam->pictParam->fMQ; |
|
90 vdxIn.quant = inOutParam->quant; |
|
91 vdxIn.fAIC = inParam->pictParam->fAIC; |
|
92 vdxIn.fMPEG4 = fMPEG4; |
|
93 |
|
94 ret = vdxGetIMBLayer(inParam->inBuffer, inParam->outBuffer, inParam->bufEdit, inParam->iColorEffect,&StartByteIndex, &StartBitIndex, |
|
95 inParam->iGetDecodedFrame, &vdxIn, &mbLayer, |
|
96 &bitErrorIndication, hTranscoder); |
|
97 |
|
98 if ( ret <0 ) |
|
99 goto error; |
|
100 else if ( ret == VDX_OK_BUT_BIT_ERROR ) |
|
101 goto bitError; |
|
102 |
|
103 /* Store output parameters */ |
|
104 inOutParam->quant = mbLayer.quant; |
|
105 |
|
106 /* Get block layer parameters and decode them */ |
|
107 |
|
108 |
|
109 if(fMPEG4) { |
|
110 dmdMPEGIParam_t dmdIn; |
|
111 |
|
112 |
|
113 dmdIn.inBuffer = inParam->inBuffer; |
|
114 dmdIn.outBuffer = inParam->outBuffer; |
|
115 dmdIn.bufEdit = inParam->bufEdit; |
|
116 dmdIn.iColorEffect = inParam->iColorEffect; |
|
117 dmdIn.iGetDecodedFrame = inParam->iGetDecodedFrame; |
|
118 |
|
119 dmdIn.cbpy = mbLayer.cbpy; |
|
120 dmdIn.cbpc = mbLayer.cbpc; |
|
121 dmdIn.quant = mbLayer.quant; |
|
122 dmdIn.yWidth = inParam->pictParam->lumMemWidth; |
|
123 dmdIn.yMBInFrame = inOutParam->yMBInFrame; |
|
124 dmdIn.uBlockInFrame = inOutParam->uBlockInFrame; |
|
125 dmdIn.vBlockInFrame = inOutParam->vBlockInFrame; |
|
126 |
|
127 dmdIn.xPosInMBs = inParam->xPosInMBs; |
|
128 dmdIn.yPosInMBs = inParam->yPosInMBs; |
|
129 dmdIn.numMBsInMBLine = inParam->pictParam->numMBsInMBLine; |
|
130 dmdIn.numMBLinesInGOB = inParam->pictParam->numMBLinesInGOB; |
|
131 dmdIn.pictureType = inParam->pictParam->pictureType; |
|
132 |
|
133 inOutParam->aicData->ACpred_flag = mbLayer.ac_pred_flag; |
|
134 dmdIn.aicData = inOutParam->aicData; |
|
135 |
|
136 dmdIn.switched = |
|
137 aicIntraDCSwitch(inParam->pictParam->intra_dc_vlc_thr,mbLayer.quant); |
|
138 |
|
139 dmdIn.data_partitioned = 0; |
|
140 dmdIn.reversible_vlc = 0; |
|
141 |
|
142 dmdIn.currMBNum = inOutParam->currMBNum; |
|
143 |
|
144 dmdIn.fTopOfVP = (u_char) (inOutParam->currMBNumInVP < inParam->pictParam->numMBsInMBLine); |
|
145 dmdIn.fLeftOfVP = (u_char) (inOutParam->currMBNumInVP == 0); |
|
146 dmdIn.fBBlockOut = (u_char) (inOutParam->currMBNumInVP <= inParam->pictParam->numMBsInMBLine); |
|
147 |
|
148 ret = dmdGetAndDecodeMPEGIMBBlocks(&dmdIn, hTranscoder); |
|
149 |
|
150 if ( ret < 0 ) |
|
151 goto error; |
|
152 else if ( ret == DMD_BIT_ERR ) |
|
153 goto bitError; |
|
154 |
|
155 } else |
|
156 |
|
157 { |
|
158 dmdIParam_t dmdIn; |
|
159 |
|
160 /* Store the coding type of the MB*/ |
|
161 if ( inParam->pictParam->fAIC ) { |
|
162 mvcSetBorders( |
|
163 NULL, |
|
164 inParam->xPosInMBs, |
|
165 inParam->yPosInMBs, |
|
166 (inParam->pictParam->fSS)?inParam->sliceStartMB:-1, /* If Annex K is not in use, set to -1 */ |
|
167 inParam->pictParam->numMBsInMBLine, |
|
168 &rightOfBorder, |
|
169 &downOfBorder); |
|
170 } |
|
171 |
|
172 |
|
173 dmdIn.inBuffer = inParam->inBuffer; |
|
174 |
|
175 |
|
176 dmdIn.outBuffer = inParam->outBuffer; |
|
177 dmdIn.bufEdit = inParam->bufEdit; |
|
178 dmdIn.iColorEffect = inParam->iColorEffect; |
|
179 dmdIn.iGetDecodedFrame = inParam->iGetDecodedFrame; |
|
180 dmdIn.StartByteIndex = inOutParam->StartByteIndex; |
|
181 dmdIn.StartBitIndex = inOutParam->StartBitIndex; |
|
182 |
|
183 |
|
184 dmdIn.cbpy = mbLayer.cbpy; |
|
185 dmdIn.cbpc = mbLayer.cbpc; |
|
186 dmdIn.quant = mbLayer.quant; |
|
187 dmdIn.yWidth = inParam->pictParam->lumMemWidth; |
|
188 dmdIn.yMBInFrame = inOutParam->yMBInFrame; |
|
189 dmdIn.uBlockInFrame = inOutParam->uBlockInFrame; |
|
190 dmdIn.vBlockInFrame = inOutParam->vBlockInFrame; |
|
191 |
|
192 dmdIn.xPosInMBs = inParam->xPosInMBs; |
|
193 dmdIn.yPosInMBs = inParam->yPosInMBs; |
|
194 dmdIn.numMBsInMBLine = inParam->pictParam->numMBsInMBLine; |
|
195 dmdIn.numMBLinesInGOB = inParam->pictParam->numMBLinesInGOB; |
|
196 dmdIn.pictureType = inParam->pictParam->pictureType; |
|
197 |
|
198 dmdIn.predMode = mbLayer.predMode; |
|
199 dmdIn.numMBsInMBLine = inParam->pictParam->numMBsInMBLine; |
|
200 dmdIn.fGOBHeaderPresent = inParam->fGOBHeaderPresent; |
|
201 dmdIn.rightOfBorder = rightOfBorder; |
|
202 dmdIn.downOfBorder = downOfBorder; |
|
203 dmdIn.sumBEI = 0; |
|
204 |
|
205 if (!inParam->pictParam->fAIC) |
|
206 ret = dmdGetAndDecodeIMBBlocks(&dmdIn, hTranscoder); |
|
207 else |
|
208 { |
|
209 // not supported |
|
210 goto error; |
|
211 } |
|
212 |
|
213 inOutParam->StartByteIndex = dmdIn.StartByteIndex; |
|
214 inOutParam->StartBitIndex = dmdIn.StartBitIndex; |
|
215 |
|
216 |
|
217 if ( ret < 0 ) |
|
218 goto error; |
|
219 else if ( ret == DMD_BIT_ERR ) |
|
220 goto bitError; |
|
221 } |
|
222 |
|
223 return DMB_OK; |
|
224 |
|
225 bitError: |
|
226 |
|
227 inOutParam->fCodedMBs[inParam->yPosInMBs * |
|
228 inParam->pictParam->numMBsInMBLine + inParam->xPosInMBs] = 0; |
|
229 inOutParam->numOfCodedMBs--; |
|
230 return DMB_BIT_ERR; |
|
231 |
|
232 error: |
|
233 return DMB_ERR; |
|
234 } |
|
235 |
|
236 |
|
237 /* {{-output"dmbGetAndDecodePFrameMB.txt"}} */ |
|
238 /* |
|
239 * dmbGetAndDecodePFrameMB |
|
240 * |
|
241 * |
|
242 * Parameters: |
|
243 * inParam input parameters |
|
244 * inOutParam input/output parameters, these parameters |
|
245 * may be modified in the function |
|
246 * fMPEG4 flag indicating if H.263 ("0") or MPEG-4 ("1") |
|
247 * specific block decoding should be used |
|
248 * |
|
249 * Function: |
|
250 * This function gets the coding parameters of a macroblock belonging |
|
251 * to an INTER frame (from the bitstream) and decodes the macroblock. |
|
252 * |
|
253 * Returns: |
|
254 * >= 0 the function was successful |
|
255 * < 0 an error occured when accessing bit buffer |
|
256 * |
|
257 */ |
|
258 |
|
259 int dmbGetAndDecodePFrameMB( |
|
260 const dmbPFrameMBInParam_t *inParam, |
|
261 dmbPFrameMBInOutParam_t *inOutParam, |
|
262 u_char fMPEG4, CMPEG4Transcoder *hTranscoder) |
|
263 /* {{-output"dmbGetAndDecodePFrameMB.txt"}} */ |
|
264 { |
|
265 int |
|
266 bitErrorIndication = 0, |
|
267 /* Carries bit error indication information returned |
|
268 by the video demultiplexer module */ |
|
269 sumBEI = 0, /* Sum (bit-wise OR) of bit error indications for the whole MB */ |
|
270 ret, /* Used to check return values of function calls */ |
|
271 mbPos, /* the position of the current macroblock, |
|
272 -1 = the leftmost MB of the image, |
|
273 0 = MB is not in the border of the image, |
|
274 1 = rightmost MB of the image */ |
|
275 cbpy, /* Coced block pattern for luminance */ |
|
276 xPosInMBs, /* Current macroblock position in x-direction |
|
277 in units of macroblocks starting from zero */ |
|
278 yPosInMBs, /* Current macroblock position in y-direction |
|
279 in units of macroblocks starting from zero */ |
|
280 numMBsInMBLine, /* The number of macroblocks in one line */ |
|
281 yHeight, /* Luminance image height in pixels */ |
|
282 uvHeight, /* Chrominance image height in pixels */ |
|
283 yWidth, /* Luminance image width in pixels */ |
|
284 uvWidth, /* Chrominance image width in pixels */ |
|
285 mbNum, /* Macroblock number within a picture starting |
|
286 from zero in the top-left corner and |
|
287 increasing in scan-order */ |
|
288 quant; /* Current quantization parameter */ |
|
289 |
|
290 /* Motion vectors for P-macroblock */ |
|
291 int mvx[4]; |
|
292 int mvy[4]; |
|
293 |
|
294 |
|
295 /* MVE */ |
|
296 int StartByteIndex = inOutParam->StartByteIndex; |
|
297 int StartBitIndex = inOutParam->StartBitIndex; |
|
298 |
|
299 int16 |
|
300 error = 0; /* Used for return value of vdcmvc module */ |
|
301 |
|
302 u_char |
|
303 fourMVs, /* Flag which tells if four motion vectors is |
|
304 present in the current macroblock */ |
|
305 mbNotCoded; /* == 1 if current macro block is not coded */ |
|
306 |
|
307 vdxGetPPBMBLayerInputParam_t |
|
308 vdxIn; /* Input parameters for vdxGetPPBMBLayer */ |
|
309 |
|
310 vdxPPBMBLayer_t |
|
311 mbLayer; /* Macroblock layer data */ |
|
312 int |
|
313 rightOfBorder, /* There is a border on the left of the current MB */ |
|
314 downOfBorder; /* There is a border on top of the current MB */ |
|
315 |
|
316 /* Add assertions here */ |
|
317 |
|
318 xPosInMBs = inParam->xPosInMBs; |
|
319 yPosInMBs = inParam->yPosInMBs; |
|
320 numMBsInMBLine = inParam->pictParam->numMBsInMBLine; |
|
321 mbNum = yPosInMBs * numMBsInMBLine + xPosInMBs; |
|
322 yHeight = inParam->pictParam->lumMemHeight; |
|
323 uvHeight = (yHeight >>1 /*/ 2*/); |
|
324 yWidth = inParam->pictParam->lumMemWidth; |
|
325 uvWidth = (yWidth >>1 /*/ 2*/); |
|
326 |
|
327 /* mbPos, needed in blcCopyPredictionMB */ |
|
328 if (inParam->pictParam->fSS) { |
|
329 if (xPosInMBs == numMBsInMBLine - 1) |
|
330 if (mbNum == inParam->sliceStartMB) |
|
331 mbPos = 2; |
|
332 else |
|
333 mbPos = 1; |
|
334 else if (mbNum == inParam->sliceStartMB) |
|
335 /* if this is the first MB of the slice but not the last MB of the MB line */ |
|
336 mbPos = -1; |
|
337 else if (xPosInMBs == 0) |
|
338 mbPos = -1; |
|
339 else |
|
340 mbPos = 0; |
|
341 } |
|
342 else { |
|
343 if (xPosInMBs == 0) |
|
344 mbPos = -1; |
|
345 else if (xPosInMBs == numMBsInMBLine - 1) |
|
346 mbPos = 1; |
|
347 else |
|
348 mbPos = 0; |
|
349 } |
|
350 |
|
351 /* Get MB layer parameters */ |
|
352 vdxIn.pictureType = inParam->pictParam->pictureType; |
|
353 vdxIn.fPLUSPTYPE = inParam->pictParam->fPLUSPTYPE; |
|
354 vdxIn.fUMV = inParam->pictParam->fUMV; |
|
355 vdxIn.fDF = inParam->pictParam->fDF; |
|
356 vdxIn.fMQ = inParam->pictParam->fMQ; |
|
357 vdxIn.fCustomSourceFormat = inParam->pictParam->fCustomSourceFormat; |
|
358 vdxIn.fAIC = inParam->pictParam->fAIC; |
|
359 vdxIn.quant = inOutParam->quant; |
|
360 vdxIn.fFirstMBOfPicture = (yPosInMBs == 0 && xPosInMBs == 0); |
|
361 |
|
362 vdxIn.fMPEG4 = fMPEG4; |
|
363 |
|
364 if (fMPEG4) { |
|
365 vdxIn.fAP = 1; |
|
366 vdxIn.f_code = inParam->pictParam->fcode_forward; |
|
367 } else |
|
368 |
|
369 { |
|
370 vdxIn.fAP = inParam->pictParam->fAP; |
|
371 } |
|
372 |
|
373 |
|
374 int mbType=3; // default |
|
375 ret = vdxGetPPBMBLayer(inParam->inBuffer, inParam->outBuffer, inParam->bufEdit, inParam->iColorEffect,&StartByteIndex, &StartBitIndex, |
|
376 inParam->iGetDecodedFrame, &mbType, &vdxIn, &mbLayer, &bitErrorIndication, |
|
377 hTranscoder); |
|
378 |
|
379 if ( ret < 0 ) |
|
380 goto error; |
|
381 else if ( ret == VDX_OK_BUT_BIT_ERROR ) { |
|
382 goto bitError; |
|
383 } |
|
384 /* PB macroblock */ |
|
385 if ((inParam->pictParam->pictureType == VDX_PIC_TYPE_PB) || |
|
386 (inParam->pictParam->pictureType == VDX_PIC_TYPE_IPB)) { |
|
387 |
|
388 // PB not supported |
|
389 goto error; |
|
390 } /* if (PB macroblock) */ |
|
391 |
|
392 sumBEI |= bitErrorIndication; |
|
393 |
|
394 inOutParam->quant = quant = mbLayer.quant; |
|
395 |
|
396 cbpy = mbLayer.cbpy; |
|
397 fourMVs = (u_char) (mbLayer.numMVs == 4); |
|
398 |
|
399 if(!fMPEG4) { |
|
400 mvcSetBorders( |
|
401 inOutParam->mvcData, |
|
402 xPosInMBs, |
|
403 yPosInMBs, |
|
404 (inParam->pictParam->fSS)?inParam->sliceStartMB:-1, /* If Annex K is not in use, set to -1 */ |
|
405 numMBsInMBLine, |
|
406 &rightOfBorder, |
|
407 &downOfBorder); |
|
408 } |
|
409 |
|
410 if (mbLayer.fCodedMB) { |
|
411 int currMVNum; |
|
412 |
|
413 /* Decode motion vectors */ |
|
414 mbNotCoded = 0; |
|
415 inOutParam->fCodedMBs[mbNum] = 1; |
|
416 inOutParam->numOfCodedMBs++; |
|
417 |
|
418 for (currMVNum = 0; currMVNum < mbLayer.numMVs; currMVNum++) { |
|
419 |
|
420 if(fMPEG4) |
|
421 mvcCalcMPEGMV( |
|
422 inOutParam->mvcData, |
|
423 mbLayer.mvdx[currMVNum], mbLayer.mvdy[currMVNum], |
|
424 &mvx[currMVNum], &mvy[currMVNum], |
|
425 (u_char) currMVNum, fourMVs, |
|
426 (u_char) (inOutParam->currMBNumInVP < inParam->pictParam->numMBsInMBLine), |
|
427 (u_char) (inOutParam->currMBNumInVP == 0), |
|
428 (u_char) (inOutParam->currMBNumInVP < (inParam->pictParam->numMBsInMBLine-1)), |
|
429 xPosInMBs, |
|
430 yPosInMBs, |
|
431 inParam->pictParam->tr, |
|
432 (mbLayer.mbClass == VDX_MB_INTRA) ? MVC_MB_INTRA : MVC_MB_INTER, |
|
433 &error); |
|
434 else { |
|
435 mvcCalcMV( |
|
436 inOutParam->mvcData, |
|
437 mbLayer.mvdx[currMVNum], mbLayer.mvdy[currMVNum], |
|
438 &mvx[currMVNum], &mvy[currMVNum], |
|
439 (u_char) currMVNum, |
|
440 (u_char) (mbLayer.numMVs == 4), |
|
441 (u_char) inParam->pictParam->fUMV, |
|
442 (u_char) ((inParam->pictParam->fSS)?1:inParam->fGOBHeaderPresent), |
|
443 xPosInMBs, |
|
444 yPosInMBs, |
|
445 inParam->pictParam->tr, |
|
446 (mbLayer.mbClass == VDX_MB_INTRA) ? |
|
447 MVC_MB_INTRA : MVC_MB_INTER, |
|
448 &error, |
|
449 inParam->pictParam->fPLUSPTYPE, |
|
450 inParam->pictParam->fUMVLimited); |
|
451 } |
|
452 |
|
453 /* If motion vector points illegally outside the picture, |
|
454 there may be two reasons for it: |
|
455 1) bit error has occured and corrupted MVD, or |
|
456 2) encoder (e.g. /UBC) does not follow the standard. |
|
457 Since we assume that encoders may violate this feature relatively |
|
458 frequently, the decoder considers these cases as bit errors |
|
459 only if the demultiplexer indicates a similar condition. |
|
460 Note that there may be a very improbable situation where |
|
461 the demultiplexer error indication has failed (it reports |
|
462 no errors even though there are errors), and these bit errors |
|
463 would cause an illegal motion vector. Now, we won't detect |
|
464 these cases. */ |
|
465 if (error == ERR_MVC_MVPTR && bitErrorIndication) |
|
466 goto bitError; |
|
467 else if (error && error != ERR_MVC_MVPTR) |
|
468 goto error; |
|
469 } |
|
470 |
|
471 if (mbLayer.numMVs == 1) { |
|
472 mvx[1] = mvx[2] = mvx[3] = mvx[0]; |
|
473 mvy[1] = mvy[2] = mvy[3] = mvy[0]; |
|
474 } |
|
475 } |
|
476 |
|
477 else { |
|
478 mbNotCoded = 1; |
|
479 /* Motion vectors to 0 */ |
|
480 mvx[0] = mvx[1] = mvx[2] = mvx[3] = |
|
481 mvy[0] = mvy[1] = mvy[2] = mvy[3] = 0; |
|
482 mvcMarkMBNotCoded( |
|
483 inOutParam->mvcData, |
|
484 xPosInMBs, |
|
485 yPosInMBs, |
|
486 inParam->pictParam->tr); |
|
487 inOutParam->fCodedMBs[mbNum] = 0; |
|
488 cbpy = 0; |
|
489 fourMVs = (u_char) (fMPEG4 ? fourMVs : inParam->pictParam->fAP); |
|
490 } |
|
491 |
|
492 |
|
493 |
|
494 /* If INTER MB */ |
|
495 if (mbNotCoded || mbLayer.mbClass == VDX_MB_INTER) { |
|
496 dmdPParam_t dmdIn; |
|
497 blcCopyPredictionMBParam_t blcCopyParam; |
|
498 |
|
499 dmdIn.inBuffer = inParam->inBuffer; |
|
500 |
|
501 |
|
502 dmdIn.outBuffer = inParam->outBuffer; |
|
503 dmdIn.bufEdit = inParam->bufEdit; |
|
504 dmdIn.iColorEffect = inParam->iColorEffect; |
|
505 dmdIn.iGetDecodedFrame = inParam->iGetDecodedFrame; |
|
506 dmdIn.StartByteIndex = inOutParam->StartByteIndex; |
|
507 dmdIn.StartBitIndex = inOutParam->StartBitIndex; |
|
508 dmdIn.mbType = mbType; |
|
509 |
|
510 dmdIn.cbpy = cbpy; |
|
511 dmdIn.cbpc = mbLayer.cbpc; |
|
512 dmdIn.quant = quant; |
|
513 dmdIn.refY = inParam->refY; |
|
514 dmdIn.refU = inParam->refU; |
|
515 dmdIn.refV = inParam->refV; |
|
516 dmdIn.currYMBInFrame = inOutParam->yMBInFrame; |
|
517 dmdIn.currUBlkInFrame = inOutParam->uBlockInFrame; |
|
518 dmdIn.currVBlkInFrame = inOutParam->vBlockInFrame; |
|
519 dmdIn.uvBlkXCoord = xPosInMBs * 8; |
|
520 dmdIn.uvBlkYCoord = yPosInMBs * 8; |
|
521 dmdIn.uvWidth = uvWidth; |
|
522 dmdIn.uvHeight = uvHeight; |
|
523 dmdIn.mvcData = inOutParam->mvcData; |
|
524 dmdIn.mvx = mvx; |
|
525 dmdIn.mvy = mvy; |
|
526 dmdIn.mbPlace = mbPos; |
|
527 dmdIn.fAdvancedPrediction = inParam->pictParam->fAP; |
|
528 dmdIn.fMVsOverPictureBoundaries = |
|
529 inParam->pictParam->fMVsOverPictureBoundaries; |
|
530 dmdIn.diffMB = inOutParam->diffMB; |
|
531 dmdIn.rcontrol = inParam->pictParam->rtype; |
|
532 |
|
533 dmdIn.fourMVs = fourMVs; |
|
534 dmdIn.reversible_vlc = 0; |
|
535 |
|
536 dmdIn.xPosInMBs = xPosInMBs; |
|
537 dmdIn.yPosInMBs = yPosInMBs; |
|
538 dmdIn.numMBsInMBLine = inParam->pictParam->numMBsInMBLine; |
|
539 |
|
540 /* Copy blcCopyPredictionMB parameters from input parameters */ |
|
541 memcpy(&blcCopyParam, &(dmdIn.refY), sizeof(blcCopyPredictionMBParam_t)); |
|
542 /* Note: In order to operate properly, this memcpy requires that |
|
543 the structure members are in the same order and allocate the same |
|
544 amount of space. This is not guaranteed in C! */ |
|
545 |
|
546 if (inParam->iGetDecodedFrame || hTranscoder->NeedDecodedYUVFrame()) |
|
547 { |
|
548 /* Do motion compensation */ |
|
549 if (blcCopyPredictionMB(&blcCopyParam) < 0) { |
|
550 /* MV was illegal => caused by bitError */ |
|
551 goto bitError; |
|
552 } |
|
553 } |
|
554 |
|
555 |
|
556 if (fMPEG4) { |
|
557 /* Update the AIC module data, marking the MB as Inter (quant=0) */ |
|
558 aicBlockUpdate (inOutParam->aicData, inOutParam->currMBNum, 0, NULL, 0, 0); |
|
559 } |
|
560 |
|
561 |
|
562 /* Store new CBPY */ |
|
563 inOutParam->diffMB->cbpy = cbpy; |
|
564 |
|
565 /* If some prediction error blocks are coded */ |
|
566 if (mbLayer.fCodedMB) { |
|
567 /* Decode prediction error blocks */ |
|
568 |
|
569 if (fMPEG4) { |
|
570 ret = dmdGetAndDecodeMPEGPMBBlocks(&dmdIn, hTranscoder); |
|
571 } else |
|
572 |
|
573 { |
|
574 ret = dmdGetAndDecodePMBBlocks(&dmdIn, hTranscoder); |
|
575 } |
|
576 |
|
577 |
|
578 inOutParam->StartByteIndex = dmdIn.StartByteIndex; |
|
579 inOutParam->StartBitIndex = dmdIn.StartBitIndex; |
|
580 |
|
581 |
|
582 if ( ret < 0) |
|
583 goto error; |
|
584 else if ( ret == DMD_BIT_ERR ) { |
|
585 goto bitError; |
|
586 } |
|
587 } |
|
588 |
|
589 else // for the case when the MB is not coded |
|
590 { |
|
591 /* nothing here */ |
|
592 } |
|
593 |
|
594 |
|
595 } /* if (INTER block ) */ |
|
596 |
|
597 /* Else block layer decoding of INTRA macroblock */ |
|
598 else { |
|
599 |
|
600 if (inParam->pictParam->pictureType != VDX_PIC_TYPE_PB) |
|
601 mvcMarkMBIntra(inOutParam->mvcData, xPosInMBs, yPosInMBs, |
|
602 inParam->pictParam->tr); |
|
603 |
|
604 inOutParam->diffMB->cbpy = 0; |
|
605 |
|
606 /* Get block layer parameters and decode them */ |
|
607 |
|
608 if(fMPEG4) { |
|
609 dmdMPEGIParam_t dmdIn; |
|
610 |
|
611 dmdIn.inBuffer = inParam->inBuffer; |
|
612 |
|
613 /* MVE */ |
|
614 dmdIn.outBuffer = inParam->outBuffer; |
|
615 dmdIn.bufEdit = inParam->bufEdit; |
|
616 dmdIn.iColorEffect = inParam->iColorEffect; |
|
617 dmdIn.iGetDecodedFrame = inParam->iGetDecodedFrame; |
|
618 |
|
619 dmdIn.cbpy = cbpy; |
|
620 dmdIn.cbpc = mbLayer.cbpc; |
|
621 dmdIn.quant = quant; |
|
622 dmdIn.yWidth = yWidth; |
|
623 dmdIn.yMBInFrame = inOutParam->yMBInFrame; |
|
624 dmdIn.uBlockInFrame = inOutParam->uBlockInFrame; |
|
625 dmdIn.vBlockInFrame = inOutParam->vBlockInFrame; |
|
626 |
|
627 dmdIn.xPosInMBs = inParam->xPosInMBs; |
|
628 dmdIn.yPosInMBs = inParam->yPosInMBs; |
|
629 dmdIn.numMBsInMBLine = inParam->pictParam->numMBsInMBLine; |
|
630 dmdIn.numMBLinesInGOB = inParam->pictParam->numMBLinesInGOB; |
|
631 dmdIn.pictureType = inParam->pictParam->pictureType; |
|
632 |
|
633 |
|
634 inOutParam->aicData->ACpred_flag = mbLayer.ac_pred_flag; |
|
635 dmdIn.aicData = inOutParam->aicData; |
|
636 |
|
637 dmdIn.switched = |
|
638 aicIntraDCSwitch(inParam->pictParam->intra_dc_vlc_thr,mbLayer.quant); |
|
639 |
|
640 dmdIn.data_partitioned = 0; |
|
641 dmdIn.reversible_vlc = 0; |
|
642 |
|
643 dmdIn.currMBNum = inOutParam->currMBNum; |
|
644 |
|
645 dmdIn.fTopOfVP = (u_char) |
|
646 (inOutParam->currMBNumInVP < inParam->pictParam->numMBsInMBLine || |
|
647 !aicIsBlockValid(inOutParam->aicData, inOutParam->currMBNum-inParam->pictParam->numMBsInMBLine)); |
|
648 dmdIn.fLeftOfVP = (u_char) |
|
649 (inOutParam->currMBNumInVP == 0 || |
|
650 inParam->xPosInMBs == 0 || |
|
651 !aicIsBlockValid(inOutParam->aicData, inOutParam->currMBNum-1)); |
|
652 dmdIn.fBBlockOut = (u_char) |
|
653 (inOutParam->currMBNumInVP <= inParam->pictParam->numMBsInMBLine || |
|
654 inParam->xPosInMBs == 0 || |
|
655 !aicIsBlockValid(inOutParam->aicData, inOutParam->currMBNum-inParam->pictParam->numMBsInMBLine-1)); |
|
656 |
|
657 ret = dmdGetAndDecodeMPEGIMBBlocks(&dmdIn, hTranscoder); |
|
658 |
|
659 if ( ret < 0 ) |
|
660 goto error; |
|
661 else if ( ret == DMD_BIT_ERR ) |
|
662 goto bitError; |
|
663 |
|
664 } else |
|
665 |
|
666 { |
|
667 dmdIParam_t dmdIn; |
|
668 |
|
669 dmdIn.inBuffer = inParam->inBuffer; |
|
670 |
|
671 dmdIn.outBuffer = inParam->outBuffer; |
|
672 dmdIn.bufEdit = inParam->bufEdit; |
|
673 dmdIn.iColorEffect = inParam->iColorEffect; |
|
674 dmdIn.iGetDecodedFrame = inParam->iGetDecodedFrame; |
|
675 dmdIn.StartByteIndex = inOutParam->StartByteIndex; |
|
676 dmdIn.StartBitIndex = inOutParam->StartBitIndex; |
|
677 |
|
678 dmdIn.cbpy = cbpy; |
|
679 dmdIn.cbpc = mbLayer.cbpc; |
|
680 dmdIn.quant = quant; |
|
681 dmdIn.yWidth = yWidth; |
|
682 dmdIn.yMBInFrame = inOutParam->yMBInFrame; |
|
683 dmdIn.uBlockInFrame = inOutParam->uBlockInFrame; |
|
684 dmdIn.vBlockInFrame = inOutParam->vBlockInFrame; |
|
685 |
|
686 dmdIn.xPosInMBs = inParam->xPosInMBs; |
|
687 dmdIn.yPosInMBs = inParam->yPosInMBs; |
|
688 dmdIn.numMBsInMBLine = inParam->pictParam->numMBsInMBLine; |
|
689 dmdIn.numMBLinesInGOB = inParam->pictParam->numMBLinesInGOB; |
|
690 dmdIn.pictureType = inParam->pictParam->pictureType; |
|
691 |
|
692 dmdIn.predMode = mbLayer.predMode; |
|
693 dmdIn.numMBsInMBLine = inParam->pictParam->numMBsInMBLine; |
|
694 dmdIn.fGOBHeaderPresent = (inParam->pictParam->fSS)?1:inParam->fGOBHeaderPresent; |
|
695 dmdIn.rightOfBorder = rightOfBorder; |
|
696 dmdIn.downOfBorder = downOfBorder; |
|
697 |
|
698 if (!inParam->pictParam->fAIC) |
|
699 ret = dmdGetAndDecodeIMBBlocks(&dmdIn, hTranscoder); |
|
700 else |
|
701 { |
|
702 // not supported |
|
703 goto error; |
|
704 } |
|
705 |
|
706 inOutParam->StartByteIndex = dmdIn.StartByteIndex; |
|
707 inOutParam->StartBitIndex = dmdIn.StartBitIndex; |
|
708 |
|
709 if ( ret < 0 ) |
|
710 goto error; |
|
711 else if ( ret == DMD_BIT_ERR ) |
|
712 goto bitError; |
|
713 } |
|
714 } |
|
715 |
|
716 |
|
717 |
|
718 return DMB_OK; |
|
719 |
|
720 bitError: |
|
721 if ( inOutParam->fCodedMBs[mbNum] ) { |
|
722 inOutParam->fCodedMBs[mbNum] = 0; |
|
723 inOutParam->numOfCodedMBs--; |
|
724 } |
|
725 return DMB_BIT_ERR; |
|
726 |
|
727 error: |
|
728 return DMB_ERR; |
|
729 } |
|
730 |
|
731 // End of File |
|