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

Workflow: Fixing potential deadlock.

Splitting the stopping process in three parts : first stopping the
ClipWorkflow media player, stopping the renderer, and put the workflow
in a stopped state.
This seems to improve the perfs with a MOV sample, though i don't really
see why it would...
parent a5eb7318
......@@ -299,6 +299,7 @@ WorkflowRenderer::killRenderer()
m_isRendering = false;
m_paused = false;
m_stopping = true;
m_mainWorkflow->stopFrameComputing();
m_mediaPlayer->stop();
m_mainWorkflow->stop();
delete[] m_silencedAudioBuffer;
......
......@@ -114,18 +114,28 @@ void ClipWorkflow::clipEndReached()
setState( EndReached );
}
void ClipWorkflow::stop()
void
ClipWorkflow::stop()
{
flushComputedBuffers();
releasePrealocated();
}
void
ClipWorkflow::stopRenderer()
{
if ( m_mediaPlayer )
{
{
QMutexLocker lock( m_renderLock );
m_renderWaitCond->wakeAll();
}
m_mediaPlayer->stop();
disconnect( m_mediaPlayer, SIGNAL( endReached() ), this, SLOT( clipEndReached() ) );
MemoryPool<LibVLCpp::MediaPlayer>::getInstance()->release( m_mediaPlayer );
m_mediaPlayer = NULL;
setState( Stopped );
delete m_vlcMedia;
flushComputedBuffers();
releasePrealocated();
setState( Stopped );
}
}
......
......@@ -193,6 +193,13 @@ class ClipWorkflow : public QObject
*/
bool isResyncRequired();
/**
* \brief Stop the renderer part of the ClipWorkflow
*
* IE. just stop the VLC thread, and do not flush anything.
*/
void stopRenderer();
private:
void setState( State state );
void adjustBegin();
......
......@@ -195,6 +195,13 @@ MainWorkflow::stop()
emit frameChanged( 0, Renderer );
}
void
MainWorkflow::stopFrameComputing()
{
for ( qint32 type = 0; type < NbTrackType; ++type )
m_tracks[type]->stopFrameComputing();
}
void
MainWorkflow::moveClip( const QUuid &clipUuid, unsigned int oldTrack,
unsigned int newTrack, qint64 startingFrame,
......
......@@ -339,6 +339,14 @@ class MainWorkflow : public QObject, public Singleton<MainWorkflow>
*/
bool contains( const QUuid& uuid ) const;
/**
* \brief Stop the frame computing process.
*
* This will stop all the currently running ClipWorkflow.
* This is meant to be called just before the stop() method.
*/
void stopFrameComputing();
private:
MainWorkflow( int trackCount = 64 );
~MainWorkflow();
......
......@@ -325,3 +325,15 @@ TrackHandler::contains( const QUuid &uuid ) const
return true;
return false;
}
void
TrackHandler::stopFrameComputing()
{
for ( unsigned int i = 0; i < m_trackCount; ++i )
{
//First stop the frame computing
m_tracks[i]->stopFrameComputing();
//then deactivate the track to avoid the generation to be resumed.
m_tracks[i].deactivate();
}
}
......@@ -101,6 +101,8 @@ class TrackHandler : public QObject
bool contains( const QUuid& uuid ) const;
void stopFrameComputing();
private:
void computeLength();
void activateTrack( unsigned int tracKId );
......
......@@ -526,3 +526,27 @@ TrackWorkflow::contains( const QUuid &uuid ) const
}
return false;
}
void
TrackWorkflow::stopFrameComputing()
{
QMap<qint64, ClipWorkflow*>::const_iterator it = m_clips.begin();
QMap<qint64, ClipWorkflow*>::const_iterator end = m_clips.end();
while ( it != end )
{
ClipWorkflow* cw = it.value();
cw->getStateLock()->lockForRead();
if ( cw->getState() == ClipWorkflow::Stopped ||
cw->getState() == ClipWorkflow::Muted )
{
cw->getStateLock()->unlock();
return ;
}
cw->getStateLock()->unlock();
cw->stopRenderer();
++it;
}
}
......@@ -87,6 +87,8 @@ class TrackWorkflow : public QObject
bool contains( const QUuid& uuid ) const;
void stopFrameComputing();
private:
void computeLength();
void* renderClip( ClipWorkflow* cw, qint64 currentFrame,
......
......@@ -116,6 +116,9 @@ VideoClipWorkflow::getOutput( ClipWorkflow::GetMode mode )
return NULL;
if ( getNbComputedBuffers() == 0 )
m_renderWaitCond->wait( m_renderLock );
//Recheck again, as the WaitCondition may have been awaken when stopping.
if ( getNbComputedBuffers() == 0 )
return NULL;
::StackedBuffer<LightVideoFrame*>* buff;
if ( mode == ClipWorkflow::Pop )
buff = new StackedBuffer( m_computedBuffers.dequeue(), this, true );
......
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