From 875398e9ddc87ee38867b2dbc50fe18f4e661795 Mon Sep 17 00:00:00 2001 From: fryshorts Date: Tue, 16 Sep 2014 20:46:04 +0200 Subject: [PATCH] Refactor update function for v4l2 input. The old implementation of this function assumed that there would be some settings that could be changed on the fly without restarting the capture. That was actually never used for any setting. --- plugins/linux-v4l2/v4l2-input.c | 48 ++++++++++++--------------------- 1 file changed, 17 insertions(+), 31 deletions(-) diff --git a/plugins/linux-v4l2/v4l2-input.c b/plugins/linux-v4l2/v4l2-input.c index 05b08918e..991bd9057 100644 --- a/plugins/linux-v4l2/v4l2-input.c +++ b/plugins/linux-v4l2/v4l2-input.c @@ -643,44 +643,30 @@ fail: v4l2_terminate(data); } +/** + * Update the settings for the v4l2 source + * + * Since there are very few settings that can be changed without restarting the + * stream we don't bother to even try. Whenever this is called the currently + * active stream (if exists) is stopped, the settings are updated and finally + * the new stream is started. + */ static void v4l2_update(void *vptr, obs_data_t settings) { V4L2_DATA(vptr); - bool restart = false; - const char *new_device; - new_device = obs_data_get_string(settings, "device_id"); - if (!data->set_device || strcmp(data->set_device, new_device) != 0) { - if (data->set_device) - bfree(data->set_device); - data->set_device = bstrdup(new_device); - restart = true; - } + v4l2_terminate(data); - if (data->set_input != obs_data_get_int(settings, "input")) { - data->set_input = obs_data_get_int(settings, "input"); - restart = true; - } + if (data->set_device) + bfree(data->set_device); - if (data->set_pixfmt != obs_data_get_int(settings, "pixelformat")) { - data->set_pixfmt = obs_data_get_int(settings, "pixelformat"); - restart = true; - } + data->set_device = bstrdup(obs_data_get_string(settings, "device_id")); + data->set_input = obs_data_get_int(settings, "input"); + data->set_pixfmt = obs_data_get_int(settings, "pixelformat"); + data->set_res = obs_data_get_int(settings, "resolution"); + data->set_fps = obs_data_get_int(settings, "framerate"); - if (data->set_res != obs_data_get_int(settings, "resolution")) { - data->set_res = obs_data_get_int(settings, "resolution"); - restart = true; - } - - if (data->set_fps != obs_data_get_int(settings, "framerate")) { - data->set_fps = obs_data_get_int(settings, "framerate"); - restart = true; - } - - if (restart) { - v4l2_terminate(data); - v4l2_init(data); - } + v4l2_init(data); } static void *v4l2_create(obs_data_t settings, obs_source_t source)