aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJohn Grossman2012-04-03 18:37:38 -0500
committerJohn Grossman2012-04-03 18:59:59 -0500
commit673253acf06838bb24d0b0b1a3962bed573855b8 (patch)
treec6c8a6a063171ec87872f40e585b13dc5e757a3a
parent1b32ddfd35e54b0a6ef1e43ca35dbc1547e5676a (diff)
downloadplatform-external-tinyalsa-673253acf06838bb24d0b0b1a3962bed573855b8.tar.gz
platform-external-tinyalsa-673253acf06838bb24d0b0b1a3962bed573855b8.tar.xz
platform-external-tinyalsa-673253acf06838bb24d0b0b1a3962bed573855b8.zip
tinyalsa: Add PCM_NORESTART flag.
Add a flag which can be passed to pcm_open (called PCM_NORESTART). When set on a playback stream, calls to pcm_write will not automatically attempt to restart an ALSA device in the case of an underflow. Instead, it will propagate the first EPIPE error up to the application to allow it to handle the underflow situation. Subsequent calls to pcm_write will attempt to start the pipeline. Change-Id: If17973c6de9079c4227631bac9ff09b218377344 Signed-off-by: John Grossman <johngro@google.com>
-rw-r--r--include/tinyalsa/asoundlib.h9
-rw-r--r--pcm.c6
2 files changed, 14 insertions, 1 deletions
diff --git a/include/tinyalsa/asoundlib.h b/include/tinyalsa/asoundlib.h
index d6409fe..cb70439 100644
--- a/include/tinyalsa/asoundlib.h
+++ b/include/tinyalsa/asoundlib.h
@@ -45,6 +45,15 @@ struct pcm;
45#define PCM_IN 0x10000000 45#define PCM_IN 0x10000000
46#define PCM_MMAP 0x00000001 46#define PCM_MMAP 0x00000001
47#define PCM_NOIRQ 0x00000002 47#define PCM_NOIRQ 0x00000002
48#define PCM_NORESTART 0x00000004 /* PCM_NORESTART - when set, calls to
49 * pcm_write for a playback stream will not
50 * attempt to restart the stream in the case
51 * of an underflow, but will return -EPIPE
52 * instead. After the first -EPIPE error, the
53 * stream is considered to be stopped, and a
54 * second call to pcm_write will attempt to
55 * restart the stream.
56 */
48 57
49/* PCM runtime states */ 58/* PCM runtime states */
50#define PCM_STATE_OPEN 0 59#define PCM_STATE_OPEN 0
diff --git a/pcm.c b/pcm.c
index 9324f38..b4c35b2 100644
--- a/pcm.c
+++ b/pcm.c
@@ -388,8 +388,12 @@ int pcm_write(struct pcm *pcm, void *data, unsigned int count)
388 if (ioctl(pcm->fd, SNDRV_PCM_IOCTL_WRITEI_FRAMES, &x)) { 388 if (ioctl(pcm->fd, SNDRV_PCM_IOCTL_WRITEI_FRAMES, &x)) {
389 pcm->running = 0; 389 pcm->running = 0;
390 if (errno == EPIPE) { 390 if (errno == EPIPE) {
391 /* we failed to make our window -- try to restart */ 391 /* we failed to make our window -- try to restart if we are
392 * allowed to do so. Otherwise, simply allow the EPIPE error to
393 * propagate up to the app level */
392 pcm->underruns++; 394 pcm->underruns++;
395 if (pcm->flags & PCM_NORESTART)
396 return -EPIPE;
393 continue; 397 continue;
394 } 398 }
395 return oops(pcm, errno, "cannot write stream data"); 399 return oops(pcm, errno, "cannot write stream data");