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 = u1_layer_id - 1;
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 if(ps_svcd_ctxt->pic_width < ps_svc_lyr_dec->pic_width)
4440 {
4441 ps_svcd_ctxt->pic_width = ps_svc_lyr_dec->pic_width;
4442 }
4443 if(ps_svcd_ctxt->pic_height < ps_svc_lyr_dec->pic_height)
4444 {
4445 ps_svcd_ctxt->pic_height = ps_svc_lyr_dec->pic_height;
4446 }
4447 }
4448
4449 if(i_status) return i_status;
4450
4451 break;
4452 case SUBSET_SPS_NAL:
4453
4454 i_status = isvcd_parse_subset_sps(ps_svc_lyr_dec, ps_bitstrm);
4455
4456 if(!i_status)
4457 {
4458 ps_svcd_ctxt->u4_num_sps_ctr++;
4459 ps_dec->i4_header_decoded |= 0x1;
4460
4461 if(ps_svcd_ctxt->pic_width < ps_svc_lyr_dec->pic_width)
4462 {
4463 ps_svcd_ctxt->pic_width = ps_svc_lyr_dec->pic_width;
4464 }
4465 if(ps_svcd_ctxt->pic_height < ps_svc_lyr_dec->pic_height)
4466 {
4467 ps_svcd_ctxt->pic_height = ps_svc_lyr_dec->pic_height;
4468 }
4469 }
4470 if(i_status) return i_status;
4471
4472 break;
4473
4474 case PIC_PARAM_NAL:
4475
4476 i_status = isvcd_parse_pps(ps_svc_lyr_dec, ps_bitstrm);
4477 if(i_status == ERROR_INV_SPS_PPS_T) return i_status;
4478 if(!i_status)
4479 {
4480 ps_dec->i4_header_decoded |= 0x2;
4481 ps_svcd_ctxt->u4_num_pps_ctr++;
4482 }
4483 break;
4484 case SEI_NAL:
4485 {
4486 i_status = ih264d_parse_sei_message(ps_dec, ps_bitstrm);
4487 ih264d_parse_sei(ps_dec, ps_bitstrm);
4488 }
4489 break;
4490 default:
4491 /* no other NON VCL UNIT is supported */
4492 break;
4493 }
4494
4495 /* get the next non vcl bufffer */
4496 ps_non_vcl_buf = ps_non_vcl_buf->ps_next;
4497
4498 } /* end of loop over all NAL units */
4499
4500 return (OK);
4501 }
4502 /*****************************************************************************/
4503 /* */
4504 /* Function Name : isvcd_seq_hdr_dec */
4505 /* */
4506 /* Description : This function decodes sequence header, which includes */
4507 /* non VCL NAL before the first VCL unit */
4508 /* Inputs : Decoder context, inbufs, place holder for number of bytes*/
4509 /* consumed and number of packets consumed */
4510 /* Globals : None */
4511 /* Processing : 1. Parse non VCL units before first VCL unit */
4512 /* 2. Decode parsed non VCL units */
4513 /* Outputs : Decoded header */
4514 /* Returns : OK or NOT_OK */
4515 /* */
4516 /* Issues : no known issues */
4517 /* */
4518 /* Revision History: */
4519 /* */
4520 /* DD MM YYYY Author(s) Changes (Describe the changes made) */
4521 /* 06 09 2021 Kishore Creation */
4522 /* */
4523 /*****************************************************************************/
isvcd_seq_hdr_dec(svc_dec_ctxt_t * ps_svcd_ctxt,ivd_video_decode_ip_t * ps_in_bufs,UWORD32 * pu4_bytes_consumed)4524 WORD32 isvcd_seq_hdr_dec(svc_dec_ctxt_t *ps_svcd_ctxt, ivd_video_decode_ip_t *ps_in_bufs,
4525 UWORD32 *pu4_bytes_consumed)
4526 {
4527 WORD32 i4_status;
4528
4529 /* Decode all non VCL NAL till first VCL NAL is encountered */
4530 ps_svcd_ctxt->s_non_vcl_nal.i4_num_non_vcl_nals = 0;
4531 i4_status = isvcd_nal_parse_non_vcl_nal(
4532 ps_svcd_ctxt->pv_nal_parse_ctxt, ps_in_bufs->pv_stream_buffer, &ps_svcd_ctxt->s_non_vcl_nal,
4533 pu4_bytes_consumed, &ps_in_bufs->u4_num_Bytes);
4534
4535 /* Note: The bitstream extraction module expects updated */
4536 /* pointer whenever a new call to this module has been */
4537 /* made. Hence the buffer pointer has to be incremented */
4538 /* by bytes consumed */
4539 ps_in_bufs->u4_num_Bytes -= *pu4_bytes_consumed;
4540
4541 /* ------------------------------------------------------ */
4542 /* Decoding of non VCL data. As current implementation it */
4543 /* decodes the followings: */
4544 /* 1. Sequence parameter set */
4545 /* 2. Picture parameter set */
4546 /* 3. SEI message */
4547 /* ------------------------------------------------------ */
4548 isvcd_dec_non_vcl(&ps_svcd_ctxt->s_non_vcl_nal, ps_svcd_ctxt->ps_sps, ps_svcd_ctxt->ps_pps,
4549 ps_svcd_ctxt);
4550
4551 return (i4_status);
4552 }
4553
4554 /*****************************************************************************/
4555 /* */
4556 /* Function Name : isvcd_pre_parse_refine_au */
4557 /* */
4558 /* Description : This function process a decode call */
4559 /* Inputs : ps_dec_ctxt : decoder context structure */
4560 /* ps_in_bufs : input buffer descriptor */
4561 /* pu4_bytes_consumed : pointer to store the bytes consumed */
4562 /* pi4_packets_consumed : pointer to store the packets */
4563 /* consumed */
4564 /* Globals : None */
4565 /* Processing : It calls the NAL parse module to parse the input stream */
4566 /* if a picture boundary is detected it calls the */
4567 /* Dependency list refiniment and Picture Decode routines */
4568 /* Outputs : Decoded picture */
4569 /* Returns : OK or NOT_OK */
4570 /* */
4571 /* Issues : None */
4572 /* */
4573 /* Revision History: */
4574 /* */
4575 /* DD MM YYYY Author(s) Changes (Describe the changes made) */
4576 /* 06 09 2021 Kishore Creation */
4577 /* */
4578 /*****************************************************************************/
isvcd_pre_parse_refine_au(svc_dec_ctxt_t * ps_svcd_ctxt,ivd_video_decode_ip_t * ps_in_bufs,UWORD32 * pu4_bytes_consumed)4579 WORD32 isvcd_pre_parse_refine_au(svc_dec_ctxt_t *ps_svcd_ctxt, ivd_video_decode_ip_t *ps_in_bufs,
4580 UWORD32 *pu4_bytes_consumed)
4581 {
4582 WORD32 i4_status, i4_non_vcl_status;
4583 UWORD32 u4_bytes_consumed = 0;
4584 dec_struct_t *ps_dec;
4585 svc_dec_lyr_struct_t *ps_svc_lyr_dec;
4586 ps_svc_lyr_dec = ps_svcd_ctxt->ps_svc_dec_lyr;
4587 ps_dec = &ps_svc_lyr_dec->s_dec;
4588
4589 /* Sequence header decode: */
4590 /* If sequence header is not decoded then decode the seq */
4591 /* uence header */
4592
4593 if(SVCD_FALSE == ps_dec->i4_header_decoded)
4594 {
4595 i4_status = isvcd_seq_hdr_dec(ps_svcd_ctxt, ps_in_bufs, &u4_bytes_consumed);
4596
4597 if((VCL_NAL_FOUND_TRUE == i4_status) && (ps_svcd_ctxt->u4_num_sps_ctr != 0) &&
4598 (ps_svcd_ctxt->u4_num_pps_ctr != 0))
4599 {
4600 /* set the header decoded flag */
4601 ps_dec->i4_header_decoded = 3;
4602 }
4603 }
4604 *pu4_bytes_consumed = u4_bytes_consumed;
4605 if(1 == ps_dec->i4_decode_header)
4606 {
4607 return OK;
4608 }
4609 /* Bit-stream Parsing. It performs following tasks: */
4610 /* 1. NAL hader decoder */
4611 /* 2. Emulation prevention and byte swap */
4612 /* (During this process data to moved to output*/
4613 /* buffer) */
4614 /* 3. Dependency list creation based on NAL header*/
4615 /* 4. Detection of picture boundary */
4616 /* NOTE1: */
4617 /* Output buffers for VCL and non VCL data are */
4618 /* different. VCL data can be retrieved through */
4619 /* dependency list. Whereas non VCL data is stored in*/
4620 /* one single buffer, which is accessed through NON */
4621 /* VCL structure */
4622 /* NOTE2:Partial input case for nal parsing requires a */
4623 /* flush API to be called when end of bitstream */
4624 /* occurs */
4625
4626 if(SVCD_FALSE == ps_svcd_ctxt->i4_eos_flag)
4627 {
4628 if(ps_dec->i4_header_decoded == 3)
4629 {
4630 i4_status = isvcd_nal_parse_vcl_nal_partial(
4631 ps_svcd_ctxt->pv_nal_parse_ctxt, ps_in_bufs->pv_stream_buffer,
4632 &ps_svcd_ctxt->s_non_vcl_nal, &ps_svcd_ctxt->s_vcl_nal, &u4_bytes_consumed,
4633 &ps_in_bufs->u4_num_Bytes);
4634 }
4635 else
4636 {
4637 return NOT_OK;
4638 }
4639 }
4640 else
4641 {
4642 void *pv_nal_parse_ctxt;
4643 pv_nal_parse_ctxt = ps_svcd_ctxt->pv_nal_parse_ctxt;
4644
4645 i4_status = isvcd_nal_parse_partial_signal_eos(pv_nal_parse_ctxt, &ps_svcd_ctxt->s_vcl_nal,
4646 &ps_svcd_ctxt->s_non_vcl_nal);
4647
4648 u4_bytes_consumed = 0;
4649 }
4650
4651 *pu4_bytes_consumed += u4_bytes_consumed;
4652
4653 /* Picture Boundary detected: Go ahead and do the decoding */
4654 /* Picture boundary not detected: Otherwsie retrun from this*/
4655 /* function and update the bytes consumed variable. This */
4656 /* should be repeated till we get a picture boundary */
4657
4658 if(PIC_BOUNDARY_FALSE == i4_status)
4659 {
4660 return (NOT_OK);
4661 }
4662
4663 else if(FLUSH_DECODED_PICTURE == i4_status)
4664 {
4665 /* No more data is expected to come. Pictures decoded */
4666 /* so far needs to be sent for display */
4667 return (FLUSH);
4668 }
4669
4670 if(PIC_BOUNDARY_TRUE != i4_status)
4671 {
4672 return (NOT_OK);
4673 }
4674
4675 /* check if the application has set any of the skip modes */
4676 /* add the support for P and B skip modes */
4677 /* if(ps_dec_ctxt->s_dyn_prms.u1_frame_skip_mode) */
4678
4679 /* Parse slice header to decode reference layer dQId and refine */
4680 /* the dependency list */
4681 /* NOTE: Yes, this processing could be moved into NAL parsing */
4682 /* routine to avoid unneccessary emulation prevention and */
4683 /* byte swapping over discardable data. This Optimization */
4684 /* has been deferred for some time. In future if we found */
4685 /* that there are many such streams which doesn't set */
4686 /* 'discard_flag' correctly in NAL header, we will take a */
4687 /* hit to optimize it. */
4688
4689 /* At present this routine also performs the following */
4690 /* 1. Refine DQID list based on reference layer DQID */
4691 /* 2. Calculates the POC for the target layer */
4692
4693 {
4694 i4_status = isvcd_refine_dep_list(
4695 &ps_svcd_ctxt->s_vcl_nal, ps_svcd_ctxt->ps_sps, ps_svcd_ctxt->ps_subset_sps,
4696 ps_svcd_ctxt->ps_pps, &ps_svcd_ctxt->ai4_dq_id_map[0], &ps_svcd_ctxt->as_au_prms_dep[0],
4697 &ps_svcd_ctxt->as_pps_sps_prev_au[0], &ps_svcd_ctxt->i4_error_code, ps_svcd_ctxt);
4698 }
4699
4700 if(0 != ps_svcd_ctxt->s_non_vcl_nal.i4_num_non_vcl_nals)
4701 {
4702 /* Decoding of non VCL data. In current implementation it */
4703 /* decodes the followings: */
4704 /* 1. Sequence parameter set */
4705 /* 2. Picture parameter set */
4706 /* 3. SEI message */
4707 i4_non_vcl_status = isvcd_dec_non_vcl(&ps_svcd_ctxt->s_non_vcl_nal, ps_svcd_ctxt->ps_sps,
4708 ps_svcd_ctxt->ps_pps, ps_svcd_ctxt);
4709
4710 if(OK != i4_non_vcl_status) return i4_non_vcl_status;
4711 }
4712 if(OK != i4_status) return (i4_status);
4713 return (OK);
4714 }
4715
4716 /*****************************************************************************/
4717 /* */
4718 /* Function Name : isvcd_video_decode */
4719 /* */
4720 /* Description : handle video decode API command */
4721 /* */
4722 /* Inputs :iv_obj_t decoder handle */
4723 /* :pv_api_ip pointer to input structure */
4724 /* :pv_api_op pointer to output structure */
4725 /* Outputs : */
4726 /* Returns : void */
4727 /* */
4728 /* Issues : none */
4729 /* */
4730 /* Revision History: */
4731 /* */
4732 /* DD MM YYYY Author(s) Changes (Describe the changes made) */
4733 /* 06 09 2021 Kishore Draft */
4734 /* */
4735 /*****************************************************************************/
4736
isvcd_video_decode(iv_obj_t * dec_hdl,void * pv_api_ip,void * pv_api_op)4737 WORD32 isvcd_video_decode(iv_obj_t *dec_hdl, void *pv_api_ip, void *pv_api_op)
4738 {
4739 dec_struct_t *ps_dec;
4740 dec_struct_t *ps_dec_zero_lyr;
4741 svc_dec_lyr_struct_t *ps_svc_lyr_dec;
4742 svc_dec_lyr_struct_t *ps_svc_lyr_zero_dec;
4743
4744 svc_dec_ctxt_t *ps_svcd_ctxt;
4745 WORD32 i4_err_status = 0;
4746
4747 UWORD32 bytes_consumed = 0;
4748 WORD32 ret = 0, api_ret_value = IV_SUCCESS;
4749 isvcd_video_decode_ip_t *ps_h264d_dec_ip;
4750 isvcd_video_decode_op_t *ps_h264d_dec_op;
4751 ivd_video_decode_ip_t *ps_dec_ip;
4752 ivd_video_decode_op_t *ps_dec_op;
4753 UWORD8 u1_res_id;
4754
4755 ithread_set_name((void *) "Parse_thread");
4756
4757 ps_svcd_ctxt = (svc_dec_ctxt_t *) (dec_hdl->pv_codec_handle);
4758 ps_svc_lyr_dec = &ps_svcd_ctxt->ps_svc_dec_lyr[0];
4759 ps_dec = &ps_svc_lyr_dec->s_dec;
4760
4761 ps_h264d_dec_ip = (isvcd_video_decode_ip_t *) pv_api_ip;
4762 ps_h264d_dec_op = (isvcd_video_decode_op_t *) pv_api_op;
4763 ps_dec_ip = &ps_h264d_dec_ip->s_ivd_video_decode_ip_t;
4764 ps_dec_op = &ps_h264d_dec_op->s_ivd_video_decode_op_t;
4765
4766 {
4767 UWORD32 u4_size;
4768 u4_size = ps_dec_op->u4_size;
4769 memset(ps_h264d_dec_op, 0, sizeof(isvcd_video_decode_op_t));
4770 ps_dec_op->u4_size = u4_size;
4771 }
4772
4773 ps_dec->pv_dec_out = ps_dec_op;
4774 if(ps_dec->init_done != 1)
4775 {
4776 return IV_FAIL;
4777 }
4778
4779 /*Data memory barries instruction,so that bitstream write by the application
4780 * is complete*/
4781 DATA_SYNC();
4782
4783 if(0 == ps_dec->u1_flushfrm)
4784 {
4785 if(ps_dec_ip->pv_stream_buffer == NULL)
4786 {
4787 ps_dec_op->u4_error_code |= 1 << IVD_UNSUPPORTEDPARAM;
4788 ps_dec_op->u4_error_code |= IVD_DEC_FRM_BS_BUF_NULL;
4789 return IV_FAIL;
4790 }
4791 if(ps_dec_ip->u4_num_Bytes <= 16)
4792 {
4793 ps_dec_op->u4_error_code |= 1 << IVD_UNSUPPORTEDPARAM;
4794 ps_dec_op->u4_error_code |= IVD_DEC_NUMBYTES_INV;
4795 return IV_FAIL;
4796 }
4797 }
4798 #ifdef KEEP_THREADS_ACTIVE
4799 {
4800 UWORD32 i;
4801 ps_dec->i4_break_threads = 0;
4802 for(i = 0; i < 2; i++)
4803 {
4804 ret = ithread_mutex_lock(ps_dec->apv_proc_start_mutex[i]);
4805 RETURN_IF((ret != IV_SUCCESS), ret);
4806
4807 ps_dec->ai4_process_start[i] = PROC_INIT;
4808
4809 ret = ithread_mutex_unlock(ps_dec->apv_proc_start_mutex[i]);
4810 RETURN_IF((ret != IV_SUCCESS), ret);
4811 }
4812 }
4813 #else
4814 ps_dec->u4_dec_thread_created = 0;
4815 ps_dec->u4_bs_deblk_thread_created = 0;
4816 #endif
4817 ps_dec_op->u4_num_bytes_consumed = 0;
4818 ps_dec_op->i4_reorder_depth = -1;
4819 ps_dec_op->i4_display_index = DEFAULT_POC;
4820
4821 ps_dec->ps_out_buffer = NULL;
4822 if(ps_dec_ip->u4_size >= offsetof(ivd_video_decode_ip_t, s_out_buffer))
4823 ps_dec->ps_out_buffer = &ps_dec_ip->s_out_buffer;
4824
4825 if(0 == ps_dec->u4_share_disp_buf && ps_dec->i4_decode_header == 0)
4826 {
4827 UWORD32 i;
4828 if((ps_dec->ps_out_buffer->u4_num_bufs == 0) ||
4829 (ps_dec->ps_out_buffer->u4_num_bufs > IVD_VIDDEC_MAX_IO_BUFFERS))
4830 {
4831 ps_dec_op->u4_error_code |= 1 << IVD_UNSUPPORTEDPARAM;
4832 ps_dec_op->u4_error_code |= IVD_DISP_FRM_ZERO_OP_BUFS;
4833 return IV_FAIL;
4834 }
4835
4836 for(i = 0; i < ps_dec->ps_out_buffer->u4_num_bufs; i++)
4837 {
4838 if(ps_dec->ps_out_buffer->pu1_bufs[i] == NULL)
4839 {
4840 ps_dec_op->u4_error_code |= 1 << IVD_UNSUPPORTEDPARAM;
4841 ps_dec_op->u4_error_code |= IVD_DISP_FRM_OP_BUF_NULL;
4842 return IV_FAIL;
4843 }
4844
4845 if(ps_dec->ps_out_buffer->u4_min_out_buf_size[i] == 0)
4846 {
4847 ps_dec_op->u4_error_code |= 1 << IVD_UNSUPPORTEDPARAM;
4848 ps_dec_op->u4_error_code |= IVD_DISP_FRM_ZERO_OP_BUF_SIZE;
4849 return IV_FAIL;
4850 }
4851 }
4852 }
4853
4854 if(ps_dec->u4_total_frames_decoded >= NUM_FRAMES_LIMIT)
4855 {
4856 ps_dec_op->u4_error_code = ERROR_FRAME_LIMIT_OVER;
4857 return IV_FAIL;
4858 }
4859
4860 ps_dec_op->u4_error_code = 0;
4861 ps_dec_op->e_pic_type = IV_NA_FRAME;
4862 ps_dec_op->u4_output_present = 0;
4863 ps_dec_op->u4_frame_decoded_flag = 0;
4864
4865 /* In case the decoder is not in flush mode(in shared mode),
4866 then decoder has to pick up a buffer to write current frame.
4867 Check if a frame is available in such cases */
4868 if(ps_dec->u1_init_dec_flag == 1 && ps_dec->u4_share_disp_buf == 1 && ps_dec->u1_flushfrm == 0)
4869 {
4870 UWORD32 i;
4871 WORD32 disp_avail = 0, free_id;
4872
4873 /* Check if at least one buffer is available with the codec */
4874 /* If not then return to application with error */
4875 for(i = 0; i < ps_dec->u1_pic_bufs; i++)
4876 {
4877 if(0 == ps_dec->u4_disp_buf_mapping[i] || 1 == ps_dec->u4_disp_buf_to_be_freed[i])
4878 {
4879 disp_avail = 1;
4880 break;
4881 }
4882 }
4883
4884 if(0 == disp_avail)
4885 {
4886 /* If something is queued for display wait for that buffer to be returned
4887 */
4888
4889 ps_dec_op->u4_error_code = IVD_DEC_REF_BUF_NULL;
4890 ps_dec_op->u4_error_code |= (1 << IVD_UNSUPPORTEDPARAM);
4891 return (IV_FAIL);
4892 }
4893
4894 while(1)
4895 {
4896 pic_buffer_t *ps_pic_buf;
4897 ps_pic_buf = (pic_buffer_t *) ih264_buf_mgr_get_next_free(
4898 (buf_mgr_t *) ps_dec->pv_pic_buf_mgr, &free_id);
4899
4900 if(ps_pic_buf == NULL)
4901 {
4902 UWORD32 display_queued = 0;
4903
4904 /* check if any buffer was given for display which is not returned yet */
4905 for(i = 0; i < (MAX_DISP_BUFS_NEW); i++)
4906 {
4907 if(0 != ps_dec->u4_disp_buf_mapping[i])
4908 {
4909 display_queued = 1;
4910 break;
4911 }
4912 }
4913 /* If some buffer is queued for display, then codec has to singal an
4914 error and wait for that buffer to be returned. If nothing is queued for
4915 display then codec has ownership of all display buffers and it can
4916 reuse any of the existing buffers and continue decoding */
4917
4918 if(1 == display_queued)
4919 {
4920 /* If something is queued for display wait for that buffer to be
4921 * returned */
4922 ps_dec_op->u4_error_code = IVD_DEC_REF_BUF_NULL;
4923 ps_dec_op->u4_error_code |= (1 << IVD_UNSUPPORTEDPARAM);
4924 return (IV_FAIL);
4925 }
4926 }
4927 else
4928 {
4929 /* If the buffer is with display, then mark it as in use and then look
4930 * for a buffer again */
4931 if(1 == ps_dec->u4_disp_buf_mapping[free_id])
4932 {
4933 ih264_buf_mgr_set_status((buf_mgr_t *) ps_dec->pv_pic_buf_mgr, free_id,
4934 BUF_MGR_IO);
4935 }
4936 else
4937 {
4938 /**
4939 * Found a free buffer for present call. Release it now.
4940 * Will be again obtained later.
4941 */
4942 ih264_buf_mgr_release((buf_mgr_t *) ps_dec->pv_pic_buf_mgr, free_id,
4943 BUF_MGR_IO);
4944 break;
4945 }
4946 }
4947 }
4948 }
4949
4950 if(ps_dec->u1_enable_mb_info && (ps_dec->i4_header_decoded & DECODED_SPS_MASK))
4951 {
4952 UWORD32 blk_qp_map_size = ps_h264d_dec_ip->u4_8x8_blk_qp_map_size;
4953 UWORD32 blk_type_map_size = ps_h264d_dec_ip->u4_8x8_blk_type_map_size;
4954 UWORD32 blk_8x8_map_size = ps_dec->u4_total_mbs << 2;
4955 if((ps_h264d_dec_ip->pu1_8x8_blk_qp_map && blk_qp_map_size < blk_8x8_map_size) ||
4956 (ps_h264d_dec_ip->pu1_8x8_blk_type_map && blk_type_map_size < blk_8x8_map_size))
4957 {
4958 ps_dec_op->u4_error_code |= 1 << IVD_UNSUPPORTEDPARAM;
4959 ps_dec_op->u4_error_code |= IH264D_INSUFFICIENT_METADATA_BUFFER;
4960 return IV_FAIL;
4961 }
4962 }
4963
4964 if(ps_dec->u1_flushfrm && (1 == ps_svcd_ctxt->u1_pre_parse_in_flush))
4965 {
4966 if(ps_dec->u1_init_dec_flag == 0)
4967 {
4968 ps_dec->u1_flushfrm = 0;
4969 return (IV_FAIL);
4970 }
4971
4972 ps_svc_lyr_dec = &ps_svcd_ctxt->ps_svc_dec_lyr[ps_svcd_ctxt->s_vcl_nal.i4_num_res_lyrs - 1];
4973 ps_dec = &ps_svc_lyr_dec->s_dec;
4974 ps_dec->u4_fmt_conv_cur_row = 0;
4975 ps_dec->u4_output_present = 0;
4976 ps_dec->s_disp_op.u4_error_code = 1;
4977
4978 ps_dec->ps_out_buffer = NULL;
4979 if(ps_dec_ip->u4_size >= offsetof(ivd_video_decode_ip_t, s_out_buffer))
4980 {
4981 ps_dec->ps_out_buffer = &ps_dec_ip->s_out_buffer;
4982 }
4983 ih264d_get_next_display_field(ps_dec, ps_dec->ps_out_buffer, &(ps_dec->s_disp_op));
4984 if(0 == ps_dec->s_disp_op.u4_error_code)
4985 {
4986 /* check output buffer size given by the application */
4987 if(check_app_out_buf_size(ps_dec) != IV_SUCCESS)
4988 {
4989 ps_dec_op->u4_error_code = IVD_DISP_FRM_ZERO_OP_BUF_SIZE;
4990 return (IV_FAIL);
4991 }
4992
4993 ps_dec->u4_fmt_conv_cur_row = 0;
4994 ps_dec->u4_fmt_conv_num_rows = ps_dec->s_disp_frame_info.u4_y_ht;
4995 ih264d_format_convert(ps_dec, &(ps_dec->s_disp_op), ps_dec->u4_fmt_conv_cur_row,
4996 ps_dec->u4_fmt_conv_num_rows);
4997 ps_dec->u4_fmt_conv_cur_row += ps_dec->u4_fmt_conv_num_rows;
4998 ps_dec->u4_output_present = 1;
4999 if(ps_dec->u1_enable_mb_info)
5000 {
5001 UWORD32 disp_buf_id = ps_dec->s_disp_op.u4_disp_buf_id;
5002 if(ps_h264d_dec_ip->pu1_8x8_blk_qp_map)
5003 {
5004 ps_h264d_dec_op->pu1_8x8_blk_qp_map = ps_h264d_dec_ip->pu1_8x8_blk_qp_map;
5005 ps_h264d_dec_op->u4_8x8_blk_qp_map_size = ps_dec->u4_total_mbs << 2;
5006 ih264_memcpy(ps_h264d_dec_op->pu1_8x8_blk_qp_map,
5007 ps_dec->as_buf_id_info_map[disp_buf_id].pu1_qp_map,
5008 ps_dec->u4_total_mbs << 2);
5009 }
5010 if(ps_h264d_dec_ip->pu1_8x8_blk_type_map)
5011 {
5012 ps_h264d_dec_op->pu1_8x8_blk_type_map = ps_h264d_dec_ip->pu1_8x8_blk_type_map;
5013 ps_h264d_dec_op->u4_8x8_blk_type_map_size = ps_dec->u4_total_mbs << 2;
5014 ih264_memcpy(ps_h264d_dec_op->pu1_8x8_blk_type_map,
5015 ps_dec->as_buf_id_info_map[disp_buf_id].pu1_mb_type_map,
5016 ps_dec->u4_total_mbs << 2);
5017 }
5018 }
5019 }
5020 ih264d_export_sei_params(&ps_dec_op->s_sei_decode_op, ps_dec);
5021
5022 ih264d_release_display_field(ps_dec, &(ps_dec->s_disp_op));
5023
5024 ps_dec_op->u4_pic_wd = (UWORD32) ps_dec->u2_disp_width;
5025 ps_dec_op->u4_pic_ht = (UWORD32) ps_dec->u2_disp_height;
5026 ps_dec_op->i4_reorder_depth = ps_dec->i4_reorder_depth;
5027 ps_dec_op->i4_display_index = ps_dec->i4_display_index;
5028 ps_dec_op->u4_new_seq = 0;
5029
5030 ps_dec_op->u4_output_present = ps_dec->u4_output_present;
5031 ps_dec_op->u4_progressive_frame_flag = ps_dec->s_disp_op.u4_progressive_frame_flag;
5032 ps_dec_op->e_output_format = ps_dec->s_disp_op.e_output_format;
5033 ps_dec_op->s_disp_frm_buf = ps_dec->s_disp_op.s_disp_frm_buf;
5034 ps_dec_op->e4_fld_type = ps_dec->s_disp_op.e4_fld_type;
5035 ps_dec_op->u4_ts = ps_dec->s_disp_op.u4_ts;
5036 ps_dec_op->u4_disp_buf_id = ps_dec->s_disp_op.u4_disp_buf_id;
5037
5038 /*In the case of flush ,since no frame is decoded set pic type as invalid*/
5039 ps_dec_op->u4_is_ref_flag = UINT32_MAX;
5040 ps_dec_op->e_pic_type = IV_NA_FRAME;
5041 ps_dec_op->u4_frame_decoded_flag = 0;
5042
5043 if(0 == ps_dec->s_disp_op.u4_error_code)
5044 {
5045 return (IV_SUCCESS);
5046 }
5047 else
5048 return (IV_FAIL);
5049 }
5050
5051 if(ps_dec->u1_res_changed == 1)
5052 {
5053 /*if resolution has changed and all buffers have been flushed, reset
5054 * decoder*/
5055 if(((buf_mgr_t *) ps_dec->pv_pic_buf_mgr)->pv_mutex != NULL)
5056 ih264_buf_mgr_free(ps_dec->pv_pic_buf_mgr);
5057 if(((buf_mgr_t *) ps_dec->pv_mv_buf_mgr)->pv_mutex != NULL)
5058 ih264_buf_mgr_free(ps_dec->pv_mv_buf_mgr);
5059
5060 isvcd_init_decoder(ps_svc_lyr_dec);
5061 }
5062
5063 DEBUG_THREADS_PRINTF(" Starting process call\n");
5064
5065 {
5066 vcl_node_t *ps_cur_node;
5067 UWORD8 u1_num_res_lyrs;
5068 vcl_buf_hdr_t *ps_vcl_buf;
5069 UWORD8 flush_decode = 1;
5070 ps_svcd_ctxt->u1_pre_parse_in_flush = 0;
5071
5072 ret = isvcd_pre_parse_refine_au(ps_svcd_ctxt, ps_dec_ip, &ps_dec_op->u4_num_bytes_consumed);
5073 ps_svcd_ctxt->u1_pre_parse_in_flush = (ret == FLUSH);
5074
5075 if(ret != OK)
5076 {
5077 UWORD32 error = ih264d_map_error((UWORD32) ret);
5078 if(ret != NOT_OK)
5079 {
5080 ps_dec_op->u4_error_code = error | ret;
5081 }
5082 if((ps_dec_op->u4_error_code >> IVD_FATALERROR) & 1)
5083 {
5084 ps_svcd_ctxt->u1_exit_till_next_IDR = 1;
5085 }
5086 api_ret_value = IV_FAIL;
5087 if((ret == IVD_RES_CHANGED) || (ret == IVD_MEM_ALLOC_FAILED) ||
5088 (ret == ERROR_UNAVAIL_PICBUF_T) || (ret == ERROR_UNAVAIL_MVBUF_T) ||
5089 (ret == ERROR_INV_SPS_PPS_T) || (ret == ERROR_FEATURE_UNAVAIL) ||
5090 (ret == IVD_STREAM_WIDTH_HEIGHT_NOT_SUPPORTED) ||
5091 (ret == IVD_DISP_FRM_ZERO_OP_BUF_SIZE))
5092 {
5093 ps_dec->u4_slice_start_code_found = 0;
5094 }
5095 if((ret == ERROR_INCOMPLETE_FRAME) || (ret == ERROR_DANGLING_FIELD_IN_PIC))
5096 {
5097 api_ret_value = IV_FAIL;
5098 }
5099
5100 if(ret == ERROR_IN_LAST_SLICE_OF_PIC)
5101 {
5102 api_ret_value = IV_FAIL;
5103 }
5104 }
5105
5106 if(NOT_OK == ret)
5107 {
5108 if(ps_dec->u4_pic_buf_got == 0)
5109 {
5110 ps_dec->i4_error_code = ERROR_START_CODE_NOT_FOUND;
5111 ps_dec_op->u4_error_code |= 1 << IVD_INSUFFICIENTDATA;
5112
5113 isvcd_fill_output_struct_from_context(ps_svc_lyr_dec, ps_dec_op);
5114
5115 ps_dec_op->u4_error_code = ps_dec->i4_error_code;
5116 ps_dec_op->u4_frame_decoded_flag = 0;
5117 return (IV_FAIL);
5118 }
5119 return (IV_SUCCESS);
5120 }
5121
5122 u1_num_res_lyrs = ps_svcd_ctxt->s_vcl_nal.i4_num_res_lyrs;
5123
5124 /* error concelment: exit till next IDR if any of Non Target layers are
5125 * corrupted */
5126 {
5127 ps_cur_node = ps_svcd_ctxt->s_vcl_nal.ps_bot_node;
5128
5129 if(NULL != ps_cur_node)
5130 {
5131 if(!ps_cur_node->i4_idr_pic_flag)
5132 {
5133 if(u1_num_res_lyrs != ps_svcd_ctxt->u1_prev_num_res_layers)
5134 {
5135 ps_svcd_ctxt->u1_exit_till_next_IDR = 1;
5136 ps_dec_op->u4_error_code = ERROR_UNKNOWN_NAL;
5137 return IV_FAIL;
5138 }
5139 }
5140 else
5141 {
5142 if(u1_num_res_lyrs != ps_svcd_ctxt->u1_prev_num_res_layers)
5143 {
5144 ps_svcd_ctxt->u1_prev_num_res_layers = u1_num_res_lyrs;
5145 }
5146 }
5147 }
5148 }
5149 if(ps_svcd_ctxt->u1_prev_num_res_layers != u1_num_res_lyrs && (u1_num_res_lyrs != 0))
5150 {
5151 ps_svc_lyr_dec = ps_svcd_ctxt->ps_svc_dec_lyr + u1_num_res_lyrs - 1;
5152 ps_dec = &ps_svc_lyr_dec->s_dec;
5153
5154 if(ps_dec->u1_init_dec_flag == 1)
5155 {
5156 ih264d_release_pics_in_dpb((void *) ps_dec, ps_dec->u1_pic_bufs);
5157 ih264d_release_display_bufs(ps_dec);
5158 ih264_disp_mgr_init((disp_mgr_t *) ps_dec->pv_disp_buf_mgr);
5159
5160 ih264_buf_mgr_reset(ps_dec->pv_pic_buf_mgr);
5161 ih264_buf_mgr_reset(ps_dec->pv_mv_buf_mgr);
5162 ih264d_init_ref_bufs(ps_dec->ps_dpb_mgr);
5163 }
5164
5165 // ps_svcd_ctxt->u1_prev_num_res_layers = u1_num_res_lyrs;
5166 }
5167 ps_svcd_ctxt->u1_parse_nal_unit_error = 0;
5168
5169 if((1 == ps_svcd_ctxt->u1_exit_till_next_IDR) &&
5170 (ps_svcd_ctxt->s_vcl_nal.ps_bot_node != NULL))
5171 {
5172 if(1 == ps_svcd_ctxt->s_vcl_nal.ps_bot_node->i4_idr_pic_flag)
5173 {
5174 ps_svcd_ctxt->u1_exit_till_next_IDR = 0;
5175
5176 for(u1_res_id = 0; u1_res_id < u1_num_res_lyrs; u1_res_id++)
5177 {
5178 ps_svc_lyr_dec = ps_svcd_ctxt->ps_svc_dec_lyr + u1_res_id;
5179 ps_dec = &ps_svc_lyr_dec->s_dec;
5180 ih264_buf_mgr_reset(ps_dec->pv_pic_buf_mgr);
5181 ih264_buf_mgr_reset(ps_dec->pv_mv_buf_mgr);
5182 }
5183 }
5184 else
5185 {
5186 ps_dec_op->u4_error_code = ERROR_UNKNOWN_NAL;
5187 return IV_FAIL;
5188 }
5189 }
5190
5191 if((0 == ps_dec->i4_decode_header) && (OK == ret))
5192 {
5193 flush_decode = 0;
5194 ps_cur_node = ps_svcd_ctxt->s_vcl_nal.ps_bot_node;
5195 ps_svc_lyr_zero_dec = ps_svcd_ctxt->ps_svc_dec_lyr;
5196 ps_dec_zero_lyr = &ps_svc_lyr_zero_dec->s_dec;
5197 /* master loop */
5198
5199 for(u1_res_id = 0; u1_res_id < u1_num_res_lyrs; u1_res_id++)
5200 {
5201 UWORD8 u1_layer_nal_data_present = 0;
5202 ps_svcd_ctxt->u1_cur_layer_id = u1_res_id;
5203 ps_svc_lyr_dec = ps_svcd_ctxt->ps_svc_dec_lyr + u1_res_id;
5204 ps_svc_lyr_dec->u1_res_init_done = 0;
5205 ps_dec = &ps_svc_lyr_dec->s_dec;
5206
5207 ps_dec->i4_decode_header = ps_dec_zero_lyr->i4_decode_header;
5208 ps_dec->i4_header_decoded = ps_dec_zero_lyr->i4_header_decoded;
5209 ps_dec->u1_pic_decode_done = 0;
5210 ps_dec->u4_fmt_conv_cur_row = 0;
5211
5212 ps_dec->u4_output_present = 0;
5213 ps_dec->s_disp_op.u4_error_code = 1;
5214 ps_dec->u4_fmt_conv_num_rows = FMT_CONV_NUM_ROWS;
5215 ps_dec->u4_ts = ps_dec_ip->u4_ts;
5216 ps_dec->i4_frametype = IV_NA_FRAME;
5217 ps_dec->i4_content_type = IV_CONTENTTYPE_NA;
5218
5219 ps_dec->u4_slice_start_code_found = 0;
5220 ps_dec->u2_cur_mb_addr = 0;
5221 ps_dec->u2_total_mbs_coded = 0;
5222 ps_dec->u2_cur_slice_num = 0;
5223 ps_dec->cur_dec_mb_num = 0;
5224 ps_dec->cur_recon_mb_num = 0;
5225 ps_dec->u4_first_slice_in_pic = 1;
5226 ps_dec->u1_slice_header_done = 0;
5227 ps_dec->u1_dangling_field = 0;
5228
5229 ps_dec->u4_dec_thread_created = 0;
5230 ps_dec->u4_bs_deblk_thread_created = 0;
5231 ps_dec->u4_cur_bs_mb_num = 0;
5232 ps_dec->u4_cur_deblk_mb_num = 0;
5233 ps_dec->u4_start_recon_deblk = 0;
5234 ps_dec->u4_sps_cnt_in_process = 0;
5235 ps_dec->u4_pic_buf_got = 0;
5236 ps_dec->pv_dec_out = ps_dec_op;
5237
5238 if(ps_dec_ip->u4_size >= offsetof(ivd_video_decode_ip_t, s_out_buffer))
5239 ps_dec->ps_out_buffer = &ps_dec_ip->s_out_buffer;
5240
5241 ps_dec->u1_nal_unit_type = ps_cur_node->i4_nal_unit_type;
5242 ps_dec->u1_separate_parse = 0;
5243 if(u1_res_id == (u1_num_res_lyrs - 1))
5244 {
5245 ps_svc_lyr_dec->u1_layer_identifier = TARGET_LAYER;
5246 if(ps_dec->u4_num_cores >= 2)
5247 {
5248 ps_dec->u4_num_cores = 2;
5249 ps_dec->u1_separate_parse = 1;
5250 }
5251 }
5252 else if(u1_res_id == 0)
5253 {
5254 ps_svc_lyr_dec->u1_layer_identifier = BASE_LAYER;
5255 ps_dec->u1_separate_parse = 0;
5256 ps_dec->u4_num_cores = 1;
5257 }
5258 else if(u1_res_id != 0)
5259 {
5260 ps_svc_lyr_dec->u1_layer_identifier = MEDIAL_ENHANCEMENT_LAYER;
5261 ps_dec->u1_separate_parse = 0;
5262 ps_dec->u4_num_cores = 1;
5263 }
5264 else
5265 {
5266 return IV_FAIL;
5267 }
5268
5269 ps_svc_lyr_dec->u1_base_res_flag = (0 == u1_res_id);
5270 ps_svc_lyr_dec->ps_nal_svc_ext->u1_idr_flag = ps_cur_node->i4_idr_pic_flag;
5271 ps_svc_lyr_dec->ps_nal_svc_ext->u1_dependency_id = ps_cur_node->i4_dependency_id;
5272 ps_svc_lyr_dec->ps_nal_svc_ext->u1_priority_id = ps_cur_node->i4_priority_id;
5273 ps_svc_lyr_dec->ps_nal_svc_ext->u1_no_inter_layer_pred_flag =
5274 ps_cur_node->u1_acc_no_int_pred;
5275
5276 ps_svc_lyr_dec->ps_nal_svc_ext->u1_quality_id = ps_cur_node->i4_quality_id;
5277 ps_svc_lyr_dec->ps_nal_svc_ext->u1_temporal_id = ps_cur_node->i4_temporal_id;
5278
5279 ps_svc_lyr_dec->ps_nal_svc_ext->u1_use_ref_base_pic_flag =
5280 ps_cur_node->i4_use_ref_base;
5281 ps_svc_lyr_dec->ps_nal_svc_ext->u1_discardable_flag = 0;
5282 ps_svc_lyr_dec->ps_nal_svc_ext->u1_svc_ext_flag = (u1_res_id > 1);
5283 ps_svc_lyr_dec->u4_pps_id_for_layer = UINT32_MAX;
5284 ps_vcl_buf = ps_cur_node->ps_first_vcl_nal;
5285 ps_svc_lyr_dec->u1_error_in_cur_frame = 0;
5286
5287 /* Only for Non target Layers*/
5288 if(NULL != ps_cur_node->ps_top_node)
5289 {
5290 ps_svc_lyr_dec->u1_inter_lyr_disable_dblk_filter_idc =
5291 ps_cur_node->ps_top_node->i4_inter_lyr_dblk_idc;
5292 ps_svc_lyr_dec->i1_inter_lyr_slice_alpha_c0_offset =
5293 ps_cur_node->ps_top_node->i4_inter_lyr_alpha_c0_offset;
5294 ps_svc_lyr_dec->i1_inter_lyr_slice_beta_offset =
5295 ps_cur_node->ps_top_node->i4_inter_lyr_beta_offset;
5296 }
5297
5298 while(NULL != ps_vcl_buf)
5299 {
5300 u1_layer_nal_data_present = 1;
5301 ps_dec->ps_bitstrm->u4_ofst = 0;
5302 ps_dec->ps_bitstrm->pu4_buffer =
5303 (UWORD32 *) ((UWORD8 *) ps_vcl_buf + ps_vcl_buf->i4_buf_offset +
5304 ps_vcl_buf->i4_slice_offset);
5305
5306 ps_dec->ps_bitstrm->u4_max_ofst = ps_vcl_buf->u4_max_bits;
5307
5308 ps_dec_op->u4_frame_decoded_flag = 0;
5309 ret = isvcd_parse_nal_unit(ps_svc_lyr_dec, ps_cur_node->i4_nal_ref_idc);
5310 if(ret != OK)
5311 {
5312 ps_svcd_ctxt->u1_parse_nal_unit_error = 1;
5313 break;
5314 }
5315
5316 /* go to the next slice */
5317 ps_vcl_buf = ps_vcl_buf->ps_next;
5318 }
5319 /* error concelment: exit till next IDR if a Layer data is missing */
5320 if(0 == u1_layer_nal_data_present)
5321 {
5322 ps_svcd_ctxt->u1_exit_till_next_IDR = 1;
5323 ps_dec_op->u4_error_code = ERROR_UNKNOWN_NAL;
5324 return IV_FAIL;
5325 }
5326 /* error concelment: exit till next IDR if any of Non Target layers are
5327 * corrupted */
5328 if((ret != OK) && (u1_res_id != (u1_num_res_lyrs - 1)))
5329 {
5330 ps_svcd_ctxt->u1_exit_till_next_IDR = 1;
5331 ps_dec_op->u4_error_code = ERROR_UNKNOWN_NAL;
5332 return IV_FAIL;
5333 }
5334
5335 if((ret != OK) && (u1_res_id == (u1_num_res_lyrs - 1)))
5336 {
5337 ps_svc_lyr_dec = ps_svcd_ctxt->ps_svc_dec_lyr + u1_num_res_lyrs - 1;
5338 ps_dec = &ps_svc_lyr_dec->s_dec;
5339
5340 if((0 == ps_svcd_ctxt->u4_num_sps_ctr) || (0 == ps_svcd_ctxt->u4_num_pps_ctr) ||
5341 (NULL == ps_dec->ps_cur_pps) || (ps_svc_lyr_dec->u1_res_init_done == 0))
5342 {
5343 ps_svcd_ctxt->u1_exit_till_next_IDR = 1;
5344 ps_dec_op->u4_error_code = ERROR_UNKNOWN_NAL;
5345 ih264d_signal_decode_thread(ps_dec);
5346 return IV_FAIL;
5347 }
5348 }
5349 ps_cur_node = ps_cur_node->ps_top_node;
5350
5351 if((ps_dec->u4_pic_buf_got == 1) && (ret != IVD_MEM_ALLOC_FAILED) &&
5352 ps_dec->u2_total_mbs_coded < ps_dec->u2_frm_ht_in_mbs * ps_dec->u2_frm_wd_in_mbs)
5353 {
5354 // last slice - missing/corruption
5355 WORD32 num_mb_skipped;
5356 WORD32 prev_slice_err;
5357 pocstruct_t temp_poc;
5358 WORD32 ret1;
5359 WORD32 ht_in_mbs;
5360 ht_in_mbs = ps_dec->u2_pic_ht >> (4 + ps_dec->ps_cur_slice->u1_field_pic_flag);
5361 num_mb_skipped =
5362 (ht_in_mbs * ps_dec->u2_frm_wd_in_mbs) - ps_dec->u2_total_mbs_coded;
5363
5364 if(ps_dec->u4_first_slice_in_pic && (ps_dec->u4_pic_buf_got == 0))
5365 prev_slice_err = 1;
5366 else
5367 prev_slice_err = 2;
5368
5369 if(ps_dec->u2_total_mbs_coded == 0)
5370 {
5371 prev_slice_err = 1;
5372 }
5373 ret1 = isvcd_mark_err_slice_skip(
5374 ps_svc_lyr_dec, num_mb_skipped, ps_dec->u1_nal_unit_type == IDR_SLICE_NAL,
5375 ps_dec->ps_cur_slice->u2_frame_num, &temp_poc, prev_slice_err);
5376
5377 if((ret1 == ERROR_UNAVAIL_PICBUF_T) || (ret1 == ERROR_UNAVAIL_MVBUF_T) ||
5378 (ret1 == ERROR_INV_SPS_PPS_T) || (ret1 == ERROR_CORRUPTED_SLICE) ||
5379 (ret == NOT_OK))
5380 {
5381 ret = ret1;
5382 }
5383 }
5384
5385 if((ret == IVD_RES_CHANGED) || (ret == IVD_MEM_ALLOC_FAILED) ||
5386 (ret == ERROR_UNAVAIL_PICBUF_T) || (ret == ERROR_UNAVAIL_MVBUF_T) ||
5387 (ret == ERROR_INV_SPS_PPS_T) || (ret == ERROR_CORRUPTED_SLICE) ||
5388 (ret == IVD_DISP_FRM_ZERO_OP_BUF_SIZE) || (ret == NOT_OK))
5389 {
5390 ps_svcd_ctxt->u1_exit_till_next_IDR = 1;
5391 /* signal the decode thread */
5392 ih264d_signal_decode_thread(ps_dec);
5393 /* dont consume bitstream for change in resolution case */
5394 if(ret == IVD_RES_CHANGED)
5395 {
5396 ps_dec_op->u4_num_bytes_consumed -= bytes_consumed;
5397 }
5398 return IV_FAIL;
5399 }
5400
5401 /* Multi thread - for target Layer decoding*/
5402 if((ps_dec->u1_separate_parse) &&
5403 (ps_svc_lyr_dec->u1_layer_identifier == TARGET_LAYER) &&
5404 (0 == ps_svc_lyr_dec->u1_error_in_cur_frame))
5405 {
5406 /* If Format conversion is not complete,
5407 complete it here */
5408 if(ps_dec->u4_num_cores == 2)
5409 {
5410 /*do deblocking of all mbs*/
5411 if((ps_dec->u4_nmb_deblk == 0) && (ps_dec->u4_start_recon_deblk == 1) &&
5412 (ps_dec->ps_cur_sps->u1_mb_aff_flag == 0))
5413 {
5414 UWORD8 u1_end_of_row = 0;
5415 UWORD32 u4_max_addr;
5416 tfr_ctxt_t s_tfr_ctxt = {0};
5417 tfr_ctxt_t *ps_tfr_cxt = &s_tfr_ctxt;
5418 pad_mgr_t *ps_pad_mgr = &ps_dec->s_pad_mgr;
5419 UWORD32 u4_slice_end = 0;
5420
5421 /*BS is done for all mbs while parsing*/
5422 u4_max_addr = (ps_dec->u2_frm_wd_in_mbs * ps_dec->u2_frm_ht_in_mbs) - 1;
5423 /* BS is moved post recon gen in SVC ext*/
5424
5425 ih264d_init_deblk_tfr_ctxt(ps_dec, ps_pad_mgr, ps_tfr_cxt,
5426 ps_dec->u2_frm_wd_in_mbs, 0);
5427
5428 {
5429 while(u4_slice_end != 1)
5430 {
5431 dec_mb_info_t *p_cur_mb;
5432 WORD32 i, bs_mb_grp;
5433 bs_mb_grp = ps_dec->cur_dec_mb_num - ps_dec->u4_cur_bs_mb_num;
5434
5435 for(i = 0; i < bs_mb_grp; i++)
5436 {
5437 p_cur_mb =
5438 &ps_dec->ps_frm_mb_info[ps_dec->u4_cur_bs_mb_num];
5439
5440 DEBUG_THREADS_PRINTF("ps_dec->u4_cur_bs_mb_num = %d\n",
5441 ps_dec->u4_cur_bs_mb_num);
5442 isvcd_compute_bs_non_mbaff_thread(ps_svc_lyr_dec, p_cur_mb,
5443 ps_dec->u4_cur_bs_mb_num);
5444
5445 ps_dec->u4_cur_bs_mb_num++;
5446 ps_dec->u4_bs_cur_slice_num_mbs++;
5447 }
5448 if(ps_dec->u4_cur_bs_mb_num > u4_max_addr)
5449 {
5450 u4_slice_end = 1;
5451 u1_end_of_row = 1;
5452 }
5453 /*deblock MB group*/
5454 {
5455 UWORD32 u4_num_mbs;
5456
5457 if(ps_dec->u4_cur_bs_mb_num > ps_dec->u4_cur_deblk_mb_num)
5458 {
5459 if(u1_end_of_row)
5460 {
5461 u4_num_mbs = ps_dec->u4_cur_bs_mb_num -
5462 ps_dec->u4_cur_deblk_mb_num;
5463 }
5464 else
5465 {
5466 u4_num_mbs = ps_dec->u4_cur_bs_mb_num -
5467 ps_dec->u4_cur_deblk_mb_num - 1;
5468 }
5469 }
5470 else
5471 u4_num_mbs = 0;
5472
5473 ih264d_check_mb_map_deblk(ps_dec, u4_num_mbs, ps_tfr_cxt,
5474 0);
5475 }
5476 }
5477 }
5478 }
5479 }
5480
5481 /*signal the decode thread*/
5482 ih264d_signal_decode_thread(ps_dec);
5483 }
5484 else if((ps_dec->u1_separate_parse) &&
5485 (ps_svc_lyr_dec->u1_layer_identifier == TARGET_LAYER))
5486 {
5487 /*signal the decode thread*/
5488 ih264d_signal_decode_thread(ps_dec);
5489 }
5490
5491 DATA_SYNC();
5492
5493 if((ps_dec_op->u4_error_code & 0xff) != ERROR_DYNAMIC_RESOLUTION_NOT_SUPPORTED)
5494 {
5495 ps_dec_op->u4_pic_wd = (UWORD32) ps_dec->u2_disp_width;
5496 ps_dec_op->u4_pic_ht = (UWORD32) ps_dec->u2_disp_height;
5497 ps_dec_op->i4_reorder_depth = ps_dec->i4_reorder_depth;
5498 }
5499
5500 // Report if header (sps and pps) has not been decoded yet
5501 if(ps_dec->i4_decode_header == 1 && ps_dec->i4_header_decoded != 3)
5502 {
5503 ps_dec_op->u4_error_code |= (1 << IVD_INSUFFICIENTDATA);
5504 api_ret_value = IV_FAIL;
5505 }
5506
5507 if((ps_dec->u4_pic_buf_got == 1) && (ERROR_DANGLING_FIELD_IN_PIC != i4_err_status))
5508 {
5509 /* For field pictures, set bottom and top picture decoded u4_flag correctly */
5510
5511 if(ps_dec->ps_cur_slice->u1_field_pic_flag)
5512 {
5513 if(1 == ps_dec->ps_cur_slice->u1_bottom_field_flag)
5514 {
5515 ps_dec->u1_top_bottom_decoded |= BOT_FIELD_ONLY;
5516 }
5517 else
5518 {
5519 ps_dec->u1_top_bottom_decoded |= TOP_FIELD_ONLY;
5520 }
5521 }
5522 else
5523 {
5524 ps_dec->u1_top_bottom_decoded = TOP_FIELD_ONLY | BOT_FIELD_ONLY;
5525 }
5526
5527 /* if new frame in not found (if we are still getting slices from
5528 * previous frame) ih264d_deblock_display is not called. Such frames
5529 * will not be added to reference /display
5530 */
5531 if((ps_dec->ps_dec_err_status->u1_err_flag & REJECT_CUR_PIC) == 0)
5532 {
5533 /* Calling Function to deblock Picture and Display */
5534 ret = ih264d_deblock_display(ps_dec);
5535 }
5536
5537 /*set to complete ,as we dont support partial frame decode*/
5538 if(ps_dec->i4_header_decoded == 3)
5539 {
5540 ps_dec->u2_total_mbs_coded = ps_dec->ps_cur_sps->u2_max_mb_addr + 1;
5541 }
5542
5543 /*Update the i4_frametype at the end of picture*/
5544 if(ps_dec->ps_cur_slice->u1_nal_unit_type == IDR_SLICE_NAL)
5545 {
5546 ps_dec->i4_frametype = IV_IDR_FRAME;
5547 }
5548 else if(ps_dec->i4_pic_type == B_SLICE)
5549 {
5550 ps_dec->i4_frametype = IV_B_FRAME;
5551 }
5552 else if(ps_dec->i4_pic_type == P_SLICE)
5553 {
5554 ps_dec->i4_frametype = IV_P_FRAME;
5555 }
5556 else if(ps_dec->i4_pic_type == I_SLICE)
5557 {
5558 ps_dec->i4_frametype = IV_I_FRAME;
5559 }
5560 else
5561 {
5562 H264_DEC_DEBUG_PRINT("Shouldn't come here\n");
5563 }
5564
5565 // Update the content type
5566 ps_dec->i4_content_type = ps_dec->ps_cur_slice->u1_field_pic_flag;
5567
5568 ps_dec->u4_total_frames_decoded = ps_dec->u4_total_frames_decoded + 2;
5569 ps_dec->u4_total_frames_decoded =
5570 ps_dec->u4_total_frames_decoded - ps_dec->ps_cur_slice->u1_field_pic_flag;
5571 }
5572
5573 /* In case the decoder is configured to run in low delay mode,
5574 * then get display buffer and then format convert.
5575 * Note in this mode, format conversion does not run paralelly in a
5576 * thread and adds to the codec cycles
5577 */
5578 if((IVD_DECODE_FRAME_OUT == ps_dec->e_frm_out_mode) && ps_dec->u1_init_dec_flag)
5579 {
5580 ih264d_get_next_display_field(ps_dec, ps_dec->ps_out_buffer,
5581 &(ps_dec->s_disp_op));
5582
5583 if(0 == ps_dec->s_disp_op.u4_error_code)
5584 {
5585 ps_dec->u4_fmt_conv_cur_row = 0;
5586 ps_dec->u4_output_present = 1;
5587 }
5588 else
5589 {
5590 ps_dec->u4_output_present = 0;
5591 }
5592 }
5593
5594 isvcd_fill_output_struct_from_context(ps_svc_lyr_dec, ps_dec_op);
5595
5596 /* If Format conversion is not complete,
5597 complete it here */
5598 /* For Non -target Layers , Buffers are retrived but not displayed*/
5599
5600 if((ps_svc_lyr_dec->u1_layer_identifier == TARGET_LAYER) &&
5601 ps_dec->u4_output_present &&
5602 (ps_dec->u4_fmt_conv_cur_row < ps_dec->s_disp_frame_info.u4_y_ht))
5603 {
5604 ps_dec->u4_fmt_conv_num_rows =
5605 ps_dec->s_disp_frame_info.u4_y_ht - ps_dec->u4_fmt_conv_cur_row;
5606 ih264d_format_convert(ps_dec, &(ps_dec->s_disp_op), ps_dec->u4_fmt_conv_cur_row,
5607 ps_dec->u4_fmt_conv_num_rows);
5608 ps_dec->u4_fmt_conv_cur_row += ps_dec->u4_fmt_conv_num_rows;
5609 }
5610
5611 ih264d_release_display_field(ps_dec, &(ps_dec->s_disp_op));
5612
5613 if(ps_dec->i4_decode_header == 1 && (ps_dec->i4_header_decoded & 1) == 1)
5614 {
5615 ps_dec_op->u4_progressive_frame_flag = 1;
5616 if((NULL != ps_dec->ps_cur_sps) && (1 == (ps_dec->ps_cur_sps->u1_is_valid)))
5617 {
5618 if((0 == ps_dec->ps_sps->u1_frame_mbs_only_flag) &&
5619 (0 == ps_dec->ps_sps->u1_mb_aff_flag))
5620 ps_dec_op->u4_progressive_frame_flag = 0;
5621 }
5622 }
5623
5624 if((TOP_FIELD_ONLY | BOT_FIELD_ONLY) == ps_dec->u1_top_bottom_decoded)
5625 {
5626 ps_dec->u1_top_bottom_decoded = 0;
5627 }
5628 /*--------------------------------------------------------------------*/
5629 /* Do End of Pic processing. */
5630 /* Should be called only if frame was decoded in previous process call*/
5631 /*--------------------------------------------------------------------*/
5632 if(ps_dec->u4_pic_buf_got == 1)
5633 {
5634 if(1 == ps_dec->u1_last_pic_not_decoded)
5635 {
5636 ret = ih264d_end_of_pic_dispbuf_mgr(ps_dec);
5637
5638 if(ret != OK) return ret;
5639
5640 ret = ih264d_end_of_pic(ps_dec);
5641 if(ret != OK) return ret;
5642 }
5643 else
5644 {
5645 ret = ih264d_end_of_pic(ps_dec);
5646 if(ret != OK) return ret;
5647 }
5648 }
5649
5650 if(ps_dec->u1_enable_mb_info && ps_dec->u4_output_present)
5651 {
5652 UWORD32 disp_buf_id = ps_dec->s_disp_op.u4_disp_buf_id;
5653 if(ps_h264d_dec_ip->pu1_8x8_blk_qp_map)
5654 {
5655 ps_h264d_dec_op->pu1_8x8_blk_qp_map = ps_h264d_dec_ip->pu1_8x8_blk_qp_map;
5656 ps_h264d_dec_op->u4_8x8_blk_qp_map_size = ps_dec->u4_total_mbs << 2;
5657 ih264_memcpy(ps_h264d_dec_op->pu1_8x8_blk_qp_map,
5658 ps_dec->as_buf_id_info_map[disp_buf_id].pu1_qp_map,
5659 ps_dec->u4_total_mbs << 2);
5660 }
5661 if(ps_h264d_dec_ip->pu1_8x8_blk_type_map)
5662 {
5663 ps_h264d_dec_op->pu1_8x8_blk_type_map =
5664 ps_h264d_dec_ip->pu1_8x8_blk_type_map;
5665 ps_h264d_dec_op->u4_8x8_blk_type_map_size = ps_dec->u4_total_mbs << 2;
5666 ih264_memcpy(ps_h264d_dec_op->pu1_8x8_blk_type_map,
5667 ps_dec->as_buf_id_info_map[disp_buf_id].pu1_mb_type_map,
5668 ps_dec->u4_total_mbs << 2);
5669 }
5670 }
5671 /*Data memory barrier instruction,so that yuv write by the library is
5672 * complete*/
5673 DATA_SYNC();
5674
5675 H264_DEC_DEBUG_PRINT("The num bytes consumed: %d\n",
5676 ps_dec_op->u4_num_bytes_consumed);
5677 }
5678 }
5679 /* highest layer for flush validation */
5680
5681 if((ps_dec->u1_flushfrm) && (1 == flush_decode))
5682 {
5683 u1_res_id = u1_num_res_lyrs - 1;
5684 ps_svc_lyr_dec = ps_svcd_ctxt->ps_svc_dec_lyr + u1_res_id;
5685 ps_dec = &ps_svc_lyr_dec->s_dec;
5686
5687 ih264d_get_next_display_field(ps_dec, ps_dec->ps_out_buffer, &(ps_dec->s_disp_op));
5688 if(0 == ps_dec->s_disp_op.u4_error_code)
5689 {
5690 /* check output buffer size given by the application */
5691 if(check_app_out_buf_size(ps_dec) != IV_SUCCESS)
5692 {
5693 ps_dec_op->u4_error_code = IVD_DISP_FRM_ZERO_OP_BUF_SIZE;
5694 return (IV_FAIL);
5695 }
5696
5697 ps_dec->u4_fmt_conv_cur_row = 0;
5698 ps_dec->u4_fmt_conv_num_rows = ps_dec->s_disp_frame_info.u4_y_ht;
5699 ih264d_format_convert(ps_dec, &(ps_dec->s_disp_op), ps_dec->u4_fmt_conv_cur_row,
5700 ps_dec->u4_fmt_conv_num_rows);
5701 ps_dec->u4_fmt_conv_cur_row += ps_dec->u4_fmt_conv_num_rows;
5702 ps_dec->u4_output_present = 1;
5703 }
5704 else
5705 {
5706 ps_dec->u4_output_present = 0;
5707 }
5708 ih264d_export_sei_params(&ps_dec_op->s_sei_decode_op, ps_dec);
5709
5710 ih264d_release_display_field(ps_dec, &(ps_dec->s_disp_op));
5711
5712 ps_dec_op->u4_pic_wd = (UWORD32) ps_dec->u2_disp_width;
5713 ps_dec_op->u4_pic_ht = (UWORD32) ps_dec->u2_disp_height;
5714 ps_dec_op->i4_reorder_depth = ps_dec->i4_reorder_depth;
5715 ps_dec_op->i4_display_index = ps_dec->i4_display_index;
5716
5717 ps_dec_op->u4_new_seq = 0;
5718 ps_dec_op->u4_output_present = (ps_svc_lyr_dec->u1_layer_identifier == TARGET_LAYER)
5719 ? ps_dec->u4_output_present
5720 : 0;
5721 ps_dec_op->u4_progressive_frame_flag = ps_dec->s_disp_op.u4_progressive_frame_flag;
5722 ps_dec_op->e_output_format = ps_dec->s_disp_op.e_output_format;
5723 ps_dec_op->s_disp_frm_buf = ps_dec->s_disp_op.s_disp_frm_buf;
5724 ps_dec_op->e4_fld_type = ps_dec->s_disp_op.e4_fld_type;
5725 ps_dec_op->u4_ts = ps_dec->s_disp_op.u4_ts;
5726 ps_dec_op->u4_disp_buf_id = ps_dec->s_disp_op.u4_disp_buf_id;
5727
5728 /*In the case of flush ,since no frame is decoded set pic type as invalid*/
5729 ps_dec_op->u4_is_ref_flag = UINT32_MAX;
5730 ps_dec_op->e_pic_type = IV_NA_FRAME;
5731 ps_dec_op->u4_frame_decoded_flag = 0;
5732
5733 if(0 == ps_dec->s_disp_op.u4_error_code)
5734 {
5735 return (IV_SUCCESS);
5736 }
5737 else
5738 return (IV_FAIL);
5739 }
5740 }
5741
5742 if((ps_dec_op->u4_error_code & 0xff) != ERROR_DYNAMIC_RESOLUTION_NOT_SUPPORTED)
5743 {
5744 ps_dec_op->u4_pic_wd = (UWORD32) ps_dec->u2_disp_width;
5745 ps_dec_op->u4_pic_ht = (UWORD32) ps_dec->u2_disp_height;
5746 ps_dec_op->i4_reorder_depth = ps_dec->i4_reorder_depth;
5747 }
5748 return api_ret_value;
5749 }
5750
5751 /*****************************************************************************/
5752 /* */
5753 /* Function Name : isvcd_set_display_frame */
5754 /* */
5755 /* Description : */
5756 /* */
5757 /* Inputs :iv_obj_t decoder handle */
5758 /* :pv_api_ip pointer to input structure */
5759 /* :pv_api_op pointer to output structure */
5760 /* Outputs : */
5761 /* Returns : void */
5762 /* */
5763 /* Issues : none */
5764 /* */
5765 /* Revision History: */
5766 /* */
5767 /* DD MM YYYY Author(s) Changes (Describe the changes made) */
5768 /* 06 09 2021 Kishore Draft */
5769 /* */
5770 /*****************************************************************************/
isvcd_set_display_frame(iv_obj_t * dec_hdl,void * pv_api_ip,void * pv_api_op)5771 WORD32 isvcd_set_display_frame(iv_obj_t *dec_hdl, void *pv_api_ip, void *pv_api_op)
5772 {
5773 UWORD32 u4_disp_buf_size[3] = {0};
5774 UWORD32 u4_num_disp_bufs;
5775 ivd_set_display_frame_ip_t *dec_disp_ip;
5776 ivd_set_display_frame_op_t *dec_disp_op;
5777 UWORD32 i;
5778 dec_struct_t *ps_dec;
5779 svc_dec_ctxt_t *ps_svcd_ctxt;
5780 svc_dec_lyr_struct_t *ps_svc_lyr_dec;
5781
5782 ps_svcd_ctxt = (svc_dec_ctxt_t *) dec_hdl->pv_codec_handle;
5783
5784 ps_svc_lyr_dec = &ps_svcd_ctxt->ps_svc_dec_lyr[ps_svcd_ctxt->u1_target_layer_id];
5785 ps_dec = &ps_svc_lyr_dec->s_dec;
5786
5787 dec_disp_ip = (ivd_set_display_frame_ip_t *) pv_api_ip;
5788 dec_disp_op = (ivd_set_display_frame_op_t *) pv_api_op;
5789 dec_disp_op->u4_error_code = 0;
5790
5791 ps_dec->u4_num_disp_bufs = 0;
5792 if(ps_dec->u4_share_disp_buf)
5793 {
5794 UWORD32 u4_num_bufs = dec_disp_ip->num_disp_bufs;
5795
5796 u4_num_bufs = MIN(u4_num_bufs, MAX_DISP_BUFS_NEW);
5797 ps_dec->u4_num_disp_bufs = u4_num_bufs;
5798
5799 /* Get the number and sizes of the first buffer. Compare this with the
5800 * rest to make sure all the buffers are of the same size.
5801 */
5802 u4_num_disp_bufs = dec_disp_ip->s_disp_buffer[0].u4_num_bufs;
5803
5804 u4_disp_buf_size[0] = dec_disp_ip->s_disp_buffer[0].u4_min_out_buf_size[0];
5805 u4_disp_buf_size[1] = dec_disp_ip->s_disp_buffer[0].u4_min_out_buf_size[1];
5806 u4_disp_buf_size[2] = dec_disp_ip->s_disp_buffer[0].u4_min_out_buf_size[2];
5807
5808 for(i = 0; i < u4_num_bufs; i++)
5809 {
5810 if(dec_disp_ip->s_disp_buffer[i].u4_num_bufs != u4_num_disp_bufs)
5811 {
5812 return IV_FAIL;
5813 }
5814
5815 if((dec_disp_ip->s_disp_buffer[i].u4_min_out_buf_size[0] != u4_disp_buf_size[0]) ||
5816 (dec_disp_ip->s_disp_buffer[i].u4_min_out_buf_size[1] != u4_disp_buf_size[1]) ||
5817 (dec_disp_ip->s_disp_buffer[i].u4_min_out_buf_size[2] != u4_disp_buf_size[2]))
5818 {
5819 return IV_FAIL;
5820 }
5821
5822 ps_dec->disp_bufs[i].u4_num_bufs = dec_disp_ip->s_disp_buffer[i].u4_num_bufs;
5823
5824 ps_dec->disp_bufs[i].buf[0] = dec_disp_ip->s_disp_buffer[i].pu1_bufs[0];
5825 ps_dec->disp_bufs[i].buf[1] = dec_disp_ip->s_disp_buffer[i].pu1_bufs[1];
5826 ps_dec->disp_bufs[i].buf[2] = dec_disp_ip->s_disp_buffer[i].pu1_bufs[2];
5827
5828 ps_dec->disp_bufs[i].u4_bufsize[0] =
5829 dec_disp_ip->s_disp_buffer[i].u4_min_out_buf_size[0];
5830 ps_dec->disp_bufs[i].u4_bufsize[1] =
5831 dec_disp_ip->s_disp_buffer[i].u4_min_out_buf_size[1];
5832 ps_dec->disp_bufs[i].u4_bufsize[2] =
5833 dec_disp_ip->s_disp_buffer[i].u4_min_out_buf_size[2];
5834 }
5835 }
5836 return IV_SUCCESS;
5837 }
5838
5839 /*****************************************************************************/
5840 /* */
5841 /* Function Name : ih264d_set_flush_mode_svt_ext */
5842 /* */
5843 /* Description : */
5844 /* */
5845 /* Inputs :iv_obj_t decoder handle */
5846 /* :pv_api_ip pointer to input structure */
5847 /* :pv_api_op pointer to output structure */
5848 /* Globals : <Does it use any global variables?> */
5849 /* Outputs : */
5850 /* Returns : void */
5851 /* */
5852 /* Issues : none */
5853 /* */
5854 /* Revision History: */
5855 /* */
5856 /* DD MM YYYY Author(s) Changes (Describe the changes made) */
5857 /* 06 09 2021 Kishore Draft */
5858 /* */
5859 /*****************************************************************************/
isvcd_set_flush_mode(iv_obj_t * dec_hdl,void * pv_api_ip,void * pv_api_op)5860 WORD32 isvcd_set_flush_mode(iv_obj_t *dec_hdl, void *pv_api_ip, void *pv_api_op)
5861 {
5862 UWORD8 u1_layer_id;
5863 dec_struct_t *ps_dec;
5864 svc_dec_lyr_struct_t *ps_svc_lyr_dec;
5865 ivd_ctl_flush_op_t *ps_ctl_op = (ivd_ctl_flush_op_t *) pv_api_op;
5866 svc_dec_ctxt_t *ps_svcd_ctxt;
5867 ps_svcd_ctxt = (svc_dec_ctxt_t *) dec_hdl->pv_codec_handle;
5868
5869 ps_ctl_op->u4_error_code = 0;
5870
5871 ps_svc_lyr_dec = &ps_svcd_ctxt->ps_svc_dec_lyr[0];
5872 ps_dec = &ps_svc_lyr_dec->s_dec;
5873 if(0 == ps_dec->i4_decode_header)
5874 {
5875 ps_svcd_ctxt->i4_eos_flag = 1;
5876 }
5877
5878 for(u1_layer_id = 0; u1_layer_id < MAX_NUM_RES_LYRS; u1_layer_id++)
5879 {
5880 ps_svc_lyr_dec = &ps_svcd_ctxt->ps_svc_dec_lyr[u1_layer_id];
5881 ps_dec = &ps_svc_lyr_dec->s_dec;
5882 UNUSED(pv_api_ip);
5883
5884 /* Signal flush frame control call */
5885 ps_dec->u1_flushfrm = 1;
5886
5887 if(ps_dec->u1_init_dec_flag == 1)
5888 {
5889 ih264d_release_pics_in_dpb((void *) ps_dec, ps_dec->u1_pic_bufs);
5890 ih264d_release_display_bufs(ps_dec);
5891 }
5892
5893 ps_ctl_op->u4_error_code = 0;
5894
5895 /* Ignore dangling fields during flush */
5896 ps_dec->u1_top_bottom_decoded = 0;
5897 }
5898
5899 return IV_SUCCESS;
5900 }
5901
5902 /*****************************************************************************/
5903 /* */
5904 /* Function Name : isvcd_get_status */
5905 /* */
5906 /* Description : */
5907 /* */
5908 /* Inputs :iv_obj_t decoder handle */
5909 /* :pv_api_ip pointer to input structure */
5910 /* :pv_api_op pointer to output structure */
5911 /* Globals : <Does it use any global variables?> */
5912 /* Outputs : */
5913 /* Returns : void */
5914 /* */
5915 /* Issues : none */
5916 /* */
5917 /* Revision History: */
5918 /* */
5919 /* DD MM YYYY Author(s) Changes (Describe the changes made) */
5920 /* 06 09 2021 Kishore Draft */
5921 /* */
5922 /*****************************************************************************/
5923
isvcd_get_status(iv_obj_t * dec_hdl,void * pv_api_ip,void * pv_api_op)5924 WORD32 isvcd_get_status(iv_obj_t *dec_hdl, void *pv_api_ip, void *pv_api_op)
5925 {
5926 UWORD32 i;
5927 dec_struct_t *ps_dec;
5928 UWORD32 pic_wd, pic_ht;
5929 ivd_ctl_getstatus_op_t *ps_ctl_op = (ivd_ctl_getstatus_op_t *) pv_api_op;
5930 svc_dec_ctxt_t *ps_svcd_ctxt;
5931 svc_dec_lyr_struct_t *ps_svc_lyr_dec;
5932 ps_svcd_ctxt = (svc_dec_ctxt_t *) dec_hdl->pv_codec_handle;
5933
5934 ps_svc_lyr_dec = &ps_svcd_ctxt->ps_svc_dec_lyr[ps_svcd_ctxt->u1_target_layer_id];
5935 ps_dec = &ps_svc_lyr_dec->s_dec;
5936 UNUSED(pv_api_ip);
5937 ps_ctl_op->u4_error_code = 0;
5938
5939 if((NULL != ps_dec->ps_cur_sps) && (1 == (ps_dec->ps_cur_sps->u1_is_valid)))
5940 {
5941 ps_ctl_op->u4_pic_ht = ps_dec->u2_disp_height;
5942 ps_ctl_op->u4_pic_wd = ps_dec->u2_disp_width;
5943
5944 if(0 == ps_dec->u4_share_disp_buf)
5945 {
5946 pic_wd = ps_dec->u2_disp_width;
5947 pic_ht = ps_dec->u2_disp_height;
5948 }
5949 else
5950 {
5951 pic_wd = ps_dec->u2_frm_wd_y;
5952 pic_ht = ps_dec->u2_frm_ht_y;
5953 }
5954 }
5955 else
5956 {
5957 pic_wd = 0;
5958 pic_ht = 0;
5959 ps_ctl_op->u4_pic_ht = pic_wd;
5960 ps_ctl_op->u4_pic_wd = pic_ht;
5961
5962 if(1 == ps_dec->u4_share_disp_buf)
5963 {
5964 pic_wd += (PAD_LEN_Y_H << 1);
5965 pic_ht += (PAD_LEN_Y_V << 2);
5966 }
5967 }
5968
5969 if(ps_dec->u4_app_disp_width > pic_wd) pic_wd = ps_dec->u4_app_disp_width;
5970 if(0 == ps_dec->u4_share_disp_buf)
5971 ps_ctl_op->u4_num_disp_bufs = 1;
5972 else
5973 {
5974 if((NULL != ps_dec->ps_cur_sps) && (1 == (ps_dec->ps_cur_sps->u1_is_valid)))
5975 {
5976 if((ps_dec->ps_cur_sps->u1_vui_parameters_present_flag == 1) &&
5977 (1 == ps_dec->ps_cur_sps->s_vui.u1_bitstream_restriction_flag))
5978 {
5979 ps_ctl_op->u4_num_disp_bufs = ps_dec->ps_cur_sps->s_vui.u4_num_reorder_frames + 1;
5980 }
5981 else
5982 {
5983 /*if VUI is not present assume maximum possible refrence frames for the
5984 * level, as max reorder frames*/
5985 ps_ctl_op->u4_num_disp_bufs = ih264d_get_dpb_size(ps_dec->ps_cur_sps);
5986 }
5987
5988 ps_ctl_op->u4_num_disp_bufs += ps_dec->ps_cur_sps->u1_num_ref_frames + 1;
5989 }
5990 else
5991 {
5992 ps_ctl_op->u4_num_disp_bufs = 32;
5993 }
5994 ps_ctl_op->u4_num_disp_bufs = MAX(ps_ctl_op->u4_num_disp_bufs, 6);
5995 ps_ctl_op->u4_num_disp_bufs = MIN(ps_ctl_op->u4_num_disp_bufs, 32);
5996 }
5997
5998 ps_ctl_op->u4_error_code = ps_dec->i4_error_code;
5999 ps_ctl_op->u4_frame_rate = 0;
6000 ps_ctl_op->u4_bit_rate = 0;
6001 ps_ctl_op->e_content_type = ps_dec->i4_content_type;
6002 ps_ctl_op->e_output_chroma_format = ps_dec->u1_chroma_format;
6003 ps_ctl_op->u4_min_num_in_bufs = MIN_IN_BUFS;
6004
6005 if(ps_dec->u1_chroma_format == IV_YUV_420P)
6006 {
6007 ps_ctl_op->u4_min_num_out_bufs = MIN_OUT_BUFS_420;
6008 }
6009 else if(ps_dec->u1_chroma_format == IV_YUV_422ILE)
6010 {
6011 ps_ctl_op->u4_min_num_out_bufs = MIN_OUT_BUFS_422ILE;
6012 }
6013 else if(ps_dec->u1_chroma_format == IV_RGB_565)
6014 {
6015 ps_ctl_op->u4_min_num_out_bufs = MIN_OUT_BUFS_RGB565;
6016 }
6017 else if((ps_dec->u1_chroma_format == IV_YUV_420SP_UV) ||
6018 (ps_dec->u1_chroma_format == IV_YUV_420SP_VU))
6019 {
6020 ps_ctl_op->u4_min_num_out_bufs = MIN_OUT_BUFS_420SP;
6021 }
6022 else
6023 {
6024 // Invalid chroma format; Error code may be updated, verify in testing if needed
6025 ps_ctl_op->u4_error_code = ERROR_FEATURE_UNAVAIL;
6026 return IV_FAIL;
6027 }
6028
6029 for(i = 0; i < ps_ctl_op->u4_min_num_in_bufs; i++)
6030 {
6031 ps_ctl_op->u4_min_in_buf_size[i] = MAX(256000, pic_wd * pic_ht * 3 / 2);
6032 }
6033
6034 if(ps_dec->u1_chroma_format == IV_YUV_420P)
6035 {
6036 ps_ctl_op->u4_min_out_buf_size[0] = (pic_wd * pic_ht);
6037 ps_ctl_op->u4_min_out_buf_size[1] = (pic_wd * pic_ht) >> 2;
6038 ps_ctl_op->u4_min_out_buf_size[2] = (pic_wd * pic_ht) >> 2;
6039 }
6040 else if(ps_dec->u1_chroma_format == IV_YUV_422ILE)
6041 {
6042 ps_ctl_op->u4_min_out_buf_size[0] = (pic_wd * pic_ht) * 2;
6043 ps_ctl_op->u4_min_out_buf_size[1] = ps_ctl_op->u4_min_out_buf_size[2] = 0;
6044 }
6045 else if(ps_dec->u1_chroma_format == IV_RGB_565)
6046 {
6047 ps_ctl_op->u4_min_out_buf_size[0] = (pic_wd * pic_ht) * 2;
6048 ps_ctl_op->u4_min_out_buf_size[1] = ps_ctl_op->u4_min_out_buf_size[2] = 0;
6049 }
6050 else if((ps_dec->u1_chroma_format == IV_YUV_420SP_UV) ||
6051 (ps_dec->u1_chroma_format == IV_YUV_420SP_VU))
6052 {
6053 ps_ctl_op->u4_min_out_buf_size[0] = (pic_wd * pic_ht);
6054 ps_ctl_op->u4_min_out_buf_size[1] = (pic_wd * pic_ht) >> 1;
6055 ps_ctl_op->u4_min_out_buf_size[2] = 0;
6056 }
6057
6058 ps_dec->u4_num_disp_bufs_requested = ps_ctl_op->u4_num_disp_bufs;
6059 return IV_SUCCESS;
6060 }
6061
6062 /*****************************************************************************/
6063 /* */
6064 /* Function Name : isvcd_get_buf_info */
6065 /* */
6066 /* Description : */
6067 /* */
6068 /* Inputs :iv_obj_t decoder handle */
6069 /* :pv_api_ip pointer to input structure */
6070 /* :pv_api_op pointer to output structure */
6071 /* Globals : <Does it use any global variables?> */
6072 /* Outputs : */
6073 /* Returns : void */
6074 /* */
6075 /* Issues : none */
6076 /* */
6077 /* Revision History: */
6078 /* */
6079 /* DD MM YYYY Author(s) Changes (Describe the changes made) */
6080 /* 06 09 2021 Kishore Draft */
6081 /* */
6082 /*****************************************************************************/
isvcd_get_buf_info(iv_obj_t * dec_hdl,void * pv_api_ip,void * pv_api_op)6083 WORD32 isvcd_get_buf_info(iv_obj_t *dec_hdl, void *pv_api_ip, void *pv_api_op)
6084 {
6085 dec_struct_t *ps_dec;
6086 svc_dec_lyr_struct_t *ps_svc_lyr_dec;
6087 UWORD8 i = 0; // Default for 420P format
6088 UWORD16 pic_wd, pic_ht;
6089 ivd_ctl_getbufinfo_op_t *ps_ctl_op = (ivd_ctl_getbufinfo_op_t *) pv_api_op;
6090 UWORD32 au4_min_out_buf_size[IVD_VIDDEC_MAX_IO_BUFFERS] = {0};
6091 svc_dec_ctxt_t *ps_svcd_ctxt;
6092 ps_svcd_ctxt = (svc_dec_ctxt_t *) dec_hdl->pv_codec_handle;
6093
6094 UNUSED(pv_api_ip);
6095
6096 ps_svc_lyr_dec = &ps_svcd_ctxt->ps_svc_dec_lyr[ps_svcd_ctxt->u1_target_layer_id];
6097 ps_dec = &ps_svc_lyr_dec->s_dec;
6098 ps_ctl_op->u4_error_code = 0;
6099
6100 ps_ctl_op->u4_min_num_in_bufs = MIN_IN_BUFS;
6101 ps_ctl_op->u4_num_disp_bufs = 1;
6102 pic_wd = 0;
6103 pic_ht = 0;
6104
6105 if(ps_dec->i4_header_decoded == 3)
6106 {
6107 pic_wd = ps_svcd_ctxt->pic_width;
6108 pic_ht = ps_svcd_ctxt->pic_height;
6109 }
6110
6111 for(i = 0; i < ps_ctl_op->u4_min_num_in_bufs; i++)
6112 {
6113 ps_ctl_op->u4_min_in_buf_size[i] = MAX(256000, pic_wd * pic_ht * 3 / 2);
6114 }
6115 if((WORD32) ps_dec->u4_app_disp_width > pic_wd) pic_wd = ps_dec->u4_app_disp_width;
6116
6117 if(0 == ps_dec->u4_share_disp_buf)
6118 ps_ctl_op->u4_num_disp_bufs = 1;
6119 else
6120 {
6121 if((NULL != ps_dec->ps_cur_sps) && (1 == (ps_dec->ps_cur_sps->u1_is_valid)))
6122 {
6123 if((ps_dec->ps_cur_sps->u1_vui_parameters_present_flag == 1) &&
6124 (1 == ps_dec->ps_cur_sps->s_vui.u1_bitstream_restriction_flag))
6125 {
6126 ps_ctl_op->u4_num_disp_bufs = ps_dec->ps_cur_sps->s_vui.u4_num_reorder_frames + 1;
6127 }
6128 else
6129 {
6130 /*if VUI is not present assume maximum possible refrence frames for the
6131 * level, as max reorder frames*/
6132 ps_ctl_op->u4_num_disp_bufs = ih264d_get_dpb_size(ps_dec->ps_cur_sps);
6133 }
6134
6135 ps_ctl_op->u4_num_disp_bufs += ps_dec->ps_cur_sps->u1_num_ref_frames + 1;
6136 }
6137 else
6138 {
6139 ps_ctl_op->u4_num_disp_bufs = 32;
6140 }
6141
6142 ps_ctl_op->u4_num_disp_bufs = MAX(ps_ctl_op->u4_num_disp_bufs, 6);
6143 ps_ctl_op->u4_num_disp_bufs = MIN(ps_ctl_op->u4_num_disp_bufs, 32);
6144 }
6145
6146 ps_ctl_op->u4_min_num_out_bufs =
6147 ih264d_get_outbuf_size(pic_wd, pic_ht, ps_dec->u1_chroma_format, &au4_min_out_buf_size[0]);
6148
6149 for(i = 0; i < ps_ctl_op->u4_min_num_out_bufs; i++)
6150 {
6151 ps_ctl_op->u4_min_out_buf_size[i] = au4_min_out_buf_size[i];
6152 }
6153
6154 ps_dec->u4_num_disp_bufs_requested = ps_ctl_op->u4_num_disp_bufs;
6155
6156 return IV_SUCCESS;
6157 }
6158
6159 /*****************************************************************************/
6160 /* */
6161 /* Function Name : isvcd_set_params */
6162 /* */
6163 /* Description : */
6164 /* */
6165 /* Inputs :iv_obj_t decoder handle */
6166 /* :pv_api_ip pointer to input structure */
6167 /* :pv_api_op pointer to output structure */
6168 /* Outputs : */
6169 /* Returns : void */
6170 /* */
6171 /* Issues : none */
6172 /* */
6173 /* Revision History: */
6174 /* */
6175 /* DD MM YYYY Author(s) Changes (Describe the changes made) */
6176 /* 06 09 2021 Kishore Draft */
6177 /* */
6178 /*****************************************************************************/
isvcd_set_params(iv_obj_t * dec_hdl,void * pv_api_ip,void * pv_api_op)6179 WORD32 isvcd_set_params(iv_obj_t *dec_hdl, void *pv_api_ip, void *pv_api_op)
6180 {
6181 dec_struct_t *ps_dec;
6182 svc_dec_lyr_struct_t *ps_svc_lyr_dec;
6183 WORD32 ret = IV_SUCCESS;
6184 svc_dec_ctxt_t *ps_svcd_ctxt;
6185 WORD32 u1_layer_id;
6186
6187 ps_svcd_ctxt = (svc_dec_ctxt_t *) dec_hdl->pv_codec_handle;
6188 ps_svcd_ctxt->i4_eos_flag = 0;
6189 for(u1_layer_id = 0; u1_layer_id < MAX_NUM_RES_LYRS; u1_layer_id++)
6190 {
6191 isvcd_ctl_set_config_ip_t *ps_h264d_ctl_ip = (isvcd_ctl_set_config_ip_t *) pv_api_ip;
6192 isvcd_ctl_set_config_op_t *ps_h264d_ctl_op = (isvcd_ctl_set_config_op_t *) pv_api_op;
6193 ivd_ctl_set_config_ip_t *ps_ctl_ip = &ps_h264d_ctl_ip->s_ivd_ctl_set_config_ip_t;
6194 ivd_ctl_set_config_op_t *ps_ctl_op = &ps_h264d_ctl_op->s_ivd_ctl_set_config_op_t;
6195
6196 ps_svc_lyr_dec = &ps_svcd_ctxt->ps_svc_dec_lyr[u1_layer_id];
6197 ps_dec = &ps_svc_lyr_dec->s_dec;
6198
6199 ps_dec->u1_flushfrm = 0;
6200 ps_dec->u4_skip_frm_mask = 0;
6201 ps_ctl_op->u4_error_code = 0;
6202
6203 if(ps_ctl_ip->e_frm_skip_mode != IVD_SKIP_NONE)
6204 {
6205 ps_ctl_op->u4_error_code = (1 << IVD_UNSUPPORTEDPARAM);
6206 ret = IV_FAIL;
6207 }
6208
6209 if(ps_ctl_ip->u4_disp_wd >= ps_dec->u2_disp_width)
6210 {
6211 ps_dec->u4_app_disp_width = ps_ctl_ip->u4_disp_wd;
6212 }
6213 else if(0 == ps_dec->i4_header_decoded)
6214 {
6215 ps_dec->u4_app_disp_width = ps_ctl_ip->u4_disp_wd;
6216 }
6217 else if(ps_ctl_ip->u4_disp_wd == 0)
6218 {
6219 ps_dec->u4_app_disp_width = 0;
6220 }
6221 else
6222 {
6223 /*
6224 * Set the display width to zero. This will ensure that the wrong value we
6225 * had stored (0xFFFFFFFF) does not propogate.
6226 */
6227 ps_dec->u4_app_disp_width = 0;
6228 ps_ctl_op->u4_error_code |= (1 << IVD_UNSUPPORTEDPARAM);
6229 ps_ctl_op->u4_error_code |= ERROR_DISP_WIDTH_INVALID;
6230 ret = IV_FAIL;
6231 }
6232
6233 if(ps_ctl_ip->e_vid_dec_mode == IVD_DECODE_FRAME)
6234 ps_dec->i4_decode_header = 0;
6235 else if(ps_ctl_ip->e_vid_dec_mode == IVD_DECODE_HEADER)
6236 ps_dec->i4_decode_header = 1;
6237 else
6238 {
6239 ps_ctl_op->u4_error_code = (1 << IVD_UNSUPPORTEDPARAM);
6240 ps_dec->i4_decode_header = 1;
6241 ret = IV_FAIL;
6242 }
6243 ps_dec->e_frm_out_mode = IVD_DISPLAY_FRAME_OUT;
6244
6245 if((ps_ctl_ip->e_frm_out_mode != IVD_DECODE_FRAME_OUT) &&
6246 (ps_ctl_ip->e_frm_out_mode != IVD_DISPLAY_FRAME_OUT))
6247 {
6248 ps_ctl_op->u4_error_code = (1 << IVD_UNSUPPORTEDPARAM);
6249 ret = IV_FAIL;
6250 }
6251 ps_dec->e_frm_out_mode = ps_ctl_ip->e_frm_out_mode;
6252 }
6253 return ret;
6254 }
6255
6256 /*****************************************************************************/
6257 /* */
6258 /* Function Name : isvcd_set_target_layer */
6259 /* */
6260 /* Description : */
6261 /* */
6262 /* Inputs :iv_obj_t decoder handle */
6263 /* :pv_api_ip pointer to input structure */
6264 /* :pv_api_op pointer to output structure */
6265 /* Outputs : */
6266 /* Returns : void */
6267 /* */
6268 /* Issues : none */
6269 /* */
6270 /* Revision History: */
6271 /* */
6272 /* DD MM YYYY Author(s) Changes (Describe the changes made) */
6273 /* 05 04 2021 Kishore Draft */
6274 /* */
6275 /*****************************************************************************/
isvcd_set_target_layer(iv_obj_t * dec_hdl,void * pv_api_ip,void * pv_api_op)6276 WORD32 isvcd_set_target_layer(iv_obj_t *dec_hdl, void *pv_api_ip, void *pv_api_op)
6277 {
6278 WORD32 ret = IV_SUCCESS;
6279
6280 isvcd_set_target_layer_ip_t *ps_ip;
6281 isvcd_set_target_layer_op_t *ps_op;
6282 svc_dec_ctxt_t *ps_svcd_ctxt;
6283 ps_svcd_ctxt = (svc_dec_ctxt_t *) dec_hdl->pv_codec_handle;
6284
6285 ps_ip = (isvcd_set_target_layer_ip_t *) pv_api_ip;
6286 ps_op = (isvcd_set_target_layer_op_t *) pv_api_op;
6287
6288 ps_svcd_ctxt->u1_tgt_dep_id = ps_ip->u1_tgt_dep_id;
6289 ps_svcd_ctxt->u1_tgt_quality_id = ps_ip->u1_tgt_quality_id;
6290 ps_svcd_ctxt->u1_tgt_temp_id = ps_ip->u1_tgt_temp_id;
6291 ps_svcd_ctxt->u1_tgt_priority_id = ps_ip->u1_tgt_priority_id;
6292
6293 ret = isvcd_nal_parse_set_target_attr(ps_ip->u1_tgt_quality_id, ps_ip->u1_tgt_dep_id,
6294 ps_ip->u1_tgt_temp_id, ps_ip->u1_tgt_priority_id,
6295 ps_svcd_ctxt->pv_nal_parse_ctxt);
6296 ps_op->u4_error_code = 0;
6297
6298 return ret;
6299 }
6300
6301 /*****************************************************************************/
6302 /* */
6303 /* Function Name : isvcd_set_default_params */
6304 /* */
6305 /* Description : */
6306 /* */
6307 /* Inputs :iv_obj_t decoder handle */
6308 /* :pv_api_ip pointer to input structure */
6309 /* :pv_api_op pointer to output structure */
6310 /* Outputs : */
6311 /* Returns : void */
6312 /* */
6313 /* Issues : none */
6314 /* */
6315 /* Revision History: */
6316 /* */
6317 /* DD MM YYYY Author(s) Changes (Describe the changes made) */
6318 /* 06 09 2021 Kishore Copied from set_params */
6319 /* */
6320 /*****************************************************************************/
isvcd_set_default_params(iv_obj_t * dec_hdl,void * pv_api_ip,void * pv_api_op)6321 WORD32 isvcd_set_default_params(iv_obj_t *dec_hdl, void *pv_api_ip, void *pv_api_op)
6322 {
6323 dec_struct_t *ps_dec;
6324 svc_dec_lyr_struct_t *ps_svc_lyr_dec;
6325 WORD32 ret = IV_SUCCESS;
6326 UWORD8 u1_layer_id;
6327 svc_dec_ctxt_t *ps_svcd_ctxt;
6328 ivd_ctl_set_config_op_t *ps_ctl_op = (ivd_ctl_set_config_op_t *) pv_api_op;
6329
6330 ps_svcd_ctxt = (svc_dec_ctxt_t *) dec_hdl->pv_codec_handle;
6331 UNUSED(pv_api_ip);
6332
6333 for(u1_layer_id = 0; u1_layer_id < MAX_NUM_RES_LYRS; u1_layer_id++)
6334 {
6335 ps_svc_lyr_dec = &ps_svcd_ctxt->ps_svc_dec_lyr[u1_layer_id];
6336 ps_dec = &ps_svc_lyr_dec->s_dec;
6337
6338 ps_dec->u4_app_disp_width = 0;
6339 ps_dec->u4_skip_frm_mask = 0;
6340 ps_dec->i4_decode_header = 1;
6341 }
6342 ps_ctl_op->u4_error_code = 0;
6343
6344 return ret;
6345 }
6346 /*****************************************************************************/
6347 /* */
6348 /* Function Name : isvcd_delete */
6349 /* */
6350 /* Description : */
6351 /* */
6352 /* Inputs :iv_obj_t decoder handle */
6353 /* :pv_api_ip pointer to input structure */
6354 /* :pv_api_op pointer to output structure */
6355 /* Globals : <Does it use any global variables?> */
6356 /* Outputs : */
6357 /* Returns : void */
6358 /* */
6359 /* Issues : none */
6360 /* */
6361 /* Revision History: */
6362 /* */
6363 /* DD MM YYYY Author(s) Changes (Describe the changes made) */
6364 /* 06 09 2021 Kishore Draft */
6365 /* */
6366 /*****************************************************************************/
isvcd_delete(iv_obj_t * dec_hdl,void * pv_api_ip,void * pv_api_op)6367 WORD32 isvcd_delete(iv_obj_t *dec_hdl, void *pv_api_ip, void *pv_api_op)
6368 {
6369 svc_dec_lyr_struct_t *ps_svc_lyr_dec;
6370 isvcd_delete_ip_t *ps_ip = (isvcd_delete_ip_t *) pv_api_ip;
6371 isvcd_delete_op_t *ps_op = (isvcd_delete_op_t *) pv_api_op;
6372
6373 UWORD8 u1_layer_id;
6374 svc_dec_ctxt_t *ps_svcd_ctxt;
6375 ps_svcd_ctxt = (svc_dec_ctxt_t *) dec_hdl->pv_codec_handle;
6376 UNUSED(ps_ip);
6377
6378 for(u1_layer_id = 0; u1_layer_id < MAX_NUM_RES_LYRS; u1_layer_id++)
6379 {
6380 ps_svc_lyr_dec = &ps_svcd_ctxt->ps_svc_dec_lyr[u1_layer_id];
6381 isvcd_free_dynamic_bufs(ps_svc_lyr_dec);
6382 }
6383 isvcd_free_static_bufs(dec_hdl);
6384 ps_op->s_ivd_delete_op_t.u4_error_code = 0;
6385
6386 return IV_SUCCESS;
6387 }
6388 /*****************************************************************************/
6389 /* */
6390 /* Function Name : isvcd_reset */
6391 /* */
6392 /* Description : */
6393 /* */
6394 /* Inputs :iv_obj_t decoder handle */
6395 /* :pv_api_ip pointer to input structure */
6396 /* :pv_api_op pointer to output structure */
6397 /* Globals : <Does it use any global variables?> */
6398 /* Outputs : */
6399 /* Returns : void */
6400 /* */
6401 /* Issues : none */
6402 /* */
6403 /* Revision History: */
6404 /* */
6405 /* DD MM YYYY Author(s) Changes (Describe the changes made) */
6406 /* 06 09 2021 Kishore Draft */
6407 /* */
6408 /*****************************************************************************/
isvcd_reset(iv_obj_t * dec_hdl,void * pv_api_ip,void * pv_api_op)6409 WORD32 isvcd_reset(iv_obj_t *dec_hdl, void *pv_api_ip, void *pv_api_op)
6410 {
6411 dec_struct_t *ps_dec;
6412 svc_dec_lyr_struct_t *ps_svc_lyr_dec;
6413 ivd_ctl_reset_op_t *ps_ctl_op = (ivd_ctl_reset_op_t *) pv_api_op;
6414 UWORD8 u1_layer_id;
6415 svc_dec_ctxt_t *ps_svcd_ctxt;
6416 ps_svcd_ctxt = (svc_dec_ctxt_t *) dec_hdl->pv_codec_handle;
6417 UNUSED(pv_api_ip);
6418 ps_ctl_op->u4_error_code = 0;
6419
6420 ps_svcd_ctxt->i4_eos_flag = 0;
6421 ps_svcd_ctxt->u4_num_sps_ctr = 0;
6422 ps_svcd_ctxt->u4_num_pps_ctr = 0;
6423 ps_svcd_ctxt->u1_pre_parse_in_flush = 1;
6424 for(u1_layer_id = 0; u1_layer_id < MAX_NUM_RES_LYRS; u1_layer_id++)
6425 {
6426 ps_svc_lyr_dec = &ps_svcd_ctxt->ps_svc_dec_lyr[u1_layer_id];
6427 ps_dec = &ps_svc_lyr_dec->s_dec;
6428 if(ps_dec != NULL)
6429 {
6430 if(((buf_mgr_t *) ps_dec->pv_pic_buf_mgr)->pv_mutex != NULL)
6431 ih264_buf_mgr_free(ps_dec->pv_pic_buf_mgr);
6432 if(((buf_mgr_t *) ps_dec->pv_mv_buf_mgr)->pv_mutex != NULL)
6433 ih264_buf_mgr_free(ps_dec->pv_mv_buf_mgr);
6434
6435 isvcd_init_decoder(ps_svc_lyr_dec);
6436 ps_dec->u1_flushfrm = 0;
6437 }
6438 else
6439 {
6440 H264_DEC_DEBUG_PRINT("\nReset called without Initializing the decoder\n");
6441 ps_ctl_op->u4_error_code = ERROR_INIT_NOT_DONE;
6442 }
6443 }
6444 return IV_SUCCESS;
6445 }
6446
6447 /*****************************************************************************/
6448 /* */
6449 /* Function Name : isvcd_ctl */
6450 /* */
6451 /* Description : */
6452 /* */
6453 /* Inputs :iv_obj_t decoder handle */
6454 /* :pv_api_ip pointer to input structure */
6455 /* :pv_api_op pointer to output structure */
6456 /* Outputs : */
6457 /* Returns : void */
6458 /* */
6459 /* Issues : none */
6460 /* */
6461 /* Revision History: */
6462 /* */
6463 /* DD MM YYYY Author(s) Changes (Describe the changes made) */
6464 /* 06 09 2021 Kishore Draft */
6465 /* */
6466 /*****************************************************************************/
isvcd_ctl(iv_obj_t * dec_hdl,void * pv_api_ip,void * pv_api_op)6467 WORD32 isvcd_ctl(iv_obj_t *dec_hdl, void *pv_api_ip, void *pv_api_op)
6468 {
6469 ivd_ctl_set_config_ip_t *ps_ctl_ip;
6470 ivd_ctl_set_config_op_t *ps_ctl_op;
6471 WORD32 ret = IV_SUCCESS;
6472 UWORD32 subcommand;
6473 dec_struct_t *ps_dec;
6474 svc_dec_lyr_struct_t *ps_svc_lyr_dec;
6475 svc_dec_ctxt_t *ps_svcd_ctxt;
6476 ps_svcd_ctxt = (svc_dec_ctxt_t *) dec_hdl->pv_codec_handle;
6477 ps_svc_lyr_dec = &ps_svcd_ctxt->ps_svc_dec_lyr[ps_svcd_ctxt->u1_target_layer_id];
6478 ps_dec = &ps_svc_lyr_dec->s_dec;
6479 if(ps_dec->init_done != 1)
6480 {
6481 return IV_FAIL;
6482 }
6483 ps_ctl_ip = (ivd_ctl_set_config_ip_t *) pv_api_ip;
6484 ps_ctl_op = (ivd_ctl_set_config_op_t *) pv_api_op;
6485 ps_ctl_op->u4_error_code = 0;
6486 subcommand = ps_ctl_ip->e_sub_cmd;
6487
6488 switch(subcommand)
6489 {
6490 case IVD_CMD_CTL_GETPARAMS:
6491 ret = isvcd_get_status(dec_hdl, (void *) pv_api_ip, (void *) pv_api_op);
6492 break;
6493 case IVD_CMD_CTL_SETPARAMS:
6494 ret = isvcd_set_params(dec_hdl, (void *) pv_api_ip, (void *) pv_api_op);
6495 break;
6496 case IVD_CMD_CTL_RESET:
6497 ret = isvcd_reset(dec_hdl, (void *) pv_api_ip, (void *) pv_api_op);
6498 break;
6499 case IVD_CMD_CTL_SETDEFAULT:
6500 ret = isvcd_set_default_params(dec_hdl, (void *) pv_api_ip, (void *) pv_api_op);
6501 break;
6502 case IVD_CMD_CTL_FLUSH:
6503 ret = isvcd_set_flush_mode(dec_hdl, (void *) pv_api_ip, (void *) pv_api_op);
6504 break;
6505 case IVD_CMD_CTL_GETBUFINFO:
6506 ret = isvcd_get_buf_info(dec_hdl, (void *) pv_api_ip, (void *) pv_api_op);
6507 break;
6508 case IVD_CMD_CTL_GETVERSION:
6509 ret = ih264d_get_version(dec_hdl, (void *) pv_api_ip, (void *) pv_api_op);
6510 break;
6511 case IH264D_CMD_CTL_DEGRADE:
6512 ret = isvcd_set_degrade(dec_hdl, (void *) pv_api_ip, (void *) pv_api_op);
6513 break;
6514
6515 case IH264D_CMD_CTL_SET_NUM_CORES:
6516 ret = isvcd_set_num_cores(dec_hdl, (void *) pv_api_ip, (void *) pv_api_op);
6517 break;
6518 case IH264D_CMD_CTL_GET_BUFFER_DIMENSIONS:
6519 ret = isvcd_get_frame_dimensions(dec_hdl, (void *) pv_api_ip, (void *) pv_api_op);
6520 break;
6521 case IH264D_CMD_CTL_GET_VUI_PARAMS:
6522 ret = isvcd_get_vui_params(dec_hdl, (void *) pv_api_ip, (void *) pv_api_op);
6523 break;
6524 case IH264D_CMD_CTL_GET_SEI_MDCV_PARAMS:
6525 ret = isvcd_get_sei_mdcv_params(dec_hdl, (void *) pv_api_ip, (void *) pv_api_op);
6526 break;
6527 case IH264D_CMD_CTL_GET_SEI_CLL_PARAMS:
6528 ret = isvcd_get_sei_cll_params(dec_hdl, (void *) pv_api_ip, (void *) pv_api_op);
6529 break;
6530 case IH264D_CMD_CTL_GET_SEI_AVE_PARAMS:
6531 ret = isvcd_get_sei_ave_params(dec_hdl, (void *) pv_api_ip, (void *) pv_api_op);
6532 break;
6533 case IH264D_CMD_CTL_GET_SEI_CCV_PARAMS:
6534 ret = isvcd_get_sei_ccv_params(dec_hdl, (void *) pv_api_ip, (void *) pv_api_op);
6535 break;
6536 case IH264D_CMD_CTL_SET_PROCESSOR:
6537 ret = isvcd_set_processor(dec_hdl, (void *) pv_api_ip, (void *) pv_api_op);
6538 break;
6539 case ISVCD_CMD_CTL_SET_TGT_LAYER:
6540 ret = isvcd_set_target_layer(dec_hdl, (void *) pv_api_ip, (void *) pv_api_op);
6541 break;
6542 default:
6543 H264_DEC_DEBUG_PRINT("\ndo nothing\n");
6544 break;
6545 }
6546
6547 return ret;
6548 }
6549 /*****************************************************************************/
6550 /* */
6551 /* Function Name : isvcd_rel_display_frame */
6552 /* */
6553 /* Description : */
6554 /* */
6555 /* Inputs :iv_obj_t decoder handle */
6556 /* :pv_api_ip pointer to input structure */
6557 /* :pv_api_op pointer to output structure */
6558 /* Outputs : */
6559 /* Returns : void */
6560 /* */
6561 /* Issues : none */
6562 /* */
6563 /* Revision History: */
6564 /* */
6565 /* DD MM YYYY Author(s) Changes (Describe the changes made) */
6566 /* 06 09 2021 Kishore Draft */
6567 /* */
6568 /*****************************************************************************/
isvcd_rel_display_frame(iv_obj_t * dec_hdl,void * pv_api_ip,void * pv_api_op)6569 WORD32 isvcd_rel_display_frame(iv_obj_t *dec_hdl, void *pv_api_ip, void *pv_api_op)
6570 {
6571 ivd_rel_display_frame_ip_t *ps_rel_ip;
6572 ivd_rel_display_frame_op_t *ps_rel_op;
6573 UWORD32 buf_released = 0;
6574
6575 UWORD32 u4_ts = 0;
6576 dec_struct_t *ps_dec;
6577 svc_dec_lyr_struct_t *ps_svc_lyr_dec;
6578 UWORD8 u1_layer_id;
6579 svc_dec_ctxt_t *ps_svcd_ctxt;
6580 ps_svcd_ctxt = (svc_dec_ctxt_t *) dec_hdl->pv_codec_handle;
6581
6582 ps_rel_ip = (ivd_rel_display_frame_ip_t *) pv_api_ip;
6583 ps_rel_op = (ivd_rel_display_frame_op_t *) pv_api_op;
6584 ps_rel_op->u4_error_code = 0;
6585 u4_ts = ps_rel_ip->u4_disp_buf_id;
6586
6587 for(u1_layer_id = 0; u1_layer_id < MAX_NUM_RES_LYRS; u1_layer_id++)
6588 {
6589 ps_svc_lyr_dec = &ps_svcd_ctxt->ps_svc_dec_lyr[u1_layer_id];
6590 ps_dec = &ps_svc_lyr_dec->s_dec;
6591 if(0 == ps_dec->u4_share_disp_buf)
6592 {
6593 ps_dec->u4_disp_buf_mapping[u4_ts] = 0;
6594 ps_dec->u4_disp_buf_to_be_freed[u4_ts] = 0;
6595 return IV_SUCCESS;
6596 }
6597
6598 if(ps_dec->pv_pic_buf_mgr != NULL)
6599 {
6600 if(1 == ps_dec->u4_disp_buf_mapping[u4_ts])
6601 {
6602 ih264_buf_mgr_release((buf_mgr_t *) ps_dec->pv_pic_buf_mgr,
6603 ps_rel_ip->u4_disp_buf_id, BUF_MGR_IO);
6604 ps_dec->u4_disp_buf_mapping[u4_ts] = 0;
6605 buf_released = 1;
6606 }
6607 }
6608
6609 if((1 == ps_dec->u4_share_disp_buf) && (0 == buf_released))
6610 ps_dec->u4_disp_buf_to_be_freed[u4_ts] = 1;
6611 }
6612 return IV_SUCCESS;
6613 }
6614
6615 /**
6616 *******************************************************************************
6617 *
6618 * @brief
6619 * Sets degrade params
6620 *
6621 * @par Description:
6622 * Sets degrade params.
6623 * Refer to ih264d_ctl_degrade_ip_t definition for details
6624 *
6625 * @param[in] ps_codec_obj
6626 * Pointer to codec object at API level
6627 *
6628 * @param[in] pv_api_ip
6629 * Pointer to input argument structure
6630 *
6631 * @param[out] pv_api_op
6632 * Pointer to output argument structure
6633 *
6634 * @returns Status
6635 *
6636 * @remarks
6637 *
6638 *
6639 *******************************************************************************
6640 */
6641
isvcd_set_degrade(iv_obj_t * ps_codec_obj,void * pv_api_ip,void * pv_api_op)6642 WORD32 isvcd_set_degrade(iv_obj_t *ps_codec_obj, void *pv_api_ip, void *pv_api_op)
6643 {
6644 isvcd_ctl_degrade_ip_t *ps_ip;
6645 isvcd_ctl_degrade_op_t *ps_op;
6646 dec_struct_t *ps_codec;
6647 svc_dec_lyr_struct_t *ps_svc_lyr_dec;
6648 UWORD8 u1_layer_id;
6649 svc_dec_ctxt_t *ps_svcd_ctxt;
6650 ps_svcd_ctxt = (svc_dec_ctxt_t *) ps_codec_obj->pv_codec_handle;
6651
6652 ps_ip = (isvcd_ctl_degrade_ip_t *) pv_api_ip;
6653 ps_op = (isvcd_ctl_degrade_op_t *) pv_api_op;
6654
6655 for(u1_layer_id = 0; u1_layer_id < MAX_NUM_RES_LYRS; u1_layer_id++)
6656 {
6657 ps_svc_lyr_dec = &ps_svcd_ctxt->ps_svc_dec_lyr[u1_layer_id];
6658 ps_codec = &ps_svc_lyr_dec->s_dec;
6659 ps_codec->i4_degrade_type = ps_ip->i4_degrade_type;
6660 ps_codec->i4_nondegrade_interval = ps_ip->i4_nondegrade_interval;
6661 ps_codec->i4_degrade_pics = ps_ip->i4_degrade_pics;
6662
6663 ps_codec->i4_degrade_pic_cnt = 0;
6664 }
6665 ps_op->u4_error_code = 0;
6666
6667 return IV_SUCCESS;
6668 }
6669
6670 /*****************************************************************************/
6671 /* */
6672 /* Function Name : isvcd_get_frame_dimensions */
6673 /* */
6674 /* Description : gets the frame wd and ht and the buffer sizes */
6675 /* */
6676 /* Inputs :iv_obj_t decoder handle */
6677 /* :pv_api_ip pointer to input structure */
6678 /* :pv_api_op pointer to output structure */
6679 /* Outputs : */
6680 /* Returns : void */
6681 /* */
6682 /* Issues : none */
6683 /* */
6684 /* Revision History: */
6685 /* */
6686 /* DD MM YYYY Author(s) Changes (Describe the changes made) */
6687 /* 06 09 2021 Kishore Draft */
6688 /* */
6689 /*****************************************************************************/
isvcd_get_frame_dimensions(iv_obj_t * dec_hdl,void * pv_api_ip,void * pv_api_op)6690 WORD32 isvcd_get_frame_dimensions(iv_obj_t *dec_hdl, void *pv_api_ip, void *pv_api_op)
6691 {
6692 isvcd_ctl_get_frame_dimensions_ip_t *ps_ip;
6693 isvcd_ctl_get_frame_dimensions_op_t *ps_op;
6694 dec_struct_t *ps_dec;
6695 svc_dec_lyr_struct_t *ps_svc_lyr_dec;
6696 UWORD32 disp_wd, disp_ht, buffer_wd, buffer_ht, x_offset, y_offset;
6697 svc_dec_ctxt_t *ps_svcd_ctxt;
6698 ps_svcd_ctxt = (svc_dec_ctxt_t *) dec_hdl->pv_codec_handle;
6699
6700 ps_svc_lyr_dec = &ps_svcd_ctxt->ps_svc_dec_lyr[ps_svcd_ctxt->u1_target_layer_id];
6701 ps_dec = &ps_svc_lyr_dec->s_dec;
6702
6703 ps_ip = (isvcd_ctl_get_frame_dimensions_ip_t *) pv_api_ip;
6704 ps_op = (isvcd_ctl_get_frame_dimensions_op_t *) pv_api_op;
6705 UNUSED(ps_ip);
6706 if((NULL != ps_dec->ps_cur_sps) && (1 == (ps_dec->ps_cur_sps->u1_is_valid)))
6707 {
6708 disp_wd = ps_dec->u2_disp_width;
6709 disp_ht = ps_dec->u2_disp_height;
6710
6711 if(0 == ps_dec->u4_share_disp_buf)
6712 {
6713 buffer_wd = disp_wd;
6714 buffer_ht = disp_ht;
6715 }
6716 else
6717 {
6718 buffer_wd = ps_dec->u2_frm_wd_y;
6719 buffer_ht = ps_dec->u2_frm_ht_y;
6720 }
6721 }
6722 else
6723 {
6724 disp_wd = 0;
6725 disp_ht = 0;
6726
6727 if(0 == ps_dec->u4_share_disp_buf)
6728 {
6729 buffer_wd = disp_wd;
6730 buffer_ht = disp_ht;
6731 }
6732 else
6733 {
6734 buffer_wd = ALIGN16(disp_wd) + (PAD_LEN_Y_H << 1);
6735 buffer_ht = ALIGN16(disp_ht) + (PAD_LEN_Y_V << 2);
6736 }
6737 }
6738 if(ps_dec->u4_app_disp_width > buffer_wd) buffer_wd = ps_dec->u4_app_disp_width;
6739
6740 if(0 == ps_dec->u4_share_disp_buf)
6741 {
6742 x_offset = 0;
6743 y_offset = 0;
6744 }
6745 else
6746 {
6747 y_offset = (PAD_LEN_Y_V << 1);
6748 x_offset = PAD_LEN_Y_H;
6749
6750 if((NULL != ps_dec->ps_sps) && (1 == (ps_dec->ps_sps->u1_is_valid)) &&
6751 (0 != ps_dec->u2_crop_offset_y))
6752 {
6753 y_offset += ps_dec->u2_crop_offset_y / ps_dec->u2_frm_wd_y;
6754 x_offset += ps_dec->u2_crop_offset_y % ps_dec->u2_frm_wd_y;
6755 }
6756 }
6757
6758 ps_op->u4_disp_wd[0] = disp_wd;
6759 ps_op->u4_disp_ht[0] = disp_ht;
6760 ps_op->u4_buffer_wd[0] = buffer_wd;
6761 ps_op->u4_buffer_ht[0] = buffer_ht;
6762 ps_op->u4_x_offset[0] = x_offset;
6763 ps_op->u4_y_offset[0] = y_offset;
6764
6765 ps_op->u4_disp_wd[1] = ps_op->u4_disp_wd[2] = ((ps_op->u4_disp_wd[0] + 1) >> 1);
6766 ps_op->u4_disp_ht[1] = ps_op->u4_disp_ht[2] = ((ps_op->u4_disp_ht[0] + 1) >> 1);
6767 ps_op->u4_buffer_wd[1] = ps_op->u4_buffer_wd[2] = (ps_op->u4_buffer_wd[0] >> 1);
6768 ps_op->u4_buffer_ht[1] = ps_op->u4_buffer_ht[2] = (ps_op->u4_buffer_ht[0] >> 1);
6769 ps_op->u4_x_offset[1] = ps_op->u4_x_offset[2] = (ps_op->u4_x_offset[0] >> 1);
6770 ps_op->u4_y_offset[1] = ps_op->u4_y_offset[2] = (ps_op->u4_y_offset[0] >> 1);
6771
6772 if((ps_dec->u1_chroma_format == IV_YUV_420SP_UV) ||
6773 (ps_dec->u1_chroma_format == IV_YUV_420SP_VU))
6774 {
6775 ps_op->u4_disp_wd[2] = 0;
6776 ps_op->u4_disp_ht[2] = 0;
6777 ps_op->u4_buffer_wd[2] = 0;
6778 ps_op->u4_buffer_ht[2] = 0;
6779 ps_op->u4_x_offset[2] = 0;
6780 ps_op->u4_y_offset[2] = 0;
6781
6782 ps_op->u4_disp_wd[1] <<= 1;
6783 ps_op->u4_buffer_wd[1] <<= 1;
6784 ps_op->u4_x_offset[1] <<= 1;
6785 }
6786
6787 return IV_SUCCESS;
6788 }
6789 /*****************************************************************************/
6790 /* */
6791 /* Function Name : isvcd_get_vui_params */
6792 /* */
6793 /* Description : gets the VUI params */
6794 /* */
6795 /* Inputs :iv_obj_t decoder handle */
6796 /* :pv_api_ip pointer to input structure */
6797 /* :pv_api_op pointer to output structure */
6798 /* Outputs : */
6799 /* Returns : success or failure */
6800 /* */
6801 /* Issues : none */
6802 /* */
6803 /* Revision History: */
6804 /* */
6805 /* DD MM YYYY Author(s) Changes (Describe the changes made) */
6806 /* 06 09 2021 Kishore Draft */
6807 /* */
6808 /*****************************************************************************/
6809
isvcd_get_vui_params(iv_obj_t * dec_hdl,void * pv_api_ip,void * pv_api_op)6810 WORD32 isvcd_get_vui_params(iv_obj_t *dec_hdl, void *pv_api_ip, void *pv_api_op)
6811 {
6812 isvcd_ctl_get_vui_params_ip_t *ps_ip;
6813 isvcd_ctl_get_vui_params_op_t *ps_op;
6814 dec_struct_t *ps_dec;
6815 svc_dec_lyr_struct_t *ps_svc_lyr_dec;
6816 dec_seq_params_t *ps_sps;
6817 vui_t *ps_vui;
6818 UWORD32 u4_size;
6819 svc_dec_ctxt_t *ps_svcd_ctxt;
6820 ps_svcd_ctxt = (svc_dec_ctxt_t *) dec_hdl->pv_codec_handle;
6821
6822 ps_ip = (isvcd_ctl_get_vui_params_ip_t *) pv_api_ip;
6823 ps_op = (isvcd_ctl_get_vui_params_op_t *) pv_api_op;
6824 UNUSED(ps_ip);
6825
6826 u4_size = ps_op->u4_size;
6827 memset(ps_op, 0, sizeof(isvcd_ctl_get_vui_params_op_t));
6828 ps_op->u4_size = u4_size;
6829
6830 ps_svc_lyr_dec = &ps_svcd_ctxt->ps_svc_dec_lyr[ps_svcd_ctxt->u1_target_layer_id];
6831 ps_dec = &ps_svc_lyr_dec->s_dec;
6832 if(NULL == ps_dec->ps_cur_sps)
6833 {
6834 ps_op->u4_error_code = ERROR_VUI_PARAMS_NOT_FOUND;
6835 return IV_FAIL;
6836 }
6837 ps_sps = ps_dec->ps_cur_sps;
6838
6839 if((0 == ps_sps->u1_is_valid) || (0 == ps_sps->u1_vui_parameters_present_flag))
6840 {
6841 ps_op->u4_error_code = ERROR_VUI_PARAMS_NOT_FOUND;
6842 return IV_FAIL;
6843 }
6844
6845 ps_vui = &ps_sps->s_vui;
6846
6847 ps_op->u1_aspect_ratio_idc = ps_vui->u1_aspect_ratio_idc;
6848 ps_op->u2_sar_width = ps_vui->u2_sar_width;
6849 ps_op->u2_sar_height = ps_vui->u2_sar_height;
6850 ps_op->u1_overscan_appropriate_flag = ps_vui->u1_overscan_appropriate_flag;
6851 ps_op->u1_video_format = ps_vui->u1_video_format;
6852 ps_op->u1_video_full_range_flag = ps_vui->u1_video_full_range_flag;
6853 ps_op->u1_colour_primaries = ps_vui->u1_colour_primaries;
6854 ps_op->u1_tfr_chars = ps_vui->u1_tfr_chars;
6855 ps_op->u1_matrix_coeffs = ps_vui->u1_matrix_coeffs;
6856 ps_op->u1_cr_top_field = ps_vui->u1_cr_top_field;
6857 ps_op->u1_cr_bottom_field = ps_vui->u1_cr_bottom_field;
6858 ps_op->u4_num_units_in_tick = ps_vui->u4_num_units_in_tick;
6859 ps_op->u4_time_scale = ps_vui->u4_time_scale;
6860 ps_op->u1_fixed_frame_rate_flag = ps_vui->u1_fixed_frame_rate_flag;
6861 ps_op->u1_nal_hrd_params_present = ps_vui->u1_nal_hrd_params_present;
6862 ps_op->u1_vcl_hrd_params_present = ps_vui->u1_vcl_hrd_params_present;
6863 ps_op->u1_low_delay_hrd_flag = ps_vui->u1_low_delay_hrd_flag;
6864 ps_op->u1_pic_struct_present_flag = ps_vui->u1_pic_struct_present_flag;
6865 ps_op->u1_bitstream_restriction_flag = ps_vui->u1_bitstream_restriction_flag;
6866 ps_op->u1_mv_over_pic_boundaries_flag = ps_vui->u1_mv_over_pic_boundaries_flag;
6867 ps_op->u4_max_bytes_per_pic_denom = ps_vui->u4_max_bytes_per_pic_denom;
6868 ps_op->u4_max_bits_per_mb_denom = ps_vui->u4_max_bits_per_mb_denom;
6869 ps_op->u4_log2_max_mv_length_horz = ps_vui->u4_log2_max_mv_length_horz;
6870 ps_op->u4_log2_max_mv_length_vert = ps_vui->u4_log2_max_mv_length_vert;
6871 ps_op->u4_num_reorder_frames = ps_vui->u4_num_reorder_frames;
6872 ps_op->u4_max_dec_frame_buffering = ps_vui->u4_max_dec_frame_buffering;
6873
6874 return IV_SUCCESS;
6875 }
6876 /*****************************************************************************/
6877 /* */
6878 /* Function Name : isvcd_get_sei_mdcv_params */
6879 /* */
6880 /* Description : This function populates SEI mdcv message in */
6881 /* output structure */
6882 /* Inputs : iv_obj_t decoder handle */
6883 /* : pv_api_ip pointer to input structure */
6884 /* : pv_api_op pointer to output structure */
6885 /* Outputs : */
6886 /* Returns : returns 0; 1 with error code when MDCV is not present */
6887 /* */
6888 /* Issues : none */
6889 /* */
6890 /* Revision History: */
6891 /* */
6892 /* DD MM YYYY Author(s) Changes (Describe the changes made) */
6893 /* */
6894 /* */
6895 /*****************************************************************************/
isvcd_get_sei_mdcv_params(iv_obj_t * dec_hdl,void * pv_api_ip,void * pv_api_op)6896 WORD32 isvcd_get_sei_mdcv_params(iv_obj_t *dec_hdl, void *pv_api_ip, void *pv_api_op)
6897 {
6898 isvcd_ctl_get_sei_mdcv_params_ip_t *ps_ip;
6899 isvcd_ctl_get_sei_mdcv_params_op_t *ps_op;
6900 dec_struct_t *ps_dec;
6901 svc_dec_lyr_struct_t *ps_svc_lyr_dec;
6902 sei_mdcv_params_t *ps_sei_mdcv;
6903 WORD32 i4_count;
6904 svc_dec_ctxt_t *ps_svcd_ctxt;
6905 ps_svcd_ctxt = (svc_dec_ctxt_t *) dec_hdl->pv_codec_handle;
6906
6907 ps_ip = (isvcd_ctl_get_sei_mdcv_params_ip_t *) pv_api_ip;
6908 ps_op = (isvcd_ctl_get_sei_mdcv_params_op_t *) pv_api_op;
6909 UNUSED(ps_ip);
6910
6911 ps_svc_lyr_dec = &ps_svcd_ctxt->ps_svc_dec_lyr[ps_svcd_ctxt->u1_target_layer_id];
6912 ps_dec = &ps_svc_lyr_dec->s_dec;
6913 if(0 == ps_dec->s_sei_export.u1_sei_mdcv_params_present_flag)
6914 {
6915 ps_op->u4_error_code = ERROR_SEI_MDCV_PARAMS_NOT_FOUND;
6916 return IV_FAIL;
6917 }
6918 ps_sei_mdcv = &ps_dec->s_sei_export.s_sei_mdcv_params;
6919
6920 for(i4_count = 0; i4_count < NUM_SEI_MDCV_PRIMARIES; i4_count++)
6921 {
6922 ps_op->au2_display_primaries_x[i4_count] = ps_sei_mdcv->au2_display_primaries_x[i4_count];
6923 ps_op->au2_display_primaries_y[i4_count] = ps_sei_mdcv->au2_display_primaries_y[i4_count];
6924 }
6925
6926 ps_op->u2_white_point_x = ps_sei_mdcv->u2_white_point_x;
6927 ps_op->u2_white_point_y = ps_sei_mdcv->u2_white_point_y;
6928 ps_op->u4_max_display_mastering_luminance = ps_sei_mdcv->u4_max_display_mastering_luminance;
6929 ps_op->u4_min_display_mastering_luminance = ps_sei_mdcv->u4_min_display_mastering_luminance;
6930
6931 return IV_SUCCESS;
6932 }
6933
6934 /*****************************************************************************/
6935 /* */
6936 /* Function Name : isvcd_get_sei_cll_params */
6937 /* */
6938 /* Description : This function populates SEI cll message in */
6939 /* output structure */
6940 /* Inputs : iv_obj_t decoder handle */
6941 /* : pv_api_ip pointer to input structure */
6942 /* : pv_api_op pointer to output structure */
6943 /* Outputs : */
6944 /* Returns : returns 0; 1 with error code when CLL is not present */
6945 /* */
6946 /* Issues : none */
6947 /* */
6948 /* Revision History: */
6949 /* */
6950 /* DD MM YYYY Author(s) Changes (Describe the changes made) */
6951 /* */
6952 /* */
6953 /*****************************************************************************/
isvcd_get_sei_cll_params(iv_obj_t * dec_hdl,void * pv_api_ip,void * pv_api_op)6954 WORD32 isvcd_get_sei_cll_params(iv_obj_t *dec_hdl, void *pv_api_ip, void *pv_api_op)
6955 {
6956 isvcd_ctl_get_sei_cll_params_ip_t *ps_ip;
6957 isvcd_ctl_get_sei_cll_params_op_t *ps_op;
6958 dec_struct_t *ps_dec;
6959 svc_dec_lyr_struct_t *ps_svc_lyr_dec;
6960 svc_dec_ctxt_t *ps_svcd_ctxt;
6961 sei_cll_params_t *ps_sei_cll;
6962 ps_svcd_ctxt = (svc_dec_ctxt_t *) dec_hdl->pv_codec_handle;
6963
6964 ps_ip = (isvcd_ctl_get_sei_cll_params_ip_t *) pv_api_ip;
6965 ps_op = (isvcd_ctl_get_sei_cll_params_op_t *) pv_api_op;
6966 UNUSED(ps_ip);
6967
6968 ps_svc_lyr_dec = &ps_svcd_ctxt->ps_svc_dec_lyr[ps_svcd_ctxt->u1_target_layer_id];
6969 ps_dec = &ps_svc_lyr_dec->s_dec;
6970 if(0 == ps_dec->s_sei_export.u1_sei_cll_params_present_flag)
6971 {
6972 ps_op->u4_error_code = ERROR_SEI_CLL_PARAMS_NOT_FOUND;
6973 return IV_FAIL;
6974 }
6975 ps_sei_cll = &ps_dec->s_sei_export.s_sei_cll_params;
6976
6977 ps_op->u2_max_content_light_level = ps_sei_cll->u2_max_content_light_level;
6978 ps_op->u2_max_pic_average_light_level = ps_sei_cll->u2_max_pic_average_light_level;
6979
6980 return IV_SUCCESS;
6981 }
6982
6983 /*****************************************************************************/
6984 /* */
6985 /* Function Name : isvcd_get_sei_ave_params */
6986 /* */
6987 /* Description : This function populates SEI ave message in */
6988 /* output structure */
6989 /* Inputs : iv_obj_t decoder handle */
6990 /* : pv_api_ip pointer to input structure */
6991 /* : pv_api_op pointer to output structure */
6992 /* Outputs : */
6993 /* Returns : returns 0; 1 with error code when AVE is not present */
6994 /* */
6995 /* Issues : none */
6996 /* */
6997 /* Revision History: */
6998 /* */
6999 /* DD MM YYYY Author(s) Changes (Describe the changes made) */
7000 /* */
7001 /* */
7002 /*****************************************************************************/
isvcd_get_sei_ave_params(iv_obj_t * dec_hdl,void * pv_api_ip,void * pv_api_op)7003 WORD32 isvcd_get_sei_ave_params(iv_obj_t *dec_hdl, void *pv_api_ip, void *pv_api_op)
7004 {
7005 isvcd_ctl_get_sei_ave_params_ip_t *ps_ip;
7006 isvcd_ctl_get_sei_ave_params_op_t *ps_op;
7007 dec_struct_t *ps_dec;
7008 svc_dec_lyr_struct_t *ps_svc_lyr_dec;
7009 sei_ave_params_t *ps_sei_ave;
7010 svc_dec_ctxt_t *ps_svcd_ctxt;
7011 ps_svcd_ctxt = (svc_dec_ctxt_t *) dec_hdl->pv_codec_handle;
7012
7013 ps_ip = (isvcd_ctl_get_sei_ave_params_ip_t *) pv_api_ip;
7014 ps_op = (isvcd_ctl_get_sei_ave_params_op_t *) pv_api_op;
7015 UNUSED(ps_ip);
7016
7017 ps_svc_lyr_dec = &ps_svcd_ctxt->ps_svc_dec_lyr[ps_svcd_ctxt->u1_target_layer_id];
7018 ps_dec = &ps_svc_lyr_dec->s_dec;
7019 if(0 == ps_dec->s_sei_export.u1_sei_ave_params_present_flag)
7020 {
7021 ps_op->u4_error_code = ERROR_SEI_AVE_PARAMS_NOT_FOUND;
7022 return IV_FAIL;
7023 }
7024 ps_sei_ave = &ps_dec->s_sei_export.s_sei_ave_params;
7025
7026 ps_op->u4_ambient_illuminance = ps_sei_ave->u4_ambient_illuminance;
7027 ps_op->u2_ambient_light_x = ps_sei_ave->u2_ambient_light_x;
7028 ps_op->u2_ambient_light_y = ps_sei_ave->u2_ambient_light_y;
7029
7030 return IV_SUCCESS;
7031 }
7032
7033 /*****************************************************************************/
7034 /* */
7035 /* Function Name : isvcd_get_sei_ccv_params */
7036 /* */
7037 /* Description : This function populates SEI mdcv message in */
7038 /* output structure */
7039 /* Inputs : iv_obj_t decoder handle */
7040 /* : pv_api_ip pointer to input structure */
7041 /* : pv_api_op pointer to output structure */
7042 /* Outputs : */
7043 /* Returns : returns 0; 1 with error code when CCV is not present */
7044 /* */
7045 /* Issues : none */
7046 /* */
7047 /* Revision History: */
7048 /* */
7049 /* DD MM YYYY Author(s) Changes (Describe the changes made) */
7050 /* */
7051 /* */
7052 /*****************************************************************************/
isvcd_get_sei_ccv_params(iv_obj_t * dec_hdl,void * pv_api_ip,void * pv_api_op)7053 WORD32 isvcd_get_sei_ccv_params(iv_obj_t *dec_hdl, void *pv_api_ip, void *pv_api_op)
7054 {
7055 isvcd_ctl_get_sei_ccv_params_ip_t *ps_ip;
7056 isvcd_ctl_get_sei_ccv_params_op_t *ps_op;
7057 dec_struct_t *ps_dec;
7058 svc_dec_lyr_struct_t *ps_svc_lyr_dec;
7059 sei_ccv_params_t *ps_sei_ccv;
7060 svc_dec_ctxt_t *ps_svcd_ctxt;
7061 WORD32 i4_count;
7062 ps_svcd_ctxt = (svc_dec_ctxt_t *) dec_hdl->pv_codec_handle;
7063
7064 ps_ip = (isvcd_ctl_get_sei_ccv_params_ip_t *) pv_api_ip;
7065 ps_op = (isvcd_ctl_get_sei_ccv_params_op_t *) pv_api_op;
7066 UNUSED(ps_ip);
7067
7068 ps_svc_lyr_dec = &ps_svcd_ctxt->ps_svc_dec_lyr[ps_svcd_ctxt->u1_target_layer_id];
7069 ps_dec = &ps_svc_lyr_dec->s_dec;
7070 if(0 == ps_dec->s_sei_export.u1_sei_ccv_params_present_flag)
7071 {
7072 ps_op->u4_error_code = ERROR_SEI_CCV_PARAMS_NOT_FOUND;
7073 return IV_FAIL;
7074 }
7075 ps_sei_ccv = &ps_dec->s_sei_export.s_sei_ccv_params;
7076 ps_op->u1_ccv_cancel_flag = ps_sei_ccv->u1_ccv_cancel_flag;
7077
7078 if(0 == ps_op->u1_ccv_cancel_flag)
7079 {
7080 ps_op->u1_ccv_persistence_flag = ps_sei_ccv->u1_ccv_persistence_flag;
7081 ps_op->u1_ccv_primaries_present_flag = ps_sei_ccv->u1_ccv_primaries_present_flag;
7082 ps_op->u1_ccv_min_luminance_value_present_flag =
7083 ps_sei_ccv->u1_ccv_min_luminance_value_present_flag;
7084 ps_op->u1_ccv_max_luminance_value_present_flag =
7085 ps_sei_ccv->u1_ccv_max_luminance_value_present_flag;
7086 ps_op->u1_ccv_avg_luminance_value_present_flag =
7087 ps_sei_ccv->u1_ccv_avg_luminance_value_present_flag;
7088 ps_op->u1_ccv_reserved_zero_2bits = ps_sei_ccv->u1_ccv_reserved_zero_2bits;
7089
7090 if(1 == ps_sei_ccv->u1_ccv_primaries_present_flag)
7091 {
7092 for(i4_count = 0; i4_count < NUM_SEI_CCV_PRIMARIES; i4_count++)
7093 {
7094 ps_op->ai4_ccv_primaries_x[i4_count] = ps_sei_ccv->ai4_ccv_primaries_x[i4_count];
7095 ps_op->ai4_ccv_primaries_y[i4_count] = ps_sei_ccv->ai4_ccv_primaries_y[i4_count];
7096 }
7097 }
7098
7099 if(1 == ps_sei_ccv->u1_ccv_min_luminance_value_present_flag)
7100 {
7101 ps_op->u4_ccv_min_luminance_value = ps_sei_ccv->u4_ccv_min_luminance_value;
7102 }
7103 if(1 == ps_sei_ccv->u1_ccv_max_luminance_value_present_flag)
7104 {
7105 ps_op->u4_ccv_max_luminance_value = ps_sei_ccv->u4_ccv_max_luminance_value;
7106 }
7107 if(1 == ps_sei_ccv->u1_ccv_avg_luminance_value_present_flag)
7108 {
7109 ps_op->u4_ccv_avg_luminance_value = ps_sei_ccv->u4_ccv_avg_luminance_value;
7110 }
7111 }
7112
7113 return IV_SUCCESS;
7114 }
7115
7116 /*****************************************************************************/
7117 /* */
7118 /* Function Name : isvcd_set_num_cores */
7119 /* */
7120 /* Description : This function sets the no of cores which decoder */
7121 /* can use for decoding */
7122 /* Inputs : iv_obj_t decoder handle */
7123 /* : pv_api_ip pointer to input structure */
7124 /* : pv_api_op pointer to output structure */
7125 /* Outputs : */
7126 /* Returns : returns 0; 1 with error code */
7127 /* */
7128 /* Issues : none */
7129 /* */
7130 /* Revision History: */
7131 /* */
7132 /* DD MM YYYY Author(s) Changes (Describe the changes made) */
7133 /* */
7134 /* */
7135 /*****************************************************************************/
isvcd_set_num_cores(iv_obj_t * dec_hdl,void * pv_api_ip,void * pv_api_op)7136 WORD32 isvcd_set_num_cores(iv_obj_t *dec_hdl, void *pv_api_ip, void *pv_api_op)
7137 {
7138 UWORD8 u1_layer_id;
7139 isvcd_ctl_set_num_cores_ip_t *ps_ip;
7140 isvcd_ctl_set_num_cores_op_t *ps_op;
7141 dec_struct_t *ps_dec;
7142 svc_dec_lyr_struct_t *ps_svc_lyr_dec;
7143 svc_dec_ctxt_t *ps_svcd_ctxt;
7144 ps_svcd_ctxt = (svc_dec_ctxt_t *) dec_hdl->pv_codec_handle;
7145
7146 ps_ip = (isvcd_ctl_set_num_cores_ip_t *) pv_api_ip;
7147 ps_op = (isvcd_ctl_set_num_cores_op_t *) pv_api_op;
7148 ps_op->u4_error_code = 0;
7149 for(u1_layer_id = 0; u1_layer_id < MAX_NUM_RES_LYRS; u1_layer_id++)
7150 {
7151 ps_svc_lyr_dec = &ps_svcd_ctxt->ps_svc_dec_lyr[u1_layer_id];
7152 ps_dec = &ps_svc_lyr_dec->s_dec;
7153 ps_dec->u4_num_cores = ps_ip->u4_num_cores;
7154
7155 if(ps_dec->u4_num_cores == 1)
7156 {
7157 ps_dec->u1_separate_parse = 0;
7158 }
7159 else
7160 {
7161 ps_dec->u1_separate_parse = 1;
7162 }
7163
7164 /*using only upto three threads currently*/
7165 if(ps_dec->u4_num_cores > 3) ps_dec->u4_num_cores = 3;
7166 }
7167 return IV_SUCCESS;
7168 }
7169
7170 /*****************************************************************************/
7171 /* */
7172 /* Function Name : isvcd_fill_output_struct_from_context */
7173 /* */
7174 /* Description : This function fills the output structure from the */
7175 /* svc layer context */
7176 /* Inputs : iv_obj_t decoder handle */
7177 /* : ps_svc_lyr_dec pointer to svc layer context */
7178 /* : ps_dec_op pointer to output structure */
7179 /* Outputs : */
7180 /* Returns : */
7181 /* */
7182 /* Issues : none */
7183 /* */
7184 /* Revision History: */
7185 /* */
7186 /* DD MM YYYY Author(s) Changes (Describe the changes made) */
7187 /* */
7188 /* */
7189 /*****************************************************************************/
isvcd_fill_output_struct_from_context(svc_dec_lyr_struct_t * ps_svc_lyr_dec,ivd_video_decode_op_t * ps_dec_op)7190 void isvcd_fill_output_struct_from_context(svc_dec_lyr_struct_t *ps_svc_lyr_dec,
7191 ivd_video_decode_op_t *ps_dec_op)
7192 {
7193 dec_struct_t *ps_dec;
7194 ps_dec = &ps_svc_lyr_dec->s_dec;
7195 if((ps_dec_op->u4_error_code & 0xff) != ERROR_DYNAMIC_RESOLUTION_NOT_SUPPORTED)
7196 {
7197 ps_dec_op->u4_pic_wd = (UWORD32) ps_dec->u2_disp_width;
7198 ps_dec_op->u4_pic_ht = (UWORD32) ps_dec->u2_disp_height;
7199 }
7200 ps_dec_op->i4_reorder_depth = ps_dec->i4_reorder_depth;
7201 ps_dec_op->i4_display_index = ps_dec->i4_display_index;
7202 ps_dec_op->e_pic_type = ps_dec->i4_frametype;
7203
7204 ps_dec_op->u4_new_seq = 0;
7205 ps_dec_op->u4_output_present =
7206 (ps_svc_lyr_dec->u1_layer_identifier == TARGET_LAYER) ? ps_dec->u4_output_present : 0;
7207 ps_dec_op->u4_progressive_frame_flag = ps_dec->s_disp_op.u4_progressive_frame_flag;
7208
7209 ps_dec_op->u4_is_ref_flag = 1;
7210 if(ps_dec_op->u4_frame_decoded_flag)
7211 {
7212 if(ps_dec->ps_cur_slice->u1_nal_ref_idc == 0) ps_dec_op->u4_is_ref_flag = 0;
7213 }
7214
7215 ps_dec_op->e_output_format = ps_dec->s_disp_op.e_output_format;
7216 ps_dec_op->s_disp_frm_buf = ps_dec->s_disp_op.s_disp_frm_buf;
7217 ps_dec_op->e4_fld_type = ps_dec->s_disp_op.e4_fld_type;
7218 ps_dec_op->u4_ts = ps_dec->s_disp_op.u4_ts;
7219 ps_dec_op->u4_disp_buf_id = ps_dec->s_disp_op.u4_disp_buf_id;
7220
7221 ih264d_export_sei_params(&ps_dec_op->s_sei_decode_op, ps_dec);
7222 }
7223
7224 /*****************************************************************************/
7225 /* */
7226 /* Function Name : isvcd_api_function */
7227 /* */
7228 /* Description : */
7229 /* */
7230 /* Inputs :iv_obj_t decoder handle */
7231 /* :pv_api_ip pointer to input structure */
7232 /* :pv_api_op pointer to output structure */
7233 /* Outputs : */
7234 /* Returns : void */
7235 /* */
7236 /* Issues : none */
7237 /* */
7238 /* Revision History: */
7239 /* */
7240 /* DD MM YYYY Author(s) Changes (Describe the changes made) */
7241 /* 06 09 2021 Kishore Draft */
7242 /* */
7243 /*****************************************************************************/
isvcd_api_function(iv_obj_t * dec_hdl,void * pv_api_ip,void * pv_api_op)7244 IV_API_CALL_STATUS_T isvcd_api_function(iv_obj_t *dec_hdl, void *pv_api_ip, void *pv_api_op)
7245 {
7246 UWORD32 command;
7247 UWORD32 *pu2_ptr_cmd;
7248 UWORD32 u4_api_ret;
7249 IV_API_CALL_STATUS_T e_status;
7250 e_status = api_check_struct_sanity(dec_hdl, pv_api_ip, pv_api_op);
7251
7252 if(e_status != IV_SUCCESS)
7253 {
7254 UWORD32 *ptr_err;
7255
7256 ptr_err = (UWORD32 *) pv_api_op;
7257 UNUSED(ptr_err);
7258 H264_DEC_DEBUG_PRINT("error code = %d\n", *(ptr_err + 1));
7259 return IV_FAIL;
7260 }
7261
7262 pu2_ptr_cmd = (UWORD32 *) pv_api_ip;
7263 pu2_ptr_cmd++;
7264
7265 command = *pu2_ptr_cmd;
7266 switch(command)
7267 {
7268 case IVD_CMD_CREATE:
7269 u4_api_ret = isvcd_create(dec_hdl, (void *) pv_api_ip, (void *) pv_api_op);
7270 break;
7271 case IVD_CMD_DELETE:
7272 u4_api_ret = isvcd_delete(dec_hdl, (void *) pv_api_ip, (void *) pv_api_op);
7273 break;
7274
7275 case IVD_CMD_VIDEO_DECODE:
7276 u4_api_ret = isvcd_video_decode(dec_hdl, (void *) pv_api_ip, (void *) pv_api_op);
7277 break;
7278
7279 case IVD_CMD_GET_DISPLAY_FRAME:
7280 u4_api_ret = ih264d_get_display_frame(dec_hdl, (void *) pv_api_ip, (void *) pv_api_op);
7281
7282 break;
7283
7284 case IVD_CMD_SET_DISPLAY_FRAME:
7285 u4_api_ret = isvcd_set_display_frame(dec_hdl, (void *) pv_api_ip, (void *) pv_api_op);
7286
7287 break;
7288
7289 case IVD_CMD_REL_DISPLAY_FRAME:
7290 u4_api_ret = isvcd_rel_display_frame(dec_hdl, (void *) pv_api_ip, (void *) pv_api_op);
7291 break;
7292
7293 case IVD_CMD_VIDEO_CTL:
7294 u4_api_ret = isvcd_ctl(dec_hdl, (void *) pv_api_ip, (void *) pv_api_op);
7295 break;
7296 default:
7297 u4_api_ret = IV_FAIL;
7298 break;
7299 }
7300
7301 return u4_api_ret;
7302 }
7303