uridownloader: when possible, reuse existing element to download a new URI

previously a new element was allocated for each media segment, and it was never freed
This commit is contained in:
Gianluca Gennari 2012-10-17 18:45:25 +02:00 committed by Thiago Santos
parent 5b830c3c91
commit 122f10669f

View file

@ -273,10 +273,16 @@ gst_uri_downloader_set_uri (GstUriDownloader * downloader, const gchar * uri)
if (!gst_uri_is_valid (uri))
return FALSE;
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);
if (!downloader->priv->urisrc)
return FALSE;
if (downloader->priv->urisrc == NULL) {
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);
if (!downloader->priv->urisrc)
return FALSE;
} else {
GST_DEBUG_OBJECT (downloader, "Reusing existing source element for the URI:%s", uri);
if (!gst_uri_handler_set_uri (GST_URI_HANDLER (downloader->priv->urisrc), uri))
return FALSE;
}
/* add a sync handler for the bus messages to detect errors in the download */
gst_element_set_bus (GST_ELEMENT (downloader->priv->urisrc),