[gnome-games] Add libcanberra sound option



commit 8fe525e644611955550e336988a862023c52817e
Author: Christian Persch <chpe gnome org>
Date:   Sun May 3 15:17:34 2009 +0200

    Add libcanberra sound option
    
    Add --enable-sound --with-sound=libcanberra option to use
    libcanberra-gtk to play sounds.
---
 configure.in                   |   29 +++++++++++----
 libgames-support/Makefile.am   |    5 +++
 libgames-support/games-sound.c |   75 +++++++++++++++++++++++++++++++---------
 3 files changed, 84 insertions(+), 25 deletions(-)

diff --git a/configure.in b/configure.in
index dd2632f..07988b4 100644
--- a/configure.in
+++ b/configure.in
@@ -1,9 +1,6 @@
 #                                               -*- Autoconf -*-
 # Process this file with autoconf to produce a configure script.
 
-# This can be either "trunk" or "branches/gnome-x-y"
-m4_define([gnome_games_branch],["trunk"])
-
 AC_PREREQ([2.53])
 AC_INIT([GNOME Games], [2.27.1],
   [http://bugzilla.gnome.org/enter_bug.cgi?product=gnome-games],
@@ -117,7 +114,7 @@ need_python=no
 need_libxml=no
 need_clutter=no
 need_dbus_glib=no
-want_gstreamer=no
+want_sound=no
 allow_gnuchess=no
 allow_smclient=no
 disallow_hildon=no
@@ -144,7 +141,7 @@ for game in $gamelist; do
     *) ;;
   esac
   case $game in
-    aisleriot|gnect|gnibbles|gnobots2|gnometris|iagno) want_gstreamer=yes ;;
+    aisleriot|gnect|gnibbles|gnobots2|gnometris|iagno) want_sound=yes ;;
     *) ;;
   esac
   case $game in
@@ -294,7 +291,7 @@ fi
 
 # Sound
 
-if test "$want_gstreamer" = "yes"; then
+if test "$want_sound" = "yes"; then
   AC_MSG_CHECKING([whether to enable sound support])
   AC_ARG_ENABLE([sound],
     [AS_HELP_STRING([--enable-sound],[Enable sound with GStreamer or SDL_Mixer.])],
@@ -311,7 +308,7 @@ fi
 
 AC_MSG_CHECKING([for which sound library to use])
 AC_ARG_WITH([sound],
-  [AS_HELP_STRING([--with-sound=gstreamer|sdl_mixer (default: sdl_mixer)])],
+  [AS_HELP_STRING([--with-sound=libcanberra|gstreamer|sdl_mixer (default: sdl_mixer)])],
   [with_sound="$withval"],
   [with_sound=sdl_mixer])
 AC_MSG_RESULT([$with_sound])
@@ -475,6 +472,7 @@ GSTREAMER_REQUIRED=0.10.11
 HILDON_LIBS_REQUIRED=0.14
 HILDON_1_REQUIRED=1.00
 DBUS_GLIB_REQUIRED=0.75
+LIBCANBERRA_GTK_REQUIRED=0
 
 # Check for common modules
 
@@ -617,7 +615,21 @@ AM_CONDITIONAL([HAVE_PYTHON],[test "$enable_python" = "yes"])
 
 AM_CONDITIONAL([WITH_GTHREAD],[test "$need_gthread" = "yes"])
 
-# Sound support: GStreamer and SDL_mixer
+# Sound support: Libcanberra, GStreamer or SDL_mixer
+
+if test "$enable_sound"; then
+  AC_DEFINE([ENABLE_SOUND],[1],[Define if sound support is enabled])
+fi
+
+have_libcanberra=no
+if test "$enable_sound" = "yes" -a "$with_sound" = "libcanberra"; then
+  PKG_CHECK_MODULES([CANBERRA_GTK],[libcanberra-gtk >= $LIBCANBERRA_GTK_REQUIRED],[],
+    [AC_MSG_ERROR([Sound support using libcanberra was requested, but libcanberra-gtk not found.])])
+
+  AC_DEFINE([HAVE_CANBERRA_GTK],[1],[Define if libcanberra-gtk support is enabled])
+  have_libcanberra=yes
+fi
+
 have_gstreamer=no
 if test "$enable_sound" = "yes" -a "$with_sound" = "sdl_mixer"; then
   # Check for SDL_Mixer sound support, sets SDL_MIXER_CFLAGS, SDL_MIXER_LIBS, AUDIO_SDL
@@ -655,6 +667,7 @@ if test "x$SDL_mixer" = "xyes"; then
   AC_DEFINE([HAVE_SDL_MIXER],[1],[Define if SDL_Mixer is available])
 fi
 
+AM_CONDITIONAL([HAVE_CANBERRA_GTK],[test "$have_libcanberra" = "yes"])
 AM_CONDITIONAL([HAVE_GSTREAMER],[test "$have_gstreamer" = "yes"])
 AM_CONDITIONAL([HAVE_SDL_MIXER],[test "x$SDL_mixer" = "xyes"])
 AM_CONDITIONAL([ENABLE_SOUND],[test "$enable_sound" = "yes"])
diff --git a/libgames-support/Makefile.am b/libgames-support/Makefile.am
index 1ca6a85..bcf93b7 100644
--- a/libgames-support/Makefile.am
+++ b/libgames-support/Makefile.am
@@ -201,6 +201,11 @@ libgames_support_la_CFLAGS += $(CLUTTER_CFLAGS)
 libgames_support_la_LIBADD += $(CLUTTER_LIBS)
 endif
 
+if HAVE_CANBERRA_GTK
+libgames_support_la_CFLAGS += $(CANBERRA_GTK_CFLAGS)
+libgames_support_la_LIBADD += $(CANBERRA_GTK_LIBS)
+endif
+
 if HAVE_GSTREAMER
 libgames_support_la_CFLAGS += $(GSTREAMER_CFLAGS)
 libgames_support_la_LIBADD += $(GSTREAMER_LIBS)
diff --git a/libgames-support/games-sound.c b/libgames-support/games-sound.c
index 0bd89bc..b257a4f 100644
--- a/libgames-support/games-sound.c
+++ b/libgames-support/games-sound.c
@@ -24,22 +24,24 @@
 #include <glib.h>
 #include <glib/gi18n.h>
 
-#if defined(HAVE_GSTREAMER)
-  #include <gst/gst.h>
+#if defined(HAVE_CANBERRA_GTK)
+#include <canberra-gtk.h>
+#elif defined(HAVE_GSTREAMER)
+#include <gst/gst.h>
 #elif defined(HAVE_SDL_MIXER)
-  #include "SDL.h"
-  #include "SDL_mixer.h"
-#endif 
+#include "SDL.h"
+#include "SDL_mixer.h"
+#endif
 
 #include "games-debug.h"
 #include "games-runtime.h"
 
 #include "games-sound.h"
 
-#if defined(HAVE_GSTREAMER) || defined(HAVE_SDL_MIXER)
+#ifdef ENABLE_SOUND
 static gboolean sound_enabled = FALSE;
 static gboolean sound_init = FALSE;
-#endif /* HAVE_GSTREAMER || HAVE_SDL_MIXER */
+#endif /* ENABLE_SOUND */
 
 #ifdef HAVE_GSTREAMER
 static GstElement *pipeline;
@@ -123,13 +125,23 @@ games_sound_sdl_play (const gchar *filename)
 }
 #endif /* HAVE_SDL_MIXER */
 
-#if defined(HAVE_GSTREAMER) || defined(HAVE_SDL_MIXER)
+#ifdef ENABLE_SOUND
 
 /* Initializes the games-sound support */
 static void
 games_sound_init (void)
 {
-#if defined(HAVE_GSTREAMER)
+#if defined(HAVE_CANBERRA_GTK)
+  ca_context *context;
+
+  if (!(context = ca_gtk_context_get ()))
+    return;
+
+  ca_context_change_props (context,
+                           CA_PROP_MEDIA_ROLE, "game",
+                           NULL);
+
+#elif defined(HAVE_GSTREAMER)
   GError *err = NULL;
 
   g_assert (g_thread_supported ());
@@ -168,7 +180,7 @@ games_sound_init (void)
 #endif /* HAVE_SDL_MIXER */
 }
 
-#endif /* HAVE_GSTREAMER || HAVE_SDL_MIXER */
+#endif /* ENABLE_SOUND */
 
 /**
  * games_sound_add_option_group:
@@ -195,7 +207,36 @@ games_sound_add_option_group (GOptionContext *context)
 void
 games_sound_play (const gchar * filename)
 {
-#if defined(HAVE_GSTREAMER)
+#if defined(HAVE_CANBERRA_GTK)
+  char *name, *path;
+  int rv;
+  ca_context *context;
+
+  if (!sound_enabled)
+    return;
+  if (!sound_init)
+    games_sound_init ();
+
+  if (!(context = ca_gtk_context_get ()))
+    return;
+
+  name = g_strdup_printf ("%s.ogg", filename);
+  path = games_runtime_get_file (GAMES_RUNTIME_SOUND_DIRECTORY, name);
+  g_free (name);
+
+  rv =  ca_context_play (context,
+                         0,
+                         CA_PROP_MEDIA_NAME, filename,
+                         CA_PROP_MEDIA_FILENAME, path,
+                         NULL);
+
+  _games_debug_print (GAMES_DEBUG_SOUND,
+                      "Playing sound %s [filename %s]: %s\n",
+                      filename, path, ca_strerror (rv));
+
+  g_free (path);
+
+#elif defined(HAVE_GSTREAMER)
   GError *err = NULL;
     
   if (!sound_enabled)
@@ -226,9 +267,9 @@ games_sound_play (const gchar * filename)
 void
 games_sound_enable (gboolean enabled)
 {
-#if defined(HAVE_GSTREAMER) || defined(HAVE_SDL_MIXER)
+#ifdef ENABLE_SOUND
   sound_enabled = enabled;
-#endif /* HAVE_GSTREAMER || HAVE_SDL_MIXER */
+#endif /* ENABLE_SOUND */
 }
 
 /**
@@ -239,11 +280,11 @@ games_sound_enable (gboolean enabled)
 gboolean
 games_sound_is_enabled (void)
 {
-#if defined(HAVE_GSTREAMER) || defined(HAVE_SDL_MIXER)
+#ifdef ENABLE_SOUND
   return sound_enabled;
 #else
   return FALSE;
-#endif /* HAVE_GSTREAMER || HAVE_SDL_MIXER */
+#endif /* ENABLE_SOUND */
 }
 
 /**
@@ -254,9 +295,9 @@ games_sound_is_enabled (void)
 gboolean
 games_sound_is_available (void)
 {
-#if defined(HAVE_GSTREAMER) || defined(HAVE_SDL_MIXER)
+#ifdef ENABLE_SOUND
   return TRUE;
 #else
   return FALSE;
-#endif /* HAVE_GSTREAMER || HAVE_SDL_MIXER */
+#endif /* ENABLE_SOUND */
 }



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]