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