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

Tracks workflow can now handle more than one video in time

However, they must NOT be simultaneous (for now !)
parent d51cc7a9
......@@ -125,11 +125,13 @@ void ClipWorkflow::initialize( LibVLCpp::MediaPlayer* mediaPlayer )
m_mediaPlayer->setMedia( m_clip->getParent()->getVLCMedia() );
connect( m_mediaPlayer, SIGNAL( playing() ), this, SLOT( setPosition() ), Qt::DirectConnection );
qDebug() << "Launching playback";
m_mediaPlayer->play();
}
void ClipWorkflow::setPosition()
{
qDebug() << "Setting position";
disconnect( m_mediaPlayer, SIGNAL( playing() ), this, SLOT( setPosition() ) );
connect( m_mediaPlayer, SIGNAL( positionChanged() ), this, SLOT( pauseAfterPlaybackStarted() ), Qt::DirectConnection );
m_mediaPlayer->setPosition( m_clip->getBegin() );
......@@ -141,6 +143,7 @@ void ClipWorkflow::pauseAfterPlaybackStarted()
disconnect( m_mediaPlayer, SIGNAL( playing() ), this, SLOT( pauseAfterPlaybackStarted() ) );
connect( m_mediaPlayer, SIGNAL( paused() ), this, SLOT( pausedMediaPlayer() ), Qt::DirectConnection );
qDebug() << "pausing media";
m_mediaPlayer->pause();
}
......
......@@ -38,11 +38,12 @@ class MainWorkflow : public QObject
public:
MainWorkflow();
void addClip( Clip* clip, unsigned int trackId, qint64 start );
void startRender();
unsigned char* getOutput();
void addClip( Clip* clip, unsigned int trackId, qint64 start );
void startRender();
unsigned char* getOutput();
private:
TrackWorkflow** m_tracks;
TrackWorkflow** m_tracks;
};
#endif // MAINWORKFLOW_H
......@@ -24,31 +24,101 @@
#include "TrackWorkflow.h"
TrackWorkflow::TrackWorkflow() : m_currentFrame( 0 )
unsigned char* TrackWorkflow::blackOutput = NULL;
TrackWorkflow::TrackWorkflow() : m_currentFrame( 0 ), m_isRendering( false )
{
m_condMutex = new QMutex;
m_waitCondition = new QWaitCondition;
m_mediaPlayer = new LibVLCpp::MediaPlayer();
if ( TrackWorkflow::blackOutput == NULL )
{
TrackWorkflow::blackOutput = new unsigned char[VIDEOHEIGHT * VIDEOWIDTH * 3];
memset( TrackWorkflow::blackOutput, 0, VIDEOHEIGHT * VIDEOWIDTH * 3 );
}
}
void TrackWorkflow::addClip( Clip* clip, qint64 start )
{
qDebug() << "Inserting clip at frame nb" << start;
ClipWorkflow* cw = new ClipWorkflow( clip, m_condMutex, m_waitCondition );
m_clips.insert( start, cw );
}
void TrackWorkflow::startRender()
{
m_currentFrame = 0;
m_current = m_clips.end();
//If the first frame is to be render soon, we should play it now.
if ( m_clips.begin().key() < TrackWorkflow::nbFrameBeforePreload )
{
qDebug() << "Next clip is less than" << nbFrameBeforePreload<< "frame ahead";
m_clips.begin().value()->initialize( m_mediaPlayer );
qDebug() << "Waiting for the first clip to be ready";
while ( m_clips.begin().value()->isReady() == false )
usleep( 150 );
if ( m_current.key() == 0 )
{
m_current = m_clips.begin();
qDebug() << "Clip workflow is at first frame";
m_current.value()->startRender();
m_isRendering = true;
}
}
}
void TrackWorkflow::checkNextClip()
{
QMap<qint64, ClipWorkflow*>::iterator next;
//Picking next clip :
if ( m_current == m_clips.end() )
{
// qDebug() << "Using first clip";
next = m_clips.begin();
}
else
{
// qDebug() << "Using next clip";
next = m_clips.begin() + 1;
}
//If it's about to be used, initialize it
if ( next.key() == m_currentFrame + TrackWorkflow::nbFrameBeforePreload )
{
qDebug() << "Initializing next clipWorkflow";
next.value()->initialize( m_mediaPlayer );
}
else if ( next.key() == m_currentFrame )
{
//It should have been initialized now, however, this ain't very safe :/
Q_ASSERT( next.value()->isReady() );
qDebug() << "Switching current clip workflow";
//Using it as the current clip from now on.
m_current = next;
m_current.value()->startRender();
}
}
unsigned char* TrackWorkflow::getOutput()
unsigned char* TrackWorkflow::getOutput()
{
unsigned char* ret = TrackWorkflow::blackOutput;
qDebug() << "Frame nb" << m_currentFrame;
checkNextClip();
if ( m_current == m_clips.end() )
{
// qDebug() << "Stil no clip at this time, going to the next frame";
++m_currentFrame;
return ret;
}
m_waitCondition->wakeAll();
//Getting all the current frame output.
qDebug() << "All waked";
while ( m_current.value()->renderComplete() == false )
usleep( 20 );
if ( m_current.value()->isEndReached() == false )
ret = m_current.value()->getOutput();
++m_currentFrame;
//Check if end of clip workflow is reached => return NULL
//else return the current track output
return NULL;
return ret;
}
......@@ -40,8 +40,15 @@ class TrackWorkflow : public QObject
public:
TrackWorkflow();
void startRender();
unsigned char* getOutput();
void startRender();
unsigned char* getOutput();
//FIXME: this won't be reliable as soon as we change the fps from the configuration
static const unsigned int nbFrameBeforePreload = 60; //We load aproximatively 2s before the frame has to render.
static unsigned char* blackOutput;
private:
void checkNextClip();
private:
QMap<qint64, ClipWorkflow*> m_clips;
QMap<qint64, ClipWorkflow*>::iterator m_current;
......@@ -49,8 +56,7 @@ class TrackWorkflow : public QObject
QMutex* m_condMutex;
QWaitCondition* m_waitCondition;
LibVLCpp::MediaPlayer* m_mediaPlayer;
//When a video is about to be used, we pre-load it with this second media player.
LibVLCpp::MediaPlayer* m_nextMediaPlayer;
bool m_isRendering;
public:
void addClip( Clip*, qint64 start );
......
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