[Freeciv-Dev] (PR#40582) GStreamer audio plugin

2008-11-26 Thread Thijs Vermeir

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);
+  

[Freeciv-Dev] (PR#40582) GStreamer audio plugin

2008-11-26 Thread Madeline Book

URL: http://bugs.freeciv.org/Ticket/Display.html?id=40582 

 [EMAIL PROTECTED] - Thu Nov 27 00:35:28 2008]:
 
 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.

When compiling with --enable-debug I get the following errors:

audio_gst.c: In function `my_shutdown':
audio_gst.c:40: warning: unused variable `ret'
audio_gst.c: In function `my_play':
audio_gst.c:83: warning: implicit declaration of function `g_strcmp0'

These can be easily fixed (please always use --enable-debug
for testing patches).


When I use the gst plugin and a sound should be played, instead
no sound is produced and I get the following error messages
from the client:

(unknown:18419): GStreamer-CRITICAL **: gst_object_ref: assertion 
`object != NULL' failed

(unknown:18419): GStreamer-CRITICAL **: gst_bin_add: assertion 
`GST_IS_ELEMENT (element)' failed

(unknown:18419): GLib-GObject-CRITICAL **: g_object_set: assertion 
`G_IS_OBJECT (object)' failed

It could be that my system is not setup right for gstreamer
(I had to install gstreamer-0.10.21 from source to get configure
to recognize it). Maybe I need some specific gstreamer plugins
or something?


The style is good, it is just not the freeciv coding style. :)
Check out: http://freeciv.wikia.com/wiki/Coding_Style

If in doubt look at recent patches that were committed and
try to match their style (or just ask if the guide is not
clear).


---
すみません、急いでいるんです。

___
Freeciv-dev mailing list
Freeciv-dev@gna.org
https://mail.gna.org/listinfo/freeciv-dev