GstEnginePipeline: Replace QBasicTimer with QTimer

This commit is contained in:
Jonas Kvinge
2024-11-10 01:50:53 +01:00
parent 70d0772e04
commit b659b27f95
2 changed files with 17 additions and 17 deletions

View File

@@ -67,6 +67,7 @@
#include "gstenginepipeline.h" #include "gstenginepipeline.h"
#include "gstbufferconsumer.h" #include "gstbufferconsumer.h"
using namespace std::chrono_literals;
using namespace Qt::Literals::StringLiterals; using namespace Qt::Literals::StringLiterals;
#ifdef __clang__ #ifdef __clang__
@@ -83,7 +84,7 @@ constexpr int GST_PLAY_FLAG_BUFFERING = 0x00000100;
constexpr int GST_PLAY_FLAG_SOFT_VOLUME = 0x00000010; constexpr int GST_PLAY_FLAG_SOFT_VOLUME = 0x00000010;
constexpr int kGstStateTimeoutNanosecs = 10000000; constexpr int kGstStateTimeoutNanosecs = 10000000;
constexpr int kFaderFudgeMsec = 2000; constexpr std::chrono::milliseconds kFaderFudgeMsec = 2000ms;
constexpr int kEqBandCount = 10; constexpr int kEqBandCount = 10;
constexpr int kEqBandFrequencies[] = { 60, 170, 310, 600, 1000, 3000, 6000, 12000, 14000, 16000 }; constexpr int kEqBandFrequencies[] = { 60, 170, 310, 600, 1000, 3000, 6000, 12000, 14000, 16000 };
@@ -141,6 +142,7 @@ GstEnginePipeline::GstEnginePipeline(QObject *parent)
volume_percent_(100), volume_percent_(100),
fader_active_(false), fader_active_(false),
fader_running_(false), fader_running_(false),
timer_fader_fudge(new QTimer(this)),
use_fudge_timer_(false), use_fudge_timer_(false),
pipeline_(nullptr), pipeline_(nullptr),
audiobin_(nullptr), audiobin_(nullptr),
@@ -172,6 +174,10 @@ GstEnginePipeline::GstEnginePipeline(QObject *parent)
eq_band_gains_.reserve(kEqBandCount); eq_band_gains_.reserve(kEqBandCount);
for (int i = 0; i < kEqBandCount; ++i) eq_band_gains_ << 0; 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() { GstEnginePipeline::~GstEnginePipeline() {
@@ -2020,7 +2026,7 @@ void GstEnginePipeline::StartFader(const qint64 duration_nanosec, const QTimeLin
fader_->setEasingCurve(shape); fader_->setEasingCurve(shape);
fader_->setCurrentTime(static_cast<int>(start_time)); fader_->setCurrentTime(static_cast<int>(start_time));
fader_fudge_timer_.stop(); timer_fader_fudge->stop();
use_fudge_timer_ = use_fudge_timer; use_fudge_timer_ = use_fudge_timer;
SetFaderVolume(fader_->currentValue()); 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. // 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_) { if (use_fudge_timer_) {
fader_fudge_timer_.start(kFaderFudgeMsec, this); timer_fader_fudge->setInterval(kFaderFudgeMsec);
timer_fader_fudge->start();
} }
else { else {
// Even here we cannot emit the signal directly, as it result in a stutter when resuming playback. // 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 // 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) // (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()) { qLog(Debug) << "Pipeline" << id() << "finished fading fudge";
fader_fudge_timer_.stop();
Q_EMIT FaderFinished(id());
return;
}
QObject::timerEvent(e); Q_EMIT FaderFinished(id());
} }

View File

@@ -36,7 +36,6 @@
#include <QFuture> #include <QFuture>
#include <QTimeLine> #include <QTimeLine>
#include <QEasingCurve> #include <QEasingCurve>
#include <QBasicTimer>
#include <QList> #include <QList>
#include <QByteArray> #include <QByteArray>
#include <QVariant> #include <QVariant>
@@ -48,7 +47,6 @@
#include "core/enginemetadata.h" #include "core/enginemetadata.h"
class QTimer; class QTimer;
class QTimerEvent;
class GstBufferConsumer; class GstBufferConsumer;
struct GstPlayBin; struct GstPlayBin;
@@ -156,9 +154,6 @@ class GstEnginePipeline : public QObject {
void BufferingProgress(const int percent); void BufferingProgress(const int percent);
void BufferingFinished(); void BufferingFinished();
protected:
void timerEvent(QTimerEvent*) override;
private: private:
static QString GstStateText(const GstState state); static QString GstStateText(const GstState state);
GstElement *CreateElement(const QString &factory_name, const QString &name, GstElement *bin, QString &error) const; 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 SetFaderVolume(const qreal volume);
void FaderTimelineStateChanged(const QTimeLine::State state); void FaderTimelineStateChanged(const QTimeLine::State state);
void FaderTimelineFinished(); void FaderTimelineFinished();
void FaderTimelineFudgeFinished();
private: 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. // 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_active_;
mutex_protected<bool> fader_running_; mutex_protected<bool> fader_running_;
SharedPtr<QTimeLine> fader_; SharedPtr<QTimeLine> fader_;
QBasicTimer fader_fudge_timer_; QTimer *timer_fader_fudge;
bool use_fudge_timer_; bool use_fudge_timer_;
GstElement *pipeline_; GstElement *pipeline_;