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
21 /*!
22 **************************************************************************
23 * \file ih264d_parse_islice.c
24 *
25 * \brief
26 * Contains routines that decode a I slice type
27 *
28 * Detailed_description
29 *
30 * \date
31 * 07/07/2003
32 *
33 * \author NS
34 **************************************************************************
35 */
36 #include "ih264d_error_handler.h"
37 #include "ih264d_debug.h"
38 #include <string.h>
39 #include "ih264d_bitstrm.h"
40 #include "ih264d_defs.h"
41 #include "ih264d_debug.h"
42 #include "ih264d_tables.h"
43 #include "ih264d_structs.h"
44 #include "ih264d_defs.h"
45 #include "ih264d_parse_cavlc.h"
46 #include "ih264d_mb_utils.h"
47 #include "ih264d_deblocking.h"
48 #include "ih264d_cabac.h"
49 #include "ih264d_parse_cabac.h"
50 #include "ih264d_parse_mb_header.h"
51 #include "ih264d_parse_slice.h"
52 #include "ih264d_process_pslice.h"
53 #include "ih264d_process_intra_mb.h"
54 #include "ih264d_parse_islice.h"
55 #include "ih264d_error_handler.h"
56 #include "ih264d_mvpred.h"
57 #include "ih264d_defs.h"
58 #include "ih264d_thread_parse_decode.h"
59 #include "ithread.h"
60 #include "ih264d_parse_mb_header.h"
61 #include "assert.h"
62 #include "ih264d_utils.h"
63 #include "ih264d_format_conv.h"
64
65 void ih264d_init_cabac_contexts(UWORD8 u1_slice_type, dec_struct_t * ps_dec);
66
67 void ih264d_itrans_recon_luma_dc(dec_struct_t *ps_dec,
68 WORD16* pi2_src,
69 WORD16* pi2_coeff_block,
70 const UWORD16 *pu2_weigh_mat);
71
72
73
74 /*!
75 **************************************************************************
76 * \if Function name : ParseIMb \endif
77 *
78 * \brief
79 * This function parses CAVLC syntax of a I MB. If 16x16 Luma DC transform
80 * is also done here. Transformed Luma DC values are copied in their
81 * 0th pixel location of corrosponding CoeffBlock.
82 *
83 * \return
84 * 0 on Success and Error code otherwise
85 **************************************************************************
86 */
ih264d_parse_imb_cavlc(dec_struct_t * ps_dec,dec_mb_info_t * ps_cur_mb_info,UWORD8 u1_mb_num,UWORD8 u1_mb_type)87 WORD32 ih264d_parse_imb_cavlc(dec_struct_t * ps_dec,
88 dec_mb_info_t * ps_cur_mb_info,
89 UWORD8 u1_mb_num,
90 UWORD8 u1_mb_type)
91 {
92 WORD32 i4_delta_qp;
93 UWORD32 u4_temp;
94 UWORD32 ui_is_top_mb_available;
95 UWORD32 ui_is_left_mb_available;
96 UWORD32 u4_cbp;
97 UWORD32 u4_offset;
98 UWORD32 *pu4_bitstrm_buf;
99 WORD32 ret;
100
101 dec_bit_stream_t * const ps_bitstrm = ps_dec->ps_bitstrm;
102 UWORD32 *pu4_bitstrm_ofst = &ps_bitstrm->u4_ofst;
103 UNUSED(u1_mb_num);
104 ps_cur_mb_info->u1_tran_form8x8 = 0;
105 ps_cur_mb_info->ps_curmb->u1_tran_form8x8 = 0;
106
107 ps_cur_mb_info->u1_yuv_dc_block_flag = 0;
108
109 u4_temp = ps_dec->u1_mb_ngbr_availablity;
110 ui_is_top_mb_available = BOOLEAN(u4_temp & TOP_MB_AVAILABLE_MASK);
111 ui_is_left_mb_available = BOOLEAN(u4_temp & LEFT_MB_AVAILABLE_MASK);
112
113 pu4_bitstrm_buf = ps_bitstrm->pu4_buffer;
114
115 if(u1_mb_type == I_4x4_MB)
116 {
117 ps_cur_mb_info->ps_curmb->u1_mb_type = I_4x4_MB;
118 u4_offset = 0;
119
120 /*--------------------------------------------------------------------*/
121 /* Read transform_size_8x8_flag if present */
122 /*--------------------------------------------------------------------*/
123 if(ps_dec->s_high_profile.u1_transform8x8_present)
124 {
125 ps_cur_mb_info->u1_tran_form8x8 = ih264d_get_bit_h264(ps_bitstrm);
126 COPYTHECONTEXT("transform_size_8x8_flag", ps_cur_mb_info->u1_tran_form8x8);
127 ps_cur_mb_info->ps_curmb->u1_tran_form8x8 = ps_cur_mb_info->u1_tran_form8x8;
128 }
129
130 /*--------------------------------------------------------------------*/
131 /* Read the IntraPrediction modes for LUMA */
132 /*--------------------------------------------------------------------*/
133 if (!ps_cur_mb_info->u1_tran_form8x8)
134 {
135 UWORD8 *pu1_temp;
136 ih264d_read_intra_pred_modes(ps_dec,
137 ((UWORD8 *)ps_dec->pv_parse_tu_coeff_data),
138 ((UWORD8 *)ps_dec->pv_parse_tu_coeff_data+16),
139 ps_cur_mb_info->u1_tran_form8x8);
140 pu1_temp = (UWORD8 *)ps_dec->pv_parse_tu_coeff_data;
141 pu1_temp += 32;
142 ps_dec->pv_parse_tu_coeff_data = (void *)pu1_temp;
143 }
144 else
145 {
146 UWORD8 *pu1_temp;
147 ih264d_read_intra_pred_modes(ps_dec,
148 ((UWORD8 *)ps_dec->pv_parse_tu_coeff_data),
149 ((UWORD8 *)ps_dec->pv_parse_tu_coeff_data+4),
150 ps_cur_mb_info->u1_tran_form8x8);
151 pu1_temp = (UWORD8 *)ps_dec->pv_parse_tu_coeff_data;
152 pu1_temp += 8;
153 ps_dec->pv_parse_tu_coeff_data = (void *)pu1_temp;
154 }
155 /*--------------------------------------------------------------------*/
156 /* Read the IntraPrediction mode for CHROMA */
157 /*--------------------------------------------------------------------*/
158 //Inlined ih264d_uev
159 {
160 UWORD32 u4_bitstream_offset = *pu4_bitstrm_ofst;
161 UWORD32 u4_word, u4_ldz, u4_temp;
162
163 /***************************************************************/
164 /* Find leading zeros in next 32 bits */
165 /***************************************************************/
166 NEXTBITS_32(u4_word, u4_bitstream_offset, pu4_bitstrm_buf);
167 u4_ldz = CLZ(u4_word);
168 /* Flush the ps_bitstrm */
169 u4_bitstream_offset += (u4_ldz + 1);
170 /* Read the suffix from the ps_bitstrm */
171 u4_word = 0;
172 if(u4_ldz)
173 {
174 GETBITS(u4_word, u4_bitstream_offset, pu4_bitstrm_buf,
175 u4_ldz);
176 }
177 *pu4_bitstrm_ofst = u4_bitstream_offset;
178 u4_temp = ((1 << u4_ldz) + u4_word - 1);
179 if(u4_temp > 3)
180 {
181 return ERROR_CHROMA_PRED_MODE;
182 }
183 ps_cur_mb_info->u1_chroma_pred_mode = u4_temp;
184 COPYTHECONTEXT("intra_chroma_pred_mode", ps_cur_mb_info->u1_chroma_pred_mode);
185 }
186 /*--------------------------------------------------------------------*/
187 /* Read the Coded block pattern */
188 /*--------------------------------------------------------------------*/
189 {
190 UWORD32 u4_bitstream_offset = *pu4_bitstrm_ofst;
191 UWORD32 u4_word, u4_ldz;
192
193 /***************************************************************/
194 /* Find leading zeros in next 32 bits */
195 /***************************************************************/
196 NEXTBITS_32(u4_word, u4_bitstream_offset, pu4_bitstrm_buf);
197 u4_ldz = CLZ(u4_word);
198 /* Flush the ps_bitstrm */
199 u4_bitstream_offset += (u4_ldz + 1);
200 /* Read the suffix from the ps_bitstrm */
201 u4_word = 0;
202 if(u4_ldz)
203 {
204 GETBITS(u4_word, u4_bitstream_offset, pu4_bitstrm_buf,
205 u4_ldz);
206 }
207 *pu4_bitstrm_ofst = u4_bitstream_offset;
208 u4_cbp = ((1 << u4_ldz) + u4_word - 1);
209 }
210 if(u4_cbp > 47)
211 {
212 return ERROR_CBP;
213 }
214
215 u4_cbp = gau1_ih264d_cbp_table[u4_cbp][0];
216 COPYTHECONTEXT("coded_block_pattern", u1_cbp);
217 ps_cur_mb_info->u1_cbp = u4_cbp;
218
219 /*--------------------------------------------------------------------*/
220 /* Read mb_qp_delta */
221 /*--------------------------------------------------------------------*/
222 if(ps_cur_mb_info->u1_cbp)
223 {
224 UWORD32 u4_bitstream_offset = *pu4_bitstrm_ofst;
225 UWORD32 u4_word, u4_ldz, u4_abs_val;
226
227 /***************************************************************/
228 /* Find leading zeros in next 32 bits */
229 /***************************************************************/
230 NEXTBITS_32(u4_word, u4_bitstream_offset, pu4_bitstrm_buf);
231 u4_ldz = CLZ(u4_word);
232
233 /* Flush the ps_bitstrm */
234 u4_bitstream_offset += (u4_ldz + 1);
235
236 /* Read the suffix from the ps_bitstrm */
237 u4_word = 0;
238 if(u4_ldz)
239 {
240 GETBITS(u4_word, u4_bitstream_offset, pu4_bitstrm_buf,
241 u4_ldz);
242 }
243
244 *pu4_bitstrm_ofst = u4_bitstream_offset;
245 u4_abs_val = ((1 << u4_ldz) + u4_word) >> 1;
246
247 if(u4_word & 0x1)
248 {
249 i4_delta_qp = (-(WORD32)u4_abs_val);
250 }
251 else
252 {
253 i4_delta_qp = (u4_abs_val);
254 }
255
256 if((i4_delta_qp < -26) || (i4_delta_qp > 25))
257 {
258 return ERROR_INV_RANGE_QP_T;
259 }
260
261 COPYTHECONTEXT("mb_qp_delta", i1_delta_qp);
262 if(i4_delta_qp != 0)
263 {
264 ret = ih264d_update_qp(ps_dec, (WORD8)i4_delta_qp);
265 if(ret != OK)
266 return ret;
267 }
268 }
269
270 }
271 else
272 {
273 u4_offset = 1;
274 ps_cur_mb_info->ps_curmb->u1_mb_type = I_16x16_MB;
275 /*-------------------------------------------------------------------*/
276 /* Read the IntraPrediction mode for CHROMA */
277 /*-------------------------------------------------------------------*/
278 {
279 UWORD32 u4_bitstream_offset = *pu4_bitstrm_ofst;
280 UWORD32 u4_word, u4_ldz;
281
282 /***************************************************************/
283 /* Find leading zeros in next 32 bits */
284 /***************************************************************/
285 NEXTBITS_32(u4_word, u4_bitstream_offset, pu4_bitstrm_buf);
286 u4_ldz = CLZ(u4_word);
287 /* Flush the ps_bitstrm */
288 u4_bitstream_offset += (u4_ldz + 1);
289 /* Read the suffix from the ps_bitstrm */
290 u4_word = 0;
291 if(u4_ldz)
292 {
293 GETBITS(u4_word, u4_bitstream_offset, pu4_bitstrm_buf,
294 u4_ldz);
295 }
296 *pu4_bitstrm_ofst = u4_bitstream_offset;
297 u4_temp = ((1 << u4_ldz) + u4_word - 1);
298
299 //Inlined ih264d_uev
300
301 if(u4_temp > 3)
302 {
303 return ERROR_CHROMA_PRED_MODE;
304 }
305 ps_cur_mb_info->u1_chroma_pred_mode = u4_temp;
306 COPYTHECONTEXT("intra_chroma_pred_mode", ps_cur_mb_info->u1_chroma_pred_mode);
307 }
308 /*-------------------------------------------------------------------*/
309 /* Read the Coded block pattern */
310 /*-------------------------------------------------------------------*/
311 u4_cbp = gau1_ih264d_cbp_tab[(u1_mb_type - 1) >> 2];
312 ps_cur_mb_info->u1_cbp = u4_cbp;
313
314 /*-------------------------------------------------------------------*/
315 /* Read mb_qp_delta */
316 /*-------------------------------------------------------------------*/
317 {
318 UWORD32 u4_bitstream_offset = *pu4_bitstrm_ofst;
319 UWORD32 u4_word, u4_ldz, u4_abs_val;
320
321 /***************************************************************/
322 /* Find leading zeros in next 32 bits */
323 /***************************************************************/
324 NEXTBITS_32(u4_word, u4_bitstream_offset, pu4_bitstrm_buf);
325 u4_ldz = CLZ(u4_word);
326
327 /* Flush the ps_bitstrm */
328 u4_bitstream_offset += (u4_ldz + 1);
329
330 /* Read the suffix from the ps_bitstrm */
331 u4_word = 0;
332 if(u4_ldz)
333 GETBITS(u4_word, u4_bitstream_offset, pu4_bitstrm_buf,
334 u4_ldz);
335
336 *pu4_bitstrm_ofst = u4_bitstream_offset;
337 u4_abs_val = ((1 << u4_ldz) + u4_word) >> 1;
338
339 if(u4_word & 0x1)
340 i4_delta_qp = (-(WORD32)u4_abs_val);
341 else
342 i4_delta_qp = (u4_abs_val);
343
344 if((i4_delta_qp < -26) || (i4_delta_qp > 25))
345 return ERROR_INV_RANGE_QP_T;
346
347 }
348 //inlinined ih264d_sev
349 COPYTHECONTEXT("Delta quant", i1_delta_qp);
350
351 if(i4_delta_qp != 0)
352 {
353 ret = ih264d_update_qp(ps_dec, (WORD8)i4_delta_qp);
354 if(ret != OK)
355 return ret;
356 }
357
358 {
359 WORD16 i_scaleFactor;
360 UWORD32 ui_N = 0;
361 WORD16 *pi2_scale_matrix_ptr;
362 /*******************************************************************/
363 /* for luma DC coefficients the scaling is done during the parsing */
364 /* to preserve the precision */
365 /*******************************************************************/
366 if(ps_dec->s_high_profile.u1_scaling_present)
367 {
368 pi2_scale_matrix_ptr =
369 ps_dec->s_high_profile.i2_scalinglist4x4[0];
370 }
371 else
372 {
373 i_scaleFactor = 16;
374 pi2_scale_matrix_ptr = &i_scaleFactor;
375 }
376
377 /*---------------------------------------------------------------*/
378 /* Decode DC coefficients */
379 /*---------------------------------------------------------------*/
380 /*---------------------------------------------------------------*/
381 /* Calculation of N */
382 /*---------------------------------------------------------------*/
383 if(ui_is_left_mb_available)
384 {
385
386 if(ui_is_top_mb_available)
387 {
388 ui_N = ((ps_cur_mb_info->ps_top_mb->pu1_nnz_y[0]
389 + ps_dec->pu1_left_nnz_y[0] + 1) >> 1);
390 }
391 else
392 {
393 ui_N = ps_dec->pu1_left_nnz_y[0];
394 }
395 }
396 else if(ui_is_top_mb_available)
397 {
398 ui_N = ps_cur_mb_info->ps_top_mb->pu1_nnz_y[0];
399 }
400
401 {
402 WORD16 pi2_dc_coef[16];
403 WORD32 pi4_tmp[16];
404 tu_sblk4x4_coeff_data_t *ps_tu_4x4 =
405 (tu_sblk4x4_coeff_data_t *)ps_dec->pv_parse_tu_coeff_data;
406 WORD16 *pi2_coeff_block =
407 (WORD16 *)ps_dec->pv_parse_tu_coeff_data;
408 UWORD32 u4_num_coeff;
409 ps_tu_4x4->u2_sig_coeff_map = 0;
410
411 ret = ps_dec->pf_cavlc_parse4x4coeff[(ui_N > 7)](pi2_dc_coef, 0, ui_N,
412 ps_dec, &u4_num_coeff);
413 if(ret != OK)
414 return ret;
415
416 if(EXCEED_OFFSET(ps_bitstrm))
417 return ERROR_EOB_TERMINATE_T;
418 if(ps_tu_4x4->u2_sig_coeff_map)
419 {
420 memset(pi2_dc_coef,0,sizeof(pi2_dc_coef));
421 ih264d_unpack_coeff4x4_dc_4x4blk(ps_tu_4x4,
422 pi2_dc_coef,
423 ps_dec->pu1_inv_scan);
424
425 PROFILE_DISABLE_IQ_IT_RECON()
426 ps_dec->pf_ihadamard_scaling_4x4(pi2_dc_coef,
427 pi2_coeff_block,
428 ps_dec->pu2_quant_scale_y,
429 (UWORD16 *)pi2_scale_matrix_ptr,
430 ps_dec->u1_qp_y_div6,
431 pi4_tmp);
432 pi2_coeff_block += 16;
433 ps_dec->pv_parse_tu_coeff_data = (void *)pi2_coeff_block;
434 SET_BIT(ps_cur_mb_info->u1_yuv_dc_block_flag,0);
435 }
436
437 }
438 }
439 }
440
441
442 if(u4_cbp)
443 {
444
445 ret = ih264d_parse_residual4x4_cavlc(ps_dec, ps_cur_mb_info,
446 (UWORD8)u4_offset);
447 if(ret != OK)
448 return ret;
449 if(EXCEED_OFFSET(ps_bitstrm))
450 return ERROR_EOB_TERMINATE_T;
451
452 /* Store Left Mb NNZ and TOP chroma NNZ */
453 }
454 else
455 {
456 ps_cur_mb_info->u1_qp_div6 = ps_dec->u1_qp_y_div6;
457 ps_cur_mb_info->u1_qpc_div6 = ps_dec->u1_qp_u_div6;
458 ps_cur_mb_info->u1_qpcr_div6 = ps_dec->u1_qp_v_div6;
459 ps_cur_mb_info->u1_qp_rem6 = ps_dec->u1_qp_y_rem6;
460 ps_cur_mb_info->u1_qpc_rem6 = ps_dec->u1_qp_u_rem6;
461 ps_cur_mb_info->u1_qpcr_rem6 = ps_dec->u1_qp_v_rem6;
462 ih264d_update_nnz_for_skipmb(ps_dec, ps_cur_mb_info, CAVLC);
463 }
464
465 return OK;
466 }
467
468 /*!
469 **************************************************************************
470 * \if Function name : ParseIMbCab \endif
471 *
472 * \brief
473 * This function parses CABAC syntax of a I MB. If 16x16 Luma DC transform
474 * is also done here. Transformed Luma DC values are copied in their
475 * 0th pixel location of corrosponding CoeffBlock.
476 *
477 * \return
478 * 0 on Success and Error code otherwise
479 **************************************************************************
480 */
ih264d_parse_imb_cabac(dec_struct_t * ps_dec,dec_mb_info_t * ps_cur_mb_info,UWORD8 u1_mb_type)481 WORD32 ih264d_parse_imb_cabac(dec_struct_t * ps_dec,
482 dec_mb_info_t * ps_cur_mb_info,
483 UWORD8 u1_mb_type)
484 {
485 WORD8 i1_delta_qp;
486 UWORD8 u1_cbp;
487 UWORD8 u1_offset;
488 /* Variables for handling Cabac contexts */
489 ctxt_inc_mb_info_t *p_curr_ctxt = ps_dec->ps_curr_ctxt_mb_info;
490 ctxt_inc_mb_info_t *ps_left_ctxt = ps_dec->p_left_ctxt_mb_info;
491 dec_bit_stream_t * const ps_bitstrm = ps_dec->ps_bitstrm;
492 bin_ctxt_model_t *p_bin_ctxt;
493
494 UWORD8 u1_intra_chrom_pred_mode;
495 UWORD8 u1_dc_block_flag = 0;
496 WORD32 ret;
497
498 ps_cur_mb_info->u1_yuv_dc_block_flag = 0;
499
500 if(ps_left_ctxt == ps_dec->ps_def_ctxt_mb_info)
501 {
502 ps_dec->pu1_left_yuv_dc_csbp[0] = 0xf;
503 }
504
505 if(ps_dec->ps_cur_slice->u1_slice_type != I_SLICE)
506 {
507 WORD32 *pi4_buf;
508 WORD8 *pi1_buf;
509 MEMSET_16BYTES(&ps_dec->pu1_left_mv_ctxt_inc[0][0], 0);
510 *((UWORD32 *)ps_dec->pi1_left_ref_idx_ctxt_inc) = 0;
511 MEMSET_16BYTES(p_curr_ctxt->u1_mv, 0);
512 pi1_buf = p_curr_ctxt->i1_ref_idx;
513 pi4_buf = (WORD32 *)pi1_buf;
514 *pi4_buf = 0;
515 }
516
517 if(u1_mb_type == I_4x4_MB)
518 {
519 ps_cur_mb_info->ps_curmb->u1_mb_type = I_4x4_MB;
520 p_curr_ctxt->u1_mb_type = CAB_I4x4;
521 u1_offset = 0;
522
523 ps_cur_mb_info->u1_tran_form8x8 = 0;
524 ps_cur_mb_info->ps_curmb->u1_tran_form8x8 = 0;
525
526 /*--------------------------------------------------------------------*/
527 /* Read transform_size_8x8_flag if present */
528 /*--------------------------------------------------------------------*/
529 if(ps_dec->s_high_profile.u1_transform8x8_present)
530 {
531 ps_cur_mb_info->u1_tran_form8x8 = ih264d_parse_transform8x8flag_cabac(
532 ps_dec, ps_cur_mb_info);
533 COPYTHECONTEXT("transform_size_8x8_flag", ps_cur_mb_info->u1_tran_form8x8);
534 p_curr_ctxt->u1_transform8x8_ctxt = ps_cur_mb_info->u1_tran_form8x8;
535 ps_cur_mb_info->ps_curmb->u1_tran_form8x8 = ps_cur_mb_info->u1_tran_form8x8;
536 }
537 else
538 {
539 p_curr_ctxt->u1_transform8x8_ctxt = 0;
540 }
541
542 /*--------------------------------------------------------------------*/
543 /* Read the IntraPrediction modes for LUMA */
544 /*--------------------------------------------------------------------*/
545 if (!ps_cur_mb_info->u1_tran_form8x8)
546 {
547 UWORD8 *pu1_temp;
548 ih264d_read_intra_pred_modes_cabac(
549 ps_dec,
550 ((UWORD8 *)ps_dec->pv_parse_tu_coeff_data),
551 ((UWORD8 *)ps_dec->pv_parse_tu_coeff_data+16),
552 ps_cur_mb_info->u1_tran_form8x8);
553 pu1_temp = (UWORD8 *)ps_dec->pv_parse_tu_coeff_data;
554 pu1_temp += 32;
555 ps_dec->pv_parse_tu_coeff_data = (void *)pu1_temp;
556 }
557 else
558 {
559 UWORD8 *pu1_temp;
560 ih264d_read_intra_pred_modes_cabac(
561 ps_dec,
562 ((UWORD8 *)ps_dec->pv_parse_tu_coeff_data),
563 ((UWORD8 *)ps_dec->pv_parse_tu_coeff_data+4),
564 ps_cur_mb_info->u1_tran_form8x8);
565 pu1_temp = (UWORD8 *)ps_dec->pv_parse_tu_coeff_data;
566 pu1_temp += 8;
567 ps_dec->pv_parse_tu_coeff_data = (void *)pu1_temp;
568 }
569 /*--------------------------------------------------------------------*/
570 /* Read the IntraPrediction mode for CHROMA */
571 /*--------------------------------------------------------------------*/
572 u1_intra_chrom_pred_mode = ih264d_parse_chroma_pred_mode_cabac(ps_dec);
573 COPYTHECONTEXT("intra_chroma_pred_mode", u1_intra_chrom_pred_mode);
574 p_curr_ctxt->u1_intra_chroma_pred_mode = ps_cur_mb_info->u1_chroma_pred_mode =
575 u1_intra_chrom_pred_mode;
576
577 /*--------------------------------------------------------------------*/
578 /* Read the Coded block pattern */
579 /*--------------------------------------------------------------------*/
580 u1_cbp = ih264d_parse_ctx_cbp_cabac(ps_dec);
581 COPYTHECONTEXT("coded_block_pattern", u1_cbp);
582 ps_cur_mb_info->u1_cbp = u1_cbp;
583 p_curr_ctxt->u1_cbp = u1_cbp;
584
585 /*--------------------------------------------------------------------*/
586 /* Read mb_qp_delta */
587 /*--------------------------------------------------------------------*/
588 if(ps_cur_mb_info->u1_cbp)
589 {
590 ret = ih264d_parse_mb_qp_delta_cabac(ps_dec, &i1_delta_qp);
591 if(ret != OK)
592 return ret;
593 COPYTHECONTEXT("mb_qp_delta", i1_delta_qp);
594 if(i1_delta_qp != 0)
595 {
596 ret = ih264d_update_qp(ps_dec, i1_delta_qp);
597 if(ret != OK)
598 return ret;
599 }
600 }
601 else
602 ps_dec->i1_prev_mb_qp_delta = 0;
603 p_curr_ctxt->u1_yuv_dc_csbp &= 0xFE;
604 }
605 else
606 {
607 u1_offset = 1;
608 ps_cur_mb_info->ps_curmb->u1_mb_type = I_16x16_MB;
609 p_curr_ctxt->u1_mb_type = CAB_I16x16;
610 ps_cur_mb_info->u1_tran_form8x8 = 0;
611 p_curr_ctxt->u1_transform8x8_ctxt = 0;
612 ps_cur_mb_info->ps_curmb->u1_tran_form8x8 = 0;
613 /*--------------------------------------------------------------------*/
614 /* Read the IntraPrediction mode for CHROMA */
615 /*--------------------------------------------------------------------*/
616 u1_intra_chrom_pred_mode = ih264d_parse_chroma_pred_mode_cabac(ps_dec);
617 if(u1_intra_chrom_pred_mode > 3)
618 return ERROR_CHROMA_PRED_MODE;
619
620 COPYTHECONTEXT("Chroma intra_chroma_pred_mode pred mode", u1_intra_chrom_pred_mode);
621 p_curr_ctxt->u1_intra_chroma_pred_mode = ps_cur_mb_info->u1_chroma_pred_mode =
622 u1_intra_chrom_pred_mode;
623
624 /*--------------------------------------------------------------------*/
625 /* Read the Coded block pattern */
626 /*--------------------------------------------------------------------*/
627 u1_cbp = gau1_ih264d_cbp_tab[(u1_mb_type - 1) >> 2];
628 ps_cur_mb_info->u1_cbp = u1_cbp;
629 p_curr_ctxt->u1_cbp = u1_cbp;
630
631 /*--------------------------------------------------------------------*/
632 /* Read mb_qp_delta */
633 /*--------------------------------------------------------------------*/
634 ret = ih264d_parse_mb_qp_delta_cabac(ps_dec, &i1_delta_qp);
635 if(ret != OK)
636 return ret;
637 COPYTHECONTEXT("mb_qp_delta", i1_delta_qp);
638 if(i1_delta_qp != 0)
639 {
640 ret = ih264d_update_qp(ps_dec, i1_delta_qp);
641 if(ret != OK)
642 return ret;
643 }
644
645 {
646 WORD16 i_scaleFactor;
647 WORD16* pi2_scale_matrix_ptr;
648 /*******************************************************************/
649 /* for luma DC coefficients the scaling is done during the parsing */
650 /* to preserve the precision */
651 /*******************************************************************/
652 if(ps_dec->s_high_profile.u1_scaling_present)
653 {
654 pi2_scale_matrix_ptr =
655 ps_dec->s_high_profile.i2_scalinglist4x4[0];
656
657 }
658 else
659 {
660 i_scaleFactor = 16;
661 pi2_scale_matrix_ptr = &i_scaleFactor;
662 }
663 {
664 ctxt_inc_mb_info_t *ps_top_ctxt = ps_dec->p_top_ctxt_mb_info;
665 UWORD8 uc_a, uc_b;
666 UWORD32 u4_ctx_inc;
667
668 INC_SYM_COUNT(&(ps_dec->s_cab_dec_env));
669
670 /* if MbAddrN not available then CondTermN = 1 */
671 uc_b = ((ps_top_ctxt->u1_yuv_dc_csbp) & 0x01);
672
673 /* if MbAddrN not available then CondTermN = 1 */
674 uc_a = ((ps_dec->pu1_left_yuv_dc_csbp[0]) & 0x01);
675
676 u4_ctx_inc = (uc_a + (uc_b << 1));
677
678 {
679 WORD16 pi2_dc_coef[16];
680 tu_sblk4x4_coeff_data_t *ps_tu_4x4 =
681 (tu_sblk4x4_coeff_data_t *)ps_dec->pv_parse_tu_coeff_data;
682 WORD16 *pi2_coeff_block =
683 (WORD16 *)ps_dec->pv_parse_tu_coeff_data;
684
685 p_bin_ctxt = (ps_dec->p_cbf_t[LUMA_DC_CTXCAT]) + u4_ctx_inc;
686
687 u1_dc_block_flag =
688 ih264d_read_coeff4x4_cabac(ps_bitstrm,
689 LUMA_DC_CTXCAT,
690 ps_dec->p_significant_coeff_flag_t[LUMA_DC_CTXCAT],
691 ps_dec, p_bin_ctxt);
692
693 /* Store coded_block_flag */
694 p_curr_ctxt->u1_yuv_dc_csbp &= 0xFE;
695 p_curr_ctxt->u1_yuv_dc_csbp |= u1_dc_block_flag;
696 if(u1_dc_block_flag)
697 {
698 WORD32 pi4_tmp[16];
699 memset(pi2_dc_coef,0,sizeof(pi2_dc_coef));
700 ih264d_unpack_coeff4x4_dc_4x4blk(ps_tu_4x4,
701 pi2_dc_coef,
702 ps_dec->pu1_inv_scan);
703
704 PROFILE_DISABLE_IQ_IT_RECON()
705 ps_dec->pf_ihadamard_scaling_4x4(pi2_dc_coef,
706 pi2_coeff_block,
707 ps_dec->pu2_quant_scale_y,
708 (UWORD16 *)pi2_scale_matrix_ptr,
709 ps_dec->u1_qp_y_div6,
710 pi4_tmp);
711 pi2_coeff_block += 16;
712 ps_dec->pv_parse_tu_coeff_data = (void *)pi2_coeff_block;
713 SET_BIT(ps_cur_mb_info->u1_yuv_dc_block_flag,0);
714 }
715
716 }
717
718 }
719 }
720 }
721
722 ps_dec->pu1_left_yuv_dc_csbp[0] &= 0x6;
723 ps_dec->pu1_left_yuv_dc_csbp[0] |= u1_dc_block_flag;
724
725 ih264d_parse_residual4x4_cabac(ps_dec, ps_cur_mb_info, u1_offset);
726 if(EXCEED_OFFSET(ps_bitstrm))
727 return ERROR_EOB_TERMINATE_T;
728 return OK;
729 }
730
731 /*****************************************************************************/
732 /* */
733 /* Function Name : ih264d_parse_islice_data_cavlc */
734 /* */
735 /* Description : This function parses cabac syntax of a inter slice on */
736 /* N MB basis. */
737 /* */
738 /* Inputs : ps_dec */
739 /* sliceparams */
740 /* firstMbInSlice */
741 /* */
742 /* Processing : 1. After parsing syntax for N MBs those N MBs are */
743 /* decoded till the end of slice. */
744 /* */
745 /* Returns : 0 */
746 /* */
747 /* Issues : <List any issues or problems with this function> */
748 /* */
749 /* Revision History: */
750 /* */
751 /* DD MM YYYY Author(s) Changes (Describe the changes made) */
752 /* 24 06 2005 ARNY Draft */
753 /* */
754 /*****************************************************************************/
ih264d_parse_islice_data_cavlc(dec_struct_t * ps_dec,dec_slice_params_t * ps_slice,UWORD16 u2_first_mb_in_slice)755 WORD32 ih264d_parse_islice_data_cavlc(dec_struct_t * ps_dec,
756 dec_slice_params_t * ps_slice,
757 UWORD16 u2_first_mb_in_slice)
758 {
759 UWORD8 uc_more_data_flag;
760 UWORD8 u1_num_mbs, u1_mb_idx;
761 dec_mb_info_t *ps_cur_mb_info;
762 deblk_mb_t *ps_cur_deblk_mb;
763 dec_bit_stream_t * const ps_bitstrm = ps_dec->ps_bitstrm;
764 UWORD32 *pu4_bitstrm_ofst = &ps_bitstrm->u4_ofst;
765 UWORD32 *pu4_bitstrm_buf = ps_bitstrm->pu4_buffer;
766 UWORD16 i2_pic_wdin_mbs = ps_dec->u2_frm_wd_in_mbs;
767 WORD16 i2_cur_mb_addr;
768 UWORD8 u1_mbaff;
769 UWORD8 u1_num_mbs_next, u1_end_of_row, u1_tfr_n_mb;
770 WORD32 ret = OK;
771
772 ps_dec->u1_qp = ps_slice->u1_slice_qp;
773 ih264d_update_qp(ps_dec, 0);
774 u1_mbaff = ps_slice->u1_mbaff_frame_flag;
775
776 /* initializations */
777 u1_mb_idx = ps_dec->u1_mb_idx;
778 u1_num_mbs = u1_mb_idx;
779
780 uc_more_data_flag = 1;
781 i2_cur_mb_addr = u2_first_mb_in_slice << u1_mbaff;
782
783 do
784 {
785 UWORD8 u1_mb_type;
786
787 ps_dec->pv_prev_mb_parse_tu_coeff_data = ps_dec->pv_parse_tu_coeff_data;
788
789 if(i2_cur_mb_addr > ps_dec->ps_cur_sps->u2_max_mb_addr)
790 {
791 break;
792 }
793
794 ps_cur_mb_info = ps_dec->ps_nmb_info + u1_num_mbs;
795 ps_dec->u4_num_mbs_cur_nmb = u1_num_mbs;
796 ps_dec->u4_num_pmbair = (u1_num_mbs >> u1_mbaff);
797
798 ps_cur_mb_info->u1_end_of_slice = 0;
799
800 /***************************************************************/
801 /* Get the required information for decoding of MB */
802 /* mb_x, mb_y , neighbour availablity, */
803 /***************************************************************/
804 ps_dec->pf_get_mb_info(ps_dec, i2_cur_mb_addr, ps_cur_mb_info, 0);
805
806 /***************************************************************/
807 /* Set the deblocking parameters for this MB */
808 /***************************************************************/
809 ps_cur_deblk_mb = ps_dec->ps_deblk_mbn + u1_num_mbs;
810
811 if(ps_dec->u4_app_disable_deblk_frm == 0)
812 ih264d_set_deblocking_parameters(ps_cur_deblk_mb, ps_slice,
813 ps_dec->u1_mb_ngbr_availablity,
814 ps_dec->u1_cur_mb_fld_dec_flag);
815
816 ps_cur_deblk_mb->u1_mb_type = ps_cur_deblk_mb->u1_mb_type | D_INTRA_MB;
817
818 /**************************************************************/
819 /* Macroblock Layer Begins, Decode the u1_mb_type */
820 /**************************************************************/
821 //Inlined ih264d_uev
822 {
823 UWORD32 u4_bitstream_offset = *pu4_bitstrm_ofst;
824 UWORD32 u4_word, u4_ldz, u4_temp;
825
826 /***************************************************************/
827 /* Find leading zeros in next 32 bits */
828 /***************************************************************/
829 NEXTBITS_32(u4_word, u4_bitstream_offset, pu4_bitstrm_buf);
830 u4_ldz = CLZ(u4_word);
831 /* Flush the ps_bitstrm */
832 u4_bitstream_offset += (u4_ldz + 1);
833 /* Read the suffix from the ps_bitstrm */
834 u4_word = 0;
835 if(u4_ldz)
836 GETBITS(u4_word, u4_bitstream_offset, pu4_bitstrm_buf,
837 u4_ldz);
838 *pu4_bitstrm_ofst = u4_bitstream_offset;
839 u4_temp = ((1 << u4_ldz) + u4_word - 1);
840 if(u4_temp > 25)
841 return ERROR_MB_TYPE;
842 u1_mb_type = u4_temp;
843
844 }
845 //Inlined ih264d_uev
846 ps_cur_mb_info->u1_mb_type = u1_mb_type;
847 COPYTHECONTEXT("u1_mb_type", u1_mb_type);
848
849 /**************************************************************/
850 /* Parse Macroblock data */
851 /**************************************************************/
852 if(25 == u1_mb_type)
853 {
854 /* I_PCM_MB */
855 ps_cur_mb_info->ps_curmb->u1_mb_type = I_PCM_MB;
856 ret = ih264d_parse_ipcm_mb(ps_dec, ps_cur_mb_info, u1_num_mbs);
857 if(ret != OK)
858 return ret;
859 ps_cur_deblk_mb->u1_mb_qp = 0;
860 }
861 else
862 {
863 ret = ih264d_parse_imb_cavlc(ps_dec, ps_cur_mb_info, u1_num_mbs, u1_mb_type);
864 if(ret != OK)
865 return ret;
866 ps_cur_deblk_mb->u1_mb_qp = ps_dec->u1_qp;
867 }
868
869 uc_more_data_flag = MORE_RBSP_DATA(ps_bitstrm);
870
871 if(u1_mbaff)
872 {
873 ih264d_update_mbaff_left_nnz(ps_dec, ps_cur_mb_info);
874 if(!uc_more_data_flag && (0 == (i2_cur_mb_addr & 1)))
875 {
876 return ERROR_EOB_FLUSHBITS_T;
877 }
878 }
879 /**************************************************************/
880 /* Get next Macroblock address */
881 /**************************************************************/
882
883 i2_cur_mb_addr++;
884
885
886 /* Store the colocated information */
887 {
888 mv_pred_t *ps_mv_nmb_start = ps_dec->ps_mv_cur + (u1_num_mbs << 4);
889
890 mv_pred_t s_mvPred =
891 {
892 { 0, 0, 0, 0 },
893 { -1, -1 }, 0, 0};
894 ih264d_rep_mv_colz(ps_dec, &s_mvPred, ps_mv_nmb_start, 0,
895 (UWORD8)(ps_dec->u1_cur_mb_fld_dec_flag << 1), 4,
896 4);
897 }
898
899 /*if num _cores is set to 3,compute bs will be done in another thread*/
900 if(ps_dec->u4_num_cores < 3)
901 {
902 if(ps_dec->u4_app_disable_deblk_frm == 0)
903 ps_dec->pf_compute_bs(ps_dec, ps_cur_mb_info,
904 (UWORD16)(u1_num_mbs >> u1_mbaff));
905 }
906 u1_num_mbs++;
907
908 /****************************************************************/
909 /* Check for End Of Row */
910 /****************************************************************/
911 u1_num_mbs_next = i2_pic_wdin_mbs - ps_dec->u2_mbx - 1;
912 u1_end_of_row = (!u1_num_mbs_next) && (!(u1_mbaff && (u1_num_mbs & 0x01)));
913 u1_tfr_n_mb = (u1_num_mbs == ps_dec->u1_recon_mb_grp) || u1_end_of_row
914 || (!uc_more_data_flag);
915 ps_cur_mb_info->u1_end_of_slice = (!uc_more_data_flag);
916
917 /*H264_DEC_DEBUG_PRINT("Pic: %d Mb_X=%d Mb_Y=%d",
918 ps_slice->i4_poc >> ps_slice->u1_field_pic_flag,
919 ps_dec->u2_mbx,ps_dec->u2_mby + (1 - ps_cur_mb_info->u1_topmb));
920 H264_DEC_DEBUG_PRINT("u1_tfr_n_mb || (!uc_more_data_flag): %d", u1_tfr_n_mb || (!uc_more_data_flag));*/
921 if(u1_tfr_n_mb || (!uc_more_data_flag))
922 {
923
924 if(ps_dec->u1_separate_parse)
925 {
926 ih264d_parse_tfr_nmb(ps_dec, u1_mb_idx, u1_num_mbs,
927 u1_num_mbs_next, u1_tfr_n_mb, u1_end_of_row);
928 ps_dec->ps_nmb_info += u1_num_mbs;
929 }
930 else
931 {
932 ih264d_decode_recon_tfr_nmb(ps_dec, u1_mb_idx, u1_num_mbs,
933 u1_num_mbs_next, u1_tfr_n_mb,
934 u1_end_of_row);
935 }
936 ps_dec->u2_total_mbs_coded += u1_num_mbs;
937 if(u1_tfr_n_mb)
938 u1_num_mbs = 0;
939 u1_mb_idx = u1_num_mbs;
940 ps_dec->u1_mb_idx = u1_num_mbs;
941
942 }
943 }
944 while(uc_more_data_flag);
945
946 ps_dec->u4_num_mbs_cur_nmb = 0;
947 ps_dec->ps_cur_slice->u4_mbs_in_slice = i2_cur_mb_addr
948
949 - (u2_first_mb_in_slice << u1_mbaff);
950
951 return ret;
952 }
953
954 /*****************************************************************************/
955 /* */
956 /* Function Name : ih264d_parse_islice_data_cabac */
957 /* */
958 /* Description : This function parses cabac syntax of a inter slice on */
959 /* N MB basis. */
960 /* */
961 /* Inputs : ps_dec */
962 /* sliceparams */
963 /* firstMbInSlice */
964 /* */
965 /* Processing : 1. After parsing syntax for N MBs those N MBs are */
966 /* decoded till the end of slice. */
967 /* */
968 /* Returns : 0 */
969 /* */
970 /* Issues : <List any issues or problems with this function> */
971 /* */
972 /* Revision History: */
973 /* */
974 /* DD MM YYYY Author(s) Changes (Describe the changes made) */
975 /* 24 06 2005 ARNY Draft */
976 /* */
977 /*****************************************************************************/
ih264d_parse_islice_data_cabac(dec_struct_t * ps_dec,dec_slice_params_t * ps_slice,UWORD16 u2_first_mb_in_slice)978 WORD32 ih264d_parse_islice_data_cabac(dec_struct_t * ps_dec,
979 dec_slice_params_t * ps_slice,
980 UWORD16 u2_first_mb_in_slice)
981 {
982 UWORD8 uc_more_data_flag;
983 UWORD8 u1_num_mbs, u1_mb_idx;
984 dec_mb_info_t *ps_cur_mb_info;
985 deblk_mb_t *ps_cur_deblk_mb;
986
987 dec_bit_stream_t * const ps_bitstrm = ps_dec->ps_bitstrm;
988 UWORD16 i2_pic_wdin_mbs = ps_dec->u2_frm_wd_in_mbs;
989 WORD16 i2_cur_mb_addr;
990 UWORD8 u1_mbaff;
991 UWORD8 u1_num_mbs_next, u1_end_of_row, u1_tfr_n_mb;
992 WORD32 ret = OK;
993
994 ps_dec->u1_qp = ps_slice->u1_slice_qp;
995 ih264d_update_qp(ps_dec, 0);
996 u1_mbaff = ps_slice->u1_mbaff_frame_flag;
997
998 if(ps_bitstrm->u4_ofst & 0x07)
999 {
1000 ps_bitstrm->u4_ofst += 8;
1001 ps_bitstrm->u4_ofst &= 0xFFFFFFF8;
1002 }
1003 ret = ih264d_init_cabac_dec_envirnoment(&(ps_dec->s_cab_dec_env), ps_bitstrm);
1004 if(ret != OK)
1005 return ret;
1006 ih264d_init_cabac_contexts(I_SLICE, ps_dec);
1007
1008 ps_dec->i1_prev_mb_qp_delta = 0;
1009
1010 /* initializations */
1011 u1_mb_idx = ps_dec->u1_mb_idx;
1012 u1_num_mbs = u1_mb_idx;
1013
1014 uc_more_data_flag = 1;
1015 i2_cur_mb_addr = u2_first_mb_in_slice << u1_mbaff;
1016 do
1017 {
1018 UWORD16 u2_mbx;
1019
1020 ps_dec->pv_prev_mb_parse_tu_coeff_data = ps_dec->pv_parse_tu_coeff_data;
1021
1022 if(i2_cur_mb_addr > ps_dec->ps_cur_sps->u2_max_mb_addr)
1023 {
1024 break;
1025 }
1026
1027 {
1028 UWORD8 u1_mb_type;
1029
1030 ps_cur_mb_info = ps_dec->ps_nmb_info + u1_num_mbs;
1031 ps_dec->u4_num_mbs_cur_nmb = u1_num_mbs;
1032 ps_dec->u4_num_pmbair = (u1_num_mbs >> u1_mbaff);
1033
1034 ps_cur_mb_info->u1_end_of_slice = 0;
1035
1036 /***************************************************************/
1037 /* Get the required information for decoding of MB */
1038 /* mb_x, mb_y , neighbour availablity, */
1039 /***************************************************************/
1040 ps_dec->pf_get_mb_info(ps_dec, i2_cur_mb_addr, ps_cur_mb_info, 0);
1041 u2_mbx = ps_dec->u2_mbx;
1042
1043 /*********************************************************************/
1044 /* initialize u1_tran_form8x8 to zero to aviod uninitialized accesses */
1045 /*********************************************************************/
1046 ps_cur_mb_info->u1_tran_form8x8 = 0;
1047 ps_cur_mb_info->ps_curmb->u1_tran_form8x8 = 0;
1048
1049 /***************************************************************/
1050 /* Set the deblocking parameters for this MB */
1051 /***************************************************************/
1052 ps_cur_deblk_mb = ps_dec->ps_deblk_mbn + u1_num_mbs;
1053 if(ps_dec->u4_app_disable_deblk_frm == 0)
1054 ih264d_set_deblocking_parameters(
1055 ps_cur_deblk_mb, ps_slice,
1056 ps_dec->u1_mb_ngbr_availablity,
1057 ps_dec->u1_cur_mb_fld_dec_flag);
1058
1059 ps_cur_deblk_mb->u1_mb_type = ps_cur_deblk_mb->u1_mb_type
1060 | D_INTRA_MB;
1061
1062 /* Macroblock Layer Begins */
1063 /* Decode the u1_mb_type */
1064 u1_mb_type = ih264d_parse_mb_type_intra_cabac(0, ps_dec);
1065 if(u1_mb_type > 25)
1066 return ERROR_MB_TYPE;
1067 ps_cur_mb_info->u1_mb_type = u1_mb_type;
1068 COPYTHECONTEXT("u1_mb_type", u1_mb_type);
1069
1070 /* Parse Macroblock Data */
1071 if(25 == u1_mb_type)
1072 {
1073 /* I_PCM_MB */
1074 ps_cur_mb_info->ps_curmb->u1_mb_type = I_PCM_MB;
1075 ret = ih264d_parse_ipcm_mb(ps_dec, ps_cur_mb_info, u1_num_mbs);
1076 if(ret != OK)
1077 return ret;
1078 ps_cur_deblk_mb->u1_mb_qp = 0;
1079 }
1080 else
1081 {
1082 ret = ih264d_parse_imb_cabac(ps_dec, ps_cur_mb_info, u1_mb_type);
1083 if(ret != OK)
1084 return ret;
1085 ps_cur_deblk_mb->u1_mb_qp = ps_dec->u1_qp;
1086 }
1087
1088 if(u1_mbaff)
1089 {
1090 ih264d_update_mbaff_left_nnz(ps_dec, ps_cur_mb_info);
1091 }
1092
1093
1094 if(ps_cur_mb_info->u1_topmb && u1_mbaff)
1095 uc_more_data_flag = 1;
1096 else
1097 {
1098 uc_more_data_flag = ih264d_decode_terminate(&ps_dec->s_cab_dec_env,
1099 ps_bitstrm);
1100 uc_more_data_flag = !uc_more_data_flag;
1101 COPYTHECONTEXT("Decode Sliceterm",!uc_more_data_flag);
1102 }
1103
1104 if(u1_mbaff)
1105 {
1106 if(!uc_more_data_flag && (0 == (i2_cur_mb_addr & 1)))
1107 {
1108 return ERROR_EOB_FLUSHBITS_T;
1109 }
1110 }
1111 /* Next macroblock information */
1112 i2_cur_mb_addr++;
1113 /* Store the colocated information */
1114 {
1115
1116 mv_pred_t *ps_mv_nmb_start = ps_dec->ps_mv_cur + (u1_num_mbs << 4);
1117 mv_pred_t s_mvPred =
1118 {
1119 { 0, 0, 0, 0 },
1120 { -1, -1 }, 0, 0};
1121 ih264d_rep_mv_colz(
1122 ps_dec, &s_mvPred, ps_mv_nmb_start, 0,
1123 (UWORD8)(ps_dec->u1_cur_mb_fld_dec_flag << 1),
1124 4, 4);
1125 }
1126 /*if num _cores is set to 3,compute bs will be done in another thread*/
1127 if(ps_dec->u4_num_cores < 3)
1128 {
1129 if(ps_dec->u4_app_disable_deblk_frm == 0)
1130 ps_dec->pf_compute_bs(ps_dec, ps_cur_mb_info,
1131 (UWORD16)(u1_num_mbs >> u1_mbaff));
1132 }
1133 u1_num_mbs++;
1134
1135 }
1136
1137 /****************************************************************/
1138 /* Check for End Of Row */
1139 /****************************************************************/
1140 u1_num_mbs_next = i2_pic_wdin_mbs - u2_mbx - 1;
1141 u1_end_of_row = (!u1_num_mbs_next) && (!(u1_mbaff && (u1_num_mbs & 0x01)));
1142 u1_tfr_n_mb = (u1_num_mbs == ps_dec->u1_recon_mb_grp) || u1_end_of_row
1143 || (!uc_more_data_flag);
1144 ps_cur_mb_info->u1_end_of_slice = (!uc_more_data_flag);
1145
1146 if(u1_tfr_n_mb || (!uc_more_data_flag))
1147 {
1148
1149
1150 if(ps_dec->u1_separate_parse)
1151 {
1152 ih264d_parse_tfr_nmb(ps_dec, u1_mb_idx, u1_num_mbs,
1153 u1_num_mbs_next, u1_tfr_n_mb, u1_end_of_row);
1154 ps_dec->ps_nmb_info += u1_num_mbs;
1155 }
1156 else
1157 {
1158 ih264d_decode_recon_tfr_nmb(ps_dec, u1_mb_idx, u1_num_mbs,
1159 u1_num_mbs_next, u1_tfr_n_mb,
1160 u1_end_of_row);
1161 }
1162 ps_dec->u2_total_mbs_coded += u1_num_mbs;
1163 if(u1_tfr_n_mb)
1164 u1_num_mbs = 0;
1165 u1_mb_idx = u1_num_mbs;
1166 ps_dec->u1_mb_idx = u1_num_mbs;
1167
1168 }
1169 }
1170 while(uc_more_data_flag);
1171
1172 ps_dec->u4_num_mbs_cur_nmb = 0;
1173 ps_dec->ps_cur_slice->u4_mbs_in_slice = i2_cur_mb_addr
1174
1175 - (u2_first_mb_in_slice << u1_mbaff);
1176
1177 return ret;
1178 }
1179
1180 /*****************************************************************************/
1181 /* */
1182 /* Function Name : ih264d_parse_ipcm_mb */
1183 /* */
1184 /* Description : This function decodes the pixel values of I_PCM Mb. */
1185 /* */
1186 /* Inputs : ps_dec, ps_cur_mb_info and mb number */
1187 /* */
1188 /* Description : This function reads the luma and chroma pixels directly */
1189 /* from the bitstream when the mbtype is I_PCM and stores */
1190 /* them in recon buffer. If the entropy coding mode is */
1191 /* cabac, decoding engine is re-initialized. The nnzs and */
1192 /* cabac contexts are appropriately modified. */
1193 /* Returns : void */
1194 /* */
1195 /* Revision History: */
1196 /* DD MM YYYY Author(s) Changes (Describe the changes made) */
1197 /* 13 07 2002 Jay */
1198 /* */
1199 /*****************************************************************************/
1200
ih264d_parse_ipcm_mb(dec_struct_t * ps_dec,dec_mb_info_t * ps_cur_mb_info,UWORD8 u1_mbNum)1201 WORD32 ih264d_parse_ipcm_mb(dec_struct_t * ps_dec,
1202 dec_mb_info_t *ps_cur_mb_info,
1203 UWORD8 u1_mbNum)
1204 {
1205 dec_bit_stream_t * const ps_bitstrm = ps_dec->ps_bitstrm;
1206 UWORD8 u1_mbaff = ps_dec->ps_cur_slice->u1_mbaff_frame_flag;
1207 UWORD8 *pu1_y, *pu1_u, *pu1_v;
1208 WORD32 ret;
1209
1210 UWORD32 u4_rec_width_y, u4_rec_width_uv;
1211 UWORD32 u1_num_mb_pair;
1212 UWORD8 u1_x, u1_y;
1213 /* CHANGED CODE */
1214 tfr_ctxt_t *ps_frame_buf;
1215 UWORD8 u1_mb_field_decoding_flag;
1216 UWORD32 *pu4_buf;
1217 UWORD8 *pu1_buf;
1218 /* CHANGED CODE */
1219
1220 if(ps_dec->u1_separate_parse)
1221 {
1222 ps_frame_buf = &ps_dec->s_tran_addrecon_parse;
1223 }
1224 else
1225 {
1226 ps_frame_buf = &ps_dec->s_tran_addrecon;
1227 }
1228 /* align bistream to byte boundary. */
1229 /* pcm_alignment_zero_bit discarded */
1230 /* For XX GotoByteBoundary */
1231 if(ps_bitstrm->u4_ofst & 0x07)
1232 {
1233 ps_bitstrm->u4_ofst += 8;
1234 ps_bitstrm->u4_ofst &= 0xFFFFFFF8;
1235 }
1236
1237 /* Store left Nnz as 16 for each 4x4 blk */
1238
1239 pu1_buf = ps_dec->pu1_left_nnz_y;
1240 pu4_buf = (UWORD32 *)pu1_buf;
1241 *pu4_buf = 0x10101010;
1242 pu1_buf = ps_cur_mb_info->ps_curmb->pu1_nnz_y;
1243 pu4_buf = (UWORD32 *)pu1_buf;
1244 *pu4_buf = 0x10101010;
1245 pu1_buf = ps_cur_mb_info->ps_curmb->pu1_nnz_uv;
1246 pu4_buf = (UWORD32 *)pu1_buf;
1247 *pu4_buf = 0x10101010;
1248 pu1_buf = ps_dec->pu1_left_nnz_uv;
1249 pu4_buf = (UWORD32 *)pu1_buf;
1250 *pu4_buf = 0x10101010;
1251 ps_cur_mb_info->u1_cbp = 0xff;
1252
1253 ps_dec->i1_prev_mb_qp_delta = 0;
1254 /* Get neighbour MB's */
1255 u1_num_mb_pair = (u1_mbNum >> u1_mbaff);
1256
1257 /*****************************************************************************/
1258 /* calculate the RECON buffer YUV pointers for the PCM data */
1259 /*****************************************************************************/
1260 /* CHANGED CODE */
1261 u1_mb_field_decoding_flag = ps_cur_mb_info->u1_mb_field_decodingflag;
1262 pu1_y = ps_frame_buf->pu1_dest_y + (u1_num_mb_pair << 4);
1263 pu1_u = ps_frame_buf->pu1_dest_u + (u1_num_mb_pair << 4);
1264 pu1_v = pu1_u + 1;
1265
1266 u4_rec_width_y = ps_dec->u2_frm_wd_y << u1_mb_field_decoding_flag;
1267 u4_rec_width_uv = ps_dec->u2_frm_wd_uv << u1_mb_field_decoding_flag;
1268 /* CHANGED CODE */
1269
1270 if(u1_mbaff)
1271 {
1272 UWORD8 u1_top_mb;
1273
1274 u1_top_mb = ps_cur_mb_info->u1_topmb;
1275
1276 if(u1_top_mb == 0)
1277 {
1278 pu1_y += (u1_mb_field_decoding_flag ?
1279 (u4_rec_width_y >> 1) : (u4_rec_width_y << 4));
1280 pu1_u += (u1_mb_field_decoding_flag ?
1281 (u4_rec_width_uv) : (u4_rec_width_uv << 4));
1282 pu1_v = pu1_u + 1;
1283 }
1284 }
1285
1286 /* Read Luma samples */
1287 for(u1_y = 0; u1_y < 16; u1_y++)
1288 {
1289 for(u1_x = 0; u1_x < 16; u1_x++)
1290 pu1_y[u1_x] = ih264d_get_bits_h264(ps_bitstrm, 8);
1291
1292 pu1_y += u4_rec_width_y;
1293 }
1294
1295 /* Read Chroma samples */
1296 for(u1_y = 0; u1_y < 8; u1_y++)
1297 {
1298 for(u1_x = 0; u1_x < 8; u1_x++)
1299 pu1_u[u1_x * YUV420SP_FACTOR] = ih264d_get_bits_h264(ps_bitstrm, 8);
1300
1301 pu1_u += u4_rec_width_uv;
1302 }
1303
1304 for(u1_y = 0; u1_y < 8; u1_y++)
1305 {
1306 for(u1_x = 0; u1_x < 8; u1_x++)
1307 pu1_v[u1_x * YUV420SP_FACTOR] = ih264d_get_bits_h264(ps_bitstrm, 8);
1308
1309 pu1_v += u4_rec_width_uv;
1310 }
1311
1312 if(CABAC == ps_dec->ps_cur_pps->u1_entropy_coding_mode)
1313 {
1314 UWORD32 *pu4_buf;
1315 UWORD8 *pu1_buf;
1316 ctxt_inc_mb_info_t *p_curr_ctxt = ps_dec->ps_curr_ctxt_mb_info;
1317 /* Re-initialize the cabac decoding engine. */
1318 ret = ih264d_init_cabac_dec_envirnoment(&(ps_dec->s_cab_dec_env), ps_bitstrm);
1319 if(ret != OK)
1320 return ret;
1321 /* update the cabac contetxs */
1322 p_curr_ctxt->u1_mb_type = CAB_I_PCM;
1323 p_curr_ctxt->u1_cbp = 47;
1324 p_curr_ctxt->u1_intra_chroma_pred_mode = 0;
1325 p_curr_ctxt->u1_transform8x8_ctxt = 0;
1326 ps_cur_mb_info->ps_curmb->u1_tran_form8x8 = 0;
1327
1328 pu1_buf = ps_dec->pu1_left_nnz_y;
1329 pu4_buf = (UWORD32 *)pu1_buf;
1330 *pu4_buf = 0x01010101;
1331
1332 pu1_buf = ps_cur_mb_info->ps_curmb->pu1_nnz_y;
1333 pu4_buf = (UWORD32 *)pu1_buf;
1334 *pu4_buf = 0x01010101;
1335
1336 pu1_buf = ps_cur_mb_info->ps_curmb->pu1_nnz_uv;
1337 pu4_buf = (UWORD32 *)pu1_buf;
1338 *pu4_buf = 0x01010101;
1339
1340 pu1_buf = ps_dec->pu1_left_nnz_uv;
1341 pu4_buf = (UWORD32 *)pu1_buf;
1342 *pu4_buf = 0x01010101;
1343
1344 p_curr_ctxt->u1_yuv_dc_csbp = 0x7;
1345 ps_dec->pu1_left_yuv_dc_csbp[0] = 0x7;
1346 if(ps_dec->ps_cur_slice->u1_slice_type != I_SLICE)
1347 {
1348
1349 MEMSET_16BYTES(&ps_dec->pu1_left_mv_ctxt_inc[0][0], 0);
1350 memset(ps_dec->pi1_left_ref_idx_ctxt_inc, 0, 4);
1351 MEMSET_16BYTES(p_curr_ctxt->u1_mv, 0);
1352 memset(p_curr_ctxt->i1_ref_idx, 0, 4);
1353
1354 }
1355 }
1356 return OK;
1357 }
1358
1359 /*!
1360 **************************************************************************
1361 * \if Function name : ih264d_decode_islice \endif
1362 *
1363 * \brief
1364 * Decodes an I Slice
1365 *
1366 *
1367 * \return
1368 * 0 on Success and Error code otherwise
1369 **************************************************************************
1370 */
ih264d_parse_islice(dec_struct_t * ps_dec,UWORD16 u2_first_mb_in_slice)1371 WORD32 ih264d_parse_islice(dec_struct_t *ps_dec,
1372 UWORD16 u2_first_mb_in_slice)
1373 {
1374 dec_pic_params_t * ps_pps = ps_dec->ps_cur_pps;
1375 dec_slice_params_t * ps_slice = ps_dec->ps_cur_slice;
1376 UWORD32 *pu4_bitstrm_buf = ps_dec->ps_bitstrm->pu4_buffer;
1377 UWORD32 *pu4_bitstrm_ofst = &ps_dec->ps_bitstrm->u4_ofst;
1378 UWORD32 u4_temp;
1379 WORD32 i_temp;
1380 WORD32 ret;
1381
1382 /*--------------------------------------------------------------------*/
1383 /* Read remaining contents of the slice header */
1384 /*--------------------------------------------------------------------*/
1385 /* dec_ref_pic_marking function */
1386 /* G050 */
1387 if(ps_slice->u1_nal_ref_idc != 0)
1388 {
1389 if(!ps_dec->ps_dpb_cmds->u1_dpb_commands_read)
1390 {
1391 i_temp = ih264d_read_mmco_commands(ps_dec);
1392 if (i_temp < 0)
1393 {
1394 return ERROR_DBP_MANAGER_T;
1395 }
1396 ps_dec->u4_bitoffset = i_temp;
1397 }
1398 else
1399 ps_dec->ps_bitstrm->u4_ofst += ps_dec->u4_bitoffset;
1400 }
1401 /* G050 */
1402
1403 /* Read slice_qp_delta */
1404 i_temp = ps_pps->u1_pic_init_qp
1405 + ih264d_sev(pu4_bitstrm_ofst, pu4_bitstrm_buf);
1406 if((i_temp < 0) || (i_temp > 51))
1407 return ERROR_INV_RANGE_QP_T;
1408 ps_slice->u1_slice_qp = i_temp;
1409 COPYTHECONTEXT("SH: slice_qp_delta",
1410 ps_slice->u1_slice_qp - ps_pps->u1_pic_init_qp);
1411
1412 if(ps_pps->u1_deblocking_filter_parameters_present_flag == 1)
1413 {
1414 u4_temp = ih264d_uev(pu4_bitstrm_ofst, pu4_bitstrm_buf);
1415 COPYTHECONTEXT("SH: disable_deblocking_filter_idc", u4_temp);
1416
1417 if(u4_temp > SLICE_BOUNDARY_DBLK_DISABLED)
1418 {
1419 return ERROR_INV_SLICE_HDR_T;
1420 }
1421 ps_slice->u1_disable_dblk_filter_idc = u4_temp;
1422 if(u4_temp != 1)
1423 {
1424 i_temp = ih264d_sev(pu4_bitstrm_ofst, pu4_bitstrm_buf)
1425 << 1;
1426 if((MIN_DBLK_FIL_OFF > i_temp) || (i_temp > MAX_DBLK_FIL_OFF))
1427 {
1428 return ERROR_INV_SLICE_HDR_T;
1429 }
1430 ps_slice->i1_slice_alpha_c0_offset = i_temp;
1431 COPYTHECONTEXT("SH: slice_alpha_c0_offset_div2",
1432 ps_slice->i1_slice_alpha_c0_offset >> 1);
1433
1434 i_temp = ih264d_sev(pu4_bitstrm_ofst, pu4_bitstrm_buf)
1435 << 1;
1436 if((MIN_DBLK_FIL_OFF > i_temp) || (i_temp > MAX_DBLK_FIL_OFF))
1437 {
1438 return ERROR_INV_SLICE_HDR_T;
1439 }
1440 ps_slice->i1_slice_beta_offset = i_temp;
1441 COPYTHECONTEXT("SH: slice_beta_offset_div2",
1442 ps_slice->i1_slice_beta_offset >> 1);
1443
1444 }
1445 else
1446 {
1447 ps_slice->i1_slice_alpha_c0_offset = 0;
1448 ps_slice->i1_slice_beta_offset = 0;
1449 }
1450 }
1451 else
1452 {
1453 ps_slice->u1_disable_dblk_filter_idc = 0;
1454 ps_slice->i1_slice_alpha_c0_offset = 0;
1455 ps_slice->i1_slice_beta_offset = 0;
1456 }
1457
1458 /* Initialization to check if number of motion vector per 2 Mbs */
1459 /* are exceeding the range or not */
1460 ps_dec->u2_mv_2mb[0] = 0;
1461 ps_dec->u2_mv_2mb[1] = 0;
1462
1463
1464 /*set slice header cone to 2 ,to indicate correct header*/
1465 ps_dec->u1_slice_header_done = 2;
1466
1467 if(ps_pps->u1_entropy_coding_mode)
1468 {
1469 SWITCHOFFTRACE; SWITCHONTRACECABAC;
1470 if(ps_dec->ps_cur_slice->u1_mbaff_frame_flag)
1471 {
1472 ps_dec->pf_get_mb_info = ih264d_get_mb_info_cabac_mbaff;
1473 }
1474 else
1475 ps_dec->pf_get_mb_info = ih264d_get_mb_info_cabac_nonmbaff;
1476
1477 ret = ih264d_parse_islice_data_cabac(ps_dec, ps_slice,
1478 u2_first_mb_in_slice);
1479 if(ret != OK)
1480 return ret;
1481 SWITCHONTRACE; SWITCHOFFTRACECABAC;
1482 }
1483 else
1484 {
1485 if(ps_dec->ps_cur_slice->u1_mbaff_frame_flag)
1486 {
1487 ps_dec->pf_get_mb_info = ih264d_get_mb_info_cavlc_mbaff;
1488 }
1489 else
1490 ps_dec->pf_get_mb_info = ih264d_get_mb_info_cavlc_nonmbaff;
1491 ret = ih264d_parse_islice_data_cavlc(ps_dec, ps_slice,
1492 u2_first_mb_in_slice);
1493 if(ret != OK)
1494 return ret;
1495 }
1496
1497 return OK;
1498 }
1499