summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLaurent Pinchart <laurent.pinchart@ideasonboard.com>2018-06-09 12:43:16 +0300
committerLaurent Pinchart <laurent.pinchart@ideasonboard.com>2018-06-09 12:43:16 +0300
commite8fe6b593e1f10bd6aeb5f16674b6ee1142625c6 (patch)
tree1533eeb0b640b02dade590fcd71cac62a7fe0171
parentdf651c5b397a4b6648695cdf725a8243ff512dcd (diff)
video-source: Add abstract video source class
The video_source is an abstract class representing a source of video buffers. It can be subclassed by implementing the video_source_ops operations to support different types of video sources. Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
-rw-r--r--Makefile3
-rw-r--r--video-source.c62
-rw-r--r--video-source.h55
3 files changed, 119 insertions, 1 deletions
diff --git a/Makefile b/Makefile
index 484f533..c69bc94 100644
--- a/Makefile
+++ b/Makefile
@@ -14,7 +14,8 @@ OBJS := \
stream.o \
uvc.o \
v4l2.o \
- video-buffers.o
+ video-buffers.o \
+ video-source.o
all: uvc-gadget
diff --git a/video-source.c b/video-source.c
new file mode 100644
index 0000000..06092f5
--- /dev/null
+++ b/video-source.c
@@ -0,0 +1,62 @@
+/* SPDX-License-Identifier: LGPL-2.1-or-later */
+/*
+ * Abstract video source
+ *
+ * Copyright (C) 2018 Laurent Pinchart
+ *
+ * Contact: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
+ */
+
+#include "video-source.h"
+
+void video_source_set_buffer_handler(struct video_source *src,
+ video_source_buffer_handler_t handler,
+ void *data)
+{
+ src->handler = handler;
+ src->handler_data = data;
+}
+
+void video_source_destroy(struct video_source *src)
+{
+ if (src)
+ src->ops->destroy(src);
+}
+
+int video_source_set_format(struct video_source *src,
+ struct v4l2_pix_format *fmt)
+{
+ return src->ops->set_format(src, fmt);
+}
+
+int video_source_alloc_buffers(struct video_source *src, unsigned int nbufs)
+{
+ return src->ops->alloc_buffers(src, nbufs);
+}
+
+int video_source_export_buffers(struct video_source *src,
+ struct video_buffer_set **buffers)
+{
+ return src->ops->export_buffers(src, buffers);
+}
+
+int video_source_free_buffers(struct video_source *src)
+{
+ return src->ops->free_buffers(src);
+}
+
+int video_source_stream_on(struct video_source *src)
+{
+ return src->ops->stream_on(src);
+}
+
+int video_source_stream_off(struct video_source *src)
+{
+ return src->ops->stream_off(src);
+}
+
+int video_source_queue_buffer(struct video_source *src,
+ struct video_buffer *buf)
+{
+ return src->ops->queue_buffer(src, buf);
+}
diff --git a/video-source.h b/video-source.h
new file mode 100644
index 0000000..fffcba3
--- /dev/null
+++ b/video-source.h
@@ -0,0 +1,55 @@
+/* SPDX-License-Identifier: LGPL-2.1-or-later */
+/*
+ * Abstract video source
+ *
+ * Copyright (C) 2018 Laurent Pinchart
+ *
+ * Contact: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
+ */
+#ifndef __VIDEO_SOURCE_H__
+#define __VIDEO_SOURCE_H__
+
+struct v4l2_buffer;
+struct v4l2_pix_format;
+struct video_buffer;
+struct video_buffer_set;
+struct video_source;
+
+struct video_source_ops {
+ void(*destroy)(struct video_source *src);
+ int(*set_format)(struct video_source *src, struct v4l2_pix_format *fmt);
+ int(*alloc_buffers)(struct video_source *src, unsigned int nbufs);
+ int(*export_buffers)(struct video_source *src,
+ struct video_buffer_set **buffers);
+ int(*free_buffers)(struct video_source *src);
+ int(*stream_on)(struct video_source *src);
+ int(*stream_off)(struct video_source *src);
+ int(*queue_buffer)(struct video_source *src, struct video_buffer *buf);
+};
+
+typedef void(*video_source_buffer_handler_t)(void *, struct video_source *,
+ struct video_buffer *);
+
+struct video_source {
+ const struct video_source_ops *ops;
+ struct events *events;
+ video_source_buffer_handler_t handler;
+ void *handler_data;
+};
+
+void video_source_set_buffer_handler(struct video_source *src,
+ video_source_buffer_handler_t handler,
+ void *data);
+void video_source_destroy(struct video_source *src);
+int video_source_set_format(struct video_source *src,
+ struct v4l2_pix_format *fmt);
+int video_source_alloc_buffers(struct video_source *src, unsigned int nbufs);
+int video_source_export_buffers(struct video_source *src,
+ struct video_buffer_set **buffers);
+int video_source_free_buffers(struct video_source *src);
+int video_source_stream_on(struct video_source *src);
+int video_source_stream_off(struct video_source *src);
+int video_source_queue_buffer(struct video_source *src,
+ struct video_buffer *buf);
+
+#endif /* __VIDEO_SOURCE_H__ */