fangfufu / Linux-Fake-Background-Webcam

Faking your webcam background under GNU/Linux, now supports background blurring, animated background, colour map effect, hologram effect and on-demand processing.
GNU General Public License v3.0
1.6k stars 161 forks source link

Move inotify checks to separate thread #162

Closed ObsidianX closed 3 years ago

ObsidianX commented 3 years ago

Querying the inotify watcher causes the camera to freeze momentarily every time it's queried since load_images() is called several times when consumers > 0. This moves it to its own thread so it doesn't interrupt the stream.

The primary fix is simply unindenting lines 299:306 pre-patch (101:108 post-patch) which will prevent the momentary freeze, but continuously querying inotify in the same loop as the camera stream noticeably reduces the framerate.

fangfufu commented 3 years ago

Okay I didn't quite get what you are saying, but here is my understanding:

  1. Inotify pauses the webcam the same way as sigint pauses the webcam. That causes the image to be reloaded when inotify causes pausing, which leads to the camera to freeze momentarily. So you put pausing by sigint in its own thread.
  2. You decided to put inotify stuff in a separate thread, because having it in the main loop reduces performance.

Multithreading implementation used to cause stability issue (https://github.com/fangfufu/Linux-Fake-Background-Webcam/issues/116), but I suppose you are not passing numpy array around. So I am okay with this.

fangfufu commented 3 years ago

Something went wrong with the merge (https://github.com/fangfufu/Linux-Fake-Background-Webcam/issues/163). I am investigating. If I clone your repository and run it directly, it seems to work fine.

fangfufu commented 3 years ago

Actually your patch is broken from https://github.com/ObsidianX/Linux-Fake-Background-Webcam/commit/4619a7479e3f30e39ccc689a9e95afe536c31e42

I should have checked it properly. I cloned your repository - I couldn't be bothered to download the pull request and merge it locally. I didn't realise that you were contributing from a branch of your fork. I thought you were working on the master branch of your fork directly.

ObsidianX commented 3 years ago

Actually your patch is broken from ObsidianX@4619a74

I should have checked it properly. I cloned your repository - I couldn't be bothered to download the pull request and merge it locally. I didn't realise that you were contributing from a branch of your fork. I thought you were working on the master branch of your fork directly.

Hmm, strange. I made my branch based on master, but might not have pulled recently enough. I'll rebase and retest. My apologies!