Index: /OpenSceneGraph/trunk/src/osgPlugins/ffmpeg/FFmpegDecoder.hpp
===================================================================
--- /OpenSceneGraph/trunk/src/osgPlugins/ffmpeg/FFmpegDecoder.hpp (revision 9816)
+++ /OpenSceneGraph/trunk/src/osgPlugins/ffmpeg/FFmpegDecoder.hpp (revision 9826)
@@ -3,13 +3,56 @@
 #define HEADER_GUARD_OSGFFMPEG_FFMPEG_DECODER_H
 
-#include <boost/shared_ptr.hpp>
-
 #include "FFmpegDecoderAudio.hpp"
 #include "FFmpegDecoderVideo.hpp"
 
+#include <osg/Notify>
 
 
 namespace osgFFmpeg {
 
+class FormatContextPtr
+{
+    public:
+    
+        typedef AVFormatContext T;
+    
+        explicit FormatContextPtr() : _ptr(0) {}
+        explicit FormatContextPtr(T* ptr) : _ptr(ptr) {}
+        
+        ~FormatContextPtr()
+        {
+            cleanup();
+        }
+        
+        T* get() { return _ptr; }
+
+        T * operator-> () const // never throws
+        {
+            return _ptr;
+        }
+
+        void reset(T* ptr) 
+        {
+            if (ptr==_ptr) return;
+            cleanup();
+            _ptr = ptr;
+        }
+
+        void cleanup()
+        {
+            if (_ptr) 
+            {
+                osg::notify(osg::NOTICE)<<"Calling av_close_input_file("<<_ptr<<")"<<std::endl;
+                av_close_input_file(_ptr);
+            }
+            _ptr = 0;
+        }
+        
+        
+
+    protected:
+    
+        T* _ptr;
+};
 
 
@@ -46,5 +89,4 @@
     };
 
-    typedef boost::shared_ptr<AVFormatContext> FormatContextPtr;
     typedef BoundedMessageQueue<FFmpegPacket> PacketQueue;
 
Index: /OpenSceneGraph/trunk/src/osgPlugins/ffmpeg/AudioSinkInterface.hpp
===================================================================
--- /OpenSceneGraph/trunk/src/osgPlugins/ffmpeg/AudioSinkInterface.hpp (revision 9816)
+++ /OpenSceneGraph/trunk/src/osgPlugins/ffmpeg/AudioSinkInterface.hpp (revision 9826)
@@ -1,5 +1,5 @@
 
-#ifndef HEADER_GUARD_OSGFFMPEG_AUDIO_SINK_INTERFACE_H
-#define HEADER_GUARD_OSGFFMPEG_AUDIO_SINK_INTERFACE_H
+#ifndef OSG_AUDIOSINKINTERFACE_H
+#define OSG_AUDIOSINKINTERFACE_H
 
 #include <osg/Object>
@@ -7,5 +7,5 @@
 
 
-namespace osgFFmpeg
+namespace osg
 {
 
Index: /OpenSceneGraph/trunk/src/osgPlugins/ffmpeg/FFmpegDecoderAudio.cpp
===================================================================
--- /OpenSceneGraph/trunk/src/osgPlugins/ffmpeg/FFmpegDecoderAudio.cpp (revision 9818)
+++ /OpenSceneGraph/trunk/src/osgPlugins/ffmpeg/FFmpegDecoderAudio.cpp (revision 9826)
@@ -107,5 +107,5 @@
 
 
-void FFmpegDecoderAudio::setAudioSink(osg::ref_ptr<AudioSinkInterface> audio_sink)
+void FFmpegDecoderAudio::setAudioSink(osg::ref_ptr<osg::AudioSinkInterface> audio_sink)
 {
     // The FFmpegDecoderAudio object takes the responsability of destroying the audio_sink.
Index: /OpenSceneGraph/trunk/src/osgPlugins/ffmpeg/FFmpegDecoderAudio.hpp
===================================================================
--- /OpenSceneGraph/trunk/src/osgPlugins/ffmpeg/FFmpegDecoderAudio.hpp (revision 9818)
+++ /OpenSceneGraph/trunk/src/osgPlugins/ffmpeg/FFmpegDecoderAudio.hpp (revision 9826)
@@ -31,5 +31,5 @@
     virtual void run();
 
-    void setAudioSink(osg::ref_ptr<AudioSinkInterface> audio_sink);
+    void setAudioSink(osg::ref_ptr<osg::AudioSinkInterface> audio_sink);
     void fillBuffer(void * buffer, size_t size);
 
@@ -42,5 +42,5 @@
 
     //typedef boost::shared_ptr<AVFrame> FramePtr;
-    typedef osg::ref_ptr<AudioSinkInterface> SinkPtr;
+    typedef osg::ref_ptr<osg::AudioSinkInterface> SinkPtr;
     typedef std::vector<uint8_t> Buffer;
 
Index: /OpenSceneGraph/trunk/src/osgPlugins/ffmpeg/FFmpegDecoderVideo.cpp
===================================================================
--- /OpenSceneGraph/trunk/src/osgPlugins/ffmpeg/FFmpegDecoderVideo.cpp (revision 9818)
+++ /OpenSceneGraph/trunk/src/osgPlugins/ffmpeg/FFmpegDecoderVideo.cpp (revision 9826)
@@ -73,8 +73,8 @@
 
     // Allocate video frame
-    m_frame.reset(avcodec_alloc_frame(), av_free);
+    m_frame.reset(avcodec_alloc_frame());
 
     // Allocate converted RGB frame
-    m_frame_rgba.reset(avcodec_alloc_frame(), av_free);
+    m_frame_rgba.reset(avcodec_alloc_frame());
     m_buffer_rgba.resize(avpicture_get_size(PIX_FMT_RGB32, width(), height()));
     m_buffer_rgba_public.resize(m_buffer_rgba.size());
Index: /OpenSceneGraph/trunk/src/osgPlugins/ffmpeg/FFmpegImageStream.cpp
===================================================================
--- /OpenSceneGraph/trunk/src/osgPlugins/ffmpeg/FFmpegImageStream.cpp (revision 9816)
+++ /OpenSceneGraph/trunk/src/osgPlugins/ffmpeg/FFmpegImageStream.cpp (revision 9826)
@@ -122,9 +122,8 @@
 
 
-void FFmpegImageStream::setAudioSink(osg::ref_ptr<AudioSinkInterface> audio_sink)
+void FFmpegImageStream::setAudioSink(osg::AudioSinkInterface* audio_sink)
 { 
     m_decoder->audio_decoder().setAudioSink(audio_sink); 
 }
-
 
 
Index: /OpenSceneGraph/trunk/src/osgPlugins/ffmpeg/FFmpegDecoderVideo.hpp
===================================================================
--- /OpenSceneGraph/trunk/src/osgPlugins/ffmpeg/FFmpegDecoderVideo.hpp (revision 9818)
+++ /OpenSceneGraph/trunk/src/osgPlugins/ffmpeg/FFmpegDecoderVideo.hpp (revision 9826)
@@ -14,5 +14,44 @@
 namespace osgFFmpeg {
 
+class FramePtr
+{
+    public:
+    
+        typedef AVFrame T;
+    
+        explicit FramePtr() : _ptr(0) {}
+        explicit FramePtr(T* ptr) : _ptr(ptr) {}
+        
+        ~FramePtr()
+        {
+            cleanup();
+        }
+        
+        T* get() { return _ptr; }
 
+        T * operator-> () const // never throws
+        {
+            return _ptr;
+        }
+
+        void reset(T* ptr) 
+        {
+            if (ptr==_ptr) return;
+            cleanup();
+            _ptr = ptr;
+        }
+
+        void cleanup()
+        {
+            if (_ptr) av_free(_ptr);
+            _ptr = 0;
+        }
+        
+        
+
+    protected:
+    
+        T* _ptr;
+};
 
 class FFmpegDecoderVideo : public OpenThreads::Thread
@@ -41,5 +80,4 @@
 private:
 
-    typedef boost::shared_ptr<AVFrame> FramePtr;
     typedef std::vector<uint8_t> Buffer;
 
Index: /OpenSceneGraph/trunk/src/osgPlugins/ffmpeg/FFmpegImageStream.hpp
===================================================================
--- /OpenSceneGraph/trunk/src/osgPlugins/ffmpeg/FFmpegImageStream.hpp (revision 9816)
+++ /OpenSceneGraph/trunk/src/osgPlugins/ffmpeg/FFmpegImageStream.hpp (revision 9826)
@@ -54,5 +54,6 @@
         virtual void quit(bool waitForThreadToExit = true);
 
-        void setAudioSink(osg::ref_ptr<AudioSinkInterface> audio_sink);
+        virtual void setAudioSink(osg::AudioSinkInterface* audio_sink);
+        
         void fillAudioBuffer(void * const buffer, const size_t size);
 
Index: /OpenSceneGraph/trunk/src/osgPlugins/ffmpeg/FFmpegDecoder.cpp
===================================================================
--- /OpenSceneGraph/trunk/src/osgPlugins/ffmpeg/FFmpegDecoder.cpp (revision 9816)
+++ /OpenSceneGraph/trunk/src/osgPlugins/ffmpeg/FFmpegDecoder.cpp (revision 9826)
@@ -47,5 +47,5 @@
             throw std::runtime_error("av_open_input_file() failed");
 
-        m_format_context.reset(p_format_context, av_close_input_file);
+        m_format_context.reset(p_format_context);
 
         // Retrieve stream info
