[farsight2/master] Protect transmitter hashtable with a lock
Olivier Crête
olivier.crete at collabora.co.uk
Tue Dec 16 15:43:16 PST 2008
---
gst/fsrtpconference/fs-rtp-session.c | 31 ++++++++++++++++++++++++++++++-
1 files changed, 30 insertions(+), 1 deletions(-)
diff --git a/gst/fsrtpconference/fs-rtp-session.c b/gst/fsrtpconference/fs-rtp-session.c
index 198b4f4..43a75fb 100644
--- a/gst/fsrtpconference/fs-rtp-session.c
+++ b/gst/fsrtpconference/fs-rtp-session.c
@@ -1744,15 +1744,24 @@ fs_rtp_session_get_new_stream_transmitter (FsRtpSession *self,
FsTransmitter *transmitter;
GstElement *src, *sink;
+ FS_RTP_SESSION_LOCK (self);
+
transmitter = g_hash_table_lookup (self->priv->transmitters,
transmitter_name);
if (transmitter)
{
- return fs_transmitter_new_stream_transmitter (transmitter, participant,
+ FsStreamTransmitter *st = NULL;
+ g_object_ref (transmitter);
+ FS_RTP_SESSION_UNLOCK (self);
+ st = fs_transmitter_new_stream_transmitter (transmitter, participant,
n_parameters, parameters, error);
+ g_object_unref (transmitter);
+ return st;
}
+ FS_RTP_SESSION_UNLOCK (self);
+
transmitter = fs_transmitter_new (transmitter_name, 2, error);
if (!transmitter)
return NULL;
@@ -1794,8 +1803,22 @@ fs_rtp_session_get_new_stream_transmitter (FsRtpSession *self,
gst_element_sync_state_with_parent (src);
gst_element_sync_state_with_parent (sink);
+ FS_RTP_SESSION_LOCK (self);
+ /* Check if two were added at the same time */
+ if (g_hash_table_lookup (self->priv->transmitters, transmitter_name))
+ {
+ FS_RTP_SESSION_UNLOCK (self);
+
+ gst_element_set_locked_state (src, TRUE);
+ gst_element_set_locked_state (sink, TRUE);
+ gst_element_set_state (src, GST_STATE_NULL);
+ gst_element_set_state (sink, GST_STATE_NULL);
+ goto error;
+ }
+
g_hash_table_insert (self->priv->transmitters, g_strdup (transmitter_name),
transmitter);
+ FS_RTP_SESSION_UNLOCK (self);
gst_object_unref (src);
gst_object_unref (sink);
@@ -1803,6 +1826,12 @@ fs_rtp_session_get_new_stream_transmitter (FsRtpSession *self,
return fs_transmitter_new_stream_transmitter (transmitter, participant,
n_parameters, parameters, error);
+ /*
+ * TODO:
+ * The transmitters sink/sources should be cleanly removed if there is
+ * an error
+ */
+
error:
if (src)
gst_object_unref (src);
--
1.5.6.5
More information about the farsight-commits
mailing list