diff --git a/gst/camerabin2/gstcamerabin2.c b/gst/camerabin2/gstcamerabin2.c index b6705d803d..bfead866f6 100644 --- a/gst/camerabin2/gstcamerabin2.c +++ b/gst/camerabin2/gstcamerabin2.c @@ -122,12 +122,12 @@ gst_camera_bin_start_capture (GstCameraBin * camerabin) static void gst_camera_bin_stop_capture (GstCameraBin * camerabin) { - g_mutex_lock (camerabin->capture_mutex); + /* TODO do we need a lock here? it is just an if */ if (camerabin->capturing) { + /* Capturing is cleaned on the notify function because it works + * both for images and videos */ g_object_set (camerabin->src, "mode", MODE_PREVIEW, NULL); - camerabin->capturing = FALSE; } - g_mutex_unlock (camerabin->capture_mutex); } static void @@ -144,7 +144,10 @@ gst_camera_bin_dispose (GObject * object) { GstCameraBin *camerabin = GST_CAMERA_BIN_CAST (object); - gst_object_unref (camerabin->src); + if (camerabin->src_mode_notify_id) + g_signal_handler_disconnect (camerabin->src, camerabin->src_mode_notify_id); + if (camerabin->src) + gst_object_unref (camerabin->src); g_mutex_free (camerabin->capture_mutex); G_OBJECT_CLASS (parent_class)->dispose (object); @@ -230,6 +233,23 @@ gst_camera_bin_init (GstCameraBin * camerabin) camerabin->mode = MODE_IMAGE; } +static void +gst_camera_bin_src_notify_mode (GObject * src, GParamSpec * pspec, + gpointer data) +{ + GstCameraBin *camera = GST_CAMERA_BIN_CAST (data); + gint mode; + + g_object_get (src, "mode", &mode, NULL); + + if (mode == MODE_PREVIEW) { + g_mutex_lock (camera->capture_mutex); + g_assert (camera->capturing); + camera->capturing = FALSE; + g_mutex_unlock (camera->capture_mutex); + } +} + /** * gst_camera_bin_create_elements: * @param camera: the #GstCameraBin @@ -265,6 +285,8 @@ gst_camera_bin_create_elements (GstCameraBin * camera) vf = gst_element_factory_make ("viewfinderbin", "vf-bin"); camera->src = gst_object_ref (src); + camera->src_mode_notify_id = g_signal_connect (src, "notify::mode", + (GCallback) gst_camera_bin_src_notify_mode, camera); vid_queue = gst_element_factory_make ("queue", "video-queue"); img_queue = gst_element_factory_make ("queue", "image-queue"); diff --git a/gst/camerabin2/gstcamerabin2.h b/gst/camerabin2/gstcamerabin2.h index f87b34ce8b..c0c1981a09 100644 --- a/gst/camerabin2/gstcamerabin2.h +++ b/gst/camerabin2/gstcamerabin2.h @@ -38,6 +38,7 @@ struct _GstCameraBin GstPipeline pipeline; GstElement *src; + gulong src_mode_notify_id; /* concurrency control */ GMutex *capture_mutex;