diff options
author | Wim Taymans <wim.taymans@collabora.co.uk> | 2010-09-22 15:48:13 +0200 |
---|---|---|
committer | Wim Taymans <wim.taymans@collabora.co.uk> | 2010-09-22 15:48:13 +0200 |
commit | 25d740e203ecf7753fdcba90186883c345ed50f8 (patch) | |
tree | c648dcf02f73cc3eb54cb1bc25c1671b83999d24 | |
parent | 450b68252f4fe9d4c5aa5e566810a919611e0371 (diff) |
make some things more threadsafethreadsafe
-rw-r--r-- | examples/test-readme.c | 11 | ||||
-rw-r--r-- | gst/rtsp-server/rtsp-media.c | 27 | ||||
-rw-r--r-- | gst/rtsp-server/rtsp-media.h | 1 |
3 files changed, 25 insertions, 14 deletions
diff --git a/examples/test-readme.c b/examples/test-readme.c index 977fcb0..554249e 100644 --- a/examples/test-readme.c +++ b/examples/test-readme.c @@ -46,9 +46,11 @@ main (int argc, char *argv[]) * element with pay%d names will be a stream */ factory = gst_rtsp_media_factory_new (); gst_rtsp_media_factory_set_launch (factory, - "( videotestsrc is-live=1 ! x264enc ! rtph264pay name=pay0 pt=96 )"); + "( videotestsrc is-live=1 ! ffenc_h263 ! tee name=t ! queue ! rtph263ppay name=pay0 pt=96 " + " t. ! queue ! qtmux ! filesink location=test.mp4 )"); gst_rtsp_media_factory_set_shared (factory, TRUE); + gst_rtsp_media_factory_set_eos_shutdown (factory, TRUE); /* attach the test factory to the /test url */ gst_rtsp_media_mapping_add_factory (mapping, "/test", factory); @@ -57,10 +59,9 @@ main (int argc, char *argv[]) g_object_unref (mapping); /* attach the server to the default maincontext */ - gst_rtsp_server_attach (server, NULL); - - /* start serving */ - g_main_loop_run (loop); + if (gst_rtsp_server_attach (server, NULL) > 0) + /* start serving */ + g_main_loop_run (loop); return 0; } diff --git a/gst/rtsp-server/rtsp-media.c b/gst/rtsp-server/rtsp-media.c index c6a45ac..613896e 100644 --- a/gst/rtsp-server/rtsp-media.c +++ b/gst/rtsp-server/rtsp-media.c @@ -1430,7 +1430,7 @@ pad_added_cb (GstElement * element, GstPad * pad, GstRTSPMedia * media) gchar *name; gint i; - i = media->streams->len + 1; + i = g_atomic_int_exchange_and_add (&media->stream_count, 1); GST_INFO ("pad added %s:%s, stream %d", GST_DEBUG_PAD_NAME (pad), i); @@ -1445,9 +1445,6 @@ pad_added_cb (GstElement * element, GstPad * pad, GstRTSPMedia * media) gst_element_add_pad (media->element, stream->srcpad); g_free (name); - /* add stream now */ - g_array_append_val (media->streams, stream); - setup_stream (stream, i, media); for (i = 0; i < 2; i++) { @@ -1457,18 +1454,30 @@ pad_added_cb (GstElement * element, GstPad * pad, GstRTSPMedia * media) gst_element_set_state (stream->selector[i], GST_STATE_PAUSED); gst_element_set_state (stream->appsrc[i], GST_STATE_PAUSED); } + + g_mutex_lock (media->lock); + /* add stream now */ + g_array_append_val (media->streams, stream); + g_mutex_unlock (media->lock); } static void no_more_pads_cb (GstElement * element, GstRTSPMedia * media) { + GstElement *fakesink; + + g_mutex_lock (media->lock); GST_INFO ("no more pads"); - if (media->fakesink) { - gst_object_ref (media->fakesink); - gst_bin_remove (GST_BIN (media->pipeline), media->fakesink); - gst_element_set_state (media->fakesink, GST_STATE_NULL); - gst_object_unref (media->fakesink); + if ((fakesink = media->fakesink)) { + gst_object_ref (fakesink); media->fakesink = NULL; + } + g_mutex_unlock (media->lock); + + if (fakesink) { + gst_bin_remove (GST_BIN (media->pipeline), fakesink); + gst_element_set_state (fakesink, GST_STATE_NULL); + gst_object_unref (fakesink); GST_INFO ("removed fakesink"); } } diff --git a/gst/rtsp-server/rtsp-media.h b/gst/rtsp-server/rtsp-media.h index 211e2c0..826a7f3 100644 --- a/gst/rtsp-server/rtsp-media.h +++ b/gst/rtsp-server/rtsp-media.h @@ -203,6 +203,7 @@ struct _GstRTSPMedia { gboolean eos_shutdown; GstElement *element; + gint stream_count; GArray *streams; GList *dynamic; GstRTSPMediaStatus status; |