blob: 6b1d4e945d27206e98d9b8399afdb778c9eded7c [file] [log] [blame]
Hamsalekha S8d3d3032015-03-13 21:24:58 +05301/******************************************************************************
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_pslice.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
37#include <string.h>
38#include "ih264d_bitstrm.h"
39#include "ih264d_defs.h"
40#include "ih264d_debug.h"
41#include "ih264d_tables.h"
42#include "ih264d_structs.h"
43#include "ih264d_defs.h"
44#include "ih264d_parse_cavlc.h"
45#include "ih264d_mb_utils.h"
46#include "ih264d_parse_slice.h"
47#include "ih264d_mvpred.h"
48#include "ih264d_parse_islice.h"
49#include "ih264d_process_intra_mb.h"
50#include "ih264d_inter_pred.h"
51#include "ih264d_process_pslice.h"
52#include "ih264d_deblocking.h"
53#include "ih264d_cabac.h"
54#include "ih264d_parse_mb_header.h"
55#include "ih264d_error_handler.h"
56#include "ih264d_defs.h"
57#include "ih264d_format_conv.h"
58#include "ih264d_quant_scaling.h"
59#include "ih264d_thread_parse_decode.h"
Marco Nelissen8ef4c3f2015-06-03 07:26:32 -070060#include "ih264d_thread_compute_bs.h"
Hamsalekha S8d3d3032015-03-13 21:24:58 +053061#include "ih264d_process_bslice.h"
62#include "ithread.h"
63#include "ih264d_utils.h"
64#include "ih264d_format_conv.h"
65
66void ih264d_init_cabac_contexts(UWORD8 u1_slice_type, dec_struct_t * ps_dec);
67void ih264d_deblock_mb_level(dec_struct_t *ps_dec,
68 dec_mb_info_t *ps_cur_mb_info,
69 UWORD32 nmb_index);
70
71/*!
72 **************************************************************************
73 * \if Function name : ih264d_parse_pmb_cavlc \endif
74 *
75 * \brief
76 * This function parses CAVLC syntax of a P MB.
77 *
78 * \return
79 * 0 on Success and Error code otherwise
80 **************************************************************************
81 */
82WORD32 ih264d_parse_pmb_cavlc(dec_struct_t * ps_dec,
83 dec_mb_info_t * ps_cur_mb_info,
84 UWORD8 u1_mb_num,
85 UWORD8 u1_num_mbsNby2)
86{
87 UWORD32 u1_num_mb_part;
88 UWORD32 uc_sub_mb;
89 dec_bit_stream_t * const ps_bitstrm = ps_dec->ps_bitstrm;
90 UWORD32 * const pu4_bitstrm_buf = ps_bitstrm->pu4_buffer;
91 UWORD32 *pu4_bitstrm_ofst = &ps_bitstrm->u4_ofst;
92
93 parse_pmbarams_t * ps_parse_mb_data = ps_dec->ps_parse_mb_data
94 + u1_num_mbsNby2;
95 WORD8 * pi1_ref_idx = ps_parse_mb_data->i1_ref_idx[0];
96 const UWORD8 u1_mbaff = ps_dec->ps_cur_slice->u1_mbaff_frame_flag;
97 const UWORD8 * pu1_num_mb_part = (const UWORD8 *)gau1_ih264d_num_mb_part;
98 UWORD8 * pu1_col_info = ps_parse_mb_data->u1_col_info;
99
100 UWORD32 u1_mb_type = ps_cur_mb_info->u1_mb_type;
101 UWORD32 u4_sum_mb_mode_pack = 0;
102 WORD32 ret;
103
104 UWORD8 u1_no_submb_part_size_lt8x8_flag = 1;
105 ps_cur_mb_info->u1_tran_form8x8 = 0;
106 ps_cur_mb_info->ps_curmb->u1_tran_form8x8 = 0;
107
108 ps_cur_mb_info->u1_yuv_dc_block_flag = 0;
109
110 ps_cur_mb_info->u1_mb_mc_mode = u1_mb_type;
111 uc_sub_mb = ((u1_mb_type == PRED_8x8) | (u1_mb_type == PRED_8x8R0));
112
113 /* Reading the subMB type */
114 if(uc_sub_mb)
115 {
116 WORD32 i;
117 UWORD8 u1_colz = (PRED_8x8 << 6);
118
119 for(i = 0; i < 4; i++)
120 {
121 UWORD32 ui_sub_mb_mode;
122
123 //Inlined ih264d_uev
124 UWORD32 u4_bitstream_offset = *pu4_bitstrm_ofst;
125 UWORD32 u4_word, u4_ldz;
126
127 /***************************************************************/
128 /* Find leading zeros in next 32 bits */
129 /***************************************************************/
130 NEXTBITS_32(u4_word, u4_bitstream_offset, pu4_bitstrm_buf);
131 u4_ldz = CLZ(u4_word);
132 /* Flush the ps_bitstrm */
133 u4_bitstream_offset += (u4_ldz + 1);
134 /* Read the suffix from the ps_bitstrm */
135 u4_word = 0;
136 if(u4_ldz)
137 GETBITS(u4_word, u4_bitstream_offset, pu4_bitstrm_buf,
138 u4_ldz);
139 *pu4_bitstrm_ofst = u4_bitstream_offset;
140 ui_sub_mb_mode = ((1 << u4_ldz) + u4_word - 1);
141 //Inlined ih264d_uev
142
143 if(ui_sub_mb_mode > 3)
144 {
145 return ERROR_SUB_MB_TYPE;
146 }
147 else
148 {
149 u4_sum_mb_mode_pack = (u4_sum_mb_mode_pack << 8) | ui_sub_mb_mode;
150 /* Storing collocated information */
151 *pu1_col_info++ = u1_colz | (UWORD8)(ui_sub_mb_mode << 4);
152
153 COPYTHECONTEXT("sub_mb_type", ui_sub_mb_mode);
154 }
155
156 /* check if Motion compensation is done below 8x8 */
157 if(ui_sub_mb_mode != P_L0_8x8)
158 {
159 u1_no_submb_part_size_lt8x8_flag = 0;
160 }
161 }
162
163 //
164 u1_num_mb_part = 4;
165 }
166 else
167 {
168 *pu1_col_info++ = (u1_mb_type << 6);
169 if(u1_mb_type)
170 *pu1_col_info++ = (u1_mb_type << 6);
171 u1_num_mb_part = pu1_num_mb_part[u1_mb_type];
172
173 }
174
175 /* Decoding reference index 0: For simple profile the following */
176 /* conditions are always true (mb_field_decoding_flag == 0); */
177 /* (MbPartPredMode != PredL1) */
178
179 {
180
181 UWORD8 uc_field = ps_cur_mb_info->u1_mb_field_decodingflag;
182 UWORD8 uc_num_ref_idx_l0_active_minus1 =
183 (ps_dec->ps_cur_slice->u1_num_ref_idx_lx_active[0]
184 << (u1_mbaff & uc_field)) - 1;
185
186 if((uc_num_ref_idx_l0_active_minus1 > 0) & (u1_mb_type != PRED_8x8R0))
187 {
188 if(1 == uc_num_ref_idx_l0_active_minus1)
189 ih264d_parse_pmb_ref_index_cavlc_range1(
190 u1_num_mb_part, ps_bitstrm, pi1_ref_idx,
191 uc_num_ref_idx_l0_active_minus1);
192 else
193 {
194 ret = ih264d_parse_pmb_ref_index_cavlc(
195 u1_num_mb_part, ps_bitstrm, pi1_ref_idx,
196 uc_num_ref_idx_l0_active_minus1);
197 if(ret != OK)
198 return ret;
199 }
200 }
201 else
202 {
203 /* When there exists only a single frame to predict from */
204 UWORD8 uc_i;
205 for(uc_i = 0; uc_i < u1_num_mb_part; uc_i++)
206 /* Storing Reference Idx Information */
207 pi1_ref_idx[uc_i] = 0;
208 }
209 }
210
211 {
212 UWORD8 u1_p_idx, uc_i;
213 parse_part_params_t * ps_part = ps_dec->ps_part;
214 UWORD8 u1_sub_mb_mode, u1_num_subpart, u1_mb_part_width, u1_mb_part_height;
215 UWORD8 u1_sub_mb_num;
216 const UWORD8 * pu1_top_left_sub_mb_indx;
217 mv_pred_t * ps_mv, *ps_mv_start = ps_dec->ps_mv_cur + (u1_mb_num << 4);
218 /* Loading the table pointers */
219 const UWORD8 * pu1_mb_partw = (const UWORD8 *)gau1_ih264d_mb_partw;
220 const UWORD8 * pu1_mb_parth = (const UWORD8 *)gau1_ih264d_mb_parth;
221 const UWORD8 * pu1_sub_mb_indx_mod =
222 (const UWORD8 *)(gau1_ih264d_submb_indx_mod)
223 + (uc_sub_mb * 6);
224 const UWORD8 * pu1_sub_mb_partw = (const UWORD8 *)gau1_ih264d_submb_partw;
225 const UWORD8 * pu1_sub_mb_parth = (const UWORD8 *)gau1_ih264d_submb_parth;
226 const UWORD8 * pu1_num_sub_mb_part =
227 (const UWORD8 *)gau1_ih264d_num_submb_part;
228
229 UWORD16 u2_sub_mb_num = 0x028A;
230
231 /*********************************************************/
232 /* default initialisations for condition (uc_sub_mb == 0) */
233 /* i.e. all are subpartitions of 8x8 */
234 /*********************************************************/
235 u1_sub_mb_mode = 0;
236 u1_num_subpart = 1;
237 u1_mb_part_width = pu1_mb_partw[u1_mb_type];
238 u1_mb_part_height = pu1_mb_parth[u1_mb_type];
239 pu1_top_left_sub_mb_indx = pu1_sub_mb_indx_mod + (u1_mb_type << 1);
240 u1_sub_mb_num = 0;
241
242 /* Loop on number of partitions */
243 for(uc_i = 0, u1_p_idx = 0; uc_i < u1_num_mb_part; uc_i++)
244 {
245 UWORD8 uc_j;
246 if(uc_sub_mb)
247 {
248 u1_sub_mb_mode = u4_sum_mb_mode_pack >> 24;
249 u1_num_subpart = pu1_num_sub_mb_part[u1_sub_mb_mode];
250 u1_mb_part_width = pu1_sub_mb_partw[u1_sub_mb_mode];
251 u1_mb_part_height = pu1_sub_mb_parth[u1_sub_mb_mode];
252 pu1_top_left_sub_mb_indx = pu1_sub_mb_indx_mod + (u1_sub_mb_mode << 1);
253 u1_sub_mb_num = u2_sub_mb_num >> 12;
254 u4_sum_mb_mode_pack <<= 8;
255 u2_sub_mb_num <<= 4;
256 }
257
258 /* Loop on Number of sub-partitions */
259 for(uc_j = 0; uc_j < u1_num_subpart; uc_j++, pu1_top_left_sub_mb_indx++)
260 {
261 WORD16 i2_mvx, i2_mvy;
262 u1_sub_mb_num += *pu1_top_left_sub_mb_indx;
263 ps_mv = ps_mv_start + u1_sub_mb_num;
264
265 /* Reading the differential Mv from the bitstream */
266 //i2_mvx = ih264d_sev(pu4_bitstrm_ofst, pu4_bitstrm_buf);
267 //inlining ih264d_sev
268 {
269 UWORD32 u4_bitstream_offset = *pu4_bitstrm_ofst;
270 UWORD32 u4_word, u4_ldz, u4_abs_val;
271
272 /***************************************************************/
273 /* Find leading zeros in next 32 bits */
274 /***************************************************************/
275 NEXTBITS_32(u4_word, u4_bitstream_offset,
276 pu4_bitstrm_buf);
277 u4_ldz = CLZ(u4_word);
278
279 /* Flush the ps_bitstrm */
280 u4_bitstream_offset += (u4_ldz + 1);
281
282 /* Read the suffix from the ps_bitstrm */
283 u4_word = 0;
284 if(u4_ldz)
285 GETBITS(u4_word, u4_bitstream_offset,
286 pu4_bitstrm_buf, u4_ldz);
287
288 *pu4_bitstrm_ofst = u4_bitstream_offset;
289 u4_abs_val = ((1 << u4_ldz) + u4_word) >> 1;
290
291 if(u4_word & 0x1)
292 i2_mvx = (-(WORD32)u4_abs_val);
293 else
294 i2_mvx = (u4_abs_val);
295 }
296 //inlinined ih264d_sev
297 COPYTHECONTEXT("MVD", i2_mvx);
298 i2_mvy = ih264d_sev(pu4_bitstrm_ofst,
299 pu4_bitstrm_buf);
300 COPYTHECONTEXT("MVD", i2_mvy);
301
302 /* Storing Info for partitions */
303 ps_part->u1_is_direct = PART_NOT_DIRECT;
304 ps_part->u1_sub_mb_num = u1_sub_mb_num;
305 ps_part->u1_partheight = u1_mb_part_height;
306 ps_part->u1_partwidth = u1_mb_part_width;
307
308 /* Storing Mv residuals */
309 ps_mv->i2_mv[0] = i2_mvx;
310 ps_mv->i2_mv[1] = i2_mvy;
311
312 /* Increment partition Index */
313 u1_p_idx++;
314 ps_part++;
315 }
316 }
317 ps_parse_mb_data->u1_num_part = u1_p_idx;
318 ps_dec->ps_part = ps_part;
319 }
320
321 {
322 UWORD32 u4_cbp;
323
324 /* Read the Coded block pattern */
325 UWORD32 u4_bitstream_offset = *pu4_bitstrm_ofst;
326 UWORD32 u4_word, u4_ldz;
327
328 /***************************************************************/
329 /* Find leading zeros in next 32 bits */
330 /***************************************************************/
331 NEXTBITS_32(u4_word, u4_bitstream_offset, pu4_bitstrm_buf);
332 u4_ldz = CLZ(u4_word);
333 /* Flush the ps_bitstrm */
334 u4_bitstream_offset += (u4_ldz + 1);
335 /* Read the suffix from the ps_bitstrm */
336 u4_word = 0;
337 if(u4_ldz)
338 GETBITS(u4_word, u4_bitstream_offset, pu4_bitstrm_buf, u4_ldz);
339 *pu4_bitstrm_ofst = u4_bitstream_offset;
340 u4_cbp = ((1 << u4_ldz) + u4_word - 1);
341
342 if(u4_cbp > 47)
343 return ERROR_CBP;
344
345 u4_cbp = *((UWORD8*)gau1_ih264d_cbp_inter + u4_cbp);
346 COPYTHECONTEXT("coded_block_pattern", u4_cbp);
347 ps_cur_mb_info->u1_cbp = u4_cbp;
348
349 /* Read the transform8x8 u4_flag if present */
350 if((ps_dec->s_high_profile.u1_transform8x8_present) && (u4_cbp & 0xf)
351 && u1_no_submb_part_size_lt8x8_flag)
352 {
353 ps_cur_mb_info->u1_tran_form8x8 = ih264d_get_bit_h264(ps_bitstrm);
354 COPYTHECONTEXT("transform_size_8x8_flag", ps_cur_mb_info->u1_tran_form8x8);
355 ps_cur_mb_info->ps_curmb->u1_tran_form8x8 = ps_cur_mb_info->u1_tran_form8x8;
356 }
357
358 /* Read mb_qp_delta */
359 if(u4_cbp)
360 {
361 WORD32 i_temp;
362
363 UWORD32 u4_bitstream_offset = *pu4_bitstrm_ofst;
364 UWORD32 u4_word, u4_ldz, u4_abs_val;
365
366 /***************************************************************/
367 /* Find leading zeros in next 32 bits */
368 /***************************************************************/
369 NEXTBITS_32(u4_word, u4_bitstream_offset, pu4_bitstrm_buf);
370 u4_ldz = CLZ(u4_word);
371
372 /* Flush the ps_bitstrm */
373 u4_bitstream_offset += (u4_ldz + 1);
374
375 /* Read the suffix from the ps_bitstrm */
376 u4_word = 0;
377 if(u4_ldz)
378 GETBITS(u4_word, u4_bitstream_offset, pu4_bitstrm_buf,
379 u4_ldz);
380
381 *pu4_bitstrm_ofst = u4_bitstream_offset;
382 u4_abs_val = ((1 << u4_ldz) + u4_word) >> 1;
383
384 if(u4_word & 0x1)
385 i_temp = (-(WORD32)u4_abs_val);
386 else
387 i_temp = (u4_abs_val);
388
389 if((i_temp < -26) || (i_temp > 25))
390 return ERROR_INV_RANGE_QP_T;
391 //inlinined ih264d_sev
392
393 COPYTHECONTEXT("mb_qp_delta", i_temp);
394 if(i_temp)
395 {
396 ret = ih264d_update_qp(ps_dec, (WORD8)i_temp);
397 if(ret != OK)
398 return ret;
399 }
400
401 ret = ih264d_parse_residual4x4_cavlc(ps_dec, ps_cur_mb_info, 0);
402 if(ret != OK)
403 return ret;
404 if(EXCEED_OFFSET(ps_bitstrm))
405 return ERROR_EOB_TERMINATE_T;
406 }
407 else
408 {
409 ih264d_update_nnz_for_skipmb(ps_dec, ps_cur_mb_info, CAVLC);
410 }
411
412
413
414 }
415
416 return OK;
417}
418
419/*!
420 **************************************************************************
421 * \if Function name : ih264d_parse_pmb_cabac \endif
422 *
423 * \brief
424 * This function parses CABAC syntax of a P MB.
425 *
426 * \return
427 * 0 on Success and Error code otherwise
428 **************************************************************************
429 */
430WORD32 ih264d_parse_pmb_cabac(dec_struct_t * ps_dec,
431 dec_mb_info_t * ps_cur_mb_info,
432 UWORD8 u1_mb_num,
433 UWORD8 u1_num_mbsNby2)
434{
435 UWORD32 u1_num_mb_part;
436 UWORD32 uc_sub_mb;
437 parse_pmbarams_t * ps_parse_mb_data = ps_dec->ps_parse_mb_data
438 + u1_num_mbsNby2;
439 WORD8 * pi1_ref_idx = ps_parse_mb_data->i1_ref_idx[0];
440 const UWORD8 * pu1_num_mb_part = (const UWORD8 *)gau1_ih264d_num_mb_part;
441 const UWORD32 u1_mb_type = ps_cur_mb_info->u1_mb_type;
442 UWORD8 * pu1_col_info = ps_parse_mb_data->u1_col_info;
443 UWORD32 u1_mb_mc_mode = u1_mb_type;
444 ctxt_inc_mb_info_t * p_curr_ctxt = ps_dec->ps_curr_ctxt_mb_info;
445 decoding_envirnoment_t * ps_cab_env = &ps_dec->s_cab_dec_env;
446 dec_bit_stream_t * ps_bitstrm = ps_dec->ps_bitstrm;
447 UWORD32 u4_sub_mb_pack = 0;
448 WORD32 ret;
449
450 UWORD8 u1_no_submb_part_size_lt8x8_flag = 1;
451 ps_cur_mb_info->u1_tran_form8x8 = 0;
452 ps_cur_mb_info->ps_curmb->u1_tran_form8x8 = 0;
453
454 ps_cur_mb_info->u1_yuv_dc_block_flag = 0;
455
456 p_curr_ctxt->u1_mb_type = CAB_P;
457 ps_cur_mb_info->u1_mb_mc_mode = u1_mb_type;
458 uc_sub_mb = ((u1_mb_type == PRED_8x8) | (u1_mb_type == PRED_8x8R0));
459
460 /* Reading the subMB type */
461 if(uc_sub_mb)
462 {
463
464 UWORD8 u1_colz = (PRED_8x8 << 6);
465 u1_mb_mc_mode = 0;
466
467 {
468 UWORD8 u1_sub_mb_mode;
469 u1_sub_mb_mode = ih264d_parse_submb_type_cabac(
470 0, ps_cab_env, ps_bitstrm,
471 ps_dec->p_sub_mb_type_t);
472 if(u1_sub_mb_mode > 3)
473 return ERROR_SUB_MB_TYPE;
474
475 u4_sub_mb_pack = (u4_sub_mb_pack << 8) | u1_sub_mb_mode;
476 /* Storing collocated information */
477 *pu1_col_info++ = u1_colz | ((UWORD8)(u1_sub_mb_mode << 4));
478 COPYTHECONTEXT("sub_mb_type", u1_sub_mb_mode);
479 /* check if Motion compensation is done below 8x8 */
480 if(u1_sub_mb_mode != P_L0_8x8)
481 {
482 u1_no_submb_part_size_lt8x8_flag = 0;
483 }
484 }
485 {
486 UWORD8 u1_sub_mb_mode;
487 u1_sub_mb_mode = ih264d_parse_submb_type_cabac(
488 0, ps_cab_env, ps_bitstrm,
489 ps_dec->p_sub_mb_type_t);
490 if(u1_sub_mb_mode > 3)
491 return ERROR_SUB_MB_TYPE;
492
493 u4_sub_mb_pack = (u4_sub_mb_pack << 8) | u1_sub_mb_mode;
494 /* Storing collocated information */
495 *pu1_col_info++ = u1_colz | ((UWORD8)(u1_sub_mb_mode << 4));
496 COPYTHECONTEXT("sub_mb_type", u1_sub_mb_mode);
497 /* check if Motion compensation is done below 8x8 */
498 if(u1_sub_mb_mode != P_L0_8x8)
499 {
500 u1_no_submb_part_size_lt8x8_flag = 0;
501 }
502 }
503 {
504 UWORD8 u1_sub_mb_mode;
505 u1_sub_mb_mode = ih264d_parse_submb_type_cabac(
506 0, ps_cab_env, ps_bitstrm,
507 ps_dec->p_sub_mb_type_t);
508 if(u1_sub_mb_mode > 3)
509 return ERROR_SUB_MB_TYPE;
510
511 u4_sub_mb_pack = (u4_sub_mb_pack << 8) | u1_sub_mb_mode;
512 /* Storing collocated information */
513 *pu1_col_info++ = u1_colz | ((UWORD8)(u1_sub_mb_mode << 4));
514 COPYTHECONTEXT("sub_mb_type", u1_sub_mb_mode);
515 /* check if Motion compensation is done below 8x8 */
516 if(u1_sub_mb_mode != P_L0_8x8)
517 {
518 u1_no_submb_part_size_lt8x8_flag = 0;
519 }
520 }
521 {
522 UWORD8 u1_sub_mb_mode;
523 u1_sub_mb_mode = ih264d_parse_submb_type_cabac(
524 0, ps_cab_env, ps_bitstrm,
525 ps_dec->p_sub_mb_type_t);
526 if(u1_sub_mb_mode > 3)
527 return ERROR_SUB_MB_TYPE;
528
529 u4_sub_mb_pack = (u4_sub_mb_pack << 8) | u1_sub_mb_mode;
530 /* Storing collocated information */
531 *pu1_col_info++ = u1_colz | ((UWORD8)(u1_sub_mb_mode << 4));
532 COPYTHECONTEXT("sub_mb_type", u1_sub_mb_mode);
533 /* check if Motion compensation is done below 8x8 */
534 if(u1_sub_mb_mode != P_L0_8x8)
535 {
536 u1_no_submb_part_size_lt8x8_flag = 0;
537 }
538 }
539 u1_num_mb_part = 4;
540 }
541 else
542 {
543 u1_num_mb_part = pu1_num_mb_part[u1_mb_type];
544 /* Storing collocated Mb and SubMb mode information */
545 *pu1_col_info++ = (u1_mb_type << 6);
546 if(u1_mb_type)
547 *pu1_col_info++ = (u1_mb_type << 6);
548 }
549 /* Decoding reference index 0: For simple profile the following */
550 /* conditions are always true (mb_field_decoding_flag == 0); */
551 /* (MbPartPredMode != PredL1) */
552 {
553 WORD8 * pi1_top_ref_idx_ctx_inc_arr = p_curr_ctxt->i1_ref_idx;
554 WORD8 * pi1_left_ref_idx_ctxt_inc = ps_dec->pi1_left_ref_idx_ctxt_inc;
555 UWORD8 u1_mbaff = ps_dec->ps_cur_slice->u1_mbaff_frame_flag;
556 UWORD8 uc_field = ps_cur_mb_info->u1_mb_field_decodingflag;
557 UWORD8 uc_num_ref_idx_l0_active_minus1 =
558 (ps_dec->ps_cur_slice->u1_num_ref_idx_lx_active[0]
559 << (u1_mbaff & uc_field)) - 1;
560
561 if((uc_num_ref_idx_l0_active_minus1 > 0) & (u1_mb_type != PRED_8x8R0))
562 {
563 /* force the routine to decode ref idx for each partition */
564 *((UWORD32 *)pi1_ref_idx) = 0x01010101;
565 ret = ih264d_parse_ref_idx_cabac(u1_num_mb_part, 0,
566 uc_num_ref_idx_l0_active_minus1,
567 u1_mb_mc_mode, pi1_ref_idx,
568 pi1_left_ref_idx_ctxt_inc,
569 pi1_top_ref_idx_ctx_inc_arr, ps_cab_env,
570 ps_bitstrm, ps_dec->p_ref_idx_t);
571 if(ret != OK)
572 return ret;
573 }
574 else
575 {
576 /* When there exists only a single frame to predict from */
577 pi1_left_ref_idx_ctxt_inc[0] = 0;
578 pi1_left_ref_idx_ctxt_inc[1] = 0;
579 pi1_top_ref_idx_ctx_inc_arr[0] = 0;
580 pi1_top_ref_idx_ctx_inc_arr[1] = 0;
581 *((UWORD32 *)pi1_ref_idx) = 0;
582 }
583 }
584
585 {
586 UWORD8 u1_p_idx, uc_i;
587 parse_part_params_t * ps_part = ps_dec->ps_part;
588 UWORD8 u1_sub_mb_mode, u1_num_subpart, u1_mb_part_width, u1_mb_part_height;
589 UWORD8 u1_sub_mb_num;
590 const UWORD8 * pu1_top_left_sub_mb_indx;
591 mv_pred_t *ps_mv_start = ps_dec->ps_mv_cur + (u1_mb_num << 4);
592 UWORD16 u2_sub_mb_num_pack = 0x028A;
593
594 /* Loading the table pointers */
595 const UWORD8 * pu1_mb_partw = (const UWORD8 *)gau1_ih264d_mb_partw;
596 const UWORD8 * pu1_mb_parth = (const UWORD8 *)gau1_ih264d_mb_parth;
597 const UWORD8 * pu1_sub_mb_indx_mod =
598 (const UWORD8 *)(gau1_ih264d_submb_indx_mod)
599 + (uc_sub_mb * 6);
600 const UWORD8 * pu1_sub_mb_partw = (const UWORD8 *)gau1_ih264d_submb_partw;
601 const UWORD8 * pu1_sub_mb_parth = (const UWORD8 *)gau1_ih264d_submb_parth;
602 const UWORD8 * pu1_num_sub_mb_part =
603 (const UWORD8 *)gau1_ih264d_num_submb_part;
604
605 /*********************************************************/
606 /* default initialisations for condition (uc_sub_mb == 0) */
607 /* i.e. all are subpartitions of 8x8 */
608 /*********************************************************/
609 u1_sub_mb_mode = 0;
610 u1_num_subpart = 1;
611 u1_mb_part_width = pu1_mb_partw[u1_mb_type];
612 u1_mb_part_height = pu1_mb_parth[u1_mb_type];
613 pu1_top_left_sub_mb_indx = pu1_sub_mb_indx_mod + (u1_mb_type << 1);
614 u1_sub_mb_num = 0;
615
616 /* Loop on number of partitions */
617 for(uc_i = 0, u1_p_idx = 0; uc_i < u1_num_mb_part; uc_i++)
618 {
619 UWORD8 uc_j;
620 if(uc_sub_mb)
621 {
622 u1_sub_mb_mode = u4_sub_mb_pack >> 24;
623 u1_num_subpart = pu1_num_sub_mb_part[u1_sub_mb_mode];
624 u1_mb_part_width = pu1_sub_mb_partw[u1_sub_mb_mode];
625 u1_mb_part_height = pu1_sub_mb_parth[u1_sub_mb_mode];
626 pu1_top_left_sub_mb_indx = pu1_sub_mb_indx_mod + (u1_sub_mb_mode << 1);
627 u1_sub_mb_num = u2_sub_mb_num_pack >> 12;
628 u4_sub_mb_pack <<= 8;
629 u2_sub_mb_num_pack <<= 4;
630 }
631 /* Loop on Number of sub-partitions */
632 for(uc_j = 0; uc_j < u1_num_subpart; uc_j++, pu1_top_left_sub_mb_indx++)
633 {
634 mv_pred_t * ps_mv;
635
636 u1_sub_mb_num += *pu1_top_left_sub_mb_indx;
637 ps_mv = ps_mv_start + u1_sub_mb_num;
638
639 /* Storing Info for partitions */
640 ps_part->u1_is_direct = PART_NOT_DIRECT;
641 ps_part->u1_sub_mb_num = u1_sub_mb_num;
642 ps_part->u1_partheight = u1_mb_part_height;
643 ps_part->u1_partwidth = u1_mb_part_width;
644
645 /* Increment partition Index */
646 u1_p_idx++;
647 ps_part++;
648
649 ih264d_get_mvd_cabac(u1_sub_mb_num, 0, u1_mb_part_width,
650 u1_mb_part_height, 1, ps_dec, ps_mv);
651 }
652 }
653 ps_parse_mb_data->u1_num_part = u1_p_idx;
654 ps_dec->ps_part = ps_part;
655 }
656 {
657 UWORD8 u1_cbp;
658
659 /* Read the Coded block pattern */
660 u1_cbp = (WORD8)ih264d_parse_ctx_cbp_cabac(ps_dec);
661 COPYTHECONTEXT("coded_block_pattern", u1_cbp);
662 ps_cur_mb_info->u1_cbp = u1_cbp;
663 p_curr_ctxt->u1_cbp = u1_cbp;
664 p_curr_ctxt->u1_intra_chroma_pred_mode = 0;
665 p_curr_ctxt->u1_yuv_dc_csbp &= 0xFE;
666 ps_dec->pu1_left_yuv_dc_csbp[0] &= 0x6;
667
668 if(u1_cbp > 47)
669 return ERROR_CBP;
670
671 ps_cur_mb_info->u1_tran_form8x8 = 0;
672 ps_cur_mb_info->ps_curmb->u1_tran_form8x8 = 0;
673
674 /* Read the transform8x8 u4_flag if present */
675 if((ps_dec->s_high_profile.u1_transform8x8_present) && (u1_cbp & 0xf)
676 && u1_no_submb_part_size_lt8x8_flag)
677 {
678 ps_cur_mb_info->u1_tran_form8x8 = ih264d_parse_transform8x8flag_cabac(
679 ps_dec, ps_cur_mb_info);
680 COPYTHECONTEXT("transform_size_8x8_flag", ps_cur_mb_info->u1_tran_form8x8);
681 p_curr_ctxt->u1_transform8x8_ctxt = ps_cur_mb_info->u1_tran_form8x8;
682 ps_cur_mb_info->ps_curmb->u1_tran_form8x8 = ps_cur_mb_info->u1_tran_form8x8;
683
684 }
685 else
686 {
687 p_curr_ctxt->u1_transform8x8_ctxt = 0;
688 }
689
690 /* Read mb_qp_delta */
691 if(u1_cbp)
692 {
693 WORD8 c_temp;
694 ret = ih264d_parse_mb_qp_delta_cabac(ps_dec, &c_temp);
695 if(ret != OK)
696 return ret;
697 COPYTHECONTEXT("mb_qp_delta", c_temp);
698 if(c_temp != 0)
699 {
700 ret = ih264d_update_qp(ps_dec, c_temp);
701 if(ret != OK)
702 return ret;
703 }
704 }
705 else
706 ps_dec->i1_prev_mb_qp_delta = 0;
707
708
709
710 ih264d_parse_residual4x4_cabac(ps_dec, ps_cur_mb_info, 0);
711 if(EXCEED_OFFSET(ps_dec->ps_bitstrm))
712 return ERROR_EOB_TERMINATE_T;
713 }
714 return OK;
715}
716
717/*!
718 **************************************************************************
719 * \if Function name : parsePSliceData \endif
720 *
721 * \brief
722 * This function parses CAVLC syntax of N MB's of a P slice.
723 * 1. After parsing syntax of N MB's, for those N MB's (less than N, incase
724 * of end of slice or end of row), MB is decoded. This process is carried
725 * for one complete MB row or till end of slice.
726 * 2. Bottom one row of current MB is copied to IntraPredLine buffers.
727 * IntraPredLine buffers are used for Intra prediction of next row.
728 * 3. Current MB row along with previous 4 rows of Luma (and 2 of Chroma) are
729 * deblocked.
730 * 4. 4 rows (2 for Chroma) previous row and 12 rows (6 for Chroma) are
731 * DMA'ed to picture buffers.
732 *
733 * \return
734 * 0 on Success and Error code otherwise
735 **************************************************************************
736 */
737
738/*!
739 **************************************************************************
740 * \if Function name : ih264d_update_nnz_for_skipmb \endif
741 *
742 * \brief
743 *
744 * \return
745 * None
746 *
747 **************************************************************************
748 */
749void ih264d_update_nnz_for_skipmb(dec_struct_t * ps_dec,
750 dec_mb_info_t * ps_cur_mb_info,
751 UWORD8 u1_entrpy)
752{
753 UWORD32 *pu4_buf;
754 UWORD8 *pu1_buf;
755 UNUSED(u1_entrpy);
756 pu1_buf = ps_dec->pu1_left_nnz_y;
757 pu4_buf = (UWORD32 *)pu1_buf;
758 *pu4_buf = 0;
759 pu1_buf = ps_dec->pu1_left_nnz_uv;
760 pu4_buf = (UWORD32 *)pu1_buf;
761 *pu4_buf = 0;
762 pu1_buf = ps_cur_mb_info->ps_curmb->pu1_nnz_y;
763 pu4_buf = (UWORD32 *)pu1_buf;
764 *pu4_buf = 0;
765 pu1_buf = ps_cur_mb_info->ps_curmb->pu1_nnz_uv;
766 pu4_buf = (UWORD32 *)pu1_buf;
767 *pu4_buf = 0;
768 ps_cur_mb_info->ps_curmb->u2_luma_csbp = 0;
769 ps_cur_mb_info->u2_luma_csbp = 0;
770 ps_cur_mb_info->u2_chroma_csbp = 0;
771}
772
773
774
775/*****************************************************************************/
776/* */
777/* Function Name : ih264d_parse_inter_slice_data_cabac */
778/* */
779/* Description : This function parses cabac syntax of a inter slice on */
780/* N MB basis. */
781/* */
782/* Inputs : ps_dec */
783/* sliceparams */
784/* firstMbInSlice */
785/* */
786/* Processing : 1. After parsing syntax for N MBs those N MBs are */
787/* decoded till the end of slice. */
788/* 2. MV prediction and DMA happens on a N/2 MB basis. */
789/* */
790/* Returns : 0 */
791/* */
792/* Issues : <List any issues or problems with this function> */
793/* */
794/* Revision History: */
795/* */
796/* DD MM YYYY Author(s) Changes (Describe the changes made) */
797/* 13 07 2002 Jay Draft */
798/* */
799/*****************************************************************************/
800WORD32 ih264d_parse_inter_slice_data_cabac(dec_struct_t * ps_dec,
801 dec_slice_params_t * ps_slice,
802 UWORD16 u2_first_mb_in_slice)
803{
804 UWORD32 uc_more_data_flag;
805 WORD32 i2_cur_mb_addr;
806 UWORD32 u1_num_mbs, u1_num_mbsNby2, u1_mb_idx;
807 UWORD32 u1_mbaff;
808 UWORD32 u1_num_mbs_next, u1_end_of_row;
809 const UWORD16 i2_pic_wdin_mbs = ps_dec->u2_frm_wd_in_mbs;
810 UWORD32 u1_slice_end = 0;
811 UWORD32 u1_tfr_n_mb = 0;
812 UWORD32 u1_decode_nmb = 0;
813
814
815 deblk_mb_t *ps_cur_deblk_mb;
816 dec_mb_info_t *ps_cur_mb_info;
817
818 parse_pmbarams_t *ps_parse_mb_data = ps_dec->ps_parse_mb_data;
819 UWORD32 u1_inter_mb_skip_type;
820 UWORD32 u1_inter_mb_type;
821 UWORD32 u1_deblk_mb_type;
822 UWORD32 u1_mb_threshold;
823 dec_bit_stream_t * const ps_bitstrm = ps_dec->ps_bitstrm;
Marco Nelissen8ef4c3f2015-06-03 07:26:32 -0700824 WORD32 ret = OK;
Hamsalekha S8d3d3032015-03-13 21:24:58 +0530825
826 /******************************************************/
827 /* Initialisations specific to B or P slice */
828 /******************************************************/
829 if(ps_slice->u1_slice_type == P_SLICE)
830 {
831 u1_inter_mb_skip_type = CAB_P_SKIP;
832 u1_inter_mb_type = P_MB;
833 u1_deblk_mb_type = D_INTER_MB;
834 u1_mb_threshold = 5;
835 }
836 else // B_SLICE
837 {
838 u1_inter_mb_skip_type = CAB_B_SKIP;
839 u1_inter_mb_type = B_MB;
840 u1_deblk_mb_type = D_B_SLICE;
841 u1_mb_threshold = 23;
842 }
843
844 /******************************************************/
845 /* Slice Level Initialisations */
846 /******************************************************/
847 i2_cur_mb_addr = u2_first_mb_in_slice;
848 ps_dec->u1_qp = ps_slice->u1_slice_qp;
Marco Nelissen8ef4c3f2015-06-03 07:26:32 -0700849 ih264d_update_qp(ps_dec, 0);
Hamsalekha S8d3d3032015-03-13 21:24:58 +0530850 u1_mb_idx = ps_dec->u1_mb_idx;
851 u1_num_mbs = u1_mb_idx;
852 u1_num_mbsNby2 = 0;
853 u1_mbaff = ps_slice->u1_mbaff_frame_flag;
854 i2_cur_mb_addr = u2_first_mb_in_slice << u1_mbaff;
855 uc_more_data_flag = 1;
856
857 /* Initialisations specific to cabac */
858 if(ps_bitstrm->u4_ofst & 0x07)
859 {
860 ps_bitstrm->u4_ofst += 8;
861 ps_bitstrm->u4_ofst &= 0xFFFFFFF8;
862 }
863
864 ret = ih264d_init_cabac_dec_envirnoment(&(ps_dec->s_cab_dec_env), ps_bitstrm);
865 if(ret != OK)
866 return ret;
867
868 ps_dec->i1_prev_mb_qp_delta = 0;
869
870 while(!u1_slice_end)
871 {
872 UWORD8 u1_mb_type;
873 UWORD32 u4_mb_skip;
874
Marco Nelissen8ef4c3f2015-06-03 07:26:32 -0700875 ps_dec->pv_prev_mb_parse_tu_coeff_data = ps_dec->pv_parse_tu_coeff_data;
876
877 if(i2_cur_mb_addr > ps_dec->ps_cur_sps->u2_max_mb_addr)
878 {
879 ret = ERROR_MB_ADDRESS_T;
880 break;
881 }
Hamsalekha S8d3d3032015-03-13 21:24:58 +0530882
883 ps_cur_mb_info = ps_dec->ps_nmb_info + u1_num_mbs;
Marco Nelissen8ef4c3f2015-06-03 07:26:32 -0700884 ps_dec->u4_num_mbs_cur_nmb = u1_num_mbs;
Hamsalekha S8d3d3032015-03-13 21:24:58 +0530885
886 ps_cur_mb_info->u1_Mux = 0;
887 ps_dec->u4_num_pmbair = (u1_num_mbs >> u1_mbaff);
888 ps_cur_deblk_mb = ps_dec->ps_deblk_mbn + u1_num_mbs;
889
890 ps_cur_mb_info->u1_end_of_slice = 0;
891
892 /* Storing Default partition info */
893 ps_parse_mb_data->u1_num_part = 1;
894 ps_parse_mb_data->u1_isI_mb = 0;
895
896 /***************************************************************/
897 /* Get the required information for decoding of MB */
898 /* mb_x, mb_y , neighbour availablity, */
899 /***************************************************************/
900 u4_mb_skip = ps_dec->pf_get_mb_info(ps_dec, i2_cur_mb_addr, ps_cur_mb_info, 1);
901
902 /*********************************************************************/
903 /* initialize u1_tran_form8x8 to zero to aviod uninitialized accesses */
904 /*********************************************************************/
905 ps_cur_mb_info->u1_tran_form8x8 = 0;
906 ps_cur_mb_info->ps_curmb->u1_tran_form8x8 = 0;
907
908 /***************************************************************/
909 /* Set the deblocking parameters for this MB */
910 /***************************************************************/
911 if(ps_dec->u4_app_disable_deblk_frm == 0)
912 ih264d_set_deblocking_parameters(ps_cur_deblk_mb, ps_slice,
913 ps_dec->u1_mb_ngbr_availablity,
914 ps_dec->u1_cur_mb_fld_dec_flag);
915
916 if(u4_mb_skip)
917 {
918
919 /* Set appropriate flags in ps_cur_mb_info and ps_dec */
920 memset(ps_dec->ps_curr_ctxt_mb_info, 0, sizeof(ctxt_inc_mb_info_t));
921 ps_dec->ps_curr_ctxt_mb_info->u1_mb_type = u1_inter_mb_skip_type;
922
923 MEMSET_16BYTES(&ps_dec->pu1_left_mv_ctxt_inc[0][0], 0);
924
925 *((UWORD32 *)ps_dec->pi1_left_ref_idx_ctxt_inc) = 0;
926 *(ps_dec->pu1_left_yuv_dc_csbp) = 0;
927
928 ps_dec->i1_prev_mb_qp_delta = 0;
929 ps_cur_mb_info->u1_mb_type = MB_SKIP;
930 ps_cur_mb_info->u1_cbp = 0;
931
932 {
933 /* Storing Skip partition info */
934 parse_part_params_t *ps_part_info = ps_dec->ps_part;
935 ps_part_info->u1_is_direct = PART_DIRECT_16x16;
936 ps_part_info->u1_sub_mb_num = 0;
937 ps_dec->ps_part++;
938 }
939
940 /* Update Nnzs */
941 ih264d_update_nnz_for_skipmb(ps_dec, ps_cur_mb_info, CABAC);
942
943 ps_cur_mb_info->ps_curmb->u1_mb_type = u1_inter_mb_type;
944 ps_cur_deblk_mb->u1_mb_type |= u1_deblk_mb_type;
945 ps_cur_deblk_mb->u1_mb_qp = ps_dec->u1_qp;
946
947 }
948 else
949 {
950
951 /* Macroblock Layer Begins */
952 /* Decode the u1_mb_type */
953 u1_mb_type = ih264d_parse_mb_type_cabac(ps_dec);
954 ps_cur_mb_info->u1_mb_type = u1_mb_type;
955 if(u1_mb_type > (25 + u1_mb_threshold))
956 return ERROR_MB_TYPE;
957
958 /* Parse Macroblock Data */
959 if(u1_mb_type < u1_mb_threshold)
960 {
961 ps_cur_mb_info->ps_curmb->u1_mb_type = u1_inter_mb_type;
962 *(ps_dec->pu1_left_yuv_dc_csbp) &= 0x6;
963
964 ret = ps_dec->pf_parse_inter_mb(ps_dec, ps_cur_mb_info, u1_num_mbs,
965 u1_num_mbsNby2);
966 if(ret != OK)
967 return ret;
968 ps_cur_deblk_mb->u1_mb_qp = ps_dec->u1_qp;
969 ps_cur_deblk_mb->u1_mb_type |= u1_deblk_mb_type;
970 }
971 else
972 {
973 /* Storing Intra partition info */
974 ps_parse_mb_data->u1_num_part = 0;
975 ps_parse_mb_data->u1_isI_mb = 1;
976
977 if((25 + u1_mb_threshold) == u1_mb_type)
978 {
979 /* I_PCM_MB */
980 ps_cur_mb_info->ps_curmb->u1_mb_type = I_PCM_MB;
981 ret = ih264d_parse_ipcm_mb(ps_dec, ps_cur_mb_info, u1_num_mbs);
982 if(ret != OK)
983 return ret;
984 ps_cur_deblk_mb->u1_mb_qp = 0;
985 }
986 else
987 {
988 if(u1_mb_type == u1_mb_threshold)
989 ps_cur_mb_info->ps_curmb->u1_mb_type = I_4x4_MB;
990 else
991 ps_cur_mb_info->ps_curmb->u1_mb_type = I_16x16_MB;
992
993 ret = ih264d_parse_imb_cabac(
994 ps_dec, ps_cur_mb_info,
995 (UWORD8)(u1_mb_type - u1_mb_threshold));
996 if(ret != OK)
997 return ret;
998 ps_cur_deblk_mb->u1_mb_qp = ps_dec->u1_qp;
999 }
1000 ps_cur_deblk_mb->u1_mb_type |= D_INTRA_MB;
1001
1002 }
1003
1004 }
1005
1006 if(u1_mbaff)
1007 {
1008 ih264d_update_mbaff_left_nnz(ps_dec, ps_cur_mb_info);
1009 }
1010 /* Next macroblock information */
Hamsalekha S8d3d3032015-03-13 21:24:58 +05301011 i2_cur_mb_addr++;
1012
1013 if(ps_cur_mb_info->u1_topmb && u1_mbaff)
1014 uc_more_data_flag = 1;
1015 else
1016 {
1017 uc_more_data_flag = ih264d_decode_terminate(&ps_dec->s_cab_dec_env,
1018 ps_bitstrm);
1019 uc_more_data_flag = !uc_more_data_flag;
1020 COPYTHECONTEXT("Decode Sliceterm",!uc_more_data_flag);
1021 }
1022
1023 u1_num_mbs++;
Hamsalekha S8d3d3032015-03-13 21:24:58 +05301024 u1_num_mbsNby2++;
1025 ps_parse_mb_data++;
1026
1027 /****************************************************************/
1028 /* Check for End Of Row and other flags that determine when to */
1029 /* do DMA setup for N/2-Mb, Decode for N-Mb, and Transfer for */
1030 /* N-Mb */
1031 /****************************************************************/
1032 u1_num_mbs_next = i2_pic_wdin_mbs - ps_dec->u2_mbx - 1;
1033 u1_end_of_row = (!u1_num_mbs_next) && (!(u1_mbaff && (u1_num_mbs & 0x01)));
1034 u1_slice_end = !uc_more_data_flag;
1035 u1_tfr_n_mb = (u1_num_mbs == ps_dec->u1_recon_mb_grp) || u1_end_of_row
1036 || u1_slice_end;
1037 u1_decode_nmb = u1_tfr_n_mb || u1_slice_end;
1038 ps_cur_mb_info->u1_end_of_slice = u1_slice_end;
1039 /*u1_dma_nby2mb = u1_decode_nmb ||
1040 (u1_num_mbsNby2 == ps_dec->u1_recon_mb_grp_pair);*/
1041
1042//if(u1_dma_nby2mb)
1043 if(u1_decode_nmb)
1044 {
1045
Marco Nelissen8ef4c3f2015-06-03 07:26:32 -07001046 ps_dec->pf_mvpred_ref_tfr_nby2mb(ps_dec, u1_mb_idx, u1_num_mbs);
Hamsalekha S8d3d3032015-03-13 21:24:58 +05301047 u1_num_mbsNby2 = 0;
1048
1049 {
1050 ps_parse_mb_data = ps_dec->ps_parse_mb_data;
1051 ps_dec->ps_part = ps_dec->ps_parse_part_params;
1052 }
1053 }
1054
1055 /*H264_DEC_DEBUG_PRINT("Pic: %d Mb_X=%d Mb_Y=%d",
1056 ps_slice->i4_poc >> ps_slice->u1_field_pic_flag,
1057 ps_dec->u2_mbx,ps_dec->u2_mby + (1 - ps_cur_mb_info->u1_topmb));
1058 H264_DEC_DEBUG_PRINT("u1_decode_nmb: %d, u1_num_mbs: %d", u1_decode_nmb, u1_num_mbs);*/
1059 if(u1_decode_nmb)
1060 {
1061
1062 if(ps_dec->u1_separate_parse)
1063 {
1064 ih264d_parse_tfr_nmb(ps_dec, u1_mb_idx, u1_num_mbs,
1065 u1_num_mbs_next, u1_tfr_n_mb, u1_end_of_row);
1066 ps_dec->ps_nmb_info += u1_num_mbs;
1067 }
1068 else
1069 {
Marco Nelissen8ef4c3f2015-06-03 07:26:32 -07001070 ih264d_decode_recon_tfr_nmb(ps_dec, u1_mb_idx, u1_num_mbs,
1071 u1_num_mbs_next, u1_tfr_n_mb,
1072 u1_end_of_row);
Hamsalekha S8d3d3032015-03-13 21:24:58 +05301073 }
Harish Mahendrakar4a524d32016-01-07 16:59:02 +05301074 ps_dec->u2_total_mbs_coded += u1_num_mbs;
Hamsalekha S8d3d3032015-03-13 21:24:58 +05301075 if(u1_tfr_n_mb)
1076 u1_num_mbs = 0;
1077 u1_mb_idx = u1_num_mbs;
1078 ps_dec->u1_mb_idx = u1_num_mbs;
1079
1080 }
1081 }
1082
Marco Nelissen8ef4c3f2015-06-03 07:26:32 -07001083
1084 ps_dec->u4_num_mbs_cur_nmb = 0;
1085 ps_dec->ps_cur_slice->u4_mbs_in_slice = i2_cur_mb_addr
1086
Hamsalekha S8d3d3032015-03-13 21:24:58 +05301087 - (u2_first_mb_in_slice << u1_mbaff);
Marco Nelissen8ef4c3f2015-06-03 07:26:32 -07001088
1089 return ret;
Hamsalekha S8d3d3032015-03-13 21:24:58 +05301090}
1091
1092/*****************************************************************************/
1093/* */
1094/* Function Name : ih264d_parse_inter_slice_data_cavlc */
1095/* */
1096/* Description : This function parses cavlc syntax of a inter slice on */
1097/* N MB basis. */
1098/* */
1099/* Inputs : ps_dec */
1100/* sliceparams */
1101/* firstMbInSlice */
1102/* */
1103/* Processing : 1. After parsing syntax for N MBs those N MBs are */
1104/* decoded till the end of slice. */
1105/* 2. MV prediction and DMA happens on a N/2 MB basis. */
1106/* */
1107/* Returns : 0 */
1108/* */
1109/* Issues : <List any issues or problems with this function> */
1110/* */
1111/* Revision History: */
1112/* */
1113/* DD MM YYYY Author(s) Changes (Describe the changes made) */
1114/* 13 07 2002 Jay Draft */
1115/* */
1116/*****************************************************************************/
1117
1118WORD32 ih264d_parse_inter_slice_data_cavlc(dec_struct_t * ps_dec,
1119 dec_slice_params_t * ps_slice,
1120 UWORD16 u2_first_mb_in_slice)
1121{
1122 UWORD32 uc_more_data_flag;
1123 WORD32 i2_cur_mb_addr;
1124 UWORD32 u1_num_mbs, u1_num_mbsNby2, u1_mb_idx;
1125 UWORD32 i2_mb_skip_run;
1126 UWORD32 u1_read_mb_type;
1127
1128 UWORD32 u1_mbaff;
1129 UWORD32 u1_num_mbs_next, u1_end_of_row;
1130 const UWORD32 i2_pic_wdin_mbs = ps_dec->u2_frm_wd_in_mbs;
1131 UWORD32 u1_slice_end = 0;
1132 UWORD32 u1_tfr_n_mb = 0;
1133 UWORD32 u1_decode_nmb = 0;
1134
1135 dec_bit_stream_t * const ps_bitstrm = ps_dec->ps_bitstrm;
1136 UWORD32 *pu4_bitstrm_buf = ps_bitstrm->pu4_buffer;
1137 UWORD32 *pu4_bitstrm_ofst = &ps_bitstrm->u4_ofst;
1138 deblk_mb_t *ps_cur_deblk_mb;
1139 dec_mb_info_t *ps_cur_mb_info;
1140 parse_pmbarams_t *ps_parse_mb_data = ps_dec->ps_parse_mb_data;
1141 UWORD32 u1_inter_mb_type;
1142 UWORD32 u1_deblk_mb_type;
1143 UWORD32 u1_mb_threshold;
Marco Nelissen8ef4c3f2015-06-03 07:26:32 -07001144 WORD32 ret = OK;
Hamsalekha S8d3d3032015-03-13 21:24:58 +05301145
1146 /******************************************************/
1147 /* Initialisations specific to B or P slice */
1148 /******************************************************/
1149
1150 if(ps_slice->u1_slice_type == P_SLICE)
1151 {
1152 u1_inter_mb_type = P_MB;
1153 u1_deblk_mb_type = D_INTER_MB;
1154 u1_mb_threshold = 5;
1155 }
1156 else // B_SLICE
1157 {
1158 u1_inter_mb_type = B_MB;
1159 u1_deblk_mb_type = D_B_SLICE;
1160 u1_mb_threshold = 23;
1161 }
1162 /******************************************************/
1163 /* Slice Level Initialisations */
1164 /******************************************************/
Hamsalekha S8d3d3032015-03-13 21:24:58 +05301165 ps_dec->u1_qp = ps_slice->u1_slice_qp;
Marco Nelissen8ef4c3f2015-06-03 07:26:32 -07001166 ih264d_update_qp(ps_dec, 0);
Hamsalekha S8d3d3032015-03-13 21:24:58 +05301167 u1_mb_idx = ps_dec->u1_mb_idx;
1168 u1_num_mbs = u1_mb_idx;
1169
1170 u1_num_mbsNby2 = 0;
1171 u1_mbaff = ps_slice->u1_mbaff_frame_flag;
1172 i2_cur_mb_addr = u2_first_mb_in_slice << u1_mbaff;
1173 i2_mb_skip_run = 0;
1174 uc_more_data_flag = 1;
1175 u1_read_mb_type = 0;
1176
1177 while(!u1_slice_end)
1178 {
1179 UWORD8 u1_mb_type;
1180
Marco Nelissen8ef4c3f2015-06-03 07:26:32 -07001181 ps_dec->pv_prev_mb_parse_tu_coeff_data = ps_dec->pv_parse_tu_coeff_data;
1182
Hamsalekha S8d3d3032015-03-13 21:24:58 +05301183 if(i2_cur_mb_addr > ps_dec->ps_cur_sps->u2_max_mb_addr)
1184 {
Marco Nelissen8ef4c3f2015-06-03 07:26:32 -07001185 ret = ERROR_MB_ADDRESS_T;
Hamsalekha S8d3d3032015-03-13 21:24:58 +05301186 break;
1187 }
1188
1189
1190 ps_cur_mb_info = ps_dec->ps_nmb_info + u1_num_mbs;
Marco Nelissen8ef4c3f2015-06-03 07:26:32 -07001191 ps_dec->u4_num_mbs_cur_nmb = u1_num_mbs;
Hamsalekha S8d3d3032015-03-13 21:24:58 +05301192
1193 ps_cur_mb_info->u1_Mux = 0;
1194 ps_dec->u4_num_pmbair = (u1_num_mbs >> u1_mbaff);
1195 ps_cur_deblk_mb = ps_dec->ps_deblk_mbn + u1_num_mbs;
1196
1197 ps_cur_mb_info->u1_end_of_slice = 0;
1198
1199 /* Storing Default partition info */
1200 ps_parse_mb_data->u1_num_part = 1;
1201 ps_parse_mb_data->u1_isI_mb = 0;
1202
1203 if((!i2_mb_skip_run) && (!u1_read_mb_type))
1204 {
1205
1206 //Inlined ih264d_uev
1207 UWORD32 u4_bitstream_offset = *pu4_bitstrm_ofst;
1208 UWORD32 u4_word, u4_ldz;
1209
1210 /***************************************************************/
1211 /* Find leading zeros in next 32 bits */
1212 /***************************************************************/
1213 NEXTBITS_32(u4_word, u4_bitstream_offset, pu4_bitstrm_buf);
1214
1215 u4_ldz = CLZ(u4_word);
1216
1217 /* Flush the ps_bitstrm */
1218 u4_bitstream_offset += (u4_ldz + 1);
1219 /* Read the suffix from the ps_bitstrm */
1220 u4_word = 0;
1221 if(u4_ldz)
1222 {
1223 GETBITS(u4_word, u4_bitstream_offset, pu4_bitstrm_buf,
1224 u4_ldz);
1225 }
1226 *pu4_bitstrm_ofst = u4_bitstream_offset;
1227 i2_mb_skip_run = ((1 << u4_ldz) + u4_word - 1);
1228 //Inlined ih264d_uev
1229 COPYTHECONTEXT("mb_skip_run", i2_mb_skip_run);
1230 uc_more_data_flag = MORE_RBSP_DATA(ps_bitstrm);
1231 u1_read_mb_type = uc_more_data_flag;
1232 }
1233
1234 /***************************************************************/
1235 /* Get the required information for decoding of MB */
1236 /* mb_x, mb_y , neighbour availablity, */
1237 /***************************************************************/
1238 ps_dec->pf_get_mb_info(ps_dec, i2_cur_mb_addr, ps_cur_mb_info, i2_mb_skip_run);
1239
1240 /***************************************************************/
1241 /* Set the deblocking parameters for this MB */
1242 /***************************************************************/
1243 if(ps_dec->u4_app_disable_deblk_frm == 0)
1244 ih264d_set_deblocking_parameters(ps_cur_deblk_mb, ps_slice,
1245 ps_dec->u1_mb_ngbr_availablity,
1246 ps_dec->u1_cur_mb_fld_dec_flag);
1247
1248 if(i2_mb_skip_run)
1249 {
1250 /* Set appropriate flags in ps_cur_mb_info and ps_dec */
1251 ps_dec->i1_prev_mb_qp_delta = 0;
1252 ps_dec->u1_sub_mb_num = 0;
1253 ps_cur_mb_info->u1_mb_type = MB_SKIP;
1254 ps_cur_mb_info->u1_mb_mc_mode = PRED_16x16;
1255 ps_cur_mb_info->u1_cbp = 0;
1256
1257 {
1258 /* Storing Skip partition info */
1259 parse_part_params_t *ps_part_info = ps_dec->ps_part;
1260 ps_part_info->u1_is_direct = PART_DIRECT_16x16;
1261 ps_part_info->u1_sub_mb_num = 0;
1262 ps_dec->ps_part++;
1263 }
1264
1265 /* Update Nnzs */
1266 ih264d_update_nnz_for_skipmb(ps_dec, ps_cur_mb_info, CAVLC);
1267
1268 ps_cur_mb_info->ps_curmb->u1_mb_type = u1_inter_mb_type;
1269 ps_cur_deblk_mb->u1_mb_type |= u1_deblk_mb_type;
1270
1271 i2_mb_skip_run--;
1272 }
1273 else
1274 {
1275 u1_read_mb_type = 0;
1276 /**************************************************************/
1277 /* Macroblock Layer Begins, Decode the u1_mb_type */
1278 /**************************************************************/
1279 {
1280 UWORD32 u4_bitstream_offset = *pu4_bitstrm_ofst;
1281 UWORD32 u4_word, u4_ldz, u4_temp;
1282
1283
1284 //Inlined ih264d_uev
1285 /***************************************************************/
1286 /* Find leading zeros in next 32 bits */
1287 /***************************************************************/
1288 NEXTBITS_32(u4_word, u4_bitstream_offset, pu4_bitstrm_buf);
1289 u4_ldz = CLZ(u4_word);
1290 /* Flush the ps_bitstrm */
1291 u4_bitstream_offset += (u4_ldz + 1);
1292 /* Read the suffix from the ps_bitstrm */
1293 u4_word = 0;
1294 if(u4_ldz)
1295 GETBITS(u4_word, u4_bitstream_offset, pu4_bitstrm_buf,
1296 u4_ldz);
1297 *pu4_bitstrm_ofst = u4_bitstream_offset;
1298 u4_temp = ((1 << u4_ldz) + u4_word - 1);
1299 //Inlined ih264d_uev
1300 if(u4_temp > (UWORD32)(25 + u1_mb_threshold))
1301 return ERROR_MB_TYPE;
1302 u1_mb_type = u4_temp;
1303 COPYTHECONTEXT("u1_mb_type", u1_mb_type);
1304 }
1305 ps_cur_mb_info->u1_mb_type = u1_mb_type;
1306
1307 /**************************************************************/
1308 /* Parse Macroblock data */
1309 /**************************************************************/
1310 if(u1_mb_type < u1_mb_threshold)
1311 {
1312 ps_cur_mb_info->ps_curmb->u1_mb_type = u1_inter_mb_type;
1313
1314 ret = ps_dec->pf_parse_inter_mb(ps_dec, ps_cur_mb_info, u1_num_mbs,
1315 u1_num_mbsNby2);
1316 if(ret != OK)
1317 return ret;
1318 ps_cur_deblk_mb->u1_mb_type |= u1_deblk_mb_type;
1319 }
1320 else
1321 {
1322 /* Storing Intra partition info */
1323 ps_parse_mb_data->u1_num_part = 0;
1324 ps_parse_mb_data->u1_isI_mb = 1;
1325
1326 if((25 + u1_mb_threshold) == u1_mb_type)
1327 {
1328 /* I_PCM_MB */
1329 ps_cur_mb_info->ps_curmb->u1_mb_type = I_PCM_MB;
1330 ret = ih264d_parse_ipcm_mb(ps_dec, ps_cur_mb_info, u1_num_mbs);
1331 if(ret != OK)
1332 return ret;
1333 ps_dec->u1_qp = 0;
1334 }
1335 else
1336 {
1337 ret = ih264d_parse_imb_cavlc(
1338 ps_dec, ps_cur_mb_info, u1_num_mbs,
1339 (UWORD8)(u1_mb_type - u1_mb_threshold));
1340 if(ret != OK)
1341 return ret;
1342 }
1343
1344 ps_cur_deblk_mb->u1_mb_type |= D_INTRA_MB;
1345 }
1346 uc_more_data_flag = MORE_RBSP_DATA(ps_bitstrm);
1347 }
1348 ps_cur_deblk_mb->u1_mb_qp = ps_dec->u1_qp;
1349
1350 if(u1_mbaff)
1351 {
1352 ih264d_update_mbaff_left_nnz(ps_dec, ps_cur_mb_info);
1353 }
1354 /**************************************************************/
1355 /* Get next Macroblock address */
1356 /**************************************************************/
1357 i2_cur_mb_addr++;
1358
1359 u1_num_mbs++;
Hamsalekha S8d3d3032015-03-13 21:24:58 +05301360 u1_num_mbsNby2++;
1361 ps_parse_mb_data++;
1362
1363 /****************************************************************/
1364 /* Check for End Of Row and other flags that determine when to */
1365 /* do DMA setup for N/2-Mb, Decode for N-Mb, and Transfer for */
1366 /* N-Mb */
1367 /****************************************************************/
1368 u1_num_mbs_next = i2_pic_wdin_mbs - ps_dec->u2_mbx - 1;
1369 u1_end_of_row = (!u1_num_mbs_next) && (!(u1_mbaff && (u1_num_mbs & 0x01)));
1370 u1_slice_end = (!(uc_more_data_flag || i2_mb_skip_run));
1371 u1_tfr_n_mb = (u1_num_mbs == ps_dec->u1_recon_mb_grp) || u1_end_of_row
1372 || u1_slice_end;
1373 u1_decode_nmb = u1_tfr_n_mb || u1_slice_end;
1374 ps_cur_mb_info->u1_end_of_slice = u1_slice_end;
1375
1376 /*u1_dma_nby2mb = u1_decode_nmb ||
1377 (u1_num_mbsNby2 == ps_dec->u1_recon_mb_grp_pair);*/
1378
1379//if(u1_dma_nby2mb)
1380 if(u1_decode_nmb)
1381 {
Marco Nelissen8ef4c3f2015-06-03 07:26:32 -07001382 ps_dec->pf_mvpred_ref_tfr_nby2mb(ps_dec, u1_mb_idx, u1_num_mbs);
Hamsalekha S8d3d3032015-03-13 21:24:58 +05301383 u1_num_mbsNby2 = 0;
1384
1385 {
1386 ps_parse_mb_data = ps_dec->ps_parse_mb_data;
1387 ps_dec->ps_part = ps_dec->ps_parse_part_params;
1388 }
1389 }
1390
1391 /*H264_DEC_DEBUG_PRINT("Pic: %d Mb_X=%d Mb_Y=%d",
1392 ps_slice->i4_poc >> ps_slice->u1_field_pic_flag,
1393 ps_dec->u2_mbx,ps_dec->u2_mby + (1 - ps_cur_mb_info->u1_topmb));
1394 H264_DEC_DEBUG_PRINT("u1_decode_nmb: %d", u1_decode_nmb);*/
1395 if(u1_decode_nmb)
1396 {
1397
1398
1399
1400 if(ps_dec->u1_separate_parse)
1401 {
1402 ih264d_parse_tfr_nmb(ps_dec, u1_mb_idx, u1_num_mbs,
1403 u1_num_mbs_next, u1_tfr_n_mb, u1_end_of_row);
1404 ps_dec->ps_nmb_info += u1_num_mbs;
1405 }
1406 else
1407 {
Marco Nelissen8ef4c3f2015-06-03 07:26:32 -07001408 ih264d_decode_recon_tfr_nmb(ps_dec, u1_mb_idx, u1_num_mbs,
1409 u1_num_mbs_next, u1_tfr_n_mb,
1410 u1_end_of_row);
Hamsalekha S8d3d3032015-03-13 21:24:58 +05301411 }
Harish Mahendrakar4a524d32016-01-07 16:59:02 +05301412 ps_dec->u2_total_mbs_coded += u1_num_mbs;
Hamsalekha S8d3d3032015-03-13 21:24:58 +05301413 if(u1_tfr_n_mb)
1414 u1_num_mbs = 0;
1415 u1_mb_idx = u1_num_mbs;
1416 ps_dec->u1_mb_idx = u1_num_mbs;
1417
1418 }
1419//ps_dec->ps_pred++;
1420 }
1421
Marco Nelissen8ef4c3f2015-06-03 07:26:32 -07001422 ps_dec->u4_num_mbs_cur_nmb = 0;
1423 ps_dec->ps_cur_slice->u4_mbs_in_slice = i2_cur_mb_addr
Hamsalekha S8d3d3032015-03-13 21:24:58 +05301424 - (u2_first_mb_in_slice << u1_mbaff);
Marco Nelissen8ef4c3f2015-06-03 07:26:32 -07001425
1426
1427 return ret;
1428}
1429
1430WORD32 ih264d_mark_err_slice_skip(dec_struct_t * ps_dec,
1431 WORD32 num_mb_skip,
1432 UWORD8 u1_is_idr_slice,
Hamsalekha S9f0dcba2015-06-09 15:54:31 +05301433 UWORD16 u2_frame_num,
Marco Nelissen8ef4c3f2015-06-03 07:26:32 -07001434 pocstruct_t *ps_cur_poc,
1435 WORD32 prev_slice_err)
1436{
1437 WORD32 i2_cur_mb_addr;
1438 UWORD32 u1_num_mbs, u1_num_mbsNby2;
1439 UWORD32 u1_mb_idx = ps_dec->u1_mb_idx;
1440 UWORD32 i2_mb_skip_run;
1441
1442 UWORD32 u1_num_mbs_next, u1_end_of_row;
1443 const UWORD32 i2_pic_wdin_mbs = ps_dec->u2_frm_wd_in_mbs;
1444 UWORD32 u1_slice_end;
1445 UWORD32 u1_tfr_n_mb;
1446 UWORD32 u1_decode_nmb;
1447 dec_bit_stream_t * const ps_bitstrm = ps_dec->ps_bitstrm;
1448 dec_slice_params_t * ps_slice = ps_dec->ps_cur_slice;
1449 UWORD32 *pu4_bitstrm_buf = ps_bitstrm->pu4_buffer;
1450 UWORD32 *pu4_bitstrm_ofst = &ps_bitstrm->u4_ofst;
1451 deblk_mb_t *ps_cur_deblk_mb;
1452 dec_mb_info_t *ps_cur_mb_info;
1453 parse_pmbarams_t *ps_parse_mb_data;
1454 UWORD32 u1_inter_mb_type;
1455 UWORD32 u1_deblk_mb_type;
1456 UWORD16 u2_total_mbs_coded;
1457 UWORD32 u1_mbaff = ps_slice->u1_mbaff_frame_flag;
1458 parse_part_params_t *ps_part_info;
Hamsalekha S9f0dcba2015-06-09 15:54:31 +05301459 WORD32 ret;
1460
1461
1462 if(ps_dec->ps_dec_err_status->u1_err_flag & REJECT_CUR_PIC)
1463 {
1464 ih264d_err_pic_dispbuf_mgr(ps_dec);
1465 return 0;
1466 }
Harish Mahendrakareacafb92016-05-13 10:33:34 +05301467 ps_dec->ps_dpb_cmds->u1_long_term_reference_flag = 0;
Marco Nelissen8ef4c3f2015-06-03 07:26:32 -07001468 if(prev_slice_err == 1)
1469 {
Hamsalekha S9f0dcba2015-06-09 15:54:31 +05301470 /* first slice - missing/header corruption */
1471 ps_dec->ps_cur_slice->u2_frame_num = u2_frame_num;
1472
Marco Nelissen8ef4c3f2015-06-03 07:26:32 -07001473
1474 if(!ps_dec->u1_first_slice_in_stream)
1475 {
1476 ih264d_end_of_pic(ps_dec, u1_is_idr_slice,
1477 ps_dec->ps_cur_slice->u2_frame_num);
1478 ps_dec->s_cur_pic_poc.u2_frame_num =
1479 ps_dec->ps_cur_slice->u2_frame_num;
1480 }
1481
1482 {
1483 WORD32 i, j, poc = 0;
1484
1485 ps_dec->ps_cur_slice->u2_first_mb_in_slice = 0;
1486
1487 ps_dec->pf_mvpred = ih264d_mvpred_nonmbaff;
1488 ps_dec->p_form_mb_part_info = ih264d_form_mb_part_info_bp;
1489 ps_dec->p_motion_compensate = ih264d_motion_compensate_bp;
Marco Nelissen8ef4c3f2015-06-03 07:26:32 -07001490
1491 if(ps_dec->ps_cur_pic != NULL)
1492 poc = ps_dec->ps_cur_pic->i4_poc + 2;
1493
Harish Mahendrakarc2e8ffe2016-09-17 14:04:29 +05301494 j = -1;
Marco Nelissen8ef4c3f2015-06-03 07:26:32 -07001495 for(i = 0; i < MAX_NUM_PIC_PARAMS; i++)
Harish Mahendrakarc2e8ffe2016-09-17 14:04:29 +05301496 {
Marco Nelissen8ef4c3f2015-06-03 07:26:32 -07001497 if(ps_dec->ps_pps[i].u1_is_valid == TRUE)
Harish Mahendrakarc2e8ffe2016-09-17 14:04:29 +05301498 {
1499 if(ps_dec->ps_pps[i].ps_sps->u1_is_valid == TRUE)
1500 {
1501 j = i;
1502 break;
1503 }
1504 }
1505 }
1506
1507 //if valid SPS PPS is not found return error
1508 if(j == -1)
1509 {
1510 return ERROR_INV_SPS_PPS_T;
1511 }
1512
Harish Mahendrakarbc71ad22016-09-17 17:00:37 +05301513 /* call ih264d_start_of_pic only if it was not called earlier*/
1514 if(ps_dec->u4_pic_buf_got == 0)
Hamsalekha S9f0dcba2015-06-09 15:54:31 +05301515 {
Harish Mahendrakar33db7a02016-04-20 16:13:52 +05301516 //initialize slice params required by ih264d_start_of_pic to valid values
Harish Mahendrakar33db7a02016-04-20 16:13:52 +05301517 ps_dec->ps_cur_slice->u1_slice_type = P_SLICE;
1518 ps_dec->ps_cur_slice->u1_nal_ref_idc = 1;
1519 ps_dec->ps_cur_slice->u1_nal_unit_type = 1;
Hamsalekha S9f0dcba2015-06-09 15:54:31 +05301520 ret = ih264d_start_of_pic(ps_dec, poc, ps_cur_poc,
1521 ps_dec->ps_cur_slice->u2_frame_num,
1522 &ps_dec->ps_pps[j]);
Marco Nelissen8ef4c3f2015-06-03 07:26:32 -07001523
Hamsalekha S9f0dcba2015-06-09 15:54:31 +05301524 if(ret != OK)
1525 {
1526 return ret;
1527 }
1528 }
Marco Nelissen8ef4c3f2015-06-03 07:26:32 -07001529
1530 ps_dec->ps_ref_pic_buf_lx[0][0]->u1_pic_buf_id = 0;
1531
1532 ps_dec->u4_output_present = 0;
1533
1534 {
1535 ih264d_get_next_display_field(ps_dec,
1536 ps_dec->ps_out_buffer,
1537 &(ps_dec->s_disp_op));
1538 /* If error code is non-zero then there is no buffer available for display,
1539 hence avoid format conversion */
1540
1541 if(0 != ps_dec->s_disp_op.u4_error_code)
1542 {
1543 ps_dec->u4_fmt_conv_cur_row = ps_dec->s_disp_frame_info.u4_y_ht;
1544 }
1545 else
1546 ps_dec->u4_output_present = 1;
1547 }
1548
1549 if(ps_dec->u1_separate_parse == 1)
1550 {
1551 if(ps_dec->u4_dec_thread_created == 0)
1552 {
1553 ithread_create(ps_dec->pv_dec_thread_handle, NULL,
1554 (void *)ih264d_decode_picture_thread,
1555 (void *)ps_dec);
1556
1557 ps_dec->u4_dec_thread_created = 1;
1558 }
1559
1560 if((ps_dec->u4_num_cores == 3) &&
1561 ((ps_dec->u4_app_disable_deblk_frm == 0) || ps_dec->i1_recon_in_thread3_flag)
1562 && (ps_dec->u4_bs_deblk_thread_created == 0))
1563 {
1564 ps_dec->u4_start_recon_deblk = 0;
1565 ithread_create(ps_dec->pv_bs_deblk_thread_handle, NULL,
1566 (void *)ih264d_recon_deblk_thread,
1567 (void *)ps_dec);
1568 ps_dec->u4_bs_deblk_thread_created = 1;
1569 }
1570 }
1571 }
Harish Mahendrakar5e4f64c2016-06-01 13:31:45 +05301572 ps_dec->u4_first_slice_in_pic = 0;
Marco Nelissen8ef4c3f2015-06-03 07:26:32 -07001573 }
1574 else
1575 {
1576 // Middle / last slice
1577
1578 dec_slice_struct_t *ps_parse_cur_slice;
1579 ps_parse_cur_slice = ps_dec->ps_dec_slice_buf + ps_dec->u2_cur_slice_num;
1580
1581 if(ps_dec->u1_slice_header_done
1582 && ps_parse_cur_slice == ps_dec->ps_parse_cur_slice)
1583 {
1584 // Slice data corrupted
Harish Mahendrakarbc71ad22016-09-17 17:00:37 +05301585 // in the case of mbaff, conceal from the even mb.
1586 u1_num_mbs = (ps_dec->u4_num_mbs_cur_nmb >> u1_mbaff ) << u1_mbaff;
Marco Nelissen8ef4c3f2015-06-03 07:26:32 -07001587
1588 if(u1_num_mbs)
1589 {
1590 ps_cur_mb_info = ps_dec->ps_nmb_info + u1_num_mbs - 1;
1591 }
1592 else
1593 {
1594 if(ps_dec->u1_separate_parse)
1595 {
1596 ps_cur_mb_info = ps_dec->ps_nmb_info - 1;
1597 }
1598 else
1599 {
1600 ps_cur_mb_info = ps_dec->ps_nmb_info
1601 + ps_dec->u4_num_mbs_prev_nmb - 1;
1602 }
1603 }
1604
1605 ps_dec->u2_mby = ps_cur_mb_info->u2_mby;
1606 ps_dec->u2_mbx = ps_cur_mb_info->u2_mbx;
1607
1608 ps_dec->u1_mb_ngbr_availablity =
1609 ps_cur_mb_info->u1_mb_ngbr_availablity;
1610
1611 // Going back 1 mb
1612 ps_dec->pv_parse_tu_coeff_data = ps_dec->pv_prev_mb_parse_tu_coeff_data;
1613 ps_dec->u2_cur_mb_addr--;
1614 ps_dec->i4_submb_ofst -= SUB_BLK_SIZE;
1615
1616 if(u1_num_mbs)
1617 {
1618 // Parse/decode N-MB left unparsed
1619 if (ps_dec->u1_pr_sl_type == P_SLICE
1620 || ps_dec->u1_pr_sl_type == B_SLICE)
1621 {
1622 ps_dec->pf_mvpred_ref_tfr_nby2mb(ps_dec, u1_mb_idx, u1_num_mbs);
1623 ps_dec->ps_part = ps_dec->ps_parse_part_params;
1624 }
1625
1626 u1_num_mbs_next = i2_pic_wdin_mbs - ps_dec->u2_mbx - 1;
1627 u1_end_of_row = (!u1_num_mbs_next)
1628 && (!(u1_mbaff && (u1_num_mbs & 0x01)));
1629 u1_slice_end = 1;
1630 u1_tfr_n_mb = 1;
1631 ps_cur_mb_info->u1_end_of_slice = u1_slice_end;
1632
1633 if(ps_dec->u1_separate_parse)
1634 {
1635 ih264d_parse_tfr_nmb(ps_dec, u1_mb_idx, u1_num_mbs,
1636 u1_num_mbs_next, u1_tfr_n_mb, u1_end_of_row);
1637 ps_dec->ps_nmb_info += u1_num_mbs;
1638 }
1639 else
1640 {
1641 ih264d_decode_recon_tfr_nmb(ps_dec, u1_mb_idx, u1_num_mbs,
1642 u1_num_mbs_next, u1_tfr_n_mb, u1_end_of_row);
1643 }
Harish Mahendrakar4a524d32016-01-07 16:59:02 +05301644 ps_dec->u2_total_mbs_coded += u1_num_mbs;
Marco Nelissen8ef4c3f2015-06-03 07:26:32 -07001645 ps_dec->u1_mb_idx = 0;
1646 ps_dec->u4_num_mbs_cur_nmb = 0;
1647 }
1648
1649 if(ps_dec->u2_total_mbs_coded
1650 >= ps_dec->u2_frm_ht_in_mbs * ps_dec->u2_frm_wd_in_mbs)
1651 {
1652 ps_dec->u1_pic_decode_done = 1;
Hamsalekha S9f0dcba2015-06-09 15:54:31 +05301653 return 0;
Marco Nelissen8ef4c3f2015-06-03 07:26:32 -07001654 }
1655
1656 // Inserting new slice
1657 ps_dec->u2_cur_slice_num++;
1658 ps_dec->i2_prev_slice_mbx = ps_dec->u2_mbx;
1659 ps_dec->i2_prev_slice_mby = ps_dec->u2_mby;
1660 ps_dec->ps_parse_cur_slice++;
1661
1662 }
1663 else
1664 {
1665 // Slice missing / header corrupted
1666 ps_dec->ps_parse_cur_slice = ps_dec->ps_dec_slice_buf
1667 + ps_dec->u2_cur_slice_num;
1668 }
Hamsalekha S8d3d3032015-03-13 21:24:58 +05301669 }
1670
Marco Nelissen8ef4c3f2015-06-03 07:26:32 -07001671 /******************************************************/
1672 /* Initializations to new slice */
1673 /******************************************************/
1674 {
1675 WORD32 num_entries;
1676 WORD32 size;
1677 UWORD8 *pu1_buf;
Hamsalekha S8d3d3032015-03-13 21:24:58 +05301678
Marco Nelissen8ef4c3f2015-06-03 07:26:32 -07001679 num_entries = MIN(MAX_FRAMES, ps_dec->u4_num_ref_frames_at_init);
1680 num_entries = 2 * ((2 * num_entries) + 1);
1681
1682 size = num_entries * sizeof(void *);
1683 size += PAD_MAP_IDX_POC * sizeof(void *);
1684
1685 pu1_buf = (UWORD8 *)ps_dec->pv_map_ref_idx_to_poc_buf;
1686 pu1_buf += size * ps_dec->u2_cur_slice_num;
1687 ps_dec->ps_parse_cur_slice->ppv_map_ref_idx_to_poc = (volatile void **)pu1_buf;
1688 }
1689
1690 ps_dec->ps_cur_slice->u2_first_mb_in_slice = ps_dec->u2_total_mbs_coded << u1_mbaff;
Harish Mahendrakar33db7a02016-04-20 16:13:52 +05301691 ps_dec->ps_cur_slice->i1_slice_alpha_c0_offset = 0;
1692 ps_dec->ps_cur_slice->i1_slice_beta_offset = 0;
1693
Marco Nelissen8ef4c3f2015-06-03 07:26:32 -07001694 if(ps_dec->ps_cur_slice->u1_field_pic_flag)
1695 ps_dec->u2_prv_frame_num = ps_dec->ps_cur_slice->u2_frame_num;
1696
1697 ps_dec->ps_parse_cur_slice->u4_first_mb_in_slice = ps_dec->u2_total_mbs_coded << u1_mbaff;
1698 ps_dec->ps_parse_cur_slice->u2_log2Y_crwd = ps_dec->ps_cur_slice->u2_log2Y_crwd;
1699
1700
1701 if(ps_dec->u1_separate_parse)
1702 {
1703 ps_dec->ps_parse_cur_slice->pv_tu_coeff_data_start = ps_dec->pv_parse_tu_coeff_data;
1704 }
1705 else
1706 {
1707 ps_dec->pv_proc_tu_coeff_data = ps_dec->pv_parse_tu_coeff_data;
1708 }
1709
1710 /******************************************************/
1711 /* Initializations specific to P slice */
1712 /******************************************************/
1713 u1_inter_mb_type = P_MB;
1714 u1_deblk_mb_type = D_INTER_MB;
1715
1716 ps_dec->ps_cur_slice->u1_slice_type = P_SLICE;
1717 ps_dec->ps_parse_cur_slice->slice_type = P_SLICE;
1718 ps_dec->pf_mvpred_ref_tfr_nby2mb = ih264d_mv_pred_ref_tfr_nby2_pmb;
1719 ps_dec->ps_part = ps_dec->ps_parse_part_params;
1720
1721 /******************************************************/
1722 /* Parsing / decoding the slice */
1723 /******************************************************/
Marco Nelissen8ef4c3f2015-06-03 07:26:32 -07001724 ps_dec->u1_slice_header_done = 2;
1725 ps_dec->u1_qp = ps_slice->u1_slice_qp;
1726 ih264d_update_qp(ps_dec, 0);
1727 u1_mb_idx = ps_dec->u1_mb_idx;
1728 ps_parse_mb_data = ps_dec->ps_parse_mb_data;
1729 u1_num_mbs = u1_mb_idx;
1730
1731 u1_slice_end = 0;
1732 u1_tfr_n_mb = 0;
1733 u1_decode_nmb = 0;
1734 u1_num_mbsNby2 = 0;
1735 i2_cur_mb_addr = ps_dec->u2_total_mbs_coded;
1736 i2_mb_skip_run = num_mb_skip;
1737
1738 while(!u1_slice_end)
1739 {
1740 UWORD8 u1_mb_type;
1741
1742 if(i2_cur_mb_addr > ps_dec->ps_cur_sps->u2_max_mb_addr)
1743 break;
1744
1745 ps_cur_mb_info = ps_dec->ps_nmb_info + u1_num_mbs;
1746 ps_dec->u4_num_mbs_cur_nmb = u1_num_mbs;
1747
1748 ps_cur_mb_info->u1_Mux = 0;
1749 ps_dec->u4_num_pmbair = (u1_num_mbs >> u1_mbaff);
1750 ps_cur_deblk_mb = ps_dec->ps_deblk_mbn + u1_num_mbs;
1751
1752 ps_cur_mb_info->u1_end_of_slice = 0;
1753
1754 /* Storing Default partition info */
1755 ps_parse_mb_data->u1_num_part = 1;
1756 ps_parse_mb_data->u1_isI_mb = 0;
1757
1758 /**************************************************************/
1759 /* Get the required information for decoding of MB */
1760 /**************************************************************/
1761 /* mb_x, mb_y, neighbor availablity, */
1762 if (u1_mbaff)
1763 ih264d_get_mb_info_cavlc_mbaff(ps_dec, i2_cur_mb_addr, ps_cur_mb_info, i2_mb_skip_run);
1764 else
1765 ih264d_get_mb_info_cavlc_nonmbaff(ps_dec, i2_cur_mb_addr, ps_cur_mb_info, i2_mb_skip_run);
1766
1767 /* Set the deblocking parameters for this MB */
1768 if(ps_dec->u4_app_disable_deblk_frm == 0)
1769 {
1770 ih264d_set_deblocking_parameters(ps_cur_deblk_mb, ps_slice,
1771 ps_dec->u1_mb_ngbr_availablity,
1772 ps_dec->u1_cur_mb_fld_dec_flag);
1773 }
1774
1775 /* Set appropriate flags in ps_cur_mb_info and ps_dec */
1776 ps_dec->i1_prev_mb_qp_delta = 0;
1777 ps_dec->u1_sub_mb_num = 0;
1778 ps_cur_mb_info->u1_mb_type = MB_SKIP;
1779 ps_cur_mb_info->u1_mb_mc_mode = PRED_16x16;
1780 ps_cur_mb_info->u1_cbp = 0;
1781
1782 /* Storing Skip partition info */
1783 ps_part_info = ps_dec->ps_part;
1784 ps_part_info->u1_is_direct = PART_DIRECT_16x16;
1785 ps_part_info->u1_sub_mb_num = 0;
1786 ps_dec->ps_part++;
1787
1788 /* Update Nnzs */
1789 ih264d_update_nnz_for_skipmb(ps_dec, ps_cur_mb_info, CAVLC);
1790
1791 ps_cur_mb_info->ps_curmb->u1_mb_type = u1_inter_mb_type;
1792 ps_cur_deblk_mb->u1_mb_type |= u1_deblk_mb_type;
1793
1794 i2_mb_skip_run--;
1795
1796 ps_cur_deblk_mb->u1_mb_qp = ps_dec->u1_qp;
1797
1798 if (u1_mbaff)
1799 {
1800 ih264d_update_mbaff_left_nnz(ps_dec, ps_cur_mb_info);
1801 }
1802
1803 /**************************************************************/
1804 /* Get next Macroblock address */
1805 /**************************************************************/
1806 i2_cur_mb_addr++;
1807
1808 u1_num_mbs++;
Marco Nelissen8ef4c3f2015-06-03 07:26:32 -07001809 u1_num_mbsNby2++;
1810 ps_parse_mb_data++;
1811
1812 /****************************************************************/
1813 /* Check for End Of Row and other flags that determine when to */
1814 /* do DMA setup for N/2-Mb, Decode for N-Mb, and Transfer for */
1815 /* N-Mb */
1816 /****************************************************************/
1817 u1_num_mbs_next = i2_pic_wdin_mbs - ps_dec->u2_mbx - 1;
1818 u1_end_of_row = (!u1_num_mbs_next) && (!(u1_mbaff && (u1_num_mbs & 0x01)));
1819 u1_slice_end = !i2_mb_skip_run;
1820 u1_tfr_n_mb = (u1_num_mbs == ps_dec->u1_recon_mb_grp) || u1_end_of_row
1821 || u1_slice_end;
1822 u1_decode_nmb = u1_tfr_n_mb || u1_slice_end;
1823 ps_cur_mb_info->u1_end_of_slice = u1_slice_end;
1824
1825 if(u1_decode_nmb)
1826 {
1827 ps_dec->pf_mvpred_ref_tfr_nby2mb(ps_dec, u1_mb_idx, u1_num_mbs);
1828 u1_num_mbsNby2 = 0;
1829
1830 ps_parse_mb_data = ps_dec->ps_parse_mb_data;
1831 ps_dec->ps_part = ps_dec->ps_parse_part_params;
1832
1833 if(ps_dec->u1_separate_parse)
1834 {
1835 ih264d_parse_tfr_nmb(ps_dec, u1_mb_idx, u1_num_mbs,
1836 u1_num_mbs_next, u1_tfr_n_mb, u1_end_of_row);
1837 ps_dec->ps_nmb_info += u1_num_mbs;
1838 }
1839 else
1840 {
1841 ih264d_decode_recon_tfr_nmb(ps_dec, u1_mb_idx, u1_num_mbs, u1_num_mbs_next,
1842 u1_tfr_n_mb, u1_end_of_row);
1843 }
Harish Mahendrakar4a524d32016-01-07 16:59:02 +05301844 ps_dec->u2_total_mbs_coded += u1_num_mbs;
Marco Nelissen8ef4c3f2015-06-03 07:26:32 -07001845 if(u1_tfr_n_mb)
1846 u1_num_mbs = 0;
1847 u1_mb_idx = u1_num_mbs;
1848 ps_dec->u1_mb_idx = u1_num_mbs;
1849 }
1850 }
1851
1852 ps_dec->u4_num_mbs_cur_nmb = 0;
1853 ps_dec->ps_cur_slice->u4_mbs_in_slice = i2_cur_mb_addr
1854 - ps_dec->ps_parse_cur_slice->u4_first_mb_in_slice;
1855
1856 H264_DEC_DEBUG_PRINT("Mbs in slice: %d\n", ps_dec->ps_cur_slice->u4_mbs_in_slice);
1857
Hamsalekha S9f0dcba2015-06-09 15:54:31 +05301858
1859 /* incremented here only if first slice is inserted */
1860 if(ps_dec->u4_first_slice_in_pic != 0)
Harish Mahendrakar5e4f64c2016-06-01 13:31:45 +05301861 {
Hamsalekha S9f0dcba2015-06-09 15:54:31 +05301862 ps_dec->ps_parse_cur_slice++;
Harish Mahendrakar5e4f64c2016-06-01 13:31:45 +05301863 ps_dec->u2_cur_slice_num++;
1864 }
Hamsalekha S9f0dcba2015-06-09 15:54:31 +05301865
Marco Nelissen8ef4c3f2015-06-03 07:26:32 -07001866 ps_dec->i2_prev_slice_mbx = ps_dec->u2_mbx;
1867 ps_dec->i2_prev_slice_mby = ps_dec->u2_mby;
1868
1869 if(ps_dec->u2_total_mbs_coded
1870 >= ps_dec->u2_frm_ht_in_mbs * ps_dec->u2_frm_wd_in_mbs)
1871 {
1872 ps_dec->u1_pic_decode_done = 1;
Marco Nelissen8ef4c3f2015-06-03 07:26:32 -07001873 }
1874
1875 return 0;
1876
Hamsalekha S8d3d3032015-03-13 21:24:58 +05301877}
1878
1879/*!
1880 **************************************************************************
1881 * \if Function name : ih264d_decode_pslice \endif
1882 *
1883 * \brief
1884 * Decodes a P Slice
1885 *
1886 *
1887 * \return
1888 * 0 on Success and Error code otherwise
1889 **************************************************************************
1890 */
1891WORD32 ih264d_parse_pslice(dec_struct_t *ps_dec, UWORD16 u2_first_mb_in_slice)
1892{
1893 dec_pic_params_t * ps_pps = ps_dec->ps_cur_pps;
1894 dec_slice_params_t * ps_cur_slice = ps_dec->ps_cur_slice;
1895 dec_bit_stream_t *ps_bitstrm = ps_dec->ps_bitstrm;
1896 UWORD32 *pu4_bitstrm_buf = ps_bitstrm->pu4_buffer;
1897 UWORD32 *pu4_bitstrm_ofst = &ps_bitstrm->u4_ofst;
1898 UWORD8 u1_mbaff = ps_dec->ps_cur_slice->u1_mbaff_frame_flag; //ps_dec->ps_cur_sps->u1_mb_aff_flag;
1899 UWORD8 u1_field_pic_flag = ps_cur_slice->u1_field_pic_flag;
1900
1901 UWORD32 u4_temp;
1902 WORD32 i_temp;
1903 WORD32 ret;
1904
1905 /*--------------------------------------------------------------------*/
1906 /* Read remaining contents of the slice header */
1907 /*--------------------------------------------------------------------*/
1908 {
1909 WORD8 *pi1_buf;
1910 WORD16 *pi2_mv = ps_dec->s_default_mv_pred.i2_mv;
1911 WORD32 *pi4_mv = (WORD32*)pi2_mv;
1912 WORD16 *pi16_refFrame;
1913
1914 pi1_buf = ps_dec->s_default_mv_pred.i1_ref_frame;
1915 pi16_refFrame = (WORD16*)pi1_buf;
1916 *pi4_mv = 0;
1917 *(pi4_mv + 1) = 0;
1918 *pi16_refFrame = OUT_OF_RANGE_REF;
1919 ps_dec->s_default_mv_pred.u1_col_ref_pic_idx = (UWORD8)-1;
1920 ps_dec->s_default_mv_pred.u1_pic_type = (UWORD8)-1;
1921 }
1922
1923 ps_cur_slice->u1_num_ref_idx_active_override_flag = ih264d_get_bit_h264(
1924 ps_bitstrm);
1925
1926 COPYTHECONTEXT("SH: num_ref_idx_override_flag",
1927 ps_cur_slice->u1_num_ref_idx_active_override_flag);
1928
1929 u4_temp = ps_dec->ps_cur_pps->u1_num_ref_idx_lx_active[0];
1930 if(ps_cur_slice->u1_num_ref_idx_active_override_flag)
1931 {
1932 u4_temp = ih264d_uev(pu4_bitstrm_ofst, pu4_bitstrm_buf) + 1;
1933 }
1934
1935 {
1936
1937
1938
1939 UWORD8 u1_max_ref_idx = MAX_FRAMES << u1_field_pic_flag;
1940 if(u4_temp > u1_max_ref_idx)
1941 {
1942 return ERROR_NUM_REF;
1943 }
1944 ps_cur_slice->u1_num_ref_idx_lx_active[0] = u4_temp;
1945 COPYTHECONTEXT("SH: num_ref_idx_l0_active_minus1",
1946 ps_cur_slice->u1_num_ref_idx_lx_active[0] - 1);
1947
1948 }
1949
1950 {
1951 UWORD8 uc_refIdxReFlagL0 = ih264d_get_bit_h264(ps_bitstrm);
1952 COPYTHECONTEXT("SH: ref_pic_list_reordering_flag_l0",uc_refIdxReFlagL0);
1953
1954 /* Initialize the Reference list once in Picture if the slice type */
1955 /* of first slice is between 5 to 9 defined in table 7.3 of standard */
1956 /* If picture contains both P & B slices then Initialize the Reference*/
1957 /* List only when it switches from P to B and B to P */
1958 {
1959 UWORD8 init_idx_flg = (ps_dec->u1_pr_sl_type
1960 != ps_dec->ps_cur_slice->u1_slice_type);
1961 if(ps_dec->u1_first_pb_nal_in_pic
1962 || (init_idx_flg & !ps_dec->u1_sl_typ_5_9)
1963 || ps_dec->u1_num_ref_idx_lx_active_prev
1964 != ps_cur_slice->u1_num_ref_idx_lx_active[0])
1965 {
1966 ih264d_init_ref_idx_lx_p(ps_dec);
1967 }
1968 if(ps_dec->u1_first_pb_nal_in_pic & ps_dec->u1_sl_typ_5_9)
1969 ps_dec->u1_first_pb_nal_in_pic = 0;
1970 }
1971 /* Store the value for future slices in the same picture */
1972 ps_dec->u1_num_ref_idx_lx_active_prev =
1973 ps_cur_slice->u1_num_ref_idx_lx_active[0];
1974
1975 /* Modified temporarily */
1976 if(uc_refIdxReFlagL0)
1977 {
1978 WORD8 ret;
1979 ps_dec->ps_ref_pic_buf_lx[0] = ps_dec->ps_dpb_mgr->ps_mod_dpb[0];
1980 ret = ih264d_ref_idx_reordering(ps_dec, 0);
1981 if(ret == -1)
1982 return ERROR_REFIDX_ORDER_T;
1983 ps_dec->ps_ref_pic_buf_lx[0] = ps_dec->ps_dpb_mgr->ps_mod_dpb[0];
1984 }
1985 else
1986 ps_dec->ps_ref_pic_buf_lx[0] =
1987 ps_dec->ps_dpb_mgr->ps_init_dpb[0];
1988 }
1989 /* Create refIdx to POC mapping */
1990 {
1991 void **pui_map_ref_idx_to_poc_lx0, **pui_map_ref_idx_to_poc_lx1;
1992 WORD8 idx;
1993 struct pic_buffer_t *ps_pic;
1994
1995 pui_map_ref_idx_to_poc_lx0 = ps_dec->ppv_map_ref_idx_to_poc + FRM_LIST_L0;
1996 pui_map_ref_idx_to_poc_lx0[0] = 0; //For ref_idx = -1
1997 pui_map_ref_idx_to_poc_lx0++;
1998 for(idx = 0; idx < ps_cur_slice->u1_num_ref_idx_lx_active[0]; idx++)
1999 {
2000 ps_pic = ps_dec->ps_ref_pic_buf_lx[0][idx];
2001 pui_map_ref_idx_to_poc_lx0[idx] = (ps_pic->pu1_buf1);
2002 }
2003
2004 /* Bug Fix Deblocking */
2005 pui_map_ref_idx_to_poc_lx1 = ps_dec->ppv_map_ref_idx_to_poc + FRM_LIST_L1;
2006 pui_map_ref_idx_to_poc_lx1[0] = 0;
2007
2008 if(u1_mbaff)
2009 {
2010 void **ppv_map_ref_idx_to_poc_lx_t, **ppv_map_ref_idx_to_poc_lx_b;
2011 void **ppv_map_ref_idx_to_poc_lx_t1, **ppv_map_ref_idx_to_poc_lx_b1;
2012 ppv_map_ref_idx_to_poc_lx_t = ps_dec->ppv_map_ref_idx_to_poc
2013 + TOP_LIST_FLD_L0;
2014 ppv_map_ref_idx_to_poc_lx_b = ps_dec->ppv_map_ref_idx_to_poc
2015 + BOT_LIST_FLD_L0;
2016
2017 ppv_map_ref_idx_to_poc_lx_t[0] = 0; // For ref_idx = -1
2018 ppv_map_ref_idx_to_poc_lx_t++;
2019 ppv_map_ref_idx_to_poc_lx_b[0] = 0; // For ref_idx = -1
2020 ppv_map_ref_idx_to_poc_lx_b++;
2021
2022 idx = 0;
2023 for(idx = 0; idx < ps_cur_slice->u1_num_ref_idx_lx_active[0]; idx++)
2024 {
2025 ps_pic = ps_dec->ps_ref_pic_buf_lx[0][idx];
2026 ppv_map_ref_idx_to_poc_lx_t[0] = (ps_pic->pu1_buf1);
2027 ppv_map_ref_idx_to_poc_lx_b[1] = (ps_pic->pu1_buf1);
2028
2029 ppv_map_ref_idx_to_poc_lx_b[0] = (ps_pic->pu1_buf1) + 1;
2030 ppv_map_ref_idx_to_poc_lx_t[1] = (ps_pic->pu1_buf1) + 1;
2031
2032 ppv_map_ref_idx_to_poc_lx_t += 2;
2033 ppv_map_ref_idx_to_poc_lx_b += 2;
2034 }
2035 ppv_map_ref_idx_to_poc_lx_t1 = ps_dec->ppv_map_ref_idx_to_poc
2036 + TOP_LIST_FLD_L1;
2037 ppv_map_ref_idx_to_poc_lx_t1[0] = 0;
2038 ppv_map_ref_idx_to_poc_lx_b1 = ps_dec->ppv_map_ref_idx_to_poc
2039 + BOT_LIST_FLD_L1;
2040 ppv_map_ref_idx_to_poc_lx_b1[0] = 0;
2041
2042 }
2043
2044 if(ps_dec->u4_num_cores >= 3)
2045 {
2046 WORD32 num_entries;
2047 WORD32 size;
2048
2049 num_entries = MIN(MAX_FRAMES, ps_dec->u4_num_ref_frames_at_init);
2050 num_entries = 2 * ((2 * num_entries) + 1);
2051
2052 size = num_entries * sizeof(void *);
2053 size += PAD_MAP_IDX_POC * sizeof(void *);
2054
2055 memcpy((void *)ps_dec->ps_parse_cur_slice->ppv_map_ref_idx_to_poc,
2056 ps_dec->ppv_map_ref_idx_to_poc,
2057 size);
2058 }
2059
2060
2061 }
2062 if(ps_pps->u1_wted_pred_flag)
2063 {
2064 ret = ih264d_parse_pred_weight_table(ps_cur_slice, ps_bitstrm);
2065 if(ret != OK)
2066 return ret;
2067 ih264d_form_pred_weight_matrix(ps_dec);
2068 ps_dec->pu4_wt_ofsts = ps_dec->pu4_wts_ofsts_mat;
2069 }
2070 else
2071 {
2072 ps_dec->ps_cur_slice->u2_log2Y_crwd = 0;
2073 ps_dec->pu4_wt_ofsts = ps_dec->pu4_wts_ofsts_mat;
2074 }
2075
2076 ps_dec->ps_parse_cur_slice->u2_log2Y_crwd =
2077 ps_dec->ps_cur_slice->u2_log2Y_crwd;
2078
2079 if(u1_mbaff && (u1_field_pic_flag == 0))
2080 {
2081 ih264d_convert_frm_mbaff_list(ps_dec);
2082 }
2083
2084 /* G050 */
2085 if(ps_cur_slice->u1_nal_ref_idc != 0)
2086 {
2087 if(!ps_dec->ps_dpb_cmds->u1_dpb_commands_read)
Naveen Kumar Ponnusamy943323f2015-12-04 16:51:43 +05302088 {
2089 i_temp = ih264d_read_mmco_commands(ps_dec);
2090 if (i_temp < 0)
2091 {
2092 return ERROR_DBP_MANAGER_T;
2093 }
2094 ps_dec->u4_bitoffset = i_temp;
2095 }
Hamsalekha S8d3d3032015-03-13 21:24:58 +05302096 else
2097 ps_bitstrm->u4_ofst += ps_dec->u4_bitoffset;
2098
2099 }
2100 /* G050 */
2101
2102 if(ps_pps->u1_entropy_coding_mode == CABAC)
2103 {
2104 u4_temp = ih264d_uev(pu4_bitstrm_ofst, pu4_bitstrm_buf);
2105
2106 if(u4_temp > MAX_CABAC_INIT_IDC)
2107 {
2108 return ERROR_INV_SLICE_HDR_T;
2109 }
2110 ps_cur_slice->u1_cabac_init_idc = u4_temp;
2111 COPYTHECONTEXT("SH: cabac_init_idc",ps_cur_slice->u1_cabac_init_idc);
2112 }
2113
2114 /* Read slice_qp_delta */
2115 i_temp = ps_pps->u1_pic_init_qp
2116 + ih264d_sev(pu4_bitstrm_ofst, pu4_bitstrm_buf);
2117 if((i_temp < 0) || (i_temp > 51))
2118 {
2119 return ERROR_INV_RANGE_QP_T;
2120 }
2121 ps_cur_slice->u1_slice_qp = i_temp;
2122 COPYTHECONTEXT("SH: slice_qp_delta",
2123 (WORD8)(ps_cur_slice->u1_slice_qp - ps_pps->u1_pic_init_qp));
2124
2125 if(ps_pps->u1_deblocking_filter_parameters_present_flag == 1)
2126 {
2127 u4_temp = ih264d_uev(pu4_bitstrm_ofst, pu4_bitstrm_buf);
2128 if(u4_temp > SLICE_BOUNDARY_DBLK_DISABLED)
2129 {
2130 return ERROR_INV_SLICE_HDR_T;
2131 }
2132
2133 COPYTHECONTEXT("SH: disable_deblocking_filter_idc", u4_temp);
2134 ps_cur_slice->u1_disable_dblk_filter_idc = u4_temp;
2135 if(u4_temp != 1)
2136 {
2137 i_temp = ih264d_sev(pu4_bitstrm_ofst, pu4_bitstrm_buf)
2138 << 1;
2139 if((MIN_DBLK_FIL_OFF > i_temp) || (i_temp > MAX_DBLK_FIL_OFF))
2140 {
2141 return ERROR_INV_SLICE_HDR_T;
2142 }
2143 ps_cur_slice->i1_slice_alpha_c0_offset = i_temp;
2144 COPYTHECONTEXT("SH: slice_alpha_c0_offset_div2",
2145 ps_cur_slice->i1_slice_alpha_c0_offset >> 1);
2146
2147 i_temp = ih264d_sev(pu4_bitstrm_ofst, pu4_bitstrm_buf)
2148 << 1;
2149 if((MIN_DBLK_FIL_OFF > i_temp) || (i_temp > MAX_DBLK_FIL_OFF))
2150 {
2151 return ERROR_INV_SLICE_HDR_T;
2152 }
2153 ps_cur_slice->i1_slice_beta_offset = i_temp;
2154 COPYTHECONTEXT("SH: slice_beta_offset_div2",
2155 ps_cur_slice->i1_slice_beta_offset >> 1);
2156 }
2157 else
2158 {
2159 ps_cur_slice->i1_slice_alpha_c0_offset = 0;
2160 ps_cur_slice->i1_slice_beta_offset = 0;
2161 }
2162 }
2163 else
2164 {
2165 ps_cur_slice->u1_disable_dblk_filter_idc = 0;
2166 ps_cur_slice->i1_slice_alpha_c0_offset = 0;
2167 ps_cur_slice->i1_slice_beta_offset = 0;
2168 }
2169
Marco Nelissen8ef4c3f2015-06-03 07:26:32 -07002170 ps_dec->u1_slice_header_done = 2;
Hamsalekha S8d3d3032015-03-13 21:24:58 +05302171
2172 if(ps_pps->u1_entropy_coding_mode)
2173 {
2174 SWITCHOFFTRACE; SWITCHONTRACECABAC;
2175 ps_dec->pf_parse_inter_slice = ih264d_parse_inter_slice_data_cabac;
Hamsalekha S8d3d3032015-03-13 21:24:58 +05302176 ps_dec->pf_parse_inter_mb = ih264d_parse_pmb_cabac;
2177 ih264d_init_cabac_contexts(P_SLICE, ps_dec);
2178
2179 if(ps_dec->ps_cur_slice->u1_mbaff_frame_flag)
2180 ps_dec->pf_get_mb_info = ih264d_get_mb_info_cabac_mbaff;
2181 else
2182 ps_dec->pf_get_mb_info = ih264d_get_mb_info_cabac_nonmbaff;
2183 }
2184 else
2185 {
2186 SWITCHONTRACE; SWITCHOFFTRACECABAC;
2187 ps_dec->pf_parse_inter_slice = ih264d_parse_inter_slice_data_cavlc;
2188 ps_dec->pf_parse_inter_mb = ih264d_parse_pmb_cavlc;
2189 if(ps_dec->ps_cur_slice->u1_mbaff_frame_flag)
2190 {
2191 ps_dec->pf_get_mb_info = ih264d_get_mb_info_cavlc_mbaff;
2192 }
2193 else
2194 ps_dec->pf_get_mb_info = ih264d_get_mb_info_cavlc_nonmbaff;
2195 }
2196
2197 ps_dec->u1_B = 0;
2198 ps_dec->pf_mvpred_ref_tfr_nby2mb = ih264d_mv_pred_ref_tfr_nby2_pmb;
2199 ret = ps_dec->pf_parse_inter_slice(ps_dec, ps_cur_slice, u2_first_mb_in_slice);
2200 if(ret != OK)
2201 return ret;
2202// ps_dec->curr_slice_in_error = 0 ;
2203 return OK;
2204}