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