Revision 59f6f64e libavcodec/xsubdec.c

View differences:

libavcodec/xsubdec.c
7 7
    return 0;
8 8
}
9 9

  
10
static const uint8_t tc_offsets[9] = { 0, 1, 3, 4, 6, 7, 9, 10, 11 };
11
static const uint8_t tc_muls[9] = { 10, 6, 10, 6, 10, 6, 10, 10, 1 };
12

  
13
static uint64_t parse_timecode(AVCodecContext *avctx, uint8_t *buf) {
14
    int i;
15
    int64_t ms = 0;
16
    if (buf[2] != ':' || buf[5] != ':' || buf[8] != '.')
17
        return AV_NOPTS_VALUE;
18
    for (i = 0; i < sizeof(tc_offsets); i++) {
19
        uint8_t c = buf[tc_offsets[i]] - '0';
20
        if (c > 9) return AV_NOPTS_VALUE;
21
        ms = (ms + c) * tc_muls[i];
22
    }
23
    ms = av_rescale_q(ms, (AVRational){1, 1000}, avctx->time_base);
24
    return ms;
25
}
26

  
10 27
static const uint8_t runbits[8] = { 2, 2, 6, 6, 10, 10, 14, 14 };
11 28

  
12 29
static int decode_frame(AVCodecContext *avctx, void *data, int *data_size,
......
23 40
        return -1;
24 41
    }
25 42

  
43
    // read start and end time
44
    if (buf[0] != '[' || buf[13] != '-' || buf[26] != ']') {
45
        av_log(avctx, AV_LOG_ERROR, "invalid time code\n");
46
        return -1;
47
    }
48
    sub->start_display_time = parse_timecode(avctx, buf +  1);
49
    sub->end_display_time   = parse_timecode(avctx, buf + 14);
50
    buf += 27;
51

  
26 52
    // read header
27 53
    w = bytestream_get_le16(&buf);
28 54
    h = bytestream_get_le16(&buf);

Also available in: Unified diff