Index: /OpenSceneGraph/trunk/src/osgPlugins/ffmpeg/FFmpegDecoder.hpp
===================================================================
--- /OpenSceneGraph/trunk/src/osgPlugins/ffmpeg/FFmpegDecoder.hpp (revision 9847)
+++ /OpenSceneGraph/trunk/src/osgPlugins/ffmpeg/FFmpegDecoder.hpp (revision 9869)
@@ -65,5 +65,5 @@
 
     bool open(const std::string & filename);
-    void close();
+    void close(bool waitForThreadToExit);
 
     bool readNextPacket();
Index: /OpenSceneGraph/trunk/src/osgPlugins/ffmpeg/FFmpegDecoderAudio.cpp
===================================================================
--- /OpenSceneGraph/trunk/src/osgPlugins/ffmpeg/FFmpegDecoderAudio.cpp (revision 9847)
+++ /OpenSceneGraph/trunk/src/osgPlugins/ffmpeg/FFmpegDecoderAudio.cpp (revision 9869)
@@ -38,5 +38,9 @@
     {
         m_exit = true;
+#if 0        
+        while(isRunning()) { OpenThreads::YieldCurrentThread(); }
+#else        
         join();
+#endif
     }
 }
@@ -86,4 +90,14 @@
 
 
+void FFmpegDecoderAudio::close(bool waitForThreadToExit)
+{
+    m_exit = true;
+    
+    if (isRunning() && waitForThreadToExit)
+    {
+        while(isRunning()) { OpenThreads::Thread::YieldCurrentThread(); }
+    }
+}
+
 
 void FFmpegDecoderAudio::run()
@@ -104,5 +118,4 @@
     }
 }
-
 
 
Index: /OpenSceneGraph/trunk/src/osgPlugins/ffmpeg/FFmpegDecoderAudio.hpp
===================================================================
--- /OpenSceneGraph/trunk/src/osgPlugins/ffmpeg/FFmpegDecoderAudio.hpp (revision 9861)
+++ /OpenSceneGraph/trunk/src/osgPlugins/ffmpeg/FFmpegDecoderAudio.hpp (revision 9869)
@@ -30,4 +30,6 @@
 
     void open(AVStream * stream);
+    void close(bool waitForThreadToExit);
+    
     virtual void run();
 
Index: /OpenSceneGraph/trunk/src/osgPlugins/ffmpeg/FFmpegDecoderVideo.cpp
===================================================================
--- /OpenSceneGraph/trunk/src/osgPlugins/ffmpeg/FFmpegDecoderVideo.cpp (revision 9861)
+++ /OpenSceneGraph/trunk/src/osgPlugins/ffmpeg/FFmpegDecoderVideo.cpp (revision 9869)
@@ -35,8 +35,13 @@
     osg::notify(osg::NOTICE)<<"Destructing FFmpegDecoderVideo..."<<std::endl;
 
+
     if (isRunning())
     {
         m_exit = true;
+#if 0        
+        while(isRunning()) { OpenThreads::YieldCurrentThread(); }
+#else        
         join();
+#endif
     }
     
@@ -102,4 +107,14 @@
 }
 
+
+void FFmpegDecoderVideo::close(bool waitForThreadToExit)
+{
+    m_exit = true;
+    
+    if (isRunning() && waitForThreadToExit)
+    {
+        while(isRunning()) { OpenThreads::Thread::YieldCurrentThread(); }
+    }
+}
 
 
Index: /OpenSceneGraph/trunk/src/osgPlugins/ffmpeg/FFmpegImageStream.cpp
===================================================================
--- /OpenSceneGraph/trunk/src/osgPlugins/ffmpeg/FFmpegImageStream.cpp (revision 9861)
+++ /OpenSceneGraph/trunk/src/osgPlugins/ffmpeg/FFmpegImageStream.cpp (revision 9869)
@@ -43,4 +43,10 @@
 
     quit(true);
+    
+    osg::notify(osg::NOTICE)<<"Have done quit"<<std::endl;
+
+    // release athe audio streams to make sure that the decoder doesn't retain any external
+    // refences.
+    getAudioStreams().clear();
 
     // destroy the decoder and associated threads
@@ -131,5 +137,5 @@
 
     // Close the decoder (i.e. flush the decoder packet queues)
-    m_decoder->close();
+    m_decoder->close(waitForThreadToExit);
 }
 
@@ -198,4 +204,6 @@
         osg::notify(osg::WARN) << "FFmpegImageStream::run : unhandled exception" << std::endl;
     }
+    
+    osg::notify(osg::NOTICE)<<"Finished FFmpegImageStream::run()"<<std::endl;
 }
 
Index: /OpenSceneGraph/trunk/src/osgPlugins/ffmpeg/FFmpegDecoderVideo.hpp
===================================================================
--- /OpenSceneGraph/trunk/src/osgPlugins/ffmpeg/FFmpegDecoderVideo.hpp (revision 9861)
+++ /OpenSceneGraph/trunk/src/osgPlugins/ffmpeg/FFmpegDecoderVideo.hpp (revision 9869)
@@ -66,4 +66,6 @@
 
     void open(AVStream * stream);
+    void close(bool waitForThreadToExit);
+
     virtual void run();
 
Index: /OpenSceneGraph/trunk/src/osgPlugins/ffmpeg/FFmpegDecoder.cpp
===================================================================
--- /OpenSceneGraph/trunk/src/osgPlugins/ffmpeg/FFmpegDecoder.cpp (revision 9865)
+++ /OpenSceneGraph/trunk/src/osgPlugins/ffmpeg/FFmpegDecoder.cpp (revision 9869)
@@ -32,5 +32,5 @@
 FFmpegDecoder::~FFmpegDecoder()
 {
-    close();
+    close(true);
 }
 
@@ -124,8 +124,11 @@
 
 
-void FFmpegDecoder::close()
+void FFmpegDecoder::close(bool waitForThreadToExit)
 {
     flushAudioQueue();
     flushVideoQueue();
+    
+    m_audio_decoder.close(waitForThreadToExit);
+    m_video_decoder.close(waitForThreadToExit);
 }
 
