From aa56337b1fb9540902f175a76f8b66d4647af636 Mon Sep 17 00:00:00 2001 From: thead_admin Date: Wed, 4 Jan 2023 13:00:45 +0800 Subject: [PATCH] Linux_SDK_V1.0.3 --- examples/camera/cam_demo_dual_ir.c | 81 ++++++++++++++++++++++-------- include/hal/csi_camera.h | 24 +++++++-- include/hal/csi_camera_frame.h | 9 +++- include/hal/csi_camera_property.h | 6 +++ include/hal/csi_frame.h | 7 +++ include/hal/csi_frame_ex.h | 10 +++- include/hal/csi_vdec.h | 10 ++-- 7 files changed, 114 insertions(+), 33 deletions(-) diff --git a/examples/camera/cam_demo_dual_ir.c b/examples/camera/cam_demo_dual_ir.c index b3a6d57..36d525d 100644 --- a/examples/camera/cam_demo_dual_ir.c +++ b/examples/camera/cam_demo_dual_ir.c @@ -173,6 +173,12 @@ typedef struct dsp_ctx{ char* algo_name; }dsp_ctx_t; +typedef enum { + DUAL_DSP_ALGO_TYPE_DSP0_COPY =0, + DUAL_DSP_ALGO_TYPE_DSP1_COPY, + DUAL_DSP_ALGO_TYPE_DSP01_COPY, + +}dual_dsp_algo_type_e; typedef struct dual_dsp_handle{ dsp_ctx_t dsp_ctx[MAX_DSP_DEVICE]; msg_queue_ctx_t dsp_prcoess_queue; @@ -180,6 +186,7 @@ typedef struct dual_dsp_handle{ void *mem_allocor; pthread_t thread_dsp_process; frame_mode_t frame_mode; + dual_dsp_algo_type_e dsp_run_type; }dual_dsp_handle_t; @@ -211,11 +218,11 @@ void printUsage(char *name) " -h height (default: 1280))\n" " -n runing Camera frame num :0 not stop ,else frame num to stop )\n" " -M DSP frame mode :0 none ,1 dump enable,2 display)\n" - + " -a DSP algo mode :0 catch master frame ,1 catch slave frame, 2 catch each half frame)\n" "\n", name); } -static int parseParams(int argc, char **argv, camera_param_t *params,frame_mode_t *mode) +static int parseParams(int argc, char **argv, camera_param_t *params,frame_mode_t *mode,dual_dsp_algo_type_e *dsp_type) { int index =0; int i = 1; @@ -241,6 +248,7 @@ static int parseParams(int argc, char **argv, camera_param_t *params,frame_mode params[index].frames_to_stop = 30; index++; *mode = FRAME_NONE; + *dsp_type = DUAL_DSP_ALGO_TYPE_DSP01_COPY; while (i < argc) { if (argv[i][0] != '-' || strlen(argv[i]) < 2) @@ -282,6 +290,11 @@ static int parseParams(int argc, char **argv, camera_param_t *params,frame_mode if (++i < argc) *mode = atoi(argv[i++]); } + else if (argv[i][1] == 'a') + { + if (++i < argc) + *dsp_type = atoi(argv[i++]); + } else if (strcmp(argv[i], "--help") == 0) { printUsage(argv[0]); @@ -293,7 +306,7 @@ static int parseParams(int argc, char **argv, camera_param_t *params,frame_mode printf("[DUAL IR] Resolution : %dx%d\n", params[0].out_pic[0].width,params[0].out_pic[0].height); printf("[DUAL IR] run frame : %d\n", params[0].frames_to_stop); printf("[DUAL IR] frame mode : %d\n", *mode); - + printf("[DUAL IR] dsp run type : %d\n", *dsp_type); return index; } @@ -490,7 +503,7 @@ static int dsp_send_info_to_cam(msg_queue_ctx_t* cam_msg_queue,int master_fd,int return 0; } -static dual_dsp_handle_t* dsp_process_create(frame_mode_t mode) +static dual_dsp_handle_t* dsp_process_create(frame_mode_t mode,dual_dsp_algo_type_e type) { dual_dsp_handle_t *dsp_hdl=NULL; dsp_hdl = malloc(sizeof(dual_dsp_handle_t)); @@ -506,6 +519,7 @@ static dual_dsp_handle_t* dsp_process_create(frame_mode_t mode) dsp_hdl->dsp_prcoess_queue.tail=NULL; dsp_hdl->dsp_prcoess_queue.exit = 0; dsp_hdl->frame_mode = mode; + dsp_hdl->dsp_run_type = type; pthread_mutex_init(&dsp_hdl->dsp_prcoess_queue.mutex,NULL); if(dsp_construct_task(&dsp_hdl->dsp_ctx[0])) @@ -739,10 +753,21 @@ static void* dsp_dual_ir_porcess(void *arg) continue; } dsp1_result = (algo_result_t *)buf4.planes[0].buf_vir; - setting.mode = ALGO_PIC_MODE_FULL_COPY_WITH_PARAM; - setting.buf_id=0; - setting.h_offset = dual_ir_frame->height/2; - setting.height =dual_ir_frame->height/2; + if(dsp_hdl->dsp_run_type == DUAL_DSP_ALGO_TYPE_DSP01_COPY ) + { + setting.mode = ALGO_PIC_MODE_FULL_COPY_WITH_PARAM; + setting.buf_id=0; + setting.h_offset = dual_ir_frame->height/2; + setting.height =dual_ir_frame->height/2; + }else if(dsp_hdl->dsp_run_type == DUAL_DSP_ALGO_TYPE_DSP0_COPY) + { + setting.mode = ALGO_PIC_MODE_FULL_COPY; + } + else + { + setting.mode = ALGO_PIC_MODE_FULL_COPY_NONE; + } + setting.timestap = dual_ir_frame->timestap; if(csi_dsp_request_set_property(req1,&setting,sizeof(setting))) { @@ -753,10 +778,21 @@ static void* dsp_dual_ir_porcess(void *arg) continue; } - setting.mode = ALGO_PIC_MODE_FULL_COPY_WITH_PARAM; - setting.buf_id=0; - setting.h_offset = 0; - setting.height =dual_ir_frame->height/2; + if(dsp_hdl->dsp_run_type == DUAL_DSP_ALGO_TYPE_DSP01_COPY ) + { + setting.mode = ALGO_PIC_MODE_FULL_COPY_WITH_PARAM; + setting.buf_id=0; + setting.h_offset = 0; + setting.height =dual_ir_frame->height/2; + }else if(dsp_hdl->dsp_run_type == DUAL_DSP_ALGO_TYPE_DSP1_COPY) + { + setting.mode = ALGO_PIC_MODE_FULL_COPY; + } + else + { + setting.mode = ALGO_PIC_MODE_FULL_COPY_NONE; + } + setting.timestap = dual_ir_frame->timestap; if(csi_dsp_request_set_property(req2,&setting,sizeof(setting))) { @@ -1023,7 +1059,7 @@ static int send_paired_frame_to_dsp(msg_queue_ctx_t *queue,csi_frame_s *master_f dsp_msg_payload->master_stride = master_frame->img.strides[0]; dsp_msg_payload->master_fd = master_frame->img.fds[0]; dsp_msg_payload->slave_fd = slave_frame->img.fds[0]; - dsp_msg_payload->slave_stride = slave_frame->img.strides[0]; + dsp_msg_payload->slave_stride = slave_frame->img.strides[0]; dsp_msg_payload->timestap = timestap.time_value.tv_sec*1000000+timestap.time_value.tv_usec; enqueue_msg(queue,dsp_msg); main_item = malloc(sizeof(frame_item_t)); @@ -1393,14 +1429,15 @@ static camera_ctx_t * camera_open(camera_param_t *params) LOG_O("%s open successfully\n",dev_name); - // if(params->type == CAM_TYEP_MASTER) - // { + if(params->type == CAM_TYEP_SLAVE) + { // csi_camera_floodlight_led_set_flash_bright(cam_ctx->cam_handle, 500); //500ma - // csi_camera_projection_led_set_flash_bright(cam_ctx->cam_handle, 500); //500ma - // csi_camera_projection_led_set_mode(cam_ctx->cam_handle, LED_IR_ENABLE); + csi_camera_projection_led_set_flash_bright(cam_ctx->cam_handle, 500); //500ma + csi_camera_projection_led_set_mode(cam_ctx->cam_handle, LED_IR_ENABLE); // csi_camera_floodlight_led_set_mode(cam_ctx->cam_handle, LED_IR_ENABLE); - // csi_camera_led_enable(cam_ctx->cam_handle, LED_FLOODLIGHT_PROJECTION); - // } + csi_camera_led_enable(cam_ctx->cam_handle, LED_PROJECTION); + // csi_camera_led_set_switch_mode(cam_ctx->cam_handle, SWITCH_MODE_PROJECTION_ALWAYS_ON); + } get_system_time(__func__, __LINE__); @@ -1453,16 +1490,18 @@ int main(int argc, char *argv[]) camera_param_t params[MAX_CAM_NUM]; camera_ctx_t * ctx[MAX_CAM_NUM]={NULL}; frame_mode_t frame_mode ; + dual_dsp_algo_type_e dsp_type; int cam_num=0; bool running = false; - cam_num =parseParams(argc,argv,params,&frame_mode); + cam_num =parseParams(argc,argv,params,&frame_mode,&dsp_type); if(cam_num <=0 || cam_num>MAX_CAM_NUM) { LOG_E("not camera is active\n"); exit(0); } - dsp_hdl =dsp_process_create(frame_mode); + + dsp_hdl =dsp_process_create(frame_mode,dsp_type); if(dsp_hdl==NULL) { LOG_E("dsp create faile\n"); diff --git a/include/hal/csi_camera.h b/include/hal/csi_camera.h index a59ef70..907670f 100644 --- a/include/hal/csi_camera.h +++ b/include/hal/csi_camera.h @@ -12,10 +12,10 @@ #include -#include -#include -#include -#include +#include "csi_common.h" +#include "csi_camera_property.h" +#include "csi_camera_frame.h" +#include "csi_frame_ex.h" #ifdef __cplusplus extern "C" { @@ -223,6 +223,22 @@ typedef struct csi_camera_event { }; } csi_camera_event_s; + +typedef enum csi_camera_error{ + CSI_CAMERA_RET_ERR_INVALID_DEV = -1001,/* device is not valid */ + CSI_CAMERA_RET_ERR_INVALID_PARA, /* input params is not valid */ + CSI_CAMERA_RET_ERR_NULL_PTR, + CSI_CAMERA_RET_ERR_DEV_BUSY, /* device is budy */ + CSI_CAMERA_RET_ERR_NOMEM, /* malloc fail */ + CSI_CAMERA_RET_ERR_TIMEOUT, /* evet or frame wait timeout */ + CSI_CAMERA_RET_ERR_NOT_SUPPORT, /* setting or config is not supported */ + CSI_CAMERA_CHANNEL_RET_ERR_INVALID_CHN = -501,/*channel is not valid */ + CSI_CAMERA_CHANNEL_RET_ERR_NOTOPEN, + CSI_CAMERA_RET_ERR = -1, /*common sw error */ + CSI_CAMERA_RET_OK =0, + +}csi_camera_erro_e; + int csi_camera_get_version(csi_api_version_u *version); int csi_camera_query_list(csi_camera_infos_s *infos); diff --git a/include/hal/csi_camera_frame.h b/include/hal/csi_camera_frame.h index ba3f242..af4836a 100644 --- a/include/hal/csi_camera_frame.h +++ b/include/hal/csi_camera_frame.h @@ -14,7 +14,11 @@ #include #include -#include +#include "csi_frame.h" + +#ifdef __cplusplus +extern "C" { +#endif #define CSI_CAMERA_META_MAX_LEN 1024 @@ -57,6 +61,9 @@ int csi_camera_frame_get_meta_unit(csi_camrea_meta_unit_s *meta_unit, csi_camera_meta_s *meta_data, csi_camera_meta_id_e meta_field); +#ifdef __cplusplus +} +#endif #endif /* __CSI_CAMERA_FRAME_H__ */ diff --git a/include/hal/csi_camera_property.h b/include/hal/csi_camera_property.h index 6594967..44ffb4b 100644 --- a/include/hal/csi_camera_property.h +++ b/include/hal/csi_camera_property.h @@ -10,6 +10,9 @@ #ifndef __CSI_CAMERA_PROPERTY_H__ #define __CSI_CAMERA_PROPERTY_H__ +#ifdef __cplusplus +extern "C" { +#endif /* Camera Property ID */ #define CSI_CAMERA_PID_BASE (0x009a0000 | 0x900) @@ -89,5 +92,8 @@ enum CSI_CAMERA_AUTO_PRESET_WHITE_BALANCE_MODE { #define CSI_CAMERA_PID_BAND_STOP_FILTER (CSI_CAMERA_PID_BASE + 0x62) #define CSI_CAMERA_PID_IMAGE_STABILIZATION (CSI_CAMERA_PID_BASE + 0x63) +#ifdef __cplusplus +} +#endif #endif /* __CSI_CAMERA_PROPERTY_H__ */ diff --git a/include/hal/csi_frame.h b/include/hal/csi_frame.h index 17b9d33..62f88de 100644 --- a/include/hal/csi_frame.h +++ b/include/hal/csi_frame.h @@ -15,6 +15,9 @@ #include #include +#ifdef __cplusplus +extern "C" { +#endif /* * CSI frame defination is below, including * @@ -153,4 +156,8 @@ int csi_frame_release(csi_frame_s *frame); void *csi_frame_mmap(csi_frame_s *frame); int csi_frame_munmap(csi_frame_s *frame); +#ifdef __cplusplus +} +#endif + #endif /* __CSI_FRAME_H__ */ diff --git a/include/hal/csi_frame_ex.h b/include/hal/csi_frame_ex.h index 335af5b..bef4790 100644 --- a/include/hal/csi_frame_ex.h +++ b/include/hal/csi_frame_ex.h @@ -4,8 +4,10 @@ #ifndef _CSI_FRAME_EX_H #define _CSI_FRAME_EX_H -#include - +#include "csi_common.h" +#ifdef __cplusplus +extern "C" { +#endif #define MAX_PLANE_COUNT 3 typedef enum { @@ -173,4 +175,8 @@ typedef struct csi_bitstream { } csi_bitstream_s; #endif +#ifdef __cplusplus +} +#endif + #endif \ No newline at end of file diff --git a/include/hal/csi_vdec.h b/include/hal/csi_vdec.h index cde2524..f50b4b8 100644 --- a/include/hal/csi_vdec.h +++ b/include/hal/csi_vdec.h @@ -14,11 +14,11 @@ #include #include -#include -#include -#include -#include -#include +#include "csi_common.h" +#include "csi_vcodec_common.h" +#include "csi_allocator.h" +#include "csi_frame.h" +#include "csi_frame_ex.h" #ifdef __cplusplus extern "C" {