xref: /aosp_15_r20/external/libavc/examples/avcenc/app.h (revision 495ae853bb871d1e5a258cb02c2cc13cde8ddb9a)
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 *  app.h
25 *
26 * @brief
27 *  This file contains all the necessary structure and enumeration definitions
28 *  needed for the Application
29 *
30 * @author
31 *  ittiam
32 *
33 * @remarks
34 *  none
35 *
36 *******************************************************************************
37 */
38 
39 #ifndef _APP_H_
40 #define _APP_H_
41 
42 #include "iv2.h"
43 #include "ive2.h"
44 #ifdef WINDOWS_TIMER
45 #include <windows.h>
46 #else
47 #include <sys/time.h>
48 #endif
49 
50 /*****************************************************************************/
51 /* Function Macros                                                           */
52 /*****************************************************************************/
53 #define MAX(a, b) ((a) > (b))? (a) : (b)
54 #define MIN(a, b) ((a) < (b))? (a) : (b)
55 
56 #define ALIGN16(x) ((((x) + 15) >> 4) << 4)
57 
58 /*****************************************************************************/
59 /* Constant Macros                                                           */
60 /*****************************************************************************/
61 #define DEFAULT_NUM_INPUT_BUFS   32
62 #define DEFAULT_MAX_INPUT_BUFS   32
63 
64 #define DEFAULT_NUM_OUTPUT_BUFS  32
65 #define DEFAULT_MAX_OUTPUT_BUFS  32
66 
67 #define DEFAULT_NUM_RECON_BUFS   32
68 #define DEFAULT_MAX_RECON_BUFS   DEFAULT_NUM_RECON_BUFS
69 
70 #define DEFAULT_MAX_REF_FRM         2
71 #define DEFAULT_MAX_REORDER_FRM     0
72 #define DEFAULT_MAX_SRCH_RANGE_X    256
73 #define DEFAULT_MAX_SRCH_RANGE_Y    256
74 #define DEFAULT_QP_MIN              4
75 #define DEFAULT_QP_MAX              49
76 
77 #define DEFAULT_MEM_REC_CNT         0
78 #define DEFAULT_RECON_ENABLE        0
79 #define DEFAULT_CHKSUM_ENABLE       0
80 #define DEFAULT_START_FRM           0
81 #define DEFAULT_NUM_FRMS            0xFFFFFFFF
82 #define DEFAULT_INP_COLOR_FMT       IV_YUV_420SP_UV
83 #define DEFAULT_RECON_COLOR_FMT     IV_YUV_420P
84 #define DEFAULT_NUM_CORES           1
85 #define DEFAULT_LOOPBACK            0
86 #define DEFAULT_MAX_FRAMERATE       120000 /* in ticks (1000 ticks = 1s) */
87 #define DEFAULT_SRC_FRAME_RATE      30
88 #define DEFAULT_TGT_FRAME_RATE      30
89 #define DEFAULT_MAX_WD              1920
90 #define DEFAULT_MAX_HT              1920
91 #define DEFAULT_MAX_LEVEL           40
92 #define DEFAULT_STRIDE              0
93 #define DEFAULT_WD                  0
94 #define DEFAULT_HT                  0
95 #define DEFAULT_PSNR_ENABLE         0
96 #define DEFAULT_ME_SPEED            100
97 #define DEFAULT_ENABLE_FAST_SAD     0
98 #define DEFAULT_ENABLE_ALT_REF      0
99 #define DEFAULT_RC                  1
100 #define DEFAULT_MAX_BITRATE         240000000
101 #define DEFAULT_BITRATE             6000000
102 #define DEFAULT_I_QP                25
103 #define DEFAULT_I_QP_MAX            DEFAULT_QP_MAX
104 #define DEFAULT_I_QP_MIN            DEFAULT_QP_MIN
105 #define DEFAULT_P_QP                28
106 #define DEFAULT_P_QP_MAX            DEFAULT_QP_MAX
107 #define DEFAULT_P_QP_MIN            DEFAULT_QP_MIN
108 #define DEFAULT_B_QP                28
109 #define DEFAULT_B_QP_MAX            DEFAULT_QP_MAX
110 #define DEFAULT_B_QP_MIN            DEFAULT_QP_MIN
111 #define DEFAULT_AIR                 0
112 #define DEFAULT_AIR_REFRESH_PERIOD  30
113 #define DEFAULT_SRCH_RNG_X          64
114 #define DEFAULT_SRCH_RNG_Y          64
115 #define DEFAULT_I_INTERVAL          30
116 #define DEFAULT_IDR_INTERVAL        1200
117 #define DEFAULT_CONSTRAINED_INTRAPRED  0
118 #define DEFAULT_NUM_BFRAMES         0
119 #define DEFAULT_DISABLE_DEBLK_LEVEL 0
120 #define DEFAULT_HPEL                1
121 #define DEFAULT_QPEL                1
122 #define DEFAULT_I4                  1
123 #define DEFAULT_EPROFILE            IV_PROFILE_BASE
124 #define DEFAULT_SLICE_MODE          0
125 #define DEFAULT_SLICE_PARAM         256
126 #define DEFAULT_ENTROPY_CODING_MODE 0
127 #define NUM_SEI_MDCV_PRIMARIES      3
128 #define NUM_SEI_CCV_PRIMARIES       3
129 #define SII_MAX_SUB_LAYERS 8
130 #define SII_SUB_LAYER_IDX 0
131 #define SHUTTER_INTERVAL_INFO_PRESENT_FLAG 1
132 #define SII_TIME_SCALE 24000000
133 #define FIXED_SHUTTER_INTERVAL_WITHIN_CVS_FLAG 0
134 #define SII_NUM_UNITS_IN_SHUTTER_INTERVAL 480000
135 #define SII_MAX_SUB_LAYERS_MINUS1 (SII_MAX_SUB_LAYERS - 1)
136 #define SUB_LAYER_NUM_UNITS_IN_SHUTTER_INTERVAL_HFR 480000
137 #define SUB_LAYER_NUM_UNITS_IN_SHUTTER_INTERVAL_SFR 240000
138 #define DEFAULT_MAX_DISPLAY_MASTERING_LUMINANCE 50000
139 #define DEFAULT_MIN_DISPLAY_MASTERING_LUMINANCE 1
140 
141 #define STRLENGTH               500
142 
143 
144 /*****************************************************************************/
145 /*  profile Macros                                                           */
146 /*****************************************************************************/
147 #ifdef PROFILE_ENABLE
148     #ifdef WINDOWS_TIMER
149         typedef  LARGE_INTEGER TIMER;
150     #else
151         //#ifdef X86_MINGW
152         typedef struct timeval TIMER;
153         //#endif
154     #endif
155 #endif
156 
157 #ifdef PROFILE_ENABLE
158     #ifdef WINDOWS_TIMER
159         #define GETTIME(timer) QueryPerformanceCounter(timer);
160     #else
161     //#ifdef X86_MINGW
162         #define GETTIME(timer) gettimeofday(timer,NULL);
163     //#endif
164     #endif
165 
166     #ifdef WINDOWS_TIMER
167         #define ELAPSEDTIME(s_start_timer,s_end_timer, s_elapsed_time, frequency) \
168                   { \
169                    TIMER s_temp_time;   \
170                    s_temp_time.LowPart = s_end_timer.LowPart - s_start_timer.LowPart ; \
171                    s_elapsed_time = (UWORD32) ( ((DOUBLE)s_temp_time.LowPart / (DOUBLE)frequency.LowPart )  * 1000000); \
172                 }
173     #else
174     //#ifdef X86_MINGW
175         #define ELAPSEDTIME(s_start_timer,s_end_timer, s_elapsed_time, frequency) \
176                    s_elapsed_time = ((s_end_timer.tv_sec - s_start_timer.tv_sec) * 1000000) + (s_end_timer.tv_usec - s_start_timer.tv_usec);
177     //#endif
178     #endif
179 
180 #else
181     #define GETTIME(timer)
182     #define ELAPSEDTIME(s_start_timer,s_end_timer, s_elapsed_time, frequency)
183 #endif
184 
185 
186 /*****************************************************************************/
187 /*  Structure definitions                                                    */
188 /*****************************************************************************/
189 
190 /**
191 **************************************************************************
192 * @brief input buffer context
193 **************************************************************************
194 */
195 typedef struct
196 {
197     UWORD8 *pu1_buf;
198     UWORD32 u4_buf_size;
199     UWORD32 u4_timestamp_low;
200     UWORD32 u4_timestamp_high;
201     UWORD32 u4_is_free;
202     void *pv_mb_info;
203     void *pv_pic_info;
204 } input_buf_t;
205 
206 /**
207 **************************************************************************
208 * @brief output buffer context
209 **************************************************************************
210 */
211 typedef struct
212 {
213     UWORD8 *pu1_buf;
214     UWORD32 u4_buf_size;
215     UWORD32 u4_timestamp_low;
216     UWORD32 u4_timestamp_high;
217     UWORD32 u4_is_free;
218 } output_buf_t;
219 
220 /**
221 **************************************************************************
222 * @brief recon buffer context
223 **************************************************************************
224 */
225 typedef struct
226 {
227     UWORD8 *pu1_buf;
228     UWORD32 u4_buf_size;
229     UWORD32 u4_timestamp_low;
230     UWORD32 u4_timestamp_high;
231     UWORD32 u4_is_free;
232 } recon_buf_t;
233 
234 /**
235 **************************************************************************
236 * @brief app context
237 **************************************************************************
238 */
239 typedef struct
240 {
241     iv_obj_t *ps_enc;
242     iv_mem_rec_t *ps_mem_rec;
243     UWORD32 u4_num_mem_rec;
244     UWORD32 u4_recon_enable;
245     UWORD32 u4_chksum_enable;
246     UWORD32 u4_mb_info_type;
247     UWORD32 u4_pic_info_type;
248     UWORD32 u4_mb_info_size;
249     UWORD32 u4_pic_info_size;
250     UWORD32 u4_start_frm;
251     UWORD32 u4_max_num_frms;
252     UWORD32 u4_total_bytes;
253     UWORD32 u4_pics_cnt;
254     IV_COLOR_FORMAT_T e_inp_color_fmt;
255     IV_COLOR_FORMAT_T e_recon_color_fmt;
256     IV_ARCH_T e_arch;
257     IV_SOC_T e_soc;
258 
259     WORD32 header_generated;
260     void *pv_codec_obj;
261 
262     UWORD32 u4_num_cores;
263     UWORD32 u4_pre_enc_me;
264     UWORD32 u4_pre_enc_ipe;
265 
266     CHAR ac_ip_fname[STRLENGTH];
267     CHAR ac_op_fname[STRLENGTH];
268     CHAR ac_recon_fname[STRLENGTH];
269     CHAR ac_chksum_fname[STRLENGTH];
270     CHAR ac_mb_info_fname[STRLENGTH];
271     CHAR ac_pic_info_fname[STRLENGTH];
272 
273     FILE *fp_ip;
274     FILE *fp_op;
275     FILE *fp_recon;
276     FILE *fp_chksum;
277     FILE *fp_psnr_ip;
278     FILE *fp_mb_info;
279     FILE *fp_pic_info;
280 
281     UWORD32 u4_loopback;
282     UWORD32 u4_max_frame_rate;
283     UWORD32 u4_src_frame_rate;
284     UWORD32 u4_tgt_frame_rate;
285     UWORD32 u4_max_wd;
286     UWORD32 u4_max_ht;
287     UWORD32 u4_max_level;
288 
289     UWORD32 u4_strd;
290     UWORD32 u4_wd;
291     UWORD32 u4_ht;
292 
293     UWORD32 u4_psnr_enable;
294 
295     UWORD32 u4_enc_speed;
296     UWORD32 u4_me_speed;
297     UWORD32 u4_enable_fast_sad;
298     UWORD32 u4_enable_alt_ref;
299     UWORD32 u4_rc;
300     UWORD32 u4_max_bitrate;
301     UWORD32 u4_bitrate;
302     UWORD32 u4_i_qp, u4_i_qp_max, u4_i_qp_min;
303     UWORD32 u4_p_qp, u4_p_qp_max, u4_p_qp_min;
304     UWORD32 u4_b_qp, u4_b_qp_max, u4_b_qp_min;
305     UWORD32 u4_air;
306     UWORD32 u4_air_refresh_period;
307     UWORD32 u4_srch_rng_x;
308     UWORD32 u4_srch_rng_y;
309     UWORD32 u4_i_interval;
310     UWORD32 u4_idr_interval;
311     UWORD32 u4_constrained_intra_pred;
312     UWORD32 u4_num_bframes;
313     UWORD32 u4_disable_deblk_level;
314     UWORD32 u4_hpel;
315     UWORD32 u4_qpel;
316     UWORD32 u4_enable_intra_4x4;
317     IV_PROFILE_T e_profile;
318     UWORD32 u4_slice_mode;
319     UWORD32 u4_slice_param;
320     UWORD32 u4_entropy_coding_mode;
321 
322     void *pv_input_thread_handle;
323     void *pv_output_thread_handle;
324     void *pv_recon_thread_handle;
325 
326     ih264e_ctl_getbufinfo_op_t s_get_buf_info_op;
327     input_buf_t as_input_buf[DEFAULT_MAX_INPUT_BUFS];
328     output_buf_t as_output_buf[DEFAULT_MAX_OUTPUT_BUFS];
329     recon_buf_t as_recon_buf[DEFAULT_MAX_RECON_BUFS];
330 
331     DOUBLE adbl_psnr[3];
332     UWORD32 u4_psnr_cnt;
333     UWORD8 *pu1_psnr_buf;
334     UWORD8 u4_psnr_buf_size;
335 
336     UWORD32 u4_vbv_buffer_delay;
337     UWORD32 u4_vbv_buf_size;
338 
339     TIMER enc_start_time;
340     TIMER enc_last_time;
341     WORD32 avg_time;
342 
343     UWORD32 u4_sei_mdcv_params_present_flag;
344     UWORD32 au4_display_primaries_x[NUM_SEI_MDCV_PRIMARIES];
345     UWORD32 au4_display_primaries_y[NUM_SEI_MDCV_PRIMARIES];
346     UWORD32 u4_white_point_x;
347     UWORD32 u4_white_point_y;
348     UWORD32 u4_max_display_mastering_luminance;
349     UWORD32 u4_min_display_mastering_luminance;
350 
351     UWORD32 u4_sei_cll_params_present_flag;
352     UWORD32 u4_max_content_light_level;
353     UWORD32 u4_max_pic_average_light_level;
354 
355     UWORD32 u4_sei_ave_params_present_flag;
356     UWORD32 u4_ambient_illuminance;
357     UWORD32 u4_ambient_light_x;
358     UWORD32 u4_ambient_light_y;
359 
360     UWORD32 u4_sei_ccv_params_present_flag;
361     UWORD32 u4_ccv_cancel_flag;
362     UWORD32 u4_ccv_persistence_flag;
363     UWORD32 u4_ccv_primaries_present_flag;
364     UWORD32 u4_ccv_min_luminance_value_present_flag;
365     UWORD32 u4_ccv_max_luminance_value_present_flag;
366     UWORD32 u4_ccv_avg_luminance_value_present_flag;
367     UWORD32 u4_ccv_reserved_zero_2bits;
368     WORD32  ai4_ccv_primaries_x[NUM_SEI_CCV_PRIMARIES];
369     WORD32  ai4_ccv_primaries_y[NUM_SEI_CCV_PRIMARIES];
370     UWORD32 u4_ccv_min_luminance_value;
371     UWORD32 u4_ccv_max_luminance_value;
372     UWORD32 u4_ccv_avg_luminance_value;
373 
374     UWORD32 u4_shutter_interval_info_present_flag;
375     UWORD32 u4_sii_sub_layer_idx;
376     UWORD32 u4_sii_time_scale;
377     UWORD32 u4_fixed_shutter_interval_within_cvs_flag;
378     UWORD32 u4_sii_num_units_in_shutter_interval;
379     UWORD32 u4_sii_max_sub_layers_minus1;
380     UWORD32 au4_sub_layer_num_units_in_shutter_interval[SII_MAX_SUB_LAYERS];
381 
382     ih264e_ctl_set_sei_mdcv_params_ip_t s_sei_mdcv_params;
383     ih264e_ctl_set_sei_cll_params_ip_t s_sei_cll_params;
384     ih264e_ctl_set_sei_ave_params_ip_t s_sei_ave_params;
385     ih264e_ctl_set_sei_sii_params_ip_t s_sei_sii_params;
386 
387 } app_ctxt_t;
388 
389 
390 /*****************************************************************************/
391 /*  Function Declarations                                                    */
392 /*****************************************************************************/
393 void codec_exit(CHAR *pc_err_message);
394 void allocate_input(app_ctxt_t *ps_app_ctxt);
395 void allocate_output(app_ctxt_t *ps_app_ctxt);
396 void allocate_recon(app_ctxt_t *ps_app_ctxt);
397 
398 IV_STATUS_T read_input(FILE *fp, iv_raw_buf_t *ps_raw_buf);
399 IV_STATUS_T write_recon(FILE *fp, iv_raw_buf_t *ps_raw_buf);
400 IV_STATUS_T write_output(FILE *fp, UWORD8 *pu1_buf, WORD32 num_bytes);
401 
402 IV_STATUS_T read_mb_info(app_ctxt_t *ps_app_ctxt, void *pv_mb_info);
403 IV_STATUS_T read_pic_info(app_ctxt_t *ps_app_ctxt, void *pv_pic_info);
404 
405 void * ih264a_aligned_malloc(WORD32 alignment, WORD32 size);
406 void ih264a_aligned_free(void *pv_buf);
407 
408 void free_input(app_ctxt_t *ps_app_ctxt);
409 void free_recon(app_ctxt_t *ps_app_ctxt);
410 void free_output(app_ctxt_t *ps_app_ctxt);
411 
412 void init_raw_buf_descr(app_ctxt_t *ps_app_ctxt,
413                         iv_raw_buf_t *ps_raw_buf,
414                         UWORD8 *pu1_buf,
415                         IV_COLOR_FORMAT_T e_color_fmt);
416 
417 #ifndef MD5_DISABLE
418 void calc_md5_cksum(UWORD8 *pu1_inbuf,
419                     UWORD32 u4_stride,
420                     UWORD32 u4_width,
421                     UWORD32 u4_height,
422                     UWORD8 *pu1_cksum_p);
423 #else
424 #define calc_md5_cksum(a, b, c, d, e)
425 #endif
426 
427 #endif /* _APP_H_ */
428