Commit 19ae399f authored by Hugo Beauzee-Luyssen's avatar Hugo Beauzee-Luyssen

Fixing a dead lock problem when launching more than one render in the same session

This also fix the crash when clicking on play without any media loaded
parent b68959f3
......@@ -67,7 +67,7 @@ void ClipWorkflow::lock( ClipWorkflow* clipWorkflow, void** pp_ret )
//In any case, we give vlc a buffer to render in...
//If we don't, segmentation fault will catch us and eat our brain !! ahem...
// qDebug() << "Locking in ClipWorkflow::lock";
qDebug() << "Locking in ClipWorkflow::lock";
*pp_ret = clipWorkflow->m_buffer;
}
......@@ -89,6 +89,7 @@ void ClipWorkflow::unlock( ClipWorkflow* clipWorkflow )
}
clipWorkflow->m_waitCond->wait( clipWorkflow->m_condMutex );
}
// qDebug() << "UnLocking in ClipWorkflow::unlock";
}
void ClipWorkflow::setRenderComplete()
......
......@@ -29,7 +29,10 @@ MainWorkflow::MainWorkflow() : m_renderStarted( false )
{
m_tracks = new TrackWorkflow*[NB_TRACKS];
for (unsigned int i = 0; i < NB_TRACKS; ++i)
{
m_tracks[i] = new TrackWorkflow;
connect( m_tracks[i], SIGNAL( endReached() ), this, SLOT( __endReached() ) );
}
}
void MainWorkflow::addClip( Clip* clip, unsigned int trackId, qint64 start )
......@@ -74,3 +77,8 @@ qint64 MainWorkflow::getLength() const
{
return m_length;
}
void MainWorkflow::__endReached()
{
emit endReached();
}
......@@ -63,6 +63,9 @@ class MainWorkflow : public QObject
qint64 m_currentFrame;
qint64 m_length;
private slots:
void __endReached();
signals:
/**
* \brief Used to notify a change to the timeline cursor
......@@ -72,6 +75,8 @@ class MainWorkflow : public QObject
* \brief Used to nofify a change to the PreviewWidget
*/
void positionChanged( float pos );
void endReached();
};
#endif // MAINWORKFLOW_H
......@@ -50,6 +50,9 @@ void TrackWorkflow::addClip( Clip* clip, qint64 start )
void TrackWorkflow::startRender()
{
m_current = m_clips.end();
if ( m_clips.size() <= 0)
return ;
//If the first frame is to be render soon, we should play it now.
if ( m_clips.begin().key() < TrackWorkflow::nbFrameBeforePreload )
{
......@@ -75,6 +78,9 @@ bool TrackWorkflow::checkNextClip( qint64 currentFrame )
//Picking next clip :
if ( m_current == m_clips.end() )
{
//Checking if there is a clip in the first place...
if ( m_clips.count() == 0 )
return false;
next = m_clips.begin();
}
else
......@@ -123,10 +129,15 @@ unsigned char* TrackWorkflow::getOutput( qint64 currentFrame )
QReadLocker lock( m_currentLock );
// qDebug() << "Frame nb" << m_currentFrame;
// qDebug() << "Frame nb" << currentFrame;
clipsRemaining = checkNextClip( currentFrame );
if ( m_current == m_clips.end() )
{
if ( clipsRemaining == false )
{
// qDebug() << "End Reached";
emit endReached();
}
// qDebug() << "Stil no clip at this time, going to the next frame";
return ret;
}
......@@ -139,7 +150,10 @@ unsigned char* TrackWorkflow::getOutput( qint64 currentFrame )
else
{
if ( clipsRemaining == false )
return NULL;
{
// qDebug() <<"End reached";
emit endReached();
}
}
return ret;
}
......
......@@ -96,6 +96,9 @@ class TrackWorkflow : public QObject
public:
void addClip( Clip*, qint64 start );
signals:
void endReached();
};
#endif // TRACKWORKFLOW_H
......@@ -47,7 +47,6 @@ public:
virtual void startPreview( Media* media ) = 0;
virtual void setPosition( float newPos ) = 0;
virtual void togglePlayPause( bool forcePause = false ) = 0;
protected:
LibVLCpp::MediaPlayer* m_mediaPlayer;
......@@ -58,6 +57,9 @@ public slots:
virtual void __videoPlaying() = 0;
virtual void __endReached() = 0;
//For meta invoking
virtual void togglePlayPause( bool forcePause = false ) = 0;
signals:
void stopped();
void paused();
......
......@@ -23,6 +23,7 @@
#include <QUrl>
#include <QtDebug>
#include <QMetaMethod>
#include "ui_PreviewWidget.h"
#include "gui/PreviewWidget.h"
......@@ -177,6 +178,10 @@ void PreviewWidget::on_pushButtonPlay_clicked()
{
if ( m_previewStopped == true )
m_previewStopped = false;
// int methodIndex = m_currentPreviewRenderer->metaObject()->indexOfMethod("togglePlayPause(bool)");
// qDebug() << methodIndex;
// QMetaMethod method = m_currentPreviewRenderer->metaObject()->method( methodIndex );
// qDebug() << method.invoke( m_currentPreviewRenderer, Qt::QueuedConnection, Q_ARG(bool, false) );
m_currentPreviewRenderer->togglePlayPause();
}
......
......@@ -21,6 +21,7 @@
*****************************************************************************/
#include <QtDebug>
#include <QThread>
#include "RenderPreviewWidget.h"
......@@ -50,6 +51,7 @@ RenderPreviewWidget::RenderPreviewWidget( MainWorkflow* mainWorkflow, QWidget* r
connect( m_mediaPlayer, SIGNAL( playing() ), this, SLOT( __videoPlaying() ) );
connect( m_mediaPlayer, SIGNAL( paused() ), this, SLOT( __videoPaused() ) );
connect( m_mainWorkflow, SIGNAL( endReached() ), this, SLOT( __endReached() ) );
connect( m_mainWorkflow, SIGNAL( positionChanged( float ) ), this, SLOT( __positionChanged( float ) ) );
}
......@@ -64,12 +66,6 @@ void* RenderPreviewWidget::lock( void* datas )
// qDebug() << "Locking invmem";
RenderPreviewWidget* self = reinterpret_cast<RenderPreviewWidget*>( datas);
void* ret = self->m_mainWorkflow->getOutput();
if ( ret == NULL )
{
//maybe we should display a black screen here to really emphasize
//the end of the render
self->m_mediaPlayer->stop();
}
return ret;
}
......@@ -78,6 +74,13 @@ void RenderPreviewWidget::unlock( void* )
// qDebug() << "Unlocking invmem";
}
void RenderPreviewWidget::stopPreview()
{
m_mediaPlayer->stop();
m_isRendering = false;
qDebug() << "Stopped";
}
void RenderPreviewWidget::startPreview( Media* )
{
m_mainWorkflow->startRender();
......@@ -109,7 +112,8 @@ void RenderPreviewWidget::togglePlayPause( bool /*forcePause*/ )
void RenderPreviewWidget::__endReached()
{
qDebug() << "RenderPreviewWidget::__endReached : unimplemented";
// qDebug() << "Stopping preview";
stopPreview();
}
void RenderPreviewWidget::__positionChanged()
......
......@@ -40,6 +40,7 @@ class RenderPreviewWidget : public GenericPreviewWidget
~RenderPreviewWidget();
virtual void startPreview( Media* );
void stopPreview();
/**
\brief Set the preview position
......@@ -58,12 +59,12 @@ class RenderPreviewWidget : public GenericPreviewWidget
LibVLCpp::Media* m_media;
bool m_isRendering;
public slots:
void __positionChanged();
void __positionChanged( float pos );
void __videoPaused();
void __videoPlaying();
void __endReached();
public slots:
void __positionChanged();
void __positionChanged( float pos );
void __videoPaused();
void __videoPlaying();
void __endReached();
};
#endif // RENDERPREVIEWWIDGET_H
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