mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2025-04-26 15:04:46 +00:00
uridownloader: Re-use old source element if possible
Allows to implement keep-alive handling in the source element.
This commit is contained in:
parent
e40b72bc9b
commit
c76ea2919f
1 changed files with 33 additions and 15 deletions
|
@ -112,6 +112,7 @@ gst_uri_downloader_dispose (GObject * object)
|
||||||
GstUriDownloader *downloader = GST_URI_DOWNLOADER (object);
|
GstUriDownloader *downloader = GST_URI_DOWNLOADER (object);
|
||||||
|
|
||||||
if (downloader->priv->urisrc != NULL) {
|
if (downloader->priv->urisrc != NULL) {
|
||||||
|
gst_element_set_state (downloader->priv->urisrc, GST_STATE_NULL);
|
||||||
gst_object_unref (downloader->priv->urisrc);
|
gst_object_unref (downloader->priv->urisrc);
|
||||||
downloader->priv->urisrc = NULL;
|
downloader->priv->urisrc = NULL;
|
||||||
}
|
}
|
||||||
|
@ -318,13 +319,36 @@ gst_uri_downloader_set_uri (GstUriDownloader * downloader, const gchar * uri,
|
||||||
if (!gst_uri_is_valid (uri))
|
if (!gst_uri_is_valid (uri))
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
g_assert (downloader->priv->urisrc == NULL);
|
if (downloader->priv->urisrc) {
|
||||||
|
gchar *old_protocol, *new_protocol;
|
||||||
|
gchar *old_uri;
|
||||||
|
|
||||||
GST_DEBUG_OBJECT (downloader, "Creating source element for the URI:%s", uri);
|
old_uri =
|
||||||
downloader->priv->urisrc =
|
gst_uri_handler_get_uri (GST_URI_HANDLER (downloader->priv->urisrc));
|
||||||
gst_element_make_from_uri (GST_URI_SRC, uri, NULL, NULL);
|
old_protocol = gst_uri_get_protocol (old_uri);
|
||||||
if (!downloader->priv->urisrc)
|
new_protocol = gst_uri_get_protocol (uri);
|
||||||
return FALSE;
|
|
||||||
|
if (!g_str_equal (old_protocol, new_protocol)) {
|
||||||
|
gst_element_set_state (downloader->priv->urisrc, GST_STATE_NULL);
|
||||||
|
gst_object_unref (downloader->priv->urisrc);
|
||||||
|
downloader->priv->urisrc = NULL;
|
||||||
|
GST_DEBUG_OBJECT (downloader, "Can't re-use old source element");
|
||||||
|
} else {
|
||||||
|
GST_DEBUG_OBJECT (downloader, "Re-using old source element");
|
||||||
|
}
|
||||||
|
g_free (old_uri);
|
||||||
|
g_free (old_protocol);
|
||||||
|
g_free (new_protocol);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!downloader->priv->urisrc) {
|
||||||
|
GST_DEBUG_OBJECT (downloader, "Creating source element for the URI:%s",
|
||||||
|
uri);
|
||||||
|
downloader->priv->urisrc =
|
||||||
|
gst_element_make_from_uri (GST_URI_SRC, uri, NULL, NULL);
|
||||||
|
if (!downloader->priv->urisrc)
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
gobject_class = G_OBJECT_GET_CLASS (downloader->priv->urisrc);
|
gobject_class = G_OBJECT_GET_CLASS (downloader->priv->urisrc);
|
||||||
if (g_object_class_find_property (gobject_class, "compress"))
|
if (g_object_class_find_property (gobject_class, "compress"))
|
||||||
|
@ -459,12 +483,11 @@ quit:
|
||||||
|
|
||||||
/* remove the bus' sync handler */
|
/* remove the bus' sync handler */
|
||||||
gst_bus_set_sync_handler (downloader->priv->bus, NULL, NULL, NULL);
|
gst_bus_set_sync_handler (downloader->priv->bus, NULL, NULL, NULL);
|
||||||
|
gst_bus_set_flushing (downloader->priv->bus, TRUE);
|
||||||
|
|
||||||
/* set the element state to NULL */
|
/* set the element state to NULL */
|
||||||
GST_OBJECT_UNLOCK (downloader);
|
GST_OBJECT_UNLOCK (downloader);
|
||||||
gst_bus_set_flushing (downloader->priv->bus, TRUE);
|
gst_element_set_state (urisrc, GST_STATE_READY);
|
||||||
gst_element_set_state (urisrc, GST_STATE_NULL);
|
|
||||||
gst_element_get_state (urisrc, NULL, NULL, GST_CLOCK_TIME_NONE);
|
|
||||||
GST_OBJECT_LOCK (downloader);
|
GST_OBJECT_LOCK (downloader);
|
||||||
gst_element_set_bus (urisrc, NULL);
|
gst_element_set_bus (urisrc, NULL);
|
||||||
|
|
||||||
|
@ -474,13 +497,8 @@ quit:
|
||||||
gst_pad_unlink (pad, downloader->priv->pad);
|
gst_pad_unlink (pad, downloader->priv->pad);
|
||||||
gst_object_unref (pad);
|
gst_object_unref (pad);
|
||||||
}
|
}
|
||||||
downloader->priv->urisrc = NULL;
|
|
||||||
GST_OBJECT_UNLOCK (downloader);
|
|
||||||
|
|
||||||
gst_object_unref (urisrc);
|
|
||||||
} else {
|
|
||||||
GST_OBJECT_UNLOCK (downloader);
|
|
||||||
}
|
}
|
||||||
|
GST_OBJECT_UNLOCK (downloader);
|
||||||
|
|
||||||
if (download == NULL) {
|
if (download == NULL) {
|
||||||
if (!downloader->priv->err) {
|
if (!downloader->priv->err) {
|
||||||
|
|
Loading…
Reference in a new issue