Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.bin/audiocfg Revert to use single descriptor for "audioc...



details:   https://anonhg.NetBSD.org/src/rev/f40a77ffd3f5
branches:  trunk
changeset: 463473:f40a77ffd3f5
user:      isaki <isaki%NetBSD.org@localhost>
date:      Sat Aug 24 04:04:10 2019 +0000

description:
Revert to use single descriptor for "audiocfg test" as before.

diffstat:

 usr.bin/audiocfg/audiodev.c |  68 ++++++++++++++++++++++++++++++--------------
 usr.bin/audiocfg/audiodev.h |   5 +-
 usr.bin/audiocfg/main.c     |  11 +-----
 3 files changed, 52 insertions(+), 32 deletions(-)

diffs (178 lines):

diff -r bae97b474507 -r f40a77ffd3f5 usr.bin/audiocfg/audiodev.c
--- a/usr.bin/audiocfg/audiodev.c       Sat Aug 24 03:28:37 2019 +0000
+++ b/usr.bin/audiocfg/audiodev.c       Sat Aug 24 04:04:10 2019 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: audiodev.c,v 1.8 2019/08/24 03:28:37 isaki Exp $ */
+/* $NetBSD: audiodev.c,v 1.9 2019/08/24 04:04:10 isaki Exp $ */
 
 /*
  * Copyright (c) 2010 Jared D. McNeill <jmcneill%invisible.ca@localhost>
@@ -43,6 +43,9 @@
 #include "drvctl.h"
 #include "dtmf.h"
 
+static int audiodev_test_chmask(struct audiodev *, unsigned int,
+       audio_info_t *);
+
 static TAILQ_HEAD(audiodevhead, audiodev) audiodevlist =
     TAILQ_HEAD_INITIALIZER(audiodevlist);
 
@@ -298,17 +301,16 @@
 }
 
 int
-audiodev_test(struct audiodev *adev, unsigned int chanmask)
+audiodev_test(struct audiodev *adev)
 {
        audio_info_t info;
-       int16_t *buf;
-       size_t buflen;
-       off_t off;
-       int fd;
-       int rv = -1;
+       unsigned int i;
+       int rv;
 
-       fd = open(adev->path, O_WRONLY);
-       if (fd == -1) {
+       rv = -1;
+
+       adev->fd = open(adev->path, O_WRONLY);
+       if (adev->fd == -1) {
                perror("open");
                return -1;
        }
@@ -319,19 +321,44 @@
        info.play.precision = 16;
        info.play.encoding = AUDIO_ENCODING_SLINEAR_LE;
        info.mode = AUMODE_PLAY;
-       if (ioctl(fd, AUDIO_SETINFO, &info) == -1) {
+       if (ioctl(adev->fd, AUDIO_SETINFO, &info) == -1) {
                perror("ioctl AUDIO_SETINFO");
-               goto abort;
+               goto done;
+       }
+       if (ioctl(adev->fd, AUDIO_GETINFO, &info) == -1) {
+               perror("ioctl AUDIO_GETINFO");
+               goto done;
        }
-       if (ioctl(fd, AUDIO_GETINFO, &info) == -1) {
-               perror("ioctl AUDIO_GETINFO");
-               goto abort;
+
+       for (i = 0; i < adev->hwinfo.play.channels; i++) {
+               printf("  testing channel %u...", i);
+               fflush(stdout);
+               if (audiodev_test_chmask(adev, 1 << i, &info) == -1)
+                       goto done;
+               printf(" done\n");
        }
 
-       dtmf_new(&buf, &buflen, info.play.sample_rate, 2,
+       rv = 0;
+done:
+       close(adev->fd);
+       return rv;
+}
+
+static int
+audiodev_test_chmask(struct audiodev *adev, unsigned int chanmask,
+       audio_info_t *info)
+{
+       int16_t *buf;
+       size_t buflen;
+       off_t off;
+       int rv;
+
+       rv = -1;
+
+       dtmf_new(&buf, &buflen, info->play.sample_rate, 2,
            adev->hwinfo.play.channels, chanmask, 350.0, 440.0);
        if (buf == NULL) {
-               goto abort;
+               return -1;
        }
 
        off = 0;
@@ -339,10 +366,10 @@
                size_t wlen; 
                ssize_t ret;
 
-               wlen = info.play.buffer_size;
+               wlen = info->play.buffer_size;
                if (wlen > buflen)
                        wlen = buflen;
-               ret = write(fd, (char *)buf + off, wlen);
+               ret = write(adev->fd, (char *)buf + off, wlen);
                if (ret == -1) {
                        perror("write");
                        goto done;
@@ -352,7 +379,7 @@
                buflen -= wlen;
        }
 
-       if (ioctl(fd, AUDIO_DRAIN) == -1) {
+       if (ioctl(adev->fd, AUDIO_DRAIN) == -1) {
                perror("ioctl AUDIO_DRAIN");
                goto done;
        }
@@ -360,8 +387,5 @@
        rv = 0;
 done:
        free(buf);
-abort:
-       close(fd);
-
        return rv;
 }
diff -r bae97b474507 -r f40a77ffd3f5 usr.bin/audiocfg/audiodev.h
--- a/usr.bin/audiocfg/audiodev.h       Sat Aug 24 03:28:37 2019 +0000
+++ b/usr.bin/audiocfg/audiodev.h       Sat Aug 24 04:04:10 2019 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: audiodev.h,v 1.6 2019/08/24 03:28:37 isaki Exp $ */
+/* $NetBSD: audiodev.h,v 1.7 2019/08/24 04:04:10 isaki Exp $ */
 
 /*
  * Copyright (c) 2010 Jared D. McNeill <jmcneill%invisible.ca@localhost>
@@ -46,6 +46,7 @@
        uint16_t unit;
        char path[PATH_MAX+1];
        char ctlpath[PATH_MAX+1];
+       int fd;
        int ctlfd;
 
        dev_t dev;
@@ -65,7 +66,7 @@
 int                    audiodev_set_param(struct audiodev *, int,
                                const char *, unsigned int, unsigned int,
                                unsigned int);
-int                    audiodev_test(struct audiodev *, unsigned int);
+int                    audiodev_test(struct audiodev *);
 
 extern const char *    encoding_names[];
 extern u_int           encoding_max;
diff -r bae97b474507 -r f40a77ffd3f5 usr.bin/audiocfg/main.c
--- a/usr.bin/audiocfg/main.c   Sat Aug 24 03:28:37 2019 +0000
+++ b/usr.bin/audiocfg/main.c   Sat Aug 24 04:04:10 2019 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: main.c,v 1.10 2019/08/24 03:28:37 isaki Exp $ */
+/* $NetBSD: main.c,v 1.11 2019/08/24 04:04:10 isaki Exp $ */
 
 /*
  * Copyright (c) 2010 Jared D. McNeill <jmcneill%invisible.ca@localhost>
@@ -253,13 +253,8 @@
                        return EXIT_FAILURE;
                }
                print_audiodev(adev, i);
-               for (i = 0; i < adev->hwinfo.play.channels; i++) {
-                       printf("  testing channel %d...", i);
-                       fflush(stdout);
-                       if (audiodev_test(adev, 1 << i) == -1)
-                               return EXIT_FAILURE;
-                       printf(" done\n");
-               }
+               if (audiodev_test(adev) == -1)
+                       return EXIT_FAILURE;
        } else
                usage(argv[0]);
                /* NOTREACHED */



Home | Main Index | Thread Index | Old Index