/* Copyright (c), 2001-2022, Shenshu Tech. Co., Ltd. */ #ifndef SAMPLE_COMMON_SVP_H #define SAMPLE_COMMON_SVP_H #include #include #include #include #include #include #include #include #include #include #include "ss_mpi_sys.h" #include "ot_common.h" #include "ot_common_svp.h" #include "sample_comm.h" #include "ss_mpi_dsp.h" #ifdef __cplusplus #if __cplusplus extern "C"{ #endif #endif /* __cplusplus */ #define OT_SVP_RECT_NUM 64 #define OT_POINT_NUM 4 #define OT_SVP_MAX_VPSS_CHN_NUM 2 #define OT_SVP_TIMEOUT 2000 typedef enum { ENUM_SVP_ERR_LEVEL_DEBUG = 0x0, /* debug-level */ ENUM_SVP_ERR_LEVEL_INFO = 0x1, /* informational */ ENUM_SVP_ERR_LEVEL_NOTICE = 0x2, /* normal but significant condition */ ENUM_SVP_ERR_LEVEL_WARNING = 0x3, /* warning conditions */ ENUM_SVP_ERR_LEVEL_ERROR = 0x4, /* error conditions */ ENUM_SVP_ERR_LEVEL_CRIT = 0x5, /* critical conditions */ ENUM_SVP_ERR_LEVEL_ALERT = 0x6, /* action must be taken immediately */ ENUM_SVP_ERR_LEVEL_FATAL = 0x7, /* just for compatibility with previous version */ ENUM_SVP_ERR_LEVEL_BUTT } enum_svp_err_level; typedef struct { ot_point point[OT_POINT_NUM]; } ot_struct_svp_rect; typedef struct { td_u16 num; ot_struct_svp_rect rect[OT_SVP_RECT_NUM]; } ot_struct_svp_rect_info; typedef struct { td_bool is_venc_open; td_bool is_vo_open; } ot_struct_svp_switch; typedef struct { ot_struct_svp_switch svp_switch; ot_size pic_size[OT_SVP_MAX_VPSS_CHN_NUM]; ot_enum_pic_size pic_type[OT_SVP_MAX_VPSS_CHN_NUM]; ot_vb_pool vb_pool[OT_SVP_MAX_VPSS_CHN_NUM]; td_u32 chn_num; } ot_struct_svp_media_cfg; #define macro_svp_printf(level_str, msg, ...) \ do { \ fprintf(stderr, "[level]:%s,[func]:%s [line]:%d [info]:" msg , level_str, __FUNCTION__, __LINE__, ##__VA_ARGS__); \ } while (0) #define macro_svp_printf_red(level_str, msg, ...) \ do { \ fprintf(stderr, "\033[0;31m [level]:%s,[func]:%s [line]:%d [info]:" msg "\033[0;39m\n", level_str, __FUNCTION__, \ __LINE__, ##__VA_ARGS__); \ } while (0) /* system is unusable */ #define macro_svp_trace_fatal(msg, ...) macro_svp_printf_red("Fatal", msg, ##__VA_ARGS__) /* action must be taken immediately */ #define macro_svp_trace_alert(msg, ...) macro_svp_printf_red("Alert", msg, ##__VA_ARGS__) /* critical conditions */ #define macro_svp_trace_critical(msg, ...) macro_svp_printf_red("Critical", msg, ##__VA_ARGS__) /* error conditions */ #define macro_svp_trace_err(msg, ...) macro_svp_printf_red("Error", msg, ##__VA_ARGS__) /* warning conditions */ #define macro_svp_trace_warning(msg, ...) macro_svp_printf("Warning", msg, ##__VA_ARGS__) /* normal but significant condition */ #define macro_svp_trace_notic(msg, ...) macro_svp_printf("Notice", msg, ##__VA_ARGS__) /* informational */ #define macro_svp_trace_info(msg, ...) macro_svp_printf("Info", msg, ##__VA_ARGS__) /* debug-level messages */ #define macro_svp_trace_debug(msg, ...) macro_svp_printf("Debug", msg, ##__VA_ARGS__) /* exps is true, goto */ #define macro_svp_check_exps_goto(exps, label, level, msg, ...) \ do { \ if ((exps)) { \ macro_svp_trace_err(msg, ## __VA_ARGS__); \ goto label; \ } \ } while (0) /* exps is true, return td_void */ #define macro_svp_check_exps_return_void(exps, level, msg, ...) \ do { \ if ((exps)) { \ macro_svp_trace_err(msg, ##__VA_ARGS__); \ return; \ } \ } while (0) /* exps is true, return ret */ #define macro_svp_check_exps_return(exps, ret, level, msg, ...) \ do { \ if ((exps)) { \ macro_svp_trace_err(msg, ##__VA_ARGS__); \ return (ret); \ } \ } while (0) \ /* exps is true, trace */ #define macro_svp_check_exps_trace(exps, level, msg, ...) \ do { \ if ((exps)) { \ macro_svp_trace_err(msg, ##__VA_ARGS__); \ } \ } while (0) #define macro_svp_check_exps_continue(exps, level, msg, ...) \ do { \ if ((exps)) { \ macro_svp_trace_err(msg, ##__VA_ARGS__); \ continue; \ } \ } while (0) \ /* exps is not success, trace */ #define macro_svp_check_failed_trace(exps, level, msg, ...) \ do { \ if ((exps) != TD_SUCCESS) { \ macro_svp_trace_err(msg, ##__VA_ARGS__); \ } \ } while (0) /* exps is not success, goto */ #define macro_svp_check_failed_goto(exps, label, level, msg, ...) \ do { \ if ((exps) != TD_SUCCESS) { \ macro_svp_trace_err(msg, ## __VA_ARGS__); \ goto label; \ } \ } while (0) \ /* exps is not sucecss, return */ #define macro_svp_check_failed_return(exps, ret, level, msg, ...) \ do { \ if ((exps) != TD_SUCCESS) { \ macro_svp_trace_err(msg, ##__VA_ARGS__); \ return (ret); \ } \ } while (0) /* exps is not equal to success, goto with level ENUM_SVP_ERR_LEVEL_ERROR */ #define macro_svp_check_failed_err_level_goto(exps, label, msg, ...) \ do { \ if ((exps) != TD_SUCCESS) { \ macro_svp_trace_err(msg, ## __VA_ARGS__); \ goto label; \ } \ } while (0) /* exps is not equal to success, return with level ENUM_SVP_ERR_LEVEL_ERROR */ #define macro_svp_check_failed_err_level_return(exps, ret, msg, ...) \ do { \ if ((exps) != TD_SUCCESS) { \ macro_svp_trace_err(msg, ## __VA_ARGS__); \ return (ret); \ } \ } while (0) /* exps is not equal success, trace with level ENUM_SVP_ERR_LEVEL_ERROR */ #define macro_svp_check_failed_err_level_trace(exps, msg, ...) \ do { \ if ((exps) != TD_SUCCESS) { \ macro_svp_trace_err(msg, ##__VA_ARGS__); \ } \ } while (0) #define sample_svp_pause() \ do { \ printf("---------------press Enter key to exit!---------------\n"); \ (void)getchar(); \ } while (0) #define SAMPLE_SVP_VB_POOL_NUM 2 #define SAMPLE_SVP_ALIGN_16 16 #define SAMPLE_SVP_ALIGN_32 32 #define SAMPLE_SVP_D1_PAL_HEIGHT 576 #define SAMPLE_SVP_D1_PAL_WIDTH 704 #define macro_svp_convert_addr_to_ptr(type, addr) ((type *)(td_uintptr_t)(addr)) #define macro_svp_convert_ptr_to_addr(type, addr) ((type)(td_uintptr_t)(addr)) /* free mmz */ #define macro_svp_mmz_free(phys, virt) \ do { \ if (((phys) != 0) && ((virt) != 0)) { \ ss_mpi_sys_mmz_free((td_phys_addr_t)(phys), (td_void*)(td_uintptr_t)(virt)); \ (phys) = 0; \ (virt) = 0; \ } \ } while (0) #define macro_svp_close_file(fp) \ do { \ if ((fp) != TD_NULL) { \ fclose((fp)); \ (fp) = TD_NULL; \ } \ } while (0) /* System init */ td_s32 sample_common_svp_check_sys_init(td_void); /* System exit */ td_void sample_common_svp_check_sys_exit(td_void); /* Align */ td_u32 sample_common_svp_align(td_u32 size, td_u16 align); /* Create mem info */ td_s32 sample_common_svp_create_mem_info(ot_svp_mem_info *mem_info, td_u32 size, td_u32 addr_offsset); /* Destory mem info */ td_void sample_common_svp_destroy_mem_info(ot_svp_mem_info *mem_info, td_u32 addr_offsset); /* Malloc memory */ td_s32 sample_common_svp_malloc_mem(td_char *mmb, td_char *zone, td_phys_addr_t *phys_addr, td_void **virt_addr, td_u32 size); /* Malloc memory with cached */ td_s32 sample_common_svp_malloc_cached(td_char *mmb, td_char *zone, td_phys_addr_t *phys_addr, td_void **virt_addr, td_u32 size); /* Fulsh cached */ td_s32 sample_common_svp_flush_cache(td_phys_addr_t phys_addr, td_void *virt_addr, td_u32 size); /* function : Call vgs to fill rect */ td_s32 sample_common_svp_vgs_fill_rect(const ot_video_frame_info *frame_info, ot_struct_svp_rect_info *rect, td_u32 color); /* function : Start Vi/Vpss/Venc/Vo */ td_s32 sample_common_svp_start_vi_vpss_venc_vo(struct_vi_cfg *vi_config, ot_struct_svp_switch *switch_ptr, ot_enum_pic_size *ext_pic_size_type); /* function : Stop Vi/Vpss/Venc/Vo */ td_void sample_common_svp_stop_vi_vpss_venc_vo(struct_vi_cfg *vi_config, ot_struct_svp_switch *switch_ptr); /* * Load bin */ td_s32 sample_comm_svp_load_core_binary(ot_svp_dsp_id core_id); /* * UnLoad bin */ void sample_comm_svp_unload_core_binary(ot_svp_dsp_id core_id); /* * Start Vdec/Vpss/Vo */ td_s32 sample_common_svp_create_vb_start_vdec_vpss_vo(struct_vdec_attr *vdec_attr, struct_vdec_thread_param *vdec_send, pthread_t *vdec_thread, ot_struct_svp_media_cfg *media_cfg, struct_vo_cfg *vo_cfg); /* * Stop Vdec/Vpss/Vo */ td_void sample_common_svp_destroy_vb_stop_vdec_vpss_vo(struct_vdec_thread_param *vdec_send, pthread_t *vdec_thread, ot_struct_svp_media_cfg *media_cfg, struct_vo_cfg *vo_cfg); /* * Send stream to venc/vo */ td_s32 sample_common_svp_venc_vo_send_stream(const ot_struct_svp_switch *vo_venc_switch, ot_venc_chn venc_chn, ot_vo_layer vo_layer, ot_vo_chn vo_chn, const ot_video_frame_info *frame); #ifdef __cplusplus #if __cplusplus } #endif #endif /* __cplusplus */ #endif /* SAMPLE_COMMON_SVP_H */