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

More c++ binding...

Added a tiny class for image handling
Added a Media class that will be the entrypoint for most of the timeline video
stuff
Code cleaning / reorganisation

Sorry for the big svn-like commit :p
parent 1ad2c1f3
#ifndef IMAGE_HPP
#define IMAGE_HPP
#include <QImage>
class Image
{
public:
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);
}
~Image()
{
delete this->_image;
delete this->_pixelsData;
}
uchar* getBuffer()
{
return this->_pixelsData;
}
private:
QImage* _image;
uchar* _pixelsData;
};
#endif // IMAGE_HPP
......@@ -3,22 +3,26 @@
using namespace LibVLCpp;
Media::Media(Instance* instance, const QString& filename) : _instance(*instance)
Media::Media(Instance* instance, const QString& filename) : _instance(*instance), _pixelBuffer(NULL)
{
this->_internalPtr = libvlc_media_new(this->_instance, filename.toLocal8Bit(), this->_ex);
this->_ex.checkThrow();
// this->_pixelBuffer = new uchar[VIDEOHEIGHT * VIDEOWIDTH * 4];
// this->_dataCtx = this->buildDataCtx();
}
Media::~Media()
{
libvlc_media_release(this->_internalPtr);
delete[] this->_pixelBuffer;
delete this->_dataCtx;
}
Media::DataCtx* Media::buildDataCtx()
{
Media::DataCtx* dataCtx = new Media::DataCtx;
dataCtx->mutex = new QMutex();
dataCtx->pixelBuffer = new uchar[VIDEOHEIGHT * VIDEOWIDTH * 4];
dataCtx->media = this;
return dataCtx;
}
......@@ -30,7 +34,6 @@ void Media::addOption(const char* opt)
Media::DataCtx::~DataCtx()
{
delete[] this->pixelBuffer;
delete this->mutex;
}
......@@ -64,3 +67,14 @@ void Media::outputInWindow()
{
// this->addOption();
}
void Media::setPixelBuffer(uchar* buffer)
{
this->_pixelBuffer = buffer;
}
uchar* Media::getPixelBuffer()
{
return this->_pixelBuffer;
}
......@@ -21,8 +21,8 @@ namespace LibVLCpp
struct DataCtx
{
~DataCtx();
uchar* pixelBuffer;
QMutex* mutex;
Media* media;
};
typedef void (*lockCallback)(Media::DataCtx* dataCtx, void **pp_ret);
typedef void (*unlockCallback)(Media::DataCtx* dataCtx);
......@@ -35,11 +35,16 @@ namespace LibVLCpp
void setDataCtx(Media::DataCtx* dataCtx);
void outputInVmem();
void outputInWindow();
void setPixelBuffer(uchar* buffer);
uchar* getPixelBuffer();
static DataCtx* buildDataCtx();
private:
DataCtx* buildDataCtx();
Exception _ex;
Instance& _instance;
DataCtx* _dataCtx;
uchar* _pixelBuffer;
};
}
......
......@@ -45,3 +45,9 @@ qint64 MediaPlayer::getLength()
this->_ex.checkThrow();
return length;
}
void MediaPlayer::takeSnapshot(uchar* output, unsigned int width, unsigned int heigth)
{
libvlc_video_take_snapshot(*this, reinterpret_cast<char*>(output), width, heigth, this->_ex);
this->_ex.checkThrow();
}
......@@ -21,6 +21,7 @@ namespace LibVLCpp
qint64 getTime();
void setTime(qint64 time);
qint64 getLength();
void takeSnapshot(uchar* output, unsigned int width, unsigned int heigth);
private:
Exception _ex;
};
......
#include "Media.h"
Media::Media(const QString& mrl) : _mrl(mrl), _snapshot(NULL)
{
this->_instance = new LibVLCpp::Instance(0, NULL);
this->_vlcMedia = new LibVLCpp::Media(this->_instance, this->_mrl);
this->_vlcMediaPlayer = new LibVLCpp::MediaPlayer(this->_vlcMedia);
this->_vlcMedia->outputInVmem();
this->_vlcMedia->setLockCallback(Media::lock);
this->_vlcMedia->setUnlockCallback(Media::unlock);
this->_pixelBuffer = new uchar[VIDEOHEIGHT * VIDEOWIDTH * 4];
this->_image = new QImage(this->_pixelBuffer, VIDEOWIDTH, VIDEOHEIGHT, VIDEOWIDTH * 4, QImage::Format_ARGB32);
this->_image->fill(0);
this->_vlcMedia->setPixelBuffer(this->_pixelBuffer);
}
Media::~Media()
{
delete this->_image;
delete this->_pixelBuffer;
delete this->_vlcMedia;
delete this->_vlcMediaPlayer;
delete this->_instance;
}
void Media::lock(LibVLCpp::Media::DataCtx* ctx, void **renderPtr)
{
ctx->mutex->lock();
*renderPtr = ctx->media->getPixelBuffer();
}
void Media::unlock(LibVLCpp::Media::DataCtx* ctx)
{
ctx->mutex->unlock();
}
Image* Media::takeSnapshot(unsigned int width, unsigned int height)
{
if ( this->_snapshot == NULL )
{
this->_snapshot = new Image(width, height);
this->_vlcMediaPlayer->setTime(this->_vlcMediaPlayer->getLength() / 2);
this->_vlcMediaPlayer->takeSnapshot(this->_snapshot->getBuffer(), width, height);
this->_vlcMediaPlayer->setTime(0);
}
return this->_snapshot;
}
#ifndef MEDIA_H
#define MEDIA_H
#include <QString>
#include <QImage>
#include "VLCMedia.h"
#include "VLCInstance.h"
#include "VLCMediaPlayer.h"
#include "Image.h"
class Media
{
public:
Media(const QString& mrl);
~Media();
static void lock(LibVLCpp::Media::DataCtx* dataCtx, void **pp_ret);
static void unlock(LibVLCpp::Media::DataCtx* dataCtx);
Image* takeSnapshot(unsigned int width, unsigned int heigth);
QImage& getImage();
private:
LibVLCpp::Media* _vlcMedia;
LibVLCpp::MediaPlayer* _vlcMediaPlayer;
LibVLCpp::Instance* _instance;
QString _mrl;
Image* _snapshot;
uchar* _pixelBuffer;
QImage* _image;
};
#endif // MEDIA_H
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