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

Effects: Differentiate Effects from Filter at a type level.

parent 5dd47b69
......@@ -9,6 +9,7 @@ SET(VLMC_SRCS
EffectsEngine/EffectsEngine.cpp
EffectsEngine/Effect.cpp
EffectsEngine/EffectInstance.cpp
EffectsEngine/FilterInstance.cpp
Library/Library.cpp
Library/MediaContainer.cpp
LibVLCpp/VLCInstance.cpp
......
......@@ -21,8 +21,7 @@
*****************************************************************************/
#include "Effect.h"
#include "EffectInstance.h"
#include "FilterInstance.h"
#include "frei0r/frei0r.h"
#include <QtDebug>
......@@ -120,7 +119,13 @@ EffectInstance*
Effect::createInstance()
{
m_instCount.fetchAndAddAcquire( 1 );
return new EffectInstance( this );
switch ( m_type )
{
case Filter:
return new FilterInstance( this );
default:
return NULL;
}
}
void
......
......@@ -81,6 +81,7 @@ class Effect : public QLibrary
f0r_update_t m_f0r_update;
friend class EffectInstance;
friend class FilterInstance;
};
#endif // EFFECT_H
......@@ -49,12 +49,6 @@ EffectInstance::init( quint32 width, quint32 height )
}
}
void
EffectInstance::process( double time, const quint32 *input, quint32 *output ) const
{
m_effect->m_f0r_update( m_instance, time, input, output );
}
Effect*
EffectInstance::effect()
{
......
......@@ -32,10 +32,9 @@ class EffectInstance
{
public:
void init( quint32 width, quint32 height );
void process( double time, const quint32* input, quint32* output ) const;
Effect* effect();
private:
protected:
EffectInstance( Effect *effect );
~EffectInstance();
......
......@@ -23,7 +23,7 @@
#include "EffectsEngine.h"
#include "Effect.h"
#include "EffectInstance.h"
#include "FilterInstance.h"
#include "Types.h"
#include <QDesktopServices>
......@@ -42,18 +42,6 @@ EffectsEngine::~EffectsEngine()
{
}
EffectsEngine::EffectHelper::EffectHelper( EffectInstance *_effect, qint64 _start, qint64 _end,
const QString& _uuid ) :
effect( _effect ),
start( _start ),
end( _end )
{
if ( _uuid.isNull() == true )
uuid = QUuid::createUuid();
else
uuid = _uuid;
}
Effect*
EffectsEngine::effect( const QString& name )
{
......@@ -137,7 +125,7 @@ EffectsEngine::applyEffects( const FilterList &effects, Workflow::Frame* frame,
buff = &buff2;
if ( *buff == NULL )
*buff = new quint8[frame->size()];
EffectInstance *effect = (*it)->effect;
FilterInstance *effect = (*it)->effect;
effect->process( time, (quint32*)input, (quint32*)*buff );
input = *buff;
firstBuff = !firstBuff;
......
......@@ -30,6 +30,8 @@ class QTime;
#include "Effect.h"
#include "MainWorkflow.h"
class FilterInstance;
#include <QObject>
#include <QHash>
......@@ -40,16 +42,28 @@ class EffectsEngine : public QObject, public Singleton<EffectsEngine>
Q_OBJECT
public:
template <typename T>
struct EffectHelper
{
EffectHelper( EffectInstance* effect, qint64 start = 0, qint64 end = -1,
const QString& uuid = QString() );
EffectInstance* effect;
qint64 start;
qint64 end;
QUuid uuid;
EffectHelper( T *_effect, qint64 _start = 0, qint64 _end = -1,
const QString& _uuid = QString() ) :
effect( _effect ),
start( _start ),
end( _end )
{
if ( _uuid.isNull() == true )
uuid = QUuid::createUuid();
else
uuid = _uuid;
}
T* effect;
qint64 start;
qint64 end;
QUuid uuid;
};
typedef QList<EffectHelper*> FilterList;
typedef EffectHelper<FilterInstance> FilterHelper;
typedef QList<FilterHelper*> FilterList;
Effect* effect( const QString& name );
bool loadEffect( const QString& fileName );
......
/*****************************************************************************
* EffectInstance.h: Handle a filter 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 "FilterInstance.h"
#include "Effect.h"
FilterInstance::FilterInstance( Effect *effect ) :
EffectInstance( effect )
{
}
void
FilterInstance::process( double time, const quint32 *input, quint32 *output ) const
{
m_effect->m_f0r_update( m_instance, time, input, output );
}
/*****************************************************************************
* EffectInstance.h: Handle a filter 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 FILTERINSTANCE_H
#define FILTERINSTANCE_H
#include "EffectInstance.h"
class FilterInstance : public EffectInstance
{
public:
FilterInstance( Effect *effect );
void process( double time, const quint32* input, quint32* output ) const;
};
#endif // FILTERINSTANCE_H
......@@ -26,7 +26,7 @@
#include "WorkflowRenderer.h"
#include "Clip.h"
#include "EffectInstance.h"
#include "FilterInstance.h"
#include "GenericRenderer.h"
#include "MainWorkflow.h"
#include "SettingsManager.h"
......@@ -175,7 +175,7 @@ WorkflowRenderer::lockVideo( EsHandler *handler, qint64 *pts, size_t *bufferSize
}
{
QReadLocker lock( m_effectsLock );
EffectsEngine::applyEffects( m_effects, ret->video,
EffectsEngine::applyEffects( m_filters, ret->video,
m_mainWorkflow->getCurrentFrame(),
m_mainWorkflow->getCurrentFrame() * 1000.0 / handler->fps );
}
......@@ -239,7 +239,7 @@ void WorkflowRenderer::startPreview()
setupRenderer( m_width, m_height, m_outputFps );
}
QReadLocker lock( m_effectsLock );
EffectsEngine::initEffects( m_effects, m_width, m_height );
EffectsEngine::initEffects( m_filters, m_width, m_height );
//Deactivating vlc's keyboard inputs.
m_mediaPlayer->setKeyInput( false );
......@@ -395,11 +395,17 @@ WorkflowRenderer::paramsHasChanged( quint32 width, quint32 height, double fps )
void
WorkflowRenderer::appendEffect( Effect *effect, qint64 start, qint64 end )
{
EffectInstance *effectInstance = effect->createInstance();
if ( effect->type() != Effect::Filter )
{
qWarning() << "WorkflowRenderer does not handle non filter effects.";
return ;
}
FilterInstance *filterInstance = static_cast<FilterInstance*>( effect->createInstance() );
if ( isRendering() == true )
effectInstance->init( m_width, m_height );
filterInstance->init( m_width, m_height );
QWriteLocker lock( m_effectsLock );
m_effects.push_back( new EffectsEngine::EffectHelper( effectInstance, start, end ) );
m_filters.push_back( new EffectsEngine::FilterHelper( filterInstance, start, end ) );
}
void
......@@ -408,7 +414,7 @@ WorkflowRenderer::saveProject( QXmlStreamWriter &project ) const
project.writeStartElement( "renderer" );
{
QReadLocker lock( m_effectsLock );
EffectsEngine::saveEffects( m_effects, project );
EffectsEngine::saveEffects( m_filters, project );
}
project.writeEndElement();
}
......
......@@ -284,7 +284,7 @@ class WorkflowRenderer : public GenericRenderer
qint64 m_oldLength;
QReadWriteLock *m_effectsLock;
EffectsEngine::FilterList m_effects;
EffectsEngine::FilterList m_filters;
static const quint8 VideoCookie = '0';
static const quint8 AudioCookie = '1';
......
......@@ -123,7 +123,7 @@ TrackHandler::getOutput( qint64 currentFrame, qint64 subFrame, bool paused )
{
//If paused is false at this point, there's probably something wrong...
void* ret = m_tracks[i]->getOutput( currentFrame, subFrame, paused );
//m_tmpAudioBuffer is NULl by default, so it will remain NULL if we continue;
//m_tmpAudioBuffer is NULL by default, so it will remain NULL if we continue;
if ( ret == NULL )
continue ;
StackedBuffer<Workflow::AudioSample*>* stackedBuffer =
......
......@@ -21,7 +21,7 @@
*****************************************************************************/
#include "Clip.h"
#include "EffectInstance.h"
#include "FilterInstance.h"
#include "MainWorkflow.h"
#include "Media.h"
#include "StackedBuffer.hpp"
......@@ -102,7 +102,7 @@ VideoClipWorkflow::initVlcOutput()
m_vlcMedia->addOption( buffer );
QReadLocker lock( m_effectsLock );
EffectsEngine::initEffects( m_effects, m_width, m_height );
EffectsEngine::initEffects( m_filters, m_width, m_height );
}
void*
......@@ -169,7 +169,7 @@ VideoClipWorkflow::unlock( VideoClipWorkflow *cw, void *buffer, int width,
Workflow::Frame *frame = cw->m_computedBuffers.last();
{
QWriteLocker lock( cw->m_effectsLock );
EffectsEngine::applyEffects( cw->m_effects, frame, cw->m_renderedFrame,
EffectsEngine::applyEffects( cw->m_filters, frame, cw->m_renderedFrame,
cw->m_renderedFrame * 1000.0 / cw->clip()->getMedia()->fps() );
}
{
......@@ -219,9 +219,9 @@ VideoClipWorkflow::appendEffect( Effect *effect, qint64 start, qint64 end )
qWarning() << "VideoClipWorkflow does not handle non filter effects.";
return false;
}
EffectInstance *effectInstance = effect->createInstance();
FilterInstance *filterInstance = static_cast<FilterInstance*>( effect->createInstance() );
QWriteLocker lock( m_effectsLock );
m_effects.push_back( new EffectsEngine::EffectHelper( effectInstance, start, end ) );
m_filters.push_back( new EffectsEngine::FilterHelper( filterInstance, start, end ) );
return true;
}
......@@ -229,7 +229,7 @@ void
VideoClipWorkflow::saveEffects( QXmlStreamWriter &project ) const
{
QReadLocker lock( m_effectsLock );
EffectsEngine::saveEffects( m_effects, project );
EffectsEngine::saveEffects( m_filters, project );
}
void
......
......@@ -83,7 +83,7 @@ class VideoClipWorkflow : public ClipWorkflow
QReadWriteLock *m_effectsLock;
QMutex *m_renderedFrameMutex;
qint64 m_renderedFrame;
QList<EffectsEngine::EffectHelper*> m_effects;
QList<EffectsEngine::FilterHelper*> m_filters;
};
#endif // VIDEOCLIPWORKFLOW_H
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