From b678c8ca85a2eb79c14f56fde3da93bdde6568b0 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Tue, 3 Mar 2009 17:37:48 +0000 Subject: [PATCH] Added SDL audio support for reading from ffmpeg movies --- examples/osgmovie/CMakeLists.txt | 9 ++++- examples/osgmovie/osgmovie.cpp | 65 ++++++++++++++++++++++++++++---- 2 files changed, 66 insertions(+), 8 deletions(-) diff --git a/examples/osgmovie/CMakeLists.txt b/examples/osgmovie/CMakeLists.txt index c0cdafbef..f7d0fb296 100644 --- a/examples/osgmovie/CMakeLists.txt +++ b/examples/osgmovie/CMakeLists.txt @@ -1,9 +1,16 @@ # INCLUDE_DIRECTORIES( ${OPENAL_INCLUDE_DIR} ) +# SET(TARGET_EXTERNAL_LIBRARIES ${OPENAL_LIBRARY} alut) + +IF (SDL_FOUND) + SET(TARGET_EXTERNAL_LIBRARIES ${SDL_LIBRARY} ) + INCLUDE_DIRECTORIES(${SDL_INCLUDE_DIR} ) + ADD_DEFINITIONS(-DUSE_SDL) +ENDIF(SDL_FOUND) SET(TARGET_SRC osgmovie.cpp ) SET(TARGET_ADDED_LIBRARIES osgGA ) -# SET(TARGET_EXTERNAL_LIBRARIES ${OPENAL_LIBRARY} alut) + #### end var setup ### SETUP_EXAMPLE(osgmovie) diff --git a/examples/osgmovie/osgmovie.cpp b/examples/osgmovie/osgmovie.cpp index 1a5336d88..232c4b201 100644 --- a/examples/osgmovie/osgmovie.cpp +++ b/examples/osgmovie/osgmovie.cpp @@ -320,30 +320,79 @@ osg::Geometry* myCreateTexturedQuadGeometry(const osg::Vec3& pos,float width,flo } } -class CustomAudioSink : public osg::AudioSink +#if USE_SDL + +#include "SDL.h" + +class SDLAudioSink : public osg::AudioSink { public: - CustomAudioSink(osg::AudioStream* audioStream): + SDLAudioSink(osg::AudioStream* audioStream): _playing(false), _audioStream(audioStream) {} + ~SDLAudioSink() + { + if (_playing) + { + + SDL_PauseAudio(1); + SDL_CloseAudio(); + + osg::notify(osg::NOTICE)<<"~SDLAudioSink() destructor, but still playing"< _audioStream; }; + +void SDLAudioSink::soundReadCallback(void * const user_data, Uint8 * const data, const int datalen) +{ + osg::notify(osg::NOTICE)<<"SDLAudioSink::soundReadCallback"<(user_data); + osg::ref_ptr as = sink->_audioStream.get(); + if (as.valid()) + { + as->consumeAudioBuffer(data, datalen); + } +} + +#endif + int main(int argc, char** argv) { // use an ArgumentParser object to manage the program arguments. @@ -450,8 +499,8 @@ int main(int argc, char** argv) bool xyPlane = fullscreen; - bool useOpenALAudio = false; - while(arguments.read("--OpenAL")) { useOpenALAudio = true; } + bool useAudioSink = false; + while(arguments.read("--audio")) { useAudioSink = true; } for(int i=1;igetAudioStreams(); - if (useOpenALAudio && !audioStreams.empty()) + if (useAudioSink && !audioStreams.empty()) { osg::AudioStream* audioStream = audioStreams[0].get(); osg::notify(osg::NOTICE)<<"AudioStream read ["<getName()<<"]"<setAudioSink(new CustomAudioSink(audioStream)); +#if USE_SDL + audioStream->setAudioSink(new SDLAudioSink(audioStream)); +#endif }