From aa7b9628916784ade338bd96ce0f9119a3b88f83 Mon Sep 17 00:00:00 2001 From: Thiago Santos Date: Wed, 23 Mar 2011 12:38:36 -0300 Subject: [PATCH] camerabin2: Improve idle property usage Use resource warning messages to notify camerabin2 that a capture as aborted or couldn't be started, making it decrement the processing counter and making the idle property more reliable. --- .../gst/basecamerabinsrc/gstbasecamerasrc.c | 3 ++ gst/camerabin2/gstcamerabin2.c | 36 +++++++++++++------ tests/check/elements/camerabin2.c | 3 ++ 3 files changed, 32 insertions(+), 10 deletions(-) diff --git a/gst-libs/gst/basecamerabinsrc/gstbasecamerasrc.c b/gst-libs/gst/basecamerabinsrc/gstbasecamerasrc.c index 68cc0107ac..0138c8231c 100644 --- a/gst-libs/gst/basecamerabinsrc/gstbasecamerasrc.c +++ b/gst-libs/gst/basecamerabinsrc/gstbasecamerasrc.c @@ -252,6 +252,9 @@ gst_base_camera_src_start_capture (GstBaseCameraSrc * src) if (src->capturing) { GST_WARNING_OBJECT (src, "Capturing already ongoing"); g_mutex_unlock (src->capturing_mutex); + + /* post a warning to notify camerabin2 that the capture failed */ + GST_ELEMENT_WARNING (src, RESOURCE, BUSY, (NULL), (NULL)); return; } diff --git a/gst/camerabin2/gstcamerabin2.c b/gst/camerabin2/gstcamerabin2.c index 38f093d0e6..b44a7a23dd 100644 --- a/gst/camerabin2/gstcamerabin2.c +++ b/gst/camerabin2/gstcamerabin2.c @@ -691,20 +691,36 @@ gst_image_capture_bin_post_image_done (GstCameraBin * camera, static void gst_camera_bin_handle_message (GstBin * bin, GstMessage * message) { - if (GST_MESSAGE_TYPE (message) == GST_MESSAGE_ELEMENT) { - const GstStructure *structure = gst_message_get_structure (message); - const gchar *filename; + switch (GST_MESSAGE_TYPE (message)) { + case GST_MESSAGE_ELEMENT:{ + const GstStructure *structure = gst_message_get_structure (message); + const gchar *filename; - if (gst_structure_has_name (structure, "GstMultiFileSink")) { - GST_CAMERA_BIN_PROCESSING_DEC (GST_CAMERA_BIN_CAST (bin)); - filename = gst_structure_get_string (structure, "filename"); - if (filename) { - gst_image_capture_bin_post_image_done (GST_CAMERA_BIN_CAST (bin), - filename); + if (gst_structure_has_name (structure, "GstMultiFileSink")) { + GST_CAMERA_BIN_PROCESSING_DEC (GST_CAMERA_BIN_CAST (bin)); + filename = gst_structure_get_string (structure, "filename"); + if (filename) { + gst_image_capture_bin_post_image_done (GST_CAMERA_BIN_CAST (bin), + filename); + } } } + break; + case GST_MESSAGE_WARNING:{ + GError *err = NULL; + gchar *debug = NULL; + + gst_message_parse_warning (message, &err, &debug); + if (err->domain == GST_RESOURCE_ERROR) { + /* some capturing failed */ + GST_CAMERA_BIN_PROCESSING_DEC (GST_CAMERA_BIN_CAST (bin)); + } + } + default: + break; } - GST_BIN_CLASS (parent_class)->handle_message (bin, message); + if (message) + GST_BIN_CLASS (parent_class)->handle_message (bin, message); } /* diff --git a/tests/check/elements/camerabin2.c b/tests/check/elements/camerabin2.c index 0a5a7e4cbc..4fc5caade0 100644 --- a/tests/check/elements/camerabin2.c +++ b/tests/check/elements/camerabin2.c @@ -1059,6 +1059,8 @@ GST_START_TEST (test_idle_property) /* emit a second start-capture that should be ignored */ g_signal_emit_by_name (camera, "start-capture", NULL); + g_object_get (camera, "idle", &idle, NULL); + fail_unless (!idle); /* Record for one seconds */ g_timeout_add_seconds (VIDEO_DURATION, (GSourceFunc) g_main_loop_quit, @@ -1069,6 +1071,7 @@ GST_START_TEST (test_idle_property) check_preview_image (); + g_usleep (3 * G_USEC_PER_SEC); g_object_get (camera, "idle", &idle, NULL); fail_unless (idle);