summaryrefslogtreecommitdiff
path: root/main.c
diff options
context:
space:
mode:
authorLaurent Pinchart <laurent.pinchart@ideasonboard.com>2018-06-09 12:13:38 +0300
committerLaurent Pinchart <laurent.pinchart@ideasonboard.com>2018-06-09 19:44:21 +0300
commit1b8f9204db684eff0d52b03c47fa666bf4e495f5 (patch)
tree02fadfefd72b45a6356f36f5442212aa772425bc /main.c
parentde8d802f21e002270b0b758835fa25232a31208e (diff)
stream: Use abstract video sources
Replace the manual V4L2 capture implementation by an abstract video_source, provided by the user of the UVC stream. Removes any knowledge of the video source internals from the uvc_stream class, allowing usage of different source types. Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Diffstat (limited to 'main.c')
-rw-r--r--main.c17
1 files changed, 15 insertions, 2 deletions
diff --git a/main.c b/main.c
index a99659b..70af57f 100644
--- a/main.c
+++ b/main.c
@@ -24,6 +24,7 @@
#include "configfs.h"
#include "events.h"
#include "stream.h"
+#include "v4l2-source.h"
static void usage(const char *argv0)
{
@@ -56,7 +57,7 @@ static void usage(const char *argv0)
/* Necessary for and only used by signal handler. */
static struct events *sigint_events;
-static void sigint_handler(int signal __attribute__((__unused__)))
+static void sigint_handler(int signal)
{
/* Stop the main loop when the user presses CTRL-C */
events_stop(sigint_events);
@@ -68,6 +69,7 @@ int main(int argc, char *argv[])
char *cap_device = "/dev/video1";
struct uvc_function_config *fc;
struct uvc_stream *stream;
+ struct video_source *src = NULL;
struct events events;
int ret = 0;
int opt;
@@ -108,14 +110,24 @@ int main(int argc, char *argv[])
sigint_events = &events;
signal(SIGINT, sigint_handler);
+ /* Create and initialize a video source. */
+ src = v4l2_video_source_create(cap_device);
+ if (src == NULL) {
+ ret = 1;
+ goto done;
+ }
+
+ v4l2_video_source_init(src, &events);
+
/* Create and initialise the stream. */
- stream = uvc_stream_new(fc->video, cap_device);
+ stream = uvc_stream_new(fc->video);
if (stream == NULL) {
ret = 1;
goto done;
}
uvc_stream_set_event_handler(stream, &events);
+ uvc_stream_set_video_source(stream, src);
uvc_stream_init_uvc(stream, fc);
/* Main capture loop */
@@ -124,6 +136,7 @@ int main(int argc, char *argv[])
done:
/* Cleanup */
uvc_stream_delete(stream);
+ video_source_destroy(src);
events_cleanup(&events);
configfs_free_uvc_function(fc);