Commit 1a0b7c65 authored by Hugo Beauzée-Luyssen's avatar Hugo Beauzée-Luyssen

MetadataWorker: Don't hang if the file has no length.

parent d19378be
......@@ -36,6 +36,8 @@
# include <QImage>
#endif
#include <QTimer>
MetaDataWorker::MetaDataWorker( LibVLCpp::MediaPlayer* mediaPlayer, Media* media ) :
m_mediaPlayer( mediaPlayer ),
m_media( media ),
......@@ -43,10 +45,13 @@ MetaDataWorker::MetaDataWorker( LibVLCpp::MediaPlayer* mediaPlayer, Media* media
m_lengthHasChanged( false ),
m_audioBuffer( NULL )
{
m_lengthChangedTimer = new QTimer;
m_lengthChangedTimer->setSingleShot( true );
}
MetaDataWorker::~MetaDataWorker()
{
delete m_lengthChangedTimer;
if ( m_audioBuffer )
delete m_audioBuffer;
}
......@@ -62,11 +67,14 @@ MetaDataWorker::compute()
m_media->addConstantParam( ":vout=dummy" );
m_mediaPlayer->setMedia( m_media->vlcMedia() );
connect( m_lengthChangedTimer, SIGNAL( timeout() ),
this, SLOT( lengthChangedTimeout() ), Qt::QueuedConnection );
connect( m_mediaPlayer, SIGNAL( playing() ),
this, SLOT( entrypointPlaying() ), Qt::QueuedConnection );
connect( m_mediaPlayer, SIGNAL( errorEncountered() ), this, SLOT( failure() ) );
connect( m_mediaPlayer, SIGNAL( endReached() ), this, SLOT( failure() ) );
m_mediaPlayer->play();
m_lengthChangedTimer->start( 3000 );
m_media->flushVolatileParameters();
}
......@@ -200,11 +208,26 @@ MetaDataWorker::finalize()
delete this;
}
void
MetaDataWorker::lengthChangedTimeout()
{
//No race condition possible, since both lengthChanged methods are called from the Qt event loop.
m_lengthChangedTimer->disconnect();
if ( m_lengthHasChanged == true )
return ; //This should never happen as this slot is beeing disconnected if a real length is computed.
disconnect( m_mediaPlayer, SIGNAL( lengthChanged( qint64 ) ),
this, SLOT( entrypointLengthChanged( qint64 ) ) );
m_lengthHasChanged = true;
if ( m_mediaIsPlaying == true )
metaDataAvailable();
}
void
MetaDataWorker::entrypointLengthChanged( qint64 newLength )
{
if ( newLength <= 0 )
return ;
m_lengthChangedTimer->disconnect();
disconnect( m_mediaPlayer, SIGNAL( lengthChanged( qint64 ) ),
this, SLOT( entrypointLengthChanged( qint64 ) ) );
m_lengthHasChanged = true;
......
......@@ -31,6 +31,8 @@
#include <QTemporaryFile>
#include <QTime>
class QTimer;
namespace LibVLCpp
{
class MediaPlayer;
......@@ -70,10 +72,12 @@ class MetaDataWorker : public QObject
unsigned char* m_audioBuffer;
QTime m_timer;
QTimer *m_lengthChangedTimer;
private slots:
void entrypointPlaying();
void entrypointLengthChanged( qint64 );
void lengthChangedTimeout();
// void generateAudioSpectrum();
void failure();
......
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