]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blobdiff - include/media/videobuf2-core.h
[media] v4l: vb2: Add a function to discard all DONE buffers
[mirror_ubuntu-bionic-kernel.git] / include / media / videobuf2-core.h
index af46211097269b3a47c38065f6f5567e3f615a4e..8fab6fa0dbfb08c7c8f272f7fa751db780a169a5 100644 (file)
@@ -20,6 +20,7 @@
 
 struct vb2_alloc_ctx;
 struct vb2_fileio_data;
+struct vb2_threadio_data;
 
 /**
  * struct vb2_mem_ops - memory handling/memory allocator operations
@@ -323,7 +324,7 @@ struct vb2_ops {
        void (*buf_cleanup)(struct vb2_buffer *vb);
 
        int (*start_streaming)(struct vb2_queue *q, unsigned int count);
-       int (*stop_streaming)(struct vb2_queue *q);
+       void (*stop_streaming)(struct vb2_queue *q);
 
        void (*buf_queue)(struct vb2_buffer *vb);
 };
@@ -375,6 +376,7 @@ struct v4l2_fh;
  * @start_streaming_called: start_streaming() was called successfully and we
  *             started streaming.
  * @fileio:    file io emulator internal data, used only if emulator is active
+ * @threadio:  thread io internal data, used only if thread is active
  */
 struct vb2_queue {
        enum v4l2_buf_type              type;
@@ -411,6 +413,7 @@ struct vb2_queue {
        unsigned int                    start_streaming_called:1;
 
        struct vb2_fileio_data          *fileio;
+       struct vb2_threadio_data        *threadio;
 
 #ifdef CONFIG_VIDEO_ADV_DEBUG
        /*
@@ -429,6 +432,7 @@ void *vb2_plane_vaddr(struct vb2_buffer *vb, unsigned int plane_no);
 void *vb2_plane_cookie(struct vb2_buffer *vb, unsigned int plane_no);
 
 void vb2_buffer_done(struct vb2_buffer *vb, enum vb2_buffer_state state);
+void vb2_discard_done(struct vb2_queue *q);
 int vb2_wait_for_all_buffers(struct vb2_queue *q);
 
 int vb2_querybuf(struct vb2_queue *q, struct v4l2_buffer *b);
@@ -461,6 +465,35 @@ size_t vb2_read(struct vb2_queue *q, char __user *data, size_t count,
                loff_t *ppos, int nonblock);
 size_t vb2_write(struct vb2_queue *q, const char __user *data, size_t count,
                loff_t *ppos, int nonblock);
+/**
+ * vb2_thread_fnc - callback function for use with vb2_thread
+ *
+ * This is called whenever a buffer is dequeued in the thread.
+ */
+typedef int (*vb2_thread_fnc)(struct vb2_buffer *vb, void *priv);
+
+/**
+ * vb2_thread_start() - start a thread for the given queue.
+ * @q:         videobuf queue
+ * @fnc:       callback function
+ * @priv:      priv pointer passed to the callback function
+ * @thread_name:the name of the thread. This will be prefixed with "vb2-".
+ *
+ * This starts a thread that will queue and dequeue until an error occurs
+ * or @vb2_thread_stop is called.
+ *
+ * This function should not be used for anything else but the videobuf2-dvb
+ * support. If you think you have another good use-case for this, then please
+ * contact the linux-media mailinglist first.
+ */
+int vb2_thread_start(struct vb2_queue *q, vb2_thread_fnc fnc, void *priv,
+                    const char *thread_name);
+
+/**
+ * vb2_thread_stop() - stop the thread for the given queue.
+ * @q:         videobuf queue
+ */
+int vb2_thread_stop(struct vb2_queue *q);
 
 /**
  * vb2_is_streaming() - return streaming status of the queue
@@ -471,6 +504,23 @@ static inline bool vb2_is_streaming(struct vb2_queue *q)
        return q->streaming;
 }
 
+/**
+ * vb2_fileio_is_active() - return true if fileio is active.
+ * @q:         videobuf queue
+ *
+ * This returns true if read() or write() is used to stream the data
+ * as opposed to stream I/O. This is almost never an important distinction,
+ * except in rare cases. One such case is that using read() or write() to
+ * stream a format using V4L2_FIELD_ALTERNATE is not allowed since there
+ * is no way you can pass the field information of each buffer to/from
+ * userspace. A driver that supports this field format should check for
+ * this in the queue_setup op and reject it if this function returns true.
+ */
+static inline bool vb2_fileio_is_active(struct vb2_queue *q)
+{
+       return q->fileio;
+}
+
 /**
  * vb2_is_busy() - return busy status of the queue
  * @q:         videobuf queue