static int webvtt_read_header(AVFormatContext *s)

{

    WebVTTContext *webvtt = s->priv_data;

    AVBPrint header, cue;

    int res = 0;

    AVStream *st = avformat_new_stream(s, NULL);



    if (!st)

        return AVERROR(ENOMEM);

    avpriv_set_pts_info(st, 64, 1, 1000);

    st->codec->codec_type = AVMEDIA_TYPE_SUBTITLE;

    st->codec->codec_id   = AV_CODEC_ID_WEBVTT;

    st->disposition |= webvtt->kind;



    av_bprint_init(&header, 0, AV_BPRINT_SIZE_UNLIMITED);

    av_bprint_init(&cue,    0, AV_BPRINT_SIZE_UNLIMITED);



    for (;;) {

        int i;

        int64_t pos;

        AVPacket *sub;

        const char *p, *identifier, *settings;

        int identifier_len, settings_len;

        int64_t ts_start, ts_end;



        ff_subtitles_read_chunk(s->pb, &cue);



        if (!cue.len)

            break;



        p = identifier = cue.str;

        pos = avio_tell(s->pb);



        /* ignore header chunk */

        if (!strncmp(p, "\xEF\xBB\xBFWEBVTT", 9) ||

            !strncmp(p, "WEBVTT", 6))

            continue;



        /* optional cue identifier (can be a number like in SRT or some kind of

         * chaptering id) */

        for (i = 0; p[i] && p[i] != '\n' && p[i] != '\r'; i++) {

            if (!strncmp(p + i, "-->", 3)) {

                identifier = NULL;

                break;

            }

        }

        if (!identifier)

            identifier_len = 0;

        else {

            identifier_len = strcspn(p, "\r\n");

            p += identifier_len;

            if (*p == '\r')

                p++;

            if (*p == '\n')

                p++;

        }



        /* cue timestamps */

        if ((ts_start = read_ts(p)) == AV_NOPTS_VALUE)

            break;

        if (!(p = strstr(p, "-->")))

            break;

        p += 3;

        do p++; while (*p == ' ' || *p == '\t');

        if ((ts_end = read_ts(p)) == AV_NOPTS_VALUE)

            break;



        /* optional cue settings */

        p += strcspn(p, "\n\t ");

        while (*p == '\t' || *p == ' ')

            p++;

        settings = p;

        settings_len = strcspn(p, "\r\n");

        p += settings_len;

        if (*p == '\r')

            p++;

        if (*p == '\n')

            p++;



        /* create packet */

        sub = ff_subtitles_queue_insert(&webvtt->q, p, strlen(p), 0);

        if (!sub) {

            res = AVERROR(ENOMEM);

            goto end;

        }

        sub->pos = pos;

        sub->pts = ts_start;

        sub->duration = ts_end - ts_start;



#define SET_SIDE_DATA(name, type) do {                                  \

    if (name##_len) {                                                   \

        uint8_t *buf = av_packet_new_side_data(sub, type, name##_len);  \

        if (!buf) {                                                     \

            res = AVERROR(ENOMEM);                                      \

            goto end;                                                   \

        }                                                               \

        memcpy(buf, name, name##_len);                                  \

    }                                                                   \

} while (0)



        SET_SIDE_DATA(identifier, AV_PKT_DATA_WEBVTT_IDENTIFIER);

        SET_SIDE_DATA(settings,   AV_PKT_DATA_WEBVTT_SETTINGS);

    }



    ff_subtitles_queue_finalize(&webvtt->q);



end:

    av_bprint_finalize(&cue,    NULL);

    av_bprint_finalize(&header, NULL);

    return res;

}

static int webvtt_read_header(AVFormatContext *s)

{

    WebVTTContext *webvtt = s->priv_data;

    AVBPrint header, cue;

    int res = 0;

    AVStream *st = avformat_new_stream(s, NULL);



    if (!st)

        return AVERROR(ENOMEM);

    avpriv_set_pts_info(st, 64, 1, 1000);

    st->codec->codec_type = AVMEDIA_TYPE_SUBTITLE;

    st->codec->codec_id   = AV_CODEC_ID_WEBVTT;

    st->disposition |= webvtt->kind;



    av_bprint_init(&header, 0, AV_BPRINT_SIZE_UNLIMITED);

    av_bprint_init(&cue,    0, AV_BPRINT_SIZE_UNLIMITED);



    for (;;) {

        int i;

        int64_t pos;

        AVPacket *sub;

        const char *p, *identifier, *settings;

        int identifier_len, settings_len;

        int64_t ts_start, ts_end;



        ff_subtitles_read_chunk(s->pb, &cue);



        if (!cue.len)

            break;



        p = identifier = cue.str;

        pos = avio_tell(s->pb);



        

        if (!strncmp(p, "\xEF\xBB\xBFWEBVTT", 9) ||

            !strncmp(p, "WEBVTT", 6))

            continue;



        



        for (i = 0; p[i] && p[i] != '\n' && p[i] != '\r'; i++) {

            if (!strncmp(p + i, "-->", 3)) {

                identifier = NULL;

                break;

            }

        }

        if (!identifier)

            identifier_len = 0;

        else {

            identifier_len = strcspn(p, "\r\n");

            p += identifier_len;

            if (*p == '\r')

                p++;

            if (*p == '\n')

                p++;

        }



        

        if ((ts_start = read_ts(p)) == AV_NOPTS_VALUE)

            break;

        if (!(p = strstr(p, "-->")))

            break;

        p += 3;

        do p++; while (*p == ' ' || *p == '\t');

        if ((ts_end = read_ts(p)) == AV_NOPTS_VALUE)

            break;



        

        p += strcspn(p, "\n\t ");

        while (*p == '\t' || *p == ' ')

            p++;

        settings = p;

        settings_len = strcspn(p, "\r\n");

        p += settings_len;

        if (*p == '\r')

            p++;

        if (*p == '\n')

            p++;



        

        sub = ff_subtitles_queue_insert(&webvtt->q, p, strlen(p), 0);

        if (!sub) {

            res = AVERROR(ENOMEM);

            goto end;

        }

        sub->pos = pos;

        sub->pts = ts_start;

        sub->duration = ts_end - ts_start;



#define SET_SIDE_DATA(name, type) do {                                  \

    if (name##_len) {                                                   \

        uint8_t *buf = av_packet_new_side_data(sub, type, name##_len);  \

        if (!buf) {                                                     \

            res = AVERROR(ENOMEM);                                      \

            goto end;                                                   \

        }                                                               \

        memcpy(buf, name, name##_len);                                  \

    }                                                                   \

} while (0)



        SET_SIDE_DATA(identifier, AV_PKT_DATA_WEBVTT_IDENTIFIER);

        SET_SIDE_DATA(settings,   AV_PKT_DATA_WEBVTT_SETTINGS);

    }



    ff_subtitles_queue_finalize(&webvtt->q);



end:

    av_bprint_finalize(&cue,    NULL);

    av_bprint_finalize(&header, NULL);

    return res;

}

        p += 3;
static int FUNC_0(AVFormatContext *VAR_0)

{

    WebVTTContext *webvtt = VAR_0->priv_data;

    AVBPrint header, cue;

    int VAR_1 = 0;

    AVStream *st = avformat_new_stream(VAR_0, NULL);



    if (!st)

        return AVERROR(ENOMEM);

    avpriv_set_pts_info(st, 64, 1, 1000);

    st->codec->codec_type = AVMEDIA_TYPE_SUBTITLE;

    st->codec->codec_id   = AV_CODEC_ID_WEBVTT;

    st->disposition |= webvtt->kind;



    av_bprint_init(&header, 0, AV_BPRINT_SIZE_UNLIMITED);

    av_bprint_init(&cue,    0, AV_BPRINT_SIZE_UNLIMITED);



    for (;;) {

        int VAR_2;

        int64_t pos;

        AVPacket *sub;

        const char *VAR_3, *VAR_4, *VAR_5;

        int VAR_6, VAR_7;

        int64_t ts_start, ts_end;



        ff_subtitles_read_chunk(VAR_0->pb, &cue);



        if (!cue.len)

            break;



        VAR_3 = VAR_4 = cue.str;

        pos = avio_tell(VAR_0->pb);



        

        if (!strncmp(VAR_3, "\xEF\xBB\xBFWEBVTT", 9) ||

            !strncmp(VAR_3, "WEBVTT", 6))

            continue;



        



        for (VAR_2 = 0; VAR_3[VAR_2] && VAR_3[VAR_2] != '\n' && VAR_3[VAR_2] != '\r'; VAR_2++) {

            if (!strncmp(VAR_3 + VAR_2, "-->", 3)) {

                VAR_4 = NULL;

                break;

            }

        }

        if (!VAR_4)

            VAR_6 = 0;

        else {

            VAR_6 = strcspn(VAR_3, "\r\n");

            VAR_3 += VAR_6;

            if (*VAR_3 == '\r')

                VAR_3++;

            if (*VAR_3 == '\n')

                VAR_3++;

        }



        

        if ((ts_start = read_ts(VAR_3)) == AV_NOPTS_VALUE)

            break;

        if (!(VAR_3 = strstr(VAR_3, "-->")))

            break;

        VAR_3 += 3;

        do VAR_3++; while (*VAR_3 == ' ' || *VAR_3 == '\t');

        if ((ts_end = read_ts(VAR_3)) == AV_NOPTS_VALUE)

            break;



        

        VAR_3 += strcspn(VAR_3, "\n\t ");

        while (*VAR_3 == '\t' || *VAR_3 == ' ')

            VAR_3++;

        VAR_5 = VAR_3;

        VAR_7 = strcspn(VAR_3, "\r\n");

        VAR_3 += VAR_7;

        if (*VAR_3 == '\r')

            VAR_3++;

        if (*VAR_3 == '\n')

            VAR_3++;



        

        sub = ff_subtitles_queue_insert(&webvtt->q, VAR_3, strlen(VAR_3), 0);

        if (!sub) {

            VAR_1 = AVERROR(ENOMEM);

            goto end;

        }

        sub->pos = pos;

        sub->pts = ts_start;

        sub->duration = ts_end - ts_start;



#define SET_SIDE_DATA(name, type) do {                                  \

    if (name##_len) {                                                   \

        uint8_t *buf = av_packet_new_side_data(sub, type, name##_len);  \

        if (!buf) {                                                     \

            VAR_1 = AVERROR(ENOMEM);                                      \

            goto end;                                                   \

        }                                                               \

        memcpy(buf, name, name##_len);                                  \

    }                                                                   \

} while (0)



        SET_SIDE_DATA(VAR_4, AV_PKT_DATA_WEBVTT_IDENTIFIER);

        SET_SIDE_DATA(VAR_5,   AV_PKT_DATA_WEBVTT_SETTINGS);

    }



    ff_subtitles_queue_finalize(&webvtt->q);



end:

    av_bprint_finalize(&cue,    NULL);

    av_bprint_finalize(&header, NULL);

    return VAR_1;

}

static int FUNC_0(AVFormatContext *VAR_0)
{ WebVTTContext *webvtt = VAR_0->priv_data; AVBPrint header, cue; int VAR_1 = 0; AVStream *st = avformat_new_stream(VAR_0, NULL); if (!st)
return AVERROR(ENOMEM); avpriv_set_pts_info(st, 64, 1, 1000); st->codec->codec_type = AVMEDIA_TYPE_SUBTITLE; st->codec->codec_id   = AV_CODEC_ID_WEBVTT; st->disposition |= webvtt->kind; av_bprint_init(&header, 0, AV_BPRINT_SIZE_UNLIMITED); av_bprint_init(&cue,    0, AV_BPRINT_SIZE_UNLIMITED); for (;;) { int VAR_2; int64_t pos; AVPacket *sub; const char *VAR_3, *VAR_4, *VAR_5; int VAR_6, VAR_7; int64_t ts_start, ts_end; ff_subtitles_read_chunk(VAR_0->pb, &cue); if (!cue.len)
break; VAR_3 = VAR_4 = cue.str; pos = avio_tell(VAR_0->pb); if (!strncmp(VAR_3, "\xEF\xBB\xBFWEBVTT", 9) ||
!strncmp(VAR_3, "WEBVTT", 6))
continue; for (VAR_2 = 0; VAR_3[VAR_2] && VAR_3[VAR_2] != '\n' && VAR_3[VAR_2] != '\r'; VAR_2++) { if (!strncmp(VAR_3 + VAR_2, "-->", 3)) { VAR_4 = NULL; break; } } if (!VAR_4)
VAR_6 = 0; else { VAR_6 = strcspn(VAR_3, "\r\n"); VAR_3 += VAR_6; if (*VAR_3 == '\r')
VAR_3++; if (*VAR_3 == '\n')
VAR_3++; } if ((ts_start = read_ts(VAR_3)) == AV_NOPTS_VALUE)
break; if (!(VAR_3 = strstr(VAR_3, "-->")))
break; VAR_3 += 3; do VAR_3++; while (*VAR_3 == ' ' || *VAR_3 == '\t'); if ((ts_end = read_ts(VAR_3)) == AV_NOPTS_VALUE)
break; VAR_3 += strcspn(VAR_3, "\n\t "); while (*VAR_3 == '\t' || *VAR_3 == ' ')
VAR_3++; VAR_5 = VAR_3; VAR_7 = strcspn(VAR_3, "\r\n"); VAR_3 += VAR_7; if (*VAR_3 == '\r')
VAR_3++; if (*VAR_3 == '\n')
VAR_3++; sub = ff_subtitles_queue_insert(&webvtt->q, VAR_3, strlen(VAR_3), 0); if (!sub) { VAR_1 = AVERROR(ENOMEM); goto end; } sub->pos = pos; sub->pts = ts_start; sub->duration = ts_end - ts_start; #define SET_SIDE_DATA(name, type) do {                                  \ if (name##_len) {                                                   \ uint8_t *buf = av_packet_new_side_data(sub, type, name##_len);  \ if (!buf) {                                                     \ VAR_1 = AVERROR(ENOMEM);                                      \ goto end;                                                   \ }                                                               \ memcpy(buf, name, name##_len);                                  \ }                                                                   \ } while (0) SET_SIDE_DATA(VAR_4, AV_PKT_DATA_WEBVTT_IDENTIFIER); SET_SIDE_DATA(VAR_5,   AV_PKT_DATA_WEBVTT_SETTINGS); } ff_subtitles_queue_finalize(&webvtt->q); end:
av_bprint_finalize(&cue,    NULL); av_bprint_finalize(&header, NULL); return VAR_1; }