Commit 28cb7be4 authored by Clement CHAVANCE's avatar Clement CHAVANCE
Browse files

Merge branch 'master' of git@github.com:VLMC/vlmc

parents 550c5cdb f24add47
......@@ -59,7 +59,6 @@ qint64 MediaPlayer::getTime()
void MediaPlayer::setTime( qint64 time )
{
// qDebug() << "Setting media time to " << time;
libvlc_media_player_set_time( m_internalPtr, time, m_ex );
m_ex.checkThrow();
}
......@@ -68,7 +67,6 @@ qint64 MediaPlayer::getLength()
{
qint64 length = libvlc_media_player_get_length( m_internalPtr, m_ex );
m_ex.checkThrow();
//qDebug() << "Media length: " << length;
return length;
}
......@@ -92,8 +90,12 @@ bool MediaPlayer::isSeekable()
return (res == 1);
}
void MediaPlayer::setDrawable(int handle)
void MediaPlayer::setDrawable( void* hwnd )
{
libvlc_drawable_t window = handle;
libvlc_media_player_set_drawable( m_internalPtr, window, m_ex );
libvlc_media_player_set_hwnd( m_internalPtr, hwnd, m_ex );
}
void MediaPlayer::setDrawable( uint32_t drawable )
{
libvlc_media_player_set_xwindow( m_internalPtr, drawable, m_ex );
}
......@@ -46,7 +46,8 @@ namespace LibVLCpp
void takeSnapshot( char* outputFile, unsigned int width, unsigned int heigth );
bool isPlaying();
bool isSeekable();
void setDrawable(int handle);
void setDrawable( void* hwnd );
void setDrawable( uint32_t drawable );
private:
Exception m_ex;
......
#include "VlmManager.h"
#include <QString>
using namespace LibVLCpp;
VlmManager::VlmManager( Instance* instance ) : m_instance( *instance )
{
}
VlmMedia* VlmManager::addMedia( const QString& filename, const char* const* argv, int argc )
{
VlmMedia* media = new VlmMedia( m_instance, filename );
libvlc_vlm_add_broadcast( m_instance, media->getHash().toLocal8Bit(), filename.toLocal8Bit(),
"#duplicate{dst=display{vmem}}",
argc, argv, true, false, m_ex );
m_ex.checkThrow();
m_hashTable[ media->getHash() ] = media;
return media;
}
VlmMedia* VlmManager::getMedia( const QString& hash )
{
if ( m_hashTable.contains( hash ) )
return m_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* > m_hashTable;
Instance& m_instance;
Exception m_ex;
};
}
#endif // VLM_H
#include <QtDebug>
#include <QCryptographicHash>
#include "vlc/vlc.h"
#include "VlmMedia.h"
using namespace LibVLCpp;
VlmMedia::VlmMedia(Instance& instance, const QString& filename) : _instance(instance)
{
QByteArray hash = QCryptographicHash::hash(filename.toAscii(), QCryptographicHash::Md5);
//To have a printable value :
this->_hash = hash.toHex();
}
const QString& VlmMedia::getHash() const
{
return this->_hash;
}
void VlmMedia::play()
{
libvlc_vlm_play_media(this->_instance, this->_hash.toLocal8Bit(), this->_ex);
this->_ex.checkThrow();
}
int VlmMedia::getLength()
{
int length = libvlc_vlm_get_media_instance_length(this->_instance, this->_hash.toLocal8Bit(), 0, this->_ex);
this->_ex.checkThrow();
return length;
}
#ifndef VLMMEDIA_H
#define VLMMEDIA_H
#include <QString>
#include "VLCInstance.h"
#include "VLCException.h"
namespace LibVLCpp
{
class VlmMedia
{
public:
VlmMedia(Instance& inst, const QString& filename);
const QString& getHash() const;
int getLength();
void play();
private:
Instance& _instance;
Exception _ex;
QString _hash;
};
}
#endif // VLMMEDIA_H
......@@ -21,6 +21,7 @@
*****************************************************************************/
#include <QtDebug>
#include <QTemporaryFile>
#include "Media.h"
......@@ -30,7 +31,6 @@ Media::Media( const QString& mrl ) : m_mrl( mrl ), m_snapshot( NULL )
{
"-verbose", "3",
"--no-skip-frames",
//"--snapshot-format", "jpg",
//"--plugin-path", VLC_TREE "/modules",
//"--ignore-config", /* Don't use VLC's config files */
};
......@@ -65,7 +65,7 @@ Media::Media( const QString& mrl ) : m_mrl( mrl ), m_snapshot( NULL )
//And now we play the media
m_vlcMediaPlayer = new LibVLCpp::MediaPlayer( m_vlcMedia );
m_isMediaInitialized = false;
//And launch the checking thread
start();
}
......@@ -77,6 +77,7 @@ void Media::run()
if( m_vlcMediaPlayer->isSeekable() && m_vlcMediaPlayer->getLength() > 0 )
{
m_isMediaInitialized = true;
emit mediaReady();
m_vlcMediaPlayer->pause();
return ;
}
......@@ -107,18 +108,24 @@ void Media::unlock( LibVLCpp::Media::DataCtx* ctx )
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 ( m_snapshot == NULL )
{
qDebug() << "trying to take a snapshot";
m_vlcMediaPlayer->takeSnapshot( "/tmp/vlmcscreenshot.tmp.gif", width, height );
qDebug() << "done snapshoting";
m_snapshot = new QImage( "/tmp/vlmcscreenshot.tmp.gif" );
qDebug() << "written to a QImage";
// 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";
m_snapshot = new QImage( tmp.fileName() );
// qDebug() << "written to a QImage";
// m_vlcMediaPlayer->setTime(currentTime);
}
return m_snapshot;
}
......@@ -133,6 +140,12 @@ bool Media::isSeekable()
return m_vlcMediaPlayer->isSeekable();
}
bool Media::isReady()
{
//If the thread has finished without any error, then the media is ready o//
return m_isMediaInitialized;
}
qint64 Media::getLength()
{
return m_vlcMediaPlayer->getLength();
......@@ -159,7 +172,7 @@ QImage& Media::getImage()
return *m_image;
}
void Media::setDrawable(int handle)
void Media::setDrawable( WId handle )
{
m_vlcMediaPlayer->setDrawable(handle);
m_vlcMediaPlayer->setDrawable( handle );
}
......@@ -45,12 +45,33 @@ public:
QImage* takeSnapshot( unsigned int width, unsigned int heigth );
/**
* Ask libvlc if the media is currently playing
*/
bool isPlaying();
/**
* 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();
/**
* Return the length (duration) of a Media
*/
qint64 getLength();
/**
* Returns the last rendered frame
*/
QImage& getImage();
/**
* Start the playback.
* This need to be called at least once in order to prepare the media. if not, the media can't be seeked or anything else.
* When pre-launching is completed, a "mediaReady" signal will be fired.
*/
void play();
void setDrawable(int handle);
void setDrawable( WId handle );
private:
virtual void run();
......@@ -69,7 +90,7 @@ private slots:
void playSlot();
signals:
void mediaPlayerReady();
void mediaReady();
};
#endif // MEDIA_H
......@@ -13,9 +13,7 @@ SOURCES += src/main.cpp \
src/gui/LibraryWidget.cpp \
src/gui/DockWidgetManager.cpp \
src/LibVLCpp/VLCException.cpp \
src/LibVLCpp/VlmManager.cpp \
src/LibVLCpp/VLCInstance.cpp \
src/LibVLCpp/VlmMedia.cpp \
src/gui/Timeline.cpp \
src/LibVLCpp/VLCMediaPlayer.cpp \
src/LibVLCpp/VLCMedia.cpp \
......@@ -35,9 +33,7 @@ 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 \
src/gui/Timeline.h \
src/LibVLCpp/VLCMediaPlayer.h \
src/LibVLCpp/VLCMedia.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