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

Effect: Adding an EffectInstance class.

Only load the effects when required.
parent 075622d2
......@@ -8,6 +8,7 @@ SET(VLMC_SRCS
Commands/Commands.cpp
EffectsEngine/EffectsEngine.cpp
EffectsEngine/Effect.cpp
EffectsEngine/EffectInstance.cpp
Library/Library.cpp
Library/MediaContainer.cpp
LibVLCpp/VLCInstance.cpp
......@@ -55,6 +56,7 @@ ENDIF(WIN32)
SET (VLMC_HDRS
EffectsEngine/EffectsEngine.h
EffectsEngine/Effect.h
EffectsEngine/EffectInstance.h
Library/Library.h
Library/MediaContainer.h
LibVLCpp/VLCInstance.h
......
......@@ -28,19 +28,13 @@
Effect::Effect( const QString &fileName ) :
QLibrary( fileName ),
m_instance( NULL ),
m_width( 0 ),
m_height( 0 )
m_type( Unknown )
{
}
Effect::~Effect()
{
m_f0r_deinit();
if ( m_instance != NULL )
{
m_f0r_destruct( m_instance );
}
}
#define LOAD_FREI0R_SYMBOL( dest, symbolName ) \
......@@ -53,6 +47,8 @@ if ( ( dest = reinterpret_cast<typeof( dest )>( resolve( symbolName ) ) ) == NUL
bool
Effect::load()
{
if ( isLoaded() == true )
return true;
LOAD_FREI0R_SYMBOL( m_f0r_init, "f0r_init" );
LOAD_FREI0R_SYMBOL( m_f0r_deinit, "f0r_deinit" )
LOAD_FREI0R_SYMBOL( m_f0r_info, "f0r_get_plugin_info" )
......@@ -90,20 +86,3 @@ Effect::type() const
{
return m_type;
}
void
Effect::init( quint32 width, quint32 height )
{
if ( width != m_width || height != m_height )
{
m_instance = m_f0r_construct( width, height );
m_width = width;
m_height = height;
}
}
void
Effect::process( double time, const quint32 *input, quint32 *output ) const
{
m_f0r_update( m_instance, time, input, output );
}
......@@ -27,11 +27,14 @@
#include "frei0r/frei0r.h"
class EffectInstance;
class Effect : public QLibrary
{
public:
enum Type
{
Unknown = -1,
Filter = F0R_PLUGIN_TYPE_FILTER,
Source = F0R_PLUGIN_TYPE_SOURCE,
Mixer2 = F0R_PLUGIN_TYPE_MIXER2,
......@@ -52,9 +55,13 @@ class Effect : public QLibrary
const QString& name() const;
const QString& description() const;
Type type() const;
void init( quint32 width, quint32 height );
void process( double time, const quint32* input, quint32* output ) const;
private:
QString m_name;
QString m_desc;
Type m_type;
//Symbols:
f0r_init_t m_f0r_init;
f0r_deinit_t m_f0r_deinit;
f0r_get_info_t m_f0r_info;
......@@ -62,12 +69,7 @@ class Effect : public QLibrary
f0r_destruct_t m_f0r_destruct;
f0r_update_t m_f0r_update;
f0r_instance_t m_instance;
QString m_name;
QString m_desc;
quint32 m_width;
quint32 m_height;
Type m_type;
friend class EffectInstance;
};
#endif // EFFECT_H
/*****************************************************************************
* EffectInstance.cpp: Handle an effect instance.
*****************************************************************************
* Copyright (C) 2008-2010 VideoLAN
*
* Authors: Hugo Beauzée-Luyssen <beauze.h@gmail.com>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
#include "EffectInstance.h"
#include "Effect.h"
EffectInstance::EffectInstance( Effect *effect ) :
m_effect( effect ),
m_width( 0 ),
m_height( 0 ),
m_instance( NULL )
{
}
EffectInstance::~EffectInstance()
{
m_effect->m_f0r_destruct( m_instance );
}
void
EffectInstance::init( quint32 width, quint32 height )
{
if ( width != m_width || height != m_height )
{
m_effect->load();
m_instance = m_effect->m_f0r_construct( width, height );
m_width = width;
m_height = height;
}
}
void
EffectInstance::process( double time, const quint32 *input, quint32 *output ) const
{
m_effect->m_f0r_update( m_instance, time, input, output );
}
const Effect*
EffectInstance::effect() const
{
return m_effect;
}
/*****************************************************************************
* EffectInstance.h: Handle an effect instance.
*****************************************************************************
* Copyright (C) 2008-2010 VideoLAN
*
* Authors: Hugo Beauzée-Luyssen <beauze.h@gmail.com>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
#ifndef EFFECTINSTANCE_H
#define EFFECTINSTANCE_H
class Effect;
#include <QtGlobal>
#include "frei0r/frei0r.h"
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:
Effect *m_effect;
quint32 m_width;
quint32 m_height;
f0r_instance_t m_instance;
};
#endif // EFFECTINSTANCE_H
......@@ -23,6 +23,7 @@
#include "EffectsEngine.h"
#include "Effect.h"
#include "EffectInstance.h"
#include "Types.h"
#include <QDir>
......@@ -36,7 +37,7 @@ EffectsEngine::~EffectsEngine()
{
}
EffectsEngine::EffectHelper::EffectHelper( Effect *_effect, qint64 _start, qint64 _end,
EffectsEngine::EffectHelper::EffectHelper( EffectInstance *_effect, qint64 _start, qint64 _end,
const QString& _uuid ) :
effect( _effect ),
start( _start ),
......@@ -109,7 +110,7 @@ EffectsEngine::applyEffects( const EffectList &effects, Workflow::Frame* frame,
buff = &buff2;
if ( *buff == NULL )
*buff = new quint8[frame->size()];
Effect *effect = (*it)->effect;
EffectInstance *effect = (*it)->effect;
effect->process( 0.0, (quint32*)input, (quint32*)*buff );
input = *buff;
firstBuff = !firstBuff;
......
......@@ -38,9 +38,9 @@ class EffectsEngine : public QObject, public Singleton<EffectsEngine>
public:
struct EffectHelper
{
EffectHelper( Effect* effect, qint64 start = 0, qint64 end = -1,
EffectHelper( EffectInstance* effect, qint64 start = 0, qint64 end = -1,
const QString& uuid = QString() );
Effect* effect;
EffectInstance* effect;
qint64 start;
qint64 end;
QUuid uuid;
......
......@@ -28,6 +28,7 @@
#include <inttypes.h>
#include "Clip.h"
#include "EffectInstance.h"
#include "GenericRenderer.h"
#include "MainWorkflow.h"
#include "SettingsManager.h"
......@@ -386,9 +387,10 @@ WorkflowRenderer::paramsHasChanged( quint32 width, quint32 height, double fps )
void
WorkflowRenderer::appendEffect( Effect *effect, qint64 start, qint64 end )
{
effect->init( m_width, m_height );
EffectInstance *effectInstance = new EffectInstance( effect );
effectInstance->init( m_width, m_height );
QWriteLocker lock( m_effectsLock );
m_effects.push_back( new EffectsEngine::EffectHelper( effect, start, end ) );
m_effects.push_back( new EffectsEngine::EffectHelper( effectInstance, start, end ) );
}
/////////////////////////////////////////////////////////////////////
......
......@@ -21,6 +21,7 @@
*****************************************************************************/
#include "Clip.h"
#include "EffectInstance.h"
#include "MainWorkflow.h"
#include "StackedBuffer.hpp"
#include "VideoClipWorkflow.h"
......@@ -213,9 +214,10 @@ VideoClipWorkflow::appendEffect( Effect *effect, qint64 start, qint64 end )
qWarning() << "VideoClipWorkflow does not handle non filter effects.";
return false;
}
effect->init( m_width, m_height );
EffectInstance *effectInstance = new EffectInstance( effect );
effectInstance->init( m_width, m_height );
QWriteLocker lock( m_effectsLock );
m_effects.push_back( new EffectsEngine::EffectHelper( effect, start, end ) );
m_effects.push_back( new EffectsEngine::EffectHelper( effectInstance, start, end ) );
return true;
}
......
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