media: add optional context for bus messages
authorWim Taymans <wim.taymans@collabora.co.uk>
Fri, 5 Jul 2013 18:43:39 +0000 (20:43 +0200)
committerWim Taymans <wim.taymans@collabora.co.uk>
Mon, 8 Jul 2013 09:10:20 +0000 (11:10 +0200)
Add an optional mainloop to _prepare that will handle the bus messages instead
of always using the shared mainloop.

gst/rtsp-server/rtsp-client.c
gst/rtsp-server/rtsp-media.c
gst/rtsp-server/rtsp-media.h
tests/check/gst/media.c

index a597916..47956e5 100644 (file)
@@ -522,7 +522,7 @@ find_media (GstRTSPClient * client, GstRTSPClientState * state, gint * matched)
       goto no_media;
 
     /* prepare the media */
-    if (!(gst_rtsp_media_prepare (media)))
+    if (!(gst_rtsp_media_prepare (media, NULL)))
       goto no_prepare;
 
     /* now keep track of the uri and the media */
index 4e25e15..2a875b3 100644 (file)
@@ -1507,6 +1507,7 @@ struct _DynPaySignalHandlers
 /**
  * gst_rtsp_media_prepare:
  * @media: a #GstRTSPMedia
+ * @context: a #GMainContext to run the bus handler or %NULL
  *
  * Prepare @media for streaming. This function will create the objects
  * to manage the streaming. A pipeline must have been set on @media with
@@ -1518,7 +1519,7 @@ struct _DynPaySignalHandlers
  * Returns: %TRUE on success.
  */
 gboolean
-gst_rtsp_media_prepare (GstRTSPMedia * media)
+gst_rtsp_media_prepare (GstRTSPMedia * media, GMainContext * context)
 {
   GstRTSPMediaPrivate *priv;
   GstStateChangeReturn ret;
@@ -1570,7 +1571,7 @@ gst_rtsp_media_prepare (GstRTSPMedia * media)
       g_object_ref (media), (GDestroyNotify) watch_destroyed);
 
   klass = GST_RTSP_MEDIA_GET_CLASS (media);
-  priv->id = g_source_attach (priv->source, klass->context);
+  priv->id = g_source_attach (priv->source, context ? context : klass->context);
 
   /* add stuff to the bin */
   gst_bin_add (GST_BIN (priv->pipeline), priv->rtpbin);
index 02be092..f76a6dd 100644 (file)
@@ -149,7 +149,7 @@ GstNetTimeProvider *  gst_rtsp_media_get_time_provider (GstRTSPMedia *media,
                                                         const gchar *address, guint16 port);
 
 /* prepare the media for playback */
-gboolean              gst_rtsp_media_prepare          (GstRTSPMedia *media);
+gboolean              gst_rtsp_media_prepare          (GstRTSPMedia *media, GMainContext *context);
 gboolean              gst_rtsp_media_unprepare        (GstRTSPMedia *media);
 
 /* creating streams */
index dd814cf..0692bcb 100644 (file)
@@ -53,7 +53,7 @@ GST_START_TEST (test_launch)
   /* fails, need to be prepared */
   fail_if (gst_rtsp_media_seek (media, range));
 
-  fail_unless (gst_rtsp_media_prepare (media));
+  fail_unless (gst_rtsp_media_prepare (media, NULL));
 
   str = gst_rtsp_media_get_range_string (media, FALSE, GST_RTSP_RANGE_NPT);
   fail_unless (g_str_equal (str, "npt=0-"));
@@ -132,10 +132,10 @@ GST_START_TEST (test_media_prepare)
   fail_unless (GST_IS_RTSP_MEDIA (media));
   fail_unless (gst_rtsp_media_n_streams (media) == 1);
 
-  fail_unless (gst_rtsp_media_prepare (media));
+  fail_unless (gst_rtsp_media_prepare (media, NULL));
   fail_unless (gst_rtsp_media_unprepare (media));
   fail_unless (gst_rtsp_media_n_streams (media) == 1);
-  fail_if (gst_rtsp_media_prepare (media));
+  fail_if (gst_rtsp_media_prepare (media, NULL));
 
   g_object_unref (media);
   gst_rtsp_url_free (url);
@@ -155,10 +155,10 @@ GST_START_TEST (test_media_prepare)
 
   g_object_set (G_OBJECT (media), "reusable", TRUE, NULL);
 
-  fail_unless (gst_rtsp_media_prepare (media));
+  fail_unless (gst_rtsp_media_prepare (media, NULL));
   fail_unless (gst_rtsp_media_unprepare (media));
   fail_unless (gst_rtsp_media_n_streams (media) == 1);
-  fail_unless (gst_rtsp_media_prepare (media));
+  fail_unless (gst_rtsp_media_prepare (media, NULL));
   fail_unless (gst_rtsp_media_unprepare (media));
 
   g_object_unref (media);
@@ -220,13 +220,13 @@ GST_START_TEST (test_media_dyn_prepare)
   g_signal_connect (srcpad, "notify::caps", (GCallback) on_notify_caps, pay);
 
   fail_unless (gst_rtsp_media_n_streams (media) == 0);
-  fail_unless (gst_rtsp_media_prepare (media));
+  fail_unless (gst_rtsp_media_prepare (media, NULL));
   fail_unless (gst_rtsp_media_n_streams (media) == 1);
   fail_unless (gst_rtsp_media_unprepare (media));
   fail_unless (gst_rtsp_media_n_streams (media) == 0);
 
   fail_unless (gst_rtsp_media_n_streams (media) == 0);
-  fail_unless (gst_rtsp_media_prepare (media));
+  fail_unless (gst_rtsp_media_prepare (media, NULL));
   fail_unless (gst_rtsp_media_n_streams (media) == 1);
   fail_unless (gst_rtsp_media_unprepare (media));
   fail_unless (gst_rtsp_media_n_streams (media) == 0);