Coverage Report

Created: 2025-08-29 06:39

/src/libavc/encoder/ih264e_api.c
Line
Count
Source (jump to first uncovered line)
1
/******************************************************************************
2
 *
3
 * Copyright (C) 2015 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
*  ih264e_api.c
25
*
26
* @brief
27
*  Contains api function definitions for H264 encoder
28
*
29
* @author
30
*  ittiam
31
*
32
* @par List of Functions:
33
*  - api_check_struct_sanity
34
*  - ih264e_codec_update_config
35
*  - ih264e_set_default_params
36
*  - ih264e_init
37
*  - ih264e_get_num_rec
38
*  - ih264e_fill_num_mem_rec
39
*  - ih264e_init_mem_rec
40
*  - ih264e_retrieve_memrec
41
*  - ih264e_set_flush_mode
42
*  - ih264e_get_buf_info
43
*  - ih264e_set_dimensions
44
*  - ih264e_set_frame_rate
45
*  - ih264e_set_bit_rate
46
*  - ih264e_set_frame_type
47
*  - ih264e_set_qp
48
*  - ih264e_set_enc_mode
49
*  - ih264e_set_vbv_params
50
*  - ih264_set_air_params
51
*  - ih264_set_me_params
52
*  - ih264_set_ipe_params
53
*  - ih264_set_gop_params
54
*  - ih264_set_profile_params
55
*  - ih264_set_deblock_params
56
*  - ih264e_set_num_cores
57
*  - ih264e_reset
58
*  - ih264e_ctl
59
*  - ih264e_api_function
60
*
61
* @remarks
62
*  none
63
*
64
*******************************************************************************
65
*/
66
67
/*****************************************************************************/
68
/* File Includes                                                             */
69
/*****************************************************************************/
70
71
/* System Include Files */
72
#include <stdio.h>
73
#include <stddef.h>
74
#include <stdlib.h>
75
#include <string.h>
76
#include <assert.h>
77
78
/* User Include Files */
79
#include "ih264e_config.h"
80
#include "ih264_typedefs.h"
81
#include "iv2.h"
82
#include "ive2.h"
83
#include "ithread.h"
84
85
#include "ih264_debug.h"
86
#include "ih264_macros.h"
87
#include "ih264_error.h"
88
#include "ih264_defs.h"
89
#include "ih264_mem_fns.h"
90
#include "ih264_padding.h"
91
#include "ih264_structs.h"
92
#include "ih264_size_defs.h"
93
#include "ih264_trans_quant_itrans_iquant.h"
94
#include "ih264_inter_pred_filters.h"
95
#include "ih264_intra_pred_filters.h"
96
#include "ih264_deblk_edge_filters.h"
97
#include "ih264_common_tables.h"
98
#include "ih264_cavlc_tables.h"
99
#include "ih264_cabac_tables.h"
100
#include "ih264_buf_mgr.h"
101
#include "ih264_list.h"
102
#include "ih264_dpb_mgr.h"
103
#include "ih264_platform_macros.h"
104
105
#include "ime_defs.h"
106
#include "ime_distortion_metrics.h"
107
#include "ime_structs.h"
108
109
#include "irc_mem_req_and_acq.h"
110
#include "irc_cntrl_param.h"
111
#include "irc_frame_info_collector.h"
112
#include "irc_rate_control_api.h"
113
114
#include "ih264e.h"
115
#include "ih264e_error.h"
116
#include "ih264e_version.h"
117
#include "ih264e_defs.h"
118
#include "ih264e_globals.h"
119
#include "ih264e_time_stamp.h"
120
#include "ih264e_modify_frm_rate.h"
121
#include "ih264e_rate_control.h"
122
#include "ih264e_rc_mem_interface.h"
123
#include "ih264e_bitstream.h"
124
#include "ih264e_cabac_structs.h"
125
#include "ih264e_structs.h"
126
#include "ih264e_utils.h"
127
#include "ih264e_core_coding.h"
128
#include "ih264e_cavlc.h"
129
#include "ih264e_master.h"
130
#include "ih264e_fmt_conv.h"
131
#include "ih264e_platform_macros.h"
132
133
134
/*****************************************************************************/
135
/* Function Definitions                                                      */
136
/*****************************************************************************/
137
138
/**
139
*******************************************************************************
140
*
141
* @brief
142
*  Used to test arguments for corresponding API call
143
*
144
* @par Description:
145
*  For each command the arguments are validated
146
*
147
* @param[in] ps_handle
148
*  Codec handle at API level
149
*
150
* @param[in] pv_api_ip
151
*  Pointer to input structure
152
*
153
* @param[out] pv_api_op
154
*  Pointer to output structure
155
*
156
* @returns error status
157
*
158
* @remarks none
159
*
160
*******************************************************************************
161
*/
162
static IV_STATUS_T api_check_struct_sanity(iv_obj_t *ps_handle,
163
                                           void *pv_api_ip,
164
                                           void *pv_api_op)
165
183k
{
166
    /* api call */
167
183k
    WORD32 command = IV_CMD_NA;
168
169
    /* input structure expected by the api call */
170
183k
    UWORD32 *pu4_api_ip = pv_api_ip;
171
172
    /* output structure expected by the api call */
173
183k
    UWORD32 *pu4_api_op = pv_api_op;
174
175
    /* temp var */
176
183k
    WORD32 i, j;
177
178
183k
    if (NULL == pv_api_op || NULL == pv_api_ip)
179
0
    {
180
0
        return (IV_FAIL);
181
0
    }
182
183
    /* get command */
184
183k
    command = pu4_api_ip[1];
185
186
    /* set error code */
187
183k
    pu4_api_op[1] = 0;
188
189
    /* error checks on handle */
190
183k
    switch (command)
191
183k
    {
192
4.24k
        case IV_CMD_GET_NUM_MEM_REC:
193
12.7k
        case IV_CMD_FILL_NUM_MEM_REC:
194
12.7k
            break;
195
196
4.23k
        case IV_CMD_INIT:
197
4.23k
            if (ps_handle == NULL)
198
0
            {
199
0
                *(pu4_api_op + 1) |= 1 << IVE_UNSUPPORTEDPARAM;
200
0
                *(pu4_api_op + 1) |= IVE_ERR_HANDLE_NULL;
201
0
                return IV_FAIL;
202
0
            }
203
204
4.23k
            if (ps_handle->u4_size != sizeof(iv_obj_t))
205
0
            {
206
0
                *(pu4_api_op + 1) |= 1 << IVE_UNSUPPORTEDPARAM;
207
0
                *(pu4_api_op + 1) |= IVE_ERR_HANDLE_STRUCT_SIZE_INCORRECT;
208
0
                return IV_FAIL;
209
0
            }
210
4.23k
            break;
211
212
4.23k
        case IVE_CMD_QUEUE_INPUT:
213
0
        case IVE_CMD_QUEUE_OUTPUT:
214
0
        case IVE_CMD_DEQUEUE_OUTPUT:
215
0
        case IVE_CMD_GET_RECON:
216
4.22k
        case IV_CMD_RETRIEVE_MEMREC:
217
99.7k
        case IVE_CMD_VIDEO_CTL:
218
166k
        case IVE_CMD_VIDEO_ENCODE:
219
220
166k
            if (ps_handle == NULL)
221
0
            {
222
0
                *(pu4_api_op + 1) |= 1 << IVE_UNSUPPORTEDPARAM;
223
0
                *(pu4_api_op + 1) |= IVE_ERR_HANDLE_NULL;
224
0
                return IV_FAIL;
225
0
            }
226
227
166k
            if (ps_handle->u4_size != sizeof(iv_obj_t))
228
0
            {
229
0
                *(pu4_api_op + 1) |= 1 << IVE_UNSUPPORTEDPARAM;
230
0
                *(pu4_api_op + 1) |= IVE_ERR_HANDLE_STRUCT_SIZE_INCORRECT;
231
0
                return IV_FAIL;
232
0
            }
233
234
166k
            if (ps_handle->pv_fxns != ih264e_api_function)
235
0
            {
236
0
                *(pu4_api_op + 1) |= 1 << IVE_UNSUPPORTEDPARAM;
237
0
                *(pu4_api_op + 1) |= IVE_ERR_API_FUNCTION_PTR_NULL;
238
0
                return IV_FAIL;
239
0
            }
240
241
166k
            if (ps_handle->pv_codec_handle == NULL)
242
0
            {
243
0
                *(pu4_api_op + 1) |= 1 << IVE_UNSUPPORTEDPARAM;
244
0
                *(pu4_api_op + 1) |= IVE_ERR_INVALID_CODEC_HANDLE;
245
0
                return IV_FAIL;
246
0
            }
247
166k
            break;
248
249
166k
        default:
250
0
            *(pu4_api_op + 1) |= 1 << IVE_UNSUPPORTEDPARAM;
251
0
            *(pu4_api_op + 1) |= IVE_ERR_INVALID_API_CMD;
252
0
            return IV_FAIL;
253
183k
    }
254
255
    /* error checks on input output structures */
256
183k
    switch (command)
257
183k
    {
258
4.24k
        case IV_CMD_GET_NUM_MEM_REC:
259
4.24k
        {
260
4.24k
            ih264e_num_mem_rec_ip_t *ps_ip = pv_api_ip;
261
4.24k
            ih264e_num_mem_rec_op_t *ps_op = pv_api_op;
262
263
4.24k
            ps_op->s_ive_op.u4_error_code = 0;
264
265
4.24k
            if (ps_ip->s_ive_ip.u4_size != sizeof(ih264e_num_mem_rec_ip_t))
266
0
            {
267
0
                ps_op->s_ive_op.u4_error_code |= 1 << IVE_UNSUPPORTEDPARAM;
268
0
                ps_op->s_ive_op.u4_error_code |=
269
0
                                IVE_ERR_IP_GET_MEM_REC_API_STRUCT_SIZE_INCORRECT;
270
0
                return (IV_FAIL);
271
0
            }
272
273
4.24k
            if (ps_op->s_ive_op.u4_size != sizeof(ih264e_num_mem_rec_op_t))
274
0
            {
275
0
                ps_op->s_ive_op.u4_error_code |= 1 << IVE_UNSUPPORTEDPARAM;
276
0
                ps_op->s_ive_op.u4_error_code |=
277
0
                                IVE_ERR_OP_GET_MEM_REC_API_STRUCT_SIZE_INCORRECT;
278
0
                return (IV_FAIL);
279
0
            }
280
4.24k
            break;
281
4.24k
        }
282
283
8.46k
        case IV_CMD_FILL_NUM_MEM_REC:
284
8.46k
        {
285
8.46k
            ih264e_fill_mem_rec_ip_t *ps_ip = pv_api_ip;
286
8.46k
            ih264e_fill_mem_rec_op_t *ps_op = pv_api_op;
287
288
8.46k
            iv_mem_rec_t *ps_mem_rec = NULL;
289
290
8.46k
            WORD32 max_wd = ALIGN16(ps_ip->s_ive_ip.u4_max_wd);
291
8.46k
            WORD32 max_ht = ALIGN16(ps_ip->s_ive_ip.u4_max_ht);
292
293
8.46k
            ps_op->s_ive_op.u4_error_code = 0;
294
295
8.46k
            if (ps_ip->s_ive_ip.u4_size != sizeof(ih264e_fill_mem_rec_ip_t))
296
0
            {
297
0
                ps_op->s_ive_op.u4_error_code |= 1 << IVE_UNSUPPORTEDPARAM;
298
0
                ps_op->s_ive_op.u4_error_code |=
299
0
                                IVE_ERR_IP_FILL_MEM_REC_API_STRUCT_SIZE_INCORRECT;
300
0
                return (IV_FAIL);
301
0
            }
302
303
8.46k
            if (ps_op->s_ive_op.u4_size != sizeof(ih264e_fill_mem_rec_op_t))
304
0
            {
305
0
                ps_op->s_ive_op.u4_error_code |= 1 << IVE_UNSUPPORTEDPARAM;
306
0
                ps_op->s_ive_op.u4_error_code |=
307
0
                                IVE_ERR_OP_FILL_MEM_REC_API_STRUCT_SIZE_INCORRECT;
308
0
                return (IV_FAIL);
309
0
            }
310
311
8.46k
            if (max_wd < MIN_WD || max_wd > MAX_WD)
312
4
            {
313
4
                ps_op->s_ive_op.u4_error_code |= 1 << IVE_UNSUPPORTEDPARAM;
314
4
                ps_op->s_ive_op.u4_error_code |= IH264E_WIDTH_NOT_SUPPORTED;
315
4
                return (IV_FAIL);
316
4
            }
317
318
8.46k
            if (max_ht < MIN_HT || max_ht > MAX_HT)
319
5
            {
320
5
                ps_op->s_ive_op.u4_error_code |= 1 << IVE_UNSUPPORTEDPARAM;
321
5
                ps_op->s_ive_op.u4_error_code |= IH264E_HEIGHT_NOT_SUPPORTED;
322
5
                return (IV_FAIL);
323
5
            }
324
325
            /* verify number of mem rec ptr */
326
8.45k
            if (NULL == ps_ip->s_ive_ip.ps_mem_rec)
327
0
            {
328
0
                ps_op->s_ive_op.u4_error_code |= 1 << IVE_UNSUPPORTEDPARAM;
329
0
                ps_op->s_ive_op.u4_error_code |=
330
0
                                IVE_ERR_FILL_NUM_MEM_RECS_POINTER_NULL;
331
0
                return (IV_FAIL);
332
0
            }
333
334
            /* verify number of mem records */
335
8.45k
            if (ps_ip->s_ive_ip.u4_num_mem_rec != MEM_REC_CNT)
336
0
            {
337
0
                ps_op->s_ive_op.u4_error_code |= 1 << IVE_UNSUPPORTEDPARAM;
338
0
                ps_op->s_ive_op.u4_error_code |=
339
0
                                IVE_ERR_NUM_MEM_REC_NOT_SUFFICIENT;
340
0
                return IV_FAIL;
341
0
            }
342
343
            /* check mem records sizes are correct */
344
8.45k
            ps_mem_rec = ps_ip->s_ive_ip.ps_mem_rec;
345
439k
            for (i = 0; i < MEM_REC_CNT; i++)
346
431k
            {
347
431k
                if (ps_mem_rec[i].u4_size != sizeof(iv_mem_rec_t))
348
0
                {
349
0
                    ps_op->s_ive_op.u4_error_code |= 1 << IVE_UNSUPPORTEDPARAM;
350
0
                    ps_op->s_ive_op.u4_error_code |=
351
0
                                    IVE_ERR_MEM_REC_STRUCT_SIZE_INCORRECT;
352
0
                    return IV_FAIL;
353
0
                }
354
431k
            }
355
8.45k
            break;
356
8.45k
        }
357
358
8.45k
        case IV_CMD_INIT:
359
4.23k
        {
360
4.23k
            ih264e_init_ip_t *ps_ip = pv_api_ip;
361
4.23k
            ih264e_init_op_t *ps_op = pv_api_op;
362
363
4.23k
            iv_mem_rec_t *ps_mem_rec = NULL;
364
365
4.23k
            WORD32 max_wd = ALIGN16(ps_ip->s_ive_ip.u4_max_wd);
366
4.23k
            WORD32 max_ht = ALIGN16(ps_ip->s_ive_ip.u4_max_ht);
367
368
4.23k
            ps_op->s_ive_op.u4_error_code = 0;
369
370
4.23k
            if (ps_ip->s_ive_ip.u4_size != sizeof(ih264e_init_ip_t))
371
0
            {
372
0
                ps_op->s_ive_op.u4_error_code |= 1 << IVE_UNSUPPORTEDPARAM;
373
0
                ps_op->s_ive_op.u4_error_code |=
374
0
                                IVE_ERR_IP_INIT_API_STRUCT_SIZE_INCORRECT;
375
0
                return (IV_FAIL);
376
0
            }
377
378
4.23k
            if (ps_op->s_ive_op.u4_size != sizeof(ih264e_init_op_t))
379
0
            {
380
0
                ps_op->s_ive_op.u4_error_code |= 1 << IVE_UNSUPPORTEDPARAM;
381
0
                ps_op->s_ive_op.u4_error_code |=
382
0
                                IVE_ERR_OP_INIT_API_STRUCT_SIZE_INCORRECT;
383
0
                return (IV_FAIL);
384
0
            }
385
386
4.23k
            if (max_wd < MIN_WD || max_wd > MAX_WD)
387
0
            {
388
0
                ps_op->s_ive_op.u4_error_code |= 1 << IVE_UNSUPPORTEDPARAM;
389
0
                ps_op->s_ive_op.u4_error_code |= IH264E_WIDTH_NOT_SUPPORTED;
390
0
                return (IV_FAIL);
391
0
            }
392
393
4.23k
            if (max_ht < MIN_HT || max_ht > MAX_HT)
394
0
            {
395
0
                ps_op->s_ive_op.u4_error_code |= 1 << IVE_UNSUPPORTEDPARAM;
396
0
                ps_op->s_ive_op.u4_error_code |= IH264E_HEIGHT_NOT_SUPPORTED;
397
0
                return (IV_FAIL);
398
0
            }
399
400
4.23k
            if (ps_ip->s_ive_ip.u4_max_ref_cnt > MAX_REF_PIC_CNT ||
401
4.23k
                           ps_ip->s_ive_ip.u4_max_ref_cnt < MIN_REF_PIC_CNT)
402
0
            {
403
0
                ps_op->s_ive_op.u4_error_code |= 1 << IVE_UNSUPPORTEDPARAM;
404
0
                ps_op->s_ive_op.u4_error_code |= IH264E_NUM_REF_UNSUPPORTED;
405
0
                return (IV_FAIL);
406
0
            }
407
408
4.23k
            if (ps_ip->s_ive_ip.u4_max_reorder_cnt != 0)
409
0
            {
410
0
                ps_op->s_ive_op.u4_error_code |= 1 << IVE_UNSUPPORTEDPARAM;
411
0
                ps_op->s_ive_op.u4_error_code |= IH264E_NUM_REORDER_UNSUPPORTED;
412
0
                return (IV_FAIL);
413
0
            }
414
415
4.23k
            if ((ps_ip->s_ive_ip.u4_max_level != IH264_LEVEL_10)
416
4.23k
                            && (ps_ip->s_ive_ip.u4_max_level != IH264_LEVEL_1B)
417
4.23k
                            && (ps_ip->s_ive_ip.u4_max_level != IH264_LEVEL_11)
418
4.23k
                            && (ps_ip->s_ive_ip.u4_max_level != IH264_LEVEL_12)
419
4.23k
                            && (ps_ip->s_ive_ip.u4_max_level != IH264_LEVEL_13)
420
4.23k
                            && (ps_ip->s_ive_ip.u4_max_level != IH264_LEVEL_20)
421
4.23k
                            && (ps_ip->s_ive_ip.u4_max_level != IH264_LEVEL_21)
422
4.23k
                            && (ps_ip->s_ive_ip.u4_max_level != IH264_LEVEL_22)
423
4.23k
                            && (ps_ip->s_ive_ip.u4_max_level != IH264_LEVEL_30)
424
4.23k
                            && (ps_ip->s_ive_ip.u4_max_level != IH264_LEVEL_31)
425
4.23k
                            && (ps_ip->s_ive_ip.u4_max_level != IH264_LEVEL_32)
426
4.23k
                            && (ps_ip->s_ive_ip.u4_max_level != IH264_LEVEL_40)
427
4.23k
                            && (ps_ip->s_ive_ip.u4_max_level != IH264_LEVEL_41)
428
4.23k
                            && (ps_ip->s_ive_ip.u4_max_level != IH264_LEVEL_42)
429
4.23k
                            && (ps_ip->s_ive_ip.u4_max_level != IH264_LEVEL_50)
430
4.23k
                            && (ps_ip->s_ive_ip.u4_max_level != IH264_LEVEL_51))
431
0
            {
432
0
                ps_op->s_ive_op.u4_error_code |= 1 << IVE_UNSUPPORTEDPARAM;
433
0
                ps_op->s_ive_op.u4_error_code |=
434
0
                                IH264E_CODEC_LEVEL_NOT_SUPPORTED;
435
0
                return (IV_FAIL);
436
0
            }
437
438
4.23k
            if ((ps_ip->s_ive_ip.e_inp_color_fmt != IV_YUV_420P)
439
4.23k
                            && (ps_ip->s_ive_ip.e_inp_color_fmt != IV_YUV_422ILE)
440
4.23k
                            && (ps_ip->s_ive_ip.e_inp_color_fmt != IV_YUV_420SP_UV)
441
4.23k
                            && (ps_ip->s_ive_ip.e_inp_color_fmt != IV_YUV_420SP_VU))
442
0
            {
443
0
                ps_op->s_ive_op.u4_error_code |= 1 << IVE_UNSUPPORTEDPARAM;
444
0
                ps_op->s_ive_op.u4_error_code |=
445
0
                                IH264E_INPUT_CHROMA_FORMAT_NOT_SUPPORTED;
446
0
                return (IV_FAIL);
447
0
            }
448
449
4.23k
            if ((ps_ip->s_ive_ip.e_recon_color_fmt != IV_YUV_420P)
450
4.23k
                            && (ps_ip->s_ive_ip.e_recon_color_fmt != IV_YUV_420SP_UV)
451
4.23k
                            && (ps_ip->s_ive_ip.e_recon_color_fmt != IV_YUV_420SP_VU))
452
0
            {
453
0
                ps_op->s_ive_op.u4_error_code |= 1 << IVE_UNSUPPORTEDPARAM;
454
0
                ps_op->s_ive_op.u4_error_code |=
455
0
                                IH264E_RECON_CHROMA_FORMAT_NOT_SUPPORTED;
456
0
                return (IV_FAIL);
457
0
            }
458
459
4.23k
            if ((ps_ip->s_ive_ip.e_rc_mode != IVE_RC_NONE)
460
4.23k
                            && (ps_ip->s_ive_ip.e_rc_mode != IVE_RC_STORAGE)
461
4.23k
                            && (ps_ip->s_ive_ip.e_rc_mode != IVE_RC_CBR_NON_LOW_DELAY))
462
12
            {
463
12
                ps_op->s_ive_op.u4_error_code |= 1 << IVE_UNSUPPORTEDPARAM;
464
12
                ps_op->s_ive_op.u4_error_code |=
465
12
                                IH264E_RATE_CONTROL_MODE_NOT_SUPPORTED;
466
12
                return (IV_FAIL);
467
12
            }
468
469
4.22k
            if (ps_ip->s_ive_ip.u4_max_framerate > DEFAULT_MAX_FRAMERATE)
470
0
            {
471
0
                ps_op->s_ive_op.u4_error_code |= 1 << IVE_UNSUPPORTEDPARAM;
472
0
                ps_op->s_ive_op.u4_error_code |=
473
0
                                IH264E_FRAME_RATE_NOT_SUPPORTED;
474
0
                return (IV_FAIL);
475
0
            }
476
477
4.22k
            if (ps_ip->s_ive_ip.u4_max_bitrate > DEFAULT_MAX_BITRATE)
478
0
            {
479
0
                ps_op->s_ive_op.u4_error_code |= 1 << IVE_UNSUPPORTEDPARAM;
480
0
                ps_op->s_ive_op.u4_error_code |= IH264E_BITRATE_NOT_SUPPORTED;
481
0
                return (IV_FAIL);
482
0
            }
483
484
4.22k
            if (ps_ip->s_ive_ip.u4_num_bframes > MAX_NUM_BFRAMES)
485
0
            {
486
0
                ps_op->s_ive_op.u4_error_code |= 1 << IVE_UNSUPPORTEDPARAM;
487
0
                ps_op->s_ive_op.u4_error_code |= IH264E_BFRAMES_NOT_SUPPORTED;
488
0
                return (IV_FAIL);
489
0
            }
490
491
4.22k
            if (ps_ip->s_ive_ip.u4_num_bframes
492
4.22k
                            && (ps_ip->s_ive_ip.u4_max_ref_cnt < 2))
493
0
            {
494
0
                ps_op->s_ive_op.u4_error_code |= 1 << IVE_UNSUPPORTEDPARAM;
495
0
                ps_op->s_ive_op.u4_error_code |= IH264E_BFRAMES_NOT_SUPPORTED;
496
0
                return (IV_FAIL);
497
0
            }
498
499
4.22k
            if (ps_ip->s_ive_ip.e_content_type != IV_PROGRESSIVE)
500
0
            {
501
0
                ps_op->s_ive_op.u4_error_code |= 1 << IVE_UNSUPPORTEDPARAM;
502
0
                ps_op->s_ive_op.u4_error_code |=
503
0
                                IH264E_CONTENT_TYPE_NOT_SUPPORTED;
504
0
                return (IV_FAIL);
505
0
            }
506
507
4.22k
            if (ps_ip->s_ive_ip.u4_max_srch_rng_x > DEFAULT_MAX_SRCH_RANGE_X)
508
0
            {
509
0
                ps_op->s_ive_op.u4_error_code |= 1 << IVE_UNSUPPORTEDPARAM;
510
0
                ps_op->s_ive_op.u4_error_code |=
511
0
                                IH264E_HORIZONTAL_SEARCH_RANGE_NOT_SUPPORTED;
512
0
                return (IV_FAIL);
513
0
            }
514
515
4.22k
            if (ps_ip->s_ive_ip.u4_max_srch_rng_y > DEFAULT_MAX_SRCH_RANGE_Y)
516
0
            {
517
0
                ps_op->s_ive_op.u4_error_code |= 1 << IVE_UNSUPPORTEDPARAM;
518
0
                ps_op->s_ive_op.u4_error_code |=
519
0
                                IH264E_VERTICAL_SEARCH_RANGE_NOT_SUPPORTED;
520
0
                return (IV_FAIL);
521
0
            }
522
523
4.22k
            if ((ps_ip->s_ive_ip.e_slice_mode != IVE_SLICE_MODE_NONE)
524
4.22k
                            && (ps_ip->s_ive_ip.e_slice_mode != IVE_SLICE_MODE_BLOCKS))
525
0
            {
526
0
                ps_op->s_ive_op.u4_error_code |= 1 << IVE_UNSUPPORTEDPARAM;
527
0
                ps_op->s_ive_op.u4_error_code |=
528
0
                                IH264E_SLICE_TYPE_INPUT_INVALID;
529
0
                return (IV_FAIL);
530
0
            }
531
532
4.22k
            if (ps_ip->s_ive_ip.e_slice_mode == IVE_SLICE_MODE_BLOCKS)
533
0
            {
534
0
                if (ps_ip->s_ive_ip.u4_slice_param == 0
535
0
                                || ps_ip->s_ive_ip.u4_slice_param > ((UWORD32)max_ht >> 4))
536
0
                {
537
0
                    ps_op->s_ive_op.u4_error_code |= 1 << IVE_UNSUPPORTEDPARAM;
538
0
                    ps_op->s_ive_op.u4_error_code |=
539
0
                                    IH264E_SLICE_PARAM_INPUT_INVALID;
540
0
                    return (IV_FAIL);
541
0
                }
542
0
            }
543
544
4.22k
            if (NULL == ps_ip->s_ive_ip.ps_mem_rec)
545
0
            {
546
0
                ps_op->s_ive_op.u4_error_code |= 1 << IVE_UNSUPPORTEDPARAM;
547
0
                ps_op->s_ive_op.u4_error_code |=
548
0
                                IVE_ERR_FILL_NUM_MEM_RECS_POINTER_NULL;
549
0
                return (IV_FAIL);
550
0
            }
551
552
            /* verify number of mem records */
553
4.22k
            if (ps_ip->s_ive_ip.u4_num_mem_rec != MEM_REC_CNT)
554
0
            {
555
0
                ps_op->s_ive_op.u4_error_code |= 1 << IVE_UNSUPPORTEDPARAM;
556
0
                ps_op->s_ive_op.u4_error_code |=
557
0
                                IVE_ERR_NUM_MEM_REC_NOT_SUFFICIENT;
558
0
                return (IV_FAIL);
559
0
            }
560
561
4.22k
            ps_mem_rec = ps_ip->s_ive_ip.ps_mem_rec;
562
563
            /* check memrecords sizes are correct */
564
219k
            for (i = 0; i <((WORD32)ps_ip->s_ive_ip.u4_num_mem_rec); i++)
565
215k
            {
566
215k
                if (ps_mem_rec[i].u4_size != sizeof(iv_mem_rec_t))
567
0
                {
568
0
                    ps_op->s_ive_op.u4_error_code |= 1 << IVE_UNSUPPORTEDPARAM;
569
0
                    ps_op->s_ive_op.u4_error_code |=
570
0
                                    IVE_ERR_MEM_REC_STRUCT_SIZE_INCORRECT;
571
0
                    return IV_FAIL;
572
0
                }
573
574
                /* check memrecords pointers are not NULL */
575
215k
                if (ps_mem_rec[i].pv_base == NULL)
576
0
                {
577
0
                    ps_op->s_ive_op.u4_error_code |= 1 << IVE_UNSUPPORTEDPARAM;
578
0
                    ps_op->s_ive_op.u4_error_code |=
579
0
                                    IVE_ERR_MEM_REC_BASE_POINTER_NULL;
580
0
                    return IV_FAIL;
581
0
                }
582
215k
            }
583
584
            /* verify memtabs for overlapping regions */
585
4.22k
            {
586
4.22k
                void *start[MEM_REC_CNT];
587
4.22k
                void *end[MEM_REC_CNT];
588
589
4.22k
                start[0] = (ps_mem_rec[0].pv_base);
590
4.22k
                end[0] = ((UWORD8 *) ps_mem_rec[0].pv_base)
591
4.22k
                                + ps_mem_rec[0].u4_mem_size - 1;
592
593
215k
                for (i = 1; i < MEM_REC_CNT; i++)
594
211k
                {
595
                    /* This array is populated to check memtab overlap */
596
211k
                    start[i] = (ps_mem_rec[i].pv_base);
597
211k
                    end[i] = ((UWORD8 *) ps_mem_rec[i].pv_base)
598
211k
                                    + ps_mem_rec[i].u4_mem_size - 1;
599
600
5.59M
                    for (j = 0; j < i; j++)
601
5.38M
                    {
602
5.38M
                        if ((start[i] >= start[j]) && (start[i] <= end[j]))
603
0
                        {
604
0
                            ps_op->s_ive_op.u4_error_code |= 1
605
0
                                            << IVE_UNSUPPORTEDPARAM;
606
0
                            ps_op->s_ive_op.u4_error_code |=
607
0
                                            IVE_ERR_MEM_REC_OVERLAP_ERR;
608
0
                            return IV_FAIL;
609
0
                        }
610
611
5.38M
                        if ((end[i] >= start[j]) && (end[i] <= end[j]))
612
0
                        {
613
0
                            ps_op->s_ive_op.u4_error_code |= 1
614
0
                                            << IVE_UNSUPPORTEDPARAM;
615
0
                            ps_op->s_ive_op.u4_error_code |=
616
0
                                            IVE_ERR_MEM_REC_OVERLAP_ERR;
617
0
                            return IV_FAIL;
618
0
                        }
619
620
5.38M
                        if ((start[i] < start[j]) && (end[i] > end[j]))
621
0
                        {
622
0
                            ps_op->s_ive_op.u4_error_code |= 1
623
0
                                            << IVE_UNSUPPORTEDPARAM;
624
0
                            ps_op->s_ive_op.u4_error_code |=
625
0
                                            IVE_ERR_MEM_REC_OVERLAP_ERR;
626
0
                            return IV_FAIL;
627
0
                        }
628
5.38M
                    }
629
211k
                }
630
4.22k
            }
631
632
            /* re-validate mem records with init config */
633
4.22k
            {
634
                /* mem records */
635
4.22k
                iv_mem_rec_t s_mem_rec_ittiam_api[MEM_REC_CNT];
636
637
                /* api interface structs */
638
4.22k
                ih264e_fill_mem_rec_ip_t s_ip;
639
4.22k
                ih264e_fill_mem_rec_op_t s_op;
640
641
                /* error status */
642
4.22k
                IV_STATUS_T e_status;
643
644
                /* temp var */
645
4.22k
                WORD32 i;
646
647
4.22k
                s_ip.s_ive_ip.u4_size = sizeof(ih264e_fill_mem_rec_ip_t);
648
4.22k
                s_op.s_ive_op.u4_size = sizeof(ih264e_fill_mem_rec_op_t);
649
650
4.22k
                s_ip.s_ive_ip.e_cmd = IV_CMD_FILL_NUM_MEM_REC;
651
4.22k
                s_ip.s_ive_ip.ps_mem_rec = s_mem_rec_ittiam_api;
652
4.22k
                s_ip.s_ive_ip.u4_max_wd = max_wd;
653
4.22k
                s_ip.s_ive_ip.u4_max_ht = max_ht;
654
4.22k
                s_ip.s_ive_ip.u4_num_mem_rec = ps_ip->s_ive_ip.u4_num_mem_rec;
655
4.22k
                s_ip.s_ive_ip.u4_max_level = ps_ip->s_ive_ip.u4_max_level;
656
4.22k
                s_ip.s_ive_ip.u4_max_ref_cnt = ps_ip->s_ive_ip.u4_max_ref_cnt;
657
4.22k
                s_ip.s_ive_ip.u4_max_reorder_cnt =
658
4.22k
                                ps_ip->s_ive_ip.u4_max_reorder_cnt;
659
4.22k
                s_ip.s_ive_ip.e_color_format = ps_ip->s_ive_ip.e_inp_color_fmt;
660
4.22k
                s_ip.s_ive_ip.u4_max_srch_rng_x =
661
4.22k
                                ps_ip->s_ive_ip.u4_max_srch_rng_x;
662
4.22k
                s_ip.s_ive_ip.u4_max_srch_rng_y =
663
4.22k
                                ps_ip->s_ive_ip.u4_max_srch_rng_y;
664
4.22k
                s_ip.s_ive_ip.u4_keep_threads_active = ps_ip->s_ive_ip.u4_keep_threads_active;
665
666
219k
                for (i = 0; i < MEM_REC_CNT; i++)
667
215k
                {
668
215k
                    s_mem_rec_ittiam_api[i].u4_size = sizeof(iv_mem_rec_t);
669
215k
                }
670
671
                /* fill mem records */
672
4.22k
                e_status = ih264e_api_function(NULL, (void *) &s_ip,
673
4.22k
                                               (void *) &s_op);
674
675
4.22k
                if (IV_FAIL == e_status)
676
0
                {
677
0
                    ps_op->s_ive_op.u4_error_code = s_op.s_ive_op.u4_error_code;
678
0
                    return (IV_FAIL);
679
0
                }
680
681
                /* verify mem records */
682
219k
                for (i = 0; i < MEM_REC_CNT; i++)
683
215k
                {
684
215k
                    if (ps_mem_rec[i].u4_mem_size
685
215k
                                    < s_mem_rec_ittiam_api[i].u4_mem_size)
686
0
                    {
687
0
                        ps_op->s_ive_op.u4_error_code |= 1
688
0
                                        << IVE_UNSUPPORTEDPARAM;
689
0
                        ps_op->s_ive_op.u4_error_code |=
690
0
                                        IVE_ERR_MEM_REC_INSUFFICIENT_SIZE;
691
692
0
                        return IV_FAIL;
693
0
                    }
694
695
215k
                    if (ps_mem_rec[i].u4_mem_alignment
696
215k
                                    != s_mem_rec_ittiam_api[i].u4_mem_alignment)
697
0
                    {
698
0
                        ps_op->s_ive_op.u4_error_code |= 1
699
0
                                        << IVE_UNSUPPORTEDPARAM;
700
0
                        ps_op->s_ive_op.u4_error_code |=
701
0
                                        IVE_ERR_MEM_REC_ALIGNMENT_ERR;
702
703
0
                        return IV_FAIL;
704
0
                    }
705
706
215k
                    if (ps_mem_rec[i].e_mem_type
707
215k
                                    != s_mem_rec_ittiam_api[i].e_mem_type)
708
0
                    {
709
0
                        UWORD32 check = IV_SUCCESS;
710
0
                        UWORD32 diff = s_mem_rec_ittiam_api[i].e_mem_type
711
0
                                        - ps_mem_rec[i].e_mem_type;
712
713
0
                        if ((ps_mem_rec[i].e_mem_type
714
0
                                        <= IV_EXTERNAL_CACHEABLE_SCRATCH_MEM)
715
0
                                        && (s_mem_rec_ittiam_api[i].e_mem_type
716
0
                                                        >= IV_INTERNAL_NONCACHEABLE_PERSISTENT_MEM))
717
0
                        {
718
0
                            check = IV_FAIL;
719
0
                        }
720
721
0
                        if (3 != (s_mem_rec_ittiam_api[i].e_mem_type % 4))
722
0
                        {
723
                            /* It is not IV_EXTERNAL_NONCACHEABLE_PERSISTENT_MEM or
724
                             * IV_EXTERNAL_CACHEABLE_PERSISTENT_MEM */
725
726
0
                            if ((diff < 1) || (diff > 3))
727
0
                            {
728
                                /* Difference between 1 and 3 is okay for all cases other than the
729
                                 * two filtered with the MOD condition above */
730
0
                                check = IV_FAIL;
731
0
                            }
732
0
                        }
733
0
                        else
734
0
                        {
735
0
                            if (diff == 1)
736
0
                            {
737
                                /* This particular case is when codec asked for External Persistent,
738
                                 * but got Internal Scratch */
739
0
                                check = IV_FAIL;
740
0
                            }
741
0
                            if ((diff != 2) && (diff != 3))
742
0
                            {
743
0
                                check = IV_FAIL;
744
0
                            }
745
0
                        }
746
747
0
                        if (check == IV_FAIL)
748
0
                        {
749
0
                            ps_op->s_ive_op.u4_error_code |= 1
750
0
                                            << IVE_UNSUPPORTEDPARAM;
751
0
                            ps_op->s_ive_op.u4_error_code |=
752
0
                                            IVE_ERR_MEM_REC_INCORRECT_TYPE;
753
754
0
                            return IV_FAIL;
755
0
                        }
756
0
                    }
757
215k
                }
758
4.22k
            }
759
4.22k
            break;
760
4.22k
        }
761
762
4.22k
        case IVE_CMD_QUEUE_INPUT:
763
0
        case IVE_CMD_QUEUE_OUTPUT:
764
0
        case IVE_CMD_DEQUEUE_OUTPUT:
765
0
        case IVE_CMD_GET_RECON:
766
0
            break;
767
768
4.22k
        case IV_CMD_RETRIEVE_MEMREC:
769
4.22k
        {
770
4.22k
            ih264e_retrieve_mem_rec_ip_t *ps_ip = pv_api_ip;
771
4.22k
            ih264e_retrieve_mem_rec_op_t *ps_op = pv_api_op;
772
773
4.22k
            iv_mem_rec_t *ps_mem_rec = NULL;
774
775
4.22k
            ps_op->s_ive_op.u4_error_code = 0;
776
777
4.22k
            if (ps_ip->s_ive_ip.u4_size != sizeof(ih264e_retrieve_mem_rec_ip_t))
778
0
            {
779
0
                ps_op->s_ive_op.u4_error_code |= 1 << IVE_UNSUPPORTEDPARAM;
780
0
                ps_op->s_ive_op.u4_error_code |=
781
0
                                IVE_ERR_IP_RETRIEVE_MEM_REC_API_STRUCT_SIZE_INCORRECT;
782
0
                return (IV_FAIL);
783
0
            }
784
785
4.22k
            if (ps_op->s_ive_op.u4_size != sizeof(ih264e_retrieve_mem_rec_op_t))
786
0
            {
787
0
                ps_op->s_ive_op.u4_error_code |= 1 << IVE_UNSUPPORTEDPARAM;
788
0
                ps_op->s_ive_op.u4_error_code |=
789
0
                                IVE_ERR_OP_RETRIEVE_MEM_REC_API_STRUCT_SIZE_INCORRECT;
790
0
                return (IV_FAIL);
791
0
            }
792
793
4.22k
            if (NULL == ps_ip->s_ive_ip.ps_mem_rec)
794
0
            {
795
0
                ps_op->s_ive_op.u4_error_code |= 1 << IVE_UNSUPPORTEDPARAM;
796
0
                ps_op->s_ive_op.u4_error_code |=
797
0
                                IVE_ERR_FILL_NUM_MEM_RECS_POINTER_NULL;
798
0
                return (IV_FAIL);
799
0
            }
800
801
4.22k
            ps_mem_rec = ps_ip->s_ive_ip.ps_mem_rec;
802
803
            /* check memrecords sizes are correct */
804
219k
            for (i = 0; i < MEM_REC_CNT; i++)
805
215k
            {
806
215k
                if (ps_mem_rec[i].u4_size != sizeof(iv_mem_rec_t))
807
0
                {
808
0
                    ps_op->s_ive_op.u4_error_code |= 1 << IVE_UNSUPPORTEDPARAM;
809
0
                    ps_op->s_ive_op.u4_error_code |=
810
0
                                    IVE_ERR_MEM_REC_STRUCT_SIZE_INCORRECT;
811
0
                    return IV_FAIL;
812
0
                }
813
215k
            }
814
4.22k
            break;
815
4.22k
        }
816
817
66.5k
        case IVE_CMD_VIDEO_ENCODE:
818
66.5k
        {
819
66.5k
            ih264e_video_encode_ip_t *ps_ip = pv_api_ip;
820
66.5k
            ih264e_video_encode_op_t *ps_op = pv_api_op;
821
822
66.5k
            if (ps_ip->s_ive_ip.u4_size != sizeof(ih264e_video_encode_ip_t))
823
0
            {
824
0
                ps_op->s_ive_op.u4_error_code |= 1 << IVE_UNSUPPORTEDPARAM;
825
0
                ps_op->s_ive_op.u4_error_code |=
826
0
                                IVE_ERR_IP_ENCODE_API_STRUCT_SIZE_INCORRECT;
827
0
                return (IV_FAIL);
828
0
            }
829
830
66.5k
            if (ps_op->s_ive_op.u4_size != sizeof(ih264e_video_encode_op_t))
831
0
            {
832
0
                ps_op->s_ive_op.u4_error_code |= 1 << IVE_UNSUPPORTEDPARAM;
833
0
                ps_op->s_ive_op.u4_error_code |=
834
0
                                IVE_ERR_OP_ENCODE_API_STRUCT_SIZE_INCORRECT;
835
0
                return (IV_FAIL);
836
0
            }
837
838
66.5k
            break;
839
66.5k
        }
840
841
95.5k
        case IVE_CMD_VIDEO_CTL:
842
95.5k
        {
843
            /* ptr to input structure */
844
95.5k
            WORD32 *pu4_ptr_cmd = pv_api_ip;
845
846
            /* sub command */
847
95.5k
            WORD32 sub_command = pu4_ptr_cmd[2];
848
849
95.5k
            switch (sub_command)
850
95.5k
            {
851
4.22k
                case IVE_CMD_CTL_SETDEFAULT:
852
4.22k
                {
853
4.22k
                    ih264e_ctl_setdefault_ip_t *ps_ip = pv_api_ip;
854
4.22k
                    ih264e_ctl_setdefault_op_t *ps_op = pv_api_op;
855
856
4.22k
                    if (ps_ip->s_ive_ip.u4_size
857
4.22k
                                    != sizeof(ih264e_ctl_setdefault_ip_t))
858
0
                    {
859
0
                        ps_op->s_ive_op.u4_error_code |= 1
860
0
                                        << IVE_UNSUPPORTEDPARAM;
861
0
                        ps_op->s_ive_op.u4_error_code |=
862
0
                                        IVE_ERR_IP_CTL_SETDEF_API_STRUCT_SIZE_INCORRECT;
863
0
                        return IV_FAIL;
864
0
                    }
865
866
4.22k
                    if (ps_op->s_ive_op.u4_size
867
4.22k
                                    != sizeof(ih264e_ctl_setdefault_op_t))
868
0
                    {
869
0
                        ps_op->s_ive_op.u4_error_code |= 1
870
0
                                        << IVE_UNSUPPORTEDPARAM;
871
0
                        ps_op->s_ive_op.u4_error_code |=
872
0
                                        IVE_ERR_OP_CTL_SETDEF_API_STRUCT_SIZE_INCORRECT;
873
0
                        return IV_FAIL;
874
0
                    }
875
4.22k
                    break;
876
4.22k
                }
877
878
4.22k
                case IVE_CMD_CTL_GETBUFINFO:
879
4.22k
                {
880
4.22k
                    codec_t *ps_codec = (codec_t *) (ps_handle->pv_codec_handle);
881
882
4.22k
                    ih264e_ctl_getbufinfo_ip_t *ps_ip = pv_api_ip;
883
4.22k
                    ih264e_ctl_getbufinfo_op_t *ps_op = pv_api_op;
884
885
4.22k
                    if (ps_ip->s_ive_ip.u4_size
886
4.22k
                                    != sizeof(ih264e_ctl_getbufinfo_ip_t))
887
0
                    {
888
0
                        ps_op->s_ive_op.u4_error_code |= 1
889
0
                                        << IVE_UNSUPPORTEDPARAM;
890
0
                        ps_op->s_ive_op.u4_error_code |=
891
0
                                        IVE_ERR_IP_CTL_GETBUFINFO_API_STRUCT_SIZE_INCORRECT;
892
0
                        return IV_FAIL;
893
0
                    }
894
895
4.22k
                    if (ps_op->s_ive_op.u4_size
896
4.22k
                                    != sizeof(ih264e_ctl_getbufinfo_op_t))
897
0
                    {
898
0
                        ps_op->s_ive_op.u4_error_code |= 1
899
0
                                        << IVE_UNSUPPORTEDPARAM;
900
0
                        ps_op->s_ive_op.u4_error_code |=
901
0
                                        IVE_ERR_OP_CTL_GETBUFINFO_API_STRUCT_SIZE_INCORRECT;
902
0
                        return IV_FAIL;
903
0
                    }
904
905
4.22k
                    if (ps_ip->s_ive_ip.u4_max_wd < MIN_WD)
906
45
                    {
907
45
                        ps_op->s_ive_op.u4_error_code |= 1
908
45
                                        << IVE_UNSUPPORTEDPARAM;
909
45
                        ps_op->s_ive_op.u4_error_code |=
910
45
                                        IH264E_WIDTH_NOT_SUPPORTED;
911
45
                        return (IV_FAIL);
912
45
                    }
913
914
4.17k
                    if (ps_ip->s_ive_ip.u4_max_wd > ps_codec->s_cfg.u4_max_wd)
915
0
                    {
916
0
                        ps_op->s_ive_op.u4_error_code |= 1
917
0
                                        << IVE_UNSUPPORTEDPARAM;
918
0
                        ps_op->s_ive_op.u4_error_code |=
919
0
                                        IH264E_WIDTH_NOT_SUPPORTED;
920
0
                        return (IV_FAIL);
921
0
                    }
922
923
4.17k
                    if (ps_ip->s_ive_ip.u4_max_ht < MIN_HT)
924
11
                    {
925
11
                        ps_op->s_ive_op.u4_error_code |= 1
926
11
                                        << IVE_UNSUPPORTEDPARAM;
927
11
                        ps_op->s_ive_op.u4_error_code |=
928
11
                                        IH264E_HEIGHT_NOT_SUPPORTED;
929
11
                        return (IV_FAIL);
930
11
                    }
931
932
4.16k
                    if (ps_ip->s_ive_ip.u4_max_ht > ps_codec->s_cfg.u4_max_ht)
933
0
                    {
934
0
                        ps_op->s_ive_op.u4_error_code |= 1
935
0
                                        << IVE_UNSUPPORTEDPARAM;
936
0
                        ps_op->s_ive_op.u4_error_code |=
937
0
                                        IH264E_HEIGHT_NOT_SUPPORTED;
938
0
                        return (IV_FAIL);
939
0
                    }
940
941
4.16k
                    if ((ps_ip->s_ive_ip.e_inp_color_fmt != IV_YUV_420P)
942
4.16k
                                    && (ps_ip->s_ive_ip.e_inp_color_fmt != IV_YUV_422ILE)
943
4.16k
                                    && (ps_ip->s_ive_ip.e_inp_color_fmt != IV_YUV_420SP_UV)
944
4.16k
                                    && (ps_ip->s_ive_ip.e_inp_color_fmt != IV_YUV_420SP_VU))
945
0
                    {
946
0
                        ps_op->s_ive_op.u4_error_code |= 1
947
0
                                        << IVE_UNSUPPORTEDPARAM;
948
0
                        ps_op->s_ive_op.u4_error_code |=
949
0
                                        IH264E_INPUT_CHROMA_FORMAT_NOT_SUPPORTED;
950
0
                        return (IV_FAIL);
951
0
                    }
952
4.16k
                    break;
953
4.16k
                }
954
955
4.22k
                case IVE_CMD_CTL_GETVERSION:
956
4.22k
                {
957
4.22k
                    ih264e_ctl_getversioninfo_ip_t *ps_ip = pv_api_ip;
958
4.22k
                    ih264e_ctl_getversioninfo_op_t *ps_op = pv_api_op;
959
960
4.22k
                    if (ps_ip->s_ive_ip.u4_size
961
4.22k
                                    != sizeof(ih264e_ctl_getversioninfo_ip_t))
962
0
                    {
963
0
                        ps_op->s_ive_op.u4_error_code |= 1
964
0
                                        << IVE_UNSUPPORTEDPARAM;
965
0
                        ps_op->s_ive_op.u4_error_code |=
966
0
                                        IVE_ERR_IP_CTL_GETVERSION_API_STRUCT_SIZE_INCORRECT;
967
0
                        return IV_FAIL;
968
0
                    }
969
970
4.22k
                    if (ps_op->s_ive_op.u4_size
971
4.22k
                                    != sizeof(ih264e_ctl_getversioninfo_op_t))
972
0
                    {
973
0
                        ps_op->s_ive_op.u4_error_code |= 1
974
0
                                        << IVE_UNSUPPORTEDPARAM;
975
0
                        ps_op->s_ive_op.u4_error_code |=
976
0
                                        IVE_ERR_OP_CTL_GETVERSION_API_STRUCT_SIZE_INCORRECT;
977
0
                        return IV_FAIL;
978
0
                    }
979
980
4.22k
                    if (ps_ip->s_ive_ip.pu1_version == NULL)
981
0
                    {
982
0
                        ps_op->s_ive_op.u4_error_code |= 1
983
0
                                        << IVE_UNSUPPORTEDPARAM;
984
0
                        ps_op->s_ive_op.u4_error_code |=
985
0
                                        IVE_ERR_CTL_GET_VERSION_BUFFER_IS_NULL;
986
0
                        return IV_FAIL;
987
0
                    }
988
989
4.22k
                    break;
990
4.22k
                }
991
992
4.22k
                case IVE_CMD_CTL_FLUSH:
993
0
                {
994
0
                    ih264e_ctl_flush_ip_t *ps_ip = pv_api_ip;
995
0
                    ih264e_ctl_flush_op_t *ps_op = pv_api_op;
996
997
0
                    if (ps_ip->s_ive_ip.u4_size
998
0
                                    != sizeof(ih264e_ctl_flush_ip_t))
999
0
                    {
1000
0
                        ps_op->s_ive_op.u4_error_code |= 1
1001
0
                                        << IVE_UNSUPPORTEDPARAM;
1002
0
                        ps_op->s_ive_op.u4_error_code |=
1003
0
                                        IVE_ERR_IP_CTL_FLUSH_API_STRUCT_SIZE_INCORRECT;
1004
0
                        return IV_FAIL;
1005
0
                    }
1006
1007
0
                    if (ps_op->s_ive_op.u4_size
1008
0
                                    != sizeof(ih264e_ctl_flush_op_t))
1009
0
                    {
1010
0
                        ps_op->s_ive_op.u4_error_code |= 1
1011
0
                                        << IVE_UNSUPPORTEDPARAM;
1012
0
                        ps_op->s_ive_op.u4_error_code |=
1013
0
                                        IVE_ERR_OP_CTL_FLUSH_API_STRUCT_SIZE_INCORRECT;
1014
0
                        return IV_FAIL;
1015
0
                    }
1016
1017
0
                    break;
1018
0
                }
1019
1020
0
                case IVE_CMD_CTL_RESET:
1021
0
                {
1022
0
                    ih264e_ctl_reset_ip_t *ps_ip = pv_api_ip;
1023
0
                    ih264e_ctl_reset_op_t *ps_op = pv_api_op;
1024
1025
0
                    if (ps_ip->s_ive_ip.u4_size
1026
0
                                    != sizeof(ih264e_ctl_reset_ip_t))
1027
0
                    {
1028
0
                        ps_op->s_ive_op.u4_error_code |= 1
1029
0
                                        << IVE_UNSUPPORTEDPARAM;
1030
0
                        ps_op->s_ive_op.u4_error_code |=
1031
0
                                        IVE_ERR_IP_CTL_RESET_API_STRUCT_SIZE_INCORRECT;
1032
0
                        return IV_FAIL;
1033
0
                    }
1034
1035
0
                    if (ps_op->s_ive_op.u4_size
1036
0
                                    != sizeof(ih264e_ctl_reset_op_t))
1037
0
                    {
1038
0
                        ps_op->s_ive_op.u4_error_code |= 1
1039
0
                                        << IVE_UNSUPPORTEDPARAM;
1040
0
                        ps_op->s_ive_op.u4_error_code |=
1041
0
                                        IVE_ERR_OP_CTL_RESET_API_STRUCT_SIZE_INCORRECT;
1042
0
                        return IV_FAIL;
1043
0
                    }
1044
1045
0
                    break;
1046
0
                }
1047
1048
4.22k
                case IVE_CMD_CTL_SET_NUM_CORES:
1049
4.22k
                {
1050
4.22k
                    ih264e_ctl_set_num_cores_ip_t *ps_ip = pv_api_ip;
1051
4.22k
                    ih264e_ctl_set_num_cores_op_t *ps_op = pv_api_op;
1052
1053
4.22k
                    if (ps_ip->s_ive_ip.u4_size
1054
4.22k
                                    != sizeof(ih264e_ctl_set_num_cores_ip_t))
1055
0
                    {
1056
0
                        ps_op->s_ive_op.u4_error_code |= 1
1057
0
                                        << IVE_UNSUPPORTEDPARAM;
1058
0
                        ps_op->s_ive_op.u4_error_code |=
1059
0
                                        IVE_ERR_IP_CTL_SETCORES_API_STRUCT_SIZE_INCORRECT;
1060
0
                        return IV_FAIL;
1061
0
                    }
1062
1063
4.22k
                    if (ps_op->s_ive_op.u4_size
1064
4.22k
                                    != sizeof(ih264e_ctl_set_num_cores_op_t))
1065
0
                    {
1066
0
                        ps_op->s_ive_op.u4_error_code |= 1
1067
0
                                        << IVE_UNSUPPORTEDPARAM;
1068
0
                        ps_op->s_ive_op.u4_error_code |=
1069
0
                                        IVE_ERR_OP_CTL_SETCORES_API_STRUCT_SIZE_INCORRECT;
1070
0
                        return IV_FAIL;
1071
0
                    }
1072
1073
4.22k
                    if ((ps_ip->s_ive_ip.u4_num_cores < 1)
1074
4.22k
                                    || (ps_ip->s_ive_ip.u4_num_cores > MAX_NUM_CORES))
1075
0
                    {
1076
0
                        ps_op->s_ive_op.u4_error_code |= 1
1077
0
                                        << IVE_UNSUPPORTEDPARAM;
1078
0
                        ps_op->s_ive_op.u4_error_code |=
1079
0
                                        IH264E_INVALID_NUM_CORES;
1080
0
                        return IV_FAIL;
1081
0
                    }
1082
1083
4.22k
                    break;
1084
4.22k
                }
1085
1086
4.22k
                case IVE_CMD_CTL_SET_DIMENSIONS:
1087
4.22k
                {
1088
4.22k
                    codec_t *ps_codec = (codec_t *) (ps_handle->pv_codec_handle);
1089
1090
4.22k
                    ih264e_ctl_set_dimensions_ip_t *ps_ip = pv_api_ip;
1091
4.22k
                    ih264e_ctl_set_dimensions_op_t *ps_op = pv_api_op;
1092
1093
4.22k
                    if (ps_ip->s_ive_ip.u4_size
1094
4.22k
                                    != sizeof(ih264e_ctl_set_dimensions_ip_t))
1095
0
                    {
1096
0
                        ps_op->s_ive_op.u4_error_code |= 1
1097
0
                                        << IVE_UNSUPPORTEDPARAM;
1098
0
                        ps_op->s_ive_op.u4_error_code |=
1099
0
                                        IVE_ERR_IP_CTL_SETDIM_API_STRUCT_SIZE_INCORRECT;
1100
0
                        return IV_FAIL;
1101
0
                    }
1102
1103
4.22k
                    if (ps_op->s_ive_op.u4_size
1104
4.22k
                                    != sizeof(ih264e_ctl_set_dimensions_op_t))
1105
0
                    {
1106
0
                        ps_op->s_ive_op.u4_error_code |= 1
1107
0
                                        << IVE_UNSUPPORTEDPARAM;
1108
0
                        ps_op->s_ive_op.u4_error_code |=
1109
0
                                        IVE_ERR_OP_CTL_SETDIM_API_STRUCT_SIZE_INCORRECT;
1110
0
                        return IV_FAIL;
1111
0
                    }
1112
1113
4.22k
                    if (ps_ip->s_ive_ip.u4_wd < MIN_WD)
1114
45
                    {
1115
45
                        ps_op->s_ive_op.u4_error_code |= 1
1116
45
                                        << IVE_UNSUPPORTEDPARAM;
1117
45
                        ps_op->s_ive_op.u4_error_code |=
1118
45
                                        IH264E_WIDTH_NOT_SUPPORTED;
1119
45
                        return (IV_FAIL);
1120
45
                    }
1121
1122
4.17k
                    if (ps_ip->s_ive_ip.u4_wd > ps_codec->s_cfg.u4_max_wd)
1123
0
                    {
1124
0
                        ps_op->s_ive_op.u4_error_code |= 1
1125
0
                                        << IVE_UNSUPPORTEDPARAM;
1126
0
                        ps_op->s_ive_op.u4_error_code |=
1127
0
                                        IH264E_WIDTH_NOT_SUPPORTED;
1128
0
                        return (IV_FAIL);
1129
0
                    }
1130
1131
4.17k
                    if (ps_ip->s_ive_ip.u4_ht < MIN_HT)
1132
11
                    {
1133
11
                        ps_op->s_ive_op.u4_error_code |= 1
1134
11
                                        << IVE_UNSUPPORTEDPARAM;
1135
11
                        ps_op->s_ive_op.u4_error_code |=
1136
11
                                        IH264E_HEIGHT_NOT_SUPPORTED;
1137
11
                        return (IV_FAIL);
1138
11
                    }
1139
1140
4.16k
                    if (ps_ip->s_ive_ip.u4_ht > ps_codec->s_cfg.u4_max_ht)
1141
0
                    {
1142
0
                        ps_op->s_ive_op.u4_error_code |= 1
1143
0
                                        << IVE_UNSUPPORTEDPARAM;
1144
0
                        ps_op->s_ive_op.u4_error_code |=
1145
0
                                        IH264E_HEIGHT_NOT_SUPPORTED;
1146
0
                        return (IV_FAIL);
1147
0
                    }
1148
1149
4.16k
                    if(ps_ip->s_ive_ip.u4_wd & 1)
1150
47
                    {
1151
47
                        ps_op->s_ive_op.u4_error_code |= 1
1152
47
                                        << IVE_UNSUPPORTEDPARAM;
1153
47
                        ps_op->s_ive_op.u4_error_code |=
1154
47
                                        IH264E_WIDTH_NOT_SUPPORTED;
1155
47
                        return (IV_FAIL);
1156
47
                    }
1157
1158
4.12k
                    if(ps_ip->s_ive_ip.u4_ht & 1)
1159
31
                    {
1160
31
                        ps_op->s_ive_op.u4_error_code |= 1
1161
31
                                        << IVE_UNSUPPORTEDPARAM;
1162
31
                        ps_op->s_ive_op.u4_error_code |=
1163
31
                                        IH264E_HEIGHT_NOT_SUPPORTED;
1164
31
                        return (IV_FAIL);
1165
31
                    }
1166
1167
4.08k
                    break;
1168
4.12k
                }
1169
1170
5.04k
                case IVE_CMD_CTL_SET_FRAMERATE:
1171
5.04k
                {
1172
5.04k
                    ih264e_ctl_set_frame_rate_ip_t *ps_ip = pv_api_ip;
1173
5.04k
                    ih264e_ctl_set_frame_rate_op_t *ps_op = pv_api_op;
1174
1175
5.04k
                    if (ps_ip->s_ive_ip.u4_size
1176
5.04k
                                    != sizeof(ih264e_ctl_set_frame_rate_ip_t))
1177
0
                    {
1178
0
                        ps_op->s_ive_op.u4_error_code |= 1
1179
0
                                        << IVE_UNSUPPORTEDPARAM;
1180
0
                        ps_op->s_ive_op.u4_error_code |=
1181
0
                                        IVE_ERR_IP_CTL_SETFRAMERATE_API_STRUCT_SIZE_INCORRECT;
1182
0
                        return IV_FAIL;
1183
0
                    }
1184
1185
5.04k
                    if (ps_op->s_ive_op.u4_size
1186
5.04k
                                    != sizeof(ih264e_ctl_set_frame_rate_op_t))
1187
0
                    {
1188
0
                        ps_op->s_ive_op.u4_error_code |= 1
1189
0
                                        << IVE_UNSUPPORTEDPARAM;
1190
0
                        ps_op->s_ive_op.u4_error_code |=
1191
0
                                        IVE_ERR_OP_CTL_SETFRAMERATE_API_STRUCT_SIZE_INCORRECT;
1192
0
                        return IV_FAIL;
1193
0
                    }
1194
1195
5.04k
                    if (((ps_ip->s_ive_ip.u4_src_frame_rate * 1000) > DEFAULT_MAX_FRAMERATE)
1196
5.04k
                                    || ((ps_ip->s_ive_ip.u4_tgt_frame_rate * 1000) > DEFAULT_MAX_FRAMERATE))
1197
1.68k
                    {
1198
1.68k
                        ps_op->s_ive_op.u4_error_code |= 1
1199
1.68k
                                        << IVE_UNSUPPORTEDPARAM;
1200
1.68k
                        ps_op->s_ive_op.u4_error_code |=
1201
1.68k
                                        IH264E_FRAME_RATE_NOT_SUPPORTED;
1202
1.68k
                        return (IV_FAIL);
1203
1.68k
                    }
1204
1205
3.35k
                    if ((ps_ip->s_ive_ip.u4_src_frame_rate == 0)
1206
3.35k
                                    || (ps_ip->s_ive_ip.u4_tgt_frame_rate == 0))
1207
1.02k
                    {
1208
1.02k
                        ps_op->s_ive_op.u4_error_code |= 1
1209
1.02k
                                        << IVE_UNSUPPORTEDPARAM;
1210
1.02k
                        ps_op->s_ive_op.u4_error_code |=
1211
1.02k
                                        IH264E_FRAME_RATE_NOT_SUPPORTED;
1212
1.02k
                        return (IV_FAIL);
1213
1.02k
                    }
1214
1215
2.32k
                    if (ps_ip->s_ive_ip.u4_tgt_frame_rate
1216
2.32k
                                    > ps_ip->s_ive_ip.u4_src_frame_rate)
1217
0
                    {
1218
0
                        ps_op->s_ive_op.u4_error_code |= 1
1219
0
                                        << IVE_UNSUPPORTEDPARAM;
1220
0
                        ps_op->s_ive_op.u4_error_code |=
1221
0
                                        IH264E_TGT_FRAME_RATE_EXCEEDS_SRC_FRAME_RATE;
1222
0
                        return (IV_FAIL);
1223
0
                    }
1224
1225
2.32k
                    break;
1226
2.32k
                }
1227
1228
5.11k
                case IVE_CMD_CTL_SET_BITRATE:
1229
5.11k
                {
1230
5.11k
                    ih264e_ctl_set_bitrate_ip_t *ps_ip = pv_api_ip;
1231
5.11k
                    ih264e_ctl_set_bitrate_op_t *ps_op = pv_api_op;
1232
1233
5.11k
                    if (ps_ip->s_ive_ip.u4_size
1234
5.11k
                                    != sizeof(ih264e_ctl_set_bitrate_ip_t))
1235
0
                    {
1236
0
                        ps_op->s_ive_op.u4_error_code |= 1
1237
0
                                        << IVE_UNSUPPORTEDPARAM;
1238
0
                        ps_op->s_ive_op.u4_error_code |=
1239
0
                                        IVE_ERR_IP_CTL_SETBITRATE_API_STRUCT_SIZE_INCORRECT;
1240
0
                        return IV_FAIL;
1241
0
                    }
1242
1243
5.11k
                    if (ps_op->s_ive_op.u4_size
1244
5.11k
                                    != sizeof(ih264e_ctl_set_bitrate_op_t))
1245
0
                    {
1246
0
                        ps_op->s_ive_op.u4_error_code |= 1
1247
0
                                        << IVE_UNSUPPORTEDPARAM;
1248
0
                        ps_op->s_ive_op.u4_error_code |=
1249
0
                                        IVE_ERR_OP_CTL_SETBITRATE_API_STRUCT_SIZE_INCORRECT;
1250
0
                        return IV_FAIL;
1251
0
                    }
1252
1253
5.11k
                    if ((ps_ip->s_ive_ip.u4_target_bitrate > DEFAULT_MAX_BITRATE)
1254
5.11k
                                    || (ps_ip->s_ive_ip.u4_target_bitrate == 0))
1255
450
                    {
1256
450
                        ps_op->s_ive_op.u4_error_code |= 1
1257
450
                                        << IVE_UNSUPPORTEDPARAM;
1258
450
                        ps_op->s_ive_op.u4_error_code |=
1259
450
                                        IH264E_BITRATE_NOT_SUPPORTED;
1260
450
                        return (IV_FAIL);
1261
450
                    }
1262
1263
4.66k
                    break;
1264
5.11k
                }
1265
1266
4.66k
                case IVE_CMD_CTL_SET_FRAMETYPE:
1267
913
                {
1268
913
                    ih264e_ctl_set_frame_type_ip_t *ps_ip = pv_api_ip;
1269
913
                    ih264e_ctl_set_frame_type_op_t *ps_op = pv_api_op;
1270
1271
913
                    if (ps_ip->s_ive_ip.u4_size
1272
913
                                    != sizeof(ih264e_ctl_set_frame_type_ip_t))
1273
0
                    {
1274
0
                        ps_op->s_ive_op.u4_error_code |= 1
1275
0
                                        << IVE_UNSUPPORTEDPARAM;
1276
0
                        ps_op->s_ive_op.u4_error_code |=
1277
0
                                        IVE_ERR_IP_CTL_SETFRAMETYPE_API_STRUCT_SIZE_INCORRECT;
1278
0
                        return IV_FAIL;
1279
0
                    }
1280
1281
913
                    if (ps_op->s_ive_op.u4_size
1282
913
                                    != sizeof(ih264e_ctl_set_frame_type_op_t))
1283
0
                    {
1284
0
                        ps_op->s_ive_op.u4_error_code |= 1
1285
0
                                        << IVE_UNSUPPORTEDPARAM;
1286
0
                        ps_op->s_ive_op.u4_error_code |=
1287
0
                                        IVE_ERR_OP_CTL_SETFRAMETYPE_API_STRUCT_SIZE_INCORRECT;
1288
0
                        return IV_FAIL;
1289
0
                    }
1290
1291
913
                    if ((ps_ip->s_ive_ip.e_frame_type != IV_NA_FRAME)
1292
913
                                    && (ps_ip->s_ive_ip.e_frame_type != IV_I_FRAME)
1293
913
                                    && (ps_ip->s_ive_ip.e_frame_type != IV_P_FRAME)
1294
913
                                    && (ps_ip->s_ive_ip.e_frame_type != IV_IDR_FRAME))
1295
0
                    {
1296
0
                        ps_op->s_ive_op.u4_error_code |= 1
1297
0
                                        << IVE_UNSUPPORTEDPARAM;
1298
0
                        ps_op->s_ive_op.u4_error_code |=
1299
0
                                        IH264E_INVALID_FORCE_FRAME_INPUT;
1300
0
                        return IV_FAIL;
1301
0
                    }
1302
913
                    break;
1303
913
                }
1304
1305
4.22k
                case IVE_CMD_CTL_SET_ME_PARAMS:
1306
4.22k
                {
1307
4.22k
                    codec_t *ps_codec = (codec_t *) (ps_handle->pv_codec_handle);
1308
1309
4.22k
                    ih264e_ctl_set_me_params_ip_t *ps_ip = pv_api_ip;
1310
4.22k
                    ih264e_ctl_set_me_params_op_t *ps_op = pv_api_op;
1311
1312
4.22k
                    if (ps_ip->s_ive_ip.u4_size
1313
4.22k
                                    != sizeof(ih264e_ctl_set_me_params_ip_t))
1314
0
                    {
1315
0
                        ps_op->s_ive_op.u4_error_code |= 1
1316
0
                                        << IVE_UNSUPPORTEDPARAM;
1317
0
                        ps_op->s_ive_op.u4_error_code |=
1318
0
                                        IVE_ERR_IP_CTL_SETMEPARAMS_API_STRUCT_SIZE_INCORRECT;
1319
0
                        return IV_FAIL;
1320
0
                    }
1321
1322
4.22k
                    if (ps_op->s_ive_op.u4_size
1323
4.22k
                                    != sizeof(ih264e_ctl_set_me_params_op_t))
1324
0
                    {
1325
0
                        ps_op->s_ive_op.u4_error_code |= 1
1326
0
                                        << IVE_UNSUPPORTEDPARAM;
1327
0
                        ps_op->s_ive_op.u4_error_code |=
1328
0
                                        IVE_ERR_OP_CTL_SETMEPARAMS_API_STRUCT_SIZE_INCORRECT;
1329
0
                        return IV_FAIL;
1330
0
                    }
1331
1332
4.22k
                    if (ps_ip->s_ive_ip.u4_me_speed_preset != DMND_SRCH)
1333
3.13k
                    {
1334
3.13k
                        ps_op->s_ive_op.u4_error_code |= 1
1335
3.13k
                                        << IVE_UNSUPPORTEDPARAM;
1336
3.13k
                        ps_op->s_ive_op.u4_error_code |=
1337
3.13k
                                        IH264E_INVALID_ME_SPEED_PRESET;
1338
3.13k
                        return IV_FAIL;
1339
3.13k
                    }
1340
1341
1.08k
                    if ((ps_ip->s_ive_ip.u4_enable_hpel != 0)
1342
1.08k
                                    && (ps_ip->s_ive_ip.u4_enable_hpel != 1))
1343
0
                    {
1344
0
                        ps_op->s_ive_op.u4_error_code |= 1
1345
0
                                        << IVE_UNSUPPORTEDPARAM;
1346
0
                        ps_op->s_ive_op.u4_error_code |=
1347
0
                                        IH264E_INVALID_HALFPEL_OPTION;
1348
0
                        return IV_FAIL;
1349
0
                    }
1350
1351
1.08k
                    if ((ps_ip->s_ive_ip.u4_enable_qpel != 0)
1352
1.08k
                                    && (ps_ip->s_ive_ip.u4_enable_qpel != 1))
1353
0
                    {
1354
0
                        ps_op->s_ive_op.u4_error_code |= 1
1355
0
                                        << IVE_UNSUPPORTEDPARAM;
1356
0
                        ps_op->s_ive_op.u4_error_code |=
1357
0
                                        IH264E_INVALID_QPEL_OPTION;
1358
0
                        return IV_FAIL;
1359
0
                    }
1360
1361
1.08k
                    if ((ps_ip->s_ive_ip.u4_enable_fast_sad != 0)
1362
1.08k
                                    && (ps_ip->s_ive_ip.u4_enable_fast_sad != 1))
1363
0
                    {
1364
0
                        ps_op->s_ive_op.u4_error_code |= 1
1365
0
                                        << IVE_UNSUPPORTEDPARAM;
1366
0
                        ps_op->s_ive_op.u4_error_code |=
1367
0
                                        IH264E_INVALID_FAST_SAD_OPTION;
1368
0
                        return IV_FAIL;
1369
0
                    }
1370
1371
1.08k
                    if (ps_ip->s_ive_ip.u4_enable_alt_ref > 255)
1372
0
                    {
1373
0
                        ps_op->s_ive_op.u4_error_code |= 1
1374
0
                                        << IVE_UNSUPPORTEDPARAM;
1375
0
                        ps_op->s_ive_op.u4_error_code |=
1376
0
                                        IH264E_INVALID_ALT_REF_OPTION;
1377
0
                        return IV_FAIL;
1378
0
                    }
1379
1380
1.08k
                    if (ps_ip->s_ive_ip.u4_srch_rng_x
1381
1.08k
                                    > ps_codec->s_cfg.u4_max_srch_rng_x)
1382
0
                    {
1383
0
                        ps_op->s_ive_op.u4_error_code |= 1
1384
0
                                        << IVE_UNSUPPORTEDPARAM;
1385
0
                        ps_op->s_ive_op.u4_error_code |=
1386
0
                                        IH264E_HORIZONTAL_SEARCH_RANGE_NOT_SUPPORTED;
1387
0
                        return (IV_FAIL);
1388
0
                    }
1389
1390
1.08k
                    if (ps_ip->s_ive_ip.u4_srch_rng_y
1391
1.08k
                                    > ps_codec->s_cfg.u4_max_srch_rng_y)
1392
0
                    {
1393
0
                        ps_op->s_ive_op.u4_error_code |= 1
1394
0
                                        << IVE_UNSUPPORTEDPARAM;
1395
0
                        ps_op->s_ive_op.u4_error_code |=
1396
0
                                        IH264E_VERTICAL_SEARCH_RANGE_NOT_SUPPORTED;
1397
0
                        return (IV_FAIL);
1398
0
                    }
1399
1400
1.08k
                    break;
1401
1.08k
                }
1402
1403
4.22k
                case IVE_CMD_CTL_SET_IPE_PARAMS:
1404
4.22k
                {
1405
4.22k
                    ih264e_ctl_set_ipe_params_ip_t *ps_ip = pv_api_ip;
1406
4.22k
                    ih264e_ctl_set_ipe_params_op_t *ps_op = pv_api_op;
1407
1408
4.22k
                    if (ps_ip->s_ive_ip.u4_size
1409
4.22k
                                    != sizeof(ih264e_ctl_set_ipe_params_ip_t))
1410
0
                    {
1411
0
                        ps_op->s_ive_op.u4_error_code |= 1
1412
0
                                        << IVE_UNSUPPORTEDPARAM;
1413
0
                        ps_op->s_ive_op.u4_error_code |=
1414
0
                                        IVE_ERR_IP_CTL_SETIPEPARAMS_API_STRUCT_SIZE_INCORRECT;
1415
0
                        return IV_FAIL;
1416
0
                    }
1417
1418
4.22k
                    if (ps_op->s_ive_op.u4_size
1419
4.22k
                                    != sizeof(ih264e_ctl_set_ipe_params_op_t))
1420
0
                    {
1421
0
                        ps_op->s_ive_op.u4_error_code |= 1
1422
0
                                        << IVE_UNSUPPORTEDPARAM;
1423
0
                        ps_op->s_ive_op.u4_error_code |=
1424
0
                                        IVE_ERR_OP_CTL_SETIPEPARAMS_API_STRUCT_SIZE_INCORRECT;
1425
0
                        return IV_FAIL;
1426
0
                    }
1427
1428
4.22k
                    if ((ps_ip->s_ive_ip.u4_enable_intra_4x4 != 0)
1429
4.22k
                                    && (ps_ip->s_ive_ip.u4_enable_intra_4x4 != 1))
1430
0
                    {
1431
0
                        ps_op->s_ive_op.u4_error_code |= 1
1432
0
                                        << IVE_UNSUPPORTEDPARAM;
1433
0
                        ps_op->s_ive_op.u4_error_code |=
1434
0
                                        IH264E_INVALID_INTRA4x4_OPTION;
1435
0
                        return IV_FAIL;
1436
0
                    }
1437
1438
4.22k
                    if ((ps_ip->s_ive_ip.u4_constrained_intra_pred != 0)
1439
4.22k
                                    && (ps_ip->s_ive_ip.u4_constrained_intra_pred != 1))
1440
0
                    {
1441
0
                        ps_op->s_ive_op.u4_error_code |= 1
1442
0
                                        << IVE_UNSUPPORTEDPARAM;
1443
0
                        ps_op->s_ive_op.u4_error_code |=
1444
0
                                        IH264E_INVALID_CONSTRAINED_INTRA_PREDICTION_MODE;
1445
0
                        return IV_FAIL;
1446
0
                    }
1447
1448
4.22k
                    if ((ps_ip->s_ive_ip.u4_enc_speed_preset != IVE_CONFIG)
1449
4.22k
                                    && (ps_ip->s_ive_ip.u4_enc_speed_preset != IVE_SLOWEST)
1450
4.22k
                                    && (ps_ip->s_ive_ip.u4_enc_speed_preset != IVE_NORMAL)
1451
4.22k
                                    && (ps_ip->s_ive_ip.u4_enc_speed_preset != IVE_FAST)
1452
4.22k
                                    && (ps_ip->s_ive_ip.u4_enc_speed_preset != IVE_HIGH_SPEED)
1453
4.22k
                                    && (ps_ip->s_ive_ip.u4_enc_speed_preset != IVE_FASTEST))
1454
0
                    {
1455
0
                        ps_op->s_ive_op.u4_error_code |= 1
1456
0
                                        << IVE_UNSUPPORTEDPARAM;
1457
0
                        ps_op->s_ive_op.u4_error_code |=
1458
0
                                        IH264E_INVALID_ENC_SPEED_PRESET;
1459
0
                        return IV_FAIL;
1460
0
                    }
1461
1462
4.22k
                    break;
1463
4.22k
                }
1464
1465
4.22k
                case IVE_CMD_CTL_SET_GOP_PARAMS:
1466
4.22k
                {
1467
4.22k
                    ih264e_ctl_set_gop_params_ip_t *ps_ip = pv_api_ip;
1468
4.22k
                    ih264e_ctl_set_gop_params_op_t *ps_op = pv_api_op;
1469
1470
4.22k
                    if (ps_ip->s_ive_ip.u4_size
1471
4.22k
                                    != sizeof(ih264e_ctl_set_gop_params_ip_t))
1472
0
                    {
1473
0
                        ps_op->s_ive_op.u4_error_code |= 1
1474
0
                                        << IVE_UNSUPPORTEDPARAM;
1475
0
                        ps_op->s_ive_op.u4_error_code |=
1476
0
                                        IVE_ERR_IP_CTL_SETGOPPARAMS_API_STRUCT_SIZE_INCORRECT;
1477
0
                        return IV_FAIL;
1478
0
                    }
1479
1480
4.22k
                    if (ps_op->s_ive_op.u4_size
1481
4.22k
                                    != sizeof(ih264e_ctl_set_gop_params_op_t))
1482
0
                    {
1483
0
                        ps_op->s_ive_op.u4_error_code |= 1
1484
0
                                        << IVE_UNSUPPORTEDPARAM;
1485
0
                        ps_op->s_ive_op.u4_error_code |=
1486
0
                                        IVE_ERR_OP_CTL_SETGOPPARAMS_API_STRUCT_SIZE_INCORRECT;
1487
0
                        return IV_FAIL;
1488
0
                    }
1489
1490
4.22k
                    if ((ps_ip->s_ive_ip.u4_i_frm_interval < DEFAULT_MIN_INTRA_FRAME_RATE)
1491
4.22k
                                    || (ps_ip->s_ive_ip.u4_i_frm_interval > DEFAULT_MAX_INTRA_FRAME_RATE))
1492
0
                    {
1493
0
                        ps_op->s_ive_op.u4_error_code |= 1
1494
0
                                        << IVE_UNSUPPORTEDPARAM;
1495
0
                        ps_op->s_ive_op.u4_error_code |=
1496
0
                                        IH264E_INVALID_INTRA_FRAME_INTERVAL;
1497
0
                        return IV_FAIL;
1498
0
                    }
1499
1500
4.22k
                    if ((ps_ip->s_ive_ip.u4_idr_frm_interval < DEFAULT_MIN_INTRA_FRAME_RATE)
1501
4.22k
                                    || (ps_ip->s_ive_ip.u4_idr_frm_interval > DEFAULT_MAX_INTRA_FRAME_RATE))
1502
0
                    {
1503
0
                        ps_op->s_ive_op.u4_error_code |= 1
1504
0
                                        << IVE_UNSUPPORTEDPARAM;
1505
0
                        ps_op->s_ive_op.u4_error_code |=
1506
0
                                        IH264E_INVALID_IDR_FRAME_INTERVAL;
1507
0
                        return IV_FAIL;
1508
0
                    }
1509
1510
4.22k
                    if((ps_ip->s_ive_ip.u4_idr_frm_interval > ps_ip->s_ive_ip.u4_i_frm_interval) &&
1511
4.22k
                                    (ps_ip->s_ive_ip.u4_idr_frm_interval % ps_ip->s_ive_ip.u4_i_frm_interval != 0))
1512
747
                    {
1513
747
                        ps_op->s_ive_op.u4_error_code |= 1
1514
747
                                        << IVE_UNSUPPORTEDPARAM;
1515
747
                        ps_op->s_ive_op.u4_error_code |=
1516
747
                                        IH264E_INVALID_INTRA_FRAME_INTERVAL;
1517
747
                        return IV_FAIL;
1518
747
                    }
1519
1520
3.47k
                    break;
1521
4.22k
                }
1522
1523
4.22k
                case IVE_CMD_CTL_SET_DEBLOCK_PARAMS:
1524
4.22k
                {
1525
4.22k
                    ih264e_ctl_set_deblock_params_ip_t *ps_ip = pv_api_ip;
1526
4.22k
                    ih264e_ctl_set_deblock_params_op_t *ps_op = pv_api_op;
1527
1528
4.22k
                    if (ps_ip->s_ive_ip.u4_size
1529
4.22k
                                    != sizeof(ih264e_ctl_set_deblock_params_ip_t))
1530
0
                    {
1531
0
                        ps_op->s_ive_op.u4_error_code |= 1
1532
0
                                        << IVE_UNSUPPORTEDPARAM;
1533
0
                        ps_op->s_ive_op.u4_error_code |=
1534
0
                                        IVE_ERR_IP_CTL_SETDEBLKPARAMS_API_STRUCT_SIZE_INCORRECT;
1535
0
                        return IV_FAIL;
1536
0
                    }
1537
1538
4.22k
                    if (ps_op->s_ive_op.u4_size
1539
4.22k
                                    != sizeof(ih264e_ctl_set_deblock_params_op_t))
1540
0
                    {
1541
0
                        ps_op->s_ive_op.u4_error_code |= 1
1542
0
                                        << IVE_UNSUPPORTEDPARAM;
1543
0
                        ps_op->s_ive_op.u4_error_code |=
1544
0
                                        IVE_ERR_OP_CTL_SETDEBLKPARAMS_API_STRUCT_SIZE_INCORRECT;
1545
0
                        return IV_FAIL;
1546
0
                    }
1547
1548
4.22k
                    if ((ps_ip->s_ive_ip.u4_disable_deblock_level != DISABLE_DEBLK_LEVEL_0)
1549
4.22k
                                    && (ps_ip->s_ive_ip.u4_disable_deblock_level != DISABLE_DEBLK_LEVEL_2)
1550
4.22k
                                    && (ps_ip->s_ive_ip.u4_disable_deblock_level != DISABLE_DEBLK_LEVEL_3)
1551
4.22k
                                    && (ps_ip->s_ive_ip.u4_disable_deblock_level != DISABLE_DEBLK_LEVEL_4))
1552
716
                    {
1553
716
                        ps_op->s_ive_op.u4_error_code |= 1
1554
716
                                        << IVE_UNSUPPORTEDPARAM;
1555
716
                        ps_op->s_ive_op.u4_error_code |=
1556
716
                                        IH264E_INVALID_DEBLOCKING_TYPE_INPUT;
1557
716
                        return IV_FAIL;
1558
716
                    }
1559
1560
3.50k
                    break;
1561
4.22k
                }
1562
1563
4.22k
                case IVE_CMD_CTL_SET_QP:
1564
4.22k
                {
1565
4.22k
                    ih264e_ctl_set_qp_ip_t *ps_ip = pv_api_ip;
1566
4.22k
                    ih264e_ctl_set_qp_op_t *ps_op = pv_api_op;
1567
1568
4.22k
                    if (ps_ip->s_ive_ip.u4_size
1569
4.22k
                                    != sizeof(ih264e_ctl_set_qp_ip_t))
1570
0
                    {
1571
0
                        ps_op->s_ive_op.u4_error_code |= 1
1572
0
                                        << IVE_UNSUPPORTEDPARAM;
1573
0
                        ps_op->s_ive_op.u4_error_code |=
1574
0
                                        IVE_ERR_IP_CTL_SETQPPARAMS_API_STRUCT_SIZE_INCORRECT;
1575
0
                        return IV_FAIL;
1576
0
                    }
1577
1578
4.22k
                    if (ps_op->s_ive_op.u4_size
1579
4.22k
                                    != sizeof(ih264e_ctl_set_qp_op_t))
1580
0
                    {
1581
0
                        ps_op->s_ive_op.u4_error_code |= 1
1582
0
                                        << IVE_UNSUPPORTEDPARAM;
1583
0
                        ps_op->s_ive_op.u4_error_code |=
1584
0
                                        IVE_ERR_OP_CTL_SETQPPARAMS_API_STRUCT_SIZE_INCORRECT;
1585
0
                        return IV_FAIL;
1586
0
                    }
1587
1588
4.22k
                    if ((ps_ip->s_ive_ip.u4_i_qp_max > MAX_H264_QP)
1589
4.22k
                                    || (ps_ip->s_ive_ip.u4_p_qp_max > MAX_H264_QP)
1590
4.22k
                                    || (ps_ip->s_ive_ip.u4_b_qp_max > MAX_H264_QP))
1591
0
                    {
1592
0
                        ps_op->s_ive_op.u4_error_code |= 1
1593
0
                                        << IVE_UNSUPPORTEDPARAM;
1594
0
                        ps_op->s_ive_op.u4_error_code |=
1595
0
                                        IH264E_INVALID_MAX_FRAME_QP;
1596
0
                        return IV_FAIL;
1597
0
                    }
1598
1599
                    /* We donot support QP < 4 */
1600
4.22k
                    if ((ps_ip->s_ive_ip.u4_i_qp_min < 4)
1601
4.22k
                                    || (ps_ip->s_ive_ip.u4_p_qp_min < 4)
1602
4.22k
                                    || (ps_ip->s_ive_ip.u4_b_qp_min < 4)
1603
4.22k
                                    || (ps_ip->s_ive_ip.u4_i_qp_min > ps_ip->s_ive_ip.u4_i_qp_max)
1604
4.22k
                                    || (ps_ip->s_ive_ip.u4_p_qp_min > ps_ip->s_ive_ip.u4_p_qp_max)
1605
4.22k
                                    || (ps_ip->s_ive_ip.u4_b_qp_min > ps_ip->s_ive_ip.u4_b_qp_max))
1606
0
                    {
1607
0
                        ps_op->s_ive_op.u4_error_code |= 1
1608
0
                                        << IVE_UNSUPPORTEDPARAM;
1609
0
                        ps_op->s_ive_op.u4_error_code |=
1610
0
                                        IH264E_INVALID_MIN_FRAME_QP;
1611
0
                        return IV_FAIL;
1612
0
                    }
1613
1614
4.22k
                    if ((ps_ip->s_ive_ip.u4_i_qp > ps_ip->s_ive_ip.u4_i_qp_max)
1615
4.22k
                                    || (ps_ip->s_ive_ip.u4_p_qp > ps_ip->s_ive_ip.u4_p_qp_max)
1616
4.22k
                                    || (ps_ip->s_ive_ip.u4_b_qp > ps_ip->s_ive_ip.u4_b_qp_max)
1617
4.22k
                                    || (ps_ip->s_ive_ip.u4_i_qp < ps_ip->s_ive_ip.u4_i_qp_min)
1618
4.22k
                                    || (ps_ip->s_ive_ip.u4_p_qp < ps_ip->s_ive_ip.u4_p_qp_min)
1619
4.22k
                                    || (ps_ip->s_ive_ip.u4_b_qp < ps_ip->s_ive_ip.u4_b_qp_min))
1620
0
                    {
1621
0
                        ps_op->s_ive_op.u4_error_code |= 1
1622
0
                                        << IVE_UNSUPPORTEDPARAM;
1623
0
                        ps_op->s_ive_op.u4_error_code |= IH264E_INVALID_INIT_QP;
1624
0
                        return IV_FAIL;
1625
0
                    }
1626
1627
4.22k
                    break;
1628
4.22k
                }
1629
1630
4.22k
                case IVE_CMD_CTL_SET_VUI_PARAMS:
1631
4.22k
                {
1632
4.22k
                    ih264e_vui_ip_t *ps_ip = pv_api_ip;
1633
4.22k
                    ih264e_vui_op_t *ps_op = pv_api_op;
1634
1635
4.22k
                    if(ps_ip->u4_size != sizeof(ih264e_vui_ip_t))
1636
0
                    {
1637
0
                        ps_op->u4_error_code |= 1 << IVE_UNSUPPORTEDPARAM;
1638
0
                        ps_op->u4_error_code |=
1639
0
                                        IVE_ERR_IP_CTL_SET_VUI_STRUCT_SIZE_INCORRECT;
1640
0
                        return IV_FAIL;
1641
0
                    }
1642
1643
4.22k
                    if(ps_op->u4_size != sizeof(ih264e_vui_op_t))
1644
0
                    {
1645
0
                        ps_op->u4_error_code |= 1 << IVE_UNSUPPORTEDPARAM;
1646
0
                        ps_op->u4_error_code |=
1647
0
                                        IVE_ERR_OP_CTL_SET_VUI_STRUCT_SIZE_INCORRECT;
1648
0
                        return IV_FAIL;
1649
0
                    }
1650
1651
4.22k
                    break;
1652
4.22k
                }
1653
1654
4.22k
                case IVE_CMD_CTL_SET_SEI_MDCV_PARAMS:
1655
4.22k
                {
1656
4.22k
                    ih264e_ctl_set_sei_mdcv_params_ip_t *ps_ip = pv_api_ip;
1657
4.22k
                    ih264e_ctl_set_sei_mdcv_params_op_t *ps_op = pv_api_op;
1658
1659
4.22k
                    if(ps_ip->u4_size != sizeof(ih264e_ctl_set_sei_mdcv_params_ip_t))
1660
0
                    {
1661
0
                        ps_op->u4_error_code |= 1 << IVE_UNSUPPORTEDPARAM;
1662
0
                        ps_op->u4_error_code |=
1663
0
                                IVE_ERR_IP_CTL_SET_SEI_MDCV_STRUCT_SIZE_INCORRECT;
1664
0
                        return IV_FAIL;
1665
0
                    }
1666
1667
4.22k
                    if(ps_op->u4_size != sizeof(ih264e_ctl_set_sei_mdcv_params_op_t))
1668
0
                    {
1669
0
                        ps_op->u4_error_code |= 1 << IVE_UNSUPPORTEDPARAM;
1670
0
                        ps_op->u4_error_code |=
1671
0
                                IVE_ERR_OP_CTL_SET_SEI_MDCV_STRUCT_SIZE_INCORRECT;
1672
0
                        return IV_FAIL;
1673
0
                    }
1674
1675
4.22k
                    if((ps_ip->u1_sei_mdcv_params_present_flag != 0)
1676
4.22k
                            && (ps_ip->u1_sei_mdcv_params_present_flag) != 1)
1677
0
                    {
1678
0
                        ps_op->u4_error_code |= 1 << IVE_UNSUPPORTEDPARAM;
1679
0
                        ps_op->u4_error_code |=
1680
0
                                IH264E_INVALID_SEI_MDCV_PARAMS;
1681
0
                        return IV_FAIL;
1682
0
                    }
1683
1684
4.22k
                    if(1 == ps_ip->u1_sei_mdcv_params_present_flag)
1685
1.83k
                    {
1686
                        /* Check values for u2_display_primaries_x and u2_display_primaries_y */
1687
7.33k
                        for(i = 0; i < 3; i++)
1688
5.50k
                        {
1689
5.50k
                            if((ps_ip->au2_display_primaries_x[i] >
1690
5.50k
                                                    DISPLAY_PRIMARIES_X_UPPER_LIMIT) ||
1691
5.50k
                               (ps_ip->au2_display_primaries_x[i] <
1692
5.50k
                                                    DISPLAY_PRIMARIES_X_LOWER_LIMIT) ||
1693
5.50k
                               ((ps_ip->au2_display_primaries_x[i] %
1694
5.50k
                                                    DISPLAY_PRIMARIES_X_DIVISION_FACTOR) != 0))
1695
0
                            {
1696
0
                                ps_op->u4_error_code |= 1 << IVE_UNSUPPORTEDPARAM;
1697
0
                                ps_op->u4_error_code |=
1698
0
                                        IH264E_INVALID_SEI_MDCV_PARAMS;
1699
0
                                return IV_FAIL;
1700
0
                            }
1701
1702
5.50k
                            if((ps_ip->au2_display_primaries_y[i] >
1703
5.50k
                                                    DISPLAY_PRIMARIES_Y_UPPER_LIMIT) ||
1704
5.50k
                               (ps_ip->au2_display_primaries_y[i] <
1705
5.50k
                                                    DISPLAY_PRIMARIES_Y_LOWER_LIMIT) ||
1706
5.50k
                               ((ps_ip->au2_display_primaries_y[i] %
1707
5.50k
                                                    DISPLAY_PRIMARIES_Y_DIVISION_FACTOR) != 0))
1708
0
                            {
1709
0
                                ps_op->u4_error_code |= 1 << IVE_UNSUPPORTEDPARAM;
1710
0
                                ps_op->u4_error_code |=
1711
0
                                        IH264E_INVALID_SEI_MDCV_PARAMS;
1712
0
                                return IV_FAIL;
1713
0
                            }
1714
5.50k
                        }
1715
1716
1.83k
                        if((ps_ip->u2_white_point_x > WHITE_POINT_X_UPPER_LIMIT) ||
1717
1.83k
                           (ps_ip->u2_white_point_x < WHITE_POINT_X_LOWER_LIMIT) ||
1718
1.83k
                           ((ps_ip->u2_white_point_x % WHITE_POINT_X_DIVISION_FACTOR) != 0))
1719
0
                        {
1720
0
                            ps_op->u4_error_code |= 1 << IVE_UNSUPPORTEDPARAM;
1721
0
                            ps_op->u4_error_code |=
1722
0
                                    IH264E_INVALID_SEI_MDCV_PARAMS;
1723
0
                            return IV_FAIL;
1724
0
                        }
1725
1726
1.83k
                        if((ps_ip->u2_white_point_y > WHITE_POINT_Y_UPPER_LIMIT) ||
1727
1.83k
                           (ps_ip->u2_white_point_y < WHITE_POINT_Y_LOWER_LIMIT) ||
1728
1.83k
                           ((ps_ip->u2_white_point_y % WHITE_POINT_Y_DIVISION_FACTOR) != 0))
1729
0
                        {
1730
0
                            ps_op->u4_error_code |= 1 << IVE_UNSUPPORTEDPARAM;
1731
0
                            ps_op->u4_error_code |=
1732
0
                                    IH264E_INVALID_SEI_MDCV_PARAMS;
1733
0
                            return IV_FAIL;
1734
0
                        }
1735
1736
1.83k
                        if((ps_ip->u4_max_display_mastering_luminance >
1737
1.83k
                                        MAX_DISPLAY_MASTERING_LUMINANCE_UPPER_LIMIT) ||
1738
1.83k
                           (ps_ip->u4_max_display_mastering_luminance <
1739
1.83k
                                        MAX_DISPLAY_MASTERING_LUMINANCE_LOWER_LIMIT) ||
1740
1.83k
                           ((ps_ip->u4_max_display_mastering_luminance %
1741
1.83k
                                        MAX_DISPLAY_MASTERING_LUMINANCE_DIVISION_FACTOR) != 0))
1742
0
                        {
1743
0
                            ps_op->u4_error_code |= 1 << IVE_UNSUPPORTEDPARAM;
1744
0
                            ps_op->u4_error_code |=
1745
0
                                    IH264E_INVALID_SEI_MDCV_PARAMS;
1746
0
                            return IV_FAIL;
1747
0
                        }
1748
1749
1.83k
                        if((ps_ip->u4_min_display_mastering_luminance >
1750
1.83k
                                        MIN_DISPLAY_MASTERING_LUMINANCE_UPPER_LIMIT ) ||
1751
1.83k
                           (ps_ip->u4_min_display_mastering_luminance <
1752
1.83k
                                        MIN_DISPLAY_MASTERING_LUMINANCE_LOWER_LIMIT))
1753
0
                        {
1754
0
                            ps_op->u4_error_code |= 1 << IVE_UNSUPPORTEDPARAM;
1755
0
                            ps_op->u4_error_code |=
1756
0
                                    IH264E_INVALID_SEI_MDCV_PARAMS;
1757
0
                            return IV_FAIL;
1758
0
                        }
1759
1760
1.83k
                        if(ps_ip->u4_max_display_mastering_luminance <=
1761
1.83k
                                ps_ip->u4_min_display_mastering_luminance)
1762
0
                        {
1763
0
                            ps_op->u4_error_code |= 1 << IVE_UNSUPPORTEDPARAM;
1764
0
                            ps_op->u4_error_code |=
1765
0
                                    IH264E_INVALID_SEI_MDCV_PARAMS;
1766
0
                            return IV_FAIL;
1767
0
                        }
1768
1.83k
                    }
1769
4.22k
                    break;
1770
4.22k
                }
1771
1772
4.22k
                case IVE_CMD_CTL_SET_SEI_CLL_PARAMS:
1773
4.22k
                {
1774
4.22k
                    ih264e_ctl_set_sei_cll_params_ip_t *ps_ip = pv_api_ip;
1775
4.22k
                    ih264e_ctl_set_sei_cll_params_op_t *ps_op = pv_api_op;
1776
1777
4.22k
                    if(ps_ip->u4_size != sizeof(ih264e_ctl_set_sei_cll_params_ip_t))
1778
0
                    {
1779
0
                        ps_op->u4_error_code |= 1 << IVE_UNSUPPORTEDPARAM;
1780
0
                        ps_op->u4_error_code |=
1781
0
                                IVE_ERR_IP_CTL_SET_SEI_CLL_STRUCT_SIZE_INCORRECT;
1782
0
                        return IV_FAIL;
1783
0
                    }
1784
1785
4.22k
                    if(ps_op->u4_size != sizeof(ih264e_ctl_set_sei_cll_params_op_t))
1786
0
                    {
1787
0
                        ps_op->u4_error_code |= 1 << IVE_UNSUPPORTEDPARAM;
1788
0
                        ps_op->u4_error_code |=
1789
0
                                IVE_ERR_OP_CTL_SET_SEI_CLL_STRUCT_SIZE_INCORRECT;
1790
0
                        return IV_FAIL;
1791
0
                    }
1792
1793
4.22k
                    if((ps_ip->u1_sei_cll_params_present_flag != 0)
1794
4.22k
                            && (ps_ip->u1_sei_cll_params_present_flag != 1))
1795
0
                    {
1796
0
                        ps_op->u4_error_code |= 1 << IVE_UNSUPPORTEDPARAM;
1797
0
                        ps_op->u4_error_code |=
1798
0
                                IH264E_INVALID_SEI_CLL_PARAMS;
1799
0
                        return IV_FAIL;
1800
0
                    }
1801
4.22k
                    break;
1802
4.22k
                }
1803
1804
4.22k
                case IVE_CMD_CTL_SET_SEI_AVE_PARAMS:
1805
4.22k
                {
1806
4.22k
                    ih264e_ctl_set_sei_ave_params_ip_t *ps_ip = pv_api_ip;
1807
4.22k
                    ih264e_ctl_set_sei_ave_params_op_t *ps_op = pv_api_op;
1808
1809
4.22k
                    if(ps_ip->u4_size != sizeof(ih264e_ctl_set_sei_ave_params_ip_t))
1810
0
                    {
1811
0
                        ps_op->u4_error_code |= 1 << IVE_UNSUPPORTEDPARAM;
1812
0
                        ps_op->u4_error_code |=
1813
0
                                IVE_ERR_IP_CTL_SET_SEI_AVE_STRUCT_SIZE_INCORRECT;
1814
0
                        return IV_FAIL;
1815
0
                    }
1816
1817
4.22k
                    if(ps_op->u4_size != sizeof(ih264e_ctl_set_sei_ave_params_op_t))
1818
0
                    {
1819
0
                        ps_op->u4_error_code |= 1 << IVE_UNSUPPORTEDPARAM;
1820
0
                        ps_op->u4_error_code |=
1821
0
                                IVE_ERR_OP_CTL_SET_SEI_AVE_STRUCT_SIZE_INCORRECT;
1822
0
                        return IV_FAIL;
1823
0
                    }
1824
1825
4.22k
                    if((ps_ip->u1_sei_ave_params_present_flag != 0)
1826
4.22k
                            && (ps_ip->u1_sei_ave_params_present_flag != 1))
1827
0
                    {
1828
0
                        ps_op->u4_error_code |= 1 << IVE_UNSUPPORTEDPARAM;
1829
0
                        ps_op->u4_error_code |=
1830
0
                                IH264E_INVALID_SEI_AVE_PARAMS;
1831
0
                        return IV_FAIL;
1832
0
                    }
1833
1834
4.22k
                    if(1 == ps_ip->u1_sei_ave_params_present_flag)
1835
1.59k
                    {
1836
1.59k
                        if((0 == ps_ip->u4_ambient_illuminance))
1837
0
                        {
1838
0
                            ps_op->u4_error_code |= 1 << IVE_UNSUPPORTEDPARAM;
1839
0
                            ps_op->u4_error_code |=
1840
0
                                    IH264E_INVALID_SEI_AVE_PARAMS;
1841
0
                            return IV_FAIL;
1842
0
                        }
1843
1844
1.59k
                        if(ps_ip->u2_ambient_light_x > AMBIENT_LIGHT_X_UPPER_LIMIT)
1845
0
                        {
1846
0
                            ps_op->u4_error_code |= 1 << IVE_UNSUPPORTEDPARAM;
1847
0
                            ps_op->u4_error_code |=
1848
0
                                    IH264E_INVALID_SEI_AVE_PARAMS;
1849
0
                            return IV_FAIL;
1850
0
                        }
1851
1852
1.59k
                        if(ps_ip->u2_ambient_light_y > AMBIENT_LIGHT_Y_UPPER_LIMIT)
1853
0
                        {
1854
0
                            ps_op->u4_error_code |= 1 << IVE_UNSUPPORTEDPARAM;
1855
0
                            ps_op->u4_error_code |=
1856
0
                                    IH264E_INVALID_SEI_AVE_PARAMS;
1857
0
                            return IV_FAIL;
1858
0
                        }
1859
1.59k
                    }
1860
4.22k
                    break;
1861
4.22k
                }
1862
1863
4.22k
                case IVE_CMD_CTL_SET_SEI_CCV_PARAMS:
1864
4.22k
                {
1865
4.22k
                    ih264e_ctl_set_sei_ccv_params_ip_t *ps_ip = pv_api_ip;
1866
4.22k
                    ih264e_ctl_set_sei_ccv_params_op_t *ps_op = pv_api_op;
1867
1868
4.22k
                    if(ps_ip->u4_size != sizeof(ih264e_ctl_set_sei_ccv_params_ip_t))
1869
0
                    {
1870
0
                        ps_op->u4_error_code |= 1 << IVE_UNSUPPORTEDPARAM;
1871
0
                        ps_op->u4_error_code |=
1872
0
                                IVE_ERR_IP_CTL_SET_SEI_CCV_STRUCT_SIZE_INCORRECT;
1873
0
                        return IV_FAIL;
1874
0
                    }
1875
1876
4.22k
                    if(ps_op->u4_size != sizeof(ih264e_ctl_set_sei_ccv_params_op_t))
1877
0
                    {
1878
0
                        ps_op->u4_error_code |= 1 << IVE_UNSUPPORTEDPARAM;
1879
0
                        ps_op->u4_error_code |=
1880
0
                                IVE_ERR_OP_CTL_SET_SEI_CCV_STRUCT_SIZE_INCORRECT;
1881
0
                        return IV_FAIL;
1882
0
                    }
1883
1884
4.22k
                    if((ps_ip->u1_sei_ccv_params_present_flag != 0)
1885
4.22k
                            && (ps_ip->u1_sei_ccv_params_present_flag != 1))
1886
0
                    {
1887
0
                        ps_op->u4_error_code |= 1 << IVE_UNSUPPORTEDPARAM;
1888
0
                        ps_op->u4_error_code |=
1889
0
                                IH264E_INVALID_SEI_CCV_PARAMS;
1890
0
                        return IV_FAIL;
1891
0
                    }
1892
1893
1894
4.22k
                    if(1 == ps_ip->u1_sei_ccv_params_present_flag)
1895
1.40k
                    {
1896
1.40k
                        if((ps_ip->u1_ccv_cancel_flag != 0)
1897
1.40k
                                && (ps_ip->u1_ccv_cancel_flag != 1))
1898
0
                        {
1899
0
                            ps_op->u4_error_code |= 1 << IVE_UNSUPPORTEDPARAM;
1900
0
                            ps_op->u4_error_code |=
1901
0
                                    IH264E_INVALID_SEI_CCV_PARAMS;
1902
0
                            return IV_FAIL;
1903
0
                        }
1904
1905
1.40k
                        if(0 == ps_ip->u1_ccv_cancel_flag)
1906
1.40k
                        {
1907
1.40k
                            if((ps_ip->u1_ccv_persistence_flag != 0)
1908
1.40k
                                    && (ps_ip->u1_ccv_persistence_flag != 1))
1909
0
                            {
1910
0
                                ps_op->u4_error_code |= 1 << IVE_UNSUPPORTEDPARAM;
1911
0
                                ps_op->u4_error_code |=
1912
0
                                        IH264E_INVALID_SEI_CCV_PARAMS;
1913
0
                                return IV_FAIL;
1914
0
                            }
1915
1.40k
                            if((ps_ip->u1_ccv_primaries_present_flag != 0)
1916
1.40k
                                    && (ps_ip->u1_ccv_primaries_present_flag != 1))
1917
0
                            {
1918
0
                                ps_op->u4_error_code |= 1 << IVE_UNSUPPORTEDPARAM;
1919
0
                                ps_op->u4_error_code |=
1920
0
                                        IH264E_INVALID_SEI_CCV_PARAMS;
1921
0
                                return IV_FAIL;
1922
0
                            }
1923
1.40k
                            if((ps_ip->u1_ccv_min_luminance_value_present_flag != 0)
1924
1.40k
                                    && (ps_ip->u1_ccv_min_luminance_value_present_flag != 1))
1925
0
                            {
1926
0
                                ps_op->u4_error_code |= 1 << IVE_UNSUPPORTEDPARAM;
1927
0
                                ps_op->u4_error_code |=
1928
0
                                        IH264E_INVALID_SEI_CCV_PARAMS;
1929
0
                                return IV_FAIL;
1930
0
                            }
1931
1.40k
                            if((ps_ip->u1_ccv_max_luminance_value_present_flag != 0)
1932
1.40k
                                    && (ps_ip->u1_ccv_max_luminance_value_present_flag != 1))
1933
0
                            {
1934
0
                                ps_op->u4_error_code |= 1 << IVE_UNSUPPORTEDPARAM;
1935
0
                                ps_op->u4_error_code |=
1936
0
                                        IH264E_INVALID_SEI_CCV_PARAMS;
1937
0
                                return IV_FAIL;
1938
0
                            }
1939
1.40k
                            if((ps_ip->u1_ccv_avg_luminance_value_present_flag != 0)
1940
1.40k
                                    && (ps_ip->u1_ccv_avg_luminance_value_present_flag != 1))
1941
0
                            {
1942
0
                                ps_op->u4_error_code |= 1 << IVE_UNSUPPORTEDPARAM;
1943
0
                                ps_op->u4_error_code |=
1944
0
                                        IH264E_INVALID_SEI_CCV_PARAMS;
1945
0
                                return IV_FAIL;
1946
0
                            }
1947
1.40k
                            if((ps_ip->u1_ccv_primaries_present_flag == 0)
1948
1.40k
                                    && (ps_ip->u1_ccv_min_luminance_value_present_flag == 0)
1949
1.40k
                                    && (ps_ip->u1_ccv_max_luminance_value_present_flag == 0)
1950
1.40k
                                    && (ps_ip->u1_ccv_avg_luminance_value_present_flag == 0))
1951
0
                            {
1952
0
                                ps_op->u4_error_code |= 1 << IVE_UNSUPPORTEDPARAM;
1953
0
                                ps_op->u4_error_code |=
1954
0
                                        IH264E_INVALID_SEI_CCV_PARAMS;
1955
0
                                return IV_FAIL;
1956
0
                            }
1957
1958
1.40k
                            if((ps_ip->u1_ccv_reserved_zero_2bits != 0))
1959
0
                            {
1960
0
                                ps_op->u4_error_code |= 1 << IVE_UNSUPPORTEDPARAM;
1961
0
                                ps_op->u4_error_code |=
1962
0
                                        IH264E_INVALID_SEI_CCV_PARAMS;
1963
0
                                return IV_FAIL;
1964
0
                            }
1965
1966
1.40k
                            if(1 == ps_ip->u1_ccv_primaries_present_flag)
1967
1.40k
                            {
1968
5.61k
                                for(i = 0; i < 3; i++)
1969
4.21k
                                {
1970
4.21k
                                    if((ps_ip->ai4_ccv_primaries_x[i] >
1971
4.21k
                                                        CCV_PRIMARIES_X_UPPER_LIMIT) ||
1972
4.21k
                                       (ps_ip->ai4_ccv_primaries_x[i] <
1973
4.21k
                                                        CCV_PRIMARIES_X_LOWER_LIMIT))
1974
0
                                    {
1975
0
                                        ps_op->u4_error_code |= 1 << IVE_UNSUPPORTEDPARAM;
1976
0
                                        ps_op->u4_error_code |=
1977
0
                                                IH264E_INVALID_SEI_CCV_PARAMS;
1978
0
                                        return IV_FAIL;
1979
0
                                    }
1980
1981
4.21k
                                    if((ps_ip->ai4_ccv_primaries_y[i] >
1982
4.21k
                                                        CCV_PRIMARIES_Y_UPPER_LIMIT) ||
1983
4.21k
                                       (ps_ip->ai4_ccv_primaries_y[i] <
1984
4.21k
                                                        CCV_PRIMARIES_Y_LOWER_LIMIT))
1985
0
                                    {
1986
0
                                        ps_op->u4_error_code |= 1 << IVE_UNSUPPORTEDPARAM;
1987
0
                                        ps_op->u4_error_code |=
1988
0
                                                IH264E_INVALID_SEI_CCV_PARAMS;
1989
0
                                        return IV_FAIL;
1990
0
                                    }
1991
4.21k
                                }
1992
1.40k
                            }
1993
1994
1.40k
                            if((1 == ps_ip->u1_ccv_min_luminance_value_present_flag) &&
1995
1.40k
                                    (1 == ps_ip->u1_ccv_avg_luminance_value_present_flag))
1996
1.40k
                            {
1997
1.40k
                                if((ps_ip->u4_ccv_avg_luminance_value <
1998
1.40k
                                                    ps_ip->u4_ccv_min_luminance_value))
1999
0
                                {
2000
0
                                    ps_op->u4_error_code |= 1 << IVE_UNSUPPORTEDPARAM;
2001
0
                                    ps_op->u4_error_code |=
2002
0
                                            IH264E_INVALID_SEI_CCV_PARAMS;
2003
0
                                    return IV_FAIL;
2004
0
                                }
2005
1.40k
                            }
2006
2007
1.40k
                            if((1 == ps_ip->u1_ccv_min_luminance_value_present_flag) &&
2008
1.40k
                                    (1 == ps_ip->u1_ccv_max_luminance_value_present_flag))
2009
1.40k
                            {
2010
1.40k
                                if((ps_ip->u4_ccv_max_luminance_value <
2011
1.40k
                                                    ps_ip->u4_ccv_min_luminance_value))
2012
0
                                {
2013
0
                                    ps_op->u4_error_code |= 1 << IVE_UNSUPPORTEDPARAM;
2014
0
                                    ps_op->u4_error_code |=
2015
0
                                            IH264E_INVALID_SEI_CCV_PARAMS;
2016
0
                                    return IV_FAIL;
2017
0
                                }
2018
1.40k
                            }
2019
1.40k
                            if((1 == ps_ip->u1_ccv_avg_luminance_value_present_flag) &&
2020
1.40k
                                    (1 == ps_ip->u1_ccv_max_luminance_value_present_flag))
2021
1.40k
                            {
2022
1.40k
                                if((ps_ip->u4_ccv_max_luminance_value <
2023
1.40k
                                                    ps_ip->u4_ccv_avg_luminance_value))
2024
0
                                {
2025
0
                                    ps_op->u4_error_code |= 1 << IVE_UNSUPPORTEDPARAM;
2026
0
                                    ps_op->u4_error_code |=
2027
0
                                            IH264E_INVALID_SEI_CCV_PARAMS;
2028
0
                                    return IV_FAIL;
2029
0
                                }
2030
1.40k
                            }
2031
1.40k
                        }
2032
1.40k
                    }
2033
4.22k
                    break;
2034
4.22k
                }
2035
2036
4.22k
                case IVE_CMD_CTL_SET_SEI_SII_PARAMS:
2037
4.22k
                {
2038
4.22k
                    ih264e_ctl_set_sei_sii_params_ip_t *ps_ip = pv_api_ip;
2039
4.22k
                    ih264e_ctl_set_sei_sii_params_op_t *ps_op = pv_api_op;
2040
2041
4.22k
                    if(ps_ip->u4_size != sizeof(ih264e_ctl_set_sei_sii_params_ip_t))
2042
0
                    {
2043
0
                        ps_op->u4_error_code |= 1 << IVE_UNSUPPORTEDPARAM;
2044
0
                        ps_op->u4_error_code |= IVE_ERR_IP_CTL_SET_SEI_SII_STRUCT_SIZE_INCORRECT;
2045
0
                        return IV_FAIL;
2046
0
                    }
2047
2048
4.22k
                    if(ps_op->u4_size != sizeof(ih264e_ctl_set_sei_sii_params_op_t))
2049
0
                    {
2050
0
                        ps_op->u4_error_code |= 1 << IVE_UNSUPPORTEDPARAM;
2051
0
                        ps_op->u4_error_code |= IVE_ERR_OP_CTL_SET_SEI_SII_STRUCT_SIZE_INCORRECT;
2052
0
                        return IV_FAIL;
2053
0
                    }
2054
2055
                    /* The below error check is based on H264 spec docs SII syntax */
2056
4.22k
                    if(0 != ps_ip->u4_sii_sub_layer_idx)
2057
0
                    {
2058
0
                        ps_op->u4_error_code |= 1 << IVE_UNSUPPORTEDPARAM;
2059
0
                        ps_op->u4_error_code |= IH264E_INVALID_SEI_SII_PARAMS;
2060
0
                        return IV_FAIL;
2061
0
                    }
2062
2063
4.22k
                    if(ps_ip->u1_sii_max_sub_layers_minus1 > 7)
2064
0
                    {
2065
0
                        ps_op->u4_error_code |= 1 << IVE_UNSUPPORTEDPARAM;
2066
0
                        ps_op->u4_error_code |= IH264E_INVALID_SEI_SII_PARAMS;
2067
0
                        return IV_FAIL;
2068
0
                    }
2069
2070
4.22k
                    if((ps_ip->u4_sii_sub_layer_idx > 0) &&
2071
4.22k
                       (ps_ip->u1_fixed_shutter_interval_within_cvs_flag == 1))
2072
0
                    {
2073
0
                        ps_op->u4_error_code |= 1 << IVE_UNSUPPORTEDPARAM;
2074
0
                        ps_op->u4_error_code |= IH264E_SEI_SII_FAILED_TO_MATCH_SPEC_COND;
2075
0
                        return IV_FAIL;
2076
0
                    }
2077
2078
4.22k
                    if((ps_ip->u4_sii_sub_layer_idx > ps_ip->u1_sii_max_sub_layers_minus1) &&
2079
4.22k
                       (ps_ip->u1_fixed_shutter_interval_within_cvs_flag == 0))
2080
0
                    {
2081
0
                        ps_op->u4_error_code |= 1 << IVE_UNSUPPORTEDPARAM;
2082
0
                        ps_op->u4_error_code |= IH264E_SEI_SII_FAILED_TO_MATCH_SPEC_COND;
2083
0
                        return IV_FAIL;
2084
0
                    }
2085
2086
4.22k
                    break;
2087
4.22k
                }
2088
2089
4.22k
                case IVE_CMD_CTL_SET_ENC_MODE:
2090
4.22k
                {
2091
4.22k
                    ih264e_ctl_set_enc_mode_ip_t *ps_ip = pv_api_ip;
2092
4.22k
                    ih264e_ctl_set_enc_mode_op_t *ps_op = pv_api_op;
2093
2094
4.22k
                    if (ps_ip->s_ive_ip.u4_size
2095
4.22k
                                    != sizeof(ih264e_ctl_set_enc_mode_ip_t))
2096
0
                    {
2097
0
                        ps_op->s_ive_op.u4_error_code |= 1
2098
0
                                        << IVE_UNSUPPORTEDPARAM;
2099
0
                        ps_op->s_ive_op.u4_error_code |=
2100
0
                                        IVE_ERR_IP_CTL_SETENCMODE_API_STRUCT_SIZE_INCORRECT;
2101
0
                        return IV_FAIL;
2102
0
                    }
2103
2104
4.22k
                    if (ps_op->s_ive_op.u4_size
2105
4.22k
                                    != sizeof(ih264e_ctl_set_enc_mode_op_t))
2106
0
                    {
2107
0
                        ps_op->s_ive_op.u4_error_code |= 1
2108
0
                                        << IVE_UNSUPPORTEDPARAM;
2109
0
                        ps_op->s_ive_op.u4_error_code |=
2110
0
                                        IVE_ERR_OP_CTL_SETENCMODE_API_STRUCT_SIZE_INCORRECT;
2111
0
                        return IV_FAIL;
2112
0
                    }
2113
2114
4.22k
                    if ((ps_ip->s_ive_ip.e_enc_mode != IVE_ENC_MODE_HEADER)
2115
4.22k
                                    && (ps_ip->s_ive_ip.e_enc_mode != IVE_ENC_MODE_PICTURE))
2116
0
                    {
2117
0
                        ps_op->s_ive_op.u4_error_code |= 1
2118
0
                                        << IVE_UNSUPPORTEDPARAM;
2119
0
                        ps_op->s_ive_op.u4_error_code |=
2120
0
                                        IH264E_INVALID_ENC_OPERATION_MODE;
2121
0
                        return IV_FAIL;
2122
0
                    }
2123
2124
4.22k
                    break;
2125
4.22k
                }
2126
2127
4.22k
                case IVE_CMD_CTL_SET_VBV_PARAMS:
2128
4.22k
                {
2129
4.22k
                    ih264e_ctl_set_vbv_params_ip_t *ps_ip = pv_api_ip;
2130
4.22k
                    ih264e_ctl_set_vbv_params_op_t *ps_op = pv_api_op;
2131
2132
4.22k
                    if (ps_ip->s_ive_ip.u4_size
2133
4.22k
                                    != sizeof(ih264e_ctl_set_vbv_params_ip_t))
2134
0
                    {
2135
0
                        ps_op->s_ive_op.u4_error_code |= 1
2136
0
                                        << IVE_UNSUPPORTEDPARAM;
2137
0
                        ps_op->s_ive_op.u4_error_code |=
2138
0
                                        IVE_ERR_IP_CTL_SETVBVPARAMS_API_STRUCT_SIZE_INCORRECT;
2139
0
                        return IV_FAIL;
2140
0
                    }
2141
2142
4.22k
                    if (ps_op->s_ive_op.u4_size
2143
4.22k
                                    != sizeof(ih264e_ctl_set_vbv_params_op_t))
2144
0
                    {
2145
0
                        ps_op->s_ive_op.u4_error_code |= 1
2146
0
                                        << IVE_UNSUPPORTEDPARAM;
2147
0
                        ps_op->s_ive_op.u4_error_code |=
2148
0
                                        IVE_ERR_OP_CTL_SETVBVPARAMS_API_STRUCT_SIZE_INCORRECT;
2149
0
                        return IV_FAIL;
2150
0
                    }
2151
2152
4.22k
                    if ((ps_ip->s_ive_ip.u4_vbv_buffer_delay < DEFAULT_MIN_BUFFER_DELAY)
2153
4.22k
                                    || (ps_ip->s_ive_ip.u4_vbv_buffer_delay > DEFAULT_MAX_BUFFER_DELAY))
2154
0
                    {
2155
0
                        ps_op->s_ive_op.u4_error_code |= 1
2156
0
                                        << IVE_UNSUPPORTEDPARAM;
2157
0
                        ps_op->s_ive_op.u4_error_code |=
2158
0
                                        IH264E_INVALID_BUFFER_DELAY;
2159
0
                        return IV_FAIL;
2160
0
                    }
2161
2162
4.22k
                    break;
2163
4.22k
                }
2164
2165
4.22k
                case IVE_CMD_CTL_SET_AIR_PARAMS:
2166
4.22k
                {
2167
4.22k
                    ih264e_ctl_set_air_params_ip_t *ps_ip = pv_api_ip;
2168
4.22k
                    ih264e_ctl_set_air_params_op_t *ps_op = pv_api_op;
2169
2170
4.22k
                    if (ps_ip->s_ive_ip.u4_size
2171
4.22k
                                    != sizeof(ih264e_ctl_set_air_params_ip_t))
2172
0
                    {
2173
0
                        ps_op->s_ive_op.u4_error_code |= 1
2174
0
                                        << IVE_UNSUPPORTEDPARAM;
2175
0
                        ps_op->s_ive_op.u4_error_code |=
2176
0
                                        IVE_ERR_IP_CTL_SETAIRPARAMS_API_STRUCT_SIZE_INCORRECT;
2177
0
                        return IV_FAIL;
2178
0
                    }
2179
2180
4.22k
                    if (ps_op->s_ive_op.u4_size
2181
4.22k
                                    != sizeof(ih264e_ctl_set_air_params_op_t))
2182
0
                    {
2183
0
                        ps_op->s_ive_op.u4_error_code |= 1
2184
0
                                        << IVE_UNSUPPORTEDPARAM;
2185
0
                        ps_op->s_ive_op.u4_error_code |=
2186
0
                                        IVE_ERR_OP_CTL_SETAIRPARAMS_API_STRUCT_SIZE_INCORRECT;
2187
0
                        return IV_FAIL;
2188
0
                    }
2189
2190
4.22k
                    if ((ps_ip->s_ive_ip.e_air_mode != IVE_AIR_MODE_NONE)
2191
4.22k
                                    && (ps_ip->s_ive_ip.e_air_mode != IVE_AIR_MODE_CYCLIC)
2192
4.22k
                                    && (ps_ip->s_ive_ip.e_air_mode != IVE_AIR_MODE_RANDOM))
2193
0
                    {
2194
0
                        ps_op->s_ive_op.u4_error_code |= 1
2195
0
                                        << IVE_UNSUPPORTEDPARAM;
2196
0
                        ps_op->s_ive_op.u4_error_code |=
2197
0
                                        IH264E_INVALID_AIR_MODE;
2198
0
                        return IV_FAIL;
2199
0
                    }
2200
2201
4.22k
                    if (ps_ip->s_ive_ip.e_air_mode != IVE_AIR_MODE_NONE &&
2202
4.22k
                        ps_ip->s_ive_ip.u4_air_refresh_period == 0)
2203
0
                    {
2204
0
                        ps_op->s_ive_op.u4_error_code |= 1
2205
0
                                        << IVE_UNSUPPORTEDPARAM;
2206
0
                        ps_op->s_ive_op.u4_error_code |=
2207
0
                                        IH264E_INVALID_AIR_REFRESH_PERIOD;
2208
0
                        return IV_FAIL;
2209
0
                    }
2210
2211
4.22k
                    break;
2212
4.22k
                }
2213
2214
4.22k
                case IVE_CMD_CTL_SET_PROFILE_PARAMS:
2215
4.22k
                {
2216
4.22k
                    ih264e_ctl_set_profile_params_ip_t *ps_ip = pv_api_ip;
2217
4.22k
                    ih264e_ctl_set_profile_params_op_t *ps_op = pv_api_op;
2218
2219
4.22k
                    if (ps_ip->s_ive_ip.u4_size
2220
4.22k
                                    != sizeof(ih264e_ctl_set_profile_params_ip_t))
2221
0
                    {
2222
0
                        ps_op->s_ive_op.u4_error_code |= 1
2223
0
                                        << IVE_UNSUPPORTEDPARAM;
2224
0
                        ps_op->s_ive_op.u4_error_code |=
2225
0
                                        IVE_ERR_IP_CTL_SETPROFILE_API_STRUCT_SIZE_INCORRECT;
2226
0
                        return IV_FAIL;
2227
0
                    }
2228
2229
4.22k
                    if (ps_op->s_ive_op.u4_size
2230
4.22k
                                    != sizeof(ih264e_ctl_set_profile_params_op_t))
2231
0
                    {
2232
0
                        ps_op->s_ive_op.u4_error_code |= 1
2233
0
                                        << IVE_UNSUPPORTEDPARAM;
2234
0
                        ps_op->s_ive_op.u4_error_code |=
2235
0
                                        IVE_ERR_OP_CTL_SETPROFILE_API_STRUCT_SIZE_INCORRECT;
2236
0
                        return IV_FAIL;
2237
0
                    }
2238
2239
4.22k
                    if (ps_ip->s_ive_ip.e_profile != IV_PROFILE_BASE &&
2240
4.22k
                        ps_ip->s_ive_ip.e_profile != IV_PROFILE_MAIN)
2241
0
                    {
2242
0
                        ps_op->s_ive_op.u4_error_code |= 1
2243
0
                                        << IVE_UNSUPPORTEDPARAM;
2244
0
                        ps_op->s_ive_op.u4_error_code |=
2245
0
                                        IH264E_PROFILE_NOT_SUPPORTED;
2246
0
                        return IV_FAIL;
2247
0
                    }
2248
2249
4.22k
                    if (ps_ip->s_ive_ip.u4_entropy_coding_mode > 1)
2250
0
                    {
2251
0
                        ps_op->s_ive_op.u4_error_code |= 1
2252
0
                                        << IVE_UNSUPPORTEDPARAM;
2253
0
                        ps_op->s_ive_op.u4_error_code |=
2254
0
                                        IH264E_INVALID_ENTROPY_CODING_MODE;
2255
0
                        return IV_FAIL;
2256
0
                    }
2257
2258
4.22k
                    break;
2259
4.22k
                }
2260
2261
4.22k
                default:
2262
0
                    *(pu4_api_op + 1) |= 1 << IVE_UNSUPPORTEDPARAM;
2263
0
                    *(pu4_api_op + 1) |= IVE_ERR_INVALID_API_SUB_CMD;
2264
0
                    return IV_FAIL;
2265
95.5k
            }
2266
2267
87.5k
            break;
2268
95.5k
        }
2269
2270
87.5k
        default:
2271
0
            *(pu4_api_op + 1) |= 1 << IVE_UNSUPPORTEDPARAM;
2272
0
            *(pu4_api_op + 1) |= IVE_ERR_INVALID_API_CMD;
2273
0
            return IV_FAIL;
2274
183k
    }
2275
2276
175k
    return IV_SUCCESS;
2277
183k
}
2278
2279
/**
2280
*******************************************************************************
2281
*
2282
* @brief update encoder configuration parameters
2283
*
2284
* @par Description:
2285
*  updates encoder configuration parameters from the given config set.
2286
*  Initialize/reinitialize codec parameters according to new configurations.
2287
*
2288
* @param[in] ps_codec
2289
*  Pointer to codec context
2290
*
2291
* @param[in] ps_cfg
2292
*  Pointer to config param set
2293
*
2294
* @remarks none
2295
*
2296
*******************************************************************************
2297
*/
2298
IH264E_ERROR_T ih264e_codec_update_config(codec_t *ps_codec,
2299
                                          cfg_params_t *ps_cfg)
2300
79.1k
{
2301
    /* config params */
2302
79.1k
    cfg_params_t *ps_curr_cfg = &ps_codec->s_cfg;
2303
2304
    /* error status */
2305
79.1k
    IH264E_ERROR_T err = IH264E_SUCCESS;
2306
2307
    /* temp var */
2308
79.1k
    UWORD32 u4_init_rc = 0;
2309
2310
    /***********************/
2311
    /* UPDATE CODEC CONFIG */
2312
    /***********************/
2313
79.1k
    if (ps_cfg->e_cmd == IVE_CMD_CTL_SET_DIMENSIONS)
2314
4.08k
    {
2315
4.08k
        UWORD32 wd_aln = ALIGN16(ps_cfg->u4_wd);
2316
4.08k
        UWORD32 ht_aln = ALIGN16(ps_cfg->u4_ht);
2317
2318
4.08k
        if (ps_curr_cfg->u4_wd != wd_aln || ps_curr_cfg->u4_ht != ht_aln
2319
4.08k
                        || ps_curr_cfg->u4_disp_wd != ps_cfg->u4_disp_wd
2320
4.08k
                        || ps_curr_cfg->u4_disp_ht != ps_cfg->u4_disp_ht)
2321
3.04k
        {
2322
3.04k
            ps_curr_cfg->u4_wd = wd_aln;
2323
3.04k
            ps_curr_cfg->u4_ht = ht_aln;
2324
2325
3.04k
            ps_curr_cfg->u4_disp_wd = ps_cfg->u4_disp_wd;
2326
3.04k
            ps_curr_cfg->u4_disp_ht = ps_cfg->u4_disp_ht;
2327
2328
3.04k
            ps_curr_cfg->i4_wd_mbs = ps_curr_cfg->u4_wd >> 4;
2329
3.04k
            ps_curr_cfg->i4_ht_mbs = ps_curr_cfg->u4_ht >> 4;
2330
2331
3.04k
            ps_codec->i4_rec_strd = ALIGN16(ps_cfg->u4_wd) + PAD_WD;
2332
2333
            /* If number of MBs in a frame changes the air map also changes.
2334
             * Hence recompute air map also reset air pic cnt */
2335
3.04k
            if (ps_codec->s_cfg.e_air_mode != IVE_AIR_MODE_NONE)
2336
0
            {
2337
                /* re-init the air map */
2338
0
                ih264e_init_air_map(ps_codec);
2339
2340
                /* reset air counter */
2341
0
                ps_codec->i4_air_pic_cnt = -1;
2342
0
            }
2343
2344
            /* initialize mv bank buffer manager */
2345
3.04k
            err = ih264e_mv_buf_mgr_add_bufs(ps_codec);
2346
3.04k
            if (err != IH264E_SUCCESS)
2347
0
                return err;
2348
2349
            /* initialize ref bank buffer manager */
2350
3.04k
            err = ih264e_pic_buf_mgr_add_bufs(ps_codec);
2351
3.04k
            if (err != IH264E_SUCCESS)
2352
0
                return err;
2353
2354
            /* since dimension changed, start new sequence by forcing IDR */
2355
3.04k
            ps_codec->force_curr_frame_type = IV_IDR_FRAME;
2356
2357
            /* in case dimension changes, we need to reinitialize RC as the
2358
             * old model shall not fit further */
2359
3.04k
            u4_init_rc = 1;
2360
2361
            /* when the dimension changes, the header needs to be regenerated */
2362
3.04k
            ps_codec->i4_gen_header = 1;
2363
3.04k
        }
2364
4.08k
    }
2365
75.0k
    else if (ps_cfg->e_cmd == IVE_CMD_CTL_SET_FRAMERATE)
2366
2.32k
    {
2367
        /* temp var */
2368
2.32k
        UWORD32 u4_src_ticks, u4_tgt_ticks;
2369
2370
2.32k
        u4_src_ticks = ih264e_frame_time_get_src_ticks(
2371
2.32k
                        ps_codec->s_rate_control.pps_frame_time);
2372
2373
2.32k
        u4_tgt_ticks = ih264e_frame_time_get_tgt_ticks(
2374
2.32k
                        ps_codec->s_rate_control.pps_frame_time);
2375
2376
        /* Change frame rate */
2377
2.32k
        if (ps_codec->s_cfg.u4_src_frame_rate
2378
2.32k
                        != ps_cfg->u4_src_frame_rate * 1000)
2379
2.31k
        {
2380
2.31k
            ps_codec->s_cfg.u4_src_frame_rate = ps_cfg->u4_src_frame_rate
2381
2.31k
                            * 1000;
2382
2383
2.31k
            ih264e_frame_time_update_src_frame_rate(
2384
2.31k
                            ps_codec->s_rate_control.pps_frame_time,
2385
2.31k
                            ps_codec->s_cfg.u4_src_frame_rate);
2386
2387
2.31k
            ih264_time_stamp_update_frame_rate(
2388
2.31k
                            ps_codec->s_rate_control.pps_time_stamp,
2389
2.31k
                            ps_codec->s_cfg.u4_src_frame_rate);
2390
2391
2.31k
            irc_change_frame_rate(ps_codec->s_rate_control.pps_rate_control_api,
2392
2.31k
                                  ps_codec->s_cfg.u4_src_frame_rate,
2393
2.31k
                                  u4_src_ticks, u4_tgt_ticks);
2394
2.31k
        }
2395
2396
2.32k
        if (ps_codec->s_cfg.u4_tgt_frame_rate
2397
2.32k
                        != ps_cfg->u4_tgt_frame_rate * 1000)
2398
2.31k
        {
2399
2.31k
            ps_codec->s_cfg.u4_tgt_frame_rate = ps_cfg->u4_tgt_frame_rate
2400
2.31k
                            * 1000;
2401
2402
2.31k
            ih264e_frame_time_update_tgt_frame_rate(
2403
2.31k
                            ps_codec->s_rate_control.pps_frame_time,
2404
2.31k
                            ps_codec->s_cfg.u4_tgt_frame_rate);
2405
2406
2.31k
            irc_change_frame_rate(ps_codec->s_rate_control.pps_rate_control_api,
2407
2.31k
                                  ps_codec->s_cfg.u4_src_frame_rate,
2408
2.31k
                                  u4_src_ticks, u4_tgt_ticks);
2409
2410
2.31k
            irc_change_frm_rate_for_bit_alloc(
2411
2.31k
                            ps_codec->s_rate_control.pps_rate_control_api,
2412
2.31k
                            ps_codec->s_cfg.u4_tgt_frame_rate);
2413
2.31k
        }
2414
2415
2.32k
    }
2416
72.7k
    else if (ps_cfg->e_cmd == IVE_CMD_CTL_SET_BITRATE)
2417
4.65k
    {
2418
4.65k
        if (ps_curr_cfg->u4_target_bitrate != ps_cfg->u4_target_bitrate)
2419
4.65k
        {
2420
4.65k
            if (IVE_RC_NONE != ps_curr_cfg->e_rc_mode)
2421
2.84k
                irc_change_avg_bit_rate(
2422
2.84k
                                ps_codec->s_rate_control.pps_rate_control_api,
2423
2.84k
                                ps_cfg->u4_target_bitrate);
2424
2425
4.65k
            ps_curr_cfg->u4_target_bitrate = ps_cfg->u4_target_bitrate;
2426
4.65k
        }
2427
4.65k
    }
2428
68.0k
    else if (ps_cfg->e_cmd == IVE_CMD_CTL_SET_FRAMETYPE)
2429
906
    {
2430
906
        switch (ps_cfg->e_frame_type)
2431
906
        {
2432
0
            case IV_I_FRAME:
2433
0
                ps_codec->force_curr_frame_type = IV_I_FRAME;
2434
0
                break;
2435
2436
906
            case IV_IDR_FRAME:
2437
906
                ps_codec->force_curr_frame_type = IV_IDR_FRAME;
2438
906
                break;
2439
2440
0
            case IV_P_FRAME:
2441
0
            default:
2442
0
                break;
2443
906
        }
2444
906
    }
2445
67.1k
    else if (ps_cfg->e_cmd == IVE_CMD_CTL_SET_ME_PARAMS)
2446
1.08k
    {
2447
1.08k
        if (ps_curr_cfg->u4_enc_speed_preset == IVE_CONFIG)
2448
380
        {
2449
380
            ps_codec->s_cfg.u4_enable_hpel = ps_cfg->u4_enable_hpel;
2450
380
            ps_codec->s_cfg.u4_enable_fast_sad = ps_cfg->u4_enable_fast_sad;
2451
380
            ps_codec->s_cfg.u4_me_speed_preset = ps_cfg->u4_me_speed_preset;
2452
380
            ps_codec->s_cfg.u4_enable_qpel = ps_cfg->u4_enable_qpel;
2453
380
        }
2454
706
        else if (ps_curr_cfg->u4_enc_speed_preset == IVE_FASTEST)
2455
63
        {
2456
63
            ps_codec->s_cfg.u4_enable_fast_sad = ps_cfg->u4_enable_fast_sad;
2457
63
        }
2458
1.08k
        ps_codec->s_cfg.u4_srch_rng_x = ps_cfg->u4_srch_rng_x;
2459
1.08k
        ps_codec->s_cfg.u4_srch_rng_y = ps_cfg->u4_srch_rng_y;
2460
2461
1.08k
        if (ps_codec->s_cfg.u4_enable_alt_ref != ps_cfg->u4_enable_alt_ref)
2462
0
        {
2463
0
            ps_codec->s_cfg.u4_enable_alt_ref = ps_cfg->u4_enable_alt_ref;
2464
0
            ps_codec->u4_is_curr_frm_ref = 1;
2465
0
        }
2466
1.08k
    }
2467
66.1k
    else if (ps_cfg->e_cmd == IVE_CMD_CTL_SET_IPE_PARAMS)
2468
4.22k
    {
2469
4.22k
        ps_curr_cfg->u4_enc_speed_preset = ps_cfg->u4_enc_speed_preset;
2470
2471
4.22k
        ps_curr_cfg->u4_constrained_intra_pred = ps_cfg->u4_constrained_intra_pred;
2472
2473
4.22k
        if (ps_curr_cfg->u4_enc_speed_preset != IVE_CONFIG)
2474
2.86k
        {
2475
2.86k
            ih264e_speed_preset_side_effects(ps_codec);
2476
2.86k
        }
2477
1.36k
        else
2478
1.36k
        {
2479
1.36k
            ps_curr_cfg->u4_enable_intra_4x4 = ps_cfg->u4_enable_intra_4x4;
2480
1.36k
        }
2481
4.22k
    }
2482
61.8k
    else if (ps_cfg->e_cmd == IVE_CMD_CTL_SET_GOP_PARAMS)
2483
3.47k
    {
2484
3.47k
        if (ps_curr_cfg->u4_i_frm_interval != ps_cfg->u4_i_frm_interval)
2485
3.46k
        {
2486
3.46k
            ps_curr_cfg->u4_i_frm_interval = ps_cfg->u4_i_frm_interval;
2487
2488
            /* reset air counter */
2489
3.46k
            ps_codec->i4_air_pic_cnt = -1;
2490
2491
            /* re-init air map */
2492
3.46k
            ih264e_init_air_map(ps_codec);
2493
2494
            /* Effect intra frame interval change */
2495
3.46k
            irc_change_intra_frm_int_call(
2496
3.46k
                            ps_codec->s_rate_control.pps_rate_control_api,
2497
3.46k
                            ps_curr_cfg->u4_i_frm_interval);
2498
3.46k
        }
2499
2500
3.47k
        ps_curr_cfg->u4_idr_frm_interval = ps_cfg->u4_idr_frm_interval;
2501
2502
3.47k
    }
2503
58.4k
    else if (ps_cfg->e_cmd == IVE_CMD_CTL_SET_DEBLOCK_PARAMS)
2504
3.50k
    {
2505
3.50k
        if (ps_curr_cfg->u4_enc_speed_preset == IVE_CONFIG)
2506
1.12k
        {
2507
1.12k
            ps_curr_cfg->u4_disable_deblock_level =
2508
1.12k
                            ps_cfg->u4_disable_deblock_level;
2509
1.12k
        }
2510
3.50k
    }
2511
54.8k
    else if (ps_cfg->e_cmd == IVE_CMD_CTL_SET_QP)
2512
4.22k
    {
2513
4.22k
        UWORD8 au1_init_qp[MAX_PIC_TYPE];
2514
4.22k
        UWORD8 au1_min_max_qp[2 * MAX_PIC_TYPE];
2515
2516
4.22k
        ps_codec->s_cfg.u4_i_qp_max = ps_cfg->u4_i_qp_max;
2517
4.22k
        ps_codec->s_cfg.u4_i_qp_min = ps_cfg->u4_i_qp_min;
2518
4.22k
        ps_codec->s_cfg.u4_i_qp = ps_cfg->u4_i_qp;
2519
2520
4.22k
        ps_codec->s_cfg.u4_p_qp_max = ps_cfg->u4_p_qp_max;
2521
4.22k
        ps_codec->s_cfg.u4_p_qp_min = ps_cfg->u4_p_qp_min;
2522
4.22k
        ps_codec->s_cfg.u4_p_qp = ps_cfg->u4_p_qp;
2523
2524
4.22k
        ps_codec->s_cfg.u4_b_qp_max = ps_cfg->u4_b_qp_max;
2525
4.22k
        ps_codec->s_cfg.u4_b_qp_min = ps_cfg->u4_b_qp_min;
2526
4.22k
        ps_codec->s_cfg.u4_b_qp = ps_cfg->u4_b_qp;
2527
2528
        /* update rc lib with modified qp */
2529
4.22k
        au1_init_qp[0] = gau1_h264_to_mpeg2_qmap[ps_codec->s_cfg.u4_i_qp];
2530
4.22k
        au1_init_qp[1] = gau1_h264_to_mpeg2_qmap[ps_codec->s_cfg.u4_p_qp];
2531
4.22k
        au1_init_qp[2] = gau1_h264_to_mpeg2_qmap[ps_codec->s_cfg.u4_b_qp];
2532
2533
4.22k
        irc_change_init_qp(ps_codec->s_rate_control.pps_rate_control_api,
2534
4.22k
                           au1_init_qp);
2535
2536
4.22k
        au1_min_max_qp[2 * I_PIC] =
2537
4.22k
                        gau1_h264_to_mpeg2_qmap[ps_codec->s_cfg.u4_i_qp_min];
2538
4.22k
        au1_min_max_qp[2 * I_PIC + 1] =
2539
4.22k
                        gau1_h264_to_mpeg2_qmap[ps_codec->s_cfg.u4_i_qp_max];
2540
2541
4.22k
        au1_min_max_qp[2 * P_PIC] =
2542
4.22k
                        gau1_h264_to_mpeg2_qmap[ps_codec->s_cfg.u4_p_qp_min];
2543
4.22k
        au1_min_max_qp[2 * P_PIC + 1] =
2544
4.22k
                        gau1_h264_to_mpeg2_qmap[ps_codec->s_cfg.u4_p_qp_max];
2545
2546
4.22k
        au1_min_max_qp[2 * B_PIC] =
2547
4.22k
                        gau1_h264_to_mpeg2_qmap[ps_codec->s_cfg.u4_b_qp_min];
2548
4.22k
        au1_min_max_qp[2 * B_PIC + 1] =
2549
4.22k
                        gau1_h264_to_mpeg2_qmap[ps_codec->s_cfg.u4_b_qp_max];
2550
2551
4.22k
        irc_change_min_max_qp(ps_codec->s_rate_control.pps_rate_control_api,
2552
4.22k
                              au1_min_max_qp);
2553
4.22k
    }
2554
50.6k
    else if (ps_cfg->e_cmd == IVE_CMD_CTL_SET_ENC_MODE)
2555
4.22k
    {
2556
4.22k
        ps_codec->s_cfg.e_enc_mode = ps_cfg->e_enc_mode;
2557
2558
4.22k
        if (ps_codec->s_cfg.e_enc_mode == IVE_ENC_MODE_HEADER)
2559
4.22k
        {
2560
4.22k
            ps_codec->i4_header_mode = 1;
2561
4.22k
            ps_codec->s_cfg.e_enc_mode = IVE_ENC_MODE_PICTURE;
2562
4.22k
        }
2563
0
        else
2564
0
        {
2565
0
            ps_codec->i4_header_mode = 0;
2566
0
        }
2567
4.22k
    }
2568
46.4k
    else if (ps_cfg->e_cmd == IVE_CMD_CTL_SET_VBV_PARAMS
2569
46.4k
                    && IVE_RC_NONE != ps_codec->s_cfg.e_rc_mode)
2570
2.44k
    {
2571
2.44k
        ps_codec->s_cfg.u4_vbv_buf_size = ps_cfg->u4_vbv_buf_size;
2572
2.44k
        ps_codec->s_cfg.u4_vbv_buffer_delay = ps_cfg->u4_vbv_buffer_delay;
2573
2574
        // irc_change_buffer_delay(ps_codec->s_rate_control.pps_rate_control_api, ps_codec->s_cfg.u4_vbv_buffer_delay);
2575
2576
        // TODO: remove this when the support for changing buffer dynamically
2577
        // is yet to be added.
2578
2.44k
        u4_init_rc = 1;
2579
2.44k
    }
2580
44.0k
    else if (ps_cfg->e_cmd == IVE_CMD_CTL_SET_AIR_PARAMS)
2581
4.22k
    {
2582
4.22k
        if (ps_curr_cfg->e_air_mode != ps_cfg->e_air_mode
2583
4.22k
                        || ps_curr_cfg->u4_air_refresh_period
2584
2.41k
                                        != ps_cfg->u4_air_refresh_period)
2585
4.21k
        {
2586
4.21k
            ps_curr_cfg->e_air_mode = ps_cfg->e_air_mode;
2587
4.21k
            ps_curr_cfg->u4_air_refresh_period = ps_cfg->u4_air_refresh_period;
2588
2589
4.21k
            ih264e_init_air_map(ps_codec);
2590
2591
            /* reset air counter */
2592
4.21k
            ps_codec->i4_air_pic_cnt = -1;
2593
4.21k
        }
2594
4.22k
    }
2595
39.7k
    else if (ps_cfg->e_cmd == IVE_CMD_CTL_SET_PROFILE_PARAMS)
2596
4.22k
    {
2597
4.22k
        ps_codec->s_cfg.e_profile = ps_cfg->e_profile;
2598
4.22k
        ps_codec->s_cfg.u4_entropy_coding_mode = ps_cfg->u4_entropy_coding_mode;
2599
4.22k
    }
2600
35.5k
    else if (ps_cfg->e_cmd == IVE_CMD_CTL_SET_NUM_CORES)
2601
4.22k
    {
2602
4.22k
        ps_codec->s_cfg.u4_num_cores = ps_cfg->u4_num_cores;
2603
4.22k
    }
2604
31.3k
    else if (ps_cfg->e_cmd == IVE_CMD_CTL_SET_VUI_PARAMS)
2605
4.22k
    {
2606
4.22k
        ps_codec->s_cfg.s_vui = ps_cfg->s_vui;
2607
4.22k
    }
2608
2609
27.1k
    else if (ps_cfg->e_cmd == IVE_CMD_CTL_SET_SEI_MDCV_PARAMS)
2610
4.22k
    {
2611
4.22k
        ps_codec->s_cfg.s_sei.u1_sei_mdcv_params_present_flag =
2612
4.22k
                                                ps_cfg->s_sei.u1_sei_mdcv_params_present_flag;
2613
4.22k
        ps_codec->s_cfg.s_sei.s_sei_mdcv_params = ps_cfg->s_sei.s_sei_mdcv_params;
2614
4.22k
    }
2615
22.8k
    else if (ps_cfg->e_cmd == IVE_CMD_CTL_SET_SEI_CLL_PARAMS)
2616
4.22k
    {
2617
4.22k
        ps_codec->s_cfg.s_sei.u1_sei_cll_params_present_flag =
2618
4.22k
                                                ps_cfg->s_sei.u1_sei_cll_params_present_flag;
2619
4.22k
        ps_codec->s_cfg.s_sei.s_sei_cll_params = ps_cfg->s_sei.s_sei_cll_params;
2620
4.22k
    }
2621
18.6k
    else if (ps_cfg->e_cmd == IVE_CMD_CTL_SET_SEI_AVE_PARAMS)
2622
4.22k
    {
2623
4.22k
        ps_codec->s_cfg.s_sei.u1_sei_ave_params_present_flag =
2624
4.22k
                                                ps_cfg->s_sei.u1_sei_ave_params_present_flag;
2625
4.22k
        ps_codec->s_cfg.s_sei.s_sei_ave_params = ps_cfg->s_sei.s_sei_ave_params;
2626
4.22k
    }
2627
14.4k
    else if (ps_cfg->e_cmd == IVE_CMD_CTL_SET_SEI_CCV_PARAMS)
2628
4.22k
    {
2629
4.22k
        ps_codec->s_cfg.s_sei.u1_sei_ccv_params_present_flag =
2630
4.22k
                                                ps_cfg->s_sei.u1_sei_ccv_params_present_flag;
2631
4.22k
        ps_codec->s_cfg.s_sei.s_sei_ccv_params = ps_cfg->s_sei.s_sei_ccv_params;
2632
4.22k
    }
2633
10.2k
    else if(ps_cfg->e_cmd == IVE_CMD_CTL_SET_SEI_SII_PARAMS)
2634
4.22k
    {
2635
4.22k
        ps_codec->s_cfg.s_sei.u1_sei_sii_params_present_flag =
2636
4.22k
            ps_cfg->s_sei.u1_sei_sii_params_present_flag;
2637
4.22k
        ps_codec->s_cfg.s_sei.s_sei_sii_params = ps_cfg->s_sei.s_sei_sii_params;
2638
4.22k
    }
2639
2640
    /* reset RC model */
2641
79.1k
    if (u4_init_rc)
2642
5.48k
    {
2643
        /* init qp */
2644
5.48k
        UWORD8 au1_init_qp[MAX_PIC_TYPE];
2645
2646
        /* min max qp */
2647
5.48k
        UWORD8 au1_min_max_qp[2 * MAX_PIC_TYPE];
2648
2649
        /* init i,p,b qp */
2650
5.48k
        au1_init_qp[0] = gau1_h264_to_mpeg2_qmap[ps_codec->s_cfg.u4_i_qp];
2651
5.48k
        au1_init_qp[1] = gau1_h264_to_mpeg2_qmap[ps_codec->s_cfg.u4_p_qp];
2652
5.48k
        au1_init_qp[2] = gau1_h264_to_mpeg2_qmap[ps_codec->s_cfg.u4_b_qp];
2653
2654
        /* init min max qp */
2655
5.48k
        au1_min_max_qp[2 * I_PIC] =
2656
5.48k
                        gau1_h264_to_mpeg2_qmap[ps_codec->s_cfg.u4_i_qp_min];
2657
5.48k
        au1_min_max_qp[2 * I_PIC + 1] =
2658
5.48k
                        gau1_h264_to_mpeg2_qmap[ps_codec->s_cfg.u4_i_qp_max];
2659
2660
5.48k
        au1_min_max_qp[2 * P_PIC] =
2661
5.48k
                        gau1_h264_to_mpeg2_qmap[ps_codec->s_cfg.u4_p_qp_min];
2662
5.48k
        au1_min_max_qp[2 * P_PIC + 1] =
2663
5.48k
                        gau1_h264_to_mpeg2_qmap[ps_codec->s_cfg.u4_p_qp_max];
2664
2665
5.48k
        au1_min_max_qp[2 * B_PIC] =
2666
5.48k
                        gau1_h264_to_mpeg2_qmap[ps_codec->s_cfg.u4_b_qp_min];
2667
5.48k
        au1_min_max_qp[2 * B_PIC + 1] =
2668
5.48k
                        gau1_h264_to_mpeg2_qmap[ps_codec->s_cfg.u4_b_qp_max];
2669
2670
        /* get rc mode */
2671
5.48k
        switch (ps_codec->s_cfg.e_rc_mode)
2672
5.48k
        {
2673
2.31k
            case IVE_RC_STORAGE:
2674
2.31k
                ps_codec->s_rate_control.e_rc_type = VBR_STORAGE;
2675
2.31k
                break;
2676
2677
1.71k
            case IVE_RC_CBR_NON_LOW_DELAY:
2678
1.71k
                ps_codec->s_rate_control.e_rc_type = CBR_NLDRC;
2679
1.71k
                break;
2680
2681
0
            case IVE_RC_CBR_LOW_DELAY:
2682
0
                ps_codec->s_rate_control.e_rc_type = CBR_LDRC;
2683
0
                break;
2684
2685
1.46k
            case IVE_RC_NONE:
2686
1.46k
                ps_codec->s_rate_control.e_rc_type = CONST_QP;
2687
1.46k
                break;
2688
2689
0
            default:
2690
0
                break;
2691
5.48k
        }
2692
2693
        /* init rate control */
2694
5.48k
        ih264e_rc_init(ps_codec->s_rate_control.pps_rate_control_api,
2695
5.48k
                       ps_codec->s_rate_control.pps_frame_time,
2696
5.48k
                       ps_codec->s_rate_control.pps_time_stamp,
2697
5.48k
                       ps_codec->s_rate_control.pps_pd_frm_rate,
2698
5.48k
                       ps_codec->s_cfg.u4_max_framerate,
2699
5.48k
                       ps_codec->s_cfg.u4_src_frame_rate,
2700
5.48k
                       ps_codec->s_cfg.u4_tgt_frame_rate,
2701
5.48k
                       ps_codec->s_rate_control.e_rc_type,
2702
5.48k
                       ps_codec->s_cfg.u4_target_bitrate,
2703
5.48k
                       ps_codec->s_cfg.u4_max_bitrate,
2704
5.48k
                       ps_codec->s_cfg.u4_vbv_buffer_delay,
2705
5.48k
                       ps_codec->s_cfg.u4_i_frm_interval,
2706
5.48k
                       ps_codec->s_cfg.u4_num_bframes + 1, au1_init_qp,
2707
5.48k
                       ps_codec->s_cfg.u4_num_bframes + 2, au1_min_max_qp,
2708
5.48k
                       ps_codec->s_cfg.u4_max_level);
2709
5.48k
    }
2710
2711
79.1k
    return err;
2712
79.1k
}
2713
2714
/**
2715
*******************************************************************************
2716
*
2717
* @brief
2718
*  Sets default encoder config parameters
2719
*
2720
* @par Description:
2721
*  Sets default dynamic parameters. Will be called in ih264e_init() to ensure
2722
*  that even if set_params is not called, codec continues to work
2723
*
2724
* @param[in] ps_cfg
2725
*  Pointer to encoder config params
2726
*
2727
* @returns  error status
2728
*
2729
* @remarks none
2730
*
2731
*******************************************************************************
2732
*/
2733
static WORD32 ih264e_set_default_params(cfg_params_t *ps_cfg)
2734
8.44k
{
2735
8.44k
    WORD32 ret = IV_SUCCESS;
2736
2737
8.44k
    ps_cfg->u4_max_wd = MAX_WD;
2738
8.44k
    ps_cfg->u4_max_ht = MAX_HT;
2739
8.44k
    ps_cfg->u4_max_ref_cnt = MAX_REF_CNT;
2740
8.44k
    ps_cfg->u4_max_reorder_cnt = MAX_REF_CNT;
2741
8.44k
    ps_cfg->u4_max_level = DEFAULT_MAX_LEVEL;
2742
8.44k
    ps_cfg->e_inp_color_fmt = IV_YUV_420SP_UV;
2743
8.44k
    ps_cfg->u4_enable_recon = DEFAULT_RECON_ENABLE;
2744
8.44k
    ps_cfg->u4_enable_quality_metrics = DEFAULT_QUALITY_METRICS_ENABLE;
2745
8.44k
    ps_cfg->e_recon_color_fmt = IV_YUV_420P;
2746
8.44k
    ps_cfg->u4_enc_speed_preset = IVE_FASTEST;
2747
8.44k
    ps_cfg->e_rc_mode = DEFAULT_RC;
2748
8.44k
    ps_cfg->u4_max_framerate = DEFAULT_MAX_FRAMERATE;
2749
8.44k
    ps_cfg->u4_max_bitrate = DEFAULT_MAX_BITRATE;
2750
8.44k
    ps_cfg->u4_num_bframes = DEFAULT_MAX_NUM_BFRAMES;
2751
8.44k
    ps_cfg->e_content_type = IV_PROGRESSIVE;
2752
8.44k
    ps_cfg->u4_max_srch_rng_x = DEFAULT_MAX_SRCH_RANGE_X;
2753
8.44k
    ps_cfg->u4_max_srch_rng_y = DEFAULT_MAX_SRCH_RANGE_Y;
2754
8.44k
    ps_cfg->e_slice_mode = IVE_SLICE_MODE_NONE;
2755
8.44k
    ps_cfg->u4_slice_param = DEFAULT_SLICE_PARAM;
2756
8.44k
    ps_cfg->e_arch = ih264e_default_arch();
2757
8.44k
    ps_cfg->e_soc = SOC_GENERIC;
2758
8.44k
    ps_cfg->u4_disp_wd = MAX_WD;
2759
8.44k
    ps_cfg->u4_disp_ht = MAX_HT;
2760
8.44k
    ps_cfg->u4_wd = MAX_WD;
2761
8.44k
    ps_cfg->u4_ht = MAX_HT;
2762
8.44k
    ps_cfg->u4_src_frame_rate = DEFAULT_SRC_FRAME_RATE;
2763
8.44k
    ps_cfg->u4_tgt_frame_rate = DEFAULT_TGT_FRAME_RATE;
2764
8.44k
    ps_cfg->u4_target_bitrate = DEFAULT_BITRATE;
2765
8.44k
    ps_cfg->e_frame_type = IV_NA_FRAME;
2766
8.44k
    ps_cfg->e_enc_mode = IVE_ENC_MODE_DEFAULT;
2767
8.44k
    ps_cfg->u4_i_qp = DEFAULT_I_QP;
2768
8.44k
    ps_cfg->u4_p_qp = DEFAULT_P_QP;
2769
8.44k
    ps_cfg->u4_b_qp = DEFAULT_B_QP;
2770
8.44k
    ps_cfg->u4_i_qp_min = DEFAULT_QP_MIN;
2771
8.44k
    ps_cfg->u4_i_qp_max = DEFAULT_QP_MAX;
2772
8.44k
    ps_cfg->u4_p_qp_min = DEFAULT_QP_MIN;
2773
8.44k
    ps_cfg->u4_p_qp_max = DEFAULT_QP_MAX;
2774
8.44k
    ps_cfg->u4_b_qp_min = DEFAULT_QP_MIN;
2775
8.44k
    ps_cfg->u4_b_qp_max = DEFAULT_QP_MAX;
2776
8.44k
    ps_cfg->e_air_mode = DEFAULT_AIR_MODE;
2777
8.44k
    ps_cfg->u4_air_refresh_period = DEFAULT_AIR_REFRESH_PERIOD;
2778
8.44k
    ps_cfg->u4_vbv_buffer_delay = DEFAULT_VBV_DELAY;
2779
8.44k
    ps_cfg->u4_vbv_buf_size = DEFAULT_VBV_SIZE;
2780
8.44k
    ps_cfg->u4_num_cores = DEFAULT_NUM_CORES;
2781
8.44k
    ps_cfg->u4_me_speed_preset = DEFAULT_ME_SPEED_PRESET;
2782
8.44k
    ps_cfg->u4_enable_hpel = DEFAULT_HPEL;
2783
8.44k
    ps_cfg->u4_enable_qpel = DEFAULT_QPEL;
2784
8.44k
    ps_cfg->u4_enable_intra_4x4 = DEFAULT_I4;
2785
8.44k
    ps_cfg->u4_enable_intra_8x8 = DEFAULT_I8;
2786
8.44k
    ps_cfg->u4_enable_intra_16x16 = DEFAULT_I16;
2787
8.44k
    ps_cfg->u4_enable_fast_sad = DEFAULT_ENABLE_FAST_SAD;
2788
8.44k
    ps_cfg->u4_enable_satqd = DEFAULT_ENABLE_SATQD;
2789
8.44k
    ps_cfg->i4_min_sad =
2790
8.44k
                    (ps_cfg->u4_enable_satqd == DEFAULT_ENABLE_SATQD) ?
2791
8.44k
                                    DEFAULT_MIN_SAD_ENABLE :
2792
8.44k
                                    DEFAULT_MIN_SAD_DISABLE;
2793
8.44k
    ps_cfg->u4_srch_rng_x = DEFAULT_SRCH_RNG_X;
2794
8.44k
    ps_cfg->u4_srch_rng_y = DEFAULT_SRCH_RNG_Y;
2795
8.44k
    ps_cfg->u4_i_frm_interval = DEFAULT_I_INTERVAL;
2796
8.44k
    ps_cfg->u4_idr_frm_interval = DEFAULT_IDR_INTERVAL;
2797
8.44k
    ps_cfg->u4_disable_deblock_level = DEFAULT_DISABLE_DEBLK_LEVEL;
2798
8.44k
    ps_cfg->e_profile = DEFAULT_PROFILE;
2799
8.44k
    ps_cfg->u4_timestamp_low = 0;
2800
8.44k
    ps_cfg->u4_timestamp_high = 0;
2801
8.44k
    ps_cfg->u4_is_valid = 1;
2802
8.44k
    ps_cfg->e_cmd = IVE_CMD_CT_NA;
2803
8.44k
    ps_cfg->i4_wd_mbs = ps_cfg->u4_max_wd >> 4;
2804
8.44k
    ps_cfg->i4_ht_mbs = ps_cfg->u4_max_ht >> 4;
2805
8.44k
    ps_cfg->u4_entropy_coding_mode = DEFAULT_ENTROPY_CODING_MODE;
2806
8.44k
    ps_cfg->u4_weighted_prediction = 0;
2807
8.44k
    ps_cfg->u4_constrained_intra_pred = DEFAULT_CONSTRAINED_INTRAPRED;
2808
8.44k
    ps_cfg->u4_pic_info_type = 0;
2809
8.44k
    ps_cfg->u4_mb_info_type = 0;
2810
8.44k
    ps_cfg->s_vui.u1_video_signal_type_present_flag = 0;
2811
8.44k
    ps_cfg->s_vui.u1_colour_description_present_flag = 0;
2812
2813
8.44k
    return ret;
2814
8.44k
}
2815
2816
/**
2817
*******************************************************************************
2818
*
2819
* @brief
2820
*  Initialize encoder context. This will be called by init_mem_rec and during
2821
*  codec reset
2822
*
2823
* @par Description:
2824
*  Initializes the context
2825
*
2826
* @param[in] ps_codec
2827
*  Codec context pointer
2828
*
2829
* @returns error status
2830
*
2831
* @remarks none
2832
*
2833
*******************************************************************************
2834
*/
2835
static WORD32 ih264e_init(codec_t *ps_codec)
2836
4.22k
{
2837
    /* enc config param set */
2838
4.22k
    cfg_params_t *ps_cfg = &(ps_codec->s_cfg);
2839
2840
    /* temp var */
2841
4.22k
    WORD32 i;
2842
2843
    /* coded pic count */
2844
4.22k
    ps_codec->i4_poc = 0;
2845
2846
    /* Number of API calls to encode are made */
2847
4.22k
    ps_codec->i4_encode_api_call_cnt = -1;
2848
2849
    /* Indicates no header has been generated yet */
2850
4.22k
    ps_codec->u4_header_generated = 0;
2851
2852
    /* Number of pictures encoded */
2853
4.22k
    ps_codec->i4_pic_cnt = -1;
2854
2855
    /* Number of threads created */
2856
4.22k
    ps_codec->i4_proc_thread_cnt = 0;
2857
2858
    /* ctl mutex init */
2859
4.22k
    ithread_mutex_init(ps_codec->pv_ctl_mutex);
2860
2861
4.22k
    if (ps_codec->s_cfg.u4_keep_threads_active)
2862
4.22k
    {
2863
        /* thread pool mutex init */
2864
4.22k
        ithread_mutex_init(ps_codec->s_thread_pool.pv_thread_pool_mutex);
2865
2866
        /* thread pool conditional init */
2867
4.22k
        ithread_cond_init(ps_codec->s_thread_pool.pv_thread_pool_cond);
2868
4.22k
    }
2869
2870
    /* Set encoder chroma format */
2871
4.22k
    ps_codec->e_codec_color_format =
2872
4.22k
                    (ps_cfg->e_inp_color_fmt == IV_YUV_420SP_VU) ?
2873
3.16k
                                    IV_YUV_420SP_VU : IV_YUV_420SP_UV;
2874
2875
    /* Number of continuous frames where deblocking was disabled */
2876
4.22k
    ps_codec->i4_disable_deblk_pic_cnt = 0;
2877
2878
    /* frame num */
2879
4.22k
    ps_codec->i4_frame_num = 0;
2880
2881
    /* set the current frame type to I frame, since we are going to start  encoding*/
2882
4.22k
    ps_codec->force_curr_frame_type = IV_NA_FRAME;
2883
2884
    /* idr_pic_id */
2885
4.22k
    ps_codec->i4_idr_pic_id = -1;
2886
2887
    /* Flush mode */
2888
4.22k
    ps_codec->i4_flush_mode = 0;
2889
2890
    /* Encode header mode */
2891
4.22k
    ps_codec->i4_header_mode = 0;
2892
2893
    /* Encode generate header */
2894
4.22k
    ps_codec->i4_gen_header = 0;
2895
2896
    /* To signal successful completion of init */
2897
4.22k
    ps_codec->i4_init_done = 1;
2898
2899
    /* To signal that at least one picture was decoded */
2900
4.22k
    ps_codec->i4_first_pic_done = 0;
2901
2902
    /* Reset Codec */
2903
4.22k
    ps_codec->i4_reset_flag = 0;
2904
2905
    /* Current error code */
2906
4.22k
    ps_codec->i4_error_code = IH264E_SUCCESS;
2907
2908
    /* threshold residue */
2909
4.22k
    ps_codec->u4_thres_resi = 1;
2910
2911
    /* inter gating enable */
2912
4.22k
    ps_codec->u4_inter_gate = 0;
2913
2914
    /* entropy mutex init */
2915
4.22k
    ithread_mutex_init(ps_codec->pv_entropy_mutex);
2916
2917
    /* sps id */
2918
4.22k
    ps_codec->i4_sps_id = 0;
2919
2920
    /* sps id */
2921
4.22k
    ps_codec->i4_pps_id = 0;
2922
2923
    /* Process thread created status */
2924
4.22k
    memset(ps_codec->ai4_process_thread_created, 0,
2925
4.22k
           sizeof(ps_codec->ai4_process_thread_created));
2926
2927
4.22k
    memset(&ps_codec->s_global_quality_stats, 0, sizeof(ps_codec->s_global_quality_stats));
2928
2929
    /* Number of MBs processed together */
2930
4.22k
    ps_codec->i4_proc_nmb = 8;
2931
2932
    /* Previous POC msb */
2933
4.22k
    ps_codec->i4_prev_poc_msb = 0;
2934
2935
    /* Previous POC lsb */
2936
4.22k
    ps_codec->i4_prev_poc_lsb = -1;
2937
2938
    /* max Previous POC lsb */
2939
4.22k
    ps_codec->i4_max_prev_poc_lsb = -1;
2940
2941
    /* sps, pps status */
2942
4.22k
    {
2943
4.22k
        sps_t *ps_sps = ps_codec->ps_sps_base;
2944
4.22k
        pps_t *ps_pps = ps_codec->ps_pps_base;
2945
2946
143k
        for (i = 0; i < MAX_SPS_CNT; i++)
2947
139k
        {
2948
139k
            ps_sps->i1_sps_valid = 0;
2949
139k
            ps_sps++;
2950
139k
        }
2951
2952
1.08M
        for (i = 0; i < MAX_PPS_CNT; i++)
2953
1.08M
        {
2954
1.08M
            ps_pps->i1_pps_valid = 0;
2955
1.08M
            ps_pps++;
2956
1.08M
        }
2957
4.22k
    }
2958
2959
4.22k
    {
2960
4.22k
        WORD32 max_mb_rows = ps_cfg->i4_ht_mbs;
2961
2962
4.22k
        WORD32 num_jobs = max_mb_rows * MAX_CTXT_SETS;
2963
4.22k
        WORD32 clz;
2964
2965
        /* Use next power of two number of entries*/
2966
4.22k
        clz = CLZ(num_jobs);
2967
4.22k
        num_jobs = 1 << (32 - clz);
2968
2969
        /* init process jobq */
2970
4.22k
        ps_codec->pv_proc_jobq = ih264_list_init(
2971
4.22k
                        ps_codec->pv_proc_jobq_buf,
2972
4.22k
                        ps_codec->i4_proc_jobq_buf_size, num_jobs,
2973
4.22k
                        sizeof(job_t), 10);
2974
4.22k
        RETURN_IF((ps_codec->pv_proc_jobq == NULL), IV_FAIL);
2975
4.22k
        ih264_list_reset(ps_codec->pv_proc_jobq);
2976
2977
        /* init entropy jobq */
2978
4.22k
        ps_codec->pv_entropy_jobq = ih264_list_init(
2979
4.22k
                        ps_codec->pv_entropy_jobq_buf,
2980
4.22k
                        ps_codec->i4_entropy_jobq_buf_size, num_jobs,
2981
4.22k
                        sizeof(job_t), 10);
2982
4.22k
        RETURN_IF((ps_codec->pv_entropy_jobq == NULL), IV_FAIL);
2983
4.22k
        ih264_list_reset(ps_codec->pv_entropy_jobq);
2984
4.22k
    }
2985
2986
    /* Update the jobq context to all the threads */
2987
38.0k
    for (i = 0; i < MAX_PROCESS_CTXT; i++)
2988
33.7k
    {
2989
33.7k
        ps_codec->as_process[i].pv_proc_jobq = ps_codec->pv_proc_jobq;
2990
33.7k
        ps_codec->as_process[i].pv_entropy_jobq = ps_codec->pv_entropy_jobq;
2991
2992
        /* i4_id always stays between 0 and MAX_PROCESS_THREADS */
2993
33.7k
        ps_codec->as_process[i].i4_id =
2994
33.7k
                        (i >= MAX_PROCESS_THREADS) ?
2995
33.7k
                                        (i - MAX_PROCESS_THREADS) : i;
2996
33.7k
        ps_codec->as_process[i].ps_codec = ps_codec;
2997
2998
33.7k
        ps_codec->as_process[i].s_entropy.pv_proc_jobq = ps_codec->pv_proc_jobq;
2999
33.7k
        ps_codec->as_process[i].s_entropy.pv_entropy_jobq =
3000
33.7k
                        ps_codec->pv_entropy_jobq;
3001
33.7k
        ps_codec->as_process[i].s_entropy.i4_abs_pic_order_cnt = -1;
3002
33.7k
    }
3003
3004
    /* Initialize MV Bank buffer manager */
3005
4.22k
    ps_codec->pv_mv_buf_mgr = ih264_buf_mgr_init(ps_codec->pv_mv_buf_mgr_base);
3006
3007
    /* Initialize Picture buffer manager for reference buffers*/
3008
4.22k
    ps_codec->pv_ref_buf_mgr = ih264_buf_mgr_init(
3009
4.22k
                    ps_codec->pv_ref_buf_mgr_base);
3010
3011
    /* Initialize Picture buffer manager for input buffers*/
3012
4.22k
    ps_codec->pv_inp_buf_mgr = ih264_buf_mgr_init(
3013
4.22k
                    ps_codec->pv_inp_buf_mgr_base);
3014
3015
    /* Initialize buffer manager for output buffers*/
3016
4.22k
    ps_codec->pv_out_buf_mgr = ih264_buf_mgr_init(
3017
4.22k
                    ps_codec->pv_out_buf_mgr_base);
3018
3019
    /* buffer cnt in buffer manager */
3020
4.22k
    ps_codec->i4_inp_buf_cnt = 0;
3021
4.22k
    ps_codec->i4_out_buf_cnt = 0;
3022
4.22k
    ps_codec->i4_ref_buf_cnt = 0;
3023
3024
4.22k
    ps_codec->ps_pic_buf = (pic_buf_t *) ps_codec->pv_pic_buf_base;
3025
4.22k
    memset(ps_codec->ps_pic_buf, 0, BUF_MGR_MAX_CNT * sizeof(pic_buf_t));
3026
3027
    /* Initialize dpb manager */
3028
4.22k
    ih264_dpb_mgr_init((dpb_mgr_t*) ps_codec->pv_dpb_mgr);
3029
3030
4.22k
    memset(ps_codec->as_ref_set, 0,
3031
4.22k
           sizeof(ref_set_t) * (MAX_DPB_SIZE + MAX_CTXT_SETS));
3032
76.0k
    for (i = 0; i < (MAX_DPB_SIZE + MAX_CTXT_SETS); i++)
3033
71.7k
    {
3034
71.7k
        ps_codec->as_ref_set[i].i4_pic_cnt = -1;
3035
71.7k
    }
3036
3037
    /* fn ptr init */
3038
4.22k
    ih264e_init_function_ptr(ps_codec);
3039
3040
    /* reset status flags */
3041
8.44k
    for (i = 0; i < MAX_CTXT_SETS; i++)
3042
4.22k
    {
3043
4.22k
        ps_codec->au4_entropy_thread_active[i] = 0;
3044
4.22k
        ps_codec->ai4_pic_cnt[i] = -1;
3045
3046
4.22k
        ps_codec->s_rate_control.pre_encode_skip[i] = 0;
3047
4.22k
        ps_codec->s_rate_control.post_encode_skip[i] = 0;
3048
4.22k
    }
3049
3050
4.22k
    ps_codec->s_rate_control.num_intra_in_prev_frame = 0;
3051
4.22k
    ps_codec->s_rate_control.i4_avg_activity = 0;
3052
3053
4.22k
    return IV_SUCCESS;
3054
4.22k
}
3055
3056
/**
3057
*******************************************************************************
3058
*
3059
* @brief
3060
*  Gets number of memory records required by the codec
3061
*
3062
* @par Description:
3063
*  Gets codec memory requirements
3064
*
3065
* @param[in] pv_api_ip
3066
*  Pointer to input argument structure
3067
*
3068
* @param[out] pv_api_op
3069
*  Pointer to output argument structure
3070
*
3071
* @returns  status
3072
*
3073
* @remarks
3074
*
3075
*******************************************************************************
3076
*/
3077
static WORD32 ih264e_get_num_rec(void *pv_api_ip, void *pv_api_op)
3078
4.24k
{
3079
    /* api call I/O structures */
3080
4.24k
    ih264e_num_mem_rec_op_t *ps_op = pv_api_op;
3081
3082
4.24k
    UNUSED(pv_api_ip);
3083
3084
4.24k
    ps_op->s_ive_op.u4_num_mem_rec = MEM_REC_CNT;
3085
3086
4.24k
    return IV_SUCCESS;
3087
4.24k
}
3088
3089
/**
3090
*******************************************************************************
3091
*
3092
* @brief
3093
*  Fills memory records of the codec
3094
*
3095
* @par Description:
3096
*  Fills codec memory requirements
3097
*
3098
* @param[in] pv_api_ip
3099
*  Pointer to input argument structure
3100
*
3101
* @param[out] pv_api_op
3102
*  Pointer to output argument structure
3103
*
3104
* @returns error status
3105
*
3106
* @remarks none
3107
*
3108
*******************************************************************************
3109
*/
3110
static WORD32 ih264e_fill_num_mem_rec(void *pv_api_ip, void *pv_api_op)
3111
8.45k
{
3112
    /* api call I/O structures */
3113
8.45k
    ih264e_fill_mem_rec_ip_t *ps_ip = pv_api_ip;
3114
8.45k
    ih264e_fill_mem_rec_op_t *ps_op = pv_api_op;
3115
3116
    /* profile / level info */
3117
8.45k
    WORD32 level;
3118
8.45k
    WORD32 num_reorder_frames;
3119
8.45k
    WORD32 num_ref_frames;
3120
3121
    /* mem records */
3122
8.45k
    WORD32 no_of_mem_rec;
3123
8.45k
    iv_mem_rec_t *ps_mem_rec_base, *ps_mem_rec;
3124
3125
    /* frame dimensions */
3126
8.45k
    WORD32 max_wd_luma, max_ht_luma;
3127
8.45k
    WORD32 max_mb_rows, max_mb_cols, max_mb_cnt;
3128
3129
    /* temp var */
3130
8.45k
    WORD32 i;
3131
3132
    /* error status */
3133
8.45k
    IV_STATUS_T status = IV_SUCCESS;
3134
3135
8.45k
    num_reorder_frames = ps_ip->s_ive_ip.u4_max_reorder_cnt;
3136
8.45k
    num_ref_frames = ps_ip->s_ive_ip.u4_max_ref_cnt;
3137
3138
    /* mem records */
3139
8.45k
    ps_mem_rec_base = ps_ip->s_ive_ip.ps_mem_rec;
3140
8.45k
    no_of_mem_rec = ps_ip->s_ive_ip.u4_num_mem_rec;
3141
3142
    /* frame dimensions */
3143
8.45k
    max_ht_luma = ps_ip->s_ive_ip.u4_max_ht;
3144
8.45k
    max_wd_luma = ps_ip->s_ive_ip.u4_max_wd;
3145
8.45k
    max_ht_luma = ALIGN16(max_ht_luma);
3146
8.45k
    max_wd_luma = ALIGN16(max_wd_luma);
3147
8.45k
    max_mb_rows = max_ht_luma / MB_SIZE;
3148
8.45k
    max_mb_cols = max_wd_luma / MB_SIZE;
3149
8.45k
    max_mb_cnt = max_mb_rows * max_mb_cols;
3150
3151
    /* profile / level info */
3152
8.45k
    level = ih264e_get_min_level(max_wd_luma, max_ht_luma);
3153
3154
    /* validate params */
3155
8.45k
    if ((level < MIN_LEVEL) || (level > MAX_LEVEL))
3156
0
    {
3157
0
        ps_op->s_ive_op.u4_error_code |= IH264E_CODEC_LEVEL_NOT_SUPPORTED;
3158
0
        level = MAX_LEVEL;
3159
0
    }
3160
3161
8.45k
    if (num_ref_frames > MAX_REF_CNT)
3162
0
    {
3163
0
        ps_op->s_ive_op.u4_error_code |= IH264E_NUM_REF_UNSUPPORTED;
3164
0
        num_ref_frames = MAX_REF_CNT;
3165
0
    }
3166
3167
8.45k
    if (num_reorder_frames > MAX_REF_CNT)
3168
0
    {
3169
0
        ps_op->s_ive_op.u4_error_code |= IH264E_NUM_REORDER_UNSUPPORTED;
3170
0
        num_reorder_frames = MAX_REF_CNT;
3171
0
    }
3172
3173
    /* Set all memory records as persistent and alignment as 128 by default */
3174
8.45k
    ps_mem_rec = ps_mem_rec_base;
3175
439k
    for (i = 0; i < no_of_mem_rec; i++)
3176
431k
    {
3177
431k
        ps_mem_rec->u4_mem_alignment = 128;
3178
431k
        ps_mem_rec->e_mem_type = IV_EXTERNAL_CACHEABLE_PERSISTENT_MEM;
3179
431k
        ps_mem_rec++;
3180
431k
    }
3181
3182
    /************************************************************************
3183
     * Request memory for h264 encoder handle                               *
3184
     ***********************************************************************/
3185
8.45k
    ps_mem_rec = &ps_mem_rec_base[MEM_REC_IV_OBJ];
3186
8.45k
    {
3187
8.45k
        ps_mem_rec->u4_mem_size = sizeof(iv_obj_t);
3188
8.45k
    }
3189
8.45k
    DEBUG("\nMemory record Id %d = %d \n", MEM_REC_IV_OBJ, ps_mem_rec->u4_mem_size);
3190
3191
    /************************************************************************
3192
     * Request memory for h264 encoder context                              *
3193
     ***********************************************************************/
3194
8.45k
    ps_mem_rec = &ps_mem_rec_base[MEM_REC_CODEC];
3195
8.45k
    {
3196
8.45k
        ps_mem_rec->u4_mem_size = sizeof(codec_t);
3197
8.45k
    }
3198
8.45k
    DEBUG("\nMemory record Id %d = %d \n", MEM_REC_CODEC, ps_mem_rec->u4_mem_size);
3199
3200
    /************************************************************************
3201
     * Request memory for CABAC context                                     *
3202
     ***********************************************************************/
3203
8.45k
    ps_mem_rec = &ps_mem_rec_base[MEM_REC_CABAC];
3204
8.45k
    {
3205
8.45k
        ps_mem_rec->u4_mem_size = sizeof(cabac_ctxt_t);
3206
8.45k
    }
3207
8.45k
    DEBUG("\nMemory record Id %d = %d \n", MEM_REC_CABAC, ps_mem_rec->u4_mem_size);
3208
3209
    /************************************************************************
3210
     * Request memory for CABAC MB info                                     *
3211
     ***********************************************************************/
3212
8.45k
    ps_mem_rec = &ps_mem_rec_base[MEM_REC_CABAC_MB_INFO];
3213
8.45k
    {
3214
8.45k
        ps_mem_rec->u4_mem_size = ((max_mb_cols + 1) + 1)
3215
8.45k
                        * sizeof(mb_info_ctxt_t);
3216
8.45k
    }
3217
8.45k
    DEBUG("\nMemory record Id %d = %d \n", MEM_REC_CABAC_MB_INFO, ps_mem_rec->u4_mem_size);
3218
3219
3220
    /************************************************************************
3221
     *  Request memory for entropy context                                  *
3222
     *  In multi core encoding, each row is assumed to be launched on a     *
3223
     *  thread. The rows below can only start after its neighbors are coded *
3224
     *  The status of an mb coded/uncoded is signaled via entropy map.      *
3225
     *         1. One word32 to store skip run cnt                          *
3226
     *         2. mb entropy map (mb status entropy coded/uncoded). The size*
3227
     *            of the entropy map is max mb cols. Further allocate one   *
3228
     *            more additional row to evade checking for row -1.         *
3229
     *         3. size of bit stream buffer to store bit stream ctxt.       *
3230
     *         4. Entropy coding is dependent on nnz coefficient count for  *
3231
     *            the neighbor blocks. It is sufficient to maintain one row *
3232
     *            worth of nnz as entropy for lower row waits on entropy map*
3233
     ************************************************************************/
3234
8.45k
    ps_mem_rec = &ps_mem_rec_base[MEM_REC_ENTROPY];
3235
8.45k
    {
3236
        /* total size of the mem record */
3237
8.45k
        WORD32 total_size = 0;
3238
3239
        /* size of skip mb run */
3240
8.45k
        total_size += sizeof(WORD32);
3241
8.45k
        total_size = ALIGN8(total_size);
3242
3243
        /* size in bytes to store entropy status of an entire frame */
3244
8.45k
        total_size += (max_mb_cols * max_mb_rows);
3245
        /* add an additional 1 row of bytes to evade the special case of row 0 */
3246
8.45k
        total_size += max_mb_cols;
3247
8.45k
        total_size = ALIGN128(total_size);
3248
3249
        /* size of bit stream buffer */
3250
8.45k
        total_size += sizeof(bitstrm_t);
3251
8.45k
        total_size = ALIGN128(total_size);
3252
3253
        /* top nnz luma */
3254
8.45k
        total_size += (max_mb_cols * 4 * sizeof(UWORD8));
3255
8.45k
        total_size = ALIGN128(total_size);
3256
3257
        /* top nnz cbcr */
3258
8.45k
        total_size += (max_mb_cols * 4 * sizeof(UWORD8));
3259
8.45k
        total_size = ALIGN128(total_size);
3260
3261
        /* total size per each proc ctxt */
3262
8.45k
        total_size *= MAX_CTXT_SETS;
3263
3264
8.45k
        ps_mem_rec->u4_mem_size = total_size;
3265
8.45k
    }
3266
8.45k
    DEBUG("\nMemory record Id %d = %d \n", MEM_REC_ENTROPY, ps_mem_rec->u4_mem_size);
3267
3268
    /************************************************************************
3269
     *  The residue coefficients that needs to be entropy coded are packed  *
3270
     *  at a buffer space by the proc threads. The entropy thread shall     *
3271
     *  read from the buffer space, unpack them and encode the same. The    *
3272
     *  buffer space required to pack a row of mbs are as follows.          *
3273
     *  Assuming transform_8x8_flag is disabled,                            *
3274
     *  In the worst case, 1 mb contains 1 dc 4x4 luma sub block, followed  *
3275
     *  by 16 ac 4x4 luma sub blocks, 2 dc chroma 2x2 sub blocks, followed  *
3276
     *  by 8 ac 4x4 chroma sub blocks.                                      *
3277
     *  For the sake of simplicity we assume that all sub blocks are of     *
3278
     *  type 4x4. The packing of each 4x4 is depicted by the structure      *
3279
     *  tu_sblk_coeff_data_t                                                *
3280
     ************************************************************************/
3281
8.45k
    ps_mem_rec = &ps_mem_rec_base[MEM_REC_MB_COEFF_DATA];
3282
8.45k
    {
3283
        /* temp var */
3284
8.45k
        WORD32 size = 0;
3285
3286
        /* size of coeff data of 1 mb */
3287
8.45k
        size += sizeof(tu_sblk_coeff_data_t) * MAX_4x4_SUBBLKS;
3288
3289
        /* size of coeff data of 1 row of mb's */
3290
8.45k
        size *= max_mb_cols;
3291
3292
        /* align to avoid any false sharing across threads */
3293
8.45k
        size = ALIGN64(size);
3294
3295
        /* size for one full frame */
3296
8.45k
        size *= max_mb_rows;
3297
3298
        /* size of each proc buffer set (ping, pong) */
3299
8.45k
        size *= MAX_CTXT_SETS;
3300
3301
8.45k
        ps_mem_rec->u4_mem_size = size;
3302
8.45k
    }
3303
8.45k
    DEBUG("\nMemory record Id %d = %d \n", MEM_REC_MB_COEFF_DATA, ps_mem_rec->u4_mem_size);
3304
3305
    /************************************************************************
3306
     *  while encoding an mb, the mb header data is signaled to the entropy*
3307
     *  thread by writing to a buffer space. the size of header data per mb *
3308
     *  is assumed to be 40 bytes                                           *
3309
     *  TODO: revisit this inference                                        *
3310
     ************************************************************************/
3311
8.45k
    ps_mem_rec = &ps_mem_rec_base[MEM_REC_MB_HEADER_DATA];
3312
8.45k
    {
3313
        /* temp var */
3314
8.45k
        WORD32 size;
3315
3316
        /* size per MB */
3317
8.45k
        size = 40;
3318
3319
        /* size for 1 row of mbs */
3320
8.45k
        size = size * max_mb_cols;
3321
3322
        /* align to avoid any false sharing across threads */
3323
8.45k
        size = ALIGN64(size);
3324
3325
        /* size for one full frame */
3326
8.45k
        size *= max_mb_rows;
3327
3328
        /* size of each proc buffer set (ping, pong) */
3329
8.45k
        size *= MAX_CTXT_SETS;
3330
3331
8.45k
        ps_mem_rec->u4_mem_size = size;
3332
8.45k
    }
3333
8.45k
    DEBUG("\nMemory record Id %d = %d \n", MEM_REC_MB_HEADER_DATA, ps_mem_rec->u4_mem_size);
3334
3335
    /************************************************************************
3336
     *  Size for holding mv_buf_t for each MV Bank.                         *
3337
     *  Note this allocation is done for BUF_MGR_MAX_CNT instead of         *
3338
     *  MAX_DPB_SIZE or max_dpb_size for following reasons                  *
3339
     *  max_dpb_size will be based on max_wd and max_ht                     *
3340
     *  For higher max_wd and max_ht this number will be smaller than       *
3341
     *  MAX_DPB_SIZE But during actual initialization number of buffers     *
3342
     *  allocated can be more.                                              *
3343
     *                                                                      *
3344
     *  One extra MV Bank is needed to hold current pics MV bank.           *
3345
     *  Since this is only a structure allocation and not actual buffer     *
3346
     *  allocation, it is allocated for BUF_MGR_MAX_CNT entries             *
3347
     ************************************************************************/
3348
8.45k
    ps_mem_rec = &ps_mem_rec_base[MEM_REC_MVBANK];
3349
8.45k
    {
3350
        /* max luma samples */
3351
8.45k
        WORD32 max_luma_samples = 0;
3352
3353
        /* determine max luma samples */
3354
143k
        for (i = 0; i < 16; i++)
3355
135k
            if (level ==(WORD32)gas_ih264_lvl_tbl[i].u4_level_idc)
3356
8.45k
                max_luma_samples = gas_ih264_lvl_tbl[i].u4_max_fs
3357
8.45k
                                << (BLK_SIZE + BLK_SIZE);
3358
3359
8.45k
        ps_mem_rec->u4_mem_size = ih264_buf_mgr_size();
3360
3361
        /************************************************************************
3362
         * Allocate for pu_map, enc_pu_t and pic_pu_idx for each MV bank        *
3363
         * Note: Number of luma samples is not max_wd * max_ht here, instead it *
3364
         * is set to maximum number of luma samples allowed at the given level. *
3365
         * This is done to ensure that any stream with width and height lesser  *
3366
         * than max_wd and max_ht is supported. Number of buffers required can  *
3367
         * be greater for lower width and heights at a given level and this     *
3368
         * increased number of buffers might require more memory than what      *
3369
         * max_wd and max_ht buffer would have required Also note one extra     *
3370
         * buffer is allocated to store current pictures MV bank.                *
3371
         ***********************************************************************/
3372
3373
8.45k
        ps_mem_rec->u4_mem_size += BUF_MGR_MAX_CNT * sizeof(mv_buf_t);
3374
3375
8.45k
        ps_mem_rec->u4_mem_size += (num_ref_frames + num_reorder_frames
3376
8.45k
                        + MAX_CTXT_SETS)
3377
8.45k
                        * ih264e_get_pic_mv_bank_size(max_luma_samples);
3378
8.45k
    }
3379
8.45k
    DEBUG("\nMemory record Id %d = %d \n", MEM_REC_MVBANK, ps_mem_rec->u4_mem_size);
3380
3381
    /************************************************************************
3382
     *  While encoding inter slices, to compute the cost of encoding an mb  *
3383
     *  with the mv's at hand, we employ the expression cost = sad + lambda *
3384
     *  x mv_bits. Here mv_bits is the total number of bits taken to represe*
3385
     *  nt the mv in the stream. The mv bits for all the possible mv are    *
3386
     *  stored in the look up table. The mem record for this look up table  *
3387
     *  is given below.                                                     *
3388
     ************************************************************************/
3389
8.45k
    ps_mem_rec = &ps_mem_rec_base[MEM_REC_MVBITS];
3390
8.45k
    {
3391
        /* max srch range x */
3392
8.45k
        UWORD32 u4_srch_range_x = ps_ip->s_ive_ip.u4_max_srch_rng_x;
3393
3394
        /* max srch range y */
3395
8.45k
        UWORD32 u4_srch_range_y = ps_ip->s_ive_ip.u4_max_srch_rng_y;
3396
3397
        /* max srch range */
3398
8.45k
        UWORD32 u4_max_srch_range = MAX(u4_srch_range_x, u4_srch_range_y);
3399
3400
        /* due to subpel */
3401
8.45k
        u4_max_srch_range <<= 2;
3402
3403
        /* due to mv on either direction */
3404
8.45k
        u4_max_srch_range = (u4_max_srch_range << 1);
3405
3406
        /* due to pred mv + zero */
3407
8.45k
        u4_max_srch_range = (u4_max_srch_range << 1) + 1;
3408
3409
8.45k
        u4_max_srch_range = ALIGN128(u4_max_srch_range);
3410
3411
8.45k
        ps_mem_rec->u4_mem_size = u4_max_srch_range;
3412
8.45k
    }
3413
8.45k
    DEBUG("\nMemory record Id %d = %d \n", MEM_REC_MVBITS, ps_mem_rec->u4_mem_size);
3414
3415
    /************************************************************************
3416
     *  Frame level Intra Cost Map. During intra/inter analysis preserve the*
3417
     *  intra mb cost for future complexity estimation.                     *
3418
     *  NOTE: The cost map is a overlay on the previous frame. In case if an*
3419
     *  mb is not intra analyzed, the cost here represents its collocated mb*
3420
     *  intra cost. This traversal can go till the latest I frame at worse  *
3421
     ************************************************************************/
3422
8.45k
    ps_mem_rec = &ps_mem_rec_base[MEM_REC_INTRA_COST];
3423
8.45k
    {
3424
        /* total size of the mem record */
3425
8.45k
        WORD32 total_size = 0;
3426
3427
        /* size in bytes to mb core coding status of an entire frame */
3428
8.45k
        total_size = max_mb_cnt * sizeof(WORD32);
3429
3430
8.45k
        ps_mem_rec->u4_mem_size = total_size;
3431
8.45k
    }
3432
8.45k
    DEBUG("\nMemory record Id %d = %d \n", MEM_REC_INTRA_COST, ps_mem_rec->u4_mem_size);
3433
3434
    /************************************************************************
3435
     * Request memory for SPS                                               *
3436
     ***********************************************************************/
3437
8.45k
    ps_mem_rec = &ps_mem_rec_base[MEM_REC_SPS];
3438
8.45k
    {
3439
8.45k
        ps_mem_rec->u4_mem_size = MAX_SPS_CNT * sizeof(sps_t);
3440
8.45k
    }
3441
8.45k
    DEBUG("\nMemory record Id %d = %d \n", MEM_REC_SPS, ps_mem_rec->u4_mem_size);
3442
3443
    /************************************************************************
3444
     * Request memory for PPS                                               *
3445
     ***********************************************************************/
3446
8.45k
    ps_mem_rec = &ps_mem_rec_base[MEM_REC_PPS];
3447
8.45k
    {
3448
8.45k
        ps_mem_rec->u4_mem_size = MAX_PPS_CNT * sizeof(pps_t);
3449
8.45k
    }
3450
8.45k
    DEBUG("\nMemory record Id %d = %d \n", MEM_REC_PPS, ps_mem_rec->u4_mem_size);
3451
3452
    /************************************************************************
3453
     * Request memory for Slice Header                                      *
3454
     ***********************************************************************/
3455
8.45k
    ps_mem_rec = &ps_mem_rec_base[MEM_REC_SLICE_HDR];
3456
8.45k
    {
3457
8.45k
        ps_mem_rec->u4_mem_size = MAX_CTXT_SETS * MAX_SLICE_HDR_CNT
3458
8.45k
                        * sizeof(slice_header_t);
3459
8.45k
    }
3460
8.45k
    DEBUG("\nMemory record Id %d = %d \n", MEM_REC_SLICE_HDR, ps_mem_rec->u4_mem_size);
3461
3462
    /************************************************************************
3463
     * Request memory for Adaptive Intra Refresh                            *
3464
     ***********************************************************************/
3465
8.45k
    ps_mem_rec = &ps_mem_rec_base[MEM_REC_AIR_MAP];
3466
8.45k
    {
3467
        /* total size of the mem record */
3468
8.45k
        WORD32 total_size = 0;
3469
3470
        /* intra coded map */
3471
8.45k
        total_size += max_mb_cnt;
3472
8.45k
        total_size *= MAX_CTXT_SETS;
3473
3474
        /* mb refresh map */
3475
8.45k
        total_size += sizeof(UWORD16) * max_mb_cnt;
3476
3477
        /* alignment */
3478
8.45k
        total_size = ALIGN128(total_size);
3479
3480
8.45k
        ps_mem_rec->u4_mem_size = total_size;
3481
8.45k
    }
3482
8.45k
    DEBUG("\nMemory record Id %d = %d \n", MEM_REC_AIR_MAP, ps_mem_rec->u4_mem_size);
3483
3484
    /************************************************************************
3485
     *  In multi slice encoding, this memory record helps tracking the start*
3486
     *  of slice with reference to mb.                                      *
3487
     *  MEM RECORD for holding                                              *
3488
     *         1. mb slice map                                              *
3489
     ************************************************************************/
3490
8.45k
    ps_mem_rec = &ps_mem_rec_base[MEM_REC_SLICE_MAP];
3491
8.45k
    {
3492
        /* total size of the mem record */
3493
8.45k
        WORD32 total_size = 0;
3494
3495
        /* size in bytes to slice index of all mbs of a frame */
3496
8.45k
        total_size = ALIGN64(max_mb_cnt);
3497
3498
        /* ih264e_update_proc_ctxt can overread by 1 at the end */
3499
8.45k
        total_size += 1;
3500
3501
        /* total size per each proc ctxt */
3502
8.45k
        total_size *= MAX_CTXT_SETS;
3503
8.45k
        ps_mem_rec->u4_mem_size = total_size;
3504
8.45k
    }
3505
8.45k
    DEBUG("\nMemory record Id %d = %d \n", MEM_REC_SLICE_MAP, ps_mem_rec->u4_mem_size);
3506
3507
    /************************************************************************
3508
     * Request memory to hold thread handles and synchronization variables  *
3509
     ************************************************************************/
3510
8.45k
    ps_mem_rec = &ps_mem_rec_base[MEM_REC_THREAD_HANDLE];
3511
8.45k
    {
3512
8.45k
        WORD32 thread_pool_size = 0;
3513
8.45k
        WORD32 handle_size = ithread_get_handle_size();
3514
3515
8.45k
        if (ps_ip->s_ive_ip.u4_keep_threads_active)
3516
8.45k
        {
3517
8.45k
            thread_pool_size += ithread_get_mutex_lock_size();
3518
8.45k
            thread_pool_size += ithread_get_cond_size();
3519
8.45k
        }
3520
3521
8.45k
        ps_mem_rec->u4_mem_size = thread_pool_size + (MAX_PROCESS_THREADS * handle_size);
3522
8.45k
    }
3523
8.45k
    DEBUG("\nMemory record Id %d = %d \n", MEM_REC_THREAD_HANDLE, ps_mem_rec->u4_mem_size);
3524
3525
    /************************************************************************
3526
     * Request memory to hold mutex for control calls                       *
3527
     ************************************************************************/
3528
8.45k
    ps_mem_rec = &ps_mem_rec_base[MEM_REC_CTL_MUTEX];
3529
8.45k
    {
3530
8.45k
        ps_mem_rec->u4_mem_size = ithread_get_mutex_lock_size();
3531
8.45k
    }
3532
8.45k
    DEBUG("\nMemory record Id %d = %d \n", MEM_REC_CTL_MUTEX, ps_mem_rec->u4_mem_size);
3533
3534
    /************************************************************************
3535
     * Request memory to hold mutex for entropy calls                       *
3536
     ************************************************************************/
3537
8.45k
    ps_mem_rec = &ps_mem_rec_base[MEM_REC_ENTROPY_MUTEX];
3538
8.45k
    {
3539
8.45k
        ps_mem_rec->u4_mem_size = ithread_get_mutex_lock_size();
3540
8.45k
    }
3541
8.45k
    DEBUG("\nMemory record Id %d = %d \n", MEM_REC_ENTROPY_MUTEX, ps_mem_rec->u4_mem_size);
3542
3543
    /************************************************************************
3544
     * Request memory to hold process jobs                                  *
3545
     ***********************************************************************/
3546
8.45k
    ps_mem_rec = &ps_mem_rec_base[MEM_REC_PROC_JOBQ];
3547
8.45k
    {
3548
        /* One process job per row of MBs */
3549
        /* Allocate for two pictures, so that wrap around can be handled easily */
3550
8.45k
        WORD32 num_jobs = max_mb_rows * MAX_CTXT_SETS;
3551
3552
8.45k
        WORD32 job_queue_size = ih264_list_size(num_jobs, sizeof(job_t));
3553
3554
8.45k
        ps_mem_rec->u4_mem_size = job_queue_size;
3555
8.45k
    }
3556
8.45k
    DEBUG("\nMemory record Id %d = %d \n", MEM_REC_PROC_JOBQ, ps_mem_rec->u4_mem_size);
3557
3558
    /************************************************************************
3559
     * Request memory to hold entropy jobs                                  *
3560
     ***********************************************************************/
3561
8.45k
    ps_mem_rec = &ps_mem_rec_base[MEM_REC_ENTROPY_JOBQ];
3562
8.45k
    {
3563
        /* One process job per row of MBs */
3564
        /* Allocate for two pictures, so that wrap around can be handled easily */
3565
8.45k
        WORD32 num_jobs = max_mb_rows * MAX_CTXT_SETS;
3566
3567
8.45k
        WORD32 job_queue_size = ih264_list_size(num_jobs, sizeof(job_t));
3568
3569
8.45k
        ps_mem_rec->u4_mem_size = job_queue_size;
3570
8.45k
    }
3571
8.45k
    DEBUG("\nMemory record Id %d = %d \n", MEM_REC_ENTROPY_JOBQ, ps_mem_rec->u4_mem_size);
3572
3573
    /************************************************************************
3574
     *  In multi core encoding, each row is assumed to be launched on a     *
3575
     *  thread. The rows below can only start after its neighbors are coded *
3576
     *  The status of an mb coded/uncoded is signaled via proc map.        *
3577
     *  MEM RECORD for holding                                              *
3578
     *         1. mb proc map (mb status core coded/uncoded)                *
3579
     ************************************************************************/
3580
8.45k
    ps_mem_rec = &ps_mem_rec_base[MEM_REC_PROC_MAP];
3581
8.45k
    {
3582
        /* total size of the mem record */
3583
8.45k
        WORD32 total_size = 0;
3584
3585
        /* size in bytes to mb core coding status of an entire frame */
3586
8.45k
        total_size = max_mb_cnt;
3587
3588
        /* add an additional 1 row of bytes to evade the special case of row 0 */
3589
8.45k
        total_size += max_mb_cols;
3590
3591
        /* total size per each proc ctxt */
3592
8.45k
        total_size *= MAX_CTXT_SETS;
3593
8.45k
        ps_mem_rec->u4_mem_size = total_size;
3594
8.45k
    }
3595
8.45k
    DEBUG("\nMemory record Id %d = %d \n", MEM_REC_PROC_MAP, ps_mem_rec->u4_mem_size);
3596
3597
    /************************************************************************
3598
     *  mem record for holding a particular MB is deblocked or not          *
3599
     *         1. mb deblk map (mb status deblocked/not deblocked)          *
3600
     ************************************************************************/
3601
8.45k
    ps_mem_rec = &ps_mem_rec_base[MEM_REC_DBLK_MAP];
3602
8.45k
    {
3603
        /* total size of the mem record */
3604
8.45k
        WORD32 total_size = 0;
3605
3606
        /* size in bytes to mb core coding status of an entire frame */
3607
8.45k
        total_size = max_mb_cnt;
3608
3609
        /* add an additional 1 row of bytes to evade the special case of row 0 */
3610
8.45k
        total_size += max_mb_cols;
3611
3612
8.45k
        total_size = ALIGN64(total_size);
3613
3614
        /* total size per each proc ctxt */
3615
8.45k
        total_size *= MAX_CTXT_SETS;
3616
8.45k
        ps_mem_rec->u4_mem_size = total_size;
3617
8.45k
    }
3618
8.45k
    DEBUG("\nMemory record Id %d = %d \n", MEM_REC_DBLK_MAP, ps_mem_rec->u4_mem_size);
3619
3620
    /************************************************************************
3621
     *  mem record for holding a particular MB's me is done or not          *
3622
     *         1. mb me map                                                 *
3623
     ************************************************************************/
3624
8.45k
    ps_mem_rec = &ps_mem_rec_base[MEM_REC_ME_MAP];
3625
8.45k
    {
3626
        /* total size of the mem record */
3627
8.45k
        WORD32 total_size = 0;
3628
3629
        /* size in bytes to mb core coding status of an entire frame */
3630
8.45k
        total_size = max_mb_cnt;
3631
3632
        /* add an additional 1 row of bytes to evade the special case of row 0 */
3633
8.45k
        total_size += max_mb_cols;
3634
3635
        /* total size per each proc ctxt */
3636
8.45k
        total_size *= MAX_CTXT_SETS;
3637
3638
8.45k
        ps_mem_rec->u4_mem_size = total_size;
3639
8.45k
    }
3640
8.45k
    DEBUG("\nMemory record Id %d = %d \n", MEM_REC_ME_MAP, ps_mem_rec->u4_mem_size);
3641
3642
    /************************************************************************
3643
     * size for holding dpb manager context                                 *
3644
     ************************************************************************/
3645
8.45k
    ps_mem_rec = &ps_mem_rec_base[MEM_REC_DPB_MGR];
3646
8.45k
    {
3647
8.45k
        ps_mem_rec->u4_mem_size = sizeof(dpb_mgr_t);
3648
8.45k
    }
3649
8.45k
    DEBUG("\nMemory record Id %d = %d \n", MEM_REC_DPB_MGR, ps_mem_rec->u4_mem_size);
3650
3651
    /************************************************************************
3652
     *  luma or chroma core coding involves mb estimation, error computation*
3653
     *  between the estimated singnal and the actual signal, transform the  *
3654
     *  error, quantize the error, then inverse transform and inverse quant *
3655
     *  ize the residue and add the result back to estimated signal.        *
3656
     *  To perform all these, a set of temporary buffers are needed.        *
3657
     *  MEM RECORD for holding scratch buffers                              *
3658
     *         1. prediction buffer used during mb mode analysis            *
3659
     *         2  temp. reference buffer when intra 4x4 with rdopt on is    *
3660
     *            enabled                                                   *
3661
     *            - when intra 4x4 is enabled, rdopt is on, to store the    *
3662
     *            reconstructed values and use them later this temp. buffer *
3663
     *            is used.                                                  *
3664
     *         3. prediction buffer used during intra mode analysis         *
3665
     *         4. prediction buffer used during intra 16x16 plane mode      *
3666
     *            analysis
3667
     *         5. prediction buffer used during intra chroma mode analysis  *
3668
     *         6. prediction buffer used during intra chroma 16x16 plane    *
3669
     *            mode analysis
3670
     *         7. forward transform output buffer                           *
3671
     *            - to store the error between estimated and the actual inp *
3672
     *              ut and to store the fwd transformed quantized output    *
3673
     *         8. forward transform output buffer                           *
3674
     *            - when intra 4x4 is enabled, rdopt is on, to store the    *
3675
     *            fwd transform values and use them later this temp. buffer *
3676
     *            is used.                                                  *
3677
     *         9. temporary buffer for inverse transform                    *
3678
     *            - temporary buffer used in inverse transform and inverse  *
3679
     *              quantization                                            *
3680
     *         A. Buffers for holding half_x , half_y and half_xy planes    *
3681
     ************************************************************************/
3682
8.45k
    ps_mem_rec = &ps_mem_rec_base[MEM_REC_PROC_SCRATCH];
3683
8.45k
    {
3684
8.45k
        WORD32 total_size = 0;
3685
8.45k
        WORD32 i4_tmp_size;
3686
3687
        /* size to hold prediction buffer */
3688
8.45k
        total_size += sizeof(UWORD8) * 16 * 16;
3689
8.45k
        total_size = ALIGN64(total_size);
3690
3691
        /* size to hold recon for intra 4x4 buffer */
3692
8.45k
        total_size += sizeof(UWORD8) * 16 * 16;
3693
8.45k
        total_size = ALIGN64(total_size);
3694
3695
        /* prediction buffer intra 16x16 */
3696
8.45k
        total_size += sizeof(UWORD8) * 16 * 16;
3697
8.45k
        total_size = ALIGN64(total_size);
3698
3699
        /* prediction buffer intra 16x16 plane*/
3700
8.45k
        total_size += sizeof(UWORD8) * 16 * 16;
3701
8.45k
        total_size = ALIGN64(total_size);
3702
3703
        /* prediction buffer intra chroma*/
3704
8.45k
        total_size += sizeof(UWORD8) * 16 * 8;
3705
8.45k
        total_size = ALIGN64(total_size);
3706
3707
        /* prediction buffer intra chroma plane*/
3708
8.45k
        total_size += sizeof(UWORD8) * 16 * 8;
3709
8.45k
        total_size = ALIGN64(total_size);
3710
3711
        /* size to hold fwd transform output */
3712
8.45k
        total_size += sizeof(WORD16) * SIZE_TRANS_BUFF;
3713
8.45k
        total_size = ALIGN64(total_size);
3714
3715
        /* size to hold fwd transform output */
3716
8.45k
        total_size += sizeof(WORD16) * SIZE_TRANS_BUFF;
3717
8.45k
        total_size = ALIGN64(total_size);
3718
3719
        /* size to hold temporary data during inverse transform */
3720
8.45k
        total_size += sizeof(WORD32) * SIZE_TMP_BUFF_ITRANS;
3721
8.45k
        total_size = ALIGN64(total_size);
3722
3723
        /* Buffers for holding half_x , half_y and half_xy planes */
3724
8.45k
        i4_tmp_size = sizeof(UWORD8) * (HP_BUFF_WD * HP_BUFF_HT);
3725
8.45k
        total_size += (ALIGN64(i4_tmp_size) * SUBPEL_BUFF_CNT);
3726
3727
        /* Allocate for each process thread */
3728
8.45k
        total_size *= MAX_PROCESS_CTXT;
3729
3730
8.45k
        ps_mem_rec->u4_mem_size = total_size;
3731
8.45k
    }
3732
8.45k
    DEBUG("\nMemory record Id %d = %d \n", MEM_REC_PROC_SCRATCH, ps_mem_rec->u4_mem_size);
3733
3734
    /************************************************************************
3735
     *  When transform_8x8_flag is disabled, the size of a sub block is     *
3736
     *  4x4 and when the transform_8x8_flag is enabled the size of the sub  *
3737
     *  block is 8x8. The threshold matrix and the forward scaling list     *
3738
     *  is of the size of the sub block.                                    *
3739
     *  MEM RECORD for holding                                              *
3740
     *         1. quantization parameters for plane y, cb, cr               *
3741
     *            - threshold matrix for quantization                       *
3742
     *            - forward weight matrix                                   *
3743
     *            - satqd threshold matrix                                  *
3744
     ************************************************************************/
3745
8.45k
    ps_mem_rec = &ps_mem_rec_base[MEM_REC_QUANT_PARAM];
3746
8.45k
    {
3747
        /* total size of the mem record */
3748
8.45k
        WORD32 total_size = 0;
3749
3750
        /* quantization parameter list for planes y,cb and cr */
3751
8.45k
        total_size += ALIGN64(sizeof(quant_params_t)) * 3;
3752
3753
        /* size of threshold matrix for quantization
3754
         * (assuming the transform_8x8_flag is disabled).
3755
         * for all 3 planes */
3756
8.45k
        total_size += ALIGN64(sizeof(WORD16) * 4 * 4) * 3;
3757
3758
        /* size of forward weight matrix for quantization
3759
         * (assuming the transform_8x8_flag is disabled).
3760
         * for all 3 planes */
3761
8.45k
        total_size += ALIGN64(sizeof(WORD16) * 4 * 4) * 3;
3762
3763
        /* Size for SATDQ threshold matrix for palnes y, cb and cr */
3764
8.45k
        total_size += ALIGN64(sizeof(UWORD16) * 9) * 3;
3765
3766
        /* total size per each proc thread */
3767
8.45k
        total_size *= MAX_PROCESS_CTXT;
3768
3769
8.45k
        ps_mem_rec->u4_mem_size = total_size;
3770
8.45k
    }
3771
8.45k
    DEBUG("\nMemory record Id %d = %d \n", MEM_REC_QUANT_PARAM, ps_mem_rec->u4_mem_size);
3772
3773
    /************************************************************************
3774
     *  While computing blocking strength for the current mb, the csbp, mb  *
3775
     *  type for the neighboring mbs are necessary. memtab for storing top  *
3776
     *  row mbtype and csbp is evaluated here.                              *
3777
     *                                                                      *
3778
     *  when encoding intra 4x4 or intra 8x8 the submb types are estimated  *
3779
     *  and sent. The estimation is dependent on neighbor mbs. For this     *
3780
     *  store the top row sub mb types for intra mbs                        *
3781
     *                                                                      *
3782
     *  During motion vector prediction, the curr mb mv is predicted from   *
3783
     *  neigbors left, top, top right and sometimes top left depending on   *
3784
     *  the availability. The top and top right content is accessed from    *
3785
     *  the memtab specified below.                                         *
3786
     ************************************************************************/
3787
8.45k
    ps_mem_rec = &ps_mem_rec_base[MEM_REC_TOP_ROW_SYN_INFO];
3788
8.45k
    {
3789
        /* total size of the mem record */
3790
8.45k
        WORD32 total_size = 0;
3791
3792
        /* size in bytes to store  1 row of mb_info_t */
3793
        /* one additional mb, to avoid checking end of row condition */
3794
8.45k
        total_size += (max_mb_cols + 1) * sizeof(mb_info_t);
3795
3796
        /* size in bytes to store  1 row of intra macroblock sub modes */
3797
8.45k
        total_size += max_mb_cols * sizeof(UWORD8) * 16;
3798
3799
        /* size in bytes to store  1 row + 1 of enc_pu_t */
3800
        /* one additional mb, to avoid checking end of row condition */
3801
8.45k
        total_size += (max_mb_cols + 1) * sizeof(enc_pu_t);
3802
3803
        /* total size per proc ctxt */
3804
8.45k
        total_size = ALIGN128(total_size);
3805
3806
        /* total size per each proc ctxt */
3807
8.45k
        total_size *= MAX_CTXT_SETS;
3808
8.45k
        ps_mem_rec->u4_mem_size = total_size;
3809
8.45k
    }
3810
8.45k
    DEBUG("\nMemory record Id %d = %d \n", MEM_REC_TOP_ROW_SYN_INFO, ps_mem_rec->u4_mem_size);
3811
3812
    /************************************************************************
3813
     *  When transform_8x8_flag is disabled, the mb is partitioned into     *
3814
     *  4 sub blocks. This corresponds to 1 vertical left edge and 1        *
3815
     *  vertical inner edge, 1 horizontal top edge and 1 horizontal         *
3816
     *  inner edge per mb. Further, When transform_8x8_flag is enabled,     *
3817
     *  the mb is partitioned in to 16 sub blocks. This corresponds to      *
3818
     *  1 vertical left edge and 3 vertical inner edges, 1 horizontal top   *
3819
     *  edge and 3 horizontal inner edges per mb.                           *
3820
     *  MEM RECORD for holding                                              *
3821
     *         1. vertical edge blocking strength                           *
3822
     *         2. horizontal edge blocking strength                         *
3823
     *         3. mb qp                                                     *
3824
     *         all are frame level                                          *
3825
     ************************************************************************/
3826
8.45k
    ps_mem_rec = &ps_mem_rec_base[MEM_REC_BS_QP];
3827
8.45k
    {
3828
        /* total size of the mem record */
3829
8.45k
        WORD32 total_size = 0;
3830
3831
        /* size in bytes to store vertical edge bs, horizontal edge bs and qp of every mb*/
3832
8.45k
        WORD32 vert_bs_size, horz_bs_size, qp_size;
3833
3834
        /* vertical edge bs = total number of vertical edges * number of bytes per each edge */
3835
        /* total num of v edges = total mb * 4 (assuming transform_8x8_flag = 0),
3836
         * each edge is formed by 4 pairs of subblks, requiring 4 bytes to storing bs */
3837
8.45k
        vert_bs_size = ALIGN64(max_mb_cnt * 4 * 4);
3838
3839
        /* horizontal edge bs = total number of horizontal edges * number of bytes per each edge */
3840
        /* total num of h edges = total mb * 4 (assuming transform_8x8_flag = 0),
3841
         * each edge is formed by 4 pairs of subblks, requiring 4 bytes to storing bs */
3842
8.45k
        horz_bs_size = ALIGN64(max_mb_cnt * 4 * 4);
3843
3844
        /* qp of each mb requires 1 byte */
3845
8.45k
        qp_size = ALIGN64(max_mb_cnt);
3846
3847
        /* total size */
3848
8.45k
        total_size = vert_bs_size + horz_bs_size + qp_size;
3849
3850
        /* total size per each proc ctxt */
3851
8.45k
        total_size *= MAX_CTXT_SETS;
3852
3853
8.45k
        ps_mem_rec->u4_mem_size = total_size;
3854
8.45k
    }
3855
8.45k
    DEBUG("\nMemory record Id %d = %d \n", MEM_REC_BS_QP, ps_mem_rec->u4_mem_size);
3856
3857
    /************************************************************************
3858
     * size for holding dpb manager context                                 *
3859
     ************************************************************************/
3860
8.45k
    ps_mem_rec = &ps_mem_rec_base[MEM_REC_INP_PIC];
3861
8.45k
    {
3862
8.45k
        ps_mem_rec->u4_mem_size = ih264_buf_mgr_size();
3863
8.45k
    }
3864
8.45k
    DEBUG("\nMemory record Id %d = %d \n", MEM_REC_INP_PIC, ps_mem_rec->u4_mem_size);
3865
3866
    /************************************************************************
3867
     * size for holding dpb manager context                                 *
3868
     ************************************************************************/
3869
8.45k
    ps_mem_rec = &ps_mem_rec_base[MEM_REC_OUT];
3870
8.45k
    {
3871
8.45k
        ps_mem_rec->u4_mem_size = ih264_buf_mgr_size();
3872
8.45k
    }
3873
8.45k
    DEBUG("\nMemory record Id %d = %d \n", MEM_REC_OUT, ps_mem_rec->u4_mem_size);
3874
3875
    /************************************************************************
3876
     * Size for color space conversion                                      *
3877
     ************************************************************************/
3878
8.45k
    ps_mem_rec = &ps_mem_rec_base[MEM_REC_CSC];
3879
8.45k
    {
3880
        /* We need a total a memory for a single frame of 420 sp, ie
3881
         * (wd * ht) for luma and (wd * ht / 2) for chroma*/
3882
8.45k
        ps_mem_rec->u4_mem_size = MAX_CTXT_SETS
3883
8.45k
                        * ((3 * max_ht_luma * max_wd_luma) >> 1);
3884
        /* Allocate an extra row, since inverse transform functions for
3885
         * chroma access(only read, not used) few extra bytes due to
3886
         * interleaved input
3887
         */
3888
8.45k
        ps_mem_rec->u4_mem_size += max_wd_luma;
3889
8.45k
    }
3890
8.45k
    DEBUG("\nMemory record Id %d = %d \n", MEM_REC_CSC, ps_mem_rec->u4_mem_size);
3891
3892
    /************************************************************************
3893
     *  Size for holding pic_buf_t for each reference picture               *
3894
     *  Note this allocation is done for BUF_MGR_MAX_CNT instead of         *
3895
     *  MAX_DPB_SIZE or max_dpb_size for following reasons                  *
3896
     *  max_dpb_size will be based on max_wd and max_ht                     *
3897
     *  For higher max_wd and max_ht this number will be smaller than       *
3898
     *  MAX_DPB_SIZE But during actual initialization number of buffers     *
3899
     *  allocated can be more.                                              *
3900
     *                                                                      *
3901
     *  Also to handle display depth application can allocate more than     *
3902
     *  what codec asks for in case of non-shared mode                      *
3903
     *  Since this is only a structure allocation and not actual buffer     *
3904
     *  allocation, it is allocated for BUF_MGR_MAX_CNT entries             *
3905
     ************************************************************************/
3906
8.45k
    ps_mem_rec = &ps_mem_rec_base[MEM_REC_REF_PIC];
3907
8.45k
    {
3908
8.45k
        ps_mem_rec->u4_mem_size = ih264_buf_mgr_size();
3909
8.45k
        ps_mem_rec->u4_mem_size += BUF_MGR_MAX_CNT * sizeof(pic_buf_t);
3910
3911
        /************************************************************************
3912
         * Note: Number of luma samples is not max_wd * max_ht here, instead it *
3913
         * is set to maximum number of luma samples allowed at the given level. *
3914
         * This is done to ensure that any stream with width and height lesser  *
3915
         * than max_wd and max_ht is supported. Number of buffers required can  *
3916
         * be greater for lower width and heights at a given level and this     *
3917
         * increased number of buffers might require more memory than what      *
3918
         * max_wd and max_ht buffer would have required. Number of buffers is   *
3919
         * doubled in order to return one frame at a time instead of sending    *
3920
         * multiple outputs during dpb full case. Also note one extra buffer is *
3921
         * allocted to store current picture.                                   *
3922
         *                                                                      *
3923
         * Half-pel planes for each reference buffer are allocated along with   *
3924
         * the reference buffer. So each reference buffer is 4 times the        *
3925
         * required size. This way buffer management for the half-pel planes is *
3926
         * easier and while using the half-pel planes in MC, an offset can be   *
3927
         * used from a single pointer                                           *
3928
         ***********************************************************************/
3929
8.45k
        ps_mem_rec->u4_mem_size += HPEL_PLANES_CNT
3930
8.45k
                        * ih264e_get_total_pic_buf_size(
3931
8.45k
                                        max_wd_luma * max_ht_luma, level,
3932
8.45k
                                        PAD_WD, PAD_HT, num_ref_frames,
3933
8.45k
                                        num_reorder_frames);
3934
8.45k
    }
3935
8.45k
    DEBUG("\nMemory record Id %d = %d \n", MEM_REC_REF_PIC, ps_mem_rec->u4_mem_size);
3936
3937
    /************************************************************************
3938
     * Request memory to hold mem recs to be returned during retrieve call  *
3939
     ************************************************************************/
3940
8.45k
    ps_mem_rec = &ps_mem_rec_base[MEM_REC_BACKUP];
3941
8.45k
    {
3942
8.45k
        ps_mem_rec->u4_mem_size = MEM_REC_CNT * sizeof(iv_mem_rec_t);
3943
8.45k
    }
3944
8.45k
    DEBUG("\nMemory record Id %d = %d \n", MEM_REC_BACKUP, ps_mem_rec->u4_mem_size);
3945
3946
    /************************************************************************
3947
     * size for memory required by NMB info structs and buffer for storing  *
3948
     * half pel plane                                                       *
3949
     ************************************************************************/
3950
8.45k
    ps_mem_rec = &ps_mem_rec_base[MEM_REC_MB_INFO_NMB];
3951
8.45k
    {
3952
8.45k
        ps_mem_rec->u4_mem_size = MAX_PROCESS_CTXT * max_mb_cols *
3953
8.45k
                                 (sizeof(mb_info_nmb_t) + MB_SIZE * MB_SIZE
3954
8.45k
                                  * sizeof(UWORD8));
3955
8.45k
    }
3956
8.45k
    DEBUG("\nMemory record Id %d = %d \n", MEM_REC_MB_INFO_NMB, ps_mem_rec->u4_mem_size);
3957
3958
    /************************************************************************
3959
     * RC mem records                                                       *
3960
     ************************************************************************/
3961
8.45k
    ps_mem_rec = &ps_mem_rec_base[MEM_REC_RC];
3962
8.45k
    {
3963
8.45k
        ih264e_get_rate_control_mem_tab(NULL, ps_mem_rec, FILL_MEMTAB);
3964
8.45k
    }
3965
8.45k
    DEBUG("\nMemory record Id %d = %d \n", MEM_REC_RC, ps_mem_rec->u4_mem_size);
3966
3967
    /* Each memtab size is aligned to next multiple of 128 bytes */
3968
    /* This is to ensure all the memtabs start at different cache lines */
3969
8.45k
    ps_mem_rec = ps_mem_rec_base;
3970
439k
    for (i = 0; i < MEM_REC_CNT; i++)
3971
431k
    {
3972
431k
        ps_mem_rec->u4_mem_size = ALIGN128(ps_mem_rec->u4_mem_size);
3973
431k
        ps_mem_rec++;
3974
431k
    }
3975
3976
8.45k
    ps_op->s_ive_op.u4_num_mem_rec = MEM_REC_CNT;
3977
3978
8.45k
    DEBUG("Num mem recs in fill call : %d\n", ps_op->s_ive_op.u4_num_mem_rec);
3979
3980
8.45k
    return (status);
3981
8.45k
}
3982
3983
/**
3984
*******************************************************************************
3985
*
3986
* @brief
3987
*  Initializes from mem records passed to the codec
3988
*
3989
* @par Description:
3990
*  Initializes pointers based on mem records passed
3991
*
3992
* @param[in] ps_codec_obj
3993
*  Pointer to codec object at API level
3994
*
3995
* @param[in] pv_api_ip
3996
*  Pointer to input argument structure
3997
*
3998
* @param[out] pv_api_op
3999
*  Pointer to output argument structure
4000
*
4001
* @returns error status
4002
*
4003
* @remarks none
4004
*
4005
*******************************************************************************
4006
*/
4007
static WORD32 ih264e_init_mem_rec(iv_obj_t *ps_codec_obj,
4008
                                  void *pv_api_ip,
4009
                                  void *pv_api_op)
4010
4.22k
{
4011
    /* api call I/O structures */
4012
4.22k
    ih264e_init_ip_t *ps_ip = pv_api_ip;
4013
4.22k
    ih264e_init_op_t *ps_op = pv_api_op;
4014
4015
    /* mem records */
4016
4.22k
    iv_mem_rec_t *ps_mem_rec_base, *ps_mem_rec;
4017
4018
    /* codec variables */
4019
4.22k
    codec_t * ps_codec;
4020
4.22k
    cabac_ctxt_t *ps_cabac;
4021
4.22k
    mb_info_ctxt_t *ps_mb_map_ctxt_inc;
4022
4023
4.22k
    cfg_params_t *ps_cfg;
4024
4025
    /* frame dimensions */
4026
4.22k
    WORD32 max_wd_luma, max_ht_luma;
4027
4.22k
    WORD32 max_mb_rows, max_mb_cols, max_mb_cnt;
4028
4029
    /* temp var */
4030
4.22k
    WORD32 i, j;
4031
4.22k
    WORD32 status = IV_SUCCESS;
4032
4033
    /* frame dimensions */
4034
4.22k
    max_ht_luma = ALIGN16(ps_ip->s_ive_ip.u4_max_ht);
4035
4.22k
    max_wd_luma = ALIGN16(ps_ip->s_ive_ip.u4_max_wd);
4036
4.22k
    max_mb_rows = max_ht_luma / MB_SIZE;
4037
4.22k
    max_mb_cols = max_wd_luma / MB_SIZE;
4038
4.22k
    max_mb_cnt = max_mb_rows * max_mb_cols;
4039
4040
    /* mem records */
4041
4.22k
    ps_mem_rec_base = ps_ip->s_ive_ip.ps_mem_rec;
4042
    /* memset all allocated memory, except the first one. First buffer (i.e. i == MEM_REC_IV_OBJ)
4043
       is initialized by application before calling this init function */
4044
215k
    for (i = MEM_REC_CODEC; i < MEM_REC_CNT; i++)
4045
211k
    {
4046
211k
        ps_mem_rec = &ps_mem_rec_base[i];
4047
211k
        memset(ps_mem_rec->pv_base, 0, ps_mem_rec->u4_mem_size);
4048
211k
    }
4049
4050
    /* Init mem records */
4051
4.22k
    ps_mem_rec = &ps_mem_rec_base[MEM_REC_CODEC];
4052
4.22k
    {
4053
4.22k
        ps_codec_obj->pv_codec_handle = ps_mem_rec->pv_base;
4054
4.22k
        ps_codec = (codec_t *) (ps_codec_obj->pv_codec_handle);
4055
4.22k
    }
4056
    /* Init mem records_cabac ctxt */
4057
4.22k
    ps_mem_rec = &ps_mem_rec_base[MEM_REC_CABAC];
4058
4.22k
    {
4059
4.22k
        ps_cabac = (cabac_ctxt_t *)(ps_mem_rec->pv_base);
4060
4.22k
    }
4061
4062
    /* Init mem records mb info array for CABAC */
4063
4.22k
    ps_mem_rec = &ps_mem_rec_base[MEM_REC_CABAC_MB_INFO];
4064
4.22k
    {
4065
4.22k
        ps_mb_map_ctxt_inc = (mb_info_ctxt_t *)(ps_mem_rec->pv_base);
4066
4.22k
    }
4067
4068
    /* Note this memset can not be done in init() call, since init will called
4069
     during reset as well. And calling this during reset will mean all pointers
4070
     need to reinitialized */
4071
4.22k
    memset(ps_codec, 0, sizeof(codec_t));
4072
4.22k
    memset(ps_cabac, 0, sizeof(cabac_ctxt_t));
4073
4074
    /* Set default Config Params */
4075
4.22k
    ps_cfg = &ps_codec->s_cfg;
4076
4.22k
    ih264e_set_default_params(ps_cfg);
4077
4078
    /* Update config params as per input */
4079
4.22k
    ps_cfg->u4_max_wd = ALIGN16(ps_ip->s_ive_ip.u4_max_wd);
4080
4.22k
    ps_cfg->u4_max_ht = ALIGN16(ps_ip->s_ive_ip.u4_max_ht);
4081
4082
    /* Initialize dimensions to max dimensions during init */
4083
4.22k
    ps_cfg->u4_wd = ps_cfg->u4_disp_wd = ps_cfg->u4_max_wd;
4084
4.22k
    ps_cfg->u4_ht = ps_cfg->u4_disp_ht = ps_cfg->u4_max_ht;
4085
4086
4.22k
    ps_cfg->i4_wd_mbs = ps_cfg->u4_max_wd >> 4;
4087
4.22k
    ps_cfg->i4_ht_mbs = ps_cfg->u4_max_ht >> 4;
4088
4.22k
    ps_cfg->u4_max_ref_cnt = ps_ip->s_ive_ip.u4_max_ref_cnt;
4089
4.22k
    ps_cfg->u4_max_reorder_cnt = ps_ip->s_ive_ip.u4_max_reorder_cnt;
4090
4.22k
    ps_cfg->u4_max_level = ps_ip->s_ive_ip.u4_max_level;
4091
4.22k
    ps_cfg->e_inp_color_fmt = ps_ip->s_ive_ip.e_inp_color_fmt;
4092
4.22k
    ps_cfg->e_recon_color_fmt = ps_ip->s_ive_ip.e_recon_color_fmt;
4093
4.22k
    ps_cfg->u4_max_framerate = ps_ip->s_ive_ip.u4_max_framerate;
4094
4.22k
    ps_cfg->u4_max_bitrate = ps_ip->s_ive_ip.u4_max_bitrate;
4095
4.22k
    ps_cfg->u4_num_bframes = ps_ip->s_ive_ip.u4_num_bframes;
4096
4.22k
    ps_cfg->e_content_type = ps_ip->s_ive_ip.e_content_type;
4097
4.22k
    ps_cfg->u4_max_srch_rng_x = ps_ip->s_ive_ip.u4_max_srch_rng_x;
4098
4.22k
    ps_cfg->u4_max_srch_rng_y = ps_ip->s_ive_ip.u4_max_srch_rng_y;
4099
4.22k
    ps_cfg->e_slice_mode = ps_ip->s_ive_ip.e_slice_mode;
4100
4.22k
    ps_cfg->u4_slice_param = ps_ip->s_ive_ip.u4_slice_param;
4101
4.22k
    ps_cfg->e_arch = ps_ip->s_ive_ip.e_arch;
4102
4.22k
    ps_cfg->e_soc = ps_ip->s_ive_ip.e_soc;
4103
4.22k
    ps_cfg->u4_enable_recon = ps_ip->s_ive_ip.u4_enable_recon;
4104
4.22k
    ps_cfg->e_rc_mode = ps_ip->s_ive_ip.e_rc_mode;
4105
4.22k
    ps_cfg->u4_keep_threads_active = ps_ip->s_ive_ip.u4_keep_threads_active;
4106
4107
    /* Validate params */
4108
4.22k
    if ((ps_ip->s_ive_ip.u4_max_level < MIN_LEVEL)
4109
4.22k
                    || (ps_ip->s_ive_ip.u4_max_level > MAX_LEVEL))
4110
0
    {
4111
0
        ps_op->s_ive_op.u4_error_code |= IH264E_CODEC_LEVEL_NOT_SUPPORTED;
4112
0
        ps_cfg->u4_max_level = DEFAULT_MAX_LEVEL;
4113
0
    }
4114
4115
4.22k
    if (ps_ip->s_ive_ip.u4_max_ref_cnt > MAX_REF_CNT)
4116
0
    {
4117
0
        ps_op->s_ive_op.u4_error_code |= IH264E_NUM_REF_UNSUPPORTED;
4118
0
        ps_cfg->u4_max_ref_cnt = MAX_REF_CNT;
4119
0
    }
4120
4121
4.22k
    if (ps_ip->s_ive_ip.u4_max_reorder_cnt > MAX_REF_CNT)
4122
0
    {
4123
0
        ps_op->s_ive_op.u4_error_code |= IH264E_NUM_REORDER_UNSUPPORTED;
4124
0
        ps_cfg->u4_max_reorder_cnt = MAX_REF_CNT;
4125
0
    }
4126
4127
4.22k
    ps_mem_rec = &ps_mem_rec_base[MEM_REC_BACKUP];
4128
4.22k
    {
4129
4.22k
        ps_codec->ps_mem_rec_backup = (iv_mem_rec_t *) ps_mem_rec->pv_base;
4130
4131
4.22k
        memcpy(ps_codec->ps_mem_rec_backup, ps_mem_rec_base,
4132
4.22k
               MEM_REC_CNT * sizeof(iv_mem_rec_t));
4133
4.22k
    }
4134
4135
4.22k
    ps_mem_rec = &ps_mem_rec_base[MEM_REC_ENTROPY];
4136
4.22k
    {
4137
        /* temp var */
4138
4.22k
        WORD32 size = 0, offset;
4139
4140
38.0k
        for (i = 0; i < MAX_PROCESS_CTXT; i++)
4141
33.7k
        {
4142
33.7k
            if (i < MAX_PROCESS_CTXT / MAX_CTXT_SETS)
4143
33.7k
            {
4144
                /* base ptr */
4145
33.7k
                UWORD8 *pu1_buf = ps_mem_rec->pv_base;
4146
4147
                /* reset size */
4148
33.7k
                size = 0;
4149
4150
                /* skip mb run */
4151
33.7k
                ps_codec->as_process[i].s_entropy.pi4_mb_skip_run =
4152
33.7k
                                (void *) (pu1_buf + size);
4153
33.7k
                size += sizeof(WORD32);
4154
33.7k
                size = ALIGN8(size);
4155
4156
                /* entropy map */
4157
33.7k
                ps_codec->as_process[i].s_entropy.pu1_entropy_map =
4158
33.7k
                                (void *) (pu1_buf + size + max_mb_cols);
4159
                /* size in bytes to store entropy status of an entire frame */
4160
33.7k
                size += (max_mb_cols * max_mb_rows);
4161
                /* add an additional 1 row of bytes to evade the special case of row 0 */
4162
33.7k
                size += max_mb_cols;
4163
33.7k
                size = ALIGN128(size);
4164
4165
                /* bit stream ptr */
4166
33.7k
                ps_codec->as_process[i].s_entropy.ps_bitstrm = (void *) (pu1_buf
4167
33.7k
                                + size);
4168
33.7k
                size += sizeof(bitstrm_t);
4169
33.7k
                size = ALIGN128(size);
4170
4171
                /* nnz luma */
4172
33.7k
                ps_codec->as_process[i].s_entropy.pu1_top_nnz_luma =
4173
33.7k
                                (void *) (pu1_buf + size);
4174
33.7k
                size += (max_mb_cols * 4 * sizeof(UWORD8));
4175
33.7k
                size = ALIGN128(size);
4176
4177
                /* nnz chroma */
4178
33.7k
                ps_codec->as_process[i].s_entropy.pu1_top_nnz_cbcr =
4179
33.7k
                                (void *) (pu1_buf + size);
4180
33.7k
                size += (max_mb_cols * 4 * sizeof(UWORD8));
4181
33.7k
                size = ALIGN128(size);
4182
33.7k
                offset = size;
4183
                /* cabac Context */
4184
33.7k
                ps_codec->as_process[i].s_entropy.ps_cabac = ps_cabac;
4185
33.7k
            }
4186
0
            else
4187
0
            {
4188
                /* base ptr */
4189
0
                UWORD8 *pu1_buf = ps_mem_rec->pv_base;
4190
4191
                /* reset size */
4192
0
                size = offset;
4193
4194
                /* skip mb run */
4195
0
                ps_codec->as_process[i].s_entropy.pi4_mb_skip_run =
4196
0
                                (void *) (pu1_buf + size);
4197
0
                size += sizeof(WORD32);
4198
0
                size = ALIGN8(size);
4199
4200
                /* entropy map */
4201
0
                ps_codec->as_process[i].s_entropy.pu1_entropy_map =
4202
0
                                (void *) (pu1_buf + size + max_mb_cols);
4203
                /* size in bytes to store entropy status of an entire frame */
4204
0
                size += (max_mb_cols * max_mb_rows);
4205
                /* add an additional 1 row of bytes to evade the special case of row 0 */
4206
0
                size += max_mb_cols;
4207
0
                size = ALIGN128(size);
4208
4209
                /* bit stream ptr */
4210
0
                ps_codec->as_process[i].s_entropy.ps_bitstrm = (void *) (pu1_buf
4211
0
                                + size);
4212
0
                size += sizeof(bitstrm_t);
4213
0
                size = ALIGN128(size);
4214
4215
                /* nnz luma */
4216
0
                ps_codec->as_process[i].s_entropy.pu1_top_nnz_luma =
4217
0
                                (void *) (pu1_buf + size);
4218
0
                size += (max_mb_cols * 4 * sizeof(UWORD8));
4219
0
                size = ALIGN128(size);
4220
4221
                /* nnz chroma */
4222
0
                ps_codec->as_process[i].s_entropy.pu1_top_nnz_cbcr =
4223
0
                                (void *) (pu1_buf + size);
4224
0
                size += (max_mb_cols * 4 * sizeof(UWORD8));
4225
0
                size = ALIGN128(size);
4226
                /* cabac Context */
4227
0
                ps_codec->as_process[i].s_entropy.ps_cabac = ps_cabac;
4228
0
           }
4229
33.7k
        }
4230
4.22k
        ps_codec->as_process[0].s_entropy.ps_cabac->ps_mb_map_ctxt_inc_base =
4231
4.22k
                        ps_mb_map_ctxt_inc;
4232
4.22k
    }
4233
4234
4.22k
    ps_mem_rec = &ps_mem_rec_base[MEM_REC_MB_COEFF_DATA];
4235
4.22k
    {
4236
        /* temp var */
4237
4.22k
        WORD32 size = 0, size_of_row;
4238
4.22k
        UWORD8 *pu1_buf = ps_mem_rec->pv_base;
4239
4240
        /* size of coeff data of 1 mb */
4241
4.22k
        size += sizeof(tu_sblk_coeff_data_t) * MAX_4x4_SUBBLKS;
4242
4243
        /* size of coeff data of 1 row of mb's */
4244
4.22k
        size *= max_mb_cols;
4245
4246
        /* align to avoid false sharing */
4247
4.22k
        size = ALIGN64(size);
4248
4.22k
        size_of_row = size;
4249
4250
        /* size for one full frame */
4251
4.22k
        size *= max_mb_rows;
4252
4253
4.22k
        ps_codec->u4_size_coeff_data = size_of_row;
4254
4255
38.0k
        for (i = 0; i < MAX_PROCESS_CTXT; i++)
4256
33.7k
        {
4257
33.7k
            if (i < MAX_PROCESS_CTXT / MAX_CTXT_SETS)
4258
33.7k
            {
4259
33.7k
                ps_codec->as_process[i].pv_pic_mb_coeff_data = pu1_buf;
4260
33.7k
                ps_codec->as_process[i].s_entropy.pv_pic_mb_coeff_data =
4261
33.7k
                                pu1_buf;
4262
33.7k
            }
4263
0
            else
4264
0
            {
4265
0
                ps_codec->as_process[i].pv_pic_mb_coeff_data = pu1_buf + size;
4266
0
                ps_codec->as_process[i].s_entropy.pv_pic_mb_coeff_data = pu1_buf
4267
0
                                + size;
4268
0
            }
4269
33.7k
        }
4270
4.22k
    }
4271
4272
4.22k
    ps_mem_rec = &ps_mem_rec_base[MEM_REC_MB_HEADER_DATA];
4273
4.22k
    {
4274
        /* temp var */
4275
4.22k
        WORD32 size, size_of_row;
4276
4.22k
        UWORD8 *pu1_buf = ps_mem_rec->pv_base;
4277
4278
        /* size of header data of 1 mb */
4279
4.22k
        size = sizeof(mb_hdr_t);
4280
4281
        /* size for 1 row of mbs */
4282
4.22k
        size = size * max_mb_cols;
4283
4284
        /* align to avoid any false sharing across threads */
4285
4.22k
        size = ALIGN64(size);
4286
4.22k
        size_of_row = size;
4287
4288
        /* size for one full frame */
4289
4.22k
        size *= max_mb_rows;
4290
4291
4.22k
        ps_codec->u4_size_header_data = size_of_row;
4292
4293
38.0k
        for (i = 0; i < MAX_PROCESS_CTXT; i++)
4294
33.7k
        {
4295
33.7k
            if (i < MAX_PROCESS_CTXT / MAX_CTXT_SETS)
4296
33.7k
            {
4297
33.7k
                ps_codec->as_process[i].pv_pic_mb_header_data = pu1_buf;
4298
33.7k
                ps_codec->as_process[i].s_entropy.pv_pic_mb_header_data =
4299
33.7k
                                pu1_buf;
4300
33.7k
            }
4301
0
            else
4302
0
            {
4303
0
                ps_codec->as_process[i].pv_pic_mb_header_data = pu1_buf + size;
4304
0
                ps_codec->as_process[i].s_entropy.pv_pic_mb_header_data =
4305
0
                                pu1_buf + size;
4306
0
            }
4307
33.7k
        }
4308
4.22k
    }
4309
4310
4.22k
    ps_mem_rec = &ps_mem_rec_base[MEM_REC_MVBANK];
4311
4.22k
    {
4312
        /* size of buf mgr struct */
4313
4.22k
        WORD32 size = ih264_buf_mgr_size();
4314
4315
        /* temp var */
4316
4.22k
        UWORD8 *pu1_buf = ps_mem_rec->pv_base;
4317
4318
        /* mv buffer mgr */
4319
4.22k
        ps_codec->pv_mv_buf_mgr_base = pu1_buf;
4320
4321
        /* mv bank */
4322
4.22k
        ps_codec->pv_mv_bank_buf_base = pu1_buf + size;
4323
4.22k
        ps_codec->i4_total_mv_bank_size = ps_mem_rec->u4_mem_size - size;
4324
4.22k
    }
4325
4326
4.22k
    ps_mem_rec = &ps_mem_rec_base[MEM_REC_MVBITS];
4327
4.22k
    {
4328
        /* max srch range x */
4329
4.22k
        UWORD32 u4_srch_range_x = ps_ip->s_ive_ip.u4_max_srch_rng_x;
4330
4331
        /* max srch range y */
4332
4.22k
        UWORD32 u4_srch_range_y = ps_ip->s_ive_ip.u4_max_srch_rng_y;
4333
4334
        /* max srch range */
4335
4.22k
        UWORD32 u4_max_srch_range = MAX(u4_srch_range_x, u4_srch_range_y);
4336
4337
        /* temp var */
4338
4.22k
        UWORD8 *pu1_buf = ps_mem_rec->pv_base;
4339
4340
        /* due to subpel */
4341
4.22k
        u4_max_srch_range <<= 2;
4342
4343
//        /* due to mv on either direction */
4344
//        u4_max_srch_range = (u4_max_srch_range << 1);
4345
4346
        /* due to pred mv + zero */
4347
4.22k
        u4_max_srch_range = (u4_max_srch_range << 1) + 1;
4348
4349
38.0k
        for (i = 0; i < MAX_PROCESS_CTXT; i++)
4350
33.7k
        {
4351
            /* me ctxt */
4352
33.7k
            me_ctxt_t *ps_mem_ctxt = &(ps_codec->as_process[i].s_me_ctxt);
4353
4354
            /* init at zero mv */
4355
33.7k
            ps_mem_ctxt->pu1_mv_bits = pu1_buf + u4_max_srch_range;
4356
33.7k
        }
4357
4.22k
    }
4358
4359
4.22k
    ps_mem_rec = &ps_mem_rec_base[MEM_REC_INTRA_COST];
4360
4.22k
    {
4361
4.22k
        ps_codec->pi4_mb_intra_cost = ps_mem_rec->pv_base;
4362
4.22k
    }
4363
4364
4.22k
    ps_mem_rec = &ps_mem_rec_base[MEM_REC_SPS];
4365
4.22k
    {
4366
4.22k
        ps_codec->ps_sps_base = (sps_t *) ps_mem_rec->pv_base;
4367
4.22k
    }
4368
4369
4.22k
    ps_mem_rec = &ps_mem_rec_base[MEM_REC_PPS];
4370
4.22k
    {
4371
4.22k
        ps_codec->ps_pps_base = (pps_t *) ps_mem_rec->pv_base;
4372
4.22k
    }
4373
4374
4.22k
    ps_mem_rec = &ps_mem_rec_base[MEM_REC_SLICE_HDR];
4375
4.22k
    {
4376
4.22k
        ps_codec->ps_slice_hdr_base = ps_mem_rec->pv_base;
4377
4378
38.0k
        for (i = 0; i < MAX_PROCESS_CTXT; i++)
4379
33.7k
        {
4380
33.7k
            if (i < MAX_PROCESS_CTXT / MAX_CTXT_SETS)
4381
33.7k
            {
4382
33.7k
                ps_codec->as_process[i].ps_slice_hdr_base = ps_mem_rec->pv_base;
4383
33.7k
            }
4384
0
            else
4385
0
            {
4386
                /* temp var */
4387
0
                WORD32 size = MAX_SLICE_HDR_CNT * sizeof(slice_header_t);
4388
0
                void *pv_buf = (UWORD8 *) ps_mem_rec->pv_base + size;
4389
4390
0
                ps_codec->as_process[i].ps_slice_hdr_base = pv_buf;
4391
0
            }
4392
33.7k
        }
4393
4.22k
    }
4394
4395
4.22k
    ps_mem_rec = &ps_mem_rec_base[MEM_REC_AIR_MAP];
4396
4.22k
    {
4397
        /* temp var */
4398
4.22k
        UWORD8 *pu1_buf = ps_mem_rec->pv_base;
4399
4400
38.0k
        for (i = 0; i < MAX_PROCESS_CTXT; i++)
4401
33.7k
        {
4402
33.7k
            if (i < MAX_PROCESS_CTXT / MAX_CTXT_SETS)
4403
33.7k
            {
4404
33.7k
                ps_codec->as_process[i].pu1_is_intra_coded = pu1_buf;
4405
33.7k
            }
4406
0
            else
4407
0
            {
4408
0
                ps_codec->as_process[i].pu1_is_intra_coded = pu1_buf
4409
0
                                + max_mb_cnt;
4410
0
            }
4411
33.7k
        }
4412
4413
4.22k
        ps_codec->pu2_intr_rfrsh_map = (UWORD16 *) (pu1_buf + max_mb_cnt * MAX_CTXT_SETS);
4414
4.22k
    }
4415
4416
4.22k
    ps_mem_rec = &ps_mem_rec_base[MEM_REC_SLICE_MAP];
4417
4.22k
    {
4418
        /* pointer to storage space */
4419
4.22k
        UWORD8 *pu1_buf_ping, *pu1_buf_pong;
4420
4421
        /* init pointer */
4422
4.22k
        pu1_buf_ping = ps_mem_rec->pv_base;
4423
4.22k
        pu1_buf_pong = pu1_buf_ping + ALIGN64(max_mb_cnt);
4424
4425
38.0k
        for (i = 0; i < MAX_PROCESS_CTXT; i++)
4426
33.7k
        {
4427
33.7k
            if (i < MAX_PROCESS_CTXT / MAX_CTXT_SETS)
4428
33.7k
            {
4429
33.7k
                ps_codec->as_process[i].pu1_slice_idx = pu1_buf_ping;
4430
33.7k
            }
4431
0
            else
4432
0
            {
4433
0
                ps_codec->as_process[i].pu1_slice_idx = pu1_buf_pong;
4434
0
            }
4435
33.7k
        }
4436
4.22k
    }
4437
4438
4.22k
    ps_mem_rec = &ps_mem_rec_base[MEM_REC_THREAD_HANDLE];
4439
4.22k
    {
4440
4.22k
        UWORD8 *pu1_buf = (UWORD8 *)ps_mem_rec->pv_base;
4441
4.22k
        WORD32 handle_size = ithread_get_handle_size();
4442
4443
4.22k
        if (ps_ip->s_ive_ip.u4_keep_threads_active)
4444
4.22k
        {
4445
4.22k
            ps_codec->s_thread_pool.pv_thread_pool_mutex = (void *)pu1_buf;
4446
4.22k
            pu1_buf += ithread_get_mutex_lock_size();
4447
4448
4.22k
            ps_codec->s_thread_pool.pv_thread_pool_cond = (void *)pu1_buf;
4449
4.22k
            pu1_buf += ithread_get_cond_size();
4450
4.22k
        }
4451
4452
38.0k
        for (i = 0; i < MAX_PROCESS_THREADS; i++)
4453
33.7k
        {
4454
33.7k
            ps_codec->apv_proc_thread_handle[i] = (void *)(pu1_buf + (i * handle_size));
4455
33.7k
        }
4456
4.22k
    }
4457
4458
4.22k
    ps_mem_rec = &ps_mem_rec_base[MEM_REC_CTL_MUTEX];
4459
4.22k
    {
4460
4.22k
        ps_codec->pv_ctl_mutex = ps_mem_rec->pv_base;
4461
4.22k
    }
4462
4463
4.22k
    ps_mem_rec = &ps_mem_rec_base[MEM_REC_ENTROPY_MUTEX];
4464
4.22k
    {
4465
4.22k
        ps_codec->pv_entropy_mutex = ps_mem_rec->pv_base;
4466
4.22k
    }
4467
4468
4.22k
    ps_mem_rec = &ps_mem_rec_base[MEM_REC_PROC_JOBQ];
4469
4.22k
    {
4470
4.22k
        ps_codec->pv_proc_jobq_buf = ps_mem_rec->pv_base;
4471
4.22k
        ps_codec->i4_proc_jobq_buf_size = ps_mem_rec->u4_mem_size;
4472
4.22k
    }
4473
4474
4.22k
    ps_mem_rec = &ps_mem_rec_base[MEM_REC_ENTROPY_JOBQ];
4475
4.22k
    {
4476
4.22k
        ps_codec->pv_entropy_jobq_buf = ps_mem_rec->pv_base;
4477
4.22k
        ps_codec->i4_entropy_jobq_buf_size = ps_mem_rec->u4_mem_size;
4478
4.22k
    }
4479
4480
4.22k
    ps_mem_rec = &ps_mem_rec_base[MEM_REC_PROC_MAP];
4481
4.22k
    {
4482
        /* pointer to storage space */
4483
4.22k
        UWORD8 *pu1_buf = ps_mem_rec->pv_base;
4484
4485
        /* total size of the mem record */
4486
4.22k
        WORD32 total_size = 0;
4487
4488
        /* size in bytes to mb core coding status of an entire frame */
4489
4.22k
        total_size = max_mb_cnt;
4490
4491
        /* add an additional 1 row of bytes to evade the special case of row 0 */
4492
4.22k
        total_size += max_mb_cols;
4493
4494
38.0k
        for (i = 0; i < MAX_PROCESS_CTXT; i++)
4495
33.7k
        {
4496
33.7k
            if (i < MAX_PROCESS_CTXT / MAX_CTXT_SETS)
4497
33.7k
            {
4498
33.7k
                ps_codec->as_process[i].pu1_proc_map = pu1_buf + max_mb_cols;
4499
33.7k
            }
4500
0
            else
4501
0
            {
4502
0
                ps_codec->as_process[i].pu1_proc_map = pu1_buf + total_size
4503
0
                                + max_mb_cols;
4504
0
            }
4505
33.7k
        }
4506
4.22k
    }
4507
4508
4.22k
    ps_mem_rec = &ps_mem_rec_base[MEM_REC_DBLK_MAP];
4509
4.22k
    {
4510
        /* pointer to storage space */
4511
4.22k
        UWORD8 *pu1_buf = ps_mem_rec->pv_base;
4512
4513
        /* total size of the mem record */
4514
4.22k
        WORD32 total_size = 0;
4515
4516
        /* size in bytes to mb core coding status of an entire frame */
4517
4.22k
        total_size = max_mb_cnt;
4518
4519
        /* add an additional 1 row of bytes to evade the special case of row 0 */
4520
4.22k
        total_size += max_mb_cols;
4521
4522
        /*Align the memory offsets*/
4523
4.22k
        total_size = ALIGN64(total_size);
4524
4525
38.0k
        for (i = 0; i < MAX_PROCESS_CTXT; i++)
4526
33.7k
        {
4527
33.7k
            if (i < MAX_PROCESS_CTXT / MAX_CTXT_SETS)
4528
33.7k
            {
4529
33.7k
                ps_codec->as_process[i].pu1_deblk_map = pu1_buf + max_mb_cols;
4530
4531
33.7k
            }
4532
0
            else
4533
0
            {
4534
0
                ps_codec->as_process[i].pu1_deblk_map = pu1_buf + total_size
4535
0
                                + max_mb_cols;
4536
4537
0
            }
4538
33.7k
        }
4539
4.22k
    }
4540
4541
4.22k
    ps_mem_rec = &ps_mem_rec_base[MEM_REC_ME_MAP];
4542
4.22k
    {
4543
        /* pointer to storage space */
4544
4.22k
        UWORD8 *pu1_buf = (UWORD8 *) ps_mem_rec->pv_base;
4545
4546
        /* total size of the mem record */
4547
4.22k
        WORD32 total_size = 0;
4548
4549
        /* size in bytes to mb core coding status of an entire frame */
4550
4.22k
        total_size = max_mb_cnt;
4551
4552
        /* add an additional 1 row of bytes to evade the special case of row 0 */
4553
4.22k
        total_size += max_mb_cols;
4554
4555
38.0k
        for (i = 0; i < MAX_PROCESS_CTXT; i++)
4556
33.7k
        {
4557
33.7k
            if (i < MAX_PROCESS_CTXT / MAX_CTXT_SETS)
4558
33.7k
            {
4559
33.7k
                ps_codec->as_process[i].pu1_me_map = pu1_buf + max_mb_cols;
4560
33.7k
            }
4561
0
            else
4562
0
            {
4563
0
                ps_codec->as_process[i].pu1_me_map = pu1_buf + total_size
4564
0
                                + max_mb_cols;
4565
0
            }
4566
33.7k
        }
4567
4.22k
    }
4568
4569
4.22k
    ps_mem_rec = &ps_mem_rec_base[MEM_REC_DPB_MGR];
4570
4.22k
    {
4571
4.22k
        ps_codec->pv_dpb_mgr = ps_mem_rec->pv_base;
4572
4.22k
    }
4573
4574
4.22k
    ps_mem_rec = &ps_mem_rec_base[MEM_REC_PROC_SCRATCH];
4575
4.22k
    {
4576
        /* pointer to storage space */
4577
4.22k
        UWORD8 *pu1_buf = (UWORD8 *) ps_mem_rec->pv_base;
4578
4579
        /* size of pred buffer, fwd transform output, temp buffer for inv tra */
4580
4.22k
        WORD32 size_pred_luma, size_pred_chroma, size_fwd, size_inv, size_hp;
4581
4582
        /* temp var */
4583
4.22k
        WORD32 size = 0;
4584
4585
        /* size to hold intra/inter prediction buffer */
4586
4.22k
        size_pred_luma = sizeof(UWORD8) * 16 * 16;
4587
4.22k
        size_pred_chroma = sizeof(UWORD8) * 8 * 16;
4588
4589
        /* size to hold fwd transform output */
4590
4.22k
        size_fwd = sizeof(WORD16) * SIZE_TRANS_BUFF;
4591
4592
        /* size to hold temporary data during inverse transform */
4593
4.22k
        size_inv = sizeof(WORD32) * SIZE_TMP_BUFF_ITRANS;
4594
4595
        /* size to hold half pel plane buffers */
4596
4.22k
        size_hp = sizeof(UWORD8) * (HP_BUFF_WD * HP_BUFF_HT);
4597
4598
38.0k
        for (i = 0; i < MAX_PROCESS_CTXT; i++)
4599
33.7k
        {
4600
            /* prediction buffer */
4601
33.7k
            ps_codec->as_process[i].pu1_pred_mb = (void *) (pu1_buf + size);
4602
33.7k
            ps_codec->as_process[i].i4_pred_strd = 16;
4603
33.7k
            size += size_pred_luma;
4604
33.7k
            size = ALIGN64(size);
4605
4606
            /* prediction buffer */
4607
33.7k
            ps_codec->as_process[i].pu1_ref_mb_intra_4x4 = (void *) (pu1_buf
4608
33.7k
                            + size);
4609
33.7k
            size += size_pred_luma;
4610
33.7k
            size = ALIGN64(size);
4611
4612
            /* prediction buffer intra 16x16 */
4613
33.7k
            ps_codec->as_process[i].pu1_pred_mb_intra_16x16 = (void *) (pu1_buf
4614
33.7k
                            + size);
4615
33.7k
            size += size_pred_luma;
4616
33.7k
            size = ALIGN64(size);
4617
4618
            /* prediction buffer intra 16x16 plane*/
4619
33.7k
            ps_codec->as_process[i].pu1_pred_mb_intra_16x16_plane =
4620
33.7k
                            (void *) (pu1_buf + size);
4621
33.7k
            size += size_pred_luma;
4622
33.7k
            size = ALIGN64(size);
4623
4624
            /* prediction buffer intra chroma*/
4625
33.7k
            ps_codec->as_process[i].pu1_pred_mb_intra_chroma = (void *) (pu1_buf
4626
33.7k
                            + size);
4627
33.7k
            size += size_pred_chroma;
4628
33.7k
            size = ALIGN64(size);
4629
4630
            /* prediction buffer intra chroma plane*/
4631
33.7k
            ps_codec->as_process[i].pu1_pred_mb_intra_chroma_plane =
4632
33.7k
                            (void *) (pu1_buf + size);
4633
33.7k
            size += size_pred_chroma;
4634
33.7k
            size = ALIGN64(size);
4635
4636
            /* Fwd transform output */
4637
33.7k
            ps_codec->as_process[i].pi2_res_buf = (void *) (pu1_buf + size);
4638
33.7k
            ps_codec->as_process[i].i4_res_strd = 16;
4639
33.7k
            size += size_fwd;
4640
33.7k
            size = ALIGN64(size);
4641
4642
            /* Fwd transform output */
4643
33.7k
            ps_codec->as_process[i].pi2_res_buf_intra_4x4 = (void *) (pu1_buf
4644
33.7k
                            + size);
4645
33.7k
            size += size_fwd;
4646
33.7k
            size = ALIGN64(size);
4647
4648
            /* scratch buffer used during inverse transform */
4649
33.7k
            ps_codec->as_process[i].pv_scratch_buff = (void *) (pu1_buf + size);
4650
33.7k
            size += size_inv;
4651
33.7k
            size = ALIGN64(size);
4652
4653
168k
            for (j = 0; j < SUBPEL_BUFF_CNT; j++)
4654
135k
            {
4655
135k
                ps_codec->as_process[i].apu1_subpel_buffs[j] = (pu1_buf + size);
4656
135k
                size += ALIGN64(size_hp);
4657
135k
            }
4658
33.7k
        }
4659
4.22k
    }
4660
4661
4.22k
    ps_mem_rec = &ps_mem_rec_base[MEM_REC_QUANT_PARAM];
4662
4.22k
    {
4663
        /* pointer to storage space */
4664
4.22k
        UWORD8 *pu1_buf = (UWORD8 *) ps_mem_rec->pv_base;
4665
4666
        /* size of qp, threshold matrix, fwd scaling list for one plane */
4667
4.22k
        WORD32 size_quant_param, size_thres_mat, size_fwd_weight_mat,
4668
4.22k
                        size_satqd_weight_mat;
4669
4670
        /* temp var */
4671
4.22k
        WORD32 total_size = 0;
4672
4673
        /* size of quantization parameter list of 1 plane */
4674
4.22k
        size_quant_param = ALIGN64(sizeof(quant_params_t));
4675
4676
        /* size of threshold matrix for quantization
4677
         * (assuming the transform_8x8_flag is disabled).
4678
         * for 1 plane */
4679
4.22k
        size_thres_mat = ALIGN64(sizeof(WORD16) * 4 * 4);
4680
4681
        /* size of forward weight matrix for quantization
4682
         * (assuming the transform_8x8_flag is disabled).
4683
         * for 1 plane */
4684
4.22k
        size_fwd_weight_mat = ALIGN64(sizeof(WORD16) * 4 * 4);
4685
4686
        /* size of SATQD matrix*/
4687
4.22k
        size_satqd_weight_mat = ALIGN64(sizeof(UWORD16) * 9);
4688
4689
38.0k
        for (i = 0; i < MAX_PROCESS_CTXT; i++)
4690
33.7k
        {
4691
33.7k
            quant_params_t **ps_qp_params = ps_codec->as_process[i].ps_qp_params;
4692
4693
            /* quantization param structure */
4694
33.7k
            ps_qp_params[0] = (quant_params_t *) (pu1_buf + total_size);
4695
33.7k
            total_size = total_size + size_quant_param;
4696
33.7k
            ps_qp_params[1] = (quant_params_t *) (pu1_buf + total_size);
4697
33.7k
            total_size = total_size + size_quant_param;
4698
33.7k
            ps_qp_params[2] = (quant_params_t *) (pu1_buf + total_size);
4699
33.7k
            total_size = total_size + size_quant_param;
4700
4701
            /* threshold matrix for quantization */
4702
33.7k
            ps_qp_params[0]->pu2_thres_mat = (void *) (pu1_buf + total_size);
4703
33.7k
            total_size = total_size + size_thres_mat;
4704
33.7k
            ps_qp_params[1]->pu2_thres_mat = (void *) (pu1_buf + total_size);
4705
33.7k
            total_size = total_size + size_thres_mat;
4706
33.7k
            ps_qp_params[2]->pu2_thres_mat = (void *) (pu1_buf + total_size);
4707
33.7k
            total_size = total_size + size_thres_mat;
4708
4709
            /* fwd weight matrix */
4710
33.7k
            ps_qp_params[0]->pu2_weigh_mat = (void *) (pu1_buf + total_size);
4711
33.7k
            total_size = total_size + size_fwd_weight_mat;
4712
33.7k
            ps_qp_params[1]->pu2_weigh_mat = (void *) (pu1_buf + total_size);
4713
33.7k
            total_size = total_size + size_fwd_weight_mat;
4714
33.7k
            ps_qp_params[2]->pu2_weigh_mat = (void *) (pu1_buf + total_size);
4715
33.7k
            total_size = total_size + size_fwd_weight_mat;
4716
4717
            /* threshold matrix for SATQD */
4718
33.7k
            ps_qp_params[0]->pu2_sad_thrsh = (void *) (pu1_buf + total_size);
4719
33.7k
            total_size = total_size + size_satqd_weight_mat;
4720
33.7k
            ps_qp_params[1]->pu2_sad_thrsh = (void *) (pu1_buf + total_size);
4721
33.7k
            total_size = total_size + size_satqd_weight_mat;
4722
33.7k
            ps_qp_params[2]->pu2_sad_thrsh = (void *) (pu1_buf + total_size);
4723
33.7k
            total_size = total_size + size_satqd_weight_mat;
4724
4725
33.7k
            total_size = ALIGN128(total_size);
4726
33.7k
        }
4727
4.22k
    }
4728
4729
4.22k
    ps_mem_rec = &ps_mem_rec_base[MEM_REC_TOP_ROW_SYN_INFO];
4730
4.22k
    {
4731
        /* total size of the mem record */
4732
4.22k
        WORD32 total_size = 0, size_csbp, size_intra_modes, size_mv;
4733
4734
        /* pointer to buffer */
4735
4.22k
        UWORD8 *pu1_buf = ps_mem_rec->pv_base;
4736
4737
        /* size in bytes to store  1 row of mb_info_t */
4738
        /* one additional mb, to avoid checking end of row condition */
4739
4.22k
        size_csbp = (max_mb_cols + 1) * sizeof(mb_info_t);
4740
4741
        /* size in bytes to store  1 row of intra macroblock sub modes */
4742
4.22k
        size_intra_modes = max_mb_cols * sizeof(UWORD8) * 16;
4743
4744
        /* size in bytes to store  1 row + 1 of enc_pu_t */
4745
        /* one additional mb, to avoid checking end of row condition */
4746
4.22k
        size_mv = (max_mb_cols + 1) * sizeof(enc_pu_t);
4747
4748
        /* total size per proc ctxt */
4749
4.22k
        total_size = size_csbp + size_intra_modes + size_mv;
4750
4751
38.0k
        for (i = 0; i < MAX_PROCESS_CTXT; i++)
4752
33.7k
        {
4753
33.7k
            if (i < MAX_PROCESS_CTXT / MAX_CTXT_SETS)
4754
33.7k
            {
4755
33.7k
                ps_codec->as_process[i].ps_top_row_mb_syntax_ele_base =
4756
33.7k
                                (mb_info_t *) pu1_buf;
4757
33.7k
                ps_codec->as_process[i].pu1_top_mb_intra_modes_base = pu1_buf
4758
33.7k
                                + size_csbp;
4759
33.7k
                ps_codec->as_process[i].ps_top_row_pu_base =
4760
33.7k
                                (enc_pu_t *) (pu1_buf + size_csbp
4761
33.7k
                                                + size_intra_modes);
4762
33.7k
            }
4763
0
            else
4764
0
            {
4765
0
                ps_codec->as_process[i].ps_top_row_mb_syntax_ele_base =
4766
0
                                (mb_info_t *) (pu1_buf + total_size);
4767
0
                ps_codec->as_process[i].pu1_top_mb_intra_modes_base = pu1_buf
4768
0
                                + total_size + size_csbp;
4769
0
                ps_codec->as_process[i].ps_top_row_pu_base =
4770
0
                                (enc_pu_t *) (pu1_buf + total_size + size_csbp
4771
0
                                                + size_intra_modes);
4772
0
            }
4773
33.7k
        }
4774
4.22k
    }
4775
4776
4.22k
    ps_mem_rec = &ps_mem_rec_base[MEM_REC_BS_QP];
4777
4.22k
    {
4778
4.22k
        UWORD8 *pu1_buf_ping, *pu1_buf_pong;
4779
4780
        /* total size of the mem record */
4781
4.22k
        WORD32 total_size = 0;
4782
4783
        /* size in bytes to store vertical edge bs, horizontal edge bs and qp of every mb*/
4784
4.22k
        WORD32 vert_bs_size, horz_bs_size, qp_size;
4785
4786
        /* vertical edge bs = total number of vertical edges * number of bytes per each edge */
4787
        /* total num of v edges = total mb * 4 (assuming transform_8x8_flag = 0),
4788
         * each edge is formed by 4 pairs of subblks, requiring 4 bytes to storing bs */
4789
4.22k
        vert_bs_size = ALIGN64(max_mb_cnt * 4 * 4);
4790
4791
        /* horizontal edge bs = total number of horizontal edges * number of bytes per each edge */
4792
        /* total num of h edges = total mb * 4 (assuming transform_8x8_flag = 0),
4793
         * each edge is formed by 4 pairs of subblks, requiring 4 bytes to storing bs */
4794
4.22k
        horz_bs_size = ALIGN64(max_mb_cnt * 4 * 4);
4795
4796
        /* qp of each mb requires 1 byte */
4797
4.22k
        qp_size = ALIGN64(max_mb_cnt);
4798
4799
        /* total size */
4800
4.22k
        total_size = vert_bs_size + horz_bs_size + qp_size;
4801
4802
38.0k
        for (i = 0; i < MAX_PROCESS_CTXT; i++)
4803
33.7k
        {
4804
33.7k
            if (i < MAX_PROCESS_CTXT / MAX_CTXT_SETS)
4805
33.7k
            {
4806
33.7k
                pu1_buf_ping = (UWORD8 *) ps_mem_rec->pv_base;
4807
4808
                /* vertical edge bs storage space */
4809
33.7k
                ps_codec->as_process[i].s_deblk_ctxt.s_bs_ctxt.pu4_pic_vert_bs =
4810
33.7k
                                (UWORD32 *) pu1_buf_ping;
4811
33.7k
                pu1_buf_ping += vert_bs_size;
4812
4813
                /* horizontal edge bs storage space */
4814
33.7k
                ps_codec->as_process[i].s_deblk_ctxt.s_bs_ctxt.pu4_pic_horz_bs =
4815
33.7k
                                (UWORD32 *) pu1_buf_ping;
4816
33.7k
                pu1_buf_ping += horz_bs_size;
4817
4818
                /* qp */
4819
33.7k
                ps_codec->as_process[i].s_deblk_ctxt.s_bs_ctxt.pu1_pic_qp =
4820
33.7k
                                (UWORD8 *) pu1_buf_ping;
4821
33.7k
                pu1_buf_ping += qp_size;
4822
33.7k
            }
4823
0
            else
4824
0
            {
4825
0
                pu1_buf_pong = (UWORD8 *) ps_mem_rec->pv_base;
4826
0
                pu1_buf_pong += total_size;
4827
4828
                /* vertical edge bs storage space */
4829
0
                ps_codec->as_process[i].s_deblk_ctxt.s_bs_ctxt.pu4_pic_vert_bs =
4830
0
                                (UWORD32 *) pu1_buf_pong;
4831
0
                pu1_buf_pong += vert_bs_size;
4832
4833
                /* horizontal edge bs storage space */
4834
0
                ps_codec->as_process[i].s_deblk_ctxt.s_bs_ctxt.pu4_pic_horz_bs =
4835
0
                                (UWORD32 *) pu1_buf_pong;
4836
0
                pu1_buf_pong += horz_bs_size;
4837
4838
                /* qp */
4839
0
                ps_codec->as_process[i].s_deblk_ctxt.s_bs_ctxt.pu1_pic_qp =
4840
0
                                (UWORD8 *) pu1_buf_pong;
4841
0
                pu1_buf_pong += qp_size;
4842
0
            }
4843
33.7k
        }
4844
4.22k
    }
4845
4846
4.22k
    ps_mem_rec = &ps_mem_rec_base[MEM_REC_INP_PIC];
4847
4.22k
    {
4848
4.22k
        ps_codec->pv_inp_buf_mgr_base = ps_mem_rec->pv_base;
4849
4.22k
    }
4850
4851
4.22k
    ps_mem_rec = &ps_mem_rec_base[MEM_REC_OUT];
4852
4.22k
    {
4853
4.22k
        ps_codec->pv_out_buf_mgr_base = ps_mem_rec->pv_base;
4854
4.22k
    }
4855
4856
4.22k
    ps_mem_rec = &ps_mem_rec_base[MEM_REC_CSC];
4857
4.22k
    {
4858
4.22k
        ps_codec->pu1_y_csc_buf_base = ps_mem_rec->pv_base;
4859
4.22k
        ps_codec->pu1_uv_csc_buf_base = (UWORD8 *) ps_mem_rec->pv_base
4860
4.22k
                        + (max_ht_luma * max_wd_luma);
4861
4.22k
    }
4862
4863
4.22k
    ps_mem_rec = &ps_mem_rec_base[MEM_REC_REF_PIC];
4864
4.22k
    {
4865
        /* size of buf mgr struct */
4866
4.22k
        WORD32 size = ih264_buf_mgr_size();
4867
4868
        /* temp var */
4869
4.22k
        UWORD8 *pu1_buf = ps_mem_rec->pv_base;
4870
4871
        /* pic buffer mgr */
4872
4.22k
        ps_codec->pv_ref_buf_mgr_base = pu1_buf;
4873
4874
        /* picture bank */
4875
4.22k
        ps_codec->pv_pic_buf_base = pu1_buf + size;
4876
4.22k
        ps_codec->i4_total_pic_buf_size = ps_mem_rec->u4_mem_size - size;
4877
4.22k
    }
4878
4879
4.22k
    ps_mem_rec = &ps_mem_rec_base[MEM_REC_MB_INFO_NMB];
4880
4.22k
    {
4881
        /* temp var */
4882
4.22k
        UWORD8 *pu1_buf = ps_mem_rec->pv_base;
4883
4884
        /* size of nmb ctxt */
4885
4.22k
        WORD32 size = max_mb_cols * sizeof(mb_info_nmb_t);
4886
4887
4.22k
        WORD32 nmb_cntr, subpel_buf_size;
4888
4889
        /* init nmb info structure pointer in all proc ctxts */
4890
38.0k
        for (i = 0; i < MAX_PROCESS_CTXT; i++)
4891
33.7k
        {
4892
33.7k
            ps_codec->as_process[i].ps_nmb_info = (mb_info_nmb_t *) (pu1_buf);
4893
4894
33.7k
            pu1_buf += size;
4895
33.7k
        }
4896
4897
4.22k
        subpel_buf_size = MB_SIZE * MB_SIZE * sizeof(UWORD8);
4898
4899
        /* adjusting pointers for nmb halfpel buffer */
4900
38.0k
        for (i = 0; i < MAX_PROCESS_CTXT; i++)
4901
33.7k
        {
4902
33.7k
            mb_info_nmb_t* ps_mb_info_nmb =
4903
33.7k
                            &ps_codec->as_process[i].ps_nmb_info[0];
4904
4905
849k
            for (nmb_cntr = 0; nmb_cntr < max_mb_cols; nmb_cntr++)
4906
816k
            {
4907
816k
                ps_mb_info_nmb[nmb_cntr].pu1_best_sub_pel_buf = pu1_buf;
4908
4909
816k
                pu1_buf = pu1_buf + subpel_buf_size;
4910
4911
816k
                ps_mb_info_nmb[nmb_cntr].u4_bst_spel_buf_strd = MB_SIZE;
4912
816k
            }
4913
33.7k
        }
4914
4.22k
    }
4915
4916
4.22k
    ps_mem_rec = &ps_mem_rec_base[MEM_REC_RC];
4917
4.22k
    {
4918
4.22k
        ih264e_get_rate_control_mem_tab(&ps_codec->s_rate_control, ps_mem_rec,
4919
4.22k
                                        USE_BASE);
4920
4.22k
    }
4921
4922
    /* init codec ctxt */
4923
4.22k
    status = ih264e_init(ps_codec);
4924
4925
4.22k
    return status;
4926
4.22k
}
4927
4928
/**
4929
*******************************************************************************
4930
*
4931
* @brief
4932
*  Retrieves mem records passed to the codec
4933
*
4934
* @par Description:
4935
*  Retrieves mem recs passed during init
4936
*
4937
* @param[in] ps_codec_obj
4938
*  Pointer to codec object at API level
4939
*
4940
* @param[in] pv_api_ip
4941
*  Pointer to input argument structure
4942
*
4943
* @param[out] pv_api_op
4944
*  Pointer to output argument structure
4945
*
4946
* @returns error status
4947
*
4948
* @remarks none
4949
*
4950
*******************************************************************************
4951
*/
4952
static WORD32 ih264e_retrieve_memrec(iv_obj_t *ps_codec_obj,
4953
                                     void *pv_api_ip,
4954
                                     void *pv_api_op)
4955
4.22k
{
4956
    /* codec ctxt */
4957
4.22k
    codec_t *ps_codec = (codec_t *) ps_codec_obj->pv_codec_handle;
4958
4959
    /* ctrl call I/O structures */
4960
4.22k
    ih264e_retrieve_mem_rec_ip_t *ps_ip = pv_api_ip;
4961
4.22k
    ih264e_retrieve_mem_rec_op_t *ps_op = pv_api_op;
4962
4963
4.22k
    if (ps_codec->i4_init_done != 1)
4964
0
    {
4965
0
        ps_op->s_ive_op.u4_error_code |= 1 << IVE_FATALERROR;
4966
0
        ps_op->s_ive_op.u4_error_code |= IH264E_INIT_NOT_DONE;
4967
0
        return IV_FAIL;
4968
0
    }
4969
4970
4.22k
    if (ps_codec->s_cfg.u4_keep_threads_active)
4971
4.22k
    {
4972
4.22k
        ih264e_thread_pool_shutdown(ps_codec);
4973
4.22k
        ithread_cond_destroy(ps_codec->s_thread_pool.pv_thread_pool_cond);
4974
4.22k
        ithread_mutex_destroy(ps_codec->s_thread_pool.pv_thread_pool_mutex);
4975
4.22k
    }
4976
0
    else
4977
0
    {
4978
        /* join threads upon at end of sequence */
4979
0
        ih264e_join_threads(ps_codec);
4980
0
    }
4981
4982
    /* collect list of memory records used by the encoder library */
4983
4.22k
    memcpy(ps_ip->s_ive_ip.ps_mem_rec, ps_codec->ps_mem_rec_backup,
4984
4.22k
           MEM_REC_CNT * (sizeof(iv_mem_rec_t)));
4985
4.22k
    ps_op->s_ive_op.u4_num_mem_rec_filled = MEM_REC_CNT;
4986
4987
    /* clean up mutex memory */
4988
4.22k
    ih264_list_free(ps_codec->pv_entropy_jobq);
4989
4.22k
    ih264_list_free(ps_codec->pv_proc_jobq);
4990
4.22k
    ithread_mutex_destroy(ps_codec->pv_ctl_mutex);
4991
4.22k
    ithread_mutex_destroy(ps_codec->pv_entropy_mutex);
4992
4993
4.22k
    ih264_buf_mgr_free((buf_mgr_t *)ps_codec->pv_mv_buf_mgr);
4994
4.22k
    ih264_buf_mgr_free((buf_mgr_t *)ps_codec->pv_ref_buf_mgr);
4995
4.22k
    ih264_buf_mgr_free((buf_mgr_t *)ps_codec->pv_inp_buf_mgr);
4996
4.22k
    ih264_buf_mgr_free((buf_mgr_t *)ps_codec->pv_out_buf_mgr);
4997
4998
4.22k
    return IV_SUCCESS;
4999
4.22k
}
5000
5001
/**
5002
*******************************************************************************
5003
*
5004
* @brief
5005
*  Sets the encoder in flush mode.
5006
*
5007
* @par Description:
5008
*  Sets the encoder in flush mode
5009
*
5010
* @param[in] ps_codec_obj
5011
*  Pointer to codec object at API level
5012
*
5013
* @param[in] pv_api_ip
5014
*  Pointer to input argument structure
5015
*
5016
* @param[out] pv_api_op
5017
*  Pointer to output argument structure
5018
*
5019
* @returns error status
5020
*
5021
* @remarks This call has no real effect on encoder
5022
*
5023
*******************************************************************************
5024
*/
5025
static WORD32 ih264e_set_flush_mode(iv_obj_t *ps_codec_obj,
5026
                                    void *pv_api_ip,
5027
                                    void *pv_api_op)
5028
0
{
5029
    /* codec ctxt */
5030
0
    codec_t *ps_codec = (codec_t *) ps_codec_obj->pv_codec_handle;
5031
5032
    /* ctrl call I/O structures */
5033
0
    ih264e_ctl_flush_op_t *ps_ctl_op = pv_api_op;
5034
5035
0
    UNUSED(pv_api_ip);
5036
5037
0
    ps_ctl_op->s_ive_op.u4_error_code = 0;
5038
5039
    /* signal flush frame control call */
5040
0
    ps_codec->i4_flush_mode = 1;
5041
5042
0
    return IV_SUCCESS;
5043
0
}
5044
5045
/**
5046
*******************************************************************************
5047
*
5048
* @brief
5049
*  Gets encoder buffer requirements
5050
*
5051
* @par Description:
5052
*  Gets the encoder buffer requirements. Basing on max width and max height
5053
*  configuration settings, this routine, computes the sizes of necessary input,
5054
*  output buffers returns this info to callee.
5055
*
5056
* @param[in] ps_codec_obj
5057
*  Pointer to codec object at API level
5058
*
5059
* @param[in] pv_api_ip
5060
*  Pointer to input argument structure
5061
*
5062
* @param[out] pv_api_op
5063
*  Pointer to output argument structure
5064
*
5065
* @returns error status
5066
*
5067
* @remarks none
5068
*
5069
*******************************************************************************
5070
*/
5071
static WORD32 ih264e_get_buf_info(iv_obj_t *ps_codec_obj,
5072
                                  void *pv_api_ip,
5073
                                  void *pv_api_op)
5074
4.16k
{
5075
    /* ctrl call I/O structures */
5076
4.16k
    ih264e_ctl_getbufinfo_ip_t *ps_ip = pv_api_ip;
5077
4.16k
    ih264e_ctl_getbufinfo_op_t *ps_op = pv_api_op;
5078
5079
    /* temp var */
5080
4.16k
    WORD32 wd = ALIGN16(ps_ip->s_ive_ip.u4_max_wd);
5081
4.16k
    WORD32 ht = ALIGN16(ps_ip->s_ive_ip.u4_max_ht);
5082
4.16k
    WORD32 i;
5083
5084
4.16k
    UNUSED(ps_codec_obj);
5085
5086
4.16k
    ps_op->s_ive_op.u4_error_code = 0;
5087
5088
    /* Number of components in input buffers required for codec  &
5089
     * Minimum sizes of each component in input buffer required */
5090
4.16k
    if (ps_ip->s_ive_ip.e_inp_color_fmt == IV_YUV_420P)
5091
1.72k
    {
5092
1.72k
        ps_op->s_ive_op.u4_inp_comp_cnt = MIN_RAW_BUFS_420_COMP;
5093
5094
1.72k
        ps_op->s_ive_op.au4_min_in_buf_size[0] = wd * ht;
5095
1.72k
        ps_op->s_ive_op.au4_min_in_buf_size[1] = (wd >> 1) * (ht >> 1);
5096
1.72k
        ps_op->s_ive_op.au4_min_in_buf_size[2] = (wd >> 1) * (ht >> 1);
5097
1.72k
    }
5098
2.44k
    else if (ps_ip->s_ive_ip.e_inp_color_fmt == IV_YUV_422ILE)
5099
572
    {
5100
572
        ps_op->s_ive_op.u4_inp_comp_cnt = MIN_RAW_BUFS_422ILE_COMP;
5101
5102
572
        ps_op->s_ive_op.au4_min_in_buf_size[0] = wd * ht * 2;
5103
572
        ps_op->s_ive_op.au4_min_in_buf_size[1] =
5104
572
                        ps_op->s_ive_op.au4_min_in_buf_size[2] = 0;
5105
572
    }
5106
1.87k
    else if (ps_ip->s_ive_ip.e_inp_color_fmt == IV_RGB_565)
5107
0
    {
5108
0
        ps_op->s_ive_op.u4_inp_comp_cnt = MIN_RAW_BUFS_RGB565_COMP;
5109
5110
0
        ps_op->s_ive_op.au4_min_in_buf_size[0] = wd * ht * 2;
5111
0
        ps_op->s_ive_op.au4_min_in_buf_size[1] =
5112
0
                        ps_op->s_ive_op.au4_min_in_buf_size[2] = 0;
5113
0
    }
5114
1.87k
    else if (ps_ip->s_ive_ip.e_inp_color_fmt == IV_RGBA_8888)
5115
0
    {
5116
0
        ps_op->s_ive_op.u4_inp_comp_cnt = MIN_RAW_BUFS_RGBA8888_COMP;
5117
5118
0
        ps_op->s_ive_op.au4_min_in_buf_size[0] = wd * ht * 4;
5119
0
        ps_op->s_ive_op.au4_min_in_buf_size[1] =
5120
0
                        ps_op->s_ive_op.au4_min_in_buf_size[2] = 0;
5121
0
    }
5122
1.87k
    else if ((ps_ip->s_ive_ip.e_inp_color_fmt == IV_YUV_420SP_UV)
5123
1.87k
                    || (ps_ip->s_ive_ip.e_inp_color_fmt == IV_YUV_420SP_VU))
5124
1.87k
    {
5125
1.87k
        ps_op->s_ive_op.u4_inp_comp_cnt = MIN_RAW_BUFS_420SP_COMP;
5126
5127
1.87k
        ps_op->s_ive_op.au4_min_in_buf_size[0] = wd * ht;
5128
1.87k
        ps_op->s_ive_op.au4_min_in_buf_size[1] = wd * (ht >> 1);
5129
1.87k
        ps_op->s_ive_op.au4_min_in_buf_size[2] = 0;
5130
1.87k
    }
5131
5132
    /* Number of components in output buffers required for codec  &
5133
     * Minimum sizes of each component in output buffer required */
5134
4.16k
    ps_op->s_ive_op.u4_out_comp_cnt = MIN_BITS_BUFS_COMP;
5135
5136
8.33k
    for (i = 0; i < (WORD32) ps_op->s_ive_op.u4_out_comp_cnt; i++)
5137
4.16k
    {
5138
4.16k
        ps_op->s_ive_op.au4_min_out_buf_size[i] = MAX(((wd * ht * 3) >> 1), MIN_STREAM_SIZE);
5139
4.16k
    }
5140
5141
4.16k
    ps_op->s_ive_op.u4_min_inp_bufs = MIN_INP_BUFS;
5142
4.16k
    ps_op->s_ive_op.u4_min_out_bufs = MIN_OUT_BUFS;
5143
5144
4.16k
    return IV_SUCCESS;
5145
4.16k
}
5146
5147
/**
5148
*******************************************************************************
5149
*
5150
* @brief
5151
*  Sets the picture dimensions
5152
*
5153
* @par Description:
5154
*  Sets width, height, display width, display height and strides
5155
*
5156
* @param[in] pv_api_ip
5157
*  Pointer to input argument structure
5158
*
5159
* @param[out] pv_api_op
5160
*  Pointer to output argument structure
5161
*
5162
* @param[out] ps_cfg
5163
*  Pointer to config structure to be updated
5164
*
5165
* @returns error status
5166
*
5167
* @remarks none
5168
*
5169
*******************************************************************************
5170
*/
5171
static IV_STATUS_T ih264e_set_dimensions(void *pv_api_ip,
5172
                                         void *pv_api_op,
5173
                                         cfg_params_t *ps_cfg)
5174
4.08k
{
5175
    /* ctrl call I/O structures */
5176
4.08k
    ih264e_ctl_set_dimensions_ip_t *ps_ip = pv_api_ip;
5177
4.08k
    ih264e_ctl_set_dimensions_op_t *ps_op = pv_api_op;
5178
5179
4.08k
    ps_op->s_ive_op.u4_error_code = 0;
5180
5181
4.08k
    ps_cfg->u4_wd = ALIGN16(ps_ip->s_ive_ip.u4_wd);
5182
4.08k
    ps_cfg->u4_ht = ALIGN16(ps_ip->s_ive_ip.u4_ht);
5183
4.08k
    ps_cfg->i4_wd_mbs = ps_cfg->u4_wd >> 4;
5184
4.08k
    ps_cfg->i4_ht_mbs = ps_cfg->u4_ht >> 4;
5185
4.08k
    ps_cfg->u4_disp_wd = ps_ip->s_ive_ip.u4_wd;
5186
4.08k
    ps_cfg->u4_disp_ht = ps_ip->s_ive_ip.u4_ht;
5187
5188
4.08k
    ps_cfg->u4_timestamp_high = ps_ip->s_ive_ip.u4_timestamp_high;
5189
4.08k
    ps_cfg->u4_timestamp_low = ps_ip->s_ive_ip.u4_timestamp_low;
5190
5191
4.08k
    return IV_SUCCESS;
5192
4.08k
}
5193
5194
/**
5195
*******************************************************************************
5196
*
5197
* @brief
5198
*  Sets source and target frame rates
5199
*
5200
* @par Description:
5201
*  Sets source and target frame rates
5202
*
5203
* @param[in] pv_api_ip
5204
*  Pointer to input argument structure
5205
*
5206
* @param[out] pv_api_op
5207
*  Pointer to output argument structure
5208
*
5209
* @param[out] ps_cfg
5210
*  Pointer to config structure to be updated
5211
*
5212
* @returns error status
5213
*
5214
* @remarks none
5215
*
5216
*******************************************************************************
5217
*/
5218
static IV_STATUS_T ih264e_set_frame_rate(void *pv_api_ip,
5219
                                         void *pv_api_op,
5220
                                         cfg_params_t *ps_cfg)
5221
2.32k
{
5222
    /* ctrl call I/O structures */
5223
2.32k
    ih264e_ctl_set_frame_rate_ip_t *ps_ip = pv_api_ip;
5224
2.32k
    ih264e_ctl_set_frame_rate_op_t *ps_op = pv_api_op;
5225
5226
2.32k
    ps_op->s_ive_op.u4_error_code = 0;
5227
5228
2.32k
    ps_cfg->u4_src_frame_rate = ps_ip->s_ive_ip.u4_src_frame_rate;
5229
2.32k
    ps_cfg->u4_tgt_frame_rate = ps_ip->s_ive_ip.u4_tgt_frame_rate;
5230
5231
2.32k
    ps_cfg->u4_timestamp_high = ps_ip->s_ive_ip.u4_timestamp_high;
5232
2.32k
    ps_cfg->u4_timestamp_low = ps_ip->s_ive_ip.u4_timestamp_low;
5233
5234
2.32k
    return IV_SUCCESS;
5235
2.32k
}
5236
5237
/**
5238
*******************************************************************************
5239
*
5240
* @brief
5241
*  Sets target bit rate
5242
*
5243
* @par Description:
5244
*  Sets target bit rate
5245
*
5246
* @param[in] pv_api_ip
5247
*  Pointer to input argument structure
5248
*
5249
* @param[out] pv_api_op
5250
*  Pointer to output argument structure
5251
*
5252
* @param[out] ps_cfg
5253
*  Pointer to config structure to be updated
5254
*
5255
* @returns error status
5256
*
5257
* @remarks none
5258
*
5259
*******************************************************************************
5260
*/
5261
static IV_STATUS_T ih264e_set_bit_rate(void *pv_api_ip,
5262
                                       void *pv_api_op,
5263
                                       cfg_params_t *ps_cfg)
5264
4.66k
{
5265
    /* ctrl call I/O structures */
5266
4.66k
    ih264e_ctl_set_bitrate_ip_t *ps_ip = pv_api_ip;
5267
4.66k
    ih264e_ctl_set_bitrate_op_t *ps_op = pv_api_op;
5268
5269
4.66k
    ps_op->s_ive_op.u4_error_code = 0;
5270
5271
4.66k
    ps_cfg->u4_target_bitrate = ps_ip->s_ive_ip.u4_target_bitrate;
5272
5273
4.66k
    ps_cfg->u4_timestamp_high = ps_ip->s_ive_ip.u4_timestamp_high;
5274
4.66k
    ps_cfg->u4_timestamp_low = ps_ip->s_ive_ip.u4_timestamp_low;
5275
5276
4.66k
    return IV_SUCCESS;
5277
4.66k
}
5278
5279
/**
5280
*******************************************************************************
5281
*
5282
* @brief
5283
*  Sets frame type
5284
*
5285
* @par Description:
5286
*  Sets frame type
5287
*
5288
* @param[in] pv_api_ip
5289
*  Pointer to input argument structure
5290
*
5291
* @param[out] pv_api_op
5292
*  Pointer to output argument structure
5293
*
5294
* @param[out] ps_cfg
5295
*  Pointer to config structure to be updated
5296
*
5297
* @returns error status
5298
*
5299
* @remarks not a sticky tag
5300
*
5301
*******************************************************************************
5302
*/
5303
static IV_STATUS_T ih264e_set_frame_type(void *pv_api_ip,
5304
                                         void *pv_api_op,
5305
                                         cfg_params_t *ps_cfg)
5306
913
{
5307
    /* ctrl call I/O structures */
5308
913
    ih264e_ctl_set_frame_type_ip_t *ps_ip = pv_api_ip;
5309
913
    ih264e_ctl_set_frame_type_op_t *ps_op = pv_api_op;
5310
5311
913
    ps_op->s_ive_op.u4_error_code = 0;
5312
5313
913
    ps_cfg->e_frame_type = ps_ip->s_ive_ip.e_frame_type;
5314
5315
913
    ps_cfg->u4_timestamp_high = ps_ip->s_ive_ip.u4_timestamp_high;
5316
913
    ps_cfg->u4_timestamp_low = ps_ip->s_ive_ip.u4_timestamp_low;
5317
5318
913
    return IV_SUCCESS;
5319
913
}
5320
5321
/**
5322
*******************************************************************************
5323
*
5324
* @brief
5325
*  Sets quantization params
5326
*
5327
* @par Description:
5328
*  Sets the max, min and default qp for I frame, P frame and B frame
5329
*
5330
* @param[in] pv_api_ip
5331
*  Pointer to input argument structure
5332
*
5333
* @param[out] pv_api_op
5334
*  Pointer to output argument structure
5335
*
5336
* @param[out] ps_cfg
5337
*  Pointer to config structure to be updated
5338
*
5339
* @returns error status
5340
*
5341
* @remarks none
5342
*
5343
*******************************************************************************
5344
*/
5345
static IV_STATUS_T ih264e_set_qp(void *pv_api_ip,
5346
                                 void *pv_api_op,
5347
                                 cfg_params_t *ps_cfg)
5348
4.22k
{
5349
    /* ctrl call I/O structures */
5350
4.22k
    ih264e_ctl_set_qp_ip_t *ps_set_qp_ip = pv_api_ip;
5351
4.22k
    ih264e_ctl_set_qp_op_t *ps_set_qp_op = pv_api_op;
5352
5353
4.22k
    ps_set_qp_op->s_ive_op.u4_error_code = 0;
5354
5355
4.22k
    ps_cfg->u4_i_qp_max = ps_set_qp_ip->s_ive_ip.u4_i_qp_max;
5356
4.22k
    ps_cfg->u4_i_qp_min = ps_set_qp_ip->s_ive_ip.u4_i_qp_min;
5357
4.22k
    ps_cfg->u4_i_qp = ps_set_qp_ip->s_ive_ip.u4_i_qp;
5358
4.22k
    ps_cfg->u4_p_qp_max = ps_set_qp_ip->s_ive_ip.u4_p_qp_max;
5359
4.22k
    ps_cfg->u4_p_qp_min = ps_set_qp_ip->s_ive_ip.u4_p_qp_min;
5360
4.22k
    ps_cfg->u4_p_qp = ps_set_qp_ip->s_ive_ip.u4_p_qp;
5361
4.22k
    ps_cfg->u4_b_qp_max = ps_set_qp_ip->s_ive_ip.u4_b_qp_max;
5362
4.22k
    ps_cfg->u4_b_qp_min = ps_set_qp_ip->s_ive_ip.u4_b_qp_min;
5363
4.22k
    ps_cfg->u4_b_qp = ps_set_qp_ip->s_ive_ip.u4_b_qp;
5364
5365
4.22k
    ps_cfg->u4_timestamp_high = ps_set_qp_ip->s_ive_ip.u4_timestamp_high;
5366
4.22k
    ps_cfg->u4_timestamp_low = ps_set_qp_ip->s_ive_ip.u4_timestamp_low;
5367
5368
4.22k
    return IV_SUCCESS;
5369
4.22k
}
5370
5371
/**
5372
*******************************************************************************
5373
*
5374
* @brief
5375
*  Sets encoding mode
5376
*
5377
* @par Description:
5378
*  Sets encoding mode
5379
*
5380
* @param[in] pv_api_ip
5381
*  Pointer to input argument structure
5382
*
5383
* @param[out] pv_api_op
5384
*  Pointer to output argument structure
5385
*
5386
* @param[out] ps_cfg
5387
*  Pointer to config structure to be updated
5388
*
5389
* @returns error status
5390
*
5391
* @remarks none
5392
*
5393
*******************************************************************************
5394
*/
5395
static IV_STATUS_T ih264e_set_enc_mode(void *pv_api_ip,
5396
                                       void *pv_api_op,
5397
                                       cfg_params_t *ps_cfg)
5398
4.22k
{
5399
    /* ctrl call I/O structures */
5400
4.22k
    ih264e_ctl_set_enc_mode_ip_t *ps_ip = pv_api_ip;
5401
4.22k
    ih264e_ctl_set_enc_mode_op_t *ps_op = pv_api_op;
5402
5403
4.22k
    ps_op->s_ive_op.u4_error_code = 0;
5404
5405
4.22k
    ps_cfg->e_enc_mode = ps_ip->s_ive_ip.e_enc_mode;
5406
5407
4.22k
    ps_cfg->u4_timestamp_high = ps_ip->s_ive_ip.u4_timestamp_high;
5408
4.22k
    ps_cfg->u4_timestamp_low = ps_ip->s_ive_ip.u4_timestamp_low;
5409
5410
4.22k
    return IV_SUCCESS;
5411
4.22k
}
5412
5413
/**
5414
*******************************************************************************
5415
*
5416
* @brief
5417
*  Sets vbv parameters
5418
*
5419
* @par Description:
5420
*  Sets vbv parameters
5421
*
5422
* @param[in] pv_api_ip
5423
*  Pointer to input argument structure
5424
*
5425
* @param[out] pv_api_op
5426
*  Pointer to output argument structure
5427
*
5428
* @param[out] ps_cfg
5429
*  Pointer to config structure to be updated
5430
*
5431
* @returns error status
5432
*
5433
* @remarks none
5434
*
5435
*******************************************************************************
5436
*/
5437
static IV_STATUS_T ih264e_set_vbv_params(void *pv_api_ip,
5438
                                         void *pv_api_op,
5439
                                         cfg_params_t *ps_cfg)
5440
4.22k
{
5441
    /* ctrl call I/O structures */
5442
4.22k
    ih264e_ctl_set_vbv_params_ip_t *ps_ip = pv_api_ip;
5443
4.22k
    ih264e_ctl_set_vbv_params_op_t *ps_op = pv_api_op;
5444
5445
4.22k
    ps_op->s_ive_op.u4_error_code = 0;
5446
5447
4.22k
    ps_cfg->u4_vbv_buf_size = ps_ip->s_ive_ip.u4_vbv_buf_size;
5448
4.22k
    ps_cfg->u4_vbv_buffer_delay = ps_ip->s_ive_ip.u4_vbv_buffer_delay;
5449
5450
4.22k
    ps_cfg->u4_timestamp_high = ps_ip->s_ive_ip.u4_timestamp_high;
5451
4.22k
    ps_cfg->u4_timestamp_low = ps_ip->s_ive_ip.u4_timestamp_low;
5452
5453
4.22k
    return IV_SUCCESS;
5454
4.22k
}
5455
5456
/**
5457
*******************************************************************************
5458
*
5459
* @brief
5460
*  Sets AIR parameters
5461
*
5462
* @par Description:
5463
*  Sets AIR parameters
5464
*
5465
* @param[in] pv_api_ip
5466
*  Pointer to input argument structure
5467
*
5468
* @param[out] pv_api_op
5469
*  Pointer to output argument structure
5470
*
5471
* @param[out] ps_cfg
5472
*  Pointer to config structure to be updated
5473
*
5474
* @returns error status
5475
*
5476
* @remarks none
5477
*
5478
*******************************************************************************
5479
*/
5480
static IV_STATUS_T ih264_set_air_params(void *pv_api_ip,
5481
                                        void *pv_api_op,
5482
                                        cfg_params_t *ps_cfg)
5483
4.22k
{
5484
    /* ctrl call I/O structures */
5485
4.22k
    ih264e_ctl_set_air_params_ip_t *ps_ip = pv_api_ip;
5486
4.22k
    ih264e_ctl_set_air_params_op_t *ps_op = pv_api_op;
5487
5488
4.22k
    ps_op->s_ive_op.u4_error_code = 0;
5489
5490
4.22k
    ps_cfg->e_air_mode = ps_ip->s_ive_ip.e_air_mode;
5491
4.22k
    ps_cfg->u4_air_refresh_period = ps_ip->s_ive_ip.u4_air_refresh_period;
5492
5493
4.22k
    ps_cfg->u4_timestamp_high = ps_ip->s_ive_ip.u4_timestamp_high;
5494
4.22k
    ps_cfg->u4_timestamp_low = ps_ip->s_ive_ip.u4_timestamp_low;
5495
5496
4.22k
    return IV_SUCCESS;
5497
4.22k
}
5498
5499
/**
5500
*******************************************************************************
5501
*
5502
* @brief
5503
*  Sets motion estimation parameters
5504
*
5505
* @par Description:
5506
*  Sets motion estimation parameters
5507
*
5508
* @param[in] pv_api_ip
5509
*  Pointer to input argument structure
5510
*
5511
* @param[out] pv_api_op
5512
*  Pointer to output argument structure
5513
*
5514
* @param[out] ps_cfg
5515
*  Pointer to config structure to be updated
5516
*
5517
* @returns error status
5518
*
5519
* @remarks none
5520
*
5521
*******************************************************************************
5522
*/
5523
static IV_STATUS_T ih264_set_me_params(void *pv_api_ip,
5524
                                       void *pv_api_op,
5525
                                       cfg_params_t *ps_cfg)
5526
1.08k
{
5527
    /* ctrl call I/O structures */
5528
1.08k
    ih264e_ctl_set_me_params_ip_t *ps_ip = pv_api_ip;
5529
1.08k
    ih264e_ctl_set_me_params_op_t *ps_op = pv_api_op;
5530
5531
1.08k
    ps_op->s_ive_op.u4_error_code = 0;
5532
5533
1.08k
    ps_cfg->u4_enable_hpel = ps_ip->s_ive_ip.u4_enable_hpel;
5534
1.08k
    ps_cfg->u4_enable_qpel = ps_ip->s_ive_ip.u4_enable_qpel;
5535
1.08k
    ps_cfg->u4_enable_fast_sad = ps_ip->s_ive_ip.u4_enable_fast_sad;
5536
1.08k
    ps_cfg->u4_enable_alt_ref = ps_ip->s_ive_ip.u4_enable_alt_ref;
5537
1.08k
    ps_cfg->u4_srch_rng_x = ps_ip->s_ive_ip.u4_srch_rng_x;
5538
1.08k
    ps_cfg->u4_srch_rng_y = ps_ip->s_ive_ip.u4_srch_rng_y;
5539
1.08k
    ps_cfg->u4_me_speed_preset = ps_ip->s_ive_ip.u4_me_speed_preset;
5540
5541
1.08k
    ps_cfg->u4_timestamp_high = ps_ip->s_ive_ip.u4_timestamp_high;
5542
1.08k
    ps_cfg->u4_timestamp_low = ps_ip->s_ive_ip.u4_timestamp_low;
5543
5544
1.08k
    return IV_SUCCESS;
5545
1.08k
}
5546
5547
/**
5548
*******************************************************************************
5549
*
5550
* @brief
5551
*  Sets Intra/Inter Prediction estimation parameters
5552
*
5553
* @par Description:
5554
*  Sets Intra/Inter Prediction estimation parameters
5555
*
5556
* @param[in] pv_api_ip
5557
*  Pointer to input argument structure
5558
*
5559
* @param[out] pv_api_op
5560
*  Pointer to output argument structure
5561
*
5562
* @param[out] ps_cfg
5563
*  Pointer to config structure to be updated
5564
*
5565
* @returns error status
5566
*
5567
* @remarks none
5568
*
5569
*******************************************************************************
5570
*/
5571
static IV_STATUS_T ih264_set_ipe_params(void *pv_api_ip,
5572
                                        void *pv_api_op,
5573
                                        cfg_params_t *ps_cfg)
5574
4.22k
{
5575
    /* ctrl call I/O structures */
5576
4.22k
    ih264e_ctl_set_ipe_params_ip_t *ps_ip = pv_api_ip;
5577
4.22k
    ih264e_ctl_set_ipe_params_op_t *ps_op = pv_api_op;
5578
5579
4.22k
    ps_op->s_ive_op.u4_error_code = 0;
5580
5581
4.22k
    ps_cfg->u4_enable_intra_4x4 = ps_ip->s_ive_ip.u4_enable_intra_4x4;
5582
4.22k
    ps_cfg->u4_enc_speed_preset = ps_ip->s_ive_ip.u4_enc_speed_preset;
5583
4.22k
    ps_cfg->u4_constrained_intra_pred = ps_ip->s_ive_ip.u4_constrained_intra_pred;
5584
5585
4.22k
    ps_cfg->u4_timestamp_high = ps_ip->s_ive_ip.u4_timestamp_high;
5586
4.22k
    ps_cfg->u4_timestamp_low = ps_ip->s_ive_ip.u4_timestamp_low;
5587
5588
4.22k
    return IV_SUCCESS;
5589
4.22k
}
5590
5591
/**
5592
*******************************************************************************
5593
*
5594
* @brief
5595
*  Sets GOP parameters
5596
*
5597
* @par Description:
5598
*  Sets GOP parameters
5599
*
5600
* @param[in] pv_api_ip
5601
*  Pointer to input argument structure
5602
*
5603
* @param[out] pv_api_op
5604
*  Pointer to output argument structure
5605
*
5606
* @param[out] ps_cfg
5607
*  Pointer to config structure to be updated
5608
*
5609
* @returns error status
5610
*
5611
* @remarks none
5612
*
5613
*******************************************************************************
5614
*/
5615
static IV_STATUS_T ih264_set_gop_params(void *pv_api_ip,
5616
                                        void *pv_api_op,
5617
                                        cfg_params_t *ps_cfg)
5618
3.47k
{
5619
    /* ctrl call I/O structures */
5620
3.47k
    ih264e_ctl_set_gop_params_ip_t *ps_ip = pv_api_ip;
5621
3.47k
    ih264e_ctl_set_gop_params_op_t *ps_op = pv_api_op;
5622
5623
3.47k
    ps_op->s_ive_op.u4_error_code = 0;
5624
5625
3.47k
    ps_cfg->u4_i_frm_interval = ps_ip->s_ive_ip.u4_i_frm_interval;
5626
3.47k
    ps_cfg->u4_idr_frm_interval = ps_ip->s_ive_ip.u4_idr_frm_interval;
5627
3.47k
    if (ps_cfg->u4_idr_frm_interval < ps_cfg->u4_i_frm_interval)
5628
1.36k
        ps_cfg->u4_i_frm_interval = ps_cfg->u4_idr_frm_interval;
5629
5630
3.47k
    ps_cfg->u4_timestamp_high = ps_ip->s_ive_ip.u4_timestamp_high;
5631
3.47k
    ps_cfg->u4_timestamp_low = ps_ip->s_ive_ip.u4_timestamp_low;
5632
5633
3.47k
    return IV_SUCCESS;
5634
3.47k
}
5635
5636
/**
5637
*******************************************************************************
5638
*
5639
* @brief
5640
*  Sets profile parameters
5641
*
5642
* @par Description:
5643
*  Sets profile parameters
5644
*
5645
* @param[in] pv_api_ip
5646
*  Pointer to input argument structure
5647
*
5648
* @param[out] pv_api_op
5649
*  Pointer to output argument structure
5650
*
5651
* @param[out] ps_cfg
5652
*  Pointer to config structure to be updated
5653
*
5654
* @returns error status
5655
*
5656
* @remarks none
5657
*
5658
*******************************************************************************
5659
*/
5660
static IV_STATUS_T ih264_set_profile_params(void *pv_api_ip,
5661
                                            void *pv_api_op,
5662
                                            cfg_params_t *ps_cfg)
5663
4.22k
{
5664
    /* ctrl call I/O structures */
5665
4.22k
    ih264e_ctl_set_profile_params_ip_t *ps_ip = pv_api_ip;
5666
4.22k
    ih264e_ctl_set_profile_params_op_t *ps_op = pv_api_op;
5667
5668
4.22k
    ps_op->s_ive_op.u4_error_code = 0;
5669
5670
4.22k
    ps_cfg->e_profile = ps_ip->s_ive_ip.e_profile;
5671
4.22k
    ps_cfg->u4_entropy_coding_mode = ps_ip->s_ive_ip.u4_entropy_coding_mode;
5672
5673
4.22k
    ps_cfg->u4_timestamp_high = ps_ip->s_ive_ip.u4_timestamp_high;
5674
4.22k
    ps_cfg->u4_timestamp_low = ps_ip->s_ive_ip.u4_timestamp_low;
5675
5676
4.22k
    return IV_SUCCESS;
5677
4.22k
}
5678
5679
/**
5680
*******************************************************************************
5681
*
5682
* @brief
5683
*  Sets disable deblock level
5684
*
5685
* @par Description:
5686
*  Sets disable deblock level. Level 0 means no disabling  and level 4 means
5687
*  disable completely. 1, 2, 3 are intermediate levels that control amount
5688
*  of deblocking done.
5689
*
5690
* @param[in] ps_codec_obj
5691
*  Pointer to codec object at API level
5692
*
5693
* @param[in] pv_api_ip
5694
*  Pointer to input argument structure
5695
*
5696
* @param[out] pv_api_op
5697
*  Pointer to output argument structure
5698
*
5699
* @returns error status
5700
*
5701
* @remarks none
5702
*
5703
*******************************************************************************
5704
*/
5705
static WORD32 ih264_set_deblock_params(void *pv_api_ip,
5706
                                       void *pv_api_op,
5707
                                       cfg_params_t *ps_cfg)
5708
3.50k
{
5709
    /* ctrl call I/O structures */
5710
3.50k
    ih264e_ctl_set_deblock_params_ip_t *ps_ip = pv_api_ip;
5711
3.50k
    ih264e_ctl_set_deblock_params_op_t *ps_op = pv_api_op;
5712
5713
3.50k
    ps_op->s_ive_op.u4_error_code = 0;
5714
5715
3.50k
    ps_cfg->u4_disable_deblock_level = ps_ip->s_ive_ip.u4_disable_deblock_level;
5716
5717
3.50k
    ps_cfg->u4_timestamp_high = ps_ip->s_ive_ip.u4_timestamp_high;
5718
3.50k
    ps_cfg->u4_timestamp_low = ps_ip->s_ive_ip.u4_timestamp_low;
5719
5720
3.50k
    return IV_SUCCESS;
5721
3.50k
}
5722
/**
5723
 *******************************************************************************
5724
 *
5725
 * @brief
5726
 *  Sets vui params
5727
 *
5728
 * @par Description:
5729
 *  Video usability information
5730
 *
5731
 * @param[in] pv_api_ip
5732
 *  Pointer to input argument structure
5733
 *
5734
 * @param[out] pv_api_op
5735
 *  Pointer to output argument structure
5736
 *
5737
 * @param[out] ps_cfg
5738
 *  Pointer to config structure to be updated
5739
 *
5740
 * @returns error status
5741
 *
5742
 * @remarks none
5743
 *
5744
 *******************************************************************************
5745
 */
5746
static WORD32 ih264e_set_vui_params(void *pv_api_ip,
5747
                                    void *pv_api_op,
5748
                                    cfg_params_t *ps_cfg)
5749
4.22k
{
5750
    /* ctrl call I/O structures */
5751
4.22k
    ih264e_vui_ip_t *ps_ip = pv_api_ip;
5752
4.22k
    ih264e_vui_op_t *ps_op = pv_api_op;
5753
4.22k
    vui_t *ps_vui = &ps_cfg->s_vui;
5754
5755
4.22k
    ps_op->u4_error_code = 0;
5756
5757
4.22k
    ps_vui->u1_aspect_ratio_info_present_flag = ps_ip->u1_aspect_ratio_info_present_flag;
5758
4.22k
    ps_vui->u1_aspect_ratio_idc = ps_ip->u1_aspect_ratio_idc;
5759
4.22k
    ps_vui->u2_sar_width = ps_ip->u2_sar_width;
5760
4.22k
    ps_vui->u2_sar_height = ps_ip->u2_sar_height;
5761
4.22k
    ps_vui->u1_overscan_info_present_flag = ps_ip->u1_overscan_info_present_flag;
5762
4.22k
    ps_vui->u1_overscan_appropriate_flag = ps_ip->u1_overscan_appropriate_flag;
5763
4.22k
    ps_vui->u1_video_signal_type_present_flag = ps_ip->u1_video_signal_type_present_flag;
5764
4.22k
    ps_vui->u1_video_format = ps_ip->u1_video_format;
5765
4.22k
    ps_vui->u1_video_full_range_flag = ps_ip->u1_video_full_range_flag;
5766
4.22k
    ps_vui->u1_colour_description_present_flag = ps_ip->u1_colour_description_present_flag;
5767
4.22k
    ps_vui->u1_colour_primaries = ps_ip->u1_colour_primaries;
5768
4.22k
    ps_vui->u1_transfer_characteristics = ps_ip->u1_transfer_characteristics;
5769
4.22k
    ps_vui->u1_matrix_coefficients = ps_ip->u1_matrix_coefficients;
5770
4.22k
    ps_vui->u1_chroma_loc_info_present_flag = ps_ip->u1_chroma_loc_info_present_flag;
5771
4.22k
    ps_vui->u1_chroma_sample_loc_type_top_field = ps_ip->u1_chroma_sample_loc_type_top_field;
5772
4.22k
    ps_vui->u1_chroma_sample_loc_type_bottom_field = ps_ip->u1_chroma_sample_loc_type_bottom_field;
5773
4.22k
    ps_vui->u1_vui_timing_info_present_flag = ps_ip->u1_vui_timing_info_present_flag;
5774
4.22k
    ps_vui->u4_vui_num_units_in_tick = ps_ip->u4_vui_num_units_in_tick;
5775
4.22k
    ps_vui->u4_vui_time_scale = ps_ip->u4_vui_time_scale;
5776
4.22k
    ps_vui->u1_fixed_frame_rate_flag = ps_ip->u1_fixed_frame_rate_flag;
5777
4.22k
    ps_vui->u1_nal_hrd_parameters_present_flag = ps_ip->u1_nal_hrd_parameters_present_flag;
5778
4.22k
    ps_vui->u1_vcl_hrd_parameters_present_flag = ps_ip->u1_vcl_hrd_parameters_present_flag;
5779
4.22k
    ps_vui->u1_low_delay_hrd_flag = ps_ip->u1_low_delay_hrd_flag;
5780
4.22k
    ps_vui->u1_pic_struct_present_flag = ps_ip->u1_pic_struct_present_flag;
5781
4.22k
    ps_vui->u1_bitstream_restriction_flag = ps_ip->u1_bitstream_restriction_flag;
5782
4.22k
    ps_vui->u1_motion_vectors_over_pic_boundaries_flag = ps_ip->u1_motion_vectors_over_pic_boundaries_flag;
5783
4.22k
    ps_vui->u1_max_bytes_per_pic_denom = ps_ip->u1_max_bytes_per_pic_denom;
5784
4.22k
    ps_vui->u1_max_bits_per_mb_denom = ps_ip->u1_max_bits_per_mb_denom;
5785
4.22k
    ps_vui->u1_log2_max_mv_length_horizontal = ps_ip->u1_log2_max_mv_length_horizontal;
5786
4.22k
    ps_vui->u1_log2_max_mv_length_vertical = ps_ip->u1_log2_max_mv_length_vertical;
5787
4.22k
    ps_vui->u1_num_reorder_frames = ps_ip->u1_num_reorder_frames;
5788
4.22k
    ps_vui->u1_max_dec_frame_buffering = ps_ip->u1_max_dec_frame_buffering;
5789
5790
4.22k
    ps_cfg->u4_timestamp_high = -1;
5791
4.22k
    ps_cfg->u4_timestamp_low = -1;
5792
5793
4.22k
    return IV_SUCCESS;
5794
4.22k
}
5795
5796
/**
5797
 *******************************************************************************
5798
 *
5799
 * @brief
5800
 *  Sets Mastering display color volume sei params
5801
 *
5802
 * @par Description:
5803
 *  Supplemental enhancement information
5804
 *
5805
 * @param[in] pv_api_ip
5806
 *  Pointer to input argument structure
5807
 *
5808
 * @param[out] pv_api_op
5809
 *  Pointer to output argument structure
5810
 *
5811
 * @param[out] ps_cfg
5812
 *  Pointer to config structure to be updated
5813
 *
5814
 * @return error status
5815
 *
5816
 * @remarks none
5817
 *
5818
 *******************************************************************************
5819
 */
5820
static WORD32 ih264e_set_sei_mdcv_params(void *pv_api_ip,
5821
                                         void *pv_api_op,
5822
                                         cfg_params_t *ps_cfg)
5823
4.22k
{
5824
4.22k
    WORD32 i4_count;
5825
    /* ctrl call I/O structures */
5826
4.22k
    ih264e_ctl_set_sei_mdcv_params_ip_t *ps_ip = pv_api_ip;
5827
4.22k
    ih264e_ctl_set_sei_mdcv_params_op_t *ps_op = pv_api_op;
5828
4.22k
    sei_params_t *ps_sei = &ps_cfg->s_sei;
5829
5830
4.22k
    ps_op->u4_error_code = 0;
5831
5832
4.22k
    ps_sei->u1_sei_mdcv_params_present_flag = ps_ip->u1_sei_mdcv_params_present_flag;
5833
16.8k
    for(i4_count = 0; i4_count < NUM_SEI_MDCV_PRIMARIES; i4_count++)
5834
12.6k
    {
5835
12.6k
        ps_sei->s_sei_mdcv_params.au2_display_primaries_x[i4_count] =
5836
12.6k
                                                ps_ip->au2_display_primaries_x[i4_count];
5837
12.6k
        ps_sei->s_sei_mdcv_params.au2_display_primaries_y[i4_count] =
5838
12.6k
                                                ps_ip->au2_display_primaries_y[i4_count];
5839
12.6k
    }
5840
5841
4.22k
    ps_sei->s_sei_mdcv_params.u2_white_point_x = ps_ip->u2_white_point_x;
5842
4.22k
    ps_sei->s_sei_mdcv_params.u2_white_point_y = ps_ip->u2_white_point_y;
5843
4.22k
    ps_sei->s_sei_mdcv_params.u4_max_display_mastering_luminance =
5844
4.22k
                                                ps_ip->u4_max_display_mastering_luminance;
5845
4.22k
    ps_sei->s_sei_mdcv_params.u4_min_display_mastering_luminance =
5846
4.22k
                                                ps_ip->u4_min_display_mastering_luminance;
5847
5848
4.22k
    ps_cfg->u4_timestamp_high = ps_ip->u4_timestamp_high;
5849
4.22k
    ps_cfg->u4_timestamp_low = ps_ip->u4_timestamp_low;
5850
5851
4.22k
    return IV_SUCCESS;
5852
4.22k
}
5853
5854
/**
5855
 *******************************************************************************
5856
 *
5857
 * @brief
5858
 *  Sets content light level sei params
5859
 *
5860
 * @par Description:
5861
 *  Supplemental enhancement information
5862
 *
5863
 * @param[in] pv_api_ip
5864
 *  Pointer to input argument structure
5865
 *
5866
 * @param[out] pv_api_op
5867
 *  Pointer to output argument structure
5868
 *
5869
 * @param[out] ps_cfg
5870
 *  Pointer to config structure to be updated
5871
 *
5872
 * @return error status
5873
 *
5874
 * @remarks none
5875
 *
5876
 *******************************************************************************
5877
 */
5878
static WORD32 ih264e_set_sei_cll_params(void *pv_api_ip,
5879
                                        void *pv_api_op,
5880
                                        cfg_params_t *ps_cfg)
5881
4.22k
{
5882
    /* ctrl call I/O structures */
5883
4.22k
    ih264e_ctl_set_sei_cll_params_ip_t *ps_ip = pv_api_ip;
5884
4.22k
    ih264e_ctl_set_sei_cll_params_op_t *ps_op = pv_api_op;
5885
4.22k
    sei_params_t *ps_sei = &ps_cfg->s_sei;
5886
5887
4.22k
    ps_op->u4_error_code = 0;
5888
5889
4.22k
    ps_sei->u1_sei_cll_params_present_flag = ps_ip->u1_sei_cll_params_present_flag;
5890
5891
4.22k
    ps_sei->s_sei_cll_params.u2_max_content_light_level = ps_ip->u2_max_content_light_level;
5892
4.22k
    ps_sei->s_sei_cll_params.u2_max_pic_average_light_level =
5893
4.22k
                                                ps_ip->u2_max_pic_average_light_level;
5894
5895
4.22k
    ps_cfg->u4_timestamp_high = ps_ip->u4_timestamp_high;
5896
4.22k
    ps_cfg->u4_timestamp_low = ps_ip->u4_timestamp_low;
5897
5898
4.22k
    return IV_SUCCESS;
5899
4.22k
}
5900
5901
/**
5902
 *******************************************************************************
5903
 *
5904
 * @brief
5905
 *  Sets ambient viewing environment sei params
5906
 *
5907
 * @par Description:
5908
 *  Supplemental enhancement information
5909
 *
5910
 * @param[in] pv_api_ip
5911
 *  Pointer to input argument structure
5912
 *
5913
 * @param[out] pv_api_op
5914
 *  Pointer to output argument structure
5915
 *
5916
 * @param[out] ps_cfg
5917
 *  Pointer to config structure to be updated
5918
 *
5919
 * @return error status
5920
 *
5921
 * @remarks none
5922
 *
5923
 *******************************************************************************
5924
 */
5925
static WORD32 ih264e_set_sei_ave_params(void *pv_api_ip,
5926
                                        void *pv_api_op,
5927
                                        cfg_params_t *ps_cfg)
5928
4.22k
{
5929
    /* ctrl call I/O structures */
5930
4.22k
    ih264e_ctl_set_sei_ave_params_ip_t *ps_ip = pv_api_ip;
5931
4.22k
    ih264e_ctl_set_sei_ave_params_op_t *ps_op = pv_api_op;
5932
4.22k
    sei_params_t *ps_sei = &ps_cfg->s_sei;
5933
5934
4.22k
    ps_op->u4_error_code = 0;
5935
5936
4.22k
    ps_sei->u1_sei_ave_params_present_flag = ps_ip->u1_sei_ave_params_present_flag;
5937
5938
4.22k
    ps_sei->s_sei_ave_params.u4_ambient_illuminance = ps_ip->u4_ambient_illuminance;
5939
4.22k
    ps_sei->s_sei_ave_params.u2_ambient_light_x = ps_ip->u2_ambient_light_x;
5940
4.22k
    ps_sei->s_sei_ave_params.u2_ambient_light_y = ps_ip->u2_ambient_light_y;
5941
5942
4.22k
    ps_cfg->u4_timestamp_high = ps_ip->u4_timestamp_high;
5943
4.22k
    ps_cfg->u4_timestamp_low = ps_ip->u4_timestamp_low;
5944
5945
4.22k
    return IV_SUCCESS;
5946
4.22k
}
5947
5948
/**
5949
 *******************************************************************************
5950
 *
5951
 * @brief
5952
 *  Sets content color volume sei params
5953
 *
5954
 * @par Description:
5955
 *  Supplemental enhancement information
5956
 *
5957
 * @param[in] pv_api_ip
5958
 *  Pointer to input argument structure
5959
 *
5960
 * @param[out] pv_api_op
5961
 *  Pointer to output argument structure
5962
 *
5963
 * @param[out] ps_cfg
5964
 *  Pointer to config structure to be updated
5965
 *
5966
 * @return error status
5967
 *
5968
 * @remarks none
5969
 *
5970
 *******************************************************************************
5971
 */
5972
static WORD32 ih264e_set_sei_ccv_params(void *pv_api_ip,
5973
                                        void *pv_api_op,
5974
                                        cfg_params_t *ps_cfg)
5975
4.22k
{
5976
4.22k
    WORD32 i4_count;
5977
    /* ctrl call I/O structures */
5978
4.22k
    ih264e_ctl_set_sei_ccv_params_ip_t *ps_ip = pv_api_ip;
5979
4.22k
    ih264e_ctl_set_sei_ccv_params_op_t *ps_op = pv_api_op;
5980
4.22k
    sei_params_t *ps_sei = &ps_cfg->s_sei;
5981
5982
4.22k
    ps_op->u4_error_code = 0;
5983
5984
4.22k
    ps_sei->u1_sei_ccv_params_present_flag = ps_ip->u1_sei_ccv_params_present_flag;
5985
5986
4.22k
    ps_sei->s_sei_ccv_params.u1_ccv_cancel_flag = ps_ip->u1_ccv_cancel_flag;
5987
4.22k
    ps_sei->s_sei_ccv_params.u1_ccv_persistence_flag = ps_ip->u1_ccv_persistence_flag;
5988
4.22k
    ps_sei->s_sei_ccv_params.u1_ccv_primaries_present_flag =
5989
4.22k
                                                ps_ip->u1_ccv_primaries_present_flag;
5990
4.22k
    ps_sei->s_sei_ccv_params.u1_ccv_min_luminance_value_present_flag =
5991
4.22k
                                                ps_ip->u1_ccv_min_luminance_value_present_flag;
5992
4.22k
    ps_sei->s_sei_ccv_params.u1_ccv_max_luminance_value_present_flag =
5993
4.22k
                                                ps_ip->u1_ccv_max_luminance_value_present_flag;
5994
4.22k
    ps_sei->s_sei_ccv_params.u1_ccv_avg_luminance_value_present_flag =
5995
4.22k
                                                ps_ip->u1_ccv_avg_luminance_value_present_flag;
5996
4.22k
    ps_sei->s_sei_ccv_params.u1_ccv_reserved_zero_2bits =
5997
4.22k
                                                ps_ip->u1_ccv_reserved_zero_2bits;
5998
5999
16.8k
    for(i4_count = 0; i4_count < NUM_SEI_CCV_PRIMARIES; i4_count++)
6000
12.6k
    {
6001
12.6k
        ps_sei->s_sei_ccv_params.ai4_ccv_primaries_x[i4_count] =
6002
12.6k
                                                ps_ip->ai4_ccv_primaries_x[i4_count];
6003
12.6k
        ps_sei->s_sei_ccv_params.ai4_ccv_primaries_y[i4_count] =
6004
12.6k
                                                ps_ip->ai4_ccv_primaries_y[i4_count];
6005
12.6k
    }
6006
6007
4.22k
    ps_sei->s_sei_ccv_params.u4_ccv_min_luminance_value = ps_ip->u4_ccv_min_luminance_value;
6008
4.22k
    ps_sei->s_sei_ccv_params.u4_ccv_max_luminance_value = ps_ip->u4_ccv_max_luminance_value;
6009
4.22k
    ps_sei->s_sei_ccv_params.u4_ccv_avg_luminance_value = ps_ip->u4_ccv_avg_luminance_value;
6010
6011
4.22k
    ps_cfg->u4_timestamp_high = ps_ip->u4_timestamp_high;
6012
4.22k
    ps_cfg->u4_timestamp_low = ps_ip->u4_timestamp_low;
6013
6014
4.22k
    return IV_SUCCESS;
6015
4.22k
}
6016
6017
/**
6018
*******************************************************************************
6019
*
6020
* @brief
6021
 *  Sets shutter interval info sei params
6022
 *
6023
 * @par Description:
6024
 *  Supplemental enhancement information
6025
 *
6026
 * @param[in] pv_api_ip
6027
 *  Pointer to input argument structure
6028
 *
6029
 * @param[out] pv_api_op
6030
 *  Pointer to output argument structure
6031
 *
6032
 * @param[out] ps_cfg
6033
 *  Pointer to config structure to be updated
6034
 *
6035
 * @return error status
6036
 *
6037
 * @remarks none
6038
 *
6039
 *******************************************************************************
6040
 */
6041
static WORD32 ih264e_set_sei_sii_params(void *pv_api_ip, void *pv_api_op, cfg_params_t *ps_cfg)
6042
4.22k
{
6043
    /* ctrl call I/O structures */
6044
4.22k
    ih264e_ctl_set_sei_sii_params_ip_t *ps_ip = pv_api_ip;
6045
4.22k
    ih264e_ctl_set_sei_sii_params_op_t *ps_op = pv_api_op;
6046
4.22k
    sei_params_t *ps_sei = &ps_cfg->s_sei;
6047
6048
4.22k
    ps_op->u4_error_code = 0;
6049
4.22k
    ps_sei->u1_sei_sii_params_present_flag = ps_ip->u1_shutter_interval_info_present_flag;
6050
4.22k
    ps_sei->s_sei_sii_params.u4_sii_sub_layer_idx = ps_ip->u4_sii_sub_layer_idx;
6051
6052
4.22k
    if(0 == ps_sei->s_sei_sii_params.u4_sii_sub_layer_idx)
6053
4.22k
    {
6054
4.22k
        ps_sei->s_sei_sii_params.u1_shutter_interval_info_present_flag =
6055
4.22k
            ps_ip->u1_shutter_interval_info_present_flag;
6056
6057
4.22k
        if(1 == ps_sei->s_sei_sii_params.u1_shutter_interval_info_present_flag)
6058
1.60k
        {
6059
1.60k
            ps_sei->s_sei_sii_params.u4_sii_time_scale = ps_ip->u4_sii_time_scale;
6060
1.60k
            ps_sei->s_sei_sii_params.u1_fixed_shutter_interval_within_cvs_flag =
6061
1.60k
                ps_ip->u1_fixed_shutter_interval_within_cvs_flag;
6062
6063
1.60k
            if(1 == ps_sei->s_sei_sii_params.u1_fixed_shutter_interval_within_cvs_flag)
6064
0
            {
6065
0
                ps_sei->s_sei_sii_params.u4_sii_num_units_in_shutter_interval =
6066
0
                    ps_ip->u4_sii_num_units_in_shutter_interval;
6067
0
            }
6068
1.60k
            else
6069
1.60k
            {
6070
1.60k
                int i;
6071
1.60k
                ps_sei->s_sei_sii_params.u1_sii_max_sub_layers_minus1 =
6072
1.60k
                    ps_ip->u1_sii_max_sub_layers_minus1;
6073
6074
14.4k
                for(i = 0; i <= ps_ip->u1_sii_max_sub_layers_minus1; i++)
6075
12.8k
                {
6076
12.8k
                    ps_sei->s_sei_sii_params.au4_sub_layer_num_units_in_shutter_interval[i] =
6077
12.8k
                        ps_ip->au4_sub_layer_num_units_in_shutter_interval[i];
6078
12.8k
                }
6079
1.60k
            }
6080
1.60k
        }
6081
4.22k
    }
6082
6083
4.22k
    ps_cfg->u4_timestamp_high = ps_ip->u4_timestamp_high;
6084
4.22k
    ps_cfg->u4_timestamp_low = ps_ip->u4_timestamp_low;
6085
6086
4.22k
    return IV_SUCCESS;
6087
4.22k
}
6088
6089
/**
6090
*******************************************************************************
6091
*
6092
* @brief
6093
*  Sets number of cores
6094
*
6095
* @par Description:
6096
*  Sets number of cores
6097
*
6098
* @param[in] ps_codec_obj
6099
*  Pointer to codec object at API level
6100
*
6101
* @param[in] pv_api_ip
6102
*  Pointer to input argument structure
6103
*
6104
* @param[out] pv_api_op
6105
*  Pointer to output argument structure
6106
*
6107
* @returns error status
6108
*
6109
* @remarks The number of encoder threads is limited to MAX_PROCESS_THREADS
6110
*
6111
*******************************************************************************
6112
*/
6113
static WORD32 ih264e_set_num_cores(void *pv_api_ip,
6114
                                   void *pv_api_op,
6115
                                   cfg_params_t *ps_cfg)
6116
4.22k
{
6117
    /* ctrl call I/O structures */
6118
4.22k
    ih264e_ctl_set_num_cores_ip_t *ps_ip = pv_api_ip;
6119
4.22k
    ih264e_ctl_set_num_cores_op_t *ps_op = pv_api_op;
6120
6121
4.22k
    ps_op->s_ive_op.u4_error_code = 0;
6122
6123
4.22k
    ps_cfg->u4_num_cores = MIN(ps_ip->s_ive_ip.u4_num_cores, MAX_PROCESS_THREADS);
6124
6125
4.22k
    ps_cfg->u4_timestamp_high = ps_ip->s_ive_ip.u4_timestamp_high;
6126
4.22k
    ps_cfg->u4_timestamp_low = ps_ip->s_ive_ip.u4_timestamp_low;
6127
6128
4.22k
    return IV_SUCCESS;
6129
4.22k
}
6130
6131
/**
6132
*******************************************************************************
6133
*
6134
* @brief
6135
*  Resets encoder state
6136
*
6137
* @par Description:
6138
*  Resets encoder state by calling ih264e_init()
6139
*
6140
* @param[in] ps_codec_obj
6141
*  Pointer to codec object at API level
6142
*
6143
* @param[in] pv_api_ip
6144
*  Pointer to input argument structure
6145
*
6146
* @param[out] pv_api_op
6147
*  Pointer to output argument structure
6148
*
6149
* @returns  error status
6150
*
6151
* @remarks none
6152
*
6153
*******************************************************************************
6154
*/
6155
static WORD32 ih264e_reset(iv_obj_t *ps_codec_obj,
6156
                           void *pv_api_ip,
6157
                           void *pv_api_op)
6158
0
{
6159
    /* codec ctxt */
6160
0
    codec_t * ps_codec = (codec_t *) (ps_codec_obj->pv_codec_handle);
6161
6162
    /* ctrl call I/O structures */
6163
0
    ih264e_ctl_reset_op_t *ps_op = pv_api_op;
6164
6165
0
    UNUSED(pv_api_ip);
6166
6167
0
    ps_op->s_ive_op.u4_error_code = 0;
6168
6169
0
    if (ps_codec != NULL)
6170
0
    {
6171
0
        if (ps_codec->s_cfg.u4_keep_threads_active)
6172
0
        {
6173
            /* Shutdown active threads before reinitialization */
6174
0
            ih264e_thread_pool_shutdown(ps_codec);
6175
0
        }
6176
0
        ih264e_init(ps_codec);
6177
0
    }
6178
0
    else
6179
0
    {
6180
0
        ps_op->s_ive_op.u4_error_code = IH264E_INIT_NOT_DONE;
6181
0
    }
6182
6183
0
    return IV_SUCCESS;
6184
0
}
6185
6186
/**
6187
*******************************************************************************
6188
*
6189
* @brief
6190
*  Codec control call
6191
*
6192
* @par Description:
6193
*  Codec control call which in turn calls appropriate calls  based on sub-command
6194
*
6195
* @param[in] ps_codec_obj
6196
*  Pointer to codec object at API level
6197
*
6198
* @param[in] pv_api_ip
6199
*  Pointer to input argument structure
6200
*
6201
* @param[out] pv_api_op
6202
*  Pointer to output argument structure
6203
*
6204
* @returns error status
6205
*
6206
* @remarks none
6207
*
6208
*******************************************************************************
6209
*/
6210
static WORD32 ih264e_ctl(iv_obj_t *ps_codec_obj,
6211
                         void *pv_api_ip,
6212
                         void *pv_api_op)
6213
87.5k
{
6214
    /* codec ctxt */
6215
87.5k
    codec_t *ps_codec = (codec_t *) ps_codec_obj->pv_codec_handle;
6216
6217
    /* ctrl call I/O structures */
6218
87.5k
    ih264e_ctl_setdefault_ip_t *ps_ctl_ip = pv_api_ip;
6219
87.5k
    ih264e_ctl_setdefault_op_t *ps_ctl_op = pv_api_op;
6220
6221
    /* ctrl call sub cmd */
6222
87.5k
    IVE_CONTROL_API_COMMAND_TYPE_T sub_cmd = ps_ctl_ip->s_ive_ip.e_sub_cmd;
6223
6224
    /* error status */
6225
87.5k
    IV_STATUS_T ret = IV_SUCCESS;
6226
6227
    /* temp var */
6228
87.5k
    WORD32 i;
6229
87.5k
    cfg_params_t *ps_cfg = NULL;
6230
6231
    /* control call is for configuring encoding params, this is not to be called
6232
     * before a successful init call */
6233
87.5k
    if (ps_codec->i4_init_done != 1)
6234
0
    {
6235
0
        ps_ctl_op->s_ive_op.u4_error_code |= 1 << IVE_FATALERROR;
6236
0
        ps_ctl_op->s_ive_op.u4_error_code |= IH264E_INIT_NOT_DONE;
6237
0
        return IV_FAIL;
6238
0
    }
6239
6240
    /* make it thread safe */
6241
87.5k
    ithread_mutex_lock(ps_codec->pv_ctl_mutex);
6242
6243
    /* find a free config param set to hold current parameters */
6244
755k
    for (i = 0; i < MAX_ACTIVE_CONFIG_PARAMS; i++)
6245
755k
    {
6246
755k
        if (0 == ps_codec->as_cfg[i].u4_is_valid)
6247
87.5k
        {
6248
87.5k
            ps_cfg = &ps_codec->as_cfg[i];
6249
87.5k
            break;
6250
87.5k
        }
6251
755k
    }
6252
6253
    /* If all are invalid, then start overwriting from the head config params */
6254
87.5k
    if (NULL == ps_cfg)
6255
0
    {
6256
0
        ps_cfg = &ps_codec->as_cfg[0];
6257
0
    }
6258
6259
87.5k
    ps_cfg->u4_is_valid = 1;
6260
6261
87.5k
    ps_cfg->e_cmd = sub_cmd;
6262
6263
87.5k
    switch (sub_cmd)
6264
87.5k
    {
6265
4.08k
        case IVE_CMD_CTL_SET_DIMENSIONS:
6266
4.08k
            ret = ih264e_set_dimensions(pv_api_ip, pv_api_op, ps_cfg);
6267
4.08k
            break;
6268
6269
2.32k
        case IVE_CMD_CTL_SET_FRAMERATE:
6270
2.32k
            ret = ih264e_set_frame_rate(pv_api_ip, pv_api_op, ps_cfg);
6271
2.32k
            break;
6272
6273
4.66k
        case IVE_CMD_CTL_SET_BITRATE:
6274
4.66k
            ret = ih264e_set_bit_rate(pv_api_ip, pv_api_op, ps_cfg);
6275
4.66k
            break;
6276
6277
913
        case IVE_CMD_CTL_SET_FRAMETYPE:
6278
913
            ret = ih264e_set_frame_type(pv_api_ip, pv_api_op, ps_cfg);
6279
913
            break;
6280
6281
4.22k
        case IVE_CMD_CTL_SET_QP:
6282
4.22k
            ret = ih264e_set_qp(pv_api_ip, pv_api_op, ps_cfg);
6283
4.22k
            break;
6284
6285
4.22k
        case IVE_CMD_CTL_SET_ENC_MODE:
6286
4.22k
            ret = ih264e_set_enc_mode(pv_api_ip, pv_api_op, ps_cfg);
6287
4.22k
            break;
6288
6289
4.22k
        case IVE_CMD_CTL_SET_VBV_PARAMS:
6290
4.22k
            ret = ih264e_set_vbv_params(pv_api_ip, pv_api_op, ps_cfg);
6291
4.22k
            break;
6292
6293
4.22k
        case IVE_CMD_CTL_SET_AIR_PARAMS:
6294
4.22k
            ret = ih264_set_air_params(pv_api_ip, pv_api_op, ps_cfg);
6295
4.22k
            break;
6296
6297
1.08k
        case IVE_CMD_CTL_SET_ME_PARAMS:
6298
1.08k
            ret = ih264_set_me_params(pv_api_ip, pv_api_op, ps_cfg);
6299
1.08k
            break;
6300
6301
4.22k
        case IVE_CMD_CTL_SET_IPE_PARAMS:
6302
4.22k
            ret = ih264_set_ipe_params(pv_api_ip, pv_api_op, ps_cfg);
6303
4.22k
            break;
6304
6305
3.47k
        case IVE_CMD_CTL_SET_GOP_PARAMS:
6306
3.47k
            ret = ih264_set_gop_params(pv_api_ip, pv_api_op, ps_cfg);
6307
3.47k
            break;
6308
6309
4.22k
        case IVE_CMD_CTL_SET_PROFILE_PARAMS:
6310
4.22k
            ret = ih264_set_profile_params(pv_api_ip, pv_api_op, ps_cfg);
6311
4.22k
            break;
6312
6313
3.50k
        case IVE_CMD_CTL_SET_DEBLOCK_PARAMS:
6314
3.50k
            ret = ih264_set_deblock_params(pv_api_ip, pv_api_op, ps_cfg);
6315
3.50k
            break;
6316
6317
4.22k
        case IVE_CMD_CTL_SET_VUI_PARAMS:
6318
4.22k
            ret = ih264e_set_vui_params(pv_api_ip, pv_api_op, ps_cfg);
6319
4.22k
            break;
6320
6321
4.22k
        case IVE_CMD_CTL_SET_SEI_MDCV_PARAMS:
6322
4.22k
            ret = ih264e_set_sei_mdcv_params(pv_api_ip, pv_api_op, ps_cfg);
6323
4.22k
            break;
6324
6325
4.22k
        case IVE_CMD_CTL_SET_SEI_CLL_PARAMS:
6326
4.22k
            ret = ih264e_set_sei_cll_params(pv_api_ip, pv_api_op, ps_cfg);
6327
4.22k
            break;
6328
6329
4.22k
        case IVE_CMD_CTL_SET_SEI_AVE_PARAMS:
6330
4.22k
            ret = ih264e_set_sei_ave_params(pv_api_ip, pv_api_op, ps_cfg);
6331
4.22k
            break;
6332
6333
4.22k
        case IVE_CMD_CTL_SET_SEI_CCV_PARAMS:
6334
4.22k
            ret = ih264e_set_sei_ccv_params(pv_api_ip, pv_api_op, ps_cfg);
6335
4.22k
            break;
6336
6337
4.22k
        case IVE_CMD_CTL_SET_SEI_SII_PARAMS:
6338
4.22k
            ret = ih264e_set_sei_sii_params(pv_api_ip, pv_api_op, ps_cfg);
6339
4.22k
            break;
6340
6341
0
        case IVE_CMD_CTL_RESET:
6342
6343
            /* invalidate config param struct as it is being served right away */
6344
0
            ps_codec->as_cfg[i].u4_is_valid = 0;
6345
6346
0
            ret = ih264e_reset(ps_codec_obj, pv_api_ip, pv_api_op);
6347
0
            break;
6348
6349
4.22k
        case IVE_CMD_CTL_SETDEFAULT:
6350
4.22k
        {
6351
            /* ctrl call I/O structures */
6352
4.22k
            ih264e_ctl_setdefault_op_t *ps_op = pv_api_op;
6353
6354
            /* invalidate config param struct as it is being served right away */
6355
4.22k
            ps_codec->as_cfg[i].u4_is_valid = 0;
6356
6357
            /* error status */
6358
4.22k
            ret = ih264e_set_default_params(ps_cfg);
6359
6360
4.22k
            ps_op->s_ive_op.u4_error_code = ret;
6361
6362
4.22k
            break;
6363
0
        }
6364
6365
0
        case IVE_CMD_CTL_FLUSH:
6366
6367
            /* invalidate config param struct as it is being served right away */
6368
0
            ps_codec->as_cfg[i].u4_is_valid = 0;
6369
6370
0
            ret = ih264e_set_flush_mode(ps_codec_obj, pv_api_ip, pv_api_op);
6371
0
            break;
6372
6373
4.16k
        case IVE_CMD_CTL_GETBUFINFO:
6374
6375
            /* invalidate config param struct as it is being served right away */
6376
4.16k
            ps_codec->as_cfg[i].u4_is_valid = 0;
6377
6378
4.16k
            ret = ih264e_get_buf_info(ps_codec_obj, pv_api_ip, pv_api_op);
6379
4.16k
            break;
6380
6381
4.22k
        case IVE_CMD_CTL_GETVERSION:
6382
4.22k
        {
6383
            /* ctrl call I/O structures */
6384
4.22k
            ih264e_ctl_getversioninfo_ip_t *ps_ip = pv_api_ip;
6385
4.22k
            ih264e_ctl_getversioninfo_op_t *ps_op = pv_api_op;
6386
6387
            /* invalidate config param struct as it is being served right away */
6388
4.22k
            ps_codec->as_cfg[i].u4_is_valid = 0;
6389
6390
            /* error status */
6391
4.22k
            ps_op->s_ive_op.u4_error_code = IV_SUCCESS;
6392
6393
4.22k
            if (ps_ip->s_ive_ip.u4_version_bufsize <= 0)
6394
0
            {
6395
0
                ps_op->s_ive_op.u4_error_code =
6396
0
                                IH264E_CXA_VERS_BUF_INSUFFICIENT;
6397
0
                ret = IV_FAIL;
6398
0
            }
6399
4.22k
            else
6400
4.22k
            {
6401
4.22k
                ret = ih264e_get_version((CHAR *) ps_ip->s_ive_ip.pu1_version,
6402
4.22k
                                         ps_ip->s_ive_ip.u4_version_bufsize);
6403
6404
4.22k
                if (ret != IV_SUCCESS)
6405
0
                {
6406
0
                    ps_op->s_ive_op.u4_error_code =
6407
0
                                    IH264E_CXA_VERS_BUF_INSUFFICIENT;
6408
0
                    ret = IV_FAIL;
6409
0
                }
6410
4.22k
            }
6411
4.22k
            break;
6412
0
        }
6413
6414
4.22k
        case IVE_CMD_CTL_SET_NUM_CORES:
6415
4.22k
            ret = ih264e_set_num_cores(pv_api_ip, pv_api_op, ps_cfg);
6416
4.22k
            break;
6417
6418
0
        default:
6419
            /* invalidate config param struct as it is being served right away */
6420
0
            ps_codec->as_cfg[i].u4_is_valid = 0;
6421
6422
0
            DEBUG("Warning !! unrecognized control api command \n");
6423
0
            break;
6424
87.5k
    }
6425
6426
87.5k
    ithread_mutex_unlock(ps_codec->pv_ctl_mutex);
6427
6428
87.5k
    return ret;
6429
87.5k
}
6430
6431
/**
6432
*******************************************************************************
6433
*
6434
* @brief
6435
*  Codec entry point function. All the function calls to  the codec are done
6436
*  using this function with different values specified in command
6437
*
6438
* @par Description:
6439
*  Arguments are tested for validity and then based on the command
6440
*  appropriate function is called
6441
*
6442
* @param[in] ps_handle
6443
*  API level handle for codec
6444
*
6445
* @param[in] pv_api_ip
6446
*  Input argument structure
6447
*
6448
* @param[out] pv_api_op
6449
*  Output argument structure
6450
*
6451
* @returns  error_status
6452
*
6453
* @remarks
6454
*
6455
*******************************************************************************
6456
*/
6457
IV_STATUS_T ih264e_api_function(iv_obj_t *ps_handle,
6458
                                void *pv_api_ip,
6459
                                void *pv_api_op)
6460
183k
{
6461
    /* api command */
6462
183k
    WORD32 command = IV_CMD_NA;
6463
6464
    /* error status */
6465
183k
    IV_STATUS_T e_status;
6466
183k
    WORD32 ret;
6467
6468
    /* tmp var */
6469
183k
    WORD32 *pu4_ptr_cmd = (WORD32 *) pv_api_ip;
6470
6471
    /* validate input / output structures */
6472
183k
    e_status = api_check_struct_sanity(ps_handle, pv_api_ip, pv_api_op);
6473
6474
183k
    if (e_status != IV_SUCCESS)
6475
7.97k
    {
6476
7.97k
        DEBUG("error code = %d\n", *((UWORD32 *)pv_api_op + 1));
6477
7.97k
        return IV_FAIL;
6478
7.97k
    }
6479
6480
175k
    pu4_ptr_cmd++;
6481
6482
175k
    command = *pu4_ptr_cmd;
6483
6484
175k
    switch (command)
6485
175k
    {
6486
4.24k
        case IV_CMD_GET_NUM_MEM_REC:
6487
4.24k
            ret = ih264e_get_num_rec(pv_api_ip, pv_api_op);
6488
4.24k
            break;
6489
6490
8.45k
        case IV_CMD_FILL_NUM_MEM_REC:
6491
8.45k
            ret = ih264e_fill_num_mem_rec(pv_api_ip, pv_api_op);
6492
8.45k
            break;
6493
6494
4.22k
        case IV_CMD_INIT:
6495
4.22k
            ret = ih264e_init_mem_rec(ps_handle, pv_api_ip, pv_api_op);
6496
4.22k
            break;
6497
6498
4.22k
        case IV_CMD_RETRIEVE_MEMREC:
6499
4.22k
            ret = ih264e_retrieve_memrec(ps_handle, pv_api_ip, pv_api_op);
6500
4.22k
            break;
6501
6502
87.5k
        case IVE_CMD_VIDEO_CTL:
6503
87.5k
            ret = ih264e_ctl(ps_handle, pv_api_ip, pv_api_op);
6504
87.5k
            break;
6505
6506
66.5k
        case IVE_CMD_VIDEO_ENCODE:
6507
66.5k
            ret = ih264e_encode(ps_handle, pv_api_ip, pv_api_op);
6508
66.5k
            break;
6509
6510
0
        default:
6511
0
            ret = IV_FAIL;
6512
0
            break;
6513
175k
    }
6514
6515
175k
    return (IV_STATUS_T) ret;
6516
175k
}