Commit 725ad563 authored by Hugo Beauzee-Luyssen's avatar Hugo Beauzee-Luyssen

Refactored media player, so that we can load more than one media at a time

parent 8a03a261
......@@ -65,6 +65,7 @@ MainWindow::~MainWindow()
{
if ( m_renderer )
delete m_renderer;
MetaDataManager::destroyInstance();
}
void MainWindow::changeEvent( QEvent *e )
......
/*****************************************************************************
* MetaDataManager.h: Launch the metadata threads
*****************************************************************************
* Copyright (C) 2008-2009 the VLMC team
*
* Authors: Hugo Beauzee-Luyssen <hugo@vlmc.org>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
#include "MetaDataManager.h"
#include "MetaDataWorker.h"
#include "Library.h"
MetaDataManager::MetaDataManager()
{
connect( Library::getInstance(), SIGNAL( newMediaLoaded( Media* ) ),this, SLOT( newMediaLoaded( Media* ) ) );
m_renderWidget = new QWidget;
}
MetaDataManager::~MetaDataManager()
{
delete m_renderWidget;
}
void MetaDataManager::newMediaLoaded( Media* media )
{
MetaDataWorker* w = new MetaDataWorker( media );
w->setRenderWidget( m_renderWidget );
w->run();
}
/*****************************************************************************
* MetaDataManager.h: Launch the metadata threads
*****************************************************************************
* Copyright (C) 2008-2009 the VLMC team
*
* Authors: Hugo Beauzee-Luyssen <hugo@vlmc.org>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
#ifndef METADATAMANAGER_H
#define METADATAMANAGER_H
#include <QObject>
#include "Media.h"
#include "Singleton.hpp"
class MetaDataManager : public QObject, public Singleton<MetaDataManager>
{
Q_OBJECT
Q_DISABLE_COPY( MetaDataManager );
friend class Singleton<MetaDataManager>;
public slots:
void newMediaLoaded( Media* );
private:
QWidget* m_renderWidget;
private:
MetaDataManager();
~MetaDataManager();
};
#endif // METADATAMANAGER_H
/*****************************************************************************
* MetaDataManmger.cpp: MetaDataManager
* MetaDataWorker.cpp: Implement the thread that will get the media informations
*****************************************************************************
* Copyright (C) 2008-2009 the VLMC team
*
......@@ -19,28 +19,22 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
/** \file
* This file contains the MetaDataManager class implementation.
* It used by the library in Library.[hc]pp.
* It parse a Clip (see in Clip.[hc]pp) to get meta-data like length, first image, etc.
*/
#include <QtDebug>
#include "vlmc.h"
#include "MetaDataManager.h"
#include "MetaDataWorker.h"
#include "Library.h"
MetaDataManager::MetaDataManager() : m_renderWidget( NULL ),
m_mediaIsPlaying( false), m_lengthHasChanged( false )
MetaDataWorker::MetaDataWorker( Media* media ) :
m_currentMedia( media ),
m_mediaIsPlaying( false),
m_lengthHasChanged( false )
{
m_mediaPlayer = new LibVLCpp::MediaPlayer();
connect( Library::getInstance(), SIGNAL( newMediaLoaded( Media* ) ),this, SLOT( newMediaLoaded( Media* ) ) );
m_renderWidget = new QWidget();
m_mediaPlayer->setDrawable( m_renderWidget->winId() );
}
MetaDataManager::~MetaDataManager()
MetaDataWorker::~MetaDataWorker()
{
if (m_mediaPlayer)
delete m_mediaPlayer;
......@@ -48,72 +42,55 @@ MetaDataManager::~MetaDataManager()
delete m_renderWidget;
}
void MetaDataManager::newMediaLoaded( Media* item )
void MetaDataWorker::setRenderWidget( QWidget* widget )
{
m_mediaList.append( item );
if ( !isRunning() )
start();
m_renderWidget = widget;
m_mediaPlayer->setDrawable( m_renderWidget->winId() );
}
void MetaDataManager::run()
void MetaDataWorker::run()
{
m_nextMedia = true;
while ( !m_mediaList.isEmpty() )
if ( m_currentMedia->getFileType() == Media::Video )
{
if ( m_nextMedia )
{
m_nextMedia = false;
m_currentClip = m_mediaList.front();
m_mediaList.pop_front();
if ( m_currentClip->getFileType() == Media::Video )
{
computeVideoMetaData();
}
else if ( m_currentClip->getFileType() == Media::Image )
{
computeImageMetaData();
}
m_mediaPlayer->setMedia( m_currentClip->getVLCMedia() );
connect( m_mediaPlayer, SIGNAL( playing() ), this, SLOT( entrypointPlaying() ) );
m_mediaPlayer->play();
m_currentClip->flushVolatileParameters();
}
SleepMS( 1 );
computeVideoMetaData();
}
return;
else if ( m_currentMedia->getFileType() == Media::Image )
{
computeImageMetaData();
}
m_mediaPlayer->setMedia( m_currentMedia->getVLCMedia() );
connect( m_mediaPlayer, SIGNAL( playing() ), this, SLOT( entrypointPlaying() ) );
m_mediaPlayer->play();
m_currentMedia->flushVolatileParameters();
}
void MetaDataManager::computeVideoMetaData()
void MetaDataWorker::computeVideoMetaData()
{
//Disabling audio for this specific use of the media
m_currentClip->addVolatileParam( ":no-audio", ":audio" );
m_currentMedia->addVolatileParam( ":no-audio", ":audio" );
connect( m_mediaPlayer, SIGNAL( lengthChanged() ), this, SLOT( entrypointLengthChanged() ) );
}
void MetaDataManager::computeImageMetaData()
void MetaDataWorker::computeImageMetaData()
{
m_currentClip->addVolatileParam( ":access=fake", ":access=''" );
m_currentClip->addVolatileParam( ":fake-duration=10000", ":fake-duration=''" );
m_currentMedia->addVolatileParam( ":access=fake", ":access=''" );
m_currentMedia->addVolatileParam( ":fake-duration=10000", ":fake-duration=''" );
}
void MetaDataManager::getMetaData()
void MetaDataWorker::getMetaData()
{
m_mediaIsPlaying = false;
//TODO: restore this when VLC1.1 comes out.
m_lengthHasChanged = false;
m_nextMedia = true;
m_currentClip->setLength( m_mediaPlayer->getLength() );
m_currentClip->setWidth( m_mediaPlayer->getWidth() );
m_currentClip->setHeight( m_mediaPlayer->getHeight() );
m_currentClip->setFps( static_cast<unsigned int>( m_mediaPlayer->getFps() ) );
m_currentMedia->setLength( m_mediaPlayer->getLength() );
m_currentMedia->setWidth( m_mediaPlayer->getWidth() );
m_currentMedia->setHeight( m_mediaPlayer->getHeight() );
m_currentMedia->setFps( static_cast<unsigned int>( m_mediaPlayer->getFps() ) );
//Setting time for snapshot :
if ( m_currentClip->getFileType() == Media::Video )
if ( m_currentMedia->getFileType() == Media::Video )
{
connect( m_mediaPlayer, SIGNAL( positionChanged() ), this, SLOT( renderSnapshot() ) );
m_mediaPlayer->setTime( m_mediaPlayer->getLength() / 3 );
......@@ -122,9 +99,9 @@ void MetaDataManager::getMetaData()
renderSnapshot();
}
void MetaDataManager::renderSnapshot()
void MetaDataWorker::renderSnapshot()
{
if ( m_currentClip->getFileType() == Media::Video )
if ( m_currentMedia->getFileType() == Media::Video )
disconnect( m_mediaPlayer, SIGNAL( positionChanged() ), this, SLOT( renderSnapshot() ) );
QTemporaryFile tmp;
tmp.setAutoRemove( false );
......@@ -139,13 +116,13 @@ void MetaDataManager::renderSnapshot()
//Snapshot slot should has been called (but maybe not in next version...)
}
void MetaDataManager::setSnapshot()
void MetaDataWorker::setSnapshot()
{
QPixmap* pixmap = new QPixmap( m_tmpSnapshotFilename );
if ( pixmap->isNull() )
delete pixmap;
else
m_currentClip->setSnapshot( pixmap );
m_currentMedia->setSnapshot( pixmap );
//TODO : we shouldn't have to do this... patch vlc to get a memory snapshot.
QFile tmp( m_tmpSnapshotFilename );
tmp.remove();
......@@ -159,67 +136,71 @@ void MetaDataManager::setSnapshot()
//startAudioDataParsing();
}
void MetaDataManager::startAudioDataParsing()
void MetaDataWorker::startAudioDataParsing()
{
qDebug() << "Starting audio parsing";
char osb[64], psb[64], csb[64], iph[64], data[64];
// disconnect( m_mediaPlayer, SIGNAL( stopped() ), this, SLOT( startAudioDataParsing() ) );
sprintf( osb, ":amem-opensb=%lld", (long long int)(intptr_t) &MetaDataManager::openSoundBuffer);
sprintf( psb, ":amem-playsb=%lld", (long long int)(intptr_t) &MetaDataManager::playSoundBuffer);
sprintf( csb, ":amem-closesb=%lld", (long long int)(intptr_t) &MetaDataManager::closeSoundBuffer);
sprintf( iph, ":amem-iph=%lld", (long long int)(intptr_t) &MetaDataManager::instanceParameterHandler);
sprintf( osb, ":amem-opensb=%lld", (long long int)(intptr_t) &MetaDataWorker::openSoundBuffer);
sprintf( psb, ":amem-playsb=%lld", (long long int)(intptr_t) &MetaDataWorker::playSoundBuffer);
sprintf( csb, ":amem-closesb=%lld", (long long int)(intptr_t) &MetaDataWorker::closeSoundBuffer);
sprintf( iph, ":amem-iph=%lld", (long long int)(intptr_t) &MetaDataWorker::instanceParameterHandler);
sprintf( data, ":amem-data=%lld", (long long int)(intptr_t) this);
m_currentClip->addVolatileParam( ":no-video", ":video" );
m_currentClip->addConstantParam( ":audio" );
m_currentClip->addVolatileParam( ":aout=amem", ":aout=''" ); //I'm really not sure about this one...
m_currentClip->addConstantParam( osb );
m_currentClip->addConstantParam( psb );
m_currentClip->addConstantParam( csb );
m_currentClip->addConstantParam( iph );
m_currentClip->addConstantParam( data );
m_mediaPlayer->setMedia( m_currentClip->getVLCMedia() );
m_currentClip->flushVolatileParameters();
m_currentMedia->addVolatileParam( ":no-video", ":video" );
m_currentMedia->addConstantParam( ":audio" );
m_currentMedia->addVolatileParam( ":aout=amem", ":aout=''" ); //I'm really not sure about this one...
m_currentMedia->addConstantParam( osb );
m_currentMedia->addConstantParam( psb );
m_currentMedia->addConstantParam( csb );
m_currentMedia->addConstantParam( iph );
m_currentMedia->addConstantParam( data );
m_mediaPlayer->setMedia( m_currentMedia->getVLCMedia() );
m_currentMedia->flushVolatileParameters();
connect( m_mediaPlayer, SIGNAL( endReached() ), this, SLOT( stopAudioDataParsing() ) );
qDebug() << "Starting playback again";
m_mediaPlayer->play();
}
void MetaDataManager::stopAudioDataParsing()
void MetaDataWorker::stopAudioDataParsing()
{
qDebug() << "Stopping AudioDataParsing";
m_mediaPlayer->stop();
}
void MetaDataManager::openSoundBuffer( void* datas, unsigned int* freq, unsigned int* nbChannels, unsigned int* fourCCFormat, unsigned int* frameSize )
void MetaDataWorker::openSoundBuffer( void* datas, unsigned int* freq, unsigned int* nbChannels, unsigned int* fourCCFormat, unsigned int* frameSize )
{
//qDebug() << "Opening sound buffer with freq =" << *freq << "nbChannels =" << *nbChannels << "frameSize =" << *frameSize;
MetaDataManager::getInstance()->getCurrentMedia()->initAudioData( datas, freq, nbChannels, fourCCFormat, frameSize );
MetaDataWorker* self = reinterpret_cast<MetaDataWorker*>( datas );
self->m_currentMedia->initAudioData( datas, freq, nbChannels, fourCCFormat, frameSize );
}
void MetaDataManager::playSoundBuffer( void* datas, unsigned char* buffer, size_t buffSize, unsigned int nbSample )
void MetaDataWorker::playSoundBuffer( void* datas, unsigned char* buffer, size_t buffSize, unsigned int nbSample )
{
//qDebug() << "Playing sound buffer with nbSample =" << nbSample << "buffSize =" << buffSize;
// qDebug() << "Buff[0] = " << (unsigned int)buffer[0];
//if (MetaDataManager::getInstance()->getCurrentMedia()->getAudioData()->frameList.size() < 500 )
MetaDataManager::getInstance()->getCurrentMedia()->addAudioFrame( datas, buffer, buffSize, nbSample );
//if (MetaDataWorker::getInstance()->getCurrentMedia()->getAudioData()->frameList.size() < 500 )
MetaDataWorker* self = reinterpret_cast<MetaDataWorker*>( datas );
self->m_currentMedia->addAudioFrame( datas, buffer, buffSize, nbSample );
//else
// MetaDataManager::getInstance()->getMediaPlayer()->stop();
// MetaDataWorker::getInstance()->getMediaPlayer()->stop();
}
void MetaDataManager::closeSoundBuffer( void* datas )
void MetaDataWorker::closeSoundBuffer( void* datas )
{
qDebug() << "Closing sound buffer";
MetaDataManager::getInstance()->getMediaPlayer()->stop();
MetaDataWorker* self = reinterpret_cast<MetaDataWorker*>( datas );
self->m_mediaPlayer->stop();
}
void MetaDataManager::instanceParameterHandler( void*, char*, char* )
void MetaDataWorker::instanceParameterHandler( void*, char*, char* )
{
}
void MetaDataManager::entrypointLengthChanged()
void MetaDataWorker::entrypointLengthChanged()
{
disconnect( m_mediaPlayer, SIGNAL( lengthChanged() ), this, SLOT( entrypointLengthChanged() ) );
m_lengthHasChanged = true;
......@@ -227,7 +208,7 @@ void MetaDataManager::entrypointLengthChanged()
getMetaData();
}
void MetaDataManager::entrypointPlaying()
void MetaDataWorker::entrypointPlaying()
{
disconnect( m_mediaPlayer, SIGNAL( playing() ), this, SLOT( entrypointPlaying() ) );
m_mediaIsPlaying = true;
......
/*****************************************************************************
* MetaDataManmger.h: MetaDataManager
* MetaDataWorker.h: MetaDataWorker
*****************************************************************************
* Copyright (C) 2008-2009 the VLMC team
*
......@@ -21,14 +21,8 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
/** \file
* This file contains the MetaDataManager class declaration/definition.
* It used by the library in Library.[hc]pp.
* It parse a Clip (see in Clip.[hc]pp) to get meta-data like length, first image, etc.
*/
#ifndef METADATAMANAGER_H
#define METADATAMANAGER_H
#ifndef METADATAWORKER_H
#define METADATAWORKER_H
#include <QList>
#include <QTemporaryFile>
......@@ -36,25 +30,19 @@
#include <QWidget>
#include "Media.h"
#include "VLCMediaPlayer.h"
#include "Singleton.hpp"
class MetaDataManager : public QThread, public Singleton<MetaDataManager>
class MetaDataWorker : public QThread
{
Q_OBJECT
Q_DISABLE_COPY( MetaDataManager )
friend class Singleton<MetaDataManager>;
Q_DISABLE_COPY( MetaDataWorker )
public:
Media* getCurrentMedia() { return m_currentClip; }
LibVLCpp::MediaPlayer* getMediaPlayer() { return m_mediaPlayer; }
private:
MetaDataManager();
~MetaDataManager();
MetaDataWorker( Media* media );
~MetaDataWorker();
void setRenderWidget( QWidget* widget );
virtual void run();
private:
void computeVideoMetaData();
void computeImageMetaData();
......@@ -70,16 +58,11 @@ class MetaDataManager : public QThread, public Singleton<MetaDataManager>
private:
void getMetaData();
private:
LibVLCpp::MediaPlayer* m_mediaPlayer;
QWidget* m_renderWidget;
// TODO: THREAD SAFING
QList<Media*> m_mediaList;
// Thread component
bool m_nextMedia;
Media* m_currentClip;
//FIXME: Won't work in asynchrone mode
Media* m_currentMedia;
QWidget* m_renderWidget;
QString m_tmpSnapshotFilename;
bool m_mediaIsPlaying;
......@@ -87,7 +70,6 @@ class MetaDataManager : public QThread, public Singleton<MetaDataManager>
private slots:
void renderSnapshot();
void newMediaLoaded( Media* );
void setSnapshot();
void startAudioDataParsing();
void stopAudioDataParsing();
......@@ -95,4 +77,4 @@ class MetaDataManager : public QThread, public Singleton<MetaDataManager>
void entrypointLengthChanged();
};
#endif // METADATAMANAGER_H
#endif // METADATAWORKER_H
......@@ -30,7 +30,7 @@ SOURCES += src/main.cpp \
src/gui/About.cpp \
src/gui/Transcode.cpp \
src/gui/Slider.cpp \
src/MetaDataManager.cpp \
src/metadata/MetaDataWorker.cpp \
src/Library.cpp \
src/gui/GraphicsMovieItem.cpp \
src/gui/AbstractGraphicsMediaItem.cpp \
......@@ -46,7 +46,8 @@ SOURCES += src/main.cpp \
src/API/Module.cpp \
src/API/ModuleManager.cpp \
src/WorkflowFileRenderer.cpp \
src/UndoStack.cpp
src/UndoStack.cpp \
src/metadata/MetaDataManager.cpp
HEADERS += src/gui/MainWindow.h \
src/gui/DockWidgetManager.h \
src/gui/LibraryWidget.h \
......@@ -68,7 +69,7 @@ HEADERS += src/gui/MainWindow.h \
src/gui/About.h \
src/gui/Transcode.h \
src/gui/Slider.h \
src/MetaDataManager.h \
src/metadata/MetaDataWorker.h \
src/tools/Singleton.hpp \
src/Library.h \
src/gui/AbstractGraphicsMediaItem.h \
......@@ -91,7 +92,8 @@ HEADERS += src/gui/MainWindow.h \
src/vlmc.h \
src/tools/Pool.hpp \
src/UndoStack.h \
src/tools/WaitCondition.hpp
src/tools/WaitCondition.hpp \
src/metadata/MetaDataManager.h
FORMS += src/gui/ui/MainWindow.ui \
src/gui/ui/PreviewWidget.ui \
src/gui/ui/Preferences.ui \
......@@ -110,6 +112,7 @@ INCLUDEPATH += src/LibVLCpp \
src/gui \
src/tools \
src/renderer \
src/metadata \
src
# QMAKE_CFLAGS+=-pg
......
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