static int applehttp_open(URLContext *h, const char *uri, int flags)

{

    AppleHTTPContext *s;

    int ret, i;

    const char *nested_url;



    if (flags & AVIO_FLAG_WRITE)

        return AVERROR(ENOSYS);



    s = av_mallocz(sizeof(AppleHTTPContext));

    if (!s)

        return AVERROR(ENOMEM);

    h->priv_data = s;

    h->is_streamed = 1;



    if (av_strstart(uri, "applehttp+", &nested_url)) {

        av_strlcpy(s->playlisturl, nested_url, sizeof(s->playlisturl));

    } 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));

    } else {

        av_log(h, AV_LOG_ERROR, "Unsupported url %s\n", uri);

        ret = AVERROR(EINVAL);

        goto fail;

    }



    if ((ret = parse_playlist(h, s->playlisturl)) < 0)

        goto fail;



    if (s->n_segments == 0 && s->n_variants > 0) {

        int max_bandwidth = 0, maxvar = -1;

        for (i = 0; i < s->n_variants; i++) {

            if (s->variants[i]->bandwidth > max_bandwidth || i == 0) {

                max_bandwidth = s->variants[i]->bandwidth;

                maxvar = i;

            }

        }

        av_strlcpy(s->playlisturl, s->variants[maxvar]->url,

                   sizeof(s->playlisturl));

        if ((ret = parse_playlist(h, s->playlisturl)) < 0)

            goto fail;

    }



    if (s->n_segments == 0) {

        av_log(h, AV_LOG_WARNING, "Empty playlist\n");

        ret = AVERROR(EIO);

        goto fail;

    }

    s->cur_seq_no = s->start_seq_no;

    if (!s->finished && s->n_segments >= 3)

        s->cur_seq_no = s->start_seq_no + s->n_segments - 3;



    return 0;



fail:

    av_free(s);

    return ret;

}

static int applehttp_open(URLContext *h, const char *uri, int flags)

{

    AppleHTTPContext *s;

    int ret, i;

    const char *nested_url;



    if (flags & AVIO_FLAG_WRITE)

        return AVERROR(ENOSYS);



    s = av_mallocz(sizeof(AppleHTTPContext));

    if (!s)

        return AVERROR(ENOMEM);

    h->priv_data = s;

    h->is_streamed = 1;



    if (av_strstart(uri, "applehttp+", &nested_url)) {

        av_strlcpy(s->playlisturl, nested_url, sizeof(s->playlisturl));

    } else if (av_strstart(uri, "applehttp:

        av_strlcpy(s->playlisturl, "http:

        av_strlcat(s->playlisturl, nested_url, sizeof(s->playlisturl));

    } else {

        av_log(h, AV_LOG_ERROR, "Unsupported url %s\n", uri);

        ret = AVERROR(EINVAL);

        goto fail;

    }



    if ((ret = parse_playlist(h, s->playlisturl)) < 0)

        goto fail;



    if (s->n_segments == 0 && s->n_variants > 0) {

        int max_bandwidth = 0, maxvar = -1;

        for (i = 0; i < s->n_variants; i++) {

            if (s->variants[i]->bandwidth > max_bandwidth || i == 0) {

                max_bandwidth = s->variants[i]->bandwidth;

                maxvar = i;

            }

        }

        av_strlcpy(s->playlisturl, s->variants[maxvar]->url,

                   sizeof(s->playlisturl));

        if ((ret = parse_playlist(h, s->playlisturl)) < 0)

            goto fail;

    }



    if (s->n_segments == 0) {

        av_log(h, AV_LOG_WARNING, "Empty playlist\n");

        ret = AVERROR(EIO);

        goto fail;

    }

    s->cur_seq_no = s->start_seq_no;

    if (!s->finished && s->n_segments >= 3)

        s->cur_seq_no = s->start_seq_no + s->n_segments - 3;



    return 0;



fail:

    av_free(s);

    return ret;

}

    av_free(s);     av_free(s);     return 0;
static int FUNC_0(URLContext *VAR_0, const char *VAR_1, int VAR_2)

{

    AppleHTTPContext *s;

    int VAR_3, VAR_4;

    const char *VAR_5;



    if (VAR_2 & AVIO_FLAG_WRITE)

        return AVERROR(ENOSYS);



    s = av_mallocz(sizeof(AppleHTTPContext));

    if (!s)

        return AVERROR(ENOMEM);

    VAR_0->priv_data = s;

    VAR_0->is_streamed = 1;



    if (av_strstart(VAR_1, "applehttp+", &VAR_5)) {

        av_strlcpy(s->playlisturl, VAR_5, sizeof(s->playlisturl));

    } else if (av_strstart(VAR_1, "applehttp:

        av_strlcpy(s->playlisturl, "http:

        av_strlcat(s->playlisturl, VAR_5, sizeof(s->playlisturl));

    } else {

        av_log(VAR_0, AV_LOG_ERROR, "Unsupported url %s\n", VAR_1);

        VAR_3 = AVERROR(EINVAL);

        goto fail;

    }



    if ((VAR_3 = parse_playlist(VAR_0, s->playlisturl)) < 0)

        goto fail;



    if (s->n_segments == 0 && s->n_variants > 0) {

        int VAR_6 = 0, VAR_7 = -1;

        for (VAR_4 = 0; VAR_4 < s->n_variants; VAR_4++) {

            if (s->variants[VAR_4]->bandwidth > VAR_6 || VAR_4 == 0) {

                VAR_6 = s->variants[VAR_4]->bandwidth;

                VAR_7 = VAR_4;

            }

        }

        av_strlcpy(s->playlisturl, s->variants[VAR_7]->url,

                   sizeof(s->playlisturl));

        if ((VAR_3 = parse_playlist(VAR_0, s->playlisturl)) < 0)

            goto fail;

    }



    if (s->n_segments == 0) {

        av_log(VAR_0, AV_LOG_WARNING, "Empty playlist\n");

        VAR_3 = AVERROR(EIO);

        goto fail;

    }

    s->cur_seq_no = s->start_seq_no;

    if (!s->finished && s->n_segments >= 3)

        s->cur_seq_no = s->start_seq_no + s->n_segments - 3;



    return 0;



fail:

    av_free(s);

    return VAR_3;

}

static int FUNC_0(URLContext *VAR_0, const char *VAR_1, int VAR_2)
{ AppleHTTPContext *s; int VAR_3, VAR_4; const char *VAR_5; if (VAR_2 & AVIO_FLAG_WRITE)
return AVERROR(ENOSYS); s = av_mallocz(sizeof(AppleHTTPContext)); if (!s)
return AVERROR(ENOMEM); VAR_0->priv_data = s; VAR_0->is_streamed = 1; if (av_strstart(VAR_1, "applehttp+", &VAR_5)) { av_strlcpy(s->playlisturl, VAR_5, sizeof(s->playlisturl)); } else if (av_strstart(VAR_1, "applehttp: av_strlcpy(s->playlisturl, "http:
av_strlcat(s->playlisturl, VAR_5, sizeof(s->playlisturl)); } else { av_log(VAR_0, AV_LOG_ERROR, "Unsupported url %s\n", VAR_1); VAR_3 = AVERROR(EINVAL); goto fail; } if ((VAR_3 = parse_playlist(VAR_0, s->playlisturl)) < 0)
goto fail; if (s->n_segments == 0 && s->n_variants > 0) { int VAR_6 = 0, VAR_7 = -1; for (VAR_4 = 0; VAR_4 < s->n_variants; VAR_4++) { if (s->variants[VAR_4]->bandwidth > VAR_6 || VAR_4 == 0) { VAR_6 = s->variants[VAR_4]->bandwidth; VAR_7 = VAR_4; } } av_strlcpy(s->playlisturl, s->variants[VAR_7]->url,
sizeof(s->playlisturl)); if ((VAR_3 = parse_playlist(VAR_0, s->playlisturl)) < 0)
goto fail; } if (s->n_segments == 0) { av_log(VAR_0, AV_LOG_WARNING, "Empty playlist\n"); VAR_3 = AVERROR(EIO); goto fail; } s->cur_seq_no = s->start_seq_no; if (!s->finished && s->n_segments >= 3)
s->cur_seq_no = s->start_seq_no + s->n_segments - 3; return 0; fail:
av_free(s); return VAR_3; }