From ab558f87b53e2a8167e6862c106c748b7e7c9e21 Mon Sep 17 00:00:00 2001 From: Jonas Kvinge Date: Wed, 15 Jan 2025 07:01:43 +0100 Subject: [PATCH] GstEnginePipeline: Use SetStateAsync in finish if needed --- src/engine/gstenginepipeline.cpp | 15 +++++++++++++-- src/engine/gstenginepipeline.h | 3 +++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/engine/gstenginepipeline.cpp b/src/engine/gstenginepipeline.cpp index 42d75943c..7322bf758 100644 --- a/src/engine/gstenginepipeline.cpp +++ b/src/engine/gstenginepipeline.cpp @@ -176,7 +176,9 @@ GstEnginePipeline::GstEnginePipeline(QObject *parent) finish_requested_(false), finished_(false), set_state_in_progress_(0), - set_state_async_in_progress_(0) { + set_state_async_in_progress_(0), + last_set_state_in_progress_(GST_STATE_VOID_PENDING), + last_set_state_async_in_progress_(GST_STATE_VOID_PENDING) { eq_band_gains_.reserve(kEqBandCount); for (int i = 0; i < kEqBandCount; ++i) eq_band_gains_ << 0; @@ -425,7 +427,12 @@ bool GstEnginePipeline::Finish() { finished_ = true; } else { - SetState(GST_STATE_NULL); + if (set_state_async_in_progress_ > 0 && last_set_state_async_in_progress_ != GST_STATE_NULL) { + SetStateAsync(GST_STATE_NULL); + } + else if ((!IsStateNull() || set_state_in_progress_ > 0) && last_set_state_in_progress_ != GST_STATE_NULL) { + SetState(GST_STATE_NULL); + } } return finished_.value(); @@ -1794,6 +1801,7 @@ bool GstEnginePipeline::IsStateNull() const { void GstEnginePipeline::SetStateAsync(const GstState state) { + last_set_state_async_in_progress_ = state; ++set_state_async_in_progress_; QMetaObject::invokeMethod(this, "SetStateAsyncSlot", Qt::QueuedConnection, Q_ARG(GstState, state)); @@ -1802,6 +1810,7 @@ void GstEnginePipeline::SetStateAsync(const GstState state) { void GstEnginePipeline::SetStateAsyncSlot(const GstState state) { + last_set_state_async_in_progress_ = GST_STATE_VOID_PENDING; --set_state_async_in_progress_; SetState(state); @@ -1812,6 +1821,7 @@ QFuture GstEnginePipeline::SetState(const GstState state) qLog(Debug) << "Setting pipeline" << id() << "state to" << GstStateText(state); + last_set_state_in_progress_ = state; ++set_state_in_progress_; QFutureWatcher *watcher = new QFutureWatcher(); @@ -1829,6 +1839,7 @@ QFuture GstEnginePipeline::SetState(const GstState state) void GstEnginePipeline::SetStateFinishedSlot(const GstState state, const GstStateChangeReturn state_change_return) { + last_set_state_in_progress_ = GST_STATE_VOID_PENDING; --set_state_in_progress_; switch (state_change_return) { diff --git a/src/engine/gstenginepipeline.h b/src/engine/gstenginepipeline.h index 96ff87424..476fddb6f 100644 --- a/src/engine/gstenginepipeline.h +++ b/src/engine/gstenginepipeline.h @@ -373,6 +373,9 @@ class GstEnginePipeline : public QObject { mutex_protected set_state_in_progress_; mutex_protected set_state_async_in_progress_; + + mutex_protected last_set_state_in_progress_; + mutex_protected last_set_state_async_in_progress_; }; using GstEnginePipelinePtr = QSharedPointer;