/src/libavc/decoder/svc/isvcd_parse_slice.c
Line | Count | Source (jump to first uncovered line) |
1 | | /****************************************************************************** |
2 | | * |
3 | | * Copyright (C) 2022 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 |
23 | | * isvcd_parse_slice.c |
24 | | * |
25 | | * @brief |
26 | | * Contains routines that decodes a slice NAL unit |
27 | | * |
28 | | * @author |
29 | | * Kishore |
30 | | * |
31 | | * @remarks |
32 | | * None |
33 | | * |
34 | | ******************************************************************************* |
35 | | */ |
36 | | |
37 | | #include <string.h> |
38 | | #include <assert.h> |
39 | | #include "ih264_typedefs.h" |
40 | | #include "ih264_macros.h" |
41 | | #include "ih264_platform_macros.h" |
42 | | #include "ithread.h" |
43 | | #include "isvcd_structs.h" |
44 | | #include "ih264d_debug.h" |
45 | | #include "ih264d_bitstrm.h" |
46 | | #include "ih264d_parse_mb_header.h" |
47 | | #include "ih264d_process_bslice.h" |
48 | | #include "ih264d_process_pslice.h" |
49 | | #include "ih264d_parse_cavlc.h" |
50 | | #include "ih264d_utils.h" |
51 | | #include "isvcd_utils.h" |
52 | | #include "ih264d_deblocking.h" |
53 | | #include "ih264d_defs.h" |
54 | | #include "ih264d_error_handler.h" |
55 | | #include "ih264d_tables.h" |
56 | | #include "ih264d_defs.h" |
57 | | #include "ih264d_mem_request.h" |
58 | | #include "ih264d_parse_islice.h" |
59 | | #include "ih264d_parse_slice.h" |
60 | | #include "ih264d_mvpred.h" |
61 | | #include "ih264d_mb_utils.h" |
62 | | #include "ih264d_defs.h" |
63 | | #include "ih264d_quant_scaling.h" |
64 | | #include "ih264d_inter_pred.h" |
65 | | #include "ih264d_sei.h" |
66 | | #include "ih264_error.h" |
67 | | #include "ih264_disp_mgr.h" |
68 | | #include "ih264_buf_mgr.h" |
69 | | #include "ih264d_thread_parse_decode.h" |
70 | | #include "ih264d_thread_compute_bs.h" |
71 | | #include "ih264d_dpb_manager.h" |
72 | | #include "ih264d_parse_islice.h" |
73 | | #include "isvcd_parse_slice.h" |
74 | | #include "isvcd_process_epslice.h" |
75 | | #include "isvcd_process_ebslice.h" |
76 | | #include "isvcd_thread_compute_bs.h" |
77 | | #include "isvcd_thread_parse_decode.h" |
78 | | #include "isvcd_deblocking.h" |
79 | | |
80 | | #define RET_LAST_SKIP 0x80000000 |
81 | | |
82 | | WORD32 check_app_out_buf_size(dec_struct_t *ps_dec); |
83 | | /*! |
84 | | ************************************************************************** |
85 | | * \if Function name : isvcd_verify_level \endif |
86 | | * |
87 | | * \brief |
88 | | * Initialize the Parameter required for all the slices for a picture |
89 | | * |
90 | | * \return : Nothing |
91 | | * |
92 | | ************************************************************************** |
93 | | */ |
94 | | WORD32 isvcd_verify_level(UWORD8 u1_level_idc) |
95 | 151k | { |
96 | 151k | switch(u1_level_idc) |
97 | 151k | { |
98 | 1.01k | case H264_LEVEL_1_0: |
99 | 38.6k | case H264_LEVEL_1_1: |
100 | 41.7k | case H264_LEVEL_1_2: |
101 | 42.9k | case H264_LEVEL_1_3: |
102 | 95.2k | case H264_LEVEL_2_0: |
103 | 103k | case H264_LEVEL_2_1: |
104 | 104k | case H264_LEVEL_2_2: |
105 | 109k | case H264_LEVEL_3_0: |
106 | 110k | case H264_LEVEL_3_1: |
107 | 129k | case H264_LEVEL_3_2: |
108 | 145k | case H264_LEVEL_4_0: |
109 | 147k | case H264_LEVEL_4_1: |
110 | 151k | case H264_LEVEL_4_2: |
111 | 151k | case H264_LEVEL_5_0: |
112 | 151k | case H264_LEVEL_5_1: |
113 | 151k | return OK; |
114 | 223 | default: |
115 | 223 | return NOT_OK; |
116 | 151k | } |
117 | 151k | } |
118 | | |
119 | | /*! |
120 | | ************************************************************************** |
121 | | * \if Function name : isvcd_start_of_pic \endif |
122 | | * |
123 | | * \brief |
124 | | * Initialize the Parameter required for all the slices for a picture |
125 | | * |
126 | | * \return : Nothing |
127 | | * |
128 | | ************************************************************************** |
129 | | */ |
130 | | |
131 | | WORD32 isvcd_start_of_pic(svc_dec_lyr_struct_t *ps_svc_lyr_dec, WORD32 i4_poc, |
132 | | pocstruct_t *ps_temp_poc, UWORD16 u2_frame_num, dec_pic_params_t *ps_pps) |
133 | 143k | { |
134 | 143k | dec_struct_t *ps_dec = &ps_svc_lyr_dec->s_dec; |
135 | 143k | pocstruct_t *ps_prev_poc = &ps_dec->s_cur_pic_poc; |
136 | 143k | pocstruct_t *ps_cur_poc = ps_temp_poc; |
137 | | |
138 | 143k | dec_slice_params_t *ps_cur_slice = ps_dec->ps_cur_slice; |
139 | 143k | dec_seq_params_t *ps_seq = ps_dec->ps_cur_sps; |
140 | 143k | UWORD8 u1_bottom_field_flag = ps_cur_slice->u1_bottom_field_flag; |
141 | 143k | UWORD8 u1_field_pic_flag = ps_cur_slice->u1_field_pic_flag; |
142 | | /* high profile related declarations */ |
143 | 143k | WORD32 ret; |
144 | | |
145 | 143k | H264_MUTEX_LOCK(&ps_dec->process_disp_mutex); |
146 | | |
147 | 143k | if(u1_field_pic_flag == 1) |
148 | 0 | { |
149 | 0 | ps_dec->i4_error_code = ERROR_SVC_FIELD_PIC_UNSUPPORTED; |
150 | 0 | return ERROR_SVC_FIELD_PIC_UNSUPPORTED; |
151 | 0 | } |
152 | | |
153 | | /* check output buffer size given by the application */ |
154 | 143k | if(check_app_out_buf_size(ps_dec) != IV_SUCCESS) return IVD_DISP_FRM_ZERO_OP_BUF_SIZE; |
155 | | |
156 | 142k | ps_prev_poc->i4_pic_order_cnt_lsb = ps_cur_poc->i4_pic_order_cnt_lsb; |
157 | 142k | ps_prev_poc->i4_pic_order_cnt_msb = ps_cur_poc->i4_pic_order_cnt_msb; |
158 | 142k | ps_prev_poc->i4_delta_pic_order_cnt_bottom = ps_cur_poc->i4_delta_pic_order_cnt_bottom; |
159 | 142k | ps_prev_poc->i4_delta_pic_order_cnt[0] = ps_cur_poc->i4_delta_pic_order_cnt[0]; |
160 | 142k | ps_prev_poc->i4_delta_pic_order_cnt[1] = ps_cur_poc->i4_delta_pic_order_cnt[1]; |
161 | 142k | ps_prev_poc->u1_bot_field = ps_dec->ps_cur_slice->u1_bottom_field_flag; |
162 | 142k | ps_prev_poc->i4_prev_frame_num_ofst = ps_cur_poc->i4_prev_frame_num_ofst; |
163 | 142k | ps_prev_poc->u2_frame_num = u2_frame_num; |
164 | 142k | ps_dec->i1_prev_mb_qp_delta = 0; |
165 | 142k | ps_dec->i1_next_ctxt_idx = 0; |
166 | | |
167 | 142k | ps_dec->u4_nmb_deblk = 0; |
168 | 142k | if(ps_dec->u4_num_cores == 1) ps_dec->u4_nmb_deblk = 1; |
169 | | |
170 | 142k | if(ps_seq->u1_mb_aff_flag == 1) |
171 | 0 | { |
172 | 0 | ps_dec->u4_nmb_deblk = 0; |
173 | 0 | if(ps_dec->u4_num_cores > 2) ps_dec->u4_num_cores = 2; |
174 | 0 | } |
175 | | |
176 | 142k | ps_dec->u4_use_intrapred_line_copy = 0; |
177 | | |
178 | 142k | if(ps_seq->u1_mb_aff_flag == 0) |
179 | 142k | { |
180 | 142k | ps_dec->u4_use_intrapred_line_copy = 1; |
181 | 142k | } |
182 | | |
183 | 142k | ps_dec->u4_app_disable_deblk_frm = 0; |
184 | | /* If degrade is enabled, set the degrade flags appropriately */ |
185 | 142k | if(ps_dec->i4_degrade_type && ps_dec->i4_degrade_pics) |
186 | 0 | { |
187 | 0 | WORD32 degrade_pic; |
188 | 0 | ps_dec->i4_degrade_pic_cnt++; |
189 | 0 | degrade_pic = 0; |
190 | | |
191 | | /* If degrade is to be done in all frames, then do not check further */ |
192 | 0 | switch(ps_dec->i4_degrade_pics) |
193 | 0 | { |
194 | 0 | case 4: |
195 | 0 | { |
196 | 0 | degrade_pic = 1; |
197 | 0 | break; |
198 | 0 | } |
199 | 0 | case 3: |
200 | 0 | { |
201 | 0 | if(ps_cur_slice->u1_slice_type != I_SLICE) degrade_pic = 1; |
202 | |
|
203 | 0 | break; |
204 | 0 | } |
205 | 0 | case 2: |
206 | 0 | { |
207 | | /* If pic count hits non-degrade interval or it is an islice, then do not |
208 | | * degrade */ |
209 | 0 | if((ps_cur_slice->u1_slice_type != I_SLICE) && |
210 | 0 | (ps_dec->i4_degrade_pic_cnt != ps_dec->i4_nondegrade_interval)) |
211 | 0 | degrade_pic = 1; |
212 | |
|
213 | 0 | break; |
214 | 0 | } |
215 | 0 | case 1: |
216 | 0 | { |
217 | | /* Check if the current picture is non-ref */ |
218 | 0 | if(0 == ps_cur_slice->u1_nal_ref_idc) |
219 | 0 | { |
220 | 0 | degrade_pic = 1; |
221 | 0 | } |
222 | 0 | break; |
223 | 0 | } |
224 | 0 | } |
225 | 0 | if(degrade_pic) |
226 | 0 | { |
227 | 0 | if(ps_dec->i4_degrade_type & 0x2) ps_dec->u4_app_disable_deblk_frm = 1; |
228 | | |
229 | | /* MC degrading is done only for non-ref pictures */ |
230 | 0 | if(0 == ps_cur_slice->u1_nal_ref_idc) |
231 | 0 | { |
232 | 0 | if(ps_dec->i4_degrade_type & 0x4) ps_dec->i4_mv_frac_mask = 0; |
233 | |
|
234 | 0 | if(ps_dec->i4_degrade_type & 0x8) ps_dec->i4_mv_frac_mask = 0; |
235 | 0 | } |
236 | 0 | } |
237 | 0 | else |
238 | 0 | ps_dec->i4_degrade_pic_cnt = 0; |
239 | 0 | } |
240 | | |
241 | 142k | { |
242 | 142k | dec_err_status_t *ps_err = ps_dec->ps_dec_err_status; |
243 | 142k | if((ps_cur_slice->u1_slice_type == I_SLICE) || (ps_cur_slice->u1_slice_type == SI_SLICE)) |
244 | 13.8k | ps_err->u1_cur_pic_type = PIC_TYPE_I; |
245 | 128k | else |
246 | 128k | ps_err->u1_cur_pic_type = PIC_TYPE_UNKNOWN; |
247 | | |
248 | 142k | if(ps_err->u1_pic_aud_i == PIC_TYPE_I) |
249 | 0 | { |
250 | 0 | ps_err->u1_cur_pic_type = PIC_TYPE_I; |
251 | 0 | ps_err->u1_pic_aud_i = PIC_TYPE_UNKNOWN; |
252 | 0 | } |
253 | | |
254 | 142k | if(ps_cur_slice->u1_nal_unit_type == IDR_SLICE_NAL) |
255 | 119k | { |
256 | 119k | if(ps_err->u1_err_flag) ih264d_reset_ref_bufs(ps_dec->ps_dpb_mgr); |
257 | 119k | ps_err->u1_err_flag = ACCEPT_ALL_PICS; |
258 | 119k | } |
259 | 142k | } |
260 | | |
261 | 142k | if(ps_dec->u1_init_dec_flag && ps_dec->s_prev_seq_params.u1_eoseq_pending) |
262 | 0 | { |
263 | | /* Reset the decoder picture buffers */ |
264 | 0 | WORD32 j; |
265 | 0 | for(j = 0; j < MAX_DISP_BUFS_NEW; j++) |
266 | 0 | { |
267 | 0 | ih264_buf_mgr_release((buf_mgr_t *) ps_dec->pv_pic_buf_mgr, j, BUF_MGR_REF); |
268 | 0 | ih264_buf_mgr_release((buf_mgr_t *) ps_dec->pv_mv_buf_mgr, |
269 | 0 | ps_dec->as_buf_id_info_map[j].mv_buf_id, BUF_MGR_REF); |
270 | 0 | ih264_buf_mgr_release((buf_mgr_t *) ps_dec->pv_pic_buf_mgr, j, BUF_MGR_IO); |
271 | 0 | } |
272 | | |
273 | | /* reset the decoder structure parameters related to buffer handling */ |
274 | 0 | ps_dec->u1_second_field = 0; |
275 | 0 | ps_dec->i4_cur_display_seq = 0; |
276 | | |
277 | | /********************************************************************/ |
278 | | /* indicate in the decoder output i4_status that some frames are being */ |
279 | | /* dropped, so that it resets timestamp and wait for a new sequence */ |
280 | | /********************************************************************/ |
281 | 0 | ps_dec->s_prev_seq_params.u1_eoseq_pending = 0; |
282 | 0 | } |
283 | 142k | ret = isvcd_init_pic(ps_svc_lyr_dec, u2_frame_num, i4_poc, ps_pps); |
284 | 142k | if(ret != OK) return ret; |
285 | | |
286 | 142k | ps_dec->pv_parse_tu_coeff_data = ps_dec->pv_pic_tu_coeff_data; |
287 | 142k | ps_dec->pv_proc_tu_coeff_data = ps_dec->pv_pic_tu_coeff_data; |
288 | 142k | ps_dec->ps_nmb_info = ps_dec->ps_frm_mb_info; |
289 | 142k | ps_svc_lyr_dec->ps_svc_nmb_info = ps_svc_lyr_dec->ps_svc_frm_mb_info; |
290 | 142k | if(ps_dec->u1_separate_parse) |
291 | 51.8k | { |
292 | 51.8k | UWORD32 num_mbs; |
293 | 51.8k | num_mbs = ps_dec->ps_cur_sps->u4_total_num_of_mbs |
294 | 51.8k | << (1 - ps_dec->ps_cur_sps->u1_frame_mbs_only_flag); |
295 | | |
296 | 51.8k | if(ps_dec->pu1_dec_mb_map) |
297 | 51.8k | { |
298 | 51.8k | memset((void *) ps_dec->pu1_dec_mb_map, 0, num_mbs); |
299 | 51.8k | } |
300 | | |
301 | 51.8k | if(ps_dec->pu1_recon_mb_map) |
302 | 51.8k | { |
303 | 51.8k | memset((void *) ps_dec->pu1_recon_mb_map, 0, num_mbs); |
304 | 51.8k | } |
305 | | |
306 | 51.8k | if(ps_dec->pu2_slice_num_map) |
307 | 51.8k | { |
308 | 51.8k | memset((void *) ps_dec->pu2_slice_num_map, 0, (num_mbs * sizeof(UWORD16))); |
309 | 51.8k | } |
310 | 51.8k | } |
311 | | |
312 | 142k | ps_dec->ps_parse_cur_slice = &(ps_dec->ps_dec_slice_buf[0]); |
313 | 142k | ps_dec->ps_decode_cur_slice = &(ps_dec->ps_dec_slice_buf[0]); |
314 | 142k | ps_dec->ps_computebs_cur_slice = &(ps_dec->ps_dec_slice_buf[0]); |
315 | 142k | ps_dec->u2_cur_slice_num = 0; |
316 | | |
317 | | /* Initialize all the HP toolsets to zero */ |
318 | 142k | ps_dec->s_high_profile.u1_scaling_present = 0; |
319 | 142k | ps_dec->s_high_profile.u1_transform8x8_present = 0; |
320 | | |
321 | | /* Get Next Free Picture */ |
322 | 142k | if(1 == ps_dec->u4_share_disp_buf) |
323 | 0 | { |
324 | 0 | UWORD32 i; |
325 | | /* Free any buffer that is in the queue to be freed */ |
326 | 0 | for(i = 0; i < MAX_DISP_BUFS_NEW; i++) |
327 | 0 | { |
328 | 0 | if(0 == ps_dec->u4_disp_buf_to_be_freed[i]) continue; |
329 | 0 | ih264_buf_mgr_release((buf_mgr_t *) ps_dec->pv_pic_buf_mgr, i, BUF_MGR_IO); |
330 | 0 | ps_dec->u4_disp_buf_to_be_freed[i] = 0; |
331 | 0 | ps_dec->u4_disp_buf_mapping[i] = 0; |
332 | 0 | } |
333 | 0 | } |
334 | 142k | if(!(u1_field_pic_flag && 0 != ps_dec->u1_top_bottom_decoded)) |
335 | 142k | { |
336 | 142k | pic_buffer_t *ps_cur_pic; |
337 | 142k | WORD32 cur_pic_buf_id, cur_mv_buf_id; |
338 | 142k | col_mv_buf_t *ps_col_mv; |
339 | 142k | while(1) |
340 | 142k | { |
341 | 142k | ps_cur_pic = (pic_buffer_t *) ih264_buf_mgr_get_next_free( |
342 | 142k | (buf_mgr_t *) ps_dec->pv_pic_buf_mgr, &cur_pic_buf_id); |
343 | | |
344 | | /* In case of IDR slices, if there is no free picture buffer, then release |
345 | | * all buffers from display and reference |
346 | | */ |
347 | 142k | if((ps_cur_pic == NULL) && (ps_cur_slice->u1_nal_unit_type == IDR_SLICE_NAL)) |
348 | 902 | { |
349 | 902 | WORD32 j; |
350 | | |
351 | 58.6k | for(j = 0; j < MAX_DISP_BUFS_NEW; j++) |
352 | 57.7k | { |
353 | 57.7k | ih264_buf_mgr_release((buf_mgr_t *) ps_dec->pv_pic_buf_mgr, j, BUF_MGR_REF); |
354 | 57.7k | ih264_buf_mgr_release((buf_mgr_t *) ps_dec->pv_mv_buf_mgr, |
355 | 57.7k | ps_dec->as_buf_id_info_map[j].mv_buf_id, BUF_MGR_REF); |
356 | | |
357 | 57.7k | ih264_buf_mgr_release((buf_mgr_t *) ps_dec->pv_pic_buf_mgr, j, BUF_MGR_IO); |
358 | 57.7k | } |
359 | 902 | ps_cur_pic = (pic_buffer_t *) ih264_buf_mgr_get_next_free( |
360 | 902 | (buf_mgr_t *) ps_dec->pv_pic_buf_mgr, &cur_pic_buf_id); |
361 | 902 | } |
362 | 142k | if(ps_cur_pic == NULL) |
363 | 101 | { |
364 | 101 | ps_dec->i4_error_code = ERROR_UNAVAIL_PICBUF_T; |
365 | 101 | ps_dec->ps_dec_err_status->u1_err_flag |= REJECT_CUR_PIC; |
366 | 101 | return ERROR_UNAVAIL_PICBUF_T; |
367 | 101 | } |
368 | 142k | if(0 == ps_dec->u4_disp_buf_mapping[cur_pic_buf_id]) |
369 | 142k | { |
370 | 142k | break; |
371 | 142k | } |
372 | 142k | } |
373 | 142k | ps_col_mv = (col_mv_buf_t *) ih264_buf_mgr_get_next_free( |
374 | 142k | (buf_mgr_t *) ps_dec->pv_mv_buf_mgr, &cur_mv_buf_id); |
375 | 142k | if(ps_col_mv == NULL) |
376 | 483 | { |
377 | 483 | ps_dec->i4_error_code = ERROR_UNAVAIL_MVBUF_T; |
378 | 483 | ps_dec->ps_dec_err_status->u1_err_flag |= REJECT_CUR_PIC; |
379 | 483 | return ERROR_UNAVAIL_MVBUF_T; |
380 | 483 | } |
381 | | |
382 | 141k | ps_dec->ps_cur_pic = ps_cur_pic; |
383 | 141k | ps_dec->u1_pic_buf_id = cur_pic_buf_id; |
384 | 141k | ps_cur_pic->u4_ts = ps_dec->u4_ts; |
385 | 141k | memcpy(&ps_cur_pic->s_sei_pic, ps_dec->ps_sei, sizeof(sei)); |
386 | | |
387 | 141k | ps_cur_pic->u1_mv_buf_id = cur_mv_buf_id; |
388 | 141k | ps_dec->as_buf_id_info_map[cur_pic_buf_id].mv_buf_id = cur_mv_buf_id; |
389 | | |
390 | 141k | if(ps_dec->u1_enable_mb_info) |
391 | 0 | { |
392 | 0 | UWORD32 mb_info_map_size = ps_dec->u4_total_mbs << 2; |
393 | 0 | ps_dec->as_buf_id_info_map[cur_pic_buf_id].pu1_qp_map = |
394 | 0 | ps_dec->pu1_qp_map_base + cur_pic_buf_id * mb_info_map_size; |
395 | 0 | ps_dec->as_buf_id_info_map[cur_pic_buf_id].pu1_mb_type_map = |
396 | 0 | ps_dec->pu1_mb_type_map_base + cur_pic_buf_id * mb_info_map_size; |
397 | 0 | memset(ps_dec->as_buf_id_info_map[cur_pic_buf_id].pu1_qp_map, 0, mb_info_map_size); |
398 | 0 | memset(ps_dec->as_buf_id_info_map[cur_pic_buf_id].pu1_mb_type_map, 0, mb_info_map_size); |
399 | 0 | } |
400 | 141k | ps_cur_pic->pu1_col_zero_flag = (UWORD8 *) ps_col_mv->pv_col_zero_flag; |
401 | 141k | ps_cur_pic->ps_mv = (mv_pred_t *) ps_col_mv->pv_mv; |
402 | 141k | ps_dec->au1_pic_buf_ref_flag[cur_pic_buf_id] = 0; |
403 | | |
404 | 141k | { |
405 | | /*make first entry of list0 and list1 point to cur pic, |
406 | | *so that if first slice is in error, ref pic struct will have valid |
407 | | *entries*/ |
408 | 141k | ps_dec->ps_ref_pic_buf_lx[0] = ps_dec->ps_dpb_mgr->ps_init_dpb[0]; |
409 | 141k | ps_dec->ps_ref_pic_buf_lx[1] = ps_dec->ps_dpb_mgr->ps_init_dpb[1]; |
410 | 141k | *(ps_dec->ps_dpb_mgr->ps_init_dpb[0][0]) = *ps_cur_pic; |
411 | | /* Initialize for field reference as well */ |
412 | 141k | *(ps_dec->ps_dpb_mgr->ps_init_dpb[0][MAX_REF_BUFS]) = *ps_cur_pic; |
413 | | |
414 | 141k | *(ps_dec->ps_dpb_mgr->ps_mod_dpb[0][0]) = *ps_cur_pic; |
415 | | /* Initialize for field reference as well */ |
416 | 141k | *(ps_dec->ps_dpb_mgr->ps_mod_dpb[0][MAX_REF_BUFS]) = *ps_cur_pic; |
417 | 141k | *(ps_dec->ps_dpb_mgr->ps_init_dpb[1][0]) = *ps_cur_pic; |
418 | | /* Initialize for field reference as well */ |
419 | 141k | *(ps_dec->ps_dpb_mgr->ps_init_dpb[1][MAX_REF_BUFS]) = *ps_cur_pic; |
420 | 141k | *(ps_dec->ps_dpb_mgr->ps_mod_dpb[1][0]) = *ps_cur_pic; |
421 | | /* Initialize for field reference as well */ |
422 | 141k | *(ps_dec->ps_dpb_mgr->ps_mod_dpb[1][MAX_REF_BUFS]) = *ps_cur_pic; |
423 | 141k | } |
424 | | |
425 | 141k | ps_dec->ps_cur_pic->u1_picturetype = u1_field_pic_flag; |
426 | 141k | ps_dec->ps_cur_pic->u4_pack_slc_typ = SKIP_NONE; |
427 | 141k | H264_DEC_DEBUG_PRINT("got a buffer\n"); |
428 | 141k | } |
429 | 0 | else |
430 | 0 | { |
431 | 0 | H264_DEC_DEBUG_PRINT("did not get a buffer\n"); |
432 | 0 | } |
433 | | |
434 | 141k | ps_dec->u4_pic_buf_got = 1; |
435 | | |
436 | 141k | ps_dec->ps_cur_pic->i4_poc = i4_poc; |
437 | 141k | ps_dec->ps_cur_pic->i4_frame_num = u2_frame_num; |
438 | 141k | ps_dec->ps_cur_pic->i4_pic_num = u2_frame_num; |
439 | 141k | ps_dec->ps_cur_pic->i4_top_field_order_cnt = ps_pps->i4_top_field_order_cnt; |
440 | 141k | ps_dec->ps_cur_pic->i4_bottom_field_order_cnt = ps_pps->i4_bottom_field_order_cnt; |
441 | 141k | ps_dec->ps_cur_pic->i4_avg_poc = ps_pps->i4_avg_poc; |
442 | 141k | ps_dec->ps_cur_pic->u4_time_stamp = ps_dec->u4_pts; |
443 | | |
444 | 141k | ps_dec->s_cur_pic = *(ps_dec->ps_cur_pic); |
445 | 141k | if(u1_field_pic_flag && u1_bottom_field_flag) |
446 | 0 | { |
447 | 0 | WORD32 i4_temp_poc; |
448 | 0 | WORD32 i4_top_field_order_poc, i4_bot_field_order_poc; |
449 | | /* Point to odd lines, since it's bottom field */ |
450 | 0 | ps_dec->s_cur_pic.pu1_buf1 += ps_dec->s_cur_pic.u2_frm_wd_y; |
451 | 0 | ps_dec->s_cur_pic.pu1_buf2 += ps_dec->s_cur_pic.u2_frm_wd_uv; |
452 | 0 | ps_dec->s_cur_pic.pu1_buf3 += ps_dec->s_cur_pic.u2_frm_wd_uv; |
453 | 0 | ps_dec->s_cur_pic.ps_mv += ((ps_dec->u2_pic_ht * ps_dec->u2_pic_wd) >> 5); |
454 | 0 | ps_dec->s_cur_pic.pu1_col_zero_flag += ((ps_dec->u2_pic_ht * ps_dec->u2_pic_wd) >> 5); |
455 | 0 | ps_dec->ps_cur_pic->u1_picturetype |= BOT_FLD; |
456 | 0 | i4_top_field_order_poc = ps_dec->ps_cur_pic->i4_top_field_order_cnt; |
457 | 0 | i4_bot_field_order_poc = ps_dec->ps_cur_pic->i4_bottom_field_order_cnt; |
458 | 0 | i4_temp_poc = MIN(i4_top_field_order_poc, i4_bot_field_order_poc); |
459 | 0 | ps_dec->ps_cur_pic->i4_avg_poc = i4_temp_poc; |
460 | 0 | } |
461 | | |
462 | 141k | ps_cur_slice->u1_mbaff_frame_flag = ps_seq->u1_mb_aff_flag && (!u1_field_pic_flag); |
463 | 141k | ps_dec->ps_cur_pic->u1_picturetype |= (ps_cur_slice->u1_mbaff_frame_flag << 2); |
464 | | |
465 | 141k | ps_dec->ps_cur_mb_row = ps_dec->ps_nbr_mb_row; |
466 | 141k | ps_dec->ps_cur_mb_row += 2; |
467 | 141k | ps_dec->ps_top_mb_row = ps_dec->ps_nbr_mb_row; |
468 | 141k | ps_dec->ps_top_mb_row += |
469 | 141k | ((ps_dec->u2_frm_wd_in_mbs + 2) << (1 - ps_dec->ps_cur_sps->u1_frame_mbs_only_flag)); |
470 | | // Increment by 2 ,so that left mb (mbaff decrements by 2) will always be valid |
471 | 141k | ps_dec->ps_top_mb_row += 2; |
472 | 141k | ps_dec->ps_mv_cur = ps_dec->s_cur_pic.ps_mv; |
473 | 141k | ps_dec->ps_mv_top = ps_dec->ps_mv_top_p[0]; |
474 | 141k | ps_dec->u1_mv_top_p = 0; |
475 | 141k | ps_dec->u4_mb_idx = 0; |
476 | 141k | ps_dec->ps_mv_left = ps_dec->s_cur_pic.ps_mv; |
477 | 141k | ps_dec->u4_total_mbs_coded = 0; |
478 | 141k | ps_dec->i4_submb_ofst = -(SUB_BLK_SIZE); |
479 | 141k | ps_dec->u4_pred_info_idx = 0; |
480 | 141k | ps_dec->u4_pred_info_pkd_idx = 0; |
481 | 141k | ps_dec->u4_dma_buf_idx = 0; |
482 | 141k | ps_dec->ps_mv = ps_dec->s_cur_pic.ps_mv; |
483 | 141k | ps_dec->ps_mv_bank_cur = ps_dec->s_cur_pic.ps_mv; |
484 | 141k | ps_dec->pu1_col_zero_flag = ps_dec->s_cur_pic.pu1_col_zero_flag; |
485 | 141k | ps_dec->ps_part = ps_dec->ps_parse_part_params; |
486 | 141k | ps_dec->i2_prev_slice_mbx = -1; |
487 | 141k | ps_dec->i2_prev_slice_mby = 0; |
488 | 141k | ps_dec->u2_mv_2mb[0] = 0; |
489 | 141k | ps_dec->u2_mv_2mb[1] = 0; |
490 | 141k | ps_dec->u1_last_pic_not_decoded = 0; |
491 | | |
492 | 141k | ps_dec->u2_cur_slice_num_dec_thread = 0; |
493 | 141k | ps_dec->u2_cur_slice_num_bs = 0; |
494 | 141k | ps_dec->u4_intra_pred_line_ofst = 0; |
495 | 141k | ps_dec->pu1_cur_y_intra_pred_line = ps_dec->pu1_y_intra_pred_line; |
496 | 141k | ps_dec->pu1_cur_u_intra_pred_line = ps_dec->pu1_u_intra_pred_line; |
497 | 141k | ps_dec->pu1_cur_v_intra_pred_line = ps_dec->pu1_v_intra_pred_line; |
498 | | |
499 | 141k | ps_dec->pu1_cur_y_intra_pred_line_base = ps_dec->pu1_y_intra_pred_line; |
500 | 141k | ps_dec->pu1_cur_u_intra_pred_line_base = ps_dec->pu1_u_intra_pred_line; |
501 | 141k | ps_dec->pu1_cur_v_intra_pred_line_base = ps_dec->pu1_v_intra_pred_line; |
502 | | |
503 | 141k | ps_dec->pu1_prev_y_intra_pred_line = |
504 | 141k | ps_dec->pu1_y_intra_pred_line + (ps_dec->u2_frm_wd_in_mbs * MB_SIZE); |
505 | | |
506 | 141k | ps_dec->pu1_prev_u_intra_pred_line = |
507 | 141k | ps_dec->pu1_u_intra_pred_line + ps_dec->u2_frm_wd_in_mbs * BLK8x8SIZE * YUV420SP_FACTOR; |
508 | 141k | ps_dec->pu1_prev_v_intra_pred_line = |
509 | 141k | ps_dec->pu1_v_intra_pred_line + ps_dec->u2_frm_wd_in_mbs * BLK8x8SIZE; |
510 | | |
511 | 141k | ps_dec->ps_deblk_mbn = ps_dec->ps_deblk_pic; |
512 | | /* Initialize The Function Pointer Depending Upon the Entropy and MbAff Flag |
513 | | */ |
514 | 141k | { |
515 | 141k | if(ps_cur_slice->u1_mbaff_frame_flag) |
516 | 0 | { |
517 | 0 | ps_dec->pf_compute_bs = ih264d_compute_bs_mbaff; |
518 | 0 | ps_dec->pf_mvpred = ih264d_mvpred_mbaff; |
519 | 0 | ps_svc_lyr_dec->pf_svc_compute_bs = isvcd_compute_bs_non_mbaff; |
520 | 0 | } |
521 | 141k | else |
522 | 141k | { |
523 | 141k | ps_dec->pf_compute_bs = ih264d_compute_bs_non_mbaff; |
524 | 141k | ps_svc_lyr_dec->pf_svc_compute_bs = isvcd_compute_bs_non_mbaff; |
525 | 141k | ps_dec->u1_cur_mb_fld_dec_flag = ps_cur_slice->u1_field_pic_flag; |
526 | | |
527 | 141k | if((ps_svc_lyr_dec->u1_layer_identifier == TARGET_LAYER) && |
528 | 141k | (0 == ps_svc_lyr_dec->u1_base_res_flag)) |
529 | 36.6k | { |
530 | 36.6k | ps_svc_lyr_dec->pf_svc_compute_bs = isvcd_compute_bs_non_mbaff_target_lyr; |
531 | 36.6k | } |
532 | | |
533 | 141k | if((ps_svc_lyr_dec->u1_layer_identifier == TARGET_LAYER) && |
534 | 141k | (1 == ps_svc_lyr_dec->u1_base_res_flag)) |
535 | 58.6k | { |
536 | 58.6k | ps_svc_lyr_dec->pf_svc_compute_bs = |
537 | 58.6k | isvcd_compute_bs_non_mbaff_target_lyr_no_inter_layer; |
538 | 58.6k | } |
539 | | |
540 | 141k | if((ps_svc_lyr_dec->u1_layer_identifier == MEDIAL_ENHANCEMENT_LAYER) && |
541 | 141k | (0 == ps_svc_lyr_dec->u1_base_res_flag)) |
542 | 0 | { |
543 | 0 | ps_svc_lyr_dec->pf_svc_compute_bs = isvcd_compute_bs_non_mbaff_medial_lyr; |
544 | 0 | } |
545 | 141k | } |
546 | 141k | } |
547 | | /* Set up the Parameter for DMA transfer */ |
548 | 141k | { |
549 | 141k | UWORD8 u1_field_pic_flag = ps_dec->ps_cur_slice->u1_field_pic_flag; |
550 | 141k | UWORD8 u1_mbaff = ps_cur_slice->u1_mbaff_frame_flag; |
551 | 141k | UWORD8 uc_lastmbs = (((ps_dec->u2_pic_wd) >> 4) % (ps_dec->u4_recon_mb_grp >> u1_mbaff)); |
552 | 141k | UWORD16 ui16_lastmbs_widthY = |
553 | 141k | (uc_lastmbs ? (uc_lastmbs << 4) : ((ps_dec->u4_recon_mb_grp >> u1_mbaff) << 4)); |
554 | 141k | UWORD16 ui16_lastmbs_widthUV = |
555 | 141k | uc_lastmbs ? (uc_lastmbs << 3) : ((ps_dec->u4_recon_mb_grp >> u1_mbaff) << 3); |
556 | | |
557 | 141k | ps_dec->s_tran_addrecon.pu1_dest_y = ps_dec->s_cur_pic.pu1_buf1; |
558 | 141k | ps_dec->s_tran_addrecon.pu1_dest_u = ps_dec->s_cur_pic.pu1_buf2; |
559 | 141k | ps_dec->s_tran_addrecon.pu1_dest_v = ps_dec->s_cur_pic.pu1_buf3; |
560 | | |
561 | 141k | ps_dec->s_tran_addrecon.u2_frm_wd_y = ps_dec->u2_frm_wd_y << u1_field_pic_flag; |
562 | 141k | ps_dec->s_tran_addrecon.u2_frm_wd_uv = ps_dec->u2_frm_wd_uv << u1_field_pic_flag; |
563 | | |
564 | 141k | if(u1_field_pic_flag) |
565 | 0 | { |
566 | 0 | ui16_lastmbs_widthY += ps_dec->u2_frm_wd_y; |
567 | 0 | ui16_lastmbs_widthUV += ps_dec->u2_frm_wd_uv; |
568 | 0 | } |
569 | | |
570 | | /* Normal Increment of Pointer */ |
571 | 141k | ps_dec->s_tran_addrecon.u4_inc_y[0] = ((ps_dec->u4_recon_mb_grp << 4) >> u1_mbaff); |
572 | 141k | ps_dec->s_tran_addrecon.u4_inc_uv[0] = ((ps_dec->u4_recon_mb_grp << 4) >> u1_mbaff); |
573 | | |
574 | | /* End of Row Increment */ |
575 | 141k | ps_dec->s_tran_addrecon.u4_inc_y[1] = |
576 | 141k | (ui16_lastmbs_widthY + (PAD_LEN_Y_H << 1) + |
577 | 141k | ps_dec->s_tran_addrecon.u2_frm_wd_y * ((15 << u1_mbaff) + u1_mbaff)); |
578 | 141k | ps_dec->s_tran_addrecon.u4_inc_uv[1] = |
579 | 141k | (ui16_lastmbs_widthUV + (PAD_LEN_UV_H << 2) + |
580 | 141k | ps_dec->s_tran_addrecon.u2_frm_wd_uv * ((15 << u1_mbaff) + u1_mbaff)); |
581 | | |
582 | | /* Assign picture numbers to each frame/field */ |
583 | | /* only once per picture. */ |
584 | 141k | ih264d_assign_pic_num(ps_dec); |
585 | 141k | ps_dec->s_tran_addrecon.u2_mv_top_left_inc = |
586 | 141k | (ps_dec->u4_recon_mb_grp << 2) - 1 - (u1_mbaff << 2); |
587 | 141k | ps_dec->s_tran_addrecon.u2_mv_left_inc = ((ps_dec->u4_recon_mb_grp >> u1_mbaff) - 1) |
588 | 141k | << (4 + u1_mbaff); |
589 | 141k | } |
590 | | /**********************************************************************/ |
591 | | /* High profile related initialization at pictrue level */ |
592 | | /**********************************************************************/ |
593 | 141k | if((ps_seq->u1_profile_idc == HIGH_PROFILE_IDC) || |
594 | 141k | (ps_seq->u1_profile_idc == SCALABLE_HIGH_PROFILE_IDC) || |
595 | 141k | (ps_seq->u1_profile_idc == SCALABLE_BASELINE_PROFILE_IDC)) |
596 | 15.2k | { |
597 | 15.2k | if((ps_seq->i4_seq_scaling_matrix_present_flag) || |
598 | 15.2k | (ps_pps->i4_pic_scaling_matrix_present_flag)) |
599 | 11.0k | { |
600 | 11.0k | ret = ih264d_form_scaling_matrix_picture(ps_seq, ps_pps, ps_dec); |
601 | 11.0k | ps_dec->s_high_profile.u1_scaling_present = 1; |
602 | 11.0k | } |
603 | 4.19k | else |
604 | 4.19k | { |
605 | 4.19k | ret = ih264d_form_default_scaling_matrix(ps_dec); |
606 | 4.19k | } |
607 | | |
608 | 15.2k | if(ps_pps->i4_transform_8x8_mode_flag) |
609 | 9.53k | { |
610 | 9.53k | ps_dec->s_high_profile.u1_transform8x8_present = 1; |
611 | 9.53k | } |
612 | 15.2k | } |
613 | 126k | else |
614 | 126k | { |
615 | 126k | ret = ih264d_form_default_scaling_matrix(ps_dec); |
616 | 126k | } |
617 | | |
618 | 141k | if(ret != OK) return ret; |
619 | | |
620 | | /* required while reading the transform_size_8x8 u4_flag */ |
621 | 141k | ps_dec->s_high_profile.u1_direct_8x8_inference_flag = ps_seq->u1_direct_8x8_inference_flag; |
622 | 141k | ps_dec->s_high_profile.s_cavlc_ctxt = ps_dec->s_cavlc_ctxt; |
623 | | |
624 | 141k | ps_dec->i1_recon_in_thread3_flag = 1; |
625 | 141k | ps_dec->ps_frame_buf_ip_recon = &ps_dec->s_tran_addrecon; |
626 | 141k | if(ps_dec->u1_separate_parse) |
627 | 51.4k | { |
628 | 51.4k | memcpy(&ps_dec->s_tran_addrecon_parse, &ps_dec->s_tran_addrecon, sizeof(tfr_ctxt_t)); |
629 | 51.4k | } |
630 | | |
631 | 141k | ih264d_init_deblk_tfr_ctxt(ps_dec, &(ps_dec->s_pad_mgr), &(ps_dec->s_tran_addrecon), |
632 | 141k | ps_dec->u2_frm_wd_in_mbs, 0); |
633 | | |
634 | 141k | ps_dec->ps_cur_deblk_mb = ps_dec->ps_deblk_pic; |
635 | 141k | ps_dec->u4_cur_deblk_mb_num = 0; |
636 | 141k | ps_dec->u4_deblk_mb_x = 0; |
637 | 141k | ps_dec->u4_deblk_mb_y = 0; |
638 | 141k | ps_dec->pu4_wt_ofsts = ps_dec->pu4_wts_ofsts_mat; |
639 | | |
640 | 141k | ps_dec->u4_first_slice_in_pic = 0; |
641 | 141k | H264_MUTEX_UNLOCK(&ps_dec->process_disp_mutex); |
642 | 141k | return OK; |
643 | 141k | } |
644 | | /*! |
645 | | ************************************************************************** |
646 | | * \if Function name : isvcd_parse_decode_slice_ext_nal \endif |
647 | | * |
648 | | * \brief |
649 | | * Parses a slice extension NAL |
650 | | * |
651 | | * \return |
652 | | * 0 on Success and Error code otherwise |
653 | | ************************************************************************** |
654 | | */ |
655 | | WORD32 isvcd_parse_decode_slice_ext_nal(UWORD8 u1_is_idr_slice, UWORD8 u1_nal_ref_idc, |
656 | | svc_dec_lyr_struct_t *ps_svc_lyr_dec) |
657 | 40.2k | { |
658 | 40.2k | dec_struct_t *ps_dec = &ps_svc_lyr_dec->s_dec; |
659 | 40.2k | dec_bit_stream_t *ps_bitstrm = ps_dec->ps_bitstrm; |
660 | 40.2k | dec_pic_params_t *ps_pps; |
661 | 40.2k | dec_seq_params_t *ps_seq; |
662 | 40.2k | dec_svc_seq_params_t *ps_subset_seq; |
663 | 40.2k | dec_slice_params_t *ps_cur_slice = NULL; |
664 | 40.2k | dec_slice_svc_ext_params_t *ps_svc_slice_params = NULL; |
665 | | |
666 | 40.2k | pocstruct_t s_tmp_poc = {0}; |
667 | 40.2k | WORD32 i_delta_poc[2] = {0}; |
668 | 40.2k | WORD32 i4_poc = 0; |
669 | 40.2k | UWORD16 u2_first_mb_in_slice, u2_frame_num; |
670 | 40.2k | UWORD8 u1_field_pic_flag, u1_redundant_pic_cnt = 0, u1_slice_type; |
671 | 40.2k | UWORD32 u4_idr_pic_id = 0; |
672 | 40.2k | UWORD8 u1_bottom_field_flag, u1_pic_order_cnt_type; |
673 | | |
674 | 40.2k | UWORD8 u1_nal_unit_type; |
675 | 40.2k | UWORD32 *pu4_bitstrm_buf = ps_bitstrm->pu4_buffer; |
676 | 40.2k | UWORD32 *pu4_bitstrm_ofst = &ps_bitstrm->u4_ofst; |
677 | 40.2k | WORD8 i1_is_end_of_poc; |
678 | 40.2k | WORD32 ret; |
679 | 40.2k | WORD32 prev_slice_err, num_mb_skipped; |
680 | 40.2k | UWORD8 u1_mbaff; |
681 | 40.2k | pocstruct_t *ps_cur_poc; |
682 | 40.2k | UWORD32 u4_temp; |
683 | 40.2k | WORD32 i_temp; |
684 | 40.2k | svc_dec_ctxt_t *psvcd_dec_ctxt; |
685 | 40.2k | dec_struct_t *ps_dec_cur_lyr_minus_1; |
686 | 40.2k | svc_dec_lyr_struct_t *ps_svc_cur_lyr_dec_minus_1; |
687 | | |
688 | 40.2k | ps_cur_slice = ps_dec->ps_cur_slice; |
689 | 40.2k | ps_svc_slice_params = &ps_svc_lyr_dec->s_svc_slice_params; |
690 | | |
691 | | /* read FirstMbInSlice and slice type*/ |
692 | 40.2k | ps_dec->ps_dpb_cmds->u1_dpb_commands_read_slc = 0; |
693 | 40.2k | u2_first_mb_in_slice = ih264d_uev(pu4_bitstrm_ofst, pu4_bitstrm_buf); |
694 | 40.2k | if(u2_first_mb_in_slice > (ps_dec->u2_frm_ht_in_mbs * ps_dec->u2_frm_wd_in_mbs)) |
695 | 160 | { |
696 | 160 | return ERROR_CORRUPTED_SLICE; |
697 | 160 | } |
698 | | |
699 | | /*we currently don not support ASO*/ |
700 | 40.1k | if(((u2_first_mb_in_slice << ps_cur_slice->u1_mbaff_frame_flag) <= ps_dec->u4_cur_mb_addr) && |
701 | 40.1k | (ps_dec->u4_first_slice_in_pic == 0)) |
702 | 89 | { |
703 | 89 | return ERROR_CORRUPTED_SLICE; |
704 | 89 | } |
705 | | |
706 | 40.0k | if(ps_dec->u4_first_slice_in_pic == 1) |
707 | 39.6k | { |
708 | 39.6k | if(u2_first_mb_in_slice != 0) |
709 | 115 | { |
710 | 115 | return ERROR_CORRUPTED_SLICE; |
711 | 115 | } |
712 | 39.6k | } |
713 | | |
714 | 39.9k | COPYTHECONTEXT("Slice Header SVC ext: first_mb_in_slice", u2_first_mb_in_slice); |
715 | | |
716 | 39.9k | u4_temp = ih264d_uev(pu4_bitstrm_ofst, pu4_bitstrm_buf); |
717 | | |
718 | 39.9k | if(u4_temp > 9) return ERROR_INV_SLC_TYPE_T; |
719 | | |
720 | 39.8k | u1_slice_type = u4_temp; |
721 | 39.8k | COPYTHECONTEXT("Slice Header SVC ext: slice_type", (u1_slice_type)); |
722 | | /* Find Out the Slice Type is 5 to 9 or not then Set the Flag */ |
723 | | /* u1_sl_typ_5_9 = 1 .Which tells that all the slices in the Pic*/ |
724 | | /* will be of same type of current */ |
725 | 39.8k | if(u1_slice_type > 4) |
726 | 294 | { |
727 | 294 | u1_slice_type -= 5; |
728 | 294 | } |
729 | | |
730 | 39.8k | u4_temp = ih264d_uev(pu4_bitstrm_ofst, pu4_bitstrm_buf); |
731 | 39.8k | if(u4_temp & MASK_ERR_PIC_SET_ID) return ERROR_INV_SLICE_HDR_T; |
732 | | /* discard slice if pic param is invalid */ |
733 | 39.7k | COPYTHECONTEXT("Slice Header SVC ext: pic_parameter_set_id", u4_temp); |
734 | 39.7k | ps_pps = &ps_dec->ps_pps[u4_temp]; |
735 | 39.7k | if(FALSE == ps_pps->u1_is_valid) |
736 | 75 | { |
737 | 75 | return ERROR_INV_SLICE_HDR_T; |
738 | 75 | } |
739 | | /* slices in a layer should have same PPS id*/ |
740 | 39.6k | if(UINT32_MAX == ps_svc_lyr_dec->u4_pps_id_for_layer) |
741 | 39.2k | { |
742 | 39.2k | ps_svc_lyr_dec->u4_pps_id_for_layer = u4_temp; |
743 | 39.2k | } |
744 | 380 | else if(u4_temp != ps_svc_lyr_dec->u4_pps_id_for_layer) |
745 | 66 | { |
746 | 66 | return ERROR_INV_SLICE_HDR_T; |
747 | 66 | } |
748 | 39.5k | ps_seq = ps_pps->ps_sps; |
749 | 39.5k | ps_seq += MAX_NUM_SEQ_PARAMS; |
750 | 39.5k | ps_subset_seq = |
751 | 39.5k | &ps_svc_lyr_dec->ps_subset_sps[MAX_NUM_SEQ_PARAMS + ps_seq->u1_seq_parameter_set_id]; |
752 | | |
753 | 39.5k | ps_dec->ps_cur_sps = ps_seq; |
754 | 39.5k | ps_svc_lyr_dec->ps_cur_subset_sps = ps_subset_seq; |
755 | | |
756 | 39.5k | if(!ps_seq) return ERROR_INV_SLICE_HDR_T; |
757 | 39.5k | if(FALSE == ps_seq->u1_is_valid) return ERROR_INV_SLICE_HDR_T; |
758 | 39.3k | if(ps_seq->u1_mb_aff_flag) return ERROR_INV_SLICE_HDR_T; |
759 | 39.2k | if(ps_seq->u1_level_idc > H264_LEVEL_4_2) return ERROR_INV_SLICE_HDR_T; |
760 | 39.2k | if(!ps_seq->u1_frame_mbs_only_flag) return ERROR_INV_SLICE_HDR_T; |
761 | 39.1k | if(OK != isvcd_verify_level(ps_seq->u1_level_idc)) return ERROR_INV_SLICE_HDR_T; |
762 | | |
763 | 39.0k | if(ps_dec->u1_init_dec_flag == 1) |
764 | 30.8k | { |
765 | 30.8k | if(ps_dec->u2_frm_wd_in_mbs != ps_seq->u2_frm_wd_in_mbs) return ERROR_INV_SLICE_HDR_T; |
766 | 30.8k | if(ps_dec->u2_frm_ht_in_mbs != ps_seq->u2_frm_ht_in_mbs) return ERROR_INV_SLICE_HDR_T; |
767 | 30.8k | } |
768 | | |
769 | 38.9k | if(ps_dec->u1_init_dec_flag == 1) |
770 | 30.7k | { |
771 | 30.7k | if(ps_dec->u2_disp_height != ps_subset_seq->u2_disp_height) return ERROR_INV_SLICE_HDR_T; |
772 | 30.6k | if(ps_dec->u2_disp_width != ps_subset_seq->u2_disp_width) return ERROR_INV_SLICE_HDR_T; |
773 | 30.6k | } |
774 | | |
775 | 38.7k | ps_dec->i4_reorder_depth = ps_subset_seq->i4_reorder_depth; |
776 | | |
777 | 38.7k | ps_dec->u2_disp_height = ps_subset_seq->u2_disp_height; |
778 | 38.7k | ps_dec->u2_disp_width = ps_subset_seq->u2_disp_width; |
779 | | |
780 | 38.7k | if(ps_svc_lyr_dec->u1_layer_id > 0) |
781 | 38.7k | { |
782 | 38.7k | psvcd_dec_ctxt = ps_svc_lyr_dec->ps_svcd_ctxt; |
783 | 38.7k | ps_svc_cur_lyr_dec_minus_1 = |
784 | 38.7k | &psvcd_dec_ctxt->ps_svc_dec_lyr[ps_svc_lyr_dec->u1_layer_id - 1]; |
785 | | |
786 | 38.7k | ps_dec_cur_lyr_minus_1 = &ps_svc_cur_lyr_dec_minus_1->s_dec; |
787 | | |
788 | 38.7k | if((ps_dec_cur_lyr_minus_1->u2_pic_wd > ps_subset_seq->u2_pic_wd) || |
789 | 38.7k | (ps_dec_cur_lyr_minus_1->u2_pic_ht > ps_subset_seq->u2_pic_ht)) |
790 | 142 | { |
791 | 142 | return ERROR_CORRUPTED_SLICE; |
792 | 142 | } |
793 | 38.7k | } |
794 | | |
795 | 38.6k | ps_dec->u2_pic_wd = ps_subset_seq->u2_pic_wd; |
796 | 38.6k | ps_dec->u2_pic_ht = ps_subset_seq->u2_pic_ht; |
797 | 38.6k | ps_dec->u4_total_mbs = ps_seq->u4_total_num_of_mbs << (1 - ps_seq->u1_frame_mbs_only_flag); |
798 | | |
799 | | /* Determining the Width and Height of Frame from that of Picture */ |
800 | 38.6k | ps_dec->u2_frm_wd_y = ps_subset_seq->u2_frm_wd_y; |
801 | 38.6k | ps_dec->u2_frm_ht_y = ps_subset_seq->u2_frm_ht_y; |
802 | | |
803 | 38.6k | ps_dec->u2_frm_wd_uv = ps_subset_seq->u2_frm_wd_uv; |
804 | 38.6k | ps_dec->u2_frm_ht_uv = ps_subset_seq->u2_frm_ht_uv; |
805 | | |
806 | 38.6k | ps_dec->s_pad_mgr.u1_pad_len_y_v = ps_subset_seq->u1_pad_len_y_v; |
807 | 38.6k | ps_dec->s_pad_mgr.u1_pad_len_cr_v = ps_subset_seq->u1_pad_len_cr_v; |
808 | | |
809 | 38.6k | ps_dec->u2_frm_wd_in_mbs = ps_seq->u2_frm_wd_in_mbs; |
810 | 38.6k | ps_dec->u2_frm_ht_in_mbs = ps_seq->u2_frm_ht_in_mbs; |
811 | | |
812 | 38.6k | ps_dec->u2_crop_offset_y = ps_subset_seq->u2_crop_offset_y; |
813 | 38.6k | ps_dec->u2_crop_offset_uv = ps_subset_seq->u2_crop_offset_uv; |
814 | | |
815 | | /* Get the frame num */ |
816 | 38.6k | u2_frame_num = ih264d_get_bits_h264(ps_bitstrm, ps_seq->u1_bits_in_frm_num); |
817 | | |
818 | 38.6k | COPYTHECONTEXT("Slice Header SVC ext: frame_num", u2_frame_num); |
819 | 38.6k | if(!ps_dec->u1_first_slice_in_stream && ps_dec->u4_first_slice_in_pic) |
820 | 23.5k | { |
821 | 23.5k | pocstruct_t *ps_prev_poc = &ps_dec->s_prev_pic_poc; |
822 | 23.5k | pocstruct_t *ps_cur_poc = &ps_dec->s_cur_pic_poc; |
823 | | |
824 | 23.5k | ps_dec->u2_mbx = 0xffff; |
825 | 23.5k | ps_dec->u2_mby = 0; |
826 | | |
827 | 23.5k | if((0 == u1_is_idr_slice) && ps_cur_slice->u1_nal_ref_idc) |
828 | 1.59k | ps_dec->u2_prev_ref_frame_num = ps_cur_slice->u2_frame_num; |
829 | | |
830 | 23.5k | if(u1_is_idr_slice || ps_cur_slice->u1_mmco_equalto5) ps_dec->u2_prev_ref_frame_num = 0; |
831 | | |
832 | 23.5k | if(ps_dec->ps_cur_sps->u1_gaps_in_frame_num_value_allowed_flag) |
833 | 0 | { |
834 | 0 | isvcd_decode_gaps_in_frame_num(ps_dec, u2_frame_num); |
835 | 0 | } |
836 | | |
837 | 23.5k | ps_prev_poc->i4_prev_frame_num_ofst = ps_cur_poc->i4_prev_frame_num_ofst; |
838 | 23.5k | ps_prev_poc->u2_frame_num = ps_cur_poc->u2_frame_num; |
839 | 23.5k | ps_prev_poc->u1_mmco_equalto5 = ps_cur_slice->u1_mmco_equalto5; |
840 | 23.5k | if(ps_cur_slice->u1_nal_ref_idc) |
841 | 20.1k | { |
842 | 20.1k | ps_prev_poc->i4_pic_order_cnt_lsb = ps_cur_poc->i4_pic_order_cnt_lsb; |
843 | 20.1k | ps_prev_poc->i4_pic_order_cnt_msb = ps_cur_poc->i4_pic_order_cnt_msb; |
844 | 20.1k | ps_prev_poc->i4_delta_pic_order_cnt_bottom = ps_cur_poc->i4_delta_pic_order_cnt_bottom; |
845 | 20.1k | ps_prev_poc->i4_delta_pic_order_cnt[0] = ps_cur_poc->i4_delta_pic_order_cnt[0]; |
846 | 20.1k | ps_prev_poc->i4_delta_pic_order_cnt[1] = ps_cur_poc->i4_delta_pic_order_cnt[1]; |
847 | 20.1k | ps_prev_poc->u1_bot_field = ps_cur_poc->u1_bot_field; |
848 | 20.1k | } |
849 | | |
850 | 23.5k | ps_dec->u4_total_mbs_coded = 0; |
851 | 23.5k | } |
852 | | /* Get the field related flags */ |
853 | 38.6k | if(!ps_seq->u1_frame_mbs_only_flag) |
854 | 0 | { |
855 | 0 | u1_field_pic_flag = ih264d_get_bit_h264(ps_bitstrm); |
856 | 0 | COPYTHECONTEXT("Slice Header SVC ext: field_pic_flag", u1_field_pic_flag); |
857 | 0 | u1_bottom_field_flag = 0; |
858 | |
|
859 | 0 | if(u1_field_pic_flag) |
860 | 0 | { |
861 | 0 | ps_dec->pu1_inv_scan = (UWORD8 *) gau1_ih264d_inv_scan_fld; |
862 | 0 | u1_bottom_field_flag = ih264d_get_bit_h264(ps_bitstrm); |
863 | 0 | COPYTHECONTEXT("Slice Header SVC ext: bottom_field_flag", u1_bottom_field_flag); |
864 | 0 | } |
865 | 0 | else |
866 | 0 | { |
867 | 0 | ps_dec->pu1_inv_scan = (UWORD8 *) gau1_ih264d_inv_scan; |
868 | 0 | } |
869 | 0 | } |
870 | 38.6k | else |
871 | 38.6k | { |
872 | 38.6k | u1_field_pic_flag = 0; |
873 | 38.6k | u1_bottom_field_flag = 0; |
874 | 38.6k | ps_dec->pu1_inv_scan = (UWORD8 *) gau1_ih264d_inv_scan; |
875 | 38.6k | } |
876 | | |
877 | 38.6k | u1_nal_unit_type = SLICE_NAL; |
878 | 38.6k | if(u1_is_idr_slice) |
879 | 34.5k | { |
880 | 34.5k | u1_nal_unit_type = IDR_SLICE_NAL; |
881 | 34.5k | u4_idr_pic_id = ih264d_uev(pu4_bitstrm_ofst, pu4_bitstrm_buf); |
882 | 34.5k | if(u4_idr_pic_id > 65535) return ERROR_INV_SLICE_HDR_T; |
883 | 34.3k | COPYTHECONTEXT("Slice Header SVC ext: ", u4_idr_pic_id); |
884 | 34.3k | } |
885 | | |
886 | | /* read delta pic order count information*/ |
887 | 38.4k | i_delta_poc[0] = i_delta_poc[1] = 0; |
888 | 38.4k | s_tmp_poc.i4_pic_order_cnt_lsb = 0; |
889 | 38.4k | s_tmp_poc.i4_delta_pic_order_cnt_bottom = 0; |
890 | 38.4k | u1_pic_order_cnt_type = ps_seq->u1_pic_order_cnt_type; |
891 | 38.4k | if(u1_pic_order_cnt_type == 0) |
892 | 36.3k | { |
893 | 36.3k | i_temp = ih264d_get_bits_h264(ps_bitstrm, ps_seq->u1_log2_max_pic_order_cnt_lsb_minus); |
894 | 36.3k | if(i_temp < 0 || i_temp >= ps_seq->i4_max_pic_order_cntLsb) return ERROR_INV_SLICE_HDR_T; |
895 | 36.3k | s_tmp_poc.i4_pic_order_cnt_lsb = i_temp; |
896 | 36.3k | COPYTHECONTEXT("Slice Header SVC ext: pic_order_cnt_lsb", s_tmp_poc.i4_pic_order_cnt_lsb); |
897 | | |
898 | 36.3k | if((ps_pps->u1_pic_order_present_flag == 1) && (!u1_field_pic_flag)) |
899 | 4.06k | { |
900 | 4.06k | s_tmp_poc.i4_delta_pic_order_cnt_bottom = ih264d_sev(pu4_bitstrm_ofst, pu4_bitstrm_buf); |
901 | 4.06k | COPYTHECONTEXT("Slice Header SVC ext: delta_pic_order_cnt_bottom", |
902 | 4.06k | s_tmp_poc.i4_delta_pic_order_cnt_bottom); |
903 | 4.06k | } |
904 | 36.3k | } |
905 | | |
906 | 38.4k | s_tmp_poc.i4_delta_pic_order_cnt[0] = 0; |
907 | 38.4k | s_tmp_poc.i4_delta_pic_order_cnt[1] = 0; |
908 | 38.4k | if(u1_pic_order_cnt_type == 1 && (!ps_seq->u1_delta_pic_order_always_zero_flag)) |
909 | 458 | { |
910 | 458 | s_tmp_poc.i4_delta_pic_order_cnt[0] = ih264d_sev(pu4_bitstrm_ofst, pu4_bitstrm_buf); |
911 | 458 | COPYTHECONTEXT("Slice Header SVC ext: delta_pic_order_cnt[0]", |
912 | 458 | s_tmp_poc.i4_delta_pic_order_cnt[0]); |
913 | | |
914 | 458 | if(ps_pps->u1_pic_order_present_flag && !u1_field_pic_flag) |
915 | 282 | { |
916 | 282 | s_tmp_poc.i4_delta_pic_order_cnt[1] = ih264d_sev(pu4_bitstrm_ofst, pu4_bitstrm_buf); |
917 | 282 | COPYTHECONTEXT("Slice Header SVC ext: delta_pic_order_cnt[1]", |
918 | 282 | s_tmp_poc.i4_delta_pic_order_cnt[1]); |
919 | 282 | } |
920 | 458 | } |
921 | | |
922 | 38.4k | if(ps_pps->u1_redundant_pic_cnt_present_flag) |
923 | 13.9k | { |
924 | 13.9k | u4_temp = ih264d_uev(pu4_bitstrm_ofst, pu4_bitstrm_buf); |
925 | 13.9k | if(u4_temp > MAX_REDUNDANT_PIC_CNT) return ERROR_INV_SLICE_HDR_T; |
926 | 13.8k | u1_redundant_pic_cnt = u4_temp; |
927 | 13.8k | COPYTHECONTEXT("Slice Header SVC ext: redundant_pic_cnt", u1_redundant_pic_cnt); |
928 | 13.8k | } |
929 | | |
930 | | /*--------------------------------------------------------------------*/ |
931 | | /* Check if the slice is part of new picture */ |
932 | | /*--------------------------------------------------------------------*/ |
933 | | /* First slice of a picture is always considered as part of new picture */ |
934 | 38.3k | i1_is_end_of_poc = 1; |
935 | 38.3k | ps_dec->ps_dec_err_status->u1_err_flag &= MASK_REJECT_CUR_PIC; |
936 | | |
937 | 38.3k | if(ps_dec->u4_first_slice_in_pic == 0) |
938 | 314 | { |
939 | 314 | i1_is_end_of_poc = |
940 | 314 | ih264d_is_end_of_pic(u2_frame_num, u1_nal_ref_idc, &s_tmp_poc, &ps_dec->s_cur_pic_poc, |
941 | 314 | ps_cur_slice, u1_pic_order_cnt_type, u1_nal_unit_type, |
942 | 314 | u4_idr_pic_id, u1_field_pic_flag, u1_bottom_field_flag); |
943 | 314 | if(i1_is_end_of_poc) |
944 | 69 | { |
945 | 69 | ps_dec->u1_first_slice_in_stream = 0; |
946 | 69 | return ERROR_INCOMPLETE_FRAME; |
947 | 69 | } |
948 | 314 | } |
949 | | |
950 | | /*--------------------------------------------------------------------*/ |
951 | | /* Check for error in slice and parse the missing/corrupted MB's */ |
952 | | /* as skip-MB's in an inserted P-slice */ |
953 | | /*--------------------------------------------------------------------*/ |
954 | 38.2k | u1_mbaff = ps_seq->u1_mb_aff_flag && (!u1_field_pic_flag); |
955 | 38.2k | prev_slice_err = 0; |
956 | | |
957 | 38.2k | if(i1_is_end_of_poc || ps_dec->u1_first_slice_in_stream) |
958 | 38.0k | { |
959 | | /* If the current slice is not a field or frame number of the current |
960 | | * slice doesn't match with previous slice, and decoder is expecting |
961 | | * to decode a field i.e. ps_dec->u1_top_bottom_decoded is not 0 and |
962 | | * is not (TOP_FIELD_ONLY | BOT_FIELD_ONLY), treat it as a dangling |
963 | | * field */ |
964 | 38.0k | if((u1_field_pic_flag == 0 || u2_frame_num != ps_dec->u2_prv_frame_num) && |
965 | 38.0k | ps_dec->u1_top_bottom_decoded != 0 && |
966 | 38.0k | ps_dec->u1_top_bottom_decoded != (TOP_FIELD_ONLY | BOT_FIELD_ONLY)) |
967 | 0 | { |
968 | 0 | ps_dec->u1_dangling_field = 1; |
969 | 0 | if(ps_dec->u4_first_slice_in_pic) |
970 | 0 | { |
971 | | // first slice - dangling field |
972 | 0 | prev_slice_err = 1; |
973 | 0 | } |
974 | 0 | else |
975 | 0 | { |
976 | | // last slice - dangling field |
977 | 0 | prev_slice_err = 2; |
978 | 0 | } |
979 | |
|
980 | 0 | if(ps_dec->u1_top_bottom_decoded == TOP_FIELD_ONLY) |
981 | 0 | ps_cur_slice->u1_bottom_field_flag = 1; |
982 | 0 | else |
983 | 0 | ps_cur_slice->u1_bottom_field_flag = 0; |
984 | |
|
985 | 0 | num_mb_skipped = |
986 | 0 | (ps_dec->u2_frm_ht_in_mbs * ps_dec->u2_frm_wd_in_mbs) - ps_dec->u4_total_mbs_coded; |
987 | 0 | ps_cur_poc = &ps_dec->s_cur_pic_poc; |
988 | |
|
989 | 0 | u1_is_idr_slice = ps_cur_slice->u1_nal_unit_type == IDR_SLICE_NAL; |
990 | 0 | } |
991 | 38.0k | else if(ps_dec->u4_first_slice_in_pic) |
992 | 38.0k | { |
993 | 38.0k | if(u2_first_mb_in_slice > 0) |
994 | 0 | { |
995 | | // first slice - missing/header corruption |
996 | 0 | prev_slice_err = 1; |
997 | 0 | num_mb_skipped = u2_first_mb_in_slice << u1_mbaff; |
998 | 0 | ps_cur_poc = &s_tmp_poc; |
999 | | |
1000 | | // initializing slice parameters |
1001 | 0 | ps_cur_slice->u4_idr_pic_id = u4_idr_pic_id; |
1002 | 0 | ps_cur_slice->u1_field_pic_flag = u1_field_pic_flag; |
1003 | 0 | ps_cur_slice->u1_bottom_field_flag = u1_bottom_field_flag; |
1004 | 0 | ps_cur_slice->i4_pic_order_cnt_lsb = s_tmp_poc.i4_pic_order_cnt_lsb; |
1005 | 0 | ps_cur_slice->u1_nal_unit_type = u1_nal_unit_type; |
1006 | 0 | ps_cur_slice->u1_redundant_pic_cnt = u1_redundant_pic_cnt; |
1007 | 0 | ps_cur_slice->u1_nal_ref_idc = u1_nal_ref_idc; |
1008 | 0 | ps_cur_slice->u1_pic_order_cnt_type = u1_pic_order_cnt_type; |
1009 | 0 | ps_cur_slice->u1_mbaff_frame_flag = ps_seq->u1_mb_aff_flag && (!u1_field_pic_flag); |
1010 | 0 | } |
1011 | 38.0k | } |
1012 | 0 | else |
1013 | 0 | { |
1014 | | /* since i1_is_end_of_poc is set ,means new frame num is encountered. so |
1015 | | * conceal the current frame completely */ |
1016 | 0 | prev_slice_err = 2; |
1017 | 0 | num_mb_skipped = |
1018 | 0 | (ps_dec->u2_frm_ht_in_mbs * ps_dec->u2_frm_wd_in_mbs) - ps_dec->u4_total_mbs_coded; |
1019 | 0 | ps_cur_poc = &s_tmp_poc; |
1020 | 0 | } |
1021 | 38.0k | } |
1022 | 245 | else |
1023 | 245 | { |
1024 | 245 | if((u2_first_mb_in_slice << u1_mbaff) > ps_dec->u4_total_mbs_coded) |
1025 | 34 | { |
1026 | | // previous slice - missing/corruption |
1027 | 34 | prev_slice_err = 2; |
1028 | 34 | num_mb_skipped = (u2_first_mb_in_slice << u1_mbaff) - ps_dec->u4_total_mbs_coded; |
1029 | 34 | ps_cur_poc = &s_tmp_poc; |
1030 | 34 | } |
1031 | 211 | else if((u2_first_mb_in_slice << u1_mbaff) < ps_dec->u4_total_mbs_coded) |
1032 | 0 | { |
1033 | 0 | return ERROR_CORRUPTED_SLICE; |
1034 | 0 | } |
1035 | 245 | } |
1036 | 38.2k | if(prev_slice_err) |
1037 | 34 | { |
1038 | 34 | ret = isvcd_mark_err_slice_skip((svc_dec_lyr_struct_t *) ps_dec, num_mb_skipped, |
1039 | 34 | u1_is_idr_slice, u2_frame_num, ps_cur_poc, prev_slice_err); |
1040 | | |
1041 | 34 | if(ps_dec->u1_dangling_field == 1) |
1042 | 0 | { |
1043 | 0 | ps_dec->u1_second_field = 1 - ps_dec->u1_second_field; |
1044 | 0 | ps_dec->u1_first_slice_in_stream = 0; |
1045 | 0 | ps_dec->u1_top_bottom_decoded = TOP_FIELD_ONLY | BOT_FIELD_ONLY; |
1046 | 0 | return ERROR_DANGLING_FIELD_IN_PIC; |
1047 | 0 | } |
1048 | | |
1049 | 34 | if(prev_slice_err == 2) |
1050 | 34 | { |
1051 | 34 | ps_dec->u1_first_slice_in_stream = 0; |
1052 | 34 | return ERROR_INCOMPLETE_FRAME; |
1053 | 34 | } |
1054 | | |
1055 | 0 | if(ps_dec->u4_total_mbs_coded >= ps_dec->u2_frm_ht_in_mbs * ps_dec->u2_frm_wd_in_mbs) |
1056 | 0 | { |
1057 | | /* return if all MBs in frame are parsed*/ |
1058 | 0 | ps_dec->u1_first_slice_in_stream = 0; |
1059 | 0 | return ERROR_IN_LAST_SLICE_OF_PIC; |
1060 | 0 | } |
1061 | | |
1062 | 0 | if(ps_dec->ps_dec_err_status->u1_err_flag & REJECT_CUR_PIC) |
1063 | 0 | { |
1064 | 0 | ih264d_err_pic_dispbuf_mgr(ps_dec); |
1065 | 0 | return ERROR_NEW_FRAME_EXPECTED; |
1066 | 0 | } |
1067 | | |
1068 | 0 | if(ret != OK) return ret; |
1069 | | |
1070 | 0 | i1_is_end_of_poc = 0; |
1071 | 0 | } |
1072 | | |
1073 | 38.2k | if(u1_field_pic_flag) |
1074 | 0 | { |
1075 | 0 | ps_dec->u2_prv_frame_num = u2_frame_num; |
1076 | 0 | } |
1077 | | |
1078 | 38.2k | if(ps_cur_slice->u1_mmco_equalto5) |
1079 | 994 | { |
1080 | 994 | WORD32 i4_temp_poc; |
1081 | 994 | WORD32 i4_top_field_order_poc, i4_bot_field_order_poc; |
1082 | 994 | WORD64 i8_result; |
1083 | 994 | if(!ps_cur_slice->u1_field_pic_flag) // or a complementary field pair |
1084 | 994 | { |
1085 | 994 | i4_top_field_order_poc = ps_dec->ps_cur_pic->i4_top_field_order_cnt; |
1086 | 994 | i4_bot_field_order_poc = ps_dec->ps_cur_pic->i4_bottom_field_order_cnt; |
1087 | 994 | i4_temp_poc = MIN(i4_top_field_order_poc, i4_bot_field_order_poc); |
1088 | 994 | } |
1089 | 0 | else if(!ps_cur_slice->u1_bottom_field_flag) |
1090 | 0 | i4_temp_poc = ps_dec->ps_cur_pic->i4_top_field_order_cnt; |
1091 | 0 | else |
1092 | 0 | i4_temp_poc = ps_dec->ps_cur_pic->i4_bottom_field_order_cnt; |
1093 | | |
1094 | 994 | i8_result = (WORD64) i4_temp_poc - ps_dec->ps_cur_pic->i4_top_field_order_cnt; |
1095 | 994 | if(IS_OUT_OF_RANGE_S32(i8_result)) |
1096 | 0 | { |
1097 | 0 | return ERROR_INV_POC; |
1098 | 0 | } |
1099 | 994 | ps_dec->ps_cur_pic->i4_top_field_order_cnt = (WORD32) i8_result; |
1100 | 994 | i8_result = (WORD64) i4_temp_poc - ps_dec->ps_cur_pic->i4_bottom_field_order_cnt; |
1101 | 994 | if(IS_OUT_OF_RANGE_S32(i8_result)) |
1102 | 0 | { |
1103 | 0 | return ERROR_INV_POC; |
1104 | 0 | } |
1105 | 994 | ps_dec->ps_cur_pic->i4_bottom_field_order_cnt = (WORD32) i8_result; |
1106 | 994 | ps_dec->ps_cur_pic->i4_poc = i4_temp_poc; |
1107 | 994 | ps_dec->ps_cur_pic->i4_avg_poc = i4_temp_poc; |
1108 | 994 | } |
1109 | 38.2k | if(ps_dec->u4_first_slice_in_pic) |
1110 | 38.0k | { |
1111 | 38.0k | ret = isvcd_decode_pic_order_cnt(u1_is_idr_slice, u2_frame_num, &ps_dec->s_prev_pic_poc, |
1112 | 38.0k | &s_tmp_poc, ps_cur_slice, ps_pps, u1_nal_ref_idc, |
1113 | 38.0k | u1_bottom_field_flag, u1_field_pic_flag, &i4_poc, ps_dec); |
1114 | 38.0k | if(ret != OK) return ret; |
1115 | | /* Display seq no calculations */ |
1116 | 37.9k | if(i4_poc >= ps_dec->i4_max_poc) ps_dec->i4_max_poc = i4_poc; |
1117 | | /* IDR Picture or POC wrap around */ |
1118 | 37.9k | if(i4_poc == 0) |
1119 | 3.71k | { |
1120 | 3.71k | WORD64 i8_temp; |
1121 | 3.71k | i8_temp = (WORD64) ps_dec->i4_prev_max_display_seq + ps_dec->i4_max_poc + |
1122 | 3.71k | ps_dec->u1_max_dec_frame_buffering + 1; |
1123 | | /*If i4_prev_max_display_seq overflows integer range, reset it */ |
1124 | 3.71k | ps_dec->i4_prev_max_display_seq = IS_OUT_OF_RANGE_S32(i8_temp) ? 0 : i8_temp; |
1125 | 3.71k | ps_dec->i4_max_poc = 0; |
1126 | 3.71k | } |
1127 | 37.9k | } |
1128 | | |
1129 | | /* Increment only if the current slice has atleast 1 more MB */ |
1130 | 38.1k | if(ps_dec->u4_first_slice_in_pic == 0 && |
1131 | 38.1k | (ps_dec->ps_parse_cur_slice->u4_first_mb_in_slice < |
1132 | 211 | (UWORD32) (ps_dec->u4_total_mbs_coded >> ps_dec->ps_cur_slice->u1_mbaff_frame_flag))) |
1133 | 211 | { |
1134 | 211 | ps_dec->ps_parse_cur_slice++; |
1135 | 211 | ps_dec->u2_cur_slice_num++; |
1136 | | // in the case of single core increment ps_decode_cur_slice |
1137 | 211 | if(ps_dec->u1_separate_parse == 0) |
1138 | 112 | { |
1139 | 112 | ps_dec->ps_decode_cur_slice++; |
1140 | 112 | } |
1141 | 211 | } |
1142 | | |
1143 | 38.1k | ps_dec->u1_slice_header_done = 0; |
1144 | | |
1145 | | /*--------------------------------------------------------------------*/ |
1146 | | /* Copy the values read from the bitstream to the slice header and then*/ |
1147 | | /* If the slice is first slice in picture, then do Start of Picture */ |
1148 | | /* processing. */ |
1149 | | /*--------------------------------------------------------------------*/ |
1150 | 38.1k | ps_cur_slice->i4_delta_pic_order_cnt[0] = i_delta_poc[0]; |
1151 | 38.1k | ps_cur_slice->i4_delta_pic_order_cnt[1] = i_delta_poc[1]; |
1152 | 38.1k | ps_cur_slice->u4_idr_pic_id = u4_idr_pic_id; |
1153 | 38.1k | ps_cur_slice->u2_first_mb_in_slice = u2_first_mb_in_slice; |
1154 | 38.1k | ps_cur_slice->u1_field_pic_flag = u1_field_pic_flag; |
1155 | 38.1k | ps_cur_slice->u1_bottom_field_flag = u1_bottom_field_flag; |
1156 | 38.1k | ps_cur_slice->u1_slice_type = u1_slice_type; |
1157 | 38.1k | ps_cur_slice->i4_pic_order_cnt_lsb = s_tmp_poc.i4_pic_order_cnt_lsb; |
1158 | | |
1159 | 38.1k | ps_cur_slice->u1_nal_unit_type = u1_nal_unit_type; |
1160 | 38.1k | ps_cur_slice->u1_redundant_pic_cnt = u1_redundant_pic_cnt; |
1161 | 38.1k | ps_cur_slice->u1_nal_ref_idc = u1_nal_ref_idc; |
1162 | 38.1k | ps_cur_slice->u1_pic_order_cnt_type = u1_pic_order_cnt_type; |
1163 | | |
1164 | 38.1k | if(ps_seq->u1_frame_mbs_only_flag) |
1165 | 38.1k | ps_cur_slice->u1_direct_8x8_inference_flag = ps_seq->u1_direct_8x8_inference_flag; |
1166 | 0 | else |
1167 | 0 | ps_cur_slice->u1_direct_8x8_inference_flag = 1; |
1168 | | |
1169 | 38.1k | if(0 == ps_svc_lyr_dec->ps_nal_svc_ext->u1_quality_id) |
1170 | 38.1k | { |
1171 | 38.1k | if(B_SLICE == u1_slice_type) |
1172 | 14.6k | { |
1173 | 14.6k | ps_cur_slice->u1_direct_spatial_mv_pred_flag = ih264d_get_bit_h264(ps_bitstrm); |
1174 | 14.6k | COPYTHECONTEXT("Slice Header SVC ext: direct_spatial_mv_pred_flag", |
1175 | 14.6k | ps_cur_slice->u1_direct_spatial_mv_pred_flag); |
1176 | | |
1177 | 14.6k | if(ps_cur_slice->u1_direct_spatial_mv_pred_flag) |
1178 | 4.64k | ps_cur_slice->pf_decodeDirect = isvcd_decode_spatial_direct; |
1179 | 9.99k | else |
1180 | 9.99k | ps_cur_slice->pf_decodeDirect = ih264d_decode_temporal_direct; |
1181 | 14.6k | if(!((ps_seq->u1_mb_aff_flag) && (!u1_field_pic_flag))) |
1182 | 14.6k | ps_dec->pf_mvpred = ih264d_mvpred_nonmbaffB; |
1183 | 14.6k | } |
1184 | 23.4k | else |
1185 | 23.4k | { |
1186 | 23.4k | if(!((ps_seq->u1_mb_aff_flag) && (!u1_field_pic_flag))) /*check if this is valid here */ |
1187 | 23.4k | ps_dec->pf_mvpred = ih264d_mvpred_nonmbaff; |
1188 | 23.4k | } |
1189 | 38.1k | } |
1190 | | |
1191 | 38.1k | if(ps_dec->u4_first_slice_in_pic) |
1192 | 37.9k | { |
1193 | 37.9k | if(u2_first_mb_in_slice == 0) |
1194 | 37.9k | { |
1195 | 37.9k | ret = isvcd_start_of_pic(ps_svc_lyr_dec, i4_poc, &s_tmp_poc, u2_frame_num, ps_pps); |
1196 | 37.9k | if(ret != OK) return ret; |
1197 | | /*inter layer buffer intialization */ |
1198 | 36.6k | ps_svc_lyr_dec->ps_inter_lyr_mb_prms_cur_mb = |
1199 | 36.6k | ps_svc_lyr_dec->ps_inter_lyr_mb_prms_frm_start; |
1200 | 36.6k | ps_svc_lyr_dec->ps_il_pred_mv_bank_buf_cur_mb = |
1201 | 36.6k | ps_svc_lyr_dec->ps_il_pred_mv_bank_buf_base; |
1202 | 36.6k | } |
1203 | | |
1204 | 36.6k | ps_dec->u4_output_present = 0; |
1205 | | |
1206 | 36.6k | { |
1207 | 36.6k | ih264d_get_next_display_field(ps_dec, ps_dec->ps_out_buffer, &(ps_dec->s_disp_op)); |
1208 | | /* If error code is non-zero then there is no buffer available for |
1209 | | display, hence avoid format conversion */ |
1210 | | |
1211 | 36.6k | if(0 != ps_dec->s_disp_op.u4_error_code) |
1212 | 12.1k | { |
1213 | 12.1k | ps_dec->u4_output_present = 0; |
1214 | 12.1k | ps_dec->u4_fmt_conv_cur_row = ps_dec->s_disp_frame_info.u4_y_ht; |
1215 | 12.1k | } |
1216 | 24.5k | else |
1217 | 24.5k | ps_dec->u4_output_present = 1; |
1218 | 36.6k | } |
1219 | 36.6k | ret = isvcd_parse_interlayer_resamp_func_init(ps_svc_lyr_dec, u2_first_mb_in_slice); |
1220 | 36.6k | if(ret != OK) |
1221 | 499 | { |
1222 | 499 | return ERROR_CORRUPTED_SLICE; |
1223 | 499 | } |
1224 | 36.1k | if((ps_dec->u1_separate_parse == 1) && |
1225 | 36.1k | (ps_svc_lyr_dec->u1_layer_identifier == TARGET_LAYER) && (ps_svc_lyr_dec->u1_res_init_done == 1)) |
1226 | 20.6k | { |
1227 | 20.6k | if(ps_dec->u4_dec_thread_created == 0) |
1228 | 20.6k | { |
1229 | 20.6k | ithread_create(ps_dec->pv_dec_thread_handle, NULL, |
1230 | 20.6k | (void *) isvcd_decode_picture_thread, (void *) ps_dec); |
1231 | | |
1232 | 20.6k | ps_dec->u4_dec_thread_created = 1; |
1233 | 20.6k | } |
1234 | | #ifdef KEEP_THREADS_ACTIVE |
1235 | | ret = ithread_mutex_lock(ps_dec->apv_proc_start_mutex[0]); |
1236 | | RETURN_IF((ret != IV_SUCCESS), ret); |
1237 | | |
1238 | | ps_dec->ai4_process_start[0] = PROC_START; |
1239 | | ret = ithread_cond_signal(ps_dec->apv_proc_start_condition[0]); |
1240 | | RETURN_IF((ret != IV_SUCCESS), ret); |
1241 | | |
1242 | | ret = ithread_mutex_unlock(ps_dec->apv_proc_start_mutex[0]); |
1243 | | RETURN_IF((ret != IV_SUCCESS), ret); |
1244 | | #endif |
1245 | | #ifdef KEEP_THREADS_ACTIVE |
1246 | | if(ps_dec->u4_bs_deblk_thread_created) |
1247 | | { |
1248 | | ret = ithread_mutex_lock(ps_dec->apv_proc_start_mutex[1]); |
1249 | | RETURN_IF((ret != IV_SUCCESS), ret); |
1250 | | |
1251 | | ps_dec->ai4_process_start[1] = PROC_START; |
1252 | | ret = ithread_cond_signal(ps_dec->apv_proc_start_condition[1]); |
1253 | | RETURN_IF((ret != IV_SUCCESS), ret); |
1254 | | |
1255 | | ret = ithread_mutex_unlock(ps_dec->apv_proc_start_mutex[1]); |
1256 | | RETURN_IF((ret != IV_SUCCESS), ret); |
1257 | | } |
1258 | | #endif |
1259 | 20.6k | } |
1260 | 36.1k | } |
1261 | | |
1262 | | /* INITIALIZATION of fn ptrs for MC and formMbPartInfo functions */ |
1263 | 36.4k | { |
1264 | 36.4k | UWORD8 uc_nofield_nombaff; |
1265 | | |
1266 | 36.4k | uc_nofield_nombaff = |
1267 | 36.4k | ((ps_dec->ps_cur_slice->u1_field_pic_flag == 0) && |
1268 | 36.4k | (ps_dec->ps_cur_slice->u1_mbaff_frame_flag == 0) && (u1_slice_type != B_SLICE) && |
1269 | 36.4k | (ps_dec->ps_cur_pps->u1_wted_pred_flag == 0)); |
1270 | | |
1271 | | /* Initialise MC and formMbPartInfo fn ptrs one time based on profile_idc */ |
1272 | | |
1273 | 36.4k | if(uc_nofield_nombaff) |
1274 | 18.3k | { |
1275 | 18.3k | ps_dec->p_form_mb_part_info = ih264d_form_mb_part_info_bp; |
1276 | 18.3k | ps_dec->p_motion_compensate = ih264d_motion_compensate_bp; |
1277 | 18.3k | } |
1278 | 18.0k | else |
1279 | 18.0k | { |
1280 | 18.0k | ps_dec->p_form_mb_part_info = ih264d_form_mb_part_info_mp; |
1281 | 18.0k | ps_dec->p_motion_compensate = ih264d_motion_compensate_mp; |
1282 | 18.0k | } |
1283 | 36.4k | } |
1284 | | |
1285 | | /* |
1286 | | * Decide whether to decode the current picture or not |
1287 | | */ |
1288 | 36.4k | { |
1289 | 36.4k | dec_err_status_t *ps_err = ps_dec->ps_dec_err_status; |
1290 | 36.4k | if(ps_err->u4_frm_sei_sync == u2_frame_num) |
1291 | 0 | { |
1292 | 0 | ps_err->u1_err_flag = ACCEPT_ALL_PICS; |
1293 | 0 | ps_err->u4_frm_sei_sync = SYNC_FRM_DEFAULT; |
1294 | 0 | } |
1295 | 36.4k | ps_err->u4_cur_frm = u2_frame_num; |
1296 | 36.4k | } |
1297 | | |
1298 | | /* Decision for decoding if the picture is to be skipped */ |
1299 | 36.4k | { |
1300 | 36.4k | WORD32 i4_skip_b_pic, i4_skip_p_pic; |
1301 | | |
1302 | 36.4k | i4_skip_b_pic = (ps_dec->u4_skip_frm_mask & B_SLC_BIT) && (B_SLICE == u1_slice_type) && |
1303 | 36.4k | (0 == u1_nal_ref_idc); |
1304 | | |
1305 | 36.4k | i4_skip_p_pic = (ps_dec->u4_skip_frm_mask & P_SLC_BIT) && (P_SLICE == u1_slice_type) && |
1306 | 36.4k | (0 == u1_nal_ref_idc); |
1307 | | |
1308 | | /**************************************************************/ |
1309 | | /* Skip the B picture if skip mask is set for B picture and */ |
1310 | | /* Current B picture is a non reference B picture or there is */ |
1311 | | /* no user for reference B picture */ |
1312 | | /**************************************************************/ |
1313 | 36.4k | if(i4_skip_b_pic) |
1314 | 0 | { |
1315 | 0 | ps_dec->ps_cur_pic->u4_pack_slc_typ |= B_SLC_BIT; |
1316 | | /* Don't decode the picture in SKIP-B mode if that picture is B */ |
1317 | | /* and also it is not to be used as a reference picture */ |
1318 | 0 | ps_dec->u1_last_pic_not_decoded = 1; |
1319 | |
|
1320 | 0 | return OK; |
1321 | 0 | } |
1322 | | /**************************************************************/ |
1323 | | /* Skip the P picture if skip mask is set for P picture and */ |
1324 | | /* Current P picture is a non reference P picture or there is */ |
1325 | | /* no user for reference P picture */ |
1326 | | /**************************************************************/ |
1327 | 36.4k | if(i4_skip_p_pic) |
1328 | 0 | { |
1329 | 0 | ps_dec->ps_cur_pic->u4_pack_slc_typ |= P_SLC_BIT; |
1330 | | /* Don't decode the picture in SKIP-P mode if that picture is P */ |
1331 | | /* and also it is not to be used as a reference picture */ |
1332 | 0 | ps_dec->u1_last_pic_not_decoded = 1; |
1333 | |
|
1334 | 0 | return OK; |
1335 | 0 | } |
1336 | 36.4k | } |
1337 | | |
1338 | 36.4k | { |
1339 | 36.4k | UWORD16 u2_mb_x, u2_mb_y; |
1340 | | |
1341 | 36.4k | ps_dec->i4_submb_ofst = |
1342 | 36.4k | ((u2_first_mb_in_slice << ps_cur_slice->u1_mbaff_frame_flag) * SUB_BLK_SIZE) - |
1343 | 36.4k | SUB_BLK_SIZE; |
1344 | 36.4k | if(u2_first_mb_in_slice) |
1345 | 211 | { |
1346 | 211 | UWORD8 u1_mb_aff; |
1347 | 211 | UWORD8 u1_field_pic; |
1348 | 211 | UWORD16 u2_frm_wd_in_mbs; |
1349 | 211 | u2_frm_wd_in_mbs = ps_seq->u2_frm_wd_in_mbs; |
1350 | 211 | u1_mb_aff = ps_cur_slice->u1_mbaff_frame_flag; |
1351 | 211 | u1_field_pic = ps_cur_slice->u1_field_pic_flag; |
1352 | | |
1353 | 211 | { |
1354 | 211 | UWORD32 x_offset; |
1355 | 211 | UWORD32 y_offset; |
1356 | 211 | UWORD32 u4_frame_stride; |
1357 | 211 | tfr_ctxt_t *ps_trns_addr; // = &ps_dec->s_tran_addrecon_parse; |
1358 | | |
1359 | 211 | if(ps_dec->u1_separate_parse) |
1360 | 99 | { |
1361 | 99 | ps_trns_addr = &ps_dec->s_tran_addrecon_parse; |
1362 | 99 | } |
1363 | 112 | else |
1364 | 112 | { |
1365 | 112 | ps_trns_addr = &ps_dec->s_tran_addrecon; |
1366 | 112 | } |
1367 | 211 | u2_mb_x = MOD(u2_first_mb_in_slice, u2_frm_wd_in_mbs); |
1368 | 211 | u2_mb_y = DIV(u2_first_mb_in_slice, u2_frm_wd_in_mbs); |
1369 | | |
1370 | 211 | u2_mb_y <<= u1_mb_aff; |
1371 | | |
1372 | 211 | if((u2_mb_x > u2_frm_wd_in_mbs - 1) || (u2_mb_y > ps_dec->u2_frm_ht_in_mbs - 1)) |
1373 | 0 | { |
1374 | 0 | return ERROR_CORRUPTED_SLICE; |
1375 | 0 | } |
1376 | | |
1377 | 211 | u4_frame_stride = ps_dec->u2_frm_wd_y << u1_field_pic; |
1378 | 211 | x_offset = u2_mb_x << 4; |
1379 | 211 | y_offset = (u2_mb_y * u4_frame_stride) << 4; |
1380 | | |
1381 | 211 | ps_trns_addr->pu1_dest_y = ps_dec->s_cur_pic.pu1_buf1 + x_offset + y_offset; |
1382 | | |
1383 | 211 | u4_frame_stride = ps_dec->u2_frm_wd_uv << u1_field_pic; |
1384 | 211 | x_offset >>= 1; |
1385 | 211 | y_offset = (u2_mb_y * u4_frame_stride) << 3; |
1386 | | |
1387 | 211 | x_offset *= YUV420SP_FACTOR; |
1388 | | |
1389 | 211 | ps_trns_addr->pu1_dest_u = ps_dec->s_cur_pic.pu1_buf2 + x_offset + y_offset; |
1390 | 211 | ps_trns_addr->pu1_dest_v = ps_dec->s_cur_pic.pu1_buf3 + x_offset + y_offset; |
1391 | | |
1392 | 211 | ps_trns_addr->pu1_mb_y = ps_trns_addr->pu1_dest_y; |
1393 | 211 | ps_trns_addr->pu1_mb_u = ps_trns_addr->pu1_dest_u; |
1394 | 211 | ps_trns_addr->pu1_mb_v = ps_trns_addr->pu1_dest_v; |
1395 | | |
1396 | | // assign the deblock structure pointers to start of slice |
1397 | 211 | if(ps_dec->u1_separate_parse == 1) |
1398 | 99 | { |
1399 | 99 | ps_dec->ps_deblk_mbn = |
1400 | 99 | ps_dec->ps_deblk_pic + (u2_first_mb_in_slice << u1_mb_aff); |
1401 | 99 | } |
1402 | 112 | else |
1403 | 112 | { |
1404 | 112 | ps_dec->ps_deblk_mbn = |
1405 | 112 | ps_dec->ps_deblk_pic + (u2_first_mb_in_slice << u1_mb_aff); |
1406 | 112 | } |
1407 | | |
1408 | 211 | ps_dec->u4_cur_mb_addr = (u2_first_mb_in_slice << u1_mb_aff); |
1409 | | |
1410 | 211 | ps_dec->ps_mv_cur = |
1411 | 211 | ps_dec->s_cur_pic.ps_mv + ((u2_first_mb_in_slice << u1_mb_aff) << 4); |
1412 | 211 | } |
1413 | 211 | } |
1414 | 36.1k | else |
1415 | 36.1k | { |
1416 | 36.1k | tfr_ctxt_t *ps_trns_addr; |
1417 | | |
1418 | 36.1k | if(ps_dec->u1_separate_parse) |
1419 | 20.6k | { |
1420 | 20.6k | ps_trns_addr = &ps_dec->s_tran_addrecon_parse; |
1421 | 20.6k | } |
1422 | 15.5k | else |
1423 | 15.5k | { |
1424 | 15.5k | ps_trns_addr = &ps_dec->s_tran_addrecon; |
1425 | 15.5k | } |
1426 | | |
1427 | 36.1k | u2_mb_x = 0xffff; |
1428 | 36.1k | u2_mb_y = 0; |
1429 | | // assign the deblock structure pointers to start of slice |
1430 | 36.1k | ps_dec->u4_cur_mb_addr = 0; |
1431 | 36.1k | ps_dec->ps_deblk_mbn = ps_dec->ps_deblk_pic; |
1432 | 36.1k | ps_dec->ps_mv_cur = ps_dec->s_cur_pic.ps_mv; |
1433 | 36.1k | ps_trns_addr->pu1_dest_y = ps_dec->s_cur_pic.pu1_buf1; |
1434 | 36.1k | ps_trns_addr->pu1_dest_u = ps_dec->s_cur_pic.pu1_buf2; |
1435 | 36.1k | ps_trns_addr->pu1_dest_v = ps_dec->s_cur_pic.pu1_buf3; |
1436 | | |
1437 | 36.1k | ps_trns_addr->pu1_mb_y = ps_trns_addr->pu1_dest_y; |
1438 | 36.1k | ps_trns_addr->pu1_mb_u = ps_trns_addr->pu1_dest_u; |
1439 | 36.1k | ps_trns_addr->pu1_mb_v = ps_trns_addr->pu1_dest_v; |
1440 | 36.1k | } |
1441 | | |
1442 | 36.4k | ps_dec->ps_part = ps_dec->ps_parse_part_params; |
1443 | | |
1444 | 36.4k | ps_dec->u2_mbx = (MOD(u2_first_mb_in_slice - 1, ps_seq->u2_frm_wd_in_mbs)); |
1445 | 36.4k | ps_dec->u2_mby = (DIV(u2_first_mb_in_slice - 1, ps_seq->u2_frm_wd_in_mbs)); |
1446 | 36.4k | ps_dec->u2_mby <<= ps_cur_slice->u1_mbaff_frame_flag; |
1447 | 36.4k | ps_dec->i2_prev_slice_mbx = ps_dec->u2_mbx; |
1448 | 36.4k | ps_dec->i2_prev_slice_mby = ps_dec->u2_mby; |
1449 | 36.4k | } |
1450 | | |
1451 | | /* RBSP stop bit is used for CABAC decoding*/ |
1452 | 0 | ps_bitstrm->u4_max_ofst += ps_dec->ps_cur_pps->u1_entropy_coding_mode; |
1453 | | |
1454 | 36.4k | ps_dec->u1_B = (u1_slice_type == B_SLICE); |
1455 | 36.4k | ps_dec->u4_next_mb_skip = 0; |
1456 | | |
1457 | 36.4k | ps_dec->ps_parse_cur_slice->u4_first_mb_in_slice = ps_dec->ps_cur_slice->u2_first_mb_in_slice; |
1458 | 36.4k | ps_dec->ps_parse_cur_slice->slice_type = ps_dec->ps_cur_slice->u1_slice_type; |
1459 | | |
1460 | 36.4k | ps_dec->u4_start_recon_deblk = 1; |
1461 | 36.4k | { |
1462 | 36.4k | WORD32 num_entries; |
1463 | 36.4k | WORD32 size; |
1464 | 36.4k | UWORD8 *pu1_buf; |
1465 | | |
1466 | 36.4k | num_entries = MAX_FRAMES; |
1467 | 36.4k | if((1 >= ps_dec->ps_cur_sps->u1_num_ref_frames) && (0 == ps_dec->i4_display_delay)) |
1468 | 0 | { |
1469 | 0 | num_entries = 1; |
1470 | 0 | } |
1471 | 36.4k | num_entries = ((2 * num_entries) + 1); |
1472 | 36.4k | num_entries *= 2; |
1473 | | |
1474 | 36.4k | size = num_entries * sizeof(void *); |
1475 | 36.4k | size += PAD_MAP_IDX_POC * sizeof(void *); |
1476 | | |
1477 | 36.4k | pu1_buf = (UWORD8 *) ps_dec->pv_map_ref_idx_to_poc_buf; |
1478 | 36.4k | pu1_buf += size * ps_dec->u2_cur_slice_num; |
1479 | 36.4k | ps_dec->ps_parse_cur_slice->ppv_map_ref_idx_to_poc = (void *) pu1_buf; |
1480 | 36.4k | } |
1481 | | |
1482 | 36.4k | if(ps_dec->u1_separate_parse) |
1483 | 20.7k | { |
1484 | 20.7k | ps_dec->ps_parse_cur_slice->pv_tu_coeff_data_start = ps_dec->pv_parse_tu_coeff_data; |
1485 | 20.7k | } |
1486 | 15.6k | else |
1487 | 15.6k | { |
1488 | 15.6k | ps_dec->pv_proc_tu_coeff_data = ps_dec->pv_parse_tu_coeff_data; |
1489 | 15.6k | } |
1490 | | |
1491 | 36.4k | ret = ih264d_fix_error_in_dpb(ps_dec); |
1492 | 36.4k | if(ret < 0) return ERROR_DBP_MANAGER_T; |
1493 | | |
1494 | | /*Default initializing default values for some parameters*/ |
1495 | 36.4k | ps_svc_slice_params->u1_slice_skip_flag = 0; |
1496 | 36.4k | ps_svc_slice_params->u1_adaptive_base_mode_flag = 0; |
1497 | 36.4k | ps_svc_slice_params->u1_default_base_mode_flag = 0; |
1498 | 36.4k | ps_svc_slice_params->u1_adaptive_motion_prediction_flag = 0; |
1499 | 36.4k | ps_svc_slice_params->u1_default_motion_prediction_flag = 0; |
1500 | 36.4k | ps_svc_slice_params->u1_adaptive_residual_prediction_flag = 0; |
1501 | 36.4k | ps_svc_slice_params->u1_default_residual_prediction_flag = 0; |
1502 | | |
1503 | 36.4k | if(u1_slice_type == I_SLICE) |
1504 | 6.65k | { |
1505 | 6.65k | ps_dec->ps_cur_pic->u4_pack_slc_typ |= I_SLC_BIT; |
1506 | | |
1507 | 6.65k | ret = isvcd_parse_eislice(ps_svc_lyr_dec, u2_first_mb_in_slice); |
1508 | 6.65k | ps_dec->u1_pr_sl_type = u1_slice_type; |
1509 | 6.65k | if(ps_dec->i4_pic_type != B_SLICE && ps_dec->i4_pic_type != P_SLICE) |
1510 | 6.65k | ps_dec->i4_pic_type = I_SLICE; |
1511 | 6.65k | } |
1512 | 29.7k | else if(u1_slice_type == P_SLICE) |
1513 | 15.4k | { |
1514 | 15.4k | ps_dec->ps_cur_pic->u4_pack_slc_typ |= P_SLC_BIT; |
1515 | 15.4k | ret = isvcd_parse_epslice(ps_svc_lyr_dec, u2_first_mb_in_slice); |
1516 | 15.4k | ps_dec->u1_pr_sl_type = u1_slice_type; |
1517 | 15.4k | if(ps_dec->i4_pic_type != B_SLICE) ps_dec->i4_pic_type = P_SLICE; |
1518 | 15.4k | } |
1519 | 14.2k | else if(u1_slice_type == B_SLICE) |
1520 | 14.2k | { |
1521 | 14.2k | ps_dec->ps_cur_pic->u4_pack_slc_typ |= B_SLC_BIT; |
1522 | 14.2k | ret = isvcd_parse_ebslice(ps_svc_lyr_dec, u2_first_mb_in_slice); |
1523 | 14.2k | ps_dec->u1_pr_sl_type = u1_slice_type; |
1524 | 14.2k | ps_dec->i4_pic_type = B_SLICE; |
1525 | 14.2k | } |
1526 | 66 | else |
1527 | 66 | return ERROR_INV_SLC_TYPE_T; |
1528 | | |
1529 | 36.3k | if(ps_dec->u1_slice_header_done) |
1530 | 26.1k | { |
1531 | | /* set to zero to indicate a valid slice has been decoded */ |
1532 | 26.1k | ps_dec->u1_first_slice_in_stream = 0; |
1533 | 26.1k | } |
1534 | | |
1535 | 36.3k | if(ret != OK) return ret; |
1536 | | |
1537 | 11.6k | if(u1_nal_ref_idc != 0) |
1538 | 10.6k | { |
1539 | 10.6k | if(!ps_dec->ps_dpb_cmds->u1_dpb_commands_read) |
1540 | 10.5k | { |
1541 | 10.5k | memcpy((void *) ps_dec->ps_dpb_cmds, (void *) (&(ps_dec->s_dpb_cmds_scratch)), |
1542 | 10.5k | sizeof(dpb_commands_t)); |
1543 | 10.5k | } |
1544 | 10.6k | } |
1545 | | |
1546 | | /* storing last Mb X and MbY of the slice */ |
1547 | 11.6k | ps_dec->i2_prev_slice_mbx = ps_dec->u2_mbx; |
1548 | 11.6k | ps_dec->i2_prev_slice_mby = ps_dec->u2_mby; |
1549 | | |
1550 | | /* End of Picture detection */ |
1551 | 11.6k | if(ps_dec->u4_total_mbs_coded >= (ps_seq->u4_max_mb_addr + 1)) |
1552 | 7.93k | { |
1553 | 7.93k | ps_dec->u1_pic_decode_done = 1; |
1554 | 7.93k | } |
1555 | | |
1556 | 11.6k | { |
1557 | 11.6k | dec_err_status_t *ps_err = ps_dec->ps_dec_err_status; |
1558 | 11.6k | if((ps_err->u1_err_flag & REJECT_PB_PICS) && (ps_err->u1_cur_pic_type == PIC_TYPE_I)) |
1559 | 0 | { |
1560 | 0 | ps_err->u1_err_flag = ACCEPT_ALL_PICS; |
1561 | 0 | } |
1562 | 11.6k | } |
1563 | | |
1564 | 11.6k | PRINT_BIN_BIT_RATIO(ps_dec) |
1565 | | |
1566 | 11.6k | return ret; |
1567 | 36.3k | } |
1568 | | |
1569 | | /*! |
1570 | | ************************************************************************** |
1571 | | * \if Function name : isvcd_set_default_slice_header_ext \endif |
1572 | | * |
1573 | | * \brief |
1574 | | * sets the default values for the svc slice header attr |
1575 | | * |
1576 | | * \return |
1577 | | * 0 on Success and Error code otherwise |
1578 | | ************************************************************************** |
1579 | | */ |
1580 | | WORD32 isvcd_set_default_slice_header_ext(svc_dec_lyr_struct_t *ps_svc_lyr_dec) |
1581 | 28.9k | { |
1582 | 28.9k | dec_struct_t *ps_dec = &ps_svc_lyr_dec->s_dec; |
1583 | 28.9k | WORD32 i_status = OK; |
1584 | 28.9k | dec_pic_params_t *ps_pps = ps_dec->ps_cur_pps; |
1585 | 28.9k | dec_seq_params_t *ps_seq; |
1586 | 28.9k | dec_svc_seq_params_t *ps_subset_seq; |
1587 | 28.9k | dec_slice_svc_ext_params_t *ps_svc_slice_params = NULL; |
1588 | 28.9k | dec_subset_seq_params_t *ps_sps_svc_ext = NULL; |
1589 | 28.9k | ps_seq = ps_pps->ps_sps; |
1590 | 28.9k | ps_seq += MAX_NUM_SEQ_PARAMS; |
1591 | 28.9k | ps_subset_seq = |
1592 | 28.9k | &ps_svc_lyr_dec->ps_subset_sps[MAX_NUM_SEQ_PARAMS + ps_seq->u1_seq_parameter_set_id]; |
1593 | 28.9k | ps_sps_svc_ext = &ps_subset_seq->s_sps_svc_ext; |
1594 | 28.9k | ps_svc_slice_params = &ps_svc_lyr_dec->s_svc_slice_params; |
1595 | | |
1596 | 28.9k | if(0 == ps_svc_lyr_dec->ps_nal_svc_ext->u1_quality_id) |
1597 | 28.9k | { |
1598 | 28.9k | ps_svc_slice_params->u1_ref_layer_chroma_phase_y_plus1 = |
1599 | 28.9k | ps_sps_svc_ext->u1_seq_ref_layer_chroma_phase_y_plus1; |
1600 | | |
1601 | 28.9k | ps_svc_slice_params->u1_ref_layer_chroma_phase_x_plus1_flag = |
1602 | 28.9k | ps_sps_svc_ext->u1_seq_ref_layer_chroma_phase_x_plus1_flag; |
1603 | 28.9k | } |
1604 | | |
1605 | 28.9k | ps_svc_slice_params->u4_ref_layer_dq_id = UINT32_MAX; |
1606 | 28.9k | ps_svc_slice_params->u4_disable_inter_layer_deblk_filter_idc = 0; |
1607 | 28.9k | ps_svc_slice_params->u1_scan_idx_start = 0; |
1608 | 28.9k | ps_svc_slice_params->u1_scan_idx_end = 15; |
1609 | 28.9k | ps_svc_slice_params->i4_inter_layer_slice_alpha_c0_offset_div2 = 0; |
1610 | 28.9k | ps_svc_slice_params->i4_inter_layer_slice_beta_offset_div2 = 0; |
1611 | 28.9k | ps_svc_slice_params->u1_constrained_intra_resampling_flag = 0; |
1612 | | |
1613 | 28.9k | return i_status; |
1614 | 28.9k | } |
1615 | | |
1616 | | /*! |
1617 | | ************************************************************************** |
1618 | | * \if Function name : isvcd_parse_slice_header \endif |
1619 | | * |
1620 | | * \brief |
1621 | | * parses the svc slice header attr |
1622 | | * |
1623 | | * \return |
1624 | | * 0 on Success and Error code otherwise |
1625 | | ************************************************************************** |
1626 | | */ |
1627 | | WORD32 isvcd_parse_slice_header(svc_dec_lyr_struct_t *ps_svc_lyr_dec) |
1628 | 28.9k | { |
1629 | 28.9k | dec_struct_t *ps_dec = &ps_svc_lyr_dec->s_dec; |
1630 | 28.9k | dec_pic_params_t *ps_pps = ps_dec->ps_cur_pps; |
1631 | 28.9k | dec_bit_stream_t *ps_bitstrm = ps_dec->ps_bitstrm; |
1632 | 28.9k | dec_seq_params_t *ps_seq; |
1633 | 28.9k | dec_svc_seq_params_t *ps_subset_seq; |
1634 | 28.9k | dec_slice_svc_ext_params_t *ps_svc_slice_params = NULL; |
1635 | 28.9k | dec_subset_seq_params_t *ps_sps_svc_ext = NULL; |
1636 | 28.9k | svc_dec_ctxt_t *ps_svcd_ctxt; |
1637 | 28.9k | UWORD32 *pu4_bitstrm_buf = ps_dec->ps_bitstrm->pu4_buffer; |
1638 | 28.9k | UWORD32 *pu4_bitstrm_ofst = &ps_dec->ps_bitstrm->u4_ofst; |
1639 | 28.9k | ps_svcd_ctxt = ps_svc_lyr_dec->ps_svcd_ctxt; |
1640 | 28.9k | ps_seq = ps_pps->ps_sps; |
1641 | 28.9k | ps_seq += MAX_NUM_SEQ_PARAMS; |
1642 | 28.9k | ps_subset_seq = |
1643 | 28.9k | &ps_svc_lyr_dec->ps_subset_sps[MAX_NUM_SEQ_PARAMS + ps_seq->u1_seq_parameter_set_id]; |
1644 | 28.9k | ps_sps_svc_ext = &ps_subset_seq->s_sps_svc_ext; |
1645 | 28.9k | ps_svc_slice_params = &ps_svc_lyr_dec->s_svc_slice_params; |
1646 | | |
1647 | 28.9k | if(!ps_svc_lyr_dec->ps_nal_svc_ext->u1_no_inter_layer_pred_flag && |
1648 | 28.9k | (0 == ps_svc_lyr_dec->ps_nal_svc_ext->u1_quality_id)) |
1649 | 28.9k | { |
1650 | 28.9k | ps_svc_slice_params->u4_ref_layer_dq_id = ih264d_uev(pu4_bitstrm_ofst, pu4_bitstrm_buf); |
1651 | 28.9k | COPYTHECONTEXT("Slice Header SVC ext: u4_ref_layer_dq_id", |
1652 | 28.9k | ps_svc_slice_params->u4_ref_layer_dq_id); |
1653 | 28.9k | if(ps_svc_slice_params->u4_ref_layer_dq_id > MAX_REF_DEP_ID) |
1654 | 851 | { |
1655 | 851 | return ERROR_INV_SLICE_HDR_T; |
1656 | 851 | } |
1657 | | /* Reference layer id update is taken care during resolution init */ |
1658 | | /* |
1659 | | ps_svc_lyr_dec->u1_ref_layer_id = ps_svc_slice_params->u4_ref_layer_dq_id >> 4; |
1660 | | if(ps_svc_lyr_dec->u1_ref_layer_id >= ps_svc_lyr_dec->u1_layer_id) |
1661 | | { |
1662 | | return ERROR_INV_SLICE_HDR_T; |
1663 | | } |
1664 | | */ |
1665 | 28.1k | ps_svc_lyr_dec->ps_dec_svc_ref_layer = |
1666 | 28.1k | &ps_svcd_ctxt->ps_svc_dec_lyr[ps_svc_lyr_dec->u1_ref_layer_id]; |
1667 | | |
1668 | 28.1k | if(ps_sps_svc_ext->u1_inter_layer_deblocking_filter_control_present_flag) |
1669 | 1.84k | { |
1670 | 1.84k | ps_svc_slice_params->u4_disable_inter_layer_deblk_filter_idc = |
1671 | 1.84k | ih264d_uev(pu4_bitstrm_ofst, pu4_bitstrm_buf); |
1672 | 1.84k | COPYTHECONTEXT("Slice Header SVC ext: u4_disable_inter_layer_deblk_filter_idc", |
1673 | 1.84k | ps_svc_slice_params->u4_disable_inter_layer_deblk_filter_idc); |
1674 | | |
1675 | 1.84k | if(ps_svc_slice_params->u4_disable_inter_layer_deblk_filter_idc > 6) |
1676 | 127 | { |
1677 | 127 | return ERROR_INV_SLICE_HDR_T; |
1678 | 127 | } |
1679 | | |
1680 | 1.71k | if(1 != ps_svc_slice_params->u4_disable_inter_layer_deblk_filter_idc) |
1681 | 1.42k | { |
1682 | 1.42k | ps_svc_slice_params->i4_inter_layer_slice_alpha_c0_offset_div2 = |
1683 | 1.42k | ih264d_sev(pu4_bitstrm_ofst, pu4_bitstrm_buf); |
1684 | 1.42k | COPYTHECONTEXT("Slice Header SVC ext: i4_inter_layer_slice_alpha_c0_offset_div2", |
1685 | 1.42k | ps_svc_slice_params->i4_inter_layer_slice_alpha_c0_offset_div2); |
1686 | | |
1687 | 1.42k | if(ps_svc_slice_params->i4_inter_layer_slice_alpha_c0_offset_div2 > 6 || |
1688 | 1.42k | ps_svc_slice_params->i4_inter_layer_slice_alpha_c0_offset_div2 < -6) |
1689 | 167 | { |
1690 | 167 | return ERROR_INV_SLICE_HDR_T; |
1691 | 167 | } |
1692 | | |
1693 | 1.25k | ps_svc_slice_params->i4_inter_layer_slice_beta_offset_div2 = |
1694 | 1.25k | ih264d_sev(pu4_bitstrm_ofst, pu4_bitstrm_buf); |
1695 | 1.25k | COPYTHECONTEXT("Slice Header SVC ext: i4_inter_layer_slice_beta_offset_div2", |
1696 | 1.25k | ps_svc_slice_params->i4_inter_layer_slice_beta_offset_div2); |
1697 | | |
1698 | 1.25k | if(ps_svc_slice_params->i4_inter_layer_slice_beta_offset_div2 > 6 || |
1699 | 1.25k | ps_svc_slice_params->i4_inter_layer_slice_beta_offset_div2 < -6) |
1700 | 174 | { |
1701 | 174 | return ERROR_INV_SLICE_HDR_T; |
1702 | 174 | } |
1703 | 1.25k | } |
1704 | 1.71k | } |
1705 | | |
1706 | 27.6k | ps_svc_slice_params->u1_constrained_intra_resampling_flag = ih264d_get_bit_h264(ps_bitstrm); |
1707 | 27.6k | COPYTHECONTEXT("Slice Header SVC ext: u1_constrained_intra_resampling_flag", |
1708 | 27.6k | ps_svc_slice_params->u1_constrained_intra_resampling_flag); |
1709 | | |
1710 | 27.6k | ps_svc_lyr_dec->s_res_prms.i1_constrained_intra_rsmpl_flag = |
1711 | 27.6k | ps_svc_lyr_dec->s_svc_slice_params.u1_constrained_intra_resampling_flag; |
1712 | 27.6k | isvcd_intra_resamp_res_init_update_flags(ps_svc_lyr_dec); |
1713 | | |
1714 | 27.6k | if(2 == ps_sps_svc_ext->u1_extended_spatial_scalability_idc) |
1715 | 0 | { |
1716 | | /* ChromaArrayType = i4_chroma_format_idc if separate_colour_plane_flag |
1717 | | * = 0 for all chroma format except 4:4:4 */ |
1718 | 0 | if(ps_dec->ps_cur_sps->i4_chroma_format_idc >= 0) |
1719 | 0 | { |
1720 | 0 | ps_svc_slice_params->u1_ref_layer_chroma_phase_x_plus1_flag = |
1721 | 0 | ih264d_get_bit_h264(ps_bitstrm); |
1722 | 0 | COPYTHECONTEXT("Slice Header SVC ext: u1_ref_layer_chroma_phase_x_plus1_flag", |
1723 | 0 | ps_svc_slice_params->u1_ref_layer_chroma_phase_x_plus1_flag); |
1724 | |
|
1725 | 0 | ps_svc_slice_params->u1_ref_layer_chroma_phase_y_plus1 = |
1726 | 0 | ih264d_get_bits_h264(ps_bitstrm, 2); |
1727 | 0 | COPYTHECONTEXT("Slice Header SVC ext: u1_ref_layer_chroma_phase_y_plus1", |
1728 | 0 | ps_svc_slice_params->u1_ref_layer_chroma_phase_y_plus1); |
1729 | |
|
1730 | 0 | if(ps_svc_slice_params->u1_ref_layer_chroma_phase_y_plus1 > 2) |
1731 | 0 | { |
1732 | 0 | return ERROR_INV_SLICE_HDR_T; |
1733 | 0 | } |
1734 | 0 | } |
1735 | 0 | else |
1736 | 0 | { |
1737 | 0 | if(0 == ps_svc_lyr_dec->ps_nal_svc_ext->u1_quality_id) |
1738 | 0 | { |
1739 | 0 | ps_svc_slice_params->u1_ref_layer_chroma_phase_y_plus1 = |
1740 | 0 | ps_sps_svc_ext->u1_seq_ref_layer_chroma_phase_y_plus1; |
1741 | 0 | } |
1742 | 0 | } |
1743 | | |
1744 | 0 | ps_svc_slice_params->i4_scaled_ref_layer_left_offset = |
1745 | 0 | ih264d_sev(pu4_bitstrm_ofst, pu4_bitstrm_buf); |
1746 | 0 | COPYTHECONTEXT("Slice Header SVC ext: i4_scaled_ref_layer_left_offset", |
1747 | 0 | ps_svc_slice_params->i4_scaled_ref_layer_left_offset); |
1748 | |
|
1749 | 0 | if(ps_svc_slice_params->i4_scaled_ref_layer_left_offset != 0) |
1750 | 0 | { |
1751 | 0 | return ERROR_INV_SLICE_HDR_T; |
1752 | 0 | } |
1753 | | |
1754 | 0 | if(ps_svc_slice_params->i4_scaled_ref_layer_left_offset >= MAX_SCLD_REF_LAYER_OFFSET || |
1755 | 0 | ps_svc_slice_params->i4_scaled_ref_layer_left_offset < MIN_SCLD_REF_LAYER_OFFSET) |
1756 | 0 | { |
1757 | 0 | return ERROR_INV_SLICE_HDR_T; |
1758 | 0 | } |
1759 | | |
1760 | 0 | ps_svc_slice_params->i4_scaled_ref_layer_top_offset = |
1761 | 0 | ih264d_sev(pu4_bitstrm_ofst, pu4_bitstrm_buf); |
1762 | 0 | COPYTHECONTEXT("Slice Header SVC ext: i4_scaled_ref_layer_top_offset", |
1763 | 0 | ps_svc_slice_params->i4_scaled_ref_layer_top_offset); |
1764 | |
|
1765 | 0 | if(ps_svc_slice_params->i4_scaled_ref_layer_top_offset != 0) |
1766 | 0 | { |
1767 | 0 | return ERROR_INV_SLICE_HDR_T; |
1768 | 0 | } |
1769 | | |
1770 | 0 | if(ps_svc_slice_params->i4_scaled_ref_layer_top_offset >= MAX_SCLD_REF_LAYER_OFFSET || |
1771 | 0 | ps_svc_slice_params->i4_scaled_ref_layer_top_offset < MIN_SCLD_REF_LAYER_OFFSET) |
1772 | 0 | { |
1773 | 0 | return ERROR_INV_SLICE_HDR_T; |
1774 | 0 | } |
1775 | | |
1776 | 0 | ps_svc_slice_params->i4_scaled_ref_layer_right_offset = |
1777 | 0 | ih264d_sev(pu4_bitstrm_ofst, pu4_bitstrm_buf); |
1778 | 0 | COPYTHECONTEXT("Slice Header SVC ext: i4_scaled_ref_layer_right_offset", |
1779 | 0 | ps_svc_slice_params->i4_scaled_ref_layer_right_offset); |
1780 | |
|
1781 | 0 | if(ps_svc_slice_params->i4_scaled_ref_layer_right_offset >= MAX_SCLD_REF_LAYER_OFFSET || |
1782 | 0 | ps_svc_slice_params->i4_scaled_ref_layer_right_offset < MIN_SCLD_REF_LAYER_OFFSET) |
1783 | 0 | { |
1784 | 0 | return ERROR_INV_SLICE_HDR_T; |
1785 | 0 | } |
1786 | | |
1787 | 0 | ps_svc_slice_params->i4_scaled_ref_layer_bottom_offset = |
1788 | 0 | ih264d_sev(pu4_bitstrm_ofst, pu4_bitstrm_buf); |
1789 | 0 | COPYTHECONTEXT("Slice Header SVC ext: i4_scaled_ref_layer_bottom_offset", |
1790 | 0 | ps_svc_slice_params->i4_scaled_ref_layer_bottom_offset); |
1791 | |
|
1792 | 0 | if(ps_svc_slice_params->i4_scaled_ref_layer_bottom_offset >= |
1793 | 0 | MAX_SCLD_REF_LAYER_OFFSET || |
1794 | 0 | ps_svc_slice_params->i4_scaled_ref_layer_bottom_offset < MIN_SCLD_REF_LAYER_OFFSET) |
1795 | 0 | { |
1796 | 0 | return ERROR_INV_SLICE_HDR_T; |
1797 | 0 | } |
1798 | 0 | } |
1799 | 27.6k | else |
1800 | 27.6k | { |
1801 | 27.6k | ps_svc_slice_params->i4_scaled_ref_layer_left_offset = |
1802 | 27.6k | ps_sps_svc_ext->i4_seq_scaled_ref_layer_left_offset; |
1803 | 27.6k | ps_svc_slice_params->i4_scaled_ref_layer_top_offset = |
1804 | 27.6k | ps_sps_svc_ext->i4_seq_scaled_ref_layer_top_offset; |
1805 | 27.6k | ps_svc_slice_params->i4_scaled_ref_layer_right_offset = |
1806 | 27.6k | ps_sps_svc_ext->i4_seq_scaled_ref_layer_right_offset; |
1807 | 27.6k | ps_svc_slice_params->i4_scaled_ref_layer_bottom_offset = |
1808 | 27.6k | ps_sps_svc_ext->i4_seq_scaled_ref_layer_bottom_offset; |
1809 | 27.6k | } |
1810 | 27.6k | } |
1811 | | |
1812 | 27.6k | if(!ps_svc_lyr_dec->ps_nal_svc_ext->u1_no_inter_layer_pred_flag) |
1813 | 27.6k | { |
1814 | 27.6k | ps_svc_slice_params->u1_slice_skip_flag = ih264d_get_bit_h264(ps_bitstrm); |
1815 | 27.6k | COPYTHECONTEXT("Slice Header SVC ext: u1_slice_skip_flag", |
1816 | 27.6k | ps_svc_slice_params->u1_slice_skip_flag); |
1817 | | |
1818 | 27.6k | if(ps_svc_slice_params->u1_slice_skip_flag) |
1819 | 1.16k | { |
1820 | 1.16k | ps_svc_slice_params->u4_num_mbs_in_slice_minus1 = |
1821 | 1.16k | ih264d_uev(pu4_bitstrm_ofst, pu4_bitstrm_buf); |
1822 | 1.16k | COPYTHECONTEXT("Slice Header SVC ext: u4_num_mbs_in_slice_minus1", |
1823 | 1.16k | ps_svc_slice_params->u4_num_mbs_in_slice_minus1); |
1824 | 1.16k | } |
1825 | 26.4k | else |
1826 | 26.4k | { |
1827 | 26.4k | ps_svc_slice_params->u1_adaptive_base_mode_flag = ih264d_get_bit_h264(ps_bitstrm); |
1828 | 26.4k | COPYTHECONTEXT("Slice Header SVC ext: u1_adaptive_base_mode_flag", |
1829 | 26.4k | ps_svc_slice_params->u1_adaptive_base_mode_flag); |
1830 | | |
1831 | 26.4k | if(!ps_svc_slice_params->u1_adaptive_base_mode_flag) |
1832 | 14.4k | { |
1833 | 14.4k | ps_svc_slice_params->u1_default_base_mode_flag = ih264d_get_bit_h264(ps_bitstrm); |
1834 | 14.4k | COPYTHECONTEXT("Slice Header SVC ext: u1_default_base_mode_flag", |
1835 | 14.4k | ps_svc_slice_params->u1_default_base_mode_flag); |
1836 | 14.4k | } |
1837 | 26.4k | if(!ps_svc_slice_params->u1_default_base_mode_flag) |
1838 | 20.7k | { |
1839 | 20.7k | ps_svc_slice_params->u1_adaptive_motion_prediction_flag = |
1840 | 20.7k | ih264d_get_bit_h264(ps_bitstrm); |
1841 | 20.7k | COPYTHECONTEXT("Slice Header SVC ext: u1_adaptive_motion_prediction_flag", |
1842 | 20.7k | ps_svc_slice_params->u1_adaptive_motion_prediction_flag); |
1843 | | |
1844 | 20.7k | if(!ps_svc_slice_params->u1_adaptive_motion_prediction_flag) |
1845 | 13.3k | { |
1846 | 13.3k | ps_svc_slice_params->u1_default_motion_prediction_flag = |
1847 | 13.3k | ih264d_get_bit_h264(ps_bitstrm); |
1848 | 13.3k | COPYTHECONTEXT("Slice Header SVC ext: u1_default_motion_prediction_flag", |
1849 | 13.3k | ps_svc_slice_params->u1_default_motion_prediction_flag); |
1850 | 13.3k | } |
1851 | 20.7k | } |
1852 | 26.4k | ps_svc_slice_params->u1_adaptive_residual_prediction_flag = |
1853 | 26.4k | ih264d_get_bit_h264(ps_bitstrm); |
1854 | 26.4k | COPYTHECONTEXT("Slice Header SVC ext: u1_adaptive_residual_prediction_flag", |
1855 | 26.4k | ps_svc_slice_params->u1_adaptive_residual_prediction_flag); |
1856 | | |
1857 | 26.4k | if(!ps_svc_slice_params->u1_adaptive_residual_prediction_flag) |
1858 | 19.6k | { |
1859 | 19.6k | ps_svc_slice_params->u1_default_residual_prediction_flag = |
1860 | 19.6k | ih264d_get_bit_h264(ps_bitstrm); |
1861 | 19.6k | COPYTHECONTEXT("Slice Header SVC ext: u1_default_residual_prediction_flag", |
1862 | 19.6k | ps_svc_slice_params->u1_default_residual_prediction_flag); |
1863 | 19.6k | } |
1864 | 26.4k | } |
1865 | | |
1866 | 27.6k | if(ps_sps_svc_ext->u1_adaptive_tcoeff_level_prediction_flag) |
1867 | 1.62k | { |
1868 | 1.62k | ps_svc_slice_params->u1_tcoeff_level_prediction_flag = ih264d_get_bit_h264(ps_bitstrm); |
1869 | 1.62k | COPYTHECONTEXT("Slice Header SVC ext: u1_tcoeff_level_prediction_flag", |
1870 | 1.62k | ps_svc_slice_params->u1_tcoeff_level_prediction_flag); |
1871 | | |
1872 | 1.62k | if(ps_svc_slice_params->u1_tcoeff_level_prediction_flag != 0) |
1873 | 167 | { |
1874 | 167 | return ERROR_INV_SPS_PPS_T; |
1875 | 167 | } |
1876 | 1.62k | } |
1877 | 27.6k | } |
1878 | | |
1879 | 27.4k | if(!ps_sps_svc_ext->u1_slice_header_restriction_flag && |
1880 | 27.4k | !ps_svc_slice_params->u1_slice_skip_flag) |
1881 | 21.1k | { |
1882 | 21.1k | ps_svc_slice_params->u1_scan_idx_start = ih264d_get_bits_h264(ps_bitstrm, 4); |
1883 | 21.1k | COPYTHECONTEXT("Slice Header SVC ext: u1_scan_idx_start", |
1884 | 21.1k | ps_svc_slice_params->u1_scan_idx_start); |
1885 | 21.1k | ps_svc_slice_params->u1_scan_idx_end = ih264d_get_bits_h264(ps_bitstrm, 4); |
1886 | 21.1k | COPYTHECONTEXT("Slice Header SVC ext: u1_scan_idx_end", |
1887 | 21.1k | ps_svc_slice_params->u1_scan_idx_end); |
1888 | | |
1889 | 21.1k | if(0 != ps_svc_slice_params->u1_scan_idx_start && |
1890 | 21.1k | 15 != ps_svc_slice_params->u1_scan_idx_end) |
1891 | 1.28k | return ERROR_SVC_INV_SCAN_IDX; |
1892 | 21.1k | } |
1893 | 26.1k | return OK; |
1894 | 27.4k | } |
1895 | | |
1896 | | /*! |
1897 | | ************************************************************************** |
1898 | | * \if Function name : DecodeSlice \endif |
1899 | | * |
1900 | | * \brief |
1901 | | * Parses a slice |
1902 | | * |
1903 | | * \return |
1904 | | * 0 on Success and Error code otherwise |
1905 | | ************************************************************************** |
1906 | | */ |
1907 | | |
1908 | | WORD32 isvcd_parse_decode_slice(UWORD8 u1_is_idr_slice, UWORD8 u1_nal_ref_idc, |
1909 | | svc_dec_lyr_struct_t *ps_svc_lyr_dec /* SVC Decoder parameters */ |
1910 | | ) |
1911 | 139k | { |
1912 | 139k | dec_struct_t *ps_dec = &ps_svc_lyr_dec->s_dec; |
1913 | 139k | dec_bit_stream_t *ps_bitstrm = ps_dec->ps_bitstrm; |
1914 | 139k | dec_pic_params_t *ps_pps; |
1915 | 139k | dec_seq_params_t *ps_seq; |
1916 | 139k | dec_svc_seq_params_t *ps_subset_seq; |
1917 | 139k | dec_slice_params_t *ps_cur_slice = ps_dec->ps_cur_slice; |
1918 | 139k | pocstruct_t s_tmp_poc = {0}; |
1919 | 139k | WORD32 i_delta_poc[2] = {0}; |
1920 | 139k | WORD32 i4_poc = 0; |
1921 | 139k | UWORD16 u2_first_mb_in_slice, u2_frame_num; |
1922 | 139k | UWORD8 u1_field_pic_flag, u1_redundant_pic_cnt = 0, u1_slice_type; |
1923 | 139k | UWORD32 u4_idr_pic_id = 0; |
1924 | 139k | UWORD8 u1_bottom_field_flag, u1_pic_order_cnt_type; |
1925 | 139k | UWORD8 u1_nal_unit_type; |
1926 | 139k | UWORD32 *pu4_bitstrm_buf = ps_bitstrm->pu4_buffer; |
1927 | 139k | UWORD32 *pu4_bitstrm_ofst = &ps_bitstrm->u4_ofst; |
1928 | 139k | WORD8 i1_is_end_of_poc; |
1929 | | |
1930 | 139k | WORD32 ret; |
1931 | 139k | WORD32 prev_slice_err, num_mb_skipped; |
1932 | 139k | UWORD8 u1_mbaff; |
1933 | 139k | pocstruct_t *ps_cur_poc; |
1934 | | |
1935 | 139k | UWORD32 u4_temp; |
1936 | 139k | WORD32 i_temp; |
1937 | 139k | svc_dec_ctxt_t *psvcd_dec_ctxt; |
1938 | 139k | dec_struct_t *ps_dec_cur_lyr_minus_1; |
1939 | 139k | svc_dec_lyr_struct_t *ps_svc_cur_lyr_dec_minus_1; |
1940 | | |
1941 | | /* read FirstMbInSlice and slice type*/ |
1942 | 139k | ps_dec->ps_dpb_cmds->u1_dpb_commands_read_slc = 0; |
1943 | 139k | u2_first_mb_in_slice = ih264d_uev(pu4_bitstrm_ofst, pu4_bitstrm_buf); |
1944 | 139k | if(u2_first_mb_in_slice > (ps_dec->u2_frm_ht_in_mbs * ps_dec->u2_frm_wd_in_mbs)) |
1945 | 15.6k | { |
1946 | 15.6k | return ERROR_CORRUPTED_SLICE; |
1947 | 15.6k | } |
1948 | | |
1949 | | /*we currently don not support ASO*/ |
1950 | 123k | if(((u2_first_mb_in_slice << ps_cur_slice->u1_mbaff_frame_flag) <= ps_dec->u4_cur_mb_addr) && |
1951 | 123k | (ps_dec->u4_first_slice_in_pic == 0)) |
1952 | 728 | { |
1953 | 728 | return ERROR_CORRUPTED_SLICE; |
1954 | 728 | } |
1955 | | |
1956 | 123k | if(ps_dec->u4_first_slice_in_pic == 1) |
1957 | 119k | { |
1958 | 119k | if(u2_first_mb_in_slice != 0) |
1959 | 3.93k | { |
1960 | 3.93k | return ERROR_CORRUPTED_SLICE; |
1961 | 3.93k | } |
1962 | 119k | } |
1963 | | |
1964 | 119k | COPYTHECONTEXT("SH: first_mb_in_slice", u2_first_mb_in_slice); |
1965 | | |
1966 | 119k | u4_temp = ih264d_uev(pu4_bitstrm_ofst, pu4_bitstrm_buf); |
1967 | 119k | if(u4_temp > 9) return ERROR_INV_SLC_TYPE_T; |
1968 | | |
1969 | 118k | u1_slice_type = u4_temp; |
1970 | 118k | COPYTHECONTEXT("SH: slice_type", (u1_slice_type)); |
1971 | | /* Find Out the Slice Type is 5 to 9 or not then Set the Flag */ |
1972 | | /* u1_sl_typ_5_9 = 1 .Which tells that all the slices in the Pic*/ |
1973 | | /* will be of same type of current */ |
1974 | 118k | if(u1_slice_type > 4) |
1975 | 4.98k | { |
1976 | 4.98k | u1_slice_type -= 5; |
1977 | 4.98k | } |
1978 | | |
1979 | 118k | u4_temp = ih264d_uev(pu4_bitstrm_ofst, pu4_bitstrm_buf); |
1980 | 118k | if(u4_temp & MASK_ERR_PIC_SET_ID) return ERROR_INV_SLICE_HDR_T; |
1981 | | /* discard slice if pic param is invalid */ |
1982 | 118k | COPYTHECONTEXT("SH: pic_parameter_set_id", u4_temp); |
1983 | 118k | ps_pps = &ps_dec->ps_pps[u4_temp]; |
1984 | 118k | if(FALSE == ps_pps->u1_is_valid) |
1985 | 4.16k | { |
1986 | 4.16k | return ERROR_INV_SLICE_HDR_T; |
1987 | 4.16k | } |
1988 | | /* slices in a layer should have same PPS id*/ |
1989 | 114k | if(UINT32_MAX == ps_svc_lyr_dec->u4_pps_id_for_layer) |
1990 | 110k | { |
1991 | 110k | ps_svc_lyr_dec->u4_pps_id_for_layer = u4_temp; |
1992 | 110k | } |
1993 | 3.74k | else if(u4_temp != ps_svc_lyr_dec->u4_pps_id_for_layer) |
1994 | 66 | { |
1995 | 66 | return ERROR_INV_SLICE_HDR_T; |
1996 | 66 | } |
1997 | 114k | ps_seq = ps_pps->ps_sps; |
1998 | 114k | ps_dec->ps_cur_sps = ps_seq; |
1999 | 114k | ps_subset_seq = &ps_svc_lyr_dec->ps_subset_sps[ps_seq->u1_seq_parameter_set_id]; |
2000 | 114k | ps_svc_lyr_dec->ps_cur_subset_sps = ps_subset_seq; |
2001 | 114k | if(!ps_seq) return ERROR_INV_SLICE_HDR_T; |
2002 | 114k | if(FALSE == ps_seq->u1_is_valid) return ERROR_INV_SLICE_HDR_T; |
2003 | 113k | if(ps_seq->u1_mb_aff_flag) return ERROR_INV_SLICE_HDR_T; |
2004 | 113k | if(ps_seq->u1_level_idc > H264_LEVEL_4_2) return ERROR_INV_SLICE_HDR_T; |
2005 | 113k | if(!ps_seq->u1_frame_mbs_only_flag) return ERROR_INV_SLICE_HDR_T; |
2006 | 112k | if(OK != isvcd_verify_level(ps_seq->u1_level_idc)) return ERROR_INV_SLICE_HDR_T; |
2007 | 112k | if(ps_dec->u1_init_dec_flag == 1) |
2008 | 90.1k | { |
2009 | 90.1k | if(ps_dec->u2_frm_wd_in_mbs != ps_seq->u2_frm_wd_in_mbs) return ERROR_INV_SLICE_HDR_T; |
2010 | 90.0k | if(ps_dec->u2_frm_ht_in_mbs != ps_seq->u2_frm_ht_in_mbs) return ERROR_INV_SLICE_HDR_T; |
2011 | 90.0k | } |
2012 | | |
2013 | 112k | if(ps_dec->u1_init_dec_flag == 1) |
2014 | 89.9k | { |
2015 | 89.9k | if(ps_dec->u2_disp_height != ps_subset_seq->u2_disp_height) return ERROR_INV_SLICE_HDR_T; |
2016 | 89.8k | if(ps_dec->u2_disp_width != ps_subset_seq->u2_disp_width) return ERROR_INV_SLICE_HDR_T; |
2017 | 89.8k | } |
2018 | | |
2019 | 112k | if(ps_seq->u1_profile_idc == BASE_PROFILE_IDC) |
2020 | 21.7k | { |
2021 | 21.7k | if(ps_pps->u1_entropy_coding_mode != 0) |
2022 | 69 | { |
2023 | 69 | return ERROR_INV_SPS_PPS_T; |
2024 | 69 | } |
2025 | 21.7k | } |
2026 | | |
2027 | 112k | ps_dec->i4_reorder_depth = ps_subset_seq->i4_reorder_depth; |
2028 | 112k | ps_dec->u2_disp_height = ps_subset_seq->u2_disp_height; |
2029 | 112k | ps_dec->u2_disp_width = ps_subset_seq->u2_disp_width; |
2030 | | |
2031 | 112k | if(ps_svc_lyr_dec->u1_layer_id > 0) |
2032 | 0 | { |
2033 | 0 | psvcd_dec_ctxt = ps_svc_lyr_dec->ps_svcd_ctxt; |
2034 | 0 | ps_svc_cur_lyr_dec_minus_1 = |
2035 | 0 | &psvcd_dec_ctxt->ps_svc_dec_lyr[ps_svc_lyr_dec->u1_layer_id - 1]; |
2036 | |
|
2037 | 0 | ps_dec_cur_lyr_minus_1 = &ps_svc_cur_lyr_dec_minus_1->s_dec; |
2038 | |
|
2039 | 0 | if((ps_dec_cur_lyr_minus_1->u2_pic_wd > ps_subset_seq->u2_pic_wd) || |
2040 | 0 | (ps_dec_cur_lyr_minus_1->u2_pic_ht > ps_subset_seq->u2_pic_ht)) |
2041 | 0 | { |
2042 | 0 | return ERROR_CORRUPTED_SLICE; |
2043 | 0 | } |
2044 | 0 | } |
2045 | | |
2046 | 112k | ps_dec->u2_pic_wd = ps_subset_seq->u2_pic_wd; |
2047 | 112k | ps_dec->u2_pic_ht = ps_subset_seq->u2_pic_ht; |
2048 | 112k | ps_dec->u4_total_mbs = ps_seq->u4_total_num_of_mbs << (1 - ps_seq->u1_frame_mbs_only_flag); |
2049 | | |
2050 | | /* Determining the Width and Height of Frame from that of Picture */ |
2051 | 112k | ps_dec->u2_frm_wd_y = ps_subset_seq->u2_frm_wd_y; |
2052 | 112k | ps_dec->u2_frm_ht_y = ps_subset_seq->u2_frm_ht_y; |
2053 | | |
2054 | 112k | ps_dec->u2_frm_wd_uv = ps_subset_seq->u2_frm_wd_uv; |
2055 | 112k | ps_dec->u2_frm_ht_uv = ps_subset_seq->u2_frm_ht_uv; |
2056 | | |
2057 | 112k | ps_dec->s_pad_mgr.u1_pad_len_y_v = ps_subset_seq->u1_pad_len_y_v; |
2058 | 112k | ps_dec->s_pad_mgr.u1_pad_len_cr_v = ps_subset_seq->u1_pad_len_cr_v; |
2059 | 112k | ps_dec->u2_frm_wd_in_mbs = ps_seq->u2_frm_wd_in_mbs; |
2060 | 112k | ps_dec->u2_frm_ht_in_mbs = ps_seq->u2_frm_ht_in_mbs; |
2061 | | |
2062 | 112k | ps_dec->u2_crop_offset_y = ps_subset_seq->u2_crop_offset_y; |
2063 | 112k | ps_dec->u2_crop_offset_uv = ps_subset_seq->u2_crop_offset_uv; |
2064 | | |
2065 | | /* Get the frame num */ |
2066 | 112k | u2_frame_num = ih264d_get_bits_h264(ps_bitstrm, ps_seq->u1_bits_in_frm_num); |
2067 | 112k | COPYTHECONTEXT("SH: frame_num", u2_frame_num); |
2068 | | |
2069 | 112k | if(!ps_dec->u1_first_slice_in_stream && ps_dec->u4_first_slice_in_pic) |
2070 | 78.7k | { |
2071 | 78.7k | pocstruct_t *ps_prev_poc = &ps_dec->s_prev_pic_poc; |
2072 | 78.7k | pocstruct_t *ps_cur_poc = &ps_dec->s_cur_pic_poc; |
2073 | | |
2074 | 78.7k | ps_dec->u2_mbx = 0xffff; |
2075 | 78.7k | ps_dec->u2_mby = 0; |
2076 | | |
2077 | 78.7k | if((0 == u1_is_idr_slice) && ps_cur_slice->u1_nal_ref_idc) |
2078 | 10.0k | ps_dec->u2_prev_ref_frame_num = ps_cur_slice->u2_frame_num; |
2079 | | |
2080 | 78.7k | if(u1_is_idr_slice || ps_cur_slice->u1_mmco_equalto5) ps_dec->u2_prev_ref_frame_num = 0; |
2081 | | |
2082 | 78.7k | if(ps_dec->ps_cur_sps->u1_gaps_in_frame_num_value_allowed_flag) |
2083 | 0 | { |
2084 | 0 | isvcd_decode_gaps_in_frame_num(ps_dec, u2_frame_num); |
2085 | 0 | } |
2086 | | |
2087 | 78.7k | ps_prev_poc->i4_prev_frame_num_ofst = ps_cur_poc->i4_prev_frame_num_ofst; |
2088 | 78.7k | ps_prev_poc->u2_frame_num = ps_cur_poc->u2_frame_num; |
2089 | 78.7k | ps_prev_poc->u1_mmco_equalto5 = ps_cur_slice->u1_mmco_equalto5; |
2090 | 78.7k | if(ps_cur_slice->u1_nal_ref_idc) |
2091 | 69.7k | { |
2092 | 69.7k | ps_prev_poc->i4_pic_order_cnt_lsb = ps_cur_poc->i4_pic_order_cnt_lsb; |
2093 | 69.7k | ps_prev_poc->i4_pic_order_cnt_msb = ps_cur_poc->i4_pic_order_cnt_msb; |
2094 | 69.7k | ps_prev_poc->i4_delta_pic_order_cnt_bottom = ps_cur_poc->i4_delta_pic_order_cnt_bottom; |
2095 | 69.7k | ps_prev_poc->i4_delta_pic_order_cnt[0] = ps_cur_poc->i4_delta_pic_order_cnt[0]; |
2096 | 69.7k | ps_prev_poc->i4_delta_pic_order_cnt[1] = ps_cur_poc->i4_delta_pic_order_cnt[1]; |
2097 | 69.7k | ps_prev_poc->u1_bot_field = ps_cur_poc->u1_bot_field; |
2098 | 69.7k | } |
2099 | | |
2100 | 78.7k | ps_dec->u4_total_mbs_coded = 0; |
2101 | 78.7k | } |
2102 | | /* Get the field related flags */ |
2103 | 112k | if(!ps_seq->u1_frame_mbs_only_flag) |
2104 | 0 | { |
2105 | 0 | u1_field_pic_flag = ih264d_get_bit_h264(ps_bitstrm); |
2106 | 0 | COPYTHECONTEXT("SH: field_pic_flag", u1_field_pic_flag); |
2107 | 0 | u1_bottom_field_flag = 0; |
2108 | |
|
2109 | 0 | if(u1_field_pic_flag) |
2110 | 0 | { |
2111 | 0 | ps_dec->pu1_inv_scan = (UWORD8 *) gau1_ih264d_inv_scan_fld; |
2112 | 0 | u1_bottom_field_flag = ih264d_get_bit_h264(ps_bitstrm); |
2113 | 0 | COPYTHECONTEXT("SH: bottom_field_flag", u1_bottom_field_flag); |
2114 | 0 | } |
2115 | 0 | else |
2116 | 0 | { |
2117 | 0 | ps_dec->pu1_inv_scan = (UWORD8 *) gau1_ih264d_inv_scan; |
2118 | 0 | } |
2119 | 0 | } |
2120 | 112k | else |
2121 | 112k | { |
2122 | 112k | u1_field_pic_flag = 0; |
2123 | 112k | u1_bottom_field_flag = 0; |
2124 | | |
2125 | 112k | ps_dec->pu1_inv_scan = (UWORD8 *) gau1_ih264d_inv_scan; |
2126 | 112k | } |
2127 | | |
2128 | 112k | u1_nal_unit_type = SLICE_NAL; |
2129 | 112k | if(u1_is_idr_slice) |
2130 | 89.8k | { |
2131 | 89.8k | u1_nal_unit_type = IDR_SLICE_NAL; |
2132 | 89.8k | u4_idr_pic_id = ih264d_uev(pu4_bitstrm_ofst, pu4_bitstrm_buf); |
2133 | 89.8k | if(u4_idr_pic_id > 65535) return ERROR_INV_SLICE_HDR_T; |
2134 | 88.8k | COPYTHECONTEXT("SH: ", u4_idr_pic_id); |
2135 | 88.8k | } |
2136 | | |
2137 | | /* read delta pic order count information*/ |
2138 | 111k | i_delta_poc[0] = i_delta_poc[1] = 0; |
2139 | 111k | s_tmp_poc.i4_pic_order_cnt_lsb = 0; |
2140 | 111k | s_tmp_poc.i4_delta_pic_order_cnt_bottom = 0; |
2141 | 111k | u1_pic_order_cnt_type = ps_seq->u1_pic_order_cnt_type; |
2142 | 111k | if(u1_pic_order_cnt_type == 0) |
2143 | 81.7k | { |
2144 | 81.7k | i_temp = ih264d_get_bits_h264(ps_bitstrm, ps_seq->u1_log2_max_pic_order_cnt_lsb_minus); |
2145 | 81.7k | if(i_temp < 0 || i_temp >= ps_seq->i4_max_pic_order_cntLsb) return ERROR_INV_SLICE_HDR_T; |
2146 | 81.7k | s_tmp_poc.i4_pic_order_cnt_lsb = i_temp; |
2147 | 81.7k | COPYTHECONTEXT("SH: pic_order_cnt_lsb", s_tmp_poc.i4_pic_order_cnt_lsb); |
2148 | | |
2149 | 81.7k | if((ps_pps->u1_pic_order_present_flag == 1) && (!u1_field_pic_flag)) |
2150 | 32.6k | { |
2151 | 32.6k | s_tmp_poc.i4_delta_pic_order_cnt_bottom = ih264d_sev(pu4_bitstrm_ofst, pu4_bitstrm_buf); |
2152 | 32.6k | COPYTHECONTEXT("SH: delta_pic_order_cnt_bottom", |
2153 | 32.6k | s_tmp_poc.i4_delta_pic_order_cnt_bottom); |
2154 | 32.6k | } |
2155 | 81.7k | } |
2156 | | |
2157 | 111k | s_tmp_poc.i4_delta_pic_order_cnt[0] = 0; |
2158 | 111k | s_tmp_poc.i4_delta_pic_order_cnt[1] = 0; |
2159 | 111k | if(u1_pic_order_cnt_type == 1 && (!ps_seq->u1_delta_pic_order_always_zero_flag)) |
2160 | 25.2k | { |
2161 | 25.2k | s_tmp_poc.i4_delta_pic_order_cnt[0] = ih264d_sev(pu4_bitstrm_ofst, pu4_bitstrm_buf); |
2162 | 25.2k | COPYTHECONTEXT("SH: delta_pic_order_cnt[0]", s_tmp_poc.i4_delta_pic_order_cnt[0]); |
2163 | | |
2164 | 25.2k | if(ps_pps->u1_pic_order_present_flag && !u1_field_pic_flag) |
2165 | 22.2k | { |
2166 | 22.2k | s_tmp_poc.i4_delta_pic_order_cnt[1] = ih264d_sev(pu4_bitstrm_ofst, pu4_bitstrm_buf); |
2167 | 22.2k | COPYTHECONTEXT("SH: delta_pic_order_cnt[1]", s_tmp_poc.i4_delta_pic_order_cnt[1]); |
2168 | 22.2k | } |
2169 | 25.2k | } |
2170 | | |
2171 | 111k | if(ps_pps->u1_redundant_pic_cnt_present_flag) |
2172 | 33.9k | { |
2173 | 33.9k | u4_temp = ih264d_uev(pu4_bitstrm_ofst, pu4_bitstrm_buf); |
2174 | 33.9k | if(u4_temp > MAX_REDUNDANT_PIC_CNT) return ERROR_INV_SLICE_HDR_T; |
2175 | 33.0k | u1_redundant_pic_cnt = u4_temp; |
2176 | 33.0k | COPYTHECONTEXT("SH: redundant_pic_cnt", u1_redundant_pic_cnt); |
2177 | 33.0k | } |
2178 | | |
2179 | | /*--------------------------------------------------------------------*/ |
2180 | | /* Check if the slice is part of new picture */ |
2181 | | /*--------------------------------------------------------------------*/ |
2182 | | /* First slice of a picture is always considered as part of new picture */ |
2183 | 110k | i1_is_end_of_poc = 1; |
2184 | 110k | ps_dec->ps_dec_err_status->u1_err_flag &= MASK_REJECT_CUR_PIC; |
2185 | | |
2186 | 110k | if(ps_dec->u4_first_slice_in_pic == 0) |
2187 | 3.67k | { |
2188 | 3.67k | i1_is_end_of_poc = |
2189 | 3.67k | ih264d_is_end_of_pic(u2_frame_num, u1_nal_ref_idc, &s_tmp_poc, &ps_dec->s_cur_pic_poc, |
2190 | 3.67k | ps_cur_slice, u1_pic_order_cnt_type, u1_nal_unit_type, |
2191 | 3.67k | u4_idr_pic_id, u1_field_pic_flag, u1_bottom_field_flag); |
2192 | 3.67k | if(i1_is_end_of_poc) |
2193 | 372 | { |
2194 | 372 | ps_dec->u1_first_slice_in_stream = 0; |
2195 | 372 | return ERROR_INCOMPLETE_FRAME; |
2196 | 372 | } |
2197 | 3.67k | } |
2198 | | |
2199 | | /*--------------------------------------------------------------------*/ |
2200 | | /* Check for error in slice and parse the missing/corrupted MB's */ |
2201 | | /* as skip-MB's in an inserted P-slice */ |
2202 | | /*--------------------------------------------------------------------*/ |
2203 | 110k | u1_mbaff = ps_seq->u1_mb_aff_flag && (!u1_field_pic_flag); |
2204 | 110k | prev_slice_err = 0; |
2205 | | |
2206 | 110k | if(i1_is_end_of_poc || ps_dec->u1_first_slice_in_stream) |
2207 | 106k | { |
2208 | | /* If the current slice is not a field or frame number of the current |
2209 | | * slice doesn't match with previous slice, and decoder is expecting |
2210 | | * to decode a field i.e. ps_dec->u1_top_bottom_decoded is not 0 and |
2211 | | * is not (TOP_FIELD_ONLY | BOT_FIELD_ONLY), treat it as a dangling |
2212 | | * field */ |
2213 | 106k | if((u1_field_pic_flag == 0 || u2_frame_num != ps_dec->u2_prv_frame_num) && |
2214 | 106k | ps_dec->u1_top_bottom_decoded != 0 && |
2215 | 106k | ps_dec->u1_top_bottom_decoded != (TOP_FIELD_ONLY | BOT_FIELD_ONLY)) |
2216 | 0 | { |
2217 | 0 | ps_dec->u1_dangling_field = 1; |
2218 | 0 | if(ps_dec->u4_first_slice_in_pic) |
2219 | 0 | { |
2220 | | // first slice - dangling field |
2221 | 0 | prev_slice_err = 1; |
2222 | 0 | } |
2223 | 0 | else |
2224 | 0 | { |
2225 | | // last slice - dangling field |
2226 | 0 | prev_slice_err = 2; |
2227 | 0 | } |
2228 | |
|
2229 | 0 | if(ps_dec->u1_top_bottom_decoded == TOP_FIELD_ONLY) |
2230 | 0 | ps_cur_slice->u1_bottom_field_flag = 1; |
2231 | 0 | else |
2232 | 0 | ps_cur_slice->u1_bottom_field_flag = 0; |
2233 | |
|
2234 | 0 | num_mb_skipped = |
2235 | 0 | (ps_dec->u2_frm_ht_in_mbs * ps_dec->u2_frm_wd_in_mbs) - ps_dec->u4_total_mbs_coded; |
2236 | 0 | ps_cur_poc = &ps_dec->s_cur_pic_poc; |
2237 | |
|
2238 | 0 | u1_is_idr_slice = ps_cur_slice->u1_nal_unit_type == IDR_SLICE_NAL; |
2239 | 0 | } |
2240 | 106k | else if(ps_dec->u4_first_slice_in_pic) |
2241 | 106k | { |
2242 | 106k | if(u2_first_mb_in_slice > 0) |
2243 | 0 | { |
2244 | | /* first slice - missing/header corruption */ |
2245 | 0 | prev_slice_err = 1; |
2246 | 0 | num_mb_skipped = u2_first_mb_in_slice << u1_mbaff; |
2247 | 0 | ps_cur_poc = &s_tmp_poc; |
2248 | | |
2249 | | /* initializing slice parameters */ |
2250 | 0 | ps_cur_slice->u4_idr_pic_id = u4_idr_pic_id; |
2251 | 0 | ps_cur_slice->u1_field_pic_flag = u1_field_pic_flag; |
2252 | 0 | ps_cur_slice->u1_bottom_field_flag = u1_bottom_field_flag; |
2253 | 0 | ps_cur_slice->i4_pic_order_cnt_lsb = s_tmp_poc.i4_pic_order_cnt_lsb; |
2254 | 0 | ps_cur_slice->u1_nal_unit_type = u1_nal_unit_type; |
2255 | 0 | ps_cur_slice->u1_redundant_pic_cnt = u1_redundant_pic_cnt; |
2256 | 0 | ps_cur_slice->u1_nal_ref_idc = u1_nal_ref_idc; |
2257 | 0 | ps_cur_slice->u1_pic_order_cnt_type = u1_pic_order_cnt_type; |
2258 | 0 | ps_cur_slice->u1_mbaff_frame_flag = ps_seq->u1_mb_aff_flag && (!u1_field_pic_flag); |
2259 | 0 | } |
2260 | 106k | } |
2261 | 0 | else |
2262 | 0 | { |
2263 | | /* since i1_is_end_of_poc is set ,means new frame num is encountered. so |
2264 | | * conceal the current frame completely */ |
2265 | 0 | prev_slice_err = 2; |
2266 | 0 | num_mb_skipped = |
2267 | 0 | (ps_dec->u2_frm_ht_in_mbs * ps_dec->u2_frm_wd_in_mbs) - ps_dec->u4_total_mbs_coded; |
2268 | 0 | ps_cur_poc = &s_tmp_poc; |
2269 | 0 | } |
2270 | 106k | } |
2271 | 3.30k | else |
2272 | 3.30k | { |
2273 | 3.30k | if((u2_first_mb_in_slice << u1_mbaff) > ps_dec->u4_total_mbs_coded) |
2274 | 141 | { |
2275 | | // previous slice - missing/corruption |
2276 | 141 | prev_slice_err = 2; |
2277 | 141 | num_mb_skipped = (u2_first_mb_in_slice << u1_mbaff) - ps_dec->u4_total_mbs_coded; |
2278 | 141 | ps_cur_poc = &s_tmp_poc; |
2279 | 141 | } |
2280 | 3.16k | else if((u2_first_mb_in_slice << u1_mbaff) < ps_dec->u4_total_mbs_coded) |
2281 | 0 | { |
2282 | 0 | return ERROR_CORRUPTED_SLICE; |
2283 | 0 | } |
2284 | 3.30k | } |
2285 | 110k | if(prev_slice_err) |
2286 | 141 | { |
2287 | 141 | ret = isvcd_mark_err_slice_skip((svc_dec_lyr_struct_t *) ps_dec, num_mb_skipped, |
2288 | 141 | u1_is_idr_slice, u2_frame_num, ps_cur_poc, prev_slice_err); |
2289 | | |
2290 | 141 | if(ps_dec->u1_dangling_field == 1) |
2291 | 0 | { |
2292 | 0 | ps_dec->u1_second_field = 1 - ps_dec->u1_second_field; |
2293 | 0 | ps_dec->u1_first_slice_in_stream = 0; |
2294 | 0 | ps_dec->u1_top_bottom_decoded = TOP_FIELD_ONLY | BOT_FIELD_ONLY; |
2295 | 0 | return ERROR_DANGLING_FIELD_IN_PIC; |
2296 | 0 | } |
2297 | | |
2298 | 141 | if(prev_slice_err == 2) |
2299 | 141 | { |
2300 | 141 | ps_dec->u1_first_slice_in_stream = 0; |
2301 | 141 | return ERROR_INCOMPLETE_FRAME; |
2302 | 141 | } |
2303 | | |
2304 | 0 | if(ps_dec->u4_total_mbs_coded >= ps_dec->u2_frm_ht_in_mbs * ps_dec->u2_frm_wd_in_mbs) |
2305 | 0 | { |
2306 | | /* return if all MBs in frame are parsed*/ |
2307 | 0 | ps_dec->u1_first_slice_in_stream = 0; |
2308 | 0 | return ERROR_IN_LAST_SLICE_OF_PIC; |
2309 | 0 | } |
2310 | | |
2311 | 0 | if(ps_dec->ps_dec_err_status->u1_err_flag & REJECT_CUR_PIC) |
2312 | 0 | { |
2313 | 0 | ih264d_err_pic_dispbuf_mgr(ps_dec); |
2314 | 0 | return ERROR_NEW_FRAME_EXPECTED; |
2315 | 0 | } |
2316 | | |
2317 | 0 | if(ret != OK) return ret; |
2318 | | |
2319 | 0 | i1_is_end_of_poc = 0; |
2320 | 0 | } |
2321 | | |
2322 | 109k | if(u1_field_pic_flag) |
2323 | 0 | { |
2324 | 0 | ps_dec->u2_prv_frame_num = u2_frame_num; |
2325 | 0 | } |
2326 | | |
2327 | 109k | if(ps_cur_slice->u1_mmco_equalto5 && NULL != ps_dec->ps_cur_pic) |
2328 | 1.94k | { |
2329 | 1.94k | WORD32 i4_temp_poc; |
2330 | 1.94k | WORD32 i4_top_field_order_poc, i4_bot_field_order_poc; |
2331 | 1.94k | WORD64 i8_result; |
2332 | 1.94k | if(!ps_cur_slice->u1_field_pic_flag) |
2333 | 1.94k | { |
2334 | 1.94k | i4_top_field_order_poc = ps_dec->ps_cur_pic->i4_top_field_order_cnt; |
2335 | 1.94k | i4_bot_field_order_poc = ps_dec->ps_cur_pic->i4_bottom_field_order_cnt; |
2336 | 1.94k | i4_temp_poc = MIN(i4_top_field_order_poc, i4_bot_field_order_poc); |
2337 | 1.94k | } |
2338 | 0 | else if(!ps_cur_slice->u1_bottom_field_flag) |
2339 | 0 | i4_temp_poc = ps_dec->ps_cur_pic->i4_top_field_order_cnt; |
2340 | 0 | else |
2341 | 0 | i4_temp_poc = ps_dec->ps_cur_pic->i4_bottom_field_order_cnt; |
2342 | | |
2343 | 1.94k | i8_result = (WORD64) i4_temp_poc - ps_dec->ps_cur_pic->i4_top_field_order_cnt; |
2344 | 1.94k | if(IS_OUT_OF_RANGE_S32(i8_result)) |
2345 | 66 | { |
2346 | 66 | return ERROR_INV_POC; |
2347 | 66 | } |
2348 | 1.87k | ps_dec->ps_cur_pic->i4_top_field_order_cnt = (WORD32) i8_result; |
2349 | 1.87k | i8_result = (WORD64) i4_temp_poc - ps_dec->ps_cur_pic->i4_bottom_field_order_cnt; |
2350 | 1.87k | if(IS_OUT_OF_RANGE_S32(i8_result)) |
2351 | 35 | { |
2352 | 35 | return ERROR_INV_POC; |
2353 | 35 | } |
2354 | 1.84k | ps_dec->ps_cur_pic->i4_bottom_field_order_cnt = (WORD32) i8_result; |
2355 | 1.84k | ps_dec->ps_cur_pic->i4_poc = i4_temp_poc; |
2356 | 1.84k | ps_dec->ps_cur_pic->i4_avg_poc = i4_temp_poc; |
2357 | 1.84k | } |
2358 | 109k | if(ps_dec->u4_first_slice_in_pic) |
2359 | 106k | { |
2360 | 106k | ret = isvcd_decode_pic_order_cnt(u1_is_idr_slice, u2_frame_num, &ps_dec->s_prev_pic_poc, |
2361 | 106k | &s_tmp_poc, ps_cur_slice, ps_pps, u1_nal_ref_idc, |
2362 | 106k | u1_bottom_field_flag, u1_field_pic_flag, &i4_poc, ps_dec); |
2363 | 106k | if(ret != OK) return ret; |
2364 | | /* Display seq no calculations */ |
2365 | 105k | if(i4_poc >= ps_dec->i4_max_poc) ps_dec->i4_max_poc = i4_poc; |
2366 | | /* IDR Picture or POC wrap around */ |
2367 | 105k | if(i4_poc == 0) |
2368 | 20.3k | { |
2369 | 20.3k | WORD64 i8_temp; |
2370 | 20.3k | i8_temp = (WORD64) ps_dec->i4_prev_max_display_seq + ps_dec->i4_max_poc + |
2371 | 20.3k | ps_dec->u1_max_dec_frame_buffering + 1; |
2372 | | /*If i4_prev_max_display_seq overflows integer range, reset it */ |
2373 | 20.3k | ps_dec->i4_prev_max_display_seq = IS_OUT_OF_RANGE_S32(i8_temp) ? 0 : i8_temp; |
2374 | 20.3k | ps_dec->i4_max_poc = 0; |
2375 | 20.3k | } |
2376 | 105k | } |
2377 | | |
2378 | | /* Increment only if the current slice has atleast 1 more MB */ |
2379 | 108k | if(ps_dec->u4_first_slice_in_pic == 0 && |
2380 | 108k | (ps_dec->ps_parse_cur_slice->u4_first_mb_in_slice < |
2381 | 3.16k | (UWORD32) (ps_dec->u4_total_mbs_coded >> ps_dec->ps_cur_slice->u1_mbaff_frame_flag))) |
2382 | 3.16k | { |
2383 | 3.16k | ps_dec->ps_parse_cur_slice++; |
2384 | 3.16k | ps_dec->u2_cur_slice_num++; |
2385 | | // in the case of single core increment ps_decode_cur_slice |
2386 | 3.16k | if(ps_dec->u1_separate_parse == 0) |
2387 | 1.33k | { |
2388 | 1.33k | ps_dec->ps_decode_cur_slice++; |
2389 | 1.33k | } |
2390 | 3.16k | } |
2391 | | |
2392 | 108k | ps_dec->u1_slice_header_done = 0; |
2393 | | |
2394 | | /*--------------------------------------------------------------------*/ |
2395 | | /* Copy the values read from the bitstream to the slice header and then*/ |
2396 | | /* If the slice is first slice in picture, then do Start of Picture */ |
2397 | | /* processing. */ |
2398 | | /*--------------------------------------------------------------------*/ |
2399 | 108k | ps_cur_slice->i4_delta_pic_order_cnt[0] = i_delta_poc[0]; |
2400 | 108k | ps_cur_slice->i4_delta_pic_order_cnt[1] = i_delta_poc[1]; |
2401 | 108k | ps_cur_slice->u4_idr_pic_id = u4_idr_pic_id; |
2402 | 108k | ps_cur_slice->u2_first_mb_in_slice = u2_first_mb_in_slice; |
2403 | 108k | ps_cur_slice->u1_field_pic_flag = u1_field_pic_flag; |
2404 | 108k | ps_cur_slice->u1_bottom_field_flag = u1_bottom_field_flag; |
2405 | 108k | ps_cur_slice->u1_slice_type = u1_slice_type; |
2406 | 108k | ps_cur_slice->i4_pic_order_cnt_lsb = s_tmp_poc.i4_pic_order_cnt_lsb; |
2407 | | |
2408 | 108k | ps_cur_slice->u1_nal_unit_type = u1_nal_unit_type; |
2409 | 108k | ps_cur_slice->u1_redundant_pic_cnt = u1_redundant_pic_cnt; |
2410 | 108k | ps_cur_slice->u1_nal_ref_idc = u1_nal_ref_idc; |
2411 | 108k | ps_cur_slice->u1_pic_order_cnt_type = u1_pic_order_cnt_type; |
2412 | | |
2413 | 108k | if(ps_seq->u1_frame_mbs_only_flag) |
2414 | 108k | ps_cur_slice->u1_direct_8x8_inference_flag = ps_seq->u1_direct_8x8_inference_flag; |
2415 | 0 | else |
2416 | 0 | ps_cur_slice->u1_direct_8x8_inference_flag = 1; |
2417 | | |
2418 | 108k | if(u1_slice_type == B_SLICE) |
2419 | 32.4k | { |
2420 | 32.4k | ps_cur_slice->u1_direct_spatial_mv_pred_flag = ih264d_get_bit_h264(ps_bitstrm); |
2421 | 32.4k | COPYTHECONTEXT("SH: direct_spatial_mv_pred_flag", |
2422 | 32.4k | ps_cur_slice->u1_direct_spatial_mv_pred_flag); |
2423 | | |
2424 | 32.4k | if(ps_cur_slice->u1_direct_spatial_mv_pred_flag) |
2425 | 16.0k | ps_cur_slice->pf_decodeDirect = ih264d_decode_spatial_direct; |
2426 | 16.3k | else |
2427 | 16.3k | ps_cur_slice->pf_decodeDirect = ih264d_decode_temporal_direct; |
2428 | 32.4k | if(!((ps_seq->u1_mb_aff_flag) && (!u1_field_pic_flag))) |
2429 | 32.4k | ps_dec->pf_mvpred = ih264d_mvpred_nonmbaffB; |
2430 | 32.4k | } |
2431 | 76.3k | else |
2432 | 76.3k | { |
2433 | 76.3k | if(!((ps_seq->u1_mb_aff_flag) && (!u1_field_pic_flag))) |
2434 | 76.3k | ps_dec->pf_mvpred = ih264d_mvpred_nonmbaff; |
2435 | 76.3k | } |
2436 | | |
2437 | 108k | if(ps_dec->u4_first_slice_in_pic) |
2438 | 105k | { |
2439 | 105k | if(u2_first_mb_in_slice == 0) |
2440 | 105k | { |
2441 | 105k | ret = isvcd_start_of_pic(ps_svc_lyr_dec, i4_poc, &s_tmp_poc, u2_frame_num, ps_pps); |
2442 | 105k | if(ret != OK) return ret; |
2443 | | /*inter layer buffer intialization */ |
2444 | 104k | ps_svc_lyr_dec->ps_inter_lyr_mb_prms_cur_mb = |
2445 | 104k | ps_svc_lyr_dec->ps_inter_lyr_mb_prms_frm_start; |
2446 | 104k | ps_svc_lyr_dec->ps_il_pred_mv_bank_buf_cur_mb = |
2447 | 104k | ps_svc_lyr_dec->ps_il_pred_mv_bank_buf_base; |
2448 | 104k | } |
2449 | | |
2450 | 104k | ps_dec->u4_output_present = 0; |
2451 | | |
2452 | 104k | { |
2453 | 104k | ih264d_get_next_display_field(ps_dec, ps_dec->ps_out_buffer, &(ps_dec->s_disp_op)); |
2454 | | /* If error code is non-zero then there is no buffer available for |
2455 | | display, hence avoid format conversion */ |
2456 | | |
2457 | 104k | if(0 != ps_dec->s_disp_op.u4_error_code) |
2458 | 45.1k | { |
2459 | 45.1k | ps_dec->u4_output_present = 0; |
2460 | 45.1k | ps_dec->u4_fmt_conv_cur_row = ps_dec->s_disp_frame_info.u4_y_ht; |
2461 | 45.1k | } |
2462 | 59.6k | else |
2463 | 59.6k | ps_dec->u4_output_present = 1; |
2464 | 104k | } |
2465 | 104k | ret = isvcd_parse_interlayer_resamp_func_init(ps_svc_lyr_dec, u2_first_mb_in_slice); |
2466 | 104k | if(ret != OK) |
2467 | 0 | { |
2468 | 0 | return ERROR_CORRUPTED_SLICE; |
2469 | 0 | } |
2470 | 104k | if((ps_dec->u1_separate_parse == 1) && (ps_svc_lyr_dec->u1_res_init_done == 1)) |
2471 | 30.5k | { |
2472 | 30.5k | if(ps_dec->u4_dec_thread_created == 0) |
2473 | 30.5k | { |
2474 | 30.5k | if(ps_svc_lyr_dec->u1_layer_identifier != TARGET_LAYER) |
2475 | 0 | { |
2476 | 0 | ithread_create(ps_dec->pv_dec_thread_handle, NULL, |
2477 | 0 | (void *) isvcd_decode_picture_thread, (void *) ps_dec); |
2478 | |
|
2479 | 0 | ps_dec->u4_dec_thread_created = 1; |
2480 | 0 | } |
2481 | 30.5k | else |
2482 | 30.5k | { |
2483 | 30.5k | ithread_create(ps_dec->pv_dec_thread_handle, NULL, |
2484 | 30.5k | (void *) ih264d_decode_picture_thread, (void *) ps_dec); |
2485 | | |
2486 | 30.5k | ps_dec->u4_dec_thread_created = 1; |
2487 | 30.5k | } |
2488 | 30.5k | } |
2489 | | #ifdef KEEP_THREADS_ACTIVE |
2490 | | ret = ithread_mutex_lock(ps_dec->apv_proc_start_mutex[0]); |
2491 | | RETURN_IF((ret != IV_SUCCESS), ret); |
2492 | | |
2493 | | ps_dec->ai4_process_start[0] = PROC_START; |
2494 | | ret = ithread_cond_signal(ps_dec->apv_proc_start_condition[0]); |
2495 | | RETURN_IF((ret != IV_SUCCESS), ret); |
2496 | | |
2497 | | ret = ithread_mutex_unlock(ps_dec->apv_proc_start_mutex[0]); |
2498 | | RETURN_IF((ret != IV_SUCCESS), ret); |
2499 | | #endif |
2500 | | #ifdef KEEP_THREADS_ACTIVE |
2501 | | if(ps_dec->u4_bs_deblk_thread_created) |
2502 | | { |
2503 | | ret = ithread_mutex_lock(ps_dec->apv_proc_start_mutex[1]); |
2504 | | RETURN_IF((ret != IV_SUCCESS), ret); |
2505 | | |
2506 | | ps_dec->ai4_process_start[1] = PROC_START; |
2507 | | ret = ithread_cond_signal(ps_dec->apv_proc_start_condition[1]); |
2508 | | RETURN_IF((ret != IV_SUCCESS), ret); |
2509 | | |
2510 | | ret = ithread_mutex_unlock(ps_dec->apv_proc_start_mutex[1]); |
2511 | | RETURN_IF((ret != IV_SUCCESS), ret); |
2512 | | } |
2513 | | #endif |
2514 | 30.5k | } |
2515 | 104k | } |
2516 | | |
2517 | | /* INITIALIZATION of fn ptrs for MC and formMbPartInfo functions */ |
2518 | 108k | { |
2519 | 108k | UWORD8 uc_nofield_nombaff; |
2520 | | |
2521 | 108k | uc_nofield_nombaff = |
2522 | 108k | ((ps_dec->ps_cur_slice->u1_field_pic_flag == 0) && |
2523 | 108k | (ps_dec->ps_cur_slice->u1_mbaff_frame_flag == 0) && (u1_slice_type != B_SLICE) && |
2524 | 108k | (ps_dec->ps_cur_pps->u1_wted_pred_flag == 0)); |
2525 | | |
2526 | | /* Initialise MC and formMbPartInfo fn ptrs one time based on profile_idc */ |
2527 | | |
2528 | 108k | if(uc_nofield_nombaff) |
2529 | 52.6k | { |
2530 | 52.6k | ps_dec->p_form_mb_part_info = ih264d_form_mb_part_info_bp; |
2531 | 52.6k | ps_dec->p_motion_compensate = ih264d_motion_compensate_bp; |
2532 | 52.6k | } |
2533 | 55.3k | else |
2534 | 55.3k | { |
2535 | 55.3k | ps_dec->p_form_mb_part_info = ih264d_form_mb_part_info_mp; |
2536 | 55.3k | ps_dec->p_motion_compensate = ih264d_motion_compensate_mp; |
2537 | 55.3k | } |
2538 | 108k | } |
2539 | | |
2540 | | /* |
2541 | | * Decide whether to decode the current picture or not |
2542 | | */ |
2543 | 108k | { |
2544 | 108k | dec_err_status_t *ps_err = ps_dec->ps_dec_err_status; |
2545 | 108k | if(ps_err->u4_frm_sei_sync == u2_frame_num) |
2546 | 67 | { |
2547 | 67 | ps_err->u1_err_flag = ACCEPT_ALL_PICS; |
2548 | 67 | ps_err->u4_frm_sei_sync = SYNC_FRM_DEFAULT; |
2549 | 67 | } |
2550 | 108k | ps_err->u4_cur_frm = u2_frame_num; |
2551 | 108k | } |
2552 | | |
2553 | | /* Decision for decoding if the picture is to be skipped */ |
2554 | 108k | { |
2555 | 108k | WORD32 i4_skip_b_pic, i4_skip_p_pic; |
2556 | | |
2557 | 108k | i4_skip_b_pic = (ps_dec->u4_skip_frm_mask & B_SLC_BIT) && (B_SLICE == u1_slice_type) && |
2558 | 108k | (0 == u1_nal_ref_idc); |
2559 | | |
2560 | 108k | i4_skip_p_pic = (ps_dec->u4_skip_frm_mask & P_SLC_BIT) && (P_SLICE == u1_slice_type) && |
2561 | 108k | (0 == u1_nal_ref_idc); |
2562 | | |
2563 | | /**************************************************************/ |
2564 | | /* Skip the B picture if skip mask is set for B picture and */ |
2565 | | /* Current B picture is a non reference B picture or there is */ |
2566 | | /* no user for reference B picture */ |
2567 | | /**************************************************************/ |
2568 | 108k | if(i4_skip_b_pic) |
2569 | 0 | { |
2570 | 0 | ps_dec->ps_cur_pic->u4_pack_slc_typ |= B_SLC_BIT; |
2571 | | /* Don't decode the picture in SKIP-B mode if that picture is B */ |
2572 | | /* and also it is not to be used as a reference picture */ |
2573 | 0 | ps_dec->u1_last_pic_not_decoded = 1; |
2574 | |
|
2575 | 0 | return OK; |
2576 | 0 | } |
2577 | | /**************************************************************/ |
2578 | | /* Skip the P picture if skip mask is set for P picture and */ |
2579 | | /* Current P picture is a non reference P picture or there is */ |
2580 | | /* no user for reference P picture */ |
2581 | | /**************************************************************/ |
2582 | 108k | if(i4_skip_p_pic) |
2583 | 0 | { |
2584 | 0 | ps_dec->ps_cur_pic->u4_pack_slc_typ |= P_SLC_BIT; |
2585 | | /* Don't decode the picture in SKIP-P mode if that picture is P */ |
2586 | | /* and also it is not to be used as a reference picture */ |
2587 | 0 | ps_dec->u1_last_pic_not_decoded = 1; |
2588 | |
|
2589 | 0 | return OK; |
2590 | 0 | } |
2591 | 108k | } |
2592 | | |
2593 | 108k | { |
2594 | 108k | UWORD16 u2_mb_x, u2_mb_y; |
2595 | | |
2596 | 108k | ps_dec->i4_submb_ofst = |
2597 | 108k | ((u2_first_mb_in_slice << ps_cur_slice->u1_mbaff_frame_flag) * SUB_BLK_SIZE) - |
2598 | 108k | SUB_BLK_SIZE; |
2599 | 108k | if(u2_first_mb_in_slice) |
2600 | 3.16k | { |
2601 | 3.16k | UWORD8 u1_mb_aff; |
2602 | 3.16k | UWORD8 u1_field_pic; |
2603 | 3.16k | UWORD16 u2_frm_wd_in_mbs; |
2604 | 3.16k | u2_frm_wd_in_mbs = ps_seq->u2_frm_wd_in_mbs; |
2605 | 3.16k | u1_mb_aff = ps_cur_slice->u1_mbaff_frame_flag; |
2606 | 3.16k | u1_field_pic = ps_cur_slice->u1_field_pic_flag; |
2607 | | |
2608 | 3.16k | { |
2609 | 3.16k | UWORD32 x_offset; |
2610 | 3.16k | UWORD32 y_offset; |
2611 | 3.16k | UWORD32 u4_frame_stride; |
2612 | 3.16k | tfr_ctxt_t *ps_trns_addr; |
2613 | | |
2614 | 3.16k | if(ps_dec->u1_separate_parse) |
2615 | 1.83k | { |
2616 | 1.83k | ps_trns_addr = &ps_dec->s_tran_addrecon_parse; |
2617 | 1.83k | } |
2618 | 1.33k | else |
2619 | 1.33k | { |
2620 | 1.33k | ps_trns_addr = &ps_dec->s_tran_addrecon; |
2621 | 1.33k | } |
2622 | 3.16k | u2_mb_x = MOD(u2_first_mb_in_slice, u2_frm_wd_in_mbs); |
2623 | 3.16k | u2_mb_y = DIV(u2_first_mb_in_slice, u2_frm_wd_in_mbs); |
2624 | | |
2625 | 3.16k | u2_mb_y <<= u1_mb_aff; |
2626 | | |
2627 | 3.16k | if((u2_mb_x > u2_frm_wd_in_mbs - 1) || (u2_mb_y > ps_dec->u2_frm_ht_in_mbs - 1)) |
2628 | 77 | { |
2629 | 77 | return ERROR_CORRUPTED_SLICE; |
2630 | 77 | } |
2631 | | |
2632 | 3.08k | u4_frame_stride = ps_dec->u2_frm_wd_y << u1_field_pic; |
2633 | 3.08k | x_offset = u2_mb_x << 4; |
2634 | 3.08k | y_offset = (u2_mb_y * u4_frame_stride) << 4; |
2635 | | |
2636 | 3.08k | ps_trns_addr->pu1_dest_y = ps_dec->s_cur_pic.pu1_buf1 + x_offset + y_offset; |
2637 | | |
2638 | 3.08k | u4_frame_stride = ps_dec->u2_frm_wd_uv << u1_field_pic; |
2639 | 3.08k | x_offset >>= 1; |
2640 | 3.08k | y_offset = (u2_mb_y * u4_frame_stride) << 3; |
2641 | | |
2642 | 3.08k | x_offset *= YUV420SP_FACTOR; |
2643 | | |
2644 | 3.08k | ps_trns_addr->pu1_dest_u = ps_dec->s_cur_pic.pu1_buf2 + x_offset + y_offset; |
2645 | 3.08k | ps_trns_addr->pu1_dest_v = ps_dec->s_cur_pic.pu1_buf3 + x_offset + y_offset; |
2646 | | |
2647 | 3.08k | ps_trns_addr->pu1_mb_y = ps_trns_addr->pu1_dest_y; |
2648 | 3.08k | ps_trns_addr->pu1_mb_u = ps_trns_addr->pu1_dest_u; |
2649 | 3.08k | ps_trns_addr->pu1_mb_v = ps_trns_addr->pu1_dest_v; |
2650 | | |
2651 | | /* assign the deblock structure pointers to start of slice */ |
2652 | 3.08k | if(ps_dec->u1_separate_parse == 1) |
2653 | 1.82k | { |
2654 | 1.82k | ps_dec->ps_deblk_mbn = |
2655 | 1.82k | ps_dec->ps_deblk_pic + (u2_first_mb_in_slice << u1_mb_aff); |
2656 | 1.82k | } |
2657 | 1.26k | else |
2658 | 1.26k | { |
2659 | 1.26k | ps_dec->ps_deblk_mbn = |
2660 | 1.26k | ps_dec->ps_deblk_pic + (u2_first_mb_in_slice << u1_mb_aff); |
2661 | 1.26k | } |
2662 | | |
2663 | 3.08k | ps_dec->u4_cur_mb_addr = (u2_first_mb_in_slice << u1_mb_aff); |
2664 | | |
2665 | 3.08k | ps_dec->ps_mv_cur = |
2666 | 3.08k | ps_dec->s_cur_pic.ps_mv + ((u2_first_mb_in_slice << u1_mb_aff) << 4); |
2667 | 3.08k | } |
2668 | 3.08k | } |
2669 | 104k | else |
2670 | 104k | { |
2671 | 104k | tfr_ctxt_t *ps_trns_addr; |
2672 | | |
2673 | 104k | if(ps_dec->u1_separate_parse) |
2674 | 30.5k | { |
2675 | 30.5k | ps_trns_addr = &ps_dec->s_tran_addrecon_parse; |
2676 | 30.5k | } |
2677 | 74.3k | else |
2678 | 74.3k | { |
2679 | 74.3k | ps_trns_addr = &ps_dec->s_tran_addrecon; |
2680 | 74.3k | } |
2681 | | |
2682 | 104k | u2_mb_x = 0xffff; |
2683 | 104k | u2_mb_y = 0; |
2684 | | // assign the deblock structure pointers to start of slice |
2685 | 104k | ps_dec->u4_cur_mb_addr = 0; |
2686 | 104k | ps_dec->ps_deblk_mbn = ps_dec->ps_deblk_pic; |
2687 | 104k | ps_dec->ps_mv_cur = ps_dec->s_cur_pic.ps_mv; |
2688 | 104k | ps_trns_addr->pu1_dest_y = ps_dec->s_cur_pic.pu1_buf1; |
2689 | 104k | ps_trns_addr->pu1_dest_u = ps_dec->s_cur_pic.pu1_buf2; |
2690 | 104k | ps_trns_addr->pu1_dest_v = ps_dec->s_cur_pic.pu1_buf3; |
2691 | | |
2692 | 104k | ps_trns_addr->pu1_mb_y = ps_trns_addr->pu1_dest_y; |
2693 | 104k | ps_trns_addr->pu1_mb_u = ps_trns_addr->pu1_dest_u; |
2694 | 104k | ps_trns_addr->pu1_mb_v = ps_trns_addr->pu1_dest_v; |
2695 | 104k | } |
2696 | | |
2697 | 107k | ps_dec->ps_part = ps_dec->ps_parse_part_params; |
2698 | | |
2699 | 107k | ps_dec->u2_mbx = (MOD(u2_first_mb_in_slice - 1, ps_seq->u2_frm_wd_in_mbs)); |
2700 | 107k | ps_dec->u2_mby = (DIV(u2_first_mb_in_slice - 1, ps_seq->u2_frm_wd_in_mbs)); |
2701 | 107k | ps_dec->u2_mby <<= ps_cur_slice->u1_mbaff_frame_flag; |
2702 | 107k | ps_dec->i2_prev_slice_mbx = (WORD16) ps_dec->u2_mbx; |
2703 | 107k | ps_dec->i2_prev_slice_mby = (WORD16) ps_dec->u2_mby; |
2704 | 107k | } |
2705 | | |
2706 | | /* RBSP stop bit is used for CABAC decoding*/ |
2707 | 0 | ps_bitstrm->u4_max_ofst += ps_dec->ps_cur_pps->u1_entropy_coding_mode; |
2708 | | |
2709 | 107k | ps_dec->u1_B = (u1_slice_type == B_SLICE); |
2710 | 107k | ps_dec->u4_next_mb_skip = 0; |
2711 | | |
2712 | 107k | ps_dec->ps_parse_cur_slice->u4_first_mb_in_slice = ps_dec->ps_cur_slice->u2_first_mb_in_slice; |
2713 | 107k | ps_dec->ps_parse_cur_slice->slice_type = ps_dec->ps_cur_slice->u1_slice_type; |
2714 | | |
2715 | 107k | ps_dec->u4_start_recon_deblk = 1; |
2716 | 107k | { |
2717 | 107k | WORD32 num_entries; |
2718 | 107k | WORD32 size; |
2719 | 107k | UWORD8 *pu1_buf; |
2720 | | |
2721 | 107k | num_entries = MAX_FRAMES; |
2722 | 107k | if((1 >= ps_dec->ps_cur_sps->u1_num_ref_frames) && (0 == ps_dec->i4_display_delay)) |
2723 | 0 | { |
2724 | 0 | num_entries = 1; |
2725 | 0 | } |
2726 | 107k | num_entries = ((2 * num_entries) + 1); |
2727 | 107k | num_entries *= 2; |
2728 | | |
2729 | 107k | size = num_entries * sizeof(void *); |
2730 | 107k | size += PAD_MAP_IDX_POC * sizeof(void *); |
2731 | | |
2732 | 107k | pu1_buf = (UWORD8 *) ps_dec->pv_map_ref_idx_to_poc_buf; |
2733 | 107k | pu1_buf += size * ps_dec->u2_cur_slice_num; |
2734 | 107k | ps_dec->ps_parse_cur_slice->ppv_map_ref_idx_to_poc = (void *) pu1_buf; |
2735 | 107k | } |
2736 | | |
2737 | 107k | if(ps_dec->u1_separate_parse) |
2738 | 32.3k | { |
2739 | 32.3k | ps_dec->ps_parse_cur_slice->pv_tu_coeff_data_start = ps_dec->pv_parse_tu_coeff_data; |
2740 | 32.3k | } |
2741 | 75.5k | else |
2742 | 75.5k | { |
2743 | 75.5k | ps_dec->pv_proc_tu_coeff_data = ps_dec->pv_parse_tu_coeff_data; |
2744 | 75.5k | } |
2745 | | |
2746 | 107k | ret = ih264d_fix_error_in_dpb(ps_dec); |
2747 | 107k | if(ret < 0) return ERROR_DBP_MANAGER_T; |
2748 | | |
2749 | 107k | if(u1_slice_type == I_SLICE) |
2750 | 7.49k | { |
2751 | 7.49k | ps_dec->ps_cur_pic->u4_pack_slc_typ |= I_SLC_BIT; |
2752 | | |
2753 | 7.49k | ret = isvcd_parse_islice(ps_svc_lyr_dec, u2_first_mb_in_slice); |
2754 | 7.49k | ps_dec->u1_pr_sl_type = u1_slice_type; |
2755 | 7.49k | if(ps_dec->i4_pic_type != B_SLICE && ps_dec->i4_pic_type != P_SLICE) |
2756 | 6.76k | ps_dec->i4_pic_type = I_SLICE; |
2757 | 7.49k | } |
2758 | 100k | else if(u1_slice_type == P_SLICE) |
2759 | 68.0k | { |
2760 | 68.0k | ps_dec->ps_cur_pic->u4_pack_slc_typ |= P_SLC_BIT; |
2761 | 68.0k | ret = isvcd_parse_pslice(ps_svc_lyr_dec, u2_first_mb_in_slice); |
2762 | 68.0k | ps_dec->u1_pr_sl_type = u1_slice_type; |
2763 | 68.0k | if(ps_dec->i4_pic_type != B_SLICE) ps_dec->i4_pic_type = P_SLICE; |
2764 | 68.0k | } |
2765 | 32.3k | else if(u1_slice_type == B_SLICE) |
2766 | 31.9k | { |
2767 | 31.9k | ps_dec->ps_cur_pic->u4_pack_slc_typ |= B_SLC_BIT; |
2768 | 31.9k | ret = isvcd_parse_bslice(ps_svc_lyr_dec, u2_first_mb_in_slice); |
2769 | 31.9k | ps_dec->u1_pr_sl_type = u1_slice_type; |
2770 | 31.9k | ps_dec->i4_pic_type = B_SLICE; |
2771 | 31.9k | } |
2772 | 399 | else |
2773 | 399 | return ERROR_INV_SLC_TYPE_T; |
2774 | | |
2775 | 107k | if(ps_dec->u1_slice_header_done) |
2776 | 85.0k | { |
2777 | | /* set to zero to indicate a valid slice has been decoded */ |
2778 | 85.0k | ps_dec->u1_first_slice_in_stream = 0; |
2779 | 85.0k | } |
2780 | | |
2781 | 107k | if(ret != OK) return ret; |
2782 | | |
2783 | 56.9k | if(u1_nal_ref_idc != 0) |
2784 | 51.1k | { |
2785 | 51.1k | if(!ps_dec->ps_dpb_cmds->u1_dpb_commands_read) |
2786 | 50.5k | { |
2787 | 50.5k | memcpy((void *) ps_dec->ps_dpb_cmds, (void *) (&(ps_dec->s_dpb_cmds_scratch)), |
2788 | 50.5k | sizeof(dpb_commands_t)); |
2789 | 50.5k | } |
2790 | 51.1k | } |
2791 | | |
2792 | | /* storing last Mb X and MbY of the slice */ |
2793 | 56.9k | ps_dec->i2_prev_slice_mbx = ps_dec->u2_mbx; |
2794 | 56.9k | ps_dec->i2_prev_slice_mby = ps_dec->u2_mby; |
2795 | | |
2796 | | /* End of Picture detection */ |
2797 | | |
2798 | 56.9k | if(ps_dec->u4_total_mbs_coded >= (ps_seq->u4_max_mb_addr + 1)) |
2799 | 28.4k | { |
2800 | 28.4k | ps_dec->u1_pic_decode_done = 1; |
2801 | 28.4k | } |
2802 | | |
2803 | 56.9k | { |
2804 | 56.9k | dec_err_status_t *ps_err = ps_dec->ps_dec_err_status; |
2805 | 56.9k | if((ps_err->u1_err_flag & REJECT_PB_PICS) && (ps_err->u1_cur_pic_type == PIC_TYPE_I)) |
2806 | 0 | { |
2807 | 0 | ps_err->u1_err_flag = ACCEPT_ALL_PICS; |
2808 | 0 | } |
2809 | 56.9k | } |
2810 | | |
2811 | 56.9k | PRINT_BIN_BIT_RATIO(ps_dec) |
2812 | | |
2813 | 56.9k | return ret; |
2814 | 107k | } |