[vlmc-devel] commit: MetadataWorker: Don't hang if the file has no length. ( Hugo Beauzée-Luyssen )
git at videolan.org
git at videolan.org
Sat Jul 3 17:21:49 CEST 2010
vlmc | branch: master | Hugo Beauzée-Luyssen <beauze.h at gmail.com> | Thu Jul 1 17:32:19 2010 +0200| [1a0b7c659e4cfe70c6e2cc4616cd9af8217f4277] | committer: Hugo Beauzée-Luyssen
MetadataWorker: Don't hang if the file has no length.
> http://git.videolan.org/gitweb.cgi/vlmc.git/?a=commit;h=1a0b7c659e4cfe70c6e2cc4616cd9af8217f4277
---
src/Metadata/MetaDataWorker.cpp | 23 +++++++++++++++++++++++
src/Metadata/MetaDataWorker.h | 4 ++++
2 files changed, 27 insertions(+), 0 deletions(-)
diff --git a/src/Metadata/MetaDataWorker.cpp b/src/Metadata/MetaDataWorker.cpp
index 0590743..4d8091a 100644
--- a/src/Metadata/MetaDataWorker.cpp
+++ b/src/Metadata/MetaDataWorker.cpp
@@ -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();
}
@@ -201,10 +209,25 @@ MetaDataWorker::finalize()
}
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;
diff --git a/src/Metadata/MetaDataWorker.h b/src/Metadata/MetaDataWorker.h
index 6795cdb..9281179 100644
--- a/src/Metadata/MetaDataWorker.h
+++ b/src/Metadata/MetaDataWorker.h
@@ -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();
More information about the Vlmc-devel
mailing list