[mutter] screen-cast: Handle PipeWire errors



commit 9d8922764cbf03f1d35a8acb7e9a0d58969fcb20
Author: Jonas Ådahl <jadahl gmail com>
Date:   Mon Jun 26 12:50:26 2017 +0800

    screen-cast: Handle PipeWire errors
    
    When the PipeWire context or stream ends up in an error state, signal
    that the source has closed. This then triggers the stream and finally
    the session to be closed too.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=784199

 src/backends/meta-screen-cast-stream-src.c |   40 ++++++++++++++++++++++++++++
 src/backends/meta-screen-cast-stream.c     |   12 ++++++++
 2 files changed, 52 insertions(+), 0 deletions(-)
---
diff --git a/src/backends/meta-screen-cast-stream-src.c b/src/backends/meta-screen-cast-stream-src.c
index 5e64846..214fdbe 100644
--- a/src/backends/meta-screen-cast-stream-src.c
+++ b/src/backends/meta-screen-cast-stream-src.c
@@ -50,6 +50,15 @@ enum
   PROP_STREAM_ID,
 };
 
+enum
+{
+  CLOSED,
+
+  N_SIGNALS
+};
+
+static guint signals[N_SIGNALS];
+
 typedef struct _MetaSpaType
 {
   uint32_t format;
@@ -189,11 +198,33 @@ meta_screen_cast_stream_src_maybe_record_frame (MetaScreenCastStreamSrc *src)
 }
 
 static void
+meta_screen_cast_stream_src_notify_closed (MetaScreenCastStreamSrc *src)
+{
+  g_signal_emit (src, signals[CLOSED], 0);
+}
+
+static void
 on_stream_state_changed (void                 *data,
                          enum pw_stream_state  old,
                          enum pw_stream_state  state,
                          const char           *error_message)
 {
+  MetaScreenCastStreamSrc *src = data;
+
+  switch (state)
+    {
+    case PW_STREAM_STATE_ERROR:
+      g_warning ("pipewire stream error: %s", error_message);
+      meta_screen_cast_stream_src_notify_closed (src);
+      break;
+    case PW_STREAM_STATE_UNCONNECTED:
+    case PW_STREAM_STATE_CONNECTING:
+    case PW_STREAM_STATE_CONFIGURE:
+    case PW_STREAM_STATE_READY:
+    case PW_STREAM_STATE_PAUSED:
+    case PW_STREAM_STATE_STREAMING:
+      break;
+    }
 }
 
 static void
@@ -341,6 +372,7 @@ on_state_changed (void                 *data,
     {
     case PW_REMOTE_STATE_ERROR:
       g_warning ("pipewire remote error: %s\n", error_message);
+      meta_screen_cast_stream_src_notify_closed (src);
       break;
     case PW_REMOTE_STATE_CONNECTED:
       pipewire_stream = create_pipewire_stream (src, &error);
@@ -348,6 +380,7 @@ on_state_changed (void                 *data,
         {
           g_warning ("Could not create pipewire stream: %s", error->message);
           g_error_free (error);
+          meta_screen_cast_stream_src_notify_closed (src);
         }
       else
         {
@@ -594,4 +627,11 @@ meta_screen_cast_stream_src_class_init (MetaScreenCastStreamSrcClass *klass)
                                                         G_PARAM_READWRITE |
                                                         G_PARAM_CONSTRUCT_ONLY |
                                                         G_PARAM_STATIC_STRINGS));
+
+  signals[CLOSED] = g_signal_new ("closed",
+                                  G_TYPE_FROM_CLASS (klass),
+                                  G_SIGNAL_RUN_LAST,
+                                  0,
+                                  NULL, NULL, NULL,
+                                  G_TYPE_NONE, 0);
 }
diff --git a/src/backends/meta-screen-cast-stream.c b/src/backends/meta-screen-cast-stream.c
index 8d7a6df..047f287 100644
--- a/src/backends/meta-screen-cast-stream.c
+++ b/src/backends/meta-screen-cast-stream.c
@@ -70,6 +70,17 @@ meta_screen_cast_stream_create_src (MetaScreenCastStream  *stream,
                                                                  error);
 }
 
+static void
+on_stream_src_closed (MetaScreenCastStreamSrc *src,
+                      MetaScreenCastStream    *stream)
+{
+  MetaScreenCastStreamPrivate *priv =
+    meta_screen_cast_stream_get_instance_private (stream);
+
+  if (priv->src)
+    meta_screen_cast_stream_close (stream);
+}
+
 gboolean
 meta_screen_cast_stream_start (MetaScreenCastStream  *stream,
                                GError               **error)
@@ -87,6 +98,7 @@ meta_screen_cast_stream_start (MetaScreenCastStream  *stream,
     return FALSE;
 
   priv->src = src;
+  g_signal_connect (src, "closed", G_CALLBACK (on_stream_src_closed), stream);
 
   meta_dbus_screen_cast_stream_emit_pipewire_stream_added (skeleton, stream_id);
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]