浏览代码

linux-v4l2: Add buffering option

Add a source property to enable buffering of frames, which is enabled by
default. This replaces the old "Use system timing" option by setting the
unbuffered source flag instead of using different timestamps.
While similar in intentions to the old option, this method should reduce
latency even more.
fryshorts 10 年之前
父节点
当前提交
cdbf193e2e
共有 2 个文件被更改,包括 18 次插入0 次删除
  1. 1 0
      plugins/linux-v4l2/data/locale/en-US.ini
  2. 17 0
      plugins/linux-v4l2/v4l2-input.c

+ 1 - 0
plugins/linux-v4l2/data/locale/en-US.ini

@@ -7,3 +7,4 @@ DVTiming="DV Timing"
 Resolution="Resolution"
 FrameRate="Frame Rate"
 LeaveUnchanged="Leave Unchanged"
+UseBuffering="Use Buffering"

+ 17 - 0
plugins/linux-v4l2/v4l2-input.c

@@ -225,6 +225,7 @@ static void v4l2_defaults(obs_data_t *settings)
 	obs_data_set_default_int(settings, "dv_timing", -1);
 	obs_data_set_default_int(settings, "resolution", -1);
 	obs_data_set_default_int(settings, "framerate", -1);
+	obs_data_set_default_bool(settings, "buffering", true);
 }
 
 /**
@@ -732,6 +733,9 @@ static obs_properties_t *v4l2_properties(void *vptr)
 			"framerate", obs_module_text("FrameRate"),
 			OBS_COMBO_TYPE_LIST, OBS_COMBO_FORMAT_INT);
 
+	obs_properties_add_bool(props,
+			"buffering", obs_module_text("UseBuffering"));
+
 	obs_data_t *settings = obs_source_get_settings(data->source);
 	v4l2_device_list(device_list, settings);
 	obs_data_release(settings);
@@ -873,6 +877,17 @@ fail:
 	v4l2_terminate(data);
 }
 
+/** Update source flags depending on the settings */
+static void v4l2_update_source_flags(struct v4l2_data *data,
+		obs_data_t *settings)
+{
+	uint32_t flags = obs_source_get_flags(data->source);
+	flags = (obs_data_get_bool(settings, "buffering"))
+			? flags & ~OBS_SOURCE_FLAG_UNBUFFERED
+			: flags | OBS_SOURCE_FLAG_UNBUFFERED;
+	obs_source_set_flags(data->source, flags);
+}
+
 /**
  * Update the settings for the v4l2 source
  *
@@ -898,6 +913,8 @@ 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");
 
+	v4l2_update_source_flags(data, settings);
+
 	v4l2_init(data);
 }