Commit 60ce125d authored by Hugo Beauzee-Luyssen's avatar Hugo Beauzee-Luyssen

Removed commented debug texts, so that the code can be a little less green...

parent f34f1d55
......@@ -29,13 +29,11 @@
ClipWorkflow::ClipWorkflow( Clip::Clip* clip ) :
m_clip( clip ),
m_buffer( NULL ),
//m_usingBackBuffer( false ),
m_mediaPlayer(NULL),
m_state( ClipWorkflow::Stopped ),
m_requiredState( ClipWorkflow::None )
{
m_buffer = new unsigned char[VIDEOHEIGHT * VIDEOWIDTH * 4];
// m_backBuffer = new unsigned char[VIDEOHEIGHT * VIDEOWIDTH * 4];
m_stateLock = new QReadWriteLock;
m_requiredStateLock = new QMutex;
m_waitCond = new QWaitCondition;
......@@ -44,13 +42,10 @@ ClipWorkflow::ClipWorkflow( Clip::Clip* clip ) :
m_renderWaitCond = new WaitCondition;
m_pausingStateWaitCond = new WaitCondition;
m_pausedThreadCondWait = new WaitCondition;
// m_backBufferLock = new QReadWriteLock;
}
ClipWorkflow::~ClipWorkflow()
{
// delete[] m_backBuffer;
// delete m_backBufferLock;
delete m_pausedThreadCondWait;
delete m_pausingStateWaitCond;
delete m_initWaitCond;
......@@ -63,10 +58,7 @@ ClipWorkflow::~ClipWorkflow()
unsigned char* ClipWorkflow::getOutput()
{
// QReadLocker lock( m_backBufferLock );
// if ( m_usingBackBuffer == true )
return m_buffer;
// return m_backBuffer;
}
void ClipWorkflow::checkStateChange()
......@@ -75,7 +67,6 @@ void ClipWorkflow::checkStateChange()
QWriteLocker lock2( m_stateLock );
if ( m_requiredState != ClipWorkflow::None )
{
// qDebug() << "Changed state from" << m_state << "to state" << m_requiredState;
m_state = m_requiredState;
m_requiredState = ClipWorkflow::None;
checkSynchronisation( m_state );
......@@ -84,54 +75,26 @@ void ClipWorkflow::checkStateChange()
void ClipWorkflow::lock( ClipWorkflow* cw, void** pp_ret )
{
// QReadLocker lock( cw->m_backBufferLock );
// if ( cw->m_usingBackBuffer )
// {
// *pp_ret = cw->m_backBuffer;
// }
// else
// {
qDebug() << "Rendering one frame";
*pp_ret = cw->m_buffer;
// qDebug() << "Clip workflow locking <<<<<<<<<<<<<<<<<<<<<<<<<<";
// }
*pp_ret = cw->m_buffer;
}
void ClipWorkflow::unlock( ClipWorkflow* cw )
{
// qDebug() << "ClipWorkflow::unlock()";
cw->m_stateLock->lockForWrite();
// if ( cw->m_oneFrameOnly )
// {
// qDebug() << "One frame only mode is ON :)";
// //Forcing pause after rendering a frame
// cw->m_oneFrameOnly = 0;
// cw->m_state = Paused;
// }
// else
// qDebug() << "One frame only mode is OFF :(";
if ( cw->m_state == Rendering )
{
QMutexLocker lock( cw->m_condMutex );
cw->m_state = Sleeping;
cw->m_stateLock->unlock();
//Signal that render has been completed.
cw->m_renderWaitCond->wake();
// qDebug() << "Clip render completed";
cw->emit renderComplete( cw );
// qDebug() << "\t\tEntering condwait";
cw->m_waitCond->wait( cw->m_condMutex );
// qDebug() << "\t\tLeaved condwait";
cw->m_stateLock->lockForWrite();
cw->m_state = Rendering;
// {
// QWriteLocker lock2( cw->m_backBufferLock );
// cw->m_usingBackBuffer = !cw->m_usingBackBuffer;
// }
cw->m_stateLock->unlock();
}
else if ( cw->m_state == Paused )
......@@ -139,16 +102,13 @@ void ClipWorkflow::unlock( ClipWorkflow* cw )
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();
}
......@@ -350,30 +310,18 @@ void ClipWorkflow::pause()
void ClipWorkflow::unpause( bool wakeRenderThread /*= true*/ )
{
//Since VLC will detect that the media player is paused and unpause it, we can do this safely
queryStateChange( ClipWorkflow::Rendering );
m_mediaPlayer->pause();
// QMutexLocker lock( m_requiredStateLock );
// m_requiredState = ClipWorkflow::None;
if ( wakeRenderThread == true )
{
// qDebug() << "Unpausing and waking thread";
wake();
}
}
//void ClipWorkflow::activateOneFrameOnly()
//{
// qDebug() << "Activating one frame only";
// m_oneFrameOnly = 1;
//}
void ClipWorkflow::waitForCompleteRender( bool dontCheckRenderStarted /*= false*/ )
{
if ( isRendering() == true || dontCheckRenderStarted == true )
m_renderWaitCond->wait();
// else
// qDebug() << "waitForCompleteRender(), not rendering. State == " << getState();
}
void ClipWorkflow::waitForCompleteInit()
......
......@@ -90,10 +90,8 @@ unsigned char* TrackWorkflow::renderClip( ClipWorkflow* cw, qint64 currentF
cw->getStateLock()->lockForRead();
// qDebug() << "Rendering clip";
if ( cw->getState() == ClipWorkflow::ThreadPaused && pauseAfterRender == false )
{
// qDebug() << "Paused clip, but no need to repause it after";
cw->getStateLock()->unlock();
//If we must pause after render, we must NOT wake the renderer thread, or it could render more than one frame
// (since this is for the next/previous frame)
......@@ -103,7 +101,6 @@ unsigned char* TrackWorkflow::renderClip( ClipWorkflow* cw, qint64 currentF
}
if ( cw->getState() == ClipWorkflow::Rendering )
{
// qDebug() << "Rendering a 'Rendering' ClipWorkflow";
//The rendering state meens... whell it means that the frame is
//beeing rendered, so we wait.
cw->getStateLock()->unlock();
......@@ -117,9 +114,6 @@ unsigned char* TrackWorkflow::renderClip( ClipWorkflow* cw, qint64 currentF
//If frame has been rendered :
if ( cw->getState() == ClipWorkflow::Sleeping || pauseAfterRender == true )
{
// qDebug() << "rendering a sleeping clip workflow";
// if ( pauseAfterRender == true )
// qDebug() << "Rendering only one frame";
cw->getStateLock()->unlock();
if ( needRepositioning == true )
......@@ -127,7 +121,6 @@ unsigned char* TrackWorkflow::renderClip( ClipWorkflow* cw, qint64 currentF
float pos = ( (float)( currentFrame - start ) / (float)(cw->getClip()->getLength()) );
cw->setPosition( pos );
}
// qDebug() << "getting clip output";
ret = cw->getOutput();
if ( pauseAfterRender == false )
{
......@@ -137,22 +130,18 @@ unsigned char* TrackWorkflow::renderClip( ClipWorkflow* cw, qint64 currentF
else
{
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();
}
}
else if ( cw->getState() == ClipWorkflow::Stopped )
{
// qDebug() << "Rendering a stopped clip workflow";
cw->getStateLock()->unlock();
cw->initialize( );
cw->startRender();
......@@ -167,7 +156,6 @@ unsigned char* TrackWorkflow::renderClip( ClipWorkflow* cw, qint64 currentF
{
//If the state is Initializing, then the workflow will wait.
//Otherwise, it will start directly.
// qDebug() << "Rendering a ready clip workflow";
cw->getStateLock()->unlock();
cw->startRender();
if ( needRepositioning == true )
......@@ -183,7 +171,6 @@ unsigned char* TrackWorkflow::renderClip( ClipWorkflow* cw, qint64 currentF
}
else
{
// qDebug() << "Unexpected ClipWorkflow::State when rendering:" << cw->getState();
cw->getStateLock()->unlock();
}
return ret;
......@@ -215,16 +202,13 @@ void TrackWorkflow::stopClipWorkflow( ClipWorkflow* cw )
cw->getState() == ClipWorkflow::Ready ||
cw->getState() == ClipWorkflow::EndReached )
{
// qDebug() << "Stopping a sleeping / ready / endreached clip. Status == " << cw->getState();
cw->getStateLock()->unlock();
cw->queryStateChange( ClipWorkflow::Stopping );
cw->wake();
cw->stop();
// qDebug() << "Stopping sleeping/ready/endreached clip";
}
else if ( cw->getState() == ClipWorkflow::Rendering )
{
// qDebug() << "Stopping a rendering clipworkflow";
cw->getStateLock()->unlock();
cw->waitForCompleteRender();
{
......@@ -233,24 +217,19 @@ void TrackWorkflow::stopClipWorkflow( ClipWorkflow* cw )
}
cw->wake();
cw->stop();
// qDebug() << "Stopped rendering clipworkflow";
}
else if ( cw->getState() == ClipWorkflow::Initializing )
{
// qDebug() << "Stopping an Initializing clipworkflow";
cw->getStateLock()->unlock();
cw->waitForCompleteInit();
cw->stop();
// qDebug() << "Stopped Initializing clipworkflow";
}
else if ( cw->getState() == ClipWorkflow::Paused )
{
// qDebug() << "Stopping a paused clipworkflow";
cw->getStateLock()->unlock();
cw->queryStateChange( ClipWorkflow::Stopping );
cw->wake();
cw->stop();
// qDebug() << "Stopped a paused clipworkflow";
}
else if ( cw->getState() == ClipWorkflow::ThreadPaused )
{
......@@ -305,10 +284,7 @@ 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 );
......@@ -337,10 +313,6 @@ unsigned char* TrackWorkflow::getOutput( qint64 currentFrame )
{
m_nbClipToRender.fetchAndAddAcquire( 1 );
ret = renderClip( cw, currentFrame, start, needRepositioning, oneFrameOnlyFlag );
// if ( oneFrameOnlyFlag == true )
// {
// cw->pause();
// }
lastFrame = currentFrame;
}
//Is it about to be rendered ?
......@@ -385,18 +357,20 @@ void TrackWorkflow::pauseClipWorkflow( ClipWorkflow* cw )
//Locking this mutex ensure that the thread is really asleep, and hasn't
//just changed the state, and then get pulled back by the scheduler...
QMutexLocker lock( cw->getSleepMutex() );
cw->queryStateChange( ClipWorkflow::Pausing );
{
QMutexLocker lock( cw->getSleepMutex() );
cw->queryStateChange( ClipWorkflow::Pausing );
}
cw->wake();
}
else if ( cw->getState() == ClipWorkflow::Rendering )
{
cw->getStateLock()->unlock();
// qDebug() << "Waiting for complete render";
cw->waitForCompleteRender();
// qDebug() << "Render has been completed... continue pausing";
QMutexLocker lock( cw->getSleepMutex() );
cw->queryStateChange( ClipWorkflow::Pausing );
{
QMutexLocker lock( cw->getSleepMutex() );
cw->queryStateChange( ClipWorkflow::Pausing );
}
cw->wake();
}
else if ( cw->getState() == ClipWorkflow::Initializing )
......@@ -407,7 +381,7 @@ void TrackWorkflow::pauseClipWorkflow( ClipWorkflow* cw )
}
else
{
// qDebug() << "Unexpected ClipWorkflow::State when pausing:" << cw->getState();
// qDebug() << "Unexpected ClipWorkflow::State when pausing:" << cw->getState();
cw->getStateLock()->unlock();
}
cw->waitForPausingState();
......@@ -415,9 +389,7 @@ void TrackWorkflow::pauseClipWorkflow( ClipWorkflow* cw )
}
else
cw->getStateLock()->unlock();
// qDebug() << "Wait for pausedthread state";
cw->waitForPausedThread();
// qDebug() << "Ok thread is paused";
}
void TrackWorkflow::pause()
......@@ -434,7 +406,6 @@ void TrackWorkflow::pause()
ClipWorkflow* cw = it.value();
cw->getStateLock()->lockForRead();
// qDebug() << "Pausing a clip in state" << cw->getState();
if ( cw->getState() == ClipWorkflow::Stopped )
{
cw->getStateLock()->unlock();
......@@ -444,7 +415,6 @@ void TrackWorkflow::pause()
{
cw->getStateLock()->unlock();
m_nbClipToPause.fetchAndAddAcquire( 1 );
// connect( cw->getMediaPlayer(), SIGNAL( paused() ), this, SLOT( clipWorkflowPaused() ) );
pauseClipWorkflow( cw );
}
else
......@@ -498,8 +468,6 @@ Clip* TrackWorkflow::removeClip( const QUuid& id )
ClipWorkflow* cw = it.value();
Clip* clip = cw->getClip();
m_clips.erase( it );
// stopClipWorkflow( cw );
// delete cw;
computeLength();
return clip;
}
......@@ -513,18 +481,8 @@ void TrackWorkflow::activateOneFrameOnly()
m_oneFrameOnly = 1;
}
//void TrackWorkflow::clipWorkflowPaused()
//{
// m_nbClipToPause.fetchAndAddAcquire( -1 );
// if ( m_nbClipToPause == 0 )
// {
// emit trackPaused();
// }
//}
void TrackWorkflow::clipWorkflowRenderCompleted( ClipWorkflow* cw )
{
// qDebug() << "clip workflow render complete. Checking for track completed";
if ( cw != NULL )
{
m_synchroneRenderBuffer = cw->getOutput();
......@@ -538,8 +496,6 @@ void TrackWorkflow::clipWorkflowRenderCompleted( ClipWorkflow* cw )
//or equal to 0
if ( m_nbClipToRender <= 0 )
emit renderCompleted( m_trackId );
// else
// qDebug() << "Trackworfklow render isn't complete yet." << m_nbClipToRender << "cw remaining";
}
unsigned char* TrackWorkflow::getSynchroneOutput()
......
......@@ -34,14 +34,10 @@ WorkflowRenderer::WorkflowRenderer( MainWorkflow* mainWorkflow ) :
m_pausedMediaPlayer( false ),
m_frameByFrameMode( 0 )
{
char buffer[64];
m_actionsLock = new QReadWriteLock;
m_media = new LibVLCpp::Media( "fake://" );
// --invmem-width <integer> Width
// --invmem-height <integer> Height
// --invmem-lock <string> Lock function
// --invmem-unlock <string> Unlock function
// --invmem-data <string> Callback data
char buffer[64];
sprintf( buffer, ":invmem-width=%i", VIDEOWIDTH );
m_media->addOption( ":codec=invmem" );
......@@ -86,26 +82,18 @@ WorkflowRenderer::~WorkflowRenderer()
void* WorkflowRenderer::lock( void* datas )
{
WorkflowRenderer* self = reinterpret_cast<WorkflowRenderer*>( datas );
qDebug() << "One frame is queryied by the workflowrenderer";
//If renderer is stopping, don't ask for another frame:
if ( self->m_isRendering == false )
{
// qDebug() << "WorkflowRenderer doesn't render anymore (stopping state)";
return self->m_lastFrame;
}
//If a pause was asked, don't try to start a new render... it could (and would) dead lock...
if ( self->m_pauseAsked == true )
{
// qDebug() << "WorkflowRenderer is pausing, returning last frame";
return self->m_lastFrame;
}
//If we're not playing, then where in a paused media player.
if ( self->m_pausedMediaPlayer == true )
{
// qDebug() << "Returning last frame, since media player is paused";
return self->m_lastFrame;
}
if ( self->m_oneFrameOnly < 2 )
{
void* ret;
......@@ -118,26 +106,19 @@ void* WorkflowRenderer::lock( void* datas )
// qDebug() << "Got it";
// }
self->m_lastFrame = static_cast<unsigned char*>( ret );
// qDebug() << "Returning new frame";
return ret;
}
else
{
// qDebug() << "Returning last frame, due to m_oneFrameOnly flag (" << self->m_oneFrameOnly << ")";
return self->m_lastFrame;
}
}
void WorkflowRenderer::unlock( void* datas )
{
WorkflowRenderer* self = reinterpret_cast<WorkflowRenderer*>( datas );
// qDebug() << "Workflowrenderer::unlock. m_oneFrameOnly ==" << self->m_oneFrameOnly;
if ( self->m_oneFrameOnly == 1 )
{
// qDebug() << "Pausing back";
self->internalPlayPause( true );
// qDebug() << "Switching m_oneFrameOnly flag to 2";
self->m_oneFrameOnly = 2;
}
self->m_framePlayed = true;
......@@ -160,7 +141,6 @@ void WorkflowRenderer::checkActions()
if ( m_pauseAsked == true )
continue ;
m_pauseAsked = true;
qDebug() << "Asking the media player to pause";
m_mediaPlayer->pause();
//This will also pause the MainWorkflow via a signal/slot
break ;
......@@ -200,13 +180,9 @@ void WorkflowRenderer::setPosition( float newPos )
void WorkflowRenderer::frameByFrameAfterPaused()
{
qDebug() << "<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<";
m_oneFrameOnly = 1;
m_mainWorkflow->activateOneFrameOnly();
// m_mainWorkflow->nextFrame();
internalPlayPause( false );
}
......@@ -227,7 +203,6 @@ void WorkflowRenderer::nextFrame()
{
if ( m_frameByFrameMode == 0 )
{
// disconnect( m_mainWorkflow, SIGNAL( mainWorkflowPaused() ), this, SLOT( mainWorkflowPaused() ) );
m_frameByFrameMode = 1;
}
if ( m_pausedMediaPlayer == true )
......@@ -257,10 +232,8 @@ void WorkflowRenderer::pauseMainWorkflow()
void WorkflowRenderer::mainWorkflowPaused()
{
// qDebug() << "Mainworkflow is now paused";
m_paused = true;
m_pauseAsked = false;
qDebug() << "mainWorkflowPaused();, m_oneFrameOnly ==" << m_oneFrameOnly;
if ( m_frameByFrameMode < 2 )
{
emit paused();
......@@ -274,8 +247,6 @@ void WorkflowRenderer::togglePlayPause( bool forcePause )
{
if ( m_frameByFrameMode != 0 )
{
qDebug() << "Falling back in normal render mode";
// connect( m_mainWorkflow, SIGNAL( mainWorkflowPaused() ), this, SLOT( mainWorkflowPaused() ) );
m_frameByFrameMode = 0;
}
if ( m_isRendering == false && forcePause == false )
......@@ -342,13 +313,11 @@ void WorkflowRenderer::__videoPaused()
{
m_oneFrameOnly = 0;
}
// qDebug() << "Pausing main workflow";
pauseMainWorkflow();
}
void WorkflowRenderer::__videoPlaying()
{
qDebug() << "__videoPlaying(), m_oneFrameOnly ==" << m_oneFrameOnly;
if ( m_frameByFrameMode == 0 )
emit playing();
m_pausedMediaPlayer = false;
......
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