From 5d9bf9f4d5353bba4092adb39b1becc3b3b5b509 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Thu, 7 Jan 2010 14:35:17 +0000 Subject: [PATCH] Added virtual pause() method into osg::AudioSink to support pausing of a movie thread and it's associated audio. Updated osgmovie plugin to use the pause support. --- examples/osgmovie/osgmovie.cpp | 57 +++++++++++++++----- include/osg/AudioStream | 10 ++-- src/osgPlugins/ffmpeg/FFmpegDecoderAudio.cpp | 15 ++++-- src/osgWrappers/osg/AudioStream.cpp | 34 +++++++----- 4 files changed, 82 insertions(+), 34 deletions(-) diff --git a/examples/osgmovie/osgmovie.cpp b/examples/osgmovie/osgmovie.cpp index 803505f88..23961e776 100644 --- a/examples/osgmovie/osgmovie.cpp +++ b/examples/osgmovie/osgmovie.cpp @@ -383,16 +383,21 @@ class SDLAudioSink : public osg::AudioSink public: SDLAudioSink(osg::AudioStream* audioStream): - _playing(false), + _started(false), + _paused(false), _audioStream(audioStream) {} ~SDLAudioSink(); - virtual void startPlaying(); - virtual bool playing() const { return _playing; } + virtual void play(); + virtual void pause(); + virtual void stop(); + + virtual bool playing() const { return _started && !_paused; } - bool _playing; + bool _started; + bool _paused; osg::observer_ptr _audioStream; }; @@ -670,19 +675,24 @@ static void soundReadCallback(void * user_data, uint8_t * data, int datalen) SDLAudioSink::~SDLAudioSink() { - if (_playing) - { - - SDL_PauseAudio(1); - SDL_CloseAudio(); - - osg::notify(osg::NOTICE)<<"~SDLAudioSink() destructor, but still playing"<pause(); + else m_audio_sink->play(); + } + } } void FFmpegDecoderAudio::close(bool waitForThreadToExit) @@ -183,7 +188,7 @@ void FFmpegDecoderAudio::decodeLoop() if (! skip_audio && ! m_audio_sink->playing()) { m_clocks.audioSetDelay(m_audio_sink->getDelay()); - m_audio_sink->startPlaying(); + m_audio_sink->play(); } else { diff --git a/src/osgWrappers/osg/AudioStream.cpp b/src/osgWrappers/osg/AudioStream.cpp index c73529ca9..de138b27d 100644 --- a/src/osgWrappers/osg/AudioStream.cpp +++ b/src/osgWrappers/osg/AudioStream.cpp @@ -28,9 +28,29 @@ BEGIN_ABSTRACT_OBJECT_REFLECTOR(osg::AudioSink) I_Constructor0(____AudioSink, "", ""); - I_Method0(void, startPlaying, + I_Method0(const char *, libraryName, + Properties::VIRTUAL, + __C5_char_P1__libraryName, + "return the name of the object's library. ", + "Must be defined by derived classes. The OpenSceneGraph convention is that the namespace of a library is the same as the library name. "); + I_Method0(const char *, className, + Properties::VIRTUAL, + __C5_char_P1__className, + "return the name of the object's class type. ", + "Must be defined by derived classes. "); + I_Method0(void, play, Properties::PURE_VIRTUAL, - __void__startPlaying, + __void__play, + "", + ""); + I_Method0(void, pause, + Properties::PURE_VIRTUAL, + __void__pause, + "", + ""); + I_Method0(void, stop, + Properties::PURE_VIRTUAL, + __void__stop, "", ""); I_Method0(bool, playing, @@ -48,16 +68,6 @@ BEGIN_ABSTRACT_OBJECT_REFLECTOR(osg::AudioSink) __void__setDelay__C5_double, "", ""); - I_Method0(const char *, libraryName, - Properties::VIRTUAL, - __C5_char_P1__libraryName, - "return the name of the object's library. ", - "Must be defined by derived classes. The OpenSceneGraph convention is that the namespace of a library is the same as the library name. "); - I_Method0(const char *, className, - Properties::VIRTUAL, - __C5_char_P1__className, - "return the name of the object's class type. ", - "Must be defined by derived classes. "); I_SimpleProperty(double, Delay, __double__getDelay, 0);