summaryrefslogtreecommitdiff
path: root/ext
diff options
context:
space:
mode:
authorThiago Santos <ts.santos@sisa.samsung.com>2014-04-16 20:02:35 -0300
committerThiago Santos <ts.santos@sisa.samsung.com>2014-04-29 18:17:07 -0300
commit4b9d91d4974e9751313f13e0b1e8b1c7e55d72d0 (patch)
tree3b44456c7b7fe920f5fa54aeaf44a24f39b17da6 /ext
parent671f8c0e35ae0875b0835eba94b63410e8772640 (diff)
downloadgstreamer-plugins-bad-4b9d91d4974e9751313f13e0b1e8b1c7e55d72d0.tar.gz
hlsdemux: create sources from uri
Instead of using always an http source, create it dynamically from uri when needed. If not needed just replace the URI on the current element
Diffstat (limited to 'ext')
-rw-r--r--ext/hls/gsthlsdemux.c58
1 files changed, 49 insertions, 9 deletions
diff --git a/ext/hls/gsthlsdemux.c b/ext/hls/gsthlsdemux.c
index b42bdb62e..6ede49556 100644
--- a/ext/hls/gsthlsdemux.c
+++ b/ext/hls/gsthlsdemux.c
@@ -242,9 +242,6 @@ gst_hls_demux_init (GstHLSDemux * demux)
demux->stream_task =
gst_task_new ((GstTaskFunction) gst_hls_demux_stream_loop, demux, NULL);
gst_task_set_lock (demux->stream_task, &demux->stream_lock);
- demux->src = gst_element_factory_make ("souphttpsrc", "hls-download-src");
- gst_element_set_locked_state (demux->src, TRUE);
- gst_bin_add (GST_BIN_CAST (demux), demux->src);
demux->have_group_id = FALSE;
demux->group_id = G_MAXUINT;
@@ -1717,6 +1714,48 @@ decrypt_error:
return decrypted_buffer;
}
+static void
+gst_hls_demux_update_source (GstHLSDemux * demux, const gchar * uri)
+{
+ if (!gst_uri_is_valid (uri)) /* TODO error out */
+ return;
+
+ if (demux->src != NULL) {
+ gchar *old_protocol, *new_protocol;
+ gchar *old_uri;
+
+ old_uri = gst_uri_handler_get_uri (GST_URI_HANDLER (demux->src));
+ old_protocol = gst_uri_get_protocol (old_uri);
+ new_protocol = gst_uri_get_protocol (uri);
+
+ if (!g_str_equal (old_protocol, new_protocol)) {
+ gst_bin_remove (GST_BIN_CAST (demux), demux->src);
+ demux->src = NULL;
+ GST_DEBUG_OBJECT (demux, "Can't re-use old source element");
+ } else {
+ GError *err = NULL;
+
+ GST_DEBUG_OBJECT (demux, "Re-using old source element");
+ if (!gst_uri_handler_set_uri (GST_URI_HANDLER (demux->src), uri, &err)) {
+ GST_DEBUG_OBJECT (demux, "Failed to re-use old source element: %s",
+ err->message);
+ g_clear_error (&err);
+ gst_bin_remove (GST_BIN_CAST (demux), demux->src);
+ demux->src = NULL;
+ }
+ }
+ g_free (old_uri);
+ g_free (old_protocol);
+ g_free (new_protocol);
+ }
+
+ if (demux->src == NULL) {
+ demux->src = gst_element_make_from_uri (GST_URI_SRC, uri, NULL, NULL);
+ gst_element_set_locked_state (demux->src, TRUE);
+ gst_bin_add (GST_BIN_CAST (demux), demux->src);
+ }
+}
+
static gboolean
gst_hls_demux_get_next_fragment (GstHLSDemux * demux,
gboolean * end_of_playlist, GError ** err)
@@ -1738,11 +1777,6 @@ gst_hls_demux_get_next_fragment (GstHLSDemux * demux,
return FALSE;
}
- if (!gst_hls_demux_configure_src_pad (demux, NULL)) {
- *end_of_playlist = FALSE;
- return FALSE;
- }
-
g_mutex_lock (&demux->fragment_download_lock);
GST_DEBUG_OBJECT (demux,
"Fetching next fragment %s (range=%" G_GINT64_FORMAT "-%" G_GINT64_FORMAT
@@ -1753,7 +1787,13 @@ gst_hls_demux_get_next_fragment (GstHLSDemux * demux,
demux->starting_fragment = TRUE;
demux->current_key = key;
demux->current_iv = iv;
- g_object_set (demux->src, "location", next_fragment_uri, NULL);
+
+ gst_hls_demux_update_source (demux, next_fragment_uri);
+ if (!gst_hls_demux_configure_src_pad (demux, NULL)) {
+ *end_of_playlist = FALSE;
+ return FALSE;
+ }
+
gst_element_set_state (demux->src, GST_STATE_READY); /* TODO check return */
gst_element_send_event (demux->src, gst_event_new_seek (1.0, GST_FORMAT_BYTES,
(GstSeekFlags) GST_SEEK_FLAG_FLUSH, GST_SEEK_TYPE_SET, range_start,