[MPlayer-dev-eng] [PATCH] ALSA AO, attempt both chunk sizes before failing

Andrew Calkin andrew.calkin at gmail.com
Wed Aug 29 17:56:29 CEST 2007


Hi all,

The attached patch has been sitting in the GeeXboX development tree
since antiquity. Basically if it fails to set the period size with one
of the values (1024 or 512), then it tries the other before bailing out.

If someone more knowledgable on this topic (Clemens?) could say whether
this is still useful and should be applied upstream or discarded it
would be good. After some research it seems that the return value of the
snd_pcm_hw_params_set_period_size() function isn't often checked in
other projects.

//Andrew
-------------- next part --------------
* Variable chunk_size takes a value of either 512 or 1024, so if it fails with
  the "correct" setting, try the alternate setting as a final attempt to get
  the device working 
diff -r 0ad70995f3b9 libao2/ao_alsa.c
--- a/libao2/ao_alsa.c	Sun Apr 30 16:54:28 2006 +0200
+++ b/libao2/ao_alsa.c	Sun Apr 30 16:54:28 2006 +0200
@@ -615,11 +615,15 @@ static int init(int rate_hz, int channel
 	if ((err = snd_pcm_hw_params_set_period_size_near(alsa_handler, alsa_hwparams, 
 							  &chunk_size, NULL)) < 0)
 	  {
-	    mp_msg(MSGT_AO,MSGL_ERR,MSGTR_AO_ALSA_UnableToSetPeriodSize,
-			    chunk_size, snd_strerror(err));
+	    chunk_size = 512 + 1024 - chunk_size;
+	    if ((err = snd_pcm_hw_params_set_period_size(alsa_handler, alsa_hwparams, 
+	                                                 chunk_size, 0)) < 0) {
+	      mp_msg(MSGT_AO,MSGL_ERR,MSGTR_AO_ALSA_UnableToSetPeriodSize,
+	      chunk_size, snd_strerror(err));
+	    }
 	    return 0;
 	  }
-	else {
+	if (err >= 0) {
 	  mp_msg(MSGT_AO,MSGL_V,"alsa-init: chunksize set to %li\n", chunk_size);
 	}
 	if ((err = snd_pcm_hw_params_set_periods_near(alsa_handler, alsa_hwparams,


More information about the MPlayer-dev-eng mailing list