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

EffectsEngine: Multiple filters can be applied to the WorkflowRenderer output.

parent ad903dd2
......@@ -25,6 +25,7 @@
#include "Effect.h"
#include <QDir>
#include <QtDebug>
EffectsEngine::EffectsEngine()
{
......@@ -34,6 +35,13 @@ EffectsEngine::~EffectsEngine()
{
}
EffectsEngine::EffectHelper::EffectHelper( Effect *_effect, qint64 _start, qint64 _end ) :
effect( _effect ),
start( _start ),
end( _end )
{
}
void
EffectsEngine::initAll( quint32 width, quint32 height )
{
......
......@@ -35,6 +35,14 @@ class EffectsEngine : public QObject, public Singleton<EffectsEngine>
Q_OBJECT
public:
struct EffectHelper
{
EffectHelper( Effect* effect, qint64 start = 0, qint64 end = -1 );
Effect* effect;
qint64 start;
qint64 end;
};
void initAll( quint32 width, quint32 height );
Effect* effect( const QString& name );
bool loadEffect( const QString& fileName );
......
......@@ -425,6 +425,9 @@ MainWindow::createStatusBar()
void
MainWindow::initializeDockWidgets( void )
{
//FIXME !!!
EffectsEngine::getInstance()->browseDirectory( "/usr/lib/frei0r-1" );
m_renderer = new WorkflowRenderer();
m_renderer->initializeRenderer();
m_timeline = new Timeline( m_renderer, this );
......@@ -459,8 +462,6 @@ MainWindow::initializeDockWidgets( void )
QT_TRANSLATE_NOOP( "DockWidgetManager", "Effects List" ),
Qt::AllDockWidgetAreas, QDockWidget::AllDockWidgetFeatures,
Qt::LeftDockWidgetArea );
//FIXME !!!
EffectsEngine::getInstance()->browseDirectory( "/usr/lib/frei0r-1" );
QDockWidget* dock = dockManager->addDockedWidget( UndoStack::getInstance( this ),
QT_TRANSLATE_NOOP( "DockWidgetManager", "History" ),
......
......@@ -52,7 +52,7 @@ ProjectManager::ProjectManager() : m_projectFile( NULL ), m_needSave( false )
VLMC_CREATE_PROJECT_INT( "video/VideoProjectWidth", 480,
QT_TRANSLATE_NOOP( "PreferenceWidget", "Video width" ),
QT_TRANSLATE_NOOP( "PreferenceWidget", "Width resolution of the output video" ) );
VLMC_CREATE_PROJECT_INT( "video/VideoProjectHeight", 300,
VLMC_CREATE_PROJECT_INT( "video/VideoProjectHeight", 320,
QT_TRANSLATE_NOOP( "PreferenceWidget", "Video height" ),
QT_TRANSLATE_NOOP( "PreferenceWidget", "Height resolution of the output video" ) );
VLMC_CREATE_PROJECT_INT( "audio/AudioSampleRate", 0,
......
......@@ -157,12 +157,9 @@ WorkflowRenderer::lockVideo( EsHandler *handler, qint64 *pts, size_t *bufferSize
if ( m_stopping == true )
return 1;
else
{
ret = m_mainWorkflow->getOutput( MainWorkflow::VideoTrack, m_paused );
m_videoBuffSize = ret->video->size();
ptsDiff = ret->video->ptsDiff;
}
if ( ptsDiff == 0 )
{
//If no ptsDiff has been computed, we have to fake it, so we compute
......@@ -170,9 +167,10 @@ WorkflowRenderer::lockVideo( EsHandler *handler, qint64 *pts, size_t *bufferSize
//this is a bit hackish though... (especially regarding the "no frame computed" detection)
ptsDiff = 1000000 / handler->fps;
}
applyEffects( ret );
m_pts = *pts = ptsDiff + m_pts;
*buffer = ret->video->buffer();
*bufferSize = m_videoBuffSize;
*bufferSize = ret->video->size();
return 0;
}
......@@ -218,6 +216,54 @@ void WorkflowRenderer::unlock( void*, const char*, size_t, void* )
{
}
void
WorkflowRenderer::applyEffects( MainWorkflow::OutputBuffers* ret )
{
if ( m_effects.size() == 0 )
return ;
QList<EffectsEngine::EffectHelper*>::const_iterator it = m_effects.constBegin();
QList<EffectsEngine::EffectHelper*>::const_iterator ite = m_effects.constEnd();
quint8 *buff1 = NULL;
quint8 *buff2 = NULL;
quint8 *input = ret->video->buffer();
bool firstBuff = true;
while ( it != ite )
{
if ( (*it)->start < m_mainWorkflow->getCurrentFrame() &&
( (*it)->end < 0 || (*it)->end > m_mainWorkflow->getCurrentFrame() ) )
{
quint8 **buff;
if ( firstBuff == true )
buff = &buff1;
else
buff = &buff2;
if ( *buff == NULL )
*buff = new quint8[ret->video->size()];
Effect *effect = (*it)->effect;
effect->process( 0.0, (quint32*)input, (quint32*)*buff );
input = *buff;
firstBuff = !firstBuff;
}
++it;
}
if ( buff1 != NULL || buff2 != NULL )
{
//The old input frame will automatically be deleted when setting the new buffer
if ( firstBuff == true )
{
delete[] buff1;
ret->video->setBuffer( buff2 );
}
else
{
delete[] buff2;
ret->video->setBuffer( buff1 );
}
}
}
void WorkflowRenderer::startPreview()
{
if ( m_mainWorkflow->getLengthFrame() <= 0 )
......@@ -380,6 +426,12 @@ WorkflowRenderer::paramsHasChanged( quint32 width, quint32 height, double fps )
newOutputFps != fps );
}
void
WorkflowRenderer::appendEffect( Effect *effect, qint64 start, qint64 end )
{
m_effects.push_back( new EffectsEngine::EffectHelper( effect, start, end ) );
}
/////////////////////////////////////////////////////////////////////
/////SLOTS :
/////////////////////////////////////////////////////////////////////
......
......@@ -23,9 +23,11 @@
#ifndef WORKFLOWRENDERER_H
#define WORKFLOWRENDERER_H
#include "EffectsEngine/EffectsEngine.h"
#include "GenericRenderer.h"
#include "MainWorkflow.h"
#include <QObject>
class Clip;
......@@ -129,6 +131,8 @@ class WorkflowRenderer : public GenericRenderer
*/
void killRenderer();
void appendEffect( Effect* effect, qint64 start = 0, qint64 end = -1 );
private:
/**
* \brief This is a subpart of the togglePlayPause( bool ) method
......@@ -145,6 +149,8 @@ class WorkflowRenderer : public GenericRenderer
*/
virtual void startPreview();
void applyEffects( MainWorkflow::OutputBuffers *ret );
protected:
/**
* \brief Will return a pointer to the function/static method to use
......@@ -247,6 +253,7 @@ class WorkflowRenderer : public GenericRenderer
*/
bool paramsHasChanged( quint32 width, quint32 height,
double fps );
protected:
MainWorkflow* m_mainWorkflow;
LibVLCpp::Media* m_media;
......@@ -267,7 +274,6 @@ class WorkflowRenderer : public GenericRenderer
* be injected
*/
quint8 *m_silencedAudioBuffer;
size_t m_videoBuffSize;
EsHandler* m_esHandler;
quint32 m_nbChannels;
quint32 m_rate;
......@@ -277,6 +283,8 @@ class WorkflowRenderer : public GenericRenderer
*/
qint64 m_oldLength;
QList<EffectsEngine::EffectHelper*> m_effects;
static const quint8 VideoCookie = '0';
static const quint8 AudioCookie = '1';
......
......@@ -61,7 +61,7 @@ class MainWorkflow : public QObject, public Singleton<MainWorkflow>
*/
struct OutputBuffers
{
const Workflow::Frame *video;
Workflow::Frame *video;
Workflow::AudioSample *audio;
};
/**
......
......@@ -77,3 +77,10 @@ Frame::clone() const
memcpy( f->buffer(), m_buffer, m_size );
return f;
}
void
Frame::setBuffer( quint8 *buff )
{
delete[] m_buffer;
m_buffer = buff;
}
......@@ -38,6 +38,7 @@ namespace Workflow
quint32 height() const;
quint8 *buffer();
const quint8 *buffer() const;
void setBuffer( quint8 *buff );
Frame *clone() const;
/**
* \returns The frame size in pixels
......
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