Commit 4ee7255c authored by Hugo Beauzee-Luyssen's avatar Hugo Beauzee-Luyssen

Started a big refactoring. This compiles, but probably don't work...

it will on next commit.
We don't use Media / [Input|Output]Media anymore.
parent bad4c91b
/*****************************************************************************
* InputMedia.h: Class for media handling
* Clip.cpp: Represents a basic container for media informations.
*****************************************************************************
* Copyright (C) 2008-2009 the VLMC team
*
......@@ -20,53 +20,56 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
#include <QtDebug>
#include "Clip.h"
#ifndef INPUTMEDIA_H
#define INPUTMEDIA_H
#include <QString>
#include <QImage>
#include "Media.h"
#include "VLCMediaPlayer.h"
#include "Image.h"
class InputMedia : public Media
Clip::Clip( const QString& mrl )
: m_vlcMedia( NULL ), m_mrl( mrl ), m_snapshot( NULL )
{
Q_OBJECT
public:
InputMedia( const QString& mrl, LibVLCpp::Instance* instance = NULL );
~InputMedia();
static void lock( LibVLCpp::Media::DataCtx* dataCtx, void **pp_ret );
static void unlock( LibVLCpp::Media::DataCtx* dataCtx );
m_instance = LibVLCpp::Instance::getInstance();
m_vlcMedia = new LibVLCpp::Media( m_instance, mrl );
}
//QPixmap* takeSnapshot( unsigned int width, unsigned int heigth );
Clip::~Clip()
{
if ( m_vlcMedia )
{
delete m_vlcMedia;
}
}
/**
* Ask libvlc if the media can be seeked
*/
bool isSeekable();
/**
* Can be used to know if the Media is fully usable (IE. can be seeked, vmem can be used, etc...)
*/
bool isReady();
void Clip::loadMedia( const QString& mrl )
{
if ( m_vlcMedia )
delete m_vlcMedia;
m_mrl = mrl;
/**
* Returns the last rendered frame
*/
QImage& getImage();
m_vlcMedia = new LibVLCpp::Media( m_instance, mrl );
}
virtual void play();
virtual void pause();
virtual void stop();
void Clip::setupMedia()
{
//Flushing the args into the media :
QString param;
foreach ( param, m_parameters )
m_vlcMedia->addOption( param.toStdString().c_str() );
}
private:
uchar* m_pixelBuffer;
QImage* m_image;
void Clip::addParam( const QString& param )
{
m_parameters.append( param );
}
};
void Clip::setSnapshot( QPixmap* snapshot )
{
//TODO: check for mem leaks.
m_snapshot = snapshot;
}
#endif // INPUTMEDIA_H
const QPixmap& Clip::getSnapshot() const
{
if ( m_snapshot )
return *m_snapshot;
//TODO: instanciate this as a static pixmap
return QPixmap( ":/images/images/vlmc.png" );
}
/*****************************************************************************
* OutputMedia.h: Class for outpouting a media from a VMEM
* Clip.h : Represents a basic container for media informations.
*****************************************************************************
* Copyright (C) 2008-2009 the VLMC team
*
......@@ -20,33 +20,39 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
#ifndef OUTPUTMEDIA_H
#define OUTPUTMEDIA_H
#ifndef CLIP_H__
#define CLIP_H__
#include "Media.h"
#include <QList>
#include <QString>
#include <QPixmap>
class OutputMedia : public Media
#include "VLCMedia.h"
/**
* Represents a basic container for media informations.
*/
class Clip
{
public:
struct DataCtx
{
~DataCtx();
QMutex* mutex;
OutputMedia* outputMedia;
};
OutputMedia( LibVLCpp::Instance* instance );
virtual ~OutputMedia();
static uchar* lock( OutputMedia::DataCtx* dataCtx );
static void unlock( OutputMedia::DataCtx* dataCtx );
void setVmem( uchar* pixelBuffer );
virtual void play();
private:
OutputMedia::DataCtx* m_dataCtx;
uchar* m_pixelBuffer;
Clip( const QString& mrl );
virtual ~Clip();
void loadMedia( const QString& mrl );
void addParam( const QString& param );
void setupMedia();
LibVLCpp::Media* getVLCMedia() { return m_vlcMedia; }
void setSnapshot( QPixmap* snapshot );
const QPixmap& getSnapshot() const;
protected:
//TODO: is this really usefull now ?!
LibVLCpp::Instance* m_instance;
LibVLCpp::Media* m_vlcMedia;
QString m_mrl;
QList<QString> m_parameters;
QPixmap* m_snapshot;
};
#endif // OUTPUTMEDIA_H
#endif // MEDIA_H
/*****************************************************************************
* InputMedia.cpp: Class for media handling
*****************************************************************************
* 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 <QTemporaryFile>
#include "InputMedia.h"
InputMedia::InputMedia( const QString& mrl, LibVLCpp::Instance* instance /*= NULL*/ ) :
Media( instance, mrl ), m_pixelBuffer( NULL ), m_image ( NULL )
{
// m_vlcMedia->outputInVmem();
// m_vlcMedia->setLockCallback( InputMedia::lock );
// m_vlcMedia->setUnlockCallback( InputMedia::unlock );
char width[64], height[64], chroma[64], pitch[64];
sprintf( width, ":vmem-width=%i", VIDEOWIDTH );
sprintf( height, ":vmem-height=%i", VIDEOHEIGHT );
sprintf( chroma, ":vmem-chroma=%s", "RV32" );
sprintf( pitch, ":vmem-pitch=%i", VIDEOWIDTH * 4 );
// m_vlcMedia->addOption( width );
// m_vlcMedia->addOption( height );
// m_vlcMedia->addOption( chroma );
// m_vlcMedia->addOption( pitch );
// m_pixelBuffer = new uchar[ VIDEOHEIGHT * VIDEOWIDTH * 4 ];
// m_image = new QImage( m_pixelBuffer, VIDEOWIDTH, VIDEOHEIGHT, VIDEOWIDTH * 4, QImage::Format_RGB32 );
// m_image->fill( 0 );
//Once we got the pixel buffer up and running, we can put it in the "render context"
// m_vlcMedia->setPixelBuffer( m_pixelBuffer );
// m_vlcMedia->setDataCtx();
}
InputMedia::~InputMedia()
{
if ( m_image != NULL )
delete m_image;
if ( m_pixelBuffer != NULL)
delete m_pixelBuffer;
}
void InputMedia::lock( LibVLCpp::Media::DataCtx* ctx, void **renderPtr )
{
ctx->mutex->lock();
*renderPtr = ctx->media->getPixelBuffer();
}
void InputMedia::unlock( LibVLCpp::Media::DataCtx* ctx )
{
//qDebug() << "frame just rendered";
ctx->mutex->unlock();
}
//QPixmap* InputMedia::takeSnapshot( unsigned int width, unsigned int height )
//{
//// qint64 currentTime = m_vlcMediaPlayer->getTime();
//// qint64 length = getLength();
//// qDebug() << currentTime << length;
//// m_vlcMediaPlayer->setTime(length / 2);
//
//
//// qDebug() << "trying to take a snapshot";
// QTemporaryFile tmp;
// tmp.open();
// char* tmpStr = const_cast<char*>(tmp.fileName().toStdString().c_str());
// m_vlcMediaPlayer->takeSnapshot( tmpStr, width, height );
//// qDebug() << "done snapshoting";
// return new QPixmap( tmp.fileName() );
//// qDebug() << "written to a QImage";
//// m_vlcMediaPlayer->setTime(currentTime);
//}
bool InputMedia::isSeekable()
{
return m_vlcMediaPlayer->isSeekable();
}
QImage& InputMedia::getImage()
{
return *m_image;
}
void InputMedia::play()
{
Media::play();
}
void InputMedia::pause()
{
Media::pause();
}
void InputMedia::stop()
{
Media::stop();
}
bool InputMedia::isReady()
{
if (m_vlcMediaPlayer->isPlaying() && m_vlcMediaPlayer->isSeekable())
return true;
return false;
}
......@@ -45,7 +45,7 @@ MediaPlayer::MediaPlayer()
libvlc_event_attach( p_em, libvlc_MediaPlayerPositionChanged, callbacks, this, m_ex );
}
MediaPlayer::MediaPlayer( Media* media, bool playStop /* = true*/ )
MediaPlayer::MediaPlayer( Media* media )
{
m_internalPtr = libvlc_media_player_new_from_media( media->getInternalPtr(), m_ex );
m_ex.checkThrow();
......
......@@ -39,7 +39,7 @@ namespace LibVLCpp
Q_OBJECT
public:
MediaPlayer();
MediaPlayer( Media* media, bool playStop = true );
MediaPlayer( Media* media );
void play();
void pause();
void stop();
......
/*****************************************************************************
* Media.cpp: Generic class for media handling
*****************************************************************************
* 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 "Media.h"
Media::Media(LibVLCpp::Instance* instance, const QString& mrl )
: m_instance( NULL ), m_vlcMedia( NULL ), m_vlcMediaPlayer( NULL ),
m_mrl( mrl ), m_snapshot( NULL ), m_instanceOwned( false )
{
if ( !instance )
{
char const *vlc_argv[] =
{
//"-vvvvv",
"--no-skip-frames",
"--no-audio",
//"--plugin-path", VLC_TREE "/modules",
//"--ignore-config", //Don't use VLC's config files
};
int vlc_argc = sizeof( vlc_argv ) / sizeof( *vlc_argv );
instance = LibVLCpp::Instance::getNewInstance( vlc_argc, vlc_argv );
m_instanceOwned = true;
}
m_instance = instance;
m_vlcMedia = new LibVLCpp::Media( m_instance, mrl );
}
Media::~Media()
{
if ( m_instance && m_instanceOwned == true )
{
delete m_instance;
}
if ( m_vlcMedia )
{
delete m_vlcMedia;
}
if ( m_vlcMediaPlayer )
{
delete m_vlcMediaPlayer;
}
}
void Media::loadMedia( const QString& mrl )
{
if ( m_vlcMedia )
delete m_vlcMedia;
m_mrl = mrl;
m_vlcMedia = new LibVLCpp::Media( m_instance, mrl );
}
void Media::setupMedia()
{
// if ( m_vlcMediaPlayer )
// delete m_vlcMediaPlayer;
//Flushing the args into the media :
QString param;
foreach ( param, m_parameters )
m_vlcMedia->addOption( param.toStdString().c_str() );
// m_vlcMediaPlayer = new LibVLCpp::MediaPlayer( m_vlcMedia );
}
void Media::play()
{
if ( !m_vlcMediaPlayer )
setupMedia();
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 );
}
void Media::setDrawable( WId handle )
{
m_vlcMediaPlayer->setDrawable( handle );
}
qint64 Media::getLength()
{
return m_vlcMediaPlayer->getLength();
}
qint64 Media::getTime()
{
return m_vlcMediaPlayer->getTime();
}
void Media::setTime( qint64 time )
{
m_vlcMediaPlayer->setTime( time );
}
bool Media::isPlaying()
{
return m_vlcMediaPlayer->isPlaying();
}
float Media::getPosition()
{
return m_vlcMediaPlayer->getPosition();
}
void Media::setPosition( float pos )
{
m_vlcMediaPlayer->setPosition( pos );
}
void Media::setSnapshot( QPixmap* snapshot )
{
//TODO: check for mem leaks.
m_snapshot = snapshot;
}
const QPixmap& Media::getSnapshot() const
{
if ( m_snapshot )
return *m_snapshot;
//TODO: instanciate this as a static pixmap
return QPixmap( ":/images/images/vlmc.png" );
}
/*****************************************************************************
* Media.h : Generic class for media handling
*****************************************************************************
* 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 MEDIA_H
#define MEDIA_H
#include <QList>
#include <QString>
#include <QWidget>
#include "VLCMedia.h"
#include "VLCInstance.h"
#include "VLCMediaPlayer.h"
/**
* Generic class for media handling.
*/
class Media : public QObject
{
public:
virtual ~Media();
void loadMedia( const QString& mrl );
virtual void play();
virtual void pause();
virtual void stop();
void addParam( const QString& param );
void setupMedia();
void setDrawable( WId handle );
LibVLCpp::MediaPlayer* mediaPlayer() { return m_vlcMediaPlayer; }
LibVLCpp::Media* getVLCMedia() { return m_vlcMedia; }
void setMediaPlayer( LibVLCpp::MediaPlayer* mediaPlayer ) { m_vlcMediaPlayer = mediaPlayer; }
/**
* Return the length (duration) of a Media
*/
qint64 getLength();
/**
* Return the current time of the media
*/
qint64 getTime();
/**
* Change the current time of the media
*/
void setTime( qint64 time );
/**
* Ask libvlc if the media is currently playing
*/
virtual bool isPlaying();
/**
* Return the current position in the media as a float.
*/
float getPosition();
/**
* Set the current position in the media as a float.
*/
void setPosition( float pos );
void setSnapshot( QPixmap* snapshot );
const QPixmap& getSnapshot() const;
protected:
//Protected constructor so we can't use a Media without its sub-implementation
Media( LibVLCpp::Instance* instance, const QString& mrl );
LibVLCpp::Instance* m_instance;
LibVLCpp::Media* m_vlcMedia;
LibVLCpp::MediaPlayer* m_vlcMediaPlayer;
QString m_mrl;
QList<QString> m_parameters;
QPixmap* m_snapshot;
private:
bool m_instanceOwned;
};
#endif // MEDIA_H
......@@ -21,8 +21,9 @@ void MetaDataManager::listViewMediaAdded( ListViewMediaItem* item )
{
m_mediaList.append( item );
if ( !isRunning() )
start();
//TODO: relaunch the thread after refactoring
// if ( !isRunning() )
// start();
}
void MetaDataManager::run()
......@@ -41,13 +42,8 @@ void MetaDataManager::run()
m_currentMediaItem = m_mediaList.front();
m_mediaList.pop_front();
m_currentMediaItem->getInputMedia()->setMediaPlayer( m_mediaPlayer );
m_mediaPlayer->setMedia( m_currentMediaItem->getInputMedia()->getVLCMedia() );
connect( m_mediaPlayer, SIGNAL( playing() ), this, SLOT( renderSnapshot() ) );
m_mediaPlayer->play();
//TODO: launch (play) the media and connect the MediaPlayer "playing" signal to the renderSnapshot slot.
}
usleep( 100 );
}
......@@ -56,7 +52,7 @@ void MetaDataManager::run()
void MetaDataManager::renderSnapshot()
{
m_currentMediaItem->getInputMedia()->setTime( m_currentMediaItem->getInputMedia()->getLength() / 3 );
//TODO: set the position to 1/3 of the video length
QTemporaryFile tmp;
tmp.setAutoRemove( false );
......@@ -74,8 +70,7 @@ void MetaDataManager::renderSnapshot()
void MetaDataManager::setSnapshotInIcon()
{
m_currentMediaItem->getInputMedia()->setSnapshot( new QPixmap( m_tmpSnapshotFilename ) );
m_currentMediaItem->setIcon( QIcon( m_currentMediaItem->getInputMedia()->getSnapshot() ) );
//TODO: Set the media icon from the snapshot.
m_nextMedia = true;
disconnect( this, SLOT( setSnapshotInIcon() ) );
m_mediaPlayer->stop();
......
/*****************************************************************************
* OutputMedia.cpp: Class for outpouting a media from a VMEM
*****************************************************************************
* 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 "OutputMedia.h"
OutputMedia::OutputMedia( LibVLCpp::Instance* instance ) : Media( instance, "fake://" ), m_dataCtx( NULL ), m_pixelBuffer( NULL )
{
// m_dataCtx = new OutputMedia::DataCtx;
// m_dataCtx->mutex = new QMutex;
// m_dataCtx->outputMedia = this;
char width[64], height[64], lock[64], unlock[64], data[64];
sprintf( width, ":invmem-width=%i", VIDEOWIDTH );
sprintf( height, ":invmem-height=%i", VIDEOHEIGHT );
sprintf( lock, ":invmem-lock=%lld", (qint64)(intptr_t)&OutputMedia::lock );
sprintf( unlock, ":invmem-unlock=%lld", (qint64)(intptr_t)&OutputMedia::unlock );
sprintf( data, ":invmem-data=%lld", (qint64)(intptr_t)m_dataCtx );
// addParam( width );
// addParam( height );
// addParam( lock );
// addParam( unlock );