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

VideoClipWorkflow: Adding Effects handling.

parent baf29920
......@@ -86,7 +86,7 @@ EffectsEngine::browseDirectory( const QString &path )
}
void
EffectsEngine::applyEffects( const EffectList &effects, MainWorkflow::OutputBuffers *ret,
EffectsEngine::applyEffects( const EffectList &effects, Workflow::Frame* frame,
qint64 currentFrame )
{
if ( effects.size() == 0 )
......@@ -96,7 +96,7 @@ EffectsEngine::applyEffects( const EffectList &effects, MainWorkflow::OutputBuff
quint8 *buff1 = NULL;
quint8 *buff2 = NULL;
quint8 *input = ret->video->buffer();
quint8 *input = frame->buffer();
bool firstBuff = true;
while ( it != ite )
......@@ -110,7 +110,7 @@ EffectsEngine::applyEffects( const EffectList &effects, MainWorkflow::OutputBuff
else
buff = &buff2;
if ( *buff == NULL )
*buff = new quint8[ret->video->size()];
*buff = new quint8[frame->size()];
Effect *effect = (*it)->effect;
effect->process( 0.0, (quint32*)input, (quint32*)*buff );
input = *buff;
......@@ -124,12 +124,12 @@ EffectsEngine::applyEffects( const EffectList &effects, MainWorkflow::OutputBuff
if ( firstBuff == true )
{
delete[] buff1;
ret->video->setBuffer( buff2 );
frame->setBuffer( buff2 );
}
else
{
delete[] buff2;
ret->video->setBuffer( buff1 );
frame->setBuffer( buff1 );
}
}
}
......@@ -51,7 +51,7 @@ class EffectsEngine : public QObject, public Singleton<EffectsEngine>
void browseDirectory( const QString& path );
static void applyEffects( const EffectList& effects,
MainWorkflow::OutputBuffers* ret, qint64 currentFrame );
Workflow::Frame *frame, qint64 currentFrame );
private:
EffectsEngine();
~EffectsEngine();
......
......@@ -171,7 +171,7 @@ WorkflowRenderer::lockVideo( EsHandler *handler, qint64 *pts, size_t *bufferSize
}
{
QReadLocker lock( m_effectsLock );
EffectsEngine::applyEffects( m_effects, ret, m_mainWorkflow->getCurrentFrame() );
EffectsEngine::applyEffects( m_effects, ret->video, m_mainWorkflow->getCurrentFrame() );
}
m_pts = *pts = ptsDiff + m_pts;
*buffer = ret->video->buffer();
......
......@@ -147,7 +147,7 @@ class ClipWorkflow : public QObject
* \brief Set the rendering position
* \param time The position in millisecond
*/
void setTime( qint64 time );
virtual void setTime( qint64 time );
/**
* This method must be used to change the state of the ClipWorkflow
......
......@@ -33,13 +33,18 @@
VideoClipWorkflow::VideoClipWorkflow( ClipHelper *ch ) :
ClipWorkflow( ch ),
m_width( 0 ),
m_height( 0 )
m_height( 0 ),
m_renderedFrame( 0 )
{
m_effectsLock = new QReadWriteLock();
m_renderedFrameMutex = new QMutex();
}
VideoClipWorkflow::~VideoClipWorkflow()
{
stop();
delete m_renderedFrameMutex;
delete m_effectsLock;
}
void
......@@ -157,6 +162,14 @@ VideoClipWorkflow::unlock( VideoClipWorkflow *cw, void *buffer, int width,
cw->computePtsDiff( pts );
Workflow::Frame *frame = cw->m_computedBuffers.last();
{
QWriteLocker lock( cw->m_effectsLock );
EffectsEngine::applyEffects( cw->m_effects, frame, cw->m_renderedFrame );
}
{
QMutexLocker lock( cw->m_renderedFrameMutex );
cw->m_renderedFrame++;
}
frame->ptsDiff = cw->m_currentPts - cw->m_previousPts;
cw->commonUnlock();
cw->m_renderWaitCond->wakeAll();
......@@ -192,6 +205,31 @@ VideoClipWorkflow::flushComputedBuffers()
m_availableBuffers.enqueue( m_computedBuffers.dequeue() );
}
bool
VideoClipWorkflow::appendEffect( Effect *effect, qint64 start, qint64 end )
{
if ( effect->type() != Effect::Filter )
{
qWarning() << "VideoClipWorkflow does not handle non filter effects.";
return false;
}
effect->setUsed( true );
effect->init( m_width, m_height );
QWriteLocker lock( m_effectsLock );
m_effects.push_back( new EffectsEngine::EffectHelper( effect, start, end ) );
return true;
}
void
VideoClipWorkflow::setTime( qint64 time )
{
{
QMutexLocker lock( m_renderedFrameMutex );
m_renderedFrame = time / 1000 * Clip::DefaultFPS;
}
ClipWorkflow::setTime( time );
}
VideoClipWorkflow::StackedBuffer::StackedBuffer( Workflow::Frame *frame,
VideoClipWorkflow *poolHandler,
bool mustBeReleased) :
......
......@@ -24,6 +24,7 @@
#define VIDEOCLIPWORKFLOW_H
#include "ClipWorkflow.h"
#include "EffectsEngine.h"
#include "StackedBuffer.hpp"
#include "Pool.hpp"
......@@ -51,6 +52,8 @@ class VideoClipWorkflow : public ClipWorkflow
void *getLockCallback() const;
void *getUnlockCallback() const;
virtual void *getOutput( ClipWorkflow::GetMode mode );
virtual bool appendEffect( Effect *effect, qint64 start = 0, qint64 end = -1 );
virtual void setTime( qint64 time );
static const quint32 nbBuffers = 3 * 30; //3 seconds with an average fps of 30
......@@ -76,6 +79,10 @@ class VideoClipWorkflow : public ClipWorkflow
qint64 pts );
quint32 m_width;
quint32 m_height;
QReadWriteLock *m_effectsLock;
QMutex *m_renderedFrameMutex;
qint64 m_renderedFrame;
QList<EffectsEngine::EffectHelper*> m_effects;
};
#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