aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon Wilson <simonwilson@google.com>2011-06-21 14:58:11 -0700
committerSimon Wilson <simonwilson@google.com>2011-06-24 11:05:08 -0700
commitd6458e6f62ea7d09a82f78f509df58c452358ae8 (patch)
tree54e4687d27bd1fd8446e250584c5b95b9da03452
parentbc03b620835886fb4de50ef1499200a9ca80a999 (diff)
pcm: add pcm_start/stop() functions for streams
This is essential for streams such as loopback devices that do not transfer data.
-rw-r--r--include/tinyalsa/asoundlib.h4
-rw-r--r--pcm.c19
2 files changed, 23 insertions, 0 deletions
diff --git a/include/tinyalsa/asoundlib.h b/include/tinyalsa/asoundlib.h
index bd0cdee..14511c9 100644
--- a/include/tinyalsa/asoundlib.h
+++ b/include/tinyalsa/asoundlib.h
@@ -97,6 +97,10 @@ unsigned int pcm_get_latency(struct pcm *pcm);
int pcm_write(struct pcm *pcm, void *data, unsigned int count);
int pcm_read(struct pcm *pcm, void *data, unsigned int count);
+/* Start and stop a PCM channel that doesn't transfer data */
+int pcm_start(struct pcm *pcm);
+int pcm_stop(struct pcm *pcm);
+
/*
* MIXER API
diff --git a/pcm.c b/pcm.c
index adc0495..3ba51ba 100644
--- a/pcm.c
+++ b/pcm.c
@@ -350,3 +350,22 @@ int pcm_is_ready(struct pcm *pcm)
{
return pcm->fd >= 0;
}
+
+int pcm_start(struct pcm *pcm)
+{
+ if (ioctl(pcm->fd, SNDRV_PCM_IOCTL_PREPARE) < 0)
+ return oops(pcm, errno, "cannot prepare channel");
+ if (ioctl(pcm->fd, SNDRV_PCM_IOCTL_START) < 0)
+ return oops(pcm, errno, "cannot start channel");
+
+ return 0;
+}
+
+int pcm_stop(struct pcm *pcm)
+{
+ if (ioctl(pcm->fd, SNDRV_PCM_IOCTL_DROP) < 0)
+ return oops(pcm, errno, "cannot stop channel");
+
+ return 0;
+}
+