Commit 55693dc3 authored by Hugo Beauzee-Luyssen's avatar Hugo Beauzee-Luyssen

More bugged c++ binding...

parent e8ae2fae
......@@ -20,6 +20,10 @@ public:
{
return this->_pixelsData;
}
QImage& getImage()
{
return *(this->_image);
}
private:
QImage* _image;
uchar* _pixelsData;
......
#include <QtDebug>
#include <cassert>
#include "VLCMedia.h"
......@@ -8,7 +9,6 @@ Media::Media(Instance* instance, const QString& filename) : _instance(*instance)
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()
......@@ -18,18 +18,11 @@ Media::~Media()
delete this->_dataCtx;
}
Media::DataCtx* Media::buildDataCtx()
{
Media::DataCtx* dataCtx = new Media::DataCtx;
dataCtx->mutex = new QMutex();
dataCtx->media = this;
return dataCtx;
}
void Media::addOption(const char* opt)
{
libvlc_media_add_option(this->_internalPtr, opt, this->_ex);
this->_ex.checkThrow();
qDebug() << "Added media option: " << opt;
}
Media::DataCtx::~DataCtx()
......@@ -51,10 +44,15 @@ void Media::setUnlockCallback(Media::unlockCallback callback)
this->addOption(param);
}
void Media::setDataCtx(Media::DataCtx* dataCtx)
void Media::setDataCtx()
{
char param[64];
sprintf(param, ":vmem-data=%lld", (long long int)(intptr_t)dataCtx);
this->_dataCtx = new Media::DataCtx;
this->_dataCtx->mutex = new QMutex();
this->_dataCtx->media = this;
sprintf(param, ":vmem-data=%lld", (long long int)(intptr_t)this->_dataCtx);
this->addOption(param);
}
......@@ -77,4 +75,3 @@ uchar* Media::getPixelBuffer()
{
return this->_pixelBuffer;
}
......@@ -32,15 +32,13 @@ namespace LibVLCpp
void addOption(const char* opt);
void setLockCallback(Media::lockCallback);
void setUnlockCallback(Media::unlockCallback);
void setDataCtx(Media::DataCtx* dataCtx);
void setDataCtx();
void outputInVmem();
void outputInWindow();
void setPixelBuffer(uchar* buffer);
uchar* getPixelBuffer();
private:
DataCtx* buildDataCtx();
Exception _ex;
Instance& _instance;
DataCtx* _dataCtx;
......
#include <QtDebug>
#include <cassert>
#include "VLCMediaPlayer.h"
using namespace LibVLCpp;
MediaPlayer::MediaPlayer(Media* media)
//void MediaPlayer::eventPlayingCallback(const EventManager::Event*, void* data)
//{
// //getting the event manager back...
// MediaPlayer* mp = static_cast<MediaPlayer*>(data);
// //...and removing this dirty callback.
// //mp->_evMgr->removeEvent(EventManager::MediaPlayingEvent, &eventPlayingCallback, reinterpret_cast<void*>(data));
// mp->_isReady = true;
// //stopping the playback must be the last thing we do since it wont continue after this...
// //mp->stop();
//}
MediaPlayer::MediaPlayer(Media* media, bool playStop /* = true*/) : /*_evMgr(NULL),`*/ _isReady(false)
{
this->_internalPtr = libvlc_media_player_new_from_media(media->getInternalPtr(), this->_ex);
this->_ex.checkThrow();
// if ( playStop == true )
// {
// this->_evMgr = new EventManager(this->getInternalPtr());
// this->_evMgr->addEvent(EventManager::MediaPlayerPositionChangedEvent, &eventPlayingCallback, static_cast<void*>(this));
// }
}
void MediaPlayer::play()
......@@ -24,6 +41,7 @@ void MediaPlayer::pause()
void MediaPlayer::stop()
{
libvlc_media_player_stop(this->_internalPtr, this->_ex);
this->_ex.checkThrow();
}
qint64 MediaPlayer::getTime()
......@@ -51,3 +69,17 @@ void MediaPlayer::takeSnapshot(uchar* output, unsigne
libvlc_video_take_snapshot(*this, reinterpret_cast<char*>(output), width, heigth, this->_ex);
this->_ex.checkThrow();
}
int MediaPlayer::isPlaying()
{
int res = libvlc_media_player_is_playing(this->_internalPtr, this->_ex);
this->_ex.checkThrow();
return res;
}
int MediaPlayer::isSeekable()
{
int res = libvlc_media_player_is_seekable(this->_internalPtr, this->_ex);
this->_ex.checkThrow();
return res;
}
......@@ -8,13 +8,14 @@
#include "VLCpp.hpp"
#include "VLCMedia.h"
#include "VLCException.h"
#include "VLCEventManager.h"
namespace LibVLCpp
{
class MediaPlayer : public Internal<libvlc_media_player_t>
{
public:
MediaPlayer(Media* media);
MediaPlayer(Media* media, bool playStop = true);
void play();
void pause();
void stop();
......@@ -22,8 +23,14 @@ namespace LibVLCpp
void setTime(qint64 time);
qint64 getLength();
void takeSnapshot(uchar* output, unsigned int width, unsigned int heigth);
private:
int isPlaying();
int isSeekable();
//FIXME: private
//static void eventPlayingCallback(const EventManager::Event*, void* data);
private: public:
Exception _ex;
// EventManager* _evMgr;
bool _isReady;
};
}
......
#include <QtDebug>
#include "Media.h"
Media::Media(const QString& mrl) : _mrl(mrl), _snapshot(NULL)
{
this->_instance = new LibVLCpp::Instance(0, NULL);
// qDebug() << "Built instance";
this->_vlcMedia = new LibVLCpp::Media(this->_instance, this->_mrl);
this->_vlcMediaPlayer = new LibVLCpp::MediaPlayer(this->_vlcMedia);
// qDebug() << "Built Media";
// qDebug() << "Built mediaPlayer";
this->_vlcMedia->outputInVmem();
this->_vlcMedia->setLockCallback(Media::lock);
this->_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);
this->_vlcMedia->addOption(width);
this->_vlcMedia->addOption(height);
this->_vlcMedia->addOption(chroma);
this->_vlcMedia->addOption(pitch);
this->_pixelBuffer = new uchar[VIDEOHEIGHT * VIDEOWIDTH * 4];
this->_image = new QImage(this->_pixelBuffer, VIDEOWIDTH, VIDEOHEIGHT, VIDEOWIDTH * 4, QImage::Format_ARGB32);
this->_image = new QImage(this->_pixelBuffer, VIDEOWIDTH, VIDEOHEIGHT, VIDEOWIDTH * 4, QImage::Format_RGB32);
this->_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();
//And now we play the media
this->_vlcMediaPlayer = new LibVLCpp::MediaPlayer(this->_vlcMedia);
}
Media::~Media()
......@@ -34,17 +54,29 @@ void Media::lock(LibVLCpp::Media::DataCtx* ctx, void **renderPtr)
void Media::unlock(LibVLCpp::Media::DataCtx* ctx)
{
// QImage(ctx->media->getPixelBuffer(), VIDEOWIDTH, VIDEOHEIGHT, QImage::Format_RGB32).save("/home/chouquette/Desktop/testRender.png");
qDebug() << "frame just rendered";
ctx->mutex->unlock();
}
Image* Media::takeSnapshot(unsigned int width, unsigned int height)
QImage* Media::takeSnapshot(unsigned int width, unsigned int height)
{
if ( this->_snapshot == NULL )
{
this->_snapshot = new Image(width, height);
this->_snapshot = new QImage(*this->_image);
this->_vlcMediaPlayer->setTime(this->_vlcMediaPlayer->getLength() / 2);
this->_vlcMediaPlayer->takeSnapshot(this->_snapshot->getBuffer(), width, height);
this->_vlcMediaPlayer->setTime(0);
}
return this->_snapshot;
}
int Media::isPlaying()
{
return this->_vlcMediaPlayer->isPlaying();
}
int Media::isSeekable()
{
return this->_vlcMediaPlayer->isSeekable();
}
......@@ -18,17 +18,22 @@ public:
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* takeSnapshot(unsigned int width, unsigned int heigth);
QImage& getImage();
//FIXME into bool
int isPlaying();
int isSeekable();
private:
//FIXME
private: public:
LibVLCpp::Media* _vlcMedia;
LibVLCpp::MediaPlayer* _vlcMediaPlayer;
LibVLCpp::Instance* _instance;
QString _mrl;
Image* _snapshot;
QImage* _snapshot;
uchar* _pixelBuffer;
QImage* _image;
......
......@@ -26,7 +26,9 @@ SOURCES += src/main.cpp \
src/gui/TracksRuler.cpp \
src/gui/Preferences.cpp \
src/gui/ListViewMediaItem.cpp \
src/gui/MediaListWidget.cpp
src/gui/MediaListWidget.cpp \
src/Media.cpp
HEADERS += src/gui/MainWindow.h \
src/gui/DockWidgetManager.h \
src/gui/LibraryWidget.h \
......@@ -44,12 +46,16 @@ HEADERS += src/gui/MainWindow.h \
src/gui/TracksRuler.h \
src/gui/Preferences.h \
src/gui/ListViewMediaItem.h \
src/Media.h \
src/Image.h \
src/gui/MediaListWidget.h
FORMS += src/gui/ui/MainWindow.ui \
src/gui/ui/Timeline.ui \
src/gui/ui/LibraryWidget.ui \
src/gui/ui/PreviewWidget.ui \
src/gui/ui/Preferences.ui
RESOURCES +=
INCLUDEPATH += src/LibVLCpp
LIBS = -L/usr/local/lib \
......
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