~ppsspp/ppsspp/ffmpeg

« back to all changes in this revision

Viewing changes to libavcodec/textdec.c

  • Committer: Henrik Rydgård
  • Date: 2014-01-03 10:44:32 UTC
  • Revision ID: git-v1:87c6c126784b1718bfa448ecf2e6a9fef781eb4e
Update our ffmpeg snapshot to a clone of the official repository.

This is because Maxim's at3plus support has been officially merged!

Show diffs side-by-side

added added

removed removed

Lines of Context:
41
41
    { NULL }
42
42
};
43
43
 
44
 
static int text_event_to_ass(const AVCodecContext *avctx, AVBPrint *buf,
45
 
                             const char *p, const char *p_end)
46
 
{
47
 
    const TextContext *text = avctx->priv_data;
48
 
 
49
 
    for (; p < p_end && *p; p++) {
50
 
 
51
 
        /* forced custom line breaks, not accounted as "normal" EOL */
52
 
        if (text->linebreaks && strchr(text->linebreaks, *p)) {
53
 
            av_bprintf(buf, "\\N");
54
 
 
55
 
        /* standard ASS escaping so random characters don't get mis-interpreted
56
 
         * as ASS */
57
 
        } else if (!text->keep_ass_markup && strchr("{}\\", *p)) {
58
 
            av_bprintf(buf, "\\%c", *p);
59
 
 
60
 
        /* some packets might end abruptly (no \0 at the end, like for example
61
 
         * in some cases of demuxing from a classic video container), some
62
 
         * might be terminated with \n or \r\n which we have to remove (for
63
 
         * consistency with those who haven't), and we also have to deal with
64
 
         * evil cases such as \r at the end of the buffer (and no \0 terminated
65
 
         * character) */
66
 
        } else if (p[0] == '\n') {
67
 
            /* some stuff left so we can insert a line break */
68
 
            if (p < p_end - 1)
69
 
                av_bprintf(buf, "\\N");
70
 
        } else if (p[0] == '\r' && p < p_end - 1 && p[1] == '\n') {
71
 
            /* \r followed by a \n, we can skip it. We don't insert the \N yet
72
 
             * because we don't know if it is followed by more text */
73
 
            continue;
74
 
 
75
 
        /* finally, a sane character */
76
 
        } else {
77
 
            av_bprint_chars(buf, *p, 1);
78
 
        }
79
 
    }
80
 
    av_bprintf(buf, "\r\n");
81
 
    return 0;
82
 
}
83
 
 
84
44
static int text_decode_frame(AVCodecContext *avctx, void *data,
85
45
                             int *got_sub_ptr, AVPacket *avpkt)
86
46
{
87
47
    AVBPrint buf;
88
48
    AVSubtitle *sub = data;
89
49
    const char *ptr = avpkt->data;
 
50
    const TextContext *text = avctx->priv_data;
90
51
    const int ts_start     = av_rescale_q(avpkt->pts,      avctx->time_base, (AVRational){1,100});
91
52
    const int ts_duration  = avpkt->duration != -1 ?
92
53
                             av_rescale_q(avpkt->duration, avctx->time_base, (AVRational){1,100}) : -1;
93
54
 
94
55
    av_bprint_init(&buf, 0, AV_BPRINT_SIZE_UNLIMITED);
95
 
    if (ptr && avpkt->size > 0 && *ptr &&
96
 
        !text_event_to_ass(avctx, &buf, ptr, ptr + avpkt->size)) {
 
56
    if (ptr && avpkt->size > 0 && *ptr) {
 
57
        ff_ass_bprint_text_event(&buf, ptr, avpkt->size, text->linebreaks, text->keep_ass_markup);
97
58
        if (!av_bprint_is_complete(&buf)) {
98
59
            av_bprint_finalize(&buf, NULL);
99
60
            return AVERROR(ENOMEM);