diff options
author | Uoti Urpala <uau@glyph.nonexistent.invalid> | 2008-12-08 22:21:23 +0200 |
---|---|---|
committer | Uoti Urpala <uau@glyph.nonexistent.invalid> | 2008-12-08 22:36:06 +0200 |
commit | 66cefd5f7196022f5f0c45b2f68a8fa3b354c917 (patch) | |
tree | 3add6cd4148e0742ce8aace315c3c1f99d9d64e9 /libao2/ao_alsa.c | |
parent | bc4c570ab1fd93db0f24759b35306a3d10985c4b (diff) | |
download | mpv-66cefd5f7196022f5f0c45b2f68a8fa3b354c917.tar.bz2 mpv-66cefd5f7196022f5f0c45b2f68a8fa3b354c917.tar.xz |
ao_alsa: If pause loses samples replace them with silence
If the ALSA pause functionality is not available the driver has to
drop buffered samples when MPlayer calls pause(). Replace them by
playing a corresponding amount of silence in resume() instead of
shortening the overall audio duration.
Diffstat (limited to 'libao2/ao_alsa.c')
-rw-r--r-- | libao2/ao_alsa.c | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/libao2/ao_alsa.c b/libao2/ao_alsa.c index cd7b862728..81bcc2c8b3 100644 --- a/libao2/ao_alsa.c +++ b/libao2/ao_alsa.c @@ -70,6 +70,7 @@ static int ao_noblock = 0; static int open_mode; static int alsa_can_pause = 0; +static snd_pcm_sframes_t prepause_frames; #define ALSA_DEVICE_SIZE 256 @@ -334,6 +335,8 @@ static int init(int rate_hz, int channels, int format, int flags) mp_msg(MSGT_AO,MSGL_V,"alsa-init: compiled for ALSA-%s\n", SND_LIB_VERSION_STR); #endif + prepause_frames = 0; + snd_lib_error_set_handler(alsa_error_handler); ao_data.samplerate = rate_hz; @@ -753,6 +756,10 @@ static void audio_pause(void) } mp_msg(MSGT_AO,MSGL_V,"alsa-pause: pause supported by hardware\n"); } else { + if (snd_pcm_delay(alsa_handler, &prepause_frames) < 0 + || prepause_frames < 0) + prepause_frames = 0; + if ((err = snd_pcm_drop(alsa_handler)) < 0) { mp_msg(MSGT_AO,MSGL_ERR,MSGTR_AO_ALSA_PcmDropError, snd_strerror(err)); @@ -782,6 +789,11 @@ static void audio_resume(void) mp_msg(MSGT_AO,MSGL_ERR,MSGTR_AO_ALSA_PcmPrepareError, snd_strerror(err)); return; } + if (prepause_frames) { + void *silence = calloc(prepause_frames, bytes_per_sample); + play(silence, prepause_frames * bytes_per_sample, 0); + free(silence); + } } } @@ -790,6 +802,7 @@ static void reset(void) { int err; + prepause_frames = 0; if ((err = snd_pcm_drop(alsa_handler)) < 0) { mp_msg(MSGT_AO,MSGL_ERR,MSGTR_AO_ALSA_PcmPrepareError, snd_strerror(err)); |