Mercurial > libavcodec.hg
comparison xsubdec.c @ 10054:8ab9fbad11b2 libavcodec
Fix start_display_time/end_display_time to be relative to packet pts in xsub decoder.
Makes no difference for the sample AVI files since they all have no packet pts values.
author | reimar |
---|---|
date | Sat, 15 Aug 2009 09:12:58 +0000 |
parents | 089dd845c8c0 |
children | 8ac9bc10b485 |
comparison
equal
deleted
inserted
replaced
10053:089dd845c8c0 | 10054:8ab9fbad11b2 |
---|---|
28 } | 28 } |
29 | 29 |
30 static const uint8_t tc_offsets[9] = { 0, 1, 3, 4, 6, 7, 9, 10, 11 }; | 30 static const uint8_t tc_offsets[9] = { 0, 1, 3, 4, 6, 7, 9, 10, 11 }; |
31 static const uint8_t tc_muls[9] = { 10, 6, 10, 6, 10, 10, 10, 10, 1 }; | 31 static const uint8_t tc_muls[9] = { 10, 6, 10, 6, 10, 10, 10, 10, 1 }; |
32 | 32 |
33 static uint64_t parse_timecode(const uint8_t *buf) { | 33 static int64_t parse_timecode(const uint8_t *buf, int64_t packet_time) { |
34 int i; | 34 int i; |
35 int64_t ms = 0; | 35 int64_t ms = 0; |
36 if (buf[2] != ':' || buf[5] != ':' || buf[8] != '.') | 36 if (buf[2] != ':' || buf[5] != ':' || buf[8] != '.') |
37 return AV_NOPTS_VALUE; | 37 return AV_NOPTS_VALUE; |
38 for (i = 0; i < sizeof(tc_offsets); i++) { | 38 for (i = 0; i < sizeof(tc_offsets); i++) { |
39 uint8_t c = buf[tc_offsets[i]] - '0'; | 39 uint8_t c = buf[tc_offsets[i]] - '0'; |
40 if (c > 9) return AV_NOPTS_VALUE; | 40 if (c > 9) return AV_NOPTS_VALUE; |
41 ms = (ms + c) * tc_muls[i]; | 41 ms = (ms + c) * tc_muls[i]; |
42 } | 42 } |
43 return ms; | 43 return ms - packet_time; |
44 } | 44 } |
45 | 45 |
46 static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, | 46 static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, |
47 AVPacket *avpkt) { | 47 AVPacket *avpkt) { |
48 const uint8_t *buf = avpkt->data; | 48 const uint8_t *buf = avpkt->data; |
49 int buf_size = avpkt->size; | 49 int buf_size = avpkt->size; |
50 AVSubtitle *sub = data; | 50 AVSubtitle *sub = data; |
51 const uint8_t *buf_end = buf + buf_size; | 51 const uint8_t *buf_end = buf + buf_size; |
52 uint8_t *bitmap; | 52 uint8_t *bitmap; |
53 int w, h, x, y, rlelen, i; | 53 int w, h, x, y, rlelen, i; |
54 int64_t packet_time = 0; | |
54 GetBitContext gb; | 55 GetBitContext gb; |
55 | 56 |
56 memset(sub, 0, sizeof(*sub)); | 57 memset(sub, 0, sizeof(*sub)); |
57 | 58 |
58 // check that at least header fits | 59 // check that at least header fits |
64 // read start and end time | 65 // read start and end time |
65 if (buf[0] != '[' || buf[13] != '-' || buf[26] != ']') { | 66 if (buf[0] != '[' || buf[13] != '-' || buf[26] != ']') { |
66 av_log(avctx, AV_LOG_ERROR, "invalid time code\n"); | 67 av_log(avctx, AV_LOG_ERROR, "invalid time code\n"); |
67 return -1; | 68 return -1; |
68 } | 69 } |
69 sub->start_display_time = parse_timecode(buf + 1); | 70 if (avpkt->pts != AV_NOPTS_VALUE) |
70 sub->end_display_time = parse_timecode(buf + 14); | 71 packet_time = av_rescale_q(avpkt->pts, AV_TIME_BASE_Q, (AVRational){1, 1000}); |
72 sub->start_display_time = parse_timecode(buf + 1, packet_time); | |
73 sub->end_display_time = parse_timecode(buf + 14, packet_time); | |
71 buf += 27; | 74 buf += 27; |
72 | 75 |
73 // read header | 76 // read header |
74 w = bytestream_get_le16(&buf); | 77 w = bytestream_get_le16(&buf); |
75 h = bytestream_get_le16(&buf); | 78 h = bytestream_get_le16(&buf); |