alsa: don't read more than available samples

Keep the original available samples and use them to avoid reading
a chunk when there is not enough data.
This commit is contained in:
Wim Taymans 2022-02-16 21:30:54 +01:00
parent 56c03c11f8
commit e28b613404

View file

@ -2115,7 +2115,7 @@ int spa_alsa_read(struct state *state)
if (state->following && state->alsa_started) {
uint64_t current_time;
snd_pcm_uframes_t delay, target;
snd_pcm_uframes_t avail, delay, target;
uint32_t threshold = state->threshold;
current_time = state->position->clock.nsec;
@ -2123,6 +2123,8 @@ int spa_alsa_read(struct state *state)
if ((res = get_status(state, current_time, &delay, &target)) < 0)
return res;
avail = delay;
if (state->alsa_sync) {
spa_log_warn(state->log, "%s: follower delay:%lu target:%lu thr:%u, resync",
state->props.device, delay, target, threshold);
@ -2137,7 +2139,7 @@ int spa_alsa_read(struct state *state)
if ((res = update_time(state, current_time, delay, target, true)) < 0)
return res;
if (delay < state->read_size)
if (avail < state->read_size)
max_read = 0;
}