From 75e10cd1adae434794ade03c13764ac64eb56a4f Mon Sep 17 00:00:00 2001 From: Jaroslav Kysela Date: Thu, 19 Feb 2004 16:02:20 +0000 Subject: [PATCH] - fixed poll and select code - more work on osstest utility --- alsa/alsa-oss.c | 3 +- alsa/pcm.c | 2 +- test/osstest.c | 244 +++++++++++++++++++++++++++++++++++++----------- 3 files changed, 194 insertions(+), 55 deletions(-) diff --git a/alsa/alsa-oss.c b/alsa/alsa-oss.c index 5dcfc3e..1005f19 100644 --- a/alsa/alsa-oss.c +++ b/alsa/alsa-oss.c @@ -385,7 +385,7 @@ int poll(struct pollfd *pfds, unsigned long nfds, int timeout) { unsigned short events = pfds[k].events; int fmode = 0; - if (events & (POLLIN|POLLOUT)) + if ((events & (POLLIN|POLLOUT)) == (POLLIN|POLLOUT)) fmode = O_RDWR; else if (events & POLLIN) fmode = O_RDONLY; @@ -436,6 +436,7 @@ int poll(struct pollfd *pfds, unsigned long nfds, int timeout) ((result & OSS_WAIT_EVENT_READ) ? POLLIN : 0) | ((result & OSS_WAIT_EVENT_WRITE) ? POLLOUT : 0); } + nfds1 += lib_oss_pcm_poll_fds(fd); break; } default: diff --git a/alsa/pcm.c b/alsa/pcm.c index a881f61..2ca5db6 100644 --- a/alsa/pcm.c +++ b/alsa/pcm.c @@ -1476,7 +1476,7 @@ int lib_oss_pcm_poll_result(int fd, struct pollfd *ufds) result |= OSS_WAIT_EVENT_ERROR; if (revents & POLLIN) result |= OSS_WAIT_EVENT_READ; - if (revents & POLLIN) + if (revents & POLLOUT) result |= OSS_WAIT_EVENT_WRITE; ufds += count; } diff --git a/test/osstest.c b/test/osstest.c index a77332c..7a980b1 100644 --- a/test/osstest.c +++ b/test/osstest.c @@ -8,10 +8,9 @@ #include #include #include +#include #include -#define VERBOSE 1 - //static char data[500000]; static int verbose; static char *device = "/dev/dsp"; @@ -24,7 +23,7 @@ static audio_buf_info ospace; static audio_buf_info ispace; static int bufsize; static int fragsize; -static char *wbuf, *rbuf; +static char *wbuf = NULL, *rbuf = NULL; static int loop = 40; static void help(void) @@ -35,15 +34,16 @@ static void help(void) "-D,--device playback device\n" "-r,--rate stream rate in Hz\n" "-c,--channels count of channels in stream\n" -"-f,--frequency sine wave frequency in Hz\n" -"-b,--buffer ring buffer size in us\n" -"-p,--period period size in us\n" -"-m,--method transfer method (read/write/duplex)\n" -"-v,--verbose show the PCM setup parameters\n" +//"-f,--frequency sine wave frequency in Hz\n" +"-F,--frag OSS fragment settings (SNDCTL_DSP_SETFRAGMENT)\n" +"-M,--omode open mode (read/write/duplex)\n" +"-m,--method transfer method (rw, mmap_and_select, mmap_and_poll)\n" +"-L,--loop set loop count\n" +"-v,--verbose show more info\n" "\n"); } -static void set_params(void) +static void set_params(int do_mmap) { int caps; @@ -64,8 +64,9 @@ static void set_params(void) fprintf(stderr, "Sorry but your sound driver is too old\n"); exit(EXIT_FAILURE); } - if (!(caps & DSP_CAP_TRIGGER) || - !(caps & DSP_CAP_MMAP)) + if (do_mmap && + (!(caps & DSP_CAP_TRIGGER) || + !(caps & DSP_CAP_MMAP))) { fprintf(stderr, "Sorry but your soundcard can't do this\n"); exit(EXIT_FAILURE); @@ -84,11 +85,13 @@ static void set_params(void) printf("ospace.fragsize = %i\n", ospace.fragsize); printf("ospace.periods = %i\n", ospace.fragments); printf("ospace.bytes = %i\n", ospace.bytes); - if ((wbuf=mmap(NULL, bufsize, PROT_WRITE, MAP_FILE|MAP_SHARED, fd, 0))==MAP_FAILED) { - perror("mmap (write)"); - exit(-1); + if (do_mmap) { + if ((wbuf=mmap(NULL, bufsize, PROT_WRITE, MAP_FILE|MAP_SHARED, fd, 0))==MAP_FAILED) { + perror("mmap (write)"); + exit(-1); + } + printf("mmap (out) returned %p\n", wbuf); } - printf("mmap (out) returned %p\n", wbuf); } if (omode == O_RDWR || omode == O_RDONLY) { if (oss_pcm_ioctl(fd, SNDCTL_DSP_GETISPACE, &ispace) < 0) { @@ -109,11 +112,13 @@ static void set_params(void) printf("ispace.fragsize = %i\n", ispace.fragsize); printf("ispace.periods = %i\n", ispace.fragments); printf("ispace.bytes = %i\n", ispace.bytes); - if ((rbuf=mmap(NULL, bufsize, PROT_READ, MAP_FILE|MAP_SHARED, fd, 0))==MAP_FAILED) { - perror("mmap (read)"); - exit(-1); + if (do_mmap) { + if ((rbuf=mmap(NULL, bufsize, PROT_READ, MAP_FILE|MAP_SHARED, fd, 0))==MAP_FAILED) { + perror("mmap (read)"); + exit(-1); + } + printf("mmap (in) returned %p\n", rbuf); } - printf("mmap (in) returned %p\n", rbuf); } } } @@ -141,18 +146,166 @@ static void set_trigger(void) printf("Trigger set to %08x\n", tmp); } -int main(int argc, char *argv[]) +static void rw_loop(void) { - int morehelp = 0; - int nfrag, idx; + int idx, first = 1; + + for (idx=0; idx %i\n", sizeof(buf), (int)res); + } + res = oss_pcm_write(fd, buf, sizeof(buf)); + if (verbose) + printf("write: (%i) -> %i\n", sizeof(buf), (int)res); + first = 0; + } + if (omode != O_WRONLY) { + ssize_t res = oss_pcm_read(fd, buf, sizeof(buf)); + if (verbose) + printf("read: (%i) -> %i\n", sizeof(buf), (int)res); + } + } +} + +static void rw_and_select_loop(void) +{ +} + +static void rw_and_poll_loop(void) +{ +} + +static void mmap_loop(void) +{ +} + +static void mmap_and_select_loop(void) +{ + int nfrag_in = 0, nfrag_out = 0, idx; struct timeval tim; fd_set writeset, readset; + + for (idx=0; idx