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

Factorized Video/Audio Clipworkflow::unlock code

parent 6fb8ea58
......@@ -102,9 +102,13 @@ void AudioClipWorkflow::unlock( AudioClipWorkflow* cw, uint8_t* pcm_buffe
Q_UNUSED( size );
static qint64 previous_pts = pts;
static qint64 current_pts = pts;
//Q_UNUSED( pts );
cw->m_renderLock->unlock();
cw->m_stateLock->lockForWrite();
previous_pts = current_pts;
current_pts = pts;
current_pts = qMax( current_pts, previous_pts );
if ( cw->m_buffer->buff != NULL )
{
......@@ -113,34 +117,5 @@ void AudioClipWorkflow::unlock( AudioClipWorkflow* cw, uint8_t* pcm_buffe
cw->m_buffer->ptsDiff = current_pts - previous_pts;
}
current_pts = qMax( current_pts, previous_pts );
cw->m_renderLock->unlock();
cw->m_stateLock->lockForWrite();
if ( cw->m_state == Rendering )
{
QMutexLocker lock( cw->m_condMutex );
cw->m_state = Sleeping;
cw->m_stateLock->unlock();
{
QMutexLocker lock2( cw->m_renderWaitCond->getMutex() );
cw->m_renderWaitCond->wake();
}
cw->emit renderComplete( cw );
// qDebug() << "Emmiting render completed";
// qDebug() << "Entering cond wait";
cw->m_waitCond->wait( cw->m_condMutex );
// qDebug() << "Leaving condwait";
cw->m_stateLock->lockForWrite();
if ( cw->m_state == Sleeping )
cw->m_state = Rendering;
cw->m_stateLock->unlock();
}
else
cw->m_stateLock->unlock();
// qDebug() << '[' << (void*)cw << "] ClipWorkflow::unlock";
cw->checkStateChange();
cw->commonUnlock();
}
......@@ -326,3 +326,34 @@ WaitCondition* ClipWorkflow::getRenderCondWait()
{
return m_renderWaitCond;
}
void ClipWorkflow::commonUnlock()
{
if ( m_state == Rendering )
{
QMutexLocker lock( m_condMutex );
m_state = Sleeping;
m_stateLock->unlock();
{
QMutexLocker lock2( m_renderWaitCond->getMutex() );
m_renderWaitCond->wake();
}
emit renderComplete( this );
// qDebug() << "Emmiting render completed";
// qDebug() << "Entering cond wait";
m_waitCond->wait( m_condMutex );
// qDebug() << "Leaving condwait";
m_stateLock->lockForWrite();
if ( m_state == Sleeping )
m_state = Rendering;
m_stateLock->unlock();
}
else
m_stateLock->unlock();
// qDebug() << '[' << (void*)this << "] ClipWorkflow::unlock";
checkStateChange();
}
......@@ -163,6 +163,9 @@ class ClipWorkflow : public QObject
void checkSynchronisation( State newState );
void adjustBegin();
protected:
void commonUnlock();
private:
LibVLCpp::MediaPlayer* m_mediaPlayer;
......
......@@ -102,40 +102,15 @@ void VideoClipWorkflow::unlock( VideoClipWorkflow* cw, void* buffer, int widt
Q_UNUSED( size );
static qint64 previous_pts = pts;
static qint64 current_pts = pts;
cw->m_renderLock->unlock();
cw->m_stateLock->lockForWrite();
previous_pts = current_pts;
current_pts = pts;
current_pts = qMax( current_pts, previous_pts );
if ( cw->m_state == Rendering )
{
QMutexLocker lock( cw->m_condMutex );
(*(cw->m_buffer))->ptsDiff = current_pts - previous_pts;
cw->m_state = Sleeping;
cw->m_stateLock->unlock();
{
QMutexLocker lock2( cw->m_renderWaitCond->getMutex() );
cw->m_renderWaitCond->wake();
}
cw->emit renderComplete( cw );
// qDebug() << "Emmiting render completed";
(*(cw->m_buffer))->ptsDiff = current_pts - previous_pts;
// qDebug() << "Entering cond wait";
cw->m_waitCond->wait( cw->m_condMutex );
// qDebug() << "Leaving condwait";
cw->m_stateLock->lockForWrite();
if ( cw->m_state == Sleeping )
cw->m_state = Rendering;
cw->m_stateLock->unlock();
}
else
cw->m_stateLock->unlock();
current_pts = qMax( current_pts, previous_pts );
// qDebug() << '[' << (void*)cw << "] ClipWorkflow::unlock";
cw->checkStateChange();
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