mixerctl.c revision 7c478bd95313f5f23a4c958a745db2134aa03244
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright (c) 1991-2001 by Sun Microsystems, Inc.
* All rights reserved.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
/*
* mixerctl command:
* mixerctl [-a|-d dev] [-iv] [-e|-o]
*
* NOTE: Option D is not documented, it is for debugging.
*/
#include <stdio.h>
#include <stdlib.h> /* getopt() */
#include <errno.h> /* errno */
#include <strings.h> /* strrchr(), strcpy(), strcat(), strerror() */
#include <locale.h> /* setlocale() */
#include <libintl.h> /* textdomain(), gettext() */
#include <fcntl.h> /* open() */
#include <unistd.h> /* close(), ioctl() */
#include <stropts.h> /* ioctl() */
#include <ctype.h> /* isdigit() */
#include <dirent.h> /* opendir(), readdir(), closedir() */
#define GETOPT "ad:iveoD"
#define DEFAULT_DEVICE "/dev/audioctl"
#define CONTROL "ctl"
#define DOT "."
#define DOTDOT ".."
#define SLASH "/"
#define ENV "AUDIODEV"
#define AUX1 "AUX1"
#define AUX2 "AUX2"
#define CD "CD"
#define HDPHONE "HDPHONE"
#define LINE "LINE"
#define LOOPBACK "CODEC LOOPBACK"
#define MIC "MIC"
#define NONE "NONE"
#define SPDIF "SPDIF"
#define SPEAKER "SPKR"
#define SUNVTSLB "SunVTS LOOPBACK"
#define UNKNOWN "UNKNOWN"
#define SEPARATOR "|"
#define BUF_SIZE 128
#define PPORT_STR_SIZE 30
#define NOT_SUPPORTED (-1)
typedef struct info {
char *pgm;
char *opt;
char *device;
int all;
int debug;
int disable;
int enable;
int info;
int verbose;
} info_t;
/* local functions */
int
{
char dev_buffer[BUF_SIZE];
int c;
int errflag = 0;
#if !defined(TEXT_DOMAIN) /* Should be defined by cc -D */
#endif
(void) textdomain(TEXT_DOMAIN);
/* make sure info structure is zeroed out */
} else {
}
/* check for options, they're listed at the top */
switch (c) {
break;
default: errflag++; break;
}
}
/* now we do some checks to make sure we haven't done anything bad */
gettext("usage: %s [-a|-d dev] [-iv] [-e|-o]\n"),
return (1);
}
/* make sure we have something to do */
}
/* if "all" then we loop, otherwise we just take care of business */
/*
* dev_number{function}
*
*/
"Couldn't open directory %s: %s\n"), SOUND_DIR,
return (1);
}
/* skip . and .. */
cp);
}
continue;
}
/* go past the device number */
cp++;
}
/* if next char is NULL then not an audio ctl device */
if (*cp == '\0') {
}
continue;
}
/* we've got a control device, so call it */
"Found device: %s\n"), dev_buffer);
}
/* we don't bother with the return code */
}
}
} else {
/* make sure we've got a good device */
"using default device: %s\n"),
}
} else {
/* using ENV value, so get it */
"using ENV device: %s\n"),
}
}
}
/* we have a device, make sure it is a control device */
}
(void) printf(
}
}
return (0);
} /* main() */
/*
* doit()
*
* Description:
* This routine does all the real work
*
* Arguments:
* info_t *info Program info
* char *dev Device
*
* Returns:
* 1 Error
* 0 Okay
*/
static int
{
char *pencoding;
char *rencoding;
int fd;
int mode;
int new_mode;
int rc = 0;
/* first, make sure the device is there */
/* return a meaningful error message if possible */
switch (errno) {
case EPERM :
case EACCES :
gettext("%s: device %s permission denied\n"),
break;
case ENOENT :
case ENXIO :
case ENODEV :
gettext("%s: device %s does not exist\n"),
break;
default:
gettext("%s: device %s not available\n"),
break;
}
return (1);
}
/* make sure it is a special device */
return (1);
}
gettext("%s: %s is not a character special device\n"),
return (1);
}
/* if verbose or info wanted, we get the device info */
"%s: AUDIO_GETDEV ioctl() for device %s failed\n"),
return (1);
}
}
/* get the mixer mode, if there is a mixer */
(void) printf(
gettext("\n%s doesn't support the audio mixer function\n"),
dev);
if (mode != AM_MIXER_MODE) {
"%s: couldn't enable audio mixer for %s\n"),
rc = 1;
}
}
if (!rc) {
"Audio mixer for %s is enabled\n"), dev);
}
} else {
/* sanity check */
rc = 1;
} else if (mode != AM_COMPAT_MODE) {
"couldn't disable audio mixer for %s\n"),
rc = 1;
}
}
if (!rc) {
"Audio mixer for %s is disabled\n"), dev);
}
}
/* only for verbose do we get the device's info_t structure */
"%s: AUDIO_GETINFO ioctl() for device %s failed\n"),
return (1);
}
case AUDIO_ENCODING_ULAW:
break;
case AUDIO_ENCODING_ALAW:
break;
case AUDIO_ENCODING_LINEAR:
break;
default:
break;
}
case AUDIO_ENCODING_ULAW:
break;
case AUDIO_ENCODING_ALAW:
break;
case AUDIO_ENCODING_LINEAR:
break;
default:
break;
}
(void) printf(
gettext("Sample Rate\n Play\t\t%u\n Record\t%u\n"),
(void) printf(
gettext("Precision\n Play\t\t%u\n Record\t%u\n"),
(void) printf(
gettext("Port\n Play\t\t0x%08x %s\n Record\t0x%08x %s\n"),
(void) printf(
gettext("Avail Ports\n Play\t\t0x%08x %s\n"
" Record\t0x%08x %s\n"),
(void) printf(
gettext("Mod Ports\n Play\t\t0x%08x %s\n"
" Record\t0x%08x %s\n"),
}
}
}
}
}
}
}
}
(void) printf("\n");
return (rc);
} /* doit() */
/*
* pport2str()
*
* Description:
* Convert the play port bit map into strings. This makes the port number
* a bit more readable. The returned string is in parenthesis and always
* has 30 valid characters for spacing.
*
* Arguments:
* uint port The port to convert
* char *buf The storage to put the string into
*
* Returns:
* void
*/
static void
{
int sep = 0;
if (port & AUDIO_SPEAKER) {
sep++;
}
if (port & AUDIO_HEADPHONE) {
if (sep) {
} else {
sep++;
}
}
if (port & AUDIO_LINE_OUT) {
if (sep) {
} else {
sep++;
}
}
if (port & AUDIO_SPDIF_OUT) {
if (sep) {
} else {
sep++;
}
}
if (port & AUDIO_AUX1_OUT) {
if (sep) {
} else {
sep++;
}
}
if (port & AUDIO_AUX2_OUT) {
if (sep) {
} else {
sep++;
}
}
if (port & ~ALL_PLAY_PORTS) {
if (sep) {
} else {
sep++;
}
}
if (sep == 0) {
}
} /* pport2str() */
/*
* rport2str()
*
* Description:
* Convert the record port bit map into strings. This makes the port
* number a bit more readable. The returned string in parenthesis.
*
* Arguments:
* uint port The port to convert
* char *buf The storage to put the string into
*
* Returns:
* void
*/
static void
{
int sep = 0;
if (port & AUDIO_MICROPHONE) {
sep++;
}
if (port & AUDIO_LINE_IN) {
if (sep) {
} else {
sep++;
}
}
if (sep) {
} else {
sep++;
}
}
if (port & AUDIO_SPDIF_IN) {
if (sep) {
} else {
sep++;
}
}
if (port & AUDIO_AUX1_IN) {
if (sep) {
} else {
sep++;
}
}
if (port & AUDIO_AUX2_IN) {
if (sep) {
} else {
sep++;
}
}
if (port & AUDIO_CODEC_LOOPB_IN) {
if (sep) {
} else {
sep++;
}
}
if (port & AUDIO_SUNVTS) {
if (sep) {
} else {
sep++;
}
}
if (port & ~ALL_REC_PORTS) {
if (sep) {
} else {
sep++;
}
}
if (sep == 0) {
}
} /* rport2str() */