[libcamera-devel] [PATCH] v4l2: Provide libcamera-v4l2 wrapper script

Kieran Bingham kieran.bingham at ideasonboard.com
Tue Jan 4 23:51:47 CET 2022


Support easier usage of the v4l2 compatibility layer with a script that
handles the LD_PRELOAD for applications.

The wrapper can be prefixed to launch any application with the preload
set:

 $ libcamera-v4l2 v4l2-ctl --list-devices
 \_SB_.PCI0.GP13.XHC0.RHUB.PRT4- (libcamera:0):
 	/dev/video0

 platform/vimc.0 Sensor B (libcamera:1):
 	/dev/video2
 	/dev/video3
 	/dev/video4

Signed-off-by: Kieran Bingham <kieran.bingham at ideasonboard.com>
---

This will install 'libcamera-v4l2' in the bindir (/usr/bin/) alongside
cam.

 src/v4l2/libcamera-v4l2.in | 11 +++++++++++
 src/v4l2/meson.build       | 14 ++++++++++++++
 2 files changed, 25 insertions(+)
 create mode 100755 src/v4l2/libcamera-v4l2.in

diff --git a/src/v4l2/libcamera-v4l2.in b/src/v4l2/libcamera-v4l2.in
new file mode 100755
index 000000000000..e8f77ec6d784
--- /dev/null
+++ b/src/v4l2/libcamera-v4l2.in
@@ -0,0 +1,11 @@
+#!/bin/sh
+
+if [ "$LD_PRELOAD" = "" ] ; then
+   LD_PRELOAD='@LIBCAMERA_V4L2_SO@'
+else
+   LD_PRELOAD="$LD_PRELOAD "'@LIBCAMERA_V4L2_SO@'
+fi
+
+export LD_PRELOAD
+
+exec "$@"
diff --git a/src/v4l2/meson.build b/src/v4l2/meson.build
index f78497b6799b..3b17668e8df5 100644
--- a/src/v4l2/meson.build
+++ b/src/v4l2/meson.build
@@ -33,3 +33,17 @@ v4l2_compat = shared_library('v4l2-compat',
                              install : true,
                              dependencies : [libcamera_private, libdl],
                              cpp_args : v4l2_compat_cpp_args)
+
+# Provide a wrapper script to support easily loading applications with the V4L2
+# adaptation layer
+
+config_h.set('LIBCAMERA_V4L2_SO', get_option('prefix') / get_option('libdir') / 'v4l2-compat.so')
+
+summary({
+    'LIBCAMERA_V4L2_SO' : config_h.get('LIBCAMERA_V4L2_SO'),
+}, section : 'Paths')
+
+configure_file(input : 'libcamera-v4l2.in',
+               output : 'libcamera-v4l2',
+               configuration : config_h,
+               install_dir : get_option('bindir'))
-- 
2.30.2



More information about the libcamera-devel mailing list