A proper way to differenciate whether the camera interface is connected?

I’m currently writing launchers that will warn the user if certain security confinement interface is not connected, however, I can find out a reliable way to detect the connection of the camera interface in the script(it seems that most access are also granted by the hardware-observe interface, which doesn’t differentiate the result), can anyone help?

Isnt the camera interface just allowing access to /dev/videoX ? so in shell something like:

[ -r /dev/video0 ] || echo "can not open camera !"

should be enough…

The -r conditional expression won’t work as the device file has read file permission:

$ snap disconnect guvcview:camera
$ snap run --shell guvcview
$ eval "$(head --lines=-1 ${SNAP}/command-guvcview.wrapper)"
guvcview(snap)$ ls -l /dev/video*
crw-rw-rw-+ 1 root root 81, 0 Dec 26 00:23 /dev/video0
crw-rw-rw-+ 1 root root 81, 1 Dec 26 00:23 /dev/video1
guvcview(snap)$ [ -r /dev/video0 ] || echo "can not open camera !"
guvcview(snap)$ v4l2-ctl --list-devices
Failed to open /dev/video0: Permission denied
guvcview(snap)$ 

Current implementation:

1 Like