screen-cast/src: Add helper to close stream after dispatch

This is needed to close the stream from non-abstract sources during
PipeWire dispatch.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1698>
This commit is contained in:
Jonas Ådahl 2021-02-01 09:54:56 +01:00 committed by Marge Bot
parent 688280f82d
commit cf5836a6ec
2 changed files with 15 additions and 10 deletions

View File

@ -640,6 +640,17 @@ meta_screen_cast_stream_src_disable (MetaScreenCastStreamSrc *src)
priv->is_enabled = FALSE; priv->is_enabled = FALSE;
} }
void
meta_screen_cast_stream_src_close (MetaScreenCastStreamSrc *src)
{
MetaScreenCastStreamSrcPrivate *priv =
meta_screen_cast_stream_src_get_instance_private (src);
if (meta_screen_cast_stream_src_is_enabled (src))
meta_screen_cast_stream_src_disable (src);
priv->emit_closed_after_dispatch = TRUE;
}
static void static void
on_stream_state_changed (void *data, on_stream_state_changed (void *data,
enum pw_stream_state old, enum pw_stream_state old,
@ -654,9 +665,7 @@ on_stream_state_changed (void *data,
{ {
case PW_STREAM_STATE_ERROR: case PW_STREAM_STATE_ERROR:
g_warning ("pipewire stream error: %s", error_message); g_warning ("pipewire stream error: %s", error_message);
if (meta_screen_cast_stream_src_is_enabled (src)) meta_screen_cast_stream_src_close (src);
meta_screen_cast_stream_src_disable (src);
priv->emit_closed_after_dispatch = TRUE;
break; break;
case PW_STREAM_STATE_PAUSED: case PW_STREAM_STATE_PAUSED:
if (priv->node_id == SPA_ID_INVALID && priv->pipewire_stream) if (priv->node_id == SPA_ID_INVALID && priv->pipewire_stream)
@ -942,17 +951,11 @@ on_core_error (void *data,
const char *message) const char *message)
{ {
MetaScreenCastStreamSrc *src = data; MetaScreenCastStreamSrc *src = data;
MetaScreenCastStreamSrcPrivate *priv =
meta_screen_cast_stream_src_get_instance_private (src);
g_warning ("pipewire remote error: id:%u %s", id, message); g_warning ("pipewire remote error: id:%u %s", id, message);
if (id == PW_ID_CORE && res == -EPIPE) if (id == PW_ID_CORE && res == -EPIPE)
{ meta_screen_cast_stream_src_close (src);
if (meta_screen_cast_stream_src_is_enabled (src))
meta_screen_cast_stream_src_disable (src);
priv->emit_closed_after_dispatch = TRUE;
}
} }
static gboolean static gboolean

View File

@ -76,6 +76,8 @@ struct _MetaScreenCastStreamSrcClass
struct spa_meta_cursor *spa_meta_cursor); struct spa_meta_cursor *spa_meta_cursor);
}; };
void meta_screen_cast_stream_src_close (MetaScreenCastStreamSrc *src);
void meta_screen_cast_stream_src_maybe_record_frame (MetaScreenCastStreamSrc *src, void meta_screen_cast_stream_src_maybe_record_frame (MetaScreenCastStreamSrc *src,
MetaScreenCastRecordFlag flags); MetaScreenCastRecordFlag flags);