(OSS) Get rid of static globals
This commit is contained in:
parent
11b4043ef6
commit
e50d5af2db
|
@ -42,23 +42,27 @@
|
||||||
#define DEFAULT_OSS_DEV "/dev/dsp"
|
#define DEFAULT_OSS_DEV "/dev/dsp"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* TODO/FIXME - static global variable */
|
typedef struct oss_audio
|
||||||
static bool oss_is_paused = false;
|
{
|
||||||
|
int fd;
|
||||||
|
bool is_paused;
|
||||||
|
} oss_audio_t;
|
||||||
|
|
||||||
static void *oss_init(const char *device, unsigned rate, unsigned latency,
|
static void *oss_init(const char *device,
|
||||||
|
unsigned rate, unsigned latency,
|
||||||
unsigned block_frames,
|
unsigned block_frames,
|
||||||
unsigned *new_out_rate)
|
unsigned *new_out_rate)
|
||||||
{
|
{
|
||||||
int frags, frag, channels, format, new_rate;
|
int frags, frag, channels, format, new_rate;
|
||||||
int *fd = (int*)calloc(1, sizeof(int));
|
oss_audio_t *ossaudio = (oss_audio_t*)calloc(1, sizeof(oss_audio_t));
|
||||||
const char *oss_device = device ? device : DEFAULT_OSS_DEV;
|
const char *oss_device = device ? device : DEFAULT_OSS_DEV;
|
||||||
|
|
||||||
if (!fd)
|
if (!ossaudio)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
if ((*fd = open(oss_device, O_WRONLY)) < 0)
|
if ((ossaudio->fd = open(oss_device, O_WRONLY)) < 0)
|
||||||
{
|
{
|
||||||
free(fd);
|
free(ossaudio);
|
||||||
perror("open");
|
perror("open");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
@ -66,21 +70,21 @@ static void *oss_init(const char *device, unsigned rate, unsigned latency,
|
||||||
frags = (latency * rate * 4) / (1000 * (1 << 10));
|
frags = (latency * rate * 4) / (1000 * (1 << 10));
|
||||||
frag = (frags << 16) | 10;
|
frag = (frags << 16) | 10;
|
||||||
|
|
||||||
if (ioctl(*fd, SNDCTL_DSP_SETFRAGMENT, &frag) < 0)
|
if (ioctl(ossaudio->fd, SNDCTL_DSP_SETFRAGMENT, &frag) < 0)
|
||||||
RARCH_WARN("Cannot set fragment sizes. Latency might not be as expected ...\n");
|
RARCH_WARN("Cannot set fragment sizes. Latency might not be as expected ...\n");
|
||||||
|
|
||||||
channels = 2;
|
channels = 2;
|
||||||
format = is_little_endian() ? AFMT_S16_LE : AFMT_S16_BE;
|
format = is_little_endian() ? AFMT_S16_LE : AFMT_S16_BE;
|
||||||
|
|
||||||
if (ioctl(*fd, SNDCTL_DSP_CHANNELS, &channels) < 0)
|
if (ioctl(ossaudio->fd, SNDCTL_DSP_CHANNELS, &channels) < 0)
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
if (ioctl(*fd, SNDCTL_DSP_SETFMT, &format) < 0)
|
if (ioctl(ossaudio->fd, SNDCTL_DSP_SETFMT, &format) < 0)
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
new_rate = rate;
|
new_rate = rate;
|
||||||
|
|
||||||
if (ioctl(*fd, SNDCTL_DSP_SPEED, &new_rate) < 0)
|
if (ioctl(ossaudio->fd, SNDCTL_DSP_SPEED, &new_rate) < 0)
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
if (new_rate != (int)rate)
|
if (new_rate != (int)rate)
|
||||||
|
@ -89,11 +93,12 @@ static void *oss_init(const char *device, unsigned rate, unsigned latency,
|
||||||
*new_out_rate = new_rate;
|
*new_out_rate = new_rate;
|
||||||
}
|
}
|
||||||
|
|
||||||
return fd;
|
return ossaudio;
|
||||||
|
|
||||||
error:
|
error:
|
||||||
close(*fd);
|
close(ossaudio->fd);
|
||||||
free(fd);
|
if (ossaudio)
|
||||||
|
free(ossaudio);
|
||||||
perror("ioctl");
|
perror("ioctl");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
@ -101,14 +106,14 @@ error:
|
||||||
static ssize_t oss_write(void *data, const void *buf, size_t size)
|
static ssize_t oss_write(void *data, const void *buf, size_t size)
|
||||||
{
|
{
|
||||||
ssize_t ret;
|
ssize_t ret;
|
||||||
int *fd = (int*)data;
|
oss_audio_t *ossaudio = (oss_audio_t*)data;
|
||||||
|
|
||||||
if (size == 0)
|
if (size == 0)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
if ((ret = write(*fd, buf, size)) < 0)
|
if ((ret = write(ossaudio->fd, buf, size)) < 0)
|
||||||
{
|
{
|
||||||
if (errno == EAGAIN && (fcntl(*fd, F_GETFL) & O_NONBLOCK))
|
if (errno == EAGAIN && (fcntl(ossaudio->fd, F_GETFL) & O_NONBLOCK))
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -119,9 +124,9 @@ static ssize_t oss_write(void *data, const void *buf, size_t size)
|
||||||
|
|
||||||
static bool oss_stop(void *data)
|
static bool oss_stop(void *data)
|
||||||
{
|
{
|
||||||
int *fd = (int*)data;
|
oss_audio_t *ossaudio = (oss_audio_t*)data;
|
||||||
|
|
||||||
if (ioctl(*fd, SNDCTL_DSP_RESET, 0) < 0)
|
if (ioctl(ossaudio->fd, SNDCTL_DSP_RESET, 0) < 0)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
oss_is_paused = true;
|
oss_is_paused = true;
|
||||||
|
@ -144,33 +149,35 @@ static bool oss_alive(void *data)
|
||||||
static void oss_set_nonblock_state(void *data, bool state)
|
static void oss_set_nonblock_state(void *data, bool state)
|
||||||
{
|
{
|
||||||
int rc;
|
int rc;
|
||||||
int *fd = (int*)data;
|
oss_audio_t *ossaudio = (oss_audio_t*)data;
|
||||||
|
|
||||||
if (state)
|
if (state)
|
||||||
rc = fcntl(*fd, F_SETFL, fcntl(*fd, F_GETFL) | O_NONBLOCK);
|
rc = fcntl(ossaudio->fd, F_SETFL,
|
||||||
|
fcntl(ossaudio->fd, F_GETFL) | O_NONBLOCK);
|
||||||
else
|
else
|
||||||
rc = fcntl(*fd, F_SETFL, fcntl(*fd, F_GETFL) & (~O_NONBLOCK));
|
rc = fcntl(ossaudio->fd, F_SETFL,
|
||||||
|
fcntl(ossaudio->fd, F_GETFL) & (~O_NONBLOCK));
|
||||||
if (rc != 0)
|
if (rc != 0)
|
||||||
RARCH_WARN("Could not set nonblocking on OSS file descriptor. Will not be able to fast-forward.\n");
|
RARCH_WARN("Could not set nonblocking on OSS file descriptor. Will not be able to fast-forward.\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
static void oss_free(void *data)
|
static void oss_free(void *data)
|
||||||
{
|
{
|
||||||
int *fd = (int*)data;
|
oss_audio_t *ossaudio = (oss_audio_t*)data;
|
||||||
|
|
||||||
if (ioctl(*fd, SNDCTL_DSP_RESET, 0) < 0)
|
if (ioctl(ossaudio->fd, SNDCTL_DSP_RESET, 0) < 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
close(*fd);
|
close(ossaudio->fd);
|
||||||
free(fd);
|
free(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
static size_t oss_write_avail(void *data)
|
static size_t oss_write_avail(void *data)
|
||||||
{
|
{
|
||||||
audio_buf_info info;
|
audio_buf_info info;
|
||||||
int *fd = (int*)data;
|
oss_audio_t *ossaudio = (oss_audio_t*)data;
|
||||||
|
|
||||||
if (ioctl(*fd, SNDCTL_DSP_GETOSPACE, &info) < 0)
|
if (ioctl(ossaudio->fd, SNDCTL_DSP_GETOSPACE, &info) < 0)
|
||||||
{
|
{
|
||||||
RARCH_ERR("[OSS]: SNDCTL_DSP_GETOSPACE failed ...\n");
|
RARCH_ERR("[OSS]: SNDCTL_DSP_GETOSPACE failed ...\n");
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -182,9 +189,9 @@ static size_t oss_write_avail(void *data)
|
||||||
static size_t oss_buffer_size(void *data)
|
static size_t oss_buffer_size(void *data)
|
||||||
{
|
{
|
||||||
audio_buf_info info;
|
audio_buf_info info;
|
||||||
int *fd = (int*)data;
|
oss_audio_t *ossaudio = (oss_audio_t*)data;
|
||||||
|
|
||||||
if (ioctl(*fd, SNDCTL_DSP_GETOSPACE, &info) < 0)
|
if (ioctl(ossaudio->fd, SNDCTL_DSP_GETOSPACE, &info) < 0)
|
||||||
{
|
{
|
||||||
RARCH_ERR("[OSS]: SNDCTL_DSP_GETOSPACE failed ...\n");
|
RARCH_ERR("[OSS]: SNDCTL_DSP_GETOSPACE failed ...\n");
|
||||||
return 1; /* Return something non-zero to avoid SIGFPE. */
|
return 1; /* Return something non-zero to avoid SIGFPE. */
|
||||||
|
|
Loading…
Reference in New Issue