Commit f8db26d6 authored by Hugo Beauzée-Luyssen's avatar Hugo Beauzée-Luyssen

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

parent 3cc5ace1
......@@ -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();
}
......@@ -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;
......
......@@ -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
......@@ -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 ) );
......
......@@ -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 ) );
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment