annotate dvdsub.c @ 2830:4e31ad3623cf libavcodec

removed a bunch of unused, sub-optimal code
author melanson
date Sat, 13 Aug 2005 18:49:01 +0000
parents 217844bd1fa1
children 1f117208d20f
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2756
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
1 /*
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
2 * DVD subtitle decoding for ffmpeg
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
3 * Copyright (c) 2005 Fabrice Bellard.
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
4 *
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
5 * This library is free software; you can redistribute it and/or
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
6 * modify it under the terms of the GNU Lesser General Public
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
7 * License as published by the Free Software Foundation; either
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
8 * version 2 of the License, or (at your option) any later version.
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
9 *
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
10 * This library is distributed in the hope that it will be useful,
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
13 * Lesser General Public License for more details.
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
14 *
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
15 * You should have received a copy of the GNU Lesser General Public
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
16 * License along with this library; if not, write to the Free Software
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
18 */
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
19 #include "avcodec.h"
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
20
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
21 //#define DEBUG
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
22
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
23 typedef struct DVDSubContext {
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
24 } DVDSubContext;
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
25
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
26 static int dvdsub_init_decoder(AVCodecContext *avctx)
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
27 {
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
28 return 0;
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
29 }
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
30
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
31 uint16_t getbe16(const uint8_t *p)
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
32 {
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
33 return (p[0] << 8) | p[1];
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
34 }
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
35
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
36 int get_nibble(const uint8_t *buf, int nibble_offset)
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
37 {
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
38 return (buf[nibble_offset >> 1] >> ((1 - (nibble_offset & 1)) << 2)) & 0xf;
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
39 }
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
40
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
41 static int decode_rle(uint8_t *bitmap, int linesize, int w, int h,
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
42 const uint8_t *buf, int nibble_offset, int buf_size)
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
43 {
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
44 unsigned int v;
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
45 int x, y, len, color, nibble_end;
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
46 uint8_t *d;
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
47
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
48 nibble_end = buf_size * 2;
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
49 x = 0;
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
50 y = 0;
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
51 d = bitmap;
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
52 for(;;) {
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
53 if (nibble_offset >= nibble_end)
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
54 return -1;
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
55 v = get_nibble(buf, nibble_offset++);
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
56 if (v < 0x4) {
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
57 v = (v << 4) | get_nibble(buf, nibble_offset++);
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
58 if (v < 0x10) {
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
59 v = (v << 4) | get_nibble(buf, nibble_offset++);
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
60 if (v < 0x040) {
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
61 v = (v << 4) | get_nibble(buf, nibble_offset++);
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
62 if (v < 4) {
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
63 v |= (w - x) << 2;
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
64 }
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
65 }
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
66 }
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
67 }
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
68 len = v >> 2;
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
69 if (len > (w - x))
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
70 len = (w - x);
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
71 color = v & 0x03;
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
72 memset(d + x, color, len);
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
73 x += len;
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
74 if (x >= w) {
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
75 y++;
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
76 if (y >= h)
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
77 break;
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
78 d += linesize;
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
79 x = 0;
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
80 /* byte align */
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
81 nibble_offset += (nibble_offset & 1);
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
82 }
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
83 }
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
84 return 0;
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
85 }
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
86
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
87 static void guess_palette(uint32_t *rgba_palette,
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
88 uint8_t *palette,
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
89 uint8_t *alpha,
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
90 uint32_t subtitle_color)
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
91 {
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
92 uint8_t color_used[16];
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
93 int nb_opaque_colors, i, level, j, r, g, b;
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
94
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
95 for(i = 0; i < 4; i++)
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
96 rgba_palette[i] = 0;
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
97
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
98 memset(color_used, 0, 16);
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
99 nb_opaque_colors = 0;
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
100 for(i = 0; i < 4; i++) {
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
101 if (alpha[i] != 0 && !color_used[palette[i]]) {
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
102 color_used[palette[i]] = 1;
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
103 nb_opaque_colors++;
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
104 }
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
105 }
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
106
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
107 if (nb_opaque_colors == 0)
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
108 return;
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
109
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
110 j = 0;
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
111 memset(color_used, 0, 16);
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
112 for(i = 0; i < 4; i++) {
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
113 if (alpha[i] != 0) {
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
114 if (!color_used[palette[i]]) {
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
115 level = (0xff * (j + 1)) / nb_opaque_colors;
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
116 r = (((subtitle_color >> 16) & 0xff) * level) >> 8;
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
117 g = (((subtitle_color >> 8) & 0xff) * level) >> 8;
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
118 b = (((subtitle_color >> 0) & 0xff) * level) >> 8;
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
119 rgba_palette[i] = b | (g << 8) | (r << 16) | (0xff << 24);
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
120 color_used[palette[i]] = (i + 1);
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
121 j++;
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
122 } else {
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
123 rgba_palette[i] = rgba_palette[color_used[palette[i]] - 1];
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
124 }
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
125 }
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
126 }
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
127 }
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
128
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
129 static int decode_dvd_subtitles(AVSubtitle *sub_header,
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
130 const uint8_t *buf, int buf_size)
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
131 {
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
132 int cmd_pos, pos, cmd, x1, y1, x2, y2, offset1, offset2, next_cmd_pos;
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
133 uint8_t palette[4], alpha[4];
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
134 int date;
2797
217844bd1fa1 10l (forgot to commit this yesterday)
michael
parents: 2756
diff changeset
135 int i;
2756
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
136
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
137 if (buf_size < 4)
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
138 return -1;
2797
217844bd1fa1 10l (forgot to commit this yesterday)
michael
parents: 2756
diff changeset
139 sub_header->rects = NULL;
217844bd1fa1 10l (forgot to commit this yesterday)
michael
parents: 2756
diff changeset
140 sub_header->num_rects = 0;
2756
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
141 sub_header->start_display_time = 0;
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
142 sub_header->end_display_time = 0;
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
143
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
144 cmd_pos = getbe16(buf + 2);
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
145 while ((cmd_pos + 4) < buf_size) {
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
146 date = getbe16(buf + cmd_pos);
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
147 next_cmd_pos = getbe16(buf + cmd_pos + 2);
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
148 #ifdef DEBUG
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
149 av_log(NULL, AV_LOG_INFO, "cmd_pos=0x%04x next=0x%04x date=%d\n",
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
150 cmd_pos, next_cmd_pos, date);
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
151 #endif
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
152 pos = cmd_pos + 4;
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
153 offset1 = -1;
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
154 offset2 = -1;
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
155 x1 = y1 = x2 = y2 = 0;
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
156 while (pos < buf_size) {
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
157 cmd = buf[pos++];
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
158 #ifdef DEBUG
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
159 av_log(NULL, AV_LOG_INFO, "cmd=%02x\n", cmd);
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
160 #endif
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
161 switch(cmd) {
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
162 case 0x00:
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
163 /* force display */
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
164 break;
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
165 case 0x01:
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
166 /* set start date */
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
167 sub_header->start_display_time = date * 10;
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
168 break;
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
169 case 0x02:
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
170 /* set end date */
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
171 sub_header->end_display_time = date * 10;
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
172 break;
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
173 case 0x03:
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
174 /* set palette */
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
175 if ((buf_size - pos) < 2)
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
176 goto fail;
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
177 palette[0] = buf[pos] >> 4;
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
178 palette[1] = buf[pos] & 0x0f;
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
179 palette[2] = buf[pos + 1] >> 4;
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
180 palette[3] = buf[pos + 1] & 0x0f;
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
181 pos += 2;
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
182 break;
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
183 case 0x04:
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
184 /* set alpha */
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
185 if ((buf_size - pos) < 2)
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
186 goto fail;
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
187 alpha[0] = buf[pos] >> 4;
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
188 alpha[1] = buf[pos] & 0x0f;
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
189 alpha[2] = buf[pos + 1] >> 4;
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
190 alpha[3] = buf[pos + 1] & 0x0f;
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
191 pos += 2;
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
192 break;
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
193 case 0x05:
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
194 if ((buf_size - pos) < 6)
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
195 goto fail;
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
196 x1 = (buf[pos] << 4) | (buf[pos + 1] >> 4);
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
197 x2 = ((buf[pos + 1] & 0x0f) << 8) | buf[pos + 2];
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
198 y1 = (buf[pos + 3] << 4) | (buf[pos + 4] >> 4);
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
199 y2 = ((buf[pos + 4] & 0x0f) << 8) | buf[pos + 5];
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
200 #ifdef DEBUG
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
201 av_log(NULL, AV_LOG_INFO, "x1=%d x2=%d y1=%d y2=%d\n",
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
202 x1, x2, y1, y2);
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
203 #endif
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
204 pos += 6;
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
205 break;
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
206 case 0x06:
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
207 if ((buf_size - pos) < 4)
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
208 goto fail;
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
209 offset1 = getbe16(buf + pos);
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
210 offset2 = getbe16(buf + pos + 2);
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
211 #ifdef DEBUG
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
212 av_log(NULL, AV_LOG_INFO, "offset1=0x%04x offset2=0x%04x\n", offset1, offset2);
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
213 #endif
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
214 pos += 4;
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
215 break;
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
216 case 0xff:
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
217 default:
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
218 goto the_end;
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
219 }
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
220 }
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
221 the_end:
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
222 if (offset1 >= 0) {
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
223 int w, h;
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
224 uint8_t *bitmap;
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
225
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
226 /* decode the bitmap */
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
227 w = x2 - x1 + 1;
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
228 if (w < 0)
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
229 w = 0;
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
230 h = y2 - y1;
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
231 if (h < 0)
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
232 h = 0;
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
233 if (w > 0 && h > 0) {
2797
217844bd1fa1 10l (forgot to commit this yesterday)
michael
parents: 2756
diff changeset
234 if (sub_header->rects != NULL) {
217844bd1fa1 10l (forgot to commit this yesterday)
michael
parents: 2756
diff changeset
235 for (i = 0; i < sub_header->num_rects; i++) {
217844bd1fa1 10l (forgot to commit this yesterday)
michael
parents: 2756
diff changeset
236 av_free(sub_header->rects[i].bitmap);
217844bd1fa1 10l (forgot to commit this yesterday)
michael
parents: 2756
diff changeset
237 av_free(sub_header->rects[i].rgba_palette);
217844bd1fa1 10l (forgot to commit this yesterday)
michael
parents: 2756
diff changeset
238 }
217844bd1fa1 10l (forgot to commit this yesterday)
michael
parents: 2756
diff changeset
239 av_freep(&sub_header->rects);
217844bd1fa1 10l (forgot to commit this yesterday)
michael
parents: 2756
diff changeset
240 sub_header->num_rects = 0;
217844bd1fa1 10l (forgot to commit this yesterday)
michael
parents: 2756
diff changeset
241 }
217844bd1fa1 10l (forgot to commit this yesterday)
michael
parents: 2756
diff changeset
242
2756
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
243 bitmap = av_malloc(w * h);
2797
217844bd1fa1 10l (forgot to commit this yesterday)
michael
parents: 2756
diff changeset
244 sub_header->rects = av_mallocz(sizeof(AVSubtitleRect));
217844bd1fa1 10l (forgot to commit this yesterday)
michael
parents: 2756
diff changeset
245 sub_header->num_rects = 1;
217844bd1fa1 10l (forgot to commit this yesterday)
michael
parents: 2756
diff changeset
246 sub_header->rects[0].rgba_palette = av_malloc(4 * 4);
2756
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
247 decode_rle(bitmap, w * 2, w, h / 2,
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
248 buf, offset1 * 2, buf_size);
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
249 decode_rle(bitmap + w, w * 2, w, h / 2,
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
250 buf, offset2 * 2, buf_size);
2797
217844bd1fa1 10l (forgot to commit this yesterday)
michael
parents: 2756
diff changeset
251 guess_palette(sub_header->rects[0].rgba_palette,
2756
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
252 palette, alpha, 0xffff00);
2797
217844bd1fa1 10l (forgot to commit this yesterday)
michael
parents: 2756
diff changeset
253 sub_header->rects[0].x = x1;
217844bd1fa1 10l (forgot to commit this yesterday)
michael
parents: 2756
diff changeset
254 sub_header->rects[0].y = y1;
217844bd1fa1 10l (forgot to commit this yesterday)
michael
parents: 2756
diff changeset
255 sub_header->rects[0].w = w;
217844bd1fa1 10l (forgot to commit this yesterday)
michael
parents: 2756
diff changeset
256 sub_header->rects[0].h = h;
217844bd1fa1 10l (forgot to commit this yesterday)
michael
parents: 2756
diff changeset
257 sub_header->rects[0].nb_colors = 4;
217844bd1fa1 10l (forgot to commit this yesterday)
michael
parents: 2756
diff changeset
258 sub_header->rects[0].linesize = w;
217844bd1fa1 10l (forgot to commit this yesterday)
michael
parents: 2756
diff changeset
259 sub_header->rects[0].bitmap = bitmap;
2756
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
260 }
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
261 }
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
262 if (next_cmd_pos == cmd_pos)
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
263 break;
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
264 cmd_pos = next_cmd_pos;
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
265 }
2797
217844bd1fa1 10l (forgot to commit this yesterday)
michael
parents: 2756
diff changeset
266 if (sub_header->num_rects > 0)
2756
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
267 return 0;
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
268 fail:
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
269 return -1;
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
270 }
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
271
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
272 static int is_transp(const uint8_t *buf, int pitch, int n,
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
273 const uint8_t *transp_color)
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
274 {
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
275 int i;
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
276 for(i = 0; i < n; i++) {
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
277 if (!transp_color[*buf])
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
278 return 0;
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
279 buf += pitch;
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
280 }
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
281 return 1;
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
282 }
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
283
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
284 /* return 0 if empty rectangle, 1 if non empty */
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
285 static int find_smallest_bouding_rectangle(AVSubtitle *s)
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
286 {
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
287 uint8_t transp_color[256];
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
288 int y1, y2, x1, x2, y, w, h, i;
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
289 uint8_t *bitmap;
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
290
2797
217844bd1fa1 10l (forgot to commit this yesterday)
michael
parents: 2756
diff changeset
291 if (s->num_rects == 0 || s->rects == NULL || s->rects[0].w <= 0 || s->rects[0].h <= 0)
2756
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
292 return 0;
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
293
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
294 memset(transp_color, 0, 256);
2797
217844bd1fa1 10l (forgot to commit this yesterday)
michael
parents: 2756
diff changeset
295 for(i = 0; i < s->rects[0].nb_colors; i++) {
217844bd1fa1 10l (forgot to commit this yesterday)
michael
parents: 2756
diff changeset
296 if ((s->rects[0].rgba_palette[i] >> 24) == 0)
2756
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
297 transp_color[i] = 1;
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
298 }
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
299 y1 = 0;
2797
217844bd1fa1 10l (forgot to commit this yesterday)
michael
parents: 2756
diff changeset
300 while (y1 < s->rects[0].h && is_transp(s->rects[0].bitmap + y1 * s->rects[0].linesize,
217844bd1fa1 10l (forgot to commit this yesterday)
michael
parents: 2756
diff changeset
301 1, s->rects[0].w, transp_color))
2756
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
302 y1++;
2797
217844bd1fa1 10l (forgot to commit this yesterday)
michael
parents: 2756
diff changeset
303 if (y1 == s->rects[0].h) {
217844bd1fa1 10l (forgot to commit this yesterday)
michael
parents: 2756
diff changeset
304 av_freep(&s->rects[0].bitmap);
217844bd1fa1 10l (forgot to commit this yesterday)
michael
parents: 2756
diff changeset
305 s->rects[0].w = s->rects[0].h = 0;
2756
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
306 return 0;
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
307 }
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
308
2797
217844bd1fa1 10l (forgot to commit this yesterday)
michael
parents: 2756
diff changeset
309 y2 = s->rects[0].h - 1;
217844bd1fa1 10l (forgot to commit this yesterday)
michael
parents: 2756
diff changeset
310 while (y2 > 0 && is_transp(s->rects[0].bitmap + y2 * s->rects[0].linesize, 1,
217844bd1fa1 10l (forgot to commit this yesterday)
michael
parents: 2756
diff changeset
311 s->rects[0].w, transp_color))
2756
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
312 y2--;
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
313 x1 = 0;
2797
217844bd1fa1 10l (forgot to commit this yesterday)
michael
parents: 2756
diff changeset
314 while (x1 < (s->rects[0].w - 1) && is_transp(s->rects[0].bitmap + x1, s->rects[0].linesize,
217844bd1fa1 10l (forgot to commit this yesterday)
michael
parents: 2756
diff changeset
315 s->rects[0].h, transp_color))
2756
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
316 x1++;
2797
217844bd1fa1 10l (forgot to commit this yesterday)
michael
parents: 2756
diff changeset
317 x2 = s->rects[0].w - 1;
217844bd1fa1 10l (forgot to commit this yesterday)
michael
parents: 2756
diff changeset
318 while (x2 > 0 && is_transp(s->rects[0].bitmap + x2, s->rects[0].linesize, s->rects[0].h,
2756
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
319 transp_color))
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
320 x2--;
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
321 w = x2 - x1 + 1;
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
322 h = y2 - y1 + 1;
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
323 bitmap = av_malloc(w * h);
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
324 if (!bitmap)
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
325 return 1;
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
326 for(y = 0; y < h; y++) {
2797
217844bd1fa1 10l (forgot to commit this yesterday)
michael
parents: 2756
diff changeset
327 memcpy(bitmap + w * y, s->rects[0].bitmap + x1 + (y1 + y) * s->rects[0].linesize, w);
2756
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
328 }
2797
217844bd1fa1 10l (forgot to commit this yesterday)
michael
parents: 2756
diff changeset
329 av_freep(&s->rects[0].bitmap);
217844bd1fa1 10l (forgot to commit this yesterday)
michael
parents: 2756
diff changeset
330 s->rects[0].bitmap = bitmap;
217844bd1fa1 10l (forgot to commit this yesterday)
michael
parents: 2756
diff changeset
331 s->rects[0].linesize = w;
217844bd1fa1 10l (forgot to commit this yesterday)
michael
parents: 2756
diff changeset
332 s->rects[0].w = w;
217844bd1fa1 10l (forgot to commit this yesterday)
michael
parents: 2756
diff changeset
333 s->rects[0].h = h;
217844bd1fa1 10l (forgot to commit this yesterday)
michael
parents: 2756
diff changeset
334 s->rects[0].x += x1;
217844bd1fa1 10l (forgot to commit this yesterday)
michael
parents: 2756
diff changeset
335 s->rects[0].y += y1;
2756
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
336 return 1;
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
337 }
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
338
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
339 static int dvdsub_close_decoder(AVCodecContext *avctx)
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
340 {
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
341 return 0;
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
342 }
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
343
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
344 #ifdef DEBUG
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
345 #undef fprintf
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
346 static void ppm_save(const char *filename, uint8_t *bitmap, int w, int h,
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
347 uint32_t *rgba_palette)
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
348 {
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
349 int x, y, v;
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
350 FILE *f;
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
351
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
352 f = fopen(filename, "w");
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
353 if (!f) {
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
354 perror(filename);
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
355 exit(1);
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
356 }
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
357 fprintf(f, "P6\n"
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
358 "%d %d\n"
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
359 "%d\n",
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
360 w, h, 255);
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
361 for(y = 0; y < h; y++) {
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
362 for(x = 0; x < w; x++) {
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
363 v = rgba_palette[bitmap[y * w + x]];
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
364 putc((v >> 16) & 0xff, f);
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
365 putc((v >> 8) & 0xff, f);
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
366 putc((v >> 0) & 0xff, f);
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
367 }
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
368 }
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
369 fclose(f);
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
370 }
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
371 #endif
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
372
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
373 static int dvdsub_decode(AVCodecContext *avctx,
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
374 void *data, int *data_size,
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
375 uint8_t *buf, int buf_size)
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
376 {
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
377 AVSubtitle *sub = (void *)data;
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
378
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
379 if (decode_dvd_subtitles(sub, buf, buf_size) < 0) {
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
380 no_subtitle:
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
381 *data_size = 0;
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
382
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
383 return buf_size;
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
384 }
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
385 if (find_smallest_bouding_rectangle(sub) == 0)
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
386 goto no_subtitle;
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
387
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
388 #if defined(DEBUG)
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
389 av_log(NULL, AV_LOG_INFO, "start=%d ms end =%d ms\n",
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
390 sub->start_display_time,
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
391 sub->end_display_time);
2797
217844bd1fa1 10l (forgot to commit this yesterday)
michael
parents: 2756
diff changeset
392 ppm_save("/tmp/a.ppm", sub->rects[0].bitmap,
217844bd1fa1 10l (forgot to commit this yesterday)
michael
parents: 2756
diff changeset
393 sub->rects[0].w, sub->rects[0].h, sub->rects[0].rgba_palette);
2756
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
394 #endif
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
395
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
396 *data_size = 1;
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
397 return buf_size;
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
398 }
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
399
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
400 AVCodec dvdsub_decoder = {
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
401 "dvdsub",
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
402 CODEC_TYPE_SUBTITLE,
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
403 CODEC_ID_DVD_SUBTITLE,
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
404 sizeof(DVDSubContext),
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
405 dvdsub_init_decoder,
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
406 NULL,
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
407 dvdsub_close_decoder,
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
408 dvdsub_decode,
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
409 };
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
410
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
411 /* parser definition */
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
412 typedef struct DVDSubParseContext {
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
413 uint8_t *packet;
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
414 int packet_len;
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
415 int packet_index;
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
416 } DVDSubParseContext;
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
417
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
418 static int dvdsub_parse_init(AVCodecParserContext *s)
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
419 {
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
420 return 0;
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
421 }
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
422
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
423 static int dvdsub_parse(AVCodecParserContext *s,
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
424 AVCodecContext *avctx,
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
425 uint8_t **poutbuf, int *poutbuf_size,
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
426 const uint8_t *buf, int buf_size)
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
427 {
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
428 DVDSubParseContext *pc = s->priv_data;
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
429
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
430 if (pc->packet_index == 0) {
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
431 if (buf_size < 2)
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
432 return 0;
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
433 pc->packet_len = (buf[0] << 8) | buf[1];
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
434 av_freep(&pc->packet);
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
435 pc->packet = av_malloc(pc->packet_len);
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
436 }
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
437 if (pc->packet) {
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
438 if (pc->packet_index + buf_size <= pc->packet_len) {
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
439 memcpy(pc->packet + pc->packet_index, buf, buf_size);
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
440 pc->packet_index += buf_size;
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
441 if (pc->packet_index >= pc->packet_len) {
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
442 *poutbuf = pc->packet;
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
443 *poutbuf_size = pc->packet_len;
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
444 pc->packet_index = 0;
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
445 return buf_size;
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
446 }
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
447 } else {
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
448 /* erroneous size */
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
449 pc->packet_index = 0;
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
450 }
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
451 }
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
452 *poutbuf = NULL;
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
453 *poutbuf_size = 0;
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
454 return buf_size;
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
455 }
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
456
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
457 static void dvdsub_parse_close(AVCodecParserContext *s)
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
458 {
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
459 DVDSubParseContext *pc = s->priv_data;
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
460 av_freep(&pc->packet);
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
461 }
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
462
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
463 AVCodecParser dvdsub_parser = {
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
464 { CODEC_ID_DVD_SUBTITLE },
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
465 sizeof(DVDSubParseContext),
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
466 dvdsub_parse_init,
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
467 dvdsub_parse,
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
468 dvdsub_parse_close,
d8874c8749ec subtitle codec type support
bellard
parents:
diff changeset
469 };