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

Refactored library.

Library is now made of a GUI representation, and a frontend/backend,
that communicate with slots/signals
Also, VLCException must now be catched using the macro
CheckVlcppException, so that it prints out file and line of the error.
parent f7330fd4
......@@ -61,14 +61,14 @@ int Exception::raised() const
return libvlc_exception_raised( m_internalPtr );
}
void Exception::checkThrow()
void Exception::checkThrow( const char* file, int line )
{
if ( raised() == Exception::Raised )
{
if ( Exception::m_errorCallback != NULL )
Exception::m_errorCallback( getErrorText(), Exception::m_datas );
else
qWarning() << "An exception was raised, but no error handler is set.\nError message is: " << getErrorText();
qWarning() << "A VLC exception was raised in" << file << " at line " << line << ": \"" << getErrorText() << "\"";
clear();
}
}
......@@ -26,6 +26,8 @@
#include "vlc/vlc.h"
#include "VLCpp.hpp"
#define CheckVlcppException(ex) (ex.checkThrow(__FILE__, __LINE__))
namespace LibVLCpp
{
class Exception : public Internal< libvlc_exception_t >
......@@ -37,7 +39,7 @@ namespace LibVLCpp
const char* getErrorText() const;
void clear();
int raised() const;
void checkThrow();
void checkThrow( const char* file, int line );
static const int Raised = 1;
static const int NotRaised = 0;
......
......@@ -41,11 +41,11 @@ Instance::Instance()
int argc = sizeof( argv ) / sizeof( *argv );
m_internalPtr = libvlc_new( argc, argv, m_ex );
m_ex.checkThrow();
CheckVlcppException(m_ex);
}
Instance::Instance( int argc, const char** argv )
{
m_internalPtr = libvlc_new( argc, argv, m_ex );
m_ex.checkThrow();
CheckVlcppException(m_ex);
}
......@@ -30,7 +30,7 @@ Media::Media( const QString& filename )
: m_dataCtx( NULL ), m_pixelBuffer( NULL )
{
m_internalPtr = libvlc_media_new( *(LibVLCpp::Instance::getInstance()), filename.toLocal8Bit(), m_ex );
m_ex.checkThrow();
CheckVlcppException(m_ex);
}
Media::~Media()
......@@ -53,7 +53,7 @@ Media::DataCtx* Media::buildDataCtx()
void Media::addOption( const char* opt )
{
libvlc_media_add_option( m_internalPtr, opt, m_ex);
m_ex.checkThrow();
CheckVlcppException(m_ex);
qDebug() << "Added media option: " << opt;
}
......
......@@ -9,19 +9,19 @@ MediaList::MediaList() : m_listPlayer( NULL )
{
//Initializing media list :
m_internalPtr = libvlc_media_list_new( *(Instance::getInstance()), m_exception );
m_exception.checkThrow();
CheckVlcppException(m_exception);
//Initializing list_player :
m_listPlayer = libvlc_media_list_player_new( *(Instance::getInstance()), m_exception );
m_exception.checkThrow();
CheckVlcppException(m_exception);
//Associating player with media list :
libvlc_media_list_player_set_media_list( m_listPlayer, m_internalPtr, m_exception );
m_exception.checkThrow();
CheckVlcppException(m_exception);
//Initializing event manager :
m_eventManager = libvlc_media_list_event_manager( m_internalPtr, m_exception );
m_exception.checkThrow();
CheckVlcppException(m_exception);
initWatchedEvents();
}
......@@ -53,12 +53,13 @@ void MediaList::addMedia( Media* media )
MediaList::Locker lockMediaList( m_internalPtr );
libvlc_media_list_add_media( m_internalPtr, *media, m_exception );
m_exception.checkThrow();
CheckVlcppException(m_exception);
}
void MediaList::setMediaPlayer( MediaPlayer* mp )
{
libvlc_media_list_player_set_media_player( m_listPlayer, *mp, m_exception );
CheckVlcppException(m_exception);
}
MediaList::Locker::Locker( MediaList::internalPtr mediaList ) : m_mediaList( mediaList )
......
......@@ -30,7 +30,7 @@ using namespace LibVLCpp;
MediaPlayer::MediaPlayer()
{
m_internalPtr = libvlc_media_player_new( LibVLCpp::Instance::getInstance()->getInternalPtr(), m_ex );
m_ex.checkThrow();
CheckVlcppException(m_ex);
// Initialize the event manager
p_em = libvlc_media_player_event_manager( m_internalPtr, m_ex );
......@@ -48,7 +48,7 @@ MediaPlayer::MediaPlayer()
MediaPlayer::MediaPlayer( Media* media )
{
m_internalPtr = libvlc_media_player_new_from_media( media->getInternalPtr(), m_ex );
m_ex.checkThrow();
CheckVlcppException(m_ex);
// Initialize the event manager
p_em = libvlc_media_player_event_manager( m_internalPtr, m_ex );
......@@ -126,82 +126,84 @@ void MediaPlayer::callbacks( const libvlc_event_t* ev
void MediaPlayer::play()
{
libvlc_media_player_play( m_internalPtr, m_ex );
m_ex.checkThrow();
CheckVlcppException(m_ex);
}
void MediaPlayer::pause()
{
libvlc_media_player_pause( m_internalPtr, m_ex );
m_ex.checkThrow();
CheckVlcppException(m_ex);
}
void MediaPlayer::stop()
{
libvlc_media_player_stop( m_internalPtr, m_ex );
m_ex.checkThrow();
CheckVlcppException(m_ex);
}
qint64 MediaPlayer::getTime()
{
qint64 t = libvlc_media_player_get_time( m_internalPtr, m_ex );
m_ex.checkThrow();
CheckVlcppException(m_ex);
return t;
}
void MediaPlayer::setTime( qint64 time )
{
libvlc_media_player_set_time( m_internalPtr, time, m_ex );
m_ex.checkThrow();
CheckVlcppException(m_ex);
}
float MediaPlayer::getPosition()
{
float p = libvlc_media_player_get_position( m_internalPtr, m_ex );
m_ex.checkThrow();
CheckVlcppException(m_ex);
return p;
}
void MediaPlayer::setPosition( float pos )
{
libvlc_media_player_set_position( m_internalPtr, pos, m_ex );
m_ex.checkThrow();
CheckVlcppException(m_ex);
}
qint64 MediaPlayer::getLength()
{
qint64 length = libvlc_media_player_get_length( m_internalPtr, m_ex );
m_ex.checkThrow();
CheckVlcppException(m_ex);
return length;
}
void MediaPlayer::takeSnapshot( char* outputFile, unsigned int width, unsigned int heigth )
{
libvlc_video_take_snapshot( *this, outputFile, width, heigth, m_ex);
m_ex.checkThrow();
CheckVlcppException(m_ex);
}
bool MediaPlayer::isPlaying()
{
int res = libvlc_media_player_is_playing( m_internalPtr, m_ex );
m_ex.checkThrow();
CheckVlcppException(m_ex);
return (res == 1);
}
bool MediaPlayer::isSeekable()
{
int res = libvlc_media_player_is_seekable( m_internalPtr, m_ex );
m_ex.checkThrow();
CheckVlcppException(m_ex);
return (res == 1);
}
void MediaPlayer::setDrawable( void* hwnd )
{
libvlc_media_player_set_hwnd( m_internalPtr, hwnd, m_ex );
CheckVlcppException(m_ex);
}
void MediaPlayer::setDrawable( uint32_t drawable )
{
libvlc_media_player_set_xwindow( m_internalPtr, drawable, m_ex );
CheckVlcppException(m_ex);
}
void MediaPlayer::timeChangedFilter()
......@@ -218,18 +220,19 @@ void MediaPlayer::timeChangedFilter()
void MediaPlayer::setMedia( Media* media )
{
libvlc_media_player_set_media( m_internalPtr, media->getInternalPtr(), m_ex);
CheckVlcppException(m_ex);
}
int MediaPlayer::getWidth()
{
int width = libvlc_video_get_width( m_internalPtr, m_ex );
m_ex.checkThrow();
CheckVlcppException(m_ex);
return width;
}
int MediaPlayer::getHeight()
{
int height = libvlc_video_get_height( m_internalPtr, m_ex );
m_ex.checkThrow();
CheckVlcppException(m_ex);
return height;
}
/*****************************************************************************
* Library.cpp: Multimedia library
*****************************************************************************
* Copyright (C) 2008-2009 the VLMC team
*
* Authors: Hugo Beauzee-Luyssen <hugo@vlmc.org>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
#include <QtDebug>
#include "Library.h"
#include "Clip.h"
Library::Library()
{
}
Clip* Library::getClip( const QUuid& uuid )
{
QHash<QUuid, Clip*>::iterator it = m_clips.find( uuid );
if ( it == m_clips.end() )
return NULL;
return *it;
}
void Library::removingClipAsked( const QUuid& uuid )
{
QHash<QUuid, Clip*>::iterator it = m_clips.find( uuid );
if ( it == m_clips.end() )
return ;
emit clipRemoved( uuid );
//TODO: this is obviously a memleak, but at the moment, the library depends on the clip to work,
//and won't be abble to remove the ListViewMediaItem without it.
//delete *it;
m_clips.erase( it );
}
void Library::newClipLoadingAsked( const QString& filePath )
{
Clip* clip;
foreach ( clip, m_clips )
{
if ( clip->getFileInfo()->absoluteFilePath() == filePath )
return ;
}
//TODO: maybe we should think about taking a reference to a QFileInfo on Clip::Clip() to avoid multiple new...
QFileInfo* fInfo = new QFileInfo( filePath );
clip = new Clip( fInfo );
m_clips[clip->getUuid()] = clip;
emit newClipLoaded( clip );
delete fInfo;
}
/*****************************************************************************
* Library.h: Multimedia library
*****************************************************************************
* Copyright (C) 2008-2009 the VLMC team
*
* Authors: Hugo Beauzee-Luyssen <hugo@vlmc.org>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
#ifndef LIBRARY_H
#define LIBRARY_H
#include <QObject>
#include <QHash>
#include <QUuid>
#include <QFileInfo>
#include "Clip.h"
#include "Singleton.hpp"
class Library : public QObject, public Singleton<Library>
{
Q_OBJECT
Q_DISABLE_COPY( Library );
public:
Clip* getClip( const QUuid& uuid );
private:
Library();
QHash<QUuid, Clip*> m_clips;
public slots:
void newClipLoadingAsked( const QString& filePath );
void removingClipAsked( const QUuid& uuid );
signals:
void newClipLoaded( Clip* );
void clipRemoved( const QUuid& );
friend class Singleton<Library>;
};
#endif // LIBRARY_H
#include <QtDebug>
#include "MetaDataManager.h"
#include "Library.h"
MetaDataManager::MetaDataManager() : m_renderWidget( NULL )
{
m_mediaPlayer = new LibVLCpp::MediaPlayer();
connect( LibraryWidget::getInstance(), SIGNAL( listViewMediaAdded( Clip* ) ), this, SLOT( listViewMediaAdded( Clip* ) ) );
connect( Library::getInstance(), SIGNAL( newClipLoaded( Clip* ) ),this, SLOT( newClipLoaded( Clip* ) ) );
m_tmpSnapshotFilename = new char[512];
m_renderWidget = new QWidget();
m_mediaPlayer->setDrawable( m_renderWidget->winId() );
......@@ -18,7 +21,7 @@ MetaDataManager::~MetaDataManager()
delete[] m_tmpSnapshotFilename;
}
void MetaDataManager::listViewMediaAdded( Clip* item )
void MetaDataManager::newClipLoaded( Clip* item )
{
m_mediaList.append( item );
......
......@@ -4,8 +4,8 @@
#include <QList>
#include <QTemporaryFile>
#include <QThread>
#include <QWidget>
#include "Clip.h"
#include "LibraryWidget.h"
#include "VLCMediaPlayer.h"
class MetaDataManager : public QThread
......@@ -36,7 +36,7 @@ class MetaDataManager : public QThread
private slots:
void renderSnapshot();
void getMetaData();
void listViewMediaAdded( Clip* );
void newClipLoaded( Clip* );
void setSnapshot();
};
......
......@@ -5,14 +5,14 @@ template <typename T>
class Singleton
{
public:
T* getInstance()
static T* getInstance()
{
if ( m_instance == NULL )
m_instance = new T;
return m_instance;
}
void destroyInstance()
static void destroyInstance()
{
if ( m_instance != NULL )
{
......
......@@ -25,8 +25,6 @@
#include "LibraryWidget.h"
QList<ListViewMediaItem*>* LibraryWidget::m_medias = NULL;
//TODO: please remove me :'(
LibraryWidget* LibraryWidget::m_instance = NULL;
LibraryWidget::LibraryWidget( QWidget *parent ) : QWidget( parent )
{
......@@ -53,12 +51,12 @@ LibraryWidget::~LibraryWidget()
}
}
ListViewMediaItem* LibraryWidget::addMedia( QFileInfo* fileInfo, ListViewMediaItem::fType fileType )
ListViewMediaItem* LibraryWidget::addMedia( const Clip* clip, ListViewMediaItem::fType fileType )
{
ListViewMediaItem* item = new ListViewMediaItem( fileInfo, fileType );
emit listViewMediaAdded( item->getClip() );
ListViewMediaItem* item = new ListViewMediaItem( clip, fileType );
//TODO: replace this :
//emit listViewMediaAdded( item->getClip() );
m_medias->append( item );
m_mediaHash[item->getClip()->getUuid()] = item->getClip();
switch ( fileType )
{
case ListViewMediaItem::Audio:
......@@ -74,41 +72,54 @@ ListViewMediaItem* LibraryWidget::addMedia( QFileInfo* fileInfo, ListViewMediaI
return item;
}
bool LibraryWidget::removeMedia(ListViewMediaItem* item)
void LibraryWidget::clipRemoved( const QUuid& uuid )
{
if ( m_medias->contains( item ) )
removeMedia( uuid );
}
void LibraryWidget::removeMedia( const QUuid& uuid )
{
ListViewMediaItem* item;
foreach (item, *m_medias)
{
switch( item->fileType() )
if ( item->getClip()->getUuid() == uuid )
{
case ListViewMediaItem::Audio:
this->m_ui.listWidgetAudio->removeItemWidget( item );
break;
case ListViewMediaItem::Image:
this->m_ui.listWidgetImage->removeItemWidget( item );
break;
case ListViewMediaItem::Video:
this->m_ui.listWidgetVideo->removeItemWidget( item );
break;
switch( item->fileType() )
{
case ListViewMediaItem::Audio:
this->m_ui.listWidgetAudio->removeItemWidget( item );
break;
case ListViewMediaItem::Image:
this->m_ui.listWidgetImage->removeItemWidget( item );
break;
case ListViewMediaItem::Video:
this->m_ui.listWidgetVideo->removeItemWidget( item );
break;
}
m_medias->removeOne( item );
delete item;
}
bool ret = m_medias->removeOne( item );
delete item;
return ret;
}
return false;
}
ListViewMediaItem* LibraryWidget::insertNewMedia( QString fileName, ListViewMediaItem::fType fileType )
//
//ListViewMediaItem* LibraryWidget::insertNewMedia( QString fileName, ListViewMediaItem::fType fileType )
//{
// ListViewMediaItem* item = NULL;
// foreach( item, *m_medias )
// {
// if ( item->getClip()->getFileInfo()->absoluteFilePath() == fileName )
// return item;
// }
// QFileInfo* fileInfo = new QFileInfo( fileName );
// item = addMedia( fileInfo, fileType );
// delete fileInfo;
// return item;
//}
void LibraryWidget::newClipLoaded( Clip* clip )
{
ListViewMediaItem* item = NULL;
foreach( item, *m_medias )
{
if ( item->getClip()->getFileInfo()->absoluteFilePath() == fileName )
return item;
}
QFileInfo* fileInfo = new QFileInfo( fileName );
item = addMedia( fileInfo, fileType );
delete fileInfo;
return item;
//From here, the clip is const.
addMedia( clip, ListViewMediaItem::Video );
}
void LibraryWidget::insertNewMediasFromFileDialog( QString title, QString filter, ListViewMediaItem::fType filetype )
......@@ -118,13 +129,14 @@ void LibraryWidget::insertNewMediasFromFileDialog( QString title, QString fil
QStringList fileNames = QFileDialog::getOpenFileNames( this, title, path, filter );
if ( fileNames.isEmpty() )
return ;
QString fileName;
ListViewMediaItem* item = NULL;
foreach ( fileName, fileNames )
item = insertNewMedia( fileName, filetype );
if ( item != NULL )
settings.setValue( "mediaLibraryDialogPath" , item->getClip()->getFileInfo()->absoluteDir().absolutePath() );
return ;
QString filePath;
// ListViewMediaItem* item = NULL;
foreach ( filePath, fileNames )
// item = insertNewMedia( fileName, filetype );
emit newClipLoadingAsked( filePath );
// if ( item != NULL )
// settings.setValue( "mediaLibraryDialogPath" , item->getClip()->getFileInfo()->absoluteDir().absolutePath() );
// return ;
}
void LibraryWidget::on_pushButtonAddMedia_clicked()
......@@ -154,7 +166,8 @@ void LibraryWidget::on_pushButtonRemoveMedia_clicked()
{
QListWidget* mediaList = ( QListWidget* )( this->m_ui.LibraryTabs->currentWidget()->children().back() );
ListViewMediaItem* item = ( ListViewMediaItem* ) mediaList->currentItem();
this->removeMedia( item );
// this->removeMedia( item );
emit removingClipAsked( item->getClip()->getUuid() );
}
void LibraryWidget::changeEvent( QEvent *e )
......@@ -168,11 +181,3 @@ void LibraryWidget::changeEvent( QEvent *e )
break;
}
}
Clip* LibraryWidget::getClip( const QUuid& uuid )
{
QHash<QUuid, Clip*>::iterator it = m_mediaHash.find( uuid );
if ( it == m_mediaHash.end() )
return NULL;
return *it;
}
/*****************************************************************************
* LibraryWidget.h: Multimedia library
* LibraryWidget.h: Multimedia library GUI
*****************************************************************************
* Copyright (C) 2008-2009 the VLMC team
*
......@@ -33,35 +33,23 @@
#include <QMimeData>
#include <QDrag>
#include <QList>
#include <QHash>
#include <QUuid>
#include <QSettings>
#include "ListViewMediaItem.h"
#include "ui_LibraryWidget.h"
#include "Clip.h"
#include "Singleton.hpp"
class LibraryWidget : public QWidget//, public Singleton<LibraryWidget>
class LibraryWidget : public QWidget
{
Q_OBJECT
public:
ListViewMediaItem* addMedia( QFileInfo* fileInfo, ListViewMediaItem::fType fileType );
bool removeMedia( ListViewMediaItem* item );
int getIndex( ListViewMediaItem* media );
Clip* getClip( const QUuid& uuid );
explicit LibraryWidget( QWidget *parent = 0 );
virtual ~LibraryWidget();
//Temporary !!!
static LibraryWidget* getInstance( QWidget* parent = NULL )
{
if ( m_instance == NULL )
m_instance = new LibraryWidget( parent );
return m_instance;
}
ListViewMediaItem* addMedia( const Clip* clip, ListViewMediaItem::fType fileType );
void removeMedia( const QUuid& uuid );
int getIndex( ListViewMediaItem* media );
protected:
explicit LibraryWidget( QWidget *parent = 0 );
virtual ~LibraryWidget();
virtual void changeEvent( QEvent *e );
private:
......@@ -70,18 +58,20 @@ private:
Ui::LibraryWidget m_ui;
static QList<ListViewMediaItem*>* m_medias;
QHash<QUuid, Clip*> m_mediaHash;
//TODO: remove the singleton from this class...
static LibraryWidget* m_instance;
//friend class Singleton<LibraryWidget>;
public slots:
void newClipLoaded( Clip* );
void clipRemoved( const QUuid& );
private slots:
void on_pushButtonAddMedia_clicked();
void on_pushButtonRemoveMedia_clicked();
signals:
void listViewMediaAdded(Clip* clip);
// void listViewMediaAdded(Clip* clip);
void newClipLoadingAsked( const QString& );
void removingClipAsked( const QUuid& );
};
#endif /* !LIBRARYWIDGET_H */
......@@ -24,27 +24,28 @@
#include <QPixmap>
#include <QDebug>
ListViewMediaItem::ListViewMediaItem( QFileInfo* fInfo, ListViewMediaItem::fType fType, QListWidget* parent, int type ) :
QListWidgetItem( parent, type ), m_clip( NULL )
ListViewMediaItem::ListViewMediaItem( const Clip* clip, ListViewMediaItem::fType fType, QListWidget* parent, int type ) :
QListWidgetItem( parent, type ), m_clip( clip )
{
m_fileType = fType;
setIcon( QIcon( ":/images/images/vlmc.png") );
setText( fInfo->baseName() );
setText( clip->getFileInfo()->baseName() );
m_renderWidget = new QWidget();
m_clip = new Clip( fInfo );
connect( m_clip, SIGNAL( snapshotChanged() ), this, SLOT( snapshotChanged() ) );
}
ListViewMediaItem::~ListViewMediaItem()
{
if ( m_clip != NULL )
delete m_clip;
}
void ListViewMediaItem::snapshotChanged()
{
setIcon( QIcon( m_clip->getSnapshot() ) );
}
const Clip* ListViewMediaItem::getClip() const
{
return m_clip;
}
......@@ -57,7 +57,7 @@ public:
* \param parent parent widget
* \param type
*/
ListViewMediaItem( QFileInfo* fileInfo, ListViewMediaItem::fType fType, QListWidget* parent = 0, int type = Type );
ListViewMediaItem( const Clip* clip, ListViewMediaItem::fType fType, QListWidget* parent = 0, int type = Type );
/**
* \brief Destructor
......@@ -70,14 +70,7 @@ public:
*/
ListViewMediaItem::fType fileType() { return m_fileType; }
/**
* \brief Get the current media snapshot
* \return the current media snapshot as a QPixmap*, or NULL if there is no current media.
*/
//const QPixmap* getSnapshot() const;
Clip* getClip() { return m_clip; }
const Clip* getClip() const;
//void setInputMedia( InputMedia* inputMedia ) { m_inputMedia = inputMedia; }
......@@ -90,12 +83,7 @@ private:
/**
* \Instance of the InputMedia
*/
Clip* m_clip;
/**
* \brief Instance of the temporary QWidget use for the snapshot
*/
QWidget* m_renderWidget;
const Clip* m_clip;
private slots:
void snapshotChanged();
......
......@@ -24,7 +24,10 @@
#include <QSizePolicy>
#include <QPalette>
#include <QDockWidget>
#include "MainWindow.h"
#include "LibraryWidget.h"
#include "Library.h"
#include "Timeline.h"
#include "About.h"
#include "Transcode.h"
......@@ -61,6 +64,27 @@ void MainWindow::changeEvent( QEvent *e )
}
}