Commit 844eb31a authored by Hugo Beauzee-Luyssen's avatar Hugo Beauzee-Luyssen

Solved crash when moving after the current media

parent bcda39c4
......@@ -67,7 +67,7 @@ void ClipWorkflow::lock( ClipWorkflow* clipWorkflow, void** pp_ret )
//In any case, we give vlc a buffer to render in...
//If we don't, segmentation fault will catch us and eat our brain !! ahem...
// qDebug() << "Locking in ClipWorkflow::lock";
qDebug() << "Locking in ClipWorkflow::lock";
*pp_ret = clipWorkflow->m_buffer;
}
......@@ -75,8 +75,14 @@ void ClipWorkflow::unlock( ClipWorkflow* clipWorkflow )
{
if ( clipWorkflow->m_isReady == true )
{
QMutexLocker lock( clipWorkflow->m_condMutex );
{
QReadLocker lock( clipWorkflow->m_endReachedLock );
if ( clipWorkflow->m_endReached == true )
{
qDebug() << "UnLocking in ClipWorkflow::unlock";
return ;
}
}
{
QWriteLocker lock2( clipWorkflow->m_mutex );
clipWorkflow->m_renderComplete = true;
......@@ -87,9 +93,11 @@ void ClipWorkflow::unlock( ClipWorkflow* clipWorkflow )
QWriteLocker lock2( clipWorkflow->m_endReachedLock );
clipWorkflow->m_endReached = true;
}
QMutexLocker lock( clipWorkflow->m_condMutex );
clipWorkflow->m_waitCond->wait( clipWorkflow->m_condMutex );
}
// qDebug() << "UnLocking in ClipWorkflow::unlock";
qDebug() << "UnLocking in ClipWorkflow::unlock";
}
void ClipWorkflow::setRenderComplete()
......@@ -199,13 +207,14 @@ const Clip* ClipWorkflow::getClip() const
void ClipWorkflow::stop()
{
Q_ASSERT( m_mediaPlayer != NULL );
{
QWriteLocker lock2( m_mutex );
m_renderComplete = false;
}
{
QWriteLocker lock2( m_endReachedLock );
m_endReached = false;
m_endReached = true;
}
{
QWriteLocker lock( m_initMutex);
......@@ -213,10 +222,15 @@ void ClipWorkflow::stop()
}
m_mediaPlayer->stop();
m_mediaPlayer = NULL;
// qDebug() << "Stoped ClipWorkflow";
qDebug() << "Stoped ClipWorkflow";
}
void ClipWorkflow::setPosition( float pos )
{
m_mediaPlayer->setPosition( pos );
}
bool ClipWorkflow::isStopped() const
{
return ( m_mediaPlayer == NULL );
}
......@@ -62,6 +62,10 @@ class ClipWorkflow : public QObject
*/
void stop();
void setPosition( float pos );
/**
* \return true if the workflow has already been stopped.
*/
bool isStopped() const;
private:
static void lock( ClipWorkflow* clipWorkflow, void** pp_ret );
......
......@@ -34,11 +34,20 @@ TrackWorkflow::TrackWorkflow()
m_currentLock = new QReadWriteLock();
if ( TrackWorkflow::blackOutput == NULL )
{
//TODO: this ain't free !
TrackWorkflow::blackOutput = new unsigned char[VIDEOHEIGHT * VIDEOWIDTH * 3];
memset( TrackWorkflow::blackOutput, 0, VIDEOHEIGHT * VIDEOWIDTH * 3 );
}
}
TrackWorkflow::~TrackWorkflow()
{
delete m_condMutex;
delete m_waitCondition;
delete m_mediaPlayer;
delete m_currentLock;
}
void TrackWorkflow::addClip( Clip* clip, qint64 start )
{
qDebug() << "Inserting clip at frame nb" << start;
......@@ -141,23 +150,34 @@ unsigned char* TrackWorkflow::getOutput( qint64 currentFrame )
// qDebug() << "Stil no clip at this time, going to the next frame";
return ret;
}
m_waitCondition->wakeAll();
// qDebug() << "All waked";
while ( m_current.value()->renderComplete() == false )
usleep( 20 );
if ( m_current.value()->isEndReached() == false )
ret = m_current.value()->getOutput();
else
// qDebug() << "All waked"
if ( m_current.value()->isStopped() == false )
{
if ( clipsRemaining == false )
{
// qDebug() <<"End reached";
emit endReached();
}
m_waitCondition->wakeAll();
while ( m_current.value()->renderComplete() == false )
usleep( 20 );
if ( m_current.value()->isEndReached() == false )
ret = m_current.value()->getOutput();
return ret;
}
qDebug() << "End reached : stopping current clipworkflow";
stopCurrentClipWorkflow();
if ( clipsRemaining == false )
{
qDebug() <<"End reached";
emit endReached();
}
return ret;
}
void TrackWorkflow::stopCurrentClipWorkflow()
{
//Awaking renderer thread to avoid dead lock
if ( m_current.value()->isStopped() == false )
m_current.value()->stop();
}
void TrackWorkflow::setPosition( float pos )
{
qint64 frame = (float)m_length * pos;
......@@ -171,7 +191,7 @@ void TrackWorkflow::setPosition( float pos )
// qDebug() << "setting position after the end of this track";
if ( m_current != end )
{
m_current.value()->stop();
stopCurrentClipWorkflow();
m_current = end;
return ;
}
......@@ -183,7 +203,7 @@ void TrackWorkflow::setPosition( float pos )
if ( it.key() <= frame &&
( it.key() + it.value()->getClip()->getLength() ) > frame )
{
// qDebug() << "Found new current clip workflow";
qDebug() << "Found new current clip workflow";
break;
}
else if ( next == m_clips.end() && it.key() > frame )
......@@ -195,13 +215,13 @@ void TrackWorkflow::setPosition( float pos )
next = it;
if ( next != m_clips.begin() )
{
// qDebug() << "Next clip isn't the first one";
qDebug() << "Next clip isn't the first one";
next = next - 1; //Since the iterator must point to the previous video
}
else
{
next = end;
// qDebug() << "Next clip is the first of the track";
qDebug() << "Next clip is the first of the track";
}
// in order to checkNextClip() to work.
it = end;
......@@ -214,13 +234,13 @@ void TrackWorkflow::setPosition( float pos )
{
if ( m_current != end )
{
m_current.value()->stop();
stopCurrentClipWorkflow();
}
m_current = next;
}
else if ( it == m_current )
{
// qDebug() << "Changing the position of the current clip";
qDebug() << "Changing the position of the current clip";
//We're changing the position of the current clip
it.value()->setPosition( (float)( frame - it.key() ) / (float)(it.value()->getClip()->getLength()) );
//Awaking renderers to avoid them to be stuck inside of the lock...
......@@ -229,10 +249,10 @@ void TrackWorkflow::setPosition( float pos )
}
else
{
// qDebug() << "Switching to other Clip";
qDebug() << "Switching to other Clip";
if ( m_current != end )
{
m_current.value()->stop();
stopCurrentClipWorkflow();
// m_waitCondition->wakeAll();
}
......
......@@ -43,6 +43,7 @@ class TrackWorkflow : public QObject
public:
TrackWorkflow();
~TrackWorkflow();
void startRender();
unsigned char* getOutput( qint64 currentFrame );
......@@ -67,6 +68,7 @@ class TrackWorkflow : public QObject
*/
bool checkNextClip( qint64 currentFrame );
void computeLength();
void stopCurrentClipWorkflow();
private:
QMap<qint64, ClipWorkflow*> m_clips;
......
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