]> git.sesse.net Git - ffmpeg/blobdiff - libavformat/hls.c
avformat/hls: enable http_multiple only for http/1.1 servers
[ffmpeg] / libavformat / hls.c
index c0bade0e844762cb14b2c7a57fa03276393673ab..dccc7c7dd2c3fb57f5ee45d33758ddeb9eb7b2c5 100644 (file)
@@ -725,8 +725,9 @@ static int parse_playlist(HLSContext *c, const char *url,
     struct variant_info variant_info;
     char tmp_str[MAX_URL_SIZE];
     struct segment *cur_init_section = NULL;
+    int is_http = av_strstart(url, "http", NULL);
 
-    if (!in && c->http_persistent && c->playlist_pb) {
+    if (is_http && !in && c->http_persistent && c->playlist_pb) {
         in = c->playlist_pb;
         ret = open_url_keepalive(c->ctx, &c->playlist_pb, url);
         if (ret == AVERROR_EXIT) {
@@ -760,7 +761,7 @@ static int parse_playlist(HLSContext *c, const char *url,
         if (ret < 0)
             return ret;
 
-        if (c->http_persistent)
+        if (is_http && c->http_persistent)
             c->playlist_pb = in;
         else
             close_in = 1;
@@ -1451,7 +1452,7 @@ reload:
         if (ret)
             return ret;
 
-        if (c->http_multiple && av_strstart(seg->url, "http", NULL) && v->input_next_requested) {
+        if (c->http_multiple == 1 && v->input_next_requested) {
             FFSWAP(AVIOContext *, v->input, v->input_next);
             v->input_next_requested = 0;
             ret = 0;
@@ -1470,8 +1471,15 @@ reload:
         just_opened = 1;
     }
 
+    if (c->http_multiple == -1) {
+        uint8_t *http_version_opt = NULL;
+        av_opt_get(v->input, "http_version", AV_OPT_SEARCH_CHILDREN, &http_version_opt);
+        c->http_multiple = http_version_opt && strncmp((const char *)http_version_opt, "1.1", 3) == 0;
+    }
+
     seg = next_segment(v);
-    if (c->http_multiple && !v->input_next_requested && seg) {
+    if (c->http_multiple == 1 && !v->input_next_requested &&
+        seg && av_strstart(seg->url, "http", NULL)) {
         ret = open_input(c, v, seg, &v->input_next);
         if (ret < 0) {
             if (ff_check_interrupt(c->interrupt_callback))
@@ -2305,7 +2313,7 @@ static const AVOption hls_options[] = {
     {"http_persistent", "Use persistent HTTP connections",
         OFFSET(http_persistent), AV_OPT_TYPE_BOOL, {.i64 = 1}, 0, 1, FLAGS },
     {"http_multiple", "Use multiple HTTP connections for fetching segments",
-        OFFSET(http_multiple), AV_OPT_TYPE_BOOL, {.i64 = 1}, 0, 1, FLAGS},
+        OFFSET(http_multiple), AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 1, FLAGS},
     {NULL}
 };