MonkeyMedia (GStreamer) in the gnome libraries



Hey,

I just hacked a few patches together that port the gnome libraries and
the settings daemon to use MonkeyMedia (a thin library on top of
gstreamer to make music playback Really Easy[tm], with some extra
goodies as well. Lives in the monkey-sound module in cvs.), this has the
advantage that you can now play any kind of sound file supported by
gstreamer in gnome, and that gnome isn't esound-dependant anymore.
(GStreamer still supports audio output to esound, in case you were
wondering).

I also have a quick port of the nautilus musicview to this stuff ready,
just needs some brushing up.

I needed to change the gnome-sound api a little though, since it had
some esound specific bits in there (esound connections and stuff like
that).

IMHO it would be great if something like this could be in a future gnome
release, being forces to use esd sucks and it's fun to be able to play
an ogg on startup ;)

Let me know what you think,
Jorn
? =
? stamp-h1
? libgnome/.gnome-init.c.swp
Index: ChangeLog
===================================================================
RCS file: /cvs/gnome/libgnome/ChangeLog,v
retrieving revision 1.205
diff -u -r1.205 ChangeLog
--- ChangeLog	13 May 2002 17:11:54 -0000	1.205
+++ ChangeLog	14 May 2002 17:57:49 -0000
@@ -1,3 +1,14 @@
+2002-05-14  Jorn Baayen  <jorn nl linux org>
+
+	* configure.in:
+	* libgnome/gnome-init.c:
+	* libgnome/gnome-program.c:
+	* libgnome/gnome-sound.c:
+	* libgnome/gnome-sound.h:
+	* libgnome/gnome-triggers.c:
+	* libgnome/libgnome-2.0.pc.in:
+	* schemas/desktop_gnome_sound.schemas: port sound code to MonkeyMedia
+
 2002-05-13  Anders Carlsson  <andersca gnu org>
 
 	* configure.in: Release 1.117.0
Index: configure.in
===================================================================
RCS file: /cvs/gnome/libgnome/configure.in,v
retrieving revision 1.121
diff -u -r1.121 configure.in
--- configure.in	13 May 2002 17:11:54 -0000	1.121
+++ configure.in	14 May 2002 17:57:49 -0000
@@ -83,23 +83,9 @@
 dnl
 dnl Start of pkg-config checks
 dnl
-dnl We first check for esound and audiofile (which has conditional
-dnl support built in)
-dnl
-
-AUDIOFILE_MODULE="audiofile >= 0.2.3"
-ESOUND_MODULE="esound >= 0.2.25"
-PKG_CHECK_MODULES(SOUND_TEST, $ESOUND_MODULE $AUDIOFILE_MODULE, [
-	AC_DEFINE(HAVE_LIBAUDIOFILE)
-	AC_DEFINE(HAVE_ESD)
-],[
-	AUDIOFILE_MODULE=""
-	ESOUND_MODULE=""
-])
 
 PKG_CHECK_MODULES(LIBGNOME, glib-2.0 >= 2.0.1 gmodule-2.0 >= 2.0.1 gnome-vfs-2.0 >= 1.9.13 \
-libxml-2.0 >= 2.4.20 libbonobo-2.0 >= 1.116.0 gconf-2.0 >= 1.1.9 \
-$AUDIOFILE_MODULE $ESOUND_MODULE)
+libxml-2.0 >= 2.4.20 libbonobo-2.0 >= 1.116.0 gconf-2.0 >= 1.1.9 monkey-media >= 0.5.0)
 
 PKG_CHECK_MODULES(HELP_VFS_MODULE, glib-2.0 >= 2.0.1 gmodule-2.0 >= 2.0.1 gnome-vfs-2.0 >= 1.9.13 gnome-vfs-module-2.0 >= 1.9.13 \
 libxml-2.0 >= 2.4.20 libbonobo-2.0 >= 1.116.0)
Index: doc/reference/tmpl/gnome-sound.sgml
===================================================================
RCS file: /cvs/gnome/libgnome/doc/reference/tmpl/gnome-sound.sgml,v
retrieving revision 1.3
diff -u -r1.3 gnome-sound.sgml
--- doc/reference/tmpl/gnome-sound.sgml	6 Oct 2001 16:15:34 -0000	1.3
+++ doc/reference/tmpl/gnome-sound.sgml	14 May 2002 17:57:49 -0000
@@ -26,6 +26,7 @@
 
 </para>
 
+<!-- # Unused Parameters # -->
 @hostname: 
 
 
@@ -41,24 +42,8 @@
 
 </para>
 
+ uri: 
+<!-- # Unused Parameters # -->
 @filename: 
-
-
-<!-- ##### FUNCTION gnome_sound_sample_load ##### -->
-<para>
-
-</para>
-
- sample_name: 
- filename: 
- Returns: 
-
-
-<!-- ##### FUNCTION gnome_sound_connection_get ##### -->
-<para>
-
-</para>
-
- Returns: 
 
 
Index: libgnome/gnome-init.c
===================================================================
RCS file: /cvs/gnome/libgnome/libgnome/gnome-init.c,v
retrieving revision 1.102
diff -u -r1.102 gnome-init.c
--- libgnome/gnome-init.c	29 Apr 2002 11:12:54 -0000	1.102
+++ libgnome/gnome-init.c	14 May 2002 17:57:49 -0000
@@ -158,7 +158,7 @@
  * libgnome
  *****************************************************************************/
 
-enum { ARG_DISABLE_SOUND = 1, ARG_ENABLE_SOUND, ARG_ESPEAKER, ARG_VERSION };
+enum { ARG_DISABLE_SOUND = 1, ARG_ENABLE_SOUND, ARG_VERSION };
 
 static char *gnome_user_dir = NULL;
 static char *gnome_user_private_dir = NULL;
@@ -218,14 +218,6 @@
 	switch(reason) {
 	case POPT_CALLBACK_REASON_OPTION:
 		switch(opt->val) {
-		case ARG_ESPEAKER:
-			g_value_init (&value, G_TYPE_STRING);
-			g_value_set_string (&value, opt->arg);
-			g_object_set_property (G_OBJECT (program),
-					       GNOME_PARAM_ESPEAKER, &value);
-			g_value_unset (&value);
-			break;
-
 		case ARG_DISABLE_SOUND:
 			g_value_init (&value, G_TYPE_BOOLEAN);
 			g_value_set_boolean (&value, FALSE);
@@ -314,8 +306,7 @@
 			  GnomeModuleInfo *mod_info)
 {
 	GValue value = { 0 };
-	gboolean enable_val = TRUE, create_dirs_val = TRUE;                           
-	char *espeaker_val = NULL;                                                    
+	gboolean enable_val = TRUE, create_dirs_val = TRUE;
 
 	g_value_init (&value, G_TYPE_BOOLEAN);
 	g_object_get_property (G_OBJECT (program),
@@ -330,15 +321,8 @@
 	enable_val = g_value_get_boolean (&value);
 	g_value_unset (&value);
 
-	g_value_init (&value, G_TYPE_STRING);
-	g_object_get_property (G_OBJECT (program), 
-			       GNOME_PARAM_ESPEAKER, &value);
-	espeaker_val = g_value_dup_string (&value);
-	g_value_unset (&value);
-
-
 	if (enable_val) {
-		gnome_sound_init(espeaker_val);
+		gnome_sound_init();
 	}
 
 	libgnome_userdir_setup (create_dirs_val);
@@ -362,11 +346,6 @@
 
 	{ "enable-sound", '\0', POPT_ARG_NONE,                                  
 	  NULL, ARG_ENABLE_SOUND, N_("Enable sound server usage"), NULL},       
-
-	{ "espeaker", '\0', POPT_ARG_STRING,                                    
-	  NULL, ARG_ESPEAKER, N_("Host:port on which the sound server to use is"
-				 " running"),
-	  N_("HOSTNAME:PORT")},                                                 
 
 	{"version", '\0', POPT_ARG_NONE, NULL, ARG_VERSION },
 
Index: libgnome/gnome-program.c
===================================================================
RCS file: /cvs/gnome/libgnome/libgnome/gnome-program.c,v
retrieving revision 1.57
diff -u -r1.57 gnome-program.c
--- libgnome/gnome-program.c	22 Mar 2002 16:02:45 -0000	1.57
+++ libgnome/gnome-program.c	14 May 2002 17:57:50 -0000
@@ -75,7 +75,6 @@
     gchar *prop_app_datadir;
     gboolean prop_create_directories;
     gboolean prop_enable_sound;
-    gchar *prop_espeaker;
 
     gchar **gnome_path;
 
@@ -109,7 +108,6 @@
     PROP_APP_SYSCONFDIR,
     PROP_CREATE_DIRECTORIES,
     PROP_ENABLE_SOUND,
-    PROP_ESPEAKER,
     PROP_POPT_TABLE,
     PROP_POPT_FLAGS,
     PROP_POPT_CONTEXT,
@@ -203,10 +201,6 @@
     case PROP_ENABLE_SOUND:
 	program->_priv->prop_enable_sound = g_value_get_boolean (value);
 	break;
-    case PROP_ESPEAKER:
-	g_free (program->_priv->prop_espeaker);
-	program->_priv->prop_espeaker = g_value_dup_string (value);
-	break;
     default: {
 	    GObjectSetPropertyFunc set_func;
 
@@ -281,9 +275,6 @@
     case PROP_ENABLE_SOUND:
 	g_value_set_boolean (value, program->_priv->prop_enable_sound);
 	break;
-    case PROP_ESPEAKER:
-	g_value_set_string (value, program->_priv->prop_espeaker);
-	break;
     default: {
 	    GObjectSetPropertyFunc get_func;
 
@@ -581,16 +572,6 @@
 			       (G_PARAM_READABLE | G_PARAM_WRITABLE |
 				G_PARAM_CONSTRUCT_ONLY)));
 
-    g_object_class_install_property
-	(object_class,
-	 PROP_ESPEAKER,
-	 g_param_spec_string (GNOME_PARAM_ESPEAKER,
-			      _("Espeaker"), 
-			      _("How to connect to esd"),
-			      NULL,
-			      (G_PARAM_READABLE | G_PARAM_WRITABLE |
-			       G_PARAM_CONSTRUCT_ONLY)));
-
     object_class->finalize  = gnome_program_finalize;
 }
 
@@ -648,8 +629,6 @@
 	self->_priv->prop_app_sysconfdir = NULL;
 	g_free (self->_priv->prop_app_datadir);
 	self->_priv->prop_app_datadir = NULL;
-	g_free (self->_priv->prop_espeaker);
-	self->_priv->prop_espeaker = NULL;
 
 	g_strfreev (self->_priv->gnome_path);
 	self->_priv->gnome_path = NULL;
Index: libgnome/gnome-sound.c
===================================================================
RCS file: /cvs/gnome/libgnome/libgnome/gnome-sound.c,v
retrieving revision 1.32
diff -u -r1.32 gnome-sound.c
--- libgnome/gnome-sound.c	8 Jan 2002 21:17:34 -0000	1.32
+++ libgnome/gnome-sound.c	14 May 2002 17:57:50 -0000
@@ -1,5 +1,6 @@
 /*
  * Copyright (C) 1997-1998 Stuart Parmenter and Elliot Lee
+ * Copyright (C) 2002 Jorn Baayen
  * All rights reserved.
  *
  * This file is part of the Gnome Library.
@@ -28,527 +29,136 @@
 #include "libgnome.h"
 #include "gnome-sound.h"
 
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <time.h>
-
-#ifdef HAVE_ESD
-#include <esd.h>
-#endif
-
-#ifdef HAVE_ESD
-static char *esound_hostname = NULL;
-static gboolean esound_hostname_null_ok = FALSE;
-static int gnome_sound_connection = -1;
-#endif
-
-typedef struct _sample
-  {
-    int rate, format, samples, id, size;
-    short *data;
-  }
-GnomeSoundSample;
+#include <monkey-media.h>
+#include <libgnomevfs/gnome-vfs-utils.h>
 
-#ifndef HAVE_LIBAUDIOFILE
-typedef struct _WAVFormatChunk
-  {
-    char chunkID[4];
-    int chunkSize;
-
-    unsigned int dwSamplesPerSec;
-    unsigned int dwAvgBytesPerSec;
-    short wFormatTag;
-    unsigned short wChannels;
-    unsigned short wBlockAlign;
-    unsigned short wBitsPerSample;
-  }
-WAVFormatChunk;
+#include <stdlib.h>
 
-#ifdef WORDS_BIGENDIAN
-#define SWAP_SHORT( x ) x = ( ( x & 0x00ff ) << 8 ) | ( ( x >> 8 ) & 0x00ff )
-#define SWAP_LONG( x ) x = ( ( ( x & 0x000000ff ) << 24 ) |\
-( ( x & 0x0000ff00 ) << 8 ) |\
-( ( x & 0x00ff0000 ) >> 8 ) |\
-( ( x & 0xff000000 ) >> 24 ) )
-#endif
+static MonkeyMediaMixer *mixer = NULL;
+static GHashTable *cache = NULL;
 
 /**
- * gnome_sound_sample_load_wav:
- * @file: filename to try loading a WAV file from.
- * 
- * Used to load a .wav file into esound.
- *
- * Returns a GnomeSoundSample or NULL if file did not exist.
+ * gnome_sound_play:
+ * @uri URI containing the sound sample.
  *
+ * Plays the audio stored in @uri, if possible. Fail quietly if playing is
+ * not possible (due to missing sound support or for other reasons).
  */
-#ifdef HAVE_ESD
-static GnomeSoundSample *
-gnome_sound_sample_load_wav(const char *file)
+void 
+gnome_sound_play (const char * uri)
 {
-  FILE *f;
-  GnomeSoundSample *s;
-  char buf[4];
-  WAVFormatChunk fmt;
-  int skipl = 0;
-  int skipr = 0;
-  char bytes = 0;
-  char stereo = 0;
-  int len;
-
-  /* int                 count; */
-
-  f = fopen (file, "r");
-  if (!f)
-    return NULL;
-  s = g_malloc (sizeof (GnomeSoundSample));
-  if (!s)
-    {
-      fclose (f);
-      return NULL;
-    }
-  s->rate = 44100;
-  s->format = ESD_STREAM | ESD_PLAY;
-  s->samples = 0;
-  s->data = NULL;
-  s->id = 0;
-  fread (buf, 1, 4, f);
-  if ((buf[0] != 'R') ||
-      (buf[1] != 'I') ||
-      (buf[2] != 'F') ||
-      (buf[3] != 'F'))
-    {
-      /* not a RIFF WAV file */
-      fclose (f);
-      g_free (s);
-      return NULL;
-    }
-  fread (buf, 1, 4, f);
-  fread (buf, 1, 4, f);
-  fread (fmt.chunkID, 1, 4, f);
-  fread (&(fmt.chunkSize), 1, 4, f);
-
-#ifdef WORDS_BIGENDIAN
-  SWAP_LONG (fmt.chunkSize);
-#endif
-
-  if ((fmt.chunkID[0] == 'f') &&
-      (fmt.chunkID[1] == 'm') &&
-      (fmt.chunkID[2] == 't') &&
-      (fmt.chunkID[3] == ' ') &&
-      16 == fmt.chunkSize)
-    /* fmt chunk */
-    {
-      fread (&(fmt.wFormatTag), 1, 2, f);
-      fread (&(fmt.wChannels), 1, 2, f);
-      fread (&(fmt.dwSamplesPerSec), 1, 4, f);
-      fread (&(fmt.dwAvgBytesPerSec), 1, 4, f);
-      fread (&(fmt.wBlockAlign), 1, 2, f);
-      fread (&(fmt.wBitsPerSample), 1, 2, f);
-#ifdef WORDS_BIGENDIAN
-      SWAP_SHORT (fmt.wFormatTag);
-      SWAP_SHORT (fmt.wChannels);
-      SWAP_LONG (fmt.dwSamplesPerSec);
-      SWAP_LONG (fmt.dwAvgBytesPerSec);
-      SWAP_SHORT (fmt.wBlockAlign);
-      SWAP_SHORT (fmt.wBitsPerSample);
-#endif
-
-      if (fmt.wFormatTag != 1)
-	{
-	  /* unknown WAV encoding format - exit */
-	  fclose (f);
-	  g_free (s);
-	  return NULL;
-	}
-      skipl = 0;
-      skipr = 0;
-      bytes = 0;
-      stereo = 0;
-      if (fmt.wChannels == 1)
-	s->format |= ESD_MONO;
-      else if (fmt.wChannels == 2)
-	{
-	  stereo = 1;
-	  s->format |= ESD_STEREO;
-	}
-      else
-	{
-	  stereo = 1;
-	  s->format |= ESD_STEREO;
-	  if (fmt.wChannels == 3)
-	    {
-	      skipl = 0;
-	      skipr = 1;
-	    }
-	  else if (fmt.wChannels == 4)
-	    {
-	      skipl = 0;
-	      skipr = 2;
-	    }
-	  else if (fmt.wChannels == 4)
-	    {
-	      skipl = 0;
-	      skipr = 2;
-	    }
-	  else if (fmt.wChannels == 6)
-	    {
-	      skipl = 3;
-	      skipr = 1;
-	    }
-	  else
-	    {
-	      /* unknown channel encoding */
-	      fclose (f);
-	      g_free (s);
-	      return NULL;
-	    }
-	}
-      s->rate = fmt.dwSamplesPerSec;
-      if (fmt.wBitsPerSample <= 8)
-	{
-	  bytes = 1;
-	  s->format |= ESD_BITS8;
-	}
-      else if (fmt.wBitsPerSample <= 16)
-	s->format |= ESD_BITS16;
-      else
-	{
-	  /* unknown bits encoding encoding */
-	  fclose (f);
-	  g_free (s);
-	  return NULL;
-	}
-    }
-  for (;;)
-    {
-      if (fread (buf, 1, 4, f) &&
-	  fread (&len, 4, 1, f))
-	{
-#ifdef WORDS_BIGENDIAN
-	  SWAP_LONG (len);
-#endif
-
-	  if ((buf[0] != 'd') ||
-	      (buf[1] != 'a') ||
-	      (buf[2] != 't') ||
-	      (buf[3] != 'a'))
-	    fseek (f, len, SEEK_CUR);
-	  else
-	    {
-	      s->data = g_malloc (len);
-	      if (!s->data)
-		{
-		  fclose (f);
-		  g_free (s);
-		  return NULL;
-		}
-	      if ((skipl == 0) && (skipr == 0))
-		{
-		  fread (s->data, len, 1, f);
-#ifdef WORDS_BIGENDIAN
-		  if (fmt.wBitsPerSample > 8 && fmt.wBitsPerSample <= 16)
-		    {
-		      char *tmp;
-		      char tmpval;
-		      int i;
-
-		      tmp = (char *) (s->data);
-
-		      for (i = 0; i < len; i++)
-			{
-			  tmpval = tmp[i];
-			  tmp[i] = tmp[i + 1];
-			  tmp[i + 1] = tmpval;
-			}
-		    }
-#endif
-		}
-	      else
-		{
-		}
-	      s->samples = len;
-	      if (stereo)
-		s->samples /= 2;
-	      if (!bytes)
-		s->samples /= 2;
-	      fclose (f);
-	      return s;
-	    }
-	}
-      else
-	{
-	  fclose (f);
-	  return NULL;
-	}
-    }
-  fclose (f);
-  g_free (s);
-  if (s->data)
-    g_free (s->data);
+  MonkeyMediaAudioStream *stream;
+  char *real_uri;
+
+  if (mixer == NULL)
+    return;
+
+  real_uri = gnome_vfs_get_uri_from_local_path (uri);
+  stream = monkey_media_audio_stream_new (real_uri, NULL);
+  g_free (real_uri);
+  if (stream == NULL)
+    return;
+  
+  monkey_media_mixer_append_audio_stream (mixer, stream);
+  monkey_media_mixer_set_playing_audio_stream (mixer, stream);
+  monkey_media_mixer_set_state (mixer, MONKEY_MEDIA_MIXER_STATE_PLAYING);
 
-  return NULL;
+  /* mixer holds a reference */
+  g_object_unref (G_OBJECT (stream));
 }
-#endif
-#endif
 
-#ifdef HAVE_ESD
-/*
- * This does delayed initialization of Esound
+/**
+ * gnome_sound_init:
+ *
+ * Initialize the sound system.
  */
-static gboolean
-use_sound (void)
+void
+gnome_sound_init(void)
 {
-  if (gnome_sound_connection == -1){
-    if (esound_hostname || esound_hostname_null_ok){
-      gnome_sound_connection = esd_open_sound (esound_hostname);
-      if (gnome_sound_connection == -1){
-	g_free (esound_hostname);
-	esound_hostname = NULL;
-	esound_hostname_null_ok = FALSE;
-	return FALSE;
-      }
-    }
-  }
-  return TRUE;
+  monkey_media_init (NULL, NULL);
+  
+  mixer = monkey_media_mixer_new (NULL);
+  if (mixer == NULL)
+    return;
 }
-#endif
 
-#if defined(HAVE_LIBAUDIOFILE) && defined(HAVE_ESD)
-#include <audiofile.h>
-
-static GnomeSoundSample *
-gnome_sound_sample_load_audiofile(const char *file)
+static void
+gnome_sound_unref_stream (char *key, GObject *stream, gpointer unused)
 {
-  AFfilehandle in_file;
-  GnomeSoundSample *s;
-  int in_format, in_width, in_channels;
-  double in_rate;
-  int bytes_per_frame;
-  AFframecount frame_count, frames_read;
-
-  int out_bits, out_channels, out_rate;
-  int out_mode = ESD_STREAM, out_func = ESD_PLAY;
-  esd_format_t out_format;
-
-  in_file = afOpenFile(file, "r", NULL);
-  if(!in_file)
-    return NULL;
-
-  frame_count = afGetFrameCount(in_file, AF_DEFAULT_TRACK);
-  in_channels = afGetChannels(in_file, AF_DEFAULT_TRACK);
-  in_rate = afGetRate (in_file, AF_DEFAULT_TRACK);
-  afGetSampleFormat (in_file, AF_DEFAULT_TRACK, &in_format, &in_width);
-  if (in_width == 8)
-    out_bits = ESD_BITS8;
-  else if (in_width == 16)
-    out_bits = ESD_BITS16;
-  else {
-      g_warning ("only sample widths of 8 and 16 supported");
-      return NULL;
-  }
-
-  bytes_per_frame = in_width / 8;
-
-  if (in_channels == 1)
-    out_channels = ESD_MONO;
-  else if (in_channels == 2)
-    out_channels = ESD_STEREO;
-  else {
-      g_warning ("only 1 or 2 channel samples supported");
-      return NULL;
-  }
-
-  out_format = out_bits | out_channels | out_mode | out_func;
-
-  out_rate = (int) in_rate;
-
-  s = g_new0 (GnomeSoundSample, 1);
-
-  s->rate = out_rate;
-  s->format = out_format;
-  s->samples = frame_count;
-  s->data = g_malloc(frame_count * in_channels * bytes_per_frame);
-  s->id = 0;
-
-  frames_read = afReadFrames(in_file, AF_DEFAULT_TRACK, s->data,
-			     frame_count * in_channels);
-
-  afCloseFile(in_file);
-
-  return s;
+  g_object_unref (stream);
+  g_free (key);
 }
-#endif
 
-
-/**
- * gnome_sound_sample_load:
- * @sample_name: The name of the sample.
- * @filename: The filename where the audio is stored.
- *
- * Loads the audio from @filename and load it into the esd cache for later
- * playing. Programs will rarely want to call this function directly. Use
- * gnome_sound_play() instead for fire and forget sound playing.
+/** 
+ * gnome_sound_shutdown:
  *
- * Returns: The esound sample_id or %-1 if the sample was unable to be cached
- * for esound.
+ * Shuts down the gnome sound support.
  */
-int
-gnome_sound_sample_load(const char *sample_name, const char *filename)
+void
+gnome_sound_shutdown (void)
 {
-#ifdef HAVE_ESD
-  GnomeSoundSample *s = NULL;
-  int sample_id;
-  int size;
-  int confirm = 0;
-
-  if (!use_sound ())
-    return -2;
-
-  if(!filename || !*filename)
-    return -2;
-
-#ifdef HAVE_LIBAUDIOFILE
-  s = gnome_sound_sample_load_audiofile(filename);
-#else
-  s = gnome_sound_sample_load_wav(filename);
-#endif
-  if(s)
-    goto playsamp;
-
-  /* XXX: Add handlers for more formats here */
-
- playsamp:
-  if (!s)
-    return -1;
-
-  size = s->samples;
-  if (s->format & ESD_STEREO)
-    size *= 2;
-  if (s->format & ESD_BITS16)
-    size *= 2;
-
-  if (gnome_sound_connection >= 0)
-    {
-      if (s->data)
-	{
-	  /* "name" of all samples is currently "E", should be name of sound 
-	   * file, or event type, for later identification */
-	  s->id = esd_sample_cache (gnome_sound_connection, s->format, s->rate,
-				    size, (char *)sample_name);
-	  write (gnome_sound_connection, s->data, size);
-	  confirm = esd_confirm_sample_cache (gnome_sound_connection);
-	  if (s->id <= 0 || confirm != s->id)
-	    {
-	      g_warning ("error caching sample <%d>!\n", s->id);
-	      s->id = 0;
-	    }
-	  g_free (s->data);
-	  s->data = NULL;
-	}
-    }
-
-  sample_id = s->id;
-
-  g_free(s->data); g_free(s);
-
-  return sample_id;
-#else
-  return -1;
-#endif
+  if (cache != NULL) {
+    g_hash_table_foreach (cache, (GHFunc) gnome_sound_unref_stream, NULL);
+    g_hash_table_destroy (cache);
+    cache = NULL;
+  }
+
+  monkey_media_shutdown ();
 }
 
 /**
- * gnome_sound_play:
- * @filename: File containing the sound sample.
+ * gnome_sound_cache:
  *
- * Plays the audio stored in @filename, if possible. Fail quietly if playing is
- * not possible (due to missing sound support or for other reasons).
+ * Cache an audio stream.
+ *
+ * @uri: URI to be loaded
+ * @sndname: Name in the cache 
  */
-void 
-gnome_sound_play (const char * filename)
+void
+gnome_sound_cache (const char * uri, const char * sndname)
 {
-#ifdef HAVE_ESD
-  char buf[256];
-  int sample;
-  static guint cookie = 0;
-
-  if(!use_sound ())
+  MonkeyMediaAudioStream *stream;
+  char *real_uri;
+  gpointer origname, origstream;
+
+  if (cache == NULL)
+    cache = g_hash_table_new (g_str_hash, g_str_equal);
+
+  real_uri = gnome_vfs_get_uri_from_local_path (uri);
+  stream = monkey_media_audio_stream_new (real_uri, NULL);
+  g_free (real_uri);
+  if (stream == NULL)
     return;
 
-  if (cookie == 0)
-	  cookie = rand ();
+  /* free old one */
+  if (g_hash_table_lookup_extended (cache, sndname, &origname, &origstream)) {
+    g_free (origname);
+    g_object_unref (G_OBJECT (origstream));
+  }
 
-  g_snprintf(buf, sizeof(buf), "%d-%u-%d",
-	     getpid(), cookie++, rand ());
- 
-  /* overflow, make sure we don't reinit with rand again */
-  if (cookie == 0)
-	  cookie = 1;
-
-  sample = gnome_sound_sample_load (buf, filename);
-
-  esd_sample_play(gnome_sound_connection, sample);
-  fsync (gnome_sound_connection);
-  esd_sample_free(gnome_sound_connection, sample);
-#endif
+  g_hash_table_insert (cache, g_strdup (sndname), stream);
 }
 
 /**
- * gnome_sound_init:
- * @hostname: Hostname where esd daemon resides.
+ * gnome_sound_play_cached:
  *
- * Initialize the esd connection.
- */
-void
-gnome_sound_init(const char *hostname)
-{
-#ifdef HAVE_ESD
-	srand(time(NULL));
-	g_free (esound_hostname);
-	if (hostname)
-		esound_hostname = g_strdup (hostname);
-	else
-		esound_hostname_null_ok = TRUE;
-#endif
-}
-
-/** 
- * gnome_sound_shutdown:
+ * Play a cached audio stream
  *
- * Shuts down the gnome sound support.
+ * @sndname: name of the cached stream
  */
 void
-gnome_sound_shutdown(void)
+gnome_sound_play_cached (const char * sndname)
 {
-#ifdef HAVE_ESD
-	g_free (esound_hostname);
-	esound_hostname = NULL;
-	if(gnome_sound_connection >= 0){
-		esd_close(gnome_sound_connection);
-		gnome_sound_connection = -1;
-	}
-#endif
-}
+  MonkeyMediaAudioStream *stream;
 
-/** 
- * gnome_sound_connection_get:
- *
- * Rarely needed to by programs directly, this function may be useful if a
- * program has cached a sample with gnome_sound_sample_load() and now wishes to
- * call esd_sample_play() to play the sample.
- *
- * Returns: the file descriptor of our esound connection or %-1
- * on error.
- **/
-int
-gnome_sound_connection_get (void)
-{
-#ifdef HAVE_ESD
-	if ( ! use_sound ())
-		return -1;
-	return gnome_sound_connection;
-#else
-	return -1;
-#endif
+  if (cache == NULL)
+    return;
+
+  stream = g_hash_table_lookup (cache, sndname);
+  if (stream == NULL)
+    return;
+
+  monkey_media_mixer_append_audio_stream (mixer, stream);
+  monkey_media_mixer_set_playing_audio_stream (mixer, stream);
+  monkey_media_mixer_set_state (mixer, MONKEY_MEDIA_MIXER_STATE_PLAYING);
 }
Index: libgnome/gnome-sound.h
===================================================================
RCS file: /cvs/gnome/libgnome/libgnome/gnome-sound.h,v
retrieving revision 1.18
diff -u -r1.18 gnome-sound.h
--- libgnome/gnome-sound.h	3 Sep 2001 06:42:03 -0000	1.18
+++ libgnome/gnome-sound.h	14 May 2002 17:57:50 -0000
@@ -1,5 +1,6 @@
 /*
  * Copyright (C) 1997-1998 Stuart Parmenter and Elliot Lee
+ * Copyright (C) 2002 Jorn Baayen
  * All rights reserved.
  *
  * This file is part of the Gnome Library.
@@ -30,20 +31,19 @@
 
 G_BEGIN_DECLS
 
-/* Use this with the Esound functions */
-int gnome_sound_connection_get (void);
+/* Initialize sound system */
+void gnome_sound_init (void);
 
-/* Initialize esd connection */
-void gnome_sound_init(const char *hostname);
+/* Closes sound system */
+void gnome_sound_shutdown (void);
 
-/* Closes esd connection */
-void gnome_sound_shutdown(void);
+/* Plays a stream */
+void gnome_sound_play (const char * uri);
 
-/* Returns the Esound sample ID for the sample */
-int gnome_sound_sample_load(const char *sample_name, const char *filename);
+/* Stream caching */
+void gnome_sound_cache (const char * uri, const char * sndname);
 
-/* Loads sample, plays sample, frees sample */
-void gnome_sound_play (const char * filename);
+void gnome_sound_play_cached (const char * sndname);
 
 G_END_DECLS
 
Index: libgnome/gnome-triggers.c
===================================================================
RCS file: /cvs/gnome/libgnome/libgnome/gnome-triggers.c,v
retrieving revision 1.48
diff -u -r1.48 gnome-triggers.c
--- libgnome/gnome-triggers.c	25 Jan 2002 20:08:02 -0000	1.48
+++ libgnome/gnome-triggers.c	14 May 2002 17:57:51 -0000
@@ -32,9 +32,6 @@
 #include "gnome-config.h"
 #include "gnome-util.h"
 #include "gnome-sound.h"
-#ifdef HAVE_ESD
- #include <esd.h>
-#endif
 
 #include <unistd.h>
 #include <stdio.h>
@@ -182,7 +179,7 @@
  * should be activated, 'section' is a colon-separated list indicating
  * which part of the "message classification tree" this trigger will
  * be activated for, 'type' is either "command" (run the command
- * specified in 'params') or 'play' (play the esd sound sample named
+ * specified in 'params') or 'play' (play the sound sample named
  * 'params').
  *
  * Returns 0 on success.  1 otherwise.
@@ -412,28 +409,7 @@
 static void
 gnome_triggers_play_sound(const char *sndname)
 {
-#ifdef HAVE_ESD
-  int sid;
-  static GHashTable *sound_ids = NULL;
-
-  if(gnome_sound_connection_get () < 0) return;
-
-  if(!sound_ids)
-    sound_ids = g_hash_table_new(g_str_hash, g_str_equal);
-
-  sid = GPOINTER_TO_INT(g_hash_table_lookup(sound_ids, sndname));
-
-  if(!sid) {
-    sid = esd_sample_getid(gnome_sound_connection_get (), sndname);
-    if(sid >= 0) sid++;
-    g_hash_table_insert(sound_ids, g_strdup(sndname), GINT_TO_POINTER(sid));
-  }
-
-  if(sid < 0) return;
-  sid--;
-  esd_sample_play(gnome_sound_connection_get (), sid);
-#endif
-  /* If there's no esound, this is just a no-op */
+  gnome_sound_play_cached(sndname);
 }
 
 /**
@@ -595,14 +571,9 @@
 			   const char *level,
 			   const char *supinfo[])
 {
-#if defined(HAVE_ESD)
-  if(gnome_sound_connection_get () == -1)
-    return;
-
   if(t->u.media.cache_id >= 0)
-    esd_sample_play(gnome_sound_connection_get (), t->u.media.cache_id);
+    gnome_sound_play_cached(t->u.media.cache_id);
   else if(t->u.media.cache_id == -1)
     gnome_sound_play(t->u.media.file);
-#endif
 }
 
Index: libgnome/libgnome-2.0.pc.in
===================================================================
RCS file: /cvs/gnome/libgnome/libgnome/libgnome-2.0.pc.in,v
retrieving revision 1.13
diff -u -r1.13 libgnome-2.0.pc.in
--- libgnome/libgnome-2.0.pc.in	30 Oct 2001 17:28:46 -0000	1.13
+++ libgnome/libgnome-2.0.pc.in	14 May 2002 17:57:51 -0000
@@ -5,7 +5,7 @@
 
 Name: libgnome
 Description: libgnome
-Requires: glib-2.0 ORBit-2.0 libbonobo-2.0 gconf-2.0 gnome-vfs-2.0
+Requires: glib-2.0 ORBit-2.0 libbonobo-2.0 gconf-2.0 gnome-vfs-2.0 monkey-media
 Version: @VERSION@
 Libs: -L${libdir} -lgnome-2
 Cflags: -I${includedir}/libgnome-2.0
Index: schemas/desktop_gnome_sound.schemas
===================================================================
RCS file: /cvs/gnome/libgnome/schemas/desktop_gnome_sound.schemas,v
retrieving revision 1.1
diff -u -r1.1 desktop_gnome_sound.schemas
--- schemas/desktop_gnome_sound.schemas	26 Mar 2002 15:49:37 -0000	1.1
+++ schemas/desktop_gnome_sound.schemas	14 May 2002 17:57:51 -0000
@@ -2,17 +2,6 @@
 <gconfschemafile>
   <schemalist>
     <schema>
-      <applyto>/desktop/gnome/sound/enable_esd</applyto>
-      <key>/schemas/desktop/gnome/sound/enable_esd</key>
-      <owner>gnome</owner>
-      <type>bool</type>
-      <default>false</default>
-      <locale name="C">
-        <short>Enable ESD</short>
-        <long>Enable sound server startup.</long>
-      </locale>
-    </schema>
-    <schema>
       <applyto>/desktop/gnome/sound/event_sounds</applyto>
       <key>/schemas/desktop/gnome/sound/event_sounds</key>
       <owner>gnome</owner>
? stamp-h1
Index: ChangeLog
===================================================================
RCS file: /cvs/gnome/libgnomeui/ChangeLog,v
retrieving revision 1.171
diff -u -r1.171 ChangeLog
--- ChangeLog	13 May 2002 20:18:39 -0000	1.171
+++ ChangeLog	14 May 2002 17:47:58 -0000
@@ -1,3 +1,8 @@
+2002-05-14  Jorn Baayen  <jorn nl linux org>
+
+	* configure.in:
+	* libgnomeui/gnome-ui-init.c: remove esd stuff
+
 2002-05-13  Anders Carlsson  <andersca gnu org>
 
 	* configure.in: Release 1.117.0
Index: configure.in
===================================================================
RCS file: /cvs/gnome/libgnomeui/configure.in,v
retrieving revision 1.94
diff -u -r1.94 configure.in
--- configure.in	13 May 2002 20:18:39 -0000	1.94
+++ configure.in	14 May 2002 17:47:58 -0000
@@ -54,20 +54,7 @@
 dnl Start of pkg-config checks
 dnl
 
-dnl We first check for esound and audiofile (which has conditional
-dnl support built in)
-dnl
-AUDIOFILE_MODULE="audiofile >= 0.2.3"
-ESOUND_MODULE="esound >= 0.2.25"
-PKG_CHECK_MODULES(SOUND_TEST, $ESOUND_MODULE $AUDIOFILE_MODULE, [
-	AC_DEFINE(HAVE_LIBAUDIOFILE)
-	AC_DEFINE(HAVE_ESD)
-],[
-	AUDIOFILE_MODULE=""
-	ESOUND_MODULE=""
-])
-
-GNOMEUI_MODULES="libgnome-2.0 >= 1.116.0 libgnomecanvas-2.0 >= 1.116.0 libbonoboui-2.0 >= 1.116.0 gconf-2.0 >= 1.1.10"
+GNOMEUI_MODULES="libgnome-2.0 >= 1.116.0 libgnomecanvas-2.0 >= 1.116.0 libbonoboui-2.0 >= 1.116.0 gconf-2.0 >= 1.1.10 monkey-media >= 0.5.0"
 PKG_CHECK_MODULES(LIBGNOMEUI, $GNOMEUI_MODULES)
 AC_SUBST(LIBGNOMEUI_CFLAGS)
 AC_SUBST(LIBGNOMEUI_LIBS)
Index: libgnomeui/gnome-ui-init.c
===================================================================
RCS file: /cvs/gnome/libgnomeui/libgnomeui/gnome-ui-init.c,v
retrieving revision 1.178
diff -u -r1.178 gnome-ui-init.c
--- libgnomeui/gnome-ui-init.c	14 Mar 2002 00:23:01 -0000	1.178
+++ libgnomeui/gnome-ui-init.c	14 May 2002 17:47:59 -0000
@@ -276,7 +276,6 @@
                 libgnomeui_segv_setup (app, FALSE);
 }
 
-#ifdef HAVE_ESD
 static gboolean
 relay_gtk_signal(GSignalInvocationHint *hint,
 		 guint n_param_values,
@@ -307,19 +306,14 @@
 
   return TRUE;
 }
-#endif
 
 static void
 initialize_gtk_signal_relay (void)
 {
-#ifdef HAVE_ESD
 	gpointer iter_signames;
 	char *signame;
 	char *ctmp, *ctmp2;
 	
-	if (gnome_sound_connection_get () < 0)
-		return;
-	
 	if (!gnome_config_get_bool ("/sound/system/settings/event_sounds=true"))
 		return;
 	
@@ -381,7 +375,6 @@
                         g_free(signame);
 	}
 	gnome_config_pop_prefix ();
-#endif
 }
 
 static void
? stamp-h1
? help/C/omf_timestamp
Index: ChangeLog
===================================================================
RCS file: /cvs/gnome/gnome-control-center/ChangeLog,v
retrieving revision 1.488
diff -u -r1.488 ChangeLog
--- ChangeLog	12 May 2002 08:59:56 -0000	1.488
+++ ChangeLog	14 May 2002 18:01:14 -0000
@@ -1,3 +1,11 @@
+2002-05-14  Jorn Baayen  <jorn nl linux org>
+
+	* configure.in:
+	* capplets/sound/sound-properties-capplet.c:
+	* capplets/sound/sound-properties.glade:
+	* gnome-settings-daemon/gnome-settings-sound.c: port to new
+	gnome-sound stuff
+
 2002-05-12  Anders Carlsson  <andersca gnu org>
 
 	* configure.in: Require a new libglade.
Index: configure.in
===================================================================
RCS file: /cvs/gnome/gnome-control-center/configure.in,v
retrieving revision 1.334
diff -u -r1.334 configure.in
--- configure.in	12 May 2002 08:59:56 -0000	1.334
+++ configure.in	14 May 2002 18:01:14 -0000
@@ -51,11 +51,11 @@
 COMMON_MODULES="gtk+-2.0 gconf-2.0 libgnomeui-2.0 libglade-2.0 >= 1.99.12 libbonobo-2.0 libbonoboui-2.0 libglade-2.0 gconf-2.0 gnome-desktop-2.0"
 PKG_CHECK_MODULES(CAPPLET, $COMMON_MODULES)
 PKG_CHECK_MODULES(GNOMECC, $COMMON_MODULES libxml-2.0 gnome-desktop-2.0 gnome-vfs-2.0)
-PKG_CHECK_MODULES(GNOME_SETTINGS_DAEMON, gtk+-2.0 gconf-2.0 libgnomeui-2.0 esound)
+PKG_CHECK_MODULES(GNOME_SETTINGS_DAEMON, gtk+-2.0 gconf-2.0 libgnomeui-2.0 monkey-media >= 0.5.0)
 PKG_CHECK_MODULES(OLD_CAPPLET, libgnomeui-2.0 libglade-2.0)
 PKG_CHECK_MODULES(GNOME, libgnomeui-2.0)
 PKG_CHECK_MODULES(VFS_CAPPLET, $COMMON_MODULES gnome-vfs-module-2.0 gnome-vfs-2.0)
-PKG_CHECK_MODULES(SOUND_CAPPLET, esound)
+PKG_CHECK_MODULES(SOUND_CAPPLET, monkey-media >= 0.5.0)
 
 CAPPLET_LIBS="$CAPPLET_LIBS $x_libs"
 GNOMECC_LIBS="$GNOMECC_LIBS $x_libs"
Index: capplets/sound/sound-properties-capplet.c
===================================================================
RCS file: /cvs/gnome/gnome-control-center/capplets/sound/sound-properties-capplet.c,v
retrieving revision 1.31
diff -u -r1.31 sound-properties-capplet.c
--- capplets/sound/sound-properties-capplet.c	8 May 2002 15:24:50 -0000	1.31
+++ capplets/sound/sound-properties-capplet.c	14 May 2002 18:01:14 -0000
@@ -92,9 +92,6 @@
 {
 	GObject *peditor;
 
-	peditor = gconf_peditor_new_boolean (NULL, "/desktop/gnome/sound/enable_esd", WID ("enable_toggle"), NULL);
-	gconf_peditor_widget_set_guard (GCONF_PROPERTY_EDITOR (peditor), WID ("events_toggle"));
-	gconf_peditor_widget_set_guard (GCONF_PROPERTY_EDITOR (peditor), WID ("events_vbox"));
 	peditor = gconf_peditor_new_boolean (NULL, "/desktop/gnome/sound/event_sounds", WID ("events_toggle"), NULL);
 }
 
@@ -114,7 +111,6 @@
 	gboolean val_bool, def;
 
 	client = gconf_client_get_default ();
-	COPY_FROM_LEGACY (bool, "/desktop/gnome/sound/enable_esd", "/sound/system/settings/start_esd=false");
 	COPY_FROM_LEGACY (bool, "/desktop/gnome/sound/event_sounds", "/sound/system/settings/event_sounds=false");
 	g_object_unref (G_OBJECT (client));
 }
Index: capplets/sound/sound-properties.glade
===================================================================
RCS file: /cvs/gnome/gnome-control-center/capplets/sound/sound-properties.glade,v
retrieving revision 1.7
diff -u -r1.7 sound-properties.glade
--- capplets/sound/sound-properties.glade	28 Mar 2002 01:10:53 -0000	1.7
+++ capplets/sound/sound-properties.glade	14 May 2002 18:01:14 -0000
@@ -30,24 +30,6 @@
             <property name="visible">yes</property>
 
             <child>
-              <widget class="GtkCheckButton" id="enable_toggle">
-                <property name="can_focus">yes</property>
-                <property name="label" translatable="yes">E_nable sound server startup</property>
-                <property name="active">no</property>
-                <property name="draw_indicator">yes</property>
-                <property name="visible">yes</property>
-	    	<property name="use_underline">yes</property>
-
-                <signal name="toggled" handler="enable_toggled_cb" />
-              </widget>
-              <packing>
-                <property name="padding">0</property>
-                <property name="expand">no</property>
-                <property name="fill">no</property>
-              </packing>
-            </child>
-
-            <child>
               <widget class="GtkCheckButton" id="events_toggle">
                 <property name="can_focus">yes</property>
                 <property name="label" translatable="yes">_Sounds for events</property>
Index: gnome-settings-daemon/gnome-settings-sound.c
===================================================================
RCS file: /cvs/gnome/gnome-control-center/gnome-settings-daemon/gnome-settings-sound.c,v
retrieving revision 1.6
diff -u -r1.6 gnome-settings-sound.c
--- gnome-settings-daemon/gnome-settings-sound.c	30 Apr 2002 09:45:05 -0000	1.6
+++ gnome-settings-daemon/gnome-settings-sound.c	14 May 2002 18:01:15 -0000
@@ -6,6 +6,8 @@
  *
  * Written by Rachel Hestilow <hestilow ximian com>
  *
+ * Ported to MonkeyMedia by Jorn Baayen <jorn nl linux org>
+ *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
  * the Free Software Foundation; either version 2, or (at your option)
@@ -29,7 +31,6 @@
 #include <string.h>
 #include <stdlib.h>
 #include <time.h>
-#include <esd.h>
 #include <sys/types.h>
 
 #include <gconf/gconf-client.h>
@@ -42,50 +43,6 @@
 #include "gnome-settings-sound.h"
 #include "gnome-settings-daemon.h"
 
-/* start_esd
- *
- * Start the Enlightenment Sound Daemon. 
- */
-static void
-start_esd (void) 
-{
-        int esdpid;
-        static const char *esd_cmdline[] = {"esd", "-nobeeps", NULL};
-        char *tmpargv[3];
-        char argbuf[32];
-        time_t starttime;
-        GnomeClient *client = gnome_master_client ();
-
-	g_print (_("Starting esd\n"));
-        esdpid = gnome_execute_async (NULL, 2, (char **)esd_cmdline);
-        g_snprintf (argbuf, sizeof (argbuf), "%d", esdpid);
-        tmpargv[0] = "kill"; tmpargv[1] = argbuf; tmpargv[2] = NULL;
-        gnome_client_set_shutdown_command (client, 2, tmpargv);
-        starttime = time (NULL);
-        gnome_sound_init (NULL);
-
-        while (gnome_sound_connection_get () < 0
-	       && ((time(NULL) - starttime) < 4)) 
-        {
-#ifdef HAVE_USLEEP
-                usleep(1000);
-#endif
-                gnome_sound_init(NULL);
-        }
-}
-
-/* stop_esd
- *
- * Stop the Enlightenment Sound Daemon. 
- */
-static void
-stop_esd (void) 
-{
-	g_print (_("Stopping esd\n"));
-	/* Can't think of a way to do this reliably, so we fake it for now */
-	esd_standby (gnome_sound_connection_get ());
-}
-
 /* reload_foreach_cb
  *
  * For a given SoundEvent, reload the sound file associate with the event. 
@@ -94,15 +51,8 @@
 reload_foreach_cb (SoundEvent *event, gpointer data)
 {
 	gchar *file, *tmp, *key;
-	int sid;
 	
 	key = sound_event_compose_key (event);
-	/* We need to free up the old sample, because
-	 * esd allows multiple samples with the same name,
-	 * putting memory to waste. */
-	sid = esd_sample_getid(gnome_sound_connection_get (), key);
-	if (sid >= 0)
-		esd_sample_free(gnome_sound_connection_get (), sid);
 
 	if (!event->file || !strcmp (event->file, ""))
 		return;
@@ -121,12 +71,8 @@
 		return;
 	}
 
-	sid = gnome_sound_sample_load (key, file);
+	gnome_sound_cache (file, key);
 	
-	if (sid < 0)
-		g_warning (_("Couldn't load sound file %s as sample %s"),
-			   file, key);
-
 	g_free (key);
 }
 
@@ -139,19 +85,12 @@
 	static int event_changed_old = 0;
 	int event_changed_new;
 
-	gboolean enable_esd;
 	gboolean event_sounds;
 
 	client = gconf_client_get_default ();
 
-	enable_esd        = gconf_client_get_bool (client, "/desktop/gnome/sound/enable_esd", NULL);
 	event_sounds      = gconf_client_get_bool (client, "/desktop/gnome/sound/event_sounds", NULL);
 	event_changed_new = gconf_client_get_int  (client, "/desktop/gnome/sound/event_changed", NULL);
-
-	if (enable_esd && gnome_sound_connection_get () < 0)
-		start_esd ();
-	else if (!enable_esd)
-		stop_esd ();
 
 	if (!inited || event_changed_old != event_changed_new)
 	{


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