Delayed sound initialization.




Hello guys,

   I have implemented delayed sound initialization, and I would like a
few people to try this out.  It should improve startup time for most
GNOME applications.

   Patch included.

Cheers,
Miguel.

Index: gnome-sound.c
===================================================================
RCS file: /cvs/gnome/gnome-libs/libgnome/gnome-sound.c,v
retrieving revision 1.17
diff -u -r1.17 gnome-sound.c
--- gnome-sound.c	1999/10/05 13:15:22	1.17
+++ gnome-sound.c	2000/07/12 00:38:46
@@ -31,6 +31,8 @@
 #include <esd.h>
 #endif
 
+static char *esound_hostname;
+
 int gnome_sound_connection = -1;
 
 typedef struct _sample
@@ -63,6 +65,25 @@
 ( ( x & 0xff000000 ) >> 24 ) )
 #endif
 
+/*
+ * This does delayed initialization of Esound
+ */
+static gboolean
+use_sound (void)
+{
+  if (gnome_sound_connection == -1){
+    if (esound_hostname){
+      gnome_sound_connection = esd_open_sound (esound_hostname);
+      if (gnome_sound_connection == -1){
+	g_free (esound_hostname);
+	esound_hostname = NULL;
+	return FALSE;
+      }
+    }
+  }
+  return TRUE;
+}
+
 /**
  * gnome_sound_sample_load_wav:
  * @file: filename to try loading a WAV file from.
@@ -367,7 +388,7 @@
   int size;
   int confirm = 0;
 
-  if(gnome_sound_connection < 0)
+  if (!use_sound ())
     return -2;
 
   if(!filename || !*filename)
@@ -436,7 +457,8 @@
   char buf[23];
   int sample;
 
-  if(gnome_sound_connection < 0) return;
+  if(!use_sound ())
+    return;
 
   srand(time(NULL));
   g_snprintf(buf, sizeof(buf), "%d-%d", getpid(), rand());
@@ -458,6 +480,7 @@
 gnome_sound_init(const char *hostname)
 {
 #ifdef HAVE_ESD
+  esound_hostname = g_strdup (hostname);
   if(gnome_sound_connection < 0)
     gnome_sound_connection = esd_open_sound((char *)hostname);
 #endif
@@ -475,6 +498,8 @@
 	if(gnome_sound_connection >= 0){
 		esd_close(gnome_sound_connection);
 		gnome_sound_connection = -1;
+		g_free (esound_hostname);
+		esound_hostname = NULL;
 	}
 #endif
 }




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