1 diff --git a/gst/hls/gsthlsdemux.c b/gst/hls/gsthlsdemux.c
2 index 3308a29..09acee1 100644
3 --- a/gst/hls/gsthlsdemux.c
4 +++ b/gst/hls/gsthlsdemux.c
5 @@ -315,14 +315,6 @@ gst_hls_demux_change_state (GstElement * element, GstStateChange transition)
6 case GST_STATE_CHANGE_READY_TO_PAUSED:
7 gst_hls_demux_reset (demux, FALSE);
9 - case GST_STATE_CHANGE_PAUSED_TO_PLAYING:
10 - /* Start the streaming loop in paused only if we already received
11 - the main playlist. It might have been stopped if we were in PAUSED
12 - state and we filled our queue with enough cached fragments
14 - if (gst_m3u8_client_get_uri (demux->client)[0] != '\0')
15 - gst_task_start (demux->updates_task);
20 @@ -330,17 +322,6 @@ gst_hls_demux_change_state (GstElement * element, GstStateChange transition)
21 ret = GST_ELEMENT_CLASS (parent_class)->change_state (element, transition);
24 - case GST_STATE_CHANGE_PLAYING_TO_PAUSED:
25 - demux->cancelled = TRUE;
26 - gst_uri_downloader_cancel (demux->downloader);
27 - gst_task_stop (demux->updates_task);
28 - g_mutex_lock (demux->updates_timed_lock);
29 - GST_TASK_SIGNAL (demux->updates_task);
30 - g_mutex_unlock (demux->updates_timed_lock);
31 - g_static_rec_mutex_lock (&demux->updates_lock);
32 - g_static_rec_mutex_unlock (&demux->updates_lock);
33 - demux->cancelled = FALSE;
35 case GST_STATE_CHANGE_PAUSED_TO_READY:
36 demux->cancelled = TRUE;
37 gst_hls_demux_stop (demux);
38 @@ -718,14 +699,14 @@ gst_hls_demux_stream_loop (GstHLSDemux * demux)
39 * cache the first fragments and then it waits until it has more data in the
40 * queue. This task is woken up when we push a new fragment to the queue or
41 * when we reached the end of the playlist */
42 + GST_DEBUG_OBJECT (demux, "Enter task");
44 if (G_UNLIKELY (demux->need_cache)) {
45 if (!gst_hls_demux_cache_fragments (demux))
48 /* we can start now the updates thread (only if on playing) */
49 - if (GST_STATE (demux) == GST_STATE_PLAYING)
50 - gst_task_start (demux->updates_task);
51 + gst_task_start (demux->updates_task);
52 GST_INFO_OBJECT (demux, "First fragments cached successfully");
55 @@ -765,10 +746,14 @@ gst_hls_demux_stream_loop (GstHLSDemux * demux)
56 demux->position_shift = 0;
59 + GST_DEBUG_OBJECT (demux, "Pushing buffer %p", buf);
61 ret = gst_pad_push_list (demux->srcpad, buffer_list);
62 if (ret != GST_FLOW_OK)
65 + GST_DEBUG_OBJECT (demux, "Pushed buffer");
70 @@ -806,6 +791,7 @@ error_pushing:
74 + GST_DEBUG_OBJECT (demux, "Pause task");
75 gst_task_pause (demux->stream_task);
78 @@ -877,10 +863,13 @@ gst_hls_demux_updates_loop (GstHLSDemux * demux)
79 gst_hls_demux_schedule (demux);
81 /* block until the next scheduled update or the signal to quit this thread */
82 + GST_DEBUG_OBJECT (demux, "Waiting");
83 if (g_cond_timed_wait (GST_TASK_GET_COND (demux->updates_task),
84 demux->updates_timed_lock, &demux->next_update)) {
85 + GST_DEBUG_OBJECT (demux, "Unlocked");
88 + GST_DEBUG_OBJECT (demux, "Continue");
92 @@ -918,6 +907,7 @@ gst_hls_demux_updates_loop (GstHLSDemux * demux)
94 /* fetch the next fragment */
95 if (g_queue_is_empty (demux->queue)) {
96 + GST_DEBUG_OBJECT (demux, "queue empty, get next fragment");
97 if (!gst_hls_demux_get_next_fragment (demux, FALSE)) {
98 if (demux->cancelled) {
100 @@ -1289,6 +1279,7 @@ gst_hls_demux_get_next_fragment (GstHLSDemux * demux, gboolean caching)
101 GST_BUFFER_FLAG_SET (buf, GST_BUFFER_FLAG_DISCONT);
104 + GST_DEBUG_OBJECT (demux, "Pushing fragment in queue");
105 g_queue_push_tail (demux->queue, download);
106 gst_buffer_list_unref (buffer_list);
108 diff --git a/gst/hls/m3u8.c b/gst/hls/m3u8.c
109 index 65afa8b..b6c04a8 100644
112 @@ -37,6 +37,7 @@ static gboolean gst_m3u8_update (GstM3U8 * m3u8, gchar * data,
113 static GstM3U8MediaFile *gst_m3u8_media_file_new (gchar * uri,
114 gchar * title, GstClockTime duration, guint sequence);
115 static void gst_m3u8_media_file_free (GstM3U8MediaFile * self);
116 +gchar *uri_join (const gchar * uri, const gchar * path);
120 @@ -270,24 +271,9 @@ gst_m3u8_update (GstM3U8 * self, gchar * data, gboolean * updated)
124 - if (!gst_uri_is_valid (data)) {
127 - GST_WARNING ("uri not set, can't build a valid uri");
130 - slash = g_utf8_strrchr (self->uri, -1, '/');
132 - GST_WARNING ("Can't build a valid uri");
137 - data = g_strdup_printf ("%s/%s", self->uri, data);
140 - data = g_strdup (data);
142 + data = uri_join (self->uri, data);
146 r = g_utf8_strchr (data, -1, '\r');
148 @@ -674,3 +660,51 @@ gst_m3u8_client_get_playlist_for_bitrate (GstM3U8Client * client, guint bitrate)
150 return current_variant;
154 +uri_join (const gchar * uri1, const gchar * uri2)
156 + gchar *uri_copy, *tmp, *ret = NULL;
158 + if (gst_uri_is_valid (uri2))
159 + return g_strdup (uri2);
161 + uri_copy = g_strdup (uri1);
162 + if (uri2[0] != '/') {
163 + /* uri2 is a relative uri2 */
164 + tmp = g_utf8_strrchr (uri_copy, -1, '/');
166 + GST_WARNING ("Can't build a valid uri_copy");
171 + ret = g_strdup_printf ("%s/%s", uri_copy, uri2);
173 + /* uri2 is an absolute uri2 */
174 + char *scheme, *hostname;
177 + /* find the : in <scheme>:// */
178 + tmp = g_utf8_strchr (uri_copy, -1, ':');
180 + GST_WARNING ("Can't build a valid uri_copy");
187 + hostname = tmp + 3;
189 + tmp = g_utf8_strchr (hostname, -1, '/');
193 + ret = g_strdup_printf ("%s://%s%s", scheme, hostname, uri2);