+gst_hls_demux_update_rendition_manifest (GstHLSDemux * demux,
+ GstHLSMedia * media, GError ** err)
+{
+ GstAdaptiveDemux *adaptive_demux = GST_ADAPTIVE_DEMUX (demux);
+ GstFragment *download;
+ GstBuffer *buf;
+ gchar *playlist;
+ const gchar *main_uri;
+ GstM3U8 *m3u8;
+ gchar *uri = media->uri;
+
+ main_uri = gst_adaptive_demux_get_manifest_ref_uri (adaptive_demux);
+ download =
+ gst_uri_downloader_fetch_uri (adaptive_demux->downloader, uri, main_uri,
+ TRUE, TRUE, TRUE, err);
+
+ if (download == NULL)
+ return FALSE;
+
+ m3u8 = media->playlist;
+
+ /* Set the base URI of the playlist to the redirect target if any */
+ if (download->redirect_permanent && download->redirect_uri) {
+ gst_m3u8_set_uri (m3u8, download->redirect_uri, NULL, media->name);
+ } else {
+ gst_m3u8_set_uri (m3u8, download->uri, download->redirect_uri, media->name);
+ }
+
+ buf = gst_fragment_get_buffer (download);
+ playlist = gst_hls_src_buf_to_utf8_playlist (buf);
+ gst_buffer_unref (buf);
+ g_object_unref (download);
+
+ if (playlist == NULL) {
+ GST_WARNING_OBJECT (demux, "Couldn't validate playlist encoding");
+ g_set_error (err, GST_STREAM_ERROR, GST_STREAM_ERROR_WRONG_TYPE,
+ "Couldn't validate playlist encoding");
+ return FALSE;
+ }
+
+ if (!gst_m3u8_update (m3u8, playlist)) {
+ GST_WARNING_OBJECT (demux, "Couldn't update playlist");
+ g_set_error (err, GST_STREAM_ERROR, GST_STREAM_ERROR_FAILED,
+ "Couldn't update playlist");
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
+static gboolean