annotate vobsub.c @ 6314:cca3f20aadee

updated to english version
author jonas
date Thu, 06 Jun 2002 20:47:59 +0000
parents 141a082e6da6
children f8551f89dd48
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
4080
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
1 /*
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
2 * Some code freely inspired from VobSub <URL:http://vobsub.edensrising.com>,
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
3 * with kind permission from Gabest <gabest@freemail.hu>
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
4 */
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
5 /* #define HAVE_GETLINE */
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
6 #include <ctype.h>
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
7 #include <errno.h>
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
8 #include <stdio.h>
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
9 #include <stdlib.h>
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
10 #include <string.h>
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
11 #include <fcntl.h>
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
12 #include <unistd.h>
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
13 #include <sys/stat.h>
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
14 #include <sys/types.h>
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
15
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
16 #include "config.h"
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
17
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
18 #include "stream.h"
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
19 #include "vobsub.h"
6110
7bea806b9c5f Improvment for spu subtitles.
albeu
parents: 5869
diff changeset
20 #include "libvo/video_out.h"
4080
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
21 #include "spudec.h"
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
22 #include "mp_msg.h"
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
23
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
24 extern int vobsub_id;
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
25
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
26 extern int verbose;
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
27
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
28 #ifdef HAVE_GETLINE
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
29 extern ssize_t getline(char **, size_t *, FILE *);
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
30 #else
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
31 /* FIXME This should go into a general purpose library or even a
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
32 separate file. */
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
33 static ssize_t
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
34 getline (char **lineptr, size_t *n, FILE *stream)
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
35 {
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
36 size_t res = 0;
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
37 int c;
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
38 if (*lineptr == NULL) {
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
39 *lineptr = malloc(4096);
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
40 if (*lineptr)
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
41 *n = 4096;
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
42 }
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
43 else if (*n == 0) {
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
44 char *tmp = realloc(*lineptr, 4096);
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
45 if (tmp) {
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
46 *lineptr = tmp;
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
47 *n = 4096;
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
48 }
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
49 }
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
50 if (*lineptr == NULL || *n == 0)
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
51 return -1;
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
52
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
53 for (c = fgetc(stream); c != EOF; c = fgetc(stream)) {
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
54 if (res + 1 >= *n) {
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
55 char *tmp = realloc(*lineptr, *n * 2);
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
56 if (tmp == NULL)
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
57 return -1;
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
58 *lineptr = tmp;
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
59 *n *= 2;
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
60 }
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
61 (*lineptr)[res++] = c;
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
62 if (c == '\n') {
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
63 (*lineptr)[res] = 0;
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
64 return res;
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
65 }
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
66 }
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
67 if (res == 0)
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
68 return -1;
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
69 (*lineptr)[res] = 0;
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
70 return res;
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
71 }
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
72 #endif
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
73
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
74 /**********************************************************************
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
75 * MPEG parsing
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
76 **********************************************************************/
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
77
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
78 typedef struct {
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
79 stream_t *stream;
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
80 unsigned int pts;
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
81 int aid;
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
82 unsigned char *packet;
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
83 unsigned int packet_reserve;
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
84 unsigned int packet_size;
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
85 } mpeg_t;
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
86
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
87 static mpeg_t *
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
88 mpeg_open(const char *filename)
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
89 {
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
90 mpeg_t *res = malloc(sizeof(mpeg_t));
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
91 int err = res == NULL;
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
92 if (!err) {
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
93 int fd;
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
94 res->pts = 0;
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
95 res->aid = -1;
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
96 res->packet = NULL;
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
97 res->packet_size = 0;
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
98 res->packet_reserve = 0;
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
99 fd = open(filename, O_RDONLY);
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
100 err = fd < 0;
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
101 if (!err) {
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
102 res->stream = new_stream(fd, STREAMTYPE_FILE);
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
103 err = res->stream == NULL;
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
104 if (err)
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
105 close(fd);
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
106 }
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
107 if (err)
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
108 free(res);
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
109 }
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
110 return err ? NULL : res;
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
111 }
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
112
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
113 static void
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
114 mpeg_free(mpeg_t *mpeg)
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
115 {
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
116 int fd;
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
117 if (mpeg->packet)
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
118 free(mpeg->packet);
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
119 fd = mpeg->stream->fd;
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
120 free_stream(mpeg->stream);
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
121 close(fd);
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
122 free(mpeg);
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
123 }
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
124
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
125 static int
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
126 mpeg_eof(mpeg_t *mpeg)
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
127 {
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
128 return stream_eof(mpeg->stream);
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
129 }
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
130
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
131 static off_t
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
132 mpeg_tell(mpeg_t *mpeg)
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
133 {
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
134 return stream_tell(mpeg->stream);
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
135 }
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
136
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
137 static int
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
138 mpeg_run(mpeg_t *mpeg)
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
139 {
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
140 unsigned int len, idx, version;
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
141 int c;
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
142 /* Goto start of a packet, it starts with 0x000001?? */
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
143 const unsigned char wanted[] = { 0, 0, 1 };
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
144 unsigned char buf[5];
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
145
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
146 mpeg->aid = -1;
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
147 mpeg->packet_size = 0;
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
148 if (stream_read(mpeg->stream, buf, 4) != 4)
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
149 return -1;
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
150 while (memcmp(buf, wanted, sizeof(wanted)) != 0) {
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
151 c = stream_read_char(mpeg->stream);
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
152 if (c < 0)
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
153 return -1;
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
154 memmove(buf, buf + 1, 3);
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
155 buf[3] = c;
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
156 }
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
157 switch (buf[3]) {
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
158 case 0xb9: /* System End Code */
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
159 break;
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
160 case 0xba: /* Packet start code */
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
161 c = stream_read_char(mpeg->stream);
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
162 if (c < 0)
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
163 return -1;
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
164 if ((c & 0xc0) == 0x40)
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
165 version = 4;
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
166 else if ((c & 0xf0) == 0x20)
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
167 version = 2;
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
168 else {
6110
7bea806b9c5f Improvment for spu subtitles.
albeu
parents: 5869
diff changeset
169 mp_msg(MSGT_VOBSUB,MSGL_ERR, "Unsupported MPEG version: 0x%02x", c);
4080
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
170 return -1;
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
171 }
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
172 if (version == 4) {
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
173 if (!stream_skip(mpeg->stream, 9))
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
174 return -1;
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
175 }
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
176 else if (version == 2) {
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
177 if (!stream_skip(mpeg->stream, 7))
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
178 return -1;
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
179 }
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
180 else
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
181 abort();
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
182 break;
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
183 case 0xbd: /* packet */
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
184 if (stream_read(mpeg->stream, buf, 2) != 2)
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
185 return -1;
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
186 len = buf[0] << 8 | buf[1];
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
187 idx = mpeg_tell(mpeg);
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
188 c = stream_read_char(mpeg->stream);
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
189 if (c < 0)
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
190 return -1;
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
191 if ((c & 0xC0) == 0x40) { /* skip STD scale & size */
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
192 if (stream_read_char(mpeg->stream) < 0)
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
193 return -1;
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
194 c = stream_read_char(mpeg->stream);
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
195 if (c < 0)
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
196 return -1;
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
197 }
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
198 if ((c & 0xf0) == 0x20) { /* System-1 stream timestamp */
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
199 /* Do we need this? */
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
200 abort();
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
201 }
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
202 else if ((c & 0xf0) == 0x30) {
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
203 /* Do we need this? */
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
204 abort();
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
205 }
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
206 else if ((c & 0xc0) == 0x80) { /* System-2 (.VOB) stream */
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
207 unsigned int pts_flags, hdrlen, dataidx;
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
208 c = stream_read_char(mpeg->stream);
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
209 if (c < 0)
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
210 return -1;
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
211 pts_flags = c;
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
212 c = stream_read_char(mpeg->stream);
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
213 if (c < 0)
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
214 return -1;
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
215 hdrlen = c;
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
216 dataidx = mpeg_tell(mpeg) + hdrlen;
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
217 if (dataidx > idx + len) {
6110
7bea806b9c5f Improvment for spu subtitles.
albeu
parents: 5869
diff changeset
218 mp_msg(MSGT_VOBSUB,MSGL_ERR, "Invalid header length: %d (total length: %d, idx: %d, dataidx: %d)\n",
4080
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
219 hdrlen, len, idx, dataidx);
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
220 return -1;
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
221 }
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
222 if ((pts_flags & 0xc0) == 0x80) {
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
223 if (stream_read(mpeg->stream, buf, 5) != 5)
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
224 return -1;
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
225 if (!(((buf[0] & 0xf0) == 0x20) && (buf[0] & 1) && (buf[2] & 1) && (buf[4] & 1))) {
6110
7bea806b9c5f Improvment for spu subtitles.
albeu
parents: 5869
diff changeset
226 mp_msg(MSGT_VOBSUB,MSGL_ERR, "vobsub PTS error: 0x%02x %02x%02x %02x%02x \n",
4080
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
227 buf[0], buf[1], buf[2], buf[3], buf[4]);
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
228 mpeg->pts = 0;
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
229 }
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
230 else
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
231 mpeg->pts = ((buf[0] & 0x0e) << 29 | buf[1] << 22 | (buf[2] & 0xfe) << 14
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
232 | buf[3] << 7 | (buf[4] >> 1)) / 900;
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
233 }
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
234 else /* if ((pts_flags & 0xc0) == 0xc0) */ {
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
235 /* what's this? */
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
236 /* abort(); */
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
237 }
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
238 stream_seek(mpeg->stream, dataidx);
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
239 mpeg->aid = stream_read_char(mpeg->stream);
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
240 if (mpeg->aid < 0) {
6110
7bea806b9c5f Improvment for spu subtitles.
albeu
parents: 5869
diff changeset
241 mp_msg(MSGT_VOBSUB,MSGL_ERR, "Bogus aid %d\n", mpeg->aid);
4080
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
242 return -1;
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
243 }
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
244 mpeg->packet_size = len - ((unsigned int) mpeg_tell(mpeg) - idx);
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
245 if (mpeg->packet_reserve < mpeg->packet_size) {
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
246 if (mpeg->packet)
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
247 free(mpeg->packet);
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
248 mpeg->packet = malloc(mpeg->packet_size);
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
249 if (mpeg->packet)
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
250 mpeg->packet_reserve = mpeg->packet_size;
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
251 }
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
252 if (mpeg->packet == NULL) {
6110
7bea806b9c5f Improvment for spu subtitles.
albeu
parents: 5869
diff changeset
253 mp_msg(MSGT_VOBSUB,MSGL_FATAL,"malloc failure");
4080
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
254 mpeg->packet_reserve = 0;
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
255 mpeg->packet_size = 0;
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
256 return -1;
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
257 }
6110
7bea806b9c5f Improvment for spu subtitles.
albeu
parents: 5869
diff changeset
258 if ((unsigned int)stream_read(mpeg->stream, mpeg->packet, mpeg->packet_size) != mpeg->packet_size) {
7bea806b9c5f Improvment for spu subtitles.
albeu
parents: 5869
diff changeset
259 mp_msg(MSGT_VOBSUB,MSGL_ERR,"stream_read failure");
4080
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
260 mpeg->packet_size = 0;
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
261 return -1;
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
262 }
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
263 idx = len;
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
264 }
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
265 break;
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
266 case 0xbe: /* Padding */
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
267 if (stream_read(mpeg->stream, buf, 2) != 2)
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
268 return -1;
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
269 len = buf[0] << 8 | buf[1];
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
270 if (len > 0 && !stream_skip(mpeg->stream, len))
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
271 return -1;
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
272 break;
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
273 default:
5388
3af2729c5c87 * New command line switch for mplayer & mencoder:
kmkaplan
parents: 4787
diff changeset
274 if (0xc0 <= buf[3] && buf[3] < 0xf0) {
3af2729c5c87 * New command line switch for mplayer & mencoder:
kmkaplan
parents: 4787
diff changeset
275 /* MPEG audio or video */
3af2729c5c87 * New command line switch for mplayer & mencoder:
kmkaplan
parents: 4787
diff changeset
276 if (stream_read(mpeg->stream, buf, 2) != 2)
3af2729c5c87 * New command line switch for mplayer & mencoder:
kmkaplan
parents: 4787
diff changeset
277 return -1;
3af2729c5c87 * New command line switch for mplayer & mencoder:
kmkaplan
parents: 4787
diff changeset
278 len = buf[0] << 8 | buf[1];
3af2729c5c87 * New command line switch for mplayer & mencoder:
kmkaplan
parents: 4787
diff changeset
279 if (len > 0 && !stream_skip(mpeg->stream, len))
3af2729c5c87 * New command line switch for mplayer & mencoder:
kmkaplan
parents: 4787
diff changeset
280 return -1;
3af2729c5c87 * New command line switch for mplayer & mencoder:
kmkaplan
parents: 4787
diff changeset
281
3af2729c5c87 * New command line switch for mplayer & mencoder:
kmkaplan
parents: 4787
diff changeset
282 }
3af2729c5c87 * New command line switch for mplayer & mencoder:
kmkaplan
parents: 4787
diff changeset
283 else {
6110
7bea806b9c5f Improvment for spu subtitles.
albeu
parents: 5869
diff changeset
284 mp_msg(MSGT_VOBSUB,MSGL_ERR,"unknown header 0x%02X%02X%02X%02X\n",
5388
3af2729c5c87 * New command line switch for mplayer & mencoder:
kmkaplan
parents: 4787
diff changeset
285 buf[0], buf[1], buf[2], buf[3]);
3af2729c5c87 * New command line switch for mplayer & mencoder:
kmkaplan
parents: 4787
diff changeset
286 return -1;
3af2729c5c87 * New command line switch for mplayer & mencoder:
kmkaplan
parents: 4787
diff changeset
287 }
4080
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
288 }
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
289 return 0;
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
290 }
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
291
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
292 /**********************************************************************
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
293 * Packet queue
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
294 **********************************************************************/
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
295
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
296 typedef struct {
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
297 unsigned int pts100;
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
298 off_t filepos;
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
299 unsigned int size;
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
300 unsigned char *data;
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
301 } packet_t;
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
302
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
303 typedef struct {
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
304 char *id;
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
305 packet_t *packets;
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
306 unsigned int packets_reserve;
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
307 unsigned int packets_size;
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
308 unsigned int current_index;
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
309 } packet_queue_t;
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
310
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
311 static void
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
312 packet_construct(packet_t *pkt)
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
313 {
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
314 pkt->pts100 = 0;
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
315 pkt->filepos = 0;
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
316 pkt->size = 0;
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
317 pkt->data = NULL;
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
318 }
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
319
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
320 static void
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
321 packet_destroy(packet_t *pkt)
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
322 {
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
323 if (pkt->data)
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
324 free(pkt->data);
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
325 }
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
326
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
327 static void
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
328 packet_queue_construct(packet_queue_t *queue)
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
329 {
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
330 queue->id = NULL;
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
331 queue->packets = NULL;
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
332 queue->packets_reserve = 0;
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
333 queue->packets_size = 0;
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
334 queue->current_index = 0;
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
335 }
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
336
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
337 static void
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
338 packet_queue_destroy(packet_queue_t *queue)
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
339 {
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
340 if (queue->packets) {
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
341 while (queue->packets_size--)
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
342 packet_destroy(queue->packets + queue->packets_size);
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
343 free(queue->packets);
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
344 }
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
345 return;
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
346 }
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
347
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
348 /* Make sure there is enough room for needed_size packets in the
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
349 packet queue. */
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
350 static int
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
351 packet_queue_ensure(packet_queue_t *queue, unsigned int needed_size)
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
352 {
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
353 if (queue->packets_reserve < needed_size) {
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
354 if (queue->packets) {
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
355 packet_t *tmp = realloc(queue->packets, 2 * queue->packets_reserve * sizeof(packet_t));
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
356 if (tmp == NULL) {
6110
7bea806b9c5f Improvment for spu subtitles.
albeu
parents: 5869
diff changeset
357 mp_msg(MSGT_VOBSUB,MSGL_FATAL,"realloc failure");
4080
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
358 return -1;
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
359 }
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
360 queue->packets = tmp;
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
361 queue->packets_reserve *= 2;
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
362 }
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
363 else {
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
364 queue->packets = malloc(sizeof(packet_t));
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
365 if (queue->packets == NULL) {
6110
7bea806b9c5f Improvment for spu subtitles.
albeu
parents: 5869
diff changeset
366 mp_msg(MSGT_VOBSUB,MSGL_FATAL,"malloc failure");
4080
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
367 return -1;
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
368 }
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
369 queue->packets_reserve = 1;
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
370 }
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
371 }
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
372 return 0;
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
373 }
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
374
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
375 /* add one more packet */
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
376 static int
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
377 packet_queue_grow(packet_queue_t *queue)
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
378 {
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
379 if (packet_queue_ensure(queue, queue->packets_size + 1) < 0)
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
380 return -1;
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
381 packet_construct(queue->packets + queue->packets_size);
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
382 ++queue->packets_size;
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
383 return 0;
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
384 }
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
385
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
386 /* insert a new packet, duplicating pts from the current one */
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
387 static int
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
388 packet_queue_insert(packet_queue_t *queue)
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
389 {
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
390 packet_t *pkts;
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
391 if (packet_queue_ensure(queue, queue->packets_size + 1) < 0)
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
392 return -1;
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
393 /* XXX packet_size does not reflect the real thing here, it will be updated a bit later */
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
394 memmove(queue->packets + queue->current_index + 2,
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
395 queue->packets + queue->current_index + 1,
4085
dc0a91965b97 Support vobsub without index files.
kmkaplan
parents: 4080
diff changeset
396 sizeof(packet_t) * (queue->packets_size - queue->current_index - 1));
4080
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
397 pkts = queue->packets + queue->current_index;
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
398 ++queue->packets_size;
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
399 ++queue->current_index;
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
400 packet_construct(pkts + 1);
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
401 pkts[1].pts100 = pkts[0].pts100;
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
402 pkts[1].filepos = pkts[0].filepos;
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
403 return 0;
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
404 }
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
405
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
406 /**********************************************************************
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
407 * Vosub
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
408 **********************************************************************/
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
409
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
410 typedef struct {
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
411 unsigned int palette[16];
5833
91d766389a5d VobSub updates, custom palette support and other stuff, can't write the name of the chinese(?) patch supplier.
atmos4
parents: 5563
diff changeset
412 unsigned int cuspal[4];
91d766389a5d VobSub updates, custom palette support and other stuff, can't write the name of the chinese(?) patch supplier.
atmos4
parents: 5563
diff changeset
413 int delay;
91d766389a5d VobSub updates, custom palette support and other stuff, can't write the name of the chinese(?) patch supplier.
atmos4
parents: 5563
diff changeset
414 unsigned int custom;
91d766389a5d VobSub updates, custom palette support and other stuff, can't write the name of the chinese(?) patch supplier.
atmos4
parents: 5563
diff changeset
415 unsigned int have_palette;
5388
3af2729c5c87 * New command line switch for mplayer & mencoder:
kmkaplan
parents: 4787
diff changeset
416 unsigned int orig_frame_width, orig_frame_height;
5563
71372b7125cf Sorry, fix vobsub duration the arpi way.
atmos4
parents: 5388
diff changeset
417 unsigned int origin_x, origin_y;
4080
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
418 /* index */
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
419 packet_queue_t *spu_streams;
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
420 unsigned int spu_streams_size;
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
421 unsigned int spu_streams_current;
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
422 } vobsub_t;
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
423
4085
dc0a91965b97 Support vobsub without index files.
kmkaplan
parents: 4080
diff changeset
424 /* Make sure that the spu stream idx exists. */
4080
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
425 static int
4085
dc0a91965b97 Support vobsub without index files.
kmkaplan
parents: 4080
diff changeset
426 vobsub_ensure_spu_stream(vobsub_t *vob, unsigned int index)
4080
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
427 {
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
428 if (index >= vob->spu_streams_size) {
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
429 /* This is a new stream */
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
430 if (vob->spu_streams) {
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
431 packet_queue_t *tmp = realloc(vob->spu_streams, (index + 1) * sizeof(packet_queue_t));
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
432 if (tmp == NULL) {
6110
7bea806b9c5f Improvment for spu subtitles.
albeu
parents: 5869
diff changeset
433 mp_msg(MSGT_VOBSUB,MSGL_ERR,"vobsub_ensure_spu_stream: realloc failure");
4080
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
434 return -1;
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
435 }
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
436 vob->spu_streams = tmp;
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
437 }
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
438 else {
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
439 vob->spu_streams = malloc((index + 1) * sizeof(packet_queue_t));
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
440 if (vob->spu_streams == NULL) {
6110
7bea806b9c5f Improvment for spu subtitles.
albeu
parents: 5869
diff changeset
441 mp_msg(MSGT_VOBSUB,MSGL_ERR,"vobsub_ensure_spu_stream: malloc failure");
4080
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
442 return -1;
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
443 }
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
444 }
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
445 while (vob->spu_streams_size <= index) {
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
446 packet_queue_construct(vob->spu_streams + vob->spu_streams_size);
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
447 ++vob->spu_streams_size;
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
448 }
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
449 }
4085
dc0a91965b97 Support vobsub without index files.
kmkaplan
parents: 4080
diff changeset
450 return 0;
dc0a91965b97 Support vobsub without index files.
kmkaplan
parents: 4080
diff changeset
451 }
dc0a91965b97 Support vobsub without index files.
kmkaplan
parents: 4080
diff changeset
452
dc0a91965b97 Support vobsub without index files.
kmkaplan
parents: 4080
diff changeset
453 static int
dc0a91965b97 Support vobsub without index files.
kmkaplan
parents: 4080
diff changeset
454 vobsub_add_id(vobsub_t *vob, const char *id, size_t idlen, const unsigned int index)
dc0a91965b97 Support vobsub without index files.
kmkaplan
parents: 4080
diff changeset
455 {
dc0a91965b97 Support vobsub without index files.
kmkaplan
parents: 4080
diff changeset
456 if (vobsub_ensure_spu_stream(vob, index) < 0)
dc0a91965b97 Support vobsub without index files.
kmkaplan
parents: 4080
diff changeset
457 return -1;
4080
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
458 if (id && idlen) {
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
459 if (vob->spu_streams[index].id)
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
460 free(vob->spu_streams[index].id);
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
461 vob->spu_streams[index].id = malloc(idlen + 1);
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
462 if (vob->spu_streams[index].id == NULL) {
6110
7bea806b9c5f Improvment for spu subtitles.
albeu
parents: 5869
diff changeset
463 mp_msg(MSGT_VOBSUB,MSGL_FATAL,"vobsub_add_id: malloc failure");
4080
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
464 return -1;
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
465 }
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
466 vob->spu_streams[index].id[idlen] = 0;
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
467 memcpy(vob->spu_streams[index].id, id, idlen);
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
468 }
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
469 vob->spu_streams_current = index;
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
470 if (verbose)
6110
7bea806b9c5f Improvment for spu subtitles.
albeu
parents: 5869
diff changeset
471 mp_msg(MSGT_VOBSUB,MSGL_V,"[vobsub] subtitle (vobsubid): %d language %s\n",
4080
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
472 index, vob->spu_streams[index].id);
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
473 return 0;
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
474 }
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
475
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
476 static int
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
477 vobsub_add_timestamp(vobsub_t *vob, off_t filepos, unsigned int ms)
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
478 {
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
479 packet_queue_t *queue;
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
480 packet_t *pkt;
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
481 if (vob->spu_streams == 0) {
6110
7bea806b9c5f Improvment for spu subtitles.
albeu
parents: 5869
diff changeset
482 mp_msg(MSGT_VOBSUB,MSGL_WARN,"[vobsub] warning, binning some index entries. Check your index file\n");
4080
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
483 return -1;
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
484 }
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
485 queue = vob->spu_streams + vob->spu_streams_current;
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
486 if (packet_queue_grow(queue) >= 0) {
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
487 pkt = queue->packets + (queue->packets_size - 1);
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
488 pkt->filepos = filepos;
5563
71372b7125cf Sorry, fix vobsub duration the arpi way.
atmos4
parents: 5388
diff changeset
489 pkt->pts100 = ms * 90;
4080
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
490 return 0;
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
491 }
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
492 return -1;
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
493 }
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
494
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
495 static int
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
496 vobsub_parse_id(vobsub_t *vob, const char *line)
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
497 {
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
498 // id: xx, index: n
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
499 size_t idlen;
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
500 const char *p, *q;
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
501 p = line;
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
502 while (isspace(*p))
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
503 ++p;
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
504 q = p;
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
505 while (isalpha(*q))
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
506 ++q;
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
507 idlen = q - p;
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
508 if (idlen == 0)
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
509 return -1;
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
510 ++q;
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
511 while (isspace(*q))
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
512 ++q;
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
513 if (strncmp("index:", q, 6))
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
514 return -1;
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
515 q += 6;
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
516 while (isspace(*q))
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
517 ++q;
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
518 if (!isdigit(*q))
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
519 return -1;
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
520 return vobsub_add_id(vob, p, idlen, atoi(q));
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
521 }
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
522
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
523 static int
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
524 vobsub_parse_timestamp(vobsub_t *vob, const char *line)
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
525 {
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
526 // timestamp: HH:MM:SS.mmm, filepos: 0nnnnnnnnn
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
527 const char *p;
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
528 int h, m, s, ms;
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
529 off_t filepos;
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
530 while (isspace(*line))
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
531 ++line;
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
532 p = line;
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
533 while (isdigit(*p))
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
534 ++p;
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
535 if (p - line != 2)
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
536 return -1;
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
537 h = atoi(line);
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
538 if (*p != ':')
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
539 return -1;
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
540 line = ++p;
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
541 while (isdigit(*p))
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
542 ++p;
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
543 if (p - line != 2)
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
544 return -1;
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
545 m = atoi(line);
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
546 if (*p != ':')
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
547 return -1;
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
548 line = ++p;
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
549 while (isdigit(*p))
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
550 ++p;
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
551 if (p - line != 2)
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
552 return -1;
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
553 s = atoi(line);
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
554 if (*p != ':')
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
555 return -1;
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
556 line = ++p;
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
557 while (isdigit(*p))
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
558 ++p;
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
559 if (p - line != 3)
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
560 return -1;
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
561 ms = atoi(line);
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
562 if (*p != ',')
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
563 return -1;
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
564 line = p + 1;
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
565 while (isspace(*line))
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
566 ++line;
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
567 if (strncmp("filepos:", line, 8))
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
568 return -1;
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
569 line += 8;
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
570 while (isspace(*line))
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
571 ++line;
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
572 if (! isxdigit(*line))
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
573 return -1;
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
574 filepos = strtol(line, NULL, 16);
5833
91d766389a5d VobSub updates, custom palette support and other stuff, can't write the name of the chinese(?) patch supplier.
atmos4
parents: 5563
diff changeset
575 return vobsub_add_timestamp(vob, filepos, vob->delay + ms + 1000 * (s + 60 * (m + 60 * h)));
4080
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
576 }
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
577
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
578 static int
5388
3af2729c5c87 * New command line switch for mplayer & mencoder:
kmkaplan
parents: 4787
diff changeset
579 vobsub_parse_size(vobsub_t *vob, const char *line)
3af2729c5c87 * New command line switch for mplayer & mencoder:
kmkaplan
parents: 4787
diff changeset
580 {
3af2729c5c87 * New command line switch for mplayer & mencoder:
kmkaplan
parents: 4787
diff changeset
581 // size: WWWxHHH
3af2729c5c87 * New command line switch for mplayer & mencoder:
kmkaplan
parents: 4787
diff changeset
582 char *p;
3af2729c5c87 * New command line switch for mplayer & mencoder:
kmkaplan
parents: 4787
diff changeset
583 while (isspace(*line))
3af2729c5c87 * New command line switch for mplayer & mencoder:
kmkaplan
parents: 4787
diff changeset
584 ++line;
3af2729c5c87 * New command line switch for mplayer & mencoder:
kmkaplan
parents: 4787
diff changeset
585 if (!isdigit(*line))
3af2729c5c87 * New command line switch for mplayer & mencoder:
kmkaplan
parents: 4787
diff changeset
586 return -1;
3af2729c5c87 * New command line switch for mplayer & mencoder:
kmkaplan
parents: 4787
diff changeset
587 vob->orig_frame_width = strtoul(line, &p, 10);
3af2729c5c87 * New command line switch for mplayer & mencoder:
kmkaplan
parents: 4787
diff changeset
588 if (*p != 'x')
3af2729c5c87 * New command line switch for mplayer & mencoder:
kmkaplan
parents: 4787
diff changeset
589 return -1;
3af2729c5c87 * New command line switch for mplayer & mencoder:
kmkaplan
parents: 4787
diff changeset
590 ++p;
3af2729c5c87 * New command line switch for mplayer & mencoder:
kmkaplan
parents: 4787
diff changeset
591 vob->orig_frame_height = strtoul(p, NULL, 10);
3af2729c5c87 * New command line switch for mplayer & mencoder:
kmkaplan
parents: 4787
diff changeset
592 return 0;
3af2729c5c87 * New command line switch for mplayer & mencoder:
kmkaplan
parents: 4787
diff changeset
593 }
3af2729c5c87 * New command line switch for mplayer & mencoder:
kmkaplan
parents: 4787
diff changeset
594
3af2729c5c87 * New command line switch for mplayer & mencoder:
kmkaplan
parents: 4787
diff changeset
595 static int
5563
71372b7125cf Sorry, fix vobsub duration the arpi way.
atmos4
parents: 5388
diff changeset
596 vobsub_parse_origin(vobsub_t *vob, const char *line)
71372b7125cf Sorry, fix vobsub duration the arpi way.
atmos4
parents: 5388
diff changeset
597 {
71372b7125cf Sorry, fix vobsub duration the arpi way.
atmos4
parents: 5388
diff changeset
598 // org: X,Y
71372b7125cf Sorry, fix vobsub duration the arpi way.
atmos4
parents: 5388
diff changeset
599 char *p;
71372b7125cf Sorry, fix vobsub duration the arpi way.
atmos4
parents: 5388
diff changeset
600 while (isspace(*line))
71372b7125cf Sorry, fix vobsub duration the arpi way.
atmos4
parents: 5388
diff changeset
601 ++line;
71372b7125cf Sorry, fix vobsub duration the arpi way.
atmos4
parents: 5388
diff changeset
602 if (!isdigit(*line))
71372b7125cf Sorry, fix vobsub duration the arpi way.
atmos4
parents: 5388
diff changeset
603 return -1;
71372b7125cf Sorry, fix vobsub duration the arpi way.
atmos4
parents: 5388
diff changeset
604 vob->origin_x = strtoul(line, &p, 10);
71372b7125cf Sorry, fix vobsub duration the arpi way.
atmos4
parents: 5388
diff changeset
605 if (*p != ',')
71372b7125cf Sorry, fix vobsub duration the arpi way.
atmos4
parents: 5388
diff changeset
606 return -1;
71372b7125cf Sorry, fix vobsub duration the arpi way.
atmos4
parents: 5388
diff changeset
607 ++p;
71372b7125cf Sorry, fix vobsub duration the arpi way.
atmos4
parents: 5388
diff changeset
608 vob->origin_y = strtoul(p, NULL, 10);
71372b7125cf Sorry, fix vobsub duration the arpi way.
atmos4
parents: 5388
diff changeset
609 return 0;
71372b7125cf Sorry, fix vobsub duration the arpi way.
atmos4
parents: 5388
diff changeset
610 }
71372b7125cf Sorry, fix vobsub duration the arpi way.
atmos4
parents: 5388
diff changeset
611
71372b7125cf Sorry, fix vobsub duration the arpi way.
atmos4
parents: 5388
diff changeset
612 static int
5388
3af2729c5c87 * New command line switch for mplayer & mencoder:
kmkaplan
parents: 4787
diff changeset
613 vobsub_parse_palette(vobsub_t *vob, const char *line)
3af2729c5c87 * New command line switch for mplayer & mencoder:
kmkaplan
parents: 4787
diff changeset
614 {
3af2729c5c87 * New command line switch for mplayer & mencoder:
kmkaplan
parents: 4787
diff changeset
615 // palette: XXXXXX, XXXXXX, XXXXXX, XXXXXX, XXXXXX, XXXXXX, XXXXXX, XXXXXX, XXXXXX, XXXXXX, XXXXXX, XXXXXX, XXXXXX, XXXXXX, XXXXXX, XXXXXX
3af2729c5c87 * New command line switch for mplayer & mencoder:
kmkaplan
parents: 4787
diff changeset
616 unsigned int n;
3af2729c5c87 * New command line switch for mplayer & mencoder:
kmkaplan
parents: 4787
diff changeset
617 n = 0;
3af2729c5c87 * New command line switch for mplayer & mencoder:
kmkaplan
parents: 4787
diff changeset
618 while (1) {
3af2729c5c87 * New command line switch for mplayer & mencoder:
kmkaplan
parents: 4787
diff changeset
619 const char *p;
3af2729c5c87 * New command line switch for mplayer & mencoder:
kmkaplan
parents: 4787
diff changeset
620 while (isspace(*line))
3af2729c5c87 * New command line switch for mplayer & mencoder:
kmkaplan
parents: 4787
diff changeset
621 ++line;
3af2729c5c87 * New command line switch for mplayer & mencoder:
kmkaplan
parents: 4787
diff changeset
622 p = line;
3af2729c5c87 * New command line switch for mplayer & mencoder:
kmkaplan
parents: 4787
diff changeset
623 while (isxdigit(*p))
3af2729c5c87 * New command line switch for mplayer & mencoder:
kmkaplan
parents: 4787
diff changeset
624 ++p;
3af2729c5c87 * New command line switch for mplayer & mencoder:
kmkaplan
parents: 4787
diff changeset
625 if (p - line != 6)
3af2729c5c87 * New command line switch for mplayer & mencoder:
kmkaplan
parents: 4787
diff changeset
626 return -1;
3af2729c5c87 * New command line switch for mplayer & mencoder:
kmkaplan
parents: 4787
diff changeset
627 vob->palette[n++] = strtoul(line, NULL, 16);
3af2729c5c87 * New command line switch for mplayer & mencoder:
kmkaplan
parents: 4787
diff changeset
628 if (n == 16)
3af2729c5c87 * New command line switch for mplayer & mencoder:
kmkaplan
parents: 4787
diff changeset
629 break;
3af2729c5c87 * New command line switch for mplayer & mencoder:
kmkaplan
parents: 4787
diff changeset
630 if (*p == ',')
3af2729c5c87 * New command line switch for mplayer & mencoder:
kmkaplan
parents: 4787
diff changeset
631 ++p;
3af2729c5c87 * New command line switch for mplayer & mencoder:
kmkaplan
parents: 4787
diff changeset
632 line = p;
3af2729c5c87 * New command line switch for mplayer & mencoder:
kmkaplan
parents: 4787
diff changeset
633 }
5833
91d766389a5d VobSub updates, custom palette support and other stuff, can't write the name of the chinese(?) patch supplier.
atmos4
parents: 5563
diff changeset
634 vob->have_palette = 1;
91d766389a5d VobSub updates, custom palette support and other stuff, can't write the name of the chinese(?) patch supplier.
atmos4
parents: 5563
diff changeset
635 return 0;
91d766389a5d VobSub updates, custom palette support and other stuff, can't write the name of the chinese(?) patch supplier.
atmos4
parents: 5563
diff changeset
636 }
91d766389a5d VobSub updates, custom palette support and other stuff, can't write the name of the chinese(?) patch supplier.
atmos4
parents: 5563
diff changeset
637
91d766389a5d VobSub updates, custom palette support and other stuff, can't write the name of the chinese(?) patch supplier.
atmos4
parents: 5563
diff changeset
638 static int
91d766389a5d VobSub updates, custom palette support and other stuff, can't write the name of the chinese(?) patch supplier.
atmos4
parents: 5563
diff changeset
639 vobsub_parse_custom(vobsub_t *vob, const char *line)
91d766389a5d VobSub updates, custom palette support and other stuff, can't write the name of the chinese(?) patch supplier.
atmos4
parents: 5563
diff changeset
640 {
91d766389a5d VobSub updates, custom palette support and other stuff, can't write the name of the chinese(?) patch supplier.
atmos4
parents: 5563
diff changeset
641 //custom colors: OFF/ON(0/1)
5839
80af8b0589e1 Fix bug in LR's patch.
atmos4
parents: 5833
diff changeset
642 if ((strncmp("ON", line + 15, 2) == 0)||strncmp("1", line + 15, 1) == 0)
5833
91d766389a5d VobSub updates, custom palette support and other stuff, can't write the name of the chinese(?) patch supplier.
atmos4
parents: 5563
diff changeset
643 vob->custom=1;
5839
80af8b0589e1 Fix bug in LR's patch.
atmos4
parents: 5833
diff changeset
644 else if ((strncmp("OFF", line + 15, 3) == 0)||strncmp("0", line + 15, 1) == 0)
5833
91d766389a5d VobSub updates, custom palette support and other stuff, can't write the name of the chinese(?) patch supplier.
atmos4
parents: 5563
diff changeset
645 vob->custom=0;
91d766389a5d VobSub updates, custom palette support and other stuff, can't write the name of the chinese(?) patch supplier.
atmos4
parents: 5563
diff changeset
646 else
91d766389a5d VobSub updates, custom palette support and other stuff, can't write the name of the chinese(?) patch supplier.
atmos4
parents: 5563
diff changeset
647 return -1;
91d766389a5d VobSub updates, custom palette support and other stuff, can't write the name of the chinese(?) patch supplier.
atmos4
parents: 5563
diff changeset
648 return 0;
91d766389a5d VobSub updates, custom palette support and other stuff, can't write the name of the chinese(?) patch supplier.
atmos4
parents: 5563
diff changeset
649 }
91d766389a5d VobSub updates, custom palette support and other stuff, can't write the name of the chinese(?) patch supplier.
atmos4
parents: 5563
diff changeset
650
91d766389a5d VobSub updates, custom palette support and other stuff, can't write the name of the chinese(?) patch supplier.
atmos4
parents: 5563
diff changeset
651 static int
91d766389a5d VobSub updates, custom palette support and other stuff, can't write the name of the chinese(?) patch supplier.
atmos4
parents: 5563
diff changeset
652 vobsub_parse_cuspal(vobsub_t *vob, const char *line)
91d766389a5d VobSub updates, custom palette support and other stuff, can't write the name of the chinese(?) patch supplier.
atmos4
parents: 5563
diff changeset
653 {
91d766389a5d VobSub updates, custom palette support and other stuff, can't write the name of the chinese(?) patch supplier.
atmos4
parents: 5563
diff changeset
654 //colors: XXXXXX, XXXXXX, XXXXXX, XXXXXX
91d766389a5d VobSub updates, custom palette support and other stuff, can't write the name of the chinese(?) patch supplier.
atmos4
parents: 5563
diff changeset
655 unsigned int n;
91d766389a5d VobSub updates, custom palette support and other stuff, can't write the name of the chinese(?) patch supplier.
atmos4
parents: 5563
diff changeset
656 n = 0;
91d766389a5d VobSub updates, custom palette support and other stuff, can't write the name of the chinese(?) patch supplier.
atmos4
parents: 5563
diff changeset
657 line += 40;
91d766389a5d VobSub updates, custom palette support and other stuff, can't write the name of the chinese(?) patch supplier.
atmos4
parents: 5563
diff changeset
658 while(1){
91d766389a5d VobSub updates, custom palette support and other stuff, can't write the name of the chinese(?) patch supplier.
atmos4
parents: 5563
diff changeset
659 const char *p;
91d766389a5d VobSub updates, custom palette support and other stuff, can't write the name of the chinese(?) patch supplier.
atmos4
parents: 5563
diff changeset
660 while (isspace(*line))
91d766389a5d VobSub updates, custom palette support and other stuff, can't write the name of the chinese(?) patch supplier.
atmos4
parents: 5563
diff changeset
661 ++line;
91d766389a5d VobSub updates, custom palette support and other stuff, can't write the name of the chinese(?) patch supplier.
atmos4
parents: 5563
diff changeset
662 p=line;
91d766389a5d VobSub updates, custom palette support and other stuff, can't write the name of the chinese(?) patch supplier.
atmos4
parents: 5563
diff changeset
663 while (isxdigit(*p))
91d766389a5d VobSub updates, custom palette support and other stuff, can't write the name of the chinese(?) patch supplier.
atmos4
parents: 5563
diff changeset
664 ++p;
91d766389a5d VobSub updates, custom palette support and other stuff, can't write the name of the chinese(?) patch supplier.
atmos4
parents: 5563
diff changeset
665 if (p - line !=6)
91d766389a5d VobSub updates, custom palette support and other stuff, can't write the name of the chinese(?) patch supplier.
atmos4
parents: 5563
diff changeset
666 return -1;
91d766389a5d VobSub updates, custom palette support and other stuff, can't write the name of the chinese(?) patch supplier.
atmos4
parents: 5563
diff changeset
667 vob->cuspal[n++] = strtoul(line, NULL,16);
91d766389a5d VobSub updates, custom palette support and other stuff, can't write the name of the chinese(?) patch supplier.
atmos4
parents: 5563
diff changeset
668 if (n==4)
91d766389a5d VobSub updates, custom palette support and other stuff, can't write the name of the chinese(?) patch supplier.
atmos4
parents: 5563
diff changeset
669 break;
91d766389a5d VobSub updates, custom palette support and other stuff, can't write the name of the chinese(?) patch supplier.
atmos4
parents: 5563
diff changeset
670 if(*p == ',')
91d766389a5d VobSub updates, custom palette support and other stuff, can't write the name of the chinese(?) patch supplier.
atmos4
parents: 5563
diff changeset
671 ++p;
91d766389a5d VobSub updates, custom palette support and other stuff, can't write the name of the chinese(?) patch supplier.
atmos4
parents: 5563
diff changeset
672 line = p;
91d766389a5d VobSub updates, custom palette support and other stuff, can't write the name of the chinese(?) patch supplier.
atmos4
parents: 5563
diff changeset
673 }
91d766389a5d VobSub updates, custom palette support and other stuff, can't write the name of the chinese(?) patch supplier.
atmos4
parents: 5563
diff changeset
674 return 0;
91d766389a5d VobSub updates, custom palette support and other stuff, can't write the name of the chinese(?) patch supplier.
atmos4
parents: 5563
diff changeset
675 }
91d766389a5d VobSub updates, custom palette support and other stuff, can't write the name of the chinese(?) patch supplier.
atmos4
parents: 5563
diff changeset
676
91d766389a5d VobSub updates, custom palette support and other stuff, can't write the name of the chinese(?) patch supplier.
atmos4
parents: 5563
diff changeset
677 /* don't know how to use tridx */
91d766389a5d VobSub updates, custom palette support and other stuff, can't write the name of the chinese(?) patch supplier.
atmos4
parents: 5563
diff changeset
678 static int
6110
7bea806b9c5f Improvment for spu subtitles.
albeu
parents: 5869
diff changeset
679 vobsub_parse_tridx(const char *line)
5833
91d766389a5d VobSub updates, custom palette support and other stuff, can't write the name of the chinese(?) patch supplier.
atmos4
parents: 5563
diff changeset
680 {
91d766389a5d VobSub updates, custom palette support and other stuff, can't write the name of the chinese(?) patch supplier.
atmos4
parents: 5563
diff changeset
681 //tridx: XXXX
91d766389a5d VobSub updates, custom palette support and other stuff, can't write the name of the chinese(?) patch supplier.
atmos4
parents: 5563
diff changeset
682 int tridx;
91d766389a5d VobSub updates, custom palette support and other stuff, can't write the name of the chinese(?) patch supplier.
atmos4
parents: 5563
diff changeset
683 tridx = strtoul((line + 26), NULL, 16);
91d766389a5d VobSub updates, custom palette support and other stuff, can't write the name of the chinese(?) patch supplier.
atmos4
parents: 5563
diff changeset
684 tridx = ((tridx&0x1000)>>12) | ((tridx&0x100)>>7) | ((tridx&0x10)>>2) | ((tridx&1)<<3);
6110
7bea806b9c5f Improvment for spu subtitles.
albeu
parents: 5869
diff changeset
685 return tridx;
5833
91d766389a5d VobSub updates, custom palette support and other stuff, can't write the name of the chinese(?) patch supplier.
atmos4
parents: 5563
diff changeset
686 }
91d766389a5d VobSub updates, custom palette support and other stuff, can't write the name of the chinese(?) patch supplier.
atmos4
parents: 5563
diff changeset
687
91d766389a5d VobSub updates, custom palette support and other stuff, can't write the name of the chinese(?) patch supplier.
atmos4
parents: 5563
diff changeset
688 static int
91d766389a5d VobSub updates, custom palette support and other stuff, can't write the name of the chinese(?) patch supplier.
atmos4
parents: 5563
diff changeset
689 vobsub_parse_delay(vobsub_t *vob, const char *line)
91d766389a5d VobSub updates, custom palette support and other stuff, can't write the name of the chinese(?) patch supplier.
atmos4
parents: 5563
diff changeset
690 {
91d766389a5d VobSub updates, custom palette support and other stuff, can't write the name of the chinese(?) patch supplier.
atmos4
parents: 5563
diff changeset
691 int h, m, s, ms;
91d766389a5d VobSub updates, custom palette support and other stuff, can't write the name of the chinese(?) patch supplier.
atmos4
parents: 5563
diff changeset
692 int forward = 1;
91d766389a5d VobSub updates, custom palette support and other stuff, can't write the name of the chinese(?) patch supplier.
atmos4
parents: 5563
diff changeset
693 if (*(line + 7) == '+'){
91d766389a5d VobSub updates, custom palette support and other stuff, can't write the name of the chinese(?) patch supplier.
atmos4
parents: 5563
diff changeset
694 forward = 1;
91d766389a5d VobSub updates, custom palette support and other stuff, can't write the name of the chinese(?) patch supplier.
atmos4
parents: 5563
diff changeset
695 line++;
91d766389a5d VobSub updates, custom palette support and other stuff, can't write the name of the chinese(?) patch supplier.
atmos4
parents: 5563
diff changeset
696 }
91d766389a5d VobSub updates, custom palette support and other stuff, can't write the name of the chinese(?) patch supplier.
atmos4
parents: 5563
diff changeset
697 else if (*(line + 7) == '-'){
91d766389a5d VobSub updates, custom palette support and other stuff, can't write the name of the chinese(?) patch supplier.
atmos4
parents: 5563
diff changeset
698 forward = -1;
91d766389a5d VobSub updates, custom palette support and other stuff, can't write the name of the chinese(?) patch supplier.
atmos4
parents: 5563
diff changeset
699 line++;
91d766389a5d VobSub updates, custom palette support and other stuff, can't write the name of the chinese(?) patch supplier.
atmos4
parents: 5563
diff changeset
700 }
6110
7bea806b9c5f Improvment for spu subtitles.
albeu
parents: 5869
diff changeset
701 mp_msg(MSGT_SPUDEC,MSGL_V, "forward=%d", forward);
5833
91d766389a5d VobSub updates, custom palette support and other stuff, can't write the name of the chinese(?) patch supplier.
atmos4
parents: 5563
diff changeset
702 h = atoi(line + 7);
6110
7bea806b9c5f Improvment for spu subtitles.
albeu
parents: 5869
diff changeset
703 mp_msg(MSGT_VOBSUB,MSGL_V, "h=%d," ,h);
5833
91d766389a5d VobSub updates, custom palette support and other stuff, can't write the name of the chinese(?) patch supplier.
atmos4
parents: 5563
diff changeset
704 m = atoi(line + 10);
6110
7bea806b9c5f Improvment for spu subtitles.
albeu
parents: 5869
diff changeset
705 mp_msg(MSGT_VOBSUB,MSGL_V, "m=%d,", m);
5833
91d766389a5d VobSub updates, custom palette support and other stuff, can't write the name of the chinese(?) patch supplier.
atmos4
parents: 5563
diff changeset
706 s = atoi(line + 13);
6110
7bea806b9c5f Improvment for spu subtitles.
albeu
parents: 5869
diff changeset
707 mp_msg(MSGT_VOBSUB,MSGL_V, "s=%d,", s);
5833
91d766389a5d VobSub updates, custom palette support and other stuff, can't write the name of the chinese(?) patch supplier.
atmos4
parents: 5563
diff changeset
708 ms = atoi(line + 16);
6110
7bea806b9c5f Improvment for spu subtitles.
albeu
parents: 5869
diff changeset
709 mp_msg(MSGT_VOBSUB,MSGL_V, "ms=%d", ms);
5833
91d766389a5d VobSub updates, custom palette support and other stuff, can't write the name of the chinese(?) patch supplier.
atmos4
parents: 5563
diff changeset
710 vob->delay = ms + 1000 * (s + 60 * (m + 60 * h)) * forward;
91d766389a5d VobSub updates, custom palette support and other stuff, can't write the name of the chinese(?) patch supplier.
atmos4
parents: 5563
diff changeset
711 return 0;
91d766389a5d VobSub updates, custom palette support and other stuff, can't write the name of the chinese(?) patch supplier.
atmos4
parents: 5563
diff changeset
712 }
91d766389a5d VobSub updates, custom palette support and other stuff, can't write the name of the chinese(?) patch supplier.
atmos4
parents: 5563
diff changeset
713
91d766389a5d VobSub updates, custom palette support and other stuff, can't write the name of the chinese(?) patch supplier.
atmos4
parents: 5563
diff changeset
714 static int
6110
7bea806b9c5f Improvment for spu subtitles.
albeu
parents: 5869
diff changeset
715 vobsub_set_lang(const char *line)
5833
91d766389a5d VobSub updates, custom palette support and other stuff, can't write the name of the chinese(?) patch supplier.
atmos4
parents: 5563
diff changeset
716 {
91d766389a5d VobSub updates, custom palette support and other stuff, can't write the name of the chinese(?) patch supplier.
atmos4
parents: 5563
diff changeset
717 if (vobsub_id == -1)
91d766389a5d VobSub updates, custom palette support and other stuff, can't write the name of the chinese(?) patch supplier.
atmos4
parents: 5563
diff changeset
718 vobsub_id = atoi(line + 8);
5388
3af2729c5c87 * New command line switch for mplayer & mencoder:
kmkaplan
parents: 4787
diff changeset
719 return 0;
3af2729c5c87 * New command line switch for mplayer & mencoder:
kmkaplan
parents: 4787
diff changeset
720 }
3af2729c5c87 * New command line switch for mplayer & mencoder:
kmkaplan
parents: 4787
diff changeset
721
3af2729c5c87 * New command line switch for mplayer & mencoder:
kmkaplan
parents: 4787
diff changeset
722 static int
4080
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
723 vobsub_parse_one_line(vobsub_t *vob, FILE *fd)
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
724 {
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
725 ssize_t line_size;
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
726 int res = -1;
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
727 do {
6163
141a082e6da6 applied 64bit patch from Ulrich Hecht <uli at suse dot de>
alex
parents: 6110
diff changeset
728 size_t line_reserve = 0;
4080
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
729 char *line = NULL;
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
730 line_size = getline(&line, &line_reserve, fd);
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
731 if (line_size < 0) {
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
732 if (line)
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
733 free(line);
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
734 break;
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
735 }
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
736 if (*line == 0 || *line == '\r' || *line == '\n' || *line == '#')
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
737 continue;
5833
91d766389a5d VobSub updates, custom palette support and other stuff, can't write the name of the chinese(?) patch supplier.
atmos4
parents: 5563
diff changeset
738 else if (strncmp("langidx:", line, 8) == 0)
6110
7bea806b9c5f Improvment for spu subtitles.
albeu
parents: 5869
diff changeset
739 res = vobsub_set_lang(line);
5833
91d766389a5d VobSub updates, custom palette support and other stuff, can't write the name of the chinese(?) patch supplier.
atmos4
parents: 5563
diff changeset
740 else if (strncmp("delay:", line, 6) == 0)
91d766389a5d VobSub updates, custom palette support and other stuff, can't write the name of the chinese(?) patch supplier.
atmos4
parents: 5563
diff changeset
741 res = vobsub_parse_delay(vob, line);
4080
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
742 else if (strncmp("id:", line, 3) == 0)
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
743 res = vobsub_parse_id(vob, line + 3);
5388
3af2729c5c87 * New command line switch for mplayer & mencoder:
kmkaplan
parents: 4787
diff changeset
744 else if (strncmp("palette:", line, 8) == 0)
3af2729c5c87 * New command line switch for mplayer & mencoder:
kmkaplan
parents: 4787
diff changeset
745 res = vobsub_parse_palette(vob, line + 8);
3af2729c5c87 * New command line switch for mplayer & mencoder:
kmkaplan
parents: 4787
diff changeset
746 else if (strncmp("size:", line, 5) == 0)
3af2729c5c87 * New command line switch for mplayer & mencoder:
kmkaplan
parents: 4787
diff changeset
747 res = vobsub_parse_size(vob, line + 5);
5563
71372b7125cf Sorry, fix vobsub duration the arpi way.
atmos4
parents: 5388
diff changeset
748 else if (strncmp("org:", line, 4) == 0)
71372b7125cf Sorry, fix vobsub duration the arpi way.
atmos4
parents: 5388
diff changeset
749 res = vobsub_parse_origin(vob, line + 4);
4080
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
750 else if (strncmp("timestamp:", line, 10) == 0)
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
751 res = vobsub_parse_timestamp(vob, line + 10);
5833
91d766389a5d VobSub updates, custom palette support and other stuff, can't write the name of the chinese(?) patch supplier.
atmos4
parents: 5563
diff changeset
752 else if (strncmp("custom colors:", line, 14) == 0)
91d766389a5d VobSub updates, custom palette support and other stuff, can't write the name of the chinese(?) patch supplier.
atmos4
parents: 5563
diff changeset
753 //custom colors: ON/OFF, tridx: XXXX, colors: XXXXXX, XXXXXX, XXXXXX,XXXXXX
6110
7bea806b9c5f Improvment for spu subtitles.
albeu
parents: 5869
diff changeset
754 res = vobsub_parse_cuspal(vob, line) + vobsub_parse_tridx(line) + vobsub_parse_custom(vob, line);
4080
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
755 else {
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
756 if (verbose)
6110
7bea806b9c5f Improvment for spu subtitles.
albeu
parents: 5869
diff changeset
757 mp_msg(MSGT_VOBSUB,MSGL_V, "vobsub: ignoring %s", line);
4080
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
758 continue;
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
759 }
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
760 if (res < 0)
6110
7bea806b9c5f Improvment for spu subtitles.
albeu
parents: 5869
diff changeset
761 mp_msg(MSGT_VOBSUB,MSGL_ERR, "ERROR in %s", line);
4080
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
762 break;
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
763 } while (1);
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
764 return res;
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
765 }
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
766
5388
3af2729c5c87 * New command line switch for mplayer & mencoder:
kmkaplan
parents: 4787
diff changeset
767 int
6110
7bea806b9c5f Improvment for spu subtitles.
albeu
parents: 5869
diff changeset
768 vobsub_parse_ifo(void* this, const char *const name, unsigned int *palette, unsigned int *width, unsigned int *height, int force)
5388
3af2729c5c87 * New command line switch for mplayer & mencoder:
kmkaplan
parents: 4787
diff changeset
769 {
6110
7bea806b9c5f Improvment for spu subtitles.
albeu
parents: 5869
diff changeset
770 vobsub_t *vob = (vobsub_t*)this;
5388
3af2729c5c87 * New command line switch for mplayer & mencoder:
kmkaplan
parents: 4787
diff changeset
771 int res = -1;
3af2729c5c87 * New command line switch for mplayer & mencoder:
kmkaplan
parents: 4787
diff changeset
772 FILE *fd = fopen(name, "rb");
5869
412ff784c971 Avoid bogus file not found message if vobsub isn'T forced (autodetect).
atmos4
parents: 5839
diff changeset
773 if (fd == NULL) {
412ff784c971 Avoid bogus file not found message if vobsub isn'T forced (autodetect).
atmos4
parents: 5839
diff changeset
774 if (force)
6110
7bea806b9c5f Improvment for spu subtitles.
albeu
parents: 5869
diff changeset
775 mp_msg(MSGT_VOBSUB,MSGL_ERR, "Can't open IFO file");
5869
412ff784c971 Avoid bogus file not found message if vobsub isn'T forced (autodetect).
atmos4
parents: 5839
diff changeset
776 } else {
5388
3af2729c5c87 * New command line switch for mplayer & mencoder:
kmkaplan
parents: 4787
diff changeset
777 // parse IFO header
3af2729c5c87 * New command line switch for mplayer & mencoder:
kmkaplan
parents: 4787
diff changeset
778 unsigned char block[0x800];
3af2729c5c87 * New command line switch for mplayer & mencoder:
kmkaplan
parents: 4787
diff changeset
779 const char *const ifo_magic = "DVDVIDEO-VTS";
3af2729c5c87 * New command line switch for mplayer & mencoder:
kmkaplan
parents: 4787
diff changeset
780 if (fread(block, sizeof(block), 1, fd) != 1) {
3af2729c5c87 * New command line switch for mplayer & mencoder:
kmkaplan
parents: 4787
diff changeset
781 if (force)
6110
7bea806b9c5f Improvment for spu subtitles.
albeu
parents: 5869
diff changeset
782 mp_msg(MSGT_VOBSUB,MSGL_ERR, "Can't read IFO header");
5388
3af2729c5c87 * New command line switch for mplayer & mencoder:
kmkaplan
parents: 4787
diff changeset
783 } else if (memcmp(block, ifo_magic, strlen(ifo_magic) + 1))
6110
7bea806b9c5f Improvment for spu subtitles.
albeu
parents: 5869
diff changeset
784 mp_msg(MSGT_VOBSUB,MSGL_ERR, "Bad magic in IFO header\n");
5388
3af2729c5c87 * New command line switch for mplayer & mencoder:
kmkaplan
parents: 4787
diff changeset
785 else {
3af2729c5c87 * New command line switch for mplayer & mencoder:
kmkaplan
parents: 4787
diff changeset
786 unsigned long pgci_sector = block[0xcc] << 24 | block[0xcd] << 16
3af2729c5c87 * New command line switch for mplayer & mencoder:
kmkaplan
parents: 4787
diff changeset
787 | block[0xce] << 8 | block[0xcf];
3af2729c5c87 * New command line switch for mplayer & mencoder:
kmkaplan
parents: 4787
diff changeset
788 int standard = (block[0x200] & 0x30) >> 4;
3af2729c5c87 * New command line switch for mplayer & mencoder:
kmkaplan
parents: 4787
diff changeset
789 int resolution = (block[0x201] & 0x0c) >> 2;
3af2729c5c87 * New command line switch for mplayer & mencoder:
kmkaplan
parents: 4787
diff changeset
790 *height = standard ? 576 : 480;
3af2729c5c87 * New command line switch for mplayer & mencoder:
kmkaplan
parents: 4787
diff changeset
791 *width = 0;
3af2729c5c87 * New command line switch for mplayer & mencoder:
kmkaplan
parents: 4787
diff changeset
792 switch (resolution) {
3af2729c5c87 * New command line switch for mplayer & mencoder:
kmkaplan
parents: 4787
diff changeset
793 case 0x0:
3af2729c5c87 * New command line switch for mplayer & mencoder:
kmkaplan
parents: 4787
diff changeset
794 *width = 720;
3af2729c5c87 * New command line switch for mplayer & mencoder:
kmkaplan
parents: 4787
diff changeset
795 break;
3af2729c5c87 * New command line switch for mplayer & mencoder:
kmkaplan
parents: 4787
diff changeset
796 case 0x1:
3af2729c5c87 * New command line switch for mplayer & mencoder:
kmkaplan
parents: 4787
diff changeset
797 *width = 704;
3af2729c5c87 * New command line switch for mplayer & mencoder:
kmkaplan
parents: 4787
diff changeset
798 break;
3af2729c5c87 * New command line switch for mplayer & mencoder:
kmkaplan
parents: 4787
diff changeset
799 case 0x2:
3af2729c5c87 * New command line switch for mplayer & mencoder:
kmkaplan
parents: 4787
diff changeset
800 *width = 352;
3af2729c5c87 * New command line switch for mplayer & mencoder:
kmkaplan
parents: 4787
diff changeset
801 break;
3af2729c5c87 * New command line switch for mplayer & mencoder:
kmkaplan
parents: 4787
diff changeset
802 case 0x3:
3af2729c5c87 * New command line switch for mplayer & mencoder:
kmkaplan
parents: 4787
diff changeset
803 *width = 352;
3af2729c5c87 * New command line switch for mplayer & mencoder:
kmkaplan
parents: 4787
diff changeset
804 *height /= 2;
3af2729c5c87 * New command line switch for mplayer & mencoder:
kmkaplan
parents: 4787
diff changeset
805 break;
3af2729c5c87 * New command line switch for mplayer & mencoder:
kmkaplan
parents: 4787
diff changeset
806 default:
6110
7bea806b9c5f Improvment for spu subtitles.
albeu
parents: 5869
diff changeset
807 mp_msg(MSGT_VOBSUB,MSGL_WARN,"Vobsub: Unknown resolution %d \n", resolution);
5388
3af2729c5c87 * New command line switch for mplayer & mencoder:
kmkaplan
parents: 4787
diff changeset
808 }
3af2729c5c87 * New command line switch for mplayer & mencoder:
kmkaplan
parents: 4787
diff changeset
809 if (fseek(fd, pgci_sector * sizeof(block), SEEK_SET)
3af2729c5c87 * New command line switch for mplayer & mencoder:
kmkaplan
parents: 4787
diff changeset
810 || fread(block, sizeof(block), 1, fd) != 1)
6110
7bea806b9c5f Improvment for spu subtitles.
albeu
parents: 5869
diff changeset
811 mp_msg(MSGT_VOBSUB,MSGL_ERR, "Can't read IFO PGCI");
5388
3af2729c5c87 * New command line switch for mplayer & mencoder:
kmkaplan
parents: 4787
diff changeset
812 else {
3af2729c5c87 * New command line switch for mplayer & mencoder:
kmkaplan
parents: 4787
diff changeset
813 unsigned long idx;
3af2729c5c87 * New command line switch for mplayer & mencoder:
kmkaplan
parents: 4787
diff changeset
814 unsigned long pgc_offset = block[0xc] << 24 | block[0xd] << 16
3af2729c5c87 * New command line switch for mplayer & mencoder:
kmkaplan
parents: 4787
diff changeset
815 | block[0xe] << 8 | block[0xf];
3af2729c5c87 * New command line switch for mplayer & mencoder:
kmkaplan
parents: 4787
diff changeset
816 for (idx = 0; idx < 16; ++idx) {
3af2729c5c87 * New command line switch for mplayer & mencoder:
kmkaplan
parents: 4787
diff changeset
817 unsigned char *p = block + pgc_offset + 0xa4 + 4 * idx;
3af2729c5c87 * New command line switch for mplayer & mencoder:
kmkaplan
parents: 4787
diff changeset
818 palette[idx] = p[0] << 24 | p[1] << 16 | p[2] << 8 | p[3];
3af2729c5c87 * New command line switch for mplayer & mencoder:
kmkaplan
parents: 4787
diff changeset
819 }
6110
7bea806b9c5f Improvment for spu subtitles.
albeu
parents: 5869
diff changeset
820 if(vob)
7bea806b9c5f Improvment for spu subtitles.
albeu
parents: 5869
diff changeset
821 vob->have_palette = 1;
5388
3af2729c5c87 * New command line switch for mplayer & mencoder:
kmkaplan
parents: 4787
diff changeset
822 res = 0;
3af2729c5c87 * New command line switch for mplayer & mencoder:
kmkaplan
parents: 4787
diff changeset
823 }
3af2729c5c87 * New command line switch for mplayer & mencoder:
kmkaplan
parents: 4787
diff changeset
824 }
3af2729c5c87 * New command line switch for mplayer & mencoder:
kmkaplan
parents: 4787
diff changeset
825 fclose(fd);
3af2729c5c87 * New command line switch for mplayer & mencoder:
kmkaplan
parents: 4787
diff changeset
826 }
3af2729c5c87 * New command line switch for mplayer & mencoder:
kmkaplan
parents: 4787
diff changeset
827 return res;
3af2729c5c87 * New command line switch for mplayer & mencoder:
kmkaplan
parents: 4787
diff changeset
828 }
3af2729c5c87 * New command line switch for mplayer & mencoder:
kmkaplan
parents: 4787
diff changeset
829
4080
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
830 void *
6110
7bea806b9c5f Improvment for spu subtitles.
albeu
parents: 5869
diff changeset
831 vobsub_open(const char *const name,const char *const ifo,const int force,void** spu)
4080
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
832 {
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
833 vobsub_t *vob = malloc(sizeof(vobsub_t));
6110
7bea806b9c5f Improvment for spu subtitles.
albeu
parents: 5869
diff changeset
834 if(spu)
7bea806b9c5f Improvment for spu subtitles.
albeu
parents: 5869
diff changeset
835 *spu = NULL;
4080
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
836 if (vob) {
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
837 char *buf;
5388
3af2729c5c87 * New command line switch for mplayer & mencoder:
kmkaplan
parents: 4787
diff changeset
838 vob->orig_frame_width = 0;
3af2729c5c87 * New command line switch for mplayer & mencoder:
kmkaplan
parents: 4787
diff changeset
839 vob->orig_frame_height = 0;
4080
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
840 vob->spu_streams = NULL;
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
841 vob->spu_streams_size = 0;
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
842 vob->spu_streams_current = 0;
5833
91d766389a5d VobSub updates, custom palette support and other stuff, can't write the name of the chinese(?) patch supplier.
atmos4
parents: 5563
diff changeset
843 vob->delay = 0;
4080
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
844 buf = malloc((strlen(name) + 5) * sizeof(char));
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
845 if (buf) {
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
846 FILE *fd;
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
847 mpeg_t *mpg;
5388
3af2729c5c87 * New command line switch for mplayer & mencoder:
kmkaplan
parents: 4787
diff changeset
848 /* read in the info file */
6110
7bea806b9c5f Improvment for spu subtitles.
albeu
parents: 5869
diff changeset
849 if(!ifo) {
7bea806b9c5f Improvment for spu subtitles.
albeu
parents: 5869
diff changeset
850 strcpy(buf, name);
7bea806b9c5f Improvment for spu subtitles.
albeu
parents: 5869
diff changeset
851 strcat(buf, ".ifo");
7bea806b9c5f Improvment for spu subtitles.
albeu
parents: 5869
diff changeset
852 vobsub_parse_ifo(vob,buf, vob->palette, &vob->orig_frame_width, &vob->orig_frame_height, force);
7bea806b9c5f Improvment for spu subtitles.
albeu
parents: 5869
diff changeset
853 } else
7bea806b9c5f Improvment for spu subtitles.
albeu
parents: 5869
diff changeset
854 vobsub_parse_ifo(vob,ifo, vob->palette, &vob->orig_frame_width, &vob->orig_frame_height, force);
4080
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
855 /* read in the index */
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
856 strcpy(buf, name);
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
857 strcat(buf, ".idx");
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
858 fd = fopen(buf, "rb");
4787
1ee5574d67d6 Fix automatic vobsub detection and make it silent.
atmos4
parents: 4786
diff changeset
859 if (fd == NULL) {
1ee5574d67d6 Fix automatic vobsub detection and make it silent.
atmos4
parents: 4786
diff changeset
860 if(force)
6110
7bea806b9c5f Improvment for spu subtitles.
albeu
parents: 5869
diff changeset
861 mp_msg(MSGT_VOBSUB,MSGL_ERR,"VobSub: Can't open IDX file");
7bea806b9c5f Improvment for spu subtitles.
albeu
parents: 5869
diff changeset
862 else {
7bea806b9c5f Improvment for spu subtitles.
albeu
parents: 5869
diff changeset
863 free(buf);
7bea806b9c5f Improvment for spu subtitles.
albeu
parents: 5869
diff changeset
864 free(vob);
7bea806b9c5f Improvment for spu subtitles.
albeu
parents: 5869
diff changeset
865 return NULL;
7bea806b9c5f Improvment for spu subtitles.
albeu
parents: 5869
diff changeset
866 }
4787
1ee5574d67d6 Fix automatic vobsub detection and make it silent.
atmos4
parents: 4786
diff changeset
867 } else {
4080
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
868 while (vobsub_parse_one_line(vob, fd) >= 0)
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
869 /* NOOP */ ;
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
870 fclose(fd);
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
871 }
5833
91d766389a5d VobSub updates, custom palette support and other stuff, can't write the name of the chinese(?) patch supplier.
atmos4
parents: 5563
diff changeset
872 /* if no palette in .idx then use custom colors */
91d766389a5d VobSub updates, custom palette support and other stuff, can't write the name of the chinese(?) patch supplier.
atmos4
parents: 5563
diff changeset
873 if ((vob->custom == 0)&&(vob->have_palette!=1))
91d766389a5d VobSub updates, custom palette support and other stuff, can't write the name of the chinese(?) patch supplier.
atmos4
parents: 5563
diff changeset
874 vob->custom = 1;
6110
7bea806b9c5f Improvment for spu subtitles.
albeu
parents: 5869
diff changeset
875 if (spu && vob->orig_frame_width && vob->orig_frame_height)
7bea806b9c5f Improvment for spu subtitles.
albeu
parents: 5869
diff changeset
876 *spu = spudec_new_scaled_vobsub(vob->palette, vob->cuspal, vob->custom, vob->orig_frame_width, vob->orig_frame_height);
4080
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
877
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
878 /* read the indexed mpeg_stream */
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
879 strcpy(buf, name);
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
880 strcat(buf, ".sub");
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
881 mpg = mpeg_open(buf);
4787
1ee5574d67d6 Fix automatic vobsub detection and make it silent.
atmos4
parents: 4786
diff changeset
882 if (mpg == NULL) {
6110
7bea806b9c5f Improvment for spu subtitles.
albeu
parents: 5869
diff changeset
883 if(force)
7bea806b9c5f Improvment for spu subtitles.
albeu
parents: 5869
diff changeset
884 mp_msg(MSGT_VOBSUB,MSGL_ERR,"VobSub: Can't open SUB file");
7bea806b9c5f Improvment for spu subtitles.
albeu
parents: 5869
diff changeset
885 else {
7bea806b9c5f Improvment for spu subtitles.
albeu
parents: 5869
diff changeset
886
7bea806b9c5f Improvment for spu subtitles.
albeu
parents: 5869
diff changeset
887 free(buf);
7bea806b9c5f Improvment for spu subtitles.
albeu
parents: 5869
diff changeset
888 free(vob);
7bea806b9c5f Improvment for spu subtitles.
albeu
parents: 5869
diff changeset
889 return NULL;
7bea806b9c5f Improvment for spu subtitles.
albeu
parents: 5869
diff changeset
890 }
4787
1ee5574d67d6 Fix automatic vobsub detection and make it silent.
atmos4
parents: 4786
diff changeset
891 } else {
4080
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
892 long last_pts_diff = 0;
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
893 while (!mpeg_eof(mpg)) {
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
894 off_t pos = mpeg_tell(mpg);
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
895 if (mpeg_run(mpg) < 0) {
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
896 if (!mpeg_eof(mpg))
6110
7bea806b9c5f Improvment for spu subtitles.
albeu
parents: 5869
diff changeset
897 mp_msg(MSGT_VOBSUB,MSGL_ERR,"mpeg_run error");
4080
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
898 break;
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
899 }
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
900 if (mpg->packet_size) {
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
901 if ((mpg->aid & 0xe0) == 0x20) {
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
902 unsigned int sid = mpg->aid & 0x1f;
4085
dc0a91965b97 Support vobsub without index files.
kmkaplan
parents: 4080
diff changeset
903 if (vobsub_ensure_spu_stream(vob, sid) >= 0) {
4080
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
904 packet_queue_t *queue = vob->spu_streams + sid;
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
905 /* get the packet to fill */
4085
dc0a91965b97 Support vobsub without index files.
kmkaplan
parents: 4080
diff changeset
906 if (queue->packets_size == 0 && packet_queue_grow(queue) < 0)
dc0a91965b97 Support vobsub without index files.
kmkaplan
parents: 4080
diff changeset
907 abort();
4080
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
908 while (queue->current_index + 1 < queue->packets_size
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
909 && queue->packets[queue->current_index + 1].filepos <= pos)
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
910 ++queue->current_index;
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
911 if (queue->current_index < queue->packets_size) {
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
912 packet_t *pkt;
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
913 if (queue->packets[queue->current_index].data) {
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
914 /* insert a new packet and fix the PTS ! */
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
915 packet_queue_insert(queue);
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
916 queue->packets[queue->current_index].pts100 =
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
917 mpg->pts + last_pts_diff;
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
918 }
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
919 pkt = queue->packets + queue->current_index;
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
920 last_pts_diff = pkt->pts100 - mpg->pts;
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
921 /* FIXME: should not use mpg_sub internal informations, make a copy */
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
922 pkt->data = mpg->packet;
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
923 pkt->size = mpg->packet_size;
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
924 mpg->packet = NULL;
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
925 mpg->packet_reserve = 0;
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
926 mpg->packet_size = 0;
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
927 }
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
928 }
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
929 else
6110
7bea806b9c5f Improvment for spu subtitles.
albeu
parents: 5869
diff changeset
930 mp_msg(MSGT_VOBSUB,MSGL_WARN, "don't know what to do with subtitle #%u\n", sid);
4080
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
931 }
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
932 }
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
933 }
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
934 vob->spu_streams_current = vob->spu_streams_size;
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
935 while (vob->spu_streams_current-- > 0)
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
936 vob->spu_streams[vob->spu_streams_current].current_index = 0;
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
937 mpeg_free(mpg);
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
938 }
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
939 free(buf);
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
940 }
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
941 }
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
942 return vob;
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
943 }
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
944
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
945 void
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
946 vobsub_close(void *this)
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
947 {
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
948 vobsub_t *vob = (vobsub_t *)this;
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
949 if (vob->spu_streams) {
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
950 while (vob->spu_streams_size--)
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
951 packet_queue_destroy(vob->spu_streams + vob->spu_streams_size);
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
952 free(vob->spu_streams);
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
953 }
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
954 free(vob);
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
955 }
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
956
6110
7bea806b9c5f Improvment for spu subtitles.
albeu
parents: 5869
diff changeset
957 int
7bea806b9c5f Improvment for spu subtitles.
albeu
parents: 5869
diff changeset
958 vobsub_get_packet(void *vobhandle, float pts,void** data, int* timestamp) {
7bea806b9c5f Improvment for spu subtitles.
albeu
parents: 5869
diff changeset
959 vobsub_t *vob = (vobsub_t *)vobhandle;
7bea806b9c5f Improvment for spu subtitles.
albeu
parents: 5869
diff changeset
960 unsigned int pts100 = 90000 * pts;
7bea806b9c5f Improvment for spu subtitles.
albeu
parents: 5869
diff changeset
961 if (vob->spu_streams && 0 <= vobsub_id && (unsigned) vobsub_id < vob->spu_streams_size) {
7bea806b9c5f Improvment for spu subtitles.
albeu
parents: 5869
diff changeset
962 packet_queue_t *queue = vob->spu_streams + vobsub_id;
7bea806b9c5f Improvment for spu subtitles.
albeu
parents: 5869
diff changeset
963 while (queue->current_index < queue->packets_size) {
7bea806b9c5f Improvment for spu subtitles.
albeu
parents: 5869
diff changeset
964 packet_t *pkt = queue->packets + queue->current_index;
7bea806b9c5f Improvment for spu subtitles.
albeu
parents: 5869
diff changeset
965 if (pkt->pts100 <= pts100) {
7bea806b9c5f Improvment for spu subtitles.
albeu
parents: 5869
diff changeset
966 ++queue->current_index;
7bea806b9c5f Improvment for spu subtitles.
albeu
parents: 5869
diff changeset
967 *data = pkt->data;
7bea806b9c5f Improvment for spu subtitles.
albeu
parents: 5869
diff changeset
968 *timestamp = pkt->pts100;
7bea806b9c5f Improvment for spu subtitles.
albeu
parents: 5869
diff changeset
969 return pkt->size;
7bea806b9c5f Improvment for spu subtitles.
albeu
parents: 5869
diff changeset
970 } else break;
4080
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
971 }
6110
7bea806b9c5f Improvment for spu subtitles.
albeu
parents: 5869
diff changeset
972 }
7bea806b9c5f Improvment for spu subtitles.
albeu
parents: 5869
diff changeset
973 return -1;
4080
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
974 }
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
975
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
976 void
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
977 vobsub_reset(void *vobhandle)
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
978 {
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
979 vobsub_t *vob = (vobsub_t *)vobhandle;
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
980 if (vob->spu_streams) {
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
981 unsigned int n = vob->spu_streams_size;
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
982 while (n-- > 0)
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
983 vob->spu_streams[n].current_index = 0;
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
984 }
47bcafe1442e Add vobsub support.
kmkaplan
parents:
diff changeset
985 }