From 68a6bb0f8c5be236fe81af76961c85ac5cd63e22 Mon Sep 17 00:00:00 2001 From: Philip Chimento Date: Sun, 27 Oct 2013 13:55:59 -0700 Subject: [PATCH] Support for GStreamer 1.0 Configure.ac now supports an argument --with-sound, with possible values "no", "auto" (default), "gstreamer0.10", and "gstreamer1.0". The old --with-gstreamer option is removed. Supplying "auto" will pick which sound library is available, preferring 1.0 over 0.10. --- configure.ac | 105 ++++++++++++++++++++++++++++++++---------- libchimara/gestalt.c | 4 +- libchimara/init.c | 9 ++-- libchimara/schannel.c | 55 +++++++++++++--------- libchimara/schannel.h | 4 +- 5 files changed, 122 insertions(+), 55 deletions(-) diff --git a/configure.ac b/configure.ac index 2d89075..e4bfa39 100644 --- a/configure.ac +++ b/configure.ac @@ -2,7 +2,7 @@ ### INITIALIZATION ############################################################ -AC_PREREQ([2.62]) # Oldest version of Autoconf that works with introspection +AC_PREREQ([2.64]) # Newest feature: m4_map_args_w # Initialize Autoconf # Args: (human-readable package name, package version, bug report address, # tarballname) @@ -89,14 +89,39 @@ AM_CONDITIONAL(BUILDING_RPM, $TEST "x$enable_rpm" = xyes) ### SOUND LIBRARY TO USE ###################################################### -AC_ARG_WITH([gstreamer], - [AS_HELP_STRING([--without-gstreamer], [Disable GStreamer sound])], +AC_ARG_WITH([sound], + [AS_HELP_STRING([--with-sound=@<:@no/auto/gstreamer0.10/gstreamer1.0@:>@], + [Choose library with which to implement Glk sound])], [], - [with_gstreamer=yes]) + [with_sound=auto]) + +have_gstreamer0_10=no +have_gstreamer1_0=no +AS_IF([test "x$with_sound" != "xno"], [ + PKG_CHECK_EXISTS([gstreamer-1.0], [have_gstreamer1_0=yes]) + PKG_CHECK_EXISTS([gstreamer-0.10], [have_gstreamer0_10=yes])]) SOUND_MODULE= -AS_IF([$TEST "x$with_gstreamer" != xno], - [AC_DEFINE([GSTREAMER_SOUND], [1], [Define to enable sound support with GStreamer]) - SOUND_MODULE="gstreamer-0.10 >= 0.10.12"]) +# Autodetect sound library +AS_IF([test "x$with_sound" = "xauto"], [ + AC_MSG_CHECKING([which sound library to use]) + AS_IF([test "x$have_gstreamer1_0" = "xyes"], [with_sound=gstreamer1.0], [ + AS_IF([test "x$have_gstreamer0_10" = "xyes"], + [with_sound=gstreamer0.10], + [with_sound=no])]) + AC_MSG_RESULT([$with_sound])]) +# Sound library to use in the end +AS_CASE([$with_sound], + [gstreamer0.10], [ + AC_DEFINE([GSTREAMER_0_10_SOUND], [1], + [Define to enable sound support with GStreamer 0.10]) + SOUND_MODULE="gstreamer-0.10 >= 0.10.12"], + [gstreamer1.0], [ + AC_DEFINE([GSTREAMER_1_0_SOUND], [1], + [Define to enable sound support with GStreamer 1.0]) + SOUND_MODULE="gstreamer-1.0"], + []) +AS_IF([test "x$with_sound" != "xno"], + [AC_DEFINE([HAVE_SOUND], [1], [Define if any sound support is enabled])]) ### WHETHER TO GENERATE A .VAPI FILE ########################################## # Requires vapigen @@ -129,23 +154,55 @@ PKG_CHECK_MODULES([TEST], [ ]) # GStreamer plugins needed to run library -AS_IF([$TEST "x$with_gstreamer" != xno], [ - m4_defun([AX_GST_REQUIRE_ELEMENT], - [AM_GST_ELEMENT_CHECK([$1], - [], - [AC_MSG_ERROR([GStreamer element $1 not found. You need to install gstreamer-plugins-m4_default([$2], [base]).])] - )] - ) - AX_GST_REQUIRE_ELEMENT([giostreamsrc]) - AX_GST_REQUIRE_ELEMENT([typefind]) - AX_GST_REQUIRE_ELEMENT([audioconvert]) - AX_GST_REQUIRE_ELEMENT([volume]) - AX_GST_REQUIRE_ELEMENT([oggdemux]) - AX_GST_REQUIRE_ELEMENT([vorbisdec]) - AX_GST_REQUIRE_ELEMENT([autoaudiosink], [good]) - AX_GST_REQUIRE_ELEMENT([aiffparse], [bad]) - AX_GST_REQUIRE_ELEMENT([modplug], [bad]) -]) +AS_CASE([$with_sound], + [gstreamer0.10], [ + have_all_elements=yes + m4_ifdef([AM_GST_ELEMENT_CHECK], [ + m4_map_args_w([ + giostreamsrc + typefind + audioconvert + volume + oggdemux + vorbisdec + autoaudiosink + aiffparse + modplug], + [AM_GST_ELEMENT_CHECK(], [, [], [have_all_elements=no])]) + AS_IF([test "x$have_all_elements" = "xno"], + [AC_MSG_ERROR([One or more required GStreamer elements were not found. +You will have to install your system's "base", "good", and "bad" plugins +pacakges. Try looking for names such as: gstreamer-plugins-base, +gstreamer-plugins-good, gstreamer-plugins-bad-free, +gstreamer-plugins-bad-free-extras, gstreamer0.10-plugins-base, +gstreamer0.10-plugins-good, gstreamer0.10-plugins-bad])])], + [AC_MSG_ERROR([AM_GST_ELEMENT_CHECK not found. Install the development package +for GStreamer 0.10 and rerun autogen.sh.])]) + ], + [gstreamer1.0], [dnl aiffparse is currently broken in Fedora 19 + have_all_elements=yes + m4_ifdef([GST_ELEMENT_CHECK], [ + m4_map_args_w([ + giostreamsrc + typefind + audioconvert + volume + oggdemux + vorbisdec + autoaudiosink + modplug], + [GST_ELEMENT_CHECK(], [, [1.0], [], [have_all_elements=no])]) + AS_IF([test "x$have_all_elements" = "xno"], + [AC_MSG_ERROR([One or more required GStreamer elements were not found. +You will have to install your system's "base", "good", and "bad" plugins +packages. Try looking for names such as: gstreamer1-plugins-base, +gstreamer1-plugins-good, gstreamer1-plugins-bad-free, +gstreamer1-plugins-bad-free-extras, gstreamer1.0-plugins-base, +gstreamer1.0-plugins-good, gstreamer1.0-plugins-bad])])], + [AC_MSG_ERROR([GST_ELEMENT_CHECK not found. Install the development package +for GStreamer 1.0 and rerun autogen.sh.])]) + ], + []) # Plugin flags; include '-module' in each Makefile.am, because AC_SUBSTed # variables are black boxes to Automake, so it has to know about it being a diff --git a/libchimara/gestalt.c b/libchimara/gestalt.c index 1dad9d9..195733b 100644 --- a/libchimara/gestalt.c +++ b/libchimara/gestalt.c @@ -126,13 +126,13 @@ glk_gestalt_ext(glui32 sel, glui32 val, glui32 *arr, glui32 arrlen) case gestalt_ResourceStream: return 1; - /* Capabilities supported if compiled with GStreamer */ + /* Capabilities supported if compiled with sound support */ case gestalt_Sound: case gestalt_SoundVolume: case gestalt_SoundNotify: case gestalt_SoundMusic: case gestalt_Sound2: -#ifdef GSTREAMER_SOUND +#ifdef HAVE_SOUND return 1; #else return 0; diff --git a/libchimara/init.c b/libchimara/init.c index 0145920..bcf1ad3 100644 --- a/libchimara/init.c +++ b/libchimara/init.c @@ -1,7 +1,7 @@ #include #include #include -#ifdef GSTREAMER_SOUND +#if defined(GSTREAMER_0_10_SOUND) || defined(GSTREAMER_1_0_SOUND) #include #endif @@ -18,13 +18,12 @@ chimara_init(void) bindtextdomain(GETTEXT_PACKAGE, LOCALEDIR); bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8"); -#ifdef GSTREAMER_SOUND +#if defined(GSTREAMER_0_10_SOUND) || defined(GSTREAMER_1_0_SOUND) /* Make sure GStreamer has been initialized if it hasn't been already; in particular, if you want your program to parse GStreamer command line options then you should do it yourself, before gtk_init(). */ - - /* SUCKY DEBIAN: gst_is_initialized() supported from 0.10.30 onward */ - /*if( !gst_is_initialized() )*/ + + if( !gst_is_initialized() ) gst_init(NULL, NULL); #endif } diff --git a/libchimara/schannel.c b/libchimara/schannel.c index b64470d..3c75599 100644 --- a/libchimara/schannel.c +++ b/libchimara/schannel.c @@ -2,9 +2,9 @@ #include #include #include -#ifdef GSTREAMER_SOUND +#if defined(GSTREAMER_0_10_SOUND) || defined(GSTREAMER_1_0_SOUND) #include -#endif +#endif /* GSTREAMER_0_10_SOUND || GSTREAMER_1_0_SOUND */ #include "magic.h" #include "schannel.h" #include "chimara-glk-private.h" @@ -15,9 +15,16 @@ #define VOLUME_TIMER_RESOLUTION 1.0 /* In milliseconds */ +#ifdef GSTREAMER_0_10_SOUND +#define OGG_MIMETYPE "application/ogg" +#endif +#ifdef GSTREAMER_1_0_SOUND +#define OGG_MIMETYPE "audio/ogg" +#endif + extern GPrivate glk_data_key; -#ifdef GSTREAMER_SOUND +#if defined(GSTREAMER_0_10_SOUND) || defined(GSTREAMER_1_0_SOUND) /* Stop any currently playing sound on this channel, and remove any format-specific GStreamer elements from the channel. */ static void @@ -121,7 +128,7 @@ static void on_type_found(GstElement *typefind, guint probability, GstCaps *caps, schanid_t s) { gchar *type = gst_caps_to_string(caps); - if(strcmp(type, "application/ogg") == 0) { + if(strcmp(type, OGG_MIMETYPE) == 0) { s->demux = gst_element_factory_make("oggdemux", NULL); s->decode = gst_element_factory_make("vorbisdec", NULL); if(!s->demux || !s->decode) { @@ -166,7 +173,7 @@ on_type_found(GstElement *typefind, guint probability, GstCaps *caps, schanid_t finally: g_free(type); } -#endif /* GSTREAMER_SOUND */ +#endif /* GSTREAMER_0_10_SOUND || GSTREAMER_1_0_SOUND */ /** * glk_schannel_create: @@ -220,7 +227,7 @@ glk_schannel_create(glui32 rock) schanid_t glk_schannel_create_ext(glui32 rock, glui32 volume) { -#ifdef GSTREAMER_SOUND +#if defined(GSTREAMER_0_10_SOUND) || defined(GSTREAMER_1_0_SOUND) ChimaraGlkPrivate *glk_data = g_private_get(&glk_data_key); schanid_t s = g_new0(struct glk_schannel_struct, 1); @@ -278,7 +285,7 @@ fail: return NULL; #else return NULL; -#endif /* GSTREAMER_SOUND */ +#endif /* GSTREAMER_0_10_SOUND || GSTREAMER_1_0_SOUND */ } /** @@ -293,7 +300,7 @@ glk_schannel_destroy(schanid_t chan) { VALID_SCHANNEL(chan, return); -#ifdef GSTREAMER_SOUND +#if defined(GSTREAMER_0_10_SOUND) || defined(GSTREAMER_1_0_SOUND) ChimaraGlkPrivate *glk_data = g_private_get(&glk_data_key); if(!gst_element_set_state(chan->pipeline, GST_STATE_NULL)) @@ -313,7 +320,7 @@ glk_schannel_destroy(schanid_t chan) chan->magic = MAGIC_FREE; g_free(chan); -#endif +#endif /* GSTREAMER_0_10_SOUND || GSTREAMER_1_0_SOUND */ } /** @@ -335,7 +342,7 @@ glk_schannel_iterate(schanid_t chan, glui32 *rockptr) { VALID_SCHANNEL_OR_NULL(chan, return NULL); -#ifdef GSTREAMER_SOUND +#if defined(GSTREAMER_0_10_SOUND) || defined(GSTREAMER_1_0_SOUND) ChimaraGlkPrivate *glk_data = g_private_get(&glk_data_key); GList *retnode; @@ -352,7 +359,7 @@ glk_schannel_iterate(schanid_t chan, glui32 *rockptr) return retval; #else return NULL; -#endif /* GSTREAMER_SOUND */ +#endif /* GSTREAMER_0_10_SOUND || GSTREAMER_1_0_SOUND */ } /** @@ -442,7 +449,7 @@ glui32 glk_schannel_play_ext(schanid_t chan, glui32 snd, glui32 repeats, glui32 notify) { VALID_SCHANNEL(chan, return 0); -#ifdef GSTREAMER_SOUND +#if defined(GSTREAMER_0_10_SOUND) || defined(GSTREAMER_1_0_SOUND) ChimaraGlkPrivate *glk_data = g_private_get(&glk_data_key); GInputStream *stream; @@ -511,7 +518,7 @@ glk_schannel_play_ext(schanid_t chan, glui32 snd, glui32 repeats, glui32 notify) return 1; #else return 0; -#endif +#endif /* GSTREAMER_0_10_SOUND || GSTREAMER_1_0_SOUND */ } /** @@ -556,7 +563,7 @@ glk_schannel_play_multi(schanid_t *chanarray, glui32 chancount, glui32 *sndarray for(count = 0; count < chancount; count++) VALID_SCHANNEL(chanarray[count], return 0); -#ifdef GSTREAMER_SOUND +#if defined(GSTREAMER_0_10_SOUND) || defined(GSTREAMER_1_0_SOUND) ChimaraGlkPrivate *glk_data = g_private_get(&glk_data_key); GInputStream *stream; @@ -638,7 +645,7 @@ glk_schannel_play_multi(schanid_t *chanarray, glui32 chancount, glui32 *sndarray return successes; #else return 0; -#endif +#endif /* GSTREAMER_0_10_SOUND || GSTREAMER_1_0_SOUND */ } /** @@ -652,7 +659,7 @@ void glk_schannel_stop(schanid_t chan) { VALID_SCHANNEL(chan, return); -#ifdef GSTREAMER_SOUND +#if defined(GSTREAMER_0_10_SOUND) || defined(GSTREAMER_1_0_SOUND) clean_up_after_playing_sound(chan); #endif } @@ -680,6 +687,7 @@ glk_schannel_pause(schanid_t chan) /* Mark the channel as paused even if there is no sound playing yet */ chan->paused = TRUE; +#if defined(GSTREAMER_0_10_SOUND) || defined(GSTREAMER_1_0_SOUND) GstState state; if(gst_element_get_state(chan->pipeline, &state, NULL, GST_CLOCK_TIME_NONE) != GST_STATE_CHANGE_SUCCESS) { WARNING(_("Could not get GstElement state")); @@ -692,6 +700,7 @@ glk_schannel_pause(schanid_t chan) WARNING_S(_("Could not set GstElement state to"), "PAUSED"); return; } +#endif /* GSTREAMER_0_10_SOUND || GSTREAMER_1_0_SOUND */ } /** @@ -719,6 +728,7 @@ glk_schannel_unpause(schanid_t chan) /* Mark the channel as not paused in any case */ chan->paused = FALSE; +#if defined(GSTREAMER_0_10_SOUND) || defined(GSTREAMER_1_0_SOUND) GstState state; if(gst_element_get_state(chan->pipeline, &state, NULL, GST_CLOCK_TIME_NONE) != GST_STATE_CHANGE_SUCCESS) { WARNING(_("Could not get GstElement state")); @@ -731,6 +741,7 @@ glk_schannel_unpause(schanid_t chan) WARNING_S(_("Could not set GstElement state to"), "PLAYING"); return; } +#endif /* GSTREAMER_0_10_SOUND || GSTREAMER_1_0_SOUND */ } /** @@ -775,7 +786,7 @@ volume_glk_to_gstreamer(glui32 volume_glk) return CLAMP(((double)volume_glk / 0x10000), 0.0, 10.0); } -#ifdef GSTREAMER_SOUND +#if defined(GSTREAMER_0_10_SOUND) || defined(GSTREAMER_1_0_SOUND) static gboolean volume_change_timeout(schanid_t chan) { @@ -806,7 +817,7 @@ volume_change_timeout(schanid_t chan) return TRUE; } -#endif /* GSTREAMER_SOUND */ +#endif /* GSTREAMER_0_10_SOUND || GSTREAMER_1_0_SOUND */ /** * glk_schannel_set_volume_ext: @@ -847,7 +858,7 @@ glk_schannel_set_volume_ext(schanid_t chan, glui32 vol, glui32 duration, glui32 VALID_SCHANNEL(chan, return); /* Silently ignore out-of-range volume values */ -#ifdef GSTREAMER_SOUND +#if defined(GSTREAMER_0_10_SOUND) || defined(GSTREAMER_1_0_SOUND) /* Interrupt a previous volume change */ if(chan->volume_timer_id > 0) g_source_remove(chan->volume_timer_id); @@ -874,7 +885,7 @@ glk_schannel_set_volume_ext(schanid_t chan, glui32 vol, glui32 duration, glui32 /* Set up a timer for the volume */ chan->volume_timer_id = g_timeout_add(VOLUME_TIMER_RESOLUTION, (GSourceFunc)volume_change_timeout, chan); -#endif +#endif /* GSTREAMER_0_10_SOUND || GSTREAMER_1_0_SOUND */ } /** @@ -893,7 +904,7 @@ glk_schannel_set_volume_ext(schanid_t chan, glui32 vol, glui32 duration, glui32 void glk_sound_load_hint(glui32 snd, glui32 flag) { -#ifdef GSTREAMER_SOUND +#if defined(GSTREAMER_0_10_SOUND) || defined(GSTREAMER_1_0_SOUND) ChimaraGlkPrivate *glk_data = g_private_get(&glk_data_key); giblorb_result_t resource; giblorb_err_t result; @@ -925,5 +936,5 @@ glk_sound_load_hint(glui32 snd, glui32 flag) return; } } -#endif /* GSTREAMER_SOUND */ +#endif /* GSTREAMER_0_10_SOUND || GSTREAMER_1_0_SOUND */ } diff --git a/libchimara/schannel.h b/libchimara/schannel.h index a0eba87..ab1bee4 100644 --- a/libchimara/schannel.h +++ b/libchimara/schannel.h @@ -6,7 +6,7 @@ #include "glk.h" #include "gi_dispa.h" #include "chimara-glk.h" -#ifdef GSTREAMER_SOUND +#if defined(GSTREAMER_0_10_SOUND) || defined(GSTREAMER_1_0_SOUND) #include #endif @@ -34,7 +34,7 @@ struct glk_schannel_struct guint volume_timer_id; glui32 volume_notify; -#ifdef GSTREAMER_SOUND +#if defined(GSTREAMER_0_10_SOUND) || defined(GSTREAMER_1_0_SOUND) /* Each sound channel is represented as a GStreamer pipeline. */ GstElement *pipeline, *source, *typefind, *demux, *decode, *convert, *filter, *sink; #endif -- 2.30.2