Commit 06f52598 authored by Hugo Beauzee-Luyssen's avatar Hugo Beauzee-Luyssen

Independent clipworkflow works quite well for video :)

parent 1189fb7c
......@@ -59,6 +59,7 @@ public:
}
int count() const
{
QMutexLocker lock( m_mutex );
return m_pool.count();
}
......@@ -69,10 +70,12 @@ public:
}
bool isEmpty() const
{
QMutexLocker lock( m_mutex );
return m_pool.empty();
}
void push_back( const T& val )
{
QMutexLocker lock( m_mutex );
m_pool.push_back( val );
}
......
......@@ -55,8 +55,9 @@ void* AudioClipWorkflow::getUnlockCallback()
void* AudioClipWorkflow::getOutput( ClipWorkflow::GetMode mode )
{
QMutexLocker lock( m_renderLock );
preGetOutput();
qWarning() << "Audio. Available:" << m_availableBuffers.count() << "Computed:" << m_computedBuffers.count();
if ( isEndReached() == true )
{
qDebug() << "Audio end reached";
......@@ -135,3 +136,8 @@ uint32_t AudioClipWorkflow::getComputedBuffers() const
{
return m_computedBuffers.count();
}
uint32_t AudioClipWorkflow::getMaxComputedBuffers() const
{
return AudioClipWorkflow::nbBuffers;
}
......@@ -46,6 +46,7 @@ class AudioClipWorkflow : public ClipWorkflow
protected:
virtual uint32_t getAvailableBuffers() const;
virtual uint32_t getComputedBuffers() const;
virtual uint32_t getMaxComputedBuffers() const;
private:
QReadWriteLock* m_computedBuffersLock;
......
......@@ -192,12 +192,16 @@ LibVLCpp::MediaPlayer* ClipWorkflow::getMediaPlayer()
void ClipWorkflow::postGetOutput()
{
//If we have more empty buffers than computed ones, refill our stack.
if ( getComputedBuffers() > getAvailableBuffers() )
//If we're running out of computed buffers, refill our stack.
if ( getComputedBuffers() < getMaxComputedBuffers() / 3 )
{
//Assume the media player was paused in this case...
//FIXME: this is probably a very bad idea...
m_mediaPlayer->pause();
if ( m_mediaPlayer->isPlaying() == false )
{
qWarning() << "Unpausing media player";
m_mediaPlayer->pause();
}
else
qCritical() << "Running out of output buffers !";
}
}
......@@ -208,21 +212,28 @@ void ClipWorkflow::preGetOutput()
if ( getComputedBuffers() == 0 )
{
qWarning() << "Waiting for buffer to be fed";
m_renderLock->unlock();
m_feedingCondWait->waitLocked();
m_renderLock->lock();
}
}
void ClipWorkflow::commonUnlock()
{
if ( getAvailableBuffers() == 0 )
{
qDebug() << "No more available buffers : pausing";
m_mediaPlayer->pause();
}
if ( getComputedBuffers() == 1 )
{
qDebug() << "trying to inform of first buffer";
QMutexLocker lock( m_feedingCondWait->getMutex() );
qWarning() << "Just rendered the first buffer.";
m_feedingCondWait->wake();
}
checkStateChange();
qDebug() << "exited from common unlock";
}
void ClipWorkflow::computePtsDiff( qint64 pts )
......
......@@ -147,6 +147,7 @@ class ClipWorkflow : public QObject
void commonUnlock();
virtual uint32_t getAvailableBuffers() const = 0;
virtual uint32_t getComputedBuffers() const = 0;
virtual uint32_t getMaxComputedBuffers() const = 0;
private:
LibVLCpp::MediaPlayer* m_mediaPlayer;
......
......@@ -86,12 +86,10 @@ void* VideoClipWorkflow::getUnlockCallback()
void* VideoClipWorkflow::getOutput( ClipWorkflow::GetMode mode )
{
preGetOutput();
//Don't lock before preGetOutput() : it can eventually waits for the clipworkflow to render a frame
//which requires the renderLock to be unheld.
QMutexLocker lock( m_renderLock );
qWarning() << "poping buffer";
preGetOutput();
qWarning() << "Video. Available:" << m_availableBuffers.count() << "Computed:" << m_computedBuffers.count();
if ( isEndReached() == true )
return NULL;
StackedBuffer<LightVideoFrame*>* buff;
......@@ -106,10 +104,13 @@ void* VideoClipWorkflow::getOutput( ClipWorkflow::GetMode mode )
void VideoClipWorkflow::lock( VideoClipWorkflow* cw, void** pp_ret, int size )
{
Q_UNUSED( size );
qDebug() << "trying to lock renderlock";
cw->m_renderLock->lock();
qDebug() << "trying to pop available buffer";
LightVideoFrame* lvf = cw->m_availableBuffers.pop();
cw->m_computedBuffers.push_back( lvf );
qWarning() << "feeding video buffer";
qWarning() << ">>>VideoGeneration. Available:" << cw->m_availableBuffers.count() << "Computed:" << cw->m_computedBuffers.count();
// qWarning() << "feeding video buffer";
*pp_ret = (*(lvf))->frame.octets;
}
......@@ -122,11 +123,14 @@ void VideoClipWorkflow::unlock( VideoClipWorkflow* cw, void* buffer, int widt
Q_UNUSED( size );
cw->computePtsDiff( pts );
qDebug() << "getting computed buffers head";
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.
qDebug() << "calling commonUnlock";
cw->commonUnlock();
qDebug() << "unlocking render lock";
cw->m_renderLock->unlock();
}
uint32_t VideoClipWorkflow::getAvailableBuffers() const
......@@ -138,3 +142,8 @@ uint32_t VideoClipWorkflow::getComputedBuffers() const
{
return m_computedBuffers.count();
}
uint32_t VideoClipWorkflow::getMaxComputedBuffers() const
{
return VideoClipWorkflow::nbBuffers;
}
......@@ -43,7 +43,7 @@ class VideoClipWorkflow : public ClipWorkflow
virtual void initVlcOutput();
virtual uint32_t getAvailableBuffers() const;
virtual uint32_t getComputedBuffers() const;
virtual uint32_t getMaxComputedBuffers() const;
private:
// Pool<LightVideoFrame*> m_pool;
// QReadWriteLock* m_computedBuffersLock;
......
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