mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-12-28 03:00:35 +00:00
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
This commit is contained in:
parent
b8605b56af
commit
8cf858fb27
2 changed files with 52 additions and 0 deletions
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in a new issue