wpe: Properly lock property fields

Use the object lock for the following fields:
 - `bytes`: Written by the `load-bytes` signal unless running; consumed
   on start.
 - `draw_background`: Read and written by the `draw-background`
   property.
 - `location`: Read and written by the `location` property and the URI
   handler.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/2222>
This commit is contained in:
Jan Alexander Steffens (heftig) 2021-05-06 19:17:29 +02:00 committed by GStreamer Marge Bot
parent 3d02559002
commit 950d5eedf9

View File

@ -264,6 +264,7 @@ gst_wpe_src_start (GstWpeSrc * src)
GstGLDisplay *display = NULL; GstGLDisplay *display = NULL;
GstGLBaseSrc *base_src = GST_GL_BASE_SRC (src); GstGLBaseSrc *base_src = GST_GL_BASE_SRC (src);
gboolean created_view = FALSE; gboolean created_view = FALSE;
GBytes *bytes;
GST_INFO_OBJECT (src, "Starting up"); GST_INFO_OBJECT (src, "Starting up");
WPE_LOCK (src); WPE_LOCK (src);
@ -292,10 +293,14 @@ gst_wpe_src_start (GstWpeSrc * src)
return FALSE; return FALSE;
} }
if (src->bytes != NULL) { GST_OBJECT_LOCK (src);
src->view->loadData (src->bytes); bytes = src->bytes;
g_bytes_unref (src->bytes);
src->bytes = NULL; src->bytes = NULL;
GST_OBJECT_UNLOCK (src);
if (bytes != NULL) {
src->view->loadData (bytes);
g_bytes_unref (bytes);
} }
if (created_view) { if (created_view) {
@ -431,9 +436,11 @@ gst_wpe_src_load_bytes (GstWpeSrc * src, GBytes * bytes)
if (src->view && GST_STATE (GST_ELEMENT_CAST (src)) > GST_STATE_NULL) { if (src->view && GST_STATE (GST_ELEMENT_CAST (src)) > GST_STATE_NULL) {
src->view->loadData (bytes); src->view->loadData (bytes);
} else { } else {
GST_OBJECT_LOCK (src);
if (src->bytes) if (src->bytes)
g_bytes_unref (src->bytes); g_bytes_unref (src->bytes);
src->bytes = g_bytes_ref (bytes); src->bytes = g_bytes_ref (bytes);
GST_OBJECT_UNLOCK (src);
} }
} }
@ -441,10 +448,13 @@ static gboolean
gst_wpe_src_set_location (GstWpeSrc * src, const gchar * location, gst_wpe_src_set_location (GstWpeSrc * src, const gchar * location,
GError ** error) GError ** error)
{ {
GST_OBJECT_LOCK (src);
g_free (src->location); g_free (src->location);
src->location = g_strdup (location); src->location = g_strdup (location);
GST_OBJECT_UNLOCK (src);
if (src->view) if (src->view)
src->view->loadUri (src->location); src->view->loadUri (location);
return TRUE; return TRUE;
} }
@ -452,9 +462,12 @@ gst_wpe_src_set_location (GstWpeSrc * src, const gchar * location,
static void static void
gst_wpe_src_set_draw_background (GstWpeSrc * src, gboolean draw_background) gst_wpe_src_set_draw_background (GstWpeSrc * src, gboolean draw_background)
{ {
GST_OBJECT_LOCK (src);
src->draw_background = draw_background;
GST_OBJECT_UNLOCK (src);
if (src->view) if (src->view)
src->view->setDrawBackground (draw_background); src->view->setDrawBackground (draw_background);
src->draw_background = draw_background;
} }
static void static void
@ -496,10 +509,14 @@ gst_wpe_src_get_property (GObject * object, guint prop_id, GValue * value,
switch (prop_id) { switch (prop_id) {
case PROP_LOCATION: case PROP_LOCATION:
GST_OBJECT_LOCK (src);
g_value_set_string (value, src->location); g_value_set_string (value, src->location);
GST_OBJECT_UNLOCK (src);
break; break;
case PROP_DRAW_BACKGROUND: case PROP_DRAW_BACKGROUND:
GST_OBJECT_LOCK (src);
g_value_set_boolean (value, src->draw_background); g_value_set_boolean (value, src->draw_background);
GST_OBJECT_UNLOCK (src);
break; break;
default: default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
@ -671,7 +688,13 @@ static gchar *
gst_wpe_src_get_uri (GstURIHandler * handler) gst_wpe_src_get_uri (GstURIHandler * handler)
{ {
GstWpeSrc *src = GST_WPE_SRC (handler); GstWpeSrc *src = GST_WPE_SRC (handler);
return g_strdup_printf ("wpe://%s", src->location); gchar *uri;
GST_OBJECT_LOCK (src);
uri = g_strdup_printf ("wpe://%s", src->location);
GST_OBJECT_UNLOCK (src);
return uri;
} }
static gboolean static gboolean