static int jacosub_read_header(AVFormatContext *s)

{

    AVBPrint header;

    AVIOContext *pb = s->pb;

    char line[JSS_MAX_LINESIZE];

    JACOsubContext *jacosub = s->priv_data;

    int shift_set = 0; // only the first shift matters

    int merge_line = 0;

    int i, ret;



    AVStream *st = avformat_new_stream(s, NULL);

    if (!st)

        return AVERROR(ENOMEM);

    avpriv_set_pts_info(st, 64, 1, 100);

    st->codec->codec_type = AVMEDIA_TYPE_SUBTITLE;

    st->codec->codec_id   = AV_CODEC_ID_JACOSUB;



    jacosub->timeres = 30;



    av_bprint_init(&header, 1024+FF_INPUT_BUFFER_PADDING_SIZE, 4096);



    while (!avio_feof(pb)) {

        int cmd_len;

        const char *p = line;

        int64_t pos = avio_tell(pb);

        int len = ff_get_line(pb, line, sizeof(line));



        p = jss_skip_whitespace(p);



        /* queue timed line */

        if (merge_line || timed_line(p)) {

            AVPacket *sub;



            sub = ff_subtitles_queue_insert(&jacosub->q, line, len, merge_line);

            if (!sub)

                return AVERROR(ENOMEM);

            sub->pos = pos;

            merge_line = len > 1 && !strcmp(&line[len - 2], "\\\n");

            continue;

        }



        /* skip all non-compiler commands and focus on the command */

        if (*p != '#')

            continue;

        p++;

        i = get_jss_cmd(p[0]);

        if (i == -1)

            continue;



        /* trim command + spaces */

        cmd_len = strlen(cmds[i]);

        if (av_strncasecmp(p, cmds[i], cmd_len) == 0)

            p += cmd_len;

        else

            p++;

        p = jss_skip_whitespace(p);



        /* handle commands which affect the whole script */

        switch (cmds[i][0]) {

        case 'S': // SHIFT command affect the whole script...

            if (!shift_set) {

                jacosub->shift = get_shift(jacosub->timeres, p);

                shift_set = 1;

            }

            av_bprintf(&header, "#S %s", p);

            break;

        case 'T': // ...but must be placed after TIMERES

            jacosub->timeres = strtol(p, NULL, 10);

            if (!jacosub->timeres)

                jacosub->timeres = 30;

            else

                av_bprintf(&header, "#T %s", p);

            break;

        }

    }



    /* general/essential directives in the extradata */

    ret = avpriv_bprint_to_extradata(st->codec, &header);

    if (ret < 0)

        return ret;



    /* SHIFT and TIMERES affect the whole script so packet timing can only be

     * done in a second pass */

    for (i = 0; i < jacosub->q.nb_subs; i++) {

        AVPacket *sub = &jacosub->q.subs[i];

        read_ts(jacosub, sub->data, &sub->pts, &sub->duration);

    }

    ff_subtitles_queue_finalize(&jacosub->q);



    return 0;

}

static int jacosub_read_header(AVFormatContext *s)

{

    AVBPrint header;

    AVIOContext *pb = s->pb;

    char line[JSS_MAX_LINESIZE];

    JACOsubContext *jacosub = s->priv_data;

    int shift_set = 0; 

    int merge_line = 0;

    int i, ret;



    AVStream *st = avformat_new_stream(s, NULL);

    if (!st)

        return AVERROR(ENOMEM);

    avpriv_set_pts_info(st, 64, 1, 100);

    st->codec->codec_type = AVMEDIA_TYPE_SUBTITLE;

    st->codec->codec_id   = AV_CODEC_ID_JACOSUB;



    jacosub->timeres = 30;



    av_bprint_init(&header, 1024+FF_INPUT_BUFFER_PADDING_SIZE, 4096);



    while (!avio_feof(pb)) {

        int cmd_len;

        const char *p = line;

        int64_t pos = avio_tell(pb);

        int len = ff_get_line(pb, line, sizeof(line));



        p = jss_skip_whitespace(p);



        

        if (merge_line || timed_line(p)) {

            AVPacket *sub;



            sub = ff_subtitles_queue_insert(&jacosub->q, line, len, merge_line);

            if (!sub)

                return AVERROR(ENOMEM);

            sub->pos = pos;

            merge_line = len > 1 && !strcmp(&line[len - 2], "\\\n");

            continue;

        }



        

        if (*p != '#')

            continue;

        p++;

        i = get_jss_cmd(p[0]);

        if (i == -1)

            continue;



        

        cmd_len = strlen(cmds[i]);

        if (av_strncasecmp(p, cmds[i], cmd_len) == 0)

            p += cmd_len;

        else

            p++;

        p = jss_skip_whitespace(p);



        

        switch (cmds[i][0]) {

        case 'S': 

            if (!shift_set) {

                jacosub->shift = get_shift(jacosub->timeres, p);

                shift_set = 1;

            }

            av_bprintf(&header, "#S %s", p);

            break;

        case 'T': 

            jacosub->timeres = strtol(p, NULL, 10);

            if (!jacosub->timeres)

                jacosub->timeres = 30;

            else

                av_bprintf(&header, "#T %s", p);

            break;

        }

    }



    

    ret = avpriv_bprint_to_extradata(st->codec, &header);

    if (ret < 0)

        return ret;



    



    for (i = 0; i < jacosub->q.nb_subs; i++) {

        AVPacket *sub = &jacosub->q.subs[i];

        read_ts(jacosub, sub->data, &sub->pts, &sub->duration);

    }

    ff_subtitles_queue_finalize(&jacosub->q);



    return 0;

}

        return ret;
static int FUNC_0(AVFormatContext *VAR_0)

{

    AVBPrint header;

    AVIOContext *pb = VAR_0->pb;

    char VAR_1[JSS_MAX_LINESIZE];

    JACOsubContext *jacosub = VAR_0->priv_data;

    int VAR_2 = 0; 

    int VAR_3 = 0;

    int VAR_4, VAR_5;



    AVStream *st = avformat_new_stream(VAR_0, NULL);

    if (!st)

        return AVERROR(ENOMEM);

    avpriv_set_pts_info(st, 64, 1, 100);

    st->codec->codec_type = AVMEDIA_TYPE_SUBTITLE;

    st->codec->codec_id   = AV_CODEC_ID_JACOSUB;



    jacosub->timeres = 30;



    av_bprint_init(&header, 1024+FF_INPUT_BUFFER_PADDING_SIZE, 4096);



    while (!avio_feof(pb)) {

        int VAR_6;

        const char *VAR_7 = VAR_1;

        int64_t pos = avio_tell(pb);

        int VAR_8 = ff_get_line(pb, VAR_1, sizeof(VAR_1));



        VAR_7 = jss_skip_whitespace(VAR_7);



        

        if (VAR_3 || timed_line(VAR_7)) {

            AVPacket *sub;



            sub = ff_subtitles_queue_insert(&jacosub->q, VAR_1, VAR_8, VAR_3);

            if (!sub)

                return AVERROR(ENOMEM);

            sub->pos = pos;

            VAR_3 = VAR_8 > 1 && !strcmp(&VAR_1[VAR_8 - 2], "\\\n");

            continue;

        }



        

        if (*VAR_7 != '#')

            continue;

        VAR_7++;

        VAR_4 = get_jss_cmd(VAR_7[0]);

        if (VAR_4 == -1)

            continue;



        

        VAR_6 = strlen(cmds[VAR_4]);

        if (av_strncasecmp(VAR_7, cmds[VAR_4], VAR_6) == 0)

            VAR_7 += VAR_6;

        else

            VAR_7++;

        VAR_7 = jss_skip_whitespace(VAR_7);



        

        switch (cmds[VAR_4][0]) {

        case 'S': 

            if (!VAR_2) {

                jacosub->shift = get_shift(jacosub->timeres, VAR_7);

                VAR_2 = 1;

            }

            av_bprintf(&header, "#S %VAR_0", VAR_7);

            break;

        case 'T': 

            jacosub->timeres = strtol(VAR_7, NULL, 10);

            if (!jacosub->timeres)

                jacosub->timeres = 30;

            else

                av_bprintf(&header, "#T %VAR_0", VAR_7);

            break;

        }

    }



    

    VAR_5 = avpriv_bprint_to_extradata(st->codec, &header);

    if (VAR_5 < 0)

        return VAR_5;



    



    for (VAR_4 = 0; VAR_4 < jacosub->q.nb_subs; VAR_4++) {

        AVPacket *sub = &jacosub->q.subs[VAR_4];

        read_ts(jacosub, sub->data, &sub->pts, &sub->duration);

    }

    ff_subtitles_queue_finalize(&jacosub->q);



    return 0;

}

static int FUNC_0(AVFormatContext *VAR_0)
{ AVBPrint header; AVIOContext *pb = VAR_0->pb; char VAR_1[JSS_MAX_LINESIZE]; JACOsubContext *jacosub = VAR_0->priv_data; int VAR_2 = 0; int VAR_3 = 0; int VAR_4, VAR_5; AVStream *st = avformat_new_stream(VAR_0, NULL); if (!st)
return AVERROR(ENOMEM); avpriv_set_pts_info(st, 64, 1, 100); st->codec->codec_type = AVMEDIA_TYPE_SUBTITLE; st->codec->codec_id   = AV_CODEC_ID_JACOSUB; jacosub->timeres = 30; av_bprint_init(&header, 1024+FF_INPUT_BUFFER_PADDING_SIZE, 4096); while (!avio_feof(pb)) { int VAR_6; const char *VAR_7 = VAR_1; int64_t pos = avio_tell(pb); int VAR_8 = ff_get_line(pb, VAR_1, sizeof(VAR_1)); VAR_7 = jss_skip_whitespace(VAR_7); if (VAR_3 || timed_line(VAR_7)) { AVPacket *sub; sub = ff_subtitles_queue_insert(&jacosub->q, VAR_1, VAR_8, VAR_3); if (!sub)
return AVERROR(ENOMEM); sub->pos = pos; VAR_3 = VAR_8 > 1 && !strcmp(&VAR_1[VAR_8 - 2], "\\\n"); continue; } if (*VAR_7 != '#')
continue; VAR_7++; VAR_4 = get_jss_cmd(VAR_7[0]); if (VAR_4 == -1)
continue; VAR_6 = strlen(cmds[VAR_4]); if (av_strncasecmp(VAR_7, cmds[VAR_4], VAR_6) == 0)
VAR_7 += VAR_6; else
VAR_7++; VAR_7 = jss_skip_whitespace(VAR_7); switch (cmds[VAR_4][0]) { case 'S':
if (!VAR_2) { jacosub->shift = get_shift(jacosub->timeres, VAR_7); VAR_2 = 1; } av_bprintf(&header, "#S %VAR_0", VAR_7); break; case 'T':
jacosub->timeres = strtol(VAR_7, NULL, 10); if (!jacosub->timeres)
jacosub->timeres = 30; else
av_bprintf(&header, "#T %VAR_0", VAR_7); break; } } VAR_5 = avpriv_bprint_to_extradata(st->codec, &header); if (VAR_5 < 0)
return VAR_5; for (VAR_4 = 0; VAR_4 < jacosub->q.nb_subs; VAR_4++) { AVPacket *sub = &jacosub->q.subs[VAR_4]; read_ts(jacosub, sub->data, &sub->pts, &sub->duration); } ff_subtitles_queue_finalize(&jacosub->q); return 0; }