gst-plugins-bad : update SRCREV & patchs.
[vuplus_openvuplus_3.0] / meta-openvuplus / recipes-multimedia / gstreamer / gst-plugins-bad-0.10.23 / 0006-hlsdemux-backport.patch
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);
8        break;
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
13 -       */
14 -      if (gst_m3u8_client_get_uri (demux->client)[0] != '\0')
15 -        gst_task_start (demux->updates_task);
16 -      break;
17      default:
18        break;
19    }
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);
22  
23    switch (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;
34 -      break;
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");
43  
44    if (G_UNLIKELY (demux->need_cache)) {
45      if (!gst_hls_demux_cache_fragments (demux))
46        goto cache_error;
47  
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");
53    }
54  
55 @@ -765,10 +746,14 @@ gst_hls_demux_stream_loop (GstHLSDemux * demux)
56      demux->position_shift = 0;
57    }
58  
59 +  GST_DEBUG_OBJECT (demux, "Pushing buffer %p", buf);
60 +
61    ret = gst_pad_push_list (demux->srcpad, buffer_list);
62    if (ret != GST_FLOW_OK)
63      goto error_pushing;
64  
65 +  GST_DEBUG_OBJECT (demux, "Pushed buffer");
66 +
67    return;
68  
69  end_of_playlist:
70 @@ -806,6 +791,7 @@ error_pushing:
71  
72  pause_task:
73    {
74 +    GST_DEBUG_OBJECT (demux, "Pause task");
75      gst_task_pause (demux->stream_task);
76      return;
77    }
78 @@ -877,10 +863,13 @@ gst_hls_demux_updates_loop (GstHLSDemux * demux)
79      gst_hls_demux_schedule (demux);
80  
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");
86        goto quit;
87      }
88 +    GST_DEBUG_OBJECT (demux, "Continue");
89  
90      if (demux->cancelled)
91        goto quit;
92 @@ -918,6 +907,7 @@ gst_hls_demux_updates_loop (GstHLSDemux * demux)
93  
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) {
99            goto quit;
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);
102    }
103  
104 +  GST_DEBUG_OBJECT (demux, "Pushing fragment in queue");
105    g_queue_push_tail (demux->queue, download);
106    gst_buffer_list_unref (buffer_list);
107    if (!caching) {
108 diff --git a/gst/hls/m3u8.c b/gst/hls/m3u8.c
109 index 65afa8b..b6c04a8 100644
110 --- a/gst/hls/m3u8.c
111 +++ b/gst/hls/m3u8.c
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);
117  
118  static GstM3U8 *
119  gst_m3u8_new (void)
120 @@ -270,24 +271,9 @@ gst_m3u8_update (GstM3U8 * self, gchar * data, gboolean * updated)
121          goto next_line;
122        }
123  
124 -      if (!gst_uri_is_valid (data)) {
125 -        gchar *slash;
126 -        if (!self->uri) {
127 -          GST_WARNING ("uri not set, can't build a valid uri");
128 -          goto next_line;
129 -        }
130 -        slash = g_utf8_strrchr (self->uri, -1, '/');
131 -        if (!slash) {
132 -          GST_WARNING ("Can't build a valid uri");
133 -          goto next_line;
134 -        }
135 -
136 -        *slash = '\0';
137 -        data = g_strdup_printf ("%s/%s", self->uri, data);
138 -        *slash = '/';
139 -      } else {
140 -        data = g_strdup (data);
141 -      }
142 +      data = uri_join (self->uri, data);
143 +      if (data == NULL)
144 +        goto next_line;
145  
146        r = g_utf8_strchr (data, -1, '\r');
147        if (r)
148 @@ -674,3 +660,51 @@ gst_m3u8_client_get_playlist_for_bitrate (GstM3U8Client * client, guint bitrate)
149  
150    return current_variant;
151  }
152 +
153 +gchar *
154 +uri_join (const gchar * uri1, const gchar * uri2)
155 +{
156 +  gchar *uri_copy, *tmp, *ret = NULL;
157 +
158 +  if (gst_uri_is_valid (uri2))
159 +    return g_strdup (uri2);
160 +
161 +  uri_copy = g_strdup (uri1);
162 +  if (uri2[0] != '/') {
163 +    /* uri2 is a relative uri2 */
164 +    tmp = g_utf8_strrchr (uri_copy, -1, '/');
165 +    if (!tmp) {
166 +      GST_WARNING ("Can't build a valid uri_copy");
167 +      goto out;
168 +    }
169 +
170 +    *tmp = '\0';
171 +    ret = g_strdup_printf ("%s/%s", uri_copy, uri2);
172 +  } else {
173 +    /* uri2 is an absolute uri2 */
174 +    char *scheme, *hostname;
175 +
176 +    scheme = uri_copy;
177 +    /* find the : in <scheme>:// */
178 +    tmp = g_utf8_strchr (uri_copy, -1, ':');
179 +    if (!tmp) {
180 +      GST_WARNING ("Can't build a valid uri_copy");
181 +      goto out;
182 +    }
183 +
184 +    *tmp = '\0';
185 +
186 +    /* skip :// */
187 +    hostname = tmp + 3;
188 +
189 +    tmp = g_utf8_strchr (hostname, -1, '/');
190 +    if (tmp)
191 +      *tmp = '\0';
192 +
193 +    ret = g_strdup_printf ("%s://%s%s", scheme, hostname, uri2);
194 +  }
195 +
196 +out:
197 +  g_free (uri_copy);
198 +  return ret;
199 +}