Commit 10b904b2 authored by Hugo Beauzee-Luyssen's avatar Hugo Beauzee-Luyssen

Avoiding wasting time and ressource when initializing a clip.

When loading a clip, media player was launched in play state, then paused, then unpaused.
Not it's just launched in a play state.
Preloading still use this method, as it's not supposed to play before we explicitly ask for it.
parent 01addde3
......@@ -155,7 +155,7 @@ void ClipWorkflow::setVmem()
//m_vlcMedia->addOption( buffer );
}
void ClipWorkflow::initialize()
void ClipWorkflow::initialize( bool preloading /*= false*/ )
{
setState( Initializing );
m_vlcMedia = new LibVLCpp::Media( "file://" + m_clip->getParent()->getFileInfo()->absoluteFilePath() );
......@@ -163,29 +163,28 @@ void ClipWorkflow::initialize()
m_mediaPlayer = Pool<LibVLCpp::MediaPlayer>::getInstance()->get();
m_mediaPlayer->setMedia( m_vlcMedia );
connect( m_mediaPlayer, SIGNAL( playing() ), this, SLOT( pauseAfterPlaybackStarted() ), Qt::DirectConnection );
if ( preloading == true )
connect( m_mediaPlayer, SIGNAL( playing() ), this, SLOT( pauseAfterPlaybackStarted() ), Qt::DirectConnection );
else
connect( m_mediaPlayer, SIGNAL( playing() ), this, SLOT( loadingComplete() ), Qt::DirectConnection );
connect( m_mediaPlayer, SIGNAL( endReached() ), this, SLOT( clipEndReached() ), Qt::DirectConnection );
m_mediaPlayer->play();
}
//FIXME: this step is probably useless, due to modification in the TrackWorkflow
//void ClipWorkflow::setPositionAfterPlayback()
//{
// disconnect( m_mediaPlayer, SIGNAL( playing() ), this, SLOT( setPositionAfterPlayback() ) );
// connect( m_mediaPlayer, SIGNAL( timeChanged() ), this, SLOT( pauseAfterPlaybackStarted() ), Qt::DirectConnection );
//
// m_mediaPlayer->setTime( m_clip->getBegin() );
//}
void ClipWorkflow::pauseAfterPlaybackStarted()
{
// disconnect( m_mediaPlayer, SIGNAL( timeChanged() ), this, SLOT( pauseAfterPlaybackStarted() ) );
disconnect( m_mediaPlayer, SIGNAL( playing() ), this, SLOT( pauseAfterPlaybackStarted() ) );
connect( m_mediaPlayer, SIGNAL( paused() ), this, SLOT( initializedMediaPlayer() ), Qt::DirectConnection );
m_mediaPlayer->pause();
}
void ClipWorkflow::loadingComplete()
{
disconnect( m_mediaPlayer, SIGNAL( playing() ), this, SLOT( loadingComplete() ) );
setState( Ready );
}
void ClipWorkflow::initializedMediaPlayer()
{
disconnect( m_mediaPlayer, SIGNAL( paused() ), this, SLOT( initializedMediaPlayer() ) );
......
......@@ -66,7 +66,7 @@ class ClipWorkflow : public QObject
* of the rendering process advancement.
*/
unsigned char* getOutput();
void initialize();
void initialize( bool preloading = false );
/**
* Return true ONLY if the state is equal to Ready.
* If the state is Rendering, EndReached or anything else, this will
......@@ -208,9 +208,15 @@ class ClipWorkflow : public QObject
bool m_fullSpeedRender;
private slots:
/**
* \brief This slot is used when preloading, to pause the mediaplayer once fully loaded.
*/
void pauseAfterPlaybackStarted();
/**
* \brief When preloading, this slot is used to mark that the media player has been paused again.
*/
void initializedMediaPlayer();
// void setPositionAfterPlayback();
void loadingComplete();
void pausedMediaPlayer();
void unpausedMediaPlayer();
......
......@@ -142,13 +142,9 @@ void TrackWorkflow::renderClip( ClipWorkflow* cw, qint64 currentFrame,
}
else if ( cw->getState() == ClipWorkflow::Stopped )
{
// qDebug() << "Unlocking state lock";
cw->getStateLock()->unlock();
// qDebug() << "Initializing";
cw->initialize();
// qDebug() << "Calling start render";
cw->startRender( m_paused );
// qDebug() << "Start render done !";
if ( start != currentFrame ) //Clip was not started as its real begining
{
adjustClipTime( currentFrame, start, cw );
......@@ -197,7 +193,7 @@ void TrackWorkflow::preloadClip( ClipWorkflow* cw )
if ( cw->getState() == ClipWorkflow::Stopped )
{
cw->getStateLock()->unlock();
cw->initialize();
cw->initialize( true );
return ;
}
cw->getStateLock()->unlock();
......@@ -290,7 +286,7 @@ bool TrackWorkflow::getOutput( qint64 currentFrame )
if ( checkEnd( currentFrame ) == true )
{
emit trackEndReached( m_trackId );
//We continue, as there can be ClipWorkflow that required to be stopped.
//We continue, as there can be ClipWorkflow that requires to be stopped.
}
{
QMutexLocker lock( m_forceRepositionningMutex );
......
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