Commit 273057c5 authored by Christophe Courtaut's avatar Christophe Courtaut

Bugfix in Dtors of medias, avoid segfault on drop

parent b12ce039
......@@ -25,7 +25,8 @@
#include "InputMedia.h"
InputMedia::InputMedia( const QString& mrl, LibVLCpp::Instance* instance /*= NULL*/ ) : Media( instance, mrl ), m_snapshot( NULL )
InputMedia::InputMedia( const QString& mrl, LibVLCpp::Instance* instance /*= NULL*/ ) :
Media( instance, mrl ), m_snapshot( NULL ), m_pixelBuffer( NULL ), m_image ( NULL )
{
// m_vlcMedia->outputInVmem();
// m_vlcMedia->setLockCallback( InputMedia::lock );
......@@ -53,8 +54,11 @@ InputMedia::InputMedia( const QString& mrl, LibVLCpp::Instance* instance /*= NUL
InputMedia::~InputMedia()
{
delete m_image;
delete m_pixelBuffer;
qDebug() << "dtor InputMedia";
if ( m_image != NULL )
delete m_image;
if ( m_pixelBuffer != NULL)
delete m_pixelBuffer;
}
void InputMedia::lock( LibVLCpp::Media::DataCtx* ctx, void **renderPtr )
......
......@@ -27,7 +27,7 @@
using namespace LibVLCpp;
Media::Media( Instance* instance, const QString& filename )
: m_instance( *instance ), m_pixelBuffer( NULL )
: m_instance( *instance ), m_dataCtx( NULL ), m_pixelBuffer( NULL )
{
m_internalPtr = libvlc_media_new( m_instance, filename.toLocal8Bit(), m_ex );
m_ex.checkThrow();
......@@ -36,8 +36,10 @@ Media::Media( Instance* instance, const QString& filename )
Media::~Media()
{
libvlc_media_release( m_internalPtr );
delete[] m_pixelBuffer;
delete m_dataCtx;
if ( m_pixelBuffer != NULL )
delete[] m_pixelBuffer;
if ( m_dataCtx != NULL )
delete m_dataCtx;
}
Media::DataCtx* Media::buildDataCtx()
......
......@@ -25,7 +25,7 @@
Media::Media(LibVLCpp::Instance* instance, const QString& mrl )
: m_instance( NULL ), m_vlcMedia( NULL ), m_vlcMediaPlayer( NULL ),
m_mrl( mrl )
m_mrl( mrl ), m_instanceOwned( false )
{
if ( instance == NULL )
{
......@@ -39,6 +39,7 @@ Media::Media(LibVLCpp::Instance* instance, const QString& mrl )
};
int vlc_argc = sizeof( vlc_argv ) / sizeof( *vlc_argv );
instance = new LibVLCpp::Instance( vlc_argc, vlc_argv );
m_instanceOwned = true;
}
m_instance = instance;
......@@ -47,12 +48,23 @@ Media::Media(LibVLCpp::Instance* instance, const QString& mrl )
Media::~Media()
{
if ( m_instance )
qDebug() << "dtor Media";
if ( m_instance && m_instanceOwned == true )
{
delete m_instance;
qDebug() << "deleted m_instance";
}
if ( m_vlcMedia )
{
qDebug() << "deleting m_vlcMedia";
delete m_vlcMedia;
qDebug() << "deleted m_vlcMedia";
}
if ( m_vlcMediaPlayer )
{
delete m_vlcMediaPlayer;
qDebug() << "deleted m_vlcMediaPlayer";
}
}
void Media::loadMedia( const QString& mrl )
......@@ -85,6 +97,20 @@ void Media::play()
m_vlcMediaPlayer->play();
}
void Media::pause()
{
if ( m_vlcMediaPlayer == NULL )
return;
m_vlcMediaPlayer->pause();
}
void Media::stop()
{
if ( m_vlcMediaPlayer == NULL )
return;
m_vlcMediaPlayer->stop();
}
void Media::addParam( const QString& param )
{
m_parameters.append( param );
......
......@@ -40,6 +40,8 @@ public:
void loadMedia( const QString& mrl );
virtual void play();
virtual void pause();
virtual void stop();
void addParam( const QString& param );
void setupMedia();
......@@ -52,6 +54,8 @@ protected:
LibVLCpp::MediaPlayer* m_vlcMediaPlayer;
QString m_mrl;
QList<QString> m_parameters;
private:
bool m_instanceOwned;
};
#endif // MEDIA_H
......@@ -70,6 +70,11 @@ void PreviewWidget::dropEvent( QDropEvent* event )
ListViewMediaItem* item = dynamic_cast<ListViewMediaItem*>( listWidget->currentItem() );
if ( item == NULL )
return ;
if ( m_currentMedia != NULL )
{
m_currentMedia->stop();
delete m_currentMedia;
}
m_currentMedia = new InputMedia("file://" + item->fileInfo()->absoluteFilePath(), m_currentInstance );
m_currentMedia->setupMedia();
m_currentMedia->setDrawable( m_ui->clipRenderWidget->winId() );
......
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