ha-mqtt-iot
ha-mqtt-iot copied to clipboard
`camera_sensor.sh` not accurate when using Wireplumber and/or Pipewire.
These processes will show as using the camera. This is likely going to be the case moving forward, especially under Wayland. This present a challenge, as we may instead need to check Pipewire for camera status instead.
Stupid question - as far as I understand the fuser command it checks if the camera is used by a process.
Quote from the manpage
fuser displays the PIDs of processes using the specified files or file systems.
To be honest, I have not so much experience with pipewire. But even with pipewire fuser should be a reliable source if the camera is in use or not. If I am wrong - please correct me. New knowledge is always welcome on my side :-)
In my case, pipewire and wireplumber both are reported as using it even when the camera isn't actually in use.
Interesting - I run pipewire and I have not the issue - but to be honest, I am not very familiar with pipewire. Yesterday I had a video conference and the sensors works well. I use Arch Linux - and if I am correct you as well (acorrding to your config template :-))
More than a year later...
fuser and lsof remain to be not very good for detecting whether or not the camera is in active use. fuser just gives a list of PIDs and nothing else, which is quite useless, but lsof might be usable.
I've been observing the output from lsof and as @W-Floyd said, wireplumb and pipewire are always there no matter what the camera is doing. Even if it's sitting idle without recording, those two are there. But when I start using the camera actively, on the browser or inside the Zoom desktop app or whatever, they appear as new processes in the lsof output AND they look different. They always appear like this:
One process as two lines in the output, one with mem as the file descriptor. Firefox does the same. Discord does the same. Maybe that can be used to detect that the camera is currently being used to capture video. Though I don't know what those mean exactly, so it might not be as useful as I wish.
Also, for some reason, Cheese doesn't show up on lsof even when it's actively using the camera. That means there are ways around lsof too.