changeset 4581:4b1e24835bbf

[gaim-migrate @ 4864] put NAS sound support back in, and re-wrote a lot of the libao stuff this should mostly put an end to people having to make a ~/.libao file committer: Tailor Script <tailor@pidgin.im>
author Nathan Walp <nwalp@pidgin.im>
date Fri, 14 Feb 2003 20:57:32 +0000
parents 3fef2d45dce0
children ff3b123aed43
files configure.ac configure.in src/gaim.h src/gaimrc.c src/main.c src/prefs.c src/sound.c src/sound.h
diffstat 8 files changed, 112 insertions(+), 52 deletions(-) [+]
line wrap: on
line diff
--- a/configure.ac	Wed Feb 12 17:16:16 2003 +0000
+++ b/configure.ac	Fri Feb 14 20:57:32 2003 +0000
@@ -123,6 +123,7 @@
 	[Loads static protocol plugin module initialization functions.])
 
 AC_ARG_ENABLE(audio,   [  --disable-audio         compile without libao/libaudiofile for sound playing],,enable_audio=yes)
+AC_ARG_ENABLE(nas,     [  --enable-nas            enable NAS (Network Audio System) support],,enable_nas=no)
 AC_ARG_ENABLE(plugins, [  --disable-plugins       compile without plugin support],,enable_plugins=yes)
 AC_ARG_ENABLE(perl,    [  --disable-perl          compile without perl scripting],,enable_perl=yes)
 AC_ARG_ENABLE(gtkspell, [  --disable-gtkspell      compile without GtkSpell automatic spell checking],,enable_gtkspell=yes)
@@ -271,13 +272,18 @@
 	fi
 fi
 
+if test "$enable_nas" = yes ; then
+	AC_DEFINE(USE_NAS_AUDIO, 1, [Define if we have NAS sound support.])
+	SOUND_LIBS="$SOUND_LIBS -laudio -lXt"
+fi
+
 if test "$enable_audio" = yes ; then
 	GAIM_PATH_AO(found_ao_lib=true)
 
 	AM_PATH_AUDIOFILE([0.2.0], found_af_lib=true)
 
 	if test "$found_ao_lib" = "true" -a "$found_af_lib" = "true"; then
-		SOUND_LIBS="$AO_LIBS $AUDIOFILE_LIBS"
+		SOUND_LIBS="$SOUND_LIBS $AO_LIBS $AUDIOFILE_LIBS"
 		AC_SUBST(SOUND_LIBS)
 		AC_DEFINE(USE_AO, 1, [Define if we're using libao and libaudiofile for sound playing])
 		enable_audio=yes
@@ -421,6 +427,7 @@
 echo Build with Plugin support..... : $enable_plugins
 echo Build with Perl support....... : $enable_perl
 echo Build with Audio support...... : $enable_audio
+echo Build with NAS support........ : $enable_nas
 echo Build with GtkSpell support... : $enable_gtkspell
 echo
 echo Use XScreenSaver Extension.... : $enable_xss
--- a/configure.in	Wed Feb 12 17:16:16 2003 +0000
+++ b/configure.in	Fri Feb 14 20:57:32 2003 +0000
@@ -113,6 +113,7 @@
 	[Loads static protocol plugin module initialization functions.])
 
 AC_ARG_ENABLE(audio,   [  --disable-audio         compile without libao/libaudiofile for sound playing],,enable_audio=yes)
+AC_ARG_ENABLE(nas,     [  --enable-nas            enable NAS (Network Audio System) support],,enable_nas=no)
 AC_ARG_ENABLE(plugins, [  --disable-plugins       compile without plugin support],,enable_plugins=yes)
 AC_ARG_ENABLE(perl,    [  --disable-perl          compile without perl scripting],,enable_perl=yes)
 AC_ARG_ENABLE(gtkspell, [  --disable-gtkspell      compile without GtkSpell automatic spell checking],,enable_gtkspell=yes)
@@ -245,13 +246,18 @@
 	fi
 fi
 
+if test "$enable_nas" = yes ; then
+	AC_DEFINE(USE_NAS_AUDIO, 1, [Define if we have NAS sound support.])
+	SOUND_LIBS="$SOUND_LIBS -laudio -lXt"
+fi
+
 if test "$enable_audio" = yes ; then
 	GAIM_PATH_AO(found_ao_lib=true)
 
 	AM_PATH_AUDIOFILE([0.2.0], found_af_lib=true)
 
 	if test "$found_ao_lib" = "true" -a "$found_af_lib" = "true"; then
-		SOUND_LIBS="$AO_LIBS $AUDIOFILE_LIBS"
+		SOUND_LIBS="$SOUND_LIBS $AO_LIBS $AUDIOFILE_LIBS"
 		AC_SUBST(SOUND_LIBS)
 		AC_DEFINE(USE_AO, 1, [Define if we're using libao and libaudiofile for sound playing])
 		enable_audio=yes
@@ -397,6 +403,7 @@
 echo Build with Plugin support..... : $enable_plugins
 echo Build with Perl support....... : $enable_perl
 echo Build with Audio support...... : $enable_audio
+echo Build with NAS support........ : $enable_nas
 echo Build with GtkSpell support... : $enable_gtkspell
 echo
 echo Use XScreenSaver Extension.... : $enable_xss
--- a/src/gaim.h	Wed Feb 12 17:16:16 2003 +0000
+++ b/src/gaim.h	Fri Feb 14 20:57:32 2003 +0000
@@ -308,7 +308,7 @@
 #define OPT_SOUND_CHAT_YOU_SAY		0x00001000
 #define OPT_SOUND_NORMAL		0x00002000
 #define OPT_SOUND_NAS			0x00004000
-#define OPT_SOUND_ARTSC			0x00008000
+#define OPT_SOUND_ARTS			0x00008000
 #define OPT_SOUND_ESD			0x00010000
 #define OPT_SOUND_CMD			0x00020000
 #define OPT_SOUND_CHAT_NICK             0x00040000
--- a/src/gaimrc.c	Wed Feb 12 17:16:16 2003 +0000
+++ b/src/gaimrc.c	Fri Feb 14 20:57:32 2003 +0000
@@ -758,6 +758,7 @@
 			font_options = atoi(p->value[0]);
 		} else if (!strcmp(p->option, "sound_options")) {
 			sound_options = atoi(p->value[0]);
+			gaim_sound_change_output_method();
 		} else if (!strcmp(p->option, "away_options")) {
 			away_options = atoi(p->value[0]);
 			away_resend = atoi(p->value[1]);
@@ -799,7 +800,8 @@
 	}
 
 	/* this is where we do bugs and compatibility stuff */
-	if (!(sound_options & (OPT_SOUND_BEEP | OPT_SOUND_NORMAL | OPT_SOUND_CMD)))
+	if (!(sound_options & (OPT_SOUND_BEEP | OPT_SOUND_NORMAL | OPT_SOUND_ESD
+					| OPT_SOUND_ARTS | OPT_SOUND_NAS | OPT_SOUND_CMD)))
 		sound_options |= OPT_SOUND_NORMAL;
 
 	if (conv_size.width == 0 &&
@@ -822,7 +824,7 @@
 		if (!read_logging) {
 			logging_options = 0;
 			if (general_options & OPT_GEN_LOG_ALL)
-  				logging_options |= OPT_LOG_CONVOS | OPT_LOG_CHATS; 
+				logging_options |= OPT_LOG_CONVOS | OPT_LOG_CHATS;
 			if (general_options & OPT_GEN_STRIP_HTML)
 				logging_options |= OPT_LOG_STRIP_HTML;
 		}
@@ -1232,7 +1234,8 @@
 	    OPT_SOUND_RECV |
 	    OPT_SOUND_SEND |
 	    OPT_SOUND_SILENT_SIGNON |
-	    OPT_SOUND_NORMAL;
+	    OPT_SOUND_NORMAL |
+		OPT_SOUND_NAS;
 
 #ifdef USE_SCREENSAVER
 	report_idle = IDLE_SCREENSAVER;
--- a/src/main.c	Wed Feb 12 17:16:16 2003 +0000
+++ b/src/main.c	Fri Feb 14 20:57:32 2003 +0000
@@ -530,8 +530,6 @@
 
 	setup_stock();
 
-	gaim_sound_init();
-
 #ifndef _WIN32
 	/* use the nice PNG icon for all the windows */
 	icon_path = g_build_filename(DATADIR, "pixmaps", "gaim.png", NULL);
--- a/src/prefs.c	Wed Feb 12 17:16:16 2003 +0000
+++ b/src/prefs.c	Fri Feb 14 20:57:32 2003 +0000
@@ -986,11 +986,16 @@
 #ifndef _WIN32
 	vbox = make_frame (ret, _("Sound Method"));
 	dd = gaim_dropdown(vbox, _("_Method"), &sound_options, OPT_SOUND_BEEP |
-		      OPT_SOUND_NORMAL |
-		      OPT_SOUND_CMD,
+		      OPT_SOUND_ESD | OPT_SOUND_ARTS | OPT_SOUND_NAS |
+			  OPT_SOUND_NORMAL | OPT_SOUND_CMD,
 		      _("Console beep"), OPT_SOUND_BEEP,
 #ifdef USE_AO
 		      _("Automatic"), OPT_SOUND_NORMAL,
+			  "ESD", OPT_SOUND_ESD,
+			  "Arts", OPT_SOUND_ARTS,
+#endif
+#ifdef USE_NAS_AUDIO
+			  "NAS", OPT_SOUND_NAS,
 #endif
 		      _("Command"), OPT_SOUND_CMD, NULL);
 	gtk_size_group_add_widget(sg, dd);
@@ -2300,6 +2305,7 @@
 			gtk_widget_set_sensitive(sndcmd, TRUE);
 		else
 			gtk_widget_set_sensitive(sndcmd, FALSE);
+		gaim_sound_change_output_method();
 	} else if (option == (int*)&im_options) { 
 		if (clear == (OPT_IM_SIDE_TAB | OPT_IM_BR_TAB))
 			gaim_gtkconv_update_tabs();
--- a/src/sound.c	Wed Feb 12 17:16:16 2003 +0000
+++ b/src/sound.c	Fri Feb 14 20:57:32 2003 +0000
@@ -28,23 +28,20 @@
 #include <string.h>
 
 #ifndef _WIN32
-#include <sys/time.h>
-#include <unistd.h>
-#include <sys/wait.h>
 #include <unistd.h>
 #else
 #include <windows.h>
 #include <mmsystem.h>
 #endif
 
-#include <fcntl.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-
 #ifdef USE_AO
 #include <ao/ao.h>
 #include <audiofile.h>
 #endif /* USE_AO */
+#ifdef USE_NAS_AUDIO
+#include <audio/audiolib.h>
+#include <audio/soundlib.h>
+#endif /* USE_NAS_AUDIO */
 
 #include "gaim.h"
 #include "sound.h"
@@ -60,7 +57,8 @@
 };
 
 #ifdef USE_AO
-static int ao_driver;
+static gboolean ao_initialized=FALSE;
+static int ao_driver = -1;
 #endif /* USE_AO */
 
 
@@ -89,37 +87,79 @@
 
 static char *sound_file[GAIM_NUM_SOUNDS];
 
-void gaim_sound_init()
+
+#ifdef USE_AO
+static void check_ao_init()
 {
-#ifdef USE_AO
+	if(!ao_initialized) {
+		debug_printf("Initializing sound ouput drivers.\n");
+		ao_initialize();
+		ao_initialized = TRUE;
+	}
+}
+#endif /* USE_AO */
 
-	ao_initialize();
-	ao_driver = ao_default_driver_id();
+void gaim_sound_change_output_method() {
+#ifdef USE_AO
+	ao_driver = -1;
 
-	if(ao_driver == -1) {
-		debug_printf("No suitable sound ouput driver found.\n");
-	} else {
+	if ((sound_options & OPT_SOUND_ESD) || (sound_options & OPT_SOUND_ARTS) ||
+			(sound_options & OPT_SOUND_NORMAL)) {
+		check_ao_init();
+		if (ao_driver == -1 && (sound_options & OPT_SOUND_ESD)) {
+			ao_driver = ao_driver_id("esd");
+		}
+		if(ao_driver == -1 && (sound_options & OPT_SOUND_ARTS)) {
+			ao_driver = ao_driver_id("arts");
+		}
+		if (ao_driver == -1) {
+			ao_driver = ao_default_driver_id();
+		}
+	}
+	if(ao_driver != -1) {
 		ao_info *info = ao_driver_info(ao_driver);
 		debug_printf("Sound output driver loaded: %s\n", info->name);
 	}
-
-#endif
+#endif /* USE_AO */
+#ifdef USE_NAS
+	if((sound_options & OPT_SOUND_NAS))
+		debug_printf("Sound output driver loaded: NAS output\n");
+#endif /* USE_NAS */
 }
 
 void gaim_sound_quit()
 {
 #ifdef USE_AO
-
-	ao_shutdown();
-
+	if(ao_initialized)
+		ao_shutdown();
 #endif
 }
 
+
+#ifdef USE_NAS_AUDIO
+static gboolean play_file_nas(const char *filename)
+{
+	AuServer *nas_serv;
+	gboolean ret = FALSE;
+
+	if((nas_serv = AuOpenServer(NULL, 0, NULL, 0, NULL, NULL))) {
+		ret = AuSoundPlaySynchronousFromFile(nas_serv, filename, 100);
+		AuCloseServer(nas_serv);
+	}
+
+	return ret;
+}
+
+#endif /* USE_NAS_AUDIO */
+
 void gaim_sound_play_file(char *filename)
 {
-#ifdef USE_AO
+#if defined(USE_NAS_AUDIO) || defined(USE_AO)
 	pid_t pid;
-#endif /* USE_AO */
+#ifdef USE_AO
+	AFfilehandle file;
+#endif
+#endif
 
 	if (mute_sounds)
 		return;
@@ -161,21 +201,20 @@
 		g_free(command);
 		return;
 	}
-#ifdef USE_AO
-
-	if(ao_driver == -1) {
-		/* do _something_ audible ;-) */
-		gdk_beep();
-		return;
-	}
-
-
+#if defined(USE_NAS_AUDIO) || defined(USE_AO)
 	pid = fork();
-
 	if (pid < 0)
 		return;
 	else if (pid == 0) {
-		AFfilehandle file = afOpenFile(filename, "rb", NULL);
+#ifdef USE_NAS_AUDIO
+		if ((sound_options & OPT_SOUND_NAS)) {
+			if (play_file_nas(filename))
+				_exit(0);
+		}
+#endif /* USE_NAS_AUDIO */
+
+#ifdef USE_AO
+		file = afOpenFile(filename, "rb", NULL);
 		if(file) {
 			ao_device *device;
 			ao_sample_format format;
@@ -210,17 +249,17 @@
 						break;
 				}
 				ao_close(device);
-			} else {
-				debug_printf("error opening audio device!\n");
 			}
 			afCloseFile(file);
 		}
+		ao_shutdown();
+#endif /* USE_AO */
 		_exit(0);
 	}
-#else /* USE_AO */
+#else /* USE_NAS_AUDIO || USE_AO */
 	gdk_beep();
 	return;
-#endif /* USE_AO */
+#endif /* USE_NAS_AUDIO || USE_AO */
 #else /* _WIN32 */
 	debug_printf("Playing %s\n", filename);
 	if (!PlaySound(filename, 0, SND_ASYNC | SND_FILENAME))
--- a/src/sound.h	Wed Feb 12 17:16:16 2003 +0000
+++ b/src/sound.h	Fri Feb 14 20:57:32 2003 +0000
@@ -21,8 +21,8 @@
  *
  */
 
-#ifndef _SOUND_H_
-#define _SOUND_H_
+#ifndef _GAIM_SOUND_H_
+#define _GAIM_SOUND_H_
 
 /**************************************************************************/
 /** Data Structures                                                       */
@@ -55,9 +55,9 @@
 /*@{*/
 
 /**
- * Sets up the sound system.
+ * Lets the sound subsystem know when the sound output method has changed.
  */
-void gaim_sound_init();
+void gaim_sound_change_output_method();
 
 /**
  * Properly shuts down the sound system.
@@ -146,4 +146,4 @@
 
 /*@}*/
 
-#endif /* _SOUND_H_ */
+#endif /* _GAIM_SOUND_H_ */