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