From 7d3eedbcb01a76c17dd951611e38f21adaeed208 Mon Sep 17 00:00:00 2001 From: Skyler Lipthay Date: Mon, 23 Feb 2015 23:43:49 -0800 Subject: [PATCH] mac-avcapture: Default to unbuffered video capture By default, video plays back based upon the timestamp for each frame, and buffers the frames as needed to ensure that they play back at the expected timing. However, this can add some minor additional delay to the video, and may not be ideal for certain devices such as webcams and generally any device that has minimal latency. However, because those are the only type of devices that typically have drivers, there's no real need to have it on by default. This adds an option to use buffering, and leaves it off by default. Closes pull request #384 (message added by jim) --- plugins/mac-avcapture/av-capture.m | 21 +++++++++++++++++++++ plugins/mac-avcapture/data/locale/en-US.ini | 1 + 2 files changed, 22 insertions(+) diff --git a/plugins/mac-avcapture/av-capture.m b/plugins/mac-avcapture/av-capture.m index 1077809eb..ad9c298e7 100644 --- a/plugins/mac-avcapture/av-capture.m +++ b/plugins/mac-avcapture/av-capture.m @@ -243,6 +243,18 @@ static inline bool update_frame(struct av_capture *capture, } @end +static void av_capture_enable_buffering(struct av_capture *capture, + bool enabled) +{ + obs_source_t *source = capture->source; + uint32_t flags = obs_source_get_flags(source); + if (enabled) + flags &= ~OBS_SOURCE_FLAG_UNBUFFERED; + else + flags |= OBS_SOURCE_FLAG_UNBUFFERED; + obs_source_set_flags(source, flags); +} + static const char *av_capture_getname(void) { return TEXT_AVCAPTURE; @@ -569,6 +581,9 @@ static void *av_capture_create(obs_data_t *settings, obs_source_t *source) capture = NULL; } + av_capture_enable_buffering(capture, + obs_data_get_bool(settings, "buffering")); + return capture; } @@ -805,6 +820,9 @@ static obs_properties_t *av_capture_properties(void *unused) obs_property_set_modified_callback(preset_list, properties_preset_changed); + obs_properties_add_bool(props, "buffering", + obs_module_text("Buffering")); + return props; } @@ -847,6 +865,9 @@ static void av_capture_update(void *data, obs_data_t *settings) capture->session.sessionPreset = preset; AVLOG(LOG_INFO, "Selected preset %s", preset.UTF8String); + + av_capture_enable_buffering(capture, + obs_data_get_bool(settings, "buffering")); } struct obs_source_info av_capture_info = { diff --git a/plugins/mac-avcapture/data/locale/en-US.ini b/plugins/mac-avcapture/data/locale/en-US.ini index 1989133d4..be56ade8a 100644 --- a/plugins/mac-avcapture/data/locale/en-US.ini +++ b/plugins/mac-avcapture/data/locale/en-US.ini @@ -2,3 +2,4 @@ AVCapture="Video Capture Device" Device="Device" UsePreset="Use Preset" Preset="Preset" +Buffering="Use Buffering"