Coverage Report

Created: 2026-10-17 07:28

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