URL: http://bugs.freeciv.org/Ticket/Display.html?id=40582
Hello all,
I tried to make a GStreamer audio plugin for Freeciv. It's a work in
progress but it already works well. It's my first contribution so,
please let me know if there are any rules I break.
I'm working on a Linux machine so I didn't test this on other
platforms but because GStreamer can run on all the other supported
platforms it should not be a problem I think.
Gr,
Thijs
---
client/Makefile.am | 20 -
client/audio.c | 17 -
client/audio_gst.c | 180 +
client/audio_gst.h | 18 +
configure.ac | 13 +++
5 files changed, 240 insertions(+), 8 deletions(-)
--- freeciv.orig/client/Makefile.am
+++ freeciv/client/Makefile.am
@@ -33,11 +33,17 @@
AUDIO_SDL_FILES=$(ALL_AUDIO_SDL_FILES)
endif
+ALL_AUDIO_GST_FILES=audio_gst.c audio_gst.h
+
+if AUDIO_GST
+AUDIO_GST_FILES=$(ALL_AUDIO_GST_FILES)
+endif
+
if MINGW32
CLIENTICON=../win32/clienticon.o
endif
-EXTRA_DIST= $(ALL_AUDIO_SDL_FILES)
+EXTRA_DIST= $(ALL_AUDIO_SDL_FILES) $(ALL_AUDIO_GST_FILES)
## This is usually false, so include is not recursed into
## by 'make', but it can be enabled in configure, and it is
@@ -53,9 +59,10 @@
bin_PROGRAMS = civclient
-AM_CPPFLAGS = -I$(top_srcdir)/utility -I$(srcdir)/include -I$(top_srcdir)/common -I$(top_srcdir)/common/aicore -I$(srcdir)/agents $(CLIENT_CFLAGS) $(SOUND_CFLAGS) $(LIBGGZ_INCLUDES) $(GGZMOD_INCLUDES) $(GGZ_GTK_INCLUDES)
+AM_CPPFLAGS = -I$(top_srcdir)/utility -I$(srcdir)/include -I$(top_srcdir)/common -I$(top_srcdir)/common/aicore -I$(srcdir)/agents $(CLIENT_CFLAGS) $(SOUND_CFLAGS) $(LIBGGZ_INCLUDES) $(GGZMOD_INCLUDES) $(GGZ_GTK_INCLUDES) $(GSTREAMER_CFLAGS)
civclient_SOURCES = $(AUDIO_SDL_FILES) \
+ $(AUDIO_GST_FILES) \
attribute.h \
attribute.c \
citydlg_common.c \
@@ -114,9 +121,9 @@
themes_common.h \
tilespec.c \
tilespec.h \
- audio.c \
- audio.h \
- audio_none.c\
+ audio.c \
+ audio.h \
+ audio_none.c \
audio_none.h
# packhand_gen.c packhand_gen.h are generated files, but as they are
@@ -132,7 +139,8 @@
$(gui_sources)/libguiclient.a
civclient_DEPENDENCIES = $(fc_civclient_libs)
civclient_LDADD= $(fc_civclient_libs) $(fc_civclient_libs) \
- $(INTLLIBS) $(CLIENT_LIBS) $(SOUND_LIBS) $(LIB_GGZMOD) $(CLIENTICON)
+ $(INTLLIBS) $(CLIENT_LIBS) $(SOUND_LIBS) $(LIB_GGZMOD) $(CLIENTICON) \
+ $(GSTREAMER_LIBS)
desktopfiledir = $(prefix)/share/applications
desktopfile_DATA = \
freeciv.desktop
--- freeciv.orig/client/audio.c
+++ freeciv/client/audio.c
@@ -29,13 +29,18 @@
#include support.h
#include audio_none.h
+
+#ifdef AUDIO_GST
+#include audio_gst.h
+#endif
+
#ifdef AUDIO_SDL
#include audio_sdl.h
#endif
#include audio.h
-#define MAX_NUM_PLUGINS 2
+#define MAX_NUM_PLUGINS 3
#define SNDSPEC_SUFFIX .soundspec
/* keep it open throughout */
@@ -142,6 +147,10 @@
assert(num_plugins_used == 1);
selected_plugin = 0;
+#ifdef AUDIO_GST
+ audio_gst_init ();
+#endif
+
#ifdef AUDIO_SDL
audio_sdl_init();
#endif
@@ -248,8 +257,12 @@
return;
}
+#ifdef AUDIO_GST
+ if (audio_select_plugin (gst)) return;
+#endif
+
#ifdef AUDIO_SDL
- if (audio_select_plugin(sdl)) return;
+ if (audio_select_plugin(sdl)) return;
#endif
freelog(LOG_NORMAL, _(No real audio subsystem managed to initialize!));
freelog(LOG_NORMAL,
--- /dev/null
+++ freeciv/client/audio_gst.c
@@ -0,0 +1,180 @@
+/**
+ Freeciv - Copyright (C) 2008 Thijs Vermeir [EMAIL PROTECTED]
+ 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)
+ any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+***/
+
+#ifdef HAVE_CONFIG_H
+#include config.h
+#endif
+
+#include string.h
+
+#include support.h
+
+#include audio.h
+#include gui_main_g.h
+
+#include audio_gst.h
+
+#include gst/gst.h
+
+static void my_stop(void);
+static void my_wait(void);
+
+GstElement *pipeline;
+GstElement *playbin;
+gchar *last_fullpath;
+GMutex *audio_lock;
+
+static void my_shutdown(void)
+{
+ GstState new_state;
+ GstStateChangeReturn ret;
+
+ gst_element_set_state (GST_ELEMENT (pipeline), GST_STATE_NULL);
+ gst_element_get_state (pipeline, new_state, NULL, GST_CLOCK_TIME_NONE);
+
+ gst_object_unref (pipeline);
+ gst_object_unref (playbin);
+ if (last_fullpath)
+g_free (last_fullpath);
+ if (audio_lock)
+g_mutex_free (audio_lock);
+}
+
+static void my_stop(void)
+{
+ g_mutex_lock (audio_lock);
+