Commit 8c348652 authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont

ALSA: fix time measurements

The latency needs to be returned also when not (yet) running to start
playback on time (the audio output core inserts zeroes accordingly).

Also, then there is no point to using PCM status, as only one single
parameter is used. This simplifies the code and works around a bug
(probably in ALSA plugin framework) whereby delay was always zero
when using the ALSA<->PulseAudio I/O plugin.
parent 2b51a84f
......@@ -545,22 +545,14 @@ error:
static int TimeGet (audio_output_t *aout, mtime_t *restrict pts)
{
aout_sys_t *sys = aout->sys;
snd_pcm_t *pcm = sys->pcm;
snd_pcm_status_t *status;
int val;
snd_pcm_sframes_t frames;
snd_pcm_status_alloca (&status);
val = snd_pcm_status (pcm, status);
if (val < 0)
int val = snd_pcm_delay (sys->pcm, &frames);
if (val)
{
msg_Err (aout, "cannot get status: %s", snd_strerror (val));
msg_Err (aout, "cannot estimate delay: %s", snd_strerror (val));
return -1;
}
if (snd_pcm_status_get_state (status) != SND_PCM_STATE_RUNNING)
return -1;
snd_pcm_sframes_t frames = snd_pcm_status_get_delay (status);
*pts = mdate () + (frames * CLOCK_FREQ / sys->format.i_rate);
return 0;
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment