diff options
author | Thiago Santos <thiago.sousa.santos@collabora.com> | 2013-06-19 18:28:15 -0300 |
---|---|---|
committer | Thiago Santos <thiago.sousa.santos@collabora.com> | 2013-07-01 14:22:01 -0300 |
commit | e76f3e95fd0846bccccab387755aace9c0050c2b (patch) | |
tree | 79ce382deeaeb076e32be46257039b520f864cb3 /gst-libs/gst/uridownloader | |
parent | 65758debf1eead6028f0b22a13d7965d44c0f731 (diff) | |
download | gstreamer-plugins-bad-e76f3e95fd0846bccccab387755aace9c0050c2b.tar.gz |
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
Diffstat (limited to 'gst-libs/gst/uridownloader')
-rw-r--r-- | gst-libs/gst/uridownloader/gsturidownloader.c | 48 | ||||
-rw-r--r-- | gst-libs/gst/uridownloader/gsturidownloader.h | 1 |
2 files changed, 47 insertions, 2 deletions
diff --git a/gst-libs/gst/uridownloader/gsturidownloader.c b/gst-libs/gst/uridownloader/gsturidownloader.c index 15af6a498..6056ac88a 100644 --- a/gst-libs/gst/uridownloader/gsturidownloader.c +++ b/gst-libs/gst/uridownloader/gsturidownloader.c @@ -321,6 +321,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) { GstPad *pad; @@ -353,6 +371,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; } - downloader->priv->download = gst_fragment_new (); - 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 (); ret = gst_element_set_state (downloader->priv->urisrc, GST_STATE_PLAYING); if (ret == GST_STATE_CHANGE_FAILURE) { g_object_unref (downloader->priv->download); diff --git a/gst-libs/gst/uridownloader/gsturidownloader.h b/gst-libs/gst/uridownloader/gsturidownloader.h index c29cb52b3..c5837c342 100644 --- a/gst-libs/gst/uridownloader/gsturidownloader.h +++ b/gst-libs/gst/uridownloader/gsturidownloader.h @@ -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); |