media: add optional context for bus messages

Add an optional mainloop to _prepare that will handle the bus messages instead
of always using the shared mainloop.
This commit is contained in:
Wim Taymans 2013-07-05 20:43:39 +02:00
parent 48ff096a25
commit 12583e819c
4 changed files with 12 additions and 11 deletions

View file

@ -522,7 +522,7 @@ find_media (GstRTSPClient * client, GstRTSPClientState * state, gint * matched)
goto no_media; goto no_media;
/* prepare the media */ /* prepare the media */
if (!(gst_rtsp_media_prepare (media))) if (!(gst_rtsp_media_prepare (media, NULL)))
goto no_prepare; goto no_prepare;
/* now keep track of the uri and the media */ /* now keep track of the uri and the media */

View file

@ -1507,6 +1507,7 @@ struct _DynPaySignalHandlers
/** /**
* gst_rtsp_media_prepare: * gst_rtsp_media_prepare:
* @media: a #GstRTSPMedia * @media: a #GstRTSPMedia
* @context: a #GMainContext to run the bus handler or %NULL
* *
* Prepare @media for streaming. This function will create the objects * Prepare @media for streaming. This function will create the objects
* to manage the streaming. A pipeline must have been set on @media with * to manage the streaming. A pipeline must have been set on @media with
@ -1518,7 +1519,7 @@ struct _DynPaySignalHandlers
* Returns: %TRUE on success. * Returns: %TRUE on success.
*/ */
gboolean gboolean
gst_rtsp_media_prepare (GstRTSPMedia * media) gst_rtsp_media_prepare (GstRTSPMedia * media, GMainContext * context)
{ {
GstRTSPMediaPrivate *priv; GstRTSPMediaPrivate *priv;
GstStateChangeReturn ret; GstStateChangeReturn ret;
@ -1570,7 +1571,7 @@ gst_rtsp_media_prepare (GstRTSPMedia * media)
g_object_ref (media), (GDestroyNotify) watch_destroyed); g_object_ref (media), (GDestroyNotify) watch_destroyed);
klass = GST_RTSP_MEDIA_GET_CLASS (media); 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 */ /* add stuff to the bin */
gst_bin_add (GST_BIN (priv->pipeline), priv->rtpbin); gst_bin_add (GST_BIN (priv->pipeline), priv->rtpbin);

View file

@ -149,7 +149,7 @@ GstNetTimeProvider * gst_rtsp_media_get_time_provider (GstRTSPMedia *media,
const gchar *address, guint16 port); const gchar *address, guint16 port);
/* prepare the media for playback */ /* 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); gboolean gst_rtsp_media_unprepare (GstRTSPMedia *media);
/* creating streams */ /* creating streams */

View file

@ -53,7 +53,7 @@ GST_START_TEST (test_launch)
/* fails, need to be prepared */ /* fails, need to be prepared */
fail_if (gst_rtsp_media_seek (media, range)); 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); str = gst_rtsp_media_get_range_string (media, FALSE, GST_RTSP_RANGE_NPT);
fail_unless (g_str_equal (str, "npt=0-")); 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_IS_RTSP_MEDIA (media));
fail_unless (gst_rtsp_media_n_streams (media) == 1); 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_unprepare (media));
fail_unless (gst_rtsp_media_n_streams (media) == 1); 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); g_object_unref (media);
gst_rtsp_url_free (url); gst_rtsp_url_free (url);
@ -155,10 +155,10 @@ GST_START_TEST (test_media_prepare)
g_object_set (G_OBJECT (media), "reusable", TRUE, NULL); 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_unprepare (media));
fail_unless (gst_rtsp_media_n_streams (media) == 1); 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_unprepare (media));
g_object_unref (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); 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_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_n_streams (media) == 1);
fail_unless (gst_rtsp_media_unprepare (media)); 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_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_n_streams (media) == 1);
fail_unless (gst_rtsp_media_unprepare (media)); 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);