From c7db5db63224bdb0ae09c4980ad96488e9e2b9bc Mon Sep 17 00:00:00 2001 From: Thiago Santos Date: Wed, 9 Nov 2011 12:21:37 -0300 Subject: camerabin2: protect image location list with mutex Rename the image taglists' mutex into image capture mutex and use it also for the image capture list to prevent concurrent access from different threads (application and capture threads). --- gst/camerabin2/gstcamerabin2.c | 21 ++++++++++++--------- gst/camerabin2/gstcamerabin2.h | 2 +- 2 files changed, 13 insertions(+), 10 deletions(-) (limited to 'gst/camerabin2') diff --git a/gst/camerabin2/gstcamerabin2.c b/gst/camerabin2/gstcamerabin2.c index d53b0da88..afae1014a 100644 --- a/gst/camerabin2/gstcamerabin2.c +++ b/gst/camerabin2/gstcamerabin2.c @@ -401,8 +401,10 @@ gst_camera_bin_start_capture (GstCameraBin2 * camerabin) } } else { /* store the next capture buffer filename */ + g_mutex_lock (camerabin->image_capture_mutex); camerabin->image_location_list = g_slist_append (camerabin->image_location_list, g_strdup (location)); + g_mutex_unlock (camerabin->image_capture_mutex); } if (camerabin->post_previews) { @@ -433,11 +435,11 @@ gst_camera_bin_start_capture (GstCameraBin2 * camerabin) if (camerabin->mode == MODE_IMAGE) { /* Store image tags in a list and push them later, this prevents start_capture() from blocking in pad_push_event call */ - g_mutex_lock (camerabin->image_tags_mutex); + g_mutex_lock (camerabin->image_capture_mutex); camerabin->image_tags_list = g_slist_append (camerabin->image_tags_list, taglist ? gst_tag_list_copy (taglist) : NULL); - g_mutex_unlock (camerabin->image_tags_mutex); + g_mutex_unlock (camerabin->image_capture_mutex); } else if (taglist) { GstPad *active_pad; @@ -532,7 +534,7 @@ gst_camera_bin_dispose (GObject * object) g_free (camerabin->location); g_mutex_free (camerabin->preview_list_mutex); - g_mutex_free (camerabin->image_tags_mutex); + g_mutex_free (camerabin->image_capture_mutex); if (camerabin->src_capture_notify_id) g_signal_handler_disconnect (camerabin->src, @@ -889,7 +891,7 @@ gst_camera_bin_init (GstCameraBin2 * camera) camera->max_zoom = MAX_ZOOM; camera->flags = DEFAULT_FLAGS; camera->preview_list_mutex = g_mutex_new (); - camera->image_tags_mutex = g_mutex_new (); + camera->image_capture_mutex = g_mutex_new (); /* capsfilters are created here as we proxy their caps properties and * this way we avoid having to store the caps while on NULL state to @@ -1273,14 +1275,14 @@ gst_camera_bin_image_src_buffer_probe (GstPad * pad, GstBuffer * buf, GstPad *peer; GstTagList *tags; + g_mutex_lock (camerabin->image_capture_mutex); + /* Push pending image tags */ - g_mutex_lock (camerabin->image_tags_mutex); if (camerabin->image_tags_list) { tags = camerabin->image_tags_list->data; camerabin->image_tags_list = g_slist_delete_link (camerabin->image_tags_list, camerabin->image_tags_list); - g_mutex_unlock (camerabin->image_tags_mutex); GST_DEBUG_OBJECT (camerabin, "Pushing tags from application: %" GST_PTR_FORMAT, tags); if (tags) { @@ -1289,7 +1291,6 @@ gst_camera_bin_image_src_buffer_probe (GstPad * pad, GstBuffer * buf, gst_object_unref (peer); } } else { - g_mutex_unlock (camerabin->image_tags_mutex); GST_DEBUG_OBJECT (camerabin, "No tags from application to send"); } @@ -1303,8 +1304,10 @@ gst_camera_bin_image_src_buffer_probe (GstPad * pad, GstBuffer * buf, location); } else { GST_DEBUG_OBJECT (camerabin, "No filename location change to send"); + g_mutex_unlock (camerabin->image_capture_mutex); return ret; } + g_mutex_unlock (camerabin->image_capture_mutex); if (location) { evt = gst_camera_bin_new_event_file_location (location); @@ -1808,16 +1811,16 @@ gst_camera_bin_change_state (GstElement * element, GstStateChange trans) gst_tag_setter_reset_tags (GST_TAG_SETTER (camera)); GST_CAMERA_BIN2_RESET_PROCESSING_COUNTER (camera); + g_mutex_lock (camera->image_capture_mutex); g_slist_foreach (camera->image_location_list, (GFunc) g_free, NULL); g_slist_free (camera->image_location_list); camera->image_location_list = NULL; - g_mutex_lock (camera->image_tags_mutex); g_slist_foreach (camera->image_tags_list, (GFunc) _gst_tag_list_free_maybe, NULL); g_slist_free (camera->image_tags_list); camera->image_tags_list = NULL; - g_mutex_unlock (camera->image_tags_mutex); + g_mutex_unlock (camera->image_capture_mutex); g_mutex_lock (camera->preview_list_mutex); g_slist_foreach (camera->preview_location_list, (GFunc) g_free, NULL); diff --git a/gst/camerabin2/gstcamerabin2.h b/gst/camerabin2/gstcamerabin2.h index 27115bdf4..ec740a57f 100644 --- a/gst/camerabin2/gstcamerabin2.h +++ b/gst/camerabin2/gstcamerabin2.h @@ -89,12 +89,12 @@ struct _GstCameraBin2 /* Index of the auto incrementing file index for captures */ gint capture_index; + GMutex *image_capture_mutex; /* stores list of image locations to be pushed to the image sink * as file location change notifications, they are pushed before * each buffer capture */ GSList *image_location_list; /* Store also tags and push them before each captured image */ - GMutex *image_tags_mutex; GSList *image_tags_list; /* -- cgit v1.2.3