From 41fa9c1bdbd1f218478bc6a4ff777803f5ffbf3d Mon Sep 17 00:00:00 2001 From: jp9000 Date: Sat, 16 Jan 2016 10:36:53 -0800 Subject: [PATCH] libobs: Don't include sync offsets in TS smoothing Apply user sync offset *after* timestamp smoothing, not before. Prevents small or gradual sync offsets from not being properly applied. --- libobs/obs-internal.h | 1 + libobs/obs-source.c | 13 +++++++++++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/libobs/obs-internal.h b/libobs/obs-internal.h index eba9ee080..78f731bbf 100644 --- a/libobs/obs-internal.h +++ b/libobs/obs-internal.h @@ -559,6 +559,7 @@ struct obs_source { float user_volume; float volume; int64_t sync_offset; + int64_t last_sync_offset; /* async video data */ gs_texture_t *async_texture; diff --git a/libobs/obs-source.c b/libobs/obs-source.c index 86d205b32..c5bf54148 100644 --- a/libobs/obs-source.c +++ b/libobs/obs-source.c @@ -1111,6 +1111,7 @@ static void source_output_audio_data(obs_source_t *source, struct audio_data in = *data; uint64_t diff; uint64_t os_time = os_gettime_ns(); + int64_t sync_offset; bool using_direct_ts = false; bool push_back = false; @@ -1139,7 +1140,7 @@ static void source_output_audio_data(obs_source_t *source, source->next_audio_ts_min = in.timestamp + conv_frames_to_time(sample_rate, in.frames); - in.timestamp += source->timing_adjust + source->sync_offset; + in.timestamp += source->timing_adjust; if (source->next_audio_sys_ts_min == in.timestamp) { push_back = true; @@ -1149,10 +1150,18 @@ static void source_output_audio_data(obs_source_t *source, push_back = true; } + sync_offset = source->sync_offset; + in.timestamp += sync_offset; in.timestamp -= source->resample_offset; source->next_audio_sys_ts_min = source->next_audio_ts_min + - source->timing_adjust + source->sync_offset; + source->timing_adjust; + + if (source->last_sync_offset != sync_offset) { + if (source->last_sync_offset) + push_back = false; + source->last_sync_offset = sync_offset; + } pthread_mutex_lock(&source->audio_buf_mutex);