[vlmc-devel] commit: Effects: Refcount the instances, and unload the module when it become unused ( Hugo Beauzée-Luyssen )

git at videolan.org git at videolan.org
Wed Jul 28 00:22:09 CEST 2010


vlmc | branch: master | Hugo Beauzée-Luyssen <beauze.h at gmail.com> | Tue Jul 27 23:44:26 2010 +0200| [f8db26d6eccf51013bcceb08206542aff9812676] | committer: Hugo Beauzée-Luyssen 

Effects: Refcount the instances, and unload the module when it become unused

> http://git.videolan.org/gitweb.cgi/vlmc.git/?a=commit;h=f8db26d6eccf51013bcceb08206542aff9812676
---

 src/EffectsEngine/Effect.cpp       |   17 +++++++++++++++++
 src/EffectsEngine/Effect.h         |    5 +++++
 src/EffectsEngine/EffectInstance.h |    8 +++++---
 src/Renderer/WorkflowRenderer.cpp  |    2 +-
 src/Workflow/VideoClipWorkflow.cpp |    2 +-
 5 files changed, 29 insertions(+), 5 deletions(-)

diff --git a/src/EffectsEngine/Effect.cpp b/src/EffectsEngine/Effect.cpp
index ebfd8c6..582fe67 100644
--- a/src/EffectsEngine/Effect.cpp
+++ b/src/EffectsEngine/Effect.cpp
@@ -21,6 +21,7 @@
  *****************************************************************************/
 
 #include "Effect.h"
+#include "EffectInstance.h"
 
 #include "frei0r/frei0r.h"
 
@@ -92,3 +93,19 @@ Effect::type()
         load();
     return m_type;
 }
+
+EffectInstance*
+Effect::createInstance()
+{
+    m_instCount.fetchAndAddAcquire( 1 );
+    return new EffectInstance( this );
+}
+
+void
+Effect::destroyInstance( EffectInstance *instance )
+{
+    delete instance;
+    //fetchAndAddAcquire returns the old value.
+    if ( m_instCount.fetchAndAddAcquire( -1 ) == 1 )
+        unload();
+}
diff --git a/src/EffectsEngine/Effect.h b/src/EffectsEngine/Effect.h
index 9d17203..21c7c88 100644
--- a/src/EffectsEngine/Effect.h
+++ b/src/EffectsEngine/Effect.h
@@ -55,11 +55,16 @@ class Effect : public QLibrary
         const QString&  name();
         const QString&  description();
         Type            type();
+        EffectInstance  *createInstance();
+
+    private:
+        void            destroyInstance( EffectInstance* instance );
 
     private:
         QString         m_name;
         QString         m_desc;
         Type            m_type;
+        QAtomicInt      m_instCount;
 
         //Symbols:
         f0r_init_t      m_f0r_init;
diff --git a/src/EffectsEngine/EffectInstance.h b/src/EffectsEngine/EffectInstance.h
index 01cd4f7..8a75fcd 100644
--- a/src/EffectsEngine/EffectInstance.h
+++ b/src/EffectsEngine/EffectInstance.h
@@ -31,19 +31,21 @@ class   Effect;
 class EffectInstance
 {
     public:
-        EffectInstance( Effect *effect );
-        ~EffectInstance();
-
         void            init( quint32 width, quint32 height );
         void            process( double time, const quint32* input, quint32* output ) const;
         const Effect*   effect() const;
 
     private:
+        EffectInstance( Effect *effect );
+        ~EffectInstance();
+
         Effect          *m_effect;
         quint32         m_width;
         quint32         m_height;
         f0r_instance_t  m_instance;
 
+        friend class    Effect;
+
 };
 
 #endif // EFFECTINSTANCE_H
diff --git a/src/Renderer/WorkflowRenderer.cpp b/src/Renderer/WorkflowRenderer.cpp
index 0f110a8..ce1f045 100644
--- a/src/Renderer/WorkflowRenderer.cpp
+++ b/src/Renderer/WorkflowRenderer.cpp
@@ -387,7 +387,7 @@ WorkflowRenderer::paramsHasChanged( quint32 width, quint32 height, double fps )
 void
 WorkflowRenderer::appendEffect( Effect *effect, qint64 start, qint64 end )
 {
-    EffectInstance  *effectInstance = new EffectInstance( effect );
+    EffectInstance  *effectInstance = effect->createInstance();
     effectInstance->init( m_width, m_height );
     QWriteLocker    lock( m_effectsLock );
     m_effects.push_back( new EffectsEngine::EffectHelper( effectInstance, start, end ) );
diff --git a/src/Workflow/VideoClipWorkflow.cpp b/src/Workflow/VideoClipWorkflow.cpp
index c41ea3f..e5737b9 100644
--- a/src/Workflow/VideoClipWorkflow.cpp
+++ b/src/Workflow/VideoClipWorkflow.cpp
@@ -214,7 +214,7 @@ VideoClipWorkflow::appendEffect( Effect *effect, qint64 start, qint64 end )
         qWarning() << "VideoClipWorkflow does not handle non filter effects.";
         return false;
     }
-    EffectInstance  *effectInstance = new EffectInstance( effect );
+    EffectInstance  *effectInstance = effect->createInstance();
     effectInstance->init( m_width, m_height );
     QWriteLocker    lock( m_effectsLock );
     m_effects.push_back( new EffectsEngine::EffectHelper( effectInstance, start, end ) );



More information about the Vlmc-devel mailing list