Commit b7b3020c authored by Hugo Beauzee-Luyssen's avatar Hugo Beauzee-Luyssen

Corrected many bad behaviours on PreviewWidget

Avoided segfault when playing track two times
parent 382685ef
......@@ -33,11 +33,27 @@ Media::Media( const QString& filename )
CheckVlcppException(m_ex);
}
Media::Media( const Media& media )
{
clone( media );
}
Media::Media( const Media* media )
{
clone( *media );
}
Media::~Media()
{
libvlc_media_release( m_internalPtr );
}
void Media::clone( const Media& toClone )
{
m_pixelBuffer = NULL;
m_internalPtr = libvlc_media_duplicate( toClone.m_internalPtr );
}
void Media::addOption( const char* opt )
{
libvlc_media_add_option_non_unique( m_internalPtr, opt, m_ex);
......
......@@ -41,6 +41,8 @@ namespace LibVLCpp
typedef void (*unlockCallback)( void* dataCtx );
Media( const QString& filename );
Media( const Media* media );
Media( const Media& media );
~Media();
void addOption( const char* opt );
void setLockCallback( Media::lockCallback );
......@@ -51,6 +53,9 @@ namespace LibVLCpp
void setPixelBuffer( uchar* buffer );
uchar* getPixelBuffer();
private:
void clone( const Media& toClone );
private:
Exception m_ex;
......
......@@ -69,6 +69,7 @@ void MainWorkflow::startRender()
emit frameChanged( 0 );
for ( unsigned int i = 0; i < m_trackCount; ++i )
{
m_tracks[i].activate();
if ( m_tracks[i]->getLength() > maxLength )
maxLength = m_tracks[i]->getLength();
}
......
......@@ -26,7 +26,7 @@
ClipPreviewWidget::ClipPreviewWidget( QWidget* renderWidget ) :
GenericPreviewWidget( renderWidget ),
m_clipLoaded( false ), m_videoStopped( true )
m_clipLoaded( false ), m_videoStopped( true ), m_vlcMedia( NULL )
{
}
......@@ -36,8 +36,11 @@ ClipPreviewWidget::~ClipPreviewWidget()
void ClipPreviewWidget::startPreview( Media* media )
{
media->flushParameters();
m_mediaPlayer->setMedia( media->getVLCMedia() );
if ( m_vlcMedia != NULL )
delete m_vlcMedia;
m_vlcMedia = new LibVLCpp::Media( media->getVLCMedia() );
m_mediaPlayer->setMedia( m_vlcMedia );
connect( m_mediaPlayer, SIGNAL( stopped() ), this, SLOT( __videoPaused() ) );
connect( m_mediaPlayer, SIGNAL( paused() ), this, SLOT( __videoPaused() ) );
......
......@@ -47,6 +47,7 @@ public:
private:
bool m_clipLoaded;
bool m_videoStopped;
LibVLCpp::Media* m_vlcMedia;
public slots:
void __positionChanged();
......
......@@ -205,19 +205,21 @@ void PreviewWidget::endReached()
void PreviewWidget::changedTab( int tabId )
{
int tmp = m_ui->seekSlider->value();
m_currentPreviewRenderer->togglePlayPause( true );
if ( tabId == PreviewWidget::clipPreviewMode )
{
m_currentPreviewRenderer = m_clipPreview;
}
else if ( tabId == PreviewWidget::renderPreviewMode )
{
m_clipPreview->togglePlayPause( true );
m_currentPreviewRenderer = m_renderPreview;
}
else
qDebug() << "Unknown and uncoherent tabId for PreviewWidget : " << tabId;
m_currentMode = !m_currentMode;
int tmp = m_ui->seekSlider->value();
m_ui->seekSlider->setValue( m_sliderPosBackup );
m_sliderPosBackup = tmp;
}
......@@ -26,7 +26,9 @@
#include "RenderPreviewWidget.h"
RenderPreviewWidget::RenderPreviewWidget( MainWorkflow* mainWorkflow, QWidget* renderWidget ) :
GenericPreviewWidget( renderWidget ), m_mainWorkflow( mainWorkflow )
GenericPreviewWidget( renderWidget ),
m_mainWorkflow( mainWorkflow ),
m_isRendering( false )
{
m_media = new LibVLCpp::Media( "fake://" );
// --invmem-width <integer> Width
......@@ -93,16 +95,22 @@ void RenderPreviewWidget::setPosition( float newPos )
m_mainWorkflow->setPosition( newPos );
}
void RenderPreviewWidget::togglePlayPause( bool /*forcePause*/ )
void RenderPreviewWidget::togglePlayPause( bool forcePause )
{
if ( m_isRendering == false )
//If force pause is true, we just ensure that this render is paused... no need to start it.
if ( m_isRendering == false && forcePause == false )
startPreview( NULL );
else
else if ( m_isRendering == true )
{
if ( m_mediaPlayer->isPlaying() == false )
if ( m_mediaPlayer->isPlaying() == false && forcePause == false )
m_mediaPlayer->play();
else
m_mediaPlayer->pause();
{
//VLC will toggle play if we call pause while already paused...
//So be careful about pausing two times :
if ( m_mediaPlayer->isPlaying() == true )
m_mediaPlayer->pause();
}
}
}
......
......@@ -52,18 +52,18 @@ public:
void setScale( double scaleFactor );
protected:
virtual void resizeEvent( QResizeEvent* event );
virtual void drawBackground( QPainter* painter, const QRectF& rect );
virtual void mouseMoveEvent( QMouseEvent* event );
virtual void mousePressEvent( QMouseEvent* event );
virtual void mouseReleaseEvent( QMouseEvent* event );
virtual void wheelEvent( QWheelEvent* event );
virtual void dragEnterEvent( QDragEnterEvent* event );
virtual void dropEvent( QDropEvent* event );
virtual void dragMoveEvent( QDragMoveEvent* event );
virtual void resizeEvent( QResizeEvent* event );
virtual void drawBackground( QPainter* painter, const QRectF& rect );
virtual void mouseMoveEvent( QMouseEvent* event );
virtual void mousePressEvent( QMouseEvent* event );
virtual void mouseReleaseEvent( QMouseEvent* event );
virtual void wheelEvent( QWheelEvent* event );
virtual void dragEnterEvent( QDragEnterEvent* event );
virtual void dropEvent( QDropEvent* event );
virtual void dragMoveEvent( QDragMoveEvent* event );
private slots:
void ensureCursorVisible();
void ensureCursorVisible();
private:
QGraphicsScene* m_scene;
......@@ -75,9 +75,9 @@ private:
MainWorkflow* m_mainWorkflow;
signals:
void zoomIn();
void zoomOut();
void durationChanged( int duration );
void zoomIn();
void zoomOut();
void durationChanged( int duration );
};
#endif // TRACKSVIEW_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