Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ondemand does not work for WebEx #186

Open
mulbc opened this issue Jan 16, 2023 · 14 comments
Open

ondemand does not work for WebEx #186

mulbc opened this issue Jan 16, 2023 · 14 comments

Comments

@mulbc
Copy link

mulbc commented Jan 16, 2023

Great project here! I tried to use it for WebEx, but the ondemand feature doesn't work for the in-browser tool. It always registers just one consumer and thus pauses the webcam.
When I unpause it using Ctrl+C, it immediately re-pauses again.

Checking out the same thing with Google Meet, it works fine (same browser, same everything)

I checked the code and maybe listenting to inodes isn't the best approach? Maybe using something like fuser $V4L2LOOPBACK_PATH (which lists the processes accessing the device) might work better?
This might also help with #167

Environment:
Browser Chrome
OS Fedora 36
v4l2loopback

@fangfufu
Copy link
Owner

Do you have suggestion of using anything other than inotify?

@mulbc
Copy link
Author

mulbc commented Jan 17, 2023

yes, as I said, we could use lsof/fuser capabilities to check the open files by processes. That way we can count the PIDs that have our V4L2LOOPBACK device open. We can directly use this as the count of consumers in the existing code.
Unfortunately there do not appear to be libraries for lsof/fuser, so we would need to use a syscall for this. Would you be ok with that?

@mulbc
Copy link
Author

mulbc commented Jan 17, 2023

We could also look into what WebEx does differently to Google Meet in regards to inotify, but I'm unsure how I would debug that

@mulbc
Copy link
Author

mulbc commented Jan 17, 2023

So I was able to capture the inotify messages for WebEx and Google Meet

WebEx:

/dev/video2 CLOSE_WRITE,CLOSE 
/dev/video2 OPEN 
/dev/video2 CLOSE_NOWRITE,CLOSE 
/dev/video2 OPEN 
/dev/video2 CLOSE_NOWRITE,CLOSE 
/dev/video2 OPEN 
/dev/video2 CLOSE_NOWRITE,CLOSE 
/dev/video2 OPEN 
/dev/video2 CLOSE_NOWRITE,CLOSE 
/dev/video2 OPEN 
/dev/video2 CLOSE_NOWRITE,CLOSE 
/dev/video2 OPEN 
/dev/video2 CLOSE_NOWRITE,CLOSE 
/dev/video2 OPEN 
/dev/video2 CLOSE_NOWRITE,CLOSE 
/dev/video2 OPEN 
/dev/video2 CLOSE_NOWRITE,CLOSE 
/dev/video2 OPEN             <-- This is the double OPEN which should add the consumer to fake.py
/dev/video2 OPEN 
/dev/video2 CLOSE_NOWRITE,CLOSE 
/dev/video2 OPEN 
/dev/video2 CLOSE_NOWRITE,CLOSE 
/dev/video2 OPEN 
/dev/video2 CLOSE_NOWRITE,CLOSE 
/dev/video2 OPEN 
/dev/video2 CLOSE_NOWRITE,CLOSE 
/dev/video2 OPEN 
/dev/video2 CLOSE_NOWRITE,CLOSE 
/dev/video2 OPEN 
/dev/video2 CLOSE_NOWRITE,CLOSE 
/dev/video2 OPEN 
/dev/video2 CLOSE_NOWRITE,CLOSE 
/dev/video2 OPEN 
/dev/video2 CLOSE_NOWRITE,CLOSE 
/dev/video2 OPEN 
/dev/video2 CLOSE_NOWRITE,CLOSE 
/dev/video2 OPEN 
/dev/video2 CLOSE_NOWRITE,CLOSE 
/dev/video2 OPEN 
/dev/video2 CLOSE_NOWRITE,CLOSE 
/dev/video2 OPEN 
/dev/video2 CLOSE_NOWRITE,CLOSE 
/dev/video2 OPEN 
/dev/video2 CLOSE_NOWRITE,CLOSE 
      --> Leaving meeting, camera access closes
/dev/video2 CLOSE_WRITE,CLOSE 

Google Meet:

  One OPEN/CLOSE before we even join the meeting (while on meet.google.com)
/dev/video2 OPEN 
/dev/video2 CLOSE_NOWRITE,CLOSE 
--> Joining the meeting
/dev/video2 OPEN 
/dev/video2 CLOSE_NOWRITE,CLOSE 
/dev/video2 OPEN 
/dev/video2 CLOSE_NOWRITE,CLOSE 
/dev/video2 OPEN 
/dev/video2 CLOSE_NOWRITE,CLOSE 
/dev/video2 OPEN 
/dev/video2 CLOSE_NOWRITE,CLOSE 
/dev/video2 OPEN 
/dev/video2 CLOSE_NOWRITE,CLOSE 
/dev/video2 OPEN 
/dev/video2 CLOSE_NOWRITE,CLOSE 
/dev/video2 OPEN 
/dev/video2 CLOSE_NOWRITE,CLOSE 
/dev/video2 OPEN      --> Double OPEN to mark the consumer in fake.py
/dev/video2 OPEN 
/dev/video2 CLOSE_NOWRITE,CLOSE 
/dev/video2 OPEN 
/dev/video2 CLOSE_NOWRITE,CLOSE 
/dev/video2 OPEN 
/dev/video2 CLOSE_NOWRITE,CLOSE 
/dev/video2 CLOSE_WRITE,CLOSE --> Leaving the meeting, double CLOSE
/dev/video2 OPEN 
/dev/video2 CLOSE_NOWRITE,CLOSE 
/dev/video2 OPEN 
/dev/video2 CLOSE_NOWRITE,CLOSE 
/dev/video2 OPEN 
/dev/video2 CLOSE_NOWRITE,CLOSE 

In the end this might be a timing issue with the inotify messages coming in too quickly, thus we do not catch all of them?

Command to capture the messages is

inotifywait --inotify -m /dev/video2 | grep -v MODIFY

@fangfufu
Copy link
Owner

If you provide a patch, I am happy to review it and merge it in. :)

@mulbc
Copy link
Author

mulbc commented Jan 19, 2023

Just FYI - I did rewrite the code so that the inotify part is in a separate thread, but for some reason, it still doesn't reliably detect webcam usage (that's why you didn't get a PR yet)
I will see if/how I can do that better with fuser now

@fangfufu
Copy link
Owner

What's fuser?

@mulbc
Copy link
Author

mulbc commented Jan 25, 2023

It's a linux cli tool to list processes using a certain file:
https://man7.org/linux/man-pages/man1/fuser.1.html

@gchamon
Copy link

gchamon commented Feb 9, 2023

Using google chrome and gather.town I was unable to find a reliable pattern to make the ondemand work:

image

Each number is me toggling the fake camera (by configuring a different device in the app).

I guess this isn't a reliable method overall to detect consumers, maybe.


EDIT
sometimes it works as expected:

image

Still I guess this makes for the argument that this method is indeed unreliable.


EDIT2

Maybe something could be done with lsof?
image

We would have to make sure to filter out all system applications.

@machineghost
Copy link

Just two cents from a random user: making a command you can't CTRL+C, and have to close the entire terminal just to terminate, is very frustrating.

@fangfufu
Copy link
Owner

@machineghost , you can use CTRL + \ to terminate. That sends SIGKILL.

@machineghost
Copy link

I've run Linux for over a decade and never had to kill a command that way. I think it's fair to assume a decent percentage of other users won't magically know to do CTRL + \.

@fangfufu
Copy link
Owner

Well if you have better suggestions on which signal I should intercept to support changing background while the webcam is open, do let me know. :)

@machineghost
Copy link

CTRL+ C is pretty much the universal "cancel" signal. Failing that, CTRL + D is the fairly universal "disconnect" signal.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants