static int parse_playlist(URLContext *h, const char *url)

{

    HLSContext *s = h->priv_data;

    AVIOContext *in;

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

    int64_t duration = 0;

    char line[1024];

    const char *ptr;



    if ((ret = avio_open2(&in, url, AVIO_FLAG_READ,

                          &h->interrupt_callback, NULL)) < 0)

        return ret;



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

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

        return AVERROR_INVALIDDATA;



    free_segment_list(s);

    s->finished = 0;

    while (!in->eof_reached) {

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

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

            struct variant_info info = {{0}};

            is_variant = 1;

            ff_parse_key_value(ptr, (ff_parse_key_val_cb) handle_variant_args,

                               &info);

            bandwidth = atoi(info.bandwidth);

        } else if (av_strstart(line, "#EXT-X-TARGETDURATION:", &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 = atof(ptr) * AV_TIME_BASE;

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

            continue;

        } else if (line[0]) {

            if (is_segment) {

                struct segment *seg = av_malloc(sizeof(struct segment));

                if (!seg) {

                    ret = AVERROR(ENOMEM);

                    goto fail;

                }

                seg->duration = duration;

                ff_make_absolute_url(seg->url, sizeof(seg->url), url, line);

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

                is_segment = 0;

            } else if (is_variant) {

                struct variant *var = av_malloc(sizeof(struct variant));

                if (!var) {

                    ret = AVERROR(ENOMEM);

                    goto fail;

                }

                var->bandwidth = bandwidth;

                ff_make_absolute_url(var->url, sizeof(var->url), url, line);

                dynarray_add(&s->variants, &s->n_variants, var);

                is_variant = 0;

            }

        }

    }

    s->last_load_time = av_gettime_relative();



fail:

    avio_close(in);

    return ret;

}

static int parse_playlist(URLContext *h, const char *url)

{

    HLSContext *s = h->priv_data;

    AVIOContext *in;

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

    int64_t duration = 0;

    char line[1024];

    const char *ptr;



    if ((ret = avio_open2(&in, url, AVIO_FLAG_READ,

                          &h->interrupt_callback, NULL)) < 0)

        return ret;



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

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

        return AVERROR_INVALIDDATA;



    free_segment_list(s);

    s->finished = 0;

    while (!in->eof_reached) {

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

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

            struct variant_info info = {{0}};

            is_variant = 1;

            ff_parse_key_value(ptr, (ff_parse_key_val_cb) handle_variant_args,

                               &info);

            bandwidth = atoi(info.bandwidth);

        } else if (av_strstart(line, "#EXT-X-TARGETDURATION:", &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 = atof(ptr) * AV_TIME_BASE;

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

            continue;

        } else if (line[0]) {

            if (is_segment) {

                struct segment *seg = av_malloc(sizeof(struct segment));

                if (!seg) {

                    ret = AVERROR(ENOMEM);

                    goto fail;

                }

                seg->duration = duration;

                ff_make_absolute_url(seg->url, sizeof(seg->url), url, line);

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

                is_segment = 0;

            } else if (is_variant) {

                struct variant *var = av_malloc(sizeof(struct variant));

                if (!var) {

                    ret = AVERROR(ENOMEM);

                    goto fail;

                }

                var->bandwidth = bandwidth;

                ff_make_absolute_url(var->url, sizeof(var->url), url, line);

                dynarray_add(&s->variants, &s->n_variants, var);

                is_variant = 0;

            }

        }

    }

    s->last_load_time = av_gettime_relative();



fail:

    avio_close(in);

    return ret;

}

    if (strcmp(line, "#EXTM3U"))         return AVERROR_INVALIDDATA;
static int FUNC_0(URLContext *VAR_0, const char *VAR_1)

{

    HLSContext *s = VAR_0->priv_data;

    AVIOContext *in;

    int VAR_2 = 0, VAR_3 = 0, VAR_4 = 0, VAR_5 = 0;

    int64_t duration = 0;

    char VAR_6[1024];

    const char *VAR_7;



    if ((VAR_2 = avio_open2(&in, VAR_1, AVIO_FLAG_READ,

                          &VAR_0->interrupt_callback, NULL)) < 0)

        return VAR_2;



    read_chomp_line(in, VAR_6, sizeof(VAR_6));

    if (strcmp(VAR_6, "#EXTM3U"))

        return AVERROR_INVALIDDATA;



    free_segment_list(s);

    s->finished = 0;

    while (!in->eof_reached) {

        read_chomp_line(in, VAR_6, sizeof(VAR_6));

        if (av_strstart(VAR_6, "#EXT-X-STREAM-INF:", &VAR_7)) {

            struct variant_info VAR_8 = {{0}};

            VAR_4 = 1;

            ff_parse_key_value(VAR_7, (ff_parse_key_val_cb) handle_variant_args,

                               &VAR_8);

            VAR_5 = atoi(VAR_8.VAR_5);

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

            s->target_duration = atoi(VAR_7) * AV_TIME_BASE;

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

            s->start_seq_no = atoi(VAR_7);

        } else if (av_strstart(VAR_6, "#EXT-X-ENDLIST", &VAR_7)) {

            s->finished = 1;

        } else if (av_strstart(VAR_6, "#EXTINF:", &VAR_7)) {

            VAR_3 = 1;

            duration = atof(VAR_7) * AV_TIME_BASE;

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

            continue;

        } else if (VAR_6[0]) {

            if (VAR_3) {

                struct segment *VAR_9 = av_malloc(sizeof(struct segment));

                if (!VAR_9) {

                    VAR_2 = AVERROR(ENOMEM);

                    goto fail;

                }

                VAR_9->duration = duration;

                ff_make_absolute_url(VAR_9->VAR_1, sizeof(VAR_9->VAR_1), VAR_1, VAR_6);

                dynarray_add(&s->segments, &s->n_segments, VAR_9);

                VAR_3 = 0;

            } else if (VAR_4) {

                struct variant *VAR_10 = av_malloc(sizeof(struct variant));

                if (!VAR_10) {

                    VAR_2 = AVERROR(ENOMEM);

                    goto fail;

                }

                VAR_10->VAR_5 = VAR_5;

                ff_make_absolute_url(VAR_10->VAR_1, sizeof(VAR_10->VAR_1), VAR_1, VAR_6);

                dynarray_add(&s->variants, &s->n_variants, VAR_10);

                VAR_4 = 0;

            }

        }

    }

    s->last_load_time = av_gettime_relative();



fail:

    avio_close(in);

    return VAR_2;

}

static int FUNC_0(URLContext *VAR_0, const char *VAR_1)
{ HLSContext *s = VAR_0->priv_data; AVIOContext *in; int VAR_2 = 0, VAR_3 = 0, VAR_4 = 0, VAR_5 = 0; int64_t duration = 0; char VAR_6[1024]; const char *VAR_7; if ((VAR_2 = avio_open2(&in, VAR_1, AVIO_FLAG_READ,
&VAR_0->interrupt_callback, NULL)) < 0)
return VAR_2; read_chomp_line(in, VAR_6, sizeof(VAR_6)); if (strcmp(VAR_6, "#EXTM3U"))
return AVERROR_INVALIDDATA; free_segment_list(s); s->finished = 0; while (!in->eof_reached) { read_chomp_line(in, VAR_6, sizeof(VAR_6)); if (av_strstart(VAR_6, "#EXT-X-STREAM-INF:", &VAR_7)) { struct variant_info VAR_8 = {{0}}; VAR_4 = 1; ff_parse_key_value(VAR_7, (ff_parse_key_val_cb) handle_variant_args,
&VAR_8); VAR_5 = atoi(VAR_8.VAR_5); } else if (av_strstart(VAR_6, "#EXT-X-TARGETDURATION:", &VAR_7)) { s->target_duration = atoi(VAR_7) * AV_TIME_BASE; } else if (av_strstart(VAR_6, "#EXT-X-MEDIA-SEQUENCE:", &VAR_7)) { s->start_seq_no = atoi(VAR_7); } else if (av_strstart(VAR_6, "#EXT-X-ENDLIST", &VAR_7)) { s->finished = 1; } else if (av_strstart(VAR_6, "#EXTINF:", &VAR_7)) { VAR_3 = 1; duration = atof(VAR_7) * AV_TIME_BASE; } else if (av_strstart(VAR_6, "#", NULL)) { continue; } else if (VAR_6[0]) { if (VAR_3) { struct segment *VAR_9 = av_malloc(sizeof(struct segment)); if (!VAR_9) { VAR_2 = AVERROR(ENOMEM); goto fail; } VAR_9->duration = duration; ff_make_absolute_url(VAR_9->VAR_1, sizeof(VAR_9->VAR_1), VAR_1, VAR_6); dynarray_add(&s->segments, &s->n_segments, VAR_9); VAR_3 = 0; } else if (VAR_4) { struct variant *VAR_10 = av_malloc(sizeof(struct variant)); if (!VAR_10) { VAR_2 = AVERROR(ENOMEM); goto fail; } VAR_10->VAR_5 = VAR_5; ff_make_absolute_url(VAR_10->VAR_1, sizeof(VAR_10->VAR_1), VAR_1, VAR_6); dynarray_add(&s->variants, &s->n_variants, VAR_10); VAR_4 = 0; } } } s->last_load_time = av_gettime_relative(); fail:
avio_close(in); return VAR_2; }