From ba285925caa3a7fba23b0f25eaf04e86fabd50a4 Mon Sep 17 00:00:00 2001 From: Jonas Kvinge Date: Sat, 9 Nov 2024 19:30:28 +0100 Subject: [PATCH] GstEnginePipeline: Check that state is actually NULL before finishing pipeline Possible fix for #1582 --- src/engine/gstenginepipeline.cpp | 15 ++++++++++++++- src/engine/gstenginepipeline.h | 1 + 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/engine/gstenginepipeline.cpp b/src/engine/gstenginepipeline.cpp index e6291878d..bdcd75285 100644 --- a/src/engine/gstenginepipeline.cpp +++ b/src/engine/gstenginepipeline.cpp @@ -404,7 +404,7 @@ bool GstEnginePipeline::Finish() { Disconnect(); - if (state() == GST_STATE_NULL) { + if (IsStateNull()) { finished_ = true; } else { @@ -1784,6 +1784,19 @@ qint64 GstEnginePipeline::position() const { } +bool GstEnginePipeline::IsStateNull() const { + + if (!pipeline_) return true; + + GstState s = GST_STATE_NULL, sp = GST_STATE_NULL; + if (gst_element_get_state(pipeline_, &s, &sp, kGstStateTimeoutNanosecs) == GST_STATE_CHANGE_FAILURE) { + return false; + } + + return s == GST_STATE_NULL; + +} + QFuture GstEnginePipeline::SetStateAsync(const GstState state) { qLog(Debug) << "Setting pipeline" << id() << "state to" << GstStateText(state); diff --git a/src/engine/gstenginepipeline.h b/src/engine/gstenginepipeline.h index 4e255f38b..a91c04fe4 100644 --- a/src/engine/gstenginepipeline.h +++ b/src/engine/gstenginepipeline.h @@ -162,6 +162,7 @@ class GstEnginePipeline : public QObject { private: static QString GstStateText(const GstState state); GstElement *CreateElement(const QString &factory_name, const QString &name, GstElement *bin, QString &error) const; + bool IsStateNull() const; bool InitAudioBin(QString &error); void SetupVolume(GstElement *element);