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

MainWorkflow: Make getOutput return a const OutputBuffer*

This (and the changes that it implies) fix some flickering when applying
effects on a black screen.
parent 3b03d519
......@@ -110,19 +110,19 @@ EffectsEngine::browseDirectory( const QString &path )
}
}
void
EffectsEngine::applyFilters( const FilterList &effects, Workflow::Frame* frame,
quint32*
EffectsEngine::applyFilters( const FilterList &effects, const Workflow::Frame* frame,
qint64 currentFrame, double time )
{
if ( effects.size() == 0 )
return ;
return NULL;
FilterList::const_iterator it = effects.constBegin();
FilterList::const_iterator ite = effects.constEnd();
quint32 *buff1 = NULL;
quint32 *buff2 = NULL;
quint32 *input = frame->buffer();
bool firstBuff = true;
quint32 *buff1 = NULL;
quint32 *buff2 = NULL;
const quint32 *input = frame->buffer();
bool firstBuff = true;
while ( it != ite )
{
......@@ -145,18 +145,18 @@ EffectsEngine::applyFilters( const FilterList &effects, Workflow::Frame* frame,
}
if ( buff1 != NULL || buff2 != NULL )
{
//The old input frame will automatically be deleted when setting the new buffer
if ( firstBuff == true )
{
delete[] buff1;
frame->setBuffer( buff2 );
return buff2;
}
else
{
delete[] buff2;
frame->setBuffer( buff1 );
return buff1;
}
}
return NULL;
}
void
......
......@@ -80,10 +80,10 @@ class EffectsEngine : public QObject, public Singleton<EffectsEngine>
void loadEffects();
//Filters methods:
static void applyFilters( const FilterList &effects,
Workflow::Frame *frame, qint64 currentFrame, double time );
static void saveFilters( const FilterList &effects, QXmlStreamWriter &project );
static void initFilters( const FilterList &effects, quint32 width, quint32 height );
static quint32 *applyFilters( const FilterList &effects,
const Workflow::Frame *frame, qint64 currentFrame, double time );
static void saveFilters( const FilterList &effects, QXmlStreamWriter &project );
static void initFilters( const FilterList &effects, quint32 width, quint32 height );
//Mixers methods:
static MixerHelper* getMixer( const MixerList& mixers, qint64 currentFrame );
......
......@@ -50,7 +50,8 @@ WorkflowRenderer::WorkflowRenderer() :
m_height( 0 ),
m_silencedAudioBuffer( NULL ),
m_esHandler( NULL ),
m_oldLength( 0 )
m_oldLength( 0 ),
m_effectFrame( NULL )
{
m_effectsLock = new QReadWriteLock;
}
......@@ -159,12 +160,12 @@ int
WorkflowRenderer::lockVideo( EsHandler *handler, qint64 *pts, size_t *bufferSize, const void **buffer )
{
qint64 ptsDiff = 0;
Workflow::Frame *ret;
const Workflow::Frame *ret;
if ( m_stopping == true )
return 1;
ret = static_cast<Workflow::Frame*>( m_mainWorkflow->getOutput( Workflow::VideoTrack, m_paused ) );
ret = static_cast<const Workflow::Frame*>( m_mainWorkflow->getOutput( Workflow::VideoTrack, m_paused ) );
ptsDiff = ret->ptsDiff;
if ( ptsDiff == 0 )
{
......@@ -175,12 +176,15 @@ WorkflowRenderer::lockVideo( EsHandler *handler, qint64 *pts, size_t *bufferSize
}
{
QReadLocker lock( m_effectsLock );
EffectsEngine::applyFilters( m_filters, ret,
m_effectFrame = EffectsEngine::applyFilters( m_filters, ret,
m_mainWorkflow->getCurrentFrame(),
m_mainWorkflow->getCurrentFrame() * 1000.0 / handler->fps );
}
m_pts = *pts = ptsDiff + m_pts;
*buffer = ret->buffer();
if ( m_effectFrame != NULL )
*buffer = m_effectFrame;
else
*buffer = ret->buffer();
*bufferSize = ret->size();
return 0;
}
......@@ -190,11 +194,11 @@ WorkflowRenderer::lockAudio( EsHandler *handler, qint64 *pts, size_t *bufferSize
{
qint64 ptsDiff;
quint32 nbSample;
Workflow::AudioSample *renderAudioSample;
const Workflow::AudioSample *renderAudioSample;
if ( m_stopping == false && m_paused == false )
{
renderAudioSample = static_cast<Workflow::AudioSample*>( m_mainWorkflow->getOutput( Workflow::AudioTrack,
renderAudioSample = static_cast<const Workflow::AudioSample*>( m_mainWorkflow->getOutput( Workflow::AudioTrack,
m_paused ) );
}
else
......@@ -222,8 +226,11 @@ WorkflowRenderer::lockAudio( EsHandler *handler, qint64 *pts, size_t *bufferSize
return 0;
}
void WorkflowRenderer::unlock( void*, const char*, size_t, void* )
void WorkflowRenderer::unlock( void *datas, const char*, size_t, void* )
{
EsHandler* handler = reinterpret_cast<EsHandler*>( datas );
delete[] handler->self->m_effectFrame;
handler->self->m_effectFrame = NULL;
}
void WorkflowRenderer::startPreview()
......
......@@ -286,6 +286,8 @@ class WorkflowRenderer : public GenericRenderer
QReadWriteLock *m_effectsLock;
EffectsEngine::FilterList m_filters;
quint32 *m_effectFrame;
static const quint8 VideoCookie = '0';
static const quint8 AudioCookie = '1';
......
......@@ -124,7 +124,7 @@ MainWorkflow::startRender( quint32 width, quint32 height, double fps )
computeLength();
}
Workflow::OutputBuffer*
const Workflow::OutputBuffer*
MainWorkflow::getOutput( Workflow::TrackType trackType, bool paused )
{
QMutexLocker lock( m_renderStartedMutex );
......
......@@ -96,7 +96,7 @@ class MainWorkflow : public QObject, public Singleton<MainWorkflow>
* \param trackType The type of track you wish to get the render from.
* \param paused The paused state of the renderer
*/
Workflow::OutputBuffer *getOutput( Workflow::TrackType trackType, bool paused );
const Workflow::OutputBuffer *getOutput( Workflow::TrackType trackType, bool paused );
/**
* \brief Set the workflow position by the desired frame
* \param currentFrame: The desired frame to render from
......
......@@ -176,8 +176,10 @@ VideoClipWorkflow::unlock( VideoClipWorkflow *cw, void *buffer, int width,
Workflow::Frame *frame = cw->m_computedBuffers.last();
{
QWriteLocker lock( cw->m_effectsLock );
EffectsEngine::applyFilters( cw->m_filters, frame, cw->m_renderedFrame,
quint32 *newFrame = EffectsEngine::applyFilters( cw->m_filters, frame, cw->m_renderedFrame,
cw->m_renderedFrame * 1000.0 / cw->clip()->getMedia()->fps() );
if ( newFrame != NULL )
frame->setBuffer( newFrame );
}
{
QMutexLocker lock( cw->m_renderedFrameMutex );
......
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