X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=libavformat%2Fhlsproto.c;h=4c3048a790b683cdf657360736855d544bc8b29b;hb=75d98e30afab61542faab3c0f11880834653bd6b;hp=179bdf1967a5059d26e99218aa2609b9c1a37e2e;hpb=896bb0d742a513b1bb5b9a770dbffd2cd436bed6;p=ffmpeg diff --git a/libavformat/hlsproto.c b/libavformat/hlsproto.c index 179bdf1967a..4c3048a790b 100644 --- a/libavformat/hlsproto.c +++ b/libavformat/hlsproto.c @@ -36,7 +36,7 @@ * An apple http stream consists of a playlist with media segment files, * played sequentially. There may be several playlists with the same * video content, in different bandwidth variants, that are played in - * parallel (preferrably only one bandwidth variant at a time). In this case, + * parallel (preferably only one bandwidth variant at a time). In this case, * the user supplied the url to a main playlist that only lists the variant * playlists. * @@ -45,7 +45,7 @@ */ struct segment { - int duration; + int64_t duration; char url[MAX_URL_SIZE]; }; @@ -56,7 +56,7 @@ struct variant { typedef struct HLSContext { char playlisturl[MAX_URL_SIZE]; - int target_duration; + int64_t target_duration; int start_seq_no; int finished; int n_segments; @@ -71,7 +71,7 @@ typedef struct HLSContext { static int read_chomp_line(AVIOContext *s, char *buf, int maxlen) { int len = ff_get_line(s, buf, maxlen); - while (len > 0 && isspace(buf[len - 1])) + while (len > 0 && av_isspace(buf[len - 1])) buf[--len] = '\0'; return len; } @@ -111,7 +111,8 @@ static int parse_playlist(URLContext *h, const char *url) { HLSContext *s = h->priv_data; AVIOContext *in; - int ret = 0, duration = 0, is_segment = 0, is_variant = 0, bandwidth = 0; + int ret = 0, is_segment = 0, is_variant = 0, bandwidth = 0; + int64_t duration = 0; char line[1024]; const char *ptr; @@ -120,8 +121,10 @@ static int parse_playlist(URLContext *h, const char *url) return ret; read_chomp_line(in, line, sizeof(line)); - if (strcmp(line, "#EXTM3U")) - return AVERROR_INVALIDDATA; + if (strcmp(line, "#EXTM3U")) { + ret = AVERROR_INVALIDDATA; + goto fail; + } free_segment_list(s); s->finished = 0; @@ -134,14 +137,14 @@ static int parse_playlist(URLContext *h, const char *url) &info); bandwidth = atoi(info.bandwidth); } else if (av_strstart(line, "#EXT-X-TARGETDURATION:", &ptr)) { - s->target_duration = atoi(ptr); + s->target_duration = atoi(ptr) * AV_TIME_BASE; } else if (av_strstart(line, "#EXT-X-MEDIA-SEQUENCE:", &ptr)) { s->start_seq_no = atoi(ptr); } else if (av_strstart(line, "#EXT-X-ENDLIST", &ptr)) { s->finished = 1; } else if (av_strstart(line, "#EXTINF:", &ptr)) { is_segment = 1; - duration = atoi(ptr); + duration = atof(ptr) * AV_TIME_BASE; } else if (av_strstart(line, "#", NULL)) { continue; } else if (line[0]) { @@ -168,7 +171,7 @@ static int parse_playlist(URLContext *h, const char *url) } } } - s->last_load_time = av_gettime(); + s->last_load_time = av_gettime_relative(); fail: avio_close(in); @@ -204,19 +207,6 @@ static int hls_open(URLContext *h, const char *uri, int flags) nested_url); ret = AVERROR(EINVAL); goto fail; -#if FF_API_APPLEHTTP_PROTO - } else if (av_strstart(uri, "applehttp+", &nested_url)) { - av_strlcpy(s->playlisturl, nested_url, sizeof(s->playlisturl)); - av_log(h, AV_LOG_WARNING, - "The applehttp protocol is deprecated, use hls+%s as url " - "instead.\n", nested_url); - } else if (av_strstart(uri, "applehttp://", &nested_url)) { - av_strlcpy(s->playlisturl, "http://", sizeof(s->playlisturl)); - av_strlcat(s->playlisturl, nested_url, sizeof(s->playlisturl)); - av_log(h, AV_LOG_WARNING, - "The applehttp protocol is deprecated, use hls+http://%s as url " - "instead.\n", nested_url); -#endif } else { av_log(h, AV_LOG_ERROR, "Unsupported url %s\n", uri); ret = AVERROR(EINVAL); @@ -283,17 +273,16 @@ start: reload_interval = s->n_segments > 0 ? s->segments[s->n_segments - 1]->duration : s->target_duration; - reload_interval *= 1000000; retry: if (!s->finished) { - int64_t now = av_gettime(); + int64_t now = av_gettime_relative(); if (now - s->last_load_time >= reload_interval) { if ((ret = parse_playlist(h, s->playlisturl)) < 0) return ret; /* If we need to reload the playlist again below (if * there's still no more segments), switch to a reload * interval of half the target duration. */ - reload_interval = s->target_duration * 500000; + reload_interval = s->target_duration / 2; } } if (s->cur_seq_no < s->start_seq_no) { @@ -305,7 +294,7 @@ retry: if (s->cur_seq_no - s->start_seq_no >= s->n_segments) { if (s->finished) return AVERROR_EOF; - while (av_gettime() - s->last_load_time < reload_interval) { + while (av_gettime_relative() - s->last_load_time < reload_interval) { if (ff_check_interrupt(&h->interrupt_callback)) return AVERROR_EXIT; av_usleep(100*1000); @@ -315,7 +304,7 @@ retry: url = s->segments[s->cur_seq_no - s->start_seq_no]->url, av_log(h, AV_LOG_DEBUG, "opening %s\n", url); ret = ffurl_open(&s->seg_hd, url, AVIO_FLAG_READ, - &h->interrupt_callback, NULL); + &h->interrupt_callback, NULL, h->protocols, h); if (ret < 0) { if (ff_check_interrupt(&h->interrupt_callback)) return AVERROR_EXIT; @@ -326,18 +315,7 @@ retry: goto start; } -#if FF_API_APPLEHTTP_PROTO -URLProtocol ff_applehttp_protocol = { - .name = "applehttp", - .url_open = hls_open, - .url_read = hls_read, - .url_close = hls_close, - .flags = URL_PROTOCOL_FLAG_NESTED_SCHEME, - .priv_data_size = sizeof(HLSContext), -}; -#endif - -URLProtocol ff_hls_protocol = { +const URLProtocol ff_hls_protocol = { .name = "hls", .url_open = hls_open, .url_read = hls_read,