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 * \file ih264d_parse_slice.c
23 *
24 * \brief
25 * Contains routines that decodes a slice NAL unit
26 *
27 * \date
28 * 19/12/2002
29 *
30 * \author AI
31 **************************************************************************
32 */
33 #include <string.h>
34 #include "ih264_typedefs.h"
35 #include "ih264_macros.h"
36 #include "ih264_platform_macros.h"
37 #include "ithread.h"
38 #include "ih264d_structs.h"
39 #include "ih264d_debug.h"
40 #include "ih264d_bitstrm.h"
41 #include "ih264d_parse_mb_header.h"
42 #include "ih264d_process_bslice.h"
43 #include "ih264d_process_pslice.h"
44 #include "ih264d_parse_cavlc.h"
45 #include "ih264d_utils.h"
46 #include "ih264d_deblocking.h"
47 #include "ih264d_defs.h"
48 #include "ih264d_error_handler.h"
49 #include "ih264d_tables.h"
50 #include "ih264d_defs.h"
51 #include "ih264d_mem_request.h"
52 #include "ih264d_parse_islice.h"
53 #include "ih264d_parse_slice.h"
54 #include "ih264d_mvpred.h"
55 #include "ih264d_mb_utils.h"
56
57 #include "ih264d_defs.h"
58 #include "ih264d_quant_scaling.h"
59
60 #include "ih264d_inter_pred.h"
61
62 #include "ih264d_sei.h"
63 #include "ih264d.h"
64 #include "ih264_error.h"
65 #include "ih264_disp_mgr.h"
66 #include "ih264_buf_mgr.h"
67
68 #include "ih264d_thread_parse_decode.h"
69 #include "ih264d_thread_compute_bs.h"
70 #include "ih264d_dpb_manager.h"
71 #include <assert.h>
72 #include "ih264d_parse_islice.h"
73 #define RET_LAST_SKIP 0x80000000
74
75 /*!
76 **************************************************************************
77 * \if Function name : ih264d_form_pred_weight_matrix \endif
78 *
79 * \brief
80 * Forms pred weight matrix.
81 *
82 * \return
83 * None
84 *
85 **************************************************************************
86 */
87
ih264d_form_pred_weight_matrix(dec_struct_t * ps_dec)88 void ih264d_form_pred_weight_matrix(dec_struct_t *ps_dec)
89 {
90 dec_slice_params_t *ps_cur_slice;
91 UWORD8 uc_num_ref_idx_l0_active, uc_num_ref_idx_l1_active;
92 UWORD8 i, j;
93 UWORD32 *pu4_mat_iwt_ofst;
94 UWORD16 i2_idx;
95 UWORD32 *pui32_weight_offset_l0, *pui32_weight_offset_l1;
96 UWORD32 u4_temp;
97
98 ps_cur_slice = ps_dec->ps_cur_slice;
99 uc_num_ref_idx_l0_active = ps_cur_slice->u1_num_ref_idx_lx_active[0];
100 uc_num_ref_idx_l1_active = ps_cur_slice->u1_num_ref_idx_lx_active[1];
101
102 pu4_mat_iwt_ofst = ps_dec->pu4_wts_ofsts_mat;
103
104 if(ps_cur_slice->u1_slice_type == B_SLICE)
105 {
106 for(i = 0; i < uc_num_ref_idx_l0_active; i++)
107 {
108 pui32_weight_offset_l0 = ps_cur_slice->u4_wt_ofst_lx[0][i];
109 for(j = 0; j < uc_num_ref_idx_l1_active; j++)
110 {
111 pui32_weight_offset_l1 = ps_cur_slice->u4_wt_ofst_lx[1][j];
112 i2_idx = i * uc_num_ref_idx_l0_active + j;
113 i2_idx = X3(i2_idx);
114 /* u4_temp = (pui32_weight_offset_l0[0] | (pui32_weight_offset_l1[0] << 16));
115 pu4_mat_iwt_ofst[0] = u4_temp;
116 u4_temp = (pui32_weight_offset_l0[1] | (pui32_weight_offset_l1[1] << 16));
117 pu4_mat_iwt_ofst[1] = u4_temp;
118 u4_temp = (pui32_weight_offset_l0[2] | (pui32_weight_offset_l1[2] << 16));
119 pu4_mat_iwt_ofst[2] = u4_temp;
120 pu4_mat_iwt_ofst += 3;*/
121 pu4_mat_iwt_ofst[0] = pui32_weight_offset_l0[0];
122 pu4_mat_iwt_ofst[1] = pui32_weight_offset_l1[0];
123 pu4_mat_iwt_ofst[2] = pui32_weight_offset_l0[1];
124 pu4_mat_iwt_ofst[3] = pui32_weight_offset_l1[1];
125 pu4_mat_iwt_ofst[4] = pui32_weight_offset_l0[2];
126 pu4_mat_iwt_ofst[5] = pui32_weight_offset_l1[2];
127 pu4_mat_iwt_ofst += 6;
128 }
129 }
130 }
131 else
132 {
133 for(i = 0; i < uc_num_ref_idx_l0_active; i++)
134 {
135 pui32_weight_offset_l0 = ps_cur_slice->u4_wt_ofst_lx[0][i];
136 i2_idx = X3(i);
137 u4_temp = (UWORD32)pui32_weight_offset_l0[0];
138 pu4_mat_iwt_ofst[0] = u4_temp;
139 u4_temp = (UWORD32)pui32_weight_offset_l0[1];
140 pu4_mat_iwt_ofst[2] = u4_temp;
141 u4_temp = (UWORD32)pui32_weight_offset_l0[2];
142 pu4_mat_iwt_ofst[4] = u4_temp;
143 pu4_mat_iwt_ofst += 6;
144 }
145 }
146 }
147
148
149 /*!
150 **************************************************************************
151 * \if Function name : init_firstSliceParam \endif
152 *
153 * \brief
154 * Initialize the Parameter required for all the slices for a picture
155 *
156 * \return : Nothing
157 *
158 **************************************************************************
159 */
160
ih264d_start_of_pic(dec_struct_t * ps_dec,WORD32 i4_poc,pocstruct_t * ps_temp_poc,UWORD16 u2_frame_num,dec_pic_params_t * ps_pps)161 WORD32 ih264d_start_of_pic(dec_struct_t *ps_dec,
162 WORD32 i4_poc,
163 pocstruct_t *ps_temp_poc,
164 UWORD16 u2_frame_num,
165 dec_pic_params_t *ps_pps)
166 {
167 pocstruct_t *ps_prev_poc = &ps_dec->s_cur_pic_poc;
168 pocstruct_t *ps_cur_poc = ps_temp_poc;
169
170 pic_buffer_t *pic_buf;
171
172 ivd_video_decode_op_t * ps_dec_output =
173 (ivd_video_decode_op_t *)ps_dec->pv_dec_out;
174 dec_slice_params_t *ps_cur_slice = ps_dec->ps_cur_slice;
175 dec_seq_params_t *ps_seq = ps_pps->ps_sps;
176 UWORD8 u1_bottom_field_flag = ps_cur_slice->u1_bottom_field_flag;
177 UWORD8 u1_field_pic_flag = ps_cur_slice->u1_field_pic_flag;
178 /* high profile related declarations */
179 high_profile_tools_t s_high_profile;
180 WORD32 ret;
181
182 H264_MUTEX_LOCK(&ps_dec->process_disp_mutex);
183
184 ps_prev_poc->i4_pic_order_cnt_lsb = ps_cur_poc->i4_pic_order_cnt_lsb;
185 ps_prev_poc->i4_pic_order_cnt_msb = ps_cur_poc->i4_pic_order_cnt_msb;
186 ps_prev_poc->i4_delta_pic_order_cnt_bottom =
187 ps_cur_poc->i4_delta_pic_order_cnt_bottom;
188 ps_prev_poc->i4_delta_pic_order_cnt[0] =
189 ps_cur_poc->i4_delta_pic_order_cnt[0];
190 ps_prev_poc->i4_delta_pic_order_cnt[1] =
191 ps_cur_poc->i4_delta_pic_order_cnt[1];
192 ps_prev_poc->u1_bot_field = ps_dec->ps_cur_slice->u1_bottom_field_flag;
193 ps_prev_poc->i4_prev_frame_num_ofst = ps_cur_poc->i4_prev_frame_num_ofst;
194 ps_prev_poc->u2_frame_num = u2_frame_num;
195 ps_dec->i1_prev_mb_qp_delta = 0;
196 ps_dec->i1_next_ctxt_idx = 0;
197
198
199 ps_dec->u4_nmb_deblk = 0;
200 if(ps_dec->u4_num_cores == 1)
201 ps_dec->u4_nmb_deblk = 1;
202
203
204
205 if(ps_seq->u1_mb_aff_flag == 1)
206 {
207 ps_dec->u4_nmb_deblk = 0;
208 if(ps_dec->u4_num_cores > 2)
209 ps_dec->u4_num_cores = 2;
210 }
211
212 ps_dec->u4_use_intrapred_line_copy = 0;
213
214
215
216 if (ps_seq->u1_mb_aff_flag == 0)
217 {
218 ps_dec->u4_use_intrapred_line_copy = 1;
219 }
220
221 ps_dec->u4_app_disable_deblk_frm = 0;
222 /* If degrade is enabled, set the degrade flags appropriately */
223 if(ps_dec->i4_degrade_type && ps_dec->i4_degrade_pics)
224 {
225 WORD32 degrade_pic;
226 ps_dec->i4_degrade_pic_cnt++;
227 degrade_pic = 0;
228
229 /* If degrade is to be done in all frames, then do not check further */
230 switch(ps_dec->i4_degrade_pics)
231 {
232 case 4:
233 {
234 degrade_pic = 1;
235 break;
236 }
237 case 3:
238 {
239 if(ps_cur_slice->u1_slice_type != I_SLICE)
240 degrade_pic = 1;
241
242 break;
243 }
244 case 2:
245 {
246
247 /* If pic count hits non-degrade interval or it is an islice, then do not degrade */
248 if((ps_cur_slice->u1_slice_type != I_SLICE)
249 && (ps_dec->i4_degrade_pic_cnt
250 != ps_dec->i4_nondegrade_interval))
251 degrade_pic = 1;
252
253 break;
254 }
255 case 1:
256 {
257 /* Check if the current picture is non-ref */
258 if(0 == ps_cur_slice->u1_nal_ref_idc)
259 {
260 degrade_pic = 1;
261 }
262 break;
263 }
264
265 }
266 if(degrade_pic)
267 {
268 if(ps_dec->i4_degrade_type & 0x2)
269 ps_dec->u4_app_disable_deblk_frm = 1;
270
271 /* MC degrading is done only for non-ref pictures */
272 if(0 == ps_cur_slice->u1_nal_ref_idc)
273 {
274 if(ps_dec->i4_degrade_type & 0x4)
275 ps_dec->i4_mv_frac_mask = 0;
276
277 if(ps_dec->i4_degrade_type & 0x8)
278 ps_dec->i4_mv_frac_mask = 0;
279 }
280 }
281 else
282 ps_dec->i4_degrade_pic_cnt = 0;
283 }
284
285 {
286 dec_err_status_t * ps_err = ps_dec->ps_dec_err_status;
287 if((ps_cur_slice->u1_slice_type == I_SLICE)
288 || (ps_cur_slice->u1_slice_type == SI_SLICE))
289 ps_err->u1_cur_pic_type = PIC_TYPE_I;
290 else
291 ps_err->u1_cur_pic_type = PIC_TYPE_UNKNOWN;
292
293 if(ps_err->u1_pic_aud_i == PIC_TYPE_I)
294 {
295 ps_err->u1_cur_pic_type = PIC_TYPE_I;
296 ps_err->u1_pic_aud_i = PIC_TYPE_UNKNOWN;
297 }
298
299 if(ps_cur_slice->u1_nal_unit_type == IDR_SLICE_NAL)
300 {
301 if(ps_err->u1_err_flag)
302 ih264d_reset_ref_bufs(ps_dec->ps_dpb_mgr);
303 ps_err->u1_err_flag = ACCEPT_ALL_PICS;
304 }
305 }
306
307 if(ps_dec->u1_init_dec_flag && ps_dec->s_prev_seq_params.u1_eoseq_pending)
308 {
309 /* Reset the decoder picture buffers */
310 WORD32 j;
311 for(j = 0; j < MAX_DISP_BUFS_NEW; j++)
312 {
313
314 ih264_buf_mgr_release((buf_mgr_t *)ps_dec->pv_pic_buf_mgr,
315 j,
316 BUF_MGR_REF);
317 ih264_buf_mgr_release((buf_mgr_t *)ps_dec->pv_mv_buf_mgr,
318 ps_dec->au1_pic_buf_id_mv_buf_id_map[j],
319 BUF_MGR_REF);
320 ih264_buf_mgr_release((buf_mgr_t *)ps_dec->pv_pic_buf_mgr,
321 j,
322 BUF_MGR_IO);
323 }
324
325 /* reset the decoder structure parameters related to buffer handling */
326 ps_dec->u1_second_field = 0;
327 ps_dec->i4_cur_display_seq = 0;
328
329 /********************************************************************/
330 /* indicate in the decoder output i4_status that some frames are being */
331 /* dropped, so that it resets timestamp and wait for a new sequence */
332 /********************************************************************/
333
334 ps_dec->s_prev_seq_params.u1_eoseq_pending = 0;
335 }
336 ret = ih264d_init_pic(ps_dec, u2_frame_num, i4_poc, ps_pps);
337 if(ret != OK)
338 return ret;
339
340 ps_dec->pv_parse_tu_coeff_data = ps_dec->pv_pic_tu_coeff_data;
341 ps_dec->pv_proc_tu_coeff_data = ps_dec->pv_pic_tu_coeff_data;
342 ps_dec->ps_nmb_info = ps_dec->ps_frm_mb_info;
343 if(ps_dec->u1_separate_parse)
344 {
345 UWORD16 pic_wd;
346 UWORD16 pic_ht;
347 UWORD32 num_mbs;
348
349 pic_wd = ps_dec->u2_pic_wd;
350 pic_ht = ps_dec->u2_pic_ht;
351 num_mbs = (pic_wd * pic_ht) >> 8;
352
353 if(ps_dec->pu1_dec_mb_map)
354 {
355 memset((void *)ps_dec->pu1_dec_mb_map, 0, num_mbs);
356 }
357
358 if(ps_dec->pu1_recon_mb_map)
359 {
360
361 memset((void *)ps_dec->pu1_recon_mb_map, 0, num_mbs);
362 }
363
364 if(ps_dec->pu2_slice_num_map)
365 {
366 memset((void *)ps_dec->pu2_slice_num_map, 0,
367 (num_mbs * sizeof(UWORD16)));
368 }
369
370 }
371
372 ps_dec->ps_parse_cur_slice = &(ps_dec->ps_dec_slice_buf[0]);
373 ps_dec->ps_decode_cur_slice = &(ps_dec->ps_dec_slice_buf[0]);
374 ps_dec->ps_computebs_cur_slice = &(ps_dec->ps_dec_slice_buf[0]);
375 ps_dec->u2_cur_slice_num = 0;
376
377 /* Initialize all the HP toolsets to zero */
378 ps_dec->s_high_profile.u1_scaling_present = 0;
379 ps_dec->s_high_profile.u1_transform8x8_present = 0;
380
381 /* Get Next Free Picture */
382 if(1 == ps_dec->u4_share_disp_buf)
383 {
384 UWORD32 i;
385 /* Free any buffer that is in the queue to be freed */
386 for(i = 0; i < MAX_DISP_BUFS_NEW; i++)
387 {
388 if(0 == ps_dec->u4_disp_buf_to_be_freed[i])
389 continue;
390 ih264_buf_mgr_release((buf_mgr_t *)ps_dec->pv_pic_buf_mgr, i,
391 BUF_MGR_IO);
392 ps_dec->u4_disp_buf_to_be_freed[i] = 0;
393 ps_dec->u4_disp_buf_mapping[i] = 0;
394
395 }
396 }
397 if(!(u1_field_pic_flag && 0 != ps_dec->u1_top_bottom_decoded)) //ps_dec->u1_second_field))
398 {
399 pic_buffer_t *ps_cur_pic;
400 WORD32 cur_pic_buf_id, cur_mv_buf_id;
401 col_mv_buf_t *ps_col_mv;
402 while(1)
403 {
404 ps_cur_pic = (pic_buffer_t *)ih264_buf_mgr_get_next_free(
405 (buf_mgr_t *)ps_dec->pv_pic_buf_mgr,
406 &cur_pic_buf_id);
407 if(ps_cur_pic == NULL)
408 {
409 ps_dec->i4_error_code = ERROR_UNAVAIL_PICBUF_T;
410 return ERROR_UNAVAIL_PICBUF_T;
411 }
412 if(0 == ps_dec->u4_disp_buf_mapping[cur_pic_buf_id])
413 {
414 break;
415 }
416
417 }
418 ps_col_mv = (col_mv_buf_t *)ih264_buf_mgr_get_next_free((buf_mgr_t *)ps_dec->pv_mv_buf_mgr,
419 &cur_mv_buf_id);
420 if(ps_col_mv == NULL)
421 {
422 ps_dec->i4_error_code = ERROR_UNAVAIL_MVBUF_T;
423 return ERROR_UNAVAIL_MVBUF_T;
424 }
425
426 ps_dec->ps_cur_pic = ps_cur_pic;
427 ps_dec->u1_pic_buf_id = cur_pic_buf_id;
428 ps_cur_pic->u4_ts = ps_dec->u4_ts;
429
430
431 ps_cur_pic->u1_mv_buf_id = cur_mv_buf_id;
432 ps_dec->au1_pic_buf_id_mv_buf_id_map[cur_pic_buf_id] = cur_mv_buf_id;
433
434 ps_cur_pic->pu1_col_zero_flag = (UWORD8 *)ps_col_mv->pv_col_zero_flag;
435 ps_cur_pic->ps_mv = (mv_pred_t *)ps_col_mv->pv_mv;
436 ps_dec->au1_pic_buf_ref_flag[cur_pic_buf_id] = 0;
437
438 {
439 /*make first entry of list0 point to cur pic,so that if first Islice is in error, ref pic struct will have valid entries*/
440 ps_dec->ps_ref_pic_buf_lx[0] = ps_dec->ps_dpb_mgr->ps_init_dpb[0];
441 *(ps_dec->ps_dpb_mgr->ps_init_dpb[0][0]) = *ps_cur_pic;
442 /* Initialize for field reference as well */
443 *(ps_dec->ps_dpb_mgr->ps_init_dpb[0][MAX_REF_BUFS]) = *ps_cur_pic;
444 }
445
446 if(!ps_dec->ps_cur_pic)
447 {
448 WORD32 j;
449 H264_DEC_DEBUG_PRINT("------- Display Buffers Reset --------\n");
450 for(j = 0; j < MAX_DISP_BUFS_NEW; j++)
451 {
452
453 ih264_buf_mgr_release((buf_mgr_t *)ps_dec->pv_pic_buf_mgr,
454 j,
455 BUF_MGR_REF);
456 ih264_buf_mgr_release((buf_mgr_t *)ps_dec->pv_mv_buf_mgr,
457 ps_dec->au1_pic_buf_id_mv_buf_id_map[j],
458 BUF_MGR_REF);
459 ih264_buf_mgr_release((buf_mgr_t *)ps_dec->pv_pic_buf_mgr,
460 j,
461 BUF_MGR_IO);
462 }
463
464 ps_dec->i4_cur_display_seq = 0;
465 ps_dec->i4_prev_max_display_seq = 0;
466 ps_dec->i4_max_poc = 0;
467
468 ps_cur_pic = (pic_buffer_t *)ih264_buf_mgr_get_next_free(
469 (buf_mgr_t *)ps_dec->pv_pic_buf_mgr,
470 &cur_pic_buf_id);
471 if(ps_cur_pic == NULL)
472 {
473 ps_dec->i4_error_code = ERROR_UNAVAIL_PICBUF_T;
474 return ERROR_UNAVAIL_PICBUF_T;
475 }
476
477 ps_col_mv = (col_mv_buf_t *)ih264_buf_mgr_get_next_free((buf_mgr_t *)ps_dec->pv_mv_buf_mgr,
478 &cur_mv_buf_id);
479 if(ps_col_mv == NULL)
480 {
481 ps_dec->i4_error_code = ERROR_UNAVAIL_MVBUF_T;
482 return ERROR_UNAVAIL_MVBUF_T;
483 }
484
485 ps_dec->ps_cur_pic = ps_cur_pic;
486 ps_dec->u1_pic_buf_id = cur_pic_buf_id;
487 ps_cur_pic->u4_ts = ps_dec->u4_ts;
488 ps_dec->apv_buf_id_pic_buf_map[cur_pic_buf_id] = (void *)ps_cur_pic;
489
490 ps_cur_pic->u1_mv_buf_id = cur_mv_buf_id;
491 ps_dec->au1_pic_buf_id_mv_buf_id_map[cur_pic_buf_id] = cur_mv_buf_id;
492
493 ps_cur_pic->pu1_col_zero_flag = (UWORD8 *)ps_col_mv->pv_col_zero_flag;
494 ps_cur_pic->ps_mv = (mv_pred_t *)ps_col_mv->pv_mv;
495 ps_dec->au1_pic_buf_ref_flag[cur_pic_buf_id] = 0;
496
497 }
498
499 ps_dec->ps_cur_pic->u1_picturetype = u1_field_pic_flag;
500 ps_dec->ps_cur_pic->u4_pack_slc_typ = SKIP_NONE;
501 H264_DEC_DEBUG_PRINT("got a buffer\n");
502 }
503 else
504 {
505 H264_DEC_DEBUG_PRINT("did not get a buffer\n");
506 }
507
508 ps_dec->u4_pic_buf_got = 1;
509
510 ps_dec->ps_cur_pic->i4_poc = i4_poc;
511 ps_dec->ps_cur_pic->i4_frame_num = u2_frame_num;
512 ps_dec->ps_cur_pic->i4_pic_num = u2_frame_num;
513 ps_dec->ps_cur_pic->i4_top_field_order_cnt = ps_pps->i4_top_field_order_cnt;
514 ps_dec->ps_cur_pic->i4_bottom_field_order_cnt =
515 ps_pps->i4_bottom_field_order_cnt;
516 ps_dec->ps_cur_pic->i4_avg_poc = ps_pps->i4_avg_poc;
517 ps_dec->ps_cur_pic->u4_time_stamp = ps_dec->u4_pts;
518
519 ps_dec->s_cur_pic = *(ps_dec->ps_cur_pic);
520 if(u1_field_pic_flag && u1_bottom_field_flag)
521 {
522 WORD32 i4_temp_poc;
523 WORD32 i4_top_field_order_poc, i4_bot_field_order_poc;
524 /* Point to odd lines, since it's bottom field */
525 ps_dec->s_cur_pic.pu1_buf1 += ps_dec->s_cur_pic.u2_frm_wd_y;
526 ps_dec->s_cur_pic.pu1_buf2 += ps_dec->s_cur_pic.u2_frm_wd_uv;
527 ps_dec->s_cur_pic.pu1_buf3 += ps_dec->s_cur_pic.u2_frm_wd_uv;
528 ps_dec->s_cur_pic.ps_mv +=
529 ((ps_dec->u2_pic_ht * ps_dec->u2_pic_wd) >> 5);
530 ps_dec->s_cur_pic.pu1_col_zero_flag += ((ps_dec->u2_pic_ht
531 * ps_dec->u2_pic_wd) >> 5);
532 ps_dec->ps_cur_pic->u1_picturetype |= BOT_FLD;
533 i4_top_field_order_poc = ps_dec->ps_cur_pic->i4_top_field_order_cnt;
534 i4_bot_field_order_poc = ps_dec->ps_cur_pic->i4_bottom_field_order_cnt;
535 i4_temp_poc = MIN(i4_top_field_order_poc,
536 i4_bot_field_order_poc);
537 ps_dec->ps_cur_pic->i4_avg_poc = i4_temp_poc;
538 }
539
540 ps_cur_slice->u1_mbaff_frame_flag = ps_seq->u1_mb_aff_flag
541 && (!u1_field_pic_flag);
542
543 ps_dec->ps_cur_pic->u1_picturetype |= (ps_cur_slice->u1_mbaff_frame_flag
544 << 2);
545
546 ps_dec->ps_cur_mb_row = ps_dec->ps_nbr_mb_row; //[0];
547 //Increment by 2 ,so that left mb (mbaff decrements by 2) will always be valid
548 ps_dec->ps_cur_mb_row += 2;
549 ps_dec->ps_top_mb_row = ps_dec->ps_nbr_mb_row;
550 ps_dec->ps_top_mb_row += ((ps_dec->u2_frm_wd_in_mbs + 2) << (1 - ps_dec->ps_cur_sps->u1_frame_mbs_only_flag));
551 //Increment by 2 ,so that left mb (mbaff decrements by 2) will always be valid
552 ps_dec->ps_top_mb_row += 2;
553
554 /* CHANGED CODE */
555 ps_dec->ps_mv_cur = ps_dec->s_cur_pic.ps_mv;
556 ps_dec->ps_mv_top = ps_dec->ps_mv_top_p[0];
557 /* CHANGED CODE */
558 ps_dec->u1_mv_top_p = 0;
559 ps_dec->u1_mb_idx = 0;
560 /* CHANGED CODE */
561 ps_dec->ps_mv_left = ps_dec->s_cur_pic.ps_mv;
562 ps_dec->u2_total_mbs_coded = 0;
563 ps_dec->i4_submb_ofst = -(SUB_BLK_SIZE);
564 ps_dec->u4_pred_info_idx = 0;
565 ps_dec->u4_pred_info_pkd_idx = 0;
566 ps_dec->u4_dma_buf_idx = 0;
567 ps_dec->ps_mv = ps_dec->s_cur_pic.ps_mv;
568 ps_dec->ps_mv_bank_cur = ps_dec->s_cur_pic.ps_mv;
569 ps_dec->pu1_col_zero_flag = ps_dec->s_cur_pic.pu1_col_zero_flag;
570 ps_dec->ps_part = ps_dec->ps_parse_part_params;
571 ps_dec->i2_prev_slice_mbx = -1;
572 ps_dec->i2_prev_slice_mby = 0;
573 ps_dec->u2_mv_2mb[0] = 0;
574 ps_dec->u2_mv_2mb[1] = 0;
575 ps_dec->u1_last_pic_not_decoded = 0;
576
577 ps_dec->u2_cur_slice_num_dec_thread = 0;
578 ps_dec->u2_cur_slice_num_bs = 0;
579 ps_dec->u4_intra_pred_line_ofst = 0;
580 ps_dec->pu1_cur_y_intra_pred_line = ps_dec->pu1_y_intra_pred_line;
581 ps_dec->pu1_cur_u_intra_pred_line = ps_dec->pu1_u_intra_pred_line;
582 ps_dec->pu1_cur_v_intra_pred_line = ps_dec->pu1_v_intra_pred_line;
583
584 ps_dec->pu1_cur_y_intra_pred_line_base = ps_dec->pu1_y_intra_pred_line;
585 ps_dec->pu1_cur_u_intra_pred_line_base = ps_dec->pu1_u_intra_pred_line;
586 ps_dec->pu1_cur_v_intra_pred_line_base = ps_dec->pu1_v_intra_pred_line;
587
588
589
590
591
592 ps_dec->pu1_prev_y_intra_pred_line = ps_dec->pu1_y_intra_pred_line
593 + (ps_dec->u2_frm_wd_in_mbs * MB_SIZE);
594
595 ps_dec->pu1_prev_u_intra_pred_line = ps_dec->pu1_u_intra_pred_line
596 + ps_dec->u2_frm_wd_in_mbs * BLK8x8SIZE * YUV420SP_FACTOR;
597 ps_dec->pu1_prev_v_intra_pred_line = ps_dec->pu1_v_intra_pred_line
598 + ps_dec->u2_frm_wd_in_mbs * BLK8x8SIZE;
599
600 ps_dec->ps_deblk_mbn = ps_dec->ps_deblk_pic;
601 /* Initialize The Function Pointer Depending Upon the Entropy and MbAff Flag */
602 {
603 if(ps_cur_slice->u1_mbaff_frame_flag)
604 {
605 ps_dec->pf_compute_bs = ih264d_compute_bs_mbaff;
606 ps_dec->pf_mvpred = ih264d_mvpred_mbaff;
607 }
608 else
609 {
610 ps_dec->pf_compute_bs = ih264d_compute_bs_non_mbaff;
611 ps_dec->u1_cur_mb_fld_dec_flag = ps_cur_slice->u1_field_pic_flag;
612 }
613 }
614 /* Set up the Parameter for DMA transfer */
615 {
616 UWORD8 u1_field_pic_flag = ps_dec->ps_cur_slice->u1_field_pic_flag;
617
618 UWORD8 u1_mbaff = ps_cur_slice->u1_mbaff_frame_flag;
619
620 UWORD8 uc_lastmbs = (((ps_dec->u2_pic_wd) >> 4)
621 % (ps_dec->u1_recon_mb_grp >> u1_mbaff));
622 UWORD16 ui16_lastmbs_widthY =
623 (uc_lastmbs ? (uc_lastmbs << 4) : ((ps_dec->u1_recon_mb_grp
624 >> u1_mbaff) << 4));
625 UWORD16 ui16_lastmbs_widthUV =
626 uc_lastmbs ? (uc_lastmbs << 3) : ((ps_dec->u1_recon_mb_grp
627 >> u1_mbaff) << 3);
628
629 ps_dec->s_tran_addrecon.pu1_dest_y = ps_dec->s_cur_pic.pu1_buf1;
630 ps_dec->s_tran_addrecon.pu1_dest_u = ps_dec->s_cur_pic.pu1_buf2;
631 ps_dec->s_tran_addrecon.pu1_dest_v = ps_dec->s_cur_pic.pu1_buf3;
632
633 ps_dec->s_tran_addrecon.u2_frm_wd_y = ps_dec->u2_frm_wd_y
634 << u1_field_pic_flag;
635 ps_dec->s_tran_addrecon.u2_frm_wd_uv = ps_dec->u2_frm_wd_uv
636 << u1_field_pic_flag;
637
638 if(u1_field_pic_flag)
639 {
640 ui16_lastmbs_widthY += ps_dec->u2_frm_wd_y;
641 ui16_lastmbs_widthUV += ps_dec->u2_frm_wd_uv;
642 }
643
644 /* Normal Increment of Pointer */
645 ps_dec->s_tran_addrecon.u4_inc_y[0] = ((ps_dec->u1_recon_mb_grp << 4)
646 >> u1_mbaff);
647 ps_dec->s_tran_addrecon.u4_inc_uv[0] = ((ps_dec->u1_recon_mb_grp << 4)
648 >> u1_mbaff);
649
650 /* End of Row Increment */
651 ps_dec->s_tran_addrecon.u4_inc_y[1] = (ui16_lastmbs_widthY
652 + (PAD_LEN_Y_H << 1)
653 + ps_dec->s_tran_addrecon.u2_frm_wd_y
654 * ((15 << u1_mbaff) + u1_mbaff));
655 ps_dec->s_tran_addrecon.u4_inc_uv[1] = (ui16_lastmbs_widthUV
656 + (PAD_LEN_UV_H << 2)
657 + ps_dec->s_tran_addrecon.u2_frm_wd_uv
658 * ((15 << u1_mbaff) + u1_mbaff));
659
660 /* Assign picture numbers to each frame/field */
661 /* only once per picture. */
662 ih264d_assign_pic_num(ps_dec);
663 ps_dec->s_tran_addrecon.u2_mv_top_left_inc = (ps_dec->u1_recon_mb_grp
664 << 2) - 1 - (u1_mbaff << 2);
665 ps_dec->s_tran_addrecon.u2_mv_left_inc = ((ps_dec->u1_recon_mb_grp
666 >> u1_mbaff) - 1) << (4 + u1_mbaff);
667 }
668 /**********************************************************************/
669 /* High profile related initialization at pictrue level */
670 /**********************************************************************/
671 if(ps_seq->u1_profile_idc == HIGH_PROFILE_IDC)
672 {
673 if((ps_seq->i4_seq_scaling_matrix_present_flag)
674 || (ps_pps->i4_pic_scaling_matrix_present_flag))
675 {
676 ih264d_form_scaling_matrix_picture(ps_seq, ps_pps, ps_dec);
677 ps_dec->s_high_profile.u1_scaling_present = 1;
678 }
679 else
680 {
681 ih264d_form_default_scaling_matrix(ps_dec);
682 }
683
684 if(ps_pps->i4_transform_8x8_mode_flag)
685 {
686 ps_dec->s_high_profile.u1_transform8x8_present = 1;
687 }
688 }
689 else
690 {
691 ih264d_form_default_scaling_matrix(ps_dec);
692 }
693
694 /* required while reading the transform_size_8x8 u4_flag */
695 ps_dec->s_high_profile.u1_direct_8x8_inference_flag =
696 ps_seq->u1_direct_8x8_inference_flag;
697 ps_dec->s_high_profile.s_cavlc_ctxt = ps_dec->s_cavlc_ctxt;
698
699 ps_dec->i1_recon_in_thread3_flag = 1;
700 ps_dec->ps_frame_buf_ip_recon = &ps_dec->s_tran_addrecon;
701 if(ps_dec->u1_separate_parse)
702 {
703 memcpy(&ps_dec->s_tran_addrecon_parse, &ps_dec->s_tran_addrecon,
704 sizeof(tfr_ctxt_t));
705 if(ps_dec->u4_num_cores >= 3 && ps_dec->i1_recon_in_thread3_flag)
706 {
707 memcpy(&ps_dec->s_tran_iprecon, &ps_dec->s_tran_addrecon,
708 sizeof(tfr_ctxt_t));
709 ps_dec->ps_frame_buf_ip_recon = &ps_dec->s_tran_iprecon;
710 }
711 }
712
713
714 ih264d_init_deblk_tfr_ctxt(ps_dec,&(ps_dec->s_pad_mgr), &(ps_dec->s_tran_addrecon),
715 ps_dec->u2_frm_wd_in_mbs, 0);
716
717 ps_dec->ps_cur_deblk_mb = ps_dec->ps_deblk_pic;
718 ps_dec->u4_cur_deblk_mb_num = 0;
719
720 ps_dec->u4_deblk_mb_x = 0;
721 ps_dec->u4_deblk_mb_y = 0;
722 ps_dec->pu4_wt_ofsts = ps_dec->pu4_wts_ofsts_mat;
723
724 ps_dec->u4_first_slice_in_pic = 0;
725 H264_MUTEX_UNLOCK(&ps_dec->process_disp_mutex);
726 return OK;
727 }
728
729 /*!
730 **************************************************************************
731 * \if Function name : ih264d_deblock_display \endif
732 *
733 * \brief : The function callls the deblocking routine and manages
734 : the Recon buffers and displays .
735 * \return : Nothing
736 *
737 **************************************************************************
738 */
ih264d_end_of_pic_dispbuf_mgr(dec_struct_t * ps_dec)739 WORD32 ih264d_end_of_pic_dispbuf_mgr(dec_struct_t * ps_dec)
740 {
741 dec_slice_params_t *ps_cur_slice = ps_dec->ps_cur_slice;
742 UWORD8 u1_num_of_users = 0;
743 WORD32 ret;
744
745 H264_MUTEX_LOCK(&ps_dec->process_disp_mutex);
746 if(1)
747 {
748
749 {
750 ih264d_delete_nonref_nondisplay_pics(ps_dec->ps_dpb_mgr);
751 if(ps_cur_slice->u1_mmco_equalto5
752 || (ps_cur_slice->u1_nal_unit_type == IDR_SLICE_NAL))
753 {
754 ps_dec->ps_cur_pic->i4_poc = 0;
755 if(ps_dec->u2_total_mbs_coded
756 == (ps_dec->ps_cur_sps->u2_max_mb_addr + 1))
757 ih264d_reset_ref_bufs(ps_dec->ps_dpb_mgr);
758 ih264d_release_display_bufs(ps_dec);
759 }
760 if(IVD_DECODE_FRAME_OUT != ps_dec->e_frm_out_mode)
761 {
762 ret = ih264d_assign_display_seq(ps_dec);
763 if(ret != OK)
764 return ret;
765 }
766 }
767
768 if(ps_cur_slice->u1_nal_ref_idc)
769 {
770 /* Mark pic buf as needed for reference */
771 ih264_buf_mgr_set_status((buf_mgr_t *)ps_dec->pv_pic_buf_mgr,
772 ps_dec->u1_pic_buf_id,
773 BUF_MGR_REF);
774 /* Mark mv buf as needed for reference */
775 ih264_buf_mgr_set_status((buf_mgr_t *)ps_dec->pv_mv_buf_mgr,
776 ps_dec->au1_pic_buf_id_mv_buf_id_map[ps_dec->u1_pic_buf_id],
777 BUF_MGR_REF);
778 ps_dec->au1_pic_buf_ref_flag[ps_dec->u1_pic_buf_id] = 1;
779 }
780
781 /* 420 consumer */
782 /* Increment the number of users by 1 for display based upon */
783 /*the SEEK KEY FRAME control sent to decoder */
784 if(((0 == ps_dec->u1_last_pic_not_decoded)
785 && (0
786 == (ps_dec->ps_cur_pic->u4_pack_slc_typ
787 & ps_dec->u4_skip_frm_mask)))
788 || (ps_cur_slice->u1_nal_unit_type == IDR_SLICE_NAL))
789 {
790 /* Mark pic buf as needed for display */
791 ih264_buf_mgr_set_status((buf_mgr_t *)ps_dec->pv_pic_buf_mgr,
792 ps_dec->u1_pic_buf_id,
793 BUF_MGR_IO);
794
795 }
796
797 if(!ps_cur_slice->u1_field_pic_flag
798 || ((TOP_FIELD_ONLY | BOT_FIELD_ONLY)
799 != ps_dec->u1_top_bottom_decoded))
800 {
801 pic_buffer_t *ps_cur_pic = ps_dec->ps_cur_pic;
802 ps_cur_pic->u2_disp_width = ps_dec->u2_disp_width;
803 ps_cur_pic->u2_disp_height = ps_dec->u2_disp_height >> 1;
804
805 ps_cur_pic->u2_crop_offset_y = ps_dec->u2_crop_offset_y;
806 ps_cur_pic->u2_crop_offset_uv = ps_dec->u2_crop_offset_uv;
807 ps_cur_pic->u1_pic_type = 0;
808
809 ret = ih264d_insert_pic_in_display_list(
810 ps_dec->ps_dpb_mgr,
811 ps_dec->u1_pic_buf_id,
812 ps_dec->i4_prev_max_display_seq
813 + ps_dec->ps_cur_pic->i4_poc,
814 ps_dec->ps_cur_pic->i4_frame_num);
815 if(ret != OK)
816 return ret;
817
818 {
819 ivd_video_decode_op_t * ps_dec_output =
820 (ivd_video_decode_op_t *)ps_dec->pv_dec_out;
821
822 ps_dec_output->u4_frame_decoded_flag = 1;
823 }
824 if(ps_dec->au1_pic_buf_ref_flag[ps_dec->u1_pic_buf_id] == 0)
825 {
826 ih264_buf_mgr_release((buf_mgr_t *)ps_dec->pv_mv_buf_mgr,
827 ps_dec->au1_pic_buf_id_mv_buf_id_map[ps_dec->u1_pic_buf_id],
828 BUF_MGR_REF);
829 ps_dec->au1_pic_buf_ref_flag[ps_dec->u1_pic_buf_id] = 0;
830
831 }
832 }
833 else
834 {
835 H264_DEC_DEBUG_PRINT("pic not inserted display %d %d\n",
836 ps_cur_slice->u1_field_pic_flag,
837 ps_dec->u1_second_field);
838 }
839
840 if(!ps_cur_slice->u1_field_pic_flag
841 || ((TOP_FIELD_ONLY | BOT_FIELD_ONLY)
842 == ps_dec->u1_top_bottom_decoded))
843 {
844 if(IVD_DECODE_FRAME_OUT == ps_dec->e_frm_out_mode)
845 {
846 ret = ih264d_assign_display_seq(ps_dec);
847 if(ret != OK)
848 return ret;
849 }
850 }
851 }
852
853 H264_MUTEX_UNLOCK(&ps_dec->process_disp_mutex);
854
855 return OK;
856 }
857
ih264d_err_pic_dispbuf_mgr(dec_struct_t * ps_dec)858 void ih264d_err_pic_dispbuf_mgr(dec_struct_t *ps_dec)
859 {
860 dec_slice_params_t *ps_cur_slice = ps_dec->ps_cur_slice;
861 ivd_video_decode_op_t * ps_dec_output =
862 (ivd_video_decode_op_t *)ps_dec->pv_dec_out;
863
864 ih264_buf_mgr_release((buf_mgr_t *)ps_dec->pv_pic_buf_mgr,
865 ps_dec->u1_pic_buf_id,
866 BUF_MGR_REF);
867 ih264_buf_mgr_release((buf_mgr_t *)ps_dec->pv_mv_buf_mgr,
868 ps_dec->au1_pic_buf_id_mv_buf_id_map[ps_dec->u1_pic_buf_id],
869 BUF_MGR_REF);
870 ih264_buf_mgr_release((buf_mgr_t *)ps_dec->pv_pic_buf_mgr,
871 ps_dec->u1_pic_buf_id,
872 BUF_MGR_IO);
873 }
874
ih264d_deblock_picture(void * ptr)875 void ih264d_deblock_picture(void *ptr)
876 {
877 dec_struct_t *ps_dec = (dec_struct_t *)ptr;
878
879 {
880 /*Deblock picture only if all the mb's in the frame have been decoded*/
881 if(ps_dec->u1_pic_decode_done == 1)
882 {
883 if(ps_dec->ps_cur_slice->u1_mbaff_frame_flag
884 || ps_dec->ps_cur_slice->u1_field_pic_flag)
885 {
886 ps_dec->p_DeblockPicture[ps_dec->ps_cur_slice->u1_mbaff_frame_flag](
887 ps_dec);
888 }
889 else
890
891 {
892
893 ih264d_deblock_picture_progressive(ps_dec);
894 }
895
896 }
897 }
898
899 }
900
901 /*!
902 **************************************************************************
903 * \if Function name : ih264d_deblock_display \endif
904 *
905 * \brief : The function callls the deblocking routine and manages
906 : the Recon buffers and displays .
907 * \return : Nothing
908 *
909 **************************************************************************
910 */
ih264d_deblock_display(dec_struct_t * ps_dec)911 WORD32 ih264d_deblock_display(dec_struct_t *ps_dec)
912 {
913 WORD32 ret;
914 /* Call deblocking */
915 ih264d_deblock_picture(ps_dec);
916
917 ret = ih264d_end_of_pic_dispbuf_mgr(ps_dec);
918 if(ret != OK)
919 return ret;
920
921 return OK;
922 }
923
924 /*
925 *!
926 **************************************************************************
927 * \if Function name : EndofPoc \endif
928 *
929 * \brief
930 * EndofPoc Processing
931 *
932 * \return
933 * 0 on Success and Error code otherwise
934 **************************************************************************
935 */
936
ih264d_end_of_pic(dec_struct_t * ps_dec)937 WORD32 ih264d_end_of_pic(dec_struct_t *ps_dec)
938 {
939 dec_slice_params_t *ps_cur_slice = ps_dec->ps_cur_slice;
940 WORD32 ret;
941
942 {
943 dec_err_status_t * ps_err = ps_dec->ps_dec_err_status;
944 if(ps_err->u1_err_flag & REJECT_CUR_PIC)
945 {
946 ih264d_err_pic_dispbuf_mgr(ps_dec);
947 return ERROR_NEW_FRAME_EXPECTED;
948 }
949 }
950
951 H264_MUTEX_LOCK(&ps_dec->process_disp_mutex);
952 ret = ih264d_end_of_pic_processing(ps_dec);
953 if(ret != OK)
954 return ret;
955 /*--------------------------------------------------------------------*/
956 /* ih264d_decode_pic_order_cnt - calculate the Pic Order Cnt */
957 /* Needed to detect end of picture */
958 /*--------------------------------------------------------------------*/
959
960 H264_MUTEX_UNLOCK(&ps_dec->process_disp_mutex);
961
962 return OK;
963 }
964
965 /*!
966 **************************************************************************
967 * \if Function name : DecodeSlice \endif
968 *
969 * \brief
970 * Parses a slice
971 *
972 * \return
973 * 0 on Success and Error code otherwise
974 **************************************************************************
975 */
976
ih264d_parse_decode_slice(UWORD8 u1_is_idr_slice,UWORD8 u1_nal_ref_idc,dec_struct_t * ps_dec)977 WORD32 ih264d_parse_decode_slice(UWORD8 u1_is_idr_slice,
978 UWORD8 u1_nal_ref_idc,
979 dec_struct_t *ps_dec /* Decoder parameters */
980 )
981 {
982 dec_bit_stream_t * ps_bitstrm = ps_dec->ps_bitstrm;
983 dec_pic_params_t *ps_pps;
984 dec_seq_params_t *ps_seq;
985 dec_slice_params_t *ps_cur_slice = ps_dec->ps_cur_slice;
986 pocstruct_t s_tmp_poc;
987 WORD32 i_delta_poc[2];
988 WORD32 i4_poc = 0;
989 UWORD16 u2_first_mb_in_slice, u2_frame_num;
990 UWORD8 u1_field_pic_flag, u1_redundant_pic_cnt = 0, u1_slice_type;
991 UWORD32 u4_idr_pic_id = 0;
992 UWORD8 u1_bottom_field_flag, u1_pic_order_cnt_type;
993
994 UWORD8 u1_nal_unit_type;
995 UWORD32 *pu4_bitstrm_buf = ps_bitstrm->pu4_buffer;
996 UWORD32 *pu4_bitstrm_ofst = &ps_bitstrm->u4_ofst;
997 WORD8 i1_is_end_of_poc;
998
999 WORD32 ret, end_of_frame;
1000 WORD32 prev_slice_err, num_mb_skipped;
1001 UWORD8 u1_mbaff;
1002 pocstruct_t *ps_cur_poc;
1003
1004 UWORD32 u4_temp;
1005 WORD32 i_temp;
1006 UWORD32 u4_call_end_of_pic = 0;
1007
1008 /* read FirstMbInSlice and slice type*/
1009 ps_dec->ps_dpb_cmds->u1_dpb_commands_read_slc = 0;
1010 u2_first_mb_in_slice = ih264d_uev(pu4_bitstrm_ofst,
1011 pu4_bitstrm_buf);
1012 if(u2_first_mb_in_slice
1013 > (ps_dec->u2_frm_ht_in_mbs * ps_dec->u2_frm_wd_in_mbs))
1014 {
1015
1016 return ERROR_CORRUPTED_SLICE;
1017 }
1018
1019 /*we currently don not support ASO*/
1020 if(((u2_first_mb_in_slice << ps_cur_slice->u1_mbaff_frame_flag)
1021 <= ps_dec->u2_cur_mb_addr) && (ps_dec->u4_first_slice_in_pic == 0))
1022 {
1023 return ERROR_CORRUPTED_SLICE;
1024 }
1025
1026 COPYTHECONTEXT("SH: first_mb_in_slice",u2_first_mb_in_slice);
1027
1028 u4_temp = ih264d_uev(pu4_bitstrm_ofst, pu4_bitstrm_buf);
1029
1030 if(u4_temp > 9)
1031 return ERROR_INV_SLC_TYPE_T;
1032
1033 u1_slice_type = u4_temp;
1034 COPYTHECONTEXT("SH: slice_type",(u1_slice_type));
1035 /* Find Out the Slice Type is 5 to 9 or not then Set the Flag */
1036 /* u1_sl_typ_5_9 = 1 .Which tells that all the slices in the Pic*/
1037 /* will be of same type of current */
1038 if(u1_slice_type > 4)
1039 {
1040 u1_slice_type -= 5;
1041 }
1042
1043 {
1044 UWORD32 skip;
1045
1046 if((ps_dec->i4_app_skip_mode == IVD_SKIP_PB)
1047 || (ps_dec->i4_dec_skip_mode == IVD_SKIP_PB))
1048 {
1049 UWORD32 u4_bit_stream_offset = 0;
1050
1051 if(ps_dec->u1_nal_unit_type == IDR_SLICE_NAL)
1052 {
1053 skip = 0;
1054
1055 ps_dec->i4_dec_skip_mode = IVD_SKIP_NONE;
1056 }
1057 else if((I_SLICE == u1_slice_type)
1058 && (1 >= ps_dec->ps_cur_sps->u1_num_ref_frames))
1059 {
1060 skip = 0;
1061
1062 ps_dec->i4_dec_skip_mode = IVD_SKIP_NONE;
1063 }
1064 else
1065 {
1066 skip = 1;
1067 }
1068
1069 /* If one frame worth of data is already skipped, do not skip the next one */
1070 if((0 == u2_first_mb_in_slice) && (1 == ps_dec->u4_prev_nal_skipped))
1071 {
1072 skip = 0;
1073 }
1074
1075 if(skip)
1076 {
1077 ps_dec->u4_prev_nal_skipped = 1;
1078 ps_dec->i4_dec_skip_mode = IVD_SKIP_PB;
1079 return 0;
1080 }
1081 else
1082 {
1083 /* If the previous NAL was skipped, then
1084 do not process that buffer in this call.
1085 Return to app and process it in the next call.
1086 This is necessary to handle cases where I/IDR is not complete in
1087 the current buffer and application intends to fill the remaining part of the bitstream
1088 later. This ensures we process only frame worth of data in every call */
1089 if(1 == ps_dec->u4_prev_nal_skipped)
1090 {
1091 ps_dec->u4_return_to_app = 1;
1092 return 0;
1093 }
1094 }
1095 }
1096
1097 }
1098
1099 u4_temp = ih264d_uev(pu4_bitstrm_ofst, pu4_bitstrm_buf);
1100 if(u4_temp & MASK_ERR_PIC_SET_ID)
1101 return ERROR_INV_SLICE_HDR_T;
1102 /* discard slice if pic param is invalid */
1103 COPYTHECONTEXT("SH: pic_parameter_set_id", u4_temp);
1104 ps_pps = &ps_dec->ps_pps[u4_temp];
1105 if(FALSE == ps_pps->u1_is_valid)
1106 {
1107 return ERROR_INV_SLICE_HDR_T;
1108 }
1109 ps_seq = ps_pps->ps_sps;
1110 if(!ps_seq)
1111 return ERROR_INV_SLICE_HDR_T;
1112 if(FALSE == ps_seq->u1_is_valid)
1113 return ERROR_INV_SLICE_HDR_T;
1114
1115 /* Get the frame num */
1116 u2_frame_num = ih264d_get_bits_h264(ps_bitstrm,
1117 ps_seq->u1_bits_in_frm_num);
1118 // H264_DEC_DEBUG_PRINT("FRAME %d First MB in slice: %d\n", u2_frame_num, u2_first_mb_in_slice);
1119
1120 COPYTHECONTEXT("SH: frame_num", u2_frame_num);
1121 // H264_DEC_DEBUG_PRINT("Second field: %d frame num: %d prv_frame_num: %d \n", ps_dec->u1_second_field, u2_frame_num, ps_dec->u2_prv_frame_num);
1122 if(!ps_dec->u1_first_slice_in_stream && ps_dec->u4_first_slice_in_pic)
1123 {
1124 pocstruct_t *ps_prev_poc = &ps_dec->s_prev_pic_poc;
1125 pocstruct_t *ps_cur_poc = &ps_dec->s_cur_pic_poc;
1126
1127 ps_dec->u2_mbx = 0xffff;
1128 ps_dec->u2_mby = 0;
1129
1130 if((0 == u1_is_idr_slice) && ps_cur_slice->u1_nal_ref_idc)
1131 ps_dec->u2_prev_ref_frame_num = ps_cur_slice->u2_frame_num;
1132
1133 if(u1_is_idr_slice || ps_cur_slice->u1_mmco_equalto5)
1134 ps_dec->u2_prev_ref_frame_num = 0;
1135
1136 if(ps_dec->ps_cur_sps->u1_gaps_in_frame_num_value_allowed_flag)
1137 {
1138 ih264d_decode_gaps_in_frame_num(ps_dec, u2_frame_num);
1139 }
1140
1141 ps_prev_poc->i4_prev_frame_num_ofst = ps_cur_poc->i4_prev_frame_num_ofst;
1142 ps_prev_poc->u2_frame_num = ps_cur_poc->u2_frame_num;
1143 ps_prev_poc->u1_mmco_equalto5 = ps_cur_slice->u1_mmco_equalto5;
1144 if(ps_cur_slice->u1_nal_ref_idc)
1145 {
1146 ps_prev_poc->i4_pic_order_cnt_lsb = ps_cur_poc->i4_pic_order_cnt_lsb;
1147 ps_prev_poc->i4_pic_order_cnt_msb = ps_cur_poc->i4_pic_order_cnt_msb;
1148 ps_prev_poc->i4_delta_pic_order_cnt_bottom =
1149 ps_cur_poc->i4_delta_pic_order_cnt_bottom;
1150 ps_prev_poc->i4_delta_pic_order_cnt[0] =
1151 ps_cur_poc->i4_delta_pic_order_cnt[0];
1152 ps_prev_poc->i4_delta_pic_order_cnt[1] =
1153 ps_cur_poc->i4_delta_pic_order_cnt[1];
1154 ps_prev_poc->u1_bot_field = ps_cur_poc->u1_bot_field;
1155 }
1156
1157 ps_dec->u2_total_mbs_coded = 0;
1158 }
1159 /* Get the field related flags */
1160 if(!ps_seq->u1_frame_mbs_only_flag)
1161 {
1162
1163 u1_field_pic_flag = ih264d_get_bit_h264(ps_bitstrm);
1164 COPYTHECONTEXT("SH: field_pic_flag", u1_field_pic_flag);
1165 u1_bottom_field_flag = 0;
1166
1167 if(u1_field_pic_flag)
1168 {
1169 ps_dec->pu1_inv_scan = (UWORD8 *)gau1_ih264d_inv_scan_fld;
1170 u1_bottom_field_flag = ih264d_get_bit_h264(ps_bitstrm);
1171 COPYTHECONTEXT("SH: bottom_field_flag", u1_bottom_field_flag);
1172
1173 }
1174 else
1175 {
1176 ps_dec->pu1_inv_scan = (UWORD8 *)gau1_ih264d_inv_scan;
1177 }
1178 }
1179 else
1180 {
1181 u1_field_pic_flag = 0;
1182 u1_bottom_field_flag = 0;
1183
1184 ps_dec->pu1_inv_scan = (UWORD8 *)gau1_ih264d_inv_scan;
1185 }
1186
1187 u1_nal_unit_type = SLICE_NAL;
1188 if(u1_is_idr_slice)
1189 {
1190 u1_nal_unit_type = IDR_SLICE_NAL;
1191 u4_idr_pic_id = ih264d_uev(pu4_bitstrm_ofst,
1192 pu4_bitstrm_buf);
1193 if(u4_idr_pic_id > 65535)
1194 return ERROR_INV_SLICE_HDR_T;
1195 COPYTHECONTEXT("SH: ", u4_idr_pic_id);
1196 }
1197
1198 /* read delta pic order count information*/
1199 i_delta_poc[0] = i_delta_poc[1] = 0;
1200 s_tmp_poc.i4_pic_order_cnt_lsb = 0;
1201 s_tmp_poc.i4_delta_pic_order_cnt_bottom = 0;
1202 u1_pic_order_cnt_type = ps_seq->u1_pic_order_cnt_type;
1203 if(u1_pic_order_cnt_type == 0)
1204 {
1205 i_temp = ih264d_get_bits_h264(
1206 ps_bitstrm,
1207 ps_seq->u1_log2_max_pic_order_cnt_lsb_minus);
1208 if(i_temp < 0 || i_temp >= ps_seq->i4_max_pic_order_cntLsb)
1209 return ERROR_INV_SLICE_HDR_T;
1210 s_tmp_poc.i4_pic_order_cnt_lsb = i_temp;
1211 COPYTHECONTEXT("SH: pic_order_cnt_lsb", s_tmp_poc.i4_pic_order_cnt_lsb);
1212
1213 if((ps_pps->u1_pic_order_present_flag == 1) && (!u1_field_pic_flag))
1214 {
1215 s_tmp_poc.i4_delta_pic_order_cnt_bottom = ih264d_sev(
1216 pu4_bitstrm_ofst, pu4_bitstrm_buf);
1217 //if(s_tmp_poc.i4_delta_pic_order_cnt_bottom > ps_seq->i4_max_pic_order_cntLsb)
1218 COPYTHECONTEXT("SH: delta_pic_order_cnt_bottom",
1219 s_tmp_poc.i4_delta_pic_order_cnt_bottom);
1220 }
1221 }
1222
1223 s_tmp_poc.i4_delta_pic_order_cnt[0] = 0;
1224 s_tmp_poc.i4_delta_pic_order_cnt[1] = 0;
1225 if(u1_pic_order_cnt_type == 1
1226 && (!ps_seq->u1_delta_pic_order_always_zero_flag))
1227 {
1228 s_tmp_poc.i4_delta_pic_order_cnt[0] = ih264d_sev(pu4_bitstrm_ofst,
1229 pu4_bitstrm_buf);
1230 COPYTHECONTEXT("SH: delta_pic_order_cnt[0]",
1231 s_tmp_poc.i4_delta_pic_order_cnt[0]);
1232
1233 if(ps_pps->u1_pic_order_present_flag && !u1_field_pic_flag)
1234 {
1235 s_tmp_poc.i4_delta_pic_order_cnt[1] = ih264d_sev(
1236 pu4_bitstrm_ofst, pu4_bitstrm_buf);
1237 COPYTHECONTEXT("SH: delta_pic_order_cnt[1]",
1238 s_tmp_poc.i4_delta_pic_order_cnt[1]);
1239 }
1240 }
1241
1242 if(ps_pps->u1_redundant_pic_cnt_present_flag)
1243 {
1244 u4_temp = ih264d_uev(pu4_bitstrm_ofst, pu4_bitstrm_buf);
1245 if(u4_temp > MAX_REDUNDANT_PIC_CNT)
1246 return ERROR_INV_SLICE_HDR_T;
1247 u1_redundant_pic_cnt = u4_temp;
1248 COPYTHECONTEXT("SH: redundant_pic_cnt", u1_redundant_pic_cnt);
1249 }
1250
1251 /*--------------------------------------------------------------------*/
1252 /* Check if the slice is part of new picture */
1253 /*--------------------------------------------------------------------*/
1254 /* First slice of a picture is always considered as part of new picture */
1255 i1_is_end_of_poc = 1;
1256 ps_dec->ps_dec_err_status->u1_err_flag &= MASK_REJECT_CUR_PIC;
1257
1258 if(ps_dec->u4_first_slice_in_pic == 0)
1259 {
1260 i1_is_end_of_poc = ih264d_is_end_of_pic(u2_frame_num, u1_nal_ref_idc,
1261 &s_tmp_poc, &ps_dec->s_cur_pic_poc,
1262 ps_cur_slice, u1_pic_order_cnt_type,
1263 u1_nal_unit_type, u4_idr_pic_id,
1264 u1_field_pic_flag,
1265 u1_bottom_field_flag);
1266 if(i1_is_end_of_poc)
1267 {
1268 ps_dec->u1_first_slice_in_stream = 0;
1269 return ERROR_INCOMPLETE_FRAME;
1270 }
1271
1272 }
1273
1274 /*--------------------------------------------------------------------*/
1275 /* Check for error in slice and parse the missing/corrupted MB's */
1276 /* as skip-MB's in an inserted P-slice */
1277 /*--------------------------------------------------------------------*/
1278 u1_mbaff = ps_seq->u1_mb_aff_flag && (!u1_field_pic_flag);
1279 prev_slice_err = 0;
1280
1281 if(i1_is_end_of_poc || ps_dec->u1_first_slice_in_stream)
1282 {
1283 if(u2_frame_num != ps_dec->u2_prv_frame_num
1284 && ps_dec->u1_top_bottom_decoded != 0
1285 && ps_dec->u1_top_bottom_decoded
1286 != (TOP_FIELD_ONLY | BOT_FIELD_ONLY))
1287 {
1288 ps_dec->u1_dangling_field = 1;
1289 if(ps_dec->u4_first_slice_in_pic)
1290 {
1291 // first slice - dangling field
1292 prev_slice_err = 1;
1293 }
1294 else
1295 {
1296 // last slice - dangling field
1297 prev_slice_err = 2;
1298 }
1299
1300 if(ps_dec->u1_top_bottom_decoded ==TOP_FIELD_ONLY)
1301 ps_cur_slice->u1_bottom_field_flag = 1;
1302 else
1303 ps_cur_slice->u1_bottom_field_flag = 0;
1304
1305 num_mb_skipped = (ps_dec->u2_frm_ht_in_mbs * ps_dec->u2_frm_wd_in_mbs)
1306 - ps_dec->u2_total_mbs_coded;
1307 ps_cur_poc = &ps_dec->s_cur_pic_poc;
1308
1309 u1_is_idr_slice = ps_cur_slice->u1_nal_unit_type == IDR_SLICE_NAL;
1310 }
1311 else if(ps_dec->u4_first_slice_in_pic)
1312 {
1313 if(u2_first_mb_in_slice > 0)
1314 {
1315 // first slice - missing/header corruption
1316 prev_slice_err = 1;
1317 num_mb_skipped = u2_first_mb_in_slice << u1_mbaff;
1318 ps_cur_poc = &s_tmp_poc;
1319
1320 // initializing slice parameters
1321 ps_cur_slice->u4_idr_pic_id = u4_idr_pic_id;
1322 ps_cur_slice->u1_field_pic_flag = u1_field_pic_flag;
1323 ps_cur_slice->u1_bottom_field_flag = u1_bottom_field_flag;
1324 ps_cur_slice->i4_pic_order_cnt_lsb =
1325 s_tmp_poc.i4_pic_order_cnt_lsb;
1326 ps_cur_slice->u1_nal_unit_type = u1_nal_unit_type;
1327 ps_cur_slice->u1_redundant_pic_cnt = u1_redundant_pic_cnt;
1328 ps_cur_slice->u1_nal_ref_idc = u1_nal_ref_idc;
1329 ps_cur_slice->u1_pic_order_cnt_type = u1_pic_order_cnt_type;
1330 ps_cur_slice->u1_mbaff_frame_flag = ps_seq->u1_mb_aff_flag
1331 && (!u1_field_pic_flag);
1332 }
1333 }
1334 else
1335 {
1336 /* since i1_is_end_of_poc is set ,means new frame num is encountered. so conceal the current frame
1337 * completely */
1338 prev_slice_err = 2;
1339 num_mb_skipped = (ps_dec->u2_frm_ht_in_mbs
1340 * ps_dec->u2_frm_wd_in_mbs)
1341 - ps_dec->u2_total_mbs_coded;
1342 ps_cur_poc = &s_tmp_poc;
1343 }
1344 }
1345 else
1346 {
1347 if((u2_first_mb_in_slice << u1_mbaff) > ps_dec->u2_total_mbs_coded)
1348 {
1349 // previous slice - missing/corruption
1350 prev_slice_err = 2;
1351 num_mb_skipped = (u2_first_mb_in_slice << u1_mbaff)
1352 - ps_dec->u2_total_mbs_coded;
1353 ps_cur_poc = &s_tmp_poc;
1354 }
1355 else if((u2_first_mb_in_slice << u1_mbaff) < ps_dec->u2_total_mbs_coded)
1356 {
1357 return ERROR_CORRUPTED_SLICE;
1358 }
1359 }
1360
1361 if(prev_slice_err)
1362 {
1363 ret = ih264d_mark_err_slice_skip(ps_dec, num_mb_skipped, u1_is_idr_slice, u2_frame_num, ps_cur_poc, prev_slice_err);
1364
1365 if(ps_dec->u1_dangling_field == 1)
1366 {
1367 ps_dec->u1_second_field = 1 - ps_dec->u1_second_field;
1368 ps_cur_slice->u1_bottom_field_flag = u1_bottom_field_flag;
1369 ps_dec->u2_prv_frame_num = u2_frame_num;
1370 ps_dec->u1_first_slice_in_stream = 0;
1371 return ERROR_DANGLING_FIELD_IN_PIC;
1372 }
1373
1374 if(prev_slice_err == 2)
1375 {
1376 ps_dec->u1_first_slice_in_stream = 0;
1377 return ERROR_INCOMPLETE_FRAME;
1378 }
1379
1380 if(ps_dec->u2_total_mbs_coded
1381 >= ps_dec->u2_frm_ht_in_mbs * ps_dec->u2_frm_wd_in_mbs)
1382 {
1383 /* return if all MBs in frame are parsed*/
1384 ps_dec->u1_first_slice_in_stream = 0;
1385 return ERROR_IN_LAST_SLICE_OF_PIC;
1386 }
1387
1388 if(ps_dec->ps_dec_err_status->u1_err_flag & REJECT_CUR_PIC)
1389 {
1390 ih264d_err_pic_dispbuf_mgr(ps_dec);
1391 return ERROR_NEW_FRAME_EXPECTED;
1392 }
1393
1394 if(ret != OK)
1395 return ret;
1396
1397 i1_is_end_of_poc = 0;
1398 }
1399
1400 if (ps_dec->u4_first_slice_in_pic == 0)
1401 {
1402 ps_dec->ps_parse_cur_slice++;
1403 ps_dec->u2_cur_slice_num++;
1404 }
1405
1406 // in the case of single core increment ps_decode_cur_slice
1407 if((ps_dec->u1_separate_parse == 0) && (ps_dec->u4_first_slice_in_pic == 0))
1408 {
1409 ps_dec->ps_decode_cur_slice++;
1410 }
1411 ps_dec->u1_slice_header_done = 0;
1412
1413
1414 if(u1_field_pic_flag)
1415 {
1416 ps_dec->u2_prv_frame_num = u2_frame_num;
1417 }
1418
1419 if(ps_cur_slice->u1_mmco_equalto5)
1420 {
1421 WORD32 i4_temp_poc;
1422 WORD32 i4_top_field_order_poc, i4_bot_field_order_poc;
1423
1424 if(!ps_cur_slice->u1_field_pic_flag) // or a complementary field pair
1425 {
1426 i4_top_field_order_poc = ps_dec->ps_cur_pic->i4_top_field_order_cnt;
1427 i4_bot_field_order_poc =
1428 ps_dec->ps_cur_pic->i4_bottom_field_order_cnt;
1429 i4_temp_poc = MIN(i4_top_field_order_poc,
1430 i4_bot_field_order_poc);
1431 }
1432 else if(!ps_cur_slice->u1_bottom_field_flag)
1433 i4_temp_poc = ps_dec->ps_cur_pic->i4_top_field_order_cnt;
1434 else
1435 i4_temp_poc = ps_dec->ps_cur_pic->i4_bottom_field_order_cnt;
1436
1437 ps_dec->ps_cur_pic->i4_top_field_order_cnt = i4_temp_poc
1438 - ps_dec->ps_cur_pic->i4_top_field_order_cnt;
1439 ps_dec->ps_cur_pic->i4_bottom_field_order_cnt = i4_temp_poc
1440 - ps_dec->ps_cur_pic->i4_bottom_field_order_cnt;
1441 ps_dec->ps_cur_pic->i4_poc = i4_temp_poc;
1442 ps_dec->ps_cur_pic->i4_avg_poc = i4_temp_poc;
1443 }
1444 if(ps_dec->u4_first_slice_in_pic)
1445 {
1446 ret = ih264d_decode_pic_order_cnt(u1_is_idr_slice, u2_frame_num,
1447 &ps_dec->s_prev_pic_poc,
1448 &s_tmp_poc, ps_cur_slice, ps_pps,
1449 u1_nal_ref_idc,
1450 u1_bottom_field_flag,
1451 u1_field_pic_flag, &i4_poc);
1452 if(ret != OK)
1453 return ret;
1454 /* Display seq no calculations */
1455 if(i4_poc >= ps_dec->i4_max_poc)
1456 ps_dec->i4_max_poc = i4_poc;
1457 /* IDR Picture or POC wrap around */
1458 if(i4_poc == 0)
1459 {
1460 ps_dec->i4_prev_max_display_seq = ps_dec->i4_prev_max_display_seq
1461 + ps_dec->i4_max_poc
1462 + ps_dec->u1_max_dec_frame_buffering + 1;
1463 ps_dec->i4_max_poc = 0;
1464 }
1465 }
1466
1467 /*--------------------------------------------------------------------*/
1468 /* Copy the values read from the bitstream to the slice header and then*/
1469 /* If the slice is first slice in picture, then do Start of Picture */
1470 /* processing. */
1471 /*--------------------------------------------------------------------*/
1472 ps_cur_slice->i4_delta_pic_order_cnt[0] = i_delta_poc[0];
1473 ps_cur_slice->i4_delta_pic_order_cnt[1] = i_delta_poc[1];
1474 ps_cur_slice->u4_idr_pic_id = u4_idr_pic_id;
1475 ps_cur_slice->u2_first_mb_in_slice = u2_first_mb_in_slice;
1476 ps_cur_slice->u1_field_pic_flag = u1_field_pic_flag;
1477 ps_cur_slice->u1_bottom_field_flag = u1_bottom_field_flag;
1478 ps_cur_slice->u1_slice_type = u1_slice_type;
1479 ps_cur_slice->i4_pic_order_cnt_lsb = s_tmp_poc.i4_pic_order_cnt_lsb;
1480
1481 ps_cur_slice->u1_nal_unit_type = u1_nal_unit_type;
1482 ps_cur_slice->u1_redundant_pic_cnt = u1_redundant_pic_cnt;
1483 ps_cur_slice->u1_nal_ref_idc = u1_nal_ref_idc;
1484 ps_cur_slice->u1_pic_order_cnt_type = u1_pic_order_cnt_type;
1485
1486 if(ps_seq->u1_frame_mbs_only_flag)
1487 ps_cur_slice->u1_direct_8x8_inference_flag =
1488 ps_seq->u1_direct_8x8_inference_flag;
1489 else
1490 ps_cur_slice->u1_direct_8x8_inference_flag = 1;
1491
1492 if(u1_slice_type == B_SLICE)
1493 {
1494 ps_cur_slice->u1_direct_spatial_mv_pred_flag = ih264d_get_bit_h264(
1495 ps_bitstrm);
1496 COPYTHECONTEXT("SH: direct_spatial_mv_pred_flag",
1497 ps_cur_slice->u1_direct_spatial_mv_pred_flag);
1498
1499 if(ps_cur_slice->u1_direct_spatial_mv_pred_flag)
1500 ps_cur_slice->pf_decodeDirect = ih264d_decode_spatial_direct;
1501 else
1502 ps_cur_slice->pf_decodeDirect = ih264d_decode_temporal_direct;
1503 if(!((ps_pps->ps_sps->u1_mb_aff_flag) && (!u1_field_pic_flag)))
1504 ps_dec->pf_mvpred = ih264d_mvpred_nonmbaffB;
1505 }
1506 else
1507 {
1508 if(!((ps_pps->ps_sps->u1_mb_aff_flag) && (!u1_field_pic_flag)))
1509 ps_dec->pf_mvpred = ih264d_mvpred_nonmbaff;
1510 }
1511
1512 if(ps_dec->u4_first_slice_in_pic)
1513 {
1514 if(u2_first_mb_in_slice == 0)
1515 {
1516 ret = ih264d_start_of_pic(ps_dec, i4_poc, &s_tmp_poc, u2_frame_num, ps_pps);
1517 if(ret != OK)
1518 return ret;
1519 }
1520
1521 ps_dec->u4_output_present = 0;
1522
1523 {
1524 ih264d_get_next_display_field(ps_dec,
1525 ps_dec->ps_out_buffer,
1526 &(ps_dec->s_disp_op));
1527 /* If error code is non-zero then there is no buffer available for display,
1528 hence avoid format conversion */
1529
1530 if(0 != ps_dec->s_disp_op.u4_error_code)
1531 {
1532 ps_dec->u4_fmt_conv_cur_row = ps_dec->s_disp_frame_info.u4_y_ht;
1533 }
1534 else
1535 ps_dec->u4_output_present = 1;
1536 }
1537 if(ps_dec->u1_separate_parse == 1)
1538 {
1539 if(ps_dec->u4_dec_thread_created == 0)
1540 {
1541 ithread_create(ps_dec->pv_dec_thread_handle, NULL,
1542 (void *)ih264d_decode_picture_thread,
1543 (void *)ps_dec);
1544
1545 ps_dec->u4_dec_thread_created = 1;
1546 }
1547
1548 if((ps_dec->u4_num_cores == 3) &&
1549 ((ps_dec->u4_app_disable_deblk_frm == 0) || ps_dec->i1_recon_in_thread3_flag)
1550 && (ps_dec->u4_bs_deblk_thread_created == 0))
1551 {
1552 ps_dec->u4_start_recon_deblk = 0;
1553 ithread_create(ps_dec->pv_bs_deblk_thread_handle, NULL,
1554 (void *)ih264d_recon_deblk_thread,
1555 (void *)ps_dec);
1556 ps_dec->u4_bs_deblk_thread_created = 1;
1557 }
1558 }
1559
1560 }
1561
1562 /* INITIALIZATION of fn ptrs for MC and formMbPartInfo functions */
1563 {
1564 UWORD8 uc_nofield_nombaff;
1565
1566
1567
1568 uc_nofield_nombaff = ((ps_dec->ps_cur_slice->u1_field_pic_flag == 0)
1569 && (ps_dec->ps_cur_slice->u1_mbaff_frame_flag == 0)
1570 && (u1_slice_type != B_SLICE)
1571 && (ps_dec->ps_cur_pps->u1_wted_pred_flag == 0));
1572
1573 /* Initialise MC and formMbPartInfo fn ptrs one time based on profile_idc */
1574
1575 if(uc_nofield_nombaff)
1576 {
1577 ps_dec->p_form_mb_part_info = ih264d_form_mb_part_info_bp;
1578 ps_dec->p_motion_compensate = ih264d_motion_compensate_bp;
1579 }
1580 else
1581 {
1582 ps_dec->p_form_mb_part_info = ih264d_form_mb_part_info_mp;
1583 ps_dec->p_motion_compensate = ih264d_motion_compensate_mp;
1584 }
1585
1586
1587 }
1588
1589 /*
1590 * Decide whether to decode the current picture or not
1591 */
1592 {
1593 dec_err_status_t * ps_err = ps_dec->ps_dec_err_status;
1594 if(ps_err->u4_frm_sei_sync == u2_frame_num)
1595 {
1596 ps_err->u1_err_flag = ACCEPT_ALL_PICS;
1597 ps_err->u4_frm_sei_sync = SYNC_FRM_DEFAULT;
1598 }
1599 ps_err->u4_cur_frm = u2_frame_num;
1600 }
1601
1602 /* Decision for decoding if the picture is to be skipped */
1603 {
1604 WORD32 i4_skip_b_pic, i4_skip_p_pic;
1605
1606 i4_skip_b_pic = (ps_dec->u4_skip_frm_mask & B_SLC_BIT)
1607 && (B_SLICE == u1_slice_type) && (0 == u1_nal_ref_idc);
1608
1609 i4_skip_p_pic = (ps_dec->u4_skip_frm_mask & P_SLC_BIT)
1610 && (P_SLICE == u1_slice_type) && (0 == u1_nal_ref_idc);
1611
1612 /**************************************************************/
1613 /* Skip the B picture if skip mask is set for B picture and */
1614 /* Current B picture is a non reference B picture or there is */
1615 /* no user for reference B picture */
1616 /**************************************************************/
1617 if(i4_skip_b_pic)
1618 {
1619 ps_dec->ps_cur_pic->u4_pack_slc_typ |= B_SLC_BIT;
1620 /* Don't decode the picture in SKIP-B mode if that picture is B */
1621 /* and also it is not to be used as a reference picture */
1622 ps_dec->u1_last_pic_not_decoded = 1;
1623
1624 return OK;
1625 }
1626 /**************************************************************/
1627 /* Skip the P picture if skip mask is set for P picture and */
1628 /* Current P picture is a non reference P picture or there is */
1629 /* no user for reference P picture */
1630 /**************************************************************/
1631 if(i4_skip_p_pic)
1632 {
1633 ps_dec->ps_cur_pic->u4_pack_slc_typ |= P_SLC_BIT;
1634 /* Don't decode the picture in SKIP-P mode if that picture is P */
1635 /* and also it is not to be used as a reference picture */
1636 ps_dec->u1_last_pic_not_decoded = 1;
1637
1638 return OK;
1639 }
1640 }
1641
1642 {
1643 UWORD16 u2_mb_x, u2_mb_y;
1644
1645 ps_dec->i4_submb_ofst = ((u2_first_mb_in_slice
1646 << ps_cur_slice->u1_mbaff_frame_flag) * SUB_BLK_SIZE)
1647 - SUB_BLK_SIZE;
1648 if(u2_first_mb_in_slice)
1649 {
1650 UWORD8 u1_mb_aff;
1651 UWORD8 u1_field_pic;
1652 UWORD16 u2_frm_wd_in_mbs;
1653 u2_frm_wd_in_mbs = ps_seq->u2_frm_wd_in_mbs;
1654 u1_mb_aff = ps_cur_slice->u1_mbaff_frame_flag;
1655 u1_field_pic = ps_cur_slice->u1_field_pic_flag;
1656
1657 {
1658 UWORD32 x_offset;
1659 UWORD32 y_offset;
1660 UWORD32 u4_frame_stride;
1661 tfr_ctxt_t *ps_trns_addr; // = &ps_dec->s_tran_addrecon_parse;
1662
1663 if(ps_dec->u1_separate_parse)
1664 {
1665 ps_trns_addr = &ps_dec->s_tran_addrecon_parse;
1666 }
1667 else
1668 {
1669 ps_trns_addr = &ps_dec->s_tran_addrecon;
1670 }
1671 u2_mb_x = MOD(u2_first_mb_in_slice, u2_frm_wd_in_mbs);
1672 u2_mb_y = DIV(u2_first_mb_in_slice, u2_frm_wd_in_mbs);
1673
1674 u2_mb_y <<= u1_mb_aff;
1675
1676 if((u2_mb_x > u2_frm_wd_in_mbs - 1)
1677 || (u2_mb_y > ps_dec->u2_frm_ht_in_mbs - 1))
1678 {
1679 return ERROR_CORRUPTED_SLICE;
1680 }
1681
1682 u4_frame_stride = ps_dec->u2_frm_wd_y << u1_field_pic;
1683 x_offset = u2_mb_x << 4;
1684 y_offset = (u2_mb_y * u4_frame_stride) << 4;
1685
1686 ps_trns_addr->pu1_dest_y = ps_dec->s_cur_pic.pu1_buf1 + x_offset
1687 + y_offset;
1688
1689 u4_frame_stride = ps_dec->u2_frm_wd_uv << u1_field_pic;
1690 x_offset >>= 1;
1691 y_offset = (u2_mb_y * u4_frame_stride) << 3;
1692
1693 x_offset *= YUV420SP_FACTOR;
1694
1695 ps_trns_addr->pu1_dest_u = ps_dec->s_cur_pic.pu1_buf2 + x_offset
1696 + y_offset;
1697 ps_trns_addr->pu1_dest_v = ps_dec->s_cur_pic.pu1_buf3 + x_offset
1698 + y_offset;
1699
1700 ps_trns_addr->pu1_mb_y = ps_trns_addr->pu1_dest_y;
1701 ps_trns_addr->pu1_mb_u = ps_trns_addr->pu1_dest_u;
1702 ps_trns_addr->pu1_mb_v = ps_trns_addr->pu1_dest_v;
1703
1704
1705 // assign the deblock structure pointers to start of slice
1706 if(ps_dec->u1_separate_parse == 1)
1707 {
1708 ps_dec->ps_deblk_mbn = ps_dec->ps_deblk_pic
1709 + (u2_first_mb_in_slice << u1_mb_aff);
1710 }
1711 else
1712 {
1713 ps_dec->ps_deblk_mbn = ps_dec->ps_deblk_pic
1714 + (u2_first_mb_in_slice << u1_mb_aff);
1715 }
1716
1717 ps_dec->u2_cur_mb_addr = (u2_first_mb_in_slice << u1_mb_aff);
1718
1719 ps_dec->ps_mv_cur = ps_dec->s_cur_pic.ps_mv
1720 + ((u2_first_mb_in_slice << u1_mb_aff) << 4);
1721 }
1722 }
1723 else
1724 {
1725 tfr_ctxt_t *ps_trns_addr;
1726
1727 if(ps_dec->u1_separate_parse)
1728 {
1729 ps_trns_addr = &ps_dec->s_tran_addrecon_parse;
1730 }
1731 else
1732 {
1733 ps_trns_addr = &ps_dec->s_tran_addrecon;
1734 }
1735
1736 u2_mb_x = 0xffff;
1737 u2_mb_y = 0;
1738 // assign the deblock structure pointers to start of slice
1739 ps_dec->u2_cur_mb_addr = 0;
1740 ps_dec->ps_deblk_mbn = ps_dec->ps_deblk_pic;
1741 ps_dec->ps_mv_cur = ps_dec->s_cur_pic.ps_mv;
1742 ps_trns_addr->pu1_dest_y = ps_dec->s_cur_pic.pu1_buf1;
1743 ps_trns_addr->pu1_dest_u = ps_dec->s_cur_pic.pu1_buf2;
1744 ps_trns_addr->pu1_dest_v = ps_dec->s_cur_pic.pu1_buf3;
1745
1746 ps_trns_addr->pu1_mb_y = ps_trns_addr->pu1_dest_y;
1747 ps_trns_addr->pu1_mb_u = ps_trns_addr->pu1_dest_u;
1748 ps_trns_addr->pu1_mb_v = ps_trns_addr->pu1_dest_v;
1749
1750 }
1751
1752 ps_dec->ps_part = ps_dec->ps_parse_part_params;
1753
1754 ps_dec->u2_mbx =
1755 (MOD(u2_first_mb_in_slice - 1, ps_seq->u2_frm_wd_in_mbs));
1756 ps_dec->u2_mby =
1757 (DIV(u2_first_mb_in_slice - 1, ps_seq->u2_frm_wd_in_mbs));
1758 ps_dec->u2_mby <<= ps_cur_slice->u1_mbaff_frame_flag;
1759 ps_dec->i2_prev_slice_mbx = ps_dec->u2_mbx;
1760 ps_dec->i2_prev_slice_mby = ps_dec->u2_mby;
1761 }
1762
1763 /* RBSP stop bit is used for CABAC decoding*/
1764 ps_bitstrm->u4_max_ofst += ps_dec->ps_cur_pps->u1_entropy_coding_mode;
1765
1766 ps_dec->u1_B = (u1_slice_type == B_SLICE);
1767 ps_dec->u4_next_mb_skip = 0;
1768
1769 ps_dec->ps_parse_cur_slice->u4_first_mb_in_slice =
1770 ps_dec->ps_cur_slice->u2_first_mb_in_slice;
1771 ps_dec->ps_parse_cur_slice->slice_type =
1772 ps_dec->ps_cur_slice->u1_slice_type;
1773
1774
1775 ps_dec->u4_start_recon_deblk = 1;
1776 {
1777 WORD32 num_entries;
1778 WORD32 size;
1779 UWORD8 *pu1_buf;
1780
1781 num_entries = MAX_FRAMES;
1782 if((1 >= ps_dec->ps_cur_sps->u1_num_ref_frames) &&
1783 (0 == ps_dec->i4_display_delay))
1784 {
1785 num_entries = 1;
1786 }
1787 num_entries = ((2 * num_entries) + 1);
1788 if(BASE_PROFILE_IDC != ps_dec->ps_cur_sps->u1_profile_idc)
1789 {
1790 num_entries *= 2;
1791 }
1792
1793 size = num_entries * sizeof(void *);
1794 size += PAD_MAP_IDX_POC * sizeof(void *);
1795
1796 pu1_buf = (UWORD8 *)ps_dec->pv_map_ref_idx_to_poc_buf;
1797 pu1_buf += size * ps_dec->u2_cur_slice_num;
1798 ps_dec->ps_parse_cur_slice->ppv_map_ref_idx_to_poc = ( void *)pu1_buf;
1799 }
1800
1801 if(ps_dec->u1_separate_parse)
1802 {
1803 ps_dec->ps_parse_cur_slice->pv_tu_coeff_data_start = ps_dec->pv_parse_tu_coeff_data;
1804 }
1805 else
1806 {
1807 ps_dec->pv_proc_tu_coeff_data = ps_dec->pv_parse_tu_coeff_data;
1808 }
1809
1810 if(u1_slice_type == I_SLICE)
1811 {
1812 ps_dec->ps_cur_pic->u4_pack_slc_typ |= I_SLC_BIT;
1813
1814 ret = ih264d_parse_islice(ps_dec, u2_first_mb_in_slice);
1815
1816 if(ps_dec->i4_pic_type != B_SLICE && ps_dec->i4_pic_type != P_SLICE)
1817 ps_dec->i4_pic_type = I_SLICE;
1818
1819 }
1820 else if(u1_slice_type == P_SLICE)
1821 {
1822 ps_dec->ps_cur_pic->u4_pack_slc_typ |= P_SLC_BIT;
1823 ret = ih264d_parse_pslice(ps_dec, u2_first_mb_in_slice);
1824 ps_dec->u1_pr_sl_type = u1_slice_type;
1825 if(ps_dec->i4_pic_type != B_SLICE)
1826 ps_dec->i4_pic_type = P_SLICE;
1827 }
1828 else if(u1_slice_type == B_SLICE)
1829 {
1830 ps_dec->ps_cur_pic->u4_pack_slc_typ |= B_SLC_BIT;
1831 ret = ih264d_parse_bslice(ps_dec, u2_first_mb_in_slice);
1832 ps_dec->u1_pr_sl_type = u1_slice_type;
1833 ps_dec->i4_pic_type = B_SLICE;
1834 }
1835 else
1836 return ERROR_INV_SLC_TYPE_T;
1837
1838 if(ps_dec->u1_slice_header_done)
1839 {
1840 /* set to zero to indicate a valid slice has been decoded */
1841 ps_dec->u1_first_slice_in_stream = 0;
1842 }
1843
1844 if(ret != OK)
1845 return ret;
1846
1847 /* storing last Mb X and MbY of the slice */
1848 ps_dec->i2_prev_slice_mbx = ps_dec->u2_mbx;
1849 ps_dec->i2_prev_slice_mby = ps_dec->u2_mby;
1850
1851 /* End of Picture detection */
1852
1853 if(ps_dec->u2_total_mbs_coded >= (ps_seq->u2_max_mb_addr + 1))
1854 {
1855 ps_dec->u1_pic_decode_done = 1;
1856
1857 }
1858
1859 {
1860 dec_err_status_t * ps_err = ps_dec->ps_dec_err_status;
1861 if((ps_err->u1_err_flag & REJECT_PB_PICS)
1862 && (ps_err->u1_cur_pic_type == PIC_TYPE_I))
1863 {
1864 ps_err->u1_err_flag = ACCEPT_ALL_PICS;
1865 }
1866 }
1867
1868 PRINT_BIN_BIT_RATIO(ps_dec)
1869
1870 return ret;
1871 }
1872
1873