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

Started c++ binding

parent 5a9150d6
#include <QtDebug>
#include "VLCException.h"
using namespace LibVLCpp;
Exception::errorCallback Exception::_errorCallback = NULL;
void* Exception::_datas = NULL;
Exception::Exception()
{
this->_internalPtr = new libvlc_exception_t;
libvlc_exception_init(this->_internalPtr);
}
Exception::~Exception()
{
this->clear();
delete this->_internalPtr;
}
void Exception::setErrorCallback(Exception::errorCallback handler, void* datas)
{
Exception::_datas = datas;
Exception::_errorCallback = handler;
}
const char* Exception::getErrorText() const
{
return libvlc_exception_get_message(this->_internalPtr);
}
void Exception::clear()
{
libvlc_exception_clear(this->_internalPtr);
}
int Exception::raised() const
{
return libvlc_exception_raised(this->_internalPtr);
}
void Exception::checkThrow()
{
if (this->raised() == Exception::Raised)
{
if (Exception::_errorCallback != NULL)
Exception::_errorCallback(this->getErrorText(), Exception::_datas);
else
qWarning() << "An exception was raised, but no error handler is set.\nError message is: " << this->getErrorText();
this->clear();
}
}
#ifndef VLCEXCEPTION_H
#define VLCEXCEPTION_H
#include "vlc/vlc.h"
#include "VLCpp.hpp"
namespace LibVLCpp
{
class Exception : public Internal<libvlc_exception_t>
{
public:
Exception();
~Exception();
const char* getErrorText() const;
void clear();
int raised() const;
void checkThrow();
static const int Raised = 1;
static const int NotRaised = 0;
//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);
private:
static errorCallback _errorCallback;
static void* _datas;
};
}
#endif // VLCEXCEPTION_H
#include <cassert>
#include "VLCInstance.h"
#include <QtDebug>
using namespace LibVLCpp;
Instance::Instance(int argc, const char** argv)
{
this->_internalPtr = libvlc_new(argc, argv, this->_ex);
this->_ex.checkThrow();
}
#ifndef VLCINSTANCE_H
#define VLCINSTANCE_H
#include "vlc/vlc.h"
#include "VLCpp.hpp"
#include "VLCException.h"
namespace LibVLCpp
{
class Instance : public Internal<libvlc_instance_t>
{
public:
Instance(int argc, const char** argv);
private:
Exception _ex;
};
}
#endif // VLCINSTANCE_H
#ifndef VLCPP_H
#define VLCPP_H
#include <cassert>
#include <stdlib.h>
namespace LibVLCpp
{
template <typename T>
class Internal
{
public:
typedef T* internalPtr;
T* getInternalPtr()
{
assert(this->_internalPtr != NULL);
return this->_internalPtr;
}
operator T*() {return this->_internalPtr;}
protected:
Internal() : _internalPtr(NULL) {}
T* _internalPtr;
};
}
#endif // VLCPP_H
#include "VlmManager.h"
#include <QString>
using namespace LibVLCpp;
VlmManager::VlmManager(Instance* instance) : _instance(*instance)
{
}
VlmMedia* VlmManager::addMedia(const QString& filename, const char* const* argv, int argc)
{
VlmMedia* media = new VlmMedia(filename);
libvlc_vlm_add_broadcast(this->_instance, media->getHash().toLocal8Bit(), filename.toLocal8Bit(),
"#duplicate{dst=display{vmem}}",
argc, argv, true, false, this->_ex);
this->_ex.checkThrow();
this->_hashTable[media->getHash()] = media;
return media;
}
VlmMedia* VlmManager::getMedia(const QString& hash)
{
if ( this->_hashTable.contains(hash) == true )
return this->_hashTable[hash];
return NULL;
}
#ifndef VLM_H
#define VLM_H
#include <QString>
#include <QHash>
#include "VLCException.h"
#include "VLCInstance.h"
#include "VlmMedia.h"
namespace LibVLCpp
{
class VlmManager
{
public:
VlmManager(Instance* instance);
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;
};
}
#endif // VLM_H
#include <QCryptographicHash>
#include "VlmMedia.h"
using namespace LibVLCpp;
VlmMedia::VlmMedia(const QString& filename)
{
QByteArray hash = QCryptographicHash::hash(filename.toAscii(), QCryptographicHash::Md5);
this->_hash = hash;
}
const QString& VlmMedia::getHash() const
{
return this->_hash;
}
#ifndef VLMMEDIA_H
#define VLMMEDIA_H
#include <QString>
namespace LibVLCpp
{
class VlmMedia
{
public:
VlmMedia(const QString& filename);
const QString& getHash() const;
private:
QString _hash;
};
}
#endif // VLMMEDIA_H
......@@ -8,7 +8,18 @@ QT += gui \
SOURCES += src/main.cpp \
src/gui/MainWindow.cpp \
src/gui/LibraryWidget.cpp
src/LibVLCpp/VLCException.cpp \
src/LibVLCpp/VlmManager.cpp \
src/LibVLCpp/VLCInstance.cpp \
src/LibVLCpp/VlmMedia.cpp
HEADERS += src/gui/MainWindow.h \
src/gui/LibraryWidget.h
src/LibVLCpp/VLCpp.hpp \
src/LibVLCpp/VLCException.h \
src/LibVLCpp/VlmManager.h \
src/LibVLCpp/VLCInstance.h \
src/LibVLCpp/VlmMedia.h
FORMS += src/gui/ui/MainWindow.ui
RESOURCES +=
LIBS = -L/usr/local/lib \
-lvlc
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