2001-04-26 16:45:43 +00:00
|
|
|
/*
|
|
|
|
SDL - Simple DirectMedia Layer
|
2011-02-11 22:37:15 -08:00
|
|
|
Copyright (C) 1997-2011 Sam Lantinga
|
2001-04-26 16:45:43 +00:00
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or
|
2006-02-01 06:32:25 +00:00
|
|
|
modify it under the terms of the GNU Lesser General Public
|
2001-04-26 16:45:43 +00:00
|
|
|
License as published by the Free Software Foundation; either
|
2006-02-01 06:32:25 +00:00
|
|
|
version 2.1 of the License, or (at your option) any later version.
|
2001-04-26 16:45:43 +00:00
|
|
|
|
|
|
|
This library is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
2006-02-01 06:32:25 +00:00
|
|
|
Lesser General Public License for more details.
|
2001-04-26 16:45:43 +00:00
|
|
|
|
2006-02-01 06:32:25 +00:00
|
|
|
You should have received a copy of the GNU Lesser General Public
|
|
|
|
License along with this library; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
2001-04-26 16:45:43 +00:00
|
|
|
|
|
|
|
Sam Lantinga
|
2001-12-14 12:38:15 +00:00
|
|
|
slouken@libsdl.org
|
2001-04-26 16:45:43 +00:00
|
|
|
*/
|
2006-02-21 08:46:50 +00:00
|
|
|
#include "SDL_config.h"
|
2001-04-26 16:45:43 +00:00
|
|
|
|
|
|
|
/* Get the name of the audio device we use for output */
|
|
|
|
|
2006-03-21 09:33:54 +00:00
|
|
|
#if SDL_AUDIO_DRIVER_BSD || SDL_AUDIO_DRIVER_OSS || SDL_AUDIO_DRIVER_SUNAUDIO
|
2001-04-26 16:45:43 +00:00
|
|
|
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/stat.h>
|
2010-07-13 22:22:43 -07:00
|
|
|
#include <unistd.h> /* For close() */
|
2001-04-26 16:45:43 +00:00
|
|
|
|
2006-02-10 06:48:43 +00:00
|
|
|
#include "SDL_stdinc.h"
|
2001-04-26 16:45:43 +00:00
|
|
|
#include "SDL_audiodev_c.h"
|
|
|
|
|
|
|
|
#ifndef _PATH_DEV_DSP
|
2006-02-21 08:46:50 +00:00
|
|
|
#if defined(__NETBSD__) || defined(__OPENBSD__)
|
2001-07-08 09:00:06 +00:00
|
|
|
#define _PATH_DEV_DSP "/dev/audio"
|
|
|
|
#else
|
|
|
|
#define _PATH_DEV_DSP "/dev/dsp"
|
|
|
|
#endif
|
2001-04-26 16:45:43 +00:00
|
|
|
#endif
|
|
|
|
#ifndef _PATH_DEV_DSP24
|
|
|
|
#define _PATH_DEV_DSP24 "/dev/sound/dsp"
|
|
|
|
#endif
|
|
|
|
#ifndef _PATH_DEV_AUDIO
|
|
|
|
#define _PATH_DEV_AUDIO "/dev/audio"
|
|
|
|
#endif
|
|
|
|
|
2006-10-17 09:15:21 +00:00
|
|
|
static inline void
|
2006-10-28 16:48:03 +00:00
|
|
|
test_device(const char *fname, int flags, int (*test) (int fd),
|
2006-10-17 09:15:21 +00:00
|
|
|
char ***devices, int *devCount)
|
|
|
|
{
|
|
|
|
struct stat sb;
|
2006-10-28 16:48:03 +00:00
|
|
|
if ((stat(fname, &sb) == 0) && (S_ISCHR(sb.st_mode))) {
|
2006-10-17 09:15:21 +00:00
|
|
|
int audio_fd = open(fname, flags, 0);
|
2006-10-28 16:48:03 +00:00
|
|
|
if ((audio_fd >= 0) && (test(audio_fd))) {
|
|
|
|
void *p =
|
|
|
|
SDL_realloc(*devices, ((*devCount) + 1) * sizeof(char *));
|
2006-10-17 09:15:21 +00:00
|
|
|
if (p != NULL) {
|
|
|
|
size_t len = strlen(fname) + 1;
|
|
|
|
char *str = (char *) SDL_malloc(len);
|
|
|
|
*devices = (char **) p;
|
|
|
|
if (str != NULL) {
|
|
|
|
SDL_strlcpy(str, fname, len);
|
|
|
|
(*devices)[(*devCount)++] = str;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
close(audio_fd);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2001-04-26 16:45:43 +00:00
|
|
|
|
2006-10-17 09:15:21 +00:00
|
|
|
void
|
|
|
|
SDL_FreeUnixAudioDevices(char ***devices, int *devCount)
|
|
|
|
{
|
|
|
|
int i = *devCount;
|
|
|
|
if ((i > 0) && (*devices != NULL)) {
|
|
|
|
while (i--) {
|
2007-08-17 02:54:12 +00:00
|
|
|
SDL_free((*devices)[i]);
|
2006-10-17 09:15:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (*devices != NULL) {
|
|
|
|
SDL_free(*devices);
|
|
|
|
}
|
|
|
|
|
|
|
|
*devices = NULL;
|
|
|
|
*devCount = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
test_stub(int fd)
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2006-10-28 16:48:03 +00:00
|
|
|
SDL_EnumUnixAudioDevices(int flags, int classic, int (*test) (int fd),
|
2006-10-17 09:15:21 +00:00
|
|
|
char ***devices, int *devCount)
|
2001-04-26 16:45:43 +00:00
|
|
|
{
|
2006-07-10 21:04:37 +00:00
|
|
|
const char *audiodev;
|
|
|
|
char audiopath[1024];
|
|
|
|
|
2006-10-17 09:15:21 +00:00
|
|
|
if (test == NULL)
|
|
|
|
test = test_stub;
|
|
|
|
|
2006-07-10 21:04:37 +00:00
|
|
|
/* Figure out what our audio device is */
|
|
|
|
if (((audiodev = SDL_getenv("SDL_PATH_DSP")) == NULL) &&
|
|
|
|
((audiodev = SDL_getenv("AUDIODEV")) == NULL)) {
|
|
|
|
if (classic) {
|
|
|
|
audiodev = _PATH_DEV_AUDIO;
|
|
|
|
} else {
|
|
|
|
struct stat sb;
|
|
|
|
|
|
|
|
/* Added support for /dev/sound/\* in Linux 2.4 */
|
|
|
|
if (((stat("/dev/sound", &sb) == 0) && S_ISDIR(sb.st_mode))
|
|
|
|
&& ((stat(_PATH_DEV_DSP24, &sb) == 0)
|
|
|
|
&& S_ISCHR(sb.st_mode))) {
|
|
|
|
audiodev = _PATH_DEV_DSP24;
|
|
|
|
} else {
|
|
|
|
audiodev = _PATH_DEV_DSP;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2006-10-17 09:15:21 +00:00
|
|
|
test_device(audiodev, flags, test, devices, devCount);
|
2006-07-10 21:04:37 +00:00
|
|
|
|
2006-10-17 09:15:21 +00:00
|
|
|
if (SDL_strlen(audiodev) < (sizeof(audiopath) - 3)) {
|
|
|
|
int instance = 0;
|
|
|
|
while (instance++ <= 64) {
|
2006-07-10 21:04:37 +00:00
|
|
|
SDL_snprintf(audiopath, SDL_arraysize(audiopath),
|
2006-10-17 09:15:21 +00:00
|
|
|
"%s%d", audiodev, instance);
|
|
|
|
test_device(audiopath, flags, test, devices, devCount);
|
2006-07-10 21:04:37 +00:00
|
|
|
}
|
2001-04-26 16:45:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-02-21 08:46:50 +00:00
|
|
|
#endif /* Audio driver selection */
|
2006-07-10 21:04:37 +00:00
|
|
|
/* vi: set ts=4 sw=4 expandtab: */
|