Skip to content

Commit

Permalink
gst: emit notify signal on camera property if camera has changed
Browse files Browse the repository at this point in the history
  • Loading branch information
kohtala authored and EmmanuelP committed Sep 3, 2024
1 parent 34426d6 commit 2ed587c
Showing 1 changed file with 29 additions and 8 deletions.
37 changes: 29 additions & 8 deletions gst/gstaravis.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -444,6 +449,9 @@ gst_aravis_init_camera (GstAravis *gst_aravis, GError **error)
return FALSE;
}

if (notify != NULL)
*notify = TRUE;

return TRUE;
}

Expand Down Expand Up @@ -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, &notify, &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;
}
Expand Down Expand Up @@ -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, &notify, &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);
Expand Down

0 comments on commit 2ed587c

Please sign in to comment.