From eb9ef1da8d7b38558f1874afc91ec6a5f4df075a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonas=20=C3=85dahl?= Date: Mon, 26 Jun 2023 22:04:26 +0200 Subject: [PATCH] screen-cast/src: Queue follow up frame if no buffers If we tried to record but did so before the buffers had the chance to be added, schedule another follow up frame once the buffers start rolling in. Part-of: --- src/backends/meta-screen-cast-stream-src.c | 24 ++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/backends/meta-screen-cast-stream-src.c b/src/backends/meta-screen-cast-stream-src.c index 94fc222e4..0fa68e37b 100644 --- a/src/backends/meta-screen-cast-stream-src.c +++ b/src/backends/meta-screen-cast-stream-src.c @@ -107,6 +107,9 @@ typedef struct _MetaScreenCastStreamSrcPrivate int64_t last_frame_timestamp_us; guint follow_up_frame_source_id; + int buffer_count; + gboolean needs_follow_up_with_buffers; + gboolean uses_dma_bufs; GHashTable *dmabuf_handles; @@ -714,6 +717,17 @@ meta_screen_cast_stream_src_maybe_record_frame_with_timestamp (MetaScreenCastStr priv->redraw_clip = cairo_region_copy (redraw_clip); } + if (priv->buffer_count == 0) + { + meta_topic (META_DEBUG_SCREEN_CAST, + "Buffers hasn't been added, " + "postponing recording on stream %u", + priv->node_id); + + priv->needs_follow_up_with_buffers = TRUE; + return record_result; + } + if (priv->video_format.max_framerate.num > 0 && priv->last_frame_timestamp_us != 0) { @@ -1035,6 +1049,8 @@ on_stream_add_buffer (void *data, const int bpp = 4; int stride; + priv->buffer_count++; + stride = SPA_ROUND_UP_N (priv->video_format.size.width * bpp, 4); spa_data[0].mapoffset = 0; @@ -1123,6 +1139,12 @@ on_stream_add_buffer (void *data, return; } } + + if (priv->buffer_count == 1 && priv->needs_follow_up_with_buffers) + { + priv->needs_follow_up_with_buffers = FALSE; + meta_screen_cast_stream_src_record_follow_up (src); + } } static void @@ -1135,6 +1157,8 @@ on_stream_remove_buffer (void *data, struct spa_buffer *spa_buffer = buffer->buffer; struct spa_data *spa_data = spa_buffer->datas; + priv->buffer_count--; + if (spa_data[0].type == SPA_DATA_DmaBuf) { if (!g_hash_table_remove (priv->dmabuf_handles, GINT_TO_POINTER (spa_data[0].fd)))