From ac40408dfa3ed54ff6ad19878b7817775fa58c7d Mon Sep 17 00:00:00 2001 From: fryshorts Date: Sat, 25 Oct 2014 17:55:02 +0200 Subject: [PATCH] linux-v4l2: Disable properties when device is not there. This adds helper function to disable/enable all properties which is used in the device selected callback to enable/disable the properties when the selected device is available/unavailable. --- plugins/linux-v4l2/v4l2-input.c | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/plugins/linux-v4l2/v4l2-input.c b/plugins/linux-v4l2/v4l2-input.c index 7c1fdcf45..a0cf79341 100644 --- a/plugins/linux-v4l2/v4l2-input.c +++ b/plugins/linux-v4l2/v4l2-input.c @@ -219,6 +219,30 @@ static void v4l2_defaults(obs_data_t *settings) obs_data_set_default_bool(settings, "system_timing", false); } +/** + * Enable/Disable all properties for the source. + * + * @note A property that should be ignored can be specified + * + * @param props the source properties + * @param ignore ignore this property + * @param enable enable/disable all properties + */ +static void v4l2_props_set_enabled(obs_properties_t *props, + obs_property_t *ignore, bool enable) +{ + if (!props) + return; + + for (obs_property_t *prop = obs_properties_first(props); prop != NULL; + obs_property_next(&prop)) { + if (prop == ignore) + continue; + + obs_property_set_enabled(prop, enable); + } +} + /* * List available devices */ @@ -461,9 +485,11 @@ static void v4l2_framerate_list(int dev, uint_fast32_t pixelformat, static bool device_selected(obs_properties_t *props, obs_property_t *p, obs_data_t *settings) { - UNUSED_PARAMETER(p); int dev = v4l2_open(obs_data_get_string(settings, "device_id"), O_RDWR | O_NONBLOCK); + + v4l2_props_set_enabled(props, p, (dev == -1) ? false : true); + if (dev == -1) return false;