From f9cdbbad89aed30df636235a6407503b5e955d4b Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Tue, 27 May 2008 19:19:59 +0000 Subject: fix a few memleaks and make things work git-svn-id: file:///home/lennart/svn/public/libcanberra/trunk@26 01b60673-d06a-42c0-afdd-89cb8e0f78ac --- src/pulse.c | 73 +++++++++++++++++++++++++++++--------------------- src/sound-theme-spec.c | 18 ++++++------- src/test-canberra.c | 42 ++++++++++++++++------------- todo | 6 +++++ 4 files changed, 82 insertions(+), 57 deletions(-) diff --git a/src/pulse.c b/src/pulse.c index a094167..2c9f1cd 100644 --- a/src/pulse.c +++ b/src/pulse.c @@ -85,6 +85,8 @@ static void outstanding_free(struct outstanding *o) { ca_sound_file_close(o->file); if (o->stream) { + pa_stream_set_write_callback(o->stream, NULL, NULL); + pa_stream_set_state_callback(o->stream, NULL, NULL); pa_stream_disconnect(o->stream); pa_stream_unref(o->stream); } @@ -329,6 +331,11 @@ int driver_destroy(ca_context *c) { if (p->mainloop) pa_threaded_mainloop_stop(p->mainloop); + if (p->context) { + pa_context_disconnect(p->context); + pa_context_unref(p->context); + } + while (p->outstanding) { struct outstanding *out = p->outstanding; CA_LLIST_REMOVE(struct outstanding, p->outstanding, out); @@ -338,11 +345,6 @@ int driver_destroy(ca_context *c) { outstanding_free(out); } - if (p->context) { - pa_context_disconnect(p->context); - pa_context_unref(p->context); - } - if (p->mainloop) pa_threaded_mainloop_free(p->mainloop); @@ -526,44 +528,55 @@ 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; - goto finish; - } - - if ((ret = ca_sound_file_read_arbitrary(out->file, data, &bytes)) < 0) - goto finish; - - if (bytes > 0) { + while (bytes > 0) { + size_t rbytes = bytes; - if ((ret = pa_stream_write(s, data, bytes, free, 0, PA_SEEK_RELATIVE)) < 0) { - ret = translate_error(ret); + if (!(data = ca_malloc(rbytes))) { + ret = CA_ERROR_OOM; goto finish; } - } else { - /* We reached EOF */ + if ((ret = ca_sound_file_read_arbitrary(out->file, data, &rbytes)) < 0) + goto finish; - if (out->type == OUTSTANDING_UPLOAD) { + if (rbytes > 0) { + ca_assert(rbytes <= bytes); - if (pa_stream_finish_upload(s) < 0) { - ret = translate_error(pa_context_errno(p->context)); + if ((ret = pa_stream_write(s, data, rbytes, free, 0, PA_SEEK_RELATIVE)) < 0) { + ret = translate_error(ret); goto finish; } - /* Let's just signal driver_cache() which has been waiting for us */ - pa_threaded_mainloop_signal(p->mainloop, FALSE); + bytes -= rbytes; } else { - pa_operation *o; - ca_assert(out->type = OUTSTANDING_STREAM); + /* We reached EOF */ - if (!(o = pa_stream_drain(s, stream_drain_cb, out))) { - ret = translate_error(pa_context_errno(p->context)); - goto finish; + if (out->type == OUTSTANDING_UPLOAD) { + + if (pa_stream_finish_upload(s) < 0) { + ret = translate_error(pa_context_errno(p->context)); + goto finish; + } + + /* Let's just signal driver_cache() which has been waiting for us */ + pa_threaded_mainloop_signal(p->mainloop, FALSE); + + } else { + pa_operation *o; + ca_assert(out->type == OUTSTANDING_STREAM); + + if (!(o = pa_stream_drain(s, stream_drain_cb, out))) { + ret = translate_error(pa_context_errno(p->context)); + goto finish; + } + + pa_operation_unref(o); } - pa_operation_unref(o); + pa_stream_set_write_callback(s, NULL, NULL); + + break; } } @@ -709,7 +722,7 @@ int driver_play(ca_context *c, uint32_t id, ca_proplist *proplist, ca_finish_cal if ((ret = ca_lookup_sound(&out->file, &p->theme, c->props, proplist)) < 0) goto finish; - ss.channels = sample_type_table[ca_sound_file_get_sample_type(out->file)]; + ss.format = 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); diff --git a/src/sound-theme-spec.c b/src/sound-theme-spec.c index 10dd70a..5ed602b 100644 --- a/src/sound-theme-spec.c +++ b/src/sound-theme-spec.c @@ -136,7 +136,7 @@ static int load_theme_path(ca_theme_data *t, const char *prefix, const char *nam ca_return_val_if_fail(prefix, CA_ERROR_INVALID); ca_return_val_if_fail(name, CA_ERROR_INVALID); - if (!(fn = ca_new(char, strlen(prefix) + sizeof("/sounds/")-1 + strlen(name) + sizeof("index.theme")))) + if (!(fn = ca_new(char, strlen(prefix) + sizeof("/sounds/")-1 + strlen(name) + sizeof("/index.theme")))) return CA_ERROR_OOM; sprintf(fn, "%s/sounds/%s/index.theme", prefix, name); @@ -174,7 +174,7 @@ static int load_theme_path(ca_theme_data *t, const char *prefix, const char *nam continue; } - if (ln[0] == '[' && ln[strlen(ln-1)] == ']') { + if (ln[0] == '[' && ln[strlen(ln)-1] == ']') { char *d; if (!(d = ca_strndup(ln+1, strlen(ln)-2))) { @@ -194,14 +194,14 @@ static int load_theme_path(ca_theme_data *t, const char *prefix, const char *nam if (in_sound_theme_section) { - if (!strncmp(ln, "Inherits", 8)) { + if (!strncmp(ln, "Inherits=", 9)) { if (inherits) { ret = CA_ERROR_CORRUPT; goto fail; } - if (!(inherits = ca_strdup(ln + 8))) { + if (!(inherits = ca_strdup(ln + 9))) { ret = CA_ERROR_OOM; goto fail; } @@ -209,10 +209,10 @@ static int load_theme_path(ca_theme_data *t, const char *prefix, const char *nam continue; } - if (!strncmp(ln, "Directories", 11)) { + if (!strncmp(ln, "Directories=", 12)) { char *d; - d = ln+11; + d = ln+12; for (;;) { size_t k = strcspn(d, ", "); @@ -243,14 +243,14 @@ static int load_theme_path(ca_theme_data *t, const char *prefix, const char *nam if (current_data_dir) { - if (!strncmp(ln, "OutputProfile", 13)) { + if (!strncmp(ln, "OutputProfile=", 14)) { - if (current_data_dir->output_profile && !streq(current_data_dir->output_profile, ln+13)) { + if (current_data_dir->output_profile && !streq(current_data_dir->output_profile, ln+14)) { ret = CA_ERROR_CORRUPT; goto fail; } - if (!(current_data_dir->output_profile = ca_strdup(ln+13))) { + if (!(current_data_dir->output_profile = ca_strdup(ln+14))) { ret = CA_ERROR_OOM; goto fail; } diff --git a/src/test-canberra.c b/src/test-canberra.c index b153ee6..b54cba0 100644 --- a/src/test-canberra.c +++ b/src/test-canberra.c @@ -28,14 +28,13 @@ #include #include #include +#include #include "canberra.h" int main(int argc, char *argv[]) { ca_context *c; - int id = 4711; - setlocale(LC_ALL, ""); ca_context_create(&c); @@ -54,31 +53,38 @@ int main(int argc, char *argv[]) { ca_context_open(c); + fprintf(stderr, "Play ...\n"); + /* Signal a sound event. The meta data passed here overwrites the * data set in any previous ca_context_set() calls. */ - ca_context_play(c, id, - CA_PROP_EVENT_ID, "click-event", - CA_PROP_MEDIA_FILENAME, "/usr/share/sounds/foo.wav", - CA_PROP_MEDIA_NAME, "Button has been clicked", - CA_PROP_MEDIA_LANGUAGE, "de_DE@euro", - CA_PROP_MEDIA_ICON_NAME, "clicked", - NULL); +/* ca_context_play(c, 0, */ +/* CA_PROP_EVENT_ID, "desktop-logout", */ +/* CA_PROP_MEDIA_FILENAME, "/usr/share/sounds/bar.wav", */ +/* CA_PROP_MEDIA_NAME, "User has logged off from session", */ +/* CA_PROP_MEDIA_LANGUAGE, "en_EN", */ +/* NULL); */ /* .. */ - ca_context_play(c, id, - CA_PROP_EVENT_ID, "logout", - CA_PROP_MEDIA_FILENAME, "/usr/share/sounds/bar.wav", - CA_PROP_MEDIA_NAME, "User has logged of from session", - CA_PROP_MEDIA_LANGUAGE, "en_EN", - NULL); + ca_context_play(c, 1, + CA_PROP_EVENT_ID, "email-message-new", + CA_PROP_MEDIA_FILENAME, "/usr/share/sounds/uxknkurz.wav", + CA_PROP_MEDIA_NAME, "New email received", + CA_PROP_CANBERRA_CACHE_CONTROL, "permanent", + NULL); /* .. */ - sleep(1); + fprintf(stderr, "Sleep half a second ...\n"); + usleep(500000); + + + fprintf(stderr, "Cancel ...\n"); + /* Stop one sounds */ + ca_context_cancel(c, 0); - /* Stops both sounds */ - ca_context_cancel(c, id); + fprintf(stderr, "Sleep 2s ...\n"); + sleep(2); /* .. */ diff --git a/todo b/todo index 7c77f88..25980f5 100644 --- a/todo +++ b/todo @@ -2,3 +2,9 @@ * gtk bridge * alsa backend * dso backend +* lookup cache + +test: +* upload +* vorbis +* finish callback -- cgit