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