From 2ed587c886ee61904cfd6d3eb474fd904e11e88f Mon Sep 17 00:00:00 2001 From: Marko Kohtala Date: Tue, 3 Sep 2024 16:35:30 +0200 Subject: [PATCH] gst: emit notify signal on camera property if camera has changed --- gst/gstaravis.c | 37 +++++++++++++++++++++++++++++-------- 1 file changed, 29 insertions(+), 8 deletions(-) diff --git a/gst/gstaravis.c b/gst/gstaravis.c index c3552235a..fdedbf5a0 100644 --- a/gst/gstaravis.c +++ b/gst/gstaravis.c @@ -423,12 +423,17 @@ gst_aravis_set_caps (GstBaseSrc *src, GstCaps *caps) } static gboolean -gst_aravis_init_camera (GstAravis *gst_aravis, GError **error) +gst_aravis_init_camera (GstAravis *gst_aravis, gboolean *notify, GError **error) { GError *local_error = NULL; - if (gst_aravis->camera != NULL) + if (gst_aravis->camera != NULL) { g_object_unref (gst_aravis->camera); + if (notify != NULL) + *notify = TRUE; + } else + if (notify != NULL) + *notify = FALSE; gst_aravis->camera = arv_camera_new (gst_aravis->camera_name, &local_error); @@ -444,6 +449,9 @@ gst_aravis_init_camera (GstAravis *gst_aravis, GError **error) return FALSE; } + if (notify != NULL) + *notify = TRUE; + return TRUE; } @@ -472,18 +480,26 @@ gst_aravis_start (GstBaseSrc *src) { GError *error = NULL; gboolean result = TRUE; + gboolean notify = FALSE; GstAravis* gst_aravis = GST_ARAVIS(src); - GST_LOG_OBJECT (gst_aravis, "Open camera '%s'", gst_aravis->camera_name); + if (gst_aravis->camera_name != NULL) + GST_LOG_OBJECT (gst_aravis, "Open camera '%s'", gst_aravis->camera_name); + else + GST_LOG_OBJECT (gst_aravis, "Open first available camera"); GST_OBJECT_LOCK (gst_aravis); if (gst_aravis->camera == NULL) - result = gst_aravis_init_camera (gst_aravis, &error); + result = gst_aravis_init_camera (gst_aravis, ¬ify, &error); if (result) gst_aravis->all_caps = gst_aravis_get_all_camera_caps (gst_aravis, &error); GST_OBJECT_UNLOCK (gst_aravis); - if (error) gst_aravis_init_error (gst_aravis, error); + if (notify) + g_object_notify_by_pspec (G_OBJECT (gst_aravis), properties[PROP_CAMERA]); + + if (error) + gst_aravis_init_error (gst_aravis, error); return result; } @@ -730,19 +746,24 @@ gst_aravis_set_property (GObject * object, guint prop_id, GST_DEBUG_OBJECT (gst_aravis, "setting property %s", pspec->name); switch (prop_id) { + gboolean notify; case PROP_CAMERA_NAME: + notify= FALSE; GST_OBJECT_LOCK (gst_aravis); - g_free (gst_aravis->camera_name); /* check if we are currently active prevent setting camera and other values to something not representing the active camera */ if (gst_aravis->stream == NULL) { + g_free (gst_aravis->camera_name); gst_aravis->camera_name = g_strdup (g_value_get_string (value)); - gst_aravis_init_camera (gst_aravis, &error); + gst_aravis_init_camera (gst_aravis, ¬ify, &error); } GST_LOG_OBJECT (gst_aravis, "Set camera name to %s", gst_aravis->camera_name); GST_OBJECT_UNLOCK (gst_aravis); - if (error) gst_aravis_init_error (gst_aravis, error); + if (error) + gst_aravis_init_error (gst_aravis, error); + if (notify) + g_object_notify_by_pspec (G_OBJECT (gst_aravis), properties[PROP_CAMERA]); break; case PROP_GAIN: GST_OBJECT_LOCK (gst_aravis);