diff mbox series

[v4l-utils,v3,5/8] (c)v4l-helpers.h: Add support for the request api

Message ID 20190224084126.19412-6-dafna3@gmail.com (mailing list archive)
State New, archived
Headers show
Series add support to stateless decoder | expand

Commit Message

Dafna Hirschfeld Feb. 24, 2019, 8:41 a.m. UTC
Add an array of request file descriptors to v4l_queue
and add methods to allocate and get them.

Signed-off-by: Dafna Hirschfeld <dafna3@gmail.com>
---
 utils/common/cv4l-helpers.h |  5 +++++
 utils/common/v4l-helpers.h  | 22 ++++++++++++++++++++++
 2 files changed, 27 insertions(+)

Comments

Hans Verkuil Feb. 25, 2019, 10:38 a.m. UTC | #1
On 2/24/19 9:41 AM, Dafna Hirschfeld wrote:
> Add an array of request file descriptors to v4l_queue
> and add methods to allocate and get them.
> 
> Signed-off-by: Dafna Hirschfeld <dafna3@gmail.com>

This patch isn't right, just drop it altogether. These helpers are for v4l2 devices,
not for a media device.

Just use the media ioctls directly in v4l2-ctl and make the req_fds array a local
array in a function or perhaps a global in v4l2-ctl-streaming.cpp.

Regards,

	Hans

> ---
>  utils/common/cv4l-helpers.h |  5 +++++
>  utils/common/v4l-helpers.h  | 22 ++++++++++++++++++++++
>  2 files changed, 27 insertions(+)
> 
> diff --git a/utils/common/cv4l-helpers.h b/utils/common/cv4l-helpers.h
> index 1cd2b6b2..551d4673 100644
> --- a/utils/common/cv4l-helpers.h
> +++ b/utils/common/cv4l-helpers.h
> @@ -745,6 +745,7 @@ public:
>  	unsigned g_capabilities() const { return v4l_queue_g_capabilities(this); }
>  	unsigned g_length(unsigned plane) const { return v4l_queue_g_length(this, plane); }
>  	unsigned g_mem_offset(unsigned index, unsigned plane) const { return v4l_queue_g_mem_offset(this, index, plane); }
> +	unsigned g_req_fd(unsigned index) const { return v4l_queue_g_req_fd(this, index); }
>  	void *g_mmapping(unsigned index, unsigned plane) const { return v4l_queue_g_mmapping(this, index, plane); }
>  	void s_mmapping(unsigned index, unsigned plane, void *m) { v4l_queue_s_mmapping(this, index, plane, m); }
>  	void *g_userptr(unsigned index, unsigned plane) const { return v4l_queue_g_userptr(this, index, plane); }
> @@ -797,6 +798,10 @@ public:
>  	{
>  		return v4l_queue_export_bufs(fd->g_v4l_fd(), this, exp_type);
>  	}
> +	int alloc_req(int media_fd, unsigned index)
> +	{
> +		return v4l_queue_alloc_req(this, media_fd, index);
> +	}
>  	void close_exported_fds()
>  	{
>  		v4l_queue_close_exported_fds(this);
> diff --git a/utils/common/v4l-helpers.h b/utils/common/v4l-helpers.h
> index 59d8566a..daa49a1f 100644
> --- a/utils/common/v4l-helpers.h
> +++ b/utils/common/v4l-helpers.h
> @@ -10,6 +10,7 @@
>  #define _V4L_HELPERS_H_
>  
>  #include <linux/videodev2.h>
> +#include <linux/media.h>
>  #include <string.h>
>  #include <stdlib.h>
>  #include <stdio.h>
> @@ -1414,6 +1415,7 @@ struct v4l_queue {
>  	void *mmappings[VIDEO_MAX_FRAME][VIDEO_MAX_PLANES];
>  	unsigned long userptrs[VIDEO_MAX_FRAME][VIDEO_MAX_PLANES];
>  	int fds[VIDEO_MAX_FRAME][VIDEO_MAX_PLANES];
> +	int req_fds[VIDEO_MAX_FRAME];
>  };
>  
>  static inline void v4l_queue_init(struct v4l_queue *q,
> @@ -1445,6 +1447,11 @@ static inline __u32 v4l_queue_g_mem_offset(const struct v4l_queue *q, unsigned i
>  	return q->mem_offsets[index][plane];
>  }
>  
> +static inline unsigned v4l_queue_g_req_fd(const struct v4l_queue *q, unsigned index)
> +{
> +	return q->req_fds[index];
> +}
> +
>  static inline void v4l_queue_s_mmapping(struct v4l_queue *q, unsigned index, unsigned plane, void *m)
>  {
>  	q->mmappings[index][plane] = m;
> @@ -1701,6 +1708,21 @@ static inline int v4l_queue_export_bufs(struct v4l_fd *f, struct v4l_queue *q,
>  	return 0;
>  }
>  
> +static inline int v4l_queue_alloc_req(struct v4l_queue *q, int media_fd, unsigned index)
> +{
> +	int rc = 0;
> +
> +	rc = ioctl(media_fd, MEDIA_IOC_REQUEST_ALLOC, &q->req_fds[index]);
> +	if (rc < 0) {
> +		fprintf(stderr, "Unable to allocate media request: %s\n",
> +			strerror(errno));
> +		return rc;
> +	}
> +
> +	return 0;
> +}
> +
> +
>  static inline void v4l_queue_close_exported_fds(struct v4l_queue *q)
>  {
>  	unsigned b, p;
>
diff mbox series

Patch

diff --git a/utils/common/cv4l-helpers.h b/utils/common/cv4l-helpers.h
index 1cd2b6b2..551d4673 100644
--- a/utils/common/cv4l-helpers.h
+++ b/utils/common/cv4l-helpers.h
@@ -745,6 +745,7 @@  public:
 	unsigned g_capabilities() const { return v4l_queue_g_capabilities(this); }
 	unsigned g_length(unsigned plane) const { return v4l_queue_g_length(this, plane); }
 	unsigned g_mem_offset(unsigned index, unsigned plane) const { return v4l_queue_g_mem_offset(this, index, plane); }
+	unsigned g_req_fd(unsigned index) const { return v4l_queue_g_req_fd(this, index); }
 	void *g_mmapping(unsigned index, unsigned plane) const { return v4l_queue_g_mmapping(this, index, plane); }
 	void s_mmapping(unsigned index, unsigned plane, void *m) { v4l_queue_s_mmapping(this, index, plane, m); }
 	void *g_userptr(unsigned index, unsigned plane) const { return v4l_queue_g_userptr(this, index, plane); }
@@ -797,6 +798,10 @@  public:
 	{
 		return v4l_queue_export_bufs(fd->g_v4l_fd(), this, exp_type);
 	}
+	int alloc_req(int media_fd, unsigned index)
+	{
+		return v4l_queue_alloc_req(this, media_fd, index);
+	}
 	void close_exported_fds()
 	{
 		v4l_queue_close_exported_fds(this);
diff --git a/utils/common/v4l-helpers.h b/utils/common/v4l-helpers.h
index 59d8566a..daa49a1f 100644
--- a/utils/common/v4l-helpers.h
+++ b/utils/common/v4l-helpers.h
@@ -10,6 +10,7 @@ 
 #define _V4L_HELPERS_H_
 
 #include <linux/videodev2.h>
+#include <linux/media.h>
 #include <string.h>
 #include <stdlib.h>
 #include <stdio.h>
@@ -1414,6 +1415,7 @@  struct v4l_queue {
 	void *mmappings[VIDEO_MAX_FRAME][VIDEO_MAX_PLANES];
 	unsigned long userptrs[VIDEO_MAX_FRAME][VIDEO_MAX_PLANES];
 	int fds[VIDEO_MAX_FRAME][VIDEO_MAX_PLANES];
+	int req_fds[VIDEO_MAX_FRAME];
 };
 
 static inline void v4l_queue_init(struct v4l_queue *q,
@@ -1445,6 +1447,11 @@  static inline __u32 v4l_queue_g_mem_offset(const struct v4l_queue *q, unsigned i
 	return q->mem_offsets[index][plane];
 }
 
+static inline unsigned v4l_queue_g_req_fd(const struct v4l_queue *q, unsigned index)
+{
+	return q->req_fds[index];
+}
+
 static inline void v4l_queue_s_mmapping(struct v4l_queue *q, unsigned index, unsigned plane, void *m)
 {
 	q->mmappings[index][plane] = m;
@@ -1701,6 +1708,21 @@  static inline int v4l_queue_export_bufs(struct v4l_fd *f, struct v4l_queue *q,
 	return 0;
 }
 
+static inline int v4l_queue_alloc_req(struct v4l_queue *q, int media_fd, unsigned index)
+{
+	int rc = 0;
+
+	rc = ioctl(media_fd, MEDIA_IOC_REQUEST_ALLOC, &q->req_fds[index]);
+	if (rc < 0) {
+		fprintf(stderr, "Unable to allocate media request: %s\n",
+			strerror(errno));
+		return rc;
+	}
+
+	return 0;
+}
+
+
 static inline void v4l_queue_close_exported_fds(struct v4l_queue *q)
 {
 	unsigned b, p;