Prevent audio too far from expected timing

Audio that goes below the minimum expecting timing (current time -
buffering time) is automatically removed.  However, delayed audio is not
removed regardless of its delay.  This puts a hard cap of 6 seconds from
current time that the maximum delay audio can have.  This will also
prevent the circular buffer from dynamically growing too large.
master
jp9000 2014-09-03 12:26:23 -07:00
parent c5fdaef450
commit dc43438057
1 changed files with 12 additions and 4 deletions

View File

@ -695,11 +695,19 @@ static void audio_line_place_data(struct audio_line *line,
audio_line_place_data_pos(line, data, pos);
}
#define MAX_DELAY_NS 6000000000ULL
/* prevent insertation of data too far away from expected audio timing */
static inline bool valid_timestamp_range(struct audio_line *line, uint64_t ts)
{
uint64_t buffer_ns = 1000000ULL * line->audio->info.buffer_ms;
uint64_t max_ts = line->base_timestamp + buffer_ns + MAX_DELAY_NS;
return ts >= line->base_timestamp && ts < max_ts;
}
void audio_line_output(audio_line_t line, const struct audio_data *data)
{
/* TODO: prevent insertation of data too far away from expected
* audio timing */
if (!line || !data) return;
pthread_mutex_lock(&line->mutex);
@ -709,7 +717,7 @@ void audio_line_output(audio_line_t line, const struct audio_data *data)
line->audio->info.buffer_ms * 1000000;
audio_line_place_data(line, data);
} else if (line->base_timestamp <= data->timestamp) {
} else if (valid_timestamp_range(line, data->timestamp)) {
audio_line_place_data(line, data);
} else {