From f3d05e2699388cd50857cb4cc88319be64fcd032 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sun, 7 Nov 2010 07:17:57 +0000 Subject: [PATCH] - applied Chriss OpenAL patch to make it uzable without GStreamer. SVN r2984 (openal) --- src/CMakeLists.txt | 105 +++++++++++++++--------- src/sound/oalsound.cpp | 178 +++++++++++++++++++++++++++++------------ 2 files changed, 191 insertions(+), 92 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index af135b72c..11df8be43 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -167,11 +167,15 @@ if( WIN32 ) message( STATUS "Looking for al.h - not found" ) endif( OPENAL_INCLUDE_DIR ) - if( NOT OPENAL_INCLUDE_DIR OR NOT GLIB_INCLUDE_DIR OR NOT GST_INCLUDE_DIR ) + if( NOT OPENAL_INCLUDE_DIR ) set( NO_OPENAL ON ) - else( NOT OPENAL_INCLUDE_DIR OR NOT GLIB_INCLUDE_DIR OR NOT GST_INCLUDE_DIR ) - include_directories( ${OPENAL_INCLUDE_DIR} ${GLIB_INCLUDE_DIR} ${GST_INCLUDE_DIR} ) - endif( NOT OPENAL_INCLUDE_DIR OR NOT GLIB_INCLUDE_DIR OR NOT GST_INCLUDE_DIR ) + else( NOT OPENAL_INCLUDE_DIR ) + include_directories( ${OPENAL_INCLUDE_DIR} ) + if( GLIB_INCLUDE_DIR AND GST_INCLUDE_DIR ) + include_directories( ${OPENAL_INCLUDE_DIR} ${GLIB_INCLUDE_DIR} ${GST_INCLUDE_DIR} ) + set( WITH_GSTREAMER ON ) + endif( GLIB_INCLUDE_DIR AND GST_INCLUDE_DIR ) + endif( NOT OPENAL_INCLUDE_DIR ) endif( NOT NO_OPENAL ) @@ -191,38 +195,51 @@ if( WIN32 ) oleaut32 ) if( NOT NO_OPENAL ) - message( STATUS "Looking for GST libraries" ) + message( STATUS "Looking for OpenAL library" ) find_library( OPENAL_LIBRARY NAMES OpenAL32 PATHS ${OPENAL_SEARCH_PATHS} PATH_SUFFIXES lib ) - find_library( GST_LIBRARY1 NAMES gstapp-0.10 - PATHS ${GST_SEARCH_PATHS} - PATH_SUFFIXES lib ) - find_library( GST_LIBRARY2 NAMES gstaudio-0.10 - PATHS ${GST_SEARCH_PATHS} - PATH_SUFFIXES lib ) - find_library( GST_LIBRARY3 NAMES gstreamer-0.10 - PATHS ${GST_SEARCH_PATHS} - PATH_SUFFIXES lib ) - find_library( GST_LIBRARY4 NAMES gthread-2.0 - PATHS ${GST_SEARCH_PATHS} - PATH_SUFFIXES lib ) - find_library( GST_LIBRARY5 NAMES gmodule-2.0 - PATHS ${GST_SEARCH_PATHS} - PATH_SUFFIXES lib ) - find_library( GST_LIBRARY6 NAMES gobject-2.0 - PATHS ${GST_SEARCH_PATHS} - PATH_SUFFIXES lib ) - find_library( GST_LIBRARY7 NAMES glib-2.0 - PATHS ${GST_SEARCH_PATHS} - PATH_SUFFIXES lib ) - if( OPENAL_LIBRARY AND GST_LIBRARY1 AND GST_LIBRARY2 AND GST_LIBRARY3 AND GST_LIBRARY4 AND GST_LIBRARY5 AND GST_LIBRARY6 AND GST_LIBRARY7 ) - set( ZDOOM_LIBS ${ZDOOM_LIBS} "${OPENAL_LIBRARY}" "${GST_LIBRARY1}" "${GST_LIBRARY2}" "${GST_LIBRARY3}" "${GST_LIBRARY4}" "${GST_LIBRARY5}" "${GST_LIBRARY6}" "${GST_LIBRARY7}" ) - message( STATUS "Looking for GST libraries - found" ) - else( OPENAL_LIBRARY AND GST_LIBRARY1 AND GST_LIBRARY2 AND GST_LIBRARY3 AND GST_LIBRARY4 AND GST_LIBRARY5 AND GST_LIBRARY6 AND GST_LIBRARY7 ) + + if( NOT OPENAL_LIBRARY ) set( NO_OPENAL ON ) - message( STATUS "Looking for GST libraries - not found" ) - endif( OPENAL_LIBRARY AND GST_LIBRARY1 AND GST_LIBRARY2 AND GST_LIBRARY3 AND GST_LIBRARY4 AND GST_LIBRARY5 AND GST_LIBRARY6 AND GST_LIBRARY7 ) + message( STATUS "Looking for OpenAL library - not found" ) + else( NOT OPENAL_LIBRARY ) + set( ZDOOM_LIBS ${ZDOOM_LIBS} "${OPENAL_LIBRARY}" ) + message( STATUS "Looking for OpenAL library - found" ) + endif( NOT OPENAL_LIBRARY ) + + if( WITH_GSTREAMER AND NOT NO_OPENAL ) + message( STATUS "Looking for GST libraries" ) + find_library( GST_LIBRARY1 NAMES gstapp-0.10 + PATHS ${GST_SEARCH_PATHS} + PATH_SUFFIXES lib ) + find_library( GST_LIBRARY2 NAMES gstaudio-0.10 + PATHS ${GST_SEARCH_PATHS} + PATH_SUFFIXES lib ) + find_library( GST_LIBRARY3 NAMES gstreamer-0.10 + PATHS ${GST_SEARCH_PATHS} + PATH_SUFFIXES lib ) + find_library( GST_LIBRARY4 NAMES gthread-2.0 + PATHS ${GST_SEARCH_PATHS} + PATH_SUFFIXES lib ) + find_library( GST_LIBRARY5 NAMES gmodule-2.0 + PATHS ${GST_SEARCH_PATHS} + PATH_SUFFIXES lib ) + find_library( GST_LIBRARY6 NAMES gobject-2.0 + PATHS ${GST_SEARCH_PATHS} + PATH_SUFFIXES lib ) + find_library( GST_LIBRARY7 NAMES glib-2.0 + PATHS ${GST_SEARCH_PATHS} + PATH_SUFFIXES lib ) + + if( GST_LIBRARY1 AND GST_LIBRARY2 AND GST_LIBRARY3 AND GST_LIBRARY4 AND GST_LIBRARY5 AND GST_LIBRARY6 AND GST_LIBRARY7 ) + set( ZDOOM_LIBS ${ZDOOM_LIBS} "${GST_LIBRARY1}" "${GST_LIBRARY2}" "${GST_LIBRARY3}" "${GST_LIBRARY4}" "${GST_LIBRARY5}" "${GST_LIBRARY6}" "${GST_LIBRARY7}" ) + message( STATUS "Looking for GST libraries - found" ) + else( GST_LIBRARY1 AND GST_LIBRARY2 AND GST_LIBRARY3 AND GST_LIBRARY4 AND GST_LIBRARY5 AND GST_LIBRARY6 AND GST_LIBRARY7 ) + set( WITH_GSTREAMER OFF ) + message( STATUS "Looking for GST libraries - not found" ) + endif( GST_LIBRARY1 AND GST_LIBRARY2 AND GST_LIBRARY3 AND GST_LIBRARY4 AND GST_LIBRARY5 AND GST_LIBRARY6 AND GST_LIBRARY7 ) + endif( WITH_GSTREAMER AND NOT NO_OPENAL ) endif( NOT NO_OPENAL ) else( WIN32 ) if( APPLE ) @@ -232,12 +249,13 @@ else( WIN32 ) set( NO_GTK ON ) if( NOT NO_OPENAL ) + set( ZDOOM_LIBS ${ZDOOM_LIBS} "-framework OpenAL") + check_library_exists( gstapp-0.10 gst_app_src_set_callbacks "" HAS_GSTAPP ) check_library_exists( gstaudio-0.10 gst_audio_set_channel_positions "" HAS_GSTAUDIO ) if( HAS_GSTAPP AND HAS_GSTAUDIO ) set( ZDOOM_LIBS ${ZDOOM_LIBS} gstapp-0.10 gst-audio-0.10 "-framework OpenAL") - else( HAS_GSTAPP AND HAS_GSTAUDIO ) - set( NO_OPENAL ON ) + set( WITH_GSTREAMER ON ) endif( HAS_GSTAPP AND HAS_GSTAUDIO ) endif( NOT NO_OPENAL ) else( APPLE ) @@ -266,13 +284,20 @@ else( WIN32 ) endif( GTK2_FOUND ) endif( NOT NO_GTK ) - pkg_check_modules( OPENAL openal gstreamer-app-0.10>=0.10.23 gstreamer-audio-0.10 ) - if( OPENAL_FOUND ) + pkg_check_modules( OPENAL openal ) + if( NOT OPENAL_FOUND ) + set( NO_OPENAL ON ) + else( NOT OPENAL_FOUND ) set( ZDOOM_LIBS ${ZDOOM_LIBS} ${OPENAL_LIBRARIES} ) include_directories( ${OPENAL_INCLUDE_DIRS} ) - else( OPENAL_FOUND ) - set( NO_OPENAL ON ) - endif( OPENAL_FOUND ) + + pkg_check_modules( GSTREAMER gstreamer-app-0.10>=0.10.23 gstreamer-audio-0.10 ) + if( GSTREAMER_FOUND ) + set( ZDOOM_LIBS ${ZDOOM_LIBS} ${GSTREAMER_LIBRARIES} ) + include_directories( ${GSTREAMER_INCLUDE_DIRS} ) + set( WITH_GSTREAMER ON ) + endif( GSTREAMER_FOUND ) + endif( NOT OPENAL_FOUND ) endif( APPLE ) set( NASM_NAMES nasm ) @@ -357,6 +382,8 @@ if( NO_FMOD ) endif( NO_FMOD ) if( NO_OPENAL ) add_definitions( -DNO_OPENAL=1 ) +elseif( WITH_GSTREAMER ) + add_definitions( -DWITH_GSTREAMER=1 ) endif( NO_OPENAL ) # Search for FluidSynth diff --git a/src/sound/oalsound.cpp b/src/sound/oalsound.cpp index d64b230e9..7bed39a86 100644 --- a/src/sound/oalsound.cpp +++ b/src/sound/oalsound.cpp @@ -177,7 +177,40 @@ static float GetRolloff(const FRolloffInfo *rolloff, float distance) } -/*** GStreamer start ***/ +static ALenum FormatFromDesc(int bits, int channels) +{ + if(bits == 8) + { + if(channels == 1) return AL_FORMAT_MONO8; + if(channels == 2) return AL_FORMAT_STEREO8; + if(channels == 4) return AL_FORMAT_QUAD8; + if(channels == 6) return AL_FORMAT_51CHN8; + if(channels == 7) return AL_FORMAT_61CHN8; + if(channels == 8) return AL_FORMAT_71CHN8; + } + if(bits == 16) + { + if(channels == 1) return AL_FORMAT_MONO16; + if(channels == 2) return AL_FORMAT_STEREO16; + if(channels == 4) return AL_FORMAT_QUAD16; + if(channels == 6) return AL_FORMAT_51CHN16; + if(channels == 7) return AL_FORMAT_61CHN16; + if(channels == 8) return AL_FORMAT_71CHN16; + } + if(bits == 32) + { + if(channels == 1) return AL_FORMAT_MONO_FLOAT32; + if(channels == 2) return AL_FORMAT_STEREO_FLOAT32; + if(channels == 4) return AL_FORMAT_QUAD32; + if(channels == 6) return AL_FORMAT_51CHN32; + if(channels == 7) return AL_FORMAT_61CHN32; + if(channels == 8) return AL_FORMAT_71CHN32; + } + return AL_NONE; +} + + +#ifdef WITH_GSTREAMER #include #include #include @@ -358,38 +391,6 @@ static GstCaps *SupportedBufferFormatCaps(int forcebits=0) return caps; } -static ALenum FormatFromDesc(int bits, int channels) -{ - if(bits == 8) - { - if(channels == 1) return AL_FORMAT_MONO8; - if(channels == 2) return AL_FORMAT_STEREO8; - if(channels == 4) return AL_FORMAT_QUAD8; - if(channels == 6) return AL_FORMAT_51CHN8; - if(channels == 7) return AL_FORMAT_61CHN8; - if(channels == 8) return AL_FORMAT_71CHN8; - } - if(bits == 16) - { - if(channels == 1) return AL_FORMAT_MONO16; - if(channels == 2) return AL_FORMAT_STEREO16; - if(channels == 4) return AL_FORMAT_QUAD16; - if(channels == 6) return AL_FORMAT_51CHN16; - if(channels == 7) return AL_FORMAT_61CHN16; - if(channels == 8) return AL_FORMAT_71CHN16; - } - if(bits == 32) - { - if(channels == 1) return AL_FORMAT_MONO_FLOAT32; - if(channels == 2) return AL_FORMAT_STEREO_FLOAT32; - if(channels == 4) return AL_FORMAT_QUAD32; - if(channels == 6) return AL_FORMAT_51CHN32; - if(channels == 7) return AL_FORMAT_61CHN32; - if(channels == 8) return AL_FORMAT_71CHN32; - } - return AL_NONE; -} - class OpenALSoundStream : public SoundStream { OpenALSoundRenderer *Renderer; @@ -783,18 +784,21 @@ class OpenALSoundStream : public SoundStream { PrintErrMsg("Prepare Error", msg); ret = GST_STATE_CHANGE_FAILURE; + gst_message_unref(msg); break; } - else if(GST_MESSAGE_TYPE(msg) == GST_MESSAGE_TAG) + else if(GST_MESSAGE_TYPE(msg) != GST_MESSAGE_TAG) { - GstTagList *tags = NULL; - gst_message_parse_tag(msg, &tags); - - gst_tag_list_insert(TagList, tags, GST_TAG_MERGE_KEEP); - - gst_tag_list_free(tags); + gst_message_unref(msg); + break; } - else break; + + GstTagList *tags = NULL; + gst_message_parse_tag(msg, &tags); + + gst_tag_list_insert(TagList, tags, GST_TAG_MERGE_KEEP); + + gst_tag_list_free(tags); gst_message_unref(msg); } } @@ -1403,22 +1407,22 @@ public: if(GST_MESSAGE_TYPE(msg) == GST_MESSAGE_EOS) { err = false; + gst_message_unref(msg); break; } - else if(GST_MESSAGE_TYPE(msg) == GST_MESSAGE_TAG) - { - GstTagList *tags = NULL; - gst_message_parse_tag(msg, &tags); - - gst_tag_list_insert(TagList, tags, GST_TAG_MERGE_KEEP); - - gst_tag_list_free(tags); - } - else if(GST_MESSAGE_TYPE(msg) == GST_MESSAGE_ERROR) + if(GST_MESSAGE_TYPE(msg) != GST_MESSAGE_TAG) { PrintErrMsg("Decoder Error", msg); + gst_message_unref(msg); break; } + + GstTagList *tags = NULL; + gst_message_parse_tag(msg, &tags); + + gst_tag_list_insert(TagList, tags, GST_TAG_MERGE_KEEP); + + gst_tag_list_free(tags); gst_message_unref(msg); } } @@ -1437,8 +1441,8 @@ public: unsigned int looppt[2] = { 0, 0 }; bool looppt_is_samples[2] = { true, true }; bool has_looppt[2] = { false, false }; - HandleLoopTags(looppt, looppt_is_samples, has_looppt); + HandleLoopTags(looppt, looppt_is_samples, has_looppt); if(has_looppt[0] || has_looppt[1]) { if(!has_looppt[0]) @@ -1467,7 +1471,73 @@ public: return !err; } }; -/*** GStreamer end ***/ +#else /* WITH_GSTREAMER */ +class OpenALSoundStream : public SoundStream +{ + OpenALSoundRenderer *Renderer; + +public: + FTempFileName tmpfile; + ALfloat Volume; + + OpenALSoundStream(OpenALSoundRenderer *renderer) + : Renderer(renderer), Volume(1.0f) + { Renderer->Streams.push_back(this); } + + virtual ~OpenALSoundStream() + { + Renderer->Streams.erase(find(Renderer->Streams.begin(), + Renderer->Streams.end(), this)); + Renderer = NULL; + } + + + virtual bool Play(bool, float) + { return false; } + + virtual void Stop() + { } + + virtual void SetVolume(float vol) + { Volume = vol; } + + virtual bool SetPaused(bool) + { return false; } + + virtual unsigned int GetPosition() + { return 0; } + + virtual bool IsEnded() + { return true; } + + bool Init(const char*) + { return false; } + + bool Init(const BYTE*, unsigned int) + { return false; } + + bool Init(SoundStreamCallback, int, int, int, void*) + { return false; } +}; + +class Decoder +{ +public: + std::vector OutData; + ALint LoopPts[2]; + ALsizei OutRate; + ALuint OutChannels; + ALuint OutBits; + + Decoder() + : OutRate(0), OutChannels(0), OutBits(0) + { LoopPts[0] = LoopPts[1] = 0; } + + bool Decode(const void*, unsigned int, int=0) + { return false; } +}; +#endif /* WITH_GSTREAMER */ + template static void LoadALFunc(const char *name, T *x) @@ -1481,6 +1551,7 @@ OpenALSoundRenderer::OpenALSoundRenderer() Printf("I_InitSound: Initializing OpenAL\n"); +#ifdef WITH_GSTREAMER static bool GSTInited = false; if(!GSTInited) { @@ -1493,6 +1564,7 @@ OpenALSoundRenderer::OpenALSoundRenderer() } GSTInited = true; } +#endif if(snd_aldevice != "Default") {