Commit 4fbc0258 authored by Ludovic Fauvet's avatar Ludovic Fauvet

Code cleanup / normalization.

Please do not use 'this' pointer when it isn't required.
parent 2279f2d7
......@@ -20,8 +20,6 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
#ifndef IMAGE_HPP
#define IMAGE_HPP
......@@ -30,29 +28,29 @@
class Image
{
public:
Image(int width, int height)
Image( int width, int height )
{
this->_pixelsData = new uchar[width * height * 4];
this->_image = new QImage(this->_pixelsData, width, height, width * 4, QImage::Format_ARGB32);
m_pixelsData = new uchar[ width * height * 4 ];
m_image = new QImage( m_pixelsData, width, height, width * 4, QImage::Format_ARGB32 );
}
~Image()
{
delete this->_image;
delete this->_pixelsData;
delete m_image;
delete m_pixelsData;
}
uchar* getBuffer()
{
return this->_pixelsData;
return m_pixelsData;
}
QImage& getImage()
{
return *(this->_image);
return *(m_image);
}
private:
QImage* _image;
uchar* _pixelsData;
QImage* m_image;
uchar* m_pixelsData;
};
#endif // IMAGE_HPP
......@@ -25,50 +25,50 @@
using namespace LibVLCpp;
Exception::errorCallback Exception::_errorCallback = NULL;
void* Exception::_datas = NULL;
Exception::errorCallback Exception::m_errorCallback = NULL;
void* Exception::m_datas = NULL;
Exception::Exception()
{
this->_internalPtr = new libvlc_exception_t;
libvlc_exception_init(this->_internalPtr);
m_internalPtr = new libvlc_exception_t;
libvlc_exception_init( m_internalPtr );
}
Exception::~Exception()
{
this->clear();
delete this->_internalPtr;
clear();
delete m_internalPtr;
}
void Exception::setErrorCallback(Exception::errorCallback handler, void* datas)
void Exception::setErrorCallback( Exception::errorCallback handler, void* datas )
{
Exception::_datas = datas;
Exception::_errorCallback = handler;
Exception::m_datas = datas;
Exception::m_errorCallback = handler;
}
const char* Exception::getErrorText() const
{
return libvlc_exception_get_message(this->_internalPtr);
return libvlc_exception_get_message( m_internalPtr );
}
void Exception::clear()
{
libvlc_exception_clear(this->_internalPtr);
libvlc_exception_clear( m_internalPtr );
}
int Exception::raised() const
{
return libvlc_exception_raised(this->_internalPtr);
return libvlc_exception_raised( m_internalPtr );
}
void Exception::checkThrow()
{
if (this->raised() == Exception::Raised)
if ( raised() == Exception::Raised )
{
if (Exception::_errorCallback != NULL)
Exception::_errorCallback(this->getErrorText(), Exception::_datas);
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: " << this->getErrorText();
this->clear();
qWarning() << "An exception was raised, but no error handler is set.\nError message is: " << getErrorText();
clear();
}
}
......@@ -28,7 +28,7 @@
namespace LibVLCpp
{
class Exception : public Internal<libvlc_exception_t>
class Exception : public Internal< libvlc_exception_t >
{
public:
Exception();
......@@ -44,12 +44,12 @@ namespace LibVLCpp
//error handling part :
//TODO: have a private error handling in which we could fall back for some specific cases
typedef void (*errorCallback)(const char* msg, void* data);
static void setErrorCallback(errorCallback, void* data);
typedef void (*errorCallback)( const char* msg, void* data );
static void setErrorCallback( errorCallback, void* data );
private:
static errorCallback _errorCallback;
static void* _datas;
static errorCallback m_errorCallback;
static void* m_datas;
};
}
......
......@@ -26,8 +26,8 @@
using namespace LibVLCpp;
Instance::Instance(int argc, const char** argv)
Instance::Instance( int argc, const char** argv )
{
this->_internalPtr = libvlc_new(argc, argv, this->_ex);
this->_ex.checkThrow();
m_internalPtr = libvlc_new( argc, argv, m_ex );
m_ex.checkThrow();
}
......@@ -29,12 +29,12 @@
namespace LibVLCpp
{
class Instance : public Internal<libvlc_instance_t>
class Instance : public Internal< libvlc_instance_t >
{
public:
Instance(int argc, const char** argv);
Instance( int argc, const char** argv );
private:
Exception _ex;
Exception m_ex;
};
}
......
......@@ -26,17 +26,17 @@
using namespace LibVLCpp;
Media::Media(Instance* instance, const QString& filename) : _instance(*instance), _pixelBuffer(NULL)
Media::Media( Instance* instance, const QString& filename ) : m_instance( *instance ), m_pixelBuffer( NULL )
{
this->_internalPtr = libvlc_media_new(this->_instance, filename.toLocal8Bit(), this->_ex);
this->_ex.checkThrow();
m_internalPtr = libvlc_media_new( m_instance, filename.toLocal8Bit(), m_ex );
m_ex.checkThrow();
}
Media::~Media()
{
libvlc_media_release(this->_internalPtr);
delete[] this->_pixelBuffer;
delete this->_dataCtx;
libvlc_media_release( m_internalPtr );
delete[] m_pixelBuffer;
delete m_dataCtx;
}
Media::DataCtx* Media::buildDataCtx()
......@@ -47,47 +47,47 @@ Media::DataCtx* Media::buildDataCtx()
return dataCtx;
}
void Media::addOption(const char* opt)
void Media::addOption( const char* opt )
{
libvlc_media_add_option(this->_internalPtr, opt, this->_ex);
this->_ex.checkThrow();
libvlc_media_add_option( m_internalPtr, opt, m_ex);
m_ex.checkThrow();
qDebug() << "Added media option: " << opt;
}
Media::DataCtx::~DataCtx()
{
delete this->mutex;
delete mutex;
}
void Media::setLockCallback(Media::lockCallback callback)
void Media::setLockCallback( Media::lockCallback callback )
{
char param[64];
sprintf(param, ":vmem-lock=%lld", (long long int)(intptr_t)callback);
this->addOption(param);
sprintf( param, ":vmem-lock=%lld", (long long int)(intptr_t)callback );
addOption(param);
}
void Media::setUnlockCallback(Media::unlockCallback callback)
void Media::setUnlockCallback( Media::unlockCallback callback )
{
char param[64];
sprintf(param, ":vmem-unlock=%lld", (long long int)(intptr_t)callback);
this->addOption(param);
sprintf( param, ":vmem-unlock=%lld", (long long int)(intptr_t)callback );
addOption( param );
}
void Media::setDataCtx()
{
char param[64];
this->_dataCtx = new Media::DataCtx;
this->_dataCtx->mutex = new QMutex();
this->_dataCtx->media = this;
m_dataCtx = new Media::DataCtx;
m_dataCtx->mutex = new QMutex();
m_dataCtx->media = this;
sprintf(param, ":vmem-data=%lld", (long long int)(intptr_t)this->_dataCtx);
this->addOption(param);
sprintf( param, ":vmem-data=%lld", (long long int)(intptr_t)m_dataCtx );
addOption( param );
}
void Media::outputInVmem()
{
this->addOption(":vout=vmem");
addOption( ":vout=vmem" );
}
void Media::outputInWindow()
......@@ -95,12 +95,12 @@ void Media::outputInWindow()
// this->addOption();
}
void Media::setPixelBuffer(uchar* buffer)
void Media::setPixelBuffer( uchar* buffer )
{
this->_pixelBuffer = buffer;
m_pixelBuffer = buffer;
}
uchar* Media::getPixelBuffer()
{
return this->_pixelBuffer;
return m_pixelBuffer;
}
......@@ -37,7 +37,7 @@
namespace LibVLCpp
{
class Media : public Internal<libvlc_media_t>
class Media : public Internal< libvlc_media_t >
{
public:
struct DataCtx
......@@ -46,27 +46,27 @@ namespace LibVLCpp
QMutex* mutex;
Media* media;
};
typedef void (*lockCallback)(Media::DataCtx* dataCtx, void **pp_ret);
typedef void (*unlockCallback)(Media::DataCtx* dataCtx);
typedef void (*lockCallback)( Media::DataCtx* dataCtx, void **pp_ret );
typedef void (*unlockCallback)( Media::DataCtx* dataCtx );
Media(Instance* instance, const QString& filename);
Media( Instance* instance, const QString& filename );
~Media();
void addOption(const char* opt);
void setLockCallback(Media::lockCallback);
void setUnlockCallback(Media::unlockCallback);
void addOption( const char* opt );
void setLockCallback( Media::lockCallback );
void setUnlockCallback( Media::unlockCallback );
void setDataCtx();
void outputInVmem();
void outputInWindow();
void setPixelBuffer(uchar* buffer);
void setPixelBuffer( uchar* buffer );
uchar* getPixelBuffer();
private:
DataCtx* buildDataCtx();
Exception _ex;
Instance& _instance;
DataCtx* _dataCtx;
uchar* _pixelBuffer;
Exception m_ex;
Instance& m_instance;
DataCtx* m_dataCtx;
uchar* m_pixelBuffer;
};
}
......
......@@ -26,68 +26,68 @@
using namespace LibVLCpp;
MediaPlayer::MediaPlayer(Media* media, bool playStop /* = true*/)
MediaPlayer::MediaPlayer( Media* media, bool playStop /* = true*/ )
{
this->_internalPtr = libvlc_media_player_new_from_media(media->getInternalPtr(), this->_ex);
this->_ex.checkThrow();
m_internalPtr = libvlc_media_player_new_from_media( media->getInternalPtr(), m_ex );
m_ex.checkThrow();
}
void MediaPlayer::play()
{
libvlc_media_player_play(this->_internalPtr, this->_ex);
this->_ex.checkThrow();
libvlc_media_player_play( m_internalPtr, m_ex );
m_ex.checkThrow();
}
void MediaPlayer::pause()
{
libvlc_media_player_pause(this->_internalPtr, this->_ex);
this->_ex.checkThrow();
libvlc_media_player_pause( m_internalPtr, m_ex );
m_ex.checkThrow();
}
void MediaPlayer::stop()
{
libvlc_media_player_stop(this->_internalPtr, this->_ex);
this->_ex.checkThrow();
libvlc_media_player_stop( m_internalPtr, m_ex );
m_ex.checkThrow();
}
qint64 MediaPlayer::getTime()
{
qint64 t = libvlc_media_player_get_time(this->_internalPtr, this->_ex);
this->_ex.checkThrow();
qint64 t = libvlc_media_player_get_time( m_internalPtr, m_ex );
m_ex.checkThrow();
return t;
}
void MediaPlayer::setTime(qint64 time)
void MediaPlayer::setTime( qint64 time )
{
// qDebug() << "Setting media time to " << time;
libvlc_media_player_set_time(this->_internalPtr, time, this->_ex);
this->_ex.checkThrow();
libvlc_media_player_set_time( m_internalPtr, time, m_ex );
m_ex.checkThrow();
}
qint64 MediaPlayer::getLength()
{
qint64 length = libvlc_media_player_get_length(this->_internalPtr, this->_ex);
this->_ex.checkThrow();
qint64 length = libvlc_media_player_get_length( m_internalPtr, m_ex );
m_ex.checkThrow();
// qDebug() << "Media length: " << length;
return length;
}
void MediaPlayer::takeSnapshot(char* outputFile, unsigned int width, unsigned int heigth)
void MediaPlayer::takeSnapshot( char* outputFile, unsigned int width, unsigned int heigth )
{
libvlc_video_take_snapshot(*this, outputFile, width, heigth, this->_ex);
this->_ex.checkThrow();
libvlc_video_take_snapshot( *this, outputFile, width, heigth, m_ex);
m_ex.checkThrow();
}
bool MediaPlayer::isPlaying()
{
int res = libvlc_media_player_is_playing(this->_internalPtr, this->_ex);
this->_ex.checkThrow();
int res = libvlc_media_player_is_playing( m_internalPtr, m_ex );
m_ex.checkThrow();
return (res == 1);
}
bool MediaPlayer::isSeekable()
{
int res = libvlc_media_player_is_seekable(this->_internalPtr, this->_ex);
this->_ex.checkThrow();
int res = libvlc_media_player_is_seekable( m_internalPtr, m_ex );
m_ex.checkThrow();
return (res == 1);
}
......@@ -33,22 +33,22 @@
namespace LibVLCpp
{
class MediaPlayer : public Internal<libvlc_media_player_t>
class MediaPlayer : public Internal< libvlc_media_player_t >
{
public:
MediaPlayer(Media* media, bool playStop = true);
MediaPlayer( Media* media, bool playStop = true );
void play();
void pause();
void stop();
qint64 getTime();
void setTime(qint64 time);
void setTime( qint64 time );
qint64 getLength();
void takeSnapshot(char* outputFile, unsigned int width, unsigned int heigth);
void takeSnapshot( char* outputFile, unsigned int width, unsigned int heigth );
bool isPlaying();
bool isSeekable();
private:
Exception _ex;
Exception m_ex;
};
}
......
......@@ -28,21 +28,21 @@
namespace LibVLCpp
{
template <typename T>
template < typename T >
class Internal
{
public:
typedef T* internalPtr;
T* getInternalPtr()
{
assert(this->_internalPtr != NULL);
return this->_internalPtr;
assert( m_internalPtr != NULL );
return m_internalPtr;
}
operator T*() {return this->_internalPtr;}
operator T*() { return m_internalPtr; }
protected:
Internal() : _internalPtr(NULL) {}
Internal() : m_internalPtr( NULL ) {}
T* _internalPtr;
T* m_internalPtr;
};
}
......
......@@ -3,25 +3,25 @@
using namespace LibVLCpp;
VlmManager::VlmManager(Instance* instance) : _instance(*instance)
VlmManager::VlmManager( Instance* instance ) : m_instance( *instance )
{
}
VlmMedia* VlmManager::addMedia(const QString& filename, const char* const* argv, int argc)
VlmMedia* VlmManager::addMedia( const QString& filename, const char* const* argv, int argc )
{
VlmMedia* media = new VlmMedia(this->_instance, filename);
VlmMedia* media = new VlmMedia( m_instance, filename );
libvlc_vlm_add_broadcast(this->_instance, media->getHash().toLocal8Bit(), filename.toLocal8Bit(),
libvlc_vlm_add_broadcast( m_instance, media->getHash().toLocal8Bit(), filename.toLocal8Bit(),
"#duplicate{dst=display{vmem}}",
argc, argv, true, false, this->_ex);
this->_ex.checkThrow();
this->_hashTable[media->getHash()] = media;
argc, argv, true, false, m_ex );
m_ex.checkThrow();
m_hashTable[ media->getHash() ] = media;
return media;
}
VlmMedia* VlmManager::getMedia(const QString& hash)
VlmMedia* VlmManager::getMedia( const QString& hash )
{
if ( this->_hashTable.contains(hash) == true )
return this->_hashTable[hash];
if ( m_hashTable.contains( hash ) )
return m_hashTable[ hash ];
return NULL;
}
......@@ -13,14 +13,14 @@ namespace LibVLCpp
class VlmManager
{
public:
VlmManager(Instance* instance);
VlmManager( Instance* instance );
VlmMedia* addMedia(const QString& filename, const char* const* argv, int argc);
VlmMedia* getMedia(const QString& hash);
VlmMedia* addMedia( const QString& filename, const char* const* argv, int argc );
VlmMedia* getMedia( const QString& hash );
private:
QHash<QString, VlmMedia*> _hashTable;
Instance& _instance;
Exception _ex;
QHash< QString, VlmMedia* > m_hashTable;
Instance& m_instance;
Exception m_ex;
};
}
......
......@@ -24,7 +24,7 @@
#include "Media.h"
Media::Media(const QString& mrl) : _mrl(mrl), _snapshot(NULL)
Media::Media( const QString& mrl ) : m_mrl( mrl ), m_snapshot( NULL )
{
char const *vlc_argv[] =
{
......@@ -34,88 +34,88 @@ Media::Media(const QString& mrl) : _mrl(mrl), _snapshot(NULL)
//"--plugin-path", VLC_TREE "/modules",
//"--ignore-config", /* Don't use VLC's config files */
};
int vlc_argc = sizeof(vlc_argv) / sizeof(*vlc_argv);
this->_instance = new LibVLCpp::Instance(vlc_argc, vlc_argv);
int vlc_argc = sizeof( vlc_argv ) / sizeof( *vlc_argv );
m_instance = new LibVLCpp::Instance( vlc_argc, vlc_argv );
this->_vlcMedia = new LibVLCpp::Media(this->_instance, this->_mrl);
m_vlcMedia = new LibVLCpp::Media( m_instance, m_mrl );
this->_vlcMedia->outputInVmem();
this->_vlcMedia->setLockCallback(Media::lock);
this->_vlcMedia->setUnlockCallback(Media::unlock);
m_vlcMedia->outputInVmem();
m_vlcMedia->setLockCallback( Media::lock );
m_vlcMedia->setUnlockCallback( Media::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);
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 );
this->_vlcMedia->addOption(width);
this->_vlcMedia->addOption(height);
this->_vlcMedia->addOption(chroma);
this->_vlcMedia->addOption(pitch);
m_vlcMedia->addOption( width );
m_vlcMedia->addOption( height );
m_vlcMedia->addOption( chroma );
m_vlcMedia->addOption( pitch );
this->_pixelBuffer = new uchar[VIDEOHEIGHT * VIDEOWIDTH * 4];
this->_image = new QImage(this->_pixelBuffer, VIDEOWIDTH, VIDEOHEIGHT, VIDEOWIDTH * 4, QImage::Format_RGB32);
this->_image->fill(0);
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"
this->_vlcMedia->setPixelBuffer(this->_pixelBuffer);
this->_vlcMedia->setDataCtx();
m_vlcMedia->setPixelBuffer( m_pixelBuffer );
m_vlcMedia->setDataCtx();
//And now we play the media
this->_vlcMediaPlayer = new LibVLCpp::MediaPlayer(this->_vlcMedia);
m_vlcMediaPlayer = new LibVLCpp::MediaPlayer( m_vlcMedia );
}
Media::~Media()
{
delete this->_image;
delete this->_pixelBuffer;
delete this->_vlcMedia;
delete this->_vlcMediaPlayer;
delete this->_instance;
delete m_image;
delete m_pixelBuffer;
delete m_vlcMedia;
delete m_vlcMediaPlayer;
delete m_instance;
}
void Media::lock(LibVLCpp::Media::DataCtx* ctx, void **renderPtr)
void Media::lock( LibVLCpp::Media::DataCtx* ctx, void **renderPtr )
{
ctx->mutex->lock();
*renderPtr = ctx->media->getPixelBuffer();
}
void Media::unlock(LibVLCpp::Media::DataCtx* ctx)
void Media::unlock( LibVLCpp::Media::DataCtx* ctx )
{
// qDebug() << "frame just rendered";
ctx->mutex->unlock();
}
QImage* Media::takeSnapshot(unsigned int width, unsigned int height)
QImage* Media::takeSnapshot( unsigned int width, unsigned int height )
{
//FIXME
//this isn't working, but it seems like a vlc problem, since lastest release of vlc segfault when a screenshot is taken... -_-
return NULL;
if ( this->_snapshot == NULL )
if ( m_snapshot == NULL )
{
qDebug() << "trying to take a snapshot";
this->_vlcMediaPlayer->takeSnapshot("/tmp/vlmcscreenshot.tmp.gif", width, height);
m_vlcMediaPlayer->takeSnapshot( "/tmp/vlmcscreenshot.tmp.gif", width, height );
qDebug() << "done snapshoting";
this->_snapshot = new QImage("/tmp/vlmcscreenshot.tmp.gif");
m_snapshot = new QImage( "/tmp/vlmcscreenshot.tmp.gif" );
qDebug() << "written to a QImage";
}
return this->_snapshot;
return m_snapshot;
}
bool Media::isPlaying()
{
return this->_vlcMediaPlayer->isPlaying();
return m_vlcMediaPlayer->isPlaying();
}
bool Media::isSeekable()
{
return this->_vlcMediaPlayer->isSeekable();
return m_vlcMediaPlayer->isSeekable();
}
qint64 Media::getLength()
{
return this->_vlcMediaPlayer->getLength();
return m_vlcMediaPlayer->getLength();
}
......@@ -35,13 +35,13 @@
class Media
{
public:
Media(const QString& mrl);
Media( const QString& mrl );
~Media();
static void lock(LibVLCpp::Media::DataCtx* dataCtx, void **pp_ret);
static void unlock(LibVLCpp::Media::DataCtx* dataCtx);
static void lock( LibVLCpp::Media::DataCtx* dataCtx, void **pp_ret );
static void unlock( LibVLCpp::Media::DataCtx* dataCtx );
QImage* takeSnapshot(unsigned int width, unsigned int heigth);
QImage* takeSnapshot( unsigned int width, unsigned int heigth );
bool isPlaying();
bool isSeekable();
......@@ -49,15 +49,13 @@ public:
QImage& getImage();
private:
LibVLCpp::Media* _vlcMedia;
LibVLCpp::MediaPlayer* _vlcMediaPlayer;
LibVLCpp::Instance* _instance;
QString _mrl;
QImage* _snapshot;