2003-07-27 00:34:11 +04:00
|
|
|
/* $NetBSD: ctl.c,v 1.35 2003/07/26 20:34:12 salo Exp $ */
|
1997-05-13 21:35:50 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright (c) 1997 The NetBSD Foundation, Inc.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
1998-11-26 01:17:06 +03:00
|
|
|
* This code is derived from software contributed to The NetBSD Foundation
|
2003-07-27 00:34:11 +04:00
|
|
|
* by Lennart Augustsson (augustss@NetBSD.org).
|
1997-05-13 21:35:50 +04:00
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
* 3. All advertising materials mentioning features or use of this software
|
|
|
|
* must display the following acknowledgement:
|
|
|
|
* This product includes software developed by the NetBSD
|
|
|
|
* Foundation, Inc. and its contributors.
|
|
|
|
* 4. Neither the name of The NetBSD Foundation nor the names of its
|
|
|
|
* contributors may be used to endorse or promote products derived
|
|
|
|
* from this software without specific prior written permission.
|
|
|
|
*
|
|
|
|
* 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
|
1997-10-09 02:31:53 +04:00
|
|
|
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
|
|
|
|
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
1997-05-13 21:35:50 +04:00
|
|
|
* 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.
|
|
|
|
*/
|
2003-06-23 16:15:00 +04:00
|
|
|
#include <sys/cdefs.h>
|
|
|
|
|
|
|
|
#ifndef lint
|
2003-07-27 00:34:11 +04:00
|
|
|
__RCSID("$NetBSD: ctl.c,v 1.35 2003/07/26 20:34:12 salo Exp $");
|
2003-06-23 16:15:00 +04:00
|
|
|
#endif
|
|
|
|
|
1997-05-13 21:35:50 +04:00
|
|
|
|
|
|
|
#include <sys/types.h>
|
1997-05-19 20:32:54 +04:00
|
|
|
#include <sys/stat.h>
|
1997-05-13 21:35:50 +04:00
|
|
|
#include <sys/ioctl.h>
|
|
|
|
#include <sys/audioio.h>
|
|
|
|
|
1999-03-26 17:02:39 +03:00
|
|
|
#include <err.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
|
|
|
|
#include <paths.h>
|
|
|
|
|
|
|
|
#include "libaudio.h"
|
|
|
|
|
2002-01-16 02:48:51 +03:00
|
|
|
struct field *findfield (const char *name);
|
|
|
|
void prfield (struct field *p, const char *sep);
|
2000-12-22 14:38:42 +03:00
|
|
|
void rdfield (struct field *p, char *q);
|
|
|
|
void getinfo (int fd);
|
|
|
|
void audioctl_write (int, int, char *[]);
|
|
|
|
void usage (void);
|
|
|
|
int main (int argc, char **argv);
|
1997-10-07 17:55:03 +04:00
|
|
|
|
1997-05-13 21:35:50 +04:00
|
|
|
audio_device_t adev;
|
|
|
|
|
|
|
|
audio_info_t info;
|
|
|
|
|
|
|
|
char encbuf[1000];
|
|
|
|
|
1997-07-27 05:28:04 +04:00
|
|
|
int properties, fullduplex, rerror;
|
1997-05-13 21:35:50 +04:00
|
|
|
|
|
|
|
struct field {
|
2002-01-16 02:48:51 +03:00
|
|
|
const char *name;
|
1997-05-13 21:35:50 +04:00
|
|
|
void *valp;
|
|
|
|
int format;
|
|
|
|
#define STRING 1
|
|
|
|
#define INT 2
|
|
|
|
#define UINT 3
|
|
|
|
#define P_R 4
|
1998-08-13 13:36:34 +04:00
|
|
|
#define ULONG 5 /* XXX obsolete now */
|
1997-05-13 21:35:50 +04:00
|
|
|
#define UCHAR 6
|
|
|
|
#define ENC 7
|
1997-07-27 05:28:04 +04:00
|
|
|
#define PROPS 8
|
1997-10-19 11:44:12 +04:00
|
|
|
#define XINT 9
|
1998-08-10 22:19:03 +04:00
|
|
|
#define FORMAT 10
|
1997-05-19 20:32:54 +04:00
|
|
|
char flags;
|
|
|
|
#define READONLY 1
|
|
|
|
#define ALIAS 2
|
|
|
|
#define SET 4
|
1997-05-13 21:35:50 +04:00
|
|
|
} fields[] = {
|
1997-10-11 17:40:26 +04:00
|
|
|
{ "name", &adev.name, STRING, READONLY },
|
|
|
|
{ "version", &adev.version, STRING, READONLY },
|
|
|
|
{ "config", &adev.config, STRING, READONLY },
|
|
|
|
{ "encodings", encbuf, STRING, READONLY },
|
|
|
|
{ "properties", &properties, PROPS, READONLY },
|
1998-07-13 19:11:03 +04:00
|
|
|
{ "full_duplex", &fullduplex, UINT, 0 },
|
|
|
|
{ "fullduplex", &fullduplex, UINT, 0 },
|
1997-10-11 17:40:26 +04:00
|
|
|
{ "blocksize", &info.blocksize, UINT, 0 },
|
|
|
|
{ "hiwat", &info.hiwat, UINT, 0 },
|
|
|
|
{ "lowat", &info.lowat, UINT, 0 },
|
1997-10-19 11:44:12 +04:00
|
|
|
{ "monitor_gain", &info.monitor_gain, UINT, 0 },
|
1997-10-11 17:40:26 +04:00
|
|
|
{ "mode", &info.mode, P_R, READONLY },
|
1998-08-10 22:19:03 +04:00
|
|
|
{ "play", &info.play, FORMAT, ALIAS },
|
1997-10-11 17:40:26 +04:00
|
|
|
{ "play.rate", &info.play.sample_rate, UINT, 0 },
|
|
|
|
{ "play.sample_rate", &info.play.sample_rate, UINT, ALIAS },
|
|
|
|
{ "play.channels", &info.play.channels, UINT, 0 },
|
|
|
|
{ "play.precision", &info.play.precision, UINT, 0 },
|
|
|
|
{ "play.encoding", &info.play.encoding, ENC, 0 },
|
|
|
|
{ "play.gain", &info.play.gain, UINT, 0 },
|
1997-10-19 11:44:12 +04:00
|
|
|
{ "play.balance", &info.play.balance, UCHAR, 0 },
|
|
|
|
{ "play.port", &info.play.port, XINT, 0 },
|
|
|
|
{ "play.avail_ports", &info.play.avail_ports, XINT, 0 },
|
1998-08-13 13:36:34 +04:00
|
|
|
{ "play.seek", &info.play.seek, UINT, READONLY },
|
1997-10-11 17:40:26 +04:00
|
|
|
{ "play.samples", &info.play.samples, UINT, READONLY },
|
|
|
|
{ "play.eof", &info.play.eof, UINT, READONLY },
|
|
|
|
{ "play.pause", &info.play.pause, UCHAR, 0 },
|
|
|
|
{ "play.error", &info.play.error, UCHAR, READONLY },
|
|
|
|
{ "play.waiting", &info.play.waiting, UCHAR, READONLY },
|
|
|
|
{ "play.open", &info.play.open, UCHAR, READONLY },
|
|
|
|
{ "play.active", &info.play.active, UCHAR, READONLY },
|
1997-10-19 11:44:12 +04:00
|
|
|
{ "play.buffer_size", &info.play.buffer_size, UINT, 0 },
|
1998-08-10 22:19:03 +04:00
|
|
|
{ "record", &info.record, FORMAT, ALIAS },
|
1997-10-11 17:40:26 +04:00
|
|
|
{ "record.rate", &info.record.sample_rate,UINT, 0 },
|
|
|
|
{ "record.sample_rate", &info.record.sample_rate,UINT, ALIAS },
|
|
|
|
{ "record.channels", &info.record.channels, UINT, 0 },
|
|
|
|
{ "record.precision", &info.record.precision, UINT, 0 },
|
|
|
|
{ "record.encoding", &info.record.encoding, ENC, 0 },
|
|
|
|
{ "record.gain", &info.record.gain, UINT, 0 },
|
1997-10-19 11:44:12 +04:00
|
|
|
{ "record.balance", &info.record.balance, UCHAR, 0 },
|
|
|
|
{ "record.port", &info.record.port, XINT, 0 },
|
|
|
|
{ "record.avail_ports", &info.record.avail_ports,XINT, 0 },
|
1998-08-13 13:36:34 +04:00
|
|
|
{ "record.seek", &info.record.seek, UINT, READONLY },
|
1997-10-11 17:40:26 +04:00
|
|
|
{ "record.samples", &info.record.samples, UINT, READONLY },
|
|
|
|
{ "record.eof", &info.record.eof, UINT, READONLY },
|
|
|
|
{ "record.pause", &info.record.pause, UCHAR, 0 },
|
|
|
|
{ "record.error", &info.record.error, UCHAR, READONLY },
|
|
|
|
{ "record.waiting", &info.record.waiting, UCHAR, READONLY },
|
|
|
|
{ "record.open", &info.record.open, UCHAR, READONLY },
|
|
|
|
{ "record.active", &info.record.active, UCHAR, READONLY },
|
1997-10-19 11:44:12 +04:00
|
|
|
{ "record.buffer_size", &info.record.buffer_size,UINT, 0 },
|
1997-10-11 17:40:26 +04:00
|
|
|
{ "record.errors", &rerror, INT, READONLY },
|
|
|
|
{ 0 }
|
1997-05-13 21:35:50 +04:00
|
|
|
};
|
|
|
|
|
1997-10-11 17:40:26 +04:00
|
|
|
static struct {
|
2002-01-16 02:48:51 +03:00
|
|
|
const char *name;
|
1997-10-11 17:40:26 +04:00
|
|
|
u_int prop;
|
|
|
|
} props[] = {
|
|
|
|
{ "full_duplex", AUDIO_PROP_FULLDUPLEX },
|
|
|
|
{ "mmap", AUDIO_PROP_MMAP },
|
|
|
|
{ "independent", AUDIO_PROP_INDEPENDENT },
|
|
|
|
{ 0 }
|
1997-05-13 21:35:50 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
struct field *
|
1997-10-07 17:55:03 +04:00
|
|
|
findfield(name)
|
2002-01-16 02:48:51 +03:00
|
|
|
const char *name;
|
1997-05-13 21:35:50 +04:00
|
|
|
{
|
1997-10-11 17:40:26 +04:00
|
|
|
int i;
|
1999-03-26 17:02:39 +03:00
|
|
|
for (i = 0; fields[i].name; i++)
|
1997-10-11 17:40:26 +04:00
|
|
|
if (strcmp(fields[i].name, name) == 0)
|
|
|
|
return &fields[i];
|
|
|
|
return 0;
|
1997-05-13 21:35:50 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
1997-10-07 17:55:03 +04:00
|
|
|
prfield(p, sep)
|
1997-10-11 17:40:26 +04:00
|
|
|
struct field *p;
|
2002-01-16 02:48:51 +03:00
|
|
|
const char *sep;
|
1997-05-13 21:35:50 +04:00
|
|
|
{
|
1997-10-11 17:40:26 +04:00
|
|
|
u_int v;
|
2002-01-16 02:48:51 +03:00
|
|
|
const char *cm, *encstr;
|
1997-10-11 17:40:26 +04:00
|
|
|
int i;
|
1997-05-13 21:35:50 +04:00
|
|
|
|
1997-10-11 17:40:26 +04:00
|
|
|
if (sep)
|
2002-01-27 21:21:52 +03:00
|
|
|
printf("%s%s", p->name, sep);
|
1997-10-11 17:40:26 +04:00
|
|
|
switch(p->format) {
|
|
|
|
case STRING:
|
2002-01-27 21:21:52 +03:00
|
|
|
printf("%s", (char*)p->valp);
|
1997-05-19 20:32:54 +04:00
|
|
|
break;
|
1997-10-11 17:40:26 +04:00
|
|
|
case INT:
|
2002-01-27 21:21:52 +03:00
|
|
|
printf("%d", *(int*)p->valp);
|
1997-10-11 17:40:26 +04:00
|
|
|
break;
|
|
|
|
case UINT:
|
2002-01-27 21:21:52 +03:00
|
|
|
printf("%u", *(u_int*)p->valp);
|
1997-10-11 17:40:26 +04:00
|
|
|
break;
|
1997-10-19 11:44:12 +04:00
|
|
|
case XINT:
|
2002-01-27 21:21:52 +03:00
|
|
|
printf("0x%x", *(u_int*)p->valp);
|
1997-10-19 11:44:12 +04:00
|
|
|
break;
|
1997-10-11 17:40:26 +04:00
|
|
|
case UCHAR:
|
2002-01-27 21:21:52 +03:00
|
|
|
printf("%u", *(u_char*)p->valp);
|
1997-10-11 17:40:26 +04:00
|
|
|
break;
|
|
|
|
case ULONG:
|
2002-01-27 21:21:52 +03:00
|
|
|
printf("%lu", *(u_long*)p->valp);
|
1997-10-11 17:40:26 +04:00
|
|
|
break;
|
|
|
|
case P_R:
|
|
|
|
v = *(u_int*)p->valp;
|
|
|
|
cm = "";
|
|
|
|
if (v & AUMODE_PLAY) {
|
|
|
|
if (v & AUMODE_PLAY_ALL)
|
2002-01-27 21:21:52 +03:00
|
|
|
printf("play");
|
1997-10-11 17:40:26 +04:00
|
|
|
else
|
2002-01-27 21:21:52 +03:00
|
|
|
printf("playsync");
|
1997-10-11 17:40:26 +04:00
|
|
|
cm = ",";
|
|
|
|
}
|
|
|
|
if (v & AUMODE_RECORD)
|
2002-01-27 21:21:52 +03:00
|
|
|
printf("%srecord", cm);
|
1997-10-11 17:40:26 +04:00
|
|
|
break;
|
|
|
|
case ENC:
|
|
|
|
v = *(u_int*)p->valp;
|
1999-03-26 17:02:39 +03:00
|
|
|
encstr = audio_enc_from_val(v);
|
|
|
|
if (encstr)
|
2002-01-27 21:21:52 +03:00
|
|
|
printf("%s", encstr);
|
1997-10-11 17:40:26 +04:00
|
|
|
else
|
2002-01-27 21:21:52 +03:00
|
|
|
printf("%u", v);
|
1997-10-11 17:40:26 +04:00
|
|
|
break;
|
|
|
|
case PROPS:
|
|
|
|
v = *(u_int*)p->valp;
|
|
|
|
for (cm = "", i = 0; props[i].name; i++) {
|
|
|
|
if (v & props[i].prop) {
|
2002-01-27 21:21:52 +03:00
|
|
|
printf("%s%s", cm, props[i].name);
|
1997-10-11 17:40:26 +04:00
|
|
|
cm = ",";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
1998-08-10 22:19:03 +04:00
|
|
|
case FORMAT:
|
|
|
|
prfield(p + 1, 0);
|
2002-01-27 21:21:52 +03:00
|
|
|
printf(",");
|
1998-08-10 22:19:03 +04:00
|
|
|
prfield(p + 3, 0);
|
2002-01-27 21:21:52 +03:00
|
|
|
printf(",");
|
1998-08-10 22:19:03 +04:00
|
|
|
prfield(p + 4, 0);
|
2002-01-27 21:21:52 +03:00
|
|
|
printf(",");
|
1998-08-10 22:19:03 +04:00
|
|
|
prfield(p + 5, 0);
|
|
|
|
break;
|
1997-10-11 17:40:26 +04:00
|
|
|
default:
|
1997-10-19 11:44:12 +04:00
|
|
|
errx(1, "Invalid print format.");
|
1997-07-27 05:28:04 +04:00
|
|
|
}
|
1997-05-13 21:35:50 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
1997-10-07 17:55:03 +04:00
|
|
|
rdfield(p, q)
|
1997-10-11 17:40:26 +04:00
|
|
|
struct field *p;
|
|
|
|
char *q;
|
1997-05-13 21:35:50 +04:00
|
|
|
{
|
1999-03-26 17:02:39 +03:00
|
|
|
int enc;
|
1997-10-19 11:44:12 +04:00
|
|
|
u_int u;
|
1998-08-10 22:19:03 +04:00
|
|
|
char *s;
|
1997-05-13 21:35:50 +04:00
|
|
|
|
1997-10-11 17:40:26 +04:00
|
|
|
switch(p->format) {
|
|
|
|
case UINT:
|
|
|
|
if (sscanf(q, "%u", (unsigned int *)p->valp) != 1)
|
1998-08-10 22:19:03 +04:00
|
|
|
errx(1, "Bad number: %s", q);
|
1997-05-13 21:35:50 +04:00
|
|
|
break;
|
1997-10-19 11:44:12 +04:00
|
|
|
case UCHAR:
|
|
|
|
if (sscanf(q, "%u", &u) != 1)
|
1998-08-10 22:19:03 +04:00
|
|
|
errx(1, "Bad number: %s", q);
|
1997-10-19 11:44:12 +04:00
|
|
|
else
|
|
|
|
*(u_char *)p->valp = u;
|
|
|
|
break;
|
|
|
|
case XINT:
|
|
|
|
if (sscanf(q, "0x%x", (unsigned int *)p->valp) != 1 &&
|
|
|
|
sscanf(q, "%x", (unsigned int *)p->valp) != 1)
|
1998-08-10 22:19:03 +04:00
|
|
|
errx(1, "Bad number: %s", q);
|
1997-10-19 11:44:12 +04:00
|
|
|
break;
|
1997-10-11 17:40:26 +04:00
|
|
|
case ENC:
|
1999-03-26 17:02:39 +03:00
|
|
|
enc = audio_enc_to_val(q);
|
|
|
|
if (enc >= 0)
|
|
|
|
*(u_int*)p->valp = enc;
|
1997-10-11 17:40:26 +04:00
|
|
|
else
|
1998-08-10 22:19:03 +04:00
|
|
|
errx(1, "Unknown encoding: %s", q);
|
|
|
|
break;
|
|
|
|
case FORMAT:
|
|
|
|
s = strsep(&q, ",");
|
|
|
|
if (s)
|
|
|
|
rdfield(p + 1, s);
|
|
|
|
s = strsep(&q, ",");
|
|
|
|
if (s)
|
|
|
|
rdfield(p + 3, s);
|
|
|
|
s = strsep(&q, ",");
|
|
|
|
if (s)
|
|
|
|
rdfield(p + 4, s);
|
|
|
|
s = strsep(&q, ",");
|
|
|
|
if (s)
|
|
|
|
rdfield(p + 5, s);
|
|
|
|
if (!s || q)
|
|
|
|
errx(1, "Bad format");
|
1997-10-11 17:40:26 +04:00
|
|
|
break;
|
|
|
|
default:
|
1997-10-19 11:44:12 +04:00
|
|
|
errx(1, "Invalid read format.");
|
1997-10-11 17:40:26 +04:00
|
|
|
}
|
|
|
|
p->flags |= SET;
|
1997-05-13 21:35:50 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
1997-10-07 17:55:03 +04:00
|
|
|
getinfo(fd)
|
1997-10-11 17:40:26 +04:00
|
|
|
int fd;
|
1997-05-13 21:35:50 +04:00
|
|
|
{
|
1997-10-11 17:40:26 +04:00
|
|
|
int pos, i;
|
1997-05-13 21:35:50 +04:00
|
|
|
|
1997-10-11 17:40:26 +04:00
|
|
|
if (ioctl(fd, AUDIO_GETDEV, &adev) < 0)
|
|
|
|
err(1, "AUDIO_GETDEV");
|
1998-07-28 23:22:54 +04:00
|
|
|
for (pos = 0, i = 0; ; i++) {
|
1997-10-11 17:40:26 +04:00
|
|
|
audio_encoding_t enc;
|
|
|
|
enc.index = i;
|
|
|
|
if (ioctl(fd, AUDIO_GETENC, &enc) < 0)
|
|
|
|
break;
|
1998-07-28 23:22:54 +04:00
|
|
|
if (pos >= sizeof(encbuf)-1)
|
|
|
|
break;
|
1997-10-11 17:40:26 +04:00
|
|
|
if (pos)
|
|
|
|
encbuf[pos++] = ',';
|
1998-07-28 23:22:54 +04:00
|
|
|
if (pos >= sizeof(encbuf)-1)
|
|
|
|
break;
|
|
|
|
pos += snprintf(encbuf+pos, sizeof(encbuf)-pos, "%s:%d%s",
|
2001-03-28 07:18:39 +04:00
|
|
|
enc.name, enc.precision,
|
1997-10-11 17:40:26 +04:00
|
|
|
enc.flags & AUDIO_ENCODINGFLAG_EMULATED ? "*" : "");
|
|
|
|
}
|
|
|
|
if (ioctl(fd, AUDIO_GETFD, &fullduplex) < 0)
|
|
|
|
err(1, "AUDIO_GETFD");
|
|
|
|
if (ioctl(fd, AUDIO_GETPROPS, &properties) < 0)
|
|
|
|
err(1, "AUDIO_GETPROPS");
|
|
|
|
if (ioctl(fd, AUDIO_RERROR, &rerror) < 0)
|
|
|
|
err(1, "AUDIO_RERROR");
|
|
|
|
if (ioctl(fd, AUDIO_GETINFO, &info) < 0)
|
|
|
|
err(1, "AUDIO_GETINFO");
|
1997-05-19 20:32:54 +04:00
|
|
|
}
|
1997-05-13 21:35:50 +04:00
|
|
|
|
1997-05-19 20:32:54 +04:00
|
|
|
void
|
1997-10-07 17:55:03 +04:00
|
|
|
usage()
|
1997-05-19 20:32:54 +04:00
|
|
|
{
|
2001-02-20 02:03:42 +03:00
|
|
|
const char *prog = getprogname();
|
1999-03-26 17:02:39 +03:00
|
|
|
|
2002-01-27 13:09:55 +03:00
|
|
|
fprintf(stderr, "Usage: %s [-d file] [-n] name ...\n", prog);
|
|
|
|
fprintf(stderr, "Usage: %s [-d file] [-n] -w name=value ...\n", prog);
|
|
|
|
fprintf(stderr, "Usage: %s [-d file] [-n] -a\n", prog);
|
1997-10-11 17:40:26 +04:00
|
|
|
exit(1);
|
1997-05-19 20:32:54 +04:00
|
|
|
}
|
|
|
|
|
1997-10-07 17:55:03 +04:00
|
|
|
int
|
|
|
|
main(argc, argv)
|
1997-10-11 17:40:26 +04:00
|
|
|
int argc;
|
|
|
|
char **argv;
|
1997-05-19 20:32:54 +04:00
|
|
|
{
|
1997-10-11 17:40:26 +04:00
|
|
|
int fd, i, ch;
|
|
|
|
int aflag = 0, wflag = 0;
|
2002-02-05 03:17:26 +03:00
|
|
|
const char *deffile = _PATH_AUDIOCTL;
|
1998-07-28 23:22:54 +04:00
|
|
|
const char *file;
|
2002-01-16 02:48:51 +03:00
|
|
|
const char *sep = "=";
|
2001-03-28 07:18:39 +04:00
|
|
|
|
1998-04-27 20:55:23 +04:00
|
|
|
file = getenv("AUDIOCTLDEVICE");
|
2002-01-31 03:03:23 +03:00
|
|
|
if (file == NULL)
|
2002-02-05 03:17:26 +03:00
|
|
|
file = deffile;
|
2001-03-28 07:18:39 +04:00
|
|
|
|
2002-01-27 13:09:55 +03:00
|
|
|
while ((ch = getopt(argc, argv, "ad:f:nw")) != -1) {
|
1997-10-11 17:40:26 +04:00
|
|
|
switch(ch) {
|
|
|
|
case 'a':
|
|
|
|
aflag++;
|
|
|
|
break;
|
|
|
|
case 'w':
|
|
|
|
wflag++;
|
|
|
|
break;
|
|
|
|
case 'n':
|
|
|
|
sep = 0;
|
|
|
|
break;
|
2003-01-06 16:26:24 +03:00
|
|
|
case 'f': /* compatibility */
|
2002-01-27 13:09:55 +03:00
|
|
|
case 'd':
|
1997-10-11 17:40:26 +04:00
|
|
|
file = optarg;
|
|
|
|
break;
|
|
|
|
case '?':
|
|
|
|
default:
|
|
|
|
usage();
|
|
|
|
}
|
1997-05-13 21:35:50 +04:00
|
|
|
}
|
1997-10-11 17:40:26 +04:00
|
|
|
argc -= optind;
|
|
|
|
argv += optind;
|
2001-03-28 07:18:39 +04:00
|
|
|
|
1997-10-11 17:40:26 +04:00
|
|
|
fd = open(file, O_WRONLY);
|
|
|
|
if (fd < 0)
|
|
|
|
fd = open(file, O_RDONLY);
|
2002-02-05 03:17:26 +03:00
|
|
|
if (fd < 0 && file == deffile) {
|
2002-01-31 03:03:23 +03:00
|
|
|
file = _PATH_AUDIOCTL0;
|
1998-08-21 23:45:37 +04:00
|
|
|
fd = open(file, O_WRONLY);
|
|
|
|
if (fd < 0)
|
|
|
|
fd = open(file, O_RDONLY);
|
|
|
|
}
|
2002-01-31 03:03:23 +03:00
|
|
|
|
1997-10-11 17:40:26 +04:00
|
|
|
if (fd < 0)
|
|
|
|
err(1, "%s", file);
|
2001-03-28 07:18:39 +04:00
|
|
|
|
1997-10-11 17:40:26 +04:00
|
|
|
if (!wflag)
|
1997-05-19 20:32:54 +04:00
|
|
|
getinfo(fd);
|
1997-10-11 17:40:26 +04:00
|
|
|
|
|
|
|
if (argc == 0 && aflag && !wflag) {
|
1999-03-26 17:02:39 +03:00
|
|
|
for (i = 0; fields[i].name; i++) {
|
1997-10-11 17:40:26 +04:00
|
|
|
if (!(fields[i].flags & ALIAS)) {
|
|
|
|
prfield(&fields[i], sep);
|
2002-01-27 21:21:52 +03:00
|
|
|
printf("\n");
|
1997-10-11 17:40:26 +04:00
|
|
|
}
|
1997-05-13 21:35:50 +04:00
|
|
|
}
|
1997-10-11 17:40:26 +04:00
|
|
|
} else if (argc > 0 && !aflag) {
|
|
|
|
if (wflag) {
|
1999-03-26 17:02:39 +03:00
|
|
|
audioctl_write(fd, argc, argv);
|
1997-10-11 17:40:26 +04:00
|
|
|
if (sep) {
|
|
|
|
getinfo(fd);
|
1999-03-26 17:02:39 +03:00
|
|
|
for (i = 0; fields[i].name; i++) {
|
1997-10-11 17:40:26 +04:00
|
|
|
if (fields[i].flags & SET) {
|
2002-01-27 21:21:52 +03:00
|
|
|
printf("%s: -> ", fields[i].name);
|
1997-10-11 17:40:26 +04:00
|
|
|
prfield(&fields[i], 0);
|
2002-01-27 21:21:52 +03:00
|
|
|
printf("\n");
|
1997-10-11 17:40:26 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
1997-05-13 21:35:50 +04:00
|
|
|
} else {
|
1999-03-26 17:02:39 +03:00
|
|
|
struct field *p;
|
|
|
|
while (argc--) {
|
1997-10-11 17:40:26 +04:00
|
|
|
p = findfield(*argv);
|
|
|
|
if (p == 0) {
|
|
|
|
if (strchr(*argv, '='))
|
|
|
|
warnx("field %s does not exist (use -w to set a variable)", *argv);
|
|
|
|
else
|
|
|
|
warnx("field %s does not exist", *argv);
|
|
|
|
} else {
|
|
|
|
prfield(p, sep);
|
2002-01-27 21:21:52 +03:00
|
|
|
printf("\n");
|
1997-10-11 17:40:26 +04:00
|
|
|
}
|
|
|
|
argv++;
|
|
|
|
}
|
1997-05-13 21:35:50 +04:00
|
|
|
}
|
1997-10-11 17:40:26 +04:00
|
|
|
} else
|
|
|
|
usage();
|
|
|
|
exit(0);
|
1997-05-13 21:35:50 +04:00
|
|
|
}
|
1999-03-26 17:02:39 +03:00
|
|
|
|
|
|
|
void
|
|
|
|
audioctl_write(fd, argc, argv)
|
|
|
|
int fd;
|
|
|
|
int argc;
|
|
|
|
char *argv[];
|
|
|
|
{
|
|
|
|
struct field *p;
|
|
|
|
|
|
|
|
AUDIO_INITINFO(&info);
|
|
|
|
while (argc--) {
|
|
|
|
char *q;
|
|
|
|
|
|
|
|
q = strchr(*argv, '=');
|
|
|
|
if (q) {
|
|
|
|
*q++ = 0;
|
|
|
|
p = findfield(*argv);
|
|
|
|
if (p == 0)
|
|
|
|
warnx("field `%s' does not exist", *argv);
|
|
|
|
else {
|
|
|
|
if (p->flags & READONLY)
|
|
|
|
warnx("`%s' is read only", *argv);
|
|
|
|
else {
|
|
|
|
rdfield(p, q);
|
|
|
|
if (p->valp == &fullduplex)
|
|
|
|
if (ioctl(fd, AUDIO_SETFD, &fullduplex) < 0)
|
|
|
|
err(1, "set failed");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else
|
|
|
|
warnx("No `=' in %s", *argv);
|
|
|
|
argv++;
|
|
|
|
}
|
|
|
|
if (ioctl(fd, AUDIO_SETINFO, &info) < 0)
|
|
|
|
err(1, "set failed");
|
|
|
|
}
|