From 2d899596e21d43ab241d0ba37c0a9f90c2e610be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonas=20=C3=85dahl?= Date: Fri, 3 Jul 2020 16:57:01 +0200 Subject: [PATCH] screen-cast/src: Make record functions return an error when failing Now that we don't use the record function to early out depending on implicit state (don't record pixels if only cursor moved for example), let it simply report an error when it fails, as we should no longer ever return without pixels if nothing failed. https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1351 --- .../meta-screen-cast-monitor-stream-src.c | 19 +++++------ src/backends/meta-screen-cast-stream-src.c | 32 ++++++++++++------- src/backends/meta-screen-cast-stream-src.h | 10 +++--- .../meta-screen-cast-window-stream-src.c | 16 +++++++--- 4 files changed, 45 insertions(+), 32 deletions(-) diff --git a/src/backends/meta-screen-cast-monitor-stream-src.c b/src/backends/meta-screen-cast-monitor-stream-src.c index 17aa7aeb4..570f16b4e 100644 --- a/src/backends/meta-screen-cast-monitor-stream-src.c +++ b/src/backends/meta-screen-cast-monitor-stream-src.c @@ -366,8 +366,9 @@ meta_screen_cast_monitor_stream_src_disable (MetaScreenCastStreamSrc *src) } static gboolean -meta_screen_cast_monitor_stream_src_record_to_buffer (MetaScreenCastStreamSrc *src, - uint8_t *data) +meta_screen_cast_monitor_stream_src_record_to_buffer (MetaScreenCastStreamSrc *src, + uint8_t *data, + GError **error) { MetaScreenCastMonitorStreamSrc *monitor_src = META_SCREEN_CAST_MONITOR_STREAM_SRC (src); @@ -384,8 +385,9 @@ meta_screen_cast_monitor_stream_src_record_to_buffer (MetaScreenCastStreamSrc *s } static gboolean -meta_screen_cast_monitor_stream_src_record_to_framebuffer (MetaScreenCastStreamSrc *src, - CoglFramebuffer *framebuffer) +meta_screen_cast_monitor_stream_src_record_to_framebuffer (MetaScreenCastStreamSrc *src, + CoglFramebuffer *framebuffer, + GError **error) { MetaScreenCastMonitorStreamSrc *monitor_src = META_SCREEN_CAST_MONITOR_STREAM_SRC (src); @@ -409,7 +411,6 @@ meta_screen_cast_monitor_stream_src_record_to_framebuffer (MetaScreenCastStreamS for (l = meta_renderer_get_views (renderer); l; l = l->next) { ClutterStageView *view = CLUTTER_STAGE_VIEW (l->data); - g_autoptr (GError) error = NULL; CoglFramebuffer *view_framebuffer; MetaRectangle view_layout; int x, y; @@ -430,12 +431,8 @@ meta_screen_cast_monitor_stream_src_record_to_framebuffer (MetaScreenCastStreamS x, y, cogl_framebuffer_get_width (view_framebuffer), cogl_framebuffer_get_height (view_framebuffer), - &error)) - { - g_warning ("Error blitting view into DMABuf framebuffer: %s", - error->message); - return FALSE; - } + error)) + return FALSE; } cogl_framebuffer_finish (framebuffer); diff --git a/src/backends/meta-screen-cast-stream-src.c b/src/backends/meta-screen-cast-stream-src.c index 463d316eb..4b7911957 100644 --- a/src/backends/meta-screen-cast-stream-src.c +++ b/src/backends/meta-screen-cast-stream-src.c @@ -135,23 +135,25 @@ meta_screen_cast_stream_src_get_videocrop (MetaScreenCastStreamSrc *src, } static gboolean -meta_screen_cast_stream_src_record_to_buffer (MetaScreenCastStreamSrc *src, - uint8_t *data) +meta_screen_cast_stream_src_record_to_buffer (MetaScreenCastStreamSrc *src, + uint8_t *data, + GError **error) { MetaScreenCastStreamSrcClass *klass = META_SCREEN_CAST_STREAM_SRC_GET_CLASS (src); - return klass->record_to_buffer (src, data); + return klass->record_to_buffer (src, data, error); } static gboolean -meta_screen_cast_stream_src_record_to_framebuffer (MetaScreenCastStreamSrc *src, - CoglFramebuffer *framebuffer) +meta_screen_cast_stream_src_record_to_framebuffer (MetaScreenCastStreamSrc *src, + CoglFramebuffer *framebuffer, + GError **error) { MetaScreenCastStreamSrcClass *klass = META_SCREEN_CAST_STREAM_SRC_GET_CLASS (src); - return klass->record_to_framebuffer (src, framebuffer); + return klass->record_to_framebuffer (src, framebuffer, error); } static void @@ -409,9 +411,10 @@ maybe_record_cursor (MetaScreenCastStreamSrc *src, } static gboolean -do_record_frame (MetaScreenCastStreamSrc *src, - struct spa_buffer *spa_buffer, - uint8_t *data) +do_record_frame (MetaScreenCastStreamSrc *src, + struct spa_buffer *spa_buffer, + uint8_t *data, + GError **error) { MetaScreenCastStreamSrcPrivate *priv = meta_screen_cast_stream_src_get_instance_private (src); @@ -419,7 +422,7 @@ do_record_frame (MetaScreenCastStreamSrc *src, if (spa_buffer->datas[0].data || spa_buffer->datas[0].type == SPA_DATA_MemFd) { - return meta_screen_cast_stream_src_record_to_buffer (src, data); + return meta_screen_cast_stream_src_record_to_buffer (src, data, error); } else if (spa_buffer->datas[0].type == SPA_DATA_DmaBuf) { @@ -430,9 +433,12 @@ do_record_frame (MetaScreenCastStreamSrc *src, cogl_dma_buf_handle_get_framebuffer (dmabuf_handle); return meta_screen_cast_stream_src_record_to_framebuffer (src, - dmabuf_fbo); + dmabuf_fbo, + error); } + g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, + "Unknown SPA buffer type %u", spa_buffer->datas[0].type); return FALSE; } @@ -447,6 +453,7 @@ meta_screen_cast_stream_src_maybe_record_frame (MetaScreenCastStreamSrc *src, struct spa_buffer *spa_buffer; uint8_t *data = NULL; uint64_t now_us; + g_autoptr (GError) error = NULL; now_us = g_get_monotonic_time (); if (priv->video_format.max_framerate.num > 0 && @@ -474,7 +481,7 @@ meta_screen_cast_stream_src_maybe_record_frame (MetaScreenCastStreamSrc *src, if (!(flags & META_SCREEN_CAST_RECORD_FLAG_CURSOR_ONLY)) { - if (do_record_frame (src, spa_buffer, data)) + if (do_record_frame (src, spa_buffer, data, &error)) { struct spa_meta_region *spa_meta_video_crop; @@ -505,6 +512,7 @@ meta_screen_cast_stream_src_maybe_record_frame (MetaScreenCastStreamSrc *src, } else { + g_warning ("Failed to record screen cast frame: %s", error->message); spa_buffer->datas[0].chunk->size = 0; } } diff --git a/src/backends/meta-screen-cast-stream-src.h b/src/backends/meta-screen-cast-stream-src.h index 87054eedf..152790ecf 100644 --- a/src/backends/meta-screen-cast-stream-src.h +++ b/src/backends/meta-screen-cast-stream-src.h @@ -59,10 +59,12 @@ struct _MetaScreenCastStreamSrcClass float *frame_rate); void (* enable) (MetaScreenCastStreamSrc *src); void (* disable) (MetaScreenCastStreamSrc *src); - gboolean (* record_to_buffer) (MetaScreenCastStreamSrc *src, - uint8_t *data); - gboolean (* record_to_framebuffer) (MetaScreenCastStreamSrc *src, - CoglFramebuffer *framebuffer); + gboolean (* record_to_buffer) (MetaScreenCastStreamSrc *src, + uint8_t *data, + GError **error); + gboolean (* record_to_framebuffer) (MetaScreenCastStreamSrc *src, + CoglFramebuffer *framebuffer, + GError **error); gboolean (* get_videocrop) (MetaScreenCastStreamSrc *src, MetaRectangle *crop_rect); void (* set_cursor_metadata) (MetaScreenCastStreamSrc *src, diff --git a/src/backends/meta-screen-cast-window-stream-src.c b/src/backends/meta-screen-cast-window-stream-src.c index dfc5baa1a..a504bd194 100644 --- a/src/backends/meta-screen-cast-window-stream-src.c +++ b/src/backends/meta-screen-cast-window-stream-src.c @@ -457,8 +457,9 @@ meta_screen_cast_window_stream_src_disable (MetaScreenCastStreamSrc *src) } static gboolean -meta_screen_cast_window_stream_src_record_to_buffer (MetaScreenCastStreamSrc *src, - uint8_t *data) +meta_screen_cast_window_stream_src_record_to_buffer (MetaScreenCastStreamSrc *src, + uint8_t *data, + GError **error) { MetaScreenCastWindowStreamSrc *window_src = META_SCREEN_CAST_WINDOW_STREAM_SRC (src); @@ -469,8 +470,9 @@ meta_screen_cast_window_stream_src_record_to_buffer (MetaScreenCastStreamSrc *sr } static gboolean -meta_screen_cast_window_stream_src_record_to_framebuffer (MetaScreenCastStreamSrc *src, - CoglFramebuffer *framebuffer) +meta_screen_cast_window_stream_src_record_to_framebuffer (MetaScreenCastStreamSrc *src, + CoglFramebuffer *framebuffer, + GError **error) { MetaScreenCastWindowStreamSrc *window_src = META_SCREEN_CAST_WINDOW_STREAM_SRC (src); @@ -485,7 +487,11 @@ meta_screen_cast_window_stream_src_record_to_framebuffer (MetaScreenCastStreamSr if (!meta_screen_cast_window_blit_to_framebuffer (window_src->screen_cast_window, &stream_rect, framebuffer)) - return FALSE; + { + g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, + "Failed to blit window content to framebuffer"); + return FALSE; + } stream = meta_screen_cast_stream_src_get_stream (src); switch (meta_screen_cast_stream_get_cursor_mode (stream))