comparison xsubdec.c @ 5484:ad3e24850727 libavcodec

Add forgotten xsub timecode parsing
author reimar
date Sun, 05 Aug 2007 12:11:11 +0000
parents 447409d8770f
children e41873bf253a
comparison
equal deleted inserted replaced
5483:447409d8770f 5484:ad3e24850727
3 #include "bytestream.h" 3 #include "bytestream.h"
4 4
5 static int decode_init(AVCodecContext *avctx) { 5 static int decode_init(AVCodecContext *avctx) {
6 avctx->pix_fmt = PIX_FMT_PAL8; 6 avctx->pix_fmt = PIX_FMT_PAL8;
7 return 0; 7 return 0;
8 }
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;
8 } 25 }
9 26
10 static const uint8_t runbits[8] = { 2, 2, 6, 6, 10, 10, 14, 14 }; 27 static const uint8_t runbits[8] = { 2, 2, 6, 6, 10, 10, 14, 14 };
11 28
12 static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, 29 static int decode_frame(AVCodecContext *avctx, void *data, int *data_size,
20 // check that at least header fits 37 // check that at least header fits
21 if (buf_size < 27 + 7 * 2 + 4 * 3) { 38 if (buf_size < 27 + 7 * 2 + 4 * 3) {
22 av_log(avctx, AV_LOG_ERROR, "coded frame too small\n"); 39 av_log(avctx, AV_LOG_ERROR, "coded frame too small\n");
23 return -1; 40 return -1;
24 } 41 }
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;
25 51
26 // read header 52 // read header
27 w = bytestream_get_le16(&buf); 53 w = bytestream_get_le16(&buf);
28 h = bytestream_get_le16(&buf); 54 h = bytestream_get_le16(&buf);
29 if (avcodec_check_dimensions(avctx, w, h) < 0) 55 if (avcodec_check_dimensions(avctx, w, h) < 0)