summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/Makefile.am3
-rw-r--r--src/canberra.h1
-rw-r--r--src/malloc.c62
-rw-r--r--src/malloc.h4
-rw-r--r--src/read-sound-file.c9
-rw-r--r--src/read-vorbis.c9
-rw-r--r--src/read-vorbis.h2
-rw-r--r--src/read-wav.c6
-rw-r--r--src/read-wav.h2
-rw-r--r--src/sound-theme-spec.c74
-rw-r--r--src/test-canberra.c7
11 files changed, 143 insertions, 36 deletions
diff --git a/src/Makefile.am b/src/Makefile.am
index 281738e..af94f1b 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -20,7 +20,6 @@
AM_CFLAGS = $(PTHREAD_CFLAGS)
AM_CXXFLAGS = $(PTHREAD_CFLAGS)
-AM_LIBADD = $(PTHREAD_LIBS)
AM_LDADD = $(PTHREAD_LIBS)
lib_LTLIBRARIES = \
@@ -42,7 +41,7 @@ libcanberra_la_SOURCES = \
sound-theme-spec.c sound-theme-spec.h \
llist.h \
macro.h \
- malloc.h
+ malloc.c malloc.h
libcanberra_la_LIBADD = \
$(PULSE_LIBS) \
$(VORBIS_LIBS)
diff --git a/src/canberra.h b/src/canberra.h
index e8241f5..f964f3a 100644
--- a/src/canberra.h
+++ b/src/canberra.h
@@ -92,6 +92,7 @@
#define CA_PROP_MEDIA_ICON_NAME "media.icon_name"
#define CA_PROP_MEDIA_ROLE "media.role"
#define CA_PROP_EVENT_ID "event.id"
+#define CA_PROP_EVENT_DESCRIPTION "event.description"
#define CA_PROP_EVENT_MOUSE_X "event.mouse.x"
#define CA_PROP_EVENT_MOUSE_Y "event.mouse.y"
#define CA_PROP_EVENT_MOUSE_BUTTON "event.mouse.button"
diff --git a/src/malloc.c b/src/malloc.c
new file mode 100644
index 0000000..105b392
--- /dev/null
+++ b/src/malloc.c
@@ -0,0 +1,62 @@
+/* $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/>.
+***/
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <stdio.h>
+#include <stdarg.h>
+
+#include "malloc.h"
+#include "macro.h"
+
+char *ca_sprintf_malloc(const char *format, ...) {
+ int size = 100;
+ char *c = NULL;
+
+ ca_assert(format);
+
+ for(;;) {
+ int r;
+ va_list ap;
+
+ ca_free(c);
+
+ if (!(c = ca_new(char, size)))
+ return NULL;
+
+ va_start(ap, format);
+ r = vsnprintf(c, size, format, ap);
+ va_end(ap);
+
+ c[size-1] = 0;
+
+ if (r > -1 && r < size)
+ return c;
+
+ if (r > -1) /* glibc 2.1 */
+ size = r+1;
+ else /* glibc 2.0 */
+ size *= 2;
+ }
+}
diff --git a/src/malloc.h b/src/malloc.h
index b720a12..f8c1ba1 100644
--- a/src/malloc.h
+++ b/src/malloc.h
@@ -1,4 +1,4 @@
-#ifndef foosydneymallochfoo
+#ifndef foocanberramallochfoo
#define foocanberramallochfoo
/* $Id$ */
@@ -38,4 +38,6 @@ void* ca_memdup(const void* p, size_t size);
#define ca_new0(t, n) ((t*) ca_malloc0(sizeof(t)*(n)))
#define ca_newdup(t, p, n) ((t*) ca_memdup(p, sizeof(t)*(n)))
+char *ca_sprintf_malloc(const char *format, ...);
+
#endif
diff --git a/src/read-sound-file.c b/src/read-sound-file.c
index b753e6f..a0e24fc 100644
--- a/src/read-sound-file.c
+++ b/src/read-sound-file.c
@@ -186,3 +186,12 @@ int ca_sound_file_read_arbitrary(ca_sound_file *f, void *d, size_t *n) {
return ret;
}
+
+size_t ca_sound_file_get_size(ca_sound_file *f) {
+ ca_return_val_if_fail(f, CA_ERROR_INVALID);
+
+ if (f->wav)
+ return ca_wav_get_size(f->wav);
+ else
+ return ca_vorbis_get_size(f->vorbis);
+}
diff --git a/src/read-vorbis.c b/src/read-vorbis.c
index 34d33a0..e61defc 100644
--- a/src/read-vorbis.c
+++ b/src/read-vorbis.c
@@ -36,6 +36,7 @@
struct ca_vorbis {
OggVorbis_File ovf;
+ size_t size;
};
static int convert_error(int or) {
@@ -94,6 +95,8 @@ int ca_vorbis_open(ca_vorbis **_v, FILE *f) {
goto fail;
}
+ v->size = n * sizeof(int16_t);
+
*_v = v;
return CA_SUCCESS;
@@ -156,3 +159,9 @@ int ca_vorbis_read_s16ne(ca_vorbis *v, int16_t *d, unsigned *n){
*n = (unsigned) r;
return CA_SUCCESS;
}
+
+size_t ca_vorbis_get_size(ca_vorbis *v) {
+ ca_return_val_if_fail(v, CA_ERROR_INVALID);
+
+ return v->size;
+}
diff --git a/src/read-vorbis.h b/src/read-vorbis.h
index ebf7df3..e23c1cc 100644
--- a/src/read-vorbis.h
+++ b/src/read-vorbis.h
@@ -36,4 +36,6 @@ unsigned ca_vorbis_get_rate(ca_vorbis *v);
int ca_vorbis_read_s16ne(ca_vorbis *v, int16_t *d, unsigned *n);
+size_t ca_vorbis_get_size(ca_vorbis *f);
+
#endif
diff --git a/src/read-wav.c b/src/read-wav.c
index 8c64c0a..a9739ff 100644
--- a/src/read-wav.c
+++ b/src/read-wav.c
@@ -252,3 +252,9 @@ int ca_wav_read_u8(ca_wav *w, uint8_t *d, unsigned *n) {
return CA_SUCCESS;
}
+
+size_t ca_wav_get_size(ca_wav *v) {
+ ca_return_val_if_fail(v, CA_ERROR_INVALID);
+
+ return v->data_size;
+}
diff --git a/src/read-wav.h b/src/read-wav.h
index ae7b8eb..4287ee1 100644
--- a/src/read-wav.h
+++ b/src/read-wav.h
@@ -39,4 +39,6 @@ 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);
+size_t ca_wav_get_size(ca_wav *f);
+
#endif
diff --git a/src/sound-theme-spec.c b/src/sound-theme-spec.c
index 274fe26..8063591 100644
--- a/src/sound-theme-spec.c
+++ b/src/sound-theme-spec.c
@@ -25,6 +25,7 @@
#endif
#include <errno.h>
+#include <locale.h>
#include "sound-theme-spec.h"
#include "malloc.h"
@@ -122,11 +123,14 @@ static int add_data_dir(ca_theme_data *t, const char *name) {
return CA_SUCCESS;
}
+static int load_theme_dir(ca_theme_data *t, const char *name);
+
static int load_theme_path(ca_theme_data *t, const char *prefix, const char *name) {
char *fn, *inherits = NULL;
FILE *f;
ca_bool_t in_sound_theme_section = FALSE;
ca_data_dir *current_data_dir = NULL;
+ int ret;
ca_return_val_if_fail(t, CA_ERROR_INVALID);
ca_return_val_if_fail(prefix, CA_ERROR_INVALID);
@@ -178,7 +182,7 @@ static int load_theme_path(ca_theme_data *t, const char *prefix, const char *nam
goto fail;
}
- current_data_dir = find_data_dir(e, d);
+ current_data_dir = find_data_dir(t, d);
ca_free(d);
in_sound_theme_section = FALSE;
@@ -230,7 +234,7 @@ static int load_theme_path(ca_theme_data *t, const char *prefix, const char *nam
if (d[k] == 0)
break;
- = k+1;
+ d += k+1;
}
continue;
@@ -259,7 +263,7 @@ static int load_theme_path(ca_theme_data *t, const char *prefix, const char *nam
t->n_theme_dir ++;
if (inherits) {
- i = inherits;
+ char *i = inherits;
for (;;) {
size_t k = strcspn(i, ", ");
@@ -281,7 +285,7 @@ static int load_theme_path(ca_theme_data *t, const char *prefix, const char *nam
if (i[k] == 0)
break;
- i = k+1;
+ i += k+1;
}
}
@@ -290,13 +294,16 @@ static int load_theme_path(ca_theme_data *t, const char *prefix, const char *nam
fail:
ca_free(inherits);
- ca_free(directories);
fclose(f);
return ret;
}
static int load_theme_dir(ca_theme_data *t, const char *name) {
+ int ret;
+ char *e;
+ const char *g;
+
ca_return_val_if_fail(t, CA_ERROR_INVALID);
ca_return_val_if_fail(name, CA_ERROR_INVALID);
ca_return_val_if_fail(t->n_theme_dir < N_THEME_DIR_MAX, CA_ERROR_CORRUPT);
@@ -315,18 +322,18 @@ static int load_theme_dir(ca_theme_data *t, const char *name) {
return ret;
}
- if (!(e = getenv("XDG_DATA_DIRS")) || *e = 0)
- e = "/usr/local/share:/usr/share";
+ if (!(g = getenv("XDG_DATA_DIRS")) || *g == 0)
+ g = "/usr/local/share:/usr/share";
for (;;) {
size_t k;
- k = strcspn(e, ":");
+ k = strcspn(g, ":");
- if (e[0] == '/' && k > 0) {
+ if (g[0] == '/' && k > 0) {
char *p;
- if (!(p = ca_strndup(e, k)))
+ if (!(p = ca_strndup(g, k)))
return CA_ERROR_OOM;
ret = load_theme_path(t, p, name);
@@ -336,10 +343,10 @@ static int load_theme_dir(ca_theme_data *t, const char *name) {
return ret;
}
- if (e[k] == 0)
+ if (g[k] == 0)
break;
- e += k+1;
+ g += k+1;
}
return CA_ERROR_NOTFOUND;
@@ -356,7 +363,7 @@ static int load_theme_data(ca_theme_data **_t, const char *name) {
if (streq((*_t)->name, name))
return CA_SUCCESS;
- if (!(t = pa_xnew0(ca_theme_data, 1)))
+ if (!(t = ca_new0(ca_theme_data, 1)))
return CA_ERROR_OOM;
if (!(t->name = ca_strdup(name))) {
@@ -387,7 +394,8 @@ fail:
}
static int find_sound_for_suffix(ca_sound_file **f, ca_theme_data *t, const char *name, const char *path, const char *suffix, const char *locale, const char *subdir) {
- const char *fn;
+ char *fn;
+ int ret;
ca_return_val_if_fail(f, CA_ERROR_INVALID);
ca_return_val_if_fail(name, CA_ERROR_INVALID);
@@ -399,7 +407,7 @@ static int find_sound_for_suffix(ca_sound_file **f, ca_theme_data *t, const char
path,
t ? "/" : "",
t ? t->name : "",
- subdir ? "/" : ""
+ subdir ? "/" : "",
subdir ? subdir : "",
locale ? "/" : "",
locale ? locale : "",
@@ -414,6 +422,7 @@ static int find_sound_for_suffix(ca_sound_file **f, ca_theme_data *t, const char
static int find_sound_in_path(ca_sound_file **f, ca_theme_data *t, const char *name, const char *path, const char *locale, const char *subdir) {
int ret;
+ char *p;
ca_return_val_if_fail(f, CA_ERROR_INVALID);
ca_return_val_if_fail(name, CA_ERROR_INVALID);
@@ -436,6 +445,8 @@ static int find_sound_in_path(ca_sound_file **f, ca_theme_data *t, const char *n
static int find_sound_in_subdir(ca_sound_file **f, ca_theme_data *t, const char *name, const char *locale, const char *subdir) {
int ret;
char *e = NULL;
+ const char *g;
+
ca_return_val_if_fail(f, CA_ERROR_INVALID);
ca_return_val_if_fail(name, CA_ERROR_INVALID);
@@ -450,18 +461,18 @@ static int find_sound_in_subdir(ca_sound_file **f, ca_theme_data *t, const char
return ret;
}
- if (!(e = getenv("XDG_DATA_DIRS")) || *e = 0)
- e = "/usr/local/share:/usr/share";
+ if (!(g = getenv("XDG_DATA_DIRS")) || *g == 0)
+ g = "/usr/local/share:/usr/share";
for (;;) {
size_t k;
- k = strcspn(e, ":");
+ k = strcspn(g, ":");
- if (e[0] == '/' && k > 0) {
+ if (g[0] == '/' && k > 0) {
char *p;
- if (!(p = ca_strndup(e, k)))
+ if (!(p = ca_strndup(g, k)))
return CA_ERROR_OOM;
ret = find_sound_in_path(f, t, name, p, locale, subdir);
@@ -471,10 +482,10 @@ static int find_sound_in_subdir(ca_sound_file **f, ca_theme_data *t, const char
return ret;
}
- if (e[k] == 0)
+ if (g[k] == 0)
break;
- e += k+1;
+ g += k+1;
}
return CA_ERROR_NOTFOUND;
@@ -501,6 +512,8 @@ static int find_sound_for_profile(ca_sound_file **f, ca_theme_data *t, const cha
}
static int find_sound_in_locale(ca_sound_file **f, ca_theme_data *t, const char *name, const char *locale, const char *profile) {
+ int ret;
+
ca_return_val_if_fail(f, CA_ERROR_INVALID);
ca_return_val_if_fail(name, CA_ERROR_INVALID);
ca_return_val_if_fail(profile, CA_ERROR_INVALID);
@@ -511,7 +524,7 @@ static int find_sound_in_locale(ca_sound_file **f, ca_theme_data *t, const char
/* Then, fall back to stereo */
if (!streq(profile, DEFAULT_OUTPUT_PROFILE))
- if ((ret = find_sound_for_profile(f, t, name, locale, DEFAULT_PROFILE)) != CA_ERROR_NOTFOUND)
+ if ((ret = find_sound_for_profile(f, t, name, locale, DEFAULT_OUTPUT_PROFILE)) != CA_ERROR_NOTFOUND)
return ret;
/* And fall back to no profile */
@@ -520,6 +533,7 @@ static int find_sound_in_locale(ca_sound_file **f, ca_theme_data *t, const char
static int find_sound_for_locale(ca_sound_file **f, ca_theme_data *theme, const char *name, const char *locale, const char *profile) {
const char *e;
+ int ret;
ca_return_val_if_fail(f, CA_ERROR_INVALID);
ca_return_val_if_fail(name, CA_ERROR_INVALID);
@@ -579,11 +593,11 @@ static int find_sound_for_theme(ca_sound_file **f, ca_theme_data **t, const char
/* First, try in the theme itself */
if ((ret = load_theme_data(t, theme)) == CA_SUCCESS)
- if ((ret = find_sound_in_theme(f, t, name, locale, profile)) != CA_ERROR_NOTFOUND)
+ if ((ret = find_sound_for_locale(f, *t, name, locale, profile)) != CA_ERROR_NOTFOUND)
return ret;
/* Then, fall back to "unthemed" files */
- return find_sound_in_theme(f, NULL, name, locale, profile);
+ return find_sound_for_locale(f, NULL, name, locale, profile);
}
int ca_lookup_sound(ca_sound_file **f, ca_theme_data **t, ca_proplist *p) {
@@ -596,22 +610,22 @@ int ca_lookup_sound(ca_sound_file **f, ca_theme_data **t, ca_proplist *p) {
ca_mutex_lock(p->mutex);
- if ((name = ca_proplist_gets(p, CA_PROP_EVENT_ID))) {
+ if ((name = ca_proplist_gets_unlocked(p, CA_PROP_EVENT_ID))) {
const char *theme, *locale, *profile;
- if (!(theme = ca_proplist_gets(p, CA_PROP_CANBERRA_XDG_THEME_NAME)))
+ if (!(theme = ca_proplist_gets_unlocked(p, CA_PROP_CANBERRA_XDG_THEME_NAME)))
theme = DEFAULT_THEME;
- if (!(locale = ca_proplist_gets(p, CA_PROP_APPLICATION_LANGUAGE)))
+ if (!(locale = ca_proplist_gets_unlocked(p, CA_PROP_APPLICATION_LANGUAGE)))
if (!(locale = setlocale(LC_MESSAGES, NULL)))
locale = "C";
- if (!(profile = ca_proplist_gets(p, CA_PROP_CANBERRA_XDG_THEME_OUTPUT_PROFILE)))
+ if (!(profile = ca_proplist_gets_unlocked(p, CA_PROP_CANBERRA_XDG_THEME_OUTPUT_PROFILE)))
profile = DEFAULT_OUTPUT_PROFILE;
ret = find_sound_for_theme(f, t, theme, name, locale, profile);
- } else if ((fname = ca_proplist_gets(p, CA_PROP_MEDIA_FILENAME)))
+ } else if ((fname = ca_proplist_gets_unlocked(p, CA_PROP_MEDIA_FILENAME)))
ret = ca_sound_file_open(f, fname);
else
ret = CA_ERROR_INVALID;
diff --git a/src/test-canberra.c b/src/test-canberra.c
index 4a379a3..f423ffd 100644
--- a/src/test-canberra.c
+++ b/src/test-canberra.c
@@ -26,15 +26,16 @@
#endif
#include <unistd.h>
+#include <stdlib.h>
#include "canberra.h"
int main(int argc, char *argv[]) {
- ca_context_t *c;
+ ca_context *c;
int id = 4711;
- ca_context_new(&c);
+ ca_context_create(&c);
/* Initialize a few meta variables for the following play()
* calls. They stay valid until they are overwritten with
@@ -43,7 +44,7 @@ int main(int argc, char *argv[]) {
CA_PROP_APPLICATION_NAME, "An example",
CA_PROP_APPLICATION_ID, "org.freedesktop.libcanberra.Test",
CA_PROP_MEDIA_LANGUAGE, "de_DE",
- CA_PROP_EVENT_X11_DISPLAY, getenv("DISPLAY"),
+ CA_PROP_WINDOW_X11_DISPLAY, getenv("DISPLAY"),
NULL);
/* .. */