/src/libavc/decoder/svc/isvcd_utils.c
Line | Count | Source |
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_utils.c |
24 | | * |
25 | | * @brief |
26 | | * Contains routines that handle of start and end of pic processing |
27 | | * |
28 | | * @author |
29 | | * Kishore |
30 | | * |
31 | | * @remarks |
32 | | * None |
33 | | * |
34 | | ******************************************************************************* |
35 | | */ |
36 | | |
37 | | #include <string.h> |
38 | | #include "ih264_typedefs.h" |
39 | | #include "ithread.h" |
40 | | #include "ih264d_deblocking.h" |
41 | | #include "ih264d_parse_slice.h" |
42 | | #include "ih264d_parse_cavlc.h" |
43 | | #include "ih264d_dpb_manager.h" |
44 | | #include "ih264d_defs.h" |
45 | | #include "isvcd_structs.h" |
46 | | #include "ih264d_mem_request.h" |
47 | | #include "ih264_typedefs.h" |
48 | | #include "ih264_macros.h" |
49 | | #include "ih264_platform_macros.h" |
50 | | #include "ih264d_tables.h" |
51 | | #include "ih264d_debug.h" |
52 | | #include "ih264d_mb_utils.h" |
53 | | #include "ih264d_error_handler.h" |
54 | | #include "ih264d_dpb_manager.h" |
55 | | #include "ih264d_utils.h" |
56 | | #include "ih264d_defs.h" |
57 | | #include "ih264d_tables.h" |
58 | | #include "ih264d_inter_pred.h" |
59 | | #include "ih264d_dpb_manager.h" |
60 | | #include "iv.h" |
61 | | #include "ivd.h" |
62 | | #include "ih264d_format_conv.h" |
63 | | #include "ih264_error.h" |
64 | | #include "ih264_disp_mgr.h" |
65 | | #include "ih264_buf_mgr.h" |
66 | | #include "ih264d_utils.h" |
67 | | |
68 | | WORD32 ih264d_init_dec_mb_grp(dec_struct_t *ps_dec); |
69 | | /*! |
70 | | ************************************************************************** |
71 | | * \if Function name : isvcd_free_dynamic_bufs \endif |
72 | | * |
73 | | * \brief |
74 | | * This function frees dynamic memory allocated by Decoder. |
75 | | * |
76 | | * \param ps_dec: Pointer to dec_struct_t. |
77 | | * |
78 | | * \return |
79 | | * Returns i4_status as returned by MemManager. |
80 | | * |
81 | | ************************************************************************** |
82 | | */ |
83 | | WORD16 isvcd_free_dynamic_bufs(svc_dec_lyr_struct_t *ps_svc_lyr_dec) |
84 | 141k | { |
85 | 141k | WORD32 i; |
86 | 141k | dec_struct_t *ps_dec = &ps_svc_lyr_dec->s_dec; |
87 | | /* Free any avc dynamic buffers that are allocated */ |
88 | 141k | ih264d_free_dynamic_bufs(ps_dec); |
89 | 141k | PS_DEC_ALIGNED_FREE(ps_dec, ps_svc_lyr_dec->pu1_crop_wnd_flag); |
90 | 141k | PS_DEC_ALIGNED_FREE(ps_dec, ps_svc_lyr_dec->ps_inter_lyr_mb_prms_base); |
91 | 141k | PS_DEC_ALIGNED_FREE(ps_dec, ps_svc_lyr_dec->ps_il_pred_mv_bank_buf_base); |
92 | 141k | PS_DEC_ALIGNED_FREE(ps_dec, ps_svc_lyr_dec->pi2_il_residual_resample_luma_base); |
93 | 141k | PS_DEC_ALIGNED_FREE(ps_dec, ps_svc_lyr_dec->pi2_il_residual_resample_chroma_base); |
94 | 141k | PS_DEC_ALIGNED_FREE(ps_dec, ps_svc_lyr_dec->ps_svc_frm_mb_info); |
95 | 141k | PS_DEC_ALIGNED_FREE(ps_dec, ps_svc_lyr_dec->pu2_frm_res_luma_csbp); |
96 | 141k | PS_DEC_ALIGNED_FREE(ps_dec, ps_svc_lyr_dec->pu1_svc_base_mode_flag); |
97 | | |
98 | 141k | memset(ps_dec->ps_pic_buf_base, 0, sizeof(struct pic_buffer_t) * (H264_MAX_REF_PICS * 2)); |
99 | 9.17M | for(i = 0; i < MAX_DISP_BUFS_NEW; i++) |
100 | 9.03M | { |
101 | 9.03M | ps_dec->apv_buf_id_pic_buf_map[i] = NULL; |
102 | 9.03M | } |
103 | 141k | return 0; |
104 | 141k | } |
105 | | |
106 | | /*! |
107 | | ************************************************************************** |
108 | | * \if Function name : isvcd_allocate_dynamic_bufs \endif |
109 | | * |
110 | | * \brief |
111 | | * This function allocates memory required by Decoder. |
112 | | * |
113 | | * \param ps_dec: Pointer to dec_struct_t. |
114 | | * |
115 | | * \return |
116 | | * Returns i4_status as returned by MemManager. |
117 | | * |
118 | | ************************************************************************** |
119 | | */ |
120 | | |
121 | | WORD16 isvcd_allocate_dynamic_bufs(svc_dec_lyr_struct_t *ps_svc_lyr_dec) |
122 | 22.4k | { |
123 | 22.4k | dec_struct_t *ps_dec = &ps_svc_lyr_dec->s_dec; |
124 | 22.4k | WORD16 i16_status = 0; |
125 | 22.4k | UWORD8 uc_frmOrFld = (1 - ps_dec->ps_cur_sps->u1_frame_mbs_only_flag); |
126 | 22.4k | dec_seq_params_t *ps_sps = ps_dec->ps_cur_sps; |
127 | 22.4k | UWORD32 u4_total_mbs = ps_sps->u4_total_num_of_mbs << uc_frmOrFld; |
128 | 22.4k | WORD32 size; |
129 | 22.4k | void *pv_buf; |
130 | 22.4k | void *pv_mem_ctxt = ps_dec->pv_mem_ctxt; |
131 | 22.4k | size = u4_total_mbs; |
132 | | |
133 | 22.4k | i16_status = ih264d_allocate_dynamic_bufs(ps_dec); |
134 | | |
135 | 22.4k | if(i16_status != OK) |
136 | 0 | { |
137 | | /* Free any dynamic buffers that are allocated */ |
138 | 0 | ih264d_free_dynamic_bufs(ps_dec); |
139 | 0 | ps_dec->i4_error_code = IVD_MEM_ALLOC_FAILED; |
140 | 0 | return IVD_MEM_ALLOC_FAILED; |
141 | 0 | } |
142 | 22.4k | if(u4_total_mbs == 0) |
143 | 0 | { |
144 | 0 | return IVD_MEM_ALLOC_FAILED; |
145 | 0 | } |
146 | | |
147 | | /* Allocate frame level mb info */ |
148 | 22.4k | size = sizeof(dec_svc_mb_info_t) * u4_total_mbs; |
149 | 22.4k | pv_buf = ps_dec->pf_aligned_alloc(pv_mem_ctxt, 128, size); |
150 | 22.4k | RETURN_IF((NULL == pv_buf), IV_FAIL); |
151 | 22.4k | ps_svc_lyr_dec->ps_svc_frm_mb_info = pv_buf; |
152 | 22.4k | memset(ps_svc_lyr_dec->ps_svc_frm_mb_info, 0, size); |
153 | | |
154 | | /* Allocate frame level residual luma csbp info */ |
155 | 22.4k | size = sizeof(UWORD16) * u4_total_mbs; |
156 | 22.4k | pv_buf = ps_dec->pf_aligned_alloc(pv_mem_ctxt, 128, size); |
157 | 22.4k | RETURN_IF((NULL == pv_buf), IV_FAIL); |
158 | 22.4k | ps_svc_lyr_dec->pu2_frm_res_luma_csbp = pv_buf; |
159 | 22.4k | memset(ps_svc_lyr_dec->pu2_frm_res_luma_csbp, 0, size); |
160 | 22.4k | ps_svc_lyr_dec->i4_frm_res_luma_csbp_stride = ps_dec->u2_frm_wd_in_mbs; |
161 | | |
162 | | /* Allocate frame level residual luma csbp info */ |
163 | 22.4k | size = sizeof(UWORD8) * u4_total_mbs; |
164 | 22.4k | pv_buf = ps_dec->pf_aligned_alloc(pv_mem_ctxt, 128, size); |
165 | 22.4k | RETURN_IF((NULL == pv_buf), IV_FAIL); |
166 | 22.4k | ps_svc_lyr_dec->pu1_svc_base_mode_flag = pv_buf; |
167 | 22.4k | memset(ps_svc_lyr_dec->pu1_svc_base_mode_flag, 0, size); |
168 | 22.4k | ps_svc_lyr_dec->i4_frm_svc_base_mode_cabac_stride = ps_dec->u2_frm_wd_in_mbs; |
169 | 22.4k | ps_svc_lyr_dec->i4_frm_svc_base_mode_cabac_size = u4_total_mbs; |
170 | | |
171 | | /* Allocate frame level crop windows flags */ |
172 | 22.4k | size = sizeof(UWORD8) * u4_total_mbs; |
173 | 22.4k | pv_buf = ps_dec->pf_aligned_alloc(pv_mem_ctxt, 128, size); |
174 | 22.4k | RETURN_IF((NULL == pv_buf), IV_FAIL); |
175 | 22.4k | ps_svc_lyr_dec->pu1_crop_wnd_flag = pv_buf; |
176 | 22.4k | memset(ps_svc_lyr_dec->pu1_crop_wnd_flag, 0, size); |
177 | | |
178 | | /**********************************/ |
179 | | /*Creation of Inter layer buffers */ |
180 | | /**********************************/ |
181 | | |
182 | | /* MB type buffer : one element per MB */ |
183 | 22.4k | size = (ps_dec->u2_frm_wd_in_mbs + 2) * (ps_dec->u2_frm_ht_in_mbs + 2) * |
184 | 22.4k | sizeof(inter_lyr_mb_prms_t); |
185 | 22.4k | pv_buf = ps_dec->pf_aligned_alloc(pv_mem_ctxt, 128, size); |
186 | 22.4k | RETURN_IF((NULL == pv_buf), IV_FAIL); |
187 | 22.4k | memset(pv_buf, -1, size); |
188 | 22.4k | ps_svc_lyr_dec->ps_inter_lyr_mb_prms_base = pv_buf; |
189 | 22.4k | ps_svc_lyr_dec->u2_inter_lyr_mb_prms_stride = ps_dec->u2_frm_wd_in_mbs + 2; |
190 | 22.4k | ps_svc_lyr_dec->ps_inter_lyr_mb_prms_frm_start = |
191 | 22.4k | ps_svc_lyr_dec->ps_inter_lyr_mb_prms_base + 1 + ps_svc_lyr_dec->u2_inter_lyr_mb_prms_stride; |
192 | | |
193 | 22.4k | ps_svc_lyr_dec->u4_inter_lyr_mb_prms_size = (ps_dec->u2_frm_wd_in_mbs + 2) * |
194 | 22.4k | (ps_dec->u2_frm_ht_in_mbs + 2) * |
195 | 22.4k | sizeof(inter_lyr_mb_prms_t); |
196 | | |
197 | | /* Luma Residual data at each layer : dafault 0*/ |
198 | 22.4k | size = ((ps_dec->u2_pic_wd + 4) * (ps_dec->u2_pic_ht + 4)) * sizeof(WORD16); |
199 | 22.4k | pv_buf = ps_dec->pf_aligned_alloc(pv_mem_ctxt, 128, size); |
200 | 22.4k | RETURN_IF((NULL == pv_buf), IV_FAIL); |
201 | 22.4k | memset(pv_buf, 0, size); |
202 | 22.4k | ps_svc_lyr_dec->pi2_il_residual_resample_luma_base = pv_buf; |
203 | 22.4k | ps_svc_lyr_dec->u2_residual_resample_luma_stride = (ps_dec->u2_pic_wd + 4); |
204 | 22.4k | ps_svc_lyr_dec->pi2_il_residual_resample_mb_luma_frm_start = |
205 | 22.4k | ps_svc_lyr_dec->pi2_il_residual_resample_luma_base + 2 + |
206 | 22.4k | (2 * ps_svc_lyr_dec->u2_residual_resample_luma_stride); |
207 | 22.4k | ps_svc_lyr_dec->u4_residual_resample_luma_size = |
208 | 22.4k | ((ps_dec->u2_pic_wd + 4) * (ps_dec->u2_pic_ht + 4)) * sizeof(WORD16); |
209 | | |
210 | | /* Chroma Residual data at each layer : dafault 0*/ |
211 | 22.4k | size = (((4 + ps_dec->u2_pic_wd) * ((4 + ps_dec->u2_pic_ht) >> 1)) * sizeof(WORD16)); |
212 | 22.4k | pv_buf = ps_dec->pf_aligned_alloc(pv_mem_ctxt, 128, size); |
213 | 22.4k | RETURN_IF((NULL == pv_buf), IV_FAIL); |
214 | 22.4k | memset(pv_buf, 0, size); |
215 | 22.4k | ps_svc_lyr_dec->pi2_il_residual_resample_chroma_base = pv_buf; |
216 | 22.4k | ps_svc_lyr_dec->u2_residual_resample_chroma_stride = (ps_dec->u2_pic_wd + 4); |
217 | 22.4k | ps_svc_lyr_dec->pi2_il_residual_resample_mb_chroma_frm_start = |
218 | 22.4k | ps_svc_lyr_dec->pi2_il_residual_resample_chroma_base + 2 + |
219 | 22.4k | ps_svc_lyr_dec->u2_residual_resample_chroma_stride; |
220 | 22.4k | ps_svc_lyr_dec->u4_residual_resample_chroma_size = |
221 | 22.4k | (((4 + ps_dec->u2_pic_wd) * ((4 + ps_dec->u2_pic_ht) >> 1)) * sizeof(WORD16)); |
222 | | |
223 | | /* mv bank buffer : 16 elements per MB: each at 4x4 block level */ |
224 | 22.4k | size = ((ps_dec->u2_pic_wd) * (ps_dec->u2_pic_ht >> 4)) * sizeof(mv_pred_t); |
225 | 22.4k | pv_buf = ps_dec->pf_aligned_alloc(pv_mem_ctxt, 128, size); |
226 | 22.4k | RETURN_IF((NULL == pv_buf), IV_FAIL); |
227 | 22.4k | memset(pv_buf, 0, size); |
228 | 22.4k | ps_svc_lyr_dec->ps_il_pred_mv_bank_buf_base = pv_buf; |
229 | | |
230 | | /*syntax for SVC related bin ctxt tables*/ |
231 | 22.4k | { |
232 | 22.4k | bin_ctxt_model_t *const p_cabac_ctxt_table_t = ps_dec->p_cabac_ctxt_table_t; |
233 | | |
234 | 22.4k | ps_svc_lyr_dec->ps_base_mode_flag = p_cabac_ctxt_table_t + CABAC_BASE_MODE_FLAG; |
235 | 22.4k | ps_svc_lyr_dec->ps_motion_prediction_flag_l0 = p_cabac_ctxt_table_t + CABAC_MOT_PRED_FLAG0; |
236 | 22.4k | ps_svc_lyr_dec->ps_motion_prediction_flag_l1 = p_cabac_ctxt_table_t + CABAC_MOT_PRED_FLAG1; |
237 | 22.4k | ps_svc_lyr_dec->ps_residual_prediction_flag = p_cabac_ctxt_table_t + CABAC_RES_PRED_FLAG; |
238 | 22.4k | } |
239 | 22.4k | return (i16_status); |
240 | 22.4k | } |
241 | | |
242 | | /*! |
243 | | ************************************************************************** |
244 | | * \if Function name : isvcd_decode_pic_order_cnt \endif |
245 | | * |
246 | | * \brief |
247 | | * Calculates picture order count of picture. |
248 | | * |
249 | | * \return |
250 | | * Returns the pic order count of the picture to which current |
251 | | * Slice belongs. |
252 | | * |
253 | | ************************************************************************** |
254 | | */ |
255 | | WORD32 isvcd_decode_pic_order_cnt( |
256 | | UWORD8 u1_is_idr_slice, UWORD32 u2_frame_num, pocstruct_t *ps_prev_poc, pocstruct_t *ps_cur_poc, |
257 | | dec_slice_params_t *ps_cur_slice, /*!< Pointer to current slice Params*/ |
258 | | dec_pic_params_t *ps_pps, UWORD8 u1_nal_ref_idc, UWORD8 u1_bottom_field_flag, |
259 | | UWORD8 u1_field_pic_flag, WORD32 *pi4_poc, dec_struct_t *ps_dec) |
260 | 116k | { |
261 | 116k | WORD64 i8_pic_msb; |
262 | 116k | WORD32 i4_top_field_order_cnt = 0, i4_bottom_field_order_cnt = 0; |
263 | 116k | dec_seq_params_t *ps_seq = ps_dec->ps_cur_sps; |
264 | 116k | WORD32 i4_prev_frame_num_ofst; |
265 | | |
266 | 116k | switch(ps_seq->u1_pic_order_cnt_type) |
267 | 116k | { |
268 | 94.1k | case 0: |
269 | | /* POC TYPE 0 */ |
270 | 94.1k | if(u1_is_idr_slice) |
271 | 84.9k | { |
272 | 84.9k | ps_prev_poc->i4_pic_order_cnt_msb = 0; |
273 | 84.9k | ps_prev_poc->i4_pic_order_cnt_lsb = 0; |
274 | 84.9k | } |
275 | 94.1k | if(ps_prev_poc->u1_mmco_equalto5) |
276 | 912 | { |
277 | 912 | if(ps_prev_poc->u1_bot_field != 1) |
278 | 912 | { |
279 | 912 | ps_prev_poc->i4_pic_order_cnt_msb = 0; |
280 | 912 | ps_prev_poc->i4_pic_order_cnt_lsb = ps_prev_poc->i4_top_field_order_count; |
281 | 912 | } |
282 | 0 | else |
283 | 0 | { |
284 | 0 | ps_prev_poc->i4_pic_order_cnt_msb = 0; |
285 | 0 | ps_prev_poc->i4_pic_order_cnt_lsb = 0; |
286 | 0 | } |
287 | 912 | } |
288 | | |
289 | 94.1k | if((ps_cur_poc->i4_pic_order_cnt_lsb < ps_prev_poc->i4_pic_order_cnt_lsb) && |
290 | 3.51k | ((ps_prev_poc->i4_pic_order_cnt_lsb - ps_cur_poc->i4_pic_order_cnt_lsb) >= |
291 | 3.51k | (ps_seq->i4_max_pic_order_cntLsb >> 1))) |
292 | 2.39k | { |
293 | 2.39k | i8_pic_msb = |
294 | 2.39k | (WORD64) ps_prev_poc->i4_pic_order_cnt_msb + ps_seq->i4_max_pic_order_cntLsb; |
295 | 2.39k | } |
296 | 91.7k | else if((ps_cur_poc->i4_pic_order_cnt_lsb > ps_prev_poc->i4_pic_order_cnt_lsb) && |
297 | 67.2k | ((ps_cur_poc->i4_pic_order_cnt_lsb - ps_prev_poc->i4_pic_order_cnt_lsb) >= |
298 | 67.2k | (ps_seq->i4_max_pic_order_cntLsb >> 1))) |
299 | 39.1k | { |
300 | 39.1k | i8_pic_msb = |
301 | 39.1k | (WORD64) ps_prev_poc->i4_pic_order_cnt_msb - ps_seq->i4_max_pic_order_cntLsb; |
302 | 39.1k | } |
303 | 52.5k | else |
304 | 52.5k | { |
305 | 52.5k | i8_pic_msb = ps_prev_poc->i4_pic_order_cnt_msb; |
306 | 52.5k | } |
307 | | |
308 | 94.1k | if(!u1_field_pic_flag || !u1_bottom_field_flag) |
309 | 94.1k | { |
310 | 94.1k | WORD64 i8_result = i8_pic_msb + ps_cur_poc->i4_pic_order_cnt_lsb; |
311 | 94.1k | if(IS_OUT_OF_RANGE_S32(i8_result)) |
312 | 0 | { |
313 | 0 | return ERROR_INV_POC; |
314 | 0 | } |
315 | 94.1k | i4_top_field_order_cnt = (WORD32) i8_result; |
316 | 94.1k | } |
317 | | |
318 | 94.1k | if(!u1_field_pic_flag) |
319 | 94.1k | { |
320 | 94.1k | WORD64 i8_result = |
321 | 94.1k | (WORD64) i4_top_field_order_cnt + ps_cur_poc->i4_delta_pic_order_cnt_bottom; |
322 | 94.1k | if(IS_OUT_OF_RANGE_S32(i8_result)) |
323 | 125 | { |
324 | 125 | return ERROR_INV_POC; |
325 | 125 | } |
326 | 94.0k | i4_bottom_field_order_cnt = (WORD32) i8_result; |
327 | 94.0k | } |
328 | 0 | else if(u1_bottom_field_flag) |
329 | 0 | { |
330 | 0 | WORD64 i8_result = i8_pic_msb + ps_cur_poc->i4_pic_order_cnt_lsb; |
331 | 0 | if(IS_OUT_OF_RANGE_S32(i8_result)) |
332 | 0 | { |
333 | 0 | return ERROR_INV_POC; |
334 | 0 | } |
335 | 0 | i4_bottom_field_order_cnt = (WORD32) i8_result; |
336 | 0 | } |
337 | | |
338 | 94.0k | if(IS_OUT_OF_RANGE_S32(i8_pic_msb)) |
339 | 0 | { |
340 | 0 | return ERROR_INV_POC; |
341 | 0 | } |
342 | 94.0k | ps_cur_poc->i4_pic_order_cnt_msb = (WORD32) i8_pic_msb; |
343 | 94.0k | break; |
344 | | |
345 | 19.7k | case 1: |
346 | 19.7k | { |
347 | | /* POC TYPE 1 */ |
348 | 19.7k | UWORD8 i; |
349 | 19.7k | WORD32 prev_frame_num; |
350 | 19.7k | WORD32 frame_num_ofst; |
351 | 19.7k | WORD32 abs_frm_num; |
352 | 19.7k | WORD32 poc_cycle_cnt, frame_num_in_poc_cycle; |
353 | 19.7k | WORD64 i8_expected_delta_poc_cycle; |
354 | 19.7k | WORD32 expected_poc; |
355 | 19.7k | WORD64 i8_result; |
356 | | |
357 | 19.7k | prev_frame_num = (WORD32) ps_cur_slice->u2_frame_num; |
358 | 19.7k | if(!u1_is_idr_slice) |
359 | 9.15k | { |
360 | 9.15k | if(ps_cur_slice->u1_mmco_equalto5) |
361 | 579 | { |
362 | 579 | prev_frame_num = 0; |
363 | 579 | i4_prev_frame_num_ofst = 0; |
364 | 579 | } |
365 | 8.57k | else |
366 | 8.57k | { |
367 | 8.57k | i4_prev_frame_num_ofst = ps_prev_poc->i4_prev_frame_num_ofst; |
368 | 8.57k | } |
369 | 9.15k | } |
370 | 10.5k | else |
371 | 10.5k | i4_prev_frame_num_ofst = 0; |
372 | | |
373 | | /* 1. Derivation for FrameNumOffset */ |
374 | 19.7k | if(u1_is_idr_slice) |
375 | 10.5k | { |
376 | 10.5k | frame_num_ofst = 0; |
377 | 10.5k | ps_cur_poc->i4_delta_pic_order_cnt[0] = 0; |
378 | 10.5k | ps_cur_poc->i4_delta_pic_order_cnt[1] = 0; |
379 | 10.5k | } |
380 | 9.15k | else if(prev_frame_num > ((WORD32) u2_frame_num)) |
381 | 3.95k | { |
382 | 3.95k | WORD64 i8_result = |
383 | 3.95k | i4_prev_frame_num_ofst + (WORD64) ps_seq->u2_u4_max_pic_num_minus1 + 1; |
384 | 3.95k | if(IS_OUT_OF_RANGE_S32(i8_result)) |
385 | 74 | { |
386 | 74 | return ERROR_INV_FRAME_NUM; |
387 | 74 | } |
388 | 3.88k | frame_num_ofst = (WORD32) i8_result; |
389 | 3.88k | } |
390 | 5.19k | else |
391 | 5.19k | frame_num_ofst = i4_prev_frame_num_ofst; |
392 | | |
393 | | /* 2. Derivation for absFrameNum */ |
394 | 19.6k | if(0 != ps_seq->u1_num_ref_frames_in_pic_order_cnt_cycle) |
395 | 12.8k | { |
396 | 12.8k | WORD64 i8_result = frame_num_ofst + (WORD64) u2_frame_num; |
397 | 12.8k | if(IS_OUT_OF_RANGE_S32(i8_result)) |
398 | 0 | { |
399 | 0 | return ERROR_INV_FRAME_NUM; |
400 | 0 | } |
401 | 12.8k | abs_frm_num = (WORD32) i8_result; |
402 | 12.8k | } |
403 | 6.82k | else |
404 | 6.82k | abs_frm_num = 0; |
405 | 19.6k | if((u1_nal_ref_idc == 0) && (abs_frm_num > 0)) abs_frm_num = abs_frm_num - 1; |
406 | | |
407 | | /* 4. expectedDeltaPerPicOrderCntCycle is derived as */ |
408 | 19.6k | i8_expected_delta_poc_cycle = 0; |
409 | 113k | for(i = 0; i < ps_seq->u1_num_ref_frames_in_pic_order_cnt_cycle; i++) |
410 | 94.3k | { |
411 | 94.3k | i8_expected_delta_poc_cycle += ps_seq->i4_ofst_for_ref_frame[i]; |
412 | 94.3k | } |
413 | | |
414 | | /* 3. When absFrameNum > 0, picOrderCntCycleCnt and |
415 | | frame_num_in_poc_cycle are derived as : */ |
416 | | /* 5. expectedPicOrderCnt is derived as : */ |
417 | 19.6k | if(abs_frm_num > 0) |
418 | 12.7k | { |
419 | 12.7k | poc_cycle_cnt = |
420 | 12.7k | DIV((abs_frm_num - 1), ps_seq->u1_num_ref_frames_in_pic_order_cnt_cycle); |
421 | 12.7k | frame_num_in_poc_cycle = |
422 | 12.7k | MOD((abs_frm_num - 1), ps_seq->u1_num_ref_frames_in_pic_order_cnt_cycle); |
423 | | |
424 | 12.7k | i8_result = poc_cycle_cnt * i8_expected_delta_poc_cycle; |
425 | | |
426 | 66.1k | for(i = 0; i <= frame_num_in_poc_cycle; i++) |
427 | 53.3k | { |
428 | 53.3k | i8_result = i8_result + ps_seq->i4_ofst_for_ref_frame[i]; |
429 | 53.3k | } |
430 | | |
431 | 12.7k | if(IS_OUT_OF_RANGE_S32(i8_result)) return ERROR_INV_POC; |
432 | | |
433 | 12.5k | expected_poc = (WORD32) i8_result; |
434 | 12.5k | } |
435 | 6.84k | else |
436 | 6.84k | expected_poc = 0; |
437 | | |
438 | 19.4k | if(u1_nal_ref_idc == 0) |
439 | 3.06k | { |
440 | 3.06k | i8_result = (WORD64) expected_poc + ps_seq->i4_ofst_for_non_ref_pic; |
441 | | |
442 | 3.06k | if(IS_OUT_OF_RANGE_S32(i8_result)) return ERROR_INV_POC; |
443 | | |
444 | 2.99k | expected_poc = (WORD32) i8_result; |
445 | 2.99k | } |
446 | | |
447 | | /* 6. TopFieldOrderCnt or BottomFieldOrderCnt are derived as */ |
448 | 19.3k | if(!u1_field_pic_flag) |
449 | 19.3k | { |
450 | 19.3k | i8_result = (WORD64) expected_poc + ps_cur_poc->i4_delta_pic_order_cnt[0]; |
451 | | |
452 | 19.3k | if(IS_OUT_OF_RANGE_S32(i8_result)) return ERROR_INV_POC; |
453 | 19.2k | i4_top_field_order_cnt = (WORD32) i8_result; |
454 | | |
455 | 19.2k | i8_result = (WORD64) i4_top_field_order_cnt + |
456 | 19.2k | ps_seq->i4_ofst_for_top_to_bottom_field + |
457 | 19.2k | ps_cur_poc->i4_delta_pic_order_cnt[1]; |
458 | | |
459 | 19.2k | if(IS_OUT_OF_RANGE_S32(i8_result)) return ERROR_INV_POC; |
460 | 19.0k | i4_bottom_field_order_cnt = (WORD32) i8_result; |
461 | 19.0k | } |
462 | 0 | else if(!u1_bottom_field_flag) |
463 | 0 | { |
464 | 0 | i8_result = (WORD64) expected_poc + ps_cur_poc->i4_delta_pic_order_cnt[0]; |
465 | |
|
466 | 0 | if(IS_OUT_OF_RANGE_S32(i8_result)) return ERROR_INV_POC; |
467 | 0 | i4_top_field_order_cnt = (WORD32) i8_result; |
468 | 0 | } |
469 | 0 | else |
470 | 0 | { |
471 | 0 | i8_result = (WORD64) expected_poc + ps_seq->i4_ofst_for_top_to_bottom_field + |
472 | 0 | ps_cur_poc->i4_delta_pic_order_cnt[0]; |
473 | |
|
474 | 0 | if(IS_OUT_OF_RANGE_S32(i8_result)) return ERROR_INV_POC; |
475 | 0 | i4_bottom_field_order_cnt = (WORD32) i8_result; |
476 | 0 | } |
477 | | /* Copy the current POC info into Previous POC structure */ |
478 | 19.0k | ps_cur_poc->i4_prev_frame_num_ofst = frame_num_ofst; |
479 | 19.0k | } |
480 | | |
481 | 0 | break; |
482 | 2.83k | case 2: |
483 | 2.83k | { |
484 | | /* POC TYPE 2 */ |
485 | 2.83k | WORD32 prev_frame_num; |
486 | 2.83k | WORD32 frame_num_ofst; |
487 | 2.83k | WORD32 tmp_poc; |
488 | | |
489 | 2.83k | prev_frame_num = (WORD32) ps_cur_slice->u2_frame_num; |
490 | 2.83k | if(!u1_is_idr_slice) |
491 | 1.32k | { |
492 | 1.32k | if(ps_cur_slice->u1_mmco_equalto5) |
493 | 372 | { |
494 | 372 | prev_frame_num = 0; |
495 | 372 | i4_prev_frame_num_ofst = 0; |
496 | 372 | } |
497 | 953 | else |
498 | 953 | i4_prev_frame_num_ofst = ps_prev_poc->i4_prev_frame_num_ofst; |
499 | 1.32k | } |
500 | 1.50k | else |
501 | 1.50k | i4_prev_frame_num_ofst = 0; |
502 | | |
503 | | /* 1. Derivation for FrameNumOffset */ |
504 | 2.83k | if(u1_is_idr_slice) |
505 | 1.50k | { |
506 | 1.50k | frame_num_ofst = 0; |
507 | 1.50k | ps_cur_poc->i4_delta_pic_order_cnt[0] = 0; |
508 | 1.50k | ps_cur_poc->i4_delta_pic_order_cnt[1] = 0; |
509 | 1.50k | } |
510 | 1.32k | else if(prev_frame_num > ((WORD32) u2_frame_num)) |
511 | 526 | { |
512 | 526 | WORD64 i8_result = |
513 | 526 | i4_prev_frame_num_ofst + (WORD64) ps_seq->u2_u4_max_pic_num_minus1 + 1; |
514 | 526 | if(IS_OUT_OF_RANGE_S32(i8_result)) |
515 | 41 | { |
516 | 41 | return ERROR_INV_FRAME_NUM; |
517 | 41 | } |
518 | 485 | frame_num_ofst = (WORD32) i8_result; |
519 | 485 | } |
520 | 799 | else |
521 | 799 | frame_num_ofst = i4_prev_frame_num_ofst; |
522 | | |
523 | | /* 2. Derivation for tempPicOrderCnt */ |
524 | 2.79k | if(u1_is_idr_slice) |
525 | 1.50k | tmp_poc = 0; |
526 | 1.28k | else if(u1_nal_ref_idc == 0) |
527 | 459 | { |
528 | 459 | WORD64 i8_result = ((frame_num_ofst + (WORD64) u2_frame_num) << 1) - 1; |
529 | 459 | if(IS_OUT_OF_RANGE_S32(i8_result)) |
530 | 0 | { |
531 | 0 | return ERROR_INV_POC; |
532 | 0 | } |
533 | 459 | tmp_poc = (WORD32) i8_result; |
534 | 459 | } |
535 | 825 | else |
536 | 825 | { |
537 | 825 | WORD64 i8_result = (frame_num_ofst + (WORD64) u2_frame_num) << 1; |
538 | 825 | if(IS_OUT_OF_RANGE_S32(i8_result)) |
539 | 0 | { |
540 | 0 | return ERROR_INV_POC; |
541 | 0 | } |
542 | 825 | tmp_poc = (WORD32) i8_result; |
543 | 825 | } |
544 | | |
545 | | /* 6. TopFieldOrderCnt or BottomFieldOrderCnt are derived as */ |
546 | 2.79k | if(!u1_field_pic_flag) |
547 | 2.79k | { |
548 | 2.79k | i4_top_field_order_cnt = tmp_poc; |
549 | 2.79k | i4_bottom_field_order_cnt = tmp_poc; |
550 | 2.79k | } |
551 | 0 | else if(!u1_bottom_field_flag) |
552 | 0 | i4_top_field_order_cnt = tmp_poc; |
553 | 0 | else |
554 | 0 | i4_bottom_field_order_cnt = tmp_poc; |
555 | | |
556 | | /* Copy the current POC info into Previous POC structure */ |
557 | 2.79k | ps_prev_poc->i4_prev_frame_num_ofst = frame_num_ofst; |
558 | 2.79k | ps_cur_poc->i4_prev_frame_num_ofst = frame_num_ofst; |
559 | 2.79k | } |
560 | 0 | break; |
561 | 0 | default: |
562 | 0 | return ERROR_INV_POC_TYPE_T; |
563 | 0 | break; |
564 | 116k | } |
565 | | |
566 | 115k | if(!u1_field_pic_flag) // or a complementary field pair |
567 | 115k | { |
568 | 115k | *pi4_poc = MIN(i4_top_field_order_cnt, i4_bottom_field_order_cnt); |
569 | 115k | ps_pps->i4_top_field_order_cnt = i4_top_field_order_cnt; |
570 | 115k | ps_pps->i4_bottom_field_order_cnt = i4_bottom_field_order_cnt; |
571 | 115k | } |
572 | 0 | else if(!u1_bottom_field_flag) |
573 | 0 | { |
574 | 0 | *pi4_poc = i4_top_field_order_cnt; |
575 | 0 | ps_pps->i4_top_field_order_cnt = i4_top_field_order_cnt; |
576 | 0 | } |
577 | 0 | else |
578 | 0 | { |
579 | 0 | *pi4_poc = i4_bottom_field_order_cnt; |
580 | 0 | ps_pps->i4_bottom_field_order_cnt = i4_bottom_field_order_cnt; |
581 | 0 | } |
582 | | |
583 | 115k | ps_pps->i4_avg_poc = *pi4_poc; |
584 | | |
585 | 115k | return OK; |
586 | 116k | } |
587 | | |
588 | | /*****************************************************************************/ |
589 | | /* */ |
590 | | /* Function Name : isvcd_decode_gaps_in_frame_num */ |
591 | | /* */ |
592 | | /* Description : This function decodes gaps in frame number */ |
593 | | /* */ |
594 | | /* Inputs : ps_dec Decoder parameters */ |
595 | | /* u2_frame_num current frame number */ |
596 | | /* */ |
597 | | /* Globals : None */ |
598 | | /* Processing : This functionality needs to be implemented */ |
599 | | /* Outputs : None */ |
600 | | /* Returns : None */ |
601 | | /* */ |
602 | | /* Issues : Not implemented */ |
603 | | /* */ |
604 | | /* Revision History: */ |
605 | | /* */ |
606 | | /* DD MM YYYY Author(s) Changes (Describe the changes made) */ |
607 | | /* 06 05 2002 NS Draft */ |
608 | | /* */ |
609 | | /*****************************************************************************/ |
610 | | WORD32 isvcd_decode_gaps_in_frame_num(dec_struct_t *ps_dec, UWORD16 u2_frame_num) |
611 | 0 | { |
612 | 0 | UWORD32 u4_next_frm_num, u4_start_frm_num; |
613 | 0 | UWORD32 u4_max_frm_num; |
614 | 0 | pocstruct_t s_tmp_poc; |
615 | 0 | WORD32 i4_poc; |
616 | 0 | dec_slice_params_t *ps_cur_slice; |
617 | |
|
618 | 0 | dec_pic_params_t *ps_pic_params; |
619 | 0 | WORD8 i1_gap_idx; |
620 | 0 | WORD32 *i4_gaps_start_frm_num; |
621 | 0 | dpb_manager_t *ps_dpb_mgr; |
622 | 0 | WORD8 *pi1_gaps_per_seq; |
623 | 0 | WORD32 ret; |
624 | |
|
625 | 0 | ps_cur_slice = ps_dec->ps_cur_slice; |
626 | 0 | if(ps_cur_slice->u1_field_pic_flag) |
627 | 0 | { |
628 | 0 | if(ps_dec->u2_prev_ref_frame_num == u2_frame_num) return 0; |
629 | 0 | } |
630 | | |
631 | 0 | u4_next_frm_num = ps_dec->u2_prev_ref_frame_num + 1; |
632 | 0 | u4_max_frm_num = ps_dec->ps_cur_sps->u2_u4_max_pic_num_minus1 + 1; |
633 | |
|
634 | 0 | if(u4_next_frm_num >= u4_max_frm_num) |
635 | 0 | { |
636 | 0 | u4_next_frm_num -= u4_max_frm_num; |
637 | 0 | } |
638 | |
|
639 | 0 | if(u4_next_frm_num == u2_frame_num) |
640 | 0 | { |
641 | 0 | return (0); |
642 | 0 | } |
643 | | |
644 | 0 | if((ps_dec->u1_nal_unit_type == IDR_SLICE_NAL) && (u4_next_frm_num >= u2_frame_num)) |
645 | 0 | { |
646 | 0 | return (0); |
647 | 0 | } |
648 | 0 | u4_start_frm_num = u4_next_frm_num; |
649 | |
|
650 | 0 | s_tmp_poc.i4_pic_order_cnt_lsb = 0; |
651 | 0 | s_tmp_poc.i4_delta_pic_order_cnt_bottom = 0; |
652 | 0 | s_tmp_poc.i4_pic_order_cnt_lsb = 0; |
653 | 0 | s_tmp_poc.i4_delta_pic_order_cnt_bottom = 0; |
654 | 0 | s_tmp_poc.i4_delta_pic_order_cnt[0] = 0; |
655 | 0 | s_tmp_poc.i4_delta_pic_order_cnt[1] = 0; |
656 | |
|
657 | 0 | ps_cur_slice = ps_dec->ps_cur_slice; |
658 | 0 | ps_pic_params = ps_dec->ps_cur_pps; |
659 | |
|
660 | 0 | ps_dpb_mgr = ps_dec->ps_dpb_mgr; |
661 | | |
662 | | /* Find a empty slot to store gap seqn info */ |
663 | 0 | i4_gaps_start_frm_num = ps_dpb_mgr->ai4_gaps_start_frm_num; |
664 | 0 | for(i1_gap_idx = 0; i1_gap_idx < MAX_FRAMES; i1_gap_idx++) |
665 | 0 | { |
666 | 0 | if(INVALID_FRAME_NUM == i4_gaps_start_frm_num[i1_gap_idx]) break; |
667 | 0 | } |
668 | 0 | if(MAX_FRAMES == i1_gap_idx) |
669 | 0 | { |
670 | 0 | UWORD32 i4_error_code; |
671 | 0 | i4_error_code = ERROR_DBP_MANAGER_T; |
672 | 0 | return i4_error_code; |
673 | 0 | } |
674 | | |
675 | 0 | i4_poc = 0; |
676 | 0 | i4_gaps_start_frm_num[i1_gap_idx] = u4_start_frm_num; |
677 | 0 | ps_dpb_mgr->ai4_gaps_end_frm_num[i1_gap_idx] = u2_frame_num - 1; |
678 | 0 | pi1_gaps_per_seq = ps_dpb_mgr->ai1_gaps_per_seq; |
679 | 0 | pi1_gaps_per_seq[i1_gap_idx] = 0; |
680 | 0 | while(u4_next_frm_num != u2_frame_num) |
681 | 0 | { |
682 | 0 | ih264d_delete_nonref_nondisplay_pics(ps_dpb_mgr); |
683 | 0 | if(ps_pic_params->ps_sps->u1_pic_order_cnt_type) |
684 | 0 | { |
685 | | /* allocate a picture buffer and insert it as ST node */ |
686 | 0 | ret = |
687 | 0 | isvcd_decode_pic_order_cnt(0, u4_next_frm_num, &ps_dec->s_prev_pic_poc, &s_tmp_poc, |
688 | 0 | ps_cur_slice, ps_pic_params, 1, 0, 0, &i4_poc, ps_dec); |
689 | 0 | if(ret != OK) return ret; |
690 | | |
691 | | /* Display seq no calculations */ |
692 | 0 | if(i4_poc >= ps_dec->i4_max_poc) ps_dec->i4_max_poc = i4_poc; |
693 | | /* IDR Picture or POC wrap around */ |
694 | 0 | if(i4_poc == 0) |
695 | 0 | { |
696 | 0 | WORD64 i8_temp; |
697 | 0 | i8_temp = (WORD64) ps_dec->i4_prev_max_display_seq + ps_dec->i4_max_poc + |
698 | 0 | ps_dec->u1_max_dec_frame_buffering + 1; |
699 | | /*If i4_prev_max_display_seq overflows integer range, reset it */ |
700 | 0 | ps_dec->i4_prev_max_display_seq = |
701 | 0 | IS_OUT_OF_RANGE_S32(i8_temp) ? 0 : (WORD32) i8_temp; |
702 | 0 | ps_dec->i4_max_poc = 0; |
703 | 0 | } |
704 | |
|
705 | 0 | ps_cur_slice->u1_mmco_equalto5 = 0; |
706 | 0 | ps_cur_slice->u2_frame_num = u4_next_frm_num; |
707 | 0 | } |
708 | | |
709 | 0 | if(ps_dpb_mgr->i1_poc_buf_id_entries >= ps_dec->u1_max_dec_frame_buffering) |
710 | 0 | { |
711 | 0 | ret = ih264d_assign_display_seq(ps_dec); |
712 | 0 | if(ret != OK) return ret; |
713 | 0 | } |
714 | | |
715 | 0 | { |
716 | 0 | WORD64 i8_display_poc; |
717 | 0 | i8_display_poc = (WORD64) ps_dec->i4_prev_max_display_seq + i4_poc; |
718 | 0 | if(IS_OUT_OF_RANGE_S32(i8_display_poc)) |
719 | 0 | { |
720 | 0 | ps_dec->i4_prev_max_display_seq = 0; |
721 | 0 | } |
722 | 0 | } |
723 | 0 | ret = ih264d_insert_pic_in_display_list(ps_dec->ps_dpb_mgr, (WORD8) DO_NOT_DISP, |
724 | 0 | (WORD32) (ps_dec->i4_prev_max_display_seq + i4_poc), |
725 | 0 | u4_next_frm_num); |
726 | 0 | if(ret != OK) return ret; |
727 | | |
728 | 0 | pi1_gaps_per_seq[i1_gap_idx]++; |
729 | 0 | ret = ih264d_do_mmco_for_gaps(ps_dpb_mgr, ps_dec->ps_cur_sps->u1_num_ref_frames); |
730 | 0 | if(ret != OK) return ret; |
731 | | |
732 | 0 | ih264d_delete_nonref_nondisplay_pics(ps_dpb_mgr); |
733 | |
|
734 | 0 | u4_next_frm_num++; |
735 | 0 | if(u4_next_frm_num >= u4_max_frm_num) |
736 | 0 | { |
737 | 0 | u4_next_frm_num -= u4_max_frm_num; |
738 | 0 | } |
739 | 0 | } |
740 | | |
741 | 0 | return OK; |
742 | 0 | } |
743 | | |
744 | | /*! |
745 | | **************************************************************************** |
746 | | * |
747 | | * \if Function name : isvcd_init_dpb_ref_bufs \endif |
748 | | * |
749 | | * \brief |
750 | | * Initializes the reference buffers |
751 | | * |
752 | | * \return |
753 | | * None |
754 | | * |
755 | | * \note |
756 | | * This function is called to initialize the reference buffers. |
757 | | **************************************************************************** |
758 | | */ |
759 | | |
760 | | void isvcd_init_dpb_ref_bufs(dec_struct_t *ps_dec) |
761 | 100k | { |
762 | 100k | UWORD8 i; |
763 | 100k | struct pic_buffer_t *ps_init_dpb; |
764 | 100k | ps_init_dpb = ps_dec->ps_dpb_mgr->ps_init_dpb[0][0]; |
765 | 6.53M | for(i = 0; i < 2 * MAX_REF_BUFS; i++) |
766 | 6.43M | { |
767 | 6.43M | memset(ps_init_dpb, 0, sizeof(struct pic_buffer_t)); |
768 | 6.43M | ps_init_dpb->pu1_buf1 = NULL; |
769 | 6.43M | ps_init_dpb->u1_long_term_frm_idx = MAX_REF_BUFS + 1; |
770 | 6.43M | ps_dec->ps_dpb_mgr->ps_init_dpb[0][i] = ps_init_dpb; |
771 | 6.43M | ps_dec->ps_dpb_mgr->ps_mod_dpb[0][i] = ps_init_dpb; |
772 | 6.43M | ps_init_dpb++; |
773 | 6.43M | } |
774 | | |
775 | 100k | ps_init_dpb = ps_dec->ps_dpb_mgr->ps_init_dpb[1][0]; |
776 | 6.53M | for(i = 0; i < 2 * MAX_REF_BUFS; i++) |
777 | 6.43M | { |
778 | 6.43M | memset(ps_init_dpb, 0, sizeof(struct pic_buffer_t)); |
779 | 6.43M | ps_init_dpb->pu1_buf1 = NULL; |
780 | 6.43M | ps_init_dpb->u1_long_term_frm_idx = MAX_REF_BUFS + 1; |
781 | 6.43M | ps_dec->ps_dpb_mgr->ps_init_dpb[1][i] = ps_init_dpb; |
782 | 6.43M | ps_dec->ps_dpb_mgr->ps_mod_dpb[1][i] = ps_init_dpb; |
783 | 6.43M | ps_init_dpb++; |
784 | 6.43M | } |
785 | 100k | } |
786 | | |
787 | | /*! |
788 | | ************************************************************************** |
789 | | * \if Function name : isvcd_init_pic \endif |
790 | | * |
791 | | * \brief |
792 | | * Initializes the picture. |
793 | | * |
794 | | * \return |
795 | | * 0 on Success and Error code otherwise |
796 | | * |
797 | | * \note |
798 | | * This function is called when first slice of the |
799 | | * NON -IDR picture is encountered. |
800 | | ************************************************************************** |
801 | | */ |
802 | | WORD32 isvcd_init_pic(svc_dec_lyr_struct_t *ps_svc_lyr_dec, UWORD16 u2_frame_num, WORD32 i4_poc, |
803 | | dec_pic_params_t *ps_pps) |
804 | 114k | { |
805 | 114k | dec_struct_t *ps_dec = &ps_svc_lyr_dec->s_dec; |
806 | 114k | dec_seq_params_t *ps_seq = ps_dec->ps_cur_sps; |
807 | 114k | prev_seq_params_t *ps_prev_seq_params = &ps_dec->s_prev_seq_params; |
808 | 114k | WORD32 ret; |
809 | | |
810 | 114k | ps_dec->ps_cur_slice->u2_frame_num = u2_frame_num; |
811 | 114k | ps_dec->ps_cur_slice->i4_poc = i4_poc; |
812 | 114k | ps_dec->ps_cur_pps = ps_pps; |
813 | 114k | ps_dec->ps_cur_pps->pv_codec_handle = ps_dec; |
814 | | |
815 | 114k | ps_dec->ps_dpb_mgr->i4_max_frm_num = ps_seq->u2_u4_max_pic_num_minus1 + 1; |
816 | | |
817 | 114k | ps_dec->ps_dpb_mgr->u2_pic_ht = ps_dec->u2_pic_ht; |
818 | 114k | ps_dec->ps_dpb_mgr->u2_pic_wd = ps_dec->u2_pic_wd; |
819 | 114k | ps_dec->i4_pic_type = NA_SLICE; |
820 | 114k | ps_dec->i4_frametype = IV_NA_FRAME; |
821 | 114k | ps_dec->i4_content_type = IV_CONTENTTYPE_NA; |
822 | | |
823 | | /*--------------------------------------------------------------------*/ |
824 | | /* Get the value of MaxMbAddress and frmheight in Mbs */ |
825 | | /*--------------------------------------------------------------------*/ |
826 | 114k | ps_seq->u4_max_mb_addr = |
827 | 114k | ((UWORD32)ps_seq->u2_frm_wd_in_mbs * |
828 | 114k | ((UWORD32)ps_dec->u2_pic_ht >> (4 + ps_dec->ps_cur_slice->u1_field_pic_flag))) - |
829 | 114k | 1; |
830 | 114k | ps_dec->u2_frm_ht_in_mbs = (ps_dec->u2_pic_ht >> (4 + ps_dec->ps_cur_slice->u1_field_pic_flag)); |
831 | | |
832 | | /***************************************************************************/ |
833 | | /* If change in Level or the required PicBuffers i4_size is more than the */ |
834 | | /* current one FREE the current PicBuffers and allocate affresh */ |
835 | | /***************************************************************************/ |
836 | 114k | if(!ps_dec->u1_init_dec_flag) |
837 | 22.4k | { |
838 | 22.4k | ps_dec->u1_max_dec_frame_buffering = ih264d_get_dpb_size(ps_seq); |
839 | | |
840 | 22.4k | ps_dec->i4_display_delay = ps_dec->u1_max_dec_frame_buffering; |
841 | 22.4k | if((1 == ps_seq->u1_vui_parameters_present_flag) && |
842 | 1.57k | (1 == ps_seq->s_vui.u1_bitstream_restriction_flag)) |
843 | 149 | { |
844 | 149 | if(ps_seq->u1_frame_mbs_only_flag == 1) |
845 | 149 | ps_dec->i4_display_delay = ps_seq->s_vui.u4_num_reorder_frames + 1; |
846 | 0 | else |
847 | 0 | ps_dec->i4_display_delay = ps_seq->s_vui.u4_num_reorder_frames * 2 + 2; |
848 | 149 | } |
849 | | |
850 | 22.4k | if(IVD_DECODE_FRAME_OUT == ps_dec->e_frm_out_mode) ps_dec->i4_display_delay = 0; |
851 | | |
852 | 22.4k | if(ps_dec->u4_share_disp_buf == 0) |
853 | 22.4k | { |
854 | 22.4k | if(ps_seq->u1_frame_mbs_only_flag == 1) |
855 | 22.4k | ps_dec->u1_pic_bufs = ps_dec->i4_display_delay + ps_seq->u1_num_ref_frames + 1; |
856 | 0 | else |
857 | 0 | ps_dec->u1_pic_bufs = ps_dec->i4_display_delay + ps_seq->u1_num_ref_frames * 2 + 2; |
858 | 22.4k | } |
859 | 0 | else |
860 | 0 | { |
861 | 0 | ps_dec->u1_pic_bufs = (WORD32) ps_dec->u4_num_disp_bufs; |
862 | 0 | } |
863 | | |
864 | | /* Ensure at least two buffers are allocated */ |
865 | 22.4k | ps_dec->u1_pic_bufs = MAX(ps_dec->u1_pic_bufs, 2); |
866 | | |
867 | 22.4k | if(ps_dec->u4_share_disp_buf == 0) |
868 | 22.4k | ps_dec->u1_pic_bufs = MIN(ps_dec->u1_pic_bufs, (H264_MAX_REF_PICS * 2)); |
869 | | |
870 | 22.4k | ps_dec->u1_max_dec_frame_buffering = |
871 | 22.4k | MIN(ps_dec->u1_max_dec_frame_buffering, ps_dec->u1_pic_bufs); |
872 | | |
873 | | /* Temporary hack to run Tractor Cav/Cab/MbAff Profiler streams also for |
874 | | * CAFI1_SVA_C.264 in conformance*/ |
875 | 22.4k | if(ps_dec->u1_init_dec_flag) |
876 | 0 | { |
877 | 0 | ih264d_release_pics_in_dpb((void *) ps_dec, ps_dec->u1_pic_bufs); |
878 | 0 | ih264d_release_display_bufs(ps_dec); |
879 | 0 | ih264d_reset_ref_bufs(ps_dec->ps_dpb_mgr); |
880 | 0 | } |
881 | | |
882 | | /*********************************************************************/ |
883 | | /* Configuring decoder parameters based on level and then */ |
884 | | /* fresh pointer initialisation in decoder scratch and state buffers */ |
885 | | /*********************************************************************/ |
886 | 22.4k | if(!ps_dec->u1_init_dec_flag || ((ps_seq->u1_level_idc < H264_LEVEL_3_0) ^ |
887 | 0 | (ps_prev_seq_params->u1_level_idc < H264_LEVEL_3_0))) |
888 | 22.4k | { |
889 | 22.4k | ret = ih264d_init_dec_mb_grp(ps_dec); |
890 | 22.4k | if(ret != OK) return ret; |
891 | 22.4k | } |
892 | | |
893 | 22.4k | ret = isvcd_allocate_dynamic_bufs(ps_svc_lyr_dec); |
894 | | |
895 | 22.4k | if(ret != OK) |
896 | 0 | { |
897 | | /* Free any dynamic buffers that are allocated */ |
898 | 0 | isvcd_free_dynamic_bufs(ps_svc_lyr_dec); |
899 | 0 | ps_dec->i4_error_code = IVD_MEM_ALLOC_FAILED; |
900 | 0 | return IVD_MEM_ALLOC_FAILED; |
901 | 0 | } |
902 | | |
903 | 22.4k | ih264d_init_ref_bufs((dpb_manager_t *)ps_dec->ps_dpb_mgr); |
904 | 22.4k | isvcd_init_dpb_ref_bufs(ps_dec); |
905 | | |
906 | 22.4k | ret = ih264d_create_pic_buffers(ps_dec->u1_pic_bufs, ps_dec); |
907 | 22.4k | if(ret != OK) return ret; |
908 | | |
909 | 22.4k | ret = ih264d_create_mv_bank(ps_dec, ps_dec->u2_pic_wd, ps_dec->u2_pic_ht); |
910 | 22.4k | if(ret != OK) return ret; |
911 | | |
912 | | /* In shared mode, set all of them as used by display */ |
913 | 22.4k | if(ps_dec->u4_share_disp_buf == 1) |
914 | 0 | { |
915 | 0 | WORD32 i; |
916 | |
|
917 | 0 | for(i = 0; i < ps_dec->u1_pic_bufs; i++) |
918 | 0 | { |
919 | 0 | ih264_buf_mgr_set_status((buf_mgr_t *) ps_dec->pv_pic_buf_mgr, i, BUF_MGR_IO); |
920 | 0 | } |
921 | 0 | } |
922 | | |
923 | 22.4k | ps_dec->u1_init_dec_flag = 1; |
924 | 22.4k | ps_prev_seq_params->u2_frm_wd_in_mbs = ps_seq->u2_frm_wd_in_mbs; |
925 | 22.4k | ps_prev_seq_params->u1_level_idc = ps_seq->u1_level_idc; |
926 | 22.4k | ps_prev_seq_params->u1_profile_idc = ps_seq->u1_profile_idc; |
927 | 22.4k | ps_prev_seq_params->u2_frm_ht_in_mbs = ps_seq->u2_frm_ht_in_mbs; |
928 | 22.4k | ps_prev_seq_params->u1_frame_mbs_only_flag = ps_seq->u1_frame_mbs_only_flag; |
929 | 22.4k | ps_prev_seq_params->u1_direct_8x8_inference_flag = ps_seq->u1_direct_8x8_inference_flag; |
930 | | |
931 | 22.4k | ps_dec->i4_cur_display_seq = 0; |
932 | 22.4k | ps_dec->i4_prev_max_display_seq = 0; |
933 | 22.4k | ps_dec->i4_max_poc = 0; |
934 | | |
935 | 22.4k | { |
936 | | /* 0th entry of CtxtIncMbMap will be always be containing default values |
937 | | for CABAC context representing MB not available */ |
938 | 22.4k | ctxt_inc_mb_info_t *p_DefCtxt = ps_dec->p_ctxt_inc_mb_map - 1; |
939 | 22.4k | UWORD8 *pu1_temp; |
940 | 22.4k | WORD8 i; |
941 | 22.4k | p_DefCtxt->u1_mb_type = CAB_SKIP; |
942 | | |
943 | 22.4k | p_DefCtxt->u1_cbp = 0x0f; |
944 | 22.4k | p_DefCtxt->u1_intra_chroma_pred_mode = 0; |
945 | | |
946 | 22.4k | p_DefCtxt->u1_yuv_dc_csbp = 0x7; |
947 | | |
948 | 22.4k | p_DefCtxt->u1_transform8x8_ctxt = 0; |
949 | | |
950 | 22.4k | pu1_temp = (UWORD8 *) p_DefCtxt->i1_ref_idx; |
951 | 112k | for(i = 0; i < 4; i++, pu1_temp++) (*pu1_temp) = 0; |
952 | 22.4k | pu1_temp = (UWORD8 *) p_DefCtxt->u1_mv; |
953 | 382k | for(i = 0; i < 16; i++, pu1_temp++) (*pu1_temp) = 0; |
954 | 22.4k | ps_dec->ps_def_ctxt_mb_info = p_DefCtxt; |
955 | 22.4k | } |
956 | 22.4k | } |
957 | | /* reset DBP commands read u4_flag */ |
958 | 114k | ps_dec->ps_dpb_cmds->u1_dpb_commands_read = 0; |
959 | | |
960 | 114k | return OK; |
961 | 114k | } |