Commit 62a598c2 authored by Hugo Beauzee-Luyssen's avatar Hugo Beauzee-Luyssen

Pausing and unpausing doesn't dead lock anymore.

parent 4945c0b1
...@@ -349,7 +349,7 @@ void ClipWorkflow::pause() ...@@ -349,7 +349,7 @@ void ClipWorkflow::pause()
void ClipWorkflow::unpause( bool wakeRenderThread /*= true*/ ) void ClipWorkflow::unpause( bool wakeRenderThread /*= true*/ )
{ {
//Since VLC will detect that the media player is paused and unpause it, we can do this safely //Since VLC will detect that the media player is paused and unpause it, we can do this safely
setState( ClipWorkflow::Rendering ); queryStateChange( ClipWorkflow::Rendering );
m_mediaPlayer->pause(); m_mediaPlayer->pause();
// QMutexLocker lock( m_requiredStateLock ); // QMutexLocker lock( m_requiredStateLock );
// m_requiredState = ClipWorkflow::None; // m_requiredState = ClipWorkflow::None;
......
...@@ -91,8 +91,9 @@ unsigned char* TrackWorkflow::renderClip( ClipWorkflow* cw, qint64 currentF ...@@ -91,8 +91,9 @@ unsigned char* TrackWorkflow::renderClip( ClipWorkflow* cw, qint64 currentF
cw->getStateLock()->lockForRead(); cw->getStateLock()->lockForRead();
qDebug() << "Rendering clip"; qDebug() << "Rendering clip";
if ( cw->getState() == ClipWorkflow::Paused && pauseAfterRender == false ) if ( cw->getState() == ClipWorkflow::ThreadPaused && pauseAfterRender == false )
{ {
qDebug() << "Paused clip, but no need to repause it after";
cw->getStateLock()->unlock(); cw->getStateLock()->unlock();
//If we must pause after render, we must NOT wake the renderer thread, or it could render more than one frame //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) // (since this is for the next/previous frame)
...@@ -116,7 +117,7 @@ unsigned char* TrackWorkflow::renderClip( ClipWorkflow* cw, qint64 currentF ...@@ -116,7 +117,7 @@ unsigned char* TrackWorkflow::renderClip( ClipWorkflow* cw, qint64 currentF
//If frame has been rendered : //If frame has been rendered :
if ( cw->getState() == ClipWorkflow::Sleeping || pauseAfterRender == true ) if ( cw->getState() == ClipWorkflow::Sleeping || pauseAfterRender == true )
{ {
// qDebug() << "rendering a sleeping clip workflow"; qDebug() << "rendering a sleeping clip workflow";
if ( pauseAfterRender == true ) if ( pauseAfterRender == true )
qDebug() << "Rendering only one frame"; qDebug() << "Rendering only one frame";
cw->getStateLock()->unlock(); cw->getStateLock()->unlock();
...@@ -126,6 +127,7 @@ unsigned char* TrackWorkflow::renderClip( ClipWorkflow* cw, qint64 currentF ...@@ -126,6 +127,7 @@ unsigned char* TrackWorkflow::renderClip( ClipWorkflow* cw, qint64 currentF
float pos = ( (float)( currentFrame - start ) / (float)(cw->getClip()->getLength()) ); float pos = ( (float)( currentFrame - start ) / (float)(cw->getClip()->getLength()) );
cw->setPosition( pos ); cw->setPosition( pos );
} }
qDebug() << "getting clip output";
ret = cw->getOutput(); ret = cw->getOutput();
if ( pauseAfterRender == false ) if ( pauseAfterRender == false )
{ {
...@@ -150,6 +152,7 @@ unsigned char* TrackWorkflow::renderClip( ClipWorkflow* cw, qint64 currentF ...@@ -150,6 +152,7 @@ unsigned char* TrackWorkflow::renderClip( ClipWorkflow* cw, qint64 currentF
} }
else if ( cw->getState() == ClipWorkflow::Stopped ) else if ( cw->getState() == ClipWorkflow::Stopped )
{ {
qDebug() << "Rendering a stopped clip workflow";
cw->getStateLock()->unlock(); cw->getStateLock()->unlock();
cw->initialize( ); cw->initialize( );
cw->startRender(); cw->startRender();
...@@ -164,6 +167,7 @@ unsigned char* TrackWorkflow::renderClip( ClipWorkflow* cw, qint64 currentF ...@@ -164,6 +167,7 @@ unsigned char* TrackWorkflow::renderClip( ClipWorkflow* cw, qint64 currentF
{ {
//If the state is Initializing, then the workflow will wait. //If the state is Initializing, then the workflow will wait.
//Otherwise, it will start directly. //Otherwise, it will start directly.
qDebug() << "Rendering a ready clip workflow";
cw->getStateLock()->unlock(); cw->getStateLock()->unlock();
cw->startRender(); cw->startRender();
if ( needRepositioning == true ) if ( needRepositioning == true )
...@@ -495,10 +499,17 @@ void TrackWorkflow::clipWorkflowPaused() ...@@ -495,10 +499,17 @@ void TrackWorkflow::clipWorkflowPaused()
void TrackWorkflow::clipWorkflowRenderCompleted( ClipWorkflow* cw ) void TrackWorkflow::clipWorkflowRenderCompleted( ClipWorkflow* cw )
{ {
qDebug() << "clip workflow render complete. Checking for track completed";
if ( cw != NULL ) if ( cw != NULL )
{
qDebug() << " There is a complete buffer to return/////////////////////";
m_synchroneRenderBuffer = cw->getOutput(); m_synchroneRenderBuffer = cw->getOutput();
}
else else
{
qDebug() << "cw is null, no tracks to render/////////////////////////";
m_synchroneRenderBuffer = NULL; m_synchroneRenderBuffer = NULL;
}
m_nbClipToRender.fetchAndAddAcquire( -1 ); m_nbClipToRender.fetchAndAddAcquire( -1 );
//When there is nothing to render, m_nbClipToRender will be equal to one here, so we check for minus //When there is nothing to render, m_nbClipToRender will be equal to one here, so we check for minus
//or equal to 0 //or equal to 0
......
...@@ -119,10 +119,10 @@ void MainWindow::setupLibrary() ...@@ -119,10 +119,10 @@ void MainWindow::setupLibrary()
libraryWidget, libraryWidget,
SLOT( mediaRemoved( const QUuid& ) ) ); SLOT( mediaRemoved( const QUuid& ) ) );
connect( libraryWidget->getVideoListWidget(), SIGNAL( selectedMediaChanged(const Media*) ), // connect( libraryWidget->getVideoListWidget(), SIGNAL( selectedMediaChanged(const Media*) ),
m_clipPreview->getGenericRenderer(), SLOT( setMedia(const Media*) ) ); // m_clipPreview->getGenericRenderer(), SLOT( setMedia(const Media*) ) );
connect( Library::getInstance(), SIGNAL( mediaRemoved( const QUuid& ) ), // connect( Library::getInstance(), SIGNAL( mediaRemoved( const QUuid& ) ),
m_clipPreview->getGenericRenderer(), SLOT( mediaUnloaded( QUuid ) ) ); // m_clipPreview->getGenericRenderer(), SLOT( mediaUnloaded( QUuid ) ) );
} }
void MainWindow::createStatusBar() void MainWindow::createStatusBar()
...@@ -153,12 +153,12 @@ void MainWindow::initializeDockWidgets( void ) ...@@ -153,12 +153,12 @@ void MainWindow::initializeDockWidgets( void )
QDockWidget::AllDockWidgetFeatures, QDockWidget::AllDockWidgetFeatures,
Qt::TopDockWidgetArea); Qt::TopDockWidgetArea);
m_clipPreview = new PreviewWidget( new ClipRenderer, this ); // m_clipPreview = new PreviewWidget( new ClipRenderer, this );
dockManager->addDockedWidget( m_clipPreview, // dockManager->addDockedWidget( m_clipPreview,
tr( "Clip Preview" ), // tr( "Clip Preview" ),
Qt::AllDockWidgetAreas, // Qt::AllDockWidgetAreas,
QDockWidget::AllDockWidgetFeatures, // QDockWidget::AllDockWidgetFeatures,
Qt::TopDockWidgetArea ); // Qt::TopDockWidgetArea );
m_projectPreview = new PreviewWidget( new WorkflowRenderer( m_timeline->getMainWorkflow() ), this ); m_projectPreview = new PreviewWidget( new WorkflowRenderer( m_timeline->getMainWorkflow() ), this );
dockManager->addDockedWidget( m_projectPreview, dockManager->addDockedWidget( m_projectPreview,
......
...@@ -84,11 +84,15 @@ WorkflowRenderer::~WorkflowRenderer() ...@@ -84,11 +84,15 @@ WorkflowRenderer::~WorkflowRenderer()
void* WorkflowRenderer::lock( void* datas ) void* WorkflowRenderer::lock( void* datas )
{ {
qDebug() << "Locking workflow renderer";
WorkflowRenderer* self = reinterpret_cast<WorkflowRenderer*>( datas ); WorkflowRenderer* self = reinterpret_cast<WorkflowRenderer*>( datas );
//If renderer is stopping, don't ask for another frame: //If renderer is stopping, don't ask for another frame:
if ( self->m_isRendering == false ) if ( self->m_isRendering == false )
return self->m_lastFrame; 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 )
return self->m_lastFrame;
//If we're not playing, then where in a paused media player. //If we're not playing, then where in a paused media player.
if ( self->m_pausedMediaPlayer == true ) if ( self->m_pausedMediaPlayer == true )
{ {
...@@ -102,7 +106,7 @@ void* WorkflowRenderer::lock( void* datas ) ...@@ -102,7 +106,7 @@ void* WorkflowRenderer::lock( void* datas )
// ret = self->m_mainWorkflow->getOutput(); // ret = self->m_mainWorkflow->getOutput();
// else // else
// { // {
// qDebug() << "Asking synchrone frame"; qDebug() << "Asking synchrone frame";
ret = self->m_mainWorkflow->getSynchroneOutput(); ret = self->m_mainWorkflow->getSynchroneOutput();
// } // }
self->m_lastFrame = static_cast<unsigned char*>( ret ); self->m_lastFrame = static_cast<unsigned char*>( ret );
...@@ -119,6 +123,8 @@ void* WorkflowRenderer::lock( void* datas ) ...@@ -119,6 +123,8 @@ void* WorkflowRenderer::lock( void* datas )
void WorkflowRenderer::unlock( void* datas ) void WorkflowRenderer::unlock( void* datas )
{ {
WorkflowRenderer* self = reinterpret_cast<WorkflowRenderer*>( datas ); WorkflowRenderer* self = reinterpret_cast<WorkflowRenderer*>( datas );
qDebug() << "Workflowrenderer::unlock. m_oneFrameOnly ==" << self->m_oneFrameOnly;
if ( self->m_oneFrameOnly == 1 ) if ( self->m_oneFrameOnly == 1 )
{ {
qDebug() << "Pausing back"; qDebug() << "Pausing back";
...@@ -146,6 +152,7 @@ void WorkflowRenderer::checkActions() ...@@ -146,6 +152,7 @@ void WorkflowRenderer::checkActions()
if ( m_pauseAsked == true ) if ( m_pauseAsked == true )
continue ; continue ;
m_pauseAsked = true; m_pauseAsked = true;
qDebug() << "Pausing workflow renderer";
m_mediaPlayer->pause(); m_mediaPlayer->pause();
//This will also pause the MainWorkflow via a signal/slot //This will also pause the MainWorkflow via a signal/slot
break ; break ;
...@@ -154,6 +161,7 @@ void WorkflowRenderer::checkActions() ...@@ -154,6 +161,7 @@ void WorkflowRenderer::checkActions()
break ; break ;
} }
} }
qDebug() << "End of method ----------------------------------------";
} }
void WorkflowRenderer::stopPreview() void WorkflowRenderer::stopPreview()
...@@ -194,6 +202,7 @@ void WorkflowRenderer::frameByFrameAfterPaused() ...@@ -194,6 +202,7 @@ void WorkflowRenderer::frameByFrameAfterPaused()
qDebug() << "Unpausing everything"; qDebug() << "Unpausing everything";
togglePlayPause( false ); togglePlayPause( false );
qDebug() << "Everything should be unpaused";
} }
void WorkflowRenderer::frameByFramePausingProxy() void WorkflowRenderer::frameByFramePausingProxy()
...@@ -254,6 +263,7 @@ void WorkflowRenderer::togglePlayPause( bool forcePause ) ...@@ -254,6 +263,7 @@ void WorkflowRenderer::togglePlayPause( bool forcePause )
if ( m_paused == true && forcePause == false ) if ( m_paused == true && forcePause == false )
{ {
//This will automaticly unpause the ClipWorkflow... no worries //This will automaticly unpause the ClipWorkflow... no worries
qDebug() << "Unpausing workflow renderer";
m_mediaPlayer->play(); m_mediaPlayer->play();
} }
else else
...@@ -301,6 +311,7 @@ void WorkflowRenderer::__positionChanged( float pos ) ...@@ -301,6 +311,7 @@ void WorkflowRenderer::__positionChanged( float pos )
void WorkflowRenderer::__videoPaused() void WorkflowRenderer::__videoPaused()
{ {
qDebug() << "Slot for media player paused";
if ( m_oneFrameOnly != 0 ) if ( m_oneFrameOnly != 0 )
{ {
m_oneFrameOnly = 0; m_oneFrameOnly = 0;
......
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