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/1361
This commit is contained in:
Jonas Ådahl 2020-07-03 16:57:01 +02:00
parent 882967d3ce
commit 047da80c3b
5 changed files with 53 additions and 42 deletions

View File

@ -393,7 +393,8 @@ meta_screen_cast_area_stream_src_disable (MetaScreenCastStreamSrc *src)
static gboolean static gboolean
meta_screen_cast_area_stream_src_record_to_buffer (MetaScreenCastStreamSrc *src, meta_screen_cast_area_stream_src_record_to_buffer (MetaScreenCastStreamSrc *src,
uint8_t *data) uint8_t *data,
GError **error)
{ {
MetaScreenCastAreaStreamSrc *area_src = MetaScreenCastAreaStreamSrc *area_src =
META_SCREEN_CAST_AREA_STREAM_SRC (src); META_SCREEN_CAST_AREA_STREAM_SRC (src);
@ -404,7 +405,6 @@ meta_screen_cast_area_stream_src_record_to_buffer (MetaScreenCastStreamSrc *src,
float scale; float scale;
int stride; int stride;
ClutterPaintFlag paint_flags = CLUTTER_PAINT_FLAG_NONE; ClutterPaintFlag paint_flags = CLUTTER_PAINT_FLAG_NONE;
g_autoptr (GError) error = NULL;
stage = get_stage (area_src); stage = get_stage (area_src);
area = meta_screen_cast_area_stream_get_area (area_stream); area = meta_screen_cast_area_stream_get_area (area_stream);
@ -426,18 +426,16 @@ meta_screen_cast_area_stream_src_record_to_buffer (MetaScreenCastStreamSrc *src,
stride, stride,
CLUTTER_CAIRO_FORMAT_ARGB32, CLUTTER_CAIRO_FORMAT_ARGB32,
paint_flags, paint_flags,
&error)) error))
{
g_warning ("Failed to record area: %s", error->message);
return FALSE; return FALSE;
}
return TRUE; return TRUE;
} }
static gboolean static gboolean
meta_screen_cast_area_stream_src_record_to_framebuffer (MetaScreenCastStreamSrc *src, meta_screen_cast_area_stream_src_record_to_framebuffer (MetaScreenCastStreamSrc *src,
CoglFramebuffer *framebuffer) CoglFramebuffer *framebuffer,
GError **error)
{ {
MetaScreenCastAreaStreamSrc *area_src = MetaScreenCastAreaStreamSrc *area_src =
META_SCREEN_CAST_AREA_STREAM_SRC (src); META_SCREEN_CAST_AREA_STREAM_SRC (src);

View File

@ -388,7 +388,8 @@ meta_screen_cast_monitor_stream_src_disable (MetaScreenCastStreamSrc *src)
static gboolean static gboolean
meta_screen_cast_monitor_stream_src_record_to_buffer (MetaScreenCastStreamSrc *src, meta_screen_cast_monitor_stream_src_record_to_buffer (MetaScreenCastStreamSrc *src,
uint8_t *data) uint8_t *data,
GError **error)
{ {
MetaScreenCastMonitorStreamSrc *monitor_src = MetaScreenCastMonitorStreamSrc *monitor_src =
META_SCREEN_CAST_MONITOR_STREAM_SRC (src); META_SCREEN_CAST_MONITOR_STREAM_SRC (src);
@ -406,7 +407,8 @@ meta_screen_cast_monitor_stream_src_record_to_buffer (MetaScreenCastStreamSrc *s
static gboolean static gboolean
meta_screen_cast_monitor_stream_src_record_to_framebuffer (MetaScreenCastStreamSrc *src, meta_screen_cast_monitor_stream_src_record_to_framebuffer (MetaScreenCastStreamSrc *src,
CoglFramebuffer *framebuffer) CoglFramebuffer *framebuffer,
GError **error)
{ {
MetaScreenCastMonitorStreamSrc *monitor_src = MetaScreenCastMonitorStreamSrc *monitor_src =
META_SCREEN_CAST_MONITOR_STREAM_SRC (src); META_SCREEN_CAST_MONITOR_STREAM_SRC (src);
@ -430,7 +432,6 @@ meta_screen_cast_monitor_stream_src_record_to_framebuffer (MetaScreenCastStreamS
for (l = meta_renderer_get_views (renderer); l; l = l->next) for (l = meta_renderer_get_views (renderer); l; l = l->next)
{ {
ClutterStageView *view = CLUTTER_STAGE_VIEW (l->data); ClutterStageView *view = CLUTTER_STAGE_VIEW (l->data);
g_autoptr (GError) error = NULL;
CoglFramebuffer *view_framebuffer; CoglFramebuffer *view_framebuffer;
MetaRectangle view_layout; MetaRectangle view_layout;
int x, y; int x, y;
@ -451,13 +452,9 @@ meta_screen_cast_monitor_stream_src_record_to_framebuffer (MetaScreenCastStreamS
x, y, x, y,
cogl_framebuffer_get_width (view_framebuffer), cogl_framebuffer_get_width (view_framebuffer),
cogl_framebuffer_get_height (view_framebuffer), cogl_framebuffer_get_height (view_framebuffer),
&error)) error))
{
g_warning ("Error blitting view into DMABuf framebuffer: %s",
error->message);
return FALSE; return FALSE;
} }
}
cogl_framebuffer_finish (framebuffer); cogl_framebuffer_finish (framebuffer);

View File

@ -136,22 +136,24 @@ meta_screen_cast_stream_src_get_videocrop (MetaScreenCastStreamSrc *src,
static gboolean static gboolean
meta_screen_cast_stream_src_record_to_buffer (MetaScreenCastStreamSrc *src, meta_screen_cast_stream_src_record_to_buffer (MetaScreenCastStreamSrc *src,
uint8_t *data) uint8_t *data,
GError **error)
{ {
MetaScreenCastStreamSrcClass *klass = MetaScreenCastStreamSrcClass *klass =
META_SCREEN_CAST_STREAM_SRC_GET_CLASS (src); 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 static gboolean
meta_screen_cast_stream_src_record_to_framebuffer (MetaScreenCastStreamSrc *src, meta_screen_cast_stream_src_record_to_framebuffer (MetaScreenCastStreamSrc *src,
CoglFramebuffer *framebuffer) CoglFramebuffer *framebuffer,
GError **error)
{ {
MetaScreenCastStreamSrcClass *klass = MetaScreenCastStreamSrcClass *klass =
META_SCREEN_CAST_STREAM_SRC_GET_CLASS (src); 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 static void
@ -411,7 +413,8 @@ maybe_record_cursor (MetaScreenCastStreamSrc *src,
static gboolean static gboolean
do_record_frame (MetaScreenCastStreamSrc *src, do_record_frame (MetaScreenCastStreamSrc *src,
struct spa_buffer *spa_buffer, struct spa_buffer *spa_buffer,
uint8_t *data) uint8_t *data,
GError **error)
{ {
MetaScreenCastStreamSrcPrivate *priv = MetaScreenCastStreamSrcPrivate *priv =
meta_screen_cast_stream_src_get_instance_private (src); meta_screen_cast_stream_src_get_instance_private (src);
@ -419,7 +422,7 @@ do_record_frame (MetaScreenCastStreamSrc *src,
if (spa_buffer->datas[0].data || if (spa_buffer->datas[0].data ||
spa_buffer->datas[0].type == SPA_DATA_MemFd) 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) 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); cogl_dma_buf_handle_get_framebuffer (dmabuf_handle);
return meta_screen_cast_stream_src_record_to_framebuffer (src, 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; return FALSE;
} }
@ -447,6 +453,7 @@ meta_screen_cast_stream_src_maybe_record_frame (MetaScreenCastStreamSrc *src,
struct spa_buffer *spa_buffer; struct spa_buffer *spa_buffer;
uint8_t *data = NULL; uint8_t *data = NULL;
uint64_t now_us; uint64_t now_us;
g_autoptr (GError) error = NULL;
now_us = g_get_monotonic_time (); now_us = g_get_monotonic_time ();
if (priv->video_format.max_framerate.num > 0 && 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 (!(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; struct spa_meta_region *spa_meta_video_crop;
@ -505,6 +512,7 @@ meta_screen_cast_stream_src_maybe_record_frame (MetaScreenCastStreamSrc *src,
} }
else else
{ {
g_warning ("Failed to record screen cast frame: %s", error->message);
spa_buffer->datas[0].chunk->size = 0; spa_buffer->datas[0].chunk->size = 0;
} }
} }

View File

@ -60,9 +60,11 @@ struct _MetaScreenCastStreamSrcClass
void (* enable) (MetaScreenCastStreamSrc *src); void (* enable) (MetaScreenCastStreamSrc *src);
void (* disable) (MetaScreenCastStreamSrc *src); void (* disable) (MetaScreenCastStreamSrc *src);
gboolean (* record_to_buffer) (MetaScreenCastStreamSrc *src, gboolean (* record_to_buffer) (MetaScreenCastStreamSrc *src,
uint8_t *data); uint8_t *data,
GError **error);
gboolean (* record_to_framebuffer) (MetaScreenCastStreamSrc *src, gboolean (* record_to_framebuffer) (MetaScreenCastStreamSrc *src,
CoglFramebuffer *framebuffer); CoglFramebuffer *framebuffer,
GError **error);
gboolean (* get_videocrop) (MetaScreenCastStreamSrc *src, gboolean (* get_videocrop) (MetaScreenCastStreamSrc *src,
MetaRectangle *crop_rect); MetaRectangle *crop_rect);
void (* set_cursor_metadata) (MetaScreenCastStreamSrc *src, void (* set_cursor_metadata) (MetaScreenCastStreamSrc *src,

View File

@ -458,7 +458,8 @@ meta_screen_cast_window_stream_src_disable (MetaScreenCastStreamSrc *src)
static gboolean static gboolean
meta_screen_cast_window_stream_src_record_to_buffer (MetaScreenCastStreamSrc *src, meta_screen_cast_window_stream_src_record_to_buffer (MetaScreenCastStreamSrc *src,
uint8_t *data) uint8_t *data,
GError **error)
{ {
MetaScreenCastWindowStreamSrc *window_src = MetaScreenCastWindowStreamSrc *window_src =
META_SCREEN_CAST_WINDOW_STREAM_SRC (src); META_SCREEN_CAST_WINDOW_STREAM_SRC (src);
@ -470,7 +471,8 @@ meta_screen_cast_window_stream_src_record_to_buffer (MetaScreenCastStreamSrc *sr
static gboolean static gboolean
meta_screen_cast_window_stream_src_record_to_framebuffer (MetaScreenCastStreamSrc *src, meta_screen_cast_window_stream_src_record_to_framebuffer (MetaScreenCastStreamSrc *src,
CoglFramebuffer *framebuffer) CoglFramebuffer *framebuffer,
GError **error)
{ {
MetaScreenCastWindowStreamSrc *window_src = MetaScreenCastWindowStreamSrc *window_src =
META_SCREEN_CAST_WINDOW_STREAM_SRC (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, if (!meta_screen_cast_window_blit_to_framebuffer (window_src->screen_cast_window,
&stream_rect, &stream_rect,
framebuffer)) framebuffer))
{
g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
"Failed to blit window content to framebuffer");
return FALSE; return FALSE;
}
stream = meta_screen_cast_stream_src_get_stream (src); stream = meta_screen_cast_stream_src_get_stream (src);
switch (meta_screen_cast_stream_get_cursor_mode (stream)) switch (meta_screen_cast_stream_get_cursor_mode (stream))