drivers/video: add capture arg to support multi instance

Signed-off-by: yuexinyi <yuexinyi@xiaomi.com>
This commit is contained in:
yuexinyi 2023-07-05 18:08:34 +08:00 committed by Xiang Xiao
parent 52859fe10f
commit 56be0ab050
4 changed files with 34 additions and 18 deletions

View File

@ -175,6 +175,7 @@ static uint32_t g_cisif_time_stop;
#endif
static imgdata_capture_t g_cxd56_cisif_complete_capture;
static void *g_cxd56_cisif_capture_arg;
/****************************************************************************
* Private Function Prototypes
@ -216,7 +217,8 @@ static int cxd56_cisif_start_capture
uint8_t nr_datafmt,
imgdata_format_t *datafmt,
imgdata_interval_t *interval,
imgdata_capture_t callback);
imgdata_capture_t callback,
void *arg);
static int cxd56_cisif_stop_capture(struct imgdata_s *data);
static int cxd56_cisif_validate_buf(struct imgdata_s *data,
uint8_t *addr, uint32_t size);
@ -373,7 +375,7 @@ static void cisif_callback_for_intlev(uint8_t code)
/* Notify and get next addr */
g_cxd56_cisif_complete_capture(0, size, NULL);
g_cxd56_cisif_complete_capture(0, size, NULL, g_cxd56_cisif_capture_arg);
g_jpgint_receive = false;
@ -413,7 +415,8 @@ static void cisif_ycc_axi_trdn_int(uint8_t code)
else
{
size = cisif_reg_read(CISIF_YCC_DSTRG_CONT);
g_cxd56_cisif_complete_capture(0, size, NULL);
g_cxd56_cisif_complete_capture(0, size, NULL,
g_cxd56_cisif_capture_arg);
cisif_reg_write(CISIF_YCC_DREAD_CONT, 0);
}
}
@ -463,7 +466,8 @@ static void cisif_jpg_axi_trdn_int(uint8_t code)
else
{
size = cisif_reg_read(CISIF_JPG_DSTRG_CONT);
g_cxd56_cisif_complete_capture(0, size, NULL);
g_cxd56_cisif_complete_capture(0, size, NULL,
g_cxd56_cisif_capture_arg);
cisif_reg_write(CISIF_JPG_DREAD_CONT, 0);
}
}
@ -495,7 +499,8 @@ static void cisif_ycc_err_int(uint8_t code)
#endif
size = cisif_reg_read(CISIF_YCC_DSTRG_CONT);
g_cxd56_cisif_complete_capture(code, size, NULL);
g_cxd56_cisif_complete_capture(code, size, NULL,
g_cxd56_cisif_capture_arg);
cisif_reg_write(CISIF_YCC_DREAD_CONT, 0);
g_errint_receive = true;
}
@ -513,7 +518,8 @@ static void cisif_jpg_err_int(uint8_t code)
#endif
size = cisif_reg_read(CISIF_JPG_DSTRG_CONT);
g_cxd56_cisif_complete_capture(code, size, NULL);
g_cxd56_cisif_complete_capture(code, size, NULL,
g_cxd56_cisif_capture_arg);
cisif_reg_write(CISIF_JPG_DREAD_CONT, 0);
g_errint_receive = true;
}
@ -850,7 +856,8 @@ static int cxd56_cisif_start_capture
uint8_t nr_fmt,
imgdata_format_t *fmt,
imgdata_interval_t *interval,
imgdata_capture_t callback)
imgdata_capture_t callback,
void *arg)
{
cisif_param_t param =
{
@ -924,6 +931,7 @@ static int cxd56_cisif_start_capture
}
g_cxd56_cisif_complete_capture = callback;
g_cxd56_cisif_capture_arg = arg;
g_state = STATE_CAPTURE;

View File

@ -44,6 +44,7 @@ typedef struct
struct imgdata_s data;
struct imgsensor_s sensor;
imgdata_capture_t capture_cb;
void *capture_arg;
uint32_t buf_size;
uint8_t *next_buf;
struct timeval *next_ts;
@ -86,7 +87,8 @@ static int sim_camera_data_start_capture(struct imgdata_s *data,
uint8_t nr_datafmt,
imgdata_format_t *datafmt,
imgdata_interval_t *interval,
imgdata_capture_t callback);
imgdata_capture_t callback,
void *arg);
static int sim_camera_data_stop_capture(struct imgdata_s *data);
static int sim_camera_data_set_buf(struct imgdata_s *data,
uint8_t *addr, uint32_t size);
@ -289,7 +291,8 @@ static int sim_camera_data_start_capture(struct imgdata_s *data,
uint8_t nr_datafmt,
imgdata_format_t *datafmt,
imgdata_interval_t *interval,
imgdata_capture_t callback)
imgdata_capture_t callback,
void *arg)
{
sim_camera_priv_t *priv = (sim_camera_priv_t *)data;
int ret;
@ -306,6 +309,7 @@ static int sim_camera_data_start_capture(struct imgdata_s *data,
}
priv->capture_cb = callback;
priv->capture_arg = arg;
return host_video_start_capture(priv->vdev);
}
@ -344,7 +348,7 @@ void sim_camera_loop(void)
{
clock_gettime(CLOCK_MONOTONIC, &ts);
TIMESPEC_TO_TIMEVAL(&tv, &ts);
priv->capture_cb(0, ret, &tv);
priv->capture_cb(0, ret, &tv, priv->capture_arg);
}
}
}

View File

@ -232,7 +232,8 @@ static int save_scene_param(FAR video_mng_t *vmng,
uint32_t id,
struct v4l2_ext_control *control);
static int video_complete_capture(uint8_t err_code, uint32_t datasize,
FAR const struct timeval *ts);
FAR const struct timeval *ts,
FAR void *arg);
static int validate_frame_setting(FAR video_mng_t *vmng,
enum v4l2_buf_type type,
uint8_t nr_fmt,
@ -630,7 +631,7 @@ static int start_capture(FAR video_mng_t *vmng,
IMGSENSOR_STREAM_TYPE_VIDEO : IMGSENSOR_STREAM_TYPE_STILL,
nr_fmt, sf, &si);
IMGDATA_START_CAPTURE(vmng->imgdata,
nr_fmt, df, &di, video_complete_capture);
nr_fmt, df, &di, video_complete_capture, vmng);
IMGDATA_SET_BUF(vmng->imgdata, (FAR uint8_t *)bufaddr, bufsize);
return OK;
}
@ -3376,9 +3377,10 @@ static int video_unregister(FAR video_mng_t *priv)
/* Callback function which device driver call when capture has done. */
static int video_complete_capture(uint8_t err_code, uint32_t datasize,
FAR const struct timeval *ts)
FAR const struct timeval *ts,
FAR void *arg)
{
FAR video_mng_t *vmng = (FAR video_mng_t *)g_video_handler;
FAR video_mng_t *vmng = (FAR video_mng_t *)arg;
FAR video_type_inf_t *type_inf;
FAR vbuf_container_t *container = NULL;
enum v4l2_buf_type buf_type;

View File

@ -57,9 +57,9 @@
#define IMGDATA_VALIDATE_FRAME_SETTING(d, n, f, i) \
((d)->ops->validate_frame_setting ? \
(d)->ops->validate_frame_setting(d, n, f, i) : -ENOTTY)
#define IMGDATA_START_CAPTURE(d, n, f, i, c) \
#define IMGDATA_START_CAPTURE(d, n, f, i, c, a) \
((d)->ops->start_capture ? \
(d)->ops->start_capture(d, n, f, i, c) : -ENOTTY)
(d)->ops->start_capture(d, n, f, i, c, a) : -ENOTTY)
#define IMGDATA_STOP_CAPTURE(d) \
((d)->ops->stop_capture ? (d)->ops->stop_capture(d) : -ENOTTY)
@ -83,7 +83,8 @@ typedef struct imgdata_interval_s
} imgdata_interval_t;
typedef int (*imgdata_capture_t)(uint8_t result, uint32_t size,
FAR const struct timeval *ts);
FAR const struct timeval *ts,
FAR void *arg);
/* Structure for Data Control I/F */
@ -104,7 +105,8 @@ struct imgdata_ops_s
uint8_t nr_datafmts,
FAR imgdata_format_t *datafmts,
FAR imgdata_interval_t *interval,
FAR imgdata_capture_t callback);
FAR imgdata_capture_t callback,
FAR void *arg);
CODE int (*stop_capture)(FAR struct imgdata_s *data);
};