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

Workflow: Stop the renderer when something goes wrong.

Removing useless methods.
This commit should solve some potential deadlocks
parent f67c2b1c
......@@ -84,7 +84,7 @@ AudioClipWorkflow::getOutput( ClipWorkflow::GetMode mode )
if ( getNbComputedBuffers() == 0 )
return NULL;
if ( isEndReached() == true )
if ( shouldRender() == false )
return NULL;
if ( mode == ClipWorkflow::Get )
qCritical() << "A sound buffer should never be asked with 'Get' mode";
......
......@@ -68,10 +68,12 @@ void ClipWorkflow::initialize()
connect( m_mediaPlayer, SIGNAL( playing() ), this, SLOT( loadingComplete() ), Qt::DirectConnection );
connect( m_mediaPlayer, SIGNAL( endReached() ), this, SLOT( clipEndReached() ), Qt::DirectConnection );
connect( m_mediaPlayer, SIGNAL( errorEncountered() ), this, SLOT( errorEncountered() ) );
m_mediaPlayer->play();
}
void ClipWorkflow::loadingComplete()
void
ClipWorkflow::loadingComplete()
{
adjustBegin();
disconnect( m_mediaPlayer, SIGNAL( playing() ), this, SLOT( loadingComplete() ) );
......@@ -82,7 +84,8 @@ void ClipWorkflow::loadingComplete()
m_initWaitCond->wake();
}
void ClipWorkflow::adjustBegin()
void
ClipWorkflow::adjustBegin()
{
if ( m_clipHelper->clip()->getMedia()->fileType() == Media::Video ||
m_clipHelper->clip()->getMedia()->fileType() == Media::Audio )
......@@ -92,24 +95,14 @@ void ClipWorkflow::adjustBegin()
}
}
bool ClipWorkflow::isEndReached() const
{
QReadLocker lock( m_stateLock );
return m_state == ClipWorkflow::EndReached;
}
bool ClipWorkflow::isStopped() const
{
QReadLocker lock( m_stateLock );
return m_state == ClipWorkflow::Stopped;
}
ClipWorkflow::State ClipWorkflow::getState() const
ClipWorkflow::State
ClipWorkflow::getState() const
{
return m_state;
}
void ClipWorkflow::clipEndReached()
void
ClipWorkflow::clipEndReached()
{
setState( EndReached );
}
......@@ -126,6 +119,11 @@ ClipWorkflow::stopRenderer()
{
if ( m_mediaPlayer )
{
setState( Stopping );
{
QMutexLocker lock( m_initWaitCond->getMutex() );
m_initWaitCond->wake();
}
{
QMutexLocker lock( m_renderLock );
m_renderWaitCond->wakeAll();
......@@ -152,12 +150,6 @@ ClipWorkflow::setTime( qint64 time )
}
}
bool ClipWorkflow::isRendering() const
{
QReadLocker lock( m_stateLock );
return m_state == ClipWorkflow::Rendering;
}
void ClipWorkflow::setState( State state )
{
QWriteLocker lock( m_stateLock );
......@@ -169,13 +161,30 @@ QReadWriteLock* ClipWorkflow::getStateLock()
return m_stateLock;
}
void ClipWorkflow::waitForCompleteInit()
bool
ClipWorkflow::waitForCompleteInit()
{
if ( isRendering() == false )
m_stateLock->lockForRead();
if ( m_state != ClipWorkflow::Rendering && m_state != ClipWorkflow::Error )
{
if ( m_state == ClipWorkflow::Error )
{
m_stateLock->unlock();
return false;
}
m_stateLock->unlock();
QMutexLocker lock( m_initWaitCond->getMutex() );
m_initWaitCond->waitLocked();
m_stateLock->lockForRead();
if ( m_state == ClipWorkflow::Error )
{
m_stateLock->unlock();
return false;
}
}
m_stateLock->unlock();
return true;
}
LibVLCpp::MediaPlayer* ClipWorkflow::getMediaPlayer()
......@@ -279,3 +288,20 @@ ClipWorkflow::isResyncRequired()
}
return false;
}
void
ClipWorkflow::errorEncountered()
{
stopRenderer();
setState( Error );
emit error();
}
bool
ClipWorkflow::shouldRender() const
{
QReadLocker lock( m_stateLock );
return ( m_state != ClipWorkflow::Error &&
m_state != ClipWorkflow::Stopped &&
m_state != ClipWorkflow::Stopping );
}
......@@ -76,7 +76,9 @@ class ClipWorkflow : public QObject
/// because of a sufficient number of computed buffers
Paused, //7
/// \brief This state means a clip is mutted and must not be restarted
Muted,
Muted, //8
/// \brief An error was encountered, this ClipWorkflow must not be used anymore.
Error, //9
};
/**
......@@ -104,22 +106,12 @@ class ClipWorkflow : public QObject
void initialize();
/**
* Return true ONLY if the state is equal to EndReached.
* In any other cases, this will return false.
*/
bool isEndReached() const;
/**
* Return true ONLY if the state is equal to Stopped.
* In any other cases, this will return false.
*/
bool isStopped() const;
/**
* Return true ONLY if the state is equal to Rendering.
* In any other cases, this will return false.
* \return true if the ClipWorkflow is able to, and should render
* a frame.
*
* This is true when the state is not stopped, stopping, nor rendering.
*/
bool isRendering() const;
bool shouldRender() const;
/**
* Returns the current workflow state.
......@@ -169,7 +161,7 @@ class ClipWorkflow : public QObject
*/
QReadWriteLock* getStateLock();
void waitForCompleteInit();
bool waitForCompleteInit();
virtual void* getLockCallback() const = 0;
virtual void* getUnlockCallback() const = 0;
......@@ -264,6 +256,10 @@ class ClipWorkflow : public QObject
void mediaPlayerPaused();
void mediaPlayerUnpaused();
void resyncClipWorkflow();
void errorEncountered();
signals:
void error();
};
#endif // CLIPWORKFLOW_H
......@@ -159,7 +159,9 @@ TrackWorkflow::renderClip( ClipWorkflow* cw, qint64 currentFrame,
{
cw->getStateLock()->unlock();
cw->initialize();
cw->waitForCompleteInit();
//If the init failed, don't even try to call getOutput.
if ( cw->waitForCompleteInit() == false )
return NULL;
//We check for a difference greater than one to avoid false positive when starting.
if ( ( qAbs(start - currentFrame) > 1 ) || cw->getClipHelper()->begin() != 0 )
{
......@@ -169,7 +171,8 @@ TrackWorkflow::renderClip( ClipWorkflow* cw, qint64 currentFrame,
return cw->getOutput( mode );
}
else if ( cw->getState() == ClipWorkflow::EndReached ||
cw->getState() == ClipWorkflow::Muted )
cw->getState() == ClipWorkflow::Muted ||
cw->getState() == ClipWorkflow::Error )
{
cw->getStateLock()->unlock();
//The stopClipWorkflow() method will take care of that.
......@@ -201,7 +204,8 @@ void TrackWorkflow::stopClipWorkflow( ClipWorkflow* cw )
cw->getStateLock()->lockForRead();
if ( cw->getState() == ClipWorkflow::Stopped ||
cw->getState() == ClipWorkflow::Muted )
cw->getState() == ClipWorkflow::Muted ||
cw->getState() == ClipWorkflow::Error )
{
cw->getStateLock()->unlock();
return ;
......@@ -540,7 +544,8 @@ TrackWorkflow::stopFrameComputing()
cw->getStateLock()->lockForRead();
if ( cw->getState() == ClipWorkflow::Stopped ||
cw->getState() == ClipWorkflow::Muted )
cw->getState() == ClipWorkflow::Muted ||
cw->getState() == ClipWorkflow::Error )
{
cw->getStateLock()->unlock();
return ;
......
......@@ -112,7 +112,7 @@ VideoClipWorkflow::getOutput( ClipWorkflow::GetMode mode )
{
QMutexLocker lock( m_renderLock );
if ( isEndReached() == true )
if ( shouldRender() == false )
return NULL;
if ( getNbComputedBuffers() == 0 )
m_renderWaitCond->wait( m_renderLock );
......
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