From 7ac8038c3690eb5547cfdff83235f3636f87c303 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Tue, 27 May 2008 10:53:55 +0000 Subject: add acx_pthread to the build git-svn-id: file:///home/lennart/svn/public/libcanberra/trunk@14 01b60673-d06a-42c0-afdd-89cb8e0f78ac --- acinclude.m4 | 388 +++++++++++++++++++++++++++++++++++++++++++++++++ src/pulse.c | 20 +-- src/read-sound-file.c | 16 +- src/read-vorbis.c | 28 ++-- src/read-vorbis.h | 2 +- src/read-wav.c | 36 ++--- src/sound-theme-spec.c | 13 +- 7 files changed, 450 insertions(+), 53 deletions(-) create mode 100644 acinclude.m4 diff --git a/acinclude.m4 b/acinclude.m4 new file mode 100644 index 0000000..723eb87 --- /dev/null +++ b/acinclude.m4 @@ -0,0 +1,388 @@ +dnl @synopsis ACX_PTHREAD([ACTION-IF-FOUND[, ACTION-IF-NOT-FOUND]]) +dnl +dnl @summary figure out how to build C programs using POSIX threads +dnl +dnl This macro figures out how to build C programs using POSIX threads. +dnl It sets the PTHREAD_LIBS output variable to the threads library and +dnl linker flags, and the PTHREAD_CFLAGS output variable to any special +dnl C compiler flags that are needed. (The user can also force certain +dnl compiler flags/libs to be tested by setting these environment +dnl variables.) +dnl +dnl Also sets PTHREAD_CC to any special C compiler that is needed for +dnl multi-threaded programs (defaults to the value of CC otherwise). +dnl (This is necessary on AIX to use the special cc_r compiler alias.) +dnl +dnl NOTE: You are assumed to not only compile your program with these +dnl flags, but also link it with them as well. e.g. you should link +dnl with $PTHREAD_CC $CFLAGS $PTHREAD_CFLAGS $LDFLAGS ... $PTHREAD_LIBS +dnl $LIBS +dnl +dnl If you are only building threads programs, you may wish to use +dnl these variables in your default LIBS, CFLAGS, and CC: +dnl +dnl LIBS="$PTHREAD_LIBS $LIBS" +dnl CFLAGS="$CFLAGS $PTHREAD_CFLAGS" +dnl CC="$PTHREAD_CC" +dnl +dnl In addition, if the PTHREAD_CREATE_JOINABLE thread-attribute +dnl constant has a nonstandard name, defines PTHREAD_CREATE_JOINABLE to +dnl that name (e.g. PTHREAD_CREATE_UNDETACHED on AIX). +dnl +dnl ACTION-IF-FOUND is a list of shell commands to run if a threads +dnl library is found, and ACTION-IF-NOT-FOUND is a list of commands to +dnl run it if it is not found. If ACTION-IF-FOUND is not specified, the +dnl default action will define HAVE_PTHREAD. +dnl +dnl Please let the authors know if this macro fails on any platform, or +dnl if you have any other suggestions or comments. This macro was based +dnl on work by SGJ on autoconf scripts for FFTW (www.fftw.org) (with +dnl help from M. Frigo), as well as ac_pthread and hb_pthread macros +dnl posted by Alejandro Forero Cuervo to the autoconf macro repository. +dnl We are also grateful for the helpful feedback of numerous users. +dnl +dnl @category InstalledPackages +dnl @author Steven G. Johnson +dnl @version 2006-05-29 +dnl @license GPLWithACException +dnl +dnl Checks for GCC shared/pthread inconsistency based on work by +dnl Marcin Owsiany + + +AC_DEFUN([ACX_PTHREAD], [ +AC_REQUIRE([AC_CANONICAL_HOST]) +AC_LANG_SAVE +AC_LANG_C +acx_pthread_ok=no + +# We used to check for pthread.h first, but this fails if pthread.h +# requires special compiler flags (e.g. on True64 or Sequent). +# It gets checked for in the link test anyway. + +# First of all, check if the user has set any of the PTHREAD_LIBS, +# etcetera environment variables, and if threads linking works using +# them: +if test x"$PTHREAD_LIBS$PTHREAD_CFLAGS" != x; then + save_CFLAGS="$CFLAGS" + CFLAGS="$CFLAGS $PTHREAD_CFLAGS" + save_LIBS="$LIBS" + LIBS="$PTHREAD_LIBS $LIBS" + AC_MSG_CHECKING([for pthread_join in LIBS=$PTHREAD_LIBS with CFLAGS=$PTHREAD_CFLAGS]) + AC_TRY_LINK_FUNC(pthread_join, acx_pthread_ok=yes) + AC_MSG_RESULT($acx_pthread_ok) + if test x"$acx_pthread_ok" = xno; then + PTHREAD_LIBS="" + PTHREAD_CFLAGS="" + fi + LIBS="$save_LIBS" + CFLAGS="$save_CFLAGS" +fi + +# We must check for the threads library under a number of different +# names; the ordering is very important because some systems +# (e.g. DEC) have both -lpthread and -lpthreads, where one of the +# libraries is broken (non-POSIX). + +# Create a list of thread flags to try. Items starting with a "-" are +# C compiler flags, and other items are library names, except for "none" +# which indicates that we try without any flags at all, and "pthread-config" +# which is a program returning the flags for the Pth emulation library. + +acx_pthread_flags="pthreads none -Kthread -kthread lthread -pthread -pthreads -mthreads pthread --thread-safe -mt pthread-config" + +# The ordering *is* (sometimes) important. Some notes on the +# individual items follow: + +# pthreads: AIX (must check this before -lpthread) +# none: in case threads are in libc; should be tried before -Kthread and +# other compiler flags to prevent continual compiler warnings +# -Kthread: Sequent (threads in libc, but -Kthread needed for pthread.h) +# -kthread: FreeBSD kernel threads (preferred to -pthread since SMP-able) +# lthread: LinuxThreads port on FreeBSD (also preferred to -pthread) +# -pthread: Linux/gcc (kernel threads), BSD/gcc (userland threads) +# -pthreads: Solaris/gcc +# -mthreads: Mingw32/gcc, Lynx/gcc +# -mt: Sun Workshop C (may only link SunOS threads [-lthread], but it +# doesn't hurt to check since this sometimes defines pthreads too; +# also defines -D_REENTRANT) +# ... -mt is also the pthreads flag for HP/aCC +# pthread: Linux, etcetera +# --thread-safe: KAI C++ +# pthread-config: use pthread-config program (for GNU Pth library) + +case "${host_cpu}-${host_os}" in + *solaris*) + + # On Solaris (at least, for some versions), libc contains stubbed + # (non-functional) versions of the pthreads routines, so link-based + # tests will erroneously succeed. (We need to link with -pthreads/-mt/ + # -lpthread.) (The stubs are missing pthread_cleanup_push, or rather + # a function called by this macro, so we could check for that, but + # who knows whether they'll stub that too in a future libc.) So, + # we'll just look for -pthreads and -lpthread first: + + acx_pthread_flags="-pthreads pthread -mt -pthread $acx_pthread_flags" + ;; +esac + +if test x"$acx_pthread_ok" = xno; then +for flag in $acx_pthread_flags; do + + case $flag in + none) + AC_MSG_CHECKING([whether pthreads work without any flags]) + ;; + + -*) + AC_MSG_CHECKING([whether pthreads work with $flag]) + PTHREAD_CFLAGS="$flag" + ;; + + pthread-config) + AC_CHECK_PROG(acx_pthread_config, pthread-config, yes, no) + if test x"$acx_pthread_config" = xno; then continue; fi + PTHREAD_CFLAGS="`pthread-config --cflags`" + PTHREAD_LIBS="`pthread-config --ldflags` `pthread-config --libs`" + ;; + + *) + AC_MSG_CHECKING([for the pthreads library -l$flag]) + PTHREAD_LIBS="-l$flag" + ;; + esac + + save_LIBS="$LIBS" + save_CFLAGS="$CFLAGS" + LIBS="$PTHREAD_LIBS $LIBS" + CFLAGS="$CFLAGS $PTHREAD_CFLAGS" + + # Check for various functions. We must include pthread.h, + # since some functions may be macros. (On the Sequent, we + # need a special flag -Kthread to make this header compile.) + # We check for pthread_join because it is in -lpthread on IRIX + # while pthread_create is in libc. We check for pthread_attr_init + # due to DEC craziness with -lpthreads. We check for + # pthread_cleanup_push because it is one of the few pthread + # functions on Solaris that doesn't have a non-functional libc stub. + # We try pthread_create on general principles. + AC_TRY_LINK([#include ], + [pthread_t th; pthread_join(th, 0); + pthread_attr_init(0); pthread_cleanup_push(0, 0); + pthread_create(0,0,0,0); pthread_cleanup_pop(0); ], + [acx_pthread_ok=yes]) + + LIBS="$save_LIBS" + CFLAGS="$save_CFLAGS" + + AC_MSG_RESULT($acx_pthread_ok) + if test "x$acx_pthread_ok" = xyes; then + break; + fi + + PTHREAD_LIBS="" + PTHREAD_CFLAGS="" +done +fi + +# Various other checks: +if test "x$acx_pthread_ok" = xyes; then + save_LIBS="$LIBS" + LIBS="$PTHREAD_LIBS $LIBS" + save_CFLAGS="$CFLAGS" + CFLAGS="$CFLAGS $PTHREAD_CFLAGS" + + # Detect AIX lossage: JOINABLE attribute is called UNDETACHED. + AC_MSG_CHECKING([for joinable pthread attribute]) + attr_name=unknown + for attr in PTHREAD_CREATE_JOINABLE PTHREAD_CREATE_UNDETACHED; do + AC_TRY_LINK([#include ], [int attr=$attr; return attr;], + [attr_name=$attr; break]) + done + AC_MSG_RESULT($attr_name) + if test "$attr_name" != PTHREAD_CREATE_JOINABLE; then + AC_DEFINE_UNQUOTED(PTHREAD_CREATE_JOINABLE, $attr_name, + [Define to necessary symbol if this constant + uses a non-standard name on your system.]) + fi + + AC_MSG_CHECKING([if more special flags are required for pthreads]) + flag=no + case "${host_cpu}-${host_os}" in + *-aix* | *-freebsd* | *-darwin*) flag="-D_THREAD_SAFE";; + *solaris* | *-osf* | *-hpux*) flag="-D_REENTRANT";; + esac + AC_MSG_RESULT(${flag}) + if test "x$flag" != xno; then + PTHREAD_CFLAGS="$flag $PTHREAD_CFLAGS" + fi + + LIBS="$save_LIBS" + CFLAGS="$save_CFLAGS" + # More AIX lossage: must compile with xlc_r or cc_r + if test x"$GCC" != xyes; then + AC_CHECK_PROGS(PTHREAD_CC, xlc_r cc_r, ${CC}) + else + PTHREAD_CC=$CC + fi + + # The next part tries to detect GCC inconsistency with -shared on some + # architectures and systems. The problem is that in certain + # configurations, when -shared is specified, GCC "forgets" to + # internally use various flags which are still necessary. + + AC_MSG_CHECKING([whether to check for GCC pthread/shared inconsistencies]) + check_inconsistencies=yes + case "${host_cpu}-${host_os}" in + *-darwin*) check_inconsistencies=no ;; + esac + if test x"$GCC" != xyes -o "x$check_inconsistencies" != xyes ; then + AC_MSG_RESULT([no]) + else + AC_MSG_RESULT([yes]) + + # In order not to create several levels of indentation, we test + # the value of "$ok" until we find out the cure or run out of + # ideas. + ok="no" + + # + # Prepare the flags + # + save_CFLAGS="$CFLAGS" + save_LIBS="$LIBS" + save_CC="$CC" + # Try with the flags determined by the earlier checks. + # + # -Wl,-z,defs forces link-time symbol resolution, so that the + # linking checks with -shared actually have any value + # + # FIXME: -fPIC is required for -shared on many architectures, + # so we specify it here, but the right way would probably be to + # properly detect whether it is actually required. + CFLAGS="-shared -fPIC -Wl,-z,defs $CFLAGS $PTHREAD_CFLAGS" + LIBS="$PTHREAD_LIBS $LIBS" + CC="$PTHREAD_CC" + + AC_MSG_CHECKING([whether -pthread is sufficient with -shared]) + AC_TRY_LINK([#include ], + [pthread_t th; pthread_join(th, 0); + pthread_attr_init(0); pthread_cleanup_push(0, 0); + pthread_create(0,0,0,0); pthread_cleanup_pop(0); ], + [ok=yes]) + + if test "x$ok" = xyes; then + AC_MSG_RESULT([yes]) + else + AC_MSG_RESULT([no]) + fi + + # + # Linux gcc on some architectures such as mips/mipsel forgets + # about -lpthread + # + if test x"$ok" = xno; then + AC_MSG_CHECKING([whether -lpthread fixes that]) + LIBS="-lpthread $PTHREAD_LIBS $save_LIBS" + AC_TRY_LINK([#include ], + [pthread_t th; pthread_join(th, 0); + pthread_attr_init(0); pthread_cleanup_push(0, 0); + pthread_create(0,0,0,0); pthread_cleanup_pop(0); ], + [ok=yes]) + + if test "x$ok" = xyes; then + AC_MSG_RESULT([yes]) + PTHREAD_LIBS="-lpthread $PTHREAD_LIBS" + else + AC_MSG_RESULT([no]) + fi + fi + # + # FreeBSD 4.10 gcc forgets to use -lc_r instead of -lc + # + if test x"$ok" = xno; then + AC_MSG_CHECKING([whether -lc_r fixes that]) + LIBS="-lc_r $PTHREAD_LIBS $save_LIBS" + AC_TRY_LINK([#include ], + [pthread_t th; pthread_join(th, 0); + pthread_attr_init(0); pthread_cleanup_push(0, 0); + pthread_create(0,0,0,0); pthread_cleanup_pop(0); ], + [ok=yes]) + + if test "x$ok" = xyes; then + AC_MSG_RESULT([yes]) + PTHREAD_LIBS="-lc_r $PTHREAD_LIBS" + else + AC_MSG_RESULT([no]) + fi + fi + if test x"$ok" = xno; then + # OK, we have run out of ideas + AC_MSG_WARN([Impossible to determine how to use pthreads with shared libraries]) + + # so it's not safe to assume that we may use pthreads + acx_pthread_ok=no + fi + + CFLAGS="$save_CFLAGS" + LIBS="$save_LIBS" + CC="$save_CC" + fi +else + PTHREAD_CC="$CC" +fi + +AC_SUBST(PTHREAD_LIBS) +AC_SUBST(PTHREAD_CFLAGS) +AC_SUBST(PTHREAD_CC) + +# Finally, execute ACTION-IF-FOUND/ACTION-IF-NOT-FOUND: +if test x"$acx_pthread_ok" = xyes; then + ifelse([$1],,AC_DEFINE(HAVE_PTHREAD,1,[Define if you have POSIX threads libraries and header files.]),[$1]) + : +else + acx_pthread_ok=no + $2 +fi +AC_LANG_RESTORE +])dnl ACX_PTHREAD +AC_DEFUN([AC_CHECK_DEFINE],[ +AS_VAR_PUSHDEF([ac_var],[ac_cv_defined_$1_$2])dnl +AC_CACHE_CHECK([for $1 in $2], ac_var, +AC_TRY_COMPILE([#include <$2>],[ + #ifdef $1 + int ok; + #else + choke me + #endif +],AS_VAR_SET(ac_var, yes),AS_VAR_SET(ac_var, no))) +AS_IF([test AS_VAR_GET(ac_var) != "no"], [$3], [$4])dnl +AS_VAR_POPDEF([ac_var])dnl +]) + +AC_DEFUN([ACX_LIBWRAP], [ +LIBWRAP_LIBS= +saved_LIBS="$LIBS" +LIBS="$LIBS -lwrap" +AC_MSG_CHECKING([for tcpwrap library and headers]) +AC_LINK_IFELSE( +AC_LANG_PROGRAM( +[#include +#include +int allow_severity = LOG_INFO; +int deny_severity = LOG_WARNING;], +[struct request_info *req; +return hosts_access (req);]), +[AC_DEFINE(HAVE_LIBWRAP, [], [Have tcpwrap?]) +LIBWRAP_LIBS="-lwrap" +AC_MSG_RESULT(yes)], +[AC_MSG_RESULT(no)]) +LIBS="$saved_LIBS" +]) + +AC_DEFUN([ACX_LIRC], [ +LIRC_CFLAGS= +LIRC_LIBS= +AC_CHECK_HEADER(lirc/lirc_client.h,[AC_CHECK_LIB(lirc_client,lirc_init,[HAVE_LIRC=1 +LIRC_LIBS=-llirc_client],HAVE_LIRC=0)],HAVE_LIRC=0) +]) diff --git a/src/pulse.c b/src/pulse.c index bb92bba..fcf8148 100644 --- a/src/pulse.c +++ b/src/pulse.c @@ -831,7 +831,8 @@ int driver_cache(ca_context *c, ca_proplist *proplist) { char *name = NULL; pa_sample_spec ss; ca_cache_control_t cache_control = CA_CACHE_CONTROL_NEVER; - struct outstanding out; + struct outstanding *out; + int ret; ca_return_val_if_fail(c, CA_ERROR_INVALID); ca_return_val_if_fail(proplist, CA_ERROR_INVALID); @@ -860,7 +861,7 @@ int driver_cache(ca_context *c, ca_proplist *proplist) { } if (!(name = ca_strdup(n))) { - ret = PA_ERROR_OOM; + ret = CA_ERROR_OOM; goto finish; } @@ -879,7 +880,7 @@ int driver_cache(ca_context *c, ca_proplist *proplist) { /* 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(out->file)]; ss.channels = ca_sound_file_get_nchannels(out->file); @@ -890,21 +891,20 @@ int driver_cache(ca_context *c, ca_proplist *proplist) { 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(out->stream, out); pa_stream_set_state_callback(out->stream, stream_state_cb, out); - pa_stream_set_write_callback(out->stream, stream_request_cb, out); + pa_stream_set_write_callback(out->stream, stream_write_cb, out); - if (pa_stream_connect_upload(s, ca_sound_file_get_size(out->file)) < 0) { + if (pa_stream_connect_upload(out->stream, ca_sound_file_get_size(out->file)) < 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 and uploaded */ if (state == PA_STREAM_TERMINATED) @@ -914,7 +914,7 @@ int driver_cache(ca_context *c, ca_proplist *proplist) { if (state == PA_STREAM_FAILED) { ret = translate_error(pa_context_errno(p->context)); pa_threaded_mainloop_unlock(p->mainloop); - goto fail; + goto finish; } pa_threaded_mainloop_wait(p->mainloop); diff --git a/src/read-sound-file.c b/src/read-sound-file.c index eb2acbd..b753e6f 100644 --- a/src/read-sound-file.c +++ b/src/read-sound-file.c @@ -68,7 +68,7 @@ int ca_sound_file_open(ca_sound_file **_f, const char *fn) { f->nchannels = ca_wav_get_nchannels(f->wav); f->rate = ca_wav_get_rate(f->wav); f->type = ca_wav_get_sample_type(f->wav); - *f = f; + *_f = f; return CA_SUCCESS; } @@ -83,7 +83,7 @@ int ca_sound_file_open(ca_sound_file **_f, const char *fn) { f->nchannels = ca_vorbis_get_nchannels(f->vorbis); f->rate = ca_vorbis_get_rate(f->vorbis); f->type = CA_SAMPLE_S16NE; - *f = f; + *_f = f; return CA_SUCCESS; } } @@ -100,9 +100,9 @@ void ca_sound_file_close(ca_sound_file *f) { ca_assert(f); if (f->wav) - ca_wav_free(f->wav); + ca_wav_close(f->wav); if (f->vorbis) - ca_vorbis_free(f->vorbis); + ca_vorbis_close(f->vorbis); ca_free(f); } @@ -132,10 +132,10 @@ int ca_sound_file_read_int16(ca_sound_file *f, int16_t *d, unsigned *n) { if (f->wav) return ca_wav_read_s16le(f->wav, d, n); else - return ca_vorbis_read_s16ne(f->wav, d, n); + return ca_vorbis_read_s16ne(f->vorbis, d, n); } -int ca_sound_file_read_uint8(ca_sound_file *fn, uint8_t *d, unsigned *n) { +int ca_sound_file_read_uint8(ca_sound_file *f, uint8_t *d, unsigned *n) { ca_return_val_if_fail(f, CA_ERROR_INVALID); ca_return_val_if_fail(d, CA_ERROR_INVALID); ca_return_val_if_fail(n, CA_ERROR_INVALID); @@ -145,6 +145,8 @@ int ca_sound_file_read_uint8(ca_sound_file *fn, uint8_t *d, unsigned *n) { if (f->wav) return ca_wav_read_u8(f->wav, d, n); + + return CA_ERROR_STATE; } int ca_sound_file_read_arbitrary(ca_sound_file *f, void *d, size_t *n) { @@ -168,7 +170,7 @@ int ca_sound_file_read_arbitrary(ca_sound_file *f, void *d, size_t *n) { break; } - case CA_SAMPLE_S16RE: { + case CA_SAMPLE_U8: { unsigned k; k = *n; diff --git a/src/read-vorbis.c b/src/read-vorbis.c index f54e271..34d33a0 100644 --- a/src/read-vorbis.c +++ b/src/read-vorbis.c @@ -27,8 +27,10 @@ #include #include +#include "canberra.h" #include "read-vorbis.h" #include "macro.h" +#include "malloc.h" #define FILE_SIZE_MAX (64U*1024U*1024U) @@ -43,13 +45,13 @@ static int convert_error(int or) { case OV_EBADLINK: case OV_EFAULT: case OV_EREAD: - case OV_EHOLE: + case OV_HOLE: return CA_ERROR_IO; case OV_EIMPL: case OV_EVERSION: - case OV_ENOTAUDIO - return CA_ERROR_NOT_SUPPORTED; + case OV_ENOTAUDIO: + return CA_ERROR_NOTSUPPORTED; case OV_ENOTVORBIS: case OV_EBADHEADER: @@ -60,7 +62,7 @@ static int convert_error(int or) { return CA_ERROR_INVALID; default: - return CA_ERROR_INTERNAL; + return CA_ERROR_IO; } } @@ -80,7 +82,7 @@ int ca_vorbis_open(ca_vorbis **_v, FILE *f) { goto fail; } - if ((n = ov_pcm_total(&ovf, -1)) < 0) { + if ((n = ov_pcm_total(&v->ovf, -1)) < 0) { ret = convert_error(or); ov_clear(&v->ovf); goto fail; @@ -110,33 +112,33 @@ void ca_vorbis_close(ca_vorbis *v) { } unsigned ca_vorbis_get_nchannels(ca_vorbis *v) { - vorbis_info *vi; + const vorbis_info *vi; ca_assert(v); - ca_assert_se(vi = ov_info(&vf, -1)); + ca_assert_se(vi = ov_info(&v->ovf, -1)); return vi->channels; } unsigned ca_vorbis_get_rate(ca_vorbis *v) { - vorbis_info *vi; + const vorbis_info *vi; ca_assert(v); - ca_assert_se(vi = ov_info(&vf, -1)); + ca_assert_se(vi = ov_info(&v->ovf, -1)); return (unsigned) vi->rate; } -int ca_vorbis_read_int16ne(ca_vorbis *v, int16_t *d, unsigned *n){ +int ca_vorbis_read_s16ne(ca_vorbis *v, int16_t *d, unsigned *n){ long r; int section; - ca_return_val_if_fail(w, CA_ERROR_INVALID); + ca_return_val_if_fail(v, CA_ERROR_INVALID); ca_return_val_if_fail(d, CA_ERROR_INVALID); ca_return_val_if_fail(n, CA_ERROR_INVALID); ca_return_val_if_fail(*n > 0, CA_ERROR_INVALID); - r = ov_read(&v->ovf, d, *n * sizeof(float), + r = ov_read(&v->ovf, (char*) d, *n * sizeof(float), #ifdef WORDS_BIGENDIAN 1, #else @@ -145,7 +147,7 @@ int ca_vorbis_read_int16ne(ca_vorbis *v, int16_t *d, unsigned *n){ 2, 1, §ion); if (r < 0) - return convert_error(or); + return convert_error(r); /* We only read the first section */ if (section != 0) diff --git a/src/read-vorbis.h b/src/read-vorbis.h index d9b5ade..ebf7df3 100644 --- a/src/read-vorbis.h +++ b/src/read-vorbis.h @@ -28,7 +28,7 @@ typedef struct ca_vorbis ca_vorbis; -int ca_vorbis_open(ca_vorbis *v, FILE *f); +int ca_vorbis_open(ca_vorbis **v, FILE *f); void ca_vorbis_close(ca_vorbis *v); unsigned ca_vorbis_get_nchannels(ca_vorbis *v); diff --git a/src/read-wav.c b/src/read-wav.c index e96e8ae..8c64c0a 100644 --- a/src/read-wav.c +++ b/src/read-wav.c @@ -24,8 +24,10 @@ #include #endif +#include "canberra.h" #include "read-wav.h" #include "macro.h" +#include "malloc.h" #define FILE_SIZE_MAX (64U*1024U*1024U) @@ -38,16 +40,16 @@ struct ca_wav { unsigned depth; }; -static int skip_to_chunk(ca_wav *v, uint32_t id, uint32_t *size) { +static int skip_to_chunk(ca_wav *w, uint32_t id, uint32_t *size) { - ca_return_val_if_fail(v, CA_ERROR_INVALID); + ca_return_val_if_fail(w, CA_ERROR_INVALID); ca_return_val_if_fail(size, CA_ERROR_INVALID); for (;;) { uint32_t chunk[2]; size_t s; - if (fread(chunk, sizeof(uint32), CA_ELEMENTSOF(chunk), w->file) != CA_ELEMENTSOF(chunk)) + if (fread(chunk, sizeof(uint32_t), CA_ELEMENTSOF(chunk), w->file) != CA_ELEMENTSOF(chunk)) goto fail_io; s = PA_UINT32_FROM_LE(chunk[1]); @@ -68,9 +70,9 @@ static int skip_to_chunk(ca_wav *v, uint32_t id, uint32_t *size) { fail_io: - if (feof(f)) + if (feof(w->file)) return CA_ERROR_CORRUPT; - else if (ferror(f)) + else if (ferror(w->file)) return CA_ERROR_SYSTEM; ca_assert_not_reached(); @@ -80,7 +82,7 @@ int ca_wav_open(ca_wav **_w, FILE *f) { uint32_t header[3], fmt_chunk[4]; int ret; ca_wav *w; - uint32_t file_size, fmt_size, data_size; + uint32_t file_size, fmt_size; ca_return_val_if_fail(_w, CA_ERROR_INVALID); ca_return_val_if_fail(f, CA_ERROR_INVALID); @@ -88,9 +90,9 @@ int ca_wav_open(ca_wav **_w, FILE *f) { if (!(w = ca_new(ca_wav, 1))) return CA_ERROR_OOM; - v->file = f; + w->file = f; - if (fread(header, sizeof(uint32), CA_ELEMENTSOF(header), f) != CA_ELEMENTSOF(header)) + if (fread(header, sizeof(uint32_t), CA_ELEMENTSOF(header), f) != CA_ELEMENTSOF(header)) goto fail_io; if (PA_UINT32_FROM_LE(header[0]) != 0x46464952U || @@ -111,15 +113,15 @@ int ca_wav_open(ca_wav **_w, FILE *f) { goto fail; if (fmt_size != 16) { - ret = CA_ERROR_NOT_SUPPORTED; + ret = CA_ERROR_NOTSUPPORTED; goto fail; } - if (fread(fmt_chunk, sizeof(uint32), CA_ELEMENTSOF(fmt_chunk), f) != CA_ELEMENTSOF(fmt_chunk)) + if (fread(fmt_chunk, sizeof(uint32_t), CA_ELEMENTSOF(fmt_chunk), f) != CA_ELEMENTSOF(fmt_chunk)) goto fail_io; - if (PA_UINT32_FROM_LE(fmt_chunk[0]) & 0xFFFF != 1) { - ret = CA_ERROR_NOT_SUPPORTED; + if ((PA_UINT32_FROM_LE(fmt_chunk[0]) & 0xFFFF) != 1) { + ret = CA_ERROR_NOTSUPPORTED; goto fail; } @@ -127,13 +129,13 @@ int ca_wav_open(ca_wav **_w, FILE *f) { w->rate = PA_UINT32_FROM_LE(fmt_chunk[1]); w->depth = PA_UINT32_FROM_LE(fmt_chunk[3]) >> 16; - if (w->nchannels <= 0 || w->nrate <= 0) { + if (w->nchannels <= 0 || w->rate <= 0) { ret = CA_ERROR_CORRUPT; goto fail; } if (w->depth != 16 && w->depth != 8) { - ret = CA_ERROR_NOT_SUPPORTED; + ret = CA_ERROR_NOTSUPPORTED; goto fail; } @@ -148,7 +150,7 @@ int ca_wav_open(ca_wav **_w, FILE *f) { *_w = w; - return PA_SUCCESS; + return CA_SUCCESS; fail_io: @@ -185,7 +187,7 @@ unsigned ca_wav_get_rate(ca_wav *w) { return w->rate; } -ca_sample_type_t ca_wav_get_sample_type(ca_wav *f) { +ca_sample_type_t ca_wav_get_sample_type(ca_wav *w) { ca_assert(w); return w->depth == 16 ? @@ -224,7 +226,7 @@ int ca_wav_read_s16le(ca_wav *w, int16_t *d, unsigned *n) { return CA_SUCCESS; } -int ca_wav_read_u(ca_wav *w, uint8_t *d, unsigned *n) { +int ca_wav_read_u8(ca_wav *w, uint8_t *d, unsigned *n) { unsigned remaining; ca_return_val_if_fail(w, CA_ERROR_INVALID); diff --git a/src/sound-theme-spec.c b/src/sound-theme-spec.c index 11f15d8..274fe26 100644 --- a/src/sound-theme-spec.c +++ b/src/sound-theme-spec.c @@ -24,7 +24,10 @@ #include #endif +#include + #include "sound-theme-spec.h" +#include "malloc.h" #include "llist.h" #define DEFAULT_THEME "freedesktop" @@ -45,7 +48,7 @@ struct ca_theme_data { char *name; CA_LLIST_HEAD(ca_data_dir, data_dirs); - ca_theme_dir *last_dir; + ca_data_dir *last_dir; unsigned n_theme_dir; ca_bool_t loaded_fallback_theme; @@ -76,11 +79,11 @@ static int get_data_home(char **e) { static ca_bool_t data_dir_matches(ca_data_dir *d, const char*output_profile) { ca_assert(d); - ca_assert(profile); + ca_assert(output_profile); /* We might want to add more elaborate matching here eventually */ - return streq(d->profile, output_profile); + return streq(d->output_profile, output_profile); } static ca_data_dir* find_data_dir(ca_theme_data *t, const char *name) { @@ -103,7 +106,7 @@ static int add_data_dir(ca_theme_data *t, const char *name) { ca_return_val_if_fail(name, CA_ERROR_INVALID); if (find_data_dir(t, name)) - return; + return CA_SUCCESS; if (!(d = ca_new0(ca_data_dir, 1))) return CA_ERROR_OOM; @@ -146,7 +149,7 @@ static int load_theme_path(ca_theme_data *t, const char *prefix, const char *nam for (;;) { char ln[1024]; - if (!(fgets(ln, f))) { + if (!(fgets(ln, sizeof(ln), f))) { if (feof(f)) break; -- cgit