Commit 2ddc015a authored by Hugo Beauzee-Luyssen's avatar Hugo Beauzee-Luyssen

Solved potential deadlock when pausing preview.

Solves #83
parent d465337d
......@@ -43,6 +43,7 @@ void Stack::addAction( Action::Generic* act )
{
if ( (*it)->isOpposite( act ) == true )
{
qDebug() << "is opposite == true";
delete *it;
it = erase( it );
delete act;
......
......@@ -64,8 +64,8 @@ WorkflowRenderer::WorkflowRenderer() :
m_renderVideoFrame = new unsigned char[VIDEOHEIGHT * VIDEOWIDTH * Pixel::NbComposantes];
//Workflow part
connect( m_mainWorkflow, SIGNAL( mainWorkflowPaused() ), this, SLOT( mainWorkflowPaused() ) );
connect( m_mainWorkflow, SIGNAL( mainWorkflowUnpaused() ), this, SLOT( mainWorkflowUnpaused() ) );
connect( m_mainWorkflow, SIGNAL( mainWorkflowPaused() ), this, SLOT( mainWorkflowPaused() ), Qt::QueuedConnection );
connect( m_mainWorkflow, SIGNAL( mainWorkflowUnpaused() ), this, SLOT( mainWorkflowUnpaused() ), Qt::QueuedConnection );
connect( m_mainWorkflow, SIGNAL( mainWorkflowEndReached() ), this, SLOT( __endReached() ) );
connect( m_mainWorkflow, SIGNAL( frameChanged( qint64, MainWorkflow::FrameChangedReason ) ),
this, SLOT( __frameChanged( qint64, MainWorkflow::FrameChangedReason ) ) );
......@@ -93,7 +93,8 @@ void* WorkflowRenderer::lock( void* datas )
{
WorkflowRenderer* self = reinterpret_cast<WorkflowRenderer*>( datas );
if ( self->m_stopping == false )
//FIXME: when frame by frame will work again, we will probably have to remove the m_paused check.
if ( self->m_stopping == false && self->m_paused == false )
{
MainWorkflow::OutputBuffers* ret = self->m_mainWorkflow->getSynchroneOutput();
memcpy( self->m_renderVideoFrame, (*(ret->video))->frame.octets, (*(ret->video))->nboctets );
......@@ -105,7 +106,6 @@ void* WorkflowRenderer::lock( void* datas )
void WorkflowRenderer::unlock( void* datas )
{
WorkflowRenderer* self = reinterpret_cast<WorkflowRenderer*>( datas );
qDebug() << ""
self->checkActions();
}
......
......@@ -45,6 +45,7 @@ MainWorkflow::MainWorkflow( int trackCount ) :
m_renderMutex = new QMutex;
m_synchroneRenderWaitCondition = new QWaitCondition;
m_synchroneRenderWaitConditionMutex = new QMutex;
m_pauseWaitCond = new WaitCondition;
m_effectEngine = new EffectsEngine;
m_effectEngine->disable();
......@@ -70,6 +71,7 @@ MainWorkflow::~MainWorkflow()
//FIXME: this is probably useless, since already done by the renderer
stop();
delete m_pauseWaitCond;
delete m_effectEngine;
delete m_synchroneRenderWaitConditionMutex;
delete m_synchroneRenderWaitCondition;
......@@ -136,10 +138,14 @@ void MainWorkflow::getOutput()
void MainWorkflow::pause()
{
QMutexLocker lock( m_renderMutex );
//Just wait for the current render to finish
m_renderMutex->lock();
QMutexLocker lock( m_pauseWaitCond->getMutex() );
m_renderMutex->unlock();
for ( unsigned int i = 0; i < MainWorkflow::NbTrackType; ++i )
m_tracks[i]->pause();
m_pauseWaitCond->waitLocked();
}
void MainWorkflow::unpause()
......@@ -392,6 +398,10 @@ void MainWorkflow::tracksPaused()
if ( m_tracks[i]->isPaused() == false )
return ;
m_paused = true;
{
QMutexLocker lock( m_pauseWaitCond->getMutex() );
m_pauseWaitCond->wake();
}
emit mainWorkflowPaused();
}
......
......@@ -30,6 +30,7 @@
#include <QDomElement>
#include <QWaitCondition>
#include "WaitCondition.hpp"
#include "Singleton.hpp"
#include "Clip.h"
#include "LightVideoFrame.h"
......@@ -150,6 +151,8 @@ class MainWorkflow : public QObject, public Singleton<MainWorkflow>
QMutex* m_renderMutex;
QWaitCondition* m_synchroneRenderWaitCondition;
QMutex* m_synchroneRenderWaitConditionMutex;
WaitCondition* m_pauseWaitCond;
bool m_paused;
TrackHandler** m_tracks;
OutputBuffers* m_outputBuffers;
......
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