Commit 8509debd authored by Hugo Beauzee-Luyssen's avatar Hugo Beauzee-Luyssen

Improvements in output buffers

parent a082e08e
......@@ -85,11 +85,11 @@ void MediaPlayer::callbacks( const libvlc_event_t* ev
switch ( event->type )
{
case libvlc_MediaPlayerPlaying:
// qDebug() << "Media player playing";
qDebug() << "Media player playing";
self->emit playing();
break;
case libvlc_MediaPlayerPaused:
// qDebug() << "Media player paused";
qDebug() << "Media player paused";
self->emit paused();
break;
case libvlc_MediaPlayerStopped:
......
......@@ -30,7 +30,9 @@ ClipWorkflow::ClipWorkflow( Clip::Clip* clip ) :
m_clip( clip ),
m_mediaPlayer(NULL),
m_state( ClipWorkflow::Stopped ),
m_requiredState( ClipWorkflow::None )
m_requiredState( ClipWorkflow::None ),
m_rendering( false ),
m_initFlag( false )
{
for ( unsigned int i = 0; i < 5; ++i )
m_availableBuffers.enqueue( new unsigned char[VIDEOHEIGHT * VIDEOWIDTH * 4] );
......@@ -56,6 +58,8 @@ ClipWorkflow::~ClipWorkflow()
delete m_requiredStateLock;
delete m_stateLock;
while ( m_buffers.empty() == false )
delete[] m_buffers.dequeue();
while ( m_availableBuffers.empty() == false )
delete[] m_availableBuffers.dequeue();
}
......@@ -63,12 +67,18 @@ unsigned char* ClipWorkflow::getOutput()
{
QMutexLocker lock( m_buffersLock );
qDebug() << "Getting output";
if ( m_mediaPlayer->isPlaying() == false )
{
qDebug() << "Generating in same buffer as last time";
return m_buffers.head();
}
if ( m_buffers.isEmpty() == true )
return NULL;
unsigned char* buff = m_buffers.dequeue();
m_availableBuffers.enqueue( buff );
qDebug() << "Getting output. Buffers... Available:" << m_availableBuffers.size() << "Used:" << m_buffers.size();
return buff;
}
......@@ -86,9 +96,19 @@ void ClipWorkflow::checkStateChange()
void ClipWorkflow::lock( ClipWorkflow* cw, void** pp_ret )
{
qDebug() << "Computing new frame";
qDebug() << "Buffers... Available:" << cw->m_availableBuffers.size() << "Used:" << cw->m_buffers.size();
cw->m_buffersLock->lock();
unsigned char* buff;
if ( cw->m_mediaPlayer->isPlaying() == false )
{
if ( cw->m_buffers.size() > 0 )
*pp_ret = cw->m_buffers.last();
else
*pp_ret = cw->m_availableBuffers.head();
qDebug() << "Using same buffer than last time";
return ;
}
qDebug() << "New frame";
if ( cw->m_availableBuffers.size() > 0 )
buff = cw->m_availableBuffers.dequeue();
else
......@@ -255,6 +275,8 @@ void ClipWorkflow::stop()
QMutexLocker lock( m_requiredStateLock );
m_requiredState = ClipWorkflow::None;
delete m_vlcMedia;
m_initFlag = false;
m_rendering = false;
}
else
qDebug() << "ClipWorkflow has already been stopped";
......
......@@ -201,6 +201,18 @@ class ClipWorkflow : public QObject
WaitCondition* m_pausingStateWaitCond;
WaitCondition* m_pausedThreadCondWait;
/**
* While this flag is set to false, we will use the same buffer, to prevent
* having X buffers with the same picture (when media player is paused mainly)
*/
bool m_rendering;
/**
* This flag is here to avoid multiple connection to the mediaPlayer* slots.
* It's essentially a nasty hack due to the multiples calls to lock/unlock when
* the render is started, and that cannot really be avoided...
*/
bool m_initFlag;
private slots:
void pauseAfterPlaybackStarted();
void initializedMediaPlayer();
......
......@@ -178,6 +178,7 @@ void TrackWorkflow::preloadClip( ClipWorkflow* cw )
if ( cw->getState() == ClipWorkflow::Stopped )
{
qDebug() << "Preloading clip";
cw->getStateLock()->unlock();
cw->initialize();
return ;
......
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