libobs: Discard remainder audio if source audio stopped

If the circular audio buffer of the source has data remaining that's
less than the audio frame tick count (1024 frames), it would just leave
that audio data on the source without discarding it.  However, this
could cause audio buffering to increase unnecessarily under certain
circumstances (when the next audio timestamp is within the timestamp
jump window), so it would append data to that circular buffer despite
the audio stopping that long ago, causing audio buffering to have to
increase to compensate.

Instead, just discard pending audio if it hasn't been written to.  In
other words, if the audio has stopped and there's insufficient audio
left to continue processing.
This commit is contained in:
jp9000
2016-01-30 15:14:47 -08:00
parent 9aa18d3de5
commit 4b15880231
2 changed files with 37 additions and 0 deletions

View File

@@ -93,6 +93,37 @@ static void ignore_audio(obs_source_t *source, size_t channels,
}
}
static bool discard_if_stopped(obs_source_t *source, size_t channels)
{
size_t last_size;
size_t size;
last_size = source->last_audio_input_buf_size;
size = source->audio_input_buf[0].size;
if (!size)
return false;
/* if perpetually pending data, it means the audio has stopped,
* so clear the audio data */
if (last_size == size) {
for (size_t ch = 0; ch < channels; ch++)
circlebuf_pop_front(&source->audio_input_buf[ch], NULL,
source->audio_input_buf[ch].size);
source->audio_ts = 0;
source->last_audio_input_buf_size = 0;
#if DEBUG_AUDIO == 1
blog(LOG_DEBUG, "source audio data appears to have "
"stopped, clearing");
#endif
return true;
} else {
source->last_audio_input_buf_size = size;
return false;
}
}
static inline void discard_audio(struct obs_core_audio *audio,
obs_source_t *source, size_t channels, size_t sample_rate,
struct ts_info *ts)
@@ -120,6 +151,8 @@ static inline void discard_audio(struct obs_core_audio *audio,
}
if (source->audio_ts < (ts->start - 1)) {
if (discard_if_stopped(source, channels))
return;
#if DEBUG_AUDIO == 1
if (is_audio_source) {
blog(LOG_DEBUG, "can't discard, source "
@@ -152,6 +185,9 @@ static inline void discard_audio(struct obs_core_audio *audio,
size = total_floats * sizeof(float);
if (source->audio_input_buf[0].size < size) {
if (discard_if_stopped(source, channels))
return;
#if DEBUG_AUDIO == 1
if (is_audio_source)
blog(LOG_DEBUG, "can't discard, data still pending");

View File

@@ -544,6 +544,7 @@ struct obs_source {
struct obs_source **prev_next_audio_source;
uint64_t audio_ts;
struct circlebuf audio_input_buf[MAX_AUDIO_CHANNELS];
size_t last_audio_input_buf_size;
DARRAY(struct audio_action) audio_actions;
float *audio_output_buf[MAX_AUDIO_MIXES][MAX_AUDIO_CHANNELS];
struct resample_info sample_info;