X-Git-Url: https://vcs.maemo.org/git/?a=blobdiff_plain;f=src%2Fhildon-sound.c;h=1bbc26449f4790f3a3dace0f493dd3eed3b8b8d8;hb=e547cfac9ea4f2cc1d83252c55145831ab3eed4e;hp=c29fad7ff031a2898a7b8907b8af0beb8b5245d3;hpb=a8bd03bf755fdbfbd7253dbaf7534d00c2046250;p=hildon diff --git a/src/hildon-sound.c b/src/hildon-sound.c index c29fad7..1bbc264 100644 --- a/src/hildon-sound.c +++ b/src/hildon-sound.c @@ -1,14 +1,14 @@ /* - * This file is a part of hildon + * This file is a part of libhildon * - * Copyright (C) 2005, 2006 Nokia Corporation, all rights reserved. + * Copyright (C) 2005-2008 Nokia Corporation. All rights reserved. * - * Contact: Michael Dominic Kostrzewa + * Contact: Kimmo Hämäläinen * * This library 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; version 2.1 of - * the License. + * the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of @@ -24,71 +24,106 @@ /** * SECTION:hildon-sound - * @short_description: An esd-based utility function for playing a sound. + * @short_description: libcanberra-based utility function for playing a sound. * */ -#include "hildon-sound.h" -#include -#include -#include +#include +#include +#include -#define ALARM_GCONF_PATH \ - "/apps/osso/sound/system_alert_volume" +#include "hildon-sound.h" + +#define ALARM_GCONF_PATH "/apps/osso/sound/system_alert_volume" + +static ca_context *hildon_ca_context_get (void); + +/* + * hildon_ca_context_get: + * + * hildon maintains a single application-global ca_context object. + * + * This functions is based on ca_gtk_context_get + * + * Returns: a ca_context object + */ +static ca_context * +hildon_ca_context_get (void) +{ + static GStaticPrivate context_private = G_STATIC_PRIVATE_INIT; + ca_context *c = NULL; + const gchar *name = NULL; + gint ret; + + if ((c = g_static_private_get(&context_private))) + return c; + + if ((ret = ca_context_create(&c)) != CA_SUCCESS) { + g_warning("ca_context_create: %s\n", ca_strerror(ret)); + return NULL; + } + if ((ret = ca_context_open(c)) != CA_SUCCESS) { + g_warning("ca_context_open: %s\n", ca_strerror(ret)); + ca_context_destroy(c); + return NULL; + } + + if ((name = g_get_application_name())) + ca_context_change_props(c, CA_PROP_APPLICATION_NAME, name, NULL); + + g_static_private_set(&context_private, c, (GDestroyNotify) ca_context_destroy); + + return c; +} /** * hildon_play_system_sound: * @sample: sound file to play * - * Plays the given sample using esd sound daemon. + * Plays the given sample using libcanberra. * Volume level is received from gconf. */ void -hildon_play_system_sound (const gchar *sample) +hildon_play_system_sound(const gchar *sample) { + float volume = 0; + int ret; + ca_context *ca_con = NULL; + ca_proplist *pl = NULL; + +#if 0 /* FIXME: Check volume handling. Would be great not to use Gconf... */ GConfClient *client; GConfValue *value; - gint volume, scale, sock, sample_id; + gint gconf_vol; + /* + * The volume is from -0dB to -6dB, + The full volume is marked as 2 in gconf */ client = gconf_client_get_default (); value = gconf_client_get (client, ALARM_GCONF_PATH, NULL); /* We want error cases to match full volume, not silence, so we do not want to use gconf_client_get_int */ if (!value || value->type != GCONF_VALUE_INT) - volume = 2; + gconf_vol = 2; else - volume = gconf_value_get_int(value); + gconf_vol = gconf_value_get_int(value); if (value) gconf_value_free(value); g_object_unref (client); - switch (volume) - { - case 0: - return; - case 1: - scale = 0x80; - break; - case 2: - default: - scale = 0xff; - break; - }; - - sock = esd_open_sound (NULL); - if (sock <= 0) - return; - - sample_id = esd_file_cache (sock, g_get_prgname(), sample); - if (sample_id < 0) { - close(sock); - return; - } + volume = ((1.0 - (float)gconf_vol / 2.0)) * (-6.0); +#endif + + ca_con = hildon_ca_context_get (); + + ca_proplist_create(&pl); + ca_proplist_sets(pl, CA_PROP_MEDIA_FILENAME, sample); + ca_proplist_setf(pl, CA_PROP_CANBERRA_VOLUME, "%f", volume); + + ret = ca_context_play_full(ca_con, 0, pl, NULL, NULL); + g_debug("ca_context_play_full (vol %f): %s\n", volume, ca_strerror(ret)); - esd_set_default_sample_pan (sock, sample_id, scale, scale); - esd_sample_play(sock, sample_id); - esd_sample_free(sock, sample_id); - close (sock); + ca_proplist_destroy(pl); }