Commit 87e73d35 authored by Hugo Beauzee-Luyssen's avatar Hugo Beauzee-Luyssen

Resolved potential bug when rendering too fast

parent 9ef8e805
......@@ -74,7 +74,7 @@ void ClipWorkflow::checkStateChange()
if ( m_requiredState != ClipWorkflow::None )
{
m_state = m_requiredState;
// qDebug() << '[' << (void*)this << "] Applying required state change:" << m_state;
qDebug() << '[' << (void*)this << "] Applying required state change:" << m_state;
m_requiredState = ClipWorkflow::None;
checkSynchronisation( m_state );
}
......@@ -85,7 +85,7 @@ void ClipWorkflow::lock( ClipWorkflow* cw, void** pp_ret, int size )
Q_UNUSED( size );
cw->m_renderLock->lock();
*pp_ret = cw->m_buffer;
// qDebug() << '[' << (void*)cw << "] ClipWorkflow::lock";
qDebug() << '[' << (void*)cw << "] ClipWorkflow::lock";
}
void ClipWorkflow::unlock( ClipWorkflow* cw, void* buffer, int width, int height, int bpp, int size )
......@@ -110,7 +110,7 @@ void ClipWorkflow::unlock( ClipWorkflow* cw, void* buffer, int width, int hei
cw->m_renderWaitCond->wake();
}
cw->emit renderComplete( cw );
// qDebug() << "Emmiting render completed";
qDebug() << "Emmiting render completed";
// qDebug() << "Entering cond wait";
cw->m_waitCond->wait( cw->m_condMutex );
......@@ -122,7 +122,7 @@ void ClipWorkflow::unlock( ClipWorkflow* cw, void* buffer, int width, int hei
}
else
cw->m_stateLock->unlock();
// qDebug() << '[' << (void*)cw << "] ClipWorkflow::unlock";
qDebug() << '[' << (void*)cw << "] ClipWorkflow::unlock";
cw->checkStateChange();
}
......@@ -303,7 +303,7 @@ void ClipWorkflow::setState( State state )
{
{
QWriteLocker lock( m_stateLock );
// qDebug() << '[' << (void*)this << "] Setting state to" << state;
qDebug() << '[' << (void*)this << "] Setting state to" << state;
m_state = state;
}
checkSynchronisation( state );
......
......@@ -54,12 +54,14 @@ MainWorkflow::MainWorkflow( int trackCount ) :
m_highestTrackNumberMutex = new QMutex;
m_synchroneRenderWaitCondition = new QWaitCondition;
m_synchroneRenderWaitConditionMutex = new QMutex;
m_nbTracksToRenderMutex = new QMutex;
}
MainWorkflow::~MainWorkflow()
{
stop();
delete m_nbTracksToRenderMutex;
delete m_synchroneRenderWaitConditionMutex;
delete m_synchroneRenderWaitCondition;
delete m_highestTrackNumberMutex;
......@@ -125,12 +127,13 @@ void MainWorkflow::getOutput()
m_synchroneRenderingBuffer = NULL;
if ( m_renderStarted == true )
{
QMutexLocker lockNbTracks( m_nbTracksToRenderMutex );
for ( unsigned int i = 0; i < m_trackCount; ++i )
{
if ( m_tracks[i].activated() == false )
continue ;
m_nbTracksToRender.fetchAndAddAcquire( 1 );
++m_nbTracksToRender;
m_tracks[i]->getOutput( m_currentFrame );
}
if ( m_paused == false )
......@@ -272,8 +275,8 @@ void MainWorkflow::moveClip( const QUuid& clipUuid, unsigned int oldTr
}
else
{
Clip* clip = m_tracks[oldTrack]->removeClip( clipUuid );
m_tracks[newTrack]->addClip( clip, startingFrame );
ClipWorkflow* cw = m_tracks[oldTrack]->removeClipWorkflow( clipUuid );
m_tracks[newTrack]->addClip( cw, startingFrame );
activateTrack( oldTrack );
activateTrack( newTrack );
}
......@@ -317,7 +320,8 @@ void MainWorkflow::trackUnpaused()
void MainWorkflow::tracksRenderCompleted( unsigned int trackId )
{
m_nbTracksToRender.fetchAndAddAcquire( -1 );
QMutexLocker lockNbTracks( m_nbTracksToRenderMutex );
--m_nbTracksToRender;
{
QMutexLocker lock( m_highestTrackNumberMutex );
......
......@@ -134,7 +134,8 @@ class MainWorkflow : public QObject, public Singleton<MainWorkflow>
QMutex* m_renderMutex;
QAtomicInt m_nbTracksToPause;
QAtomicInt m_nbTracksToUnpause;
QAtomicInt m_nbTracksToRender;
unsigned int m_nbTracksToRender;
QMutex* m_nbTracksToRenderMutex;
QMutex* m_highestTrackNumberMutex;
unsigned int m_highestTrackNumber;
unsigned char* m_synchroneRenderingBuffer;
......
......@@ -117,7 +117,7 @@ void TrackWorkflow::renderClip( ClipWorkflow* cw, qint64 currentFrame,
{
cw->getStateLock()->lockForRead();
// qDebug() << "Rendering clip" << cw << "state:" << cw->getState();
qDebug() << "Rendering clip" << cw << "state:" << cw->getState();
if ( cw->getState() == ClipWorkflow::Rendering )
{
//The rendering state meens... whell it means that the frame is
......@@ -429,6 +429,28 @@ Clip* TrackWorkflow::removeClip( const QUuid& id )
return NULL;
}
ClipWorkflow* TrackWorkflow::removeClipWorkflow( const QUuid& id )
{
QWriteLocker lock( m_clipsLock );
QMap<qint64, ClipWorkflow*>::iterator it = m_clips.begin();
QMap<qint64, ClipWorkflow*>::iterator end = m_clips.end();
while ( it != end )
{
if ( it.value()->getClip()->getUuid() == id )
{
ClipWorkflow* cw = it.value();
m_clips.erase( it );
computeLength();
return cw;
}
++it;
}
return NULL;
}
void TrackWorkflow::clipWorkflowRenderCompleted( ClipWorkflow* cw )
{
if ( cw != NULL )
......
......@@ -57,7 +57,9 @@ class TrackWorkflow : public QObject
void unpause();
void moveClip( const QUuid& id, qint64 startingFrame );
Clip* removeClip( const QUuid& id );
ClipWorkflow* removeClipWorkflow( const QUuid& id );
void addClip( Clip*, qint64 start );
void addClip( ClipWorkflow*, qint64 start );
qint64 getClipPosition( const QUuid& uuid ) const;
Clip* getClip( const QUuid& uuid );
......@@ -81,7 +83,6 @@ class TrackWorkflow : public QObject
void preloadClip( ClipWorkflow* cw );
void stopClipWorkflow( ClipWorkflow* cw );
bool checkEnd( qint64 currentFrame ) const;
void addClip( ClipWorkflow*, qint64 start );
void adjustClipTime( qint64 currentFrame, qint64 start, ClipWorkflow* cw );
......
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