static int parse_playlist(HLSContext *c, const char *url,

                          struct playlist *pls, AVIOContext *in)

{

    int ret = 0, is_segment = 0, is_variant = 0;

    int64_t duration = 0;

    enum KeyType key_type = KEY_NONE;

    uint8_t iv[16] = "";

    int has_iv = 0;

    char key[MAX_URL_SIZE] = "";

    char line[MAX_URL_SIZE];

    const char *ptr;

    int close_in = 0;

    int64_t seg_offset = 0;

    int64_t seg_size = -1;

    uint8_t *new_url = NULL;

    struct variant_info variant_info;

    char tmp_str[MAX_URL_SIZE];

    struct segment *cur_init_section = NULL;



    if (!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) {

            return ret;

        } else if (ret < 0) {

            av_log(c->ctx, AV_LOG_WARNING,

                "keepalive request failed for '%s', retrying with new connection: %s\n",

                url, av_err2str(ret));

            in = NULL;

        }

    }



    if (!in) {

#if 1

        AVDictionary *opts = NULL;

        /* Some HLS servers don't like being sent the range header */

        av_dict_set(&opts, "seekable", "0", 0);



        // broker prior HTTP options that should be consistent across requests

        av_dict_set(&opts, "user_agent", c->user_agent, 0);

        av_dict_set(&opts, "cookies", c->cookies, 0);

        av_dict_set(&opts, "headers", c->headers, 0);

        av_dict_set(&opts, "http_proxy", c->http_proxy, 0);



        if (c->http_persistent)

            av_dict_set(&opts, "multiple_requests", "1", 0);



        ret = c->ctx->io_open(c->ctx, &in, url, AVIO_FLAG_READ, &opts);

        av_dict_free(&opts);

        if (ret < 0)

            return ret;



        if (c->http_persistent)

            c->playlist_pb = in;

        else

            close_in = 1;

#else

        ret = open_in(c, &in, url);

        if (ret < 0)

            return ret;

        close_in = 1;

#endif

    }



    if (av_opt_get(in, "location", AV_OPT_SEARCH_CHILDREN, &new_url) >= 0)

        url = new_url;



    read_chomp_line(in, line, sizeof(line));

    if (strcmp(line, "#EXTM3U")) {

        ret = AVERROR_INVALIDDATA;

        goto fail;

    }



    if (pls) {

        free_segment_list(pls);

        pls->finished = 0;

        pls->type = PLS_TYPE_UNSPECIFIED;

    }

    while (!avio_feof(in)) {

        read_chomp_line(in, line, sizeof(line));

        if (av_strstart(line, "#EXT-X-STREAM-INF:", &ptr)) {

            is_variant = 1;

            memset(&variant_info, 0, sizeof(variant_info));

            ff_parse_key_value(ptr, (ff_parse_key_val_cb) handle_variant_args,

                               &variant_info);

        } else if (av_strstart(line, "#EXT-X-KEY:", &ptr)) {

            struct key_info info = {{0}};

            ff_parse_key_value(ptr, (ff_parse_key_val_cb) handle_key_args,

                               &info);

            key_type = KEY_NONE;

            has_iv = 0;

            if (!strcmp(info.method, "AES-128"))

                key_type = KEY_AES_128;

            if (!strcmp(info.method, "SAMPLE-AES"))

                key_type = KEY_SAMPLE_AES;

            if (!strncmp(info.iv, "0x", 2) || !strncmp(info.iv, "0X", 2)) {

                ff_hex_to_data(iv, info.iv + 2);

                has_iv = 1;

            }

            av_strlcpy(key, info.uri, sizeof(key));

        } else if (av_strstart(line, "#EXT-X-MEDIA:", &ptr)) {

            struct rendition_info info = {{0}};

            ff_parse_key_value(ptr, (ff_parse_key_val_cb) handle_rendition_args,

                               &info);

            new_rendition(c, &info, url);

        } else if (av_strstart(line, "#EXT-X-TARGETDURATION:", &ptr)) {

            ret = ensure_playlist(c, &pls, url);

            if (ret < 0)

                goto fail;

            pls->target_duration = strtoll(ptr, NULL, 10) * AV_TIME_BASE;

        } else if (av_strstart(line, "#EXT-X-MEDIA-SEQUENCE:", &ptr)) {

            ret = ensure_playlist(c, &pls, url);

            if (ret < 0)

                goto fail;

            pls->start_seq_no = atoi(ptr);

        } else if (av_strstart(line, "#EXT-X-PLAYLIST-TYPE:", &ptr)) {

            ret = ensure_playlist(c, &pls, url);

            if (ret < 0)

                goto fail;

            if (!strcmp(ptr, "EVENT"))

                pls->type = PLS_TYPE_EVENT;

            else if (!strcmp(ptr, "VOD"))

                pls->type = PLS_TYPE_VOD;

        } else if (av_strstart(line, "#EXT-X-MAP:", &ptr)) {

            struct init_section_info info = {{0}};

            ret = ensure_playlist(c, &pls, url);

            if (ret < 0)

                goto fail;

            ff_parse_key_value(ptr, (ff_parse_key_val_cb) handle_init_section_args,

                               &info);

            cur_init_section = new_init_section(pls, &info, url);

        } else if (av_strstart(line, "#EXT-X-ENDLIST", &ptr)) {

            if (pls)

                pls->finished = 1;

        } else if (av_strstart(line, "#EXTINF:", &ptr)) {

            is_segment = 1;

            duration   = atof(ptr) * AV_TIME_BASE;

        } else if (av_strstart(line, "#EXT-X-BYTERANGE:", &ptr)) {

            seg_size = strtoll(ptr, NULL, 10);

            ptr = strchr(ptr, '@');

            if (ptr)

                seg_offset = strtoll(ptr+1, NULL, 10);

        } else if (av_strstart(line, "#", NULL)) {

            continue;

        } else if (line[0]) {

            if (is_variant) {

                if (!new_variant(c, &variant_info, line, url)) {

                    ret = AVERROR(ENOMEM);

                    goto fail;

                }

                is_variant = 0;

            }

            if (is_segment) {

                struct segment *seg;

                if (!pls) {

                    if (!new_variant(c, 0, url, NULL)) {

                        ret = AVERROR(ENOMEM);

                        goto fail;

                    }

                    pls = c->playlists[c->n_playlists - 1];

                }

                seg = av_malloc(sizeof(struct segment));

                if (!seg) {

                    ret = AVERROR(ENOMEM);

                    goto fail;

                }

                seg->duration = duration;

                seg->key_type = key_type;

                if (has_iv) {

                    memcpy(seg->iv, iv, sizeof(iv));

                } else {

                    int seq = pls->start_seq_no + pls->n_segments;

                    memset(seg->iv, 0, sizeof(seg->iv));

                    AV_WB32(seg->iv + 12, seq);

                }



                if (key_type != KEY_NONE) {

                    ff_make_absolute_url(tmp_str, sizeof(tmp_str), url, key);

                    seg->key = av_strdup(tmp_str);

                    if (!seg->key) {

                        av_free(seg);

                        ret = AVERROR(ENOMEM);

                        goto fail;

                    }

                } else {

                    seg->key = NULL;

                }



                ff_make_absolute_url(tmp_str, sizeof(tmp_str), url, line);

                seg->url = av_strdup(tmp_str);

                if (!seg->url) {

                    av_free(seg->key);

                    av_free(seg);

                    ret = AVERROR(ENOMEM);

                    goto fail;

                }



                dynarray_add(&pls->segments, &pls->n_segments, seg);

                is_segment = 0;



                seg->size = seg_size;

                if (seg_size >= 0) {

                    seg->url_offset = seg_offset;

                    seg_offset += seg_size;

                    seg_size = -1;

                } else {

                    seg->url_offset = 0;

                    seg_offset = 0;

                }



                seg->init_section = cur_init_section;

            }

        }

    }

    if (pls)

        pls->last_load_time = av_gettime_relative();



fail:

    av_free(new_url);

    if (close_in)

        ff_format_io_close(c->ctx, &in);

    return ret;

}

static int parse_playlist(HLSContext *c, const char *url,

                          struct playlist *pls, AVIOContext *in)

{

    int ret = 0, is_segment = 0, is_variant = 0;

    int64_t duration = 0;

    enum KeyType key_type = KEY_NONE;

    uint8_t iv[16] = "";

    int has_iv = 0;

    char key[MAX_URL_SIZE] = "";

    char line[MAX_URL_SIZE];

    const char *ptr;

    int close_in = 0;

    int64_t seg_offset = 0;

    int64_t seg_size = -1;

    uint8_t *new_url = NULL;

    struct variant_info variant_info;

    char tmp_str[MAX_URL_SIZE];

    struct segment *cur_init_section = NULL;



    if (!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) {

            return ret;

        } else if (ret < 0) {

            av_log(c->ctx, AV_LOG_WARNING,

                "keepalive request failed for '%s', retrying with new connection: %s\n",

                url, av_err2str(ret));

            in = NULL;

        }

    }



    if (!in) {

#if 1

        AVDictionary *opts = NULL;

        

        av_dict_set(&opts, "seekable", "0", 0);



        

        av_dict_set(&opts, "user_agent", c->user_agent, 0);

        av_dict_set(&opts, "cookies", c->cookies, 0);

        av_dict_set(&opts, "headers", c->headers, 0);

        av_dict_set(&opts, "http_proxy", c->http_proxy, 0);



        if (c->http_persistent)

            av_dict_set(&opts, "multiple_requests", "1", 0);



        ret = c->ctx->io_open(c->ctx, &in, url, AVIO_FLAG_READ, &opts);

        av_dict_free(&opts);

        if (ret < 0)

            return ret;



        if (c->http_persistent)

            c->playlist_pb = in;

        else

            close_in = 1;

#else

        ret = open_in(c, &in, url);

        if (ret < 0)

            return ret;

        close_in = 1;

#endif

    }



    if (av_opt_get(in, "location", AV_OPT_SEARCH_CHILDREN, &new_url) >= 0)

        url = new_url;



    read_chomp_line(in, line, sizeof(line));

    if (strcmp(line, "#EXTM3U")) {

        ret = AVERROR_INVALIDDATA;

        goto fail;

    }



    if (pls) {

        free_segment_list(pls);

        pls->finished = 0;

        pls->type = PLS_TYPE_UNSPECIFIED;

    }

    while (!avio_feof(in)) {

        read_chomp_line(in, line, sizeof(line));

        if (av_strstart(line, "#EXT-X-STREAM-INF:", &ptr)) {

            is_variant = 1;

            memset(&variant_info, 0, sizeof(variant_info));

            ff_parse_key_value(ptr, (ff_parse_key_val_cb) handle_variant_args,

                               &variant_info);

        } else if (av_strstart(line, "#EXT-X-KEY:", &ptr)) {

            struct key_info info = {{0}};

            ff_parse_key_value(ptr, (ff_parse_key_val_cb) handle_key_args,

                               &info);

            key_type = KEY_NONE;

            has_iv = 0;

            if (!strcmp(info.method, "AES-128"))

                key_type = KEY_AES_128;

            if (!strcmp(info.method, "SAMPLE-AES"))

                key_type = KEY_SAMPLE_AES;

            if (!strncmp(info.iv, "0x", 2) || !strncmp(info.iv, "0X", 2)) {

                ff_hex_to_data(iv, info.iv + 2);

                has_iv = 1;

            }

            av_strlcpy(key, info.uri, sizeof(key));

        } else if (av_strstart(line, "#EXT-X-MEDIA:", &ptr)) {

            struct rendition_info info = {{0}};

            ff_parse_key_value(ptr, (ff_parse_key_val_cb) handle_rendition_args,

                               &info);

            new_rendition(c, &info, url);

        } else if (av_strstart(line, "#EXT-X-TARGETDURATION:", &ptr)) {

            ret = ensure_playlist(c, &pls, url);

            if (ret < 0)

                goto fail;

            pls->target_duration = strtoll(ptr, NULL, 10) * AV_TIME_BASE;

        } else if (av_strstart(line, "#EXT-X-MEDIA-SEQUENCE:", &ptr)) {

            ret = ensure_playlist(c, &pls, url);

            if (ret < 0)

                goto fail;

            pls->start_seq_no = atoi(ptr);

        } else if (av_strstart(line, "#EXT-X-PLAYLIST-TYPE:", &ptr)) {

            ret = ensure_playlist(c, &pls, url);

            if (ret < 0)

                goto fail;

            if (!strcmp(ptr, "EVENT"))

                pls->type = PLS_TYPE_EVENT;

            else if (!strcmp(ptr, "VOD"))

                pls->type = PLS_TYPE_VOD;

        } else if (av_strstart(line, "#EXT-X-MAP:", &ptr)) {

            struct init_section_info info = {{0}};

            ret = ensure_playlist(c, &pls, url);

            if (ret < 0)

                goto fail;

            ff_parse_key_value(ptr, (ff_parse_key_val_cb) handle_init_section_args,

                               &info);

            cur_init_section = new_init_section(pls, &info, url);

        } else if (av_strstart(line, "#EXT-X-ENDLIST", &ptr)) {

            if (pls)

                pls->finished = 1;

        } else if (av_strstart(line, "#EXTINF:", &ptr)) {

            is_segment = 1;

            duration   = atof(ptr) * AV_TIME_BASE;

        } else if (av_strstart(line, "#EXT-X-BYTERANGE:", &ptr)) {

            seg_size = strtoll(ptr, NULL, 10);

            ptr = strchr(ptr, '@');

            if (ptr)

                seg_offset = strtoll(ptr+1, NULL, 10);

        } else if (av_strstart(line, "#", NULL)) {

            continue;

        } else if (line[0]) {

            if (is_variant) {

                if (!new_variant(c, &variant_info, line, url)) {

                    ret = AVERROR(ENOMEM);

                    goto fail;

                }

                is_variant = 0;

            }

            if (is_segment) {

                struct segment *seg;

                if (!pls) {

                    if (!new_variant(c, 0, url, NULL)) {

                        ret = AVERROR(ENOMEM);

                        goto fail;

                    }

                    pls = c->playlists[c->n_playlists - 1];

                }

                seg = av_malloc(sizeof(struct segment));

                if (!seg) {

                    ret = AVERROR(ENOMEM);

                    goto fail;

                }

                seg->duration = duration;

                seg->key_type = key_type;

                if (has_iv) {

                    memcpy(seg->iv, iv, sizeof(iv));

                } else {

                    int seq = pls->start_seq_no + pls->n_segments;

                    memset(seg->iv, 0, sizeof(seg->iv));

                    AV_WB32(seg->iv + 12, seq);

                }



                if (key_type != KEY_NONE) {

                    ff_make_absolute_url(tmp_str, sizeof(tmp_str), url, key);

                    seg->key = av_strdup(tmp_str);

                    if (!seg->key) {

                        av_free(seg);

                        ret = AVERROR(ENOMEM);

                        goto fail;

                    }

                } else {

                    seg->key = NULL;

                }



                ff_make_absolute_url(tmp_str, sizeof(tmp_str), url, line);

                seg->url = av_strdup(tmp_str);

                if (!seg->url) {

                    av_free(seg->key);

                    av_free(seg);

                    ret = AVERROR(ENOMEM);

                    goto fail;

                }



                dynarray_add(&pls->segments, &pls->n_segments, seg);

                is_segment = 0;



                seg->size = seg_size;

                if (seg_size >= 0) {

                    seg->url_offset = seg_offset;

                    seg_offset += seg_size;

                    seg_size = -1;

                } else {

                    seg->url_offset = 0;

                    seg_offset = 0;

                }



                seg->init_section = cur_init_section;

            }

        }

    }

    if (pls)

        pls->last_load_time = av_gettime_relative();



fail:

    av_free(new_url);

    if (close_in)

        ff_format_io_close(c->ctx, &in);

    return ret;

}

static int FUNC_0(HLSContext *VAR_0, const char *VAR_1,

                          struct playlist *VAR_2, AVIOContext *VAR_3)

{

    int VAR_4 = 0, VAR_5 = 0, VAR_6 = 0;

    int64_t duration = 0;

    enum KeyType VAR_7 = KEY_NONE;

    uint8_t iv[16] = "";

    int VAR_8 = 0;

    char VAR_9[MAX_URL_SIZE] = "";

    char VAR_10[MAX_URL_SIZE];

    const char *VAR_11;

    int VAR_12 = 0;

    int64_t seg_offset = 0;

    int64_t seg_size = -1;

    uint8_t *new_url = NULL;

    struct VAR_13 VAR_13;

    char VAR_14[MAX_URL_SIZE];

    struct segment *VAR_15 = NULL;



    if (!VAR_3 && VAR_0->http_persistent && VAR_0->playlist_pb) {

        VAR_3 = VAR_0->playlist_pb;

        VAR_4 = open_url_keepalive(VAR_0->ctx, &VAR_0->playlist_pb, VAR_1);

        if (VAR_4 == AVERROR_EXIT) {

            return VAR_4;

        } else if (VAR_4 < 0) {

            av_log(VAR_0->ctx, AV_LOG_WARNING,

                "keepalive request failed for '%s', retrying with new connection: %s\n",

                VAR_1, av_err2str(VAR_4));

            VAR_3 = NULL;

        }

    }



    if (!VAR_3) {

#if 1

        AVDictionary *opts = NULL;

        

        av_dict_set(&opts, "seekable", "0", 0);



        

        av_dict_set(&opts, "user_agent", VAR_0->user_agent, 0);

        av_dict_set(&opts, "cookies", VAR_0->cookies, 0);

        av_dict_set(&opts, "headers", VAR_0->headers, 0);

        av_dict_set(&opts, "http_proxy", VAR_0->http_proxy, 0);



        if (VAR_0->http_persistent)

            av_dict_set(&opts, "multiple_requests", "1", 0);



        VAR_4 = VAR_0->ctx->io_open(VAR_0->ctx, &VAR_3, VAR_1, AVIO_FLAG_READ, &opts);

        av_dict_free(&opts);

        if (VAR_4 < 0)

            return VAR_4;



        if (VAR_0->http_persistent)

            VAR_0->playlist_pb = VAR_3;

        else

            VAR_12 = 1;

#else

        VAR_4 = open_in(VAR_0, &VAR_3, VAR_1);

        if (VAR_4 < 0)

            return VAR_4;

        VAR_12 = 1;

#endif

    }



    if (av_opt_get(VAR_3, "location", AV_OPT_SEARCH_CHILDREN, &new_url) >= 0)

        VAR_1 = new_url;



    read_chomp_line(VAR_3, VAR_10, sizeof(VAR_10));

    if (strcmp(VAR_10, "#EXTM3U")) {

        VAR_4 = AVERROR_INVALIDDATA;

        goto fail;

    }



    if (VAR_2) {

        free_segment_list(VAR_2);

        VAR_2->finished = 0;

        VAR_2->type = PLS_TYPE_UNSPECIFIED;

    }

    while (!avio_feof(VAR_3)) {

        read_chomp_line(VAR_3, VAR_10, sizeof(VAR_10));

        if (av_strstart(VAR_10, "#EXT-X-STREAM-INF:", &VAR_11)) {

            VAR_6 = 1;

            memset(&VAR_13, 0, sizeof(VAR_13));

            ff_parse_key_value(VAR_11, (ff_parse_key_val_cb) handle_variant_args,

                               &VAR_13);

        } else if (av_strstart(VAR_10, "#EXT-X-KEY:", &VAR_11)) {

            struct key_info VAR_17 = {{0}};

            ff_parse_key_value(VAR_11, (ff_parse_key_val_cb) handle_key_args,

                               &VAR_17);

            VAR_7 = KEY_NONE;

            VAR_8 = 0;

            if (!strcmp(VAR_17.method, "AES-128"))

                VAR_7 = KEY_AES_128;

            if (!strcmp(VAR_17.method, "SAMPLE-AES"))

                VAR_7 = KEY_SAMPLE_AES;

            if (!strncmp(VAR_17.iv, "0x", 2) || !strncmp(VAR_17.iv, "0X", 2)) {

                ff_hex_to_data(iv, VAR_17.iv + 2);

                VAR_8 = 1;

            }

            av_strlcpy(VAR_9, VAR_17.uri, sizeof(VAR_9));

        } else if (av_strstart(VAR_10, "#EXT-X-MEDIA:", &VAR_11)) {

            struct rendition_info VAR_17 = {{0}};

            ff_parse_key_value(VAR_11, (ff_parse_key_val_cb) handle_rendition_args,

                               &VAR_17);

            new_rendition(VAR_0, &VAR_17, VAR_1);

        } else if (av_strstart(VAR_10, "#EXT-X-TARGETDURATION:", &VAR_11)) {

            VAR_4 = ensure_playlist(VAR_0, &VAR_2, VAR_1);

            if (VAR_4 < 0)

                goto fail;

            VAR_2->target_duration = strtoll(VAR_11, NULL, 10) * AV_TIME_BASE;

        } else if (av_strstart(VAR_10, "#EXT-X-MEDIA-SEQUENCE:", &VAR_11)) {

            VAR_4 = ensure_playlist(VAR_0, &VAR_2, VAR_1);

            if (VAR_4 < 0)

                goto fail;

            VAR_2->start_seq_no = atoi(VAR_11);

        } else if (av_strstart(VAR_10, "#EXT-X-PLAYLIST-TYPE:", &VAR_11)) {

            VAR_4 = ensure_playlist(VAR_0, &VAR_2, VAR_1);

            if (VAR_4 < 0)

                goto fail;

            if (!strcmp(VAR_11, "EVENT"))

                VAR_2->type = PLS_TYPE_EVENT;

            else if (!strcmp(VAR_11, "VOD"))

                VAR_2->type = PLS_TYPE_VOD;

        } else if (av_strstart(VAR_10, "#EXT-X-MAP:", &VAR_11)) {

            struct init_section_info VAR_17 = {{0}};

            VAR_4 = ensure_playlist(VAR_0, &VAR_2, VAR_1);

            if (VAR_4 < 0)

                goto fail;

            ff_parse_key_value(VAR_11, (ff_parse_key_val_cb) handle_init_section_args,

                               &VAR_17);

            VAR_15 = new_init_section(VAR_2, &VAR_17, VAR_1);

        } else if (av_strstart(VAR_10, "#EXT-X-ENDLIST", &VAR_11)) {

            if (VAR_2)

                VAR_2->finished = 1;

        } else if (av_strstart(VAR_10, "#EXTINF:", &VAR_11)) {

            VAR_5 = 1;

            duration   = atof(VAR_11) * AV_TIME_BASE;

        } else if (av_strstart(VAR_10, "#EXT-X-BYTERANGE:", &VAR_11)) {

            seg_size = strtoll(VAR_11, NULL, 10);

            VAR_11 = strchr(VAR_11, '@');

            if (VAR_11)

                seg_offset = strtoll(VAR_11+1, NULL, 10);

        } else if (av_strstart(VAR_10, "#", NULL)) {

            continue;

        } else if (VAR_10[0]) {

            if (VAR_6) {

                if (!new_variant(VAR_0, &VAR_13, VAR_10, VAR_1)) {

                    VAR_4 = AVERROR(ENOMEM);

                    goto fail;

                }

                VAR_6 = 0;

            }

            if (VAR_5) {

                struct segment *VAR_17;

                if (!VAR_2) {

                    if (!new_variant(VAR_0, 0, VAR_1, NULL)) {

                        VAR_4 = AVERROR(ENOMEM);

                        goto fail;

                    }

                    VAR_2 = VAR_0->playlists[VAR_0->n_playlists - 1];

                }

                VAR_17 = av_malloc(sizeof(struct segment));

                if (!VAR_17) {

                    VAR_4 = AVERROR(ENOMEM);

                    goto fail;

                }

                VAR_17->duration = duration;

                VAR_17->VAR_7 = VAR_7;

                if (VAR_8) {

                    memcpy(VAR_17->iv, iv, sizeof(iv));

                } else {

                    int VAR_18 = VAR_2->start_seq_no + VAR_2->n_segments;

                    memset(VAR_17->iv, 0, sizeof(VAR_17->iv));

                    AV_WB32(VAR_17->iv + 12, VAR_18);

                }



                if (VAR_7 != KEY_NONE) {

                    ff_make_absolute_url(VAR_14, sizeof(VAR_14), VAR_1, VAR_9);

                    VAR_17->VAR_9 = av_strdup(VAR_14);

                    if (!VAR_17->VAR_9) {

                        av_free(VAR_17);

                        VAR_4 = AVERROR(ENOMEM);

                        goto fail;

                    }

                } else {

                    VAR_17->VAR_9 = NULL;

                }



                ff_make_absolute_url(VAR_14, sizeof(VAR_14), VAR_1, VAR_10);

                VAR_17->VAR_1 = av_strdup(VAR_14);

                if (!VAR_17->VAR_1) {

                    av_free(VAR_17->VAR_9);

                    av_free(VAR_17);

                    VAR_4 = AVERROR(ENOMEM);

                    goto fail;

                }



                dynarray_add(&VAR_2->segments, &VAR_2->n_segments, VAR_17);

                VAR_5 = 0;



                VAR_17->size = seg_size;

                if (seg_size >= 0) {

                    VAR_17->url_offset = seg_offset;

                    seg_offset += seg_size;

                    seg_size = -1;

                } else {

                    VAR_17->url_offset = 0;

                    seg_offset = 0;

                }



                VAR_17->init_section = VAR_15;

            }

        }

    }

    if (VAR_2)

        VAR_2->last_load_time = av_gettime_relative();



fail:

    av_free(new_url);

    if (VAR_12)

        ff_format_io_close(VAR_0->ctx, &VAR_3);

    return VAR_4;

}

static int FUNC_0(HLSContext *VAR_0, const char *VAR_1,
struct playlist *VAR_2, AVIOContext *VAR_3)
{ int VAR_4 = 0, VAR_5 = 0, VAR_6 = 0; int64_t duration = 0; enum KeyType VAR_7 = KEY_NONE; uint8_t iv[16] = ""; int VAR_8 = 0; char VAR_9[MAX_URL_SIZE] = ""; char VAR_10[MAX_URL_SIZE]; const char *VAR_11; int VAR_12 = 0; int64_t seg_offset = 0; int64_t seg_size = -1; uint8_t *new_url = NULL; struct VAR_13 VAR_13; char VAR_14[MAX_URL_SIZE]; struct segment *VAR_15 = NULL; if (!VAR_3 && VAR_0->http_persistent && VAR_0->playlist_pb) { VAR_3 = VAR_0->playlist_pb; VAR_4 = open_url_keepalive(VAR_0->ctx, &VAR_0->playlist_pb, VAR_1); if (VAR_4 == AVERROR_EXIT) { return VAR_4; } else if (VAR_4 < 0) { av_log(VAR_0->ctx, AV_LOG_WARNING,
"keepalive request failed for '%s', retrying with new connection: %s\n",
VAR_1, av_err2str(VAR_4)); VAR_3 = NULL; } } if (!VAR_3) { #if 1
AVDictionary *opts = NULL; av_dict_set(&opts, "seekable", "0", 0); av_dict_set(&opts, "user_agent", VAR_0->user_agent, 0); av_dict_set(&opts, "cookies", VAR_0->cookies, 0); av_dict_set(&opts, "headers", VAR_0->headers, 0); av_dict_set(&opts, "http_proxy", VAR_0->http_proxy, 0); if (VAR_0->http_persistent)
av_dict_set(&opts, "multiple_requests", "1", 0); VAR_4 = VAR_0->ctx->io_open(VAR_0->ctx, &VAR_3, VAR_1, AVIO_FLAG_READ, &opts); av_dict_free(&opts); if (VAR_4 < 0)
return VAR_4; if (VAR_0->http_persistent)
VAR_0->playlist_pb = VAR_3; else
VAR_12 = 1; #else
VAR_4 = open_in(VAR_0, &VAR_3, VAR_1); if (VAR_4 < 0)
return VAR_4; VAR_12 = 1; #endif
} if (av_opt_get(VAR_3, "location", AV_OPT_SEARCH_CHILDREN, &new_url) >= 0)
VAR_1 = new_url; read_chomp_line(VAR_3, VAR_10, sizeof(VAR_10)); if (strcmp(VAR_10, "#EXTM3U")) { VAR_4 = AVERROR_INVALIDDATA; goto fail; } if (VAR_2) { free_segment_list(VAR_2); VAR_2->finished = 0; VAR_2->type = PLS_TYPE_UNSPECIFIED; } while (!avio_feof(VAR_3)) { read_chomp_line(VAR_3, VAR_10, sizeof(VAR_10)); if (av_strstart(VAR_10, "#EXT-X-STREAM-INF:", &VAR_11)) { VAR_6 = 1; memset(&VAR_13, 0, sizeof(VAR_13)); ff_parse_key_value(VAR_11, (ff_parse_key_val_cb) handle_variant_args,
&VAR_13); } else if (av_strstart(VAR_10, "#EXT-X-KEY:", &VAR_11)) { struct key_info VAR_17 = {{0}}; ff_parse_key_value(VAR_11, (ff_parse_key_val_cb) handle_key_args,
&VAR_17); VAR_7 = KEY_NONE; VAR_8 = 0; if (!strcmp(VAR_17.method, "AES-128"))
VAR_7 = KEY_AES_128; if (!strcmp(VAR_17.method, "SAMPLE-AES"))
VAR_7 = KEY_SAMPLE_AES; if (!strncmp(VAR_17.iv, "0x", 2) || !strncmp(VAR_17.iv, "0X", 2)) { ff_hex_to_data(iv, VAR_17.iv + 2); VAR_8 = 1; } av_strlcpy(VAR_9, VAR_17.uri, sizeof(VAR_9)); } else if (av_strstart(VAR_10, "#EXT-X-MEDIA:", &VAR_11)) { struct rendition_info VAR_17 = {{0}}; ff_parse_key_value(VAR_11, (ff_parse_key_val_cb) handle_rendition_args,
&VAR_17); new_rendition(VAR_0, &VAR_17, VAR_1); } else if (av_strstart(VAR_10, "#EXT-X-TARGETDURATION:", &VAR_11)) { VAR_4 = ensure_playlist(VAR_0, &VAR_2, VAR_1); if (VAR_4 < 0)
goto fail; VAR_2->target_duration = strtoll(VAR_11, NULL, 10) * AV_TIME_BASE; } else if (av_strstart(VAR_10, "#EXT-X-MEDIA-SEQUENCE:", &VAR_11)) { VAR_4 = ensure_playlist(VAR_0, &VAR_2, VAR_1); if (VAR_4 < 0)
goto fail; VAR_2->start_seq_no = atoi(VAR_11); } else if (av_strstart(VAR_10, "#EXT-X-PLAYLIST-TYPE:", &VAR_11)) { VAR_4 = ensure_playlist(VAR_0, &VAR_2, VAR_1); if (VAR_4 < 0)
goto fail; if (!strcmp(VAR_11, "EVENT"))
VAR_2->type = PLS_TYPE_EVENT; else if (!strcmp(VAR_11, "VOD"))
VAR_2->type = PLS_TYPE_VOD; } else if (av_strstart(VAR_10, "#EXT-X-MAP:", &VAR_11)) { struct init_section_info VAR_17 = {{0}}; VAR_4 = ensure_playlist(VAR_0, &VAR_2, VAR_1); if (VAR_4 < 0)
goto fail; ff_parse_key_value(VAR_11, (ff_parse_key_val_cb) handle_init_section_args,
&VAR_17); VAR_15 = new_init_section(VAR_2, &VAR_17, VAR_1); } else if (av_strstart(VAR_10, "#EXT-X-ENDLIST", &VAR_11)) { if (VAR_2)
VAR_2->finished = 1; } else if (av_strstart(VAR_10, "#EXTINF:", &VAR_11)) { VAR_5 = 1; duration   = atof(VAR_11) * AV_TIME_BASE; } else if (av_strstart(VAR_10, "#EXT-X-BYTERANGE:", &VAR_11)) { seg_size = strtoll(VAR_11, NULL, 10); VAR_11 = strchr(VAR_11, '@'); if (VAR_11)
seg_offset = strtoll(VAR_11+1, NULL, 10); } else if (av_strstart(VAR_10, "#", NULL)) { continue; } else if (VAR_10[0]) { if (VAR_6) { if (!new_variant(VAR_0, &VAR_13, VAR_10, VAR_1)) { VAR_4 = AVERROR(ENOMEM); goto fail; } VAR_6 = 0; } if (VAR_5) { struct segment *VAR_17; if (!VAR_2) { if (!new_variant(VAR_0, 0, VAR_1, NULL)) { VAR_4 = AVERROR(ENOMEM); goto fail; } VAR_2 = VAR_0->playlists[VAR_0->n_playlists - 1]; } VAR_17 = av_malloc(sizeof(struct segment)); if (!VAR_17) { VAR_4 = AVERROR(ENOMEM); goto fail; } VAR_17->duration = duration; VAR_17->VAR_7 = VAR_7; if (VAR_8) { memcpy(VAR_17->iv, iv, sizeof(iv)); } else { int VAR_18 = VAR_2->start_seq_no + VAR_2->n_segments; memset(VAR_17->iv, 0, sizeof(VAR_17->iv)); AV_WB32(VAR_17->iv + 12, VAR_18); } if (VAR_7 != KEY_NONE) { ff_make_absolute_url(VAR_14, sizeof(VAR_14), VAR_1, VAR_9); VAR_17->VAR_9 = av_strdup(VAR_14); if (!VAR_17->VAR_9) { av_free(VAR_17); VAR_4 = AVERROR(ENOMEM); goto fail; } } else { VAR_17->VAR_9 = NULL; } ff_make_absolute_url(VAR_14, sizeof(VAR_14), VAR_1, VAR_10); VAR_17->VAR_1 = av_strdup(VAR_14); if (!VAR_17->VAR_1) { av_free(VAR_17->VAR_9); av_free(VAR_17); VAR_4 = AVERROR(ENOMEM); goto fail; } dynarray_add(&VAR_2->segments, &VAR_2->n_segments, VAR_17); VAR_5 = 0; VAR_17->size = seg_size; if (seg_size >= 0) { VAR_17->url_offset = seg_offset; seg_offset += seg_size; seg_size = -1; } else { VAR_17->url_offset = 0; seg_offset = 0; } VAR_17->init_section = VAR_15; } } } if (VAR_2)
VAR_2->last_load_time = av_gettime_relative(); fail:
av_free(new_url); if (VAR_12)
ff_format_io_close(VAR_0->ctx, &VAR_3); return VAR_4; }