Skip to content

Commit

Permalink
GstEnginePipeline: Use SetStateAsync in finish if needed
Browse files Browse the repository at this point in the history
  • Loading branch information
jonaski committed Jan 15, 2025
1 parent ab73eda commit ab558f8
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
15 changes: 13 additions & 2 deletions src/engine/gstenginepipeline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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));
Expand All @@ -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);
Expand All @@ -1812,6 +1821,7 @@ QFuture<GstStateChangeReturn> 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<GstStateChangeReturn> *watcher = new QFutureWatcher<GstStateChangeReturn>();
Expand All @@ -1829,6 +1839,7 @@ QFuture<GstStateChangeReturn> 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) {
Expand Down
3 changes: 3 additions & 0 deletions src/engine/gstenginepipeline.h
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,9 @@ class GstEnginePipeline : public QObject {

mutex_protected<int> set_state_in_progress_;
mutex_protected<int> set_state_async_in_progress_;

mutex_protected<GstState> last_set_state_in_progress_;
mutex_protected<GstState> last_set_state_async_in_progress_;
};

using GstEnginePipelinePtr = QSharedPointer<GstEnginePipeline>;
Expand Down

0 comments on commit ab558f8

Please sign in to comment.