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