From d6ec5438a84bd598be666bd8e40af711603a834f Mon Sep 17 00:00:00 2001 From: jp9000 Date: Thu, 20 Feb 2014 16:16:25 -0700 Subject: [PATCH] Add source audio sync offset setting --- libobs/obs-internal.h | 1 + libobs/obs-source.c | 26 ++++++++++++++++++++------ libobs/obs.h | 6 ++++++ 3 files changed, 27 insertions(+), 6 deletions(-) diff --git a/libobs/obs-internal.h b/libobs/obs-internal.h index 5afd05c3b..4961960fd 100644 --- a/libobs/obs-internal.h +++ b/libobs/obs-internal.h @@ -209,6 +209,7 @@ struct obs_source { size_t audio_storage_size; float user_volume; float present_volume; + int64_t sync_offset; /* async video data */ texture_t output_texture; diff --git a/libobs/obs-source.c b/libobs/obs-source.c index c96b641c3..9d60de213 100644 --- a/libobs/obs-source.c +++ b/libobs/obs-source.c @@ -95,6 +95,7 @@ bool obs_source_init(struct obs_source *source, source->refs = 1; source->user_volume = 1.0f; source->present_volume = 1.0f; + source->sync_offset = 0; pthread_mutex_init_value(&source->filter_mutex); pthread_mutex_init_value(&source->video_mutex); pthread_mutex_init_value(&source->audio_mutex); @@ -388,7 +389,7 @@ static void source_output_audio_line(obs_source_t source, if (source->audio_reset_ref != 0) return; - in.timestamp += source->timing_adjust; + in.timestamp += source->timing_adjust + source->sync_offset; in.volume = source->user_volume * source->present_volume * obs->audio.user_volume * obs->audio.present_volume; @@ -1126,25 +1127,38 @@ signal_handler_t obs_source_signalhandler(obs_source_t source) proc_handler_t obs_source_prochandler(obs_source_t source) { - return source->procs; + return source ? source->procs : NULL; } void obs_source_setvolume(obs_source_t source, float volume) { - source->user_volume = volume; + if (source) + source->user_volume = volume; } void obs_source_set_present_volume(obs_source_t source, float volume) { - source->present_volume = volume; + if (source) + source->present_volume = volume; } float obs_source_getvolume(obs_source_t source) { - return source->user_volume; + return source ? source->user_volume : 0.0f; } float obs_source_get_present_volume(obs_source_t source) { - return source->present_volume; + return source ? source->present_volume : 0.0f; +} + +void obs_source_set_sync_offset(obs_source_t source, int64_t offset) +{ + if (source) + source->sync_offset = offset; +} + +int64_t obs_source_get_sync_offset(obs_source_t source) +{ + return source ? source->sync_offset : 0; } diff --git a/libobs/obs.h b/libobs/obs.h index fd4f833cf..a26685991 100644 --- a/libobs/obs.h +++ b/libobs/obs.h @@ -504,6 +504,12 @@ EXPORT float obs_source_getvolume(obs_source_t source); /** Gets the presentation volume for a source */ EXPORT float obs_source_get_present_volume(obs_source_t source); +/** Sets the audio sync offset (in nanoseconds) for a source */ +EXPORT void obs_source_set_sync_offset(obs_source_t source, int64_t offset); + +/** Gets the audio sync offset (in nanoseconds) for a source */ +EXPORT int64_t obs_source_get_sync_offset(obs_source_t source); + /* ------------------------------------------------------------------------- */ /* Functions used by sources */