Commit 5392c2be authored by Hugo Beauzee-Luyssen's avatar Hugo Beauzee-Luyssen
Browse files

This should solve at least one of the pause race condition.

Pause can be toggled until every single ClipWorkflow of every single TrackWorkflow has been paused.
parent 8ee8758c
......@@ -188,14 +188,14 @@ void ClipWorkflow::pauseAfterPlaybackStarted()
disconnect( m_mediaPlayer, SIGNAL( positionChanged() ), this, SLOT( pauseAfterPlaybackStarted() ) );
disconnect( m_mediaPlayer, SIGNAL( playing() ), this, SLOT( pauseAfterPlaybackStarted() ) );
connect( m_mediaPlayer, SIGNAL( paused() ), this, SLOT( pausedMediaPlayer() ), Qt::DirectConnection );
connect( m_mediaPlayer, SIGNAL( paused() ), this, SLOT( initializedMediaPlayer() ), Qt::DirectConnection );
m_mediaPlayer->pause();
}
void ClipWorkflow::pausedMediaPlayer()
void ClipWorkflow::initializedMediaPlayer()
{
disconnect( m_mediaPlayer, SIGNAL( paused() ), this, SLOT( pausedMediaPlayer() ) );
disconnect( m_mediaPlayer, SIGNAL( paused() ), this, SLOT( initializedMediaPlayer() ) );
setState( Ready );
}
......@@ -373,3 +373,8 @@ QMutex* ClipWorkflow::getSleepMutex()
{
return m_condMutex;
}
LibVLCpp::MediaPlayer* ClipWorkflow::getMediaPlayer()
{
return m_mediaPlayer;
}
......@@ -45,15 +45,15 @@ class ClipWorkflow : public QObject
enum State
{
None = -1,
Stopped,
Initializing,
Ready,
Rendering,
Sleeping,
Pausing,
Paused,
Stopping,
EndReached,
Stopped, //0
Initializing, //1
Ready, //2
Rendering, //3
Sleeping, //4
Pausing, //5
Paused, //6
Stopping, //7
EndReached, //8
};
int debugId;
......@@ -154,6 +154,8 @@ class ClipWorkflow : public QObject
void waitForPausingState();
QMutex* getSleepMutex();
LibVLCpp::MediaPlayer* getMediaPlayer();
// void activateOneFrameOnly();
private:
......@@ -206,7 +208,7 @@ class ClipWorkflow : public QObject
private slots:
void pauseAfterPlaybackStarted();
void pausedMediaPlayer();
void initializedMediaPlayer();
void setPositionAfterPlayback();
public slots:
......
......@@ -45,6 +45,7 @@ MainWorkflow::MainWorkflow( int trackCount ) :
{
m_tracks[i].setPtr( new TrackWorkflow( i ) );
connect( m_tracks[i], SIGNAL( trackEndReached( unsigned int ) ), this, SLOT( trackEndReached(unsigned int) ) );
connect( m_tracks[i], SIGNAL( trackPaused() ), this, SLOT( trackPaused() ) );
}
m_renderStartedLock = new QReadWriteLock;
m_renderMutex = new QMutex;
......@@ -127,10 +128,14 @@ void MainWorkflow::pause()
QMutexLocker lock( m_renderMutex );
qDebug() << "Pausing.......................";
m_nbTracksToPause = 0;
for ( unsigned int i = 0; i < m_trackCount; ++i )
{
if ( m_tracks[i].activated() == true )
{
m_nbTracksToPause.fetchAndAddAcquire( 1 );
m_tracks[i]->pause();
}
}
qDebug() << "Pausing completed <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<\n\n";
}
......@@ -249,3 +254,13 @@ void MainWorkflow::activateOneFrameOnly()
m_tracks[i]->activateOneFrameOnly();
}
}
void MainWorkflow::trackPaused()
{
m_nbTracksToPause.fetchAndAddAcquire( -1 );
if ( m_nbTracksToPause == 0 )
{
emit mainWorkflowPaused();
qDebug() << "Emitted mainworkflow paused";
}
}
......@@ -98,12 +98,14 @@ class MainWorkflow : public QObject, public Singleton<MainWorkflow>
QReadWriteLock* m_renderStartedLock;
QMutex* m_renderMutex;
QAtomicInt m_nbTracksToPause;
public slots:
void clipMoved( QUuid, int, int, qint64 );
private slots:
void trackEndReached( unsigned int trackId );
void trackPaused();
signals:
/**
......@@ -116,6 +118,7 @@ class MainWorkflow : public QObject, public Singleton<MainWorkflow>
void positionChanged( float pos );
void mainWorkflowEndReached();
void mainWorkflowPaused();
};
#endif // MAINWORKFLOW_H
......@@ -342,9 +342,13 @@ void TrackWorkflow::pauseClipWorkflow( ClipWorkflow* cw )
cw->getState() == ClipWorkflow::EndReached )
{
qDebug() << "Pausing a sleeping, ready or EndReached ClipWorkflow, state =" << cw->getState();
qDebug() << "getting condwait lock";
cw->getSleepMutex()->lock();
cw->queryStateChange( ClipWorkflow::Pausing );
qDebug() << "Unlocked state mutex";
cw->getStateLock()->unlock();
qDebug() << "Unlocked state mutex";
qDebug() << "Realeasing condwait lock";
cw->getSleepMutex()->unlock();
cw->wake();
}
else if ( cw->getState() == ClipWorkflow::Rendering )
......@@ -388,6 +392,7 @@ void TrackWorkflow::pause()
//FIXME: it's probably bad to iterate over every clip workflows.
qDebug() << "Started track pause loop";
m_nbClipToPause = 0;
for ( ; it != end; ++it )
{
ClipWorkflow* cw = it.value();
......@@ -401,6 +406,8 @@ void TrackWorkflow::pause()
if ( cw->getState() != ClipWorkflow::Paused )
{
cw->getStateLock()->unlock();
m_nbClipToPause.fetchAndAddAcquire( 1 );
connect( cw->getMediaPlayer(), SIGNAL( paused() ), this, SLOT( clipWorkflowPaused() ) );
pauseClipWorkflow( cw );
}
else
......@@ -467,3 +474,13 @@ void TrackWorkflow::activateOneFrameOnly()
{
m_oneFrameOnly = 1;
}
void TrackWorkflow::clipWorkflowPaused()
{
m_nbClipToPause.fetchAndAddAcquire( -1 );
if ( m_nbClipToPause == 0 )
{
emit trackPaused();
qDebug() << "Emitted track paused";
}
}
......@@ -94,8 +94,14 @@ class TrackWorkflow : public QObject
bool m_paused;
QAtomicInt m_oneFrameOnly;
QAtomicInt m_nbClipToPause;
private slots:
void clipWorkflowPaused();
signals:
void trackEndReached( unsigned int );
void trackEndReached( unsigned int );
void trackPaused();
};
#endif // TRACKWORKFLOW_H
......@@ -149,6 +149,7 @@ void WorkflowRenderer::startPreview()
connect( m_mainWorkflow, SIGNAL( frameChanged(qint64) ),
Timeline::getInstance()->tracksView()->tracksCursor(), SLOT( updateCursorPos( qint64 ) ) );
connect( m_mainWorkflow, SIGNAL( mainWorkflowPaused() ), this, SLOT( mainWorkflowPaused() ) );
m_mainWorkflow->startRender();
sprintf( buff, ":fake-duration=%lli", m_mainWorkflow->getLength() / FPS * 1000 );
m_media->addOption( buff );
......@@ -186,7 +187,12 @@ void WorkflowRenderer::pauseMainWorkflow()
{
qDebug() << "In pause callback";
m_mainWorkflow->pause();
}
void WorkflowRenderer::mainWorkflowPaused()
{
m_paused = true;
emit paused();
}
void WorkflowRenderer::togglePlayPause( bool forcePause )
......@@ -252,7 +258,6 @@ void WorkflowRenderer::__videoPaused()
m_oneFrameOnly = 0;
}
pauseMainWorkflow();
emit paused();
}
void WorkflowRenderer::__videoPlaying()
......
......@@ -79,6 +79,8 @@ class WorkflowRenderer : public GenericRenderer
QReadWriteLock* m_actionsLock;
public slots:
void mainWorkflowPaused();
void __positionChanged();
void __positionChanged( float pos );
void __videoPaused();
......
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