Source-Changes-HG archive

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

[src/trunk]: src/lib/libossaudio ossaudio(3): refactor library into separate ...



details:   https://anonhg.NetBSD.org/src/rev/f3595ec1323e
branches:  trunk
changeset: 983818:f3595ec1323e
user:      nia <nia%NetBSD.org@localhost>
date:      Tue Jun 08 18:43:54 2021 +0000

description:
ossaudio(3): refactor library into separate files

diffstat:

 lib/libossaudio/Makefile      |     6 +-
 lib/libossaudio/internal.h    |    53 +
 lib/libossaudio/oss3_mixer.c  |   393 ++++++++
 lib/libossaudio/oss4_global.c |    63 +
 lib/libossaudio/oss4_mixer.c  |   640 ++++++++++++++
 lib/libossaudio/oss_caps.c    |    78 +
 lib/libossaudio/oss_dsp.c     |   711 +++++++++++++++
 lib/libossaudio/oss_ioctl.c   |    26 +
 lib/libossaudio/ossaudio.c    |  1834 -----------------------------------------
 9 files changed, 1968 insertions(+), 1836 deletions(-)

diffs (truncated from 3849 to 300 lines):

diff -r 8add2be744e5 -r f3595ec1323e lib/libossaudio/Makefile
--- a/lib/libossaudio/Makefile  Tue Jun 08 16:15:11 2021 +0000
+++ b/lib/libossaudio/Makefile  Tue Jun 08 18:43:54 2021 +0000
@@ -1,11 +1,13 @@
-#      $NetBSD: Makefile,v 1.10 2012/05/05 15:57:45 christos Exp $
+#      $NetBSD: Makefile,v 1.11 2021/06/08 18:43:54 nia Exp $
 
 WARNS= 5
 
 LIB=   ossaudio
 MAN=   ossaudio.3
 
-SRCS=  ossaudio.c
+SRCS=  oss_caps.c oss_dsp.c oss_ioctl.c
+SRCS+= oss3_mixer.c oss4_mixer.c
+SRCS+= oss4_global.c
 
 CPPFLAGS+= -I${.CURDIR}
 
diff -r 8add2be744e5 -r f3595ec1323e lib/libossaudio/internal.h
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/lib/libossaudio/internal.h        Tue Jun 08 18:43:54 2021 +0000
@@ -0,0 +1,53 @@
+/*     $NetBSD: internal.h,v 1.1 2021/06/08 18:43:54 nia Exp $ */
+
+/*-
+ * Copyright (c) 1997-2021 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef OSSAUDIO_INTERNAL_H
+#define OSSAUDIO_INTERNAL_H
+
+#include <sys/ioctl.h>
+#include "soundcard.h"
+#undef ioctl
+
+#define TO_OSSVOL(x)   (((x) * 100 + 127) / 255)
+#define FROM_OSSVOL(x) ((((x) > 100 ? 100 : (x)) * 255 + 50) / 100)
+
+#define INTARG         (*(int*)argp)
+
+#define GET_DEV(com)   ((com) & 0xff)
+
+#define oss_private    __attribute__((__visibility__("hidden")))
+
+int _oss_ioctl(int, unsigned long, ...);
+
+oss_private int _oss_dsp_ioctl(int, unsigned long, void *);
+oss_private int _oss_get_caps(int, int *);
+oss_private int _oss3_mixer_ioctl(int, unsigned long, void *);
+oss_private int _oss4_mixer_ioctl(int, unsigned long, void *);
+oss_private int _oss4_global_ioctl(int, unsigned long, void *);
+
+#endif
diff -r 8add2be744e5 -r f3595ec1323e lib/libossaudio/oss3_mixer.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/lib/libossaudio/oss3_mixer.c      Tue Jun 08 18:43:54 2021 +0000
@@ -0,0 +1,393 @@
+/*     $NetBSD: oss3_mixer.c,v 1.1 2021/06/08 18:43:54 nia Exp $       */
+
+/*-
+ * Copyright (c) 1997-2021 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <sys/audioio.h>
+#include <sys/stat.h>
+#include <errno.h>
+#include "internal.h"
+
+/* If the NetBSD mixer device should have more than NETBSD_MAXDEVS devices
+ * some will not be available to OSS applications */
+#define NETBSD_MAXDEVS 64
+
+struct audiodevinfo {
+       int done;
+       dev_t dev;
+       int16_t devmap[SOUND_MIXER_NRDEVICES],
+               rdevmap[NETBSD_MAXDEVS];
+       char names[NETBSD_MAXDEVS][MAX_AUDIO_DEV_LEN];
+       int enum2opaque[NETBSD_MAXDEVS];
+        u_long devmask, recmask, stereomask;
+       u_long caps;
+       int source;
+};
+
+static struct audiodevinfo *getdevinfo(int);
+static int opaque_to_enum(struct audiodevinfo *, audio_mixer_name_t *, int);
+static int enum_to_ord(struct audiodevinfo *, int);
+static int enum_to_mask(struct audiodevinfo *, int);
+
+oss_private int
+_oss3_mixer_ioctl(int fd, unsigned long com, void *argp)
+{
+       struct audiodevinfo *di;
+       struct mixer_info *omi;
+       struct audio_device adev;
+       mixer_ctrl_t mc;
+       u_long idat, n;
+       int i;
+       int retval;
+       int l, r, error, e;
+
+       idat = 0;
+       di = getdevinfo(fd);
+       if (di == 0)
+               return -1;
+
+       switch (com) {
+        case OSS_GETVERSION:
+                idat = SOUND_VERSION;
+                break;
+       case SOUND_MIXER_INFO:
+       case SOUND_OLD_MIXER_INFO:
+               error = ioctl(fd, AUDIO_GETDEV, &adev);
+               if (error)
+                       return (error);
+               omi = argp;
+               if (com == SOUND_MIXER_INFO)
+                       omi->modify_counter = 1;
+               strlcpy(omi->id, adev.name, sizeof omi->id);
+               strlcpy(omi->name, adev.name, sizeof omi->name);
+               return 0;
+       case SOUND_MIXER_READ_RECSRC:
+               if (di->source == -1) {
+                       errno = EINVAL;
+                       return -1;
+               }
+               mc.dev = di->source;
+               if (di->caps & SOUND_CAP_EXCL_INPUT) {
+                       mc.type = AUDIO_MIXER_ENUM;
+                       retval = ioctl(fd, AUDIO_MIXER_READ, &mc);
+                       if (retval < 0)
+                               return retval;
+                       e = opaque_to_enum(di, NULL, mc.un.ord);
+                       if (e >= 0)
+                               idat = 1 << di->rdevmap[e];
+               } else {
+                       mc.type = AUDIO_MIXER_SET;
+                       retval = ioctl(fd, AUDIO_MIXER_READ, &mc);
+                       if (retval < 0)
+                               return retval;
+                       e = opaque_to_enum(di, NULL, mc.un.mask);
+                       if (e >= 0)
+                               idat = 1 << di->rdevmap[e];
+               }
+               break;
+       case SOUND_MIXER_READ_DEVMASK:
+               idat = di->devmask;
+               break;
+       case SOUND_MIXER_READ_RECMASK:
+               idat = di->recmask;
+               break;
+       case SOUND_MIXER_READ_STEREODEVS:
+               idat = di->stereomask;
+               break;
+       case SOUND_MIXER_READ_CAPS:
+               idat = di->caps;
+               break;
+       case SOUND_MIXER_WRITE_RECSRC:
+       case SOUND_MIXER_WRITE_R_RECSRC:
+               if (di->source == -1) {
+                       errno = EINVAL;
+                       return -1;
+               }
+               mc.dev = di->source;
+               idat = INTARG;
+               if (di->caps & SOUND_CAP_EXCL_INPUT) {
+                       mc.type = AUDIO_MIXER_ENUM;
+                       for(i = 0; i < SOUND_MIXER_NRDEVICES; i++)
+                               if (idat & (1 << i))
+                                       break;
+                       if (i >= SOUND_MIXER_NRDEVICES ||
+                           di->devmap[i] == -1) {
+                               errno = EINVAL;
+                               return -1;
+                       }
+                       mc.un.ord = enum_to_ord(di, di->devmap[i]);
+               } else {
+                       mc.type = AUDIO_MIXER_SET;
+                       mc.un.mask = 0;
+                       for(i = 0; i < SOUND_MIXER_NRDEVICES; i++) {
+                               if (idat & (1 << i)) {
+                                       if (di->devmap[i] == -1) {
+                                               errno = EINVAL;
+                                               return -1;
+                                       }
+                                       mc.un.mask |=
+                                           enum_to_mask(di, di->devmap[i]);
+                               }
+                       }
+               }
+               return ioctl(fd, AUDIO_MIXER_WRITE, &mc);
+       default:
+               if (MIXER_READ(SOUND_MIXER_FIRST) <= com &&
+                   com < MIXER_READ(SOUND_MIXER_NRDEVICES)) {
+                       n = GET_DEV(com);
+                       if (di->devmap[n] == -1) {
+                               errno = EINVAL;
+                               return -1;
+                       }
+                       mc.dev = di->devmap[n];
+                       mc.type = AUDIO_MIXER_VALUE;
+                   doread:
+                       mc.un.value.num_channels =
+                           di->stereomask & (1 << (u_int)n) ? 2 : 1;
+                       retval = ioctl(fd, AUDIO_MIXER_READ, &mc);
+                       if (retval < 0)
+                               return retval;
+                       if (mc.type != AUDIO_MIXER_VALUE) {
+                               errno = EINVAL;
+                               return -1;
+                       }
+                       if (mc.un.value.num_channels != 2) {
+                               l = r =
+                                   mc.un.value.level[AUDIO_MIXER_LEVEL_MONO];
+                       } else {
+                               l = mc.un.value.level[AUDIO_MIXER_LEVEL_LEFT];
+                               r = mc.un.value.level[AUDIO_MIXER_LEVEL_RIGHT];
+                       }
+                       idat = TO_OSSVOL(l) | (TO_OSSVOL(r) << 8);
+                       break;
+               } else if ((MIXER_WRITE_R(SOUND_MIXER_FIRST) <= com &&
+                          com < MIXER_WRITE_R(SOUND_MIXER_NRDEVICES)) ||
+                          (MIXER_WRITE(SOUND_MIXER_FIRST) <= com &&
+                          com < MIXER_WRITE(SOUND_MIXER_NRDEVICES))) {
+                       n = GET_DEV(com);
+                       if (di->devmap[n] == -1) {
+                               errno = EINVAL;
+                               return -1;
+                       }
+                       idat = INTARG;
+                       l = FROM_OSSVOL((u_int)idat & 0xff);
+                       r = FROM_OSSVOL(((u_int)idat >> 8) & 0xff);
+                       mc.dev = di->devmap[n];
+                       mc.type = AUDIO_MIXER_VALUE;
+                       if (di->stereomask & (1 << (u_int)n)) {
+                               mc.un.value.num_channels = 2;
+                               mc.un.value.level[AUDIO_MIXER_LEVEL_LEFT] = l;
+                               mc.un.value.level[AUDIO_MIXER_LEVEL_RIGHT] = r;
+                       } else {
+                               mc.un.value.num_channels = 1;
+                               mc.un.value.level[AUDIO_MIXER_LEVEL_MONO] =
+                                   (l + r) / 2;
+                       }
+                       retval = ioctl(fd, AUDIO_MIXER_WRITE, &mc);
+                       if (retval < 0)
+                               return retval;
+                       if (MIXER_WRITE(SOUND_MIXER_FIRST) <= com &&
+                          com < MIXER_WRITE(SOUND_MIXER_NRDEVICES))
+                               return 0;
+                       goto doread;
+               } else {
+                       errno = EINVAL;
+                       return -1;
+               }
+       }



Home | Main Index | Thread Index | Old Index