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

Handle the mediaRemoved signal from the ClipRenderer.

Added LibVLCpp::MediaPlayer destructor, avoiding event crashes
Fixed potential memory leaks
Removed junk code, corrected minor typo
parent 9d909a89
......@@ -64,6 +64,18 @@ MediaPlayer::MediaPlayer( Media* media )
libvlc_event_attach( p_em, libvlc_MediaPlayerPositionChanged, callbacks, this, m_ex );
}
MediaPlayer::~MediaPlayer()
{
libvlc_event_detach( p_em, libvlc_MediaPlayerSnapshotTaken, callbacks, this, m_ex );
libvlc_event_detach( p_em, libvlc_MediaPlayerTimeChanged, callbacks, this, m_ex );
libvlc_event_detach( p_em, libvlc_MediaPlayerPlaying, callbacks, this, m_ex );
libvlc_event_detach( p_em, libvlc_MediaPlayerPaused, callbacks, this, m_ex );
libvlc_event_detach( p_em, libvlc_MediaPlayerStopped, callbacks, this, m_ex );
libvlc_event_detach( p_em, libvlc_MediaPlayerEndReached, callbacks, this, m_ex );
libvlc_event_detach( p_em, libvlc_MediaPlayerPositionChanged, callbacks, this, m_ex );
libvlc_media_player_release( m_internalPtr );
}
/**
* Event dispatcher.
*/
......
......@@ -40,6 +40,7 @@ namespace LibVLCpp
public:
MediaPlayer();
MediaPlayer( Media* media );
~MediaPlayer();
void play();
void pause();
void stop();
......
......@@ -51,9 +51,10 @@ Media::Media( const QFileInfo* fileInfo)
Media::~Media()
{
if ( m_vlcMedia )
{
delete m_vlcMedia;
}
if ( m_snapshot )
delete m_snapshot;
delete m_fileInfo;
}
void Media::setFileType()
......
......@@ -119,8 +119,10 @@ void MainWindow::setupLibrary()
libraryWidget,
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*) ) );
connect( Library::getInstance(), SIGNAL( mediaRemoved( const QUuid& ) ),
m_clipPreview->getGenericRenderer(), SLOT( mediaUnloaded( QUuid ) ) );
}
void MainWindow::createStatusBar()
......
......@@ -43,7 +43,7 @@ PreviewWidget::PreviewWidget( GenericRenderer* genericRenderer, QWidget *parent
m_ui->seekSlider->setSingleStep( 2 );
m_ui->seekSlider->setFocusPolicy( Qt::NoFocus );
setAcceptDrops( true );
setAcceptDrops( false );
connect( m_ui->seekSlider, SIGNAL( sliderPressed() ), this, SLOT( seekSliderPressed() ) );
connect( m_ui->seekSlider, SIGNAL( sliderPosChanged(int) ), this, SLOT( seekSliderMoved(int) ) );
......@@ -75,43 +75,6 @@ void PreviewWidget::changeEvent( QEvent *e )
}
}
//void PreviewWidget::dragEnterEvent( QDragEnterEvent* event )
//{
// if ( event->mimeData()->hasFormat( "vlmc/uuid" ) ||
// event->mimeData()->urls().count() == 1 )
// {
// event->acceptProposedAction();
// }
//}
//
//void PreviewWidget::dropEvent( QDropEvent* event )
//{
// //If the dropped event is a clip to preview :
// if ( event->mimeData()->hasFormat( "vlmc/uuid" ) ||
// event->mimeData()->urls().count() == 1 )
// {
// Media* media;
// if ( event->mimeData()->urls().count() == 1 )
// {
// Library* lib = Library::getInstance();
// lib->newMediaLoadingAsked( event->mimeData()->urls()[0].path() );
// media = lib->getMedia( event->mimeData()->urls()[0].path() );
// }
// else
// media = Library::getInstance()->getMedia( QUuid( QString( event->mimeData()->data( "vlmc/uuid" ) ) ) );
//
// if ( media == NULL )
// {
// qDebug() << "Unknown media" << event->mimeData()->data( "vlmc/uuid" );
// return ;
// }
//
// event->acceptProposedAction();
// m_renderer->startPreview( media );
// m_previewStopped = false;
// }
//}
void PreviewWidget::positionChanged( float newPos )
{
if ( m_previewStopped == false )
......
......@@ -50,8 +50,6 @@ private:
protected:
virtual void changeEvent( QEvent *e );
// virtual void dragEnterEvent( QDragEnterEvent* event );
// virtual void dropEvent( QDropEvent* event );
private slots:
void on_pushButtonPlay_clicked();
......
......@@ -133,6 +133,19 @@ void ClipRenderer::previousFrame()
}
}
void ClipRenderer::mediaUnloaded( const QUuid& uuid )
{
if ( m_selectedMedia != NULL && m_selectedMedia->getUuid() == uuid )
{
m_mediaPlayer->stop();
qDebug() << "Media unloaded";
m_clipLoaded = false;
m_selectedMedia = NULL;
m_isRendering = false;
m_paused = false;
}
}
/////////////////////////////////////////////////////////////////////
/////SLOTS :
/////////////////////////////////////////////////////////////////////
......
......@@ -40,7 +40,6 @@ public:
explicit ClipRenderer();
virtual ~ClipRenderer();
virtual void setMedia( const Media* media );
virtual void setPosition( float newPos );
virtual void togglePlayPause( bool forcePause );
virtual void stop();
......@@ -61,6 +60,9 @@ private:
bool m_mediaChanged;
public slots:
virtual void setMedia( const Media* media );
virtual void mediaUnloaded( const QUuid& );
void __positionChanged();
void __videoPaused();
void __videoPlaying();
......
......@@ -84,7 +84,8 @@ public slots:
virtual void __videoPaused() = 0;
virtual void __videoPlaying() = 0;
virtual void __endReached() = 0;
virtual void setMedia( const Media* media ) = 0;
virtual void setMedia( const Media* ) = 0;
virtual void mediaUnloaded( const QUuid& ) = 0;
signals:
......
......@@ -45,8 +45,6 @@ class WorkflowRenderer : public GenericRenderer
WorkflowRenderer( MainWorkflow* mainWorkflow );
~WorkflowRenderer();
virtual void setMedia( const Media* ){}
void stopPreview();
/**
......@@ -86,6 +84,9 @@ class WorkflowRenderer : public GenericRenderer
bool m_pausedMediaPlayer;
public slots:
void setMedia( const Media* ){}
void mediaUnloaded( const QUuid& uuid ) {}
void mainWorkflowPaused();
void __positionChanged();
......
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