From 694c5e9f9e1a967bf42edbf6182cd8dbdf6547a6 Mon Sep 17 00:00:00 2001 From: David Sansome Date: Sat, 15 May 2010 17:55:36 +0000 Subject: [PATCH] Wait 2 seconds after the fadeout finished before destroying the pipeline, to allow for delays in the sound server/driver. Fixes issue #294. --- src/engines/gstenginepipeline.cpp | 21 ++++++++++++++++++++- src/engines/gstenginepipeline.h | 11 ++++++++++- 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/src/engines/gstenginepipeline.cpp b/src/engines/gstenginepipeline.cpp index 38d01c7bf..63497664b 100644 --- a/src/engines/gstenginepipeline.cpp +++ b/src/engines/gstenginepipeline.cpp @@ -20,6 +20,9 @@ #include +const int GstEnginePipeline::kGstStateTimeoutNanosecs = 10000000; +const int GstEnginePipeline::kFaderFudgeMsec = 2000; + GstEnginePipeline::GstEnginePipeline(GstEngine* engine) : QObject(NULL), engine_(engine), @@ -359,10 +362,26 @@ void GstEnginePipeline::StartFader(int duration_msec, fader_ = new QTimeLine(duration_msec, this); connect(fader_, SIGNAL(valueChanged(qreal)), SLOT(SetVolumeModifier(qreal))); - connect(fader_, SIGNAL(finished()), SIGNAL(FaderFinished())); + connect(fader_, SIGNAL(finished()), SLOT(FaderTimelineFinished())); fader_->setDirection(direction); fader_->setCurveShape(shape); fader_->start(); SetVolumeModifier(fader_->currentValue()); } + +void GstEnginePipeline::FaderTimelineFinished() { + // Wait a little while longer before emitting the finished signal (and + // probably distroying the pipeline) to account for delays in the audio + // server/driver. + fader_fudge_timer_.start(kFaderFudgeMsec, this); +} + +void GstEnginePipeline::timerEvent(QTimerEvent* e) { + if (e->timerId() == fader_fudge_timer_.timerId()) { + emit FaderFinished(); + return; + } + + QObject::timerEvent(e); +} diff --git a/src/engines/gstenginepipeline.h b/src/engines/gstenginepipeline.h index 53c9fa385..6c2c037dd 100644 --- a/src/engines/gstenginepipeline.h +++ b/src/engines/gstenginepipeline.h @@ -20,6 +20,7 @@ #include #include #include +#include #include @@ -74,6 +75,9 @@ class GstEnginePipeline : public QObject { void Error(const QString& message); void FaderFinished(); + protected: + void timerEvent(QTimerEvent *); + private: // Static callbacks. The GstEnginePipeline instance is passed in the last // argument. @@ -91,8 +95,12 @@ class GstEnginePipeline : public QObject { void UpdateVolume(); bool ReplaceDecodeBin(const QUrl& url); + private slots: + void FaderTimelineFinished(); + private: - static const int kGstStateTimeoutNanosecs = 10000000; + static const int kGstStateTimeoutNanosecs; + static const int kFaderFudgeMsec; GstEngine* engine_; @@ -108,6 +116,7 @@ class GstEnginePipeline : public QObject { qreal volume_modifier_; QTimeLine* fader_; + QBasicTimer fader_fudge_timer_; GstElement* pipeline_;