Commit 7f0a978e authored by Hugo Beauzee-Luyssen's avatar Hugo Beauzee-Luyssen

Removed all SleepMS from workflows.

Performance are really improved, ie previewing is as fast as watching a video in VLC
parent 7fe5dbdc
......@@ -40,6 +40,8 @@ ClipWorkflow::ClipWorkflow( Clip::Clip* clip ) :
m_requiredStateLock = new QMutex;
m_waitCond = new WaitCondition;
m_initWaitCond = new WaitCondition;
m_renderWaitCond = new WaitCondition;
m_pausingStateWaitCond = new WaitCondition;
// m_backBufferLock = new QReadWriteLock;
}
......@@ -47,6 +49,7 @@ ClipWorkflow::~ClipWorkflow()
{
// delete[] m_backBuffer;
// delete m_backBufferLock;
delete m_pausingStateWaitCond;
delete m_initWaitCond;
delete m_waitCond;
delete m_requiredStateLock;
......@@ -71,6 +74,7 @@ void ClipWorkflow::checkStateChange()
// qDebug() << "Changed state from" << m_state << "to state" << m_requiredState;
m_state = m_requiredState;
m_requiredState = ClipWorkflow::None;
checkSynchronisation( m_state );
}
}
......@@ -106,6 +110,7 @@ void ClipWorkflow::unlock( ClipWorkflow* cw )
{
cw->m_state = Sleeping;
cw->m_stateLock->unlock();
cw->m_renderWaitCond->wake();
// qDebug() << "Entering condwait";
cw->m_waitCond->wait();
......@@ -263,6 +268,9 @@ void ClipWorkflow::checkSynchronisation( State newState )
case Ready:
m_initWaitCond->wake();
break ;
case Pausing:
m_pausingStateWaitCond->wake();
break ;
default:
break ;
}
......@@ -324,3 +332,21 @@ void ClipWorkflow::unpause( bool wakeRenderThread /*= true*/ )
// qDebug() << "Activating one frame only";
// m_oneFrameOnly = 1;
//}
void ClipWorkflow::waitForCompleteRender()
{
if ( isRendering() == true )
m_renderWaitCond->wait();
}
void ClipWorkflow::waitForCompleteInit()
{
if ( isReady() == false )
m_initWaitCond->wait();
}
void ClipWorkflow::waitForPausingState()
{
if ( getState() != Pausing )
m_pausingStateWaitCond->wait();
}
......@@ -147,6 +147,10 @@ class ClipWorkflow : public QObject
void unpause( bool wakeRenderThread = true );
void waitForCompleteInit();
void waitForCompleteRender();
void waitForPausingState();
// void activateOneFrameOnly();
private:
......@@ -194,7 +198,8 @@ class ClipWorkflow : public QObject
QAtomicInt m_oneFrameOnly;
WaitCondition* m_initWaitCond;
WaitCondition* m_renderWaitCond;
WaitCondition* m_pausingStateWaitCond;
private slots:
void pauseAfterPlaybackStarted();
......
......@@ -104,10 +104,7 @@ unsigned char* TrackWorkflow::renderClip( ClipWorkflow* cw, qint64 currentF
//The rendering state meens... whell it means that the frame is
//beeing rendered, so we wait.
cw->getStateLock()->unlock();
while ( cw->isRendering() == true )
{
SleepMS( 100 );
}
cw->waitForCompleteRender();
//This way we can trigger the appropriate if just below.
//by restoring the initial state of the function, and just pretend that
//nothing happened.
......@@ -205,8 +202,7 @@ void TrackWorkflow::stopClipWorkflow( ClipWorkflow* cw )
else if ( cw->getState() == ClipWorkflow::Rendering )
{
cw->getStateLock()->unlock();
while ( cw->isRendering() == true )
SleepMS( 1 );
cw->waitForCompleteRender();
cw->queryStateChange( ClipWorkflow::Stopping );
cw->wake();
cw->stop();
......@@ -214,8 +210,7 @@ void TrackWorkflow::stopClipWorkflow( ClipWorkflow* cw )
else if ( cw->getState() == ClipWorkflow::Initializing )
{
cw->getStateLock()->unlock();
while ( cw->isReady() == false )
SleepMS( 1 );
cw->waitForCompleteInit();
cw->stop();
}
else if ( cw->getState() == ClipWorkflow::Paused )
......@@ -348,30 +343,21 @@ void TrackWorkflow::pauseClipWorkflow( ClipWorkflow* cw )
else if ( cw->getState() == ClipWorkflow::Rendering )
{
cw->getStateLock()->unlock();
while ( cw->isRendering() == true )
SleepMS( 1 );
cw->waitForCompleteRender();
cw->queryStateChange( ClipWorkflow::Pausing );
cw->wake();
}
else if ( cw->getState() == ClipWorkflow::Initializing )
{
cw->getStateLock()->unlock();
while ( cw->isReady() == false )
SleepMS( 1 );
cw->waitForCompleteInit();
}
else
{
qDebug() << "Unexpected ClipWorkflow::State when pausing:" << cw->getState();
cw->getStateLock()->unlock();
}
bool pausing = false;
while ( pausing == false )
{
cw->getStateLock()->lockForRead();
pausing = ( cw->getState() == ClipWorkflow::Pausing );
SleepMS( 1 );
cw->getStateLock()->unlock();
}
cw->waitForPausingState();
cw->pause();
}
......
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