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 *******************************************************************************
23 * @file
24 * isvcd_api.c
25 *
26 * @brief
27 * Contains all the API related functions
28 *
29 * @author
30 * Kishore
31 *
32 * @par List of Functions:
33 * - api_check_struct_sanity()
34 * - isvcd_set_processor()
35 * - isvcd_init_decoder()
36 * - isvcd_nal_parse_ctxt_free()
37 * - isvcd_residual_resample_ctxt_free()
38 * - isvcd_intra_resample_ctxt_free()
39 * - isvcd_mode_mv_resample_ctxt_free()
40 * - isvcd_free_static_bufs()
41 * - isvcd_nal_parse_ctxt_create()
42 * - isvcd_intra_resample_ctxt_create()
43 * - isvcd_residual_resample_ctxt_create()
44 * - isvcd_mode_mv_resample_ctxt_create()
45 * - isvcd_allocate_static_bufs()
46 * - isvcd_create()
47 * - isvcd_update_dqid()
48 * - isvcd_detect_res_change()
49 * - isvcd_parse_ref_pic_list_modify()
50 * - isvcd_parse_slice_hdr_refdq_id()
51 * - isvcd_get_ref_lyr_dqid()
52 * - isvcd_conceal_node_params()
53 * - isvcd_refine_dep_list()
54 * - isvcd_dec_non_vcl()
55 * - isvcd_seq_hdr_dec()
56 * - isvcd_pre_parse_refine_au()
57 * - isvcd_video_decode()
58 * - isvcd_set_display_frame()
59 * - isvcd_set_flush_mode()
60 * - isvcd_get_status()
61 * - isvcd_get_buf_info()
62 * - isvcd_set_params()
63 * - isvcd_set_target_layer()
64 * - isvcd_set_default_params()
65 * - isvcd_delete()
66 * - isvcd_reset()
67 * - isvcd_ctl()
68 * - isvcd_rel_display_frame()
69 * - isvcd_set_degrade()
70 * - isvcd_get_frame_dimensions()
71 * - isvcd_get_vui_params()
72 * - isvcd_get_sei_mdcv_params()
73 * - isvcd_get_sei_cll_params()
74 * - isvcd_get_sei_ave_params()
75 * - isvcd_get_sei_ccv_params()
76 * - isvcd_set_num_cores()
77 * - isvcd_fill_output_struct_from_context()
78 * - isvcd_api_function()
79 *
80 * @remarks
81 * None
82 *
83 *******************************************************************************
84 */
85
86 #include <string.h>
87 #include <limits.h>
88 #include <stddef.h>
89 #include <assert.h>
90 #include "ih264_defs.h"
91 #include "ih264_typedefs.h"
92 #include "ih264_macros.h"
93 #include "ih264_platform_macros.h"
94 #include "ih264d_tables.h"
95 #include "iv.h"
96 #include "ivd.h"
97 #include "ih264d_defs.h"
98 #include "ih264d_debug.h"
99 #include "ih264_debug.h"
100 #include "ih264d_inter_pred.h"
101 #include "isvcd_structs.h"
102 #include "ih264d_nal.h"
103 #include "ih264d_error_handler.h"
104 #include "ithread.h"
105 #include "ih264d_parse_slice.h"
106 #include "ih264d_function_selector.h"
107 #include "ih264_error.h"
108 #include "ih264_disp_mgr.h"
109 #include "ih264_buf_mgr.h"
110 #include "ih264d_deblocking.h"
111 #include "ih264d_parse_cavlc.h"
112 #include "ih264d_parse_cabac.h"
113 #include "ih264d_process_pslice.h"
114 #include "isvcd_process_epslice.h"
115 #include "ih264d_utils.h"
116 #include "ih264d_api_utils.h"
117 #include "ih264d_format_conv.h"
118 #include "ih264d_parse_headers.h"
119 #include "ih264d_thread_compute_bs.h"
120 #include "isvcd_utils.h"
121 #include "isvcd.h"
122 #include "isvcd_mode_mv_resamp.h"
123 #include "isvcd_parse_headers.h"
124 #include "isvcd_thread_compute_bs.h"
125 #include "isvcd_function_selector.h"
126 /*********************/
127 /* Codec Versioning */
128 /*********************/
129 // Move this to where it is used
130 #define CODEC_NAME "H264VDEC"
131 #define CODEC_RELEASE_TYPE "production"
132 #define CODEC_RELEASE_VER "05.00"
133 #define CODEC_VENDOR "ITTIAM"
134 #define MAXVERSION_STRLEN 511
135 #ifdef ANDROID
136 #define VERSION(version_string, codec_name, codec_release_type, codec_release_ver, codec_vendor) \
137 snprintf(version_string, MAXVERSION_STRLEN, "@(#)Id:%s_%s Ver:%s Released by %s", codec_name, \
138 codec_release_type, codec_release_ver, codec_vendor)
139 #else
140 #define VERSION(version_string, codec_name, codec_release_type, codec_release_ver, codec_vendor) \
141 snprintf(version_string, MAXVERSION_STRLEN, \
142 "@(#)Id:%s_%s Ver:%s Released by %s Build: %s @ %s", codec_name, codec_release_type, \
143 codec_release_ver, codec_vendor, __DATE__, __TIME__)
144 #endif
145
146 #define MIN_IN_BUFS 1
147 #define MIN_OUT_BUFS_420 3
148 #define MIN_OUT_BUFS_422ILE 1
149 #define MIN_OUT_BUFS_RGB565 1
150 #define MIN_OUT_BUFS_420SP 2
151
152 #define NUM_FRAMES_LIMIT_ENABLED 0
153
154 #if NUM_FRAMES_LIMIT_ENABLED
155 #define NUM_FRAMES_LIMIT 10000
156 #else
157 #define NUM_FRAMES_LIMIT 0x7FFFFFFF
158 #endif
159 WORD32 ih264d_get_version(iv_obj_t *dec_hdl, void *pv_api_ip, void *pv_api_op);
160 WORD32 ih264d_parse_sei(dec_struct_t *ps_dec, dec_bit_stream_t *ps_bitstrm);
161 WORD32 check_app_out_buf_size(dec_struct_t *ps_dec);
162 UWORD32 ih264d_get_extra_mem_external(UWORD32 width, UWORD32 height);
163 WORD32 isvcd_get_frame_dimensions(iv_obj_t *dec_hdl, void *pv_api_ip, void *pv_api_op);
164 WORD32 isvcd_get_vui_params(iv_obj_t *dec_hdl, void *pv_api_ip, void *pv_api_op);
165
166 WORD32 isvcd_get_sei_mdcv_params(iv_obj_t *dec_hdl, void *pv_api_ip, void *pv_api_op);
167 WORD32 isvcd_get_sei_cll_params(iv_obj_t *dec_hdl, void *pv_api_ip, void *pv_api_op);
168 WORD32 isvcd_get_sei_ave_params(iv_obj_t *dec_hdl, void *pv_api_ip, void *pv_api_op);
169 WORD32 isvcd_get_sei_ccv_params(iv_obj_t *dec_hdl, void *pv_api_ip, void *pv_api_op);
170 WORD32 isvcd_set_num_cores(iv_obj_t *dec_hdl, void *pv_api_ip, void *pv_api_op);
171
172 WORD32 ih264d_deblock_display(dec_struct_t *ps_dec);
173 WORD32 ih264d_get_display_frame(iv_obj_t *dec_hdl, void *pv_api_ip, void *pv_api_op);
174
175 void ih264d_signal_decode_thread(dec_struct_t *ps_dec);
176
177 void ih264d_signal_bs_deblk_thread(dec_struct_t *ps_dec);
178 void ih264d_decode_picture_thread(dec_struct_t *ps_dec);
179 void isvcd_decode_picture_thread(svc_dec_lyr_struct_t *ps_svc_lyr_dec);
180
181 WORD32 isvcd_set_degrade(iv_obj_t *ps_codec_obj, void *pv_api_ip, void *pv_api_op);
182
183 void isvcd_fill_output_struct_from_context(svc_dec_lyr_struct_t *ps_svc_lyr_dec,
184 ivd_video_decode_op_t *ps_dec_op);
185
api_check_struct_sanity(iv_obj_t * ps_handle,void * pv_api_ip,void * pv_api_op)186 static IV_API_CALL_STATUS_T api_check_struct_sanity(iv_obj_t *ps_handle, void *pv_api_ip,
187 void *pv_api_op)
188 {
189 IVD_API_COMMAND_TYPE_T e_cmd;
190 UWORD32 *pu4_api_ip;
191 UWORD32 *pu4_api_op;
192 UWORD32 i;
193
194 if(NULL == pv_api_op) return (IV_FAIL);
195
196 if(NULL == pv_api_ip) return (IV_FAIL);
197
198 pu4_api_ip = (UWORD32 *) pv_api_ip;
199 pu4_api_op = (UWORD32 *) pv_api_op;
200 e_cmd = *(pu4_api_ip + 1);
201
202 /* error checks on handle */
203 switch((WORD32) e_cmd)
204 {
205 case IVD_CMD_CREATE:
206 break;
207
208 case IVD_CMD_REL_DISPLAY_FRAME:
209 case IVD_CMD_SET_DISPLAY_FRAME:
210 case IVD_CMD_GET_DISPLAY_FRAME:
211 case IVD_CMD_VIDEO_DECODE:
212 case IVD_CMD_DELETE:
213 case IVD_CMD_VIDEO_CTL:
214 if(ps_handle == NULL)
215 {
216 *(pu4_api_op + 1) |= 1 << IVD_UNSUPPORTEDPARAM;
217 *(pu4_api_op + 1) |= IVD_HANDLE_NULL;
218 return IV_FAIL;
219 }
220
221 if(ps_handle->u4_size != sizeof(iv_obj_t))
222 {
223 *(pu4_api_op + 1) |= 1 << IVD_UNSUPPORTEDPARAM;
224 *(pu4_api_op + 1) |= IVD_HANDLE_STRUCT_SIZE_INCORRECT;
225 return IV_FAIL;
226 }
227
228 if(ps_handle->pv_fxns != isvcd_api_function)
229 {
230 *(pu4_api_op + 1) |= 1 << IVD_UNSUPPORTEDPARAM;
231 *(pu4_api_op + 1) |= IVD_INVALID_HANDLE_NULL;
232 return IV_FAIL;
233 }
234
235 if(ps_handle->pv_codec_handle == NULL)
236 {
237 *(pu4_api_op + 1) |= 1 << IVD_UNSUPPORTEDPARAM;
238 *(pu4_api_op + 1) |= IVD_INVALID_HANDLE_NULL;
239 return IV_FAIL;
240 }
241 break;
242 default:
243 *(pu4_api_op + 1) |= 1 << IVD_UNSUPPORTEDPARAM;
244 *(pu4_api_op + 1) |= IVD_INVALID_API_CMD;
245 return IV_FAIL;
246 }
247
248 switch((WORD32) e_cmd)
249 {
250 case IVD_CMD_CREATE:
251 {
252 isvcd_create_ip_t *ps_ip = (isvcd_create_ip_t *) pv_api_ip;
253 isvcd_create_op_t *ps_op = (isvcd_create_op_t *) pv_api_op;
254
255 ps_op->s_ivd_create_op_t.u4_error_code = 0;
256
257 if((ps_ip->s_ivd_create_ip_t.u4_size > sizeof(isvcd_create_ip_t)) ||
258 (ps_ip->s_ivd_create_ip_t.u4_size < sizeof(ivd_create_ip_t)))
259 {
260 ps_op->s_ivd_create_op_t.u4_error_code |= 1 << IVD_UNSUPPORTEDPARAM;
261 ps_op->s_ivd_create_op_t.u4_error_code |= IVD_IP_API_STRUCT_SIZE_INCORRECT;
262 H264_DEC_DEBUG_PRINT("\n");
263 return (IV_FAIL);
264 }
265
266 if((ps_op->s_ivd_create_op_t.u4_size != sizeof(isvcd_create_op_t)) &&
267 (ps_op->s_ivd_create_op_t.u4_size != sizeof(ivd_create_op_t)))
268 {
269 ps_op->s_ivd_create_op_t.u4_error_code |= 1 << IVD_UNSUPPORTEDPARAM;
270 ps_op->s_ivd_create_op_t.u4_error_code |= IVD_OP_API_STRUCT_SIZE_INCORRECT;
271 H264_DEC_DEBUG_PRINT("\n");
272 return (IV_FAIL);
273 }
274
275 if((ps_ip->s_ivd_create_ip_t.e_output_format != IV_YUV_420P) &&
276 (ps_ip->s_ivd_create_ip_t.e_output_format != IV_YUV_422ILE) &&
277 (ps_ip->s_ivd_create_ip_t.e_output_format != IV_RGB_565) &&
278 (ps_ip->s_ivd_create_ip_t.e_output_format != IV_YUV_420SP_UV) &&
279 (ps_ip->s_ivd_create_ip_t.e_output_format != IV_YUV_420SP_VU))
280 {
281 ps_op->s_ivd_create_op_t.u4_error_code |= 1 << IVD_UNSUPPORTEDPARAM;
282 ps_op->s_ivd_create_op_t.u4_error_code |= IVD_INIT_DEC_COL_FMT_NOT_SUPPORTED;
283 H264_DEC_DEBUG_PRINT("\n");
284 return (IV_FAIL);
285 }
286 }
287 break;
288
289 case IVD_CMD_GET_DISPLAY_FRAME:
290 {
291 isvcd_get_display_frame_ip_t *ps_ip = (isvcd_get_display_frame_ip_t *) pv_api_ip;
292 isvcd_get_display_frame_op_t *ps_op = (isvcd_get_display_frame_op_t *) pv_api_op;
293
294 ps_op->s_ivd_get_display_frame_op_t.u4_error_code = 0;
295
296 if((ps_ip->s_ivd_get_display_frame_ip_t.u4_size !=
297 sizeof(isvcd_get_display_frame_ip_t)) &&
298 (ps_ip->s_ivd_get_display_frame_ip_t.u4_size != sizeof(ivd_get_display_frame_ip_t)))
299 {
300 ps_op->s_ivd_get_display_frame_op_t.u4_error_code |= 1 << IVD_UNSUPPORTEDPARAM;
301 ps_op->s_ivd_get_display_frame_op_t.u4_error_code |=
302 IVD_IP_API_STRUCT_SIZE_INCORRECT;
303 return (IV_FAIL);
304 }
305
306 if((ps_op->s_ivd_get_display_frame_op_t.u4_size !=
307 sizeof(isvcd_get_display_frame_op_t)) &&
308 (ps_op->s_ivd_get_display_frame_op_t.u4_size != sizeof(ivd_get_display_frame_op_t)))
309 {
310 ps_op->s_ivd_get_display_frame_op_t.u4_error_code |= 1 << IVD_UNSUPPORTEDPARAM;
311 ps_op->s_ivd_get_display_frame_op_t.u4_error_code |=
312 IVD_OP_API_STRUCT_SIZE_INCORRECT;
313 return (IV_FAIL);
314 }
315 }
316 break;
317
318 case IVD_CMD_REL_DISPLAY_FRAME:
319 {
320 isvcd_rel_display_frame_ip_t *ps_ip = (isvcd_rel_display_frame_ip_t *) pv_api_ip;
321 isvcd_rel_display_frame_op_t *ps_op = (isvcd_rel_display_frame_op_t *) pv_api_op;
322
323 ps_op->s_ivd_rel_display_frame_op_t.u4_error_code = 0;
324
325 if((ps_ip->s_ivd_rel_display_frame_ip_t.u4_size !=
326 sizeof(isvcd_rel_display_frame_ip_t)) &&
327 (ps_ip->s_ivd_rel_display_frame_ip_t.u4_size != sizeof(ivd_rel_display_frame_ip_t)))
328 {
329 ps_op->s_ivd_rel_display_frame_op_t.u4_error_code |= 1 << IVD_UNSUPPORTEDPARAM;
330 ps_op->s_ivd_rel_display_frame_op_t.u4_error_code |=
331 IVD_IP_API_STRUCT_SIZE_INCORRECT;
332 return (IV_FAIL);
333 }
334
335 if((ps_op->s_ivd_rel_display_frame_op_t.u4_size !=
336 sizeof(isvcd_rel_display_frame_op_t)) &&
337 (ps_op->s_ivd_rel_display_frame_op_t.u4_size != sizeof(ivd_rel_display_frame_op_t)))
338 {
339 ps_op->s_ivd_rel_display_frame_op_t.u4_error_code |= 1 << IVD_UNSUPPORTEDPARAM;
340 ps_op->s_ivd_rel_display_frame_op_t.u4_error_code |=
341 IVD_OP_API_STRUCT_SIZE_INCORRECT;
342 return (IV_FAIL);
343 }
344 }
345 break;
346
347 case IVD_CMD_SET_DISPLAY_FRAME:
348 {
349 isvcd_set_display_frame_ip_t *ps_ip = (isvcd_set_display_frame_ip_t *) pv_api_ip;
350 isvcd_set_display_frame_op_t *ps_op = (isvcd_set_display_frame_op_t *) pv_api_op;
351 UWORD32 j;
352
353 ps_op->s_ivd_set_display_frame_op_t.u4_error_code = 0;
354
355 if((ps_ip->s_ivd_set_display_frame_ip_t.u4_size !=
356 sizeof(isvcd_set_display_frame_ip_t)) &&
357 (ps_ip->s_ivd_set_display_frame_ip_t.u4_size != sizeof(ivd_set_display_frame_ip_t)))
358 {
359 ps_op->s_ivd_set_display_frame_op_t.u4_error_code |= 1 << IVD_UNSUPPORTEDPARAM;
360 ps_op->s_ivd_set_display_frame_op_t.u4_error_code |=
361 IVD_IP_API_STRUCT_SIZE_INCORRECT;
362 return (IV_FAIL);
363 }
364
365 if((ps_op->s_ivd_set_display_frame_op_t.u4_size !=
366 sizeof(isvcd_set_display_frame_op_t)) &&
367 (ps_op->s_ivd_set_display_frame_op_t.u4_size != sizeof(ivd_set_display_frame_op_t)))
368 {
369 ps_op->s_ivd_set_display_frame_op_t.u4_error_code |= 1 << IVD_UNSUPPORTEDPARAM;
370 ps_op->s_ivd_set_display_frame_op_t.u4_error_code |=
371 IVD_OP_API_STRUCT_SIZE_INCORRECT;
372 return (IV_FAIL);
373 }
374
375 if(ps_ip->s_ivd_set_display_frame_ip_t.num_disp_bufs == 0)
376 {
377 ps_op->s_ivd_set_display_frame_op_t.u4_error_code |= 1 << IVD_UNSUPPORTEDPARAM;
378 ps_op->s_ivd_set_display_frame_op_t.u4_error_code |= IVD_DISP_FRM_ZERO_OP_BUFS;
379 return IV_FAIL;
380 }
381
382 for(j = 0; j < ps_ip->s_ivd_set_display_frame_ip_t.num_disp_bufs; j++)
383 {
384 if(ps_ip->s_ivd_set_display_frame_ip_t.s_disp_buffer[j].u4_num_bufs == 0)
385 {
386 ps_op->s_ivd_set_display_frame_op_t.u4_error_code |= 1 << IVD_UNSUPPORTEDPARAM;
387 ps_op->s_ivd_set_display_frame_op_t.u4_error_code |= IVD_DISP_FRM_ZERO_OP_BUFS;
388 return IV_FAIL;
389 }
390
391 for(i = 0; i < ps_ip->s_ivd_set_display_frame_ip_t.s_disp_buffer[j].u4_num_bufs;
392 i++)
393 {
394 if(ps_ip->s_ivd_set_display_frame_ip_t.s_disp_buffer[j].pu1_bufs[i] == NULL)
395 {
396 ps_op->s_ivd_set_display_frame_op_t.u4_error_code |=
397 1 << IVD_UNSUPPORTEDPARAM;
398 ps_op->s_ivd_set_display_frame_op_t.u4_error_code |=
399 IVD_DISP_FRM_OP_BUF_NULL;
400 return IV_FAIL;
401 }
402
403 if(ps_ip->s_ivd_set_display_frame_ip_t.s_disp_buffer[j]
404 .u4_min_out_buf_size[i] == 0)
405 {
406 ps_op->s_ivd_set_display_frame_op_t.u4_error_code |=
407 1 << IVD_UNSUPPORTEDPARAM;
408 ps_op->s_ivd_set_display_frame_op_t.u4_error_code |=
409 IVD_DISP_FRM_ZERO_OP_BUF_SIZE;
410 return IV_FAIL;
411 }
412 }
413 }
414 }
415 break;
416
417 case IVD_CMD_VIDEO_DECODE:
418 {
419 isvcd_video_decode_ip_t *ps_ip = (isvcd_video_decode_ip_t *) pv_api_ip;
420 isvcd_video_decode_op_t *ps_op = (isvcd_video_decode_op_t *) pv_api_op;
421
422 H264_DEC_DEBUG_PRINT("The input bytes is: %d",
423 ps_ip->s_ivd_video_decode_ip_t.u4_num_Bytes);
424 ps_op->s_ivd_video_decode_op_t.u4_error_code = 0;
425
426 if(ps_ip->s_ivd_video_decode_ip_t.u4_size != sizeof(isvcd_video_decode_ip_t) &&
427 ps_ip->s_ivd_video_decode_ip_t.u4_size !=
428 offsetof(ivd_video_decode_ip_t, s_out_buffer))
429 {
430 ps_op->s_ivd_video_decode_op_t.u4_error_code |= 1 << IVD_UNSUPPORTEDPARAM;
431 ps_op->s_ivd_video_decode_op_t.u4_error_code |= IVD_IP_API_STRUCT_SIZE_INCORRECT;
432 return (IV_FAIL);
433 }
434
435 if(ps_op->s_ivd_video_decode_op_t.u4_size != sizeof(isvcd_video_decode_op_t) &&
436 ps_op->s_ivd_video_decode_op_t.u4_size !=
437 offsetof(ivd_video_decode_op_t, u4_output_present))
438 {
439 ps_op->s_ivd_video_decode_op_t.u4_error_code |= 1 << IVD_UNSUPPORTEDPARAM;
440 ps_op->s_ivd_video_decode_op_t.u4_error_code |= IVD_OP_API_STRUCT_SIZE_INCORRECT;
441 return (IV_FAIL);
442 }
443 {
444 svc_dec_ctxt_t *ps_svcd_ctxt;
445 svc_dec_lyr_struct_t *ps_svc_lyr_dec;
446 dec_struct_t *ps_dec;
447 ps_svcd_ctxt = (svc_dec_ctxt_t *) (ps_handle->pv_codec_handle);
448 ps_svc_lyr_dec = &ps_svcd_ctxt->ps_svc_dec_lyr[0];
449 ps_dec = &ps_svc_lyr_dec->s_dec;
450 if(ps_dec->u1_enable_mb_info)
451 {
452 if(!ps_ip->pu1_8x8_blk_qp_map && !ps_ip->pu1_8x8_blk_type_map)
453 {
454 ps_op->s_ivd_video_decode_op_t.u4_error_code |= 1 << IVD_UNSUPPORTEDPARAM;
455 ps_op->s_ivd_video_decode_op_t.u4_error_code |=
456 IH264D_FRAME_INFO_OP_BUF_NULL;
457 return IV_FAIL;
458 }
459 }
460 }
461 }
462 break;
463
464 case IVD_CMD_DELETE:
465 {
466 isvcd_delete_ip_t *ps_ip = (isvcd_delete_ip_t *) pv_api_ip;
467 isvcd_delete_op_t *ps_op = (isvcd_delete_op_t *) pv_api_op;
468
469 ps_op->s_ivd_delete_op_t.u4_error_code = 0;
470
471 if(ps_ip->s_ivd_delete_ip_t.u4_size != sizeof(isvcd_delete_ip_t))
472 {
473 ps_op->s_ivd_delete_op_t.u4_error_code |= 1 << IVD_UNSUPPORTEDPARAM;
474 ps_op->s_ivd_delete_op_t.u4_error_code |= IVD_IP_API_STRUCT_SIZE_INCORRECT;
475 return (IV_FAIL);
476 }
477
478 if(ps_op->s_ivd_delete_op_t.u4_size != sizeof(isvcd_delete_op_t))
479 {
480 ps_op->s_ivd_delete_op_t.u4_error_code |= 1 << IVD_UNSUPPORTEDPARAM;
481 ps_op->s_ivd_delete_op_t.u4_error_code |= IVD_OP_API_STRUCT_SIZE_INCORRECT;
482 return (IV_FAIL);
483 }
484 }
485 break;
486
487 case IVD_CMD_VIDEO_CTL:
488 {
489 UWORD32 *pu4_ptr_cmd;
490 UWORD32 sub_command;
491
492 pu4_ptr_cmd = (UWORD32 *) pv_api_ip;
493 pu4_ptr_cmd += 2;
494 sub_command = *pu4_ptr_cmd;
495
496 switch(sub_command)
497 {
498 case IVD_CMD_CTL_SETPARAMS:
499 {
500 isvcd_ctl_set_config_ip_t *ps_ip;
501 isvcd_ctl_set_config_op_t *ps_op;
502 ps_ip = (isvcd_ctl_set_config_ip_t *) pv_api_ip;
503 ps_op = (isvcd_ctl_set_config_op_t *) pv_api_op;
504
505 if(ps_ip->s_ivd_ctl_set_config_ip_t.u4_size !=
506 sizeof(isvcd_ctl_set_config_ip_t))
507 {
508 ps_op->s_ivd_ctl_set_config_op_t.u4_error_code |= 1 << IVD_UNSUPPORTEDPARAM;
509 ps_op->s_ivd_ctl_set_config_op_t.u4_error_code |=
510 IVD_IP_API_STRUCT_SIZE_INCORRECT;
511 return IV_FAIL;
512 }
513 }
514 break;
515
516 case IVD_CMD_CTL_SETDEFAULT:
517 {
518 isvcd_ctl_set_config_op_t *ps_op;
519 ps_op = (isvcd_ctl_set_config_op_t *) pv_api_op;
520 if(ps_op->s_ivd_ctl_set_config_op_t.u4_size !=
521 sizeof(isvcd_ctl_set_config_op_t))
522 {
523 ps_op->s_ivd_ctl_set_config_op_t.u4_error_code |= 1 << IVD_UNSUPPORTEDPARAM;
524 ps_op->s_ivd_ctl_set_config_op_t.u4_error_code |=
525 IVD_OP_API_STRUCT_SIZE_INCORRECT;
526 return IV_FAIL;
527 }
528 }
529 break;
530
531 case IVD_CMD_CTL_GETPARAMS:
532 {
533 isvcd_ctl_getstatus_ip_t *ps_ip;
534 isvcd_ctl_getstatus_op_t *ps_op;
535
536 ps_ip = (isvcd_ctl_getstatus_ip_t *) pv_api_ip;
537 ps_op = (isvcd_ctl_getstatus_op_t *) pv_api_op;
538 if(ps_ip->s_ivd_ctl_getstatus_ip_t.u4_size != sizeof(isvcd_ctl_getstatus_ip_t))
539 {
540 ps_op->s_ivd_ctl_getstatus_op_t.u4_error_code |= 1 << IVD_UNSUPPORTEDPARAM;
541 ps_op->s_ivd_ctl_getstatus_op_t.u4_error_code |=
542 IVD_IP_API_STRUCT_SIZE_INCORRECT;
543 return IV_FAIL;
544 }
545 if(ps_op->s_ivd_ctl_getstatus_op_t.u4_size != sizeof(isvcd_ctl_getstatus_op_t))
546 {
547 ps_op->s_ivd_ctl_getstatus_op_t.u4_error_code |= 1 << IVD_UNSUPPORTEDPARAM;
548 ps_op->s_ivd_ctl_getstatus_op_t.u4_error_code |=
549 IVD_OP_API_STRUCT_SIZE_INCORRECT;
550 return IV_FAIL;
551 }
552 }
553 break;
554
555 case IVD_CMD_CTL_GETBUFINFO:
556 {
557 isvcd_ctl_getbufinfo_ip_t *ps_ip;
558 isvcd_ctl_getbufinfo_op_t *ps_op;
559 ps_ip = (isvcd_ctl_getbufinfo_ip_t *) pv_api_ip;
560 ps_op = (isvcd_ctl_getbufinfo_op_t *) pv_api_op;
561
562 if(ps_ip->s_ivd_ctl_getbufinfo_ip_t.u4_size !=
563 sizeof(isvcd_ctl_getbufinfo_ip_t))
564 {
565 ps_op->s_ivd_ctl_getbufinfo_op_t.u4_error_code |= 1 << IVD_UNSUPPORTEDPARAM;
566 ps_op->s_ivd_ctl_getbufinfo_op_t.u4_error_code |=
567 IVD_IP_API_STRUCT_SIZE_INCORRECT;
568 return IV_FAIL;
569 }
570 if(ps_op->s_ivd_ctl_getbufinfo_op_t.u4_size !=
571 sizeof(isvcd_ctl_getbufinfo_op_t))
572 {
573 ps_op->s_ivd_ctl_getbufinfo_op_t.u4_error_code |= 1 << IVD_UNSUPPORTEDPARAM;
574 ps_op->s_ivd_ctl_getbufinfo_op_t.u4_error_code |=
575 IVD_OP_API_STRUCT_SIZE_INCORRECT;
576 return IV_FAIL;
577 }
578 }
579 break;
580
581 case IVD_CMD_CTL_GETVERSION:
582 {
583 isvcd_ctl_getversioninfo_ip_t *ps_ip;
584 isvcd_ctl_getversioninfo_op_t *ps_op;
585 ps_ip = (isvcd_ctl_getversioninfo_ip_t *) pv_api_ip;
586 ps_op = (isvcd_ctl_getversioninfo_op_t *) pv_api_op;
587 if(ps_ip->s_ivd_ctl_getversioninfo_ip_t.u4_size !=
588 sizeof(isvcd_ctl_getversioninfo_ip_t))
589 {
590 ps_op->s_ivd_ctl_getversioninfo_op_t.u4_error_code |=
591 1 << IVD_UNSUPPORTEDPARAM;
592 ps_op->s_ivd_ctl_getversioninfo_op_t.u4_error_code |=
593 IVD_IP_API_STRUCT_SIZE_INCORRECT;
594 return IV_FAIL;
595 }
596 if(ps_op->s_ivd_ctl_getversioninfo_op_t.u4_size !=
597 sizeof(isvcd_ctl_getversioninfo_op_t))
598 {
599 ps_op->s_ivd_ctl_getversioninfo_op_t.u4_error_code |=
600 1 << IVD_UNSUPPORTEDPARAM;
601 ps_op->s_ivd_ctl_getversioninfo_op_t.u4_error_code |=
602 IVD_OP_API_STRUCT_SIZE_INCORRECT;
603 return IV_FAIL;
604 }
605 }
606 break;
607
608 case IVD_CMD_CTL_FLUSH:
609 {
610 isvcd_ctl_flush_ip_t *ps_ip;
611 isvcd_ctl_flush_op_t *ps_op;
612 ps_ip = (isvcd_ctl_flush_ip_t *) pv_api_ip;
613 ps_op = (isvcd_ctl_flush_op_t *) pv_api_op;
614 if(ps_ip->s_ivd_ctl_flush_ip_t.u4_size != sizeof(isvcd_ctl_flush_ip_t))
615 {
616 ps_op->s_ivd_ctl_flush_op_t.u4_error_code |= 1 << IVD_UNSUPPORTEDPARAM;
617 ps_op->s_ivd_ctl_flush_op_t.u4_error_code |=
618 IVD_IP_API_STRUCT_SIZE_INCORRECT;
619 return IV_FAIL;
620 }
621 if(ps_op->s_ivd_ctl_flush_op_t.u4_size != sizeof(isvcd_ctl_flush_op_t))
622 {
623 ps_op->s_ivd_ctl_flush_op_t.u4_error_code |= 1 << IVD_UNSUPPORTEDPARAM;
624 ps_op->s_ivd_ctl_flush_op_t.u4_error_code |=
625 IVD_OP_API_STRUCT_SIZE_INCORRECT;
626 return IV_FAIL;
627 }
628 }
629 break;
630
631 case IVD_CMD_CTL_RESET:
632 {
633 isvcd_ctl_reset_ip_t *ps_ip;
634 isvcd_ctl_reset_op_t *ps_op;
635 ps_ip = (isvcd_ctl_reset_ip_t *) pv_api_ip;
636 ps_op = (isvcd_ctl_reset_op_t *) pv_api_op;
637 if(ps_ip->s_ivd_ctl_reset_ip_t.u4_size != sizeof(isvcd_ctl_reset_ip_t))
638 {
639 ps_op->s_ivd_ctl_reset_op_t.u4_error_code |= 1 << IVD_UNSUPPORTEDPARAM;
640 ps_op->s_ivd_ctl_reset_op_t.u4_error_code |=
641 IVD_IP_API_STRUCT_SIZE_INCORRECT;
642 return IV_FAIL;
643 }
644 if(ps_op->s_ivd_ctl_reset_op_t.u4_size != sizeof(isvcd_ctl_reset_op_t))
645 {
646 ps_op->s_ivd_ctl_reset_op_t.u4_error_code |= 1 << IVD_UNSUPPORTEDPARAM;
647 ps_op->s_ivd_ctl_reset_op_t.u4_error_code |=
648 IVD_OP_API_STRUCT_SIZE_INCORRECT;
649 return IV_FAIL;
650 }
651 }
652 break;
653
654 case IH264D_CMD_CTL_DEGRADE:
655 {
656 isvcd_ctl_degrade_ip_t *ps_ip;
657 isvcd_ctl_degrade_op_t *ps_op;
658
659 ps_ip = (isvcd_ctl_degrade_ip_t *) pv_api_ip;
660 ps_op = (isvcd_ctl_degrade_op_t *) pv_api_op;
661
662 if(ps_ip->u4_size != sizeof(isvcd_ctl_degrade_ip_t))
663 {
664 ps_op->u4_error_code |= 1 << IVD_UNSUPPORTEDPARAM;
665 ps_op->u4_error_code |= IVD_IP_API_STRUCT_SIZE_INCORRECT;
666 return IV_FAIL;
667 }
668
669 if(ps_op->u4_size != sizeof(isvcd_ctl_degrade_op_t))
670 {
671 ps_op->u4_error_code |= 1 << IVD_UNSUPPORTEDPARAM;
672 ps_op->u4_error_code |= IVD_OP_API_STRUCT_SIZE_INCORRECT;
673 return IV_FAIL;
674 }
675
676 if((ps_ip->i4_degrade_pics < 0) || (ps_ip->i4_degrade_pics > 4) ||
677 (ps_ip->i4_nondegrade_interval < 0) || (ps_ip->i4_degrade_type < 0) ||
678 (ps_ip->i4_degrade_type > 15))
679 {
680 ps_op->u4_error_code |= 1 << IVD_UNSUPPORTEDPARAM;
681 return IV_FAIL;
682 }
683
684 break;
685 }
686
687 case IH264D_CMD_CTL_GET_BUFFER_DIMENSIONS:
688 {
689 isvcd_ctl_get_frame_dimensions_ip_t *ps_ip;
690 isvcd_ctl_get_frame_dimensions_op_t *ps_op;
691
692 ps_ip = (isvcd_ctl_get_frame_dimensions_ip_t *) pv_api_ip;
693 ps_op = (isvcd_ctl_get_frame_dimensions_op_t *) pv_api_op;
694
695 if(ps_ip->u4_size != sizeof(isvcd_ctl_get_frame_dimensions_ip_t))
696 {
697 ps_op->u4_error_code |= 1 << IVD_UNSUPPORTEDPARAM;
698 ps_op->u4_error_code |= IVD_IP_API_STRUCT_SIZE_INCORRECT;
699 return IV_FAIL;
700 }
701
702 if(ps_op->u4_size != sizeof(isvcd_ctl_get_frame_dimensions_op_t))
703 {
704 ps_op->u4_error_code |= 1 << IVD_UNSUPPORTEDPARAM;
705 ps_op->u4_error_code |= IVD_OP_API_STRUCT_SIZE_INCORRECT;
706 return IV_FAIL;
707 }
708
709 break;
710 }
711 case IH264D_CMD_CTL_GET_VUI_PARAMS:
712 {
713 isvcd_ctl_get_vui_params_ip_t *ps_ip;
714 isvcd_ctl_get_vui_params_op_t *ps_op;
715
716 ps_ip = (isvcd_ctl_get_vui_params_ip_t *) pv_api_ip;
717 ps_op = (isvcd_ctl_get_vui_params_op_t *) pv_api_op;
718
719 if(ps_ip->u4_size != sizeof(isvcd_ctl_get_vui_params_ip_t))
720 {
721 ps_op->u4_error_code |= 1 << IVD_UNSUPPORTEDPARAM;
722 ps_op->u4_error_code |= IVD_IP_API_STRUCT_SIZE_INCORRECT;
723 return IV_FAIL;
724 }
725
726 if(ps_op->u4_size != sizeof(isvcd_ctl_get_vui_params_op_t))
727 {
728 ps_op->u4_error_code |= 1 << IVD_UNSUPPORTEDPARAM;
729 ps_op->u4_error_code |= IVD_OP_API_STRUCT_SIZE_INCORRECT;
730 return IV_FAIL;
731 }
732
733 break;
734 }
735 case IH264D_CMD_CTL_GET_SEI_MDCV_PARAMS:
736 {
737 isvcd_ctl_get_sei_mdcv_params_ip_t *ps_ip;
738 isvcd_ctl_get_sei_mdcv_params_op_t *ps_op;
739
740 ps_ip = (isvcd_ctl_get_sei_mdcv_params_ip_t *) pv_api_ip;
741 ps_op = (isvcd_ctl_get_sei_mdcv_params_op_t *) pv_api_op;
742
743 if(ps_ip->u4_size != sizeof(isvcd_ctl_get_sei_mdcv_params_ip_t))
744 {
745 ps_op->u4_error_code |= 1 << IVD_UNSUPPORTEDPARAM;
746 ps_op->u4_error_code |= IVD_IP_API_STRUCT_SIZE_INCORRECT;
747 return IV_FAIL;
748 }
749
750 if(ps_op->u4_size != sizeof(isvcd_ctl_get_sei_mdcv_params_op_t))
751 {
752 ps_op->u4_error_code |= 1 << IVD_UNSUPPORTEDPARAM;
753 ps_op->u4_error_code |= IVD_OP_API_STRUCT_SIZE_INCORRECT;
754 return IV_FAIL;
755 }
756
757 break;
758 }
759
760 case IH264D_CMD_CTL_GET_SEI_CLL_PARAMS:
761 {
762 isvcd_ctl_get_sei_cll_params_ip_t *ps_ip;
763 isvcd_ctl_get_sei_cll_params_op_t *ps_op;
764
765 ps_ip = (isvcd_ctl_get_sei_cll_params_ip_t *) pv_api_ip;
766 ps_op = (isvcd_ctl_get_sei_cll_params_op_t *) pv_api_op;
767
768 if(ps_ip->u4_size != sizeof(isvcd_ctl_get_sei_cll_params_ip_t))
769 {
770 ps_op->u4_error_code |= 1 << IVD_UNSUPPORTEDPARAM;
771 ps_op->u4_error_code |= IVD_IP_API_STRUCT_SIZE_INCORRECT;
772 return IV_FAIL;
773 }
774
775 if(ps_op->u4_size != sizeof(isvcd_ctl_get_sei_cll_params_op_t))
776 {
777 ps_op->u4_error_code |= 1 << IVD_UNSUPPORTEDPARAM;
778 ps_op->u4_error_code |= IVD_OP_API_STRUCT_SIZE_INCORRECT;
779 return IV_FAIL;
780 }
781
782 break;
783 }
784
785 case IH264D_CMD_CTL_GET_SEI_AVE_PARAMS:
786 {
787 isvcd_ctl_get_sei_ave_params_ip_t *ps_ip;
788 isvcd_ctl_get_sei_ave_params_op_t *ps_op;
789
790 ps_ip = (isvcd_ctl_get_sei_ave_params_ip_t *) pv_api_ip;
791 ps_op = (isvcd_ctl_get_sei_ave_params_op_t *) pv_api_op;
792
793 if(ps_ip->u4_size != sizeof(isvcd_ctl_get_sei_ave_params_ip_t))
794 {
795 ps_op->u4_error_code |= 1 << IVD_UNSUPPORTEDPARAM;
796 ps_op->u4_error_code |= IVD_IP_API_STRUCT_SIZE_INCORRECT;
797 return IV_FAIL;
798 }
799
800 if(ps_op->u4_size != sizeof(isvcd_ctl_get_sei_ave_params_op_t))
801 {
802 ps_op->u4_error_code |= 1 << IVD_UNSUPPORTEDPARAM;
803 ps_op->u4_error_code |= IVD_OP_API_STRUCT_SIZE_INCORRECT;
804 return IV_FAIL;
805 }
806
807 break;
808 }
809
810 case IH264D_CMD_CTL_GET_SEI_CCV_PARAMS:
811 {
812 isvcd_ctl_get_sei_ccv_params_ip_t *ps_ip;
813 isvcd_ctl_get_sei_ccv_params_op_t *ps_op;
814
815 ps_ip = (isvcd_ctl_get_sei_ccv_params_ip_t *) pv_api_ip;
816 ps_op = (isvcd_ctl_get_sei_ccv_params_op_t *) pv_api_op;
817
818 if(ps_ip->u4_size != sizeof(isvcd_ctl_get_sei_ccv_params_ip_t))
819 {
820 ps_op->u4_error_code |= 1 << IVD_UNSUPPORTEDPARAM;
821 ps_op->u4_error_code |= IVD_IP_API_STRUCT_SIZE_INCORRECT;
822 return IV_FAIL;
823 }
824
825 if(ps_op->u4_size != sizeof(isvcd_ctl_get_sei_ccv_params_op_t))
826 {
827 ps_op->u4_error_code |= 1 << IVD_UNSUPPORTEDPARAM;
828 ps_op->u4_error_code |= IVD_OP_API_STRUCT_SIZE_INCORRECT;
829 return IV_FAIL;
830 }
831
832 break;
833 }
834
835 case IH264D_CMD_CTL_SET_NUM_CORES:
836 {
837 isvcd_ctl_set_num_cores_ip_t *ps_ip;
838 isvcd_ctl_set_num_cores_op_t *ps_op;
839
840 ps_ip = (isvcd_ctl_set_num_cores_ip_t *) pv_api_ip;
841 ps_op = (isvcd_ctl_set_num_cores_op_t *) pv_api_op;
842
843 if(ps_ip->u4_size != sizeof(isvcd_ctl_set_num_cores_ip_t))
844 {
845 ps_op->u4_error_code |= 1 << IVD_UNSUPPORTEDPARAM;
846 ps_op->u4_error_code |= IVD_IP_API_STRUCT_SIZE_INCORRECT;
847 return IV_FAIL;
848 }
849
850 if(ps_op->u4_size != sizeof(isvcd_ctl_set_num_cores_op_t))
851 {
852 ps_op->u4_error_code |= 1 << IVD_UNSUPPORTEDPARAM;
853 ps_op->u4_error_code |= IVD_OP_API_STRUCT_SIZE_INCORRECT;
854 return IV_FAIL;
855 }
856
857 if((ps_ip->u4_num_cores != 1) && (ps_ip->u4_num_cores != 2) &&
858 (ps_ip->u4_num_cores != 3) && (ps_ip->u4_num_cores != 4))
859 {
860 ps_op->u4_error_code |= 1 << IVD_UNSUPPORTEDPARAM;
861 return IV_FAIL;
862 }
863 break;
864 }
865 case IH264D_CMD_CTL_SET_PROCESSOR:
866 {
867 isvcd_ctl_set_processor_ip_t *ps_ip;
868 isvcd_ctl_set_processor_op_t *ps_op;
869
870 ps_ip = (isvcd_ctl_set_processor_ip_t *) pv_api_ip;
871 ps_op = (isvcd_ctl_set_processor_op_t *) pv_api_op;
872
873 if(ps_ip->u4_size != sizeof(isvcd_ctl_set_processor_ip_t))
874 {
875 ps_op->u4_error_code |= 1 << IVD_UNSUPPORTEDPARAM;
876 ps_op->u4_error_code |= IVD_IP_API_STRUCT_SIZE_INCORRECT;
877 return IV_FAIL;
878 }
879
880 if(ps_op->u4_size != sizeof(isvcd_ctl_set_processor_op_t))
881 {
882 ps_op->u4_error_code |= 1 << IVD_UNSUPPORTEDPARAM;
883 ps_op->u4_error_code |= IVD_OP_API_STRUCT_SIZE_INCORRECT;
884 return IV_FAIL;
885 }
886
887 break;
888 }
889
890 case ISVCD_CMD_CTL_SET_TGT_LAYER:
891 {
892 isvcd_set_target_layer_ip_t *ps_ip;
893 isvcd_set_target_layer_op_t *ps_op;
894
895 ps_ip = (isvcd_set_target_layer_ip_t *) pv_api_ip;
896 ps_op = (isvcd_set_target_layer_op_t *) pv_api_op;
897
898 if(ps_ip->u4_size != sizeof(isvcd_set_target_layer_ip_t))
899 {
900 ps_op->u4_error_code |= 1 << IVD_UNSUPPORTEDPARAM;
901 ps_op->u4_error_code |= IVD_IP_API_STRUCT_SIZE_INCORRECT;
902 return IV_FAIL;
903 }
904
905 if(ps_ip->u1_tgt_dep_id > MAX_DEPENDENCY_ID)
906 {
907 ps_op->u4_error_code |= 1 << IVD_UNSUPPORTEDPARAM;
908 return IV_FAIL;
909 }
910
911 if(ps_ip->u1_tgt_temp_id > MAX_TEMPORAL_ID)
912 {
913 ps_op->u4_error_code |= 1 << IVD_UNSUPPORTEDPARAM;
914 return IV_FAIL;
915 }
916
917 if(ps_ip->u1_tgt_quality_id > MAX_QUALITY_ID)
918 {
919 ps_op->u4_error_code |= 1 << IVD_UNSUPPORTEDPARAM;
920 return IV_FAIL;
921 }
922
923 if(ps_ip->u1_tgt_priority_id > MAX_PRIORITY_ID)
924 {
925 ps_op->u4_error_code |= 1 << IVD_UNSUPPORTEDPARAM;
926 return IV_FAIL;
927 }
928
929 if(ps_op->u4_size != sizeof(isvcd_set_target_layer_op_t))
930 {
931 ps_op->u4_error_code |= 1 << IVD_UNSUPPORTEDPARAM;
932 ps_op->u4_error_code |= IVD_OP_API_STRUCT_SIZE_INCORRECT;
933 return IV_FAIL;
934 }
935
936 break;
937 }
938
939 default:
940 *(pu4_api_op + 1) |= 1 << IVD_UNSUPPORTEDPARAM;
941 *(pu4_api_op + 1) |= IVD_UNSUPPORTED_API_CMD;
942 return IV_FAIL;
943 break;
944 }
945 }
946 break;
947 }
948
949 return IV_SUCCESS;
950 }
951
952 /**
953 *******************************************************************************
954 *
955 * @brief
956 * Sets Processor type
957 *
958 * @par Description:
959 * Sets Processor type
960 *
961 * @param[in] ps_codec_obj
962 * Pointer to codec object at API level
963 *
964 * @param[in] pv_api_ip
965 * Pointer to input argument structure
966 *
967 * @param[out] pv_api_op
968 * Pointer to output argument structure
969 *
970 * @returns Status
971 *
972 * @remarks
973 *
974 *
975 *******************************************************************************
976 */
977
isvcd_set_processor(iv_obj_t * dec_hdl,void * pv_api_ip,void * pv_api_op)978 WORD32 isvcd_set_processor(iv_obj_t *dec_hdl, void *pv_api_ip, void *pv_api_op)
979 {
980 isvcd_ctl_set_processor_ip_t *ps_ip;
981 isvcd_ctl_set_processor_op_t *ps_op;
982 UWORD8 u1_layer_id;
983 svc_dec_lyr_struct_t *ps_codec;
984 svc_dec_ctxt_t *ps_svcd_ctxt;
985 ps_svcd_ctxt = (svc_dec_ctxt_t *) dec_hdl->pv_codec_handle;
986
987 ps_ip = (isvcd_ctl_set_processor_ip_t *) pv_api_ip;
988 ps_op = (isvcd_ctl_set_processor_op_t *) pv_api_op;
989
990 ps_svcd_ctxt->e_processor_arch = (IVD_ARCH_T) ps_ip->u4_arch;
991 ps_svcd_ctxt->e_processor_soc = (IVD_SOC_T) ps_ip->u4_soc;
992
993 for(u1_layer_id = 0; u1_layer_id < MAX_NUM_RES_LYRS; u1_layer_id++)
994 {
995 ps_codec = &ps_svcd_ctxt->ps_svc_dec_lyr[u1_layer_id];
996 ps_codec->s_dec.e_processor_arch = (IVD_ARCH_T) ps_ip->u4_arch;
997 ps_codec->s_dec.e_processor_soc = (IVD_SOC_T) ps_ip->u4_soc;
998
999 isvcd_init_function_ptr(ps_codec);
1000 }
1001
1002 ps_op->u4_error_code = 0;
1003 return IV_SUCCESS;
1004 }
1005
1006 /**************************************************************************
1007 * \if Function name : isvcd_init_decoder \endif
1008 *
1009 *
1010 * \brief
1011 * Initializes the decoder
1012 *
1013 * \param apiVersion : Version of the api being used.
1014 * \param errorHandlingMechanism : Mechanism to be used for errror handling.
1015 * \param postFilteringType: Type of post filtering operation to be used.
1016 * \param uc_outputFormat: Format of the decoded picture [default 4:2:0].
1017 * \param uc_dispBufs: Number of Display Buffers.
1018 * \param p_NALBufAPI: Pointer to NAL Buffer API.
1019 * \param p_DispBufAPI: Pointer to Display Buffer API.
1020 * \param ih264d_dec_mem_manager :Pointer to the function that will be called
1021 *by decoder for memory allocation and freeing.
1022 *
1023 * \return
1024 * 0 on Success and -1 on error
1025 *
1026 **************************************************************************
1027 */
isvcd_init_decoder(svc_dec_lyr_struct_t * ps_dec_svc_lyr_params)1028 void isvcd_init_decoder(svc_dec_lyr_struct_t *ps_dec_svc_lyr_params)
1029 {
1030 svc_dec_lyr_struct_t *ps_svc_lyr_dec = (svc_dec_lyr_struct_t *) ps_dec_svc_lyr_params;
1031 dec_struct_t *ps_dec;
1032 dec_slice_params_t *ps_cur_slice;
1033 pocstruct_t *ps_prev_poc, *ps_cur_poc;
1034 size_t size;
1035 ps_dec = &ps_svc_lyr_dec->s_dec;
1036
1037 size = sizeof(pred_info_t) * 2 * 32;
1038 memset(ps_dec->ps_pred, 0, size);
1039
1040 size = sizeof(disp_mgr_t);
1041 memset(ps_dec->pv_disp_buf_mgr, 0, size);
1042
1043 size = ih264_buf_mgr_size();
1044 memset(ps_dec->pv_pic_buf_mgr, 0, size);
1045
1046 size = sizeof(dec_err_status_t);
1047 memset(ps_dec->ps_dec_err_status, 0, size);
1048
1049 size = sizeof(sei);
1050 memset(ps_dec->ps_sei, 0, size);
1051
1052 size = sizeof(sei);
1053 memset(ps_dec->ps_sei_parse, 0, size);
1054
1055 size = sizeof(dpb_commands_t);
1056 memset(ps_dec->ps_dpb_cmds, 0, size);
1057
1058 size = sizeof(dec_bit_stream_t);
1059 memset(ps_dec->ps_bitstrm, 0, size);
1060
1061 size = sizeof(dec_slice_params_t);
1062 memset(ps_dec->ps_cur_slice, 0, size);
1063
1064 size = MAX(sizeof(dec_seq_params_t), sizeof(dec_pic_params_t));
1065 memset(ps_dec->pv_scratch_sps_pps, 0, size);
1066
1067 size = sizeof(dec_svc_seq_params_t);
1068 memset(ps_svc_lyr_dec->pv_scratch_subset_sps, 0, size);
1069
1070 size = sizeof(ctxt_inc_mb_info_t);
1071 memset(ps_dec->ps_left_mb_ctxt_info, 0, size);
1072
1073 size = (sizeof(neighbouradd_t) << 2);
1074 memset(ps_dec->ps_left_mvpred_addr, 0, size);
1075
1076 size = ih264_buf_mgr_size();
1077 memset(ps_dec->pv_mv_buf_mgr, 0, size);
1078
1079 /* Free any dynamic buffers that are allocated */
1080 isvcd_free_dynamic_bufs(ps_svc_lyr_dec);
1081
1082 {
1083 UWORD8 i;
1084 struct pic_buffer_t *ps_init_dpb;
1085 ps_init_dpb = ps_dec->ps_dpb_mgr->ps_init_dpb[0][0];
1086 for(i = 0; i < 2 * MAX_REF_BUFS; i++)
1087 {
1088 ps_init_dpb->pu1_buf1 = NULL;
1089 ps_init_dpb->u1_long_term_frm_idx = MAX_REF_BUFS + 1;
1090 ps_dec->ps_dpb_mgr->ps_init_dpb[0][i] = ps_init_dpb;
1091 ps_dec->ps_dpb_mgr->ps_mod_dpb[0][i] = ps_init_dpb;
1092 ps_init_dpb++;
1093 }
1094
1095 ps_init_dpb = ps_dec->ps_dpb_mgr->ps_init_dpb[1][0];
1096 for(i = 0; i < 2 * MAX_REF_BUFS; i++)
1097 {
1098 ps_init_dpb->pu1_buf1 = NULL;
1099 ps_init_dpb->u1_long_term_frm_idx = MAX_REF_BUFS + 1;
1100 ps_dec->ps_dpb_mgr->ps_init_dpb[1][i] = ps_init_dpb;
1101 ps_dec->ps_dpb_mgr->ps_mod_dpb[1][i] = ps_init_dpb;
1102 ps_init_dpb++;
1103 }
1104 }
1105
1106 ps_cur_slice = ps_dec->ps_cur_slice;
1107 ps_dec->init_done = 0;
1108
1109 ps_dec->u4_num_cores = 1;
1110 ps_dec->u2_pic_ht = ps_dec->u2_pic_wd = 0;
1111
1112 ps_dec->u1_separate_parse = DEFAULT_SEPARATE_PARSE;
1113 ps_dec->u4_app_disable_deblk_frm = 0;
1114 ps_dec->i4_degrade_type = 0;
1115 ps_dec->i4_degrade_pics = 0;
1116
1117 /* Initialization of function pointers ih264d_deblock_picture function*/
1118 ps_dec->p_DeblockPicture[0] = ih264d_deblock_picture_non_mbaff;
1119 ps_dec->p_DeblockPicture[1] = ih264d_deblock_picture_mbaff;
1120
1121 ps_dec->s_cab_dec_env.pv_codec_handle = ps_dec;
1122 ps_dec->u4_num_fld_in_frm = 0;
1123 ps_dec->ps_dpb_mgr->pv_codec_handle = ps_dec;
1124
1125 /* Initialize the sei validity u4_flag with zero indiacting sei is not valid*/
1126 ps_dec->ps_sei->u1_is_valid = 0;
1127
1128 /* decParams Initializations */
1129 ps_dec->ps_cur_pps = NULL;
1130 ps_dec->ps_cur_sps = NULL;
1131 ps_dec->u1_init_dec_flag = 0;
1132 ps_dec->u1_first_slice_in_stream = 1;
1133 ps_dec->u1_last_pic_not_decoded = 0;
1134 ps_dec->u4_app_disp_width = 0;
1135 ps_dec->i4_header_decoded = 0;
1136 ps_dec->u4_total_frames_decoded = 0;
1137
1138 ps_dec->i4_error_code = 0;
1139 ps_dec->i4_content_type = IV_CONTENTTYPE_NA;
1140 ps_dec->ps_cur_slice->u1_mbaff_frame_flag = 0;
1141
1142 ps_dec->ps_dec_err_status->u1_err_flag = ACCEPT_ALL_PICS;
1143 ps_dec->ps_dec_err_status->u1_cur_pic_type = PIC_TYPE_UNKNOWN;
1144 ps_dec->ps_dec_err_status->u4_frm_sei_sync = SYNC_FRM_DEFAULT;
1145 ps_dec->ps_dec_err_status->u4_cur_frm = INIT_FRAME;
1146 ps_dec->ps_dec_err_status->u1_pic_aud_i = PIC_TYPE_UNKNOWN;
1147
1148 ps_dec->u1_pr_sl_type = 0xFF;
1149 ps_dec->u2_mbx = 0xffff;
1150 ps_dec->u2_mby = 0;
1151 ps_dec->u2_total_mbs_coded = 0;
1152
1153 /* POC initializations */
1154 ps_prev_poc = &ps_dec->s_prev_pic_poc;
1155 ps_cur_poc = &ps_dec->s_cur_pic_poc;
1156 ps_prev_poc->i4_pic_order_cnt_lsb = ps_cur_poc->i4_pic_order_cnt_lsb = 0;
1157 ps_prev_poc->i4_pic_order_cnt_msb = ps_cur_poc->i4_pic_order_cnt_msb = 0;
1158 ps_prev_poc->i4_delta_pic_order_cnt_bottom = ps_cur_poc->i4_delta_pic_order_cnt_bottom = 0;
1159 ps_prev_poc->i4_delta_pic_order_cnt[0] = ps_cur_poc->i4_delta_pic_order_cnt[0] = 0;
1160 ps_prev_poc->i4_delta_pic_order_cnt[1] = ps_cur_poc->i4_delta_pic_order_cnt[1] = 0;
1161 ps_prev_poc->u1_mmco_equalto5 = ps_cur_poc->u1_mmco_equalto5 = 0;
1162 ps_prev_poc->i4_top_field_order_count = ps_cur_poc->i4_top_field_order_count = 0;
1163 ps_prev_poc->i4_bottom_field_order_count = ps_cur_poc->i4_bottom_field_order_count = 0;
1164 ps_prev_poc->u1_bot_field = ps_cur_poc->u1_bot_field = 0;
1165 ps_prev_poc->u1_mmco_equalto5 = ps_cur_poc->u1_mmco_equalto5 = 0;
1166 ps_prev_poc->i4_prev_frame_num_ofst = ps_cur_poc->i4_prev_frame_num_ofst = 0;
1167 ps_cur_slice->u1_mmco_equalto5 = 0;
1168 ps_cur_slice->u2_frame_num = 0;
1169
1170 ps_dec->i4_max_poc = 0;
1171 ps_dec->i4_prev_max_display_seq = 0;
1172 ps_dec->u1_recon_mb_grp = 4;
1173 ps_dec->i4_reorder_depth = -1;
1174
1175 /* Field PIC initializations */
1176 ps_dec->u1_second_field = 0;
1177 ps_dec->s_prev_seq_params.u1_eoseq_pending = 0;
1178
1179 /* Set the cropping parameters as zero */
1180 ps_dec->u2_crop_offset_y = 0;
1181 ps_dec->u2_crop_offset_uv = 0;
1182
1183 /* The Initial Frame Rate Info is not Present */
1184 ps_dec->i4_vui_frame_rate = -1;
1185 ps_dec->i4_pic_type = NA_SLICE;
1186 ps_dec->i4_frametype = IV_NA_FRAME;
1187 ps_dec->i4_content_type = IV_CONTENTTYPE_NA;
1188
1189 ps_dec->u1_res_changed = 0;
1190
1191 ps_dec->u1_frame_decoded_flag = 0;
1192
1193 /* Set the default frame seek mask mode */
1194 ps_dec->u4_skip_frm_mask = SKIP_NONE;
1195
1196 /********************************************************/
1197 /* Initialize CAVLC residual decoding function pointers */
1198 /********************************************************/
1199 ps_dec->pf_cavlc_4x4res_block[0] = ih264d_cavlc_4x4res_block_totalcoeff_1;
1200 ps_dec->pf_cavlc_4x4res_block[1] = ih264d_cavlc_4x4res_block_totalcoeff_2to10;
1201 ps_dec->pf_cavlc_4x4res_block[2] = ih264d_cavlc_4x4res_block_totalcoeff_11to16;
1202
1203 ps_dec->pf_cavlc_parse4x4coeff[0] = ih264d_cavlc_parse4x4coeff_n0to7;
1204 ps_dec->pf_cavlc_parse4x4coeff[1] = ih264d_cavlc_parse4x4coeff_n8;
1205
1206 ps_dec->pf_cavlc_parse_8x8block[0] = ih264d_cavlc_parse_8x8block_none_available;
1207 ps_dec->pf_cavlc_parse_8x8block[1] = ih264d_cavlc_parse_8x8block_left_available;
1208 ps_dec->pf_cavlc_parse_8x8block[2] = ih264d_cavlc_parse_8x8block_top_available;
1209 ps_dec->pf_cavlc_parse_8x8block[3] = ih264d_cavlc_parse_8x8block_both_available;
1210
1211 /***************************************************************************/
1212 /* Initialize Bs calculation function pointers for P and B, 16x16/non16x16 */
1213 /***************************************************************************/
1214 ps_dec->pf_fill_bs1[0][0] = ih264d_fill_bs1_16x16mb_pslice;
1215 ps_dec->pf_fill_bs1[0][1] = ih264d_fill_bs1_non16x16mb_pslice;
1216
1217 ps_dec->pf_fill_bs1[1][0] = ih264d_fill_bs1_16x16mb_bslice;
1218 ps_dec->pf_fill_bs1[1][1] = ih264d_fill_bs1_non16x16mb_bslice;
1219
1220 ps_dec->pf_fill_bs_xtra_left_edge[0] = ih264d_fill_bs_xtra_left_edge_cur_frm;
1221 ps_dec->pf_fill_bs_xtra_left_edge[1] = ih264d_fill_bs_xtra_left_edge_cur_fld;
1222
1223 /* Initialize Reference Pic Buffers */
1224 ih264d_init_ref_bufs(ps_dec->ps_dpb_mgr);
1225
1226 ps_dec->u2_prv_frame_num = 0;
1227 ps_dec->u1_top_bottom_decoded = 0;
1228 ps_dec->u1_dangling_field = 0;
1229
1230 ps_dec->s_cab_dec_env.cabac_table = gau4_ih264d_cabac_table;
1231
1232 ps_dec->pu1_left_mv_ctxt_inc = ps_dec->u1_left_mv_ctxt_inc_arr[0];
1233 ps_dec->pi1_left_ref_idx_ctxt_inc = &ps_dec->i1_left_ref_idx_ctx_inc_arr[0][0];
1234 ps_dec->pu1_left_yuv_dc_csbp = &ps_dec->u1_yuv_dc_csbp_topmb;
1235
1236 /* ! */
1237 /* Initializing flush frame u4_flag */
1238 ps_dec->u1_flushfrm = 0;
1239
1240 ps_dec->s_cab_dec_env.pv_codec_handle = (void *) ps_dec;
1241 ps_dec->ps_bitstrm->pv_codec_handle = (void *) ps_dec;
1242 ps_dec->ps_cur_slice->pv_codec_handle = (void *) ps_dec;
1243 ps_dec->ps_dpb_mgr->pv_codec_handle = (void *) ps_dec;
1244
1245 memset(ps_dec->disp_bufs, 0, (MAX_DISP_BUFS_NEW) * sizeof(disp_buf_t));
1246 memset(ps_dec->u4_disp_buf_mapping, 0, (MAX_DISP_BUFS_NEW) * sizeof(UWORD32));
1247 memset(ps_dec->u4_disp_buf_to_be_freed, 0, (MAX_DISP_BUFS_NEW) * sizeof(UWORD32));
1248 memset(ps_dec->ps_cur_slice, 0, sizeof(dec_slice_params_t));
1249
1250 ih264d_init_arch(ps_dec);
1251 isvcd_init_function_ptr(ps_svc_lyr_dec);
1252 ps_dec->e_frm_out_mode = IVD_DISPLAY_FRAME_OUT;
1253 ps_dec->init_done = 1;
1254 ps_svc_lyr_dec->u1_layer_identifier = BASE_LAYER;
1255 }
1256
1257 /*****************************************************************************/
1258 /* */
1259 /* Function Name : isvcd_nal_parse_ctxt_free */
1260 /* */
1261 /* Description :this function is used to free the nal parse context */
1262 /* Inputs : */
1263 /* Globals : none */
1264 /* Processing : */
1265 /* */
1266 /* Outputs : none */
1267 /* Returns : none */
1268 /* */
1269 /* Issues : none */
1270 /* */
1271 /* Revision History: */
1272 /* */
1273 /* DD MM YYYY Author(s) Changes (Describe the changes made) */
1274 /* 25 11 2021 Kishore creation */
1275 /* */
1276 /*****************************************************************************/
1277
isvcd_nal_parse_ctxt_free(svc_dec_ctxt_t * ps_svcd_ctxt)1278 void isvcd_nal_parse_ctxt_free(svc_dec_ctxt_t *ps_svcd_ctxt)
1279 {
1280 dec_struct_t *ps_dec;
1281 svc_dec_lyr_struct_t *ps_svc_lyr_dec;
1282 void (*pf_aligned_free)(void *pv_mem_ctxt, void *pv_buf);
1283 void *pv_mem_ctxt;
1284 nal_parse_ctxt_t *ps_ctxt;
1285 ps_svc_lyr_dec = &ps_svcd_ctxt->ps_svc_dec_lyr[0];
1286 ps_dec = &ps_svc_lyr_dec->s_dec;
1287 pf_aligned_free = ps_dec->pf_aligned_free;
1288
1289 pv_mem_ctxt = ps_dec->pv_mem_ctxt;
1290 ps_ctxt = (nal_parse_ctxt_t *) ps_svcd_ctxt->pv_nal_parse_ctxt;
1291
1292 pf_aligned_free(pv_mem_ctxt, ps_ctxt->s_dqid_ctxt.ps_dqid_node);
1293 pf_aligned_free(pv_mem_ctxt, ps_ctxt->pv_nal_header_buf);
1294 pf_aligned_free(pv_mem_ctxt, ps_ctxt->pv_nal_unit);
1295 pf_aligned_free(pv_mem_ctxt, ps_svcd_ctxt->pv_vcl_nal_buff);
1296 pf_aligned_free(pv_mem_ctxt, ps_svcd_ctxt->pv_non_vcl_nal_buff);
1297 pf_aligned_free(pv_mem_ctxt, ps_svcd_ctxt->pv_nal_parse_ctxt);
1298 }
1299 /*****************************************************************************/
1300 /* */
1301 /* Function Name : isvcd_residual_resample_ctxt_free */
1302 /* */
1303 /* Description :this function is used to free the resd_resamp context */
1304 /* Inputs : */
1305 /* Globals : none */
1306 /* Processing : */
1307 /* */
1308 /* Outputs : none */
1309 /* Returns : none */
1310 /* */
1311 /* Issues : none */
1312 /* */
1313 /* Revision History: */
1314 /* */
1315 /* DD MM YYYY Author(s) Changes (Describe the changes made) */
1316 /* 25 11 2021 Kishore creation */
1317 /* */
1318 /*****************************************************************************/
1319
isvcd_residual_resample_ctxt_free(svc_dec_ctxt_t * ps_svcd_ctxt)1320 void isvcd_residual_resample_ctxt_free(svc_dec_ctxt_t *ps_svcd_ctxt)
1321 {
1322 dec_struct_t *ps_dec;
1323 svc_dec_lyr_struct_t *ps_svc_lyr_dec;
1324 void (*pf_aligned_free)(void *pv_mem_ctxt, void *pv_buf);
1325 void *pv_mem_ctxt;
1326 residual_sampling_ctxt_t *ps_ctxt;
1327 ps_svc_lyr_dec = &ps_svcd_ctxt->ps_svc_dec_lyr[0];
1328 ps_dec = &ps_svc_lyr_dec->s_dec;
1329 pf_aligned_free = ps_dec->pf_aligned_free;
1330
1331 pv_mem_ctxt = ps_dec->pv_mem_ctxt;
1332 ps_ctxt = (residual_sampling_ctxt_t *) ps_svcd_ctxt->pv_residual_sample_ctxt;
1333
1334 pf_aligned_free(pv_mem_ctxt, ps_ctxt->pi2_refarray_buffer);
1335 pf_aligned_free(pv_mem_ctxt, ps_ctxt->pu1_ref_x_ptr_incr);
1336 pf_aligned_free(pv_mem_ctxt, ps_ctxt->as_res_lyrs[0].s_luma_map_ctxt.ps_x_offset_length);
1337 pf_aligned_free(pv_mem_ctxt, ps_ctxt->as_res_lyrs[0].s_luma_map_ctxt.ps_y_offset_length);
1338 pf_aligned_free(pv_mem_ctxt, ps_ctxt->as_res_lyrs[0].s_luma_map_ctxt.ps_x_pos_phase);
1339 pf_aligned_free(pv_mem_ctxt, ps_ctxt->as_res_lyrs[0].s_luma_map_ctxt.ps_y_pos_phase);
1340 pf_aligned_free(pv_mem_ctxt, ps_svcd_ctxt->pv_residual_sample_ctxt);
1341 }
1342
1343 /*****************************************************************************/
1344 /* */
1345 /* Function Name : isvcd_intra_resample_ctxt_free */
1346 /* */
1347 /* Description :this function is used to free the intra_resamp context */
1348 /* Inputs : */
1349 /* Globals : none */
1350 /* Processing : */
1351 /* */
1352 /* Outputs : none */
1353 /* Returns : none */
1354 /* */
1355 /* Issues : none */
1356 /* */
1357 /* Revision History: */
1358 /* */
1359 /* DD MM YYYY Author(s) Changes (Describe the changes made) */
1360 /* 25 11 2021 Kishore creation */
1361 /* */
1362 /*****************************************************************************/
isvcd_intra_resample_ctxt_free(svc_dec_ctxt_t * ps_svcd_ctxt)1363 void isvcd_intra_resample_ctxt_free(svc_dec_ctxt_t *ps_svcd_ctxt)
1364 {
1365 dec_struct_t *ps_dec;
1366 svc_dec_lyr_struct_t *ps_svc_lyr_dec;
1367 void (*pf_aligned_free)(void *pv_mem_ctxt, void *pv_buf);
1368 void *pv_mem_ctxt;
1369 intra_sampling_ctxt_t *ps_ctxt;
1370 ps_svc_lyr_dec = &ps_svcd_ctxt->ps_svc_dec_lyr[0];
1371 ps_dec = &ps_svc_lyr_dec->s_dec;
1372 pf_aligned_free = ps_dec->pf_aligned_free;
1373
1374 pv_mem_ctxt = ps_dec->pv_mem_ctxt;
1375 ps_ctxt = (intra_sampling_ctxt_t *) ps_svcd_ctxt->pv_intra_sample_ctxt;
1376
1377 pf_aligned_free(pv_mem_ctxt, ps_ctxt->pu1_refarray_buffer);
1378 pf_aligned_free(pv_mem_ctxt, ps_ctxt->pu1_refarray_cb);
1379 pf_aligned_free(pv_mem_ctxt, ps_ctxt->pu1_refarray_cr);
1380 pf_aligned_free(pv_mem_ctxt, ps_ctxt->pi4_temp_interpolation_buffer);
1381 pf_aligned_free(pv_mem_ctxt, ps_ctxt->as_res_lyrs[0].s_luma_map_ctxt.ps_x_offset_length);
1382 pf_aligned_free(pv_mem_ctxt, ps_ctxt->as_res_lyrs[0].s_luma_map_ctxt.ps_y_offset_length);
1383 pf_aligned_free(pv_mem_ctxt, ps_ctxt->as_res_lyrs[0].s_luma_map_ctxt.ps_x_min_max);
1384 pf_aligned_free(pv_mem_ctxt, ps_ctxt->as_res_lyrs[0].s_luma_map_ctxt.ps_y_min_max);
1385 pf_aligned_free(pv_mem_ctxt, ps_ctxt->as_res_lyrs[0].s_luma_map_ctxt.ps_x_pos_phase);
1386 pf_aligned_free(pv_mem_ctxt, ps_ctxt->as_res_lyrs[0].s_luma_map_ctxt.ps_y_pos_phase);
1387 pf_aligned_free(pv_mem_ctxt, ps_ctxt->as_res_lyrs[0].s_luma_map_ctxt.pi2_xd_index);
1388 pf_aligned_free(pv_mem_ctxt, ps_ctxt->as_res_lyrs[0].s_luma_map_ctxt.pi2_yd_index);
1389 pf_aligned_free(pv_mem_ctxt, ps_ctxt->as_res_lyrs[0].s_luma_map_ctxt.pi2_ya_index);
1390 pf_aligned_free(pv_mem_ctxt, ps_ctxt->as_res_lyrs[0].s_luma_map_ctxt.ps_seg_lookup_horz);
1391 pf_aligned_free(pv_mem_ctxt, ps_ctxt->as_res_lyrs[0].s_luma_map_ctxt.ps_seg_lookup_vert);
1392 pf_aligned_free(pv_mem_ctxt, ps_ctxt->as_res_lyrs[0].s_luma_map_ctxt.pu1_refarray_x_idx);
1393 pf_aligned_free(pv_mem_ctxt, ps_svcd_ctxt->pv_intra_sample_ctxt);
1394 pf_aligned_free(pv_mem_ctxt, ps_svcd_ctxt->pv_ii_pred_ctxt);
1395 }
1396 /*****************************************************************************/
1397 /* */
1398 /* Function Name : isvcd_mode_mv_resample_ctxt_free */
1399 /* */
1400 /* Description :this function is used to free the mv resamp context */
1401 /* Inputs : */
1402 /* Globals : none */
1403 /* Processing : */
1404 /* */
1405 /* Outputs : none */
1406 /* Returns : none */
1407 /* */
1408 /* Issues : none */
1409 /* */
1410 /* Revision History: */
1411 /* */
1412 /* DD MM YYYY Author(s) Changes (Describe the changes made) */
1413 /* 25 11 2021 Kishore creation */
1414 /* */
1415 /*****************************************************************************/
isvcd_mode_mv_resample_ctxt_free(svc_dec_ctxt_t * ps_svcd_ctxt)1416 void isvcd_mode_mv_resample_ctxt_free(svc_dec_ctxt_t *ps_svcd_ctxt)
1417 {
1418 dec_struct_t *ps_dec;
1419 svc_dec_lyr_struct_t *ps_svc_lyr_dec;
1420 void (*pf_aligned_free)(void *pv_mem_ctxt, void *pv_buf);
1421 void *pv_mem_ctxt;
1422 mode_motion_ctxt_t *ps_mode_motion;
1423
1424 ps_svc_lyr_dec = &ps_svcd_ctxt->ps_svc_dec_lyr[0];
1425 ps_dec = &ps_svc_lyr_dec->s_dec;
1426 pf_aligned_free = ps_dec->pf_aligned_free;
1427
1428 pv_mem_ctxt = ps_dec->pv_mem_ctxt;
1429 ps_mode_motion = (mode_motion_ctxt_t *) ps_svcd_ctxt->pv_mode_mv_sample_ctxt;
1430
1431 pf_aligned_free(pv_mem_ctxt, ps_mode_motion->ps_motion_pred_struct);
1432 pf_aligned_free(pv_mem_ctxt, ps_mode_motion->as_res_lyr_mem[0].pi2_ref_loc_x);
1433 pf_aligned_free(pv_mem_ctxt, ps_mode_motion->as_res_lyr_mem[0].pi2_ref_loc_y);
1434 pf_aligned_free(pv_mem_ctxt, ps_svcd_ctxt->pv_ref_lyr_offset);
1435 pf_aligned_free(pv_mem_ctxt, ps_svcd_ctxt->pv_mode_mv_sample_ctxt);
1436 }
1437 /*****************************************************************************/
1438 /* */
1439 /* Function Name : isvcd_free_static_bufs */
1440 /* */
1441 /* Description :this function is used to free the static buffers */
1442 /* Inputs : */
1443 /* Globals : none */
1444 /* Processing : */
1445 /* */
1446 /* Outputs : none */
1447 /* Returns : none */
1448 /* */
1449 /* Issues : none */
1450 /* */
1451 /* Revision History: */
1452 /* */
1453 /* DD MM YYYY Author(s) Changes (Describe the changes made) */
1454 /* 25 11 2021 Kishore creation */
1455 /* */
1456 /*****************************************************************************/
1457
isvcd_free_static_bufs(iv_obj_t * dec_hdl)1458 WORD32 isvcd_free_static_bufs(iv_obj_t *dec_hdl)
1459 {
1460 dec_struct_t *ps_dec;
1461 svc_dec_lyr_struct_t *ps_svc_lyr_dec;
1462
1463 UWORD8 u1_layer_id;
1464 svc_dec_ctxt_t *ps_svcd_ctxt;
1465
1466 void (*pf_aligned_free)(void *pv_mem_ctxt, void *pv_buf);
1467 void *pv_mem_ctxt;
1468
1469 ps_svcd_ctxt = (svc_dec_ctxt_t *) dec_hdl->pv_codec_handle;
1470
1471 isvcd_intra_resample_ctxt_free(ps_svcd_ctxt);
1472 isvcd_residual_resample_ctxt_free(ps_svcd_ctxt);
1473 isvcd_mode_mv_resample_ctxt_free(ps_svcd_ctxt);
1474 isvcd_nal_parse_ctxt_free(ps_svcd_ctxt);
1475
1476 for(u1_layer_id = 0; u1_layer_id < MAX_NUM_RES_LYRS; u1_layer_id++)
1477 {
1478 ps_svc_lyr_dec = &ps_svcd_ctxt->ps_svc_dec_lyr[u1_layer_id];
1479 ps_dec = &ps_svc_lyr_dec->s_dec;
1480 pf_aligned_free = ps_dec->pf_aligned_free;
1481 pv_mem_ctxt = ps_dec->pv_mem_ctxt;
1482
1483 #ifdef KEEP_THREADS_ACTIVE
1484 /* Wait for threads */
1485 ps_dec->i4_break_threads = 1;
1486 if(ps_dec->u4_dec_thread_created)
1487 {
1488 ithread_mutex_lock(ps_dec->apv_proc_start_mutex[0]);
1489
1490 ps_dec->ai4_process_start[0] = PROC_START;
1491
1492 ithread_cond_signal(ps_dec->apv_proc_start_condition[0]);
1493
1494 ithread_mutex_unlock(ps_dec->apv_proc_start_mutex[0]);
1495
1496 ithread_join(ps_dec->pv_dec_thread_handle, NULL);
1497
1498 ps_dec->u4_dec_thread_created = 0;
1499 }
1500
1501 if(ps_dec->u4_bs_deblk_thread_created)
1502 {
1503 ithread_mutex_lock(ps_dec->apv_proc_start_mutex[1]);
1504
1505 ps_dec->ai4_process_start[1] = PROC_START;
1506
1507 ithread_cond_signal(ps_dec->apv_proc_start_condition[1]);
1508
1509 ithread_mutex_unlock(ps_dec->apv_proc_start_mutex[1]);
1510
1511 ithread_join(ps_dec->pv_bs_deblk_thread_handle, NULL);
1512
1513 ps_dec->u4_bs_deblk_thread_created = 0;
1514 }
1515
1516 // destroy mutex and condition variable for both the threads
1517 // 1. ih264d_decode_picture_thread
1518 // 2. ih264d_recon_deblk_thread
1519 {
1520 UWORD32 i;
1521 for(i = 0; i < 2; i++)
1522 {
1523 ithread_cond_destroy(ps_dec->apv_proc_start_condition[i]);
1524 ithread_cond_destroy(ps_dec->apv_proc_done_condition[i]);
1525
1526 ithread_mutex_destroy(ps_dec->apv_proc_start_mutex[i]);
1527 ithread_mutex_destroy(ps_dec->apv_proc_done_mutex[i]);
1528 }
1529 }
1530 PS_DEC_ALIGNED_FREE(ps_dec, ps_dec->apv_proc_start_mutex[0]);
1531 PS_DEC_ALIGNED_FREE(ps_dec, ps_dec->apv_proc_start_condition[0]);
1532 #endif
1533 if(0 == u1_layer_id)
1534 {
1535 UWORD8 u1_sps_ctr;
1536 PS_DEC_ALIGNED_FREE(ps_dec, ps_dec->ps_sps);
1537 for(u1_sps_ctr = 0; u1_sps_ctr < (2 * MAX_NUM_SEQ_PARAMS); u1_sps_ctr++)
1538 {
1539 if(NULL != ps_svcd_ctxt->ps_subset_sps[u1_sps_ctr].s_sps_svc_ext.ps_svc_vui_ext)
1540 {
1541 PS_DEC_ALIGNED_FREE(
1542 ps_dec,
1543 ps_svcd_ctxt->ps_subset_sps[u1_sps_ctr].s_sps_svc_ext.ps_svc_vui_ext);
1544 }
1545 }
1546 PS_DEC_ALIGNED_FREE(ps_dec, ps_svc_lyr_dec->ps_subset_sps);
1547 PS_DEC_ALIGNED_FREE(ps_dec, ps_dec->ps_pps);
1548 PS_DEC_ALIGNED_FREE(ps_dec, ps_dec->ps_sei);
1549 PS_DEC_ALIGNED_FREE(ps_dec, ps_dec->ps_sei_parse);
1550 }
1551
1552 PS_DEC_ALIGNED_FREE(ps_dec, ps_dec->pv_dec_thread_handle);
1553 PS_DEC_ALIGNED_FREE(ps_dec, ps_dec->pv_bs_deblk_thread_handle);
1554
1555 PS_DEC_ALIGNED_FREE(ps_dec, ps_dec->ps_dpb_mgr);
1556 PS_DEC_ALIGNED_FREE(ps_dec, ps_dec->ps_pred);
1557 PS_DEC_ALIGNED_FREE(ps_dec, ps_dec->pv_disp_buf_mgr);
1558 PS_DEC_ALIGNED_FREE(ps_dec, ps_dec->ps_pic_buf_base);
1559 PS_DEC_ALIGNED_FREE(ps_dec, ps_dec->ps_dec_err_status);
1560
1561 PS_DEC_ALIGNED_FREE(ps_dec, ps_dec->ps_dpb_cmds);
1562 PS_DEC_ALIGNED_FREE(ps_dec, ps_dec->ps_bitstrm);
1563 PS_DEC_ALIGNED_FREE(ps_dec, ps_svc_lyr_dec->ps_nal_svc_ext);
1564 PS_DEC_ALIGNED_FREE(ps_dec, ps_dec->ps_cur_slice);
1565 PS_DEC_ALIGNED_FREE(ps_dec, ps_dec->pv_scratch_sps_pps);
1566 PS_DEC_ALIGNED_FREE(ps_dec, ps_svc_lyr_dec->pv_scratch_subset_sps);
1567 PS_DEC_ALIGNED_FREE(ps_dec, ps_dec->pu1_bits_buf_static);
1568 PS_DEC_ALIGNED_FREE(ps_dec, ps_dec->ppv_map_ref_idx_to_poc_base);
1569 PS_DEC_ALIGNED_FREE(ps_dec, ps_dec->p_cabac_ctxt_table_t);
1570 PS_DEC_ALIGNED_FREE(ps_dec, ps_dec->ps_left_mb_ctxt_info);
1571 PS_DEC_ALIGNED_FREE(ps_dec, ps_dec->pu1_ref_buff_base);
1572 PS_DEC_ALIGNED_FREE(ps_dec, ps_dec->pi2_pred1);
1573 PS_DEC_ALIGNED_FREE(ps_dec, ps_dec->pu1_temp_mc_buffer);
1574 PS_DEC_ALIGNED_FREE(ps_dec, ps_dec->pu1_init_dpb_base);
1575 PS_DEC_ALIGNED_FREE(ps_dec, ps_dec->pu4_mbaff_wt_mat);
1576 PS_DEC_ALIGNED_FREE(ps_dec, ps_dec->pu4_wts_ofsts_mat);
1577 PS_DEC_ALIGNED_FREE(ps_dec, ps_dec->ps_left_mvpred_addr);
1578 PS_DEC_ALIGNED_FREE(ps_dec, ps_dec->ps_col_mv_base);
1579 PS_DEC_ALIGNED_FREE(ps_dec, ps_svc_lyr_dec->pu1_ii_resamp_buffer_luma);
1580
1581 if(NULL != ps_dec->pv_pic_buf_mgr)
1582 {
1583 if(u1_layer_id < ps_svcd_ctxt->u1_prev_num_res_layers)
1584 {
1585 if(((buf_mgr_t *) ps_dec->pv_pic_buf_mgr)->pv_mutex != NULL)
1586 ih264_buf_mgr_free(ps_dec->pv_pic_buf_mgr);
1587 }
1588 PS_DEC_ALIGNED_FREE(ps_dec, ps_dec->pv_pic_buf_mgr);
1589 }
1590 if(NULL != ps_dec->pv_mv_buf_mgr)
1591 {
1592 if(u1_layer_id < ps_svcd_ctxt->u1_prev_num_res_layers)
1593 {
1594 if(((buf_mgr_t *) ps_dec->pv_mv_buf_mgr)->pv_mutex != NULL)
1595 ih264_buf_mgr_free(ps_dec->pv_mv_buf_mgr);
1596 }
1597 PS_DEC_ALIGNED_FREE(ps_dec, ps_dec->pv_mv_buf_mgr);
1598 }
1599 }
1600
1601 pf_aligned_free(pv_mem_ctxt, ps_svcd_ctxt->ps_svc_dec_lyr);
1602 pf_aligned_free(pv_mem_ctxt, dec_hdl->pv_codec_handle);
1603
1604 if(dec_hdl)
1605 {
1606 pf_aligned_free(pv_mem_ctxt, dec_hdl);
1607 }
1608
1609 return IV_SUCCESS;
1610 }
1611
1612 /*****************************************************************************/
1613 /* */
1614 /* Function Name : isvcd_nal_parse_init */
1615 /* */
1616 /* Description : Initiaization of allocation of memory */
1617 /* */
1618 /* Inputs : pv_mem_rec - Allocated memory records */
1619 /* */
1620 /* Globals : None */
1621 /* */
1622 /* Processing : None */
1623 /* */
1624 /* Outputs : None */
1625 /* */
1626 /* Returns : Module's handle */
1627 /* */
1628 /* Issues : None */
1629 /* */
1630 /* Revision History: */
1631 /* DD MM YYYY Author(s) Changes */
1632 /* 06 09 2021 Vijay Draft */
1633 /* */
1634 /*****************************************************************************/
isvcd_nal_parse_ctxt_create(svc_dec_ctxt_t * ps_svcd_ctxt,void * pv_api_ip,void * pv_api_op)1635 WORD32 isvcd_nal_parse_ctxt_create(svc_dec_ctxt_t *ps_svcd_ctxt, void *pv_api_ip, void *pv_api_op)
1636 {
1637 isvcd_create_ip_t *ps_create_ip;
1638 void *pv_buf;
1639 void *(*pf_aligned_alloc)(void *pv_mem_ctxt, WORD32 alignment, WORD32 size);
1640 void *pv_mem_ctxt;
1641 WORD32 size;
1642 nal_parse_ctxt_t *ps_nal_parse_ctxt;
1643 UWORD8 *pu1_ptr;
1644 UNUSED(pv_api_op);
1645
1646 ps_create_ip = (isvcd_create_ip_t *) pv_api_ip;
1647
1648 pf_aligned_alloc = ps_create_ip->s_ivd_create_ip_t.pf_aligned_alloc;
1649 pv_mem_ctxt = ps_create_ip->s_ivd_create_ip_t.pv_mem_ctxt;
1650
1651 /*-----------------------------------------------------------------------*/
1652 /* Handle */
1653 /*-----------------------------------------------------------------------*/
1654 size = sizeof(nal_parse_ctxt_t);
1655 pv_buf = pf_aligned_alloc(pv_mem_ctxt, 128, size);
1656 RETURN_IF((NULL == pv_buf), IV_FAIL);
1657 memset(pv_buf, 0, size);
1658 ps_nal_parse_ctxt = pv_buf;
1659
1660 /* set the lowest dqid to -1 */
1661 ps_nal_parse_ctxt->i4_prev_dq_id = -1;
1662
1663 /*-----------------------------------------------------------------------*/
1664 /* DQID list buffer and initialization of vcl node buffer context */
1665 /*-----------------------------------------------------------------------*/
1666 {
1667 WORD32 i4_lyr_idx;
1668 WORD32 i4_max_num_lyrs;
1669 vcl_node_t *ps_vcl_node;
1670 dqid_node_t *ps_dqid_node;
1671 dqid_ctxt_t *ps_dqid_ctxt;
1672
1673 size = sizeof(vcl_node_t);
1674 size += sizeof(dqid_node_t);
1675 size *= MAX_NUM_RES_LYRS;
1676
1677 ps_dqid_ctxt = &ps_nal_parse_ctxt->s_dqid_ctxt;
1678
1679 ps_dqid_ctxt->i4_max_num_lyrs = MAX_NUM_RES_LYRS;
1680
1681 pv_buf = pf_aligned_alloc(pv_mem_ctxt, 128, size);
1682 RETURN_IF((NULL == pv_buf), IV_FAIL);
1683 memset(pv_buf, 0, size);
1684
1685 ps_dqid_ctxt->ps_dqid_node = pv_buf;
1686 ps_dqid_node = ps_dqid_ctxt->ps_dqid_node;
1687
1688 i4_max_num_lyrs = ps_dqid_ctxt->i4_max_num_lyrs;
1689
1690 pu1_ptr = pv_buf;
1691 pu1_ptr += sizeof(dqid_node_t) * i4_max_num_lyrs;
1692 ps_vcl_node = (vcl_node_t *) pu1_ptr;
1693
1694 for(i4_lyr_idx = 0; i4_lyr_idx < i4_max_num_lyrs; i4_lyr_idx++)
1695 {
1696 ps_dqid_node->ps_vcl_node = ps_vcl_node;
1697
1698 /* Loop updates */
1699 ps_vcl_node += 1;
1700 ps_dqid_node += 1;
1701 } /* Loop over all the layers */
1702 }
1703
1704 /*-----------------------------------------------------------------------*/
1705 /* Common memory */
1706 /*-----------------------------------------------------------------------*/
1707 size = UP_ALIGN_8(HEADER_BUFFER_LEN_BEFORE_EP);
1708 pv_buf = pf_aligned_alloc(pv_mem_ctxt, 128, size);
1709 RETURN_IF((NULL == pv_buf), IV_FAIL);
1710 memset(pv_buf, 0, size);
1711 ps_nal_parse_ctxt->pv_nal_header_buf = (void *) pv_buf;
1712
1713 /*-----------------------------------------------------------------------*/
1714 /* Layer params memory */
1715 /*-----------------------------------------------------------------------*/
1716 size = sizeof(nal_unit_t);
1717 pv_buf = pf_aligned_alloc(pv_mem_ctxt, 128, size);
1718 RETURN_IF((NULL == pv_buf), IV_FAIL);
1719 memset(pv_buf, 0, size);
1720 ps_nal_parse_ctxt->pv_nal_unit = pv_buf;
1721
1722 size = MAX_VCL_NAL_BUFF_SIZE * sizeof(UWORD8);
1723 pv_buf = pf_aligned_alloc(pv_mem_ctxt, 128, size);
1724 RETURN_IF((NULL == pv_buf), IV_FAIL);
1725 memset(pv_buf, 0, size);
1726 ps_svcd_ctxt->pv_vcl_nal_buff = pv_buf;
1727
1728 size = MAX_NON_VCL_NAL_BUFF_SIZE * sizeof(UWORD8);
1729 pv_buf = pf_aligned_alloc(pv_mem_ctxt, 128, size);
1730 RETURN_IF((NULL == pv_buf), IV_FAIL);
1731 memset(pv_buf, 0, size);
1732 ps_svcd_ctxt->pv_non_vcl_nal_buff = pv_buf;
1733
1734 /*-----------------------------------------------------------------------*/
1735 /* Registering the seq and pic prms buffer pointers */
1736 /*-----------------------------------------------------------------------*/
1737 if(NULL == ps_svcd_ctxt->ps_sps || NULL == ps_svcd_ctxt->ps_pps)
1738 {
1739 return IV_FAIL;
1740 }
1741
1742 ps_svcd_ctxt->pv_nal_parse_ctxt = ps_nal_parse_ctxt;
1743 ps_nal_parse_ctxt->pv_seq_prms = ps_svcd_ctxt->ps_sps;
1744 ps_nal_parse_ctxt->pv_pic_prms = ps_svcd_ctxt->ps_pps;
1745
1746 /* register VCL and NON VCL buffer pointers */
1747 if(NULL == ps_svcd_ctxt->pv_vcl_nal_buff || NULL == ps_svcd_ctxt->pv_non_vcl_nal_buff)
1748 {
1749 return IV_FAIL;
1750 }
1751
1752 ps_nal_parse_ctxt->pv_vcl_nal_buf = (UWORD8 *) ps_svcd_ctxt->pv_vcl_nal_buff;
1753 ps_nal_parse_ctxt->pv_non_vcl_nal_buf = (UWORD8 *) ps_svcd_ctxt->pv_non_vcl_nal_buff;
1754 isvcd_nal_parse_reset_ctxt(ANNEX_B, PARTIAL_INPUT_MODE, ps_nal_parse_ctxt);
1755
1756 return IV_SUCCESS;
1757 }
1758
1759 /*****************************************************************************/
1760 /* */
1761 /* Function Name : isvcd_intra_resample_ctxt_create */
1762 /* */
1763 /* Description :this function is used to create intra_resamp context */
1764 /* Inputs : */
1765 /* Globals : none */
1766 /* Processing : */
1767 /* */
1768 /* Outputs : none */
1769 /* Returns : none */
1770 /* */
1771 /* Issues : none */
1772 /* */
1773 /* Revision History: */
1774 /* */
1775 /* DD MM YYYY Author(s) Changes (Describe the changes made) */
1776 /* 25 11 2021 Kishore creation */
1777 /* */
1778 /*****************************************************************************/
isvcd_intra_resample_ctxt_create(svc_dec_ctxt_t * ps_svcd_ctxt,void * pv_api_ip,void * pv_api_op)1779 WORD32 isvcd_intra_resample_ctxt_create(svc_dec_ctxt_t *ps_svcd_ctxt, void *pv_api_ip,
1780 void *pv_api_op)
1781 {
1782 isvcd_create_ip_t *ps_create_ip;
1783 svc_dec_lyr_struct_t *ps_svc_lyr_dec;
1784 void *pv_buf;
1785 UWORD8 u1_layer_id;
1786 void *(*pf_aligned_alloc)(void *pv_mem_ctxt, WORD32 alignment, WORD32 size);
1787 void *pv_mem_ctxt;
1788 WORD32 size;
1789 intra_inter_pred_ctxt_t *ps_ii_pred_ctxt;
1790
1791 intra_sampling_ctxt_t *ps_ctxt;
1792 UNUSED(pv_api_op);
1793 ps_create_ip = (isvcd_create_ip_t *) pv_api_ip;
1794
1795 pf_aligned_alloc = ps_create_ip->s_ivd_create_ip_t.pf_aligned_alloc;
1796 pv_mem_ctxt = ps_create_ip->s_ivd_create_ip_t.pv_mem_ctxt;
1797
1798 {
1799 intra_samp_lyr_ctxt *ps_lyr_ctxt;
1800
1801 /* allocate context structure */
1802 size = ((sizeof(intra_sampling_ctxt_t) + 127) >> 7) << 7;
1803 pv_buf = pf_aligned_alloc(pv_mem_ctxt, 128, size);
1804 RETURN_IF((NULL == pv_buf), IV_FAIL);
1805 memset(pv_buf, 0, size);
1806 ps_ctxt = pv_buf;
1807
1808 /* luma reference array buffer */
1809 size = REF_ARRAY_WIDTH * REF_ARRAY_HEIGHT * sizeof(UWORD8);
1810 pv_buf = pf_aligned_alloc(pv_mem_ctxt, 128, size);
1811 RETURN_IF((NULL == pv_buf), IV_FAIL);
1812 memset(pv_buf, 0, size);
1813 ps_ctxt->pu1_refarray_buffer = pv_buf;
1814
1815 /* cb reference array buffer */
1816 size = REF_ARRAY_WIDTH * REF_ARRAY_HEIGHT * sizeof(UWORD8);
1817 pv_buf = pf_aligned_alloc(pv_mem_ctxt, 128, size);
1818 RETURN_IF((NULL == pv_buf), IV_FAIL);
1819 memset(pv_buf, 0, size);
1820 ps_ctxt->pu1_refarray_cb = pv_buf;
1821
1822 /* cr reference array buffer */
1823 size = ((DYADIC_REF_W_C + 2) * (DYADIC_REF_H_C + 2) * sizeof(UWORD8));
1824 pv_buf = pf_aligned_alloc(pv_mem_ctxt, 128, size);
1825 RETURN_IF((NULL == pv_buf), IV_FAIL);
1826 memset(pv_buf, 0, size);
1827 ps_ctxt->pu1_refarray_cr = pv_buf;
1828
1829 /* Temp Intermediate Buffer */
1830 size = INTERMEDIATE_BUFF_WIDTH * INTERMEDIATE_BUFF_HEIGHT * sizeof(WORD32);
1831 pv_buf = pf_aligned_alloc(pv_mem_ctxt, 128, size);
1832 RETURN_IF((NULL == pv_buf), IV_FAIL);
1833 memset(pv_buf, 0, size);
1834 ps_ctxt->pi4_temp_interpolation_buffer = pv_buf;
1835
1836 /****************** projected locations buffers ******************/
1837 {
1838 intra_samp_map_ctxt_t *ps_luma_map;
1839 intra_samp_map_ctxt_t *ps_chroma_map;
1840 WORD32 i4_lyr_id;
1841 ref_mb_map_t *ps_off_len_map;
1842 ref_pixel_map_t *ps_pos_phase_map;
1843 ref_min_max_map_t *ps_min_max;
1844 WORD16 *pi2_mem;
1845 UWORD8 *pu1_mem;
1846 seg_lookup_desc_t *ps_seg_lookup;
1847
1848 /****************** Horz offset length ******************/
1849
1850 size = (H264_MAX_FRAME_WIDTH >> 4) * MAX_NUM_RES_LYRS * 2 * sizeof(ref_mb_map_t);
1851 pv_buf = pf_aligned_alloc(pv_mem_ctxt, 128, size);
1852 RETURN_IF((NULL == pv_buf), IV_FAIL);
1853 memset(pv_buf, 0, size);
1854 ps_off_len_map = pv_buf;
1855
1856 /* loop over num layers -1 */
1857 for(i4_lyr_id = 0; i4_lyr_id < MAX_NUM_RES_LYRS; i4_lyr_id++)
1858 {
1859 /* derive the layer map ctxt */
1860 ps_lyr_ctxt = &ps_ctxt->as_res_lyrs[i4_lyr_id];
1861 ps_luma_map = &ps_lyr_ctxt->s_luma_map_ctxt;
1862 ps_chroma_map = &ps_lyr_ctxt->s_chroma_map_ctxt;
1863
1864 /* initialise the pointers */
1865 ps_luma_map->ps_x_offset_length = ps_off_len_map;
1866 ps_off_len_map += (H264_MAX_FRAME_WIDTH >> 4);
1867 ps_chroma_map->ps_x_offset_length = ps_off_len_map;
1868 ps_off_len_map += (H264_MAX_FRAME_WIDTH >> 4);
1869
1870 } /* end of loop over resolution layers */
1871
1872 /****************** Vert offset length ******************/
1873 size = (H264_MAX_FRAME_HEIGHT >> 4) * MAX_NUM_RES_LYRS * 2 * sizeof(ref_mb_map_t);
1874 pv_buf = pf_aligned_alloc(pv_mem_ctxt, 128, size);
1875 RETURN_IF((NULL == pv_buf), IV_FAIL);
1876 memset(pv_buf, 0, size);
1877 ps_off_len_map = pv_buf;
1878
1879 /* loop over num layers -1 */
1880 for(i4_lyr_id = 0; i4_lyr_id < MAX_NUM_RES_LYRS; i4_lyr_id++)
1881 {
1882 /* derive the layer map ctxt */
1883 ps_lyr_ctxt = &ps_ctxt->as_res_lyrs[i4_lyr_id];
1884 ps_luma_map = &ps_lyr_ctxt->s_luma_map_ctxt;
1885 ps_chroma_map = &ps_lyr_ctxt->s_chroma_map_ctxt;
1886
1887 /* initialise the pointers */
1888 ps_luma_map->ps_y_offset_length = ps_off_len_map;
1889 ps_off_len_map += (H264_MAX_FRAME_HEIGHT >> 4);
1890 ps_chroma_map->ps_y_offset_length = ps_off_len_map;
1891 ps_off_len_map += (H264_MAX_FRAME_HEIGHT >> 4);
1892
1893 } /* end of loop over resolution layers */
1894
1895 /****************** Horz Min Max Pos ******************/
1896
1897 size = (H264_MAX_FRAME_WIDTH >> 4) * MAX_NUM_RES_LYRS * 2 * sizeof(ref_mb_map_t);
1898 pv_buf = pf_aligned_alloc(pv_mem_ctxt, 128, size);
1899 RETURN_IF((NULL == pv_buf), IV_FAIL);
1900 memset(pv_buf, 0, size);
1901 ps_min_max = pv_buf;
1902
1903 /* loop over num layers -1 */
1904 for(i4_lyr_id = 0; i4_lyr_id < MAX_NUM_RES_LYRS; i4_lyr_id++)
1905 {
1906 /* derive the layer map ctxt */
1907 ps_lyr_ctxt = &ps_ctxt->as_res_lyrs[i4_lyr_id];
1908 ps_luma_map = &ps_lyr_ctxt->s_luma_map_ctxt;
1909 ps_chroma_map = &ps_lyr_ctxt->s_chroma_map_ctxt;
1910
1911 /* initialise the pointers */
1912 ps_luma_map->ps_x_min_max = ps_min_max;
1913 ps_min_max += (H264_MAX_FRAME_WIDTH >> 4);
1914 ps_chroma_map->ps_x_min_max = ps_min_max;
1915 ps_min_max += (H264_MAX_FRAME_WIDTH >> 4);
1916 } /* end of loop over resolution layers */
1917
1918 /****************** Vert Min Max Pos ******************/
1919 size = (H264_MAX_FRAME_HEIGHT >> 4) * MAX_NUM_RES_LYRS * 2 * sizeof(ref_mb_map_t);
1920
1921 pv_buf = pf_aligned_alloc(pv_mem_ctxt, 128, size);
1922 RETURN_IF((NULL == pv_buf), IV_FAIL);
1923 memset(pv_buf, 0, size);
1924 ps_min_max = pv_buf;
1925
1926 /* loop over num layers -1 */
1927 for(i4_lyr_id = 0; i4_lyr_id < MAX_NUM_RES_LYRS; i4_lyr_id++)
1928 {
1929 /* derive the layer map ctxt */
1930 ps_lyr_ctxt = &ps_ctxt->as_res_lyrs[i4_lyr_id];
1931 ps_luma_map = &ps_lyr_ctxt->s_luma_map_ctxt;
1932 ps_chroma_map = &ps_lyr_ctxt->s_chroma_map_ctxt;
1933
1934 /* initialise the pointers */
1935 ps_luma_map->ps_y_min_max = ps_min_max;
1936 ps_min_max += (H264_MAX_FRAME_HEIGHT >> 4);
1937 ps_chroma_map->ps_y_min_max = ps_min_max;
1938 ps_min_max += (H264_MAX_FRAME_HEIGHT >> 4);
1939
1940 } /* end of loop over resolution layers */
1941
1942 /****************** Horz position phase ******************/
1943 size = (H264_MAX_FRAME_WIDTH) *MAX_NUM_RES_LYRS * 2 * sizeof(ref_pixel_map_t);
1944 pv_buf = pf_aligned_alloc(pv_mem_ctxt, 128, size);
1945 RETURN_IF((NULL == pv_buf), IV_FAIL);
1946 memset(pv_buf, 0, size);
1947 ps_pos_phase_map = pv_buf;
1948
1949 /* loop over num layers -1 */
1950 for(i4_lyr_id = 0; i4_lyr_id < MAX_NUM_RES_LYRS; i4_lyr_id++)
1951 {
1952 /* derive the layer map ctxt */
1953 ps_lyr_ctxt = &ps_ctxt->as_res_lyrs[i4_lyr_id];
1954 ps_luma_map = &ps_lyr_ctxt->s_luma_map_ctxt;
1955 ps_chroma_map = &ps_lyr_ctxt->s_chroma_map_ctxt;
1956
1957 /* initialise the pointers */
1958 ps_luma_map->ps_x_pos_phase = ps_pos_phase_map;
1959 ps_pos_phase_map += (H264_MAX_FRAME_WIDTH);
1960 ps_chroma_map->ps_x_pos_phase = ps_pos_phase_map;
1961 ps_pos_phase_map += (H264_MAX_FRAME_WIDTH);
1962
1963 } /* end of loop over resolution layers */
1964
1965 /****************** Vert position phase ******************/
1966
1967 size = (H264_MAX_FRAME_HEIGHT) *MAX_NUM_RES_LYRS * 2 * sizeof(ref_pixel_map_t);
1968 pv_buf = pf_aligned_alloc(pv_mem_ctxt, 128, size);
1969 RETURN_IF((NULL == pv_buf), IV_FAIL);
1970 memset(pv_buf, 0, size);
1971 ps_pos_phase_map = pv_buf;
1972
1973 /* loop over num layers -1 */
1974 for(i4_lyr_id = 0; i4_lyr_id < MAX_NUM_RES_LYRS; i4_lyr_id++)
1975 {
1976 /* derive the layer map ctxt */
1977 ps_lyr_ctxt = &ps_ctxt->as_res_lyrs[i4_lyr_id];
1978 ps_luma_map = &ps_lyr_ctxt->s_luma_map_ctxt;
1979 ps_chroma_map = &ps_lyr_ctxt->s_chroma_map_ctxt;
1980
1981 /* initialise the pointers */
1982 ps_luma_map->ps_y_pos_phase = ps_pos_phase_map;
1983 ps_pos_phase_map += (H264_MAX_FRAME_HEIGHT);
1984 ps_chroma_map->ps_y_pos_phase = ps_pos_phase_map;
1985 ps_pos_phase_map += (H264_MAX_FRAME_HEIGHT);
1986
1987 } /* end of loop over resolution layers */
1988
1989 /**************** XD Index ******************************/
1990 size = (MB_WIDTH) *MAX_NUM_RES_LYRS * 2 * sizeof(WORD16);
1991 pv_buf = pf_aligned_alloc(pv_mem_ctxt, 128, size);
1992 RETURN_IF((NULL == pv_buf), IV_FAIL);
1993 memset(pv_buf, 0, size);
1994 pi2_mem = pv_buf;
1995
1996 /* loop over num layers -1 */
1997 for(i4_lyr_id = 0; i4_lyr_id < MAX_NUM_RES_LYRS; i4_lyr_id++)
1998 {
1999 /* derive the layer map ctxt */
2000 ps_lyr_ctxt = &ps_ctxt->as_res_lyrs[i4_lyr_id];
2001 ps_luma_map = &ps_lyr_ctxt->s_luma_map_ctxt;
2002 ps_chroma_map = &ps_lyr_ctxt->s_chroma_map_ctxt;
2003
2004 /* initialise the pointers */
2005 ps_luma_map->pi2_xd_index = pi2_mem;
2006 pi2_mem += MB_WIDTH;
2007 ps_chroma_map->pi2_xd_index = pi2_mem;
2008 pi2_mem += MB_WIDTH;
2009
2010 } /* end of loop over resolution layers */
2011
2012 /**************** YD Index ******************************/
2013 size = (MB_HEIGHT) *MAX_NUM_RES_LYRS * 2 * sizeof(WORD16);
2014 pv_buf = pf_aligned_alloc(pv_mem_ctxt, 128, size);
2015 RETURN_IF((NULL == pv_buf), IV_FAIL);
2016 memset(pv_buf, 0, size);
2017 pi2_mem = pv_buf;
2018
2019 /* loop over num layers -1 */
2020 for(i4_lyr_id = 0; i4_lyr_id < MAX_NUM_RES_LYRS; i4_lyr_id++)
2021 {
2022 /* derive the layer map ctxt */
2023 ps_lyr_ctxt = &ps_ctxt->as_res_lyrs[i4_lyr_id];
2024 ps_luma_map = &ps_lyr_ctxt->s_luma_map_ctxt;
2025 ps_chroma_map = &ps_lyr_ctxt->s_chroma_map_ctxt;
2026
2027 /* initialise the pointers */
2028 ps_luma_map->pi2_yd_index = pi2_mem;
2029 pi2_mem += MB_HEIGHT;
2030 ps_chroma_map->pi2_yd_index = pi2_mem;
2031 pi2_mem += MB_HEIGHT;
2032
2033 } /* end of loop over resolution layers */
2034
2035 /**************** YA Index ******************************/
2036 size = MB_HEIGHT * MAX_NUM_RES_LYRS * 2 * sizeof(WORD16);
2037 pv_buf = pf_aligned_alloc(pv_mem_ctxt, 128, size);
2038 RETURN_IF((NULL == pv_buf), IV_FAIL);
2039 memset(pv_buf, 0, size);
2040 pi2_mem = pv_buf;
2041
2042 /* loop over num layers -1 */
2043 for(i4_lyr_id = 0; i4_lyr_id < MAX_NUM_RES_LYRS; i4_lyr_id++)
2044 {
2045 /* derive the layer map ctxt */
2046 ps_lyr_ctxt = &ps_ctxt->as_res_lyrs[i4_lyr_id];
2047 ps_luma_map = &ps_lyr_ctxt->s_luma_map_ctxt;
2048 ps_chroma_map = &ps_lyr_ctxt->s_chroma_map_ctxt;
2049
2050 /* initialise the pointers */
2051 ps_luma_map->pi2_ya_index = pi2_mem;
2052 pi2_mem += MB_HEIGHT;
2053 ps_chroma_map->pi2_ya_index = pi2_mem;
2054 pi2_mem += MB_HEIGHT;
2055
2056 } /* end of loop over resolution layers */
2057
2058 /**************** Horizontal segment lookup **************************/
2059 /* (MB_WIDTH x seg_lookup_desc_t) x (num layers - 1) (for luma )*/
2060 /* (BLOCK_WIDTH x seg_lookup_desc_t) x (num layers - 1) (for chroma )*/
2061 size = (MB_WIDTH * sizeof(seg_lookup_desc_t)) * MAX_NUM_RES_LYRS;
2062
2063 size += (BLOCK_WIDTH * sizeof(seg_lookup_desc_t)) * MAX_NUM_RES_LYRS;
2064
2065 pv_buf = pf_aligned_alloc(pv_mem_ctxt, 128, size);
2066 RETURN_IF((NULL == pv_buf), IV_FAIL);
2067 memset(pv_buf, 0, size);
2068 ps_seg_lookup = pv_buf;
2069
2070 /* loop over num layers -1 */
2071 for(i4_lyr_id = 0; i4_lyr_id < MAX_NUM_RES_LYRS; i4_lyr_id++)
2072 {
2073 /* derive the layer map ctxt */
2074 ps_lyr_ctxt = &ps_ctxt->as_res_lyrs[i4_lyr_id];
2075 ps_luma_map = &ps_lyr_ctxt->s_luma_map_ctxt;
2076 ps_chroma_map = &ps_lyr_ctxt->s_chroma_map_ctxt;
2077
2078 /* initialise the pointers */
2079 ps_luma_map->ps_seg_lookup_horz = ps_seg_lookup;
2080 ps_seg_lookup += MB_WIDTH;
2081 ps_chroma_map->ps_seg_lookup_horz = ps_seg_lookup;
2082 ps_seg_lookup += BLOCK_WIDTH;
2083
2084 } /* end of loop over resolution layers */
2085
2086 /**************** Vertical segment lookup ****************************/
2087 /* (MB_HEIGHT x seg_lookup_desc_t) x (num layers - 1) (for luma )*/
2088 /* (BLOCK_HEIGHT x seg_lookup_desc_t) x (num layers - 1) (for chroma)*/
2089 size = (MB_HEIGHT * sizeof(seg_lookup_desc_t)) * MAX_NUM_RES_LYRS;
2090
2091 size += (BLOCK_HEIGHT * sizeof(seg_lookup_desc_t)) * MAX_NUM_RES_LYRS;
2092
2093 pv_buf = pf_aligned_alloc(pv_mem_ctxt, 128, size);
2094 RETURN_IF((NULL == pv_buf), IV_FAIL);
2095 memset(pv_buf, 0, size);
2096 ps_seg_lookup = pv_buf;
2097
2098 /* loop over num layers -1 */
2099 for(i4_lyr_id = 0; i4_lyr_id < MAX_NUM_RES_LYRS; i4_lyr_id++)
2100 {
2101 /* derive the layer map ctxt */
2102 ps_lyr_ctxt = &ps_ctxt->as_res_lyrs[i4_lyr_id];
2103 ps_luma_map = &ps_lyr_ctxt->s_luma_map_ctxt;
2104 ps_chroma_map = &ps_lyr_ctxt->s_chroma_map_ctxt;
2105
2106 /* initialise the pointers */
2107 ps_luma_map->ps_seg_lookup_vert = ps_seg_lookup;
2108 ps_seg_lookup += MB_HEIGHT;
2109 ps_chroma_map->ps_seg_lookup_vert = ps_seg_lookup;
2110 ps_seg_lookup += BLOCK_HEIGHT;
2111
2112 } /* end of loop over resolution layers */
2113
2114 /**************** X and Y Reference Array Index lookup ***************/
2115 /* (MAX_REF_IDX_ARRAY) x (num layers - 1) (for luma x-index) */
2116 /* (MAX_REF_IDX_ARRAY) x (num layers - 1) (for luma y-index) */
2117 /* (MAX_REF_IDX_ARRAY) x (num layers - 1) (for chroma x-index) */
2118 /* (MAX_REF_IDX_ARRAY) x (num layers - 1) (for chroma y-index) */
2119 /*********************************************************************/
2120 size = (MAX_REF_IDX_ARRAY * MAX_NUM_RES_LYRS * 4);
2121 pv_buf = pf_aligned_alloc(pv_mem_ctxt, 128, size);
2122 RETURN_IF((NULL == pv_buf), IV_FAIL);
2123 memset(pv_buf, 0, size);
2124 pu1_mem = pv_buf;
2125
2126 /* loop over num layers -1 */
2127 for(i4_lyr_id = 0; i4_lyr_id < MAX_NUM_RES_LYRS; i4_lyr_id++)
2128 {
2129 /* derive the layer map ctxt */
2130 ps_lyr_ctxt = &ps_ctxt->as_res_lyrs[i4_lyr_id];
2131 ps_luma_map = &ps_lyr_ctxt->s_luma_map_ctxt;
2132 ps_chroma_map = &ps_lyr_ctxt->s_chroma_map_ctxt;
2133
2134 /* initialise the pointers */
2135 ps_luma_map->pu1_refarray_x_idx = pu1_mem;
2136 pu1_mem += MAX_REF_IDX_ARRAY;
2137
2138 ps_luma_map->pu1_refarray_y_idx = pu1_mem;
2139 pu1_mem += MAX_REF_IDX_ARRAY;
2140
2141 ps_chroma_map->pu1_refarray_x_idx = pu1_mem;
2142 pu1_mem += MAX_REF_IDX_ARRAY;
2143
2144 ps_chroma_map->pu1_refarray_y_idx = pu1_mem;
2145 pu1_mem += MAX_REF_IDX_ARRAY;
2146
2147 } /* end of loop over resolution layers */
2148 }
2149
2150 size = ((sizeof(intra_inter_pred_ctxt_t) + 127) >> 7) << 7;
2151 pv_buf = pf_aligned_alloc(pv_mem_ctxt, 128, size);
2152 RETURN_IF((NULL == pv_buf), IV_FAIL);
2153 memset(pv_buf, 0, size);
2154 ps_ii_pred_ctxt = pv_buf;
2155 }
2156
2157 ps_svcd_ctxt->pv_intra_sample_ctxt = ps_ctxt;
2158 ps_svcd_ctxt->pv_ii_pred_ctxt = ps_ii_pred_ctxt;
2159
2160 for(u1_layer_id = 0; u1_layer_id < MAX_NUM_RES_LYRS; u1_layer_id++)
2161 {
2162 ps_svc_lyr_dec = &ps_svcd_ctxt->ps_svc_dec_lyr[u1_layer_id];
2163 ps_svc_lyr_dec->pv_intra_sample_ctxt = ps_svcd_ctxt->pv_intra_sample_ctxt;
2164 ps_svc_lyr_dec->pv_ii_pred_ctxt = ps_svcd_ctxt->pv_ii_pred_ctxt;
2165 }
2166
2167 return IV_SUCCESS;
2168 }
2169
2170 /*****************************************************************************/
2171 /* */
2172 /* Function Name : isvcd_residual_resample_ctxt_create */
2173 /* */
2174 /* Description :this function is used to create resd_resamp context */
2175 /* Inputs : */
2176 /* Globals : none */
2177 /* Processing : */
2178 /* */
2179 /* Outputs : none */
2180 /* Returns : none */
2181 /* */
2182 /* Issues : none */
2183 /* */
2184 /* Revision History: */
2185 /* */
2186 /* DD MM YYYY Author(s) Changes (Describe the changes made) */
2187 /* 25 11 2021 ittiam creation */
2188 /* */
2189 /*****************************************************************************/
isvcd_residual_resample_ctxt_create(svc_dec_ctxt_t * ps_svcd_ctxt,void * pv_api_ip,void * pv_api_op)2190 WORD32 isvcd_residual_resample_ctxt_create(svc_dec_ctxt_t *ps_svcd_ctxt, void *pv_api_ip,
2191 void *pv_api_op)
2192 {
2193 isvcd_create_ip_t *ps_create_ip;
2194 svc_dec_lyr_struct_t *ps_svc_lyr_dec;
2195 void *pv_buf;
2196 UWORD8 u1_layer_id;
2197 void *(*pf_aligned_alloc)(void *pv_mem_ctxt, WORD32 alignment, WORD32 size);
2198 void *pv_mem_ctxt;
2199 WORD32 size;
2200
2201 residual_sampling_ctxt_t *ps_ctxt;
2202 res_lyr_ctxt *ps_lyr_ctxt;
2203 UNUSED(pv_api_op);
2204 ps_create_ip = (isvcd_create_ip_t *) pv_api_ip;
2205
2206 pf_aligned_alloc = ps_create_ip->s_ivd_create_ip_t.pf_aligned_alloc;
2207 pv_mem_ctxt = ps_create_ip->s_ivd_create_ip_t.pv_mem_ctxt;
2208
2209 /* allocate context structure */
2210 size = ((sizeof(residual_sampling_ctxt_t) + 127) >> 7) << 7;
2211 pv_buf = pf_aligned_alloc(pv_mem_ctxt, 128, size);
2212 RETURN_IF((NULL == pv_buf), IV_FAIL);
2213 memset(pv_buf, 0, size);
2214 ps_ctxt = pv_buf;
2215
2216 /* reference array buffer */
2217 size = REF_ARRAY_WIDTH_RES_SAMP * REF_ARRAY_HEIGHT_RES_SAMP * sizeof(WORD16);
2218 pv_buf = pf_aligned_alloc(pv_mem_ctxt, 128, size);
2219 RETURN_IF((NULL == pv_buf), IV_FAIL);
2220 memset(pv_buf, 0, size);
2221 ps_ctxt->pi2_refarray_buffer = pv_buf;
2222
2223 /* reference array pointer increment buffer */
2224 {
2225 WORD32 i4_size;
2226
2227 i4_size = REF_ARRAY_WIDTH_RES_SAMP * REF_ARRAY_HEIGHT_RES_SAMP * sizeof(UWORD8);
2228 size = REF_ARRAY_WIDTH_RES_SAMP * REF_ARRAY_HEIGHT_RES_SAMP * 2 * sizeof(UWORD8);
2229 pv_buf = pf_aligned_alloc(pv_mem_ctxt, 128, size);
2230 RETURN_IF((NULL == pv_buf), IV_FAIL);
2231 memset(pv_buf, 0, size);
2232 ps_ctxt->pu1_ref_x_ptr_incr = pv_buf;
2233 ps_ctxt->pu1_ref_y_ptr_incr = ps_ctxt->pu1_ref_x_ptr_incr + i4_size;
2234 }
2235
2236 /****************** projected locations buffers ******************/
2237 {
2238 residual_samp_map_ctxt_t *ps_luma_map;
2239 residual_samp_map_ctxt_t *ps_chroma_map;
2240 WORD32 i4_lyr_id;
2241 ref_mb_map_t *ps_off_len_map;
2242 ref_pixel_map_t *ps_pos_phase_map;
2243
2244 /****************** Horz offset length ******************/
2245 size = (H264_MAX_FRAME_WIDTH >> 4) * MAX_NUM_RES_LYRS * 2 * sizeof(ref_mb_map_t);
2246 pv_buf = pf_aligned_alloc(pv_mem_ctxt, 128, size);
2247 RETURN_IF((NULL == pv_buf), IV_FAIL);
2248 memset(pv_buf, 0, size);
2249 ps_off_len_map = pv_buf;
2250
2251 /* loop over num layers -1 */
2252 for(i4_lyr_id = 0; i4_lyr_id < MAX_NUM_RES_LYRS; i4_lyr_id++)
2253 {
2254 /* derive the layer map ctxt */
2255 ps_lyr_ctxt = &ps_ctxt->as_res_lyrs[i4_lyr_id];
2256 ps_luma_map = &ps_lyr_ctxt->s_luma_map_ctxt;
2257 ps_chroma_map = &ps_lyr_ctxt->s_chroma_map_ctxt;
2258
2259 /* initialise the pointers */
2260 ps_luma_map->ps_x_offset_length = ps_off_len_map;
2261 ps_off_len_map += (H264_MAX_FRAME_WIDTH >> 4);
2262 ps_chroma_map->ps_x_offset_length = ps_off_len_map;
2263 ps_off_len_map += (H264_MAX_FRAME_WIDTH >> 4);
2264
2265 } /* end of loop over resolution layers */
2266
2267 /****************** Vert offset length ******************/
2268 size = (H264_MAX_FRAME_HEIGHT >> 4) * MAX_NUM_RES_LYRS * 2 * sizeof(ref_mb_map_t);
2269 pv_buf = pf_aligned_alloc(pv_mem_ctxt, 128, size);
2270 RETURN_IF((NULL == pv_buf), IV_FAIL);
2271 memset(pv_buf, 0, size);
2272 ps_off_len_map = pv_buf;
2273
2274 /* loop over num layers -1 */
2275 for(i4_lyr_id = 0; i4_lyr_id < MAX_NUM_RES_LYRS; i4_lyr_id++)
2276 {
2277 /* derive the layer map ctxt */
2278 ps_lyr_ctxt = &ps_ctxt->as_res_lyrs[i4_lyr_id];
2279 ps_luma_map = &ps_lyr_ctxt->s_luma_map_ctxt;
2280 ps_chroma_map = &ps_lyr_ctxt->s_chroma_map_ctxt;
2281
2282 /* initialise the pointers */
2283 ps_luma_map->ps_y_offset_length = ps_off_len_map;
2284 ps_off_len_map += (H264_MAX_FRAME_HEIGHT >> 4);
2285 ps_chroma_map->ps_y_offset_length = ps_off_len_map;
2286 ps_off_len_map += (H264_MAX_FRAME_HEIGHT >> 4);
2287
2288 } /* end of loop over resolution layers */
2289
2290 /****************** Horz position phase ******************/
2291 size = H264_MAX_FRAME_WIDTH * MAX_NUM_RES_LYRS * 2 * sizeof(ref_pixel_map_t);
2292 pv_buf = pf_aligned_alloc(pv_mem_ctxt, 128, size);
2293 RETURN_IF((NULL == pv_buf), IV_FAIL);
2294 memset(pv_buf, 0, size);
2295 ps_pos_phase_map = pv_buf;
2296
2297 /* loop over num layers -1 */
2298 for(i4_lyr_id = 0; i4_lyr_id < MAX_NUM_RES_LYRS; i4_lyr_id++)
2299 {
2300 /* derive the layer map ctxt */
2301 ps_lyr_ctxt = &ps_ctxt->as_res_lyrs[i4_lyr_id];
2302 ps_luma_map = &ps_lyr_ctxt->s_luma_map_ctxt;
2303 ps_chroma_map = &ps_lyr_ctxt->s_chroma_map_ctxt;
2304
2305 /* initialise the pointers */
2306 ps_luma_map->ps_x_pos_phase = ps_pos_phase_map;
2307 ps_pos_phase_map += H264_MAX_FRAME_WIDTH;
2308 ps_chroma_map->ps_x_pos_phase = ps_pos_phase_map;
2309 ps_pos_phase_map += H264_MAX_FRAME_WIDTH;
2310
2311 } /* end of loop over resolution layers */
2312
2313 /****************** Vert position phase ******************/
2314
2315 size = H264_MAX_FRAME_HEIGHT * MAX_NUM_RES_LYRS * 2 * sizeof(ref_pixel_map_t);
2316 pv_buf = pf_aligned_alloc(pv_mem_ctxt, 128, size);
2317 RETURN_IF((NULL == pv_buf), IV_FAIL);
2318 memset(pv_buf, 0, size);
2319 ps_pos_phase_map = pv_buf;
2320
2321 /* loop over num layers -1 */
2322 for(i4_lyr_id = 0; i4_lyr_id < MAX_NUM_RES_LYRS; i4_lyr_id++)
2323 {
2324 /* derive the layer map ctxt */
2325 ps_lyr_ctxt = &ps_ctxt->as_res_lyrs[i4_lyr_id];
2326 ps_luma_map = &ps_lyr_ctxt->s_luma_map_ctxt;
2327 ps_chroma_map = &ps_lyr_ctxt->s_chroma_map_ctxt;
2328
2329 /* initialise the pointers */
2330 ps_luma_map->ps_y_pos_phase = ps_pos_phase_map;
2331 ps_pos_phase_map += H264_MAX_FRAME_HEIGHT;
2332 ps_chroma_map->ps_y_pos_phase = ps_pos_phase_map;
2333 ps_pos_phase_map += H264_MAX_FRAME_HEIGHT;
2334
2335 } /* end of loop over resolution layers */
2336 }
2337
2338 ps_svcd_ctxt->pv_residual_sample_ctxt = ps_ctxt;
2339
2340 for(u1_layer_id = 0; u1_layer_id < MAX_NUM_RES_LYRS; u1_layer_id++)
2341 {
2342 ps_svc_lyr_dec = &ps_svcd_ctxt->ps_svc_dec_lyr[u1_layer_id];
2343 ps_svc_lyr_dec->pv_residual_sample_ctxt = ps_svcd_ctxt->pv_residual_sample_ctxt;
2344 }
2345 return IV_SUCCESS;
2346 }
2347 /*****************************************************************************/
2348 /* */
2349 /* Function Name : isvcd_mode_mv_resample_ctxt_create */
2350 /* */
2351 /* Description :this function is used to create mv_resamp context */
2352 /* Inputs : */
2353 /* Globals : none */
2354 /* Processing : */
2355 /* */
2356 /* Outputs : none */
2357 /* Returns : none */
2358 /* */
2359 /* Issues : none */
2360 /* */
2361 /* Revision History: */
2362 /* */
2363 /* DD MM YYYY Author(s) Changes (Describe the changes made) */
2364 /* 25 11 2021 Kishore creation */
2365 /* */
2366 /*****************************************************************************/
isvcd_mode_mv_resample_ctxt_create(svc_dec_ctxt_t * ps_svcd_ctxt,void * pv_api_ip,void * pv_api_op)2367 WORD32 isvcd_mode_mv_resample_ctxt_create(svc_dec_ctxt_t *ps_svcd_ctxt, void *pv_api_ip,
2368 void *pv_api_op)
2369 {
2370 isvcd_create_ip_t *ps_create_ip;
2371 svc_dec_lyr_struct_t *ps_svc_lyr_dec;
2372 void *pv_buf;
2373 WORD16 *pi2_mem;
2374 UWORD8 u1_layer_id;
2375 void *(*pf_aligned_alloc)(void *pv_mem_ctxt, WORD32 alignment, WORD32 size);
2376 void *pv_mem_ctxt;
2377 WORD32 size, i4_res_id;
2378 ref_lyr_scaled_offset_t *ps_ref_pic_offsets;
2379 mode_motion_ctxt_t *ps_mode_motion;
2380 mode_motion_lyr_ctxt *ps_lyr_mem;
2381 UNUSED(pv_api_op);
2382 ps_create_ip = (isvcd_create_ip_t *) pv_api_ip;
2383
2384 pf_aligned_alloc = ps_create_ip->s_ivd_create_ip_t.pf_aligned_alloc;
2385 pv_mem_ctxt = ps_create_ip->s_ivd_create_ip_t.pv_mem_ctxt;
2386
2387 size = ((sizeof(mode_motion_ctxt_t) + 127) >> 7) << 7;
2388 pv_buf = pf_aligned_alloc(pv_mem_ctxt, 128, size);
2389 RETURN_IF((NULL == pv_buf), IV_FAIL);
2390 memset(pv_buf, 0, size);
2391 ps_mode_motion = pv_buf;
2392
2393 /* motion pred structure */
2394 size = 2 * NUM_MB_PARTS * NUM_SUB_MB_PARTS * sizeof(mv_pred_t);
2395 pv_buf = pf_aligned_alloc(pv_mem_ctxt, 128, size);
2396 RETURN_IF((NULL == pv_buf), IV_FAIL);
2397 memset(pv_buf, 0, size);
2398 ps_mode_motion->ps_motion_pred_struct = (mv_pred_t *) pv_buf;
2399
2400 /* projected locations X */
2401 size = H264_MAX_FRAME_WIDTH * MAX_NUM_RES_LYRS * sizeof(WORD16);
2402 pv_buf = pf_aligned_alloc(pv_mem_ctxt, 128, size);
2403 RETURN_IF((NULL == pv_buf), IV_FAIL);
2404 memset(pv_buf, 0, size);
2405 pi2_mem = (WORD16 *) pv_buf;
2406
2407 /* loop over NUM resolution layers */
2408 for(i4_res_id = 0; i4_res_id < MAX_NUM_RES_LYRS; i4_res_id++)
2409 {
2410 ps_lyr_mem = &ps_mode_motion->as_res_lyr_mem[i4_res_id];
2411
2412 /* initialise the pointers */
2413 ps_lyr_mem->pi2_ref_loc_x = pi2_mem;
2414
2415 /* increment the buffer pointer */
2416 pi2_mem += H264_MAX_FRAME_WIDTH;
2417
2418 } /* end of loop over num resolution layers */
2419
2420 /* projected locations Y */
2421 size = H264_MAX_FRAME_HEIGHT * MAX_NUM_RES_LYRS * sizeof(WORD16);
2422 pv_buf = pf_aligned_alloc(pv_mem_ctxt, 128, size);
2423 RETURN_IF((NULL == pv_buf), IV_FAIL);
2424 memset(pv_buf, 0, size);
2425 pi2_mem = (WORD16 *) pv_buf;
2426 /* loop over NUM resolution layers */
2427 for(i4_res_id = 0; i4_res_id < MAX_NUM_RES_LYRS; i4_res_id++)
2428 {
2429 ps_lyr_mem = &ps_mode_motion->as_res_lyr_mem[i4_res_id];
2430
2431 /* initialise the pointers */
2432 ps_lyr_mem->pi2_ref_loc_y = pi2_mem;
2433 /* increment the buffer pointer */
2434 pi2_mem += H264_MAX_FRAME_HEIGHT;
2435
2436 } /* end of loop over num resolution layers */
2437
2438 size = sizeof(ref_lyr_scaled_offset_t) * MAX_NUM_RES_LYRS * MAX_NUM_PIC_BUFS;
2439 pv_buf = pf_aligned_alloc(pv_mem_ctxt, 128, size);
2440 RETURN_IF((NULL == pv_buf), IV_FAIL);
2441 memset(pv_buf, 0, size);
2442 ps_svcd_ctxt->pv_ref_lyr_offset = pv_buf;
2443
2444 /* loop over NUM resolution layers */
2445 ps_ref_pic_offsets = (ref_lyr_scaled_offset_t *) ps_svcd_ctxt->pv_ref_lyr_offset;
2446
2447 for(i4_res_id = 0; i4_res_id < MAX_NUM_RES_LYRS; i4_res_id++)
2448 {
2449 ps_lyr_mem = &ps_mode_motion->as_res_lyr_mem[i4_res_id];
2450
2451 /* store the current resolution layer pic offset start pointer */
2452 ps_lyr_mem->ps_ref_pic_lyr_offsets = ps_ref_pic_offsets + (i4_res_id * MAX_NUM_PIC_BUFS);
2453
2454 } /* end of loop over num resolution layers */
2455
2456 ps_svcd_ctxt->pv_mode_mv_sample_ctxt = ps_mode_motion;
2457
2458 for(u1_layer_id = 0; u1_layer_id < MAX_NUM_RES_LYRS; u1_layer_id++)
2459 {
2460 ps_svc_lyr_dec = &ps_svcd_ctxt->ps_svc_dec_lyr[u1_layer_id];
2461 ps_svc_lyr_dec->pv_mode_mv_sample_ctxt = ps_svcd_ctxt->pv_mode_mv_sample_ctxt;
2462 ps_svc_lyr_dec->pv_ref_lyr_offset = ps_svcd_ctxt->pv_ref_lyr_offset;
2463 }
2464 return IV_SUCCESS;
2465 }
2466 /*****************************************************************************/
2467 /* */
2468 /* Function Name : isvcd_allocate_static_bufs */
2469 /* */
2470 /* Description : allocates static buffers */
2471 /* */
2472 /* Inputs :iv_obj_t decoder handle */
2473 /* :pv_api_ip pointer to input structure */
2474 /* :pv_api_op pointer to output structure */
2475 /* Outputs : */
2476 /* Returns : void */
2477 /* */
2478 /* Issues : none */
2479 /* */
2480 /* Revision History: */
2481 /* */
2482 /* DD MM YYYY Author(s) Changes (Describe the changes made) */
2483 /* 06 09 2021 Kishore Draft */
2484 /* */
2485 /*****************************************************************************/
isvcd_allocate_static_bufs(iv_obj_t ** dec_hdl,void * pv_api_ip,void * pv_api_op)2486 WORD32 isvcd_allocate_static_bufs(iv_obj_t **dec_hdl, void *pv_api_ip, void *pv_api_op)
2487 {
2488 isvcd_create_ip_t *ps_create_ip;
2489 isvcd_create_op_t *ps_create_op;
2490 void *pv_buf;
2491 UWORD8 *pu1_buf;
2492 dec_struct_t *ps_dec;
2493 svc_dec_lyr_struct_t *ps_svc_lyr_dec;
2494 svc_dec_ctxt_t *ps_svcd_ctxt;
2495 void *(*pf_aligned_alloc)(void *pv_mem_ctxt, WORD32 alignment, WORD32 size);
2496 void (*pf_aligned_free)(void *pv_mem_ctxt, void *pv_buf);
2497 void *pv_mem_ctxt;
2498 WORD32 size;
2499 UWORD8 u1_layer_id, u1_sps_ctr;
2500 UWORD8 u1_chroma_format;
2501 WORD32 ret;
2502
2503 ps_create_ip = (isvcd_create_ip_t *) pv_api_ip;
2504 ps_create_op = (isvcd_create_op_t *) pv_api_op;
2505
2506 ps_create_op->s_ivd_create_op_t.u4_error_code = 0;
2507 pf_aligned_alloc = ps_create_ip->s_ivd_create_ip_t.pf_aligned_alloc;
2508 pf_aligned_free = ps_create_ip->s_ivd_create_ip_t.pf_aligned_free;
2509 pv_mem_ctxt = ps_create_ip->s_ivd_create_ip_t.pv_mem_ctxt;
2510 u1_chroma_format = (UWORD8) (ps_create_ip->s_ivd_create_ip_t.e_output_format);
2511
2512 if((u1_chroma_format != IV_YUV_420P) && (u1_chroma_format != IV_YUV_420SP_UV) &&
2513 (u1_chroma_format != IV_YUV_420SP_VU))
2514 {
2515 ps_create_op->s_ivd_create_op_t.pv_handle = NULL;
2516
2517 return IV_FAIL;
2518 }
2519
2520 /* Initialize return handle to NULL */
2521 ps_create_op->s_ivd_create_op_t.pv_handle = NULL;
2522 pv_buf = pf_aligned_alloc(pv_mem_ctxt, 128, sizeof(iv_obj_t));
2523 RETURN_IF((NULL == pv_buf), IV_FAIL);
2524 memset(pv_buf, 0, sizeof(iv_obj_t));
2525 *dec_hdl = (iv_obj_t *) pv_buf;
2526 ps_create_op->s_ivd_create_op_t.pv_handle = *dec_hdl;
2527
2528 (*dec_hdl)->pv_codec_handle = NULL;
2529 pv_buf = pf_aligned_alloc(pv_mem_ctxt, 128, sizeof(svc_dec_ctxt_t));
2530 RETURN_IF((NULL == pv_buf), IV_FAIL);
2531 (*dec_hdl)->pv_codec_handle = (svc_dec_ctxt_t *) pv_buf;
2532 ps_svcd_ctxt = (svc_dec_ctxt_t *) pv_buf;
2533
2534 memset(ps_svcd_ctxt, 0, sizeof(svc_dec_ctxt_t));
2535
2536 ps_svcd_ctxt->u1_prev_num_res_layers = UINT8_MAX;
2537 ps_svcd_ctxt->u1_pre_parse_in_flush = 1;
2538 /* set default to maximum values supported */
2539 ps_svcd_ctxt->u1_tgt_dep_id = MAX_DEPENDENCY_ID;
2540 ps_svcd_ctxt->u1_tgt_quality_id = MAX_QUALITY_ID;
2541 ps_svcd_ctxt->u1_tgt_temp_id = MAX_TEMPORAL_ID;
2542 ps_svcd_ctxt->u1_tgt_priority_id = MAX_PRIORITY_ID;
2543
2544 /* two sets of MAX_NUM_SEQ_PARAMS are created one for sps-base layer; one for
2545 * subset_sps- enhancement*/
2546 size = ((sizeof(dec_seq_params_t)) * MAX_NUM_SEQ_PARAMS * 2);
2547 pv_buf = pf_aligned_alloc(pv_mem_ctxt, 128, size);
2548 RETURN_IF((NULL == pv_buf), IV_FAIL);
2549 memset(pv_buf, 0, size);
2550 ps_svcd_ctxt->ps_sps = pv_buf;
2551
2552 /* two sets of MAX_NUM_SEQ_PARAMS are created one for sps-base layer; one for
2553 * subset_sps- enhancement*/
2554 size = ((sizeof(dec_svc_seq_params_t)) * MAX_NUM_SEQ_PARAMS * 2);
2555 pv_buf = pf_aligned_alloc(pv_mem_ctxt, 128, size);
2556 RETURN_IF((NULL == pv_buf), IV_FAIL);
2557 memset(pv_buf, 0, size);
2558 ps_svcd_ctxt->ps_subset_sps = pv_buf;
2559
2560 for(u1_sps_ctr = 0; u1_sps_ctr < (2 * MAX_NUM_SEQ_PARAMS); u1_sps_ctr++)
2561 {
2562 ps_svcd_ctxt->ps_subset_sps[u1_sps_ctr].ps_seq = &ps_svcd_ctxt->ps_sps[u1_sps_ctr];
2563 }
2564
2565 size = sizeof(sei);
2566 pv_buf = pf_aligned_alloc(pv_mem_ctxt, 128, size);
2567 RETURN_IF((NULL == pv_buf), IV_FAIL);
2568 memset(pv_buf, 0, size);
2569 ps_svcd_ctxt->ps_sei = (sei *) pv_buf;
2570
2571 size = sizeof(sei);
2572 pv_buf = pf_aligned_alloc(pv_mem_ctxt, 128, size);
2573 RETURN_IF((NULL == pv_buf), IV_FAIL);
2574 memset(pv_buf, 0, size);
2575 ps_svcd_ctxt->ps_sei_parse = (sei *) pv_buf;
2576
2577 size = (sizeof(dec_pic_params_t)) * MAX_NUM_PIC_PARAMS;
2578 pv_buf = pf_aligned_alloc(pv_mem_ctxt, 128, size);
2579 RETURN_IF((NULL == pv_buf), IV_FAIL);
2580 memset(pv_buf, 0, size);
2581 ps_svcd_ctxt->ps_pps = pv_buf;
2582
2583 size = (sizeof(svc_dec_lyr_struct_t)) * MAX_NUM_RES_LYRS;
2584 pv_buf = pf_aligned_alloc(pv_mem_ctxt, 128, size);
2585 RETURN_IF((NULL == pv_buf), IV_FAIL);
2586 memset(pv_buf, 0, size);
2587 ps_svcd_ctxt->ps_svc_dec_lyr = pv_buf;
2588 ps_svcd_ctxt->u1_target_layer_id = 0;
2589 ps_svcd_ctxt->u1_cur_layer_id = 0;
2590 ps_svcd_ctxt->i4_eos_flag = 0;
2591
2592 ret = isvcd_mode_mv_resample_ctxt_create(ps_svcd_ctxt, pv_api_ip, pv_api_op);
2593 if(ret != IV_SUCCESS)
2594 {
2595 return ret;
2596 }
2597 ret = isvcd_intra_resample_ctxt_create(ps_svcd_ctxt, pv_api_ip, pv_api_op);
2598 if(ret != IV_SUCCESS)
2599 {
2600 return ret;
2601 }
2602 ret = isvcd_residual_resample_ctxt_create(ps_svcd_ctxt, pv_api_ip, pv_api_op);
2603 if(ret != IV_SUCCESS)
2604 {
2605 return ret;
2606 }
2607 ret = isvcd_nal_parse_ctxt_create(ps_svcd_ctxt, pv_api_ip, pv_api_op);
2608 if(ret != IV_SUCCESS)
2609 {
2610 return ret;
2611 }
2612 for(u1_layer_id = 0; u1_layer_id < MAX_NUM_RES_LYRS; u1_layer_id++)
2613 {
2614 ps_svc_lyr_dec = &ps_svcd_ctxt->ps_svc_dec_lyr[u1_layer_id];
2615 ps_dec = &ps_svc_lyr_dec->s_dec;
2616
2617 ps_svc_lyr_dec->ps_svcd_ctxt = ps_svcd_ctxt;
2618 ps_svc_lyr_dec->u1_layer_id = u1_layer_id;
2619 ps_svc_lyr_dec->u1_dyadic_flag = 1;
2620 ps_svc_lyr_dec->u1_restricted_res_change_flag = 1;
2621 ps_svc_lyr_dec->u1_base_res_flag = 1;
2622 ps_svc_lyr_dec->u1_ref_layer_id = 0;
2623 ps_svc_lyr_dec->ps_dec_svc_ref_layer =
2624 &ps_svcd_ctxt->ps_svc_dec_lyr[ps_svc_lyr_dec->u1_ref_layer_id];
2625 ps_svc_lyr_dec->u4_pps_id_for_layer = UINT32_MAX;
2626
2627 #ifndef LOGO_EN
2628 ps_dec->u4_share_disp_buf = ps_create_ip->s_ivd_create_ip_t.u4_share_disp_buf;
2629 #else
2630 ps_dec->u4_share_disp_buf = 0;
2631 #endif
2632
2633 ps_dec->u1_chroma_format = (UWORD8) (ps_create_ip->s_ivd_create_ip_t.e_output_format);
2634
2635 if((ps_dec->u1_chroma_format != IV_YUV_420P) &&
2636 (ps_dec->u1_chroma_format != IV_YUV_420SP_UV) &&
2637 (ps_dec->u1_chroma_format != IV_YUV_420SP_VU))
2638 {
2639 ps_dec->u4_share_disp_buf = 0;
2640 }
2641
2642 ps_dec->u1_enable_mb_info = ps_create_ip->u4_enable_frame_info;
2643 ps_dec->pf_aligned_alloc = pf_aligned_alloc;
2644 ps_dec->pf_aligned_free = pf_aligned_free;
2645 ps_dec->pv_mem_ctxt = pv_mem_ctxt;
2646
2647 ps_dec->ps_sps = ps_svcd_ctxt->ps_sps;
2648 ps_svc_lyr_dec->ps_subset_sps = ps_svcd_ctxt->ps_subset_sps;
2649 ps_dec->ps_pps = ps_svcd_ctxt->ps_pps;
2650 ps_dec->ps_sei = ps_svcd_ctxt->ps_sei;
2651 ps_dec->ps_sei_parse = ps_svcd_ctxt->ps_sei_parse;
2652
2653 size = ithread_get_handle_size();
2654 pv_buf = pf_aligned_alloc(pv_mem_ctxt, 128, size);
2655 RETURN_IF((NULL == pv_buf), IV_FAIL);
2656 memset(pv_buf, 0, size);
2657 ps_dec->pv_dec_thread_handle = pv_buf;
2658
2659 size = ithread_get_handle_size();
2660 pv_buf = pf_aligned_alloc(pv_mem_ctxt, 128, size);
2661 RETURN_IF((NULL == pv_buf), IV_FAIL);
2662 memset(pv_buf, 0, size);
2663 ps_dec->pv_bs_deblk_thread_handle = pv_buf;
2664
2665 #ifdef KEEP_THREADS_ACTIVE
2666 {
2667 UWORD32 i;
2668 /* Request memory to hold mutex (start/done) for both threads */
2669 size = ithread_get_mutex_lock_size() << 2;
2670 pv_buf = pf_aligned_alloc(pv_mem_ctxt, 8, size);
2671 RETURN_IF((NULL == pv_buf), IV_FAIL);
2672 memset(pv_buf, 0, size);
2673
2674 // init mutex variable for both the threads
2675 // 1. ih264d_decode_picture_thread
2676 // 2. ih264d_recon_deblk_thread
2677 for(i = 0; i < 2; i++)
2678 {
2679 WORD32 ret;
2680 WORD32 mutex_size = ithread_get_mutex_lock_size();
2681
2682 ps_dec->apv_proc_start_mutex[i] = (UWORD8 *) pv_buf + (2 * i * mutex_size);
2683 ps_dec->apv_proc_done_mutex[i] = (UWORD8 *) pv_buf + ((2 * i + 1) * mutex_size);
2684
2685 ret = ithread_mutex_init(ps_dec->apv_proc_start_mutex[0]);
2686 RETURN_IF((ret != IV_SUCCESS), ret);
2687
2688 ret = ithread_mutex_init(ps_dec->apv_proc_done_mutex[i]);
2689 RETURN_IF((ret != IV_SUCCESS), ret);
2690 }
2691
2692 size = ithread_get_cond_struct_size() << 2;
2693 pv_buf = pf_aligned_alloc(pv_mem_ctxt, 8, size);
2694 RETURN_IF((NULL == pv_buf), IV_FAIL);
2695 memset(pv_buf, 0, size);
2696
2697 // init condition variable for both the threads
2698 for(i = 0; i < 2; i++)
2699 {
2700 WORD32 ret;
2701 WORD32 cond_size = ithread_get_cond_struct_size();
2702 ps_dec->apv_proc_start_condition[i] = (UWORD8 *) pv_buf + (2 * i * cond_size);
2703 ps_dec->apv_proc_done_condition[i] = (UWORD8 *) pv_buf + ((2 * i + 1) * cond_size);
2704
2705 ret = ithread_cond_init(ps_dec->apv_proc_start_condition[i]);
2706 RETURN_IF((ret != IV_SUCCESS), ret);
2707
2708 ret = ithread_cond_init(ps_dec->apv_proc_done_condition[i]);
2709 RETURN_IF((ret != IV_SUCCESS), ret);
2710 }
2711 }
2712 #endif
2713 size = sizeof(dpb_manager_t);
2714 pv_buf = pf_aligned_alloc(pv_mem_ctxt, 128, size);
2715 RETURN_IF((NULL == pv_buf), IV_FAIL);
2716 memset(pv_buf, 0, size);
2717 ps_dec->ps_dpb_mgr = pv_buf;
2718
2719 size = sizeof(pred_info_t) * 2 * 32;
2720 pv_buf = pf_aligned_alloc(pv_mem_ctxt, 128, size);
2721 RETURN_IF((NULL == pv_buf), IV_FAIL);
2722 memset(pv_buf, 0, size);
2723 ps_dec->ps_pred = pv_buf;
2724
2725 size = sizeof(disp_mgr_t);
2726 pv_buf = pf_aligned_alloc(pv_mem_ctxt, 128, size);
2727 RETURN_IF((NULL == pv_buf), IV_FAIL);
2728 memset(pv_buf, 0, size);
2729 ps_dec->pv_disp_buf_mgr = pv_buf;
2730
2731 size = ih264_buf_mgr_size();
2732 pv_buf = pf_aligned_alloc(pv_mem_ctxt, 128, size);
2733 RETURN_IF((NULL == pv_buf), IV_FAIL);
2734 memset(pv_buf, 0, size);
2735 ps_dec->pv_pic_buf_mgr = pv_buf;
2736
2737 size = sizeof(struct pic_buffer_t) * (H264_MAX_REF_PICS * 2);
2738 pv_buf = pf_aligned_alloc(pv_mem_ctxt, 128, size);
2739 RETURN_IF((NULL == pv_buf), IV_FAIL);
2740 memset(pv_buf, 0, size);
2741 ps_dec->ps_pic_buf_base = pv_buf;
2742
2743 size = sizeof(dec_err_status_t);
2744 pv_buf = pf_aligned_alloc(pv_mem_ctxt, 128, size);
2745 RETURN_IF((NULL == pv_buf), IV_FAIL);
2746 memset(pv_buf, 0, size);
2747 ps_dec->ps_dec_err_status = (dec_err_status_t *) pv_buf;
2748
2749 size = sizeof(dpb_commands_t);
2750 pv_buf = pf_aligned_alloc(pv_mem_ctxt, 128, size);
2751 RETURN_IF((NULL == pv_buf), IV_FAIL);
2752 memset(pv_buf, 0, size);
2753 ps_dec->ps_dpb_cmds = (dpb_commands_t *) pv_buf;
2754
2755 size = sizeof(dec_bit_stream_t);
2756 pv_buf = pf_aligned_alloc(pv_mem_ctxt, 128, size);
2757 RETURN_IF((NULL == pv_buf), IV_FAIL);
2758 memset(pv_buf, 0, size);
2759 ps_dec->ps_bitstrm = (dec_bit_stream_t *) pv_buf;
2760
2761 size = sizeof(dec_nal_unit_svc_ext_params_t);
2762 pv_buf = pf_aligned_alloc(pv_mem_ctxt, 128, size);
2763 RETURN_IF((NULL == pv_buf), IV_FAIL);
2764 memset(pv_buf, 0, size);
2765 ps_svc_lyr_dec->ps_nal_svc_ext = (dec_nal_unit_svc_ext_params_t *) pv_buf;
2766
2767 size = sizeof(dec_slice_params_t);
2768 pv_buf = pf_aligned_alloc(pv_mem_ctxt, 128, size);
2769 RETURN_IF((NULL == pv_buf), IV_FAIL);
2770 memset(pv_buf, 0, size);
2771 ps_dec->ps_cur_slice = (dec_slice_params_t *) pv_buf;
2772
2773 size = MAX(sizeof(dec_seq_params_t), sizeof(dec_pic_params_t));
2774 pv_buf = pf_aligned_alloc(pv_mem_ctxt, 128, size);
2775 RETURN_IF((NULL == pv_buf), IV_FAIL);
2776 memset(pv_buf, 0, size);
2777 ps_dec->pv_scratch_sps_pps = pv_buf;
2778
2779 size = sizeof(dec_svc_seq_params_t);
2780 pv_buf = pf_aligned_alloc(pv_mem_ctxt, 128, size);
2781 RETURN_IF((NULL == pv_buf), IV_FAIL);
2782 memset(pv_buf, 0, size);
2783 ps_svc_lyr_dec->pv_scratch_subset_sps = pv_buf;
2784
2785 ps_dec->u4_static_bits_buf_size = 256000;
2786 pv_buf = pf_aligned_alloc(pv_mem_ctxt, 128, ps_dec->u4_static_bits_buf_size);
2787 RETURN_IF((NULL == pv_buf), IV_FAIL);
2788 memset(pv_buf, 0, ps_dec->u4_static_bits_buf_size);
2789 ps_dec->pu1_bits_buf_static = pv_buf;
2790
2791 size = ((TOTAL_LIST_ENTRIES + PAD_MAP_IDX_POC) * sizeof(void *));
2792 pv_buf = pf_aligned_alloc(pv_mem_ctxt, 128, size);
2793 RETURN_IF((NULL == pv_buf), IV_FAIL);
2794 ps_dec->ppv_map_ref_idx_to_poc_base = pv_buf;
2795 memset(ps_dec->ppv_map_ref_idx_to_poc_base, 0, size);
2796
2797 ps_dec->ppv_map_ref_idx_to_poc = ps_dec->ppv_map_ref_idx_to_poc_base + OFFSET_MAP_IDX_POC;
2798
2799 size = (sizeof(bin_ctxt_model_t) * NUM_CABAC_CTXTS_SVC);
2800 pv_buf = pf_aligned_alloc(pv_mem_ctxt, 128, size);
2801 RETURN_IF((NULL == pv_buf), IV_FAIL);
2802 memset(pv_buf, 0, size);
2803 ps_dec->p_cabac_ctxt_table_t = pv_buf;
2804
2805 size = sizeof(ctxt_inc_mb_info_t);
2806 pv_buf = pf_aligned_alloc(pv_mem_ctxt, 128, size);
2807 RETURN_IF((NULL == pv_buf), IV_FAIL);
2808 memset(pv_buf, 0, size);
2809 ps_dec->ps_left_mb_ctxt_info = pv_buf;
2810
2811 size = MAX_REF_BUF_SIZE * 2;
2812 pv_buf = pf_aligned_alloc(pv_mem_ctxt, 128, size);
2813 RETURN_IF((NULL == pv_buf), IV_FAIL);
2814 memset(pv_buf, 0, size);
2815 ps_dec->pu1_ref_buff_base = pv_buf;
2816 ps_dec->pu1_ref_buff = ps_dec->pu1_ref_buff_base + MAX_REF_BUF_SIZE;
2817
2818 size = ((sizeof(WORD16)) * PRED_BUFFER_WIDTH * PRED_BUFFER_HEIGHT * 2);
2819 pv_buf = pf_aligned_alloc(pv_mem_ctxt, 128, size);
2820 RETURN_IF((NULL == pv_buf), IV_FAIL);
2821 memset(pv_buf, 0, size);
2822 ps_dec->pi2_pred1 = pv_buf;
2823
2824 size = sizeof(UWORD8) * (MB_LUM_SIZE);
2825 pv_buf = pf_aligned_alloc(pv_mem_ctxt, 128, size);
2826 RETURN_IF((NULL == pv_buf), IV_FAIL);
2827 memset(pv_buf, 0, size);
2828 ps_dec->pu1_temp_mc_buffer = pv_buf;
2829
2830 size = 8 * MAX_REF_BUFS * sizeof(struct pic_buffer_t);
2831 pv_buf = pf_aligned_alloc(pv_mem_ctxt, 128, size);
2832 RETURN_IF((NULL == pv_buf), IV_FAIL);
2833 memset(pv_buf, 0, size);
2834
2835 ps_dec->pu1_init_dpb_base = pv_buf;
2836 pu1_buf = pv_buf;
2837 ps_dec->ps_dpb_mgr->ps_init_dpb[0][0] = (struct pic_buffer_t *) pu1_buf;
2838
2839 pu1_buf += size / 2;
2840 ps_dec->ps_dpb_mgr->ps_init_dpb[1][0] = (struct pic_buffer_t *) pu1_buf;
2841
2842 size = (sizeof(UWORD32) * 2 * 3 * ((MAX_FRAMES << 1) * (MAX_FRAMES << 1)) * 2);
2843 pv_buf = pf_aligned_alloc(pv_mem_ctxt, 128, size);
2844 RETURN_IF((NULL == pv_buf), IV_FAIL);
2845 memset(pv_buf, 0, size);
2846 ps_dec->pu4_mbaff_wt_mat = pv_buf;
2847
2848 size = sizeof(UWORD32) * 2 * 3 * ((MAX_FRAMES << 1) * (MAX_FRAMES << 1));
2849 pv_buf = pf_aligned_alloc(pv_mem_ctxt, 128, size);
2850 RETURN_IF((NULL == pv_buf), IV_FAIL);
2851 memset(pv_buf, 0, size);
2852 ps_dec->pu4_wts_ofsts_mat = pv_buf;
2853
2854 size = (sizeof(neighbouradd_t) << 2);
2855 pv_buf = pf_aligned_alloc(pv_mem_ctxt, 128, size);
2856 RETURN_IF((NULL == pv_buf), IV_FAIL);
2857 memset(pv_buf, 0, size);
2858 ps_dec->ps_left_mvpred_addr = pv_buf;
2859
2860 size = ih264_buf_mgr_size();
2861 pv_buf = pf_aligned_alloc(pv_mem_ctxt, 128, size);
2862 RETURN_IF((NULL == pv_buf), IV_FAIL);
2863 memset(pv_buf, 0, size);
2864 ps_dec->pv_mv_buf_mgr = pv_buf;
2865
2866 size = sizeof(col_mv_buf_t) * (H264_MAX_REF_PICS * 2);
2867 pv_buf = pf_aligned_alloc(pv_mem_ctxt, 128, size);
2868 RETURN_IF((NULL == pv_buf), IV_FAIL);
2869 ps_dec->ps_col_mv_base = pv_buf;
2870 memset(ps_dec->ps_col_mv_base, 0, size);
2871
2872 size = ((MB_SIZE * MB_SIZE * 3) >> 1) + MB_SIZE;
2873 pv_buf = pf_aligned_alloc(pv_mem_ctxt, 128, size);
2874 RETURN_IF((NULL == pv_buf), IV_FAIL);
2875 ps_svc_lyr_dec->pu1_ii_resamp_buffer_luma = pv_buf;
2876 ps_svc_lyr_dec->pu1_ii_resamp_buffer_chroma =
2877 ps_svc_lyr_dec->pu1_ii_resamp_buffer_luma + (MB_SIZE * MB_SIZE);
2878 memset(ps_svc_lyr_dec->pu1_ii_resamp_buffer_luma, 0, size);
2879
2880 isvcd_init_decoder(ps_svc_lyr_dec);
2881 }
2882 return IV_SUCCESS;
2883 }
2884
2885 /*****************************************************************************/
2886 /* */
2887 /* Function Name : isvcd_create */
2888 /* */
2889 /* Description : creates decoder */
2890 /* */
2891 /* Inputs :iv_obj_t decoder handle */
2892 /* :pv_api_ip pointer to input structure */
2893 /* :pv_api_op pointer to output structure */
2894 /* Outputs : */
2895 /* Returns : void */
2896 /* */
2897 /* Issues : none */
2898 /* */
2899 /* Revision History: */
2900 /* */
2901 /* DD MM YYYY Author(s) Changes (Describe the changes made) */
2902 /* 06 09 2021 Kishore */
2903 /* */
2904 /*****************************************************************************/
isvcd_create(iv_obj_t * dec_hdl,void * pv_api_ip,void * pv_api_op)2905 WORD32 isvcd_create(iv_obj_t *dec_hdl, void *pv_api_ip, void *pv_api_op)
2906 {
2907 isvcd_create_ip_t *ps_create_ip;
2908 isvcd_create_op_t *ps_create_op;
2909 WORD32 ret;
2910
2911 ps_create_ip = (isvcd_create_ip_t *) pv_api_ip;
2912 ps_create_op = (isvcd_create_op_t *) pv_api_op;
2913
2914 ps_create_op->s_ivd_create_op_t.u4_error_code = 0;
2915 dec_hdl = NULL;
2916 ret = isvcd_allocate_static_bufs(&dec_hdl, pv_api_ip, pv_api_op);
2917
2918 /* If allocation of some buffer fails, then free buffers allocated till then */
2919 if(IV_FAIL == ret)
2920 {
2921 if(dec_hdl)
2922 {
2923 if(dec_hdl->pv_codec_handle)
2924 {
2925 isvcd_free_static_bufs(dec_hdl);
2926 }
2927 else
2928 {
2929 void (*pf_aligned_free)(void *pv_mem_ctxt, void *pv_buf);
2930 void *pv_mem_ctxt;
2931
2932 pf_aligned_free = ps_create_ip->s_ivd_create_ip_t.pf_aligned_free;
2933 pv_mem_ctxt = ps_create_ip->s_ivd_create_ip_t.pv_mem_ctxt;
2934 pf_aligned_free(pv_mem_ctxt, dec_hdl);
2935 }
2936 }
2937 ps_create_op->s_ivd_create_op_t.u4_error_code = IVD_MEM_ALLOC_FAILED;
2938 ps_create_op->s_ivd_create_op_t.u4_error_code |= 1 << IVD_FATALERROR;
2939 return IV_FAIL;
2940 }
2941
2942 return IV_SUCCESS;
2943 }
2944
2945 /*****************************************************************************/
2946 /* */
2947 /* Function Name : isvcd_update_dqid */
2948 /* */
2949 /* Description : Updates the DQID list based on reference layer DQID */
2950 /* */
2951 /* */
2952 /* Inputs : 1. Reference layer DQID */
2953 /* 2. current layer's vcl node structure */
2954 /* 3. pointer to store the bottom layer VCL node */
2955 /* Globals : None */
2956 /* Processing : 1. Searches for a layer with reference layer DQID */
2957 /* 2. Updates the bottom and top nodes of current layer and */
2958 /* reference layer vcl nodes respectively */
2959 /* */
2960 /* Outputs : Updates top and bottom node field of vcl nodes of current*/
2961 /* layer and reference layer respectively */
2962 /* Returns : status */
2963 /* */
2964 /* Issues : None */
2965 /* */
2966 /* Revision History: */
2967 /* */
2968 /* DD MM YYYY Author(s) Changes (Describe the changes made) */
2969 /* 06 09 2021 Vijay Draft */
2970 /*****************************************************************************/
isvcd_update_dqid(WORD32 i4_ref_lyr_dqid,vcl_node_t * ps_cur_lyr_node,vcl_node_t ** pps_bot_lyr_node)2971 WORD32 isvcd_update_dqid(WORD32 i4_ref_lyr_dqid, vcl_node_t *ps_cur_lyr_node,
2972 vcl_node_t **pps_bot_lyr_node)
2973 {
2974 vcl_node_t *ps_vcl_node;
2975
2976 /* sanity checks */
2977 if((NULL == ps_cur_lyr_node) || (NULL == pps_bot_lyr_node))
2978 {
2979 return NOT_OK;
2980 }
2981
2982 ps_vcl_node = ps_cur_lyr_node->ps_bot_node;
2983 while(NULL != ps_vcl_node)
2984 {
2985 WORD32 i4_dqid;
2986
2987 i4_dqid = (ps_vcl_node->i4_dependency_id << 4) + ps_vcl_node->i4_quality_id;
2988
2989 /* if reference layer DQ ID matches */
2990 /* or reference layer is a layer below reference dq id layer */
2991 if((i4_dqid == i4_ref_lyr_dqid) ||
2992 (ps_vcl_node->i4_quality_id < (i4_ref_lyr_dqid & 0x0F)) ||
2993 (ps_vcl_node->i4_dependency_id < (i4_ref_lyr_dqid >> 4)))
2994 {
2995 break;
2996 }
2997 ps_vcl_node = ps_vcl_node->ps_bot_node;
2998 }
2999
3000 /* Update the top and bottom node of ref layer and current layer nodes */
3001
3002 if(NULL != ps_vcl_node)
3003 {
3004 ps_cur_lyr_node->ps_bot_node = ps_vcl_node;
3005 ps_vcl_node->ps_top_node = ps_cur_lyr_node;
3006 }
3007
3008 /* Update pointer to bottom VCL node */
3009 *pps_bot_lyr_node = ps_vcl_node;
3010 return (OK);
3011 }
3012
3013 /*****************************************************************************/
3014 /* */
3015 /* Function Name : isvcd_detect_res_change */
3016 /* */
3017 /* Description : This function detects the resolution change */
3018 /* */
3019 /* */
3020 /* Inputs : 1. Pointer to Current SPS */
3021 /* 2. Pointer to prevoius SPS */
3022 /* Globals : None */
3023 /* Processing : */
3024 /* */
3025 /* Outputs : none */
3026 /* Returns : SVCD_TRUE if different resolution else SVCD_FALSE */
3027 /* */
3028 /* Issues : none */
3029 /* */
3030 /* Revision History: */
3031 /* */
3032 /* DD MM YYYY Author(s) Changes (Describe the changes made) */
3033 /* 06 09 2021 Vijayakumar Draft */
3034 /* */
3035 /*****************************************************************************/
isvcd_detect_res_change(dec_seq_params_t * ps_curr_sps,dec_seq_params_t * ps_prev_sps,dec_svc_seq_params_t * ps_curr_subset_sps,dec_svc_seq_params_t * ps_prev_subset_sps)3036 WORD32 isvcd_detect_res_change(dec_seq_params_t *ps_curr_sps, dec_seq_params_t *ps_prev_sps,
3037 dec_svc_seq_params_t *ps_curr_subset_sps,
3038 dec_svc_seq_params_t *ps_prev_subset_sps)
3039 {
3040 UWORD16 u2_scaled_ref_width_sps;
3041 UWORD16 u2_scaled_ref_ht_sps;
3042 UNUSED(ps_prev_subset_sps);
3043
3044 if(NULL == ps_prev_sps)
3045 {
3046 /* indicates bottom most layer in Access unit */
3047 return (SVCD_FALSE);
3048 }
3049 /* Check for the ESS idc */
3050 if(2 == ps_curr_subset_sps->s_sps_svc_ext.u1_extended_spatial_scalability_idc)
3051 {
3052 return (SVCD_TRUE);
3053 }
3054
3055 /* Calculate the scaled reference width and height */
3056 u2_scaled_ref_width_sps = (ps_curr_sps->u2_frm_wd_in_mbs << 4);
3057 u2_scaled_ref_width_sps -=
3058 (ps_curr_subset_sps->s_sps_svc_ext.i4_seq_scaled_ref_layer_left_offset +
3059 ps_curr_subset_sps->s_sps_svc_ext.i4_seq_scaled_ref_layer_right_offset);
3060
3061 u2_scaled_ref_ht_sps = (ps_curr_sps->u2_frm_ht_in_mbs << 4);
3062 u2_scaled_ref_ht_sps -=
3063 (ps_curr_subset_sps->s_sps_svc_ext.i4_seq_scaled_ref_layer_top_offset +
3064 ps_curr_subset_sps->s_sps_svc_ext.i4_seq_scaled_ref_layer_bottom_offset);
3065
3066 /* Check for frame width being different */
3067 if(u2_scaled_ref_width_sps != (ps_prev_sps->u2_frm_wd_in_mbs << 4))
3068 {
3069 return (SVCD_TRUE);
3070 }
3071
3072 /* Check for frame height being different */
3073 if(u2_scaled_ref_ht_sps != (ps_prev_sps->u2_frm_ht_in_mbs << 4))
3074 {
3075 return (SVCD_TRUE);
3076 }
3077
3078 /* check for crop offset not MB aligned */
3079 if((0 != (ps_curr_subset_sps->s_sps_svc_ext.i4_seq_scaled_ref_layer_left_offset & 15)) ||
3080 (0 != (ps_curr_subset_sps->s_sps_svc_ext.i4_seq_scaled_ref_layer_top_offset & 15)))
3081 {
3082 return (SVCD_TRUE);
3083 }
3084
3085 /* check for chroma Phase Y being different */
3086 if(ps_curr_subset_sps->s_sps_svc_ext.u1_chroma_phase_x_plus1_flag !=
3087 ps_curr_subset_sps->s_sps_svc_ext.u1_seq_ref_layer_chroma_phase_x_plus1_flag)
3088 {
3089 return (SVCD_TRUE);
3090 }
3091
3092 /* check for chroma Phase Y being different */
3093 if(ps_curr_subset_sps->s_sps_svc_ext.u1_chroma_phase_y_plus1 !=
3094 ps_curr_subset_sps->s_sps_svc_ext.u1_seq_ref_layer_chroma_phase_y_plus1)
3095 {
3096 return (SVCD_TRUE);
3097 }
3098
3099 /* If none of the above are true then there is no resolution change */
3100 return (SVCD_FALSE);
3101 }
3102
3103 /*****************************************************************************/
3104 /* */
3105 /* Function Name : isvcd_parse_ref_pic_list_modify */
3106 /* */
3107 /* Description : Parses the reference picture modification related */
3108 /* syntax elements */
3109 /* */
3110 /* Inputs : 1. stream context structure */
3111 /* 2. slice prms structure */
3112 /* Globals : None */
3113 /* Processing : Parses the syntax elements */
3114 /* */
3115 /* Outputs : Updated stream buffer context */
3116 /* Returns : status */
3117 /* */
3118 /* Issues : None */
3119 /* */
3120 /* Revision History: */
3121 /* */
3122 /* DD MM YYYY Author(s) Changes (Describe the changes made) */
3123 /* 06 09 2021 Vijay Draft */
3124 /* */
3125 /*****************************************************************************/
isvcd_parse_ref_pic_list_modify(dec_bit_stream_t * ps_bitstrm,dec_slice_params_t * ps_slice_prms,dec_seq_params_t * ps_curr_sps)3126 WORD32 isvcd_parse_ref_pic_list_modify(dec_bit_stream_t *ps_bitstrm,
3127 dec_slice_params_t *ps_slice_prms,
3128 dec_seq_params_t *ps_curr_sps)
3129 {
3130 WORD32 i4_mod_flag;
3131 UWORD16 ui_nextUev;
3132 WORD32 i4_num_sets_ctr = 0;
3133 UWORD32 *pu4_bitstrm_buf = ps_bitstrm->pu4_buffer;
3134 UWORD32 *pu4_bitstrm_ofst = &ps_bitstrm->u4_ofst;
3135
3136 if(I_SLICE != ps_slice_prms->u1_slice_type)
3137 {
3138 /* ref_pic_list_modification_flag_l0 */
3139 i4_mod_flag = ih264d_get_bit_h264(ps_bitstrm);
3140
3141 if(0 != i4_mod_flag)
3142 {
3143 WORD32 i4_mod_pic_num_idc;
3144
3145 i4_num_sets_ctr = 0;
3146 do
3147 {
3148 /* modification_of_pic_nums_idc */
3149 i4_mod_pic_num_idc = ih264d_uev(pu4_bitstrm_ofst, pu4_bitstrm_buf);
3150
3151 if((i4_mod_pic_num_idc > 3) || (i4_mod_pic_num_idc < 0))
3152 {
3153 return ERROR_INV_SLICE_HDR_T;
3154 }
3155 if(3 != i4_mod_pic_num_idc)
3156 {
3157 /* i4_mod_pic_num_idc = 0,1 ==> abs_diff_pic_num_minus1 */
3158 /* i4_mod_pic_num_idc = 2 ==> long_term_pic_num */
3159
3160 ui_nextUev = ih264d_uev(pu4_bitstrm_ofst, pu4_bitstrm_buf);
3161 if(ui_nextUev > (ps_curr_sps->u2_u4_max_pic_num_minus1 + 1))
3162 return ERROR_INV_SLICE_HDR_T;
3163 }
3164
3165 i4_num_sets_ctr++;
3166
3167 /* if the number of commands recieved exceeds max limit */
3168 if((H264_MAX_REF_PICS) == i4_num_sets_ctr) break;
3169
3170 } while(3 != i4_mod_pic_num_idc);
3171 }
3172
3173 /*********** if (I_SLICE != u1_slice_type) ***************************/
3174 }
3175
3176 if(B_SLICE != ps_slice_prms->u1_slice_type)
3177 {
3178 return (OK);
3179 }
3180
3181 /* ref_pic_list_modification_flag_l1 */
3182 i4_mod_flag = ih264d_get_bit_h264(ps_bitstrm);
3183
3184 if(0 != i4_mod_flag)
3185 {
3186 WORD32 i4_mod_pic_num_idc;
3187
3188 do
3189 {
3190 /* modification_of_pic_nums_idc */
3191 i4_mod_pic_num_idc = ih264d_uev(pu4_bitstrm_ofst, pu4_bitstrm_buf);
3192
3193 if((i4_mod_pic_num_idc > 3) || (i4_mod_pic_num_idc < 0))
3194 {
3195 return ERROR_INV_SLICE_HDR_T;
3196 }
3197 if(3 != i4_mod_pic_num_idc)
3198 {
3199 /* i4_mod_pic_num_idc = 0,1 ==> abs_diff_pic_num_minus1 */
3200 /* i4_mod_pic_num_idc = 2 ==> long_term_pic_num */
3201
3202 ui_nextUev = ih264d_uev(pu4_bitstrm_ofst, pu4_bitstrm_buf);
3203 if(ui_nextUev > (ps_curr_sps->u2_u4_max_pic_num_minus1 + 1))
3204 return ERROR_INV_SLICE_HDR_T;
3205 }
3206
3207 i4_num_sets_ctr++;
3208
3209 /* if the number of commands recieved exceeds max limit */
3210 if((H264_MAX_REF_PICS) == i4_num_sets_ctr) break;
3211
3212 } while(3 != i4_mod_pic_num_idc);
3213 }
3214
3215 return (OK);
3216 }
3217 /*****************************************************************************/
3218 /* */
3219 /* Function Name : isvcd_parse_slice_hdr_refdq_id */
3220 /* */
3221 /* Description : this function decodes the slice until Inter layer deblk */
3222 /* parameters are parsed */
3223 /* */
3224 /* Inputs : 1. pointer to VCL node of given layer */
3225 /* 2. pointer toi slice params structure */
3226 /* 3. pointer to layer params strcuture */
3227 /* 4. pointer to stream context structure */
3228 /* 5. pointer to store the reference DQID */
3229 /* 6. pointer to array of SPS */
3230 /* 7. pointer to array of PPS */
3231 /* 8. no inter layer pred flag of current slice */
3232 /* Globals : none */
3233 /* Processing : prases syntax elements */
3234 /* */
3235 /* Outputs : reference layer DQ ID */
3236 /* Returns : Error code */
3237 /* */
3238 /* Issues : none */
3239 /* */
3240 /* Revision History: */
3241 /* */
3242 /* DD MM YYYY Author(s) Changes (Describe the changes made) */
3243 /* 06 09 2021 vijayakumar creation */
3244 /* */
3245 /*****************************************************************************/
isvcd_parse_slice_hdr_refdq_id(vcl_node_t * ps_vcl_node,dec_slice_params_t * ps_slice_prms,dec_bit_stream_t * ps_bitstrm,WORD32 * pi4_ref_dq_id,dec_seq_params_t * ps_sps,dec_pic_params_t * ps_pps,WORD32 i4_no_int_lyr_pred,svc_dec_ctxt_t * ps_svcd_ctxt)3246 WORD32 isvcd_parse_slice_hdr_refdq_id(vcl_node_t *ps_vcl_node, dec_slice_params_t *ps_slice_prms,
3247 dec_bit_stream_t *ps_bitstrm, WORD32 *pi4_ref_dq_id,
3248 dec_seq_params_t *ps_sps, dec_pic_params_t *ps_pps,
3249 WORD32 i4_no_int_lyr_pred, svc_dec_ctxt_t *ps_svcd_ctxt)
3250 {
3251 UWORD8 u1_pps_id;
3252 WORD32 i_temp;
3253 UWORD32 u4_temp;
3254 WORD32 i4_nal_unit_type;
3255 WORD32 i4_nal_ref_idc, i4_quality_id;
3256 WORD32 i4_use_ref_base, i4_idr_pic_flag;
3257 UWORD32 *pu4_bitstrm_buf = ps_bitstrm->pu4_buffer;
3258 UWORD32 *pu4_bitstrm_ofst = &ps_bitstrm->u4_ofst;
3259 dec_svc_seq_params_t *ps_subset_sps = NULL;
3260 WORD32 ret = OK;
3261
3262 i4_nal_unit_type = ps_vcl_node->i4_nal_unit_type;
3263 i4_nal_ref_idc = ps_vcl_node->i4_nal_ref_idc;
3264 i4_quality_id = ps_vcl_node->i4_quality_id;
3265 i4_use_ref_base = ps_vcl_node->i4_use_ref_base;
3266 i4_idr_pic_flag = ps_vcl_node->i4_idr_pic_flag;
3267
3268 /*-----------------------------------------------------------------------*/
3269 /*--------------------- first mb in slice -------------------------------*/
3270 /*-----------------------------------------------------------------------*/
3271 ps_slice_prms->u2_first_mb_in_slice = ih264d_uev(pu4_bitstrm_ofst, pu4_bitstrm_buf);
3272
3273 /*-----------------------------------------------------------------------*/
3274 /*---------------------------- slice type -------------------------------*/
3275 /*-----------------------------------------------------------------------*/
3276 ps_slice_prms->u1_slice_type = ih264d_uev(pu4_bitstrm_ofst, pu4_bitstrm_buf);
3277 if(ps_slice_prms->u1_slice_type > 4)
3278 {
3279 ps_slice_prms->u1_slice_type -= 5;
3280 }
3281
3282 /*-----------------------------------------------------------------------*/
3283 /*----------------------------- PPS id ----------------------------------*/
3284 /*-----------------------------------------------------------------------*/
3285 u1_pps_id = ih264d_uev(pu4_bitstrm_ofst, pu4_bitstrm_buf);
3286
3287 /* set correspoding sps and pps id also */
3288 ps_pps += u1_pps_id;
3289 if(FALSE == ps_pps->u1_is_valid)
3290 {
3291 return ERROR_INV_SLICE_HDR_T;
3292 }
3293 ps_sps = ps_pps->ps_sps;
3294 ps_subset_sps = &ps_svcd_ctxt->ps_subset_sps[ps_sps->u1_seq_parameter_set_id];
3295 if(CODED_SLICE_EXTENSION_NAL == i4_nal_unit_type)
3296 {
3297 ps_sps += MAX_NUM_SEQ_PARAMS;
3298 ps_subset_sps =
3299 &ps_svcd_ctxt->ps_subset_sps[MAX_NUM_SEQ_PARAMS + ps_sps->u1_seq_parameter_set_id];
3300 }
3301 /*-----------------------------------------------------------------------*/
3302 /*--------------------------- frm num -----------------------------------*/
3303 /*-----------------------------------------------------------------------*/
3304 if(!ps_sps) return ERROR_INV_SLICE_HDR_T;
3305 if(FALSE == ps_sps->u1_is_valid) return ERROR_INV_SLICE_HDR_T;
3306
3307 ps_slice_prms->u2_frame_num = ih264d_get_bits_h264(ps_bitstrm, ps_sps->u1_bits_in_frm_num);
3308
3309 /*-----------------------------------------------------------------------*/
3310 /*------------------ field pic flag and bottom field flag ---------------*/
3311 /*-----------------------------------------------------------------------*/
3312 if(SVCD_TRUE != ps_sps->u1_frame_mbs_only_flag)
3313 {
3314 return ERROR_INV_SLICE_HDR_T;
3315 }
3316 /*-----------------------------------------------------------------------*/
3317 /*--------------------------- IDR pic id --------------------------------*/
3318 /*-----------------------------------------------------------------------*/
3319 if(SVCD_TRUE == i4_idr_pic_flag)
3320 {
3321 UWORD32 u4_idr_pic_id = 0;
3322 u4_idr_pic_id = ih264d_uev(pu4_bitstrm_ofst, pu4_bitstrm_buf);
3323 if(u4_idr_pic_id > 65535) return ERROR_INV_SLICE_HDR_T;
3324 }
3325
3326 /*-----------------------------------------------------------------------*/
3327 /*----------------- poc lsb and delts_poc_bottom ------------------------*/
3328 /*-----------------------------------------------------------------------*/
3329 if(0 == ps_sps->u1_pic_order_cnt_type)
3330 {
3331 i_temp = ih264d_get_bits_h264(ps_bitstrm, ps_sps->u1_log2_max_pic_order_cnt_lsb_minus);
3332
3333 if(i_temp < 0 || i_temp >= ps_sps->i4_max_pic_order_cntLsb) return ERROR_INV_SLICE_HDR_T;
3334 if(SVCD_TRUE == ps_pps->u1_pic_order_present_flag)
3335 {
3336 i_temp = ih264d_sev(pu4_bitstrm_ofst, pu4_bitstrm_buf);
3337 }
3338 }
3339
3340 /*-----------------------------------------------------------------------*/
3341 /*---------------- delta_poc_count[0] and [1] ---------------------------*/
3342 /*-----------------------------------------------------------------------*/
3343 if((1 == ps_sps->u1_pic_order_cnt_type) && (!ps_sps->u1_delta_pic_order_always_zero_flag))
3344 {
3345 i_temp = ih264d_sev(pu4_bitstrm_ofst, pu4_bitstrm_buf);
3346
3347 if(ps_pps->u1_pic_order_present_flag)
3348 {
3349 i_temp = ih264d_sev(pu4_bitstrm_ofst, pu4_bitstrm_buf);
3350 }
3351 }
3352
3353 /*-----------------------------------------------------------------------*/
3354 /*---------------------- redundant pic cnt ------------------------------*/
3355 /*-----------------------------------------------------------------------*/
3356 if(ps_pps->u1_redundant_pic_cnt_present_flag)
3357 {
3358 u4_temp = ih264d_uev(pu4_bitstrm_ofst, pu4_bitstrm_buf);
3359 if(u4_temp > MAX_REDUNDANT_PIC_CNT) return ERROR_INV_SLICE_HDR_T;
3360 }
3361 /*-----------------------------------------------------------------------*/
3362 /*-----------------Direct_spatial_mv_pred_flag --------------------------*/
3363 /*-----------------num ref active override flag -------------------------*/
3364 /*-----------------num_ref_idx_active_l0&1 ------------------------------*/
3365 /*-----------------------------------------------------------------------*/
3366 if(0 == i4_quality_id)
3367 {
3368 if(B_SLICE == ps_slice_prms->u1_slice_type)
3369 {
3370 ps_slice_prms->u1_direct_spatial_mv_pred_flag = ih264d_get_bit_h264(ps_bitstrm);
3371 }
3372
3373 if((P_SLICE == ps_slice_prms->u1_slice_type) || (B_SLICE == ps_slice_prms->u1_slice_type))
3374 {
3375 WORD8 i1_over_ride_flag;
3376 i1_over_ride_flag = ih264d_get_bit_h264(ps_bitstrm);
3377
3378 ps_slice_prms->u1_num_ref_idx_active_override_flag = i1_over_ride_flag;
3379
3380 if(SVCD_TRUE == i1_over_ride_flag)
3381 {
3382 UWORD8 u8_ref_idx_l0;
3383 u8_ref_idx_l0 = ih264d_uev(pu4_bitstrm_ofst, pu4_bitstrm_buf);
3384 if(u8_ref_idx_l0 > H264_MAX_REF_PICS)
3385 {
3386 return ERROR_NUM_REF;
3387 }
3388 if(B_SLICE == ps_slice_prms->u1_slice_type)
3389 {
3390 UWORD8 u8_ref_idx_l1;
3391 u8_ref_idx_l1 = ih264d_uev(pu4_bitstrm_ofst, pu4_bitstrm_buf);
3392 if(u8_ref_idx_l1 > H264_MAX_REF_PICS)
3393 {
3394 return ERROR_NUM_REF;
3395 }
3396 }
3397 }
3398 }
3399
3400 /*-----------------------------------------------------------------------*/
3401 /*---------------------- ref pic list modification ----------------------*/
3402 /*-----------------------------------------------------------------------*/
3403 {
3404 ret = isvcd_parse_ref_pic_list_modify(ps_bitstrm, ps_slice_prms, ps_sps);
3405 if(OK != ret) return ret;
3406 }
3407
3408 if(((1 == ps_pps->u1_wted_pred_flag) && (P_SLICE == ps_slice_prms->u1_slice_type)) ||
3409 ((B_SLICE == ps_slice_prms->u1_slice_type) && (1 == ps_pps->u1_wted_bipred_idc)))
3410 {
3411 if((ps_slice_prms->u1_num_ref_idx_lx_active[0] >= H264_MAX_REF_IDX) ||
3412 (ps_slice_prms->u1_num_ref_idx_lx_active[1] >= H264_MAX_REF_IDX))
3413 {
3414 return ERROR_NUM_REF;
3415 }
3416 /*-------------------------------------------------------------------*/
3417 /*------------------------- Pred weight table -----------------------*/
3418 /*-------------------------------------------------------------------*/
3419 if(CODED_SLICE_EXTENSION_NAL == i4_nal_unit_type)
3420 {
3421 WORD32 i4_base_pred_wt_tbl_flag = 1;
3422
3423 /* base_pred_weight_table_flag */
3424 if(0 == i4_no_int_lyr_pred)
3425 {
3426 i4_base_pred_wt_tbl_flag = ih264d_get_bit_h264(ps_bitstrm);
3427 }
3428
3429 if((1 == i4_no_int_lyr_pred) || (0 == i4_base_pred_wt_tbl_flag))
3430 {
3431 ret = ih264d_parse_pred_weight_table(ps_slice_prms, ps_bitstrm);
3432 if(ret != OK) return ret;
3433 }
3434 }
3435 else
3436 {
3437 ret = ih264d_parse_pred_weight_table(ps_slice_prms, ps_bitstrm);
3438 if(ret != OK) return ret;
3439 }
3440 }
3441
3442 /*-----------------------------------------------------------------------*/
3443 /*------------------------- ref pic marking -----------------------------*/
3444 /*-----------------------------------------------------------------------*/
3445 if(0 != i4_nal_ref_idc)
3446 {
3447 dec_struct_t *ps_dec;
3448 svc_dec_lyr_struct_t *ps_svc_lyr_dec;
3449 UWORD8 u1_store_ref_base_pic;
3450 ps_svc_lyr_dec = ps_svcd_ctxt->ps_svc_dec_lyr;
3451 ps_dec = &ps_svc_lyr_dec->s_dec;
3452 {
3453 dec_seq_params_t *ps_sps_tmp = ps_pps->ps_sps;
3454
3455 ps_dec->u1_nal_unit_type = i4_nal_unit_type;
3456 ps_svc_lyr_dec->ps_nal_svc_ext->u1_idr_flag = i4_idr_pic_flag;
3457 ps_dec->ps_cur_sps = ps_sps;
3458 ps_dec->ps_cur_pps = ps_pps;
3459 ps_pps->ps_sps = ps_sps;
3460
3461 if(ps_svc_lyr_dec->ps_nal_svc_ext->u1_idr_flag)
3462 ps_dec->u1_nal_unit_type = IDR_SLICE_NAL;
3463
3464 i_temp = ih264d_read_mmco_commands(ps_dec);
3465 ps_pps->ps_sps = ps_sps_tmp;
3466 ps_dec->u1_nal_unit_type = i4_nal_unit_type;
3467 if(i_temp < 0)
3468 {
3469 return ERROR_DBP_MANAGER_T;
3470 }
3471 ps_dec->u4_bitoffset = i_temp;
3472 }
3473
3474 if(0 == ps_subset_sps->s_sps_svc_ext.u1_slice_header_restriction_flag)
3475 {
3476 /* store_ref_base_pic_flag */
3477 u1_store_ref_base_pic = ih264d_get_bit_h264(ps_bitstrm);
3478 if(0 != u1_store_ref_base_pic)
3479 {
3480 return ERROR_INV_SLICE_HDR_T;
3481 }
3482
3483 if(((1 == i4_use_ref_base) || (1 == u1_store_ref_base_pic)) &&
3484 (SVCD_FALSE == i4_idr_pic_flag))
3485 {
3486 i_temp = isvcd_dec_ref_base_pic_marking(
3487 &ps_svc_lyr_dec->s_svc_slice_params.s_ref_base_pic_marking_svc_ext,
3488 ps_bitstrm);
3489 if(i_temp != OK)
3490 {
3491 return i_temp;
3492 }
3493 }
3494 /******* End of if (SVC_VCL_NAL == i4_nal_unit_type) *********/
3495 }
3496 /******** End of if(0 != i4_nal_ref_idc) *************************/
3497 }
3498 /************* End of if(0 == i4_quality_id) *************************/
3499 }
3500
3501 /*-----------------------------------------------------------------------*/
3502 /*--------------------------- cabac int idc -----------------------------*/
3503 /*-----------------------------------------------------------------------*/
3504 if((ps_pps->u1_entropy_coding_mode == CABAC) && (I_SLICE != ps_slice_prms->u1_slice_type))
3505 {
3506 ps_slice_prms->u1_cabac_init_idc = ih264d_uev(pu4_bitstrm_ofst, pu4_bitstrm_buf);
3507 if(ps_slice_prms->u1_cabac_init_idc > MAX_CABAC_INIT_IDC)
3508 {
3509 return ERROR_INV_SLICE_HDR_T;
3510 }
3511 }
3512
3513 /*-----------------------------------------------------------------------*/
3514 /*--------------------------- slice qp delta ----------------------------*/
3515 /*-----------------------------------------------------------------------*/
3516 {
3517 WORD8 i1_slice_qp_delta;
3518 i1_slice_qp_delta = ih264d_sev(pu4_bitstrm_ofst, pu4_bitstrm_buf);
3519 i1_slice_qp_delta += ps_pps->u1_pic_init_qp;
3520 if((i1_slice_qp_delta < MIN_H264_QP) || (i1_slice_qp_delta > MAX_H264_QP))
3521 {
3522 return ERROR_INV_RANGE_QP_T;
3523 }
3524 ps_slice_prms->u1_slice_qp = (UWORD8) i1_slice_qp_delta;
3525 }
3526
3527 /*-----------------------------------------------------------------------*/
3528 /*--------------------------- disable dblk filter idc -------------------*/
3529 /*-----------------------------------------------------------------------*/
3530 /* Set to default value */
3531
3532 ps_slice_prms->u1_disable_dblk_filter_idc = 0;
3533 if(SVCD_TRUE == ps_pps->u1_deblocking_filter_parameters_present_flag)
3534 {
3535 ps_slice_prms->u1_disable_dblk_filter_idc = ih264d_uev(pu4_bitstrm_ofst, pu4_bitstrm_buf);
3536
3537 if(ps_slice_prms->u1_disable_dblk_filter_idc > SLICE_BOUNDARY_DBLK_DISABLED)
3538 {
3539 return ERROR_INV_SLICE_HDR_T;
3540 }
3541 /*-------------------------------------------------------------------*/
3542 /*--------------------------- slice_alpha_c0_offset_div2 ------------*/
3543 /*--------------------------- slice_beta_offset_div2 ----------------*/
3544 /*-------------------------------------------------------------------*/
3545 if(1 != ps_slice_prms->u1_disable_dblk_filter_idc)
3546 {
3547 /* slice_alpha_c0_offset_div2 */
3548 ps_slice_prms->i1_slice_alpha_c0_offset = ih264d_sev(pu4_bitstrm_ofst, pu4_bitstrm_buf);
3549 if((MIN_DBLK_FIL_OFF > ps_slice_prms->i1_slice_alpha_c0_offset) ||
3550 (ps_slice_prms->i1_slice_alpha_c0_offset > MAX_DBLK_FIL_OFF))
3551 {
3552 return ERROR_INV_SLICE_HDR_T;
3553 }
3554 ps_slice_prms->i1_slice_beta_offset = ih264d_sev(pu4_bitstrm_ofst, pu4_bitstrm_buf);
3555 if((MIN_DBLK_FIL_OFF > ps_slice_prms->i1_slice_beta_offset) ||
3556 (ps_slice_prms->i1_slice_beta_offset > MAX_DBLK_FIL_OFF))
3557 {
3558 return ERROR_INV_SLICE_HDR_T;
3559 }
3560 }
3561 }
3562
3563 *pi4_ref_dq_id = -1;
3564
3565 if((0 == i4_no_int_lyr_pred) && (0 == i4_quality_id))
3566 {
3567 WORD32 i4_inter_lyr_dblk_idc;
3568 WORD32 i4_inter_lyr_alpha_c0_offset;
3569 WORD32 i4_inter_lyr_beta_offset;
3570
3571 /*-------------------------------------------------------------------*/
3572 /*--------------------------- ref_layer_dq_id -----------------------*/
3573 /*-------------------------------------------------------------------*/
3574 *pi4_ref_dq_id = ih264d_uev(pu4_bitstrm_ofst, pu4_bitstrm_buf);
3575
3576 if(*pi4_ref_dq_id > MAX_REF_DEP_ID)
3577 {
3578 return ERROR_INV_SLICE_HDR_T;
3579 }
3580 /* ------------------------------------------- */
3581 /* ---- Inter layer de-blocking parameters ---- */
3582 /* ------------------------------------------- */
3583 i4_inter_lyr_dblk_idc = 0;
3584 i4_inter_lyr_alpha_c0_offset = 0;
3585 i4_inter_lyr_beta_offset = 0;
3586 if(SVCD_TRUE ==
3587 ps_subset_sps->s_sps_svc_ext.u1_inter_layer_deblocking_filter_control_present_flag)
3588 {
3589 i4_inter_lyr_dblk_idc = ih264d_uev(pu4_bitstrm_ofst, pu4_bitstrm_buf);
3590
3591 if(i4_inter_lyr_dblk_idc > 6)
3592 {
3593 return ERROR_INV_SLICE_HDR_T;
3594 }
3595 if(1 != i4_inter_lyr_dblk_idc)
3596 {
3597 /* Alpha Offset */
3598 i4_inter_lyr_alpha_c0_offset = ih264d_sev(pu4_bitstrm_ofst, pu4_bitstrm_buf);
3599 if(i4_inter_lyr_alpha_c0_offset > 6 || i4_inter_lyr_alpha_c0_offset < -6)
3600 {
3601 return ERROR_INV_SLICE_HDR_T;
3602 }
3603 i4_inter_lyr_alpha_c0_offset <<= 1;
3604
3605 /* Beta Offset */
3606 i4_inter_lyr_beta_offset = ih264d_sev(pu4_bitstrm_ofst, pu4_bitstrm_buf);
3607 if(i4_inter_lyr_beta_offset > 6 || i4_inter_lyr_beta_offset < -6)
3608 {
3609 return ERROR_INV_SLICE_HDR_T;
3610 }
3611 i4_inter_lyr_beta_offset <<= 1;
3612 }
3613 }
3614 ps_vcl_node->i4_inter_lyr_dblk_idc = i4_inter_lyr_dblk_idc;
3615 ps_vcl_node->i4_inter_lyr_beta_offset = i4_inter_lyr_beta_offset;
3616 ps_vcl_node->i4_inter_lyr_alpha_c0_offset = i4_inter_lyr_alpha_c0_offset;
3617 }
3618
3619 return (0);
3620 }
3621 /*****************************************************************************/
3622 /* */
3623 /* Function Name : isvcd_get_ref_lyr_dqid */
3624 /* */
3625 /* Description : Parses the slice header till ref lyr dqid. */
3626 /* */
3627 /* */
3628 /* Inputs : 1. vcl node */
3629 /* 2. sequence prms set base buffer pointer */
3630 /* 3. picture prms set base buffer pointer */
3631 /* 4. Target layer flag */
3632 /* 5. DPB command context structure */
3633 /* 6. Reference layer DQID */
3634 /* Globals : None */
3635 /* Processing : 1. Parses the slice header till ref lyr DQID */
3636 /* 2. If current layer is target layer then it calculates */
3637 /* poc and gaps in frame number */
3638 /* */
3639 /* Outputs : Updates 1) ref dqid variable 2) dpb command context */
3640 /* Returns : status */
3641 /* */
3642 /* Issues : None */
3643 /* */
3644 /* Revision History: */
3645 /* */
3646 /* DD MM YYYY Author(s) Changes (Describe the changes made) */
3647 /* 06 09 2021 Vijay Draft */
3648 /*****************************************************************************/
isvcd_get_ref_lyr_dqid(vcl_node_t * ps_vcl_node,dec_seq_params_t * ps_sps,dec_pic_params_t * ps_pps,WORD32 * pi4_ref_lyr_dqid,WORD32 i4_prev_au_dqid,WORD32 * pi4_err_code,svc_dec_ctxt_t * ps_svcd_ctxt)3649 WORD32 isvcd_get_ref_lyr_dqid(vcl_node_t *ps_vcl_node, dec_seq_params_t *ps_sps,
3650 dec_pic_params_t *ps_pps, WORD32 *pi4_ref_lyr_dqid,
3651 WORD32 i4_prev_au_dqid, WORD32 *pi4_err_code,
3652 svc_dec_ctxt_t *ps_svcd_ctxt)
3653 {
3654 WORD32 i4_status;
3655 WORD32 ai4_ref_dq_id[2] = {0};
3656 WORD32 i4_num_slc_dec;
3657
3658 /* local structures */
3659 dec_slice_params_t s_slice_prms = {0};
3660
3661 /* vcl buffer */
3662 vcl_buf_hdr_t *ps_vcl_buf;
3663 dec_struct_t *ps_dec;
3664 svc_dec_lyr_struct_t *ps_svc_lyr_dec = ps_svcd_ctxt->ps_svc_dec_lyr;
3665 UNUSED(i4_prev_au_dqid);
3666 ps_dec = &ps_svc_lyr_dec->s_dec;
3667 /* Sanity checks */
3668 if((NULL == ps_vcl_node) || (NULL == ps_sps) || (NULL == ps_pps) || (NULL == pi4_ref_lyr_dqid))
3669 {
3670 return NOT_OK;
3671 }
3672
3673 i4_num_slc_dec = 0;
3674 ps_vcl_buf = ps_vcl_node->ps_first_vcl_nal;
3675 i4_status = NOT_OK;
3676
3677 while(NULL != ps_vcl_buf)
3678 {
3679 WORD32 i4_error;
3680
3681 /* Fill the stream context structure */
3682 ps_dec->ps_bitstrm->u4_ofst = 0;
3683 ps_dec->ps_bitstrm->pu4_buffer =
3684 (UWORD32 *) ((UWORD8 *) ps_vcl_buf + ps_vcl_buf->i4_buf_offset +
3685 ps_vcl_buf->i4_slice_offset);
3686 ps_dec->ps_bitstrm->u4_max_ofst = ps_vcl_buf->u4_max_bits;
3687
3688 /* call the function which decodes the slice header */
3689 i4_error = isvcd_parse_slice_hdr_refdq_id(ps_vcl_node, &s_slice_prms, ps_dec->ps_bitstrm,
3690 &ai4_ref_dq_id[i4_num_slc_dec], ps_sps, ps_pps,
3691 ps_vcl_buf->i4_no_int_lyr_pred, ps_svcd_ctxt);
3692
3693 /* store the first error encountered */
3694 if(0 == *pi4_err_code)
3695 {
3696 *pi4_err_code = i4_error;
3697 }
3698 if(i4_error != 0)
3699 {
3700 /* check on the Error returned */
3701 return NOT_OK;
3702 }
3703
3704 /* set the return status */
3705 i4_status = OK;
3706 break;
3707
3708 /* go to the next slice header */
3709 ps_vcl_buf = ps_vcl_buf->ps_next;
3710 }
3711
3712 /* set the appropriate reference dqid of the first slice */
3713 *pi4_ref_lyr_dqid = ai4_ref_dq_id[0];
3714
3715 return (i4_status);
3716 }
3717 /*****************************************************************************/
3718 /* */
3719 /* Function Name : isvcd_conceal_node_params */
3720 /* */
3721 /* Description : This function detects the resolution change */
3722 /* */
3723 /* */
3724 /* Inputs : 1. Pointer to Current SPS */
3725 /* 2. Pointer to prevoius SPS */
3726 /* Globals : None */
3727 /* Processing : */
3728 /* */
3729 /* Outputs : none */
3730 /* Returns : SVCD_TRUE if different resolution else SVCD_FALSE */
3731 /* */
3732 /* Issues : none */
3733 /* */
3734 /* Revision History: */
3735 /* */
3736 /* DD MM YYYY Author(s) Changes (Describe the changes made) */
3737 /* 06 09 2021 Vijayakumar Draft */
3738 /* */
3739 /*****************************************************************************/
isvcd_conceal_node_params(vcl_nal_t * ps_vcl_nal,prev_au_prms_t * ps_prev_au_prms)3740 void isvcd_conceal_node_params(vcl_nal_t *ps_vcl_nal, prev_au_prms_t *ps_prev_au_prms)
3741 {
3742 vcl_node_t *ps_node;
3743 WORD32 i4_conceal_lyrs;
3744 WORD32 i4_no_gaps_flag;
3745
3746 /* get the bottom node */
3747 ps_node = ps_vcl_nal->ps_bot_node;
3748 i4_conceal_lyrs = SVCD_FALSE;
3749 i4_no_gaps_flag = SVCD_FALSE;
3750
3751 /* loop over all nodes present in the current AU */
3752 while(NULL != ps_node)
3753 {
3754 WORD32 i4_dep_id = 0;
3755 WORD32 i4_qua_id = 0;
3756 UWORD16 u2_frm_num_dep = 0;
3757 WORD32 i4_idr_pic_flag = 0;
3758 WORD32 i4_idr_pic_num = 0;
3759 WORD32 i4_nal_ref_idc = 0;
3760 WORD32 i4_poc_syntax = 0;
3761 WORD32 i4_qua_zero_lyr_sts = 0;
3762
3763 i4_dep_id = ps_node->i4_dependency_id;
3764 i4_qua_id = ps_node->i4_quality_id;
3765
3766 /* reset the quality 0 layer updated status */
3767 if(0 == i4_qua_id)
3768 {
3769 i4_qua_zero_lyr_sts = SVCD_FALSE;
3770 }
3771
3772 /* process the quality id 0 layers */
3773 if((0 == i4_qua_id) && (NULL != ps_node->ps_first_vcl_nal))
3774 {
3775 /* if current and previous are reference pictures */
3776 if((0 != ps_prev_au_prms[i4_dep_id].i4_nal_ref_id) && (0 != ps_node->i4_nal_ref_idc))
3777 {
3778 if(ps_prev_au_prms[i4_dep_id].u2_frm_num == ps_node->u2_frm_num)
3779 {
3780 /* frame number is concealed */
3781 ps_node->u2_frm_num++;
3782 i4_conceal_lyrs = SVCD_TRUE;
3783 }
3784 else if((SVCD_TRUE == i4_conceal_lyrs) || (SVCD_TRUE == i4_no_gaps_flag))
3785 {
3786 /* if the current au frm_num is less than prev */
3787 /* or the difference is greater than 1 */
3788 if((ps_prev_au_prms[i4_dep_id].u2_frm_num > ps_node->u2_frm_num) ||
3789 ((ps_node->u2_frm_num - ps_prev_au_prms[i4_dep_id].u2_frm_num) > 1))
3790 {
3791 /* frame number is concealed */
3792 ps_node->u2_frm_num = ps_prev_au_prms[i4_dep_id].u2_frm_num + 1;
3793 }
3794 }
3795
3796 /* set the no gaps flag */
3797 if(1 == (ps_node->u2_frm_num - ps_prev_au_prms[i4_dep_id].u2_frm_num))
3798 {
3799 i4_no_gaps_flag = SVCD_TRUE;
3800 }
3801 }
3802
3803 /* store the final frame number */
3804 u2_frm_num_dep = ps_node->u2_frm_num;
3805 i4_idr_pic_flag = ps_node->i4_idr_pic_flag;
3806 i4_idr_pic_num = ps_node->i4_idr_pic_num;
3807 i4_nal_ref_idc = ps_node->i4_nal_ref_idc;
3808 i4_poc_syntax = ps_node->i4_poc_syntax;
3809 i4_qua_zero_lyr_sts = SVCD_TRUE;
3810 }
3811 else
3812 {
3813 if(SVCD_TRUE == i4_qua_zero_lyr_sts)
3814 {
3815 /* for higher quality layers store the same value */
3816 /* present in the quality id 0 layer */
3817 ps_node->u2_frm_num = u2_frm_num_dep;
3818 ps_node->i4_idr_pic_flag = i4_idr_pic_flag;
3819 ps_node->i4_idr_pic_num = i4_idr_pic_num;
3820 ps_node->i4_nal_ref_idc = i4_nal_ref_idc;
3821 ps_node->i4_poc_syntax = i4_poc_syntax;
3822 }
3823 }
3824
3825 /* get the upper node pointer */
3826 ps_node = ps_node->ps_top_node;
3827 }
3828 }
3829 /*****************************************************************************/
3830 /* */
3831 /* Function Name : isvcd_refine_dep_list */
3832 /* */
3833 /* Description : Refines the DQID list based on reference layer DQID */
3834 /* */
3835 /* */
3836 /* Inputs : 1. vcl nal structure (input and output) */
3837 /* 2. sps prms base buffer pointer */
3838 /* 3. pps prms base buffer pointer */
3839 /* 4. pointer to array in which the dep id should be stored */
3840 /* 5. pointer to array having prev AU ref dq id */
3841 /* 6. pointer to init params structure */
3842 /* 7. pointer to store the Error code */
3843 /* Globals : None */
3844 /* Processing : */
3845 /* */
3846 /* Outputs : Updates the vcl nal structure */
3847 /* Also determines frm_num and poc */
3848 /* Returns : status */
3849 /* */
3850 /* Issues : None */
3851 /* */
3852 /* Revision History: */
3853 /* */
3854 /* DD MM YYYY Author(s) Changes (Describe the changes made) */
3855 /* 06 09 2021 Vijay Draft */
3856 /*****************************************************************************/
isvcd_refine_dep_list(void * pv_out_vcl_ctxt,dec_seq_params_t * ps_sps,dec_svc_seq_params_t * ps_subset_sps,dec_pic_params_t * ps_pps,WORD32 * pi4_dep_id_map,prev_au_prms_t * ps_prev_au_prms,prev_au_sps_pps_t * ps_pps_sps_prev,WORD32 * pi4_err_code,svc_dec_ctxt_t * ps_svcd_ctxt)3857 WORD32 isvcd_refine_dep_list(void *pv_out_vcl_ctxt, dec_seq_params_t *ps_sps,
3858 dec_svc_seq_params_t *ps_subset_sps, dec_pic_params_t *ps_pps,
3859 WORD32 *pi4_dep_id_map, prev_au_prms_t *ps_prev_au_prms,
3860 prev_au_sps_pps_t *ps_pps_sps_prev, WORD32 *pi4_err_code,
3861 svc_dec_ctxt_t *ps_svcd_ctxt)
3862 {
3863 vcl_nal_t *ps_vcl_nal;
3864 vcl_node_t *ps_vcl_node;
3865 WORD32 i4_idr_pic_flag;
3866 WORD32 i4_nal_ref_idc;
3867 WORD32 i4_idr_pic_num;
3868 WORD32 i4_num_res_lyrs_bup;
3869 WORD32 i4_restore_prms_flag;
3870 vcl_node_t *ps_node_bup;
3871 WORD32 ai4_dep_id[MAX_NUM_RES_LYRS] = {0};
3872
3873 /* used for checking the init prms */
3874 dec_seq_params_t *ps_sps_tgt_minus1_lyr = NULL;
3875 dec_seq_params_t *ps_sps_tgt_minus2_lyr = NULL;
3876 UNUSED(pi4_err_code);
3877 /* sanity checks */
3878 if((NULL == pv_out_vcl_ctxt) || (NULL == ps_sps) || (NULL == ps_pps))
3879 {
3880 return NOT_OK;
3881 }
3882
3883 ps_vcl_nal = (vcl_nal_t *) pv_out_vcl_ctxt;
3884
3885 /* no node is present */
3886 if(NULL == ps_vcl_nal->ps_bot_node)
3887 {
3888 return (NOT_OK);
3889 }
3890
3891 /* set the single layer flag if top node and bottom node are same */
3892 if((ps_vcl_nal->ps_bot_node == ps_vcl_nal->ps_top_node) &&
3893 (0 == ps_vcl_nal->ps_bot_node->i4_dependency_id))
3894 {
3895 }
3896 else
3897 {
3898 /* call the function which corrects the frame number of each node */
3899 /* based on previous access unit frame number */
3900 isvcd_conceal_node_params(ps_vcl_nal, ps_prev_au_prms);
3901 }
3902 /* get the top most node */
3903 ps_vcl_node = ps_vcl_nal->ps_top_node;
3904
3905 /* get the IDR picture flag for top most layer in current AU */
3906 /* if not valid then set the value present in the first valid node */
3907 {
3908 vcl_node_t *ps_node;
3909 WORD32 i4_node_present_flag;
3910
3911 ps_node = ps_vcl_node;
3912 i4_node_present_flag = SVCD_FALSE;
3913
3914 /* store default values */
3915 i4_idr_pic_flag = SVCD_FALSE;
3916 i4_nal_ref_idc = 0;
3917 i4_idr_pic_num = 0;
3918
3919 /* loop until valid node */
3920 while(NULL != ps_node)
3921 {
3922 if(NULL != ps_node->ps_first_vcl_nal)
3923 {
3924 i4_idr_pic_flag = ps_node->i4_idr_pic_flag;
3925 i4_nal_ref_idc = ps_node->i4_nal_ref_idc;
3926 i4_idr_pic_num = ps_node->i4_idr_pic_num;
3927 i4_node_present_flag = SVCD_TRUE;
3928 break;
3929 }
3930 else if(SVCD_TRUE == ps_node->i4_idr_pic_flag)
3931 {
3932 i4_idr_pic_flag = ps_node->i4_idr_pic_flag;
3933 i4_nal_ref_idc = ps_node->i4_nal_ref_idc;
3934 i4_idr_pic_num = ps_node->i4_idr_pic_num;
3935 i4_node_present_flag = SVCD_TRUE;
3936 break;
3937 }
3938 /* point to next node */
3939 ps_node = ps_node->ps_bot_node;
3940 }
3941
3942 /* alteast one node should be present */
3943 if(SVCD_FALSE == i4_node_present_flag)
3944 {
3945 return (NOT_OK);
3946 }
3947 }
3948
3949 /* initially the access unit is considered to have a single resolution */
3950 ai4_dep_id[0] = 0;
3951 ps_vcl_nal->i4_num_res_lyrs = 1;
3952 i4_restore_prms_flag = SVCD_FALSE;
3953
3954 /*-----------------------------------------------------------------------*/
3955 /* loop until all the nodes are processed */
3956 /*-----------------------------------------------------------------------*/
3957 while(NULL != ps_vcl_node)
3958 {
3959 WORD32 i4_ref_lyr_dqid, i4_status;
3960 vcl_node_t *ps_bot_vcl_node;
3961 WORD32 i4_res_chnge_flag = SVCD_FALSE;
3962 WORD32 i4_dep_id, i4_qua_id;
3963 WORD32 i4_prev_sps_pps_valid;
3964 WORD32 i4_prev_au_prms_valid;
3965
3966 /* set the reference layer DQID to -1 */
3967 i4_ref_lyr_dqid = -1;
3968
3969 /* get the current layer dependency and quality id */
3970 i4_dep_id = ps_vcl_node->i4_dependency_id;
3971 i4_qua_id = ps_vcl_node->i4_quality_id;
3972
3973 /* get the valid status of prev access unit params */
3974 i4_prev_au_prms_valid = ps_prev_au_prms[i4_dep_id].i4_updated_sts;
3975 i4_prev_sps_pps_valid = ps_pps_sps_prev[(i4_dep_id << 4) + i4_qua_id].i4_updated_sts;
3976
3977 /* missing layer handling */
3978 if(NULL == ps_vcl_node->ps_first_vcl_nal)
3979 {
3980 /* store the params appropriately */
3981 ps_vcl_node->i4_idr_pic_flag = i4_idr_pic_flag;
3982 ps_vcl_node->i4_nal_ref_idc = i4_nal_ref_idc;
3983 ps_vcl_node->i4_idr_pic_num = i4_idr_pic_num;
3984 ps_vcl_node->i4_num_slices = 0;
3985 ps_vcl_node->i4_use_ref_base = 0;
3986 ps_vcl_node->i4_temporal_id = 0;
3987
3988 if((0 != i4_dep_id) || (0 != i4_qua_id))
3989 {
3990 ps_vcl_node->i4_nal_unit_type = CODED_SLICE_EXTENSION_NAL;
3991 ps_vcl_node->u1_acc_no_int_pred = 0;
3992 }
3993 else if(SVCD_TRUE == i4_idr_pic_flag)
3994 {
3995 ps_vcl_node->i4_nal_unit_type = IDR_SLICE_NAL;
3996 ps_vcl_node->u1_acc_no_int_pred = 1;
3997 }
3998 else
3999 {
4000 ps_vcl_node->i4_nal_unit_type = SLICE_NAL;
4001 ps_vcl_node->u1_acc_no_int_pred = 1;
4002 }
4003
4004 if(SVCD_FALSE == i4_idr_pic_flag)
4005 {
4006 /* pick the other params form previous access unit */
4007 if(SVCD_TRUE == i4_prev_sps_pps_valid)
4008 {
4009 ps_vcl_node->u1_pps_id =
4010 ps_pps_sps_prev[(i4_dep_id << 4) + i4_qua_id].u1_pps_id;
4011
4012 ps_vcl_node->u1_sps_id =
4013 ps_pps_sps_prev[(i4_dep_id << 4) + i4_qua_id].u1_sps_id;
4014 }
4015
4016 if(SVCD_TRUE == i4_prev_au_prms_valid)
4017 {
4018 if(0 == ps_vcl_node->i4_nal_ref_idc)
4019 {
4020 ps_vcl_node->u2_frm_num = ps_prev_au_prms[i4_dep_id].u2_frm_num;
4021 }
4022 else
4023 {
4024 ps_vcl_node->u2_frm_num = ps_prev_au_prms[i4_dep_id].u2_frm_num + 1;
4025 }
4026 }
4027 }
4028 }
4029
4030 /* SPS id cannot change unless its an IDR pic */
4031 if(SVCD_FALSE == ps_vcl_node->i4_idr_pic_flag)
4032 {
4033 if(SVCD_TRUE == i4_prev_sps_pps_valid)
4034 {
4035 /* store the SPS id of the current layer */
4036 ps_vcl_node->u1_sps_id = ps_pps_sps_prev[(i4_dep_id << 4) + i4_qua_id].u1_sps_id;
4037 }
4038 }
4039
4040 /* store the PPS id and SPS id of the current layer */
4041 ps_pps_sps_prev[(i4_dep_id << 4) + i4_qua_id].u1_pps_id = ps_vcl_node->u1_pps_id;
4042 ps_pps_sps_prev[(i4_dep_id << 4) + i4_qua_id].u1_sps_id = ps_vcl_node->u1_sps_id;
4043 ps_pps_sps_prev[(i4_dep_id << 4) + i4_qua_id].i4_updated_sts = SVCD_TRUE;
4044
4045 /* handling of no_inter_layer_pred_flag 1 cases */
4046 if((1 == ps_vcl_node->u1_acc_no_int_pred) && (NULL != ps_vcl_node->ps_bot_node))
4047 {
4048 if(SVCD_TRUE == i4_idr_pic_flag)
4049 {
4050 /* take a back up of the parameters till the current node. */
4051 /* these parameters will be restored at the end of loop */
4052
4053 if(SVCD_FALSE == i4_restore_prms_flag)
4054 {
4055 /* get the number of resolution detected so far */
4056 i4_num_res_lyrs_bup = ps_vcl_nal->i4_num_res_lyrs;
4057
4058 ps_node_bup = ps_vcl_node;
4059
4060 /* set the restore params flag */
4061 i4_restore_prms_flag = SVCD_TRUE;
4062 }
4063 }
4064 else
4065 {
4066 ps_vcl_node->i4_ref_dq_id = -1;
4067 ps_vcl_node->i4_res_change_flag = i4_res_chnge_flag;
4068
4069 /* store the reference DQID for current dependency */
4070 ps_prev_au_prms[i4_dep_id].i4_ref_dq_id = -1;
4071 ps_prev_au_prms[i4_dep_id].u2_frm_num = ps_vcl_node->u2_frm_num;
4072 ps_prev_au_prms[i4_dep_id].i4_nal_ref_id = ps_vcl_node->i4_nal_ref_idc;
4073
4074 /* the bottom node is set to NULL */
4075 ps_vcl_node->ps_bot_node = NULL;
4076 break;
4077 }
4078 }
4079
4080 /* derive the reference layer DQID for quality id equal to 0 */
4081 if(0 == i4_qua_id)
4082 {
4083 dec_seq_params_t *ps_curr_sps;
4084 dec_svc_seq_params_t *ps_curr_subset_sps;
4085
4086 /* derive current SPS */
4087 ps_curr_sps = ps_sps + ps_vcl_node->u1_sps_id;
4088 ps_curr_subset_sps = ps_subset_sps + ps_vcl_node->u1_sps_id;
4089
4090 {
4091 WORD32 i4_max_frm_num;
4092
4093 /* get the maximum value of frame number */
4094 i4_max_frm_num = (1 << (ps_curr_sps->u1_bits_in_frm_num + 1));
4095 ps_vcl_node->u2_frm_num = ps_vcl_node->u2_frm_num % i4_max_frm_num;
4096 if(SVCD_TRUE == ps_vcl_node->i4_idr_pic_flag)
4097 {
4098 /* if idr then frm num should be 0 */
4099 ps_vcl_node->u2_frm_num = 0;
4100 }
4101 }
4102
4103 /* store default params to inter layer deblocking params */
4104 ps_vcl_node->i4_inter_lyr_dblk_idc = 0;
4105 ps_vcl_node->i4_inter_lyr_beta_offset = 0;
4106 ps_vcl_node->i4_inter_lyr_alpha_c0_offset = 0;
4107 /* No SEI support for scalability info*/
4108 i4_status = NOT_OK;
4109
4110 /* if no inter layer pred flag is present set the */
4111 /* status to fail since the slices will not contain */
4112 /* reference layer Dqid */
4113 if(1 == ps_vcl_node->u1_acc_no_int_pred)
4114 {
4115 i4_status = NOT_OK;
4116 }
4117 else
4118 {
4119 WORD32 *pi4_ref_dq_id;
4120 WORD32 i4_ref_dq_id_temp;
4121
4122 /* check if the SEI message has given the ref_dq_id */
4123 if(NOT_OK == i4_status)
4124 {
4125 pi4_ref_dq_id = &i4_ref_lyr_dqid;
4126 }
4127 else
4128 {
4129 pi4_ref_dq_id = &i4_ref_dq_id_temp;
4130 }
4131
4132 i4_status = isvcd_get_ref_lyr_dqid(ps_vcl_node, ps_sps, ps_pps, pi4_ref_dq_id,
4133 ps_prev_au_prms[i4_dep_id].i4_ref_dq_id,
4134 &ps_svcd_ctxt->i4_error_code, ps_svcd_ctxt);
4135 }
4136
4137 /* no slice in the layer has been successfully decoded */
4138 if(NOT_OK == i4_status)
4139 {
4140 /* check for IDR picture */
4141 if(SVCD_TRUE == i4_idr_pic_flag)
4142 {
4143 /* set the next lower layer as the reference layer */
4144 if(NULL != ps_vcl_node->ps_bot_node)
4145 {
4146 i4_ref_lyr_dqid = ps_vcl_node->ps_bot_node->i4_dependency_id << 4;
4147
4148 i4_ref_lyr_dqid += ps_vcl_node->ps_bot_node->i4_quality_id;
4149 }
4150 else
4151 {
4152 i4_ref_lyr_dqid = -1;
4153 }
4154 }
4155 else
4156 {
4157 /* take the reference dq id from previous access unit */
4158 i4_ref_lyr_dqid = ps_prev_au_prms[i4_dep_id].i4_ref_dq_id;
4159 }
4160 }
4161
4162 /* Update the DQID list based on ref DQID. */
4163 /* This routine also updates the ref_dq_id */
4164 /* in case the actual layer is completely lost */
4165 i4_status = isvcd_update_dqid(i4_ref_lyr_dqid, ps_vcl_node, &ps_bot_vcl_node);
4166
4167 if(!(OK == i4_status))
4168 {
4169 return i4_status;
4170 }
4171
4172 /* store the reference DQID for current depedency and */
4173 /* quality id 0 layer */
4174 ps_prev_au_prms[i4_dep_id].i4_ref_dq_id = i4_ref_lyr_dqid;
4175 ps_prev_au_prms[i4_dep_id].i4_nal_ref_id = ps_vcl_node->i4_nal_ref_idc;
4176 ps_prev_au_prms[i4_dep_id].u2_frm_num = ps_vcl_node->u2_frm_num;
4177 ps_prev_au_prms[i4_dep_id].i4_updated_sts = SVCD_TRUE;
4178
4179 /* ------- Detect Resolution Change ---------------- */
4180 {
4181 dec_seq_params_t *ps_lower_sps = NULL;
4182 dec_svc_seq_params_t *ps_lower_subset_sps = NULL;
4183
4184 if(NULL != ps_bot_vcl_node)
4185 {
4186 if((NULL != ps_bot_vcl_node->ps_first_vcl_nal) ||
4187 (SVCD_TRUE == i4_idr_pic_flag))
4188 {
4189 /* get the SPS of layer */
4190 ps_lower_sps = ps_sps + ps_bot_vcl_node->u1_sps_id;
4191 ps_lower_subset_sps = ps_subset_sps + ps_bot_vcl_node->u1_sps_id;
4192 }
4193 else
4194 {
4195 /* if the bottom layer is completely missed */
4196 WORD32 i4_bot_dep_id, i4_bot_qua_id;
4197 UWORD8 u1_sps_id = 0;
4198
4199 /* sps id is picked from previous access unit */
4200 i4_bot_dep_id = ps_bot_vcl_node->i4_dependency_id;
4201 i4_bot_qua_id = ps_bot_vcl_node->i4_quality_id;
4202
4203 if(SVCD_TRUE ==
4204 ps_pps_sps_prev[(i4_bot_dep_id << 4) + i4_bot_qua_id].i4_updated_sts)
4205 {
4206 u1_sps_id =
4207 ps_pps_sps_prev[(i4_bot_dep_id << 4) + i4_bot_qua_id].u1_sps_id;
4208 }
4209 else
4210 {
4211 /* should not enter here */
4212 return NOT_OK;
4213 }
4214
4215 /* get the SPS of lower layer */
4216 ps_lower_sps = ps_sps + u1_sps_id;
4217 ps_lower_subset_sps = ps_subset_sps + u1_sps_id;
4218 }
4219 }
4220
4221 /* call the function which detects resolution change */
4222 i4_res_chnge_flag = isvcd_detect_res_change(
4223 ps_curr_sps, ps_lower_sps, ps_curr_subset_sps, ps_lower_subset_sps);
4224
4225 /* if a resolution exists below current resolution */
4226 if(SVCD_TRUE == i4_res_chnge_flag)
4227 {
4228 /* if current picture id IDR */
4229 if(SVCD_TRUE == i4_idr_pic_flag)
4230 {
4231 /* store the depedency id of bottom most layer in current resolution */
4232 ai4_dep_id[ps_vcl_nal->i4_num_res_lyrs - 1] = i4_dep_id;
4233 }
4234
4235 /* increment the num resolution layer counter */
4236 ps_vcl_nal->i4_num_res_lyrs++;
4237
4238 /* store the SPS of target -1 and -2 resolution layers */
4239 if(2 == ps_vcl_nal->i4_num_res_lyrs)
4240 {
4241 ps_sps_tgt_minus1_lyr = ps_curr_sps;
4242 }
4243 else if(3 == ps_vcl_nal->i4_num_res_lyrs)
4244 {
4245 ps_sps_tgt_minus2_lyr = ps_curr_sps;
4246 }
4247 else if(ps_vcl_nal->i4_num_res_lyrs > MAX_NUM_RES_LYRS)
4248 {
4249 return NOT_OK;
4250 }
4251 }
4252 }
4253
4254 /* -------- end of resolution change detection -------- */
4255 }
4256 else
4257 {
4258 i4_ref_lyr_dqid = (i4_dep_id << 4);
4259 i4_ref_lyr_dqid += (i4_qua_id - 1);
4260
4261 /* Update the DQID list based on ref DQID. */
4262 /* This routine also updates the ref_dq_id */
4263 /* in case the actual layer is completely lost */
4264 i4_status = isvcd_update_dqid(i4_ref_lyr_dqid, ps_vcl_node, &ps_bot_vcl_node);
4265
4266 if(!(OK == i4_status))
4267 {
4268 return i4_status;
4269 }
4270 if(SVCD_TRUE == ps_vcl_node->i4_idr_pic_flag)
4271 {
4272 /* if idr then frm num should be 0 */
4273 ps_vcl_node->u2_frm_num = 0;
4274 }
4275 }
4276
4277 /* Update resolution change flag inside VCL */
4278 /* node structure. This parameter is later used*/
4279 /* in detecting the top most layer in the */
4280 /* resolution currently being decoded */
4281 ps_vcl_node->i4_res_change_flag = i4_res_chnge_flag;
4282 ps_vcl_node->i4_ref_dq_id = i4_ref_lyr_dqid;
4283
4284 /* go to the next node */
4285 ps_vcl_node = ps_bot_vcl_node;
4286 }
4287
4288 /* update the Dependency array for each resolution */
4289 if(SVCD_TRUE == i4_idr_pic_flag)
4290 {
4291 WORD32 i4_idx;
4292
4293 ai4_dep_id[ps_vcl_nal->i4_num_res_lyrs - 1] = 0;
4294
4295 /* loop over number of resolutions detected */
4296 for(i4_idx = 0; i4_idx < ps_vcl_nal->i4_num_res_lyrs; i4_idx++)
4297 {
4298 pi4_dep_id_map[i4_idx] = ai4_dep_id[ps_vcl_nal->i4_num_res_lyrs - 1 - i4_idx];
4299 }
4300 }
4301
4302 if(SVCD_TRUE == i4_restore_prms_flag)
4303 {
4304 /* restore the number of resolutions */
4305 ps_vcl_nal->i4_num_res_lyrs = i4_num_res_lyrs_bup;
4306
4307 ps_vcl_node = ps_node_bup;
4308
4309 /* set the bottom node to NULL */
4310 ps_vcl_node->ps_bot_node = NULL;
4311
4312 ps_vcl_node->i4_ref_dq_id = -1;
4313 ps_vcl_node->i4_res_change_flag = SVCD_FALSE;
4314
4315 /* store the reference DQID for current dependency */
4316 ps_prev_au_prms[ps_vcl_node->i4_dependency_id].i4_ref_dq_id = -1;
4317
4318 ps_prev_au_prms[ps_vcl_node->i4_dependency_id].u2_frm_num = ps_vcl_node->u2_frm_num;
4319
4320 ps_prev_au_prms[ps_vcl_node->i4_dependency_id].i4_nal_ref_id = ps_vcl_node->i4_nal_ref_idc;
4321 }
4322
4323 /* Finally update the bottom most node in the current access unit */
4324 ps_vcl_node = ps_vcl_nal->ps_top_node;
4325
4326 while(NULL != ps_vcl_node->ps_bot_node)
4327 {
4328 ps_vcl_node = ps_vcl_node->ps_bot_node;
4329 }
4330
4331 ps_vcl_nal->ps_bot_node = ps_vcl_node;
4332
4333 /* check on validity of Target Layer -1 and -2 dimensions */
4334 if((NULL != ps_sps_tgt_minus1_lyr) && (0 == ps_sps_tgt_minus1_lyr->u1_is_valid))
4335 {
4336 if((H264_MAX_FRAME_WIDTH < (WORD32) (ps_sps_tgt_minus1_lyr->u2_frm_wd_in_mbs << 4)) ||
4337 (H264_MAX_FRAME_HEIGHT < (WORD32) (ps_sps_tgt_minus1_lyr->u2_frm_ht_in_mbs << 4)))
4338 {
4339 return NOT_OK;
4340 }
4341 }
4342
4343 if((NULL != ps_sps_tgt_minus2_lyr) && (0 == ps_sps_tgt_minus2_lyr->u1_is_valid))
4344 {
4345 if((H264_MAX_FRAME_WIDTH < (WORD32) (ps_sps_tgt_minus2_lyr->u2_frm_wd_in_mbs << 4)) ||
4346 (H264_MAX_FRAME_HEIGHT < (WORD32) (ps_sps_tgt_minus2_lyr->u2_frm_ht_in_mbs << 4)))
4347 {
4348 return NOT_OK;
4349 }
4350 }
4351
4352 return (OK);
4353 }
4354
4355 /*****************************************************************************/
4356 /* */
4357 /* Function Name : isvcd_dec_non_vcl */
4358 /* */
4359 /* Description : this function decodes the NON VCL NAL units */
4360 /* */
4361 /* */
4362 /* Inputs : pv_out_non_vcl : pointer to the structure containing */
4363 /* NON VCL NAL units */
4364 /* ps_seq_params : pointer to array of SPS structures */
4365 /* ps_pic_params : pointer to array of PPS structures */
4366 /* ps_sei_ctxt : pointer to array of SEI structures */
4367 /* Globals : none */
4368 /* Processing : it decodes the units unitl all the units are */
4369 /* decoded */
4370 /* Outputs : decoded parameters in appropriate structures */
4371 /* Returns : Success or Faliure */
4372 /* */
4373 /* Issues : */
4374 /* */
4375 /* Revision History: */
4376 /* */
4377 /* DD MM YYYY Author(s) Changes (Describe the changes made) */
4378 /* 06 09 2021 vijayakumar creation */
4379 /* */
4380 /*****************************************************************************/
isvcd_dec_non_vcl(void * pv_out_non_vcl,void * pv_seq_params,void * pv_pic_params,svc_dec_ctxt_t * ps_svcd_ctxt)4381 WORD32 isvcd_dec_non_vcl(void *pv_out_non_vcl, void *pv_seq_params, void *pv_pic_params,
4382 svc_dec_ctxt_t *ps_svcd_ctxt)
4383 {
4384 /* local varibles */
4385 non_vcl_nal_t *ps_non_vcl;
4386 WORD32 i4_unit_indx;
4387 non_vcl_buf_hdr_t *ps_non_vcl_buf;
4388 WORD32 i_status = OK;
4389 dec_struct_t *ps_dec;
4390 svc_dec_lyr_struct_t *ps_svc_lyr_dec;
4391 dec_bit_stream_t *ps_bitstrm;
4392
4393 if((NULL == pv_out_non_vcl) || (NULL == pv_seq_params) || (NULL == pv_pic_params))
4394 {
4395 return NOT_OK;
4396 }
4397 UNUSED(pv_seq_params);
4398 UNUSED(pv_pic_params);
4399
4400 /* currently SEI decoding is not supported */
4401 /* derive the local variables */
4402 ps_non_vcl = (non_vcl_nal_t *) pv_out_non_vcl;
4403 ps_non_vcl_buf = ps_non_vcl->ps_first_non_vcl_nal;
4404 if(NULL == ps_non_vcl_buf) return (NOT_OK);
4405
4406 /* loop until all NON VCL NAL are decoded */
4407 for(i4_unit_indx = 0; i4_unit_indx < ps_non_vcl->i4_num_non_vcl_nals; i4_unit_indx++)
4408 {
4409 UWORD32 u4_nal_unit_type;
4410 ps_svc_lyr_dec = ps_svcd_ctxt->ps_svc_dec_lyr;
4411 ps_dec = &ps_svc_lyr_dec->s_dec;
4412 if(NULL == ps_non_vcl_buf) return (NOT_OK);
4413 /* get the current NAL unit type */
4414 u4_nal_unit_type = (UWORD32) ps_non_vcl_buf->i4_nal_unit_type;
4415 if(u4_nal_unit_type > MAX_SVC_NAL_UNIT_TYPE) return (NOT_OK);
4416 ps_dec->u1_nal_unit_type = u4_nal_unit_type;
4417
4418 ps_dec->ps_bitstrm->pu4_buffer =
4419 (UWORD32 *) ((UWORD8 *) ps_non_vcl_buf + ps_non_vcl_buf->i4_buf_offset);
4420 ps_dec->ps_bitstrm->u4_ofst = 0;
4421 ps_dec->ps_bitstrm->u4_max_ofst = isvcd_nal_rbsp_to_sodb(
4422 (UWORD8 *) ps_dec->ps_bitstrm->pu4_buffer, ps_non_vcl_buf->i4_buf_size, 0);
4423 if(ps_dec->ps_bitstrm->u4_max_ofst <= 0) return (NOT_OK);
4424
4425 ps_bitstrm = ps_dec->ps_bitstrm;
4426
4427 /* call the processing module based on nal unit type */
4428 switch(u4_nal_unit_type)
4429 {
4430 case SEQ_PARAM_NAL:
4431
4432 i_status = isvcd_parse_sps(ps_svc_lyr_dec, ps_bitstrm);
4433
4434 if(!i_status)
4435 {
4436 ps_dec->i4_header_decoded |= 0x1;
4437 ps_svcd_ctxt->u4_num_sps_ctr++;
4438 }
4439
4440 if(i_status) return i_status;
4441
4442 break;
4443 case SUBSET_SPS_NAL:
4444
4445 i_status = isvcd_parse_subset_sps(ps_svc_lyr_dec, ps_bitstrm);
4446
4447 if(!i_status)
4448 {
4449 ps_svcd_ctxt->u4_num_sps_ctr++;
4450 ps_dec->i4_header_decoded |= 0x1;
4451 }
4452 if(i_status) return i_status;
4453
4454 break;
4455
4456 case PIC_PARAM_NAL:
4457
4458 i_status = isvcd_parse_pps(ps_svc_lyr_dec, ps_bitstrm);
4459 if(i_status == ERROR_INV_SPS_PPS_T) return i_status;
4460 if(!i_status)
4461 {
4462 ps_dec->i4_header_decoded |= 0x2;
4463 ps_svcd_ctxt->u4_num_pps_ctr++;
4464 }
4465 break;
4466 case SEI_NAL:
4467 {
4468 i_status = ih264d_parse_sei_message(ps_dec, ps_bitstrm);
4469 ih264d_parse_sei(ps_dec, ps_bitstrm);
4470 }
4471 break;
4472 default:
4473 /* no other NON VCL UNIT is supported */
4474 break;
4475 }
4476
4477 /* get the next non vcl bufffer */
4478 ps_non_vcl_buf = ps_non_vcl_buf->ps_next;
4479
4480 } /* end of loop over all NAL units */
4481
4482 return (OK);
4483 }
4484 /*****************************************************************************/
4485 /* */
4486 /* Function Name : isvcd_seq_hdr_dec */
4487 /* */
4488 /* Description : This function decodes sequence header, which includes */
4489 /* non VCL NAL before the first VCL unit */
4490 /* Inputs : Decoder context, inbufs, place holder for number of bytes*/
4491 /* consumed and number of packets consumed */
4492 /* Globals : None */
4493 /* Processing : 1. Parse non VCL units before first VCL unit */
4494 /* 2. Decode parsed non VCL units */
4495 /* Outputs : Decoded header */
4496 /* Returns : OK or NOT_OK */
4497 /* */
4498 /* Issues : no known issues */
4499 /* */
4500 /* Revision History: */
4501 /* */
4502 /* DD MM YYYY Author(s) Changes (Describe the changes made) */
4503 /* 06 09 2021 Kishore Creation */
4504 /* */
4505 /*****************************************************************************/
isvcd_seq_hdr_dec(svc_dec_ctxt_t * ps_svcd_ctxt,ivd_video_decode_ip_t * ps_in_bufs,UWORD32 * pu4_bytes_consumed)4506 WORD32 isvcd_seq_hdr_dec(svc_dec_ctxt_t *ps_svcd_ctxt, ivd_video_decode_ip_t *ps_in_bufs,
4507 UWORD32 *pu4_bytes_consumed)
4508 {
4509 WORD32 i4_status;
4510
4511 /* Decode all non VCL NAL till first VCL NAL is encountered */
4512 ps_svcd_ctxt->s_non_vcl_nal.i4_num_non_vcl_nals = 0;
4513 i4_status = isvcd_nal_parse_non_vcl_nal(
4514 ps_svcd_ctxt->pv_nal_parse_ctxt, ps_in_bufs->pv_stream_buffer, &ps_svcd_ctxt->s_non_vcl_nal,
4515 pu4_bytes_consumed, &ps_in_bufs->u4_num_Bytes);
4516
4517 /* Note: The bitstream extraction module expects updated */
4518 /* pointer whenever a new call to this module has been */
4519 /* made. Hence the buffer pointer has to be incremented */
4520 /* by bytes consumed */
4521 ps_in_bufs->u4_num_Bytes -= *pu4_bytes_consumed;
4522
4523 /* ------------------------------------------------------ */
4524 /* Decoding of non VCL data. As current implementation it */
4525 /* decodes the followings: */
4526 /* 1. Sequence parameter set */
4527 /* 2. Picture parameter set */
4528 /* 3. SEI message */
4529 /* ------------------------------------------------------ */
4530 isvcd_dec_non_vcl(&ps_svcd_ctxt->s_non_vcl_nal, ps_svcd_ctxt->ps_sps, ps_svcd_ctxt->ps_pps,
4531 ps_svcd_ctxt);
4532
4533 return (i4_status);
4534 }
4535
4536 /*****************************************************************************/
4537 /* */
4538 /* Function Name : isvcd_pre_parse_refine_au */
4539 /* */
4540 /* Description : This function process a decode call */
4541 /* Inputs : ps_dec_ctxt : decoder context structure */
4542 /* ps_in_bufs : input buffer descriptor */
4543 /* pu4_bytes_consumed : pointer to store the bytes consumed */
4544 /* pi4_packets_consumed : pointer to store the packets */
4545 /* consumed */
4546 /* Globals : None */
4547 /* Processing : It calls the NAL parse module to parse the input stream */
4548 /* if a picture boundary is detected it calls the */
4549 /* Dependency list refiniment and Picture Decode routines */
4550 /* Outputs : Decoded picture */
4551 /* Returns : OK or NOT_OK */
4552 /* */
4553 /* Issues : None */
4554 /* */
4555 /* Revision History: */
4556 /* */
4557 /* DD MM YYYY Author(s) Changes (Describe the changes made) */
4558 /* 06 09 2021 Kishore Creation */
4559 /* */
4560 /*****************************************************************************/
isvcd_pre_parse_refine_au(svc_dec_ctxt_t * ps_svcd_ctxt,ivd_video_decode_ip_t * ps_in_bufs,UWORD32 * pu4_bytes_consumed)4561 WORD32 isvcd_pre_parse_refine_au(svc_dec_ctxt_t *ps_svcd_ctxt, ivd_video_decode_ip_t *ps_in_bufs,
4562 UWORD32 *pu4_bytes_consumed)
4563 {
4564 WORD32 i4_status, i4_non_vcl_status;
4565 UWORD32 u4_bytes_consumed = 0;
4566 dec_struct_t *ps_dec;
4567 svc_dec_lyr_struct_t *ps_svc_lyr_dec;
4568 ps_svc_lyr_dec = ps_svcd_ctxt->ps_svc_dec_lyr;
4569 ps_dec = &ps_svc_lyr_dec->s_dec;
4570
4571 /* Sequence header decode: */
4572 /* If sequence header is not decoded then decode the seq */
4573 /* uence header */
4574
4575 if(SVCD_FALSE == ps_dec->i4_header_decoded)
4576 {
4577 i4_status = isvcd_seq_hdr_dec(ps_svcd_ctxt, ps_in_bufs, &u4_bytes_consumed);
4578
4579 if((VCL_NAL_FOUND_TRUE == i4_status) && (ps_svcd_ctxt->u4_num_sps_ctr != 0) &&
4580 (ps_svcd_ctxt->u4_num_pps_ctr != 0))
4581 {
4582 /* set the header decoded flag */
4583 ps_dec->i4_header_decoded = 3;
4584 }
4585 }
4586 *pu4_bytes_consumed = u4_bytes_consumed;
4587 if(1 == ps_dec->i4_decode_header)
4588 {
4589 return OK;
4590 }
4591 /* Bit-stream Parsing. It performs following tasks: */
4592 /* 1. NAL hader decoder */
4593 /* 2. Emulation prevention and byte swap */
4594 /* (During this process data to moved to output*/
4595 /* buffer) */
4596 /* 3. Dependency list creation based on NAL header*/
4597 /* 4. Detection of picture boundary */
4598 /* NOTE1: */
4599 /* Output buffers for VCL and non VCL data are */
4600 /* different. VCL data can be retrieved through */
4601 /* dependency list. Whereas non VCL data is stored in*/
4602 /* one single buffer, which is accessed through NON */
4603 /* VCL structure */
4604 /* NOTE2:Partial input case for nal parsing requires a */
4605 /* flush API to be called when end of bitstream */
4606 /* occurs */
4607
4608 if(SVCD_FALSE == ps_svcd_ctxt->i4_eos_flag)
4609 {
4610 if(ps_dec->i4_header_decoded == 3)
4611 {
4612 i4_status = isvcd_nal_parse_vcl_nal_partial(
4613 ps_svcd_ctxt->pv_nal_parse_ctxt, ps_in_bufs->pv_stream_buffer,
4614 &ps_svcd_ctxt->s_non_vcl_nal, &ps_svcd_ctxt->s_vcl_nal, &u4_bytes_consumed,
4615 &ps_in_bufs->u4_num_Bytes);
4616 }
4617 else
4618 {
4619 return NOT_OK;
4620 }
4621 }
4622 else
4623 {
4624 void *pv_nal_parse_ctxt;
4625 pv_nal_parse_ctxt = ps_svcd_ctxt->pv_nal_parse_ctxt;
4626
4627 i4_status = isvcd_nal_parse_partial_signal_eos(pv_nal_parse_ctxt, &ps_svcd_ctxt->s_vcl_nal,
4628 &ps_svcd_ctxt->s_non_vcl_nal);
4629
4630 u4_bytes_consumed = 0;
4631 }
4632
4633 *pu4_bytes_consumed += u4_bytes_consumed;
4634
4635 /* Picture Boundary detected: Go ahead and do the decoding */
4636 /* Picture boundary not detected: Otherwsie retrun from this*/
4637 /* function and update the bytes consumed variable. This */
4638 /* should be repeated till we get a picture boundary */
4639
4640 if(PIC_BOUNDARY_FALSE == i4_status)
4641 {
4642 return (NOT_OK);
4643 }
4644
4645 else if(FLUSH_DECODED_PICTURE == i4_status)
4646 {
4647 /* No more data is expected to come. Pictures decoded */
4648 /* so far needs to be sent for display */
4649 return (FLUSH);
4650 }
4651
4652 if(PIC_BOUNDARY_TRUE != i4_status)
4653 {
4654 return (NOT_OK);
4655 }
4656
4657 /* check if the application has set any of the skip modes */
4658 /* add the support for P and B skip modes */
4659 /* if(ps_dec_ctxt->s_dyn_prms.u1_frame_skip_mode) */
4660
4661 /* Parse slice header to decode reference layer dQId and refine */
4662 /* the dependency list */
4663 /* NOTE: Yes, this processing could be moved into NAL parsing */
4664 /* routine to avoid unneccessary emulation prevention and */
4665 /* byte swapping over discardable data. This Optimization */
4666 /* has been deferred for some time. In future if we found */
4667 /* that there are many such streams which doesn't set */
4668 /* 'discard_flag' correctly in NAL header, we will take a */
4669 /* hit to optimize it. */
4670
4671 /* At present this routine also performs the following */
4672 /* 1. Refine DQID list based on reference layer DQID */
4673 /* 2. Calculates the POC for the target layer */
4674
4675 {
4676 i4_status = isvcd_refine_dep_list(
4677 &ps_svcd_ctxt->s_vcl_nal, ps_svcd_ctxt->ps_sps, ps_svcd_ctxt->ps_subset_sps,
4678 ps_svcd_ctxt->ps_pps, &ps_svcd_ctxt->ai4_dq_id_map[0], &ps_svcd_ctxt->as_au_prms_dep[0],
4679 &ps_svcd_ctxt->as_pps_sps_prev_au[0], &ps_svcd_ctxt->i4_error_code, ps_svcd_ctxt);
4680 }
4681
4682 if(0 != ps_svcd_ctxt->s_non_vcl_nal.i4_num_non_vcl_nals)
4683 {
4684 /* Decoding of non VCL data. In current implementation it */
4685 /* decodes the followings: */
4686 /* 1. Sequence parameter set */
4687 /* 2. Picture parameter set */
4688 /* 3. SEI message */
4689 i4_non_vcl_status = isvcd_dec_non_vcl(&ps_svcd_ctxt->s_non_vcl_nal, ps_svcd_ctxt->ps_sps,
4690 ps_svcd_ctxt->ps_pps, ps_svcd_ctxt);
4691
4692 if(OK != i4_non_vcl_status) return i4_non_vcl_status;
4693 }
4694 if(OK != i4_status) return (i4_status);
4695 return (OK);
4696 }
4697
4698 /*****************************************************************************/
4699 /* */
4700 /* Function Name : isvcd_video_decode */
4701 /* */
4702 /* Description : handle video decode API command */
4703 /* */
4704 /* Inputs :iv_obj_t decoder handle */
4705 /* :pv_api_ip pointer to input structure */
4706 /* :pv_api_op pointer to output structure */
4707 /* Outputs : */
4708 /* Returns : void */
4709 /* */
4710 /* Issues : none */
4711 /* */
4712 /* Revision History: */
4713 /* */
4714 /* DD MM YYYY Author(s) Changes (Describe the changes made) */
4715 /* 06 09 2021 Kishore Draft */
4716 /* */
4717 /*****************************************************************************/
4718
isvcd_video_decode(iv_obj_t * dec_hdl,void * pv_api_ip,void * pv_api_op)4719 WORD32 isvcd_video_decode(iv_obj_t *dec_hdl, void *pv_api_ip, void *pv_api_op)
4720 {
4721 dec_struct_t *ps_dec;
4722 dec_struct_t *ps_dec_zero_lyr;
4723 svc_dec_lyr_struct_t *ps_svc_lyr_dec;
4724 svc_dec_lyr_struct_t *ps_svc_lyr_zero_dec;
4725
4726 svc_dec_ctxt_t *ps_svcd_ctxt;
4727 WORD32 i4_err_status = 0;
4728
4729 UWORD32 bytes_consumed = 0;
4730 WORD32 ret = 0, api_ret_value = IV_SUCCESS;
4731 isvcd_video_decode_ip_t *ps_h264d_dec_ip;
4732 isvcd_video_decode_op_t *ps_h264d_dec_op;
4733 ivd_video_decode_ip_t *ps_dec_ip;
4734 ivd_video_decode_op_t *ps_dec_op;
4735 UWORD8 u1_res_id;
4736
4737 ithread_set_name((void *) "Parse_thread");
4738
4739 ps_svcd_ctxt = (svc_dec_ctxt_t *) (dec_hdl->pv_codec_handle);
4740 ps_svc_lyr_dec = &ps_svcd_ctxt->ps_svc_dec_lyr[0];
4741 ps_dec = &ps_svc_lyr_dec->s_dec;
4742
4743 ps_h264d_dec_ip = (isvcd_video_decode_ip_t *) pv_api_ip;
4744 ps_h264d_dec_op = (isvcd_video_decode_op_t *) pv_api_op;
4745 ps_dec_ip = &ps_h264d_dec_ip->s_ivd_video_decode_ip_t;
4746 ps_dec_op = &ps_h264d_dec_op->s_ivd_video_decode_op_t;
4747
4748 {
4749 UWORD32 u4_size;
4750 u4_size = ps_dec_op->u4_size;
4751 memset(ps_h264d_dec_op, 0, sizeof(isvcd_video_decode_op_t));
4752 ps_dec_op->u4_size = u4_size;
4753 }
4754
4755 ps_dec->pv_dec_out = ps_dec_op;
4756 if(ps_dec->init_done != 1)
4757 {
4758 return IV_FAIL;
4759 }
4760
4761 /*Data memory barries instruction,so that bitstream write by the application
4762 * is complete*/
4763 DATA_SYNC();
4764
4765 if(0 == ps_dec->u1_flushfrm)
4766 {
4767 if(ps_dec_ip->pv_stream_buffer == NULL)
4768 {
4769 ps_dec_op->u4_error_code |= 1 << IVD_UNSUPPORTEDPARAM;
4770 ps_dec_op->u4_error_code |= IVD_DEC_FRM_BS_BUF_NULL;
4771 return IV_FAIL;
4772 }
4773 if(ps_dec_ip->u4_num_Bytes <= 16)
4774 {
4775 ps_dec_op->u4_error_code |= 1 << IVD_UNSUPPORTEDPARAM;
4776 ps_dec_op->u4_error_code |= IVD_DEC_NUMBYTES_INV;
4777 return IV_FAIL;
4778 }
4779 }
4780 #ifdef KEEP_THREADS_ACTIVE
4781 {
4782 UWORD32 i;
4783 ps_dec->i4_break_threads = 0;
4784 for(i = 0; i < 2; i++)
4785 {
4786 ret = ithread_mutex_lock(ps_dec->apv_proc_start_mutex[i]);
4787 RETURN_IF((ret != IV_SUCCESS), ret);
4788
4789 ps_dec->ai4_process_start[i] = PROC_INIT;
4790
4791 ret = ithread_mutex_unlock(ps_dec->apv_proc_start_mutex[i]);
4792 RETURN_IF((ret != IV_SUCCESS), ret);
4793 }
4794 }
4795 #else
4796 ps_dec->u4_dec_thread_created = 0;
4797 ps_dec->u4_bs_deblk_thread_created = 0;
4798 #endif
4799 ps_dec_op->u4_num_bytes_consumed = 0;
4800 ps_dec_op->i4_reorder_depth = -1;
4801 ps_dec_op->i4_display_index = DEFAULT_POC;
4802
4803 ps_dec->ps_out_buffer = NULL;
4804 if(ps_dec_ip->u4_size >= offsetof(ivd_video_decode_ip_t, s_out_buffer))
4805 ps_dec->ps_out_buffer = &ps_dec_ip->s_out_buffer;
4806
4807 if(0 == ps_dec->u4_share_disp_buf && ps_dec->i4_decode_header == 0)
4808 {
4809 UWORD32 i;
4810 if((ps_dec->ps_out_buffer->u4_num_bufs == 0) ||
4811 (ps_dec->ps_out_buffer->u4_num_bufs > IVD_VIDDEC_MAX_IO_BUFFERS))
4812 {
4813 ps_dec_op->u4_error_code |= 1 << IVD_UNSUPPORTEDPARAM;
4814 ps_dec_op->u4_error_code |= IVD_DISP_FRM_ZERO_OP_BUFS;
4815 return IV_FAIL;
4816 }
4817
4818 for(i = 0; i < ps_dec->ps_out_buffer->u4_num_bufs; i++)
4819 {
4820 if(ps_dec->ps_out_buffer->pu1_bufs[i] == NULL)
4821 {
4822 ps_dec_op->u4_error_code |= 1 << IVD_UNSUPPORTEDPARAM;
4823 ps_dec_op->u4_error_code |= IVD_DISP_FRM_OP_BUF_NULL;
4824 return IV_FAIL;
4825 }
4826
4827 if(ps_dec->ps_out_buffer->u4_min_out_buf_size[i] == 0)
4828 {
4829 ps_dec_op->u4_error_code |= 1 << IVD_UNSUPPORTEDPARAM;
4830 ps_dec_op->u4_error_code |= IVD_DISP_FRM_ZERO_OP_BUF_SIZE;
4831 return IV_FAIL;
4832 }
4833 }
4834 }
4835
4836 if(ps_dec->u4_total_frames_decoded >= NUM_FRAMES_LIMIT)
4837 {
4838 ps_dec_op->u4_error_code = ERROR_FRAME_LIMIT_OVER;
4839 return IV_FAIL;
4840 }
4841
4842 ps_dec_op->u4_error_code = 0;
4843 ps_dec_op->e_pic_type = IV_NA_FRAME;
4844 ps_dec_op->u4_output_present = 0;
4845 ps_dec_op->u4_frame_decoded_flag = 0;
4846
4847 /* In case the decoder is not in flush mode(in shared mode),
4848 then decoder has to pick up a buffer to write current frame.
4849 Check if a frame is available in such cases */
4850 if(ps_dec->u1_init_dec_flag == 1 && ps_dec->u4_share_disp_buf == 1 && ps_dec->u1_flushfrm == 0)
4851 {
4852 UWORD32 i;
4853 WORD32 disp_avail = 0, free_id;
4854
4855 /* Check if at least one buffer is available with the codec */
4856 /* If not then return to application with error */
4857 for(i = 0; i < ps_dec->u1_pic_bufs; i++)
4858 {
4859 if(0 == ps_dec->u4_disp_buf_mapping[i] || 1 == ps_dec->u4_disp_buf_to_be_freed[i])
4860 {
4861 disp_avail = 1;
4862 break;
4863 }
4864 }
4865
4866 if(0 == disp_avail)
4867 {
4868 /* If something is queued for display wait for that buffer to be returned
4869 */
4870
4871 ps_dec_op->u4_error_code = IVD_DEC_REF_BUF_NULL;
4872 ps_dec_op->u4_error_code |= (1 << IVD_UNSUPPORTEDPARAM);
4873 return (IV_FAIL);
4874 }
4875
4876 while(1)
4877 {
4878 pic_buffer_t *ps_pic_buf;
4879 ps_pic_buf = (pic_buffer_t *) ih264_buf_mgr_get_next_free(
4880 (buf_mgr_t *) ps_dec->pv_pic_buf_mgr, &free_id);
4881
4882 if(ps_pic_buf == NULL)
4883 {
4884 UWORD32 display_queued = 0;
4885
4886 /* check if any buffer was given for display which is not returned yet */
4887 for(i = 0; i < (MAX_DISP_BUFS_NEW); i++)
4888 {
4889 if(0 != ps_dec->u4_disp_buf_mapping[i])
4890 {
4891 display_queued = 1;
4892 break;
4893 }
4894 }
4895 /* If some buffer is queued for display, then codec has to singal an
4896 error and wait for that buffer to be returned. If nothing is queued for
4897 display then codec has ownership of all display buffers and it can
4898 reuse any of the existing buffers and continue decoding */
4899
4900 if(1 == display_queued)
4901 {
4902 /* If something is queued for display wait for that buffer to be
4903 * returned */
4904 ps_dec_op->u4_error_code = IVD_DEC_REF_BUF_NULL;
4905 ps_dec_op->u4_error_code |= (1 << IVD_UNSUPPORTEDPARAM);
4906 return (IV_FAIL);
4907 }
4908 }
4909 else
4910 {
4911 /* If the buffer is with display, then mark it as in use and then look
4912 * for a buffer again */
4913 if(1 == ps_dec->u4_disp_buf_mapping[free_id])
4914 {
4915 ih264_buf_mgr_set_status((buf_mgr_t *) ps_dec->pv_pic_buf_mgr, free_id,
4916 BUF_MGR_IO);
4917 }
4918 else
4919 {
4920 /**
4921 * Found a free buffer for present call. Release it now.
4922 * Will be again obtained later.
4923 */
4924 ih264_buf_mgr_release((buf_mgr_t *) ps_dec->pv_pic_buf_mgr, free_id,
4925 BUF_MGR_IO);
4926 break;
4927 }
4928 }
4929 }
4930 }
4931
4932 if(ps_dec->u1_enable_mb_info && (ps_dec->i4_header_decoded & DECODED_SPS_MASK))
4933 {
4934 UWORD32 blk_qp_map_size = ps_h264d_dec_ip->u4_8x8_blk_qp_map_size;
4935 UWORD32 blk_type_map_size = ps_h264d_dec_ip->u4_8x8_blk_type_map_size;
4936 UWORD32 blk_8x8_map_size = ps_dec->u4_total_mbs << 2;
4937 if((ps_h264d_dec_ip->pu1_8x8_blk_qp_map && blk_qp_map_size < blk_8x8_map_size) ||
4938 (ps_h264d_dec_ip->pu1_8x8_blk_type_map && blk_type_map_size < blk_8x8_map_size))
4939 {
4940 ps_dec_op->u4_error_code |= 1 << IVD_UNSUPPORTEDPARAM;
4941 ps_dec_op->u4_error_code |= IH264D_INSUFFICIENT_METADATA_BUFFER;
4942 return IV_FAIL;
4943 }
4944 }
4945
4946 if(ps_dec->u1_flushfrm && (1 == ps_svcd_ctxt->u1_pre_parse_in_flush))
4947 {
4948 if(ps_dec->u1_init_dec_flag == 0)
4949 {
4950 ps_dec->u1_flushfrm = 0;
4951 return (IV_FAIL);
4952 }
4953
4954 ps_svc_lyr_dec = &ps_svcd_ctxt->ps_svc_dec_lyr[ps_svcd_ctxt->s_vcl_nal.i4_num_res_lyrs - 1];
4955 ps_dec = &ps_svc_lyr_dec->s_dec;
4956 ps_dec->u4_fmt_conv_cur_row = 0;
4957 ps_dec->u4_output_present = 0;
4958 ps_dec->s_disp_op.u4_error_code = 1;
4959
4960 ps_dec->ps_out_buffer = NULL;
4961 if(ps_dec_ip->u4_size >= offsetof(ivd_video_decode_ip_t, s_out_buffer))
4962 {
4963 ps_dec->ps_out_buffer = &ps_dec_ip->s_out_buffer;
4964 }
4965 ih264d_get_next_display_field(ps_dec, ps_dec->ps_out_buffer, &(ps_dec->s_disp_op));
4966 if(0 == ps_dec->s_disp_op.u4_error_code)
4967 {
4968 /* check output buffer size given by the application */
4969 if(check_app_out_buf_size(ps_dec) != IV_SUCCESS)
4970 {
4971 ps_dec_op->u4_error_code = IVD_DISP_FRM_ZERO_OP_BUF_SIZE;
4972 return (IV_FAIL);
4973 }
4974
4975 ps_dec->u4_fmt_conv_cur_row = 0;
4976 ps_dec->u4_fmt_conv_num_rows = ps_dec->s_disp_frame_info.u4_y_ht;
4977 ih264d_format_convert(ps_dec, &(ps_dec->s_disp_op), ps_dec->u4_fmt_conv_cur_row,
4978 ps_dec->u4_fmt_conv_num_rows);
4979 ps_dec->u4_fmt_conv_cur_row += ps_dec->u4_fmt_conv_num_rows;
4980 ps_dec->u4_output_present = 1;
4981 if(ps_dec->u1_enable_mb_info)
4982 {
4983 UWORD32 disp_buf_id = ps_dec->s_disp_op.u4_disp_buf_id;
4984 if(ps_h264d_dec_ip->pu1_8x8_blk_qp_map)
4985 {
4986 ps_h264d_dec_op->pu1_8x8_blk_qp_map = ps_h264d_dec_ip->pu1_8x8_blk_qp_map;
4987 ps_h264d_dec_op->u4_8x8_blk_qp_map_size = ps_dec->u4_total_mbs << 2;
4988 ih264_memcpy(ps_h264d_dec_op->pu1_8x8_blk_qp_map,
4989 ps_dec->as_buf_id_info_map[disp_buf_id].pu1_qp_map,
4990 ps_dec->u4_total_mbs << 2);
4991 }
4992 if(ps_h264d_dec_ip->pu1_8x8_blk_type_map)
4993 {
4994 ps_h264d_dec_op->pu1_8x8_blk_type_map = ps_h264d_dec_ip->pu1_8x8_blk_type_map;
4995 ps_h264d_dec_op->u4_8x8_blk_type_map_size = ps_dec->u4_total_mbs << 2;
4996 ih264_memcpy(ps_h264d_dec_op->pu1_8x8_blk_type_map,
4997 ps_dec->as_buf_id_info_map[disp_buf_id].pu1_mb_type_map,
4998 ps_dec->u4_total_mbs << 2);
4999 }
5000 }
5001 }
5002 ih264d_export_sei_params(&ps_dec_op->s_sei_decode_op, ps_dec);
5003
5004 ih264d_release_display_field(ps_dec, &(ps_dec->s_disp_op));
5005
5006 ps_dec_op->u4_pic_wd = (UWORD32) ps_dec->u2_disp_width;
5007 ps_dec_op->u4_pic_ht = (UWORD32) ps_dec->u2_disp_height;
5008 ps_dec_op->i4_reorder_depth = ps_dec->i4_reorder_depth;
5009 ps_dec_op->i4_display_index = ps_dec->i4_display_index;
5010 ps_dec_op->u4_new_seq = 0;
5011
5012 ps_dec_op->u4_output_present = ps_dec->u4_output_present;
5013 ps_dec_op->u4_progressive_frame_flag = ps_dec->s_disp_op.u4_progressive_frame_flag;
5014 ps_dec_op->e_output_format = ps_dec->s_disp_op.e_output_format;
5015 ps_dec_op->s_disp_frm_buf = ps_dec->s_disp_op.s_disp_frm_buf;
5016 ps_dec_op->e4_fld_type = ps_dec->s_disp_op.e4_fld_type;
5017 ps_dec_op->u4_ts = ps_dec->s_disp_op.u4_ts;
5018 ps_dec_op->u4_disp_buf_id = ps_dec->s_disp_op.u4_disp_buf_id;
5019
5020 /*In the case of flush ,since no frame is decoded set pic type as invalid*/
5021 ps_dec_op->u4_is_ref_flag = UINT32_MAX;
5022 ps_dec_op->e_pic_type = IV_NA_FRAME;
5023 ps_dec_op->u4_frame_decoded_flag = 0;
5024
5025 if(0 == ps_dec->s_disp_op.u4_error_code)
5026 {
5027 return (IV_SUCCESS);
5028 }
5029 else
5030 return (IV_FAIL);
5031 }
5032
5033 if(ps_dec->u1_res_changed == 1)
5034 {
5035 /*if resolution has changed and all buffers have been flushed, reset
5036 * decoder*/
5037 if(((buf_mgr_t *) ps_dec->pv_pic_buf_mgr)->pv_mutex != NULL)
5038 ih264_buf_mgr_free(ps_dec->pv_pic_buf_mgr);
5039 if(((buf_mgr_t *) ps_dec->pv_mv_buf_mgr)->pv_mutex != NULL)
5040 ih264_buf_mgr_free(ps_dec->pv_mv_buf_mgr);
5041
5042 isvcd_init_decoder(ps_svc_lyr_dec);
5043 }
5044
5045 DEBUG_THREADS_PRINTF(" Starting process call\n");
5046
5047 {
5048 vcl_node_t *ps_cur_node;
5049 UWORD8 u1_num_res_lyrs;
5050 vcl_buf_hdr_t *ps_vcl_buf;
5051 UWORD8 flush_decode = 1;
5052 ps_svcd_ctxt->u1_pre_parse_in_flush = 0;
5053
5054 ret = isvcd_pre_parse_refine_au(ps_svcd_ctxt, ps_dec_ip, &ps_dec_op->u4_num_bytes_consumed);
5055 ps_svcd_ctxt->u1_pre_parse_in_flush = (ret == FLUSH);
5056
5057 if(ret != OK)
5058 {
5059 UWORD32 error = ih264d_map_error((UWORD32) ret);
5060 if(ret != NOT_OK)
5061 {
5062 ps_dec_op->u4_error_code = error | ret;
5063 }
5064 if((ps_dec_op->u4_error_code >> IVD_FATALERROR) & 1)
5065 {
5066 ps_svcd_ctxt->u1_exit_till_next_IDR = 1;
5067 }
5068 api_ret_value = IV_FAIL;
5069 if((ret == IVD_RES_CHANGED) || (ret == IVD_MEM_ALLOC_FAILED) ||
5070 (ret == ERROR_UNAVAIL_PICBUF_T) || (ret == ERROR_UNAVAIL_MVBUF_T) ||
5071 (ret == ERROR_INV_SPS_PPS_T) || (ret == ERROR_FEATURE_UNAVAIL) ||
5072 (ret == IVD_STREAM_WIDTH_HEIGHT_NOT_SUPPORTED) ||
5073 (ret == IVD_DISP_FRM_ZERO_OP_BUF_SIZE))
5074 {
5075 ps_dec->u4_slice_start_code_found = 0;
5076 }
5077 if((ret == ERROR_INCOMPLETE_FRAME) || (ret == ERROR_DANGLING_FIELD_IN_PIC))
5078 {
5079 api_ret_value = IV_FAIL;
5080 }
5081
5082 if(ret == ERROR_IN_LAST_SLICE_OF_PIC)
5083 {
5084 api_ret_value = IV_FAIL;
5085 }
5086 }
5087
5088 if(NOT_OK == ret)
5089 {
5090 if(ps_dec->u4_pic_buf_got == 0)
5091 {
5092 ps_dec->i4_error_code = ERROR_START_CODE_NOT_FOUND;
5093 ps_dec_op->u4_error_code |= 1 << IVD_INSUFFICIENTDATA;
5094
5095 isvcd_fill_output_struct_from_context(ps_svc_lyr_dec, ps_dec_op);
5096
5097 ps_dec_op->u4_error_code = ps_dec->i4_error_code;
5098 ps_dec_op->u4_frame_decoded_flag = 0;
5099 return (IV_FAIL);
5100 }
5101 return (IV_SUCCESS);
5102 }
5103
5104 u1_num_res_lyrs = ps_svcd_ctxt->s_vcl_nal.i4_num_res_lyrs;
5105
5106 /* error concelment: exit till next IDR if any of Non Target layers are
5107 * corrupted */
5108 {
5109 ps_cur_node = ps_svcd_ctxt->s_vcl_nal.ps_bot_node;
5110
5111 if(NULL != ps_cur_node)
5112 {
5113 if(!ps_cur_node->i4_idr_pic_flag)
5114 {
5115 if(u1_num_res_lyrs != ps_svcd_ctxt->u1_prev_num_res_layers)
5116 {
5117 ps_svcd_ctxt->u1_exit_till_next_IDR = 1;
5118 ps_dec_op->u4_error_code = ERROR_UNKNOWN_NAL;
5119 return IV_FAIL;
5120 }
5121 }
5122 else
5123 {
5124 if(u1_num_res_lyrs != ps_svcd_ctxt->u1_prev_num_res_layers)
5125 {
5126 ps_svcd_ctxt->u1_prev_num_res_layers = u1_num_res_lyrs;
5127 }
5128 }
5129 }
5130 }
5131 if(ps_svcd_ctxt->u1_prev_num_res_layers != u1_num_res_lyrs && (u1_num_res_lyrs != 0))
5132 {
5133 ps_svc_lyr_dec = ps_svcd_ctxt->ps_svc_dec_lyr + u1_num_res_lyrs - 1;
5134 ps_dec = &ps_svc_lyr_dec->s_dec;
5135
5136 if(ps_dec->u1_init_dec_flag == 1)
5137 {
5138 ih264d_release_pics_in_dpb((void *) ps_dec, ps_dec->u1_pic_bufs);
5139 ih264d_release_display_bufs(ps_dec);
5140 ih264_disp_mgr_init((disp_mgr_t *) ps_dec->pv_disp_buf_mgr);
5141
5142 ih264_buf_mgr_reset(ps_dec->pv_pic_buf_mgr);
5143 ih264_buf_mgr_reset(ps_dec->pv_mv_buf_mgr);
5144 ih264d_init_ref_bufs(ps_dec->ps_dpb_mgr);
5145 }
5146
5147 // ps_svcd_ctxt->u1_prev_num_res_layers = u1_num_res_lyrs;
5148 }
5149 ps_svcd_ctxt->u1_parse_nal_unit_error = 0;
5150
5151 if((1 == ps_svcd_ctxt->u1_exit_till_next_IDR) &&
5152 (ps_svcd_ctxt->s_vcl_nal.ps_bot_node != NULL))
5153 {
5154 if(1 == ps_svcd_ctxt->s_vcl_nal.ps_bot_node->i4_idr_pic_flag)
5155 {
5156 ps_svcd_ctxt->u1_exit_till_next_IDR = 0;
5157
5158 for(u1_res_id = 0; u1_res_id < u1_num_res_lyrs; u1_res_id++)
5159 {
5160 ps_svc_lyr_dec = ps_svcd_ctxt->ps_svc_dec_lyr + u1_res_id;
5161 ps_dec = &ps_svc_lyr_dec->s_dec;
5162 ih264_buf_mgr_reset(ps_dec->pv_pic_buf_mgr);
5163 ih264_buf_mgr_reset(ps_dec->pv_mv_buf_mgr);
5164 }
5165 }
5166 else
5167 {
5168 ps_dec_op->u4_error_code = ERROR_UNKNOWN_NAL;
5169 return IV_FAIL;
5170 }
5171 }
5172
5173 if((0 == ps_dec->i4_decode_header) && (OK == ret))
5174 {
5175 flush_decode = 0;
5176 ps_cur_node = ps_svcd_ctxt->s_vcl_nal.ps_bot_node;
5177 ps_svc_lyr_zero_dec = ps_svcd_ctxt->ps_svc_dec_lyr;
5178 ps_dec_zero_lyr = &ps_svc_lyr_zero_dec->s_dec;
5179 /* master loop */
5180
5181 for(u1_res_id = 0; u1_res_id < u1_num_res_lyrs; u1_res_id++)
5182 {
5183 UWORD8 u1_layer_nal_data_present = 0;
5184 ps_svcd_ctxt->u1_cur_layer_id = u1_res_id;
5185 ps_svc_lyr_dec = ps_svcd_ctxt->ps_svc_dec_lyr + u1_res_id;
5186 ps_dec = &ps_svc_lyr_dec->s_dec;
5187
5188 ps_dec->i4_decode_header = ps_dec_zero_lyr->i4_decode_header;
5189 ps_dec->i4_header_decoded = ps_dec_zero_lyr->i4_header_decoded;
5190 ps_dec->u1_pic_decode_done = 0;
5191 ps_dec->u4_fmt_conv_cur_row = 0;
5192
5193 ps_dec->u4_output_present = 0;
5194 ps_dec->s_disp_op.u4_error_code = 1;
5195 ps_dec->u4_fmt_conv_num_rows = FMT_CONV_NUM_ROWS;
5196 ps_dec->u4_ts = ps_dec_ip->u4_ts;
5197 ps_dec->i4_frametype = IV_NA_FRAME;
5198 ps_dec->i4_content_type = IV_CONTENTTYPE_NA;
5199
5200 ps_dec->u4_slice_start_code_found = 0;
5201 ps_dec->u2_cur_mb_addr = 0;
5202 ps_dec->u2_total_mbs_coded = 0;
5203 ps_dec->u2_cur_slice_num = 0;
5204 ps_dec->cur_dec_mb_num = 0;
5205 ps_dec->cur_recon_mb_num = 0;
5206 ps_dec->u4_first_slice_in_pic = 1;
5207 ps_dec->u1_slice_header_done = 0;
5208 ps_dec->u1_dangling_field = 0;
5209
5210 ps_dec->u4_dec_thread_created = 0;
5211 ps_dec->u4_bs_deblk_thread_created = 0;
5212 ps_dec->u4_cur_bs_mb_num = 0;
5213 ps_dec->u4_cur_deblk_mb_num = 0;
5214 ps_dec->u4_start_recon_deblk = 0;
5215 ps_dec->u4_sps_cnt_in_process = 0;
5216 ps_dec->u4_pic_buf_got = 0;
5217 ps_dec->pv_dec_out = ps_dec_op;
5218
5219 if(ps_dec_ip->u4_size >= offsetof(ivd_video_decode_ip_t, s_out_buffer))
5220 ps_dec->ps_out_buffer = &ps_dec_ip->s_out_buffer;
5221
5222 ps_dec->u1_nal_unit_type = ps_cur_node->i4_nal_unit_type;
5223 ps_dec->u1_separate_parse = 0;
5224 if(u1_res_id == (u1_num_res_lyrs - 1))
5225 {
5226 ps_svc_lyr_dec->u1_layer_identifier = TARGET_LAYER;
5227 if(ps_dec->u4_num_cores >= 2)
5228 {
5229 ps_dec->u4_num_cores = 2;
5230 ps_dec->u1_separate_parse = 1;
5231 }
5232 }
5233 else if(u1_res_id == 0)
5234 {
5235 ps_svc_lyr_dec->u1_layer_identifier = BASE_LAYER;
5236 ps_dec->u1_separate_parse = 0;
5237 ps_dec->u4_num_cores = 1;
5238 }
5239 else if(u1_res_id != 0)
5240 {
5241 ps_svc_lyr_dec->u1_layer_identifier = MEDIAL_ENHANCEMENT_LAYER;
5242 ps_dec->u1_separate_parse = 0;
5243 ps_dec->u4_num_cores = 1;
5244 }
5245 else
5246 {
5247 return IV_FAIL;
5248 }
5249
5250 ps_svc_lyr_dec->u1_base_res_flag = (0 == u1_res_id);
5251 ps_svc_lyr_dec->ps_nal_svc_ext->u1_idr_flag = ps_cur_node->i4_idr_pic_flag;
5252 ps_svc_lyr_dec->ps_nal_svc_ext->u1_dependency_id = ps_cur_node->i4_dependency_id;
5253 ps_svc_lyr_dec->ps_nal_svc_ext->u1_priority_id = ps_cur_node->i4_priority_id;
5254 ps_svc_lyr_dec->ps_nal_svc_ext->u1_no_inter_layer_pred_flag =
5255 ps_cur_node->u1_acc_no_int_pred;
5256
5257 ps_svc_lyr_dec->ps_nal_svc_ext->u1_quality_id = ps_cur_node->i4_quality_id;
5258 ps_svc_lyr_dec->ps_nal_svc_ext->u1_temporal_id = ps_cur_node->i4_temporal_id;
5259
5260 ps_svc_lyr_dec->ps_nal_svc_ext->u1_use_ref_base_pic_flag =
5261 ps_cur_node->i4_use_ref_base;
5262 ps_svc_lyr_dec->ps_nal_svc_ext->u1_discardable_flag = 0;
5263 ps_svc_lyr_dec->ps_nal_svc_ext->u1_svc_ext_flag = (u1_res_id > 1);
5264 ps_svc_lyr_dec->u4_pps_id_for_layer = UINT32_MAX;
5265 ps_vcl_buf = ps_cur_node->ps_first_vcl_nal;
5266 ps_svc_lyr_dec->u1_error_in_cur_frame = 0;
5267
5268 /* Only for Non target Layers*/
5269 if(NULL != ps_cur_node->ps_top_node)
5270 {
5271 ps_svc_lyr_dec->u1_inter_lyr_disable_dblk_filter_idc =
5272 ps_cur_node->ps_top_node->i4_inter_lyr_dblk_idc;
5273 ps_svc_lyr_dec->i1_inter_lyr_slice_alpha_c0_offset =
5274 ps_cur_node->ps_top_node->i4_inter_lyr_alpha_c0_offset;
5275 ps_svc_lyr_dec->i1_inter_lyr_slice_beta_offset =
5276 ps_cur_node->ps_top_node->i4_inter_lyr_beta_offset;
5277 }
5278
5279 while(NULL != ps_vcl_buf)
5280 {
5281 u1_layer_nal_data_present = 1;
5282 ps_dec->ps_bitstrm->u4_ofst = 0;
5283 ps_dec->ps_bitstrm->pu4_buffer =
5284 (UWORD32 *) ((UWORD8 *) ps_vcl_buf + ps_vcl_buf->i4_buf_offset +
5285 ps_vcl_buf->i4_slice_offset);
5286
5287 ps_dec->ps_bitstrm->u4_max_ofst = ps_vcl_buf->u4_max_bits;
5288
5289 ps_dec_op->u4_frame_decoded_flag = 0;
5290 ret = isvcd_parse_nal_unit(ps_svc_lyr_dec, ps_cur_node->i4_nal_ref_idc);
5291 if(ret != OK)
5292 {
5293 ps_svcd_ctxt->u1_parse_nal_unit_error = 1;
5294 break;
5295 }
5296
5297 /* go to the next slice */
5298 ps_vcl_buf = ps_vcl_buf->ps_next;
5299 }
5300 /* error concelment: exit till next IDR if a Layer data is missing */
5301 if(0 == u1_layer_nal_data_present)
5302 {
5303 ps_svcd_ctxt->u1_exit_till_next_IDR = 1;
5304 ps_dec_op->u4_error_code = ERROR_UNKNOWN_NAL;
5305 return IV_FAIL;
5306 }
5307 /* error concelment: exit till next IDR if any of Non Target layers are
5308 * corrupted */
5309 if((ret != OK) && (u1_res_id != (u1_num_res_lyrs - 1)))
5310 {
5311 ps_svcd_ctxt->u1_exit_till_next_IDR = 1;
5312 ps_dec_op->u4_error_code = ERROR_UNKNOWN_NAL;
5313 return IV_FAIL;
5314 }
5315
5316 if((ret != OK) && (u1_res_id == (u1_num_res_lyrs - 1)))
5317 {
5318 ps_svc_lyr_dec = ps_svcd_ctxt->ps_svc_dec_lyr + u1_num_res_lyrs - 1;
5319 ps_dec = &ps_svc_lyr_dec->s_dec;
5320
5321 if((0 == ps_svcd_ctxt->u4_num_sps_ctr) || (0 == ps_svcd_ctxt->u4_num_pps_ctr) ||
5322 (NULL == ps_dec->ps_cur_pps))
5323 {
5324 ps_svcd_ctxt->u1_exit_till_next_IDR = 1;
5325 ps_dec_op->u4_error_code = ERROR_UNKNOWN_NAL;
5326 ih264d_signal_decode_thread(ps_dec);
5327 return IV_FAIL;
5328 }
5329 }
5330 ps_cur_node = ps_cur_node->ps_top_node;
5331
5332 if((ps_dec->u4_pic_buf_got == 1) && (ret != IVD_MEM_ALLOC_FAILED) &&
5333 ps_dec->u2_total_mbs_coded < ps_dec->u2_frm_ht_in_mbs * ps_dec->u2_frm_wd_in_mbs)
5334 {
5335 // last slice - missing/corruption
5336 WORD32 num_mb_skipped;
5337 WORD32 prev_slice_err;
5338 pocstruct_t temp_poc;
5339 WORD32 ret1;
5340 WORD32 ht_in_mbs;
5341 ht_in_mbs = ps_dec->u2_pic_ht >> (4 + ps_dec->ps_cur_slice->u1_field_pic_flag);
5342 num_mb_skipped =
5343 (ht_in_mbs * ps_dec->u2_frm_wd_in_mbs) - ps_dec->u2_total_mbs_coded;
5344
5345 if(ps_dec->u4_first_slice_in_pic && (ps_dec->u4_pic_buf_got == 0))
5346 prev_slice_err = 1;
5347 else
5348 prev_slice_err = 2;
5349
5350 if(ps_dec->u2_total_mbs_coded == 0)
5351 {
5352 prev_slice_err = 1;
5353 }
5354 ret1 = isvcd_mark_err_slice_skip(
5355 ps_svc_lyr_dec, num_mb_skipped, ps_dec->u1_nal_unit_type == IDR_SLICE_NAL,
5356 ps_dec->ps_cur_slice->u2_frame_num, &temp_poc, prev_slice_err);
5357
5358 if((ret1 == ERROR_UNAVAIL_PICBUF_T) || (ret1 == ERROR_UNAVAIL_MVBUF_T) ||
5359 (ret1 == ERROR_INV_SPS_PPS_T) || (ret1 == ERROR_CORRUPTED_SLICE) ||
5360 (ret == NOT_OK))
5361 {
5362 ret = ret1;
5363 }
5364 }
5365
5366 if((ret == IVD_RES_CHANGED) || (ret == IVD_MEM_ALLOC_FAILED) ||
5367 (ret == ERROR_UNAVAIL_PICBUF_T) || (ret == ERROR_UNAVAIL_MVBUF_T) ||
5368 (ret == ERROR_INV_SPS_PPS_T) || (ret == ERROR_CORRUPTED_SLICE) ||
5369 (ret == IVD_DISP_FRM_ZERO_OP_BUF_SIZE) || (ret == NOT_OK))
5370 {
5371 ps_svcd_ctxt->u1_exit_till_next_IDR = 1;
5372 /* signal the decode thread */
5373 ih264d_signal_decode_thread(ps_dec);
5374 /* dont consume bitstream for change in resolution case */
5375 if(ret == IVD_RES_CHANGED)
5376 {
5377 ps_dec_op->u4_num_bytes_consumed -= bytes_consumed;
5378 }
5379 return IV_FAIL;
5380 }
5381
5382 /* Multi thread - for target Layer decoding*/
5383 if((ps_dec->u1_separate_parse) &&
5384 (ps_svc_lyr_dec->u1_layer_identifier == TARGET_LAYER) &&
5385 (0 == ps_svc_lyr_dec->u1_error_in_cur_frame))
5386 {
5387 /* If Format conversion is not complete,
5388 complete it here */
5389 if(ps_dec->u4_num_cores == 2)
5390 {
5391 /*do deblocking of all mbs*/
5392 if((ps_dec->u4_nmb_deblk == 0) && (ps_dec->u4_start_recon_deblk == 1) &&
5393 (ps_dec->ps_cur_sps->u1_mb_aff_flag == 0))
5394 {
5395 UWORD8 u1_end_of_row = 0;
5396 UWORD32 u4_max_addr;
5397 tfr_ctxt_t s_tfr_ctxt = {0};
5398 tfr_ctxt_t *ps_tfr_cxt = &s_tfr_ctxt;
5399 pad_mgr_t *ps_pad_mgr = &ps_dec->s_pad_mgr;
5400 UWORD32 u4_slice_end = 0;
5401
5402 /*BS is done for all mbs while parsing*/
5403 u4_max_addr = (ps_dec->u2_frm_wd_in_mbs * ps_dec->u2_frm_ht_in_mbs) - 1;
5404 /* BS is moved post recon gen in SVC ext*/
5405
5406 ih264d_init_deblk_tfr_ctxt(ps_dec, ps_pad_mgr, ps_tfr_cxt,
5407 ps_dec->u2_frm_wd_in_mbs, 0);
5408
5409 {
5410 while(u4_slice_end != 1)
5411 {
5412 dec_mb_info_t *p_cur_mb;
5413 WORD32 i, bs_mb_grp;
5414 bs_mb_grp = ps_dec->cur_dec_mb_num - ps_dec->u4_cur_bs_mb_num;
5415
5416 for(i = 0; i < bs_mb_grp; i++)
5417 {
5418 p_cur_mb =
5419 &ps_dec->ps_frm_mb_info[ps_dec->u4_cur_bs_mb_num];
5420
5421 DEBUG_THREADS_PRINTF("ps_dec->u4_cur_bs_mb_num = %d\n",
5422 ps_dec->u4_cur_bs_mb_num);
5423 isvcd_compute_bs_non_mbaff_thread(ps_svc_lyr_dec, p_cur_mb,
5424 ps_dec->u4_cur_bs_mb_num);
5425
5426 ps_dec->u4_cur_bs_mb_num++;
5427 ps_dec->u4_bs_cur_slice_num_mbs++;
5428 }
5429 if(ps_dec->u4_cur_bs_mb_num > u4_max_addr)
5430 {
5431 u4_slice_end = 1;
5432 u1_end_of_row = 1;
5433 }
5434 /*deblock MB group*/
5435 {
5436 UWORD32 u4_num_mbs;
5437
5438 if(ps_dec->u4_cur_bs_mb_num > ps_dec->u4_cur_deblk_mb_num)
5439 {
5440 if(u1_end_of_row)
5441 {
5442 u4_num_mbs = ps_dec->u4_cur_bs_mb_num -
5443 ps_dec->u4_cur_deblk_mb_num;
5444 }
5445 else
5446 {
5447 u4_num_mbs = ps_dec->u4_cur_bs_mb_num -
5448 ps_dec->u4_cur_deblk_mb_num - 1;
5449 }
5450 }
5451 else
5452 u4_num_mbs = 0;
5453
5454 ih264d_check_mb_map_deblk(ps_dec, u4_num_mbs, ps_tfr_cxt,
5455 0);
5456 }
5457 }
5458 }
5459 }
5460 }
5461
5462 /*signal the decode thread*/
5463 ih264d_signal_decode_thread(ps_dec);
5464 }
5465 else if((ps_dec->u1_separate_parse) &&
5466 (ps_svc_lyr_dec->u1_layer_identifier == TARGET_LAYER))
5467 {
5468 /*signal the decode thread*/
5469 ih264d_signal_decode_thread(ps_dec);
5470 }
5471
5472 DATA_SYNC();
5473
5474 if((ps_dec_op->u4_error_code & 0xff) != ERROR_DYNAMIC_RESOLUTION_NOT_SUPPORTED)
5475 {
5476 ps_dec_op->u4_pic_wd = (UWORD32) ps_dec->u2_disp_width;
5477 ps_dec_op->u4_pic_ht = (UWORD32) ps_dec->u2_disp_height;
5478 ps_dec_op->i4_reorder_depth = ps_dec->i4_reorder_depth;
5479 }
5480
5481 // Report if header (sps and pps) has not been decoded yet
5482 if(ps_dec->i4_decode_header == 1 && ps_dec->i4_header_decoded != 3)
5483 {
5484 ps_dec_op->u4_error_code |= (1 << IVD_INSUFFICIENTDATA);
5485 api_ret_value = IV_FAIL;
5486 }
5487
5488 if((ps_dec->u4_pic_buf_got == 1) && (ERROR_DANGLING_FIELD_IN_PIC != i4_err_status))
5489 {
5490 /* For field pictures, set bottom and top picture decoded u4_flag correctly */
5491
5492 if(ps_dec->ps_cur_slice->u1_field_pic_flag)
5493 {
5494 if(1 == ps_dec->ps_cur_slice->u1_bottom_field_flag)
5495 {
5496 ps_dec->u1_top_bottom_decoded |= BOT_FIELD_ONLY;
5497 }
5498 else
5499 {
5500 ps_dec->u1_top_bottom_decoded |= TOP_FIELD_ONLY;
5501 }
5502 }
5503 else
5504 {
5505 ps_dec->u1_top_bottom_decoded = TOP_FIELD_ONLY | BOT_FIELD_ONLY;
5506 }
5507
5508 /* if new frame in not found (if we are still getting slices from
5509 * previous frame) ih264d_deblock_display is not called. Such frames
5510 * will not be added to reference /display
5511 */
5512 if((ps_dec->ps_dec_err_status->u1_err_flag & REJECT_CUR_PIC) == 0)
5513 {
5514 /* Calling Function to deblock Picture and Display */
5515 ret = ih264d_deblock_display(ps_dec);
5516 }
5517
5518 /*set to complete ,as we dont support partial frame decode*/
5519 if(ps_dec->i4_header_decoded == 3)
5520 {
5521 ps_dec->u2_total_mbs_coded = ps_dec->ps_cur_sps->u2_max_mb_addr + 1;
5522 }
5523
5524 /*Update the i4_frametype at the end of picture*/
5525 if(ps_dec->ps_cur_slice->u1_nal_unit_type == IDR_SLICE_NAL)
5526 {
5527 ps_dec->i4_frametype = IV_IDR_FRAME;
5528 }
5529 else if(ps_dec->i4_pic_type == B_SLICE)
5530 {
5531 ps_dec->i4_frametype = IV_B_FRAME;
5532 }
5533 else if(ps_dec->i4_pic_type == P_SLICE)
5534 {
5535 ps_dec->i4_frametype = IV_P_FRAME;
5536 }
5537 else if(ps_dec->i4_pic_type == I_SLICE)
5538 {
5539 ps_dec->i4_frametype = IV_I_FRAME;
5540 }
5541 else
5542 {
5543 H264_DEC_DEBUG_PRINT("Shouldn't come here\n");
5544 }
5545
5546 // Update the content type
5547 ps_dec->i4_content_type = ps_dec->ps_cur_slice->u1_field_pic_flag;
5548
5549 ps_dec->u4_total_frames_decoded = ps_dec->u4_total_frames_decoded + 2;
5550 ps_dec->u4_total_frames_decoded =
5551 ps_dec->u4_total_frames_decoded - ps_dec->ps_cur_slice->u1_field_pic_flag;
5552 }
5553
5554 /* In case the decoder is configured to run in low delay mode,
5555 * then get display buffer and then format convert.
5556 * Note in this mode, format conversion does not run paralelly in a
5557 * thread and adds to the codec cycles
5558 */
5559 if((IVD_DECODE_FRAME_OUT == ps_dec->e_frm_out_mode) && ps_dec->u1_init_dec_flag)
5560 {
5561 ih264d_get_next_display_field(ps_dec, ps_dec->ps_out_buffer,
5562 &(ps_dec->s_disp_op));
5563
5564 if(0 == ps_dec->s_disp_op.u4_error_code)
5565 {
5566 ps_dec->u4_fmt_conv_cur_row = 0;
5567 ps_dec->u4_output_present = 1;
5568 }
5569 else
5570 {
5571 ps_dec->u4_output_present = 0;
5572 }
5573 }
5574
5575 isvcd_fill_output_struct_from_context(ps_svc_lyr_dec, ps_dec_op);
5576
5577 /* If Format conversion is not complete,
5578 complete it here */
5579 /* For Non -target Layers , Buffers are retrived but not displayed*/
5580
5581 if((ps_svc_lyr_dec->u1_layer_identifier == TARGET_LAYER) &&
5582 ps_dec->u4_output_present &&
5583 (ps_dec->u4_fmt_conv_cur_row < ps_dec->s_disp_frame_info.u4_y_ht))
5584 {
5585 ps_dec->u4_fmt_conv_num_rows =
5586 ps_dec->s_disp_frame_info.u4_y_ht - ps_dec->u4_fmt_conv_cur_row;
5587 ih264d_format_convert(ps_dec, &(ps_dec->s_disp_op), ps_dec->u4_fmt_conv_cur_row,
5588 ps_dec->u4_fmt_conv_num_rows);
5589 ps_dec->u4_fmt_conv_cur_row += ps_dec->u4_fmt_conv_num_rows;
5590 }
5591
5592 ih264d_release_display_field(ps_dec, &(ps_dec->s_disp_op));
5593
5594 if(ps_dec->i4_decode_header == 1 && (ps_dec->i4_header_decoded & 1) == 1)
5595 {
5596 ps_dec_op->u4_progressive_frame_flag = 1;
5597 if((NULL != ps_dec->ps_cur_sps) && (1 == (ps_dec->ps_cur_sps->u1_is_valid)))
5598 {
5599 if((0 == ps_dec->ps_sps->u1_frame_mbs_only_flag) &&
5600 (0 == ps_dec->ps_sps->u1_mb_aff_flag))
5601 ps_dec_op->u4_progressive_frame_flag = 0;
5602 }
5603 }
5604
5605 if((TOP_FIELD_ONLY | BOT_FIELD_ONLY) == ps_dec->u1_top_bottom_decoded)
5606 {
5607 ps_dec->u1_top_bottom_decoded = 0;
5608 }
5609 /*--------------------------------------------------------------------*/
5610 /* Do End of Pic processing. */
5611 /* Should be called only if frame was decoded in previous process call*/
5612 /*--------------------------------------------------------------------*/
5613 if(ps_dec->u4_pic_buf_got == 1)
5614 {
5615 if(1 == ps_dec->u1_last_pic_not_decoded)
5616 {
5617 ret = ih264d_end_of_pic_dispbuf_mgr(ps_dec);
5618
5619 if(ret != OK) return ret;
5620
5621 ret = ih264d_end_of_pic(ps_dec);
5622 if(ret != OK) return ret;
5623 }
5624 else
5625 {
5626 ret = ih264d_end_of_pic(ps_dec);
5627 if(ret != OK) return ret;
5628 }
5629 }
5630
5631 if(ps_dec->u1_enable_mb_info && ps_dec->u4_output_present)
5632 {
5633 UWORD32 disp_buf_id = ps_dec->s_disp_op.u4_disp_buf_id;
5634 if(ps_h264d_dec_ip->pu1_8x8_blk_qp_map)
5635 {
5636 ps_h264d_dec_op->pu1_8x8_blk_qp_map = ps_h264d_dec_ip->pu1_8x8_blk_qp_map;
5637 ps_h264d_dec_op->u4_8x8_blk_qp_map_size = ps_dec->u4_total_mbs << 2;
5638 ih264_memcpy(ps_h264d_dec_op->pu1_8x8_blk_qp_map,
5639 ps_dec->as_buf_id_info_map[disp_buf_id].pu1_qp_map,
5640 ps_dec->u4_total_mbs << 2);
5641 }
5642 if(ps_h264d_dec_ip->pu1_8x8_blk_type_map)
5643 {
5644 ps_h264d_dec_op->pu1_8x8_blk_type_map =
5645 ps_h264d_dec_ip->pu1_8x8_blk_type_map;
5646 ps_h264d_dec_op->u4_8x8_blk_type_map_size = ps_dec->u4_total_mbs << 2;
5647 ih264_memcpy(ps_h264d_dec_op->pu1_8x8_blk_type_map,
5648 ps_dec->as_buf_id_info_map[disp_buf_id].pu1_mb_type_map,
5649 ps_dec->u4_total_mbs << 2);
5650 }
5651 }
5652 /*Data memory barrier instruction,so that yuv write by the library is
5653 * complete*/
5654 DATA_SYNC();
5655
5656 H264_DEC_DEBUG_PRINT("The num bytes consumed: %d\n",
5657 ps_dec_op->u4_num_bytes_consumed);
5658 }
5659 }
5660 /* highest layer for flush validation */
5661
5662 if((ps_dec->u1_flushfrm) && (1 == flush_decode))
5663 {
5664 u1_res_id = u1_num_res_lyrs - 1;
5665 ps_svc_lyr_dec = ps_svcd_ctxt->ps_svc_dec_lyr + u1_res_id;
5666 ps_dec = &ps_svc_lyr_dec->s_dec;
5667
5668 ih264d_get_next_display_field(ps_dec, ps_dec->ps_out_buffer, &(ps_dec->s_disp_op));
5669 if(0 == ps_dec->s_disp_op.u4_error_code)
5670 {
5671 /* check output buffer size given by the application */
5672 if(check_app_out_buf_size(ps_dec) != IV_SUCCESS)
5673 {
5674 ps_dec_op->u4_error_code = IVD_DISP_FRM_ZERO_OP_BUF_SIZE;
5675 return (IV_FAIL);
5676 }
5677
5678 ps_dec->u4_fmt_conv_cur_row = 0;
5679 ps_dec->u4_fmt_conv_num_rows = ps_dec->s_disp_frame_info.u4_y_ht;
5680 ih264d_format_convert(ps_dec, &(ps_dec->s_disp_op), ps_dec->u4_fmt_conv_cur_row,
5681 ps_dec->u4_fmt_conv_num_rows);
5682 ps_dec->u4_fmt_conv_cur_row += ps_dec->u4_fmt_conv_num_rows;
5683 ps_dec->u4_output_present = 1;
5684 }
5685 else
5686 {
5687 ps_dec->u4_output_present = 0;
5688 }
5689 ih264d_export_sei_params(&ps_dec_op->s_sei_decode_op, ps_dec);
5690
5691 ih264d_release_display_field(ps_dec, &(ps_dec->s_disp_op));
5692
5693 ps_dec_op->u4_pic_wd = (UWORD32) ps_dec->u2_disp_width;
5694 ps_dec_op->u4_pic_ht = (UWORD32) ps_dec->u2_disp_height;
5695 ps_dec_op->i4_reorder_depth = ps_dec->i4_reorder_depth;
5696 ps_dec_op->i4_display_index = ps_dec->i4_display_index;
5697
5698 ps_dec_op->u4_new_seq = 0;
5699 ps_dec_op->u4_output_present = (ps_svc_lyr_dec->u1_layer_identifier == TARGET_LAYER)
5700 ? ps_dec->u4_output_present
5701 : 0;
5702 ps_dec_op->u4_progressive_frame_flag = ps_dec->s_disp_op.u4_progressive_frame_flag;
5703 ps_dec_op->e_output_format = ps_dec->s_disp_op.e_output_format;
5704 ps_dec_op->s_disp_frm_buf = ps_dec->s_disp_op.s_disp_frm_buf;
5705 ps_dec_op->e4_fld_type = ps_dec->s_disp_op.e4_fld_type;
5706 ps_dec_op->u4_ts = ps_dec->s_disp_op.u4_ts;
5707 ps_dec_op->u4_disp_buf_id = ps_dec->s_disp_op.u4_disp_buf_id;
5708
5709 /*In the case of flush ,since no frame is decoded set pic type as invalid*/
5710 ps_dec_op->u4_is_ref_flag = UINT32_MAX;
5711 ps_dec_op->e_pic_type = IV_NA_FRAME;
5712 ps_dec_op->u4_frame_decoded_flag = 0;
5713
5714 if(0 == ps_dec->s_disp_op.u4_error_code)
5715 {
5716 return (IV_SUCCESS);
5717 }
5718 else
5719 return (IV_FAIL);
5720 }
5721 }
5722
5723 if((ps_dec_op->u4_error_code & 0xff) != ERROR_DYNAMIC_RESOLUTION_NOT_SUPPORTED)
5724 {
5725 ps_dec_op->u4_pic_wd = (UWORD32) ps_dec->u2_disp_width;
5726 ps_dec_op->u4_pic_ht = (UWORD32) ps_dec->u2_disp_height;
5727 ps_dec_op->i4_reorder_depth = ps_dec->i4_reorder_depth;
5728 }
5729 return api_ret_value;
5730 }
5731
5732 /*****************************************************************************/
5733 /* */
5734 /* Function Name : isvcd_set_display_frame */
5735 /* */
5736 /* Description : */
5737 /* */
5738 /* Inputs :iv_obj_t decoder handle */
5739 /* :pv_api_ip pointer to input structure */
5740 /* :pv_api_op pointer to output structure */
5741 /* Outputs : */
5742 /* Returns : void */
5743 /* */
5744 /* Issues : none */
5745 /* */
5746 /* Revision History: */
5747 /* */
5748 /* DD MM YYYY Author(s) Changes (Describe the changes made) */
5749 /* 06 09 2021 Kishore Draft */
5750 /* */
5751 /*****************************************************************************/
isvcd_set_display_frame(iv_obj_t * dec_hdl,void * pv_api_ip,void * pv_api_op)5752 WORD32 isvcd_set_display_frame(iv_obj_t *dec_hdl, void *pv_api_ip, void *pv_api_op)
5753 {
5754 UWORD32 u4_disp_buf_size[3] = {0};
5755 UWORD32 u4_num_disp_bufs;
5756 ivd_set_display_frame_ip_t *dec_disp_ip;
5757 ivd_set_display_frame_op_t *dec_disp_op;
5758 UWORD32 i;
5759 dec_struct_t *ps_dec;
5760 svc_dec_ctxt_t *ps_svcd_ctxt;
5761 svc_dec_lyr_struct_t *ps_svc_lyr_dec;
5762
5763 ps_svcd_ctxt = (svc_dec_ctxt_t *) dec_hdl->pv_codec_handle;
5764
5765 ps_svc_lyr_dec = &ps_svcd_ctxt->ps_svc_dec_lyr[ps_svcd_ctxt->u1_target_layer_id];
5766 ps_dec = &ps_svc_lyr_dec->s_dec;
5767
5768 dec_disp_ip = (ivd_set_display_frame_ip_t *) pv_api_ip;
5769 dec_disp_op = (ivd_set_display_frame_op_t *) pv_api_op;
5770 dec_disp_op->u4_error_code = 0;
5771
5772 ps_dec->u4_num_disp_bufs = 0;
5773 if(ps_dec->u4_share_disp_buf)
5774 {
5775 UWORD32 u4_num_bufs = dec_disp_ip->num_disp_bufs;
5776
5777 u4_num_bufs = MIN(u4_num_bufs, MAX_DISP_BUFS_NEW);
5778 ps_dec->u4_num_disp_bufs = u4_num_bufs;
5779
5780 /* Get the number and sizes of the first buffer. Compare this with the
5781 * rest to make sure all the buffers are of the same size.
5782 */
5783 u4_num_disp_bufs = dec_disp_ip->s_disp_buffer[0].u4_num_bufs;
5784
5785 u4_disp_buf_size[0] = dec_disp_ip->s_disp_buffer[0].u4_min_out_buf_size[0];
5786 u4_disp_buf_size[1] = dec_disp_ip->s_disp_buffer[0].u4_min_out_buf_size[1];
5787 u4_disp_buf_size[2] = dec_disp_ip->s_disp_buffer[0].u4_min_out_buf_size[2];
5788
5789 for(i = 0; i < u4_num_bufs; i++)
5790 {
5791 if(dec_disp_ip->s_disp_buffer[i].u4_num_bufs != u4_num_disp_bufs)
5792 {
5793 return IV_FAIL;
5794 }
5795
5796 if((dec_disp_ip->s_disp_buffer[i].u4_min_out_buf_size[0] != u4_disp_buf_size[0]) ||
5797 (dec_disp_ip->s_disp_buffer[i].u4_min_out_buf_size[1] != u4_disp_buf_size[1]) ||
5798 (dec_disp_ip->s_disp_buffer[i].u4_min_out_buf_size[2] != u4_disp_buf_size[2]))
5799 {
5800 return IV_FAIL;
5801 }
5802
5803 ps_dec->disp_bufs[i].u4_num_bufs = dec_disp_ip->s_disp_buffer[i].u4_num_bufs;
5804
5805 ps_dec->disp_bufs[i].buf[0] = dec_disp_ip->s_disp_buffer[i].pu1_bufs[0];
5806 ps_dec->disp_bufs[i].buf[1] = dec_disp_ip->s_disp_buffer[i].pu1_bufs[1];
5807 ps_dec->disp_bufs[i].buf[2] = dec_disp_ip->s_disp_buffer[i].pu1_bufs[2];
5808
5809 ps_dec->disp_bufs[i].u4_bufsize[0] =
5810 dec_disp_ip->s_disp_buffer[i].u4_min_out_buf_size[0];
5811 ps_dec->disp_bufs[i].u4_bufsize[1] =
5812 dec_disp_ip->s_disp_buffer[i].u4_min_out_buf_size[1];
5813 ps_dec->disp_bufs[i].u4_bufsize[2] =
5814 dec_disp_ip->s_disp_buffer[i].u4_min_out_buf_size[2];
5815 }
5816 }
5817 return IV_SUCCESS;
5818 }
5819
5820 /*****************************************************************************/
5821 /* */
5822 /* Function Name : ih264d_set_flush_mode_svt_ext */
5823 /* */
5824 /* Description : */
5825 /* */
5826 /* Inputs :iv_obj_t decoder handle */
5827 /* :pv_api_ip pointer to input structure */
5828 /* :pv_api_op pointer to output structure */
5829 /* Globals : <Does it use any global variables?> */
5830 /* Outputs : */
5831 /* Returns : void */
5832 /* */
5833 /* Issues : none */
5834 /* */
5835 /* Revision History: */
5836 /* */
5837 /* DD MM YYYY Author(s) Changes (Describe the changes made) */
5838 /* 06 09 2021 Kishore Draft */
5839 /* */
5840 /*****************************************************************************/
isvcd_set_flush_mode(iv_obj_t * dec_hdl,void * pv_api_ip,void * pv_api_op)5841 WORD32 isvcd_set_flush_mode(iv_obj_t *dec_hdl, void *pv_api_ip, void *pv_api_op)
5842 {
5843 UWORD8 u1_layer_id;
5844 dec_struct_t *ps_dec;
5845 svc_dec_lyr_struct_t *ps_svc_lyr_dec;
5846 ivd_ctl_flush_op_t *ps_ctl_op = (ivd_ctl_flush_op_t *) pv_api_op;
5847 svc_dec_ctxt_t *ps_svcd_ctxt;
5848 ps_svcd_ctxt = (svc_dec_ctxt_t *) dec_hdl->pv_codec_handle;
5849
5850 ps_ctl_op->u4_error_code = 0;
5851
5852 ps_svc_lyr_dec = &ps_svcd_ctxt->ps_svc_dec_lyr[0];
5853 ps_dec = &ps_svc_lyr_dec->s_dec;
5854 if(0 == ps_dec->i4_decode_header)
5855 {
5856 ps_svcd_ctxt->i4_eos_flag = 1;
5857 }
5858
5859 for(u1_layer_id = 0; u1_layer_id < MAX_NUM_RES_LYRS; u1_layer_id++)
5860 {
5861 ps_svc_lyr_dec = &ps_svcd_ctxt->ps_svc_dec_lyr[u1_layer_id];
5862 ps_dec = &ps_svc_lyr_dec->s_dec;
5863 UNUSED(pv_api_ip);
5864
5865 /* Signal flush frame control call */
5866 ps_dec->u1_flushfrm = 1;
5867
5868 if(ps_dec->u1_init_dec_flag == 1)
5869 {
5870 ih264d_release_pics_in_dpb((void *) ps_dec, ps_dec->u1_pic_bufs);
5871 ih264d_release_display_bufs(ps_dec);
5872 }
5873
5874 ps_ctl_op->u4_error_code = 0;
5875
5876 /* Ignore dangling fields during flush */
5877 ps_dec->u1_top_bottom_decoded = 0;
5878 }
5879
5880 return IV_SUCCESS;
5881 }
5882
5883 /*****************************************************************************/
5884 /* */
5885 /* Function Name : isvcd_get_status */
5886 /* */
5887 /* Description : */
5888 /* */
5889 /* Inputs :iv_obj_t decoder handle */
5890 /* :pv_api_ip pointer to input structure */
5891 /* :pv_api_op pointer to output structure */
5892 /* Globals : <Does it use any global variables?> */
5893 /* Outputs : */
5894 /* Returns : void */
5895 /* */
5896 /* Issues : none */
5897 /* */
5898 /* Revision History: */
5899 /* */
5900 /* DD MM YYYY Author(s) Changes (Describe the changes made) */
5901 /* 06 09 2021 Kishore Draft */
5902 /* */
5903 /*****************************************************************************/
5904
isvcd_get_status(iv_obj_t * dec_hdl,void * pv_api_ip,void * pv_api_op)5905 WORD32 isvcd_get_status(iv_obj_t *dec_hdl, void *pv_api_ip, void *pv_api_op)
5906 {
5907 UWORD32 i;
5908 dec_struct_t *ps_dec;
5909 UWORD32 pic_wd, pic_ht;
5910 ivd_ctl_getstatus_op_t *ps_ctl_op = (ivd_ctl_getstatus_op_t *) pv_api_op;
5911 svc_dec_ctxt_t *ps_svcd_ctxt;
5912 svc_dec_lyr_struct_t *ps_svc_lyr_dec;
5913 ps_svcd_ctxt = (svc_dec_ctxt_t *) dec_hdl->pv_codec_handle;
5914
5915 ps_svc_lyr_dec = &ps_svcd_ctxt->ps_svc_dec_lyr[ps_svcd_ctxt->u1_target_layer_id];
5916 ps_dec = &ps_svc_lyr_dec->s_dec;
5917 UNUSED(pv_api_ip);
5918 ps_ctl_op->u4_error_code = 0;
5919
5920 if((NULL != ps_dec->ps_cur_sps) && (1 == (ps_dec->ps_cur_sps->u1_is_valid)))
5921 {
5922 ps_ctl_op->u4_pic_ht = ps_dec->u2_disp_height;
5923 ps_ctl_op->u4_pic_wd = ps_dec->u2_disp_width;
5924
5925 if(0 == ps_dec->u4_share_disp_buf)
5926 {
5927 pic_wd = ps_dec->u2_disp_width;
5928 pic_ht = ps_dec->u2_disp_height;
5929 }
5930 else
5931 {
5932 pic_wd = ps_dec->u2_frm_wd_y;
5933 pic_ht = ps_dec->u2_frm_ht_y;
5934 }
5935 }
5936 else
5937 {
5938 pic_wd = 0;
5939 pic_ht = 0;
5940 ps_ctl_op->u4_pic_ht = pic_wd;
5941 ps_ctl_op->u4_pic_wd = pic_ht;
5942
5943 if(1 == ps_dec->u4_share_disp_buf)
5944 {
5945 pic_wd += (PAD_LEN_Y_H << 1);
5946 pic_ht += (PAD_LEN_Y_V << 2);
5947 }
5948 }
5949
5950 if(ps_dec->u4_app_disp_width > pic_wd) pic_wd = ps_dec->u4_app_disp_width;
5951 if(0 == ps_dec->u4_share_disp_buf)
5952 ps_ctl_op->u4_num_disp_bufs = 1;
5953 else
5954 {
5955 if((NULL != ps_dec->ps_cur_sps) && (1 == (ps_dec->ps_cur_sps->u1_is_valid)))
5956 {
5957 if((ps_dec->ps_cur_sps->u1_vui_parameters_present_flag == 1) &&
5958 (1 == ps_dec->ps_cur_sps->s_vui.u1_bitstream_restriction_flag))
5959 {
5960 ps_ctl_op->u4_num_disp_bufs = ps_dec->ps_cur_sps->s_vui.u4_num_reorder_frames + 1;
5961 }
5962 else
5963 {
5964 /*if VUI is not present assume maximum possible refrence frames for the
5965 * level, as max reorder frames*/
5966 ps_ctl_op->u4_num_disp_bufs = ih264d_get_dpb_size(ps_dec->ps_cur_sps);
5967 }
5968
5969 ps_ctl_op->u4_num_disp_bufs += ps_dec->ps_cur_sps->u1_num_ref_frames + 1;
5970 }
5971 else
5972 {
5973 ps_ctl_op->u4_num_disp_bufs = 32;
5974 }
5975 ps_ctl_op->u4_num_disp_bufs = MAX(ps_ctl_op->u4_num_disp_bufs, 6);
5976 ps_ctl_op->u4_num_disp_bufs = MIN(ps_ctl_op->u4_num_disp_bufs, 32);
5977 }
5978
5979 ps_ctl_op->u4_error_code = ps_dec->i4_error_code;
5980 ps_ctl_op->u4_frame_rate = 0;
5981 ps_ctl_op->u4_bit_rate = 0;
5982 ps_ctl_op->e_content_type = ps_dec->i4_content_type;
5983 ps_ctl_op->e_output_chroma_format = ps_dec->u1_chroma_format;
5984 ps_ctl_op->u4_min_num_in_bufs = MIN_IN_BUFS;
5985
5986 if(ps_dec->u1_chroma_format == IV_YUV_420P)
5987 {
5988 ps_ctl_op->u4_min_num_out_bufs = MIN_OUT_BUFS_420;
5989 }
5990 else if(ps_dec->u1_chroma_format == IV_YUV_422ILE)
5991 {
5992 ps_ctl_op->u4_min_num_out_bufs = MIN_OUT_BUFS_422ILE;
5993 }
5994 else if(ps_dec->u1_chroma_format == IV_RGB_565)
5995 {
5996 ps_ctl_op->u4_min_num_out_bufs = MIN_OUT_BUFS_RGB565;
5997 }
5998 else if((ps_dec->u1_chroma_format == IV_YUV_420SP_UV) ||
5999 (ps_dec->u1_chroma_format == IV_YUV_420SP_VU))
6000 {
6001 ps_ctl_op->u4_min_num_out_bufs = MIN_OUT_BUFS_420SP;
6002 }
6003 else
6004 {
6005 // Invalid chroma format; Error code may be updated, verify in testing if needed
6006 ps_ctl_op->u4_error_code = ERROR_FEATURE_UNAVAIL;
6007 return IV_FAIL;
6008 }
6009
6010 for(i = 0; i < ps_ctl_op->u4_min_num_in_bufs; i++)
6011 {
6012 ps_ctl_op->u4_min_in_buf_size[i] = MAX(256000, pic_wd * pic_ht * 3 / 2);
6013 }
6014
6015 if(ps_dec->u1_chroma_format == IV_YUV_420P)
6016 {
6017 ps_ctl_op->u4_min_out_buf_size[0] = (pic_wd * pic_ht);
6018 ps_ctl_op->u4_min_out_buf_size[1] = (pic_wd * pic_ht) >> 2;
6019 ps_ctl_op->u4_min_out_buf_size[2] = (pic_wd * pic_ht) >> 2;
6020 }
6021 else if(ps_dec->u1_chroma_format == IV_YUV_422ILE)
6022 {
6023 ps_ctl_op->u4_min_out_buf_size[0] = (pic_wd * pic_ht) * 2;
6024 ps_ctl_op->u4_min_out_buf_size[1] = ps_ctl_op->u4_min_out_buf_size[2] = 0;
6025 }
6026 else if(ps_dec->u1_chroma_format == IV_RGB_565)
6027 {
6028 ps_ctl_op->u4_min_out_buf_size[0] = (pic_wd * pic_ht) * 2;
6029 ps_ctl_op->u4_min_out_buf_size[1] = ps_ctl_op->u4_min_out_buf_size[2] = 0;
6030 }
6031 else if((ps_dec->u1_chroma_format == IV_YUV_420SP_UV) ||
6032 (ps_dec->u1_chroma_format == IV_YUV_420SP_VU))
6033 {
6034 ps_ctl_op->u4_min_out_buf_size[0] = (pic_wd * pic_ht);
6035 ps_ctl_op->u4_min_out_buf_size[1] = (pic_wd * pic_ht) >> 1;
6036 ps_ctl_op->u4_min_out_buf_size[2] = 0;
6037 }
6038
6039 ps_dec->u4_num_disp_bufs_requested = ps_ctl_op->u4_num_disp_bufs;
6040 return IV_SUCCESS;
6041 }
6042
6043 /*****************************************************************************/
6044 /* */
6045 /* Function Name : isvcd_get_buf_info */
6046 /* */
6047 /* Description : */
6048 /* */
6049 /* Inputs :iv_obj_t decoder handle */
6050 /* :pv_api_ip pointer to input structure */
6051 /* :pv_api_op pointer to output structure */
6052 /* Globals : <Does it use any global variables?> */
6053 /* Outputs : */
6054 /* Returns : void */
6055 /* */
6056 /* Issues : none */
6057 /* */
6058 /* Revision History: */
6059 /* */
6060 /* DD MM YYYY Author(s) Changes (Describe the changes made) */
6061 /* 06 09 2021 Kishore Draft */
6062 /* */
6063 /*****************************************************************************/
isvcd_get_buf_info(iv_obj_t * dec_hdl,void * pv_api_ip,void * pv_api_op)6064 WORD32 isvcd_get_buf_info(iv_obj_t *dec_hdl, void *pv_api_ip, void *pv_api_op)
6065 {
6066 dec_struct_t *ps_dec;
6067 svc_dec_lyr_struct_t *ps_svc_lyr_dec;
6068 UWORD8 i = 0; // Default for 420P format
6069 UWORD16 pic_wd, pic_ht;
6070 ivd_ctl_getbufinfo_op_t *ps_ctl_op = (ivd_ctl_getbufinfo_op_t *) pv_api_op;
6071 UWORD32 au4_min_out_buf_size[IVD_VIDDEC_MAX_IO_BUFFERS] = {0};
6072 svc_dec_ctxt_t *ps_svcd_ctxt;
6073 ps_svcd_ctxt = (svc_dec_ctxt_t *) dec_hdl->pv_codec_handle;
6074
6075 UNUSED(pv_api_ip);
6076
6077 ps_svc_lyr_dec = &ps_svcd_ctxt->ps_svc_dec_lyr[ps_svcd_ctxt->u1_target_layer_id];
6078 ps_dec = &ps_svc_lyr_dec->s_dec;
6079 ps_ctl_op->u4_error_code = 0;
6080
6081 ps_ctl_op->u4_min_num_in_bufs = MIN_IN_BUFS;
6082 ps_ctl_op->u4_num_disp_bufs = 1;
6083 pic_wd = 0;
6084 pic_ht = 0;
6085
6086 if(ps_dec->i4_header_decoded == 3)
6087 {
6088 if(0 == ps_dec->u4_share_disp_buf)
6089 {
6090 pic_wd = ps_dec->u2_disp_width;
6091 pic_ht = ps_dec->u2_disp_height;
6092 }
6093 else
6094 {
6095 pic_wd = ps_dec->u2_frm_wd_y;
6096 pic_ht = ps_dec->u2_frm_ht_y;
6097 }
6098 }
6099
6100 for(i = 0; i < ps_ctl_op->u4_min_num_in_bufs; i++)
6101 {
6102 ps_ctl_op->u4_min_in_buf_size[i] = MAX(256000, pic_wd * pic_ht * 3 / 2);
6103 }
6104 if((WORD32) ps_dec->u4_app_disp_width > pic_wd) pic_wd = ps_dec->u4_app_disp_width;
6105
6106 if(0 == ps_dec->u4_share_disp_buf)
6107 ps_ctl_op->u4_num_disp_bufs = 1;
6108 else
6109 {
6110 if((NULL != ps_dec->ps_cur_sps) && (1 == (ps_dec->ps_cur_sps->u1_is_valid)))
6111 {
6112 if((ps_dec->ps_cur_sps->u1_vui_parameters_present_flag == 1) &&
6113 (1 == ps_dec->ps_cur_sps->s_vui.u1_bitstream_restriction_flag))
6114 {
6115 ps_ctl_op->u4_num_disp_bufs = ps_dec->ps_cur_sps->s_vui.u4_num_reorder_frames + 1;
6116 }
6117 else
6118 {
6119 /*if VUI is not present assume maximum possible refrence frames for the
6120 * level, as max reorder frames*/
6121 ps_ctl_op->u4_num_disp_bufs = ih264d_get_dpb_size(ps_dec->ps_cur_sps);
6122 }
6123
6124 ps_ctl_op->u4_num_disp_bufs += ps_dec->ps_cur_sps->u1_num_ref_frames + 1;
6125 }
6126 else
6127 {
6128 ps_ctl_op->u4_num_disp_bufs = 32;
6129 }
6130
6131 ps_ctl_op->u4_num_disp_bufs = MAX(ps_ctl_op->u4_num_disp_bufs, 6);
6132 ps_ctl_op->u4_num_disp_bufs = MIN(ps_ctl_op->u4_num_disp_bufs, 32);
6133 }
6134
6135 ps_ctl_op->u4_min_num_out_bufs =
6136 ih264d_get_outbuf_size(pic_wd, pic_ht, ps_dec->u1_chroma_format, &au4_min_out_buf_size[0]);
6137
6138 for(i = 0; i < ps_ctl_op->u4_min_num_out_bufs; i++)
6139 {
6140 ps_ctl_op->u4_min_out_buf_size[i] = au4_min_out_buf_size[i];
6141 }
6142
6143 ps_dec->u4_num_disp_bufs_requested = ps_ctl_op->u4_num_disp_bufs;
6144
6145 return IV_SUCCESS;
6146 }
6147
6148 /*****************************************************************************/
6149 /* */
6150 /* Function Name : isvcd_set_params */
6151 /* */
6152 /* Description : */
6153 /* */
6154 /* Inputs :iv_obj_t decoder handle */
6155 /* :pv_api_ip pointer to input structure */
6156 /* :pv_api_op pointer to output structure */
6157 /* Outputs : */
6158 /* Returns : void */
6159 /* */
6160 /* Issues : none */
6161 /* */
6162 /* Revision History: */
6163 /* */
6164 /* DD MM YYYY Author(s) Changes (Describe the changes made) */
6165 /* 06 09 2021 Kishore Draft */
6166 /* */
6167 /*****************************************************************************/
isvcd_set_params(iv_obj_t * dec_hdl,void * pv_api_ip,void * pv_api_op)6168 WORD32 isvcd_set_params(iv_obj_t *dec_hdl, void *pv_api_ip, void *pv_api_op)
6169 {
6170 dec_struct_t *ps_dec;
6171 svc_dec_lyr_struct_t *ps_svc_lyr_dec;
6172 WORD32 ret = IV_SUCCESS;
6173 svc_dec_ctxt_t *ps_svcd_ctxt;
6174 WORD32 u1_layer_id;
6175
6176 ps_svcd_ctxt = (svc_dec_ctxt_t *) dec_hdl->pv_codec_handle;
6177 ps_svcd_ctxt->i4_eos_flag = 0;
6178 for(u1_layer_id = 0; u1_layer_id < MAX_NUM_RES_LYRS; u1_layer_id++)
6179 {
6180 isvcd_ctl_set_config_ip_t *ps_h264d_ctl_ip = (isvcd_ctl_set_config_ip_t *) pv_api_ip;
6181 isvcd_ctl_set_config_op_t *ps_h264d_ctl_op = (isvcd_ctl_set_config_op_t *) pv_api_op;
6182 ivd_ctl_set_config_ip_t *ps_ctl_ip = &ps_h264d_ctl_ip->s_ivd_ctl_set_config_ip_t;
6183 ivd_ctl_set_config_op_t *ps_ctl_op = &ps_h264d_ctl_op->s_ivd_ctl_set_config_op_t;
6184
6185 ps_svc_lyr_dec = &ps_svcd_ctxt->ps_svc_dec_lyr[u1_layer_id];
6186 ps_dec = &ps_svc_lyr_dec->s_dec;
6187
6188 ps_dec->u1_flushfrm = 0;
6189 ps_dec->u4_skip_frm_mask = 0;
6190 ps_ctl_op->u4_error_code = 0;
6191
6192 if(ps_ctl_ip->e_frm_skip_mode != IVD_SKIP_NONE)
6193 {
6194 ps_ctl_op->u4_error_code = (1 << IVD_UNSUPPORTEDPARAM);
6195 ret = IV_FAIL;
6196 }
6197
6198 if(ps_ctl_ip->u4_disp_wd >= ps_dec->u2_disp_width)
6199 {
6200 ps_dec->u4_app_disp_width = ps_ctl_ip->u4_disp_wd;
6201 }
6202 else if(0 == ps_dec->i4_header_decoded)
6203 {
6204 ps_dec->u4_app_disp_width = ps_ctl_ip->u4_disp_wd;
6205 }
6206 else if(ps_ctl_ip->u4_disp_wd == 0)
6207 {
6208 ps_dec->u4_app_disp_width = 0;
6209 }
6210 else
6211 {
6212 /*
6213 * Set the display width to zero. This will ensure that the wrong value we
6214 * had stored (0xFFFFFFFF) does not propogate.
6215 */
6216 ps_dec->u4_app_disp_width = 0;
6217 ps_ctl_op->u4_error_code |= (1 << IVD_UNSUPPORTEDPARAM);
6218 ps_ctl_op->u4_error_code |= ERROR_DISP_WIDTH_INVALID;
6219 ret = IV_FAIL;
6220 }
6221
6222 if(ps_ctl_ip->e_vid_dec_mode == IVD_DECODE_FRAME)
6223 ps_dec->i4_decode_header = 0;
6224 else if(ps_ctl_ip->e_vid_dec_mode == IVD_DECODE_HEADER)
6225 ps_dec->i4_decode_header = 1;
6226 else
6227 {
6228 ps_ctl_op->u4_error_code = (1 << IVD_UNSUPPORTEDPARAM);
6229 ps_dec->i4_decode_header = 1;
6230 ret = IV_FAIL;
6231 }
6232 ps_dec->e_frm_out_mode = IVD_DISPLAY_FRAME_OUT;
6233
6234 if((ps_ctl_ip->e_frm_out_mode != IVD_DECODE_FRAME_OUT) &&
6235 (ps_ctl_ip->e_frm_out_mode != IVD_DISPLAY_FRAME_OUT))
6236 {
6237 ps_ctl_op->u4_error_code = (1 << IVD_UNSUPPORTEDPARAM);
6238 ret = IV_FAIL;
6239 }
6240 ps_dec->e_frm_out_mode = ps_ctl_ip->e_frm_out_mode;
6241 }
6242 return ret;
6243 }
6244
6245 /*****************************************************************************/
6246 /* */
6247 /* Function Name : isvcd_set_target_layer */
6248 /* */
6249 /* Description : */
6250 /* */
6251 /* Inputs :iv_obj_t decoder handle */
6252 /* :pv_api_ip pointer to input structure */
6253 /* :pv_api_op pointer to output structure */
6254 /* Outputs : */
6255 /* Returns : void */
6256 /* */
6257 /* Issues : none */
6258 /* */
6259 /* Revision History: */
6260 /* */
6261 /* DD MM YYYY Author(s) Changes (Describe the changes made) */
6262 /* 05 04 2021 Kishore Draft */
6263 /* */
6264 /*****************************************************************************/
isvcd_set_target_layer(iv_obj_t * dec_hdl,void * pv_api_ip,void * pv_api_op)6265 WORD32 isvcd_set_target_layer(iv_obj_t *dec_hdl, void *pv_api_ip, void *pv_api_op)
6266 {
6267 WORD32 ret = IV_SUCCESS;
6268
6269 isvcd_set_target_layer_ip_t *ps_ip;
6270 isvcd_set_target_layer_op_t *ps_op;
6271 svc_dec_ctxt_t *ps_svcd_ctxt;
6272 ps_svcd_ctxt = (svc_dec_ctxt_t *) dec_hdl->pv_codec_handle;
6273
6274 ps_ip = (isvcd_set_target_layer_ip_t *) pv_api_ip;
6275 ps_op = (isvcd_set_target_layer_op_t *) pv_api_op;
6276
6277 ps_svcd_ctxt->u1_tgt_dep_id = ps_ip->u1_tgt_dep_id;
6278 ps_svcd_ctxt->u1_tgt_quality_id = ps_ip->u1_tgt_quality_id;
6279 ps_svcd_ctxt->u1_tgt_temp_id = ps_ip->u1_tgt_temp_id;
6280 ps_svcd_ctxt->u1_tgt_priority_id = ps_ip->u1_tgt_priority_id;
6281
6282 ret = isvcd_nal_parse_set_target_attr(ps_ip->u1_tgt_quality_id, ps_ip->u1_tgt_dep_id,
6283 ps_ip->u1_tgt_temp_id, ps_ip->u1_tgt_priority_id,
6284 ps_svcd_ctxt->pv_nal_parse_ctxt);
6285 ps_op->u4_error_code = 0;
6286
6287 return ret;
6288 }
6289
6290 /*****************************************************************************/
6291 /* */
6292 /* Function Name : isvcd_set_default_params */
6293 /* */
6294 /* Description : */
6295 /* */
6296 /* Inputs :iv_obj_t decoder handle */
6297 /* :pv_api_ip pointer to input structure */
6298 /* :pv_api_op pointer to output structure */
6299 /* Outputs : */
6300 /* Returns : void */
6301 /* */
6302 /* Issues : none */
6303 /* */
6304 /* Revision History: */
6305 /* */
6306 /* DD MM YYYY Author(s) Changes (Describe the changes made) */
6307 /* 06 09 2021 Kishore Copied from set_params */
6308 /* */
6309 /*****************************************************************************/
isvcd_set_default_params(iv_obj_t * dec_hdl,void * pv_api_ip,void * pv_api_op)6310 WORD32 isvcd_set_default_params(iv_obj_t *dec_hdl, void *pv_api_ip, void *pv_api_op)
6311 {
6312 dec_struct_t *ps_dec;
6313 svc_dec_lyr_struct_t *ps_svc_lyr_dec;
6314 WORD32 ret = IV_SUCCESS;
6315 UWORD8 u1_layer_id;
6316 svc_dec_ctxt_t *ps_svcd_ctxt;
6317 ivd_ctl_set_config_op_t *ps_ctl_op = (ivd_ctl_set_config_op_t *) pv_api_op;
6318
6319 ps_svcd_ctxt = (svc_dec_ctxt_t *) dec_hdl->pv_codec_handle;
6320 UNUSED(pv_api_ip);
6321
6322 for(u1_layer_id = 0; u1_layer_id < MAX_NUM_RES_LYRS; u1_layer_id++)
6323 {
6324 ps_svc_lyr_dec = &ps_svcd_ctxt->ps_svc_dec_lyr[u1_layer_id];
6325 ps_dec = &ps_svc_lyr_dec->s_dec;
6326
6327 ps_dec->u4_app_disp_width = 0;
6328 ps_dec->u4_skip_frm_mask = 0;
6329 ps_dec->i4_decode_header = 1;
6330 }
6331 ps_ctl_op->u4_error_code = 0;
6332
6333 return ret;
6334 }
6335 /*****************************************************************************/
6336 /* */
6337 /* Function Name : isvcd_delete */
6338 /* */
6339 /* Description : */
6340 /* */
6341 /* Inputs :iv_obj_t decoder handle */
6342 /* :pv_api_ip pointer to input structure */
6343 /* :pv_api_op pointer to output structure */
6344 /* Globals : <Does it use any global variables?> */
6345 /* Outputs : */
6346 /* Returns : void */
6347 /* */
6348 /* Issues : none */
6349 /* */
6350 /* Revision History: */
6351 /* */
6352 /* DD MM YYYY Author(s) Changes (Describe the changes made) */
6353 /* 06 09 2021 Kishore Draft */
6354 /* */
6355 /*****************************************************************************/
isvcd_delete(iv_obj_t * dec_hdl,void * pv_api_ip,void * pv_api_op)6356 WORD32 isvcd_delete(iv_obj_t *dec_hdl, void *pv_api_ip, void *pv_api_op)
6357 {
6358 svc_dec_lyr_struct_t *ps_svc_lyr_dec;
6359 isvcd_delete_ip_t *ps_ip = (isvcd_delete_ip_t *) pv_api_ip;
6360 isvcd_delete_op_t *ps_op = (isvcd_delete_op_t *) pv_api_op;
6361
6362 UWORD8 u1_layer_id;
6363 svc_dec_ctxt_t *ps_svcd_ctxt;
6364 ps_svcd_ctxt = (svc_dec_ctxt_t *) dec_hdl->pv_codec_handle;
6365 UNUSED(ps_ip);
6366
6367 for(u1_layer_id = 0; u1_layer_id < MAX_NUM_RES_LYRS; u1_layer_id++)
6368 {
6369 ps_svc_lyr_dec = &ps_svcd_ctxt->ps_svc_dec_lyr[u1_layer_id];
6370 isvcd_free_dynamic_bufs(ps_svc_lyr_dec);
6371 }
6372 isvcd_free_static_bufs(dec_hdl);
6373 ps_op->s_ivd_delete_op_t.u4_error_code = 0;
6374
6375 return IV_SUCCESS;
6376 }
6377 /*****************************************************************************/
6378 /* */
6379 /* Function Name : isvcd_reset */
6380 /* */
6381 /* Description : */
6382 /* */
6383 /* Inputs :iv_obj_t decoder handle */
6384 /* :pv_api_ip pointer to input structure */
6385 /* :pv_api_op pointer to output structure */
6386 /* Globals : <Does it use any global variables?> */
6387 /* Outputs : */
6388 /* Returns : void */
6389 /* */
6390 /* Issues : none */
6391 /* */
6392 /* Revision History: */
6393 /* */
6394 /* DD MM YYYY Author(s) Changes (Describe the changes made) */
6395 /* 06 09 2021 Kishore Draft */
6396 /* */
6397 /*****************************************************************************/
isvcd_reset(iv_obj_t * dec_hdl,void * pv_api_ip,void * pv_api_op)6398 WORD32 isvcd_reset(iv_obj_t *dec_hdl, void *pv_api_ip, void *pv_api_op)
6399 {
6400 dec_struct_t *ps_dec;
6401 svc_dec_lyr_struct_t *ps_svc_lyr_dec;
6402 ivd_ctl_reset_op_t *ps_ctl_op = (ivd_ctl_reset_op_t *) pv_api_op;
6403 UWORD8 u1_layer_id;
6404 svc_dec_ctxt_t *ps_svcd_ctxt;
6405 ps_svcd_ctxt = (svc_dec_ctxt_t *) dec_hdl->pv_codec_handle;
6406 UNUSED(pv_api_ip);
6407 ps_ctl_op->u4_error_code = 0;
6408
6409 ps_svcd_ctxt->i4_eos_flag = 0;
6410 ps_svcd_ctxt->u4_num_sps_ctr = 0;
6411 ps_svcd_ctxt->u4_num_pps_ctr = 0;
6412 ps_svcd_ctxt->u1_pre_parse_in_flush = 1;
6413 for(u1_layer_id = 0; u1_layer_id < MAX_NUM_RES_LYRS; u1_layer_id++)
6414 {
6415 ps_svc_lyr_dec = &ps_svcd_ctxt->ps_svc_dec_lyr[u1_layer_id];
6416 ps_dec = &ps_svc_lyr_dec->s_dec;
6417 if(ps_dec != NULL)
6418 {
6419 if(((buf_mgr_t *) ps_dec->pv_pic_buf_mgr)->pv_mutex != NULL)
6420 ih264_buf_mgr_free(ps_dec->pv_pic_buf_mgr);
6421 if(((buf_mgr_t *) ps_dec->pv_mv_buf_mgr)->pv_mutex != NULL)
6422 ih264_buf_mgr_free(ps_dec->pv_mv_buf_mgr);
6423
6424 isvcd_init_decoder(ps_svc_lyr_dec);
6425 ps_dec->u1_flushfrm = 0;
6426 }
6427 else
6428 {
6429 H264_DEC_DEBUG_PRINT("\nReset called without Initializing the decoder\n");
6430 ps_ctl_op->u4_error_code = ERROR_INIT_NOT_DONE;
6431 }
6432 }
6433 return IV_SUCCESS;
6434 }
6435
6436 /*****************************************************************************/
6437 /* */
6438 /* Function Name : isvcd_ctl */
6439 /* */
6440 /* Description : */
6441 /* */
6442 /* Inputs :iv_obj_t decoder handle */
6443 /* :pv_api_ip pointer to input structure */
6444 /* :pv_api_op pointer to output structure */
6445 /* Outputs : */
6446 /* Returns : void */
6447 /* */
6448 /* Issues : none */
6449 /* */
6450 /* Revision History: */
6451 /* */
6452 /* DD MM YYYY Author(s) Changes (Describe the changes made) */
6453 /* 06 09 2021 Kishore Draft */
6454 /* */
6455 /*****************************************************************************/
isvcd_ctl(iv_obj_t * dec_hdl,void * pv_api_ip,void * pv_api_op)6456 WORD32 isvcd_ctl(iv_obj_t *dec_hdl, void *pv_api_ip, void *pv_api_op)
6457 {
6458 ivd_ctl_set_config_ip_t *ps_ctl_ip;
6459 ivd_ctl_set_config_op_t *ps_ctl_op;
6460 WORD32 ret = IV_SUCCESS;
6461 UWORD32 subcommand;
6462 dec_struct_t *ps_dec;
6463 svc_dec_lyr_struct_t *ps_svc_lyr_dec;
6464 svc_dec_ctxt_t *ps_svcd_ctxt;
6465 ps_svcd_ctxt = (svc_dec_ctxt_t *) dec_hdl->pv_codec_handle;
6466 ps_svc_lyr_dec = &ps_svcd_ctxt->ps_svc_dec_lyr[ps_svcd_ctxt->u1_target_layer_id];
6467 ps_dec = &ps_svc_lyr_dec->s_dec;
6468 if(ps_dec->init_done != 1)
6469 {
6470 return IV_FAIL;
6471 }
6472 ps_ctl_ip = (ivd_ctl_set_config_ip_t *) pv_api_ip;
6473 ps_ctl_op = (ivd_ctl_set_config_op_t *) pv_api_op;
6474 ps_ctl_op->u4_error_code = 0;
6475 subcommand = ps_ctl_ip->e_sub_cmd;
6476
6477 switch(subcommand)
6478 {
6479 case IVD_CMD_CTL_GETPARAMS:
6480 ret = isvcd_get_status(dec_hdl, (void *) pv_api_ip, (void *) pv_api_op);
6481 break;
6482 case IVD_CMD_CTL_SETPARAMS:
6483 ret = isvcd_set_params(dec_hdl, (void *) pv_api_ip, (void *) pv_api_op);
6484 break;
6485 case IVD_CMD_CTL_RESET:
6486 ret = isvcd_reset(dec_hdl, (void *) pv_api_ip, (void *) pv_api_op);
6487 break;
6488 case IVD_CMD_CTL_SETDEFAULT:
6489 ret = isvcd_set_default_params(dec_hdl, (void *) pv_api_ip, (void *) pv_api_op);
6490 break;
6491 case IVD_CMD_CTL_FLUSH:
6492 ret = isvcd_set_flush_mode(dec_hdl, (void *) pv_api_ip, (void *) pv_api_op);
6493 break;
6494 case IVD_CMD_CTL_GETBUFINFO:
6495 ret = isvcd_get_buf_info(dec_hdl, (void *) pv_api_ip, (void *) pv_api_op);
6496 break;
6497 case IVD_CMD_CTL_GETVERSION:
6498 ret = ih264d_get_version(dec_hdl, (void *) pv_api_ip, (void *) pv_api_op);
6499 break;
6500 case IH264D_CMD_CTL_DEGRADE:
6501 ret = isvcd_set_degrade(dec_hdl, (void *) pv_api_ip, (void *) pv_api_op);
6502 break;
6503
6504 case IH264D_CMD_CTL_SET_NUM_CORES:
6505 ret = isvcd_set_num_cores(dec_hdl, (void *) pv_api_ip, (void *) pv_api_op);
6506 break;
6507 case IH264D_CMD_CTL_GET_BUFFER_DIMENSIONS:
6508 ret = isvcd_get_frame_dimensions(dec_hdl, (void *) pv_api_ip, (void *) pv_api_op);
6509 break;
6510 case IH264D_CMD_CTL_GET_VUI_PARAMS:
6511 ret = isvcd_get_vui_params(dec_hdl, (void *) pv_api_ip, (void *) pv_api_op);
6512 break;
6513 case IH264D_CMD_CTL_GET_SEI_MDCV_PARAMS:
6514 ret = isvcd_get_sei_mdcv_params(dec_hdl, (void *) pv_api_ip, (void *) pv_api_op);
6515 break;
6516 case IH264D_CMD_CTL_GET_SEI_CLL_PARAMS:
6517 ret = isvcd_get_sei_cll_params(dec_hdl, (void *) pv_api_ip, (void *) pv_api_op);
6518 break;
6519 case IH264D_CMD_CTL_GET_SEI_AVE_PARAMS:
6520 ret = isvcd_get_sei_ave_params(dec_hdl, (void *) pv_api_ip, (void *) pv_api_op);
6521 break;
6522 case IH264D_CMD_CTL_GET_SEI_CCV_PARAMS:
6523 ret = isvcd_get_sei_ccv_params(dec_hdl, (void *) pv_api_ip, (void *) pv_api_op);
6524 break;
6525 case IH264D_CMD_CTL_SET_PROCESSOR:
6526 ret = isvcd_set_processor(dec_hdl, (void *) pv_api_ip, (void *) pv_api_op);
6527 break;
6528 case ISVCD_CMD_CTL_SET_TGT_LAYER:
6529 ret = isvcd_set_target_layer(dec_hdl, (void *) pv_api_ip, (void *) pv_api_op);
6530 break;
6531 default:
6532 H264_DEC_DEBUG_PRINT("\ndo nothing\n");
6533 break;
6534 }
6535
6536 return ret;
6537 }
6538 /*****************************************************************************/
6539 /* */
6540 /* Function Name : isvcd_rel_display_frame */
6541 /* */
6542 /* Description : */
6543 /* */
6544 /* Inputs :iv_obj_t decoder handle */
6545 /* :pv_api_ip pointer to input structure */
6546 /* :pv_api_op pointer to output structure */
6547 /* Outputs : */
6548 /* Returns : void */
6549 /* */
6550 /* Issues : none */
6551 /* */
6552 /* Revision History: */
6553 /* */
6554 /* DD MM YYYY Author(s) Changes (Describe the changes made) */
6555 /* 06 09 2021 Kishore Draft */
6556 /* */
6557 /*****************************************************************************/
isvcd_rel_display_frame(iv_obj_t * dec_hdl,void * pv_api_ip,void * pv_api_op)6558 WORD32 isvcd_rel_display_frame(iv_obj_t *dec_hdl, void *pv_api_ip, void *pv_api_op)
6559 {
6560 ivd_rel_display_frame_ip_t *ps_rel_ip;
6561 ivd_rel_display_frame_op_t *ps_rel_op;
6562 UWORD32 buf_released = 0;
6563
6564 UWORD32 u4_ts = 0;
6565 dec_struct_t *ps_dec;
6566 svc_dec_lyr_struct_t *ps_svc_lyr_dec;
6567 UWORD8 u1_layer_id;
6568 svc_dec_ctxt_t *ps_svcd_ctxt;
6569 ps_svcd_ctxt = (svc_dec_ctxt_t *) dec_hdl->pv_codec_handle;
6570
6571 ps_rel_ip = (ivd_rel_display_frame_ip_t *) pv_api_ip;
6572 ps_rel_op = (ivd_rel_display_frame_op_t *) pv_api_op;
6573 ps_rel_op->u4_error_code = 0;
6574 u4_ts = ps_rel_ip->u4_disp_buf_id;
6575
6576 for(u1_layer_id = 0; u1_layer_id < MAX_NUM_RES_LYRS; u1_layer_id++)
6577 {
6578 ps_svc_lyr_dec = &ps_svcd_ctxt->ps_svc_dec_lyr[u1_layer_id];
6579 ps_dec = &ps_svc_lyr_dec->s_dec;
6580 if(0 == ps_dec->u4_share_disp_buf)
6581 {
6582 ps_dec->u4_disp_buf_mapping[u4_ts] = 0;
6583 ps_dec->u4_disp_buf_to_be_freed[u4_ts] = 0;
6584 return IV_SUCCESS;
6585 }
6586
6587 if(ps_dec->pv_pic_buf_mgr != NULL)
6588 {
6589 if(1 == ps_dec->u4_disp_buf_mapping[u4_ts])
6590 {
6591 ih264_buf_mgr_release((buf_mgr_t *) ps_dec->pv_pic_buf_mgr,
6592 ps_rel_ip->u4_disp_buf_id, BUF_MGR_IO);
6593 ps_dec->u4_disp_buf_mapping[u4_ts] = 0;
6594 buf_released = 1;
6595 }
6596 }
6597
6598 if((1 == ps_dec->u4_share_disp_buf) && (0 == buf_released))
6599 ps_dec->u4_disp_buf_to_be_freed[u4_ts] = 1;
6600 }
6601 return IV_SUCCESS;
6602 }
6603
6604 /**
6605 *******************************************************************************
6606 *
6607 * @brief
6608 * Sets degrade params
6609 *
6610 * @par Description:
6611 * Sets degrade params.
6612 * Refer to ih264d_ctl_degrade_ip_t definition for details
6613 *
6614 * @param[in] ps_codec_obj
6615 * Pointer to codec object at API level
6616 *
6617 * @param[in] pv_api_ip
6618 * Pointer to input argument structure
6619 *
6620 * @param[out] pv_api_op
6621 * Pointer to output argument structure
6622 *
6623 * @returns Status
6624 *
6625 * @remarks
6626 *
6627 *
6628 *******************************************************************************
6629 */
6630
isvcd_set_degrade(iv_obj_t * ps_codec_obj,void * pv_api_ip,void * pv_api_op)6631 WORD32 isvcd_set_degrade(iv_obj_t *ps_codec_obj, void *pv_api_ip, void *pv_api_op)
6632 {
6633 isvcd_ctl_degrade_ip_t *ps_ip;
6634 isvcd_ctl_degrade_op_t *ps_op;
6635 dec_struct_t *ps_codec;
6636 svc_dec_lyr_struct_t *ps_svc_lyr_dec;
6637 UWORD8 u1_layer_id;
6638 svc_dec_ctxt_t *ps_svcd_ctxt;
6639 ps_svcd_ctxt = (svc_dec_ctxt_t *) ps_codec_obj->pv_codec_handle;
6640
6641 ps_ip = (isvcd_ctl_degrade_ip_t *) pv_api_ip;
6642 ps_op = (isvcd_ctl_degrade_op_t *) pv_api_op;
6643
6644 for(u1_layer_id = 0; u1_layer_id < MAX_NUM_RES_LYRS; u1_layer_id++)
6645 {
6646 ps_svc_lyr_dec = &ps_svcd_ctxt->ps_svc_dec_lyr[u1_layer_id];
6647 ps_codec = &ps_svc_lyr_dec->s_dec;
6648 ps_codec->i4_degrade_type = ps_ip->i4_degrade_type;
6649 ps_codec->i4_nondegrade_interval = ps_ip->i4_nondegrade_interval;
6650 ps_codec->i4_degrade_pics = ps_ip->i4_degrade_pics;
6651
6652 ps_codec->i4_degrade_pic_cnt = 0;
6653 }
6654 ps_op->u4_error_code = 0;
6655
6656 return IV_SUCCESS;
6657 }
6658
6659 /*****************************************************************************/
6660 /* */
6661 /* Function Name : isvcd_get_frame_dimensions */
6662 /* */
6663 /* Description : gets the frame wd and ht and the buffer sizes */
6664 /* */
6665 /* Inputs :iv_obj_t decoder handle */
6666 /* :pv_api_ip pointer to input structure */
6667 /* :pv_api_op pointer to output structure */
6668 /* Outputs : */
6669 /* Returns : void */
6670 /* */
6671 /* Issues : none */
6672 /* */
6673 /* Revision History: */
6674 /* */
6675 /* DD MM YYYY Author(s) Changes (Describe the changes made) */
6676 /* 06 09 2021 Kishore Draft */
6677 /* */
6678 /*****************************************************************************/
isvcd_get_frame_dimensions(iv_obj_t * dec_hdl,void * pv_api_ip,void * pv_api_op)6679 WORD32 isvcd_get_frame_dimensions(iv_obj_t *dec_hdl, void *pv_api_ip, void *pv_api_op)
6680 {
6681 isvcd_ctl_get_frame_dimensions_ip_t *ps_ip;
6682 isvcd_ctl_get_frame_dimensions_op_t *ps_op;
6683 dec_struct_t *ps_dec;
6684 svc_dec_lyr_struct_t *ps_svc_lyr_dec;
6685 UWORD32 disp_wd, disp_ht, buffer_wd, buffer_ht, x_offset, y_offset;
6686 svc_dec_ctxt_t *ps_svcd_ctxt;
6687 ps_svcd_ctxt = (svc_dec_ctxt_t *) dec_hdl->pv_codec_handle;
6688
6689 ps_svc_lyr_dec = &ps_svcd_ctxt->ps_svc_dec_lyr[ps_svcd_ctxt->u1_target_layer_id];
6690 ps_dec = &ps_svc_lyr_dec->s_dec;
6691
6692 ps_ip = (isvcd_ctl_get_frame_dimensions_ip_t *) pv_api_ip;
6693 ps_op = (isvcd_ctl_get_frame_dimensions_op_t *) pv_api_op;
6694 UNUSED(ps_ip);
6695 if((NULL != ps_dec->ps_cur_sps) && (1 == (ps_dec->ps_cur_sps->u1_is_valid)))
6696 {
6697 disp_wd = ps_dec->u2_disp_width;
6698 disp_ht = ps_dec->u2_disp_height;
6699
6700 if(0 == ps_dec->u4_share_disp_buf)
6701 {
6702 buffer_wd = disp_wd;
6703 buffer_ht = disp_ht;
6704 }
6705 else
6706 {
6707 buffer_wd = ps_dec->u2_frm_wd_y;
6708 buffer_ht = ps_dec->u2_frm_ht_y;
6709 }
6710 }
6711 else
6712 {
6713 disp_wd = 0;
6714 disp_ht = 0;
6715
6716 if(0 == ps_dec->u4_share_disp_buf)
6717 {
6718 buffer_wd = disp_wd;
6719 buffer_ht = disp_ht;
6720 }
6721 else
6722 {
6723 buffer_wd = ALIGN16(disp_wd) + (PAD_LEN_Y_H << 1);
6724 buffer_ht = ALIGN16(disp_ht) + (PAD_LEN_Y_V << 2);
6725 }
6726 }
6727 if(ps_dec->u4_app_disp_width > buffer_wd) buffer_wd = ps_dec->u4_app_disp_width;
6728
6729 if(0 == ps_dec->u4_share_disp_buf)
6730 {
6731 x_offset = 0;
6732 y_offset = 0;
6733 }
6734 else
6735 {
6736 y_offset = (PAD_LEN_Y_V << 1);
6737 x_offset = PAD_LEN_Y_H;
6738
6739 if((NULL != ps_dec->ps_sps) && (1 == (ps_dec->ps_sps->u1_is_valid)) &&
6740 (0 != ps_dec->u2_crop_offset_y))
6741 {
6742 y_offset += ps_dec->u2_crop_offset_y / ps_dec->u2_frm_wd_y;
6743 x_offset += ps_dec->u2_crop_offset_y % ps_dec->u2_frm_wd_y;
6744 }
6745 }
6746
6747 ps_op->u4_disp_wd[0] = disp_wd;
6748 ps_op->u4_disp_ht[0] = disp_ht;
6749 ps_op->u4_buffer_wd[0] = buffer_wd;
6750 ps_op->u4_buffer_ht[0] = buffer_ht;
6751 ps_op->u4_x_offset[0] = x_offset;
6752 ps_op->u4_y_offset[0] = y_offset;
6753
6754 ps_op->u4_disp_wd[1] = ps_op->u4_disp_wd[2] = ((ps_op->u4_disp_wd[0] + 1) >> 1);
6755 ps_op->u4_disp_ht[1] = ps_op->u4_disp_ht[2] = ((ps_op->u4_disp_ht[0] + 1) >> 1);
6756 ps_op->u4_buffer_wd[1] = ps_op->u4_buffer_wd[2] = (ps_op->u4_buffer_wd[0] >> 1);
6757 ps_op->u4_buffer_ht[1] = ps_op->u4_buffer_ht[2] = (ps_op->u4_buffer_ht[0] >> 1);
6758 ps_op->u4_x_offset[1] = ps_op->u4_x_offset[2] = (ps_op->u4_x_offset[0] >> 1);
6759 ps_op->u4_y_offset[1] = ps_op->u4_y_offset[2] = (ps_op->u4_y_offset[0] >> 1);
6760
6761 if((ps_dec->u1_chroma_format == IV_YUV_420SP_UV) ||
6762 (ps_dec->u1_chroma_format == IV_YUV_420SP_VU))
6763 {
6764 ps_op->u4_disp_wd[2] = 0;
6765 ps_op->u4_disp_ht[2] = 0;
6766 ps_op->u4_buffer_wd[2] = 0;
6767 ps_op->u4_buffer_ht[2] = 0;
6768 ps_op->u4_x_offset[2] = 0;
6769 ps_op->u4_y_offset[2] = 0;
6770
6771 ps_op->u4_disp_wd[1] <<= 1;
6772 ps_op->u4_buffer_wd[1] <<= 1;
6773 ps_op->u4_x_offset[1] <<= 1;
6774 }
6775
6776 return IV_SUCCESS;
6777 }
6778 /*****************************************************************************/
6779 /* */
6780 /* Function Name : isvcd_get_vui_params */
6781 /* */
6782 /* Description : gets the VUI params */
6783 /* */
6784 /* Inputs :iv_obj_t decoder handle */
6785 /* :pv_api_ip pointer to input structure */
6786 /* :pv_api_op pointer to output structure */
6787 /* Outputs : */
6788 /* Returns : success or failure */
6789 /* */
6790 /* Issues : none */
6791 /* */
6792 /* Revision History: */
6793 /* */
6794 /* DD MM YYYY Author(s) Changes (Describe the changes made) */
6795 /* 06 09 2021 Kishore Draft */
6796 /* */
6797 /*****************************************************************************/
6798
isvcd_get_vui_params(iv_obj_t * dec_hdl,void * pv_api_ip,void * pv_api_op)6799 WORD32 isvcd_get_vui_params(iv_obj_t *dec_hdl, void *pv_api_ip, void *pv_api_op)
6800 {
6801 isvcd_ctl_get_vui_params_ip_t *ps_ip;
6802 isvcd_ctl_get_vui_params_op_t *ps_op;
6803 dec_struct_t *ps_dec;
6804 svc_dec_lyr_struct_t *ps_svc_lyr_dec;
6805 dec_seq_params_t *ps_sps;
6806 vui_t *ps_vui;
6807 UWORD32 u4_size;
6808 svc_dec_ctxt_t *ps_svcd_ctxt;
6809 ps_svcd_ctxt = (svc_dec_ctxt_t *) dec_hdl->pv_codec_handle;
6810
6811 ps_ip = (isvcd_ctl_get_vui_params_ip_t *) pv_api_ip;
6812 ps_op = (isvcd_ctl_get_vui_params_op_t *) pv_api_op;
6813 UNUSED(ps_ip);
6814
6815 u4_size = ps_op->u4_size;
6816 memset(ps_op, 0, sizeof(isvcd_ctl_get_vui_params_op_t));
6817 ps_op->u4_size = u4_size;
6818
6819 ps_svc_lyr_dec = &ps_svcd_ctxt->ps_svc_dec_lyr[ps_svcd_ctxt->u1_target_layer_id];
6820 ps_dec = &ps_svc_lyr_dec->s_dec;
6821 if(NULL == ps_dec->ps_cur_sps)
6822 {
6823 ps_op->u4_error_code = ERROR_VUI_PARAMS_NOT_FOUND;
6824 return IV_FAIL;
6825 }
6826 ps_sps = ps_dec->ps_cur_sps;
6827
6828 if((0 == ps_sps->u1_is_valid) || (0 == ps_sps->u1_vui_parameters_present_flag))
6829 {
6830 ps_op->u4_error_code = ERROR_VUI_PARAMS_NOT_FOUND;
6831 return IV_FAIL;
6832 }
6833
6834 ps_vui = &ps_sps->s_vui;
6835
6836 ps_op->u1_aspect_ratio_idc = ps_vui->u1_aspect_ratio_idc;
6837 ps_op->u2_sar_width = ps_vui->u2_sar_width;
6838 ps_op->u2_sar_height = ps_vui->u2_sar_height;
6839 ps_op->u1_overscan_appropriate_flag = ps_vui->u1_overscan_appropriate_flag;
6840 ps_op->u1_video_format = ps_vui->u1_video_format;
6841 ps_op->u1_video_full_range_flag = ps_vui->u1_video_full_range_flag;
6842 ps_op->u1_colour_primaries = ps_vui->u1_colour_primaries;
6843 ps_op->u1_tfr_chars = ps_vui->u1_tfr_chars;
6844 ps_op->u1_matrix_coeffs = ps_vui->u1_matrix_coeffs;
6845 ps_op->u1_cr_top_field = ps_vui->u1_cr_top_field;
6846 ps_op->u1_cr_bottom_field = ps_vui->u1_cr_bottom_field;
6847 ps_op->u4_num_units_in_tick = ps_vui->u4_num_units_in_tick;
6848 ps_op->u4_time_scale = ps_vui->u4_time_scale;
6849 ps_op->u1_fixed_frame_rate_flag = ps_vui->u1_fixed_frame_rate_flag;
6850 ps_op->u1_nal_hrd_params_present = ps_vui->u1_nal_hrd_params_present;
6851 ps_op->u1_vcl_hrd_params_present = ps_vui->u1_vcl_hrd_params_present;
6852 ps_op->u1_low_delay_hrd_flag = ps_vui->u1_low_delay_hrd_flag;
6853 ps_op->u1_pic_struct_present_flag = ps_vui->u1_pic_struct_present_flag;
6854 ps_op->u1_bitstream_restriction_flag = ps_vui->u1_bitstream_restriction_flag;
6855 ps_op->u1_mv_over_pic_boundaries_flag = ps_vui->u1_mv_over_pic_boundaries_flag;
6856 ps_op->u4_max_bytes_per_pic_denom = ps_vui->u4_max_bytes_per_pic_denom;
6857 ps_op->u4_max_bits_per_mb_denom = ps_vui->u4_max_bits_per_mb_denom;
6858 ps_op->u4_log2_max_mv_length_horz = ps_vui->u4_log2_max_mv_length_horz;
6859 ps_op->u4_log2_max_mv_length_vert = ps_vui->u4_log2_max_mv_length_vert;
6860 ps_op->u4_num_reorder_frames = ps_vui->u4_num_reorder_frames;
6861 ps_op->u4_max_dec_frame_buffering = ps_vui->u4_max_dec_frame_buffering;
6862
6863 return IV_SUCCESS;
6864 }
6865 /*****************************************************************************/
6866 /* */
6867 /* Function Name : isvcd_get_sei_mdcv_params */
6868 /* */
6869 /* Description : This function populates SEI mdcv message in */
6870 /* output structure */
6871 /* Inputs : iv_obj_t decoder handle */
6872 /* : pv_api_ip pointer to input structure */
6873 /* : pv_api_op pointer to output structure */
6874 /* Outputs : */
6875 /* Returns : returns 0; 1 with error code when MDCV is not present */
6876 /* */
6877 /* Issues : none */
6878 /* */
6879 /* Revision History: */
6880 /* */
6881 /* DD MM YYYY Author(s) Changes (Describe the changes made) */
6882 /* */
6883 /* */
6884 /*****************************************************************************/
isvcd_get_sei_mdcv_params(iv_obj_t * dec_hdl,void * pv_api_ip,void * pv_api_op)6885 WORD32 isvcd_get_sei_mdcv_params(iv_obj_t *dec_hdl, void *pv_api_ip, void *pv_api_op)
6886 {
6887 isvcd_ctl_get_sei_mdcv_params_ip_t *ps_ip;
6888 isvcd_ctl_get_sei_mdcv_params_op_t *ps_op;
6889 dec_struct_t *ps_dec;
6890 svc_dec_lyr_struct_t *ps_svc_lyr_dec;
6891 sei_mdcv_params_t *ps_sei_mdcv;
6892 WORD32 i4_count;
6893 svc_dec_ctxt_t *ps_svcd_ctxt;
6894 ps_svcd_ctxt = (svc_dec_ctxt_t *) dec_hdl->pv_codec_handle;
6895
6896 ps_ip = (isvcd_ctl_get_sei_mdcv_params_ip_t *) pv_api_ip;
6897 ps_op = (isvcd_ctl_get_sei_mdcv_params_op_t *) pv_api_op;
6898 UNUSED(ps_ip);
6899
6900 ps_svc_lyr_dec = &ps_svcd_ctxt->ps_svc_dec_lyr[ps_svcd_ctxt->u1_target_layer_id];
6901 ps_dec = &ps_svc_lyr_dec->s_dec;
6902 if(0 == ps_dec->s_sei_export.u1_sei_mdcv_params_present_flag)
6903 {
6904 ps_op->u4_error_code = ERROR_SEI_MDCV_PARAMS_NOT_FOUND;
6905 return IV_FAIL;
6906 }
6907 ps_sei_mdcv = &ps_dec->s_sei_export.s_sei_mdcv_params;
6908
6909 for(i4_count = 0; i4_count < NUM_SEI_MDCV_PRIMARIES; i4_count++)
6910 {
6911 ps_op->au2_display_primaries_x[i4_count] = ps_sei_mdcv->au2_display_primaries_x[i4_count];
6912 ps_op->au2_display_primaries_y[i4_count] = ps_sei_mdcv->au2_display_primaries_y[i4_count];
6913 }
6914
6915 ps_op->u2_white_point_x = ps_sei_mdcv->u2_white_point_x;
6916 ps_op->u2_white_point_y = ps_sei_mdcv->u2_white_point_y;
6917 ps_op->u4_max_display_mastering_luminance = ps_sei_mdcv->u4_max_display_mastering_luminance;
6918 ps_op->u4_min_display_mastering_luminance = ps_sei_mdcv->u4_min_display_mastering_luminance;
6919
6920 return IV_SUCCESS;
6921 }
6922
6923 /*****************************************************************************/
6924 /* */
6925 /* Function Name : isvcd_get_sei_cll_params */
6926 /* */
6927 /* Description : This function populates SEI cll message in */
6928 /* output structure */
6929 /* Inputs : iv_obj_t decoder handle */
6930 /* : pv_api_ip pointer to input structure */
6931 /* : pv_api_op pointer to output structure */
6932 /* Outputs : */
6933 /* Returns : returns 0; 1 with error code when CLL is not present */
6934 /* */
6935 /* Issues : none */
6936 /* */
6937 /* Revision History: */
6938 /* */
6939 /* DD MM YYYY Author(s) Changes (Describe the changes made) */
6940 /* */
6941 /* */
6942 /*****************************************************************************/
isvcd_get_sei_cll_params(iv_obj_t * dec_hdl,void * pv_api_ip,void * pv_api_op)6943 WORD32 isvcd_get_sei_cll_params(iv_obj_t *dec_hdl, void *pv_api_ip, void *pv_api_op)
6944 {
6945 isvcd_ctl_get_sei_cll_params_ip_t *ps_ip;
6946 isvcd_ctl_get_sei_cll_params_op_t *ps_op;
6947 dec_struct_t *ps_dec;
6948 svc_dec_lyr_struct_t *ps_svc_lyr_dec;
6949 svc_dec_ctxt_t *ps_svcd_ctxt;
6950 sei_cll_params_t *ps_sei_cll;
6951 ps_svcd_ctxt = (svc_dec_ctxt_t *) dec_hdl->pv_codec_handle;
6952
6953 ps_ip = (isvcd_ctl_get_sei_cll_params_ip_t *) pv_api_ip;
6954 ps_op = (isvcd_ctl_get_sei_cll_params_op_t *) pv_api_op;
6955 UNUSED(ps_ip);
6956
6957 ps_svc_lyr_dec = &ps_svcd_ctxt->ps_svc_dec_lyr[ps_svcd_ctxt->u1_target_layer_id];
6958 ps_dec = &ps_svc_lyr_dec->s_dec;
6959 if(0 == ps_dec->s_sei_export.u1_sei_cll_params_present_flag)
6960 {
6961 ps_op->u4_error_code = ERROR_SEI_CLL_PARAMS_NOT_FOUND;
6962 return IV_FAIL;
6963 }
6964 ps_sei_cll = &ps_dec->s_sei_export.s_sei_cll_params;
6965
6966 ps_op->u2_max_content_light_level = ps_sei_cll->u2_max_content_light_level;
6967 ps_op->u2_max_pic_average_light_level = ps_sei_cll->u2_max_pic_average_light_level;
6968
6969 return IV_SUCCESS;
6970 }
6971
6972 /*****************************************************************************/
6973 /* */
6974 /* Function Name : isvcd_get_sei_ave_params */
6975 /* */
6976 /* Description : This function populates SEI ave message in */
6977 /* output structure */
6978 /* Inputs : iv_obj_t decoder handle */
6979 /* : pv_api_ip pointer to input structure */
6980 /* : pv_api_op pointer to output structure */
6981 /* Outputs : */
6982 /* Returns : returns 0; 1 with error code when AVE is not present */
6983 /* */
6984 /* Issues : none */
6985 /* */
6986 /* Revision History: */
6987 /* */
6988 /* DD MM YYYY Author(s) Changes (Describe the changes made) */
6989 /* */
6990 /* */
6991 /*****************************************************************************/
isvcd_get_sei_ave_params(iv_obj_t * dec_hdl,void * pv_api_ip,void * pv_api_op)6992 WORD32 isvcd_get_sei_ave_params(iv_obj_t *dec_hdl, void *pv_api_ip, void *pv_api_op)
6993 {
6994 isvcd_ctl_get_sei_ave_params_ip_t *ps_ip;
6995 isvcd_ctl_get_sei_ave_params_op_t *ps_op;
6996 dec_struct_t *ps_dec;
6997 svc_dec_lyr_struct_t *ps_svc_lyr_dec;
6998 sei_ave_params_t *ps_sei_ave;
6999 svc_dec_ctxt_t *ps_svcd_ctxt;
7000 ps_svcd_ctxt = (svc_dec_ctxt_t *) dec_hdl->pv_codec_handle;
7001
7002 ps_ip = (isvcd_ctl_get_sei_ave_params_ip_t *) pv_api_ip;
7003 ps_op = (isvcd_ctl_get_sei_ave_params_op_t *) pv_api_op;
7004 UNUSED(ps_ip);
7005
7006 ps_svc_lyr_dec = &ps_svcd_ctxt->ps_svc_dec_lyr[ps_svcd_ctxt->u1_target_layer_id];
7007 ps_dec = &ps_svc_lyr_dec->s_dec;
7008 if(0 == ps_dec->s_sei_export.u1_sei_ave_params_present_flag)
7009 {
7010 ps_op->u4_error_code = ERROR_SEI_AVE_PARAMS_NOT_FOUND;
7011 return IV_FAIL;
7012 }
7013 ps_sei_ave = &ps_dec->s_sei_export.s_sei_ave_params;
7014
7015 ps_op->u4_ambient_illuminance = ps_sei_ave->u4_ambient_illuminance;
7016 ps_op->u2_ambient_light_x = ps_sei_ave->u2_ambient_light_x;
7017 ps_op->u2_ambient_light_y = ps_sei_ave->u2_ambient_light_y;
7018
7019 return IV_SUCCESS;
7020 }
7021
7022 /*****************************************************************************/
7023 /* */
7024 /* Function Name : isvcd_get_sei_ccv_params */
7025 /* */
7026 /* Description : This function populates SEI mdcv message in */
7027 /* output structure */
7028 /* Inputs : iv_obj_t decoder handle */
7029 /* : pv_api_ip pointer to input structure */
7030 /* : pv_api_op pointer to output structure */
7031 /* Outputs : */
7032 /* Returns : returns 0; 1 with error code when CCV is not present */
7033 /* */
7034 /* Issues : none */
7035 /* */
7036 /* Revision History: */
7037 /* */
7038 /* DD MM YYYY Author(s) Changes (Describe the changes made) */
7039 /* */
7040 /* */
7041 /*****************************************************************************/
isvcd_get_sei_ccv_params(iv_obj_t * dec_hdl,void * pv_api_ip,void * pv_api_op)7042 WORD32 isvcd_get_sei_ccv_params(iv_obj_t *dec_hdl, void *pv_api_ip, void *pv_api_op)
7043 {
7044 isvcd_ctl_get_sei_ccv_params_ip_t *ps_ip;
7045 isvcd_ctl_get_sei_ccv_params_op_t *ps_op;
7046 dec_struct_t *ps_dec;
7047 svc_dec_lyr_struct_t *ps_svc_lyr_dec;
7048 sei_ccv_params_t *ps_sei_ccv;
7049 svc_dec_ctxt_t *ps_svcd_ctxt;
7050 WORD32 i4_count;
7051 ps_svcd_ctxt = (svc_dec_ctxt_t *) dec_hdl->pv_codec_handle;
7052
7053 ps_ip = (isvcd_ctl_get_sei_ccv_params_ip_t *) pv_api_ip;
7054 ps_op = (isvcd_ctl_get_sei_ccv_params_op_t *) pv_api_op;
7055 UNUSED(ps_ip);
7056
7057 ps_svc_lyr_dec = &ps_svcd_ctxt->ps_svc_dec_lyr[ps_svcd_ctxt->u1_target_layer_id];
7058 ps_dec = &ps_svc_lyr_dec->s_dec;
7059 if(0 == ps_dec->s_sei_export.u1_sei_ccv_params_present_flag)
7060 {
7061 ps_op->u4_error_code = ERROR_SEI_CCV_PARAMS_NOT_FOUND;
7062 return IV_FAIL;
7063 }
7064 ps_sei_ccv = &ps_dec->s_sei_export.s_sei_ccv_params;
7065 ps_op->u1_ccv_cancel_flag = ps_sei_ccv->u1_ccv_cancel_flag;
7066
7067 if(0 == ps_op->u1_ccv_cancel_flag)
7068 {
7069 ps_op->u1_ccv_persistence_flag = ps_sei_ccv->u1_ccv_persistence_flag;
7070 ps_op->u1_ccv_primaries_present_flag = ps_sei_ccv->u1_ccv_primaries_present_flag;
7071 ps_op->u1_ccv_min_luminance_value_present_flag =
7072 ps_sei_ccv->u1_ccv_min_luminance_value_present_flag;
7073 ps_op->u1_ccv_max_luminance_value_present_flag =
7074 ps_sei_ccv->u1_ccv_max_luminance_value_present_flag;
7075 ps_op->u1_ccv_avg_luminance_value_present_flag =
7076 ps_sei_ccv->u1_ccv_avg_luminance_value_present_flag;
7077 ps_op->u1_ccv_reserved_zero_2bits = ps_sei_ccv->u1_ccv_reserved_zero_2bits;
7078
7079 if(1 == ps_sei_ccv->u1_ccv_primaries_present_flag)
7080 {
7081 for(i4_count = 0; i4_count < NUM_SEI_CCV_PRIMARIES; i4_count++)
7082 {
7083 ps_op->ai4_ccv_primaries_x[i4_count] = ps_sei_ccv->ai4_ccv_primaries_x[i4_count];
7084 ps_op->ai4_ccv_primaries_y[i4_count] = ps_sei_ccv->ai4_ccv_primaries_y[i4_count];
7085 }
7086 }
7087
7088 if(1 == ps_sei_ccv->u1_ccv_min_luminance_value_present_flag)
7089 {
7090 ps_op->u4_ccv_min_luminance_value = ps_sei_ccv->u4_ccv_min_luminance_value;
7091 }
7092 if(1 == ps_sei_ccv->u1_ccv_max_luminance_value_present_flag)
7093 {
7094 ps_op->u4_ccv_max_luminance_value = ps_sei_ccv->u4_ccv_max_luminance_value;
7095 }
7096 if(1 == ps_sei_ccv->u1_ccv_avg_luminance_value_present_flag)
7097 {
7098 ps_op->u4_ccv_avg_luminance_value = ps_sei_ccv->u4_ccv_avg_luminance_value;
7099 }
7100 }
7101
7102 return IV_SUCCESS;
7103 }
7104
7105 /*****************************************************************************/
7106 /* */
7107 /* Function Name : isvcd_set_num_cores */
7108 /* */
7109 /* Description : This function sets the no of cores which decoder */
7110 /* can use for decoding */
7111 /* Inputs : iv_obj_t decoder handle */
7112 /* : pv_api_ip pointer to input structure */
7113 /* : pv_api_op pointer to output structure */
7114 /* Outputs : */
7115 /* Returns : returns 0; 1 with error code */
7116 /* */
7117 /* Issues : none */
7118 /* */
7119 /* Revision History: */
7120 /* */
7121 /* DD MM YYYY Author(s) Changes (Describe the changes made) */
7122 /* */
7123 /* */
7124 /*****************************************************************************/
isvcd_set_num_cores(iv_obj_t * dec_hdl,void * pv_api_ip,void * pv_api_op)7125 WORD32 isvcd_set_num_cores(iv_obj_t *dec_hdl, void *pv_api_ip, void *pv_api_op)
7126 {
7127 UWORD8 u1_layer_id;
7128 isvcd_ctl_set_num_cores_ip_t *ps_ip;
7129 isvcd_ctl_set_num_cores_op_t *ps_op;
7130 dec_struct_t *ps_dec;
7131 svc_dec_lyr_struct_t *ps_svc_lyr_dec;
7132 svc_dec_ctxt_t *ps_svcd_ctxt;
7133 ps_svcd_ctxt = (svc_dec_ctxt_t *) dec_hdl->pv_codec_handle;
7134
7135 ps_ip = (isvcd_ctl_set_num_cores_ip_t *) pv_api_ip;
7136 ps_op = (isvcd_ctl_set_num_cores_op_t *) pv_api_op;
7137 ps_op->u4_error_code = 0;
7138 for(u1_layer_id = 0; u1_layer_id < MAX_NUM_RES_LYRS; u1_layer_id++)
7139 {
7140 ps_svc_lyr_dec = &ps_svcd_ctxt->ps_svc_dec_lyr[u1_layer_id];
7141 ps_dec = &ps_svc_lyr_dec->s_dec;
7142 ps_dec->u4_num_cores = ps_ip->u4_num_cores;
7143
7144 if(ps_dec->u4_num_cores == 1)
7145 {
7146 ps_dec->u1_separate_parse = 0;
7147 }
7148 else
7149 {
7150 ps_dec->u1_separate_parse = 1;
7151 }
7152
7153 /*using only upto three threads currently*/
7154 if(ps_dec->u4_num_cores > 3) ps_dec->u4_num_cores = 3;
7155 }
7156 return IV_SUCCESS;
7157 }
7158
7159 /*****************************************************************************/
7160 /* */
7161 /* Function Name : isvcd_fill_output_struct_from_context */
7162 /* */
7163 /* Description : This function fills the output structure from the */
7164 /* svc layer context */
7165 /* Inputs : iv_obj_t decoder handle */
7166 /* : ps_svc_lyr_dec pointer to svc layer context */
7167 /* : ps_dec_op pointer to output structure */
7168 /* Outputs : */
7169 /* Returns : */
7170 /* */
7171 /* Issues : none */
7172 /* */
7173 /* Revision History: */
7174 /* */
7175 /* DD MM YYYY Author(s) Changes (Describe the changes made) */
7176 /* */
7177 /* */
7178 /*****************************************************************************/
isvcd_fill_output_struct_from_context(svc_dec_lyr_struct_t * ps_svc_lyr_dec,ivd_video_decode_op_t * ps_dec_op)7179 void isvcd_fill_output_struct_from_context(svc_dec_lyr_struct_t *ps_svc_lyr_dec,
7180 ivd_video_decode_op_t *ps_dec_op)
7181 {
7182 dec_struct_t *ps_dec;
7183 ps_dec = &ps_svc_lyr_dec->s_dec;
7184 if((ps_dec_op->u4_error_code & 0xff) != ERROR_DYNAMIC_RESOLUTION_NOT_SUPPORTED)
7185 {
7186 ps_dec_op->u4_pic_wd = (UWORD32) ps_dec->u2_disp_width;
7187 ps_dec_op->u4_pic_ht = (UWORD32) ps_dec->u2_disp_height;
7188 }
7189 ps_dec_op->i4_reorder_depth = ps_dec->i4_reorder_depth;
7190 ps_dec_op->i4_display_index = ps_dec->i4_display_index;
7191 ps_dec_op->e_pic_type = ps_dec->i4_frametype;
7192
7193 ps_dec_op->u4_new_seq = 0;
7194 ps_dec_op->u4_output_present =
7195 (ps_svc_lyr_dec->u1_layer_identifier == TARGET_LAYER) ? ps_dec->u4_output_present : 0;
7196 ps_dec_op->u4_progressive_frame_flag = ps_dec->s_disp_op.u4_progressive_frame_flag;
7197
7198 ps_dec_op->u4_is_ref_flag = 1;
7199 if(ps_dec_op->u4_frame_decoded_flag)
7200 {
7201 if(ps_dec->ps_cur_slice->u1_nal_ref_idc == 0) ps_dec_op->u4_is_ref_flag = 0;
7202 }
7203
7204 ps_dec_op->e_output_format = ps_dec->s_disp_op.e_output_format;
7205 ps_dec_op->s_disp_frm_buf = ps_dec->s_disp_op.s_disp_frm_buf;
7206 ps_dec_op->e4_fld_type = ps_dec->s_disp_op.e4_fld_type;
7207 ps_dec_op->u4_ts = ps_dec->s_disp_op.u4_ts;
7208 ps_dec_op->u4_disp_buf_id = ps_dec->s_disp_op.u4_disp_buf_id;
7209
7210 ih264d_export_sei_params(&ps_dec_op->s_sei_decode_op, ps_dec);
7211 }
7212
7213 /*****************************************************************************/
7214 /* */
7215 /* Function Name : isvcd_api_function */
7216 /* */
7217 /* Description : */
7218 /* */
7219 /* Inputs :iv_obj_t decoder handle */
7220 /* :pv_api_ip pointer to input structure */
7221 /* :pv_api_op pointer to output structure */
7222 /* Outputs : */
7223 /* Returns : void */
7224 /* */
7225 /* Issues : none */
7226 /* */
7227 /* Revision History: */
7228 /* */
7229 /* DD MM YYYY Author(s) Changes (Describe the changes made) */
7230 /* 06 09 2021 Kishore Draft */
7231 /* */
7232 /*****************************************************************************/
isvcd_api_function(iv_obj_t * dec_hdl,void * pv_api_ip,void * pv_api_op)7233 IV_API_CALL_STATUS_T isvcd_api_function(iv_obj_t *dec_hdl, void *pv_api_ip, void *pv_api_op)
7234 {
7235 UWORD32 command;
7236 UWORD32 *pu2_ptr_cmd;
7237 UWORD32 u4_api_ret;
7238 IV_API_CALL_STATUS_T e_status;
7239 e_status = api_check_struct_sanity(dec_hdl, pv_api_ip, pv_api_op);
7240
7241 if(e_status != IV_SUCCESS)
7242 {
7243 UWORD32 *ptr_err;
7244
7245 ptr_err = (UWORD32 *) pv_api_op;
7246 UNUSED(ptr_err);
7247 H264_DEC_DEBUG_PRINT("error code = %d\n", *(ptr_err + 1));
7248 return IV_FAIL;
7249 }
7250
7251 pu2_ptr_cmd = (UWORD32 *) pv_api_ip;
7252 pu2_ptr_cmd++;
7253
7254 command = *pu2_ptr_cmd;
7255 switch(command)
7256 {
7257 case IVD_CMD_CREATE:
7258 u4_api_ret = isvcd_create(dec_hdl, (void *) pv_api_ip, (void *) pv_api_op);
7259 break;
7260 case IVD_CMD_DELETE:
7261 u4_api_ret = isvcd_delete(dec_hdl, (void *) pv_api_ip, (void *) pv_api_op);
7262 break;
7263
7264 case IVD_CMD_VIDEO_DECODE:
7265 u4_api_ret = isvcd_video_decode(dec_hdl, (void *) pv_api_ip, (void *) pv_api_op);
7266 break;
7267
7268 case IVD_CMD_GET_DISPLAY_FRAME:
7269 u4_api_ret = ih264d_get_display_frame(dec_hdl, (void *) pv_api_ip, (void *) pv_api_op);
7270
7271 break;
7272
7273 case IVD_CMD_SET_DISPLAY_FRAME:
7274 u4_api_ret = isvcd_set_display_frame(dec_hdl, (void *) pv_api_ip, (void *) pv_api_op);
7275
7276 break;
7277
7278 case IVD_CMD_REL_DISPLAY_FRAME:
7279 u4_api_ret = isvcd_rel_display_frame(dec_hdl, (void *) pv_api_ip, (void *) pv_api_op);
7280 break;
7281
7282 case IVD_CMD_VIDEO_CTL:
7283 u4_api_ret = isvcd_ctl(dec_hdl, (void *) pv_api_ip, (void *) pv_api_op);
7284 break;
7285 default:
7286 u4_api_ret = IV_FAIL;
7287 break;
7288 }
7289
7290 return u4_api_ret;
7291 }
7292