Coverage Report

Created: 2026-06-10 07:07

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libavc/encoder/ih264e_api.c
Line
Count
Source
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
0
{
166
    /* api call */
167
0
    WORD32 command = IV_CMD_NA;
168
169
    /* input structure expected by the api call */
170
0
    UWORD32 *pu4_api_ip = pv_api_ip;
171
172
    /* output structure expected by the api call */
173
0
    UWORD32 *pu4_api_op = pv_api_op;
174
175
    /* temp var */
176
0
    WORD32 i, j;
177
178
0
    if (NULL == pv_api_op || NULL == pv_api_ip)
179
0
    {
180
0
        return (IV_FAIL);
181
0
    }
182
183
    /* get command */
184
0
    command = pu4_api_ip[1];
185
186
    /* set error code */
187
0
    pu4_api_op[1] = 0;
188
189
    /* error checks on handle */
190
0
    switch (command)
191
0
    {
192
0
        case IV_CMD_GET_NUM_MEM_REC:
193
0
        case IV_CMD_FILL_NUM_MEM_REC:
194
0
            break;
195
196
0
        case IV_CMD_INIT:
197
0
            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
0
            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
0
            break;
211
212
0
        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
0
        case IV_CMD_RETRIEVE_MEMREC:
217
0
        case IVE_CMD_VIDEO_CTL:
218
0
        case IVE_CMD_VIDEO_ENCODE:
219
220
0
            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
0
            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
0
            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
0
            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
0
            break;
248
249
0
        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
0
    }
254
255
    /* error checks on input output structures */
256
0
    switch (command)
257
0
    {
258
0
        case IV_CMD_GET_NUM_MEM_REC:
259
0
        {
260
0
            ih264e_num_mem_rec_ip_t *ps_ip = pv_api_ip;
261
0
            ih264e_num_mem_rec_op_t *ps_op = pv_api_op;
262
263
0
            ps_op->s_ive_op.u4_error_code = 0;
264
265
0
            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
0
            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
0
            break;
281
0
        }
282
283
0
        case IV_CMD_FILL_NUM_MEM_REC:
284
0
        {
285
0
            ih264e_fill_mem_rec_ip_t *ps_ip = pv_api_ip;
286
0
            ih264e_fill_mem_rec_op_t *ps_op = pv_api_op;
287
288
0
            iv_mem_rec_t *ps_mem_rec = NULL;
289
290
0
            WORD32 max_wd = ALIGN16(ps_ip->s_ive_ip.u4_max_wd);
291
0
            WORD32 max_ht = ALIGN16(ps_ip->s_ive_ip.u4_max_ht);
292
293
0
            ps_op->s_ive_op.u4_error_code = 0;
294
295
0
            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
0
            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
0
            if (max_wd < MIN_WD || max_wd > MAX_WD)
312
0
            {
313
0
                ps_op->s_ive_op.u4_error_code |= 1 << IVE_UNSUPPORTEDPARAM;
314
0
                ps_op->s_ive_op.u4_error_code |= IH264E_WIDTH_NOT_SUPPORTED;
315
0
                return (IV_FAIL);
316
0
            }
317
318
0
            if (max_ht < MIN_HT || max_ht > MAX_HT)
319
0
            {
320
0
                ps_op->s_ive_op.u4_error_code |= 1 << IVE_UNSUPPORTEDPARAM;
321
0
                ps_op->s_ive_op.u4_error_code |= IH264E_HEIGHT_NOT_SUPPORTED;
322
0
                return (IV_FAIL);
323
0
            }
324
325
            /* verify number of mem rec ptr */
326
0
            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
0
            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
0
            ps_mem_rec = ps_ip->s_ive_ip.ps_mem_rec;
345
0
            for (i = 0; i < MEM_REC_CNT; i++)
346
0
            {
347
0
                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
0
            }
355
0
            break;
356
0
        }
357
358
0
        case IV_CMD_INIT:
359
0
        {
360
0
            ih264e_init_ip_t *ps_ip = pv_api_ip;
361
0
            ih264e_init_op_t *ps_op = pv_api_op;
362
363
0
            iv_mem_rec_t *ps_mem_rec = NULL;
364
365
0
            WORD32 max_wd = ALIGN16(ps_ip->s_ive_ip.u4_max_wd);
366
0
            WORD32 max_ht = ALIGN16(ps_ip->s_ive_ip.u4_max_ht);
367
368
0
            ps_op->s_ive_op.u4_error_code = 0;
369
370
0
            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
0
            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
0
            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
0
            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
0
            if (ps_ip->s_ive_ip.u4_max_ref_cnt > MAX_REF_PIC_CNT ||
401
0
                           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
0
            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
0
            if ((ps_ip->s_ive_ip.u4_max_level != IH264_LEVEL_10)
416
0
                            && (ps_ip->s_ive_ip.u4_max_level != IH264_LEVEL_1B)
417
0
                            && (ps_ip->s_ive_ip.u4_max_level != IH264_LEVEL_11)
418
0
                            && (ps_ip->s_ive_ip.u4_max_level != IH264_LEVEL_12)
419
0
                            && (ps_ip->s_ive_ip.u4_max_level != IH264_LEVEL_13)
420
0
                            && (ps_ip->s_ive_ip.u4_max_level != IH264_LEVEL_20)
421
0
                            && (ps_ip->s_ive_ip.u4_max_level != IH264_LEVEL_21)
422
0
                            && (ps_ip->s_ive_ip.u4_max_level != IH264_LEVEL_22)
423
0
                            && (ps_ip->s_ive_ip.u4_max_level != IH264_LEVEL_30)
424
0
                            && (ps_ip->s_ive_ip.u4_max_level != IH264_LEVEL_31)
425
0
                            && (ps_ip->s_ive_ip.u4_max_level != IH264_LEVEL_32)
426
0
                            && (ps_ip->s_ive_ip.u4_max_level != IH264_LEVEL_40)
427
0
                            && (ps_ip->s_ive_ip.u4_max_level != IH264_LEVEL_41)
428
0
                            && (ps_ip->s_ive_ip.u4_max_level != IH264_LEVEL_42)
429
0
                            && (ps_ip->s_ive_ip.u4_max_level != IH264_LEVEL_50)
430
0
                            && (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
0
            if ((ps_ip->s_ive_ip.e_inp_color_fmt != IV_YUV_420P)
439
0
                            && (ps_ip->s_ive_ip.e_inp_color_fmt != IV_YUV_422ILE)
440
0
                            && (ps_ip->s_ive_ip.e_inp_color_fmt != IV_YUV_420SP_UV)
441
0
                            && (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
0
            if ((ps_ip->s_ive_ip.e_recon_color_fmt != IV_YUV_420P)
450
0
                            && (ps_ip->s_ive_ip.e_recon_color_fmt != IV_YUV_420SP_UV)
451
0
                            && (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
0
            if ((ps_ip->s_ive_ip.e_rc_mode != IVE_RC_NONE)
460
0
                            && (ps_ip->s_ive_ip.e_rc_mode != IVE_RC_STORAGE)
461
0
                            && (ps_ip->s_ive_ip.e_rc_mode != IVE_RC_CBR_NON_LOW_DELAY))
462
0
            {
463
0
                ps_op->s_ive_op.u4_error_code |= 1 << IVE_UNSUPPORTEDPARAM;
464
0
                ps_op->s_ive_op.u4_error_code |=
465
0
                                IH264E_RATE_CONTROL_MODE_NOT_SUPPORTED;
466
0
                return (IV_FAIL);
467
0
            }
468
469
0
            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
0
            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
0
            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
0
            if (ps_ip->s_ive_ip.u4_num_bframes
492
0
                            && (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
0
            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
0
            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
0
            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
0
            if ((ps_ip->s_ive_ip.e_slice_mode != IVE_SLICE_MODE_NONE)
524
0
                            && (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
0
            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
0
            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
0
            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
0
            ps_mem_rec = ps_ip->s_ive_ip.ps_mem_rec;
562
563
            /* check memrecords sizes are correct */
564
0
            for (i = 0; i <((WORD32)ps_ip->s_ive_ip.u4_num_mem_rec); i++)
565
0
            {
566
0
                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
0
                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
0
            }
583
584
            /* verify memtabs for overlapping regions */
585
0
            {
586
0
                void *start[MEM_REC_CNT];
587
0
                void *end[MEM_REC_CNT];
588
589
0
                start[0] = (ps_mem_rec[0].pv_base);
590
0
                end[0] = ((UWORD8 *) ps_mem_rec[0].pv_base)
591
0
                                + ps_mem_rec[0].u4_mem_size - 1;
592
593
0
                for (i = 1; i < MEM_REC_CNT; i++)
594
0
                {
595
                    /* This array is populated to check memtab overlap */
596
0
                    start[i] = (ps_mem_rec[i].pv_base);
597
0
                    end[i] = ((UWORD8 *) ps_mem_rec[i].pv_base)
598
0
                                    + ps_mem_rec[i].u4_mem_size - 1;
599
600
0
                    for (j = 0; j < i; j++)
601
0
                    {
602
0
                        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
0
                        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
0
                        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
0
                    }
629
0
                }
630
0
            }
631
632
            /* re-validate mem records with init config */
633
0
            {
634
                /* mem records */
635
0
                iv_mem_rec_t s_mem_rec_ittiam_api[MEM_REC_CNT];
636
637
                /* api interface structs */
638
0
                ih264e_fill_mem_rec_ip_t s_ip;
639
0
                ih264e_fill_mem_rec_op_t s_op;
640
641
                /* error status */
642
0
                IV_STATUS_T e_status;
643
644
                /* temp var */
645
0
                WORD32 i;
646
647
0
                s_ip.s_ive_ip.u4_size = sizeof(ih264e_fill_mem_rec_ip_t);
648
0
                s_op.s_ive_op.u4_size = sizeof(ih264e_fill_mem_rec_op_t);
649
650
0
                s_ip.s_ive_ip.e_cmd = IV_CMD_FILL_NUM_MEM_REC;
651
0
                s_ip.s_ive_ip.ps_mem_rec = s_mem_rec_ittiam_api;
652
0
                s_ip.s_ive_ip.u4_max_wd = max_wd;
653
0
                s_ip.s_ive_ip.u4_max_ht = max_ht;
654
0
                s_ip.s_ive_ip.u4_num_mem_rec = ps_ip->s_ive_ip.u4_num_mem_rec;
655
0
                s_ip.s_ive_ip.u4_max_level = ps_ip->s_ive_ip.u4_max_level;
656
0
                s_ip.s_ive_ip.u4_max_ref_cnt = ps_ip->s_ive_ip.u4_max_ref_cnt;
657
0
                s_ip.s_ive_ip.u4_max_reorder_cnt =
658
0
                                ps_ip->s_ive_ip.u4_max_reorder_cnt;
659
0
                s_ip.s_ive_ip.e_color_format = ps_ip->s_ive_ip.e_inp_color_fmt;
660
0
                s_ip.s_ive_ip.u4_max_srch_rng_x =
661
0
                                ps_ip->s_ive_ip.u4_max_srch_rng_x;
662
0
                s_ip.s_ive_ip.u4_max_srch_rng_y =
663
0
                                ps_ip->s_ive_ip.u4_max_srch_rng_y;
664
0
                s_ip.s_ive_ip.u4_keep_threads_active = ps_ip->s_ive_ip.u4_keep_threads_active;
665
666
0
                for (i = 0; i < MEM_REC_CNT; i++)
667
0
                {
668
0
                    s_mem_rec_ittiam_api[i].u4_size = sizeof(iv_mem_rec_t);
669
0
                }
670
671
                /* fill mem records */
672
0
                e_status = ih264e_api_function(NULL, (void *) &s_ip,
673
0
                                               (void *) &s_op);
674
675
0
                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
0
                for (i = 0; i < MEM_REC_CNT; i++)
683
0
                {
684
0
                    if (ps_mem_rec[i].u4_mem_size
685
0
                                    < 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
0
                    if (ps_mem_rec[i].u4_mem_alignment
696
0
                                    != 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
0
                    if (ps_mem_rec[i].e_mem_type
707
0
                                    != 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
0
                }
758
0
            }
759
0
            break;
760
0
        }
761
762
0
        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
0
        case IV_CMD_RETRIEVE_MEMREC:
769
0
        {
770
0
            ih264e_retrieve_mem_rec_ip_t *ps_ip = pv_api_ip;
771
0
            ih264e_retrieve_mem_rec_op_t *ps_op = pv_api_op;
772
773
0
            iv_mem_rec_t *ps_mem_rec = NULL;
774
775
0
            ps_op->s_ive_op.u4_error_code = 0;
776
777
0
            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
0
            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
0
            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
0
            ps_mem_rec = ps_ip->s_ive_ip.ps_mem_rec;
802
803
            /* check memrecords sizes are correct */
804
0
            for (i = 0; i < MEM_REC_CNT; i++)
805
0
            {
806
0
                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
0
            }
814
0
            break;
815
0
        }
816
817
0
        case IVE_CMD_VIDEO_ENCODE:
818
0
        {
819
0
            ih264e_video_encode_ip_t *ps_ip = pv_api_ip;
820
0
            ih264e_video_encode_op_t *ps_op = pv_api_op;
821
822
0
            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
0
            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
0
            break;
839
0
        }
840
841
0
        case IVE_CMD_VIDEO_CTL:
842
0
        {
843
            /* ptr to input structure */
844
0
            WORD32 *pu4_ptr_cmd = pv_api_ip;
845
846
            /* sub command */
847
0
            WORD32 sub_command = pu4_ptr_cmd[2];
848
849
0
            switch (sub_command)
850
0
            {
851
0
                case IVE_CMD_CTL_SETDEFAULT:
852
0
                {
853
0
                    ih264e_ctl_setdefault_ip_t *ps_ip = pv_api_ip;
854
0
                    ih264e_ctl_setdefault_op_t *ps_op = pv_api_op;
855
856
0
                    if (ps_ip->s_ive_ip.u4_size
857
0
                                    != 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
0
                    if (ps_op->s_ive_op.u4_size
867
0
                                    != 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
0
                    break;
876
0
                }
877
878
0
                case IVE_CMD_CTL_GETBUFINFO:
879
0
                {
880
0
                    codec_t *ps_codec = (codec_t *) (ps_handle->pv_codec_handle);
881
882
0
                    ih264e_ctl_getbufinfo_ip_t *ps_ip = pv_api_ip;
883
0
                    ih264e_ctl_getbufinfo_op_t *ps_op = pv_api_op;
884
885
0
                    if (ps_ip->s_ive_ip.u4_size
886
0
                                    != 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
0
                    if (ps_op->s_ive_op.u4_size
896
0
                                    != 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
0
                    if (ps_ip->s_ive_ip.u4_max_wd < MIN_WD)
906
0
                    {
907
0
                        ps_op->s_ive_op.u4_error_code |= 1
908
0
                                        << IVE_UNSUPPORTEDPARAM;
909
0
                        ps_op->s_ive_op.u4_error_code |=
910
0
                                        IH264E_WIDTH_NOT_SUPPORTED;
911
0
                        return (IV_FAIL);
912
0
                    }
913
914
0
                    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
0
                    if (ps_ip->s_ive_ip.u4_max_ht < MIN_HT)
924
0
                    {
925
0
                        ps_op->s_ive_op.u4_error_code |= 1
926
0
                                        << IVE_UNSUPPORTEDPARAM;
927
0
                        ps_op->s_ive_op.u4_error_code |=
928
0
                                        IH264E_HEIGHT_NOT_SUPPORTED;
929
0
                        return (IV_FAIL);
930
0
                    }
931
932
0
                    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
0
                    if ((ps_ip->s_ive_ip.e_inp_color_fmt != IV_YUV_420P)
942
0
                                    && (ps_ip->s_ive_ip.e_inp_color_fmt != IV_YUV_422ILE)
943
0
                                    && (ps_ip->s_ive_ip.e_inp_color_fmt != IV_YUV_420SP_UV)
944
0
                                    && (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
0
                    break;
953
0
                }
954
955
0
                case IVE_CMD_CTL_GETVERSION:
956
0
                {
957
0
                    ih264e_ctl_getversioninfo_ip_t *ps_ip = pv_api_ip;
958
0
                    ih264e_ctl_getversioninfo_op_t *ps_op = pv_api_op;
959
960
0
                    if (ps_ip->s_ive_ip.u4_size
961
0
                                    != 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
0
                    if (ps_op->s_ive_op.u4_size
971
0
                                    != 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
0
                    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
0
                    break;
990
0
                }
991
992
0
                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
0
                case IVE_CMD_CTL_SET_NUM_CORES:
1049
0
                {
1050
0
                    ih264e_ctl_set_num_cores_ip_t *ps_ip = pv_api_ip;
1051
0
                    ih264e_ctl_set_num_cores_op_t *ps_op = pv_api_op;
1052
1053
0
                    if (ps_ip->s_ive_ip.u4_size
1054
0
                                    != 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
0
                    if (ps_op->s_ive_op.u4_size
1064
0
                                    != 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
0
                    if ((ps_ip->s_ive_ip.u4_num_cores < 1)
1074
0
                                    || (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
0
                    break;
1084
0
                }
1085
1086
0
                case IVE_CMD_CTL_SET_DIMENSIONS:
1087
0
                {
1088
0
                    codec_t *ps_codec = (codec_t *) (ps_handle->pv_codec_handle);
1089
1090
0
                    ih264e_ctl_set_dimensions_ip_t *ps_ip = pv_api_ip;
1091
0
                    ih264e_ctl_set_dimensions_op_t *ps_op = pv_api_op;
1092
1093
0
                    if (ps_ip->s_ive_ip.u4_size
1094
0
                                    != 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
0
                    if (ps_op->s_ive_op.u4_size
1104
0
                                    != 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
0
                    if (ps_ip->s_ive_ip.u4_wd < MIN_WD)
1114
0
                    {
1115
0
                        ps_op->s_ive_op.u4_error_code |= 1
1116
0
                                        << IVE_UNSUPPORTEDPARAM;
1117
0
                        ps_op->s_ive_op.u4_error_code |=
1118
0
                                        IH264E_WIDTH_NOT_SUPPORTED;
1119
0
                        return (IV_FAIL);
1120
0
                    }
1121
1122
0
                    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
0
                    if (ps_ip->s_ive_ip.u4_ht < MIN_HT)
1132
0
                    {
1133
0
                        ps_op->s_ive_op.u4_error_code |= 1
1134
0
                                        << IVE_UNSUPPORTEDPARAM;
1135
0
                        ps_op->s_ive_op.u4_error_code |=
1136
0
                                        IH264E_HEIGHT_NOT_SUPPORTED;
1137
0
                        return (IV_FAIL);
1138
0
                    }
1139
1140
0
                    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
0
                    if(ps_ip->s_ive_ip.u4_wd & 1)
1150
0
                    {
1151
0
                        ps_op->s_ive_op.u4_error_code |= 1
1152
0
                                        << IVE_UNSUPPORTEDPARAM;
1153
0
                        ps_op->s_ive_op.u4_error_code |=
1154
0
                                        IH264E_WIDTH_NOT_SUPPORTED;
1155
0
                        return (IV_FAIL);
1156
0
                    }
1157
1158
0
                    if(ps_ip->s_ive_ip.u4_ht & 1)
1159
0
                    {
1160
0
                        ps_op->s_ive_op.u4_error_code |= 1
1161
0
                                        << IVE_UNSUPPORTEDPARAM;
1162
0
                        ps_op->s_ive_op.u4_error_code |=
1163
0
                                        IH264E_HEIGHT_NOT_SUPPORTED;
1164
0
                        return (IV_FAIL);
1165
0
                    }
1166
1167
0
                    break;
1168
0
                }
1169
1170
0
                case IVE_CMD_CTL_SET_FRAMERATE:
1171
0
                {
1172
0
                    ih264e_ctl_set_frame_rate_ip_t *ps_ip = pv_api_ip;
1173
0
                    ih264e_ctl_set_frame_rate_op_t *ps_op = pv_api_op;
1174
1175
0
                    if (ps_ip->s_ive_ip.u4_size
1176
0
                                    != 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
0
                    if (ps_op->s_ive_op.u4_size
1186
0
                                    != 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
0
                    if (((ps_ip->s_ive_ip.u4_src_frame_rate * 1000) > DEFAULT_MAX_FRAMERATE)
1196
0
                                    || ((ps_ip->s_ive_ip.u4_tgt_frame_rate * 1000) > DEFAULT_MAX_FRAMERATE))
1197
0
                    {
1198
0
                        ps_op->s_ive_op.u4_error_code |= 1
1199
0
                                        << IVE_UNSUPPORTEDPARAM;
1200
0
                        ps_op->s_ive_op.u4_error_code |=
1201
0
                                        IH264E_FRAME_RATE_NOT_SUPPORTED;
1202
0
                        return (IV_FAIL);
1203
0
                    }
1204
1205
0
                    if ((ps_ip->s_ive_ip.u4_src_frame_rate == 0)
1206
0
                                    || (ps_ip->s_ive_ip.u4_tgt_frame_rate == 0))
1207
0
                    {
1208
0
                        ps_op->s_ive_op.u4_error_code |= 1
1209
0
                                        << IVE_UNSUPPORTEDPARAM;
1210
0
                        ps_op->s_ive_op.u4_error_code |=
1211
0
                                        IH264E_FRAME_RATE_NOT_SUPPORTED;
1212
0
                        return (IV_FAIL);
1213
0
                    }
1214
1215
0
                    if (ps_ip->s_ive_ip.u4_tgt_frame_rate
1216
0
                                    > 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
0
                    break;
1226
0
                }
1227
1228
0
                case IVE_CMD_CTL_SET_BITRATE:
1229
0
                {
1230
0
                    ih264e_ctl_set_bitrate_ip_t *ps_ip = pv_api_ip;
1231
0
                    ih264e_ctl_set_bitrate_op_t *ps_op = pv_api_op;
1232
1233
0
                    if (ps_ip->s_ive_ip.u4_size
1234
0
                                    != 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
0
                    if (ps_op->s_ive_op.u4_size
1244
0
                                    != 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
0
                    if ((ps_ip->s_ive_ip.u4_target_bitrate > DEFAULT_MAX_BITRATE)
1254
0
                                    || (ps_ip->s_ive_ip.u4_target_bitrate == 0))
1255
0
                    {
1256
0
                        ps_op->s_ive_op.u4_error_code |= 1
1257
0
                                        << IVE_UNSUPPORTEDPARAM;
1258
0
                        ps_op->s_ive_op.u4_error_code |=
1259
0
                                        IH264E_BITRATE_NOT_SUPPORTED;
1260
0
                        return (IV_FAIL);
1261
0
                    }
1262
1263
0
                    break;
1264
0
                }
1265
1266
0
                case IVE_CMD_CTL_SET_FRAMETYPE:
1267
0
                {
1268
0
                    ih264e_ctl_set_frame_type_ip_t *ps_ip = pv_api_ip;
1269
0
                    ih264e_ctl_set_frame_type_op_t *ps_op = pv_api_op;
1270
1271
0
                    if (ps_ip->s_ive_ip.u4_size
1272
0
                                    != 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
0
                    if (ps_op->s_ive_op.u4_size
1282
0
                                    != 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
0
                    if ((ps_ip->s_ive_ip.e_frame_type != IV_NA_FRAME)
1292
0
                                    && (ps_ip->s_ive_ip.e_frame_type != IV_I_FRAME)
1293
0
                                    && (ps_ip->s_ive_ip.e_frame_type != IV_P_FRAME)
1294
0
                                    && (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
0
                    break;
1303
0
                }
1304
1305
0
                case IVE_CMD_CTL_SET_ME_PARAMS:
1306
0
                {
1307
0
                    codec_t *ps_codec = (codec_t *) (ps_handle->pv_codec_handle);
1308
1309
0
                    ih264e_ctl_set_me_params_ip_t *ps_ip = pv_api_ip;
1310
0
                    ih264e_ctl_set_me_params_op_t *ps_op = pv_api_op;
1311
1312
0
                    if (ps_ip->s_ive_ip.u4_size
1313
0
                                    != 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
0
                    if (ps_op->s_ive_op.u4_size
1323
0
                                    != 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
0
                    if (ps_ip->s_ive_ip.u4_me_speed_preset != DMND_SRCH)
1333
0
                    {
1334
0
                        ps_op->s_ive_op.u4_error_code |= 1
1335
0
                                        << IVE_UNSUPPORTEDPARAM;
1336
0
                        ps_op->s_ive_op.u4_error_code |=
1337
0
                                        IH264E_INVALID_ME_SPEED_PRESET;
1338
0
                        return IV_FAIL;
1339
0
                    }
1340
1341
0
                    if ((ps_ip->s_ive_ip.u4_enable_hpel != 0)
1342
0
                                    && (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
0
                    if ((ps_ip->s_ive_ip.u4_enable_qpel != 0)
1352
0
                                    && (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
0
                    if ((ps_ip->s_ive_ip.u4_enable_fast_sad != 0)
1362
0
                                    && (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
0
                    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
0
                    if (ps_ip->s_ive_ip.u4_srch_rng_x
1381
0
                                    > 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
0
                    if (ps_ip->s_ive_ip.u4_srch_rng_y
1391
0
                                    > 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
0
                    break;
1401
0
                }
1402
1403
0
                case IVE_CMD_CTL_SET_IPE_PARAMS:
1404
0
                {
1405
0
                    ih264e_ctl_set_ipe_params_ip_t *ps_ip = pv_api_ip;
1406
0
                    ih264e_ctl_set_ipe_params_op_t *ps_op = pv_api_op;
1407
1408
0
                    if (ps_ip->s_ive_ip.u4_size
1409
0
                                    != 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
0
                    if (ps_op->s_ive_op.u4_size
1419
0
                                    != 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
0
                    if ((ps_ip->s_ive_ip.u4_enable_intra_4x4 != 0)
1429
0
                                    && (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
0
                    if ((ps_ip->s_ive_ip.u4_constrained_intra_pred != 0)
1439
0
                                    && (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
0
                    if ((ps_ip->s_ive_ip.u4_enc_speed_preset != IVE_CONFIG)
1449
0
                                    && (ps_ip->s_ive_ip.u4_enc_speed_preset != IVE_SLOWEST)
1450
0
                                    && (ps_ip->s_ive_ip.u4_enc_speed_preset != IVE_NORMAL)
1451
0
                                    && (ps_ip->s_ive_ip.u4_enc_speed_preset != IVE_FAST)
1452
0
                                    && (ps_ip->s_ive_ip.u4_enc_speed_preset != IVE_HIGH_SPEED)
1453
0
                                    && (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
0
                    break;
1463
0
                }
1464
1465
0
                case IVE_CMD_CTL_SET_GOP_PARAMS:
1466
0
                {
1467
0
                    ih264e_ctl_set_gop_params_ip_t *ps_ip = pv_api_ip;
1468
0
                    ih264e_ctl_set_gop_params_op_t *ps_op = pv_api_op;
1469
1470
0
                    if (ps_ip->s_ive_ip.u4_size
1471
0
                                    != 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
0
                    if (ps_op->s_ive_op.u4_size
1481
0
                                    != 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
0
                    if ((ps_ip->s_ive_ip.u4_i_frm_interval < DEFAULT_MIN_INTRA_FRAME_RATE)
1491
0
                                    || (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
0
                    if ((ps_ip->s_ive_ip.u4_idr_frm_interval < DEFAULT_MIN_INTRA_FRAME_RATE)
1501
0
                                    || (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
0
                    if((ps_ip->s_ive_ip.u4_idr_frm_interval > ps_ip->s_ive_ip.u4_i_frm_interval) &&
1511
0
                                    (ps_ip->s_ive_ip.u4_idr_frm_interval % ps_ip->s_ive_ip.u4_i_frm_interval != 0))
1512
0
                    {
1513
0
                        ps_op->s_ive_op.u4_error_code |= 1
1514
0
                                        << IVE_UNSUPPORTEDPARAM;
1515
0
                        ps_op->s_ive_op.u4_error_code |=
1516
0
                                        IH264E_INVALID_INTRA_FRAME_INTERVAL;
1517
0
                        return IV_FAIL;
1518
0
                    }
1519
1520
0
                    break;
1521
0
                }
1522
1523
0
                case IVE_CMD_CTL_SET_DEBLOCK_PARAMS:
1524
0
                {
1525
0
                    ih264e_ctl_set_deblock_params_ip_t *ps_ip = pv_api_ip;
1526
0
                    ih264e_ctl_set_deblock_params_op_t *ps_op = pv_api_op;
1527
1528
0
                    if (ps_ip->s_ive_ip.u4_size
1529
0
                                    != 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
0
                    if (ps_op->s_ive_op.u4_size
1539
0
                                    != 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
0
                    if ((ps_ip->s_ive_ip.u4_disable_deblock_level != DISABLE_DEBLK_LEVEL_0)
1549
0
                                    && (ps_ip->s_ive_ip.u4_disable_deblock_level != DISABLE_DEBLK_LEVEL_2)
1550
0
                                    && (ps_ip->s_ive_ip.u4_disable_deblock_level != DISABLE_DEBLK_LEVEL_3)
1551
0
                                    && (ps_ip->s_ive_ip.u4_disable_deblock_level != DISABLE_DEBLK_LEVEL_4))
1552
0
                    {
1553
0
                        ps_op->s_ive_op.u4_error_code |= 1
1554
0
                                        << IVE_UNSUPPORTEDPARAM;
1555
0
                        ps_op->s_ive_op.u4_error_code |=
1556
0
                                        IH264E_INVALID_DEBLOCKING_TYPE_INPUT;
1557
0
                        return IV_FAIL;
1558
0
                    }
1559
1560
0
                    break;
1561
0
                }
1562
1563
0
                case IVE_CMD_CTL_SET_QP:
1564
0
                {
1565
0
                    ih264e_ctl_set_qp_ip_t *ps_ip = pv_api_ip;
1566
0
                    ih264e_ctl_set_qp_op_t *ps_op = pv_api_op;
1567
1568
0
                    if (ps_ip->s_ive_ip.u4_size
1569
0
                                    != 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
0
                    if (ps_op->s_ive_op.u4_size
1579
0
                                    != 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
0
                    if ((ps_ip->s_ive_ip.u4_i_qp_max > MAX_H264_QP)
1589
0
                                    || (ps_ip->s_ive_ip.u4_p_qp_max > MAX_H264_QP)
1590
0
                                    || (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
0
                    if ((ps_ip->s_ive_ip.u4_i_qp_min < 4)
1601
0
                                    || (ps_ip->s_ive_ip.u4_p_qp_min < 4)
1602
0
                                    || (ps_ip->s_ive_ip.u4_b_qp_min < 4)
1603
0
                                    || (ps_ip->s_ive_ip.u4_i_qp_min > ps_ip->s_ive_ip.u4_i_qp_max)
1604
0
                                    || (ps_ip->s_ive_ip.u4_p_qp_min > ps_ip->s_ive_ip.u4_p_qp_max)
1605
0
                                    || (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
0
                    if ((ps_ip->s_ive_ip.u4_i_qp > ps_ip->s_ive_ip.u4_i_qp_max)
1615
0
                                    || (ps_ip->s_ive_ip.u4_p_qp > ps_ip->s_ive_ip.u4_p_qp_max)
1616
0
                                    || (ps_ip->s_ive_ip.u4_b_qp > ps_ip->s_ive_ip.u4_b_qp_max)
1617
0
                                    || (ps_ip->s_ive_ip.u4_i_qp < ps_ip->s_ive_ip.u4_i_qp_min)
1618
0
                                    || (ps_ip->s_ive_ip.u4_p_qp < ps_ip->s_ive_ip.u4_p_qp_min)
1619
0
                                    || (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
0
                    break;
1628
0
                }
1629
1630
0
                case IVE_CMD_CTL_SET_VUI_PARAMS:
1631
0
                {
1632
0
                    ih264e_vui_ip_t *ps_ip = pv_api_ip;
1633
0
                    ih264e_vui_op_t *ps_op = pv_api_op;
1634
1635
0
                    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
0
                    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
0
                    break;
1652
0
                }
1653
1654
0
                case IVE_CMD_CTL_SET_SEI_MDCV_PARAMS:
1655
0
                {
1656
0
                    ih264e_ctl_set_sei_mdcv_params_ip_t *ps_ip = pv_api_ip;
1657
0
                    ih264e_ctl_set_sei_mdcv_params_op_t *ps_op = pv_api_op;
1658
1659
0
                    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
0
                    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
0
                    if((ps_ip->u1_sei_mdcv_params_present_flag != 0)
1676
0
                            && (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
0
                    if(1 == ps_ip->u1_sei_mdcv_params_present_flag)
1685
0
                    {
1686
                        /* Check values for u2_display_primaries_x and u2_display_primaries_y */
1687
0
                        for(i = 0; i < 3; i++)
1688
0
                        {
1689
0
                            if((ps_ip->au2_display_primaries_x[i] >
1690
0
                                                    DISPLAY_PRIMARIES_X_UPPER_LIMIT) ||
1691
0
                               (ps_ip->au2_display_primaries_x[i] <
1692
0
                                                    DISPLAY_PRIMARIES_X_LOWER_LIMIT) ||
1693
0
                               ((ps_ip->au2_display_primaries_x[i] %
1694
0
                                                    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
0
                            if((ps_ip->au2_display_primaries_y[i] >
1703
0
                                                    DISPLAY_PRIMARIES_Y_UPPER_LIMIT) ||
1704
0
                               (ps_ip->au2_display_primaries_y[i] <
1705
0
                                                    DISPLAY_PRIMARIES_Y_LOWER_LIMIT) ||
1706
0
                               ((ps_ip->au2_display_primaries_y[i] %
1707
0
                                                    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
0
                        }
1715
1716
0
                        if((ps_ip->u2_white_point_x > WHITE_POINT_X_UPPER_LIMIT) ||
1717
0
                           (ps_ip->u2_white_point_x < WHITE_POINT_X_LOWER_LIMIT) ||
1718
0
                           ((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
0
                        if((ps_ip->u2_white_point_y > WHITE_POINT_Y_UPPER_LIMIT) ||
1727
0
                           (ps_ip->u2_white_point_y < WHITE_POINT_Y_LOWER_LIMIT) ||
1728
0
                           ((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
0
                        if((ps_ip->u4_max_display_mastering_luminance >
1737
0
                                        MAX_DISPLAY_MASTERING_LUMINANCE_UPPER_LIMIT) ||
1738
0
                           (ps_ip->u4_max_display_mastering_luminance <
1739
0
                                        MAX_DISPLAY_MASTERING_LUMINANCE_LOWER_LIMIT) ||
1740
0
                           ((ps_ip->u4_max_display_mastering_luminance %
1741
0
                                        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
0
                        if((ps_ip->u4_min_display_mastering_luminance >
1750
0
                                        MIN_DISPLAY_MASTERING_LUMINANCE_UPPER_LIMIT ) ||
1751
0
                           (ps_ip->u4_min_display_mastering_luminance <
1752
0
                                        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
0
                        if(ps_ip->u4_max_display_mastering_luminance <=
1761
0
                                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
0
                    }
1769
0
                    break;
1770
0
                }
1771
1772
0
                case IVE_CMD_CTL_SET_SEI_CLL_PARAMS:
1773
0
                {
1774
0
                    ih264e_ctl_set_sei_cll_params_ip_t *ps_ip = pv_api_ip;
1775
0
                    ih264e_ctl_set_sei_cll_params_op_t *ps_op = pv_api_op;
1776
1777
0
                    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
0
                    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
0
                    if((ps_ip->u1_sei_cll_params_present_flag != 0)
1794
0
                            && (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
0
                    break;
1802
0
                }
1803
1804
0
                case IVE_CMD_CTL_SET_SEI_AVE_PARAMS:
1805
0
                {
1806
0
                    ih264e_ctl_set_sei_ave_params_ip_t *ps_ip = pv_api_ip;
1807
0
                    ih264e_ctl_set_sei_ave_params_op_t *ps_op = pv_api_op;
1808
1809
0
                    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
0
                    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
0
                    if((ps_ip->u1_sei_ave_params_present_flag != 0)
1826
0
                            && (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
0
                    if(1 == ps_ip->u1_sei_ave_params_present_flag)
1835
0
                    {
1836
0
                        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
0
                        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
0
                        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
0
                    }
1860
0
                    break;
1861
0
                }
1862
1863
0
                case IVE_CMD_CTL_SET_SEI_CCV_PARAMS:
1864
0
                {
1865
0
                    ih264e_ctl_set_sei_ccv_params_ip_t *ps_ip = pv_api_ip;
1866
0
                    ih264e_ctl_set_sei_ccv_params_op_t *ps_op = pv_api_op;
1867
1868
0
                    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
0
                    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
0
                    if((ps_ip->u1_sei_ccv_params_present_flag != 0)
1885
0
                            && (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
0
                    if(1 == ps_ip->u1_sei_ccv_params_present_flag)
1895
0
                    {
1896
0
                        if((ps_ip->u1_ccv_cancel_flag != 0)
1897
0
                                && (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
0
                        if(0 == ps_ip->u1_ccv_cancel_flag)
1906
0
                        {
1907
0
                            if((ps_ip->u1_ccv_persistence_flag != 0)
1908
0
                                    && (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
0
                            if((ps_ip->u1_ccv_primaries_present_flag != 0)
1916
0
                                    && (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
0
                            if((ps_ip->u1_ccv_min_luminance_value_present_flag != 0)
1924
0
                                    && (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
0
                            if((ps_ip->u1_ccv_max_luminance_value_present_flag != 0)
1932
0
                                    && (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
0
                            if((ps_ip->u1_ccv_avg_luminance_value_present_flag != 0)
1940
0
                                    && (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
0
                            if((ps_ip->u1_ccv_primaries_present_flag == 0)
1948
0
                                    && (ps_ip->u1_ccv_min_luminance_value_present_flag == 0)
1949
0
                                    && (ps_ip->u1_ccv_max_luminance_value_present_flag == 0)
1950
0
                                    && (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
0
                            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
0
                            if(1 == ps_ip->u1_ccv_primaries_present_flag)
1967
0
                            {
1968
0
                                for(i = 0; i < 3; i++)
1969
0
                                {
1970
0
                                    if((ps_ip->ai4_ccv_primaries_x[i] >
1971
0
                                                        CCV_PRIMARIES_X_UPPER_LIMIT) ||
1972
0
                                       (ps_ip->ai4_ccv_primaries_x[i] <
1973
0
                                                        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
0
                                    if((ps_ip->ai4_ccv_primaries_y[i] >
1982
0
                                                        CCV_PRIMARIES_Y_UPPER_LIMIT) ||
1983
0
                                       (ps_ip->ai4_ccv_primaries_y[i] <
1984
0
                                                        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
0
                                }
1992
0
                            }
1993
1994
0
                            if((1 == ps_ip->u1_ccv_min_luminance_value_present_flag) &&
1995
0
                                    (1 == ps_ip->u1_ccv_avg_luminance_value_present_flag))
1996
0
                            {
1997
0
                                if((ps_ip->u4_ccv_avg_luminance_value <
1998
0
                                                    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
0
                            }
2006
2007
0
                            if((1 == ps_ip->u1_ccv_min_luminance_value_present_flag) &&
2008
0
                                    (1 == ps_ip->u1_ccv_max_luminance_value_present_flag))
2009
0
                            {
2010
0
                                if((ps_ip->u4_ccv_max_luminance_value <
2011
0
                                                    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
0
                            }
2019
0
                            if((1 == ps_ip->u1_ccv_avg_luminance_value_present_flag) &&
2020
0
                                    (1 == ps_ip->u1_ccv_max_luminance_value_present_flag))
2021
0
                            {
2022
0
                                if((ps_ip->u4_ccv_max_luminance_value <
2023
0
                                                    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
0
                            }
2031
0
                        }
2032
0
                    }
2033
0
                    break;
2034
0
                }
2035
2036
0
                case IVE_CMD_CTL_SET_SEI_SII_PARAMS:
2037
0
                {
2038
0
                    ih264e_ctl_set_sei_sii_params_ip_t *ps_ip = pv_api_ip;
2039
0
                    ih264e_ctl_set_sei_sii_params_op_t *ps_op = pv_api_op;
2040
2041
0
                    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
0
                    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
0
                    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
0
                    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
0
                    if((ps_ip->u4_sii_sub_layer_idx > 0) &&
2071
0
                       (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
0
                    if((ps_ip->u4_sii_sub_layer_idx > ps_ip->u1_sii_max_sub_layers_minus1) &&
2079
0
                       (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
0
                    break;
2087
0
                }
2088
2089
0
                case IVE_CMD_CTL_SET_ENC_MODE:
2090
0
                {
2091
0
                    ih264e_ctl_set_enc_mode_ip_t *ps_ip = pv_api_ip;
2092
0
                    ih264e_ctl_set_enc_mode_op_t *ps_op = pv_api_op;
2093
2094
0
                    if (ps_ip->s_ive_ip.u4_size
2095
0
                                    != 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
0
                    if (ps_op->s_ive_op.u4_size
2105
0
                                    != 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
0
                    if ((ps_ip->s_ive_ip.e_enc_mode != IVE_ENC_MODE_HEADER)
2115
0
                                    && (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
0
                    break;
2125
0
                }
2126
2127
0
                case IVE_CMD_CTL_SET_VBV_PARAMS:
2128
0
                {
2129
0
                    ih264e_ctl_set_vbv_params_ip_t *ps_ip = pv_api_ip;
2130
0
                    ih264e_ctl_set_vbv_params_op_t *ps_op = pv_api_op;
2131
2132
0
                    if (ps_ip->s_ive_ip.u4_size
2133
0
                                    != 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
0
                    if (ps_op->s_ive_op.u4_size
2143
0
                                    != 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
0
                    if ((ps_ip->s_ive_ip.u4_vbv_buffer_delay < DEFAULT_MIN_BUFFER_DELAY)
2153
0
                                    || (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
0
                    break;
2163
0
                }
2164
2165
0
                case IVE_CMD_CTL_SET_AIR_PARAMS:
2166
0
                {
2167
0
                    ih264e_ctl_set_air_params_ip_t *ps_ip = pv_api_ip;
2168
0
                    ih264e_ctl_set_air_params_op_t *ps_op = pv_api_op;
2169
2170
0
                    if (ps_ip->s_ive_ip.u4_size
2171
0
                                    != 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
0
                    if (ps_op->s_ive_op.u4_size
2181
0
                                    != 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
0
                    if ((ps_ip->s_ive_ip.e_air_mode != IVE_AIR_MODE_NONE)
2191
0
                                    && (ps_ip->s_ive_ip.e_air_mode != IVE_AIR_MODE_CYCLIC)
2192
0
                                    && (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
0
                    if (ps_ip->s_ive_ip.e_air_mode != IVE_AIR_MODE_NONE &&
2202
0
                        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
0
                    break;
2212
0
                }
2213
2214
0
                case IVE_CMD_CTL_SET_PROFILE_PARAMS:
2215
0
                {
2216
0
                    ih264e_ctl_set_profile_params_ip_t *ps_ip = pv_api_ip;
2217
0
                    ih264e_ctl_set_profile_params_op_t *ps_op = pv_api_op;
2218
2219
0
                    if (ps_ip->s_ive_ip.u4_size
2220
0
                                    != 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
0
                    if (ps_op->s_ive_op.u4_size
2230
0
                                    != 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
0
                    if (ps_ip->s_ive_ip.e_profile != IV_PROFILE_BASE &&
2240
0
                        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
0
                    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
0
                    break;
2259
0
                }
2260
2261
0
                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
0
            }
2266
2267
0
            break;
2268
0
        }
2269
2270
0
        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
0
    }
2275
2276
0
    return IV_SUCCESS;
2277
0
}
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
0
{
2301
    /* config params */
2302
0
    cfg_params_t *ps_curr_cfg = &ps_codec->s_cfg;
2303
2304
    /* error status */
2305
0
    IH264E_ERROR_T err = IH264E_SUCCESS;
2306
2307
    /* temp var */
2308
0
    UWORD32 u4_init_rc = 0;
2309
2310
    /***********************/
2311
    /* UPDATE CODEC CONFIG */
2312
    /***********************/
2313
0
    if (ps_cfg->e_cmd == IVE_CMD_CTL_SET_DIMENSIONS)
2314
0
    {
2315
0
        UWORD32 wd_aln = ALIGN16(ps_cfg->u4_wd);
2316
0
        UWORD32 ht_aln = ALIGN16(ps_cfg->u4_ht);
2317
2318
0
        if (ps_curr_cfg->u4_wd != wd_aln || ps_curr_cfg->u4_ht != ht_aln
2319
0
                        || ps_curr_cfg->u4_disp_wd != ps_cfg->u4_disp_wd
2320
0
                        || ps_curr_cfg->u4_disp_ht != ps_cfg->u4_disp_ht)
2321
0
        {
2322
0
            ps_curr_cfg->u4_wd = wd_aln;
2323
0
            ps_curr_cfg->u4_ht = ht_aln;
2324
2325
0
            ps_curr_cfg->u4_disp_wd = ps_cfg->u4_disp_wd;
2326
0
            ps_curr_cfg->u4_disp_ht = ps_cfg->u4_disp_ht;
2327
2328
0
            ps_curr_cfg->i4_wd_mbs = ps_curr_cfg->u4_wd >> 4;
2329
0
            ps_curr_cfg->i4_ht_mbs = ps_curr_cfg->u4_ht >> 4;
2330
2331
0
            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
0
            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
0
            err = ih264e_mv_buf_mgr_add_bufs(ps_codec);
2346
0
            if (err != IH264E_SUCCESS)
2347
0
                return err;
2348
2349
            /* initialize ref bank buffer manager */
2350
0
            err = ih264e_pic_buf_mgr_add_bufs(ps_codec);
2351
0
            if (err != IH264E_SUCCESS)
2352
0
                return err;
2353
2354
            /* since dimension changed, start new sequence by forcing IDR */
2355
0
            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
0
            u4_init_rc = 1;
2360
2361
            /* when the dimension changes, the header needs to be regenerated */
2362
0
            ps_codec->i4_gen_header = 1;
2363
0
        }
2364
0
    }
2365
0
    else if (ps_cfg->e_cmd == IVE_CMD_CTL_SET_FRAMERATE)
2366
0
    {
2367
        /* temp var */
2368
0
        UWORD32 u4_src_ticks, u4_tgt_ticks;
2369
2370
0
        u4_src_ticks = ih264e_frame_time_get_src_ticks(
2371
0
                        ps_codec->s_rate_control.pps_frame_time);
2372
2373
0
        u4_tgt_ticks = ih264e_frame_time_get_tgt_ticks(
2374
0
                        ps_codec->s_rate_control.pps_frame_time);
2375
2376
        /* Change frame rate */
2377
0
        if (ps_codec->s_cfg.u4_src_frame_rate
2378
0
                        != ps_cfg->u4_src_frame_rate * 1000)
2379
0
        {
2380
0
            ps_codec->s_cfg.u4_src_frame_rate = ps_cfg->u4_src_frame_rate
2381
0
                            * 1000;
2382
2383
0
            ih264e_frame_time_update_src_frame_rate(
2384
0
                            ps_codec->s_rate_control.pps_frame_time,
2385
0
                            ps_codec->s_cfg.u4_src_frame_rate);
2386
2387
0
            ih264_time_stamp_update_frame_rate(
2388
0
                            ps_codec->s_rate_control.pps_time_stamp,
2389
0
                            ps_codec->s_cfg.u4_src_frame_rate);
2390
2391
0
            irc_change_frame_rate(ps_codec->s_rate_control.pps_rate_control_api,
2392
0
                                  ps_codec->s_cfg.u4_src_frame_rate,
2393
0
                                  u4_src_ticks, u4_tgt_ticks);
2394
0
        }
2395
2396
0
        if (ps_codec->s_cfg.u4_tgt_frame_rate
2397
0
                        != ps_cfg->u4_tgt_frame_rate * 1000)
2398
0
        {
2399
0
            ps_codec->s_cfg.u4_tgt_frame_rate = ps_cfg->u4_tgt_frame_rate
2400
0
                            * 1000;
2401
2402
0
            ih264e_frame_time_update_tgt_frame_rate(
2403
0
                            ps_codec->s_rate_control.pps_frame_time,
2404
0
                            ps_codec->s_cfg.u4_tgt_frame_rate);
2405
2406
0
            irc_change_frame_rate(ps_codec->s_rate_control.pps_rate_control_api,
2407
0
                                  ps_codec->s_cfg.u4_src_frame_rate,
2408
0
                                  u4_src_ticks, u4_tgt_ticks);
2409
2410
0
            irc_change_frm_rate_for_bit_alloc(
2411
0
                            ps_codec->s_rate_control.pps_rate_control_api,
2412
0
                            ps_codec->s_cfg.u4_tgt_frame_rate);
2413
0
        }
2414
2415
0
    }
2416
0
    else if (ps_cfg->e_cmd == IVE_CMD_CTL_SET_BITRATE)
2417
0
    {
2418
0
        if (ps_curr_cfg->u4_target_bitrate != ps_cfg->u4_target_bitrate)
2419
0
        {
2420
0
            if (IVE_RC_NONE != ps_curr_cfg->e_rc_mode)
2421
0
                irc_change_avg_bit_rate(
2422
0
                                ps_codec->s_rate_control.pps_rate_control_api,
2423
0
                                ps_cfg->u4_target_bitrate);
2424
2425
0
            ps_curr_cfg->u4_target_bitrate = ps_cfg->u4_target_bitrate;
2426
0
        }
2427
0
    }
2428
0
    else if (ps_cfg->e_cmd == IVE_CMD_CTL_SET_FRAMETYPE)
2429
0
    {
2430
0
        switch (ps_cfg->e_frame_type)
2431
0
        {
2432
0
            case IV_I_FRAME:
2433
0
                ps_codec->force_curr_frame_type = IV_I_FRAME;
2434
0
                break;
2435
2436
0
            case IV_IDR_FRAME:
2437
0
                ps_codec->force_curr_frame_type = IV_IDR_FRAME;
2438
0
                break;
2439
2440
0
            case IV_P_FRAME:
2441
0
            default:
2442
0
                break;
2443
0
        }
2444
0
    }
2445
0
    else if (ps_cfg->e_cmd == IVE_CMD_CTL_SET_ME_PARAMS)
2446
0
    {
2447
0
        if (ps_curr_cfg->u4_enc_speed_preset == IVE_CONFIG)
2448
0
        {
2449
0
            ps_codec->s_cfg.u4_enable_hpel = ps_cfg->u4_enable_hpel;
2450
0
            ps_codec->s_cfg.u4_enable_fast_sad = ps_cfg->u4_enable_fast_sad;
2451
0
            ps_codec->s_cfg.u4_me_speed_preset = ps_cfg->u4_me_speed_preset;
2452
0
            ps_codec->s_cfg.u4_enable_qpel = ps_cfg->u4_enable_qpel;
2453
0
        }
2454
0
        else if (ps_curr_cfg->u4_enc_speed_preset == IVE_FASTEST)
2455
0
        {
2456
0
            ps_codec->s_cfg.u4_enable_fast_sad = ps_cfg->u4_enable_fast_sad;
2457
0
        }
2458
0
        ps_codec->s_cfg.u4_srch_rng_x = ps_cfg->u4_srch_rng_x;
2459
0
        ps_codec->s_cfg.u4_srch_rng_y = ps_cfg->u4_srch_rng_y;
2460
2461
0
        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
0
    }
2467
0
    else if (ps_cfg->e_cmd == IVE_CMD_CTL_SET_IPE_PARAMS)
2468
0
    {
2469
0
        ps_curr_cfg->u4_enc_speed_preset = ps_cfg->u4_enc_speed_preset;
2470
2471
0
        ps_curr_cfg->u4_constrained_intra_pred = ps_cfg->u4_constrained_intra_pred;
2472
2473
0
        if (ps_curr_cfg->u4_enc_speed_preset != IVE_CONFIG)
2474
0
        {
2475
0
            ih264e_speed_preset_side_effects(ps_codec);
2476
0
        }
2477
0
        else
2478
0
        {
2479
0
            ps_curr_cfg->u4_enable_intra_4x4 = ps_cfg->u4_enable_intra_4x4;
2480
0
        }
2481
0
    }
2482
0
    else if (ps_cfg->e_cmd == IVE_CMD_CTL_SET_GOP_PARAMS)
2483
0
    {
2484
0
        if (ps_curr_cfg->u4_i_frm_interval != ps_cfg->u4_i_frm_interval)
2485
0
        {
2486
0
            ps_curr_cfg->u4_i_frm_interval = ps_cfg->u4_i_frm_interval;
2487
2488
            /* reset air counter */
2489
0
            ps_codec->i4_air_pic_cnt = -1;
2490
2491
            /* re-init air map */
2492
0
            ih264e_init_air_map(ps_codec);
2493
2494
            /* Effect intra frame interval change */
2495
0
            irc_change_intra_frm_int_call(
2496
0
                            ps_codec->s_rate_control.pps_rate_control_api,
2497
0
                            ps_curr_cfg->u4_i_frm_interval);
2498
0
        }
2499
2500
0
        ps_curr_cfg->u4_idr_frm_interval = ps_cfg->u4_idr_frm_interval;
2501
2502
0
    }
2503
0
    else if (ps_cfg->e_cmd == IVE_CMD_CTL_SET_DEBLOCK_PARAMS)
2504
0
    {
2505
0
        if (ps_curr_cfg->u4_enc_speed_preset == IVE_CONFIG)
2506
0
        {
2507
0
            ps_curr_cfg->u4_disable_deblock_level =
2508
0
                            ps_cfg->u4_disable_deblock_level;
2509
0
        }
2510
0
    }
2511
0
    else if (ps_cfg->e_cmd == IVE_CMD_CTL_SET_QP)
2512
0
    {
2513
0
        UWORD8 au1_init_qp[MAX_PIC_TYPE];
2514
0
        UWORD8 au1_min_max_qp[2 * MAX_PIC_TYPE];
2515
2516
0
        ps_codec->s_cfg.u4_i_qp_max = ps_cfg->u4_i_qp_max;
2517
0
        ps_codec->s_cfg.u4_i_qp_min = ps_cfg->u4_i_qp_min;
2518
0
        ps_codec->s_cfg.u4_i_qp = ps_cfg->u4_i_qp;
2519
2520
0
        ps_codec->s_cfg.u4_p_qp_max = ps_cfg->u4_p_qp_max;
2521
0
        ps_codec->s_cfg.u4_p_qp_min = ps_cfg->u4_p_qp_min;
2522
0
        ps_codec->s_cfg.u4_p_qp = ps_cfg->u4_p_qp;
2523
2524
0
        ps_codec->s_cfg.u4_b_qp_max = ps_cfg->u4_b_qp_max;
2525
0
        ps_codec->s_cfg.u4_b_qp_min = ps_cfg->u4_b_qp_min;
2526
0
        ps_codec->s_cfg.u4_b_qp = ps_cfg->u4_b_qp;
2527
2528
        /* update rc lib with modified qp */
2529
0
        au1_init_qp[0] = gau1_h264_to_mpeg2_qmap[ps_codec->s_cfg.u4_i_qp];
2530
0
        au1_init_qp[1] = gau1_h264_to_mpeg2_qmap[ps_codec->s_cfg.u4_p_qp];
2531
0
        au1_init_qp[2] = gau1_h264_to_mpeg2_qmap[ps_codec->s_cfg.u4_b_qp];
2532
2533
0
        irc_change_init_qp(ps_codec->s_rate_control.pps_rate_control_api,
2534
0
                           au1_init_qp);
2535
2536
0
        au1_min_max_qp[2 * I_PIC] =
2537
0
                        gau1_h264_to_mpeg2_qmap[ps_codec->s_cfg.u4_i_qp_min];
2538
0
        au1_min_max_qp[2 * I_PIC + 1] =
2539
0
                        gau1_h264_to_mpeg2_qmap[ps_codec->s_cfg.u4_i_qp_max];
2540
2541
0
        au1_min_max_qp[2 * P_PIC] =
2542
0
                        gau1_h264_to_mpeg2_qmap[ps_codec->s_cfg.u4_p_qp_min];
2543
0
        au1_min_max_qp[2 * P_PIC + 1] =
2544
0
                        gau1_h264_to_mpeg2_qmap[ps_codec->s_cfg.u4_p_qp_max];
2545
2546
0
        au1_min_max_qp[2 * B_PIC] =
2547
0
                        gau1_h264_to_mpeg2_qmap[ps_codec->s_cfg.u4_b_qp_min];
2548
0
        au1_min_max_qp[2 * B_PIC + 1] =
2549
0
                        gau1_h264_to_mpeg2_qmap[ps_codec->s_cfg.u4_b_qp_max];
2550
2551
0
        irc_change_min_max_qp(ps_codec->s_rate_control.pps_rate_control_api,
2552
0
                              au1_min_max_qp);
2553
0
    }
2554
0
    else if (ps_cfg->e_cmd == IVE_CMD_CTL_SET_ENC_MODE)
2555
0
    {
2556
0
        ps_codec->s_cfg.e_enc_mode = ps_cfg->e_enc_mode;
2557
2558
0
        if (ps_codec->s_cfg.e_enc_mode == IVE_ENC_MODE_HEADER)
2559
0
        {
2560
0
            ps_codec->i4_header_mode = 1;
2561
0
            ps_codec->s_cfg.e_enc_mode = IVE_ENC_MODE_PICTURE;
2562
0
        }
2563
0
        else
2564
0
        {
2565
0
            ps_codec->i4_header_mode = 0;
2566
0
        }
2567
0
    }
2568
0
    else if (ps_cfg->e_cmd == IVE_CMD_CTL_SET_VBV_PARAMS
2569
0
                    && IVE_RC_NONE != ps_codec->s_cfg.e_rc_mode)
2570
0
    {
2571
0
        ps_codec->s_cfg.u4_vbv_buf_size = ps_cfg->u4_vbv_buf_size;
2572
0
        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
0
        u4_init_rc = 1;
2579
0
    }
2580
0
    else if (ps_cfg->e_cmd == IVE_CMD_CTL_SET_AIR_PARAMS)
2581
0
    {
2582
0
        if (ps_curr_cfg->e_air_mode != ps_cfg->e_air_mode
2583
0
                        || ps_curr_cfg->u4_air_refresh_period
2584
0
                                        != ps_cfg->u4_air_refresh_period)
2585
0
        {
2586
0
            ps_curr_cfg->e_air_mode = ps_cfg->e_air_mode;
2587
0
            ps_curr_cfg->u4_air_refresh_period = ps_cfg->u4_air_refresh_period;
2588
2589
0
            ih264e_init_air_map(ps_codec);
2590
2591
            /* reset air counter */
2592
0
            ps_codec->i4_air_pic_cnt = -1;
2593
0
        }
2594
0
    }
2595
0
    else if (ps_cfg->e_cmd == IVE_CMD_CTL_SET_PROFILE_PARAMS)
2596
0
    {
2597
0
        ps_codec->s_cfg.e_profile = ps_cfg->e_profile;
2598
0
        ps_codec->s_cfg.u4_entropy_coding_mode = ps_cfg->u4_entropy_coding_mode;
2599
0
    }
2600
0
    else if (ps_cfg->e_cmd == IVE_CMD_CTL_SET_NUM_CORES)
2601
0
    {
2602
0
        ps_codec->s_cfg.u4_num_cores = ps_cfg->u4_num_cores;
2603
0
    }
2604
0
    else if (ps_cfg->e_cmd == IVE_CMD_CTL_SET_VUI_PARAMS)
2605
0
    {
2606
0
        ps_codec->s_cfg.s_vui = ps_cfg->s_vui;
2607
0
    }
2608
2609
0
    else if (ps_cfg->e_cmd == IVE_CMD_CTL_SET_SEI_MDCV_PARAMS)
2610
0
    {
2611
0
        ps_codec->s_cfg.s_sei.u1_sei_mdcv_params_present_flag =
2612
0
                                                ps_cfg->s_sei.u1_sei_mdcv_params_present_flag;
2613
0
        ps_codec->s_cfg.s_sei.s_sei_mdcv_params = ps_cfg->s_sei.s_sei_mdcv_params;
2614
0
    }
2615
0
    else if (ps_cfg->e_cmd == IVE_CMD_CTL_SET_SEI_CLL_PARAMS)
2616
0
    {
2617
0
        ps_codec->s_cfg.s_sei.u1_sei_cll_params_present_flag =
2618
0
                                                ps_cfg->s_sei.u1_sei_cll_params_present_flag;
2619
0
        ps_codec->s_cfg.s_sei.s_sei_cll_params = ps_cfg->s_sei.s_sei_cll_params;
2620
0
    }
2621
0
    else if (ps_cfg->e_cmd == IVE_CMD_CTL_SET_SEI_AVE_PARAMS)
2622
0
    {
2623
0
        ps_codec->s_cfg.s_sei.u1_sei_ave_params_present_flag =
2624
0
                                                ps_cfg->s_sei.u1_sei_ave_params_present_flag;
2625
0
        ps_codec->s_cfg.s_sei.s_sei_ave_params = ps_cfg->s_sei.s_sei_ave_params;
2626
0
    }
2627
0
    else if (ps_cfg->e_cmd == IVE_CMD_CTL_SET_SEI_CCV_PARAMS)
2628
0
    {
2629
0
        ps_codec->s_cfg.s_sei.u1_sei_ccv_params_present_flag =
2630
0
                                                ps_cfg->s_sei.u1_sei_ccv_params_present_flag;
2631
0
        ps_codec->s_cfg.s_sei.s_sei_ccv_params = ps_cfg->s_sei.s_sei_ccv_params;
2632
0
    }
2633
0
    else if(ps_cfg->e_cmd == IVE_CMD_CTL_SET_SEI_SII_PARAMS)
2634
0
    {
2635
0
        ps_codec->s_cfg.s_sei.u1_sei_sii_params_present_flag =
2636
0
            ps_cfg->s_sei.u1_sei_sii_params_present_flag;
2637
0
        ps_codec->s_cfg.s_sei.s_sei_sii_params = ps_cfg->s_sei.s_sei_sii_params;
2638
0
    }
2639
2640
    /* reset RC model */
2641
0
    if (u4_init_rc)
2642
0
    {
2643
        /* init qp */
2644
0
        UWORD8 au1_init_qp[MAX_PIC_TYPE];
2645
2646
        /* min max qp */
2647
0
        UWORD8 au1_min_max_qp[2 * MAX_PIC_TYPE];
2648
2649
        /* init i,p,b qp */
2650
0
        au1_init_qp[0] = gau1_h264_to_mpeg2_qmap[ps_codec->s_cfg.u4_i_qp];
2651
0
        au1_init_qp[1] = gau1_h264_to_mpeg2_qmap[ps_codec->s_cfg.u4_p_qp];
2652
0
        au1_init_qp[2] = gau1_h264_to_mpeg2_qmap[ps_codec->s_cfg.u4_b_qp];
2653
2654
        /* init min max qp */
2655
0
        au1_min_max_qp[2 * I_PIC] =
2656
0
                        gau1_h264_to_mpeg2_qmap[ps_codec->s_cfg.u4_i_qp_min];
2657
0
        au1_min_max_qp[2 * I_PIC + 1] =
2658
0
                        gau1_h264_to_mpeg2_qmap[ps_codec->s_cfg.u4_i_qp_max];
2659
2660
0
        au1_min_max_qp[2 * P_PIC] =
2661
0
                        gau1_h264_to_mpeg2_qmap[ps_codec->s_cfg.u4_p_qp_min];
2662
0
        au1_min_max_qp[2 * P_PIC + 1] =
2663
0
                        gau1_h264_to_mpeg2_qmap[ps_codec->s_cfg.u4_p_qp_max];
2664
2665
0
        au1_min_max_qp[2 * B_PIC] =
2666
0
                        gau1_h264_to_mpeg2_qmap[ps_codec->s_cfg.u4_b_qp_min];
2667
0
        au1_min_max_qp[2 * B_PIC + 1] =
2668
0
                        gau1_h264_to_mpeg2_qmap[ps_codec->s_cfg.u4_b_qp_max];
2669
2670
        /* get rc mode */
2671
0
        switch (ps_codec->s_cfg.e_rc_mode)
2672
0
        {
2673
0
            case IVE_RC_STORAGE:
2674
0
                ps_codec->s_rate_control.e_rc_type = VBR_STORAGE;
2675
0
                break;
2676
2677
0
            case IVE_RC_CBR_NON_LOW_DELAY:
2678
0
                ps_codec->s_rate_control.e_rc_type = CBR_NLDRC;
2679
0
                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
0
            case IVE_RC_NONE:
2686
0
                ps_codec->s_rate_control.e_rc_type = CONST_QP;
2687
0
                break;
2688
2689
0
            default:
2690
0
                break;
2691
0
        }
2692
2693
        /* init rate control */
2694
0
        ih264e_rc_init(ps_codec->s_rate_control.pps_rate_control_api,
2695
0
                       ps_codec->s_rate_control.pps_frame_time,
2696
0
                       ps_codec->s_rate_control.pps_time_stamp,
2697
0
                       ps_codec->s_rate_control.pps_pd_frm_rate,
2698
0
                       ps_codec->s_cfg.u4_max_framerate,
2699
0
                       ps_codec->s_cfg.u4_src_frame_rate,
2700
0
                       ps_codec->s_cfg.u4_tgt_frame_rate,
2701
0
                       ps_codec->s_rate_control.e_rc_type,
2702
0
                       ps_codec->s_cfg.u4_target_bitrate,
2703
0
                       ps_codec->s_cfg.u4_max_bitrate,
2704
0
                       ps_codec->s_cfg.u4_vbv_buffer_delay,
2705
0
                       ps_codec->s_cfg.u4_i_frm_interval,
2706
0
                       ps_codec->s_cfg.u4_num_bframes + 1, au1_init_qp,
2707
0
                       ps_codec->s_cfg.u4_num_bframes + 2, au1_min_max_qp,
2708
0
                       ps_codec->s_cfg.u4_max_level);
2709
0
    }
2710
2711
0
    return err;
2712
0
}
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
0
{
2735
0
    WORD32 ret = IV_SUCCESS;
2736
2737
0
    ps_cfg->u4_max_wd = MAX_WD;
2738
0
    ps_cfg->u4_max_ht = MAX_HT;
2739
0
    ps_cfg->u4_max_ref_cnt = MAX_REF_CNT;
2740
0
    ps_cfg->u4_max_reorder_cnt = MAX_REF_CNT;
2741
0
    ps_cfg->u4_max_level = DEFAULT_MAX_LEVEL;
2742
0
    ps_cfg->e_inp_color_fmt = IV_YUV_420SP_UV;
2743
0
    ps_cfg->u4_enable_recon = DEFAULT_RECON_ENABLE;
2744
0
    ps_cfg->u4_enable_quality_metrics = DEFAULT_QUALITY_METRICS_ENABLE;
2745
0
    ps_cfg->e_recon_color_fmt = IV_YUV_420P;
2746
0
    ps_cfg->u4_enc_speed_preset = IVE_FASTEST;
2747
0
    ps_cfg->e_rc_mode = DEFAULT_RC;
2748
0
    ps_cfg->u4_max_framerate = DEFAULT_MAX_FRAMERATE;
2749
0
    ps_cfg->u4_max_bitrate = DEFAULT_MAX_BITRATE;
2750
0
    ps_cfg->u4_num_bframes = DEFAULT_MAX_NUM_BFRAMES;
2751
0
    ps_cfg->e_content_type = IV_PROGRESSIVE;
2752
0
    ps_cfg->u4_max_srch_rng_x = DEFAULT_MAX_SRCH_RANGE_X;
2753
0
    ps_cfg->u4_max_srch_rng_y = DEFAULT_MAX_SRCH_RANGE_Y;
2754
0
    ps_cfg->e_slice_mode = IVE_SLICE_MODE_NONE;
2755
0
    ps_cfg->u4_slice_param = DEFAULT_SLICE_PARAM;
2756
0
    ps_cfg->e_arch = ih264e_default_arch();
2757
0
    ps_cfg->e_soc = SOC_GENERIC;
2758
0
    ps_cfg->u4_disp_wd = MAX_WD;
2759
0
    ps_cfg->u4_disp_ht = MAX_HT;
2760
0
    ps_cfg->u4_wd = MAX_WD;
2761
0
    ps_cfg->u4_ht = MAX_HT;
2762
0
    ps_cfg->u4_src_frame_rate = DEFAULT_SRC_FRAME_RATE;
2763
0
    ps_cfg->u4_tgt_frame_rate = DEFAULT_TGT_FRAME_RATE;
2764
0
    ps_cfg->u4_target_bitrate = DEFAULT_BITRATE;
2765
0
    ps_cfg->e_frame_type = IV_NA_FRAME;
2766
0
    ps_cfg->e_enc_mode = IVE_ENC_MODE_DEFAULT;
2767
0
    ps_cfg->u4_i_qp = DEFAULT_I_QP;
2768
0
    ps_cfg->u4_p_qp = DEFAULT_P_QP;
2769
0
    ps_cfg->u4_b_qp = DEFAULT_B_QP;
2770
0
    ps_cfg->u4_i_qp_min = DEFAULT_QP_MIN;
2771
0
    ps_cfg->u4_i_qp_max = DEFAULT_QP_MAX;
2772
0
    ps_cfg->u4_p_qp_min = DEFAULT_QP_MIN;
2773
0
    ps_cfg->u4_p_qp_max = DEFAULT_QP_MAX;
2774
0
    ps_cfg->u4_b_qp_min = DEFAULT_QP_MIN;
2775
0
    ps_cfg->u4_b_qp_max = DEFAULT_QP_MAX;
2776
0
    ps_cfg->e_air_mode = DEFAULT_AIR_MODE;
2777
0
    ps_cfg->u4_air_refresh_period = DEFAULT_AIR_REFRESH_PERIOD;
2778
0
    ps_cfg->u4_vbv_buffer_delay = DEFAULT_VBV_DELAY;
2779
0
    ps_cfg->u4_vbv_buf_size = DEFAULT_VBV_SIZE;
2780
0
    ps_cfg->u4_num_cores = DEFAULT_NUM_CORES;
2781
0
    ps_cfg->u4_me_speed_preset = DEFAULT_ME_SPEED_PRESET;
2782
0
    ps_cfg->u4_enable_hpel = DEFAULT_HPEL;
2783
0
    ps_cfg->u4_enable_qpel = DEFAULT_QPEL;
2784
0
    ps_cfg->u4_enable_intra_4x4 = DEFAULT_I4;
2785
0
    ps_cfg->u4_enable_intra_8x8 = DEFAULT_I8;
2786
0
    ps_cfg->u4_enable_intra_16x16 = DEFAULT_I16;
2787
0
    ps_cfg->u4_enable_fast_sad = DEFAULT_ENABLE_FAST_SAD;
2788
0
    ps_cfg->u4_enable_satqd = DEFAULT_ENABLE_SATQD;
2789
0
    ps_cfg->i4_min_sad =
2790
0
                    (ps_cfg->u4_enable_satqd == DEFAULT_ENABLE_SATQD) ?
2791
0
                                    DEFAULT_MIN_SAD_ENABLE :
2792
0
                                    DEFAULT_MIN_SAD_DISABLE;
2793
0
    ps_cfg->u4_srch_rng_x = DEFAULT_SRCH_RNG_X;
2794
0
    ps_cfg->u4_srch_rng_y = DEFAULT_SRCH_RNG_Y;
2795
0
    ps_cfg->u4_i_frm_interval = DEFAULT_I_INTERVAL;
2796
0
    ps_cfg->u4_idr_frm_interval = DEFAULT_IDR_INTERVAL;
2797
0
    ps_cfg->u4_disable_deblock_level = DEFAULT_DISABLE_DEBLK_LEVEL;
2798
0
    ps_cfg->e_profile = DEFAULT_PROFILE;
2799
0
    ps_cfg->u4_timestamp_low = 0;
2800
0
    ps_cfg->u4_timestamp_high = 0;
2801
0
    ps_cfg->u4_is_valid = 1;
2802
0
    ps_cfg->e_cmd = IVE_CMD_CT_NA;
2803
0
    ps_cfg->i4_wd_mbs = ps_cfg->u4_max_wd >> 4;
2804
0
    ps_cfg->i4_ht_mbs = ps_cfg->u4_max_ht >> 4;
2805
0
    ps_cfg->u4_entropy_coding_mode = DEFAULT_ENTROPY_CODING_MODE;
2806
0
    ps_cfg->u4_weighted_prediction = 0;
2807
0
    ps_cfg->u4_constrained_intra_pred = DEFAULT_CONSTRAINED_INTRAPRED;
2808
0
    ps_cfg->u4_pic_info_type = 0;
2809
0
    ps_cfg->u4_mb_info_type = 0;
2810
0
    ps_cfg->s_vui.u1_video_signal_type_present_flag = 0;
2811
0
    ps_cfg->s_vui.u1_colour_description_present_flag = 0;
2812
2813
0
    return ret;
2814
0
}
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
0
{
2837
    /* enc config param set */
2838
0
    cfg_params_t *ps_cfg = &(ps_codec->s_cfg);
2839
2840
    /* temp var */
2841
0
    WORD32 i;
2842
2843
    /* coded pic count */
2844
0
    ps_codec->i4_poc = 0;
2845
2846
    /* Number of API calls to encode are made */
2847
0
    ps_codec->i4_encode_api_call_cnt = -1;
2848
2849
    /* Indicates no header has been generated yet */
2850
0
    ps_codec->u4_header_generated = 0;
2851
2852
    /* Number of pictures encoded */
2853
0
    ps_codec->i4_pic_cnt = -1;
2854
2855
    /* Number of threads created */
2856
0
    ps_codec->i4_proc_thread_cnt = 0;
2857
2858
    /* ctl mutex init */
2859
0
    ithread_mutex_init(ps_codec->pv_ctl_mutex);
2860
2861
0
    if (ps_codec->s_cfg.u4_keep_threads_active)
2862
0
    {
2863
        /* thread pool mutex init */
2864
0
        ithread_mutex_init(ps_codec->s_thread_pool.pv_thread_pool_mutex);
2865
2866
        /* thread pool conditional init */
2867
0
        ithread_cond_init(ps_codec->s_thread_pool.pv_thread_pool_cond);
2868
0
    }
2869
2870
    /* Set encoder chroma format */
2871
0
    ps_codec->e_codec_color_format =
2872
0
                    (ps_cfg->e_inp_color_fmt == IV_YUV_420SP_VU) ?
2873
0
                                    IV_YUV_420SP_VU : IV_YUV_420SP_UV;
2874
2875
    /* Number of continuous frames where deblocking was disabled */
2876
0
    ps_codec->i4_disable_deblk_pic_cnt = 0;
2877
2878
    /* frame num */
2879
0
    ps_codec->i4_frame_num = 0;
2880
2881
    /* set the current frame type to I frame, since we are going to start  encoding*/
2882
0
    ps_codec->force_curr_frame_type = IV_NA_FRAME;
2883
2884
    /* idr_pic_id */
2885
0
    ps_codec->i4_idr_pic_id = -1;
2886
2887
    /* Flush mode */
2888
0
    ps_codec->i4_flush_mode = 0;
2889
2890
    /* Encode header mode */
2891
0
    ps_codec->i4_header_mode = 0;
2892
2893
    /* Encode generate header */
2894
0
    ps_codec->i4_gen_header = 0;
2895
2896
    /* To signal successful completion of init */
2897
0
    ps_codec->i4_init_done = 1;
2898
2899
    /* To signal that at least one picture was decoded */
2900
0
    ps_codec->i4_first_pic_done = 0;
2901
2902
    /* Reset Codec */
2903
0
    ps_codec->i4_reset_flag = 0;
2904
2905
    /* Current error code */
2906
0
    ps_codec->i4_error_code = IH264E_SUCCESS;
2907
2908
    /* threshold residue */
2909
0
    ps_codec->u4_thres_resi = 1;
2910
2911
    /* inter gating enable */
2912
0
    ps_codec->u4_inter_gate = 0;
2913
2914
    /* entropy mutex init */
2915
0
    ithread_mutex_init(ps_codec->pv_entropy_mutex);
2916
2917
    /* sps id */
2918
0
    ps_codec->i4_sps_id = 0;
2919
2920
    /* sps id */
2921
0
    ps_codec->i4_pps_id = 0;
2922
2923
    /* Process thread created status */
2924
0
    memset(ps_codec->ai4_process_thread_created, 0,
2925
0
           sizeof(ps_codec->ai4_process_thread_created));
2926
2927
0
    memset(&ps_codec->s_global_quality_stats, 0, sizeof(ps_codec->s_global_quality_stats));
2928
2929
    /* Number of MBs processed together */
2930
0
    ps_codec->i4_proc_nmb = 8;
2931
2932
    /* Previous POC msb */
2933
0
    ps_codec->i4_prev_poc_msb = 0;
2934
2935
    /* Previous POC lsb */
2936
0
    ps_codec->i4_prev_poc_lsb = -1;
2937
2938
    /* max Previous POC lsb */
2939
0
    ps_codec->i4_max_prev_poc_lsb = -1;
2940
2941
    /* sps, pps status */
2942
0
    {
2943
0
        sps_t *ps_sps = ps_codec->ps_sps_base;
2944
0
        pps_t *ps_pps = ps_codec->ps_pps_base;
2945
2946
0
        for (i = 0; i < MAX_SPS_CNT; i++)
2947
0
        {
2948
0
            ps_sps->i1_sps_valid = 0;
2949
0
            ps_sps++;
2950
0
        }
2951
2952
0
        for (i = 0; i < MAX_PPS_CNT; i++)
2953
0
        {
2954
0
            ps_pps->i1_pps_valid = 0;
2955
0
            ps_pps++;
2956
0
        }
2957
0
    }
2958
2959
0
    {
2960
0
        WORD32 max_mb_rows = ps_cfg->i4_ht_mbs;
2961
2962
0
        WORD32 num_jobs = max_mb_rows * MAX_CTXT_SETS;
2963
0
        WORD32 clz;
2964
2965
        /* Use next power of two number of entries*/
2966
0
        clz = CLZ(num_jobs);
2967
0
        num_jobs = 1 << (32 - clz);
2968
2969
        /* init process jobq */
2970
0
        ps_codec->pv_proc_jobq = ih264_list_init(
2971
0
                        ps_codec->pv_proc_jobq_buf,
2972
0
                        ps_codec->i4_proc_jobq_buf_size, num_jobs,
2973
0
                        sizeof(job_t), 10);
2974
0
        RETURN_IF((ps_codec->pv_proc_jobq == NULL), IV_FAIL);
2975
0
        ih264_list_reset(ps_codec->pv_proc_jobq);
2976
2977
        /* init entropy jobq */
2978
0
        ps_codec->pv_entropy_jobq = ih264_list_init(
2979
0
                        ps_codec->pv_entropy_jobq_buf,
2980
0
                        ps_codec->i4_entropy_jobq_buf_size, num_jobs,
2981
0
                        sizeof(job_t), 10);
2982
0
        RETURN_IF((ps_codec->pv_entropy_jobq == NULL), IV_FAIL);
2983
0
        ih264_list_reset(ps_codec->pv_entropy_jobq);
2984
0
    }
2985
2986
    /* Update the jobq context to all the threads */
2987
0
    for (i = 0; i < MAX_PROCESS_CTXT; i++)
2988
0
    {
2989
0
        ps_codec->as_process[i].pv_proc_jobq = ps_codec->pv_proc_jobq;
2990
0
        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
0
        ps_codec->as_process[i].i4_id =
2994
0
                        (i >= MAX_PROCESS_THREADS) ?
2995
0
                                        (i - MAX_PROCESS_THREADS) : i;
2996
0
        ps_codec->as_process[i].ps_codec = ps_codec;
2997
2998
0
        ps_codec->as_process[i].s_entropy.pv_proc_jobq = ps_codec->pv_proc_jobq;
2999
0
        ps_codec->as_process[i].s_entropy.pv_entropy_jobq =
3000
0
                        ps_codec->pv_entropy_jobq;
3001
0
        ps_codec->as_process[i].s_entropy.i4_abs_pic_order_cnt = -1;
3002
0
    }
3003
3004
    /* Initialize MV Bank buffer manager */
3005
0
    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
0
    ps_codec->pv_ref_buf_mgr = ih264_buf_mgr_init(
3009
0
                    ps_codec->pv_ref_buf_mgr_base);
3010
3011
    /* Initialize Picture buffer manager for input buffers*/
3012
0
    ps_codec->pv_inp_buf_mgr = ih264_buf_mgr_init(
3013
0
                    ps_codec->pv_inp_buf_mgr_base);
3014
3015
    /* Initialize buffer manager for output buffers*/
3016
0
    ps_codec->pv_out_buf_mgr = ih264_buf_mgr_init(
3017
0
                    ps_codec->pv_out_buf_mgr_base);
3018
3019
    /* buffer cnt in buffer manager */
3020
0
    ps_codec->i4_inp_buf_cnt = 0;
3021
0
    ps_codec->i4_out_buf_cnt = 0;
3022
0
    ps_codec->i4_ref_buf_cnt = 0;
3023
3024
0
    ps_codec->ps_pic_buf = (pic_buf_t *) ps_codec->pv_pic_buf_base;
3025
0
    memset(ps_codec->ps_pic_buf, 0, BUF_MGR_MAX_CNT * sizeof(pic_buf_t));
3026
3027
    /* Initialize dpb manager */
3028
0
    ih264_dpb_mgr_init((dpb_mgr_t*) ps_codec->pv_dpb_mgr);
3029
3030
0
    memset(ps_codec->as_ref_set, 0,
3031
0
           sizeof(ref_set_t) * (MAX_DPB_SIZE + MAX_CTXT_SETS));
3032
0
    for (i = 0; i < (MAX_DPB_SIZE + MAX_CTXT_SETS); i++)
3033
0
    {
3034
0
        ps_codec->as_ref_set[i].i4_pic_cnt = -1;
3035
0
    }
3036
3037
    /* fn ptr init */
3038
0
    ih264e_init_function_ptr(ps_codec);
3039
3040
    /* reset status flags */
3041
0
    for (i = 0; i < MAX_CTXT_SETS; i++)
3042
0
    {
3043
0
        ps_codec->au4_entropy_thread_active[i] = 0;
3044
0
        ps_codec->ai4_pic_cnt[i] = -1;
3045
3046
0
        ps_codec->s_rate_control.pre_encode_skip[i] = 0;
3047
0
        ps_codec->s_rate_control.post_encode_skip[i] = 0;
3048
0
    }
3049
3050
0
    ps_codec->s_rate_control.num_intra_in_prev_frame = 0;
3051
0
    ps_codec->s_rate_control.i4_avg_activity = 0;
3052
3053
0
    return IV_SUCCESS;
3054
0
}
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
0
{
3079
    /* api call I/O structures */
3080
0
    ih264e_num_mem_rec_op_t *ps_op = pv_api_op;
3081
3082
0
    UNUSED(pv_api_ip);
3083
3084
0
    ps_op->s_ive_op.u4_num_mem_rec = MEM_REC_CNT;
3085
3086
0
    return IV_SUCCESS;
3087
0
}
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
0
{
3112
    /* api call I/O structures */
3113
0
    ih264e_fill_mem_rec_ip_t *ps_ip = pv_api_ip;
3114
0
    ih264e_fill_mem_rec_op_t *ps_op = pv_api_op;
3115
3116
    /* profile / level info */
3117
0
    WORD32 level;
3118
0
    WORD32 num_reorder_frames;
3119
0
    WORD32 num_ref_frames;
3120
3121
    /* mem records */
3122
0
    WORD32 no_of_mem_rec;
3123
0
    iv_mem_rec_t *ps_mem_rec_base, *ps_mem_rec;
3124
3125
    /* frame dimensions */
3126
0
    WORD32 max_wd_luma, max_ht_luma;
3127
0
    WORD32 max_mb_rows, max_mb_cols, max_mb_cnt;
3128
3129
    /* temp var */
3130
0
    WORD32 i;
3131
3132
    /* error status */
3133
0
    IV_STATUS_T status = IV_SUCCESS;
3134
3135
0
    num_reorder_frames = ps_ip->s_ive_ip.u4_max_reorder_cnt;
3136
0
    num_ref_frames = ps_ip->s_ive_ip.u4_max_ref_cnt;
3137
3138
    /* mem records */
3139
0
    ps_mem_rec_base = ps_ip->s_ive_ip.ps_mem_rec;
3140
0
    no_of_mem_rec = ps_ip->s_ive_ip.u4_num_mem_rec;
3141
3142
    /* frame dimensions */
3143
0
    max_ht_luma = ps_ip->s_ive_ip.u4_max_ht;
3144
0
    max_wd_luma = ps_ip->s_ive_ip.u4_max_wd;
3145
0
    max_ht_luma = ALIGN16(max_ht_luma);
3146
0
    max_wd_luma = ALIGN16(max_wd_luma);
3147
0
    max_mb_rows = max_ht_luma / MB_SIZE;
3148
0
    max_mb_cols = max_wd_luma / MB_SIZE;
3149
0
    max_mb_cnt = max_mb_rows * max_mb_cols;
3150
3151
    /* profile / level info */
3152
0
    level = ih264e_get_min_level(max_wd_luma, max_ht_luma);
3153
3154
    /* validate params */
3155
0
    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
0
    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
0
    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
0
    ps_mem_rec = ps_mem_rec_base;
3175
0
    for (i = 0; i < no_of_mem_rec; i++)
3176
0
    {
3177
0
        ps_mem_rec->u4_mem_alignment = 128;
3178
0
        ps_mem_rec->e_mem_type = IV_EXTERNAL_CACHEABLE_PERSISTENT_MEM;
3179
0
        ps_mem_rec++;
3180
0
    }
3181
3182
    /************************************************************************
3183
     * Request memory for h264 encoder handle                               *
3184
     ***********************************************************************/
3185
0
    ps_mem_rec = &ps_mem_rec_base[MEM_REC_IV_OBJ];
3186
0
    {
3187
0
        ps_mem_rec->u4_mem_size = sizeof(iv_obj_t);
3188
0
    }
3189
0
    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
0
    ps_mem_rec = &ps_mem_rec_base[MEM_REC_CODEC];
3195
0
    {
3196
0
        ps_mem_rec->u4_mem_size = sizeof(codec_t);
3197
0
    }
3198
0
    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
0
    ps_mem_rec = &ps_mem_rec_base[MEM_REC_CABAC];
3204
0
    {
3205
0
        ps_mem_rec->u4_mem_size = sizeof(cabac_ctxt_t);
3206
0
    }
3207
0
    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
0
    ps_mem_rec = &ps_mem_rec_base[MEM_REC_CABAC_MB_INFO];
3213
0
    {
3214
0
        ps_mem_rec->u4_mem_size = ((max_mb_cols + 1) + 1)
3215
0
                        * sizeof(mb_info_ctxt_t);
3216
0
    }
3217
0
    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
0
    ps_mem_rec = &ps_mem_rec_base[MEM_REC_ENTROPY];
3235
0
    {
3236
        /* total size of the mem record */
3237
0
        WORD32 total_size = 0;
3238
3239
        /* size of skip mb run */
3240
0
        total_size += sizeof(WORD32);
3241
0
        total_size = ALIGN8(total_size);
3242
3243
        /* size in bytes to store entropy status of an entire frame */
3244
0
        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
0
        total_size += max_mb_cols;
3247
0
        total_size = ALIGN128(total_size);
3248
3249
        /* size of bit stream buffer */
3250
0
        total_size += sizeof(bitstrm_t);
3251
0
        total_size = ALIGN128(total_size);
3252
3253
        /* top nnz luma */
3254
0
        total_size += (max_mb_cols * 4 * sizeof(UWORD8));
3255
0
        total_size = ALIGN128(total_size);
3256
3257
        /* top nnz cbcr */
3258
0
        total_size += (max_mb_cols * 4 * sizeof(UWORD8));
3259
0
        total_size = ALIGN128(total_size);
3260
3261
        /* total size per each proc ctxt */
3262
0
        total_size *= MAX_CTXT_SETS;
3263
3264
0
        ps_mem_rec->u4_mem_size = total_size;
3265
0
    }
3266
0
    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
0
    ps_mem_rec = &ps_mem_rec_base[MEM_REC_MB_COEFF_DATA];
3282
0
    {
3283
        /* temp var */
3284
0
        WORD32 size = 0;
3285
3286
        /* size of coeff data of 1 mb */
3287
0
        size += sizeof(tu_sblk_coeff_data_t) * MAX_4x4_SUBBLKS;
3288
3289
        /* size of coeff data of 1 row of mb's */
3290
0
        size *= max_mb_cols;
3291
3292
        /* align to avoid any false sharing across threads */
3293
0
        size = ALIGN64(size);
3294
3295
        /* size for one full frame */
3296
0
        size *= max_mb_rows;
3297
3298
        /* size of each proc buffer set (ping, pong) */
3299
0
        size *= MAX_CTXT_SETS;
3300
3301
0
        ps_mem_rec->u4_mem_size = size;
3302
0
    }
3303
0
    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
0
    ps_mem_rec = &ps_mem_rec_base[MEM_REC_MB_HEADER_DATA];
3312
0
    {
3313
        /* temp var */
3314
0
        WORD32 size;
3315
3316
        /* size per MB */
3317
0
        size = 40;
3318
3319
        /* size for 1 row of mbs */
3320
0
        size = size * max_mb_cols;
3321
3322
        /* align to avoid any false sharing across threads */
3323
0
        size = ALIGN64(size);
3324
3325
        /* size for one full frame */
3326
0
        size *= max_mb_rows;
3327
3328
        /* size of each proc buffer set (ping, pong) */
3329
0
        size *= MAX_CTXT_SETS;
3330
3331
0
        ps_mem_rec->u4_mem_size = size;
3332
0
    }
3333
0
    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
0
    ps_mem_rec = &ps_mem_rec_base[MEM_REC_MVBANK];
3349
0
    {
3350
        /* max luma samples */
3351
0
        WORD32 max_luma_samples = 0;
3352
3353
        /* determine max luma samples */
3354
0
        for (i = 0; i < 16; i++)
3355
0
            if (level ==(WORD32)gas_ih264_lvl_tbl[i].u4_level_idc)
3356
0
                max_luma_samples = gas_ih264_lvl_tbl[i].u4_max_fs
3357
0
                                << (BLK_SIZE + BLK_SIZE);
3358
3359
0
        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
0
        ps_mem_rec->u4_mem_size += BUF_MGR_MAX_CNT * sizeof(mv_buf_t);
3374
3375
0
        ps_mem_rec->u4_mem_size += (num_ref_frames + num_reorder_frames
3376
0
                        + MAX_CTXT_SETS)
3377
0
                        * ih264e_get_pic_mv_bank_size(max_luma_samples);
3378
0
    }
3379
0
    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
0
    ps_mem_rec = &ps_mem_rec_base[MEM_REC_MVBITS];
3390
0
    {
3391
        /* max srch range x */
3392
0
        UWORD32 u4_srch_range_x = ps_ip->s_ive_ip.u4_max_srch_rng_x;
3393
3394
        /* max srch range y */
3395
0
        UWORD32 u4_srch_range_y = ps_ip->s_ive_ip.u4_max_srch_rng_y;
3396
3397
        /* max srch range */
3398
0
        UWORD32 u4_max_srch_range = MAX(u4_srch_range_x, u4_srch_range_y);
3399
3400
        /* due to subpel */
3401
0
        u4_max_srch_range <<= 2;
3402
3403
        /* due to mv on either direction */
3404
0
        u4_max_srch_range = (u4_max_srch_range << 1);
3405
3406
        /* due to pred mv + zero */
3407
0
        u4_max_srch_range = (u4_max_srch_range << 1) + 1;
3408
3409
0
        u4_max_srch_range = ALIGN128(u4_max_srch_range);
3410
3411
0
        ps_mem_rec->u4_mem_size = u4_max_srch_range;
3412
0
    }
3413
0
    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
0
    ps_mem_rec = &ps_mem_rec_base[MEM_REC_INTRA_COST];
3423
0
    {
3424
        /* total size of the mem record */
3425
0
        WORD32 total_size = 0;
3426
3427
        /* size in bytes to mb core coding status of an entire frame */
3428
0
        total_size = max_mb_cnt * sizeof(WORD32);
3429
3430
0
        ps_mem_rec->u4_mem_size = total_size;
3431
0
    }
3432
0
    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
0
    ps_mem_rec = &ps_mem_rec_base[MEM_REC_SPS];
3438
0
    {
3439
0
        ps_mem_rec->u4_mem_size = MAX_SPS_CNT * sizeof(sps_t);
3440
0
    }
3441
0
    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
0
    ps_mem_rec = &ps_mem_rec_base[MEM_REC_PPS];
3447
0
    {
3448
0
        ps_mem_rec->u4_mem_size = MAX_PPS_CNT * sizeof(pps_t);
3449
0
    }
3450
0
    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
0
    ps_mem_rec = &ps_mem_rec_base[MEM_REC_SLICE_HDR];
3456
0
    {
3457
0
        ps_mem_rec->u4_mem_size = MAX_CTXT_SETS * MAX_SLICE_HDR_CNT
3458
0
                        * sizeof(slice_header_t);
3459
0
    }
3460
0
    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
0
    ps_mem_rec = &ps_mem_rec_base[MEM_REC_AIR_MAP];
3466
0
    {
3467
        /* total size of the mem record */
3468
0
        WORD32 total_size = 0;
3469
3470
        /* intra coded map */
3471
0
        total_size += max_mb_cnt;
3472
0
        total_size *= MAX_CTXT_SETS;
3473
3474
        /* mb refresh map */
3475
0
        total_size += sizeof(UWORD16) * max_mb_cnt;
3476
3477
        /* alignment */
3478
0
        total_size = ALIGN128(total_size);
3479
3480
0
        ps_mem_rec->u4_mem_size = total_size;
3481
0
    }
3482
0
    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
0
    ps_mem_rec = &ps_mem_rec_base[MEM_REC_SLICE_MAP];
3491
0
    {
3492
        /* total size of the mem record */
3493
0
        WORD32 total_size = 0;
3494
3495
        /* size in bytes to slice index of all mbs of a frame */
3496
0
        total_size = ALIGN64(max_mb_cnt);
3497
3498
        /* ih264e_update_proc_ctxt can overread by 1 at the end */
3499
0
        total_size += 1;
3500
3501
        /* total size per each proc ctxt */
3502
0
        total_size *= MAX_CTXT_SETS;
3503
0
        ps_mem_rec->u4_mem_size = total_size;
3504
0
    }
3505
0
    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
0
    ps_mem_rec = &ps_mem_rec_base[MEM_REC_THREAD_HANDLE];
3511
0
    {
3512
0
        WORD32 thread_pool_size = 0;
3513
0
        WORD32 handle_size = ithread_get_handle_size();
3514
3515
0
        if (ps_ip->s_ive_ip.u4_keep_threads_active)
3516
0
        {
3517
0
            thread_pool_size += ithread_get_mutex_lock_size();
3518
0
            thread_pool_size += ithread_get_cond_size();
3519
0
        }
3520
3521
0
        ps_mem_rec->u4_mem_size = thread_pool_size + (MAX_PROCESS_THREADS * handle_size);
3522
0
    }
3523
0
    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
0
    ps_mem_rec = &ps_mem_rec_base[MEM_REC_CTL_MUTEX];
3529
0
    {
3530
0
        ps_mem_rec->u4_mem_size = ithread_get_mutex_lock_size();
3531
0
    }
3532
0
    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
0
    ps_mem_rec = &ps_mem_rec_base[MEM_REC_ENTROPY_MUTEX];
3538
0
    {
3539
0
        ps_mem_rec->u4_mem_size = ithread_get_mutex_lock_size();
3540
0
    }
3541
0
    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
0
    ps_mem_rec = &ps_mem_rec_base[MEM_REC_PROC_JOBQ];
3547
0
    {
3548
        /* One process job per row of MBs */
3549
        /* Allocate for two pictures, so that wrap around can be handled easily */
3550
0
        WORD32 num_jobs = max_mb_rows * MAX_CTXT_SETS;
3551
3552
0
        WORD32 job_queue_size = ih264_list_size(num_jobs, sizeof(job_t));
3553
3554
0
        ps_mem_rec->u4_mem_size = job_queue_size;
3555
0
    }
3556
0
    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
0
    ps_mem_rec = &ps_mem_rec_base[MEM_REC_ENTROPY_JOBQ];
3562
0
    {
3563
        /* One process job per row of MBs */
3564
        /* Allocate for two pictures, so that wrap around can be handled easily */
3565
0
        WORD32 num_jobs = max_mb_rows * MAX_CTXT_SETS;
3566
3567
0
        WORD32 job_queue_size = ih264_list_size(num_jobs, sizeof(job_t));
3568
3569
0
        ps_mem_rec->u4_mem_size = job_queue_size;
3570
0
    }
3571
0
    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
0
    ps_mem_rec = &ps_mem_rec_base[MEM_REC_PROC_MAP];
3581
0
    {
3582
        /* total size of the mem record */
3583
0
        WORD32 total_size = 0;
3584
3585
        /* size in bytes to mb core coding status of an entire frame */
3586
0
        total_size = max_mb_cnt;
3587
3588
        /* add an additional 1 row of bytes to evade the special case of row 0 */
3589
0
        total_size += max_mb_cols;
3590
3591
        /* total size per each proc ctxt */
3592
0
        total_size *= MAX_CTXT_SETS;
3593
0
        ps_mem_rec->u4_mem_size = total_size;
3594
0
    }
3595
0
    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
0
    ps_mem_rec = &ps_mem_rec_base[MEM_REC_DBLK_MAP];
3602
0
    {
3603
        /* total size of the mem record */
3604
0
        WORD32 total_size = 0;
3605
3606
        /* size in bytes to mb core coding status of an entire frame */
3607
0
        total_size = max_mb_cnt;
3608
3609
        /* add an additional 1 row of bytes to evade the special case of row 0 */
3610
0
        total_size += max_mb_cols;
3611
3612
0
        total_size = ALIGN64(total_size);
3613
3614
        /* total size per each proc ctxt */
3615
0
        total_size *= MAX_CTXT_SETS;
3616
0
        ps_mem_rec->u4_mem_size = total_size;
3617
0
    }
3618
0
    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
0
    ps_mem_rec = &ps_mem_rec_base[MEM_REC_ME_MAP];
3625
0
    {
3626
        /* total size of the mem record */
3627
0
        WORD32 total_size = 0;
3628
3629
        /* size in bytes to mb core coding status of an entire frame */
3630
0
        total_size = max_mb_cnt;
3631
3632
        /* add an additional 1 row of bytes to evade the special case of row 0 */
3633
0
        total_size += max_mb_cols;
3634
3635
        /* total size per each proc ctxt */
3636
0
        total_size *= MAX_CTXT_SETS;
3637
3638
0
        ps_mem_rec->u4_mem_size = total_size;
3639
0
    }
3640
0
    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
0
    ps_mem_rec = &ps_mem_rec_base[MEM_REC_DPB_MGR];
3646
0
    {
3647
0
        ps_mem_rec->u4_mem_size = sizeof(dpb_mgr_t);
3648
0
    }
3649
0
    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
0
    ps_mem_rec = &ps_mem_rec_base[MEM_REC_PROC_SCRATCH];
3683
0
    {
3684
0
        WORD32 total_size = 0;
3685
0
        WORD32 i4_tmp_size;
3686
3687
        /* size to hold prediction buffer */
3688
0
        total_size += sizeof(UWORD8) * 16 * 16;
3689
0
        total_size = ALIGN64(total_size);
3690
3691
        /* size to hold recon for intra 4x4 buffer */
3692
0
        total_size += sizeof(UWORD8) * 16 * 16;
3693
0
        total_size = ALIGN64(total_size);
3694
3695
        /* prediction buffer intra 16x16 */
3696
0
        total_size += sizeof(UWORD8) * 16 * 16;
3697
0
        total_size = ALIGN64(total_size);
3698
3699
        /* prediction buffer intra 16x16 plane*/
3700
0
        total_size += sizeof(UWORD8) * 16 * 16;
3701
0
        total_size = ALIGN64(total_size);
3702
3703
        /* prediction buffer intra chroma*/
3704
0
        total_size += sizeof(UWORD8) * 16 * 8;
3705
0
        total_size = ALIGN64(total_size);
3706
3707
        /* prediction buffer intra chroma plane*/
3708
0
        total_size += sizeof(UWORD8) * 16 * 8;
3709
0
        total_size = ALIGN64(total_size);
3710
3711
        /* size to hold fwd transform output */
3712
0
        total_size += sizeof(WORD16) * SIZE_TRANS_BUFF;
3713
0
        total_size = ALIGN64(total_size);
3714
3715
        /* size to hold fwd transform output */
3716
0
        total_size += sizeof(WORD16) * SIZE_TRANS_BUFF;
3717
0
        total_size = ALIGN64(total_size);
3718
3719
        /* size to hold temporary data during inverse transform */
3720
0
        total_size += sizeof(WORD32) * SIZE_TMP_BUFF_ITRANS;
3721
0
        total_size = ALIGN64(total_size);
3722
3723
        /* Buffers for holding half_x , half_y and half_xy planes */
3724
0
        i4_tmp_size = sizeof(UWORD8) * (HP_BUFF_WD * HP_BUFF_HT);
3725
0
        total_size += (ALIGN64(i4_tmp_size) * SUBPEL_BUFF_CNT);
3726
3727
        /* Allocate for each process thread */
3728
0
        total_size *= MAX_PROCESS_CTXT;
3729
3730
0
        ps_mem_rec->u4_mem_size = total_size;
3731
0
    }
3732
0
    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
0
    ps_mem_rec = &ps_mem_rec_base[MEM_REC_QUANT_PARAM];
3746
0
    {
3747
        /* total size of the mem record */
3748
0
        WORD32 total_size = 0;
3749
3750
        /* quantization parameter list for planes y,cb and cr */
3751
0
        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
0
        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
0
        total_size += ALIGN64(sizeof(WORD16) * 4 * 4) * 3;
3762
3763
        /* Size for SATDQ threshold matrix for palnes y, cb and cr */
3764
0
        total_size += ALIGN64(sizeof(UWORD16) * 9) * 3;
3765
3766
        /* total size per each proc thread */
3767
0
        total_size *= MAX_PROCESS_CTXT;
3768
3769
0
        ps_mem_rec->u4_mem_size = total_size;
3770
0
    }
3771
0
    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
0
    ps_mem_rec = &ps_mem_rec_base[MEM_REC_TOP_ROW_SYN_INFO];
3788
0
    {
3789
        /* total size of the mem record */
3790
0
        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
0
        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
0
        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
0
        total_size += (max_mb_cols + 1) * sizeof(enc_pu_t);
3802
3803
        /* total size per proc ctxt */
3804
0
        total_size = ALIGN128(total_size);
3805
3806
        /* total size per each proc ctxt */
3807
0
        total_size *= MAX_CTXT_SETS;
3808
0
        ps_mem_rec->u4_mem_size = total_size;
3809
0
    }
3810
0
    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
0
    ps_mem_rec = &ps_mem_rec_base[MEM_REC_BS_QP];
3827
0
    {
3828
        /* total size of the mem record */
3829
0
        WORD32 total_size = 0;
3830
3831
        /* size in bytes to store vertical edge bs, horizontal edge bs and qp of every mb*/
3832
0
        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
0
        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
0
        horz_bs_size = ALIGN64(max_mb_cnt * 4 * 4);
3843
3844
        /* qp of each mb requires 1 byte */
3845
0
        qp_size = ALIGN64(max_mb_cnt);
3846
3847
        /* total size */
3848
0
        total_size = vert_bs_size + horz_bs_size + qp_size;
3849
3850
        /* total size per each proc ctxt */
3851
0
        total_size *= MAX_CTXT_SETS;
3852
3853
0
        ps_mem_rec->u4_mem_size = total_size;
3854
0
    }
3855
0
    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
0
    ps_mem_rec = &ps_mem_rec_base[MEM_REC_INP_PIC];
3861
0
    {
3862
0
        ps_mem_rec->u4_mem_size = ih264_buf_mgr_size();
3863
0
    }
3864
0
    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
0
    ps_mem_rec = &ps_mem_rec_base[MEM_REC_OUT];
3870
0
    {
3871
0
        ps_mem_rec->u4_mem_size = ih264_buf_mgr_size();
3872
0
    }
3873
0
    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
0
    ps_mem_rec = &ps_mem_rec_base[MEM_REC_CSC];
3879
0
    {
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
0
        ps_mem_rec->u4_mem_size = MAX_CTXT_SETS
3883
0
                        * ((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
0
        ps_mem_rec->u4_mem_size += max_wd_luma;
3889
0
    }
3890
0
    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
0
    ps_mem_rec = &ps_mem_rec_base[MEM_REC_REF_PIC];
3907
0
    {
3908
0
        ps_mem_rec->u4_mem_size = ih264_buf_mgr_size();
3909
0
        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
0
        ps_mem_rec->u4_mem_size += HPEL_PLANES_CNT
3930
0
                        * ih264e_get_total_pic_buf_size(
3931
0
                                        max_wd_luma * max_ht_luma, level,
3932
0
                                        PAD_WD, PAD_HT, num_ref_frames,
3933
0
                                        num_reorder_frames);
3934
0
    }
3935
0
    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
0
    ps_mem_rec = &ps_mem_rec_base[MEM_REC_BACKUP];
3941
0
    {
3942
0
        ps_mem_rec->u4_mem_size = MEM_REC_CNT * sizeof(iv_mem_rec_t);
3943
0
    }
3944
0
    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
0
    ps_mem_rec = &ps_mem_rec_base[MEM_REC_MB_INFO_NMB];
3951
0
    {
3952
0
        ps_mem_rec->u4_mem_size = MAX_PROCESS_CTXT * max_mb_cols *
3953
0
                                 (sizeof(mb_info_nmb_t) + MB_SIZE * MB_SIZE
3954
0
                                  * sizeof(UWORD8));
3955
0
    }
3956
0
    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
0
    ps_mem_rec = &ps_mem_rec_base[MEM_REC_RC];
3962
0
    {
3963
0
        ih264e_get_rate_control_mem_tab(NULL, ps_mem_rec, FILL_MEMTAB);
3964
0
    }
3965
0
    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
0
    ps_mem_rec = ps_mem_rec_base;
3970
0
    for (i = 0; i < MEM_REC_CNT; i++)
3971
0
    {
3972
0
        ps_mem_rec->u4_mem_size = ALIGN128(ps_mem_rec->u4_mem_size);
3973
0
        ps_mem_rec++;
3974
0
    }
3975
3976
0
    ps_op->s_ive_op.u4_num_mem_rec = MEM_REC_CNT;
3977
3978
0
    DEBUG("Num mem recs in fill call : %d\n", ps_op->s_ive_op.u4_num_mem_rec);
3979
3980
0
    return (status);
3981
0
}
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
0
{
4011
    /* api call I/O structures */
4012
0
    ih264e_init_ip_t *ps_ip = pv_api_ip;
4013
0
    ih264e_init_op_t *ps_op = pv_api_op;
4014
4015
    /* mem records */
4016
0
    iv_mem_rec_t *ps_mem_rec_base, *ps_mem_rec;
4017
4018
    /* codec variables */
4019
0
    codec_t * ps_codec;
4020
0
    cabac_ctxt_t *ps_cabac;
4021
0
    mb_info_ctxt_t *ps_mb_map_ctxt_inc;
4022
4023
0
    cfg_params_t *ps_cfg;
4024
4025
    /* frame dimensions */
4026
0
    WORD32 max_wd_luma, max_ht_luma;
4027
0
    WORD32 max_mb_rows, max_mb_cols, max_mb_cnt;
4028
4029
    /* temp var */
4030
0
    WORD32 i, j;
4031
0
    WORD32 status = IV_SUCCESS;
4032
4033
    /* frame dimensions */
4034
0
    max_ht_luma = ALIGN16(ps_ip->s_ive_ip.u4_max_ht);
4035
0
    max_wd_luma = ALIGN16(ps_ip->s_ive_ip.u4_max_wd);
4036
0
    max_mb_rows = max_ht_luma / MB_SIZE;
4037
0
    max_mb_cols = max_wd_luma / MB_SIZE;
4038
0
    max_mb_cnt = max_mb_rows * max_mb_cols;
4039
4040
    /* mem records */
4041
0
    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
0
    for (i = MEM_REC_CODEC; i < MEM_REC_CNT; i++)
4045
0
    {
4046
0
        ps_mem_rec = &ps_mem_rec_base[i];
4047
0
        memset(ps_mem_rec->pv_base, 0, ps_mem_rec->u4_mem_size);
4048
0
    }
4049
4050
    /* Init mem records */
4051
0
    ps_mem_rec = &ps_mem_rec_base[MEM_REC_CODEC];
4052
0
    {
4053
0
        ps_codec_obj->pv_codec_handle = ps_mem_rec->pv_base;
4054
0
        ps_codec = (codec_t *) (ps_codec_obj->pv_codec_handle);
4055
0
    }
4056
    /* Init mem records_cabac ctxt */
4057
0
    ps_mem_rec = &ps_mem_rec_base[MEM_REC_CABAC];
4058
0
    {
4059
0
        ps_cabac = (cabac_ctxt_t *)(ps_mem_rec->pv_base);
4060
0
    }
4061
4062
    /* Init mem records mb info array for CABAC */
4063
0
    ps_mem_rec = &ps_mem_rec_base[MEM_REC_CABAC_MB_INFO];
4064
0
    {
4065
0
        ps_mb_map_ctxt_inc = (mb_info_ctxt_t *)(ps_mem_rec->pv_base);
4066
0
    }
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
0
    memset(ps_codec, 0, sizeof(codec_t));
4072
0
    memset(ps_cabac, 0, sizeof(cabac_ctxt_t));
4073
4074
    /* Set default Config Params */
4075
0
    ps_cfg = &ps_codec->s_cfg;
4076
0
    ih264e_set_default_params(ps_cfg);
4077
4078
    /* Update config params as per input */
4079
0
    ps_cfg->u4_max_wd = ALIGN16(ps_ip->s_ive_ip.u4_max_wd);
4080
0
    ps_cfg->u4_max_ht = ALIGN16(ps_ip->s_ive_ip.u4_max_ht);
4081
4082
    /* Initialize dimensions to max dimensions during init */
4083
0
    ps_cfg->u4_wd = ps_cfg->u4_disp_wd = ps_cfg->u4_max_wd;
4084
0
    ps_cfg->u4_ht = ps_cfg->u4_disp_ht = ps_cfg->u4_max_ht;
4085
4086
0
    ps_cfg->i4_wd_mbs = ps_cfg->u4_max_wd >> 4;
4087
0
    ps_cfg->i4_ht_mbs = ps_cfg->u4_max_ht >> 4;
4088
0
    ps_cfg->u4_max_ref_cnt = ps_ip->s_ive_ip.u4_max_ref_cnt;
4089
0
    ps_cfg->u4_max_reorder_cnt = ps_ip->s_ive_ip.u4_max_reorder_cnt;
4090
0
    ps_cfg->u4_max_level = ps_ip->s_ive_ip.u4_max_level;
4091
0
    ps_cfg->e_inp_color_fmt = ps_ip->s_ive_ip.e_inp_color_fmt;
4092
0
    ps_cfg->e_recon_color_fmt = ps_ip->s_ive_ip.e_recon_color_fmt;
4093
0
    ps_cfg->u4_max_framerate = ps_ip->s_ive_ip.u4_max_framerate;
4094
0
    ps_cfg->u4_max_bitrate = ps_ip->s_ive_ip.u4_max_bitrate;
4095
0
    ps_cfg->u4_num_bframes = ps_ip->s_ive_ip.u4_num_bframes;
4096
0
    ps_cfg->e_content_type = ps_ip->s_ive_ip.e_content_type;
4097
0
    ps_cfg->u4_max_srch_rng_x = ps_ip->s_ive_ip.u4_max_srch_rng_x;
4098
0
    ps_cfg->u4_max_srch_rng_y = ps_ip->s_ive_ip.u4_max_srch_rng_y;
4099
0
    ps_cfg->e_slice_mode = ps_ip->s_ive_ip.e_slice_mode;
4100
0
    ps_cfg->u4_slice_param = ps_ip->s_ive_ip.u4_slice_param;
4101
0
    ps_cfg->e_arch = ps_ip->s_ive_ip.e_arch;
4102
0
    ps_cfg->e_soc = ps_ip->s_ive_ip.e_soc;
4103
0
    ps_cfg->u4_enable_recon = ps_ip->s_ive_ip.u4_enable_recon;
4104
0
    ps_cfg->e_rc_mode = ps_ip->s_ive_ip.e_rc_mode;
4105
0
    ps_cfg->u4_keep_threads_active = ps_ip->s_ive_ip.u4_keep_threads_active;
4106
4107
    /* Validate params */
4108
0
    if ((ps_ip->s_ive_ip.u4_max_level < MIN_LEVEL)
4109
0
                    || (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
0
    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
0
    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
0
    ps_mem_rec = &ps_mem_rec_base[MEM_REC_BACKUP];
4128
0
    {
4129
0
        ps_codec->ps_mem_rec_backup = (iv_mem_rec_t *) ps_mem_rec->pv_base;
4130
4131
0
        memcpy(ps_codec->ps_mem_rec_backup, ps_mem_rec_base,
4132
0
               MEM_REC_CNT * sizeof(iv_mem_rec_t));
4133
0
    }
4134
4135
0
    ps_mem_rec = &ps_mem_rec_base[MEM_REC_ENTROPY];
4136
0
    {
4137
        /* temp var */
4138
0
        WORD32 size = 0, offset;
4139
4140
0
        for (i = 0; i < MAX_PROCESS_CTXT; i++)
4141
0
        {
4142
0
            if (i < MAX_PROCESS_CTXT / MAX_CTXT_SETS)
4143
0
            {
4144
                /* base ptr */
4145
0
                UWORD8 *pu1_buf = ps_mem_rec->pv_base;
4146
4147
                /* reset size */
4148
0
                size = 0;
4149
4150
                /* skip mb run */
4151
0
                ps_codec->as_process[i].s_entropy.pi4_mb_skip_run =
4152
0
                                (void *) (pu1_buf + size);
4153
0
                size += sizeof(WORD32);
4154
0
                size = ALIGN8(size);
4155
4156
                /* entropy map */
4157
0
                ps_codec->as_process[i].s_entropy.pu1_entropy_map =
4158
0
                                (void *) (pu1_buf + size + max_mb_cols);
4159
                /* size in bytes to store entropy status of an entire frame */
4160
0
                size += (max_mb_cols * max_mb_rows);
4161
                /* add an additional 1 row of bytes to evade the special case of row 0 */
4162
0
                size += max_mb_cols;
4163
0
                size = ALIGN128(size);
4164
4165
                /* bit stream ptr */
4166
0
                ps_codec->as_process[i].s_entropy.ps_bitstrm = (void *) (pu1_buf
4167
0
                                + size);
4168
0
                size += sizeof(bitstrm_t);
4169
0
                size = ALIGN128(size);
4170
4171
                /* nnz luma */
4172
0
                ps_codec->as_process[i].s_entropy.pu1_top_nnz_luma =
4173
0
                                (void *) (pu1_buf + size);
4174
0
                size += (max_mb_cols * 4 * sizeof(UWORD8));
4175
0
                size = ALIGN128(size);
4176
4177
                /* nnz chroma */
4178
0
                ps_codec->as_process[i].s_entropy.pu1_top_nnz_cbcr =
4179
0
                                (void *) (pu1_buf + size);
4180
0
                size += (max_mb_cols * 4 * sizeof(UWORD8));
4181
0
                size = ALIGN128(size);
4182
0
                offset = size;
4183
                /* cabac Context */
4184
0
                ps_codec->as_process[i].s_entropy.ps_cabac = ps_cabac;
4185
0
            }
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
0
        }
4230
0
        ps_codec->as_process[0].s_entropy.ps_cabac->ps_mb_map_ctxt_inc_base =
4231
0
                        ps_mb_map_ctxt_inc;
4232
0
    }
4233
4234
0
    ps_mem_rec = &ps_mem_rec_base[MEM_REC_MB_COEFF_DATA];
4235
0
    {
4236
        /* temp var */
4237
0
        WORD32 size = 0, size_of_row;
4238
0
        UWORD8 *pu1_buf = ps_mem_rec->pv_base;
4239
4240
        /* size of coeff data of 1 mb */
4241
0
        size += sizeof(tu_sblk_coeff_data_t) * MAX_4x4_SUBBLKS;
4242
4243
        /* size of coeff data of 1 row of mb's */
4244
0
        size *= max_mb_cols;
4245
4246
        /* align to avoid false sharing */
4247
0
        size = ALIGN64(size);
4248
0
        size_of_row = size;
4249
4250
        /* size for one full frame */
4251
0
        size *= max_mb_rows;
4252
4253
0
        ps_codec->u4_size_coeff_data = size_of_row;
4254
4255
0
        for (i = 0; i < MAX_PROCESS_CTXT; i++)
4256
0
        {
4257
0
            if (i < MAX_PROCESS_CTXT / MAX_CTXT_SETS)
4258
0
            {
4259
0
                ps_codec->as_process[i].pv_pic_mb_coeff_data = pu1_buf;
4260
0
                ps_codec->as_process[i].s_entropy.pv_pic_mb_coeff_data =
4261
0
                                pu1_buf;
4262
0
            }
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
0
        }
4270
0
    }
4271
4272
0
    ps_mem_rec = &ps_mem_rec_base[MEM_REC_MB_HEADER_DATA];
4273
0
    {
4274
        /* temp var */
4275
0
        WORD32 size, size_of_row;
4276
0
        UWORD8 *pu1_buf = ps_mem_rec->pv_base;
4277
4278
        /* size of header data of 1 mb */
4279
0
        size = sizeof(mb_hdr_t);
4280
4281
        /* size for 1 row of mbs */
4282
0
        size = size * max_mb_cols;
4283
4284
        /* align to avoid any false sharing across threads */
4285
0
        size = ALIGN64(size);
4286
0
        size_of_row = size;
4287
4288
        /* size for one full frame */
4289
0
        size *= max_mb_rows;
4290
4291
0
        ps_codec->u4_size_header_data = size_of_row;
4292
4293
0
        for (i = 0; i < MAX_PROCESS_CTXT; i++)
4294
0
        {
4295
0
            if (i < MAX_PROCESS_CTXT / MAX_CTXT_SETS)
4296
0
            {
4297
0
                ps_codec->as_process[i].pv_pic_mb_header_data = pu1_buf;
4298
0
                ps_codec->as_process[i].s_entropy.pv_pic_mb_header_data =
4299
0
                                pu1_buf;
4300
0
            }
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
0
        }
4308
0
    }
4309
4310
0
    ps_mem_rec = &ps_mem_rec_base[MEM_REC_MVBANK];
4311
0
    {
4312
        /* size of buf mgr struct */
4313
0
        WORD32 size = ih264_buf_mgr_size();
4314
4315
        /* temp var */
4316
0
        UWORD8 *pu1_buf = ps_mem_rec->pv_base;
4317
4318
        /* mv buffer mgr */
4319
0
        ps_codec->pv_mv_buf_mgr_base = pu1_buf;
4320
4321
        /* mv bank */
4322
0
        ps_codec->pv_mv_bank_buf_base = pu1_buf + size;
4323
0
        ps_codec->i4_total_mv_bank_size = ps_mem_rec->u4_mem_size - size;
4324
0
    }
4325
4326
0
    ps_mem_rec = &ps_mem_rec_base[MEM_REC_MVBITS];
4327
0
    {
4328
        /* max srch range x */
4329
0
        UWORD32 u4_srch_range_x = ps_ip->s_ive_ip.u4_max_srch_rng_x;
4330
4331
        /* max srch range y */
4332
0
        UWORD32 u4_srch_range_y = ps_ip->s_ive_ip.u4_max_srch_rng_y;
4333
4334
        /* max srch range */
4335
0
        UWORD32 u4_max_srch_range = MAX(u4_srch_range_x, u4_srch_range_y);
4336
4337
        /* temp var */
4338
0
        UWORD8 *pu1_buf = ps_mem_rec->pv_base;
4339
4340
        /* due to subpel */
4341
0
        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
0
        u4_max_srch_range = (u4_max_srch_range << 1) + 1;
4348
4349
0
        for (i = 0; i < MAX_PROCESS_CTXT; i++)
4350
0
        {
4351
            /* me ctxt */
4352
0
            me_ctxt_t *ps_mem_ctxt = &(ps_codec->as_process[i].s_me_ctxt);
4353
4354
            /* init at zero mv */
4355
0
            ps_mem_ctxt->pu1_mv_bits = pu1_buf + u4_max_srch_range;
4356
0
        }
4357
0
    }
4358
4359
0
    ps_mem_rec = &ps_mem_rec_base[MEM_REC_INTRA_COST];
4360
0
    {
4361
0
        ps_codec->pi4_mb_intra_cost = ps_mem_rec->pv_base;
4362
0
    }
4363
4364
0
    ps_mem_rec = &ps_mem_rec_base[MEM_REC_SPS];
4365
0
    {
4366
0
        ps_codec->ps_sps_base = (sps_t *) ps_mem_rec->pv_base;
4367
0
    }
4368
4369
0
    ps_mem_rec = &ps_mem_rec_base[MEM_REC_PPS];
4370
0
    {
4371
0
        ps_codec->ps_pps_base = (pps_t *) ps_mem_rec->pv_base;
4372
0
    }
4373
4374
0
    ps_mem_rec = &ps_mem_rec_base[MEM_REC_SLICE_HDR];
4375
0
    {
4376
0
        ps_codec->ps_slice_hdr_base = ps_mem_rec->pv_base;
4377
4378
0
        for (i = 0; i < MAX_PROCESS_CTXT; i++)
4379
0
        {
4380
0
            if (i < MAX_PROCESS_CTXT / MAX_CTXT_SETS)
4381
0
            {
4382
0
                ps_codec->as_process[i].ps_slice_hdr_base = ps_mem_rec->pv_base;
4383
0
            }
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
0
        }
4393
0
    }
4394
4395
0
    ps_mem_rec = &ps_mem_rec_base[MEM_REC_AIR_MAP];
4396
0
    {
4397
        /* temp var */
4398
0
        UWORD8 *pu1_buf = ps_mem_rec->pv_base;
4399
4400
0
        for (i = 0; i < MAX_PROCESS_CTXT; i++)
4401
0
        {
4402
0
            if (i < MAX_PROCESS_CTXT / MAX_CTXT_SETS)
4403
0
            {
4404
0
                ps_codec->as_process[i].pu1_is_intra_coded = pu1_buf;
4405
0
            }
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
0
        }
4412
4413
0
        ps_codec->pu2_intr_rfrsh_map = (UWORD16 *) (pu1_buf + max_mb_cnt * MAX_CTXT_SETS);
4414
0
    }
4415
4416
0
    ps_mem_rec = &ps_mem_rec_base[MEM_REC_SLICE_MAP];
4417
0
    {
4418
        /* pointer to storage space */
4419
0
        UWORD8 *pu1_buf_ping, *pu1_buf_pong;
4420
4421
        /* init pointer */
4422
0
        pu1_buf_ping = ps_mem_rec->pv_base;
4423
0
        pu1_buf_pong = pu1_buf_ping + ALIGN64(max_mb_cnt);
4424
4425
0
        for (i = 0; i < MAX_PROCESS_CTXT; i++)
4426
0
        {
4427
0
            if (i < MAX_PROCESS_CTXT / MAX_CTXT_SETS)
4428
0
            {
4429
0
                ps_codec->as_process[i].pu1_slice_idx = pu1_buf_ping;
4430
0
            }
4431
0
            else
4432
0
            {
4433
0
                ps_codec->as_process[i].pu1_slice_idx = pu1_buf_pong;
4434
0
            }
4435
0
        }
4436
0
    }
4437
4438
0
    ps_mem_rec = &ps_mem_rec_base[MEM_REC_THREAD_HANDLE];
4439
0
    {
4440
0
        UWORD8 *pu1_buf = (UWORD8 *)ps_mem_rec->pv_base;
4441
0
        WORD32 handle_size = ithread_get_handle_size();
4442
4443
0
        if (ps_ip->s_ive_ip.u4_keep_threads_active)
4444
0
        {
4445
0
            ps_codec->s_thread_pool.pv_thread_pool_mutex = (void *)pu1_buf;
4446
0
            pu1_buf += ithread_get_mutex_lock_size();
4447
4448
0
            ps_codec->s_thread_pool.pv_thread_pool_cond = (void *)pu1_buf;
4449
0
            pu1_buf += ithread_get_cond_size();
4450
0
        }
4451
4452
0
        for (i = 0; i < MAX_PROCESS_THREADS; i++)
4453
0
        {
4454
0
            ps_codec->apv_proc_thread_handle[i] = (void *)(pu1_buf + (i * handle_size));
4455
0
        }
4456
0
    }
4457
4458
0
    ps_mem_rec = &ps_mem_rec_base[MEM_REC_CTL_MUTEX];
4459
0
    {
4460
0
        ps_codec->pv_ctl_mutex = ps_mem_rec->pv_base;
4461
0
    }
4462
4463
0
    ps_mem_rec = &ps_mem_rec_base[MEM_REC_ENTROPY_MUTEX];
4464
0
    {
4465
0
        ps_codec->pv_entropy_mutex = ps_mem_rec->pv_base;
4466
0
    }
4467
4468
0
    ps_mem_rec = &ps_mem_rec_base[MEM_REC_PROC_JOBQ];
4469
0
    {
4470
0
        ps_codec->pv_proc_jobq_buf = ps_mem_rec->pv_base;
4471
0
        ps_codec->i4_proc_jobq_buf_size = ps_mem_rec->u4_mem_size;
4472
0
    }
4473
4474
0
    ps_mem_rec = &ps_mem_rec_base[MEM_REC_ENTROPY_JOBQ];
4475
0
    {
4476
0
        ps_codec->pv_entropy_jobq_buf = ps_mem_rec->pv_base;
4477
0
        ps_codec->i4_entropy_jobq_buf_size = ps_mem_rec->u4_mem_size;
4478
0
    }
4479
4480
0
    ps_mem_rec = &ps_mem_rec_base[MEM_REC_PROC_MAP];
4481
0
    {
4482
        /* pointer to storage space */
4483
0
        UWORD8 *pu1_buf = ps_mem_rec->pv_base;
4484
4485
        /* total size of the mem record */
4486
0
        WORD32 total_size = 0;
4487
4488
        /* size in bytes to mb core coding status of an entire frame */
4489
0
        total_size = max_mb_cnt;
4490
4491
        /* add an additional 1 row of bytes to evade the special case of row 0 */
4492
0
        total_size += max_mb_cols;
4493
4494
0
        for (i = 0; i < MAX_PROCESS_CTXT; i++)
4495
0
        {
4496
0
            if (i < MAX_PROCESS_CTXT / MAX_CTXT_SETS)
4497
0
            {
4498
0
                ps_codec->as_process[i].pu1_proc_map = pu1_buf + max_mb_cols;
4499
0
            }
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
0
        }
4506
0
    }
4507
4508
0
    ps_mem_rec = &ps_mem_rec_base[MEM_REC_DBLK_MAP];
4509
0
    {
4510
        /* pointer to storage space */
4511
0
        UWORD8 *pu1_buf = ps_mem_rec->pv_base;
4512
4513
        /* total size of the mem record */
4514
0
        WORD32 total_size = 0;
4515
4516
        /* size in bytes to mb core coding status of an entire frame */
4517
0
        total_size = max_mb_cnt;
4518
4519
        /* add an additional 1 row of bytes to evade the special case of row 0 */
4520
0
        total_size += max_mb_cols;
4521
4522
        /*Align the memory offsets*/
4523
0
        total_size = ALIGN64(total_size);
4524
4525
0
        for (i = 0; i < MAX_PROCESS_CTXT; i++)
4526
0
        {
4527
0
            if (i < MAX_PROCESS_CTXT / MAX_CTXT_SETS)
4528
0
            {
4529
0
                ps_codec->as_process[i].pu1_deblk_map = pu1_buf + max_mb_cols;
4530
4531
0
            }
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
0
        }
4539
0
    }
4540
4541
0
    ps_mem_rec = &ps_mem_rec_base[MEM_REC_ME_MAP];
4542
0
    {
4543
        /* pointer to storage space */
4544
0
        UWORD8 *pu1_buf = (UWORD8 *) ps_mem_rec->pv_base;
4545
4546
        /* total size of the mem record */
4547
0
        WORD32 total_size = 0;
4548
4549
        /* size in bytes to mb core coding status of an entire frame */
4550
0
        total_size = max_mb_cnt;
4551
4552
        /* add an additional 1 row of bytes to evade the special case of row 0 */
4553
0
        total_size += max_mb_cols;
4554
4555
0
        for (i = 0; i < MAX_PROCESS_CTXT; i++)
4556
0
        {
4557
0
            if (i < MAX_PROCESS_CTXT / MAX_CTXT_SETS)
4558
0
            {
4559
0
                ps_codec->as_process[i].pu1_me_map = pu1_buf + max_mb_cols;
4560
0
            }
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
0
        }
4567
0
    }
4568
4569
0
    ps_mem_rec = &ps_mem_rec_base[MEM_REC_DPB_MGR];
4570
0
    {
4571
0
        ps_codec->pv_dpb_mgr = ps_mem_rec->pv_base;
4572
0
    }
4573
4574
0
    ps_mem_rec = &ps_mem_rec_base[MEM_REC_PROC_SCRATCH];
4575
0
    {
4576
        /* pointer to storage space */
4577
0
        UWORD8 *pu1_buf = (UWORD8 *) ps_mem_rec->pv_base;
4578
4579
        /* size of pred buffer, fwd transform output, temp buffer for inv tra */
4580
0
        WORD32 size_pred_luma, size_pred_chroma, size_fwd, size_inv, size_hp;
4581
4582
        /* temp var */
4583
0
        WORD32 size = 0;
4584
4585
        /* size to hold intra/inter prediction buffer */
4586
0
        size_pred_luma = sizeof(UWORD8) * 16 * 16;
4587
0
        size_pred_chroma = sizeof(UWORD8) * 8 * 16;
4588
4589
        /* size to hold fwd transform output */
4590
0
        size_fwd = sizeof(WORD16) * SIZE_TRANS_BUFF;
4591
4592
        /* size to hold temporary data during inverse transform */
4593
0
        size_inv = sizeof(WORD32) * SIZE_TMP_BUFF_ITRANS;
4594
4595
        /* size to hold half pel plane buffers */
4596
0
        size_hp = sizeof(UWORD8) * (HP_BUFF_WD * HP_BUFF_HT);
4597
4598
0
        for (i = 0; i < MAX_PROCESS_CTXT; i++)
4599
0
        {
4600
            /* prediction buffer */
4601
0
            ps_codec->as_process[i].pu1_pred_mb = (void *) (pu1_buf + size);
4602
0
            ps_codec->as_process[i].i4_pred_strd = 16;
4603
0
            size += size_pred_luma;
4604
0
            size = ALIGN64(size);
4605
4606
            /* prediction buffer */
4607
0
            ps_codec->as_process[i].pu1_ref_mb_intra_4x4 = (void *) (pu1_buf
4608
0
                            + size);
4609
0
            size += size_pred_luma;
4610
0
            size = ALIGN64(size);
4611
4612
            /* prediction buffer intra 16x16 */
4613
0
            ps_codec->as_process[i].pu1_pred_mb_intra_16x16 = (void *) (pu1_buf
4614
0
                            + size);
4615
0
            size += size_pred_luma;
4616
0
            size = ALIGN64(size);
4617
4618
            /* prediction buffer intra 16x16 plane*/
4619
0
            ps_codec->as_process[i].pu1_pred_mb_intra_16x16_plane =
4620
0
                            (void *) (pu1_buf + size);
4621
0
            size += size_pred_luma;
4622
0
            size = ALIGN64(size);
4623
4624
            /* prediction buffer intra chroma*/
4625
0
            ps_codec->as_process[i].pu1_pred_mb_intra_chroma = (void *) (pu1_buf
4626
0
                            + size);
4627
0
            size += size_pred_chroma;
4628
0
            size = ALIGN64(size);
4629
4630
            /* prediction buffer intra chroma plane*/
4631
0
            ps_codec->as_process[i].pu1_pred_mb_intra_chroma_plane =
4632
0
                            (void *) (pu1_buf + size);
4633
0
            size += size_pred_chroma;
4634
0
            size = ALIGN64(size);
4635
4636
            /* Fwd transform output */
4637
0
            ps_codec->as_process[i].pi2_res_buf = (void *) (pu1_buf + size);
4638
0
            ps_codec->as_process[i].i4_res_strd = 16;
4639
0
            size += size_fwd;
4640
0
            size = ALIGN64(size);
4641
4642
            /* Fwd transform output */
4643
0
            ps_codec->as_process[i].pi2_res_buf_intra_4x4 = (void *) (pu1_buf
4644
0
                            + size);
4645
0
            size += size_fwd;
4646
0
            size = ALIGN64(size);
4647
4648
            /* scratch buffer used during inverse transform */
4649
0
            ps_codec->as_process[i].pv_scratch_buff = (void *) (pu1_buf + size);
4650
0
            size += size_inv;
4651
0
            size = ALIGN64(size);
4652
4653
0
            for (j = 0; j < SUBPEL_BUFF_CNT; j++)
4654
0
            {
4655
0
                ps_codec->as_process[i].apu1_subpel_buffs[j] = (pu1_buf + size);
4656
0
                size += ALIGN64(size_hp);
4657
0
            }
4658
0
        }
4659
0
    }
4660
4661
0
    ps_mem_rec = &ps_mem_rec_base[MEM_REC_QUANT_PARAM];
4662
0
    {
4663
        /* pointer to storage space */
4664
0
        UWORD8 *pu1_buf = (UWORD8 *) ps_mem_rec->pv_base;
4665
4666
        /* size of qp, threshold matrix, fwd scaling list for one plane */
4667
0
        WORD32 size_quant_param, size_thres_mat, size_fwd_weight_mat,
4668
0
                        size_satqd_weight_mat;
4669
4670
        /* temp var */
4671
0
        WORD32 total_size = 0;
4672
4673
        /* size of quantization parameter list of 1 plane */
4674
0
        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
0
        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
0
        size_fwd_weight_mat = ALIGN64(sizeof(WORD16) * 4 * 4);
4685
4686
        /* size of SATQD matrix*/
4687
0
        size_satqd_weight_mat = ALIGN64(sizeof(UWORD16) * 9);
4688
4689
0
        for (i = 0; i < MAX_PROCESS_CTXT; i++)
4690
0
        {
4691
0
            quant_params_t **ps_qp_params = ps_codec->as_process[i].ps_qp_params;
4692
4693
            /* quantization param structure */
4694
0
            ps_qp_params[0] = (quant_params_t *) (pu1_buf + total_size);
4695
0
            total_size = total_size + size_quant_param;
4696
0
            ps_qp_params[1] = (quant_params_t *) (pu1_buf + total_size);
4697
0
            total_size = total_size + size_quant_param;
4698
0
            ps_qp_params[2] = (quant_params_t *) (pu1_buf + total_size);
4699
0
            total_size = total_size + size_quant_param;
4700
4701
            /* threshold matrix for quantization */
4702
0
            ps_qp_params[0]->pu2_thres_mat = (void *) (pu1_buf + total_size);
4703
0
            total_size = total_size + size_thres_mat;
4704
0
            ps_qp_params[1]->pu2_thres_mat = (void *) (pu1_buf + total_size);
4705
0
            total_size = total_size + size_thres_mat;
4706
0
            ps_qp_params[2]->pu2_thres_mat = (void *) (pu1_buf + total_size);
4707
0
            total_size = total_size + size_thres_mat;
4708
4709
            /* fwd weight matrix */
4710
0
            ps_qp_params[0]->pu2_weigh_mat = (void *) (pu1_buf + total_size);
4711
0
            total_size = total_size + size_fwd_weight_mat;
4712
0
            ps_qp_params[1]->pu2_weigh_mat = (void *) (pu1_buf + total_size);
4713
0
            total_size = total_size + size_fwd_weight_mat;
4714
0
            ps_qp_params[2]->pu2_weigh_mat = (void *) (pu1_buf + total_size);
4715
0
            total_size = total_size + size_fwd_weight_mat;
4716
4717
            /* threshold matrix for SATQD */
4718
0
            ps_qp_params[0]->pu2_sad_thrsh = (void *) (pu1_buf + total_size);
4719
0
            total_size = total_size + size_satqd_weight_mat;
4720
0
            ps_qp_params[1]->pu2_sad_thrsh = (void *) (pu1_buf + total_size);
4721
0
            total_size = total_size + size_satqd_weight_mat;
4722
0
            ps_qp_params[2]->pu2_sad_thrsh = (void *) (pu1_buf + total_size);
4723
0
            total_size = total_size + size_satqd_weight_mat;
4724
4725
0
            total_size = ALIGN128(total_size);
4726
0
        }
4727
0
    }
4728
4729
0
    ps_mem_rec = &ps_mem_rec_base[MEM_REC_TOP_ROW_SYN_INFO];
4730
0
    {
4731
        /* total size of the mem record */
4732
0
        WORD32 total_size = 0, size_csbp, size_intra_modes, size_mv;
4733
4734
        /* pointer to buffer */
4735
0
        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
0
        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
0
        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
0
        size_mv = (max_mb_cols + 1) * sizeof(enc_pu_t);
4747
4748
        /* total size per proc ctxt */
4749
0
        total_size = size_csbp + size_intra_modes + size_mv;
4750
4751
0
        for (i = 0; i < MAX_PROCESS_CTXT; i++)
4752
0
        {
4753
0
            if (i < MAX_PROCESS_CTXT / MAX_CTXT_SETS)
4754
0
            {
4755
0
                ps_codec->as_process[i].ps_top_row_mb_syntax_ele_base =
4756
0
                                (mb_info_t *) pu1_buf;
4757
0
                ps_codec->as_process[i].pu1_top_mb_intra_modes_base = pu1_buf
4758
0
                                + size_csbp;
4759
0
                ps_codec->as_process[i].ps_top_row_pu_base =
4760
0
                                (enc_pu_t *) (pu1_buf + size_csbp
4761
0
                                                + size_intra_modes);
4762
0
            }
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
0
        }
4774
0
    }
4775
4776
0
    ps_mem_rec = &ps_mem_rec_base[MEM_REC_BS_QP];
4777
0
    {
4778
0
        UWORD8 *pu1_buf_ping, *pu1_buf_pong;
4779
4780
        /* total size of the mem record */
4781
0
        WORD32 total_size = 0;
4782
4783
        /* size in bytes to store vertical edge bs, horizontal edge bs and qp of every mb*/
4784
0
        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
0
        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
0
        horz_bs_size = ALIGN64(max_mb_cnt * 4 * 4);
4795
4796
        /* qp of each mb requires 1 byte */
4797
0
        qp_size = ALIGN64(max_mb_cnt);
4798
4799
        /* total size */
4800
0
        total_size = vert_bs_size + horz_bs_size + qp_size;
4801
4802
0
        for (i = 0; i < MAX_PROCESS_CTXT; i++)
4803
0
        {
4804
0
            if (i < MAX_PROCESS_CTXT / MAX_CTXT_SETS)
4805
0
            {
4806
0
                pu1_buf_ping = (UWORD8 *) ps_mem_rec->pv_base;
4807
4808
                /* vertical edge bs storage space */
4809
0
                ps_codec->as_process[i].s_deblk_ctxt.s_bs_ctxt.pu4_pic_vert_bs =
4810
0
                                (UWORD32 *) pu1_buf_ping;
4811
0
                pu1_buf_ping += vert_bs_size;
4812
4813
                /* horizontal edge bs storage space */
4814
0
                ps_codec->as_process[i].s_deblk_ctxt.s_bs_ctxt.pu4_pic_horz_bs =
4815
0
                                (UWORD32 *) pu1_buf_ping;
4816
0
                pu1_buf_ping += horz_bs_size;
4817
4818
                /* qp */
4819
0
                ps_codec->as_process[i].s_deblk_ctxt.s_bs_ctxt.pu1_pic_qp =
4820
0
                                (UWORD8 *) pu1_buf_ping;
4821
0
                pu1_buf_ping += qp_size;
4822
0
            }
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
0
        }
4844
0
    }
4845
4846
0
    ps_mem_rec = &ps_mem_rec_base[MEM_REC_INP_PIC];
4847
0
    {
4848
0
        ps_codec->pv_inp_buf_mgr_base = ps_mem_rec->pv_base;
4849
0
    }
4850
4851
0
    ps_mem_rec = &ps_mem_rec_base[MEM_REC_OUT];
4852
0
    {
4853
0
        ps_codec->pv_out_buf_mgr_base = ps_mem_rec->pv_base;
4854
0
    }
4855
4856
0
    ps_mem_rec = &ps_mem_rec_base[MEM_REC_CSC];
4857
0
    {
4858
0
        ps_codec->pu1_y_csc_buf_base = ps_mem_rec->pv_base;
4859
0
        ps_codec->pu1_uv_csc_buf_base = (UWORD8 *) ps_mem_rec->pv_base
4860
0
                        + (max_ht_luma * max_wd_luma);
4861
0
    }
4862
4863
0
    ps_mem_rec = &ps_mem_rec_base[MEM_REC_REF_PIC];
4864
0
    {
4865
        /* size of buf mgr struct */
4866
0
        WORD32 size = ih264_buf_mgr_size();
4867
4868
        /* temp var */
4869
0
        UWORD8 *pu1_buf = ps_mem_rec->pv_base;
4870
4871
        /* pic buffer mgr */
4872
0
        ps_codec->pv_ref_buf_mgr_base = pu1_buf;
4873
4874
        /* picture bank */
4875
0
        ps_codec->pv_pic_buf_base = pu1_buf + size;
4876
0
        ps_codec->i4_total_pic_buf_size = ps_mem_rec->u4_mem_size - size;
4877
0
    }
4878
4879
0
    ps_mem_rec = &ps_mem_rec_base[MEM_REC_MB_INFO_NMB];
4880
0
    {
4881
        /* temp var */
4882
0
        UWORD8 *pu1_buf = ps_mem_rec->pv_base;
4883
4884
        /* size of nmb ctxt */
4885
0
        WORD32 size = max_mb_cols * sizeof(mb_info_nmb_t);
4886
4887
0
        WORD32 nmb_cntr, subpel_buf_size;
4888
4889
        /* init nmb info structure pointer in all proc ctxts */
4890
0
        for (i = 0; i < MAX_PROCESS_CTXT; i++)
4891
0
        {
4892
0
            ps_codec->as_process[i].ps_nmb_info = (mb_info_nmb_t *) (pu1_buf);
4893
4894
0
            pu1_buf += size;
4895
0
        }
4896
4897
0
        subpel_buf_size = MB_SIZE * MB_SIZE * sizeof(UWORD8);
4898
4899
        /* adjusting pointers for nmb halfpel buffer */
4900
0
        for (i = 0; i < MAX_PROCESS_CTXT; i++)
4901
0
        {
4902
0
            mb_info_nmb_t* ps_mb_info_nmb =
4903
0
                            &ps_codec->as_process[i].ps_nmb_info[0];
4904
4905
0
            for (nmb_cntr = 0; nmb_cntr < max_mb_cols; nmb_cntr++)
4906
0
            {
4907
0
                ps_mb_info_nmb[nmb_cntr].pu1_best_sub_pel_buf = pu1_buf;
4908
4909
0
                pu1_buf = pu1_buf + subpel_buf_size;
4910
4911
0
                ps_mb_info_nmb[nmb_cntr].u4_bst_spel_buf_strd = MB_SIZE;
4912
0
            }
4913
0
        }
4914
0
    }
4915
4916
0
    ps_mem_rec = &ps_mem_rec_base[MEM_REC_RC];
4917
0
    {
4918
0
        ih264e_get_rate_control_mem_tab(&ps_codec->s_rate_control, ps_mem_rec,
4919
0
                                        USE_BASE);
4920
0
    }
4921
4922
    /* init codec ctxt */
4923
0
    status = ih264e_init(ps_codec);
4924
4925
0
    return status;
4926
0
}
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
0
{
4956
    /* codec ctxt */
4957
0
    codec_t *ps_codec = (codec_t *) ps_codec_obj->pv_codec_handle;
4958
4959
    /* ctrl call I/O structures */
4960
0
    ih264e_retrieve_mem_rec_ip_t *ps_ip = pv_api_ip;
4961
0
    ih264e_retrieve_mem_rec_op_t *ps_op = pv_api_op;
4962
4963
0
    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
0
    if (ps_codec->s_cfg.u4_keep_threads_active)
4971
0
    {
4972
0
        ih264e_thread_pool_shutdown(ps_codec);
4973
0
        ithread_cond_destroy(ps_codec->s_thread_pool.pv_thread_pool_cond);
4974
0
        ithread_mutex_destroy(ps_codec->s_thread_pool.pv_thread_pool_mutex);
4975
0
    }
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
0
    memcpy(ps_ip->s_ive_ip.ps_mem_rec, ps_codec->ps_mem_rec_backup,
4984
0
           MEM_REC_CNT * (sizeof(iv_mem_rec_t)));
4985
0
    ps_op->s_ive_op.u4_num_mem_rec_filled = MEM_REC_CNT;
4986
4987
    /* clean up mutex memory */
4988
0
    ih264_list_free(ps_codec->pv_entropy_jobq);
4989
0
    ih264_list_free(ps_codec->pv_proc_jobq);
4990
0
    ithread_mutex_destroy(ps_codec->pv_ctl_mutex);
4991
0
    ithread_mutex_destroy(ps_codec->pv_entropy_mutex);
4992
4993
0
    ih264_buf_mgr_free((buf_mgr_t *)ps_codec->pv_mv_buf_mgr);
4994
0
    ih264_buf_mgr_free((buf_mgr_t *)ps_codec->pv_ref_buf_mgr);
4995
0
    ih264_buf_mgr_free((buf_mgr_t *)ps_codec->pv_inp_buf_mgr);
4996
0
    ih264_buf_mgr_free((buf_mgr_t *)ps_codec->pv_out_buf_mgr);
4997
4998
0
    return IV_SUCCESS;
4999
0
}
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
0
{
5075
    /* ctrl call I/O structures */
5076
0
    ih264e_ctl_getbufinfo_ip_t *ps_ip = pv_api_ip;
5077
0
    ih264e_ctl_getbufinfo_op_t *ps_op = pv_api_op;
5078
5079
    /* temp var */
5080
0
    WORD32 wd = ALIGN16(ps_ip->s_ive_ip.u4_max_wd);
5081
0
    WORD32 ht = ALIGN16(ps_ip->s_ive_ip.u4_max_ht);
5082
0
    WORD32 i;
5083
5084
0
    UNUSED(ps_codec_obj);
5085
5086
0
    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
0
    if (ps_ip->s_ive_ip.e_inp_color_fmt == IV_YUV_420P)
5091
0
    {
5092
0
        ps_op->s_ive_op.u4_inp_comp_cnt = MIN_RAW_BUFS_420_COMP;
5093
5094
0
        ps_op->s_ive_op.au4_min_in_buf_size[0] = wd * ht;
5095
0
        ps_op->s_ive_op.au4_min_in_buf_size[1] = (wd >> 1) * (ht >> 1);
5096
0
        ps_op->s_ive_op.au4_min_in_buf_size[2] = (wd >> 1) * (ht >> 1);
5097
0
    }
5098
0
    else if (ps_ip->s_ive_ip.e_inp_color_fmt == IV_YUV_422ILE)
5099
0
    {
5100
0
        ps_op->s_ive_op.u4_inp_comp_cnt = MIN_RAW_BUFS_422ILE_COMP;
5101
5102
0
        ps_op->s_ive_op.au4_min_in_buf_size[0] = wd * ht * 2;
5103
0
        ps_op->s_ive_op.au4_min_in_buf_size[1] =
5104
0
                        ps_op->s_ive_op.au4_min_in_buf_size[2] = 0;
5105
0
    }
5106
0
    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
0
    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
0
    else if ((ps_ip->s_ive_ip.e_inp_color_fmt == IV_YUV_420SP_UV)
5123
0
                    || (ps_ip->s_ive_ip.e_inp_color_fmt == IV_YUV_420SP_VU))
5124
0
    {
5125
0
        ps_op->s_ive_op.u4_inp_comp_cnt = MIN_RAW_BUFS_420SP_COMP;
5126
5127
0
        ps_op->s_ive_op.au4_min_in_buf_size[0] = wd * ht;
5128
0
        ps_op->s_ive_op.au4_min_in_buf_size[1] = wd * (ht >> 1);
5129
0
        ps_op->s_ive_op.au4_min_in_buf_size[2] = 0;
5130
0
    }
5131
5132
    /* Number of components in output buffers required for codec  &
5133
     * Minimum sizes of each component in output buffer required */
5134
0
    ps_op->s_ive_op.u4_out_comp_cnt = MIN_BITS_BUFS_COMP;
5135
5136
0
    for (i = 0; i < (WORD32) ps_op->s_ive_op.u4_out_comp_cnt; i++)
5137
0
    {
5138
0
        ps_op->s_ive_op.au4_min_out_buf_size[i] = MAX(((wd * ht * 3) >> 1), MIN_STREAM_SIZE);
5139
0
    }
5140
5141
0
    ps_op->s_ive_op.u4_min_inp_bufs = MIN_INP_BUFS;
5142
0
    ps_op->s_ive_op.u4_min_out_bufs = MIN_OUT_BUFS;
5143
5144
0
    return IV_SUCCESS;
5145
0
}
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
0
{
5175
    /* ctrl call I/O structures */
5176
0
    ih264e_ctl_set_dimensions_ip_t *ps_ip = pv_api_ip;
5177
0
    ih264e_ctl_set_dimensions_op_t *ps_op = pv_api_op;
5178
5179
0
    ps_op->s_ive_op.u4_error_code = 0;
5180
5181
0
    ps_cfg->u4_wd = ALIGN16(ps_ip->s_ive_ip.u4_wd);
5182
0
    ps_cfg->u4_ht = ALIGN16(ps_ip->s_ive_ip.u4_ht);
5183
0
    ps_cfg->i4_wd_mbs = ps_cfg->u4_wd >> 4;
5184
0
    ps_cfg->i4_ht_mbs = ps_cfg->u4_ht >> 4;
5185
0
    ps_cfg->u4_disp_wd = ps_ip->s_ive_ip.u4_wd;
5186
0
    ps_cfg->u4_disp_ht = ps_ip->s_ive_ip.u4_ht;
5187
5188
0
    ps_cfg->u4_timestamp_high = ps_ip->s_ive_ip.u4_timestamp_high;
5189
0
    ps_cfg->u4_timestamp_low = ps_ip->s_ive_ip.u4_timestamp_low;
5190
5191
0
    return IV_SUCCESS;
5192
0
}
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
0
{
5222
    /* ctrl call I/O structures */
5223
0
    ih264e_ctl_set_frame_rate_ip_t *ps_ip = pv_api_ip;
5224
0
    ih264e_ctl_set_frame_rate_op_t *ps_op = pv_api_op;
5225
5226
0
    ps_op->s_ive_op.u4_error_code = 0;
5227
5228
0
    ps_cfg->u4_src_frame_rate = ps_ip->s_ive_ip.u4_src_frame_rate;
5229
0
    ps_cfg->u4_tgt_frame_rate = ps_ip->s_ive_ip.u4_tgt_frame_rate;
5230
5231
0
    ps_cfg->u4_timestamp_high = ps_ip->s_ive_ip.u4_timestamp_high;
5232
0
    ps_cfg->u4_timestamp_low = ps_ip->s_ive_ip.u4_timestamp_low;
5233
5234
0
    return IV_SUCCESS;
5235
0
}
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
0
{
5265
    /* ctrl call I/O structures */
5266
0
    ih264e_ctl_set_bitrate_ip_t *ps_ip = pv_api_ip;
5267
0
    ih264e_ctl_set_bitrate_op_t *ps_op = pv_api_op;
5268
5269
0
    ps_op->s_ive_op.u4_error_code = 0;
5270
5271
0
    ps_cfg->u4_target_bitrate = ps_ip->s_ive_ip.u4_target_bitrate;
5272
5273
0
    ps_cfg->u4_timestamp_high = ps_ip->s_ive_ip.u4_timestamp_high;
5274
0
    ps_cfg->u4_timestamp_low = ps_ip->s_ive_ip.u4_timestamp_low;
5275
5276
0
    return IV_SUCCESS;
5277
0
}
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
0
{
5307
    /* ctrl call I/O structures */
5308
0
    ih264e_ctl_set_frame_type_ip_t *ps_ip = pv_api_ip;
5309
0
    ih264e_ctl_set_frame_type_op_t *ps_op = pv_api_op;
5310
5311
0
    ps_op->s_ive_op.u4_error_code = 0;
5312
5313
0
    ps_cfg->e_frame_type = ps_ip->s_ive_ip.e_frame_type;
5314
5315
0
    ps_cfg->u4_timestamp_high = ps_ip->s_ive_ip.u4_timestamp_high;
5316
0
    ps_cfg->u4_timestamp_low = ps_ip->s_ive_ip.u4_timestamp_low;
5317
5318
0
    return IV_SUCCESS;
5319
0
}
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
0
{
5349
    /* ctrl call I/O structures */
5350
0
    ih264e_ctl_set_qp_ip_t *ps_set_qp_ip = pv_api_ip;
5351
0
    ih264e_ctl_set_qp_op_t *ps_set_qp_op = pv_api_op;
5352
5353
0
    ps_set_qp_op->s_ive_op.u4_error_code = 0;
5354
5355
0
    ps_cfg->u4_i_qp_max = ps_set_qp_ip->s_ive_ip.u4_i_qp_max;
5356
0
    ps_cfg->u4_i_qp_min = ps_set_qp_ip->s_ive_ip.u4_i_qp_min;
5357
0
    ps_cfg->u4_i_qp = ps_set_qp_ip->s_ive_ip.u4_i_qp;
5358
0
    ps_cfg->u4_p_qp_max = ps_set_qp_ip->s_ive_ip.u4_p_qp_max;
5359
0
    ps_cfg->u4_p_qp_min = ps_set_qp_ip->s_ive_ip.u4_p_qp_min;
5360
0
    ps_cfg->u4_p_qp = ps_set_qp_ip->s_ive_ip.u4_p_qp;
5361
0
    ps_cfg->u4_b_qp_max = ps_set_qp_ip->s_ive_ip.u4_b_qp_max;
5362
0
    ps_cfg->u4_b_qp_min = ps_set_qp_ip->s_ive_ip.u4_b_qp_min;
5363
0
    ps_cfg->u4_b_qp = ps_set_qp_ip->s_ive_ip.u4_b_qp;
5364
5365
0
    ps_cfg->u4_timestamp_high = ps_set_qp_ip->s_ive_ip.u4_timestamp_high;
5366
0
    ps_cfg->u4_timestamp_low = ps_set_qp_ip->s_ive_ip.u4_timestamp_low;
5367
5368
0
    return IV_SUCCESS;
5369
0
}
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
0
{
5399
    /* ctrl call I/O structures */
5400
0
    ih264e_ctl_set_enc_mode_ip_t *ps_ip = pv_api_ip;
5401
0
    ih264e_ctl_set_enc_mode_op_t *ps_op = pv_api_op;
5402
5403
0
    ps_op->s_ive_op.u4_error_code = 0;
5404
5405
0
    ps_cfg->e_enc_mode = ps_ip->s_ive_ip.e_enc_mode;
5406
5407
0
    ps_cfg->u4_timestamp_high = ps_ip->s_ive_ip.u4_timestamp_high;
5408
0
    ps_cfg->u4_timestamp_low = ps_ip->s_ive_ip.u4_timestamp_low;
5409
5410
0
    return IV_SUCCESS;
5411
0
}
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
0
{
5441
    /* ctrl call I/O structures */
5442
0
    ih264e_ctl_set_vbv_params_ip_t *ps_ip = pv_api_ip;
5443
0
    ih264e_ctl_set_vbv_params_op_t *ps_op = pv_api_op;
5444
5445
0
    ps_op->s_ive_op.u4_error_code = 0;
5446
5447
0
    ps_cfg->u4_vbv_buf_size = ps_ip->s_ive_ip.u4_vbv_buf_size;
5448
0
    ps_cfg->u4_vbv_buffer_delay = ps_ip->s_ive_ip.u4_vbv_buffer_delay;
5449
5450
0
    ps_cfg->u4_timestamp_high = ps_ip->s_ive_ip.u4_timestamp_high;
5451
0
    ps_cfg->u4_timestamp_low = ps_ip->s_ive_ip.u4_timestamp_low;
5452
5453
0
    return IV_SUCCESS;
5454
0
}
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
0
{
5484
    /* ctrl call I/O structures */
5485
0
    ih264e_ctl_set_air_params_ip_t *ps_ip = pv_api_ip;
5486
0
    ih264e_ctl_set_air_params_op_t *ps_op = pv_api_op;
5487
5488
0
    ps_op->s_ive_op.u4_error_code = 0;
5489
5490
0
    ps_cfg->e_air_mode = ps_ip->s_ive_ip.e_air_mode;
5491
0
    ps_cfg->u4_air_refresh_period = ps_ip->s_ive_ip.u4_air_refresh_period;
5492
5493
0
    ps_cfg->u4_timestamp_high = ps_ip->s_ive_ip.u4_timestamp_high;
5494
0
    ps_cfg->u4_timestamp_low = ps_ip->s_ive_ip.u4_timestamp_low;
5495
5496
0
    return IV_SUCCESS;
5497
0
}
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
0
{
5527
    /* ctrl call I/O structures */
5528
0
    ih264e_ctl_set_me_params_ip_t *ps_ip = pv_api_ip;
5529
0
    ih264e_ctl_set_me_params_op_t *ps_op = pv_api_op;
5530
5531
0
    ps_op->s_ive_op.u4_error_code = 0;
5532
5533
0
    ps_cfg->u4_enable_hpel = ps_ip->s_ive_ip.u4_enable_hpel;
5534
0
    ps_cfg->u4_enable_qpel = ps_ip->s_ive_ip.u4_enable_qpel;
5535
0
    ps_cfg->u4_enable_fast_sad = ps_ip->s_ive_ip.u4_enable_fast_sad;
5536
0
    ps_cfg->u4_enable_alt_ref = ps_ip->s_ive_ip.u4_enable_alt_ref;
5537
0
    ps_cfg->u4_srch_rng_x = ps_ip->s_ive_ip.u4_srch_rng_x;
5538
0
    ps_cfg->u4_srch_rng_y = ps_ip->s_ive_ip.u4_srch_rng_y;
5539
0
    ps_cfg->u4_me_speed_preset = ps_ip->s_ive_ip.u4_me_speed_preset;
5540
5541
0
    ps_cfg->u4_timestamp_high = ps_ip->s_ive_ip.u4_timestamp_high;
5542
0
    ps_cfg->u4_timestamp_low = ps_ip->s_ive_ip.u4_timestamp_low;
5543
5544
0
    return IV_SUCCESS;
5545
0
}
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
0
{
5575
    /* ctrl call I/O structures */
5576
0
    ih264e_ctl_set_ipe_params_ip_t *ps_ip = pv_api_ip;
5577
0
    ih264e_ctl_set_ipe_params_op_t *ps_op = pv_api_op;
5578
5579
0
    ps_op->s_ive_op.u4_error_code = 0;
5580
5581
0
    ps_cfg->u4_enable_intra_4x4 = ps_ip->s_ive_ip.u4_enable_intra_4x4;
5582
0
    ps_cfg->u4_enc_speed_preset = ps_ip->s_ive_ip.u4_enc_speed_preset;
5583
0
    ps_cfg->u4_constrained_intra_pred = ps_ip->s_ive_ip.u4_constrained_intra_pred;
5584
5585
0
    ps_cfg->u4_timestamp_high = ps_ip->s_ive_ip.u4_timestamp_high;
5586
0
    ps_cfg->u4_timestamp_low = ps_ip->s_ive_ip.u4_timestamp_low;
5587
5588
0
    return IV_SUCCESS;
5589
0
}
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
0
{
5619
    /* ctrl call I/O structures */
5620
0
    ih264e_ctl_set_gop_params_ip_t *ps_ip = pv_api_ip;
5621
0
    ih264e_ctl_set_gop_params_op_t *ps_op = pv_api_op;
5622
5623
0
    ps_op->s_ive_op.u4_error_code = 0;
5624
5625
0
    ps_cfg->u4_i_frm_interval = ps_ip->s_ive_ip.u4_i_frm_interval;
5626
0
    ps_cfg->u4_idr_frm_interval = ps_ip->s_ive_ip.u4_idr_frm_interval;
5627
0
    if (ps_cfg->u4_idr_frm_interval < ps_cfg->u4_i_frm_interval)
5628
0
        ps_cfg->u4_i_frm_interval = ps_cfg->u4_idr_frm_interval;
5629
5630
0
    ps_cfg->u4_timestamp_high = ps_ip->s_ive_ip.u4_timestamp_high;
5631
0
    ps_cfg->u4_timestamp_low = ps_ip->s_ive_ip.u4_timestamp_low;
5632
5633
0
    return IV_SUCCESS;
5634
0
}
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
0
{
5664
    /* ctrl call I/O structures */
5665
0
    ih264e_ctl_set_profile_params_ip_t *ps_ip = pv_api_ip;
5666
0
    ih264e_ctl_set_profile_params_op_t *ps_op = pv_api_op;
5667
5668
0
    ps_op->s_ive_op.u4_error_code = 0;
5669
5670
0
    ps_cfg->e_profile = ps_ip->s_ive_ip.e_profile;
5671
0
    ps_cfg->u4_entropy_coding_mode = ps_ip->s_ive_ip.u4_entropy_coding_mode;
5672
5673
0
    ps_cfg->u4_timestamp_high = ps_ip->s_ive_ip.u4_timestamp_high;
5674
0
    ps_cfg->u4_timestamp_low = ps_ip->s_ive_ip.u4_timestamp_low;
5675
5676
0
    return IV_SUCCESS;
5677
0
}
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
0
{
5709
    /* ctrl call I/O structures */
5710
0
    ih264e_ctl_set_deblock_params_ip_t *ps_ip = pv_api_ip;
5711
0
    ih264e_ctl_set_deblock_params_op_t *ps_op = pv_api_op;
5712
5713
0
    ps_op->s_ive_op.u4_error_code = 0;
5714
5715
0
    ps_cfg->u4_disable_deblock_level = ps_ip->s_ive_ip.u4_disable_deblock_level;
5716
5717
0
    ps_cfg->u4_timestamp_high = ps_ip->s_ive_ip.u4_timestamp_high;
5718
0
    ps_cfg->u4_timestamp_low = ps_ip->s_ive_ip.u4_timestamp_low;
5719
5720
0
    return IV_SUCCESS;
5721
0
}
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
0
{
5750
    /* ctrl call I/O structures */
5751
0
    ih264e_vui_ip_t *ps_ip = pv_api_ip;
5752
0
    ih264e_vui_op_t *ps_op = pv_api_op;
5753
0
    vui_t *ps_vui = &ps_cfg->s_vui;
5754
5755
0
    ps_op->u4_error_code = 0;
5756
5757
0
    ps_vui->u1_aspect_ratio_info_present_flag = ps_ip->u1_aspect_ratio_info_present_flag;
5758
0
    ps_vui->u1_aspect_ratio_idc = ps_ip->u1_aspect_ratio_idc;
5759
0
    ps_vui->u2_sar_width = ps_ip->u2_sar_width;
5760
0
    ps_vui->u2_sar_height = ps_ip->u2_sar_height;
5761
0
    ps_vui->u1_overscan_info_present_flag = ps_ip->u1_overscan_info_present_flag;
5762
0
    ps_vui->u1_overscan_appropriate_flag = ps_ip->u1_overscan_appropriate_flag;
5763
0
    ps_vui->u1_video_signal_type_present_flag = ps_ip->u1_video_signal_type_present_flag;
5764
0
    ps_vui->u1_video_format = ps_ip->u1_video_format;
5765
0
    ps_vui->u1_video_full_range_flag = ps_ip->u1_video_full_range_flag;
5766
0
    ps_vui->u1_colour_description_present_flag = ps_ip->u1_colour_description_present_flag;
5767
0
    ps_vui->u1_colour_primaries = ps_ip->u1_colour_primaries;
5768
0
    ps_vui->u1_transfer_characteristics = ps_ip->u1_transfer_characteristics;
5769
0
    ps_vui->u1_matrix_coefficients = ps_ip->u1_matrix_coefficients;
5770
0
    ps_vui->u1_chroma_loc_info_present_flag = ps_ip->u1_chroma_loc_info_present_flag;
5771
0
    ps_vui->u1_chroma_sample_loc_type_top_field = ps_ip->u1_chroma_sample_loc_type_top_field;
5772
0
    ps_vui->u1_chroma_sample_loc_type_bottom_field = ps_ip->u1_chroma_sample_loc_type_bottom_field;
5773
0
    ps_vui->u1_vui_timing_info_present_flag = ps_ip->u1_vui_timing_info_present_flag;
5774
0
    ps_vui->u4_vui_num_units_in_tick = ps_ip->u4_vui_num_units_in_tick;
5775
0
    ps_vui->u4_vui_time_scale = ps_ip->u4_vui_time_scale;
5776
0
    ps_vui->u1_fixed_frame_rate_flag = ps_ip->u1_fixed_frame_rate_flag;
5777
0
    ps_vui->u1_nal_hrd_parameters_present_flag = ps_ip->u1_nal_hrd_parameters_present_flag;
5778
0
    ps_vui->u1_vcl_hrd_parameters_present_flag = ps_ip->u1_vcl_hrd_parameters_present_flag;
5779
0
    ps_vui->u1_low_delay_hrd_flag = ps_ip->u1_low_delay_hrd_flag;
5780
0
    ps_vui->u1_pic_struct_present_flag = ps_ip->u1_pic_struct_present_flag;
5781
0
    ps_vui->u1_bitstream_restriction_flag = ps_ip->u1_bitstream_restriction_flag;
5782
0
    ps_vui->u1_motion_vectors_over_pic_boundaries_flag = ps_ip->u1_motion_vectors_over_pic_boundaries_flag;
5783
0
    ps_vui->u1_max_bytes_per_pic_denom = ps_ip->u1_max_bytes_per_pic_denom;
5784
0
    ps_vui->u1_max_bits_per_mb_denom = ps_ip->u1_max_bits_per_mb_denom;
5785
0
    ps_vui->u1_log2_max_mv_length_horizontal = ps_ip->u1_log2_max_mv_length_horizontal;
5786
0
    ps_vui->u1_log2_max_mv_length_vertical = ps_ip->u1_log2_max_mv_length_vertical;
5787
0
    ps_vui->u1_num_reorder_frames = ps_ip->u1_num_reorder_frames;
5788
0
    ps_vui->u1_max_dec_frame_buffering = ps_ip->u1_max_dec_frame_buffering;
5789
5790
0
    ps_cfg->u4_timestamp_high = -1;
5791
0
    ps_cfg->u4_timestamp_low = -1;
5792
5793
0
    return IV_SUCCESS;
5794
0
}
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
0
{
5824
0
    WORD32 i4_count;
5825
    /* ctrl call I/O structures */
5826
0
    ih264e_ctl_set_sei_mdcv_params_ip_t *ps_ip = pv_api_ip;
5827
0
    ih264e_ctl_set_sei_mdcv_params_op_t *ps_op = pv_api_op;
5828
0
    sei_params_t *ps_sei = &ps_cfg->s_sei;
5829
5830
0
    ps_op->u4_error_code = 0;
5831
5832
0
    ps_sei->u1_sei_mdcv_params_present_flag = ps_ip->u1_sei_mdcv_params_present_flag;
5833
0
    for(i4_count = 0; i4_count < NUM_SEI_MDCV_PRIMARIES; i4_count++)
5834
0
    {
5835
0
        ps_sei->s_sei_mdcv_params.au2_display_primaries_x[i4_count] =
5836
0
                                                ps_ip->au2_display_primaries_x[i4_count];
5837
0
        ps_sei->s_sei_mdcv_params.au2_display_primaries_y[i4_count] =
5838
0
                                                ps_ip->au2_display_primaries_y[i4_count];
5839
0
    }
5840
5841
0
    ps_sei->s_sei_mdcv_params.u2_white_point_x = ps_ip->u2_white_point_x;
5842
0
    ps_sei->s_sei_mdcv_params.u2_white_point_y = ps_ip->u2_white_point_y;
5843
0
    ps_sei->s_sei_mdcv_params.u4_max_display_mastering_luminance =
5844
0
                                                ps_ip->u4_max_display_mastering_luminance;
5845
0
    ps_sei->s_sei_mdcv_params.u4_min_display_mastering_luminance =
5846
0
                                                ps_ip->u4_min_display_mastering_luminance;
5847
5848
0
    ps_cfg->u4_timestamp_high = ps_ip->u4_timestamp_high;
5849
0
    ps_cfg->u4_timestamp_low = ps_ip->u4_timestamp_low;
5850
5851
0
    return IV_SUCCESS;
5852
0
}
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
0
{
5882
    /* ctrl call I/O structures */
5883
0
    ih264e_ctl_set_sei_cll_params_ip_t *ps_ip = pv_api_ip;
5884
0
    ih264e_ctl_set_sei_cll_params_op_t *ps_op = pv_api_op;
5885
0
    sei_params_t *ps_sei = &ps_cfg->s_sei;
5886
5887
0
    ps_op->u4_error_code = 0;
5888
5889
0
    ps_sei->u1_sei_cll_params_present_flag = ps_ip->u1_sei_cll_params_present_flag;
5890
5891
0
    ps_sei->s_sei_cll_params.u2_max_content_light_level = ps_ip->u2_max_content_light_level;
5892
0
    ps_sei->s_sei_cll_params.u2_max_pic_average_light_level =
5893
0
                                                ps_ip->u2_max_pic_average_light_level;
5894
5895
0
    ps_cfg->u4_timestamp_high = ps_ip->u4_timestamp_high;
5896
0
    ps_cfg->u4_timestamp_low = ps_ip->u4_timestamp_low;
5897
5898
0
    return IV_SUCCESS;
5899
0
}
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
0
{
5929
    /* ctrl call I/O structures */
5930
0
    ih264e_ctl_set_sei_ave_params_ip_t *ps_ip = pv_api_ip;
5931
0
    ih264e_ctl_set_sei_ave_params_op_t *ps_op = pv_api_op;
5932
0
    sei_params_t *ps_sei = &ps_cfg->s_sei;
5933
5934
0
    ps_op->u4_error_code = 0;
5935
5936
0
    ps_sei->u1_sei_ave_params_present_flag = ps_ip->u1_sei_ave_params_present_flag;
5937
5938
0
    ps_sei->s_sei_ave_params.u4_ambient_illuminance = ps_ip->u4_ambient_illuminance;
5939
0
    ps_sei->s_sei_ave_params.u2_ambient_light_x = ps_ip->u2_ambient_light_x;
5940
0
    ps_sei->s_sei_ave_params.u2_ambient_light_y = ps_ip->u2_ambient_light_y;
5941
5942
0
    ps_cfg->u4_timestamp_high = ps_ip->u4_timestamp_high;
5943
0
    ps_cfg->u4_timestamp_low = ps_ip->u4_timestamp_low;
5944
5945
0
    return IV_SUCCESS;
5946
0
}
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
0
{
5976
0
    WORD32 i4_count;
5977
    /* ctrl call I/O structures */
5978
0
    ih264e_ctl_set_sei_ccv_params_ip_t *ps_ip = pv_api_ip;
5979
0
    ih264e_ctl_set_sei_ccv_params_op_t *ps_op = pv_api_op;
5980
0
    sei_params_t *ps_sei = &ps_cfg->s_sei;
5981
5982
0
    ps_op->u4_error_code = 0;
5983
5984
0
    ps_sei->u1_sei_ccv_params_present_flag = ps_ip->u1_sei_ccv_params_present_flag;
5985
5986
0
    ps_sei->s_sei_ccv_params.u1_ccv_cancel_flag = ps_ip->u1_ccv_cancel_flag;
5987
0
    ps_sei->s_sei_ccv_params.u1_ccv_persistence_flag = ps_ip->u1_ccv_persistence_flag;
5988
0
    ps_sei->s_sei_ccv_params.u1_ccv_primaries_present_flag =
5989
0
                                                ps_ip->u1_ccv_primaries_present_flag;
5990
0
    ps_sei->s_sei_ccv_params.u1_ccv_min_luminance_value_present_flag =
5991
0
                                                ps_ip->u1_ccv_min_luminance_value_present_flag;
5992
0
    ps_sei->s_sei_ccv_params.u1_ccv_max_luminance_value_present_flag =
5993
0
                                                ps_ip->u1_ccv_max_luminance_value_present_flag;
5994
0
    ps_sei->s_sei_ccv_params.u1_ccv_avg_luminance_value_present_flag =
5995
0
                                                ps_ip->u1_ccv_avg_luminance_value_present_flag;
5996
0
    ps_sei->s_sei_ccv_params.u1_ccv_reserved_zero_2bits =
5997
0
                                                ps_ip->u1_ccv_reserved_zero_2bits;
5998
5999
0
    for(i4_count = 0; i4_count < NUM_SEI_CCV_PRIMARIES; i4_count++)
6000
0
    {
6001
0
        ps_sei->s_sei_ccv_params.ai4_ccv_primaries_x[i4_count] =
6002
0
                                                ps_ip->ai4_ccv_primaries_x[i4_count];
6003
0
        ps_sei->s_sei_ccv_params.ai4_ccv_primaries_y[i4_count] =
6004
0
                                                ps_ip->ai4_ccv_primaries_y[i4_count];
6005
0
    }
6006
6007
0
    ps_sei->s_sei_ccv_params.u4_ccv_min_luminance_value = ps_ip->u4_ccv_min_luminance_value;
6008
0
    ps_sei->s_sei_ccv_params.u4_ccv_max_luminance_value = ps_ip->u4_ccv_max_luminance_value;
6009
0
    ps_sei->s_sei_ccv_params.u4_ccv_avg_luminance_value = ps_ip->u4_ccv_avg_luminance_value;
6010
6011
0
    ps_cfg->u4_timestamp_high = ps_ip->u4_timestamp_high;
6012
0
    ps_cfg->u4_timestamp_low = ps_ip->u4_timestamp_low;
6013
6014
0
    return IV_SUCCESS;
6015
0
}
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
0
{
6043
    /* ctrl call I/O structures */
6044
0
    ih264e_ctl_set_sei_sii_params_ip_t *ps_ip = pv_api_ip;
6045
0
    ih264e_ctl_set_sei_sii_params_op_t *ps_op = pv_api_op;
6046
0
    sei_params_t *ps_sei = &ps_cfg->s_sei;
6047
6048
0
    ps_op->u4_error_code = 0;
6049
0
    ps_sei->u1_sei_sii_params_present_flag = ps_ip->u1_shutter_interval_info_present_flag;
6050
0
    ps_sei->s_sei_sii_params.u4_sii_sub_layer_idx = ps_ip->u4_sii_sub_layer_idx;
6051
6052
0
    if(0 == ps_sei->s_sei_sii_params.u4_sii_sub_layer_idx)
6053
0
    {
6054
0
        ps_sei->s_sei_sii_params.u1_shutter_interval_info_present_flag =
6055
0
            ps_ip->u1_shutter_interval_info_present_flag;
6056
6057
0
        if(1 == ps_sei->s_sei_sii_params.u1_shutter_interval_info_present_flag)
6058
0
        {
6059
0
            ps_sei->s_sei_sii_params.u4_sii_time_scale = ps_ip->u4_sii_time_scale;
6060
0
            ps_sei->s_sei_sii_params.u1_fixed_shutter_interval_within_cvs_flag =
6061
0
                ps_ip->u1_fixed_shutter_interval_within_cvs_flag;
6062
6063
0
            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
0
            else
6069
0
            {
6070
0
                int i;
6071
0
                ps_sei->s_sei_sii_params.u1_sii_max_sub_layers_minus1 =
6072
0
                    ps_ip->u1_sii_max_sub_layers_minus1;
6073
6074
0
                for(i = 0; i <= ps_ip->u1_sii_max_sub_layers_minus1; i++)
6075
0
                {
6076
0
                    ps_sei->s_sei_sii_params.au4_sub_layer_num_units_in_shutter_interval[i] =
6077
0
                        ps_ip->au4_sub_layer_num_units_in_shutter_interval[i];
6078
0
                }
6079
0
            }
6080
0
        }
6081
0
    }
6082
6083
0
    ps_cfg->u4_timestamp_high = ps_ip->u4_timestamp_high;
6084
0
    ps_cfg->u4_timestamp_low = ps_ip->u4_timestamp_low;
6085
6086
0
    return IV_SUCCESS;
6087
0
}
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
0
{
6117
    /* ctrl call I/O structures */
6118
0
    ih264e_ctl_set_num_cores_ip_t *ps_ip = pv_api_ip;
6119
0
    ih264e_ctl_set_num_cores_op_t *ps_op = pv_api_op;
6120
6121
0
    ps_op->s_ive_op.u4_error_code = 0;
6122
6123
0
    ps_cfg->u4_num_cores = MIN(ps_ip->s_ive_ip.u4_num_cores, MAX_PROCESS_THREADS);
6124
6125
0
    ps_cfg->u4_timestamp_high = ps_ip->s_ive_ip.u4_timestamp_high;
6126
0
    ps_cfg->u4_timestamp_low = ps_ip->s_ive_ip.u4_timestamp_low;
6127
6128
0
    return IV_SUCCESS;
6129
0
}
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
0
{
6214
    /* codec ctxt */
6215
0
    codec_t *ps_codec = (codec_t *) ps_codec_obj->pv_codec_handle;
6216
6217
    /* ctrl call I/O structures */
6218
0
    ih264e_ctl_setdefault_ip_t *ps_ctl_ip = pv_api_ip;
6219
0
    ih264e_ctl_setdefault_op_t *ps_ctl_op = pv_api_op;
6220
6221
    /* ctrl call sub cmd */
6222
0
    IVE_CONTROL_API_COMMAND_TYPE_T sub_cmd = ps_ctl_ip->s_ive_ip.e_sub_cmd;
6223
6224
    /* error status */
6225
0
    IV_STATUS_T ret = IV_SUCCESS;
6226
6227
    /* temp var */
6228
0
    WORD32 i;
6229
0
    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
0
    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
0
    ithread_mutex_lock(ps_codec->pv_ctl_mutex);
6242
6243
    /* find a free config param set to hold current parameters */
6244
0
    for (i = 0; i < MAX_ACTIVE_CONFIG_PARAMS; i++)
6245
0
    {
6246
0
        if (0 == ps_codec->as_cfg[i].u4_is_valid)
6247
0
        {
6248
0
            ps_cfg = &ps_codec->as_cfg[i];
6249
0
            break;
6250
0
        }
6251
0
    }
6252
6253
    /* If all are invalid, then start overwriting from the head config params */
6254
0
    if (NULL == ps_cfg)
6255
0
    {
6256
0
        ps_cfg = &ps_codec->as_cfg[0];
6257
0
    }
6258
6259
0
    ps_cfg->u4_is_valid = 1;
6260
6261
0
    ps_cfg->e_cmd = sub_cmd;
6262
6263
0
    switch (sub_cmd)
6264
0
    {
6265
0
        case IVE_CMD_CTL_SET_DIMENSIONS:
6266
0
            ret = ih264e_set_dimensions(pv_api_ip, pv_api_op, ps_cfg);
6267
0
            break;
6268
6269
0
        case IVE_CMD_CTL_SET_FRAMERATE:
6270
0
            ret = ih264e_set_frame_rate(pv_api_ip, pv_api_op, ps_cfg);
6271
0
            break;
6272
6273
0
        case IVE_CMD_CTL_SET_BITRATE:
6274
0
            ret = ih264e_set_bit_rate(pv_api_ip, pv_api_op, ps_cfg);
6275
0
            break;
6276
6277
0
        case IVE_CMD_CTL_SET_FRAMETYPE:
6278
0
            ret = ih264e_set_frame_type(pv_api_ip, pv_api_op, ps_cfg);
6279
0
            break;
6280
6281
0
        case IVE_CMD_CTL_SET_QP:
6282
0
            ret = ih264e_set_qp(pv_api_ip, pv_api_op, ps_cfg);
6283
0
            break;
6284
6285
0
        case IVE_CMD_CTL_SET_ENC_MODE:
6286
0
            ret = ih264e_set_enc_mode(pv_api_ip, pv_api_op, ps_cfg);
6287
0
            break;
6288
6289
0
        case IVE_CMD_CTL_SET_VBV_PARAMS:
6290
0
            ret = ih264e_set_vbv_params(pv_api_ip, pv_api_op, ps_cfg);
6291
0
            break;
6292
6293
0
        case IVE_CMD_CTL_SET_AIR_PARAMS:
6294
0
            ret = ih264_set_air_params(pv_api_ip, pv_api_op, ps_cfg);
6295
0
            break;
6296
6297
0
        case IVE_CMD_CTL_SET_ME_PARAMS:
6298
0
            ret = ih264_set_me_params(pv_api_ip, pv_api_op, ps_cfg);
6299
0
            break;
6300
6301
0
        case IVE_CMD_CTL_SET_IPE_PARAMS:
6302
0
            ret = ih264_set_ipe_params(pv_api_ip, pv_api_op, ps_cfg);
6303
0
            break;
6304
6305
0
        case IVE_CMD_CTL_SET_GOP_PARAMS:
6306
0
            ret = ih264_set_gop_params(pv_api_ip, pv_api_op, ps_cfg);
6307
0
            break;
6308
6309
0
        case IVE_CMD_CTL_SET_PROFILE_PARAMS:
6310
0
            ret = ih264_set_profile_params(pv_api_ip, pv_api_op, ps_cfg);
6311
0
            break;
6312
6313
0
        case IVE_CMD_CTL_SET_DEBLOCK_PARAMS:
6314
0
            ret = ih264_set_deblock_params(pv_api_ip, pv_api_op, ps_cfg);
6315
0
            break;
6316
6317
0
        case IVE_CMD_CTL_SET_VUI_PARAMS:
6318
0
            ret = ih264e_set_vui_params(pv_api_ip, pv_api_op, ps_cfg);
6319
0
            break;
6320
6321
0
        case IVE_CMD_CTL_SET_SEI_MDCV_PARAMS:
6322
0
            ret = ih264e_set_sei_mdcv_params(pv_api_ip, pv_api_op, ps_cfg);
6323
0
            break;
6324
6325
0
        case IVE_CMD_CTL_SET_SEI_CLL_PARAMS:
6326
0
            ret = ih264e_set_sei_cll_params(pv_api_ip, pv_api_op, ps_cfg);
6327
0
            break;
6328
6329
0
        case IVE_CMD_CTL_SET_SEI_AVE_PARAMS:
6330
0
            ret = ih264e_set_sei_ave_params(pv_api_ip, pv_api_op, ps_cfg);
6331
0
            break;
6332
6333
0
        case IVE_CMD_CTL_SET_SEI_CCV_PARAMS:
6334
0
            ret = ih264e_set_sei_ccv_params(pv_api_ip, pv_api_op, ps_cfg);
6335
0
            break;
6336
6337
0
        case IVE_CMD_CTL_SET_SEI_SII_PARAMS:
6338
0
            ret = ih264e_set_sei_sii_params(pv_api_ip, pv_api_op, ps_cfg);
6339
0
            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
0
        case IVE_CMD_CTL_SETDEFAULT:
6350
0
        {
6351
            /* ctrl call I/O structures */
6352
0
            ih264e_ctl_setdefault_op_t *ps_op = pv_api_op;
6353
6354
            /* invalidate config param struct as it is being served right away */
6355
0
            ps_codec->as_cfg[i].u4_is_valid = 0;
6356
6357
            /* error status */
6358
0
            ret = ih264e_set_default_params(ps_cfg);
6359
6360
0
            ps_op->s_ive_op.u4_error_code = ret;
6361
6362
0
            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
0
        case IVE_CMD_CTL_GETBUFINFO:
6374
6375
            /* invalidate config param struct as it is being served right away */
6376
0
            ps_codec->as_cfg[i].u4_is_valid = 0;
6377
6378
0
            ret = ih264e_get_buf_info(ps_codec_obj, pv_api_ip, pv_api_op);
6379
0
            break;
6380
6381
0
        case IVE_CMD_CTL_GETVERSION:
6382
0
        {
6383
            /* ctrl call I/O structures */
6384
0
            ih264e_ctl_getversioninfo_ip_t *ps_ip = pv_api_ip;
6385
0
            ih264e_ctl_getversioninfo_op_t *ps_op = pv_api_op;
6386
6387
            /* invalidate config param struct as it is being served right away */
6388
0
            ps_codec->as_cfg[i].u4_is_valid = 0;
6389
6390
            /* error status */
6391
0
            ps_op->s_ive_op.u4_error_code = IV_SUCCESS;
6392
6393
0
            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
0
            else
6400
0
            {
6401
0
                ret = ih264e_get_version((CHAR *) ps_ip->s_ive_ip.pu1_version,
6402
0
                                         ps_ip->s_ive_ip.u4_version_bufsize);
6403
6404
0
                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
0
            }
6411
0
            break;
6412
0
        }
6413
6414
0
        case IVE_CMD_CTL_SET_NUM_CORES:
6415
0
            ret = ih264e_set_num_cores(pv_api_ip, pv_api_op, ps_cfg);
6416
0
            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
0
    }
6425
6426
0
    ithread_mutex_unlock(ps_codec->pv_ctl_mutex);
6427
6428
0
    return ret;
6429
0
}
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
0
{
6461
    /* api command */
6462
0
    WORD32 command = IV_CMD_NA;
6463
6464
    /* error status */
6465
0
    IV_STATUS_T e_status;
6466
0
    WORD32 ret;
6467
6468
    /* tmp var */
6469
0
    WORD32 *pu4_ptr_cmd = (WORD32 *) pv_api_ip;
6470
6471
    /* validate input / output structures */
6472
0
    e_status = api_check_struct_sanity(ps_handle, pv_api_ip, pv_api_op);
6473
6474
0
    if (e_status != IV_SUCCESS)
6475
0
    {
6476
0
        DEBUG("error code = %d\n", *((UWORD32 *)pv_api_op + 1));
6477
0
        return IV_FAIL;
6478
0
    }
6479
6480
0
    pu4_ptr_cmd++;
6481
6482
0
    command = *pu4_ptr_cmd;
6483
6484
0
    switch (command)
6485
0
    {
6486
0
        case IV_CMD_GET_NUM_MEM_REC:
6487
0
            ret = ih264e_get_num_rec(pv_api_ip, pv_api_op);
6488
0
            break;
6489
6490
0
        case IV_CMD_FILL_NUM_MEM_REC:
6491
0
            ret = ih264e_fill_num_mem_rec(pv_api_ip, pv_api_op);
6492
0
            break;
6493
6494
0
        case IV_CMD_INIT:
6495
0
            ret = ih264e_init_mem_rec(ps_handle, pv_api_ip, pv_api_op);
6496
0
            break;
6497
6498
0
        case IV_CMD_RETRIEVE_MEMREC:
6499
0
            ret = ih264e_retrieve_memrec(ps_handle, pv_api_ip, pv_api_op);
6500
0
            break;
6501
6502
0
        case IVE_CMD_VIDEO_CTL:
6503
0
            ret = ih264e_ctl(ps_handle, pv_api_ip, pv_api_op);
6504
0
            break;
6505
6506
0
        case IVE_CMD_VIDEO_ENCODE:
6507
0
            ret = ih264e_encode(ps_handle, pv_api_ip, pv_api_op);
6508
0
            break;
6509
6510
0
        default:
6511
0
            ret = IV_FAIL;
6512
0
            break;
6513
0
    }
6514
6515
0
    return (IV_STATUS_T) ret;
6516
0
}