diff options
author | cladisch <cladisch@b3059339-0415-0410-9bf9-f77b7e298cf2> | 2006-02-10 09:24:48 +0000 |
---|---|---|
committer | cladisch <cladisch@b3059339-0415-0410-9bf9-f77b7e298cf2> | 2006-02-10 09:24:48 +0000 |
commit | a25341464ca043e26e189f92772d3357d3f039f5 (patch) | |
tree | d2cc5e72d49a2d688918febe5ccdf862e4b841c7 | |
parent | 689c7b37a295bbe4e8465733d17217ba28623e25 (diff) | |
download | mpv-a25341464ca043e26e189f92772d3357d3f039f5.tar.bz2 mpv-a25341464ca043e26e189f92772d3357d3f039f5.tar.xz |
Simplify get_delay(): we don't need to get the complete PCM status but
can call snd_pcm_delay() directly.
To avoid the audio device appearing to be running too fast after an
underrun, ignore any samples that were lost in an underrun.
git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@17574 b3059339-0415-0410-9bf9-f77b7e298cf2
-rw-r--r-- | libao2/ao_alsa.c | 35 |
1 files changed, 10 insertions, 25 deletions
diff --git a/libao2/ao_alsa.c b/libao2/ao_alsa.c index f03ea55441..7c44974f06 100644 --- a/libao2/ao_alsa.c +++ b/libao2/ao_alsa.c @@ -1037,35 +1037,20 @@ static int get_space(void) /* delay in seconds between first and last sample in buffer */ static float get_delay(void) { - if (alsa_handler) { - - snd_pcm_status_t *status; - float ret; - - snd_pcm_status_alloca(&status); + snd_pcm_sframes_t delay; - if ((ret = snd_pcm_status(alsa_handler, status)) < 0) - { - mp_msg(MSGT_AO,MSGL_ERR,"alsa-delay: cannot get pcm status: %s\n", snd_strerror(ret)); - } + if (snd_pcm_delay(alsa_handler, &delay) < 0) + return 0; - switch(snd_pcm_status_get_state(status)) - { - case SND_PCM_STATE_OPEN: - case SND_PCM_STATE_PREPARED: - case SND_PCM_STATE_RUNNING: - ret = (float)snd_pcm_status_get_delay(status)/(float)ao_data.samplerate; - break; - default: - ret = 0; + if (delay < 0) { + /* underrun - move the application pointer forward to catch up */ +#if SND_LIB_VERSION >= 0x000901 /* snd_pcm_forward() exists since 0.9.0rc8 */ + snd_pcm_forward(alsa_handler, -delay); +#endif + delay = 0; } - - - if (ret < 0) - ret = 0; - return(ret); - + return (float)delay / (float)ao_data.samplerate; } else { return(0); } |