GstEnginePipeline: Replace QBasicTimer with QTimer
This commit is contained in:
parent
70d0772e04
commit
b659b27f95
@ -67,6 +67,7 @@
|
||||
#include "gstenginepipeline.h"
|
||||
#include "gstbufferconsumer.h"
|
||||
|
||||
using namespace std::chrono_literals;
|
||||
using namespace Qt::Literals::StringLiterals;
|
||||
|
||||
#ifdef __clang__
|
||||
@ -83,7 +84,7 @@ constexpr int GST_PLAY_FLAG_BUFFERING = 0x00000100;
|
||||
constexpr int GST_PLAY_FLAG_SOFT_VOLUME = 0x00000010;
|
||||
|
||||
constexpr int kGstStateTimeoutNanosecs = 10000000;
|
||||
constexpr int kFaderFudgeMsec = 2000;
|
||||
constexpr std::chrono::milliseconds kFaderFudgeMsec = 2000ms;
|
||||
|
||||
constexpr int kEqBandCount = 10;
|
||||
constexpr int kEqBandFrequencies[] = { 60, 170, 310, 600, 1000, 3000, 6000, 12000, 14000, 16000 };
|
||||
@ -141,6 +142,7 @@ GstEnginePipeline::GstEnginePipeline(QObject *parent)
|
||||
volume_percent_(100),
|
||||
fader_active_(false),
|
||||
fader_running_(false),
|
||||
timer_fader_fudge(new QTimer(this)),
|
||||
use_fudge_timer_(false),
|
||||
pipeline_(nullptr),
|
||||
audiobin_(nullptr),
|
||||
@ -172,6 +174,10 @@ GstEnginePipeline::GstEnginePipeline(QObject *parent)
|
||||
eq_band_gains_.reserve(kEqBandCount);
|
||||
for (int i = 0; i < kEqBandCount; ++i) eq_band_gains_ << 0;
|
||||
|
||||
timer_fader_fudge->setSingleShot(true);
|
||||
timer_fader_fudge->setInterval(kFaderFudgeMsec);
|
||||
QObject::connect(timer_fader_fudge, &QTimer::timeout, this, &GstEnginePipeline::FaderTimelineFudgeFinished);
|
||||
|
||||
}
|
||||
|
||||
GstEnginePipeline::~GstEnginePipeline() {
|
||||
@ -2020,7 +2026,7 @@ void GstEnginePipeline::StartFader(const qint64 duration_nanosec, const QTimeLin
|
||||
fader_->setEasingCurve(shape);
|
||||
fader_->setCurrentTime(static_cast<int>(start_time));
|
||||
|
||||
fader_fudge_timer_.stop();
|
||||
timer_fader_fudge->stop();
|
||||
use_fudge_timer_ = use_fudge_timer;
|
||||
|
||||
SetFaderVolume(fader_->currentValue());
|
||||
@ -2066,26 +2072,24 @@ void GstEnginePipeline::FaderTimelineFinished() {
|
||||
|
||||
// Wait a little while longer before emitting the finished signal (and probably destroying the pipeline) to account for delays in the audio server/driver.
|
||||
if (use_fudge_timer_) {
|
||||
fader_fudge_timer_.start(kFaderFudgeMsec, this);
|
||||
timer_fader_fudge->setInterval(kFaderFudgeMsec);
|
||||
timer_fader_fudge->start();
|
||||
}
|
||||
else {
|
||||
// Even here we cannot emit the signal directly, as it result in a stutter when resuming playback.
|
||||
// So use a quest small time, so you won't notice the difference when resuming playback
|
||||
// (You get here when the pause fading is active)
|
||||
fader_fudge_timer_.start(250, this);
|
||||
timer_fader_fudge->setInterval(250ms);
|
||||
timer_fader_fudge->start();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void GstEnginePipeline::timerEvent(QTimerEvent *e) {
|
||||
void GstEnginePipeline::FaderTimelineFudgeFinished() {
|
||||
|
||||
if (e->timerId() == fader_fudge_timer_.timerId()) {
|
||||
fader_fudge_timer_.stop();
|
||||
Q_EMIT FaderFinished(id());
|
||||
return;
|
||||
}
|
||||
qLog(Debug) << "Pipeline" << id() << "finished fading fudge";
|
||||
|
||||
QObject::timerEvent(e);
|
||||
Q_EMIT FaderFinished(id());
|
||||
|
||||
}
|
||||
|
||||
|
@ -36,7 +36,6 @@
|
||||
#include <QFuture>
|
||||
#include <QTimeLine>
|
||||
#include <QEasingCurve>
|
||||
#include <QBasicTimer>
|
||||
#include <QList>
|
||||
#include <QByteArray>
|
||||
#include <QVariant>
|
||||
@ -48,7 +47,6 @@
|
||||
#include "core/enginemetadata.h"
|
||||
|
||||
class QTimer;
|
||||
class QTimerEvent;
|
||||
class GstBufferConsumer;
|
||||
struct GstPlayBin;
|
||||
|
||||
@ -156,9 +154,6 @@ class GstEnginePipeline : public QObject {
|
||||
void BufferingProgress(const int percent);
|
||||
void BufferingFinished();
|
||||
|
||||
protected:
|
||||
void timerEvent(QTimerEvent*) override;
|
||||
|
||||
private:
|
||||
static QString GstStateText(const GstState state);
|
||||
GstElement *CreateElement(const QString &factory_name, const QString &name, GstElement *bin, QString &error) const;
|
||||
@ -204,6 +199,7 @@ class GstEnginePipeline : public QObject {
|
||||
void SetFaderVolume(const qreal volume);
|
||||
void FaderTimelineStateChanged(const QTimeLine::State state);
|
||||
void FaderTimelineFinished();
|
||||
void FaderTimelineFudgeFinished();
|
||||
|
||||
private:
|
||||
// Using == to compare two pipelines is a bad idea, because new ones often get created in the same address as old ones. This ID will be unique for each pipeline.
|
||||
@ -333,7 +329,7 @@ class GstEnginePipeline : public QObject {
|
||||
mutex_protected<bool> fader_active_;
|
||||
mutex_protected<bool> fader_running_;
|
||||
SharedPtr<QTimeLine> fader_;
|
||||
QBasicTimer fader_fudge_timer_;
|
||||
QTimer *timer_fader_fudge;
|
||||
bool use_fudge_timer_;
|
||||
|
||||
GstElement *pipeline_;
|
||||
|
Loading…
x
Reference in New Issue
Block a user