camerabin2: Cleanup capturing flag

Cleanup capturing flag when the source switches back to the
viewfinder mode
This commit is contained in:
Thiago Santos 2010-11-29 18:53:34 -03:00
parent 9df40915d6
commit b4d73cb9a8
2 changed files with 27 additions and 4 deletions

View file

@ -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");

View file

@ -38,6 +38,7 @@ struct _GstCameraBin
GstPipeline pipeline;
GstElement *src;
gulong src_mode_notify_id;
/* concurrency control */
GMutex *capture_mutex;