aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDikshita Agarwal <dikshita@codeaurora.org>2020-02-21 13:34:02 +0530
committerStanimir Varbanov <stanimir.varbanov@linaro.org>2020-05-06 14:02:52 +0300
commit7a42581689abf12fbca7f9627155c89bf4b835c9 (patch)
tree9b1d0ee78b6da836f093d979ef800cb66e0f2ac6
parentb3f49cc2e1840a642dbe27cd95f498f471a1a9fd (diff)
downloadv4l2-encode-dikshita/request-api.tar.gz
Enable Request API on Capture buffersdikshita/request-api
- Allocate request fd - setup control before QBUF - Queue request for each QBUF - Reinit Request after DQBUF
-rw-r--r--common.h1
-rw-r--r--video.c78
-rw-r--r--video.h1
3 files changed, 79 insertions, 1 deletions
diff --git a/common.h b/common.h
index 72e8bbc..afd40a5 100644
--- a/common.h
+++ b/common.h
@@ -128,6 +128,7 @@ struct video {
uint8_t *out_buf_addr[MAX_OUT_BUF];
int out_buf_flag[MAX_OUT_BUF];
int request_fd_out[MAX_OUT_BUF];
+ int request_fd_cap[MAX_CAP_BUF];
/* Capture queue related */
unsigned int cap_w;
diff --git a/video.c b/video.c
index 3284800..c08bbca 100644
--- a/video.c
+++ b/video.c
@@ -381,6 +381,42 @@ int video_setup_extra_control_out(struct instance *inst, unsigned int index)
}
return rc;
}
+
+int video_setup_extra_control_cap(struct instance *inst, unsigned int index)
+{
+ struct video *vid = &inst->video;
+ int rc;
+ unsigned int i;
+ err("video_setup_extra_control_cap index %d",index);
+ struct v4l2_ctrl_venus_metadata {
+ unsigned int index;
+ //__u8 hdr10plus[16];
+ } hdr10plusInfo[] = {{1},{2},{3},{4},{5},{6},{7},{8},{9}};
+
+ if (index >= vid->cap_buf_cnt) {
+ err("Tried to queue a non exisiting buffer");
+ return -1;
+ }
+ struct {
+ char *description;
+ unsigned int id;
+ void *data;
+ unsigned int size;
+ } controls[] = {{"HDR10", V4L2_CID_MPEG_VIDEO_VENUS_METADATA , &hdr10plusInfo[index], sizeof(hdr10plusInfo)}};
+ for (i = 0; i < ARRAY_SIZE(controls); i++) {
+ struct v4l2_ctrl_venus_metadata *meta = controls[i].data;
+ err("set_extra_control : vid->fd %d vid->request_fd_cap[%d] %d meta index %d",vid->fd,index,vid->request_fd_cap[index],meta->index);
+ rc = set_extra_control(vid->fd, vid->request_fd_cap[index], controls[i].id, controls[i].data,
+ controls[i].size);
+ if (rc < 0) {
+ err("Unable to set %s control\n", controls[i].description);
+ fprintf(stderr, "Unable to set %s control\n",strerror(errno));
+ return -1;
+ }
+ }
+ return rc;
+}
+
int video_export_buf(struct instance *i, unsigned int index)
{
struct video *vid = &i->video;
@@ -436,6 +472,8 @@ static int video_queue_buf(struct instance *i, unsigned int index,
if(type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE)
request_fd = vid->request_fd_out[index];
+ else
+ request_fd = vid->request_fd_cap[index];
if (request_fd >= 0) {
err("request_fd %d", request_fd);
buf.flags = V4L2_BUF_FLAG_REQUEST_FD;
@@ -490,6 +528,7 @@ int video_queue_buf_out(struct instance *i, unsigned int n, unsigned int length)
int video_queue_buf_cap(struct instance *i, unsigned int index)
{
+ int ret;
struct video *vid = &i->video;
if (index >= vid->cap_buf_cnt) {
@@ -497,10 +536,28 @@ int video_queue_buf_cap(struct instance *i, unsigned int index)
return -1;
}
- return video_queue_buf(i, index, vid->cap_buf_size[0],
+ ret = video_setup_extra_control_cap(i,index);
+ if (ret)
+ {
+ err("Unable to video_setup_extra_control_out: %s\n",strerror(errno));
+ return -1;
+ }
+ err("queuing output buffer %d", index);
+ ret = video_queue_buf(i, index, vid->cap_buf_size[0],
vid->cap_buf_size[1],
V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE,
CAP_PLANES);
+ if (ret)
+ {
+ err("Unable to video_queue_buf out : %s\n",strerror(errno));
+ return -1;
+ }
+ ret = ioctl(vid->request_fd_cap[index], MEDIA_REQUEST_IOC_QUEUE, NULL);
+ if (ret < 0) {
+ err("Unable to queue media request: %s\n",strerror(errno));
+ return -1;
+ }
+ return 0;
}
static int video_dequeue_buf(struct instance *i, struct v4l2_buffer *buf)
@@ -555,6 +612,8 @@ int video_dequeue_capture(struct instance *i, unsigned int *n,
{
struct v4l2_buffer buf;
struct v4l2_plane planes[CAP_PLANES];
+ int request_fd = -1;
+ int ret;
memzero(buf);
buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE;
@@ -577,6 +636,14 @@ int video_dequeue_capture(struct instance *i, unsigned int *n,
if (buf_flags)
*buf_flags = buf.flags;
+ request_fd = i->video.request_fd_cap[*n];
+ ret = ioctl(request_fd, MEDIA_REQUEST_IOC_REINIT, NULL);
+ if (ret < 0) {
+ fprintf(stderr, "Unable to reinit media request for fd %d: %s\n",
+ request_fd,strerror(errno));
+ //return -1;
+ }
+
return 0;
}
@@ -627,6 +694,7 @@ int video_setup_capture(struct instance *i, unsigned int count, unsigned int w,
struct v4l2_plane planes[CAP_PLANES];
unsigned int n;
int ret;
+ int request_fd = -1;
memzero(fmt);
fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE;
@@ -699,6 +767,14 @@ int video_setup_capture(struct instance *i, unsigned int count, unsigned int w,
}
vid->cap_buf_size[0] = buf.m.planes[0].length;
+
+ ret = ioctl(vid->media_fd, MEDIA_IOC_REQUEST_ALLOC, &request_fd);
+ if (ret) {
+ err("Unable to allocate media request %u (%s)", errno,strerror(errno));
+ return -1;
+ }
+ vid->request_fd_cap[n] = request_fd;
+ err("request_fd %d vid->request_fd_out[%d] %d", request_fd,n,vid->request_fd_cap[n]);
}
info("CAPTURE: Succesfully mmapped %u buffers", n);
diff --git a/video.h b/video.h
index aa44b0f..c16dfb3 100644
--- a/video.h
+++ b/video.h
@@ -67,6 +67,7 @@ int video_set_control(struct instance *i);
int set_extra_control(int video_fd, int request_fd, unsigned int id,
void *data, unsigned int size);
int video_setup_extra_control_out(struct instance *i, unsigned int index);
+int video_setup_extra_control_cap(struct instance *i, unsigned int index);
int video_stop(struct instance *i);