[libcamera-devel] v4l2: Provide libcamera-v4l2 wrapper script
diff mbox series

Message ID 20220104225147.1340786-1-kieran.bingham@ideasonboard.com
State Superseded
Delegated to: Kieran Bingham
Headers show
Series
  • [libcamera-devel] v4l2: Provide libcamera-v4l2 wrapper script
Related show

Commit Message

Kieran Bingham Jan. 4, 2022, 10:51 p.m. UTC
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@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

Comments

Kieran Bingham Jan. 4, 2022, 10:57 p.m. UTC | #1
I should have mentioned, this was heavily inspired by Wim Taymans
implementation at
  https://github.com/PipeWire/pipewire/blob/master/pipewire-v4l2/src/pw-v4l2.in

Where I think their V4L2 layer was inspired by ours ;-)
--
Kieran


Quoting Kieran Bingham (2022-01-04 22:51:47)
> 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@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
>

Patch
diff mbox series

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'))