From 27940dce2b17bc1c2a77625662f3e16e75685813 Mon Sep 17 00:00:00 2001 From: Jaroslav Kysela Date: Mon, 9 Feb 2004 12:36:39 +0000 Subject: [PATCH] - moved aoss code to alsa directory - created oss-redir directory with OSS redirection library (not finished yet) --- Makefile.am | 16 ++-- alsa/Makefile.am | 10 +++ alsa-oss.c => alsa/alsa-oss.c | 0 aoss.1 => alsa/aoss.1 | 0 aoss.in => alsa/aoss.in | 0 configure.in | 21 ++++- oss-redir/Makefile.am | 9 +++ oss-redir/oss-redir.c | 144 ++++++++++++++++++++++++++++++++++ oss-redir/oss-redir.h | 49 ++++++++++++ 9 files changed, 236 insertions(+), 13 deletions(-) create mode 100644 alsa/Makefile.am rename alsa-oss.c => alsa/alsa-oss.c (100%) rename aoss.1 => alsa/aoss.1 (100%) rename aoss.in => alsa/aoss.in (100%) create mode 100644 oss-redir/Makefile.am create mode 100644 oss-redir/oss-redir.c create mode 100644 oss-redir/oss-redir.h diff --git a/Makefile.am b/Makefile.am index 667430e..15f8ded 100644 --- a/Makefile.am +++ b/Makefile.am @@ -1,14 +1,10 @@ -lib_LTLIBRARIES = libaoss.la -bin_SCRIPTS = aoss -man_MANS = aoss.1 -EXTRA_DIST = aoss.1 +if WITH_AOSS +ALSA_DIR = alsa +else +ALSA_DIR = +endif -libaoss_la_SOURCES = alsa-oss.c -libaoss_la_LIBADD = -ldl -lasound - - -clean: - rm -f aoss +SUBDIRS = $(ALSA_DIR) oss-redir dist-hook: echo $(VERSION) >> version diff --git a/alsa/Makefile.am b/alsa/Makefile.am new file mode 100644 index 0000000..1c8c06f --- /dev/null +++ b/alsa/Makefile.am @@ -0,0 +1,10 @@ +lib_LTLIBRARIES = libaoss.la +bin_SCRIPTS = aoss +man_MANS = aoss.1 +EXTRA_DIST = aoss.1 + +libaoss_la_SOURCES = alsa-oss.c +libaoss_la_LIBADD = -ldl -lasound + +clean: + rm -f aoss diff --git a/alsa-oss.c b/alsa/alsa-oss.c similarity index 100% rename from alsa-oss.c rename to alsa/alsa-oss.c diff --git a/aoss.1 b/alsa/aoss.1 similarity index 100% rename from aoss.1 rename to alsa/aoss.1 diff --git a/aoss.in b/alsa/aoss.in similarity index 100% rename from aoss.in rename to alsa/aoss.in diff --git a/configure.in b/configure.in index 3b900f0..e7e9054 100644 --- a/configure.in +++ b/configure.in @@ -1,4 +1,4 @@ -AC_INIT(alsa-oss.c) +AC_INIT(alsa/alsa-oss.c) AM_INIT_AUTOMAKE(alsa-oss, 1.0.2) AC_PREFIX_DEFAULT(/usr) @@ -7,6 +7,21 @@ AC_PROG_CC AC_PROG_INSTALL AC_PROG_LN_S AM_PROG_LIBTOOL -AM_PATH_ALSA(0.9.0) -AC_OUTPUT(Makefile aoss) +dnl Check for aoss... +AC_MSG_CHECKING(for aoss) +AC_ARG_WITH(aoss, + [ --with-aoss=yes,no OSS -> ALSA emulation library build], + with_aoss="$withval", with_aoss="yes") +if test "$with_aoss" = "yes"; then + AC_MSG_RESULT(yes) +else + AC_MSG_RESULT(no) +fi +AM_CONDITIONAL(WITH_AOSS, test x$with_aoss = xyes) + +if test "$with_aoss" = "yes"; then + AM_PATH_ALSA(0.9.0) +fi + +AC_OUTPUT(Makefile alsa/Makefile alsa/aoss oss-redir/Makefile) diff --git a/oss-redir/Makefile.am b/oss-redir/Makefile.am new file mode 100644 index 0000000..d97e4de --- /dev/null +++ b/oss-redir/Makefile.am @@ -0,0 +1,9 @@ +ossredirincludedir = ${includedir} + +ossredirinclude_HEADERS = oss-redir.h + +lib_LTLIBRARIES = libossredir.la + +libossredir_la_SOURCES = oss-redir.c +libossredir_la_LIBADD = -ldl +libossredir_la_LDFLAGS = -static diff --git a/oss-redir/oss-redir.c b/oss-redir/oss-redir.c new file mode 100644 index 0000000..4e26acd --- /dev/null +++ b/oss-redir/oss-redir.c @@ -0,0 +1,144 @@ +/* + * OSS Redirector + * Copyright (c) by Jaroslav Kysela + * + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ + +#define _GNU_SOURCE + +#include "oss-redir.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +static int initialized = 0; +static int native_oss = 1; +static char hal[64]; + +int (*oss_pcm_open)(const char *pathname, int flags, ...); +int (*oss_pcm_close)(int fd); +ssize_t (*oss_pcm_read)(int fd, void *buf, size_t count); +ssize_t (*oss_pcm_write)(int fd, const void *buf, size_t count); +void * (*oss_pcm_mmap)(void *start, size_t length, int prot, int flags, int fd, off_t offset); +int (*oss_pcm_munmap)(void *start, size_t length); +int (*oss_pcm_ioctl)(int fd, unsigned long int request, ...); +int (*oss_pcm_select_prepare)(int fd, fd_set *readfds, fd_set *writefds); +int (*oss_pcm_select_result)(int fd, fd_set *readfds, fd_set *writefds); +int (*oss_pcm_poll_fds)(int fd); +int (*oss_pcm_poll_prepare)(int fd, struct pollfd *ufds); +int (*oss_pcm_poll_result)(int fd, struct pollfd *ufds); + +int (*oss_mixer_open)(const char *pathname, int flags, ...); +int (*oss_mixer_close)(int fd); +int (*oss_mixer_ioctl)(int fd, unsigned long int request, ...); + +int native_pcm_select_prepare(int fd, fd_set *readfds, fd_set *writefds) +{ + if (fd < 0) + return -EINVAL; + if (readfds) + FD_SET(fd, readfds); + if (writefds) + FD_SET(fd, writefds); + return 0; +} + +int native_pcm_select_result(int fd, fd_set *readfds, fd_set *writefds) +{ + int result = 0; + + if (fd < 0) + return -EINVAL; + if (readfds && FD_ISSET(fd, readfds)) + result |= OSS_WAIT_EVENT_READ; + if (writefds && FD_ISSET(fd, writefds)) + result |= OSS_WAIT_EVENT_WRITE; + return result; +} + +int native_pcm_poll_fds(int fd) +{ + if (fd < 0) + return -EINVAL; + return 1; +} + +int native_pcm_poll_prepare(int fd, struct pollfd *ufds) +{ + if (fd < 0) + return -EINVAL; + ufds->fd = fd; + ufds->events = POLLIN | POLLOUT | POLLERR; + return 0; +} + +int native_pcm_poll_result(int fd, struct pollfd *ufds) +{ + int result = 0; + + if (fd < 0) + return -EINVAL; + if (ufds->events & POLLIN) + result |= OSS_WAIT_EVENT_READ; + if (ufds->events & POLLOUT) + result |= OSS_WAIT_EVENT_WRITE; + return result; +} + +static void initialize() +{ + char *s = getenv("OSS_REDIRECTOR"); + if (s) { + strncpy(hal, s, sizeof(hal)); + hal[sizeof(hal)-1] = '\0'; + if (!strcmp(hal, "oss")) + native_oss = 1; + } else { + native_oss = 1; + } + if (native_oss) { + oss_pcm_open = open; + oss_pcm_close = close; + oss_pcm_read = read; + oss_pcm_write = write; + oss_pcm_mmap = mmap; + oss_pcm_munmap = munmap; + oss_pcm_ioctl = ioctl; + oss_pcm_select_prepare = native_pcm_select_prepare; + oss_pcm_select_result = native_pcm_select_result; + oss_pcm_poll_fds = native_pcm_poll_fds; + oss_pcm_poll_prepare = native_pcm_poll_prepare; + oss_pcm_poll_result = native_pcm_poll_result; + oss_mixer_open = open; + oss_mixer_close = close; + oss_mixer_ioctl = ioctl; + } +} + +static inline void check_initialized(void) +{ + if (!initialized) + initialize(); +} diff --git a/oss-redir/oss-redir.h b/oss-redir/oss-redir.h new file mode 100644 index 0000000..1035338 --- /dev/null +++ b/oss-redir/oss-redir.h @@ -0,0 +1,49 @@ +#ifndef __OSS_REDIR_H +/* + * OSS Redirector + * Copyright (c) by Jaroslav Kysela + * + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ + +#include +#include + +struct pollfd; + +#define OSS_WAIT_EVENT_READ (1<<0) +#define OSS_WAIT_EVENT_WRITE (1<<1) + +extern int (*oss_pcm_open)(const char *pathname, int flags, ...); +extern int (*oss_pcm_close)(int fd); +extern ssize_t (*oss_pcm_read)(int fd, void *buf, size_t count); +extern ssize_t (*oss_pcm_write)(int fd, const void *buf, size_t count); +extern void * (*oss_pcm_mmap)(void *start, size_t length, int prot, int flags, int fd, off_t offset); +extern int (*oss_pcm_munmap)(void *start, size_t length); +extern int (*oss_pcm_ioctl)(int fd, unsigned long int request, ...); +extern int (*oss_pcm_select_prepare)(int fd, fd_set *readfds, fd_set *writefds); +extern int (*oss_pcm_select_result)(int fd, fd_set *readfds, fd_set *writefds); +extern int (*oss_pcm_poll_fds)(int fd); +extern int (*oss_pcm_poll_prepare)(int fd, struct pollfd *ufds); +extern int (*oss_pcm_poll_result)(int fd, struct pollfd *ufds); + +extern int (*oss_mixer_open)(const char *pathname, int flags, ...); +extern int (*oss_mixer_close)(int fd); +extern int (*oss_mixer_ioctl)(int fd, unsigned long int request, ...); + + +#endif /* __OSS_REDIR_H */ -- 2.47.1