libobs: Apply resampler offset to system audio TS
Instead of applying the resampler offset right away (to each audio packet), apply the resampler offset when the timestamps are converted to system timestamps. This fixes an issue where if audio timestamps reset to 0 (for whatever reason), the offset would cause the timestamp to go in to the negative.
This commit is contained in:
@@ -528,6 +528,7 @@ struct obs_source {
|
||||
/* timing (if video is present, is based upon video) */
|
||||
volatile bool timing_set;
|
||||
volatile uint64_t timing_adjust;
|
||||
uint64_t resample_offset;
|
||||
uint64_t next_audio_ts_min;
|
||||
uint64_t next_audio_sys_ts_min;
|
||||
uint64_t last_frame_ts;
|
||||
|
@@ -1149,6 +1149,8 @@ static void source_output_audio_data(obs_source_t *source,
|
||||
push_back = true;
|
||||
}
|
||||
|
||||
in.timestamp -= source->resample_offset;
|
||||
|
||||
source->next_audio_sys_ts_min = source->next_audio_ts_min +
|
||||
source->timing_adjust + source->sync_offset;
|
||||
|
||||
@@ -2219,6 +2221,7 @@ static inline void reset_resampler(obs_source_t *source,
|
||||
|
||||
audio_resampler_destroy(source->resampler);
|
||||
source->resampler = NULL;
|
||||
source->resample_offset = 0;
|
||||
|
||||
if (source->sample_info.samples_per_sec == obs_info->samples_per_sec &&
|
||||
source->sample_info.format == obs_info->format &&
|
||||
@@ -2298,16 +2301,15 @@ static void process_audio(obs_source_t *source,
|
||||
|
||||
if (source->resampler) {
|
||||
uint8_t *output[MAX_AV_PLANES];
|
||||
uint64_t offset;
|
||||
|
||||
memset(output, 0, sizeof(output));
|
||||
|
||||
audio_resampler_resample(source->resampler,
|
||||
output, &frames, &offset,
|
||||
output, &frames, &source->resample_offset,
|
||||
audio->data, audio->frames);
|
||||
|
||||
copy_audio_data(source, (const uint8_t *const *)output, frames,
|
||||
audio->timestamp - offset);
|
||||
audio->timestamp);
|
||||
} else {
|
||||
copy_audio_data(source, audio->data, audio->frames,
|
||||
audio->timestamp);
|
||||
|
Reference in New Issue
Block a user