added OBS patch to deactivate v4l2 sources (by Julijane)

This commit is contained in:
4aiman 2023-12-04 22:44:42 +03:00
commit 729be31a5d
2 changed files with 181 additions and 0 deletions

View file

@ -0,0 +1,157 @@
From 1a5f42ff40a600ea0c5c9a337930f1ce8dd8019a Mon Sep 17 00:00:00 2001
From: 4aiman <konsorumaniakku@ya.ru>
Date: Mon, 4 Dec 2023 22:22:16 +0300
Subject: [PATCH] merge pull request 3159 (Add deactivate button to v4l2 devices)
---
plugins/linux-v4l2/data/locale/en-US.ini | 1 +
plugins/linux-v4l2/v4l2-input.c | 66 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++---
2 files changed, 64 insertions(+), 3 deletions(-)
diff --git a/plugins/linux-v4l2/data/locale/en-US.ini b/plugins/linux-v4l2/data/locale/en-US.ini
index f7d27cd..51087a8 100644
--- a/plugins/linux-v4l2/data/locale/en-US.ini
+++ b/plugins/linux-v4l2/data/locale/en-US.ini
@@ -13,5 +13,6 @@ ColorRange.Default="Default"
ColorRange.Partial="Limited"
ColorRange.Full="Full"
CameraCtrls="Camera Controls"
+DeactivateWhenNotShowing="Deactivate when not showing"
AutoresetOnTimeout="Autoreset on Timeout"
FramesUntilTimeout="Frames Until Timeout"
diff --git a/plugins/linux-v4l2/v4l2-input.c b/plugins/linux-v4l2/v4l2-input.c
index 3ba95cc..b202094 100644
--- a/plugins/linux-v4l2/v4l2-input.c
+++ b/plugins/linux-v4l2/v4l2-input.c
@@ -87,6 +87,9 @@ struct v4l2_data {
bool framerate_unchanged;
bool resolution_unchanged;
+ bool deactivate_when_not_showing;
+ bool active;
+
int_fast32_t dev;
int width;
int height;
@@ -318,6 +321,7 @@ static void v4l2_defaults(obs_data_t *settings)
obs_data_set_default_int(settings, "framerate", -1);
obs_data_set_default_int(settings, "color_range", VIDEO_RANGE_DEFAULT);
obs_data_set_default_bool(settings, "buffering", true);
+ obs_data_set_default_bool(settings, "deactivate_when_not_showing", false);
obs_data_set_default_bool(settings, "auto_reset", false);
obs_data_set_default_int(settings, "timeout_frames", 5);
}
@@ -889,6 +893,9 @@ static obs_properties_t *v4l2_properties(void *vptr)
obs_properties_add_bool(props, "buffering",
obs_module_text("UseBuffering"));
+ obs_properties_add_bool(props, "deactivate_when_not_showing",
+ obs_module_text("DeactivateWhenNotShowing"));
+
obs_properties_add_bool(props, "auto_reset",
obs_module_text("AutoresetOnTimeout"));
@@ -1124,6 +1131,10 @@ static bool v4l2_settings_changed(struct v4l2_data *data, obs_data_t *settings)
res |= data->color_range !=
obs_data_get_int(settings, "color_range");
+
+ res |= data->deactivate_when_not_showing !=
+ obs_data_get_bool(settings,
+ "deactivate_when_not_showing");
} else {
res = true;
}
@@ -1145,7 +1156,7 @@ static void v4l2_update(void *vptr, obs_data_t *settings)
bool needs_restart = v4l2_settings_changed(data, settings);
- if (needs_restart)
+ if (needs_restart && data->active)
v4l2_terminate(data);
if (data->device_id)
@@ -1159,22 +1170,69 @@ static void v4l2_update(void *vptr, obs_data_t *settings)
data->resolution = obs_data_get_int(settings, "resolution");
data->framerate = obs_data_get_int(settings, "framerate");
data->color_range = obs_data_get_int(settings, "color_range");
+ data->deactivate_when_not_showing =
+ obs_data_get_bool(settings, "deactivate_when_not_showing");
+ data->active = obs_data_get_bool(settings, "active") ||
+ !data->deactivate_when_not_showing;
data->auto_reset = obs_data_get_bool(settings, "auto_reset");
data->timeout_frames = obs_data_get_int(settings, "timeout_frames");
-
v4l2_update_source_flags(data, settings);
- if (needs_restart)
+ if (needs_restart && data->active) {
v4l2_init(data);
+ obs_data_set_bool(settings, "active", true);
+ }
+}
+
+/**
+ * Handle hide of input
+ */
+static void v4l2_hide(void *vptr)
+{
+ V4L2_DATA(vptr);
+
+ if (data->active) {
+ if (data->deactivate_when_not_showing) {
+ v4l2_terminate(data);
+ obs_source_output_video(data->source, NULL);
+ }
+
+ obs_data_t *settings;
+ settings = obs_source_get_settings(data->source);
+ obs_data_set_bool(settings, "active", false);
+ obs_data_release(settings);
+
+ data->active = false;
+ }
+}
+
+/**
+ * Handle show of input
+ */
+static void v4l2_show(void *vptr)
+{
+ V4L2_DATA(vptr);
+
+ if (!data->active) {
+ v4l2_init(data);
+
+ obs_data_t *settings;
+ settings = obs_source_get_settings(data->source);
+ obs_data_set_bool(settings, "active", true);
+ obs_data_release(settings);
+
+ data->active = true;
+ }
}
static void *v4l2_create(obs_data_t *settings, obs_source_t *source)
{
struct v4l2_data *data = bzalloc(sizeof(struct v4l2_data));
data->dev = -1;
data->source = source;
data->resolution_unchanged = false;
data->framerate_unchanged = false;
+ data->active = false;
/* Bitch about build problems ... */
#ifndef V4L2_CAP_DEVICE_CAPS
@@ -1207,6 +1265,8 @@ struct obs_source_info v4l2_input = {
.create = v4l2_create,
.destroy = v4l2_destroy,
.update = v4l2_update,
+ .hide = v4l2_hide,
+ .show = v4l2_show,
.get_defaults = v4l2_defaults,
.get_properties = v4l2_properties,
.icon_type = OBS_ICON_TYPE_CAMERA,
--
libgit2 1.7.1

24
one.md
View file

@ -18,6 +18,30 @@ In the end rav1e-git and dav1d-git will probably complain about ffmpeg depending
I've used a combination of pacman, pamac and pamac GUI to install all the needed things, cause none seect one would onlieg and do what I wanted it to do.
# Get back the ability to free webcams/capture cards when not in active use
As of 4th of December 2023 OBS on Linux (v 30.0!!!) still has no way to disable v4l2 devices when those are not in active use. <br>
The most baffling thing is that the patch was made by [julijane](https://github.com/obsproject/obs-studio/pull/3159/files) almost ***four years ago***.
Insane, right?
Anyway, this patch is for OBS 30.0 (more specifically the master branch) and all it does is gets in Julijane's changes.
Clone OBS, apply the [patch](Add%20deactivate%20button%20to%20v4l2%20devices%20--%20pr#3159%20--%20patch%20for%20OBS%2030.0%20with%20changes%20from%202020%20by%20julijane.patch)
via git and build. Onec done, you'll have that sweet "Disable when not showing" checkbox you love so much back.
In case you have no idea how to apply patches:
```
# Switch to the branch where the changes should be applied
$ git checkout master
# Apply the patch
$ git am bugfix.patch
# Check what has happened in the commit log
$ git log
```
# remove flatpak support
removing flatpaks from manjaro be like: