xref: /aosp_15_r20/external/libhevc/encoder/ihevce_plugin_priv.h (revision c83a76b084498d55f252f48b2e3786804cdf24b7)
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_plugin_priv.h
23 *
24 * \brief
25 *    This file contains sample application definations and structures
26 *
27 * \date
28 *    15/04/2014
29 *
30 * \author
31 *    Ittiam
32 *
33 *
34 * List of Functions
35 *
36 *
37 ******************************************************************************
38 */
39 #ifndef _IHEVCE_PLUGIN_PRIV_H_
40 #define _IHEVCE_PLUGIN_PRIV_H_
41 
42 /*****************************************************************************/
43 /* File Includes                                                             */
44 /*****************************************************************************/
45 
46 /*****************************************************************************/
47 /* Constant Macros                                                           */
48 /*****************************************************************************/
49 
50 #define XTRA_INP_DATA_BUFS 0
51 #define MAX_NUM_INP_DATA_BUFS MAX_SUB_GOP_SIZE + NUM_LAP2_LOOK_AHEAD
52 #define MAX_NUM_INP_CTRL_SYNC_BUFS MAX_NUM_INP_DATA_BUFS
53 #define MAX_NUM_INP_CTRL_ASYNC_BUFS 5
54 
55 #define XTRA_OUT_DATA_BUFS 0
56 #define MAX_NUM_OUT_DATA_BUFS (16 + XTRA_OUT_DATA_BUFS)
57 #define MAX_NUM_OUT_CTRL_ASYNC_BUFS 16
58 
59 #define MAX_NUM_RECON_DATA_BUFS 64
60 
61 /** Queue from Master to Slave for MBR/MRES cases **/
62 #define MBR_M2S_QUEUE 200
63 
64 /*****************************************************************************/
65 /* Typedefs                                                                  */
66 /*****************************************************************************/
67 
68 /*****************************************************************************/
69 /* Enums                                                                     */
70 /*****************************************************************************/
71 
72 /*****************************************************************************/
73 /* Structure                                                                 */
74 /*****************************************************************************/
75 
76 /**
77 *  @brief  Store output buffer parameters
78 */
79 typedef struct
80 {
81     UWORD8 *pu1_bs_buffer;
82     WORD32 i4_bytes_generated;
83     WORD32 i4_is_key_frame;
84     ULWORD64 u8_pts;
85     LWORD64 i8_dts;
86 } bitstream_buf_t;
87 
88 /**
89 *  @brief  Store buffer queue parameters
90 */
91 typedef struct
92 {
93     /******* Buffer q indexes *******/
94     WORD32 i4_q_rd_idx;
95     WORD32 i4_q_wr_idx;
96     WORD32 i4_quit;
97     WORD32 i4_q_size;
98 
99     /******* Semaphore Handles ******/
100     void *pv_q_deq_sem_handle;
101     void *pv_rel_free_sem_handle;
102 } queue_t;
103 
104 /**
105 *  @brief  Datatype of global pointer used for data sharing
106 *          across encoder nodes.
107 */
108 
109 typedef struct
110 {
111     queue_t s_queue_params;
112     bitstream_buf_t bs_buf_nodes[MBR_M2S_QUEUE];
113     WORD32 i4_slave_inst_done;
114 
115 } ihevce_mbr_mres_handle_t;
116 
117 typedef struct
118 {
119     WORD32 i4_idx;
120 
121     UWORD8 *pu1_buf;
122 
123     WORD32 i4_is_free;
124 
125     WORD32 i4_is_prod;
126 
127     WORD32 i4_timestamp_low;
128 
129     WORD32 i4_timestamp_high;
130 
131     WORD32 i4_bytes_gen;
132 
133     WORD32 i4_is_key_frame;
134 
135     WORD32 i4_buf_size;
136 
137     WORD32 i4_end_flag;
138 
139 } out_buf_ctxt_t;
140 
141 typedef struct
142 {
143     ULWORD64 u8_total_bits;
144 
145     UWORD32 u4_num_frms_enc;
146 
147     /* mutex controlling the out strm buf b/w appln and encoder */
148     void *pv_app_out_strm_buf_mutex_hdl;
149 
150     void *pv_app_out_strm_buf_cond_var_hdl;
151 
152 } out_strm_prms_t;
153 
154 typedef struct
155 {
156     void *pv_mem_mngr_handle; /*!< memory manager handle */
157 
158     WORD32 ai4_out_strm_end_flag[IHEVCE_MAX_NUM_RESOLUTIONS]
159                                 [IHEVCE_MAX_NUM_BITRATES]; /*!< end of strm processing */
160 
161     out_strm_prms_t as_out_strm_prms[IHEVCE_MAX_NUM_RESOLUTIONS]
162                                     [IHEVCE_MAX_NUM_BITRATES]; /*!< to store out strm related prms */
163 
164 } app_ctxt_t;
165 
166 typedef struct
167 {
168     /*!< Static paramters same memory pointer will be passed to
169          processing interface layer */
170     ihevce_static_cfg_params_t *ps_static_cfg_prms;
171 
172     /*!< Osal Handle */
173     void *pv_osal_handle;
174 
175     /*!< Call back API for freeing */
176     void (*ihevce_mem_free)(void *pv_handle, void *pv_mem);
177 
178     /*!< Call back API to be called during allocation */
179     void *(*ihevce_mem_alloc)(void *pv_handle, UWORD32 u4_size);
180 
181     /** App context memory */
182     app_ctxt_t s_app_ctxt;
183 
184     /** semaphore handle for Input data proc thread */
185     void *pv_app_inp_ctrl_sem_hdl;
186 
187     /** semaphore handle for Output data proc thread */
188     void *pv_app_out_sts_sem_hdl;
189 
190     /** Pointer to HLE interface ctxt */
191     void *pv_hle_interface_ctxt;
192 
193     /** Memtab of input buffers */
194     iv_mem_rec_t s_memtab_inp_data_buf;
195 
196     /** Memtab of input command buffers */
197     iv_mem_rec_t s_memtab_inp_sync_ctrl_buf;
198 
199     /** Array of memtabs of outptu buffers */
200     iv_mem_rec_t as_memtab_out_data_buf[IHEVCE_MAX_NUM_RESOLUTIONS][IHEVCE_MAX_NUM_BITRATES];
201 
202     /* pointer to async command input buffer */
203     UWORD8 *pu1_inp_async_ctrl_buf;
204 
205     /* pointer to async command output buffer*/
206     UWORD8 *pu1_out_ctrl_buf;
207 
208     /* HLE thread handle */
209     void *pv_hle_thread_hdl;
210 
211     /* flag to indicate that flush mode is ON */
212     WORD32 i4_flush_mode_on;
213 
214     /* field id for interlaced case */
215     WORD32 i4_field_id;
216 
217     /* frame stride of input buffers */
218     WORD32 i4_frm_stride;
219 
220     /* flag to indicate Output end status */
221     WORD32 ai4_out_end_flag[IHEVCE_MAX_NUM_RESOLUTIONS][IHEVCE_MAX_NUM_BITRATES];
222 
223     /* output buffer context */
224     out_buf_ctxt_t aaas_out_bufs[IHEVCE_MAX_NUM_RESOLUTIONS][IHEVCE_MAX_NUM_BITRATES]
225                                 [MAX_NUM_OUT_DATA_BUFS + 1];
226 
227     /* Num Output buffers */
228     WORD32 i4_num_out_bufs;
229 
230     /* Free outbuf idx */
231     WORD32 ai4_free_out_buf_idx[IHEVCE_MAX_NUM_RESOLUTIONS][IHEVCE_MAX_NUM_BITRATES];
232 
233     /* Out produced idx */
234     WORD32 i4_prod_out_buf_idx;
235 
236     /* DTS for output population */
237     LWORD64 i8_dts;
238 
239     /* Flag used for flushing in case of EVAL version */
240     WORD32 i4_internal_flush;
241 
242     ULWORD64 u8_num_frames_encoded;
243 
244     /* Count no of frames queued */
245     ULWORD64 u8_num_frames_queued;
246 
247     /** Structure which contains params to be shared across different FFMPEG instances **/
248     ihevce_mbr_mres_handle_t
249         *ps_mbr_mres_handle[IHEVCE_MAX_NUM_RESOLUTIONS][IHEVCE_MAX_NUM_BITRATES];
250 
251     /* Dynamic change in bitrate detecting mechnaism related vaiables */
252     WORD32 ai4_old_bitrate[IHEVCE_MAX_NUM_RESOLUTIONS][IHEVCE_MAX_NUM_BITRATES];
253 
254 } plugin_ctxt_t;
255 
256 /*****************************************************************************/
257 /* Extern Variable Declarations                                              */
258 /*****************************************************************************/
259 
260 /*****************************************************************************/
261 /* Extern Function Declarations                                              */
262 /*****************************************************************************/
263 
264 #endif /* _IHEVCE_PLUGIN_PRIV_H_ */
265