mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-12-28 11:10:37 +00:00
camerabin2: Add a mutex to avoid concurrent access of preview filename lists
The preview filename list is acessed whenever a new capture is started, when camera-source posts a new preview message or on state changes. All of those can occur simultaneously, so add a mutex to prevent concurrent access.
This commit is contained in:
parent
17a00123a4
commit
e90e041e52
2 changed files with 23 additions and 1 deletions
|
@ -406,8 +406,10 @@ gst_camera_bin_start_capture (GstCameraBin2 * camerabin)
|
|||
}
|
||||
|
||||
/* store the next preview filename */
|
||||
g_mutex_lock (camerabin->preview_list_mutex);
|
||||
camerabin->preview_location_list =
|
||||
g_slist_append (camerabin->preview_location_list, location);
|
||||
g_mutex_unlock (camerabin->preview_list_mutex);
|
||||
|
||||
g_signal_emit_by_name (camerabin->src, "start-capture", NULL);
|
||||
if (camerabin->mode == MODE_VIDEO && camerabin->audio_src)
|
||||
|
@ -518,6 +520,7 @@ gst_camera_bin_dispose (GObject * object)
|
|||
GstCameraBin2 *camerabin = GST_CAMERA_BIN2_CAST (object);
|
||||
|
||||
g_free (camerabin->location);
|
||||
g_mutex_free (camerabin->preview_list_mutex);
|
||||
|
||||
if (camerabin->src_capture_notify_id)
|
||||
g_signal_handler_disconnect (camerabin->src,
|
||||
|
@ -873,6 +876,7 @@ gst_camera_bin_init (GstCameraBin2 * camera)
|
|||
camera->zoom = DEFAULT_ZOOM;
|
||||
camera->max_zoom = MAX_ZOOM;
|
||||
camera->flags = DEFAULT_FLAGS;
|
||||
camera->preview_list_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
|
||||
|
@ -947,12 +951,14 @@ gst_camera_bin_handle_message (GstBin * bin, GstMessage * message)
|
|||
GValue *value;
|
||||
gchar *location;
|
||||
|
||||
g_mutex_lock (camerabin->preview_list_mutex);
|
||||
location = camerabin->preview_location_list->data;
|
||||
camerabin->preview_location_list =
|
||||
g_slist_delete_link (camerabin->preview_location_list,
|
||||
camerabin->preview_location_list);
|
||||
GST_DEBUG_OBJECT (camerabin, "Adding preview location to preview "
|
||||
"message '%s'", location);
|
||||
g_mutex_unlock (camerabin->preview_list_mutex);
|
||||
|
||||
value = g_new0 (GValue, 1);
|
||||
g_value_init (value, G_TYPE_STRING);
|
||||
|
@ -1725,9 +1731,11 @@ gst_camera_bin_change_state (GstElement * element, GstStateChange trans)
|
|||
g_slist_free (camera->image_location_list);
|
||||
camera->image_location_list = NULL;
|
||||
|
||||
g_mutex_lock (camera->preview_list_mutex);
|
||||
g_slist_foreach (camera->preview_location_list, (GFunc) g_free, NULL);
|
||||
g_slist_free (camera->preview_location_list);
|
||||
camera->preview_location_list = NULL;
|
||||
g_mutex_unlock (camera->preview_list_mutex);
|
||||
|
||||
/* explicitly set to READY as they might be outside of the bin */
|
||||
gst_element_set_state (camera->audio_volume, GST_STATE_READY);
|
||||
|
|
|
@ -94,8 +94,22 @@ struct _GstCameraBin2
|
|||
* each buffer capture */
|
||||
GSList *image_location_list;
|
||||
|
||||
/* similar to above, but used for giving names to previews */
|
||||
/*
|
||||
* Similar to above, but used for giving names to previews
|
||||
*
|
||||
* Need to protect with a mutex as this list is used when the
|
||||
* camera-source posts a preview image. As we have no control
|
||||
* on how the camera-source will behave (we can only tell how
|
||||
* it should), the preview location list might be used in an
|
||||
* inconsistent way.
|
||||
* One example is the camera-source posting a preview image after
|
||||
* camerabin2 was put to ready, when this preview list will be
|
||||
* freed and set to NULL. Concurrent access might lead to crashes in
|
||||
* this situation. (Concurrency from the state-change freeing the
|
||||
* list and the message handling function looking at preview names)
|
||||
*/
|
||||
GSList *preview_location_list;
|
||||
GMutex *preview_list_mutex;
|
||||
|
||||
gboolean video_profile_switch;
|
||||
gboolean image_profile_switch;
|
||||
|
|
Loading…
Reference in a new issue