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.
This commit is contained in:
Thiago Santos 2011-03-23 12:38:36 -03:00
parent 6913db30f8
commit aa7b962891
3 changed files with 32 additions and 10 deletions

View file

@ -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;
}

View file

@ -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);
}
/*

View file

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