mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2025-10-29 05:40:27 -04:00
alsa: use get_avail() recover logic
Always use get_avail() and then only fetch the hires timestamp when enabled to enhance the delay reporting. This way we also recover from errors from snd_pcm_avail() instead of ignoring them. This should make the recover after mmap_begin obsolete but we'll leave that just to be safe.
This commit is contained in:
parent
c34a987076
commit
927eb64177
1 changed files with 30 additions and 44 deletions
|
|
@ -1990,32 +1990,21 @@ static int get_avail(struct state *state, uint64_t current_time, snd_pcm_uframes
|
|||
state->alsa_recovering = false;
|
||||
}
|
||||
*delay = avail;
|
||||
return avail;
|
||||
}
|
||||
|
||||
static int get_avail_htimestamp(struct state *state, uint64_t current_time, snd_pcm_uframes_t *delay)
|
||||
{
|
||||
int res, missed;
|
||||
snd_pcm_uframes_t avail;
|
||||
if (state->htimestamp) {
|
||||
snd_pcm_uframes_t havail;
|
||||
snd_htimestamp_t tstamp;
|
||||
uint64_t then;
|
||||
|
||||
avail = snd_pcm_avail(state->hndl);
|
||||
if ((res = snd_pcm_htimestamp(state->hndl, &avail, &tstamp)) < 0) {
|
||||
if ((res = alsa_recover(state, res)) < 0)
|
||||
return res;
|
||||
if ((res = snd_pcm_htimestamp(state->hndl, &avail, &tstamp)) < 0) {
|
||||
if ((res = snd_pcm_htimestamp(state->hndl, &havail, &tstamp)) < 0) {
|
||||
if ((missed = ratelimit_test(&state->rate_limit, current_time)) >= 0) {
|
||||
spa_log_warn(state->log, "%s: (%d missed) snd_pcm_htimestamp error: %s",
|
||||
state->props.device, missed, snd_strerror(res));
|
||||
}
|
||||
avail = state->threshold * 2;
|
||||
return avail;
|
||||
}
|
||||
} else {
|
||||
state->alsa_recovering = false;
|
||||
}
|
||||
*delay = avail;
|
||||
|
||||
avail = havail;
|
||||
*delay = havail;
|
||||
if ((then = SPA_TIMESPEC_TO_NSEC(&tstamp)) != 0) {
|
||||
int64_t diff;
|
||||
|
||||
|
|
@ -2042,7 +2031,8 @@ static int get_avail_htimestamp(struct state *state, uint64_t current_time, snd_
|
|||
}
|
||||
}
|
||||
}
|
||||
return SPA_MIN(avail, state->buffer_frames);
|
||||
}
|
||||
return avail;
|
||||
}
|
||||
|
||||
static int get_status(struct state *state, uint64_t current_time, snd_pcm_uframes_t *avail,
|
||||
|
|
@ -2051,11 +2041,7 @@ static int get_status(struct state *state, uint64_t current_time, snd_pcm_uframe
|
|||
int res;
|
||||
snd_pcm_uframes_t a, d;
|
||||
|
||||
if (state->htimestamp)
|
||||
res = get_avail_htimestamp(state, current_time, &d);
|
||||
else
|
||||
res = get_avail(state, current_time, &d);
|
||||
if (res < 0)
|
||||
if ((res = get_avail(state, current_time, &d)) < 0)
|
||||
return res;
|
||||
|
||||
a = SPA_MIN(res, (int)state->buffer_frames);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue