From d8a25ef94357d288d3a1f899efdaed889f02d5b1 Mon Sep 17 00:00:00 2001 From: Kurt Kartaltepe Date: Sun, 24 Jan 2021 21:46:02 -0800 Subject: [PATCH] linux-v4l2: Improve module detection Expand PATH for Debian-like systems. Improve detection when the module is already loaded. --- plugins/linux-v4l2/linux-v4l2.c | 15 ++------------- plugins/linux-v4l2/v4l2-output.c | 16 +++++++++++++++- 2 files changed, 17 insertions(+), 14 deletions(-) diff --git a/plugins/linux-v4l2/linux-v4l2.c b/plugins/linux-v4l2/linux-v4l2.c index 0df54450f..94f834665 100644 --- a/plugins/linux-v4l2/linux-v4l2.c +++ b/plugins/linux-v4l2/linux-v4l2.c @@ -26,18 +26,7 @@ MODULE_EXPORT const char *obs_module_description(void) extern struct obs_source_info v4l2_input; extern struct obs_output_info virtualcam_info; - -static bool v4l2loopback_installed() -{ - bool loaded = false; - - int ret = system("modinfo v4l2loopback >/dev/null 2>&1"); - - if (ret == 0) - loaded = true; - - return loaded; -} +extern bool loopback_module_available(); bool obs_module_load(void) { @@ -45,7 +34,7 @@ bool obs_module_load(void) obs_data_t *obs_settings = obs_data_create(); - if (v4l2loopback_installed()) { + if (loopback_module_available()) { obs_register_output(&virtualcam_info); obs_data_set_bool(obs_settings, "vcamEnabled", true); } else { diff --git a/plugins/linux-v4l2/v4l2-output.c b/plugins/linux-v4l2/v4l2-output.c index ab560cb66..a2031a656 100644 --- a/plugins/linux-v4l2/v4l2-output.c +++ b/plugins/linux-v4l2/v4l2-output.c @@ -50,10 +50,24 @@ static bool loopback_module_loaded() return loaded; } +bool loopback_module_available() +{ + if (loopback_module_loaded()) { + return true; + } + + if (system("PATH=\"$PATH:/sbin\" modinfo v4l2loopback >/dev/null 2>&1") == + 0) { + return true; + } + + return false; +} + static int loopback_module_load() { return system( - "pkexec modprobe v4l2loopback exclusive_caps=1 card_label='OBS Virtual Camera' && sleep 0.5"); + "PATH=\"$PATH:/sbin\" pkexec modprobe v4l2loopback exclusive_caps=1 card_label='OBS Virtual Camera' && sleep 0.5"); } static void *virtualcam_create(obs_data_t *settings, obs_output_t *output)