From dd08a7afd5957d8ae74cd0d1cb07d6e0f755ae9a Mon Sep 17 00:00:00 2001
From: Aleix Pol Gonzalez <aleixpol@kde.org>
Date: Mon, 19 Aug 2024 10:13:01 +0000
Subject: [PATCH] sourcestream: Do not process null streams

We have a callback that tells us that a stream has been destroyed and so
we clean it up. Now we shouldn't process streams after this happened,
otherwise we crash.


(cherry picked from commit b526691684b004ff12fe52d8d86f77c21dedc996)

Co-authored-by: Aleix Pol <aleixpol@kde.org>
---
 src/pipewiresourcestream.cpp | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/src/pipewiresourcestream.cpp b/src/pipewiresourcestream.cpp
index f4fc63e..6f8242a 100644
--- a/src/pipewiresourcestream.cpp
+++ b/src/pipewiresourcestream.cpp
@@ -685,6 +685,14 @@ void PipeWireSourceStream::coreFailed(const QString &errorMessage)
 
 void PipeWireSourceStream::process()
 {
+#if !PW_CHECK_VERSION(0, 3, 73)
+    if (Q_UNLIKELY(!d->pwStream)) {
+        // Assuming it's caused by https://gitlab.freedesktop.org/pipewire/pipewire/-/issues/3314
+        qCDebug(PIPEWIRE_LOGGING) << "stream was terminated before processing buffer";
+        return;
+    }
+#endif
+
     pw_buffer *buf = pw_stream_dequeue_buffer(d->pwStream);
     if (!buf) {
         qCDebug(PIPEWIRE_LOGGING) << "out of buffers";
-- 
GitLab

