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