return VLC_EGENERIC;
}
- for (int i = 8; i ; --i) {
+ for (int i = 7; i >= 0 ; --i) {
iv[ i] = iv_hi & 0xff;
iv[8+i] = iv_lo & 0xff;
iv_hi >>= 8;
assert(*hls == NULL);
attr = parse_Attributes(p_read, "PROGRAM-ID");
- if (attr == NULL)
+ if (attr)
{
- msg_Err(s, "#EXT-X-STREAM-INF: expected PROGRAM-ID=<value>");
- return VLC_EGENERIC;
+ id = atol(attr);
+ free(attr);
}
- id = atol(attr);
- free(attr);
+ else
+ id = 0;
attr = parse_Attributes(p_read, "BANDWIDTH");
if (attr == NULL)
if (end != NULL)
*end = 0;
}
- hls->psz_current_key_path = strdup(uri);
+ /* For absolute URI, just duplicate it
+ * don't limit to HTTP, maybe some sanity checking
+ * should be done more in here? */
+ if( strstr( uri , "://" ) )
+ hls->psz_current_key_path = strdup( uri );
+ else
+ hls->psz_current_key_path = relative_URI(hls->url, uri);
free(value);
value = iv = parse_Attributes(p_read, "IV");
/* M3U8 Meta Index file */
do {
+ bool failed_to_download_stream_m3u8 = false;
+
/* Next line */
line = ReadLine(p_begin, &p_read, p_end - p_begin);
if (line == NULL)
}
else
{
+ bool new_stream_added = false;
hls_stream_t *hls = NULL;
err = parse_StreamInformation(s, &streams, &hls, line, uri);
+ if (err == VLC_SUCCESS)
+ new_stream_added = true;
+
free(uri);
/* Download playlist file from server */
uint8_t *buf = NULL;
ssize_t len = read_M3U8_from_url(s, hls->url, &buf);
if (len < 0)
- err = VLC_EGENERIC;
+ {
+ msg_Warn(s, "failed to read %s, continue for other streams", hls->url);
+ failed_to_download_stream_m3u8 = true;
+
+ /* remove stream just added */
+ if (new_stream_added)
+ vlc_array_remove(streams, vlc_array_count(streams) - 1);
+
+ /* ignore download error, so we have chance to try other streams */
+ err = VLC_SUCCESS;
+ }
else
{
/* Parse HLS m3u8 content. */
} while (err == VLC_SUCCESS);
+ size_t stream_count = vlc_array_count(streams);
+ msg_Dbg(s, "%d streams loaded in Meta playlist", (int)stream_count);
+ if (stream_count == 0)
+ {
+ msg_Err(s, "No playable streams found in Meta playlist");
+ err = VLC_EGENERIC;
+ }
}
else
{
assert(hls);
/* */
+ bool media_sequence_loaded = false;
int segment_duration = -1;
do
{
else if (strncmp(line, "#EXT-X-TARGETDURATION", 21) == 0)
err = parse_TargetDuration(s, hls, line);
else if (strncmp(line, "#EXT-X-MEDIA-SEQUENCE", 21) == 0)
- err = parse_MediaSequence(s, hls, line);
+ {
+ /* A Playlist file MUST NOT contain more than one EXT-X-MEDIA-SEQUENCE tag. */
+ /* We only care about first one */
+ if (!media_sequence_loaded)
+ {
+ err = parse_MediaSequence(s, hls, line);
+ media_sequence_loaded = true;
+ }
+ }
else if (strncmp(line, "#EXT-X-KEY", 10) == 0)
err = parse_Key(s, hls, line);
else if (strncmp(line, "#EXT-X-PROGRAM-DATE-TIME", 24) == 0)
return err;
}
-/* Update hls_old (an existing member of p_sys->hls_stream) to match hls_new
+/* Update hls_old (an existing member of p_sys->hls_stream) to match hls_new
(which represents a downloaded, perhaps newer version of the same playlist) */
static int hls_UpdatePlaylist(stream_t *s, hls_stream_t *hls_new, hls_stream_t *hls_old)
{
/* next pass start after \r and \n */
p++;
*pos = p;
- }
+ }
}
return line;
/* Wait for download to be finished */
msg_Info(s, "seek to segment %d", p_sys->playback.segment);
while ((p_sys->download.seek != -1) ||
- ((p_sys->download.segment - p_sys->playback.segment < 3) &&
+ ((p_sys->download.segment - p_sys->playback.segment < 3) &&
(p_sys->download.segment < count)))
{
vlc_cond_wait(&p_sys->download.wait, &p_sys->download.lock_wait);