summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2008-05-27 00:30:25 +0000
committerLennart Poettering <lennart@poettering.net>2008-05-27 00:30:25 +0000
commit6a75b780762a8695a83e0e94e6fcbce4d2f73573 (patch)
treee2b41bd6dd4d9a5751c6b0e91f329530c0b5447f
parentd7fd6a45e50475cddf0b8bad8baab01b33cf3c1f (diff)
autoconfization
git-svn-id: file:///home/lennart/svn/public/libcanberra/trunk@13 01b60673-d06a-42c0-afdd-89cb8e0f78ac
-rw-r--r--Makefile7
-rw-r--r--Makefile.am28
-rwxr-xr-xbootstrap.sh67
-rw-r--r--configure.ac310
-rw-r--r--libcanberra.pc.in11
-rw-r--r--src/Makefile.am58
-rw-r--r--src/canberra.c1
-rw-r--r--src/canberra.h6
-rw-r--r--src/common.c30
-rw-r--r--src/macro.h2
-rw-r--r--src/proplist.c8
-rw-r--r--src/proplist.h4
-rw-r--r--src/pulse.c300
-rw-r--r--src/read-sound-file.c17
-rw-r--r--src/read-sound-file.h7
-rw-r--r--src/read-vorbis.c18
-rw-r--r--src/read-vorbis.h1
-rw-r--r--src/read-wav.c5
-rw-r--r--src/read-wav.h2
-rw-r--r--src/sound-theme-spec.c4
-rw-r--r--src/test-canberra.c (renamed from src/test.c)5
21 files changed, 721 insertions, 170 deletions
diff --git a/Makefile b/Makefile
deleted file mode 100644
index 01be0a4..0000000
--- a/Makefile
+++ /dev/null
@@ -1,7 +0,0 @@
-CFLAGS=-W -Wall -pipe -O0 -g -DPACKAGE=libcanberra -pthread
-
-test: proplist.o mutex-posix.o common.o
- $(CC) $(CFLAGS) -o $@ $^
-
-clean:
- rm -f *.o test
diff --git a/Makefile.am b/Makefile.am
new file mode 100644
index 0000000..2cb96a6
--- /dev/null
+++ b/Makefile.am
@@ -0,0 +1,28 @@
+# $Id$
+#
+# This file is part of libcanberra.
+#
+# Copyright 2008 Lennart Poettering
+#
+# libcanberra is free software; you can redistribute it and/or modify
+# it under the terms of the GNU Lesser General Public License as
+# published by the Free Software Foundation, either version 2.1 of the
+# License, or (at your option) any later version.
+#
+# libcanberra 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
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with libcanberra. If not, If not, see
+# <http://www.gnu.org/licenses/>.
+
+EXTRA_DIST = bootstrap.sh LGPL
+SUBDIRS = src
+
+MAINTAINERCLEANFILES =
+noinst_DATA =
+
+pkgconfigdir = $(libdir)/pkgconfig
+pkgconfig_DATA = libcanberra.pc
diff --git a/bootstrap.sh b/bootstrap.sh
new file mode 100755
index 0000000..4eb0f67
--- /dev/null
+++ b/bootstrap.sh
@@ -0,0 +1,67 @@
+#!/bin/bash
+
+# $Id$
+#
+# This file is part of libcanberra.
+#
+# Copyright 2008 Lennart Poettering
+#
+# libcanberra is free software; you can redistribute it and/or modify
+# it under the terms of the GNU Lesser General Public License as
+# published by the Free Software Foundation, either version 2.1 of the
+# License, or (at your option) any later version.
+#
+# libcanberra 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
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with libcanberra. If not, If not, see
+# <http://www.gnu.org/licenses/>.
+
+VERSION=1.9
+
+run_versioned() {
+ local P
+ local V
+
+ V=$(echo "$2" | sed -e 's,\.,,g')
+
+ if [ -e "`which $1$V 2> /dev/null`" ] ; then
+ P="$1$V"
+ else
+ if [ -e "`which $1-$2 2> /dev/null`" ] ; then
+ P="$1-$2"
+ else
+ P="$1"
+ fi
+ fi
+
+ shift 2
+ "$P" "$@"
+}
+
+set -ex
+
+if [ "x$1" = "xam" ] ; then
+ run_versioned automake "$VERSION" -a -c --foreign
+ ./config.status
+else
+ rm -rf autom4te.cache
+ rm -f config.cache
+
+ touch config.rpath
+ test "x$LIBTOOLIZE" = "x" && LIBTOOLIZE=libtoolize
+
+ "$LIBTOOLIZE" -c --force
+ run_versioned aclocal "$VERSION"
+ run_versioned autoconf 2.59 -Wall
+ run_versioned autoheader 2.59
+ run_versioned automake "$VERSION" --copy --foreign --add-missing
+
+ if test "x$NOCONFIGURE" = "x"; then
+ CFLAGS="-g -O0" ./configure --sysconfdir=/etc --localstatedir=/var "$@"
+ make clean
+ fi
+fi
diff --git a/configure.ac b/configure.ac
new file mode 100644
index 0000000..de665de
--- /dev/null
+++ b/configure.ac
@@ -0,0 +1,310 @@
+# -*- Autoconf -*-
+# Process this file with autoconf to produce a configure script.
+
+# $Id$
+#
+# This file is part of libcanberra.
+#
+# Copyright 2008 Lennart Poettering
+#
+# libcanberra is free software; you can redistribute it and/or modify
+# it under the terms of the GNU Lesser General Public License as
+# published by the Free Software Foundation, either version 2.1 of the
+# License, or (at your option) any later version.
+#
+# libcanberra 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
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with libcanberra. If not, If not, see
+# <http://www.gnu.org/licenses/>.
+
+AC_PREREQ(2.57)
+
+AC_INIT([libcanberra], 0.1, [mzyvopnaoreen (at) 0pointer (dot) de])
+AC_CONFIG_SRCDIR([src/common.c])
+AC_CONFIG_HEADERS([config.h])
+AM_INIT_AUTOMAKE([foreign -Wall])
+
+AC_SUBST(PACKAGE_URL, [https://tango.0pointer.de/mailman/listinfo/libcanberra-discuss/])
+
+AC_SUBST(LIBCANBERRA_VERSION_INFO, [0:0:0])
+
+AC_CANONICAL_HOST
+
+if type -p stow > /dev/null && test -d /usr/local/stow ; then
+ AC_MSG_NOTICE([*** Found /usr/local/stow: default install prefix set to /usr/local/stow/${PACKAGE_NAME}-${PACKAGE_VERSION} ***])
+ ac_default_prefix="/usr/local/stow/${PACKAGE_NAME}-${PACKAGE_VERSION}"
+fi
+
+#### Checks for programs. ####
+
+# CC
+
+AC_PROG_CC
+AM_PROG_CC_C_O
+AC_PROG_GCC_TRADITIONAL
+AC_GNU_SOURCE
+
+# C++
+
+AC_PROG_CXX
+
+# GCC flags
+
+test_gcc_flag() {
+ AC_LANG_CONFTEST([int main(int argc, char*argv[]) {}])
+ $CC -c conftest.c $CFLAGS -o conftest.o > /dev/null 2> /dev/null
+ ret=$?
+ rm -f conftest.o
+ return $ret
+}
+
+# If using GCC specify some additional parameters
+if test "x$GCC" = "xyes" ; then
+
+ # We use gnu99 instead of c99 because many have interpreted the standard
+ # in a way that int64_t isn't defined on non-64 bit platforms.
+ DESIRED_FLAGS="-std=gnu99 -Wall -W -Wextra -pedantic -pipe -Wformat -Wold-style-definition -Wdeclaration-after-statement -Wfloat-equal -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wredundant-decls -Wmissing-noreturn -Wshadow -Wendif-labels -Wpointer-arith -Wcast-align -Wwrite-strings -Winline -Wno-unused-parameter -ffast-math"
+
+ for flag in $DESIRED_FLAGS ; do
+ AC_MSG_CHECKING([whether $CC accepts $flag])
+ if test_gcc_flag $flag ; then
+ CFLAGS="$CFLAGS $flag"
+ CXXFLAGS="$CXXFLAGS $flag"
+ AC_MSG_RESULT([yes])
+ else
+ AC_MSG_RESULT([no])
+ fi
+ done
+fi
+
+#### libtool stuff ####
+
+AC_LIBTOOL_WIN32_DLL
+AC_PROG_LIBTOOL
+
+#### Determine build environment ####
+
+os_is_win32=0
+
+case "$host_os" in
+ mingw*)
+ AC_DEFINE([OS_IS_WIN32], 1, [Build target is Windows.])
+ os_is_win32=1
+ ;;
+ esac
+
+AM_CONDITIONAL(OS_IS_WIN32, test "x$os_is_win32" = "x1")
+
+###################################
+# Basic environment checks #
+###################################
+
+#### Checks for header files. ####
+
+# ISO
+AC_HEADER_STDC
+
+# XPG4-UNIX
+AC_CHECK_HEADERS([sys/poll.h])
+
+# Other
+AC_CHECK_HEADERS([sys/ioctl.h])
+AC_CHECK_HEADERS([byteswap.h])
+
+#### Typdefs, structures, etc. ####
+
+AC_C_CONST
+AC_C_BIGENDIAN
+AC_TYPE_PID_T
+AC_TYPE_SIZE_T
+AC_CHECK_TYPES(ssize_t, , [AC_DEFINE([ssize_t], [signed long],
+ [Define ssize_t if it is not done by the standard libs.])])
+AC_TYPE_OFF_T
+AC_TYPE_SIGNAL
+AC_TYPE_UID_T
+
+#### Check for libs ####
+
+# ISO
+AC_SEARCH_LIBS([pow], [m])
+
+# POSIX
+AC_SEARCH_LIBS([sched_setscheduler], [rt])
+
+# Non-standard
+
+#### Check for functions ####
+
+# ISO
+AC_CHECK_FUNCS([lrintf strtof])
+
+# POSIX
+AC_FUNC_SELECT_ARGTYPES
+AC_CHECK_FUNCS([gettimeofday nanosleep posix_memalign sigaction sleep sysconf pthread_yield])
+
+# SUSv3
+AC_CHECK_FUNCS([strerror_r])
+
+# BSD
+AC_CHECK_FUNCS([lstat])
+
+#### POSIX threads ####
+
+ACX_PTHREAD
+
+AC_MSG_CHECKING([for PTHREAD_PRIO_INHERIT])
+AC_LANG_CONFTEST([AC_LANG_SOURCE([[
+#include <pthread.h>
+int main() { int i = PTHREAD_PRIO_INHERIT; }]])])
+$PTHREAD_CC conftest.c $PTHREAD_CFLAGS $CFLAGS $PTHREAD_LIBS -o conftest > /dev/null 2> /dev/null
+ret=$?
+rm -f conftest.o conftest
+
+if test $ret -eq 0 ; then
+ AC_DEFINE([HAVE_PTHREAD_PRIO_INHERIT], 1, [Have PTHREAD_PRIO_INHERIT.])
+ AC_MSG_RESULT([yes])
+else
+ AC_MSG_RESULT([no])
+fi
+
+
+#### Large File-Support (LFS) ####
+
+AC_SYS_LARGEFILE
+
+# Check for open64 to know if the current system does have open64() and similar functions
+AC_CHECK_FUNCS([open64])
+
+#### [lib]iconv ####
+
+AM_ICONV
+
+###################################
+# External libraries #
+###################################
+
+#### pkg-config ####
+
+# Check for pkg-config manually first, as if its not installed the
+# PKG_PROG_PKG_CONFIG macro won't be defined.
+AC_CHECK_PROG(have_pkg_config, pkg-config, yes, no)
+
+if test x"$have_pkg_config" = "xno"; then
+ AC_MSG_ERROR(pkg-config is required to install this program)
+fi
+
+PKG_PROG_PKG_CONFIG
+
+#### ALSA support (optional) ####
+
+AC_ARG_ENABLE([alsa],
+ AC_HELP_STRING([--disable-alsa], [Disable optional ALSA support]),
+ [
+ case "${enableval}" in
+ yes) alsa=yes ;;
+ no) alsa=no ;;
+ *) AC_MSG_ERROR(bad value ${enableval} for --disable-alsa) ;;
+ esac
+ ],
+ [alsa=auto])
+
+if test "x${alsa}" != xno ; then
+ PKG_CHECK_MODULES(ASOUNDLIB, [ alsa >= 1.0.0 ],
+ [
+ HAVE_ALSA=1
+ AC_DEFINE([HAVE_ALSA], 1, [Have ALSA?])
+ ],
+ [
+ HAVE_ALSA=0
+ if test "x$alsa" = xyes ; then
+ AC_MSG_ERROR([*** ALSA support not found])
+ fi
+ ])
+else
+ HAVE_ALSA=0
+fi
+
+AC_SUBST(ASOUNDLIB_CFLAGS)
+AC_SUBST(ASOUNDLIB_LIBS)
+AC_SUBST(HAVE_ALSA)
+AM_CONDITIONAL([HAVE_ALSA], [test "x$HAVE_ALSA" = x1])
+
+### PulseAudio (optional) ####
+
+AC_ARG_ENABLE([pulse],
+ AC_HELP_STRING([--disable-pulse], [Disable optional PulseAudio support]),
+ [
+ case "${enableval}" in
+ yes) pulse=yes ;;
+ no) pulse=no ;;
+ *) AC_MSG_ERROR(bad value ${enableval} for --disable-pulse) ;;
+ esac
+ ],
+ [pulse=auto])
+
+if test "x${pulse}" != xno ; then
+
+ if test -d ../pulseaudio ; then
+ PULSE_CFLAGS='-I$(top_srcdir)/../pulseaudio/src'
+ PULSE_LIBS='-L$(top_srcdir)/../pulseaudio/src/.libs -lpulse -lpulse-mainloop-glib'
+ echo "*** Found pulseaudio in ../pulseaudio, using that version ***"
+ else
+ PKG_CHECK_MODULES(PULSE, [ libpulse >= 0.9.11 libpulse-mainloop-glib >= 0.9.11 ],
+ HAVE_PULSE=1,
+ [
+ HAVE_PULSE=0
+ if test "x$pulse" = xyes ; then
+ AC_MSG_ERROR([*** PULSE support not found])
+ fi
+ ])
+ fi
+else
+ HAVE_PULSE=0
+fi
+
+AC_SUBST(PULSE_LIBS)
+AC_SUBST(PULSE_CFLAGS)
+AC_SUBST(HAVE_PULSE)
+AM_CONDITIONAL([HAVE_PULSE], [test "x$HAVE_PULSE" = x1])
+
+PKG_CHECK_MODULES(VORBIS, [ vorbisfile ])
+
+###################################
+# Output #
+###################################
+
+AC_CONFIG_FILES([
+Makefile
+src/Makefile
+libcanberra.pc
+])
+AC_OUTPUT
+
+# ==========================================================================
+ENABLE_ALSA=no
+if test "x$HAVE_ALSA" = "x1" ; then
+ ENABLE_ALSA=yes
+fi
+
+ENABLE_PULSE=no
+if test "x$HAVE_PULSE" = "x1" ; then
+ ENABLE_PULSE=yes
+fi
+
+echo "
+ ---{ $PACKAGE_NAME $VERSION }---
+
+ prefix: ${prefix}
+ sysconfdir: ${sysconfdir}
+ localstatedir: ${localstatedir}
+ Compiler: ${CC}
+ CFLAGS: ${CFLAGS}
+ C++-Compiler: ${CXX}
+ CXXFLAGS: ${CXXFLAGS}
+ Enable Alsa: ${ENABLE_ALSA}
+ Enable Pulse: ${ENABLE_PULSE}
+"
diff --git a/libcanberra.pc.in b/libcanberra.pc.in
new file mode 100644
index 0000000..edb1420
--- /dev/null
+++ b/libcanberra.pc.in
@@ -0,0 +1,11 @@
+prefix=@prefix@
+exec_prefix=${prefix}
+libdir=@libdir@
+includedir=${prefix}/include
+
+Name: libcanberra
+Description: Event Sound Interface
+Version: @PACKAGE_VERSION@
+Libs: -L${libdir} -lcanberra @PTHREAD_LIBS@
+Cflags: -D_REENTRANT -I${includedir}
+Requires:
diff --git a/src/Makefile.am b/src/Makefile.am
new file mode 100644
index 0000000..281738e
--- /dev/null
+++ b/src/Makefile.am
@@ -0,0 +1,58 @@
+# $Id$
+#
+# This file is part of libcanberra.
+#
+# Copyright 2008 Lennart Poettering
+#
+# libcanberra is free software; you can redistribute it and/or modify
+# it under the terms of the GNU Lesser General Public License as
+# published by the Free Software Foundation, either version 2.1 of the
+# License, or (at your option) any later version.
+#
+# libcanberra 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
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with libcanberra. If not, If not, see
+# <http://www.gnu.org/licenses/>.
+
+AM_CFLAGS = $(PTHREAD_CFLAGS)
+AM_CXXFLAGS = $(PTHREAD_CFLAGS)
+AM_LIBADD = $(PTHREAD_LIBS)
+AM_LDADD = $(PTHREAD_LIBS)
+
+lib_LTLIBRARIES = \
+ libcanberra.la
+
+noinst_PROGRAMS = \
+ test-canberra
+
+libcanberra_la_SOURCES = \
+ canberra.h \
+ common.c common.h \
+ mutex-posix.c mutex.h \
+ proplist.c proplist.h \
+ driver.h \
+ pulse.c \
+ read-sound-file.c read-sound-file.h \
+ read-vorbis.c read-vorbis.h \
+ read-wav.c read-wav.h \
+ sound-theme-spec.c sound-theme-spec.h \
+ llist.h \
+ macro.h \
+ malloc.h
+libcanberra_la_LIBADD = \
+ $(PULSE_LIBS) \
+ $(VORBIS_LIBS)
+libcanberra_la_CFLAGS = \
+ $(AM_CFLAGS) \
+ $(PULSE_CFLAGS) \
+ $(VORBIS_CFLAGS)
+
+test_canberra_SOURCES = \
+ test-canberra.c
+test_canberra_LDADD = \
+ $(AM_LDADD) \
+ libcanberra.la
diff --git a/src/canberra.c b/src/canberra.c
deleted file mode 100644
index 8b13789..0000000
--- a/src/canberra.c
+++ /dev/null
@@ -1 +0,0 @@
-
diff --git a/src/canberra.h b/src/canberra.h
index 2d48cd8..e8241f5 100644
--- a/src/canberra.h
+++ b/src/canberra.h
@@ -121,7 +121,7 @@ typedef struct ca_context ca_context;
/** Playback completion event callback. This callback will be called
* from a background thread. */
-typedef void ca_finish_callback_t(ca_context *c, uint32_t id, int error_code, void *userdata);
+typedef void (*ca_finish_callback_t)(ca_context *c, uint32_t id, int error_code, void *userdata);
/** Error codes */
enum {
@@ -154,9 +154,9 @@ int ca_proplist_set(ca_proplist *p, const char *key, const void *data, size_t nb
/** Create an (unconnected) context object */
int ca_context_create(ca_context **c);
-int ca_context_set_driver(ca_context **c, const char *driver);
+int ca_context_set_driver(ca_context *c, const char *driver);
-int ca_context_change_device(ca_context **c, const char *device);
+int ca_context_change_device(ca_context *c, const char *device);
/** Connect the context. This call is implicitly called if necessary. It
* is recommended to initialize the application.* properties before
diff --git a/src/common.c b/src/common.c
index bf11450..db59e27 100644
--- a/src/common.c
+++ b/src/common.c
@@ -20,6 +20,10 @@
<http://www.gnu.org/licenses/>.
***/
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
#include <stdarg.h>
#include "canberra.h"
@@ -27,6 +31,7 @@
#include "malloc.h"
#include "driver.h"
#include "proplist.h"
+#include "macro.h"
int ca_context_create(ca_context **_c) {
ca_context *c;
@@ -75,7 +80,7 @@ int ca_context_destroy(ca_context *c) {
return ret;
}
-int ca_context_set_driver(ca_context *c, char *driver) {
+int ca_context_set_driver(ca_context *c, const char *driver) {
char *n;
int ret;
@@ -99,7 +104,7 @@ fail:
return ret;
}
-int ca_context_change_device(ca_context *c, char *device) {
+int ca_context_change_device(ca_context *c, const char *device) {
char *n;
int ret;
@@ -164,7 +169,6 @@ static int ca_proplist_from_ap(ca_proplist **_p, va_list ap) {
for (;;) {
const char *key, *value;
- int ret;
if (!(key = va_arg(ap, const char*)))
break;
@@ -348,12 +352,20 @@ const char *ca_strerror(int code) {
const char * const error_table[-_CA_ERROR_MAX] = {
[-CA_SUCCESS] = "Success",
- [-CA_ERROR_NOT_SUPPORTED] = "Operation not supported",
+ [-CA_ERROR_NOTSUPPORTED] = "Operation not supported",
[-CA_ERROR_INVALID] = "Invalid argument",
[-CA_ERROR_STATE] = "Invalid state",
[-CA_ERROR_OOM] = "Out of memory",
- [-CA_ERROR_NO_DRIVER] = "No such driver",
- [-CA_ERROR_SYSTEM] = "System error"
+ [-CA_ERROR_NODRIVER] = "No such driver",
+ [-CA_ERROR_SYSTEM] = "System error",
+ [-CA_ERROR_CORRUPT] = "File or data corrupt",
+ [-CA_ERROR_TOOBIG] = "File or data too large",
+ [-CA_ERROR_NOTFOUND] = "File or data not found",
+ [-CA_ERROR_DESTROYED] = "Destroyed",
+ [-CA_ERROR_CANCELED] = "Canceled",
+ [-CA_ERROR_NOTAVAILABLE] = "Not available",
+ [-CA_ERROR_ACCESS] = "Access forbidden",
+ [-CA_ERROR_IO] = "IO error"
};
ca_return_val_if_fail(code <= 0, NULL);
@@ -367,11 +379,11 @@ int ca_parse_cache_control(ca_cache_control_t *control, const char *c) {
ca_return_val_if_fail(control, CA_ERROR_INVALID);
ca_return_val_if_fail(c, CA_ERROR_INVALID);
- if (streq(control, "never"))
+ if (streq(c, "never"))
*control = CA_CACHE_CONTROL_NEVER;
- else if (streq(control, "permanent"))
+ else if (streq(c, "permanent"))
*control = CA_CACHE_CONTROL_PERMANENT;
- else if (streq(control, "volatile"))
+ else if (streq(c, "volatile"))
*control = CA_CACHE_CONTROL_VOLATILE;
else
return CA_ERROR_INVALID;
diff --git a/src/macro.h b/src/macro.h
index 2f37bc1..cdc2bab 100644
--- a/src/macro.h
+++ b/src/macro.h
@@ -236,4 +236,6 @@ typedef int ca_bool_t;
#define PA_UINT32_TO_BE(x) PA_UINT32_SWAP(x)
#endif
+#define streq(a, b) (strcmp((a),(b)) == 0)
+
#endif
diff --git a/src/proplist.c b/src/proplist.c
index 6c10595..a835779 100644
--- a/src/proplist.c
+++ b/src/proplist.c
@@ -20,6 +20,10 @@
<http://www.gnu.org/licenses/>.
***/
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
#include <stdarg.h>
#include "canberra.h"
@@ -27,10 +31,6 @@
#include "macro.h"
#include "malloc.h"
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-
static unsigned calc_hash(const char *c) {
unsigned hash = 0;
diff --git a/src/proplist.h b/src/proplist.h
index 4cb511e..d23e5dc 100644
--- a/src/proplist.h
+++ b/src/proplist.h
@@ -47,7 +47,7 @@ int ca_proplist_merge(ca_proplist **_a, ca_proplist *b, ca_proplist *c);
ca_bool_t ca_proplist_contains(ca_proplist *p, const char *key);
/* Both of the following two functions are not locked! Need manual locking! */
-ca_prop* ca_context_get_unlocked(ca_proplist *c, const char *key);
-const char* ca_context_gets_unlocked(ca_proplist *c, const char *key);
+ca_prop* ca_proplist_get_unlocked(ca_proplist *p, const char *key);
+const char* ca_proplist_gets_unlocked(ca_proplist *p, const char *key);
#endif
diff --git a/src/pulse.c b/src/pulse.c
index c69668a..bb92bba 100644
--- a/src/pulse.c
+++ b/src/pulse.c
@@ -20,18 +20,31 @@
<http://www.gnu.org/licenses/>.
***/
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
/* The locking order needs to be strictly followed! First take the
* mainloop mutex, only then take outstanding_mutex if you need both!
* Not the other way round, beacause we might then enter a
* deadlock! */
+#include <errno.h>
+#include <stdlib.h>
+
#include <pulse/thread-mainloop.h>
#include <pulse/context.h>
#include <pulse/scache.h>
+#include <pulse/subscribe.h>
+#include <pulse/introspect.h>
#include "canberra.h"
-#include "common."
+#include "common.h"
#include "driver.h"
+#include "llist.h"
+#include "read-sound-file.h"
+#include "sound-theme-spec.h"
+#include "malloc.h"
enum outstanding_type {
OUTSTANDING_SAMPLE,
@@ -40,12 +53,12 @@ enum outstanding_type {
};
struct outstanding {
- PA_LLIST_FIELDS(struct outstanding);
+ CA_LLIST_FIELDS(struct outstanding);
enum outstanding_type type;
ca_context *context;
uint32_t id;
uint32_t sink_input;
- ca_stream *stream;
+ pa_stream *stream;
ca_finish_callback_t callback;
void *userdata;
ca_sound_file *file;
@@ -60,16 +73,16 @@ struct private {
ca_bool_t subscribed;
ca_mutex *outstanding_mutex;
- PA_LLIST_HEAD(struct outstanding, outstanding);
+ CA_LLIST_HEAD(struct outstanding, outstanding);
};
-#define PRIVATE(c) ((struct private *) ((c)->private)
+#define PRIVATE(c) ((struct private *) ((c)->private))
static void outstanding_free(struct outstanding *o) {
ca_assert(o);
if (o->file)
- ca_sound_file_free(o->file);
+ ca_sound_file_close(o->file);
if (o->stream) {
pa_stream_disconnect(o->stream);
@@ -79,7 +92,7 @@ static void outstanding_free(struct outstanding *o) {
ca_free(o);
}
-static int convert_proplist(pa_proplist **_l, pa_proplist *c) {
+static int convert_proplist(pa_proplist **_l, ca_proplist *c) {
pa_proplist *l;
ca_prop *i;
@@ -92,17 +105,17 @@ static int convert_proplist(pa_proplist **_l, pa_proplist *c) {
ca_mutex_lock(c->mutex);
for (i = c->first_item; i; i = i->next_item)
- if (pa_proplist_put(l, i->key, CA_PROP_DATA(i), i->nbytes) < 0) {
+ if (pa_proplist_set(l, i->key, CA_PROP_DATA(i), i->nbytes) < 0) {
ca_mutex_unlock(c->mutex);
pa_proplist_free(l);
- return PA_ERROR_INVALID;
+ return CA_ERROR_INVALID;
}
ca_mutex_unlock(c->mutex);
*_l = l;
- return PA_SUCCESS;
+ return CA_SUCCESS;
}
static pa_proplist *strip_canberra_data(pa_proplist *l) {
@@ -112,7 +125,7 @@ static pa_proplist *strip_canberra_data(pa_proplist *l) {
while ((key = pa_proplist_iterate(l, &state)))
if (strncmp(key, "canberra.", 12) == 0)
- pa_proplist_remove(l, key);
+ pa_proplist_unset(l, key);
return l;
}
@@ -151,10 +164,13 @@ static int translate_error(int error) {
static void context_state_cb(pa_context *pc, void *userdata) {
ca_context *c = userdata;
pa_context_state_t state;
+ struct private *p;
ca_assert(pc);
ca_assert(c);
+ p = PRIVATE(c);
+
state = pa_context_get_state(pc);
if (state == PA_CONTEXT_FAILED || state == PA_CONTEXT_TERMINATED) {
@@ -163,57 +179,61 @@ static void context_state_cb(pa_context *pc, void *userdata) {
ret = translate_error(pa_context_errno(pc));
- ca_mutex_lock(c->outstanding_mutex);
+ ca_mutex_lock(p->outstanding_mutex);
- while ((out = c->outstanding)) {
+ while ((out = p->outstanding)) {
- PA_LLIST_REMOVE(struct outstanding, c->outstanding, out);
- ca_mutex_unlock(c->outstanding_mutex);
+ CA_LLIST_REMOVE(struct outstanding, p->outstanding, out);
+ ca_mutex_unlock(p->outstanding_mutex);
if (out->callback)
out->callback(c, out->id, ret, out->userdata);
- outstanding_free(c->outstanding);
- ca_mutex_lock(c->outstanding_mutex);
+ outstanding_free(out);
+
+ ca_mutex_lock(p->outstanding_mutex);
}
- ca_mutex_unlock(c->outstanding_mutex);
+ ca_mutex_unlock(p->outstanding_mutex);
}
- pa_threaded_mainloop_signal(c->mainloop, FALSE);
+ pa_threaded_mainloop_signal(p->mainloop, FALSE);
}
static void context_subscribe_cb(pa_context *pc, pa_subscription_event_type_t t, uint32_t idx, void *userdata) {
struct outstanding *out, *n;
- PA_LLIST_HEAD(struct outstanding, l);
+ CA_LLIST_HEAD(struct outstanding, l);
ca_context *c = userdata;
+ struct private *p;
ca_assert(pc);
ca_assert(c);
- if (t != PA_SUBSCRIPTION_EVENT_SINK_INPUT|PA_SUBSCRIPTION_EVENT_REMOVE)
+ if (t != (PA_SUBSCRIPTION_EVENT_SINK_INPUT|PA_SUBSCRIPTION_EVENT_REMOVE))
return;
- PA_LLIST_HEAD_INIT(struct outstanding, l);
+ p = PRIVATE(c);
+
+ CA_LLIST_HEAD_INIT(struct outstanding, l);
- ca_mutex_lock(c->outstanding_mutex);
+ ca_mutex_lock(p->outstanding_mutex);
- for (out = c->outstanding; out; out = n) {
+ for (out = p->outstanding; out; out = n) {
n = out->next;
if (out->type != OUTSTANDING_SAMPLE || out->sink_input != idx)
continue;
- PA_LLIST_REMOVE(struct outstanding, c->outstanding, out);
- PA_LLIST_PREPEND(struct outstanding, l, out);
+ CA_LLIST_REMOVE(struct outstanding, p->outstanding, out);
+ CA_LLIST_PREPEND(struct outstanding, l, out);
}
- ca_mutex_unlock(c->outstanding_mutex);
+ ca_mutex_unlock(p->outstanding_mutex);
while (l) {
out = l;
- PA_LLIST_REMOVE(struct outstanding, l, out);
+ CA_LLIST_REMOVE(struct outstanding, l, out);
if (out->callback)
out->callback(c, out->id, CA_SUCCESS, out->userdata);
@@ -225,28 +245,36 @@ static void context_subscribe_cb(pa_context *pc, pa_subscription_event_type_t t,
int driver_open(ca_context *c) {
pa_proplist *l;
struct private *p;
+ int ret;
- ca_return_val_if_fail(c, PA_ERROR_INVALID);
- ca_return_val_if_fail(!c->driver || streq(c->driver, "pulse"), PA_ERROR_NO_DRIVER);
- ca_return_val_if_fail(!PRIVATE(c), PA_ERROR_STATE);
+ ca_return_val_if_fail(c, CA_ERROR_INVALID);
+ ca_return_val_if_fail(!c->driver || streq(c->driver, "pulse"), CA_ERROR_NODRIVER);
+ ca_return_val_if_fail(!PRIVATE(c), CA_ERROR_STATE);
+
+ if (!(c->private = p = ca_new0(struct private, 1)))
+ return CA_ERROR_OOM;
- if (!(p = PRIVATE(c) = ca_new0(struct private, 1)))
- return PA_ERROR_OOM;
+
+ if (!(p->outstanding_mutex = ca_mutex_new())) {
+ driver_destroy(c);
+ return CA_ERROR_OOM;
+ }
if (!(p->mainloop = pa_threaded_mainloop_new())) {
driver_destroy(c);
- return PA_ERROR_OOM;
+ return CA_ERROR_OOM;
}
- if ((ret = convert_proplist(&l, c->proplist))) {
+ if ((ret = convert_proplist(&l, c->props))) {
driver_destroy(c);
return ret;
}
- if (!(p->context = pa_context_new_with_proplist(pa_threaded_mainloop_get_api(p->mainloop), l))) {
+
+ if (!(p->context = pa_context_new_with_proplist(pa_threaded_mainloop_get_api(p->mainloop), "libcanberra", l))) {
pa_proplist_free(l);
driver_destroy(c);
- return PA_ERROR_OOM;
+ return CA_ERROR_OOM;
}
pa_proplist_free(l);
@@ -255,7 +283,7 @@ int driver_open(ca_context *c) {
pa_context_set_subscribe_callback(p->context, context_subscribe_cb, c);
if (pa_context_connect(p->context, NULL, 0, NULL) < 0) {
- int ret = translate_error(pa_context_errno(p->context));
+ ret = translate_error(pa_context_errno(p->context));
driver_destroy(c);
return ret;
}
@@ -265,13 +293,13 @@ int driver_open(ca_context *c) {
if (pa_threaded_mainloop_start(p->mainloop) < 0) {
pa_threaded_mainloop_unlock(p->mainloop);
driver_destroy(c);
- return PA_ERROR_INTERNAL;
+ return CA_ERROR_OOM;
}
pa_threaded_mainloop_wait(p->mainloop);
if (pa_context_get_state(p->context) != PA_CONTEXT_READY) {
- int ret = translate_error(pa_context_errno(p->context));
+ ret = translate_error(pa_context_errno(p->context));
pa_threaded_mainloop_unlock(p->mainloop);
driver_destroy(c);
return ret;
@@ -283,14 +311,25 @@ int driver_open(ca_context *c) {
}
int driver_destroy(ca_context *c) {
- ca_return_val_if_fail(c, PA_ERROR_INVALID);
- ca_return_val_if_fail(c->private, PA_ERROR_STATE);
+ struct private *p;
+
+ ca_return_val_if_fail(c, CA_ERROR_INVALID);
+ ca_return_val_if_fail(c->private, CA_ERROR_STATE);
p = PRIVATE(c);
if (p->mainloop)
pa_threaded_mainloop_stop(p->mainloop);
+ while (p->outstanding) {
+ struct outstanding *out = p->outstanding;
+ CA_LLIST_REMOVE(struct outstanding, p->outstanding, out);
+
+ if (out->callback)
+ out->callback(c, out->id, CA_ERROR_DESTROYED, out->userdata);
+
+ outstanding_free(out);
+ }
if (p->context) {
pa_context_disconnect(p->context);
pa_context_unref(p->context);
@@ -302,21 +341,16 @@ int driver_destroy(ca_context *c) {
if (p->theme)
ca_theme_data_free(p->theme);
- while (p->outstanding) {
- struct outstanding *out = p->outstanding;
- PA_LLIST_REMOVE(struct outstanding, p->outstanding, out);
-
- if (out->callback)
- out->callback(c, out->id, CA_ERROR_DESTROYED, out->userdata);
-
- outstanding_free(out);
- }
+ if (p->outstanding_mutex)
+ ca_mutex_free(p->outstanding_mutex);
ca_free(p);
+
+ return CA_SUCCESS;
}
int driver_change_device(ca_context *c, char *device) {
- ca_return_val_if_fail(c, PA_ERROR_INVALID);
+ ca_return_val_if_fail(c, CA_ERROR_INVALID);
/* We're happy with any device change. We might however add code
* here eventually to move all currently played back event sounds
@@ -331,15 +365,15 @@ int driver_change_props(ca_context *c, ca_proplist *changed, ca_proplist *merged
pa_proplist *l;
int ret = CA_SUCCESS;
- ca_return_val_if_fail(c, PA_ERROR_INVALID);
- ca_return_val_if_fail(changed, PA_ERROR_INVALID);
- ca_return_val_if_fail(merged, PA_ERROR_INVALID);
- ca_return_val_if_fail(c->private, PA_ERROR_STATE);
+ ca_return_val_if_fail(c, CA_ERROR_INVALID);
+ ca_return_val_if_fail(changed, CA_ERROR_INVALID);
+ ca_return_val_if_fail(merged, CA_ERROR_INVALID);
+ ca_return_val_if_fail(c->private, CA_ERROR_STATE);
p = PRIVATE(c);
- ca_return_val_if_fail(p->mainloop, PA_ERROR_STATE);
- ca_return_val_if_fail(p->context, PA_ERROR_STATE);
+ ca_return_val_if_fail(p->mainloop, CA_ERROR_STATE);
+ ca_return_val_if_fail(p->context, CA_ERROR_STATE);
if ((ret = convert_proplist(&l, changed)))
return ret;
@@ -366,14 +400,15 @@ int driver_change_props(ca_context *c, ca_proplist *changed, ca_proplist *merged
static int subscribe(ca_context *c) {
struct private *p;
pa_operation *o;
+ int ret;
- ca_return_val_if_fail(c, PA_ERROR_INVALID);
- ca_return_val_if_fail(c->private, PA_ERROR_STATE);
+ ca_return_val_if_fail(c, CA_ERROR_INVALID);
+ ca_return_val_if_fail(c->private, CA_ERROR_STATE);
p = PRIVATE(c);
- ca_return_val_if_fail(p->mainloop, PA_ERROR_STATE);
- ca_return_val_if_fail(p->context, PA_ERROR_STATE);
- ca_return_val_if_fail(!p->subscribed, PA_SUCCESS);
+ ca_return_val_if_fail(p->mainloop, CA_ERROR_STATE);
+ ca_return_val_if_fail(p->context, CA_ERROR_STATE);
+ ca_return_val_if_fail(!p->subscribed, CA_SUCCESS);
pa_threaded_mainloop_lock(p->mainloop);
@@ -422,20 +457,20 @@ static void stream_state_cb(pa_stream *s, void *userdata) {
if (state == PA_STREAM_FAILED || state == PA_STREAM_TERMINATED) {
int err;
- ca_mutex_lock(p->context->outstanding_mutex);
- PA_LLIST_REMOVE(struct outstanding, c->outstanding, out);
- ca_mutex_unlock(p->context->outstanding_mutex);
+ ca_mutex_lock(p->outstanding_mutex);
+ CA_LLIST_REMOVE(struct outstanding, p->outstanding, out);
+ ca_mutex_unlock(p->outstanding_mutex);
- err = state == PA_STREAM_FAILED ? translate_error(pa_context_errno(pa_stream_get_context(s)))
+ err = state == PA_STREAM_FAILED ? translate_error(pa_context_errno(pa_stream_get_context(s))) : CA_ERROR_DESTROYED;
if (out->callback)
- out->callback(c, out->id, ret, out->userdata);
+ out->callback(out->context, out->id, err, out->userdata);
- outstanding_free(c->outstanding);
+ outstanding_free(out);
}
}
- pa_threaded_mainloop_signal(c->mainloop, TRUE);
+ pa_threaded_mainloop_signal(p->mainloop, TRUE);
}
static void stream_drain_cb(pa_stream *s, int success, void *userdata) {
@@ -450,9 +485,9 @@ static void stream_drain_cb(pa_stream *s, int success, void *userdata) {
ca_assert(out->type = OUTSTANDING_STREAM);
ca_assert(out->clean_up);
- ca_mutex_lock(p->context->outstanding_mutex);
- PA_LLIST_REMOVE(struct outstanding, c->outstanding, out);
- ca_mutex_unlock(p->context->outstanding_mutex);
+ ca_mutex_lock(p->outstanding_mutex);
+ CA_LLIST_REMOVE(struct outstanding, p->outstanding, out);
+ ca_mutex_unlock(p->outstanding_mutex);
if (out->callback) {
int err;
@@ -477,7 +512,7 @@ static void stream_write_cb(pa_stream *s, size_t bytes, void *userdata) {
p = PRIVATE(out->context);
if (!(data = ca_malloc(bytes))) {
- ret = CA_ERROR_OOM
+ ret = CA_ERROR_OOM;
goto finish;
}
@@ -486,7 +521,7 @@ static void stream_write_cb(pa_stream *s, size_t bytes, void *userdata) {
if (bytes > 0) {
- if ((ret = pa_stream_writesp, data, bytes)) < 0) {
+ if ((ret = pa_stream_write(s, data, bytes, free, 0, PA_SEEK_RELATIVE)) < 0) {
ret = translate_error(ret);
goto finish;
}
@@ -502,22 +537,21 @@ static void stream_write_cb(pa_stream *s, size_t bytes, void *userdata) {
}
/* Let's just signal driver_cache() which has been waiting for us */
- pa_threaded_mainloop_signal(c->mainloop, TRUE);
+ pa_threaded_mainloop_signal(p->mainloop, TRUE);
} else {
+ pa_operation *o;
ca_assert(out->type = OUTSTANDING_STREAM);
- if (!(o = pa_stream_drain(p->context, stream_drain_cb, out))) {
+ if (!(o = pa_stream_drain(s, stream_drain_cb, out))) {
ret = translate_error(pa_context_errno(p->context));
- goto fail;
+ goto finish;
}
pa_operation_unref(o);
}
}
- ca_free(data);
-
return;
finish:
@@ -525,17 +559,17 @@ finish:
ca_free(data);
if (out->clean_up) {
- ca_mutex_lock(p->context->outstanding_mutex);
- PA_LLIST_REMOVE(struct outstanding, c->outstanding, out);
- ca_mutex_unlock(p->context->outstanding_mutex);
+ ca_mutex_lock(p->outstanding_mutex);
+ CA_LLIST_REMOVE(struct outstanding, p->outstanding, out);
+ ca_mutex_unlock(p->outstanding_mutex);
if (out->callback)
out->callback(out->context, out->id, ret, out->userdata);
outstanding_free(out);
} else {
- pa_stream_disconnect(p);
- pa_threaded_mainloop_signal(c->mainloop, TRUE);
+ pa_stream_disconnect(s);
+ pa_threaded_mainloop_signal(p->mainloop, TRUE);
out->error = ret;
}
}
@@ -551,25 +585,26 @@ int driver_play(ca_context *c, uint32_t id, ca_proplist *proplist, ca_finish_cal
pa_proplist *l = NULL;
const char *n, *vol, *ct;
char *name = NULL;
- int err = 0;
pa_volume_t v = PA_VOLUME_NORM;
pa_sample_spec ss;
ca_cache_control_t cache_control = CA_CACHE_CONTROL_NEVER;
struct outstanding *out = NULL;
int try = 3;
+ int ret;
+ pa_operation *o;
- ca_return_val_if_fail(c, PA_ERROR_INVALID);
- ca_return_val_if_fail(proplist, PA_ERROR_INVALID);
- ca_return_val_if_fail(!userdata || cb, PA_ERROR_INVALID);
- ca_return_val_if_fail(c->private, PA_ERROR_STATE);
+ ca_return_val_if_fail(c, CA_ERROR_INVALID);
+ ca_return_val_if_fail(proplist, CA_ERROR_INVALID);
+ ca_return_val_if_fail(!userdata || cb, CA_ERROR_INVALID);
+ ca_return_val_if_fail(c->private, CA_ERROR_STATE);
p = PRIVATE(c);
- ca_return_val_if_fail(p->mainloop, PA_ERROR_STATE);
- ca_return_val_if_fail(p->context, PA_ERROR_STATE);
+ ca_return_val_if_fail(p->mainloop, CA_ERROR_STATE);
+ ca_return_val_if_fail(p->context, CA_ERROR_STATE);
- if (!(out = pa_xnew0(struct outstanding, 1))) {
- ret = PA_ERROR_OOM;
+ if (!(out = ca_new0(struct outstanding, 1))) {
+ ret = CA_ERROR_OOM;
goto finish;
}
@@ -584,12 +619,12 @@ int driver_play(ca_context *c, uint32_t id, ca_proplist *proplist, ca_finish_cal
goto finish;
if (!(n = pa_proplist_gets(l, CA_PROP_EVENT_ID))) {
- ret = PA_ERROR_INVALID;
+ ret = CA_ERROR_INVALID;
goto finish;
}
if (!(name = ca_strdup(n))) {
- ret = PA_ERROR_OOM;
+ ret = CA_ERROR_OOM;
goto finish;
}
@@ -600,7 +635,7 @@ int driver_play(ca_context *c, uint32_t id, ca_proplist *proplist, ca_finish_cal
errno = 0;
dvol = strtod(vol, &e);
if (errno != 0 || !e || *e) {
- ret = PA_ERROR_INVALID;
+ ret = CA_ERROR_INVALID;
goto finish;
}
@@ -609,7 +644,7 @@ int driver_play(ca_context *c, uint32_t id, ca_proplist *proplist, ca_finish_cal
if ((ct = pa_proplist_gets(l, CA_PROP_CANBERRA_CACHE_CONTROL)))
if ((ret = ca_parse_cache_control(&cache_control, ct)) < 0) {
- ret = PA_ERROR_INVALID;
+ ret = CA_ERROR_INVALID;
goto finish;
}
@@ -623,21 +658,21 @@ int driver_play(ca_context *c, uint32_t id, ca_proplist *proplist, ca_finish_cal
pa_threaded_mainloop_lock(p->mainloop);
/* Let's try to play the sample */
- if (!(o = pa_context_play_sample_with_proplist(p->context, name, NULL, v, l, id, play_sample_cb, out))) {
+ if (!(o = pa_context_play_sample_with_proplist(p->context, name, c->device, v, l, play_sample_cb, out))) {
ret = translate_error(pa_context_errno(p->context));
pa_threaded_mainloop_unlock(p->mainloop);
goto finish;
}
- while (pa_operation_get_state(o) != OPERATION_DONE)
- pa_threaded_mainloop_wait(m);
+ while (pa_operation_get_state(o) != PA_OPERATION_DONE)
+ pa_threaded_mainloop_wait(p->mainloop);
pa_operation_unref(o);
pa_threaded_mainloop_unlock(p->mainloop);
/* Did we manage to play the sample or did some other error occur? */
- if (out->error != CA_ERROR_NOT_FOUND)
+ if (out->error != CA_ERROR_NOTFOUND)
goto finish;
/* Hmm, we need to play it directly */
@@ -650,39 +685,38 @@ int driver_play(ca_context *c, uint32_t id, ca_proplist *proplist, ca_finish_cal
/* Let's upload the sample and retry playing */
if ((ret = driver_cache(c, proplist)) < 0)
- goto fail;
+ goto finish;
}
out->type = OUTSTANDING_STREAM;
/* Let's stream the sample directly */
if ((ret = ca_lookup_sound(&out->file, &p->theme, proplist)) < 0)
- goto fail;
+ goto finish;
- ss.channels = sample_type_table[ca_sound_file_get_sample_type(f)];
- ss.channels = ca_sound_file_get_nchannels(f);
- ss.rate = ca_sound_file_get_rate(f);
+ ss.channels = sample_type_table[ca_sound_file_get_sample_type(out->file)];
+ ss.channels = ca_sound_file_get_nchannels(out->file);
+ ss.rate = ca_sound_file_get_rate(out->file);
pa_threaded_mainloop_lock(p->mainloop);
if (!(out->stream = pa_stream_new_with_proplist(p->context, name, &ss, NULL, l))) {
ret = translate_error(pa_context_errno(p->context));
pa_threaded_mainloop_unlock(p->mainloop);
- goto fail;
+ goto finish;
}
- pa_stream_set_userdata(p->stream, out);
- pa_stream_set_state_callback(p->stream, stream_state_cb, out);
- pa_stream_set_write_callback(p->stream, stream_request_cb, out);
+ pa_stream_set_state_callback(out->stream, stream_state_cb, out);
+ pa_stream_set_write_callback(out->stream, stream_write_cb, out);
- if (pa_stream_connect_playback(s, NULL, NULL, 0, NULL, NULL) < 0) {
+ if (pa_stream_connect_playback(out->stream, NULL, NULL, 0, NULL, NULL) < 0) {
ret = translate_error(pa_context_errno(p->context));
pa_threaded_mainloop_unlock(p->mainloop);
- goto fail;
+ goto finish;
}
for (;;) {
- pa_stream_state state = pa_stream_get_state(s);
+ pa_stream_state_t state = pa_stream_get_state(out->stream);
/* Stream sucessfully created */
if (state == PA_STREAM_READY)
@@ -692,22 +726,22 @@ int driver_play(ca_context *c, uint32_t id, ca_proplist *proplist, ca_finish_cal
if (state == PA_STREAM_FAILED) {
ret = translate_error(pa_context_errno(p->context));
pa_threaded_mainloop_unlock(p->mainloop);
- goto fail;
+ goto finish;
}
if (state == PA_STREAM_TERMINATED) {
ret = out->error;
pa_threaded_mainloop_unlock(p->mainloop);
- goto fail;
+ goto finish;
}
pa_threaded_mainloop_wait(p->mainloop);
}
- if ((out->sink_input = pa_stream_get_index(s)) == PA_INVALID_INDEX) {
+ if ((out->sink_input = pa_stream_get_index(out->stream)) == PA_INVALID_INDEX) {
ret = translate_error(pa_context_errno(p->context));
pa_threaded_mainloop_unlock(p->mainloop);
- goto fail;
+ goto finish;
}
pa_threaded_mainloop_unlock(p->mainloop);
@@ -720,9 +754,9 @@ finish:
if (ret == CA_SUCCESS && (out->type == OUTSTANDING_STREAM || cb)) {
out->clean_up = TRUE;
- pa_mutex_lock(p->outstanding_mutex);
- PA_LLIST_PREPEND(struct outstanding, p->outstanding, out);
- pa_mutex_unlock(p->outstanding_mutex);
+ ca_mutex_lock(p->outstanding_mutex);
+ CA_LLIST_PREPEND(struct outstanding, p->outstanding, out);
+ ca_mutex_unlock(p->outstanding_mutex);
} else
outstanding_free(out);
@@ -740,13 +774,13 @@ int driver_cancel(ca_context *c, uint32_t id) {
int ret = CA_SUCCESS;
struct outstanding *out, *n;
- ca_return_val_if_fail(c, PA_ERROR_INVALID);
- ca_return_val_if_fail(c->private, PA_ERROR_STATE);
+ ca_return_val_if_fail(c, CA_ERROR_INVALID);
+ ca_return_val_if_fail(c->private, CA_ERROR_STATE);
p = PRIVATE(c);
- ca_return_val_if_fail(p->mainloop, PA_ERROR_STATE);
- ca_return_val_if_fail(p->context, PA_ERROR_STATE);
+ ca_return_val_if_fail(p->mainloop, CA_ERROR_STATE);
+ ca_return_val_if_fail(p->context, CA_ERROR_STATE);
pa_threaded_mainloop_lock(p->mainloop);
@@ -799,14 +833,14 @@ int driver_cache(ca_context *c, ca_proplist *proplist) {
ca_cache_control_t cache_control = CA_CACHE_CONTROL_NEVER;
struct outstanding out;
- ca_return_val_if_fail(c, PA_ERROR_INVALID);
- ca_return_val_if_fail(proplist, PA_ERROR_INVALID);
- ca_return_val_if_fail(c->private, PA_ERROR_STATE);
+ ca_return_val_if_fail(c, CA_ERROR_INVALID);
+ ca_return_val_if_fail(proplist, CA_ERROR_INVALID);
+ ca_return_val_if_fail(c->private, CA_ERROR_STATE);
p = PRIVATE(c);
- ca_return_val_if_fail(p->mainloop, PA_ERROR_STATE);
- ca_return_val_if_fail(p->context, PA_ERROR_STATE);
+ ca_return_val_if_fail(p->mainloop, CA_ERROR_STATE);
+ ca_return_val_if_fail(p->context, CA_ERROR_STATE);
if (!(out = ca_new0(struct outstanding, 1))) {
ret = CA_ERROR_OOM;
@@ -821,7 +855,7 @@ int driver_cache(ca_context *c, ca_proplist *proplist) {
goto finish;
if (!(n = pa_proplist_gets(l, CA_PROP_EVENT_ID))) {
- ret = PA_ERROR_INVALID;
+ ret = CA_ERROR_INVALID;
goto finish;
}
@@ -832,12 +866,12 @@ int driver_cache(ca_context *c, ca_proplist *proplist) {
if ((ct = pa_proplist_gets(l, CA_PROP_CANBERRA_CACHE_CONTROL)))
if ((ret = ca_parse_cache_control(&cache_control, ct)) < 0) {
- ret = PA_ERROR_INVALID;
+ ret = CA_ERROR_INVALID;
goto finish;
}
if (ct == CA_CACHE_CONTROL_NEVER) {
- ret = PA_ERROR_INVALID;
+ ret = CA_ERROR_INVALID;
goto finish;
}
diff --git a/src/read-sound-file.c b/src/read-sound-file.c
index 8670445..eb2acbd 100644
--- a/src/read-sound-file.c
+++ b/src/read-sound-file.c
@@ -20,7 +20,18 @@
<http://www.gnu.org/licenses/>.
***/
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <errno.h>
+
#include "read-sound-file.h"
+#include "read-wav.h"
+#include "read-vorbis.h"
+#include "macro.h"
+#include "malloc.h"
+#include "canberra.h"
struct ca_sound_file {
ca_wav *wav;
@@ -32,13 +43,13 @@ struct ca_sound_file {
ca_sample_type_t type;
};
-int ca_sound_file_open(ca_sound_file *_f, const char *fn) {
+int ca_sound_file_open(ca_sound_file **_f, const char *fn) {
FILE *file;
ca_sound_file *f;
int ret;
- ca_return_val_if_fail(_f, PA_ERROR_INVALID);
- ca_return_val_if_fail(fn, PA_ERROR_INVALID);
+ ca_return_val_if_fail(_f, CA_ERROR_INVALID);
+ ca_return_val_if_fail(fn, CA_ERROR_INVALID);
if (!(f = ca_new0(ca_sound_file, 1)))
return CA_ERROR_OOM;
diff --git a/src/read-sound-file.h b/src/read-sound-file.h
index 5ab7e66..f236b13 100644
--- a/src/read-sound-file.h
+++ b/src/read-sound-file.h
@@ -23,15 +23,18 @@
<http://www.gnu.org/licenses/>.
***/
+#include <sys/types.h>
+#include <inttypes.h>
+
typedef enum ca_sample_type {
CA_SAMPLE_S16NE,
CA_SAMPLE_S16RE,
CA_SAMPLE_U8
} ca_sample_type_t;
-typedef struct ca_sound_file wa_sound_file;
+typedef struct ca_sound_file ca_sound_file;
-int ca_sound_file_open(ca_sound_file *f, const char *fn);
+int ca_sound_file_open(ca_sound_file **f, const char *fn);
void ca_sound_file_close(ca_sound_file *f);
unsigned ca_sound_file_get_nchannels(ca_sound_file *f);
diff --git a/src/read-vorbis.c b/src/read-vorbis.c
index 717f851..f54e271 100644
--- a/src/read-vorbis.c
+++ b/src/read-vorbis.c
@@ -20,7 +20,15 @@
<http://www.gnu.org/licenses/>.
***/
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <vorbis/vorbisfile.h>
+#include <vorbis/codec.h>
+
#include "read-vorbis.h"
+#include "macro.h"
#define FILE_SIZE_MAX (64U*1024U*1024U)
@@ -30,12 +38,12 @@ struct ca_vorbis {
static int convert_error(int or) {
switch (or) {
- case OV_NOSEEK:
- case OV_BADPACKET:
- case OV_BADLINK:
- case OV_FAULT:
+ case OV_ENOSEEK:
+ case OV_EBADPACKET:
+ case OV_EBADLINK:
+ case OV_EFAULT:
case OV_EREAD:
- case OV_HOLE:
+ case OV_EHOLE:
return CA_ERROR_IO;
case OV_EIMPL:
diff --git a/src/read-vorbis.h b/src/read-vorbis.h
index 5521c09..d9b5ade 100644
--- a/src/read-vorbis.h
+++ b/src/read-vorbis.h
@@ -24,6 +24,7 @@
***/
#include <stdio.h>
+#include <inttypes.h>
typedef struct ca_vorbis ca_vorbis;
diff --git a/src/read-wav.c b/src/read-wav.c
index 1f3d634..e96e8ae 100644
--- a/src/read-wav.c
+++ b/src/read-wav.c
@@ -20,7 +20,12 @@
<http://www.gnu.org/licenses/>.
***/
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
#include "read-wav.h"
+#include "macro.h"
#define FILE_SIZE_MAX (64U*1024U*1024U)
diff --git a/src/read-wav.h b/src/read-wav.h
index 8344cc9..ae7b8eb 100644
--- a/src/read-wav.h
+++ b/src/read-wav.h
@@ -34,7 +34,7 @@ void ca_wav_close(ca_wav *f);
unsigned ca_wav_get_nchannels(ca_wav *f);
unsigned ca_wav_get_rate(ca_wav *f);
-ca_sample_type ca_wav_get_sample_type(ca_wav *f);
+ca_sample_type_t ca_wav_get_sample_type(ca_wav *f);
int ca_wav_read_u8(ca_wav *f, uint8_t *d, unsigned *n);
int ca_wav_read_s16le(ca_wav *f, int16_t *d, unsigned *n);
diff --git a/src/sound-theme-spec.c b/src/sound-theme-spec.c
index fd0f95b..11f15d8 100644
--- a/src/sound-theme-spec.c
+++ b/src/sound-theme-spec.c
@@ -20,6 +20,10 @@
<http://www.gnu.org/licenses/>.
***/
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
#include "sound-theme-spec.h"
#include "llist.h"
diff --git a/src/test.c b/src/test-canberra.c
index 0fd30e0..4a379a3 100644
--- a/src/test.c
+++ b/src/test-canberra.c
@@ -20,6 +20,11 @@
<http://www.gnu.org/licenses/>.
***/
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
#include <unistd.h>
#include "canberra.h"