Commit 373d7a68 authored by Hugo Beauzee-Luyssen's avatar Hugo Beauzee-Luyssen

More work on next frame process, though it kinda crash/don't work/warps...

parent 72a5bf84
......@@ -84,7 +84,6 @@ void MediaPlayer::callbacks( const libvlc_event_t* ev
MediaPlayer* self = reinterpret_cast<MediaPlayer*>( ptr );
switch ( event->type )
{
qDebug() << "Event received" << event->type;
case libvlc_MediaPlayerPlaying:
qDebug() << "Media player playing";
self->emit playing();
......
......@@ -43,6 +43,7 @@ ClipWorkflow::ClipWorkflow( Clip::Clip* clip ) :
m_initWaitCond = new WaitCondition;
m_renderWaitCond = new WaitCondition;
m_pausingStateWaitCond = new WaitCondition;
m_pausedThreadCondWait = new WaitCondition;
// m_backBufferLock = new QReadWriteLock;
}
......@@ -50,6 +51,7 @@ ClipWorkflow::~ClipWorkflow()
{
// delete[] m_backBuffer;
// delete m_backBufferLock;
delete m_pausedThreadCondWait;
delete m_pausingStateWaitCond;
delete m_initWaitCond;
delete m_condMutex;
......@@ -73,7 +75,7 @@ void ClipWorkflow::checkStateChange()
QWriteLocker lock2( m_stateLock );
if ( m_requiredState != ClipWorkflow::None )
{
// qDebug() << "Changed state from" << m_state << "to state" << m_requiredState;
qDebug() << "Changed state from" << m_state << "to state" << m_requiredState;
m_state = m_requiredState;
m_requiredState = ClipWorkflow::None;
checkSynchronisation( m_state );
......@@ -91,12 +93,13 @@ void ClipWorkflow::lock( ClipWorkflow* cw, void** pp_ret )
// else
// {
*pp_ret = cw->m_buffer;
// qDebug() << "Clip workflow locking <<<<<<<<<<<<<<<<<<<<<<<<<<";
qDebug() << "Clip workflow locking <<<<<<<<<<<<<<<<<<<<<<<<<<";
// }
}
void ClipWorkflow::unlock( ClipWorkflow* cw )
{
qDebug() << "ClipWorkflow::unlock()";
cw->m_stateLock->lockForWrite();
// if ( cw->m_oneFrameOnly )
......@@ -116,10 +119,10 @@ void ClipWorkflow::unlock( ClipWorkflow* cw )
cw->m_stateLock->unlock();
//Signal that render has been completed.
cw->m_renderWaitCond->wake();
qDebug() << "Render completed";
qDebug() << "Clip render completed";
cw->emit renderComplete( cw );
qDebug() << "Entering condwait";
// qDebug() << "Entering condwait";
cw->m_waitCond->wait( cw->m_condMutex );
// qDebug() << "Leaved condwait";
cw->m_stateLock->lockForWrite();
......@@ -132,11 +135,19 @@ void ClipWorkflow::unlock( ClipWorkflow* cw )
}
else if ( cw->m_state == Paused )
{
QMutexLocker lock( cw->m_condMutex );
cw->m_stateLock->unlock();
qDebug() << "Entering forced pause condwait";
cw->setState( ClipWorkflow::ThreadPaused );
cw->m_pausedThreadCondWait->wake();
cw->m_waitCond->wait( cw->m_condMutex );
qDebug() << "Leaving forced pause condwait";
cw->setState( ClipWorkflow::Paused );
}
else
cw->m_stateLock->unlock();
qDebug() << "End of the ClipWorkflow::unlock()";
cw->checkStateChange();
}
......@@ -209,6 +220,12 @@ bool ClipWorkflow::isPausing() const
return m_state == ClipWorkflow::Pausing;
}
bool ClipWorkflow::isThreadPaused() const
{
QReadLocker lock( m_stateLock );
return m_state == ClipWorkflow::ThreadPaused;
}
bool ClipWorkflow::isEndReached() const
{
QReadLocker lock( m_stateLock );
......@@ -337,7 +354,10 @@ void ClipWorkflow::unpause( bool wakeRenderThread /*= true*/ )
// QMutexLocker lock( m_requiredStateLock );
// m_requiredState = ClipWorkflow::None;
if ( wakeRenderThread == true )
{
qDebug() << "Unpausing and waking thread";
wake();
}
}
//void ClipWorkflow::activateOneFrameOnly()
......@@ -346,10 +366,12 @@ void ClipWorkflow::unpause( bool wakeRenderThread /*= true*/ )
// m_oneFrameOnly = 1;
//}
void ClipWorkflow::waitForCompleteRender()
void ClipWorkflow::waitForCompleteRender( bool dontCheckRenderStarted /*= false*/ )
{
if ( isRendering() == true )
if ( isRendering() == true || dontCheckRenderStarted == true )
m_renderWaitCond->wait();
else
qDebug() << "waitForCompleteRender(), not rendering. State == " << getState();
}
void ClipWorkflow::waitForCompleteInit()
......@@ -364,6 +386,12 @@ void ClipWorkflow::waitForPausingState()
m_pausingStateWaitCond->wait();
}
void ClipWorkflow::waitForPausedThread()
{
if ( isThreadPaused() == false )
m_pausedThreadCondWait->wait();
}
QMutex* ClipWorkflow::getSleepMutex()
{
return m_condMutex;
......
......@@ -52,8 +52,9 @@ class ClipWorkflow : public QObject
Sleeping, //4
Pausing, //5
Paused, //6
Stopping, //7
EndReached, //8
ThreadPaused, //7
Stopping, //8
EndReached, //9
};
int debugId;
......@@ -93,6 +94,8 @@ class ClipWorkflow : public QObject
bool isPausing() const;
bool isThreadPaused() const;
/**
* Returns the current workflow state.
* Be carrefull, as this function is NOT thread safe, and return the
......@@ -150,8 +153,9 @@ class ClipWorkflow : public QObject
void unpause( bool wakeRenderThread = true );
void waitForCompleteInit();
void waitForCompleteRender();
void waitForCompleteRender( bool dontCheckRenderStarted = false );
void waitForPausingState();
void waitForPausedThread();
QMutex* getSleepMutex();
LibVLCpp::MediaPlayer* getMediaPlayer();
......@@ -205,6 +209,7 @@ class ClipWorkflow : public QObject
WaitCondition* m_initWaitCond;
WaitCondition* m_renderWaitCond;
WaitCondition* m_pausingStateWaitCond;
WaitCondition* m_pausedThreadCondWait;
private slots:
void pauseAfterPlaybackStarted();
......
......@@ -134,14 +134,10 @@ unsigned char* MainWorkflow::getOutput()
if ( ret == NULL )
ret = MainWorkflow::blackOutput;
nextFrame();
qDebug() << "Getoutput complete";
return ret;
}
else
{
qDebug() << "Getoutput empty";
return MainWorkflow::blackOutput;
}
}
void MainWorkflow::pause()
......@@ -161,6 +157,7 @@ void MainWorkflow::pause()
void MainWorkflow::nextFrame()
{
qDebug() << "Going to the next frame";
++m_currentFrame;
//FIXME: This is probably a bit much...
emit frameChanged( m_currentFrame );
......@@ -169,6 +166,7 @@ void MainWorkflow::nextFrame()
void MainWorkflow::previousFrame()
{
qDebug() << "Going to the previous frame";
--m_currentFrame;
//FIXME: This is probably a bit much...
emit frameChanged( m_currentFrame );
......@@ -266,7 +264,7 @@ void MainWorkflow::clipMoved( QUuid clipUuid, int oldTrack, int newTra
void MainWorkflow::activateOneFrameOnly()
{
for (unsigned int i = 0; i < m_trackCount; ++i)
for (unsigned int i = 0; i < m_trackCount; ++i)
{
//FIXME: After debugging period, this should'nt be necessary --
if ( m_tracks[i].activated() == true )
......@@ -277,8 +275,9 @@ void MainWorkflow::activateOneFrameOnly()
void MainWorkflow::trackPaused()
{
m_nbTracksToPause.fetchAndAddAcquire( -1 );
if ( m_nbTracksToPause == 0 )
if ( m_nbTracksToPause <= 0 )
{
qDebug() << "MainWorkflow is paused";
emit mainWorkflowPaused();
}
}
......@@ -299,15 +298,16 @@ void MainWorkflow::tracksRenderCompleted( unsigned int trackId )
//therefore, m_nbTracksToRender will be equal to -1
if ( m_nbTracksToRender <= 0 )
{
qDebug() << "MainWorkflow render completed";
qDebug() << "MainWorkflow render is completed. Acquiring synchronization lock";
//Just a synchronisation barriere
{
QMutexLocker lock( m_synchroneRenderWaitConditionMutex );
}
qDebug() << "Waking synchronisation threads";
m_synchroneRenderWaitCondition->wakeAll();
}
else
qDebug() << m_nbTracksToRender << "tracks left to render";
// else
// qDebug() << m_nbTracksToRender << "tracks left to render";
}
unsigned char* MainWorkflow::getSynchroneOutput()
......
......@@ -83,6 +83,7 @@ class MainWorkflow : public QObject, public Singleton<MainWorkflow>
private:
static MainWorkflow* m_instance;
// QAtomicInt m_oneFrameOnly;
private:
void computeLength();
......
......@@ -90,7 +90,7 @@ unsigned char* TrackWorkflow::renderClip( ClipWorkflow* cw, qint64 currentF
cw->getStateLock()->lockForRead();
// qDebug() << "Rendering clip";
qDebug() << "Rendering clip";
if ( cw->getState() == ClipWorkflow::Paused && pauseAfterRender == false )
{
cw->getStateLock()->unlock();
......@@ -102,7 +102,7 @@ unsigned char* TrackWorkflow::renderClip( ClipWorkflow* cw, qint64 currentF
}
if ( cw->getState() == ClipWorkflow::Rendering )
{
qDebug() << "Rendering a 'Rendering' ClipWorkflow";
// qDebug() << "Rendering a 'Rendering' ClipWorkflow";
//The rendering state meens... whell it means that the frame is
//beeing rendered, so we wait.
cw->getStateLock()->unlock();
......@@ -116,7 +116,9 @@ unsigned char* TrackWorkflow::renderClip( ClipWorkflow* cw, qint64 currentF
//If frame has been rendered :
if ( cw->getState() == ClipWorkflow::Sleeping || pauseAfterRender == true )
{
qDebug() << "renderign a sleeping clip worjkflow";
// qDebug() << "rendering a sleeping clip workflow";
if ( pauseAfterRender == true )
qDebug() << "Rendering only one frame";
cw->getStateLock()->unlock();
if ( needRepositioning == true )
......@@ -125,16 +127,26 @@ unsigned char* TrackWorkflow::renderClip( ClipWorkflow* cw, qint64 currentF
cw->setPosition( pos );
}
ret = cw->getOutput();
if ( pauseAfterRender == true )
if ( pauseAfterRender == false )
{
cw->unpause( false );
// qDebug() << "Querying state back to pause after render";
cw->queryStateChange( ClipWorkflow::Paused );
QMutexLocker lock( cw->getSleepMutex() );
cw->wake();
}
else
{
QMutexLocker lock( cw->getSleepMutex() );
cw->queryStateChange( ClipWorkflow::Rendering );
// cw->unpause( true );
cw->getMediaPlayer()->pause();
cw->wake();
qDebug() << "Waiting for render now...";
cw->waitForCompleteRender( true );
{
QMutexLocker lock( cw->getSleepMutex() );
}
qDebug() << "Querying state back to pause after render";
cw->queryStateChange( ClipWorkflow::Paused );
cw->wake();
}
cw->wake();
}
else if ( cw->getState() == ClipWorkflow::Stopped )
{
......@@ -267,7 +279,6 @@ void TrackWorkflow::stop()
unsigned char* TrackWorkflow::getOutput( qint64 currentFrame )
{
qDebug() << "Getting track output";
QReadLocker lock( m_clipsLock );
unsigned char* ret = NULL;
......@@ -278,7 +289,10 @@ unsigned char* TrackWorkflow::getOutput( qint64 currentFrame )
bool oneFrameOnlyFlag = false;
if ( m_oneFrameOnly == 1 )
{
qDebug() << "Activating oneFrameOnlyFlag";
oneFrameOnlyFlag = true;
}
if ( checkEnd( currentFrame ) == true )
{
emit trackEndReached( m_trackId );
......@@ -330,14 +344,7 @@ unsigned char* TrackWorkflow::getOutput( qint64 currentFrame )
m_oneFrameOnly = 0;
}
if ( ret == NULL )
{
qDebug() << "No output";
clipWorkflowRenderCompleted( NULL );
}
else
{
qDebug() << "Got output";
}
return ret;
}
......@@ -381,6 +388,9 @@ void TrackWorkflow::pauseClipWorkflow( ClipWorkflow* cw )
}
cw->waitForPausingState();
cw->pause();
qDebug() << "Wait for pausedthread state";
cw->waitForPausedThread();
qDebug() << "Ok thread is paused";
}
void TrackWorkflow::pause()
......@@ -493,15 +503,9 @@ void TrackWorkflow::clipWorkflowRenderCompleted( ClipWorkflow* cw )
//When there is nothing to render, m_nbClipToRender will be equal to one here, so we check for minus
//or equal to 0
if ( m_nbClipToRender <= 0 )
{
qDebug() << "TrackWorkflow render is completed. Buffer =" << (void*)m_synchroneRenderBuffer;
emit renderCompleted( m_trackId );
}
else
{
qDebug() << "Trackworfklow render isn't complete yet." << m_nbClipToRender << "cw remaining";
}
qDebug() << "End of method";
// else
// qDebug() << "Trackworfklow render isn't complete yet." << m_nbClipToRender << "cw remaining";
}
unsigned char* TrackWorkflow::getSynchroneOutput()
......
......@@ -84,7 +84,6 @@ WorkflowRenderer::~WorkflowRenderer()
void* WorkflowRenderer::lock( void* datas )
{
qDebug() << "WorkflowRenderer::lock()";
WorkflowRenderer* self = reinterpret_cast<WorkflowRenderer*>( datas );
//If we're not playing, then where in a paused media player.
......@@ -95,7 +94,14 @@ void* WorkflowRenderer::lock( void* datas )
}
if ( self->m_oneFrameOnly < 2 )
{
void* ret = self->m_mainWorkflow->getSynchroneOutput();
void* ret;
// if ( self->m_oneFrameOnly == 0 )
// ret = self->m_mainWorkflow->getOutput();
// else
// {
// qDebug() << "Asking synchrone frame";
ret = self->m_mainWorkflow->getSynchroneOutput();
// }
self->m_lastFrame = static_cast<unsigned char*>( ret );
qDebug() << "Returning new frame";
return ret;
......@@ -109,11 +115,11 @@ void* WorkflowRenderer::lock( void* datas )
void WorkflowRenderer::unlock( void* datas )
{
qDebug() << __func__;
WorkflowRenderer* self = reinterpret_cast<WorkflowRenderer*>( datas );
if ( self->m_oneFrameOnly == 1 )
{
self->m_mediaPlayer->pause();
qDebug() << "Pausing back";
self->togglePlayPause( true );
qDebug() << "Switching m_oneFrameOnly flag to 2";
self->m_oneFrameOnly = 2;
}
......@@ -174,19 +180,45 @@ void WorkflowRenderer::setPosition( float newPos )
m_mainWorkflow->setPosition( newPos );
}
void WorkflowRenderer::nextFrame()
void WorkflowRenderer::frameByFrameAfterPaused()
{
// qDebug() << "Next frame :";
qDebug() << "<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<";
qDebug() << "Activatin one frame only";
m_oneFrameOnly = 1;
m_mainWorkflow->nextFrame();
// qDebug() << "Activatign one frame only";
m_mainWorkflow->activateOneFrameOnly();
//Both media players should be stopped now... restauring playback
// m_framePlayed = 0;
m_mediaPlayer->pause();
// while ( m_framePlayed == 0 )
// SleepMS( 1 );
// m_mediaPlayer->pause();
// m_mainWorkflow->nextFrame();
qDebug() << "Unpausing everything";
togglePlayPause( false );
}
void WorkflowRenderer::frameByFramePausingProxy()
{
static unsigned int nbPaused = 0;
++nbPaused;
if ( nbPaused == 2 )
{
nbPaused = 0;
frameByFrameAfterPaused();
}
}
void WorkflowRenderer::nextFrame()
{
qDebug() << "<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<";
if ( m_pausedMediaPlayer == true )
{
qDebug() << "Already paused media player";
frameByFrameAfterPaused();
}
else
{
qDebug() << "Waiting for paused media player";
connect( m_mediaPlayer, SIGNAL( paused() ), this, SLOT( frameByFramePausingProxy() ), Qt::QueuedConnection );
connect( m_mainWorkflow, SIGNAL( mainWorkflowPaused() ), this, SLOT( frameByFramePausingProxy() ), Qt::QueuedConnection );
togglePlayPause( true );
}
}
void WorkflowRenderer::previousFrame()
......@@ -196,10 +228,8 @@ void WorkflowRenderer::previousFrame()
void WorkflowRenderer::pauseMainWorkflow()
{
qDebug() << "Pausing main workflow, setting m_pausedMediaPlayer to true... ?";
if ( m_paused == true )
return ;
qDebug() << "Indeed. Setting m_pausedMediaPlayer to true";
m_pausedMediaPlayer = true;
m_mainWorkflow->pause();
}
......@@ -274,7 +304,6 @@ void WorkflowRenderer::__videoPaused()
void WorkflowRenderer::__videoPlaying()
{
emit playing();
qDebug() << "Setting m_pausedMediaPlayer to false";
m_pausedMediaPlayer = false;
m_paused = false;
}
......
......@@ -66,6 +66,7 @@ class WorkflowRenderer : public GenericRenderer
void pauseMainWorkflow();
virtual void startPreview();
void checkActions();
void frameByFrameAfterPaused();
private:
MainWorkflow* m_mainWorkflow;
......@@ -83,6 +84,9 @@ class WorkflowRenderer : public GenericRenderer
*/
bool m_pausedMediaPlayer;
private slots:
void frameByFramePausingProxy();
public slots:
void setMedia( const Media* ){}
void mediaUnloaded( const QUuid& ) {}
......
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