1 /******************************************************************************
2 *
3 * Copyright (C) 2015 The Android Open Source Project
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at:
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 *
17 *****************************************************************************
18 * Originally developed and contributed by Ittiam Systems Pvt. Ltd, Bangalore
19 */
20 #include <stdio.h>
21 #include <string.h>
22
23 #include "iv_datatypedef.h"
24 #include "iv.h"
25
26 #include "impeg2_buf_mgr.h"
27 #include "impeg2_disp_mgr.h"
28 #include "impeg2_defs.h"
29 #include "impeg2_platform_macros.h"
30 #include "impeg2_inter_pred.h"
31 #include "impeg2_idct.h"
32 #include "impeg2_globals.h"
33 #include "impeg2_mem_func.h"
34 #include "impeg2_format_conv.h"
35 #include "impeg2_macros.h"
36
37 #include "ivd.h"
38 #include "impeg2d.h"
39 #include "impeg2d_bitstream.h"
40 #include "impeg2d_structs.h"
41 #include "impeg2d_vld_tables.h"
42 #include "impeg2d_vld.h"
43 #include "impeg2d_pic_proc.h"
44 #include "impeg2d_debug.h"
45 #include "impeg2d_mc.h"
46
47 #define BLK_SIZE 8
48 #define LUMA_BLK_SIZE (2 * (BLK_SIZE))
49 #define CHROMA_BLK_SIZE (BLK_SIZE)
50
51
52 /*******************************************************************************
53 *
54 * Function Name : impeg2d_dec_p_mb_params
55 *
56 * Description : Decodes the parameters for P
57 *
58 * Arguments :
59 * dec : Decoder context
60 *
61 * Values Returned : None
62 *******************************************************************************/
impeg2d_dec_p_mb_params(dec_state_t * ps_dec)63 WORD32 impeg2d_dec_p_mb_params(dec_state_t *ps_dec)
64 {
65 stream_t *ps_stream = &ps_dec->s_bit_stream;
66 UWORD16 u2_mb_addr_incr;
67 UWORD16 u2_total_len;
68 UWORD16 u2_len;
69 UWORD16 u2_mb_type;
70 UWORD32 u4_next_word;
71 const dec_mb_params_t *ps_dec_mb_params;
72 if(impeg2d_bit_stream_nxt(ps_stream,1) == 1)
73 {
74 impeg2d_bit_stream_flush(ps_stream,1);
75
76 }
77 else
78 {
79 u2_mb_addr_incr = impeg2d_get_mb_addr_incr(ps_stream);
80
81 if(!u2_mb_addr_incr)
82 {
83 return IV_FAIL;
84 }
85
86 if(0 == ps_dec->u2_first_mb)
87 {
88 /****************************************************************/
89 /* If the 2nd member of a field picture pair is a P picture and */
90 /* the first one was an I picture, there cannot be any skipped */
91 /* MBs in the second field picture */
92 /****************************************************************/
93 /*
94 if((dec->picture_structure != FRAME_PICTURE) &&
95 (dec->f->FieldFuncCall != 0) &&
96 (dec->las->u1_last_coded_vop_type == I))
97 {
98 core0_err_handler((void *)(VOLParams),
99 ITTMPEG2_ERR_INVALID_MB_SKIP);
100 }
101 */
102 /****************************************************************/
103 /* In MPEG-2, the last MB of the row cannot be skipped and the */
104 /* MBAddrIncr cannot be such that it will take the current MB */
105 /* beyond the current row */
106 /* In MPEG-1, the slice could start and end anywhere and is not */
107 /* restricted to a row like in MPEG-2. Hence this check should */
108 /* not be done for MPEG-1 streams. */
109 /****************************************************************/
110 if(ps_dec->u2_is_mpeg2 && ((ps_dec->u2_mb_x + u2_mb_addr_incr) > ps_dec->u2_num_horiz_mb) )
111 {
112 u2_mb_addr_incr = ps_dec->u2_num_horiz_mb - ps_dec->u2_mb_x;
113 }
114
115 if ((u2_mb_addr_incr - 1) > ps_dec->u2_num_mbs_left)
116 {
117 /* If the number of skip MBs are more than the number of MBs
118 * left, indicate error.
119 */
120 return IV_FAIL;
121 }
122
123 impeg2d_dec_skip_mbs(ps_dec, (UWORD16)(u2_mb_addr_incr - 1));
124 }
125
126 }
127 u4_next_word = (UWORD16)impeg2d_bit_stream_nxt(ps_stream,16);
128 /*-----------------------------------------------------------------------*/
129 /* MB type */
130 /*-----------------------------------------------------------------------*/
131 {
132 u2_mb_type = ps_dec->pu2_mb_type[BITS((UWORD16)u4_next_word,15,10)];
133 u2_len = BITS(u2_mb_type,15,8);
134 u2_total_len = u2_len;
135 u4_next_word = (UWORD16)LSW((UWORD16)u4_next_word << u2_len);
136 }
137 /*-----------------------------------------------------------------------*/
138 /* motion type */
139 /*-----------------------------------------------------------------------*/
140 {
141 if((u2_mb_type & MB_FORW_OR_BACK) && ps_dec->u2_read_motion_type)
142 {
143 WORD32 i4_motion_type;
144 ps_dec->u2_motion_type = BITS((UWORD16)u4_next_word,15,14);
145 u2_total_len += MB_MOTION_TYPE_LEN;
146 u4_next_word = (UWORD16)LSW((UWORD16)u4_next_word << MB_MOTION_TYPE_LEN);
147 i4_motion_type = ps_dec->u2_motion_type;
148
149 if((i4_motion_type == 0) ||
150 (i4_motion_type == 4) ||
151 (i4_motion_type > 7))
152 {
153 //TODO : VANG Check for validity
154 i4_motion_type = 1;
155 }
156
157 }
158 }
159 /*-----------------------------------------------------------------------*/
160 /* dct type */
161 /*-----------------------------------------------------------------------*/
162 {
163 if((u2_mb_type & MB_CODED) && ps_dec->u2_read_dct_type)
164 {
165 ps_dec->u2_field_dct = BIT((UWORD16)u4_next_word,15);
166 u2_total_len += MB_DCT_TYPE_LEN;
167 u4_next_word = (UWORD16)LSW((UWORD16)u4_next_word << MB_DCT_TYPE_LEN);
168 }
169 }
170 /*-----------------------------------------------------------------------*/
171 /* Quant scale code */
172 /*-----------------------------------------------------------------------*/
173 if(u2_mb_type & MB_QUANT)
174 {
175 UWORD16 u2_quant_scale_code;
176 u2_quant_scale_code = BITS((UWORD16)u4_next_word,15,11);
177
178 ps_dec->u1_quant_scale = (ps_dec->u2_q_scale_type) ?
179 gau1_impeg2_non_linear_quant_scale[u2_quant_scale_code] : (u2_quant_scale_code << 1);
180 u2_total_len += MB_QUANT_SCALE_CODE_LEN;
181 }
182 impeg2d_bit_stream_flush(ps_stream,u2_total_len);
183 /*-----------------------------------------------------------------------*/
184 /* Set the function pointers */
185 /*-----------------------------------------------------------------------*/
186 ps_dec->u2_coded_mb = (UWORD16)(u2_mb_type & MB_CODED);
187
188 if(u2_mb_type & MB_FORW_OR_BACK)
189 {
190
191 UWORD16 refPic = !(u2_mb_type & MB_MV_FORW);
192 UWORD16 index = (ps_dec->u2_motion_type);
193 ps_dec->u2_prev_intra_mb = 0;
194 ps_dec->e_mb_pred = (e_pred_direction_t)refPic;
195 ps_dec_mb_params = &ps_dec->ps_func_forw_or_back[index];
196 ps_dec->s_mb_type = ps_dec_mb_params->s_mb_type;
197 if(NULL == ps_dec_mb_params->pf_func_mb_params)
198 return -1;
199 ps_dec_mb_params->pf_func_mb_params(ps_dec);
200
201 }
202 else if(u2_mb_type & MB_TYPE_INTRA)
203 {
204 ps_dec->u2_prev_intra_mb = 1;
205 impeg2d_dec_intra_mb(ps_dec);
206
207 }
208 else
209 {
210 ps_dec->u2_prev_intra_mb = 0;
211 ps_dec->e_mb_pred = FORW;
212 ps_dec->u2_motion_type = 0;
213 impeg2d_dec_0mv_coded_mb(ps_dec);
214 }
215
216 /*-----------------------------------------------------------------------*/
217 /* decode cbp */
218 /*-----------------------------------------------------------------------*/
219 if((u2_mb_type & MB_TYPE_INTRA))
220 {
221 ps_dec->u2_cbp = 0x3f;
222 ps_dec->u2_prev_intra_mb = 1;
223 }
224 else
225 {
226 ps_dec->u2_prev_intra_mb = 0;
227 ps_dec->u2_def_dc_pred[Y_LUMA] = 128 << ps_dec->u2_intra_dc_precision;
228 ps_dec->u2_def_dc_pred[U_CHROMA] = 128 << ps_dec->u2_intra_dc_precision;
229 ps_dec->u2_def_dc_pred[V_CHROMA] = 128 << ps_dec->u2_intra_dc_precision;
230 if((ps_dec->u2_coded_mb))
231 {
232 UWORD16 cbpValue;
233 cbpValue = gau2_impeg2d_cbp_code[impeg2d_bit_stream_nxt(ps_stream,MB_CBP_LEN)];
234 ps_dec->u2_cbp = cbpValue & 0xFF;
235 impeg2d_bit_stream_flush(ps_stream,(cbpValue >> 8) & 0x0FF);
236 }
237 else
238 {
239 ps_dec->u2_cbp = 0;
240 }
241 }
242 return 0;
243 }
244
245
246 /*******************************************************************************
247 *
248 * Function Name : impeg2d_dec_pnb_mb_params
249 *
250 * Description : Decodes the parameters for P and B pictures
251 *
252 * Arguments :
253 * dec : Decoder context
254 *
255 * Values Returned : None
256 *******************************************************************************/
impeg2d_dec_pnb_mb_params(dec_state_t * ps_dec)257 WORD32 impeg2d_dec_pnb_mb_params(dec_state_t *ps_dec)
258 {
259 stream_t *ps_stream = &ps_dec->s_bit_stream;
260 UWORD16 u2_mb_addr_incr;
261 UWORD16 u2_total_len;
262 UWORD16 u2_len;
263 UWORD16 u2_mb_type;
264 UWORD32 u4_next_word;
265 const dec_mb_params_t *ps_dec_mb_params;
266 if(impeg2d_bit_stream_nxt(ps_stream,1) == 1)
267 {
268 impeg2d_bit_stream_flush(ps_stream,1);
269
270 }
271 else
272 {
273 u2_mb_addr_incr = impeg2d_get_mb_addr_incr(ps_stream);
274
275 if(ps_dec->u2_first_mb)
276 {
277 /****************************************************************/
278 /* Section 6.3.17 */
279 /* The first MB of a slice cannot be skipped */
280 /* But the mb_addr_incr can be > 1, because at the beginning of */
281 /* a slice, it indicates the offset from the last MB in the */
282 /* previous row. Hence for the first slice in a row, the */
283 /* mb_addr_incr needs to be 1. */
284 /****************************************************************/
285 /* MB_x is set to zero whenever MB_y changes. */
286 ps_dec->u2_mb_x = u2_mb_addr_incr - 1;
287 /* For error resilience */
288 ps_dec->u2_mb_x = MIN(ps_dec->u2_mb_x, (ps_dec->u2_num_horiz_mb - 1));
289
290 /****************************************************************/
291 /* mb_addr_incr is forced to 1 because in this decoder it is used */
292 /* more as an indicator of the number of MBs skipped than the */
293 /* as defined by the standard (Section 6.3.17) */
294 /****************************************************************/
295 u2_mb_addr_incr = 1;
296 ps_dec->u2_first_mb = 0;
297 }
298 else
299 {
300 /****************************************************************/
301 /* In MPEG-2, the last MB of the row cannot be skipped and the */
302 /* mb_addr_incr cannot be such that it will take the current MB */
303 /* beyond the current row */
304 /* In MPEG-1, the slice could start and end anywhere and is not */
305 /* restricted to a row like in MPEG-2. Hence this check should */
306 /* not be done for MPEG-1 streams. */
307 /****************************************************************/
308 if(ps_dec->u2_is_mpeg2 &&
309 ((ps_dec->u2_mb_x + u2_mb_addr_incr) > ps_dec->u2_num_horiz_mb))
310 {
311 u2_mb_addr_incr = ps_dec->u2_num_horiz_mb - ps_dec->u2_mb_x;
312 }
313
314 if ((u2_mb_addr_incr - 1) > ps_dec->u2_num_mbs_left)
315 {
316 /* If the number of skip MBs are more than the number of MBs
317 * left, indicate error.
318 */
319 return IV_FAIL;
320 }
321
322 impeg2d_dec_skip_mbs(ps_dec, (UWORD16)(u2_mb_addr_incr - 1));
323 }
324
325 }
326 u4_next_word = (UWORD16)impeg2d_bit_stream_nxt(ps_stream,16);
327 /*-----------------------------------------------------------------------*/
328 /* MB type */
329 /*-----------------------------------------------------------------------*/
330 {
331 u2_mb_type = ps_dec->pu2_mb_type[BITS((UWORD16)u4_next_word,15,10)];
332 u2_len = BITS(u2_mb_type,15,8);
333 u2_total_len = u2_len;
334 u4_next_word = (UWORD16)LSW((UWORD16)u4_next_word << u2_len);
335 }
336 /*-----------------------------------------------------------------------*/
337 /* motion type */
338 /*-----------------------------------------------------------------------*/
339 {
340 WORD32 i4_motion_type = ps_dec->u2_motion_type;
341
342 if((u2_mb_type & MB_FORW_OR_BACK) && ps_dec->u2_read_motion_type)
343 {
344 ps_dec->u2_motion_type = BITS((UWORD16)u4_next_word,15,14);
345 u2_total_len += MB_MOTION_TYPE_LEN;
346 u4_next_word = (UWORD16)LSW((UWORD16)u4_next_word << MB_MOTION_TYPE_LEN);
347 i4_motion_type = ps_dec->u2_motion_type;
348
349 }
350
351
352 if ((u2_mb_type & MB_FORW_OR_BACK) &&
353 ((i4_motion_type == 0) ||
354 (i4_motion_type == 3) ||
355 (i4_motion_type == 4) ||
356 (i4_motion_type >= 7)))
357 {
358 //TODO: VANG Check for validity
359 i4_motion_type = 1;
360 }
361
362 }
363 /*-----------------------------------------------------------------------*/
364 /* dct type */
365 /*-----------------------------------------------------------------------*/
366 {
367 if((u2_mb_type & MB_CODED) && ps_dec->u2_read_dct_type)
368 {
369 ps_dec->u2_field_dct = BIT((UWORD16)u4_next_word,15);
370 u2_total_len += MB_DCT_TYPE_LEN;
371 u4_next_word = (UWORD16)LSW((UWORD16)u4_next_word << MB_DCT_TYPE_LEN);
372 }
373 }
374 /*-----------------------------------------------------------------------*/
375 /* Quant scale code */
376 /*-----------------------------------------------------------------------*/
377 if(u2_mb_type & MB_QUANT)
378 {
379 UWORD16 u2_quant_scale_code;
380 u2_quant_scale_code = BITS((UWORD16)u4_next_word,15,11);
381
382 ps_dec->u1_quant_scale = (ps_dec->u2_q_scale_type) ?
383 gau1_impeg2_non_linear_quant_scale[u2_quant_scale_code] : (u2_quant_scale_code << 1);
384 u2_total_len += MB_QUANT_SCALE_CODE_LEN;
385 }
386 impeg2d_bit_stream_flush(ps_stream,u2_total_len);
387 /*-----------------------------------------------------------------------*/
388 /* Set the function pointers */
389 /*-----------------------------------------------------------------------*/
390 ps_dec->u2_coded_mb = (UWORD16)(u2_mb_type & MB_CODED);
391
392 if(u2_mb_type & MB_BIDRECT)
393 {
394 UWORD16 u2_index = (ps_dec->u2_motion_type);
395
396 ps_dec->u2_prev_intra_mb = 0;
397 ps_dec->e_mb_pred = BIDIRECT;
398 ps_dec_mb_params = &ps_dec->ps_func_bi_direct[u2_index];
399 ps_dec->s_mb_type = ps_dec_mb_params->s_mb_type;
400 if(NULL == ps_dec_mb_params->pf_func_mb_params)
401 return -1;
402 ps_dec_mb_params->pf_func_mb_params(ps_dec);
403 }
404 else if(u2_mb_type & MB_FORW_OR_BACK)
405 {
406
407 UWORD16 u2_refPic = !(u2_mb_type & MB_MV_FORW);
408 UWORD16 u2_index = (ps_dec->u2_motion_type);
409 ps_dec->u2_prev_intra_mb = 0;
410 ps_dec->e_mb_pred = (e_pred_direction_t)u2_refPic;
411 ps_dec_mb_params = &ps_dec->ps_func_forw_or_back[u2_index];
412 ps_dec->s_mb_type = ps_dec_mb_params->s_mb_type;
413 if(NULL == ps_dec_mb_params->pf_func_mb_params)
414 return -1;
415 ps_dec_mb_params->pf_func_mb_params(ps_dec);
416
417 }
418 else if(u2_mb_type & MB_TYPE_INTRA)
419 {
420 ps_dec->u2_prev_intra_mb = 1;
421 impeg2d_dec_intra_mb(ps_dec);
422
423 }
424 else
425 {
426 ps_dec->u2_prev_intra_mb =0;
427 ps_dec->e_mb_pred = FORW;
428 ps_dec->u2_motion_type = 0;
429 impeg2d_dec_0mv_coded_mb(ps_dec);
430 }
431
432 /*-----------------------------------------------------------------------*/
433 /* decode cbp */
434 /*-----------------------------------------------------------------------*/
435 if((u2_mb_type & MB_TYPE_INTRA))
436 {
437 ps_dec->u2_cbp = 0x3f;
438 ps_dec->u2_prev_intra_mb = 1;
439 }
440 else
441 {
442 ps_dec->u2_prev_intra_mb = 0;
443 ps_dec->u2_def_dc_pred[Y_LUMA] = 128 << ps_dec->u2_intra_dc_precision;
444 ps_dec->u2_def_dc_pred[U_CHROMA] = 128 << ps_dec->u2_intra_dc_precision;
445 ps_dec->u2_def_dc_pred[V_CHROMA] = 128 << ps_dec->u2_intra_dc_precision;
446 if((ps_dec->u2_coded_mb))
447 {
448 UWORD16 cbpValue;
449 cbpValue = gau2_impeg2d_cbp_code[impeg2d_bit_stream_nxt(ps_stream,MB_CBP_LEN)];
450 ps_dec->u2_cbp = cbpValue & 0xFF;
451 impeg2d_bit_stream_flush(ps_stream,(cbpValue >> 8) & 0x0FF);
452 }
453 else
454 {
455 ps_dec->u2_cbp = 0;
456 }
457 }
458 return 0;
459 }
460
461 /*******************************************************************************
462 * Function Name : impeg2d_dec_p_b_slice
463 *
464 * Description : Decodes P and B slices
465 *
466 * Arguments :
467 * dec : Decoder state
468 *
469 * Values Returned : None
470 *******************************************************************************/
impeg2d_dec_p_b_slice(dec_state_t * ps_dec)471 IMPEG2D_ERROR_CODES_T impeg2d_dec_p_b_slice(dec_state_t *ps_dec)
472 {
473 WORD16 *pi2_vld_out;
474 UWORD32 i;
475 yuv_buf_t *ps_cur_frm_buf = &ps_dec->s_cur_frm_buf;
476
477 UWORD32 u4_frm_offset = 0;
478 const dec_mb_params_t *ps_dec_mb_params;
479 IMPEG2D_ERROR_CODES_T e_error = (IMPEG2D_ERROR_CODES_T)IVD_ERROR_NONE;
480
481 pi2_vld_out = ps_dec->ai2_vld_buf;
482 memset(ps_dec->ai2_pred_mv,0,sizeof(ps_dec->ai2_pred_mv));
483
484 ps_dec->u2_prev_intra_mb = 0;
485 ps_dec->u2_first_mb = 1;
486
487 ps_dec->u2_picture_width = ps_dec->u2_frame_width;
488
489 if(ps_dec->u2_picture_structure != FRAME_PICTURE)
490 {
491 ps_dec->u2_picture_width <<= 1;
492 if(ps_dec->u2_picture_structure == BOTTOM_FIELD)
493 {
494 u4_frm_offset = ps_dec->u2_frame_width;
495 }
496 }
497
498 do
499 {
500 UWORD32 u4_x_offset, u4_y_offset;
501 WORD32 ret;
502
503
504 UWORD32 u4_x_dst_offset = 0;
505 UWORD32 u4_y_dst_offset = 0;
506 UWORD8 *pu1_out_p;
507 UWORD8 *pu1_pred;
508 WORD32 u4_pred_strd;
509
510 IMPEG2D_TRACE_MB_START(ps_dec->u2_mb_x, ps_dec->u2_mb_y);
511
512 if(ps_dec->e_pic_type == B_PIC)
513 ret = impeg2d_dec_pnb_mb_params(ps_dec);
514 else
515 ret = impeg2d_dec_p_mb_params(ps_dec);
516
517 if(ret)
518 return IMPEG2D_MB_TEX_DECODE_ERR;
519
520 if(0 >= ps_dec->u2_num_mbs_left)
521 {
522 break;
523 }
524
525 IMPEG2D_TRACE_MB_START(ps_dec->u2_mb_x, ps_dec->u2_mb_y);
526
527 u4_x_dst_offset = u4_frm_offset + (ps_dec->u2_mb_x << 4);
528 u4_y_dst_offset = (ps_dec->u2_mb_y << 4) * ps_dec->u2_picture_width;
529 pu1_out_p = ps_cur_frm_buf->pu1_y + u4_x_dst_offset + u4_y_dst_offset;
530 if(ps_dec->u2_prev_intra_mb == 0)
531 {
532 UWORD32 offset_x, offset_y, stride;
533 UWORD16 index = (ps_dec->u2_motion_type);
534 /*only for non intra mb's*/
535 if(ps_dec->e_mb_pred == BIDIRECT)
536 {
537 ps_dec_mb_params = &ps_dec->ps_func_bi_direct[index];
538 }
539 else
540 {
541 ps_dec_mb_params = &ps_dec->ps_func_forw_or_back[index];
542 }
543
544 stride = ps_dec->u2_picture_width;
545
546 offset_x = u4_frm_offset + (ps_dec->u2_mb_x << 4);
547
548 offset_y = (ps_dec->u2_mb_y << 4);
549
550 ps_dec->s_dest_buf.pu1_y = ps_cur_frm_buf->pu1_y + offset_y * stride + offset_x;
551
552 stride = stride >> 1;
553
554 ps_dec->s_dest_buf.pu1_u = ps_cur_frm_buf->pu1_u + (offset_y >> 1) * stride
555 + (offset_x >> 1);
556
557 ps_dec->s_dest_buf.pu1_v = ps_cur_frm_buf->pu1_v + (offset_y >> 1) * stride
558 + (offset_x >> 1);
559
560 PROFILE_DISABLE_MC_IF0
561 ps_dec_mb_params->pf_mc(ps_dec);
562
563 }
564 for(i = 0; i < NUM_LUMA_BLKS; ++i)
565 {
566 if((ps_dec->u2_cbp & (1 << (BLOCKS_IN_MB - 1 - i))) != 0)
567 {
568 e_error = ps_dec->pf_vld_inv_quant(ps_dec, pi2_vld_out, ps_dec->pu1_inv_scan_matrix,
569 ps_dec->u2_prev_intra_mb, Y_LUMA, 0);
570 if ((IMPEG2D_ERROR_CODES_T)IVD_ERROR_NONE != e_error)
571 {
572 return e_error;
573 }
574
575 u4_x_offset = gai2_impeg2_blk_x_off[i];
576
577 if(ps_dec->u2_field_dct == 0)
578 u4_y_offset = gai2_impeg2_blk_y_off_frm[i] ;
579 else
580 u4_y_offset = gai2_impeg2_blk_y_off_fld[i] ;
581
582
583
584
585
586 IMPEG2D_IDCT_INP_STATISTICS(pi2_vld_out, ps_dec->u4_non_zero_cols, ps_dec->u4_non_zero_rows);
587
588 PROFILE_DISABLE_IDCT_IF0
589 {
590 WORD32 idx;
591 if(1 == (ps_dec->u4_non_zero_cols | ps_dec->u4_non_zero_rows))
592 idx = 0;
593 else
594 idx = 1;
595
596 if(0 == ps_dec->u2_prev_intra_mb)
597 {
598 pu1_pred = pu1_out_p + u4_y_offset * ps_dec->u2_picture_width + u4_x_offset;
599 u4_pred_strd = ps_dec->u2_picture_width << ps_dec->u2_field_dct;
600 }
601 else
602 {
603 pu1_pred = (UWORD8 *)gau1_impeg2_zerobuf;
604 u4_pred_strd = 8;
605 }
606
607 ps_dec->pf_idct_recon[idx * 2 + ps_dec->i4_last_value_one](pi2_vld_out,
608 ps_dec->ai2_idct_stg1,
609 pu1_pred,
610 pu1_out_p + u4_y_offset * ps_dec->u2_picture_width + u4_x_offset,
611 8,
612 u4_pred_strd,
613 ps_dec->u2_picture_width << ps_dec->u2_field_dct,
614 ~ps_dec->u4_non_zero_cols, ~ps_dec->u4_non_zero_rows);
615 }
616 }
617
618 }
619
620 /* For U and V blocks, divide the x and y offsets by 2. */
621 u4_x_dst_offset >>= 1;
622 u4_y_dst_offset >>= 2;
623
624
625 /* In case of chrominance blocks the DCT will be frame DCT */
626 /* i = 0, U component and i = 1 is V componet */
627 if((ps_dec->u2_cbp & 0x02) != 0)
628 {
629 pu1_out_p = ps_cur_frm_buf->pu1_u + u4_x_dst_offset + u4_y_dst_offset;
630 e_error = ps_dec->pf_vld_inv_quant(ps_dec, pi2_vld_out, ps_dec->pu1_inv_scan_matrix,
631 ps_dec->u2_prev_intra_mb, U_CHROMA, 0);
632 if ((IMPEG2D_ERROR_CODES_T)IVD_ERROR_NONE != e_error)
633 {
634 return e_error;
635 }
636
637
638 IMPEG2D_IDCT_INP_STATISTICS(pi2_vld_out, ps_dec->u4_non_zero_cols, ps_dec->u4_non_zero_rows);
639
640 PROFILE_DISABLE_IDCT_IF0
641 {
642 WORD32 idx;
643 if(1 == (ps_dec->u4_non_zero_cols | ps_dec->u4_non_zero_rows))
644 idx = 0;
645 else
646 idx = 1;
647
648 if(0 == ps_dec->u2_prev_intra_mb)
649 {
650 pu1_pred = pu1_out_p;
651 u4_pred_strd = ps_dec->u2_picture_width >> 1;
652 }
653 else
654 {
655 pu1_pred = (UWORD8 *)gau1_impeg2_zerobuf;
656 u4_pred_strd = 8;
657 }
658
659 ps_dec->pf_idct_recon[idx * 2 + ps_dec->i4_last_value_one](pi2_vld_out,
660 ps_dec->ai2_idct_stg1,
661 pu1_pred,
662 pu1_out_p,
663 8,
664 u4_pred_strd,
665 ps_dec->u2_picture_width >> 1,
666 ~ps_dec->u4_non_zero_cols, ~ps_dec->u4_non_zero_rows);
667
668 }
669
670 }
671
672
673 if((ps_dec->u2_cbp & 0x01) != 0)
674 {
675 pu1_out_p = ps_cur_frm_buf->pu1_v + u4_x_dst_offset + u4_y_dst_offset;
676 e_error = ps_dec->pf_vld_inv_quant(ps_dec, pi2_vld_out, ps_dec->pu1_inv_scan_matrix,
677 ps_dec->u2_prev_intra_mb, V_CHROMA, 0);
678 if ((IMPEG2D_ERROR_CODES_T)IVD_ERROR_NONE != e_error)
679 {
680 return e_error;
681 }
682
683
684 IMPEG2D_IDCT_INP_STATISTICS(pi2_vld_out, ps_dec->u4_non_zero_cols, ps_dec->u4_non_zero_rows);
685
686 PROFILE_DISABLE_IDCT_IF0
687 {
688 WORD32 idx;
689 if(1 == (ps_dec->u4_non_zero_cols | ps_dec->u4_non_zero_rows))
690 idx = 0;
691 else
692 idx = 1;
693 if(0 == ps_dec->u2_prev_intra_mb)
694 {
695 pu1_pred = pu1_out_p;
696 u4_pred_strd = ps_dec->u2_picture_width >> 1;
697 }
698 else
699 {
700 pu1_pred = (UWORD8 *)gau1_impeg2_zerobuf;
701 u4_pred_strd = 8;
702 }
703
704 ps_dec->pf_idct_recon[idx * 2 + ps_dec->i4_last_value_one](pi2_vld_out,
705 ps_dec->ai2_idct_stg1,
706 pu1_pred,
707 pu1_out_p,
708 8,
709 u4_pred_strd,
710 ps_dec->u2_picture_width >> 1,
711 ~ps_dec->u4_non_zero_cols, ~ps_dec->u4_non_zero_rows);
712
713 }
714 }
715
716 ps_dec->u2_num_mbs_left--;
717 ps_dec->u2_first_mb = 0;
718 ps_dec->u2_mb_x++;
719
720 if(ps_dec->s_bit_stream.u4_offset > ps_dec->s_bit_stream.u4_max_offset)
721 {
722 return IMPEG2D_BITSTREAM_BUFF_EXCEEDED_ERR;
723 }
724 else if (ps_dec->u2_mb_x == ps_dec->u2_num_horiz_mb)
725 {
726 ps_dec->u2_mb_x = 0;
727 ps_dec->u2_mb_y++;
728
729 }
730 }
731 while(ps_dec->u2_num_mbs_left != 0 && impeg2d_bit_stream_nxt(&ps_dec->s_bit_stream,23) != 0x0);
732 return e_error;
733 }
734