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): Add SNDCTL_DSP_COOKEDMODE, SNDC...



details:   https://anonhg.NetBSD.org/src/rev/0ccb7856e469
branches:  trunk
changeset: 955917:0ccb7856e469
user:      nia <nia%NetBSD.org@localhost>
date:      Fri Oct 16 20:24:35 2020 +0000

description:
ossaudio(3): Add SNDCTL_DSP_COOKEDMODE, SNDCTL_DSP_GETERROR

SNDCTL_DSP_COOKEDMODE simply always returns 1.
"Cooked mode" is a silly way the OSSv4 authors chose to refer to allowing
for reprocessed streams. The NetBSD kernel always performs format
conversion and it can't be turned off.

SNDCTL_DSP_GETERROR provides access to the read/write over/underrun
counters. There are other things it might return, but they don't make
sense for our implementation.

diffstat:

 lib/libossaudio/ossaudio.c  |  41 +++++++++++++++++++++++++++++++++++++++--
 lib/libossaudio/soundcard.h |  18 +++++++++++++++++-
 2 files changed, 56 insertions(+), 3 deletions(-)

diffs (108 lines):

diff -r 1a02bab4789d -r 0ccb7856e469 lib/libossaudio/ossaudio.c
--- a/lib/libossaudio/ossaudio.c        Fri Oct 16 18:27:34 2020 +0000
+++ b/lib/libossaudio/ossaudio.c        Fri Oct 16 20:24:35 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: ossaudio.c,v 1.47 2020/10/16 15:40:16 nia Exp $        */
+/*     $NetBSD: ossaudio.c,v 1.48 2020/10/16 20:24:35 nia Exp $        */
 
 /*-
  * Copyright (c) 1997, 2020 The NetBSD Foundation, Inc.
@@ -27,7 +27,7 @@
  */
 
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: ossaudio.c,v 1.47 2020/10/16 15:40:16 nia Exp $");
+__RCSID("$NetBSD: ossaudio.c,v 1.48 2020/10/16 20:24:35 nia Exp $");
 
 /*
  * This is an Open Sound System compatibility layer, which provides
@@ -106,6 +106,7 @@
        struct audio_offset tmpoffs;
        struct audio_buf_info bufinfo;
        struct audio_format_query fmtq;
+       struct audio_errinfo *tmperrinfo;
        struct count_info cntinfo;
        struct audio_encoding tmpenc;
        struct oss_sysinfo tmpsysinfo;
@@ -118,6 +119,9 @@
        u_int u;
        u_int encoding;
        u_int precision;
+       int perrors, rerrors;
+       static int totalperrors = 0;
+       static int totalrerrors = 0;
        int idat, idata;
        int props;
        int retval;
@@ -136,6 +140,39 @@
                if (retval < 0)
                        return retval;
                break;
+       case SNDCTL_DSP_GETERROR:
+               tmperrinfo = (struct audio_errinfo *)argp;
+               if (tmperrinfo == NULL)
+                       return EINVAL;
+               memset(tmperrinfo, 0, sizeof(struct audio_errinfo));
+               if ((retval = ioctl(fd, AUDIO_GETBUFINFO, &tmpinfo)) < 0)
+                       return retval;
+               /*
+                * OSS requires that we return counters that are relative to
+                * the last call. We must maintain state here...
+                */
+               if (ioctl(fd, AUDIO_PERROR, &perrors) != -1) {
+                       perrors /= ((tmpinfo.play.precision / NBBY) *
+                           tmpinfo.play.channels);
+                       tmperrinfo->play_underruns =
+                           (perrors / tmpinfo.blocksize) - totalperrors;
+                       totalperrors += tmperrinfo->play_underruns;
+               }
+               if (ioctl(fd, AUDIO_RERROR, &rerrors) != -1) {
+                       rerrors /= ((tmpinfo.record.precision / NBBY) *
+                           tmpinfo.record.channels);
+                       tmperrinfo->rec_overruns =
+                           (rerrors / tmpinfo.blocksize) - totalrerrors;
+                       totalrerrors += tmperrinfo->rec_overruns;
+               }
+               break;
+       case SNDCTL_DSP_COOKEDMODE:
+               /*
+                * NetBSD is always running in "cooked mode" - the kernel
+                * always performs format conversions.
+                */
+               INTARG = 1;
+               break;
        case SNDCTL_DSP_POST:
                /* This call is merely advisory, and may be a nop. */
                break;
diff -r 1a02bab4789d -r 0ccb7856e469 lib/libossaudio/soundcard.h
--- a/lib/libossaudio/soundcard.h       Fri Oct 16 18:27:34 2020 +0000
+++ b/lib/libossaudio/soundcard.h       Fri Oct 16 20:24:35 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: soundcard.h,v 1.24 2014/09/09 10:45:18 nat Exp $       */
+/*     $NetBSD: soundcard.h,v 1.25 2020/10/16 20:24:35 nia Exp $       */
 
 /*-
  * Copyright (c) 1997 The NetBSD Foundation, Inc.
@@ -327,6 +327,22 @@
 #define SNDCTL_DSP_SETRECVOL           _IOW ('P',30, uint)
 #define SNDCTL_DSP_SKIP                        _IO ('P',31)
 #define SNDCTL_DSP_SILENCE             _IO ('P',32)
+#define SNDCTL_DSP_COOKEDMODE          _IOW ('P',33, int)
+#define SNDCTL_DSP_GETERROR            _IOR ('P',34, struct audio_errinfo)
+
+typedef struct audio_errinfo {
+       int play_underruns;
+       int rec_overruns;
+       unsigned int play_ptradjust;    /* Obsolete */
+       unsigned int rec_ptradjust;     /* Obsolete */
+       int play_errorcount;            /* Unused */
+       int rec_errorcount;             /* Unused */
+       int play_lasterror;             /* Unused */
+       int rec_lasterror;              /* Unused */
+       int play_errorparm;             /* Unused */
+       int rec_errorparm;              /* Unused */
+       int filler[16];                 /* Unused */
+} audio_errinfo;
 
 typedef struct oss_sysinfo {
        char product[32];



Home | Main Index | Thread Index | Old Index