From: Jaroslav Kysela Date: Tue, 22 Feb 2000 17:36:34 +0000 (+0000) Subject: Fixed return codes (added EPIPE). X-Git-Tag: v1.0.3~1318 X-Git-Url: https://git.alsa-project.org/?a=commitdiff_plain;h=4637dfaa3ef68240d9cc2ef8dfeea7455218fe25;p=alsa-lib.git Fixed return codes (added EPIPE). --- diff --git a/src/pcm/plugin/mmap.c b/src/pcm/plugin/mmap.c index 9e912915..c9496492 100644 --- a/src/pcm/plugin/mmap.c +++ b/src/pcm/plugin/mmap.c @@ -74,7 +74,7 @@ static int query_playback(struct mmap_private_data *data, } break; case SND_PCM_STATUS_UNDERRUN: - return -EAGAIN; + return -EPIPE; default: return -EIO; } @@ -116,7 +116,7 @@ static int query_capture(struct mmap_private_data *data, } break; case SND_PCM_STATUS_OVERRUN: - return -EAGAIN; + return -EPIPE; default: return -EIO; } diff --git a/test/latency.c b/test/latency.c index b87d1008..e0b6991c 100644 --- a/test/latency.c +++ b/test/latency.c @@ -5,9 +5,15 @@ #include #include "../include/asoundlib.h" +#if 0 +#define USE_BLOCK_MODE /* latency is twice more than for stream mode!!! */ +#endif + +#define USED_RATE 48000 #define LATENCY_LIMIT 8192 /* in bytes */ #define LOOP_LIMIT (30 * 176400) /* 30 seconds */ +#if 0 static char *xitoa(int aaa) { static char str[12]; @@ -15,6 +21,7 @@ static char *xitoa(int aaa) sprintf(str, "%i", aaa); return str; } +#endif static int syncro(snd_pcm_t *phandle, snd_pcm_t *chandle) { @@ -66,11 +73,15 @@ int setparams(snd_pcm_t *phandle, snd_pcm_t *chandle, int sync, int *queue) bzero(¶ms, sizeof(params)); params.channel = SND_PCM_CHANNEL_PLAYBACK; +#ifdef USE_BLOCK_MODE + params.mode = SND_PCM_MODE_BLOCK; +#else params.mode = SND_PCM_MODE_STREAM; +#endif params.format.interleave = 1; params.format.format = SND_PCM_SFMT_S16_LE; params.format.voices = 2; - params.format.rate = 44100; + params.format.rate = USED_RATE; params.start_mode = SND_PCM_START_GO; params.stop_mode = SND_PCM_STOP_STOP; params.time = 1; @@ -88,7 +99,13 @@ int setparams(snd_pcm_t *phandle, snd_pcm_t *chandle, int sync, int *queue) return -1; again = 0; params.channel = SND_PCM_CHANNEL_PLAYBACK; +#ifdef USE_BLOCK_MODE + params.buf.block.frag_size = *queue; + params.buf.block.frags_min = 1; + params.buf.block.frags_max = -1; +#else params.buf.stream.queue_size = *queue; +#endif if ((err = snd_pcm_plugin_params(phandle, ¶ms)) < 0) { printf("Playback params error: %s\n", snd_strerror(err)); exit(0); @@ -99,14 +116,12 @@ int setparams(snd_pcm_t *phandle, snd_pcm_t *chandle, int sync, int *queue) exit(0); } bzero(&psetup, sizeof(psetup)); - psetup.mode = SND_PCM_MODE_STREAM; psetup.channel = SND_PCM_CHANNEL_PLAYBACK; if ((err = snd_pcm_plugin_setup(phandle, &psetup)) < 0) { printf("Playback setup error: %s\n", snd_strerror(err)); exit(0); } bzero(&csetup, sizeof(csetup)); - csetup.mode = SND_PCM_MODE_STREAM; csetup.channel = SND_PCM_CHANNEL_CAPTURE; if ((err = snd_pcm_plugin_setup(chandle, &csetup)) < 0) { printf("Capture setup error: %s\n", snd_strerror(err)); @@ -130,7 +145,13 @@ int setparams(snd_pcm_t *phandle, snd_pcm_t *chandle, int sync, int *queue) printf("Capture prepare error: %s\n", snd_strerror(err)); exit(0); } - printf("Trying latency %i...\n", *queue); + printf("Trying latency %i (playback rate = %iHz, capture rate = %iHz)...\n", +#ifdef USE_BLOCK_MODE + *queue * 2, +#else + *queue, +#endif + psetup.format.rate, csetup.format.rate); fflush(stdout); return 0; } @@ -153,6 +174,7 @@ void showstat(snd_pcm_t *handle, int channel, snd_pcm_channel_status_t *rstatus) printf(" status = %i\n", status.status); printf(" position = %u\n", status.scount); printf(" free = %i\n", status.free); + printf(" count = %i\n", status.count); if (rstatus) *rstatus = status; } @@ -192,7 +214,9 @@ long readbuf(snd_pcm_t *handle, char *buf, long len) { long r; - r = snd_pcm_plugin_read(handle, buf, len); + do { + r = snd_pcm_plugin_read(handle, buf, len); + } while (r == -EAGAIN); // printf("read = %li\n", r); // showstat(handle, SND_PCM_CHANNEL_CAPTURE, NULL); return r; @@ -204,8 +228,10 @@ long writebuf(snd_pcm_t *handle, char *buf, long len) while (len > 0) { r = snd_pcm_plugin_write(handle, buf, len); +#ifndef USE_BLOCK_MODE if (r == -EAGAIN) continue; +#endif // printf("write = %li\n", r); if (r < 0) return r; @@ -239,6 +265,11 @@ int main(void) printf("Record open error: %s\n", snd_strerror(err)); return 0; } +#ifdef USE_BLOCK_MODE + printf("Using block mode...\n"); +#else + printf("Using stream mode...\n"); +#endif sync = syncro(phandle, chandle); if (sync) printf("Using hardware synchronization mode\n"); @@ -248,6 +279,10 @@ int main(void) memset(buffer, 0, latency); if (writebuf(phandle, buffer, latency) < 0) break; +#ifdef USE_BLOCK_MODE /* at least two fragments MUST BE filled !!! */ + if (writebuf(phandle, buffer, latency) < 0) + break; +#endif if (sync) { syncro_id(&ssync); if ((err = snd_pcm_sync_go(phandle, &ssync)) < 0) {