Mercurial > mplayer.hg
annotate sub/vobsub.c @ 36220:d1a2f89d0ba6
Remove unused arguments.
author | reimar |
---|---|
date | Sun, 09 Jun 2013 18:33:22 +0000 |
parents | 389d43c448b3 |
children | 5c8339df2496 |
rev | line source |
---|---|
32459
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1 /* |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
2 * Some code freely inspired from VobSub <URL:http://vobsub.edensrising.com>, |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
3 * with kind permission from Gabest <gabest@freemail.hu> |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
4 * |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
5 * This file is part of MPlayer. |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
6 * |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
7 * MPlayer is free software; you can redistribute it and/or modify |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
8 * it under the terms of the GNU General Public License as published by |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
9 * the Free Software Foundation; either version 2 of the License, or |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
10 * (at your option) any later version. |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
11 * |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
12 * MPlayer is distributed in the hope that it will be useful, |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
15 * GNU General Public License for more details. |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
16 * |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
17 * You should have received a copy of the GNU General Public License along |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
18 * with MPlayer; if not, write to the Free Software Foundation, Inc., |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
20 */ |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
21 |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
22 #include <ctype.h> |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
23 #include <errno.h> |
34139
cc8dfde2b6c5
Fix off_t printf conversion specifiers and related warnings.
diego
parents:
33514
diff
changeset
|
24 #include <inttypes.h> |
32459
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
25 #include <limits.h> |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
26 #include <stddef.h> |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
27 #include <stdio.h> |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
28 #include <stdlib.h> |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
29 #include <string.h> |
35903 | 30 #include <strings.h> |
32459
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
31 #include <fcntl.h> |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
32 #include <unistd.h> |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
33 #include <sys/stat.h> |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
34 #include <sys/types.h> |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
35 |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
36 #include "config.h" |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
37 #include "mpcommon.h" |
32464
22888a8cb312
Do not use a path for including files in the same directory.
reimar
parents:
32459
diff
changeset
|
38 #include "vobsub.h" |
22888a8cb312
Do not use a path for including files in the same directory.
reimar
parents:
32459
diff
changeset
|
39 #include "spudec.h" |
32459
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
40 #include "mp_msg.h" |
32588 | 41 #include "path.h" |
32464
22888a8cb312
Do not use a path for including files in the same directory.
reimar
parents:
32459
diff
changeset
|
42 #include "unrar_exec.h" |
32459
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
43 #include "libavutil/common.h" |
35238
036f41724884
Use AV_RB32 to avoid sign extension issues and validate offset before using it.
reimar
parents:
35237
diff
changeset
|
44 #include "libavutil/intreadwrite.h" |
32459
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
45 |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
46 // Record the original -vobsubid set by commandline, since vobsub_id will be |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
47 // overridden if slang match any of vobsub streams. |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
48 static int vobsubid = -2; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
49 |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
50 /********************************************************************** |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
51 * RAR stream handling |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
52 * The RAR file must have the same basename as the file to open |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
53 **********************************************************************/ |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
54 #ifdef CONFIG_UNRAR_EXEC |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
55 typedef struct { |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
56 FILE *file; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
57 unsigned char *data; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
58 unsigned long size; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
59 unsigned long pos; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
60 } rar_stream_t; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
61 |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
62 static rar_stream_t *rar_open(const char *const filename, |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
63 const char *const mode) |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
64 { |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
65 rar_stream_t *stream; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
66 /* unrar_exec can only read */ |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
67 if (strcmp("r", mode) && strcmp("rb", mode)) { |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
68 errno = EINVAL; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
69 return NULL; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
70 } |
35283 | 71 stream = calloc(1, sizeof(rar_stream_t)); |
32459
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
72 if (stream == NULL) |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
73 return NULL; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
74 /* first try normal access */ |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
75 stream->file = fopen(filename, mode); |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
76 if (stream->file == NULL) { |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
77 char *rar_filename; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
78 const char *p; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
79 int rc; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
80 /* Guess the RAR archive filename */ |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
81 rar_filename = NULL; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
82 p = strrchr(filename, '.'); |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
83 if (p) { |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
84 ptrdiff_t l = p - filename; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
85 rar_filename = malloc(l + 5); |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
86 if (rar_filename == NULL) { |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
87 free(stream); |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
88 return NULL; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
89 } |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
90 strncpy(rar_filename, filename, l); |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
91 strcpy(rar_filename + l, ".rar"); |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
92 } else { |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
93 rar_filename = malloc(strlen(filename) + 5); |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
94 if (rar_filename == NULL) { |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
95 free(stream); |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
96 return NULL; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
97 } |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
98 strcpy(rar_filename, filename); |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
99 strcat(rar_filename, ".rar"); |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
100 } |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
101 /* get rid of the path if there is any */ |
32588 | 102 p = mp_basename(filename); |
32459
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
103 rc = unrar_exec_get(&stream->data, &stream->size, p, rar_filename); |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
104 if (!rc) { |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
105 /* There is no matching filename in the archive. However, sometimes |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
106 * the files we are looking for have been given arbitrary names in the archive. |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
107 * Let's look for a file with an exact match in the extension only. */ |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
108 int i, num_files, name_len; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
109 ArchiveList_struct *list, *lp; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
110 num_files = unrar_exec_list(rar_filename, &list); |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
111 if (num_files > 0) { |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
112 char *demanded_ext; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
113 demanded_ext = strrchr (p, '.'); |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
114 if (demanded_ext) { |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
115 int demanded_ext_len = strlen (demanded_ext); |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
116 for (i = 0, lp = list; i < num_files; i++, lp = lp->next) { |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
117 name_len = strlen (lp->item.Name); |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
118 if (name_len >= demanded_ext_len && !strcasecmp (lp->item.Name + name_len - demanded_ext_len, demanded_ext)) { |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
119 rc = unrar_exec_get(&stream->data, &stream->size, |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
120 lp->item.Name, rar_filename); |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
121 if (rc) |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
122 break; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
123 } |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
124 } |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
125 } |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
126 unrar_exec_freelist(list); |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
127 } |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
128 if (!rc) { |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
129 free(rar_filename); |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
130 free(stream); |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
131 return NULL; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
132 } |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
133 } |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
134 |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
135 free(rar_filename); |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
136 stream->pos = 0; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
137 } |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
138 return stream; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
139 } |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
140 |
35283 | 141 static void rar_close(rar_stream_t *stream) |
32459
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
142 { |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
143 if (stream->file) |
35283 | 144 fclose(stream->file); |
32459
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
145 free(stream->data); |
35283 | 146 free(stream); |
32459
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
147 } |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
148 |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
149 static int rar_eof(rar_stream_t *stream) |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
150 { |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
151 if (stream->file) |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
152 return feof(stream->file); |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
153 return stream->pos >= stream->size; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
154 } |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
155 |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
156 static long rar_tell(rar_stream_t *stream) |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
157 { |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
158 if (stream->file) |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
159 return ftell(stream->file); |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
160 return stream->pos; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
161 } |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
162 |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
163 static int rar_seek(rar_stream_t *stream, long offset, int whence) |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
164 { |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
165 if (stream->file) |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
166 return fseek(stream->file, offset, whence); |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
167 switch (whence) { |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
168 case SEEK_SET: |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
169 if (offset < 0) { |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
170 errno = EINVAL; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
171 return -1; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
172 } |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
173 stream->pos = offset; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
174 break; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
175 case SEEK_CUR: |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
176 if (offset < 0 && stream->pos < (unsigned long) -offset) { |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
177 errno = EINVAL; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
178 return -1; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
179 } |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
180 stream->pos += offset; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
181 break; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
182 case SEEK_END: |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
183 if (offset < 0 && stream->size < (unsigned long) -offset) { |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
184 errno = EINVAL; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
185 return -1; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
186 } |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
187 stream->pos = stream->size + offset; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
188 break; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
189 default: |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
190 errno = EINVAL; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
191 return -1; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
192 } |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
193 return 0; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
194 } |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
195 |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
196 static int rar_getc(rar_stream_t *stream) |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
197 { |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
198 if (stream->file) |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
199 return getc(stream->file); |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
200 if (rar_eof(stream)) |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
201 return EOF; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
202 return stream->data[stream->pos++]; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
203 } |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
204 |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
205 static size_t rar_read(void *ptr, size_t size, size_t nmemb, |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
206 rar_stream_t *stream) |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
207 { |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
208 size_t res; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
209 unsigned long remain; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
210 if (stream->file) |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
211 return fread(ptr, size, nmemb, stream->file); |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
212 if (rar_eof(stream)) |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
213 return 0; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
214 res = size * nmemb; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
215 remain = stream->size - stream->pos; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
216 if (res > remain) |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
217 res = remain / size * size; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
218 memcpy(ptr, stream->data + stream->pos, res); |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
219 stream->pos += res; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
220 res /= size; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
221 return res; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
222 } |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
223 |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
224 #else |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
225 typedef FILE rar_stream_t; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
226 #define rar_open fopen |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
227 #define rar_close fclose |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
228 #define rar_eof feof |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
229 #define rar_tell ftell |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
230 #define rar_seek fseek |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
231 #define rar_getc getc |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
232 #define rar_read fread |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
233 #endif |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
234 |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
235 /**********************************************************************/ |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
236 |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
237 static ssize_t vobsub_getline(char **lineptr, size_t *n, rar_stream_t *stream) |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
238 { |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
239 size_t res = 0; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
240 int c; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
241 if (*lineptr == NULL) { |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
242 *lineptr = malloc(4096); |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
243 if (*lineptr) |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
244 *n = 4096; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
245 } else if (*n == 0) { |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
246 char *tmp = realloc(*lineptr, 4096); |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
247 if (tmp) { |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
248 *lineptr = tmp; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
249 *n = 4096; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
250 } |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
251 } |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
252 if (*lineptr == NULL || *n == 0) |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
253 return -1; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
254 |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
255 for (c = rar_getc(stream); c != EOF; c = rar_getc(stream)) { |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
256 if (res + 1 >= *n) { |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
257 char *tmp = realloc(*lineptr, *n * 2); |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
258 if (tmp == NULL) |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
259 return -1; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
260 *lineptr = tmp; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
261 *n *= 2; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
262 } |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
263 (*lineptr)[res++] = c; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
264 if (c == '\n') { |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
265 (*lineptr)[res] = 0; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
266 return res; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
267 } |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
268 } |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
269 if (res == 0) |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
270 return -1; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
271 (*lineptr)[res] = 0; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
272 return res; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
273 } |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
274 |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
275 /********************************************************************** |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
276 * MPEG parsing |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
277 **********************************************************************/ |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
278 |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
279 typedef struct { |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
280 rar_stream_t *stream; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
281 unsigned int pts; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
282 int aid; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
283 unsigned char *packet; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
284 unsigned int packet_reserve; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
285 unsigned int packet_size; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
286 int padding_was_here; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
287 int merge; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
288 } mpeg_t; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
289 |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
290 static mpeg_t *mpeg_open(const char *filename) |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
291 { |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
292 mpeg_t *res = malloc(sizeof(mpeg_t)); |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
293 int err = res == NULL; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
294 if (!err) { |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
295 res->pts = 0; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
296 res->aid = -1; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
297 res->packet = NULL; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
298 res->packet_size = 0; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
299 res->packet_reserve = 0; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
300 res->padding_was_here = 1; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
301 res->merge = 0; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
302 res->stream = rar_open(filename, "rb"); |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
303 err = res->stream == NULL; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
304 if (err) |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
305 perror("fopen Vobsub file failed"); |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
306 if (err) |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
307 free(res); |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
308 } |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
309 return err ? NULL : res; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
310 } |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
311 |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
312 static void mpeg_free(mpeg_t *mpeg) |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
313 { |
32511
b39155e98ac3
Remove some useless NULL pointer checks before invoking free() on the pointer.
diego
parents:
32464
diff
changeset
|
314 free(mpeg->packet); |
32459
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
315 if (mpeg->stream) |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
316 rar_close(mpeg->stream); |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
317 free(mpeg); |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
318 } |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
319 |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
320 static int mpeg_eof(mpeg_t *mpeg) |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
321 { |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
322 return rar_eof(mpeg->stream); |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
323 } |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
324 |
35879 | 325 static uint64_t mpeg_tell(mpeg_t *mpeg) |
32459
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
326 { |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
327 return rar_tell(mpeg->stream); |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
328 } |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
329 |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
330 static int mpeg_run(mpeg_t *mpeg) |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
331 { |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
332 unsigned int len, idx, version; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
333 int c; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
334 /* Goto start of a packet, it starts with 0x000001?? */ |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
335 const unsigned char wanted[] = { 0, 0, 1 }; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
336 unsigned char buf[5]; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
337 |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
338 mpeg->aid = -1; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
339 mpeg->packet_size = 0; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
340 if (rar_read(buf, 4, 1, mpeg->stream) != 1) |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
341 return -1; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
342 while (memcmp(buf, wanted, sizeof(wanted)) != 0) { |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
343 c = rar_getc(mpeg->stream); |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
344 if (c < 0) |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
345 return -1; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
346 memmove(buf, buf + 1, 3); |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
347 buf[3] = c; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
348 } |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
349 switch (buf[3]) { |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
350 case 0xb9: /* System End Code */ |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
351 break; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
352 case 0xba: /* Packet start code */ |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
353 c = rar_getc(mpeg->stream); |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
354 if (c < 0) |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
355 return -1; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
356 if ((c & 0xc0) == 0x40) |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
357 version = 4; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
358 else if ((c & 0xf0) == 0x20) |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
359 version = 2; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
360 else { |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
361 mp_msg(MSGT_VOBSUB, MSGL_ERR, "VobSub: Unsupported MPEG version: 0x%02x\n", c); |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
362 return -1; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
363 } |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
364 if (version == 4) { |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
365 if (rar_seek(mpeg->stream, 9, SEEK_CUR)) |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
366 return -1; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
367 } else if (version == 2) { |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
368 if (rar_seek(mpeg->stream, 7, SEEK_CUR)) |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
369 return -1; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
370 } else |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
371 abort(); |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
372 if (!mpeg->padding_was_here) |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
373 mpeg->merge = 1; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
374 break; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
375 case 0xbd: /* packet */ |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
376 if (rar_read(buf, 2, 1, mpeg->stream) != 1) |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
377 return -1; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
378 mpeg->padding_was_here = 0; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
379 len = buf[0] << 8 | buf[1]; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
380 idx = mpeg_tell(mpeg); |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
381 c = rar_getc(mpeg->stream); |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
382 if (c < 0) |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
383 return -1; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
384 if ((c & 0xC0) == 0x40) { /* skip STD scale & size */ |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
385 if (rar_getc(mpeg->stream) < 0) |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
386 return -1; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
387 c = rar_getc(mpeg->stream); |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
388 if (c < 0) |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
389 return -1; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
390 } |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
391 if ((c & 0xf0) == 0x20) { /* System-1 stream timestamp */ |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
392 /* Do we need this? */ |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
393 abort(); |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
394 } else if ((c & 0xf0) == 0x30) { |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
395 /* Do we need this? */ |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
396 abort(); |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
397 } else if ((c & 0xc0) == 0x80) { /* System-2 (.VOB) stream */ |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
398 unsigned int pts_flags, hdrlen, dataidx; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
399 c = rar_getc(mpeg->stream); |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
400 if (c < 0) |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
401 return -1; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
402 pts_flags = c; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
403 c = rar_getc(mpeg->stream); |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
404 if (c < 0) |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
405 return -1; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
406 hdrlen = c; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
407 dataidx = mpeg_tell(mpeg) + hdrlen; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
408 if (dataidx > idx + len) { |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
409 mp_msg(MSGT_VOBSUB, MSGL_ERR, "Invalid header length: %d (total length: %d, idx: %d, dataidx: %d)\n", |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
410 hdrlen, len, idx, dataidx); |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
411 return -1; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
412 } |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
413 if ((pts_flags & 0xc0) == 0x80) { |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
414 if (rar_read(buf, 5, 1, mpeg->stream) != 1) |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
415 return -1; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
416 if (!(((buf[0] & 0xf0) == 0x20) && (buf[0] & 1) && (buf[2] & 1) && (buf[4] & 1))) { |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
417 mp_msg(MSGT_VOBSUB, MSGL_ERR, "vobsub PTS error: 0x%02x %02x%02x %02x%02x \n", |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
418 buf[0], buf[1], buf[2], buf[3], buf[4]); |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
419 mpeg->pts = 0; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
420 } else |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
421 mpeg->pts = ((buf[0] & 0x0e) << 29 | buf[1] << 22 | (buf[2] & 0xfe) << 14 |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
422 | buf[3] << 7 | (buf[4] >> 1)); |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
423 } else /* if ((pts_flags & 0xc0) == 0xc0) */ { |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
424 /* what's this? */ |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
425 /* abort(); */ |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
426 } |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
427 rar_seek(mpeg->stream, dataidx, SEEK_SET); |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
428 mpeg->aid = rar_getc(mpeg->stream); |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
429 if (mpeg->aid < 0) { |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
430 mp_msg(MSGT_VOBSUB, MSGL_ERR, "Bogus aid %d\n", mpeg->aid); |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
431 return -1; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
432 } |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
433 mpeg->packet_size = len - ((unsigned int) mpeg_tell(mpeg) - idx); |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
434 if (mpeg->packet_reserve < mpeg->packet_size) { |
32511
b39155e98ac3
Remove some useless NULL pointer checks before invoking free() on the pointer.
diego
parents:
32464
diff
changeset
|
435 free(mpeg->packet); |
32459
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
436 mpeg->packet = malloc(mpeg->packet_size); |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
437 if (mpeg->packet) |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
438 mpeg->packet_reserve = mpeg->packet_size; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
439 } |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
440 if (mpeg->packet == NULL) { |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
441 mp_msg(MSGT_VOBSUB, MSGL_FATAL, "malloc failure"); |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
442 mpeg->packet_reserve = 0; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
443 mpeg->packet_size = 0; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
444 return -1; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
445 } |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
446 if (rar_read(mpeg->packet, mpeg->packet_size, 1, mpeg->stream) != 1) { |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
447 mp_msg(MSGT_VOBSUB, MSGL_ERR, "fread failure"); |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
448 mpeg->packet_size = 0; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
449 return -1; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
450 } |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
451 idx = len; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
452 } |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
453 break; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
454 case 0xbe: /* Padding */ |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
455 if (rar_read(buf, 2, 1, mpeg->stream) != 1) |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
456 return -1; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
457 len = buf[0] << 8 | buf[1]; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
458 if (len > 0 && rar_seek(mpeg->stream, len, SEEK_CUR)) |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
459 return -1; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
460 mpeg->padding_was_here = 1; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
461 break; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
462 default: |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
463 if (0xc0 <= buf[3] && buf[3] < 0xf0) { |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
464 /* MPEG audio or video */ |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
465 if (rar_read(buf, 2, 1, mpeg->stream) != 1) |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
466 return -1; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
467 len = buf[0] << 8 | buf[1]; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
468 if (len > 0 && rar_seek(mpeg->stream, len, SEEK_CUR)) |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
469 return -1; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
470 } else { |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
471 mp_msg(MSGT_VOBSUB, MSGL_ERR, "unknown header 0x%02X%02X%02X%02X\n", |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
472 buf[0], buf[1], buf[2], buf[3]); |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
473 return -1; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
474 } |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
475 } |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
476 return 0; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
477 } |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
478 |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
479 /********************************************************************** |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
480 * Packet queue |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
481 **********************************************************************/ |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
482 |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
483 typedef struct { |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
484 unsigned int pts100; |
35879 | 485 uint64_t filepos; |
32459
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
486 unsigned int size; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
487 unsigned char *data; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
488 } packet_t; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
489 |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
490 typedef struct { |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
491 char *id; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
492 packet_t *packets; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
493 unsigned int packets_reserve; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
494 unsigned int packets_size; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
495 unsigned int current_index; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
496 } packet_queue_t; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
497 |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
498 static void packet_construct(packet_t *pkt) |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
499 { |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
500 pkt->pts100 = 0; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
501 pkt->filepos = 0; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
502 pkt->size = 0; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
503 pkt->data = NULL; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
504 } |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
505 |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
506 static void packet_destroy(packet_t *pkt) |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
507 { |
32511
b39155e98ac3
Remove some useless NULL pointer checks before invoking free() on the pointer.
diego
parents:
32464
diff
changeset
|
508 free(pkt->data); |
32459
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
509 } |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
510 |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
511 static void packet_queue_construct(packet_queue_t *queue) |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
512 { |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
513 queue->id = NULL; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
514 queue->packets = NULL; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
515 queue->packets_reserve = 0; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
516 queue->packets_size = 0; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
517 queue->current_index = 0; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
518 } |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
519 |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
520 static void packet_queue_destroy(packet_queue_t *queue) |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
521 { |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
522 if (queue->packets) { |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
523 while (queue->packets_size--) |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
524 packet_destroy(queue->packets + queue->packets_size); |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
525 free(queue->packets); |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
526 } |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
527 return; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
528 } |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
529 |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
530 /* Make sure there is enough room for needed_size packets in the |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
531 packet queue. */ |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
532 static int packet_queue_ensure(packet_queue_t *queue, unsigned int needed_size) |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
533 { |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
534 if (queue->packets_reserve < needed_size) { |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
535 if (queue->packets) { |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
536 packet_t *tmp = realloc(queue->packets, 2 * queue->packets_reserve * sizeof(packet_t)); |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
537 if (tmp == NULL) { |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
538 mp_msg(MSGT_VOBSUB, MSGL_FATAL, "realloc failure"); |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
539 return -1; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
540 } |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
541 queue->packets = tmp; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
542 queue->packets_reserve *= 2; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
543 } else { |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
544 queue->packets = malloc(sizeof(packet_t)); |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
545 if (queue->packets == NULL) { |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
546 mp_msg(MSGT_VOBSUB, MSGL_FATAL, "malloc failure"); |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
547 return -1; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
548 } |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
549 queue->packets_reserve = 1; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
550 } |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
551 } |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
552 return 0; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
553 } |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
554 |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
555 /* add one more packet */ |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
556 static int packet_queue_grow(packet_queue_t *queue) |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
557 { |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
558 if (packet_queue_ensure(queue, queue->packets_size + 1) < 0) |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
559 return -1; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
560 packet_construct(queue->packets + queue->packets_size); |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
561 ++queue->packets_size; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
562 return 0; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
563 } |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
564 |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
565 /* insert a new packet, duplicating pts from the current one */ |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
566 static int packet_queue_insert(packet_queue_t *queue) |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
567 { |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
568 packet_t *pkts; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
569 if (packet_queue_ensure(queue, queue->packets_size + 1) < 0) |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
570 return -1; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
571 /* XXX packet_size does not reflect the real thing here, it will be updated a bit later */ |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
572 memmove(queue->packets + queue->current_index + 2, |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
573 queue->packets + queue->current_index + 1, |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
574 sizeof(packet_t) * (queue->packets_size - queue->current_index - 1)); |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
575 pkts = queue->packets + queue->current_index; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
576 ++queue->packets_size; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
577 ++queue->current_index; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
578 packet_construct(pkts + 1); |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
579 pkts[1].pts100 = pkts[0].pts100; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
580 pkts[1].filepos = pkts[0].filepos; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
581 return 0; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
582 } |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
583 |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
584 /********************************************************************** |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
585 * Vobsub |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
586 **********************************************************************/ |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
587 |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
588 typedef struct { |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
589 unsigned int palette[16]; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
590 int delay; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
591 unsigned int have_palette; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
592 unsigned int orig_frame_width, orig_frame_height; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
593 unsigned int origin_x, origin_y; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
594 /* index */ |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
595 packet_queue_t *spu_streams; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
596 unsigned int spu_streams_size; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
597 unsigned int spu_streams_current; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
598 unsigned int spu_valid_streams_size; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
599 } vobsub_t; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
600 |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
601 /* Make sure that the spu stream idx exists. */ |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
602 static int vobsub_ensure_spu_stream(vobsub_t *vob, unsigned int index) |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
603 { |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
604 if (index >= vob->spu_streams_size) { |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
605 /* This is a new stream */ |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
606 if (vob->spu_streams) { |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
607 packet_queue_t *tmp = realloc(vob->spu_streams, (index + 1) * sizeof(packet_queue_t)); |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
608 if (tmp == NULL) { |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
609 mp_msg(MSGT_VOBSUB, MSGL_ERR, "vobsub_ensure_spu_stream: realloc failure"); |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
610 return -1; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
611 } |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
612 vob->spu_streams = tmp; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
613 } else { |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
614 vob->spu_streams = malloc((index + 1) * sizeof(packet_queue_t)); |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
615 if (vob->spu_streams == NULL) { |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
616 mp_msg(MSGT_VOBSUB, MSGL_ERR, "vobsub_ensure_spu_stream: malloc failure"); |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
617 return -1; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
618 } |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
619 } |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
620 while (vob->spu_streams_size <= index) { |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
621 packet_queue_construct(vob->spu_streams + vob->spu_streams_size); |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
622 ++vob->spu_streams_size; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
623 } |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
624 } |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
625 return 0; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
626 } |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
627 |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
628 static int vobsub_add_id(vobsub_t *vob, const char *id, size_t idlen, |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
629 const unsigned int index) |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
630 { |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
631 if (vobsub_ensure_spu_stream(vob, index) < 0) |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
632 return -1; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
633 if (id && idlen) { |
32511
b39155e98ac3
Remove some useless NULL pointer checks before invoking free() on the pointer.
diego
parents:
32464
diff
changeset
|
634 free(vob->spu_streams[index].id); |
32459
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
635 vob->spu_streams[index].id = malloc(idlen + 1); |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
636 if (vob->spu_streams[index].id == NULL) { |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
637 mp_msg(MSGT_VOBSUB, MSGL_FATAL, "vobsub_add_id: malloc failure"); |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
638 return -1; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
639 } |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
640 vob->spu_streams[index].id[idlen] = 0; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
641 memcpy(vob->spu_streams[index].id, id, idlen); |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
642 } |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
643 vob->spu_streams_current = index; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
644 mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_VOBSUB_ID=%d\n", index); |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
645 if (id && idlen) |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
646 mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_VSID_%d_LANG=%s\n", index, vob->spu_streams[index].id); |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
647 mp_msg(MSGT_VOBSUB, MSGL_V, "[vobsub] subtitle (vobsubid): %d language %s\n", |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
648 index, vob->spu_streams[index].id); |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
649 return 0; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
650 } |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
651 |
35879 | 652 static int vobsub_add_timestamp(vobsub_t *vob, uint64_t filepos, int ms) |
32459
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
653 { |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
654 packet_queue_t *queue; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
655 packet_t *pkt; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
656 if (vob->spu_streams == 0) { |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
657 mp_msg(MSGT_VOBSUB, MSGL_WARN, "[vobsub] warning, binning some index entries. Check your index file\n"); |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
658 return -1; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
659 } |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
660 queue = vob->spu_streams + vob->spu_streams_current; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
661 if (packet_queue_grow(queue) >= 0) { |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
662 pkt = queue->packets + (queue->packets_size - 1); |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
663 pkt->filepos = filepos; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
664 pkt->pts100 = ms < 0 ? UINT_MAX : (unsigned int)ms * 90; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
665 return 0; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
666 } |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
667 return -1; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
668 } |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
669 |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
670 static int vobsub_parse_id(vobsub_t *vob, const char *line) |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
671 { |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
672 // id: xx, index: n |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
673 size_t idlen; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
674 const char *p, *q; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
675 p = line; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
676 while (isspace(*p)) |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
677 ++p; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
678 q = p; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
679 while (isalpha(*q)) |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
680 ++q; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
681 idlen = q - p; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
682 if (idlen == 0) |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
683 return -1; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
684 ++q; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
685 while (isspace(*q)) |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
686 ++q; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
687 if (strncmp("index:", q, 6)) |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
688 return -1; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
689 q += 6; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
690 while (isspace(*q)) |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
691 ++q; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
692 if (!isdigit(*q)) |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
693 return -1; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
694 return vobsub_add_id(vob, p, idlen, atoi(q)); |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
695 } |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
696 |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
697 static int vobsub_parse_timestamp(vobsub_t *vob, const char *line) |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
698 { |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
699 int h, m, s, ms; |
35879 | 700 uint64_t filepos; |
34144
beafae9de2be
Employ correct off_t printf conversion specifiers; this time without typos.
diego
parents:
34139
diff
changeset
|
701 if (sscanf(line, " %02d:%02d:%02d:%03d, filepos: %09"PRIx64"", |
33513 | 702 &h, &m, &s, &ms, &filepos) != 5) |
32459
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
703 return -1; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
704 return vobsub_add_timestamp(vob, filepos, vob->delay + ms + 1000 * (s + 60 * (m + 60 * h))); |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
705 } |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
706 |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
707 static int vobsub_parse_origin(vobsub_t *vob, const char *line) |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
708 { |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
709 // org: X,Y |
33514 | 710 unsigned x, y; |
711 | |
712 if (sscanf(line, " %u,%u", &x, &y) == 2) { | |
713 vob->origin_x = x; | |
714 vob->origin_y = y; | |
715 return 0; | |
716 } | |
717 return -1; | |
32459
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
718 } |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
719 |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
720 unsigned int vobsub_palette_to_yuv(unsigned int pal) |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
721 { |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
722 int r, g, b, y, u, v; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
723 // Palette in idx file is not rgb value, it was calculated by wrong formula. |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
724 // Here's reversed formula of the one used to generate palette in idx file. |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
725 r = pal >> 16 & 0xff; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
726 g = pal >> 8 & 0xff; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
727 b = pal & 0xff; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
728 y = av_clip_uint8( 0.1494 * r + 0.6061 * g + 0.2445 * b); |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
729 u = av_clip_uint8( 0.6066 * r - 0.4322 * g - 0.1744 * b + 128); |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
730 v = av_clip_uint8(-0.08435 * r - 0.3422 * g + 0.4266 * b + 128); |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
731 y = y * 219 / 255 + 16; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
732 return y << 16 | u << 8 | v; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
733 } |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
734 |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
735 unsigned int vobsub_rgb_to_yuv(unsigned int rgb) |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
736 { |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
737 int r, g, b, y, u, v; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
738 r = rgb >> 16 & 0xff; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
739 g = rgb >> 8 & 0xff; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
740 b = rgb & 0xff; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
741 y = ( 0.299 * r + 0.587 * g + 0.114 * b) * 219 / 255 + 16.5; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
742 u = (-0.16874 * r - 0.33126 * g + 0.5 * b) * 224 / 255 + 128.5; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
743 v = ( 0.5 * r - 0.41869 * g - 0.08131 * b) * 224 / 255 + 128.5; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
744 return y << 16 | u << 8 | v; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
745 } |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
746 |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
747 static int vobsub_parse_delay(vobsub_t *vob, const char *line) |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
748 { |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
749 int h, m, s, ms; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
750 int forward = 1; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
751 if (*(line + 7) == '+') { |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
752 forward = 1; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
753 line++; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
754 } else if (*(line + 7) == '-') { |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
755 forward = -1; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
756 line++; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
757 } |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
758 mp_msg(MSGT_SPUDEC, MSGL_V, "forward=%d", forward); |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
759 h = atoi(line + 7); |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
760 mp_msg(MSGT_VOBSUB, MSGL_V, "h=%d,", h); |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
761 m = atoi(line + 10); |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
762 mp_msg(MSGT_VOBSUB, MSGL_V, "m=%d,", m); |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
763 s = atoi(line + 13); |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
764 mp_msg(MSGT_VOBSUB, MSGL_V, "s=%d,", s); |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
765 ms = atoi(line + 16); |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
766 mp_msg(MSGT_VOBSUB, MSGL_V, "ms=%d", ms); |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
767 vob->delay = (ms + 1000 * (s + 60 * (m + 60 * h))) * forward; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
768 return 0; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
769 } |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
770 |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
771 static int vobsub_set_lang(const char *line) |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
772 { |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
773 if (vobsub_id == -1) |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
774 vobsub_id = atoi(line + 8); |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
775 return 0; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
776 } |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
777 |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
778 static int vobsub_parse_one_line(vobsub_t *vob, rar_stream_t *fd, |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
779 unsigned char **extradata, |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
780 unsigned int *extradata_len) |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
781 { |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
782 ssize_t line_size; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
783 int res = -1; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
784 size_t line_reserve = 0; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
785 char *line = NULL; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
786 do { |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
787 line_size = vobsub_getline(&line, &line_reserve, fd); |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
788 if (line_size < 0 || line_size > 1000000 || |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
789 *extradata_len+line_size > 10000000) { |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
790 break; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
791 } |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
792 |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
793 *extradata = realloc(*extradata, *extradata_len+line_size+1); |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
794 memcpy(*extradata+*extradata_len, line, line_size); |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
795 *extradata_len += line_size; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
796 (*extradata)[*extradata_len] = 0; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
797 |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
798 if (*line == 0 || *line == '\r' || *line == '\n' || *line == '#') |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
799 continue; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
800 else if (strncmp("langidx:", line, 8) == 0) |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
801 res = vobsub_set_lang(line); |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
802 else if (strncmp("delay:", line, 6) == 0) |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
803 res = vobsub_parse_delay(vob, line); |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
804 else if (strncmp("id:", line, 3) == 0) |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
805 res = vobsub_parse_id(vob, line + 3); |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
806 else if (strncmp("org:", line, 4) == 0) |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
807 res = vobsub_parse_origin(vob, line + 4); |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
808 else if (strncmp("timestamp:", line, 10) == 0) |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
809 res = vobsub_parse_timestamp(vob, line + 10); |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
810 else { |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
811 mp_msg(MSGT_VOBSUB, MSGL_V, "vobsub: ignoring %s", line); |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
812 continue; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
813 } |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
814 if (res < 0) |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
815 mp_msg(MSGT_VOBSUB, MSGL_ERR, "ERROR in %s", line); |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
816 break; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
817 } while (1); |
32511
b39155e98ac3
Remove some useless NULL pointer checks before invoking free() on the pointer.
diego
parents:
32464
diff
changeset
|
818 free(line); |
32459
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
819 return res; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
820 } |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
821 |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
822 int vobsub_parse_ifo(void* this, const char *const name, unsigned int *palette, |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
823 unsigned int *width, unsigned int *height, int force, |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
824 int sid, char *langid) |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
825 { |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
826 vobsub_t *vob = this; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
827 int res = -1; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
828 rar_stream_t *fd = rar_open(name, "rb"); |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
829 if (fd == NULL) { |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
830 if (force) |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
831 mp_msg(MSGT_VOBSUB, MSGL_WARN, "VobSub: Can't open IFO file\n"); |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
832 } else { |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
833 // parse IFO header |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
834 unsigned char block[0x800]; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
835 const char *const ifo_magic = "DVDVIDEO-VTS"; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
836 if (rar_read(block, sizeof(block), 1, fd) != 1) { |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
837 if (force) |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
838 mp_msg(MSGT_VOBSUB, MSGL_ERR, "VobSub: Can't read IFO header\n"); |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
839 } else if (memcmp(block, ifo_magic, strlen(ifo_magic) + 1)) |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
840 mp_msg(MSGT_VOBSUB, MSGL_ERR, "VobSub: Bad magic in IFO header\n"); |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
841 else { |
35238
036f41724884
Use AV_RB32 to avoid sign extension issues and validate offset before using it.
reimar
parents:
35237
diff
changeset
|
842 unsigned pgci_sector = AV_RB32(block + 0xcc); |
32459
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
843 int standard = (block[0x200] & 0x30) >> 4; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
844 int resolution = (block[0x201] & 0x0c) >> 2; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
845 *height = standard ? 576 : 480; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
846 *width = 0; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
847 switch (resolution) { |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
848 case 0x0: |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
849 *width = 720; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
850 break; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
851 case 0x1: |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
852 *width = 704; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
853 break; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
854 case 0x2: |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
855 *width = 352; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
856 break; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
857 case 0x3: |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
858 *width = 352; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
859 *height /= 2; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
860 break; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
861 default: |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
862 mp_msg(MSGT_VOBSUB, MSGL_WARN, "Vobsub: Unknown resolution %d \n", resolution); |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
863 } |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
864 if (langid && 0 <= sid && sid < 32) { |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
865 unsigned char *tmp = block + 0x256 + sid * 6 + 2; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
866 langid[0] = tmp[0]; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
867 langid[1] = tmp[1]; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
868 langid[2] = 0; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
869 } |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
870 if (rar_seek(fd, pgci_sector * sizeof(block), SEEK_SET) |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
871 || rar_read(block, sizeof(block), 1, fd) != 1) |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
872 mp_msg(MSGT_VOBSUB, MSGL_ERR, "VobSub: Can't read IFO PGCI\n"); |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
873 else { |
35237 | 874 unsigned idx; |
35238
036f41724884
Use AV_RB32 to avoid sign extension issues and validate offset before using it.
reimar
parents:
35237
diff
changeset
|
875 unsigned pgc_offset = AV_RB32(block + 0xc); |
036f41724884
Use AV_RB32 to avoid sign extension issues and validate offset before using it.
reimar
parents:
35237
diff
changeset
|
876 pgc_offset = FFMIN(pgc_offset, sizeof(block) - 0xa4 - 4*16); |
32459
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
877 for (idx = 0; idx < 16; ++idx) { |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
878 unsigned char *p = block + pgc_offset + 0xa4 + 4 * idx; |
35238
036f41724884
Use AV_RB32 to avoid sign extension issues and validate offset before using it.
reimar
parents:
35237
diff
changeset
|
879 palette[idx] = AV_RB32(p); |
32459
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
880 } |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
881 if (vob) |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
882 vob->have_palette = 1; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
883 res = 0; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
884 } |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
885 } |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
886 rar_close(fd); |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
887 } |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
888 return res; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
889 } |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
890 |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
891 void *vobsub_open(const char *const name, const char *const ifo, |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
892 const int force, void** spu) |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
893 { |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
894 unsigned char *extradata = NULL; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
895 unsigned int extradata_len = 0; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
896 vobsub_t *vob = calloc(1, sizeof(vobsub_t)); |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
897 if (spu) |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
898 *spu = NULL; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
899 if (vobsubid == -2) |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
900 vobsubid = vobsub_id; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
901 if (vob) { |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
902 char *buf; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
903 buf = malloc(strlen(name) + 5); |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
904 if (buf) { |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
905 rar_stream_t *fd; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
906 mpeg_t *mpg; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
907 /* read in the info file */ |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
908 if (!ifo) { |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
909 strcpy(buf, name); |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
910 strcat(buf, ".ifo"); |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
911 vobsub_parse_ifo(vob, buf, vob->palette, &vob->orig_frame_width, &vob->orig_frame_height, force, -1, NULL); |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
912 } else |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
913 vobsub_parse_ifo(vob, ifo, vob->palette, &vob->orig_frame_width, &vob->orig_frame_height, force, -1, NULL); |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
914 /* read in the index */ |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
915 strcpy(buf, name); |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
916 strcat(buf, ".idx"); |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
917 fd = rar_open(buf, "rb"); |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
918 if (fd == NULL) { |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
919 if (force) |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
920 mp_msg(MSGT_VOBSUB, MSGL_ERR, "VobSub: Can't open IDX file\n"); |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
921 else { |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
922 free(buf); |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
923 free(vob); |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
924 return NULL; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
925 } |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
926 } else { |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
927 while (vobsub_parse_one_line(vob, fd, &extradata, &extradata_len) >= 0) |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
928 /* NOOP */ ; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
929 rar_close(fd); |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
930 } |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
931 if (spu) |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
932 *spu = spudec_new_scaled(vob->palette, vob->orig_frame_width, vob->orig_frame_height, extradata, extradata_len); |
32511
b39155e98ac3
Remove some useless NULL pointer checks before invoking free() on the pointer.
diego
parents:
32464
diff
changeset
|
933 free(extradata); |
32459
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
934 |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
935 /* read the indexed mpeg_stream */ |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
936 strcpy(buf, name); |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
937 strcat(buf, ".sub"); |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
938 mpg = mpeg_open(buf); |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
939 if (mpg == NULL) { |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
940 if (force) |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
941 mp_msg(MSGT_VOBSUB, MSGL_ERR, "VobSub: Can't open SUB file\n"); |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
942 else { |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
943 free(buf); |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
944 free(vob); |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
945 return NULL; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
946 } |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
947 } else { |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
948 long last_pts_diff = 0; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
949 while (!mpeg_eof(mpg)) { |
35879 | 950 uint64_t pos = mpeg_tell(mpg); |
32459
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
951 if (mpeg_run(mpg) < 0) { |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
952 if (!mpeg_eof(mpg)) |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
953 mp_msg(MSGT_VOBSUB, MSGL_ERR, "VobSub: mpeg_run error\n"); |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
954 break; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
955 } |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
956 if (mpg->packet_size) { |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
957 if ((mpg->aid & 0xe0) == 0x20) { |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
958 unsigned int sid = mpg->aid & 0x1f; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
959 if (vobsub_ensure_spu_stream(vob, sid) >= 0) { |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
960 packet_queue_t *queue = vob->spu_streams + sid; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
961 /* get the packet to fill */ |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
962 if (queue->packets_size == 0 && packet_queue_grow(queue) < 0) |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
963 abort(); |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
964 while (queue->current_index + 1 < queue->packets_size |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
965 && queue->packets[queue->current_index + 1].filepos <= pos) |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
966 ++queue->current_index; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
967 if (queue->current_index < queue->packets_size) { |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
968 packet_t *pkt; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
969 if (queue->packets[queue->current_index].data) { |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
970 /* insert a new packet and fix the PTS ! */ |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
971 packet_queue_insert(queue); |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
972 queue->packets[queue->current_index].pts100 = |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
973 mpg->pts + last_pts_diff; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
974 } |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
975 pkt = queue->packets + queue->current_index; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
976 if (pkt->pts100 != UINT_MAX) { |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
977 if (queue->packets_size > 1) |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
978 last_pts_diff = pkt->pts100 - mpg->pts; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
979 else |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
980 pkt->pts100 = mpg->pts; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
981 if (mpg->merge && queue->current_index > 0) { |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
982 packet_t *last = &queue->packets[queue->current_index - 1]; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
983 pkt->pts100 = last->pts100; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
984 } |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
985 mpg->merge = 0; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
986 /* FIXME: should not use mpg_sub internal informations, make a copy */ |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
987 pkt->data = mpg->packet; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
988 pkt->size = mpg->packet_size; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
989 mpg->packet = NULL; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
990 mpg->packet_reserve = 0; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
991 mpg->packet_size = 0; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
992 } |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
993 } |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
994 } else |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
995 mp_msg(MSGT_VOBSUB, MSGL_WARN, "don't know what to do with subtitle #%u\n", sid); |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
996 } |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
997 } |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
998 } |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
999 vob->spu_streams_current = vob->spu_streams_size; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1000 while (vob->spu_streams_current-- > 0) { |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1001 vob->spu_streams[vob->spu_streams_current].current_index = 0; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1002 if (vobsubid == vob->spu_streams_current || |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1003 vob->spu_streams[vob->spu_streams_current].packets_size > 0) |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1004 ++vob->spu_valid_streams_size; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1005 } |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1006 mpeg_free(mpg); |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1007 } |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1008 free(buf); |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1009 } |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1010 } |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1011 return vob; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1012 } |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1013 |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1014 void vobsub_close(void *this) |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1015 { |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1016 vobsub_t *vob = this; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1017 if (vob->spu_streams) { |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1018 while (vob->spu_streams_size--) |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1019 packet_queue_destroy(vob->spu_streams + vob->spu_streams_size); |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1020 free(vob->spu_streams); |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1021 } |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1022 free(vob); |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1023 } |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1024 |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1025 unsigned int vobsub_get_indexes_count(void *vobhandle) |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1026 { |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1027 vobsub_t *vob = vobhandle; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1028 return vob->spu_valid_streams_size; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1029 } |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1030 |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1031 char *vobsub_get_id(void *vobhandle, unsigned int index) |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1032 { |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1033 vobsub_t *vob = vobhandle; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1034 return (index < vob->spu_streams_size) ? vob->spu_streams[index].id : NULL; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1035 } |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1036 |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1037 int vobsub_get_id_by_index(void *vobhandle, unsigned int index) |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1038 { |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1039 vobsub_t *vob = vobhandle; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1040 int i, j; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1041 if (vob == NULL) |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1042 return -1; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1043 for (i = 0, j = 0; i < vob->spu_streams_size; ++i) |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1044 if (i == vobsubid || vob->spu_streams[i].packets_size > 0) { |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1045 if (j == index) |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1046 return i; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1047 ++j; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1048 } |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1049 return -1; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1050 } |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1051 |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1052 int vobsub_get_index_by_id(void *vobhandle, int id) |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1053 { |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1054 vobsub_t *vob = vobhandle; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1055 int i, j; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1056 if (vob == NULL || id < 0 || id >= vob->spu_streams_size) |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1057 return -1; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1058 if (id != vobsubid && !vob->spu_streams[id].packets_size) |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1059 return -1; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1060 for (i = 0, j = 0; i < id; ++i) |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1061 if (i == vobsubid || vob->spu_streams[i].packets_size > 0) |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1062 ++j; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1063 return j; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1064 } |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1065 |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1066 int vobsub_set_from_lang(void *vobhandle, unsigned char * lang) |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1067 { |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1068 int i; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1069 vobsub_t *vob= vobhandle; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1070 while (lang && strlen(lang) >= 2) { |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1071 for (i = 0; i < vob->spu_streams_size; i++) |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1072 if (vob->spu_streams[i].id) |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1073 if ((strncmp(vob->spu_streams[i].id, lang, 2) == 0)) { |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1074 vobsub_id = i; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1075 mp_msg(MSGT_VOBSUB, MSGL_INFO, "Selected VOBSUB language: %d language: %s\n", i, vob->spu_streams[i].id); |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1076 return 0; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1077 } |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1078 lang+=2;while (lang[0]==',' || lang[0]==' ') ++lang; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1079 } |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1080 mp_msg(MSGT_VOBSUB, MSGL_WARN, "No matching VOBSUB language found!\n"); |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1081 return -1; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1082 } |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1083 |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1084 /// make sure we seek to the first packet of packets having same pts values. |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1085 static void vobsub_queue_reseek(packet_queue_t *queue, unsigned int pts100) |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1086 { |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1087 int reseek_count = 0; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1088 unsigned int lastpts = 0; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1089 |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1090 if (queue->current_index > 0 |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1091 && (queue->packets[queue->current_index].pts100 == UINT_MAX |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1092 || queue->packets[queue->current_index].pts100 > pts100)) { |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1093 // possible pts seek previous, try to check it. |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1094 int i = 1; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1095 while (queue->current_index >= i |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1096 && queue->packets[queue->current_index-i].pts100 == UINT_MAX) |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1097 ++i; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1098 if (queue->current_index >= i |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1099 && queue->packets[queue->current_index-i].pts100 > pts100) |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1100 // pts seek previous confirmed, reseek from beginning |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1101 queue->current_index = 0; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1102 } |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1103 while (queue->current_index < queue->packets_size |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1104 && queue->packets[queue->current_index].pts100 <= pts100) { |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1105 lastpts = queue->packets[queue->current_index].pts100; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1106 ++queue->current_index; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1107 ++reseek_count; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1108 } |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1109 while (reseek_count-- && --queue->current_index) { |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1110 if (queue->packets[queue->current_index-1].pts100 != UINT_MAX && |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1111 queue->packets[queue->current_index-1].pts100 != lastpts) |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1112 break; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1113 } |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1114 } |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1115 |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1116 int vobsub_get_packet(void *vobhandle, float pts, void** data, int* timestamp) |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1117 { |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1118 vobsub_t *vob = vobhandle; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1119 unsigned int pts100 = 90000 * pts; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1120 if (vob->spu_streams && 0 <= vobsub_id && (unsigned) vobsub_id < vob->spu_streams_size) { |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1121 packet_queue_t *queue = vob->spu_streams + vobsub_id; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1122 |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1123 vobsub_queue_reseek(queue, pts100); |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1124 |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1125 while (queue->current_index < queue->packets_size) { |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1126 packet_t *pkt = queue->packets + queue->current_index; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1127 if (pkt->pts100 != UINT_MAX) |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1128 if (pkt->pts100 <= pts100) { |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1129 ++queue->current_index; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1130 *data = pkt->data; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1131 *timestamp = pkt->pts100; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1132 return pkt->size; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1133 } else |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1134 break; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1135 else |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1136 ++queue->current_index; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1137 } |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1138 } |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1139 return -1; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1140 } |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1141 |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1142 int vobsub_get_next_packet(void *vobhandle, void** data, int* timestamp) |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1143 { |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1144 vobsub_t *vob = vobhandle; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1145 if (vob->spu_streams && 0 <= vobsub_id && (unsigned) vobsub_id < vob->spu_streams_size) { |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1146 packet_queue_t *queue = vob->spu_streams + vobsub_id; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1147 if (queue->current_index < queue->packets_size) { |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1148 packet_t *pkt = queue->packets + queue->current_index; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1149 ++queue->current_index; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1150 *data = pkt->data; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1151 *timestamp = pkt->pts100; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1152 return pkt->size; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1153 } |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1154 } |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1155 return -1; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1156 } |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1157 |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1158 void vobsub_seek(void * vobhandle, float pts) |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1159 { |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1160 vobsub_t * vob = vobhandle; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1161 packet_queue_t * queue; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1162 int seek_pts100 = pts * 90000; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1163 |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1164 if (vob->spu_streams && 0 <= vobsub_id && (unsigned) vobsub_id < vob->spu_streams_size) { |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1165 /* do not seek if we don't know the id */ |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1166 if (vobsub_get_id(vob, vobsub_id) == NULL) |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1167 return; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1168 queue = vob->spu_streams + vobsub_id; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1169 queue->current_index = 0; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1170 vobsub_queue_reseek(queue, seek_pts100); |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1171 } |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1172 } |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1173 |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1174 void vobsub_reset(void *vobhandle) |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1175 { |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1176 vobsub_t *vob = vobhandle; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1177 if (vob->spu_streams) { |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1178 unsigned int n = vob->spu_streams_size; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1179 while (n-- > 0) |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1180 vob->spu_streams[n].current_index = 0; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1181 } |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1182 } |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1183 |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1184 /********************************************************************** |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1185 * Vobsub output |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1186 **********************************************************************/ |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1187 |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1188 typedef struct { |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1189 FILE *fsub; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1190 FILE *fidx; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1191 unsigned int aid; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1192 } vobsub_out_t; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1193 |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1194 static void create_idx(vobsub_out_t *me, const unsigned int *palette, |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1195 unsigned int orig_width, unsigned int orig_height) |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1196 { |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1197 int i; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1198 fprintf(me->fidx, |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1199 "# VobSub index file, v7 (do not modify this line!)\n" |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1200 "#\n" |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1201 "# Generated by %s\n" |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1202 "# See <URL:http://www.mplayerhq.hu/> for more information about MPlayer\n" |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1203 "# See <URL:http://wiki.multimedia.cx/index.php?title=VOBsub> for more information about Vobsub\n" |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1204 "#\n" |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1205 "size: %ux%u\n", |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1206 mplayer_version, orig_width, orig_height); |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1207 if (palette) { |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1208 fputs("palette:", me->fidx); |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1209 for (i = 0; i < 16; ++i) { |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1210 const double y = palette[i] >> 16 & 0xff, |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1211 u = (palette[i] >> 8 & 0xff) - 128.0, |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1212 v = (palette[i] & 0xff) - 128.0; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1213 if (i) |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1214 putc(',', me->fidx); |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1215 fprintf(me->fidx, " %02x%02x%02x", |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1216 av_clip_uint8(y + 1.4022 * u), |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1217 av_clip_uint8(y - 0.3456 * u - 0.7145 * v), |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1218 av_clip_uint8(y + 1.7710 * v)); |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1219 } |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1220 putc('\n', me->fidx); |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1221 } |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1222 |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1223 fprintf(me->fidx, "# ON: displays only forced subtitles, OFF: shows everything\n" |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1224 "forced subs: OFF\n"); |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1225 } |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1226 |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1227 void *vobsub_out_open(const char *basename, const unsigned int *palette, |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1228 unsigned int orig_width, unsigned int orig_height, |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1229 const char *id, unsigned int index) |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1230 { |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1231 vobsub_out_t *result = NULL; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1232 char *filename; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1233 filename = malloc(strlen(basename) + 5); |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1234 if (filename) { |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1235 result = malloc(sizeof(vobsub_out_t)); |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1236 if (result) { |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1237 result->aid = index; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1238 strcpy(filename, basename); |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1239 strcat(filename, ".sub"); |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1240 result->fsub = fopen(filename, "ab"); |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1241 if (result->fsub == NULL) |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1242 perror("Error: vobsub_out_open subtitle file open failed"); |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1243 strcpy(filename, basename); |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1244 strcat(filename, ".idx"); |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1245 result->fidx = fopen(filename, "ab"); |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1246 if (result->fidx) { |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1247 if (ftell(result->fidx) == 0) { |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1248 create_idx(result, palette, orig_width, orig_height); |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1249 /* Make the selected language the default language */ |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1250 fprintf(result->fidx, "\n# Language index in use\nlangidx: %u\n", index); |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1251 } |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1252 fprintf(result->fidx, "\nid: %s, index: %u\n", id ? id : "xx", index); |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1253 /* So that we can check the file now */ |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1254 fflush(result->fidx); |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1255 } else |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1256 perror("Error: vobsub_out_open index file open failed"); |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1257 free(filename); |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1258 } |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1259 } |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1260 return result; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1261 } |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1262 |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1263 void vobsub_out_close(void *me) |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1264 { |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1265 vobsub_out_t *vob = me; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1266 if (vob->fidx) |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1267 fclose(vob->fidx); |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1268 if (vob->fsub) |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1269 fclose(vob->fsub); |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1270 free(vob); |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1271 } |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1272 |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1273 void vobsub_out_output(void *me, const unsigned char *packet, |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1274 int len, double pts) |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1275 { |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1276 static double last_pts; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1277 static int last_pts_set = 0; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1278 vobsub_out_t *vob = me; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1279 if (vob->fsub) { |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1280 /* Windows' Vobsub require that every packet is exactly 2kB long */ |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1281 unsigned char buffer[2048]; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1282 unsigned char *p; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1283 int remain = 2048; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1284 /* Do not output twice a line with the same timestamp, this |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1285 breaks Windows' Vobsub */ |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1286 if (vob->fidx && (!last_pts_set || last_pts != pts)) { |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1287 static unsigned int last_h = 9999, last_m = 9999, last_s = 9999, last_ms = 9999; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1288 unsigned int h, m, ms; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1289 double s; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1290 s = pts; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1291 h = s / 3600; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1292 s -= h * 3600; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1293 m = s / 60; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1294 s -= m * 60; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1295 ms = (s - (unsigned int) s) * 1000; |
33487 | 1296 if (ms >= 1000) /* prevent overflows or bad float stuff */ |
32459
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1297 ms = 0; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1298 if (h != last_h || m != last_m || (unsigned int) s != last_s || ms != last_ms) { |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1299 fprintf(vob->fidx, "timestamp: %02u:%02u:%02u:%03u, filepos: %09lx\n", |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1300 h, m, (unsigned int) s, ms, ftell(vob->fsub)); |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1301 last_h = h; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1302 last_m = m; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1303 last_s = (unsigned int) s; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1304 last_ms = ms; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1305 } |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1306 } |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1307 last_pts = pts; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1308 last_pts_set = 1; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1309 |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1310 /* Packet start code: Windows' Vobsub needs this */ |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1311 p = buffer; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1312 *p++ = 0; /* 0x00 */ |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1313 *p++ = 0; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1314 *p++ = 1; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1315 *p++ = 0xba; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1316 *p++ = 0x40; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1317 memset(p, 0, 9); |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1318 p += 9; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1319 { /* Packet */ |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1320 static unsigned char last_pts[5] = { 0, 0, 0, 0, 0}; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1321 unsigned char now_pts[5]; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1322 int pts_len, pad_len, datalen = len; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1323 pts *= 90000; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1324 now_pts[0] = 0x21 | (((unsigned long)pts >> 29) & 0x0e); |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1325 now_pts[1] = ((unsigned long)pts >> 22) & 0xff; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1326 now_pts[2] = 0x01 | (((unsigned long)pts >> 14) & 0xfe); |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1327 now_pts[3] = ((unsigned long)pts >> 7) & 0xff; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1328 now_pts[4] = 0x01 | (((unsigned long)pts << 1) & 0xfe); |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1329 pts_len = memcmp(last_pts, now_pts, sizeof(now_pts)) ? sizeof(now_pts) : 0; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1330 memcpy(last_pts, now_pts, sizeof(now_pts)); |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1331 |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1332 datalen += 3; /* Version, PTS_flags, pts_len */ |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1333 datalen += pts_len; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1334 datalen += 1; /* AID */ |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1335 pad_len = 2048 - (p - buffer) - 4 /* MPEG ID */ - 2 /* payload len */ - datalen; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1336 /* XXX - Go figure what should go here! In any case the |
33487 | 1337 packet has to be completely filled. If I can fill it |
32459
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1338 with padding (0x000001be) latter I'll do that. But if |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1339 there is only room for 6 bytes then I can not write a |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1340 padding packet. So I add some padding in the PTS |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1341 field. This looks like a dirty kludge. Oh well... */ |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1342 if (pad_len < 0) { |
33487 | 1343 /* Packet is too big. Let's try omitting the PTS field */ |
32459
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1344 datalen -= pts_len; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1345 pts_len = 0; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1346 pad_len = 0; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1347 } else if (pad_len > 6) |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1348 pad_len = 0; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1349 datalen += pad_len; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1350 |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1351 *p++ = 0; /* 0x0e */ |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1352 *p++ = 0; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1353 *p++ = 1; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1354 *p++ = 0xbd; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1355 |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1356 *p++ = (datalen >> 8) & 0xff; /* length of payload */ |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1357 *p++ = datalen & 0xff; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1358 *p++ = 0x80; /* System-2 (.VOB) stream */ |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1359 *p++ = pts_len ? 0x80 : 0x00; /* pts_flags */ |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1360 *p++ = pts_len + pad_len; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1361 memcpy(p, now_pts, pts_len); |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1362 p += pts_len; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1363 memset(p, 0, pad_len); |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1364 p += pad_len; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1365 } |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1366 *p++ = 0x20 | vob->aid; /* aid */ |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1367 if (fwrite(buffer, p - buffer, 1, vob->fsub) != 1 |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1368 || fwrite(packet, len, 1, vob->fsub) != 1) |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1369 perror("ERROR: vobsub write failed"); |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1370 else |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1371 remain -= p - buffer + len; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1372 |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1373 /* Padding */ |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1374 if (remain >= 6) { |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1375 p = buffer; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1376 *p++ = 0x00; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1377 *p++ = 0x00; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1378 *p++ = 0x01; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1379 *p++ = 0xbe; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1380 *p++ = (remain - 6) >> 8; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1381 *p++ = (remain - 6) & 0xff; |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1382 /* for better compression, blank this */ |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1383 memset(buffer + 6, 0, remain - (p - buffer)); |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1384 if (fwrite(buffer, remain, 1, vob->fsub) != 1) |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1385 perror("ERROR: vobsub padding write failed"); |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1386 } else if (remain > 0) { |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1387 /* I don't know what to output. But anyway the block |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1388 needs to be 2KB big */ |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1389 memset(buffer, 0, remain); |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1390 if (fwrite(buffer, remain, 1, vob->fsub) != 1) |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1391 perror("ERROR: vobsub blank padding write failed"); |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1392 } else if (remain < 0) |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1393 fprintf(stderr, |
33487 | 1394 "\nERROR: wrong thing happened...\n" |
32459
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1395 " I wrote a %i data bytes spu packet and that's too long\n", len); |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1396 } |
1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents:
diff
changeset
|
1397 } |