diff options
author | Thiago Santos <thiagoss@osg.samsung.com> | 2015-12-09 13:12:42 -0300 |
---|---|---|
committer | Sebastian Dröge <sebastian@centricular.com> | 2017-04-03 11:35:51 +0300 |
commit | 8cf858fb27919e1d631223375f81b98055623733 (patch) | |
tree | 36448283fad5396f85e88d365fe810f96c60d7d6 /gst-libs | |
parent | b8605b56affcb8534b412cb08ccf8c029e82a476 (diff) | |
download | gstreamer-plugins-bad-8cf858fb27919e1d631223375f81b98055623733.tar.gz |
uridownloader: add new gst_uri_downloader_set_parent
If set, the parent is used to proxy need-context messages from
uridownloader's http source in order to get cookies/headers
from the pipeline.
Based on a patch from Philippe Normand
https://bugzilla.gnome.org/show_bug.cgi?id=726314
Diffstat (limited to 'gst-libs')
-rw-r--r-- | gst-libs/gst/uridownloader/gsturidownloader.c | 51 | ||||
-rw-r--r-- | gst-libs/gst/uridownloader/gsturidownloader.h | 1 |
2 files changed, 52 insertions, 0 deletions
diff --git a/gst-libs/gst/uridownloader/gsturidownloader.c b/gst-libs/gst/uridownloader/gsturidownloader.c index 47b6f2951..f54ced462 100644 --- a/gst-libs/gst/uridownloader/gsturidownloader.c +++ b/gst-libs/gst/uridownloader/gsturidownloader.c @@ -42,6 +42,8 @@ struct _GstUriDownloaderPrivate gboolean got_buffer; GMutex download_lock; /* used to restrict to one download only */ + GstElement *parent; + GError *err; GCond cond; @@ -133,6 +135,11 @@ gst_uri_downloader_dispose (GObject * object) downloader->priv->download = NULL; } + if (downloader->priv->parent) { + gst_object_unref (downloader->priv->parent); + downloader->priv->parent = NULL; + } + G_OBJECT_CLASS (gst_uri_downloader_parent_class)->dispose (object); } @@ -153,6 +160,23 @@ gst_uri_downloader_new (void) return g_object_new (GST_TYPE_URI_DOWNLOADER, NULL); } +/** + * gst_uri_downloader_set_parent: + * @param downloader: the #GstUriDownloader + * @param parent: the parent #GstElement + * + * Sets an element as parent of this #GstUriDownloader so that context + * requests from the underlying source are proxied to the main pipeline + * and set back if a context was provided. + */ +void +gst_uri_downloader_set_parent (GstUriDownloader * downloader, + GstElement * parent) +{ + gst_object_replace ((GstObject **) & downloader->priv->parent, + GST_OBJECT_CAST (parent)); +} + static gboolean gst_uri_downloader_sink_event (GstPad * pad, GstObject * parent, GstEvent * event) @@ -255,6 +279,33 @@ gst_uri_downloader_bus_handler (GstBus * bus, GST_DEBUG ("Debugging info: %s\n", (dbg_info) ? dbg_info : "none"); g_error_free (err); g_free (dbg_info); + } else if (GST_MESSAGE_TYPE (message) == GST_MESSAGE_NEED_CONTEXT) { + /* post the same need-context as if it was from the parent and then + * get it to our internal element that requested it */ + if (downloader->priv->parent && GST_IS_ELEMENT (GST_MESSAGE_SRC (message))) { + const gchar *context_type; + GstContext *context; + GstElement *msg_src = GST_ELEMENT_CAST (GST_MESSAGE_SRC (message)); + + gst_message_parse_context_type (message, &context_type); + context = + gst_element_get_context (downloader->priv->parent, context_type); + + /* No context, request one */ + if (!context) { + GstMessage *need_context_msg = + gst_message_new_need_context (GST_OBJECT_CAST (downloader-> + priv->parent), context_type); + gst_element_post_message (downloader->priv->parent, need_context_msg); + context = + gst_element_get_context (downloader->priv->parent, context_type); + } + + if (context) { + gst_element_set_context (msg_src, context); + gst_context_unref (context); + } + } } gst_message_unref (message); diff --git a/gst-libs/gst/uridownloader/gsturidownloader.h b/gst-libs/gst/uridownloader/gsturidownloader.h index 80b8a3e76..b37725222 100644 --- a/gst-libs/gst/uridownloader/gsturidownloader.h +++ b/gst-libs/gst/uridownloader/gsturidownloader.h @@ -61,6 +61,7 @@ struct _GstUriDownloaderClass GType gst_uri_downloader_get_type (void); GstUriDownloader * gst_uri_downloader_new (void); +void gst_uri_downloader_set_parent (GstUriDownloader * downloader, GstElement * parent); GstFragment * gst_uri_downloader_fetch_uri (GstUriDownloader * downloader, const gchar * uri, const gchar * referer, gboolean compress, gboolean refresh, gboolean allow_cache, GError ** err); GstFragment * gst_uri_downloader_fetch_uri_with_range (GstUriDownloader * downloader, const gchar * uri, const gchar * referer, gboolean compress, gboolean refresh, gboolean allow_cache, gint64 range_start, gint64 range_end, GError ** err); void gst_uri_downloader_reset (GstUriDownloader *downloader); |