alsa: Use hi-res timestamps in irq mode when available

We know in IRQ mode that any valid hi-res timestamp that the
driver privides will be before the wakeup event in pipewire.

This makes it so in IRQ mode we use better timestamping when possible,
which decreases jitter injected into the DLL, which in turn reduces
the amount of oscillations the resampler is exposed to.
This commit is contained in:
Dimitrios Katsaros 2024-03-01 21:36:47 +01:00
parent 0cfe57f33d
commit c1eacce3fc

View file

@ -3239,8 +3239,19 @@ static void alsa_irq_wakeup_event(struct spa_source *source)
uint64_t current_time; uint64_t current_time;
int res, err; int res, err;
unsigned short revents; unsigned short revents;
snd_pcm_uframes_t havail;
snd_htimestamp_t tstamp;
// First, take a snapshot of the wakeup time
current_time = get_time_ns(state); current_time = get_time_ns(state);
// If the hi-res timestamps are working, we will get a timestamp that
// is earlier then current_time
if ((res = snd_pcm_htimestamp(state->hndl, &havail, &tstamp)) == 0) {
uint64_t htime = SPA_TIMESPEC_TO_NSEC(&tstamp);
if (htime < current_time) {
current_time = htime;
}
}
for (int i = 0; i < state->n_fds; i++) { for (int i = 0; i < state->n_fds; i++) {
state->pfds[i].revents = state->source[i].rmask; state->pfds[i].revents = state->source[i].rmask;