PERFORCE change 99587 for review

Ryan Beasley ryanb at FreeBSD.org
Mon Jun 19 07:44:14 UTC 2006


http://perforce.freebsd.org/chv.cgi?CH=99587

Change 99587 by ryanb at ryanb_yuki on 2006/06/19 07:44:06

	Added support for SNDCTL_AUDIOINFO to dsp and mixer devices.  Also
	touched the copyright statement in sys/soundcard.h.
	
	Folded sound/pcm/dsp.h into sound/pcm/sound.h, since dsp.c now
	includes a global function (dsp_oss_audioinfo).
	
	In sound.c, strncpy => strlcpy after suggestion from Warner Losh.

Affected files ...

.. //depot/projects/soc2006/rbeasley_sound/sys/dev/sound/pcm/dsp.c#3 edit
.. //depot/projects/soc2006/rbeasley_sound/sys/dev/sound/pcm/dsp.h#2 edit
.. //depot/projects/soc2006/rbeasley_sound/sys/dev/sound/pcm/mixer.c#4 edit
.. //depot/projects/soc2006/rbeasley_sound/sys/dev/sound/pcm/sound.c#5 edit
.. //depot/projects/soc2006/rbeasley_sound/sys/dev/sound/pcm/sound.h#3 edit
.. //depot/projects/soc2006/rbeasley_sound/sys/sys/soundcard.h#3 edit

Differences ...

==== //depot/projects/soc2006/rbeasley_sound/sys/dev/sound/pcm/dsp.c#3 (text+ko) ====

@@ -1036,6 +1036,9 @@
 	case SNDCTL_SYSINFO:
 		sound_oss_sysinfo((oss_sysinfo *)arg);
 		break;
+	case SNDCTL_AUDIOINFO:
+		ret = dsp_oss_audioinfo(i_dev, (oss_audioinfo *)arg);
+		break;
 #endif	/* !OSSV4_EXPERIMENT */
     	case SNDCTL_DSP_MAPINBUF:
     	case SNDCTL_DSP_MAPOUTBUF:
@@ -1212,4 +1215,129 @@
 #endif
 
 #ifdef OSSV4_EXPERIMENT
+/**
+ * @brief Handler for SNDCTL_DSP_AUDIOINFO.
+ *
+ * Gathers information about the audio device specified in ai->dev.  If
+ * ai->dev == -1, then this function gathers information about the current
+ * device.  If the call comes in on a non-audio device and ai->dev == -1,
+ * return EINVAL.
+ *
+ * This routine is supposed to go practically straight to the hardware,
+ * getting capabilities directly from the sound card driver, side-stepping
+ * the intermediate channel interface.
+ * 
+ * @param dev		device on which the ioctl was issued
+ * @param ai		ioctl request data container
+ *
+ * @retval 0		success
+ * @retval EINVAL	ai->dev specifies an invalid device
+ *
+ * @todo Verify correctness of Doxygen tags.  ;)
+ */
+int
+dsp_oss_audioinfo(struct cdev *i_dev, oss_audioinfo *ai)
+{
+	struct snddev_info *d;
+	struct cdev *t_cdev;	/* handle 1 of target device */
+	device_t t_dev;		/* handle 2 */
+	int t_unit = 0;		/* unit # of target device */
+
+	/*
+	 * Searching by unit number, get device_t and struct cdev handles
+	 * on target audio device.
+	 */
+	if (ai->dev == -1) {
+		t_unit = PCMUNIT(i_dev);
+		t_cdev = i_dev;
+
+		if ((i_dev->si_devsw == &dsp_cdevsw) &&
+		    (t_unit < devclass_get_maxunit(pcm_devclass))) {
+			t_dev = devclass_get_device(pcm_devclass, t_unit);
+		} else {
+			/* Not an audio device */
+			return EINVAL;
+		}
+	} else {
+		t_dev = devclass_get_device(pcm_devclass, ai->dev);
+		if (t_dev == NULL)
+			return EINVAL;
+		t_unit = device_get_unit(t_dev);
+		 
+		LIST_FOREACH(t_cdev, &dsp_cdevsw.d_devs, si_list) {
+			if (PCMUNIT(t_cdev) == t_unit)
+				break;
+		}
+
+		if (t_cdev == NULL)
+			return EINVAL;
+	}
+
+	d = dsp_get_info(t_cdev);
+
+	/*
+	 * With all handles collected, zero out the user's container and
+	 * begin filling in its fields.
+	 */
+	bzero((void *)ai, sizeof(oss_audioinfo));
+
+	ai->dev = t_unit;
+	strlcpy(ai->name, device_get_desc(t_dev), sizeof(ai->name));
+	/**
+	 * @todo \c busy	requires examining all channels
+	 *
+	 * @note
+	 * \c pid - OSSv4 docs: "Value of -1 means that this information is
+	 * 	not available or the device is currently not open."  Since
+	 * 	multiple processes may open a device, I'm going with the
+	 * 	former.
+	 * @par
+	 * \c cmd - Same caveat as \c pid.
+	 */
+	ai->pid = -1;
+	/**
+	 * @todo \c caps - requires going directly to sound card driver
+	 * @todo \c iformats - same todo as \c caps
+	 * @todo \c oformats - same todo as \c caps
+	 *
+	 * @note
+	 * \c magic - OSSv4 docs: "Reserved for internal use by OSS."
+	 *
+	 * @par
+	 * \c card_number - OSSv4 docs: "Number of the sound card where this
+	 * 	device belongs or -1 if this information is not available.
+	 * 	Applications should normally not use this field for any
+	 * 	purpose."
+	 */
+	ai->card_number = -1;
+	/**
+	 * @todo \c song_name - depends first on SNDCTL_[GS]ETSONG
+	 * @todo \c label - depends on SNDCTL_[GS]ETLABEL
+	 * @todo \c port_number - device unit number?
+	 */
+	ai->port_number = -1;
+	ai->mixer_dev = (d->mixer_dev != NULL) ? PCMUNIT(d->mixer_dev) : -1;
+	ai->real_device = t_unit;
+	strlcpy(ai->devnode, t_cdev->si_name, sizeof(ai->devnode));
+	ai->enabled = device_is_attached(t_dev) ? 1 : 0;
+	/**
+	 * @note
+	 * \c flags - OSSv4 docs: "Reserved for future use."
+	 *
+	 * @todo \c min_rate - same todo as \c caps
+	 * @todo \c max_rate - same todo as \c caps
+	 * @todo \c nrates - same todo as \c caps
+	 * @todo \c rates - same todo as \c caps
+	 * @todo \c min_channels - same todo as \c caps
+	 * @todo \c max_channels - same todo as \c caps
+	 *
+	 * @note
+	 * \c binding - OSSv4 docs: "Reserved for future use."
+	 *
+	 * @todo \c handle - haven't decided how to generate this yet; bus,
+	 * 	vendor, device IDs?
+	 */
+
+	return 0;
+}
 #endif	/* !OSSV4_EXPERIMENT */

==== //depot/projects/soc2006/rbeasley_sound/sys/dev/sound/pcm/dsp.h#2 (text+ko) ====

@@ -1,3 +1,4 @@
+#ifndef _PCMDSP_H_
 /*-
  * Copyright (c) 1999 Cameron Grant <cg at freebsd.org>
  * All rights reserved.
@@ -27,3 +28,9 @@
  */
 
 extern struct cdevsw dsp_cdevsw;
+
+#ifdef OSSV4_EXPERIMENT
+int dsp_oss_audioinfo(struct cdev *, oss_audioinfo *);
+#endif
+
+#endif /* !_PCMDSP_H_ */

==== //depot/projects/soc2006/rbeasley_sound/sys/dev/sound/pcm/mixer.c#4 (text+ko) ====

@@ -533,6 +533,10 @@
 		sound_oss_sysinfo((oss_sysinfo *)arg);
 		snd_mtxunlock(m->lock);
 		return 0;
+	} else if (cmd == SNDCTL_AUDIOINFO) {
+		ret = dsp_oss_audioinfo(i_dev, (oss_audioinfo *)arg);
+		snd_mtxunlock(m->lock);
+		return ret;
 	}
 #endif /* !OSSV4_EXPERIMENT */
 	snd_mtxunlock(m->lock);

==== //depot/projects/soc2006/rbeasley_sound/sys/dev/sound/pcm/sound.c#5 (text+ko) ====

@@ -1140,10 +1140,8 @@
 	static char si_product[] = "FreeBSD native OSS ABI";
 	static char si_version[] = __XSTRING(__FreeBSD_version);
 
-	strncpy(si->product, si_product, sizeof(si->product) - 1);
-	si->product[sizeof(si->product) - 1] = '\0';
-	strncpy(si->version, si_version, sizeof(si->version) - 1);
-	si->product[sizeof(si->product) - 1] = '\0';
+	strlcpy(si->product, si_product, sizeof(si->product));
+	strlcpy(si->version, si_version, sizeof(si->version));
 	si->versionnum = SOUND_VERSION;
 	si->numaudios = (pcm_devclass != NULL) ?
 	    		devclass_get_count(pcm_devclass) :

==== //depot/projects/soc2006/rbeasley_sound/sys/dev/sound/pcm/sound.h#3 (text+ko) ====

@@ -92,6 +92,7 @@
 #include <dev/sound/pcm/channel.h>
 #include <dev/sound/pcm/feeder.h>
 #include <dev/sound/pcm/mixer.h>
+#include <dev/sound/pcm/dsp.h>
 
 #define	PCM_SOFTC_SIZE	512
 

==== //depot/projects/soc2006/rbeasley_sound/sys/sys/soundcard.h#3 (text+ko) ====

@@ -3,7 +3,7 @@
  */
 
 /*-
- * Copyright by Hannu Savolainen 1993
+ * Copyright by Hannu Savolainen 1993 / 4Front Technologies 1993-2006
  * Modified for the new FreeBSD sound driver by Luigi Rizzo, 1997
  *
  * Redistribution and use in source and binary forms, with or without
@@ -32,6 +32,12 @@
  * $FreeBSD: src/sys/sys/soundcard.h,v 1.45 2005/07/31 16:08:03 netchild Exp $
  */
 
+/*
+ * Unless coordinating changes with 4Front Technologies, do NOT make any
+ * modifications to ioctl commands, types, etc. that would break
+ * compatibility with the OSS API.
+ */
+
 #ifndef _SYS_SOUNDCARD_H_
 #define _SYS_SOUNDCARD_H_
  /*
@@ -1439,6 +1445,15 @@
 
 /***********************************************************************/
 
+/*
+ * Sections copyright 4Front Technologies 1993-2006.
+ *
+ * This file also contains changes taken in summer 2006 from
+ * sys/soundcard.h of 4Front Technologies OSS driver which contains
+ * the same copyright as above.
+ *
+ */     
+
 /**
  * XXX OSSv4 defines -- some bits taken straight out of the new
  * sys/soundcard.h bundled with recent OSS releases.
@@ -1446,6 +1461,9 @@
  * NB:  These macros and structures will be reorganized and inserted
  * 	in appropriate places throughout this file once the code begins
  * 	to take shape.
+ *
+ * @todo reorganize layout more like the 4Front version
+ * @todo ask about maintaining __SIOWR vs. _IOWR ioctl cmd defines
  */
 #define OSSV4_EXPERIMENT 1
 #ifdef OSSV4_EXPERIMENT
@@ -1455,8 +1473,14 @@
 # define SOUND_VERSION	0x040000
 #endif	/* !SOUND_VERSION */
 
+#define OSS_LONGNAME_SIZE	64
+#define OSS_LABEL_SIZE		16
+#define OSS_DEVNODE_SIZE        32
+typedef char oss_longname_t[OSS_LONGNAME_SIZE];
+typedef char oss_label_t[OSS_LABEL_SIZE];
+typedef char oss_devnode_t[OSS_DEVNODE_SIZE];
+
 /**
- * @struct oss_sysinfo
  * @brief	Argument for SNDCTL_SYSINFO ioctl.
  *
  * For use w/ the SNDCTL_SYSINFO ioctl available on audio (/dev/dsp*),
@@ -1485,6 +1509,48 @@
 #define SNDCTL_SYSINFO          _IOR ('X', 1, oss_sysinfo)
 #define OSS_SYSINFO             SNDCTL_SYSINFO /* Old name */
 
+#define OPEN_READ       PCM_ENABLE_INPUT
+#define OPEN_WRITE      PCM_ENABLE_OUTPUT
+#define OPEN_READWRITE  (OPEN_READ|OPEN_WRITE)
+
+/**
+ * @brief	Argument for SNDCTL_AUDIOINFO ioctl.
+ *
+ * For use w/ the SNDCTL_AUDIOINFO ioctl available on audio (/dev/dsp*)
+ * devices.
+ */
+typedef struct oss_audioinfo
+{
+  int dev;                      /* Audio device number */
+  char name[64];
+  int busy;                     /* 0, OPEN_READ, OPEN_WRITE or OPEN_READWRITE */
+  int pid;
+  int caps;                     /* DSP_CAP_INPUT, DSP_CAP_OUTPUT */
+  int iformats, oformats;
+  int magic;                    /* Reserved for internal use */
+  char cmd[64];                 /* Command using the device (if known) */
+  int card_number;
+  int port_number;
+  int mixer_dev;
+  int real_device;              /* Obsolete field. Replaced by devnode */
+  int enabled;                  /* 1=enabled, 0=device not ready at this moment */
+  int flags;                    /* For internal use only - no practical meaning */
+  int min_rate, max_rate;       /* Sample rate limits */
+  int min_channels, max_channels;       /* Number of channels supported */
+  int binding;                  /* DSP_BIND_FRONT, etc. 0 means undefined */
+  int rate_source;
+  char handle[32];
+  #define MAX_SAMPLE_RATES        20      /* Cannot be changed  */
+  unsigned int nrates, rates[MAX_SAMPLE_RATES]; /* Please read the manual before using these */
+  oss_longname_t song_name;     /* Song name (if given) */
+  oss_label_t label;            /* Device label (if given) */
+  int latency;                  /* In usecs, -1=unknown */
+  oss_devnode_t devnode;        /* Device special file name (inside /dev) */
+  int filler[186];
+} oss_audioinfo;
+
+#define SNDCTL_AUDIOINFO        _IOWR('X', 7, oss_audioinfo)
+
 #endif   /* !OSSV4_EXPERIMENT */
 
 #endif	/* !_SYS_SOUNDCARD_H_ */


More information about the p4-projects mailing list