mirror of
https://github.com/brl/mutter.git
synced 2024-11-21 15:40:41 -05:00
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:
parent
882967d3ce
commit
047da80c3b
@ -393,7 +393,8 @@ meta_screen_cast_area_stream_src_disable (MetaScreenCastStreamSrc *src)
|
||||
|
||||
static gboolean
|
||||
meta_screen_cast_area_stream_src_record_to_buffer (MetaScreenCastStreamSrc *src,
|
||||
uint8_t *data)
|
||||
uint8_t *data,
|
||||
GError **error)
|
||||
{
|
||||
MetaScreenCastAreaStreamSrc *area_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;
|
||||
int stride;
|
||||
ClutterPaintFlag paint_flags = CLUTTER_PAINT_FLAG_NONE;
|
||||
g_autoptr (GError) error = NULL;
|
||||
|
||||
stage = get_stage (area_src);
|
||||
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,
|
||||
CLUTTER_CAIRO_FORMAT_ARGB32,
|
||||
paint_flags,
|
||||
&error))
|
||||
{
|
||||
g_warning ("Failed to record area: %s", error->message);
|
||||
error))
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
meta_screen_cast_area_stream_src_record_to_framebuffer (MetaScreenCastStreamSrc *src,
|
||||
CoglFramebuffer *framebuffer)
|
||||
CoglFramebuffer *framebuffer,
|
||||
GError **error)
|
||||
{
|
||||
MetaScreenCastAreaStreamSrc *area_src =
|
||||
META_SCREEN_CAST_AREA_STREAM_SRC (src);
|
||||
|
@ -388,7 +388,8 @@ 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)
|
||||
uint8_t *data,
|
||||
GError **error)
|
||||
{
|
||||
MetaScreenCastMonitorStreamSrc *monitor_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
|
||||
meta_screen_cast_monitor_stream_src_record_to_framebuffer (MetaScreenCastStreamSrc *src,
|
||||
CoglFramebuffer *framebuffer)
|
||||
CoglFramebuffer *framebuffer,
|
||||
GError **error)
|
||||
{
|
||||
MetaScreenCastMonitorStreamSrc *monitor_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)
|
||||
{
|
||||
ClutterStageView *view = CLUTTER_STAGE_VIEW (l->data);
|
||||
g_autoptr (GError) error = NULL;
|
||||
CoglFramebuffer *view_framebuffer;
|
||||
MetaRectangle view_layout;
|
||||
int x, y;
|
||||
@ -451,13 +452,9 @@ 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);
|
||||
error))
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
cogl_framebuffer_finish (framebuffer);
|
||||
|
||||
|
@ -136,22 +136,24 @@ meta_screen_cast_stream_src_get_videocrop (MetaScreenCastStreamSrc *src,
|
||||
|
||||
static gboolean
|
||||
meta_screen_cast_stream_src_record_to_buffer (MetaScreenCastStreamSrc *src,
|
||||
uint8_t *data)
|
||||
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)
|
||||
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
|
||||
@ -411,7 +413,8 @@ maybe_record_cursor (MetaScreenCastStreamSrc *src,
|
||||
static gboolean
|
||||
do_record_frame (MetaScreenCastStreamSrc *src,
|
||||
struct spa_buffer *spa_buffer,
|
||||
uint8_t *data)
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
@ -60,9 +60,11 @@ struct _MetaScreenCastStreamSrcClass
|
||||
void (* enable) (MetaScreenCastStreamSrc *src);
|
||||
void (* disable) (MetaScreenCastStreamSrc *src);
|
||||
gboolean (* record_to_buffer) (MetaScreenCastStreamSrc *src,
|
||||
uint8_t *data);
|
||||
uint8_t *data,
|
||||
GError **error);
|
||||
gboolean (* record_to_framebuffer) (MetaScreenCastStreamSrc *src,
|
||||
CoglFramebuffer *framebuffer);
|
||||
CoglFramebuffer *framebuffer,
|
||||
GError **error);
|
||||
gboolean (* get_videocrop) (MetaScreenCastStreamSrc *src,
|
||||
MetaRectangle *crop_rect);
|
||||
void (* set_cursor_metadata) (MetaScreenCastStreamSrc *src,
|
||||
|
@ -458,7 +458,8 @@ 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)
|
||||
uint8_t *data,
|
||||
GError **error)
|
||||
{
|
||||
MetaScreenCastWindowStreamSrc *window_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
|
||||
meta_screen_cast_window_stream_src_record_to_framebuffer (MetaScreenCastStreamSrc *src,
|
||||
CoglFramebuffer *framebuffer)
|
||||
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))
|
||||
{
|
||||
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))
|
||||
|
Loading…
Reference in New Issue
Block a user