added OBS patch to deactivate v4l2 sources (by Julijane)
This commit is contained in:
parent
eb72ca45aa
commit
729be31a5d
2 changed files with 181 additions and 0 deletions
|
|
@ -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
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue