[xiph-cvs] cvs commit: ao/src/plugins/alsa09 ao_alsa09.c

Warren Dukes shank at xiph.org
Sat Oct 11 13:05:33 PDT 2003



shank       03/10/11 16:05:33

  Modified:    src/plugins/alsa09 ao_alsa09.c
  Log:
  Lets make mmio/mmap alsa support configurable at run time.
  The option is "use_mmap".  Accepted values for enabling are:
  "yes","y","true","t","1".  Anything else disables mmap support.
  If mmio is enable at compile time, use that as the default.

Revision  Changes    Path
1.19      +34 -13    ao/src/plugins/alsa09/ao_alsa09.c

Index: ao_alsa09.c
===================================================================
RCS file: /usr/local/cvsroot/ao/src/plugins/alsa09/ao_alsa09.c,v
retrieving revision 1.18
retrieving revision 1.19
diff -u -r1.18 -r1.19
--- ao_alsa09.c	11 Oct 2003 13:31:20 -0000	1.18
+++ ao_alsa09.c	11 Oct 2003 20:05:32 -0000	1.19
@@ -47,10 +47,24 @@
  * supplying a period_time to ao overrides the use of this  */
 #define AO_ALSA_SAMPLE_XFER 256
 
+/* set mmap to default if enabled at compile time, otherwise, mmap isn't
+   the default */
+#ifdef USE_ALSA_MMIO
+#define AO_ALSA_WRITEI snd_pcm_mmap_writei
+#define AO_ALSA_ACCESS_MASK SND_PCM_ACCESS_MMAP_INTERLEAVED
+#else
+#define AO_ALSA_WRITEI snd_pcm_writei
+#define AO_ALSA_ACCESS_MASK SND_PCM_ACCESS_RW_INTERLEAVED
+#endif
+
+typedef snd_pcm_sframes_t ao_alsa_writei_t(snd_pcm_t *pcm, const void *buffer,
+						snd_pcm_uframes_t size);
+
 static char *ao_alsa_options[] = {
         "dev",
         "buffer_time",
-        "period_time"
+        "period_time",
+	"use_mmap"
 };
 
 
@@ -79,6 +93,8 @@
         int bitformat;
         char *dev;
         char *cmd;
+	ao_alsa_writei_t * writei;
+	snd_pcm_access_t access_mask;
 } ao_alsa_internal;
 
 
@@ -121,6 +137,8 @@
         
         internal->buffer_time = AO_ALSA_BUFFER_TIME;
         internal->period_time = AO_ALSA_PERIOD_TIME;
+	internal->writei = AO_ALSA_WRITEI;
+	internal->access_mask = AO_ALSA_ACCESS_MASK;
 
         if (!(internal->dev = strdup("default"))) {
                 free (internal);
@@ -148,6 +166,19 @@
                 internal->buffer_time = atoi(value);
         else if (!strcmp(key, "period_time"))
                 internal->period_time = atoi(value);
+	else if (!strcmp(key,"use_mmap")) {
+		if(!strcmp(value,"yes") || !strcmp(value,"y") || 
+			!strcmp(value,"true") || !strcmp(value,"t") ||
+			!strcmp(value,"1"))
+		{
+			internal->writei = snd_pcm_mmap_writei;
+			internal->access_mask = SND_PCM_ACCESS_MMAP_INTERLEAVED;
+		}
+		else {
+			internal->writei = snd_pcm_writei;
+			internal->access_mask = SND_PCM_ACCESS_RW_INTERLEAVED;
+		}
+	}
 
         return 1;
 }
@@ -196,13 +227,7 @@
         /* create a null access mask */
         snd_pcm_access_mask_none(access);
 
-#ifdef USE_ALSA_MMIO
-	/* allow interleaved memory-mapped access */
-	snd_pcm_access_mask_set(access, SND_PCM_ACCESS_MMAP_INTERLEAVED);
-#else
-	/* allow interleaved non memory-mapped access */
-	snd_pcm_access_mask_set(access, SND_PCM_ACCESS_RW_INTERLEAVED);
-#endif
+	snd_pcm_access_mask_set(access, internal->access_mask);
 
         /* commit the access value to params structure */
         internal->cmd = "snd_pcm_hw_params_set_access";
@@ -414,11 +439,7 @@
         /* the entire buffer might not transfer at once */
         while (len > 0) {
                 /* try to write the entire buffer at once */
-#ifdef USE_ALSA_MMIO
-		err = snd_pcm_mmap_writei(internal->pcm_handle, ptr, len);
-#else
-		err = snd_pcm_writei(internal->pcm_handle, ptr, len);
-#endif
+		err = internal->writei(internal->pcm_handle, ptr, len);
 
                 /* it's possible that no data was transferred */
                 if (err == -EAGAIN) {

<p><p>--- >8 ----
List archives:  http://www.xiph.org/archives/
Ogg project homepage: http://www.xiph.org/ogg/
To unsubscribe from this list, send a message to 'cvs-request at xiph.org'
containing only the word 'unsubscribe' in the body.  No subject is needed.
Unsubscribe messages sent to the list will be ignored/filtered.



More information about the commits mailing list