video: add user define memory ops for v4l2 frame buffers.

Signed-off-by: yaojingwei <yaojingwei@xiaomi.com>
This commit is contained in:
yaojingwei 2023-12-15 16:21:59 +08:00 committed by Xiang Xiao
parent f6097cfa67
commit 64aecbcc5c
2 changed files with 47 additions and 11 deletions

View file

@ -925,13 +925,13 @@ static void initialize_frame_setting(FAR struct imgsensor_s *imgsensor,
}
static void initialize_streamresources(FAR capture_type_inf_t *type_inf,
FAR struct imgsensor_s *imgsensor)
FAR capture_mng_t *cmng)
{
memset(type_inf, 0, sizeof(capture_type_inf_t));
type_inf->remaining_capnum = REMAINING_CAPNUM_INFINITY;
nxmutex_init(&type_inf->lock_state);
nxsem_init(&type_inf->wait_capture.dqbuf_wait_flg, 0, 0);
initialize_frame_setting(imgsensor, &type_inf->nr_fmt,
initialize_frame_setting(cmng->imgsensor, &type_inf->nr_fmt,
type_inf->fmt,
&type_inf->frame_interval);
video_framebuff_init(&type_inf->bufinf);
@ -1161,19 +1161,28 @@ static void initialize_scenes_parameter(FAR capture_mng_t *cmng)
static void initialize_resources(FAR capture_mng_t *cmng)
{
initialize_streamresources(&cmng->capture_inf, cmng->imgsensor);
initialize_streamresources(&cmng->still_inf, cmng->imgsensor);
initialize_streamresources(&cmng->capture_inf, cmng);
initialize_streamresources(&cmng->still_inf, cmng);
initialize_scenes_parameter(cmng);
}
static void cleanup_streamresources(FAR capture_type_inf_t *type_inf)
static void cleanup_streamresources(FAR capture_type_inf_t *type_inf,
FAR capture_mng_t *cmng)
{
video_framebuff_uninit(&type_inf->bufinf);
nxsem_destroy(&type_inf->wait_capture.dqbuf_wait_flg);
nxmutex_destroy(&type_inf->lock_state);
if (type_inf->bufheap != NULL)
{
if (cmng->imgdata->mem_ops && cmng->imgdata->mem_ops->mem_free)
{
cmng->imgdata->mem_ops->mem_free(type_inf->bufheap);
}
else
{
kumm_free(type_inf->bufheap);
}
type_inf->bufheap = NULL;
}
}
@ -1222,8 +1231,8 @@ static void cleanup_resources(FAR capture_mng_t *cmng)
/* Clean up resource */
cleanup_streamresources(&cmng->capture_inf);
cleanup_streamresources(&cmng->still_inf);
cleanup_streamresources(&cmng->capture_inf, cmng);
cleanup_streamresources(&cmng->still_inf, cmng);
cleanup_scenes_parameter(cmng);
}
@ -2111,6 +2120,8 @@ static int capture_reqbufs(FAR struct v4l2_s *v4l2,
{
FAR capture_mng_t *cmng = (FAR capture_mng_t *)v4l2;
FAR capture_type_inf_t *type_inf;
const imgdata_mem_ops_t *mem_ops = cmng->imgdata->mem_ops;
irqstate_t flags;
int ret = OK;
@ -2146,12 +2157,28 @@ static int capture_reqbufs(FAR struct v4l2_s *v4l2,
if (ret == OK && reqbufs->memory == V4L2_MEMORY_MMAP)
{
if (type_inf->bufheap != NULL)
{
if (mem_ops && mem_ops->mem_free)
{
mem_ops->mem_free(type_inf->bufheap);
}
else
{
kumm_free(type_inf->bufheap);
}
}
if (mem_ops && mem_ops->mem_malloc)
{
type_inf->bufheap = mem_ops->mem_malloc(32, reqbufs->count *
get_bufsize(&type_inf->fmt[CAPTURE_FMT_MAIN]));
}
else
{
type_inf->bufheap = kumm_memalign(32, reqbufs->count *
get_bufsize(&type_inf->fmt[CAPTURE_FMT_MAIN]));
}
type_inf->bufheap = kumm_memalign(32,
reqbufs->count * get_bufsize(&type_inf->fmt[CAPTURE_FMT_MAIN]));
if (type_inf->bufheap == NULL)
{
ret = -ENOMEM;

View file

@ -83,6 +83,14 @@ typedef struct imgdata_interval_s
uint32_t denominator;
} imgdata_interval_t;
/* Structure for memory operations */
typedef struct imgdata_mem_ops_s
{
CODE void *(*mem_malloc)(uint32_t align_size, uint32_t size);
CODE void (*mem_free)(void *data);
} imgdata_mem_ops_t;
typedef int (*imgdata_capture_t)(uint8_t result, uint32_t size,
FAR const struct timeval *ts,
FAR void *arg);
@ -121,6 +129,7 @@ struct imgdata_ops_s
struct imgdata_s
{
FAR const struct imgdata_ops_s *ops;
FAR const struct imgdata_mem_ops_s *mem_ops;
};
#ifdef __cplusplus