Commit 0ce15dbd authored by Hugo Beauzée-Luyssen's avatar Hugo Beauzée-Luyssen

Rework snapshot & metadata updates.

Do not emit the signal from outside of the class
Remove GUIMedia class
parent b6eb37cc
......@@ -50,6 +50,7 @@ namespace Backend
virtual unsigned int nbVideoTracks() const = 0;
virtual bool hasAudio() const = 0;
virtual unsigned int nbAudioTracks() const = 0;
virtual const uint8_t* snapshot() const = 0;
};
class IMemorySource
......
......@@ -168,3 +168,12 @@ VLCSource::nbAudioTracks() const
{
return m_nbAudioTracks;
}
const uint8_t*
VLCSource::snapshot() const
{
if ( hasVideo() == false || m_snapshot == NULL )
return NULL;
return m_snapshot->bits();
}
......@@ -52,6 +52,7 @@ public:
virtual unsigned int nbVideoTracks() const;
virtual bool hasAudio() const;
virtual unsigned int nbAudioTracks() const;
const uint8_t* snapshot() const;
// Below this point are backend internal methods:
LibVLCpp::Media* media();
......
......@@ -151,7 +151,6 @@ ELSE(NOT WITH_GUI)
Gui/library/StackViewNavController.cpp
Gui/library/ViewController.h
Gui/media/ClipMetadataDisplayer.cpp
Gui/media/GuiMedia.cpp
Gui/preview/LCDTimecode.cpp
Gui/preview/PreviewRuler.cpp
Gui/preview/PreviewWidget.cpp
......
......@@ -159,7 +159,6 @@ ImportController::importMedia( const QString &filePath )
Media* media = m_temporaryMedias->addMedia( filePath );
connect( media, SIGNAL( metaDataComputed( const Media* ) ), this, SLOT( mediaLoaded() ) );
media->computeMetadata();
if ( media == NULL )
{
vlmcCritical() << "An error occurred while loading media:" << filePath;
......
......@@ -71,8 +71,9 @@ MediaCellView::MediaCellView( Clip* clip, QWidget *parent ) :
}
connect( clip->getMedia(), SIGNAL( metaDataComputed(const Media*) ),
this, SLOT( metadataUpdated( const Media*) ) );
connect( clip->getMedia(), SIGNAL( snapshotComputed(const Media*) ),
this, SLOT( snapshotUpdated(const Media*) ) );
// Snapshot generation will generate a QPixmap, which has to be done on GUI thread
connect( clip->getMedia(), SIGNAL( snapshotComputed() ),
this, SLOT( snapshotUpdated() ), Qt::QueuedConnection );
setThumbnail( clip->getMedia()->snapshot() );
setTitle( clip->getMedia()->fileName() );
......@@ -108,9 +109,9 @@ MediaCellView::metadataUpdated( const Media *media )
}
void
MediaCellView::snapshotUpdated( const Media *media )
MediaCellView::snapshotUpdated()
{
setThumbnail( media->snapshot() );
setThumbnail( m_clip->getMedia()->snapshot() );
m_ui->delLabel->setEnabled( true );
}
......@@ -219,7 +220,7 @@ MediaCellView::mouseMoveEvent( QMouseEvent* event )
mimeData->setData( "vlmc/uuid", m_clip->fullId().toLatin1() );
QDrag* drag = new QDrag( this );
drag->setMimeData( mimeData );
const Media* parent = m_clip->getMedia();
Media* parent = m_clip->getMedia();
drag->setPixmap( parent->snapshot().scaled( 100, 100, Qt::KeepAspectRatio ) );
drag->exec( Qt::CopyAction | Qt::MoveAction, Qt::CopyAction );
}
......
......@@ -73,7 +73,7 @@ public slots:
void arrowButtonClicked( QWidget *sender, QMouseEvent *event );
private slots:
void snapshotUpdated( const Media *media );
void snapshotUpdated();
void metadataComputingStarted( const Media *media );
void metadataUpdated( const Media *media );
void nbClipUpdated();
......
/*****************************************************************************
* GUIMedia.cpp: Represents the GUI part of a Media
*****************************************************************************
* Copyright (C) 2008-2010 VideoLAN
*
* Authors: Hugo Beauzée-Luyssen <hugo@beauzee.fr>
*
* 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 "GuiMedia.h"
#include "Media.h"
QPixmap* GUIMedia::defaultSnapshot = NULL;
GUIMedia::GUIMedia()
{
}
void GUIMedia::snapshotReady(const QImage* snapshot)
{
m_snapshot = QPixmap::fromImage( *snapshot );
if ( m_snapshot.isNull() == false )
emit snapshotComputed( qobject_cast<const Media*>( this ) );
delete snapshot;
}
GUIMedia::~GUIMedia()
{
}
const QPixmap&
GUIMedia::snapshot() const
{
if ( hasSnapshot() )
return m_snapshot;
if ( GUIMedia::defaultSnapshot == NULL )
GUIMedia::defaultSnapshot = new QPixmap( ":/images/vlmc" );
return *GUIMedia::defaultSnapshot;
}
bool
GUIMedia::hasSnapshot() const
{
return !m_snapshot.isNull();
}
/*****************************************************************************
* GUIMedia.h: Represents the GUI part of a Media
*****************************************************************************
* Copyright (C) 2008-2010 VideoLAN
*
* Authors: Hugo Beauzée-Luyssen <hugo@beauzee.fr>
*
* 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 GUIMEDIA_H
#define GUIMEDIA_H
#include <QObject>
#include <QPixmap>
class QImage;
class QPixmap;
class Media;
class GUIMedia : public QObject
{
Q_OBJECT
public:
~GUIMedia();
const QPixmap &snapshot() const;
bool hasSnapshot() const;
protected:
//A GUIMedia shouldn't be constructed by something else than a media
GUIMedia();
static QPixmap* defaultSnapshot;
QPixmap m_snapshot;
public slots:
void snapshotReady(const QImage *snapshot );
signals:
void snapshotComputed( const Media* );
};
#endif // GUIMEDIA_H
......@@ -135,7 +135,6 @@ Library::addMedia( const QFileInfo &fileInfo )
connect( media, SIGNAL( metaDataComputed( const Media* ) ),
this, SLOT( mediaLoaded( const Media* ) ), Qt::QueuedConnection );
m_medias[fileInfo.absoluteFilePath()] = media;
media->computeMetadata();
}
return media;
}
......
......@@ -52,16 +52,20 @@ const QString Media::AudioExtensions = "*.a52 *.aac *.ac3 *.aiff *.amr *.aob *
"*.wma *.wv *.xa *.xm";
const QString Media::streamPrefix = "stream://";
Media::Media(const QString &path ) :
m_fileInfo( NULL ),
m_nbFrames( 0 ),
m_baseClip( NULL ),
m_metadataComputed( false ),
m_inWorkspace( false )
QPixmap* Media::defaultSnapshot = NULL;
Media::Media(const QString &path )
: m_fileInfo( NULL )
, m_nbFrames( 0 )
, m_baseClip( NULL )
, m_metadataComputed( false )
, m_inWorkspace( false )
, m_snapshotImage( NULL )
{
setFilePath( path );
Backend::IBackend* backend = Backend::getBackend();
m_source = backend->createSource( qPrintable( path ) );
MetaDataManager::getInstance()->computeMediaMetadata( this );
}
Media::~Media()
......@@ -103,13 +107,6 @@ void Media::setFileType(Media::FileType type)
m_fileType = type;
}
void
Media::emitMetaDataComputed()
{
m_metadataComputed = true;
emit metaDataComputed( this );
}
Media::InputType
Media::inputType() const
{
......@@ -182,6 +179,19 @@ Media::isInWorkspace() const
return m_inWorkspace;
}
void
Media::onMetaDataComputed()
{
emit metaDataComputed();
if ( m_source->hasVideo() && m_source->snapshot() != NULL )
{
Q_ASSERT( m_snapshotImage == NULL );
m_snapshotImage = new QImage( m_source->snapshot(), m_source->width(),
m_source->height(), QImage::Format_RGB32 );
emit snapshotAvailable();
}
}
void
Media::setFilePath( const QString &filePath )
{
......@@ -209,8 +219,21 @@ Media::setFilePath( const QString &filePath )
emit workspaceStateChanged( m_inWorkspace );
}
void
Media::computeMetadata()
QPixmap&
Media::snapshot()
{
MetaDataManager::getInstance()->computeMediaMetadata( this );
if ( m_snapshot.isNull() == false )
return m_snapshot;
if ( m_snapshotImage != NULL )
{
m_snapshot = QPixmap::fromImage( *m_snapshotImage );
delete m_snapshotImage;
if ( m_snapshot.isNull() == false )
return m_snapshot;
}
if ( Media::defaultSnapshot == NULL )
Media::defaultSnapshot = new QPixmap( ":/images/vlmc" );
return *Media::defaultSnapshot;
}
......@@ -38,7 +38,8 @@
#include <QXmlStreamWriter>
#ifdef WITH_GUI
#include "media/GuiMedia.h"
#include <QPixmap>
#include <QImage>
#endif
namespace Backend
......@@ -50,11 +51,7 @@ class Clip;
/**
* Represents a basic container for media informations.
*/
#ifdef WITH_GUI
class Media : public GUIMedia
#else
class Media : public QObject
#endif
{
Q_OBJECT
......@@ -103,8 +100,6 @@ public:
InputType inputType() const;
void emitMetaDataComputed();
Clip* baseClip() { return m_baseClip; }
const Clip* baseClip() const { return m_baseClip; }
void setBaseClip( Clip* clip );
......@@ -115,12 +110,10 @@ public:
bool isInWorkspace() const;
/**
* \brief Just an helper to compute metadata.
*
* Actual computing is performed by MetadataManager
*/
void computeMetadata();
void onMetaDataComputed();
// This has to be called from the GUI thread.
QPixmap& snapshot();
private:
void computeFileType();
......@@ -138,9 +131,14 @@ protected:
bool m_inWorkspace;
QString m_workspacePath;
static QPixmap* defaultSnapshot;
QPixmap m_snapshot;
QImage* m_snapshotImage;
signals:
void metaDataComputed( const Media* );
void metaDataComputed();
void workspaceStateChanged( bool );
void snapshotAvailable();
};
#endif // MEDIA_H__
......@@ -63,8 +63,7 @@ MetaDataManager::run()
Backend::ISource* targetSource = target->source();
if ( targetSource->preparse() == false )
emit failedToCompute( target );
//FIXME: this looks really ugly. And doesn't handle snapshot for now
else
target->emitMetaDataComputed();
target->onMetaDataComputed();
}
}
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