lin
2025-08-01 633231e833e21d5b8b1c00cb15aedb62b3b78e8f
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
/******************************************************************************
 *
 * Copyright (C) 2018 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at:
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 *****************************************************************************
 * Originally developed and contributed by Ittiam Systems Pvt. Ltd, Bangalore
*/
/*!
******************************************************************************
* \file ihevce_hle_interface.h
*
* \brief
*    This file contains infertace prototypes of High level enocder interafce
*    structure and interface functions.
*
* \date
*    18/09/2012
*
* \author
*    Ittiam
*
******************************************************************************
*/
 
#ifndef _IHEVCE_HLE_INTERFACE_H_
#define _IHEVCE_HLE_INTERFACE_H_
 
#include "ihevce_profile.h"
 
/*****************************************************************************/
/* Constant Macros                                                           */
/*****************************************************************************/
#define IHEVCE_DLL
 
#define DUMP_MBR_MULTI_RES_INFO 0
 
#define DUMP_RC_2_PASS_DATA_BINARY_APP 1
/*print attributes */
 
/*print everything on console */
#define PRINTF(v, x, y, ...) ps_sys_api->ihevce_printf(v, __VA_ARGS__)
 
#define FPRINTF(v, fp, x, y, ...)                                                                  \
    if(NULL != fp)                                                                                 \
    {                                                                                              \
        ps_sys_api->s_file_io_api.ihevce_fprintf(v, fp, __VA_ARGS__);                              \
    }
 
/* Semaphore attribute */
#define SEM_START_VALUE 1
#define THREAD_STACK_SIZE 0x80000
 
/*****************************************************************************/
/* Function Macros                                                           */
/*****************************************************************************/
 
/*****************************************************************************/
/* Typedefs                                                                  */
/*****************************************************************************/
 
/*****************************************************************************/
/* Enums                                                                     */
/*****************************************************************************/
typedef enum
{
    BUFF_QUE_NON_BLOCKING_MODE = 0,
 
    BUFF_QUE_BLOCKING_MODE
 
} BUFF_QUE_MODES_T;
 
/*****************************************************************************/
/* Structure                                                                 */
/*****************************************************************************/
/**
 *  @brief  Structure to describe Process interface parameters of Encoder
 */
typedef struct
{
    /**
     * Size for version tracking purpose
     */
    WORD32 i4_size;
 
    /**
     * Flag to communicate that HLE thread int are done
     */
    WORD32 i4_hle_init_done;
 
    /**
     * Error code communciate any error during create stage
     */
    WORD32 i4_error_code;
 
    /**
    * GPU memory accumalator
    */
    WORD32 i4_gpu_mem_size;
 
    /**
     *  OSAL handle
     */
    void *pv_osal_handle;
 
    /**
     * Encoder Handle
     */
    void *apv_enc_hdl[IHEVCE_MAX_NUM_RESOLUTIONS];
 
    /**
     *  Static parameters structure
     */
    ihevce_static_cfg_params_t *ps_static_cfg_prms;
 
    /**
     * Memory Manager handle
     */
    void *pv_mem_mgr_hdl;
 
    /**
     *  Input Buffer callback handle
     */
    void *pv_inp_cb_handle;
 
    /**
     *  Ouput Buffer callback handle
     */
    void *pv_out_cb_handle;
 
    /**
     *  Ouput Recon Buffer callback handle
     */
    void *pv_recon_cb_handle;
 
    /**
     * Call back API to be called while the buffer for bitstream filling is done
     */
    IV_API_CALL_STATUS_T (*ihevce_output_strm_fill_done)
    (void *pv_out_cb_handle, void *pv_curr_out, WORD32 i4_bitrate_instance, WORD32 i4_res_instance);
 
    /**
     * Call back API to be called while the buffer for recon filling is done
     */
    IV_API_CALL_STATUS_T (*ihevce_output_recon_fill_done)
    (void *pv_recon_cb_handle,
     void *pv_curr_out,
     WORD32 i4_bitrate_instance,
     WORD32 i4_res_instance);
 
    /**
     * Call back API to be called while freeing the input buffer
     */
    IV_API_CALL_STATUS_T (*ihevce_set_free_input_buff)
    (void *pv_inp_cb_handle, iv_input_data_ctrl_buffs_t *ps_input_buf);
 
    /**
     * Call back API to be called during allocation using memory manager
     */
    void (*ihevce_mem_alloc)(
        void *pv_mem_mgr_hdl, ihevce_sys_api_t *ps_sys_api, iv_mem_rec_t *ps_memtab);
 
    /**
     * Call back API for freeing using memory manager
     */
    void (*ihevce_mem_free)(void *pv_mem_mgr_hdl, iv_mem_rec_t *ps_memtab);
 
    /* create or run time input buffer allocation, 1: create time 0: run time*/
    WORD32 i4_create_time_input_allocation;
 
    /* create or run time output buffer allocation, 1: create time 0: run time*/
    WORD32 i4_create_time_output_allocation;
 
    /*Cores per resolution*/
    WORD32 ai4_num_core_per_res[IHEVCE_MAX_NUM_RESOLUTIONS];
 
    /**
    *  Error Handling callback handle
    */
    void *pv_cmd_err_cb_handle;
 
    /**
    * Call back API to be called when errors need to be reported
    */
    IV_API_CALL_STATUS_T (*ihevce_cmds_error_report)
    (void *pv_cmd_err_cb_handle, WORD32 i4_error_code, WORD32 i4_cmd_type, WORD32 i4_buf_id);
 
    /**
    * Flag to indicate if ECU is enabled/disabled
    */
    WORD32 i4_p6_opt_enabled;
 
    /**
     * profile stats
     */
    profile_database_t profile_hle;
    profile_database_t profile_pre_enc[IHEVCE_MAX_NUM_RESOLUTIONS];
    profile_database_t profile_enc[IHEVCE_MAX_NUM_RESOLUTIONS][IHEVCE_MAX_NUM_BITRATES];
    profile_database_t profile_entropy[IHEVCE_MAX_NUM_RESOLUTIONS][IHEVCE_MAX_NUM_BITRATES];
 
} ihevce_hle_ctxt_t;
 
/**
******************************************************************************
 *  @brief  Indivisual Thread context structure
******************************************************************************
 */
typedef struct
{
    /**  Unique Id associated with every frame processing thread */
    WORD32 i4_thrd_id;
 
    /** pointer to encoder context structure */
    void *pv_enc_ctxt;
 
    /** pointer to the hle context structure */
    ihevce_hle_ctxt_t *ps_hle_ctxt;
 
} frm_proc_thrd_ctxt_t;
 
/*****************************************************************************/
/* Extern Variable Declarations                                              */
/*****************************************************************************/
 
/*****************************************************************************/
/* Extern Function Declarations                                              */
/*****************************************************************************/
 
/** Create API
 *
 * ps_hle_ctxt : Pointer to high level encoder context.
 *    It is assumed that application before calling this API
 *    has initialized with correct pointers for following
 *      - pv_osal_handle
 *      - pv_app_sem_handle
 *      - ps_static_cfg_prms
 *      - ihevce_mem_alloc
 *      - ihevce_mem_free
 *
 * Encoder after initilaization would store the encoder handle in
 *      - pv_enc_hdl
 *
 * Create Return status (success or fail) is returned
 */
IHEVCE_DLL IV_API_CALL_STATUS_T ihevce_hle_interface_create(ihevce_hle_ctxt_t *ps_hle_ctxt);
 
/** Query IO buffers requirements API
 *
 *  ps_hle_ctxt : Pointer to high level encoder context.
 *  ps_input_bufs_req : memory to store input buffer requirements
 *  ps_output_bufs_req : memory to store output buffer requirements
 *
 * Should be called only after a sucessfull create of codec instance
 *
 * Return status (success or fail) is returned
 */
IHEVCE_DLL IV_API_CALL_STATUS_T ihevce_query_io_buf_req(
    ihevce_hle_ctxt_t *ps_hle_ctxt,
    iv_input_bufs_req_t *ps_input_bufs_req,
    iv_res_layer_output_bufs_req_t *ps_res_layer_output_bufs_req,
    iv_res_layer_recon_bufs_req_t *ps_res_layer_recon_bufs_req);
 
/** Create buffer ports for procesing API
 *
 *  ps_hle_ctxt : Pointer to high level encoder context.
 *  ps_input_data_ctrl_buffs_desc :
 *       Pointer to Input (data/control) buffers details memory
 *  ps_input_asynch_ctrl_buffs_desc :
 *       Pointer to Input async control buffers details memory
 *  ps_output_data_buffs_desc :
 *      Pointer to output data buffers details memory
 *  ps_output_status_buffs_desc:
 *      Pointer to outtput async control buffers details memory
 *
 * Return status (success or fail) is returned
 */
IHEVCE_DLL IV_API_CALL_STATUS_T ihevce_create_ports(
    ihevce_hle_ctxt_t *ps_hle_ctxt,
    iv_input_data_ctrl_buffs_desc_t *ps_input_data_ctrl_buffs_desc,
    iv_input_asynch_ctrl_buffs_desc_t *ps_input_asynch_ctrl_buffs_desc,
    iv_res_layer_output_data_buffs_desc_t *ps_mres_output_data_buffs_desc,
    iv_res_layer_recon_data_buffs_desc_t *ps_mres_recon_data_buffs_desc);
 
/** Processing interface layer thread API
 *
 *  This is the entry point for this thread
 *  pointer to ihevce_hle_ctxt_t has to be passed
 *  to this function as the argument
 *
 *  return should be a exit code (0)
 */
IHEVCE_DLL WORD32 ihevce_hle_interface_thrd(void *pv_proc_intf_ctxt);
 
/** Get version API
 *
 *  This is API to return the version number of the encoder
 *
 *  returns the version number string
 */
IHEVCE_DLL const char *ihevce_get_encoder_version(void);
 
/** Validate Encoder parameters
 *
 *  This is API to return the version number of the encoder
 *
 *  returns the version number string
 */
IHEVCE_DLL WORD32 ihevce_validate_encoder_parameters(ihevce_static_cfg_params_t *ps_static_cfg_prms);
 
/** Get free input frame data buffer API
 *
 * ps_hle_ctxt : Pointer to high level encoder context.
 * pi4_buff_id : pointer to store the buffer id of the buffer returned.
 * i4_blocking_mode : Blocking mode to control if the the API should wait
 *                    for a free buffer to be available and then
 *                    return with a valid buffer @sa BUFF_QUE_MODES_T
 * returns NULL if no free buffer is present in queue (if non blocking mode)
 */
IHEVCE_DLL void *ihevce_q_get_free_inp_data_buff(
    ihevce_hle_ctxt_t *ps_hle_ctxt, WORD32 *pi4_buff_id, WORD32 i4_blocking_mode);
 
/** Get free input control data buffer API
 *
 * ps_hle_ctxt : Pointer to high level encoder context.
 * pi4_buff_id : pointer to store the buffer id of the buffer returned.
 * i4_blocking_mode : Blocking mode to control if the the API should wait
 *                    for a free buffer to be available and then
 *                    return with a valid buffer @sa BUFF_QUE_MODES_T
 * returns NULL if no free buffer is present in queue (if non blocking mode)
 */
IHEVCE_DLL void *ihevce_q_get_free_inp_ctrl_buff(
    ihevce_hle_ctxt_t *ps_hle_ctxt, WORD32 *pi4_buff_id, WORD32 i4_blocking_mode);
 
IHEVCE_DLL void *ihevce_q_get_free_out_strm_buff(
    ihevce_hle_ctxt_t *ps_hle_ctxt,
    WORD32 *pi4_buff_id,
    WORD32 i4_blocking_mode,
    WORD32 i4_bitrate_instance,
    WORD32 i4_res_instance);
 
IHEVCE_DLL void *ihevce_q_get_free_out_recon_buff(
    ihevce_hle_ctxt_t *ps_hle_ctxt,
    WORD32 *pi4_buff_id,
    WORD32 i4_blocking_mode,
    WORD32 i4_bitrate_instance,
    WORD32 i4_res_instance);
 
/** Set Input frame data buffer as produced API
 *
 * ps_hle_ctxt : Pointer to high level encoder context.
 * i4_buff_id : buffer id of the buffer returned during get free buf.
 */
IHEVCE_DLL IV_API_CALL_STATUS_T
    ihevce_q_set_inp_data_buff_prod(ihevce_hle_ctxt_t *ps_hle_ctxt, WORD32 i4_buff_id);
 
/** Set Input control data buffer as produced API
 *
 * ps_hle_ctxt : Pointer to high level encoder context.
 * i4_buff_id : buffer id of the buffer returned during get free buf.
 */
IHEVCE_DLL IV_API_CALL_STATUS_T
    ihevce_q_set_inp_ctrl_buff_prod(ihevce_hle_ctxt_t *ps_hle_ctxt, WORD32 i4_buff_id);
 
IHEVCE_DLL IV_API_CALL_STATUS_T ihevce_q_set_out_strm_buff_prod(
    ihevce_hle_ctxt_t *ps_hle_ctxt,
    WORD32 i4_buff_id,
    WORD32 i4_bitrate_instance_id,
    WORD32 i4_resolution_id);
 
IHEVCE_DLL IV_API_CALL_STATUS_T ihevce_q_set_out_recon_buff_prod(
    ihevce_hle_ctxt_t *ps_hle_ctxt,
    WORD32 i4_buff_id,
    WORD32 i4_bitrate_instance_id,
    WORD32 i4_resolution_id);
 
/** Get next filled recon data buffer API
 *
 * ps_hle_ctxt : Pointer to high level encoder context.
 * pi4_buff_id : pointer to store the buffer id of the buffer returned.
 * i4_blocking_mode : Blocking mode to control if the the API should wait
 *                    for a produced buffer to be available and then
 *                    return with a valid buffer @sa BUFF_QUE_MODES_T
 * returns NULL if no produced buffer is present in queue (if non blocking mode)
 */
IHEVCE_DLL void *ihevce_q_get_filled_recon_buff(
    ihevce_hle_ctxt_t *ps_hle_ctxt,
    WORD32 *pi4_buff_id,
    WORD32 i4_blocking_mode,
    WORD32 i4_bitrate_instance_id,
    WORD32 i4_resolution_id);
 
/** Release/ Free recon buffer buffer API
 *
 * ps_hle_ctxt : Pointer to high level encoder context.
 * i4_buff_id : buffer id of the buffer returned during get next buf.
 */
IHEVCE_DLL IV_API_CALL_STATUS_T ihevce_q_rel_recon_buf(
    ihevce_hle_ctxt_t *ps_hle_ctxt,
    WORD32 i4_buff_id,
    WORD32 i4_bitrate_instance_id,
    WORD32 i4_resolution_id);
 
/** Delete API
 *
 * Should be called only after the high level encoder thread exits or returns
 */
IHEVCE_DLL IV_API_CALL_STATUS_T ihevce_hle_interface_delete(ihevce_hle_ctxt_t *ps_hle_ctxt);
 
/** Trace API
 *
 * Open and Close trace file pointer.
 */
IHEVCE_DLL WORD32 ihevce_trace_init(UWORD8 *pu1_file_name);
 
IHEVCE_DLL WORD32 ihevce_trace_deinit(void);
 
/** Header API
 *
 *  Get sequence headers asynchronously
 */
WORD32 ihevce_entropy_encode_header(
    ihevce_hle_ctxt_t *ps_hle_ctxt, WORD32 i4_bitrate_instance_id, WORD32 i4_resolution_id);
 
#endif /* _IHEVCE_HLE_INTERFACE_H_ */