mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-11-27 12:11:13 +00:00
uridownloader: add support for range based downloads
Adds a new API gst_uri_downloader_fetch_uri_with_range that allows downloading only a byte range from an URI. It uses a seek event sent to the source to signal the range to be downloaded. https://bugzilla.gnome.org/show_bug.cgi?id=702206
This commit is contained in:
parent
65758debf1
commit
e76f3e95fd
2 changed files with 47 additions and 2 deletions
|
@ -320,6 +320,24 @@ gst_uri_downloader_cancel (GstUriDownloader * downloader)
|
|||
}
|
||||
}
|
||||
|
||||
static gboolean
|
||||
gst_uri_downloader_set_range (GstUriDownloader * downloader,
|
||||
gint64 range_start, gint64 range_end)
|
||||
{
|
||||
g_return_val_if_fail (range_start >= 0, FALSE);
|
||||
g_return_val_if_fail (range_end >= -1, FALSE);
|
||||
|
||||
if (range_start || (range_end >= 0)) {
|
||||
GstEvent *seek;
|
||||
|
||||
seek = gst_event_new_seek (1.0, GST_FORMAT_BYTES, GST_SEEK_FLAG_FLUSH,
|
||||
GST_SEEK_TYPE_SET, range_start, GST_SEEK_TYPE_SET, range_end);
|
||||
|
||||
return gst_element_send_event (downloader->priv->urisrc, seek);
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
gst_uri_downloader_set_uri (GstUriDownloader * downloader, const gchar * uri)
|
||||
{
|
||||
|
@ -352,6 +370,22 @@ gst_uri_downloader_set_uri (GstUriDownloader * downloader, const gchar * uri)
|
|||
|
||||
GstFragment *
|
||||
gst_uri_downloader_fetch_uri (GstUriDownloader * downloader, const gchar * uri)
|
||||
{
|
||||
return gst_uri_downloader_fetch_uri_with_range (downloader, uri, 0, -1);
|
||||
}
|
||||
|
||||
/**
|
||||
* gst_uri_downloader_fetch_uri_with_range:
|
||||
* @downloader: the #GstUriDownloader
|
||||
* @uri: the uri
|
||||
* @range_start: the starting byte index
|
||||
* @range_end: the final byte index, use -1 for unspecified
|
||||
*
|
||||
* Returns the downloaded #GstFragment
|
||||
*/
|
||||
GstFragment *
|
||||
gst_uri_downloader_fetch_uri_with_range (GstUriDownloader * downloader,
|
||||
const gchar * uri, gint64 range_start, gint64 range_end)
|
||||
{
|
||||
GstStateChangeReturn ret;
|
||||
GstFragment *download = NULL;
|
||||
|
@ -363,12 +397,22 @@ gst_uri_downloader_fetch_uri (GstUriDownloader * downloader, const gchar * uri)
|
|||
}
|
||||
|
||||
if (!gst_uri_downloader_set_uri (downloader, uri)) {
|
||||
GST_WARNING_OBJECT (downloader, "Failed to set URI");
|
||||
goto quit;
|
||||
}
|
||||
|
||||
gst_bus_set_flushing (downloader->priv->bus, FALSE);
|
||||
ret = gst_element_set_state (downloader->priv->urisrc, GST_STATE_READY);
|
||||
if (ret == GST_STATE_CHANGE_FAILURE) {
|
||||
goto quit;
|
||||
}
|
||||
|
||||
if (!gst_uri_downloader_set_range (downloader, range_start, range_end)) {
|
||||
GST_WARNING_OBJECT (downloader, "Failed to set range");
|
||||
goto quit;
|
||||
}
|
||||
|
||||
downloader->priv->download = gst_fragment_new ();
|
||||
|
||||
gst_bus_set_flushing (downloader->priv->bus, FALSE);
|
||||
ret = gst_element_set_state (downloader->priv->urisrc, GST_STATE_PLAYING);
|
||||
if (ret == GST_STATE_CHANGE_FAILURE) {
|
||||
g_object_unref (downloader->priv->download);
|
||||
|
|
|
@ -57,6 +57,7 @@ GType gst_uri_downloader_get_type (void);
|
|||
|
||||
GstUriDownloader * gst_uri_downloader_new (void);
|
||||
GstFragment * gst_uri_downloader_fetch_uri (GstUriDownloader * downloader, const gchar * uri);
|
||||
GstFragment * gst_uri_downloader_fetch_uri_with_range (GstUriDownloader * downloader, const gchar * uri, gint64 range_start, gint64 range_end);
|
||||
void gst_uri_downloader_reset (GstUriDownloader *downloader);
|
||||
void gst_uri_downloader_cancel (GstUriDownloader *downloader);
|
||||
void gst_uri_downloader_free (GstUriDownloader *downloader);
|
||||
|
|
Loading…
Reference in a new issue