Commit bb59b5e4 authored by Hugo Beauzee-Luyssen's avatar Hugo Beauzee-Luyssen

Adjusting common clipworkflow parts, removed useless connect/signals

parent f9ff7c22
......@@ -56,6 +56,7 @@ void* AudioClipWorkflow::getOutput( ClipWorkflow::GetMode mode )
{
QMutexLocker lock( m_renderLock );
preGetOutput();
if ( isEndReached() == true )
{
qDebug() << "Audio end reached";
......@@ -64,7 +65,7 @@ void* AudioClipWorkflow::getOutput( ClipWorkflow::GetMode mode )
if ( mode == ClipWorkflow::Get )
qCritical() << "A sound buffer should never be asked with 'Get' mode";
StackedBuffer<AudioSample*>* buff = new StackedBuffer<AudioSample*>( m_computedBuffers.pop(), &m_availableBuffers, true );
ClipWorkflow::getOutput( mode );
postGetOutput();
return buff;
}
......
......@@ -40,6 +40,7 @@ ClipWorkflow::ClipWorkflow( Clip::Clip* clip ) :
m_initWaitCond = new WaitCondition;
m_pausingStateWaitCond = new WaitCondition;
m_renderLock = new QMutex;
m_feedingCondWait = new WaitCondition;
}
ClipWorkflow::~ClipWorkflow()
......@@ -186,7 +187,7 @@ LibVLCpp::MediaPlayer* ClipWorkflow::getMediaPlayer()
return m_mediaPlayer;
}
void* ClipWorkflow::getOutput( ClipWorkflow::GetMode )
void ClipWorkflow::postGetOutput()
{
//If we have more empty buffers than computed ones, refill our stack.
if ( getComputedBuffers() > getAvailableBuffers() )
......@@ -195,14 +196,29 @@ void* ClipWorkflow::getOutput( ClipWorkflow::GetMode )
//FIXME: this is probably a very bad idea...
m_mediaPlayer->pause();
}
//Keep the compiler happy, but we don't use this return value.
return NULL;
}
void ClipWorkflow::preGetOutput()
{
QMutexLocker lock( m_feedingCondWait->getMutex() );
if ( getComputedBuffers() == 0 )
{
qWarning() << "Waiting for buffer to be fed";
m_feedingCondWait->waitLocked();
}
}
void ClipWorkflow::commonUnlock()
{
if ( getAvailableBuffers() == 0 )
m_mediaPlayer->pause();
if ( getComputedBuffers() == 1 )
{
QMutexLocker lock( m_feedingCondWait->getMutex() );
qWarning() << "Just rendered the first buffer.";
m_feedingCondWait->wake();
}
checkStateChange();
}
......
......@@ -71,7 +71,9 @@ class ClipWorkflow : public QObject
* therefore, you can call this method blindly, without taking care
* of the rendering process advancement.
*/
virtual void* getOutput( ClipWorkflow::GetMode mode );
virtual void* getOutput( ClipWorkflow::GetMode mode ) = 0;
void preGetOutput();
void postGetOutput();
virtual void initVlcOutput() = 0;
void initialize();
......@@ -178,6 +180,12 @@ class ClipWorkflow : public QObject
* \brief The VLC media used to render
*/
LibVLCpp::Media* m_vlcMedia;
/**
* \brief This is used for basic synchronisation when
* the clipworkflow hasn't generate a frame yet,
* while the renderer asks for one.
*/
WaitCondition* m_feedingCondWait;
protected:
/**
......@@ -187,8 +195,6 @@ class ClipWorkflow : public QObject
private slots:
void loadingComplete();
public slots:
void clipEndReached();
};
......
......@@ -55,9 +55,6 @@ MainWorkflow::MainWorkflow( int trackCount ) :
{
MainWorkflow::TrackType trackType = (i == 0 ? MainWorkflow::VideoTrack : MainWorkflow::AudioTrack );
m_tracks[i] = new TrackHandler( trackCount, trackType, m_effectEngine );
connect( m_tracks[i], SIGNAL( tracksPaused() ), this, SLOT( tracksPaused() ) );
connect( m_tracks[i], SIGNAL( tracksUnpaused() ), this, SLOT( tracksUnpaused() ) );
connect( m_tracks[i], SIGNAL( allTracksRenderCompleted() ), this, SLOT( tracksRenderCompleted() ) );
connect( m_tracks[i], SIGNAL( tracksEndReached() ), this, SLOT( tracksEndReached() ) );
m_currentFrame[i] = 0;
}
......@@ -145,21 +142,27 @@ MainWorkflow::OutputBuffers* MainWorkflow::getOutput( TrackType trackType )
void MainWorkflow::pause()
{
//Just wait for the current render to finish
//TODO:
//FIXME: check if this is not alreay handled by the stacked actions system.
QMutexLocker lock( m_renderMutex );
{
//Just wait for the current render to finish
//TODO:
//FIXME: check if this is not alreay handled by the stacked actions system.
QMutexLocker lock( m_renderMutex );
for ( unsigned int i = 0; i < MainWorkflow::NbTrackType; ++i )
m_tracks[i]->pause();
for ( unsigned int i = 0; i < MainWorkflow::NbTrackType; ++i )
m_tracks[i]->pause();
}
emit mainWorkflowPaused();
}
void MainWorkflow::unpause()
{
QMutexLocker lock( m_renderMutex );
{
QMutexLocker lock( m_renderMutex );
for ( unsigned int i = 0; i < MainWorkflow::NbTrackType; ++i )
m_tracks[i]->unpause();
for ( unsigned int i = 0; i < MainWorkflow::NbTrackType; ++i )
m_tracks[i]->unpause();
}
emit mainWorkflowUnpaused();
}
void MainWorkflow::goToNextFrame( MainWorkflow::TrackType trackType )
......
......@@ -188,6 +188,8 @@ class MainWorkflow : public QObject, public Singleton<MainWorkflow>
void clipRemoved( Clip*, unsigned int, MainWorkflow::TrackType );
void clipMoved( QUuid, unsigned int, qint64, MainWorkflow::TrackType );
void cleared();
void mainWorkflowPaused();
void mainWorkflowUnpaused();
};
#endif // MAINWORKFLOW_H
......@@ -75,9 +75,6 @@ void TrackWorkflow::addClip( Clip* clip, qint64 start )
void TrackWorkflow::addClip( ClipWorkflow* cw, qint64 start )
{
QWriteLocker lock( m_clipsLock );
connect( cw, SIGNAL( renderComplete( ClipWorkflow* ) ), this, SLOT( clipWorkflowRenderCompleted( ClipWorkflow* ) ), Qt::DirectConnection );
connect( cw, SIGNAL( paused() ), this, SLOT( clipWorkflowPaused() ) );
connect( cw, SIGNAL( unpaused() ), this, SLOT( clipWorkflowUnpaused() ) );
m_clips.insert( start, cw );
computeLength();
}
......
......@@ -88,6 +88,8 @@ void* VideoClipWorkflow::getOutput( ClipWorkflow::GetMode mode )
{
QMutexLocker lock( m_renderLock );
preGetOutput();
qWarning() << "poping buffer";
if ( isEndReached() == true )
return NULL;
......@@ -96,7 +98,7 @@ void* VideoClipWorkflow::getOutput( ClipWorkflow::GetMode mode )
buff = new StackedBuffer<LightVideoFrame*>( m_computedBuffers.pop(), &m_availableBuffers, true );
else if ( mode == ClipWorkflow::Get )
buff = new StackedBuffer<LightVideoFrame*>( m_computedBuffers.head(), NULL, false );
ClipWorkflow::getOutput( mode );
ClipWorkflow::postGetOutput();
return buff;
}
......@@ -122,7 +124,7 @@ void VideoClipWorkflow::unlock( VideoClipWorkflow* cw, void* buffer, int widt
LightVideoFrame* lvf = cw->m_computedBuffers.head();
(*(lvf))->ptsDiff = cw->m_currentPts - cw->m_previousPts;
cw->m_renderLock->unlock();
//If this is the first buffer that has been rendered, there may be a waiting TrackWorkflow.
cw->commonUnlock();
}
......
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