X-Git-Url: https://vcs.maemo.org/git/?a=blobdiff_plain;ds=sidebyside;f=src%2Fhildon-sound.c;h=86de034e739ba6c999348ac749a3d70821895257;hb=115aec9016a6b7ef33786cb9cc2077a8f8819175;hp=76ce0ccd1edfb530458f40fccd7000f7c5128bdd;hpb=d5736fd47ddb0f6d67e47b884370c56def27f08f;p=hildon diff --git a/src/hildon-sound.c b/src/hildon-sound.c index 76ce0cc..86de034 100644 --- a/src/hildon-sound.c +++ b/src/hildon-sound.c @@ -1,14 +1,14 @@ /* - * This file is part of hildon-libs + * 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,14 +24,15 @@ /** * 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 #include -#include +#include + #include "hildon-sound.h" -#include #define ALARM_GCONF_PATH "/apps/osso/sound/system_alert_volume" @@ -39,54 +40,58 @@ * 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) +void +hildon_play_system_sound(const gchar *sample) { - GConfClient *client; - GConfValue *value; - gint volume, scale, sock, sample_id; + 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 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) + gconf_vol = 2; + else + gconf_vol = gconf_value_get_int(value); - client = gconf_client_get_default(); - value = gconf_client_get(client, ALARM_GCONF_PATH, NULL); + if (value) + gconf_value_free(value); + g_object_unref (client); - /* 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; - else - volume = gconf_value_get_int(value); + volume = ((1.0 - (float)gconf_vol / 2.0)) * (-6.0); +#endif - if (value) - gconf_value_free(value); - g_object_unref(client); + if ((ret = ca_context_create(&ca_con)) != CA_SUCCESS) { + g_warning("ca_context_create: %s\n", ca_strerror(ret)); + return; + } + if ((ret = ca_context_open(ca_con)) != CA_SUCCESS) { + g_warning("ca_context_open: %s\n", ca_strerror(ret)); + ca_context_destroy(ca_con); + return; + } + ca_proplist_create(&pl); + ca_proplist_sets(pl, CA_PROP_MEDIA_FILENAME, sample); + ca_proplist_setf(pl, CA_PROP_CANBERRA_VOLUME, "%f", volume); - 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; + 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)); - sample_id = esd_file_cache(sock, g_get_prgname(), sample); - if (sample_id < 0) { - close(sock); - return; - } - - 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); + ca_context_destroy(ca_con); }