Commit 56a33199 authored by Hugo Beauzee-Luyssen's avatar Hugo Beauzee-Luyssen

Solved hang up when end of last track is reached

parent f966e799
......@@ -32,7 +32,7 @@ Instance::Instance()
{
char const *argv[] =
{
"-vvvvv",
// "-vvvvv",
"--no-skip-frames",
// "--intf", "dummy",
//"--no-audio",
......
......@@ -44,6 +44,7 @@ MainWorkflow::MainWorkflow( int trackCount ) :
for ( int i = 0; i < trackCount; ++i )
{
m_tracks[i].setPtr( new TrackWorkflow( i ) );
m_tracks[i].deactivate();
connect( m_tracks[i], SIGNAL( trackEndReached( unsigned int ) ), this, SLOT( trackEndReached(unsigned int) ) );
connect( m_tracks[i], SIGNAL( trackPaused() ), this, SLOT( trackPaused() ) );
connect( m_tracks[i], SIGNAL( trackUnpaused() ), this, SLOT( trackUnpaused() ) );
......@@ -76,10 +77,9 @@ void MainWorkflow::addClip( Clip* clip, unsigned int trackId, qint64 start )
Q_ASSERT_X( trackId < m_trackCount, "MainWorkflow::addClip",
"The specified trackId isn't valid, for it's higher than the number of tracks");
//if the track is deactivated, we need to reactivate it :
if ( m_tracks[trackId].deactivated() == true )
m_tracks[trackId].activate();
m_tracks[trackId]->addClip( clip, start );
//if the track is deactivated, we need to reactivate it :
activateTrack( trackId );
if ( m_tracks[trackId]->getLength() > m_length )
m_length = m_tracks[trackId]->getLength();
}
......@@ -103,7 +103,9 @@ void MainWorkflow::startRender()
m_currentFrame = 0;
emit frameChanged( 0 );
for ( unsigned int i = 0; i < m_trackCount; ++i )
m_tracks[i].activate();
{
activateTrack( i );
}
computeLength();
}
......@@ -187,7 +189,7 @@ void MainWorkflow::setPosition( float pos )
//Since any track can be reactivated, we reactivate all of them, and let them
//unable themself if required.
for ( unsigned int i = 0; i < m_trackCount; ++i)
m_tracks[i].activate();
activateTrack( i );
qint64 frame = static_cast<qint64>( (float)m_length * pos );
m_currentFrame = frame;
......@@ -210,13 +212,18 @@ qint64 MainWorkflow::getClipPosition( const QUuid& uuid, unsigned int track
void MainWorkflow::trackEndReached( unsigned int trackId )
{
qDebug() << "End of track: deactivating";
m_tracks[trackId].deactivate();
for ( unsigned int i = 0; i < m_trackCount; ++i)
{
if ( m_tracks[i].activated() == true )
{
qDebug() << "Track" << i << "is still activated";
return ;
}
}
qDebug() << "End of main workflow";
emit mainWorkflowEndReached();
m_renderStarted = false;
m_currentFrame = 0;
......@@ -266,14 +273,14 @@ void MainWorkflow::moveClip( const QUuid& clipUuid, unsigned int oldTr
{
//And now, just move the clip.
m_tracks[newTrack]->moveClip( clipUuid, startingFrame );
m_tracks[newTrack].activate();
activateTrack( newTrack );
}
else
{
Clip* clip = m_tracks[oldTrack]->removeClip( clipUuid );
m_tracks[newTrack]->addClip( clip, startingFrame );
m_tracks[oldTrack].activate();
m_tracks[newTrack].activate();
activateTrack( oldTrack );
activateTrack( newTrack );
}
computeLength();
if ( undoRedoCommand == true )
......@@ -369,3 +376,12 @@ void MainWorkflow::setCurrentFrame( qint64 currentFrame )
m_currentFrame = currentFrame;
emit positionChanged( (float)m_currentFrame / (float)m_length );
}
void MainWorkflow::activateTrack( unsigned int trackId )
{
if ( m_tracks[trackId]->getLength() > 0 )
{
qDebug()<< "Activating track" << trackId;
m_tracks[trackId].activate();
}
}
......@@ -104,6 +104,7 @@ class MainWorkflow : public QObject, public Singleton<MainWorkflow>
private:
void computeLength();
void activateTrack( unsigned int trackId );
private:
Toggleable<TrackWorkflow*>* m_tracks;
......
......@@ -191,7 +191,7 @@ void TrackWorkflow::preloadClip( ClipWorkflow* cw )
cw->getStateLock()->unlock();
}
void TrackWorkflow::stopClipWorkflow( ClipWorkflow* cw )
void TrackWorkflow::stopClipWorkflow( CW& cw )
{
cw->getStateLock()->lockForRead();
......@@ -239,6 +239,8 @@ void TrackWorkflow::stopClipWorkflow( ClipWorkflow* cw )
cw->getStateLock()->unlock();
return ;
}
qDebug() << "Reactivating clip workflow";
cw.activate();
}
void TrackWorkflow::stop()
......@@ -277,13 +279,18 @@ bool TrackWorkflow::getOutput( qint64 currentFrame )
}
m_nbClipToRender = 0;
while ( it != end )
for (; it != end; ++it )
{
qint64 start = it.key();
ClipWorkflow* cw = it.value();
//Is the clip supposed to render now ?
if ( start <= currentFrame && currentFrame <= start + cw->getClip()->getLength() )
{
if ( it.value().activated() == false )
{
qDebug() << "ClipWorkflow is deactivated. Ignoring it";
continue ;
}
m_nbClipToRender.fetchAndAddAcquire( 1 );
renderClip( cw, currentFrame, start, needRepositioning );
lastFrame = currentFrame;
......@@ -298,10 +305,8 @@ bool TrackWorkflow::getOutput( qint64 currentFrame )
//Is it supposed to be stopped ?
else
{
stopClipWorkflow( cw );
stopClipWorkflow( it.value() );
}
++it;
}
if ( hasRendered == false )
{
......@@ -472,15 +477,26 @@ void TrackWorkflow::clipWorkflowUnpaused()
void TrackWorkflow::clipWorkflowEndReached( ClipWorkflow* cw )
{
QMap<qint64, CW>::iterator it = m_clips.begin();
QMap<qint64, CW>::iterator end = m_clips.end();
while ( it != end )
{
if ( it.value() == cw )
break ;
}
Q_ASSERT( it != end );
qDebug() << "Deactivated ClipWorkflow";
it.value().deactivate();
//If this clip is the last, we emit the trackEndReached signal, and stop the
//clip workflow.
cw->stop();
//this obviously couldn't happen, since we have a clipworkflow...
Q_ASSERT ( m_clips.size() != 0 );
Q_ASSERT( m_clips.size() != 0 );
QMap<qint64, CW>::const_iterator it = m_clips.end() - 1;
QMap<qint64, CW>::const_iterator last = m_clips.end() - 1;
//If it ends before the current frame, we reached end.
if ( it.value() == cw )
if ( last.value() == cw )
emit trackEndReached( m_trackId );
}
......@@ -75,7 +75,7 @@ class TrackWorkflow : public QObject
void renderClip( ClipWorkflow* cw, qint64 currentFrame,
qint64 start, bool needRepositioning );
void preloadClip( ClipWorkflow* cw );
void stopClipWorkflow( ClipWorkflow* cw );
void stopClipWorkflow( CW& cw );
private:
unsigned int m_trackId;
......
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