From 3f6aee6a13233e9ffcbb133ab9490aead7e2ced3 Mon Sep 17 00:00:00 2001 From: Kieran Bingham Date: Wed, 14 Dec 2022 23:17:31 +0000 Subject: main: Provide a libcamera source Allow callers to create a libcamera source when available. libcamera support is optional, so conditionally compile the new options depending on whether libcamera is available. Reviewed-by: Daniel Scally Signed-off-by: Kieran Bingham Reviewed-by: Kieran Bingham Signed-off-by: Daniel Scally --- meson.build | 9 +++++++++ src/main.c | 24 +++++++++++++++++++++++- src/meson.build | 2 +- 3 files changed, 33 insertions(+), 2 deletions(-) diff --git a/meson.build b/meson.build index c928170..8101676 100644 --- a/meson.build +++ b/meson.build @@ -55,6 +55,15 @@ cc = meson.get_compiler('c') libcamera = dependency('libcamera', required : false) +conf = configuration_data() + +if libcamera.found() + conf.set('HAVE_LIBCAMERA', true) +endif + +configure_file(output : 'config.h', configuration : conf) +config_includes = include_directories('.') + subdir('include') subdir('lib') diff --git a/src/main.c b/src/main.c index 0e8726a..cec622a 100644 --- a/src/main.c +++ b/src/main.c @@ -11,9 +11,11 @@ #include #include +#include "config.h" #include "configfs.h" #include "events.h" #include "stream.h" +#include "libcamera-source.h" #include "v4l2-source.h" #include "test-source.h" #include "jpg-source.h" @@ -23,6 +25,9 @@ static void usage(const char *argv0) { fprintf(stderr, "Usage: %s [options] \n", argv0); fprintf(stderr, "Available options are\n"); +#ifdef HAVE_LIBCAMERA + fprintf(stderr, " -c libcamera camera name\n"); +#endif fprintf(stderr, " -d device V4L2 source device\n"); fprintf(stderr, " -i image MJPEG image\n"); fprintf(stderr, " -s directory directory of slideshow images\n"); @@ -60,6 +65,9 @@ static void sigint_handler(int signal __attribute__((unused))) int main(int argc, char *argv[]) { char *function = NULL; +#ifdef HAVE_LIBCAMERA + char *camera = NULL; +#endif char *cap_device = NULL; char *img_path = NULL; char *slideshow_dir = NULL; @@ -71,8 +79,13 @@ int main(int argc, char *argv[]) int ret = 0; int opt; - while ((opt = getopt(argc, argv, "d:i:s:k:h")) != -1) { + while ((opt = getopt(argc, argv, "c:d:i:s:k:h")) != -1) { switch (opt) { +#ifdef HAVE_LIBCAMERA + case 'c': + camera = optarg; + break; +#endif case 'd': cap_device = optarg; break; @@ -124,6 +137,10 @@ int main(int argc, char *argv[]) /* Create and initialize a video source. */ if (cap_device) src = v4l2_video_source_create(cap_device); +#ifdef HAVE_LIBCAMERA + else if (camera) + src = libcamera_source_create(camera); +#endif else if (img_path) src = jpg_video_source_create(img_path); else if (slideshow_dir) @@ -138,6 +155,11 @@ int main(int argc, char *argv[]) if (cap_device) v4l2_video_source_init(src, &events); +#ifdef HAVE_LIBCAMERA + if (camera) + libcamera_source_init(src, &events); +#endif + /* Create and initialise the stream. */ stream = uvc_stream_new(fc->video); if (stream == NULL) { diff --git a/src/meson.build b/src/meson.build index a457c28..b2fdd9a 100644 --- a/src/meson.build +++ b/src/meson.build @@ -6,5 +6,5 @@ gadget = executable('uvc-gadget', 'main.c', dependencies : [ libuvcgadget, ], - include_directories : includes, + include_directories : [includes, config_includes], install : true) -- cgit v1.2.3